@kodentuzo/spotkit
v0.5.0
Published
Connect an app to its slots, in production and on your machine: who the user is, accounts, the legal facts, counting visits, and the spotkit command
Maintainers
Readme
Spotkit
Connect an app to its slots, in production and on your machine.
State: the library and the CLI (spotkit dev, spotkit new) are at 0.5.0, the release
on npm.
Every Spotcraft instance runs eight slots, always: accounts, analytics, mail, legal, registry, backups, monitoring and sync. Spotkit is the app's side of them, in two parts:
- the library, in each app. By default it talks only to
/_spotcraft/*on the app's own domain; - the CLI, on your machine.
spotkit devruns the same slots locally.
An app that uses Spotkit writes no auth, privacy or analytics plumbing of its own. Spotkit is optional: it only wraps what the slots' contracts say, so an app can do the same by hand.
What it does
- Knows the user:
kit.user(request)returns the user behind a request, checked against theaccountsslot's keys (Spotpass), with one call per session. - Accounts:
signUp,signIn,signOut,verifyEmail,requestPasswordReset,resetPasswordandtwoFactorcall the matching Spotpass 0.2 routes, and each service's base URL is an option (authUrl,legalUrl,analyticsUrl), so an app can use the services without Spotcraft. - Nothing stored before an explicit action: storage is off by default, behind one Spotkit
switch (
storageSwitch). No cookie, no guest account and nothing on the device until the app turns it on, at the moment the person does something that asks for it, such as "Continue as guest" (the entry screen also offers "Sign in"). Until thensignUp()andsignIn()refuse. On the next visit the session cookie shows the switch was on (the contract). - Feeds the legal pages:
legalFacts()on the server andlegal()in the browser return who runs the app and what it processes (Spotliance), so no owner's details are committed. - Gives users their data:
exportMe()anddeleteMe()for the server's side, andlocalData()for what the browser keeps. A delete reaches every app on the instance. - Counts visits, one way:
analytics()loads theanalyticsslot's script (Spotless) and refuses event data that could identify someone. There is no consent and no opt-out, since nothing is stored on the device, and no app has a setting to switch counting off: an app is counted once it loads the script. - Reads the wiring:
config()returns where each of the eight slots answers. - The CLI:
spotkit devandspotkit new, moved here from Spotcraft'sspotcraftcommand.spotkit devruns Postgres, Spotpass and Mailpit locally, with small stand-ins foranalyticsandlegal. It readsspotkit.json, which replacesspotcraft.json. - Small helpers: the client's address behind the proxy, and a health endpoint.
Offline-first apps follow one recipe, with the server as the authority: docs/offline-first.md. Spotkit covers the user's rights over the data, and doesn't wrap the recipe itself.
How to swap it
Spotkit is a convenience, never something the platform needs. Call the slots' contracts by hand, or use another library; Spotcraft doesn't know which. An app can also skip a slot and call something else (say, Clerk for accounts); the slot stays, unused.
Use
npm install @kodentuzo/spotkitimport { spotkit } from '@kodentuzo/spotkit'
const kit = spotkit() // reads AUTH_URL, AUTH_ISSUER and AUTH_JWKS_URL
const user = await kit.user(request) // { id, isAnonymous } or nullOn your machine, pnpm exec spotkit dev starts the slots (it needs Docker) and fills .env.
The full guide is in docs/guide.md.
How it's built
- Two entry points: one for the server (one dependency,
jose) and one for the browser with no dependencies and no Node APIs. The CLI's own dependency,pg, is only loaded byspotkit. WebRequest,ResponseandHeadersonly, so it fits any framework. There are no framework adapters. - Contract first: it only wraps what the slots' contracts say. Its own contract is its types,
the paths it uses and
spotkit.json: docs/contract.md. - Published with provenance from CI with npm trusted publishing; no tokens stored.
Stack: TypeScript, Web APIs, jose, pg (CLI), Node's test runner, Biome, GitHub Actions. Used by
Sokobanko and Spotstrap's blocks. Spotstrap 0.4 needs
Spotkit 0.5 (^0.5.0), and the two ship in the same step.
Links
- The contract: what Spotkit exports, the paths it uses,
spotkit.json, andspotkit.jsonand the CLI. - Docs: the guide, offline-first apps, the CLI, architecture, development, decisions.
- Changelog.
- npm: @kodentuzo/spotkit.
- Spotkit on kodentuzo.com.
- Part of Kodentuzo.
