@xlinklight/publishing 3.2.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 -0
- 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.mjs +0 -66
- package/src/client.mjs +0 -74
- package/src/index.mjs +0 -3
- package/src/node/acceptance-delivery.mjs +0 -109
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {PublishingConfiguration} from '../protocol.
|
|
2
|
-
import type {PublishingClientLimits} from '../client.
|
|
3
|
-
import type {PublishingJournal} from './journal.
|
|
4
|
-
export interface PublishingAuthorization {configuration:PublishingConfiguration;credential:string;acceptanceDelivery?:import('./acceptance-delivery.
|
|
1
|
+
import type {PublishingConfiguration} from '../protocol.js';
|
|
2
|
+
import type {PublishingClientLimits} from '../client.js';
|
|
3
|
+
import type {PublishingJournal} from './journal.js';
|
|
4
|
+
export interface PublishingAuthorization {configuration:PublishingConfiguration;credential:string;acceptanceDelivery?:import('./acceptance-delivery.js').AcceptanceDeliveryCredential}
|
|
5
5
|
export function loadPublishingAuthorization(input:{journal:Pick<PublishingJournal,'load'|'compareAndSet'>;allowLoopback?:boolean;signal?:AbortSignal}):Promise<PublishingAuthorization|undefined>;
|
|
6
6
|
export function installPublishingAuthorization(input:PublishingAuthorization&{
|
|
7
7
|
journal:Pick<PublishingJournal,'load'|'compareAndSet'>;replaceCredential?:boolean;allowLoopback?:boolean;request?:typeof fetch;clientLimits?:PublishingClientLimits;signal?:AbortSignal;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type {SolutionPackageLimits,SolutionPackageFilePlan,PreparedSolutionPackage} from './solution-package.js';
|
|
2
|
+
export type {PublishingMetadataTransport} from '../protocol.js';
|
|
3
|
+
export {prepareSolutionPackage,prepareSolutionPackageBytes,verifySolutionPackage,verifySolutionPackageBytes} from './solution-package.js';
|
|
4
|
+
export type {PublishingJournal,PublishingJournalRecord,PublishingJournalLimits} from './journal.js';
|
|
5
|
+
export {openPublishingJournal} from './journal.js';
|
|
6
|
+
export type {PublishingSession,PublishingSessionResult} from './session.js';
|
|
7
|
+
export {createPublishingSession} from './session.js';
|
|
8
|
+
export type {PublishingAuthorization} from './authorization.js';
|
|
9
|
+
export {installPublishingAuthorization,loadPublishingAuthorization} from './authorization.js';
|
|
10
|
+
export type {PublishingActivation} from './activation.js';
|
|
11
|
+
export {createPublishingActivation,verifyPublishingActivation} from './activation.js';
|
|
12
|
+
export {PublishingSourceError} from './source-error.js';
|
|
13
|
+
export type {PublishingSourceProducer,PublishingWorkflowOptions,PublishingSourceOptions,PublishingPublishOptions,PublishingWorkflowResult,PublishingWorkflow} from './workflow.js';
|
|
14
|
+
export {createPublishingWorkflow} from './workflow.js';
|
|
15
|
+
export type {PublishingCommandOptions,PublishingCommandResult} from './publishing-command.js';
|
|
16
|
+
export {runPublishingCommand} from './publishing-command.js';
|
|
17
|
+
export * from './acceptance-delivery.js';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type {Readable} from 'node:stream';
|
|
2
2
|
import type {DurableArtifactFilesystem} from '@openge/forge-generated-artifacts/node';
|
|
3
|
-
import type {PublishingMetadataTransport as ReleaseMetadataTransport} from '../protocol.
|
|
4
|
-
import type {PublishingJournalLimits} from './journal.
|
|
5
|
-
import type {PublishingClientLimits} from '../client.
|
|
6
|
-
import type {PublishingWorkflowResult} from './workflow.
|
|
3
|
+
import type {PublishingMetadataTransport as ReleaseMetadataTransport} from '../protocol.js';
|
|
4
|
+
import type {PublishingJournalLimits} from './journal.js';
|
|
5
|
+
import type {PublishingClientLimits} from '../client.js';
|
|
6
|
+
import type {PublishingWorkflowResult} from './workflow.js';
|
|
7
7
|
export interface PublishingCommandOptions {
|
|
8
8
|
cwd?:string;stdin?:Readable&{isTTY?:boolean};signal?:AbortSignal;
|
|
9
9
|
filesystem?:DurableArtifactFilesystem;journalLimits?:PublishingJournalLimits;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type {ArtifactOperationOptions,ArtifactOperationReceipt} from '@openge/forge-artifact-publish';
|
|
2
|
-
import type {PublishingConfiguration,PublishingIntent,PublishingStatus} from '../protocol.
|
|
3
|
-
import type {PublishingClientOptions} from '../client.
|
|
4
|
-
import type {PublishingJournal} from './journal.
|
|
5
|
-
import type {PreparedSolutionPackage,SolutionPackageLimits} from './solution-package.
|
|
2
|
+
import type {PublishingConfiguration,PublishingIntent,PublishingStatus} from '../protocol.js';
|
|
3
|
+
import type {PublishingClientOptions} from '../client.js';
|
|
4
|
+
import type {PublishingJournal} from './journal.js';
|
|
5
|
+
import type {PreparedSolutionPackage,SolutionPackageLimits} from './solution-package.js';
|
|
6
6
|
export interface PublishingSessionResult {receipt:ArtifactOperationReceipt;status?:PublishingStatus}
|
|
7
7
|
export interface PublishingSession {
|
|
8
|
-
freeze(input:{intent:PublishingIntent;prepared:Pick<PreparedSolutionPackage,'files'|'manifestBytes'>;acceptanceArchive?:import('./acceptance-delivery.
|
|
9
|
-
readAcceptanceArchive(input:{requestId:string;signal?:AbortSignal}):Promise<{intent:PublishingIntent;archive:import('./acceptance-delivery.
|
|
10
|
-
acceptanceMetadata(input:{requestId:string;signal?:AbortSignal}):Promise<{intent:PublishingIntent;archive:import('./acceptance-delivery.
|
|
8
|
+
freeze(input:{intent:PublishingIntent;prepared:Pick<PreparedSolutionPackage,'files'|'manifestBytes'>;acceptanceArchive?:import('./acceptance-delivery.js').AcceptanceArchive;acceptanceTarget?:{origin:string;keyId:string;publicKeySha256:string};signal?:AbortSignal}):Promise<{requestId:string;content:{manifestSha256:string}}>;
|
|
9
|
+
readAcceptanceArchive(input:{requestId:string;signal?:AbortSignal}):Promise<{intent:PublishingIntent;archive:import('./acceptance-delivery.js').AcceptanceArchiveIdentity;bytes:Uint8Array}|undefined>;
|
|
10
|
+
acceptanceMetadata(input:{requestId:string;signal?:AbortSignal}):Promise<{intent:PublishingIntent;archive:import('./acceptance-delivery.js').AcceptanceArchiveIdentity}|undefined>;
|
|
11
11
|
read(input:{requestId:string;signal?:AbortSignal}):Promise<{intent:PublishingIntent;prepared:PreparedSolutionPackage}>;
|
|
12
12
|
create(input:{requestId:string;attempt?:number;signal?:AbortSignal}):Promise<PublishingSessionResult>;
|
|
13
13
|
observe(input:{requestId:string;stage?:'create'|'commit';attempt?:number;signal?:AbortSignal}):Promise<PublishingSessionResult>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {ArtifactContentIdentity,ArtifactContentManifest,ArtifactContentManifestFile} from '@openge/forge-artifact-publish';
|
|
2
|
-
import type {SolutionPackageDescriptor,SolutionPackageLimits} from '../package.
|
|
3
|
-
export type {SolutionPackageLimits} from '../package.
|
|
2
|
+
import type {SolutionPackageDescriptor,SolutionPackageLimits} from '../package.js';
|
|
3
|
+
export type {SolutionPackageLimits} from '../package.js';
|
|
4
4
|
export type SolutionPackageFilePlan=Omit<Extract<ArtifactContentManifestFile,{role:'asset'}>,'byteLength'|'sha256'>|Omit<Extract<ArtifactContentManifestFile,{role:'control'}>,'byteLength'|'sha256'>;
|
|
5
5
|
export interface PreparedSolutionPackage {
|
|
6
6
|
descriptor:SolutionPackageDescriptor;content:ArtifactContentIdentity;manifest:ArtifactContentManifest;manifestBytes:Uint8Array;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type {PublishingConfiguration,PublishingProject} from '../protocol.
|
|
2
|
-
import type {PublishingClientLimits} from '../client.
|
|
3
|
-
import type {PublishingJournal} from './journal.
|
|
4
|
-
import type {PreparedSolutionPackage} from './solution-package.
|
|
5
|
-
import type {PublishingMetadataTransport as ReleaseMetadataTransport} from '../protocol.
|
|
1
|
+
import type {PublishingConfiguration,PublishingProject} from '../protocol.js';
|
|
2
|
+
import type {PublishingClientLimits} from '../client.js';
|
|
3
|
+
import type {PublishingJournal} from './journal.js';
|
|
4
|
+
import type {PreparedSolutionPackage} from './solution-package.js';
|
|
5
|
+
import type {PublishingMetadataTransport as ReleaseMetadataTransport} from '../protocol.js';
|
|
6
6
|
export interface PublishingSourceProducer {
|
|
7
|
-
prepare(input:{root:string;project:PublishingProject;signal?:AbortSignal;requestId:string;includeAcceptanceArchive?:boolean}):Promise<{prepared:PreparedSolutionPackage;acceptanceArchive?:import('./acceptance-delivery.
|
|
7
|
+
prepare(input:{root:string;project:PublishingProject;signal?:AbortSignal;requestId:string;includeAcceptanceArchive?:boolean}):Promise<{prepared:PreparedSolutionPackage;acceptanceArchive?:import('./acceptance-delivery.js').AcceptanceArchive;processesClosed:true}>;
|
|
8
8
|
}
|
|
9
9
|
export interface PublishingWorkflowOptions {
|
|
10
10
|
root:string;journal:PublishingJournal;configuration:PublishingConfiguration;credential:string;
|
|
11
|
-
acceptanceDelivery?:import('./acceptance-delivery.
|
|
11
|
+
acceptanceDelivery?:import('./acceptance-delivery.js').AcceptanceDeliveryCredential;
|
|
12
12
|
allowLoopback?:boolean;request?:typeof fetch;clientLimits?:PublishingClientLimits;
|
|
13
13
|
pathCaseSensitivity?:'case-sensitive'|'case-insensitive';metadataTransport?:ReleaseMetadataTransport;
|
|
14
14
|
operationLimits?:{timeoutMilliseconds:number;closeTimeoutMilliseconds:number};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {JsonValue} from '@xlinklight/contracts';
|
|
2
|
-
import type {SolutionPackageLimits} from './package.
|
|
2
|
+
import type {SolutionPackageLimits} from './package.js';
|
|
3
3
|
/** Consumer-owned read-only public metadata port. It carries no credentials or
|
|
4
4
|
* command body and does not require the optional platform implementation. */
|
|
5
5
|
export type PublishingMetadataTransport=(address:string,options:{timeoutMs?:number;signal?:AbortSignal})=>Promise<JsonValue>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {SolutionReleaseManifest} from '@xlinklight/contracts';
|
|
2
|
-
import type {PublishingMetadataTransport,PublishingConfiguration,PublishingIntent} from '../protocol.
|
|
3
|
-
import type {PublishingActivation} from '../shared/activation.
|
|
4
|
-
export type {PublishingActivation} from '../shared/activation.
|
|
2
|
+
import type {PublishingMetadataTransport,PublishingConfiguration,PublishingIntent} from '../protocol.js';
|
|
3
|
+
import type {PublishingActivation} from '../shared/activation.js';
|
|
4
|
+
export type {PublishingActivation} from '../shared/activation.js';
|
|
5
5
|
interface ActivationContext {configuration:PublishingConfiguration;intent:PublishingIntent;allowLoopback?:boolean;metadataTransport:PublishingMetadataTransport;signal?:AbortSignal}
|
|
6
6
|
export function createPublishingActivation(input:ActivationContext&{manifest:SolutionReleaseManifest;acceptanceReceiptSha256:string;keyId:string;privateKey:string}):Promise<PublishingActivation>;
|
|
7
7
|
export function verifyPublishingActivation(input:ActivationContext&{activation:unknown}):Promise<{manifest:Readonly<SolutionReleaseManifest>;acceptanceReceiptSha256:string}>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {ArtifactContentIdentity,ArtifactContentManifest,ArtifactContentManifestFile} from '@openge/forge-artifact-publish';
|
|
2
|
-
import type {SolutionPackageDescriptor,SolutionPackageLimits} from '../package.
|
|
3
|
-
import type {PublishingIntent} from '../protocol.
|
|
2
|
+
import type {SolutionPackageDescriptor,SolutionPackageLimits} from '../package.js';
|
|
3
|
+
import type {PublishingIntent} from '../protocol.js';
|
|
4
4
|
export interface PublishingContentReader {
|
|
5
5
|
readFile(path:string,input:{maximumBytes:number;signal?:AbortSignal}):Promise<Uint8Array>;
|
|
6
6
|
streamFile(path:string,input?:{signal?:AbortSignal}):AsyncIterable<Uint8Array>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {SolutionReleasePayload,TrustedPublisher,Digest} from '@xlinklight/contracts';
|
|
2
|
-
import type {PublishingConfiguration} from '../protocol.
|
|
3
|
-
import type {SolutionPackageLimits} from '../package.
|
|
4
|
-
import type {PreparedPublishingPackage} from './package.
|
|
2
|
+
import type {PublishingConfiguration} from '../protocol.js';
|
|
3
|
+
import type {SolutionPackageLimits} from '../package.js';
|
|
4
|
+
import type {PreparedPublishingPackage} from './package.js';
|
|
5
5
|
/** Exact immutable provider URLs, canonical HTTPS without credentials, query
|
|
6
6
|
* or fragment. Routes are preserved; publisher admission uses their origins. */
|
|
7
7
|
export function preparePublishingRelease(input:{prepared:Pick<PreparedPublishingPackage,'descriptor'|'content'|'manifest'|'manifestBytes'|'payloadBytes'|'readFile'|'streamFile'>;configuration:PublishingConfiguration;serverUrl:string;uiUrl:string;serverReceiptPath:string;uiReceiptPath:string;limits:SolutionPackageLimits;signal?:AbortSignal}):Promise<{payload:Readonly<SolutionReleasePayload>;releaseDigest:Digest;publisher:TrustedPublisher}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {PublishingDurableJournal,PublishingDurableStorage} from './journal.
|
|
2
|
-
import type {PublishingService,PublishingWorkerResult} from './service.
|
|
1
|
+
import type {PublishingDurableJournal,PublishingDurableStorage} from './journal.js';
|
|
2
|
+
import type {PublishingService,PublishingWorkerResult} from './service.js';
|
|
3
3
|
export interface PublishingDurableContext {storage:PublishingDurableStorage&{getAlarm():Promise<number|null>;setAlarm(time:number):Promise<void>;deleteAlarm():Promise<void>};abort(message:string):void}
|
|
4
4
|
export function createPublishingDurableRuntime(input:{ctx:PublishingDurableContext;journal:PublishingDurableJournal;service:PublishingService;worker:{run(input:{projectId:string;requestId:string;mode:'perform'|'observe';signal:AbortSignal}):Promise<PublishingWorkerResult>};now?:()=>number;limits?:{pollMs:number;jobMs:number;maximumPolls?:number}}):{schedule():Promise<void>;run():Promise<PublishingWorkerResult|{state:'idle'|'busy'}>;alarm():Promise<PublishingWorkerResult|{state:'idle'|'busy'}>;fetch(request:Request):Promise<Response>;status():{running:boolean;blocked:boolean;nextWake:number|null}};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {PublishingConfiguration} from '../protocol.
|
|
2
|
-
import type {PublishingIntent} from '../protocol.
|
|
1
|
+
import type {PublishingConfiguration} from '../protocol.js';
|
|
2
|
+
import type {PublishingIntent} from '../protocol.js';
|
|
3
3
|
import type {ArtifactOperationTransport,ArtifactOperationRecord,ArtifactOperationReceipt,ArtifactOperationCapability} from '@openge/forge-artifact-publish';
|
|
4
|
-
import type {PublishingMetadataTransport as ReleaseMetadataTransport} from '../protocol.
|
|
5
|
-
import type {SolutionPackageLimits} from '../package.
|
|
6
|
-
import type {PublishingDurableJournal as PublishingJournal,PublishingDispatch} from './journal.
|
|
7
|
-
import type {PreparedPublishingPackage as PreparedSolutionPackage} from './package.
|
|
4
|
+
import type {PublishingMetadataTransport as ReleaseMetadataTransport} from '../protocol.js';
|
|
5
|
+
import type {SolutionPackageLimits} from '../package.js';
|
|
6
|
+
import type {PublishingDurableJournal as PublishingJournal,PublishingDispatch} from './journal.js';
|
|
7
|
+
import type {PreparedPublishingPackage as PreparedSolutionPackage} from './package.js';
|
|
8
8
|
export interface PublishingProjectPolicy {
|
|
9
9
|
schemaVersion:1;configuration:PublishingConfiguration;policyRevision:number;disabled:boolean;
|
|
10
10
|
solutionId:string;packageName:string;limits:SolutionPackageLimits;maximumRequests:number;
|
|
@@ -34,7 +34,7 @@ export interface PublishingWorkerOptions {
|
|
|
34
34
|
withProjectLock<T>(input:{projectId:string;requestId:string;mode:'perform'|'observe';signal?:AbortSignal},work:(lease:PublishingProjectLease)=>Promise<T>):Promise<T>;
|
|
35
35
|
stages:readonly PublishingDeploymentStage[];allowLoopback?:boolean;
|
|
36
36
|
metadataTransport?:ReleaseMetadataTransport;
|
|
37
|
-
verifyActivation?:typeof import('./activation.
|
|
37
|
+
verifyActivation?:typeof import('./activation.js').verifyPublishingActivation;
|
|
38
38
|
operationLimits?:{timeoutMilliseconds:number;closeTimeoutMilliseconds:number};
|
|
39
39
|
}
|
|
40
40
|
export interface PublishingWorkerResult {requestId:string;state:string;sideEffects:string;receipt?:ArtifactOperationReceipt;next?:'perform'|'verify'}
|
package/src/acceptance.mjs
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
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.mjs';
|
|
4
|
-
|
|
5
|
-
const positive=value=>Number.isSafeInteger(value)&&value>0;
|
|
6
|
-
const identityKeys=['projectId','requestId','intentSha256','policyRevision','releaseDigest','acceptanceArtifactSha256','generation'];
|
|
7
|
-
const bindingKeys=['schemaVersion','jobId',...identityKeys];
|
|
8
|
-
const invalid=part=>publishingError('ACCEPTANCE_'+part+'_INVALID');
|
|
9
|
-
|
|
10
|
-
export function acceptanceJobId(identity){
|
|
11
|
-
if(!identity||!publishingIdentifier(identity.projectId)||!publishingRequestId(identity.requestId)
|
|
12
|
-
||!publishingDigest(identity.intentSha256)||!positive(identity.policyRevision)
|
|
13
|
-
||!/^sha256:[a-f0-9]{64}$/.test(identity.releaseDigest??'')||!publishingDigest(identity.acceptanceArtifactSha256)
|
|
14
|
-
||!positive(identity.generation))throw invalid('JOB');
|
|
15
|
-
const binding=Object.fromEntries(identityKeys.map(key=>[key,identity[key]]));
|
|
16
|
-
return createHash('sha256').update('link-light/acceptance-job-id/v1\n').update(canonicalMetadata(binding)).digest('hex');
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function checkBinding(payload,kind){
|
|
20
|
-
try{return payload.schemaVersion===1&&payload.jobId===acceptanceJobId(payload);}
|
|
21
|
-
catch{throw invalid(kind);}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function jobPayload(payload){
|
|
25
|
-
if(!protocolRecord(payload,[...bindingKeys,'manifest'])||!checkBinding(payload,'JOB')
|
|
26
|
-
||payload.manifest?.releaseDigest!==payload.releaseDigest||!publishingIdentifier(payload.manifest.solutionId)
|
|
27
|
-
||!/^\d{1,8}\.\d{1,8}\.\d{1,8}$/.test(payload.manifest.version??''))throw invalid('JOB');
|
|
28
|
-
return payload;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function receiptPayload(payload){
|
|
32
|
-
if(!protocolRecord(payload,[...bindingKeys,'status','proof'])||!checkBinding(payload,'RECEIPT')||payload.status!=='PASS'
|
|
33
|
-
||!protocolRecord(payload.proof,['syntheticInstancesCreated','syntheticInstancesDisabled','closure']))throw invalid('RECEIPT');
|
|
34
|
-
const {syntheticInstancesCreated,syntheticInstancesDisabled,closure}=payload.proof;
|
|
35
|
-
if(!positive(syntheticInstancesCreated)||syntheticInstancesCreated<2||syntheticInstancesCreated>1024
|
|
36
|
-
||syntheticInstancesCreated!==syntheticInstancesDisabled||!protocolRecord(closure,['status','activeRequests'])
|
|
37
|
-
||closure.status!=='closed'||closure.activeRequests!==0)throw invalid('RECEIPT');
|
|
38
|
-
return payload;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function message(kind,payload){
|
|
42
|
-
const canonical=canonicalMetadata(payload);
|
|
43
|
-
if(Buffer.byteLength(canonical)>65536)throw invalid(kind);
|
|
44
|
-
return Buffer.from('link-light/acceptance-'+kind.toLowerCase()+'/v1\n'+canonical);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function signEnvelope(payload,kind,{keyId,privateKey}){
|
|
48
|
-
const key=typeof privateKey==='string'?createPrivateKey(privateKey):privateKey;
|
|
49
|
-
if(!publishingIdentifier(keyId)||key?.type!=='private'||key.asymmetricKeyType!=='ed25519')throw invalid('SIGNATURE');
|
|
50
|
-
return {payload:structuredClone(payload),keyId,signature:sign(null,message(kind,payload),key).toString('base64url')};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function verifyEnvelope(envelope,kind,parse,{keyId,publicKey}){
|
|
54
|
-
if(!protocolRecord(envelope,['payload','keyId','signature'])||!publishingIdentifier(keyId)||envelope.keyId!==keyId
|
|
55
|
-
||typeof envelope.signature!=='string'||!/^[A-Za-z0-9_-]{86}$/.test(envelope.signature))throw invalid('SIGNATURE');
|
|
56
|
-
const payload=parse(envelope.payload),bytes=Buffer.from(envelope.signature,'base64url');
|
|
57
|
-
const key=typeof publicKey==='string'?createPublicKey(publicKey):publicKey;
|
|
58
|
-
if(key?.type!=='public'||key.asymmetricKeyType!=='ed25519'||bytes.toString('base64url')!==envelope.signature
|
|
59
|
-
||!verify(null,message(kind,payload),key,bytes))throw invalid('SIGNATURE');
|
|
60
|
-
return structuredClone(payload);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export const signAcceptanceJob=(job,options)=>signEnvelope(jobPayload(job),'JOB',options);
|
|
64
|
-
export const verifyAcceptanceJob=(envelope,options)=>verifyEnvelope(envelope,'JOB',jobPayload,options);
|
|
65
|
-
export const signAcceptanceReceipt=(receipt,options)=>signEnvelope(receiptPayload(receipt),'RECEIPT',options);
|
|
66
|
-
export const verifyAcceptanceReceipt=(envelope,options)=>verifyEnvelope(envelope,'RECEIPT',receiptPayload,options);
|
package/src/client.mjs
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
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.mjs';
|
|
4
|
-
|
|
5
|
-
const defaults=Object.freeze({requestMs:30000,maximumResponseBytes:1048576,maximumChunkBytes:262144});
|
|
6
|
-
const serviceErrors=new Set(['NOT_AUTHORIZED','PROJECT_DISABLED','POLICY_CHANGED','CONFLICT','REQUEST_NOT_FOUND','QUOTA_PAUSED','INVALID_INPUT','UNKNOWN_EFFECTS','BUSY','NOT_READY']);
|
|
7
|
-
function boundedLimits(value){
|
|
8
|
-
if(!protocolRecord(value,['requestMs','maximumResponseBytes','maximumChunkBytes'])||Object.values(value).some(item=>!Number.isSafeInteger(item)||item<1)||value.requestMs>300000||value.maximumResponseBytes>2097152||value.maximumChunkBytes>1048576)throw publishingError('CLIENT_LIMIT_INVALID');return {...value};
|
|
9
|
-
}
|
|
10
|
-
async function responseJson(response,maximum,signal){
|
|
11
|
-
const declared=response.headers.get('content-length');if(declared!==null&&(!/^\d+$/.test(declared)||Number(declared)>maximum)){await response.body?.cancel();throw publishingError('RESPONSE_BYTE_LIMIT');}
|
|
12
|
-
if(!response.body)throw publishingError('RESPONSE_INVALID');
|
|
13
|
-
const reader=response.body.getReader(),chunks=[];let total=0;
|
|
14
|
-
try{
|
|
15
|
-
for(;;){signal.throwIfAborted();const {done,value}=await reader.read();if(done)break;total+=value.byteLength;if(total>maximum)throw publishingError('RESPONSE_BYTE_LIMIT');chunks.push(value);}
|
|
16
|
-
}catch(error){try{await reader.cancel();}catch{}throw error;}
|
|
17
|
-
finally{reader.releaseLock();}
|
|
18
|
-
const bytes=new Uint8Array(total);let offset=0;for(const chunk of chunks){bytes.set(chunk,offset);offset+=chunk.byteLength;}
|
|
19
|
-
try{return JSON.parse(new TextDecoder('utf-8',{fatal:true}).decode(bytes));}catch{throw publishingError('RESPONSE_INVALID');}
|
|
20
|
-
}
|
|
21
|
-
/** All writes are explicit. Recovery reads the original request; there is no retry loop. */
|
|
22
|
-
export function createPublishingClient({configuration,credential,allowLoopback=false,request=fetch,limits=defaults,verifyActivation}){
|
|
23
|
-
const config=parsePublishingConfiguration(configuration,{allowLoopback}),selected=boundedLimits(limits);
|
|
24
|
-
if(typeof credential!=='string'||!/^[A-Za-z0-9_-]{32,4096}$/.test(credential)||typeof request!=='function'||verifyActivation!==undefined&&typeof verifyActivation!=='function')throw publishingError('CREDENTIAL_INVALID');
|
|
25
|
-
const send=async(method,relative,body,signal,contentType='application/json')=>{
|
|
26
|
-
signal?.throwIfAborted();const timeout=AbortSignal.timeout(selected.requestMs),active=signal?AbortSignal.any([signal,timeout]):timeout;
|
|
27
|
-
let response;
|
|
28
|
-
try{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});}
|
|
29
|
-
catch{active.throwIfAborted();throw publishingError('SERVICE_UNREACHABLE');}
|
|
30
|
-
active.throwIfAborted();const value=await responseJson(response,selected.maximumResponseBytes,active);
|
|
31
|
-
if(!response.ok)throw publishingError(serviceErrors.has(value?.error?.code)?value.error.code:'SERVICE_REQUEST_FAILED');return value;
|
|
32
|
-
};
|
|
33
|
-
const boundStatus=async(value,intent)=>{
|
|
34
|
-
const status=parsePublishingStatus(value),identity=await calculateBytesIntegrity(publishingIntentBytes(intent));
|
|
35
|
-
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)throw publishingError('STATUS_BINDING_INVALID');
|
|
36
|
-
if(status.activation!==undefined){
|
|
37
|
-
if(typeof verifyActivation!=='function')throw publishingError('ACTIVATION_VERIFIER_REQUIRED');
|
|
38
|
-
await verifyActivation({activation:status.activation,intent,configuration:structuredClone(config)});
|
|
39
|
-
}
|
|
40
|
-
return status;
|
|
41
|
-
};
|
|
42
|
-
const checkedIntent=value=>{const intent=parsePublishingIntent(value);if(intent.projectId!==config.projectId||intent.package.publisherId!==config.publisher.publisherId)throw publishingError('INTENT_BINDING_INVALID');return intent;};
|
|
43
|
-
return Object.freeze({
|
|
44
|
-
async getProject({signal}={}){
|
|
45
|
-
const project=parsePublishingProject(await send('GET','/v1/project',undefined,signal),{allowLoopback});
|
|
46
|
-
if(JSON.stringify(project.configuration)!==JSON.stringify(config))throw publishingError('PROJECT_BINDING_INVALID');return project;
|
|
47
|
-
},
|
|
48
|
-
async getLatestRelease({signal}={}){
|
|
49
|
-
const value=await send('GET','/v1/project/release',undefined,signal);
|
|
50
|
-
if(!protocolRecord(value,['schemaVersion','intent'])||value.schemaVersion!==1)throw publishingError('PROJECT_BINDING_INVALID');
|
|
51
|
-
if(value.intent===null)return undefined;
|
|
52
|
-
const intent=checkedIntent(value.intent);
|
|
53
|
-
try{return {intent,status:await boundStatus(await send('GET','/v1/requests/'+intent.requestId,undefined,signal),intent)};}
|
|
54
|
-
catch(error){error.requestId=intent.requestId;throw error;}
|
|
55
|
-
},
|
|
56
|
-
async createRequest({intent:input,manifestBytes,signal}){
|
|
57
|
-
const intent=checkedIntent(input);
|
|
58
|
-
if(!(manifestBytes instanceof Uint8Array)||manifestBytes.byteLength>1048576)throw publishingError('MANIFEST_INVALID');
|
|
59
|
-
let prepared;try{prepared=await createArtifactContentManifest(JSON.parse(new TextDecoder('utf-8',{fatal:true}).decode(manifestBytes)));}catch{throw publishingError('MANIFEST_INVALID');}
|
|
60
|
-
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)throw publishingError('MANIFEST_BINDING_INVALID');
|
|
61
|
-
return boundStatus(await send('POST','/v1/requests',JSON.stringify({intent,manifest:prepared.manifest}),signal),intent);
|
|
62
|
-
},
|
|
63
|
-
async getStatus({intent:input,signal}){const intent=checkedIntent(input);return boundStatus(await send('GET','/v1/requests/'+intent.requestId,undefined,signal),intent);},
|
|
64
|
-
async resumeRequest({intent:input,signal}){const intent=checkedIntent(input);return boundStatus(await send('POST','/v1/requests/'+intent.requestId+'/resume',JSON.stringify({intent}),signal),intent);},
|
|
65
|
-
async recoverRequest({intent:input,signal}){const intent=checkedIntent(input);return boundStatus(await send('POST','/v1/requests/'+intent.requestId+'/recover',JSON.stringify({intent}),signal),intent);},
|
|
66
|
-
async queueRequest({intent:input,signal}){const intent=checkedIntent(input);return boundStatus(await send('POST','/v1/requests/'+intent.requestId+'/commit',JSON.stringify({intent}),signal),intent);},
|
|
67
|
-
async abandonRequest({intent:input,signal}){const intent=checkedIntent(input);return boundStatus(await send('POST','/v1/requests/'+intent.requestId+'/abandon','{}',signal),intent);},
|
|
68
|
-
async uploadChunk({requestId,file,offset,bytes,signal}){
|
|
69
|
-
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)throw publishingError('CHUNK_INVALID');
|
|
70
|
-
const snapshot=new Uint8Array(bytes),value=await send('PUT','/v1/requests/'+requestId+'/files/'+file.sha256+'?offset='+offset,snapshot,signal,'application/octet-stream');
|
|
71
|
-
if(!protocolRecord(value,['schemaVersion','sha256','receivedBytes'])||value.schemaVersion!==1||value.sha256!==file.sha256||value.receivedBytes!==offset+snapshot.byteLength)throw publishingError('CHUNK_RESPONSE_INVALID');return value;
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
}
|
package/src/index.mjs
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export {parseSolutionPackageDescriptor,parseSolutionPackageLimits} from './package.mjs';
|
|
2
|
-
export {parsePublishingConfiguration,parsePublishingProject,parsePublishingIntent,parsePublishingStatus,publishingIntentBytes} from './protocol.mjs';
|
|
3
|
-
export {createPublishingClient} from './client.mjs';
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import {createHash, createPrivateKey, createPublicKey, sign, verify} from 'node:crypto';
|
|
2
|
-
import {protocolRecord, publishingDigest, publishingError, publishingIdentifier} from '../protocol.mjs';
|
|
3
|
-
|
|
4
|
-
export const maximumAcceptanceArchiveBytes = 50 * 1024 ** 2;
|
|
5
|
-
const fail = code => publishingError('ACCEPTANCE_' + code);
|
|
6
|
-
const versionPattern = /^\d{1,8}\.\d{1,8}\.\d{1,8}$/;
|
|
7
|
-
const hash = bytes => createHash('sha256').update(bytes).digest('hex');
|
|
8
|
-
const fields = ['projectId','solutionId','version','origin','keyId','manifestSha256','archiveSha256','artifactSha256','byteLength'];
|
|
9
|
-
|
|
10
|
-
function validateOrigin(value) {
|
|
11
|
-
const url = typeof value === 'string' ? URL.parse(value) : null;
|
|
12
|
-
if (url?.protocol !== 'https:' || url.origin !== value) throw fail('ORIGIN_INVALID');
|
|
13
|
-
return value;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function parseAcceptanceDeliveryCredential(value) {
|
|
17
|
-
if (!protocolRecord(value,['origin','keyId','privateKey']) || !publishingIdentifier(value.keyId) ||
|
|
18
|
-
typeof value.privateKey !== 'string' || value.privateKey.length > 4096) throw fail('CREDENTIAL_INVALID');
|
|
19
|
-
validateOrigin(value.origin);
|
|
20
|
-
const key = createPrivateKey(value.privateKey);
|
|
21
|
-
if (key.asymmetricKeyType !== 'ed25519') throw fail('CREDENTIAL_INVALID');
|
|
22
|
-
return {origin:value.origin,keyId:value.keyId,privateKey:key.export({type:'pkcs8',format:'pem'}).toString()};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function acceptanceDeliveryTarget(credential) {
|
|
26
|
-
const {origin,keyId,privateKey}=parseAcceptanceDeliveryCredential(credential);
|
|
27
|
-
return {origin,keyId,publicKeySha256:hash(createPublicKey(privateKey).export({type:'spki',format:'der'}))};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function binding(value) {
|
|
31
|
-
if (!protocolRecord(value,fields) || ![value.projectId,value.solutionId,value.keyId].every(publishingIdentifier) ||
|
|
32
|
-
!versionPattern.test(value.version) || ![value.manifestSha256,value.archiveSha256,value.artifactSha256].every(publishingDigest) ||
|
|
33
|
-
!Number.isSafeInteger(value.byteLength) || value.byteLength < 1 || value.byteLength > maximumAcceptanceArchiveBytes) throw fail('BINDING_INVALID');
|
|
34
|
-
validateOrigin(value.origin);
|
|
35
|
-
return Buffer.from(JSON.stringify(['link-light/owner-acceptance-installation/v1', ...fields.map(key => value[key])]));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function signAcceptanceDelivery(value, privateKey) {
|
|
39
|
-
return sign(null,binding(value),privateKey).toString('base64url');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function verifyAcceptanceDelivery(value, signature, publicKey) {
|
|
43
|
-
if (typeof signature !== 'string' || !/^[A-Za-z0-9_-]{86}$/.test(signature)) throw fail('SIGNATURE_INVALID');
|
|
44
|
-
const key = typeof publicKey === 'string' ? createPublicKey(publicKey) : publicKey;
|
|
45
|
-
if (key?.asymmetricKeyType !== 'ed25519' || !verify(null,binding(value),key,Buffer.from(signature,'base64url'))) throw fail('SIGNATURE_INVALID');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** Only the dedicated owner's HTTPS origin receives this archive. A read after
|
|
49
|
-
* the immutable PUT also reconciles a lost response without repeating a release. */
|
|
50
|
-
function deliveryTarget({intent,archive,credential,request=fetch,signal}) {
|
|
51
|
-
if (!credential) throw fail('CREDENTIAL_REQUIRED');
|
|
52
|
-
const {origin,keyId,privateKey}=parseAcceptanceDeliveryCredential(credential);
|
|
53
|
-
const expected={projectId:intent.projectId,solutionId:intent.package.solutionId,version:intent.package.version,
|
|
54
|
-
origin,keyId,manifestSha256:intent.package.content.manifestSha256,...archive};
|
|
55
|
-
const url=new URL('/v1/acceptance/installations/'+expected.version,origin);
|
|
56
|
-
const timeout=AbortSignal.timeout(30000);
|
|
57
|
-
const options={redirect:'error',signal:signal?AbortSignal.any([signal,timeout]):timeout};
|
|
58
|
-
async function observed(){
|
|
59
|
-
const response=await request(url,{...options,method:'GET',headers:{accept:'application/json'}});
|
|
60
|
-
if(response.status===404){await response.body?.cancel();return false;}
|
|
61
|
-
if(response.status!==200){await response.body?.cancel();throw fail('DELIVERY_UNKNOWN');}
|
|
62
|
-
const receipt=await readDeliveryBody(response,8192);
|
|
63
|
-
let value;try{value=JSON.parse(receipt.toString('utf8'));}catch{throw fail('DELIVERY_UNKNOWN');}
|
|
64
|
-
if (!protocolRecord(value,fields))throw fail('DELIVERY_UNKNOWN');
|
|
65
|
-
if (!binding(value).equals(binding(expected))) throw fail('VERSION_CONFLICT');
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
return {observed,expected,privateKey,options,url,request};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export async function observeAcceptanceDelivery(input) {
|
|
72
|
-
return deliveryTarget(input).observed();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export async function deliverAcceptanceArchive(input) {
|
|
76
|
-
const {bytes,archive}=input;
|
|
77
|
-
if (!(bytes instanceof Uint8Array) || bytes.byteLength!==archive.byteLength || hash(bytes)!==archive.archiveSha256) throw fail('ARCHIVE_CHANGED');
|
|
78
|
-
const {observed,expected,privateKey,options,url,request}=deliveryTarget(input);
|
|
79
|
-
if(await observed())return;
|
|
80
|
-
const signature=signAcceptanceDelivery(expected,privateKey);
|
|
81
|
-
let rejection;
|
|
82
|
-
try {
|
|
83
|
-
const response=await request(url,{...options,method:'PUT',headers:{'content-type':'application/octet-stream',
|
|
84
|
-
'x-link-light-binding':Buffer.from(JSON.stringify(expected)).toString('base64url'),'x-link-light-signature':signature},body:bytes});
|
|
85
|
-
await response.body?.cancel();
|
|
86
|
-
if(response.status===403)rejection='SIGNATURE_INVALID';
|
|
87
|
-
if(response.status===409)rejection='VERSION_CONFLICT';
|
|
88
|
-
if([400,413,415,422].includes(response.status))rejection='DELIVERY_REJECTED';
|
|
89
|
-
} catch(error){if(error?.code?.startsWith('PUBLISHING_ACCEPTANCE_'))throw error;}
|
|
90
|
-
if(!await observed())throw fail(rejection??'DELIVERY_UNKNOWN');
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export async function readDeliveryBody(message,limit) {
|
|
94
|
-
const length=message.headers.get('content-length');
|
|
95
|
-
if(!Number.isSafeInteger(limit)||limit<1||limit>maximumAcceptanceArchiveBytes||!message.body||
|
|
96
|
-
length!==null&&(!/^\d+$/.test(length)||Number(length)>limit))throw fail('BODY_LIMIT');
|
|
97
|
-
const reader=message.body.getReader(),chunks=[];
|
|
98
|
-
let total=0;
|
|
99
|
-
try {
|
|
100
|
-
for(;;){
|
|
101
|
-
const {done,value}=await reader.read();
|
|
102
|
-
if(done)break;
|
|
103
|
-
total+=value.byteLength;
|
|
104
|
-
if(total>limit)throw fail('BODY_LIMIT');
|
|
105
|
-
chunks.push(value);
|
|
106
|
-
}
|
|
107
|
-
} finally {try{await reader.cancel();}finally{reader.releaseLock();}}
|
|
108
|
-
return Buffer.concat(chunks,total);
|
|
109
|
-
}
|
package/src/node/activation.mjs
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import {createHash,createPublicKey} from 'node:crypto';
|
|
2
|
-
import {parseAcceptanceDeliveryCredential} from './acceptance-delivery.mjs';
|
|
3
|
-
import {createPublishingClient} from '../client.mjs';
|
|
4
|
-
import {parsePublishingConfiguration,protocolRecord,publishingError} from '../protocol.mjs';
|
|
5
|
-
|
|
6
|
-
const key='client-authorization',hash=value=>createHash('sha256').update(value).digest('hex'),fail=code=>publishingError('CREDENTIAL_'+code);
|
|
7
|
-
const credentialValid=value=>typeof value==='string'&&/^[A-Za-z0-9_-]{32,4096}$/.test(value);
|
|
8
|
-
function saved(record,allowLoopback){
|
|
9
|
-
if(!record)return undefined;const value=record.payload;
|
|
10
|
-
if(!protocolRecord(value,['schemaVersion','configuration','configurationSha256','credential','credentialSha256'],['acceptanceDelivery'])||value.schemaVersion!==1||!credentialValid(value.credential))throw fail('INVALID');
|
|
11
|
-
let configuration;try{configuration=parsePublishingConfiguration(value.configuration,{allowLoopback});}catch{throw fail('INVALID');}
|
|
12
|
-
if(hash(JSON.stringify(configuration))!==value.configurationSha256||hash(value.credential)!==value.credentialSha256)throw fail('INVALID');
|
|
13
|
-
return {configuration,credential:value.credential,...(value.acceptanceDelivery?{acceptanceDelivery:parseAcceptanceDeliveryCredential(value.acceptanceDelivery)}:{})};
|
|
14
|
-
}
|
|
15
|
-
function store(journal){if(!journal||typeof journal.load!=='function'||typeof journal.compareAndSet!=='function')throw fail('STORE_INVALID');return journal;}
|
|
16
|
-
|
|
17
|
-
/** The caller supplies private persistent storage, including access controls and
|
|
18
|
-
* backup policy. No provider credential or process/global setting is stored. */
|
|
19
|
-
export async function loadPublishingAuthorization({journal,allowLoopback=false,signal}){
|
|
20
|
-
signal?.throwIfAborted();return saved(await store(journal).load(key,{signal}),allowLoopback);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** Validate installed trust and current project access before atomic install.
|
|
24
|
-
* A changed service/publisher trust never adopts an existing recovery journal. */
|
|
25
|
-
export async function installPublishingAuthorization({journal,configuration:input,credential,acceptanceDelivery,replaceCredential=false,allowLoopback=false,request,clientLimits,signal}){
|
|
26
|
-
store(journal);signal?.throwIfAborted();const configuration=parsePublishingConfiguration(input,{allowLoopback});
|
|
27
|
-
if(!credentialValid(credential)||typeof replaceCredential!=='boolean')throw fail('INVALID');
|
|
28
|
-
const previous=await journal.load(key,{signal}),current=saved(previous,allowLoopback),configurationSha256=hash(JSON.stringify(configuration)),credentialSha256=hash(credential);
|
|
29
|
-
if(current&&JSON.stringify(current.configuration)!==JSON.stringify(configuration))throw fail('TRUST_CHANGED');
|
|
30
|
-
if(current&¤t.credential!==credential&&!replaceCredential)throw fail('REPLACEMENT_REQUIRED');
|
|
31
|
-
const delivery=acceptanceDelivery===undefined?current?.acceptanceDelivery:parseAcceptanceDeliveryCredential(acceptanceDelivery);
|
|
32
|
-
if(delivery){
|
|
33
|
-
const publicBytes=key=>createPublicKey(key).export({type:'spki',format:'der'});
|
|
34
|
-
if(configuration.publisher.keys.some(key=>publicBytes(key.publicKey).equals(publicBytes(delivery.privateKey))))throw fail('TRUST_CHANGED');
|
|
35
|
-
if(current?.acceptanceDelivery&&(delivery.origin!==current.acceptanceDelivery.origin||delivery.keyId!==current.acceptanceDelivery.keyId||
|
|
36
|
-
!publicBytes(delivery.privateKey).equals(publicBytes(current.acceptanceDelivery.privateKey))))throw fail('TRUST_CHANGED');
|
|
37
|
-
if(current?.acceptanceDelivery&&JSON.stringify(current.acceptanceDelivery)!==JSON.stringify(delivery)&&!replaceCredential)throw fail('REPLACEMENT_REQUIRED');
|
|
38
|
-
}
|
|
39
|
-
const client=createPublishingClient({configuration,credential,allowLoopback,...(request?{request}:{}),...(clientLimits?{limits:clientLimits}:{})}),project=await client.getProject({signal});
|
|
40
|
-
if(current?.credential===credential&&JSON.stringify(current.acceptanceDelivery)===JSON.stringify(delivery)){
|
|
41
|
-
const latest=await journal.load(key,{signal});if(latest?.revision!==previous.revision)throw fail('CONFLICT');saved(latest,allowLoopback);
|
|
42
|
-
return {status:'VERIFIED',projectId:configuration.projectId,credentialSha256,policyRevision:project.policyRevision};
|
|
43
|
-
}
|
|
44
|
-
let result;
|
|
45
|
-
try{result=await journal.compareAndSet({key,expectedRevision:previous?.revision??0,payload:{schemaVersion:1,configuration,configurationSha256,credential,credentialSha256,...(delivery?{acceptanceDelivery:delivery}:{})}},{signal});}
|
|
46
|
-
catch{throw fail('PERSISTENCE_UNKNOWN');}
|
|
47
|
-
if(result==='conflict')throw fail('CONFLICT');if(result!=='stored')throw fail('PERSISTENCE_UNKNOWN');
|
|
48
|
-
return {status:previous?'REPLACED':'CONFIGURED',projectId:configuration.projectId,credentialSha256,policyRevision:project.policyRevision};
|
|
49
|
-
}
|
package/src/node/cli.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import {existsSync,realpathSync} from 'node:fs';
|
|
3
|
-
import {fileURLToPath} from 'node:url';
|
|
4
|
-
import {runPublishingCommand} from './publishing-command.mjs';
|
|
5
|
-
|
|
6
|
-
async function main(){
|
|
7
|
-
const controller=new AbortController(),stop=()=>controller.abort();process.once('SIGINT',stop);process.once('SIGTERM',stop);
|
|
8
|
-
try{const result=await runPublishingCommand(process.argv.slice(2),{signal:controller.signal});process.stdout.write(JSON.stringify(result.output)+'\n');process.exitCode=result.exitCode;}
|
|
9
|
-
finally{process.off('SIGINT',stop);process.off('SIGTERM',stop);}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if(process.argv[1]&&existsSync(process.argv[1])&&realpathSync(process.argv[1])===realpathSync(fileURLToPath(import.meta.url)))void main();
|
package/src/node/index.d.mts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export type {SolutionPackageLimits,SolutionPackageFilePlan,PreparedSolutionPackage} from './solution-package.mjs';
|
|
2
|
-
export type {PublishingMetadataTransport} from '../protocol.mjs';
|
|
3
|
-
export {prepareSolutionPackage,prepareSolutionPackageBytes,verifySolutionPackage,verifySolutionPackageBytes} from './solution-package.mjs';
|
|
4
|
-
export type {PublishingJournal,PublishingJournalRecord,PublishingJournalLimits} from './journal.mjs';
|
|
5
|
-
export {openPublishingJournal} from './journal.mjs';
|
|
6
|
-
export type {PublishingSession,PublishingSessionResult} from './session.mjs';
|
|
7
|
-
export {createPublishingSession} from './session.mjs';
|
|
8
|
-
export type {PublishingAuthorization} from './authorization.mjs';
|
|
9
|
-
export {installPublishingAuthorization,loadPublishingAuthorization} from './authorization.mjs';
|
|
10
|
-
export type {PublishingActivation} from './activation.mjs';
|
|
11
|
-
export {createPublishingActivation,verifyPublishingActivation} from './activation.mjs';
|
|
12
|
-
export {PublishingSourceError} from './source-error.mjs';
|
|
13
|
-
export type {PublishingSourceProducer,PublishingWorkflowOptions,PublishingSourceOptions,PublishingPublishOptions,PublishingWorkflowResult,PublishingWorkflow} from './workflow.mjs';
|
|
14
|
-
export {createPublishingWorkflow} from './workflow.mjs';
|
|
15
|
-
export type {PublishingCommandOptions,PublishingCommandResult} from './publishing-command.mjs';
|
|
16
|
-
export {runPublishingCommand} from './publishing-command.mjs';
|
|
17
|
-
export * from './acceptance-delivery.mjs';
|
package/src/node/index.mjs
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export {prepareSolutionPackage,prepareSolutionPackageBytes,verifySolutionPackage,verifySolutionPackageBytes} from './solution-package.mjs';
|
|
2
|
-
export {openPublishingJournal} from './journal.mjs';
|
|
3
|
-
export {createPublishingSession} from './session.mjs';
|
|
4
|
-
export {installPublishingAuthorization,loadPublishingAuthorization} from './authorization.mjs';
|
|
5
|
-
export {createPublishingActivation,verifyPublishingActivation} from './activation.mjs';
|
|
6
|
-
export {PublishingSourceError} from './source-error.mjs';
|
|
7
|
-
export {createPublishingWorkflow} from './workflow.mjs';
|
|
8
|
-
export {deliverAcceptanceArchive,signAcceptanceDelivery,maximumAcceptanceArchiveBytes,readDeliveryBody,verifyAcceptanceDelivery} from './acceptance-delivery.mjs';
|
|
9
|
-
export {runPublishingCommand} from './publishing-command.mjs';
|