> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Publish a typed client

> Write a client package of the app's exposed tree, with per-path pins from bijection.lock.

In the same repository, a frontend imports the app's type and connects:
`api<typeof App>()` types references from the tree. Consumers in
other repositories or languages use a client package that
`bijection client <lang>` writes from the exposed tree. It carries each
exposed path with its arguments, value and declared `refuses` codes.
For a mutation that declares `completion`, the shared interface also carries
the observer's path and exact contract pin. TypeScript infers the observer's
terminal result in `client.wait`. All generated clients return the portable
receipt as the mutation value. The runtime can observe that value or pass
it to the CLI. A callable's optional `revision` changes its reviewed pin
when it makes an incompatible semantic change with the same wire types.

## Write the package

From the application project, first make sure `bijection.lock` is current
and committed ([`bijection check --write-lock`](https://docs.bijection.com/development/cli/check)): The command compares the reviewed per-path digests with the source. Then write the package:

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection client ts --name @acme/orders-client --package-version 1.0.0 --out dist/orders-client
```

The directory holds the npm package, its TypeScript declarations,
`interface.json`. Publish it through your normal npm
workflow. The package exports its refs as `app`. Its `connect` supplies the
map of reviewed per-path digests:

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { app, connect } from "@acme/orders-client";

const client = connect(installationUrl, { token });
const order = await client.query(app.orders.lookup, { number: orderNumber });
if (!order.ok) console.error(order.code, order.message);
```

A changed function refuses calls pinned to its previous digest with
`Conflict` and reason `ContractStale`.

When using TypeScript's type-only app import directly, pass the callable
digest map from the reviewed lock to `connect` as `contract`. A path
missing from the map refuses before the SDK sends it. For a tool that
deliberately follows the installation's current interface, choose
`contract: "discover"`.

For another language, write the language-neutral interface document:

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection client json --out dist/orders.interface.json
```

A function without a declared `returns` has an `unknown` value in the
TypeScript client and is listed under `unresolved` in the interface document.
Declare `returns` on every exposed function a client package carries.

Generated view lookups, links, inspections, searches, and indexed reads supply
their own return contracts. Packaged clients retain object keys, page cursors,
and the declared types of view fields across repositories. Projected fields
are optional because a caller can omit them with `pick`. A warehouse-backed
field carries its observation state and the value type in its ready case.
`derive(type, fields, calculate)` declares its result validator.
An observed warehouse aggregate keeps one observation state and the
types of all its measures.

## Share selected ontology calls

Put the consumer's selection in a file such as `surfaces/approvals.json`.
Use an object’s tree path and list each query, link, or action the consumer needs.

```json theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{
  "objects": {
    "customers": {
      "queries": ["lookup", "inspect", "orders", "inspectLink"],
      "actions": ["approveExposure"],
      "requestEvidence": ["approveExposure"]
    }
  }
}
```

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection client json --surface surfaces/approvals.json --out contracts/approvals.json
bijection client ts --surface surfaces/approvals.json --name @acme/approvals --out dist/approvals
```

A scoped package contains the chosen callable references and their exact
reviewed contract pins. `requestEvidence` adds recovery for a selected action
with a declared evidence requirement. The recovery route fixes the fields
and freshness window from that action. Set `request: true` to include
general warehouse acquisition for the object. The installation authorizes
both operations on every call. The interface includes the public object identities,
link bounds and action evidence, plus the key types the chosen calls need. A
linked object can appear as an identity without adding any of its calls to
the package. Set `producer` in the selection to use an explicit producer
identity, or name the project in `bijection.json` or `package.json`.

A consumer can check the interface file into its own project and generate
bindings without reaching the producer’s installation.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection imports add approvals --adapter bijection.interface --from contracts/approvals.json
```

In the consumer, import `app` and `connect` from
`bijection/_generated/bijection/approvals.js`. Pass the producer installation
URL and the caller’s credentials to `connect`. The client sends each
selected function’s pin, and the installation authorizes each call.
Generated output uses `unknown` when a callable declares no return
validator.

To update, replace the captured interface in the consumer project, then
review and publish the proposed change.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection imports update approvals --dry-run
bijection imports update approvals
```

The review lists added and removed calls and changes to arguments, results,
refusals, link bounds, and action evidence. A failed import leaves the active
bindings in place.

Publish a fixed field subset with `const customerCard = customers.project("name", "openExposure")`
and place it in the application and ontology catalog. Scope consumers to
`customerCard.lookup` or `customerCard.inspect` for a read contract based
on those fields. The projection shares the Customer identity and admission.
Set `request: true` on the exported projection to include its bounded
warehouse request. Reads and requests both enforce the field subset.

## Review contract changes

Run `bijection check` in CI. It refuses a committed `bijection.lock` that
differs from the source: an added or removed path, or changed arguments,
values or codes, changes the corresponding `contract` line, and a changed MCP view, skill or
tool visibility changes the route's `descriptor`. For an intended change, run
`bijection check --write-lock`, review the diff and commit it before writing
the package again.

## Boundaries

Each consumer chooses the installation URL and passes its own `token`. The
installation decides every call: `allow`, grants, clearance and guards. For
tool hosts, expose selected functions on an [MCP endpoint](https://docs.bijection.com/mcp/native-tools.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.