@runeditrun/rer 0.2.19 → 0.2.21
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 +7 -7
- package/cli/README.md +22 -21
- package/cli/adapter.mjs +5 -0
- package/cli/container.mjs +7 -2
- package/cli/contract.mjs +3 -4
- package/cli/delivery-declarations.mjs +36 -0
- package/cli/demo-host.mjs +6 -5
- package/cli/demo-removal-provider.mjs +24 -0
- package/cli/demo.mjs +16 -5
- package/cli/deploy-command.mjs +11 -5
- package/cli/deploy-hook.mjs +10 -14
- package/cli/deploy.mjs +4 -1
- package/cli/detached-server.mjs +2 -2
- package/cli/dev-identity.mjs +1 -1
- package/cli/export.mjs +1 -1
- package/cli/inspect.mjs +13 -13
- package/cli/lifecycle.mjs +16 -49
- package/cli/listen.mjs +31 -0
- package/cli/local.mjs +12 -18
- package/cli/main.mjs +5 -0
- package/cli/managed-server.mjs +26 -44
- package/cli/output.mjs +1 -1
- package/cli/parse.mjs +3 -3
- package/cli/port.mjs +20 -20
- package/cli/production-auth.mjs +38 -0
- package/cli/server-proxy.mjs +2 -6
- package/cli/server-registry.mjs +7 -2
- package/cli/setup-input.mjs +3 -0
- package/global/CHANGELOG.md +15 -0
- package/global/README.md +7 -7
- package/global/cli/install.mjs +4 -28
- package/global/cli/path-link.mjs +25 -21
- package/global/launch/dev.mjs +1 -1
- package/global/launch/facts.mjs +11 -14
- package/global/launch/failure.mjs +20 -0
- package/global/launch/render.mjs +2 -6
- package/global/launch/worker.mjs +3 -3
- package/global/main.mjs +1 -1
- package/modules/container/build.mjs +5 -3
- package/modules/container/demo-egress.mjs +35 -0
- package/modules/container/worker-engine.mjs +3 -3
- package/modules/d1-transport/index.d.mts +9 -0
- package/modules/d1-transport/index.mjs +124 -0
- package/modules/delivery-producer/bindings.mjs +140 -0
- package/modules/delivery-producer/declarations.mjs +49 -0
- package/modules/demo/README.md +34 -0
- package/modules/demo/effects.mjs +73 -0
- package/modules/demo/index.d.mts +15 -0
- package/modules/demo/index.mjs +63 -0
- package/modules/demo/label.d.mts +2 -0
- package/modules/demo/label.mjs +24 -0
- package/modules/demo/responses.mjs +26 -0
- package/modules/demo/sockets.mjs +13 -0
- package/modules/demo/vite.d.mts +2 -0
- package/modules/demo/vite.mjs +19 -0
- package/modules/demo-host/README.md +14 -1
- package/modules/demo-host/container.mjs +17 -11
- package/modules/demo-host/diagnostics.mjs +1 -0
- package/modules/demo-host/pages.mjs +1 -1
- package/modules/demo-host/placement.mjs +23 -0
- package/modules/demo-host/plan.mjs +1 -1
- package/modules/demo-host/startup.mjs +1 -1
- package/modules/demo-host/worker.mjs +2 -2
- package/modules/deploy-kit/README.md +12 -0
- package/modules/deploy-kit/health-request.mjs +7 -5
- package/modules/deploy-kit/owner.mjs +2 -2
- package/modules/deploy-kit/r2-objects.mjs +8 -5
- package/modules/job-queue/storage.mjs +4 -1
- package/modules/mail/README.md +19 -86
- package/modules/mail/src/core/validation.mjs +0 -1
- package/modules/mail/src/development/index.d.mts +1 -6
- package/modules/mail/src/development/index.mjs +3 -16
- package/modules/operator-auth/README.md +10 -9
- package/modules/operator-auth/csp.mjs +1 -2
- package/modules/operator-auth/dev/cli-session.mjs +32 -0
- package/modules/operator-auth/dev/index.mjs +18 -11
- package/modules/operator-auth/identity/email-link/index.mjs +3 -0
- package/modules/operator-auth/page.mjs +1 -1
- package/modules/operator-auth/signin/index.d.mts +1 -1
- package/modules/portability/README.md +6 -0
- package/modules/portability/catalogue.mjs +1 -1
- package/modules/portability/copies.mjs +17 -2
- package/modules/portability/index.mjs +2 -0
- package/modules/portability/storage.mjs +5 -1
- package/onboarding/README.md +8 -11
- package/onboarding/adapter-auth.mjs +6 -38
- package/onboarding/adapter-labels.mjs +1 -1
- package/onboarding/adapter.mjs +8 -11
- package/onboarding/app-fetch.mjs +1 -1
- package/onboarding/dependency-approval.mjs +5 -15
- package/onboarding/dev-identity.mjs +1 -1
- package/onboarding/operator-install.mjs +6 -7
- package/onboarding/operator-installer.mjs +5 -5
- package/onboarding/operator-prerequisites.mjs +4 -5
- package/onboarding/port-probe.mjs +38 -0
- package/onboarding/process-diagnostics.mjs +36 -20
- package/onboarding/server.mjs +1 -1
- package/onboarding/ui/app.js +1 -1
- package/operations/README.md +3 -0
- package/package.json +4 -2
- package/scripts/publish-check/public_hygiene.py +31 -10
- package/modules/mail/src/development/viewer-html.mjs +0 -42
- package/modules/mail/src/development/viewer.mjs +0 -72
- package/modules/operator-auth/dev/badge.mjs +0 -44
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { refuse } from './errors.mjs';
|
|
2
|
+
import { mailbox } from './parse.mjs';
|
|
3
|
+
import { main as owner } from '../modules/deploy-kit/owner-cli.mjs';
|
|
4
|
+
import { hookState } from './deploy-hook-record.mjs';
|
|
5
|
+
import { savedSetupAnswers } from './setup-answers.mjs';
|
|
6
|
+
import { validateRerConfig } from '../modules/mail/src/adapters/rer/contract.mjs';
|
|
7
|
+
|
|
8
|
+
// Validate the shared email/identity contract using the bindings that will reach
|
|
9
|
+
// the runtime. Independently authored authentication remains the adapter's job.
|
|
10
|
+
export async function requireProductionAuth({ root, declaration, env, setupManifest, setupSeed, adapter, declarationPath, options = {} }) {
|
|
11
|
+
const dependencies = setupManifest?.dependencies?.filter(item => item.interface === 'oidc-provider@1') ?? [];
|
|
12
|
+
const bindings = { ...declaration.vars };
|
|
13
|
+
for (const secret of declaration.secrets ?? []) if (env[secret.environment]?.trim()) bindings[secret.binding] = env[secret.environment];
|
|
14
|
+
if (!setupManifest?.steps?.some(step => step.type === 'owner-claim') && !dependencies.length && !('MAIL_PROVIDER' in bindings) && !declaration.secrets?.some(item => item.binding === 'MAIL_API_KEY')) return;
|
|
15
|
+
const provider = bindings.MAIL_PROVIDER;
|
|
16
|
+
let mailSelected = ['resend', 'sendgrid', 'cloudflare', 'rer'].includes(provider) && mailbox(bindings.MAIL_FROM);
|
|
17
|
+
if (provider === 'rer') {
|
|
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) {
|
|
23
|
+
try {
|
|
24
|
+
const state = await hookState(root, options.environment ?? 'production');
|
|
25
|
+
const existing = await owner(['inspect', '--declaration', declarationPath, '--environment', options.environment ?? 'production', ...(state ? ['--state', state] : [])], env, { cwd: root, localOnlyKeys: adapter?.localOnlyKeys });
|
|
26
|
+
if (required.every(key => bindings[key]?.trim() || existing.liveSecrets.includes(key))) return;
|
|
27
|
+
} catch (error) {
|
|
28
|
+
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
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const answers = setupSeed ? await savedSetupAnswers({ root, adapter, setupManifest }, setupSeed.model) : undefined;
|
|
32
|
+
// Link approval and live post-link status are checked by linkDependencies;
|
|
33
|
+
// selecting an issuer never bypasses that existing setup requirement.
|
|
34
|
+
if (dependencies.some(item => {
|
|
35
|
+
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
|
+
})) return;
|
|
37
|
+
throw refuse('Production sign-in is not configured. Configure outbound email (MAIL_PROVIDER, MAIL_FROM and MAIL_API_KEY; Cloudflare also needs MAIL_ACCOUNT_ID, RER needs MAIL_RELAY_URL), 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
|
+
}
|
package/cli/server-proxy.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import http from 'node:http';
|
|
|
2
2
|
import net from 'node:net';
|
|
3
3
|
import { createHmac, randomUUID, timingSafeEqual } from 'node:crypto';
|
|
4
4
|
import { posix } from 'node:path';
|
|
5
|
-
import {
|
|
5
|
+
import { listen } from './listen.mjs';
|
|
6
6
|
import { loopback } from './parse.mjs';
|
|
7
7
|
import { fontResponseHeaders } from './font-cache.mjs';
|
|
8
8
|
|
|
@@ -79,11 +79,7 @@ export async function trafficProxy({host,port,target,activity,door,devKey,origin
|
|
|
79
79
|
}
|
|
80
80
|
upstream.on('error',()=>socket.destroy());socket.on('error',()=>upstream.destroy());socket.on('close',()=>upstream.destroy());upstream.on('close',()=>socket.destroy());
|
|
81
81
|
});
|
|
82
|
-
|
|
83
|
-
catch(error){
|
|
84
|
-
if(['EADDRINUSE','EACCES'].includes(error.code))throw refuse(`Requested port ${port} is unavailable. Stop its owner or choose an explicit free port; rer does not drift.`);
|
|
85
|
-
throw error;
|
|
86
|
-
}
|
|
82
|
+
await listen(server,host,port);
|
|
87
83
|
return {probe,port:server.address().port,async close(){for(const socket of sockets)socket.destroy();await new Promise(resolve=>server.close(resolve));}};
|
|
88
84
|
}
|
|
89
85
|
function doorAdmits(req,door){
|
package/cli/server-registry.mjs
CHANGED
|
@@ -92,9 +92,14 @@ export async function serverRegistry(root,{env=process.env,memory=availableMemor
|
|
|
92
92
|
if(info.isSymbolicLink()||!info.isDirectory()||info.uid!==process.getuid())throw refuse('Server registry directory is foreign or linked. Preserve it and choose an owned RER_SERVERS_DIR.');
|
|
93
93
|
await chmod(path,0o700);
|
|
94
94
|
}
|
|
95
|
-
try{const info=await lstat(join(directory,'state.json'));if(!info.isFile()||info.isSymbolicLink()||info.nlink!==1||info.uid!==process.getuid())throw refuse('Server registry state is foreign or linked. Preserve it for inspection.');await chmod(join(directory,'state.json'),0o600);}catch(error){if(error.code!=='ENOENT')throw error;}
|
|
96
95
|
}
|
|
97
|
-
|
|
96
|
+
async function validateState(path){
|
|
97
|
+
// Hold the transaction lock before inspecting the state inode. A concurrent
|
|
98
|
+
// atomic replacement can otherwise make lstat report the retired inode with
|
|
99
|
+
// zero links, even though both files are regular and owned by this user.
|
|
100
|
+
try{const info=await lstat(path);if(!info.isFile()||info.isSymbolicLink()||info.nlink!==1||info.uid!==process.getuid())throw refuse('Server registry state is foreign or linked. Preserve it for inspection.');await chmod(path,0o600);}catch(error){if(error.code!=='ENOENT')throw error;}
|
|
101
|
+
}
|
|
102
|
+
const change=async action=>{await (secured??=secure());return transaction(directory,lifetime.info,action,{validateState});};
|
|
98
103
|
let owned, control, closing;
|
|
99
104
|
async function inspect(state) {
|
|
100
105
|
const kept=[];
|
package/cli/setup-input.mjs
CHANGED
|
@@ -47,6 +47,9 @@ export async function setupInput(project, options, vars, signal, { origin } = {}
|
|
|
47
47
|
const savedEmail = vars[names.email];
|
|
48
48
|
if (!answers[names.email] && savedEmail) answers[names.email] = savedEmail;
|
|
49
49
|
if (hasOwnerName) answers[names.name] ??= seed.model.fields[names.name].default ?? 'Owner';
|
|
50
|
+
// Saved secrets satisfy readiness and must also reach the seed's owner hook
|
|
51
|
+
// when setup resumes. Keep them in private input, never the saved safe answers.
|
|
52
|
+
for(const field of seed.manifest.fields)if(field.kind==='secret'&&!answers[field.name]&&typeof vars[field.name]==='string')answers[field.name]=vars[field.name];
|
|
50
53
|
if(process.env[localDefaultsVariable]==='1')applyLocalDefaults(seed,answers,vars,origin);
|
|
51
54
|
const entered=seed.manifest.fields.filter(field=>field.kind==='secret'&&field.input==='entered');
|
|
52
55
|
for(const field of entered)if(!answers[field.name]&&!vars[field.name]&&process.env[field.name])answers[field.name]=process.env[field.name];
|
package/global/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.21
|
|
4
|
+
|
|
5
|
+
- Demo removal retries transient Cloudflare provider failures while preserving the resource ownership checks.
|
|
6
|
+
- Deployment finalization lets health and source identity settle before refusing a successful rollout.
|
|
7
|
+
- Hosted demos keep the same visitor reservation while Cloudflare prepares an available container, within the existing startup budget. Placement exhaustion returns a clean capacity refusal.
|
|
8
|
+
- Status polling retains a failed start's terminal answer briefly after cleanup, including after Durable Object recovery.
|
|
9
|
+
- Demo image builds load Vite configuration preparation before checking the root Wrangler Worker entry.
|
|
10
|
+
|
|
11
|
+
- Concurrent checkout launches validate server registry state under its transaction lock, avoiding a false foreign-file refusal during atomic updates.
|
|
12
|
+
- A checkout behind the front door serves its run-site preview above the app's assigned port instead of trying privileged ports.
|
|
13
|
+
- Hosted demo image builds use the adapter's declared deploy file, including names other than `deploy.json`.
|
|
14
|
+
- `rer deploy --remove --yes` empties small R2 buckets whose object listing omits pagination metadata. Ambiguous full pages and inconsistent cursors still stop removal.
|
|
15
|
+
- Setup uses a mapped owner-name field and its declared default without requiring a second `displayName`. `--owner-name` supplies that mapped field.
|
|
16
|
+
- Import-kit and portability encode mixed-script D1 bindings and count their UTF-8 and RPC sizes without splitting atomic transactions. Retained import plans are read in bounded pages. Source adopters must refresh both modules and include their shared `d1-transport` dependency before removing an edition's transport wrapper.
|
|
17
|
+
|
|
3
18
|
## 0.2.19
|
|
4
19
|
|
|
5
20
|
- `rer signin [--environment NAME]` uses the credentials that deployed a seed to print a one-time owner sign-in link, valid for 15 minutes. It requires no email delivery, refuses non-owners and used or expired links, and records successful use in the auth audit log.
|
package/global/README.md
CHANGED
|
@@ -6,7 +6,7 @@ checkout always gets the behaviour it was built and tested with.
|
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Install `rer` with one of these commands:
|
|
10
10
|
|
|
11
11
|
```sh
|
|
12
12
|
npx -y @runeditrun/rer cli install # user install in ~/.local/share/rer, launcher ~/.local/bin/rer
|
|
@@ -23,9 +23,10 @@ the package's own `rer cli install`. A failed or refused download leaves the
|
|
|
23
23
|
version you had selected.
|
|
24
24
|
|
|
25
25
|
No installer edits shell profiles. The canonical launcher is `~/.local/bin/rer`.
|
|
26
|
-
|
|
27
|
-
existing
|
|
28
|
-
|
|
26
|
+
Installation creates that directory if needed and never writes into another
|
|
27
|
+
PATH directory. It names any existing `rer` elsewhere on PATH and leaves it
|
|
28
|
+
unchanged. If `~/.local/bin` is absent from PATH or another command shadows it,
|
|
29
|
+
it prints one activation line to run in the current shell:
|
|
29
30
|
`export PATH="$HOME/.local/bin:$PATH"` (with fish syntax for fish). The launcher runs `node` from
|
|
30
31
|
PATH, so a Node upgrade does not break it. A re-run with the same build changes
|
|
31
32
|
nothing; a different build is installed beside the current one, the previous one
|
|
@@ -99,7 +100,6 @@ RER_SIGNED_IN owner@cradle.test
|
|
|
99
100
|
RER_OPEN http://127.0.0.1:8787/__dev/key#...
|
|
100
101
|
```
|
|
101
102
|
|
|
102
|
-
or `RER_SIGN_IN <outbox>` for a seed that signs in through its development outbox.
|
|
103
103
|
A seed that declares a run site prints one more line after those,
|
|
104
104
|
`RER_SITE http://127.0.0.1:8788`: a local preview of its static run site (its
|
|
105
105
|
marketing homepage, `/run` and docs) on the first free port above the app's. It
|
|
@@ -262,7 +262,7 @@ line that still names it. A later refresh is a version bump:
|
|
|
262
262
|
| `@runeditrun/rer/modules/portability`, `/catalogue`, `/cli`, `/cli-options`, `/files`, `/format`, `/http`, `/import`, `/journal`, `/legacy-safety`, `/migration-history`, `/storage` | portability module | `scripts/base-cli/modules/portability/*.mjs` |
|
|
263
263
|
| `@runeditrun/rer/modules/release/export`, `/publication-scan`, `/source`, `/signature` | release export, publication scan and shared signature verifier | `scripts/base-cli/modules/release/*.mjs` |
|
|
264
264
|
| `@runeditrun/rer/modules/deploy-kit/owner`, `/owner-cli`, `/prepare`, `/provider` | deploy kit | `scripts/base-cli/modules/deploy-kit/*.mjs` |
|
|
265
|
-
| `@runeditrun/rer/modules/operator-auth`, `/dev`, `/dev
|
|
265
|
+
| `@runeditrun/rer/modules/operator-auth`, `/dev`, `/dev-admission`, `/accounts/native`, `/identity/email-link` | operator auth | `scripts/base-cli/modules/operator-auth/index.mjs`, `dev/index.mjs`, `dev-admission.mjs`, `accounts/native.mjs`, `identity/email-link/index.mjs` |
|
|
266
266
|
| `@runeditrun/rer/modules/erasure/fence` | erasure fence statements | `scripts/base-cli/modules/erasure/fence.mjs` |
|
|
267
267
|
| `@runeditrun/rer/modules/owner-claim`, `/modules/dependencies` | owner claim, dependency links | `scripts/base-cli/modules/owner-claim/index.mjs`, `dependencies/index.mjs` |
|
|
268
268
|
| `@runeditrun/rer/internal/PATH` | any other package file, for tests | `scripts/base-cli/PATH`, and `scripts/base-onboarding/PATH` with PATH under `onboarding/` |
|
|
@@ -273,7 +273,7 @@ In a checkout, every verb runs that checkout's own pinned `rer`; `rer VERB --hel
|
|
|
273
273
|
there lists its flags:
|
|
274
274
|
|
|
275
275
|
`install`, `setup`, `dev`, `preview`, `build`, `verify`, `reset --yes`, `deploy`,
|
|
276
|
-
`export`, `import`, `
|
|
276
|
+
`export`, `import`, `doctor`, `describe`, `check`, `release`,
|
|
277
277
|
`release sign`, `release receipt` and `release keygen`.
|
|
278
278
|
|
|
279
279
|
Anywhere: `rer list [DIR]`, `rer cli status|install|uninstall`, `rer update`,
|
package/global/cli/install.mjs
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
// version directory, switch `current` atomically, keep the previous version,
|
|
3
3
|
// prune older ones and write the launcher. Never edits shell profiles.
|
|
4
4
|
import { randomUUID } from 'node:crypto';
|
|
5
|
-
import {
|
|
5
|
+
import { chmod, cp, mkdir, readdir, readlink, realpath, rename, rm, symlink, writeFile } from 'node:fs/promises';
|
|
6
6
|
import { basename, join, resolve } from 'node:path';
|
|
7
7
|
import { ownManifest, ownRoot, packageDigest, packageFileList } from '../package-info.mjs';
|
|
8
8
|
import { installRecord, launcherOwner, launcherScript, layout } from './layout.mjs';
|
|
9
|
-
import {
|
|
10
|
-
import { shellQuote } from '../../cli/node-runtime-cache.mjs';
|
|
9
|
+
import { pathAdvice } from './path-link.mjs';
|
|
11
10
|
import { runningDoor } from '../../cli/door.mjs';
|
|
12
11
|
|
|
13
12
|
async function readLink(path) { try { return await readlink(path); } catch (error) { if (['ENOENT', 'EINVAL'].includes(error.code)) return undefined; throw error; } }
|
|
@@ -40,22 +39,6 @@ async function writeLauncher(paths) {
|
|
|
40
39
|
await rename(temporary, paths.launcher);
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
export async function pathAdvice(paths, env = process.env) {
|
|
44
|
-
const entries = (env.PATH ?? '').split(':').filter(Boolean).map(entry => resolve(entry));
|
|
45
|
-
for (const directory of entries) {
|
|
46
|
-
if (directory === resolve(paths.bin)) return undefined;
|
|
47
|
-
const candidate = join(directory, 'rer');
|
|
48
|
-
try {
|
|
49
|
-
await access(candidate, constants.X_OK);
|
|
50
|
-
const found = await launcherOwner(await realpath(candidate));
|
|
51
|
-
if (found.state === 'ours' && found.root === paths.data) return undefined;
|
|
52
|
-
break; // This command shadows the canonical launcher, even if it is later on PATH.
|
|
53
|
-
} catch (error) { if (!['ENOENT', 'EACCES', 'ENOTDIR'].includes(error.code)) throw error; }
|
|
54
|
-
}
|
|
55
|
-
if (basename(env.SHELL ?? '') === 'fish') return `Activate rer in this shell:\n set -gx PATH ${shellQuote(paths.bin)} $PATH`;
|
|
56
|
-
return `Activate rer in this shell:\n export PATH=${shellQuote(paths.bin)}:"$PATH"`;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
42
|
export async function install() {
|
|
60
43
|
const paths = layout(), manifest = ownManifest(), digest = await packageDigest(ownRoot);
|
|
61
44
|
const name = `${manifest.version}-${digest.slice(0, 8)}`, channel = process.env.RER_INSTALL_CHANNEL === 'script' ? 'script' : 'npx';
|
|
@@ -69,7 +52,7 @@ export async function install() {
|
|
|
69
52
|
let present = false;
|
|
70
53
|
try { present = await packageDigest(join(paths.versions, name)) === digest; } catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
71
54
|
if (present && current === join('versions', name) && launcher.text === script && record?.channel === channel) {
|
|
72
|
-
const advice = await
|
|
55
|
+
const advice = await pathAdvice(paths);
|
|
73
56
|
process.stdout.write(`rer ${manifest.version} is already current (${join(paths.versions, name)}). Nothing changed.\n${advice ? advice + '\n' : ''}`);
|
|
74
57
|
return 0;
|
|
75
58
|
}
|
|
@@ -83,14 +66,7 @@ export async function install() {
|
|
|
83
66
|
for (const entry of await readdir(paths.versions)) if (!keep.has(entry) && !entry.startsWith('.staging-')) await rm(join(paths.versions, entry), { recursive: true, force: true });
|
|
84
67
|
await writeFile(paths.record, JSON.stringify({ channel, links: record?.links ?? [], previous: previousName && keep.has(previousName) ? previousName : null }, null, 2) + '\n', { mode: 0o644 });
|
|
85
68
|
if (launcher.text !== script) await writeLauncher(paths);
|
|
86
|
-
const advice = await
|
|
69
|
+
const advice = await pathAdvice(paths);
|
|
87
70
|
process.stdout.write(`Installed rer ${manifest.version} in ${join(paths.versions, name)}.\n${paths.launcher} runs it.${previousName ? ` The previous version (${previousName}) is kept.` : ''}\n${advice ? advice + '\n' : ''}`);
|
|
88
71
|
return 0;
|
|
89
72
|
}
|
|
90
|
-
|
|
91
|
-
async function activation(paths, record) {
|
|
92
|
-
const link = await exposeLauncher(paths);
|
|
93
|
-
const links = [...new Set([...(record?.links ?? []), ...(link ? [link] : [])])];
|
|
94
|
-
if (JSON.stringify(record?.links ?? []) !== JSON.stringify(links)) await writeFile(paths.record, JSON.stringify({ ...record, links }, null, 2) + '\n', { mode: 0o644 });
|
|
95
|
-
return link ? undefined : await pathAdvice(paths);
|
|
96
|
-
}
|
package/global/cli/path-link.mjs
CHANGED
|
@@ -1,30 +1,34 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
import { access, constants, lstat, readlink,
|
|
4
|
-
import {
|
|
1
|
+
// Installation writes only the canonical launcher in ~/.local/bin.
|
|
2
|
+
// Other PATH commands are reported, never replaced or linked alongside.
|
|
3
|
+
import { access, constants, lstat, readlink, stat } from 'node:fs/promises';
|
|
4
|
+
import { basename, delimiter, join, resolve } from 'node:path';
|
|
5
|
+
import { shellQuote } from '../../cli/node-runtime-cache.mjs';
|
|
5
6
|
|
|
7
|
+
// Older installs recorded extra PATH links; uninstall can still remove those.
|
|
6
8
|
export async function ownedPathLink(path, launcher) {
|
|
7
9
|
try { return (await lstat(path)).isSymbolicLink() && (await readlink(path)) === resolve(launcher); }
|
|
8
10
|
catch (error) { if (error.code === 'ENOENT' || error.code === 'EINVAL') return false; throw error; }
|
|
9
11
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
|
|
13
|
+
export async function pathAdvice(paths, env = process.env) {
|
|
14
|
+
const entries = [...new Set((env.PATH ?? '').split(delimiter).map(entry => resolve(entry)))];
|
|
15
|
+
const bin = resolve(paths.bin), lines = [];
|
|
16
|
+
let firstCommand;
|
|
17
|
+
for (const directory of entries) {
|
|
18
|
+
if (directory === bin) { firstCommand ??= paths.launcher; continue; }
|
|
19
|
+
const candidate = join(directory, 'rer');
|
|
14
20
|
try {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return undefined;
|
|
20
|
-
} catch (error) { if (error.code !== 'ENOENT') continue; }
|
|
21
|
-
// npm/npx add transient command directories; never install into them.
|
|
22
|
-
if (!isAbsolute(entry) || directory.split('/').includes('node_modules') || directory.split('/').includes('_npx')) continue;
|
|
23
|
-
const info = await lstat(directory);
|
|
24
|
-
if (!info.isDirectory() || !process.getuid || info.uid !== process.getuid() || (!(info.mode & 0o200) || (info.mode & 0o022))) continue;
|
|
25
|
-
await access(directory, constants.W_OK | constants.X_OK);
|
|
26
|
-
try { await symlink(paths.launcher, candidate); return candidate; }
|
|
27
|
-
catch (error) { if (error.code !== 'EEXIST' && error.code !== 'EACCES' && error.code !== 'EPERM') throw error; }
|
|
21
|
+
await access(candidate, constants.X_OK);
|
|
22
|
+
if (!(await stat(candidate)).isFile()) continue;
|
|
23
|
+
firstCommand ??= candidate;
|
|
24
|
+
lines.push(`Left existing rer at ${candidate} unchanged.`);
|
|
28
25
|
} catch (error) { if (!['ENOENT', 'EACCES', 'ENOTDIR'].includes(error.code)) throw error; }
|
|
29
26
|
}
|
|
27
|
+
if (!entries.includes(bin) || firstCommand !== paths.launcher) {
|
|
28
|
+
const command = basename(env.SHELL ?? '') === 'fish'
|
|
29
|
+
? `set -gx PATH ${shellQuote(paths.bin)} $PATH`
|
|
30
|
+
: `export PATH=${shellQuote(paths.bin)}:"$PATH"`;
|
|
31
|
+
lines.push(`Add ~/.local/bin to PATH in this shell: ${command}`);
|
|
32
|
+
}
|
|
33
|
+
return lines.join('\n');
|
|
30
34
|
}
|
package/global/launch/dev.mjs
CHANGED
|
@@ -42,7 +42,7 @@ export async function launchDev(target) {
|
|
|
42
42
|
catch (failure) { if (!(failure instanceof LaunchFailure)) throw failure; process.stderr.write(failure.message + '\n'); return failure.exitCode; }
|
|
43
43
|
}
|
|
44
44
|
const here = await realpath(process.cwd()).catch(() => undefined);
|
|
45
|
-
const out = printer({ json: devArgs.includes('--json'),
|
|
45
|
+
const out = printer({ json: devArgs.includes('--json'), stopHint: `rer dev --stop${here === checkout ? '' : ` --cwd ${JSON.stringify(checkout)}`}`, keyless: doorStart });
|
|
46
46
|
const detach = args.includes('--detach') || (!args.includes('--foreground') && !process.stdout.isTTY);
|
|
47
47
|
return detach ? detached(target, devArgs, directory, out, doorStart) : foreground(target, devArgs, directory, out, doorStart);
|
|
48
48
|
}
|
package/global/launch/facts.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// What a launch needs to know about a checkout before it changes anything.
|
|
2
2
|
import { execFile } from 'node:child_process';
|
|
3
3
|
import { stat } from 'node:fs/promises';
|
|
4
|
-
import { createServer } from 'node:net';
|
|
5
4
|
import { join } from 'node:path';
|
|
6
5
|
import { promisify } from 'node:util';
|
|
7
|
-
import {
|
|
6
|
+
import { inspectionContext } from '../../onboarding/process-diagnostics.mjs';
|
|
7
|
+
import { probePort } from '../../onboarding/port-probe.mjs';
|
|
8
8
|
import { LaunchFailure } from './failure.mjs';
|
|
9
9
|
|
|
10
10
|
const run = promisify(execFile);
|
|
@@ -64,16 +64,9 @@ export async function setupNeeded(root, described, last) {
|
|
|
64
64
|
return await finishedSince(root, described, last.at) ? undefined : 'resume';
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
const socket = createServer();
|
|
69
|
-
try { await new Promise((resolve, reject) => { socket.once('error', reject); socket.listen({ port, host, exclusive: true }, resolve); }); return true; }
|
|
70
|
-
catch (error) { return host === '::1' && ['EADDRNOTAVAIL', 'EAFNOSUPPORT'].includes(error.code); }
|
|
71
|
-
finally { if (socket.listening) await new Promise(resolve => socket.close(resolve)); }
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Whether something now listens on a port or keeps it from binding.
|
|
67
|
+
// Only a positive listener observation justifies saying another process took it.
|
|
75
68
|
export async function portTaken(port) {
|
|
76
|
-
return (
|
|
69
|
+
return Boolean((await probePort('127.0.0.1', port, { hosts: ['127.0.0.1', '::1'], anyAddress: true })).listener);
|
|
77
70
|
}
|
|
78
71
|
|
|
79
72
|
// The first port from 8787 (RER_DEV_PORT_FROM moves the start) that is not
|
|
@@ -84,10 +77,14 @@ export async function portTaken(port) {
|
|
|
84
77
|
export async function freePort(ports, claim, env = process.env) {
|
|
85
78
|
const from = Number(env.RER_DEV_PORT_FROM ?? 8787);
|
|
86
79
|
if (!Number.isInteger(from) || from < 1 || from > 65535) throw new LaunchFailure(2, 'RER_DEV_PORT_FROM must be a port number.');
|
|
87
|
-
const held = new Set(ports.filter(Boolean)),
|
|
80
|
+
const held = new Set(ports.filter(Boolean)), context = inspectionContext();
|
|
88
81
|
for (let port = from; port <= 65535; port++) {
|
|
89
|
-
if (held.has(port)
|
|
90
|
-
|
|
82
|
+
if (held.has(port)) continue;
|
|
83
|
+
const result = await probePort('127.0.0.1', port, { context, hosts: ['127.0.0.1', '::1'], anyAddress: true });
|
|
84
|
+
if (!result.available) {
|
|
85
|
+
if (performance.now() >= context.deadline) throw new LaunchFailure(4, `Could not find a free port from ${from} in time (system busy). Run rer dev again or pass rer dev --port PORT with a free port.`);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
91
88
|
const claimed = await claim(port);
|
|
92
89
|
if (claimed) return { port, ...claimed };
|
|
93
90
|
}
|
|
@@ -1,5 +1,25 @@
|
|
|
1
|
+
import { createRedaction, credentialValues } from '../../onboarding/redaction.mjs';
|
|
2
|
+
|
|
1
3
|
// A launch that stops with the dispatcher's own message (or the launcher's)
|
|
2
4
|
// and exit code. `event` keeps the dispatcher's JSON error event when it sent one.
|
|
3
5
|
export class LaunchFailure extends Error {
|
|
4
6
|
constructor(exitCode, message, event) { super(message); this.exitCode = exitCode; this.event = event; }
|
|
5
7
|
}
|
|
8
|
+
|
|
9
|
+
// Native errors have no dispatcher exit code, but their message is still the
|
|
10
|
+
// cause of this launch's failure. Redact before transporting it to followers;
|
|
11
|
+
// a JSON caller must receive the same cause and recovery as a terminal caller.
|
|
12
|
+
export function workerFailure(error, { root, env = process.env }) {
|
|
13
|
+
const redaction = createRedaction();
|
|
14
|
+
redaction.addSecrets([...credentialValues(env), ...credentialValues(error?.event)]);
|
|
15
|
+
const redact = text => redaction.redact(String(text).replace(/([#&]rer-dev=)[^&\s"'<>]+/g, '$1[REDACTED]'));
|
|
16
|
+
const clean = value => typeof value === 'string' ? redact(value)
|
|
17
|
+
: Array.isArray(value) ? value.map(clean)
|
|
18
|
+
: value && typeof value === 'object' ? Object.fromEntries(Object.entries(value).map(([key, item]) => [key, clean(item)])) : value;
|
|
19
|
+
const exitCode = Number.isInteger(error?.exitCode) && error.exitCode > 0 && error.exitCode <= 255 ? error.exitCode : 1;
|
|
20
|
+
const cause = redact(error?.message || error || 'The launch stopped before the app was ready.');
|
|
21
|
+
const retry = `rer dev --cwd '${root.replaceAll("'", "'\\''")}'`;
|
|
22
|
+
const message = `${cause}\nCorrect the cause, then run ${retry} again.`;
|
|
23
|
+
const event = { version: 1, verb: 'dev', event: 'error', code: 'launch_failed', ...clean(error?.event), message, exitCode };
|
|
24
|
+
return new LaunchFailure(exitCode, message, event);
|
|
25
|
+
}
|
package/global/launch/render.mjs
CHANGED
|
@@ -5,7 +5,7 @@ const quiet = 20000;
|
|
|
5
5
|
|
|
6
6
|
// `keyless` (a start by the front door, whose log this is): the ready lines
|
|
7
7
|
// leave out the dev-key link, so the door's files never hold a key.
|
|
8
|
-
export function printer({ json,
|
|
8
|
+
export function printer({ json, stopHint, keyless = false }) {
|
|
9
9
|
const started = Date.now();
|
|
10
10
|
let current = 'preparing', last = Date.now();
|
|
11
11
|
const event = (name, fields) => process.stdout.write(JSON.stringify({ version: 1, verb: 'dev', event: name, ...fields }) + '\n');
|
|
@@ -24,13 +24,9 @@ export function printer({ json, login, stopHint, keyless = false }) {
|
|
|
24
24
|
if (keyless) { const { openUrl, ...rest } = ready; ready = rest; }
|
|
25
25
|
if (json) { event('server', { pid, log }); process.stdout.write(JSON.stringify(ready) + '\n'); return; }
|
|
26
26
|
const out = [`RER_READY ${ready.url}`];
|
|
27
|
-
if (ready.openUrl
|
|
27
|
+
if (ready.openUrl) {
|
|
28
28
|
if (ready.signedInAs) out.push(`RER_SIGNED_IN ${ready.signedInAs}`);
|
|
29
29
|
out.push(`RER_OPEN ${ready.openUrl}`, 'Open that link on this computer. Its fragment holds this checkout\'s dev key, which the page keeps only as a cookie; never share the link.');
|
|
30
|
-
} else if (ready.signInUrl) {
|
|
31
|
-
out.push(`RER_SIGN_IN ${ready.signInUrl}`);
|
|
32
|
-
if (ready.openUrl) out.push(`RER_OPEN ${ready.openUrl}`);
|
|
33
|
-
out.push(`Open ${ready.openUrl ? 'the last link on this computer (it carries the dev key; never share it)' : 'the outbox'}, choose the newest sign-in message and follow its link. No email was sent.`);
|
|
34
30
|
}
|
|
35
31
|
// A seed with a run site: its static homepage, /run and docs, served locally.
|
|
36
32
|
if (ready.siteUrl) out.push(`RER_SITE ${ready.siteUrl}`);
|
package/global/launch/worker.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import { realpath } from 'node:fs/promises';
|
|
|
11
11
|
import { join } from 'node:path';
|
|
12
12
|
import { processInfo } from '../../modules/job-queue/processes.mjs';
|
|
13
13
|
import { liveServers } from '../registry.mjs';
|
|
14
|
-
import { LaunchFailure } from './failure.mjs';
|
|
14
|
+
import { LaunchFailure, workerFailure } from './failure.mjs';
|
|
15
15
|
import { prepare } from './prepare.mjs';
|
|
16
16
|
import { claimLaunch, eventLog, launchDirectory, liveWorker, releaseLaunch, serverRecord, stopRequest } from './state.mjs';
|
|
17
17
|
import { startServer } from './steps.mjs';
|
|
@@ -53,8 +53,8 @@ if (!await claimLaunch(directory, token)) {
|
|
|
53
53
|
await events.write({ event: 'ready', ready: started.ready, pid, ...(ours ? { log: serverLog } : {}) });
|
|
54
54
|
} catch (error) {
|
|
55
55
|
log(String(error?.stack ?? error));
|
|
56
|
-
const failure = stopping.signal.aborted ? new LaunchFailure(1, 'rer dev --stop stopped this launch before the app was ready.') : error;
|
|
57
|
-
await events.write({ event: 'failed', exitCode: failure.exitCode
|
|
56
|
+
const failure = workerFailure(stopping.signal.aborted ? new LaunchFailure(1, 'rer dev --stop stopped this launch before the app was ready.') : error, { root });
|
|
57
|
+
await events.write({ event: 'failed', exitCode: failure.exitCode, message: failure.message, error: failure.event });
|
|
58
58
|
} finally {
|
|
59
59
|
await releaseLaunch(directory, token);
|
|
60
60
|
logFile.end();
|
package/global/main.mjs
CHANGED
|
@@ -31,7 +31,7 @@ pins (installed first by any verb when node_modules holds another), else its ven
|
|
|
31
31
|
of a checkout that pins the rer package use it).
|
|
32
32
|
|
|
33
33
|
Checkout verbs: install, setup, dev, demo, preview, build, verify, reset, deploy, signin, export,
|
|
34
|
-
import,
|
|
34
|
+
import, doctor, describe, check, release. Run rer VERB --help in a checkout for its flags.
|
|
35
35
|
`;
|
|
36
36
|
|
|
37
37
|
// The checkout verbs that install the pinned package before they run when
|
|
@@ -18,9 +18,11 @@ async function buildImage(root, { output = join(root,'.rer/container/image'), en
|
|
|
18
18
|
declaration ??= JSON.parse(await readFile(join(root,'deploy.json'),'utf8'));
|
|
19
19
|
engine ??= declaration.container?.engine ?? 'workerd'; cacheContract ??= declaration.container?.cacheContract; runner ??= declaration.container?.runner;
|
|
20
20
|
if (!['workerd','node'].includes(engine)) throw new Error('Unsupported container engine');
|
|
21
|
-
await checkBoundary(root,{engine,cacheContract});
|
|
22
21
|
const vite = await import(pathToFileURL(require.resolve('vite'))), loaded = await vite.loadConfigFromFile({ command:'build',mode:'production' },undefined,root);
|
|
23
22
|
if (!loaded) throw new Error('Vite configuration missing');
|
|
23
|
+
// Config loading may prepare the seed's root Wrangler configuration. Inspect
|
|
24
|
+
// its declared entry after that preparation, still before compiling the app.
|
|
25
|
+
await checkBoundary(root,{engine,cacheContract});
|
|
24
26
|
const config = loaded.config;
|
|
25
27
|
const outputExports = new Map();
|
|
26
28
|
const freshServerFiles = new Set(), serverOutput = resolve(root,'dist/server');
|
|
@@ -86,10 +88,10 @@ async function buildImage(root, { output = join(root,'.rer/container/image'), en
|
|
|
86
88
|
for (const path of runner.files) await cp(within(path),join(output,'app/runner',path),{recursive:true,filter:path => !path.includes('/tests/') && !path.endsWith('/synthetic.mjs')});
|
|
87
89
|
}
|
|
88
90
|
const base = resolve(import.meta.dirname,'../..');
|
|
89
|
-
for (const path of ['modules/container','modules/portability','modules/deploy-kit','cli/scheduled.mjs','cli/jsonc.mjs','modules/integrations/core/public-address.ts']) { await mkdir(join(output,'runtime',path,'..'),{recursive:true}); await cp(join(base,path),join(output,'runtime',path),{recursive:true,filter:path => !path.includes('/tests/')}); }
|
|
91
|
+
for (const path of ['modules/container','modules/portability','modules/d1-transport','modules/deploy-kit','cli/scheduled.mjs','cli/jsonc.mjs','modules/integrations/core/public-address.ts']) { await mkdir(join(output,'runtime',path,'..'),{recursive:true}); await cp(join(base,path),join(output,'runtime',path),{recursive:true,filter:path => !path.includes('/tests/')}); }
|
|
90
92
|
const dependencies = engine === 'workerd' ? { miniflare:'5.20260907.0-alpha' } : {};
|
|
91
93
|
await writeFile(join(output,'runtime/package.json'),JSON.stringify({private:true,type:'module',dependencies}));
|
|
92
94
|
await writeFile(join(output,'Dockerfile'),`FROM node:26.8.1-bookworm-slim\nRUN apt-get update && apt-get install -y --no-install-recommends util-linux ca-certificates && apt-get clean\nRUN mkdir -p /private /archive\nWORKDIR /runtime\nCOPY runtime/package.json ./package.json\nRUN npm install --omit=dev --no-audit --no-fund\nCOPY runtime/ /runtime/\nCOPY app/ /app/\nENV NODE_ENV=production PORT=8080 WRANGLER_SEND_METRICS=false\nEXPOSE 8080\nVOLUME /data\nENTRYPOINT ["sh", "/runtime/modules/container/entrypoint.sh"]\n`);
|
|
93
95
|
return { output,manifest };
|
|
94
96
|
}
|
|
95
|
-
if (process.argv[1] === import.meta.filename) { try { const {output,engine}=JSON.parse(process.argv[3]??'{}'),result=await buildContainer(resolve(process.argv[2]),{...(output?{output:resolve(output)}:{}),...(engine?{engine}:{})}); console.log(JSON.stringify({output:result.output,engine:result.manifest.engine})); } catch(cause) { console.error(cause.message); if(cause.failures)console.error(JSON.stringify(cause.failures));process.exitCode=1; } }
|
|
97
|
+
if (process.argv[1] === import.meta.filename) { try { const {output,engine,declaration}=JSON.parse(process.argv[3]??'{}'),result=await buildContainer(resolve(process.argv[2]),{...(output?{output:resolve(output)}:{}),...(engine?{engine}:{}),...(declaration?{declaration}:{})}); console.log(JSON.stringify({output:result.output,engine:result.manifest.engine})); } catch(cause) { console.error(cause.message); if(cause.failures)console.error(JSON.stringify(cause.failures));process.exitCode=1; } }
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Public-address filtering and TLS belong to NETWORK. Demo's application guard
|
|
2
|
+
// simulates effects on people/accounts; this is defense for direct transports.
|
|
3
|
+
const transports = new Set([
|
|
4
|
+
'api.sendgrid.com', 'api.resend.com', 'api.twilio.com',
|
|
5
|
+
'api.mailgun.net', 'api.eu.mailgun.net', 'api.postmarkapp.com',
|
|
6
|
+
]);
|
|
7
|
+
const mailPorts = new Set(['25', '465', '587', '2525']);
|
|
8
|
+
|
|
9
|
+
function check(url) {
|
|
10
|
+
const host = url.hostname.toLowerCase().replace(/\.$/, '');
|
|
11
|
+
if (transports.has(host) || mailPorts.has(url.port)) throw new TypeError('Demo direct messaging transport refused');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
async fetch(request, env) {
|
|
16
|
+
if (env.RER_DEMO !== '1') return env.NETWORK.fetch(request);
|
|
17
|
+
const redirect = request.redirect;
|
|
18
|
+
for (let hops = 0; ; hops++) {
|
|
19
|
+
const url = new URL(request.url);
|
|
20
|
+
check(url);
|
|
21
|
+
// Check every redirect before contacting its destination, including when
|
|
22
|
+
// an otherwise public URL redirects into a messaging provider.
|
|
23
|
+
const response = await env.NETWORK.fetch(new Request(request.clone(), { redirect: 'manual' }));
|
|
24
|
+
const location = response.headers.get('location');
|
|
25
|
+
if (![301, 302, 303, 307, 308].includes(response.status) || location === null || redirect === 'manual') return response;
|
|
26
|
+
await response.body?.cancel();
|
|
27
|
+
if (redirect === 'error' || hops === 20) throw new TypeError('Demo egress redirect refused');
|
|
28
|
+
const next = new URL(location, url), headers = new Headers(request.headers);
|
|
29
|
+
const get = response.status === 303 && !['GET', 'HEAD'].includes(request.method) || [301, 302].includes(response.status) && request.method === 'POST';
|
|
30
|
+
if (get) for (const name of ['content-type', 'content-length', 'content-encoding', 'content-language', 'content-location']) headers.delete(name);
|
|
31
|
+
if (next.origin !== url.origin) for (const name of ['authorization', 'cookie', 'proxy-authorization']) headers.delete(name);
|
|
32
|
+
request = new Request(next, { method: get ? 'GET' : request.method, headers, body: get ? null : request.body, redirect, signal: request.signal, duplex: 'half' });
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
};
|
|
@@ -19,9 +19,9 @@ export async function workerEngine({ root, data, manifest, settings, edge }) {
|
|
|
19
19
|
};
|
|
20
20
|
const mf = new Miniflare(convertV4MiniflareOptions({ host:'127.0.0.1',port:0,cf:false,resourcePersistencePath:data,unsafeLocalExplorer:false,
|
|
21
21
|
workers:[{ name:'ingress',modules:true,script:`export default {fetch(request,env){const observed=request.headers.get('x-rer-original-url');if(!observed)return new Response(null,{status:400});const url=new URL(observed),headers=new Headers(request.headers);headers.delete('x-rer-original-url');headers.set('host',url.host);return env.APP.fetch(new Request(url,{method:request.method,headers,redirect:'manual',...(!['GET','HEAD'].includes(request.method)?{body:request.body}:{})}))}}`,serviceBindings:{ APP:'app' } }, app,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
{ name:'egress',modules:[{ type:'ESModule',path:join(import.meta.dirname,'demo-egress.mjs') }],modulesRoot:import.meta.dirname,
|
|
23
|
+
bindings:{ RER_DEMO:settings.RER_DEMO ?? '' },
|
|
24
|
+
serviceBindings:{ NETWORK:{ network:{ allow:['public'],tlsOptions:{ trustBrowserCas:true,trustedCertificates:[...rootCertificates] } } } } }],
|
|
25
25
|
}));
|
|
26
26
|
await mf.ready; const databases = {}, objects = {};
|
|
27
27
|
for (const [binding, plan] of Object.entries(manifest.migrations)) { const db = await mf.getD1Database(binding, 'app'); databases[binding] = db; await migrate(db, plan); await ensurePortabilitySchema(db, manifest.portabilityMigrations); }
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface Sql { sql: string; params?: any[] }
|
|
2
|
+
export const RPC_LIMIT: number;
|
|
3
|
+
export function wireSql(statement: Sql): { sql: string; params: any[] };
|
|
4
|
+
export function wireBatch(statements: Sql[]): Sql[];
|
|
5
|
+
export function rpcBytes(statements: Sql[]): number;
|
|
6
|
+
export interface RpcSize { utf8: number; units: number; hasWide: boolean }
|
|
7
|
+
export function rpcSize(statements: Sql[]): RpcSize;
|
|
8
|
+
export function rpcSizeBytes(size: RpcSize): number;
|
|
9
|
+
export function wireDatabase<T extends { prepare(sql: string): any; batch(statements: any[]): Promise<any> }>(database: T): T;
|