> ## 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.

# Customer account workflow

> Follow a source feed, labelled customers, roles and one rename sent to an external service

> [!NOTE]
>
> These examples describe the current Bijection CLI and SDK source. Use builds
> from the same source commit for these APIs. The public CLI and npm SDK
> are published independently and may lag this reference.

This tutorial follows the maintained [OpenAPI CRM application](https://github.com/bijectionhq/bijection/tree/main/examples/openapi-crm).
A CRM's OpenAPI contract becomes a receiver of targets. A feed reads the CRM's
accounts into the app every minute, the app keeps its own customers beside
them, and a rename is a task submitted to the CRM whose result the app records.

## Before you begin

Use a source checkout with the matching Bijection CLI and SDK prepared. The
example's package manifest uses workspace sources, including the sources
library `@bijectionhq/library-sources`; it is not a standalone public npm
starter. Its complete declarations live under `examples/openapi-crm`.

You also need:

* An owned deployment with application sign-in configured.
* A service implementing the captured `services/crm/openapi.yaml` contract.
  The example includes the contract, not a running CRM service.
* A service token for that CRM. Use a dedicated account whose records you may
  change.

The receiver states guarantees of this particular example service, including
idempotency keys kept for a day. An arbitrary CRM endpoint does not acquire
those guarantees by adopting the declaration.

For a first app without an external service, use the
[notes quickstart](https://docs.bijection.com/start/quickstart.md).

```mermaid theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
flowchart LR
    CRM[CRM API] -->|listCustomers, every minute| Accounts[(data.accounts)]
    Accounts --> List[customers.directory]
    Local[(data.customers)] --> List
    Rename[customers.rename] --> Local
    Rename -->|renameCustomer task| CRM
    CRM -->|result| Renamed[customers.renamed] --> Local
```

## The app tree

Every name in the example is a path in its tree:

```ts bijection/app.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { app } from "@bijectionhq/bijection";
import { api, crmFeed, token } from "./crm";
import { associate, directory, listAccounts, rename, renamed } from "./customers";
import * as roles from "./roles";
import { accounts, customers } from "./schema";
import { team } from "./team";

export default app({
  roles,
  crm: { token, ...api },
  data: { accounts, customers },
  customers: { associate, rename, renamed, directory, accounts: listAccounts },
  feed: crmFeed,
  team,
});
```

The sources library is placed at `feed` and the `members()` library at
`team`, so their tables and functions take paths there (`feed.control.refresh`,
`team.invite`).

## Follow the workflow

| Step | You will do |
| - | - |
| [Connect a source](https://docs.bijection.com/start/tutorial/connect-a-source.md) | Declare the CRM's operations as targets and the feed over them |
| [Define customers](https://docs.bijection.com/start/tutorial/define-customers.md) | Keep observed accounts and local customers in separate tables |
| [Control access](https://docs.bijection.com/start/tutorial/control-access.md) | Label the customer data, declare roles and grant them through `members()` |
| [Perform an operation](https://docs.bijection.com/start/tutorial/perform-an-operation.md) | Commit a requested name and its task together |
| [Observe the result](https://docs.bijection.com/start/tutorial/observe-the-result.md) | Tell apart the commit, the CRM's answer and the later observation |

Keep using the same project and selected deployment throughout. The code shown
in the steps comes from the maintained example.


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