@xlinklight/publishing 3.3.0 → 3.3.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.
- package/README.md +1 -1
- package/dist/src/acceptance-delivery-binding.js +59 -0
- package/dist/src/acceptance.js +79 -0
- package/dist/src/client.js +146 -0
- package/dist/src/index.js +3 -0
- package/dist/src/node/acceptance-delivery.js +88 -0
- package/dist/src/node/activation.js +3 -0
- package/dist/src/node/authorization.js +76 -0
- package/dist/src/node/cli.js +20 -0
- package/dist/src/node/index.js +9 -0
- package/dist/src/node/journal.js +282 -0
- package/dist/src/node/publishing-command.js +220 -0
- package/dist/src/node/session.js +223 -0
- package/dist/src/node/solution-package.js +217 -0
- package/dist/src/node/source-error.js +15 -0
- package/dist/src/node/source-producer.js +145 -0
- package/dist/src/node/workflow.js +455 -0
- package/dist/src/package.js +74 -0
- package/dist/src/protocol.js +105 -0
- package/dist/src/shared/activation.js +111 -0
- package/dist/src/shared/records.js +26 -0
- package/dist/src/worker/activation.js +10 -0
- package/dist/src/worker/index.js +6 -0
- package/dist/src/worker/journal.js +301 -0
- package/dist/src/worker/package.js +116 -0
- package/dist/src/worker/release.js +59 -0
- package/dist/src/worker/runtime.js +98 -0
- package/dist/src/worker/service.js +494 -0
- package/package.json +17 -14
- package/{src/acceptance.d.mts → types/acceptance.d.ts} +2 -2
- package/{src/client.d.mts → types/client.d.ts} +1 -1
- package/{src/index.d.mts → types/index.d.ts} +6 -6
- package/{src/node/acceptance-delivery.d.mts → types/node/acceptance-delivery.d.ts} +1 -1
- package/{src/node/activation.d.mts → types/node/activation.d.ts} +4 -4
- package/{src/node/authorization.d.mts → types/node/authorization.d.ts} +4 -4
- package/types/node/index.d.ts +17 -0
- package/{src/node/publishing-command.d.mts → types/node/publishing-command.d.ts} +4 -4
- package/{src/node/session.d.mts → types/node/session.d.ts} +7 -7
- package/{src/node/solution-package.d.mts → types/node/solution-package.d.ts} +2 -2
- package/{src/node/workflow.d.mts → types/node/workflow.d.ts} +7 -7
- package/{src/protocol.d.mts → types/protocol.d.ts} +1 -1
- package/{src/worker/activation.d.mts → types/worker/activation.d.ts} +3 -3
- package/types/worker/index.d.ts +6 -0
- package/{src/worker/package.d.mts → types/worker/package.d.ts} +2 -2
- package/{src/worker/release.d.mts → types/worker/release.d.ts} +3 -3
- package/{src/worker/runtime.d.mts → types/worker/runtime.d.ts} +2 -2
- package/{src/worker/service.d.mts → types/worker/service.d.ts} +7 -7
- package/src/acceptance-delivery-binding.mjs +0 -49
- package/src/acceptance.mjs +0 -67
- package/src/client.mjs +0 -74
- package/src/index.mjs +0 -3
- package/src/node/acceptance-delivery.mjs +0 -70
- package/src/node/activation.mjs +0 -3
- 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.mjs +0 -135
- package/src/node/publishing-command.mjs +0 -104
- package/src/node/session.mjs +0 -134
- package/src/node/solution-package.mjs +0 -113
- package/src/node/source-error.mjs +0 -9
- package/src/node/source-producer.mjs +0 -103
- package/src/node/workflow.mjs +0 -320
- package/src/package.mjs +0 -36
- package/src/protocol.mjs +0 -50
- package/src/shared/activation.mjs +0 -64
- 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.mjs +0 -151
- package/src/worker/package.mjs +0 -32
- package/src/worker/release.mjs +0 -21
- package/src/worker/runtime.mjs +0 -23
- package/src/worker/service.mjs +0 -251
- /package/{src/node/journal.d.mts → types/node/journal.d.ts} +0 -0
- /package/{src/node/source-error.d.mts → types/node/source-error.d.ts} +0 -0
- /package/{src/package.d.mts → types/package.d.ts} +0 -0
- /package/{src/shared/activation.d.mts → types/shared/activation.d.ts} +0 -0
- /package/{src/worker/journal.d.mts → types/worker/journal.d.ts} +0 -0
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
import { errorCode, jsonValue, objectRecord } from '../shared/records.js';
|
|
2
|
+
import { createHash, timingSafeEqual } from 'node:crypto';
|
|
3
|
+
import { createArtifactContentManifest, bindArtifactOperation, performArtifactOperation, observeArtifactOperation, ArtifactOperationError } from '@openge/forge-artifact-publish';
|
|
4
|
+
import { parsePublishingConfiguration, parsePublishingIntent, parsePublishingStatus, publishingIntentBytes, publishingIdentifier, publishingDigest, publishingRequestId, protocolRecord, publishingError } from '../protocol.js';
|
|
5
|
+
import { parseSolutionPackageLimits } from '../package.js';
|
|
6
|
+
import { openPreparedPublishingPackage } from './package.js';
|
|
7
|
+
import { verifyPublishingActivation } from './activation.js';
|
|
8
|
+
const hash = (bytes) => createHash('sha256').update(bytes).digest('hex'), encode = (value) => new TextEncoder().encode(JSON.stringify(value));
|
|
9
|
+
const fail = (code) => publishingError(code), key = (id) => 'project:' + id;
|
|
10
|
+
const publicErrors = { NOT_AUTHORIZED: 403, PROJECT_DISABLED: 403, POLICY_CHANGED: 409, CONFLICT: 409, REQUEST_NOT_FOUND: 404, QUOTA_PAUSED: 409, INVALID_INPUT: 400, UNKNOWN_EFFECTS: 409, BUSY: 409, NOT_READY: 409 };
|
|
11
|
+
const defaults = { requestMs: 30000, maximumChunkBytes: 262144, maximumChunks: 4096 };
|
|
12
|
+
function policyInput(value, allowLoopback) {
|
|
13
|
+
if (!protocolRecord(value, ['schemaVersion', 'configuration', 'policyRevision', 'disabled', 'solutionId', 'packageName', 'limits', 'maximumRequests']) || value.schemaVersion !== 1 || typeof value.policyRevision !== 'number' || !Number.isSafeInteger(value.policyRevision) || value.policyRevision < 1 || typeof value.disabled !== 'boolean' || !publishingIdentifier(value.solutionId) || 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.maximumRequests !== 'number' || !Number.isSafeInteger(value.maximumRequests) || value.maximumRequests < 1 || value.maximumRequests > 64)
|
|
14
|
+
throw fail('INVALID_INPUT');
|
|
15
|
+
return { ...value, schemaVersion: 1, configuration: parsePublishingConfiguration(value.configuration, { allowLoopback }), policyRevision: value.policyRevision, disabled: value.disabled, solutionId: value.solutionId, packageName: value.packageName, limits: parseSolutionPackageLimits(value.limits), maximumRequests: value.maximumRequests };
|
|
16
|
+
}
|
|
17
|
+
function storedRequest(item) {
|
|
18
|
+
if (!protocolRecord(item, ['intent', 'manifestByteLength', 'intentSha256', 'state', 'sideEffects', 'files'], ['activation', 'error', 'execution', 'validation']) || !publishingDigest(item.intentSha256) || typeof item.manifestByteLength !== 'number' || typeof item.state !== 'string' || typeof item.sideEffects !== 'string' || !Array.isArray(item.files))
|
|
19
|
+
return false;
|
|
20
|
+
try {
|
|
21
|
+
parsePublishingIntent(item.intent);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (!item.files.every(file => objectRecord(file) && typeof file.sha256 === 'string' && typeof file.byteLength === 'number' && typeof file.receivedBytes === 'number' && Array.isArray(file.chunks) && file.chunks.every(chunk => objectRecord(chunk) && typeof chunk.sha256 === 'string' && typeof chunk.byteLength === 'number')))
|
|
27
|
+
return false;
|
|
28
|
+
const { validation, execution, error } = item;
|
|
29
|
+
return (validation === undefined || objectRecord(validation) && typeof validation.manifestSha256 === 'string' && typeof validation.intentSha256 === 'string' && typeof validation.policySha256 === 'string' && typeof validation.cursor === 'number')
|
|
30
|
+
&& (execution === undefined || objectRecord(execution) && execution.schemaVersion === 1 && typeof execution.planSha256 === 'string' && Array.isArray(execution.completed) && execution.completed.every(stage => objectRecord(stage) && typeof stage.name === 'string' && jsonValue(stage.output)))
|
|
31
|
+
&& (item.activation === undefined || jsonValue(item.activation)) && (error === undefined || objectRecord(error) && typeof error.code === 'string');
|
|
32
|
+
}
|
|
33
|
+
function projectRecord(record, allowLoopback) {
|
|
34
|
+
if (!record || !protocolRecord(record.payload, ['schemaVersion', 'policy', 'credentialSha256', 'requests']) || record.payload.schemaVersion !== 1 || !publishingDigest(record.payload.credentialSha256) || !Array.isArray(record.payload.requests))
|
|
35
|
+
throw fail('UNKNOWN_EFFECTS');
|
|
36
|
+
const { requests, credentialSha256 } = record.payload, policy = policyInput(record.payload.policy, allowLoopback);
|
|
37
|
+
if (requests.length > policy.maximumRequests || !requests.every(storedRequest))
|
|
38
|
+
throw fail('UNKNOWN_EFFECTS');
|
|
39
|
+
return { revision: record.revision, state: { schemaVersion: 1, policy, credentialSha256, requests } };
|
|
40
|
+
}
|
|
41
|
+
function manifestInput(value) {
|
|
42
|
+
return objectRecord(value) && value.schemaVersion === 1 && Array.isArray(value.files) && value.files.every(file => objectRecord(file) && typeof file.path === 'string' && typeof file.sha256 === 'string' && typeof file.byteLength === 'number' && (file.role === 'control' || file.role === 'asset' && objectRecord(file.responseHeaders) && Object.values(file.responseHeaders).every(item => typeof item === 'string')));
|
|
43
|
+
}
|
|
44
|
+
export async function configurePublishingProject({ journal, policy: input, credential, expectedRevision, allowLoopback = false, signal }) {
|
|
45
|
+
const policy = policyInput(input, allowLoopback);
|
|
46
|
+
if (typeof credential !== 'string' || !/^[A-Za-z0-9_-]{32,4096}$/.test(credential) || !Number.isSafeInteger(expectedRevision) || expectedRevision < 0)
|
|
47
|
+
throw fail('INVALID_INPUT');
|
|
48
|
+
const stored = await journal.load(key(policy.configuration.projectId), { signal });
|
|
49
|
+
if ((stored?.revision ?? 0) !== expectedRevision)
|
|
50
|
+
throw fail('CONFLICT');
|
|
51
|
+
let requests = [];
|
|
52
|
+
if (stored) {
|
|
53
|
+
const previous = projectRecord(stored, allowLoopback).state;
|
|
54
|
+
if (policy.policyRevision !== previous.policy.policyRevision + 1 || policy.maximumRequests < previous.requests.length || ['solutionId', 'packageName'].some(name => policy[name] !== previous.policy[name]) || policy.configuration.publisher.publisherId !== previous.policy.configuration.publisher.publisherId)
|
|
55
|
+
throw fail('CONFLICT');
|
|
56
|
+
requests = previous.requests;
|
|
57
|
+
}
|
|
58
|
+
else if (policy.policyRevision !== 1)
|
|
59
|
+
throw fail('INVALID_INPUT');
|
|
60
|
+
const result = await journal.compareAndSet({ key: key(policy.configuration.projectId), expectedRevision, payload: { schemaVersion: 1, policy, credentialSha256: hash(credential), requests } }, { signal, authority: { kind: 'configure', projectId: policy.configuration.projectId } });
|
|
61
|
+
if (result !== 'stored')
|
|
62
|
+
throw fail('CONFLICT');
|
|
63
|
+
return { revision: expectedRevision + 1 };
|
|
64
|
+
}
|
|
65
|
+
async function bodyBytes(request, maximum, signal) {
|
|
66
|
+
const declared = request.headers.get('content-length');
|
|
67
|
+
if (declared !== null && (!/^\d+$/.test(declared) || Number(declared) > maximum))
|
|
68
|
+
throw fail('INVALID_INPUT');
|
|
69
|
+
if (!request.body)
|
|
70
|
+
throw fail('INVALID_INPUT');
|
|
71
|
+
const reader = request.body.getReader(), chunks = [];
|
|
72
|
+
let total = 0;
|
|
73
|
+
const cancel = () => { reader.cancel().catch(() => { }); };
|
|
74
|
+
signal.addEventListener('abort', cancel, { once: true });
|
|
75
|
+
try {
|
|
76
|
+
for (;;) {
|
|
77
|
+
signal.throwIfAborted();
|
|
78
|
+
const { done, value } = await reader.read();
|
|
79
|
+
signal.throwIfAborted();
|
|
80
|
+
if (done)
|
|
81
|
+
break;
|
|
82
|
+
total += value.byteLength;
|
|
83
|
+
if (total > maximum)
|
|
84
|
+
throw fail('INVALID_INPUT');
|
|
85
|
+
chunks.push(value);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
try {
|
|
90
|
+
await reader.cancel();
|
|
91
|
+
}
|
|
92
|
+
catch { }
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
signal.removeEventListener('abort', cancel);
|
|
97
|
+
reader.releaseLock();
|
|
98
|
+
}
|
|
99
|
+
const bytes = new Uint8Array(total);
|
|
100
|
+
let offset = 0;
|
|
101
|
+
for (const chunk of chunks) {
|
|
102
|
+
bytes.set(chunk, offset);
|
|
103
|
+
offset += chunk.byteLength;
|
|
104
|
+
}
|
|
105
|
+
return bytes;
|
|
106
|
+
}
|
|
107
|
+
async function jsonBody(request, signal) {
|
|
108
|
+
if (request.headers.get('content-type') !== 'application/json')
|
|
109
|
+
throw fail('INVALID_INPUT');
|
|
110
|
+
const bytes = await bodyBytes(request, 1056768, signal);
|
|
111
|
+
try {
|
|
112
|
+
return JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes));
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
throw fail('INVALID_INPUT');
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function json(value, status = 200) { const bytes = encode(value); if (bytes.byteLength > 1048576)
|
|
119
|
+
throw fail('QUOTA_PAUSED'); return new Response(bytes, { status, headers: { 'content-type': 'application/json', 'cache-control': 'no-store', 'x-content-type-options': 'nosniff' } }); }
|
|
120
|
+
const blocking = (request) => !['active', 'abandoned', 'superseded'].includes(request.state) && !(request.state === 'failed' && request.sideEffects === 'closed');
|
|
121
|
+
async function manifestFor(journal, item, signal) {
|
|
122
|
+
const bytes = await journal.readBlob({ sha256: item.intent.package.content.manifestSha256, byteLength: item.manifestByteLength }, { signal });
|
|
123
|
+
if (!bytes)
|
|
124
|
+
throw fail('UNKNOWN_EFFECTS');
|
|
125
|
+
try {
|
|
126
|
+
return (await createArtifactContentManifest(JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes)))).manifest;
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
throw fail('UNKNOWN_EFFECTS');
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async function assembled(journal, file, signal, extra) {
|
|
133
|
+
const digest = createHash('sha256');
|
|
134
|
+
let count = 0;
|
|
135
|
+
for (const chunk of file.chunks) {
|
|
136
|
+
signal.throwIfAborted();
|
|
137
|
+
const value = await journal.readBlob(chunk, { signal });
|
|
138
|
+
if (!value || value.byteLength !== chunk.byteLength || hash(value) !== chunk.sha256)
|
|
139
|
+
throw fail('UNKNOWN_EFFECTS');
|
|
140
|
+
digest.update(value);
|
|
141
|
+
count += value.byteLength;
|
|
142
|
+
}
|
|
143
|
+
if (count !== file.receivedBytes)
|
|
144
|
+
throw fail('UNKNOWN_EFFECTS');
|
|
145
|
+
if (extra)
|
|
146
|
+
digest.update(extra);
|
|
147
|
+
return digest.digest('hex');
|
|
148
|
+
}
|
|
149
|
+
async function preparedFor(journal, item, policy, signal) {
|
|
150
|
+
return openPreparedPublishingPackage({ journal, item, limits: policy.limits, signal });
|
|
151
|
+
}
|
|
152
|
+
/** HTTP admission and upload queue only. A separately fenced worker owns deployments. */
|
|
153
|
+
export function createPublishingService({ journal, allowLoopback = false, limits = defaults, onDispatch }) {
|
|
154
|
+
if (!journal || ['load', 'compareAndSet', 'readBlob'].some(name => typeof journal[name] !== 'function') || onDispatch !== undefined && typeof onDispatch !== 'function' || !protocolRecord(limits, ['requestMs', 'maximumChunkBytes', 'maximumChunks']) || Object.values(limits).some(value => typeof value !== 'number' || !Number.isSafeInteger(value) || value < 1) || limits.requestMs > 300000 || limits.maximumChunkBytes > 1048576 || limits.maximumChunks > 32768)
|
|
155
|
+
throw fail('INVALID_INPUT');
|
|
156
|
+
const selected = { ...limits };
|
|
157
|
+
const statusFor = async (item, signal) => {
|
|
158
|
+
const manifest = await manifestFor(journal, item, signal), files = new Map(item.files.map(file => [file.sha256, file]));
|
|
159
|
+
return parsePublishingStatus({ schemaVersion: 1, requestId: item.intent.requestId, projectId: item.intent.projectId, intentSha256: item.intentSha256, state: item.state, sideEffects: item.sideEffects, missingFiles: item.state === 'uploading' ? manifest.files.filter(file => (files.get(file.sha256)?.receivedBytes ?? 0) < file.byteLength).map(file => ({ path: file.path, sha256: file.sha256, byteLength: file.byteLength, receivedBytes: files.get(file.sha256)?.receivedBytes ?? 0 })) : [], ...(item.activation ? { activation: item.activation } : {}), ...(item.error ? { error: item.error } : {}) });
|
|
160
|
+
};
|
|
161
|
+
const authority = (current) => ({ kind: 'request', projectId: current.state.policy.configuration.projectId, policyRevision: current.state.policy.policyRevision, credentialSha256: current.state.credentialSha256 });
|
|
162
|
+
const save = async (current, blobs, signal, dispatch) => {
|
|
163
|
+
const result = await journal.compareAndSet({ key: key(current.state.policy.configuration.projectId), expectedRevision: current.revision, payload: current.state, blobs }, { signal, authority: authority(current), ...(dispatch ? { dispatch } : {}) });
|
|
164
|
+
if (result !== 'stored')
|
|
165
|
+
throw fail('CONFLICT');
|
|
166
|
+
};
|
|
167
|
+
const authorize = async (request, signal) => {
|
|
168
|
+
const header = request.headers.get('authorization'), id = request.headers.get('x-link-light-project-id');
|
|
169
|
+
if (!header || !/^Bearer [A-Za-z0-9_-]{32,4096}$/.test(header) || !publishingIdentifier(id))
|
|
170
|
+
throw fail('NOT_AUTHORIZED');
|
|
171
|
+
const stored = await journal.load(key(id), { signal });
|
|
172
|
+
if (!stored)
|
|
173
|
+
throw fail('NOT_AUTHORIZED');
|
|
174
|
+
const found = projectRecord(stored, allowLoopback);
|
|
175
|
+
if (!timingSafeEqual(Buffer.from(hash(header.slice(7)), 'hex'), Buffer.from(found.state.credentialSha256, 'hex')))
|
|
176
|
+
throw fail('NOT_AUTHORIZED');
|
|
177
|
+
if (found.state.policy.disabled)
|
|
178
|
+
throw fail('PROJECT_DISABLED');
|
|
179
|
+
if (new URL(request.url).origin !== found.state.policy.configuration.serviceUrl)
|
|
180
|
+
throw fail('NOT_AUTHORIZED');
|
|
181
|
+
return found;
|
|
182
|
+
};
|
|
183
|
+
const handle = async (request) => {
|
|
184
|
+
const signal = AbortSignal.any([request.signal, AbortSignal.timeout(selected.requestMs)]);
|
|
185
|
+
try {
|
|
186
|
+
const current = await authorize(request, signal), { state } = current, { policy } = state, url = new URL(request.url);
|
|
187
|
+
if (request.method === 'GET' && url.pathname === '/v1/project' && !url.search)
|
|
188
|
+
return json({ schemaVersion: 1, configuration: policy.configuration, policyRevision: policy.policyRevision, solutionId: policy.solutionId, packageName: policy.packageName, limits: policy.limits });
|
|
189
|
+
if (request.method === 'GET' && url.pathname === '/v1/project/release' && !url.search) {
|
|
190
|
+
const selected = state.requests.find(blocking) ?? state.requests.findLast(item => item.state !== 'abandoned');
|
|
191
|
+
return json({ schemaVersion: 1, intent: selected?.intent ?? null });
|
|
192
|
+
}
|
|
193
|
+
if (request.method === 'POST' && url.pathname === '/v1/requests' && !url.search) {
|
|
194
|
+
const body = await jsonBody(request, signal);
|
|
195
|
+
if (!protocolRecord(body, ['intent', 'manifest']))
|
|
196
|
+
throw fail('INVALID_INPUT');
|
|
197
|
+
const intent = parsePublishingIntent(body.intent), item = intent.package;
|
|
198
|
+
if (intent.projectId !== policy.configuration.projectId || item.publisherId !== policy.configuration.publisher.publisherId || item.solutionId !== policy.solutionId || item.packageName !== policy.packageName)
|
|
199
|
+
throw fail('NOT_AUTHORIZED');
|
|
200
|
+
if (intent.policyRevision !== policy.policyRevision)
|
|
201
|
+
throw fail('POLICY_CHANGED');
|
|
202
|
+
if (!manifestInput(body.manifest))
|
|
203
|
+
throw fail('INVALID_INPUT');
|
|
204
|
+
const manifest = await createArtifactContentManifest(body.manifest);
|
|
205
|
+
if (manifest.content.manifestSha256 !== item.content.manifestSha256 || manifest.manifest.files.length !== item.fileCount || manifest.manifest.files.reduce((sum, file) => sum + file.byteLength, 0) !== item.totalBytes || item.fileCount > policy.limits.maximumFiles || manifest.bytes.byteLength > policy.limits.maximumManifestBytes || item.totalBytes + manifest.bytes.byteLength > policy.limits.maximumTotalBytes || manifest.manifest.files.some(file => file.byteLength > policy.limits.maximumFileBytes))
|
|
206
|
+
throw fail('INVALID_INPUT');
|
|
207
|
+
const intentSha256 = hash(publishingIntentBytes(intent)), existing = state.requests.find(request => request.intent.requestId === intent.requestId);
|
|
208
|
+
if (existing) {
|
|
209
|
+
if (existing.intentSha256 !== intentSha256)
|
|
210
|
+
throw fail('CONFLICT');
|
|
211
|
+
return json(await statusFor(existing, signal));
|
|
212
|
+
}
|
|
213
|
+
if (state.requests.some(blocking) || state.requests.some(request => request.state !== 'abandoned' && request.intent.package.version === item.version))
|
|
214
|
+
throw fail('CONFLICT');
|
|
215
|
+
if (state.requests.length >= policy.maximumRequests)
|
|
216
|
+
throw fail('QUOTA_PAUSED');
|
|
217
|
+
const files = new Map();
|
|
218
|
+
for (const file of manifest.manifest.files) {
|
|
219
|
+
const previous = files.get(file.sha256);
|
|
220
|
+
if (previous && previous.byteLength !== file.byteLength)
|
|
221
|
+
throw fail('INVALID_INPUT');
|
|
222
|
+
files.set(file.sha256, { sha256: file.sha256, byteLength: file.byteLength, receivedBytes: 0, chunks: [] });
|
|
223
|
+
}
|
|
224
|
+
const created = { intent, manifestByteLength: manifest.bytes.byteLength, intentSha256, state: 'uploading', sideEffects: 'none', files: [...files.values()] };
|
|
225
|
+
const response = json(parsePublishingStatus({ schemaVersion: 1, requestId: intent.requestId, projectId: intent.projectId, intentSha256, state: 'uploading', sideEffects: 'none', missingFiles: manifest.manifest.files.filter(file => file.byteLength).map(file => ({ path: file.path, sha256: file.sha256, byteLength: file.byteLength, receivedBytes: 0 })) }), 201);
|
|
226
|
+
state.requests.push(created);
|
|
227
|
+
await save(current, [{ sha256: manifest.content.manifestSha256, bytes: manifest.bytes }], signal);
|
|
228
|
+
return response;
|
|
229
|
+
}
|
|
230
|
+
const route = /^\/v1\/requests\/([a-f0-9-]{36})(?:\/(commit|abandon|resume|recover|files\/([a-f0-9]{64})))?$/.exec(url.pathname);
|
|
231
|
+
if (!route || !publishingRequestId(route[1]))
|
|
232
|
+
throw fail('REQUEST_NOT_FOUND');
|
|
233
|
+
const item = state.requests.find(item => item.intent.requestId === route[1]);
|
|
234
|
+
if (!item)
|
|
235
|
+
throw fail('REQUEST_NOT_FOUND');
|
|
236
|
+
if (request.method === 'GET' && !route[2] && !url.search)
|
|
237
|
+
return json(await statusFor(item, signal));
|
|
238
|
+
if (request.method === 'POST' && route[2] === 'abandon' && !url.search) {
|
|
239
|
+
if (!protocolRecord(await jsonBody(request, signal), []))
|
|
240
|
+
throw fail('INVALID_INPUT');
|
|
241
|
+
if (item.state === 'abandoned' && item.sideEffects === 'closed')
|
|
242
|
+
return json(await statusFor(item, signal));
|
|
243
|
+
if (item.state !== 'uploading' || item.sideEffects !== 'none')
|
|
244
|
+
throw fail('UNKNOWN_EFFECTS');
|
|
245
|
+
item.state = 'abandoned';
|
|
246
|
+
item.sideEffects = 'closed';
|
|
247
|
+
await save(current, [], signal);
|
|
248
|
+
return json(await statusFor(item, signal));
|
|
249
|
+
}
|
|
250
|
+
if (item.intent.policyRevision !== policy.policyRevision)
|
|
251
|
+
throw fail('POLICY_CHANGED');
|
|
252
|
+
if (request.method === 'POST' && ['resume', 'recover'].includes(route[2]) && !url.search) {
|
|
253
|
+
const body = await jsonBody(request, signal);
|
|
254
|
+
if (!protocolRecord(body, ['intent']) || hash(publishingIntentBytes(body.intent)) !== item.intentSha256)
|
|
255
|
+
throw fail('CONFLICT');
|
|
256
|
+
if (route[2] === 'resume' && item.state === 'unknown')
|
|
257
|
+
throw fail('UNKNOWN_EFFECTS');
|
|
258
|
+
if (['queued', 'deploying', 'unknown'].includes(item.state) || route[2] === 'recover' && item.state === 'awaiting-acceptance') {
|
|
259
|
+
if (!onDispatch)
|
|
260
|
+
throw fail('NOT_READY');
|
|
261
|
+
const dispatch = { projectId: policy.configuration.projectId, requestId: item.intent.requestId, mode: route[2] === 'recover' || item.state === 'deploying' ? 'observe' : 'perform', continue: route[2] !== 'recover' };
|
|
262
|
+
await journal.enqueue(dispatch, { signal, authority: authority(current) });
|
|
263
|
+
await onDispatch(dispatch);
|
|
264
|
+
}
|
|
265
|
+
return json(await statusFor(item, signal));
|
|
266
|
+
}
|
|
267
|
+
if (request.method === 'PUT' && route[3]) {
|
|
268
|
+
if (request.headers.get('content-type') !== 'application/octet-stream' || url.searchParams.size !== 1 || !/^\d{1,9}$/.test(url.searchParams.get('offset') ?? ''))
|
|
269
|
+
throw fail('INVALID_INPUT');
|
|
270
|
+
if (item.state !== 'uploading' || item.sideEffects !== 'none')
|
|
271
|
+
throw fail('NOT_READY');
|
|
272
|
+
const file = item.files.find(file => file.sha256 === route[3]);
|
|
273
|
+
if (!file)
|
|
274
|
+
throw fail('INVALID_INPUT');
|
|
275
|
+
const offset = Number(url.searchParams.get('offset'));
|
|
276
|
+
if (offset > file.receivedBytes || item.files.reduce((sum, file) => sum + file.chunks.length, 0) >= selected.maximumChunks)
|
|
277
|
+
throw fail('INVALID_INPUT');
|
|
278
|
+
const bytes = await bodyBytes(request, Math.min(selected.maximumChunkBytes, file.byteLength - offset), signal);
|
|
279
|
+
if (!bytes.byteLength)
|
|
280
|
+
throw fail('INVALID_INPUT');
|
|
281
|
+
const sha256 = hash(bytes);
|
|
282
|
+
if (offset < file.receivedBytes) {
|
|
283
|
+
let previous = 0;
|
|
284
|
+
for (const chunk of file.chunks) {
|
|
285
|
+
if (previous === offset && chunk.byteLength === bytes.byteLength && chunk.sha256 === sha256)
|
|
286
|
+
return json({ schemaVersion: 1, sha256: file.sha256, receivedBytes: offset + bytes.byteLength });
|
|
287
|
+
previous += chunk.byteLength;
|
|
288
|
+
}
|
|
289
|
+
throw fail('CONFLICT');
|
|
290
|
+
}
|
|
291
|
+
if (offset + bytes.byteLength === file.byteLength && await assembled(journal, file, signal, bytes) !== file.sha256)
|
|
292
|
+
throw fail('INVALID_INPUT');
|
|
293
|
+
file.chunks.push({ sha256, byteLength: bytes.byteLength });
|
|
294
|
+
file.receivedBytes += bytes.byteLength;
|
|
295
|
+
await save(current, [{ sha256, bytes }], signal);
|
|
296
|
+
return json({ schemaVersion: 1, sha256: file.sha256, receivedBytes: file.receivedBytes });
|
|
297
|
+
}
|
|
298
|
+
if (request.method === 'POST' && route[2] === 'commit' && !url.search) {
|
|
299
|
+
const body = await jsonBody(request, signal);
|
|
300
|
+
if (!protocolRecord(body, ['intent']) || hash(publishingIntentBytes(body.intent)) !== item.intentSha256)
|
|
301
|
+
throw fail('CONFLICT');
|
|
302
|
+
if (item.state !== 'uploading')
|
|
303
|
+
return json(await statusFor(item, signal));
|
|
304
|
+
if (item.files.some(file => file.receivedBytes !== file.byteLength))
|
|
305
|
+
throw fail('NOT_READY');
|
|
306
|
+
await preparedFor(journal, item, policy, signal);
|
|
307
|
+
item.validation = { manifestSha256: item.intent.package.content.manifestSha256, intentSha256: item.intentSha256, policySha256: hash(encode(policy)), cursor: 0 };
|
|
308
|
+
item.state = 'queued';
|
|
309
|
+
item.sideEffects = 'pending';
|
|
310
|
+
const dispatch = { projectId: policy.configuration.projectId, requestId: item.intent.requestId, mode: 'perform', continue: true };
|
|
311
|
+
await save(current, [], signal, dispatch);
|
|
312
|
+
await onDispatch?.(dispatch);
|
|
313
|
+
return json(await statusFor(item, signal));
|
|
314
|
+
}
|
|
315
|
+
throw fail('REQUEST_NOT_FOUND');
|
|
316
|
+
}
|
|
317
|
+
catch (error) {
|
|
318
|
+
const name = error instanceof Error ? error.name : '', message = error instanceof Error ? error.message : '', reason = errorCode(error);
|
|
319
|
+
const code = Object.keys(publicErrors).find(code => reason === 'PUBLISHING_' + code) ?? (reason === 'PUBLISHING_JOURNAL_BUSY' ? 'BUSY' : /^PUBLISHING_(?:PACKAGE|INTENT|CONFIGURATION)_/.test(message) || name === 'ArtifactPublicationError' ? 'INVALID_INPUT' : 'UNKNOWN_EFFECTS');
|
|
320
|
+
return json({ error: { code } }, publicErrors[code]);
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
return Object.freeze({ handle });
|
|
324
|
+
}
|
|
325
|
+
/** One explicitly invoked worker operation. The host supplies a real distributed
|
|
326
|
+
* project lock and an installed deployment adapter; uploaded code stays opaque.
|
|
327
|
+
* Factories and readResult are read-only. Each external step has its own public
|
|
328
|
+
* Foundation operation; recovering a step never dispatches a later step. */
|
|
329
|
+
export function createPublishingWorker({ journal, withProjectLock, stages: inputStages, allowLoopback = false, metadataTransport, verifyActivation = verifyPublishingActivation, operationLimits = { timeoutMilliseconds: 300000, closeTimeoutMilliseconds: 5000 } }) {
|
|
330
|
+
if (!journal || ['load', 'compareAndSet', 'readBlob', 'operationJournal'].some(name => typeof journal[name] !== 'function') || typeof withProjectLock !== 'function' || !Array.isArray(inputStages) || !inputStages.length || inputStages.length > 20
|
|
331
|
+
|| inputStages.some(stage => !protocolRecord(stage, ['name', 'capability', 'configurationSha256', 'createDeployment'], ['waitForSignal']) || !publishingIdentifier(stage.name) || !['artifact-upload', 'deployment-create', 'deployment-ready', 'activation'].includes(stage.capability) || !publishingDigest(stage.configurationSha256) || typeof stage.createDeployment !== 'function' || Object.hasOwn(stage, 'waitForSignal') && (stage.waitForSignal !== true || stage.capability !== 'deployment-ready'))
|
|
332
|
+
|| new Set(inputStages.map(stage => stage.name)).size !== inputStages.length || inputStages.at(-1)?.capability !== 'activation')
|
|
333
|
+
throw fail('INVALID_INPUT');
|
|
334
|
+
const limits = { ...operationLimits }, stages = inputStages.map(stage => ({ ...stage })), planSha256 = hash(encode(stages.map(({ name, capability, configurationSha256, waitForSignal }) => ({ name, capability, configurationSha256, waitForSignal }))));
|
|
335
|
+
if (!protocolRecord(limits, ['timeoutMilliseconds', 'closeTimeoutMilliseconds']) || Object.values(limits).some(value => typeof value !== 'number' || !Number.isSafeInteger(value) || value < 1 || value > 300000))
|
|
336
|
+
throw fail('INVALID_INPUT');
|
|
337
|
+
return Object.freeze({ async run({ projectId, requestId, mode = 'perform', signal }) {
|
|
338
|
+
if (!publishingIdentifier(projectId) || !publishingRequestId(requestId) || !['perform', 'observe'].includes(mode))
|
|
339
|
+
throw fail('INVALID_INPUT');
|
|
340
|
+
const timeout = AbortSignal.timeout(limits.timeoutMilliseconds), deadline = signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
341
|
+
return withProjectLock({ projectId, requestId, mode, signal: deadline }, async (lock) => {
|
|
342
|
+
if (!lock || typeof lock.assertHeld !== 'function')
|
|
343
|
+
throw fail('INVALID_INPUT');
|
|
344
|
+
const currentSignal = lock.signal ? AbortSignal.any([deadline, lock.signal]) : deadline;
|
|
345
|
+
const load = async () => {
|
|
346
|
+
currentSignal.throwIfAborted();
|
|
347
|
+
await lock.assertHeld();
|
|
348
|
+
const current = projectRecord(await journal.load(key(projectId), { signal: currentSignal }), allowLoopback), item = current.state.requests.find(item => item.intent.requestId === requestId);
|
|
349
|
+
if (!item)
|
|
350
|
+
throw fail('REQUEST_NOT_FOUND');
|
|
351
|
+
if (current.state.policy.disabled)
|
|
352
|
+
throw fail('PROJECT_DISABLED');
|
|
353
|
+
if (item.intent.policyRevision !== current.state.policy.policyRevision)
|
|
354
|
+
throw fail('POLICY_CHANGED');
|
|
355
|
+
return { ...current, item };
|
|
356
|
+
};
|
|
357
|
+
const initial = await load(), intent = parsePublishingIntent(initial.item.intent), configuration = initial.state.policy.configuration, intentSha256 = hash(publishingIntentBytes(intent)), configurationSha256 = hash(encode(configuration));
|
|
358
|
+
if (initial.item.intentSha256 !== intentSha256 || intent.projectId !== projectId)
|
|
359
|
+
throw fail('UNKNOWN_EFFECTS');
|
|
360
|
+
const assertAuthorized = async () => {
|
|
361
|
+
const current = await load();
|
|
362
|
+
if (current.item.intentSha256 !== intentSha256 || hash(encode(current.state.policy.configuration)) !== configurationSha256)
|
|
363
|
+
throw fail('POLICY_CHANGED');
|
|
364
|
+
return current;
|
|
365
|
+
};
|
|
366
|
+
const save = async (state, sideEffects, execution, activation) => {
|
|
367
|
+
const current = await assertAuthorized();
|
|
368
|
+
current.item.state = state;
|
|
369
|
+
current.item.sideEffects = sideEffects;
|
|
370
|
+
current.item.execution = execution;
|
|
371
|
+
if (activation !== undefined)
|
|
372
|
+
current.item.activation = activation;
|
|
373
|
+
else
|
|
374
|
+
delete current.item.activation;
|
|
375
|
+
const stored = await journal.compareAndSet({ key: key(projectId), expectedRevision: current.revision, payload: current.state }, { signal: currentSignal });
|
|
376
|
+
if (stored !== 'stored')
|
|
377
|
+
throw fail('CONFLICT');
|
|
378
|
+
};
|
|
379
|
+
if (['uploading', 'abandoned', 'superseded'].includes(initial.item.state))
|
|
380
|
+
throw fail('NOT_READY');
|
|
381
|
+
const prepared = await preparedFor(journal, initial.item, initial.state.policy, currentSignal), validation = initial.item.validation;
|
|
382
|
+
if (!validation || validation.manifestSha256 !== intent.package.content.manifestSha256 || validation.intentSha256 !== intentSha256 || validation.policySha256 !== hash(encode(initial.state.policy)) || !Number.isSafeInteger(validation.cursor) || validation.cursor < 0 || validation.cursor > prepared.files.length)
|
|
383
|
+
throw fail('UNKNOWN_EFFECTS');
|
|
384
|
+
if (validation.cursor < prepared.files.length) {
|
|
385
|
+
const result = await prepared.verifyBatch({ cursor: validation.cursor, maximumFiles: 1, maximumBytes: initial.state.policy.limits.maximumFileBytes, signal: currentSignal }), current = await assertAuthorized();
|
|
386
|
+
if (current.item.validation?.cursor !== validation.cursor)
|
|
387
|
+
throw fail('CONFLICT');
|
|
388
|
+
current.item.validation = { ...validation, cursor: result.cursor };
|
|
389
|
+
if (await journal.compareAndSet({ key: key(projectId), expectedRevision: current.revision, payload: current.state }, { signal: currentSignal }) !== 'stored')
|
|
390
|
+
throw fail('CONFLICT');
|
|
391
|
+
return { requestId, state: current.item.state, sideEffects: current.item.sideEffects, next: 'verify' };
|
|
392
|
+
}
|
|
393
|
+
const originalExecution = structuredClone(initial.item.execution ?? { schemaVersion: 1, planSha256, completed: [] }), execution = structuredClone(originalExecution);
|
|
394
|
+
if (!protocolRecord(execution, ['schemaVersion', 'planSha256', 'completed']) || execution.schemaVersion !== 1 || execution.planSha256 !== planSha256 || !Array.isArray(execution.completed) || execution.completed.length > stages.length
|
|
395
|
+
|| execution.completed.some((item, index) => !protocolRecord(item, ['name', 'output']) || item.name !== stages[index].name) || encode(execution).byteLength > 262144)
|
|
396
|
+
throw fail('POLICY_CHANGED');
|
|
397
|
+
if (mode === 'perform' && ['active', 'failed', 'unknown'].includes(initial.item.state))
|
|
398
|
+
throw fail('RECOVERY_REQUIRED');
|
|
399
|
+
if (mode === 'perform' && execution.completed.length === stages.length)
|
|
400
|
+
throw fail('RECOVERY_REQUIRED');
|
|
401
|
+
const index = Math.min(execution.completed.length, stages.length - 1), stage = stages[index], operationId = requestId + '.' + stage.name, operationJournal = journal.operationJournal();
|
|
402
|
+
const existing = await operationJournal.load(operationId, { signal: currentSignal, timeoutMilliseconds: limits.timeoutMilliseconds });
|
|
403
|
+
if (mode === 'perform' && existing)
|
|
404
|
+
throw fail('RECOVERY_REQUIRED');
|
|
405
|
+
if (mode === 'observe' && !existing) {
|
|
406
|
+
if (execution.completed.length)
|
|
407
|
+
return { requestId, state: initial.item.state, sideEffects: initial.item.sideEffects, next: 'perform' };
|
|
408
|
+
throw fail('RECOVERY_REQUIRED');
|
|
409
|
+
}
|
|
410
|
+
const previous = execution.completed.slice(0, index), previousBytes = encode(previous);
|
|
411
|
+
const selected = stage.createDeployment({ policy: structuredClone(initial.state.policy), intent: structuredClone(intent), prepared, previous: structuredClone(previous), assertAuthorized: async () => { await assertAuthorized(); }, signal: currentSignal });
|
|
412
|
+
if (!selected || 'then' in selected && typeof selected.then === 'function' || typeof selected.readResult !== 'function' || !selected.transport || ['execute', 'observe', 'close'].some(name => typeof selected.transport[name] !== 'function') || selected.transport.capability !== stage.capability || selected.transport.configurationSha256 !== stage.configurationSha256) {
|
|
413
|
+
if (selected instanceof Promise)
|
|
414
|
+
selected.catch(() => { });
|
|
415
|
+
await save('unknown', 'unknown', originalExecution);
|
|
416
|
+
throw fail('INVALID_INPUT');
|
|
417
|
+
}
|
|
418
|
+
const binding = await bindArtifactOperation({ requestId: operationId, content: intent.package.content, ...(intent.provenance ? { provenance: intent.provenance } : {}), target: selected.transport.target, capability: stage.capability, configurationSha256: stage.configurationSha256, inputs: [{ name: 'intent.json', sha256: intentSha256, byteLength: publishingIntentBytes(intent).byteLength }, { name: 'project-policy.json', sha256: hash(encode(initial.state.policy)), byteLength: encode(initial.state.policy).byteLength }, { name: 'previous-results.json', sha256: hash(previousBytes), byteLength: previousBytes.byteLength }] });
|
|
419
|
+
const transport = { ...selected.transport,
|
|
420
|
+
async execute(bound, context) { await assertAuthorized(); const result = await selected.transport.execute(bound, context); await assertAuthorized(); return result; },
|
|
421
|
+
async observe(bound, reference, context) { await assertAuthorized(); const result = await selected.transport.observe(bound, reference, context); await assertAuthorized(); return result; },
|
|
422
|
+
close: options => selected.transport.close(options),
|
|
423
|
+
};
|
|
424
|
+
if (mode === 'perform')
|
|
425
|
+
await save('deploying', 'pending', execution);
|
|
426
|
+
try {
|
|
427
|
+
lock.beginOperation?.();
|
|
428
|
+
const receipt = await (mode === 'perform' ? performArtifactOperation : observeArtifactOperation)(transport, binding, operationJournal, { ...limits, signal: currentSignal });
|
|
429
|
+
lock.confirmClosure?.(receipt.closure);
|
|
430
|
+
await assertAuthorized();
|
|
431
|
+
let state = 'unknown', sideEffects = 'unknown', activation;
|
|
432
|
+
if (receipt.journalState === 'confirmed' && receipt.closure.status === 'closed' && receipt.closure.activeRequests === 0) {
|
|
433
|
+
if (receipt.outcome === 'succeeded') {
|
|
434
|
+
const output = selected.readResult({ record: receipt.record });
|
|
435
|
+
if (output && (typeof output === 'object' || typeof output === 'function') && 'then' in output && typeof output.then === 'function') {
|
|
436
|
+
if (output instanceof Promise)
|
|
437
|
+
output.catch(() => { });
|
|
438
|
+
throw fail('INVALID_INPUT');
|
|
439
|
+
}
|
|
440
|
+
const encoded = JSON.stringify(output);
|
|
441
|
+
if (typeof encoded !== 'string' || Buffer.byteLength(encoded) > 65536)
|
|
442
|
+
throw fail('INVALID_INPUT');
|
|
443
|
+
const snapshot = JSON.parse(encoded);
|
|
444
|
+
if (index === stages.length - 1) {
|
|
445
|
+
activation = snapshot;
|
|
446
|
+
await verifyActivation({ configuration, intent, activation, allowLoopback, metadataTransport: metadataTransport ?? (async () => { throw fail('ACTIVATION_ADMISSION_REQUIRED'); }), signal: currentSignal });
|
|
447
|
+
await assertAuthorized();
|
|
448
|
+
state = 'active';
|
|
449
|
+
sideEffects = 'closed';
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
state = 'deploying';
|
|
453
|
+
sideEffects = 'pending';
|
|
454
|
+
}
|
|
455
|
+
if (execution.completed.length === index)
|
|
456
|
+
execution.completed.push({ name: stage.name, output: snapshot });
|
|
457
|
+
else if (hash(encode(execution.completed[index].output)) !== hash(encode(snapshot)))
|
|
458
|
+
throw fail('UNKNOWN_EFFECTS');
|
|
459
|
+
if (encode(execution).byteLength > 262144)
|
|
460
|
+
throw fail('QUOTA_PAUSED');
|
|
461
|
+
}
|
|
462
|
+
else if (receipt.outcome === 'failed') {
|
|
463
|
+
state = 'failed';
|
|
464
|
+
sideEffects = 'closed';
|
|
465
|
+
}
|
|
466
|
+
else if (receipt.outcome === 'pending') {
|
|
467
|
+
state = stage.waitForSignal ? 'awaiting-acceptance' : 'deploying';
|
|
468
|
+
sideEffects = 'pending';
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
await save(state, sideEffects, execution, activation);
|
|
472
|
+
return { requestId, state, sideEffects, receipt, ...(state === 'deploying' && receipt.outcome === 'succeeded' ? { next: 'perform' } : {}) };
|
|
473
|
+
}
|
|
474
|
+
catch (error) {
|
|
475
|
+
if (error instanceof ArtifactOperationError)
|
|
476
|
+
lock.confirmClosure?.(error.receipt?.closure);
|
|
477
|
+
// A changed policy may also refuse this diagnostic write; never replace
|
|
478
|
+
// the original error or use the failure path to grant final authority.
|
|
479
|
+
try {
|
|
480
|
+
const current = await assertAuthorized(), saved = current.item.execution ?? { schemaVersion: 1, planSha256, completed: [] };
|
|
481
|
+
// A lost outer CAS acknowledgement must not downgrade a cursor that the
|
|
482
|
+
// store already advanced. Recovery can observe that committed result.
|
|
483
|
+
if (hash(encode(saved)) === hash(encode(originalExecution))) {
|
|
484
|
+
const receipt = error instanceof ArtifactOperationError ? error.receipt : undefined;
|
|
485
|
+
const rejected = errorCode(error) === 'PROVIDER_REJECTED' && receipt?.outcome === 'failed' && receipt.record.binding.fingerprint === binding.fingerprint && receipt.record.writeState === 'rejected' && receipt.journalState === 'confirmed' && receipt.closure.status === 'closed' && receipt.closure.activeRequests === 0;
|
|
486
|
+
await save(rejected ? 'failed' : 'unknown', rejected ? 'closed' : 'unknown', originalExecution);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
catch { }
|
|
490
|
+
throw error;
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
} });
|
|
494
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xlinklight/publishing",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,29 +15,30 @@
|
|
|
15
15
|
"type": "module",
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"files": [
|
|
18
|
-
"src",
|
|
18
|
+
"dist/src",
|
|
19
|
+
"types",
|
|
19
20
|
"README.md"
|
|
20
21
|
],
|
|
21
22
|
"bin": {
|
|
22
|
-
"link-light-release": "./src/node/cli.
|
|
23
|
+
"link-light-release": "./dist/src/node/cli.js"
|
|
23
24
|
},
|
|
24
25
|
"exports": {
|
|
25
26
|
"./acceptance": {
|
|
26
|
-
"types": "./
|
|
27
|
-
"import": "./src/acceptance.
|
|
27
|
+
"types": "./types/acceptance.d.ts",
|
|
28
|
+
"import": "./dist/src/acceptance.js"
|
|
28
29
|
},
|
|
29
30
|
"./worker": {
|
|
30
|
-
"types": "./
|
|
31
|
-
"import": "./src/worker/index.
|
|
31
|
+
"types": "./types/worker/index.d.ts",
|
|
32
|
+
"import": "./dist/src/worker/index.js"
|
|
32
33
|
},
|
|
33
34
|
".": {
|
|
34
|
-
"types": "./
|
|
35
|
-
"import": "./src/index.
|
|
35
|
+
"types": "./types/index.d.ts",
|
|
36
|
+
"import": "./dist/src/index.js"
|
|
36
37
|
},
|
|
37
38
|
"./node": {
|
|
38
|
-
"types": "./
|
|
39
|
+
"types": "./types/node/index.d.ts",
|
|
39
40
|
"browser": null,
|
|
40
|
-
"import": "./src/node/index.
|
|
41
|
+
"import": "./dist/src/node/index.js"
|
|
41
42
|
}
|
|
42
43
|
},
|
|
43
44
|
"dependencies": {
|
|
@@ -48,7 +49,7 @@
|
|
|
48
49
|
"@xlinklight/contracts": "3.0.0"
|
|
49
50
|
},
|
|
50
51
|
"peerDependencies": {
|
|
51
|
-
"@xlinklight/platform": "5.1.
|
|
52
|
+
"@xlinklight/platform": "5.1.1"
|
|
52
53
|
},
|
|
53
54
|
"peerDependenciesMeta": {
|
|
54
55
|
"@xlinklight/platform": {
|
|
@@ -59,7 +60,9 @@
|
|
|
59
60
|
"node": ">=22.15.0"
|
|
60
61
|
},
|
|
61
62
|
"scripts": {
|
|
62
|
-
"
|
|
63
|
-
"
|
|
63
|
+
"typecheck": "tsc --noEmit -p tsconfig.build.json",
|
|
64
|
+
"build": "tsc -p tsconfig.build.json",
|
|
65
|
+
"test": "tsc -p tsconfig.tests.json && node --test --test-concurrency=1 dist/tests/*.node-test.js",
|
|
66
|
+
"test:workerd": "tsc -p tsconfig.tests.json && node --test dist/tests/durable-workerd.native-test.js"
|
|
64
67
|
}
|
|
65
68
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {KeyObject} from 'node:crypto';
|
|
2
2
|
import type {SolutionReleaseManifest} from '@xlinklight/contracts';
|
|
3
|
-
export {maximumAcceptanceArchiveBytes, readDeliveryBody, verifyAcceptanceDelivery} from './node/acceptance-delivery.
|
|
4
|
-
export type {AcceptanceDeliveryBinding} from './node/acceptance-delivery.
|
|
3
|
+
export {maximumAcceptanceArchiveBytes, readDeliveryBody, verifyAcceptanceDelivery} from './node/acceptance-delivery.js';
|
|
4
|
+
export type {AcceptanceDeliveryBinding} from './node/acceptance-delivery.js';
|
|
5
5
|
|
|
6
6
|
export interface AcceptanceIdentity {
|
|
7
7
|
projectId:string;requestId:string;intentSha256:string;policyRevision:number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {JsonValue} from '@xlinklight/contracts';
|
|
2
|
-
import type {PublishingConfiguration,PublishingProject,PublishingIntent,PublishingStatus} from './protocol.
|
|
2
|
+
import type {PublishingConfiguration,PublishingProject,PublishingIntent,PublishingStatus} from './protocol.js';
|
|
3
3
|
export interface PublishingClientLimits {requestMs:number;maximumResponseBytes:number;maximumChunkBytes:number}
|
|
4
4
|
export interface PublishingClient {
|
|
5
5
|
getProject(input?:{signal?:AbortSignal}):Promise<PublishingProject>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export type {SolutionPackageDescriptor,SolutionPackageLimits} from './package.
|
|
2
|
-
export {parseSolutionPackageDescriptor,parseSolutionPackageLimits} from './package.
|
|
3
|
-
export type {PublishingConfiguration,PublishingProject,PublishingIntent,PublishingStatus,PublishingMetadataTransport} from './protocol.
|
|
4
|
-
export {parsePublishingConfiguration,parsePublishingProject,parsePublishingIntent,parsePublishingStatus,publishingIntentBytes} from './protocol.
|
|
5
|
-
export type {PublishingClient,PublishingClientLimits,PublishingClientOptions} from './client.
|
|
6
|
-
export {createPublishingClient} from './client.
|
|
1
|
+
export type {SolutionPackageDescriptor,SolutionPackageLimits} from './package.js';
|
|
2
|
+
export {parseSolutionPackageDescriptor,parseSolutionPackageLimits} from './package.js';
|
|
3
|
+
export type {PublishingConfiguration,PublishingProject,PublishingIntent,PublishingStatus,PublishingMetadataTransport} from './protocol.js';
|
|
4
|
+
export {parsePublishingConfiguration,parsePublishingProject,parsePublishingIntent,parsePublishingStatus,publishingIntentBytes} from './protocol.js';
|
|
5
|
+
export type {PublishingClient,PublishingClientLimits,PublishingClientOptions} from './client.js';
|
|
6
|
+
export {createPublishingClient} from './client.js';
|
|
@@ -6,6 +6,6 @@ export interface AcceptanceDeliveryBinding extends AcceptanceArchiveIdentity {
|
|
|
6
6
|
}
|
|
7
7
|
export const maximumAcceptanceArchiveBytes:number;
|
|
8
8
|
export function signAcceptanceDelivery(binding:AcceptanceDeliveryBinding,privateKey:string|import('node:crypto').KeyObject):string;
|
|
9
|
-
export function deliverAcceptanceArchive(input:{intent:import('../protocol.
|
|
9
|
+
export function deliverAcceptanceArchive(input:{intent:import('../protocol.js').PublishingIntent;archive:AcceptanceArchiveIdentity;bytes:Uint8Array;credential:AcceptanceDeliveryCredential;request?:typeof fetch;signal?:AbortSignal}):Promise<void>;
|
|
10
10
|
export function verifyAcceptanceDelivery(binding:AcceptanceDeliveryBinding,signature:string,publicKey:string|import('node:crypto').KeyObject):void;
|
|
11
11
|
export function readDeliveryBody(message:Request|Response,limit:number):Promise<Buffer>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type {SolutionReleaseManifest} from '@xlinklight/contracts';
|
|
2
|
-
import type {PublishingMetadataTransport as ReleaseMetadataTransport} from '../protocol.
|
|
3
|
-
import type {PublishingConfiguration,PublishingIntent} from '../protocol.
|
|
4
|
-
import type {PublishingActivation} from '../shared/activation.
|
|
5
|
-
export type {PublishingActivation} from '../shared/activation.
|
|
2
|
+
import type {PublishingMetadataTransport as ReleaseMetadataTransport} from '../protocol.js';
|
|
3
|
+
import type {PublishingConfiguration,PublishingIntent} from '../protocol.js';
|
|
4
|
+
import type {PublishingActivation} from '../shared/activation.js';
|
|
5
|
+
export type {PublishingActivation} from '../shared/activation.js';
|
|
6
6
|
interface ActivationContext {configuration:PublishingConfiguration;intent:PublishingIntent;allowLoopback?:boolean;metadataTransport?:ReleaseMetadataTransport;signal?:AbortSignal}
|
|
7
7
|
export function createPublishingActivation(input:ActivationContext&{manifest:SolutionReleaseManifest;acceptanceReceiptSha256:string;keyId:string;privateKey:string}):Promise<PublishingActivation>;
|
|
8
8
|
export function verifyPublishingActivation(input:ActivationContext&{activation:unknown}):Promise<{manifest:Readonly<SolutionReleaseManifest>;acceptanceReceiptSha256:string}>;
|