@xemahq/xema 0.26.0 → 0.27.0
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/README.md +70 -37
- package/dist/assets/distribution-assets.manifest.json +1 -2
- package/dist/cli.js +2 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands/dev.js +1 -0
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/down.d.ts.map +1 -1
- package/dist/commands/down.js +7 -1
- package/dist/commands/down.js.map +1 -1
- package/dist/commands/edition.d.ts +3 -0
- package/dist/commands/edition.d.ts.map +1 -0
- package/dist/commands/edition.js +46 -0
- package/dist/commands/edition.js.map +1 -0
- package/dist/commands/init.js +2 -2
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/serve.js +1 -0
- package/dist/commands/serve.js.map +1 -1
- package/dist/commands/up.js +1 -0
- package/dist/commands/up.js.map +1 -1
- package/dist/dev/env-defaults.d.ts.map +1 -1
- package/dist/dev/env-defaults.js +5 -1
- package/dist/dev/env-defaults.js.map +1 -1
- package/dist/dev/infra-preflight.d.ts +3 -2
- package/dist/dev/infra-preflight.d.ts.map +1 -1
- package/dist/dev/infra-preflight.js +18 -8
- package/dist/dev/infra-preflight.js.map +1 -1
- package/dist/edition/verify-image-evidence.bundle.mjs +54179 -0
- package/dist/edition/verify-image-evidence.bundle.provenance.json +2871 -0
- package/dist/runtime/config/schema.d.ts +1 -0
- package/dist/runtime/config/schema.d.ts.map +1 -1
- package/dist/runtime/custody/local-custody.d.ts +12 -0
- package/dist/runtime/custody/local-custody.d.ts.map +1 -0
- package/dist/runtime/custody/local-custody.js +22 -0
- package/dist/runtime/custody/local-custody.js.map +1 -0
- package/dist/runtime/custody/openbao-custody-bootstrap.d.ts +18 -0
- package/dist/runtime/custody/openbao-custody-bootstrap.d.ts.map +1 -0
- package/dist/runtime/custody/openbao-custody-bootstrap.js +50 -0
- package/dist/runtime/custody/openbao-custody-bootstrap.js.map +1 -0
- package/dist/runtime/custody/openbao-custody-store.d.ts +18 -0
- package/dist/runtime/custody/openbao-custody-store.d.ts.map +1 -0
- package/dist/runtime/custody/openbao-custody-store.js +55 -0
- package/dist/runtime/custody/openbao-custody-store.js.map +1 -0
- package/dist/runtime/custody/openbao-http-client.d.ts +34 -0
- package/dist/runtime/custody/openbao-http-client.d.ts.map +1 -0
- package/dist/runtime/custody/openbao-http-client.js +154 -0
- package/dist/runtime/custody/openbao-http-client.js.map +1 -0
- package/dist/runtime/custody/openbao-local-constants.d.ts +22 -0
- package/dist/runtime/custody/openbao-local-constants.d.ts.map +1 -0
- package/dist/runtime/custody/openbao-local-constants.js +48 -0
- package/dist/runtime/custody/openbao-local-constants.js.map +1 -0
- package/dist/runtime/custody/openbao-local-runner.d.ts +16 -0
- package/dist/runtime/custody/openbao-local-runner.d.ts.map +1 -0
- package/dist/runtime/custody/openbao-local-runner.js +86 -0
- package/dist/runtime/custody/openbao-local-runner.js.map +1 -0
- package/dist/runtime/edition/run-entry.d.ts +9 -0
- package/dist/runtime/edition/run-entry.d.ts.map +1 -0
- package/dist/runtime/edition/run-entry.js +36 -0
- package/dist/runtime/edition/run-entry.js.map +1 -0
- package/dist/runtime/edition/verb-map.d.ts +60 -0
- package/dist/runtime/edition/verb-map.d.ts.map +1 -0
- package/dist/runtime/edition/verb-map.js +146 -0
- package/dist/runtime/edition/verb-map.js.map +1 -0
- package/dist/runtime/env-seeder.d.ts +2 -0
- package/dist/runtime/env-seeder.d.ts.map +1 -1
- package/dist/runtime/env-seeder.js +18 -3
- package/dist/runtime/env-seeder.js.map +1 -1
- package/dist/runtime/launch.d.ts +2 -1
- package/dist/runtime/launch.d.ts.map +1 -1
- package/dist/runtime/launch.js +31 -7
- package/dist/runtime/launch.js.map +1 -1
- package/dist/runtime/paths.d.ts +1 -2
- package/dist/runtime/paths.d.ts.map +1 -1
- package/dist/runtime/paths.js +0 -10
- package/dist/runtime/paths.js.map +1 -1
- package/dist/runtime/runner/chart-local-provenance.d.ts +20 -0
- package/dist/runtime/runner/chart-local-provenance.d.ts.map +1 -0
- package/dist/runtime/runner/chart-local-provenance.js +114 -0
- package/dist/runtime/runner/chart-local-provenance.js.map +1 -0
- package/dist/runtime/runner/chart-preflight.d.ts +8 -8
- package/dist/runtime/runner/chart-preflight.d.ts.map +1 -1
- package/dist/runtime/runner/chart-preflight.js +30 -69
- package/dist/runtime/runner/chart-preflight.js.map +1 -1
- package/dist/runtime/runner/chart-pull.d.ts +14 -0
- package/dist/runtime/runner/chart-pull.d.ts.map +1 -0
- package/dist/runtime/runner/chart-pull.js +96 -0
- package/dist/runtime/runner/chart-pull.js.map +1 -0
- package/dist/runtime/runner/chart-resolver.d.ts +4 -12
- package/dist/runtime/runner/chart-resolver.d.ts.map +1 -1
- package/dist/runtime/runner/chart-resolver.js +16 -62
- package/dist/runtime/runner/chart-resolver.js.map +1 -1
- package/dist/runtime/runner/chart-set-lock.d.ts +6 -20
- package/dist/runtime/runner/chart-set-lock.d.ts.map +1 -1
- package/dist/runtime/runner/chart-set-lock.js +55 -99
- package/dist/runtime/runner/chart-set-lock.js.map +1 -1
- package/dist/runtime/runner/helm-cli.d.ts +3 -1
- package/dist/runtime/runner/helm-cli.d.ts.map +1 -1
- package/dist/runtime/runner/helm-cli.js +9 -7
- package/dist/runtime/runner/helm-cli.js.map +1 -1
- package/dist/runtime/runner/helm-runner.d.ts +4 -4
- package/dist/runtime/runner/helm-runner.d.ts.map +1 -1
- package/dist/runtime/runner/helm-runner.js +18 -16
- package/dist/runtime/runner/helm-runner.js.map +1 -1
- package/dist/runtime/sources/kinds/git.d.ts +1 -2
- package/dist/runtime/sources/kinds/git.d.ts.map +1 -1
- package/dist/runtime/sources/kinds/git.js +8 -5
- package/dist/runtime/sources/kinds/git.js.map +1 -1
- package/dist/runtime/sources/manifest-walk.d.ts +3 -1
- package/dist/runtime/sources/manifest-walk.d.ts.map +1 -1
- package/dist/runtime/sources/manifest-walk.js +8 -3
- package/dist/runtime/sources/manifest-walk.js.map +1 -1
- package/dist/runtime/sources/schema.d.ts +3 -0
- package/dist/runtime/sources/schema.d.ts.map +1 -1
- package/dist/runtime/sources/schema.js +6 -1
- package/dist/runtime/sources/schema.js.map +1 -1
- package/dist/runtime/supervisor.d.ts +2 -0
- package/dist/runtime/supervisor.d.ts.map +1 -1
- package/dist/runtime/supervisor.js +1 -0
- package/dist/runtime/supervisor.js.map +1 -1
- package/edition/README.md +315 -0
- package/edition/assemble-producer-input.mjs +1251 -0
- package/edition/authorization-base.mjs +347 -0
- package/edition/biome-content.mjs +268 -0
- package/edition/build-biome-index.mjs +175 -0
- package/edition/build-platform-service-index.mjs +288 -0
- package/edition/build-runtime-image-source-index.mjs +821 -0
- package/edition/built-verifier.mjs +55 -0
- package/edition/catalogue-edition.mjs +49 -0
- package/edition/catalogue-fetch.mjs +64 -0
- package/edition/catalogue.mjs +135 -0
- package/edition/chart-set-source-commit.mjs +92 -0
- package/edition/check-committed-image-evidence.mjs +383 -0
- package/edition/checkout-indexed-source-repositories.mjs +105 -0
- package/edition/comment-blanker.mjs +75 -0
- package/edition/connector-source-authority.mjs +60 -0
- package/edition/customer-definition.mjs +183 -0
- package/edition/customer-flags.mjs +7 -0
- package/edition/develop-customer-edition.mjs +99 -0
- package/edition/develop-edition-resolve.mjs +65 -0
- package/edition/develop-edition.mjs +274 -0
- package/edition/develop-freeze.mjs +173 -0
- package/edition/develop-image-coordinate.mjs +54 -0
- package/edition/develop-seal.mjs +77 -0
- package/edition/develop-snapshot-inputs.mjs +104 -0
- package/edition/dist-check.mjs +986 -0
- package/edition/distribution-evidence-set.mjs +987 -0
- package/edition/distribution-paths.mjs +191 -0
- package/edition/edition-artifact.mjs +270 -0
- package/edition/edition-biome-manifests.mjs +85 -0
- package/edition/edition-channel.mjs +6 -0
- package/edition/edition-chart-set.mjs +93 -0
- package/edition/edition-config.mjs +207 -0
- package/edition/edition-constants.mjs +57 -0
- package/edition/edition-contract.json +23 -0
- package/edition/edition-list.mjs +35 -0
- package/edition/edition-locks.mjs +69 -0
- package/edition/edition-protocol.mjs +228 -0
- package/edition/edition-workspace.mjs +176 -0
- package/edition/evidence-checkout.mjs +418 -0
- package/edition/evidence-grammars.mjs +16 -0
- package/edition/evidence-trust-pin.mjs +304 -0
- package/edition/evidence-trust-policy.mjs +256 -0
- package/edition/external-source-walk.mjs +463 -0
- package/edition/first-party-source-ids.mjs +59 -0
- package/edition/fleet-coordinate-finality.mjs +350 -0
- package/edition/git-source-auth.mjs +52 -0
- package/edition/image-evidence-replay-state.mjs +242 -0
- package/edition/image-evidence.mjs +1225 -0
- package/edition/kernel-contract-authority.mjs +443 -0
- package/edition/lib.mjs +3018 -0
- package/edition/no-follow-file.mjs +94 -0
- package/edition/oci-evidence-verbs.mjs +392 -0
- package/edition/oci-image-source-evidence.mjs +239 -0
- package/edition/oras.mjs +648 -0
- package/edition/pin-source.mjs +227 -0
- package/edition/plan-image-evidence-refresh.mjs +408 -0
- package/edition/platform-lock-readability.mjs +892 -0
- package/edition/platform-service-class.mjs +18 -0
- package/edition/platform-service-source-authority.mjs +105 -0
- package/edition/positive-closure.mjs +162 -0
- package/edition/produce-distribution-completeness-evidence.mjs +311 -0
- package/edition/produce-image-delivery-entitlement-evidence.mjs +294 -0
- package/edition/produce-image-source-evidence.mjs +765 -0
- package/edition/producer-evidence-bundle.mjs +157 -0
- package/edition/registry-credentials.mjs +193 -0
- package/edition/release-catalogue.mjs +39 -0
- package/edition/release-channel-guard.mjs +99 -0
- package/edition/release-edition-artifact.mjs +158 -0
- package/edition/remedy-command.mjs +89 -0
- package/edition/repin-evidence-trust.mjs +101 -0
- package/edition/required-resource-provider.mjs +58 -0
- package/edition/resolve-chart-set.mjs +415 -0
- package/edition/resolve-customer-edition.mjs +288 -0
- package/edition/resolve-distribution.mjs +2318 -0
- package/edition/resolve-edition.mjs +186 -0
- package/edition/resolve-images.mjs +1606 -0
- package/edition/seal-image-digests.mjs +855 -0
- package/edition/sealed-evidence-accept.mjs +82 -0
- package/edition/source-authority.mjs +725 -0
- package/edition/source-closure.mjs +116 -0
- package/edition/strict-json.mjs +121 -0
- package/edition/string-order.mjs +5 -0
- package/edition/trust-policy-arming.mjs +120 -0
- package/edition/trusted-executable.mjs +166 -0
- package/edition/verifier-binding.mjs +45 -0
- package/edition/verifier-files.mjs +8 -0
- package/edition/verifier-kernel-schemas.mjs +22 -0
- package/edition/verifier-provenance.mjs +64 -0
- package/edition/verify-image-evidence.mjs +430 -0
- package/edition/verify-image-platforms.mjs +495 -0
- package/edition/why.mjs +56 -0
- package/edition/workspace-sections.mjs +195 -0
- package/examples/06-biome-sources.yaml +1 -0
- package/package.json +14 -6
- package/dist/commands/dist.d.ts +0 -16
- package/dist/commands/dist.d.ts.map +0 -1
- package/dist/commands/dist.js +0 -182
- package/dist/commands/dist.js.map +0 -1
- package/dist/runtime/distribution/available-biome.d.ts +0 -10
- package/dist/runtime/distribution/available-biome.d.ts.map +0 -1
- package/dist/runtime/distribution/available-biome.js +0 -156
- package/dist/runtime/distribution/available-biome.js.map +0 -1
- package/dist/runtime/distribution/compose.d.ts +0 -23
- package/dist/runtime/distribution/compose.d.ts.map +0 -1
- package/dist/runtime/distribution/compose.js +0 -48
- package/dist/runtime/distribution/compose.js.map +0 -1
- package/dist/runtime/runner/chart-trust.d.ts +0 -57
- package/dist/runtime/runner/chart-trust.d.ts.map +0 -1
- package/dist/runtime/runner/chart-trust.js +0 -270
- package/dist/runtime/runner/chart-trust.js.map +0 -1
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// resolve-edition — the release lock set of one edition, in the order the
|
|
3
|
+
// distribution plane has always run it: `resolve-distribution <id>` (the
|
|
4
|
+
// distribution, authorization and chart-set locks) and then
|
|
5
|
+
// `resolve-images <id> --trusted-write-v3` (the images lock).
|
|
6
|
+
//
|
|
7
|
+
// node resolve-edition.mjs <root flags> <edition-id> --trusted-write-v3
|
|
8
|
+
// write the whole lock set into the editions root. The flag is the
|
|
9
|
+
// operator's explicit acknowledgement that the images lock is rewritten
|
|
10
|
+
// UNSEALED (a resolve never produces an `imageDigest`; `xema edition seal`
|
|
11
|
+
// writes them afterwards). Without it nothing is written.
|
|
12
|
+
// node resolve-edition.mjs <root flags> <edition-id> --check
|
|
13
|
+
// resolve the whole lock set into a scratch copy of the editions root and
|
|
14
|
+
// compare each lock with the committed one; exit 1 on any difference.
|
|
15
|
+
// Nothing committed is written, and the flag above is refused alongside
|
|
16
|
+
// it. Like is compared with like: the resolve timestamp is normalized out
|
|
17
|
+
// and the committed images lock is read through `withoutSealedDigests`,
|
|
18
|
+
// because a resolve emits no `imageDigest` and a sealed lock differs from
|
|
19
|
+
// a fresh resolve by exactly that field.
|
|
20
|
+
|
|
21
|
+
import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
22
|
+
import { tmpdir } from 'node:os';
|
|
23
|
+
import { join } from 'node:path';
|
|
24
|
+
|
|
25
|
+
import { AUTHORIZATION_LOCK_FILENAME } from './authorization-base.mjs';
|
|
26
|
+
import { fetchCatalogue } from './catalogue-fetch.mjs';
|
|
27
|
+
import {
|
|
28
|
+
CATALOGUE_FLAG,
|
|
29
|
+
CATALOGUE_TOKEN_ENV_FLAG,
|
|
30
|
+
CATALOGUE_USERNAME_FLAG,
|
|
31
|
+
CHANNEL_FLAG,
|
|
32
|
+
DEFINITION_FLAG,
|
|
33
|
+
SOURCE_IMAGE_FLAG,
|
|
34
|
+
} from './customer-flags.mjs';
|
|
35
|
+
import { assertCanonicalDistributionId } from './distribution-paths.mjs';
|
|
36
|
+
import { EditionChannel, EditionLockFile } from './edition-constants.mjs';
|
|
37
|
+
import {
|
|
38
|
+
WorkspaceRoot,
|
|
39
|
+
configureEditionWorkspace,
|
|
40
|
+
configureEditionWorkspaceFromProcess,
|
|
41
|
+
configuredWorkspace,
|
|
42
|
+
editionsRoot,
|
|
43
|
+
isEntryModule,
|
|
44
|
+
} from './edition-workspace.mjs';
|
|
45
|
+
import { comparableDistributionLock, loadKernelDistributionSchemas } from './lib.mjs';
|
|
46
|
+
import { parseSourceImages, resolveCustomerEdition, writeCustomerEdition } from './resolve-customer-edition.mjs';
|
|
47
|
+
import { writeResolvedDistribution } from './resolve-distribution.mjs';
|
|
48
|
+
import { writeResolvedImages } from './resolve-images.mjs';
|
|
49
|
+
import { withoutSealedDigests } from './seal-image-digests.mjs';
|
|
50
|
+
import { readStrictJsonFile } from './strict-json.mjs';
|
|
51
|
+
|
|
52
|
+
// A customer resolve (`--catalogue`) has no vendor editions root: `--out` IS its
|
|
53
|
+
// editions root, the directory its `<id>/` locks are written under.
|
|
54
|
+
if (isEntryModule(import.meta.url)) {
|
|
55
|
+
if (process.argv.includes(CATALOGUE_FLAG)) {
|
|
56
|
+
const at = process.argv.indexOf('--out');
|
|
57
|
+
if (at < 0 || process.argv[at + 1] === undefined) {throw new Error(`--out <dir> is required with ${CATALOGUE_FLAG}`);}
|
|
58
|
+
mkdirSync(process.argv[at + 1], { recursive: true });
|
|
59
|
+
process.argv.splice(at, 1, '--editions-root');
|
|
60
|
+
configureEditionWorkspaceFromProcess([WorkspaceRoot.Data, WorkspaceRoot.Editions, WorkspaceRoot.Sources, WorkspaceRoot.Kernel, WorkspaceRoot.Cache, WorkspaceRoot.SourceHash]);
|
|
61
|
+
} else {
|
|
62
|
+
configureEditionWorkspaceFromProcess([WorkspaceRoot.Data, WorkspaceRoot.Editions, WorkspaceRoot.Sources, WorkspaceRoot.Kernel, WorkspaceRoot.Cache, WorkspaceRoot.SourceHash]);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const CHECK_FLAG = '--check';
|
|
67
|
+
const TRUSTED_WRITE_FLAG = '--trusted-write-v3';
|
|
68
|
+
|
|
69
|
+
/** The locks one resolve writes, and the only files `--check` compares. */
|
|
70
|
+
export const RESOLVED_LOCK_FILES = Object.freeze([
|
|
71
|
+
EditionLockFile.Distribution,
|
|
72
|
+
AUTHORIZATION_LOCK_FILENAME,
|
|
73
|
+
EditionLockFile.ChartSet,
|
|
74
|
+
EditionLockFile.Images,
|
|
75
|
+
]);
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* A lock's comparable text. The resolve timestamp is the one field that changes
|
|
79
|
+
* between identical resolves; the sealed `imageDigest` of the images lock is a
|
|
80
|
+
* fact about what SHIPPED that a resolve never reproduces, so it is subtracted
|
|
81
|
+
* from the committed side (a fresh resolve carries none).
|
|
82
|
+
*/
|
|
83
|
+
export function comparableLock(file, text, schemas) {
|
|
84
|
+
const lock = JSON.parse(text);
|
|
85
|
+
if (file === EditionLockFile.Distribution) {return comparableDistributionLock(schemas, lock);}
|
|
86
|
+
const { resolvedAt: _resolvedAt, ...rest } = file === EditionLockFile.Images ? withoutSealedDigests(lock) : lock;
|
|
87
|
+
return JSON.stringify(rest);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** `{ id, check }` from the arguments after the root flags; the write flag is required to write and refused with `--check`. */
|
|
91
|
+
export function parseResolveEditionArgs(args) {
|
|
92
|
+
const [id, ...rest] = args;
|
|
93
|
+
const known = [CHECK_FLAG, TRUSTED_WRITE_FLAG];
|
|
94
|
+
const usage = `usage: resolve-edition.mjs <root flags> <edition-id> (${CHECK_FLAG} | ${TRUSTED_WRITE_FLAG})`;
|
|
95
|
+
if (!id || rest.some((argument) => !known.includes(argument))) {throw new Error(usage);}
|
|
96
|
+
const check = rest.includes(CHECK_FLAG);
|
|
97
|
+
const trustedWrite = rest.includes(TRUSTED_WRITE_FLAG);
|
|
98
|
+
if (check === trustedWrite) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
check
|
|
101
|
+
? `${CHECK_FLAG} writes nothing committed and does not take ${TRUSTED_WRITE_FLAG}`
|
|
102
|
+
: `refusing to write a lock set without ${TRUSTED_WRITE_FLAG}: the images lock is rewritten unsealed; ${usage}`,
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
return { id, check };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export async function writeResolvedLockSet(id) {
|
|
109
|
+
await writeResolvedDistribution(id);
|
|
110
|
+
await writeResolvedImages(id, { trustedWriteV3: true });
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function checkResolvedLockSet(id) {
|
|
114
|
+
const committedRoot = editionsRoot();
|
|
115
|
+
const scratch = mkdtempSync(join(tmpdir(), 'xema-edition-check-'));
|
|
116
|
+
try {
|
|
117
|
+
const schemas = await loadKernelDistributionSchemas();
|
|
118
|
+
cpSync(committedRoot, scratch, {
|
|
119
|
+
recursive: true,
|
|
120
|
+
filter: (source) => !/(^|[\\/])(\.git|node_modules)$/.test(source),
|
|
121
|
+
});
|
|
122
|
+
configureEditionWorkspace({ ...configuredWorkspace(), [WorkspaceRoot.Editions]: scratch });
|
|
123
|
+
await writeResolvedLockSet(id);
|
|
124
|
+
const drift = RESOLVED_LOCK_FILES.filter((file) => {
|
|
125
|
+
const committed = join(committedRoot, id, file);
|
|
126
|
+
const fresh = join(scratch, id, file);
|
|
127
|
+
if (!existsSync(committed) || !existsSync(fresh)) {return existsSync(committed) !== existsSync(fresh);}
|
|
128
|
+
return comparableLock(file, readFileSync(committed, 'utf8'), schemas) !== comparableLock(file, readFileSync(fresh, 'utf8'), schemas);
|
|
129
|
+
});
|
|
130
|
+
if (drift.length > 0) {
|
|
131
|
+
throw new Error(`${id}: the committed ${drift.join(', ')} differ from a fresh resolve; resolve the edition and commit the result`);
|
|
132
|
+
}
|
|
133
|
+
} finally {
|
|
134
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const CUSTOMER_VALUE_FLAGS = [DEFINITION_FLAG, CATALOGUE_FLAG, CHANNEL_FLAG, CATALOGUE_USERNAME_FLAG, CATALOGUE_TOKEN_ENV_FLAG];
|
|
139
|
+
|
|
140
|
+
/** The arguments of a customer resolve (the root flags and `--out` are already consumed). */
|
|
141
|
+
export function parseCustomerResolveArgs(args) {
|
|
142
|
+
const values = new Map();
|
|
143
|
+
const sourceImages = [];
|
|
144
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
145
|
+
const flag = args[i];
|
|
146
|
+
const value = args[i + 1];
|
|
147
|
+
if (![...CUSTOMER_VALUE_FLAGS, SOURCE_IMAGE_FLAG].includes(flag) || value === undefined || value.startsWith('--')) {
|
|
148
|
+
throw new Error(`unexpected argument ${JSON.stringify(flag)} in a customer resolve (${DEFINITION_FLAG}, ${CATALOGUE_FLAG}, ${CHANNEL_FLAG}, ${SOURCE_IMAGE_FLAG} take a value)`);
|
|
149
|
+
}
|
|
150
|
+
i += 1;
|
|
151
|
+
if (flag === SOURCE_IMAGE_FLAG) {sourceImages.push(value);} else if (values.has(flag)) {throw new Error(`${flag} given twice`);} else {values.set(flag, value);}
|
|
152
|
+
}
|
|
153
|
+
for (const required of [DEFINITION_FLAG, CATALOGUE_FLAG, CHANNEL_FLAG]) {
|
|
154
|
+
if (!values.has(required)) {throw new Error(`a customer resolve requires ${required}`);}
|
|
155
|
+
}
|
|
156
|
+
if (!Object.values(EditionChannel).includes(values.get(CHANNEL_FLAG))) {
|
|
157
|
+
throw new Error(`${CHANNEL_FLAG} must be one of ${Object.values(EditionChannel).join(' | ')}`);
|
|
158
|
+
}
|
|
159
|
+
return { values, sourceImages: parseSourceImages(sourceImages) };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async function mainCustomer() {
|
|
163
|
+
const { values, sourceImages } = parseCustomerResolveArgs(process.argv.slice(2));
|
|
164
|
+
const { catalogue, digest } = await fetchCatalogue({
|
|
165
|
+
ref: values.get(CATALOGUE_FLAG),
|
|
166
|
+
username: values.get(CATALOGUE_USERNAME_FLAG),
|
|
167
|
+
tokenEnv: values.get(CATALOGUE_TOKEN_ENV_FLAG),
|
|
168
|
+
});
|
|
169
|
+
const resolved = await resolveCustomerEdition({ rawDefinition: readStrictJsonFile(values.get(DEFINITION_FLAG)), catalogue, catalogueDigest: digest, sourceImages, channel: values.get(CHANNEL_FLAG) });
|
|
170
|
+
const { dir } = writeCustomerEdition(editionsRoot(), resolved);
|
|
171
|
+
console.log(`[edition:resolve] ${resolved.id}: customer edition against catalogue ${catalogue.offeringId} ${digest}, written to ${dir}`);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async function main() {
|
|
175
|
+
if (process.argv.includes(CATALOGUE_FLAG)) {return mainCustomer();}
|
|
176
|
+
const { id, check } = parseResolveEditionArgs(process.argv.slice(2));
|
|
177
|
+
assertCanonicalDistributionId(id);
|
|
178
|
+
await (check ? checkResolvedLockSet(id) : writeResolvedLockSet(id));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (isEntryModule(import.meta.url)) {
|
|
182
|
+
main().catch((error) => {
|
|
183
|
+
console.error(`[edition:resolve] ${error.message}`);
|
|
184
|
+
process.exit(1);
|
|
185
|
+
});
|
|
186
|
+
}
|