@dokebi/cli 0.4.28 → 0.4.30
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/AI.md +8 -8
- package/catalog.json +25 -25
- package/dist/check/asset-rules.js +4 -1
- package/dist/check/i18n-rules.d.ts +6 -1
- package/dist/check/i18n-rules.js +42 -7
- package/dist/check/seal-rules.js +6 -2
- package/dist/config-edit.js +9 -2
- package/dist/config-secrets.d.ts +11 -0
- package/dist/config-secrets.js +83 -13
- package/dist/deploy-scripts.d.ts +2 -2
- package/dist/deploy-scripts.js +28 -6
- package/dist/deploy-templates.d.ts +1 -1
- package/dist/deploy-templates.js +39 -13
- package/dist/deploy.d.ts +7 -0
- package/dist/deploy.js +64 -49
- package/dist/dev-infra.js +24 -7
- package/dist/install-module.d.ts +6 -6
- package/dist/install-module.js +6 -6
- package/dist/output.d.ts +1 -1
- package/dist/output.js +1 -1
- package/dist/plugin-lifecycle.d.ts +2 -1
- package/dist/plugin-lifecycle.js +11 -1
- package/dist/production-doctor.js +28 -13
- package/dist/project.d.ts +1 -0
- package/dist/project.js +1 -1
- package/dist/remote-verify.js +11 -5
- package/dist/server.d.ts +3 -1
- package/dist/server.js +11 -3
- package/package.json +2 -2
package/dist/deploy.js
CHANGED
|
@@ -6,7 +6,7 @@ import { dirname, join } from 'node:path';
|
|
|
6
6
|
import { parseConfig } from '@dokebi/config';
|
|
7
7
|
import { isMap, isScalar, isSeq, parseDocument } from 'yaml';
|
|
8
8
|
import { isPlaceholder } from './config-init.js';
|
|
9
|
-
import { requiredSecretPaths, schemaTypes, unreadableWarning } from './config-secrets.js';
|
|
9
|
+
import { indexedPath, namedPath, requiredSecretPaths, schemaTypes, unreadableWarning, valueAt, } from './config-secrets.js';
|
|
10
10
|
import { configShow } from './config-show.js';
|
|
11
11
|
import { CONFIG_FILE, renderConfig } from './configuration.js';
|
|
12
12
|
import { BACKUP_SCRIPT, RESTORE_DRILL_SCRIPT } from './deploy-scripts.js';
|
|
@@ -124,38 +124,25 @@ async function secretPaths(root, sample) {
|
|
|
124
124
|
const planned = await requiredSecretPaths(root, (development === undefined ? sampleOptions : parseConfig(development).options));
|
|
125
125
|
for (const path of planned.paths)
|
|
126
126
|
found.add(path);
|
|
127
|
-
// A secret inside a list item (logging.targets.
|
|
128
|
-
//
|
|
127
|
+
// A secret inside a list item is named by the item (logging.targets.2.token →
|
|
128
|
+
// logging.targets.studio.token): the secrets file fills that field of the item only, whatever
|
|
129
|
+
// the order of the list.
|
|
129
130
|
const sources = [
|
|
130
|
-
sampleOptions,
|
|
131
131
|
development === undefined ? {} : parseConfig(development).options,
|
|
132
|
+
sampleOptions,
|
|
132
133
|
];
|
|
133
|
-
const
|
|
134
|
+
const named = (path) => {
|
|
134
135
|
const keys = path.split('.');
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return keys.slice(0, end).join('.');
|
|
138
|
-
return path;
|
|
136
|
+
const source = sources.find((options) => valueAt(options, keys) !== undefined) ?? sampleOptions;
|
|
137
|
+
return namedPath(source, keys).join('.');
|
|
139
138
|
};
|
|
140
|
-
const paths = [...new Set([...found].map(
|
|
139
|
+
const paths = [...new Set([...found].map(named))].sort();
|
|
141
140
|
// A path under another listed path is covered by it.
|
|
142
141
|
return {
|
|
143
142
|
paths: paths.filter((path) => !paths.some((other) => path !== other && path.startsWith(`${other}.`))),
|
|
144
143
|
unreadable: planned.unreadable,
|
|
145
144
|
};
|
|
146
145
|
}
|
|
147
|
-
function valueAt(options, path) {
|
|
148
|
-
let value = options;
|
|
149
|
-
for (const key of path) {
|
|
150
|
-
if (Array.isArray(value) && /^\d+$/.test(key))
|
|
151
|
-
value = value[Number(key)];
|
|
152
|
-
else if (value && typeof value === 'object' && Object.hasOwn(value, key))
|
|
153
|
-
value = value[key];
|
|
154
|
-
else
|
|
155
|
-
return undefined;
|
|
156
|
-
}
|
|
157
|
-
return value;
|
|
158
|
-
}
|
|
159
146
|
/** A placeholder for a secret of the secrets sample, saying what goes there (never a value). */
|
|
160
147
|
function placeholderFor(path, at, current, types) {
|
|
161
148
|
const kind = typeof current === 'string'
|
|
@@ -184,9 +171,11 @@ function placeholderFor(path, at, current, types) {
|
|
|
184
171
|
/** The settings sample of one instance: the sample without secrets, instance values, secrets list. */
|
|
185
172
|
function instanceSample(sample, at, target, plugins, secrets, schemas) {
|
|
186
173
|
const document = parseDocument(sample, { version: '1.2' });
|
|
174
|
+
const options = parseConfig(sample).options;
|
|
187
175
|
for (const path of secrets) {
|
|
188
|
-
// Only where the sample has the path: a section left empty (`connections:`) is null there.
|
|
189
|
-
|
|
176
|
+
// Only where the sample has the path: a section left empty (`connections:`) is null there. A
|
|
177
|
+
// list item named by the path is found as the secrets file finds it.
|
|
178
|
+
const keys = ['options', ...indexedPath(options, path.split('.'))];
|
|
190
179
|
let node = document.contents;
|
|
191
180
|
for (const key of keys.slice(0, -1))
|
|
192
181
|
node = isMap(node) || isSeq(node) ? node.get(key, true) : undefined;
|
|
@@ -315,27 +304,27 @@ async function knownInstances(root) {
|
|
|
315
304
|
}
|
|
316
305
|
return found;
|
|
317
306
|
}
|
|
318
|
-
/**
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
307
|
+
/**
|
|
308
|
+
* The port of each instance asked for. An instance's port lives in its settings sample
|
|
309
|
+
* (`dokebi-web.port`); without @dokebi/web nothing listens, so no instance has one (0) and
|
|
310
|
+
* `--port` is refused. With it a new instance other than production (3000) and staging (3001)
|
|
311
|
+
* needs `--port`, and two instances of the server never share one.
|
|
312
|
+
*/
|
|
313
|
+
export function instancePorts(names, known, port, web) {
|
|
314
|
+
const ports = new Map();
|
|
315
|
+
if (!web) {
|
|
316
|
+
if (port !== undefined)
|
|
317
|
+
throw new CliError('USAGE', '--port: this project has no web server (@dokebi/web), so its instances listen on no port', {
|
|
328
318
|
phase: 'arguments',
|
|
319
|
+
details: { fix: 'leave --port out, or npx dokebi add @dokebi/web first' },
|
|
329
320
|
});
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
const known = await knownInstances(root);
|
|
335
|
-
const ports = new Map();
|
|
321
|
+
for (const name of names)
|
|
322
|
+
ports.set(name, 0);
|
|
323
|
+
return ports;
|
|
324
|
+
}
|
|
336
325
|
for (const name of names) {
|
|
337
|
-
const
|
|
338
|
-
if (
|
|
326
|
+
const chosen = port ?? known.get(name) ?? DEFAULT_PORTS[name];
|
|
327
|
+
if (chosen === undefined || chosen === 0)
|
|
339
328
|
throw new CliError('PORT_REQUIRED', `The instance ${name} needs a port: --port <n>`, {
|
|
340
329
|
phase: 'arguments',
|
|
341
330
|
details: {
|
|
@@ -343,21 +332,44 @@ export async function deployInit(input, options) {
|
|
|
343
332
|
fix: `npx dokebi deploy init --instance ${name} --port <a free port such as 3002>`,
|
|
344
333
|
},
|
|
345
334
|
});
|
|
346
|
-
ports.set(name,
|
|
335
|
+
ports.set(name, chosen);
|
|
347
336
|
}
|
|
348
|
-
//
|
|
349
|
-
|
|
350
|
-
|
|
337
|
+
// A known instance without a port (made before @dokebi/web) takes none.
|
|
338
|
+
const all = [...known, ...ports].filter(([, chosen]) => chosen !== 0);
|
|
339
|
+
for (const [name, chosen] of all) {
|
|
340
|
+
const other = all.find(([otherName, otherPort]) => otherName !== name && otherPort === chosen);
|
|
351
341
|
if (other)
|
|
352
|
-
throw new CliError('PORT_IN_USE', `The instances ${name} and ${other[0]} would both listen on 127.0.0.1:${
|
|
342
|
+
throw new CliError('PORT_IN_USE', `The instances ${name} and ${other[0]} would both listen on 127.0.0.1:${chosen}`, {
|
|
353
343
|
phase: 'arguments',
|
|
354
344
|
details: {
|
|
355
|
-
port,
|
|
345
|
+
port: chosen,
|
|
356
346
|
instances: [name, other[0]],
|
|
357
347
|
fix: `give one of them another port: --instance ${name} --port <n>`,
|
|
358
348
|
},
|
|
359
349
|
});
|
|
360
350
|
}
|
|
351
|
+
return ports;
|
|
352
|
+
}
|
|
353
|
+
function instanceUsage(name) {
|
|
354
|
+
return new CliError('USAGE', `--instance ${name}: lowercase letters, digits and -, 1 to 24 characters, starting with a letter`, { phase: 'arguments' });
|
|
355
|
+
}
|
|
356
|
+
/** `dokebi deploy init` (D-0184 §2). */
|
|
357
|
+
export async function deployInit(input, options) {
|
|
358
|
+
const root = await realpath(input);
|
|
359
|
+
const state = await projectState(root);
|
|
360
|
+
const app = await appName(root);
|
|
361
|
+
const plugins = state.plugins.map((plugin) => optionsKey(plugin));
|
|
362
|
+
const names = [...new Set(options.instances)];
|
|
363
|
+
for (const name of names)
|
|
364
|
+
if (!INSTANCE.test(name))
|
|
365
|
+
throw instanceUsage(name);
|
|
366
|
+
if (options.port !== undefined && names.length !== 1)
|
|
367
|
+
throw new CliError('USAGE', '--port names the port of one instance; give one --instance with it', {
|
|
368
|
+
phase: 'arguments',
|
|
369
|
+
});
|
|
370
|
+
const known = await knownInstances(root);
|
|
371
|
+
const web = plugins.includes('dokebi-web');
|
|
372
|
+
const ports = instancePorts(names, known, options.port, web);
|
|
361
373
|
const sample = await readOptional(await securePath(root, EXAMPLE));
|
|
362
374
|
if (sample === undefined)
|
|
363
375
|
throw new CliError('EXAMPLE_MISSING', `No ${EXAMPLE} to make the instance settings from`, {
|
|
@@ -376,7 +388,7 @@ export async function deployInit(input, options) {
|
|
|
376
388
|
parseConfig(sample).options,
|
|
377
389
|
];
|
|
378
390
|
const all = [...new Set([...known.keys(), ...names])].sort((a, b) => a === 'production' ? -1 : b === 'production' ? 1 : a.localeCompare(b));
|
|
379
|
-
const layouts = all.map((name) => layout(app, name, ports.get(name) ?? known.get(name) ?? 0));
|
|
391
|
+
const layouts = all.map((name) => layout(app, name, ports.get(name) ?? (web ? known.get(name) : 0) ?? 0));
|
|
380
392
|
const files = [];
|
|
381
393
|
const add = (path, body) => files.push({ path, content: withMarker(path, body) });
|
|
382
394
|
for (const at of layouts.filter((item) => names.includes(item.instance))) {
|
|
@@ -455,6 +467,9 @@ export async function deployProxy(input, options) {
|
|
|
455
467
|
const state = await projectState(root);
|
|
456
468
|
const app = await appName(root);
|
|
457
469
|
const plugins = state.plugins.map((plugin) => optionsKey(plugin));
|
|
470
|
+
// The name deploy init accepts: it becomes the unit, upstream and file names of the proxy.
|
|
471
|
+
if (!INSTANCE.test(options.instance))
|
|
472
|
+
throw instanceUsage(options.instance);
|
|
458
473
|
const domains = [...new Set(options.domains.map((domain) => domain.toLowerCase()))];
|
|
459
474
|
for (const domain of domains)
|
|
460
475
|
if (!DOMAIN.test(domain))
|
package/dist/dev-infra.js
CHANGED
|
@@ -7,7 +7,7 @@ import { statSync } from 'node:fs';
|
|
|
7
7
|
import { connect, createServer } from 'node:net';
|
|
8
8
|
import { delimiter, join } from 'node:path';
|
|
9
9
|
import { promisify } from 'node:util';
|
|
10
|
-
import { isMap, isScalar, parseDocument, stringify } from 'yaml';
|
|
10
|
+
import { isMap, isScalar, parseDocument, stringify, visit } from 'yaml';
|
|
11
11
|
import { databaseEnvironment } from './dev-compose.js';
|
|
12
12
|
import { debug, describeError, isMissing } from './diagnostics.js';
|
|
13
13
|
const exec = promisify(execFile);
|
|
@@ -48,11 +48,7 @@ export const FALLBACK_PROJECT_NAME = 'dokebi-app';
|
|
|
48
48
|
*/
|
|
49
49
|
export function composeUnsetVariables(compose, envKeys = []) {
|
|
50
50
|
const provided = new Set([PASSWORD_VARIABLE, ...envKeys]);
|
|
51
|
-
const text = compose
|
|
52
|
-
.split('\n')
|
|
53
|
-
.filter((line) => !line.trimStart().startsWith('#'))
|
|
54
|
-
.join('\n')
|
|
55
|
-
.replaceAll('$$', '');
|
|
51
|
+
const text = composeValues(compose).replaceAll('$$', '');
|
|
56
52
|
const unset = new Set();
|
|
57
53
|
for (const match of text.matchAll(/\$\{([A-Za-z_][A-Za-z0-9_]*)(?:(:?[-+?])[^}]*)?\}|\$([A-Za-z_][A-Za-z0-9_]*)/g)) {
|
|
58
54
|
const name = match[1] ?? match[3];
|
|
@@ -65,6 +61,27 @@ export function composeUnsetVariables(compose, envKeys = []) {
|
|
|
65
61
|
}
|
|
66
62
|
return [...unset].sort();
|
|
67
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* The text Compose interpolates: the YAML's values, so a comment after a value (`image: x # $TAG`)
|
|
66
|
+
* or a key is not read. A file that does not parse is read by lines without whole-line comments
|
|
67
|
+
* (Compose then refuses it for its own reason).
|
|
68
|
+
*/
|
|
69
|
+
function composeValues(compose) {
|
|
70
|
+
const document = parseDocument(compose);
|
|
71
|
+
if (document.errors.length)
|
|
72
|
+
return compose
|
|
73
|
+
.split('\n')
|
|
74
|
+
.filter((line) => !line.trimStart().startsWith('#'))
|
|
75
|
+
.join('\n');
|
|
76
|
+
const values = [];
|
|
77
|
+
visit(document, {
|
|
78
|
+
Scalar(key, node) {
|
|
79
|
+
if (key !== 'key' && typeof node.value === 'string')
|
|
80
|
+
values.push(node.value);
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
return values.join('\n');
|
|
84
|
+
}
|
|
68
85
|
/** The names a `.env` text sets (`NAME=` or `export NAME=`), read leniently: doctor reports an
|
|
69
86
|
* invalid `.env` on its own, so a line this cannot read is simply not a name. */
|
|
70
87
|
export function envKeys(text) {
|
|
@@ -72,7 +89,7 @@ export function envKeys(text) {
|
|
|
72
89
|
}
|
|
73
90
|
/** The doctor and dev-infra advice for compose variables dev-infra up does not set. */
|
|
74
91
|
export function composeVariablesHint(variables) {
|
|
75
|
-
return `compose.yaml needs ${variables.join(', ')} from the environment, which npx dokebi dev-infra up does not set
|
|
92
|
+
return `compose.yaml needs ${variables.join(', ')} from the environment, which npx dokebi dev-infra up does not set: \${NAME:?…} makes dev-infra up fail, and a bare \${NAME} becomes an empty value (Compose only warns), which breaks a port or a password. dev-infra up passes the passwords of dokebi.yaml: ${PASSWORD_VARIABLE}, and for every connection DOKEBI_<PLUGIN>_<CONNECTION>_PASSWORD (or _TOKEN; without the connection for main, such as DOKEBI_REDIS_PASSWORD); use those names, give a default in compose.yaml (\${NAME:-value}) or set it in .env`;
|
|
76
93
|
}
|
|
77
94
|
/** Compose project names: lower-case letters, digits, dashes and underscores. */
|
|
78
95
|
export function composeProject(name) {
|
package/dist/install-module.d.ts
CHANGED
|
@@ -31,12 +31,6 @@ export declare const PHASE_MISSING: unique symbol;
|
|
|
31
31
|
* the rest of `node_modules`, so `.env` files and other projects' files stay unreadable.
|
|
32
32
|
*/
|
|
33
33
|
export declare function installReadRoots(packageDirectory: string): Promise<string[]>;
|
|
34
|
-
/**
|
|
35
|
-
* Runs one lifecycle phase of a plugin installation module in a child process.
|
|
36
|
-
* The child uses the Node permission model: it may read only `readRoots`
|
|
37
|
-
* (at their real and link paths), cannot write files or spawn processes, and receives no
|
|
38
|
-
* parent environment variables. Node 24 does not restrict network access.
|
|
39
|
-
*/
|
|
40
34
|
/**
|
|
41
35
|
* The `--allow-fs-read` flags of the restricted child. Node 24.15's permission model denies a
|
|
42
36
|
* granted folder when a sibling folder whose name starts with it is granted too (with
|
|
@@ -46,4 +40,10 @@ export declare function installReadRoots(packageDirectory: string): Promise<stri
|
|
|
46
40
|
* the siblings that start with the same name.
|
|
47
41
|
*/
|
|
48
42
|
export declare function readPermissions(roots: readonly string[]): string[];
|
|
43
|
+
/**
|
|
44
|
+
* Runs one lifecycle phase of a plugin installation module in a child process.
|
|
45
|
+
* The child uses the Node permission model: it may read only `readRoots`
|
|
46
|
+
* (at their real and link paths), cannot write files or spawn processes, and receives no
|
|
47
|
+
* parent environment variables. Node 24 does not restrict network access.
|
|
48
|
+
*/
|
|
49
49
|
export declare function runInstallModule(modulePath: string, phase: InstallPhase, context: InstallModuleContext, readRoots?: readonly string[]): Promise<unknown>;
|
package/dist/install-module.js
CHANGED
|
@@ -116,12 +116,6 @@ export async function installReadRoots(packageDirectory) {
|
|
|
116
116
|
debug('Install module read roots', { package: own, roots: result });
|
|
117
117
|
return result;
|
|
118
118
|
}
|
|
119
|
-
/**
|
|
120
|
-
* Runs one lifecycle phase of a plugin installation module in a child process.
|
|
121
|
-
* The child uses the Node permission model: it may read only `readRoots`
|
|
122
|
-
* (at their real and link paths), cannot write files or spawn processes, and receives no
|
|
123
|
-
* parent environment variables. Node 24 does not restrict network access.
|
|
124
|
-
*/
|
|
125
119
|
/**
|
|
126
120
|
* The `--allow-fs-read` flags of the restricted child. Node 24.15's permission model denies a
|
|
127
121
|
* granted folder when a sibling folder whose name starts with it is granted too (with
|
|
@@ -138,6 +132,12 @@ export function readPermissions(roots) {
|
|
|
138
132
|
return `--allow-fs-read=${root}${shadowed ? '*' : ''}`;
|
|
139
133
|
});
|
|
140
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Runs one lifecycle phase of a plugin installation module in a child process.
|
|
137
|
+
* The child uses the Node permission model: it may read only `readRoots`
|
|
138
|
+
* (at their real and link paths), cannot write files or spawn processes, and receives no
|
|
139
|
+
* parent environment variables. Node 24 does not restrict network access.
|
|
140
|
+
*/
|
|
141
141
|
export async function runInstallModule(modulePath, phase, context, readRoots = [dirname(modulePath)]) {
|
|
142
142
|
const input = JSON.stringify(context);
|
|
143
143
|
if (Buffer.byteLength(input) > MAX_BYTES)
|
package/dist/output.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const CLI_VERSION = "0.4.
|
|
1
|
+
export declare const CLI_VERSION = "0.4.30";
|
|
2
2
|
export declare function envelope(command: string, result: unknown, ok?: boolean): object;
|
|
3
3
|
export declare function failure(command: string, error: unknown, mutationStarted: boolean): object;
|
package/dist/output.js
CHANGED
|
@@ -74,7 +74,8 @@ export type PluginOptionsVerdict = {
|
|
|
74
74
|
* cannot say. Every listed plugin's main entry is imported in ONE permission-restricted child, as
|
|
75
75
|
* install modules are (a child per plugin made `dokebi check` about a second slower on a blog
|
|
76
76
|
* project), and its `createPlugin.checkOptions` gets its section. A plugin without it (a parser
|
|
77
|
-
* function, an older core) is left out of the result; a plugin whose entry fails has `failed
|
|
77
|
+
* function, an older core) is left out of the result; a plugin whose entry fails has `failed`,
|
|
78
|
+
* and when the child itself fails (a time limit, no answer) every listed plugin has it.
|
|
78
79
|
*/
|
|
79
80
|
export declare function checkPluginsOptions(base: string, plugins: readonly PluginManifest[], options: Record<string, unknown>): Promise<Map<string, PluginOptionsVerdict>>;
|
|
80
81
|
export declare function checkPlugin(input: LifecycleInput): Promise<CheckResult>;
|
package/dist/plugin-lifecycle.js
CHANGED
|
@@ -252,7 +252,8 @@ async function mainEntry(directory) {
|
|
|
252
252
|
* cannot say. Every listed plugin's main entry is imported in ONE permission-restricted child, as
|
|
253
253
|
* install modules are (a child per plugin made `dokebi check` about a second slower on a blog
|
|
254
254
|
* project), and its `createPlugin.checkOptions` gets its section. A plugin without it (a parser
|
|
255
|
-
* function, an older core) is left out of the result; a plugin whose entry fails has `failed
|
|
255
|
+
* function, an older core) is left out of the result; a plugin whose entry fails has `failed`,
|
|
256
|
+
* and when the child itself fails (a time limit, no answer) every listed plugin has it.
|
|
256
257
|
*/
|
|
257
258
|
export async function checkPluginsOptions(base, plugins, options) {
|
|
258
259
|
const verdicts = new Map();
|
|
@@ -296,6 +297,15 @@ export async function checkPluginsOptions(base, plugins, options) {
|
|
|
296
297
|
? { code: error.code, ...(error.detail ? { module: error.detail } : {}) }
|
|
297
298
|
: { error: describeError(error) }),
|
|
298
299
|
});
|
|
300
|
+
// Audit R8-g5b-5: the child itself failed (an entry that hangs until INSTALL_TIMEOUT or ends
|
|
301
|
+
// the process before it answers): no plugin's rules ran, so each has that verdict, which
|
|
302
|
+
// doctor and config set report as the warning PLUGIN_OPTIONS_CHECK_FAILED (start checks them
|
|
303
|
+
// too). Thrown, it made doctor an error and refused every config set of the project.
|
|
304
|
+
if (error instanceof InstallPlanningError && ISSUE_CODE.test(error.code)) {
|
|
305
|
+
for (const entry of entries)
|
|
306
|
+
verdicts.set(entry.id, { failed: error.code });
|
|
307
|
+
return verdicts;
|
|
308
|
+
}
|
|
299
309
|
throw new CliError('PLUGIN_OPTIONS_CHECK_FAILED', `Plugin options could not be checked: ${error instanceof InstallPlanningError ? error.code : 'INSTALL_MODULE_FAILED'}`, { cause: error });
|
|
300
310
|
}
|
|
301
311
|
if (!Array.isArray(raw) || raw.length !== entries.length)
|
|
@@ -69,22 +69,36 @@ export async function productionDiagnostics(root, env = process.env) {
|
|
|
69
69
|
add('NODE_ENV_NOT_PRODUCTION', 'error', 'NODE_ENV', 'NODE_ENV is not production here, so this check (and an app started like this) runs with development behaviour: run it as the service runs, NODE_ENV=production npx dokebi doctor --production (the systemd unit and compose file set it)');
|
|
70
70
|
const { target, source } = await readSettings(root);
|
|
71
71
|
const secretsFile = env[SECRETS_VARIABLE] || undefined;
|
|
72
|
-
|
|
73
|
-
try {
|
|
74
|
-
options = (await applySecrets(parseConfig(source), secretsFile)).options;
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
72
|
+
const failed = (error, file) => {
|
|
77
73
|
if (!(error instanceof ConfigError))
|
|
78
74
|
throw error;
|
|
79
|
-
// The app would refuse to start with the same code
|
|
80
|
-
add(error.code, 'error',
|
|
75
|
+
// The app would refuse to start with the same code.
|
|
76
|
+
add(error.code, 'error', file, `${error.message}. ${error.fix}`, 'dokebi-config', {
|
|
81
77
|
issues: error.issues,
|
|
82
78
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
79
|
+
};
|
|
80
|
+
let document;
|
|
81
|
+
try {
|
|
82
|
+
document = parseConfig(source);
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
// A settings file that does not parse has nothing more to check.
|
|
86
|
+
failed(error, target.file);
|
|
87
|
+
return found;
|
|
88
|
+
}
|
|
89
|
+
let options;
|
|
90
|
+
let secretsFailed = false;
|
|
91
|
+
try {
|
|
92
|
+
options = (await applySecrets(document, secretsFile)).options;
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
secretsFailed = true;
|
|
96
|
+
// A secrets problem leaves the settings file itself readable: the rest is checked on it
|
|
97
|
+
// alone. The list's own failures name the settings; the file's (unreadable, not YAML, a
|
|
98
|
+
// `secrets` list in it) name the secrets file (R8-g5a-4).
|
|
99
|
+
const code = error instanceof ConfigError ? error.code : '';
|
|
100
|
+
failed(error, code.startsWith('CONFIG_SECRETS') || secretsFile === undefined ? target.file : secretsFile);
|
|
101
|
+
options = document.options;
|
|
88
102
|
}
|
|
89
103
|
const state = readState(parseObject(await readFile(join(root, '.dokebi/state.json'), 'utf8'), 'state'));
|
|
90
104
|
const installed = new Set(state.plugins.map((plugin) => optionsKey(plugin)));
|
|
@@ -127,7 +141,8 @@ export async function productionDiagnostics(root, env = process.env) {
|
|
|
127
141
|
const placeholders = placeholderPaths(options);
|
|
128
142
|
if (placeholders.length)
|
|
129
143
|
add('PLACEHOLDER_LEFT', 'error', target.file, `these options still hold a <placeholder> of the sample: ${placeholders.join(', ')}; fill them in the settings (or the secrets file)`, null, { paths: placeholders });
|
|
130
|
-
|
|
144
|
+
// The secrets list is checked once: config secrets would refuse the same file again.
|
|
145
|
+
if (!secretsFailed) {
|
|
131
146
|
try {
|
|
132
147
|
const secrets = await configSecrets(root, env);
|
|
133
148
|
for (const warning of secrets.warnings ?? [])
|
package/dist/project.d.ts
CHANGED
|
@@ -78,6 +78,7 @@ export type GeneratedSecret = {
|
|
|
78
78
|
readonly variable: string;
|
|
79
79
|
readonly file: typeof ENV_FILE;
|
|
80
80
|
};
|
|
81
|
+
/** Previous secrets `config secret --rotate` keeps after the new one in a list (AI-M05). */
|
|
81
82
|
export declare const ROTATE_KEEP = 2;
|
|
82
83
|
/** What `config secret` did at one option: names and counts only, never a value. */
|
|
83
84
|
export interface SecretOutcome {
|
package/dist/project.js
CHANGED
|
@@ -48,9 +48,9 @@ import { appViewValue, NO_VIEW, projectView } from './view-choice.js';
|
|
|
48
48
|
import { installedPath, packageFile, workspacePackages, workspaceRootOf, } from './workspace.js';
|
|
49
49
|
const GENERATED = 'src/dokebi.generated.ts';
|
|
50
50
|
const EXAMPLE = 'dokebi.example.yaml';
|
|
51
|
-
/** Previous secrets `config secret --rotate` keeps after the new one in a list (AI-M05). */
|
|
52
51
|
/** An option key that holds an address (`url`, `uri`, `databaseUrl`, `endpointURI`). */
|
|
53
52
|
const URL_KEY = /^(url|uri)$|(Url|URL|Uri|URI)$/;
|
|
53
|
+
/** Previous secrets `config secret --rotate` keeps after the new one in a list (AI-M05). */
|
|
54
54
|
export const ROTATE_KEEP = 2;
|
|
55
55
|
/** The generated registration differs from what the CLI wrote (D-0116: a sentence and a fix). */
|
|
56
56
|
function modifiedRegistration() {
|
package/dist/remote-verify.js
CHANGED
|
@@ -15,19 +15,25 @@ const HSTS_MIN = 15_552_000;
|
|
|
15
15
|
function fetchOnce(url, timeoutMs, ca) {
|
|
16
16
|
return new Promise((resolve, reject) => {
|
|
17
17
|
const send = url.protocol === 'https:' ? httpsRequest : httpRequest;
|
|
18
|
+
// The whole answer, not only each pause, stays within the limit (a server that drips bytes).
|
|
19
|
+
const deadline = setTimeout(() => request.destroy(new Error(`no answer within ${timeoutMs} ms`)), timeoutMs);
|
|
18
20
|
const request = send(url, {
|
|
19
21
|
method: 'GET',
|
|
20
22
|
headers: { 'user-agent': 'dokebi-verify-remote', accept: '*/*' },
|
|
21
23
|
timeout: timeoutMs,
|
|
22
24
|
...(ca === undefined ? {} : { ca }),
|
|
23
25
|
}, (response) => {
|
|
24
|
-
// Only the status and headers matter
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
response.
|
|
26
|
+
// Only the status and headers matter: the body is never read (an event stream or a
|
|
27
|
+
// download at the URL would keep the check waiting), the connection is closed.
|
|
28
|
+
clearTimeout(deadline);
|
|
29
|
+
resolve({ status: response.statusCode ?? 0, headers: response.headers });
|
|
30
|
+
response.destroy();
|
|
28
31
|
});
|
|
29
32
|
request.once('timeout', () => request.destroy(new Error(`no answer within ${timeoutMs} ms`)));
|
|
30
|
-
request.once('error',
|
|
33
|
+
request.once('error', (error) => {
|
|
34
|
+
clearTimeout(deadline);
|
|
35
|
+
reject(error);
|
|
36
|
+
});
|
|
31
37
|
request.end();
|
|
32
38
|
});
|
|
33
39
|
}
|
package/dist/server.d.ts
CHANGED
|
@@ -108,7 +108,9 @@ export declare function checkProject(root: string): Promise<string>;
|
|
|
108
108
|
* R1 T4 review: why a start failed, from the app log of this start only (after its last start
|
|
109
109
|
* mark): the first record with an error, as `<code>: <first line>` and, when the error has
|
|
110
110
|
* causes, `… <its last Caused by line>`. A START_FAILED said only "exited with code 1", and its
|
|
111
|
-
* tail began with an earlier start's lines.
|
|
111
|
+
* tail began with an earlier start's lines. A record below `error` that carries an error (a
|
|
112
|
+
* `warn` DB_CHECK_FAILED of a connection whose check failed) is named only when no record at
|
|
113
|
+
* `error` (or without a level) says (audit R8-g5b-1). Undefined when no record says.
|
|
112
114
|
*/
|
|
113
115
|
export declare function startFailureCause(lines: readonly string[]): string | undefined;
|
|
114
116
|
export interface LogOptions {
|
package/dist/server.js
CHANGED
|
@@ -673,14 +673,19 @@ async function tail(file, lines, current) {
|
|
|
673
673
|
}
|
|
674
674
|
/** The line the log writer writes before each start (log-writer.ts). */
|
|
675
675
|
const START_MARK = '--- dokebi start ';
|
|
676
|
+
/** Record levels below `error`: an error such a record carries did not stop the start. */
|
|
677
|
+
const LOWER_LEVELS = new Set(['trace', 'debug', 'info', 'warn']);
|
|
676
678
|
/**
|
|
677
679
|
* R1 T4 review: why a start failed, from the app log of this start only (after its last start
|
|
678
680
|
* mark): the first record with an error, as `<code>: <first line>` and, when the error has
|
|
679
681
|
* causes, `… <its last Caused by line>`. A START_FAILED said only "exited with code 1", and its
|
|
680
|
-
* tail began with an earlier start's lines.
|
|
682
|
+
* tail began with an earlier start's lines. A record below `error` that carries an error (a
|
|
683
|
+
* `warn` DB_CHECK_FAILED of a connection whose check failed) is named only when no record at
|
|
684
|
+
* `error` (or without a level) says (audit R8-g5b-1). Undefined when no record says.
|
|
681
685
|
*/
|
|
682
686
|
export function startFailureCause(lines) {
|
|
683
687
|
const from = lines.findLastIndex((line) => line.startsWith(START_MARK));
|
|
688
|
+
let lower;
|
|
684
689
|
for (const line of lines.slice(from + 1)) {
|
|
685
690
|
// Records are JSON lines; a stack line or a plain console line is not one.
|
|
686
691
|
if (!line.startsWith('{'))
|
|
@@ -703,9 +708,12 @@ export function startFailureCause(lines) {
|
|
|
703
708
|
const causes = text.split('\n').filter((each) => each.startsWith('Caused by: '));
|
|
704
709
|
const deepest = causes.at(-1)?.slice('Caused by: '.length);
|
|
705
710
|
const code = typeof record.code === 'string' ? `${record.code}: ` : '';
|
|
706
|
-
|
|
711
|
+
const said = `${code}${first}${deepest ? ` … ${deepest}` : ''}`.slice(0, 600);
|
|
712
|
+
if (!LOWER_LEVELS.has(String(record.level)))
|
|
713
|
+
return said;
|
|
714
|
+
lower ??= said;
|
|
707
715
|
}
|
|
708
|
-
return
|
|
716
|
+
return lower;
|
|
709
717
|
}
|
|
710
718
|
/** Rejects rotation settings outside LOG_LIMITS; bytes below 1 MB are allowed for tests. */
|
|
711
719
|
function logSettings(options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dokebi/cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.30",
|
|
4
4
|
"description": "Project scaffolding, plugin catalog, recipes, install and verification CLI for Dokebi.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dokebi",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"semver": "7.8.5",
|
|
37
37
|
"@dokebi/core": "^0.4.3",
|
|
38
|
-
"@dokebi/config": "^0.4.
|
|
38
|
+
"@dokebi/config": "^0.4.4",
|
|
39
39
|
"yaml": "2.9.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|