@runeditrun/rer 0.2.31 → 0.2.32
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/README.md +94 -0
- package/cli/README.md +32 -0
- package/cli/business/api.mjs +61 -0
- package/cli/business/command.mjs +44 -20
- package/cli/business/config-policy.mjs +25 -0
- package/cli/business/connect.mjs +50 -0
- package/cli/business/discovery-task.mjs +180 -0
- package/cli/business/files.mjs +25 -0
- package/cli/business/keychain.mjs +113 -0
- package/cli/business/lease.mjs +68 -0
- package/cli/business/local-commands.mjs +82 -0
- package/cli/business/outbound.mjs +29 -0
- package/cli/business/parsers-syntax.mjs +3 -1
- package/cli/business/parsers.mjs +9 -3
- package/cli/business/permissions.mjs +143 -0
- package/cli/business/policy.mjs +7 -1
- package/cli/business/progress.mjs +18 -0
- package/cli/business/prompts.mjs +12 -0
- package/cli/business/questions.mjs +98 -0
- package/cli/business/repository.mjs +17 -0
- package/cli/business/scan-command.mjs +27 -0
- package/cli/business/scan.mjs +42 -35
- package/cli/business/service.mjs +152 -0
- package/cli/business/state.mjs +46 -0
- package/cli/business/supervisor.mjs +92 -0
- package/cli/business/vendors/README.md +101 -0
- package/cli/business/vendors/calendly.mjs +80 -0
- package/cli/business/vendors/common.mjs +103 -0
- package/cli/business/vendors/index.mjs +75 -0
- package/cli/business/vendors/pagerduty.mjs +70 -0
- package/cli/business/vendors/sentry.mjs +84 -0
- package/cli/business/vendors/uptimerobot.mjs +20 -0
- package/cli/deploy-command.mjs +3 -2
- package/cli/deploy-inputs.mjs +9 -0
- package/cli/deploy.mjs +3 -2
- package/global/CHANGELOG.md +13 -0
- package/global/README.md +94 -0
- package/global/cli/describe.mjs +20 -0
- package/global/cli/install.mjs +3 -3
- package/global/cli/repo-command.mjs +53 -0
- package/global/cli/repository-contract.mjs +7 -0
- package/global/cli/repository.mjs +84 -0
- package/global/launch/prepare.mjs +9 -6
- package/global/main.mjs +22 -2
- package/install.sh +7 -0
- package/modules/deploy-kit/owner-cli.mjs +5 -2
- package/modules/deploy-kit/owner.mjs +6 -4
- package/modules/deploy-kit/public-origin.mjs +17 -0
- package/package.json +1 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createWriteStream } from 'node:fs';
|
|
2
|
+
import { realpath } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { parse } from '../../cli/parse.mjs';
|
|
5
|
+
import { shellQuote } from '../../cli/node-runtime-cache.mjs';
|
|
6
|
+
import { install } from './install.mjs';
|
|
7
|
+
import { launcherOwner, layout } from './layout.mjs';
|
|
8
|
+
import { pathAdvice } from './path-link.mjs';
|
|
9
|
+
import { checkoutRepository, runCommand } from './repository.mjs';
|
|
10
|
+
import { ownRoot } from '../package-info.mjs';
|
|
11
|
+
import { prepare } from '../launch/prepare.mjs';
|
|
12
|
+
import { launchDirectory } from '../launch/state.mjs';
|
|
13
|
+
|
|
14
|
+
export async function repoCommand(request) {
|
|
15
|
+
const { verb, directory, args } = request;
|
|
16
|
+
parse([verb, ...args]); // Refuse invalid options before installation or cloning.
|
|
17
|
+
const paths = layout(), launcher = await launcherOwner(paths.launcher);
|
|
18
|
+
const installed = await install({ quiet: true });
|
|
19
|
+
if (installed !== 0) return installed;
|
|
20
|
+
await checkoutRepository(request);
|
|
21
|
+
const root = await realpath(request.root);
|
|
22
|
+
if (launcher.state === 'absent') {
|
|
23
|
+
const advice = await pathAdvice(paths);
|
|
24
|
+
if (advice) process.stderr.write(advice + '\n');
|
|
25
|
+
}
|
|
26
|
+
const next = command => `cd ${shellQuote(directory)} && rer ${command}`;
|
|
27
|
+
if (verb === 'setup') {
|
|
28
|
+
const state = await launchDirectory(root), children = new Set(), controller = new AbortController();
|
|
29
|
+
const log = createWriteStream(join(state, 'launch.log'), { flags: 'a', mode: 0o600 });
|
|
30
|
+
const handlers = new Map(['SIGINT', 'SIGTERM'].map(signal => [signal, () => { controller.abort(); for (const child of children) child.kill(signal); }]));
|
|
31
|
+
for (const [signal, handler] of handlers) process.on(signal, handler);
|
|
32
|
+
try {
|
|
33
|
+
const result = await prepare({ root, args, setupArgs: args, env: process.env, directory: state, children, signal: controller.signal,
|
|
34
|
+
report: fields => args.includes('--json') ? process.stdout.write(JSON.stringify({ version: 1, verb, event: 'progress', ...fields }) + '\n') : process.stderr.write(`rer setup: ${fields.message}\n`), log: text => log.write(text + '\n') });
|
|
35
|
+
await result.release?.();
|
|
36
|
+
} finally {
|
|
37
|
+
for (const [signal, handler] of handlers) process.off(signal, handler);
|
|
38
|
+
log.end();
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
if (verb === 'dev' && !args.includes('--json')) process.stdout.write(`Restart: ${next('dev')}\n`);
|
|
42
|
+
const entry = join(ownRoot, 'global/rer.mjs');
|
|
43
|
+
const code = await runCommand(process.execPath, [entry, verb, ...args], { cwd: root,
|
|
44
|
+
...(verb === 'dev' ? { onInterrupt: () => runCommand(process.execPath, [entry, 'dev', '--stop'], { cwd: root }) } : {}),
|
|
45
|
+
});
|
|
46
|
+
if (code !== 0) return code;
|
|
47
|
+
}
|
|
48
|
+
if (verb !== 'dev') {
|
|
49
|
+
const command = next(verb === 'install' ? 'setup' : 'dev');
|
|
50
|
+
process.stdout.write(args.includes('--json') ? JSON.stringify({ version: 1, verb, event: 'next', command }) + '\n' : `Next: ${command}\n`);
|
|
51
|
+
}
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Repository acquisition belongs to the global CLI, before checkout dispatch.
|
|
2
|
+
export const repositoryCommands = Object.freeze({
|
|
3
|
+
install: { usage: 'rer install <repo> [--dir DIR] [FLAGS]', effects: 'Install rer for this user, clone or reuse the repository, install its dependencies, then stop.' },
|
|
4
|
+
setup: { usage: 'rer setup <repo> [--dir DIR] [FLAGS]', effects: 'Install rer, clone or reuse the repository, install dependencies and set up a local owner, then print the dev command.' },
|
|
5
|
+
dev: { usage: 'rer dev <repo> [--dir DIR] [FLAGS]', effects: 'Install rer, clone or reuse the repository, install and set up as needed, then start dev and print RER_READY and RER_OPEN.' },
|
|
6
|
+
});
|
|
7
|
+
export const repositoryHelp = 'Repository: <owner>/<repo>, a GitHub HTTPS URL (with or without .git), or a git URL.\nClones into ./<repo-name>; --dir overrides. Reuses a clone with the same origin; refuses any other non-empty folder.\n';
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { execFile, spawn } from 'node:child_process';
|
|
2
|
+
import { lstat, mkdir, readdir, realpath } from 'node:fs/promises';
|
|
3
|
+
import { basename, resolve } from 'node:path';
|
|
4
|
+
import { promisify } from 'node:util';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { invalid, refuse } from '../../cli/errors.mjs';
|
|
7
|
+
|
|
8
|
+
const git = promisify(execFile);
|
|
9
|
+
|
|
10
|
+
function repository(value) {
|
|
11
|
+
if (/^[\w.-]+\/[\w.-]+$/.test(value)) return `https://github.com/${value}`;
|
|
12
|
+
if (/^(?:https?|ssh|git|file):\/\//.test(value) || /^[\w.-]+@[\w.-]+:.+/.test(value)) return value;
|
|
13
|
+
throw invalid('Use owner/repo, a GitHub HTTPS URL, or a git URL.');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function identity(value, cwd) {
|
|
17
|
+
const scp = /^[\w.-]+@([^:]+):(.+)$/.exec(value);
|
|
18
|
+
let host, path;
|
|
19
|
+
if (scp) [, host, path] = scp;
|
|
20
|
+
else {
|
|
21
|
+
let url;
|
|
22
|
+
try { url = new URL(value); } catch { return resolve(cwd, value); }
|
|
23
|
+
if (url.protocol === 'file:') return resolve(fileURLToPath(url));
|
|
24
|
+
host = url.hostname.toLowerCase() + (url.port ? `:${url.port}` : ''); path = url.pathname;
|
|
25
|
+
}
|
|
26
|
+
path = path.replace(/^\/+|\/+$/g, '').replace(/\.git$/, '');
|
|
27
|
+
return `${host.toLowerCase()}/${host.toLowerCase() === 'github.com' ? path.toLowerCase() : path}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function repoArguments(argv) {
|
|
31
|
+
// Existing invocations without a repository are dispatched unchanged.
|
|
32
|
+
if (!['dev', 'setup', 'install'].includes(argv[0]) || !argv[1] || argv[1].startsWith('-')) return undefined;
|
|
33
|
+
const url = repository(argv[1]), args = [], cwd = process.cwd();
|
|
34
|
+
let directory;
|
|
35
|
+
for (let i = 2; i < argv.length; i++) {
|
|
36
|
+
if (argv[i] !== '--dir') { args.push(argv[i]); continue; }
|
|
37
|
+
if (directory !== undefined) throw invalid('Use --dir only once.');
|
|
38
|
+
directory = argv[++i];
|
|
39
|
+
if (!directory?.trim() || directory.startsWith('-')) throw invalid('A folder is required for --dir.');
|
|
40
|
+
}
|
|
41
|
+
if (args.includes('--cwd')) throw invalid('Use --dir with a repository, or --cwd inside a checkout.');
|
|
42
|
+
const name = basename(url.replace(/\/+$/, '').replace(/\.git$/, ''));
|
|
43
|
+
if (!name || ['.', '..'].includes(name) || /[?#\\]/.test(name)) throw invalid('The git URL must name a repository.');
|
|
44
|
+
return { verb: argv[0], url, args, root: resolve(cwd, directory ?? name), directory: directory ?? name };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function checkoutRepository({ url, root, directory }) {
|
|
48
|
+
const conflict = () => refuse(`Folder ${directory} is not an empty folder or a clone of this repository. Choose another folder with --dir DIR.`);
|
|
49
|
+
let info;
|
|
50
|
+
try { info = await lstat(root); } catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
51
|
+
if (info) {
|
|
52
|
+
if (!info.isDirectory() && !info.isSymbolicLink()) throw conflict();
|
|
53
|
+
let entries;
|
|
54
|
+
try { entries = await readdir(root); } catch { throw conflict(); }
|
|
55
|
+
if (entries.length) {
|
|
56
|
+
try {
|
|
57
|
+
const [{ stdout: origin }, { stdout: top }] = await Promise.all([
|
|
58
|
+
git('git', ['-C', root, 'config', '--get', 'remote.origin.url']),
|
|
59
|
+
git('git', ['-C', root, 'rev-parse', '--show-toplevel']),
|
|
60
|
+
]);
|
|
61
|
+
if (await realpath(root) === await realpath(top.trim()) && identity(origin.trim(), root) === identity(url, process.cwd())) return;
|
|
62
|
+
} catch { /* A non-clone is refused by the same single-line message. */ }
|
|
63
|
+
throw conflict();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
await mkdir(resolve(root, '..'), { recursive: true });
|
|
67
|
+
const code = await runCommand('git', ['clone', '--depth', '1', '--', url, root]);
|
|
68
|
+
if (code !== 0) throw refuse(`Could not clone into ${directory}. Check the git URL and access, then rerun the command.`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Preserve normal dev foreground/detached behaviour and forward interrupts to
|
|
72
|
+
// the child while it is installing, setting up or serving.
|
|
73
|
+
export async function runCommand(command, args, options = {}) {
|
|
74
|
+
const { onInterrupt, ...spawnOptions } = options;
|
|
75
|
+
const child = spawn(command, args, { ...spawnOptions, stdio: 'inherit' });
|
|
76
|
+
let interrupted;
|
|
77
|
+
const handlers = new Map(['SIGINT', 'SIGTERM'].map(signal => [signal, () => { interrupted ??= signal; child.kill(signal); }]));
|
|
78
|
+
for (const [signal, handler] of handlers) process.on(signal, handler);
|
|
79
|
+
try {
|
|
80
|
+
const code = await new Promise((done, reject) => { child.once('error', reject); child.once('close', (code, signal) => done(code ?? (signal === 'SIGINT' ? 130 : 143))); });
|
|
81
|
+
if (interrupted) await onInterrupt?.();
|
|
82
|
+
return interrupted ? (interrupted === 'SIGINT' ? 130 : 143) : code;
|
|
83
|
+
} finally { for (const [signal, handler] of handlers) process.off(signal, handler); }
|
|
84
|
+
}
|
|
@@ -24,7 +24,7 @@ export const flagValue = (args, flag) => { const index = args.indexOf(flag); ret
|
|
|
24
24
|
// step running then is signalled through `children`. `doorStart`: the front
|
|
25
25
|
// door is starting this checkout on a visit, which never installs or sets up;
|
|
26
26
|
// an unprepared checkout is refused with the reason.
|
|
27
|
-
export async function prepare({ root, args, env, report, directory, log, children, signal, doorStart = false }) {
|
|
27
|
+
export async function prepare({ root, args, setupArgs = [], env, report, directory, log, children, signal, doorStart = false }) {
|
|
28
28
|
// A checkout pinning the rer package whose node_modules lacks that version
|
|
29
29
|
// installs it first (after the same quick server-limit check: a pin with
|
|
30
30
|
// package mode has the person defaults); every step after this runs the
|
|
@@ -53,6 +53,9 @@ export async function prepare({ root, args, env, report, directory, log, childre
|
|
|
53
53
|
const step = (record, args, fields, env = childEnv) => recorded(directory, record, () => runVerb(entry, args, { root, env, note, log, children, signal }), fields);
|
|
54
54
|
// Only this setup fills the seed's declared local defaults.
|
|
55
55
|
const setupEnv = { ...childEnv, [localDefaults]: '1' };
|
|
56
|
+
// Repository setup can supply the same owner/answer inputs as checkout setup.
|
|
57
|
+
const extraSetup = setupArgs.filter((arg, i) => !['--json', '--non-interactive', '--port', '--host', '--door', '--owner-email'].includes(arg) && !['--port', '--host', '--owner-email'].includes(setupArgs[i - 1]));
|
|
58
|
+
const ownerArgs = flagValue(setupArgs, '--owner-email') ? ['--owner-email', flagValue(setupArgs, '--owner-email')] : [];
|
|
56
59
|
const unprepared = what => new LaunchFailure(3, `${checkout} is not ${what}, and the front door starts only prepared checkouts. Run rer dev in it once.`);
|
|
57
60
|
if (!installed && await needsInstall(root, await installState.read(directory))) {
|
|
58
61
|
if (doorStart) throw unprepared('installed');
|
|
@@ -65,25 +68,25 @@ export async function prepare({ root, args, env, report, directory, log, childre
|
|
|
65
68
|
if (setup === 'resume') {
|
|
66
69
|
// Saved settings hold an owner and origin; setup keeps them.
|
|
67
70
|
report({ phase: 'setup', message: 'finishing this checkout\'s setup, keeping its saved owner and port' });
|
|
68
|
-
await step(setupState, ['setup', ...hostArgs], {}, setupEnv);
|
|
71
|
+
await step(setupState, ['setup', ...hostArgs, ...ownerArgs, ...extraSetup], {}, setupEnv);
|
|
69
72
|
} else if (setup === 'fresh' && plan.freshAtDoor) {
|
|
70
73
|
// With the door enabled, a fresh checkout is set up at its door origin.
|
|
71
|
-
const owner = zeroSetupOwner(checkout);
|
|
74
|
+
const owner = flagValue(setupArgs, '--owner-email') ?? zeroSetupOwner(checkout);
|
|
72
75
|
report({ phase: 'setup', message: `setting up a local owner (${owner}) at its front-door address` });
|
|
73
|
-
await step(setupState, ['setup', '--owner-email', owner, '--door'], { owner, door: true }, setupEnv);
|
|
76
|
+
await step(setupState, ['setup', '--owner-email', owner, '--door', ...extraSetup], { owner, door: true }, setupEnv);
|
|
74
77
|
await bringBackDoor({ ...plan, atDoor: true }, env, report);
|
|
75
78
|
return { entry, added };
|
|
76
79
|
} else if (setup === 'fresh') {
|
|
77
80
|
// An interrupted setup resumes on the port it chose while that port is free.
|
|
78
81
|
// A port another process takes between choosing it and setup refusing it is
|
|
79
82
|
// passed over for the next free one; a port the person passed is kept.
|
|
80
|
-
const owner = zeroSetupOwner(checkout), explicit = flagValue(args, '--port');
|
|
83
|
+
const owner = flagValue(setupArgs, '--owner-email') ?? zeroSetupOwner(checkout), explicit = flagValue(args, '--port');
|
|
81
84
|
let from = last?.port;
|
|
82
85
|
for (let attempt = 1; ; attempt++) {
|
|
83
86
|
const held = explicit ? [] : [...(await liveServers(childEnv)).map(record => record.port), ...await savedPorts(checkout, childEnv)];
|
|
84
87
|
const { port, release } = explicit ? { port: Number(explicit) } : await freePort(held, port => claimPort(port, childEnv), from ? { ...childEnv, RER_DEV_PORT_FROM: String(from) } : childEnv);
|
|
85
88
|
report({ phase: 'setup', message: `setting up a local owner (${owner}) on port ${port}` });
|
|
86
|
-
try { await step(setupState, ['setup', '--owner-email', owner, '--port', String(port), ...hostArgs], { port, owner }, setupEnv); }
|
|
89
|
+
try { await step(setupState, ['setup', '--owner-email', owner, '--port', String(port), ...hostArgs, ...extraSetup], { port, owner }, setupEnv); }
|
|
87
90
|
catch (failure) {
|
|
88
91
|
await release?.();
|
|
89
92
|
if (explicit || attempt === 3 || failure.exitCode !== 4 || !await portTaken(port)) throw failure;
|
package/global/main.mjs
CHANGED
|
@@ -3,9 +3,16 @@ import { dispatcher, locate, pinnedPackage, unsupportedMessage } from './checkou
|
|
|
3
3
|
import { delegate } from './delegate.mjs';
|
|
4
4
|
import { localDefaults } from './launch/local-defaults.mjs';
|
|
5
5
|
import { handleBrokenPipes } from './output.mjs';
|
|
6
|
+
import { repositoryCommands, repositoryHelp } from './cli/repository-contract.mjs';
|
|
7
|
+
import { repoArguments } from './cli/repository.mjs';
|
|
6
8
|
|
|
7
9
|
const help = `Usage: rer VERB [FLAGS]
|
|
8
10
|
|
|
11
|
+
rer dev <repo> [--dir DIR] Clone, install, set up a local owner and start the app.
|
|
12
|
+
rer setup <repo> [--dir DIR] Clone, install and set up, then stop.
|
|
13
|
+
rer install <repo> [--dir DIR] Clone and install dependencies, then stop.
|
|
14
|
+
${repositoryHelp}
|
|
15
|
+
|
|
9
16
|
Inside a project (the nearest OPERATIONS.json at or above this folder, or --cwd DIR),
|
|
10
17
|
every verb runs that checkout's own pinned rer: the @runeditrun/rer version its package.json
|
|
11
18
|
pins (installed first by any verb when node_modules holds another), else its vendored scripts/rer.mjs.
|
|
@@ -17,8 +24,8 @@ pins (installed first by any verb when node_modules holds another), else its ven
|
|
|
17
24
|
to 10 minutes on a first launch, or rerun it to reattach. rer dev --stop stops it.
|
|
18
25
|
rer list [DIR] The checkouts in DIR (default: here), newest first, with whether rer dev can
|
|
19
26
|
launch them, whether they are set up, and their running URL. --json for data.
|
|
20
|
-
rer business
|
|
21
|
-
|
|
27
|
+
rer business ... Pair a Business device, store local vendor keys, inspect tasks and disconnect.
|
|
28
|
+
rer business --help lists the commands and current protocol limitations.
|
|
22
29
|
rer door ... The opt-in front door: every checkout at http://NAME.localhost:PORT, started
|
|
23
30
|
on its first visit and stopped when idle. rer door --help for its verbs.
|
|
24
31
|
rer cli status This rer: version, contents digest, install channel, launcher and other rer
|
|
@@ -59,6 +66,18 @@ export async function main(argv) {
|
|
|
59
66
|
if (verb === 'cli') return (await import('./cli/command.mjs')).cliCommand(argv.slice(1));
|
|
60
67
|
if (verb === 'list') return (await import('./list.mjs')).listCommand(argv.slice(1));
|
|
61
68
|
if (verb === 'door') return (await import('./door/command.mjs')).doorCommand(argv.slice(1));
|
|
69
|
+
if (repositoryCommands[verb] && argv.includes('--help')) {
|
|
70
|
+
const { help } = await import('../cli/parse.mjs');
|
|
71
|
+
process.stdout.write(`${help(verb)}\n${repositoryCommands[verb].usage}\n${repositoryCommands[verb].effects}\n${repositoryHelp}`);
|
|
72
|
+
return 0;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const repository = repoArguments(argv);
|
|
76
|
+
if (repository) return await (await import('./cli/repo-command.mjs')).repoCommand(repository);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
process.stderr.write(error.message + '\n');
|
|
79
|
+
return typeof error.exitCode === 'number' ? error.exitCode : 1;
|
|
80
|
+
}
|
|
62
81
|
const target = locate(argv);
|
|
63
82
|
if (target.profile === 'unsupported') { process.stderr.write(unsupportedMessage(target.root, target.version) + '\n'); return 2; }
|
|
64
83
|
const first = target.profile === 'first-party', mode = first ? dispatcher(target.root).mode : undefined;
|
|
@@ -110,6 +129,7 @@ export async function main(argv) {
|
|
|
110
129
|
catch (failure) { if (!(failure instanceof LaunchFailure)) throw failure; process.stderr.write(failure.message + '\n'); return failure.exitCode; }
|
|
111
130
|
}
|
|
112
131
|
if (mode === 'package' && installsFirst.has(verb)) await (await import('./launch/install-pinned.mjs')).settledPin(target.root);
|
|
132
|
+
if (verb === 'describe' && !argv.includes('--help')) return (await import('./cli/describe.mjs')).describeCommand(target);
|
|
113
133
|
if (first && dispatcher(target.root).mode !== 'bundled' && ['install', 'verify'].includes(verb) && !argv.includes('--help') && !argv.includes('--site')) {
|
|
114
134
|
const code = await (await import('./browser-runtime.mjs')).browserPreflight(target.root, target.args);
|
|
115
135
|
if (code !== undefined) return code;
|
package/install.sh
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
# Install the rer command (@runeditrun/rer) for this user:
|
|
3
3
|
#
|
|
4
4
|
# curl -fsSL https://runeditrun.com/install.sh | sh
|
|
5
|
+
# curl -fsSL https://runeditrun.com/install.sh | sh -s -- dev owner/repo
|
|
5
6
|
#
|
|
6
7
|
# It reads the version, tarball and sha512 integrity from the npm registry
|
|
7
8
|
# (npm_config_registry, default https://registry.npmjs.org; RER_VERSION=X pins an
|
|
@@ -18,6 +19,7 @@
|
|
|
18
19
|
# Everything runs from main, so a partly downloaded script does nothing.
|
|
19
20
|
main() {
|
|
20
21
|
set -eu
|
|
22
|
+
if [ "${1:-}" = -- ]; then shift; fi
|
|
21
23
|
package='@runeditrun/rer'
|
|
22
24
|
|
|
23
25
|
case "$(uname -s 2>/dev/null || echo unknown)" in
|
|
@@ -139,6 +141,11 @@ NODE
|
|
|
139
141
|
tar -xzf "$work/rer.tgz" -C "$work/stage" || fail "could not unpack rer $version; nothing was installed."
|
|
140
142
|
RER_INSTALL_CHANNEL=script node "$work/stage/package/global/rer.mjs" cli install </dev/null \
|
|
141
143
|
|| fail "rer cli install failed; any previous install is still selected."
|
|
144
|
+
if [ "$#" -gt 0 ]; then
|
|
145
|
+
PATH="$HOME/.local/bin:$PATH"
|
|
146
|
+
export PATH
|
|
147
|
+
"$HOME/.local/bin/rer" "$@"
|
|
148
|
+
fi
|
|
142
149
|
}
|
|
143
150
|
|
|
144
151
|
install_node() {
|
|
@@ -14,6 +14,7 @@ import { ownerSecret } from './owner-secret.mjs';
|
|
|
14
14
|
import { ownerRemove } from './owner-remove.mjs';
|
|
15
15
|
import { ownerSignin } from './owner-signin.mjs';
|
|
16
16
|
import { refuseLocalModels } from './local-only.mjs';
|
|
17
|
+
import { publicOrigin } from './public-origin.mjs';
|
|
17
18
|
|
|
18
19
|
export const cronNotice = 'This Worker has a Cron Trigger. Cloudflare may take up to about two hours to start its first scheduled run on some accounts.';
|
|
19
20
|
const usage = 'usage: owner-cli.mjs deploy|health|remove|inspect|record-owner|signin --declaration <file> --environment <name> [--product <dir>] [--state <file>] [--outcome claimed|kept] | secret ... --set NAME|--unset NAME';
|
|
@@ -44,6 +45,8 @@ export async function main(argv = process.argv.slice(2), env = process.env, {fet
|
|
|
44
45
|
try { declaration = JSON.parse(await regularBytes(resolve(root,values.declaration),256 * 1024)); }
|
|
45
46
|
catch (error) { throw new Error(error.code === 'ENOENT' ? 'missing-owner-declaration' : 'invalid-owner-declaration'); }
|
|
46
47
|
assert(typeof declaration?.project === 'string','missing-owner-project');
|
|
48
|
+
// Validate even direct kit invocations before any provider request or write.
|
|
49
|
+
publicOrigin(declaration, env);
|
|
47
50
|
// Removal reads identity before each object DELETE and may span many pages.
|
|
48
51
|
// Bound each response, not the owner's bucket size; failures retain ownership.
|
|
49
52
|
let requestWindow = propagation?.uploaded ? propagation.window : undefined;
|
|
@@ -93,7 +96,7 @@ export async function main(argv = process.argv.slice(2), env = process.env, {fet
|
|
|
93
96
|
}
|
|
94
97
|
const current = retiredSecrets.length && Array.isArray(declaration.secrets) ? {...declaration,secrets:declaration.secrets.filter(item => !retiredSecrets.includes(item?.binding))} : declaration;
|
|
95
98
|
const artifact = await ownerArtifact(root,values.product);
|
|
96
|
-
const plan = ownerPlan(target,current,artifact,{localOnlyKeys});
|
|
99
|
+
const plan = ownerPlan(target,current,artifact,{localOnlyKeys,env});
|
|
97
100
|
if (command === 'health') {
|
|
98
101
|
const readiness = {...(healthOptions?.now ? {clock:healthOptions.now} : {}), ...(healthOptions?.sleep ? {sleep:healthOptions.sleep} : {}),
|
|
99
102
|
...healthOptions?.readiness,single:true,totalMs:30000,
|
|
@@ -104,7 +107,7 @@ export async function main(argv = process.argv.slice(2), env = process.env, {fet
|
|
|
104
107
|
// Dispatch is the provider's: on some accounts a new Cron starts only at the account scheduler's next refresh.
|
|
105
108
|
if (plan.crons.length) notice(cronNotice);
|
|
106
109
|
// The fingerprint names every declared secret, retired ones too: an untouched repeat after the claim is a no-op.
|
|
107
|
-
const declaredSecrets = current === declaration ? plan.secrets : ownerPlan(target,declaration,artifact,{localOnlyKeys}).secrets;
|
|
110
|
+
const declaredSecrets = current === declaration ? plan.secrets : ownerPlan(target,declaration,artifact,{localOnlyKeys,env}).secrets;
|
|
108
111
|
const window = readinessWindow({...(healthOptions?.now ? {clock:healthOptions.now} : {}), ...(healthOptions?.sleep ? {sleep:healthOptions.sleep} : {}), ...healthOptions?.readiness});
|
|
109
112
|
requestWindow = window;
|
|
110
113
|
const {receipt,created,sentSecrets,freshUpload} = await ownerDeploy({api,target,plan,artifact,statePath,env,fetch,healthOptions,readiness:{...healthOptions?.readiness,window},settle,declaredSecrets}).catch(error => {
|
|
@@ -12,6 +12,7 @@ import { validateMigrations } from './migrations.mjs';
|
|
|
12
12
|
import { deploy } from './deploy.mjs';
|
|
13
13
|
import { verifyHealth } from './health.mjs';
|
|
14
14
|
import { validSecretNames, secretNames, pendingSecretNames } from './owner-secret-names.mjs';
|
|
15
|
+
import { publicOrigin } from './public-origin.mjs';
|
|
15
16
|
|
|
16
17
|
/* Owner-account mode: the owner's own Cloudflare account, token and account id.
|
|
17
18
|
* Names are derived from the project id and the owner's environment. A local
|
|
@@ -21,7 +22,7 @@ import { validSecretNames, secretNames, pendingSecretNames } from './owner-secre
|
|
|
21
22
|
const segment = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
22
23
|
const STATE_KIND = 'rer-deploy-owner-state';
|
|
23
24
|
export const KINDS = ['d1','r2','kv','queues'];
|
|
24
|
-
const DECLARATION_KEYS = ['version','project','compatibilityDate','compatibilityFlags','d1','r2','kv','queues','durableObjects','secrets','crons','vars','originVar','services','workersDev','platforms','container'];
|
|
25
|
+
const DECLARATION_KEYS = ['version','project','compatibilityDate','compatibilityFlags','d1','r2','kv','queues','durableObjects','secrets','crons','vars','originVar','publicOriginSetting','services','workersDev','platforms','container'];
|
|
25
26
|
const ENTRY_KEYS = {d1:['binding'],r2:['binding','locationHint'],kv:['binding'],queues:['binding','consumer','deadLetterQueue'],durableObjects:['binding','className','storage'],secrets:['binding','environment','verifyStandIn'],services:['binding','project','entrypoint','allowedHosts','grant']};
|
|
26
27
|
|
|
27
28
|
export function refuse(code, kind, name) { const error = new Error(code); error.resource = `${kind}:${name}`; return error; }
|
|
@@ -107,11 +108,11 @@ function entries(declaration, key) {
|
|
|
107
108
|
export const LOCAL_ONLY_KEYS = Object.freeze(['RER_DEV_KEY', 'RER_DEMO', 'RER_MODELS_KEY', 'RER_MODELS_SERVICE', '.rer/local/models.json']);
|
|
108
109
|
export function localOnlyBinding(declaration, localOnlyKeys = []) {
|
|
109
110
|
const refused = new Set([...LOCAL_ONLY_KEYS, ...localOnlyKeys]);
|
|
110
|
-
const names = [...Object.keys(declaration?.vars ?? {}), declaration?.originVar, ...(Array.isArray(declaration?.secrets) ? declaration.secrets.flatMap(item => [item?.binding, item?.environment]) : [])];
|
|
111
|
+
const names = [...Object.keys(declaration?.vars ?? {}), declaration?.originVar, declaration?.publicOriginSetting, ...(Array.isArray(declaration?.secrets) ? declaration.secrets.flatMap(item => [item?.binding, item?.environment]) : [])];
|
|
111
112
|
return names.find(name => refused.has(name)) ?? null;
|
|
112
113
|
}
|
|
113
114
|
/** A seed declares bindings, never names. Migrations come from the packaged artifact. */
|
|
114
|
-
export function ownerPlan(target, declaration, artifact, { localOnlyKeys = [] } = {}) {
|
|
115
|
+
export function ownerPlan(target, declaration, artifact, { localOnlyKeys = [], env = {} } = {}) {
|
|
115
116
|
assert(declaration?.version === 1 && typeof declaration === 'object' && Object.keys(declaration).every(key => DECLARATION_KEYS.includes(key)), 'invalid-owner-declaration');
|
|
116
117
|
if (declaration.platforms !== undefined) assert(Array.isArray(declaration.platforms) && declaration.platforms.length > 0 && new Set(declaration.platforms).size === declaration.platforms.length && declaration.platforms.every(item => ['workers','container'].includes(item)), 'invalid-platforms');
|
|
117
118
|
if (declaration.container !== undefined) {
|
|
@@ -131,9 +132,10 @@ export function ownerPlan(target, declaration, artifact, { localOnlyKeys = [] }
|
|
|
131
132
|
const queues = entries(declaration,'queues');
|
|
132
133
|
for (const item of queues) assert(item.deadLetterQueue === undefined || queues.some(other => other.binding === item.deadLetterQueue), 'invalid-dead-letter-queue');
|
|
133
134
|
const vars = {...(declaration.vars ?? {})};
|
|
135
|
+
const origin = publicOrigin(declaration, env);
|
|
134
136
|
if (declaration.originVar !== undefined) {
|
|
135
137
|
assert(identifier(declaration.originVar) && !Object.hasOwn(vars,declaration.originVar), 'invalid-owner-origin-variable');
|
|
136
|
-
vars[declaration.originVar] = target.origin;
|
|
138
|
+
vars[declaration.originVar] = origin ?? target.origin;
|
|
137
139
|
}
|
|
138
140
|
const kv = entries(declaration,'kv').map(({binding}) => ({binding,name:name(binding)}));
|
|
139
141
|
// A service binding names another project; its Worker name derives from the same environment.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { assert, identifier } from './validation.mjs';
|
|
2
|
+
|
|
3
|
+
// This public setting changes only originVar, never the deployment target.
|
|
4
|
+
export function publicOrigin(declaration, env = {}) {
|
|
5
|
+
const setting = declaration.publicOriginSetting;
|
|
6
|
+
if (setting === undefined) return undefined;
|
|
7
|
+
assert(identifier(setting) && identifier(declaration.originVar), 'invalid-public-origin-setting');
|
|
8
|
+
const value = env[setting];
|
|
9
|
+
if (value === undefined) return undefined;
|
|
10
|
+
// Check the input as well as URL's result: URL normalizes away empty query,
|
|
11
|
+
// fragment, dot paths, backslashes and whitespace that must be refused.
|
|
12
|
+
assert(typeof value === 'string' && /^https:\/\/(?:\[[0-9a-fA-F:.]+\]|[^:/?#@\\\s]+)(?::[0-9]+)?$/.test(value), 'invalid-public-origin');
|
|
13
|
+
let url;
|
|
14
|
+
try { url = new URL(value); } catch { throw new Error('invalid-public-origin'); }
|
|
15
|
+
assert(url.protocol === 'https:' && url.hostname && !url.username && !url.password && url.pathname === '/' && !url.search && !url.hash, 'invalid-public-origin');
|
|
16
|
+
return url.origin;
|
|
17
|
+
}
|