@runeditrun/rer 0.2.78 → 0.2.80
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 +17 -3
- package/cli/README.md +25 -13
- package/cli/authoring.mjs +14 -0
- package/cli/contract.mjs +25 -5
- package/cli/demo-host.mjs +4 -2
- package/cli/dev-identity.mjs +2 -2
- package/cli/export.mjs +1 -1
- package/cli/inspect.mjs +38 -2
- package/cli/main.mjs +8 -2
- package/cli/managed-server.mjs +1 -1
- package/cli/parse.mjs +7 -6
- package/cli/portability-worker.mjs +2 -1
- package/cli/portability.mjs +6 -2
- package/cli/production-auth.mjs +2 -1
- package/cli/production-mail.mjs +36 -9
- package/cli/project.mjs +5 -14
- package/cli/release.mjs +2 -1
- package/cli/server-proxy.mjs +30 -8
- package/cli/site-preview.mjs +4 -1
- package/cli/site.mjs +3 -2
- package/cli/upstream-agent.mjs +14 -0
- package/edition-authoring/adopt.mjs +39 -0
- package/edition-authoring/base-acknowledgements.mjs +24 -0
- package/edition-authoring/base-copies.mjs +418 -0
- package/edition-authoring/cli.mjs +85 -0
- package/edition-authoring/copy-checkout.mjs +69 -0
- package/edition-authoring/files.mjs +15 -2
- package/edition-authoring/lock.mjs +48 -0
- package/edition-authoring/offline-git.mjs +28 -0
- package/edition-authoring/parent-comparison.mjs +77 -0
- package/edition-authoring/projection-lock.mjs +38 -0
- package/edition-authoring/release.mjs +48 -0
- package/edition-authoring/sources.mjs +114 -0
- package/edition-authoring/updates.mjs +105 -0
- package/global/CHANGELOG.md +17 -0
- package/global/README.md +17 -3
- package/global/cli/install.mjs +3 -1
- package/global/main.mjs +9 -12
- package/modules/container/build.mjs +1 -1
- package/modules/d1-transport/index.mjs +68 -21
- package/modules/demo/README.md +8 -2
- package/modules/demo/declaration.mjs +21 -0
- package/modules/demo/input-path.mjs +18 -0
- package/modules/demo/label.d.mts +1 -1
- package/modules/demo/label.mjs +10 -5
- package/modules/demo/navigation.mjs +32 -0
- package/modules/demo/run-url.mjs +9 -0
- package/modules/demo/vite.d.mts +7 -2
- package/modules/demo/vite.mjs +17 -2
- package/modules/demo-host/README.md +5 -3
- package/modules/demo-host/native/visitor.mjs +1 -1
- package/modules/demo-host/page-style.mjs +2 -2
- package/modules/demo-host/pages.mjs +3 -3
- package/modules/demo-host/plan.mjs +6 -4
- package/modules/demo-host/theme.mjs +5 -2
- package/modules/deploy-kit/README.md +19 -15
- package/modules/deploy-kit/owner-cli.mjs +1 -1
- package/modules/deploy-kit/readiness-window.mjs +3 -3
- package/modules/erasure/README.md +10 -5
- package/modules/import-kit/src/d1/README.md +15 -9
- package/modules/import-kit/src/d1/apply.ts +10 -6
- package/modules/import-kit/src/d1/atomic-prefix.ts +64 -0
- package/modules/import-kit/src/d1/budget.ts +48 -26
- package/modules/import-kit/src/d1/compressed-plan.ts +9 -2
- package/modules/import-kit/src/d1/database.ts +2 -1
- package/modules/import-kit/src/d1/jobs.ts +2 -1
- package/modules/import-kit/src/d1/plans.ts +4 -2
- package/modules/import-kit/src/d1/verified-plan.ts +63 -0
- package/modules/integrations/core/README.md +2 -2
- package/modules/mail/README.md +4 -3
- package/modules/mail/pnpm-lock.yaml +16 -0
- package/modules/operator-auth/accounts/native.mjs +3 -1
- package/modules/operator-auth/accounts/provider-control.mjs +7 -4
- package/modules/operator-auth/accounts/provider-setup.mjs +34 -0
- package/modules/operator-auth/accounts/settings-page.mjs +13 -4
- package/modules/operator-auth/conformance/README.md +1 -1
- package/modules/operator-auth/dev/index.mjs +22 -4
- package/modules/operator-auth/dev/refusal.mjs +19 -0
- package/modules/operator-auth/docs/README.md +6 -5
- package/modules/operator-auth/docs/tanstack-start.md +1 -1
- package/modules/operator-auth/docs/vite-spa.md +5 -6
- package/modules/operator-auth/index.d.mts +1 -1
- package/modules/operator-auth/page.mjs +14 -0
- package/modules/operator-auth/representation.mjs +83 -0
- package/modules/operator-auth/routes.mjs +25 -2
- package/modules/portability/README.md +91 -14
- package/modules/portability/bookkeeping.mjs +3 -3
- package/modules/portability/bridge.mjs +5 -4
- package/modules/portability/catalogue.mjs +12 -8
- package/modules/portability/cli.mjs +5 -1
- package/modules/portability/export.mjs +5 -11
- package/modules/portability/format.mjs +7 -1
- package/modules/portability/http-errors.mjs +51 -0
- package/modules/portability/http.mjs +4 -1
- package/modules/portability/import-lease.mjs +13 -2
- package/modules/portability/import.mjs +10 -0
- package/modules/portability/index.d.mts +3 -0
- package/modules/portability/references.mjs +20 -0
- package/modules/portability/schema-identity.mjs +13 -0
- package/modules/portability/schema-legacy.mjs +21 -0
- package/modules/portability/sqlite-tokens.mjs +121 -0
- package/modules/release/README.md +20 -9
- package/modules/release/github-verify.mjs +30 -9
- package/modules/site/docs-search/search.css +1 -1
- package/onboarding/README.md +16 -4
- package/onboarding/adapter.mjs +5 -1
- package/onboarding/schema/SETUP.schema.json +26 -1
- package/onboarding/schema/business-field-inputs.mjs +37 -0
- package/onboarding/schema/json-schema.mjs +6 -2
- package/onboarding/schema/setup-validation.mjs +20 -3
- package/onboarding/server.mjs +1 -1
- package/onboarding/setup-manifest.mjs +2 -0
- package/onboarding/start-origin-diagnostic.mjs +24 -0
- package/onboarding/ui/style.css +9 -9
- package/package.json +1 -1
- package/scripts/publish-check/README.md +1 -1
|
@@ -26,7 +26,7 @@ function parameters(sql) {
|
|
|
26
26
|
* and decoded in SQLite. Stored values and transaction boundaries are unchanged.
|
|
27
27
|
* Values whose encoding exceeds D1's bind ceiling remain native; rpcBytes then
|
|
28
28
|
* accounts for their effect on the ENTIRE call, never just that parameter. */
|
|
29
|
-
|
|
29
|
+
function encodeSql(statement) {
|
|
30
30
|
const { sql, params = [] } = statement;
|
|
31
31
|
if (!params.some(value => typeof value === 'string' && wide.test(value))) return { sql, params };
|
|
32
32
|
const tokens = parameters(sql), values = [...params], replacements = new Set();
|
|
@@ -57,33 +57,78 @@ export function wireSql(statement) {
|
|
|
57
57
|
return result;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
// Weak keys retain work only while the caller retains a statement. Snapshots
|
|
61
|
+
// validate replaced arrays and in-place changes; mutable binding objects bypass
|
|
62
|
+
// reuse because their JSON representation can change without changing identity.
|
|
63
|
+
const representations = new WeakMap();
|
|
64
|
+
const primitive = value => value === null || !['object', 'function'].includes(typeof value);
|
|
65
|
+
function representation(statement) {
|
|
66
|
+
const { sql, params = [] } = statement;
|
|
67
|
+
if (typeof sql !== 'string' || !Array.isArray(params) || !params.every(primitive)) return { sql, params };
|
|
68
|
+
const prior = representations.get(statement);
|
|
69
|
+
if (prior && prior.sql === sql && prior.params.length === params.length && params.every((value, index) => Object.is(value, prior.params[index]))) return prior;
|
|
70
|
+
const current = { sql, params: [...params] };
|
|
71
|
+
representations.set(statement, current);
|
|
72
|
+
return current;
|
|
73
|
+
}
|
|
74
|
+
const encoded = record => record.encoded ??= encodeSql(record);
|
|
75
|
+
function publicQuery(record, statement) {
|
|
76
|
+
const query = encoded(record);
|
|
77
|
+
// Public callers may mutate returned SQL and bindings. Never expose cached
|
|
78
|
+
// encoded state; retain the native parameter alias when no encoding occurred.
|
|
79
|
+
const result = { sql: query.sql, params: query.params === record.params ? statement.params ?? [] : [...query.params] };
|
|
80
|
+
if (result.params.every(primitive)) representations.set(result, { sql: result.sql, params: [...result.params], rawSize: record.encodedSize });
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
export function wireSql(statement) { return publicQuery(representation(statement), statement); }
|
|
84
|
+
|
|
60
85
|
/** A conservative size of D1's JSON request plus RPC envelope. A single wide
|
|
61
86
|
* character makes workerd serialize every UTF-16 code unit in the call at two
|
|
62
87
|
* bytes. UTF-8 also matters independently for provider payload limits. */
|
|
63
|
-
|
|
64
|
-
let utf8 =
|
|
88
|
+
function contribution(statement) {
|
|
89
|
+
let utf8 = 0, units = 0, hasWide = false;
|
|
65
90
|
const add = text => { utf8 += bytes(text); units += text.length; hasWide ||= wide.test(text); };
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
91
|
+
add('{"sql":' + JSON.stringify(statement.sql) + ',"params":[');
|
|
92
|
+
for (const value of statement.params ?? []) {
|
|
93
|
+
if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) {
|
|
94
|
+
// D1 sends binary bindings as numeric arrays. Four bytes per element is
|
|
95
|
+
// conservative and avoids constructing a second large byte array.
|
|
96
|
+
const size = 3 + value.byteLength * 4; utf8 += size; units += size;
|
|
97
|
+
} else add(JSON.stringify(value) + ',');
|
|
98
|
+
}
|
|
99
|
+
add(']},');
|
|
100
|
+
return { utf8, units, hasWide };
|
|
101
|
+
}
|
|
102
|
+
function combined(records, encode = false) {
|
|
103
|
+
let utf8 = 2, units = 2, hasWide = false;
|
|
104
|
+
for (const record of records) {
|
|
105
|
+
let size;
|
|
106
|
+
if (encode) {
|
|
107
|
+
const query = encoded(record);
|
|
108
|
+
size = record.encodedSize ??= query.params === record.params ? record.rawSize ??= contribution(record) : contribution(query);
|
|
109
|
+
} else size = record.rawSize ??= contribution(record);
|
|
110
|
+
utf8 += size.utf8; units += size.units; hasWide ||= size.hasWide;
|
|
76
111
|
}
|
|
77
112
|
return { utf8, units, hasWide };
|
|
78
113
|
}
|
|
114
|
+
export function rpcSize(statements) { return combined(statements.map(representation)); }
|
|
79
115
|
export const rpcSizeBytes = ({ utf8, units, hasWide }) => 4096 + Math.max(utf8, units * (hasWide ? 2 : 1));
|
|
80
116
|
export const rpcBytes = statements => rpcSizeBytes(rpcSize(statements));
|
|
81
117
|
|
|
82
|
-
|
|
83
|
-
const
|
|
118
|
+
function selectBatch(statements) {
|
|
119
|
+
const records = statements.map(representation), queries = records.map(encoded);
|
|
120
|
+
const nativeBytes = rpcSizeBytes(combined(records)), encodedBytes = rpcSizeBytes(combined(records, true));
|
|
84
121
|
// Dense CJK may be smaller as native two-byte text than as six-byte escapes.
|
|
85
|
-
//
|
|
86
|
-
return
|
|
122
|
+
// One wide value affects the complete call; ties retain encoded selection.
|
|
123
|
+
return nativeBytes < encodedBytes ? { queries: statements, bytes: nativeBytes, encoded: false, records } : { queries, bytes: encodedBytes, encoded: true, records };
|
|
124
|
+
}
|
|
125
|
+
export function wireBatch(statements) {
|
|
126
|
+
const selection = selectBatch(statements);
|
|
127
|
+
return selection.encoded ? selection.records.map((record, index) => publicQuery(record, statements[index])) : statements;
|
|
128
|
+
}
|
|
129
|
+
function sameQuery(left, right) {
|
|
130
|
+
const a = left.params ?? [], b = right.params ?? [];
|
|
131
|
+
return left.sql === right.sql && a.length === b.length && a.every((value, index) => primitive(value) && Object.is(value, b[index]));
|
|
87
132
|
}
|
|
88
133
|
|
|
89
134
|
/** Adapt only D1's prepare/batch boundary; native statements supplied by a
|
|
@@ -91,7 +136,7 @@ export function wireBatch(statements) {
|
|
|
91
136
|
export function wireDatabase(db) {
|
|
92
137
|
const statements = new WeakMap();
|
|
93
138
|
const prepare = (sql, params = []) => {
|
|
94
|
-
const original = { sql, params },
|
|
139
|
+
const original = { sql, params }, selection = selectBatch([original]), query = selection.queries[0];
|
|
95
140
|
const native = params.length ? db.prepare(query.sql).bind(...query.params) : db.prepare(sql);
|
|
96
141
|
const wrapped = new Proxy(native, { get(target, key) {
|
|
97
142
|
if (key === 'bind') return (...values) => prepare(sql, values);
|
|
@@ -102,19 +147,21 @@ export function wireDatabase(db) {
|
|
|
102
147
|
};
|
|
103
148
|
return typeof value === 'function' ? value.bind(target) : value;
|
|
104
149
|
} });
|
|
105
|
-
statements.set(wrapped, { native, query, original });
|
|
150
|
+
statements.set(wrapped, { native, query: { sql: query.sql, params: [...query.params] }, original });
|
|
106
151
|
return wrapped;
|
|
107
152
|
};
|
|
108
153
|
return new Proxy(db, { get(target, key) {
|
|
109
154
|
if (key === 'prepare') return prepare;
|
|
110
155
|
if (key === 'batch') return members => {
|
|
111
156
|
const known = members.map(member => statements.get(member));
|
|
112
|
-
const
|
|
113
|
-
|
|
157
|
+
const selection = selectBatch(known.filter(Boolean).map(member => member.original));
|
|
158
|
+
const queries = selection.queries;
|
|
159
|
+
if (selection.bytes > RPC_LIMIT) throw new Error('D1_RPC_TRANSPORT_LIMIT');
|
|
114
160
|
let index = 0;
|
|
115
161
|
return db.batch(members.map((member, i) => {
|
|
116
162
|
if (!known[i]) return member;
|
|
117
163
|
const query = queries[index++];
|
|
164
|
+
if (sameQuery(query, known[i].query)) return known[i].native;
|
|
118
165
|
return query.params?.length ? db.prepare(query.sql).bind(...query.params) : db.prepare(query.sql);
|
|
119
166
|
}));
|
|
120
167
|
};
|
package/modules/demo/README.md
CHANGED
|
@@ -28,11 +28,17 @@ Production build/deploy refuses that setting; ordinary builds keep real effects.
|
|
|
28
28
|
Put `data-rer-name` on the product's text label, for example
|
|
29
29
|
`<span data-rer-name>Uptime</span>`, to show **Uptime Demo** in its nav.
|
|
30
30
|
The same attribute shows **Uptime Dev** under the local dev wrapper. No bar,
|
|
31
|
-
layout offset or timer is injected.
|
|
31
|
+
layout offset or timer is injected. In demo mode a **Run <Seed>** link sits
|
|
32
|
+
beside each marked navigation label and opens `https://<domain>/run`. The
|
|
33
|
+
existing `demoSockets()` Vite plugin supplies the public `name` and canonical
|
|
34
|
+
run-site `domain` from `deploy-demo.json` and the command adapter's
|
|
35
|
+
`site.declaration` (normally `deploy-site.json`); an explicit HTTPS `/run`
|
|
36
|
+
`runUrl` in the demo declaration takes precedence and is validated for both
|
|
37
|
+
local and hosted demos. No per-seed link is required. CSS adds the label suffix without
|
|
32
38
|
changing the application's hydrated text; CSP allows exact hashes only.
|
|
33
39
|
|
|
34
40
|
Public sockets, WebSockets and event streams remain usable for checks. The
|
|
35
41
|
local sockets guard and hosted egress retain a small direct mail/SMS denylist;
|
|
36
42
|
use the effect helper for such sends. Hosted demos keep their isolated
|
|
37
43
|
container, Turnstile, per-IP start limit, TTL/idle end and maximum instances.
|
|
38
|
-
See [adoption and hosting](
|
|
44
|
+
See [adoption and hosting](https://github.com/runeditrun/base/blob/main/export/DEMO.md).
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { containedInput } from './input-path.mjs';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
|
|
5
|
+
export async function demoRunDeclaration(declaration, { root, adapter, read } = {}) {
|
|
6
|
+
if (declaration.runUrl !== undefined) return declaration;
|
|
7
|
+
read ??= async path => JSON.parse(await readFile(await containedInput(root, path), 'utf8'));
|
|
8
|
+
let bare = false;
|
|
9
|
+
if (adapter === undefined) {
|
|
10
|
+
let operations;
|
|
11
|
+
try { operations = await read('OPERATIONS.json'); }
|
|
12
|
+
catch (error) { if (error.code !== 'ENOENT') throw error; bare = true; }
|
|
13
|
+
if (operations?.seedContract) adapter = (await import(pathToFileURL(await containedInput(root, operations.seedContract.adapter)).href)).commandAdapter;
|
|
14
|
+
}
|
|
15
|
+
const path = adapter?.site?.declaration ?? (bare ? 'deploy-site.json' : undefined);
|
|
16
|
+
if (!path) return declaration;
|
|
17
|
+
let site;
|
|
18
|
+
try { site = await read(path); }
|
|
19
|
+
catch (error) { if (!bare || error.code !== 'ENOENT') throw error; }
|
|
20
|
+
return site ? { ...declaration, runUrl: `https://${site.domain}/run` } : declaration;
|
|
21
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { lstat, realpath } from 'node:fs/promises';
|
|
2
|
+
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
|
3
|
+
|
|
4
|
+
// The CLI and standalone Vite copy share checkout-path resolution. The CLI
|
|
5
|
+
// supplies its public diagnostics; other callers retain filesystem errors.
|
|
6
|
+
export async function containedInput(root, path, { optional = false, privateFile = false, refuse = message => new Error(message), missing = (_message, error) => error } = {}) {
|
|
7
|
+
if (typeof path !== 'string' || !path || isAbsolute(path) || path.split(/[\\/]/).some(part => part === '..' || part === '')) throw refuse('Path must be a contained checkout path without traversal.');
|
|
8
|
+
const checkout = await realpath(root), destination = resolve(checkout, path), parts = relative(checkout, destination).split(sep);
|
|
9
|
+
let current = checkout;
|
|
10
|
+
for (let i = 0; i < parts.length; i++) {
|
|
11
|
+
current = resolve(current, parts[i]);
|
|
12
|
+
let status; try { status = await lstat(current); } catch (error) { if (error.code === 'ENOENT' && optional) return destination; if (error.code === 'ENOENT') throw missing(`Missing input file: ${path}. See the project operating documentation.`, error); throw error; }
|
|
13
|
+
if (status.isSymbolicLink()) throw refuse(`Symlink refused at ${path}; preserve it and resolve placement first.`);
|
|
14
|
+
if (i < parts.length - 1 && !status.isDirectory()) throw refuse(`Unsafe path ancestor for ${path}.`);
|
|
15
|
+
if (privateFile && i === parts.length - 1 && (!status.isFile() || status.nlink !== 1 || (status.mode & 0o077) !== 0 || (process.getuid && status.uid !== process.getuid()))) throw refuse(`Input must be an owned regular private file (0600): ${path}.`);
|
|
16
|
+
}
|
|
17
|
+
return destination;
|
|
18
|
+
}
|
package/modules/demo/label.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Suffix the document title and the text marked data-rer-name, without a bar. */
|
|
2
|
-
export function decorateLabel(response: Response, mode: 'Demo' | 'Dev'): Promise<Response>;
|
|
2
|
+
export function decorateLabel(response: Response, mode: 'Demo' | 'Dev', exit?: { name: string; url: string } | null): Promise<Response>;
|
package/modules/demo/label.mjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { allow, sha256 } from '../operator-auth/csp.mjs';
|
|
2
|
+
import { NAVIGATION_SCRIPT, NAVIGATION_STYLE } from './navigation.mjs';
|
|
3
|
+
|
|
4
|
+
const escape = value => String(value).replace(/[&<>"']/g, character => `&#${character.charCodeAt(0)};`);
|
|
2
5
|
|
|
3
6
|
// CSS leaves React's text alone during hydration. The title observer handles
|
|
4
7
|
// client-side route changes, whose head manager writes a fresh title. The script
|
|
@@ -6,25 +9,27 @@ import { allow, sha256 } from '../operator-auth/csp.mjs';
|
|
|
6
9
|
// on the label's style element, never as code.
|
|
7
10
|
const SCRIPT = "(()=>{const suffix=document.querySelector('style[data-rer-label]').dataset.rerLabel,update=()=>{const base=document.title.replace(/\\s*(?:Demo|Dev)$/,''),title=(base?base+' ':'')+suffix;if(document.title!==title)document.title=title};update();new MutationObserver(update).observe(document.head,{childList:true,subtree:true,characterData:true})})()";
|
|
8
11
|
|
|
9
|
-
export async function decorateLabel(response, mode) {
|
|
12
|
+
export async function decorateLabel(response, mode, exit = import.meta.rerDemo) {
|
|
10
13
|
if (!response.body || !response.headers.get('content-type')?.toLowerCase().startsWith('text/html')) return response;
|
|
11
14
|
const suffix = mode === 'Demo' ? 'Demo' : 'Dev';
|
|
12
|
-
const style = `[data-rer-name]::after{content:" ${suffix}"}`;
|
|
15
|
+
const style = `[data-rer-name]::after{content:" ${suffix}"}${suffix === 'Demo' && exit ? NAVIGATION_STYLE : ''}`;
|
|
16
|
+
const script = SCRIPT + ';' + (suffix === 'Demo' && exit ? NAVIGATION_SCRIPT : '');
|
|
13
17
|
const html = await response.text();
|
|
14
18
|
if (html.includes('data-rer-label=')) return new Response(html, response);
|
|
15
19
|
const headers = new Headers(response.headers);
|
|
16
20
|
let policy = headers.get('content-security-policy');
|
|
17
21
|
if (policy) {
|
|
18
22
|
policy = allow(policy, 'style-src', await sha256(style));
|
|
19
|
-
headers.set('content-security-policy', allow(policy, 'script-src', await sha256(
|
|
23
|
+
headers.set('content-security-policy', allow(policy, 'script-src', await sha256(script)));
|
|
20
24
|
}
|
|
21
25
|
headers.delete('content-length');
|
|
22
26
|
headers.delete('etag');
|
|
23
|
-
const
|
|
27
|
+
const metadata = suffix === 'Demo' && exit ? ` data-rer-product="${escape(exit.name)}" data-rer-run="${escape(exit.url)}"` : '';
|
|
28
|
+
const addition = `<style data-rer-label="${suffix}"${metadata}>${style}</style><script>${script}</script>`;
|
|
24
29
|
const titled = html.replace(/(<title\b[^>]*>)([\s\S]*?)(<\/title>)/i, (_, open, title, close) => {
|
|
25
30
|
const base = title.replace(/\s*(?:Demo|Dev)$/, '');
|
|
26
31
|
return `${open}${base ? `${base} ` : ''}${suffix}${close}`;
|
|
27
32
|
});
|
|
28
|
-
const body = /<\/head\s*>/i.test(titled) ? titled.replace(/<\/head\s*>/i, `${addition}</head>`) : addition + titled;
|
|
33
|
+
const body = /<\/head\s*>/i.test(titled) ? titled.replace(/<\/head\s*>/i, () => `${addition}</head>`) : addition + titled;
|
|
29
34
|
return new Response(body, { status: response.status, statusText: response.statusText, headers });
|
|
30
35
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Runs after the app's initial hydration, then follows its client navigation.
|
|
2
|
+
// Each exit belongs beside an existing marked product label, never in a bar.
|
|
3
|
+
export const NAVIGATION_SCRIPT = `(() => {
|
|
4
|
+
const settings = document.querySelector('style[data-rer-label]');
|
|
5
|
+
if (!settings.dataset.rerRun) return;
|
|
6
|
+
const update = () => {
|
|
7
|
+
for (const label of document.querySelectorAll('[data-rer-name]')) {
|
|
8
|
+
const position = label.closest('a,button') ?? label;
|
|
9
|
+
if (position.nextElementSibling?.hasAttribute('data-rer-demo-exit')) continue;
|
|
10
|
+
const link = document.createElement('a');
|
|
11
|
+
link.setAttribute('data-rer-demo-exit', '');
|
|
12
|
+
link.href = settings.dataset.rerRun;
|
|
13
|
+
link.textContent = 'Run ' + settings.dataset.rerProduct;
|
|
14
|
+
position.after(link);
|
|
15
|
+
const layout = getComputedStyle(position.parentElement);
|
|
16
|
+
if (label.scrollWidth > label.clientWidth && layout.display.includes('flex') && layout.flexWrap === 'nowrap') {
|
|
17
|
+
link.style.width = 'min-content';
|
|
18
|
+
link.style.whiteSpace = 'normal';
|
|
19
|
+
link.style.textAlign = 'center';
|
|
20
|
+
link.style.marginInlineStart = '0';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const start = () => {
|
|
25
|
+
update();
|
|
26
|
+
new MutationObserver(update).observe(document.body, { childList: true, subtree: true });
|
|
27
|
+
};
|
|
28
|
+
const ready = () => window.requestAnimationFrame(() => window.requestAnimationFrame(start));
|
|
29
|
+
if (document.readyState === 'complete') ready();
|
|
30
|
+
else window.addEventListener('load', ready, { once: true });
|
|
31
|
+
})()`;
|
|
32
|
+
export const NAVIGATION_STYLE = '[data-rer-demo-exit]{display:inline-block;flex-shrink:0;margin-inline-start:.5em;color:var(--rer-link,inherit);font:inherit;font-size:13px;font-weight:400;line-height:1.5;white-space:nowrap;text-decoration:underline;text-underline-offset:3px}[data-rer-demo-exit]:focus-visible{outline:2px solid var(--rer-focus,currentColor);outline-offset:3px}';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Shared by Vite and the hosted plan; this file also travels with src/modules/demo.
|
|
2
|
+
export function demoRunUrl(value) {
|
|
3
|
+
if (typeof value !== 'string' || !/^https:\/\//i.test(value) || /[\s\p{Cc}\\]/u.test(value)) throw new Error('invalid-demo-run-url');
|
|
4
|
+
let run;
|
|
5
|
+
try { run = new URL(value); } catch { throw new Error('invalid-demo-run-url'); }
|
|
6
|
+
if (run.protocol !== 'https:' || run.username || run.password || run.pathname !== '/run' || run.search || run.hash) throw new Error('invalid-demo-run-url');
|
|
7
|
+
if (run.hostname.length > 253 || !/^(?!www\.)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z][a-z0-9-]{0,62}$/.test(run.hostname)) throw new Error('invalid-site-domain');
|
|
8
|
+
return run.href;
|
|
9
|
+
}
|
package/modules/demo/vite.d.mts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
export function demoSockets(): {
|
|
1
|
+
/** Supplies public demo navigation metadata and guards local demo sockets. */
|
|
2
|
+
export function demoSockets(): {
|
|
3
|
+
name: string;
|
|
4
|
+
enforce: 'pre';
|
|
5
|
+
config(config: { root?: string }, environment: { command: string }): Promise<object>;
|
|
6
|
+
resolveId(id: string): string | undefined;
|
|
7
|
+
};
|
package/modules/demo/vite.mjs
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { demoRunDeclaration } from './declaration.mjs';
|
|
5
|
+
import { demoRunUrl } from './run-url.mjs';
|
|
2
6
|
|
|
3
7
|
// A module namespace cannot be patched at runtime, so under `rer demo`
|
|
4
8
|
// (RER_DEMO=1) Vite hands the Worker's `cloudflare:sockets` imports the guarded
|
|
@@ -8,10 +12,21 @@ export function demoSockets() {
|
|
|
8
12
|
const on = () => process.env.RER_DEMO === '1';
|
|
9
13
|
return {
|
|
10
14
|
name: 'rer-demo-sockets',
|
|
11
|
-
apply: 'serve',
|
|
12
15
|
enforce: 'pre',
|
|
13
16
|
// Vite resolves a Worker's builtin import only when an alias names it.
|
|
14
|
-
config
|
|
17
|
+
async config(config, { command }) {
|
|
18
|
+
let declaration;
|
|
19
|
+
try { declaration = JSON.parse(await readFile(resolve(config.root ?? process.cwd(), 'deploy-demo.json'), 'utf8')); }
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (error.code !== 'ENOENT') throw error;
|
|
22
|
+
if (on()) throw new Error('rer demo needs deploy-demo.json with the product name and canonical run-site domain. See DEMO.md.');
|
|
23
|
+
}
|
|
24
|
+
const resolved = declaration && await demoRunDeclaration(declaration, { root: config.root ?? process.cwd() });
|
|
25
|
+
return {
|
|
26
|
+
define: { 'import.meta.rerDemo': JSON.stringify(resolved ? { name: resolved.name, url: demoRunUrl(resolved.runUrl === undefined ? `https://${resolved.domain}/run` : resolved.runUrl) } : null) },
|
|
27
|
+
...(on() && command === 'serve' ? { resolve: { alias: [{ find: /^cloudflare:sockets$/, replacement: 'cloudflare:sockets' }] } } : {}),
|
|
28
|
+
};
|
|
29
|
+
},
|
|
15
30
|
resolveId(id) {
|
|
16
31
|
if (on() && id === 'cloudflare:sockets') return guarded;
|
|
17
32
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Native hosted demos
|
|
2
2
|
|
|
3
3
|
`rer deploy --demo` builds the seed's production Worker for a Worker Loader
|
|
4
|
-
host. See [adoption and deployment](
|
|
4
|
+
host. See [adoption and deployment](https://github.com/runeditrun/base/blob/main/export/DEMO.md#hosting-the-demo).
|
|
5
5
|
|
|
6
6
|
- `build.mjs`: ordinary Vite output, declared SQL and public configuration,
|
|
7
7
|
using the shared container migration-inventory and image-variable checks.
|
|
@@ -21,8 +21,10 @@ host. See [adoption and deployment](../../export/DEMO.md#hosting-the-demo).
|
|
|
21
21
|
`theme-script.mjs` sets the page and Turnstile scheme from the painted card's
|
|
22
22
|
background and text before the widget renders, and updates on preference changes.
|
|
23
23
|
The maintained default seed's theme assets supply missing tokens or an
|
|
24
|
-
absent theme, under `/__demo/theme
|
|
25
|
-
|
|
24
|
+
absent theme, under `/__demo/theme/`, except the link colour: a seed theme
|
|
25
|
+
without `--rer-link` links in its own `--rer-text`, as the theme grammar reads
|
|
26
|
+
it. Styles, fonts and marks stay same-origin; a missing mark leaves the
|
|
27
|
+
product name visible.
|
|
26
28
|
- `native/warm.mjs`: the start page's prefetch list, built from `dist/client`
|
|
27
29
|
(the Vite manifest if the build wrote one, else the build's `assetsDir`, else
|
|
28
30
|
`assets`) and TanStack Start's route manifest, the console's views first,
|
|
@@ -34,7 +34,7 @@ export class NativeDemo extends DurableObject {
|
|
|
34
34
|
// Short TTLs are usable only on the guarded testing host.
|
|
35
35
|
if (/^[123]x0{31}AA$/.test(this.env.TURNSTILE_SECRET_KEY ?? '') && this.env.NATIVE_TEST_TTL_MS) ends = Math.min(ends, started + Number(this.env.NATIVE_TEST_TTL_MS));
|
|
36
36
|
const runtime = { ...bundle.vars, ...settings, RER_DEMO: '1', [originVar]: origin,
|
|
37
|
-
RER_NATIVE_KEY: random(), SESSION_SECRET: random(), SETUP_TOKEN: random(), OWNER_EMAIL: this.env.DEMO_OWNER_EMAIL || 'owner@demo.invalid',
|
|
37
|
+
RER_NATIVE_KEY: random(), SESSION_SECRET: random(), INSTALLATION_KEY: random(), SETUP_TOKEN: random(), OWNER_EMAIL: this.env.DEMO_OWNER_EMAIL || 'owner@demo.invalid',
|
|
38
38
|
RER_OWNER_CLAIM_ISSUER: origin, RER_OWNER_CLAIM_INSTALLATION_ID: id,
|
|
39
39
|
RER_OWNER_CLAIM_PUBLIC_KEYS: JSON.stringify(keys.publicKeys), RER_DEMO_EXPIRES: endsLocal };
|
|
40
40
|
this.state = { phase: 'starting', runtime, ends, seen: started, savedSeen: started, lastCron: Math.floor(started / 60_000), correlation };
|
|
@@ -9,11 +9,11 @@ ul{padding:0;margin:23px 0 35px;list-style:none;color:var(--rer-muted);font-size
|
|
|
9
9
|
.button:disabled{background:var(--rer-surface);border-color:var(--rer-border);color:var(--rer-muted);font-weight:600;cursor:default}
|
|
10
10
|
.spinner{display:none;flex:none;width:20px;height:20px;border:3px solid color-mix(in srgb,currentColor 35%,transparent);border-top-color:currentColor;border-radius:50%;animation:spin .8s linear infinite}[data-state=working] .spinner,[data-state=signing] .spinner{display:block}@keyframes spin{to{transform:rotate(360deg)}}
|
|
11
11
|
ol.steps{display:none;list-style:none;margin:22px auto 0;padding:0;width:max-content;max-width:100%;font-size:16px;line-height:22px;color:var(--rer-muted)}[data-state=working] .steps,[data-state=signing] .steps,[data-state=slow] .steps{display:grid;gap:10px}[data-state=failed] .note{display:none}
|
|
12
|
-
.steps li{padding-left:30px;margin:0}.steps li:before{left:0;top:2px;width:18px;height:18px;box-sizing:border-box;background:none;border:2px solid var(--rer-muted)}.steps [data-at=done]{color:var(--rer-muted)}.steps [data-at=done]:before{content:'✓';border:0;background:var(--rer-accent);color:var(--rer-accent-text);font-size:
|
|
12
|
+
.steps li{padding-left:30px;margin:0}.steps li:before{left:0;top:2px;width:18px;height:18px;box-sizing:border-box;background:none;border:2px solid var(--rer-muted)}.steps [data-at=done]{color:var(--rer-muted)}.steps [data-at=done]:before{content:'✓';border:0;background:var(--rer-accent);color:var(--rer-accent-text);font-size:13px;line-height:18px;font-weight:700;text-align:center}.steps [data-at=now]{color:var(--rer-text);font-weight:600}.steps [data-at=now]:before{border-color:var(--rer-border);border-top-color:var(--rer-accent);animation:spin .8s linear infinite}
|
|
13
13
|
.visually-hidden{position:absolute;width:1px;height:1px;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
|
|
14
14
|
@media(prefers-reduced-motion:reduce){.spinner,.steps [data-at=now]:before{animation:none}.steps [data-at=now]:before{border-color:var(--rer-accent)}}.button:focus-visible,a:focus-visible{outline:3px solid var(--rer-focus);outline-offset:4px}
|
|
15
15
|
.note{font-size:15px;line-height:21px;color:var(--rer-muted);text-align:center;margin:21px 0 0}.secondary{text-align:center;margin:22px 0 0;font-size:18px;line-height:24px;font-weight:600}.secondary a{color:var(--rer-link,var(--rer-text));text-underline-offset:3px}
|
|
16
|
-
.back{text-align:center;margin:32px 0 0;font-size:15px;line-height:22px}.back a{color:var(--rer-link,var(--rer-text));text-underline-offset:3px}
|
|
16
|
+
.back{display:flex;flex-wrap:wrap;justify-content:center;gap:12px 24px;text-align:center;margin:32px 0 0;font-size:15px;line-height:22px}.back a{color:var(--rer-link,var(--rer-text));text-underline-offset:3px}
|
|
17
17
|
.ended main{width:min(560px,calc(100% - 32px));margin-top:clamp(32px,26vh,262px)}.ended .card{padding:28px 36px 42px}.ended .brand{font-size:16px;margin-bottom:26px}.ended h1{font-size:36px;line-height:44px;margin-bottom:22px}.ended .intro{margin-bottom:36px}.ended .button{margin-top:0;font-size:18px}
|
|
18
18
|
@media(min-width:600px) and (max-width:1023px){main{width:calc(100% - 64px);max-width:666px;margin:100px auto 48px}.card{padding:36px}h1{font-size:38px;line-height:46px}.intro{font-size:18px;line-height:27px}}
|
|
19
19
|
@media(max-width:599px){main,.ended main{width:calc(100% - 32px);margin:32px auto}.ended .card{padding:26px 22px}.ended h1{font-size:29px;line-height:36px}.ended .intro{font-size:17px;line-height:25px;margin-bottom:28px}.card{padding:26px 22px;border-radius:var(--rer-radius)}.brand{font-size:16px}h1{font-size:34px;line-height:41px;letter-spacing:-.8px}.intro{font-size:17px;line-height:25px}ul{font-size:16px;line-height:25px;margin:22px 0 26px}li{padding-left:22px;margin-bottom:9px}li:before{left:2px;top:9px}.button{font-size:18px;margin-top:22px}.note{font-size:13px;line-height:20px}.steps{font-size:15px}.back{margin-top:24px;font-size:14px}}`;
|
|
@@ -16,7 +16,7 @@ function html(env, { page, title, body, status = 200, headers = {}, turnstile =
|
|
|
16
16
|
const nonce = crypto.randomUUID().replaceAll('-', ''), site = new URL(env.DEMO_SITE);
|
|
17
17
|
const policy = `default-src 'none'; style-src 'self' 'nonce-${nonce}'; font-src 'self'; img-src 'self'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'; script-src 'nonce-${nonce}'${turnstile ? ` https://challenges.cloudflare.com; frame-src https://challenges.cloudflare.com; connect-src 'self' https://challenges.cloudflare.com` : ''}`;
|
|
18
18
|
return new Response(`<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex"><title>${escape(title)}</title>${env.DEMO_ICON_HEAD ?? ''}${refresh ? '<noscript><meta http-equiv="refresh" content="2;url=/__demo/status"></noscript>' : ''}<style nonce="${nonce}">${(env.DEMO_THEME ?? '').replace(/<(?=\/style)/gi, '\\3c ')}\n${STYLE}</style>${turnstile ? `<noscript><style nonce="${nonce}">#note{display:none}</style></noscript><script nonce="${nonce}">${START_SCRIPT}</script>${warm(env)}` : ''}</head>
|
|
19
|
-
<body class="${page}"><main><section class="card" aria-labelledby="title"><p class="brand"><img class="mark" alt="${escape(env.DEMO_NAME)}" width="40" height="40" hidden><span>${escape(env.DEMO_NAME)}</span></p>${body}</section><nav class="back" aria-label="Return"><a href="${escape(site.origin)}/">Back to ${escape(site.host)}</a
|
|
19
|
+
<body class="${page}"><main><section class="card" aria-labelledby="title"><p class="brand"><img class="mark" alt="${escape(env.DEMO_NAME)}" width="40" height="40" hidden><span>${escape(env.DEMO_NAME)}</span></p>${body}</section><nav class="back" aria-label="Return"><a href="${escape(site.origin)}/">Back to ${escape(site.host)}</a>${page === 'start' ? `<a href="${escape(env.DEMO_RUN_URL ?? new URL('/run', site).href)}">Run ${escape(env.DEMO_NAME)}</a>` : ''}</nav></main><script nonce="${nonce}">${THEME_SCRIPT}</script>${turnstile ? `<script nonce="${nonce}" src="https://challenges.cloudflare.com/turnstile/v0/api.js?onload=rerDemoRender&render=explicit" async defer></script>` : ''}</body></html>`,
|
|
20
20
|
{ status, headers: { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store', 'content-security-policy': policy, 'referrer-policy': 'strict-origin', 'x-content-type-options': 'nosniff', ...headers } });
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -25,7 +25,7 @@ export function startPage(env, { status = 200, notice, pending = false, headers
|
|
|
25
25
|
const name = escape(env.DEMO_NAME);
|
|
26
26
|
return html(env, { page: 'start', title: `Try ${env.DEMO_NAME}`, status, headers, turnstile: true, refresh: pending, body: `<h1 id="title">Try ${name}</h1>
|
|
27
27
|
<p class="intro">Your own copy of ${name}, signed in as its owner, with sample data.</p>
|
|
28
|
-
<ul><li>Public checks run live
|
|
28
|
+
<ul><li>Public checks run live.</li><li>It ends after an hour, or 15 idle minutes.</li><li>Then it is deleted. Nobody else can see it.</li></ul>
|
|
29
29
|
<p class="notice" id="notice" role="alert"${notice ? '' : ' hidden'}>${notice ? escape(notice) : ''}</p><form id="start" method="post" action="/__demo/start" data-auto="${notice || pending ? '0' : '1'}"${pending ? ' data-resume="1" data-state="working"' : ' data-state="waiting"'}><div class="cf-turnstile" data-theme="light" data-sitekey="${escape(env.TURNSTILE_SITE_KEY)}" data-size="flexible" data-callback="rerDemoVerified" data-before-interactive-callback="rerDemoInteractive" data-after-interactive-callback="rerDemoChecking" data-expired-callback="rerDemoExpired" data-error-callback="rerDemoCheckFailed"></div>
|
|
30
30
|
<button class="button" type="submit" disabled><span class="spinner" aria-hidden="true"></span><span class="label">${pending ? 'Starting your demo…' : 'Waiting for the human check…'}</span></button>
|
|
31
31
|
<ol class="steps" aria-hidden="true"><li data-at="done">Checking you're human</li><li data-at="now">Starting a private copy</li><li data-at="next">Signing you in</li></ol>
|
|
@@ -37,7 +37,7 @@ export function endedPage(env, { status = 410, headers = {} } = {}) {
|
|
|
37
37
|
const name = escape(env.DEMO_NAME);
|
|
38
38
|
return html(env, { page: 'ended', title: 'This demo has ended', status, headers, body: `<h1 id="title">This demo has ended</h1>
|
|
39
39
|
<p class="intro">A demo ends when you sign out, after an hour, or after 15 minutes with nothing happening. Its copy of ${name} and everything in it have been deleted.</p>
|
|
40
|
-
<a class="button" href="${escape(env.DEMO_ORIGIN)}/">Start a new demo</a><p class="secondary"><a href="${escape(new URL(env.DEMO_SITE).
|
|
40
|
+
<a class="button" href="${escape(env.DEMO_ORIGIN)}/">Start a new demo</a><p class="secondary"><a href="${escape(env.DEMO_RUN_URL ?? new URL('/run', env.DEMO_SITE).href)}">Run ${name} yourself</a></p>` });
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
const cookie = (env, value, seconds) => `rer_demo=${value}; Domain=${new URL(env.DEMO_ORIGIN).hostname}; Path=/; Max-Age=${seconds}; HttpOnly; Secure; SameSite=Lax`;
|
|
@@ -2,15 +2,17 @@ import { createHash } from 'node:crypto';
|
|
|
2
2
|
import { assert, hash, resourceName } from '../deploy-kit/validation.mjs';
|
|
3
3
|
import { ownerWorkerName } from '../deploy-kit/owner.mjs';
|
|
4
4
|
import { siteDeclaration } from '../deploy-kit/site.mjs';
|
|
5
|
+
import { demoRunUrl } from '../demo/run-url.mjs';
|
|
5
6
|
|
|
6
7
|
// Native Loader front, admission and visitor session support.
|
|
7
8
|
export const DEMO_FILES = ['worker.mjs', 'capacity.mjs', 'claim.mjs', 'pages.mjs', 'page-style.mjs', 'theme-script.mjs', 'start-script.mjs', 'diagnostics.mjs', 'operator.mjs', 'measurement.mjs'];
|
|
8
9
|
const FRONT_SET = /^(?:RER_.*|SESSION_SECRET|SETUP_TOKEN|OWNER_EMAIL)$/;
|
|
9
10
|
const SECRET = /SECRET|TOKEN|PASSWORD|_KEY$/;
|
|
10
11
|
export function demoDeclaration(value, originVar) {
|
|
11
|
-
assert(value && typeof value === 'object' && !Array.isArray(value) && value.version === 1 && Object.keys(value).every(key => ['version', 'domain', 'name', 'maxInstances', 'ownerEmail', 'settings'].includes(key)), 'invalid-demo-declaration');
|
|
12
|
+
assert(value && typeof value === 'object' && !Array.isArray(value) && value.version === 1 && Object.keys(value).every(key => ['version', 'domain', 'name', 'maxInstances', 'ownerEmail', 'settings', 'runUrl'].includes(key)), 'invalid-demo-declaration');
|
|
12
13
|
siteDeclaration({ version: 1, domain: value.domain });
|
|
13
14
|
assert(typeof value.name === 'string' && value.name.trim() === value.name && value.name.length > 0 && value.name.length <= 60 && !/[\p{Cc}\p{Cf}]/u.test(value.name), 'invalid-demo-name');
|
|
15
|
+
const runUrl = demoRunUrl(value.runUrl === undefined ? `https://${value.domain}/run` : value.runUrl);
|
|
14
16
|
const maxInstances = value.maxInstances ?? 10;
|
|
15
17
|
assert(Number.isSafeInteger(maxInstances) && maxInstances >= 1 && maxInstances <= 100, 'invalid-demo-max-instances');
|
|
16
18
|
const ownerEmail = value.ownerEmail;
|
|
@@ -18,13 +20,13 @@ export function demoDeclaration(value, originVar) {
|
|
|
18
20
|
const settings = value.settings ?? {};
|
|
19
21
|
assert(settings && typeof settings === 'object' && !Array.isArray(settings) && Object.entries(settings).every(([name, setting]) =>
|
|
20
22
|
/^[A-Z][A-Z0-9_]{0,63}$/.test(name) && !FRONT_SET.test(name) && !SECRET.test(name) && name !== originVar && typeof setting === 'string' && setting.length <= 1024), 'invalid-demo-settings');
|
|
21
|
-
return { domain: value.domain, name: value.name, maxInstances, ownerEmail, settings };
|
|
23
|
+
return { domain: value.domain, name: value.name, runUrl, maxInstances, ownerEmail, settings };
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
/** The demo Worker's name and its Wrangler configuration; no provider request. */
|
|
25
27
|
export function demoPlan({ project, environment, compatibilityDate, originVar, hostVariables = [], declaration, turnstileSiteKey }) {
|
|
26
28
|
assert(/^\d{4}-\d{2}-\d{2}$/.test(compatibilityDate ?? '') && /^[A-Z][A-Z0-9_]{0,63}$/.test(originVar ?? ''), 'invalid-plan');
|
|
27
|
-
const { domain, name, maxInstances, ownerEmail, settings } = demoDeclaration(declaration, originVar);
|
|
29
|
+
const { domain, name, runUrl, maxInstances, ownerEmail, settings } = demoDeclaration(declaration, originVar);
|
|
28
30
|
// Keep the historical container name in the ownership hash for released hosts.
|
|
29
31
|
const worker = `${ownerWorkerName(project, environment)}--demo`, hostname = `demo.${domain}`, container = worker.replace(/-+/g, '-');
|
|
30
32
|
assert(resourceName(worker), 'owner-name-too-long');
|
|
@@ -44,7 +46,7 @@ export function demoPlan({ project, environment, compatibilityDate, originVar, h
|
|
|
44
46
|
name: worker, main: 'worker.mjs', compatibility_date: compatibilityDate, workers_dev: false, preview_urls: false,
|
|
45
47
|
routes: hostnames.map(pattern => ({ pattern, custom_domain: true })),
|
|
46
48
|
observability: { enabled: true, head_sampling_rate: 1, logs: { enabled: true, invocation_logs: false } },
|
|
47
|
-
vars: { DEMO_ORIGIN: `https://${hostname}`, DEMO_SITE: `https://${domain}`, DEMO_NAME: name, DEMO_ORIGIN_VAR: originVar, DEMO_MAX_INSTANCES: String(maxInstances), DEMO_SETTINGS: JSON.stringify(settings), DEMO_SECONDARY_ORIGINS: JSON.stringify(secondaryHosts.map(host => `https://${host}`)),
|
|
49
|
+
vars: { DEMO_ORIGIN: `https://${hostname}`, DEMO_SITE: `https://${domain}`, DEMO_NAME: name, DEMO_RUN_URL: runUrl, DEMO_ORIGIN_VAR: originVar, DEMO_MAX_INSTANCES: String(maxInstances), DEMO_SETTINGS: JSON.stringify(settings), DEMO_SECONDARY_ORIGINS: JSON.stringify(secondaryHosts.map(host => `https://${host}`)),
|
|
48
50
|
...(ownerEmail ? { DEMO_OWNER_EMAIL: ownerEmail } : {}), ...(turnstileSiteKey ? { TURNSTILE_SITE_KEY: turnstileSiteKey } : {}) },
|
|
49
51
|
durable_objects: { bindings: [{ name: 'DEMO', class_name: 'NativeDemo' }, { name: 'CAPACITY', class_name: 'DemoCapacity' }] },
|
|
50
52
|
migrations: [{ tag: 'native-v2', new_sqlite_classes: ['NativeDemo', 'DemoCapacity'] }],
|
|
@@ -22,6 +22,9 @@ export async function prepareTheme(folder, assets) {
|
|
|
22
22
|
files.set(prefix + path, bytes);
|
|
23
23
|
paths.push(prefix + path);
|
|
24
24
|
}
|
|
25
|
-
const
|
|
26
|
-
|
|
25
|
+
const seed = ['/fonts/fonts.css', '/rer-theme.css'].filter(path => files.has(path));
|
|
26
|
+
// A seed theme without --rer-link links in its own --rer-text, as the theme
|
|
27
|
+
// grammar reads it (onboarding/theme.mjs), never in the default's link colour.
|
|
28
|
+
const link = files.has('/rer-theme.css') ? ':root{--rer-link:var(--rer-text)}' : '';
|
|
29
|
+
return { paths, css: [inlineTheme(files, [prefix + '/rer-theme.css']), link, inlineTheme(files, seed)].join('\n') };
|
|
27
30
|
}
|