Skip to main content
The OpenAPI CRM example keeps the observed CRM accounts in a table only the feed writes. A separate customers table holds the local identity, its associated account, the requested name and how the CRM answered the latest rename.

Declare the tables

bijection/crm.ts
bijection/schema.ts
Both tables carry the crm label, so only frames that clear crm read or write them. unique: [["external_id"]] makes accounts({ external_id }) a point. Both tables are protected: the store keeps only a token of each unique field, so customers({ account }) answers with the account fixed, and a range or an order over it is read with ctx.list(selection.atMost(n)). The tree places both under data, as data.accounts and data.customers. Tables and indexes cover the declarations.

Associate and read

customers.associate checks that the account was observed and that no customer exists for it before inserting one:
bijection/customers.ts
  • ctx.has reads only the account’s presence. ctx.get reads a fact, or null.
  • ctx.insert(customers, fact) mints the key and returns it. It assumes the fact is absent.
  • ctx.refuse leaves the transaction with a code from refuses.
customers.directory reads the first 100 customers, each with its observed account, and answers the CRM’s observed_name beside the app’s requested_name. Continue to control access.