@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
package/README.md
CHANGED
|
@@ -2,12 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
## Publishing from an owner checkout
|
|
4
4
|
|
|
5
|
-
The project administrator enrolls the owner with Publisher. Install the project authorization on each trusted workstation with `pnpm release:credentials` using a non-interactive stdin pipe. A delivery-enabled authorization contains `configuration`, `credential` and `acceptanceDelivery`. The last object contains the owner runner's exact HTTPS `origin`, its deployment `keyId` and the project-specific Ed25519 PKCS8 `privateKey`. Protect
|
|
5
|
+
The project administrator enrolls the owner with Publisher. Install the project authorization on each trusted workstation with `pnpm release:credentials` using a non-interactive stdin pipe. A delivery-enabled authorization contains `configuration`, `credential` and `acceptanceDelivery`. The last object contains the owner runner's exact HTTPS `origin`, its deployment `keyId` and the project-specific Ed25519 PKCS8 `privateKey`. Protect the input and backups with OS access controls. The owner's public `package.json` declares `linkLight.acceptanceDelivery` as `"required"`.
|
|
6
|
+
|
|
7
|
+
New client journals restrict access to the owner on Linux, and to the current user, SYSTEM and local Administrators on Windows. Credential installation checks the existing journal directory and its database and marker before storing a bearer or delivery key. A shared target returns `PUBLISHING_JOURNAL_PRIVATE_REQUIRED` and keeps its original permissions. Use the same dedicated journal for later release commands.
|
|
8
|
+
|
|
9
|
+
For split enrollment, the administrator pipes `{configuration,credential}` into `pnpm release:credentials --delivery-credential-file <absolute-local-path>` on the owner workstation. The script runs `link-light-release credentials --stdin`. The named owner secret file holds `{origin,keyId,privateKey}` as UTF-8 JSON, up to 16 KiB. The CLI reads a regular file with a single link from its canonical local path and verifies the project before installation. Supply the delivery credential once, either in stdin or in the owner file. Subsequent verification of the same installed project preserves its delivery credential when stdin contains only the project authorization.
|
|
6
10
|
|
|
7
11
|
Set the intended version in the owner's manifest and run `pnpm release`. A fresh request freezes the prepared solution and owner acceptance archive in a single journal transaction. The client retains its original destination and bytes through interruption. It observes the authenticated project's last request before starting the next version, and requires current Core admission to accept an active receipt. Another authorized machine verifies the existing intent and uses the same identity for identical version content.
|
|
8
12
|
|
|
9
13
|
Use `pnpm release:status` to inspect, `pnpm release:recover` to reconcile the original effects and `pnpm release:verify` to verify activation again. A bounded timeout or unknown response returns the request ID and a nonzero exit. A closed source preparation failure can be corrected and retried with `pnpm release --new-preparation`. Independent clients need project authorization and an installed Node toolchain.
|
|
10
14
|
|
|
15
|
+
### Workstation proxy
|
|
16
|
+
|
|
17
|
+
On Windows, `pnpm release:credentials`, `pnpm release`, `pnpm release:status` and `pnpm release:verify` automatically use the system proxy and bypass rules for the registered Publisher, Core and acceptance origins. This works on the first enrollment and with existing authorization. A selected loopback HTTP proxy uses the optional `@openge/forge-http-transport@0.1.0` development peer included in the independent solution template. Other platforms use their ordinary Node transport by default.
|
|
18
|
+
|
|
19
|
+
To select a loopback HTTP proxy for one CLI process on any platform, set `LINK_LIGHT_PUBLISHING_PROXY` to an origin such as `http://127.0.0.1:8080` or `http://[::1]:8080`. The release CLI consumes this variable before loading the owner producer.
|
|
20
|
+
|
|
21
|
+
Publisher credentials travel inside TLS to the registered Publisher. Core metadata uses a separate GET after validating every DNS answer. The tunnel connects to the selected public IP and TLS verifies the original hostname. An unavailable system proxy lookup returns `PUBLISHING_NETWORK_SYSTEM_PROXY_UNAVAILABLE`. Invalid overrides return `PUBLISHING_NETWORK_CONFIG_INVALID`.
|
|
22
|
+
|
|
23
|
+
Node tools can import `discoverWindowsProxyRoutes` from `@xlinklight/publishing/node` to resolve one to sixteen canonical HTTPS origins in one Windows settings lookup. Results follow the input order. Each entry is a loopback HTTP proxy origin or `null` for a system bypass. The optional second argument is an `AbortSignal`.
|
|
24
|
+
|
|
25
|
+
Trusted clients can also call `openPublishingTerminalNetwork({serviceUrl,coreOrigin,deliveryOrigin}, {signal,proxy})` from the Node entry. The delivery origin and options are optional. Pass the returned `request` and `metadataTransport` to the client and await `close()` when finished. An `undefined` result selects the usual direct transports.
|
|
26
|
+
|
|
11
27
|
Solution publishing binds declarative metadata, an opaque Worker module closure and separately served static UI bytes to Foundation's canonical content manifest. The publisher never discovers or executes code from an uploaded package. The root entry parses the portable envelope. `@xlinklight/publishing/node` owns local capture, the CLI, credentials and the client SQLite journal. `@xlinklight/publishing/worker` owns the service, durable queue and finite deployment stages for a SQLite Durable Object. There is one cloud execution path: Cloudflare Workers and Durable Objects, with explicit provider adapters for immutable Workers and Pages deployments.
|
|
12
28
|
|
|
13
29
|
## Local preparation and client
|
|
@@ -17,15 +33,19 @@ Solution publishing binds declarative metadata, an opaque Worker module closure
|
|
|
17
33
|
The `link-light-release` executable provides `credentials`, `check`, `publish`, `status`, `recover`, `verify` and `abandon`. `credentials --stdin` installs a pinned project configuration and token. A fresh `check` or `publish` selects an owner-installed producer in this order.
|
|
18
34
|
|
|
19
35
|
1. An explicit `--producer` portable checkout-relative `.mjs` path.
|
|
20
|
-
2. The checkout's `package.json` field `linkLight.publishingProducer`. Use a portable checkout-relative `.mjs` string or an object with a single `module` key naming a bare public package subpath, such as `{"module":"@example/owner-tools/deployment-producer"}`. Declare the package in the checkout's `dependencies` or `devDependencies` and install it under the checkout's `node_modules`. Node's `createRequire(...).resolve()` must find
|
|
36
|
+
2. The checkout's `package.json` field `linkLight.publishingProducer`. Use a portable checkout-relative `.mjs` string or an object with a single `module` key naming a bare public package subpath, such as `{"module":"@example/owner-tools/deployment-producer"}`. Declare the package in the checkout's `dependencies` or `devDependencies` and install it under the checkout's `node_modules`. Node's `createRequire(...).resolve()` must find a regular ESM file within that installed package. It may be a `.mjs` file, or a `.js` file whose nearest `package.json` declares `"type":"module"`. The package can expose its ESM entry through the `default` condition. pnpm links to packages inside the checkout's `node_modules` are supported.
|
|
21
37
|
3. `deployment/publishing.mjs` when the metadata field is absent.
|
|
22
38
|
|
|
23
|
-
The checkout manifest, installed producer's package manifest and producer entry each have a 64 KiB limit. Invalid selection fails closed before producer code runs. Correct the selection and use `--new-preparation` to retry a closed failure. Each durable preparation invokes the producer once and requires its `prepare` result to confirm `processesClosed: true`. Unknown producer closure requires recovery. Frozen requests retain their original bytes and can be resumed after the selection or its files change. The default private client state is `state/solution-publishing`, separate from disposable build outputs.
|
|
39
|
+
The checkout manifest, installed producer's package manifest and producer entry each have a 64 KiB limit. Invalid selection fails closed before producer code runs. Correct the selection and use `--new-preparation` to retry a closed failure. Each durable preparation invokes the producer once and requires its `prepare` result to confirm `processesClosed: true`. Unknown producer closure requires recovery. Frozen requests retain their original bytes and can be resumed after the selection or its files change. The default private client state is `state/solution-publishing`, separate from disposable build outputs.
|
|
24
40
|
|
|
25
41
|
The client never automatically repeats request creation. `publish` reuses frozen original bytes and an explicit request identity. CLI publish waits up to 300000 ms; `--no-wait` submits without waiting and `--wait-ms <1..3600000>` selects a finite wait. Programmatic `workflow.publish` defaults to one observation. Waiting uses GET only. Queued, pending or timed-out work exits 3; a closed failure exits 1; verified ACTIVE exits 0. Recovery observes the original operation without advancing its next stage. Resume may advance only after a known pending operation is observed successfully. Neither operation rebuilds, uploads or re-commits the package. Status and verification never dispatch work.
|
|
26
42
|
|
|
27
43
|
## Durable Object composition
|
|
28
44
|
|
|
45
|
+
A host with one active release per project can enable `replaceClosedReleases` when creating the publishing service. The Node CLI already derives a stable request ID per version. Direct clients can call `publishingVersionRequestId(configuration, packageName, version)` from the Node or Worker entry. A higher version can use the same request slot once the previous operations have closed. The service retains the signed active receipt while verifying its successor. A failed candidate leaves the previous active release available.
|
|
46
|
+
|
|
47
|
+
The SQLite journal reclaims unreferenced package chunks and settled operation records in the new request transaction. Hosts that keep private records can supply `recordsForRequest` and return exact keys and revisions after checking ownership. A conflicting revision rolls back the replacement. Blobs shared by another request and records with unresolved ownership remain available.
|
|
48
|
+
|
|
29
49
|
Use the public Worker entry with Cloudflare `nodejs_compat`; mature crypto and async-context primitives are shared with the Node client. The server graph imports no filesystem, Node HTTP, DNS, subprocess or UI implementation. The application owns one singleton SQLite Durable Object and its trusted configuration, provider credentials and lifecycle:
|
|
30
50
|
|
|
31
51
|
1. `openPublishingDurableJournal({storage: ctx.storage, identity, limits, leaseMs})` binds a durable identity and exact storage limits. `configurePublishingProject` installs a project policy and credential through the trusted composition, never an uploaded module.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { KeyObject } from 'node:crypto';
|
|
2
|
+
export interface AcceptanceArchiveIdentity {
|
|
3
|
+
archiveSha256: string;
|
|
4
|
+
artifactSha256: string;
|
|
5
|
+
byteLength: number;
|
|
6
|
+
}
|
|
7
|
+
export interface AcceptanceDeliveryBinding extends AcceptanceArchiveIdentity {
|
|
8
|
+
projectId: string;
|
|
9
|
+
solutionId: string;
|
|
10
|
+
version: string;
|
|
11
|
+
origin: string;
|
|
12
|
+
keyId: string;
|
|
13
|
+
manifestSha256: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const maximumAcceptanceArchiveBytes: number;
|
|
16
|
+
export declare const deliveryBindingFields: readonly ["projectId", "solutionId", "version", "origin", "keyId", "manifestSha256", "archiveSha256", "artifactSha256", "byteLength"];
|
|
17
|
+
export declare function validateDeliveryOrigin(value: unknown): string;
|
|
18
|
+
export declare function deliveryBindingBytes(value: unknown): Buffer<ArrayBuffer>;
|
|
19
|
+
export declare function verifyAcceptanceDelivery(value: AcceptanceDeliveryBinding, signature: string, publicKey: string | KeyObject): void;
|
|
20
|
+
export declare function readDeliveryBody(message: Request | Response, limit: number): Promise<Buffer>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createPublicKey, verify } from 'node:crypto';
|
|
2
|
+
import { protocolRecord, publishingDigest, publishingError, publishingIdentifier } from './protocol.js';
|
|
3
|
+
export const maximumAcceptanceArchiveBytes = 50 * 1024 ** 2;
|
|
4
|
+
export const deliveryBindingFields = Object.freeze([
|
|
5
|
+
'projectId', 'solutionId', 'version', 'origin', 'keyId', 'manifestSha256', 'archiveSha256', 'artifactSha256', 'byteLength',
|
|
6
|
+
]);
|
|
7
|
+
const fail = (code) => publishingError('ACCEPTANCE_' + code);
|
|
8
|
+
const versionPattern = /^\d{1,8}\.\d{1,8}\.\d{1,8}$/;
|
|
9
|
+
export function validateDeliveryOrigin(value) {
|
|
10
|
+
if (typeof value !== 'string')
|
|
11
|
+
throw fail('ORIGIN_INVALID');
|
|
12
|
+
const url = URL.parse(value);
|
|
13
|
+
if (url?.protocol !== 'https:' || url.origin !== value)
|
|
14
|
+
throw fail('ORIGIN_INVALID');
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
export function deliveryBindingBytes(value) {
|
|
18
|
+
if (!protocolRecord(value, deliveryBindingFields) || ![value.projectId, value.solutionId, value.keyId].every(publishingIdentifier) ||
|
|
19
|
+
typeof value.version !== 'string' || !versionPattern.test(value.version) || ![value.manifestSha256, value.archiveSha256, value.artifactSha256].every(publishingDigest) ||
|
|
20
|
+
typeof value.byteLength !== 'number' || !Number.isSafeInteger(value.byteLength) || value.byteLength < 1 || value.byteLength > maximumAcceptanceArchiveBytes)
|
|
21
|
+
throw fail('BINDING_INVALID');
|
|
22
|
+
validateDeliveryOrigin(value.origin);
|
|
23
|
+
return Buffer.from(JSON.stringify(['link-light/owner-acceptance-installation/v1', ...deliveryBindingFields.map(key => value[key])]));
|
|
24
|
+
}
|
|
25
|
+
export function verifyAcceptanceDelivery(value, signature, publicKey) {
|
|
26
|
+
if (typeof signature !== 'string' || !/^[A-Za-z0-9_-]{86}$/.test(signature))
|
|
27
|
+
throw fail('SIGNATURE_INVALID');
|
|
28
|
+
const key = typeof publicKey === 'string' ? createPublicKey(publicKey) : publicKey;
|
|
29
|
+
if (key?.asymmetricKeyType !== 'ed25519' || !verify(null, deliveryBindingBytes(value), key, Buffer.from(signature, 'base64url')))
|
|
30
|
+
throw fail('SIGNATURE_INVALID');
|
|
31
|
+
}
|
|
32
|
+
export async function readDeliveryBody(message, limit) {
|
|
33
|
+
const length = message.headers.get('content-length');
|
|
34
|
+
if (!Number.isSafeInteger(limit) || limit < 1 || limit > maximumAcceptanceArchiveBytes || !message.body ||
|
|
35
|
+
length !== null && (!/^\d+$/.test(length) || Number(length) > limit))
|
|
36
|
+
throw fail('BODY_LIMIT');
|
|
37
|
+
const reader = message.body.getReader(), chunks = [];
|
|
38
|
+
let total = 0;
|
|
39
|
+
try {
|
|
40
|
+
for (;;) {
|
|
41
|
+
const { done, value } = await reader.read();
|
|
42
|
+
if (done)
|
|
43
|
+
break;
|
|
44
|
+
total += value.byteLength;
|
|
45
|
+
if (total > limit)
|
|
46
|
+
throw fail('BODY_LIMIT');
|
|
47
|
+
chunks.push(value);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
try {
|
|
52
|
+
await reader.cancel();
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
reader.releaseLock();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return Buffer.concat(chunks, total);
|
|
59
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export { maximumAcceptanceArchiveBytes, readDeliveryBody, verifyAcceptanceDelivery } from './acceptance-delivery-binding.js';
|
|
2
|
+
import type { KeyObject } from 'node:crypto';
|
|
3
|
+
import type { SolutionReleaseManifest } from '@xlinklight/contracts';
|
|
4
|
+
export type { AcceptanceDeliveryBinding } from './acceptance-delivery-binding.js';
|
|
5
|
+
export interface AcceptanceIdentity {
|
|
6
|
+
projectId: string;
|
|
7
|
+
requestId: string;
|
|
8
|
+
intentSha256: string;
|
|
9
|
+
policyRevision: number;
|
|
10
|
+
releaseDigest: string;
|
|
11
|
+
acceptanceArtifactSha256: string;
|
|
12
|
+
generation: number;
|
|
13
|
+
}
|
|
14
|
+
export interface AcceptanceJob extends AcceptanceIdentity {
|
|
15
|
+
schemaVersion: 1;
|
|
16
|
+
jobId: string;
|
|
17
|
+
manifest: Readonly<SolutionReleaseManifest>;
|
|
18
|
+
}
|
|
19
|
+
export interface AcceptanceReceipt extends AcceptanceIdentity {
|
|
20
|
+
schemaVersion: 1;
|
|
21
|
+
jobId: string;
|
|
22
|
+
status: 'PASS';
|
|
23
|
+
proof: {
|
|
24
|
+
syntheticInstancesCreated: number;
|
|
25
|
+
syntheticInstancesDisabled: number;
|
|
26
|
+
closure: {
|
|
27
|
+
status: 'closed';
|
|
28
|
+
activeRequests: 0;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export interface AcceptanceEnvelope<Payload> {
|
|
33
|
+
payload: Payload;
|
|
34
|
+
keyId: string;
|
|
35
|
+
signature: string;
|
|
36
|
+
}
|
|
37
|
+
export interface AcceptanceSigner {
|
|
38
|
+
keyId: string;
|
|
39
|
+
privateKey: string | KeyObject;
|
|
40
|
+
}
|
|
41
|
+
export interface AcceptanceVerifier {
|
|
42
|
+
keyId: string;
|
|
43
|
+
publicKey: string | KeyObject;
|
|
44
|
+
}
|
|
45
|
+
export declare function acceptanceJobId(identity: AcceptanceIdentity): string;
|
|
46
|
+
export declare const signAcceptanceJob: (job: AcceptanceJob, options: AcceptanceSigner) => AcceptanceEnvelope<AcceptanceJob>;
|
|
47
|
+
export declare const verifyAcceptanceJob: (envelope: unknown, options: AcceptanceVerifier) => AcceptanceJob;
|
|
48
|
+
export declare const signAcceptanceReceipt: (receipt: AcceptanceReceipt, options: AcceptanceSigner) => AcceptanceEnvelope<AcceptanceReceipt>;
|
|
49
|
+
export declare const verifyAcceptanceReceipt: (envelope: unknown, options: AcceptanceVerifier) => AcceptanceReceipt;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { createHash, createPrivateKey, createPublicKey, sign, verify } from 'node:crypto';
|
|
2
|
+
import { canonicalMetadata } from '@xlinklight/platform/worker';
|
|
3
|
+
import { protocolRecord, publishingDigest, publishingError, publishingIdentifier, publishingRequestId } from './protocol.js';
|
|
4
|
+
export { maximumAcceptanceArchiveBytes, readDeliveryBody, verifyAcceptanceDelivery } from './acceptance-delivery-binding.js';
|
|
5
|
+
const positive = (value) => typeof value === 'number' && Number.isSafeInteger(value) && value > 0;
|
|
6
|
+
const object = (value) => value !== null && typeof value === 'object';
|
|
7
|
+
const identityKeys = ['projectId', 'requestId', 'intentSha256', 'policyRevision', 'releaseDigest', 'acceptanceArtifactSha256', 'generation'];
|
|
8
|
+
const bindingKeys = ['schemaVersion', 'jobId', ...identityKeys];
|
|
9
|
+
const invalid = (part) => publishingError('ACCEPTANCE_' + part + '_INVALID');
|
|
10
|
+
function validIdentity(value) {
|
|
11
|
+
return object(value) && publishingIdentifier(value.projectId) && publishingRequestId(value.requestId)
|
|
12
|
+
&& publishingDigest(value.intentSha256) && positive(value.policyRevision) && typeof value.releaseDigest === 'string'
|
|
13
|
+
&& /^sha256:[a-f0-9]{64}$/.test(value.releaseDigest) && publishingDigest(value.acceptanceArtifactSha256) && positive(value.generation);
|
|
14
|
+
}
|
|
15
|
+
export function acceptanceJobId(identity) {
|
|
16
|
+
if (!validIdentity(identity))
|
|
17
|
+
throw invalid('JOB');
|
|
18
|
+
const binding = Object.fromEntries(identityKeys.map(key => [key, identity[key]]));
|
|
19
|
+
return createHash('sha256').update('link-light/acceptance-job-id/v1\n').update(canonicalMetadata(binding)).digest('hex');
|
|
20
|
+
}
|
|
21
|
+
function checkBinding(payload, kind) {
|
|
22
|
+
try {
|
|
23
|
+
return payload.schemaVersion === 1 && validIdentity(payload) && payload.jobId === acceptanceJobId(payload);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
throw invalid(kind);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function assertJob(payload) {
|
|
30
|
+
if (!protocolRecord(payload, [...bindingKeys, 'manifest']) || !checkBinding(payload, 'JOB')
|
|
31
|
+
|| !object(payload.manifest) || payload.manifest.releaseDigest !== payload.releaseDigest || !publishingIdentifier(payload.manifest.solutionId)
|
|
32
|
+
|| typeof payload.manifest.version !== 'string' || !/^\d{1,8}\.\d{1,8}\.\d{1,8}$/.test(payload.manifest.version))
|
|
33
|
+
throw invalid('JOB');
|
|
34
|
+
}
|
|
35
|
+
function jobPayload(payload) {
|
|
36
|
+
assertJob(payload);
|
|
37
|
+
return payload;
|
|
38
|
+
}
|
|
39
|
+
function assertReceipt(payload) {
|
|
40
|
+
if (!protocolRecord(payload, [...bindingKeys, 'status', 'proof']) || !checkBinding(payload, 'RECEIPT') || payload.status !== 'PASS'
|
|
41
|
+
|| !protocolRecord(payload.proof, ['syntheticInstancesCreated', 'syntheticInstancesDisabled', 'closure']))
|
|
42
|
+
throw invalid('RECEIPT');
|
|
43
|
+
const { syntheticInstancesCreated, syntheticInstancesDisabled, closure } = payload.proof;
|
|
44
|
+
if (!positive(syntheticInstancesCreated) || syntheticInstancesCreated < 2 || syntheticInstancesCreated > 1024
|
|
45
|
+
|| syntheticInstancesCreated !== syntheticInstancesDisabled || !protocolRecord(closure, ['status', 'activeRequests'])
|
|
46
|
+
|| closure.status !== 'closed' || closure.activeRequests !== 0)
|
|
47
|
+
throw invalid('RECEIPT');
|
|
48
|
+
}
|
|
49
|
+
function receiptPayload(payload) {
|
|
50
|
+
assertReceipt(payload);
|
|
51
|
+
return payload;
|
|
52
|
+
}
|
|
53
|
+
function message(kind, payload) {
|
|
54
|
+
const canonical = canonicalMetadata(payload);
|
|
55
|
+
if (Buffer.byteLength(canonical) > 65536)
|
|
56
|
+
throw invalid(kind);
|
|
57
|
+
return Buffer.from('link-light/acceptance-' + kind.toLowerCase() + '/v1\n' + canonical);
|
|
58
|
+
}
|
|
59
|
+
function signEnvelope(payload, kind, { keyId, privateKey }) {
|
|
60
|
+
const key = typeof privateKey === 'string' ? createPrivateKey(privateKey) : privateKey;
|
|
61
|
+
if (!publishingIdentifier(keyId) || key?.type !== 'private' || key.asymmetricKeyType !== 'ed25519')
|
|
62
|
+
throw invalid('SIGNATURE');
|
|
63
|
+
return { payload: structuredClone(payload), keyId, signature: sign(null, message(kind, payload), key).toString('base64url') };
|
|
64
|
+
}
|
|
65
|
+
function verifyEnvelope(envelope, kind, parse, { keyId, publicKey }) {
|
|
66
|
+
if (!protocolRecord(envelope, ['payload', 'keyId', 'signature']) || !publishingIdentifier(keyId) || envelope.keyId !== keyId
|
|
67
|
+
|| typeof envelope.signature !== 'string' || !/^[A-Za-z0-9_-]{86}$/.test(envelope.signature))
|
|
68
|
+
throw invalid('SIGNATURE');
|
|
69
|
+
const payload = parse(envelope.payload), bytes = Buffer.from(envelope.signature, 'base64url');
|
|
70
|
+
const key = typeof publicKey === 'string' ? createPublicKey(publicKey) : publicKey;
|
|
71
|
+
if (key?.type !== 'public' || key.asymmetricKeyType !== 'ed25519' || bytes.toString('base64url') !== envelope.signature
|
|
72
|
+
|| !verify(null, message(kind, payload), key, bytes))
|
|
73
|
+
throw invalid('SIGNATURE');
|
|
74
|
+
return structuredClone(payload);
|
|
75
|
+
}
|
|
76
|
+
export const signAcceptanceJob = (job, options) => signEnvelope(jobPayload(job), 'JOB', options);
|
|
77
|
+
export const verifyAcceptanceJob = (envelope, options) => verifyEnvelope(envelope, 'JOB', jobPayload, options);
|
|
78
|
+
export const signAcceptanceReceipt = (receipt, options) => signEnvelope(receiptPayload(receipt), 'RECEIPT', options);
|
|
79
|
+
export const verifyAcceptanceReceipt = (envelope, options) => verifyEnvelope(envelope, 'RECEIPT', receiptPayload, options);
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { PublishingConfiguration, PublishingIntent, PublishingProject, PublishingStatus } from './protocol.js';
|
|
2
|
+
import type { JsonValue } from '@xlinklight/contracts';
|
|
3
|
+
export interface PublishingClientLimits {
|
|
4
|
+
requestMs: number;
|
|
5
|
+
maximumResponseBytes: number;
|
|
6
|
+
maximumChunkBytes: number;
|
|
7
|
+
}
|
|
8
|
+
export interface PublishingClient {
|
|
9
|
+
getProject(input?: {
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
}): Promise<PublishingProject>;
|
|
12
|
+
getLatestRelease(input?: {
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
}): Promise<{
|
|
15
|
+
intent: PublishingIntent;
|
|
16
|
+
status: PublishingStatus;
|
|
17
|
+
} | undefined>;
|
|
18
|
+
createRequest(input: {
|
|
19
|
+
intent: PublishingIntent;
|
|
20
|
+
manifestBytes: Uint8Array;
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
}): Promise<PublishingStatus>;
|
|
23
|
+
getStatus(input: {
|
|
24
|
+
intent: PublishingIntent;
|
|
25
|
+
signal?: AbortSignal;
|
|
26
|
+
}): Promise<PublishingStatus>;
|
|
27
|
+
resumeRequest(input: {
|
|
28
|
+
intent: PublishingIntent;
|
|
29
|
+
signal?: AbortSignal;
|
|
30
|
+
}): Promise<PublishingStatus>;
|
|
31
|
+
recoverRequest(input: {
|
|
32
|
+
intent: PublishingIntent;
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
}): Promise<PublishingStatus>;
|
|
35
|
+
queueRequest(input: {
|
|
36
|
+
intent: PublishingIntent;
|
|
37
|
+
signal?: AbortSignal;
|
|
38
|
+
}): Promise<PublishingStatus>;
|
|
39
|
+
abandonRequest(input: {
|
|
40
|
+
intent: PublishingIntent;
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
}): Promise<PublishingStatus>;
|
|
43
|
+
uploadChunk(input: {
|
|
44
|
+
requestId: string;
|
|
45
|
+
file: {
|
|
46
|
+
sha256: string;
|
|
47
|
+
byteLength: number;
|
|
48
|
+
};
|
|
49
|
+
offset: number;
|
|
50
|
+
bytes: Uint8Array;
|
|
51
|
+
signal?: AbortSignal;
|
|
52
|
+
}): Promise<{
|
|
53
|
+
schemaVersion: 1;
|
|
54
|
+
sha256: string;
|
|
55
|
+
receivedBytes: number;
|
|
56
|
+
}>;
|
|
57
|
+
}
|
|
58
|
+
export interface PublishingClientOptions {
|
|
59
|
+
configuration: PublishingConfiguration;
|
|
60
|
+
credential: string;
|
|
61
|
+
allowLoopback?: boolean;
|
|
62
|
+
request?: typeof fetch;
|
|
63
|
+
limits?: PublishingClientLimits;
|
|
64
|
+
verifyActivation?: (input: {
|
|
65
|
+
activation: JsonValue;
|
|
66
|
+
intent: PublishingIntent;
|
|
67
|
+
configuration: PublishingConfiguration;
|
|
68
|
+
}) => Promise<void> | void;
|
|
69
|
+
}
|
|
70
|
+
/** All writes are explicit. Recovery reads the original request; there is no retry loop. */
|
|
71
|
+
export declare function createPublishingClient({ configuration, credential, allowLoopback, request, limits, verifyActivation }: PublishingClientOptions): PublishingClient;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { calculateBytesIntegrity } from '@openge/forge-artifact-integrity';
|
|
2
|
+
import { createArtifactContentManifest } from '@openge/forge-artifact-publish';
|
|
3
|
+
import { parsePublishingConfiguration, parsePublishingProject, parsePublishingIntent, parsePublishingStatus, publishingIntentBytes, publishingError, publishingRequestId, publishingDigest, protocolRecord } from './protocol.js';
|
|
4
|
+
const defaults = Object.freeze({ requestMs: 30000, maximumResponseBytes: 1048576, maximumChunkBytes: 262144 });
|
|
5
|
+
const serviceErrors = new Set(['NOT_AUTHORIZED', 'PROJECT_DISABLED', 'POLICY_CHANGED', 'CONFLICT', 'REQUEST_NOT_FOUND', 'QUOTA_PAUSED', 'INVALID_INPUT', 'UNKNOWN_EFFECTS', 'BUSY', 'NOT_READY']);
|
|
6
|
+
function boundedLimits(value) {
|
|
7
|
+
if (!protocolRecord(value, ['requestMs', 'maximumResponseBytes', 'maximumChunkBytes']) || Object.values(value).some(item => typeof item !== 'number' || !Number.isSafeInteger(item) || item < 1) || value.requestMs > 300000 || value.maximumResponseBytes > 2097152 || value.maximumChunkBytes > 1048576)
|
|
8
|
+
throw publishingError('CLIENT_LIMIT_INVALID');
|
|
9
|
+
return { ...value };
|
|
10
|
+
}
|
|
11
|
+
async function responseJson(response, maximum, signal) {
|
|
12
|
+
const declared = response.headers.get('content-length');
|
|
13
|
+
if (declared !== null && (!/^\d+$/.test(declared) || Number(declared) > maximum)) {
|
|
14
|
+
await response.body?.cancel();
|
|
15
|
+
throw publishingError('RESPONSE_BYTE_LIMIT');
|
|
16
|
+
}
|
|
17
|
+
if (!response.body)
|
|
18
|
+
throw publishingError('RESPONSE_INVALID');
|
|
19
|
+
const reader = response.body.getReader(), chunks = [];
|
|
20
|
+
let total = 0;
|
|
21
|
+
try {
|
|
22
|
+
for (;;) {
|
|
23
|
+
signal.throwIfAborted();
|
|
24
|
+
const { done, value } = await reader.read();
|
|
25
|
+
if (done)
|
|
26
|
+
break;
|
|
27
|
+
total += value.byteLength;
|
|
28
|
+
if (total > maximum)
|
|
29
|
+
throw publishingError('RESPONSE_BYTE_LIMIT');
|
|
30
|
+
chunks.push(value);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
try {
|
|
35
|
+
await reader.cancel();
|
|
36
|
+
}
|
|
37
|
+
catch { }
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
reader.releaseLock();
|
|
42
|
+
}
|
|
43
|
+
const bytes = new Uint8Array(total);
|
|
44
|
+
let offset = 0;
|
|
45
|
+
for (const chunk of chunks) {
|
|
46
|
+
bytes.set(chunk, offset);
|
|
47
|
+
offset += chunk.byteLength;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
return JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes));
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
throw publishingError('RESPONSE_INVALID');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** All writes are explicit. Recovery reads the original request; there is no retry loop. */
|
|
57
|
+
export function createPublishingClient({ configuration, credential, allowLoopback = false, request = fetch, limits = defaults, verifyActivation }) {
|
|
58
|
+
const config = parsePublishingConfiguration(configuration, { allowLoopback }), selected = boundedLimits(limits);
|
|
59
|
+
if (typeof credential !== 'string' || !/^[A-Za-z0-9_-]{32,4096}$/.test(credential) || typeof request !== 'function' || verifyActivation !== undefined && typeof verifyActivation !== 'function')
|
|
60
|
+
throw publishingError('CREDENTIAL_INVALID');
|
|
61
|
+
const send = async (method, relative, body, signal, contentType = 'application/json') => {
|
|
62
|
+
signal?.throwIfAborted();
|
|
63
|
+
const timeout = AbortSignal.timeout(selected.requestMs), active = signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
64
|
+
let response;
|
|
65
|
+
try {
|
|
66
|
+
response = await request(config.serviceUrl + relative, { method, headers: { authorization: 'Bearer ' + credential, 'x-link-light-project-id': config.projectId, ...(body === undefined ? {} : { 'content-type': contentType }) }, body, redirect: 'error', credentials: 'omit', cache: 'no-store', signal: active });
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
active.throwIfAborted();
|
|
70
|
+
throw publishingError('SERVICE_UNREACHABLE');
|
|
71
|
+
}
|
|
72
|
+
active.throwIfAborted();
|
|
73
|
+
const value = await responseJson(response, selected.maximumResponseBytes, active);
|
|
74
|
+
if (!response.ok) {
|
|
75
|
+
const error = value && typeof value === 'object' && 'error' in value ? value.error : undefined;
|
|
76
|
+
const code = error && typeof error === 'object' && 'code' in error ? error.code : undefined;
|
|
77
|
+
throw publishingError(typeof code === 'string' && serviceErrors.has(code) ? code : 'SERVICE_REQUEST_FAILED');
|
|
78
|
+
}
|
|
79
|
+
return value;
|
|
80
|
+
};
|
|
81
|
+
const boundStatus = async (value, intent) => {
|
|
82
|
+
const status = parsePublishingStatus(value), identity = await calculateBytesIntegrity(publishingIntentBytes(intent));
|
|
83
|
+
if (intent.projectId !== config.projectId || intent.package.publisherId !== config.publisher.publisherId || status.projectId !== config.projectId || status.requestId !== intent.requestId || status.intentSha256 !== identity.sha256 || status.missingFiles.length > intent.package.fileCount || status.missingFiles.reduce((sum, file) => sum + file.byteLength, 0) > intent.package.totalBytes)
|
|
84
|
+
throw publishingError('STATUS_BINDING_INVALID');
|
|
85
|
+
if (status.activation !== undefined) {
|
|
86
|
+
if (typeof verifyActivation !== 'function')
|
|
87
|
+
throw publishingError('ACTIVATION_VERIFIER_REQUIRED');
|
|
88
|
+
await verifyActivation({ activation: status.activation, intent, configuration: structuredClone(config) });
|
|
89
|
+
}
|
|
90
|
+
return status;
|
|
91
|
+
};
|
|
92
|
+
const checkedIntent = (value) => { const intent = parsePublishingIntent(value); if (intent.projectId !== config.projectId || intent.package.publisherId !== config.publisher.publisherId)
|
|
93
|
+
throw publishingError('INTENT_BINDING_INVALID'); return intent; };
|
|
94
|
+
return Object.freeze({
|
|
95
|
+
async getProject({ signal } = {}) {
|
|
96
|
+
const project = parsePublishingProject(await send('GET', '/v1/project', undefined, signal), { allowLoopback });
|
|
97
|
+
if (JSON.stringify(project.configuration) !== JSON.stringify(config))
|
|
98
|
+
throw publishingError('PROJECT_BINDING_INVALID');
|
|
99
|
+
return project;
|
|
100
|
+
},
|
|
101
|
+
async getLatestRelease({ signal } = {}) {
|
|
102
|
+
const value = await send('GET', '/v1/project/release', undefined, signal);
|
|
103
|
+
if (!protocolRecord(value, ['schemaVersion', 'intent']) || value.schemaVersion !== 1)
|
|
104
|
+
throw publishingError('PROJECT_BINDING_INVALID');
|
|
105
|
+
if (value.intent === null)
|
|
106
|
+
return undefined;
|
|
107
|
+
const intent = checkedIntent(value.intent);
|
|
108
|
+
try {
|
|
109
|
+
return { intent, status: await boundStatus(await send('GET', '/v1/requests/' + intent.requestId, undefined, signal), intent) };
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
if (error && typeof error === 'object')
|
|
113
|
+
Object.assign(error, { requestId: intent.requestId });
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
async createRequest({ intent: input, manifestBytes, signal }) {
|
|
118
|
+
const intent = checkedIntent(input);
|
|
119
|
+
if (!(manifestBytes instanceof Uint8Array) || manifestBytes.byteLength > 1048576)
|
|
120
|
+
throw publishingError('MANIFEST_INVALID');
|
|
121
|
+
let prepared;
|
|
122
|
+
try {
|
|
123
|
+
prepared = await createArtifactContentManifest(JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(manifestBytes)));
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
throw publishingError('MANIFEST_INVALID');
|
|
127
|
+
}
|
|
128
|
+
if (prepared.content.manifestSha256 !== intent.package.content.manifestSha256 || prepared.bytes.byteLength !== manifestBytes.byteLength || prepared.bytes.some((byte, index) => byte !== manifestBytes[index]) || prepared.manifest.files.length !== intent.package.fileCount || prepared.manifest.files.reduce((sum, file) => sum + file.byteLength, 0) !== intent.package.totalBytes)
|
|
129
|
+
throw publishingError('MANIFEST_BINDING_INVALID');
|
|
130
|
+
return boundStatus(await send('POST', '/v1/requests', JSON.stringify({ intent, manifest: prepared.manifest }), signal), intent);
|
|
131
|
+
},
|
|
132
|
+
async getStatus({ intent: input, signal }) { const intent = checkedIntent(input); return boundStatus(await send('GET', '/v1/requests/' + intent.requestId, undefined, signal), intent); },
|
|
133
|
+
async resumeRequest({ intent: input, signal }) { const intent = checkedIntent(input); return boundStatus(await send('POST', '/v1/requests/' + intent.requestId + '/resume', JSON.stringify({ intent }), signal), intent); },
|
|
134
|
+
async recoverRequest({ intent: input, signal }) { const intent = checkedIntent(input); return boundStatus(await send('POST', '/v1/requests/' + intent.requestId + '/recover', JSON.stringify({ intent }), signal), intent); },
|
|
135
|
+
async queueRequest({ intent: input, signal }) { const intent = checkedIntent(input); return boundStatus(await send('POST', '/v1/requests/' + intent.requestId + '/commit', JSON.stringify({ intent }), signal), intent); },
|
|
136
|
+
async abandonRequest({ intent: input, signal }) { const intent = checkedIntent(input); return boundStatus(await send('POST', '/v1/requests/' + intent.requestId + '/abandon', '{}', signal), intent); },
|
|
137
|
+
async uploadChunk({ requestId, file, offset, bytes, signal }) {
|
|
138
|
+
if (!publishingRequestId(requestId) || !file || !publishingDigest(file.sha256) || !Number.isSafeInteger(file.byteLength) || file.byteLength < 0 || file.byteLength > 134217728 || !Number.isSafeInteger(offset) || offset < 0 || !(bytes instanceof Uint8Array) || bytes.byteLength < 1 || bytes.byteLength > selected.maximumChunkBytes || offset + bytes.byteLength > file.byteLength)
|
|
139
|
+
throw publishingError('CHUNK_INVALID');
|
|
140
|
+
const snapshot = new Uint8Array(bytes), value = await send('PUT', '/v1/requests/' + requestId + '/files/' + file.sha256 + '?offset=' + offset, snapshot, signal, 'application/octet-stream');
|
|
141
|
+
if (!protocolRecord(value, ['schemaVersion', 'sha256', 'receivedBytes']) || value.schemaVersion !== 1 || value.sha256 !== file.sha256 || value.receivedBytes !== offset + snapshot.byteLength)
|
|
142
|
+
throw publishingError('CHUNK_RESPONSE_INVALID');
|
|
143
|
+
return { schemaVersion: 1, sha256: file.sha256, receivedBytes: offset + snapshot.byteLength };
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { SolutionPackageDescriptor, SolutionPackageLimits } from './package.js';
|
|
2
|
+
export type { PublishingConfiguration, PublishingProject, PublishingIntent, PublishingStatus, PublishingMetadataTransport } from './protocol.js';
|
|
3
|
+
export type { PublishingClient, PublishingClientLimits, PublishingClientOptions } from './client.js';
|
|
4
|
+
export { parseSolutionPackageDescriptor, parseSolutionPackageLimits } from './package.js';
|
|
5
|
+
export { parsePublishingConfiguration, parsePublishingProject, parsePublishingIntent, parsePublishingStatus, publishingIntentBytes } from './protocol.js';
|
|
6
|
+
export { createPublishingClient } from './client.js';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { parseSolutionPackageDescriptor, parseSolutionPackageLimits } from './package.js';
|
|
2
|
+
export { parsePublishingConfiguration, parsePublishingProject, parsePublishingIntent, parsePublishingStatus, publishingIntentBytes } from './protocol.js';
|
|
3
|
+
export { createPublishingClient } from './client.js';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { KeyObject } from 'node:crypto';
|
|
2
|
+
import type { PublishingIntent } from '../protocol.js';
|
|
3
|
+
export { maximumAcceptanceArchiveBytes, readDeliveryBody, verifyAcceptanceDelivery } from '../acceptance-delivery-binding.js';
|
|
4
|
+
import type { AcceptanceArchiveIdentity, AcceptanceDeliveryBinding } from '../acceptance-delivery-binding.js';
|
|
5
|
+
export type { AcceptanceArchiveIdentity, AcceptanceDeliveryBinding } from '../acceptance-delivery-binding.js';
|
|
6
|
+
export interface AcceptanceDeliveryCredential {
|
|
7
|
+
origin: string;
|
|
8
|
+
keyId: string;
|
|
9
|
+
privateKey: string;
|
|
10
|
+
}
|
|
11
|
+
export interface AcceptanceArchive {
|
|
12
|
+
bytes: Uint8Array;
|
|
13
|
+
artifactSha256: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function parseAcceptanceDeliveryCredential(value: unknown): AcceptanceDeliveryCredential;
|
|
16
|
+
export declare function acceptanceDeliveryTarget(credential: unknown): {
|
|
17
|
+
origin: string;
|
|
18
|
+
keyId: string;
|
|
19
|
+
publicKeySha256: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function signAcceptanceDelivery(value: AcceptanceDeliveryBinding, privateKey: string | KeyObject): string;
|
|
22
|
+
/** Only the dedicated owner's HTTPS origin receives this archive. A read after
|
|
23
|
+
* the immutable PUT also reconciles a lost response without repeating a release. */
|
|
24
|
+
interface DeliveryInput {
|
|
25
|
+
intent: PublishingIntent;
|
|
26
|
+
archive: AcceptanceArchiveIdentity;
|
|
27
|
+
credential: AcceptanceDeliveryCredential;
|
|
28
|
+
request?: typeof fetch;
|
|
29
|
+
signal?: AbortSignal;
|
|
30
|
+
}
|
|
31
|
+
export declare function observeAcceptanceDelivery(input: DeliveryInput): Promise<boolean>;
|
|
32
|
+
export declare function deliverAcceptanceArchive(input: DeliveryInput & {
|
|
33
|
+
bytes: Uint8Array;
|
|
34
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { createHash, createPrivateKey, createPublicKey, sign } from 'node:crypto';
|
|
2
|
+
import { protocolRecord, publishingError, publishingIdentifier } from '../protocol.js';
|
|
3
|
+
import { deliveryBindingBytes, deliveryBindingFields, readDeliveryBody, validateDeliveryOrigin } from '../acceptance-delivery-binding.js';
|
|
4
|
+
export { maximumAcceptanceArchiveBytes, readDeliveryBody, verifyAcceptanceDelivery } from '../acceptance-delivery-binding.js';
|
|
5
|
+
const fail = (code) => publishingError('ACCEPTANCE_' + code);
|
|
6
|
+
const hash = (bytes) => createHash('sha256').update(bytes).digest('hex');
|
|
7
|
+
export function parseAcceptanceDeliveryCredential(value) {
|
|
8
|
+
if (!protocolRecord(value, ['origin', 'keyId', 'privateKey']) || !publishingIdentifier(value.keyId) ||
|
|
9
|
+
typeof value.privateKey !== 'string' || value.privateKey.length > 4096)
|
|
10
|
+
throw fail('CREDENTIAL_INVALID');
|
|
11
|
+
const origin = validateDeliveryOrigin(value.origin);
|
|
12
|
+
const key = createPrivateKey(value.privateKey);
|
|
13
|
+
if (key.asymmetricKeyType !== 'ed25519')
|
|
14
|
+
throw fail('CREDENTIAL_INVALID');
|
|
15
|
+
return { origin, keyId: value.keyId, privateKey: key.export({ type: 'pkcs8', format: 'pem' }).toString() };
|
|
16
|
+
}
|
|
17
|
+
export function acceptanceDeliveryTarget(credential) {
|
|
18
|
+
const { origin, keyId, privateKey } = parseAcceptanceDeliveryCredential(credential);
|
|
19
|
+
return { origin, keyId, publicKeySha256: hash(createPublicKey(privateKey).export({ type: 'spki', format: 'der' })) };
|
|
20
|
+
}
|
|
21
|
+
export function signAcceptanceDelivery(value, privateKey) {
|
|
22
|
+
return sign(null, deliveryBindingBytes(value), privateKey).toString('base64url');
|
|
23
|
+
}
|
|
24
|
+
function deliveryTarget({ intent, archive, credential, request = fetch, signal }) {
|
|
25
|
+
if (!credential)
|
|
26
|
+
throw fail('CREDENTIAL_REQUIRED');
|
|
27
|
+
const { origin, keyId, privateKey } = parseAcceptanceDeliveryCredential(credential);
|
|
28
|
+
const expected = { projectId: intent.projectId, solutionId: intent.package.solutionId, version: intent.package.version,
|
|
29
|
+
origin, keyId, manifestSha256: intent.package.content.manifestSha256, ...archive };
|
|
30
|
+
const url = new URL('/v1/acceptance/installations/' + expected.version, origin);
|
|
31
|
+
const timeout = AbortSignal.timeout(30000);
|
|
32
|
+
const options = { redirect: 'error', signal: signal ? AbortSignal.any([signal, timeout]) : timeout };
|
|
33
|
+
async function observed() {
|
|
34
|
+
const response = await request(url, { ...options, method: 'GET', headers: { accept: 'application/json' } });
|
|
35
|
+
if (response.status === 404) {
|
|
36
|
+
await response.body?.cancel();
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
if (response.status !== 200) {
|
|
40
|
+
await response.body?.cancel();
|
|
41
|
+
throw fail('DELIVERY_UNKNOWN');
|
|
42
|
+
}
|
|
43
|
+
const receipt = await readDeliveryBody(response, 8192);
|
|
44
|
+
let value;
|
|
45
|
+
try {
|
|
46
|
+
value = JSON.parse(receipt.toString('utf8'));
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
throw fail('DELIVERY_UNKNOWN');
|
|
50
|
+
}
|
|
51
|
+
if (!protocolRecord(value, deliveryBindingFields))
|
|
52
|
+
throw fail('DELIVERY_UNKNOWN');
|
|
53
|
+
if (!deliveryBindingBytes(value).equals(deliveryBindingBytes(expected)))
|
|
54
|
+
throw fail('VERSION_CONFLICT');
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
return { observed, expected, privateKey, options, url, request };
|
|
58
|
+
}
|
|
59
|
+
export async function observeAcceptanceDelivery(input) {
|
|
60
|
+
return deliveryTarget(input).observed();
|
|
61
|
+
}
|
|
62
|
+
export async function deliverAcceptanceArchive(input) {
|
|
63
|
+
const { bytes, archive } = input;
|
|
64
|
+
if (!(bytes instanceof Uint8Array) || bytes.byteLength !== archive.byteLength || hash(bytes) !== archive.archiveSha256)
|
|
65
|
+
throw fail('ARCHIVE_CHANGED');
|
|
66
|
+
const { observed, expected, privateKey, options, url, request } = deliveryTarget(input);
|
|
67
|
+
if (await observed())
|
|
68
|
+
return;
|
|
69
|
+
const signature = signAcceptanceDelivery(expected, privateKey);
|
|
70
|
+
let rejection;
|
|
71
|
+
try {
|
|
72
|
+
const response = await request(url, { ...options, method: 'PUT', headers: { 'content-type': 'application/octet-stream',
|
|
73
|
+
'x-link-light-binding': Buffer.from(JSON.stringify(expected)).toString('base64url'), 'x-link-light-signature': signature }, body: new Uint8Array(bytes) });
|
|
74
|
+
await response.body?.cancel();
|
|
75
|
+
if (response.status === 403)
|
|
76
|
+
rejection = 'SIGNATURE_INVALID';
|
|
77
|
+
if (response.status === 409)
|
|
78
|
+
rejection = 'VERSION_CONFLICT';
|
|
79
|
+
if ([400, 413, 415, 422].includes(response.status))
|
|
80
|
+
rejection = 'DELIVERY_REJECTED';
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
if (error && typeof error === 'object' && 'code' in error && typeof error.code === 'string' && error.code.startsWith('PUBLISHING_ACCEPTANCE_'))
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
if (!await observed())
|
|
87
|
+
throw fail(rejection ?? 'DELIVERY_UNKNOWN');
|
|
88
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { PublishingActivation } from '../shared/activation-types.js';
|
|
2
|
+
export declare const createPublishingActivation: (input: import("../shared/activation-types.js").CreateActivationInput) => Promise<import("../shared/activation-types.js").PublishingActivation>, verifyPublishingActivation: (input: import("../shared/activation-types.js").VerifyActivationInput) => Promise<{
|
|
3
|
+
manifest: Readonly<import("@xlinklight/contracts").SolutionReleaseManifest>;
|
|
4
|
+
acceptanceReceiptSha256: string;
|
|
5
|
+
}>;
|