@arcadia-eternity/content-sdk 4.3.4 → 4.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 +3 -3
- package/bin/arcadia-content-mcp.mjs +2 -0
- package/bin/arcadia-content.mjs +2 -0
- package/dist/asset-inspect.d.ts +30 -0
- package/dist/asset-inspect.js +84 -0
- package/dist/author-api.d.ts +48 -0
- package/dist/author-api.js +128 -0
- package/dist/author-reference.d.ts +61 -0
- package/dist/author-reference.js +130 -0
- package/dist/build-content.d.ts +2 -0
- package/dist/build-content.js +29 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +81 -0
- package/dist/content-query.d.ts +30 -0
- package/dist/content-query.js +326 -0
- package/dist/content-workspace.d.ts +204 -0
- package/dist/content-workspace.js +981 -0
- package/dist/debug-environments.d.ts +96 -0
- package/dist/debug-environments.js +135 -0
- package/dist/demo.d.ts +1 -0
- package/dist/demo.js +18 -0
- package/dist/effect-build.d.ts +3 -0
- package/dist/effect-build.js +44 -0
- package/dist/environment-rules.d.ts +7 -0
- package/dist/environment-rules.js +94 -0
- package/dist/environment.d.ts +48 -0
- package/dist/environment.js +184 -0
- package/dist/job-journal.d.ts +19 -0
- package/dist/job-journal.js +110 -0
- package/dist/jobs.d.ts +103 -0
- package/dist/jobs.js +626 -0
- package/dist/lib/content.d.ts +24 -0
- package/dist/lib/content.js +106 -0
- package/dist/lib/presentation.d.ts +26 -0
- package/dist/lib/presentation.js +252 -0
- package/dist/lib/yaml-sharing.d.ts +16 -0
- package/dist/lib/yaml-sharing.js +130 -0
- package/dist/managed-projects.d.ts +37 -0
- package/dist/managed-projects.js +305 -0
- package/dist/managed-sources.d.ts +28 -0
- package/dist/managed-sources.js +541 -0
- package/dist/mcp-contracts.d.ts +420 -0
- package/dist/mcp-contracts.js +146 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +228 -0
- package/dist/module-path.d.ts +1 -0
- package/dist/module-path.js +8 -0
- package/dist/pack-project.d.ts +10 -0
- package/dist/pack-project.js +178 -0
- package/dist/preview-control.d.ts +17 -0
- package/dist/preview-control.js +273 -0
- package/dist/preview.d.ts +24 -0
- package/dist/preview.js +332 -0
- package/dist/project-teams.d.ts +51 -0
- package/dist/project-teams.js +106 -0
- package/dist/project.d.ts +18 -0
- package/dist/project.js +146 -0
- package/dist/rename.d.ts +2 -0
- package/dist/rename.js +128 -0
- package/dist/setup.d.ts +2 -0
- package/dist/setup.js +117 -0
- package/dist/source-lock.d.ts +9 -0
- package/dist/source-lock.js +117 -0
- package/dist/template/README.md +2 -0
- package/dist/template/docs/presentation.md +3 -3
- package/dist/template/package.json +3 -7
- package/dist/template/test/pack.test.mjs +10 -7
- package/dist/testing.d.ts +58 -0
- package/dist/testing.js +205 -0
- package/dist/types.d.ts +5 -0
- package/dist/types.js +14 -0
- package/dist/workbench-context.d.ts +10 -0
- package/dist/workbench-context.js +27 -0
- package/dist/workspace-cli.d.ts +1 -0
- package/dist/workspace-cli.js +66 -0
- package/dist/workspace-materials.d.ts +19 -0
- package/dist/workspace-materials.js +165 -0
- package/dist/workspace.d.ts +190 -0
- package/dist/workspace.js +726 -0
- package/package.json +34 -27
- package/dist/asset-inspect.mjs +0 -67
- package/dist/author-api.mjs +0 -112
- package/dist/author-reference.mjs +0 -121
- package/dist/build-content.mjs +0 -30
- package/dist/cli.mjs +0 -76
- package/dist/content-query.mjs +0 -283
- package/dist/content-workspace.d.mts +0 -161
- package/dist/content-workspace.mjs +0 -936
- package/dist/debug-environments.mjs +0 -154
- package/dist/demo.mjs +0 -22
- package/dist/effect-build.d.mts +0 -2
- package/dist/effect-build.mjs +0 -46
- package/dist/environment-rules.d.mts +0 -5
- package/dist/environment-rules.mjs +0 -92
- package/dist/environment.mjs +0 -183
- package/dist/job-journal.mjs +0 -94
- package/dist/jobs.mjs +0 -579
- package/dist/lib/content.mjs +0 -95
- package/dist/lib/presentation.mjs +0 -240
- package/dist/lib/yaml-sharing.mjs +0 -101
- package/dist/managed-projects.d.mts +0 -35
- package/dist/managed-projects.mjs +0 -303
- package/dist/managed-sources.d.mts +0 -19
- package/dist/managed-sources.mjs +0 -503
- package/dist/mcp-contracts.mjs +0 -153
- package/dist/mcp.mjs +0 -369
- package/dist/pack-project.mjs +0 -157
- package/dist/preview-control.mjs +0 -260
- package/dist/preview.mjs +0 -313
- package/dist/project-teams.mjs +0 -98
- package/dist/project.mjs +0 -140
- package/dist/rename.mjs +0 -112
- package/dist/setup.mjs +0 -134
- package/dist/source-lock.mjs +0 -103
- package/dist/testing.mjs +0 -204
- package/dist/workbench-context.mjs +0 -18
- package/dist/workspace-cli.mjs +0 -60
- package/dist/workspace-materials.mjs +0 -153
- package/dist/workspace.mjs +0 -684
- /package/dist/{index.d.mts → index.d.ts} +0 -0
- /package/dist/{index.mjs → index.js} +0 -0
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { mkdir, mkdtemp, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
import { promisify } from 'node:util';
|
|
5
|
+
import { valid, validRange } from 'semver';
|
|
6
|
+
import { inspectNpmProject, resolveNpmInvocation } from '@arcadia-eternity/pack-loader/node';
|
|
7
|
+
import { normalizeEnvironmentDocument } from './debug-environments.js';
|
|
8
|
+
import { acquireSource } from './managed-sources.js';
|
|
9
|
+
import { contentError, materialFiles } from './workspace-materials.js';
|
|
10
|
+
import { errorCode, isRecord } from './types.js';
|
|
11
|
+
const execute = promisify(execFile);
|
|
12
|
+
const DEFAULT_TIMEOUT = 120_000;
|
|
13
|
+
const DEFAULT_BYTES = 256 * 1024 * 1024;
|
|
14
|
+
const packageName = /^(?:@[a-z0-9_.-]+\/)?[a-z0-9][a-z0-9_.-]*$/;
|
|
15
|
+
function limit(value, fallback, maximum) {
|
|
16
|
+
const result = value ?? fallback;
|
|
17
|
+
if (!Number.isSafeInteger(result) || result < 1 || result > maximum)
|
|
18
|
+
throw contentError('INSTALL_LIMIT_INVALID');
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
function registryUrl(value) {
|
|
22
|
+
const url = new URL(value ?? 'https://registry.npmjs.org/');
|
|
23
|
+
if (url.protocol !== 'https:' || url.username || url.password || url.search || url.hash)
|
|
24
|
+
throw contentError('INSTALL_REGISTRY_INVALID');
|
|
25
|
+
return url.href;
|
|
26
|
+
}
|
|
27
|
+
function checkDependencySpecs(manifest) {
|
|
28
|
+
for (const field of ['dependencies', 'optionalDependencies', 'peerDependencies']) {
|
|
29
|
+
if (manifest[field] === undefined)
|
|
30
|
+
continue;
|
|
31
|
+
if (!manifest[field] || typeof manifest[field] !== 'object' || Array.isArray(manifest[field]))
|
|
32
|
+
throw contentError('INSTALL_DEPENDENCY_INVALID');
|
|
33
|
+
const entries = manifest[field];
|
|
34
|
+
if (!isRecord(entries))
|
|
35
|
+
throw contentError('INSTALL_DEPENDENCY_INVALID');
|
|
36
|
+
for (const [name, range] of Object.entries(entries)) {
|
|
37
|
+
if (!packageName.test(name) || typeof range !== 'string' || !validRange(range))
|
|
38
|
+
throw contentError('INSTALL_DEPENDENCY_SOURCE_FORBIDDEN');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function checkLock(lock, candidates = false) {
|
|
43
|
+
if (!isRecord(lock) || lock.lockfileVersion !== 3 || !isRecord(lock.packages))
|
|
44
|
+
throw contentError('INSTALL_LOCK_INVALID');
|
|
45
|
+
for (const [location, value] of Object.entries(lock.packages)) {
|
|
46
|
+
if (!isRecord(value) || value.link)
|
|
47
|
+
throw contentError('INSTALL_LOCK_INVALID');
|
|
48
|
+
const entry = value;
|
|
49
|
+
if (location &&
|
|
50
|
+
(!location.startsWith('node_modules/') || location.split('/').includes('..') || location.includes('\\')))
|
|
51
|
+
throw contentError('INSTALL_LOCK_INVALID');
|
|
52
|
+
if (typeof entry.resolved !== 'string')
|
|
53
|
+
continue;
|
|
54
|
+
if (candidates && /^file:candidates\/source-[0-9]+\.tgz$/.test(entry.resolved))
|
|
55
|
+
continue;
|
|
56
|
+
const url = new URL(entry.resolved);
|
|
57
|
+
if (url.protocol !== 'https:' || url.username || url.password)
|
|
58
|
+
throw contentError('INSTALL_DEPENDENCY_SOURCE_FORBIDDEN');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** No inherited npm configuration, loader hooks, or author script can alter install behavior. */
|
|
62
|
+
function installationEnvironment(cache, configuration) {
|
|
63
|
+
const result = {};
|
|
64
|
+
for (const key of ['PATH', 'Path', 'SystemRoot', 'WINDIR', 'TEMP', 'TMP', 'TMPDIR', 'HOME', 'USERPROFILE', 'LANG'])
|
|
65
|
+
if (process.env[key])
|
|
66
|
+
result[key] = process.env[key];
|
|
67
|
+
if (process.env.ELECTRON_RUN_AS_NODE === '1' || process.versions.electron)
|
|
68
|
+
result.ELECTRON_RUN_AS_NODE = '1';
|
|
69
|
+
return {
|
|
70
|
+
...result,
|
|
71
|
+
npm_config_cache: cache,
|
|
72
|
+
npm_config_userconfig: configuration,
|
|
73
|
+
npm_config_globalconfig: configuration + '.global',
|
|
74
|
+
npm_config_ignore_scripts: 'true',
|
|
75
|
+
npm_config_engine_strict: 'true',
|
|
76
|
+
npm_config_strict_peer_deps: 'true',
|
|
77
|
+
npm_config_force: 'false',
|
|
78
|
+
npm_config_legacy_peer_deps: 'false',
|
|
79
|
+
npm_config_audit: 'false',
|
|
80
|
+
npm_config_fund: 'false',
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Resolves a captured draft into a standard installed npm project. Construction and
|
|
85
|
+
* source registration belong to the host, while requests contain only environment IDs.
|
|
86
|
+
* The ContentWorkspace still owns immutable versions, leases, and publication.
|
|
87
|
+
*/
|
|
88
|
+
export class ManagedProjects {
|
|
89
|
+
root;
|
|
90
|
+
#options;
|
|
91
|
+
#controller = new AbortController();
|
|
92
|
+
#pending = new Set();
|
|
93
|
+
#active = 0;
|
|
94
|
+
constructor(root, options = {}) {
|
|
95
|
+
this.root = resolve(root);
|
|
96
|
+
if (options.sources !== undefined &&
|
|
97
|
+
(!options.sources || typeof options.sources !== 'object' || Array.isArray(options.sources)))
|
|
98
|
+
throw contentError('INSTALL_SOURCES_INVALID');
|
|
99
|
+
this.#options = {
|
|
100
|
+
...options,
|
|
101
|
+
registry: registryUrl(options.registry),
|
|
102
|
+
sources: structuredClone(options.sources ?? {}),
|
|
103
|
+
timeoutMs: limit(options.timeoutMs, DEFAULT_TIMEOUT, 3600_000),
|
|
104
|
+
maxBytes: limit(options.maxBytes, DEFAULT_BYTES, 4 * 1024 * 1024 * 1024),
|
|
105
|
+
maxFiles: limit(options.maxFiles, 50_000, 1_000_000),
|
|
106
|
+
maxConcurrent: limit(options.maxConcurrent, 2, 16),
|
|
107
|
+
};
|
|
108
|
+
for (const name of Object.keys(this.#options.sources))
|
|
109
|
+
if (!packageName.test(name))
|
|
110
|
+
throw contentError('INSTALL_SOURCE_NAME_INVALID');
|
|
111
|
+
}
|
|
112
|
+
async #npm(args, cwd, signal) {
|
|
113
|
+
const invocation = await resolveNpmInvocation(args);
|
|
114
|
+
const cache = join(this.root, 'npm-cache');
|
|
115
|
+
const configuration = this.#options.npmUserConfig ?? join(this.root, 'empty.npmrc');
|
|
116
|
+
await mkdir(cache, { recursive: true, mode: 0o700 });
|
|
117
|
+
if (!this.#options.npmUserConfig) {
|
|
118
|
+
await writeFile(configuration, '', { mode: 0o600 });
|
|
119
|
+
await writeFile(configuration + '.global', '', { mode: 0o600 });
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
await execute(invocation.file, invocation.args, {
|
|
123
|
+
cwd,
|
|
124
|
+
signal,
|
|
125
|
+
timeout: this.#options.timeoutMs,
|
|
126
|
+
killSignal: 'SIGTERM',
|
|
127
|
+
maxBuffer: 2 * 1024 * 1024,
|
|
128
|
+
windowsHide: true,
|
|
129
|
+
env: installationEnvironment(cache, configuration),
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
signal.throwIfAborted();
|
|
134
|
+
if (isRecord(error) && typeof error.stderr === 'string' && /\bERESOLVE\b/.test(error.stderr))
|
|
135
|
+
throw contentError('ENVIRONMENT_DEPENDENCY_CONFLICT');
|
|
136
|
+
// Do not include subprocess output/configuration paths in public task errors.
|
|
137
|
+
throw contentError('NPM_INSTALL_FAILED');
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
prepareVersion(workspace, input, validate) {
|
|
141
|
+
if (typeof validate !== 'function')
|
|
142
|
+
return Promise.reject(contentError('STATIC_PREPARER_REQUIRED'));
|
|
143
|
+
return this.#track(this.#prepare(async () => {
|
|
144
|
+
const draft = await workspace.getDraft(input.environmentId);
|
|
145
|
+
if (draft.revision !== input.expectedRevision)
|
|
146
|
+
throw contentError('REVISION_CONFLICT');
|
|
147
|
+
return draft.document;
|
|
148
|
+
}, input, async (directory, signal) => {
|
|
149
|
+
const current = await workspace.getDraft(input.environmentId);
|
|
150
|
+
if (current.revision !== input.expectedRevision)
|
|
151
|
+
throw contentError('REVISION_CONFLICT');
|
|
152
|
+
return workspace.prepareVersion({ ...input, projectDirectory: directory, signal }, validate);
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
/** Transfer an installed project to the host's existing library without a second copy. */
|
|
156
|
+
prepareProject(document, input, consume) {
|
|
157
|
+
return this.#track(this.#prepare(async () => document, input ?? {}, consume));
|
|
158
|
+
}
|
|
159
|
+
#track(task) {
|
|
160
|
+
this.#pending.add(task);
|
|
161
|
+
task.finally(() => this.#pending.delete(task)).catch(() => { });
|
|
162
|
+
return task;
|
|
163
|
+
}
|
|
164
|
+
async #prepare(readDocument, input, consume) {
|
|
165
|
+
if (this.#controller.signal.aborted)
|
|
166
|
+
throw contentError('INSTALLER_CLOSED');
|
|
167
|
+
if (this.#active >= this.#options.maxConcurrent)
|
|
168
|
+
throw contentError('INSTALL_BUSY');
|
|
169
|
+
if (typeof consume !== 'function')
|
|
170
|
+
throw contentError('PROJECT_CONSUMER_REQUIRED');
|
|
171
|
+
this.#active++;
|
|
172
|
+
let directory;
|
|
173
|
+
const signal = AbortSignal.any([
|
|
174
|
+
this.#controller.signal,
|
|
175
|
+
...(input.signal ? [input.signal] : []),
|
|
176
|
+
AbortSignal.timeout(this.#options.timeoutMs),
|
|
177
|
+
]);
|
|
178
|
+
try {
|
|
179
|
+
signal.throwIfAborted();
|
|
180
|
+
await input.onProgress?.({ stage: 'resolving' });
|
|
181
|
+
const document = normalizeEnvironmentDocument(await readDocument());
|
|
182
|
+
if (Object.keys(document.packages).length + document.sources.length > 200)
|
|
183
|
+
throw contentError('INSTALL_PACKAGE_LIMIT');
|
|
184
|
+
const dependencies = {};
|
|
185
|
+
for (const [name, range] of Object.entries(document.packages)) {
|
|
186
|
+
if (typeof range !== 'string' || range.length > 256 || !validRange(range))
|
|
187
|
+
throw contentError('INSTALL_VERSION_INVALID');
|
|
188
|
+
dependencies[name] = range;
|
|
189
|
+
}
|
|
190
|
+
// Acquisition approval is separate from any runtime execution policy. This
|
|
191
|
+
// installer never evaluates author modules or invokes lifecycle scripts.
|
|
192
|
+
if (!this.#options.allowThirdPartyContent && (Object.keys(dependencies).length || document.sources.length))
|
|
193
|
+
throw contentError('THIRD_PARTY_CONTENT_NOT_AUTHORIZED');
|
|
194
|
+
await mkdir(join(this.root, 'staging'), { recursive: true, mode: 0o700 });
|
|
195
|
+
directory = await mkdtemp(join(this.root, 'staging', 'prepare-'));
|
|
196
|
+
await mkdir(join(directory, 'candidates'));
|
|
197
|
+
const provenance = {};
|
|
198
|
+
for (const [index, name] of document.sources.entries()) {
|
|
199
|
+
if (Object.hasOwn(dependencies, name))
|
|
200
|
+
throw contentError('INSTALL_DUPLICATE_PACKAGE');
|
|
201
|
+
const source = this.#options.sources[name];
|
|
202
|
+
if (!source)
|
|
203
|
+
throw contentError('INSTALL_SOURCE_NOT_REGISTERED');
|
|
204
|
+
if (this.#options.offline && (source.kind === 'url' || source.kind === 'git'))
|
|
205
|
+
throw contentError('INSTALL_SOURCE_OFFLINE');
|
|
206
|
+
await input.onProgress?.({ stage: 'acquiring', completed: index, total: document.sources.length });
|
|
207
|
+
const captured = await acquireSource(source, {
|
|
208
|
+
destination: join(directory, 'source-' + index),
|
|
209
|
+
signal,
|
|
210
|
+
maxBytes: this.#options.maxBytes,
|
|
211
|
+
maxFiles: this.#options.maxFiles,
|
|
212
|
+
timeoutMs: this.#options.timeoutMs,
|
|
213
|
+
});
|
|
214
|
+
const manifest = JSON.parse(await readFile(join(captured.directory, 'package.json'), 'utf8'));
|
|
215
|
+
if (manifest.name !== name)
|
|
216
|
+
throw contentError('INSTALL_SOURCE_IDENTITY');
|
|
217
|
+
if (typeof manifest.version !== 'string' || !valid(manifest.version))
|
|
218
|
+
throw contentError('INSTALL_SOURCE_VERSION');
|
|
219
|
+
checkDependencySpecs(manifest);
|
|
220
|
+
try {
|
|
221
|
+
checkLock(JSON.parse(await readFile(join(captured.directory, 'npm-shrinkwrap.json'), 'utf8')));
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
if (errorCode(error) !== 'ENOENT')
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
const output = join(directory, 'packed-' + index);
|
|
228
|
+
await mkdir(output);
|
|
229
|
+
await this.#npm(['pack', '--ignore-scripts', '--json', '--pack-destination', output, '--registry', this.#options.registry], captured.directory, signal);
|
|
230
|
+
const { readdir } = await import('node:fs/promises');
|
|
231
|
+
const files = await readdir(output);
|
|
232
|
+
if (files.length !== 1 || !files[0].endsWith('.tgz'))
|
|
233
|
+
throw contentError('INSTALL_PACK_INVALID');
|
|
234
|
+
const filename = 'candidates/source-' + index + '.tgz';
|
|
235
|
+
await rename(join(output, files[0]), join(directory, filename));
|
|
236
|
+
dependencies[name] = 'file:' + filename;
|
|
237
|
+
provenance[name] = captured.provenance;
|
|
238
|
+
await rm(captured.directory, { recursive: true, force: true });
|
|
239
|
+
await rm(output, { recursive: true, force: true });
|
|
240
|
+
}
|
|
241
|
+
await writeFile(join(directory, 'package.json'), JSON.stringify({
|
|
242
|
+
name: 'arcadia-managed-environment',
|
|
243
|
+
version: '1.0.0',
|
|
244
|
+
private: true,
|
|
245
|
+
dependencies,
|
|
246
|
+
arcadiaManagedSources: provenance,
|
|
247
|
+
}, null, 2) + '\n', { mode: 0o600 });
|
|
248
|
+
await this.#npm([
|
|
249
|
+
'install',
|
|
250
|
+
'--package-lock-only',
|
|
251
|
+
'--ignore-scripts',
|
|
252
|
+
'--omit=dev',
|
|
253
|
+
'--package-lock=true',
|
|
254
|
+
'--no-audit',
|
|
255
|
+
'--no-fund',
|
|
256
|
+
'--registry',
|
|
257
|
+
this.#options.registry,
|
|
258
|
+
...(this.#options.offline ? ['--offline'] : []),
|
|
259
|
+
], directory, signal);
|
|
260
|
+
checkLock(JSON.parse(await readFile(join(directory, 'package-lock.json'), 'utf8')), true);
|
|
261
|
+
await input.onProgress?.({ stage: 'installing' });
|
|
262
|
+
await this.#npm([
|
|
263
|
+
'ci',
|
|
264
|
+
'--ignore-scripts',
|
|
265
|
+
'--omit=dev',
|
|
266
|
+
'--no-audit',
|
|
267
|
+
'--no-fund',
|
|
268
|
+
'--registry',
|
|
269
|
+
this.#options.registry,
|
|
270
|
+
...(this.#options.offline ? ['--offline'] : []),
|
|
271
|
+
], directory, signal);
|
|
272
|
+
await mkdir(join(directory, 'node_modules'), { recursive: true });
|
|
273
|
+
// Standard package/lock validation and bounded material capture before static preparation.
|
|
274
|
+
await input.onProgress?.({ stage: 'verifying' });
|
|
275
|
+
await inspectNpmProject(directory);
|
|
276
|
+
await materialFiles(directory, { signal, maxBytes: this.#options.maxBytes, maxFiles: this.#options.maxFiles });
|
|
277
|
+
signal.throwIfAborted();
|
|
278
|
+
await input.onProgress?.({ stage: 'preparing' });
|
|
279
|
+
return await consume(directory, signal);
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
if (isRecord(error) && (error.name === 'AbortError' || error.name === 'TimeoutError'))
|
|
283
|
+
throw error;
|
|
284
|
+
const diagnostics = isRecord(error) && Array.isArray(error.diagnostics) ? error.diagnostics : [];
|
|
285
|
+
const firstDiagnostic = isRecord(diagnostics[0]) ? diagnostics[0] : undefined;
|
|
286
|
+
const code = isRecord(error) ? (error.code ?? firstDiagnostic?.code) : undefined;
|
|
287
|
+
if (typeof code === 'string' && /^[A-Z][A-Z0-9_]{2,79}$/.test(code))
|
|
288
|
+
throw contentError(code);
|
|
289
|
+
throw contentError('ENVIRONMENT_INSTALL_FAILED');
|
|
290
|
+
}
|
|
291
|
+
finally {
|
|
292
|
+
try {
|
|
293
|
+
if (directory)
|
|
294
|
+
await rm(directory, { recursive: true, force: true });
|
|
295
|
+
}
|
|
296
|
+
finally {
|
|
297
|
+
this.#active--;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
async close() {
|
|
302
|
+
this.#controller.abort(contentError('INSTALLER_CLOSED'));
|
|
303
|
+
await Promise.allSettled([...this.#pending]);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type ManagedSource = {
|
|
2
|
+
kind: 'archive';
|
|
3
|
+
file: string;
|
|
4
|
+
} | {
|
|
5
|
+
kind: 'directory';
|
|
6
|
+
directory: string;
|
|
7
|
+
} | {
|
|
8
|
+
kind: 'url';
|
|
9
|
+
url: string;
|
|
10
|
+
integrity?: string;
|
|
11
|
+
} | {
|
|
12
|
+
kind: 'git';
|
|
13
|
+
url: string;
|
|
14
|
+
commit: string;
|
|
15
|
+
artifactPath?: string;
|
|
16
|
+
};
|
|
17
|
+
export interface SourceAcquisitionOptions {
|
|
18
|
+
destination: string;
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
maxBytes?: number;
|
|
21
|
+
maxFiles?: number;
|
|
22
|
+
timeoutMs?: number;
|
|
23
|
+
}
|
|
24
|
+
/** Only trusted host configuration supplies descriptors. HTTP callers select registered source IDs. */
|
|
25
|
+
export declare function acquireSource(source: ManagedSource, input: SourceAcquisitionOptions): Promise<{
|
|
26
|
+
directory: string;
|
|
27
|
+
provenance: Record<string, string>;
|
|
28
|
+
}>;
|