@starci/hfs 4.11.11 → 4.11.13
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/CHANGELOG.md +19 -0
- package/README.md +1 -1
- package/package.json +1 -1
- package/release/index.mjs +2 -2
- package/runtime/knowledge/hfs/canon-pins.yaml +6 -6
- package/runtime/knowledge/hfs/rules.yaml +1 -1
- package/runtime/modules/kernel/failure-codes.yaml +5 -5
- package/runtime/scripts/api/sops/lib.mjs +25 -3
- package/runtime/scripts/api/sops/seal.mjs +4 -3
- package/runtime/scripts/hfs/path-findings.mjs +4 -2
- package/runtime/scripts/hfs/secret-init.mjs +15 -0
- package/runtime/scripts/hfs/secret-sops.mjs +65 -33
- package/runtime/scripts/lib/sops-envelope.mjs +36 -11
- package/scaffold/add-inbox-lite.mjs +6 -10
- package/scaffold/add-queue-lite.mjs +7 -2
- package/scaffold/add-table.mjs +5 -0
- package/scaffold/app.mjs +15 -3
- package/scaffold/lite-exports.mjs +23 -0
- package/src/main.mjs +3 -3
- package/stack/age-install.mjs +10 -2
- package/stack/context.mjs +2 -2
- package/stack/remote.mjs +29 -8
- package/stack/sealed.mjs +15 -11
- package/stack/server-key.mjs +31 -7
- package/templates/app/ci-workflows/github/workflows/stack-key-restore.yml +1 -1
- package/templates/app/ci-workflows-lite/github/workflows/stack-key-restore.yml +1 -1
- package/templates/be/skeleton-lite/src/modules/platform/database/database.options.ts +4 -1
- package/templates/be/skeleton-lite/src/modules/platform/database/entities.ts +4 -1
- package/templates/be/skeleton-lite/src/modules/platform/database/index.ts +0 -2
- package/templates/be/skeleton-lite/src/modules/platform/http-security/index.ts +1 -0
- package/templates/be/skeleton-lite/src/modules/platform/http-security/persistence/entities/index.ts +4 -0
- package/templates/be/skeleton-lite/src/modules/platform/http-security/persistence/entities/rate-window.entity.ts +17 -0
- package/templates/be/skeleton-lite/src/modules/platform/http-security/rate-limit.guard.spec.ts +260 -0
- package/templates/be/skeleton-lite/src/modules/platform/http-security/rate-limit.guard.ts +133 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.11.13 - 2026-10-29
|
|
4
|
+
|
|
5
|
+
- Fixed: a member sealed to an environment's whole recipient set (the owner key and the deploy server key, the production standard after `server-key --execute`) opens with either identity alone. The selected-identity decrypt (`runtime/scripts/lib/sops-envelope.mjs` `selectedAgeEnvelope`) refused every envelope whose age list held more than one entry (`unsupported-age-set`), so every production read failed once the server key joined; it now admits a set that holds the selected recipient and refuses an empty entry or gap (`invalid-age-entry`) and a recipient named twice (`duplicate-age-recipient`); a dotenv envelope reads every `sops_age__list_<n>__` entry.
|
|
6
|
+
- Fixed: every seal keeps the member's full recipient set (`secret-sops.mjs` `sealRecipients`): the caller's set, else the environment's `.sops.yaml` rule, else the set the existing member is sealed to, under a private one-rule sops config when no rule of the app matches (sops refuses an unmatched file even with `--age`). `set`, `migrate`, `split` and the edit verbs on a production member keep the server recipient.
|
|
7
|
+
- Changed: one age identity lookup for every decrypt of a member, `decryptionIdentity` (`secret-init.mjs`): the environment, the app's `.claude/secret.env`, its main checkout's, the harness CLI's secret.env (`hostIdentity`), then sops' keys.txt. `defaultSops` uses it, `stack`, `release` and `db` hand their context `hostIdentity` (`stackContext`, `release/index.mjs` `contextOf`, `main.mjs`), so a stack deploy opens its members with the same identity `app secret` does; `stack/sealed.mjs` `hasAgeIdentity` reads the seam's finding instead of guessing from files.
|
|
8
|
+
- Changed: a member that cannot be opened is refused naming the member, the format it was read as, its recipients, where the identity came from and its recipient, and why: a failed selected sops run names its class (`sopsFailureClass`: no-matching-identity, mac-mismatch, unparsable-document, timeout, exit-<n>) instead of "the selected invocation was not qualified" alone.
|
|
9
|
+
- Changed: the deploy's sealed SSH members (`deploy.remote.sealed`) are read as what they are: a `.enc.yaml` member through `decrypt(file, "yaml")` and its key, a legacy `.enc` through the binary envelope. The keys are `SEALED_SSH_KEYS` (`stack/remote.mjs`): `privateKey` of `sshKey`, `knownHosts` of `knownHosts`; the `key` and `known_hosts` aliases are gone, and a member without its key is refused naming the keys it holds.
|
|
10
|
+
- Fixed: `server-key` resolves age-keygen as root, the way it calls it (`RESOLVE_AGE_KEYGEN`, `ageKeygenScript`: root's PATH, then `/usr/local/bin`, `/usr/bin`, `/bin`): on AlmaLinux 10 sudo's secure_path leaves `/usr/local/bin` out, so the deploy user's `command -v age-keygen` passed and the root script exited 127 ("age-keygen failed on the server"). The static age installer links age and age-keygen from `/usr/bin` and counts age as present only when root sees it too; `stack-key-restore.yml` (both editions) adds `/usr/local/bin` to its root shell's PATH.
|
|
11
|
+
- Changed: the bundled canon pins name hfs 4.11.13, eslint-canon-be 3.8.12, eslint-canon-fe 9.5.14 and the Grammar family 0.15.25.
|
|
12
|
+
|
|
13
|
+
## 4.11.12 - 2026-10-29
|
|
14
|
+
|
|
15
|
+
- Changed: the skeleton canon gate (`src/scaffold-template-canon-be.spec.mjs`) lints every file under `be/src/modules/platform` of both editions with the starci-be rules, no longer `platform/http` alone; both editions are green.
|
|
16
|
+
- Fixed: the lite skeleton's `platform/http-security` reads and writes its rate limit windows through `RateWindowEntity` on the EntityManager (R334), no longer through full's `rate-limit.sql.ts` and `.query(`: a live window grows in one atomic `increment`, an ended one restarts with `update`, a missing one opens with an `orIgnore` insert builder, and the prune deletes a bounded `find` batch. The entity maps `public.http_security_rate_windows` of the baseline migration (`persistence/entities/rate-window.entity.ts`, `httpSecurityEntities` in its barrel, listed in `PRIMARY_ENTITIES`); a lite platform capability takes its `persistence/` from the lite overlay alone. The guard spec uses the kit's `mockEntityManager` and `queueQueryBuilders`.
|
|
17
|
+
- Changed: a fresh lite app no longer carries the raw SQL helpers nothing in it calls: `platform/database/database.sql.ts` and `database.client.ts` (with its spec) are written by the first generator that needs them (`add table` the sql helpers, `add queue`, `add job` and `add webhook` both), and the barrel exports `sql`, `callDbFunction` and `advisoryXactLock` are registered by those generators (`jobs` registers `advisoryXactLock`); `notify` is no longer exported by the starter.
|
|
18
|
+
- Fixed: `source-suffix` (BE_SOURCE_FORM, R89) admits the one file a file slot names by its path, read from the slot manifest: the lite entity registry `src/modules/platform/database/entities.ts` (slot `be.platform.database.entities`) was refused for having no role suffix.
|
|
19
|
+
- Fixed: the lite skeleton types its entity lists with `EntityClass` (`new () => object`, declared in `platform/database/database.options.ts` as full declares it): `DatabaseOptions.entities` and `PRIMARY_ENTITIES` of `entities.ts` were `ReadonlyArray<Function>`, which `starci-be/no-function-or-eval` refuses.
|
|
20
|
+
- Changed: R334 `BE_PERSISTENCE_NO_RAW_SQL` covers test code with one owner exception (ruling lite-test-sql-owner): specs, builders and fixtures seed and assert through entities on `world.db.<connection>`, and only `src/tests/world` holds raw SQL beside `platform/database`, as named world helpers for what entities cannot express. The bundled catalog law and the failure-code hint say so; the bundled canon pins name hfs 4.11.12, eslint-canon-be 3.8.11, eslint-canon-fe 9.5.13 and the Grammar family 0.15.24.
|
|
21
|
+
|
|
3
22
|
## 4.11.11 - 2026-10-29
|
|
4
23
|
|
|
5
24
|
- Changed: `server-key <env> --backup github` stores the server identity as the secret `SOPS_AGE_KEY` of the GitHub Environment `<env>` (`BACKUP_SECRET`, `gh secret set SOPS_AGE_KEY --env <env>`), the name the deploy workflows read: an Environment secret overrides a repository secret of the same name for every job bound to that Environment, so the deploy of `<env>` decrypts with that environment's own server key. `backupSecretName` and the `SOPS_AGE_KEY_<ENV>` name are gone.
|
package/README.md
CHANGED
|
@@ -230,7 +230,7 @@ one key its whole text or several one `KEY=value` line each, `--from-file KEY=pa
|
|
|
230
230
|
A member is sealed to its environment's rule of the managed `.sops.yaml`; `recipients <env> [--add|--remove <age1...|owner>]`
|
|
231
231
|
rewrites that rule (`environmentRecipients`, `secret-init.mjs`), and `init` takes the owner's identity as the app's recipient.
|
|
232
232
|
Re-sealing a member whose every key the set replaces needs no age identity; adding a key to one does, and the identity is found
|
|
233
|
-
by itself (`
|
|
233
|
+
by itself (`decryptionIdentity`, the one lookup every decrypt of a member uses: secret, stack, release, db): SOPS_AGE_KEY or SOPS_AGE_KEY_FILE of the environment, else of the app's git-ignored
|
|
234
234
|
`.claude/secret.env`, else of its main checkout's when the app is a git worktree, else the `hostIdentity` the harness CLI passes
|
|
235
235
|
(its own secret.env), else the sops `keys.txt`; with none, the verb refuses before asking for a value, naming every place it
|
|
236
236
|
looked and the one line that fixes it. `audit [<env>]` names every deviation and exits 1; `migrate <env> <member> [--to
|
package/package.json
CHANGED
package/release/index.mjs
CHANGED
|
@@ -18,9 +18,9 @@ import { RELEASE_CODE, VERSION, normalizeRelease, releaseGate } from './gate.mjs
|
|
|
18
18
|
import { releasePush } from './push.mjs';
|
|
19
19
|
import { releaseUrgentPush } from './urgent.mjs';
|
|
20
20
|
|
|
21
|
-
const IO_KEYS = ['cwd', 'stdout', 'stderr', 'env', 'sops'];
|
|
21
|
+
const IO_KEYS = ['cwd', 'stdout', 'stderr', 'env', 'sops', 'hostIdentity'];
|
|
22
22
|
|
|
23
|
-
/** The stack context of one invocation: the IO of the app (cwd, writers, env, sops) over the injectable seams of `io.stackIo` (spawn, sleep, now, fetch). */
|
|
23
|
+
/** The stack context of one invocation: the IO of the app (cwd, writers, env, sops, hostIdentity) over the injectable seams of `io.stackIo` (spawn, sleep, now, fetch). */
|
|
24
24
|
export function contextOf(io = {}) {
|
|
25
25
|
const own = Object.fromEntries(IO_KEYS.filter((key) => io[key] !== undefined).map((key) => [key, io[key]]));
|
|
26
26
|
return stackContext({ ...io.stackIo, ...own });
|
|
@@ -31,35 +31,35 @@ pins:
|
|
|
31
31
|
source: packages/event-stream/package.json
|
|
32
32
|
why: 'the one server-sent-events client of every front end (fe-stack event-stream, owner:event-stream-package): the transport client layer (modules/api/sse/clients) creates one instance for the app with the bearer token source and the stream operations follow on it; it carries Last-Event-ID resume, the capped doubling backoff, the heartbeat timeout, the single 401 renewal and the useSWRSubscription adapter, so no app keeps a hand-written reader.'
|
|
33
33
|
'@starci/grammar':
|
|
34
|
-
version: 0.15.
|
|
34
|
+
version: 0.15.25
|
|
35
35
|
group: starci
|
|
36
36
|
install: registry
|
|
37
37
|
side: fe
|
|
38
38
|
source: packages/grammar/package.json
|
|
39
39
|
why: 'the grammar front ends read: the brand layer sets `--font-sans` and `--font-mono` and the grammar reads them; it carries the Input tel kind, the copyable and read-only Input, the IconButton disclosure props and count badge, ChatBubble, FillViewport, Textarea mentions and Enter-to-send, the leading PrimaryRailLayout rail, the plate-less Image, ListRow, the soft Alert, Progress steps, the floating primary IconButton, FlowGraph, the STATE-8 loading views and the bordered selectable TagGroup chips. The runtime source version wins for a @starci package.'
|
|
40
40
|
'@starci/eslint-canon-be':
|
|
41
|
-
version: 3.8.
|
|
41
|
+
version: 3.8.12
|
|
42
42
|
group: starci
|
|
43
43
|
install: registry
|
|
44
44
|
side: be
|
|
45
45
|
source: packages/eslint-canon-be/package.json
|
|
46
46
|
why: 'the back-end ESLint canon: `loadHfs(import.meta.url)` of be/eslint.config.mjs finds the app-root hfs.json (kind app) and gives every linted file the view of the be side, and the project graph is built per side; its bundled runtime copies (slots, canon-pins, failure codes, the architecture machine) put .starcistacks and .sops.yaml at the app root; `starciBeConfig({ hfs: loadHfs(import.meta.url) })` is the typed factory and the BE-CONVENTION laws are its rules.'
|
|
47
47
|
'@starci/eslint-canon-fe':
|
|
48
|
-
version: 9.5.
|
|
48
|
+
version: 9.5.14
|
|
49
49
|
group: starci
|
|
50
50
|
install: registry
|
|
51
51
|
side: fe
|
|
52
52
|
source: packages/eslint-canon-fe/package.json
|
|
53
53
|
why: 'the front-end ESLint canon: `loadHfs(import.meta.url)` of fe/eslint.config.mjs finds the app-root hfs.json (kind app) and gives every linted file the view of the fe side, and the project graph is built per side; its bundled runtime copies (slots, canon-pins, failure codes, the architecture machine) put .starcistacks and .sops.yaml at the app root; the front end has no tests (FE_NO_TESTS R97 in hfs) and no-vietnamese-in-source (R91) applies.'
|
|
54
54
|
'@starci/eslint-grammar-core':
|
|
55
|
-
version: 0.15.
|
|
55
|
+
version: 0.15.25
|
|
56
56
|
group: starci
|
|
57
57
|
install: registry
|
|
58
58
|
side: fe
|
|
59
59
|
source: packages/eslint-grammar-core/package.json
|
|
60
60
|
why: 'the StarCi Grammar component API lint, versioned with @starci/grammar; front ends compose this family package with the universal FE canon.'
|
|
61
61
|
'@starci/eslint-grammar-offset-pop':
|
|
62
|
-
version: 0.15.
|
|
62
|
+
version: 0.15.25
|
|
63
63
|
group: starci
|
|
64
64
|
install: registry
|
|
65
65
|
side: fe
|
|
@@ -106,7 +106,7 @@ pins:
|
|
|
106
106
|
source: packages/ai-router/package.json
|
|
107
107
|
why: 'the AI pool router of a back end: a NestJS module that routes OpenAI-compatible chat, stream and embeddings calls across keys, models and providers, with @starci/ai-router/testing for its specs; @starci/jest-preset compiles it as an ESM-only dependency.'
|
|
108
108
|
'@starci/hfs':
|
|
109
|
-
version: 4.11.
|
|
109
|
+
version: 4.11.13
|
|
110
110
|
group: starci
|
|
111
111
|
install: registry
|
|
112
112
|
side: both
|
|
@@ -5828,7 +5828,7 @@ rules:
|
|
|
5828
5828
|
ruling: "Lite entities only map tables the migrations create, so each entity column is checked against the migrated schema by starci app db drift, which CI runs in the build job and the release gate runs as its db-drift row."
|
|
5829
5829
|
- id: R334
|
|
5830
5830
|
code: "BE_PERSISTENCE_NO_RAW_SQL"
|
|
5831
|
-
law: "Lite domain and
|
|
5831
|
+
law: "Lite domain, feature and test code reads and writes through TypeORM entities on an EntityManager (domain code the injected one, integration and e2e specs, builders and fixtures the world's `world.db.<connection>`) (find, findOne, findBy, count, exists, insert, save, update, delete, upsert, increment, and createQueryBuilder(Entity, alias) with named parameters for joins, aggregates, FOR UPDATE / SKIP LOCKED and jsonb or vector operators; never a table-name builder, a builder with no entity or a Repository); no .query( call and no sql template outside the two raw SQL owners, platform/database and the test world src/tests/world, which wraps only what entities cannot express (a trigger, a database function, a row-level-security probe, a pgmq queue) in a named, typed world helper specs call; a database function TypeORM cannot express is called, in domain and test code alike, through the callDbFunction, advisoryXactLock and notify helpers of platform/database/database.client.ts, and callDbFunction names only a function ruleParams.be.dbFunctions or hfs.json sides.be.dbFunctions lists with a reason: a function of a migration schema-qualified (public.job_claim), a pg built-in bare (pg_notify, called in pg_catalog). That file alone composes the call statement, from the name parts its validator checked and double-quotes and a numbered parameter list. Entities only map tables db/migrations created (synchronize stays false); entity-versus-schema drift is BE_ENTITY_SCHEMA_DRIFT of starci app db drift."
|
|
5832
5832
|
kinds: [lint]
|
|
5833
5833
|
gates: [pre-commit, settle, land, ci]
|
|
5834
5834
|
failureCodes: ["BE_PERSISTENCE_NO_RAW_SQL"]
|
|
@@ -5581,12 +5581,12 @@ LITE_DB_MIGRATION:
|
|
|
5581
5581
|
kind: check-finding
|
|
5582
5582
|
|
|
5583
5583
|
BE_PERSISTENCE_NO_RAW_SQL:
|
|
5584
|
-
title: "Lite domain code runs raw SQL instead of TypeORM entities"
|
|
5585
|
-
title_vi: "Mã domain của app lite chạy SQL thô thay vì entity TypeORM"
|
|
5586
|
-
meaning_vi: "File `<path>` gọi `.query(` hoặc dùng template `sql` ngoài platform/database và
|
|
5584
|
+
title: "Lite domain, feature or test code runs raw SQL instead of TypeORM entities"
|
|
5585
|
+
title_vi: "Mã domain, feature hoặc test của app lite chạy SQL thô thay vì entity TypeORM"
|
|
5586
|
+
meaning_vi: "File `<path>` gọi `.query(` hoặc dùng template `sql` ngoài hai chủ của SQL thô là platform/database và test world src/tests/world, hoặc gọi callDbFunction với một hàm không có trong ruleParams.be.dbFunctions hay hfs.json sides.be.dbFunctions."
|
|
5587
5587
|
causes_vi:
|
|
5588
|
-
- "Vi phạm R334: dữ liệu của app lite đi qua entity TypeORM trên EntityManager (find, save, update, upsert, createQueryBuilder)."
|
|
5589
|
-
nextStep_vi: "
|
|
5588
|
+
- "Vi phạm R334: dữ liệu của app lite, kể cả spec, builder và fixture, đi qua entity TypeORM trên EntityManager (find, save, update, upsert, createQueryBuilder); spec dùng world.db.<connection>."
|
|
5589
|
+
nextStep_vi: "Đọc/ghi bằng entity trên EntityManager hoặc createQueryBuilder với tham số có tên (trong test là world.db.<connection>); hàm database TypeORM không diễn đạt được thì gọi qua callDbFunction với hàm đã khai kèm lý do; điều entity không diễn đạt được trong test (trigger, thăm dò row-level security, hàng đợi pgmq) thì gọi một helper có tên của src/tests/world."
|
|
5590
5590
|
owner: op-retry
|
|
5591
5591
|
kind: check-finding
|
|
5592
5592
|
|
|
@@ -116,7 +116,11 @@ function isolatedSopsEnv(env, inlineName = 'SOPS_AGE_KEY') {
|
|
|
116
116
|
return out;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
/**
|
|
120
|
+
* A refusal of the selected invocation. `detail` says what failed in public words; `facts` carries only public values the caller
|
|
121
|
+
* names in its own refusal (`publicRecipient`, the selected identity's recipient; `sopsFailure`, the class of a failed sops run).
|
|
122
|
+
*/
|
|
123
|
+
const held = (reason, detail = 'the selected invocation was not qualified', facts = {}) => ({ status: null, stdout: '', stderr: '', error: Object.assign(new Error(`SOPS selected identity [${reason}]: ${detail}`), { name: 'SopsIdentityRefusal', identityRefusal: reason, ...facts }) });
|
|
120
124
|
const nativeFile = file => {
|
|
121
125
|
if (typeof file !== 'string' || !path.isAbsolute(file) || /\.(?:[cm]?js|cmd|bat|ps1|sh)$/i.test(file)) return false;
|
|
122
126
|
let fd;
|
|
@@ -175,11 +179,29 @@ const selectedAdmission = (selection, spec, invocation, env) => {
|
|
|
175
179
|
|
|
176
180
|
const decryptArgs = (file, inputType, outputType) => ['decrypt', '--input-type', inputType, '--output-type', outputType, '--filename-override', file, '--enable-local-keyservice=true', '--decryption-order', 'age'];
|
|
177
181
|
|
|
182
|
+
/**
|
|
183
|
+
* The class of a failed sops run, read from its stderr and exit; sops prints no value there, and only the class leaves. Classes:
|
|
184
|
+
* no-matching-identity (no age entry opens with the identity), mac-mismatch (the document changed after it was sealed),
|
|
185
|
+
* unparsable-document (the bytes are not the format they were read as), timeout, or exit-<n>.
|
|
186
|
+
*/
|
|
187
|
+
export function sopsFailureClass(result) {
|
|
188
|
+
if (result?.error?.code === 'ETIMEDOUT' || result?.signal === 'SIGTERM') return 'timeout';
|
|
189
|
+
const text = Buffer.isBuffer(result?.stderr) ? result.stderr.toString('utf8') : String(result?.stderr ?? '');
|
|
190
|
+
if (/MAC mismatch/iu.test(text)) return 'mac-mismatch';
|
|
191
|
+
if (/no identity matched|failed to get the data key|could not decrypt data key|0 successful groups/iu.test(text)) return 'no-matching-identity';
|
|
192
|
+
if (/unmarshal|could not parse|error loading file|invalid character|yaml:/iu.test(text)) return 'unparsable-document';
|
|
193
|
+
return `exit-${String(result?.status ?? 'none')}`;
|
|
194
|
+
}
|
|
195
|
+
|
|
178
196
|
const decryptSelected = (run, exe, file, input, spec, recipient) => {
|
|
197
|
+
const facts = { publicRecipient: recipient };
|
|
179
198
|
const envelope = selectedAgeEnvelope(decoded(input), spec.inputType, recipient);
|
|
180
|
-
if (!envelope.ok) return held(envelope.reason);
|
|
199
|
+
if (!envelope.ok) return held(envelope.reason, `the ${spec.inputType} envelope was refused for the selected recipient ${recipient}`, facts);
|
|
181
200
|
const result = run(exe, decryptArgs(file, spec.inputType, spec.outputType), input);
|
|
182
|
-
if (!captured(result))
|
|
201
|
+
if (!captured(result)) {
|
|
202
|
+
const failure = sopsFailureClass(result);
|
|
203
|
+
return held('selected-decryption-failed', `sops could not decrypt the ${spec.inputType} document with the selected recipient ${recipient} (${failure})`, { ...facts, sopsFailure: failure });
|
|
204
|
+
}
|
|
183
205
|
return { status: 0, stdout: decoded(result.stdout), stderr: '', error: null };
|
|
184
206
|
};
|
|
185
207
|
|
|
@@ -7,10 +7,11 @@ import { resolveSops, runSelectedSops } from './lib.mjs';
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Run `<bin> encrypt` (bin null: the sops resolveSops finds) over `plaintext` of format `inputType` (json, yaml or dotenv). Sops reads stdin only with a `--filename-override`, the path the sealed
|
|
10
|
-
* file will have: recipients are age keys (`--age`), and when none are given sops picks them from the repository's .sops.yaml for that path.
|
|
10
|
+
* file will have: recipients are age keys (`--age`), and when none are given sops picks them from the repository's .sops.yaml for that path. `config` names
|
|
11
|
+
* the sops configuration to read instead of the repository's (a rule-less member sealed to its own recipients). {status, stdout, stderr, error}.
|
|
11
12
|
*/
|
|
12
|
-
export function seal(bin, { inputType, plaintext, recipients = [], filenameOverride }, { invocation = null, env = process.env, cwd = undefined, maxBuffer = 16 * 1024 * 1024, timeout = undefined } = {}) {
|
|
13
|
-
const args = ['encrypt', '--input-type', inputType, '--output-type', inputType, '--filename-override', filenameOverride];
|
|
13
|
+
export function seal(bin, { inputType, plaintext, recipients = [], filenameOverride, config = null }, { invocation = null, env = process.env, cwd = undefined, maxBuffer = 16 * 1024 * 1024, timeout = undefined } = {}) {
|
|
14
|
+
const args = [...(config ? ['--config', config] : []), 'encrypt', '--input-type', inputType, '--output-type', inputType, '--filename-override', filenameOverride];
|
|
14
15
|
if (recipients.length) args.push('--age', recipients.join(','));
|
|
15
16
|
const selected = sopsIdentityEnv(env);
|
|
16
17
|
if (selected.error?.identityRefusal === 'inline-context-unqualified') return runSelectedSops(bin, { operation: 'seal', params: { inputType, plaintext, recipients, filenameOverride } }, { selection: selected, invocation, env, cwd, maxBuffer, timeout });
|
|
@@ -29,6 +29,8 @@ function sourceFormContext(file, resolver, suffixes, bannedSuffixes) {
|
|
|
29
29
|
const base = path.posix.basename(file);
|
|
30
30
|
if (FREE_NAMES.has(base)) return null;
|
|
31
31
|
const slot = resolver.slot(c.slot);
|
|
32
|
+
// A file slot declares its one file by its path (be.platform.database.entities: src/modules/platform/database/entities.ts).
|
|
33
|
+
if (slot?.path === c.path) return null;
|
|
32
34
|
if ([...(slot?.requires ?? []), ...(slot?.allows ?? [])].includes(base)) return null;
|
|
33
35
|
const admitted = allowsFile(resolver, file);
|
|
34
36
|
// Environment parsing is an app slot role, not a source suffix admitted outside that matching app file.
|
|
@@ -57,8 +59,8 @@ function sourceFormFinding(file, { c, base, suffixes, bannedSuffixes }, boundSuf
|
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
/**
|
|
60
|
-
* BE_SOURCE_FORM (R89): every tracked src/ or apps/ TypeScript file of a back end is index.ts, main.ts, a
|
|
61
|
-
* be.persistence, the matching <app>.env.ts explicitly admitted by its app slot, or <kebab-name>.<suffix>.ts with <suffix> in the closed vocabulary ruleParams.be.suffixes (a name such
|
|
62
|
+
* BE_SOURCE_FORM (R89): every tracked src/ or apps/ TypeScript file of a back end is index.ts, main.ts, the one file a file
|
|
63
|
+
* slot names by its path (the lite entity registry src/modules/platform/database/entities.ts), a migration of be.persistence, the matching <app>.env.ts explicitly admitted by its app slot, or <kebab-name>.<suffix>.ts with <suffix> in the closed vocabulary ruleParams.be.suffixes (a name such
|
|
62
64
|
* as order.service.spec.ts keeps its inner words kebab-case). A suffix of ruleParams.be.bannedSuffixes anywhere in the
|
|
63
65
|
* name is refused by name. Paths no slot owns are HFS_SLOT_UNDECLARED's, not this code's.
|
|
64
66
|
*/
|
|
@@ -106,6 +106,21 @@ export function localAgeIdentity(repoRoot, env, tools, host = null) {
|
|
|
106
106
|
return { env: { ...env }, source: null, looked };
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
/**
|
|
110
|
+
* The one age identity every decrypt of a sealed member opens with (secret get, verify, materialize, set over an existing member,
|
|
111
|
+
* migrate, split, the edit verbs, updatekeys, server-key, the stack's sealed members and the CLI's custody): localAgeIdentity's
|
|
112
|
+
* order (the environment, the app's `.claude/secret.env`, its main checkout's, the `host` port), then sops' per-user keys.txt.
|
|
113
|
+
* Same shape as localAgeIdentity; `looked` names every place read, keys.txt last.
|
|
114
|
+
*/
|
|
115
|
+
export function decryptionIdentity(repoRoot, env, { tools, host = null, platform = process.platform } = {}) {
|
|
116
|
+
const local = localAgeIdentity(repoRoot, env, tools, host);
|
|
117
|
+
if (local.source !== null) return local;
|
|
118
|
+
const keys = secretRoots(env, platform).identity;
|
|
119
|
+
const looked = [...local.looked, keys];
|
|
120
|
+
if (!fs.existsSync(keys)) return { ...local, looked };
|
|
121
|
+
return { env: { ...local.env, SOPS_AGE_KEY_FILE: keys }, source: keys, looked };
|
|
122
|
+
}
|
|
123
|
+
|
|
109
124
|
/** Load host-local age selections below the explicit environment (localAgeIdentity), without copying any other credentials. */
|
|
110
125
|
export function ageIdentityEnv(repoRoot, env, tools) {
|
|
111
126
|
return localAgeIdentity(repoRoot, env, tools).env;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// secret-sops.mjs - runtime SOPS adapter and age identity selection.
|
|
2
2
|
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import { runProgram } from "../api/process/run-program.mjs";
|
|
5
6
|
import { resolveRealTool } from "../api/process/resolve-real-tool.mjs";
|
|
@@ -9,8 +10,8 @@ import { updateKeys as sopsUpdateKeys } from "../api/sops/update-keys.mjs";
|
|
|
9
10
|
import { isLegacyName } from "../lib/sealed-member.mjs";
|
|
10
11
|
import { invocationDir } from "../lib/roots.mjs";
|
|
11
12
|
import { envelopeOf } from "./secret-document.mjs";
|
|
12
|
-
import { configuredRecipients,
|
|
13
|
-
import { outsideRepository
|
|
13
|
+
import { configuredRecipients, decryptionIdentity, secretTools } from "./secret-init.mjs";
|
|
14
|
+
import { outsideRepository } from "./secret-files.mjs";
|
|
14
15
|
import { SecretError, publicStorage } from "./secret-errors.mjs";
|
|
15
16
|
|
|
16
17
|
const sopsInvocation = Object.freeze({ runProgram, resolveRealTool });
|
|
@@ -45,15 +46,27 @@ function recipientsOf(file) {
|
|
|
45
46
|
* The refusal of a decrypt whose selected identity is not one `file` is sealed to: names where the identity came from and the
|
|
46
47
|
* member's recipients, and the two ways out. It carries no value.
|
|
47
48
|
*/
|
|
48
|
-
function identityMismatch(repoRoot, identity, file) {
|
|
49
|
+
function identityMismatch(repoRoot, identity, file, publicRecipient) {
|
|
49
50
|
const recipients = recipientsOf(file);
|
|
51
|
+
const own = publicRecipient ? ` (recipient ${publicRecipient})` : "";
|
|
50
52
|
return new SecretError(
|
|
51
|
-
`the age identity of ${identity.source ?? "the environment"} does not open ${path.basename(file)}, ` +
|
|
52
|
-
`sealed to ${recipients.join(", ") || "another recipient"}. Fix: put
|
|
53
|
-
"or, when no one holds
|
|
53
|
+
`the age identity of ${identity.source ?? "the environment"}${own} does not open ${path.basename(file)}, ` +
|
|
54
|
+
`sealed to ${recipients.join(", ") || "another recipient"}. Fix: put one of those recipients' age secret key in ${path.join(repoRoot, ".claude", "secret.env")} as SOPS_AGE_KEY, ` +
|
|
55
|
+
"or, when no one holds any of them any more, seal the member's keys again (remove it and set them) after .sops.yaml names this identity's recipient",
|
|
54
56
|
);
|
|
55
57
|
}
|
|
56
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Any other refusal of a decrypt: the member, the format it was read as, the recipients it is sealed to, where the age identity
|
|
61
|
+
* came from and (when derived) its recipient, then the refusal itself. Public facts only.
|
|
62
|
+
*/
|
|
63
|
+
function identityRefused(identity, file, format, error) {
|
|
64
|
+
const recipients = recipientsOf(file);
|
|
65
|
+
const own = error.publicRecipient ? `, recipient ${error.publicRecipient}` : "";
|
|
66
|
+
const source = identity.source ? `the age identity of ${identity.source}${own}` : `no age identity (looked in ${identity.looked.join(", ") || "the environment"})`;
|
|
67
|
+
return `${path.basename(file)} (read as ${format ?? "its own format"}, sealed to ${recipients.join(", ") || "no age recipient"}) cannot be opened with ${source}: ${error.message}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
57
70
|
/**
|
|
58
71
|
* The refusal of an operation that must decrypt `file` with no age identity selected: it names the recipient the member is
|
|
59
72
|
* sealed to, every place looked, and the one line that fixes it. It carries no value.
|
|
@@ -70,8 +83,40 @@ function identityMissing(repoRoot, identity, file) {
|
|
|
70
83
|
}
|
|
71
84
|
|
|
72
85
|
/**
|
|
73
|
-
* The
|
|
74
|
-
*
|
|
86
|
+
* The recipient set a seal of `file` writes: the caller's `named` set, else the environment's .sops.yaml rule, else the full set
|
|
87
|
+
* the existing member is sealed to, so no rewrite (set, migrate, split, an edit) drops a recipient such as the deploy server's.
|
|
88
|
+
* `ruled` says whether a rule of the app's .sops.yaml matches the file. Refused, as the rule refuses, when none names one.
|
|
89
|
+
*/
|
|
90
|
+
function sealRecipients(repoRoot, file, named) {
|
|
91
|
+
try {
|
|
92
|
+
const rule = configuredRecipients(repoRoot, file);
|
|
93
|
+
return { recipients: named.length ? named : rule, ruled: true };
|
|
94
|
+
} catch (error) {
|
|
95
|
+
const existing = named.length ? named : fs.existsSync(file) ? recipientsOf(file) : [];
|
|
96
|
+
if (existing.length) return { recipients: existing, ruled: false };
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Runs `seal` with a private sops configuration naming only `recipients` when the app's .sops.yaml has no rule for the member
|
|
103
|
+
* (sops refuses a file no rule matches even with --age); the folder is removed after. Public keys only.
|
|
104
|
+
*/
|
|
105
|
+
function withOwnRule(ruled, recipients, seal) {
|
|
106
|
+
if (ruled) return seal(null);
|
|
107
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "starci-sops-rule-"));
|
|
108
|
+
try {
|
|
109
|
+
const config = path.join(dir, ".sops.yaml");
|
|
110
|
+
fs.writeFileSync(config, `creation_rules:\n - age: ${recipients.join(",")}\n`);
|
|
111
|
+
return seal(config);
|
|
112
|
+
} finally {
|
|
113
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The default sops seam: the runtime's sops api, which finds the binary on this machine; the age identity is decryptionIdentity's
|
|
119
|
+
* (`host` the harness CLI's secret.env, then sops' keys.txt). `identity` says where the age identity
|
|
75
120
|
* was found (`source`, null when nowhere) and where it was looked for; `requireIdentity(file)` refuses, before any value is
|
|
76
121
|
* read, an operation that must decrypt `file` with no identity.
|
|
77
122
|
*/
|
|
@@ -83,7 +128,7 @@ export function defaultSops(
|
|
|
83
128
|
host = null,
|
|
84
129
|
) {
|
|
85
130
|
const { sops: binary } = publicStorage(() => secretTools(env, tools));
|
|
86
|
-
const local =
|
|
131
|
+
const local = decryptionIdentity(repoRoot, env, { tools, host, platform });
|
|
87
132
|
const selectedEnv = local.env;
|
|
88
133
|
const identity = { source: local.source, looked: [...local.looked] };
|
|
89
134
|
const invocation = {
|
|
@@ -109,27 +154,16 @@ export function defaultSops(
|
|
|
109
154
|
);
|
|
110
155
|
checkIdentity(value);
|
|
111
156
|
}
|
|
112
|
-
if (
|
|
113
|
-
!Object.keys(selectedEnv).some((name) => AGE_IDENTITY_NAME.test(name))
|
|
114
|
-
) {
|
|
115
|
-
const keys = secretRoots(env, platform).identity;
|
|
116
|
-
checkIdentity(keys);
|
|
117
|
-
identity.looked.push(keys);
|
|
118
|
-
if (fs.existsSync(keys)) {
|
|
119
|
-
selectedEnv.SOPS_AGE_KEY_FILE = keys;
|
|
120
|
-
identity.source = keys;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
157
|
const requireIdentity = (file) => {
|
|
124
158
|
if (identity.source === null) throw identityMissing(repoRoot, identity, file);
|
|
125
159
|
};
|
|
126
|
-
const refuse = (what, result, file) => {
|
|
160
|
+
const refuse = (what, result, file, format) => {
|
|
127
161
|
if (result.error?.identityRefusal === "identity-not-supplied" && file)
|
|
128
162
|
return identityMissing(repoRoot, identity, file);
|
|
129
163
|
if (result.error?.identityRefusal === "recipient-mismatch" && file)
|
|
130
|
-
return identityMismatch(repoRoot, identity, file);
|
|
164
|
+
return identityMismatch(repoRoot, identity, file, result.error.publicRecipient);
|
|
131
165
|
if (result.error?.identityRefusal)
|
|
132
|
-
return Object.assign(new SecretError(result.error.message), {
|
|
166
|
+
return Object.assign(new SecretError(file ? identityRefused(identity, file, format, result.error) : result.error.message), {
|
|
133
167
|
identityRefusal: result.error.identityRefusal,
|
|
134
168
|
});
|
|
135
169
|
if (result.error?.code === "SOPS_MISSING")
|
|
@@ -157,6 +191,7 @@ export function defaultSops(
|
|
|
157
191
|
`decrypt ${path.basename(file)}; is the age identity installed?`,
|
|
158
192
|
result,
|
|
159
193
|
file,
|
|
194
|
+
format,
|
|
160
195
|
);
|
|
161
196
|
if (exact) return exactMap(result.stdout);
|
|
162
197
|
const map = Object.create(null);
|
|
@@ -193,6 +228,7 @@ export function defaultSops(
|
|
|
193
228
|
`decrypt ${path.basename(file)}; is the age identity installed?`,
|
|
194
229
|
result,
|
|
195
230
|
file,
|
|
231
|
+
types[0],
|
|
196
232
|
);
|
|
197
233
|
return String(result.stdout);
|
|
198
234
|
},
|
|
@@ -207,21 +243,17 @@ export function defaultSops(
|
|
|
207
243
|
{ env: selectedEnv, cwd: repoRoot, invocation },
|
|
208
244
|
);
|
|
209
245
|
if (result.status !== 0)
|
|
210
|
-
throw refuse(`update the keys of ${path.basename(file)}; is the age identity a recipient of it?`, result, file);
|
|
246
|
+
throw refuse(`update the keys of ${path.basename(file)}; is the age identity a recipient of it?`, result, file, isLegacyName(file) ? "dotenv" : "yaml");
|
|
211
247
|
},
|
|
212
248
|
seal(request) {
|
|
213
|
-
const recipients = request.recipients
|
|
214
|
-
|
|
215
|
-
: publicStorage(() =>
|
|
216
|
-
configuredRecipients(repoRoot, request.filenameOverride),
|
|
217
|
-
);
|
|
218
|
-
// Sealing needs only public recipients, so it runs with no identity selected and may name several (an environment's
|
|
249
|
+
const { recipients, ruled } = publicStorage(() => sealRecipients(repoRoot, request.filenameOverride, request.recipients));
|
|
250
|
+
// Sealing needs only public recipients, so it runs with no identity selected and seals to the whole set (an environment's
|
|
219
251
|
// server key and the owner key both).
|
|
220
|
-
const result = sopsSeal(
|
|
252
|
+
const result = withOwnRule(ruled, recipients, (config) => sopsSeal(
|
|
221
253
|
binary,
|
|
222
|
-
{ ...request, recipients },
|
|
254
|
+
{ ...request, recipients, config },
|
|
223
255
|
{ env: withoutIdentity(selectedEnv), cwd: repoRoot, invocation },
|
|
224
|
-
);
|
|
256
|
+
));
|
|
225
257
|
if (result.status !== 0) throw refuse("seal the secret", result);
|
|
226
258
|
return result.stdout;
|
|
227
259
|
},
|
|
@@ -62,13 +62,17 @@ export function isSopsEnvelope(text) {
|
|
|
62
62
|
try { return sopsTree(parseYaml(src)); } catch { return false; }
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
/**
|
|
65
|
+
/** A refused admission, named by its reason. */
|
|
66
66
|
const refusal = (reason) => ({ ok: false, reason });
|
|
67
67
|
|
|
68
|
+
const DOTENV_AGE_FIELD = /^age__list_(0|[1-9]\d{0,2})__map_(recipient|enc)$/u;
|
|
69
|
+
|
|
68
70
|
function dotenvMetadataValue(meta, age, key, value) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
const field = DOTENV_AGE_FIELD.exec(key);
|
|
72
|
+
if (field) {
|
|
73
|
+
const entry = (age[Number(field[1])] ??= {});
|
|
74
|
+
entry[field[2]] = value;
|
|
75
|
+
} else if (key === 'mac_only_encrypted') {
|
|
72
76
|
if (value !== 'false') return 'partial-mac';
|
|
73
77
|
meta[key] = false;
|
|
74
78
|
} else if (key.includes('__')) return 'unsupported-key-group';
|
|
@@ -88,13 +92,14 @@ function readDotenvMetadata(text) {
|
|
|
88
92
|
pairs.set(name, line.slice(at + 1).replaceAll(String.raw`\n`, '\n'));
|
|
89
93
|
}
|
|
90
94
|
const meta = {};
|
|
91
|
-
const age =
|
|
95
|
+
const age = [];
|
|
92
96
|
for (const [name, value] of pairs) {
|
|
93
97
|
if (!name.startsWith('sops_')) continue;
|
|
94
98
|
const reason = dotenvMetadataValue(meta, age, name.slice('sops_'.length), value);
|
|
95
99
|
if (reason) return { refusal: reason };
|
|
96
100
|
}
|
|
97
|
-
|
|
101
|
+
// A gap in the list indices is an entry sops never wrote: refused as an empty entry, never skipped.
|
|
102
|
+
meta.age = Array.from(age, (entry) => entry ?? null);
|
|
98
103
|
return { meta };
|
|
99
104
|
}
|
|
100
105
|
|
|
@@ -142,15 +147,35 @@ function validateAgeMetadata(meta, text, recipient) {
|
|
|
142
147
|
const fields = new Set([...providers, 'age', 'lastmodified', 'mac', 'version', 'unencrypted_suffix', 'encrypted_suffix', 'unencrypted_regex', 'encrypted_regex', 'unencrypted_comment_regex', 'encrypted_comment_regex', 'mac_only_encrypted']);
|
|
143
148
|
if (Object.keys(meta).some(name => !fields.has(name))) return refusal('unknown-metadata');
|
|
144
149
|
if (Object.hasOwn(meta, 'mac_only_encrypted') && meta.mac_only_encrypted !== false) return refusal('partial-mac');
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (!
|
|
148
|
-
if (typeof entry.recipient !== 'string' || entry.recipient !== recipient) return refusal('recipient-mismatch');
|
|
149
|
-
if (!hasValidAgePayload(entry)) return refusal('invalid-age-entry');
|
|
150
|
+
const set = ageSet(meta.age);
|
|
151
|
+
if (!set.ok) return set;
|
|
152
|
+
if (!set.recipients.includes(recipient)) return refusal('recipient-mismatch');
|
|
150
153
|
if (!hasValidEnvelopeVersion(meta)) return refusal('invalid-envelope');
|
|
151
154
|
return { ok: true };
|
|
152
155
|
}
|
|
153
156
|
|
|
157
|
+
const AGE_RECIPIENT = /^age1[ac-hj-np-z02-9]+$/u;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The age set of an envelope: one or more entries (the owner key and an environment's server key are the standard pair), each a
|
|
161
|
+
* well-formed recipient with its wrapped data key; an empty entry or a recipient named twice is refused.
|
|
162
|
+
*/
|
|
163
|
+
function ageSet(entries) {
|
|
164
|
+
if (!Array.isArray(entries) || entries.length === 0) return refusal('unsupported-age-set');
|
|
165
|
+
const recipients = [];
|
|
166
|
+
for (const entry of entries) {
|
|
167
|
+
if (!isAgeEntry(entry) || typeof entry.recipient !== 'string' || !AGE_RECIPIENT.test(entry.recipient) || !hasValidAgePayload(entry))
|
|
168
|
+
return refusal('invalid-age-entry');
|
|
169
|
+
if (recipients.includes(entry.recipient)) return refusal('duplicate-age-recipient');
|
|
170
|
+
recipients.push(entry.recipient);
|
|
171
|
+
}
|
|
172
|
+
return { ok: true, recipients };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Admit one flat age envelope for the native selected-identity invocation when `recipient` (the selected identity's public key) is
|
|
177
|
+
* one of its age set. Shape admission, never cryptographic proof.
|
|
178
|
+
*/
|
|
154
179
|
export function selectedAgeEnvelope(text, format, recipient) {
|
|
155
180
|
if (!['binary', 'json', 'yaml', 'dotenv'].includes(format)) return refusal('unsupported-format');
|
|
156
181
|
const parsed = readAgeMetadata(text, format);
|
|
@@ -233,17 +233,13 @@ export function addLiteWebhookInbox({
|
|
|
233
233
|
);
|
|
234
234
|
if (!hasHandoffStorage)
|
|
235
235
|
planned[0].text = `${template("platform/migration.sql.tpl", renderValues)}\n${template("platform/client-operation-outcomes.sql.tpl", renderValues)}\n${planned[0].text}`;
|
|
236
|
-
|
|
237
|
-
|
|
236
|
+
// The sql tag and the database-function call (with its spec) the inbox and the event bus use; the lite starter leaves them out.
|
|
237
|
+
for (const file of ["database.sql.ts", "database.client.ts", "database.client.spec.ts"]) {
|
|
238
|
+
const relative = `be/src/modules/platform/database/${file}`;
|
|
239
|
+
if (fs.existsSync(path.join(root, ...relative.split("/")))) continue;
|
|
238
240
|
planned.push({
|
|
239
|
-
relative
|
|
240
|
-
text: render(
|
|
241
|
-
fs.readFileSync(
|
|
242
|
-
path.join(TEMPLATES_DIR, "be", "skeleton-lite", "src", "modules", "platform", "database", "database.sql.ts"),
|
|
243
|
-
"utf8",
|
|
244
|
-
),
|
|
245
|
-
{},
|
|
246
|
-
),
|
|
241
|
+
relative,
|
|
242
|
+
text: render(fs.readFileSync(path.join(TEMPLATES_DIR, "be", "skeleton-lite", "src", "modules", "platform", "database", file), "utf8"), {}),
|
|
247
243
|
});
|
|
248
244
|
}
|
|
249
245
|
const databaseClient = path.join(
|
|
@@ -84,12 +84,14 @@ const DATABASE_ERROR = 'be/src/modules/platform/database/errors/database.error.t
|
|
|
84
84
|
|
|
85
85
|
/** Skeleton files the lite starter leaves out and the queue capabilities use, each from its skeleton template. */
|
|
86
86
|
const SKELETON_FILES = Object.freeze([
|
|
87
|
+
['be/src/modules/platform/database/database.client.ts', 'skeleton-lite/src/modules/platform/database/database.client.ts'],
|
|
88
|
+
['be/src/modules/platform/database/database.client.spec.ts', 'skeleton-lite/src/modules/platform/database/database.client.spec.ts'],
|
|
87
89
|
['be/src/modules/platform/database/database.sql.ts', 'skeleton-lite/src/modules/platform/database/database.sql.ts'],
|
|
88
90
|
['be/src/modules/platform/primitives/sequence.policy.ts', 'skeleton/src/modules/platform/primitives/sequence.policy.ts'],
|
|
89
91
|
['be/src/modules/platform/primitives/sequence.policy.spec.ts', 'skeleton/src/modules/platform/primitives/sequence.policy.spec.ts'],
|
|
90
92
|
]);
|
|
91
93
|
|
|
92
|
-
/** The sql tag of the outbox and claim statements (with its identifier error) and the in-order relay the queue adapters walk their rows with. */
|
|
94
|
+
/** The database-function call and the sql tag of the outbox and claim statements (with its identifier error) and the in-order relay the queue adapters walk their rows with. */
|
|
93
95
|
function skeletonFiles(repoRoot) {
|
|
94
96
|
const created = SKELETON_FILES.filter(([relative]) => !fs.existsSync(path.join(repoRoot, ...relative.split('/'))))
|
|
95
97
|
.map(([relative, source]) => ({ relative, text: render(template(`be/${source}`), {}) }));
|
|
@@ -364,7 +366,10 @@ export function planLiteQueue({ repoRoot, repo, noun, patterns, now }) {
|
|
|
364
366
|
fs.writeFileSync(target, entry.text);
|
|
365
367
|
}
|
|
366
368
|
for (const patch of patches) fs.writeFileSync(patch.file, patch.text);
|
|
367
|
-
const exported =
|
|
369
|
+
const exported = [
|
|
370
|
+
...registerLiteExports({ root: repoRoot, generator: 'queue' }),
|
|
371
|
+
...(patterns.includes('fenced-job') ? registerLiteExports({ root: repoRoot, generator: 'jobs' }) : []),
|
|
372
|
+
];
|
|
368
373
|
const sealed = sealRedisMembers(repoRoot, stack.environments);
|
|
369
374
|
const changed = patches.map((patch) => path.relative(repoRoot, patch.file).split(path.sep).join('/'));
|
|
370
375
|
return [...new Set([...created.map((entry) => entry.relative), ...changed, ...exported, ...sealed])];
|
package/scaffold/add-table.mjs
CHANGED
|
@@ -472,9 +472,14 @@ function writeTableFiles({ root, planned, edit }, created) {
|
|
|
472
472
|
|
|
473
473
|
}
|
|
474
474
|
|
|
475
|
+
/** The lite sql helpers of platform/database (requireOwnedEntity, the bounds and the sql tag). */
|
|
476
|
+
const DATABASE_SQL_FILE = "be/src/modules/platform/database/database.sql.ts";
|
|
477
|
+
|
|
475
478
|
function tableRegistrations({ root, repo, fe, edit }) {
|
|
476
479
|
const errorFile = "be/src/modules/platform/database/errors/database.error.ts";
|
|
477
480
|
if (repo.edition === "lite" && fs.existsSync(at(root, errorFile))) edit(errorFile, withSqlIdentifierError);
|
|
481
|
+
// requireOwnedEntity lives in the sql helpers the lite starter leaves out; the first table writes them.
|
|
482
|
+
if (repo.edition === "lite") edit(DATABASE_SQL_FILE, (text) => text || render(fs.readFileSync(path.join(TEMPLATES_DIR, "be", "skeleton-lite", "src", "modules", "platform", "database", "database.sql.ts"), "utf8"), {}));
|
|
478
483
|
const registrations = [
|
|
479
484
|
...(repo.edition === "lite" ? ["table"] : []),
|
|
480
485
|
...(fe ? ["api", "graphql"] : []),
|