@blinkhost/cli 2.6.0 → 2.8.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/CHANGELOG.md +13 -0
- package/README.md +534 -2
- package/dist/api.d.ts +2 -2
- package/dist/api.js +57 -8
- package/dist/assistant.js +6 -1
- package/dist/cli.js +162 -9
- package/dist/design.d.ts +5 -0
- package/dist/design.js +82 -0
- package/dist/guidance.d.ts +1 -1
- package/dist/guidance.js +55 -12
- package/dist/javascript-runtime/resource-limits.js +3 -0
- package/dist/javascript-runtime/resource-profiles.js +2 -0
- package/dist/local-dev.d.ts +3 -0
- package/dist/local-dev.js +145 -0
- package/dist/local-development/README.md +410 -0
- package/dist/local-development/artifact-watch.mjs +36 -0
- package/dist/local-development/blinkhost.local.example.json +15 -0
- package/dist/local-development/frontend-proxy.mjs +189 -0
- package/dist/local-development/hello.rs +24 -0
- package/dist/local-development/local-stack.mjs +511 -0
- package/dist/local-development/native-database.mjs +37 -0
- package/dist/local-development/provider-fixtures.example.json +36 -0
- package/dist/local-development/provider-fixtures.mjs +203 -0
- package/dist/local-development/provider-grants.mjs +36 -0
- package/dist/local-development/test-provider-example.mjs +74 -0
- package/dist/local-source-build.d.ts +39 -0
- package/dist/local-source-build.js +225 -0
- package/dist/local-source-watch.d.ts +24 -0
- package/dist/local-source-watch.js +87 -0
- package/dist/local-test-command.d.ts +49 -0
- package/dist/local-test-command.js +128 -0
- package/dist/local-test-config.d.ts +37 -0
- package/dist/local-test-config.js +174 -0
- package/dist/local-test-gates.d.ts +71 -0
- package/dist/local-test-gates.js +247 -0
- package/dist/local-test-go-runner.d.ts +27 -0
- package/dist/local-test-go-runner.js +209 -0
- package/dist/local-test-node-arguments.d.ts +2 -0
- package/dist/local-test-node-arguments.js +14 -0
- package/dist/local-test-node-reporter.d.ts +7 -0
- package/dist/local-test-node-reporter.js +159 -0
- package/dist/local-test-results.d.ts +65 -0
- package/dist/local-test-results.js +163 -0
- package/dist/local-test-rust-runner.d.ts +18 -0
- package/dist/local-test-rust-runner.js +252 -0
- package/dist/local-test-starters.d.ts +3 -0
- package/dist/local-test-starters.js +157 -0
- package/dist/logs.d.ts +43 -0
- package/dist/logs.js +417 -0
- package/dist/module-build-diagnostics.d.ts +10 -0
- package/dist/module-build-diagnostics.js +208 -0
- package/dist/module-build.js +4 -0
- package/dist/release-preparation-diagnostics.d.ts +38 -0
- package/dist/release-preparation-diagnostics.js +204 -0
- package/dist/remote.js +14 -0
- package/dist/templates.d.ts +1 -0
- package/dist/templates.js +4 -1
- package/dist/test-credentials.d.ts +7 -0
- package/dist/test-credentials.js +236 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/workflows.d.ts +39 -2
- package/dist/workflows.js +241 -14
- package/package.json +4 -3
- package/test-runners/python-unittest.py +266 -0
package/dist/api.js
CHANGED
|
@@ -5,6 +5,8 @@ import { withCredentialLock } from './credential-lock.js';
|
|
|
5
5
|
import { validateDeviceTokens } from './device-flow.js';
|
|
6
6
|
import { CliError, EXIT } from './errors.js';
|
|
7
7
|
import { VERSION } from './version.js';
|
|
8
|
+
import { isModuleBuildPath, moduleBuildRejectionGuidance, readModuleBuildRejection, moduleBuildRequestId } from './module-build-diagnostics.js';
|
|
9
|
+
import { isPreparationDiagnosticsRead, readPreparationDiagnosticsResponse } from './release-preparation-diagnostics.js';
|
|
8
10
|
const REQUEST_TIMEOUT_MS = 30_000;
|
|
9
11
|
// Only locally written guidance may reach terminal output. Never echo server
|
|
10
12
|
// details, filenames or arbitrary codes from a source-export error response.
|
|
@@ -68,16 +70,54 @@ function messageFrom(payload, fallback) {
|
|
|
68
70
|
}
|
|
69
71
|
return fallback;
|
|
70
72
|
}
|
|
71
|
-
async function parseResponse(response) {
|
|
73
|
+
async function parseResponse(response, responseLimit) {
|
|
72
74
|
if (response.status === 204)
|
|
73
75
|
return null;
|
|
74
76
|
const type = response.headers.get('content-type') || '';
|
|
77
|
+
if (responseLimit !== undefined) {
|
|
78
|
+
const length = response.headers.get('content-length');
|
|
79
|
+
const reader = response.body?.getReader();
|
|
80
|
+
try {
|
|
81
|
+
if (length !== null && (!/^\d+$/.test(length) || Number(length) > responseLimit)) {
|
|
82
|
+
throw new CliError('The API response exceeds the bounded log-read limit.', EXIT.remote, 'response_too_large');
|
|
83
|
+
}
|
|
84
|
+
const chunks = [];
|
|
85
|
+
let size = 0;
|
|
86
|
+
if (reader)
|
|
87
|
+
while (true) {
|
|
88
|
+
const chunk = await reader.read();
|
|
89
|
+
if (chunk.done)
|
|
90
|
+
break;
|
|
91
|
+
size += chunk.value.byteLength;
|
|
92
|
+
if (size > responseLimit)
|
|
93
|
+
throw new CliError('The API response exceeds the bounded log-read limit.', EXIT.remote, 'response_too_large');
|
|
94
|
+
chunks.push(chunk.value);
|
|
95
|
+
}
|
|
96
|
+
const text = Buffer.concat(chunks, size).toString('utf8');
|
|
97
|
+
if (type.includes('application/json')) {
|
|
98
|
+
try {
|
|
99
|
+
return JSON.parse(text);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
throw new CliError('The API returned invalid log JSON.', EXIT.remote, 'invalid_log_response');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return text;
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
await reader?.cancel().catch(() => undefined);
|
|
109
|
+
reader?.releaseLock();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
75
112
|
if (type.includes('application/json'))
|
|
76
113
|
return response.json();
|
|
77
114
|
const text = await response.text();
|
|
78
115
|
return text.length <= 1024 * 1024 ? text : `${text.slice(0, 1024 * 1024)}\n[truncated]`;
|
|
79
116
|
}
|
|
80
|
-
export async function publicRequest(apiOrigin, path, init = {}) {
|
|
117
|
+
export async function publicRequest(apiOrigin, path, init = {}, responseLimit) {
|
|
118
|
+
if (responseLimit !== undefined && (!Number.isSafeInteger(responseLimit) || responseLimit < 1 || responseLimit > 16 * 1024 * 1024)) {
|
|
119
|
+
throw new CliError('Invalid bounded response size.', EXIT.usage, 'invalid_response_limit');
|
|
120
|
+
}
|
|
81
121
|
const controller = new AbortController();
|
|
82
122
|
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
83
123
|
try {
|
|
@@ -88,10 +128,13 @@ export async function publicRequest(apiOrigin, path, init = {}) {
|
|
|
88
128
|
const response = await fetch(new URL(path, `${apiOrigin}/`), {
|
|
89
129
|
...init,
|
|
90
130
|
redirect: 'error',
|
|
91
|
-
signal: controller.signal,
|
|
131
|
+
signal: init.signal ? AbortSignal.any([controller.signal, init.signal]) : controller.signal,
|
|
92
132
|
headers,
|
|
93
133
|
});
|
|
94
|
-
return { response, data:
|
|
134
|
+
return { response, data: responseLimit !== undefined && (!init.method || init.method === 'GET') && isPreparationDiagnosticsRead(path)
|
|
135
|
+
? await readPreparationDiagnosticsResponse(response, responseLimit)
|
|
136
|
+
: !response.ok && isModuleBuildPath(path)
|
|
137
|
+
? await readModuleBuildRejection(response) : await parseResponse(response, responseLimit) };
|
|
95
138
|
}
|
|
96
139
|
catch (error) {
|
|
97
140
|
if (error instanceof CliError)
|
|
@@ -263,18 +306,24 @@ export class ApiClient {
|
|
|
263
306
|
clearTimeout(timeout);
|
|
264
307
|
}
|
|
265
308
|
}
|
|
266
|
-
async request(path, init = {}) {
|
|
309
|
+
async request(path, init = {}, responseLimit) {
|
|
267
310
|
const headers = new Headers(init.headers);
|
|
268
311
|
headers.set('Authorization', `Bearer ${this.accessToken}`);
|
|
269
312
|
const requestId = headers.get('X-Request-ID') || randomUUID();
|
|
270
313
|
headers.set('X-Request-ID', requestId);
|
|
271
314
|
if (init.method && init.method !== 'GET' && !headers.has('Idempotency-Key'))
|
|
272
315
|
headers.set('Idempotency-Key', randomUUID());
|
|
273
|
-
const result = await publicRequest(this.profile.apiOrigin, path, { ...init, headers });
|
|
316
|
+
const result = await publicRequest(this.profile.apiOrigin, path, { ...init, headers }, responseLimit);
|
|
274
317
|
if (!result.response.ok) {
|
|
275
318
|
const exit = result.response.status === 401 || result.response.status === 403 ? EXIT.auth : result.response.status === 409 ? EXIT.conflict : EXIT.remote;
|
|
276
|
-
const
|
|
277
|
-
|
|
319
|
+
const buildRequest = isModuleBuildPath(path);
|
|
320
|
+
const diagnosticRead = responseLimit !== undefined && (!init.method || init.method === 'GET') && isPreparationDiagnosticsRead(path);
|
|
321
|
+
const responseId = buildRequest || diagnosticRead ? moduleBuildRequestId(result.response.headers.get('x-request-id'), requestId)
|
|
322
|
+
: result.response.headers.get('x-request-id') || requestId;
|
|
323
|
+
const fallback = `BlinkHost returned HTTP ${result.response.status}.`;
|
|
324
|
+
const message = buildRequest ? (result.response.status === 409 ? moduleBuildRejectionGuidance(result.data) : undefined) || fallback
|
|
325
|
+
: diagnosticRead ? fallback : messageFrom(result.data, fallback);
|
|
326
|
+
throw new CliError(message, exit, `api_${result.response.status}`, [`Request ID: ${responseId}`]);
|
|
278
327
|
}
|
|
279
328
|
return result.data;
|
|
280
329
|
}
|
package/dist/assistant.js
CHANGED
|
@@ -5,6 +5,7 @@ import { CliError, EXIT } from './errors.js';
|
|
|
5
5
|
import { validateCompatibility } from './compatibility.js';
|
|
6
6
|
import { validateResearchCatalog } from './research.js';
|
|
7
7
|
import { validateModuleBuild } from './module-build.js';
|
|
8
|
+
import { moduleBuildFailureGuidance } from './module-build-diagnostics.js';
|
|
8
9
|
import { validatePeerResponse } from './peer-review.js';
|
|
9
10
|
import { starterName, starterLanguage, validateStarter } from './starter.js';
|
|
10
11
|
const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
@@ -414,8 +415,12 @@ export async function runAssistant(input, profile) {
|
|
|
414
415
|
}
|
|
415
416
|
const client = await ApiClient.create(profile);
|
|
416
417
|
const result = await client.request(path, body === undefined ? {} : { method, body: JSON.stringify(body) });
|
|
417
|
-
if (moduleBuildExpected)
|
|
418
|
+
if (moduleBuildExpected) {
|
|
418
419
|
validateModuleBuild(result, moduleBuildExpected, action);
|
|
420
|
+
const guidance = moduleBuildFailureGuidance(result);
|
|
421
|
+
if (guidance)
|
|
422
|
+
message = `Backend module build failed. ${guidance}`;
|
|
423
|
+
}
|
|
419
424
|
if (starterExpected)
|
|
420
425
|
validateStarter(result, starterExpected, action);
|
|
421
426
|
if (peerExpected)
|
package/dist/cli.js
CHANGED
|
@@ -12,15 +12,43 @@ import { ApiClient } from './api.js';
|
|
|
12
12
|
import { login, logout } from './auth.js';
|
|
13
13
|
import { runAssistant } from './assistant.js';
|
|
14
14
|
import { runSeo } from './seo.js';
|
|
15
|
+
import { runDesign } from './design.js';
|
|
15
16
|
import { exportProject } from './project-export.js';
|
|
16
17
|
import { activeProfile, readConfig, validateProfileName, writeConfig } from './config.js';
|
|
17
18
|
import { openPreview, projectStatus, rawApi, readProjectLink, runFunctions, runRemote, runSecrets, syncProject, unlinkProject, uploadAsset, waitForRemote, writeProjectLink } from './remote.js';
|
|
18
|
-
import { checkForUpdate, ciCheck, completion, maybeUpdateNotice, observability, releaseNotes, runDev, runPlugins, supportBundle, testProject } from './workflows.js';
|
|
19
|
+
import { checkForUpdate, ciCheck, completion, localProjectCheckMessage, maybeUpdateNotice, observability, releaseNotes, runDev, runPlugins, supportBundle, testProject } from './workflows.js';
|
|
20
|
+
import { runLogCommand, renderLogEntry, writeLogOutput } from './logs.js';
|
|
19
21
|
import { documentationIndex, documentationTopic, quickstart, renderTopHelp, renderTopic, searchDocumentation, TOP_LEVEL_COMMANDS } from './guidance.js';
|
|
20
22
|
import { VERSION, supportedNodeVersion } from './version.js';
|
|
21
23
|
import { terminalJson, terminalText } from './terminal.js';
|
|
24
|
+
import { LocalTestChecksFailure, LocalTestCommandFailure, sanitizeLocalTestOutput } from './local-test-command.js';
|
|
25
|
+
import { runTestCredentials } from './test-credentials.js';
|
|
22
26
|
let quietOutput = false;
|
|
23
27
|
let verboseOutput = false;
|
|
28
|
+
let incompleteLogOutput = false;
|
|
29
|
+
async function writeLocalCheckOutput(stream, value, signal) {
|
|
30
|
+
if (!value)
|
|
31
|
+
return true;
|
|
32
|
+
let failed = false;
|
|
33
|
+
const closed = () => { failed = true; };
|
|
34
|
+
stream.on('error', closed);
|
|
35
|
+
let written = false;
|
|
36
|
+
try {
|
|
37
|
+
written = await writeLogOutput(stream, value, signal);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
failed = true;
|
|
41
|
+
}
|
|
42
|
+
if (!written || failed) {
|
|
43
|
+
incompleteLogOutput = true;
|
|
44
|
+
stream.once('close', () => stream.off('error', closed));
|
|
45
|
+
stream.destroy();
|
|
46
|
+
stream.unref?.();
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
stream.off('error', closed);
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
24
52
|
function emit(output, json) {
|
|
25
53
|
if (json)
|
|
26
54
|
process.stdout.write(`${terminalJson(JSON.stringify(output))}\n`);
|
|
@@ -102,6 +130,7 @@ async function commandCreate(args, json) {
|
|
|
102
130
|
const packageManager = (takeOption(args, '--package-manager') ?? 'npm');
|
|
103
131
|
const moduleValues = takeRepeatedOption(args, '--module');
|
|
104
132
|
const database = takeOption(args, '--database');
|
|
133
|
+
const tests = takeFlag(args, '--tests');
|
|
105
134
|
const noInstall = takeFlag(args, '--no-install');
|
|
106
135
|
const explicitInstall = takeFlag(args, '--install');
|
|
107
136
|
if (noInstall && explicitInstall)
|
|
@@ -118,7 +147,7 @@ async function commandCreate(args, json) {
|
|
|
118
147
|
if (new Set(modules.map((item) => item.name)).size !== modules.length)
|
|
119
148
|
throw new CliError('Backend module names must be unique.', EXIT.usage, 'duplicate_module');
|
|
120
149
|
const target = resolveLocalPath(name);
|
|
121
|
-
const scaffold = createScaffold({ name, framework, packageManager, modules, ...(database ? { database } : {}) });
|
|
150
|
+
const scaffold = createScaffold({ name, framework, packageManager, modules, ...(database ? { database } : {}), ...(tests ? { tests } : {}) });
|
|
122
151
|
await writeScaffoldAtomically(target, scaffold.files, scaffold.manifest);
|
|
123
152
|
if (install && framework !== 'html') {
|
|
124
153
|
const installArgs = {
|
|
@@ -313,13 +342,58 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
313
342
|
else if (command === 'doctor')
|
|
314
343
|
await commandDoctor(args, json);
|
|
315
344
|
else if (command === 'test') {
|
|
316
|
-
const
|
|
317
|
-
|
|
345
|
+
const controller = new AbortController();
|
|
346
|
+
const interrupt = () => controller.abort('SIGINT');
|
|
347
|
+
const terminate = () => controller.abort('SIGTERM');
|
|
348
|
+
process.once('SIGINT', interrupt);
|
|
349
|
+
process.once('SIGTERM', terminate);
|
|
350
|
+
try {
|
|
351
|
+
let value = '';
|
|
352
|
+
let exitCode = EXIT.success;
|
|
353
|
+
let stream = process.stdout;
|
|
354
|
+
try {
|
|
355
|
+
const data = await testProject(args, json, controller.signal);
|
|
356
|
+
const message = localProjectCheckMessage(data);
|
|
357
|
+
value = json ? terminalJson(JSON.stringify({ ok: true, command, message, data })) + '\n'
|
|
358
|
+
: quietOutput ? '' : terminalText(message) + '\n' + terminalJson(JSON.stringify(data, null, 2)) + '\n';
|
|
359
|
+
}
|
|
360
|
+
catch (error) {
|
|
361
|
+
const failure = error instanceof CliError ? error : new CliError(error instanceof Error ? error.message : String(error), EXIT.internal, 'internal_error');
|
|
362
|
+
exitCode = failure.exitCode;
|
|
363
|
+
const message = sanitizeLocalTestOutput(failure.message);
|
|
364
|
+
const details = failure.details.map(sanitizeLocalTestOutput);
|
|
365
|
+
if (json)
|
|
366
|
+
value = terminalJson(JSON.stringify({ ok: false, command, error: {
|
|
367
|
+
code: failure.code, message, details,
|
|
368
|
+
...(failure instanceof LocalTestCommandFailure ? { execution: failure.execution } : {}),
|
|
369
|
+
...(failure instanceof LocalTestChecksFailure && failure.projectChecks ? { project_checks: failure.projectChecks } : {}),
|
|
370
|
+
} })) + '\n';
|
|
371
|
+
else {
|
|
372
|
+
stream = process.stderr;
|
|
373
|
+
value = terminalText(`Error: ${message}\n` + details.map(detail => ` - ${detail}\n`).join('')
|
|
374
|
+
+ (failure instanceof LocalTestCommandFailure ? failure.execution.output.stdout + failure.execution.output.stderr : ''));
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
// A cancelled command still gets an independent, bounded attempt to emit its receipt.
|
|
378
|
+
const outputSignal = controller.signal.aborted || exitCode !== EXIT.success
|
|
379
|
+
? AbortSignal.timeout(1000) : AbortSignal.any([controller.signal, AbortSignal.timeout(3000)]);
|
|
380
|
+
const written = await writeLocalCheckOutput(stream, value, outputSignal);
|
|
381
|
+
return controller.signal.aborted ? controller.signal.reason === 'SIGTERM' ? 143 : 130
|
|
382
|
+
: written ? exitCode : EXIT.filesystem;
|
|
383
|
+
}
|
|
384
|
+
finally {
|
|
385
|
+
process.off('SIGINT', interrupt);
|
|
386
|
+
process.off('SIGTERM', terminate);
|
|
387
|
+
}
|
|
318
388
|
}
|
|
319
389
|
else if (command === 'ai') {
|
|
320
390
|
const result = await runAssistant(args, profile);
|
|
321
391
|
emit({ ok: true, command: 'ai', ...result }, json);
|
|
322
392
|
}
|
|
393
|
+
else if (command === 'design') {
|
|
394
|
+
const data = await runDesign(args, profile);
|
|
395
|
+
emit({ ok: true, command, message: 'Design references loaded. Adapt to the project and retain source notices.', data }, json);
|
|
396
|
+
}
|
|
323
397
|
else if (command === 'seo') {
|
|
324
398
|
const data = await runSeo(args, profile);
|
|
325
399
|
emit({ ok: true, command, message: 'SEO evidence loaded.', data }, json);
|
|
@@ -451,15 +525,86 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
451
525
|
const data = await runSecrets(args, profile);
|
|
452
526
|
emit({ ok: true, command, message: 'Secret operation completed.', data }, json);
|
|
453
527
|
}
|
|
528
|
+
else if (command === 'test-credentials') {
|
|
529
|
+
const data = await runTestCredentials(args, profile);
|
|
530
|
+
emit({ ok: true, command, message: 'Test credential operation completed.', data }, json);
|
|
531
|
+
}
|
|
454
532
|
else if (command === 'functions') {
|
|
455
533
|
const data = await runFunctions(args, profile);
|
|
456
534
|
emit({ ok: true, command, message: 'Function operation completed.', data }, json);
|
|
457
535
|
}
|
|
458
536
|
else if (command === 'dev') {
|
|
459
|
-
|
|
460
|
-
|
|
537
|
+
let value = '', exitCode = EXIT.success;
|
|
538
|
+
let stream = process.stdout;
|
|
539
|
+
try {
|
|
540
|
+
const data = await runDev(args, json, (ready, signal) => writeLocalCheckOutput(process.stdout, ready, signal));
|
|
541
|
+
const message = 'Local development process finished.';
|
|
542
|
+
value = json ? terminalJson(JSON.stringify({ ok: true, command, message, data })) + '\n'
|
|
543
|
+
: quietOutput ? '' : terminalText(message) + '\n' + terminalJson(JSON.stringify(data, null, 2)) + '\n';
|
|
544
|
+
}
|
|
545
|
+
catch (error) {
|
|
546
|
+
const failure = error instanceof CliError ? error : new CliError('Local development failed.', EXIT.internal, 'local_dev_failed');
|
|
547
|
+
exitCode = failure.exitCode;
|
|
548
|
+
value = json ? terminalJson(JSON.stringify({ ok: false, command, error: {
|
|
549
|
+
code: failure.code, message: failure.message, details: failure.details
|
|
550
|
+
} })) + '\n'
|
|
551
|
+
: terminalText(`Error: ${failure.message}\n` + failure.details.map(detail => ` - ${detail}\n`).join(''));
|
|
552
|
+
if (!json)
|
|
553
|
+
stream = process.stderr;
|
|
554
|
+
}
|
|
555
|
+
// Owned companions have already stopped. Final output is independently bounded.
|
|
556
|
+
if (incompleteLogOutput)
|
|
557
|
+
return exitCode === EXIT.success ? EXIT.filesystem : exitCode;
|
|
558
|
+
return await writeLocalCheckOutput(stream, value, AbortSignal.timeout(1000)) ? exitCode : EXIT.filesystem;
|
|
559
|
+
}
|
|
560
|
+
else if (command === 'logs') {
|
|
561
|
+
const controller = new AbortController();
|
|
562
|
+
let interrupted = 0;
|
|
563
|
+
const interrupt = () => { interrupted = 130; controller.abort(); };
|
|
564
|
+
const terminate = () => { interrupted = 143; controller.abort(); };
|
|
565
|
+
process.once('SIGINT', interrupt);
|
|
566
|
+
process.once('SIGTERM', terminate);
|
|
567
|
+
let outputError;
|
|
568
|
+
let outputAbandoned = false;
|
|
569
|
+
const brokenOutput = (error) => { outputError = error; controller.abort(); };
|
|
570
|
+
process.stdout.on('error', brokenOutput);
|
|
571
|
+
try {
|
|
572
|
+
await runLogCommand(args, profile, async (entry, activeSignal) => {
|
|
573
|
+
if (!json && quietOutput)
|
|
574
|
+
return;
|
|
575
|
+
if (outputAbandoned)
|
|
576
|
+
return;
|
|
577
|
+
outputAbandoned = !await writeLogOutput(process.stdout, renderLogEntry(entry, json), activeSignal.aborted && entry.kind !== 'event' ? AbortSignal.timeout(1000) : activeSignal);
|
|
578
|
+
}, controller.signal);
|
|
579
|
+
}
|
|
580
|
+
catch (error) {
|
|
581
|
+
if (outputError || ['EPIPE', 'ERR_STREAM_DESTROYED'].includes(error.code || '')) {
|
|
582
|
+
outputError = error instanceof Error ? error : new Error(String(error));
|
|
583
|
+
}
|
|
584
|
+
else
|
|
585
|
+
throw error;
|
|
586
|
+
}
|
|
587
|
+
finally {
|
|
588
|
+
process.off('SIGINT', interrupt);
|
|
589
|
+
process.off('SIGTERM', terminate);
|
|
590
|
+
if (outputAbandoned || outputError) {
|
|
591
|
+
incompleteLogOutput = true;
|
|
592
|
+
process.stdout.once('close', () => process.stdout.off('error', brokenOutput));
|
|
593
|
+
process.stdout.destroy();
|
|
594
|
+
// Node preserves stdout's descriptor when destroying the stream.
|
|
595
|
+
// A blocked pipe must not keep this interrupted command alive.
|
|
596
|
+
process.stdout.unref?.();
|
|
597
|
+
}
|
|
598
|
+
else
|
|
599
|
+
process.stdout.off('error', brokenOutput);
|
|
600
|
+
}
|
|
601
|
+
if (outputError) {
|
|
602
|
+
process.stderr.write(`Error: Log output closed: ${terminalText(outputError.message)}\n`);
|
|
603
|
+
return EXIT.filesystem;
|
|
604
|
+
}
|
|
605
|
+
return interrupted || EXIT.success;
|
|
461
606
|
}
|
|
462
|
-
else if (command === '
|
|
607
|
+
else if (command === 'metrics' || command === 'analytics') {
|
|
463
608
|
const data = await observability(command, args, profile);
|
|
464
609
|
emit({ ok: true, command, message: `${command} loaded.`, data }, json);
|
|
465
610
|
}
|
|
@@ -508,7 +653,7 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
508
653
|
const suggestion = commandSuggestion(command);
|
|
509
654
|
throw new CliError(`Unknown command: ${command}.${suggestion ? ` Did you mean \`${suggestion}\`?` : ' Run `blinkhost docs` to list commands.'}`, EXIT.usage, 'unknown_command');
|
|
510
655
|
}
|
|
511
|
-
if (!json && !quietOutput && !nonInteractive && command !== 'update') {
|
|
656
|
+
if (!json && !quietOutput && !nonInteractive && command !== 'update' && command !== 'test' && command !== 'dev') {
|
|
512
657
|
const notice = await maybeUpdateNotice(profile);
|
|
513
658
|
if (notice)
|
|
514
659
|
process.stderr.write(`\n${terminalText(notice)}\n`);
|
|
@@ -518,11 +663,15 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
518
663
|
catch (error) {
|
|
519
664
|
const failure = error instanceof CliError ? error : new CliError(error instanceof Error ? error.message : String(error), EXIT.internal, 'internal_error');
|
|
520
665
|
if (json)
|
|
521
|
-
process.stdout.write(`${terminalJson(JSON.stringify({ ok: false, command: command ?? '', error: { code: failure.code, message: failure.message, details: failure.details
|
|
666
|
+
process.stdout.write(`${terminalJson(JSON.stringify({ ok: false, command: command ?? '', error: { code: failure.code, message: failure.message, details: failure.details,
|
|
667
|
+
...(failure instanceof LocalTestCommandFailure ? { execution: failure.execution } : {}) } }))}\n`);
|
|
522
668
|
else {
|
|
523
669
|
process.stderr.write(`Error: ${terminalText(failure.message)}\n`);
|
|
524
670
|
for (const detail of failure.details)
|
|
525
671
|
process.stderr.write(` - ${terminalText(detail)}\n`);
|
|
672
|
+
if (failure instanceof LocalTestCommandFailure) {
|
|
673
|
+
process.stderr.write(terminalText(failure.execution.output.stdout + failure.execution.output.stderr));
|
|
674
|
+
}
|
|
526
675
|
if (verboseOutput)
|
|
527
676
|
process.stderr.write(`Code: ${failure.code}; exit: ${failure.exitCode}\n`);
|
|
528
677
|
}
|
|
@@ -531,5 +680,9 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
531
680
|
}
|
|
532
681
|
if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
|
|
533
682
|
process.exitCode = await main();
|
|
683
|
+
// Cleanup has finished. A pending stdout write can retain a libuv request
|
|
684
|
+
// even after unref(), so abandon it only when bounded logging gave up output.
|
|
685
|
+
if (incompleteLogOutput)
|
|
686
|
+
process.exit(process.exitCode);
|
|
534
687
|
}
|
|
535
688
|
//# sourceMappingURL=cli.js.map
|
package/dist/design.d.ts
ADDED
package/dist/design.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ApiClient } from './api.js';
|
|
2
|
+
import { CliError, EXIT } from './errors.js';
|
|
3
|
+
export function designArguments(args) {
|
|
4
|
+
args = [...args];
|
|
5
|
+
const action = args.shift() || 'list';
|
|
6
|
+
const take = (name) => {
|
|
7
|
+
const i = args.indexOf(name);
|
|
8
|
+
if (i < 0)
|
|
9
|
+
return;
|
|
10
|
+
const value = args[i + 1];
|
|
11
|
+
if (!value || value.startsWith('--'))
|
|
12
|
+
throw new CliError(`${name} needs a value.`, EXIT.usage, 'missing_option_value');
|
|
13
|
+
args.splice(i, 2);
|
|
14
|
+
return value;
|
|
15
|
+
};
|
|
16
|
+
const project = take('--project');
|
|
17
|
+
const revision = take('--revision');
|
|
18
|
+
const framework = take('--framework');
|
|
19
|
+
const limit = take('--limit');
|
|
20
|
+
const attachment = take('--attachment');
|
|
21
|
+
const imageIndex = take('--image-index');
|
|
22
|
+
const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
23
|
+
if (!project || !uuid.test(project))
|
|
24
|
+
throw new CliError('Use --project with the project UUID.', EXIT.usage, 'project_id_invalid');
|
|
25
|
+
const resources = { list: 'design_catalogue', search: 'design_search', show: 'design_reference', notices: 'design_notices' };
|
|
26
|
+
if (!resources[action])
|
|
27
|
+
throw new CliError('Use design list, search QUERY, show REFERENCE_ID or notices REFERENCE_ID.', EXIT.usage, 'design_command_invalid');
|
|
28
|
+
const body = { resource: resources[action] };
|
|
29
|
+
if (action === 'search') {
|
|
30
|
+
const query = args.shift();
|
|
31
|
+
if (!query || query.trim().length < 2 || query.length > 600 || /[\x00-\x1f\x7f]/.test(query))
|
|
32
|
+
throw new CliError('Use a focused search of 2–600 characters.', EXIT.usage, 'design_query_invalid');
|
|
33
|
+
body.design_query = query.trim();
|
|
34
|
+
if (framework)
|
|
35
|
+
body.design_framework = framework;
|
|
36
|
+
if (limit) {
|
|
37
|
+
if (!/^[1-8]$/.test(limit))
|
|
38
|
+
throw new CliError('--limit must be 1–8.', EXIT.usage, 'design_limit_invalid');
|
|
39
|
+
body.design_limit = Number(limit);
|
|
40
|
+
}
|
|
41
|
+
if (attachment) {
|
|
42
|
+
if (!uuid.test(attachment) || (imageIndex !== undefined && !/^[0-7]$/.test(imageIndex)))
|
|
43
|
+
throw new CliError('Use a ready upload UUID and an image index of 0–7.', EXIT.usage, 'design_image_invalid');
|
|
44
|
+
body.attachment_id = attachment;
|
|
45
|
+
body.design_image_index = Number(imageIndex || '0');
|
|
46
|
+
}
|
|
47
|
+
else if (imageIndex !== undefined)
|
|
48
|
+
throw new CliError('--image-index needs --attachment.', EXIT.usage, 'design_image_invalid');
|
|
49
|
+
if (revision)
|
|
50
|
+
args.push('--revision');
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
if (framework || limit || attachment || imageIndex !== undefined)
|
|
54
|
+
args.push('search-only options');
|
|
55
|
+
if (action !== 'list') {
|
|
56
|
+
const reference = args.shift();
|
|
57
|
+
if (!reference || reference.length > 190 || /[\x00-\x1f\x7f]/.test(reference) || !revision || !/^[a-f0-9]{64}$/.test(revision))
|
|
58
|
+
throw new CliError('Use a reference ID and --revision from design search.', EXIT.usage, 'design_reference_invalid');
|
|
59
|
+
body.design_reference_id = reference;
|
|
60
|
+
body.design_revision = revision;
|
|
61
|
+
}
|
|
62
|
+
else if (revision)
|
|
63
|
+
args.push('--revision');
|
|
64
|
+
}
|
|
65
|
+
if (args.length)
|
|
66
|
+
throw new CliError('Unexpected design argument. Use blinkhost help design.', EXIT.usage, 'unexpected_argument');
|
|
67
|
+
return { project, body };
|
|
68
|
+
}
|
|
69
|
+
export async function runDesign(args, profile) {
|
|
70
|
+
const { project, body } = designArguments(args);
|
|
71
|
+
const client = await ApiClient.create(profile);
|
|
72
|
+
const metadata = await client.request(`/api/sites/${project}/`);
|
|
73
|
+
const workspace = metadata?.organization;
|
|
74
|
+
if (metadata?.id !== project || !(typeof workspace === 'string' && /^[1-9]\d*$/.test(workspace)
|
|
75
|
+
|| typeof workspace === 'number' && Number.isSafeInteger(workspace) && workspace > 0)) {
|
|
76
|
+
throw new CliError('Design references need an accessible project in a workspace.', EXIT.remote, 'project_workspace_unavailable');
|
|
77
|
+
}
|
|
78
|
+
return client.request(`/api/idam/projects/${project}/design-references/`, {
|
|
79
|
+
method: 'POST', headers: { 'X-Organization-Id': String(workspace) }, body: JSON.stringify(body),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=design.js.map
|
package/dist/guidance.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface DocumentationTopic {
|
|
|
8
8
|
related: string[];
|
|
9
9
|
url: string;
|
|
10
10
|
}
|
|
11
|
-
export declare const TOP_LEVEL_COMMANDS: ("plugins" | "profile" | "modules" | "dev" | "databases" | "secrets" | "manifest" | "
|
|
11
|
+
export declare const TOP_LEVEL_COMMANDS: ("plugins" | "profile" | "builds" | "modules" | "dev" | "databases" | "secrets" | "manifest" | "test" | "projects" | "repositories" | "connections" | "previews" | "deployments" | "bindings" | "assets" | "organizations" | "templates" | "approvals" | "handoffs" | "policies" | "workloads" | "create" | "update" | "design" | "ai" | "seo" | "ci" | "auth" | "quickstart" | "init" | "doctor" | "validate" | "functions" | "test-credentials" | "logs" | "metrics" | "analytics" | "support" | "completion" | "api" | "docs")[];
|
|
12
12
|
export declare function documentationIndex(): {
|
|
13
13
|
schema: string;
|
|
14
14
|
cli_version: string;
|