@xlinklight/publishing 0.0.0-stage → 3.0.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/LICENSE +21 -0
- package/README.md +35 -2
- package/package.json +62 -3
- package/src/acceptance.d.mts +22 -0
- package/src/acceptance.mjs +66 -0
- package/src/client.d.mts +15 -0
- package/src/client.mjs +66 -0
- package/src/index.d.mts +6 -0
- package/src/index.mjs +3 -0
- package/src/node/activation.d.mts +8 -0
- package/src/node/activation.mjs +3 -0
- package/src/node/authorization.d.mts +8 -0
- package/src/node/authorization.mjs +39 -0
- package/src/node/cli.d.mts +20 -0
- package/src/node/cli.mjs +106 -0
- package/src/node/index.d.mts +16 -0
- package/src/node/index.mjs +8 -0
- package/src/node/journal.d.mts +13 -0
- package/src/node/journal.mjs +135 -0
- package/src/node/session.d.mts +23 -0
- package/src/node/session.mjs +101 -0
- package/src/node/solution-package.d.mts +15 -0
- package/src/node/solution-package.mjs +113 -0
- package/src/node/source-error.d.mts +5 -0
- package/src/node/source-error.mjs +9 -0
- package/src/node/workflow.d.mts +35 -0
- package/src/node/workflow.mjs +178 -0
- package/src/package.d.mts +11 -0
- package/src/package.mjs +36 -0
- package/src/protocol.d.mts +27 -0
- package/src/protocol.mjs +50 -0
- package/src/shared/activation.d.mts +5 -0
- package/src/shared/activation.mjs +64 -0
- package/src/worker/activation.d.mts +7 -0
- package/src/worker/activation.mjs +4 -0
- package/src/worker/index.d.mts +6 -0
- package/src/worker/index.mjs +6 -0
- package/src/worker/journal.d.mts +21 -0
- package/src/worker/journal.mjs +151 -0
- package/src/worker/package.d.mts +16 -0
- package/src/worker/package.mjs +32 -0
- package/src/worker/release.d.mts +7 -0
- package/src/worker/release.mjs +21 -0
- package/src/worker/runtime.d.mts +4 -0
- package/src/worker/runtime.mjs +23 -0
- package/src/worker/service.d.mts +41 -0
- package/src/worker/service.mjs +247 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import {pathToFileURL} from 'node:url';
|
|
4
|
+
import {randomUUID} from 'node:crypto';
|
|
5
|
+
import {setTimeout as delay} from 'node:timers/promises';
|
|
6
|
+
import {validatePortableRelativePath} from '@openge/forge-path-safety';
|
|
7
|
+
import {createPublishingClient} from '../client.mjs';
|
|
8
|
+
import {parsePublishingConfiguration,parsePublishingProject,parsePublishingIntent,publishingRequestId,protocolRecord,publishingError} from '../protocol.mjs';
|
|
9
|
+
import {createPublishingSession} from './session.mjs';
|
|
10
|
+
import {verifyPublishingActivation} from './activation.mjs';
|
|
11
|
+
import {PublishingSourceError} from './source-error.mjs';
|
|
12
|
+
|
|
13
|
+
const fail=code=>publishingError(code),sourceKey=id=>'source:'+id;
|
|
14
|
+
const sourceOptions=input=>{
|
|
15
|
+
if(!protocolRecord(input,[],['producer','newPreparation','signal'])||input.newPreparation!==undefined&&typeof input.newPreparation!=='boolean')throw fail('WORKFLOW_INPUT_INVALID');
|
|
16
|
+
const producer=input.producer??'deployment/publishing.mjs';try{if(validatePortableRelativePath(producer)!==producer||!producer.endsWith('.mjs'))throw Error();}catch{throw fail('SOURCE_PATH_INVALID');}return {...input,producer};
|
|
17
|
+
};
|
|
18
|
+
async function producerFile(root,relative){
|
|
19
|
+
const selected=path.join(root,...relative.split('/'));let current=root;
|
|
20
|
+
for(const [index,part]of relative.split('/').entries()){
|
|
21
|
+
current=path.join(current,part);const info=await fs.lstat(current,{bigint:true});
|
|
22
|
+
if(info.isSymbolicLink()||await fs.realpath(current)!==current||(index===relative.split('/').length-1? !info.isFile()||info.nlink!==1n||info.size>65536n:!info.isDirectory()))throw fail('SOURCE_PATH_INVALID');
|
|
23
|
+
}
|
|
24
|
+
return selected;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** One active request per project/client journal. Recovery never imports source
|
|
28
|
+
* or performs an operation whose durable Foundation claim already exists. */
|
|
29
|
+
export function createPublishingWorkflow(options){
|
|
30
|
+
const {root,journal,credential,allowLoopback=false,request,clientLimits,metadataTransport,operationLimits}=options;
|
|
31
|
+
const configuration=parsePublishingConfiguration(options.configuration,{allowLoopback}),pathCaseSensitivity=options.pathCaseSensitivity??(process.platform==='win32'?'case-insensitive':'case-sensitive');
|
|
32
|
+
if(typeof root!=='string'||!path.isAbsolute(root)||!journal||!['case-sensitive','case-insensitive'].includes(pathCaseSensitivity))throw fail('WORKFLOW_INPUT_INVALID');
|
|
33
|
+
const verifier=signal=>async input=>{const timeout=AbortSignal.timeout(clientLimits?.requestMs??30000);await verifyPublishingActivation({...input,allowLoopback,signal:signal?AbortSignal.any([signal,timeout]):timeout,...(metadataTransport?{metadataTransport}:{})});};
|
|
34
|
+
const shared={journal,configuration,credential,allowLoopback,...(request?{request}:{}),...(clientLimits?{clientLimits}:{})};
|
|
35
|
+
const client=signal=>createPublishingClient({...shared,...(clientLimits?{limits:clientLimits}:{}),verifyActivation:verifier(signal)}),activeKey='active:'+configuration.projectId;
|
|
36
|
+
const session=(record,signal)=>createPublishingSession({...shared,verifyActivation:verifier(signal),packageLimits:record.payload.project.limits,pathCaseSensitivity:record.payload.pathCaseSensitivity,...(operationLimits?{operationLimits}:{})});
|
|
37
|
+
const replace=async(record,phase,signal,failure)=>{
|
|
38
|
+
const payload={...record.payload,phase,...(failure?{failure}:{})},result=await journal.compareAndSet({key:sourceKey(payload.requestId),expectedRevision:record.revision,payload},{signal});
|
|
39
|
+
if(result!=='stored')throw fail('WORKFLOW_CONFLICT');return {revision:record.revision+1,payload};
|
|
40
|
+
};
|
|
41
|
+
const current=async signal=>{
|
|
42
|
+
const active=await journal.load(activeKey,{signal});if(!active)return undefined;
|
|
43
|
+
if(!protocolRecord(active.payload,['schemaVersion','requestId'])||active.payload.schemaVersion!==1||!publishingRequestId(active.payload.requestId))throw fail('WORKFLOW_STATE_INVALID');
|
|
44
|
+
let record=await journal.load(sourceKey(active.payload.requestId),{signal});
|
|
45
|
+
if(!record||!protocolRecord(record.payload,['schemaVersion','requestId','phase','project','pathCaseSensitivity'],['failure'])||record.payload.schemaVersion!==1||record.payload.requestId!==active.payload.requestId||!['preparing','failed-closed','frozen','remote','abandoned','completed','failed'].includes(record.payload.phase)||!['case-sensitive','case-insensitive'].includes(record.payload.pathCaseSensitivity))throw fail('WORKFLOW_STATE_INVALID');
|
|
46
|
+
if(record.payload.failure!==undefined&&(record.payload.phase!=='failed-closed'||!protocolRecord(record.payload.failure,['code'])||!['PUBLISHING_SOURCE_PACKAGE_BINDING_INVALID','PUBLISHING_SOURCE_PREPARATION_FAILED'].includes(record.payload.failure.code)))throw fail('WORKFLOW_STATE_INVALID');
|
|
47
|
+
const project=parsePublishingProject(record.payload.project,{allowLoopback});if(JSON.stringify(project.configuration)!==JSON.stringify(configuration))throw fail('CONFIGURATION_CHANGED');
|
|
48
|
+
// freeze is the atomic authority: losing the outer acknowledgment must never
|
|
49
|
+
// cause a second import, build, capture or request identity.
|
|
50
|
+
if(record.payload.phase==='preparing'&&await journal.load('request:'+record.payload.requestId,{signal})){
|
|
51
|
+
await session(record,signal).read({requestId:record.payload.requestId,signal});record=await replace(record,'frozen',signal);
|
|
52
|
+
}
|
|
53
|
+
return {active,record};
|
|
54
|
+
};
|
|
55
|
+
const result=(record,state,extra={})=>({requestId:record.payload.requestId,state,active:state==='active',...extra});
|
|
56
|
+
const operationClaim=(id,stage,signal)=>journal.load('operation:'+id+'.'+stage,{signal});
|
|
57
|
+
const prepare=async input=>{
|
|
58
|
+
const {producer,newPreparation=false,signal}=sourceOptions(input);let previous=await current(signal);
|
|
59
|
+
if(previous&&newPreparation&&['remote','completed','failed'].includes(previous.record.payload.phase)){
|
|
60
|
+
// Observe the original identity and current admission before permitting the
|
|
61
|
+
// next release. A prior terminal observation never authorizes an unknown,
|
|
62
|
+
// still-running or currently unverified request to be replaced.
|
|
63
|
+
const observed=await inspect({signal},true);
|
|
64
|
+
if(observed.sideEffects!=='closed'||!['abandoned','active','failed'].includes(observed.state))throw fail('SOURCE_ACTIVE_REQUEST_EXISTS');
|
|
65
|
+
previous=await current(signal);
|
|
66
|
+
}
|
|
67
|
+
if(previous){
|
|
68
|
+
const phase=previous.record.payload.phase;
|
|
69
|
+
if(phase==='preparing')throw fail('SOURCE_PREPARATION_UNKNOWN');
|
|
70
|
+
if(phase==='frozen'||phase==='remote'){if(newPreparation)throw fail('SOURCE_ACTIVE_REQUEST_EXISTS');return previous.record;}
|
|
71
|
+
if(!newPreparation)throw fail('SOURCE_NEW_PREPARATION_REQUIRED');
|
|
72
|
+
}
|
|
73
|
+
signal?.throwIfAborted();if(await fs.realpath(root)!==root||!(await fs.lstat(root)).isDirectory())throw fail('SOURCE_PATH_INVALID');
|
|
74
|
+
const project=await client(signal).getProject({signal}),requestId=randomUUID(),payload={schemaVersion:1,requestId,phase:'preparing',project,pathCaseSensitivity};
|
|
75
|
+
if(await journal.compareAndSet({key:sourceKey(requestId),expectedRevision:0,payload},{signal})!=='stored')throw fail('WORKFLOW_CONFLICT');
|
|
76
|
+
if(await journal.compareAndSet({key:activeKey,expectedRevision:previous?.active.revision??0,payload:{schemaVersion:1,requestId}},{signal})!=='stored')throw fail('WORKFLOW_CONFLICT');
|
|
77
|
+
let record={revision:1,payload},prepared,intent,processesClosed=false;
|
|
78
|
+
try{
|
|
79
|
+
const file=await producerFile(root,producer),producerModule=await import(pathToFileURL(file).href+'?publishingRequest='+requestId);
|
|
80
|
+
if(typeof producerModule.prepare!=='function')throw fail('SOURCE_PORT_INVALID');
|
|
81
|
+
const response=await producerModule.prepare({root,project:structuredClone(project),signal,requestId});
|
|
82
|
+
if(!protocolRecord(response,['prepared','processesClosed'])||response.processesClosed!==true)throw fail('SOURCE_PROCESS_CLOSURE_UNKNOWN');processesClosed=true;prepared=response.prepared;
|
|
83
|
+
const item=prepared?.descriptor;
|
|
84
|
+
if(!item||item.solutionId!==project.solutionId||item.packageName!==project.packageName||item.publisherId!==configuration.publisher.publisherId)throw fail('SOURCE_PACKAGE_BINDING_INVALID');
|
|
85
|
+
intent=parsePublishingIntent({schemaVersion:1,requestId,projectId:configuration.projectId,policyRevision:project.policyRevision,package:{solutionId:item.solutionId,publisherId:item.publisherId,packageName:item.packageName,version:item.version,content:prepared.content,fileCount:prepared.files.length,totalBytes:prepared.payloadBytes}});
|
|
86
|
+
}catch(error){
|
|
87
|
+
if(processesClosed||error instanceof PublishingSourceError&&error.processesClosed){record=await replace(record,'failed-closed',signal,{code:error.code==='PUBLISHING_SOURCE_PACKAGE_BINDING_INVALID'?error.code:'PUBLISHING_SOURCE_PREPARATION_FAILED'});throw new PublishingSourceError({cause:error,processesClosed:true});}
|
|
88
|
+
throw new PublishingSourceError({cause:error,processesClosed:false});
|
|
89
|
+
}
|
|
90
|
+
// Freeze and its acknowledgment deliberately remain outside the known-closed
|
|
91
|
+
// source catch: a storage error can mean the original bytes were committed.
|
|
92
|
+
await session(record,signal).freeze({intent,prepared,signal});record=await replace(record,'frozen',signal);return record;
|
|
93
|
+
};
|
|
94
|
+
const local=record=>result(record,['frozen','remote'].includes(record.payload.phase)?'checked':record.payload.phase==='preparing'?'preparation-unknown':record.payload.phase==='failed-closed'?'preparation-failed':record.payload.phase==='abandoned'?'abandoned':'unknown');
|
|
95
|
+
const observedResult=async(record,status,signal)=>{
|
|
96
|
+
// The client/session authenticated this exact original intent, and ACTIVE
|
|
97
|
+
// already passed the real signature and current Core-admission verifier.
|
|
98
|
+
const phase=status.sideEffects==='closed'?{abandoned:'abandoned',active:'completed',failed:'failed'}[status.state]:undefined;
|
|
99
|
+
if(phase&&record.payload.phase!==phase){
|
|
100
|
+
try{record=await replace(record,phase,signal);}
|
|
101
|
+
catch(error){
|
|
102
|
+
if(error.code!=='PUBLISHING_WORKFLOW_CONFLICT')throw error;
|
|
103
|
+
const latest=await journal.load(sourceKey(record.payload.requestId),{signal});if(latest?.payload.phase!==phase)throw error;record=latest;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return result(record,status.state,{sideEffects:status.sideEffects});
|
|
107
|
+
};
|
|
108
|
+
const inspect=async({signal}={},observe=false,dispatchRecovery=false)=>{
|
|
109
|
+
const state=await current(signal);if(!state)return {state:'empty',active:false};const {record}=state;
|
|
110
|
+
if(!['frozen','remote','completed','failed'].includes(record.payload.phase))return local(record);
|
|
111
|
+
const requestId=record.payload.requestId,commit=await operationClaim(requestId,'commit',signal),create=await operationClaim(requestId,'create',signal);
|
|
112
|
+
if(!commit&&!create)return local(record);
|
|
113
|
+
const selected=session(record,signal);
|
|
114
|
+
if(observe){
|
|
115
|
+
const observed=await selected.observe({requestId,stage:commit?'commit':'create',signal});if(!observed.status)return result(record,'unknown');
|
|
116
|
+
// The control only asks the host to observe an already committed original
|
|
117
|
+
// operation. Uploading/local preparation never dispatches provider work.
|
|
118
|
+
const status=dispatchRecovery&&commit&&['queued','deploying','awaiting-acceptance','unknown'].includes(observed.status.state)?await selected.recover({requestId,signal}):observed.status;
|
|
119
|
+
return observedResult(record,status,signal);
|
|
120
|
+
}
|
|
121
|
+
return observedResult(record,await selected.status({requestId,signal}),signal);
|
|
122
|
+
};
|
|
123
|
+
const waiting=state=>['queued','deploying','registered','awaiting-acceptance'].includes(state);
|
|
124
|
+
const waitFor=async(record,initial,{signal,waitMs,pollMs})=>{
|
|
125
|
+
if(!waitMs||!waiting(initial.state))return initial;
|
|
126
|
+
const timeout=AbortSignal.timeout(waitMs),active=signal?AbortSignal.any([signal,timeout]):timeout;let latest=initial;
|
|
127
|
+
try{
|
|
128
|
+
while(waiting(latest.state)){
|
|
129
|
+
await delay(pollMs,undefined,{signal:active});
|
|
130
|
+
latest=await observedResult(record,await session(record,active).status({requestId:record.payload.requestId,signal:active}),active);
|
|
131
|
+
}
|
|
132
|
+
return latest;
|
|
133
|
+
}catch(error){if(timeout.aborted&&!signal?.aborted)return {...latest,timedOut:true};throw error;}
|
|
134
|
+
};
|
|
135
|
+
return Object.freeze({
|
|
136
|
+
async check(input={}){return local(await prepare(input));},
|
|
137
|
+
async publish(input={}){
|
|
138
|
+
if(!protocolRecord(input,[],['producer','newPreparation','signal','waitMs','pollMs']))throw fail('WORKFLOW_INPUT_INVALID');
|
|
139
|
+
const {waitMs=0,pollMs=1000,...source}=input;
|
|
140
|
+
if(!Number.isSafeInteger(waitMs)||waitMs<0||waitMs>3600000||!Number.isSafeInteger(pollMs)||pollMs<1||pollMs>30000)throw fail('WORKFLOW_INPUT_INVALID');
|
|
141
|
+
let record=await prepare(source);const requestId=record.payload.requestId,signal=input.signal,finish=status=>waitFor(record,status,{signal,waitMs,pollMs});
|
|
142
|
+
// This CAS competes with local abandonment before any remote write. Once
|
|
143
|
+
// remote publication may start, absence of a later claim is not a closure
|
|
144
|
+
// proof for an overlapping client.
|
|
145
|
+
if(record.payload.phase==='frozen')record=await replace(record,'remote',signal);
|
|
146
|
+
const selected=session(record,signal);
|
|
147
|
+
// Never repeat creation, upload or commit after the original commit claim.
|
|
148
|
+
// A healthy confirmed original may ask the host for its known next step;
|
|
149
|
+
// unknown requires explicit recovery and cannot perform on publish.
|
|
150
|
+
if(await operationClaim(requestId,'commit',signal)){
|
|
151
|
+
const original=await inspect({signal},true);
|
|
152
|
+
if(['queued','deploying'].includes(original.state))return finish(await observedResult(record,await selected.resume({requestId,signal}),signal));
|
|
153
|
+
return finish(original);
|
|
154
|
+
}
|
|
155
|
+
const created=await(await operationClaim(requestId,'create',signal)?selected.observe({requestId,stage:'create',signal}):selected.create({requestId,signal}));
|
|
156
|
+
if(created.receipt.outcome!=='succeeded')return result(record,'unknown');
|
|
157
|
+
if(created.status&&created.status.state!=='uploading')return finish(await observedResult(record,created.status,signal));
|
|
158
|
+
const uploaded=await selected.upload({requestId,signal});if(uploaded.state!=='uploading')return finish(await observedResult(record,uploaded,signal));
|
|
159
|
+
if(uploaded.missingFiles.length)throw fail('UPLOAD_INCOMPLETE');
|
|
160
|
+
const queued=await selected.queue({requestId,signal});return queued.status?finish(await observedResult(record,queued.status,signal)):result(record,'unknown');
|
|
161
|
+
},
|
|
162
|
+
status:input=>inspect(input),recover:input=>inspect(input,true,true),verify:input=>inspect(input),
|
|
163
|
+
async abandon({signal}={}){
|
|
164
|
+
const state=await current(signal);if(!state)throw fail('SOURCE_REQUEST_MISSING');let {record}=state;
|
|
165
|
+
if(record.payload.phase==='abandoned')return local(record);
|
|
166
|
+
if(record.payload.phase==='preparing')throw fail('SOURCE_PREPARATION_UNKNOWN');if(!['frozen','remote'].includes(record.payload.phase))throw fail('ABANDON_UNSAFE');
|
|
167
|
+
const requestId=record.payload.requestId;
|
|
168
|
+
if(await operationClaim(requestId,'commit',signal))throw fail('ABANDON_UNSAFE');
|
|
169
|
+
if(await operationClaim(requestId,'create',signal)){
|
|
170
|
+
const selected=session(record,signal),{intent}=await selected.read({requestId,signal}),status=await client(signal).getStatus({intent,signal});
|
|
171
|
+
if(status.state==='abandoned'&&status.sideEffects==='closed')return observedResult(record,status,signal);
|
|
172
|
+
if(status.state!=='uploading'||status.sideEffects!=='none')throw fail('ABANDON_UNSAFE');
|
|
173
|
+
const abandoned=await selected.abandon({requestId,signal});if(abandoned.state!=='abandoned'||abandoned.sideEffects!=='closed')throw fail('ABANDON_UNSAFE');
|
|
174
|
+
}else if(record.payload.phase==='remote')throw fail('ABANDON_UNSAFE');
|
|
175
|
+
record=await replace(record,'abandoned',signal);return local(record);
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type {Digest,JsonValue} from '@xlinklight/contracts';
|
|
2
|
+
export interface SolutionPackageLimits {maximumFiles:number;maximumFileBytes:number;maximumTotalBytes:number;maximumManifestBytes:number;timeoutMs:number}
|
|
3
|
+
export function parseSolutionPackageLimits(value:unknown):SolutionPackageLimits;
|
|
4
|
+
export interface SolutionPackageDescriptor {
|
|
5
|
+
readonly schemaVersion:1;readonly solutionId:string;readonly publisherId:string;
|
|
6
|
+
readonly packageName:string;readonly version:string;readonly sdkApiVersion:'2.0.0';
|
|
7
|
+
readonly runtime:{readonly entry:string;readonly protocolVersion:2;readonly links:readonly {readonly path:string;readonly target:string}[]};
|
|
8
|
+
readonly ui:{readonly entry:string;readonly bridgeVersion:1};
|
|
9
|
+
readonly release:{readonly permissions:JsonValue;readonly display:JsonValue;readonly queries:JsonValue;readonly operations:JsonValue;readonly capabilities:JsonValue;readonly resourcesDigest:Digest};
|
|
10
|
+
}
|
|
11
|
+
export function parseSolutionPackageDescriptor(value:unknown):SolutionPackageDescriptor;
|
package/src/package.mjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {validatePortableRelativePath} from '@openge/forge-path-safety';
|
|
2
|
+
|
|
3
|
+
const invalid=()=>{throw Error('PUBLISHING_PACKAGE_DESCRIPTOR_INVALID');};
|
|
4
|
+
const record=value=>value!==null&&typeof value==='object'&&!Array.isArray(value);
|
|
5
|
+
const exact=(value,keys)=>record(value)&&Object.keys(value).sort().join(',')===keys.split(',').sort().join(',');
|
|
6
|
+
const identifier=value=>typeof value==='string'&&/^[a-z][a-z0-9-]{0,63}$/.test(value);
|
|
7
|
+
export function parseSolutionPackageLimits(value){
|
|
8
|
+
const names=['maximumFiles','maximumFileBytes','maximumTotalBytes','maximumManifestBytes','timeoutMs'];
|
|
9
|
+
if(!value||Object.keys(value).sort().join(',')!==names.sort().join(',')||names.some(key=>!Number.isSafeInteger(value[key])||value[key]<1)||value.maximumFiles>10000||value.maximumFileBytes>134217728||value.maximumTotalBytes>268435456||value.maximumManifestBytes>1048576||value.timeoutMs>300000)throw Error('PUBLISHING_PACKAGE_LIMIT_INVALID');return {...value};
|
|
10
|
+
}
|
|
11
|
+
function entry(value,prefix){
|
|
12
|
+
if(typeof value!=='string'||!value.startsWith(prefix+'/'))invalid();
|
|
13
|
+
try{if(validatePortableRelativePath(value)!==value)invalid();}catch{invalid();}
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
function json(value,depth=0){
|
|
17
|
+
if(depth>32)invalid();
|
|
18
|
+
if(value===null||typeof value==='string'||typeof value==='boolean')return;
|
|
19
|
+
if(typeof value==='number'&&Number.isFinite(value))return;
|
|
20
|
+
if(Array.isArray(value)){for(const item of value)json(item,depth+1);return;}
|
|
21
|
+
if(record(value)){for(const [key,item]of Object.entries(value)){if(['__proto__','prototype','constructor'].includes(key))invalid();json(item,depth+1);}return;}
|
|
22
|
+
invalid();
|
|
23
|
+
}
|
|
24
|
+
/** Domain metadata stays declarative; deployment and credentials are service policy. */
|
|
25
|
+
export function parseSolutionPackageDescriptor(value){
|
|
26
|
+
if(!exact(value,'schemaVersion,solutionId,publisherId,packageName,version,sdkApiVersion,runtime,ui,release')||value.schemaVersion!==1||!identifier(value.solutionId)||!identifier(value.publisherId)||typeof value.packageName!=='string'||!/^@[a-z0-9][a-z0-9.-]{0,63}\/[a-z0-9][a-z0-9.-]{0,63}$/.test(value.packageName)||typeof value.version!=='string'||!/^\d{1,8}\.\d{1,8}\.\d{1,8}$/.test(value.version)||value.sdkApiVersion!=='2.0.0')invalid();
|
|
27
|
+
if(!exact(value.runtime,'entry,protocolVersion,links')||value.runtime.protocolVersion!==2||!Array.isArray(value.runtime.links)||value.runtime.links.length>8192||!exact(value.ui,'entry,bridgeVersion')||value.ui.bridgeVersion!==1)invalid();
|
|
28
|
+
entry(value.runtime.entry,'server');entry(value.ui.entry,'ui');
|
|
29
|
+
for(const link of value.runtime.links){
|
|
30
|
+
if(!exact(link,'path,target')||typeof link.target!=='string'||!link.target||link.target.length>1024||/[\\:\0\r\n]/.test(link.target)||link.target.startsWith('/'))invalid();
|
|
31
|
+
entry(link.path,'server');
|
|
32
|
+
}
|
|
33
|
+
if(!exact(value.release,'permissions,display,queries,operations,capabilities,resourcesDigest')||!/^sha256:[a-f0-9]{64}$/.test(value.release.resourcesDigest??''))invalid();
|
|
34
|
+
json(value);if(new TextEncoder().encode(JSON.stringify(value)).byteLength>262144)invalid();
|
|
35
|
+
return structuredClone(value);
|
|
36
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type {JsonValue} from '@xlinklight/contracts';
|
|
2
|
+
import type {SolutionPackageLimits} from './package.mjs';
|
|
3
|
+
/** Consumer-owned read-only public metadata port. It carries no credentials or
|
|
4
|
+
* command body and does not require the optional platform implementation. */
|
|
5
|
+
export type PublishingMetadataTransport=(address:string,options:{timeoutMs?:number;signal?:AbortSignal})=>Promise<JsonValue>;
|
|
6
|
+
export interface PublishingConfiguration {
|
|
7
|
+
schemaVersion:1;serviceUrl:string;projectId:string;coreOrigin:string;
|
|
8
|
+
publisher:{publisherId:string;keys:{keyId:string;publicKey:string}[]};
|
|
9
|
+
}
|
|
10
|
+
export interface PublishingIntent {
|
|
11
|
+
schemaVersion:1;requestId:string;projectId:string;policyRevision:number;
|
|
12
|
+
package:{solutionId:string;publisherId:string;packageName:string;version:string;content:{manifestSha256:string};fileCount:number;totalBytes:number};
|
|
13
|
+
provenance?:{gitRevision:string};
|
|
14
|
+
}
|
|
15
|
+
export interface PublishingProject {schemaVersion:1;configuration:PublishingConfiguration;policyRevision:number;solutionId:string;packageName:string;limits:SolutionPackageLimits}
|
|
16
|
+
export interface PublishingStatus {
|
|
17
|
+
schemaVersion:1;requestId:string;projectId:string;intentSha256:string;
|
|
18
|
+
state:'uploading'|'queued'|'deploying'|'registered'|'awaiting-acceptance'|'active'|'failed'|'unknown'|'abandoned'|'superseded';
|
|
19
|
+
sideEffects:'none'|'pending'|'unknown'|'closed';
|
|
20
|
+
missingFiles:{path:string;sha256:string;byteLength:number;receivedBytes:number}[];
|
|
21
|
+
activation?:JsonValue;error?:{code:string};
|
|
22
|
+
}
|
|
23
|
+
export function parsePublishingConfiguration(value:unknown,options?:{allowLoopback?:boolean}):PublishingConfiguration;
|
|
24
|
+
export function parsePublishingIntent(value:unknown):PublishingIntent;
|
|
25
|
+
export function parsePublishingProject(value:unknown,options?:{allowLoopback?:boolean}):PublishingProject;
|
|
26
|
+
export function parsePublishingStatus(value:unknown):PublishingStatus;
|
|
27
|
+
export function publishingIntentBytes(value:unknown):Uint8Array;
|
package/src/protocol.mjs
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {validatePortableRelativePath} from '@openge/forge-path-safety';
|
|
2
|
+
import {parseSolutionPackageLimits} from './package.mjs';
|
|
3
|
+
|
|
4
|
+
export const publishingError=code=>Object.assign(Error('PUBLISHING_'+code),{code:'PUBLISHING_'+code});
|
|
5
|
+
const record=value=>value!==null&&typeof value==='object'&&!Array.isArray(value);
|
|
6
|
+
export const protocolRecord=(value,required,optional=[])=>record(value)&&required.every(key=>Object.hasOwn(value,key))&&Object.keys(value).every(key=>required.includes(key)||optional.includes(key));
|
|
7
|
+
export const publishingIdentifier=value=>typeof value==='string'&&/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/.test(value);
|
|
8
|
+
export const publishingDigest=value=>typeof value==='string'&&/^[a-f0-9]{64}$/.test(value);
|
|
9
|
+
export const publishingRequestId=value=>typeof value==='string'&&/^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/.test(value);
|
|
10
|
+
const integer=(value,min,max)=>Number.isSafeInteger(value)&&value>=min&&value<=max;
|
|
11
|
+
function origin(value,allowLoopback){
|
|
12
|
+
if(typeof value!=='string'||value.length>2048)throw publishingError('CONFIGURATION_INVALID');
|
|
13
|
+
let url;try{url=new URL(value);}catch{throw publishingError('CONFIGURATION_INVALID');}
|
|
14
|
+
if(url.origin!==value||url.username||url.password||url.hash||url.search||!(url.protocol==='https:'||allowLoopback===true&&url.protocol==='http:'&&['127.0.0.1','[::1]'].includes(url.hostname)))throw publishingError('CONFIGURATION_INVALID');
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
export function parsePublishingConfiguration(value,{allowLoopback=false}={}){
|
|
18
|
+
if(!protocolRecord(value,['schemaVersion','serviceUrl','projectId','coreOrigin','publisher'])||value.schemaVersion!==1||!publishingIdentifier(value.projectId)||!protocolRecord(value.publisher,['publisherId','keys'])||!publishingIdentifier(value.publisher.publisherId)||!Array.isArray(value.publisher.keys)||value.publisher.keys.length<1||value.publisher.keys.length>8)throw publishingError('CONFIGURATION_INVALID');
|
|
19
|
+
const seen=new Set(),keys=value.publisher.keys.map(key=>{
|
|
20
|
+
if(!protocolRecord(key,['keyId','publicKey'])||!publishingIdentifier(key.keyId)||seen.has(key.keyId)||typeof key.publicKey!=='string'||key.publicKey.length>4096||!/^-----BEGIN PUBLIC KEY-----\n[A-Za-z0-9+/=\n]+\n-----END PUBLIC KEY-----\n?$/.test(key.publicKey))throw publishingError('CONFIGURATION_INVALID');
|
|
21
|
+
seen.add(key.keyId);return {keyId:key.keyId,publicKey:key.publicKey};
|
|
22
|
+
});
|
|
23
|
+
return {schemaVersion:1,serviceUrl:origin(value.serviceUrl,allowLoopback),projectId:value.projectId,coreOrigin:origin(value.coreOrigin,allowLoopback),publisher:{publisherId:value.publisher.publisherId,keys}};
|
|
24
|
+
}
|
|
25
|
+
export function parsePublishingIntent(value){
|
|
26
|
+
if(!protocolRecord(value,['schemaVersion','requestId','projectId','policyRevision','package'],['provenance'])||value.schemaVersion!==1||!publishingRequestId(value.requestId)||!publishingIdentifier(value.projectId)||!integer(value.policyRevision,1,Number.MAX_SAFE_INTEGER))throw publishingError('INTENT_INVALID');
|
|
27
|
+
const item=value.package;
|
|
28
|
+
if(!protocolRecord(item,['solutionId','publisherId','packageName','version','content','fileCount','totalBytes'])||!publishingIdentifier(item.solutionId)||!publishingIdentifier(item.publisherId)||typeof item.packageName!=='string'||!/^@[a-z0-9][a-z0-9.-]{0,63}\/[a-z0-9][a-z0-9.-]{0,63}$/.test(item.packageName)||!/^\d{1,8}\.\d{1,8}\.\d{1,8}$/.test(item.version??'')||!protocolRecord(item.content,['manifestSha256'])||!publishingDigest(item.content.manifestSha256)||!integer(item.fileCount,1,10000)||!integer(item.totalBytes,1,268435456))throw publishingError('INTENT_INVALID');
|
|
29
|
+
let provenance;
|
|
30
|
+
if(value.provenance!==undefined){if(!protocolRecord(value.provenance,['gitRevision'])||!/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(value.provenance.gitRevision??''))throw publishingError('INTENT_INVALID');provenance={gitRevision:value.provenance.gitRevision};}
|
|
31
|
+
return {schemaVersion:1,requestId:value.requestId,projectId:value.projectId,policyRevision:value.policyRevision,package:{solutionId:item.solutionId,publisherId:item.publisherId,packageName:item.packageName,version:item.version,content:{manifestSha256:item.content.manifestSha256},fileCount:item.fileCount,totalBytes:item.totalBytes},...(provenance?{provenance}:{})};
|
|
32
|
+
}
|
|
33
|
+
export function parsePublishingProject(value,{allowLoopback=false}={}){
|
|
34
|
+
if(!protocolRecord(value,['schemaVersion','configuration','policyRevision','solutionId','packageName','limits'])||value.schemaVersion!==1||!integer(value.policyRevision,1,Number.MAX_SAFE_INTEGER)||!publishingIdentifier(value.solutionId)||!/^@[a-z0-9][a-z0-9.-]{0,63}\/[a-z0-9][a-z0-9.-]{0,63}$/.test(value.packageName??''))throw publishingError('PROJECT_INVALID');
|
|
35
|
+
let limits;try{limits=parseSolutionPackageLimits(value.limits);}catch{throw publishingError('PROJECT_INVALID');}
|
|
36
|
+
return {schemaVersion:1,configuration:parsePublishingConfiguration(value.configuration,{allowLoopback}),policyRevision:value.policyRevision,solutionId:value.solutionId,packageName:value.packageName,limits};
|
|
37
|
+
}
|
|
38
|
+
export const publishingIntentBytes=value=>new TextEncoder().encode(JSON.stringify(parsePublishingIntent(value)));
|
|
39
|
+
export function parsePublishingStatus(value){
|
|
40
|
+
if(!protocolRecord(value,['schemaVersion','requestId','projectId','intentSha256','state','sideEffects','missingFiles'],['activation','error'])||value.schemaVersion!==1||!publishingRequestId(value.requestId)||!publishingIdentifier(value.projectId)||!publishingDigest(value.intentSha256)||!['uploading','queued','deploying','registered','awaiting-acceptance','active','failed','unknown','abandoned','superseded'].includes(value.state)||!['none','pending','unknown','closed'].includes(value.sideEffects)||!Array.isArray(value.missingFiles)||value.missingFiles.length>10000)throw publishingError('STATUS_INVALID');
|
|
41
|
+
const names=new Set(),missingFiles=value.missingFiles.map(file=>{
|
|
42
|
+
if(!protocolRecord(file,['path','sha256','byteLength','receivedBytes'])||!publishingDigest(file.sha256)||!integer(file.byteLength,0,134217728)||!integer(file.receivedBytes,0,file.byteLength))throw publishingError('STATUS_INVALID');
|
|
43
|
+
let relative;try{relative=validatePortableRelativePath(file.path);}catch{throw publishingError('STATUS_INVALID');}
|
|
44
|
+
if(names.has(relative))throw publishingError('STATUS_INVALID');names.add(relative);return {path:relative,sha256:file.sha256,byteLength:file.byteLength,receivedBytes:file.receivedBytes};
|
|
45
|
+
});
|
|
46
|
+
if(value.state==='active'&&(!value.activation||value.sideEffects!=='closed'||missingFiles.length))throw publishingError('STATUS_INVALID');
|
|
47
|
+
if(value.activation!==undefined&&(!record(value.activation)||new TextEncoder().encode(JSON.stringify(value.activation)).byteLength>1048576))throw publishingError('STATUS_INVALID');
|
|
48
|
+
if(value.error!==undefined&&(!protocolRecord(value.error,['code'])||typeof value.error.code!=='string'||!/^[A-Z][A-Z0-9_]{1,95}$/.test(value.error.code)))throw publishingError('STATUS_INVALID');
|
|
49
|
+
return {schemaVersion:1,requestId:value.requestId,projectId:value.projectId,intentSha256:value.intentSha256,state:value.state,sideEffects:value.sideEffects,missingFiles,...(value.activation!==undefined?{activation:structuredClone(value.activation)}:{}),...(value.error?{error:{code:value.error.code}}:{})};
|
|
50
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type {SolutionReleaseManifest,Digest} from '@xlinklight/contracts';
|
|
2
|
+
export interface PublishingActivation {
|
|
3
|
+
payload:{schemaVersion:1;projectId:string;requestId:string;policyRevision:number;configurationSha256:string;intentSha256:string;releaseDigest:Digest;acceptanceReceiptSha256:string};
|
|
4
|
+
manifest:SolutionReleaseManifest;signature:{keyId:string;algorithm:'Ed25519';value:string};
|
|
5
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {createHash,createPrivateKey,createPublicKey,sign,verify} from 'node:crypto';
|
|
2
|
+
import {parsePublishingConfiguration,parsePublishingIntent,publishingIntentBytes,protocolRecord,publishingDigest,publishingIdentifier,publishingError} from '../protocol.mjs';
|
|
3
|
+
|
|
4
|
+
export function createPublishingActivationFunctions(loadDomain){
|
|
5
|
+
const fail=code=>publishingError('ACTIVATION_'+code),hash=value=>createHash('sha256').update(value).digest('hex');
|
|
6
|
+
const payloadKeys=['schemaVersion','projectId','requestId','policyRevision','configurationSha256','intentSha256','releaseDigest','acceptanceReceiptSha256'];
|
|
7
|
+
const signatureKeys=['keyId','algorithm','value'];
|
|
8
|
+
async function domain(){
|
|
9
|
+
let sdk;try{sdk=await loadDomain();}catch{throw fail('SDK_REQUIRED');}
|
|
10
|
+
if(['publicPublisherMetadata','verifySolutionRelease','releasePayload','canonicalMetadata','metadataDigest','resolveApprovedIndependentRelease'].some(name=>typeof sdk[name]!=='function'))throw fail('SDK_REQUIRED');return sdk;
|
|
11
|
+
}
|
|
12
|
+
function context(input){
|
|
13
|
+
const configuration=parsePublishingConfiguration(input.configuration,{allowLoopback:input.allowLoopback===true}),intent=parsePublishingIntent(input.intent);
|
|
14
|
+
if(intent.projectId!==configuration.projectId||intent.package.publisherId!==configuration.publisher.publisherId)throw fail('BINDING_INVALID');return {configuration,intent};
|
|
15
|
+
}
|
|
16
|
+
function manifestInput(value,sdk,configuration,intent){
|
|
17
|
+
try{
|
|
18
|
+
const publisher=sdk.publicPublisherMetadata({...configuration.publisher,enabled:true,serverOrigins:[new URL(value.server.url).origin],uiOrigins:[new URL(value.ui.url).origin]}),manifest=sdk.verifySolutionRelease(value,publisher);
|
|
19
|
+
if(['solutionId','publisherId','version'].some(name=>manifest[name]!==intent.package[name]))throw Error();return {manifest,publisher};
|
|
20
|
+
}catch{throw fail('MANIFEST_INVALID');}
|
|
21
|
+
}
|
|
22
|
+
function payloadFor(configuration,intent,releaseDigest,acceptanceReceiptSha256){
|
|
23
|
+
if(!publishingDigest(acceptanceReceiptSha256))throw fail('INVALID');
|
|
24
|
+
return {schemaVersion:1,projectId:intent.projectId,requestId:intent.requestId,policyRevision:intent.policyRevision,configurationSha256:hash(JSON.stringify(configuration)),intentSha256:hash(publishingIntentBytes(intent)),releaseDigest,acceptanceReceiptSha256};
|
|
25
|
+
}
|
|
26
|
+
const signedBytes=(payload,sdk)=>Buffer.from('link-light.publishing.activation.v1\n'+sdk.metadataDigest(payload));
|
|
27
|
+
async function approved({sdk,configuration,manifest,publisher,metadataTransport,signal}){
|
|
28
|
+
try{return await sdk.resolveApprovedIndependentRelease({coreOrigin:configuration.coreOrigin,candidate:{payload:sdk.releasePayload(manifest),releaseDigest:manifest.releaseDigest,publisher},...(metadataTransport?{transport:metadataTransport}:{}),signal});}
|
|
29
|
+
catch{throw fail('ADMISSION_REQUIRED');}
|
|
30
|
+
}
|
|
31
|
+
function snapshot(value){
|
|
32
|
+
try{const encoded=JSON.stringify(value);if(typeof encoded!=='string'||encoded.length>1048576||Buffer.byteLength(encoded)>1048576)throw Error();return JSON.parse(encoded);}catch{throw fail('INVALID');}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The signing owner calls this only after actual owned acceptance and closed
|
|
36
|
+
* effects. Its receipt digest binds evidence; the constructor does not run it. */
|
|
37
|
+
async function createPublishingActivation(input){
|
|
38
|
+
input.signal?.throwIfAborted();const {configuration,intent}=context(input),value=snapshot(input.manifest),sdk=await domain(),{manifest,publisher}=manifestInput(value,sdk,configuration,intent),payload=payloadFor(configuration,intent,manifest.releaseDigest,input.acceptanceReceiptSha256);
|
|
39
|
+
const selected=configuration.publisher.keys.find(key=>key.keyId===input.keyId);let key;
|
|
40
|
+
try{
|
|
41
|
+
if(!selected||typeof input.privateKey!=='string'||input.privateKey.length>8192)throw Error();key=createPrivateKey(input.privateKey);
|
|
42
|
+
if(key.asymmetricKeyType!=='ed25519'||createPublicKey(key).export({type:'spki',format:'pem'}).toString()!==createPublicKey(selected.publicKey).export({type:'spki',format:'pem'}).toString())throw Error();
|
|
43
|
+
}catch{throw fail('SIGNATURE_INVALID');}
|
|
44
|
+
await approved({sdk,configuration,manifest,publisher,metadataTransport:input.metadataTransport,signal:input.signal});input.signal?.throwIfAborted();
|
|
45
|
+
const activation={payload,manifest,signature:{keyId:input.keyId,algorithm:'Ed25519',value:sign(null,signedBytes(payload,sdk),key).toString('base64url')}};return snapshot(activation);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Authenticate original intent/content/trust, then re-read current Core trust
|
|
49
|
+
* and admission. An earlier signature never substitutes for current approval. */
|
|
50
|
+
async function verifyPublishingActivation(input){
|
|
51
|
+
input.signal?.throwIfAborted();const {configuration,intent}=context(input),activation=snapshot(input.activation);
|
|
52
|
+
if(!protocolRecord(activation,['payload','manifest','signature'])||!protocolRecord(activation.payload,payloadKeys)||activation.payload.schemaVersion!==1||!protocolRecord(activation.signature,signatureKeys)||!publishingIdentifier(activation.signature.keyId)||activation.signature.algorithm!=='Ed25519'||!/^[A-Za-z0-9_-]{86}$/.test(activation.signature.value??''))throw fail('INVALID');
|
|
53
|
+
const sdk=await domain(),expected=payloadFor(configuration,intent,activation.manifest?.releaseDigest,activation.payload.acceptanceReceiptSha256);
|
|
54
|
+
if(sdk.canonicalMetadata(expected)!==sdk.canonicalMetadata(activation.payload))throw fail('BINDING_INVALID');
|
|
55
|
+
const key=configuration.publisher.keys.find(key=>key.keyId===activation.signature.keyId);
|
|
56
|
+
try{
|
|
57
|
+
const signature=Buffer.from(activation.signature.value,'base64url'),publicKey=key&&createPublicKey(key.publicKey);
|
|
58
|
+
if(!publicKey||publicKey.asymmetricKeyType!=='ed25519'||signature.toString('base64url')!==activation.signature.value||!verify(null,signedBytes(activation.payload,sdk),publicKey,signature))throw Error();
|
|
59
|
+
}catch{throw fail('SIGNATURE_INVALID');}
|
|
60
|
+
const {manifest,publisher}=manifestInput(activation.manifest,sdk,configuration,intent),accepted=await approved({sdk,configuration,manifest,publisher,metadataTransport:input.metadataTransport,signal:input.signal});input.signal?.throwIfAborted();
|
|
61
|
+
return {manifest:accepted.manifest,acceptanceReceiptSha256:activation.payload.acceptanceReceiptSha256};
|
|
62
|
+
}
|
|
63
|
+
return {createPublishingActivation,verifyPublishingActivation};
|
|
64
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type {SolutionReleaseManifest} from '@xlinklight/contracts';
|
|
2
|
+
import type {PublishingMetadataTransport,PublishingConfiguration,PublishingIntent} from '../protocol.mjs';
|
|
3
|
+
import type {PublishingActivation} from '../shared/activation.mjs';
|
|
4
|
+
export type {PublishingActivation} from '../shared/activation.mjs';
|
|
5
|
+
interface ActivationContext {configuration:PublishingConfiguration;intent:PublishingIntent;allowLoopback?:boolean;metadataTransport:PublishingMetadataTransport;signal?:AbortSignal}
|
|
6
|
+
export function createPublishingActivation(input:ActivationContext&{manifest:SolutionReleaseManifest;acceptanceReceiptSha256:string;keyId:string;privateKey:string}):Promise<PublishingActivation>;
|
|
7
|
+
export function verifyPublishingActivation(input:ActivationContext&{activation:unknown}):Promise<{manifest:Readonly<SolutionReleaseManifest>;acceptanceReceiptSha256:string}>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import {publicPublisherMetadata,verifySolutionRelease,releasePayload,canonicalMetadata,metadataDigest,resolveApprovedIndependentRelease} from '@xlinklight/platform/worker';
|
|
2
|
+
import {createPublishingActivationFunctions} from '../shared/activation.mjs';
|
|
3
|
+
const helpers=createPublishingActivationFunctions(async()=>({publicPublisherMetadata,verifySolutionRelease,releasePayload,canonicalMetadata,metadataDigest,resolveApprovedIndependentRelease}));
|
|
4
|
+
export const {createPublishingActivation,verifyPublishingActivation}=helpers;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export {openPreparedPublishingPackage,publishingChunkBytes,publishingReadFileBytes} from './package.mjs';
|
|
2
|
+
export {createPublishingService,configurePublishingProject,createPublishingWorker} from './service.mjs';
|
|
3
|
+
export {openPublishingDurableJournal} from './journal.mjs';
|
|
4
|
+
export {createPublishingDurableRuntime} from './runtime.mjs';
|
|
5
|
+
export {preparePublishingRelease} from './release.mjs';
|
|
6
|
+
export {createPublishingActivation,verifyPublishingActivation} from './activation.mjs';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type {JsonValue} from '@xlinklight/contracts';
|
|
2
|
+
import type {ArtifactOperationJournal,ArtifactTransportClosure} from '@openge/forge-artifact-publish';
|
|
3
|
+
export interface PublishingDurableStorage {readonly sql:{readonly databaseSize:number;exec(query:string,...values:(string|number|ArrayBuffer|null)[]):{toArray():Record<string,unknown>[]}};transactionSync<T>(work:()=>T):T;sync():Promise<void>}
|
|
4
|
+
export interface PublishingDurableLimits {maximumBytes:number;maximumRecords:number;maximumRecordBytes:number;maximumBlobs:number;maximumBlobBytes:number;recoveryReserveBytes:number}
|
|
5
|
+
export interface PublishingDispatch {projectId:string;requestId:string;mode:'perform'|'observe';continue:boolean;acceptanceReceipt?:true}
|
|
6
|
+
export interface PublishingQueueLease extends PublishingDispatch {revision:number;observations:number}
|
|
7
|
+
export interface PublishingMutationAuthority {kind:'configure'|'request'|'worker';projectId:string;requestId?:string;policyRevision?:number;credentialSha256?:string;revision?:number;owner?:string;mode?:'perform'|'observe'}
|
|
8
|
+
export interface PublishingDurableJournal {
|
|
9
|
+
recordCapacity():{used:number;maximum:number};
|
|
10
|
+
load(key:string,options?:{signal?:AbortSignal}):Promise<{revision:number;payload:JsonValue}|undefined>;
|
|
11
|
+
readBlob(input:{sha256:string;byteLength:number},options?:{signal?:AbortSignal}):Promise<Uint8Array|undefined>;
|
|
12
|
+
compareAndSet(input:{key:string;expectedRevision:number;payload:JsonValue;blobs?:readonly {sha256:string;bytes:Uint8Array}[]},options?:{signal?:AbortSignal;authority?:PublishingMutationAuthority;dispatch?:PublishingDispatch}):Promise<'stored'|'conflict'>;
|
|
13
|
+
operationJournal():ArtifactOperationJournal;
|
|
14
|
+
enqueue(input:PublishingDispatch,options?:{signal?:AbortSignal;authority?:PublishingMutationAuthority}):Promise<void>;
|
|
15
|
+
nextWake():number|null;take():Promise<PublishingQueueLease|null>;
|
|
16
|
+
finish(job:PublishingQueueLease,options?:{again?:boolean;delayMs?:number;mode?:'perform'|'observe';advance?:boolean;observations?:number}):Promise<void>;
|
|
17
|
+
withIngress<T>(work:()=>Promise<T>):Promise<T>;
|
|
18
|
+
withProjectLock<T>(input:{projectId:string;requestId:string;mode?:'perform'|'observe';signal?:AbortSignal},work:(lease:{signal:AbortSignal;assertHeld():Promise<void>;beginOperation():void;confirmClosure(closure:ArtifactTransportClosure|undefined):void})=>Promise<T>):Promise<T>;
|
|
19
|
+
readonly blocked:boolean;readonly running:boolean;close():void;
|
|
20
|
+
}
|
|
21
|
+
export function openPublishingDurableJournal(input:{storage:PublishingDurableStorage;identity:string;limits:PublishingDurableLimits;now?:()=>number;leaseMs?:number;increaseMaximumRecordsTo?:number}):Promise<PublishingDurableJournal>;
|