@auth-craft/worker-d1-stack 0.0.0-stage → 0.2.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 +75 -0
- package/README.md +296 -2
- package/assets/check/config.mjs +1935 -0
- package/assets/data/snapshot.mjs +190 -0
- package/assets/engine/dev-engine.mjs +1 -0
- package/assets/manifest.json +113 -0
- package/assets/migrations/0001_baseline.sql +234 -0
- package/assets/migrations/0002_email.sql +31 -0
- package/assets/migrations/0003_email_provider_index.sql +7 -0
- package/assets/migrations/0004_audit.sql +27 -0
- package/assets/migrations/0005_allowed_origins.sql +14 -0
- package/assets/sbom/data.cdx.json +1042 -0
- package/assets/sbom/worker.cdx.json +647 -0
- package/assets/worker/worker.js +158 -0
- package/bin/auth-craft-worker.mjs +4 -0
- package/dist/check.d.ts +9 -0
- package/dist/check.d.ts.map +1 -0
- package/dist/check.js +125 -0
- package/dist/check.js.map +1 -0
- package/dist/cli.d.ts +14 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +433 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands.d.ts +39 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +108 -0
- package/dist/commands.js.map +1 -0
- package/dist/cutover.d.ts +63 -0
- package/dist/cutover.d.ts.map +1 -0
- package/dist/cutover.js +310 -0
- package/dist/cutover.js.map +1 -0
- package/dist/data.d.ts +52 -0
- package/dist/data.d.ts.map +1 -0
- package/dist/data.js +131 -0
- package/dist/data.js.map +1 -0
- package/dist/dev.d.ts +16 -0
- package/dist/dev.d.ts.map +1 -0
- package/dist/dev.js +80 -0
- package/dist/dev.js.map +1 -0
- package/dist/init.d.ts +23 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +71 -0
- package/dist/init.js.map +1 -0
- package/dist/paths.d.ts +17 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +13 -0
- package/dist/paths.js.map +1 -0
- package/dist/preflight.d.ts +45 -0
- package/dist/preflight.d.ts.map +1 -0
- package/dist/preflight.js +335 -0
- package/dist/preflight.js.map +1 -0
- package/dist/secrets-file.d.ts +5 -0
- package/dist/secrets-file.d.ts.map +1 -0
- package/dist/secrets-file.js +57 -0
- package/dist/secrets-file.js.map +1 -0
- package/dist/service-token.d.ts +6 -0
- package/dist/service-token.d.ts.map +1 -0
- package/dist/service-token.js +26 -0
- package/dist/service-token.js.map +1 -0
- package/dist/smoke.d.ts +45 -0
- package/dist/smoke.d.ts.map +1 -0
- package/dist/smoke.js +186 -0
- package/dist/smoke.js.map +1 -0
- package/dist/wrangler-config.d.ts +52 -0
- package/dist/wrangler-config.d.ts.map +1 -0
- package/dist/wrangler-config.js +23 -0
- package/dist/wrangler-config.js.map +1 -0
- package/dist/wrangler-runner.d.ts +13 -0
- package/dist/wrangler-runner.d.ts.map +1 -0
- package/dist/wrangler-runner.js +52 -0
- package/dist/wrangler-runner.js.map +1 -0
- package/package.json +42 -3
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type CheckReport } from './check.js';
|
|
2
|
+
import type { WranglerRunner } from './wrangler-runner.js';
|
|
3
|
+
export interface Output {
|
|
4
|
+
info(line: string): void;
|
|
5
|
+
error(line: string): void;
|
|
6
|
+
}
|
|
7
|
+
export declare function report(result: CheckReport, out: Output): boolean;
|
|
8
|
+
/** Upload every key of the secrets file with `wrangler secret bulk`; the JSON file lives only for the call. */
|
|
9
|
+
export declare function pushSecrets(options: {
|
|
10
|
+
config: string;
|
|
11
|
+
secretsFile: string;
|
|
12
|
+
}, run: WranglerRunner, out: Output): Promise<void>;
|
|
13
|
+
export declare function migrate(options: {
|
|
14
|
+
config: string;
|
|
15
|
+
local?: boolean;
|
|
16
|
+
}, run: WranglerRunner, out: Output): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* check → migrations (remote) → deploy. Migrations go first: the new Worker may need the
|
|
19
|
+
* new schema, and migrations are additive (the running Worker keeps working on them).
|
|
20
|
+
*/
|
|
21
|
+
export declare function deploy(options: {
|
|
22
|
+
config: string;
|
|
23
|
+
secretsFile?: string;
|
|
24
|
+
dryRun?: boolean;
|
|
25
|
+
skipMigrations?: boolean;
|
|
26
|
+
}, run: WranglerRunner, out: Output): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* MAINTENANCE_MODE on / off: written to the config's `vars`, then deployed (no
|
|
29
|
+
* migrations: the schema does not change, and maintenance is often the moment before a
|
|
30
|
+
* data move). A failed deploy puts the file back, so the file never claims a state the
|
|
31
|
+
* running Worker is not in. `status` reads the file only; the running Worker reports
|
|
32
|
+
* itself on /health (`maintenance`).
|
|
33
|
+
*/
|
|
34
|
+
export declare function maintenance(options: {
|
|
35
|
+
config: string;
|
|
36
|
+
mode: 'on' | 'off' | 'status';
|
|
37
|
+
secretsFile?: string;
|
|
38
|
+
}, run: WranglerRunner, out: Output): Promise<void>;
|
|
39
|
+
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,WAAW,EAAgB,MAAM,YAAY,CAAC;AAG5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,MAAM,WAAW,MAAM;IACrB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAKhE;AAOD,+GAA+G;AAC/G,wBAAsB,WAAW,CAC/B,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,EAChD,GAAG,EAAE,cAAc,EACnB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,IAAI,CAAC,CAiBf;AAED,wBAAsB,OAAO,CAC3B,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,EAC5C,GAAG,EAAE,cAAc,EACnB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,IAAI,CAAC,CAUf;AAED;;;GAGG;AACH,wBAAsB,MAAM,CAC1B,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,cAAc,CAAC,EAAE,OAAO,CAAA;CAAE,EAC7F,GAAG,EAAE,cAAc,EACnB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,IAAI,CAAC,CAcf;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,IAAI,GAAG,KAAK,GAAG,QAAQ,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,EAChF,GAAG,EAAE,cAAc,EACnB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,IAAI,CAAC,CAyBf"}
|
package/dist/commands.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/** `secrets`, `migrate` and `deploy`: wrangler calls, each gated on `check`. */
|
|
2
|
+
import { chmodSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { dirname, join, resolve } from 'node:path';
|
|
5
|
+
import { checkProject } from './check.js';
|
|
6
|
+
import { readSecretsFile } from './secrets-file.js';
|
|
7
|
+
import { CliError, readWranglerConfig } from './wrangler-config.js';
|
|
8
|
+
export function report(result, out) {
|
|
9
|
+
for (const warning of result.warnings)
|
|
10
|
+
out.info(`warning: ${warning}`);
|
|
11
|
+
for (const problem of result.problems)
|
|
12
|
+
out.error(`problem: ${problem}`);
|
|
13
|
+
if (result.problems.length === 0)
|
|
14
|
+
out.info('check: ok');
|
|
15
|
+
return result.problems.length === 0;
|
|
16
|
+
}
|
|
17
|
+
async function gate(config, secretsFile, out) {
|
|
18
|
+
const result = await checkProject({ config, ...(secretsFile !== undefined && { secretsFile }) });
|
|
19
|
+
if (!report(result, out))
|
|
20
|
+
throw new CliError(`check found ${result.problems.length} problem(s); nothing was changed`);
|
|
21
|
+
}
|
|
22
|
+
/** Upload every key of the secrets file with `wrangler secret bulk`; the JSON file lives only for the call. */
|
|
23
|
+
export async function pushSecrets(options, run, out) {
|
|
24
|
+
await gate(options.config, options.secretsFile, out);
|
|
25
|
+
const secrets = readSecretsFile(options.secretsFile);
|
|
26
|
+
if (Object.keys(secrets).length === 0)
|
|
27
|
+
throw new CliError('the secrets file is empty');
|
|
28
|
+
const dir = mkdtempSync(join(tmpdir(), 'auth-craft-secrets-'));
|
|
29
|
+
const file = join(dir, 'secrets.json');
|
|
30
|
+
try {
|
|
31
|
+
writeFileSync(file, JSON.stringify(secrets), { mode: 0o600 });
|
|
32
|
+
chmodSync(file, 0o600);
|
|
33
|
+
const code = await run(['secret', 'bulk', file, '--config', resolve(options.config)], {
|
|
34
|
+
cwd: dirname(resolve(options.config)),
|
|
35
|
+
});
|
|
36
|
+
if (code !== 0)
|
|
37
|
+
throw new CliError(`wrangler secret bulk failed (exit ${code})`);
|
|
38
|
+
out.info(`secrets: uploaded ${Object.keys(secrets).sort().join(', ')}`);
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
rmSync(dir, { recursive: true, force: true });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export async function migrate(options, run, out) {
|
|
45
|
+
const config = resolve(options.config);
|
|
46
|
+
const code = await run(['d1', 'migrations', 'apply', 'DB', options.local ? '--local' : '--remote', '--config', config], {
|
|
47
|
+
cwd: dirname(config),
|
|
48
|
+
});
|
|
49
|
+
if (code !== 0)
|
|
50
|
+
throw new CliError(`wrangler d1 migrations apply failed (exit ${code})`);
|
|
51
|
+
out.info(`migrate: applied (${options.local ? 'local' : 'remote'})`);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* check → migrations (remote) → deploy. Migrations go first: the new Worker may need the
|
|
55
|
+
* new schema, and migrations are additive (the running Worker keeps working on them).
|
|
56
|
+
*/
|
|
57
|
+
export async function deploy(options, run, out) {
|
|
58
|
+
await gate(options.config, options.secretsFile, out);
|
|
59
|
+
const config = resolve(options.config);
|
|
60
|
+
if (!options.dryRun && !options.skipMigrations)
|
|
61
|
+
await migrate({ config }, run, out);
|
|
62
|
+
const outdir = options.dryRun ? mkdtempSync(join(tmpdir(), 'auth-craft-worker-dry-')) : undefined;
|
|
63
|
+
try {
|
|
64
|
+
const code = await run(['deploy', '--config', config, ...(outdir ? ['--dry-run', '--outdir', outdir] : [])], {
|
|
65
|
+
cwd: dirname(config),
|
|
66
|
+
});
|
|
67
|
+
if (code !== 0)
|
|
68
|
+
throw new CliError(`wrangler deploy failed (exit ${code})`);
|
|
69
|
+
out.info(options.dryRun ? 'deploy: dry run ok (nothing uploaded)' : 'deploy: done');
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
if (outdir)
|
|
73
|
+
rmSync(outdir, { recursive: true, force: true });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* MAINTENANCE_MODE on / off: written to the config's `vars`, then deployed (no
|
|
78
|
+
* migrations: the schema does not change, and maintenance is often the moment before a
|
|
79
|
+
* data move). A failed deploy puts the file back, so the file never claims a state the
|
|
80
|
+
* running Worker is not in. `status` reads the file only; the running Worker reports
|
|
81
|
+
* itself on /health (`maintenance`).
|
|
82
|
+
*/
|
|
83
|
+
export async function maintenance(options, run, out) {
|
|
84
|
+
const config = resolve(options.config);
|
|
85
|
+
const current = readWranglerConfig(config).vars?.MAINTENANCE_MODE === 'true';
|
|
86
|
+
if (options.mode === 'status') {
|
|
87
|
+
out.info(`maintenance: ${current ? 'on' : 'off'} (in ${options.config}; the live Worker reports it on /health)`);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const wanted = options.mode === 'on';
|
|
91
|
+
const original = readFileSync(config, 'utf8');
|
|
92
|
+
const parsed = JSON.parse(original);
|
|
93
|
+
const vars = { ...(parsed.vars ?? {}) };
|
|
94
|
+
if (wanted)
|
|
95
|
+
vars.MAINTENANCE_MODE = 'true';
|
|
96
|
+
else
|
|
97
|
+
delete vars.MAINTENANCE_MODE;
|
|
98
|
+
writeFileSync(config, `${JSON.stringify({ ...parsed, vars }, null, 2)}\n`);
|
|
99
|
+
try {
|
|
100
|
+
await deploy({ config, skipMigrations: true, ...(options.secretsFile !== undefined && { secretsFile: options.secretsFile }) }, run, out);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
writeFileSync(config, original);
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
out.info(`maintenance: ${wanted ? 'on' : 'off'}${wanted === current ? ' (was already)' : ''}`);
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtF,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAoB,YAAY,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAQpE,MAAM,UAAU,MAAM,CAAC,MAAmB,EAAE,GAAW;IACrD,KAA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V,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,WAAW,KAAK,SAAS,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,EAAE,EAChH,GAAG,EACH,GAAG,CACJ,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAChC,MAAM,KAAK,CAAC;IACd,CAAC;IACD,GAAG,CAAC,IAAI,CAAC,gBAAgB,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACjG,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type Output } from './commands.js';
|
|
2
|
+
import { type NodeRunner } from './data.js';
|
|
3
|
+
import { type CaptureRunner, type WranglerRunner } from './wrangler-runner.js';
|
|
4
|
+
export type ShellRunner = (command: string) => Promise<{
|
|
5
|
+
code: number;
|
|
6
|
+
stdout: string;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const runShell: ShellRunner;
|
|
9
|
+
export interface CutoverDeps {
|
|
10
|
+
out: Output;
|
|
11
|
+
env: NodeJS.ProcessEnv;
|
|
12
|
+
run?: WranglerRunner;
|
|
13
|
+
capture?: CaptureRunner;
|
|
14
|
+
node?: NodeRunner;
|
|
15
|
+
shell?: ShellRunner;
|
|
16
|
+
fetch?: typeof fetch;
|
|
17
|
+
}
|
|
18
|
+
export interface CutoverOptions {
|
|
19
|
+
config: string;
|
|
20
|
+
secretsFile: string;
|
|
21
|
+
fromLambda: string;
|
|
22
|
+
region: string;
|
|
23
|
+
/** The Lambda's DynamoDB table ({app}-{env}-{layer}-data). */
|
|
24
|
+
table: string;
|
|
25
|
+
snapshotDir: string;
|
|
26
|
+
/** Command prefix of the Lambda fence; ` on`, ` off`, ` status` are appended. */
|
|
27
|
+
fence: string;
|
|
28
|
+
/** The app's routing change to the Worker. */
|
|
29
|
+
switchCommand: string;
|
|
30
|
+
/** The password engine's largest N (check-hashes). */
|
|
31
|
+
maxN?: string;
|
|
32
|
+
/** Smoke after maintenance off (password: AUTH_CRAFT_SMOKE_PASSWORD). */
|
|
33
|
+
smoke?: {
|
|
34
|
+
url: string;
|
|
35
|
+
email: string;
|
|
36
|
+
origin?: string;
|
|
37
|
+
app?: string;
|
|
38
|
+
};
|
|
39
|
+
/** Without it, print the plan and change nothing. */
|
|
40
|
+
yes?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface RollbackAfterWritesOptions {
|
|
43
|
+
config: string;
|
|
44
|
+
secretsFile: string;
|
|
45
|
+
region: string;
|
|
46
|
+
/** Where the Worker's data is exported to (a new directory). */
|
|
47
|
+
snapshotDir: string;
|
|
48
|
+
fence: string;
|
|
49
|
+
/** Deploys the Lambda onto the new, empty table (e.g. `LAMBDA_DYNAMODB_TABLE_SUFFIX=-r1 npx auth-craft-stack lambda …`). */
|
|
50
|
+
lambdaDeploy: string;
|
|
51
|
+
/** The new table the data goes into. */
|
|
52
|
+
table: string;
|
|
53
|
+
/** The app's routing change back to the Lambda. */
|
|
54
|
+
switchBack: string;
|
|
55
|
+
yes?: boolean;
|
|
56
|
+
}
|
|
57
|
+
export declare const stateFile: (snapshotDir: string) => string;
|
|
58
|
+
export declare function cutover(options: CutoverOptions, deps: CutoverDeps): Promise<number>;
|
|
59
|
+
/** Before the switch only: fence off, Worker in maintenance, D1 left for a later attempt. */
|
|
60
|
+
export declare function rollbackBeforeSwitch(options: Pick<CutoverOptions, 'config' | 'secretsFile' | 'snapshotDir' | 'fence' | 'yes'>, deps: CutoverDeps): Promise<number>;
|
|
61
|
+
/** After users wrote to the Worker: its data goes into a NEW Lambda table, then traffic goes back. */
|
|
62
|
+
export declare function rollbackAfterWrites(options: RollbackAfterWritesOptions, deps: CutoverDeps): Promise<number>;
|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AAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACtE,qDAAqD;IACrD,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,gEAAgE;IAChE,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,4HAA4H;IAC5H,YAAY,EAAE,MAAM,CAAC;IACrB,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AA8CD,eAAO,MAAM,SAAS,gBAAiB,MAAM,WAA2C,CAAC;AAyDzF,wBAAsB,OAAO,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAkIzF;AAED,6FAA6F;AAC7F,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,GAAG,aAAa,GAAG,aAAa,GAAG,OAAO,GAAG,KAAK,CAAC,EACzF,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,MAAM,CAAC,CA4BjB;AAED,sGAAsG;AACtG,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,0BAA0B,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAmDjH"}
|
package/dist/cutover.js
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `cutover` (docs/LAMBDA_TO_WORKER_PROPOSAL.md §4.5–4.6): move a Lambda deployment to
|
|
3
|
+
* this Worker in one command, resumable from the step that failed.
|
|
4
|
+
*
|
|
5
|
+
* 1 preflight read-only settings / D1 / relay checks
|
|
6
|
+
* 2 maintenance on deploy the Worker fenced (MAINTENANCE_MODE)
|
|
7
|
+
* 3 fence on the Lambda stops (`<fence> on`, then `<fence> status` must say FENCE=on)
|
|
8
|
+
* 4 export → verify → check-hashes → import (reconciled) → reconcile
|
|
9
|
+
* 5 maintenance off + smoke when a smoke account is given
|
|
10
|
+
* 6 switch the app's own routing change (`--switch`)
|
|
11
|
+
*
|
|
12
|
+
* State lives next to the snapshot (`<snapshot-dir>.cutover.json`). A finished step is
|
|
13
|
+
* skipped on a re-run; an import that started and did not finish is never re-run
|
|
14
|
+
* blindly (reconcile first). Before step 6 a rollback is `--rollback` (fence off, Worker
|
|
15
|
+
* back in maintenance, nothing the users wrote is lost because they wrote nowhere).
|
|
16
|
+
* From the moment step 6 starts — it deploys several things, one after the other —
|
|
17
|
+
* users may have written to the Worker: `--rollback` is refused and only
|
|
18
|
+
* `--rollback-after-writes` (data back into a new Lambda table) remains. A failed switch
|
|
19
|
+
* puts the Worker back in maintenance so nothing more is written meanwhile.
|
|
20
|
+
*
|
|
21
|
+
* External effects all go through injected runners (wrangler, aws, node, shell, fetch),
|
|
22
|
+
* so the local rehearsal runs the same sequence with a local Lambda and Worker.
|
|
23
|
+
*/
|
|
24
|
+
import { spawn } from 'node:child_process';
|
|
25
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
26
|
+
import { dirname, resolve } from 'node:path';
|
|
27
|
+
import { maintenance } from './commands.js';
|
|
28
|
+
import { runData, runNode } from './data.js';
|
|
29
|
+
import { runPreflight } from './preflight.js';
|
|
30
|
+
import { runSmoke } from './smoke.js';
|
|
31
|
+
import { CliError } from './wrangler-config.js';
|
|
32
|
+
import { runCapture, runWrangler } from './wrangler-runner.js';
|
|
33
|
+
export const runShell = (command) => new Promise((resolvePromise, reject) => {
|
|
34
|
+
const child = spawn('bash', ['-c', command], { stdio: ['ignore', 'pipe', 'inherit'] });
|
|
35
|
+
let stdout = '';
|
|
36
|
+
child.stdout?.on('data', (chunk) => {
|
|
37
|
+
const text = chunk.toString();
|
|
38
|
+
stdout += text;
|
|
39
|
+
process.stdout.write(text);
|
|
40
|
+
});
|
|
41
|
+
child.on('error', reject);
|
|
42
|
+
child.on('exit', (code) => resolvePromise({ code: code ?? 1, stdout }));
|
|
43
|
+
});
|
|
44
|
+
const CUTOVER_STEPS = [
|
|
45
|
+
'preflight',
|
|
46
|
+
'maintenance-on',
|
|
47
|
+
'fence-on',
|
|
48
|
+
'export',
|
|
49
|
+
'verify',
|
|
50
|
+
'check-hashes',
|
|
51
|
+
'import',
|
|
52
|
+
'reconcile',
|
|
53
|
+
'maintenance-off',
|
|
54
|
+
'smoke',
|
|
55
|
+
'switch',
|
|
56
|
+
];
|
|
57
|
+
const ROLLBACK_STEPS = [
|
|
58
|
+
'maintenance-on',
|
|
59
|
+
'export',
|
|
60
|
+
'verify',
|
|
61
|
+
'lambda-deploy',
|
|
62
|
+
'fence-check',
|
|
63
|
+
'import',
|
|
64
|
+
'reconcile',
|
|
65
|
+
'fence-off',
|
|
66
|
+
'switch-back',
|
|
67
|
+
];
|
|
68
|
+
/** Steps that write somewhere and must not be re-run after an interruption without a look. */
|
|
69
|
+
const NOT_BLINDLY_REPEATED = new Set(['import']);
|
|
70
|
+
export const stateFile = (snapshotDir) => `${resolve(snapshotDir)}.cutover.json`;
|
|
71
|
+
function readState(path) {
|
|
72
|
+
if (!existsSync(path))
|
|
73
|
+
return null;
|
|
74
|
+
const state = JSON.parse(readFileSync(path, 'utf8'));
|
|
75
|
+
if (state.version !== 1)
|
|
76
|
+
throw new CliError(`${path}: unknown state version`);
|
|
77
|
+
return state;
|
|
78
|
+
}
|
|
79
|
+
function writeState(path, state) {
|
|
80
|
+
if (!existsSync(dirname(path)))
|
|
81
|
+
throw new CliError(`${dirname(path)} does not exist`);
|
|
82
|
+
writeFileSync(path, `${JSON.stringify(state, null, 2)}\n`, { mode: 0o600 });
|
|
83
|
+
}
|
|
84
|
+
const NOT_CARRIED = 'Not carried by the snapshot (docs/LAMBDA_TO_WORKER_PROPOSAL.md §4.8): pending verification/reset links, sign-in and MFA codes (users request them again), rate-limit counters, email logs and suppressions of the Worker. Account lockouts and sessions are carried.';
|
|
85
|
+
async function runSteps(path, state, steps, actions, out) {
|
|
86
|
+
if (state.started && !state.done.includes(state.started) && NOT_BLINDLY_REPEATED.has(state.started)) {
|
|
87
|
+
throw new CliError(`the step "${state.started}" started and did not finish: run \`data reconcile\` to see what landed, then decide (an import only goes into an empty store)`);
|
|
88
|
+
}
|
|
89
|
+
for (const step of steps) {
|
|
90
|
+
if (state.done.includes(step)) {
|
|
91
|
+
out.info(`· ${step}: done before`);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
out.info(`→ ${step}`);
|
|
95
|
+
state.started = step;
|
|
96
|
+
writeState(path, state);
|
|
97
|
+
await actions[step]?.();
|
|
98
|
+
state.done.push(step);
|
|
99
|
+
delete state.started;
|
|
100
|
+
writeState(path, state);
|
|
101
|
+
out.info(`✓ ${step}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async function shellOk(shell, command, what) {
|
|
105
|
+
const res = await shell(command);
|
|
106
|
+
if (res.code !== 0)
|
|
107
|
+
throw new CliError(`${what} failed (exit ${res.code})`);
|
|
108
|
+
return res.stdout;
|
|
109
|
+
}
|
|
110
|
+
async function fenceIsOn(shell, fence) {
|
|
111
|
+
const status = await shellOk(shell, `${fence} status`, 'fence status');
|
|
112
|
+
if (!/^FENCE=on$/m.test(status))
|
|
113
|
+
throw new CliError('the Lambda is not fenced (`fence status` did not print FENCE=on)');
|
|
114
|
+
}
|
|
115
|
+
export async function cutover(options, deps) {
|
|
116
|
+
const { out } = deps;
|
|
117
|
+
const run = deps.run ?? runWrangler;
|
|
118
|
+
const capture = deps.capture ?? runCapture;
|
|
119
|
+
const node = deps.node ?? runNode;
|
|
120
|
+
const shell = deps.shell ?? runShell;
|
|
121
|
+
const path = stateFile(options.snapshotDir);
|
|
122
|
+
const state = readState(path) ?? { version: 1, phase: 'preparing', done: [] };
|
|
123
|
+
if (state.phase === 'switched') {
|
|
124
|
+
out.info('cutover: already switched; nothing to do');
|
|
125
|
+
return 0;
|
|
126
|
+
}
|
|
127
|
+
if (state.phase === 'rolled-back' ||
|
|
128
|
+
state.phase.startsWith('rolling-back') ||
|
|
129
|
+
state.phase === 'rolled-back-after-writes') {
|
|
130
|
+
throw new CliError(`${path}: this cutover was rolled back; start again with a new --snapshot-dir`);
|
|
131
|
+
}
|
|
132
|
+
if (!options.yes) {
|
|
133
|
+
out.info(`cutover plan (state: ${path})`);
|
|
134
|
+
for (const step of CUTOVER_STEPS)
|
|
135
|
+
out.info(` ${state.done.includes(step) ? '✓' : '·'} ${step}`);
|
|
136
|
+
out.info(NOT_CARRIED);
|
|
137
|
+
out.info('Nothing changed. Re-run with --yes to carry it out.');
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
out.info(NOT_CARRIED);
|
|
141
|
+
const data = async (operation, extra = {}) => {
|
|
142
|
+
const code = await runData({
|
|
143
|
+
operation,
|
|
144
|
+
dir: options.snapshotDir,
|
|
145
|
+
config: options.config,
|
|
146
|
+
secretsFile: options.secretsFile,
|
|
147
|
+
writeFence: operation !== 'verify' && operation !== 'check-hashes',
|
|
148
|
+
...extra,
|
|
149
|
+
}, deps.env, node);
|
|
150
|
+
if (code !== 0)
|
|
151
|
+
throw new CliError(`data ${operation} failed (exit ${code})`);
|
|
152
|
+
};
|
|
153
|
+
const maintenanceTo = (mode) => maintenance({ config: options.config, mode, secretsFile: options.secretsFile }, run, out);
|
|
154
|
+
const actions = {
|
|
155
|
+
preflight: async () => {
|
|
156
|
+
const checks = await runPreflight({
|
|
157
|
+
fromLambda: options.fromLambda,
|
|
158
|
+
region: options.region,
|
|
159
|
+
config: options.config,
|
|
160
|
+
secretsFile: options.secretsFile,
|
|
161
|
+
...(deps.fetch && { fetch: deps.fetch }),
|
|
162
|
+
}, capture);
|
|
163
|
+
for (const c of checks) {
|
|
164
|
+
const line = `${c.name}${c.detail ? `: ${c.detail}` : ''}`;
|
|
165
|
+
if (c.ok === false)
|
|
166
|
+
out.error(` ✗ ${line}`);
|
|
167
|
+
else
|
|
168
|
+
out.info(` ${c.ok === true ? '✓' : '!'} ${line}`);
|
|
169
|
+
}
|
|
170
|
+
if (checks.some((c) => c.ok === false))
|
|
171
|
+
throw new CliError('preflight failed; nothing changed');
|
|
172
|
+
},
|
|
173
|
+
'maintenance-on': () => maintenanceTo('on'),
|
|
174
|
+
'fence-on': async () => {
|
|
175
|
+
await shellOk(shell, `${options.fence} on`, 'fence on');
|
|
176
|
+
await fenceIsOn(shell, options.fence);
|
|
177
|
+
},
|
|
178
|
+
export: () => data('export', { from: 'dynamodb', table: options.table, region: options.region }),
|
|
179
|
+
verify: () => data('verify'),
|
|
180
|
+
'check-hashes': () => data('check-hashes', options.maxN !== undefined ? { maxN: options.maxN } : {}),
|
|
181
|
+
import: () => data('import', { to: 'd1' }),
|
|
182
|
+
reconcile: () => data('reconcile', { to: 'd1' }),
|
|
183
|
+
'maintenance-off': () => maintenanceTo('off'),
|
|
184
|
+
smoke: async () => {
|
|
185
|
+
if (!options.smoke) {
|
|
186
|
+
out.info(' ! no smoke account given (--smoke-email): skipped');
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const password = deps.env.AUTH_CRAFT_SMOKE_PASSWORD;
|
|
190
|
+
if (!password)
|
|
191
|
+
throw new CliError('AUTH_CRAFT_SMOKE_PASSWORD: required with --smoke-email');
|
|
192
|
+
const vars = JSON.parse(readFileSync(options.config, 'utf8')).vars ?? {};
|
|
193
|
+
const engine = vars.PASSWORD_ENGINE === 'remote' ? 'remote' : 'local';
|
|
194
|
+
const steps = await runSmoke({
|
|
195
|
+
url: options.smoke.url,
|
|
196
|
+
passwordEngine: engine,
|
|
197
|
+
email: options.smoke.email,
|
|
198
|
+
password,
|
|
199
|
+
...(options.smoke.origin && { cookie: { origin: options.smoke.origin } }),
|
|
200
|
+
...(options.smoke.app && { app: options.smoke.app }),
|
|
201
|
+
...(deps.fetch && { fetch: deps.fetch }),
|
|
202
|
+
});
|
|
203
|
+
for (const s of steps)
|
|
204
|
+
(s.ok ? out.info : out.error)(` ${s.ok ? '✓' : '✗'} ${s.name}${s.detail ? `: ${s.detail}` : ''}`);
|
|
205
|
+
if (steps.some((s) => !s.ok)) {
|
|
206
|
+
// Back behind the fence before stopping: the Worker served the smoke account only.
|
|
207
|
+
await maintenanceTo('on');
|
|
208
|
+
state.done = state.done.filter((d) => d !== 'maintenance-off');
|
|
209
|
+
writeState(path, state);
|
|
210
|
+
throw new CliError('smoke failed; the Worker is back in maintenance');
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
switch: async () => {
|
|
214
|
+
state.phase = 'switching';
|
|
215
|
+
writeState(path, state);
|
|
216
|
+
const res = await shell(options.switchCommand);
|
|
217
|
+
if (res.code !== 0) {
|
|
218
|
+
try {
|
|
219
|
+
await maintenanceTo('on');
|
|
220
|
+
out.error(' the Worker is back in maintenance (nothing more is written to it)');
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
out.error(' could not put the Worker back in maintenance: do it now (`maintenance on`)');
|
|
224
|
+
}
|
|
225
|
+
throw new CliError(`the switch failed part way (exit ${res.code}): users may already have written to the Worker. Fix and re-run \`cutover --yes\` (it resumes at the switch), or roll back with \`cutover --rollback-after-writes\`; \`--rollback\` is refused from here on`);
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
await runSteps(path, state, CUTOVER_STEPS, actions, out);
|
|
230
|
+
state.phase = 'switched';
|
|
231
|
+
writeState(path, state);
|
|
232
|
+
out.info('cutover: switched. Keep the Lambda fenced for one stable cycle; roll back with `cutover --rollback-after-writes`.');
|
|
233
|
+
return 0;
|
|
234
|
+
}
|
|
235
|
+
/** Before the switch only: fence off, Worker in maintenance, D1 left for a later attempt. */
|
|
236
|
+
export async function rollbackBeforeSwitch(options, deps) {
|
|
237
|
+
const { out } = deps;
|
|
238
|
+
const path = stateFile(options.snapshotDir);
|
|
239
|
+
const state = readState(path);
|
|
240
|
+
if (!state)
|
|
241
|
+
throw new CliError(`${path}: no cutover started here`);
|
|
242
|
+
if (state.phase === 'switching' || state.phase === 'switched') {
|
|
243
|
+
throw new CliError('the switch has started: users may have written to the Worker, and this rollback would drop that. Use `cutover --rollback-after-writes`');
|
|
244
|
+
}
|
|
245
|
+
if (!options.yes) {
|
|
246
|
+
out.info('rollback plan: Worker into maintenance, Lambda fence off. Re-run with --yes.');
|
|
247
|
+
return 0;
|
|
248
|
+
}
|
|
249
|
+
const run = deps.run ?? runWrangler;
|
|
250
|
+
const shell = deps.shell ?? runShell;
|
|
251
|
+
if (state.done.includes('maintenance-on')) {
|
|
252
|
+
await maintenance({ config: options.config, mode: 'on', secretsFile: options.secretsFile }, run, out);
|
|
253
|
+
}
|
|
254
|
+
if (state.done.includes('fence-on') || state.started === 'fence-on') {
|
|
255
|
+
await shellOk(shell, `${options.fence} off`, 'fence off');
|
|
256
|
+
}
|
|
257
|
+
state.phase = 'rolled-back';
|
|
258
|
+
writeState(path, state);
|
|
259
|
+
out.info('rollback: the Lambda serves again; the Worker stays in maintenance. D1 keeps what was imported: empty it before a new attempt.');
|
|
260
|
+
return 0;
|
|
261
|
+
}
|
|
262
|
+
/** After users wrote to the Worker: its data goes into a NEW Lambda table, then traffic goes back. */
|
|
263
|
+
export async function rollbackAfterWrites(options, deps) {
|
|
264
|
+
const { out } = deps;
|
|
265
|
+
const run = deps.run ?? runWrangler;
|
|
266
|
+
const node = deps.node ?? runNode;
|
|
267
|
+
const shell = deps.shell ?? runShell;
|
|
268
|
+
const path = stateFile(options.snapshotDir);
|
|
269
|
+
const state = readState(path) ?? { version: 1, phase: 'rolling-back-after-writes', done: [] };
|
|
270
|
+
if (state.phase === 'rolled-back-after-writes') {
|
|
271
|
+
out.info('rollback: already done');
|
|
272
|
+
return 0;
|
|
273
|
+
}
|
|
274
|
+
if (!options.yes) {
|
|
275
|
+
out.info(`rollback-after-writes plan (state: ${path})`);
|
|
276
|
+
for (const step of ROLLBACK_STEPS)
|
|
277
|
+
out.info(` ${state.done.includes(step) ? '✓' : '·'} ${step}`);
|
|
278
|
+
out.info('Nothing changed. Re-run with --yes to carry it out.');
|
|
279
|
+
return 0;
|
|
280
|
+
}
|
|
281
|
+
const data = async (operation, extra) => {
|
|
282
|
+
const code = await runData({ operation, dir: options.snapshotDir, config: options.config, secretsFile: options.secretsFile, ...extra }, deps.env, node);
|
|
283
|
+
if (code !== 0)
|
|
284
|
+
throw new CliError(`data ${operation} failed (exit ${code})`);
|
|
285
|
+
};
|
|
286
|
+
const target = { to: 'dynamodb', table: options.table, region: options.region, writeFence: true };
|
|
287
|
+
const actions = {
|
|
288
|
+
'maintenance-on': () => maintenance({ config: options.config, mode: 'on', secretsFile: options.secretsFile }, run, out),
|
|
289
|
+
export: () => data('export', { from: 'd1', writeFence: true }),
|
|
290
|
+
verify: () => data('verify', {}),
|
|
291
|
+
'lambda-deploy': async () => {
|
|
292
|
+
await shellOk(shell, options.lambdaDeploy, 'Lambda deploy onto the new table');
|
|
293
|
+
},
|
|
294
|
+
'fence-check': () => fenceIsOn(shell, options.fence),
|
|
295
|
+
import: () => data('import', target),
|
|
296
|
+
reconcile: () => data('reconcile', target),
|
|
297
|
+
'fence-off': async () => {
|
|
298
|
+
await shellOk(shell, `${options.fence} off`, 'fence off');
|
|
299
|
+
},
|
|
300
|
+
'switch-back': async () => {
|
|
301
|
+
await shellOk(shell, options.switchBack, 'switch back');
|
|
302
|
+
},
|
|
303
|
+
};
|
|
304
|
+
await runSteps(path, state, ROLLBACK_STEPS, actions, out);
|
|
305
|
+
state.phase = 'rolled-back-after-writes';
|
|
306
|
+
writeState(path, state);
|
|
307
|
+
out.info('rollback: the Lambda serves the data the Worker held, from the new table. Keep the table suffix in every later deploy.');
|
|
308
|
+
return 0;
|
|
309
|
+
}
|
|
310
|
+
//# sourceMapping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I,CAAC,WAAW,EAAE,MAAM,CAAC;QAC1C,WAAW,EAAE,KAAK,IAAI,EAAE;YACtB,MAAM,OAAO,CAAC,KAAK,EAAE,GAAG,OAAO,CAAC,KAAK,MAAM,EAAE,WAAW,CAAC,CAAC;QAC5D,CAAC;QACD,aAAa,EAAE,KAAK,IAAI,EAAE;YACxB,MAAM,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;QAC1D,CAAC;KACF,CAAC;IACF,MAAM,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;IAC1D,KAAK,CAAC,KAAK,GAAG,0BAA0B,CAAC;IACzC,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACxB,GAAG,CAAC,IAAI,CACN,wHAAwH,CACzH,CAAC;IACF,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/dist/data.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export declare const DATA_SNAPSHOT_CLI: string;
|
|
2
|
+
/**
|
|
3
|
+
* The local D1 of this config (`migrate --local`, `wrangler dev`): wrangler keeps it as a
|
|
4
|
+
* SQLite file under .wrangler/state next to the config. Exactly one database is expected.
|
|
5
|
+
*/
|
|
6
|
+
export declare function localD1File(config: string): string;
|
|
7
|
+
export type DataOperation = 'export' | 'verify' | 'check-hashes' | 'import' | 'reconcile';
|
|
8
|
+
export interface DataOptions {
|
|
9
|
+
operation: DataOperation;
|
|
10
|
+
dir: string;
|
|
11
|
+
config: string;
|
|
12
|
+
/** export: dynamodb | d1. */
|
|
13
|
+
from?: string;
|
|
14
|
+
/** import / reconcile: d1 (default) | dynamodb. */
|
|
15
|
+
to?: string;
|
|
16
|
+
table?: string;
|
|
17
|
+
region?: string;
|
|
18
|
+
writeFence?: boolean;
|
|
19
|
+
dryRun?: boolean;
|
|
20
|
+
plaintext?: boolean;
|
|
21
|
+
/** check-hashes: largest scrypt N the password engine accepts (its PASSWORD_ENGINE_MAX_N). */
|
|
22
|
+
maxN?: string;
|
|
23
|
+
/** Source of MFA_SECRET_KEY_ID / MFA_SECRET_PREVIOUS_KEYS when they are secrets. */
|
|
24
|
+
secretsFile?: string;
|
|
25
|
+
/** D1 is the local database (wrangler's SQLite file), not the remote one. */
|
|
26
|
+
local?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** Runs the bundled snapshot CLI; resolves with its exit code. Injected in tests. */
|
|
29
|
+
export type NodeRunner = (args: string[], env: NodeJS.ProcessEnv) => Promise<number>;
|
|
30
|
+
export declare const runNode: NodeRunner;
|
|
31
|
+
/** The MFA key ids the Worker decrypts with: MFA_SECRET_KEY_ID (default k1) and every previous key's id. */
|
|
32
|
+
export declare function mfaKeyIds(values: Record<string, string | undefined>): string[];
|
|
33
|
+
export declare function dataInvocation(options: DataOptions, env: NodeJS.ProcessEnv): {
|
|
34
|
+
args: string[];
|
|
35
|
+
env: NodeJS.ProcessEnv;
|
|
36
|
+
};
|
|
37
|
+
export declare function runData(options: DataOptions, env: NodeJS.ProcessEnv, run?: NodeRunner): Promise<number>;
|
|
38
|
+
export interface BootstrapAdminOptions {
|
|
39
|
+
config: string;
|
|
40
|
+
email: string;
|
|
41
|
+
create?: boolean;
|
|
42
|
+
displayName?: string;
|
|
43
|
+
local?: boolean;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* `bootstrap-admin`: the system tenant's owner on this Worker's D1 (a new deployment,
|
|
47
|
+
* dev, end-to-end tests; a moved deployment brings its admin in the snapshot). The same
|
|
48
|
+
* use case as the PostgreSQL server's `bootstrap-owner`. Idempotent for the same account;
|
|
49
|
+
* a different existing owner is refused. Password: BOOTSTRAP_OWNER_PASSWORD (with --create).
|
|
50
|
+
*/
|
|
51
|
+
export declare function runBootstrapAdmin(options: BootstrapAdminOptions, env: NodeJS.ProcessEnv, run?: NodeRunner): Promise<number>;
|
|
52
|
+
//# sourceMappingURL=data.d.ts.map
|
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