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

# Control access to the customer workflow

> Label the customer data, declare roles that clear it and manage who holds them

> [!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.

The example decides access with labels, roles and grants alone, and declares
no guards. Labels decide who may know a fact. A role decides what its holder
may do. A [guard](https://docs.bijection.com/access/guards.md) would add a refusal of acts the roles would
otherwise allow, such as "only the account's owner renames it".

## Label the data and declare roles

```ts bijection/roles.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { label, role } from "@bijectionhq/bijection";

/** Customer data: the CRM's accounts, the local customers and what the
 * CRM answers. */
export const crm = label();

/** Reads customers and the CRM feed's health. */
export const reader = role({ clear: [crm] });

/** Associates customers with CRM accounts, renames them in the CRM and
 * operates the feed. */
export const writer = role({ clear: [crm] });

/** Holds the two roles above, and grants and revokes them. */
export const admin = role({ clear: [crm], include: [reader, writer], issue: true });
```

Labels and roles take no names: the tree places this module at `roles`, so
they are `roles.crm`, `roles.reader`, `roles.writer` and `roles.admin`.

Every customer function runs `under: crm`. A function's `allow` names the
roles that may enter it: `customers.associate` and `customers.rename` take
`allow: [writer]`, and `customers.directory` takes `allow: [reader, writer]`.
The continuation `customers.renamed` has no `allow`, so it is internal: only
the delivery of its task reaches it. The receiver clears `crm`, so a task may
carry customer data to the CRM.

## Manage members

```ts bijection/team.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { members } from "@bijectionhq/library-members";
import { admin, crm, reader, writer } from "./roles";

export const team = members({ roles: [reader, writer, admin], roster: crm });
```

Placed at `team`, the library contributes `team.invite`, `team.revoke`,
`team.me` and `team.list`. Its grants, directory and invitations sit at its
`roster`, `crm`, which every role it manages clears: a person's grant never
sits at public. Declare the administrator in the app's `founders`
and choose the founder when creating the installation.

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
bijection installation create "$PROJECT_ID" notes --installation-id "$INSTALLATION_ID" --type prod --founder you@example.com
bijection mutate team.invite subject='person:<principal id>' role=roles.writer until:=null email:=null
```

After the founder signs in, use `team.invite` with the recipient's principal ID (the `person:…` ID `ctx.frame.as.id` answers for them) and role.

`bijection.lock` beside `bijection/app.ts` lists every exposed
path with its `allow` and `under`, the grave acts it can perform and the guards
on it. Run `bijection check --write-lock`, then review and commit it before
deploying. [Grants](https://docs.bijection.com/access/grants.md) covers roles and grants in full.

Continue to [perform an operation](https://docs.bijection.com/start/tutorial/perform-an-operation.md).


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