@starci/eslint-canon-be 3.8.20 → 3.9.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.
Files changed (164) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +1 -1
  3. package/runtime/bundle.json +192 -0
  4. package/runtime/engine/by-code-unit.mjs +6 -6
  5. package/runtime/engine/model-config.mjs +98 -76
  6. package/runtime/engine/orca-config.mjs +22 -17
  7. package/runtime/engine/release-config.mjs +22 -18
  8. package/runtime/engine/removed-vocabulary.mjs +21 -20
  9. package/runtime/engine/resources-config.mjs +42 -35
  10. package/runtime/engine/runtime-root.mjs +11 -13
  11. package/runtime/engine/secrets.mjs +170 -102
  12. package/runtime/engine/sonar-config.mjs +16 -13
  13. package/runtime/engine/temp-root.mjs +3 -9
  14. package/runtime/knowledge/hfs/canon-pins.yaml +10 -10
  15. package/runtime/knowledge/hfs/rules.yaml +6 -6
  16. package/runtime/knowledge/hfs/slots.yaml +2 -2
  17. package/runtime/knowledge/sonar-gate.yaml +1 -1
  18. package/runtime/packages/hfs/templates/app/package-scripts/package.json +1 -1
  19. package/runtime/scripts/api/git/cat-file.mjs +0 -1
  20. package/runtime/scripts/api/git/config-get.mjs +1 -2
  21. package/runtime/scripts/api/git/diff.mjs +0 -1
  22. package/runtime/scripts/api/git/lib.mjs +32 -32
  23. package/runtime/scripts/api/git/ls-files.mjs +0 -1
  24. package/runtime/scripts/api/git/ls-tree.mjs +0 -1
  25. package/runtime/scripts/api/git/merge-base.mjs +2 -3
  26. package/runtime/scripts/api/git/remote.mjs +0 -1
  27. package/runtime/scripts/api/git/rev-parse-query.mjs +0 -1
  28. package/runtime/scripts/api/git/show.mjs +0 -1
  29. package/runtime/scripts/hfs/allows.mjs +37 -38
  30. package/runtime/scripts/hfs/architecture/ast-walks.mjs +180 -163
  31. package/runtime/scripts/hfs/architecture/automatic-gates.mjs +80 -73
  32. package/runtime/scripts/hfs/architecture/backend-app-files.mjs +88 -77
  33. package/runtime/scripts/hfs/architecture/backend.mjs +378 -357
  34. package/runtime/scripts/hfs/architecture/background-unowned.mjs +201 -187
  35. package/runtime/scripts/hfs/architecture/canon-clones.mjs +260 -209
  36. package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +149 -116
  37. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +72 -68
  38. package/runtime/scripts/hfs/architecture/clones.mjs +212 -217
  39. package/runtime/scripts/hfs/architecture/config-unread.mjs +7 -9
  40. package/runtime/scripts/hfs/architecture/config.mjs +302 -268
  41. package/runtime/scripts/hfs/architecture/connection-map.mjs +258 -225
  42. package/runtime/scripts/hfs/architecture/constructor-deps.mjs +80 -71
  43. package/runtime/scripts/hfs/architecture/context-coupling.mjs +82 -77
  44. package/runtime/scripts/hfs/architecture/context-map.mjs +267 -234
  45. package/runtime/scripts/hfs/architecture/context-owner.mjs +73 -61
  46. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +47 -43
  47. package/runtime/scripts/hfs/architecture/context-transaction.mjs +54 -52
  48. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +113 -104
  49. package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +288 -270
  50. package/runtime/scripts/hfs/architecture/contracts.mjs +408 -393
  51. package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +50 -51
  52. package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +143 -119
  53. package/runtime/scripts/hfs/architecture/dead-exports.mjs +286 -228
  54. package/runtime/scripts/hfs/architecture/default-deny.mjs +129 -110
  55. package/runtime/scripts/hfs/architecture/doc-language.mjs +24 -19
  56. package/runtime/scripts/hfs/architecture/entity-registry.mjs +20 -22
  57. package/runtime/scripts/hfs/architecture/entrypoint.mjs +47 -45
  58. package/runtime/scripts/hfs/architecture/error-codes.mjs +37 -35
  59. package/runtime/scripts/hfs/architecture/error-masked.mjs +55 -59
  60. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +24 -23
  61. package/runtime/scripts/hfs/architecture/feature-shape.mjs +40 -38
  62. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +21 -21
  63. package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +106 -98
  64. package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +153 -150
  65. package/runtime/scripts/hfs/architecture/frontend-routing.mjs +161 -149
  66. package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +343 -305
  67. package/runtime/scripts/hfs/architecture/frontend-world.mjs +340 -294
  68. package/runtime/scripts/hfs/architecture/frontend.mjs +174 -184
  69. package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +124 -106
  70. package/runtime/scripts/hfs/architecture/hfs-graph.mjs +52 -48
  71. package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +81 -71
  72. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +155 -141
  73. package/runtime/scripts/hfs/architecture/identity.mjs +141 -125
  74. package/runtime/scripts/hfs/architecture/index.mjs +272 -272
  75. package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +45 -43
  76. package/runtime/scripts/hfs/architecture/jwt-ast.mjs +195 -176
  77. package/runtime/scripts/hfs/architecture/machine-ast.mjs +163 -155
  78. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +19 -20
  79. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +177 -172
  80. package/runtime/scripts/hfs/architecture/next-data-contract.mjs +100 -78
  81. package/runtime/scripts/hfs/architecture/next-data-inference.mjs +170 -154
  82. package/runtime/scripts/hfs/architecture/next-data-key.mjs +311 -275
  83. package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +17 -17
  84. package/runtime/scripts/hfs/architecture/next-data.mjs +351 -334
  85. package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +39 -37
  86. package/runtime/scripts/hfs/architecture/owners.mjs +97 -98
  87. package/runtime/scripts/hfs/architecture/package-shape.mjs +56 -55
  88. package/runtime/scripts/hfs/architecture/presentation.mjs +138 -130
  89. package/runtime/scripts/hfs/architecture/reachability.mjs +258 -241
  90. package/runtime/scripts/hfs/architecture/register-once.mjs +152 -139
  91. package/runtime/scripts/hfs/architecture/registration.mjs +301 -267
  92. package/runtime/scripts/hfs/architecture/required-files.mjs +172 -167
  93. package/runtime/scripts/hfs/architecture/route-files-thin.mjs +85 -77
  94. package/runtime/scripts/hfs/architecture/schema-owner.mjs +206 -181
  95. package/runtime/scripts/hfs/architecture/server-action.mjs +48 -48
  96. package/runtime/scripts/hfs/architecture/side-boundary.mjs +2 -5
  97. package/runtime/scripts/hfs/architecture/source-names-shape.mjs +261 -259
  98. package/runtime/scripts/hfs/architecture/source-names.mjs +304 -278
  99. package/runtime/scripts/hfs/architecture/sql-keys.mjs +277 -194
  100. package/runtime/scripts/hfs/architecture/sql-owner.mjs +236 -194
  101. package/runtime/scripts/hfs/architecture/sql-returning.mjs +46 -45
  102. package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +86 -74
  103. package/runtime/scripts/hfs/architecture/sql-tokens.mjs +456 -341
  104. package/runtime/scripts/hfs/architecture/staged-consumers.mjs +35 -30
  105. package/runtime/scripts/hfs/architecture/surface.mjs +64 -74
  106. package/runtime/scripts/hfs/architecture/symbols.mjs +209 -216
  107. package/runtime/scripts/hfs/architecture/test-world-files.mjs +165 -155
  108. package/runtime/scripts/hfs/architecture/tiers.mjs +161 -154
  109. package/runtime/scripts/hfs/architecture/transport-owner.mjs +155 -149
  110. package/runtime/scripts/hfs/architecture/type-context.mjs +255 -250
  111. package/runtime/scripts/hfs/architecture/typescript.mjs +358 -318
  112. package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +110 -92
  113. package/runtime/scripts/hfs/declaration-shape.mjs +140 -103
  114. package/runtime/scripts/hfs/declaration-slots.mjs +64 -61
  115. package/runtime/scripts/hfs/edition-slots.mjs +43 -40
  116. package/runtime/scripts/hfs/linear-text.mjs +20 -20
  117. package/runtime/scripts/hfs/param-names.mjs +6 -11
  118. package/runtime/scripts/hfs/path-findings.mjs +120 -100
  119. package/runtime/scripts/hfs/repo-identity.mjs +55 -42
  120. package/runtime/scripts/hfs/rule-catalog.mjs +353 -257
  121. package/runtime/scripts/hfs/rule-params-shape.mjs +60 -47
  122. package/runtime/scripts/hfs/rules/database-migrations.mjs +428 -388
  123. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +37 -36
  124. package/runtime/scripts/hfs/rules/read.mjs +19 -15
  125. package/runtime/scripts/hfs/rules/secrets.mjs +1 -1
  126. package/runtime/scripts/hfs/rules/spec-placement.mjs +12 -13
  127. package/runtime/scripts/hfs/slot-app-view.mjs +69 -74
  128. package/runtime/scripts/hfs/slot-classify.mjs +42 -38
  129. package/runtime/scripts/hfs/slot-errors.mjs +8 -7
  130. package/runtime/scripts/hfs/slot-imports.mjs +70 -63
  131. package/runtime/scripts/hfs/slot-manifest-shape.mjs +74 -52
  132. package/runtime/scripts/hfs/slot-match.mjs +122 -111
  133. package/runtime/scripts/hfs/slot-path.mjs +0 -2
  134. package/runtime/scripts/hfs/slot-required.mjs +65 -59
  135. package/runtime/scripts/hfs/slot-semantic-problems.mjs +138 -112
  136. package/runtime/scripts/hfs/slot-side-problems.mjs +23 -19
  137. package/runtime/scripts/hfs/slots.mjs +175 -152
  138. package/runtime/scripts/hfs/test-world-slot.mjs +0 -1
  139. package/runtime/scripts/hfs/trailing-slashes.mjs +4 -4
  140. package/runtime/scripts/hfs/typescript-programs.mjs +66 -69
  141. package/runtime/scripts/hfs/view.mjs +38 -40
  142. package/runtime/scripts/lib/dockerfile.mjs +131 -114
  143. package/runtime/scripts/lib/env.mjs +3 -6
  144. package/runtime/scripts/lib/event-contract.mjs +73 -78
  145. package/runtime/scripts/lib/git.mjs +15 -16
  146. package/runtime/scripts/lib/glob.mjs +23 -14
  147. package/runtime/scripts/lib/grammar-lint.mjs +33 -37
  148. package/runtime/scripts/lib/i18n.mjs +32 -35
  149. package/runtime/scripts/lib/in-order.mjs +57 -38
  150. package/runtime/scripts/lib/json-clone.mjs +45 -36
  151. package/runtime/scripts/lib/json.mjs +26 -14
  152. package/runtime/scripts/lib/language.mjs +133 -129
  153. package/runtime/scripts/lib/list.mjs +9 -14
  154. package/runtime/scripts/lib/mutation-fence.mjs +10 -5
  155. package/runtime/scripts/lib/path-key.mjs +53 -38
  156. package/runtime/scripts/lib/read-text.mjs +30 -17
  157. package/runtime/scripts/lib/regex.mjs +1 -2
  158. package/runtime/scripts/lib/same-text.mjs +0 -1
  159. package/runtime/scripts/lib/sops-envelope.mjs +148 -120
  160. package/runtime/scripts/lib/stack-services.mjs +128 -129
  161. package/runtime/scripts/lib/ts-analysis.mjs +28 -26
  162. package/runtime/scripts/lib/ts-ast.mjs +36 -42
  163. package/runtime/scripts/lib/walk.mjs +33 -27
  164. package/runtime/scripts/lib/yaml-cached.mjs +4 -4
@@ -1,4 +1,3 @@
1
1
  // regex.mjs - building a RegExp from text.
2
-
3
2
  /** `text` with every regular-expression metacharacter escaped, so it matches itself literally. */
4
- export const escapeRegExp = (text) => String(text).replace(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`);
3
+ export const escapeRegExp = (text) => String(text).replace(/[.*+?^${}()|[\]\\]/g, String.raw `\$&`);
@@ -1,5 +1,4 @@
1
1
  // same-text.mjs - text equality that ignores the line-ending form and a trailing blank tail (a git runner may trim stdout, a work tree may
2
2
  // carry CRLF): the one comparison the database rules use for a committed file against its base or against a regenerated one.
3
-
4
3
  /** True when both texts exist and are equal once CRLF is folded to LF and trailing whitespace at the end is dropped. */
5
4
  export const sameText = (a, b) => a !== null && b !== null && a.replaceAll('\r\n', '\n').trimEnd() === b.replaceAll('\r\n', '\n').trimEnd();
@@ -4,181 +4,209 @@
4
4
  // scripts/uat/test-secret.mjs; the sops binary is found by scripts/api/sops/lib.mjs.
5
5
  import path from 'node:path';
6
6
  import { parseYaml } from '../../engine/yaml.mjs';
7
-
8
7
  const NAME = /^[a-z0-9][a-z0-9._-]{0,63}$/;
9
8
  const STACK = /^[a-z0-9][a-z0-9-]{0,31}$/;
10
9
  /** One sops-encrypted leaf: `ENC[AES256_GCM,data:...,iv:...,tag:...,type:...]` (data may be empty). */
11
10
  const SOPS_VALUE = /^ENC\[AES256_GCM,data:[A-Za-z0-9+/=]*,iv:[A-Za-z0-9+/=]+,tag:[A-Za-z0-9+/=]+,type:[a-z]+\]$/;
12
-
13
11
  /** Where test credential `name` of `stack` lives in `repo`: {plain, enc, rel}. `rel` is the path the repo's
14
12
  * `stack-secret.mjs set` takes. */
15
13
  export function testSecretPaths(name, { repo, stack = 'dev' } = {}) {
16
- if (!NAME.test(String(name ?? ''))) throw new Error(`test secret name must match ${NAME} (got ${JSON.stringify(name)})`);
17
- if (!STACK.test(String(stack ?? ''))) throw new Error(`stack must match ${STACK} (got ${JSON.stringify(stack)})`);
18
- if (!repo) throw new Error('test secret needs {repo}: the product repository whose .starcistacks holds it');
19
- const rel = `${stack}/secrets/test/${name}`;
20
- const plain = path.join(path.resolve(String(repo)), '.starcistacks', stack, 'secrets', 'test', name);
21
- return { plain, enc: `${plain}.enc`, rel };
14
+ if (!NAME.test(String(name ?? '')))
15
+ throw new Error(`test secret name must match ${NAME} (got ${JSON.stringify(name)})`);
16
+ if (!STACK.test(String(stack ?? '')))
17
+ throw new Error(`stack must match ${STACK} (got ${JSON.stringify(stack)})`);
18
+ if (!repo)
19
+ throw new Error('test secret needs {repo}: the product repository whose .starcistacks holds it');
20
+ const rel = `${stack}/secrets/test/${name}`;
21
+ const plain = path.join(path.resolve(String(repo)), '.starcistacks', stack, 'secrets', 'test', name);
22
+ return { plain, enc: `${plain}.enc`, rel };
22
23
  }
23
-
24
24
  /** The command that stores a test credential, in the product repository's own tooling. */
25
25
  export const setCommand = (name = '<name>', stack = 'dev') => `node scripts/stack-secret.mjs set ${stack}/secrets/test/${name}`;
26
-
27
26
  /** sops' format for a plaintext path, as the repository's stack-secret.mjs formatFor decides it. */
28
27
  export const sopsFormatFor = (file) => {
29
- if (file.endsWith('.env')) return 'dotenv';
30
- if (file.endsWith('.json')) return 'json';
31
- if (/\.(ya?ml|kubeconfig)$/.test(file)) return 'yaml';
32
- return 'binary';
28
+ if (file.endsWith('.env'))
29
+ return 'dotenv';
30
+ if (file.endsWith('.json'))
31
+ return 'json';
32
+ if (/\.(ya?ml|kubeconfig)$/.test(file))
33
+ return 'yaml';
34
+ return 'binary';
33
35
  };
34
-
35
36
  /** Every leaf outside the `sops` block is an ENC[...] value (or null); the block itself carries a mac. */
36
37
  const allEncrypted = (node) => {
37
- if (node === null) return true;
38
- if (Array.isArray(node)) return node.every(allEncrypted);
39
- if (typeof node === 'object') return Object.values(node).every(allEncrypted);
40
- return typeof node === 'string' && SOPS_VALUE.test(node);
38
+ if (node === null)
39
+ return true;
40
+ if (Array.isArray(node))
41
+ return node.every(allEncrypted);
42
+ if (typeof node === 'object')
43
+ return Object.values(node).every(allEncrypted);
44
+ return typeof node === 'string' && SOPS_VALUE.test(node);
41
45
  };
46
+ // reason: a sops document is JSON or YAML parsed from a committed file; the envelope test reads it structurally.
42
47
  const sopsTree = (doc) => !!doc && typeof doc === 'object' && !Array.isArray(doc) && !!doc.sops && typeof doc.sops === 'object'
43
- && typeof doc.sops.mac === 'string' && SOPS_VALUE.test(doc.sops.mac)
44
- && Object.keys(doc).length > 1 && Object.entries(doc).every(([k, v]) => k === 'sops' || allEncrypted(v));
45
-
48
+ && typeof doc.sops.mac === 'string' && SOPS_VALUE.test(doc.sops.mac)
49
+ && Object.keys(doc).length > 1 && Object.entries(doc).every(([k, v]) => k === 'sops' || allEncrypted(v));
46
50
  /**
47
51
  * True only for a sops-encrypted file with no plaintext value: binary/json form ({"data": ENC[...], "sops": {...}}),
48
52
  * yaml form (every value ENC[...] plus the sops block) or dotenv form (KEY=ENC[...] lines plus sops_* metadata).
49
53
  * The sops metadata must carry its mac. A key kept plaintext through `unencrypted_suffix` does not pass.
50
54
  */
51
55
  export function isSopsEnvelope(text) {
52
- const src = String(text ?? '').replace(/^/, '');
53
- if (!src.trim()) return false;
54
- try { return sopsTree(JSON.parse(src)); } catch { /* not JSON */ }
55
- const lines = src.split(/\r?\n/).filter((l) => l.trim() && !/^\s*#/.test(l));
56
- if (lines.length && lines.every((l) => /^[A-Za-z_]\w*=/.test(l))) {
57
- const pairs = lines.map((l) => [l.slice(0, l.indexOf('=')), l.slice(l.indexOf('=') + 1)]);
58
- const meta = pairs.filter(([k]) => k.startsWith('sops_'));
59
- const vals = pairs.filter(([k]) => !k.startsWith('sops_'));
60
- return vals.length > 0 && vals.every(([, v]) => SOPS_VALUE.test(v)) && meta.some(([k, v]) => k === 'sops_mac' && SOPS_VALUE.test(v));
61
- }
62
- try { return sopsTree(parseYaml(src)); } catch { return false; }
56
+ const src = String(text ?? '').replace(/^/, '');
57
+ if (!src.trim())
58
+ return false;
59
+ try {
60
+ return sopsTree(JSON.parse(src));
61
+ }
62
+ catch { /* not JSON */ }
63
+ const lines = src.split(/\r?\n/).filter((l) => l.trim() && !/^\s*#/.test(l));
64
+ if (lines.length && lines.every((l) => /^[A-Za-z_]\w*=/.test(l))) {
65
+ const pairs = lines.map((l) => [l.slice(0, l.indexOf('=')), l.slice(l.indexOf('=') + 1)]);
66
+ const meta = pairs.filter(([k]) => k.startsWith('sops_'));
67
+ const vals = pairs.filter(([k]) => !k.startsWith('sops_'));
68
+ return vals.length > 0 && vals.every(([, v]) => SOPS_VALUE.test(v)) && meta.some(([k, v]) => k === 'sops_mac' && SOPS_VALUE.test(v));
69
+ }
70
+ try {
71
+ return sopsTree(parseYaml(src));
72
+ }
73
+ catch {
74
+ return false;
75
+ }
63
76
  }
64
-
65
77
  /** A refused admission, named by its reason. */
66
78
  const refusal = (reason) => ({ ok: false, reason });
67
-
68
79
  const DOTENV_AGE_FIELD = /^age__list_(0|[1-9]\d{0,2})__map_(recipient|enc)$/u;
69
-
70
80
  function dotenvMetadataValue(meta, age, key, value) {
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') {
76
- if (value !== 'false') return 'partial-mac';
77
- meta[key] = false;
78
- } else if (key.includes('__')) return 'unsupported-key-group';
79
- else meta[key] = value;
80
- return null;
81
+ const field = DOTENV_AGE_FIELD.exec(key);
82
+ if (field) {
83
+ const entry = (age[Number(field[1])] ??= {});
84
+ entry[field[2]] = value;
85
+ }
86
+ else if (key === 'mac_only_encrypted') {
87
+ if (value !== 'false')
88
+ return 'partial-mac';
89
+ meta[key] = false;
90
+ }
91
+ else if (key.includes('__'))
92
+ return 'unsupported-key-group';
93
+ else
94
+ meta[key] = value;
95
+ return null;
81
96
  }
82
-
83
97
  function readDotenvMetadata(text) {
84
- const pairs = new Map();
85
- for (const line of String(text).split('\n')) {
86
- if (!line || line.startsWith('#')) continue;
87
- if (line.includes('\r')) return { refusal: 'unsupported-dotenv' };
88
- const at = line.indexOf('=');
89
- if (at < 1) return { refusal: 'unsupported-dotenv' };
90
- const name = line.slice(0, at);
91
- if (pairs.has(name)) return { refusal: 'duplicate-key' };
92
- pairs.set(name, line.slice(at + 1).replaceAll(String.raw`\n`, '\n'));
93
- }
94
- const meta = {};
95
- const age = [];
96
- for (const [name, value] of pairs) {
97
- if (!name.startsWith('sops_')) continue;
98
- const reason = dotenvMetadataValue(meta, age, name.slice('sops_'.length), value);
99
- if (reason) return { refusal: reason };
100
- }
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);
103
- return { meta };
98
+ const pairs = new Map();
99
+ for (const line of String(text).split('\n')) {
100
+ if (!line || line.startsWith('#'))
101
+ continue;
102
+ if (line.includes('\r'))
103
+ return { refusal: 'unsupported-dotenv' };
104
+ const at = line.indexOf('=');
105
+ if (at < 1)
106
+ return { refusal: 'unsupported-dotenv' };
107
+ const name = line.slice(0, at);
108
+ if (pairs.has(name))
109
+ return { refusal: 'duplicate-key' };
110
+ pairs.set(name, line.slice(at + 1).replaceAll(String.raw `\n`, '\n'));
111
+ }
112
+ const meta = {};
113
+ const age = [];
114
+ for (const [name, value] of pairs) {
115
+ if (!name.startsWith('sops_'))
116
+ continue;
117
+ const reason = dotenvMetadataValue(meta, age, name.slice('sops_'.length), value);
118
+ if (reason)
119
+ return { refusal: reason };
120
+ }
121
+ // A gap in the list indices is an entry sops never wrote: refused as an empty entry, never skipped.
122
+ meta.age = Array.from(age, (entry) => entry ?? null);
123
+ return { meta };
104
124
  }
105
-
106
125
  function readStructuredMetadata(text, format) {
107
- const doc = parseYaml(String(text));
108
- if (format !== 'yaml') JSON.parse(String(text));
109
- if (format === 'binary' && (!doc || Object.keys(doc).length !== 2 || !Object.hasOwn(doc, 'data') || !Object.hasOwn(doc, 'sops') || typeof doc.data !== 'string'))
110
- return { refusal: 'unsupported-binary-shape' };
111
- return { meta: doc?.sops };
126
+ const doc = parseYaml(String(text));
127
+ if (format !== 'yaml')
128
+ JSON.parse(String(text));
129
+ if (format === 'binary' && (!doc || Object.keys(doc).length !== 2 || !Object.hasOwn(doc, 'data') || !Object.hasOwn(doc, 'sops') || typeof doc.data !== 'string'))
130
+ return { refusal: 'unsupported-binary-shape' };
131
+ return { meta: doc?.sops };
112
132
  }
113
-
114
133
  function readAgeMetadata(text, format) {
115
- try {
116
- return format === 'dotenv' ? readDotenvMetadata(text) : readStructuredMetadata(text, format);
117
- } catch { return { refusal: 'invalid-envelope' }; }
134
+ try {
135
+ return format === 'dotenv' ? readDotenvMetadata(text) : readStructuredMetadata(text, format);
136
+ }
137
+ catch {
138
+ return { refusal: 'invalid-envelope' };
139
+ }
118
140
  }
119
-
120
141
  function hasNonAgeProvider(meta, providers) {
121
- for (const name of providers) {
122
- if (Object.hasOwn(meta, name) && (!Array.isArray(meta[name]) || meta[name].length)) return true;
123
- }
124
- return false;
142
+ for (const name of providers) {
143
+ const provider = meta[name];
144
+ if (Object.hasOwn(meta, name) && (!Array.isArray(provider) || provider.length))
145
+ return true;
146
+ }
147
+ return false;
125
148
  }
126
-
127
149
  function isAgeEntry(entry) {
128
- return !!entry && typeof entry === 'object' && !Array.isArray(entry)
129
- && !Object.keys(entry).some(name => !['recipient', 'enc'].includes(name));
150
+ return !!entry && typeof entry === 'object' && !Array.isArray(entry)
151
+ && !Object.keys(entry).some(name => !['recipient', 'enc'].includes(name));
130
152
  }
131
-
132
153
  function hasValidAgePayload(entry) {
133
- return typeof entry.enc === 'string' && entry.enc.startsWith('-----BEGIN AGE ENCRYPTED FILE-----\n')
134
- && entry.enc.includes('\n-----END AGE ENCRYPTED FILE-----');
154
+ return typeof entry.enc === 'string' && entry.enc.startsWith('-----BEGIN AGE ENCRYPTED FILE-----\n')
155
+ && entry.enc.includes('\n-----END AGE ENCRYPTED FILE-----');
135
156
  }
136
-
137
157
  function hasValidEnvelopeVersion(meta) {
138
- return typeof meta.version === 'string' && /^\d+\.\d+\.\d+$/.test(meta.version)
139
- && typeof meta.lastmodified === 'string' && Number.isFinite(Date.parse(meta.lastmodified));
158
+ return typeof meta.version === 'string' && /^\d+\.\d+\.\d+$/.test(meta.version)
159
+ && typeof meta.lastmodified === 'string' && Number.isFinite(Date.parse(meta.lastmodified));
140
160
  }
141
-
142
161
  function validateAgeMetadata(meta, text, recipient) {
143
- if (!meta || typeof meta !== 'object' || Array.isArray(meta) || !isSopsEnvelope(text)) return refusal('invalid-envelope');
144
- if (Object.hasOwn(meta, 'key_groups') || Object.hasOwn(meta, 'shamir_threshold')) return refusal('unsupported-key-group');
145
- const providers = ['kms', 'gcp_kms', 'hckms', 'azure_kv', 'hc_vault', 'pgp'];
146
- if (hasNonAgeProvider(meta, providers)) return refusal('non-age-provider');
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']);
148
- if (Object.keys(meta).some(name => !fields.has(name))) return refusal('unknown-metadata');
149
- if (Object.hasOwn(meta, 'mac_only_encrypted') && meta.mac_only_encrypted !== false) return refusal('partial-mac');
150
- const set = ageSet(meta.age);
151
- if (!set.ok) return set;
152
- if (!set.recipients.includes(recipient)) return refusal('recipient-mismatch');
153
- if (!hasValidEnvelopeVersion(meta)) return refusal('invalid-envelope');
154
- return { ok: true };
162
+ if (!meta || typeof meta !== 'object' || Array.isArray(meta) || !isSopsEnvelope(text))
163
+ return refusal('invalid-envelope');
164
+ if (Object.hasOwn(meta, 'key_groups') || Object.hasOwn(meta, 'shamir_threshold'))
165
+ return refusal('unsupported-key-group');
166
+ const providers = ['kms', 'gcp_kms', 'hckms', 'azure_kv', 'hc_vault', 'pgp'];
167
+ if (hasNonAgeProvider(meta, providers))
168
+ return refusal('non-age-provider');
169
+ 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']);
170
+ if (Object.keys(meta).some(name => !fields.has(name)))
171
+ return refusal('unknown-metadata');
172
+ if (Object.hasOwn(meta, 'mac_only_encrypted') && meta.mac_only_encrypted !== false)
173
+ return refusal('partial-mac');
174
+ const set = ageSet(meta.age);
175
+ if (!set.ok)
176
+ return set;
177
+ if (!set.recipients.includes(recipient))
178
+ return refusal('recipient-mismatch');
179
+ if (!hasValidEnvelopeVersion(meta))
180
+ return refusal('invalid-envelope');
181
+ return { ok: true };
155
182
  }
156
-
157
183
  const AGE_RECIPIENT = /^age1[ac-hj-np-z02-9]+$/u;
158
-
159
184
  /**
160
185
  * 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
186
  * well-formed recipient with its wrapped data key; an empty entry or a recipient named twice is refused.
162
187
  */
163
188
  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 };
189
+ if (!Array.isArray(entries) || entries.length === 0)
190
+ return refusal('unsupported-age-set');
191
+ const recipients = [];
192
+ for (const entry of entries) {
193
+ if (!isAgeEntry(entry) || typeof entry.recipient !== 'string' || !AGE_RECIPIENT.test(entry.recipient) || !hasValidAgePayload(entry))
194
+ return refusal('invalid-age-entry');
195
+ if (recipients.includes(entry.recipient))
196
+ return refusal('duplicate-age-recipient');
197
+ recipients.push(entry.recipient);
198
+ }
199
+ return { ok: true, recipients };
173
200
  }
174
-
175
201
  /**
176
202
  * Admit one flat age envelope for the native selected-identity invocation when `recipient` (the selected identity's public key) is
177
203
  * one of its age set. Shape admission, never cryptographic proof.
178
204
  */
179
205
  export function selectedAgeEnvelope(text, format, recipient) {
180
- if (!['binary', 'json', 'yaml', 'dotenv'].includes(format)) return refusal('unsupported-format');
181
- const parsed = readAgeMetadata(text, format);
182
- if (parsed.refusal) return refusal(parsed.refusal);
183
- return validateAgeMetadata(parsed.meta, text, recipient);
206
+ if (!['binary', 'json', 'yaml', 'dotenv'].includes(format))
207
+ return refusal('unsupported-format');
208
+ const parsed = readAgeMetadata(text, format);
209
+ if (parsed.refusal)
210
+ return refusal(parsed.refusal);
211
+ return validateAgeMetadata(parsed.meta, text, recipient);
184
212
  }