@xlinklight/publishing 3.3.0 → 3.4.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 +23 -3
- package/dist/src/acceptance-delivery-binding.d.ts +20 -0
- package/dist/src/acceptance-delivery-binding.js +59 -0
- package/dist/src/acceptance.d.ts +49 -0
- package/dist/src/acceptance.js +79 -0
- package/dist/src/client.d.ts +71 -0
- package/dist/src/client.js +146 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.js +3 -0
- package/dist/src/node/acceptance-delivery.d.ts +34 -0
- package/dist/src/node/acceptance-delivery.js +88 -0
- package/dist/src/node/activation.d.ts +5 -0
- package/dist/src/node/activation.js +3 -0
- package/dist/src/node/authorization.d.ts +31 -0
- package/dist/src/node/authorization.js +76 -0
- package/dist/src/node/cli.d.ts +2 -0
- package/dist/src/node/cli.js +22 -0
- package/dist/src/node/index.d.ts +20 -0
- package/dist/src/node/index.js +11 -0
- package/dist/src/node/journal-directory.d.ts +2 -0
- package/dist/src/node/journal-directory.js +121 -0
- package/dist/src/node/journal.d.ts +49 -0
- package/dist/src/node/journal.js +280 -0
- package/dist/src/node/local-json-file.d.ts +3 -0
- package/dist/src/node/local-json-file.js +49 -0
- package/dist/src/node/publishing-command.d.ts +46 -0
- package/dist/src/node/publishing-command.js +268 -0
- package/dist/src/node/session.d.ts +95 -0
- package/dist/src/node/session.js +223 -0
- package/dist/src/node/solution-package.d.ts +55 -0
- package/dist/src/node/solution-package.js +217 -0
- package/dist/src/node/source-error.d.ts +10 -0
- package/dist/src/node/source-error.js +15 -0
- package/dist/src/node/source-producer.d.ts +5 -0
- package/dist/src/node/source-producer.js +145 -0
- package/dist/src/node/terminal-network.d.ts +23 -0
- package/dist/src/node/terminal-network.js +122 -0
- package/dist/src/node/workflow.d.ts +74 -0
- package/dist/src/node/workflow.js +467 -0
- package/dist/src/package.d.ts +38 -0
- package/dist/src/package.js +74 -0
- package/dist/src/protocol.d.ts +83 -0
- package/dist/src/protocol.js +105 -0
- package/dist/src/shared/activation-types.d.ts +37 -0
- package/dist/src/shared/activation-types.js +1 -0
- package/dist/src/shared/activation.d.ts +17 -0
- package/dist/src/shared/activation.js +111 -0
- package/dist/src/shared/records.d.ts +10 -0
- package/dist/src/shared/records.js +26 -0
- package/dist/src/shared/release-version.d.ts +4 -0
- package/dist/src/shared/release-version.js +15 -0
- package/dist/src/worker/activation.d.ts +12 -0
- package/dist/src/worker/activation.js +11 -0
- package/dist/src/worker/durable-retention.d.ts +9 -0
- package/dist/src/worker/durable-retention.js +96 -0
- package/dist/src/worker/index.d.ts +12 -0
- package/dist/src/worker/index.js +7 -0
- package/dist/src/worker/journal.d.ts +129 -0
- package/dist/src/worker/journal.js +328 -0
- package/dist/src/worker/package.d.ts +60 -0
- package/dist/src/worker/package.js +116 -0
- package/dist/src/worker/release-retention.d.ts +34 -0
- package/dist/src/worker/release-retention.js +27 -0
- package/dist/src/worker/release.d.ts +22 -0
- package/dist/src/worker/release.js +59 -0
- package/dist/src/worker/runtime.d.ts +47 -0
- package/dist/src/worker/runtime.js +98 -0
- package/dist/src/worker/service.d.ts +128 -0
- package/dist/src/worker/service.js +520 -0
- package/package.json +23 -14
- package/src/acceptance-delivery-binding.mjs +0 -49
- package/src/acceptance.d.mts +0 -24
- package/src/acceptance.mjs +0 -67
- package/src/client.d.mts +0 -16
- package/src/client.mjs +0 -74
- package/src/index.d.mts +0 -6
- package/src/index.mjs +0 -3
- package/src/node/acceptance-delivery.d.mts +0 -11
- package/src/node/acceptance-delivery.mjs +0 -70
- package/src/node/activation.d.mts +0 -8
- package/src/node/activation.mjs +0 -3
- package/src/node/authorization.d.mts +0 -8
- package/src/node/authorization.mjs +0 -49
- package/src/node/cli.mjs +0 -12
- package/src/node/index.d.mts +0 -17
- package/src/node/index.mjs +0 -9
- package/src/node/journal.d.mts +0 -13
- package/src/node/journal.mjs +0 -135
- package/src/node/publishing-command.d.mts +0 -20
- package/src/node/publishing-command.mjs +0 -104
- package/src/node/session.d.mts +0 -25
- package/src/node/session.mjs +0 -134
- package/src/node/solution-package.d.mts +0 -15
- package/src/node/solution-package.mjs +0 -113
- package/src/node/source-error.d.mts +0 -5
- package/src/node/source-error.mjs +0 -9
- package/src/node/source-producer.mjs +0 -103
- package/src/node/workflow.d.mts +0 -37
- package/src/node/workflow.mjs +0 -320
- package/src/package.d.mts +0 -11
- package/src/package.mjs +0 -36
- package/src/protocol.d.mts +0 -27
- package/src/protocol.mjs +0 -50
- package/src/shared/activation.d.mts +0 -5
- package/src/shared/activation.mjs +0 -64
- package/src/worker/activation.d.mts +0 -7
- package/src/worker/activation.mjs +0 -4
- package/src/worker/index.d.mts +0 -6
- package/src/worker/index.mjs +0 -6
- package/src/worker/journal.d.mts +0 -21
- package/src/worker/journal.mjs +0 -151
- package/src/worker/package.d.mts +0 -16
- package/src/worker/package.mjs +0 -32
- package/src/worker/release.d.mts +0 -7
- package/src/worker/release.mjs +0 -21
- package/src/worker/runtime.d.mts +0 -4
- package/src/worker/runtime.mjs +0 -23
- package/src/worker/service.d.mts +0 -41
- package/src/worker/service.mjs +0 -251
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
import { errorCode, jsonSnapshot, objectRecord } from '../shared/records.js';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
5
|
+
import { randomUUID } from 'node:crypto';
|
|
6
|
+
import { newerVersion, publishingVersionRequestId } from '../shared/release-version.js';
|
|
7
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
8
|
+
import { createPublishingClient } from '../client.js';
|
|
9
|
+
import { parsePublishingConfiguration, parsePublishingProject, parsePublishingIntent, publishingRequestId, protocolRecord, publishingError } from '../protocol.js';
|
|
10
|
+
import { createPublishingSession } from './session.js';
|
|
11
|
+
import { verifyPublishingActivation } from './activation.js';
|
|
12
|
+
import { PublishingSourceError } from './source-error.js';
|
|
13
|
+
import { checkoutReleaseVersion, checkoutRequiresAcceptanceDelivery, selectProducerFile, validateLocalProducer } from './source-producer.js';
|
|
14
|
+
import { acceptanceDeliveryTarget, deliverAcceptanceArchive, maximumAcceptanceArchiveBytes, observeAcceptanceDelivery } from './acceptance-delivery.js';
|
|
15
|
+
const fail = (code) => publishingError(code), sourceKey = (id) => 'source:' + id;
|
|
16
|
+
const phases = ['preparing', 'failed-closed', 'frozen', 'delivering', 'delivery-rejected', 'remote', 'abandoned', 'completed', 'failed'];
|
|
17
|
+
function hasPhase(value) { return phases.some(phase => phase === value); }
|
|
18
|
+
function frozenPackage(record) {
|
|
19
|
+
const body = record?.payload;
|
|
20
|
+
if (!objectRecord(body) || !objectRecord(body.intent) || !objectRecord(body.intent.package))
|
|
21
|
+
return undefined;
|
|
22
|
+
const { packageName, version } = body.intent.package;
|
|
23
|
+
return typeof packageName === 'string' && typeof version === 'string' ? { packageName, version } : undefined;
|
|
24
|
+
}
|
|
25
|
+
const rejectedDelivery = new Set(['PUBLISHING_ACCEPTANCE_VERSION_CONFLICT', 'PUBLISHING_ACCEPTANCE_SIGNATURE_INVALID', 'PUBLISHING_ACCEPTANCE_DELIVERY_REJECTED']);
|
|
26
|
+
function closedForReplacement(status) {
|
|
27
|
+
return status.sideEffects === 'closed' && ['active', 'abandoned', 'failed', 'superseded'].includes(status.state);
|
|
28
|
+
}
|
|
29
|
+
const sourceOptions = (input) => {
|
|
30
|
+
if (!protocolRecord(input, [], ['producer', 'newPreparation', 'signal']) || input.newPreparation !== undefined && typeof input.newPreparation !== 'boolean')
|
|
31
|
+
throw fail('WORKFLOW_INPUT_INVALID');
|
|
32
|
+
if (input.producer !== undefined)
|
|
33
|
+
validateLocalProducer(input.producer);
|
|
34
|
+
return input;
|
|
35
|
+
};
|
|
36
|
+
/** One active request per project/client journal. Recovery never imports source
|
|
37
|
+
* or performs an operation whose durable Foundation claim already exists. */
|
|
38
|
+
export function createPublishingWorkflow(options) {
|
|
39
|
+
const { root, journal, credential, allowLoopback = false, request, clientLimits, metadataTransport, operationLimits } = options;
|
|
40
|
+
const configuration = parsePublishingConfiguration(options.configuration, { allowLoopback }), pathCaseSensitivity = options.pathCaseSensitivity ?? (process.platform === 'win32' ? 'case-insensitive' : 'case-sensitive');
|
|
41
|
+
if (typeof root !== 'string' || !path.isAbsolute(root) || !journal || !['case-sensitive', 'case-insensitive'].includes(pathCaseSensitivity))
|
|
42
|
+
throw fail('WORKFLOW_INPUT_INVALID');
|
|
43
|
+
const verifier = (signal) => async (input) => { const timeout = AbortSignal.timeout(clientLimits?.requestMs ?? 30000); await verifyPublishingActivation({ ...input, allowLoopback, signal: signal ? AbortSignal.any([signal, timeout]) : timeout, ...(metadataTransport ? { metadataTransport } : {}) }); };
|
|
44
|
+
const shared = { journal, configuration, credential, allowLoopback, ...(request ? { request } : {}), ...(clientLimits ? { clientLimits } : {}) };
|
|
45
|
+
const client = (signal) => createPublishingClient({ ...shared, ...(clientLimits ? { limits: clientLimits } : {}), verifyActivation: verifier(signal) }), activeKey = 'active:' + configuration.projectId;
|
|
46
|
+
const selectVersion = async (project, version, signal) => {
|
|
47
|
+
const latest = await client(signal).getLatestRelease({ signal });
|
|
48
|
+
if (!latest)
|
|
49
|
+
return {};
|
|
50
|
+
const { intent, status } = latest;
|
|
51
|
+
if (intent.package.packageName !== project.packageName || intent.package.solutionId !== project.solutionId)
|
|
52
|
+
throw fail('PROJECT_BINDING_INVALID');
|
|
53
|
+
if (intent.package.version === version) {
|
|
54
|
+
if (status.state !== 'abandoned' && status.state !== 'superseded')
|
|
55
|
+
return { intent };
|
|
56
|
+
}
|
|
57
|
+
else if (closedForReplacement(status)) {
|
|
58
|
+
if (!newerVersion(version, intent.package.version))
|
|
59
|
+
throw fail('SOURCE_VERSION_NOT_NEWER');
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
return { observed: { requestId: intent.requestId, state: status.state, sideEffects: status.sideEffects, active: false } };
|
|
63
|
+
};
|
|
64
|
+
const session = (record, signal) => createPublishingSession({ ...shared, verifyActivation: verifier(signal), packageLimits: record.payload.project.limits, pathCaseSensitivity: record.payload.pathCaseSensitivity, ...(operationLimits ? { operationLimits } : {}) });
|
|
65
|
+
const replace = async (record, phase, signal, failure, createAttempt = record.payload.createAttempt) => {
|
|
66
|
+
const payload = { ...record.payload, phase, ...(createAttempt ? { createAttempt } : {}) };
|
|
67
|
+
delete payload.failure;
|
|
68
|
+
if (failure)
|
|
69
|
+
payload.failure = failure;
|
|
70
|
+
const result = await journal.compareAndSet({ key: sourceKey(payload.requestId), expectedRevision: record.revision, payload: jsonSnapshot(payload) }, { signal });
|
|
71
|
+
if (result !== 'stored')
|
|
72
|
+
throw fail('WORKFLOW_CONFLICT');
|
|
73
|
+
return { revision: record.revision + 1, payload };
|
|
74
|
+
};
|
|
75
|
+
const current = async (signal) => {
|
|
76
|
+
const active = await journal.load(activeKey, { signal });
|
|
77
|
+
if (!active)
|
|
78
|
+
return undefined;
|
|
79
|
+
if (!protocolRecord(active.payload, ['schemaVersion', 'requestId']) || active.payload.schemaVersion !== 1 || !publishingRequestId(active.payload.requestId))
|
|
80
|
+
throw fail('WORKFLOW_STATE_INVALID');
|
|
81
|
+
const stored = await journal.load(sourceKey(active.payload.requestId), { signal }), wire = stored?.payload;
|
|
82
|
+
if (!stored || !protocolRecord(wire, ['schemaVersion', 'requestId', 'phase', 'project', 'pathCaseSensitivity'], ['failure', 'selectedVersion', 'createAttempt']) || wire.schemaVersion !== 1 || wire.requestId !== active.payload.requestId || !hasPhase(wire.phase) || wire.pathCaseSensitivity !== 'case-sensitive' && wire.pathCaseSensitivity !== 'case-insensitive')
|
|
83
|
+
throw fail('WORKFLOW_STATE_INVALID');
|
|
84
|
+
const { phase, createAttempt, selectedVersion, pathCaseSensitivity } = wire;
|
|
85
|
+
if (createAttempt !== undefined && (typeof createAttempt !== 'number' || !Number.isSafeInteger(createAttempt) || createAttempt < 1 || createAttempt > 64) || selectedVersion !== undefined && typeof selectedVersion !== 'string')
|
|
86
|
+
throw fail('WORKFLOW_STATE_INVALID');
|
|
87
|
+
let failure;
|
|
88
|
+
if (wire.failure !== undefined) {
|
|
89
|
+
if (!protocolRecord(wire.failure, ['code']) || typeof wire.failure.code !== 'string' ||
|
|
90
|
+
!(phase === 'failed-closed' && ['PUBLISHING_SOURCE_PACKAGE_BINDING_INVALID', 'PUBLISHING_SOURCE_PREPARATION_FAILED', 'PUBLISHING_ACCEPTANCE_VERSION_CONFLICT'].includes(wire.failure.code) || phase === 'delivery-rejected' && rejectedDelivery.has(wire.failure.code)))
|
|
91
|
+
throw fail('WORKFLOW_STATE_INVALID');
|
|
92
|
+
failure = { code: wire.failure.code };
|
|
93
|
+
}
|
|
94
|
+
const project = parsePublishingProject(wire.project, { allowLoopback });
|
|
95
|
+
if (JSON.stringify(project.configuration) !== JSON.stringify(configuration))
|
|
96
|
+
throw fail('CONFIGURATION_CHANGED');
|
|
97
|
+
let record = { revision: stored.revision, payload: { schemaVersion: 1, requestId: active.payload.requestId, project, phase, pathCaseSensitivity, ...(failure ? { failure } : {}), ...(createAttempt !== undefined ? { createAttempt } : {}), ...(selectedVersion !== undefined ? { selectedVersion } : {}) } };
|
|
98
|
+
// freeze is the atomic authority: losing the outer acknowledgment must never
|
|
99
|
+
// cause a second import, build, capture or request identity.
|
|
100
|
+
if (record.payload.phase === 'preparing' && await journal.load('request:' + record.payload.requestId, { signal })) {
|
|
101
|
+
await session(record, signal).read({ requestId: record.payload.requestId, signal });
|
|
102
|
+
record = await replace(record, 'frozen', signal);
|
|
103
|
+
}
|
|
104
|
+
return { active, record };
|
|
105
|
+
};
|
|
106
|
+
const result = (record, state, extra = {}) => ({ requestId: record.payload.requestId, state, active: state === 'active', ...extra });
|
|
107
|
+
const operationClaim = (id, stage, signal, attempt = 0) => journal.load('operation:' + id + '.' + stage + (attempt ? '.' + attempt : ''), { signal });
|
|
108
|
+
const rejectedCreate = (claim) => objectRecord(claim?.payload) && claim.payload.writeState === 'rejected' && claim.payload.attemptFailure === 'CONFLICT';
|
|
109
|
+
const prepare = async (input) => {
|
|
110
|
+
const { producer, signal } = sourceOptions(input);
|
|
111
|
+
let { newPreparation = false } = input;
|
|
112
|
+
let previous = await current(signal), automatic = false, previousCreateRejected = false;
|
|
113
|
+
if (previous?.record.payload.phase === 'failed-closed' && previous.record.payload.selectedVersion && !newPreparation) {
|
|
114
|
+
const version = await checkoutReleaseVersion(root, previous.record.payload.project.packageName);
|
|
115
|
+
newPreparation = Boolean(version && newerVersion(version, previous.record.payload.selectedVersion));
|
|
116
|
+
}
|
|
117
|
+
if (previous && !newPreparation && ['remote', 'completed', 'failed', 'abandoned', 'delivery-rejected'].includes(previous.record.payload.phase)) {
|
|
118
|
+
const original = await journal.load('request:' + previous.record.payload.requestId, { signal });
|
|
119
|
+
const originalPackage = frozenPackage(original);
|
|
120
|
+
if (originalPackage) {
|
|
121
|
+
// A checkout is optional when resuming. Only a valid, explicitly higher owner
|
|
122
|
+
// version can select another identity. Its producer is loaded after closure.
|
|
123
|
+
const version = await checkoutReleaseVersion(root, originalPackage.packageName).catch(() => undefined);
|
|
124
|
+
if ((version === undefined || version === originalPackage.version) && ['completed', 'failed', 'delivery-rejected'].includes(previous.record.payload.phase))
|
|
125
|
+
return previous.record;
|
|
126
|
+
if (version && version !== originalPackage.version) {
|
|
127
|
+
if (newerVersion(version, originalPackage.version)) {
|
|
128
|
+
automatic = true;
|
|
129
|
+
newPreparation = true;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (previous && newPreparation && ['remote', 'completed', 'failed'].includes(previous.record.payload.phase)) {
|
|
135
|
+
// Observe the original identity and current admission before permitting the
|
|
136
|
+
// next release. A prior terminal observation never authorizes an unknown,
|
|
137
|
+
// still-running or currently unverified request to be replaced.
|
|
138
|
+
const observed = await inspect({ signal }, true);
|
|
139
|
+
if (!closedForReplacement(observed)) {
|
|
140
|
+
if (automatic)
|
|
141
|
+
return { observed: { ...observed, active: false } };
|
|
142
|
+
throw fail('SOURCE_ACTIVE_REQUEST_EXISTS');
|
|
143
|
+
}
|
|
144
|
+
previousCreateRejected = observed.error?.code === 'PUBLISHING_CONFLICT' && observed.sideEffects === 'closed';
|
|
145
|
+
previous = await current(signal);
|
|
146
|
+
}
|
|
147
|
+
if (previous) {
|
|
148
|
+
const phase = previous.record.payload.phase;
|
|
149
|
+
if (phase === 'preparing')
|
|
150
|
+
throw fail('SOURCE_PREPARATION_UNKNOWN');
|
|
151
|
+
if (['frozen', 'delivering', 'remote'].includes(phase)) {
|
|
152
|
+
if (!newPreparation) {
|
|
153
|
+
const { project, selectedVersion, requestId, createAttempt } = previous.record.payload;
|
|
154
|
+
if (options.acceptanceDelivery && (phase !== 'remote' || !await operationClaim(requestId, 'create', signal, createAttempt))) {
|
|
155
|
+
const version = selectedVersion ?? frozenPackage(await journal.load('request:' + requestId, { signal }))?.version;
|
|
156
|
+
if (!version)
|
|
157
|
+
throw fail('FROZEN_REQUEST_INVALID');
|
|
158
|
+
const selection = await selectVersion(project, version, signal);
|
|
159
|
+
if (selection.observed)
|
|
160
|
+
return { observed: selection.observed };
|
|
161
|
+
if (selection.intent && selection.intent.requestId !== requestId)
|
|
162
|
+
throw fail('ACCEPTANCE_VERSION_CONFLICT');
|
|
163
|
+
}
|
|
164
|
+
return previous.record;
|
|
165
|
+
}
|
|
166
|
+
if (phase !== 'remote' || !previousCreateRejected)
|
|
167
|
+
throw fail('SOURCE_ACTIVE_REQUEST_EXISTS');
|
|
168
|
+
}
|
|
169
|
+
if (!newPreparation)
|
|
170
|
+
throw fail('SOURCE_NEW_PREPARATION_REQUIRED');
|
|
171
|
+
}
|
|
172
|
+
signal?.throwIfAborted();
|
|
173
|
+
if (await fs.realpath(root) !== root || !(await fs.lstat(root)).isDirectory())
|
|
174
|
+
throw fail('SOURCE_PATH_INVALID');
|
|
175
|
+
const project = await client(signal).getProject({ signal });
|
|
176
|
+
let file, selectionFailure;
|
|
177
|
+
try {
|
|
178
|
+
file = await selectProducerFile(root, producer);
|
|
179
|
+
}
|
|
180
|
+
catch (cause) {
|
|
181
|
+
selectionFailure = new PublishingSourceError({ cause, processesClosed: true });
|
|
182
|
+
}
|
|
183
|
+
const deliver = Boolean(options.acceptanceDelivery);
|
|
184
|
+
if (!selectionFailure && !producer && await checkoutRequiresAcceptanceDelivery(root) && !deliver)
|
|
185
|
+
throw fail('ACCEPTANCE_CREDENTIAL_REQUIRED');
|
|
186
|
+
let inherited, selectedVersion, requestId = randomUUID();
|
|
187
|
+
if (deliver) {
|
|
188
|
+
const version = await checkoutReleaseVersion(root, project.packageName);
|
|
189
|
+
if (!version)
|
|
190
|
+
throw fail('SOURCE_PACKAGE_BINDING_INVALID');
|
|
191
|
+
selectedVersion = version;
|
|
192
|
+
const selection = await selectVersion(project, version, signal);
|
|
193
|
+
if (selection.observed)
|
|
194
|
+
return { observed: selection.observed };
|
|
195
|
+
inherited = selection.intent;
|
|
196
|
+
requestId = inherited?.requestId ?? publishingVersionRequestId(configuration, project.packageName, version);
|
|
197
|
+
}
|
|
198
|
+
signal?.throwIfAborted();
|
|
199
|
+
const payload = { schemaVersion: 1, requestId, project, pathCaseSensitivity, ...(selectedVersion ? { selectedVersion } : {}), ...(selectionFailure ? { phase: 'failed-closed', failure: { code: selectionFailure.code } } : { phase: 'preparing' }) };
|
|
200
|
+
const retry = previous?.record.payload.requestId === requestId && previous.record.payload.phase === 'failed-closed' && newPreparation;
|
|
201
|
+
const sourceRevision = retry && previous ? previous.record.revision : 0;
|
|
202
|
+
if (await journal.compareAndSet({ key: sourceKey(requestId), expectedRevision: sourceRevision, payload: jsonSnapshot(payload) }, { signal }) !== 'stored')
|
|
203
|
+
throw fail('WORKFLOW_CONFLICT');
|
|
204
|
+
if (await journal.compareAndSet({ key: activeKey, expectedRevision: previous?.active.revision ?? 0, payload: { schemaVersion: 1, requestId } }, { signal }) !== 'stored')
|
|
205
|
+
throw fail('WORKFLOW_CONFLICT');
|
|
206
|
+
if (selectionFailure)
|
|
207
|
+
throw selectionFailure;
|
|
208
|
+
let record = { revision: sourceRevision + 1, payload }, prepared, intent, acceptanceArchive, processesClosed = false;
|
|
209
|
+
try {
|
|
210
|
+
if (!file)
|
|
211
|
+
throw fail('SOURCE_PORT_INVALID');
|
|
212
|
+
const producerModule = await import(pathToFileURL(file).href + '?publishingRequest=' + requestId);
|
|
213
|
+
if (typeof producerModule.prepare !== 'function')
|
|
214
|
+
throw fail('SOURCE_PORT_INVALID');
|
|
215
|
+
const response = await producerModule.prepare({ root, project: structuredClone(project), signal, requestId, ...(deliver ? { includeAcceptanceArchive: true } : {}) });
|
|
216
|
+
if (!protocolRecord(response, ['prepared', 'processesClosed'], ['acceptanceArchive']) || response.processesClosed !== true)
|
|
217
|
+
throw fail('SOURCE_PROCESS_CLOSURE_UNKNOWN');
|
|
218
|
+
processesClosed = true;
|
|
219
|
+
prepared = response.prepared;
|
|
220
|
+
acceptanceArchive = response.acceptanceArchive;
|
|
221
|
+
const item = prepared?.descriptor;
|
|
222
|
+
if (deliver && (!acceptanceArchive || !(acceptanceArchive.bytes instanceof Uint8Array) || !acceptanceArchive.bytes.length ||
|
|
223
|
+
acceptanceArchive.bytes.length > maximumAcceptanceArchiveBytes || !/^[a-f0-9]{64}$/.test(acceptanceArchive.artifactSha256)))
|
|
224
|
+
throw fail('SOURCE_PACKAGE_BINDING_INVALID');
|
|
225
|
+
if (!deliver && acceptanceArchive)
|
|
226
|
+
throw fail('SOURCE_PACKAGE_BINDING_INVALID');
|
|
227
|
+
if (!item || item.solutionId !== project.solutionId || item.packageName !== project.packageName || item.publisherId !== configuration.publisher.publisherId)
|
|
228
|
+
throw fail('SOURCE_PACKAGE_BINDING_INVALID');
|
|
229
|
+
if (!producer) {
|
|
230
|
+
const expected = await checkoutReleaseVersion(root, project.packageName);
|
|
231
|
+
if (expected !== undefined && item.version !== expected)
|
|
232
|
+
throw fail('SOURCE_PACKAGE_BINDING_INVALID');
|
|
233
|
+
}
|
|
234
|
+
intent = parsePublishingIntent({ schemaVersion: 1, requestId, projectId: configuration.projectId, policyRevision: project.policyRevision, package: { solutionId: item.solutionId, publisherId: item.publisherId, packageName: item.packageName, version: item.version, content: prepared.content, fileCount: prepared.files.length, totalBytes: prepared.payloadBytes } });
|
|
235
|
+
if (inherited) {
|
|
236
|
+
if (JSON.stringify(intent.package) !== JSON.stringify(inherited.package))
|
|
237
|
+
throw fail('ACCEPTANCE_VERSION_CONFLICT');
|
|
238
|
+
intent = inherited;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
if (processesClosed || error instanceof PublishingSourceError && error.processesClosed) {
|
|
243
|
+
const causeCode = errorCode(error), code = causeCode && ['PUBLISHING_SOURCE_PACKAGE_BINDING_INVALID', 'PUBLISHING_ACCEPTANCE_VERSION_CONFLICT'].includes(causeCode) ? causeCode : 'PUBLISHING_SOURCE_PREPARATION_FAILED';
|
|
244
|
+
await replace(record, 'failed-closed', signal, { code });
|
|
245
|
+
if (code === 'PUBLISHING_ACCEPTANCE_VERSION_CONFLICT')
|
|
246
|
+
throw error;
|
|
247
|
+
throw new PublishingSourceError({ cause: error, processesClosed: true });
|
|
248
|
+
}
|
|
249
|
+
throw new PublishingSourceError({ cause: error, processesClosed: false });
|
|
250
|
+
}
|
|
251
|
+
// Freeze and its acknowledgment deliberately remain outside the known-closed
|
|
252
|
+
// source catch: a storage error can mean the original bytes were committed.
|
|
253
|
+
await session(record, signal).freeze({ intent, prepared, acceptanceArchive, acceptanceTarget: options.acceptanceDelivery ? acceptanceDeliveryTarget(options.acceptanceDelivery) : undefined, signal });
|
|
254
|
+
record = await replace(record, 'frozen', signal);
|
|
255
|
+
return record;
|
|
256
|
+
};
|
|
257
|
+
const local = (record) => result(record, ['frozen', 'remote', 'completed', 'failed'].includes(record.payload.phase) ? 'checked' : record.payload.phase === 'preparing' ? 'preparation-unknown' : record.payload.phase === 'failed-closed' ? 'preparation-failed' : record.payload.phase === 'abandoned' ? 'abandoned' : 'unknown');
|
|
258
|
+
const observedResult = async (record, status, signal) => {
|
|
259
|
+
// The client/session authenticated this exact original intent, and ACTIVE
|
|
260
|
+
// already passed the real signature and current Core-admission verifier.
|
|
261
|
+
const terminal = { abandoned: 'abandoned', active: 'completed', superseded: 'completed', failed: 'failed' };
|
|
262
|
+
const phase = status.sideEffects === 'closed' ? terminal[status.state] : undefined;
|
|
263
|
+
if (phase && record.payload.phase !== phase) {
|
|
264
|
+
try {
|
|
265
|
+
record = await replace(record, phase, signal);
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
if (errorCode(error) !== 'PUBLISHING_WORKFLOW_CONFLICT')
|
|
269
|
+
throw error;
|
|
270
|
+
const latest = await journal.load(sourceKey(record.payload.requestId), { signal });
|
|
271
|
+
if (!latest || !objectRecord(latest.payload) || latest.payload.phase !== phase)
|
|
272
|
+
throw error;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return result(record, status.state, { sideEffects: status.sideEffects });
|
|
276
|
+
};
|
|
277
|
+
const inspect = async ({ signal } = {}, observe = false, dispatchRecovery = false) => {
|
|
278
|
+
const state = await current(signal);
|
|
279
|
+
if (!state) {
|
|
280
|
+
const latest = options.acceptanceDelivery ? await client(signal).getLatestRelease({ signal }) : undefined;
|
|
281
|
+
return latest ? { requestId: latest.intent.requestId, state: latest.status.state, sideEffects: latest.status.sideEffects, active: latest.status.state === 'active' } : { state: 'empty', active: false };
|
|
282
|
+
}
|
|
283
|
+
const { record } = state;
|
|
284
|
+
if (record.payload.phase === 'delivery-rejected')
|
|
285
|
+
return result(record, 'failed', { sideEffects: 'closed', error: record.payload.failure });
|
|
286
|
+
if (record.payload.phase === 'delivering') {
|
|
287
|
+
const bundle = await session(record, signal).acceptanceMetadata({ requestId: record.payload.requestId, signal });
|
|
288
|
+
try {
|
|
289
|
+
if (!bundle || !options.acceptanceDelivery || !('target' in bundle) || JSON.stringify(bundle.target) !== JSON.stringify(acceptanceDeliveryTarget(options.acceptanceDelivery)))
|
|
290
|
+
throw fail('ACCEPTANCE_TRUST_CHANGED');
|
|
291
|
+
if (await observeAcceptanceDelivery({ ...bundle, credential: options.acceptanceDelivery, request, signal }))
|
|
292
|
+
return result(record, 'checked');
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
const code = errorCode(error);
|
|
296
|
+
if (code === 'PUBLISHING_ACCEPTANCE_VERSION_CONFLICT') {
|
|
297
|
+
await replace(record, 'delivery-rejected', signal, { code });
|
|
298
|
+
return result(record, 'failed', { sideEffects: 'closed', error: { code } });
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return result(record, 'unknown');
|
|
302
|
+
}
|
|
303
|
+
if (!['frozen', 'remote', 'completed', 'failed'].includes(record.payload.phase))
|
|
304
|
+
return local(record);
|
|
305
|
+
const { requestId, createAttempt: attempt = 0 } = record.payload, commit = await operationClaim(requestId, 'commit', signal), create = await operationClaim(requestId, 'create', signal, attempt);
|
|
306
|
+
if (!commit && rejectedCreate(create))
|
|
307
|
+
return result(record, 'failed', { sideEffects: 'closed', error: { code: 'PUBLISHING_CONFLICT' } });
|
|
308
|
+
if (!commit && !create)
|
|
309
|
+
return local(record);
|
|
310
|
+
const selected = session(record, signal);
|
|
311
|
+
if (observe) {
|
|
312
|
+
const observed = await selected.observe({ requestId, stage: commit ? 'commit' : 'create', attempt: commit ? 0 : attempt, signal });
|
|
313
|
+
if (!observed.status)
|
|
314
|
+
return result(record, 'unknown');
|
|
315
|
+
// The control only asks the host to observe an already committed original
|
|
316
|
+
// operation. Uploading/local preparation never dispatches provider work.
|
|
317
|
+
const status = dispatchRecovery && commit && ['queued', 'deploying', 'awaiting-acceptance', 'unknown'].includes(observed.status.state) ? await selected.recover({ requestId, signal }) : observed.status;
|
|
318
|
+
return observedResult(record, status, signal);
|
|
319
|
+
}
|
|
320
|
+
return observedResult(record, await selected.status({ requestId, signal }), signal);
|
|
321
|
+
};
|
|
322
|
+
const waiting = (state) => ['queued', 'deploying', 'registered', 'awaiting-acceptance'].includes(state);
|
|
323
|
+
const waitFor = async (record, initial, { signal, waitMs, pollMs }) => {
|
|
324
|
+
if (!waitMs || !waiting(initial.state))
|
|
325
|
+
return initial;
|
|
326
|
+
const timeout = AbortSignal.timeout(waitMs), active = signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
327
|
+
let latest = initial;
|
|
328
|
+
try {
|
|
329
|
+
while (waiting(latest.state)) {
|
|
330
|
+
await delay(pollMs, undefined, { signal: active });
|
|
331
|
+
latest = await observedResult(record, await session(record, active).status({ requestId: record.payload.requestId, signal: active }), active);
|
|
332
|
+
}
|
|
333
|
+
return latest;
|
|
334
|
+
}
|
|
335
|
+
catch (error) {
|
|
336
|
+
if (timeout.aborted && !signal?.aborted)
|
|
337
|
+
return { ...latest, timedOut: true };
|
|
338
|
+
throw error;
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
return Object.freeze({
|
|
342
|
+
async check(input = {}) {
|
|
343
|
+
const record = await prepare(input);
|
|
344
|
+
if ('observed' in record)
|
|
345
|
+
return record.observed;
|
|
346
|
+
if (['delivering', 'delivery-rejected'].includes(record.payload.phase))
|
|
347
|
+
return inspect({ signal: input.signal }, true);
|
|
348
|
+
return local(record);
|
|
349
|
+
},
|
|
350
|
+
async publish(input = {}) {
|
|
351
|
+
if (!protocolRecord(input, [], ['producer', 'newPreparation', 'signal', 'waitMs', 'pollMs']))
|
|
352
|
+
throw fail('WORKFLOW_INPUT_INVALID');
|
|
353
|
+
const { waitMs = 0, pollMs = 1000, ...source } = input;
|
|
354
|
+
if (!Number.isSafeInteger(waitMs) || waitMs < 0 || waitMs > 3600000 || !Number.isSafeInteger(pollMs) || pollMs < 1 || pollMs > 30000)
|
|
355
|
+
throw fail('WORKFLOW_INPUT_INVALID');
|
|
356
|
+
const prepared = await prepare(source);
|
|
357
|
+
if ('observed' in prepared)
|
|
358
|
+
return prepared.observed;
|
|
359
|
+
let record = prepared;
|
|
360
|
+
const requestId = record.payload.requestId, signal = input.signal, finish = (status) => waitFor(record, status, { signal, waitMs, pollMs });
|
|
361
|
+
// This CAS competes with local abandonment before any remote write. Once
|
|
362
|
+
// remote publication may start, absence of a later claim is not a closure
|
|
363
|
+
// proof for an overlapping client.
|
|
364
|
+
const selected = session(record, signal);
|
|
365
|
+
// Delivery is an immutable owner-side installation. Keep the original
|
|
366
|
+
// request frozen until its exact version and both digests can be read back.
|
|
367
|
+
if (['frozen', 'delivering', 'delivery-rejected'].includes(record.payload.phase)) {
|
|
368
|
+
const bundle = await selected.readAcceptanceArchive({ requestId, signal });
|
|
369
|
+
if (bundle) {
|
|
370
|
+
if (!options.acceptanceDelivery || !('target' in bundle) || JSON.stringify(bundle.target) !== JSON.stringify(acceptanceDeliveryTarget(options.acceptanceDelivery)))
|
|
371
|
+
return result(record, 'failed', { error: { code: 'PUBLISHING_ACCEPTANCE_TRUST_CHANGED' } });
|
|
372
|
+
if (record.payload.phase !== 'delivering')
|
|
373
|
+
record = await replace(record, 'delivering', signal);
|
|
374
|
+
try {
|
|
375
|
+
await deliverAcceptanceArchive({ ...bundle, credential: options.acceptanceDelivery, request, signal });
|
|
376
|
+
}
|
|
377
|
+
catch (error) {
|
|
378
|
+
const code = errorCode(error);
|
|
379
|
+
if (code && rejectedDelivery.has(code)) {
|
|
380
|
+
await replace(record, 'delivery-rejected', signal, { code });
|
|
381
|
+
return result(record, 'failed', { sideEffects: 'closed', error: { code } });
|
|
382
|
+
}
|
|
383
|
+
return result(record, 'unknown', { error: { code: 'PUBLISHING_ACCEPTANCE_DELIVERY_UNKNOWN' } });
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
record = await replace(record, 'remote', signal);
|
|
387
|
+
}
|
|
388
|
+
// Never repeat creation, upload or commit after the original commit claim.
|
|
389
|
+
// A healthy confirmed original may ask the host for its known next step;
|
|
390
|
+
// unknown requires explicit recovery and cannot perform on publish.
|
|
391
|
+
if (await operationClaim(requestId, 'commit', signal)) {
|
|
392
|
+
const original = await inspect({ signal }, true);
|
|
393
|
+
if (['queued', 'deploying'].includes(original.state))
|
|
394
|
+
return finish(await observedResult(record, await selected.resume({ requestId, signal }), signal));
|
|
395
|
+
return finish(original);
|
|
396
|
+
}
|
|
397
|
+
let attempt = record.payload.createAttempt ?? 0, createClaim = await operationClaim(requestId, 'create', signal, attempt);
|
|
398
|
+
if (rejectedCreate(createClaim)) {
|
|
399
|
+
const latest = await client(signal).getLatestRelease({ signal });
|
|
400
|
+
if (latest && !closedForReplacement(latest.status))
|
|
401
|
+
return { requestId: latest.intent.requestId, state: latest.status.state, sideEffects: latest.status.sideEffects, active: false };
|
|
402
|
+
const version = record.payload.selectedVersion ?? frozenPackage(await journal.load('request:' + requestId, { signal }))?.version;
|
|
403
|
+
if (!version)
|
|
404
|
+
throw fail('FROZEN_REQUEST_INVALID');
|
|
405
|
+
if (latest && !newerVersion(version, latest.intent.package.version) || attempt >= 64)
|
|
406
|
+
return result(record, 'failed', { sideEffects: 'closed', error: { code: 'PUBLISHING_CONFLICT' } });
|
|
407
|
+
// An authenticated rejection is durable. Advance only after observing
|
|
408
|
+
// closure. Unknown create acknowledgements always use the original claim.
|
|
409
|
+
record = await replace(record, 'remote', signal, undefined, ++attempt);
|
|
410
|
+
createClaim = undefined;
|
|
411
|
+
}
|
|
412
|
+
let created;
|
|
413
|
+
try {
|
|
414
|
+
created = await (createClaim ? selected.observe({ requestId, stage: 'create', attempt, signal }) : selected.create({ requestId, attempt, signal }));
|
|
415
|
+
}
|
|
416
|
+
catch (error) {
|
|
417
|
+
if (rejectedCreate(await operationClaim(requestId, 'create', signal, attempt)))
|
|
418
|
+
return result(record, 'failed', { sideEffects: 'closed', error: { code: 'PUBLISHING_CONFLICT' } });
|
|
419
|
+
throw error;
|
|
420
|
+
}
|
|
421
|
+
if (created.receipt.outcome !== 'succeeded')
|
|
422
|
+
return result(record, 'unknown');
|
|
423
|
+
if (created.status && created.status.state !== 'uploading')
|
|
424
|
+
return finish(await observedResult(record, created.status, signal));
|
|
425
|
+
const uploaded = await selected.upload({ requestId, signal });
|
|
426
|
+
if (uploaded.state !== 'uploading')
|
|
427
|
+
return finish(await observedResult(record, uploaded, signal));
|
|
428
|
+
if (uploaded.missingFiles.length)
|
|
429
|
+
throw fail('UPLOAD_INCOMPLETE');
|
|
430
|
+
const queued = await selected.queue({ requestId, signal });
|
|
431
|
+
return queued.status ? finish(await observedResult(record, queued.status, signal)) : result(record, 'unknown');
|
|
432
|
+
},
|
|
433
|
+
status: input => inspect(input), recover: input => inspect(input, true, true), verify: input => inspect(input),
|
|
434
|
+
async abandon({ signal } = {}) {
|
|
435
|
+
const state = await current(signal);
|
|
436
|
+
if (!state)
|
|
437
|
+
throw fail('SOURCE_REQUEST_MISSING');
|
|
438
|
+
let { record } = state;
|
|
439
|
+
if (record.payload.phase === 'abandoned')
|
|
440
|
+
return local(record);
|
|
441
|
+
if (record.payload.phase === 'preparing')
|
|
442
|
+
throw fail('SOURCE_PREPARATION_UNKNOWN');
|
|
443
|
+
if (!['frozen', 'remote'].includes(record.payload.phase))
|
|
444
|
+
throw fail('ABANDON_UNSAFE');
|
|
445
|
+
const requestId = record.payload.requestId;
|
|
446
|
+
if (await operationClaim(requestId, 'commit', signal))
|
|
447
|
+
throw fail('ABANDON_UNSAFE');
|
|
448
|
+
const creation = await operationClaim(requestId, 'create', signal, record.payload.createAttempt);
|
|
449
|
+
if (rejectedCreate(creation))
|
|
450
|
+
return local(await replace(record, 'abandoned', signal));
|
|
451
|
+
if (creation) {
|
|
452
|
+
const selected = session(record, signal), { intent } = await selected.read({ requestId, signal }), status = await client(signal).getStatus({ intent, signal });
|
|
453
|
+
if (status.state === 'abandoned' && status.sideEffects === 'closed')
|
|
454
|
+
return observedResult(record, status, signal);
|
|
455
|
+
if (status.state !== 'uploading' || status.sideEffects !== 'none')
|
|
456
|
+
throw fail('ABANDON_UNSAFE');
|
|
457
|
+
const abandoned = await selected.abandon({ requestId, signal });
|
|
458
|
+
if (abandoned.state !== 'abandoned' || abandoned.sideEffects !== 'closed')
|
|
459
|
+
throw fail('ABANDON_UNSAFE');
|
|
460
|
+
}
|
|
461
|
+
else if (record.payload.phase === 'remote')
|
|
462
|
+
throw fail('ABANDON_UNSAFE');
|
|
463
|
+
record = await replace(record, 'abandoned', signal);
|
|
464
|
+
return local(record);
|
|
465
|
+
},
|
|
466
|
+
});
|
|
467
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Digest, JsonValue } from '@xlinklight/contracts';
|
|
2
|
+
export interface SolutionPackageLimits {
|
|
3
|
+
maximumFiles: number;
|
|
4
|
+
maximumFileBytes: number;
|
|
5
|
+
maximumTotalBytes: number;
|
|
6
|
+
maximumManifestBytes: number;
|
|
7
|
+
timeoutMs: number;
|
|
8
|
+
}
|
|
9
|
+
export interface SolutionPackageDescriptor {
|
|
10
|
+
readonly schemaVersion: 1;
|
|
11
|
+
readonly solutionId: string;
|
|
12
|
+
readonly publisherId: string;
|
|
13
|
+
readonly packageName: string;
|
|
14
|
+
readonly version: string;
|
|
15
|
+
readonly sdkApiVersion: '2.0.0';
|
|
16
|
+
readonly runtime: {
|
|
17
|
+
readonly entry: string;
|
|
18
|
+
readonly protocolVersion: 2;
|
|
19
|
+
readonly links: readonly {
|
|
20
|
+
readonly path: string;
|
|
21
|
+
readonly target: string;
|
|
22
|
+
}[];
|
|
23
|
+
};
|
|
24
|
+
readonly ui: {
|
|
25
|
+
readonly entry: string;
|
|
26
|
+
readonly bridgeVersion: 1;
|
|
27
|
+
};
|
|
28
|
+
readonly release: {
|
|
29
|
+
readonly permissions: JsonValue;
|
|
30
|
+
readonly display: JsonValue;
|
|
31
|
+
readonly queries: JsonValue;
|
|
32
|
+
readonly operations: JsonValue;
|
|
33
|
+
readonly capabilities: JsonValue;
|
|
34
|
+
readonly resourcesDigest: Digest;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export declare function parseSolutionPackageLimits(value: unknown): SolutionPackageLimits;
|
|
38
|
+
export declare function parseSolutionPackageDescriptor(value: unknown): SolutionPackageDescriptor;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { validatePortableRelativePath } from '@openge/forge-path-safety';
|
|
2
|
+
function invalid() { throw Error('PUBLISHING_PACKAGE_DESCRIPTOR_INVALID'); }
|
|
3
|
+
const record = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
4
|
+
const exact = (value, keys) => record(value) && Object.keys(value).sort().join(',') === keys.split(',').sort().join(',');
|
|
5
|
+
const identifier = (value) => typeof value === 'string' && /^[a-z][a-z0-9-]{0,63}$/.test(value);
|
|
6
|
+
export function parseSolutionPackageLimits(value) {
|
|
7
|
+
const names = ['maximumFiles', 'maximumFileBytes', 'maximumTotalBytes', 'maximumManifestBytes', 'timeoutMs'];
|
|
8
|
+
function valid(input) {
|
|
9
|
+
if (!exact(input, names.join(',')))
|
|
10
|
+
return false;
|
|
11
|
+
const maxima = { maximumFiles: 10000, maximumFileBytes: 134217728, maximumTotalBytes: 268435456, maximumManifestBytes: 1048576, timeoutMs: 300000 };
|
|
12
|
+
return names.every(key => { const field = input[key]; return typeof field === 'number' && Number.isSafeInteger(field) && field >= 1 && field <= maxima[key]; });
|
|
13
|
+
}
|
|
14
|
+
if (!valid(value))
|
|
15
|
+
throw Error('PUBLISHING_PACKAGE_LIMIT_INVALID');
|
|
16
|
+
return { ...value };
|
|
17
|
+
}
|
|
18
|
+
function entry(value, prefix) {
|
|
19
|
+
if (typeof value !== 'string' || !value.startsWith(prefix + '/'))
|
|
20
|
+
invalid();
|
|
21
|
+
try {
|
|
22
|
+
if (validatePortableRelativePath(value) !== value)
|
|
23
|
+
invalid();
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
invalid();
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
function json(value, depth = 0) {
|
|
31
|
+
if (depth > 32)
|
|
32
|
+
invalid();
|
|
33
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean')
|
|
34
|
+
return;
|
|
35
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
36
|
+
return;
|
|
37
|
+
if (Array.isArray(value)) {
|
|
38
|
+
for (const item of value)
|
|
39
|
+
json(item, depth + 1);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (record(value)) {
|
|
43
|
+
for (const [key, item] of Object.entries(value)) {
|
|
44
|
+
if (['__proto__', 'prototype', 'constructor'].includes(key))
|
|
45
|
+
invalid();
|
|
46
|
+
json(item, depth + 1);
|
|
47
|
+
}
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
invalid();
|
|
51
|
+
}
|
|
52
|
+
/** Domain metadata stays declarative; deployment and credentials are service policy. */
|
|
53
|
+
function assertDescriptor(value) {
|
|
54
|
+
if (!exact(value, 'schemaVersion,solutionId,publisherId,packageName,version,sdkApiVersion,runtime,ui,release') || value.schemaVersion !== 1 || !identifier(value.solutionId) || !identifier(value.publisherId) || typeof value.packageName !== 'string' || !/^@[a-z0-9][a-z0-9.-]{0,63}\/[a-z0-9][a-z0-9.-]{0,63}$/.test(value.packageName) || typeof value.version !== 'string' || !/^\d{1,8}\.\d{1,8}\.\d{1,8}$/.test(value.version) || value.sdkApiVersion !== '2.0.0')
|
|
55
|
+
invalid();
|
|
56
|
+
if (!exact(value.runtime, 'entry,protocolVersion,links') || value.runtime.protocolVersion !== 2 || !Array.isArray(value.runtime.links) || value.runtime.links.length > 8192 || !exact(value.ui, 'entry,bridgeVersion') || value.ui.bridgeVersion !== 1)
|
|
57
|
+
invalid();
|
|
58
|
+
entry(value.runtime.entry, 'server');
|
|
59
|
+
entry(value.ui.entry, 'ui');
|
|
60
|
+
for (const link of value.runtime.links) {
|
|
61
|
+
if (!exact(link, 'path,target') || typeof link.target !== 'string' || !link.target || link.target.length > 1024 || /[\\:\0\r\n]/.test(link.target) || link.target.startsWith('/'))
|
|
62
|
+
invalid();
|
|
63
|
+
entry(link.path, 'server');
|
|
64
|
+
}
|
|
65
|
+
if (!exact(value.release, 'permissions,display,queries,operations,capabilities,resourcesDigest') || typeof value.release.resourcesDigest !== 'string' || !/^sha256:[a-f0-9]{64}$/.test(value.release.resourcesDigest))
|
|
66
|
+
invalid();
|
|
67
|
+
json(value);
|
|
68
|
+
if (new TextEncoder().encode(JSON.stringify(value)).byteLength > 262144)
|
|
69
|
+
invalid();
|
|
70
|
+
}
|
|
71
|
+
export function parseSolutionPackageDescriptor(value) {
|
|
72
|
+
assertDescriptor(value);
|
|
73
|
+
return structuredClone(value);
|
|
74
|
+
}
|