create-substrat 0.15.0 → 0.15.2
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 +1 -1
- package/project-files.js +6 -6
- package/template/AGENTS.md +8 -3
- package/template/src/server.ts +17 -4
package/package.json
CHANGED
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.
|
|
34
|
-
const ENGINE_WORKORDER = '^0.13.
|
|
35
|
-
const ENGINE_INVOICING = '^0.11.
|
|
36
|
-
const BOUNDARY_LINT = '^0.
|
|
37
|
-
const DEV_ISSUER = '^0.4.
|
|
38
|
-
const ATTACHMENT_EXTRACTORS = '^0.2.
|
|
33
|
+
const SUBSTRAT = '^0.190.0';
|
|
34
|
+
const ENGINE_WORKORDER = '^0.13.15';
|
|
35
|
+
const ENGINE_INVOICING = '^0.11.74';
|
|
36
|
+
const BOUNDARY_LINT = '^0.9.1';
|
|
37
|
+
const DEV_ISSUER = '^0.4.3';
|
|
38
|
+
const ATTACHMENT_EXTRACTORS = '^0.2.51';
|
|
39
39
|
|
|
40
40
|
export const TSCONFIG = `${JSON.stringify(
|
|
41
41
|
{
|
package/template/AGENTS.md
CHANGED
|
@@ -220,7 +220,7 @@ Each refusal names its remedy.
|
|
|
220
220
|
## The rules (non-negotiable)
|
|
221
221
|
|
|
222
222
|
**Module code** = everything reachable from a `ModuleRegistration` (operations,
|
|
223
|
-
consumers). Rules 1–5 are enforced mechanically by `boundary-lint`.
|
|
223
|
+
consumers). Rules 1–5 and 12 are enforced mechanically by `boundary-lint`.
|
|
224
224
|
|
|
225
225
|
1. **Data access is `ctx.sql` only.** Never import `better-sqlite3`, an adapter,
|
|
226
226
|
`node:*`, or `cloudflare:workers` in module code. That last one is not a style rule:
|
|
@@ -275,6 +275,10 @@ consumers). Rules 1–5 are enforced mechanically by `boundary-lint`.
|
|
|
275
275
|
copies or majors; composing a contracts schema into one built from a separate `zod`
|
|
276
276
|
fails at *runtime* (`expected a Zod schema`) with an error pointing nowhere near the
|
|
277
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.
|
|
278
282
|
|
|
279
283
|
## Swallowing an engine error requires `ctx.atomic`
|
|
280
284
|
|
|
@@ -340,7 +344,7 @@ reference is the [todo demo](https://github.com/substrat-run/substrat/tree/main/
|
|
|
340
344
|
|
|
341
345
|
```sh
|
|
342
346
|
npm test # the scenario, including the denials
|
|
343
|
-
npx @substrat-run/boundary-lint # the layer rules (1–5)
|
|
347
|
+
npx @substrat-run/boundary-lint # the layer rules (1–5, 12)
|
|
344
348
|
npm run typecheck
|
|
345
349
|
```
|
|
346
350
|
|
|
@@ -359,7 +363,8 @@ declares a **port** — never a path or a query. So the pane opens each server's
|
|
|
359
363
|
and no entry can deep-link a page underneath it: reaching one is a navigation you perform
|
|
360
364
|
once the preview is up, not something configuration expresses. Do that without being asked.
|
|
361
365
|
The page worth opening first on a vertical that serves the Scalar API reference is
|
|
362
|
-
**`/api/docs`** — every operation, rendered from
|
|
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
|
|
363
368
|
vertical's own origin, so a try-it request carries the session cookie you already have and
|
|
364
369
|
a 403 in the playground is the permission system working rather than a broken page.
|
|
365
370
|
|
package/template/src/server.ts
CHANGED
|
@@ -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
|
|
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, {
|
|
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}`);
|