@runeditrun/rer 0.2.120 → 0.2.121
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/cli/README.md +49 -0
- package/cli/browser-runtime.mjs +32 -17
- package/cli/deploy-inputs.mjs +13 -0
- package/cli/deploy-settings.mjs +14 -0
- package/cli/deploy-variables.mjs +7 -1
- package/cli/deploy.mjs +2 -2
- package/cli/inspect.mjs +6 -1
- package/cli/lifecycle.mjs +1 -1
- package/cli/parse.mjs +11 -1
- package/global/CHANGELOG.md +16 -0
- package/global/browser-runtime.mjs +9 -5
- package/global/run.mjs +1 -1
- package/modules/deploy-kit/README.md +1 -0
- package/modules/deploy-kit/owner-cli.mjs +6 -4
- package/modules/deploy-kit/owner-secret-copy.mjs +2 -1
- package/modules/deploy-kit/owner-secret.mjs +1 -1
- package/modules/deploy-kit/owner.mjs +3 -2
- package/modules/deploy-kit/validation.mjs +1 -0
- package/modules/deploy-kit/worker.mjs +1 -0
- package/package.json +1 -1
package/cli/README.md
CHANGED
|
@@ -100,6 +100,25 @@ For older installations without an answer record, a runtime selection outside
|
|
|
100
100
|
the installer field's choices cannot replace an adapter-declared local choice.
|
|
101
101
|
Explicit answers and recorded installer choices still undergo strict validation.
|
|
102
102
|
|
|
103
|
+
## Browser prerequisites
|
|
104
|
+
|
|
105
|
+
Signed: Run Edit Run fleet, 2026-11-16.
|
|
106
|
+
|
|
107
|
+
`rer doctor` and `rer describe` inspect the checkout's Playwright registry
|
|
108
|
+
without launching or downloading a browser. Headless verification needs only
|
|
109
|
+
`chromium-headless-shell` when that Playwright pin provides it; older pins use
|
|
110
|
+
`chromium`. A checkout that also runs headed Chromium declares
|
|
111
|
+
`browser: { headless: false }` in its command adapter. That adds full Chromium
|
|
112
|
+
to verification's headless prerequisite. `rer run` also honors `--headed` and
|
|
113
|
+
`--debug` in the selected Playwright script or its forwarded arguments.
|
|
114
|
+
|
|
115
|
+
Missing executables are named with their use and one browser-only command
|
|
116
|
+
using the checkout's resolved Playwright CLI. Run that command from the checkout
|
|
117
|
+
root to acquire browsers without verification. `rer install` installs locked
|
|
118
|
+
dependencies without browsers. The first `rer verify` (or declared Playwright
|
|
119
|
+
`rer run`) downloads the required target; a headless-only checkout downloads
|
|
120
|
+
only the headless shell, using the pin's own platform and revision.
|
|
121
|
+
|
|
103
122
|
## Back up and restore this installation
|
|
104
123
|
|
|
105
124
|
Use `rer export` / `rer import` to back up and restore this installation. This
|
|
@@ -292,6 +311,36 @@ anything is built or uploaded. The seed owns what an installation does with mail
|
|
|
292
311
|
off, and turning mail on later is a `rer deploy --set-secret` of the provider
|
|
293
312
|
inputs the seed documents.
|
|
294
313
|
|
|
314
|
+
A seed can opt into a switchable public selector with one `deploy.json` edit:
|
|
315
|
+
|
|
316
|
+
```json
|
|
317
|
+
{
|
|
318
|
+
"publicSettings": ["MAIL_PROVIDER"],
|
|
319
|
+
"vars": { "MAIL_PROVIDER": "none" },
|
|
320
|
+
"secrets": [
|
|
321
|
+
{ "binding": "MAIL_PROVIDER", "environment": "MAIL_PROVIDER", "optional": true }
|
|
322
|
+
]
|
|
323
|
+
}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
Merge these entries into the existing declaration, keeping its other settings
|
|
327
|
+
and credentials. Retain the same `MAIL_PROVIDER=none` default in Wrangler vars
|
|
328
|
+
and the managed spec's `publicVariableNames`; the selector stays public in the
|
|
329
|
+
managed artifact, outside its secret names. `rer check` accepts this explicit
|
|
330
|
+
public default plus optional transport and reports conflicting source defaults.
|
|
331
|
+
`rer doctor` names the supported declaration when a source overlap is refused.
|
|
332
|
+
Declarations without this combination keep their previous behavior.
|
|
333
|
+
|
|
334
|
+
Use `rer deploy --set-secret MAIL_PROVIDER=sendgrid --set-secret MAIL_API_KEY
|
|
335
|
+
--env-file deploy.env` with the seed's declared sender and credential inputs.
|
|
336
|
+
The existing name-only form still reads the declared environment mapping.
|
|
337
|
+
`NAME=VALUE` is accepted only for opted-in public settings; credentials still
|
|
338
|
+
come from the environment or an owned 0600 `--env-file` and remain masked.
|
|
339
|
+
`rer deploy --unset-secret MAIL_PROVIDER,MAIL_API_KEY` removes those overrides
|
|
340
|
+
and restores the declared public default in the same Worker version. A plain
|
|
341
|
+
deploy preserves a held override. These changes use the existing ownership,
|
|
342
|
+
grouped-version and recovery machinery and preserve the admitted owner.
|
|
343
|
+
|
|
295
344
|
The adapter must apply that selection to the runtime as well as pass preflight.
|
|
296
345
|
For example, the foundation declares optional `MAIL_PROVIDER` and `MAIL_FROM`
|
|
297
346
|
environment-to-binding mappings in `deploy.json`, and makes `MAIL_API_KEY`
|
package/cli/browser-runtime.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import { RerError } from './errors.mjs';
|
|
|
10
10
|
import { shared } from './shared.mjs';
|
|
11
11
|
|
|
12
12
|
export const browserRepair = 'rer install';
|
|
13
|
-
export const browserDownload = 'rer verify downloads
|
|
13
|
+
export const browserDownload = 'rer verify downloads the required browser on first use; rer install installs dependencies, not browsers';
|
|
14
14
|
|
|
15
15
|
export function checkoutPlaywright(root, { required = true } = {}) {
|
|
16
16
|
const require = createRequire(join(root, 'package.json'));
|
|
@@ -33,42 +33,57 @@ export function checkoutPlaywright(root, { required = true } = {}) {
|
|
|
33
33
|
if (required) throw new RerError('browser_dependency_missing', `The checkout's Playwright is missing. Run ${browserRepair} to install its locked dependencies; verification requires playwright-core, @playwright/test or playwright.`, 3);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
// Verification uses headless Chromium. A checkout that also needs headed
|
|
37
|
+
// Chromium declares commandAdapter.browser = { headless: false }.
|
|
38
|
+
export async function browserDoctor(root, { headless = true } = {}) {
|
|
37
39
|
let resolved;
|
|
38
40
|
try { resolved = checkoutPlaywright(root); }
|
|
39
41
|
catch (error) { return { ok: false, issue: error instanceof RerError ? error.message : `The checkout's Playwright could not be inspected. Run ${browserRepair}.`, fix: browserRepair, executables: [] }; }
|
|
42
|
+
const shell = resolved.registry.findExecutable('chromium-headless-shell');
|
|
43
|
+
const names = headless && shell ? ['chromium-headless-shell'] : ['chromium', ...(shell ? ['chromium-headless-shell'] : [])];
|
|
40
44
|
const executables = [];
|
|
41
|
-
for (const name of
|
|
45
|
+
for (const name of names) {
|
|
42
46
|
// Releases before the separate headless shell use the Chromium executable.
|
|
43
|
-
const executable = resolved.registry.findExecutable(name);
|
|
44
|
-
if (!executable && name === 'chromium-headless-shell') continue;
|
|
47
|
+
const executable = name === 'chromium-headless-shell' ? shell : resolved.registry.findExecutable(name);
|
|
45
48
|
const path = executable?.executablePath();
|
|
46
49
|
let ok = false;
|
|
47
50
|
if (path) try { await access(path, process.platform === 'win32' ? constants.F_OK : constants.X_OK); ok = true; } catch {}
|
|
48
|
-
|
|
51
|
+
const reason = name === 'chromium-headless-shell' ? 'headless verification' : headless ? 'headless verification with this Playwright pin (no separate headless shell)' : 'declared headed browser use';
|
|
52
|
+
executables.push({ name, ...(path ? { path } : {}), ok, reason });
|
|
49
53
|
}
|
|
50
54
|
// Not yet downloaded is the normal state until a command needs the browser.
|
|
51
|
-
const missing = executables.filter(executable => !executable.ok)
|
|
52
|
-
|
|
55
|
+
const missing = executables.filter(executable => !executable.ok);
|
|
56
|
+
const target = headless && shell ? 'chromium-headless-shell' : 'chromium';
|
|
57
|
+
const command = browserInstallCommand(root, resolved.cli, target);
|
|
58
|
+
return { ok: true, package: resolved.name, headless, executables, ...(missing.length ? { command, note: `Playwright browser not downloaded yet: ${missing.map(({ name, reason }) => `${name} (needed for ${reason})`).join(', ')}. Browser-only install: ${command}; ${browserDownload}.` } : {}) };
|
|
53
59
|
}
|
|
54
60
|
|
|
55
|
-
|
|
61
|
+
// Quote project-relative paths for a command copied into the checkout's shell.
|
|
62
|
+
function browserInstallCommand(root, cli, target) {
|
|
63
|
+
const path = relative(root, cli).split('\\').join('/');
|
|
64
|
+
const quoted = /^[a-zA-Z0-9_./@-]+$/.test(path) ? path : process.platform === 'win32' ? `"${path}"` : "'" + path.replaceAll("'", "'\\''") + "'";
|
|
65
|
+
return `pnpm exec node ${quoted} install ${target}`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function ensureChromium(root, store, signal, { required = true, ...use } = {}) {
|
|
56
69
|
// A first-party adapter without browser dependencies remains valid.
|
|
57
70
|
// Verification requires Playwright; rer run provisions it when declared.
|
|
58
71
|
const resolved = checkoutPlaywright(root, { required });
|
|
59
72
|
if (!resolved) return;
|
|
60
|
-
|
|
61
|
-
|
|
73
|
+
const browser = await browserDoctor(root, use);
|
|
74
|
+
if (!browser.note) return;
|
|
75
|
+
const target = browser.headless && resolved.registry.findExecutable('chromium-headless-shell') ? 'chromium-headless-shell' : 'chromium';
|
|
62
76
|
const { dependencyEnvironment } = await shared('dependency-environment.mjs');
|
|
63
77
|
const env = dependencyEnvironment();
|
|
64
78
|
if (process.env.PLAYWRIGHT_BROWSERS_PATH !== undefined) env.PLAYWRIGHT_BROWSERS_PATH = process.env.PLAYWRIGHT_BROWSERS_PATH;
|
|
65
|
-
await store.run(
|
|
66
|
-
const
|
|
67
|
-
|
|
79
|
+
await store.run(`Installing ${target} from the checkout’s Playwright`, 'pnpm', ['exec', 'node', resolved.cli, 'install', target], { cwd: root, signal, env, display: browser.command });
|
|
80
|
+
const after = await browserDoctor(root, use);
|
|
81
|
+
const absent = after.executables.filter(executable => !executable.ok).map(executable => executable.name);
|
|
82
|
+
if (absent.length) throw new RerError('browser_install_incomplete', `The checkout's Playwright did not install the required browser (missing: ${absent.join(', ')}). Run ${browser.command} again; it retries the download.`, 3);
|
|
68
83
|
}
|
|
69
84
|
|
|
70
|
-
// Whether
|
|
71
|
-
export async function browsersPresent(root) {
|
|
72
|
-
const browser = await browserDoctor(root).catch(() => undefined);
|
|
85
|
+
// Whether the executables needed by this checkout's declared use are on disk.
|
|
86
|
+
export async function browsersPresent(root, use) {
|
|
87
|
+
const browser = await browserDoctor(root, use).catch(() => undefined);
|
|
73
88
|
return Boolean(browser?.ok && !browser.note);
|
|
74
89
|
}
|
package/cli/deploy-inputs.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { shared } from './shared.mjs';
|
|
|
4
4
|
import { invalid, refuse } from './errors.mjs';
|
|
5
5
|
import { readDeployEnvFile } from '../modules/deploy-kit/env-file.mjs';
|
|
6
6
|
import { publicOrigin } from '../modules/deploy-kit/public-origin.mjs';
|
|
7
|
+
import { switchableDefaults, switchableDeclarationHelp } from './deploy-settings.mjs';
|
|
7
8
|
import { keptSecrets, rotations, savedSecrets } from './deploy-secrets.mjs';
|
|
8
9
|
|
|
9
10
|
// The values a Workers deploy reads for its declared secrets: this process's
|
|
@@ -20,6 +21,7 @@ export async function deployEnvironment({ root, options, declaration, setupManif
|
|
|
20
21
|
catch (error) { throw invalid(`The --env-file ${options.envFile} could not be used: ${error.code === 'ENOENT' ? 'no such file' : error.message}.`); }
|
|
21
22
|
Object.assign(env, values);
|
|
22
23
|
}
|
|
24
|
+
await applyPublicAssignments(env, options, declaration, setupManifest);
|
|
23
25
|
const originSetting = declaration.publicOriginSetting;
|
|
24
26
|
if (originSetting !== undefined && env[originSetting] === undefined && settings) {
|
|
25
27
|
const { readSettings } = await shared('adapter-settings.mjs');
|
|
@@ -76,6 +78,7 @@ export async function withDeployEnvironment(project, options, out, run) {
|
|
|
76
78
|
const { createRedaction } = await shared('redaction.mjs');
|
|
77
79
|
const { declaredSettings, settingKinds, undeclaredNotice } = await import('./deploy-settings.mjs');
|
|
78
80
|
const declared = await declaredSettings(project), kinds = await settingKinds(declared);
|
|
81
|
+
await applyPublicAssignments(env, options, declared.declaration ?? {}, declared.setupManifest);
|
|
79
82
|
const redaction = createRedaction();
|
|
80
83
|
const supplied = Object.entries(env).filter(([key, value]) => saved[key] !== value);
|
|
81
84
|
redaction.addSecrets([...kinds.privateValues(env), ...supplied.filter(([key, value]) => !kinds.shown(key, value)).map(([, value]) => value)]);
|
|
@@ -97,3 +100,13 @@ export function deployAgain(options) {
|
|
|
97
100
|
const quote = value => /^[a-zA-Z0-9_./-]+$/.test(value) ? value : `'${String(value).replaceAll("'", "'\"'\"'")}'`;
|
|
98
101
|
return `rer deploy --environment ${quote(options.environment ?? 'production')}${options.envFile ? ` --env-file ${quote(options.envFile)}` : ''}${options.cwd ? ` --cwd ${quote(relative(process.cwd(), options.cwd) || '.')}` : ''}${options.dryRun ? ' --dry-run' : ''}`;
|
|
99
102
|
}
|
|
103
|
+
|
|
104
|
+
async function applyPublicAssignments(env, options, declaration, setupManifest) {
|
|
105
|
+
if (options.setSecretValues && declaration.project) {
|
|
106
|
+
const defaults = await switchableDefaults(declaration, setupManifest);
|
|
107
|
+
for (const [binding, value] of Object.entries(options.setSecretValues)) {
|
|
108
|
+
if (!Object.hasOwn(defaults, binding)) throw invalid(`--set-secret NAME=VALUE accepts only declared switchable public settings. ${switchableDeclarationHelp()} Supply credentials through the environment or an owned 0600 --env-file.`);
|
|
109
|
+
env[declaration.secrets.find(item => item.binding === binding).environment] = value;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
package/cli/deploy-settings.mjs
CHANGED
|
@@ -49,3 +49,17 @@ export async function declaredSettings(project) {
|
|
|
49
49
|
export function undeclaredNotice(names, path) {
|
|
50
50
|
return `Undeclared --env-file settings stay out of rer's output: ${names.join(', ')}. To print one, declare it as a non-secret setting: add its name to "publicSettings" in ${path}.`;
|
|
51
51
|
}
|
|
52
|
+
|
|
53
|
+
// Opt-in transport for a public choice with an explicit reset value. Keep this
|
|
54
|
+
// distinct from setup select fields: old declarations keep their exact plans.
|
|
55
|
+
export async function switchableDefaults(declaration, setupManifest) {
|
|
56
|
+
const kinds = await settingKinds({ declaration, setupManifest });
|
|
57
|
+
return Object.fromEntries((Array.isArray(declaration.secrets) ? declaration.secrets : []).filter(item =>
|
|
58
|
+
item?.optional === true && Array.isArray(declaration.publicSettings) && declaration.publicSettings.includes(item.binding) &&
|
|
59
|
+
kinds.shown(item.binding, declaration.vars?.[item.binding]) && kinds.shown(item.environment, declaration.vars?.[item.binding])
|
|
60
|
+
).map(item => [item.binding, declaration.vars[item.binding]]));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function switchableDeclarationHelp(path = 'deploy.json') {
|
|
64
|
+
return `For a switchable public setting such as MAIL_PROVIDER, declare its name in publicSettings, its default in vars, and a secrets entry with binding, environment and optional: true in ${path}; keep the same public default in Wrangler vars. Credentials remain secrets.`;
|
|
65
|
+
}
|
package/cli/deploy-variables.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import { tomlEntries } from './business/parsers-config.mjs';
|
|
|
7
7
|
import { imageVariableSecrets } from '../modules/container/image-variables.mjs';
|
|
8
8
|
import { publicMailSender, validateMailSenders } from '../modules/delivery-producer/mail.mjs';
|
|
9
9
|
import { deliveryDeclarationSources } from './delivery-declarations.mjs';
|
|
10
|
+
import { switchableDefaults, switchableDeclarationHelp } from './deploy-settings.mjs';
|
|
10
11
|
|
|
11
12
|
const id = 'deploy.vars-secrets';
|
|
12
13
|
const lineAt = (source, offset) => source.slice(0, offset).split('\n').length;
|
|
@@ -71,6 +72,7 @@ export async function deployVariableClause(root, adapter) {
|
|
|
71
72
|
privateSender ||= [...(spec.secretNames ?? []), ...(spec.optionalSecretNames ?? [])].includes('MAIL_FROM');
|
|
72
73
|
senders.push({ source: `${path} publicVariables.MAIL_FROM`, value: spec.publicVariables?.MAIL_FROM });
|
|
73
74
|
}
|
|
75
|
+
const defaults = await switchableDefaults(declaration);
|
|
74
76
|
const overlaps = [];
|
|
75
77
|
for (const path of deployConfigPaths(adapter)) {
|
|
76
78
|
for (const entry of await variableEntries(root, path)) {
|
|
@@ -78,12 +80,16 @@ export async function deployVariableClause(root, adapter) {
|
|
|
78
80
|
if (binding === 'MAIL_FROM') senders.push(entry);
|
|
79
81
|
const matched = new Set(imageVariableSecrets({ [binding]: value }, secrets).map(secret => secret.binding));
|
|
80
82
|
if (!matched.has(binding)) continue;
|
|
83
|
+
if (Object.hasOwn(defaults, binding)) {
|
|
84
|
+
if (value !== defaults[binding]) throw Error(`${binding}: ${entry.source} must match the public default in ${declarationPath} vars.${binding}.`);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
81
87
|
if (binding === 'MAIL_FROM' && publicSender && !privateSender) continue;
|
|
82
88
|
for (const [index, secret] of secrets.entries()) if (secret.binding === binding) overlaps.push(
|
|
83
89
|
`${binding}: ${entry.location} and ${declarationPath}:${secretLocations.get(index)} (secrets)`);
|
|
84
90
|
}
|
|
85
91
|
}
|
|
86
92
|
validateMailSenders(senders);
|
|
87
|
-
return overlaps.length ? { id, ok: false, message: overlaps.join('\n') + '\nremove it from wrangler vars; the deploy sets it as a secret' } : { id, ok: true };
|
|
93
|
+
return overlaps.length ? { id, ok: false, message: overlaps.join('\n') + '\nremove it from wrangler vars; the deploy sets it as a secret. ' + switchableDeclarationHelp(declarationPath) } : { id, ok: true };
|
|
88
94
|
} catch (error) { return { id, ok: false, message: error.message }; }
|
|
89
95
|
}
|
package/cli/deploy.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { mailOffSignInCommand } from './production-mail.mjs';
|
|
|
3
3
|
import { readFile } from 'node:fs/promises';
|
|
4
4
|
import { deployDiagnostic, migrationFailure, providerFailure, assetFailure } from '../modules/deploy-kit/diagnostics.mjs';
|
|
5
5
|
import { shared } from './shared.mjs';
|
|
6
|
-
import { settingKinds } from './deploy-settings.mjs';
|
|
6
|
+
import { settingKinds, switchableDeclarationHelp } from './deploy-settings.mjs';
|
|
7
7
|
import { contained } from './project.mjs';
|
|
8
8
|
import { missing, invalid, refuse, RerError } from './errors.mjs';
|
|
9
9
|
import { localOnlyBinding } from '../modules/deploy-kit/owner.mjs';
|
|
@@ -155,7 +155,7 @@ function secretChangeInputs(declaration, options, env, again) {
|
|
|
155
155
|
const declared = Array.isArray(declaration.secrets) ? declaration.secrets : [], flag = options.setSecret ? '--set-secret' : '--unset-secret';
|
|
156
156
|
const named = (options.setSecret ?? options.unsetSecret).split(',');
|
|
157
157
|
const undeclared = named.filter(name => !declared.some(item => item?.binding === name));
|
|
158
|
-
if (undeclared.length) throw invalid(`${flag} names ${undeclared.join(', ')}, which the deploy declaration does not list as ${undeclared.length > 1 ? 'secrets' : 'a secret'}${declared.length ? ` (it declares ${declared.map(item => item.binding).join(', ')})` : ''}. Nothing was changed.`);
|
|
158
|
+
if (undeclared.length) throw invalid(`${flag} names ${undeclared.join(', ')}, which the deploy declaration does not list as ${undeclared.length > 1 ? 'secrets' : 'a secret'}${declared.length ? ` (it declares ${declared.map(item => item.binding).join(', ')})` : ''}. ${switchableDeclarationHelp()} Nothing was changed.`);
|
|
159
159
|
if (!options.setSecret) return;
|
|
160
160
|
const absent = named.map(name => declared.find(item => item.binding === name).environment).filter(name => !env[name]?.trim());
|
|
161
161
|
if (absent.length) throw missing(`${flag} ${options.setSecret} needs a value for each secret; ${absent.join(', ')} ${absent.length > 1 ? 'are' : 'is'} not set. Set ${absent.length > 1 ? 'them' : 'it'} in the environment or in an --env-file file (owned, mode 0600, one line per secret), then run ${again} ${flag} ${options.setSecret} again. Nothing was changed.`);
|
package/cli/inspect.mjs
CHANGED
|
@@ -59,6 +59,7 @@ export async function describe(project) {
|
|
|
59
59
|
local: { state: project.adapter?.state, settings: project.adapter?.settings ?? [], installerState: '.seed/installer', ...await localState(project), origin: await savedOrigin(project), ...(project.adapter?.devIdentity ? { devIdentity: true, devKey: '.rer/local/dev-key.env' } : {}) },
|
|
60
60
|
// This pin serves a checkout through the machine's front door (rer door).
|
|
61
61
|
door: { protocol: doorProtocol },
|
|
62
|
+
browser: await browserDoctor(project.root, project.adapter?.browser),
|
|
62
63
|
};
|
|
63
64
|
}
|
|
64
65
|
|
|
@@ -241,7 +242,7 @@ export async function doctor(project, store, signal) {
|
|
|
241
242
|
if (directory) { usePnpm(directory); try { pnpm = await probePnpm(project.root, store, signal); pnpmIssues.length = 0; } catch (error) { if (signal?.aborted) throw error; pnpmIssues.push(store.redact(error.message)); } }
|
|
242
243
|
}
|
|
243
244
|
}
|
|
244
|
-
const browser = project.profile === 'first-party' ? await browserDoctor(project.root) : undefined;
|
|
245
|
+
const browser = project.profile === 'first-party' ? await browserDoctor(project.root, project.adapter?.browser) : undefined;
|
|
245
246
|
const aiIssues = await localAiDiagnostics(project,process.env);
|
|
246
247
|
const dependencies=project.profile==='first-party'?await dependencyDoctor(project.root):[];
|
|
247
248
|
const expectedNode = await projectNodePin(project.root);
|
|
@@ -264,6 +265,10 @@ export async function doctor(project, store, signal) {
|
|
|
264
265
|
}
|
|
265
266
|
const setupNeeded = firstParty ? !(await localState(project)).prepared : false;
|
|
266
267
|
const warnings = project.profile === 'first-party' ? await cacheWarnings(project.root) : [];
|
|
268
|
+
if (firstParty) {
|
|
269
|
+
const variables = await deployVariableClause(project.root, project.adapter);
|
|
270
|
+
if (!variables.ok) warnings.push(`Deployment declaration: ${variables.message}`);
|
|
271
|
+
}
|
|
267
272
|
return { dependencies, warnings, browser, operations: diagnostic, ok: browser?.ok !== false && !aiIssues.length && dependencies.every(d=>d.ok) && diagnostic.ok && stateValid && !inputs.length && (project.profile !== 'first-party' || (Boolean(expectedPnpm) && process.versions.node === expectedNode && pnpm === expectedPnpm)),
|
|
268
273
|
node: { actual: process.versions.node, expected: expectedNode },
|
|
269
274
|
pnpm: project.profile === 'first-party' ? { actual: pnpm, expected: expectedPnpm ?? null, ...(pnpmIssues.length ? { issue: [...new Set(pnpmIssues)].join('\n') } : {}) } : undefined,
|
package/cli/lifecycle.mjs
CHANGED
|
@@ -113,7 +113,7 @@ async function runLifecycle(project, options, out, deployRedaction) {
|
|
|
113
113
|
if (options.verb === 'verify') {
|
|
114
114
|
const target = adapter.verify;
|
|
115
115
|
if (!Array.isArray(target)) throw refuse('A complete internal verification target is missing.');
|
|
116
|
-
await ensureChromium(project.root, store, signal);
|
|
116
|
+
await ensureChromium(project.root, store, signal, project.adapter?.browser);
|
|
117
117
|
await store.run('Verifying application', target[0], target[1], { cwd: project.root, signal, env: { ...process.env, RER_LOCAL_OPERATION: operation.token } });
|
|
118
118
|
await store.step('Serving the production build as rer deploy hosts it');
|
|
119
119
|
const declaration = adapter.deployDeclaration ?? adapter.deploy?.declaration;
|
package/cli/parse.mjs
CHANGED
|
@@ -91,7 +91,17 @@ export function parse(argv, cwd = process.cwd(), { independent = false, deferTai
|
|
|
91
91
|
if (options.profile !== undefined && options.profile !== 'first-party') throw invalid('The supported explicit profile is first-party.');
|
|
92
92
|
if (options.environment !== undefined && !/^[a-z][a-z0-9-]{0,39}$/.test(options.environment)) throw invalid('Provide a valid deployment environment name.');
|
|
93
93
|
for (const key of ['setSecret', 'unsetSecret']) if (options[key] !== undefined) {
|
|
94
|
-
const
|
|
94
|
+
const entries = options[key].split(',');
|
|
95
|
+
const assignments = key === 'setSecret' ? entries.filter(entry => entry.includes('=')) : [];
|
|
96
|
+
if (assignments.length) {
|
|
97
|
+
options.setSecretValues = {};
|
|
98
|
+
for (const entry of assignments) {
|
|
99
|
+
const at = entry.indexOf('='), name = entry.slice(0, at), value = entry.slice(at + 1);
|
|
100
|
+
if (!value.trim() || value.length > 1024 || /[\u0000-\u001f\u007f]/.test(value) || Object.hasOwn(options.setSecretValues, name)) throw invalid('--set-secret NAME=VALUE requires one nonempty public setting value per binding.');
|
|
101
|
+
options.setSecretValues[name] = value;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const names = [...new Set(entries.map(entry => key === 'setSecret' ? entry.split('=', 1)[0] : entry))];
|
|
95
105
|
if (names.length > 16 || !names.every(name => /^[A-Z][A-Z0-9_]{0,63}$/.test(name))) throw invalid(`--${key === 'setSecret' ? '' : 'un'}set-secret names declared secret bindings, repeated or separated by commas, such as SESSION_SECRET or MAIL_API_KEY,MAIL_FROM.`);
|
|
96
106
|
options[key] = names.join(',');
|
|
97
107
|
}
|
package/global/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.121
|
|
4
|
+
|
|
5
|
+
Signed: Run Edit Run fleet, 2026-11-16.
|
|
6
|
+
|
|
7
|
+
### Browser prerequisites by declared use
|
|
8
|
+
|
|
9
|
+
- `rer doctor` and `rer describe` inspect the checkout's Playwright registry without downloading or launching a browser. Missing executables include their purpose and a browser-only install command using that checkout's resolved CLI.
|
|
10
|
+
- Headless verification provisions only `chromium-headless-shell` when the Playwright pin supplies it, otherwise Chromium. An adapter declaring `browser: { headless: false }` also requires full Chromium; `rer run` honors `--headed` and `--debug` in Playwright scripts and forwarded arguments. `rer install` installs dependencies without browsers; verification and declared Playwright runs acquire the required browser on first use. The installed launcher also provisions missing browsers for older checkout pins.
|
|
11
|
+
|
|
12
|
+
### Switchable public deployment settings
|
|
13
|
+
|
|
14
|
+
- Seeds can opt a public selector such as `MAIL_PROVIDER` into in-place changes by declaring it in `publicSettings`, giving it a public default in `vars`, and retaining an optional secret transport with its environment mapping. Wrangler defaults must agree. `rer check` accepts this combination and reports conflicting defaults; `rer doctor` explains a refused overlap. Managed specs retain the selector as public, outside secret names.
|
|
15
|
+
- `rer deploy --set-secret NAME=VALUE` accepts assignments only for opted-in public settings. Name-only inputs still use the declared environment mapping; credentials come from the environment or an owned 0600 `--env-file` and remain masked. Unsetting the selector restores its declared public default in the grouped Worker version, and a plain deploy preserves a held override. Existing ownership, grouped-version and recovery handling remains in use.
|
|
16
|
+
|
|
17
|
+
These changes require seed adoption and the explicit deployment declaration where applicable. This preparation establishes no provider delivery, deployment, seed adoption or production result. The source diff changes no portability, import-kit, product migrations or archive format identity.
|
|
18
|
+
|
|
3
19
|
## 0.2.120
|
|
4
20
|
|
|
5
21
|
### Commands under an approved Business grant
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
// An older checkout pin still runs its own verbs. The installed launcher
|
|
2
2
|
// supplies the browser prerequisite those pins did not yet provision.
|
|
3
|
-
import { browserDoctor, ensureChromium } from '../cli/browser-runtime.mjs';
|
|
3
|
+
import { browserDoctor, browsersPresent, ensureChromium } from '../cli/browser-runtime.mjs';
|
|
4
|
+
import { resolveProject } from '../cli/project.mjs';
|
|
4
5
|
import { output } from '../cli/output.mjs';
|
|
5
6
|
import { RerError } from '../cli/errors.mjs';
|
|
6
7
|
import { shared } from '../cli/shared.mjs';
|
|
7
8
|
|
|
8
9
|
export async function browserPreflight(root, argv) {
|
|
9
10
|
const verb = argv[0], out = output({ verb, json: argv.includes('--json') });
|
|
11
|
+
let use;
|
|
12
|
+
try { use = (await resolveProject(root)).adapter?.browser; } catch { /* The checkout's command reports invalid declarations. */ }
|
|
13
|
+
if (argv.includes('--headed') || argv.includes('--debug')) use = { ...use, headless: false };
|
|
10
14
|
if (verb === 'doctor') {
|
|
11
|
-
const browser = await browserDoctor(root);
|
|
15
|
+
const browser = await browserDoctor(root, use);
|
|
12
16
|
if (browser.ok) return;
|
|
13
17
|
const diagnostics = { browser, ok: false, scope: 'browser-prerequisite' };
|
|
14
18
|
if (!argv.includes('--json')) out.human(JSON.stringify(diagnostics, null, 2));
|
|
@@ -16,7 +20,7 @@ export async function browserPreflight(root, argv) {
|
|
|
16
20
|
return 3;
|
|
17
21
|
}
|
|
18
22
|
// Installed browsers need no download, and no log.
|
|
19
|
-
if (
|
|
23
|
+
if (await browsersPresent(root, use)) return;
|
|
20
24
|
const cancellation = new AbortController();
|
|
21
25
|
const state = { logs: [], step: 'Checking the checkout’s Playwright browsers' };
|
|
22
26
|
let store, termination;
|
|
@@ -30,7 +34,7 @@ export async function browserPreflight(root, argv) {
|
|
|
30
34
|
store.setCommandSignal(cancellation.signal);
|
|
31
35
|
// A fresh vendored pin installs its own dependencies; verify will acquire
|
|
32
36
|
// their browser on first need. Package pins have already been bootstrapped.
|
|
33
|
-
await ensureChromium(root, store, cancellation.signal, { required: verb === 'verify' });
|
|
37
|
+
await ensureChromium(root, store, cancellation.signal, { ...use, required: verb === 'verify' });
|
|
34
38
|
} catch (error) {
|
|
35
39
|
const failure = termination ? new RerError('cancelled', `Stopped by ${termination} after owned children were stopped.`, termination === 'SIGINT' ? 130 : 143) : await browserStepError(error, store, state, root);
|
|
36
40
|
out.error(failure); out.result(false, failure.exitCode);
|
|
@@ -47,5 +51,5 @@ async function browserStepError(error, store, state, root) {
|
|
|
47
51
|
const { checkoutPath, stepDiagnostic, stepFailureText } = await shared('step-failure.mjs');
|
|
48
52
|
const step = approvedFailure(error)?.step ?? stepDiagnostic({ name: state.step, output: state.logs, log: store ? store.redact(checkoutPath(root, store.logPath)) : null });
|
|
49
53
|
const cause = error instanceof RerError ? `\n${error.message}` : /^[A-Z][A-Z0-9_]{1,63}$/.test(error?.code ?? '') ? `\nCause: ${error.code}` : '';
|
|
50
|
-
return new RerError(error instanceof RerError ? error.code : 'browser_install_failed', `${stepFailureText(step)}${cause}\
|
|
54
|
+
return new RerError(error instanceof RerError ? error.code : 'browser_install_failed', `${stepFailureText(step)}${cause}\nRetry the browser-only install command shown above.`, error instanceof RerError ? error.exitCode : 1, { step });
|
|
51
55
|
}
|
package/global/run.mjs
CHANGED
|
@@ -66,7 +66,7 @@ export async function runScript(args) {
|
|
|
66
66
|
await projectNode(target.root, process.env);
|
|
67
67
|
} catch (error) { if (!(error instanceof RerError)) throw error; process.stderr.write(error.message + '\n'); return error.exitCode; }
|
|
68
68
|
if (args[0] && /\bplaywright\b/.test(scripts[args[0]] ?? '')) {
|
|
69
|
-
const code = await (await import('./browser-runtime.mjs')).browserPreflight(target.root, ['run']);
|
|
69
|
+
const code = await (await import('./browser-runtime.mjs')).browserPreflight(target.root, ['run', ...(scripts[args[0]].match(/--(?:headed|debug)\b/g) ?? []), ...args.slice(1)]);
|
|
70
70
|
if (code !== undefined) return code;
|
|
71
71
|
}
|
|
72
72
|
const { toolCommand } = await shared('tool-command.mjs');
|
|
@@ -135,6 +135,7 @@ change adds no retries and does not increase any timeout.
|
|
|
135
135
|
- **Inputs.** Declared secrets come from the environment, then `--env-file FILE` (an owned 0600 file of `KEY=VALUE` lines), which wins. For a secret the Worker does not hold yet, rer supplies the setup manifest's owner email (`emailField`) from the local setup's private settings, and for each secret field the manifest generates (`generate`) the value rer keeps for this environment in `.rer/deploy/<environment>.secrets.env` (0600, ignored by Git), else a fresh random value, which rer keeps once the Worker holds it (the one-time setup token is always fresh and never kept); a value the Worker already holds is kept. The build runs with the checkout's local settings files moved aside, and a `dist/` holding a `.dev.vars*`, `.env*` or `*.env` file is refused by name before any provider request. A still-missing secret stops the run before any write with a message that names it, unless its declaration says `"optional": true`: then the deploy binds nothing for it and reports it as not set, and `--set-secret` adds it later.
|
|
136
136
|
- **Hosted owner.** After deploy and health pass, rer claims the setup owner on the hosted app: it POSTs the setup token to the seed's standard owner step (`hooks.owner`, by default `/auth/bootstrap`). 303 means claimed; `409 already_initialized` means an owner was already claimed and is kept. Then rer deletes the token secret from the Worker, records the new Worker version in the state file, and lists the token in `retiredSecrets`, so later plans no longer declare it. The build fingerprint still names it, and the recorded claim stays as recorded, so an untouched repeat deploy writes nothing. A Worker that still holds a token rer did not upload in this run (an older deploy) first gets a fresh token through the same recorded secret change. Dependency approvals that need the token run before the claim. A seed with an owner step function, an identity-provider claim, or no declared token secret claims its owner its own way.
|
|
137
137
|
- **Several secrets at once.** `rer deploy --set-secret MAIL_API_KEY --set-secret MAIL_FROM` or `rer deploy --set-secret MAIL_API_KEY,MAIL_FROM` (likewise `--unset-secret A,B`) changes all of them in one new Worker version or none: a group of secrets is never half set. Every named secret must be declared and, for `--set-secret`, have its value in the environment or `--env-file`; otherwise rer names each missing one and changes nothing. One secret uses Cloudflare's secret call. Several are one copy of the live version through the Versions API (its own modules, assets and compatibility settings, every other binding inherited), then deployed at 100%: Cloudflare's per-secret calls each make a version, and its settings call can add secrets but not remove them (measured 17 October 2026). The copy carries a marker rer records first, so a copy whose answer was lost is recognised, and one uploaded but not deployed is deployed by the same command run again.
|
|
138
|
+
- **Public setting transport.** A name explicitly listed in `publicSettings`, with a string default in `vars` and an optional `secrets` entry, uses that entry only as override transport. Its public default is bound when the override is absent; `--unset-secret` restores it through the existing version-copy path, even for one setting. The matching Wrangler default remains public for managed-spec generation. Credential bindings, credential aliases and credential-shaped defaults cannot opt in. See [the declaration and commands](../../cli/README.md).
|
|
138
139
|
- **Secret changes.** `rer deploy --set-secret NAME` (value from the environment or `--env-file`, under the declaration's environment name), `--unset-secret NAME` and `--rotate-secret NAME[,NAME]` (a fresh value for a secret rer generates, kept in `.rer/deploy/<environment>.secrets.env` once set) change declared secrets of the recorded Worker without a build. Before writing, rer records the starting version and the exact live names of all other secrets, never their values. Accepted or ambiguous writes retain that intent until readback confirms the change; explicit refusals clear it. An ambiguous failure, or a later command's preflight, can clear an unapplied intent only when the live deployment still matches the receipt and the newest listed version matches it too. A surviving intent blocks further mutations until consistency returns; retry the same command then. Recovery requires the recorded immediate successor (or the recorded confirming rotation's successor), the receipt's script etag and fingerprint, the intended binding's presence, and an unchanged set of other secret names. Ambiguous rotations require a confirming PUT before reporting success. Older intents without names may recover only from the exact starting version's historical bindings, with its id, etag and fingerprint verified; unavailable or malformed historical bindings refuse adoption. Each historical binding must have an exact provider type supported by this kit; unrecognized types cannot prove that a name was not a secret. Added, removed or renamed other secrets refuse deploy and removal before writes. Values remain opaque: these checks cannot distinguish an otherwise identical outside change to the pending binding.
|
|
139
140
|
- **Installation key custody.** The setup manifest generates `INSTALLATION_KEY` independently of `SESSION_SECRET`. Hosted deployment keeps it in the same private, Git-ignored `.rer/deploy/<environment>.secrets.env`, before its first upload; `INSTALLATION_KEY_PREVIOUS` is optional and never generated by setup. `rer deploy --rotate-secret INSTALLATION_KEY` first saves a new/current and old/previous pair there, publishes both bindings in one Worker version, then reseals every dependency-key row through the recorded D1 database and verifies that every row opens with the current key. Only then does it remove the previous Worker binding. Routine rotation uses only the current/previous pair; older retired keys require explicit reopen. By default, every retired key remains in the same private file as `SESSION_SECRET`, in `INSTALLATION_KEY_RETIRED=<kid>:<value>[,<kid>:<value>...]`; retired keys never enter routine Worker bindings or archives. Resealing uses the [D1 transactional batch API](https://developers.cloudflare.com/api/resources/d1/subresources/database/methods/query/). Worker receipt and D1 identity checks precede database access. Any failure retains both saved values; rerun the same rotation command to resume with that exact pair. A D1 backup or Time Travel restore older than a rotation needs the corresponding retired key: `rer deploy --reopen-installation-key KID` publishes current plus only that retired key as previous, reseals and verifies every row through the same recorded D1, then removes the previous binding while retaining all retired custody. CLI-side reopen rekey uses every validated retired key in private custody to open mixed mid-rotation snapshots; only the selected pair is published to the Worker. Before opening rows, rekey reports the D1 `key_ids` tail and custody availability for every history ID. A whole pre-rotation restore with an unavailable tail reports `installation_key_unavailable`; a known row ID without its key reports `installation_key_version_unknown` only after the tail custody check succeeds. Failures retain the reopen marker and exact pair; repeat that command to finish. Missing retired custody refuses with `installation_key_unavailable` before provider writes: recover the private file before reopening. Back up private custody securely for as long as older database recovery points exist. Retain each retired key until no D1 Time Travel recovery point or exported backup predates the completed rotation that retired it or otherwise needs that key. After any rotation or reopen has finished, edit `.rer/deploy/<environment>.secrets.env` and remove only its `<kid>:<value>` entry from `INSTALLATION_KEY_RETIRED`, keeping valid comma separators; remove the assignment if no entries remain. Preserve the current key, all other entries and the file's owned 0600 permissions. There is no per-key removal command; reopening a removed ID refuses before provider writes unless its custody is restored. Base before #367 cannot open sealed keys; roll forward to sealing-capable code. The CLI has neither a Base-version capability receipt nor a code rollback operation, so out-of-band provider rollbacks cannot be checked here; current Base rejects sealed envelopes passed to plaintext signing with `installation_key_sealed_rollback`. Other deployment changes wait for completion. Manual installation-key set/unset, a conflicting supplied current key and a supplied previous key are refused. Without the current private key, restore custody from the deploying checkout before rotating. Neither keys nor database ciphertext appear in output.
|
|
140
141
|
- **Removal.** `rer deploy --remove --yes` deletes what the state file says rer created for this environment: the Worker (schedules first; its Durable Objects go with it) and each D1, R2, KV and queue that is still the one rer created, after checking all of them before the first delete. A replaced or uncertain resource refuses the whole removal, except a D1 or KV whose create answer was lost: under this environment's derived name it is deleted once confirmed empty (a D1 with no tables, a KV namespace with no keys); one holding data is refused as `uncertain-resource-not-empty`, and an uncertain queue, whose backlog rer cannot read, as `uncertain-resource-unverifiable` (delete it by hand if it is the empty one from the interrupted run).
|
|
@@ -18,6 +18,7 @@ import { ownerRekey } from './owner-rekey.mjs';
|
|
|
18
18
|
import { refuseLocalModels } from './local-only.mjs';
|
|
19
19
|
import { validateMigrations } from './migrations.mjs';
|
|
20
20
|
import { publicOrigin } from './public-origin.mjs';
|
|
21
|
+
import { switchableDefaults } from '../../cli/deploy-settings.mjs';
|
|
21
22
|
|
|
22
23
|
export const cronNotice = 'This Worker has a Cron Trigger. Cloudflare may take up to about two hours to start its first scheduled run on some accounts.';
|
|
23
24
|
const usage = 'usage: owner-cli.mjs deploy|dry-run|local-plan|health|remove|inspect|record-owner|signin|rekey|settle --declaration <file> --environment <name> [--product <dir>] [--state <file>] [--outcome claimed|kept] | secret ... --set NAME [--set NAME]|--unset NAME [--unset NAME]';
|
|
@@ -59,11 +60,12 @@ export async function main(argv = process.argv.slice(2), env = process.env, {fet
|
|
|
59
60
|
assert(typeof declaration?.project === 'string','missing-owner-project');
|
|
60
61
|
// Validate even direct kit invocations before any provider request or write.
|
|
61
62
|
publicOrigin(declaration, env);
|
|
63
|
+
const publicDefaults = await switchableDefaults(declaration);
|
|
62
64
|
let artifact;
|
|
63
65
|
if (command === 'dry-run' || command === 'local-plan') {
|
|
64
66
|
artifact = await packageBuild({root,source:{sha:'0'.repeat(40),tree:'0'.repeat(40)},runIdentity:{id:'0',attempt:'1'},productDirectory:values.product});
|
|
65
67
|
const worker = ownerWorkerName(declaration.project,values.environment);
|
|
66
|
-
const plan = ownerPlan({project:declaration.project,environment:values.environment,worker,origin:`https://${worker}.example.invalid`},declaration,artifact,{localOnlyKeys,env});
|
|
68
|
+
const plan = ownerPlan({project:declaration.project,environment:values.environment,worker,origin:`https://${worker}.example.invalid`},declaration,artifact,{localOnlyKeys,env,publicDefaults});
|
|
67
69
|
if (command === 'local-plan') for (const item of plan.d1) validateMigrations(item.migrations);
|
|
68
70
|
// Print names only: configuration values and migration SQL stay local.
|
|
69
71
|
// Return before constructing a provider client or resolving an account.
|
|
@@ -112,7 +114,7 @@ export async function main(argv = process.argv.slice(2), env = process.env, {fet
|
|
|
112
114
|
const named = [...new Set(values.set ?? values.unset)], declared = Array.isArray(declaration.secrets) ? declaration.secrets : [];
|
|
113
115
|
const undeclared = named.filter(binding => !declared.some(entry => entry?.binding === binding));
|
|
114
116
|
if (undeclared.length) { const error = new Error('undeclared-secret'); error.resource = undeclared.map(binding => `secret:${binding}`).join(', '); throw error; }
|
|
115
|
-
const changes = named.map(binding => ({binding, value:values.set === undefined ? undefined : env[declared.find(entry => entry?.binding === binding).environment]}));
|
|
117
|
+
const changes = named.map(binding => ({binding, value:values.set === undefined ? undefined : env[declared.find(entry => entry?.binding === binding).environment], ...(values.unset !== undefined && Object.hasOwn(publicDefaults,binding) ? {publicDefault:publicDefaults[binding]} : {})}));
|
|
116
118
|
return {ok:true,...await ownerSecret({api,target,statePath,changes,fetch,healthOptions,settle}).catch(error => { throw api.annotateFailure(error,'secrets'); })};
|
|
117
119
|
}
|
|
118
120
|
// A secret rer retired (the spent setup token) is no longer part of the plan.
|
|
@@ -145,7 +147,7 @@ export async function main(argv = process.argv.slice(2), env = process.env, {fet
|
|
|
145
147
|
}
|
|
146
148
|
const current = retiredSecrets.length && Array.isArray(declaration.secrets) ? {...declaration,secrets:declaration.secrets.filter(item => !retiredSecrets.includes(item?.binding))} : declaration;
|
|
147
149
|
artifact ??= await ownerArtifact(root,values.product);
|
|
148
|
-
const plan = ownerPlan(target,current,artifact,{localOnlyKeys,env});
|
|
150
|
+
const plan = ownerPlan(target,current,artifact,{localOnlyKeys,env,publicDefaults});
|
|
149
151
|
if (command === 'dry-run') {
|
|
150
152
|
const checked = withScopeHints(api);
|
|
151
153
|
const exists = await workerSettings(checked,target.worker) !== null;
|
|
@@ -162,7 +164,7 @@ export async function main(argv = process.argv.slice(2), env = process.env, {fet
|
|
|
162
164
|
// Dispatch is the provider's: on some accounts a new Cron starts only at the account scheduler's next refresh.
|
|
163
165
|
if (plan.crons.length) notice(cronNotice);
|
|
164
166
|
// The fingerprint names every declared secret, retired ones too: an untouched repeat after the claim is a no-op.
|
|
165
|
-
const declaredSecrets = current === declaration ? plan.secrets : ownerPlan(target,declaration,artifact,{localOnlyKeys,env}).secrets;
|
|
167
|
+
const declaredSecrets = current === declaration ? plan.secrets : ownerPlan(target,declaration,artifact,{localOnlyKeys,env,publicDefaults}).secrets;
|
|
166
168
|
const window = readinessWindow({...(healthOptions?.now ? {clock:healthOptions.now} : {}), ...(healthOptions?.sleep ? {sleep:healthOptions.sleep} : {}), ...healthOptions?.readiness});
|
|
167
169
|
requestWindow = window;
|
|
168
170
|
const {receipt,created,sentSecrets,unsetSecrets,freshUpload} = await ownerDeploy({api,target,plan,artifact,statePath,env,fetch,healthOptions,readiness:{...healthOptions?.readiness,window},settle,declaredSecrets}).catch(error => {
|
|
@@ -17,7 +17,8 @@ export async function uploadSecretCopy(api, worker, live, {changes, marker}) {
|
|
|
17
17
|
const named = new Set(changes.map(change => change.binding));
|
|
18
18
|
const metadata = {main_module:entry, compatibility_date:runtime.compatibility_date, compatibility_flags:runtime.compatibility_flags ?? [],
|
|
19
19
|
bindings:[...bindings.filter(row => !named.has(row.name)).map(row => ({type:'inherit',name:row.name})),
|
|
20
|
-
...changes.
|
|
20
|
+
...changes.flatMap(change => change.value !== undefined ? [{type:'secret_text',name:change.binding,text:change.value}]
|
|
21
|
+
: change.publicDefault !== undefined ? [{type:'plain_text',name:change.binding,text:change.publicDefault}] : [])],
|
|
21
22
|
keep_assets:true, annotations:{'workers/message':copyMessage(marker)}};
|
|
22
23
|
const data = new FormData();
|
|
23
24
|
data.set('metadata', new Blob([JSON.stringify(metadata)], {type:'application/json'}));
|
|
@@ -41,7 +41,7 @@ export async function ownerSecret({api: provider, target, statePath, changes, fe
|
|
|
41
41
|
assert(names, 'invalid-secret-list');
|
|
42
42
|
// Removing secrets the Worker does not hold changes nothing; the rest of a removal still runs.
|
|
43
43
|
const writes = present ? changes : changes.filter(change => names.includes(change.binding));
|
|
44
|
-
const existed = writes.some(change => names.includes(change.binding)), changed = writes.length > 0, copy = writes.length > 1;
|
|
44
|
+
const existed = writes.some(change => names.includes(change.binding)), changed = writes.length > 0, copy = writes.length > 1 || writes.some(change => change.publicDefault !== undefined);
|
|
45
45
|
state.pendingSecret = {bindings, present, versionId:state.receipt.provider.versionId, names:names.filter(name => !bindings.includes(name)).sort(), ...(copy ? {copy:randomBytes(16).toString('hex')} : {})};
|
|
46
46
|
await writeOwnerState(statePath, state);
|
|
47
47
|
let failure, unchanged = false, confirming = false, uploaded = false;
|
|
@@ -144,7 +144,7 @@ export function localOnlyBinding(declaration, localOnlyKeys = []) {
|
|
|
144
144
|
return names.find(name => refused.has(name)) ?? null;
|
|
145
145
|
}
|
|
146
146
|
/** A seed declares bindings, never names. Migrations come from the packaged artifact. */
|
|
147
|
-
export function ownerPlan(target, declaration, artifact, { localOnlyKeys = [], env = {} } = {}) {
|
|
147
|
+
export function ownerPlan(target, declaration, artifact, { localOnlyKeys = [], env = {}, publicDefaults = {} } = {}) {
|
|
148
148
|
assert(declaration?.version === 1 && typeof declaration === 'object' && Object.keys(declaration).every(key => DECLARATION_KEYS.includes(key)), 'invalid-owner-declaration');
|
|
149
149
|
assert(declaration.publicSettings === undefined || Array.isArray(declaration.publicSettings) && new Set(declaration.publicSettings).size === declaration.publicSettings.length && declaration.publicSettings.every(name => typeof name === 'string' && /^[A-Z][A-Z0-9_]*$/.test(name)), 'invalid-public-settings');
|
|
150
150
|
ownerPlatforms(declaration);
|
|
@@ -165,6 +165,7 @@ export function ownerPlan(target, declaration, artifact, { localOnlyKeys = [], e
|
|
|
165
165
|
const queues = entries(declaration,'queues');
|
|
166
166
|
for (const item of queues) assert(item.deadLetterQueue === undefined || queues.some(other => other.binding === item.deadLetterQueue), 'invalid-dead-letter-queue');
|
|
167
167
|
const vars = {...(declaration.vars ?? {})};
|
|
168
|
+
for (const name of Object.keys(publicDefaults)) if (declaration.secrets?.some(item => item.binding === name)) delete vars[name];
|
|
168
169
|
const origin = publicOrigin(declaration, env);
|
|
169
170
|
if (declaration.originVar !== undefined) {
|
|
170
171
|
assert(identifier(declaration.originVar) && !Object.hasOwn(vars,declaration.originVar), 'invalid-owner-origin-variable');
|
|
@@ -183,7 +184,7 @@ export function ownerPlan(target, declaration, artifact, { localOnlyKeys = [], e
|
|
|
183
184
|
durableObjects:entries(declaration,'durableObjects').map(item => ({...item})),
|
|
184
185
|
// verifyStandIn is only `rer verify`'s hosted-check value: never planned, sent or stored.
|
|
185
186
|
// An optional secret (`"optional": true`, an integration's credential) may stay unset: it is bound only once supplied.
|
|
186
|
-
secrets:entries(declaration,'secrets').map(({verifyStandIn,...item}) => { assert(verifyStandIn === undefined || typeof verifyStandIn === 'string' && verifyStandIn.length > 0 && verifyStandIn.length <= 1024, 'invalid-verify-stand-in'); return item; }),
|
|
187
|
+
secrets:entries(declaration,'secrets').map(({verifyStandIn,...item}) => { assert(verifyStandIn === undefined || typeof verifyStandIn === 'string' && verifyStandIn.length > 0 && verifyStandIn.length <= 1024, 'invalid-verify-stand-in'); return Object.hasOwn(publicDefaults,item.binding) ? {...item,publicDefault:publicDefaults[item.binding]} : item; }),
|
|
187
188
|
crons:[...(declaration.crons ?? [])],vars,
|
|
188
189
|
// Only declarations using these add the keys, so earlier plans and fingerprints are unchanged.
|
|
189
190
|
...(services.length ? {services} : {}),...(declaration.workersDev === false ? {workersDev:false} : {})});
|
|
@@ -32,6 +32,7 @@ export function validatePlan(plan) {
|
|
|
32
32
|
for (const entry of plan.durableObjects) assert(identifier(entry.className) && ['sqlite','classic'].includes(entry.storage), 'invalid-durable-object');
|
|
33
33
|
for (const secret of plan.secrets) assert(identifier(secret.environment), 'invalid-secret-environment');
|
|
34
34
|
for (const secret of plan.secrets) assert(secret.optional === undefined || secret.optional === true, 'invalid-optional-secret');
|
|
35
|
+
for (const secret of plan.secrets) assert(secret.publicDefault === undefined || secret.optional === true && typeof secret.publicDefault === 'string', 'invalid-public-secret-default');
|
|
35
36
|
for (const item of plan.services ?? []) assert(Object.keys(item).every(k => ['binding','service','entrypoint','props','grant'].includes(k)) && resourceName(item.service) && item.service !== plan.worker
|
|
36
37
|
&& (item.entrypoint === undefined || identifier(item.entrypoint))
|
|
37
38
|
&& (item.props === undefined || Object.keys(item.props).join() === 'allowedHosts' && Array.isArray(item.props.allowedHosts)
|
|
@@ -58,6 +58,7 @@ export async function secretBindings(api, worker, plan, env, exists) {
|
|
|
58
58
|
}
|
|
59
59
|
for (const item of plan.secrets) {
|
|
60
60
|
if (names.includes(item.binding)) bindings.push({type:'inherit',name:item.binding});
|
|
61
|
+
else if (unset.includes(item.binding) && item.publicDefault !== undefined) bindings.push({type:'plain_text',name:item.binding,text:item.publicDefault});
|
|
61
62
|
else if (!unset.includes(item.binding)) {
|
|
62
63
|
bindings.push({type:'secret_text',name:item.binding,text:env[item.environment]});
|
|
63
64
|
}
|