TaxPilot

Search the docs

Search the Help centre, Developer docs and Legal centre.

Open TaxPilot

State, actions and permissions

Read and write firm data through the repository and store, check permissions with can(), and keep the audit trail and undo working.

Updated November 22, 2026

All firm data is one immutable State object. The repository in packages/t2/src/repo.ts is the only thing that changes it, and every change is checked against the caller's organization and role and recorded in the return's audit trail. The web app holds the state in apps/web/lib/store.ts and saves it to localStorage.

State and Session

src/repo.ts
export type State = {
  schema: 1
  orgs: Org[]
  users: User[]
  memberships: Membership[]
  corporations: Corporation[]
  returns: TaxReturn[]
}
export type Session = { userId: string; orgId: string }

A TaxReturn carries its status, formSet (release id), data (inputs, tables, overrides, trial balance, GIFI mappings, answers), versions (locked snapshots) and an append-only audit array. Entity details are in src/model/types.ts and docs/data-model.md.

Permissions

There are 11 actions and four fixed roles. Roles can't be customised per firm.

src/repo.ts
export const PERMISSIONS: Record<Role, Action[]> = {
  owner: ADMIN,
  admin: ADMIN,
  preparer: ["corp.read", "corp.write", "return.edit", "return.override", "return.submit", "return.export", "return.review"],
  reviewer: ["corp.read", "return.override", "return.approve", "return.reopen", "return.export", "return.review", "return.file"],
}

ADMIN is all 11: corp.read, corp.write, return.edit, return.override, return.submit, return.approve, return.reopen, return.export, return.review, return.file and org.manage. Only an owner can add, change or remove an owner (guardOwner).

  • can(state, session, action) returns a boolean and never throws. Use it to hide or disable UI.
  • roleOf(state, session) throws AccessError for a non-member or a deactivated member.
  • Every repository write calls an internal require first, so the check holds even if the UI forgets. AccessError reads like "The preparer role cannot return approve."
  • Another firm's record gives the same "not found" error as a missing one, so ids don't leak across tenants.

In a component, useSession() from lib/use-return.ts returns { state, session, user, org, role, can, saveFailed }:

app/app/page.tsx (excerpt)
action={s.can("corp.write") && <Button nativeButton={false} render={<Link href="/app/customers/new" />}>Add customer</Button>}

Writing: act()

Screens never mutate state. They call act(fn, success?, opts?) from lib/store.ts with a function that takes (state, session) and returns the next state, usually a single repository call:

app/app/settings/page.tsx (excerpt)
if (act((st, se) => setOrgSettings(st, se, { name }), "Firm name saved")) setName(name.trim())
  • On success it saves, notifies subscribers and shows the success toast, with an Undo action if you pass opts.undo.
  • Any thrown error (access, lock, validation) becomes an error toast, the state is unchanged, and act returns false, so keep your dialog open.
  • If another tab saved since this tab last read, the write is refused and the newer state is loaded. A storage listener also adopts other tabs' saves.
  • If localStorage is full or blocked, the write isn't shown as done and saveFailed becomes true.

Return lifecycle

The stored ReturnStatus values. The UI derives labels such as Preparing, Filed and Awaiting signature from these and from the filing record (lib/return-status.ts).

updateReturn enforces the locks for every write: a cancelled return must be restored first, a filed one needs an amendment, and an approved one must be reopened. A preparer's edit to a return in review takes it back to in-progress.

Audit trail and undo

  • Every write appends an AuditEntry { id, at, by, action, target, before, after, note }. There are about 50 action codes, from input.set to org.settings. describeChange(entry, reg?, ret?) turns one into a sentence for the history views.
  • undoLast and redoLast walk the audit trail back to the last boundary (a status change or lock), and refuse on an approved return. nextUndo and nextRedo give the tooltip text.
  • Overrides need a reason. Warnings are acknowledged with a reason (ackDiagnostic).

For how roles look to a firm, see Roles and permissions and The audit log.