@runeditrun/rer 0.2.18 → 0.2.20

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.
Files changed (113) hide show
  1. package/README.md +7 -7
  2. package/cli/README.md +22 -21
  3. package/cli/adapter.mjs +5 -0
  4. package/cli/container.mjs +7 -2
  5. package/cli/contract.mjs +6 -4
  6. package/cli/delivery-declarations.mjs +36 -0
  7. package/cli/demo-host.mjs +2 -2
  8. package/cli/demo.mjs +16 -5
  9. package/cli/deploy-command.mjs +4 -1
  10. package/cli/deploy.mjs +4 -1
  11. package/cli/detached-server.mjs +2 -2
  12. package/cli/dev-identity.mjs +1 -1
  13. package/cli/export.mjs +1 -1
  14. package/cli/inspect.mjs +17 -15
  15. package/cli/lifecycle.mjs +16 -49
  16. package/cli/listen.mjs +31 -0
  17. package/cli/local.mjs +12 -18
  18. package/cli/main.mjs +7 -0
  19. package/cli/managed-server.mjs +26 -44
  20. package/cli/output.mjs +1 -1
  21. package/cli/parse.mjs +8 -7
  22. package/cli/port.mjs +20 -20
  23. package/cli/production-auth.mjs +38 -0
  24. package/cli/server-proxy.mjs +2 -6
  25. package/cli/server-registry.mjs +7 -2
  26. package/cli/setup-input.mjs +3 -0
  27. package/cli/signin.mjs +41 -0
  28. package/global/CHANGELOG.md +18 -0
  29. package/global/README.md +7 -7
  30. package/global/cli/install.mjs +4 -28
  31. package/global/cli/path-link.mjs +25 -21
  32. package/global/launch/dev.mjs +1 -1
  33. package/global/launch/facts.mjs +11 -14
  34. package/global/launch/failure.mjs +20 -0
  35. package/global/launch/render.mjs +2 -6
  36. package/global/launch/worker.mjs +3 -3
  37. package/global/main.mjs +3 -3
  38. package/modules/container/build.mjs +2 -2
  39. package/modules/container/demo-egress.mjs +35 -0
  40. package/modules/container/worker-engine.mjs +3 -3
  41. package/modules/d1-transport/index.d.mts +9 -0
  42. package/modules/d1-transport/index.mjs +124 -0
  43. package/modules/delivery-producer/bindings.mjs +140 -0
  44. package/modules/delivery-producer/declarations.mjs +49 -0
  45. package/modules/demo/README.md +34 -0
  46. package/modules/demo/effects.mjs +73 -0
  47. package/modules/demo/index.d.mts +15 -0
  48. package/modules/demo/index.mjs +63 -0
  49. package/modules/demo/label.d.mts +2 -0
  50. package/modules/demo/label.mjs +24 -0
  51. package/modules/demo/responses.mjs +26 -0
  52. package/modules/demo/sockets.mjs +13 -0
  53. package/modules/demo/vite.d.mts +2 -0
  54. package/modules/demo/vite.mjs +19 -0
  55. package/modules/demo-host/README.md +5 -1
  56. package/modules/demo-host/container.mjs +4 -4
  57. package/modules/demo-host/pages.mjs +1 -1
  58. package/modules/demo-host/worker.mjs +1 -1
  59. package/modules/deploy-kit/README.md +2 -0
  60. package/modules/deploy-kit/owner-cli.mjs +5 -2
  61. package/modules/deploy-kit/owner-signin.mjs +34 -0
  62. package/modules/deploy-kit/owner.mjs +2 -2
  63. package/modules/deploy-kit/r2-objects.mjs +8 -5
  64. package/modules/job-queue/storage.mjs +4 -1
  65. package/modules/mail/README.md +62 -87
  66. package/modules/mail/src/adapters/rer/contract.mjs +22 -0
  67. package/modules/mail/src/adapters/rer/index.mjs +30 -0
  68. package/modules/mail/src/core/transport.mjs +1 -1
  69. package/modules/mail/src/core/validation.mjs +6 -3
  70. package/modules/mail/src/development/index.d.mts +1 -6
  71. package/modules/mail/src/development/index.mjs +3 -16
  72. package/modules/mail/src/sender.mjs +2 -1
  73. package/modules/operator-auth/README.md +53 -9
  74. package/modules/operator-auth/accounts/email-change.mjs +34 -0
  75. package/modules/operator-auth/accounts/owner-signin.mjs +50 -0
  76. package/modules/operator-auth/accounts/schema/owner-signin.sql +10 -0
  77. package/modules/operator-auth/csp.mjs +1 -2
  78. package/modules/operator-auth/dev/cli-session.mjs +32 -0
  79. package/modules/operator-auth/dev/index.mjs +18 -11
  80. package/modules/operator-auth/identity/email-link/confirmation.mjs +3 -3
  81. package/modules/operator-auth/identity/email-link/index.mjs +4 -1
  82. package/modules/operator-auth/index.d.mts +8 -2
  83. package/modules/operator-auth/owner-signin-grant.mjs +10 -0
  84. package/modules/operator-auth/page.mjs +1 -1
  85. package/modules/operator-auth/routes.mjs +11 -1
  86. package/modules/operator-auth/service.mjs +4 -0
  87. package/modules/operator-auth/signin/index.d.mts +1 -1
  88. package/modules/portability/README.md +6 -0
  89. package/modules/portability/catalogue.mjs +1 -1
  90. package/modules/portability/copies.mjs +17 -2
  91. package/modules/portability/index.mjs +2 -0
  92. package/modules/portability/provider-data.mjs +1 -1
  93. package/modules/portability/storage.mjs +5 -1
  94. package/onboarding/README.md +8 -11
  95. package/onboarding/adapter-auth.mjs +6 -38
  96. package/onboarding/adapter-labels.mjs +1 -1
  97. package/onboarding/adapter.mjs +8 -11
  98. package/onboarding/app-fetch.mjs +1 -1
  99. package/onboarding/dependency-approval.mjs +5 -15
  100. package/onboarding/dev-identity.mjs +1 -1
  101. package/onboarding/operator-install.mjs +6 -7
  102. package/onboarding/operator-installer.mjs +5 -5
  103. package/onboarding/operator-prerequisites.mjs +4 -5
  104. package/onboarding/port-probe.mjs +38 -0
  105. package/onboarding/process-diagnostics.mjs +36 -20
  106. package/onboarding/server.mjs +1 -1
  107. package/onboarding/ui/app.js +1 -1
  108. package/operations/README.md +3 -0
  109. package/package.json +4 -2
  110. package/scripts/publish-check/public_hygiene.py +31 -10
  111. package/modules/mail/src/development/viewer-html.mjs +0 -42
  112. package/modules/mail/src/development/viewer.mjs +0 -72
  113. package/modules/operator-auth/dev/badge.mjs +0 -44
@@ -11,7 +11,8 @@ from trust_bundle import anchor_values
11
11
  from png_text import text_chunks
12
12
  from media import sample_spans
13
13
  from c2pa import certificate_spans
14
- URI_AUTHORITY = re.compile(r'''(?i)(?a:(?P<scheme>[a-z][a-z0-9+.-]*:))?//(?P<authority>[^/?#\s<>"']+)''')
14
+ URI_AUTHORITY = re.compile(r'''//(?P<authority>[^/?#\s<>"']+)''')
15
+ SCHEME_CHARACTERS = frozenset('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+.-')
15
16
  # Match raw, complete commit trailer lines; decoded or embedded prose cannot
16
17
  # acquire trailer privileges. Only the address span is omitted from email checks.
17
18
  COAUTHOR = re.compile(
@@ -37,19 +38,39 @@ def without_public_coauthor_addresses(data):
37
38
  return bytes(result)
38
39
 
39
40
 
40
- def email_userinfo(match):
41
- userinfo, _, host = match['authority'].rpartition('@')
42
- # Without a scheme, arbitrary //text can also be a source comment.
43
- if not match['scheme'] and host.lower().split(':', 1)[0] not in REPOSITORY_HOSTS:
44
- return match.group()
45
- # Keep actual email-valued userinfo, including a decoded %40, while
46
- # excluding the host delimiter in an ordinary transport username@host.
47
- return userinfo
41
+ def without_transport_hosts(text):
42
+ pieces, offset = [], 0
43
+ for match in URI_AUTHORITY.finditer(text):
44
+ start = match.start()
45
+ colon = start - 1
46
+ if colon >= offset and text[colon] == ':':
47
+ # The optional scheme regex retried every suffix of a long run.
48
+ # Walk this gap once, stopping at the previous authority's end so
49
+ # matches keep the original substitution's non-overlapping bounds.
50
+ scheme = colon
51
+ while scheme > offset and text[scheme - 1] in SCHEME_CHARACTERS:
52
+ scheme -= 1
53
+ while scheme < colon and not text[scheme].isalpha():
54
+ scheme += 1
55
+ if scheme < colon:
56
+ start = scheme
57
+ userinfo, _, host = match['authority'].rpartition('@')
58
+ # Without a scheme, arbitrary //text can also be a source comment.
59
+ if start == match.start() and host.lower().split(':', 1)[0] not in REPOSITORY_HOSTS:
60
+ pieces.append(text[offset:match.end()])
61
+ else:
62
+ pieces.append(text[offset:start])
63
+ # Keep actual email-valued userinfo, including a decoded %40,
64
+ # while excluding an ordinary transport username@host delimiter.
65
+ pieces.append(userinfo)
66
+ offset = match.end()
67
+ pieces.append(text[offset:])
68
+ return ''.join(pieces)
48
69
 
49
70
 
50
71
  def private_emails(text, config):
51
72
  # URL paths, queries and fragments remain visible to email inspection.
52
- email_text = URI_AUTHORITY.sub(email_userinfo, without_required_notices(text))
73
+ email_text = without_transport_hosts(without_required_notices(text))
53
74
  email_text = re.sub(r'(?i)\b(?a:git@github\.com:)(?=[A-Za-z0-9]|\$\{[A-Za-z_$][A-Za-z0-9_.$]*\})', '', email_text)
54
75
  # A package manager's patch filename joins the name and version with an at sign.
55
76
  version = r'(?:v?[0-9]+(?:\.[0-9]+)*(?:-[A-Za-z0-9-]+)?|[a-f0-9]{40})(?:\.patch)?(?![A-Za-z0-9_.-])'
@@ -1,42 +0,0 @@
1
- export const style = `*{box-sizing:border-box}body{margin:0;background:#f5f7fa;color:#17212e;font:16px/1.6 system-ui,sans-serif}main{max-width:52rem;margin:0 auto;padding:24px 16px}h1{font-size:1.75rem;line-height:1.2}article{margin:20px 0;padding:20px;background:white;border:1px solid #cad2dc;border-radius:12px}h2{font-size:1.2rem}h1,h2,p,a,pre{overflow-wrap:anywhere;word-break:normal}pre{white-space:pre-wrap;font:inherit}a{color:#174fb5}a.open{display:block;padding:16px;margin:20px 0;border-radius:8px;background:#174fb5;color:white;font-weight:700;text-align:center;text-decoration:none;min-height:56px}a.nav{display:inline-block;padding:4px 0}small{color:#465569}`;
2
-
3
- // Added only when the seed declares a theme: its linked rer-theme.css supplies the
4
- // --rer-* tokens. Each falls back to the plain sheet's value, and the focus ring is
5
- // always drawn, so a theme that fails to load leaves a readable, usable page.
6
- export const themedStyle = `.rer-themed body{background:var(--rer-page,#f5f7fa);color:var(--rer-text,#17212e);font-family:var(--rer-font-body,system-ui,sans-serif)}.rer-themed h1,.rer-themed h2{font-family:var(--rer-font-heading,var(--rer-font-body,system-ui,sans-serif))}.rer-themed article{background:var(--rer-surface,#fff);border-color:var(--rer-border,#cad2dc);border-radius:var(--rer-radius,12px)}.rer-themed p,.rer-themed small{color:var(--rer-muted,#465569)}.rer-themed h2,.rer-themed pre{color:var(--rer-text,#17212e)}.rer-themed a{color:var(--rer-link,#174fb5)}.rer-themed a.open{background:var(--rer-accent,#174fb5);color:var(--rer-accent-text,#fff);border-radius:var(--rer-radius,8px)}.rer-themed :focus-visible{outline:3px solid var(--rer-focus,#17212e);outline-offset:3px}`;
7
-
8
- export function escape(value) {
9
- return String(value).replace(/[&<>"']/g, character => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[character]);
10
- }
11
-
12
- // Read link candidates as data only. Never parse or mount mail HTML in the page.
13
- export function firstLink(message) {
14
- for (const body of [message.text, message.html]) {
15
- if (typeof body !== 'string') continue;
16
- for (const match of body.matchAll(/https?:\/\/[^\s<>"']+/gi)) {
17
- try {
18
- const candidate = match[0].replace(/&amp;/g, '&').replace(/[.,;!?]+$/, '');
19
- const url = new URL(candidate);
20
- if (['http:', 'https:'].includes(url.protocol) && url.hostname && !url.username && !url.password) return url.href;
21
- } catch { /* Malformed candidates are ordinary message text. */ }
22
- }
23
- }
24
- return null;
25
- }
26
-
27
- function metadata(row) {
28
- return `<h2>${escape(row.message.subject || '(No subject)')}</h2><p>To: ${escape(row.message.to.join(', '))}</p><p>Received: <time datetime="${escape(new Date(row.createdAt).toISOString())}">${escape(new Date(row.createdAt).toUTCString())}</time></p>`;
29
- }
30
-
31
- export function document(body, theme) {
32
- return `<!doctype html><html lang="en"${theme ? ' class="rer-themed"' : ''}><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="robots" content="noindex, nofollow"><title>Development outbox</title>${theme ? `<link rel="stylesheet" href="${escape(theme)}">` : ''}<style>${theme ? style + themedStyle : style}</style></head><body><main><h1>Development outbox</h1><p>Messages captured on this computer. No email was sent.</p>${body}</main></body></html>`;
33
- }
34
-
35
- export function listing(rows, path) {
36
- return rows.length ? rows.map(row => `<article>${metadata(row)}<p><a href="${escape(`${path}?message=${encodeURIComponent(row.id)}`)}" class="nav">Read message</a></p></article>`).join('') : '<p>No messages yet.</p>';
37
- }
38
-
39
- export function detail(row, path) {
40
- const link = firstLink(row.message);
41
- return `<p><a href="${escape(path)}" class="nav">All messages</a></p><article>${metadata(row)}${link ? `<a class="open" href="${escape(link)}" rel="noreferrer noopener">Open this link</a>` : ''}<h2>Message text</h2><pre>${escape(row.message.text || row.message.html || '')}</pre>${row.message.attachments?.length ? `<p>${row.message.attachments.length} attachment(s) stored with this message.</p>` : ''}</article>`;
42
- }
@@ -1,72 +0,0 @@
1
- import { detail, document, listing, style, themedStyle } from './viewer-html.mjs';
2
-
3
- // The mail module runs as its own module root (in workerd too), so it cannot
4
- // import operator-auth's shared predicate (modules/operator-auth/loopback.mjs);
5
- // this is the same rule: the loopback hosts, 127/8, or a name under .localhost
6
- // (the front door's http://NAME.localhost:PORT).
7
- const localhostName = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+localhost$/;
8
- const isLoopbackHost = hostname => hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '[::1]' || (hostname.length <= 253 && localhostName.test(hostname));
9
-
10
- function localOrigin(origin) {
11
- if (typeof origin !== 'string') return null;
12
- try {
13
- const url = new URL(origin);
14
- const ipv4 = url.hostname.split('.');
15
- const loopback = isLoopbackHost(url.hostname) ||
16
- (ipv4.length === 4 && ipv4[0] === '127' && ipv4.every(part => /^(0|[1-9]\d{0,2})$/.test(part) && Number(part) <= 255));
17
- return loopback && ['http:', 'https:'].includes(url.protocol) && url.origin === origin ? url : null;
18
- } catch { return null; }
19
- }
20
-
21
- function routePath(path) {
22
- return typeof path === 'string' && /^\/(?:[A-Za-z0-9_-]+\/?)+$/.test(path) && !path.includes('//');
23
- }
24
-
25
- // The seed's own served stylesheet, in the grammar operator-auth branding accepts.
26
- function themePath(theme) {
27
- return typeof theme === 'string' && /^\/(?!\/)[A-Za-z0-9._~/-]{1,200}\.css$/.test(theme) && !theme.includes('//') && !theme.includes('/.');
28
- }
29
-
30
- /** Opt-in local route. Rejected requests return null without touching the outbox. */
31
- export function createDevelopmentOutboxHandler({ local, origin, outbox, path = '/__dev/outbox', theme } = {}) {
32
- if (theme !== undefined && !themePath(theme)) throw new TypeError('Declare the outbox theme as a same-origin path to the seed\'s served .css file');
33
- const configured = local === true ? localOrigin(origin) : null;
34
- if (!configured || !routePath(path)) return async () => null;
35
- if (!outbox || typeof outbox.list !== 'function' || typeof outbox.get !== 'function') throw new TypeError('Invalid development outbox reader');
36
- const sheet = theme ? style + themedStyle : style;
37
- const styles = hash => theme ? `style-src 'self' 'sha256-${hash}'; font-src 'self'; img-src 'self'` : `style-src 'sha256-${hash}'`;
38
- let hash;
39
- async function response(body, status = 200, head = false) {
40
- hash ??= crypto.subtle.digest('SHA-256', new TextEncoder().encode(sheet)).then(bytes => btoa(String.fromCharCode(...new Uint8Array(bytes))));
41
- return new Response(head ? null : document(body, theme), { status, headers: {
42
- 'Content-Type': 'text/html; charset=utf-8',
43
- 'Cache-Control': 'no-store',
44
- 'X-Robots-Tag': 'noindex, nofollow',
45
- 'X-Content-Type-Options': 'nosniff',
46
- 'Referrer-Policy': 'no-referrer',
47
- 'Content-Security-Policy': `default-src 'none'; script-src 'none'; ${styles(await hash)}; base-uri 'none'; form-action 'none'; frame-ancestors 'none'; object-src 'none'`,
48
- ...(status === 405 ? { Allow: 'GET, HEAD' } : {}),
49
- } });
50
- }
51
- return async function handle(request) {
52
- let url;
53
- try { url = new URL(request.url); } catch { return null; }
54
- if (url.origin !== configured.origin || url.username || url.password || request.headers.get('host') !== configured.host || url.pathname !== path) return null;
55
- const requestOrigin = request.headers.get('origin');
56
- if ((requestOrigin !== null && requestOrigin !== configured.origin) || request.headers.get('sec-fetch-site') === 'cross-site') return null;
57
- const head = request.method === 'HEAD';
58
- if (request.method !== 'GET' && !head) return response('<p>Use GET to read messages.</p>', 405);
59
- if ([...url.searchParams.keys()].some(key => key !== 'message') || url.searchParams.getAll('message').length > 1) return response('<p>Invalid message request.</p>', 400, head);
60
- try {
61
- if (url.searchParams.has('message')) {
62
- const id = url.searchParams.get('message');
63
- if (!id || id.length > 128) return response('<p>Invalid message request.</p>', 400, head);
64
- const row = await outbox.get(id);
65
- return response(row ? detail(row, path) : '<p>Message not found or expired.</p>', row ? 200 : 404, head);
66
- }
67
- return response(listing(await outbox.list(), path), 200, head);
68
- } catch {
69
- return response('<p>The development outbox is unavailable.</p>', 503, head);
70
- }
71
- };
72
- }
@@ -1,44 +0,0 @@
1
- import { EXCHANGE_SCRIPT, exchangeHashes } from '../dev-gate.mjs';
2
- import { escapeHtml } from '../http.mjs';
3
- import { allow, sha256 } from '../csp.mjs';
4
-
5
- // A slim bar at the top of the document, in normal flow so the page below it
6
- // starts after it and nothing is ever covered. A grid body (the frames that
7
- // centre their card) gives the bar its own auto row and keeps the card centred
8
- // in the rest.
9
- const STYLE = 'body:has(>#rer-dev-badge){grid-template-rows:auto 1fr}#rer-dev-badge{grid-column:1/-1;justify-self:stretch;align-self:start;position:relative;z-index:2147483647;box-sizing:border-box;width:100%;margin:0 0 12px;padding:6px 12px;border-radius:8px;background:#111827;color:#f9fafb;font:13px/1.5 system-ui,sans-serif;text-align:left}#rer-dev-badge summary{min-width:24px;min-height:24px;cursor:pointer;overflow-wrap:anywhere}#rer-dev-badge ul{margin:6px 0 0;padding:0;list-style:none;display:flex;flex-wrap:wrap;gap:4px 16px}#rer-dev-badge li{margin:0}#rer-dev-badge a{display:inline-block;min-width:24px;min-height:24px;color:#bfdbfe;text-decoration:underline}#rer-dev-badge a[aria-current]{color:#fff;font-weight:700}#rer-dev-badge a:focus-visible,#rer-dev-badge summary:focus-visible{outline:2px solid #fff;outline-offset:2px}';
10
- let styleHash;
11
-
12
- function badgeHtml({ session, choices }) {
13
- const current = session ? choices.find(choice => choice.email === session.operator.email)?.as : 'signed-out';
14
- const label = session ? `Dev: ${escapeHtml(session.operator.email)} (${escapeHtml(session.operator.role)})` : 'Dev: signed out';
15
- const links = [...choices.map(choice => choice.as), 'signed-out'].map(as => `<li><a href="/auth/dev/enter?as=${encodeURIComponent(as)}"${as === current ? ' aria-current="true"' : ''}>${as === 'signed-out' ? 'Sign out' : `Switch to ${escapeHtml(as)}`}</a></li>`).join('');
16
- return `<style>${STYLE}</style><aside id="rer-dev-badge" aria-label="Local development identity"><details><summary>${label}</summary><ul>${links}</ul></details></aside>`;
17
- }
18
-
19
- /** Adds the fragment key exchange (root only) and the badge to an HTML document. */
20
- export async function decorate(response, { exchange, badge }) {
21
- // The Lobby is deliberately script-free. RER_OPEN uses /__dev/key, whose
22
- // dedicated document exchanges the fragment under its own exact-hash CSP.
23
- if (response.headers.get('x-rer-document') === 'lobby') exchange = false;
24
- if ((!exchange && !badge) || !response.headers.get('content-type')?.toLowerCase().startsWith('text/html') || !response.body) return response;
25
- let bar = '', scripts = '';
26
- const headers = new Headers(response.headers);
27
- let policy = headers.get('content-security-policy');
28
- if (badge) {
29
- bar = badgeHtml(badge);
30
- if (policy) policy = allow(policy, 'style-src', styleHash ??= await sha256(STYLE));
31
- }
32
- if (exchange) {
33
- scripts = `<script>${EXCHANGE_SCRIPT}</script>`;
34
- if (policy) policy = allow(allow(policy, 'script-src', (await exchangeHashes()).script), 'connect-src', "'self'");
35
- }
36
- if (policy) headers.set('content-security-policy', policy);
37
- headers.delete('content-length');
38
- // The bar opens the body; the key exchange script stays at its end.
39
- let html = await response.text();
40
- const open = /<body\b[^>]*>/i.exec(html), at = open ? open.index + open[0].length : 0, end = html.lastIndexOf('</body>');
41
- if (end >= at) html = html.slice(0, end) + scripts + html.slice(end); else html += scripts;
42
- html = html.slice(0, at) + bar + html.slice(at);
43
- return new Response(html, { status: response.status, statusText: response.statusText, headers });
44
- }