@xlinklight/publishing 3.3.1 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -2
- package/dist/src/acceptance-delivery-binding.d.ts +20 -0
- package/dist/src/acceptance.d.ts +49 -0
- package/dist/src/client.d.ts +71 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/node/acceptance-delivery.d.ts +34 -0
- package/dist/src/node/activation.d.ts +5 -0
- package/dist/src/node/authorization.d.ts +31 -0
- package/dist/src/node/cli.d.ts +2 -0
- package/dist/src/node/cli.js +4 -2
- package/dist/src/node/index.d.ts +20 -0
- package/dist/src/node/index.js +2 -0
- package/dist/src/node/journal-directory.d.ts +2 -0
- package/dist/src/node/journal-directory.js +121 -0
- package/dist/src/node/journal.d.ts +49 -0
- package/dist/src/node/journal.js +6 -8
- package/dist/src/node/local-json-file.d.ts +3 -0
- package/dist/src/node/local-json-file.js +49 -0
- package/dist/src/node/publishing-command.d.ts +46 -0
- package/dist/src/node/publishing-command.js +64 -16
- package/dist/src/node/session.d.ts +95 -0
- package/dist/src/node/solution-package.d.ts +55 -0
- package/dist/src/node/source-error.d.ts +10 -0
- package/dist/src/node/source-producer.d.ts +5 -0
- package/dist/src/node/terminal-network.d.ts +23 -0
- package/dist/src/node/terminal-network.js +122 -0
- package/dist/src/node/workflow.d.ts +74 -0
- package/dist/src/node/workflow.js +46 -34
- package/dist/src/package.d.ts +38 -0
- package/dist/src/protocol.d.ts +83 -0
- package/dist/src/protocol.js +1 -1
- package/dist/src/shared/activation-types.d.ts +37 -0
- package/dist/src/shared/activation-types.js +1 -0
- package/dist/src/shared/activation.d.ts +17 -0
- package/dist/src/shared/records.d.ts +10 -0
- package/dist/src/shared/release-version.d.ts +4 -0
- package/dist/src/shared/release-version.js +15 -0
- package/dist/src/worker/activation.d.ts +12 -0
- package/dist/src/worker/activation.js +2 -1
- package/dist/src/worker/durable-retention.d.ts +9 -0
- package/dist/src/worker/durable-retention.js +96 -0
- package/dist/src/worker/index.d.ts +12 -0
- package/dist/src/worker/index.js +1 -0
- package/dist/src/worker/journal.d.ts +129 -0
- package/dist/src/worker/journal.js +33 -6
- package/dist/src/worker/package.d.ts +60 -0
- package/dist/src/worker/release-retention.d.ts +34 -0
- package/dist/src/worker/release-retention.js +27 -0
- package/dist/src/worker/release.d.ts +22 -0
- package/dist/src/worker/runtime.d.ts +47 -0
- package/dist/src/worker/service.d.ts +128 -0
- package/dist/src/worker/service.js +38 -12
- package/package.json +13 -7
- package/types/acceptance.d.ts +0 -24
- package/types/client.d.ts +0 -16
- package/types/index.d.ts +0 -6
- package/types/node/acceptance-delivery.d.ts +0 -11
- package/types/node/activation.d.ts +0 -8
- package/types/node/authorization.d.ts +0 -8
- package/types/node/index.d.ts +0 -17
- package/types/node/journal.d.ts +0 -13
- package/types/node/publishing-command.d.ts +0 -20
- package/types/node/session.d.ts +0 -25
- package/types/node/solution-package.d.ts +0 -15
- package/types/node/source-error.d.ts +0 -5
- package/types/node/workflow.d.ts +0 -37
- package/types/package.d.ts +0 -11
- package/types/protocol.d.ts +0 -27
- package/types/shared/activation.d.ts +0 -5
- package/types/worker/activation.d.ts +0 -7
- package/types/worker/index.d.ts +0 -6
- package/types/worker/journal.d.ts +0 -21
- package/types/worker/package.d.ts +0 -16
- package/types/worker/release.d.ts +0 -7
- package/types/worker/runtime.d.ts +0 -4
- package/types/worker/service.d.ts +0 -41
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Readable } from 'node:stream';
|
|
2
|
+
import type { DurableArtifactFilesystem } from '@openge/forge-generated-artifacts/node';
|
|
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
|
+
export interface PublishingCommandOptions {
|
|
8
|
+
cwd?: string;
|
|
9
|
+
stdin?: Readable & {
|
|
10
|
+
isTTY?: boolean;
|
|
11
|
+
};
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
filesystem?: DurableArtifactFilesystem;
|
|
14
|
+
journalLimits?: PublishingJournalLimits;
|
|
15
|
+
credentialInputTimeoutMilliseconds?: number;
|
|
16
|
+
allowLoopback?: boolean;
|
|
17
|
+
request?: typeof fetch;
|
|
18
|
+
clientLimits?: PublishingClientLimits;
|
|
19
|
+
metadataTransport?: ReleaseMetadataTransport;
|
|
20
|
+
operationLimits?: {
|
|
21
|
+
timeoutMilliseconds: number;
|
|
22
|
+
closeTimeoutMilliseconds: number;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export interface PublishingCommandResult {
|
|
26
|
+
/** 0: completed local action or verified active; 1: refused/failed;
|
|
27
|
+
* 2: unsupported arguments; 3: observed pending/non-active work. */
|
|
28
|
+
exitCode: number;
|
|
29
|
+
output: PublishingWorkflowResult | {
|
|
30
|
+
error: {
|
|
31
|
+
code: string;
|
|
32
|
+
};
|
|
33
|
+
} | {
|
|
34
|
+
state: string;
|
|
35
|
+
projectId: string;
|
|
36
|
+
policyRevision: number;
|
|
37
|
+
} | {
|
|
38
|
+
commands: string[];
|
|
39
|
+
sourceProducer: string;
|
|
40
|
+
stateDirectory: string;
|
|
41
|
+
publishWaitMs: number;
|
|
42
|
+
publishOptions: string[];
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export declare function runPublishingCommand(args: readonly string[], options?: PublishingCommandOptions): Promise<PublishingCommandResult>;
|
|
46
|
+
export declare function runPublishingTerminalCommand(args: string[], signal: AbortSignal, proxy?: string): ReturnType<typeof runPublishingCommand>;
|
|
@@ -3,12 +3,14 @@ import path from 'node:path';
|
|
|
3
3
|
import { createLinuxDurableArtifactFilesystem, createWindowsNtfsDurableArtifactFilesystem } from '@openge/forge-generated-artifacts/node';
|
|
4
4
|
import { validatePortableRelativePath } from '@openge/forge-path-safety';
|
|
5
5
|
import { parsePublishingConfiguration, protocolRecord, publishingError, publishingRequestId } from '../protocol.js';
|
|
6
|
-
import { openPublishingJournal } from './journal.js';
|
|
6
|
+
import { openPublishingCredentialJournal, openPublishingJournal } from './journal.js';
|
|
7
7
|
import { installPublishingAuthorization, loadPublishingAuthorization } from './authorization.js';
|
|
8
8
|
import { createPublishingWorkflow } from './workflow.js';
|
|
9
9
|
import { defaultProducer } from './source-producer.js';
|
|
10
10
|
import { parseAcceptanceDeliveryCredential } from './acceptance-delivery.js';
|
|
11
11
|
import { errorCode, objectRecord } from '../shared/records.js';
|
|
12
|
+
import { openPublishingTerminalNetwork } from './terminal-network.js';
|
|
13
|
+
import { isAbsoluteLocalFile, readLocalJsonFile } from './local-json-file.js';
|
|
12
14
|
const commands = ['credentials', 'check', 'publish', 'status', 'recover', 'verify', 'abandon'];
|
|
13
15
|
const journalLimits = Object.freeze({ maximumBytes: 536870912, maximumRecords: 256, maximumRecordBytes: 1048576, maximumBlobs: 12000, maximumBlobBytes: 134217728, minimumFreeBytes: 67108864 });
|
|
14
16
|
const fail = (code) => publishingError(code);
|
|
@@ -32,6 +34,12 @@ function parse(args) {
|
|
|
32
34
|
throw fail('CLI_ARGUMENT_INVALID');
|
|
33
35
|
selected[flag === '--root' ? 'root' : flag === '--state' ? 'state' : 'producer'] = value;
|
|
34
36
|
}
|
|
37
|
+
else if (flag === '--delivery-credential-file' && command === 'credentials') {
|
|
38
|
+
const value = args[++index];
|
|
39
|
+
if (!value || !isAbsoluteLocalFile(value))
|
|
40
|
+
throw fail('CLI_ARGUMENT_INVALID');
|
|
41
|
+
selected.deliveryCredentialFile = value;
|
|
42
|
+
}
|
|
35
43
|
else if (flag === '--stdin' && command === 'credentials')
|
|
36
44
|
selected.stdin = true;
|
|
37
45
|
else if (flag === '--no-wait' && command === 'publish')
|
|
@@ -147,12 +155,30 @@ function diagnostic(error) {
|
|
|
147
155
|
}
|
|
148
156
|
/** Bounded one-shot CLI. No token, private producer cause, provider output or
|
|
149
157
|
* environment is returned. Callers own private storage ACLs and backup policy. */
|
|
150
|
-
async function executeCommand(selected, options) {
|
|
151
|
-
let journal;
|
|
158
|
+
async function executeCommand(selected, options, terminal) {
|
|
159
|
+
let journal, network;
|
|
152
160
|
try {
|
|
153
161
|
const { signal, allowLoopback = false, request, clientLimits, metadataTransport } = options;
|
|
154
162
|
const raw = selected.command === 'credentials' ? await credentialInput(options.stdin ?? process.stdin, signal, options.credentialInputTimeoutMilliseconds ?? 30000) : undefined;
|
|
155
|
-
|
|
163
|
+
let input;
|
|
164
|
+
if (raw) {
|
|
165
|
+
const configuration = parsePublishingConfiguration(raw.configuration, { allowLoopback });
|
|
166
|
+
let acceptanceDelivery;
|
|
167
|
+
if (selected.deliveryCredentialFile) {
|
|
168
|
+
if (raw.acceptanceDelivery !== undefined)
|
|
169
|
+
throw fail('CREDENTIAL_DELIVERY_SOURCE_CONFLICT');
|
|
170
|
+
try {
|
|
171
|
+
acceptanceDelivery = parseAcceptanceDeliveryCredential(await readLocalJsonFile(selected.deliveryCredentialFile, 16384, signal));
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
throw fail(signal?.aborted ? 'CREDENTIAL_INPUT_CANCELLED' : 'CREDENTIAL_DELIVERY_FILE_INVALID');
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else if (raw.acceptanceDelivery !== undefined) {
|
|
178
|
+
acceptanceDelivery = parseAcceptanceDeliveryCredential(raw.acceptanceDelivery);
|
|
179
|
+
}
|
|
180
|
+
input = { configuration, credential: raw.credential, ...(acceptanceDelivery ? { acceptanceDelivery } : {}) };
|
|
181
|
+
}
|
|
156
182
|
signal?.throwIfAborted();
|
|
157
183
|
const root = path.resolve(options.cwd ?? process.cwd(), selected.root ?? '.'), info = await fs.lstat(root);
|
|
158
184
|
if (!info.isDirectory() || info.isSymbolicLink() || await fs.realpath(root) !== root)
|
|
@@ -160,18 +186,33 @@ async function executeCommand(selected, options) {
|
|
|
160
186
|
const filesystem = options.filesystem ?? await (process.platform === 'win32' ? createWindowsNtfsDurableArtifactFilesystem() : process.platform === 'linux' ? createLinuxDurableArtifactFilesystem() : Promise.reject(fail('CLI_PLATFORM_UNSUPPORTED')));
|
|
161
187
|
if (!filesystem)
|
|
162
188
|
throw fail('CLI_PLATFORM_UNSUPPORTED');
|
|
163
|
-
|
|
164
|
-
|
|
189
|
+
const directory = selected.state ?? 'state/solution-publishing';
|
|
190
|
+
if (!input) {
|
|
191
|
+
try {
|
|
192
|
+
await fs.lstat(path.join(root, directory, 'owner.json'));
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
if (errorCode(error) === 'ENOENT')
|
|
196
|
+
throw fail('CREDENTIAL_REQUIRED');
|
|
197
|
+
throw error;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const opener = input ? openPublishingCredentialJournal : openPublishingJournal;
|
|
201
|
+
journal = await opener({ root, directory, filesystem, limits: options.journalLimits ?? journalLimits, signal });
|
|
202
|
+
const authorization = input ?? await loadPublishingAuthorization({ journal, allowLoopback, signal });
|
|
203
|
+
if (!authorization)
|
|
204
|
+
throw fail('CREDENTIAL_REQUIRED');
|
|
205
|
+
if (terminal)
|
|
206
|
+
network = await openPublishingTerminalNetwork({ serviceUrl: authorization.configuration.serviceUrl, coreOrigin: authorization.configuration.coreOrigin, deliveryOrigin: authorization.acceptanceDelivery?.origin }, { proxy: terminal.proxy, signal });
|
|
207
|
+
const selectedRequest = request ?? network?.request, selectedMetadata = metadataTransport ?? network?.metadataTransport;
|
|
208
|
+
const shared = { journal, allowLoopback, ...(selectedRequest ? { request: selectedRequest } : {}), ...(clientLimits ? { clientLimits } : {}), signal };
|
|
165
209
|
if (selected.command === 'credentials') {
|
|
166
210
|
if (!input)
|
|
167
211
|
throw fail('CREDENTIAL_INPUT_INVALID');
|
|
168
|
-
const installed = await installPublishingAuthorization({ ...shared,
|
|
212
|
+
const installed = await installPublishingAuthorization({ ...shared, ...authorization, replaceCredential: selected.replaceCredential === true });
|
|
169
213
|
return { exitCode: 0, output: { state: installed.status.toLowerCase(), projectId: installed.projectId, policyRevision: installed.policyRevision } };
|
|
170
214
|
}
|
|
171
|
-
const
|
|
172
|
-
if (!authorization)
|
|
173
|
-
throw fail('CREDENTIAL_REQUIRED');
|
|
174
|
-
const workflow = createPublishingWorkflow({ ...shared, ...authorization, root, ...(metadataTransport ? { metadataTransport } : {}), ...(options.operationLimits ? { operationLimits: options.operationLimits } : {}) });
|
|
215
|
+
const workflow = createPublishingWorkflow({ ...shared, ...authorization, root, ...(selectedMetadata ? { metadataTransport: selectedMetadata } : {}), ...(options.operationLimits ? { operationLimits: options.operationLimits } : {}) });
|
|
175
216
|
let result;
|
|
176
217
|
try {
|
|
177
218
|
result = await workflow[selected.command]({ signal, ...(selected.producer ? { producer: selected.producer } : {}), ...(selected.newPreparation ? { newPreparation: true } : {}), ...(selected.command === 'publish' ? { waitMs: selected.waitMs ?? 300000 } : {}) });
|
|
@@ -194,14 +235,19 @@ async function executeCommand(selected, options) {
|
|
|
194
235
|
}
|
|
195
236
|
finally {
|
|
196
237
|
try {
|
|
197
|
-
|
|
238
|
+
await network?.close();
|
|
198
239
|
}
|
|
199
|
-
|
|
200
|
-
|
|
240
|
+
finally {
|
|
241
|
+
try {
|
|
242
|
+
journal?.close();
|
|
243
|
+
}
|
|
244
|
+
catch {
|
|
245
|
+
throw fail('JOURNAL_CLOSURE_UNKNOWN');
|
|
246
|
+
}
|
|
201
247
|
}
|
|
202
248
|
}
|
|
203
249
|
}
|
|
204
|
-
|
|
250
|
+
async function runCommand(args, options, terminal) {
|
|
205
251
|
let selected;
|
|
206
252
|
try {
|
|
207
253
|
selected = parse(args);
|
|
@@ -212,9 +258,11 @@ export async function runPublishingCommand(args, options = {}) {
|
|
|
212
258
|
if (selected.command === 'help')
|
|
213
259
|
return { exitCode: 0, output: { commands, sourceProducer: defaultProducer, stateDirectory: 'state/solution-publishing', publishWaitMs: 300000, publishOptions: ['--no-wait', '--wait-ms <1..3600000>'] } };
|
|
214
260
|
try {
|
|
215
|
-
return await executeCommand(selected, options);
|
|
261
|
+
return await executeCommand(selected, options, terminal);
|
|
216
262
|
}
|
|
217
263
|
catch (error) {
|
|
218
264
|
return { exitCode: 1, output: diagnostic(error) };
|
|
219
265
|
}
|
|
220
266
|
}
|
|
267
|
+
export function runPublishingCommand(args, options = {}) { return runCommand(args, options); }
|
|
268
|
+
export function runPublishingTerminalCommand(args, signal, proxy) { return runCommand(args, { signal }, { proxy }); }
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { ArtifactOperationOptions, ArtifactOperationReceipt } from '@openge/forge-artifact-publish';
|
|
2
|
+
import type { PublishingClientOptions } from '../client.js';
|
|
3
|
+
import type { PublishingConfiguration, PublishingIntent, PublishingStatus } from '../protocol.js';
|
|
4
|
+
import type { PreparedSolutionPackage, SolutionPackageLimits } from './solution-package.js';
|
|
5
|
+
import type { AcceptanceArchive, AcceptanceArchiveIdentity } from './acceptance-delivery.js';
|
|
6
|
+
import type { PublishingJournal } from './journal.js';
|
|
7
|
+
export interface PublishingSessionResult {
|
|
8
|
+
receipt: ArtifactOperationReceipt;
|
|
9
|
+
status?: PublishingStatus;
|
|
10
|
+
}
|
|
11
|
+
export interface PublishingSession {
|
|
12
|
+
freeze(input: {
|
|
13
|
+
intent: PublishingIntent;
|
|
14
|
+
prepared: Pick<PreparedSolutionPackage, 'files' | 'manifestBytes'>;
|
|
15
|
+
acceptanceArchive?: AcceptanceArchive;
|
|
16
|
+
acceptanceTarget?: {
|
|
17
|
+
origin: string;
|
|
18
|
+
keyId: string;
|
|
19
|
+
publicKeySha256: string;
|
|
20
|
+
};
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
}): Promise<{
|
|
23
|
+
requestId: string;
|
|
24
|
+
content: {
|
|
25
|
+
manifestSha256: string;
|
|
26
|
+
};
|
|
27
|
+
}>;
|
|
28
|
+
readAcceptanceArchive(input: {
|
|
29
|
+
requestId: string;
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
}): Promise<{
|
|
32
|
+
intent: PublishingIntent;
|
|
33
|
+
archive: AcceptanceArchiveIdentity;
|
|
34
|
+
bytes: Uint8Array;
|
|
35
|
+
} | undefined>;
|
|
36
|
+
acceptanceMetadata(input: {
|
|
37
|
+
requestId: string;
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
}): Promise<{
|
|
40
|
+
intent: PublishingIntent;
|
|
41
|
+
archive: AcceptanceArchiveIdentity;
|
|
42
|
+
} | undefined>;
|
|
43
|
+
read(input: {
|
|
44
|
+
requestId: string;
|
|
45
|
+
signal?: AbortSignal;
|
|
46
|
+
}): Promise<{
|
|
47
|
+
intent: PublishingIntent;
|
|
48
|
+
prepared: PreparedSolutionPackage;
|
|
49
|
+
}>;
|
|
50
|
+
create(input: {
|
|
51
|
+
requestId: string;
|
|
52
|
+
attempt?: number;
|
|
53
|
+
signal?: AbortSignal;
|
|
54
|
+
}): Promise<PublishingSessionResult>;
|
|
55
|
+
observe(input: {
|
|
56
|
+
requestId: string;
|
|
57
|
+
stage?: 'create' | 'commit';
|
|
58
|
+
attempt?: number;
|
|
59
|
+
signal?: AbortSignal;
|
|
60
|
+
}): Promise<PublishingSessionResult>;
|
|
61
|
+
upload(input: {
|
|
62
|
+
requestId: string;
|
|
63
|
+
signal?: AbortSignal;
|
|
64
|
+
}): Promise<PublishingStatus>;
|
|
65
|
+
queue(input: {
|
|
66
|
+
requestId: string;
|
|
67
|
+
signal?: AbortSignal;
|
|
68
|
+
}): Promise<PublishingSessionResult>;
|
|
69
|
+
/** Source-free controls use the immutable original intent, without reading payload blobs. */
|
|
70
|
+
status(input: {
|
|
71
|
+
requestId: string;
|
|
72
|
+
signal?: AbortSignal;
|
|
73
|
+
}): Promise<PublishingStatus>;
|
|
74
|
+
resume(input: {
|
|
75
|
+
requestId: string;
|
|
76
|
+
signal?: AbortSignal;
|
|
77
|
+
}): Promise<PublishingStatus>;
|
|
78
|
+
recover(input: {
|
|
79
|
+
requestId: string;
|
|
80
|
+
signal?: AbortSignal;
|
|
81
|
+
}): Promise<PublishingStatus>;
|
|
82
|
+
abandon(input: {
|
|
83
|
+
requestId: string;
|
|
84
|
+
signal?: AbortSignal;
|
|
85
|
+
}): Promise<PublishingStatus>;
|
|
86
|
+
}
|
|
87
|
+
/** A project session holds no deployment-provider credential and never evaluates payloads. */
|
|
88
|
+
export declare function createPublishingSession({ journal, configuration, credential, allowLoopback, request, clientLimits, verifyActivation, packageLimits, pathCaseSensitivity, operationLimits }: Omit<PublishingClientOptions, 'limits'> & {
|
|
89
|
+
journal: PublishingJournal;
|
|
90
|
+
configuration: PublishingConfiguration;
|
|
91
|
+
packageLimits: SolutionPackageLimits;
|
|
92
|
+
pathCaseSensitivity: 'case-sensitive' | 'case-insensitive';
|
|
93
|
+
clientLimits?: PublishingClientOptions['limits'];
|
|
94
|
+
operationLimits?: Omit<ArtifactOperationOptions, 'signal'>;
|
|
95
|
+
}): PublishingSession;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ArtifactContentIdentity, ArtifactContentManifest, ArtifactContentManifestFile } from '@openge/forge-artifact-publish';
|
|
2
|
+
import type { SolutionPackageDescriptor, SolutionPackageLimits } from '../package.js';
|
|
3
|
+
export type { SolutionPackageLimits } from '../package.js';
|
|
4
|
+
export type SolutionPackageFilePlan = Omit<Extract<ArtifactContentManifestFile, {
|
|
5
|
+
role: 'asset';
|
|
6
|
+
}>, 'byteLength' | 'sha256'> | Omit<Extract<ArtifactContentManifestFile, {
|
|
7
|
+
role: 'control';
|
|
8
|
+
}>, 'byteLength' | 'sha256'>;
|
|
9
|
+
export interface PreparedSolutionPackage {
|
|
10
|
+
descriptor: SolutionPackageDescriptor;
|
|
11
|
+
content: ArtifactContentIdentity;
|
|
12
|
+
manifest: ArtifactContentManifest;
|
|
13
|
+
manifestBytes: Uint8Array;
|
|
14
|
+
files: {
|
|
15
|
+
path: string;
|
|
16
|
+
bytes: Uint8Array;
|
|
17
|
+
}[];
|
|
18
|
+
payloadBytes: number;
|
|
19
|
+
readFile(path: string, input: {
|
|
20
|
+
maximumBytes: number;
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
}): Promise<Uint8Array>;
|
|
23
|
+
streamFile(path: string, input?: {
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
}): AsyncIterable<Uint8Array>;
|
|
26
|
+
}
|
|
27
|
+
interface PackageInput {
|
|
28
|
+
root: string;
|
|
29
|
+
pathCaseSensitivity: 'case-sensitive' | 'case-insensitive';
|
|
30
|
+
limits: SolutionPackageLimits;
|
|
31
|
+
signal?: AbortSignal;
|
|
32
|
+
}
|
|
33
|
+
/** Capture exact artifact bytes, independently of source control or a deployment. */
|
|
34
|
+
export declare function prepareSolutionPackage({ root, files, pathCaseSensitivity, limits, signal }: PackageInput & {
|
|
35
|
+
files: readonly SolutionPackageFilePlan[];
|
|
36
|
+
}): Promise<PreparedSolutionPackage>;
|
|
37
|
+
/** Compose already-captured components without staging a second directory tree. */
|
|
38
|
+
export declare function prepareSolutionPackageBytes({ files, pathCaseSensitivity, limits, signal }: Omit<PackageInput, 'root'> & {
|
|
39
|
+
files: readonly (SolutionPackageFilePlan & {
|
|
40
|
+
bytes: Uint8Array;
|
|
41
|
+
})[];
|
|
42
|
+
}): Promise<PreparedSolutionPackage>;
|
|
43
|
+
export declare function verifySolutionPackage({ root, manifestBytes, expectedContent, pathCaseSensitivity, limits, signal }: PackageInput & {
|
|
44
|
+
manifestBytes: Uint8Array;
|
|
45
|
+
expectedContent: ArtifactContentIdentity;
|
|
46
|
+
}): Promise<PreparedSolutionPackage>;
|
|
47
|
+
/** Validate opaque received bytes without importing or executing the payload. */
|
|
48
|
+
export declare function verifySolutionPackageBytes({ files, manifestBytes, expectedContent, pathCaseSensitivity, limits, signal }: Omit<PackageInput, 'root'> & {
|
|
49
|
+
files: readonly {
|
|
50
|
+
path: string;
|
|
51
|
+
bytes: Uint8Array;
|
|
52
|
+
}[];
|
|
53
|
+
manifestBytes: Uint8Array;
|
|
54
|
+
expectedContent: ArtifactContentIdentity;
|
|
55
|
+
}): Promise<PreparedSolutionPackage>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Only a source owner that observed its process lifecycle may assert closure.
|
|
2
|
+
* The original cause stays private; CLI diagnostics emit only the stable code. */
|
|
3
|
+
export declare class PublishingSourceError extends Error {
|
|
4
|
+
readonly code: 'PUBLISHING_SOURCE_PREPARATION_FAILED' | 'PUBLISHING_SOURCE_PREPARATION_UNKNOWN';
|
|
5
|
+
readonly processesClosed: boolean;
|
|
6
|
+
constructor({ cause, processesClosed }: {
|
|
7
|
+
cause: unknown;
|
|
8
|
+
processesClosed: boolean;
|
|
9
|
+
});
|
|
10
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const defaultProducer = "deployment/publishing.mjs";
|
|
2
|
+
export declare function validateLocalProducer(relative: string): string;
|
|
3
|
+
export declare function checkoutReleaseVersion(root: string, packageName: string): Promise<string | undefined>;
|
|
4
|
+
export declare function checkoutRequiresAcceptanceDelivery(root: string): Promise<boolean>;
|
|
5
|
+
export declare function selectProducerFile(root: string, explicit?: string): Promise<string>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { PublishingMetadataTransport } from '../protocol.js';
|
|
2
|
+
type Origins = {
|
|
3
|
+
serviceUrl: string;
|
|
4
|
+
coreOrigin: string;
|
|
5
|
+
deliveryOrigin?: string;
|
|
6
|
+
};
|
|
7
|
+
type Discover = typeof discoverWindowsProxyRoutes;
|
|
8
|
+
/** Resolve a single Windows proxy-settings snapshot for the supplied HTTPS origins. */
|
|
9
|
+
export declare function discoverWindowsProxyRoutes(origins: readonly string[], signal?: AbortSignal): Promise<readonly (string | null)[]>;
|
|
10
|
+
export declare function openPublishingTerminalNetwork(configuration: Origins, { signal, proxy }?: {
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
proxy?: string;
|
|
13
|
+
}): Promise<{
|
|
14
|
+
request: typeof fetch;
|
|
15
|
+
metadataTransport: PublishingMetadataTransport;
|
|
16
|
+
close(): Promise<void>;
|
|
17
|
+
} | undefined>;
|
|
18
|
+
export declare function openPublishingNetwork(configuration: Origins, proxyOverride?: string, signal?: AbortSignal, discover?: Discover | null): Promise<{
|
|
19
|
+
request: typeof fetch;
|
|
20
|
+
metadataTransport: PublishingMetadataTransport;
|
|
21
|
+
close(): Promise<void>;
|
|
22
|
+
} | undefined>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { publishingError } from '../protocol.js';
|
|
4
|
+
const fail = (code) => publishingError('NETWORK_' + code);
|
|
5
|
+
function localProxy(value) {
|
|
6
|
+
if (typeof value !== 'string' || !/^http:\/\/(?:127\.0\.0\.1|\[::1\])(?::[1-9]\d{0,4})?\/?$/.test(value))
|
|
7
|
+
throw fail('CONFIG_INVALID');
|
|
8
|
+
let url;
|
|
9
|
+
try {
|
|
10
|
+
url = new URL(value);
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
throw fail('CONFIG_INVALID');
|
|
14
|
+
}
|
|
15
|
+
return url.origin;
|
|
16
|
+
}
|
|
17
|
+
function httpsOrigin(value) {
|
|
18
|
+
if (typeof value !== 'string' || value.length > 2048)
|
|
19
|
+
throw fail('ORIGIN_INVALID');
|
|
20
|
+
const url = URL.parse(value);
|
|
21
|
+
if (url?.protocol !== 'https:' || url.origin !== value)
|
|
22
|
+
throw fail('ORIGIN_INVALID');
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
// A fresh, bounded child sees only the public origins. The Windows API applies the existing
|
|
26
|
+
// system bypass/PAC rules to each origin. Neither PowerShell nor this command changes them.
|
|
27
|
+
const windowsQuery = `$ErrorActionPreference='Stop'
|
|
28
|
+
try {
|
|
29
|
+
$origins=ConvertFrom-Json ([Console]::In.ReadToEnd())
|
|
30
|
+
$system=[System.Net.WebRequest]::GetSystemWebProxy()
|
|
31
|
+
$routes=New-Object 'System.Collections.Generic.List[object]'
|
|
32
|
+
foreach($entry in $origins){
|
|
33
|
+
$uri=[Uri]$entry
|
|
34
|
+
$proxy=$system.GetProxy($uri)
|
|
35
|
+
if($system.IsBypassed($uri) -or ($null -ne $proxy -and $proxy.AbsoluteUri -eq $uri.AbsoluteUri)){$routes.Add($null)}
|
|
36
|
+
elseif($null -eq $proxy){exit 1}
|
|
37
|
+
elseif($proxy.Scheme -eq 'http' -and ($proxy.Host -eq '127.0.0.1' -or $proxy.Host -eq '[::1]') -and !$proxy.UserInfo -and $proxy.AbsolutePath -eq '/' -and !$proxy.Query -and !$proxy.Fragment){$routes.Add($proxy.GetLeftPart([UriPartial]::Authority))}
|
|
38
|
+
else {exit 2}
|
|
39
|
+
}
|
|
40
|
+
[Console]::Out.Write((ConvertTo-Json -InputObject $routes.ToArray() -Compress))
|
|
41
|
+
} catch {exit 1}`;
|
|
42
|
+
/** Resolve a single Windows proxy-settings snapshot for the supplied HTTPS origins. */
|
|
43
|
+
export async function discoverWindowsProxyRoutes(origins, signal) {
|
|
44
|
+
if (!Array.isArray(origins) || origins.length < 1 || origins.length > 16)
|
|
45
|
+
throw fail('ORIGIN_INVALID');
|
|
46
|
+
const targets = Array.from(origins, httpsOrigin);
|
|
47
|
+
const systemRoot = process.env.SystemRoot;
|
|
48
|
+
if (signal?.aborted || process.platform !== 'win32' || !systemRoot || !path.isAbsolute(systemRoot))
|
|
49
|
+
throw fail('SYSTEM_PROXY_UNAVAILABLE');
|
|
50
|
+
const exe = path.join(systemRoot, 'System32/WindowsPowerShell/v1.0/powershell.exe');
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
const child = execFile(exe, ['-NoLogo', '-NoProfile', '-NonInteractive', '-EncodedCommand', Buffer.from(windowsQuery, 'utf16le').toString('base64')], { encoding: 'utf8', env: { SystemRoot: systemRoot, WINDIR: systemRoot }, windowsHide: true, timeout: 5000, maxBuffer: 8192, signal }, (error, stdout) => {
|
|
53
|
+
if (error) {
|
|
54
|
+
reject(fail('SYSTEM_PROXY_UNAVAILABLE'));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const routes = JSON.parse(stdout);
|
|
59
|
+
if (!Array.isArray(routes) || routes.length !== targets.length)
|
|
60
|
+
throw Error();
|
|
61
|
+
resolve(routes.map(route => route === null ? null : localProxy(route)));
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
reject(fail('SYSTEM_PROXY_UNAVAILABLE'));
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
child.stdin?.on('error', () => { });
|
|
68
|
+
child.stdin?.end(JSON.stringify(targets));
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
export function openPublishingTerminalNetwork(configuration, { signal, proxy } = {}) {
|
|
72
|
+
return openPublishingNetwork(configuration, proxy, signal, process.platform === 'win32' ? discoverWindowsProxyRoutes : null);
|
|
73
|
+
}
|
|
74
|
+
export async function openPublishingNetwork(configuration, proxyOverride, signal, discover = null) {
|
|
75
|
+
signal?.throwIfAborted();
|
|
76
|
+
if (!configuration || typeof configuration !== 'object')
|
|
77
|
+
throw fail('ORIGIN_INVALID');
|
|
78
|
+
const publisher = httpsOrigin(configuration.serviceUrl), core = httpsOrigin(configuration.coreOrigin);
|
|
79
|
+
const delivery = configuration.deliveryOrigin === undefined ? undefined : httpsOrigin(configuration.deliveryOrigin);
|
|
80
|
+
const origins = [...new Set([publisher, core, ...(delivery ? [delivery] : [])])];
|
|
81
|
+
const proxy = proxyOverride === undefined ? undefined : localProxy(proxyOverride);
|
|
82
|
+
const routes = proxy ? origins.map(() => proxy) : await discover?.(origins, signal);
|
|
83
|
+
if (!routes)
|
|
84
|
+
return;
|
|
85
|
+
if (routes.length !== origins.length)
|
|
86
|
+
throw fail('SYSTEM_PROXY_UNAVAILABLE');
|
|
87
|
+
if (routes.every(route => route === null))
|
|
88
|
+
return;
|
|
89
|
+
const selection = new Map(origins.map((origin, index) => [origin, routes[index] === null ? null : localProxy(routes[index])]));
|
|
90
|
+
let forge;
|
|
91
|
+
try {
|
|
92
|
+
forge = await import('@openge/forge-http-transport/node');
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
throw fail('TRANSPORT_REQUIRED');
|
|
96
|
+
}
|
|
97
|
+
const transports = new Map();
|
|
98
|
+
for (const proxy of new Set(selection.values()))
|
|
99
|
+
transports.set(proxy, forge.createNodeHttpTransport(proxy ? { route: 'proxy', proxyUrl: proxy, noProxy: '' } : { route: 'direct' }));
|
|
100
|
+
const request = async (input, init) => {
|
|
101
|
+
const url = new URL(input instanceof Request ? input.url : String(input));
|
|
102
|
+
const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : undefined));
|
|
103
|
+
if (url.username || url.password || url.hash || !([publisher, delivery].includes(url.origin)) ||
|
|
104
|
+
(headers.has('authorization') && url.origin !== publisher) || ((headers.has('x-link-light-signature') || headers.has('x-link-light-binding')) && url.origin !== delivery) ||
|
|
105
|
+
headers.has('host') || headers.has('proxy-authorization') || headers.has('cookie'))
|
|
106
|
+
throw fail('ORIGIN_INVALID');
|
|
107
|
+
return transports.get(selection.get(url.origin) ?? null).fetch(input, init);
|
|
108
|
+
};
|
|
109
|
+
const metadataTransport = async (address, options) => {
|
|
110
|
+
const url = new URL(address);
|
|
111
|
+
if (url.origin !== core || url.username || url.password || url.hash || url.search ||
|
|
112
|
+
!/^\/api\/registry\/releases\/sha256%3A[a-f0-9]{64}$/.test(url.pathname))
|
|
113
|
+
throw fail('ORIGIN_INVALID');
|
|
114
|
+
const platform = await import('@xlinklight/platform/server'), proxy = selection.get(core);
|
|
115
|
+
return proxy ? platform.createProxiedReleaseMetadataTransport(proxy)(address, options) : platform.requestReleaseMetadata(address, options);
|
|
116
|
+
};
|
|
117
|
+
return { request, metadataTransport, async close() {
|
|
118
|
+
const results = await Promise.allSettled([...transports.values()].map(transport => transport.close()));
|
|
119
|
+
if (results.some(result => result.status === 'rejected'))
|
|
120
|
+
throw fail('CLOSURE_UNKNOWN');
|
|
121
|
+
} };
|
|
122
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { PublishingConfiguration, PublishingMetadataTransport, PublishingProject } from '../protocol.js';
|
|
2
|
+
import type { PublishingJournal } from './journal.js';
|
|
3
|
+
import type { PublishingClientLimits } from '../client.js';
|
|
4
|
+
import type { AcceptanceArchive, AcceptanceDeliveryCredential } from './acceptance-delivery.js';
|
|
5
|
+
import type { PreparedSolutionPackage } from './solution-package.js';
|
|
6
|
+
export interface PublishingSourceProducer {
|
|
7
|
+
prepare(input: {
|
|
8
|
+
root: string;
|
|
9
|
+
project: PublishingProject;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
requestId: string;
|
|
12
|
+
includeAcceptanceArchive?: boolean;
|
|
13
|
+
}): Promise<{
|
|
14
|
+
prepared: PreparedSolutionPackage;
|
|
15
|
+
acceptanceArchive?: AcceptanceArchive;
|
|
16
|
+
processesClosed: true;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
19
|
+
export interface PublishingWorkflowOptions {
|
|
20
|
+
root: string;
|
|
21
|
+
journal: PublishingJournal;
|
|
22
|
+
configuration: PublishingConfiguration;
|
|
23
|
+
credential: string;
|
|
24
|
+
acceptanceDelivery?: AcceptanceDeliveryCredential;
|
|
25
|
+
allowLoopback?: boolean;
|
|
26
|
+
request?: typeof fetch;
|
|
27
|
+
clientLimits?: PublishingClientLimits;
|
|
28
|
+
pathCaseSensitivity?: 'case-sensitive' | 'case-insensitive';
|
|
29
|
+
metadataTransport?: PublishingMetadataTransport;
|
|
30
|
+
operationLimits?: {
|
|
31
|
+
timeoutMilliseconds: number;
|
|
32
|
+
closeTimeoutMilliseconds: number;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export interface PublishingWorkflowResult {
|
|
36
|
+
requestId?: string;
|
|
37
|
+
state: 'empty' | 'checked' | 'preparation-unknown' | 'preparation-failed' | 'uploading' | 'queued' | 'deploying' | 'registered' | 'awaiting-acceptance' | 'active' | 'failed' | 'unknown' | 'abandoned' | 'superseded';
|
|
38
|
+
active: boolean;
|
|
39
|
+
sideEffects?: 'none' | 'pending' | 'unknown' | 'closed';
|
|
40
|
+
timedOut?: true;
|
|
41
|
+
error?: {
|
|
42
|
+
code: string;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export interface PublishingSourceOptions {
|
|
46
|
+
producer?: string;
|
|
47
|
+
newPreparation?: boolean;
|
|
48
|
+
signal?: AbortSignal;
|
|
49
|
+
}
|
|
50
|
+
export interface PublishingPublishOptions extends PublishingSourceOptions {
|
|
51
|
+
/** 0 (default) returns immediately; positive values bound read-only status polling after submission. */
|
|
52
|
+
waitMs?: number;
|
|
53
|
+
/** Status polling interval, 1–30000ms; defaults to 1000ms. */
|
|
54
|
+
pollMs?: number;
|
|
55
|
+
}
|
|
56
|
+
export interface PublishingWorkflow {
|
|
57
|
+
check(input?: PublishingSourceOptions): Promise<PublishingWorkflowResult>;
|
|
58
|
+
publish(input?: PublishingPublishOptions): Promise<PublishingWorkflowResult>;
|
|
59
|
+
status(input?: {
|
|
60
|
+
signal?: AbortSignal;
|
|
61
|
+
}): Promise<PublishingWorkflowResult>;
|
|
62
|
+
recover(input?: {
|
|
63
|
+
signal?: AbortSignal;
|
|
64
|
+
}): Promise<PublishingWorkflowResult>;
|
|
65
|
+
verify(input?: {
|
|
66
|
+
signal?: AbortSignal;
|
|
67
|
+
}): Promise<PublishingWorkflowResult>;
|
|
68
|
+
abandon(input?: {
|
|
69
|
+
signal?: AbortSignal;
|
|
70
|
+
}): Promise<PublishingWorkflowResult>;
|
|
71
|
+
}
|
|
72
|
+
/** One active request per project/client journal. Recovery never imports source
|
|
73
|
+
* or performs an operation whose durable Foundation claim already exists. */
|
|
74
|
+
export declare function createPublishingWorkflow(options: PublishingWorkflowOptions): PublishingWorkflow;
|