Skip to content
Spools
Documentation
On this page

Upgrading

The framework is a package, so an update is a version:

sh
bun update @swirls/spoolsbun run crm:genbun run db:push                # a database you push to; for one you migrate, see belowbun run check

Read the changelog first. Breaking changes are listed with what to do about them. Your own files (crm.config.json, src/, swirls/) never change under you.

When an update changes the tables#

The changelog says when a version changes the tables, and what changes. What you run then depends on how each of your databases is kept up:

The database What to run after bun run crm:gen
A Postgres you push to (db:push) bun run db:push
A Postgres you migrate (db:plan, db:migrate) bun run db:plan -- --name <update>, commit the migration, then bun run db:migrate
PGlite (.data/pglite) Nothing. The server brings it up to date when it starts

If you push to a local database and migrate production, plan the migration before you push. db:plan starts from the db ref (migrations/app/refs/db.json), and db:push moves that ref on to the new tables, which leaves the plan nothing to start from. db:plan then stops with MIGRATION.HASH_NOT_IN_GRAPH. It stops with MIGRATION.PLAN_ORIGIN_UNKNOWN when there is no ref at all, because you have only ever migrated. Either way, say where to start:

sh
bun run db:plan -- --name <update> --from <the last migration's folder name>

Read the plan before you apply it: it lists each operation and the SQL. A plan that would delete or rename a column is refused until you say so (Deployment), and the changelog says when an update needs that. Running db:push or db:migrate a second time changes nothing.

PGlite adds what is missing and drops an index a table no longer declares (Database). It never drops a table or a column, so there is nothing to back up first and nothing to delete.

Versioning#

  • The framework follows semantic versioning. Before 1.0, minor versions can include breaking changes.
  • "version" in crm.config.json is the config format version. It changes only when the format breaks, and bun run crm:gen tells you if your config is on an older one.
  • New pages and endpoints are new route files. The changelog gives them to you to copy; until you do, the feature is off.

Layouts (0.9)#

Nothing changes until crm.config.json has a ui key. To use layouts:

  1. For pages of your own (ui.pages), add the route file src/routes/_crm/pages.$page.tsx:

    tsx
    import { createFileRoute } from '@tanstack/react-router'import { customPage } from '@swirls/spools/pages/custom'export const Route = createFileRoute('/_crm/pages/$page')(customPage)

    bun run crm:gen says when it is missing. A record page's layout (ui.records) needs no new file.

  2. An object with the key pages can't share a Spool with ui.pages: its list would be at their address.

No table changes.

Modules, record rules, role access and your own door (0.7)#

A Spool with no modules and none of the new config keys works as before, apart from what changes without any new key. Everything else is off until the config or src/spool.server.ts says otherwise.

The database#

Table or column When Holds
change_signals Always A "last changed" mark for each object and record (Database)
idempotent_requests Always Writes sent with an Idempotency-Key (Extending)
activities.field Always For a change line, the key of the field it changed. Empty on lines written before
rate_limit_slots Only with rateLimits: storeRateLimits() Rate limits counted in the database (Adapters)
<module>_<table> Only with a module that keeps tables of its own A module's private tables (Modules)
A unique index Only for each unique rule in the config The rule, partial when it has where (Database)

Nothing is renamed or dropped, so no plan needs to be told it may delete anything.

sh
bun update @swirls/spoolsbun run crm:genbun run db:push                                   # a database you push tobun run db:plan -- --name modules-and-rules       # or one you migrate:bun run db:migrate                                # commit the migration, then apply itbun run check

PGlite adds the tables and the column as the server starts.

What changes without any new key#

  • modules in crm.config.json is now the modules' settings. Before, a key the config's schema didn't know was ignored. Now settings under modules.<name> for a module that src/spool.server.ts doesn't list are refused when the server starts and by bun run crm:gen, and so are settings for a module that takes none. If your config has a modules key of its own, rename it.
  • The tool API wraps every timeline line. The summary, body and author of each line that get hands a workflow or the assistant are now { "untrusted": true, "text": "..." }, not a string, whoever wrote the line. A workflow of yours that reads a record's timeline reads .text. Copy the two lines about wrapped values from the starter's swirls/assistant.swirls into your assistant's instructions, then swirls deploy. See Swirls.
  • New scripts. A new Spool has "db:rules": "spools rules" in package.json. Add it, or run bunx spools rules.
  • Fixes. The Prisma adapter names each column of an included record once. Times on a record's page are drawn the same on the server and in the browser. A search still loading no longer replaces a filter chosen after it.

Modules#

Listing a module is three edits (Use a module): modules in src/spool.server.ts, its settings in crm.config.json, and its browser half. A Spool made before this version has no place for the browser half yet. Add it once:

ts
// src/spool.ui.tsimport { defineSpoolUi } from '@swirls/spools/ui/slots'export const ui = defineSpoolUi({ modules: [] })
tsx
// src/routes/__root.tsximport { SpoolUiProvider } from '@swirls/spools/ui/slots'import { authClients, ui } from '../spool.ui';<AuthClientProvider clients={authClients} id={brand?.auth}>  <SpoolUiProvider ui={ui}>    <html lang="en">...</html>  </SpoolUiProvider></AuthClientProvider>

Without the provider nothing breaks: the slots are empty, so a module's panels and sidebar links are not shown, while its objects, hooks and tables still work. Then run bunx spools modules, which lists the route files your modules expect and exits 1 until each is there.

Record rules#

  • Uniqueness rules (unique on an object) are unique indexes. Run bun run db:rules (spools rules) after adding one and before db:push or db:plan: Postgres refuses to make the index over records that already break the rule. See Database.
  • A clash is a Conflict, with the rule's name and your message, on every store. Code that relied on a constraint of your own (a migration adding a unique or exclusion constraint, and code that read the database's refusal) can move to unique in the config. Drop your own constraint in the same migration, or keep it: PGlite and Prisma leave a constraint they didn't make alone.
  • Hooks that guarded fields (refusing a change to a field once written, keeping a field to the server, writing a correction trail) can become immutable, lock, readonly and audit (Record rules). A readonly field is refused from a person's write before your before hook runs. Your hook, and code writing with actor: null, may still set it. An audit.note field must itself be readonly.
  • A locked record is deleted only by the server's own work. A person, the assistant and code with nobody said are refused the delete of a record its lock holds, of a record its parent locks (parentLock), and of a parent that locks others. Code that must remove one (an erasure request, a submission made by mistake) does it inside asSystem, behind a check of your own for who may ask. See Security.
  • beforeDelete is a new hook: throw in it to refuse a delete.

Role access#

access on a role, access.default and assistant.deny narrow what people and the assistant reach (Roles). Without any of them nobody's reach changes, and roles still decide only what Home and the sidebar show. Once the config has one:

  • Your own code runs with the role access of the teammate it runs for. A hook, a handler, a run target, a crmHandler or an apiRoute reads and writes through @swirls/spools/extensions as that person: an object their roles deny is not found, and a change to one they only read is refused. A hook that writes an object the person who caused it is kept from (an office-only ledger line when a designer closes a job) now fails until that write is inside asSystem (Hooks and role access):

    ts
    import { asSystem, createRecord } from '@swirls/spools/extensions'await asSystem(() => createRecord('ledger', { jobId: record.id, amount }, actor))
  • A read-only object changes nothing of what hangs off its records. Someone who only reads jobs adds no note, task or logged call to one, completes no task on one, sends it no email, starts no action or sequence for it, and adds, renames, moves or deletes no file in its folder or a folder inside it. A role with "readOnly": true changes nothing in the file library, shared views, Marketing or shared connections either. Your own code's addActivity, createTask and createNote keep to the same for the teammate it runs for: wrap the server's own bookkeeping in asSystem. A file is opened or changed through the folder it is in (the file browser's links carry it) for anyone role access keeps something from; a link of your own to /api/files/<id> adds ?folder=<the folder's id>.

  • asSystem lifts role access as well as record scopes. Code already inside it reaches every object. Keep its uses few, and never hand what it read to someone it is kept from.

  • Code with nobody behind it holds no role. A cron route, a script, a publicRoute and the config's automations are not narrowed, and access.default does not apply to them.

  • Timeline lines stop naming records of a denied object. A change to a relation that leads to an object any role, access.default or assistant.deny keeps from someone is written "updated Client", for everyone who reads the record. Lines written before are not changed until you run bunx spools timeline redact, once, after adding the first deny. It can't fix a line written under a label the field no longer has, nor a title in a note, an email or a line your own code wrote (Roles).

  • The assistant is not narrowed by roles. Name the objects it must never reach in assistant.deny.

Live updates#

Off until "live": { "seconds": 20 } is in the config (Live updates). Pages call one new server function (changedSinceFn), which needs no route file.

Your own door#

Endpoints for people who are not teammates are built from helpers in @swirls/spools/extensions, behind publicRoute (Building your own door). Three things to set where it runs (Deployment): TRUST_PROXY, your front end's origins for verifyToken, and CLERK_JWT_KEY with clerk(). apiRoute(name, answer, { idempotency: {} }) gives a teammate's endpoint the same once-only writes.

If you built on this version before it was released, four things changed on the way:

  • callerAddress(headers) answers null when the address can't be known (TRUST_PROXY unset or mistyped). There is no shared stand-in value. Skip the address limit for null, or refuse: never count a limit under it.
  • idempotent takes only a caller made with verifiedCaller(namespace, ...verifiedIds).
  • A rate limiter of your own implements consume and wait beside hit and record.
  • A person who could delete a record under its own lock no longer can (above).

Record scopes#

A Spool without scopes in crm.config.json needs the schema change and nothing more (bun run crm:gen, bun run db:push): seven system tables gain a scope column that stays empty. Before you add scopes, and each time you change it:

  • Run bun run db:scopes after every change to scopes.objects, not only the first time. It gives the rows that hang off records (timeline, tasks, notes, favourites, folders, uploads, sequence runs) their record's scope, where they have none or carry one from before the change. Until it has run, rows on a newly scoped object's records are only there for a role with all, and their sequence runs are held. A server that stays up says at start-up when rows are waiting. See Security.
  • Code with nobody signed in changes no record until it says it is the system. With scopes on, a script, a webhook or an endpoint of your own that creates or changes records with nobody behind it is refused, for a shared object's records too. Wrap the work in asSystem from @swirls/spools/extensions.
  • A workflow's write-back binds your hooks to its record. With scopes on, a hook or an automation's handler set off by a tool call made under a grant reaches, through @swirls/spools/extensions, the one record the grant was made for. One that lists or creates other records there needs asSystem. See Extending.
  • Remove links that cross scopes. A relations field between two scoped objects may hold links made before scopes were on that join records of two scopes. They are left as they are and shown only to someone who holds both, and such a record can't move scope or be deleted by someone who holds one. Unlink them as head office.
  • Send the grant back. Workflows that write through the tool API send the grant from their input as the X-Spools-Grant header. See Swirls.
  • Name the scopes there are. A scope a person holds counts only when it is one of this Spool's: an option of the scope field where that is a select, and otherwise one the resolver lists. With Clerk organizations, name the ones that are scopes with clerk({ scopes: 'organizations', scopesFrom: ['org_...'] }); without it no organization is a scope. A resolver of your own needs list where a scope field is text or a relation. The server says at start-up when nothing is listed. See Signing in.
  • Someone who can change no record changes nothing else. With scopes on, a read-only person and someone who holds no scope read Marketing and Integrations and are refused every change there: posts, the website's check and profile, ad results, and the accounts the team shares. If the people who run your marketing hold no scope, give them one with a role that writes.
  • Change a scope field with the server stopped. If you move an object's scope to another field, run bun run db:scopes before anyone signs in again: until it has run, rows on a record are still read by the scope the old field gave them.

For code of yours that imported the server's modules: what sendEmailFn does is now sendRecordEmail in @swirls/spools/server/workspace, and a store method can fail with ScopeRefused beside DatabaseError.

From a copy of the repository#

Before Spools was a package, a CRM was a copy of the whole repository that merged updates from it. Moving one over changes no data: the tables are the same, column for column, and crm.config.json and every environment variable keep their names.

  1. Make a Spool in a folder of its own with bun create @swirls/spools, and copy what is yours over it: crm.config.json, src/app, src/styles.css, swirls, migrations, .env, vercel.json if you changed it, and any pages you added to src/routes. Keep your repository's history by doing this on a branch of it.

  2. Say what it runs on in src/spool.server.ts. These are the services a copy used, so nothing behaves differently:

    ts
    export default defineSpool({  crm,  extensions,  auth: clerk(),  database: prisma({ contract }),  files: flashdrive(),  email: resend(),  vault: cipherstash(),  agents: swirls(),})
  3. Change your imports. In src/app/extensions.ts, '../crm/extensions' and '../server/extension-api' are both '@swirls/spools/extensions'.

  4. Change your own server code that used the database: it asks for Store instead of Database (Database). AuthError replaces ClerkError and AgentsError replaces SwirlsError.

  5. Find a home for changes you made to the framework. Most fit an extension point: hooks, handlers, pages, or an adapter. Open an issue for one that doesn't.

  6. Run bun run crm:gen and bun run check. crm:gen should leave prisma/schema.json exactly as it was, which is how you know the database needs no change.

The Resend webhook keeps its address: /api/webhooks/resend is now the same as /api/webhooks/email. The stubbed-sign-in harness reads DEV_AUTH_EMAIL and DEV_AUTH_SIGNED_OUT where it read E2E_EMAIL and E2E_SIGNED_OUT.

On a host with no long-lived process other than Vercel, set SERVERLESS=1. Vercel is still worked out from the host. Its build is now vercel() from @swirls/spools/vite in vite.config.ts, where a copy carried its own Nitro plugin.