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

# Perform a customer operation

> Commit a requested name and its task in one transaction

`customers.rename` reads the customer and its observed account, records the
requested name and submits one `renameCustomer` task. The writes and the task
commit together, or not at all.

```ts bijection/customers.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
export const rename = mutation(
  {
    under: crm,
    allow: [writer],
    args: { customer: t.key(customers), name: t.string },
    refuses: { NameInvalid: null, CustomerUnavailable: null, AccountUnavailable: null },
  },
  async (ctx, args) => {
    const name = args.name.trim();
    if (name.length === 0 || name.length > 120) ctx.refuse("NameInvalid", "A name has 1 to 120 characters");
    const fact = await ctx.get(customers(args.customer));
    if (fact === null) ctx.refuse("CustomerUnavailable", "The customer is unavailable");
    const account = await ctx.get(accounts({ external_id: fact.account }));
    if (account === null) ctx.refuse("AccountUnavailable", "The customer's CRM account has not been observed");
    await ctx.patch(customers(fact.id), { requested_name: name, rename: { name, status: "sent", detail: null } });
    // The deadline is the operation's `within`; `once` is the `Idempotency-Key`.
    await ctx.submit(
      api.renameCustomer,
      { customerId: account.external_id, revision: account.revision, name },
      {
        once: ["rename", fact.id, account.revision, name],
        then: renamed.with({ customer: fact.id, account: account.external_id, name }),
      },
    );
  },
);
```

* `ctx.refuse` returns `never`, so the code after each check sees the narrowed
  fact.
* `ctx.patch` assumes the customer is present. That assumption joins the
  transaction's read set: if the fact is gone at commit, the transaction refuses
  `Absent`.
* `ctx.submit(target, args, { once, then })` commits intent toward the target
  atomically with the writes and returns a `Task`. The host performs it after
  the commit.

`once` is the identity of this one logical effect. It names the customer, the
account revision read and the name, so asking again for the same name at the
same revision returns the original task and sends nothing more. The CRM
applies the change only to the revision this transaction read (`If-Match`).

`then: renamed.with({ … })` names the continuation: the mutation that receives
the task's result. [Effects](https://docs.bijection.com/functions/effects.md) covers targets, `submit` and
continuations. Continue to [observe the result](https://docs.bijection.com/start/tutorial/observe-the-result.md).


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