@xlinklight/publishing 3.3.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/README.md +23 -3
  2. package/dist/src/acceptance-delivery-binding.d.ts +20 -0
  3. package/dist/src/acceptance-delivery-binding.js +59 -0
  4. package/dist/src/acceptance.d.ts +49 -0
  5. package/dist/src/acceptance.js +79 -0
  6. package/dist/src/client.d.ts +71 -0
  7. package/dist/src/client.js +146 -0
  8. package/dist/src/index.d.ts +6 -0
  9. package/dist/src/index.js +3 -0
  10. package/dist/src/node/acceptance-delivery.d.ts +34 -0
  11. package/dist/src/node/acceptance-delivery.js +88 -0
  12. package/dist/src/node/activation.d.ts +5 -0
  13. package/dist/src/node/activation.js +3 -0
  14. package/dist/src/node/authorization.d.ts +31 -0
  15. package/dist/src/node/authorization.js +76 -0
  16. package/dist/src/node/cli.d.ts +2 -0
  17. package/dist/src/node/cli.js +22 -0
  18. package/dist/src/node/index.d.ts +20 -0
  19. package/dist/src/node/index.js +11 -0
  20. package/dist/src/node/journal-directory.d.ts +2 -0
  21. package/dist/src/node/journal-directory.js +121 -0
  22. package/dist/src/node/journal.d.ts +49 -0
  23. package/dist/src/node/journal.js +280 -0
  24. package/dist/src/node/local-json-file.d.ts +3 -0
  25. package/dist/src/node/local-json-file.js +49 -0
  26. package/dist/src/node/publishing-command.d.ts +46 -0
  27. package/dist/src/node/publishing-command.js +268 -0
  28. package/dist/src/node/session.d.ts +95 -0
  29. package/dist/src/node/session.js +223 -0
  30. package/dist/src/node/solution-package.d.ts +55 -0
  31. package/dist/src/node/solution-package.js +217 -0
  32. package/dist/src/node/source-error.d.ts +10 -0
  33. package/dist/src/node/source-error.js +15 -0
  34. package/dist/src/node/source-producer.d.ts +5 -0
  35. package/dist/src/node/source-producer.js +145 -0
  36. package/dist/src/node/terminal-network.d.ts +23 -0
  37. package/dist/src/node/terminal-network.js +122 -0
  38. package/dist/src/node/workflow.d.ts +74 -0
  39. package/dist/src/node/workflow.js +467 -0
  40. package/dist/src/package.d.ts +38 -0
  41. package/dist/src/package.js +74 -0
  42. package/dist/src/protocol.d.ts +83 -0
  43. package/dist/src/protocol.js +105 -0
  44. package/dist/src/shared/activation-types.d.ts +37 -0
  45. package/dist/src/shared/activation-types.js +1 -0
  46. package/dist/src/shared/activation.d.ts +17 -0
  47. package/dist/src/shared/activation.js +111 -0
  48. package/dist/src/shared/records.d.ts +10 -0
  49. package/dist/src/shared/records.js +26 -0
  50. package/dist/src/shared/release-version.d.ts +4 -0
  51. package/dist/src/shared/release-version.js +15 -0
  52. package/dist/src/worker/activation.d.ts +12 -0
  53. package/dist/src/worker/activation.js +11 -0
  54. package/dist/src/worker/durable-retention.d.ts +9 -0
  55. package/dist/src/worker/durable-retention.js +96 -0
  56. package/dist/src/worker/index.d.ts +12 -0
  57. package/dist/src/worker/index.js +7 -0
  58. package/dist/src/worker/journal.d.ts +129 -0
  59. package/dist/src/worker/journal.js +328 -0
  60. package/dist/src/worker/package.d.ts +60 -0
  61. package/dist/src/worker/package.js +116 -0
  62. package/dist/src/worker/release-retention.d.ts +34 -0
  63. package/dist/src/worker/release-retention.js +27 -0
  64. package/dist/src/worker/release.d.ts +22 -0
  65. package/dist/src/worker/release.js +59 -0
  66. package/dist/src/worker/runtime.d.ts +47 -0
  67. package/dist/src/worker/runtime.js +98 -0
  68. package/dist/src/worker/service.d.ts +128 -0
  69. package/dist/src/worker/service.js +520 -0
  70. package/package.json +23 -14
  71. package/src/acceptance-delivery-binding.mjs +0 -49
  72. package/src/acceptance.d.mts +0 -24
  73. package/src/acceptance.mjs +0 -67
  74. package/src/client.d.mts +0 -16
  75. package/src/client.mjs +0 -74
  76. package/src/index.d.mts +0 -6
  77. package/src/index.mjs +0 -3
  78. package/src/node/acceptance-delivery.d.mts +0 -11
  79. package/src/node/acceptance-delivery.mjs +0 -70
  80. package/src/node/activation.d.mts +0 -8
  81. package/src/node/activation.mjs +0 -3
  82. package/src/node/authorization.d.mts +0 -8
  83. package/src/node/authorization.mjs +0 -49
  84. package/src/node/cli.mjs +0 -12
  85. package/src/node/index.d.mts +0 -17
  86. package/src/node/index.mjs +0 -9
  87. package/src/node/journal.d.mts +0 -13
  88. package/src/node/journal.mjs +0 -135
  89. package/src/node/publishing-command.d.mts +0 -20
  90. package/src/node/publishing-command.mjs +0 -104
  91. package/src/node/session.d.mts +0 -25
  92. package/src/node/session.mjs +0 -134
  93. package/src/node/solution-package.d.mts +0 -15
  94. package/src/node/solution-package.mjs +0 -113
  95. package/src/node/source-error.d.mts +0 -5
  96. package/src/node/source-error.mjs +0 -9
  97. package/src/node/source-producer.mjs +0 -103
  98. package/src/node/workflow.d.mts +0 -37
  99. package/src/node/workflow.mjs +0 -320
  100. package/src/package.d.mts +0 -11
  101. package/src/package.mjs +0 -36
  102. package/src/protocol.d.mts +0 -27
  103. package/src/protocol.mjs +0 -50
  104. package/src/shared/activation.d.mts +0 -5
  105. package/src/shared/activation.mjs +0 -64
  106. package/src/worker/activation.d.mts +0 -7
  107. package/src/worker/activation.mjs +0 -4
  108. package/src/worker/index.d.mts +0 -6
  109. package/src/worker/index.mjs +0 -6
  110. package/src/worker/journal.d.mts +0 -21
  111. package/src/worker/journal.mjs +0 -151
  112. package/src/worker/package.d.mts +0 -16
  113. package/src/worker/package.mjs +0 -32
  114. package/src/worker/release.d.mts +0 -7
  115. package/src/worker/release.mjs +0 -21
  116. package/src/worker/runtime.d.mts +0 -4
  117. package/src/worker/runtime.mjs +0 -23
  118. package/src/worker/service.d.mts +0 -41
  119. package/src/worker/service.mjs +0 -251
@@ -0,0 +1,49 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ export function isAbsoluteLocalFile(value) {
4
+ if (!path.isAbsolute(value) || value.length > 4096 || /[\x00-\x1f]/.test(value))
5
+ return false;
6
+ if (process.platform === 'win32') {
7
+ if (!/^[A-Za-z]:[\\/]/.test(value) || value.slice(2).includes(':'))
8
+ return false;
9
+ }
10
+ else if (value.startsWith('//'))
11
+ return false;
12
+ return !value.split(path.sep === '\\' ? /[\\/]/ : '/').some(part => part === '.' || part === '..');
13
+ }
14
+ const invalid = () => Error('LOCAL_JSON_FILE_INVALID');
15
+ const sameFile = (a, b) => a.dev === b.dev && a.ino === b.ino && a.size === b.size && a.mtimeNs === b.mtimeNs && a.ctimeNs === b.ctimeNs && b.nlink === 1n;
16
+ /** Read the named regular file once. A link, replacement or size change never selects a different JSON document. */
17
+ export async function readLocalJsonFile(file, maximumBytes, signal) {
18
+ signal?.throwIfAborted();
19
+ if (!isAbsoluteLocalFile(file))
20
+ throw invalid();
21
+ const canonical = path.resolve(file), before = await fs.lstat(canonical, { bigint: true });
22
+ if (!before.isFile() || before.isSymbolicLink() || before.nlink !== 1n || before.size > BigInt(maximumBytes) ||
23
+ path.relative(canonical, await fs.realpath(canonical)) !== '')
24
+ throw invalid();
25
+ const flags = fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0) | (fs.constants.O_NONBLOCK ?? 0);
26
+ const handle = await fs.open(canonical, flags);
27
+ const buffer = Buffer.alloc(Number(before.size) + 1);
28
+ try {
29
+ if (!sameFile(before, await handle.stat({ bigint: true })))
30
+ throw invalid();
31
+ let offset = 0;
32
+ while (offset < buffer.length) {
33
+ signal?.throwIfAborted();
34
+ const { bytesRead } = await handle.read(buffer, offset, buffer.length - offset, offset);
35
+ if (!bytesRead)
36
+ break;
37
+ offset += bytesRead;
38
+ }
39
+ if (offset !== Number(before.size) || !sameFile(before, await handle.stat({ bigint: true })) ||
40
+ !sameFile(before, await fs.lstat(canonical, { bigint: true })) || path.relative(canonical, await fs.realpath(canonical)) !== '')
41
+ throw invalid();
42
+ signal?.throwIfAborted();
43
+ return JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(buffer.subarray(0, offset)));
44
+ }
45
+ finally {
46
+ buffer.fill(0);
47
+ await handle.close();
48
+ }
49
+ }
@@ -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>;
@@ -0,0 +1,268 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { createLinuxDurableArtifactFilesystem, createWindowsNtfsDurableArtifactFilesystem } from '@openge/forge-generated-artifacts/node';
4
+ import { validatePortableRelativePath } from '@openge/forge-path-safety';
5
+ import { parsePublishingConfiguration, protocolRecord, publishingError, publishingRequestId } from '../protocol.js';
6
+ import { openPublishingCredentialJournal, openPublishingJournal } from './journal.js';
7
+ import { installPublishingAuthorization, loadPublishingAuthorization } from './authorization.js';
8
+ import { createPublishingWorkflow } from './workflow.js';
9
+ import { defaultProducer } from './source-producer.js';
10
+ import { parseAcceptanceDeliveryCredential } from './acceptance-delivery.js';
11
+ import { errorCode, objectRecord } from '../shared/records.js';
12
+ import { openPublishingTerminalNetwork } from './terminal-network.js';
13
+ import { isAbsoluteLocalFile, readLocalJsonFile } from './local-json-file.js';
14
+ const commands = ['credentials', 'check', 'publish', 'status', 'recover', 'verify', 'abandon'];
15
+ const journalLimits = Object.freeze({ maximumBytes: 536870912, maximumRecords: 256, maximumRecordBytes: 1048576, maximumBlobs: 12000, maximumBlobBytes: 134217728, minimumFreeBytes: 67108864 });
16
+ const fail = (code) => publishingError(code);
17
+ function parse(args) {
18
+ if (!Array.isArray(args) || !args.length || args.some(value => typeof value !== 'string' || !value || value.includes('\0') || value.length > 4096))
19
+ throw fail('CLI_ARGUMENT_INVALID');
20
+ if (args.length === 1 && args[0] === '--help')
21
+ return { command: 'help' };
22
+ const command = commands.find(command => command === args[0]);
23
+ if (!command)
24
+ throw fail('CLI_ARGUMENT_INVALID');
25
+ const selected = { command }, seen = new Set();
26
+ for (let index = 1; index < args.length; index++) {
27
+ const flag = args[index];
28
+ if (seen.has(flag))
29
+ throw fail('CLI_ARGUMENT_INVALID');
30
+ seen.add(flag);
31
+ if (flag === '--root' || flag === '--state' || flag === '--producer') {
32
+ const value = args[++index];
33
+ if (!value || value.startsWith('--') || flag === '--producer' && !['check', 'publish'].includes(command))
34
+ throw fail('CLI_ARGUMENT_INVALID');
35
+ selected[flag === '--root' ? 'root' : flag === '--state' ? 'state' : 'producer'] = value;
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
+ }
43
+ else if (flag === '--stdin' && command === 'credentials')
44
+ selected.stdin = true;
45
+ else if (flag === '--no-wait' && command === 'publish')
46
+ selected.waitMs = 0;
47
+ else if (flag === '--wait-ms' && command === 'publish') {
48
+ const value = args[++index];
49
+ if (!/^[1-9]\d{0,6}$/.test(value ?? '') || Number(value) > 3600000)
50
+ throw fail('CLI_ARGUMENT_INVALID');
51
+ selected.waitMs = Number(value);
52
+ }
53
+ else if (flag === '--replace-credential' && command === 'credentials')
54
+ selected.replaceCredential = true;
55
+ else if (flag === '--new-preparation' && ['check', 'publish'].includes(command))
56
+ selected.newPreparation = true;
57
+ else
58
+ throw fail('CLI_ARGUMENT_INVALID');
59
+ }
60
+ if (command === 'credentials' && !selected.stdin)
61
+ throw fail('CLI_ARGUMENT_INVALID');
62
+ if (seen.has('--no-wait') && seen.has('--wait-ms'))
63
+ throw fail('CLI_ARGUMENT_INVALID');
64
+ for (const key of ['state', 'producer']) {
65
+ const value = selected[key];
66
+ if (value !== undefined) {
67
+ try {
68
+ if (validatePortableRelativePath(value) !== value || key === 'producer' && !value.endsWith('.mjs'))
69
+ throw Error();
70
+ }
71
+ catch {
72
+ throw fail('CLI_ARGUMENT_INVALID');
73
+ }
74
+ }
75
+ }
76
+ return selected;
77
+ }
78
+ async function credentialInput(stdin, signal, timeoutMilliseconds) {
79
+ if (!stdin || stdin.isTTY === true || ['on', 'off', 'destroy', 'resume'].some(name => typeof stdin[name] !== 'function'))
80
+ throw fail('CREDENTIAL_INPUT_NON_TTY_REQUIRED');
81
+ if (!Number.isSafeInteger(timeoutMilliseconds) || timeoutMilliseconds < 1 || timeoutMilliseconds > 300000)
82
+ throw fail('CREDENTIAL_INPUT_LIMIT_INVALID');
83
+ const chunks = [];
84
+ let bytes = 0, timer, abort, data, end, error, close;
85
+ let closedListener;
86
+ const closed = stdin.closed ? Promise.resolve(true) : new Promise(resolve => { closedListener = () => resolve(true); stdin.once('close', closedListener); });
87
+ try {
88
+ if (signal?.aborted)
89
+ throw fail('CREDENTIAL_INPUT_CANCELLED');
90
+ await new Promise((resolve, reject) => {
91
+ let settled = false;
92
+ const rejectOnce = (code) => { if (!settled) {
93
+ settled = true;
94
+ reject(fail(code));
95
+ } };
96
+ data = value => { if (settled)
97
+ return; if (!(value instanceof Uint8Array) && typeof value !== 'string')
98
+ return rejectOnce('CREDENTIAL_INPUT_INVALID'); const chunk = typeof value === 'string' ? Buffer.from(value) : Buffer.from(value); bytes += chunk.byteLength; if (bytes > 16384)
99
+ return rejectOnce('CREDENTIAL_INPUT_BYTE_LIMIT'); chunks.push(chunk); };
100
+ end = () => { if (!settled) {
101
+ settled = true;
102
+ resolve();
103
+ } };
104
+ error = () => rejectOnce('CREDENTIAL_INPUT_INVALID');
105
+ close = () => rejectOnce('CREDENTIAL_INPUT_CLOSED');
106
+ abort = () => rejectOnce('CREDENTIAL_INPUT_CANCELLED');
107
+ stdin.on('data', data);
108
+ stdin.once('end', end);
109
+ stdin.once('error', error);
110
+ stdin.once('close', close);
111
+ signal?.addEventListener('abort', abort, { once: true });
112
+ timer = setTimeout(() => rejectOnce('CREDENTIAL_INPUT_TIMEOUT'), timeoutMilliseconds);
113
+ stdin.resume();
114
+ });
115
+ let value;
116
+ try {
117
+ value = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(Buffer.concat(chunks)));
118
+ }
119
+ catch {
120
+ throw fail('CREDENTIAL_INPUT_INVALID');
121
+ }
122
+ if (!protocolRecord(value, ['configuration', 'credential'], ['acceptanceDelivery']) || typeof value.credential !== 'string' || !/^[A-Za-z0-9_-]{32,4096}$/.test(value.credential))
123
+ throw fail('CREDENTIAL_INPUT_INVALID');
124
+ return { configuration: value.configuration, credential: value.credential, acceptanceDelivery: value.acceptanceDelivery };
125
+ }
126
+ catch (error) {
127
+ if (errorCode(error)?.startsWith('PUBLISHING_CREDENTIAL_INPUT_'))
128
+ throw error;
129
+ throw fail(signal?.aborted ? 'CREDENTIAL_INPUT_CANCELLED' : 'CREDENTIAL_INPUT_INVALID');
130
+ }
131
+ finally {
132
+ clearTimeout(timer);
133
+ if (abort)
134
+ signal?.removeEventListener('abort', abort);
135
+ for (const [name, listener] of [['data', data], ['end', end], ['error', error], ['close', close]])
136
+ if (listener)
137
+ stdin.off(name, listener);
138
+ // Explicit credential input is owned by this call, including blocked pipes.
139
+ stdin.destroy();
140
+ let closureTimer;
141
+ try {
142
+ if (!await Promise.race([closed, new Promise(resolve => { closureTimer = setTimeout(() => resolve(false), 1000); })]))
143
+ throw fail('CREDENTIAL_INPUT_CLOSURE_UNKNOWN');
144
+ }
145
+ finally {
146
+ clearTimeout(closureTimer);
147
+ if (closedListener)
148
+ stdin.off('close', closedListener);
149
+ }
150
+ }
151
+ }
152
+ function diagnostic(error) {
153
+ const supplied = errorCode(error), code = supplied && /^PUBLISHING_[A-Z0-9_]{1,96}$/.test(supplied) ? supplied : 'PUBLISHING_COMMAND_FAILED';
154
+ return { error: { code } };
155
+ }
156
+ /** Bounded one-shot CLI. No token, private producer cause, provider output or
157
+ * environment is returned. Callers own private storage ACLs and backup policy. */
158
+ async function executeCommand(selected, options, terminal) {
159
+ let journal, network;
160
+ try {
161
+ const { signal, allowLoopback = false, request, clientLimits, metadataTransport } = options;
162
+ const raw = selected.command === 'credentials' ? await credentialInput(options.stdin ?? process.stdin, signal, options.credentialInputTimeoutMilliseconds ?? 30000) : undefined;
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
+ }
182
+ signal?.throwIfAborted();
183
+ const root = path.resolve(options.cwd ?? process.cwd(), selected.root ?? '.'), info = await fs.lstat(root);
184
+ if (!info.isDirectory() || info.isSymbolicLink() || await fs.realpath(root) !== root)
185
+ throw fail('CLI_ROOT_INVALID');
186
+ const filesystem = options.filesystem ?? await (process.platform === 'win32' ? createWindowsNtfsDurableArtifactFilesystem() : process.platform === 'linux' ? createLinuxDurableArtifactFilesystem() : Promise.reject(fail('CLI_PLATFORM_UNSUPPORTED')));
187
+ if (!filesystem)
188
+ throw fail('CLI_PLATFORM_UNSUPPORTED');
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 };
209
+ if (selected.command === 'credentials') {
210
+ if (!input)
211
+ throw fail('CREDENTIAL_INPUT_INVALID');
212
+ const installed = await installPublishingAuthorization({ ...shared, ...authorization, replaceCredential: selected.replaceCredential === true });
213
+ return { exitCode: 0, output: { state: installed.status.toLowerCase(), projectId: installed.projectId, policyRevision: installed.policyRevision } };
214
+ }
215
+ const workflow = createPublishingWorkflow({ ...shared, ...authorization, root, ...(selectedMetadata ? { metadataTransport: selectedMetadata } : {}), ...(options.operationLimits ? { operationLimits: options.operationLimits } : {}) });
216
+ let result;
217
+ try {
218
+ result = await workflow[selected.command]({ signal, ...(selected.producer ? { producer: selected.producer } : {}), ...(selected.newPreparation ? { newPreparation: true } : {}), ...(selected.command === 'publish' ? { waitMs: selected.waitMs ?? 300000 } : {}) });
219
+ }
220
+ catch (error) {
221
+ const code = diagnostic(error).error.code;
222
+ const ambiguous = code.endsWith('_UNKNOWN') || ['PUBLISHING_SERVICE_UNREACHABLE', 'PUBLISHING_PROVIDER_FAILED', 'PUBLISHING_BUSY'].includes(code) || error instanceof Error && error.name === 'TimeoutError';
223
+ let requestId = objectRecord(error) ? error.requestId : undefined;
224
+ if (requestId == null) {
225
+ const saved = (await journal.load('active:' + authorization.configuration.projectId))?.payload;
226
+ if (objectRecord(saved))
227
+ requestId = saved.requestId;
228
+ }
229
+ if (!publishingRequestId(requestId))
230
+ throw error;
231
+ return { exitCode: ambiguous ? 3 : 1, output: { ...(ambiguous ? { state: 'unknown', active: false } : {}), requestId, error: { code } } };
232
+ }
233
+ const exitCode = result.state === 'active' || selected.command === 'check' && result.state === 'checked' || selected.command === 'abandon' && result.state === 'abandoned' ? 0 : result.state === 'failed' ? 1 : 3;
234
+ return { exitCode, output: result };
235
+ }
236
+ finally {
237
+ try {
238
+ await network?.close();
239
+ }
240
+ finally {
241
+ try {
242
+ journal?.close();
243
+ }
244
+ catch {
245
+ throw fail('JOURNAL_CLOSURE_UNKNOWN');
246
+ }
247
+ }
248
+ }
249
+ }
250
+ async function runCommand(args, options, terminal) {
251
+ let selected;
252
+ try {
253
+ selected = parse(args);
254
+ }
255
+ catch {
256
+ return { exitCode: 2, output: { error: { code: 'PUBLISHING_CLI_ARGUMENT_INVALID' } } };
257
+ }
258
+ if (selected.command === 'help')
259
+ return { exitCode: 0, output: { commands, sourceProducer: defaultProducer, stateDirectory: 'state/solution-publishing', publishWaitMs: 300000, publishOptions: ['--no-wait', '--wait-ms <1..3600000>'] } };
260
+ try {
261
+ return await executeCommand(selected, options, terminal);
262
+ }
263
+ catch (error) {
264
+ return { exitCode: 1, output: diagnostic(error) };
265
+ }
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;