@runeditrun/rer 0.2.72 → 0.2.74
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 +13 -0
- package/cli/adapter.mjs +1 -0
- package/cli/contract.mjs +1 -1
- package/cli/deploy-owner-input.mjs +5 -2
- package/cli/export-summary.mjs +5 -3
- package/cli/hosted-export-command.mjs +47 -0
- package/cli/hosted-export.mjs +8 -5
- package/cli/inspect.mjs +6 -0
- package/cli/main.mjs +1 -1
- package/cli/output.mjs +1 -1
- package/cli/parse.mjs +1 -0
- package/cli/portability-worker.mjs +9 -8
- package/cli/release.mjs +9 -0
- package/cli/transfers.mjs +3 -0
- package/global/CHANGELOG.md +18 -0
- package/modules/container/build.mjs +2 -1
- package/modules/operator-auth/README.md +9 -3
- package/modules/operator-auth/dev/index.mjs +1 -1
- package/modules/operator-auth/dev-gate.mjs +18 -6
- package/modules/operator-auth/index.d.mts +3 -0
- package/modules/operator-auth/scheduled/definition.mjs +3 -1
- package/modules/operator-auth/scheduled/expiry.mjs +2 -2
- package/modules/operator-auth/scheduled/fence.mjs +2 -1
- package/modules/operator-auth/scheduled/runner.mjs +13 -5
- package/modules/portability/README.md +34 -8
- package/modules/portability/backfills.mjs +22 -14
- package/modules/portability/bookkeeping.mjs +6 -1
- package/modules/portability/bridge.mjs +9 -6
- package/modules/portability/import.mjs +7 -4
- package/modules/portability/migration-sql.mjs +8 -0
- package/modules/portability/migration-statements.mjs +22 -17
- package/modules/portability/rebuilds.mjs +106 -0
- package/modules/portability/replay-views.mjs +35 -0
- package/modules/portability/storage.mjs +9 -2
- package/modules/release/produce.mjs +5 -3
- package/modules/release/publication-scan.mjs +5 -4
- package/package.json +1 -1
- package/scripts/publish-check/README.md +6 -1
- package/scripts/publish-check/cli.py +49 -5
- package/scripts/publish-check/history_hydration.py +4 -1
- package/scripts/publish-check/slots.py +67 -0
- package/scripts/publish-check/timeout.json +1 -0
- package/scripts/publish-check/timeout.mjs +14 -0
- package/scripts/publish-check.mjs +27 -8
package/cli/README.md
CHANGED
|
@@ -103,6 +103,19 @@ destination refuses rows erased since. Erasure-fence refusals (`erased_row`,
|
|
|
103
103
|
available only when the adapter declares complete resource coverage; an
|
|
104
104
|
unsupported target exits 4.
|
|
105
105
|
|
|
106
|
+
A first-party adapter may also declare `portability.hostedExport` as an argv
|
|
107
|
+
array, for example `['node', 'scripts/export.mjs']`. With that declaration,
|
|
108
|
+
`rer export --target remote --output exports/hosted` runs the seed's script
|
|
109
|
+
from the checkout root with `--remote --environment production --out exports/hosted`.
|
|
110
|
+
`--origin URL` maps to `--origin URL`; the script is responsible for honoring it
|
|
111
|
+
and selecting the hosted install. Without `--output`, rer chooses
|
|
112
|
+
`exports/hosted-<ISO timestamp>` (colons and dots replaced by hyphens).
|
|
113
|
+
The output can be a file or directory in the seed's format; no local archive
|
|
114
|
+
format or restore compatibility is implied. The closing summary names the hosted
|
|
115
|
+
install, output path and exit status, and the process returns the script's exit
|
|
116
|
+
code. See the adapter contract in `export/SEED-COMMAND-CONTRACT.md` for the path
|
|
117
|
+
and execution rules. Plain export and undeclared adapters keep their behavior.
|
|
118
|
+
|
|
106
119
|
Import defaults to `--target local`. An explicit `--origin` is accepted for a
|
|
107
120
|
local import only when it uses HTTP, its host is exactly `localhost`,
|
|
108
121
|
`127.0.0.1` or `[::1]`, and its port matches this checkout's configured local
|
package/cli/adapter.mjs
CHANGED
|
@@ -11,5 +11,6 @@ export function commandAdapter(lifecycle, options) {
|
|
|
11
11
|
if (typeof ownerName === 'string' && ownerName.trim() && ownerName !== 'displayName') result.ownerBootstrap = false;
|
|
12
12
|
result.verbs = Object.fromEntries(Object.entries(verbs).filter(([verb]) => !['export', 'import'].includes(verb) || typeof result.portability?.[verb] === 'function').map(([verb, definition]) => [verb, { flags: [...definition.flags] }]));
|
|
13
13
|
result.verbs.release = { flags: [...releaseFlags] };
|
|
14
|
+
if (result.verbs.export && result.portability?.hostedExport !== undefined) result.verbs.export.effects = 'Export the local copy with --output, or run the declared hosted-export argv with --target remote. Hosted output keeps the seed\'s own format; the summary names its path and exit status.';
|
|
14
15
|
return result;
|
|
15
16
|
}
|
package/cli/contract.mjs
CHANGED
|
@@ -26,5 +26,5 @@ export const demoVerb = Object.freeze({ flags: [...commonFlags, '--port', '--hos
|
|
|
26
26
|
// sign the owner in to, so no seed declares it and check does not ask for it.
|
|
27
27
|
export const signinVerb = Object.freeze({ flags: [...commonFlags, '--environment', '--env-file'], effects: 'A one-time sign-in link for the hosted owner, without mail. Uses the Cloudflare credentials that deployed --environment (default production; from the environment or --env-file) to write a single-use grant for the recorded owner into that deployment\'s auth database, then prints the link once to this terminal; it is never saved. The link works once, only for that owner, expires within 15 minutes, and its use is recorded in the owner\'s audit log. Signed in this way, the owner can correct a wrong email in settings.' });
|
|
28
28
|
export const aliases = Object.fromEntries([...Object.keys(verbs).filter(v => v !== 'install'), 'release', 'deps', 'rer'].map(name => [name, name === 'deps' ? 'install' : name === 'rer' ? null : name]));
|
|
29
|
-
export const releaseFlags = ['--repo', '--project', '--repository', '--output', '--ref', '--public-base', '--dry-run', '--local-verify', '--verify-workflow', '--tag', '--clean-history', '--onto', '--env-file', '--allow-placeholder-mark', '--no-queue'];
|
|
29
|
+
export const releaseFlags = ['--repo', '--project', '--repository', '--output', '--ref', '--public-base', '--dry-run', '--local-verify', '--verify-workflow', '--scan-timeout-seconds', '--tag', '--clean-history', '--onto', '--env-file', '--allow-placeholder-mark', '--no-queue'];
|
|
30
30
|
export const requiredHooks = ['preview', 'dependencies', 'build', 'migrate', 'start', 'health', 'owner', 'signIn', 'verify', 'deploy', 'portability', 'state', 'settings', 'input'];
|
|
@@ -3,6 +3,7 @@ import { invalid, missing } from './errors.mjs';
|
|
|
3
3
|
import { validOwnerName } from './parse.mjs';
|
|
4
4
|
import { savedSetupAnswers, rememberSetupAnswers } from './setup-answers.mjs';
|
|
5
5
|
import { shared } from './shared.mjs';
|
|
6
|
+
import { heldDeployments } from './deployment-record.mjs';
|
|
6
7
|
|
|
7
8
|
// Resolve the installer identity before building or uploading. Names are safe
|
|
8
9
|
// installer answers, not runtime secrets, and use the same custody as setup.
|
|
@@ -21,8 +22,10 @@ export async function deployOwnerInput({ root, adapter, setupSeed, options, sign
|
|
|
21
22
|
}
|
|
22
23
|
const advice = 'Deploy needs your owner name; run rer deploy --owner-name "Your name" (or rer setup --owner-name "Your name"). Nothing was uploaded.';
|
|
23
24
|
if (!displayName?.trim()) {
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
// A recorded bootstrap keeps its owner; resolving inputs needs no provider read.
|
|
26
|
+
const held = (await heldDeployments(root)).find(item => item.environment === (options.environment ?? 'production'));
|
|
27
|
+
if (['claimed', 'kept'].includes(held?.record.ownerClaim?.outcome)) return { input };
|
|
28
|
+
if (options.dryRun || options.nonInteractive || options.json || !process.stdin.isTTY) throw missing(advice);
|
|
26
29
|
const prompt = createInterface({ input: process.stdin, output: process.stderr });
|
|
27
30
|
const closed = new Promise((_, reject) => prompt.once('close', () => reject(missing(advice))));
|
|
28
31
|
try { displayName = await Promise.race([prompt.question('Your name (hosted owner): ', { signal }), closed]); }
|
package/cli/export-summary.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// The one line a finished export ends with: which copy it exported, the
|
|
2
2
|
// archive, its size and what it holds.
|
|
3
|
-
export function exportSummary({ target = 'local', origin, output, bytes, tables } = {}) {
|
|
4
|
-
if (typeof output !== 'string'
|
|
5
|
-
const rows = tables.reduce((sum, table) => sum + (Number.isSafeInteger(table?.count) ? table.count : 0), 0);
|
|
3
|
+
export function exportSummary({ target = 'local', origin, output, bytes, tables, hostedExport, childExitCode, exitCode = childExitCode } = {}) {
|
|
4
|
+
if (typeof output !== 'string') return undefined;
|
|
6
5
|
const copy = target === 'remote' ? `the hosted install${origin ? ` at ${origin}` : ''}` : 'the local copy';
|
|
6
|
+
if (hostedExport && Number.isInteger(exitCode)) return exitCode === 0 ? `Exported ${copy} to ${output} (exit 0)` : `Export of ${copy} to ${output} failed (exit ${exitCode})`;
|
|
7
|
+
if (!Number.isSafeInteger(bytes) || !Array.isArray(tables)) return undefined;
|
|
8
|
+
const rows = tables.reduce((sum, table) => sum + (Number.isSafeInteger(table?.count) ? table.count : 0), 0);
|
|
7
9
|
return `Exported ${copy} to ${output} (${size(bytes)}): ${counted(tables.length, 'table')}, ${counted(rows, 'row')}`;
|
|
8
10
|
}
|
|
9
11
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { lstat } from 'node:fs/promises';
|
|
2
|
+
import { isAbsolute, relative, win32 } from 'node:path';
|
|
3
|
+
import { constants } from 'node:os';
|
|
4
|
+
import { contained } from './project.mjs';
|
|
5
|
+
import { locateExport } from './archive-path.mjs';
|
|
6
|
+
import { RerError, refuse, lifecycleError } from './errors.mjs';
|
|
7
|
+
import { shared } from './shared.mjs';
|
|
8
|
+
|
|
9
|
+
// A checkout executable, or a bare interpreter followed immediately by its
|
|
10
|
+
// checkout script. Interpreter switches and shell command strings are not hooks.
|
|
11
|
+
export async function hostedExportCommand(root, argv) {
|
|
12
|
+
const message = 'portability.hostedExport must be an argv array naming a relative regular checkout script, without absolute paths, traversal or symlinks.';
|
|
13
|
+
if (!Array.isArray(argv) || !argv.length || ![...argv].every(arg => typeof arg === 'string' && arg.trim() && !arg.includes('\0'))) throw refuse(message);
|
|
14
|
+
const [program, ...args] = argv;
|
|
15
|
+
if (isAbsolute(program) || win32.isAbsolute(program) || !/^[\w.+/-]+$/.test(program)) throw refuse(message);
|
|
16
|
+
const direct = program.includes('/'), script = direct ? program : args[0];
|
|
17
|
+
if (typeof script !== 'string' || script.startsWith('-') || win32.isAbsolute(script)) throw refuse(message);
|
|
18
|
+
let path;
|
|
19
|
+
try { path = await contained(root, script); if (!(await lstat(path)).isFile()) throw Error(); }
|
|
20
|
+
catch { throw refuse(message); }
|
|
21
|
+
return direct ? [path, ...args] : [program, ...args];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function runHostedExport(project, options, store, signal) {
|
|
25
|
+
const [program, ...args] = await hostedExportCommand(project.root, project.adapter.portability.hostedExport);
|
|
26
|
+
const file = options.output ?? `exports/hosted-${new Date().toISOString().replaceAll(/[:.]/g, '-')}`;
|
|
27
|
+
const located = await locateExport(project.root, file);
|
|
28
|
+
await located.unserved();
|
|
29
|
+
// The hook owns the archive format: its output may be a file or a directory.
|
|
30
|
+
const output = isAbsolute(file) ? located.path : relative(project.root, located.path);
|
|
31
|
+
const details = { hostedExport: true, target: 'remote', output, ...(options.origin ? { origin: new URL(options.origin).origin } : {}) };
|
|
32
|
+
const argv = [...args, '--remote', '--environment', 'production', '--out', output, ...(details.origin ? ['--origin', details.origin] : [])];
|
|
33
|
+
try {
|
|
34
|
+
// Like deploy hooks, the seed's own code receives the caller environment.
|
|
35
|
+
// No settings, credentials or hosted data are read by this dispatcher.
|
|
36
|
+
await store.run('Exporting hosted installation data', program, argv, { cwd: project.root, signal, env: { ...process.env } });
|
|
37
|
+
} catch (error) {
|
|
38
|
+
const { isBusyFailure } = await shared('failures.mjs');
|
|
39
|
+
if (isBusyFailure(error)) throw error;
|
|
40
|
+
const diagnostic = await lifecycleError(error, store);
|
|
41
|
+
const code = error.signal ? 128 + (constants.signals[error.signal] ?? 0) : Number.isInteger(error.childExitCode) && error.childExitCode > 0 ? error.childExitCode : 1;
|
|
42
|
+
throw new RerError('hosted_export_failed', diagnostic.message, code, { childExitCode: error.childExitCode, signal: error.signal, exportDetails: details });
|
|
43
|
+
}
|
|
44
|
+
const status = await lstat(located.path).catch(error => { if (error.code === 'ENOENT') return null; throw error; });
|
|
45
|
+
if (!status || !status.isFile() && !status.isDirectory()) throw new RerError('hosted_export_missing_output', `The hosted export command exited 0 but did not leave a regular file or directory at ${output}.`, 1, { childExitCode: 0, exportDetails: details });
|
|
46
|
+
return { ...details, childExitCode: 0 };
|
|
47
|
+
}
|
package/cli/hosted-export.mjs
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { heldDeployments } from './deployment-record.mjs';
|
|
2
2
|
import { invalid } from './errors.mjs';
|
|
3
|
+
import { hostedExportCommand } from './hosted-export-command.mjs';
|
|
3
4
|
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// never runs against a live hosted one. Refuse before any effect rather than
|
|
8
|
-
// save the local copy under the hosted install's name.
|
|
5
|
+
// Without an explicit hosted implementation, refuse before any effect rather
|
|
6
|
+
// than save the local copy under the hosted install's name. Local portability
|
|
7
|
+
// writes snapshot tables into the database it reads; it cannot read a live one.
|
|
9
8
|
export async function refuseHostedExport(project, options) {
|
|
10
9
|
if (options.origin === undefined && options.target !== 'remote') return;
|
|
10
|
+
if (options.target === 'remote' && project.adapter?.portability?.hostedExport !== undefined) {
|
|
11
|
+
await hostedExportCommand(project.root, project.adapter.portability.hostedExport);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
11
14
|
if (project.adapter?.portability?.remote === true) return;
|
|
12
15
|
const origin = options.origin === undefined ? undefined : new URL(options.origin).origin;
|
|
13
16
|
const held = await heldDeployments(project.root);
|
package/cli/inspect.mjs
CHANGED
|
@@ -23,6 +23,7 @@ import { probePnpm } from './pnpm-probe.mjs';
|
|
|
23
23
|
import { deliveryDeclarationClauses } from './delivery-declarations.mjs';
|
|
24
24
|
import { checkoutPlaceholderMarks } from './placeholder-mark.mjs';
|
|
25
25
|
import { contractStatusClauses } from './contract-status.mjs';
|
|
26
|
+
import { hostedExportCommand } from './hosted-export-command.mjs';
|
|
26
27
|
|
|
27
28
|
// cliVersion: the rer version of the code answering (absent for a vendored copy
|
|
28
29
|
// too old to record one). defaults: what a server start applies when the person
|
|
@@ -128,6 +129,11 @@ export async function check(project, explicitProfile) {
|
|
|
128
129
|
} catch { add('SC-01.inventory', false, 'Restore the deterministic portable CLI source inventory.'); }
|
|
129
130
|
}
|
|
130
131
|
add('SC-08.portability', typeof adapter?.portability?.export === 'function' && typeof adapter?.portability?.import === 'function', 'Adopt the reviewed mainline complete local portability API; archive support remains unavailable until then.');
|
|
132
|
+
if (adapter?.portability?.hostedExport !== undefined) {
|
|
133
|
+
let valid = true;
|
|
134
|
+
try { await hostedExportCommand(project.root, adapter.portability.hostedExport); } catch { valid = false; }
|
|
135
|
+
add('SC-08.hosted-export', valid, 'Declare portability.hostedExport as an argv array naming a relative regular checkout script, without absolute paths, traversal or symlinks.');
|
|
136
|
+
}
|
|
131
137
|
if (adapter?.devIdentity) for (const [id, ok, message] of await devIdentityClauses(project.root, adapter)) add(id, ok, message);
|
|
132
138
|
for (const [id, ok, message] of await authCopyClauses(project.root)) add(id, ok, message);
|
|
133
139
|
clauses.push(...await contractStatusClauses(project.root));
|
package/cli/main.mjs
CHANGED
|
@@ -77,7 +77,7 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
77
77
|
out.result(true, 0, result); return 0;
|
|
78
78
|
} catch (error) {
|
|
79
79
|
const failure = error instanceof RerError ? error : unexpectedFailure(error);
|
|
80
|
-
out.error(failure); out.result(false, failure.exitCode, failure.childExitCode === undefined ? {} : { childExitCode: failure.childExitCode, signal: failure.signal }); return failure.exitCode;
|
|
80
|
+
out.error(failure); out.result(false, failure.exitCode, { ...failure.exportDetails, ...(failure.childExitCode === undefined ? {} : { childExitCode: failure.childExitCode, signal: failure.signal }) }); return failure.exitCode;
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
|
package/cli/output.mjs
CHANGED
|
@@ -19,7 +19,7 @@ export function output(options) {
|
|
|
19
19
|
if (finished) throw Error('Duplicate CLI result'); finished = true;
|
|
20
20
|
if (structuredResult) this.event('result', { ok, exitCode, ...details });
|
|
21
21
|
// A finished export ends with one line naming its archive; the receipt is --json data.
|
|
22
|
-
else if (
|
|
22
|
+
else if (options.verb === 'export' && (ok || details.hostedExport) && exportSummary({ ...details, exitCode })) this.human(exportSummary({ ...details, exitCode }));
|
|
23
23
|
else if (ok && options.verb === 'import' && importSafetySummary(details)) this.human('import: complete (exit 0)\n' + importSafetySummary(details));
|
|
24
24
|
else if (!['describe', 'check', 'dev', 'preview', 'setup'].includes(options.verb) || !ok) this.human(`${options.verb}: ${ok ? 'complete' : 'failed'} (exit ${exitCode})`);
|
|
25
25
|
},
|
package/cli/parse.mjs
CHANGED
|
@@ -17,6 +17,7 @@ export const origin = (host, port) => `http://${host === '::1' ? '[::1]' : host}
|
|
|
17
17
|
export function parse(argv, cwd = process.cwd(), { independent = false, deferTail = false } = {}) {
|
|
18
18
|
const [verb, ...args] = argv;
|
|
19
19
|
if (!verb || verb === '--help') return { help: true };
|
|
20
|
+
// Release validates its own flags, including its integer publication scan timeout.
|
|
20
21
|
if (verb === 'release') return { verb, releaseArgs: args };
|
|
21
22
|
if (verb === 'archive') return { verb, archiveArgs: args };
|
|
22
23
|
// rer demo is rer dev --demo.
|
|
@@ -4,7 +4,7 @@ import { readLegacyArchive } from '../modules/portability/format.mjs';
|
|
|
4
4
|
import { recoverLegacyArchive } from '../modules/portability/legacy-files.mjs';
|
|
5
5
|
import { legacyTargetState, requireLegacyEmpty } from '../modules/portability/legacy-safety.mjs';
|
|
6
6
|
import { migrationReplay } from '../modules/portability/migration-history.mjs';
|
|
7
|
-
import {
|
|
7
|
+
import { migrationStatements } from '../modules/portability/migration-sql.mjs';
|
|
8
8
|
import { appliedMigrations as appliedMigrationNames } from '../modules/portability/bridge.mjs';
|
|
9
9
|
import { join } from 'node:path';
|
|
10
10
|
import { createHash } from 'node:crypto';
|
|
@@ -17,16 +17,15 @@ import { parseJsonc } from './jsonc.mjs';
|
|
|
17
17
|
import { loadPolicy } from './portability-policy.mjs';
|
|
18
18
|
|
|
19
19
|
// The migrations this installation applied, in its ledger's order, with each
|
|
20
|
-
// file's hash, so a restore can place an older archive within them.
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
async function appliedMigrations(root, db, binding) {
|
|
20
|
+
// file's hash, so a restore can place an older archive within them. Reproduce
|
|
21
|
+
// the runner's stored SQL text, then recover SQLite's statement boundaries.
|
|
22
|
+
async function appliedMigrations(root, db, binding, split) {
|
|
24
23
|
const config = parseJsonc(await readFile(join(root, 'wrangler.jsonc'), 'utf8'));
|
|
25
24
|
const directory = join(root, config.d1_databases.find(entry => entry.binding === binding).migrations_dir ?? 'migrations');
|
|
26
25
|
const names = await appliedMigrationNames(db) ?? [];
|
|
27
26
|
return Promise.all(names.map(async name => {
|
|
28
27
|
const bytes = await readFile(join(directory, name));
|
|
29
|
-
return { name, statements:
|
|
28
|
+
return { name, statements: migrationStatements(bytes.toString('utf8'), split), sha256: createHash('sha256').update(bytes).digest('hex') };
|
|
30
29
|
}));
|
|
31
30
|
}
|
|
32
31
|
|
|
@@ -60,7 +59,7 @@ async function run(direction, { root, path, journal, binding, buckets, policy, p
|
|
|
60
59
|
let proxy;
|
|
61
60
|
try {
|
|
62
61
|
proxy = await getPlatformProxy({ configPath, persist: { path: join(root, '.wrangler/state/v3') }, remoteBindings: false });
|
|
63
|
-
const migrations=async()=>migrationReplay(await appliedMigrations(root,proxy.env[binding],binding),policy);
|
|
62
|
+
const migrations=async()=>migrationReplay(await appliedMigrations(root,proxy.env[binding],binding,unstable_splitSqlQuery),policy);
|
|
64
63
|
const options={ db: proxy.env[binding], buckets: Object.fromEntries(Object.entries(buckets).map(([name, binding]) => [name, proxy.env[binding]])), policy, migrations };
|
|
65
64
|
if(direction==='legacy-preflight') {
|
|
66
65
|
await requireLegacyEmpty(options,await legacyTargetState(options.db,options.migrations));
|
|
@@ -69,7 +68,9 @@ async function run(direction, { root, path, journal, binding, buckets, policy, p
|
|
|
69
68
|
await ensurePortabilitySchema(proxy.env[binding], await portabilityPlan(unstable_splitSqlQuery));
|
|
70
69
|
if(legacyRecovery)return await recoverLegacyArchive(options,path,legacyRecovery.output,transient,legacyRecovery.acknowledged);
|
|
71
70
|
const service = await createPortability(options);
|
|
72
|
-
// This checkout's operation lock means no other import can be running
|
|
71
|
+
// This checkout's operation lock means no other import can be running. Abort
|
|
72
|
+
// the recorded abandoned job, dropping only its exact staging copies and
|
|
73
|
+
// sidecars before the replacement import creates its own scratch tables.
|
|
73
74
|
if (direction === 'import' && await service.imports.abortAbandoned()) process.send({ progress: 'Cleaned up an unfinished earlier import: a restore that stopped part-way left its staged data here. Its staging is removed and this import starts from the beginning.' });
|
|
74
75
|
return await (direction === 'export' ? exportArchive(service,path,transient,progress) : importArchive(service,path,transient,journal,progress));
|
|
75
76
|
} finally { await proxy?.dispose(); await rm(configPath, { force: true }); }
|
package/cli/release.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { parseTimeoutSeconds, timeoutBounds } from '../scripts/publish-check/timeout.mjs';
|
|
2
|
+
|
|
1
3
|
// Preserve release's accepted parser, producer, receipt and validation exits.
|
|
2
4
|
const releaseHelp = `Usage: rer release --repo DIR --project PUBLISHER/NAME --repository GITHUB_URL --output NEW_DIR [FLAGS]
|
|
3
5
|
|
|
@@ -22,6 +24,9 @@ Without --tag, write a preview. This command never pushes, uploads or deploys.
|
|
|
22
24
|
--verify-workflow NAME_OR_FILE
|
|
23
25
|
Override the seed's declared GitHub verification workflow
|
|
24
26
|
by name or file (case-insensitive).
|
|
27
|
+
--scan-timeout-seconds N
|
|
28
|
+
Publication scan deadline in integer seconds (1..${timeoutBounds.max}).
|
|
29
|
+
Omit to use the scanner default.
|
|
25
30
|
--clean-history Prepare a parentless public export.
|
|
26
31
|
--onto GITHUB_URL#BRANCH
|
|
27
32
|
Prepare a public child of the destination's current branch;
|
|
@@ -52,6 +57,10 @@ export async function dispatchRelease(args) {
|
|
|
52
57
|
for (let index = 0; index < args.length; index++) {
|
|
53
58
|
if(args[index]==='--no-queue'){}
|
|
54
59
|
else if (args[index] === '--tag') options.tag = args[index + 1]?.startsWith('v') ? args[++index] : true;
|
|
60
|
+
else if (args[index] === '--scan-timeout-seconds') {
|
|
61
|
+
try { options.scanTimeoutSeconds = parseTimeoutSeconds(args[++index], { integer: true }); }
|
|
62
|
+
catch (error) { throw Error(`--scan-timeout-seconds: ${error.message}`); }
|
|
63
|
+
}
|
|
55
64
|
else if (args[index] === '--clean-history') options.cleanHistory = true;
|
|
56
65
|
else if (args[index] === '--dry-run') options.dryRun = true;
|
|
57
66
|
else if (args[index] === '--allow-placeholder-mark') options.allowPlaceholderMark = true;
|
package/cli/transfers.mjs
CHANGED
|
@@ -5,6 +5,9 @@ import { contained } from './project.mjs';
|
|
|
5
5
|
import { missing, refuse } from './errors.mjs';
|
|
6
6
|
import { locateExport, locateImport } from './archive-path.mjs';
|
|
7
7
|
export async function transfer(project, options, signal, custody) {
|
|
8
|
+
if (options.verb === 'export' && options.target === 'remote' && project.adapter.portability?.hostedExport !== undefined) {
|
|
9
|
+
return (await import('./hosted-export-command.mjs')).runHostedExport(project, options, custody.store, signal);
|
|
10
|
+
}
|
|
8
11
|
const direction = options.verb, file = direction === 'export' ? options.output : options.input;
|
|
9
12
|
if (!file) throw missing(`Provide --${direction === 'export' ? 'output' : 'input'} FILE.`);
|
|
10
13
|
if (direction === 'import' && !options.yes) throw refuse('Import requires explicit --yes confirmation.');
|
package/global/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.74
|
|
4
|
+
|
|
5
|
+
- **Restores replay more later migrations (#359).** Archive admission and replay accept row-less targets and row-less tables (restored in the destination's definition), RAISE-only guard triggers, statements that read views, and row-preserving CHECK rebuilds, so retained archives from before those migrations restore exactly (Vector: 121 tables / 23 rows; Penny with its settings and clock replayed).
|
|
6
|
+
- **Publication scans share machine-wide slots (#363).** `publish-check` takes 1 of `RER_SCAN_SLOTS` (default 3) slots per machine and waits for one outside its own deadline, so concurrent scans no longer fail on the 300 s timeout under load; `rer release --scan-timeout-seconds <n>` (1-7200) forwards a longer scan deadline. Defaults are unchanged.
|
|
7
|
+
- **Replay schema identity splits migrations like the runner (#370).** Restore placement splits each applied migration the way the installation runner does, so a `--` comment inside a CREATE TABLE no longer makes a same-version restore refuse with `schema_mismatch`.
|
|
8
|
+
- **Publication scan hydration no longer races its own cleanup (#366).** The history refetch runs with `--no-auto-maintenance`, so a detached git GC cannot write into a partial clone's temporary directory while it is removed.
|
|
9
|
+
- **Scheduled policy door hardening (#369).** The run cap counts only a run's own action audit rows (refusals and expiries no longer use it up), a forged `policy_expired` result is recorded as a failure (only the audited sweeper expires runs), a snapshot whose id does not match its policy is refused, expired runs show as 'Expired run', and crash expiry covers every stale running run atomically with its audit row.
|
|
10
|
+
|
|
11
|
+
## 0.2.73
|
|
12
|
+
|
|
13
|
+
- **Local dev sessions survive OAuth callbacks (#361).** The dev-gate cookie `rer_dev_gate_<port>` is now SameSite=Lax, like the session cookie it guards, so a provider's top-level redirect back to a local connector callback (Xero, Slack) carries the dev session instead of answering 401. The new `gate.admitsSession` is the dev-session check; `gate.admits` (dev sign-in, personas, one-click /signin) still refuses a cookie-only request marked `Sec-Fetch-Site: cross-site`. Only the dev gate (`rer dev`/`rer demo`) changes; production session cookies keep their SameSite.
|
|
14
|
+
- **Import door test fixtures are synthetic or derived at runtime (#360).** Platform's source credential scan over every seed-vendored Base file finds 0 credential-shaped literals (was 2, in door.test.ts), so seeds that vendor Base pass the catalogue pin scan.
|
|
15
|
+
- **Import-kit assertion guards are bookkeeping (#355).** `ik_d1_assertions` is excluded on export and skipped on restore, a nonempty guard table is refused, and a `staged_table` refusal names its table.
|
|
16
|
+
- **Archive imports drop their staging tables (#354).** `rer import` removes its own `rer_portability_stage_*` tables when an import completes and when it is refused.
|
|
17
|
+
- **`rer export --target remote` runs a seed's declared hosted export (#358).** An adapter's `portability.hostedExport` argv runs from the checkout with `--remote --environment production --out <file> [--origin <url>]`, and its outcome is preserved; invalid argv or script paths fail `rer check` and are refused before running. Undeclared seeds are unchanged.
|
|
18
|
+
- **Publication scan usage errors report `scan.usage` (#357).** Invalid flags, missing values, invalid timeouts and malformed `--public-base` arguments exit 2 (INCOMPLETE) with one value-free `scan.usage` finding listing the valid flags, and one stderr line pointing to `--help`.
|
|
19
|
+
- **`rer deploy --dry-run` applies the real owner-name check (#356).** A dry run accepts and refuses the same owner input as a real deploy, and a saved owner claim satisfies both.
|
|
20
|
+
|
|
3
21
|
## 0.2.72
|
|
4
22
|
|
|
5
23
|
- **The import door creates jobs for multi-MB sources (#346).** Job creation is chunked within D1's statement and RPC limits, with server-side checkpoints, so a resumed creation continues where it stopped and a partly staged job is never applied; the plan codec is honoured and the original is retained once. A 6.9 MB people export (6,083 people) and a 3,000-person dependency graph plan, create, apply and undo through the default seed's door, where the same export previously failed its first apply with import_door_conflict. ADOPTING.md step 4 names owner opt-in as the recommended consent path.
|
|
@@ -4,6 +4,7 @@ import { createRequire } from 'node:module';
|
|
|
4
4
|
import { pathToFileURL } from 'node:url';
|
|
5
5
|
import { parseJsonc } from '../../cli/jsonc.mjs';
|
|
6
6
|
import { portabilityPlan } from './portability-schema.mjs';
|
|
7
|
+
import { migrationStatements } from '../portability/migration-sql.mjs';
|
|
7
8
|
import { checkBoundary } from './boundary.mjs';
|
|
8
9
|
import { localDurableObjects } from './durable-objects.mjs';
|
|
9
10
|
import { readMigrationRewrites, withRewrites } from '../deploy-kit/migrations.mjs';
|
|
@@ -75,7 +76,7 @@ async function buildImage(root, { output = join(root,'.rer/container/image'), en
|
|
|
75
76
|
const rewrites = await readMigrationRewrites(root);
|
|
76
77
|
const inventory = withRewrites(await containerMigrationInventory(root,{config:workerConfig,configFile}),rewrites);
|
|
77
78
|
const migrations = Object.fromEntries((workerConfig.d1_databases ?? []).map(db => [db.binding,[]]));
|
|
78
|
-
for (const {binding,...migration} of inventory) migrations[binding].push({...migration,statements:
|
|
79
|
+
for (const {binding,...migration} of inventory) migrations[binding].push({...migration,statements:migrationStatements(migration.sql,split)});
|
|
79
80
|
const entry = engine === 'workerd' ? 'dist/server/'+workerConfig.main : 'dist/server/index.mjs';
|
|
80
81
|
await readFile(join(root,entry));
|
|
81
82
|
if (engine === 'node' && workerConfig.kv_namespaces?.length) throw new Error('Node container does not support KV');
|
|
@@ -502,11 +502,17 @@ local reverse proxy makes remote requests look local (forwarded requests carry
|
|
|
502
502
|
a loopback URL and Host, and `CF-Connecting-IP` is whatever the caller sent), so
|
|
503
503
|
the gate is the key, not the network. `devGate({key, origin, local})` returns
|
|
504
504
|
null unless the key is present and the origin is an explicit loopback origin in
|
|
505
|
-
local mode. `
|
|
505
|
+
local mode. `admitsSession(request)` accepts the `rer_dev_gate_<port>` cookie (an HMAC of the
|
|
506
506
|
key, so a reset key refuses old cookies) or the key in `x-rer-dev-key` (the rer
|
|
507
|
-
CLI and test harnesses)
|
|
507
|
+
CLI and test harnesses); the dev layer registers it as the dev session check.
|
|
508
|
+
`admits(request)`, which guards dev sign-in, personas and the one-click sign-in
|
|
509
|
+
page, accepts the same but refuses a cookie-only request marked
|
|
510
|
+
`Sec-Fetch-Site: cross-site`. `exchange(request, branding)` serves `GET /__dev/key` and trades
|
|
508
511
|
the key from the URL fragment, through a same-origin POST, for a host-only
|
|
509
|
-
`HttpOnly; SameSite=
|
|
512
|
+
`HttpOnly; SameSite=Lax; Path=/` cookie. Lax matches the session cookie: a
|
|
513
|
+
browser sends it on the top-level GET an OAuth provider redirects back to the
|
|
514
|
+
app, so a local dev session survives a connector's callback as a deployed
|
|
515
|
+
session does, while cross-site POSTs and subresource requests carry neither. Given the seed's `branding`
|
|
510
516
|
(`productName`, optional `mark` and `theme`), the page between `rer dev` and the
|
|
511
517
|
app shows the explicit mark, or the `--rer-logo` its theme declares, as an
|
|
512
518
|
`<img>` with the product name as its alt text. With neither mark declaration,
|
|
@@ -47,7 +47,7 @@ export function withDevIdentity(worker, { bindings = env => env, config: authCon
|
|
|
47
47
|
return new URL(request.url).pathname === '/auth/dev/enter' || new URL(request.url).pathname === '/__dev/personas' || new URL(request.url).pathname === '/auth/local/cli-session' ? rejectedResponse(request, devNotFound()) : worker.fetch(request, original, execution);
|
|
48
48
|
}
|
|
49
49
|
const gate = devGate({ key: env.RER_DEV_KEY, origin: env.AUTH_ORIGIN, local: env.AUTH_LOCAL === 'true' });
|
|
50
|
-
registerDevAdmission(gate && env.RER_DEV_IDENTITY !== 'off' ? r => gate.
|
|
50
|
+
registerDevAdmission(gate && env.RER_DEV_IDENTITY !== 'off' ? r => gate.admitsSession(r) : null);
|
|
51
51
|
const path = new URL(request.url).pathname;
|
|
52
52
|
if (path === '/__dev/key') return gate ? gate.exchange(request, authConfig(env).branding) : devNotFound();
|
|
53
53
|
if (path === '/signin' && gate && env.RER_DEV_IDENTITY !== 'off' && ['GET', 'HEAD'].includes(request.method)) {
|
|
@@ -11,7 +11,10 @@ import { configureBranding } from './branding.mjs';
|
|
|
11
11
|
// gate: holding the key is. Browsers trade it once for a host-only cookie; test
|
|
12
12
|
// harnesses and the rer command line present it in a header. The cookie is
|
|
13
13
|
// named for the origin's port (`rer_dev_gate_8787`), so checkouts side by side
|
|
14
|
-
// on one loopback host keep their own.
|
|
14
|
+
// on one loopback host keep their own. It is SameSite=Lax like the session
|
|
15
|
+
// cookie it guards, so a dev session survives the top-level redirect back from
|
|
16
|
+
// an OAuth provider (`admitsSession`); the gated sign-in surfaces still refuse
|
|
17
|
+
// a cross-site request that carries only the cookie (`admits`), as Strict did.
|
|
15
18
|
export const DEV_KEY_HEADER = 'x-rer-dev-key';
|
|
16
19
|
export const DEV_KEY_PATH = '/__dev/key';
|
|
17
20
|
const encoder = new TextEncoder();
|
|
@@ -71,15 +74,24 @@ export function devGate({ key, origin, local }) {
|
|
|
71
74
|
let expected;
|
|
72
75
|
const cookieName = localCookieName('rer_dev_gate', origin);
|
|
73
76
|
const cookie = () => expected ??= cookieValue(key);
|
|
74
|
-
const
|
|
77
|
+
const admitted = async request => {
|
|
78
|
+
const presented = request.headers.get(DEV_KEY_HEADER);
|
|
79
|
+
if (presented !== null) return constantEqual(presented, key);
|
|
80
|
+
const value = readGateCookie(request, cookieName);
|
|
81
|
+
return value !== null && constantEqual(value, await cookie());
|
|
82
|
+
};
|
|
83
|
+
const setCookie = async () => `${cookieName}=${await cookie()}; Path=/; HttpOnly; SameSite=Lax; Max-Age=2592000${url.protocol === 'https:' ? '; Secure' : ''}`;
|
|
75
84
|
return Object.freeze({
|
|
76
85
|
cookieName,
|
|
86
|
+
// The gated surfaces (dev sign-in, personas, one-click sign-in): the key
|
|
87
|
+
// header, or the cookie on a request that did not come from another site.
|
|
77
88
|
async admits(request) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const value = readGateCookie(request, cookieName);
|
|
81
|
-
return value !== null && constantEqual(value, await cookie());
|
|
89
|
+
if (request.headers.get(DEV_KEY_HEADER) === null && request.headers.get('sec-fetch-site') === 'cross-site') return false;
|
|
90
|
+
return admitted(request);
|
|
82
91
|
},
|
|
92
|
+
// A dev session counts wherever the browser sends the Lax cookie, which
|
|
93
|
+
// includes a top-level GET arriving from another site (an OAuth callback).
|
|
94
|
+
admitsSession: admitted,
|
|
83
95
|
setCookie,
|
|
84
96
|
// GET serves the exchange page with the seed's productName, mark and theme; POST trades the key for the cookie.
|
|
85
97
|
async exchange(request, branding) {
|
|
@@ -229,7 +229,10 @@ export interface DevGateInput { key: string | undefined; origin: string; local:
|
|
|
229
229
|
export interface DevGate {
|
|
230
230
|
/** `rer_dev_gate_<port>`: one gate cookie per local origin. */
|
|
231
231
|
readonly cookieName: string;
|
|
232
|
+
/** Gated surfaces: the key header, or the cookie on a request not marked `Sec-Fetch-Site: cross-site`. */
|
|
232
233
|
admits(request: Request): Promise<boolean>;
|
|
234
|
+
/** Dev session admission: the key header or the cookie, including a top-level GET from another site. */
|
|
235
|
+
admitsSession(request: Request): Promise<boolean>;
|
|
233
236
|
setCookie(): Promise<string>;
|
|
234
237
|
/** Handles GET/POST /__dev/key; null for every other path. */
|
|
235
238
|
exchange(request: Request, branding?: AuthBranding): Promise<Response | null>;
|
|
@@ -34,5 +34,7 @@ export async function readPolicy(definitions, id) {
|
|
|
34
34
|
if (!Array.isArray(policies) || new Set(policies.map(policy => policy.id)).size !== policies.length) invalid();
|
|
35
35
|
const input = policies.find(policy => policy.id === id);
|
|
36
36
|
if (!input) throw new AuthError('policy_not_found', 404);
|
|
37
|
-
|
|
37
|
+
const policy = await policyVersion(input);
|
|
38
|
+
if (policy.definition.id !== id) invalid();
|
|
39
|
+
return policy;
|
|
38
40
|
}
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
export const scheduledHandlerLimitMs = 15 * 60000;
|
|
4
4
|
|
|
5
5
|
export async function expireRuns(store, policyId, now) {
|
|
6
|
-
const stale = "policy_id=? AND
|
|
6
|
+
const stale = "policy_id=? AND status='running' AND started_at<?";
|
|
7
7
|
const args = [policyId, now - scheduledHandlerLimitMs];
|
|
8
8
|
// One transaction records each abandoned run exactly once before closing it.
|
|
9
9
|
await store.batch([
|
|
10
10
|
[`INSERT INTO oa_auth_audit(id,actor_id,action,value,created_at)
|
|
11
|
-
SELECT lower(hex(randomblob(16))),'policy:'||policy_id||'@'||version_hash,'policy:expired',
|
|
11
|
+
SELECT lower(hex(randomblob(16))),'policy:'||policy_id||CASE WHEN version_hash IS NULL THEN '' ELSE '@'||version_hash END,'policy:expired',
|
|
12
12
|
json_object('policyId',policy_id,'versionHash',version_hash,'approvalId',approval_id,
|
|
13
13
|
'approvedBy',approved_by,'runId',id,'error','policy_expired'),?
|
|
14
14
|
FROM oa_policy_runs WHERE ${stale}`, [now, ...args]],
|
|
@@ -22,7 +22,8 @@ export function actionFence(approval, runId, action, target, now, maxActions) {
|
|
|
22
22
|
return { sql: '(' + sql + ')', args };
|
|
23
23
|
});
|
|
24
24
|
return { sql: `${approvalGuard.sql} AND EXISTS(SELECT 1 FROM oa_policy_runs WHERE id=? AND approval_id=? AND status='running' AND admitted=1 AND started_at>=?)
|
|
25
|
-
AND (SELECT COUNT(*) FROM oa_auth_audit WHERE
|
|
25
|
+
AND (SELECT COUNT(*) FROM oa_auth_audit WHERE action NOT IN ('policy:refused','policy:expired')
|
|
26
|
+
AND CASE WHEN json_valid(value) THEN json_extract(value,'$.runId') END=?)<?
|
|
26
27
|
AND role!='owner' AND status!='invited' AND id=? AND (${scopes.map(scope => scope.sql).join(' OR ') || '0'})`,
|
|
27
28
|
args: [...approvalGuard.args, runId, approval.id, now - scheduledHandlerLimitMs, runId, maxActions, target.id, ...scopes.flatMap(scope => scope.args)] };
|
|
28
29
|
}
|
|
@@ -4,6 +4,11 @@ import { readPolicy } from './definition.mjs';
|
|
|
4
4
|
import { actionFence, bindPolicyActor } from './fence.mjs';
|
|
5
5
|
import { finishRun } from './history.mjs';
|
|
6
6
|
import { expireRuns } from './expiry.mjs';
|
|
7
|
+
// Expiry is reserved for the audited sweeper, never a callback result.
|
|
8
|
+
function runFailure(error) {
|
|
9
|
+
return error instanceof AuthError && error.code !== 'policy_expired'
|
|
10
|
+
? { status: 'refused', code: error.code } : { status: 'failed', code: 'policy_failed' };
|
|
11
|
+
}
|
|
7
12
|
const actionStatuses = Object.freeze({ 'operators:deactivate': 'inactive', 'operators:reactivate': 'active' });
|
|
8
13
|
|
|
9
14
|
export function policyRunner({ definitions, store, clock, currentApproval, check, rolePolicy }) {
|
|
@@ -23,13 +28,16 @@ export function policyRunner({ definitions, store, clock, currentApproval, check
|
|
|
23
28
|
}
|
|
24
29
|
}
|
|
25
30
|
try {
|
|
31
|
+
await expireRuns(store, policyId, startedAt);
|
|
26
32
|
policy = await readPolicy(definitions, policyId); approval = await currentApproval(policyId);
|
|
27
33
|
await store.run('UPDATE oa_policy_runs SET version_hash=?,approval_id=?,approved_by=? WHERE id=?', [policy.versionHash, approval?.id ?? null, approval?.ownerId ?? null, id]);
|
|
28
34
|
await verify(policy);
|
|
29
|
-
await expireRuns(store, policyId, startedAt);
|
|
30
35
|
const admission = await store.first(`UPDATE oa_policy_runs SET admitted=1 WHERE id=? AND NOT EXISTS(
|
|
31
|
-
SELECT 1 FROM oa_policy_runs WHERE policy_id=? AND id!=? AND admitted=1
|
|
32
|
-
AND (status='running' OR COALESCE(CASE WHEN
|
|
36
|
+
SELECT 1 FROM oa_policy_runs prior WHERE policy_id=? AND id!=? AND admitted=1
|
|
37
|
+
AND (status='running' OR COALESCE(CASE WHEN EXISTS(
|
|
38
|
+
SELECT 1 FROM oa_auth_audit WHERE action='policy:expired'
|
|
39
|
+
AND CASE WHEN json_valid(value) THEN json_extract(value,'$.runId') END=prior.id
|
|
40
|
+
) THEN started_at ELSE finished_at END,started_at)>?)) RETURNING id`,
|
|
33
41
|
[id, policyId, id, startedAt - policy.definition.minIntervalMinutes * 60000]);
|
|
34
42
|
if (!admission) deny('policy_interval', 429);
|
|
35
43
|
let pending = null, actionError = null, committed = 0;
|
|
@@ -52,7 +60,7 @@ export function policyRunner({ definitions, store, clock, currentApproval, check
|
|
|
52
60
|
pending = operation;
|
|
53
61
|
try { return await operation; } catch (error) {
|
|
54
62
|
actionError = error;
|
|
55
|
-
await store.run('INSERT INTO oa_auth_audit(id,actor_id,action,value,created_at) VALUES(?,?,?,?,?)', [crypto.randomUUID(), capability.actor, 'policy:refused', JSON.stringify({ policyId, versionHash: policy.versionHash, approvalId: approval.id, approvedBy: approval.ownerId, runId: id, operatorId, attemptedAction: action, error: error
|
|
63
|
+
await store.run('INSERT INTO oa_auth_audit(id,actor_id,action,value,created_at) VALUES(?,?,?,?,?)', [crypto.randomUUID(), capability.actor, 'policy:refused', JSON.stringify({ policyId, versionHash: policy.versionHash, approvalId: approval.id, approvedBy: approval.ownerId, runId: id, operatorId, attemptedAction: action, error: runFailure(error).code }), clock()]);
|
|
56
64
|
throw error;
|
|
57
65
|
} finally { pending = null; }
|
|
58
66
|
} });
|
|
@@ -61,7 +69,7 @@ export function policyRunner({ definitions, store, clock, currentApproval, check
|
|
|
61
69
|
await finishRun(store, id, null, clock());
|
|
62
70
|
return { id };
|
|
63
71
|
} catch (error) {
|
|
64
|
-
await finishRun(store, id,
|
|
72
|
+
await finishRun(store, id, runFailure(error), clock());
|
|
65
73
|
throw error;
|
|
66
74
|
} finally { open = false; }
|
|
67
75
|
};
|