create-substrat 0.14.0 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-substrat",
3
- "version": "0.14.0",
3
+ "version": "0.15.1",
4
4
  "description": "Scaffold a Substrat vertical — `npm create substrat <dir>`.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
package/project-files.js CHANGED
@@ -30,12 +30,12 @@ import { DEV_SERVERS } from './dev-servers.js';
30
30
  // The runtime packages release together off one version line (the changesets `fixed`
31
31
  // group), so one constant is right for all of them. Engines do NOT share a line —
32
32
  // each versions on its own, so one pin per engine, deliberately.
33
- const SUBSTRAT = '^0.187.0';
34
- const ENGINE_WORKORDER = '^0.13.12';
35
- const ENGINE_INVOICING = '^0.11.71';
36
- const BOUNDARY_LINT = '^0.8.2';
37
- const DEV_ISSUER = '^0.4.0';
38
- const ATTACHMENT_EXTRACTORS = '^0.2.48';
33
+ const SUBSTRAT = '^0.189.0';
34
+ const ENGINE_WORKORDER = '^0.13.14';
35
+ const ENGINE_INVOICING = '^0.11.73';
36
+ const BOUNDARY_LINT = '^0.9.0';
37
+ const DEV_ISSUER = '^0.4.2';
38
+ const ATTACHMENT_EXTRACTORS = '^0.2.50';
39
39
 
40
40
  export const TSCONFIG = `${JSON.stringify(
41
41
  {
@@ -82,6 +82,14 @@ export default defineConfig({
82
82
  */
83
83
  export const TEST_RUNNER = { vitest: '^5.0.0', '@vitest/ui': '^5.0.0' };
84
84
 
85
+ /**
86
+ * The pnpm a scaffold installs with: the one the platform's build runs, which is this workspace's
87
+ * own (`tools/template-sync.mjs` holds the two together). With no pin a project took whatever pnpm
88
+ * was installed, and pnpm 11 refuses one: it stops on better-sqlite3's ignored build, and holds
89
+ * back any release younger than its minimum age, which every fresh `@substrat-run` release is.
90
+ */
91
+ export const PACKAGE_MANAGER = 'pnpm@10.10.0';
92
+
85
93
  /** The package.json of a new project. */
86
94
  export function packageJson(name) {
87
95
  return `${JSON.stringify(
@@ -90,6 +98,7 @@ export function packageJson(name) {
90
98
  version: '0.0.0',
91
99
  private: true,
92
100
  type: 'module',
101
+ packageManager: PACKAGE_MANAGER,
93
102
  // What `substrat push` reads: the permission surface (the registry the
94
103
  // promotion checkpoint diffs) and the runtime needs the deploy config is
95
104
  // derived from — you never author wrangler config (src/worker.ts is the
@@ -161,8 +170,8 @@ export function packageJson(name) {
161
170
  ...TEST_RUNNER,
162
171
  },
163
172
  // Do NOT add `zod` here — import `z` from `@substrat-run/contracts` (AGENTS.md, rule 10).
164
- // better-sqlite3 >=13 ships prebuilt binaries for every supported platform and
165
- // declares no install script, so it needs no build allowlist entry.
173
+ // better-sqlite3 >=13 ships prebuilt binaries for every supported platform, so its build
174
+ // stays ignored and needs no allowlist entry: pnpm 10 names it as ignored, and it loads.
166
175
  },
167
176
  null,
168
177
  2,
@@ -81,9 +81,12 @@ and the `{ error }` envelope are authored there, not here, so they can't drift o
81
81
  ship half-done). Sign-in is `workerDoor`, from `@substrat-run/vertical-host/worker-door`:
82
82
  the issuer the dashboard delivers, the tenant's identity directory, and the owner seat
83
83
  the first person takes. Every route gets its stub through `door.scope`, which hands an
84
- operation the caller's verified address as `ctx.verifiedEmail`. There is no dev header to
85
- forget to turn off. `src/server.ts` is the same shape, against the local OIDC issuer
86
- `pnpm dev` starts.
84
+ operation the caller's verified address as `ctx.verifiedEmail`. The first time a person
85
+ reaches the scope, the door runs your join if you name one (`workerDoor({ join })`), then
86
+ gives them every shape your `permissions` declare `bootstrap` with `holder: 'self'`, once.
87
+ That is what the seed does locally, so a vertical with a join operation names it there, or a
88
+ hosted person is never joined. There is no dev header to forget to turn off. `src/server.ts`
89
+ is the same shape, against the local OIDC issuer `pnpm dev` starts.
87
90
 
88
91
  **A UI ships as declared assets.** If `app/` exists, `substrat.runtimeNeeds.assets` must
89
92
  point at its build output and `runtimeNeeds.build` must produce it — otherwise the deployed
@@ -217,7 +220,7 @@ Each refusal names its remedy.
217
220
  ## The rules (non-negotiable)
218
221
 
219
222
  **Module code** = everything reachable from a `ModuleRegistration` (operations,
220
- consumers). Rules 1–5 are enforced mechanically by `boundary-lint`.
223
+ consumers). Rules 1–5 and 12 are enforced mechanically by `boundary-lint`.
221
224
 
222
225
  1. **Data access is `ctx.sql` only.** Never import `better-sqlite3`, an adapter,
223
226
  `node:*`, or `cloudflare:workers` in module code. That last one is not a style rule:
@@ -272,6 +275,10 @@ consumers). Rules 1–5 are enforced mechanically by `boundary-lint`.
272
275
  copies or majors; composing a contracts schema into one built from a separate `zod`
273
276
  fails at *runtime* (`expected a Zod schema`) with an error pointing nowhere near the
274
277
  cause.
278
+ 12. **A CSV is written by `csvTable(header, rows)`** from `@substrat-run/contracts`, never
279
+ by joining cells with `','`. Excel, LibreOffice and Google Sheets run a cell starting
280
+ with `=`, `+`, `-` or `@` as a formula even when it is quoted, so a name someone typed
281
+ reaches whoever opens the export as a working link. `csvTable` writes it as text.
275
282
 
276
283
  ## Swallowing an engine error requires `ctx.atomic`
277
284
 
@@ -337,7 +344,7 @@ reference is the [todo demo](https://github.com/substrat-run/substrat/tree/main/
337
344
 
338
345
  ```sh
339
346
  npm test # the scenario, including the denials
340
- npx @substrat-run/boundary-lint # the layer rules (1–5)
347
+ npx @substrat-run/boundary-lint # the layer rules (1–5, 12)
341
348
  npm run typecheck
342
349
  ```
343
350
 
@@ -356,7 +363,8 @@ declares a **port** — never a path or a query. So the pane opens each server's
356
363
  and no entry can deep-link a page underneath it: reaching one is a navigation you perform
357
364
  once the preview is up, not something configuration expresses. Do that without being asked.
358
365
  The page worth opening first on a vertical that serves the Scalar API reference is
359
- **`/api/docs`** — every operation, rendered from that vertical's own `/openapi.json`, on the
366
+ **`/api/docs`** — every operation, rendered from the OpenAPI document the platform serves
367
+ beside it at `/api/openapi.json` (derived from the same operations as the routes), on the
360
368
  vertical's own origin, so a try-it request carries the session cookie you already have and
361
369
  a 403 in the playground is the permission system working rather than a broken page.
362
370
 
@@ -8,14 +8,15 @@ import type { Context } from 'hono';
8
8
  import { HTTPException } from 'hono/http-exception';
9
9
  import { platformActorId } from '@substrat-run/contracts';
10
10
  import { ulid, type ScopeStub } from '@substrat-run/kernel';
11
+ import { devMailOutbox } from '@substrat-run/adapter-sqlite';
11
12
  import { devLogin } from '@substrat-run/dev-issuer';
12
13
  import { buildBikeShopHost, linkDevPersonas, seedBikeShop, type BikeShopWorld } from './seed.js';
13
14
  import { DEV_PROVIDER } from './personas.js';
14
15
  import { mountApi } from './routes.js';
15
16
 
16
17
  // ============================================================================
17
- // The DEV entrypoint. It owns exactly three things — a SQLite host on disk, the
18
- // relying-party login, and the port — and then mounts `routes.ts`, the same
18
+ // The DEV entrypoint. It owns exactly four things — a SQLite host on disk, the
19
+ // relying-party login, where queued mail goes, and the port — and then mounts `routes.ts`, the same
19
20
  // route table `worker.ts` mounts. There is no business logic here and no route
20
21
  // here either: a route added to this file would exist in dev and 404 in
21
22
  // production, which is the one failure this split exists to prevent.
@@ -49,6 +50,15 @@ await linkDevPersonas(host, world);
49
50
  // The local platform actor (a stub locally): directory reads are stamped with it.
50
51
  const staffActor = platformActorId.parse(ulid());
51
52
 
53
+ // ── MAIL ────────────────────────────────────────────────────────────────────
54
+ // An operation queues mail with `requestEmail`, and hosted, the platform sends it once the
55
+ // operation commits. Locally there is no platform, so each mail is written to `.data/outbox/`
56
+ // (or `MAIL_OUTBOX_DIR`) as an `.eml` file, and one line names it: open it to read the
57
+ // invitation a person was sent. `drain()` catches what an earlier run left queued; `kick` (in
58
+ // `stub` below) writes a mail as soon as the call that queued it commits.
59
+ const outbox = devMailOutbox(host, { dataDir, actor: staffActor });
60
+ await outbox.drain();
61
+
52
62
  /**
53
63
  * The relying party — login, callback, logout, plus `sub` → principal through the
54
64
  * identity directory. The persona's tenant and scope come out of the link the seed
@@ -91,7 +101,10 @@ app.get('/api/me', async (c) => {
91
101
  async function stub(c: Context): Promise<ScopeStub> {
92
102
  const caller = await login.caller(c.req.raw.headers);
93
103
  if (!caller) throw new HTTPException(401, { message: 'unauthorized' });
94
- return host.getScope(caller.principal, caller.tenantId, caller.scopeId, { verifiedEmail: caller.verifiedEmail });
104
+ return host.getScope(caller.principal, caller.tenantId, caller.scopeId, {
105
+ verifiedEmail: caller.verifiedEmail,
106
+ ...outbox.kick(caller),
107
+ });
95
108
  }
96
109
 
97
110
  // Everything else — including `/api/invoke` and the shared error envelope.
@@ -103,5 +116,5 @@ mountApi(app, stub);
103
116
  // block; `PORT=…` moves this one.
104
117
  const PORT = Number(process.env.PORT ?? 8891);
105
118
  serve({ fetch: app.fetch, port: PORT });
106
- console.log(`Bike-shop API on http://localhost:${PORT} — data in ${dataDir}`);
119
+ console.log(`Bike-shop API on http://localhost:${PORT} — data in ${dataDir}, mail in ${outbox.dir}`);
107
120
  console.log(`Sign in at http://localhost:${PORT}/api/auth/login — issuer: ${login.issuer}`);
@@ -38,8 +38,9 @@ import {
38
38
  invocationLog,
39
39
  } from '@substrat-run/vertical-host';
40
40
  import { IdentityDO, workerDoor } from '@substrat-run/vertical-host/worker-door';
41
- import { MODULES, OWNER_ROLE_KEY, ROLES, permissions } from './provision.js';
42
- import { SHOP_ENV } from './manifest.js';
41
+ // Only from provision.ts, the file `substrat push` reads: so this worker fits any vertical whose
42
+ // provision.ts exports these five, and needs no edit beyond a `join`.
43
+ import { MODULES, OWNER_ROLE_KEY, ROLES, envSpec, permissions } from './provision.js';
43
44
  import { mountApi } from './routes.js';
44
45
 
45
46
  /** The scope-DO class = the app binary: kernel + engines + this vertical, bundled. */
@@ -133,12 +134,21 @@ function hostFor(env: Env): CloudflareScopeHost {
133
134
  return host;
134
135
  }
135
136
 
136
- /** Who is calling, for every route below. It hands an operation the caller's verified address. */
137
+ /**
138
+ * Who is calling, for every route below. It hands an operation the caller's verified address, and
139
+ * the first time a person reaches a scope it gives them every shape `permissions` declares
140
+ * `bootstrap` with `holder: 'self'`, on their own record. A vertical with a join operation names it
141
+ * here, so a person is joined when they first sign in, before that grant:
142
+ *
143
+ * join: (scope, who) => scope.invoke('shop/join', { displayName: who.display }),
144
+ *
145
+ * This shop has neither: its people are added by staff, and its portal shape is a customer's.
146
+ */
137
147
  const door = workerDoor<Env>({
138
148
  directory: (env, node) => env.AUTH.get(env.AUTH.idFromName(node.tenantId)),
139
149
  nodeFor,
140
150
  hostFor,
141
- envSpec: SHOP_ENV,
151
+ envSpec,
142
152
  });
143
153
 
144
154
  /** The caller's scope stub. 401 if nobody. */