@runeditrun/rer 0.2.79 → 0.2.81

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 (147) hide show
  1. package/README.md +17 -3
  2. package/cli/README.md +25 -13
  3. package/cli/authoring.mjs +14 -0
  4. package/cli/contract.mjs +25 -5
  5. package/cli/demo-host.mjs +4 -2
  6. package/cli/deploy-needs.mjs +4 -2
  7. package/cli/dev-identity.mjs +2 -2
  8. package/cli/export.mjs +1 -1
  9. package/cli/inspect.mjs +38 -2
  10. package/cli/ledger-refusal.mjs +18 -0
  11. package/cli/main.mjs +8 -2
  12. package/cli/managed-server.mjs +1 -1
  13. package/cli/parse.mjs +7 -6
  14. package/cli/portability-migrations.mjs +30 -11
  15. package/cli/portability-worker.mjs +4 -1
  16. package/cli/portability.mjs +8 -2
  17. package/cli/production-auth.mjs +2 -1
  18. package/cli/production-mail.mjs +36 -9
  19. package/cli/project.mjs +5 -14
  20. package/cli/release.mjs +6 -5
  21. package/cli/site-hosting.mjs +90 -0
  22. package/cli/site-preview.mjs +4 -1
  23. package/cli/site-render.mjs +3 -2
  24. package/cli/site.mjs +8 -4
  25. package/edition-authoring/adopt.mjs +39 -0
  26. package/edition-authoring/base-acknowledgements.mjs +24 -0
  27. package/edition-authoring/base-copies.mjs +427 -0
  28. package/edition-authoring/cli.mjs +85 -0
  29. package/edition-authoring/copy-checkout.mjs +69 -0
  30. package/edition-authoring/files.mjs +15 -2
  31. package/edition-authoring/lock.mjs +48 -0
  32. package/edition-authoring/offline-git.mjs +28 -0
  33. package/edition-authoring/parent-comparison.mjs +77 -0
  34. package/edition-authoring/projection-lock.mjs +38 -0
  35. package/edition-authoring/release.mjs +48 -0
  36. package/edition-authoring/runtime-dependencies.mjs +108 -0
  37. package/edition-authoring/sources.mjs +114 -0
  38. package/edition-authoring/updates.mjs +105 -0
  39. package/global/CHANGELOG.md +24 -0
  40. package/global/README.md +17 -3
  41. package/global/cli/install.mjs +3 -1
  42. package/global/main.mjs +9 -12
  43. package/modules/container/build.mjs +1 -1
  44. package/modules/d1-transport/index.mjs +68 -21
  45. package/modules/demo/README.md +16 -2
  46. package/modules/demo/declaration.mjs +21 -0
  47. package/modules/demo/input-path.mjs +18 -0
  48. package/modules/demo/label.d.mts +1 -1
  49. package/modules/demo/label.mjs +10 -5
  50. package/modules/demo/navigation.mjs +148 -0
  51. package/modules/demo/run-url.mjs +9 -0
  52. package/modules/demo/vite.d.mts +7 -2
  53. package/modules/demo/vite.mjs +17 -2
  54. package/modules/demo-host/README.md +5 -3
  55. package/modules/demo-host/page-style.mjs +2 -2
  56. package/modules/demo-host/pages.mjs +3 -3
  57. package/modules/demo-host/plan.mjs +6 -4
  58. package/modules/demo-host/theme.mjs +5 -2
  59. package/modules/dependencies/auth.mjs +2 -2
  60. package/modules/deploy-kit/README.md +19 -15
  61. package/modules/deploy-kit/owner-cli.mjs +1 -1
  62. package/modules/deploy-kit/owner.mjs +8 -1
  63. package/modules/deploy-kit/readiness-window.mjs +3 -3
  64. package/modules/erasure/README.md +10 -5
  65. package/modules/import-kit/src/d1/README.md +15 -9
  66. package/modules/import-kit/src/d1/apply-effects.ts +33 -0
  67. package/modules/import-kit/src/d1/apply.ts +46 -14
  68. package/modules/import-kit/src/d1/atomic-prefix.ts +64 -0
  69. package/modules/import-kit/src/d1/budget.ts +48 -26
  70. package/modules/import-kit/src/d1/compressed-plan.ts +9 -2
  71. package/modules/import-kit/src/d1/database.ts +2 -1
  72. package/modules/import-kit/src/d1/jobs.ts +2 -1
  73. package/modules/import-kit/src/d1/plans.ts +4 -2
  74. package/modules/import-kit/src/d1/verified-plan.ts +63 -0
  75. package/modules/import-kit/src/types.ts +3 -1
  76. package/modules/integrations/core/README.md +2 -2
  77. package/modules/mail/README.md +4 -3
  78. package/modules/mail/pnpm-lock.yaml +16 -0
  79. package/modules/operator-auth/README.md +92 -3
  80. package/modules/operator-auth/accounts/admin.mjs +52 -20
  81. package/modules/operator-auth/accounts/audit.mjs +24 -0
  82. package/modules/operator-auth/accounts/business-team.mjs +91 -0
  83. package/modules/operator-auth/accounts/domain-audit.mjs +24 -0
  84. package/modules/operator-auth/accounts/native.mjs +6 -2
  85. package/modules/operator-auth/accounts/provider-control.mjs +7 -4
  86. package/modules/operator-auth/accounts/provider-setup.mjs +34 -0
  87. package/modules/operator-auth/accounts/settings-page.mjs +26 -4
  88. package/modules/operator-auth/accounts/status.mjs +7 -2
  89. package/modules/operator-auth/accounts/store.mjs +32 -6
  90. package/modules/operator-auth/business-settings.mjs +40 -0
  91. package/modules/operator-auth/conformance/README.md +1 -1
  92. package/modules/operator-auth/dev/index.mjs +22 -4
  93. package/modules/operator-auth/dev/refusal.mjs +19 -0
  94. package/modules/operator-auth/docs/README.md +6 -5
  95. package/modules/operator-auth/docs/tanstack-start.md +1 -1
  96. package/modules/operator-auth/docs/vite-spa.md +5 -6
  97. package/modules/operator-auth/identity/email-link/index.mjs +1 -1
  98. package/modules/operator-auth/identity/oidc/admin-audit.mjs +31 -0
  99. package/modules/operator-auth/identity/oidc/index.mjs +12 -5
  100. package/modules/operator-auth/identity/oidc/store.mjs +2 -0
  101. package/modules/operator-auth/index.d.mts +41 -2
  102. package/modules/operator-auth/page.mjs +14 -0
  103. package/modules/operator-auth/representation.mjs +83 -0
  104. package/modules/operator-auth/routes.mjs +31 -3
  105. package/modules/operator-auth/service.mjs +8 -3
  106. package/modules/operator-auth/signin/index.mjs +1 -1
  107. package/modules/portability/README.md +173 -15
  108. package/modules/portability/bookkeeping.mjs +3 -3
  109. package/modules/portability/bridge.mjs +5 -4
  110. package/modules/portability/catalogue.mjs +12 -8
  111. package/modules/portability/cli.mjs +5 -1
  112. package/modules/portability/export.mjs +10 -14
  113. package/modules/portability/format.mjs +12 -1
  114. package/modules/portability/http-errors.mjs +51 -0
  115. package/modules/portability/http.mjs +4 -1
  116. package/modules/portability/import-lease.mjs +13 -2
  117. package/modules/portability/import.mjs +10 -0
  118. package/modules/portability/index.d.mts +13 -2
  119. package/modules/portability/index.mjs +3 -2
  120. package/modules/portability/ledgers.mjs +27 -4
  121. package/modules/portability/references.mjs +20 -0
  122. package/modules/portability/schema-identity.mjs +13 -0
  123. package/modules/portability/schema-legacy.mjs +21 -0
  124. package/modules/portability/sqlite-tokens.mjs +121 -0
  125. package/modules/release/README.md +94 -11
  126. package/modules/release/github-verify.mjs +30 -9
  127. package/modules/release/sign.mjs +4 -2
  128. package/modules/release/signature.mjs +14 -7
  129. package/modules/release/signing-cli.mjs +2 -1
  130. package/modules/release/statement.mjs +2 -2
  131. package/modules/release/vectors/generate.mjs +1 -0
  132. package/modules/release/vectors/publisher-projects.mjs +133 -0
  133. package/modules/release/vectors/release-signature-vectors.json +5195 -0
  134. package/modules/release/verify.mjs +5 -1
  135. package/modules/site/docs-search/search.css +1 -1
  136. package/onboarding/README.md +16 -4
  137. package/onboarding/adapter.mjs +5 -1
  138. package/onboarding/schema/SETUP.schema.json +68 -1
  139. package/onboarding/schema/business-field-inputs.mjs +36 -0
  140. package/onboarding/schema/json-schema.mjs +6 -2
  141. package/onboarding/schema/setup-validation.mjs +23 -3
  142. package/onboarding/server.mjs +1 -1
  143. package/onboarding/setup-manifest.mjs +2 -0
  144. package/onboarding/start-origin-diagnostic.mjs +24 -0
  145. package/onboarding/ui/style.css +9 -9
  146. package/package.json +1 -1
  147. package/scripts/publish-check/README.md +1 -1
@@ -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:12px;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}
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></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>`,
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. Messages and account changes are simulated.</li><li>It ends after an hour, or 15 idle minutes.</li><li>Then it is deleted. Nobody else can see it.</li></ul>
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).origin)}/run">Run ${name} yourself</a></p>` });
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 stylesheets = [prefix + '/rer-theme.css', ...['/fonts/fonts.css', '/rer-theme.css'].filter(path => files.has(path))];
26
- return { paths, css: inlineTheme(files, stylesheets) };
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
  }
@@ -35,7 +35,7 @@ export function linkedProviders(options) {
35
35
  async links(){const p=await current();const links=[...await staticProviders?.links()??[],...(p!==staticProviders?await p?.links()??[]:[])];return [...new Map(links.map(link=>[link.id,link])).values()];},
36
36
  // The Auth dependency is linked and unlinked through its own approval routes;
37
37
  // a static provider keeps its own pin controls.
38
- async relink(id){if(id==='auth')throw new Error('Use the dependency link with fresh local owner proof');return staticProviders.relink(id);},
39
- async unlink(id){if(id==='auth')throw new Error('Use the dependency unlink with fresh local owner proof');return staticProviders.unlink(id);},
38
+ async relink(id, audit){if(id==='auth')throw new Error('Use the dependency link with fresh local owner proof');return staticProviders.relink(id, audit);},
39
+ async unlink(id, audit){if(id==='auth')throw new Error('Use the dependency unlink with fresh local owner proof');return staticProviders.unlink(id, audit);},
40
40
  };
41
41
  }
@@ -40,7 +40,7 @@ The maintained default-seed `/health` returns the existing `status: 'ok'` plus t
40
40
  } }
41
41
  ```
42
42
 
43
- Assets upload with `run_worker_first: true` (`RUN_WORKER_FIRST` in `render.mjs`). Every request reaches the Worker first, so the seed's routing, origin admission, `no-store` document policy and private-path refusals decide what is served, and the Base delivery producer accepts no other setting. A built file therefore reaches the browser only through the Worker: seed entries call `staticAssetResponse(request, env)` from `foundation/runtime/static-assets.ts` first. After the deploy identity passes, health requests one built file (the first artifact asset that is neither an HTML document nor under a dot path) without credentials, retries a 5xx or transport failure once within the existing readiness deadline, and fails with `asset-http-failed` unless it answers 200; the result is recorded as `health.asset`. `rer verify` serves the local build with the same setting (`cli/hosted-output.mjs`).
43
+ Assets upload with `run_worker_first: true` (`RUN_WORKER_FIRST` in `render.mjs`). Every request reaches the Worker first, so the seed's routing, origin admission, `no-store` document policy and private-path refusals decide what is served, and the Base delivery producer accepts no other setting. A built file therefore reaches the browser only through the Worker: seed entries call `staticAssetResponse(request, env)` from `foundation/runtime/static-assets.ts` first. After the deploy identity passes, health requests one built file (the first artifact asset that is neither an HTML document nor under a dot path) without credentials, polls a missing asset after upload within the smaller of 60 seconds and the remaining readiness window, replays 5xx and transport failures at most once, and fails with `asset-http-failed` unless it answers 200; the result is recorded as `health.asset`. `rer verify` serves the local build with the same setting (`cli/hosted-output.mjs`).
44
44
 
45
45
  The controller supplies the two public variables and Cloudflare version-metadata binding. The parent owns default-seed source/types, package scripts, shared manifests and workflows. Keep the staged-deploy descriptor blocked until the three-stage isolation and actual build/health integration pass; the original deploy-then-health executor cannot safely run installation/build with its credentials.
46
46
 
@@ -48,7 +48,7 @@ The controller supplies the two public variables and Cloudflare version-metadata
48
48
 
49
49
  `deploy({api,plan,artifact,artifactSha256,previousReceipt,env,fetch})` is the shared implementation for deploy and stage. Plans are controller-owned and validated; do not derive a secret-bearing plan from executable project configuration. `defaultStagePlan` demonstrates the full schema. Optional R2 `{binding,name}`, Queue `{binding,name,consumer?}`, DO `{binding,className,storage:'sqlite'|'classic'}`, and secret `{binding,environment}` declarations are supported. New DOs must use SQLite; existing classic namespaces are reusable. Namespace creation occurs through Worker upload migrations, with old/new migration tags, then authenticated namespace readback. No namespace create endpoint is invented. Cron and queue consumers reconcile after Worker creation. Conflicting consumers and resource identities fail; resources/data are never deleted.
50
50
 
51
- Cron reads require the documented `result: {schedules: [...]}` envelope, including valid unique Cron strings; bare arrays and partial/malformed results fail. Before changing an existing Worker, deployment reads its schedules and rejects any Cron outside the requested plan with `cron-drift`, before resource writes, SQL migrations or Worker upload. Trigger reconciliation repeats that read before any trigger write. This applies to ordinary changed-source upgrades with or without a prior receipt. The kit may add requested schedules; it never intentionally removes existing schedules. Removing a Cron from the plan while it still exists remotely requires a separate reviewed removal first. Every changed upload reapplies its nonempty declared Cron set after workers.dev activation, even when the Worker-scoped list already matches. The kit reads the exact schedule set back after the write and checks that the active deployment identity remained stable. A declared Cron also requires the authenticated active version to report a `scheduled` handler; absent detection fails with `missing-scheduled-handler`. These checks establish provider configuration, not proof that a scheduled invocation has executed. Dispatch is the provider's: on the RunEditRun account (11 October 2026) a correctly registered Cron started only at the account scheduler's next refresh, observed 60 to 106 minutes apart, so a first tick can arrive well after Cloudflare's documented 15 minutes; a cleared schedule keeps running, and a deleted Worker keeps being invoked (as `internalError`), until a later refresh. A redeploy keeps the existing dispatch: the first run after it executes the new version. Judge first-deploy Cron by the seed's own scheduled-run record, not by a short watch. Unchanged deployment and health require the exact desired schedule set and perform no repairs. Callers must serialize deployments and out-of-band schedule edits for a Worker: the provider schedule replacement API offers no conditional update in this interface.
51
+ Cron reads require the documented `result: {schedules: [...]}` envelope, including valid unique Cron strings; bare arrays and partial/malformed results fail. Before changing an existing Worker, deployment reads its schedules and rejects any Cron outside the requested plan with `cron-drift`, before resource writes, SQL migrations or Worker upload. Trigger reconciliation repeats that read before any trigger write. This applies to ordinary changed-source upgrades with or without a prior receipt. The kit may add requested schedules; it never intentionally removes existing schedules. Removing a Cron from the plan while it still exists remotely requires a separate reviewed removal first. Every changed upload reapplies its nonempty declared Cron set after workers.dev activation, even when the Worker-scoped list already matches. The kit reads the exact schedule set back after the write and checks that the active deployment identity remained stable. A declared Cron also requires the authenticated active version to report a `scheduled` handler; absent detection fails with `missing-scheduled-handler`. These checks establish provider configuration, not proof that a scheduled invocation has executed. Dispatch is the provider's. The following account-specific observation is historical and unverified here; no independent receipt is retained in this repository. On the RunEditRun account (11 October 2026) a correctly registered Cron started only at the account scheduler's next refresh, observed 60 to 106 minutes apart, so a first tick can arrive well after Cloudflare's documented 15 minutes; a cleared schedule keeps running, and a deleted Worker keeps being invoked (as `internalError`), until a later refresh. A redeploy keeps the existing dispatch: the first run after it executes the new version. Judge first-deploy Cron by the seed's own scheduled-run record, not by a short watch. Unchanged deployment and health require the exact desired schedule set and perform no repairs. Callers must serialize deployments and out-of-band schedule edits for a Worker: the provider schedule replacement API offers no conditional update in this interface.
52
52
 
53
53
  `workerConsumerScript(consumer)` (also exported from `index.mjs`) decodes Worker consumer identities from either documented `script_name` or the observed GET response string `script`. It returns the exact name using the plan's resource-name grammar, or `null` for missing, malformed, conflicting, or non-Worker identities. If both fields are present, each must be valid and both must agree; a malformed alias is never ignored. Reconciliation checks every consumer on queues with a requested consumer before any trigger write and rejects foreign or duplicate consumers. Writes continue to use the documented `script_name` request field. Read-only health and retained-receipt repeats accept either response variant without repairs.
54
54
 
@@ -94,7 +94,7 @@ A declaration may also bind another owner-deployed Worker and may keep its own w
94
94
  "workersDev": false }
95
95
  ```
96
96
 
97
- A service's Worker name is derived from its `project` and this deploy's environment, so the example above binds `egress-service-production`. `allowedHosts` becomes the binding's `props` (`{allowedHosts}`), which the bound Worker reads as `ctx.props`. The binding is uploaded and read back like every other binding, so a changed `props` is reported as `binding-readback-mismatch`. Before any write, deploy reads each bound Worker. If it is absent, deploy refuses with `service-worker-missing` and resource `service:<worker>`; deploy that Worker first. `workersDev: false` keeps the route off: an enabled route is switched off on upload, the receipt's `origin` is `null`, and health uses provider readback only, because there is no public `/health` to request. [modules/egress-service](../egress-service/README.md) is the Worker this exists for.
97
+ A service's Worker name is derived from its `project` and this deploy's environment, so the example above binds `egress-service-production`. `allowedHosts` becomes the binding's `props` (`{allowedHosts}`), which the bound Worker reads as `ctx.props`. The binding is uploaded and read back like every other binding, so a changed `props` is reported as `binding-readback-mismatch`. Before any write, deploy reads each bound Worker. If it is absent, deploy refuses with `service-worker-missing` and resource `service:<worker>`; deploy that Worker first. `workersDev: false` keeps the route off: an enabled route is switched off on upload, the receipt's `origin` is `null`, and health uses provider readback only, because there is no public `/health` to request. [modules/egress-service](https://github.com/runeditrun/base/blob/main/modules/egress-service/README.md) is the Worker this exists for.
98
98
 
99
99
  `ownerTarget`, `ownerPlan`, `ownerDeploy` and `ownerHealth` (exported from `index.mjs`) are the same steps for a seed's own script. A seed script can compute vars before calling `ownerPlan`.
100
100
 
@@ -104,8 +104,8 @@ Ownership lives in a state file, by default `.rer/deploy/<environment>.json` und
104
104
  - **Re-run.** The same build writes nothing: no create, upload, migration, trigger or secret write, and the state file stays byte-identical. A later release that declares a new resource creates only that resource.
105
105
  - **Partial failure and resume.** The kit records each create as `pending` before the request and `created` with the provider id after it. A failed create leaves `pending`. On the next run an absent pending name is created again, and a present one is refused as `uncertain-resource-create`, because a lost response cannot prove who created it. Inspect it: if it is the empty resource from the interrupted run, delete it and re-run. A Worker upload is recorded as created when the upload succeeds, so a failure after it resumes with one fresh upload. If the response to the very first upload is lost, the Worker exists but is still `pending`. The kit records the upload's fingerprint before sending it. When an upload's response or its readback is lost (a first upload or a redeploy), the next run accepts the live version as this deploy's own only when it carries that fingerprint both as its `RER_DEPLOY_FINGERPRINT` binding and as its `rer-deploy:<fingerprint>` annotation: it records the live version id, deployment id and etag, then resumes with one fresh upload. Any other live version is refused, as `uncertain-resource-create` with no prior receipt and as `owned-resource-replaced` with one. If the uncertain Worker cannot be authenticated, inspect it and delete it only after confirming that it is the kit-created Worker and that its Durable Object data is disposable. Back up any needed data before deleting it. Migration claims keep the rules under Migration safety.
106
106
  - **Drift.** A created resource that has gone is refused as `owned-resource-missing`; one replaced under the same name is refused as `owned-resource-replaced`. The kit never deletes or recreates them. This covers D1, KV, Queues and R2 (a bucket is identified by its creation date; a state file written before that was recorded keeps working and is not checked for that bucket). For the Worker, the live deployment (version id, deployment id and etag) must be the last receipt's before any write; someone else's upload under the same name is refused as `owned-resource-replaced` and never overwritten. Immediately before the Worker PUT, the kit rechecks every saved resource identity, including resources omitted from the current plan, then the Worker identity. A replacement during provisioning or asset upload is refused before the upload intent or receipt is saved. An interrupted successful upload may resume only when the live version id, deployment id and etag match the identity saved immediately after that upload, or, when its readback was lost before that identity was saved, when the live version carries the fingerprint saved immediately before that upload (binding and annotation). A receipt's historical fingerprint never overrides a receipt mismatch.
107
- - **Lost upgrade response.** If an upgrade response is lost and the live identity no longer matches the receipt, the kit refuses rather than guessing ownership. A [Cloudflare rollback](https://developers.cloudflare.com/workers/versions-and-deployments/rollbacks/) creates a new deployment, so it does not restore the recorded identity. Recover with a new environment and a fresh state path, or back up the state and any needed data, confirm ownership, and follow the cleanup under "If the state file is lost" with a fresh `--state` path.
108
- - **Settling listings.** Right after a create or delete, an account listing can briefly disagree with its own page counts (`provider-partial-list`: on 13 October 2026 D1's `total_count` lagged its rows by about 7 seconds after a create). Owner-mode deploy, health and removal discard such a snapshot and list again from the start for up to 30 seconds with a short backoff; a partial listing is never accepted.
107
+ - **Lost upgrade response.** An interrupted upload can resume when its saved upload intent authenticates the live version by the pending fingerprint binding and annotation, or by its saved provider identity. Otherwise deployment refuses the mismatch. A [Cloudflare rollback](https://developers.cloudflare.com/workers/versions-and-deployments/rollbacks/) creates a new deployment, so it does not restore the recorded identity.
108
+ - **Settling listings.** Right after a create or delete, an account listing can briefly disagree with its own page counts (`provider-partial-list`: on 13 October 2026 D1's `total_count` lagged its rows by about 7 seconds after a create). Owner-mode deploy, health and removal discard such a snapshot and list again from the start for up to 120 seconds with a short backoff; a partial listing is never accepted.
109
109
  - **One run at a time.** A deploy takes an exclusive lock file, `<state file>.lock`, for the whole run and removes it at the end, even after a failure. A second run on the same state file is refused as `owner-state-locked` before any provider request. If a run was killed (power loss, `kill -9`) and no deploy is running, delete the lock file by hand.
110
110
 
111
111
  The CLI prints JSON: refusal codes and resource names only, never inputs, tokens or provider bodies.
@@ -348,10 +348,12 @@ the standalone window: 2, 2, 4, 8, 10, 10 ... seconds. Only transport failures,
348
348
  names another Worker version (the edge still serving the previous version just
349
349
  after the upload). A redirect, any other status, a malformed or unhealthy body
350
350
  and a wrong identity from the uploaded version itself fail at once. The one
351
- built file then requested must answer 200; after an upload its 404, 5xx and
352
- transport failures are retried for up to 60 seconds, since an edge still serving
353
- the previous version does not have the new build's hashed files (seen live on
354
- 13 October 2026).
351
+ built file then requested must answer 200. After an upload, only asset 404
352
+ propagation receives repeated polling within the smaller of 60 seconds and the
353
+ remaining readiness window; asset 5xx and transport failures receive at most one
354
+ replay. A historical, unverified 13 October 2026 observation attributed missing
355
+ hashed files to an edge still serving the previous build; no independent receipt
356
+ is retained here.
355
357
  Each request is capped by both the 30-second request limit and the remaining
356
358
  budget, and no request starts at the deadline. An unchanged repeat uses the
357
359
  existing library window and does not record first-upload readiness attempts.
@@ -370,9 +372,10 @@ retains the existing window, retrying only 404, 503 and network failures for
370
372
  Custom-hook `rer deploy` finalization gets a separate 90-second `/health` wait
371
373
  after the hook returns, using the current recorded Worker version when available.
372
374
  The hook can already have claimed the owner and retired its token, which creates
373
- another version and can exhaust the original upload window. First hosted Slate
374
- and Pencil deploys on 15 October 2026 failed this final gate even though health
375
- named the right commit seconds later. Reusing the existing 90-second propagation
375
+ another version and can exhaust the original upload window. A historical,
376
+ unverified report says first hosted Slate and Pencil deploys on 15 October 2026
377
+ failed this final gate even though health named the right commit seconds later;
378
+ no independent receipt is retained here. Reusing the existing 90-second propagation
376
379
  budget gives this final observation the same bounded allowance, without spending
377
380
  it on the hook's earlier work. Transport failures and healthy identity mismatches wait;
378
381
  permanent HTTP or malformed responses still fail. The deadline includes request
@@ -415,8 +418,9 @@ untrusted response prefixes are never written into that record.
415
418
 
416
419
  ## Read-only teardown verification
417
420
 
418
- The kit does not perform deletes. After a seed has validated its receipt and
419
- removed only its authenticated disposable resources, call
421
+ `verifyTeardown` performs no deletes. Explicit owner-account removal deletes
422
+ authenticated owned resources and purges owned R2 objects. After a seed has
423
+ validated its receipt and removed only its authenticated disposable resources, call
420
424
  `verifyTeardown({api, plan, receipt})`. The default CLI exposes
421
425
  `node modules/deploy-kit/cli.mjs verify-teardown` with the same controller inputs.
422
426
  The target must be the exact receipt Worker with a `rer-seedproof-` prefix or
@@ -479,7 +483,7 @@ Only the ordinary named service binding is uploaded. This supports service-owned
479
483
  narrowing where Cloudflare omits service-binding `props` from settings/version
480
484
  readback. Ordinary `allowedHosts` still maps to `props` and retains strict
481
485
  readback; missing props are never silently accepted. See the
482
- [egress service guide](../egress-service/README.md).
486
+ [egress service guide](https://github.com/runeditrun/base/blob/main/modules/egress-service/README.md).
483
487
 
484
488
  ### List completion and deployment failures
485
489
 
@@ -68,7 +68,7 @@ export async function main(argv = process.argv.slice(2), env = process.env, {fet
68
68
  if (!requestWindow?.active) return undefined;
69
69
  const remaining = requestWindow.remaining();
70
70
  assert(remaining > 0, 'deployment-readiness-timeout');
71
- return AbortSignal.timeout(Math.max(1, Math.ceil(remaining)));
71
+ return requestWindow.timeout(Math.max(1, Math.ceil(remaining)));
72
72
  };
73
73
  fetch = (input, init = {}) => {
74
74
  const deadline = requestSignal();
@@ -28,6 +28,13 @@ const ENTRY_KEYS = {d1:['binding'],r2:['binding','locationHint'],kv:['binding'],
28
28
 
29
29
  export function refuse(code, kind, name) { const error = new Error(code); error.resource = `${kind}:${name}`; return error; }
30
30
 
31
+ /** Where a declaration deploys: `platforms` when it lists them, else Workers alone. */
32
+ export function ownerPlatforms(declaration) {
33
+ const platforms = declaration.platforms ?? ['workers'];
34
+ assert(Array.isArray(platforms) && platforms.length > 0 && new Set(platforms).size === platforms.length && platforms.every(item => ['workers','container'].includes(item)), 'invalid-platforms');
35
+ return platforms;
36
+ }
37
+
31
38
  export function ownerWorkerName(project, environment) {
32
39
  assert(typeof project === 'string' && /^(?:[a-z0-9][a-z0-9-]*\/)?[a-z0-9-]+$/.test(project) && segment.test(project.split('/').at(-1)), 'invalid-owner-project');
33
40
  assert(typeof environment === 'string' && environment.length <= 32 && segment.test(environment), 'invalid-owner-environment');
@@ -116,7 +123,7 @@ export function localOnlyBinding(declaration, localOnlyKeys = []) {
116
123
  export function ownerPlan(target, declaration, artifact, { localOnlyKeys = [], env = {} } = {}) {
117
124
  assert(declaration?.version === 1 && typeof declaration === 'object' && Object.keys(declaration).every(key => DECLARATION_KEYS.includes(key)), 'invalid-owner-declaration');
118
125
  assert(declaration.publicSettings === undefined || Array.isArray(declaration.publicSettings) && new Set(declaration.publicSettings).size === declaration.publicSettings.length && declaration.publicSettings.every(name => typeof name === 'string' && /^[A-Z][A-Z0-9_]*$/.test(name)), 'invalid-public-settings');
119
- if (declaration.platforms !== undefined) assert(Array.isArray(declaration.platforms) && declaration.platforms.length > 0 && new Set(declaration.platforms).size === declaration.platforms.length && declaration.platforms.every(item => ['workers','container'].includes(item)), 'invalid-platforms');
126
+ ownerPlatforms(declaration);
120
127
  if (declaration.container !== undefined) {
121
128
  const config=declaration.container;
122
129
  assert(config&&typeof config==='object'&&!Array.isArray(config)&&Object.keys(config).every(key=>['engine','cacheContract','runner','hostVariables','ingress'].includes(key))&&['node','workerd'].includes(config.engine),'invalid-container');
@@ -3,11 +3,11 @@ import { assert } from './validation.mjs';
3
3
 
4
4
  // A single, in-memory deadline travels with this upload. It is deliberately not
5
5
  // persisted: an old receipt is not evidence of a fresh propagation window.
6
- export function readinessWindow({ totalMs = 90000, clock = () => performance.now(), sleep = ms => new Promise(resolve => setTimeout(resolve, ms)) } = {}) {
6
+ export function readinessWindow({ totalMs = 90000, clock = () => performance.now(), sleep = ms => new Promise(resolve => setTimeout(resolve, ms)), timeout = ms => AbortSignal.timeout(ms) } = {}) {
7
7
  assert(Number.isFinite(totalMs) && totalMs > 0 && totalMs <= 90000, 'invalid-health-bound');
8
8
  let start;
9
9
  return {
10
- clock, sleep,
10
+ clock, sleep, timeout,
11
11
  get active() { return start !== undefined; },
12
12
  start() { start ??= clock(); },
13
13
  remaining() { return start === undefined ? totalMs : Math.max(0, totalMs - (clock() - start)); },
@@ -26,7 +26,7 @@ export function readinessAPI(api, window, failure = 'deployment-readiness-timeou
26
26
  return {...api, request(path, options = {}) {
27
27
  const remaining = window.remaining();
28
28
  assert(remaining > 0, failure);
29
- const deadline = AbortSignal.timeout(Math.max(1, Math.ceil(remaining)));
29
+ const deadline = window.timeout(Math.max(1, Math.ceil(remaining)));
30
30
  return api.request(path, {...options, signal:options.signal ? AbortSignal.any([options.signal,deadline]) : deadline});
31
31
  }};
32
32
  }
@@ -188,6 +188,9 @@ the seed retires them in its own migration.
188
188
  retires imports whose headers hold the person's exact identifiers and writes
189
189
  the import erasure journal (import-kit `src/d1/README.md`).
190
190
 
191
+ If a required retained row disappears, erasure refuses with `retained_row_missing`
192
+ and leaves the work pending.
193
+
191
194
  ## Adopting
192
195
 
193
196
  Copy these files byte for byte to a folder the Worker build serves, such as
@@ -207,6 +210,7 @@ modules/erasure/scope.mjs
207
210
  modules/erasure/completion.mjs
208
211
  modules/erasure/verification.mjs
209
212
  modules/erasure/cascade.mjs
213
+ modules/erasure/queue.mjs
210
214
  modules/erasure/blobs.mjs
211
215
  modules/erasure/audit.mjs
212
216
  modules/erasure/receipt.mjs
@@ -229,11 +233,12 @@ archives; the blob work list does not.
229
233
 
230
234
  ## Historical measurements before the review fixes
231
235
 
232
- Through the default seed's route in a local `rer dev` Worker, a subject with
233
- 10,000 dependent rows (9,500 notes and 500 file rows) and 500 R2 blobs was
234
- erased in 10.7 s in one run and 15.0 s in another. That is one request: 20
235
- bounded D1 steps, then the blob phase, with no queue continuation needed. The
236
- full proof table is kept with the consolidation evidence for this change.
236
+ A historical, unverified report through the default seed's route in a local
237
+ `rer dev` Worker recorded erasing a subject with 10,000 dependent rows (9,500
238
+ notes and 500 file rows) and 500 R2 blobs in 10.7 s in one run and 15.0 s in
239
+ another, in one request: 20 bounded D1 steps, then the blob phase, with no queue continuation needed. The cited
240
+ consolidation proof table is outside this repository; no corresponding benchmark
241
+ receipt is retained here.
237
242
  These pre-fix measurements do not establish the performance of the corrected
238
243
  helper. They are local Miniflare measurements, not production capacity claims. Real D1
239
244
  statement, CPU and request limits decide `rows` per step and the request budget.
@@ -13,7 +13,7 @@ use Undo from the same history when needed. Base's reference accepts people JSON
13
13
  here, not installation `.rer` archives. Editions adopt this same door
14
14
  with their own supported readers and native adapters.
15
15
 
16
- For seed integration, follow [the door adoption guide](../door/ADOPTING.md)
16
+ For seed integration, follow [the door adoption guide](https://github.com/runeditrun/base/blob/main/modules/import-kit/src/door/ADOPTING.md)
17
17
  first. The D1 primitives below back that shared pipeline; do not mount separate
18
18
  job creation/apply routes beside it. Keep native readers and target adapters.
19
19
 
@@ -29,6 +29,10 @@ provenance and inert-effect policy through an asynchronous native SQL port.
29
29
  When copying Base source directly, copy the shared [D1 transport](../../../d1-transport/index.mjs) and its
30
30
  [types](../../../d1-transport/index.d.mts), preserving their sibling location
31
31
  beside the import-kit directory.
32
+ Reading codec-dependent stored plans without the matching codec ID refuses with
33
+ `IMPORT_PLAN_CODEC_REQUIRED`; encoding a codec whose round trip changes the plan
34
+ fingerprint refuses with `IMPORT_PLAN_CODEC_MISMATCH`.
35
+
32
36
  The D1 entry uses this shared transport automatically. It accounts for actual
33
37
  UTF-8 bytes and workerd's whole-call two-byte strings, escapes sparse wide text
34
38
  for SQLite to decode, and keeps each mutation in its original transaction.
@@ -44,7 +48,9 @@ and D1 engine for the same jobs: each engine owns its checkpoint protocol.
44
48
  For reviewed reversal-policy conversion, also apply the additive
45
49
  `d1ReversalPolicyConversionSchema` after these existing schemas in a new
46
50
  product-owned numbered migration. `initializeD1ImportStorage` installs it
47
- automatically. Do not rewrite an applied migration.
51
+ automatically. Do not rewrite an applied migration. Partial preserved-undo schema
52
+ evolution refuses with `IMPORT_SCHEMA_EVOLUTION_INCOMPLETE`; complete the additive
53
+ evolution before continuing.
48
54
 
49
55
  Apply stream-origin backfill and legacy receipt conversion in one transaction.
50
56
  Origins record actual page, parent and job bindings and remain immutable until
@@ -64,10 +70,10 @@ evaluates the expression at both ends of every atomic mutation batch. A false
64
70
  predicate raises `IMPORT_ATOMIC_GUARD` and rolls back every native and kit write.
65
71
  Read operations also require current authority. Jobs remain bound to their actor.
66
72
  The plan and its fingerprint carry that `principalId`, so a job can never be rebound
67
- to another one, and an archive carries the jobs but not the operators who created
68
- them: after an export, reset, import and setup the owner is a new operator row. A
69
- product that wants restored jobs to stay usable passes a principal that survives a
70
- restore, such as the operator's role (`'role:' + role`), and lets `predicate` check
73
+ to another one. Identity retention depends on the seed's archive policy: a
74
+ restored job remains bound to its recorded principal, so verify whether that
75
+ principal survives the selected policy. A product that wants restored jobs to
76
+ stay usable passes a principal that survives a restore, such as the operator's role (`'role:' + role`), and lets `predicate` check
71
77
  that the acting operator is still active in that role. A product that passes the
72
78
  operator's row id keeps its jobs bound to that operator for good.
73
79
 
@@ -932,9 +938,9 @@ the new conversion and preview operations refuse with the `schema` reason until
932
938
  their additive migration is installed. Updating kit source does not silently
933
939
  adopt conversion or require an edit to an existing seed migration.
934
940
 
935
- Current rer 0.2.77 lacks this API. A seed adopts a reviewed vendored Base revision
936
- containing the capability, or a future rer release that supplies it, and proves
937
- its migration, current authority, conversion and later reversal through its own
941
+ Historically, rer 0.2.77 lacked this API. A seed adopts a reviewed vendored Base
942
+ revision containing the capability, or a pinned rer release that supplies it,
943
+ and proves its migration, current authority, conversion and later reversal through its own
938
944
  public door. Base's tests do not prove that adoption. Until then, existing strict
939
945
  jobs retain their policy and the seed's compensation-unavailable refusal remains
940
946
  in force. Adoption, seed release and deployment are separate from this Base
@@ -0,0 +1,33 @@
1
+ import type { ImportJob, PlanEntry, ProvenanceRow, TargetRow } from '../types.ts';
2
+ import type { D1ImportContext } from './types.ts';
3
+ import type { D1UndoEffect } from './undo-types.ts';
4
+ import { canonicalJson, sha256, attachmentHash } from '../provenance/identity.ts';
5
+ import { effectIdentity } from '../storage/provenance.ts';
6
+ import { remaining } from './budget.ts';
7
+
8
+ /** The exact prospective publication shape, shared by apply and admission. */
9
+ export function prospectiveEffect(id: string, entry: PlanEntry, index: number, before: TargetRow | undefined, destination: string): D1UndoEffect {
10
+ const effect = entry.effects[index], appliedRevision = sha256(canonicalJson([id, entry.identity, index, 'applied']));
11
+ const expected: TargetRow = { destination, targetKind: effect.targetKind, targetId: effect.targetId, value: effect.value, revision: appliedRevision, ...(effect.attachment ? { attachment: effect.attachment } : {}) };
12
+ const provenance: ProvenanceRow = { id: effectIdentity(id, entry.identity, index), jobId: id, sourceIdentity: entry.identity, sourceKind: entry.source.kind, sourceId: entry.source.sourceId, sourceHash: entry.source.payloadHash, artifactHash: entry.source.artifactHash, location: entry.source.location, destination, targetKind: effect.targetKind, targetId: effect.targetId, valueHash: sha256(canonicalJson(effect.value)), attachmentHash: attachmentHash(effect.attachment), appliedRevision, before: before ?? null, reversed: false };
13
+ return { provenance, expected, retained: false };
14
+ }
15
+
16
+ /** Small-batch callers can admit consecutive pending effects together, before
17
+ * any of them publish. This avoids repeatedly listing the growing native set
18
+ * for each one-record publication. Admission never survives a public request. */
19
+ export async function admissionWindow(job: ImportJob, entries: PlanEntry[], effects: D1UndoEffect[], plan: { entries: PlanEntry[] }, context: D1ImportContext, batches: number, batchSize: number, publicationCost: number): Promise<void> {
20
+ let end = job.checkpoint + entries.length;
21
+ const limit = Math.min(job.total, job.checkpoint + batchSize * Math.min(batches, Math.ceil(20 / batchSize)));
22
+ for (const entry of plan.entries.slice(end, limit)) {
23
+ if (effects.length + entry.effects.length > 1000 || remaining(context) - publicationCost < 40 + entry.effects.length * 16) break;
24
+ const { database, targets } = context.storage;
25
+ if (!await database.prepare('SELECT 1 AS present FROM ik_sources WHERE identity=?').bind(entry.identity).first()) {
26
+ for (const [index, effect] of entry.effects.entries()) {
27
+ const before = await targets.read(database, context.destination, effect.targetKind, effect.targetId);
28
+ effects.push(prospectiveEffect(job.id, entry, index, before, context.destination));
29
+ }
30
+ }
31
+ end++;
32
+ }
33
+ }
@@ -2,12 +2,14 @@ import { retainedSql } from './retained-values.ts';
2
2
  import { nativeStagingScope, readStagedTarget, expectedStagedTarget, type NativeStagingScope } from './native-staging-context.ts';
3
3
  import { targetGuards } from './target-guards.ts';
4
4
  import { D1RequestLimitError, requestContext, remaining } from './budget.ts';
5
- import type { ImportJob, PlanEntry, ProvenanceRow, TargetRow } from '../types.ts';
5
+ import type { ImportJob, PlanEntry } from '../types.ts';
6
6
  import { canonicalJson, sha256, attachmentHash } from '../provenance/identity.ts';
7
7
  import { validateEffect } from '../plan/index.ts';
8
- import { effectIdentity } from '../storage/provenance.ts';
8
+ import { prospectiveEffect, admissionWindow } from './apply-effects.ts';
9
9
  import type { D1ImportContext, D1Sql } from './types.ts';
10
- import { atomic, atomicCount, authorize, guard, limits, sql, fitsBatch } from './database.ts';
10
+ import type { D1UndoEffect } from './undo-types.ts';
11
+ import { reversalState } from './undo-state.ts';
12
+ import { atomic, atomicCount, atomicPrefix, authorize, guard, limits, sql, fitsBatch, readAtomic } from './database.ts';
11
13
  import { stored, boundary, storedReads } from './jobs.ts';
12
14
  import { custodyGuards, validatedProvenance, inventoryGuards, reusedSourceGuards } from './integrity.ts';
13
15
  import { supersedeTarget } from './history.ts';
@@ -19,6 +21,8 @@ export async function applyD1ImportBatches(jobOrId: ImportJob | string, context:
19
21
  const id = typeof jobOrId === 'string' ? jobOrId : jobOrId.id, { batchSize, maxBatches } = limits(context);
20
22
  await authorize(context, 'apply');
21
23
  let current = await stored(id, context, 'apply'), published: ImportJob | undefined;
24
+ const admitted = new Map<string, string>();
25
+ let preparing = context.storage.targets.preparePreservedUndo;
22
26
  try {
23
27
  for (let count = 0; count < maxBatches; count++) {
24
28
  const { job, plan } = current;
@@ -27,7 +31,10 @@ export async function applyD1ImportBatches(jobOrId: ImportJob | string, context:
27
31
  if (job.state === 'completed') { await atomic(context, 'apply', [...boundary(job, plan, 'apply'), ...custodyGuards(plan, id), ...await inventoryGuards(job, plan, context)], 0, nativeStagingScope(job, plan)); return job; }
28
32
  if (!['queued', 'applying', 'failed'].includes(job.state)) throw new Error('IMPORT_ALREADY_REVERSING');
29
33
  const statements: D1Sql[] = [...boundary(job, plan, 'apply'), ...custodyGuards(plan, id), ...await inventoryGuards(job, plan, context)], entries: PlanEntry[] = [], returnReads = storedReads(job);
30
- let effects = 0, scope = nativeStagingScope(job, plan), planned = cost(context, publication(job, 0, statements, scope), returnReads);
34
+ const undoEffects: D1UndoEffect[] | undefined = reversalState(job).policy === 'preserve-conflicts' ? [] : undefined;
35
+ let effects = 0, scope = nativeStagingScope(job, plan);
36
+ let prefix = atomicPrefix(context, 'apply', statements, scope);
37
+ let planned = prefix ? prefix.count(progress(job, 0), returnReads) : cost(context, publication(job, 0, statements, scope), returnReads);
31
38
  for (const entry of plan.entries.slice(job.checkpoint, job.checkpoint + batchSize)) {
32
39
  if (entries.length && effects + entry.effects.length > 1000) break;
33
40
  if (entry.effects.length > 1000) throw new Error('SOURCE_EFFECT_LIMIT');
@@ -35,20 +42,45 @@ export async function applyD1ImportBatches(jobOrId: ImportJob | string, context:
35
42
  // request, as atomic will send it, is counted again once the entry is built.
36
43
  const reserve = 40 + entry.effects.length * 16;
37
44
  if (remaining(context) - planned < reserve) { if (!entries.length) { if (count > 0) return job; throw new D1RequestLimitError(); } break; }
38
- const candidate = [...statements], nextScope = { ...scope, nativeGuards:[...scope.nativeGuards], postGuards:[...scope.postGuards], targets:[...scope.targets] };
39
- await publishEntry(id, entry, job.checkpoint + entries.length, context, candidate, nextScope);
40
- const next = publication(job, entries.length + 1, candidate, nextScope), spent = cost(context, next, returnReads);
45
+ const candidate: D1Sql[] = [], nextScope = { ...scope, nativeGuards:[...scope.nativeGuards], postGuards:[...scope.postGuards], targets:[...scope.targets] };
46
+ const candidateUndo: D1UndoEffect[] | undefined = undoEffects && [];
47
+ await publishEntry(id, entry, job.checkpoint + entries.length, context, candidate, nextScope, candidateUndo);
48
+ const nextPrefix = prefix?.extend(candidate);
49
+ const next = nextPrefix ? undefined : publication(job, entries.length + 1, [...statements, ...candidate], nextScope);
50
+ const spent = nextPrefix ? nextPrefix.count(progress(job, entries.length + 1), returnReads) : cost(context, next!, returnReads);
41
51
  if (spent > remaining(context)) { if (entries.length) break; if (count > 0) return job; throw new D1RequestLimitError(); }
42
- const fits = fitsBatch(context, 'apply', next.statements, next.scope);
52
+ const fits = nextPrefix ? true : fitsBatch(context, 'apply', next!.statements, next!.scope);
43
53
  if (!fits && entries.length) break;
44
- statements.splice(0, statements.length, ...candidate);
54
+ statements.push(...candidate); undoEffects?.push(...candidateUndo!); prefix = nextPrefix;
45
55
  scope = nextScope; entries.push(entry); effects += entry.effects.length; planned = spent;
46
56
  if (!fits) break;
47
57
  }
58
+ // Check the preserving contract before every native publication, including
59
+ // batches resumed from a nonzero checkpoint.
60
+ // This read-only admission makes no undo decision and authorizes no
61
+ // effects. Apply still fences its own exact before-images atomically.
62
+ // Do not copy this potentially large native snapshot into staging's
63
+ // compact baseline, which must fit every private publication batch.
64
+ if (undoEffects && (!admitted.size || undoEffects.some(effect => admitted.get(effect.provenance.id) !== sha256(canonicalJson(effect))) || preparing !== context.storage.targets.preparePreservedUndo)) {
65
+ const { classifyUndo } = await import('./undo-snapshot.ts');
66
+ const { database, targets } = context.storage;
67
+ const prepare = targets.preparePreservedUndo;
68
+ if (typeof prepare !== 'function') throw new Error('IMPORT_PRESERVED_UNDO_ADAPTER_REQUIRED');
69
+ await admissionWindow(job, entries, undoEffects, plan, context, maxBatches - count, batchSize, planned);
70
+ const snapshot = await prepare.call(targets, database, context.destination, structuredClone(undoEffects));
71
+ const admission = classifyUndo(undoEffects, snapshot, context);
72
+ await readAtomic(context, admission.guards, nativeStagingScope(job, plan), 'apply');
73
+ admitted.clear();
74
+ for (const effect of undoEffects) admitted.set(effect.provenance.id, sha256(canonicalJson(effect)));
75
+ preparing = prepare;
76
+ }
77
+ if (undoEffects && preparing !== context.storage.targets.preparePreservedUndo) throw new Error('IMPORT_PRESERVED_UNDO_ADAPTER_REQUIRED');
48
78
  const request = publication(job, entries.length, statements, scope), done = job.checkpoint + entries.length === job.total;
49
79
  await atomic(context, 'apply', request.statements, returnReads, request.scope);
50
80
  current = await stored(id, context, 'apply'); published = current.job;
51
- if (done || remaining(context) < 200) return published;
81
+ // Preserving admission spends a variable number of reads; let the exact
82
+ // next-batch budget check decide whether more work fits.
83
+ if (done || (!undoEffects && remaining(context) < 200)) return published;
52
84
  }
53
85
  } catch (error) {
54
86
  // Later preflight has no native effects. Its measured budget exhaustion
@@ -58,7 +90,7 @@ export async function applyD1ImportBatches(jobOrId: ImportJob | string, context:
58
90
  }
59
91
  return current.job;
60
92
  }
61
- async function publishEntry(id: string, entry: PlanEntry, ordinal: number, context: D1ImportContext, statements: D1Sql[], scope: NativeStagingScope): Promise<void> {
93
+ async function publishEntry(id: string, entry: PlanEntry, ordinal: number, context: D1ImportContext, statements: D1Sql[], scope: NativeStagingScope, undoEffects?: D1UndoEffect[]): Promise<void> {
62
94
  const { database: db, targets } = context.storage, effectsHash = sha256(canonicalJson(entry.effects));
63
95
  const prior = await db.prepare('SELECT * FROM ik_sources WHERE identity=?').bind(entry.identity).first();
64
96
  if (prior) {
@@ -83,12 +115,12 @@ async function publishEntry(id: string, entry: PlanEntry, ordinal: number, conte
83
115
  validateEffect(effect);
84
116
  const before = await readStagedTarget(context, scope, effect.targetKind, effect.targetId);
85
117
  if (before ? effect.expectedRevision !== before.revision : effect.expectedRevision !== undefined) throw new Error('TARGET_REVISION_CONFLICT');
86
- const appliedRevision = sha256(canonicalJson([id, entry.identity, index, 'applied']));
87
- const row: TargetRow = { destination: context.destination, targetKind: effect.targetKind, targetId: effect.targetId, value: effect.value, revision: appliedRevision, ...(effect.attachment ? { attachment: effect.attachment } : {}) };
118
+ const prospective = prospectiveEffect(id, entry, index, before, context.destination);
119
+ const { expected: row, provenance: p } = prospective;
88
120
  expectedStagedTarget(scope,effect.targetKind,effect.targetId,true);
89
121
  const post = targetGuards(targets, row, context.destination, effect.targetKind, effect.targetId);
90
122
  scope.postGuards.push(...post);
91
- const p: ProvenanceRow = { id: effectIdentity(id, entry.identity, index), jobId: id, sourceIdentity: entry.identity, sourceKind: entry.source.kind, sourceId: entry.source.sourceId, sourceHash: entry.source.payloadHash, artifactHash: entry.source.artifactHash, location: entry.source.location, destination: context.destination, targetKind: effect.targetKind, targetId: effect.targetId, valueHash: sha256(canonicalJson(effect.value)), attachmentHash: attachmentHash(effect.attachment), appliedRevision, before: before ?? null, reversed: false };
123
+ undoEffects?.push(prospective);
92
124
  await supersedeTarget(p, before, context, statements);
93
125
  const record_json=canonicalJson(p);
94
126
  statements.push(...targetGuards(targets,before ?? null, context.destination, effect.targetKind, effect.targetId), ...targets.write(row), ...post, changed(retainedSql(['INSERT INTO ik_provenance(id,job_id,ordinal,effect_ordinal,source_identity,destination,target_kind,target_id,record_json) VALUES(', ',', ',', ',', ',', ',', ',', ',', ',', ')'], [p.id, id, ordinal, index, entry.identity, context.destination, effect.targetKind, effect.targetId, record_json], [8]),putRow('ik_provenance',{id:p.id,job_id:id,ordinal,effect_ordinal:index,source_identity:entry.identity,destination:context.destination,target_kind:effect.targetKind,target_id:effect.targetId,reversed:0,record_json})));