API reference
The package's entry points. Anything that isn't listed here is internal and may change in a patch release. The types are the reference for each function: your editor shows them, and the links lead to the source.
Your Spool#
| Import | Exports |
|---|---|
@swirls/spools |
defineSpool, and the types Spool and SpoolOptions |
@swirls/spools/extensions |
defineExtensions, and the framework's functions as promises, for hooks, handlers and your own endpoints. See below |
@swirls/spools/handlers |
Handlers for your own server functions and endpoints. See below |
@swirls/spools/module |
What a module is written with: defineModule, defineModuleSettings, moduleTable, and table, the column helpers |
@swirls/spools/ui/slots |
The browser half of modules: defineSpoolUi, defineModuleUi, SpoolUiProvider, for src/spool.ui.ts and src/routes/__root.tsx |
@swirls/spools/oxlint |
Lint rules that refuse a server function or endpoint without a handler |
@swirls/spools/config-schema |
The config's schema, for checking a crm.config.json |
@swirls/spools/server |
serveSpool, for src/server.ts |
@swirls/spools/server/* |
The server's own modules, for code written with Effect. See Writing server code |
@swirls/spools/start |
The request middleware, for src/start.ts |
@swirls/spools/vite |
vercel, the Vercel build, for vite.config.ts |
@swirls/spools/testing |
What tests use: run, failure, installStandIns, createFakeStore, and the Tokens and RateLimiter stand-ins |
@swirls/spools/theme.css |
The styles, for src/styles.css |
defineSpool takes:
| Option | Type | |
|---|---|---|
crm |
the config | Required. The contents of crm.config.json |
extensions |
Extensions |
Your hooks and handlers |
auth |
AuthAdapter |
Required. See Signing in |
database |
StoreAdapter |
Required. See Database |
files |
FilesAdapter |
Without it, the Files pages say files aren't set up |
email |
EmailAdapter |
Without it, emails are logged |
vault |
VaultAdapter |
Without it, no outside tokens are stored |
agents |
AgentsAdapter |
Without it, workflows are skipped and the assistant is off |
rateLimits |
RateLimitAdapter |
Without it, rate limits are counted in memory, per instance |
modules |
SpoolModule[] |
The modules it uses, in order: their hooks run in that order, then yours |
overrides |
paths | What your app replaces of a module's part, by path. See Modules |
@swirls/spools/extensions#
What src/app/extensions.ts, a module's server code and your own endpoints import. Each
function returns a promise and runs with the access of whoever the code runs for:
record scopes and role access apply,
and asSystem lifts both. The source is
packages/spools/src/server/extension-api.ts.
| For | Exports |
|---|---|
| The contract | defineExtensions, and the types Extensions, Hooks, Actor, RunContext, RunResult, RunTargetHandler, PostNetwork, AdNetwork |
| Records | createRecord, updateRecord, deleteRecord, getRecord, listRecords, countMatching. Writes run hooks, the timeline and automations |
| The timeline, tasks, notes | addActivity, listActivities, listTasks, createTask, updateTask, deleteTask, listNotes, createNote |
| Server-kept fields | writeKeptFields: writes readonly fields with no timeline line, hooks or automations. See Extending |
| Whose work it is | asSystem: runs your code as the server itself. runServer, for a program written with Effect |
| People and connections | listCrmUsers, findConnections, getAccessToken. See Integrations |
| Files | filesConfigured, recordFolder, shareRecordFolder. See Files |
| Run targets | runTarget |
| A module's tables | moduleTables: find, first, count, insert, update, remove. See Modules |
| Live updates | changedSince(keys, token?) for whoever the code runs for, and changedSinceAs(keys, token, mayRead) with a check of your own |
| An outside caller | bearerToken(headers), verifyToken(token, { authorizedParties }), callerAddress(headers) (null when it can't be known), trustedHops |
| Once-only writes | idempotent(request, { caller, keepFor?, bodyLimit? }, work), verifiedCaller(namespace, ...verifiedIds), isVerifiedCaller |
| Rate limits | hitLimit(bucket, key, limit), peekLimit(bucket, key, limit), consumeLimit(bucket, key, amount, limit), where limit is { max, windowMs } |
| Your own secrets | sealText(text, owner), openText(sealed, owner), vaultProblem(). See Adapters |
The last five rows are what an endpoint for people who are not teammates is built from. See Building your own door.
Handlers#
@swirls/spools/handlers has one for each kind of server function and endpoint. Each checks
who is asking before your code runs.
| Handler | Who it answers |
|---|---|
crmHandler(name, answer) |
A server function, for signed-in teammates on the access list |
apiRoute(name, answer, options?) |
An endpoint, for the same people. With { idempotency: {} }, a write sent with an Idempotency-Key runs once |
cronRoute(name, answer, options?) |
A scheduled job's endpoint: needs CRON_SECRET, and answers 504 after limit |
publicHandler(name, answer) |
A server function that answers anyone |
publicRoute(name, answer) |
An endpoint that answers anyone: a webhook, or your own door. Your code checks who is calling |
See Pages and endpoints of your own.
Adapters#
| Import | Exports |
|---|---|
@swirls/spools/auth/clerk |
clerk |
@swirls/spools/auth/better-auth |
betterAuth |
@swirls/spools/auth/dev |
devAuth |
@swirls/spools/auth/<name>/ui |
The browser half of each, for src/spool.ui.ts |
@swirls/spools/database/postgres |
postgres |
@swirls/spools/database/pglite |
pglite |
@swirls/spools/database/prisma |
prisma |
@swirls/spools/files/drive |
drive, localBlobs, s3Blobs |
@swirls/spools/files/flashdrive |
flashdrive |
@swirls/spools/email/resend |
resend |
@swirls/spools/vault/aes |
aes |
@swirls/spools/vault/cipherstash |
cipherstash |
@swirls/spools/agents/swirls |
swirls |
@swirls/spools/rate-limits/memory |
memoryRateLimits |
@swirls/spools/rate-limits/store |
storeRateLimits |
Adapters lists the packages and variables each needs.
Writing an adapter#
@swirls/spools/adapter has the ports, types, and helpers
an adapter is made from. Write your own has worked examples.
| Port | Provides | Adapter type |
|---|---|---|
Auth |
The people on the team and the accounts they sign in with | AuthAdapter |
Store |
Reading and writing tables | StoreAdapter |
FileStore |
Folders, files, uploads, and downloads | FilesAdapter |
Email |
Sending, and reports of delivery | EmailAdapter |
Vault |
Sealing and opening tokens | VaultAdapter |
Agents |
Running workflows and the assistant | AgentsAdapter |
RateLimiter |
Counting requests in a sliding window, and quotas in a fixed one (hitLimit, peekLimit, consumeLimit) |
RateLimitAdapter |
Tokens |
Checking a token your front end forwards (verifyToken) |
tokens on an AuthAdapter |
Pages and endpoints#
Each route file in src/routes mounts one of these:
import { createFileRoute } from '@tanstack/react-router'import { tasksPage } from '@swirls/spools/pages/tasks'export const Route = createFileRoute('/_crm/tasks')(tasksPage)
| Import | What it is |
|---|---|
@swirls/spools/pages/* |
Route options for each page: home, list, record, tasks, notes, files, reports, workflows, integrations, marketing, team, assistant, custom, sign-in, unsubscribe, and the layout around them |
@swirls/spools/api/* |
Handlers for each endpoint under /api |
@swirls/spools/ui/* |
The interface's own components, for pages you write, and ui/slots for modules, and defineLayoutComponent for layouts |
The spools command#
Run in a Spool's folder. The scripts in package.json call it for you.
| Command | What it does |
|---|---|
spools gen |
Checks crm.config.json, with the modules' parts in it, and regenerates prisma/schema.prisma and crm.config.schema.json, then emits Prisma's contract (--no-emit leaves that step out) |
spools init |
First run: names the CRM, sets who may use it, writes .env with fresh secrets |
spools harden |
Takes Supabase's Data API roles off the tables, and fails if row-level security is off anywhere |
spools stats |
Recomputes the last activity, last contact, and next task dates on every record |
spools scopes backfill |
Gives the rows that hang off records their record's scope. Run after every change to scopes.objects. See Security |
spools modules |
Lists what each module adds and the route files they expect. Exits 1 while one is missing, printing what to put in it |
spools rules [object] |
Lists the records that already break a unique rule, by id. Exits 1 while any do. Run before db:push or db:plan. See Database |
spools timeline redact |
Rewrites old timeline lines that name records of an object someone is now kept from. See Roles |
spools ui check |
Says what is wrong with each layout (ui in the config). Exits 1 when one will not draw; --strict also refuses a component the kit hasn't. See Layouts |
spools ui prompt |
Prints what a coding agent needs to write a layout: the language, the kit, the tools, and this Spool's objects and fields |
spools check-client |
Fails if Effect, which server code runs on, reached the browser bundle |
A new Spool's package.json has a script for most of them: crm:gen, init, db:harden,
db:stats, db:scopes, db:rules. bun run build ends with spools check-client.
check-client reads dist/client, and .vercel/output/static after a Vercel build. To
check another folder, name it: spools check-client build/public.