@jini-ai/devops 0.7.1 → 0.7.3-next.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.
Files changed (108) hide show
  1. package/CHANGELOG.md +2 -2
  2. package/README.md +8 -4
  3. package/dist/agent-jobs/jobs.d.ts +1 -1
  4. package/dist/agent-jobs/jobs.js +4 -3
  5. package/dist/agent-jobs/node.d.ts +2 -2
  6. package/dist/agent-jobs/node.js +2 -2
  7. package/dist/backup/plan-store.node.d.ts +73 -0
  8. package/dist/backup/plan-store.node.js +60 -0
  9. package/dist/backup/push-jobs.d.ts +88 -0
  10. package/dist/backup/push-jobs.js +95 -0
  11. package/dist/backup/upload.node.d.ts +71 -0
  12. package/dist/backup/upload.node.js +122 -0
  13. package/dist/checks/coverage/diff.d.ts +2 -2
  14. package/dist/checks/coverage/diff.js +2 -2
  15. package/dist/checks/coverage/disk.d.ts +5 -5
  16. package/dist/checks/coverage/disk.js +5 -5
  17. package/dist/checks/coverage/floors.d.ts +2 -2
  18. package/dist/checks/coverage/floors.js +2 -2
  19. package/dist/checks/coverage/integrity.d.ts +10 -5
  20. package/dist/checks/coverage/integrity.js +12 -5
  21. package/dist/checks/coverage/lcov.d.ts +8 -8
  22. package/dist/checks/coverage/lcov.js +8 -8
  23. package/dist/checks/env-access.d.ts +37 -0
  24. package/dist/checks/env-access.js +57 -0
  25. package/dist/checks/hardwiring-node.d.ts +6 -3
  26. package/dist/checks/hardwiring-node.js +7 -6
  27. package/dist/checks/hardwiring.d.ts +32 -8
  28. package/dist/checks/hardwiring.js +395 -338
  29. package/dist/checks/node.d.ts +2 -2
  30. package/dist/checks/node.js +2 -2
  31. package/dist/checks/published-types/index.d.ts +10 -4
  32. package/dist/checks/published-types/index.js +30 -9
  33. package/dist/core/redirect-guard.d.ts +2 -2
  34. package/dist/core/redirect-guard.js +2 -2
  35. package/dist/deploy/adapters/undici.d.ts +8 -0
  36. package/dist/deploy/adapters/undici.js +6 -0
  37. package/dist/deploy/config-injection.d.ts +43 -0
  38. package/dist/deploy/config-injection.js +60 -0
  39. package/dist/deploy/index.d.ts +1 -0
  40. package/dist/deploy/index.js +1 -0
  41. package/dist/deploy/naming.d.ts +2 -2
  42. package/dist/deploy/naming.js +2 -2
  43. package/dist/deploy/node.d.ts +17 -6
  44. package/dist/deploy/node.js +8 -9
  45. package/dist/deploy/ops-runner.d.ts +8 -6
  46. package/dist/deploy/ops-runner.js +7 -6
  47. package/dist/deploy/ops-tool-contracts.d.ts +2 -1
  48. package/dist/deploy/ops-tools.js +1 -1
  49. package/dist/deploy/reachability.d.ts +1 -1
  50. package/dist/deploy/reachability.js +1 -1
  51. package/dist/deploy/react/PublishRunResult.d.ts +24 -0
  52. package/dist/deploy/react/PublishRunResult.js +25 -0
  53. package/dist/deploy/react/index.d.ts +3 -0
  54. package/dist/deploy/react/index.js +2 -0
  55. package/dist/deploy/tool.d.ts +1 -1
  56. package/dist/deploy/tool.js +1 -1
  57. package/dist/dns/delegation.d.ts +2 -2
  58. package/dist/dns/delegation.js +5 -5
  59. package/dist/dns/node/resolver.js +30 -29
  60. package/dist/dns/verify.d.ts +1 -2
  61. package/dist/dns/verify.js +3 -3
  62. package/dist/local-dev/free-port.d.ts +25 -0
  63. package/dist/local-dev/free-port.js +44 -0
  64. package/dist/local-dev/index.d.ts +4 -3
  65. package/dist/local-dev/index.js +4 -3
  66. package/dist/local-dev/node-runtime.d.ts +2 -2
  67. package/dist/local-dev/node-runtime.js +1 -1
  68. package/dist/packaging/electron/archive.d.ts +5 -5
  69. package/dist/packaging/electron/archive.js +5 -5
  70. package/dist/packaging/electron/asar-adapter.d.ts +1 -1
  71. package/dist/packaging/electron/asar-adapter.js +1 -1
  72. package/dist/packaging/electron/entry.d.ts +4 -0
  73. package/dist/packaging/electron/entry.js +4 -0
  74. package/dist/packaging/electron/imports.d.ts +2 -2
  75. package/dist/packaging/electron/imports.js +2 -2
  76. package/dist/packaging/electron/isolation.d.ts +36 -0
  77. package/dist/packaging/electron/isolation.js +64 -0
  78. package/dist/packaging/electron/node.d.ts +2 -2
  79. package/dist/packaging/electron/node.js +2 -2
  80. package/dist/packaging/electron/payload-scan.d.ts +17 -0
  81. package/dist/packaging/electron/payload-scan.js +20 -0
  82. package/dist/packaging/electron/policies.d.ts +6 -6
  83. package/dist/packaging/electron/policies.js +6 -6
  84. package/dist/packaging/electron/stability.d.ts +1 -1
  85. package/dist/packaging/electron/stability.js +1 -1
  86. package/dist/packaging/electron/staging.d.ts +11 -11
  87. package/dist/packaging/electron/staging.js +11 -11
  88. package/dist/packaging/electron/tree-fingerprint.d.ts +31 -0
  89. package/dist/packaging/electron/tree-fingerprint.js +59 -0
  90. package/dist/packaging/electron/typescript.d.ts +8 -2
  91. package/dist/packaging/electron/typescript.js +108 -99
  92. package/dist/packaging/electron/update-manifest-merge.d.ts +53 -0
  93. package/dist/packaging/electron/update-manifest-merge.js +82 -0
  94. package/dist/source-control/commit.d.ts +19 -3
  95. package/dist/source-control/commit.js +99 -16
  96. package/dist/source-control/contracts.d.ts +20 -1
  97. package/dist/source-control/kit.d.ts +1 -1
  98. package/dist/source-control/kit.js +1 -1
  99. package/dist/source-control/registry.d.ts +2 -2
  100. package/dist/source-control/registry.js +2 -2
  101. package/dist/static-export/css-urls.d.ts +3 -1
  102. package/dist/static-export/css-urls.js +1 -1
  103. package/dist/static-export/fetch-adapter.d.ts +1 -1
  104. package/dist/static-export/fetch-adapter.js +1 -1
  105. package/dist/static-export/html-url-locations.js +1 -1
  106. package/dist/static-export/transforms.d.ts +4 -4
  107. package/dist/static-export/transforms.js +6 -6
  108. package/package.json +48 -14
@@ -1,104 +1,113 @@
1
- /** Read syntax with the host's maintained parser. No module is executed. O(source length). */
2
- export function runtimeImportReferences({ compiler: c, file, source }, _options = {}) {
3
- const tree = c.createSourceFile(file, source, c.ScriptTarget.Latest, true, file.endsWith('.tsx') ? c.ScriptKind.TSX : c.ScriptKind.TS);
4
- const scopes = new Map();
5
- const found = [];
6
- function scopeOf(node) {
7
- let parent = node.parent;
8
- while (parent && !c.isBlock(parent) && !c.isFunctionLike(parent) && !c.isSourceFile(parent))
9
- parent = parent.parent;
10
- return parent ?? tree;
11
- }
12
- function lookup(node) {
13
- let scope = scopeOf(node);
14
- while (scope) {
15
- const value = scopes.get(scope)?.get(node.text);
16
- if (value)
17
- return value;
18
- scope = scope === tree ? undefined : scopeOf(scope);
19
- }
20
- if (node.text === 'require')
21
- return 'require';
22
- return node.text === 'createRequire' ? 'creator' : undefined;
23
- }
24
- function isCreator(node) {
25
- if (c.isIdentifier(node))
26
- return lookup(node) === 'creator';
27
- return c.isPropertyAccessExpression(node) && node.name.text === 'createRequire';
28
- }
29
- function bind(node, name, value) {
30
- const scope = scopeOf(node);
31
- const values = scopes.get(scope) ?? new Map();
32
- values.set(name, value);
33
- scopes.set(scope, values);
34
- }
35
- function variableBinding(node) {
36
- if (!c.isVariableDeclaration(node) || !c.isIdentifier(node.name))
37
- return;
38
- const init = node.initializer;
39
- const value = init && c.isCallExpression(init) && isCreator(init.expression) ? 'require' : 'other';
40
- bind(node, node.name.text, value);
41
- }
42
- /** A declared function or class (e.g. a factory-local `function require(capability)`) shadows the module require in its scope. */
43
- function declarationBinding(node) {
44
- if ((c.isFunctionDeclaration(node) || c.isClassDeclaration(node)) && node.name)
45
- bind(node, node.name.text, 'other');
46
- }
47
- function bindings(node) {
48
- if (c.isImportSpecifier(node) && (node.propertyName ?? node.name).text === 'createRequire')
49
- bind(node, node.name.text, 'creator');
50
- if (c.isParameter(node) && c.isIdentifier(node.name))
51
- bind(node, node.name.text, 'other');
52
- variableBinding(node);
53
- declarationBinding(node);
54
- c.forEachChild(node, bindings);
55
- }
56
- bindings(tree);
57
- function isRequire(node) {
58
- if (c.isIdentifier(node))
59
- return lookup(node) === 'require';
60
- return c.isCallExpression(node) && isCreator(node.expression);
61
- }
62
- function inlineTypes(clause) {
63
- if (!clause)
64
- return false;
65
- if (!c.isNamedImports(clause) && !c.isNamedExports(clause))
66
- return false;
67
- return clause.elements.length > 0 && clause.elements.every(e => e.isTypeOnly);
68
- }
69
- function erased(node) {
70
- if (c.isImportDeclaration(node)) {
71
- const clause = node.importClause;
72
- return Boolean(clause?.isTypeOnly || (!clause?.name && inlineTypes(clause?.namedBindings)));
73
- }
74
- return node.isTypeOnly || inlineTypes(node.exportClause);
75
- }
76
- function callReference(node) {
77
- if (node.expression.kind === c.SyntaxKind.ImportKeyword)
78
- return { literal: node.arguments[0], kind: 'import' };
79
- const call = node.expression;
80
- if (isRequire(call))
81
- return { literal: node.arguments[0], kind: 'require' };
82
- if (c.isPropertyAccessExpression(call) && call.name.text === 'resolve' && isRequire(call.expression))
83
- return { literal: node.arguments[0], kind: 'require' };
84
- return undefined;
85
- }
86
- function reference(node) {
87
- if (c.isImportDeclaration(node) || c.isExportDeclaration(node))
88
- return { literal: node.moduleSpecifier, kind: 'import', typeOnly: erased(node) };
89
- if (c.isImportEqualsDeclaration(node) && c.isExternalModuleReference(node.moduleReference))
90
- return { literal: node.moduleReference.expression, kind: 'require', typeOnly: node.isTypeOnly };
91
- return c.isCallExpression(node) ? callReference(node) : undefined;
1
+ function scopeOf({ c, tree }, node) {
2
+ let parent = node.parent;
3
+ while (parent && !c.isBlock(parent) && !c.isFunctionLike(parent) && !c.isSourceFile(parent))
4
+ parent = parent.parent;
5
+ return parent ?? tree;
6
+ }
7
+ function lookup(scan, node) {
8
+ let scope = scopeOf(scan, node);
9
+ while (scope) {
10
+ const value = scan.scopes.get(scope)?.get(node.text);
11
+ if (value)
12
+ return value;
13
+ scope = scope === scan.tree ? undefined : scopeOf(scan, scope);
92
14
  }
93
- function visit(node, deferred = false) {
94
- const ref = reference(node);
95
- if (ref?.literal && c.isStringLiteralLike(ref.literal))
96
- found.push({ specifier: ref.literal.text, kind: ref.kind,
97
- typeOnly: ref.typeOnly ?? false, line: tree.getLineAndCharacterOfPosition(node.getStart(tree)).line + 1, deferred });
98
- const nested = deferred || c.isFunctionLike(node);
99
- c.forEachChild(node, child => visit(child, nested));
15
+ if (node.text === 'require')
16
+ return 'require';
17
+ return node.text === 'createRequire' ? 'creator' : undefined;
18
+ }
19
+ function isCreator(scan, node) {
20
+ const { c } = scan;
21
+ if (c.isIdentifier(node))
22
+ return lookup(scan, node) === 'creator';
23
+ return c.isPropertyAccessExpression(node) && node.name.text === 'createRequire';
24
+ }
25
+ function bind({ scan, node, name, value }) {
26
+ const scope = scopeOf(scan, node);
27
+ const values = scan.scopes.get(scope) ?? new Map();
28
+ values.set(name, value);
29
+ scan.scopes.set(scope, values);
30
+ }
31
+ function variableBinding(scan, node) {
32
+ const { c } = scan;
33
+ if (!c.isVariableDeclaration(node) || !c.isIdentifier(node.name))
34
+ return;
35
+ const init = node.initializer;
36
+ const value = init && c.isCallExpression(init) && isCreator(scan, init.expression) ? 'require' : 'other';
37
+ bind({ scan, node, name: node.name.text, value });
38
+ }
39
+ /** A declared function or class (e.g. a factory-local `function require(capability)`) shadows the module require in its scope. */
40
+ function declarationBinding(scan, node) {
41
+ const { c } = scan;
42
+ if ((c.isFunctionDeclaration(node) || c.isClassDeclaration(node)) && node.name)
43
+ bind({ scan, node, name: node.name.text, value: 'other' });
44
+ }
45
+ function collectBindings(scan, node) {
46
+ const { c } = scan;
47
+ if (c.isImportSpecifier(node) && (node.propertyName ?? node.name).text === 'createRequire')
48
+ bind({ scan, node, name: node.name.text, value: 'creator' });
49
+ if (c.isParameter(node) && c.isIdentifier(node.name))
50
+ bind({ scan, node, name: node.name.text, value: 'other' });
51
+ variableBinding(scan, node);
52
+ declarationBinding(scan, node);
53
+ c.forEachChild(node, child => collectBindings(scan, child));
54
+ }
55
+ function isRequire(scan, node) {
56
+ const { c } = scan;
57
+ if (c.isIdentifier(node))
58
+ return lookup(scan, node) === 'require';
59
+ return c.isCallExpression(node) && isCreator(scan, node.expression);
60
+ }
61
+ function inlineTypes({ c }, clause) {
62
+ if (!clause)
63
+ return false;
64
+ if (!c.isNamedImports(clause) && !c.isNamedExports(clause))
65
+ return false;
66
+ return clause.elements.length > 0 && clause.elements.every(e => e.isTypeOnly);
67
+ }
68
+ function erased({ scan, node }) {
69
+ if (scan.c.isImportDeclaration(node)) {
70
+ const clause = node.importClause;
71
+ return Boolean(clause?.isTypeOnly || (!clause?.name && inlineTypes(scan, clause?.namedBindings)));
100
72
  }
101
- visit(tree);
73
+ return node.isTypeOnly || inlineTypes(scan, node.exportClause);
74
+ }
75
+ function callReference(scan, node) {
76
+ const { c } = scan;
77
+ if (node.expression.kind === c.SyntaxKind.ImportKeyword)
78
+ return { literal: node.arguments[0], kind: 'import', syntax: 'dynamic' };
79
+ const call = node.expression;
80
+ if (isRequire(scan, call))
81
+ return { literal: node.arguments[0], kind: 'require', syntax: 'require' };
82
+ if (c.isPropertyAccessExpression(call) && call.name.text === 'resolve' && isRequire(scan, call.expression))
83
+ return { literal: node.arguments[0], kind: 'require', syntax: 'require' };
84
+ return undefined;
85
+ }
86
+ function reference(scan, node) {
87
+ const { c } = scan;
88
+ if (c.isImportDeclaration(node) || c.isExportDeclaration(node))
89
+ return { literal: node.moduleSpecifier, kind: 'import', syntax: c.isImportDeclaration(node) ? 'import' : 'export', typeOnly: erased({ scan, node }) };
90
+ if (c.isImportEqualsDeclaration(node) && c.isExternalModuleReference(node.moduleReference))
91
+ return { literal: node.moduleReference.expression, kind: 'require', syntax: 'import-equals', typeOnly: node.isTypeOnly };
92
+ return c.isCallExpression(node) ? callReference(scan, node) : undefined;
93
+ }
94
+ function visitReferences(scan, found, node, deferred = false) {
95
+ const { c, tree } = scan;
96
+ const ref = reference(scan, node);
97
+ if (ref?.literal && c.isStringLiteralLike(ref.literal))
98
+ found.push({ specifier: ref.literal.text, kind: ref.kind, syntax: ref.syntax,
99
+ typeOnly: ref.typeOnly ?? false, line: tree.getLineAndCharacterOfPosition(node.getStart(tree)).line + 1, deferred });
100
+ const nested = deferred || c.isFunctionLike(node);
101
+ c.forEachChild(node, child => visitReferences(scan, found, child, nested));
102
+ }
103
+ /** Read syntax with the host's maintained parser. No module is executed. O(source length).
104
+ * A caller that already parsed the file passes its `tree` so the source is parsed once. */
105
+ export function runtimeImportReferences({ compiler: c, file, source }, { tree: parsed } = {}) {
106
+ const tree = parsed ?? c.createSourceFile(file, source, c.ScriptTarget.Latest, true, file.endsWith('.tsx') ? c.ScriptKind.TSX : c.ScriptKind.TS);
107
+ const scan = { c, tree, scopes: new Map() };
108
+ const found = [];
109
+ collectBindings(scan, tree);
110
+ visitReferences(scan, found, tree);
102
111
  return found;
103
112
  }
104
113
  /** Bind one parser owner for static, dynamic, CommonJS and createRequire references. */
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @file Merges the two per-arch `latest-mac.yml` update manifests into the one the release carries.
3
+ *
4
+ * The release workflow builds mac-arm64 and mac-x64 on separate runners (each on its own CPU, never
5
+ * cross-built), so each job's electron-builder writes a `latest-mac.yml` listing only ITS zip. A
6
+ * GitHub release can hold one `latest-mac.yml`, and `electron-updater`'s MacUpdater reads that one
7
+ * file on every Mac and picks the zip by arch: a file whose URL contains `arm64` on Apple Silicon,
8
+ * any file WITHOUT `arm64` on Intel. Upload either job's file alone and the other arch updates to a
9
+ * binary for the wrong CPU, or finds no zip at all. So the release job merges them here and refuses
10
+ * anything that would make that choice ambiguous.
11
+ *
12
+ * Only the zips are kept. MacUpdater installs from nothing else, and the dmg entries would be WRONG:
13
+ * the workflow notarizes and staples the dmg after electron-builder wrote this manifest, which
14
+ * changes its bytes, so the checksum listed for it no longer matches the file on the release.
15
+ *
16
+ * Parsing and printing YAML is the caller's job (`scripts/merge-latest-mac.ts`); this file works on
17
+ * the parsed objects so it runs under plain `node --test` with no dependency.
18
+ */
19
+ /** One entry of an update manifest's `files` list, as electron-builder writes it. */
20
+ interface UpdateFileEntry {
21
+ url: string;
22
+ sha512: string;
23
+ size?: number;
24
+ blockMapSize?: number;
25
+ [key: string]: unknown;
26
+ }
27
+ /** An electron-builder update manifest (`latest-mac.yml`). */
28
+ interface UpdateManifest {
29
+ version: string;
30
+ files: UpdateFileEntry[];
31
+ path?: string;
32
+ sha512?: string;
33
+ releaseDate?: string;
34
+ [key: string]: unknown;
35
+ }
36
+ /**
37
+ * @param required.inputs the parsed per-arch manifests, each with a label for error messages.
38
+ * @returns one manifest listing every input's zips (see this file's header for why only zips). Its legacy top-level `path`/`sha512` name the
39
+ * Intel zip: a very old updater that reads only those gets a build that runs everywhere (Apple
40
+ * Silicon through Rosetta), never an arm64 build on an Intel Mac.
41
+ * @throws {Error} when the inputs disagree on version, one URL appears with two checksums, or the
42
+ * result does not hold exactly one arm64 zip and exactly one other zip.
43
+ * @complexity O(n) in files.
44
+ */
45
+ declare function mergeMacManifests({ inputs }: {
46
+ inputs: ReadonlyArray<{
47
+ label: string;
48
+ manifest: unknown;
49
+ }>;
50
+ }, _options?: {}): UpdateManifest;
51
+ export { mergeMacManifests };
52
+ export type { UpdateFileEntry, UpdateManifest };
53
+ //# sourceMappingURL=update-manifest-merge.d.ts.map
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @file Merges the two per-arch `latest-mac.yml` update manifests into the one the release carries.
3
+ *
4
+ * The release workflow builds mac-arm64 and mac-x64 on separate runners (each on its own CPU, never
5
+ * cross-built), so each job's electron-builder writes a `latest-mac.yml` listing only ITS zip. A
6
+ * GitHub release can hold one `latest-mac.yml`, and `electron-updater`'s MacUpdater reads that one
7
+ * file on every Mac and picks the zip by arch: a file whose URL contains `arm64` on Apple Silicon,
8
+ * any file WITHOUT `arm64` on Intel. Upload either job's file alone and the other arch updates to a
9
+ * binary for the wrong CPU, or finds no zip at all. So the release job merges them here and refuses
10
+ * anything that would make that choice ambiguous.
11
+ *
12
+ * Only the zips are kept. MacUpdater installs from nothing else, and the dmg entries would be WRONG:
13
+ * the workflow notarizes and staples the dmg after electron-builder wrote this manifest, which
14
+ * changes its bytes, so the checksum listed for it no longer matches the file on the release.
15
+ *
16
+ * Parsing and printing YAML is the caller's job (`scripts/merge-latest-mac.ts`); this file works on
17
+ * the parsed objects so it runs under plain `node --test` with no dependency.
18
+ */
19
+ const isArm64 = (entry) => entry.url.includes("arm64");
20
+ const isZip = (entry) => entry.url.endsWith(".zip");
21
+ /** @throws {Error} unless `value` has a string `version` and a `files` array of `{url, sha512}`. */
22
+ function assertManifest({ value, label }) {
23
+ const manifest = value;
24
+ if (typeof manifest?.version !== "string" || !Array.isArray(manifest.files)) {
25
+ throw new Error(`${label}: not an update manifest (needs version and files)`);
26
+ }
27
+ for (const entry of manifest.files) {
28
+ if (typeof entry?.url !== "string" || typeof entry.sha512 !== "string") {
29
+ throw new Error(`${label}: every files entry needs url and sha512`);
30
+ }
31
+ }
32
+ return manifest;
33
+ }
34
+ /**
35
+ * @param required.inputs the parsed per-arch manifests, each with a label for error messages.
36
+ * @returns one manifest listing every input's zips (see this file's header for why only zips). Its legacy top-level `path`/`sha512` name the
37
+ * Intel zip: a very old updater that reads only those gets a build that runs everywhere (Apple
38
+ * Silicon through Rosetta), never an arm64 build on an Intel Mac.
39
+ * @throws {Error} when the inputs disagree on version, one URL appears with two checksums, or the
40
+ * result does not hold exactly one arm64 zip and exactly one other zip.
41
+ * @complexity O(n) in files.
42
+ */
43
+ function mergeMacManifests({ inputs }, _options = {}) {
44
+ if (inputs.length === 0)
45
+ throw new Error("no manifests to merge");
46
+ const manifests = inputs.map(({ label, manifest }) => assertManifest({ value: manifest, label }));
47
+ const [first] = manifests;
48
+ if (first === undefined)
49
+ throw new Error("no manifests to merge");
50
+ const mismatch = manifests.find((manifest) => manifest.version !== first.version);
51
+ if (mismatch)
52
+ throw new Error(`version mismatch: ${first.version} vs ${mismatch.version}`);
53
+ const files = unionFiles({ manifests }).filter(isZip);
54
+ const intelZip = onlyIntelZip({ files });
55
+ const releaseDate = manifests.map((manifest) => manifest.releaseDate).filter((date) => typeof date === "string").sort().at(-1);
56
+ return { ...first, files, path: intelZip.url, sha512: intelZip.sha512, ...(releaseDate ? { releaseDate } : {}) };
57
+ }
58
+ /** Every input's files, each URL once. @throws {Error} on one URL with two checksums. @complexity O(n). */
59
+ function unionFiles({ manifests }, _options = {}) {
60
+ const files = new Map();
61
+ for (const entry of manifests.flatMap((manifest) => manifest.files)) {
62
+ const seen = files.get(entry.url);
63
+ if (seen && seen.sha512 !== entry.sha512)
64
+ throw new Error(`${entry.url} listed with two different checksums`);
65
+ files.set(entry.url, entry);
66
+ }
67
+ return [...files.values()];
68
+ }
69
+ /** @returns the one non-arm64 zip. @throws {Error} unless there is exactly one arm64 zip and one
70
+ * other zip — the only shape MacUpdater's arch choice is unambiguous for. @complexity O(n). */
71
+ function onlyIntelZip({ files }, _options = {}) {
72
+ const zips = files.filter(isZip);
73
+ const arm = zips.filter(isArm64);
74
+ const intel = zips.filter((entry) => !isArm64(entry));
75
+ const [intelZip] = intel;
76
+ if (arm.length !== 1 || intel.length !== 1 || intelZip === undefined) {
77
+ throw new Error(`expected one arm64 zip and one x64 zip, got [${zips.map((entry) => entry.url).join(", ")}]`);
78
+ }
79
+ return intelZip;
80
+ }
81
+ export { mergeMacManifests };
82
+ //# sourceMappingURL=update-manifest-merge.js.map
@@ -1,11 +1,27 @@
1
1
  import type { CommitExportArgs, CommitFile, CommitOptions, CommitOrchestrationArgs, PreviewCommitExportResult, SourceControlCommitOutcome } from './contracts.js';
2
- /** Normalize platform separators without changing the retained byte payload. */
2
+ /** Normalize platform separators without changing the retained byte payload. An export's `outputFile` is already
3
+ * commit-relative but uses the platform separator (`path.relative`), and a stray backslash from a Windows host would
4
+ * be a wrong path in a git tree entry, not a normalized one. */
3
5
  export declare function toCommitFile(required: {
4
6
  outputFile: string;
5
7
  data: string | Buffer;
6
8
  }): CommitFile;
7
- /** Run a real fresh export, without credentials or repository I/O. */
9
+ /**
10
+ * Run a real fresh export, without credentials or repository I/O: the file count and byte total are real, not
11
+ * estimated, and the answer is a summary instead of a commit. It validates like the commit does and never
12
+ * resolves a credential or calls the provider (no network before a human has confirmed). `paths` is sorted and
13
+ * capped at 50 so a large export cannot blow out a dry-run answer.
14
+ * @complexity One export pass; no credential read, no provider call.
15
+ */
8
16
  export declare function previewCommitExport(required: CommitExportArgs, optional?: CommitOptions): Promise<PreviewCommitExportResult>;
9
- /** Resolve one provider's credential, export into an isolated host-owned directory and commit once. */
17
+ /**
18
+ * Resolve one provider's credential, export into an isolated host-owned directory and commit once.
19
+ *
20
+ * Always runs a FRESH export immediately before committing and never reuses an earlier export directory:
21
+ * correctness over one extra pass. The target is validated here even when the caller already validated it
22
+ * before opening a confirmation dialog (defense in depth for a caller that skips that check).
23
+ * This function reads as one guard per phase (credential, export, commit) rather than one long chain.
24
+ * @complexity One export pass (O(routes + assets) requests against the host's own app) plus one provider call.
25
+ */
10
26
  export declare function commitSiteToSourceControl(required: CommitOrchestrationArgs, optional?: CommitOptions): Promise<SourceControlCommitOutcome>;
11
27
  //# sourceMappingURL=commit.d.ts.map
@@ -1,6 +1,24 @@
1
+ import { redactSecrets } from '@jini-ai/core';
1
2
  import { firstExportFailure } from '../core/export-failure-summary.js';
2
3
  import { validateCommitTarget } from './repository-target.js';
3
4
  import { normalizeRepositoryFolder, prefixRepositoryPath } from './repository-path.js';
5
+ /**
6
+ * @file Source-control commit orchestration: validate the target, resolve a credential, run one fresh
7
+ * export into an isolated directory, then hand the files to a provider in ONE call.
8
+ *
9
+ * Wrap, do not reimplement: the host's own exporter runs behind `FileSourcePort`, the provider's HTTP lives
10
+ * behind `adapter`, and this module does neither. A commit is not a hosted site, so no export here ever
11
+ * takes a base path. The destination is the repository root or one explicit folder: the provider owns the
12
+ * folder prefix and the folder-local reconciliation, the host owns any packaging of the files (see
13
+ * `CommitLayoutPort.arrangeFiles`).
14
+ *
15
+ * Never throws for an expected outcome. Every failure (invalid target, no credential, a credential store
16
+ * that throws, a failed export, a refused provider call, a provider that throws) is RETURNED as
17
+ * `{ ok: false, code, message }`, because the caller is a tool handler in a long-lived process: one
18
+ * uncaught rejection there would take the whole process down, not just answer one call with an error.
19
+ * Each code is its own so a caller can tell a human what to do next; none is folded into a generic one.
20
+ * No network call and no credential read happens before the target and folder have been validated.
21
+ */
4
22
  /** Folder validation precedes credentials, rendering and all provider effects. */
5
23
  function folderError(required, optional = {}) {
6
24
  try {
@@ -13,11 +31,35 @@ function folderError(required, optional = {}) {
13
31
  return error.message;
14
32
  }
15
33
  }
16
- /** Normalize platform separators without changing the retained byte payload. */
34
+ /** Normalize platform separators without changing the retained byte payload. An export's `outputFile` is already
35
+ * commit-relative but uses the platform separator (`path.relative`), and a stray backslash from a Windows host would
36
+ * be a wrong path in a git tree entry, not a normalized one. */
17
37
  export function toCommitFile(required) {
18
38
  return { path: required.outputFile.replace(/\\/g, '/'), data: required.data };
19
39
  }
20
- /** Export into a fresh run directory, reporting it through `claim` before any export I/O starts. */
40
+ /** The files to commit: the host's arrangement when its layout supplies one, else the succeeded routes then assets. */
41
+ function arrangeCommitFiles(required) {
42
+ const { input, report } = required;
43
+ try {
44
+ const files = input.layout.arrangeFiles
45
+ ? [...input.layout.arrangeFiles({ report })]
46
+ : [...report.routes.succeeded.map(toCommitFile), ...report.assets.succeeded.map(toCommitFile)];
47
+ return { ok: true, files };
48
+ }
49
+ catch (error) {
50
+ return { ok: false, code: 'EXPORT_FAILED', message: input.describeError({ error, stage: 'arrange' }) };
51
+ }
52
+ }
53
+ /**
54
+ * Export into a fresh run directory, reporting it through `claim` before any export I/O starts.
55
+ *
56
+ * The directory is minted per RUN (the layout receives a new `runId` every call), never a fixed path per
57
+ * provider: with a fixed path two overlapping commits would `clean` and rewrite the same directory under each
58
+ * other. It is disposable once the export returns, because every byte the commit needs travels in the
59
+ * report's `data` fields and nothing re-reads the directory. A failed route AND a failed asset both refuse
60
+ * the commit (a page can export fine while its stylesheet or hero image 404s, and committing that is worse
61
+ * than refusing).
62
+ */
21
63
  async function exportIntoRunDirectory(input, claim) {
22
64
  try {
23
65
  const outputDir = input.layout.outputDirectory({ workspaceId: input.workspaceId, providerId: input.providerId, runId: input.ids.next({}) });
@@ -26,16 +68,18 @@ async function exportIntoRunDirectory(input, claim) {
26
68
  const failure = firstExportFailure({ report });
27
69
  if (failure)
28
70
  return { ok: false, code: 'EXPORT_FAILED', message: `refused to commit: ${failure.count} ${failure.kind}(s) failed to export (first: '${failure.identifier}' — ${failure.reason})` };
29
- const files = [...report.routes.succeeded.map(toCommitFile), ...report.assets.succeeded.map(toCommitFile)];
71
+ const arranged = arrangeCommitFiles({ input, report });
30
72
  // Validate every folder-relative path while export failures still use the safe outcome channel.
31
- for (const file of files)
32
- prefixRepositoryPath({ folder: input.folder, path: file.path });
33
- return { ok: true, files };
73
+ if (arranged.ok)
74
+ for (const file of arranged.files)
75
+ prefixRepositoryPath({ folder: input.folder, path: file.path });
76
+ return arranged;
34
77
  }
35
78
  catch (error) {
36
- return { ok: false, code: 'EXPORT_FAILED', message: `export failed before committing could start: ${input.describeError({ error })}` };
79
+ return { ok: false, code: 'EXPORT_FAILED', message: `export failed before committing could start: ${input.describeError({ error, stage: 'export' })}` };
37
80
  }
38
81
  }
82
+ /** The run directory is removed on every path out: success, refusal and throw alike. */
39
83
  async function exportForCommit(input) {
40
84
  let outputDir;
41
85
  try {
@@ -43,7 +87,9 @@ async function exportForCommit(input) {
43
87
  }
44
88
  finally {
45
89
  if (outputDir !== undefined) {
46
- // Byte payloads are retained by the report; cleanup cannot invalidate the commit.
90
+ // Byte payloads are retained by the report; cleanup cannot invalidate the commit. Best effort by design: a
91
+ // directory that could not be removed is disposable scratch, and failing the commit over it would
92
+ // turn a finished export into a refusal.
47
93
  try {
48
94
  await input.layout.cleanup({ outputDir });
49
95
  }
@@ -51,7 +97,13 @@ async function exportForCommit(input) {
51
97
  }
52
98
  }
53
99
  }
54
- /** Run a real fresh export, without credentials or repository I/O. */
100
+ /**
101
+ * Run a real fresh export, without credentials or repository I/O: the file count and byte total are real, not
102
+ * estimated, and the answer is a summary instead of a commit. It validates like the commit does and never
103
+ * resolves a credential or calls the provider (no network before a human has confirmed). `paths` is sorted and
104
+ * capped at 50 so a large export cannot blow out a dry-run answer.
105
+ * @complexity One export pass; no credential read, no provider call.
106
+ */
55
107
  export async function previewCommitExport(required, optional = {}) {
56
108
  const error = validateCommitTarget(required, optional) ?? folderError(required);
57
109
  if (error)
@@ -62,36 +114,67 @@ export async function previewCommitExport(required, optional = {}) {
62
114
  return { ok: true, fileCount: exported.files.length, totalBytes: exported.files.reduce((sum, file) => sum + Buffer.byteLength(file.data), 0), paths: exported.files.map(file => prefixRepositoryPath({ folder: required.folder, path: file.path })).sort().slice(0, 50) };
63
115
  }
64
116
  const PROVIDER_FAILURE_CODES = { 'repository-not-found': 'REPOSITORY_NOT_FOUND', 'no-changes': 'NO_CHANGES', diverged: 'DIVERGED_BRANCH', 'network-unreachable': 'NETWORK_UNREACHABLE', 'provider-error': 'PROVIDER_ERROR' };
65
- /** The credential must exist and belong to the requested provider; failures never reveal the token. */
117
+ /**
118
+ * The credential must exist and belong to the requested provider; failures never reveal the token.
119
+ *
120
+ * A resolver that throws (a decrypt failure: a missing site key, a tampered row) is a real possibility, not a
121
+ * theoretical one. It surfaces through this function's refusal channel, as `NO_CREDENTIALS_CONFIGURED`, the
122
+ * closest existing code (there is no dedicated "exists but cannot be unlocked" code, and adding one is a wider
123
+ * API change than that case needs). The wrong-provider guard is unreachable in practice, because the resolver
124
+ * was asked for this provider, but it stays an explicit typed check so a future bug in that invariant fails
125
+ * loudly here instead of forwarding one host's token to another host's API.
126
+ */
66
127
  async function resolveProviderCredential(required) {
67
128
  let credential;
68
129
  try {
69
130
  credential = await required.credentials.resolve({ workspaceId: required.workspaceId, providerId: required.providerId });
70
131
  }
71
132
  catch (error) {
72
- return { ok: false, code: 'NO_CREDENTIALS_CONFIGURED', message: `credential could not be resolved: ${required.describeError({ error })}` };
133
+ return { ok: false, code: 'NO_CREDENTIALS_CONFIGURED', message: `credential could not be resolved: ${required.describeError({ error, stage: 'credential' })}` };
73
134
  }
74
135
  if (!credential)
75
- return { ok: false, code: 'NO_CREDENTIALS_CONFIGURED', message: `No source control credential is configured for '${required.providerId}'.` };
136
+ return { ok: false, code: 'NO_CREDENTIALS_CONFIGURED', message: required.describeMissingCredential?.({ providerId: required.providerId }) ?? `No source control credential is configured for '${required.providerId}'.` };
76
137
  if (credential.providerId !== required.providerId)
77
138
  return { ok: false, code: 'NO_CREDENTIALS_CONFIGURED', message: `The resolved default credential is not a '${required.providerId}' connection.` };
78
139
  return { ok: true, credential };
79
140
  }
80
- /** One provider call; the adapter's failure codes map onto the host-facing outcome codes. */
141
+ /** Own keys only: a plugin's `constructor` or `__proto__` code must not resolve to an inherited member. */
142
+ function outcomeCode(required) {
143
+ return Object.hasOwn(PROVIDER_FAILURE_CODES, required.code) ? PROVIDER_FAILURE_CODES[required.code] : 'PROVIDER_ERROR';
144
+ }
145
+ /** Provider text may echo the Authorization value, so it never leaves this module without the exact token redacted
146
+ * (the shared redactor also catches shapes the token's own prefix would reveal). */
147
+ function redactToken(required) {
148
+ return redactSecrets({ input: required.text }, { exactSecrets: [required.token] });
149
+ }
150
+ /**
151
+ * One provider call; the adapter's failure codes map onto the host-facing outcome codes. A provider is
152
+ * plugin code: its throw must not break the never-throw contract, and its raw message may carry provider
153
+ * detail, so the text of a throw comes from the host's `describeError` (stage `'commit'`), which keeps detail
154
+ * for its own log and returns caller-safe words.
155
+ */
81
156
  async function commitExportedFiles(required, optional) {
82
157
  const { args, token, files } = required;
83
158
  try {
84
159
  const folder = normalizeRepositoryFolder(args);
85
160
  const result = await args.adapter.commitSite({ token, owner: args.owner, repo: args.repo, commitMessage: args.commitMessage, files, ...(folder ? { folder } : {}) }, optional.branch !== undefined ? { branch: optional.branch } : {});
86
161
  if (!result.ok)
87
- return { ok: false, code: PROVIDER_FAILURE_CODES[result.code], message: result.message };
162
+ return { ok: false, code: outcomeCode({ code: result.code }), message: redactToken({ text: result.message, token }) };
88
163
  return { ...result, owner: args.owner, repo: args.repo, divergedPaths: result.divergedPaths ?? [] };
89
164
  }
90
165
  catch (error) {
91
- return { ok: false, code: 'PROVIDER_ERROR', message: args.describeError({ error }) };
166
+ return { ok: false, code: 'PROVIDER_ERROR', message: redactToken({ text: args.describeError({ error, stage: 'commit' }), token }) };
92
167
  }
93
168
  }
94
- /** Resolve one provider's credential, export into an isolated host-owned directory and commit once. */
169
+ /**
170
+ * Resolve one provider's credential, export into an isolated host-owned directory and commit once.
171
+ *
172
+ * Always runs a FRESH export immediately before committing and never reuses an earlier export directory:
173
+ * correctness over one extra pass. The target is validated here even when the caller already validated it
174
+ * before opening a confirmation dialog (defense in depth for a caller that skips that check).
175
+ * This function reads as one guard per phase (credential, export, commit) rather than one long chain.
176
+ * @complexity One export pass (O(routes + assets) requests against the host's own app) plus one provider call.
177
+ */
95
178
  export async function commitSiteToSourceControl(required, optional = {}) {
96
179
  const configError = validateCommitTarget(required, optional) ?? folderError(required, { committing: true });
97
180
  if (configError)
@@ -280,7 +280,16 @@ export interface CommitLayoutPort {
280
280
  cleanup(required: {
281
281
  outputDir: string;
282
282
  }): Promise<void>;
283
+ /** The files to commit, arranged from the finished export (for example a host's static-download layout).
284
+ * Absent: the succeeded routes then the succeeded assets, as exported. A throw refuses the commit as
285
+ * `EXPORT_FAILED`, worded by `describeError` with stage `'arrange'`; every arranged path is still validated
286
+ * against the destination folder. Runs before `cleanup`, so an arrangement may read the output directory. */
287
+ arrangeFiles?(required: {
288
+ report: ExportReport;
289
+ }): readonly CommitFile[];
283
290
  }
291
+ /** Where in a commit an error arose, so a host can word each stage's failure on its own. */
292
+ export type CommitErrorStage = 'export' | 'arrange' | 'credential' | 'commit';
284
293
  export interface CommitExportArgs {
285
294
  folder?: string;
286
295
  workspaceId: string;
@@ -293,21 +302,31 @@ export interface CommitExportArgs {
293
302
  ids: {
294
303
  next(required: Record<string, never>): string;
295
304
  };
296
- /** Must return caller-safe text without credentials. */
305
+ /** Must return caller-safe text without credentials. `stage` names where the error arose (absent: unspecified). */
297
306
  describeError(required: {
298
307
  error: unknown;
308
+ stage?: CommitErrorStage;
299
309
  }): string;
300
310
  }
301
311
  export interface CommitOrchestrationArgs extends CommitExportArgs {
302
312
  supportsFolder?: boolean;
303
313
  credentials: CredentialResolverPort;
314
+ /** The one seam to the git host: `commitSite` is called exactly once and with no pre-flight, so every repository, branch
315
+ * and network outcome is discovered after the human confirmed. */
304
316
  adapter: Pick<SourceControlProviderOperations, 'commitSite'>;
317
+ /** The whole refusal sentence when no credential is configured for the provider (a host can say where to connect one).
318
+ * Absent: a generic sentence naming the provider. Must not contain credentials. */
319
+ describeMissingCredential?(required: {
320
+ providerId: string;
321
+ }): string;
305
322
  }
306
323
  export interface CommitOptions {
307
324
  branch?: string;
308
325
  validateTarget?: RepositoryTargetValidator;
309
326
  }
310
327
  export type CommitFailureCode = 'INVALID_CONFIG' | 'NO_CREDENTIALS_CONFIGURED' | 'EXPORT_FAILED' | 'REPOSITORY_NOT_FOUND' | 'NO_CHANGES' | 'DIVERGED_BRANCH' | 'NETWORK_UNREACHABLE' | 'PROVIDER_ERROR';
328
+ /** A success's `divergedPaths` is the provider's list passed through verbatim and always present (`[]` when it names none), so a
329
+ * caller can tell a person exactly what survived a shrinking publish because it could not be verified as still the host's own. */
311
330
  export type SourceControlCommitOutcome = {
312
331
  ok: false;
313
332
  code: CommitFailureCode;
@@ -13,5 +13,5 @@ export declare function createSourceControlProviderKit(required: {
13
13
  /** Adapt a host-selected native/guarded fetch without choosing a global transport. */
14
14
  export declare function createSourceControlFetchAdapter(required: {
15
15
  fetch: typeof fetch;
16
- }): SourceControlFetchPort;
16
+ }, _optional?: Record<string, never>): SourceControlFetchPort;
17
17
  //# sourceMappingURL=kit.d.ts.map
@@ -14,7 +14,7 @@ export function createSourceControlProviderKit(required, optional = {}) {
14
14
  };
15
15
  }
16
16
  /** Adapt a host-selected native/guarded fetch without choosing a global transport. */
17
- export function createSourceControlFetchAdapter(required) {
17
+ export function createSourceControlFetchAdapter(required, _optional = {}) {
18
18
  return ({ url }, optional = {}) => required.fetch(url, optional.init);
19
19
  }
20
20
  //# sourceMappingURL=kit.js.map