@runeditrun/rer 0.2.21 → 0.2.23
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 +26 -0
- package/cli/bounded.mjs +5 -1
- package/cli/delivery-declarations.mjs +2 -2
- package/cli/demo-host.mjs +5 -5
- package/cli/deploy-command.mjs +2 -2
- package/cli/deploy-inputs.mjs +4 -1
- package/cli/deploy.mjs +7 -3
- package/cli/deployment-record.mjs +52 -0
- package/cli/export.mjs +1 -1
- package/cli/local.mjs +11 -3
- package/cli/managed-server.mjs +7 -3
- package/cli/output.mjs +1 -1
- package/cli/production-auth.mjs +7 -13
- package/cli/production-mail.mjs +72 -0
- package/cli/signin.mjs +11 -6
- package/global/CHANGELOG.md +9 -0
- package/modules/container/README.md +18 -3
- package/modules/container/build.mjs +8 -12
- package/modules/container/host.mjs +9 -4
- package/modules/container/ingress.mjs +15 -4
- package/modules/container/migration-inventory.mjs +33 -0
- package/modules/container/migrations.mjs +16 -2
- package/modules/container/websockets.mjs +54 -0
- package/modules/container/worker-engine.mjs +2 -2
- package/modules/delivery-producer/migrations.mjs +61 -0
- package/modules/demo/README.md +4 -0
- package/modules/demo/effects.mjs +4 -0
- package/modules/demo/label.mjs +7 -4
- package/modules/demo/responses.mjs +1 -1
- package/modules/demo-host/README.md +32 -19
- package/modules/demo-host/capacity.mjs +3 -3
- package/modules/demo-host/container.mjs +65 -37
- package/modules/demo-host/pages.mjs +1 -1
- package/modules/demo-host/plan.mjs +19 -6
- package/modules/demo-host/remove.mjs +9 -7
- package/modules/demo-host/start-script.mjs +10 -1
- package/modules/demo-host/startup.mjs +4 -2
- package/modules/demo-host/worker.mjs +28 -7
- package/modules/dependencies/approval.mjs +3 -2
- package/modules/dependencies/index.mjs +2 -2
- package/modules/deploy-kit/README.md +4 -2
- package/modules/deploy-kit/diagnostics.mjs +9 -0
- package/modules/deploy-kit/owner-signin.mjs +1 -1
- package/modules/deploy-kit/provider-transport.mjs +56 -0
- package/modules/deploy-kit/provider.mjs +22 -20
- package/modules/mail/README.md +14 -5
- package/modules/mail/src/adapters/rer/contract.mjs +33 -5
- package/modules/mail/src/adapters/rer/index.mjs +4 -1
- package/modules/mail/src/core/transport.mjs +9 -3
- package/modules/operator-auth/README.md +9 -0
- package/modules/operator-auth/accounts/credentials.mjs +2 -2
- package/modules/operator-auth/accounts/email-change.mjs +2 -2
- package/modules/operator-auth/accounts/provider-control.mjs +3 -3
- package/modules/operator-auth/accounts/store.mjs +9 -8
- package/modules/operator-auth/dev/cli-session.mjs +5 -4
- package/modules/operator-auth/dev/index.mjs +5 -5
- package/modules/operator-auth/dev-gate.mjs +4 -2
- package/modules/operator-auth/identity/email-link/index.mjs +7 -1
- package/modules/operator-auth/signin/index.mjs +10 -2
- package/onboarding/adapter.mjs +11 -3
- package/onboarding/local/operation.mjs +4 -2
- package/onboarding/local/owner.mjs +9 -3
- package/onboarding/local/state-files.mjs +17 -0
- package/onboarding/operator-installer.mjs +2 -2
- package/onboarding/operator-migrations.mjs +48 -0
- package/onboarding/process-diagnostics.mjs +25 -5
- package/onboarding/process-table.mjs +45 -19
- package/package.json +1 -1
- package/scripts/publish-check/README.md +5 -2
- package/scripts/publish-check/content_identities.py +1 -1
- package/scripts/publish-check/json_identity.py +10 -1
- package/scripts/publish-check/public_hygiene.py +30 -4
package/cli/README.md
CHANGED
|
@@ -47,6 +47,13 @@ owner/sign-in hooks. The reference hook declaration is
|
|
|
47
47
|
internal build/dev/verify targets and deployment policy. The CLI owns flags,
|
|
48
48
|
pins, containment, cancellation, capture, output and sequencing.
|
|
49
49
|
|
|
50
|
+
`rer dev` runs the local migration hook before starting the app and checking its
|
|
51
|
+
owner prerequisites. The shared operator hook reads every SQL file in the seed's
|
|
52
|
+
canonical `migrations/core` inventory, including changes pulled since the last
|
|
53
|
+
build, and prints the applied names. A failed migration stops startup with its
|
|
54
|
+
captured error and `rer setup` guidance. `rer demo` uses the same inventory in
|
|
55
|
+
its isolated state directory.
|
|
56
|
+
|
|
50
57
|
Successful terminal setup saves declared nonsecret installer answers in owned
|
|
51
58
|
0600 storage under `.seed/installer`. A non-interactive repeat reuses those
|
|
52
59
|
answers, with explicit flags or an answers file taking precedence. Runtime
|
|
@@ -118,6 +125,14 @@ rebuild preview. A build that regenerates its own files declares them as
|
|
|
118
125
|
`generatedOutputs` on the command adapter (see the seed command contract); those
|
|
119
126
|
paths are not inputs, while any other file touched during the build is refused by name. Both use the same `.wrangler/state` and saved owner. Dev opens signed in through `RER_OPEN`, including with the legacy
|
|
120
127
|
`--login` flag. Stop before changing modes.
|
|
128
|
+
|
|
129
|
+
Local startup holds the checkout's exclusive operation lock until serving stops.
|
|
130
|
+
Its state-holder inspection selects only regular files under `.wrangler/state`,
|
|
131
|
+
including SQLite sidecars. Dev and demo give `lsof` three seconds to answer. A confirmed
|
|
132
|
+
holder is refused with its PID and process name. If inspection cannot answer,
|
|
133
|
+
dev (including demo) continues under the held checkout lock; another
|
|
134
|
+
cooperating launch cannot acquire it. This lock does not inventory unmanaged
|
|
135
|
+
processes. Setup, reset and preview still require their state inspection to complete.
|
|
121
136
|
Stop dev or preview before build, verification or data transfer; use the
|
|
122
137
|
documented `--stop` flag or Ctrl-C.
|
|
123
138
|
|
|
@@ -174,6 +189,17 @@ secrets after the provider verifies the owned deployment. Local setup and demo
|
|
|
174
189
|
do not require production mail credentials. Preview serves production output
|
|
175
190
|
and prints its ready address without a captured-mail sign-in flow.
|
|
176
191
|
|
|
192
|
+
The production preflight also reads the product's `artifact.specInputs` in
|
|
193
|
+
`rer-packaging.json`, `packaging.json` or `scripts/delivery/base/packaging.json`,
|
|
194
|
+
and `management/integration/deployment-spec.json`. Public inputs come from
|
|
195
|
+
`publicVariableNames` or fixed `publicVariables`; credentials come from
|
|
196
|
+
`secretNames` and `optionalSecretNames`. Native `SENDGRID_API_KEY` and
|
|
197
|
+
`RESEND_API_KEY` satisfy their respective providers. When `MAIL_PROVIDER` is
|
|
198
|
+
`later` or absent, a declared native provider key plus a declared `MAIL_FROM`
|
|
199
|
+
resolves the deferred choice for preflight. An explicitly selected provider
|
|
200
|
+
still requires its own credentials. Undeclared environment values do not count;
|
|
201
|
+
the product's deploy adapter remains responsible for applying these settings.
|
|
202
|
+
|
|
177
203
|
Idle timeout is `--idle-timeout SECONDS`, then `RER_SERVER_IDLE_SECONDS`, then
|
|
178
204
|
43200 seconds (12 hours). Only positive integer seconds are accepted. HTTP requests,
|
|
179
205
|
including assets, reset inactivity; a live request/stream prevents idle
|
package/cli/bounded.mjs
CHANGED
|
@@ -66,7 +66,11 @@ export async function boundedCommand(project,options,argv,out){
|
|
|
66
66
|
out.error(new RerError('cancelled',`Stopped by ${termination} after owned children were stopped.`,exitCode));
|
|
67
67
|
out.result(false,exitCode);
|
|
68
68
|
}else if(finalEvent&&finalEvent.exitCode===exitCode){
|
|
69
|
-
if(errorEvent)
|
|
69
|
+
if(errorEvent){
|
|
70
|
+
let deployment={};
|
|
71
|
+
try{deployment=JSON.parse(store.redact(JSON.stringify({environment:errorEvent.environment,availableDeployments:errorEvent.availableDeployments})));}catch{}
|
|
72
|
+
out.error(new RerError(errorEvent.code,store.redact(errorEvent.message),exitCode,deployment));
|
|
73
|
+
}
|
|
70
74
|
const {version,verb,event,ok,exitCode:childExit,...details}=finalEvent;
|
|
71
75
|
// Redaction can cut through a value that matches a credential; the outcome stands without its details.
|
|
72
76
|
let shown;try{shown=JSON.parse(store.redact(JSON.stringify(details)));}catch{shown={};}
|
|
@@ -4,7 +4,7 @@ import { contained } from './project.mjs';
|
|
|
4
4
|
|
|
5
5
|
// Source policy and its committed integration projection. Inspect declarations
|
|
6
6
|
// without requiring a build or executing the seed's packaging code.
|
|
7
|
-
const
|
|
7
|
+
export const deliveryDeclarationSources = [
|
|
8
8
|
['rer-packaging.json', value => value?.artifact?.specInputs],
|
|
9
9
|
['packaging.json', value => value?.artifact?.specInputs],
|
|
10
10
|
['scripts/delivery/base/packaging.json', value => value?.artifact?.specInputs],
|
|
@@ -13,7 +13,7 @@ const sources = [
|
|
|
13
13
|
|
|
14
14
|
export async function deliveryDeclarationClauses(root) {
|
|
15
15
|
const clauses = [];
|
|
16
|
-
for (const [path, select] of
|
|
16
|
+
for (const [path, select] of deliveryDeclarationSources) {
|
|
17
17
|
let text;
|
|
18
18
|
try { text = await readFile(await contained(root, path, { optional: true }), 'utf8'); }
|
|
19
19
|
catch (error) {
|
package/cli/demo-host.mjs
CHANGED
|
@@ -19,7 +19,7 @@ export async function demoHostCommand(project, options, store, signal, out, oper
|
|
|
19
19
|
const app = await read(project.adapter.deploy?.declaration ?? 'deploy.json'), declaration = await read('deploy-demo.json');
|
|
20
20
|
if (!(app.platforms ?? ['workers']).includes('container')) throw refuse('A hosted demo runs the seed\'s container image: declare "container" in deploy.json platforms first.');
|
|
21
21
|
let plan;
|
|
22
|
-
try { plan = demoPlan({ project: app.project, environment: options.environment ?? 'production', compatibilityDate: app.compatibilityDate, originVar: app.originVar, declaration, turnstileSiteKey: process.env.TURNSTILE_SITE_KEY?.trim() }); }
|
|
22
|
+
try { plan = demoPlan({ project: app.project, environment: options.environment ?? 'production', compatibilityDate: app.compatibilityDate, originVar: app.originVar, hostVariables: app.container?.hostVariables, declaration, turnstileSiteKey: process.env.TURNSTILE_SITE_KEY?.trim() }); }
|
|
23
23
|
catch (error) { throw invalid(`The demo deploy declaration is invalid (${error.message}). deploy-demo.json holds {"version": 1, "domain": "<run site apex>", "name": "<product name>"}, optionally "maxInstances", "instanceType" (${INSTANCE_TYPES.join(', ')}; default basic) and plain "settings".`); }
|
|
24
24
|
if (options.remove) return removeDemo(plan, store, signal);
|
|
25
25
|
if (process.env.RER_DEMO_OPERATOR_TOKEN && (process.env.RER_DEMO_OPERATOR_TOKEN.length < 32 || process.env.RER_DEMO_OPERATOR_TOKEN.length > 512)) throw invalid('RER_DEMO_OPERATOR_TOKEN must contain 32 to 512 characters.');
|
|
@@ -31,8 +31,8 @@ export async function demoHostCommand(project, options, store, signal, out, oper
|
|
|
31
31
|
await prepareDemoImage(join(folder, 'image'));
|
|
32
32
|
for (const file of DEMO_FILES) await cp(new URL(`../modules/demo-host/${file}`, import.meta.url), join(folder, file));
|
|
33
33
|
await writeFile(join(folder, 'wrangler.json'), JSON.stringify(plan.wrangler, null, 2) + '\n');
|
|
34
|
-
const summary = { worker: plan.worker, origin: plan.origin, hostname: plan.hostname, folder: '.rer/demo-host', maxInstances: plan.maxInstances, settings: plan.settings, instanceType: plan.instanceType, startsPerIpPerMinute: 3, minutes: 60, idleMinutes: 15, enableInternet: true };
|
|
35
|
-
const human = [`Demo plan: Worker ${summary.worker} on ${summary.
|
|
34
|
+
const summary = { worker: plan.worker, origin: plan.origin, hostname: plan.hostname, hostnames: plan.hostnames, routes: plan.wrangler.routes, folder: '.rer/demo-host', maxInstances: plan.maxInstances, settings: plan.settings, instanceType: plan.instanceType, startsPerIpPerMinute: 3, minutes: 60, idleMinutes: 15, enableInternet: true };
|
|
35
|
+
const human = [`Demo plan: Worker ${summary.worker} on ${summary.hostnames.join(', ')} (custom domains; workers.dev off), written to ${summary.folder}`,
|
|
36
36
|
` one container per visitor (${summary.instanceType}, at most ${summary.maxInstances} at once, public internet, RER_DEMO=1), 3 starts per IP per minute behind Turnstile`,
|
|
37
37
|
` each demo ends after 60 minutes or 15 idle minutes; its container is destroyed and its state deleted`];
|
|
38
38
|
if (options.dryRun) {
|
|
@@ -61,7 +61,7 @@ async function removeDemo(plan, store, signal) {
|
|
|
61
61
|
const { providerRefusal } = await import('../modules/deploy-kit/diagnostics.mjs');
|
|
62
62
|
const { demoRemove } = await import('../modules/demo-host/remove.mjs');
|
|
63
63
|
const { demoRemovalFetch } = await import('./demo-removal-provider.mjs');
|
|
64
|
-
await store.step(`Removing the demo Worker ${plan.worker} on ${plan.
|
|
64
|
+
await store.step(`Removing the demo Worker ${plan.worker} on ${plan.hostnames.join(', ')}`);
|
|
65
65
|
let result;
|
|
66
66
|
try { result = await demoRemove({ api: cloudflare({ accountId: process.env.CLOUDFLARE_ACCOUNT_ID, token: process.env.CLOUDFLARE_API_TOKEN, fetch: demoRemovalFetch(signal) }), plan }); }
|
|
67
67
|
catch (error) {
|
|
@@ -71,5 +71,5 @@ async function removeDemo(plan, store, signal) {
|
|
|
71
71
|
throw new RerError('deploy_refused', `Demo remove stopped: ${code}${detail ? ` ${detail}` : ''}. Nothing that is not the demo's was touched; run it again once the cause is fixed.`, 1);
|
|
72
72
|
}
|
|
73
73
|
store.report(result.alreadyRemoved ? `deploy --demo --remove: no demo Worker ${plan.worker} exists; nothing to remove.` : `Removed ${result.removed.join(', ')} and read back that each is gone.`);
|
|
74
|
-
return { removed: true, demo: { worker: plan.worker, hostname: plan.hostname }, deleted: result.removed, alreadyRemoved: Boolean(result.alreadyRemoved) };
|
|
74
|
+
return { removed: true, demo: { worker: plan.worker, hostname: plan.hostname, hostnames: plan.hostnames }, deleted: result.removed, alreadyRemoved: Boolean(result.alreadyRemoved) };
|
|
75
75
|
}
|
package/cli/deploy-command.mjs
CHANGED
|
@@ -15,7 +15,7 @@ import { rememberHookState, hookState } from './deploy-hook-record.mjs';
|
|
|
15
15
|
import { main as owner } from '../modules/deploy-kit/owner-cli.mjs';
|
|
16
16
|
import { localOnlyBinding, ownerWorkerName } from '../modules/deploy-kit/owner.mjs';
|
|
17
17
|
import { refuseLocalModels } from '../modules/deploy-kit/local-only.mjs';
|
|
18
|
-
import { providerRefusal } from '../modules/deploy-kit/diagnostics.mjs';
|
|
18
|
+
import { providerRefusal, providerTransport } from '../modules/deploy-kit/diagnostics.mjs';
|
|
19
19
|
import { shared } from './shared.mjs';
|
|
20
20
|
|
|
21
21
|
export function validateDeployOptions(options) {
|
|
@@ -136,7 +136,7 @@ export async function deployCommand(context) {
|
|
|
136
136
|
if (setup) throw commandFailure(redact(setup));
|
|
137
137
|
const readiness = mutationReadinessFailure(error, { again, redact });
|
|
138
138
|
if (readiness) throw commandFailure(readiness);
|
|
139
|
-
const refused = providerRefusal(error);
|
|
139
|
+
const refused = providerRefusal(error) ?? providerTransport(error);
|
|
140
140
|
throw commandFailure(redact(`${state} Failed at ${step}: ${error.message}${refused ? ` (${refused})` : ''}${error.cause ? ` (${error.cause})` : ''}. Fix the cause and run ${again} again using the same environment credentials. ${outcome && recorded ? `To retire the token without rebuilding: ${again} --unset-secret ${setupManifest?.steps?.find(item => item.type === 'owner-claim')?.tokenField ?? 'SETUP_TOKEN'}.` : ''}`));
|
|
141
141
|
}
|
|
142
142
|
}
|
package/cli/deploy-inputs.mjs
CHANGED
|
@@ -39,7 +39,10 @@ export async function withDeployEnvironment(root, options, run) {
|
|
|
39
39
|
const { env } = await deployEnvironment({ root, options, declaration: {} });
|
|
40
40
|
const { createRedaction, credentialValues } = await shared('redaction.mjs');
|
|
41
41
|
const redaction = createRedaction();
|
|
42
|
-
|
|
42
|
+
// Provider names are public enum values. Masking "resend" would also hide
|
|
43
|
+
// RESEND_API_KEY in the preflight's instruction for the missing credential.
|
|
44
|
+
const publicProvider = (key, value) => key === 'MAIL_PROVIDER' && /^(resend|sendgrid|cloudflare|rer|later)$/.test(value);
|
|
45
|
+
redaction.addSecrets([...credentialValues(env), ...Object.entries(env).filter(([key, value]) => saved[key] !== value && !publicProvider(key, value)).map(([, value]) => value)]);
|
|
43
46
|
Object.assign(process.env, env);
|
|
44
47
|
try { return await run(redaction); }
|
|
45
48
|
catch (error) { if (typeof error?.message === 'string') error.message = redaction.redact(error.message); throw error; }
|
package/cli/deploy.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { requireProductionAuth } from './production-auth.mjs';
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
|
-
import { deployDiagnostic } from '../modules/deploy-kit/diagnostics.mjs';
|
|
3
|
+
import { deployDiagnostic, providerTransport } from '../modules/deploy-kit/diagnostics.mjs';
|
|
4
4
|
import { shared } from './shared.mjs';
|
|
5
5
|
import { contained } from './project.mjs';
|
|
6
6
|
import { missing, invalid, refuse, RerError } from './errors.mjs';
|
|
@@ -13,6 +13,7 @@ import { checkHostedSetup, hostedSetupFailure } from './deploy-setup.mjs';
|
|
|
13
13
|
import { mutationReadinessFailure } from './deploy-readiness.mjs';
|
|
14
14
|
import { committedSource } from './deploy-source.mjs';
|
|
15
15
|
import { hookState, forgetHookState } from './deploy-hook-record.mjs';
|
|
16
|
+
import { deploymentRecord } from './deployment-record.mjs';
|
|
16
17
|
|
|
17
18
|
export function ownerDeploy(declarationPath, lifecycle) {
|
|
18
19
|
// rer verify serves the build with this declaration's vars and secrets.
|
|
@@ -29,6 +30,7 @@ export function ownerDeploy(declarationPath, lifecycle) {
|
|
|
29
30
|
const retry = options.remove ? `${again} --remove --yes` : options.setSecret ? `${again} --set-secret ${options.setSecret}` : options.unsetSecret ? `${again} --unset-secret ${options.unsetSecret}` : again;
|
|
30
31
|
if (change.length > 1 || change.length && options.dryRun) throw invalid(`Use ${change.join(', ')}${options.dryRun ? ' and --dry-run' : ''} on separate runs.`);
|
|
31
32
|
if (options.remove && !options.yes) throw invalid(`${again} --remove deletes this environment's Worker and every D1, R2, KV and queue rer created for it, with their data. Add --yes to confirm.`);
|
|
33
|
+
const recordedState = change.length ? await deploymentRecord(root, options) : undefined;
|
|
32
34
|
// A dry run reads the settings file too, so a refused key fails here and not only on the real deploy.
|
|
33
35
|
if (options.dryRun && options.envFile) await deployEnvironment({ root, options, declaration, localOnlyKeys });
|
|
34
36
|
if (!change.length) {
|
|
@@ -62,7 +64,7 @@ export function ownerDeploy(declarationPath, lifecycle) {
|
|
|
62
64
|
let step = 'deploy', deployed;
|
|
63
65
|
try {
|
|
64
66
|
// A custom hook's own state file, when its deploy named one.
|
|
65
|
-
const state = await hookState(root, environment);
|
|
67
|
+
const state = change.length ? recordedState : await hookState(root, environment);
|
|
66
68
|
if (options.remove) {
|
|
67
69
|
step = 'remove';
|
|
68
70
|
const result = await owner('remove', state ? ['--state', state] : []);
|
|
@@ -118,12 +120,14 @@ function failureText({ error, step, created, again, retry, secretChange, deploye
|
|
|
118
120
|
const input = /^missing-secret-([A-Z][A-Z0-9_]*)$/.exec(code)?.[1];
|
|
119
121
|
if (input) return `Deploy needs ${input}, which the deploy declaration lists as a secret and the Worker does not hold it. Set ${input} in the environment or in an --env-file file (an owned 0600 file of KEY=VALUE lines), then run the same command again. Nothing was uploaded.${created.length ? ` Resources created this attempt: ${created.join(', ')}.` : ''}`;
|
|
120
122
|
if (code === 'remove-incomplete') return `Removal stopped with ${error.remaining.join(', ')} still present${error.failed.length ? ` (${error.failed.map(item => `${item.resource}: ${item.code}`).join('; ')})` : ''}. Removed: ${error.removed.join(', ') || 'nothing'}. Confirmed owned R2 buckets are emptied automatically; unproved buckets are never purged. Run ${again} --remove --yes again to finish.`;
|
|
121
|
-
if (code === 'nothing-to-remove') return `
|
|
123
|
+
if (code === 'nothing-to-remove') return `The deployment record selected by ${again} has no resources that rer owns, so --remove deletes nothing.`;
|
|
122
124
|
if (code === 'owner-token-retirement-failed') return `The application is deployed at ${deployed?.origin}; owner ${error.owner}; setup token retirement failed (${redact(String(error.cause))}). Run ${again} --unset-secret ${error.tokenKey ?? 'SETUP_TOKEN'} using the same environment credentials, or run ${again} again to finish.`;
|
|
123
125
|
if (code === 'owner-claim-failed') return `The application is deployed at ${deployed?.origin}, but claiming its owner failed: ${redact(String(error.cause))}. Owner claim and setup token retirement are not confirmed; run ${again} again using the same environment credentials to finish.`;
|
|
124
126
|
const resource = diagnostic?.resource ?? (error.resource ? redact(String(error.resource)) : undefined);
|
|
125
127
|
if (code === 'resource-not-listed') return `Deploy stopped at ${at}: ${resource} was created, but Cloudflare's account listing still does not show it after two minutes. Nothing was uploaded.\nResources created this attempt: ${created.join(', ') || 'none'}.\nRun ${again} again once the listing catches up: it reuses ${resource}. To delete what this environment created instead: ${again} --remove --yes.`;
|
|
126
128
|
const lines = [`Deploy failed at ${at}: ${code}${resource ? ` (${resource})` : ''}${diagnostic?.providerCodes?.length ? ` (provider ${diagnostic.providerCodes.join(', ')})` : ''}.`];
|
|
129
|
+
const transport = providerTransport(error, redact);
|
|
130
|
+
if (transport) lines.push(`${transport}.`);
|
|
127
131
|
if (diagnostic?.output && diagnostic.output !== '(no provider output)') lines.push(`First redacted output lines:\n${diagnostic.output}`);
|
|
128
132
|
lines.push(`Resources created this attempt: ${created.join(', ') || 'none'}.`);
|
|
129
133
|
lines.push(recovery({ code, at, resource, again, retry, secretChange }));
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { access, readFile, readdir } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { hookState } from './deploy-hook-record.mjs';
|
|
4
|
+
import { deployAgain } from './deploy-inputs.mjs';
|
|
5
|
+
import { contained } from './project.mjs';
|
|
6
|
+
import { RerError } from './errors.mjs';
|
|
7
|
+
|
|
8
|
+
const recordPath = environment => join('.rer', 'deploy', `${environment}.json`);
|
|
9
|
+
|
|
10
|
+
// Existing-deployment commands share the same hook pointer and default record.
|
|
11
|
+
// A first deploy still creates its record through the kit as before.
|
|
12
|
+
export async function deploymentRecord(root, options) {
|
|
13
|
+
const environment = options.environment ?? 'production';
|
|
14
|
+
const state = await hookState(root, environment);
|
|
15
|
+
const path = await contained(root, state ?? recordPath(environment), { optional: true });
|
|
16
|
+
try { await access(path); }
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (error.code !== 'ENOENT') throw error;
|
|
19
|
+
const availableDeployments = (await environments(root)).map(environment => ({ environment, command: commandFor(options, environment) }));
|
|
20
|
+
const held = availableDeployments.length
|
|
21
|
+
? `It holds:\n${availableDeployments.map(item => ` ${item.environment}: ${item.command}`).join('\n')}`
|
|
22
|
+
: 'This checkout holds no deployment environments. Run it from the checkout that deployed it.';
|
|
23
|
+
const signin = options.verb === 'signin';
|
|
24
|
+
throw new RerError(signin ? 'safety_refusal' : 'command_failed', `No deployment of the ${environment} environment in this checkout. ${held}`, signin ? 4 : 1, { environment, availableDeployments });
|
|
25
|
+
}
|
|
26
|
+
return state;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function environments(root) {
|
|
30
|
+
let entries;
|
|
31
|
+
try { entries = await readdir(await contained(root, '.rer/deploy', { optional: true })); }
|
|
32
|
+
catch (error) { if (error.code === 'ENOENT') return []; throw error; }
|
|
33
|
+
const names = new Set(entries.flatMap(name => /^([a-z][a-z0-9]*(?:-[a-z0-9]+)*)(?:\.hook)?\.json$/.exec(name)?.slice(1) ?? []).filter(name => name.length <= 32));
|
|
34
|
+
const held = await Promise.all([...names].map(async environment => {
|
|
35
|
+
try {
|
|
36
|
+
const state = await hookState(root, environment);
|
|
37
|
+
const path = await contained(root, state ?? recordPath(environment));
|
|
38
|
+
const record = JSON.parse(await readFile(path, 'utf8'));
|
|
39
|
+
return record?.kind === 'rer-deploy-owner-state' && record.environment === environment ? environment : undefined;
|
|
40
|
+
} catch { return undefined; } // An unrelated or broken file is not a held deployment.
|
|
41
|
+
}));
|
|
42
|
+
return held.filter(Boolean).sort();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function commandFor(options, environment) {
|
|
46
|
+
const again = deployAgain({ ...options, environment });
|
|
47
|
+
if (options.verb === 'signin') return again.replace(/^rer deploy/, 'rer signin');
|
|
48
|
+
if (options.remove) return `${again} --remove --yes`;
|
|
49
|
+
if (options.setSecret) return `${again} --set-secret ${options.setSecret}`;
|
|
50
|
+
if (options.unsetSecret) return `${again} --unset-secret ${options.unsetSecret}`;
|
|
51
|
+
return again;
|
|
52
|
+
}
|
package/cli/export.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { cliVersion } from './version.mjs';
|
|
|
6
6
|
|
|
7
7
|
// Copy whole maintained source/tooling directories. Python publication scans
|
|
8
8
|
// load sibling modules and data dynamically; they belong in the inventory too.
|
|
9
|
-
export const sourceRoots = ['bin/rer.mjs', 'cli', 'modules/delivery-producer/declarations.mjs', 'modules/delivery-producer/bindings.mjs', 'modules/job-queue', 'modules/release', 'modules/deploy-kit', 'modules/container', 'modules/demo-host', 'modules/demo', 'modules/integrations/core', 'modules/mail', 'modules/ai', 'modules/portability', 'modules/d1-transport', 'modules/erasure', 'modules/dependencies', 'modules/operator-auth', 'modules/owner-claim', 'operations', 'scripts/publish-check', 'scripts/publish-check.mjs', 'composition/git-source.mjs', 'edition-authoring/manifest.mjs', 'edition-authoring/files.mjs'];
|
|
9
|
+
export const sourceRoots = ['bin/rer.mjs', 'cli', 'modules/delivery-producer/declarations.mjs', 'modules/delivery-producer/bindings.mjs', 'modules/delivery-producer/migrations.mjs', 'modules/job-queue', 'modules/release', 'modules/deploy-kit', 'modules/container', 'modules/demo-host', 'modules/demo', 'modules/integrations/core', 'modules/mail', 'modules/ai', 'modules/portability', 'modules/d1-transport', 'modules/erasure', 'modules/dependencies', 'modules/operator-auth', 'modules/owner-claim', 'operations', 'scripts/publish-check', 'scripts/publish-check.mjs', 'composition/git-source.mjs', 'edition-authoring/manifest.mjs', 'edition-authoring/files.mjs'];
|
|
10
10
|
export async function inventory(base, roots = sourceRoots) {
|
|
11
11
|
const files = [];
|
|
12
12
|
async function walk(path) {
|
package/cli/local.mjs
CHANGED
|
@@ -98,12 +98,20 @@ export async function reset(project, options, out) {
|
|
|
98
98
|
return { paths: inventory };
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
export async function refuseLegacyProcess(project,{reset=false,verb='dev'}={}) {
|
|
101
|
+
export async function refuseLegacyProcess(project,{reset=false,verb='dev',operation}={}) {
|
|
102
102
|
let selected;try{selected=await selectedOrigin(project,{});}catch(error){if(!reset)throw error;}
|
|
103
103
|
// Confirmed reset can recover malformed settings; checkout/state custody is
|
|
104
104
|
// still checked even when there is no usable saved origin.
|
|
105
|
-
const {localProcessConflict,inspectionContext}=await shared('process-diagnostics.mjs');
|
|
105
|
+
const {localProcessConflict,inspectionContext,uncheckedInspection}=await shared('process-diagnostics.mjs');
|
|
106
106
|
// The front door holds a door origin's port, not this checkout.
|
|
107
|
-
|
|
107
|
+
let conflict;
|
|
108
|
+
try{conflict=await localProcessConflict(project.root,selected?.door?undefined:selected?.savedOrigin,inspectionContext({verb}));}
|
|
109
|
+
catch(error){
|
|
110
|
+
// Startup already holds the exclusive checkout operation through teardown.
|
|
111
|
+
// An unanswered observation must not defeat that cooperating-launch proof.
|
|
112
|
+
// Setup/reset retain their destructive-operation inspection requirement.
|
|
113
|
+
if(operation?.token&&verb==='dev'&&uncheckedInspection(error))return {lockProof:true};
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
108
116
|
if(conflict)throw refuse(`A local process holds ${conflict.reason}: PID ${conflict.pid} (${conflict.command}). Stop it with kill -TERM ${conflict.pid}, then retry. Use rer dev --stop or rer preview --stop for a registered server.`);
|
|
109
117
|
}
|
package/cli/managed-server.mjs
CHANGED
|
@@ -85,9 +85,10 @@ export async function managedServer(project,options,out,{clock={}}={}){
|
|
|
85
85
|
throw Error('Unknown management operation');
|
|
86
86
|
});
|
|
87
87
|
await stateSafety(project);
|
|
88
|
-
await refuseLegacyProcess(project,{verb:options.verb});
|
|
89
88
|
const {localOperation}=await shared('local/operation.mjs');
|
|
90
89
|
try{operation=await localOperation(project.root);}catch(error){throw refuse(error.message);}
|
|
90
|
+
const ownership=await refuseLegacyProcess(project,{verb:options.verb,operation});
|
|
91
|
+
if(ownership?.lockProof)out.progress('Local process inspection did not answer; continuing with the exclusive checkout launch lock.\n');
|
|
91
92
|
const {recoverInterrupted}=await shared('local/recovery.mjs');await recoverInterrupted(project.root,operation);
|
|
92
93
|
const {loadInstallerSeed}=await shared('setup-manifest.mjs');
|
|
93
94
|
const seed=project.adapter.setup?await loadInstallerSeed(project.root,project.adapter):undefined;project.setupManifest=seed?.manifest;
|
|
@@ -98,7 +99,10 @@ export async function managedServer(project,options,out,{clock={}}={}){
|
|
|
98
99
|
if(devIdentity&&!devKey)devKey=await requireDevKey(project.root);
|
|
99
100
|
if(devIdentity&&options.verb==='dev')refuseManagedInstallation(selected.vars,process.env);
|
|
100
101
|
if(options.demo)demo=await demoPreflight(project,selected.vars,options.idleTimeout);
|
|
101
|
-
|
|
102
|
+
const prerequisites=async()=>{
|
|
103
|
+
if(!demo&&project.adapter.localPrerequisites&&!await project.adapter.localPrerequisites({root:project.root,vars:selected.vars,email:selected.vars[keys.email],demo:false}))throw missing('Local migrations, owner or local authentication/mail settings are missing. Run rer setup first.');
|
|
104
|
+
};
|
|
105
|
+
if(options.verb!=='dev')await prerequisites();
|
|
102
106
|
await registry.update({url:selected.url,host:selected.host,port:selected.port,models:options.models??'fake'});
|
|
103
107
|
const {privateDirectory}=await shared('private-files.mjs');
|
|
104
108
|
if(!demo)await privateDirectory(project.root,['.wrangler','state']);
|
|
@@ -114,7 +118,7 @@ export async function managedServer(project,options,out,{clock={}}={}){
|
|
|
114
118
|
proxy=await runtimeFrontDoor({host:selected.host,port:selected.port,activity,door:selected.door,devKey:devKey??undefined,origin:selected.url});const internal=proxy.runtimePort;
|
|
115
119
|
if(selected.door)await announceDoorRoute(selected,proxy,registry);
|
|
116
120
|
const modelsLive = options.verb==='dev' ? await prepareLiveModels(project.root,options,store,controller.signal) : undefined;
|
|
117
|
-
const adapterOptions={modelsLive,demo,selectedOrigin:selected.url,operationToken:operation.token,privateSettings:project.adapter.settings,runtimePort:internal,devKey:devKey??undefined,devLogin:false,scheduled:crons.length>0};
|
|
121
|
+
const adapterOptions={modelsLive,demo,selectedOrigin:selected.url,operationToken:operation.token,privateSettings:project.adapter.settings,runtimePort:internal,devKey:devKey??undefined,devLogin:false,scheduled:crons.length>0,beforeStart:options.verb==='dev'?prerequisites:undefined};
|
|
118
122
|
const input={[keys.email]:selected.vars[keys.email]};
|
|
119
123
|
if(options.verb==='preview')await productionBuild(project,()=>store.run('Building fixed production output',process.execPath,[fileURLToPath(new URL('../bin/rer.mjs',import.meta.url)),'build','--cwd',project.root,'--json'],{cwd:project.root,phase:'build',signal:controller.signal,env:{...process.env,RER_LOCAL_OPERATION:operation.token},afterCommand:()=>recoverInterrupted(project.root,operation)}),text=>store.report(text));
|
|
120
124
|
await serverResources(project.root);
|
package/cli/output.mjs
CHANGED
|
@@ -19,7 +19,7 @@ export function output(options) {
|
|
|
19
19
|
else if (!['describe', 'check', 'dev', 'preview', 'setup'].includes(options.verb) || !ok) this.human(`${options.verb}: ${ok ? 'complete' : 'failed'} (exit ${exitCode})`);
|
|
20
20
|
},
|
|
21
21
|
error(error) {
|
|
22
|
-
if (structuredResult) this.event('error', { code: error.code, message: error.message, exitCode: error.exitCode });
|
|
22
|
+
if (structuredResult) this.event('error', { code: error.code, message: error.message, exitCode: error.exitCode, ...(error.availableDeployments ? { environment: error.environment, availableDeployments: error.availableDeployments } : {}) });
|
|
23
23
|
else write(2, error.message + '\n');
|
|
24
24
|
},
|
|
25
25
|
};
|
package/cli/production-auth.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { refuse } from './errors.mjs';
|
|
2
|
-
import { mailbox } from './parse.mjs';
|
|
3
2
|
import { main as owner } from '../modules/deploy-kit/owner-cli.mjs';
|
|
4
3
|
import { hookState } from './deploy-hook-record.mjs';
|
|
5
4
|
import { savedSetupAnswers } from './setup-answers.mjs';
|
|
6
|
-
import {
|
|
5
|
+
import { productionMail } from './production-mail.mjs';
|
|
7
6
|
|
|
8
7
|
// Validate the shared email/identity contract using the bindings that will reach
|
|
9
8
|
// the runtime. Independently authored authentication remains the adapter's job.
|
|
@@ -11,19 +10,14 @@ export async function requireProductionAuth({ root, declaration, env, setupManif
|
|
|
11
10
|
const dependencies = setupManifest?.dependencies?.filter(item => item.interface === 'oidc-provider@1') ?? [];
|
|
12
11
|
const bindings = { ...declaration.vars };
|
|
13
12
|
for (const secret of declaration.secrets ?? []) if (env[secret.environment]?.trim()) bindings[secret.binding] = env[secret.environment];
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (
|
|
18
|
-
try { validateRerConfig({ relayUrl: bindings.MAIL_RELAY_URL }); } catch { mailSelected = false; }
|
|
19
|
-
}
|
|
20
|
-
const required = ['MAIL_API_KEY', ...(provider === 'cloudflare' ? ['MAIL_ACCOUNT_ID'] : [])];
|
|
21
|
-
if (mailSelected && required.every(key => bindings[key]?.trim())) return;
|
|
22
|
-
if (mailSelected && !options.dryRun && declarationPath) {
|
|
13
|
+
const mail = await productionMail(root, declaration, env);
|
|
14
|
+
if (!setupManifest?.steps?.some(step => step.type === 'owner-claim') && !dependencies.length && !mail.declared) return;
|
|
15
|
+
if (mail.configured()) return;
|
|
16
|
+
if (mail.canInspect && !options.dryRun && declarationPath) {
|
|
23
17
|
try {
|
|
24
18
|
const state = await hookState(root, options.environment ?? 'production');
|
|
25
19
|
const existing = await owner(['inspect', '--declaration', declarationPath, '--environment', options.environment ?? 'production', ...(state ? ['--state', state] : [])], env, { cwd: root, localOnlyKeys: adapter?.localOnlyKeys });
|
|
26
|
-
if (
|
|
20
|
+
if (mail.configured(existing.liveSecrets)) return;
|
|
27
21
|
} catch (error) {
|
|
28
22
|
if (!['missing-owner-receipt', 'missing-input'].includes(error.message)) throw refuse(`Production sign-in could not verify the existing deployment and its mail secrets${/^[a-z][a-z0-9-]{0,80}$/.test(error.message)?` (${error.message})`:''}. Restore provider access and the owned deployment record before retrying.`);
|
|
29
23
|
}
|
|
@@ -34,5 +28,5 @@ export async function requireProductionAuth({ root, declaration, env, setupManif
|
|
|
34
28
|
if (dependencies.some(item => {
|
|
35
29
|
try { const value = answers?.[item.address] ?? bindings[item.address], issuer = new URL(value); return issuer.protocol === 'https:' && issuer.origin === value && !issuer.username && !issuer.password; } catch { return false; }
|
|
36
30
|
})) return;
|
|
37
|
-
throw refuse(
|
|
31
|
+
throw refuse(`Production sign-in is not configured. Configure outbound email; missing or invalid: ${mail.missing}. Or select and approve an Auth SSO install through the declared oidc-provider@1 setup dependency. Local dev and demo use automatic RER_OPEN sign-in. Nothing was built or uploaded.`);
|
|
38
32
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { contained } from './project.mjs';
|
|
3
|
+
import { refuse } from './errors.mjs';
|
|
4
|
+
import { mailbox } from './parse.mjs';
|
|
5
|
+
import { deliveryDeclarationSources } from './delivery-declarations.mjs';
|
|
6
|
+
import { validateRerConfig } from '../modules/mail/src/adapters/rer/contract.mjs';
|
|
7
|
+
|
|
8
|
+
const providers = ['resend', 'sendgrid', 'cloudflare', 'rer'];
|
|
9
|
+
const nativeCredential = { sendgrid: 'SENDGRID_API_KEY', resend: 'RESEND_API_KEY' };
|
|
10
|
+
const present = value => typeof value === 'string' && Boolean(value.trim());
|
|
11
|
+
|
|
12
|
+
// Packaging can declare inputs that a product's deploy adapter adds to the
|
|
13
|
+
// root declaration later. Read that source contract, never arbitrary ambient
|
|
14
|
+
// keys or the adapter's executable source, before any build or provider write.
|
|
15
|
+
export async function productionMail(root, declaration, env) {
|
|
16
|
+
const bindings = { ...declaration.vars }, secrets = new Set(), publicInputs = new Set(), declaredProviders = new Set();
|
|
17
|
+
for (const secret of declaration.secrets ?? []) {
|
|
18
|
+
secrets.add(secret.binding);
|
|
19
|
+
if (present(env[secret.environment])) bindings[secret.binding] = env[secret.environment];
|
|
20
|
+
}
|
|
21
|
+
for (const [path, select] of deliveryDeclarationSources) {
|
|
22
|
+
let text;
|
|
23
|
+
try { text = await readFile(await contained(root, path, { optional: true }), 'utf8'); }
|
|
24
|
+
catch (error) { if (error.code === 'ENOENT') continue; throw error; }
|
|
25
|
+
let spec;
|
|
26
|
+
try { spec = select(JSON.parse(text)); }
|
|
27
|
+
catch { throw refuse(`Restore a valid mail deployment declaration at ${path}. Nothing was built or uploaded.`); }
|
|
28
|
+
if (!spec) continue;
|
|
29
|
+
for (const name of spec.publicVariableNames ?? []) publicInputs.add(name);
|
|
30
|
+
for (const [name, value] of Object.entries(spec.publicVariables ?? {})) {
|
|
31
|
+
if (!(name in bindings) || name === 'MAIL_PROVIDER' && bindings[name] === 'later') bindings[name] = value;
|
|
32
|
+
}
|
|
33
|
+
for (const name of [...(spec.secretNames ?? []), ...(spec.optionalSecretNames ?? [])]) {
|
|
34
|
+
secrets.add(name);
|
|
35
|
+
// A root secret's explicit environment-to-binding mapping wins.
|
|
36
|
+
if (!declaration.secrets?.some(secret => secret.binding === name) && present(env[name])) bindings[name] = env[name];
|
|
37
|
+
}
|
|
38
|
+
for (const provider of spec.mail?.providers ?? []) if (providers.includes(provider)) declaredProviders.add(provider);
|
|
39
|
+
}
|
|
40
|
+
for (const name of publicInputs) if (present(env[name])) bindings[name] = env[name];
|
|
41
|
+
const provider = bindings.MAIL_PROVIDER;
|
|
42
|
+
const deferred = !provider || provider === 'later';
|
|
43
|
+
const choices = new Set(declaredProviders);
|
|
44
|
+
if (deferred) for (const [name, key] of Object.entries(nativeCredential)) if (secrets.has(key)) choices.add(name);
|
|
45
|
+
const selected = deferred ? [...choices] : providers.includes(provider) ? [provider] : [];
|
|
46
|
+
const routes = selected.map(provider => {
|
|
47
|
+
const credentialKeys = deferred && nativeCredential[provider] && !declaredProviders.has(provider) ? [nativeCredential[provider]]
|
|
48
|
+
: ['MAIL_API_KEY', ...(nativeCredential[provider] ? [nativeCredential[provider]] : [])];
|
|
49
|
+
const declaredCredentials = credentialKeys.filter(key => secrets.has(key));
|
|
50
|
+
return live => {
|
|
51
|
+
let relaySelected = true;
|
|
52
|
+
if (provider === 'rer') try { validateRerConfig({ relayUrl: bindings.MAIL_RELAY_URL }); } catch { relaySelected = false; }
|
|
53
|
+
const has = key => present(bindings[key]) || secrets.has(key) && live.includes(key);
|
|
54
|
+
return [
|
|
55
|
+
...(!mailbox(bindings.MAIL_FROM) ? ['MAIL_FROM'] : []),
|
|
56
|
+
...(!credentialKeys.some(has) ? [declaredCredentials.join(' or ') || credentialKeys.join(' or ')] : []),
|
|
57
|
+
...(provider === 'cloudflare' && !has('MAIL_ACCOUNT_ID') ? ['MAIL_ACCOUNT_ID'] : []),
|
|
58
|
+
...(!relaySelected ? ['MAIL_RELAY_URL (assigned HTTPS relay URL)'] : []),
|
|
59
|
+
];
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
declared: 'MAIL_PROVIDER' in bindings || publicInputs.has('MAIL_PROVIDER') || secrets.has('MAIL_API_KEY') || selected.length > 0,
|
|
64
|
+
configured: (live = []) => routes.some(missing => missing(live).length === 0),
|
|
65
|
+
canInspect: mailbox(bindings.MAIL_FROM) && routes.length > 0,
|
|
66
|
+
missing: routes.length ? routes.map(missing => missing([]).join(', ')).join(' or ') : [
|
|
67
|
+
'MAIL_PROVIDER (resend, sendgrid, cloudflare or rer)',
|
|
68
|
+
...(!mailbox(bindings.MAIL_FROM) ? ['MAIL_FROM'] : []),
|
|
69
|
+
'MAIL_API_KEY',
|
|
70
|
+
].join(', '),
|
|
71
|
+
};
|
|
72
|
+
}
|
package/cli/signin.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { declarationFor } from './deploy-command.mjs';
|
|
2
2
|
import { deployEnvironment, deployAgain } from './deploy-inputs.mjs';
|
|
3
|
-
import {
|
|
4
|
-
import { missing, refuse, RerError } from './errors.mjs';
|
|
3
|
+
import { deploymentRecord } from './deployment-record.mjs';
|
|
4
|
+
import { invalid, missing, refuse, RerError } from './errors.mjs';
|
|
5
5
|
import { shared } from './shared.mjs';
|
|
6
6
|
import { main as owner } from '../modules/deploy-kit/owner-cli.mjs';
|
|
7
7
|
import { deployDiagnostic, providerRefusal } from '../modules/deploy-kit/diagnostics.mjs';
|
|
@@ -15,25 +15,30 @@ export async function signinCommand(project, options, out, { fetch } = {}) {
|
|
|
15
15
|
if (project.profile !== 'first-party' || typeof project.adapter?.deploy !== 'function') throw refuse('rer signin needs a seed with an owner-account deploy declaration.');
|
|
16
16
|
const root = project.root, environment = options.environment ?? 'production', again = deployAgain(options).replace(/^rer deploy/, 'rer signin');
|
|
17
17
|
const { path, value: declaration } = await declarationFor(root, project.adapter);
|
|
18
|
+
const state = await deploymentRecord(root, { ...options, verb: 'signin' });
|
|
18
19
|
const { env } = await deployEnvironment({ root, options, declaration, localOnlyKeys: project.adapter.localOnlyKeys ?? [] });
|
|
19
20
|
if (['CLOUDFLARE_ACCOUNT_ID', 'CLOUDFLARE_API_TOKEN'].some(name => !env[name]?.trim())) throw missing('rer signin uses the Cloudflare credentials that deployed this environment: set CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN in the environment or an --env-file, then run it again.');
|
|
20
21
|
const { createRedaction, credentialValues } = await shared('redaction.mjs');
|
|
21
22
|
const redaction = createRedaction();
|
|
22
23
|
redaction.addSecrets([...credentialValues(env), env.CLOUDFLARE_ACCOUNT_ID]);
|
|
23
|
-
const state = await hookState(root, environment);
|
|
24
24
|
let result;
|
|
25
25
|
try { result = await owner(['signin', '--declaration', path, '--environment', environment, ...(state ? ['--state', state] : [])], env, { cwd: root, localOnlyKeys: project.adapter.localOnlyKeys ?? [], ...(fetch ? { fetch } : {}) }); }
|
|
26
|
-
catch (error) { throw failure(error, { environment, again, redact: redaction.redact }); }
|
|
26
|
+
catch (error) { throw failure(error, { environment, again, adapter: project.adapter, redact: redaction.redact }); }
|
|
27
27
|
const minutes = Math.round((result.expiresAt - Date.now()) / 60000);
|
|
28
28
|
if (!options.json) out.human(`One-time sign-in link for the owner ${result.email}. It works once, only for that owner, and expires in ${minutes} minutes. rer does not save it; open it now:\n${result.link}`);
|
|
29
29
|
return { owner: result.email, expiresAt: result.expiresAt, ...(options.json ? { link: result.link } : {}) };
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
function failure(error, { environment, again, redact }) {
|
|
32
|
+
function failure(error, { environment, again, adapter, redact }) {
|
|
33
33
|
const code = deployDiagnostic(error, redact)?.code ?? error.message;
|
|
34
34
|
if (code === 'missing-owner-receipt') return refuse(`This checkout has no completed rer deployment of the ${environment} environment. Run rer signin from the checkout that deployed it (rer deploy --environment ${environment}).`);
|
|
35
35
|
if (code === 'owned-resource-replaced') return refuse(`The ${environment} Worker is no longer the one this checkout deployed, so rer will not sign anyone in to it. Run rer deploy --environment ${environment} first.`);
|
|
36
|
-
if (code === 'owner-signin-unsupported')
|
|
36
|
+
if (code === 'owner-signin-unsupported') {
|
|
37
|
+
const path = adapter.signInPath;
|
|
38
|
+
if (path !== undefined && (typeof path !== 'string' || path.length > 2048 || !path.startsWith('/') || path.startsWith('//') || /[\\\s\u0000-\u001f\u007f-\u009f]/u.test(path))) return invalid('The adapter signInPath must be a same-origin browser path such as /login. Correct the seed declaration, then run rer signin again.');
|
|
39
|
+
const destination = new URL(path ?? '/setup', error.origin).href;
|
|
40
|
+
return refuse(redact(`The ${environment} deployment signs owners in through the seed's own sign-in flow. ${path ? `Open ${destination} to sign in.` : `Open ${destination} for the seed's owner recovery.`} rer signin cannot issue a link for this seed.`));
|
|
41
|
+
}
|
|
37
42
|
if (code === 'owner-signin-ambiguous') return refuse(`More than one D1 database of the ${environment} deployment holds an owner sign-in table, so rer cannot tell which one signs in the owner. Nothing was written.`);
|
|
38
43
|
if (code === 'owner-not-claimed') return refuse(`No owner has claimed the ${environment} deployment yet. Run rer deploy --environment ${environment}: it claims the owner. Nothing was written.`);
|
|
39
44
|
const refusal = providerRefusal(error, redact);
|
package/global/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.23
|
|
4
|
+
|
|
5
|
+
- Managed mail (`rer` provider) works from Cloudflare Workers. Mail transport always fetches with `redirect: 'manual'`, because Workers reject `redirect: 'error'`, which made every relay send end as `transport_uncertain` without a request. A relay 3xx is never followed and is reported as `rejected` (`provider_redirected`).
|
|
6
|
+
- The `rer` relay adapter accepts `Auto-Submitted: auto-generated`, which Base's sign-in and invitation mail sets, and does not transmit it: the platform relay sets it on every message. It maps `List-Unsubscribe` and one-click `List-Unsubscribe-Post` to the relay's `listUnsubscribe` and `listUnsubscribePost` fields. Values the relay would refuse are refused before sending, and every other header is still refused.
|
|
7
|
+
|
|
8
|
+
### Upgrade notes
|
|
9
|
+
|
|
10
|
+
- Mail transport now passes `redirect: 'manual'` to an injected `fetch`. A seed that wrapped fetch for the `rer` relay to get around the Workers redirect error must remove that wrapper when it refreshes `modules/mail` or pins 0.2.23. A wrapper that insists on `redirect: 'error'` (as Spool's `src/auth/mail-fetch.server.mjs` does) would turn every send into `uncertain`. A seed that dropped `Auto-Submitted` for the relay can send it again.
|
|
11
|
+
|
|
3
12
|
## 0.2.21
|
|
4
13
|
|
|
5
14
|
- Demo removal retries transient Cloudflare provider failures while preserving the resource ownership checks.
|
|
@@ -27,9 +27,14 @@ Other Cloudflare modules have no admitted host adapters; raw sockets would also
|
|
|
27
27
|
bypass the host's routed fetch egress. Native `email()` has no configured host
|
|
28
28
|
delivery, `caches.default` has no declared container cache contract, and the host
|
|
29
29
|
disables request CF metadata (`cf: false`). The module import rule admits native
|
|
30
|
-
ES module loading, not arbitrary calls carrying module strings.
|
|
31
|
-
|
|
32
|
-
WebSocket
|
|
30
|
+
ES module loading, not arbitrary calls carrying module strings.
|
|
31
|
+
|
|
32
|
+
The host forwards WebSocket upgrades through the same ingress and app session
|
|
33
|
+
checks as HTTP. An app response with status 101 and a `WebSocketPair` is bridged
|
|
34
|
+
in both directions, preserving text and binary messages, selected protocols,
|
|
35
|
+
cookies and close codes. Refused upgrades retain their HTTP response; other
|
|
36
|
+
upgrade protocols receive 400. Hosted demo routing selects the visitor's own
|
|
37
|
+
container before forwarding the upgrade, including on declared secondary hosts.
|
|
33
38
|
|
|
34
39
|
The workerd source boundary permits Durable Object definitions, including export
|
|
35
40
|
aliases and indirect inheritance. Unbound definitions create no namespace. The
|
|
@@ -49,6 +54,9 @@ PID/heartbeat diagnostics and is never unlinked. The host applies hashed
|
|
|
49
54
|
migrations using a separately committed claim, followed by atomic SQL plus
|
|
50
55
|
completion. Changed or uncertain history stops startup. Cron uses Base's five
|
|
51
56
|
numeric-field grammar and dispatches matching handlers at minute boundaries.
|
|
57
|
+
Image packaging uses the deployment producer's complete migration inventory,
|
|
58
|
+
including packaging policy prefixes and `extraMigrationDirectories`, in declared
|
|
59
|
+
directory order. Conflicting packaging policies stop the build.
|
|
52
60
|
Node queues retain pending/claimed/dead messages across restarts; expired claims
|
|
53
61
|
are delivered again. Consumers must already be idempotent. Dead jobs make health
|
|
54
62
|
unhealthy. `/health` reports the container platform and the image ID supplied by
|
|
@@ -71,6 +79,13 @@ headers from other peers are discarded. `RER_SSH_IDENTITY` and
|
|
|
71
79
|
are logged. Local loopback origins support a disposable SSH Docker host for
|
|
72
80
|
qualification. Owner hosting/account setup remains an owner step.
|
|
73
81
|
|
|
82
|
+
An isolated front can set `RER_INGRESS_ORIGIN` to its primary public origin and
|
|
83
|
+
`RER_INGRESS_ORIGINS` to a JSON array of allowed HTTPS origins. It must overwrite
|
|
84
|
+
`x-rer-ingress-origin` on each forwarded request with its validated public
|
|
85
|
+
origin. The container accepts that header only with a fixed primary origin and
|
|
86
|
+
an exact allowlist match, then strips it before the app. Requests without the
|
|
87
|
+
header, including health probes and owner claims, use the primary origin.
|
|
88
|
+
|
|
74
89
|
A seed can package its own scoped Node runner with a declaration such as:
|
|
75
90
|
|
|
76
91
|
```json
|