@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
@@ -10,16 +10,29 @@ const nativeCredential = { sendgrid: 'SENDGRID_API_KEY', resend: 'RESEND_API_KEY
10
10
  const present = value => typeof value === 'string' && Boolean(value.trim());
11
11
  // The sender forms the mail runtime sends from: a bare address or "Display Name <address>".
12
12
  const sender = value => { try { parseAddress(value); return true; } catch { return false; } };
13
- const SENDER = 'MAIL_FROM (billing@example.com or Your Business <billing@example.com>)';
13
+ const SENDER = "MAIL_FROM (a real sender on your provider's verified domain; bare address or Display Name <address>)";
14
+ const placeholderSender = value => {
15
+ if (!sender(value)) return false;
16
+ const { email } = parseAddress(value), [local, domain] = email.toLowerCase().split('@');
17
+ return /(?:^|\.)(?:invalid|example|test|localhost)$/.test(domain)
18
+ || /(?:^|\.)example\.(?:com|net|org)$/.test(domain)
19
+ || /^(?:your-?domain|your-?business|fake|placeholder|changeme)\./.test(domain)
20
+ || /^(?:fake|placeholder|change-?me|replace-?me|your-?email|your-?name|you)(?:[+._-]|$)/.test(local);
21
+ };
14
22
 
15
23
  // Packaging can declare inputs that a product's deploy adapter adds to the
16
24
  // root declaration later. Read that source contract, never arbitrary ambient
17
25
  // keys or the adapter's executable source, before any build or provider write.
18
- export async function productionMail(root, declaration, env) {
26
+ export async function productionMail(root, declaration, env, declarationPath = 'deploy.json') {
19
27
  const bindings = { ...declaration.vars }, secrets = new Set(), publicInputs = new Set(), declaredProviders = new Set();
28
+ let senderFix = `Edit vars.MAIL_FROM in ${declarationPath}`;
29
+ const environmentFix = name => `Set ${name} in your environment or owned 0600 --env-file`;
20
30
  for (const secret of declaration.secrets ?? []) {
21
31
  secrets.add(secret.binding);
22
- if (present(env[secret.environment])) bindings[secret.binding] = env[secret.environment];
32
+ if (present(env[secret.environment])) {
33
+ bindings[secret.binding] = env[secret.environment];
34
+ if (secret.binding === 'MAIL_FROM') senderFix = environmentFix(secret.environment);
35
+ }
23
36
  }
24
37
  for (const [path, select] of deliveryDeclarationSources) {
25
38
  let text;
@@ -31,16 +44,29 @@ export async function productionMail(root, declaration, env) {
31
44
  if (!spec) continue;
32
45
  for (const name of spec.publicVariableNames ?? []) publicInputs.add(name);
33
46
  for (const [name, value] of Object.entries(spec.publicVariables ?? {})) {
34
- if (!(name in bindings) || name === 'MAIL_PROVIDER' && bindings[name] === 'later') bindings[name] = value;
47
+ if (!(name in bindings) || name === 'MAIL_PROVIDER' && bindings[name] === 'later') {
48
+ bindings[name] = value;
49
+ if (name === 'MAIL_FROM') senderFix = `Edit publicVariables.MAIL_FROM in ${path}`;
50
+ }
35
51
  }
36
52
  for (const name of [...(spec.secretNames ?? []), ...(spec.optionalSecretNames ?? [])]) {
37
53
  secrets.add(name);
38
54
  // A root secret's explicit environment-to-binding mapping wins.
39
- if (!declaration.secrets?.some(secret => secret.binding === name) && present(env[name])) bindings[name] = env[name];
55
+ if (!declaration.secrets?.some(secret => secret.binding === name) && present(env[name])) {
56
+ bindings[name] = env[name];
57
+ if (name === 'MAIL_FROM') senderFix = environmentFix(name);
58
+ }
40
59
  }
41
60
  for (const provider of spec.mail?.providers ?? []) if (providers.includes(provider)) declaredProviders.add(provider);
42
61
  }
43
- for (const name of publicInputs) if (present(env[name])) bindings[name] = env[name];
62
+ for (const name of publicInputs) if (present(env[name])) {
63
+ bindings[name] = env[name];
64
+ if (name === 'MAIL_FROM') senderFix = environmentFix(name);
65
+ }
66
+ let senderIssue;
67
+ if (present(bindings.MAIL_FROM) && (!sender(bindings.MAIL_FROM) || placeholderSender(bindings.MAIL_FROM))) {
68
+ senderIssue = `MAIL_FROM is invalid or a placeholder sender. Replace it with a real sender address on your mail provider's verified domain (a bare address or Display Name <address>). ${senderFix}, then run rer deploy --dry-run again.`;
69
+ }
44
70
  const provider = bindings.MAIL_PROVIDER;
45
71
  const deferred = !provider || provider === 'later';
46
72
  const choices = new Set(declaredProviders);
@@ -63,7 +89,7 @@ export async function productionMail(root, declaration, env) {
63
89
  if (provider === 'rer') try { validateRerConfig({ relayUrl: bindings.MAIL_RELAY_URL }); } catch { relaySelected = false; }
64
90
  const has = key => present(bindings[key]) || secrets.has(key) && live.includes(key);
65
91
  return [
66
- ...(!sender(bindings.MAIL_FROM) ? [SENDER] : []),
92
+ ...(!sender(bindings.MAIL_FROM) || senderIssue ? [senderIssue ?? SENDER] : []),
67
93
  ...(!credentialKeys.some(has) ? [credentialText] : []),
68
94
  ...(provider === 'cloudflare' && !has('MAIL_ACCOUNT_ID') ? ['MAIL_ACCOUNT_ID'] : []),
69
95
  ...(!relaySelected ? ['MAIL_RELAY_URL (assigned HTTPS relay URL)'] : []),
@@ -72,11 +98,12 @@ export async function productionMail(root, declaration, env) {
72
98
  });
73
99
  return {
74
100
  declared: 'MAIL_PROVIDER' in bindings || publicInputs.has('MAIL_PROVIDER') || secrets.has('MAIL_API_KEY') || selected.length > 0,
101
+ senderIssue,
75
102
  configured: (live = []) => routes.some(missing => missing(live).length === 0),
76
- canInspect: sender(bindings.MAIL_FROM) && routes.length > 0,
103
+ canInspect: sender(bindings.MAIL_FROM) && !senderIssue && routes.length > 0,
77
104
  missing: routes.length ? routes.map(missing => missing([]).join(', ')).join(' or ') : [
78
105
  'MAIL_PROVIDER (resend, sendgrid, cloudflare or rer)',
79
- ...(!sender(bindings.MAIL_FROM) ? [SENDER] : []),
106
+ ...(!sender(bindings.MAIL_FROM) || senderIssue ? [senderIssue ?? SENDER] : []),
80
107
  'MAIL_API_KEY',
81
108
  ].join(', '),
82
109
  };
package/cli/project.mjs CHANGED
@@ -1,21 +1,12 @@
1
- import { readFile, lstat, realpath } from 'node:fs/promises';
2
- import { isAbsolute, relative, resolve, sep } from 'node:path';
1
+ import { readFile, realpath } from 'node:fs/promises';
2
+ import { resolve } from 'node:path';
3
3
  import { pathToFileURL } from 'node:url';
4
+ import { containedInput } from '../modules/demo/input-path.mjs';
4
5
  import { readOperations } from '../operations/operations.mjs';
5
6
  import { invalid, missing, refuse } from './errors.mjs';
6
7
 
7
- export async function contained(root, path, { optional = false, privateFile = false } = {}) {
8
- if (typeof path !== 'string' || !path || isAbsolute(path) || path.split(/[\\/]/).some(part => part === '..' || part === '')) throw refuse('Path must be a contained checkout path without traversal.');
9
- const checkout = await realpath(root), destination = resolve(checkout, path), parts = relative(checkout, destination).split(sep);
10
- let current = checkout;
11
- for (let i = 0; i < parts.length; i++) {
12
- current = resolve(current, parts[i]);
13
- 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.`); throw error; }
14
- if (status.isSymbolicLink()) throw refuse(`Symlink refused at ${path}; preserve it and resolve placement first.`);
15
- if (i < parts.length - 1 && !status.isDirectory()) throw refuse(`Unsafe path ancestor for ${path}.`);
16
- 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}.`);
17
- }
18
- return destination;
8
+ export function contained(root, path, options = {}) {
9
+ return containedInput(root, path, { ...options, refuse, missing });
19
10
  }
20
11
 
21
12
  export async function resolveProject(root) {
package/cli/release.mjs CHANGED
@@ -1,15 +1,15 @@
1
+ import { releaseVerb } from './contract.mjs';
1
2
  import { parseTimeoutSeconds, timeoutBounds } from '../scripts/publish-check/timeout.mjs';
2
3
 
3
4
  // Preserve release's accepted parser, producer, receipt and validation exits.
4
- const releaseHelp = `Usage: rer release --repo DIR --project PUBLISHER/NAME --repository GITHUB_URL --output NEW_DIR [FLAGS]
5
+ const releaseHelp = `Usage: rer release --repo DIR --project OWNER/NAME --repository GITHUB_URL --output NEW_DIR [FLAGS]
5
6
 
6
7
  Produce local artifacts using the exact source commit's green GitHub Verify,
7
8
  frozen installation, local build and publication checks.
8
9
  Without --tag, write a preview. This command never pushes, uploads or deploys.
9
10
 
10
11
  --repo DIR Source Git repository.
11
- --project PUBLISHER/NAME
12
- Publishing identity.
12
+ --project OWNER/NAME Project identity recorded by the edition.
13
13
  --repository GITHUB_URL
14
14
  Credential-free https://github.com/<owner>/<repository> destination.
15
15
  --output NEW_DIR New output directory outside the source repository.
@@ -39,19 +39,20 @@ Without --tag, write a preview. This command never pushes, uploads or deploys.
39
39
  --help Print this help without performing release work.
40
40
 
41
41
  Signing and receipt commands:
42
- rer release sign --artifact DIR (--key-file FILE | --key-stdin) [--scope test|rer]
42
+ rer release sign --artifact DIR (--key-file FILE | --key-stdin) [--scope test|rer] [--publisher NAMESPACE]
43
43
  rer release receipt --artifact DIR --anchors FILE [--environment test] [--after VERSION:SHA256]
44
44
  rer release keygen --scope test|rer --publisher NAMESPACE --github-owner LOGIN --github-owner-id ID --anchor-out FILE
45
45
  [--not-before YYYY-MM-DDTHH:MM:SSZ] [--not-after YYYY-MM-DDTHH:MM:SSZ]
46
46
  [--unsigned-through PROJECT:VERSION ...]
47
47
 
48
48
  Signing scope defaults to rer; receipt environment defaults to production.
49
+ Signing publisher defaults to the project prefix; use --publisher for a different publisher.
49
50
  Key generation requires non-terminal stdout; --key-stdin requires non-terminal stdin.
50
51
  `;
51
52
 
52
53
  export async function dispatchRelease(args) {
53
54
  if (args.length === 1 && args[0] === '--help') { console.log(releaseHelp); return 0; }
54
- if (['sign', 'receipt', 'keygen'].includes(args[0])) return (await import('../modules/release/signing-cli.mjs')).dispatchSigning(args[0], args.slice(1));
55
+ if (Object.hasOwn(releaseVerb.subcommands, args[0])) return (await import('../modules/release/signing-cli.mjs')).dispatchSigning(args[0], args.slice(1));
55
56
  try {
56
57
  const options = {};
57
58
  for (let index = 0; index < args.length; index++) {
@@ -0,0 +1,90 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { contained } from './project.mjs';
3
+ import { RerError } from './errors.mjs';
4
+ import { declarationFor } from './deploy-command.mjs';
5
+ import { deployGuide, deployPermissions } from './deploy-needs.mjs';
6
+ import { deliveryDeclarationSources } from './delivery-declarations.mjs';
7
+ import { ownerPlatforms, ownerWorkerName } from '../modules/deploy-kit/owner.mjs';
8
+
9
+ // What the run site's /docs/hosting tells a person about putting this seed on
10
+ // their own Cloudflare account, read from the declarations rer deploy reads: the
11
+ // deploy declaration, the setup manifest and the mail delivery declarations. It
12
+ // holds environment names, permissions and counts, never a value. `hosting` is
13
+ // null, with the reason, when rer deploy could not put this seed on Workers from
14
+ // them; the page then offers Run Edit Run's help alone. Never throws for what a
15
+ // seed declares, so a declaration gap never stops rer dev's run site.
16
+ const OWN = ['resend', 'sendgrid', 'cloudflare'];
17
+ const NATIVE = { resend: 'RESEND_API_KEY', sendgrid: 'SENDGRID_API_KEY' };
18
+
19
+ class Gap extends Error {}
20
+ async function json(root, path) {
21
+ let text;
22
+ try { text = await readFile(await contained(root, path, { optional: true }), 'utf8'); }
23
+ catch (error) { if (error.code === 'ENOENT') return undefined; throw new Gap(`${path} cannot be read`); }
24
+ try { return JSON.parse(text); } catch { throw new Gap(`${path} is not valid JSON`); }
25
+ }
26
+
27
+ /** { hosting } for /docs/hosting, or { hosting: null, reason } when the seed does not deploy to Workers from its declarations. */
28
+ export async function siteHosting({ root, adapter }) {
29
+ if (typeof adapter?.deploy !== 'function') return { hosting: null, reason: 'the command adapter has no deploy' };
30
+ try { return { hosting: await read(root, adapter) }; }
31
+ catch (error) {
32
+ // rer deploy's own refusals of the declaration (missing, ambiguous, invalid) are gaps too.
33
+ if (error instanceof Gap || error instanceof RerError || /^[a-z]+(?:-[a-z0-9]+)+$/.test(error?.message ?? '')) return { hosting: null, reason: error.message };
34
+ throw error;
35
+ }
36
+ }
37
+
38
+ async function read(root, adapter) {
39
+ const { path, value: declaration } = await declarationFor(root, adapter);
40
+ if (!ownerPlatforms(declaration).includes('workers')) throw new Gap(`${path} does not deploy to Workers`);
41
+ const guide = deployGuide(declaration);
42
+ const manifest = await json(root, adapter.setup?.manifestFile ?? 'rer-setup.json') ?? {};
43
+ const fields = new Map((Array.isArray(manifest.fields) ? manifest.fields : []).map(field => [field?.name, field]));
44
+ const steps = Array.isArray(manifest.steps) ? manifest.steps : [], claim = steps.find(step => step?.type === 'owner-claim');
45
+ const vars = declaration.vars ?? {}, secrets = (Array.isArray(declaration.secrets) ? declaration.secrets : []).filter(item => item?.binding && item.environment);
46
+ // What the deploy file can set, by binding: a declared secret under its environment name,
47
+ // and a mail declaration's inputs under their own (productionMail reads the same).
48
+ const input = new Map(secrets.map(item => [item.binding, item.environment])), offered = new Set();
49
+ for (const [source, select] of deliveryDeclarationSources) {
50
+ const spec = select(await json(root, source));
51
+ if (!spec) continue;
52
+ for (const name of [...(spec.publicVariableNames ?? []), ...(spec.secretNames ?? []), ...(spec.optionalSecretNames ?? [])]) if (!input.has(name)) input.set(name, name);
53
+ for (const provider of spec.mail?.providers ?? []) offered.add(provider);
54
+ }
55
+ for (const option of fields.get('MAIL_PROVIDER')?.options ?? []) offered.add(option?.value);
56
+ const sso = Array.isArray(manifest.dependencies) && manifest.dependencies.some(item => item?.interface === 'oidc-provider@1');
57
+ let mail;
58
+ if (claim || sso || 'MAIL_PROVIDER' in vars || input.has('MAIL_PROVIDER') || input.has('MAIL_API_KEY')) {
59
+ const fixedProvider = input.has('MAIL_PROVIDER') ? undefined : vars.MAIL_PROVIDER;
60
+ if (!input.has('MAIL_PROVIDER') && !OWN.includes(fixedProvider)) throw new Gap(`${path} fixes MAIL_PROVIDER to ${JSON.stringify(fixedProvider ?? null)} and the deploy file cannot choose one`);
61
+ // The provider key the declaration requires, else one it accepts.
62
+ const keys = ['MAIL_API_KEY', 'MAIL_PROVIDER_API_KEY', NATIVE[fixedProvider]].filter(Boolean), needed = name => secrets.some(item => item.binding === name && !item.optional);
63
+ const key = input.get(keys.find(needed)) ?? keys.map(name => input.get(name)).find(Boolean);
64
+ if (!key) throw new Gap(`${path} declares no input for the mail provider's API key`);
65
+ mail = { providers: OWN.filter(provider => offered.has(provider)), ...(input.has('MAIL_PROVIDER') ? { provider: input.get('MAIL_PROVIDER') } : { fixedProvider }),
66
+ ...(input.has('MAIL_FROM') ? { from: input.get('MAIL_FROM') } : {}), key, ...(input.has('MAIL_ACCOUNT_ID') ? { accountId: input.get('MAIL_ACCOUNT_ID') } : {}) };
67
+ }
68
+ // rer deploy generates the setup manifest's generated secrets and keeps the installation keys; every other
69
+ // required secret the owner supplies once, under its environment name (neededForRealDeploy lists the same).
70
+ const generated = new Set([...fields.values()].filter(field => field?.kind === 'secret' && field.generate).map(field => field.name));
71
+ const ownerEmail = claim?.emailField && input.get(claim.emailField);
72
+ const shown = new Set([ownerEmail, mail?.provider, mail?.from, mail?.key, mail?.accountId].filter(Boolean)), required = [];
73
+ for (const item of secrets) {
74
+ if (item.optional || generated.has(item.binding) || ['INSTALLATION_KEY_PREVIOUS', 'MAIL_RELAY_URL'].includes(item.binding) || shown.has(item.environment) || required.some(entry => entry.name === item.environment)) continue;
75
+ const field = fields.get(item.binding);
76
+ required.push({ name: item.environment, ...(typeof field?.label === 'string' ? { label: field.label } : {}), ...(typeof field?.help === 'string' ? { help: field.help } : {}) });
77
+ }
78
+ const count = key => Array.isArray(declaration[key]) ? declaration[key].length : 0;
79
+ return {
80
+ declaration: path,
81
+ // A custom deploy hook may name and place its Worker itself: only rer's own deploy's address is known.
82
+ ...(adapter.deploy.managesHostedOwner === true ? { worker: ownerWorkerName(declaration.project, 'production') } : {}),
83
+ permissions: deployPermissions(declaration),
84
+ resources: { d1: count('d1'), r2: count('r2'), kv: count('kv'), queues: count('queues'), durableObjects: count('durableObjects'), crons: count('crons') },
85
+ ...(ownerEmail ? { ownerEmail } : {}),
86
+ ...(mail ? { mail } : {}),
87
+ required,
88
+ ...(guide ? { guide } : {}),
89
+ };
90
+ }
@@ -47,7 +47,10 @@ export async function sitePreview(folder, { host = '127.0.0.1', ports }) {
47
47
  server.once('error', failed);
48
48
  server.listen(port, host, () => { server.off('error', failed); resolve(true); });
49
49
  });
50
- if (bound) return { url: `http://${host === '::1' ? '[::1]' : host}:${port}`, port, close: () => new Promise(resolve => { server.closeAllConnections?.(); server.close(() => resolve()); }) };
50
+ if (bound) {
51
+ const port = server.address().port;
52
+ return { url: `http://${host === '::1' ? '[::1]' : host}:${port}`, port, close: () => new Promise(resolve => { server.closeAllConnections?.(); server.close(() => resolve()); }) };
53
+ }
51
54
  }
52
55
  throw new Error('No free port for the run site preview.');
53
56
  }
@@ -9,7 +9,8 @@
9
9
  // toolchain); the app's own Vite config is never loaded, because its Worker
10
10
  // plugins do not run in Node. It reads no installation data. A seed with a
11
11
  // CONTRACT.md gets it parsed as sitePages({ contract }), for its /contract
12
- // page; one that does not parse stops the build, naming its lines.
12
+ // page; one that does not parse stops the build, naming its lines. `hosting`
13
+ // (cli/site-hosting.mjs) is what its /docs/hosting page says.
13
14
  // Usage: node site-render.mjs ROOT ENTRY OUTPUT [CONFIG]
14
15
  import { shared } from './shared.mjs';
15
16
  const { seedIcons, readIconFiles } = await shared('icon-files.mjs');
@@ -68,7 +69,7 @@ try {
68
69
  const options = clientJSON ? JSON.parse(clientJSON) : {};
69
70
  const clientBuild = await buildClients(vite, root, output, options), clients = clientBuild.clients;
70
71
  styles = [...new Set([...styles,...clientBuild.styles])];
71
- const build = await module.sitePages({ styles, clients, ...(contract ? { contract } : {}) });
72
+ const build = await module.sitePages({ styles, clients, ...(contract ? { contract } : {}), hosting: options.hosting ?? null });
72
73
  if (!Array.isArray(build?.pages) || !Array.isArray(build.assets)) fail('sitePages() returns { pages, assets }.');
73
74
 
74
75
  const written = new Set();
package/cli/site.mjs CHANGED
@@ -10,13 +10,15 @@ import { unpublishedIdentities } from './site-private.mjs';
10
10
  import { privateSitePaths } from './site-inputs.mjs';
11
11
  import { redactSiteText } from './site-diagnostics.mjs';
12
12
  import { siteRuntime, buildSiteRuntime, runtimeSummary } from './site-runtime.mjs';
13
+ import { siteHosting } from './site-hosting.mjs';
13
14
 
14
15
  // The run site: a seed's static marketing pages, /run and docs, built from
15
16
  // edition identity with no installation data. A seed opts in with
16
17
  // commandAdapter's `site: { entry, output, declaration, config?, runtime? }`: the module
17
18
  // whose sitePages({ styles }) returns the pages, the ignored folder the build
18
19
  // writes, the deploy declaration naming the run site's domain, and optionally
19
- // the Vite config holding the plugins the site pages need.
20
+ // the Vite config holding the plugins the site pages need. sitePages also gets
21
+ // `hosting`, what /docs/hosting says, read from the seed's deploy declarations.
20
22
  const relativePath = value => typeof value === 'string' && /^[A-Za-z0-9._/-]+$/.test(value) && !value.split('/').some(part => !part || part === '.' || part === '..');
21
23
 
22
24
  export function declaredSite(project) {
@@ -62,7 +64,8 @@ export async function buildSite(project, store, signal, { prepare = false, deplo
62
64
  await rm(staging, { recursive: true, force: true });
63
65
  try {
64
66
  await mkdir(staging);
65
- try { await store.run('Building the run site', process.execPath, [fileURLToPath(new URL('./site-render.mjs', import.meta.url)), project.root, site.entry, staging, site.config ?? '', JSON.stringify({entries:site.clients ?? {}, config:site.clientConfig, privatePaths:privateSitePaths(project.adapter), ...(site.runtime ? {runtime:site.runtime, corpus:`${staging}.corpus.json`} : {})})], { cwd: project.root, signal, heavy: false }); }
67
+ const { hosting } = await siteHosting(project);
68
+ try { await store.run('Building the run site', process.execPath, [fileURLToPath(new URL('./site-render.mjs', import.meta.url)), project.root, site.entry, staging, site.config ?? '', JSON.stringify({entries:site.clients ?? {}, config:site.clientConfig, privatePaths:privateSitePaths(project.adapter), hosting, ...(site.runtime ? {runtime:site.runtime, corpus:`${staging}.corpus.json`} : {})})], { cwd: project.root, signal, heavy: false }); }
66
69
  catch (error) {
67
70
  const code = await readFile(`${staging}.refusal`, 'utf8').catch(() => '');
68
71
  if (code === 'site_private_input') throw new RerError(code, 'Run site client imports a private installation file or a file outside the seed and its declared dependencies.', 4);
@@ -122,7 +125,8 @@ export async function siteCommand(project, options, store, signal, out) {
122
125
  return { site: { folder: built.folder, path, pages: built.pages, files: built.files, references:built.references, ...(built.runtime ? {runtime:runtimeSummary(built.runtime)} : {}) } };
123
126
  }
124
127
  const plan = await siteDeployment(project, options, built.folder, built.runtime);
125
- const human = [`Run site plan: site Worker ${plan.worker}, Base-generated, ${built.runtime ? 'docs-search runtime with ASSETS and AI' : 'its only binding the assets'} (the app's Worker ${plan.appWorker} is not touched)`, ` assets: ${plan.assets} (${built.files} files; HTML ${plan.assetsConfig.html_handling}, not found ${plan.assetsConfig.not_found_handling}; the Worker runs first)`,
128
+ const assets = relative(project.root, plan.assets);
129
+ const human = [`Run site plan: site Worker ${plan.worker}, Base-generated, ${built.runtime ? 'docs-search runtime with ASSETS and AI' : 'its only binding the assets'} (the app's Worker ${plan.appWorker} is not touched)`, ` assets: ${assets} (${built.files} files; HTML ${plan.assetsConfig.html_handling}, not found ${plan.assetsConfig.not_found_handling}; the Worker runs first)`,
126
130
  ` custom domains: ${plan.hostnames.join(', ')}; workers.dev off`, ...plan.redirects.map(rule => ` redirect in the Worker: ${rule.from} -> ${rule.to} (${rule.status}, keeps ${rule.keeps.join(' and ')})`)];
127
131
  const { collectFiles } = await import('../modules/deploy-kit/artifact.mjs');
128
132
  const { siteFingerprint } = await import('../modules/deploy-kit/site.mjs');
@@ -131,7 +135,7 @@ export async function siteCommand(project, options, store, signal, out) {
131
135
  if (runtime) human.push(` runtime: ${runtime.type}; module ${runtime.module}; endpoint ${runtime.endpoint}; bindings ${runtime.bindings.join(', ')}; model ${runtime.model}; pooling ${runtime.pooling}; corpus ${runtime.corpusHash}`);
132
136
  const fingerprint = siteFingerprint(plan, files, {preparing:Boolean(runtime) && !prepare});
133
137
  if (runtime) human.push(` fingerprint: ${fingerprint}${prepare ? '' : ' (vectors prepared only on a real deploy)'}`);
134
- const summary = { ...(runtime ? {runtime, fingerprint, vectors:prepare ? 'prepared' : 'prepare-on-deploy'} : {}), worker: plan.worker, appWorker: plan.appWorker, module: plan.module, bindings: plan.bindings, assets: plan.assets, files: built.files, references:built.references, domain: plan.domain, hostnames: plan.hostnames, workersDev: false, runWorkerFirst: true, assetsConfig: plan.assetsConfig, redirects: plan.redirects.map(({ from, to, status }) => ({ from, to, status })) };
138
+ const summary = { ...(runtime ? {runtime, fingerprint, vectors:prepare ? 'prepared' : 'prepare-on-deploy'} : {}), worker: plan.worker, appWorker: plan.appWorker, module: plan.module, bindings: plan.bindings, assets, files: built.files, references:built.references, domain: plan.domain, hostnames: plan.hostnames, workersDev: false, runWorkerFirst: true, assetsConfig: plan.assetsConfig, redirects: plan.redirects.map(({ from, to, status }) => ({ from, to, status })) };
135
139
  if (options.dryRun) {
136
140
  if (options.json) out.event('site', summary); else for (const line of human) out.human(line);
137
141
  store.report('deploy --site: dry run complete; no deployment occurred and no provider request was made.');
@@ -0,0 +1,39 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import {VERSION} from './manifest.mjs';
4
+ import {resolveSources} from './lock.mjs';
5
+ import {validate} from './base-copies.mjs';
6
+ import {git, json, noLinks, tracked, writeTree} from './files.mjs';
7
+
8
+ // Existing source and copy/composition provenance stay authoritative. Adoption
9
+ // adds a local-source recipe and lock; it does not regenerate the product or
10
+ // manufacture an upstream origin for source the seed already owns.
11
+ export function adoptEdition(root) {
12
+ if (fs.realpathSync(git(root, 'rev-parse', '--show-toplevel')) !== fs.realpathSync(root)) throw Error('Run adoption at the edition Git repository root.');
13
+ for (const name of ['edition.json', 'sources.lock.json', 'base-copies.json', 'rer-project.json', 'OPERATIONS.json']) noLinks(root, name);
14
+ if (fs.existsSync(path.join(root, 'edition.json')) || fs.existsSync(path.join(root, 'sources.lock.json'))) throw Error('Edition authoring inputs already exist. Preserve them; inspect and lock with the existing edition-authoring CLI instead of adopting again.');
15
+ const read = name => fs.existsSync(path.join(root, name)) ? JSON.parse(fs.readFileSync(path.join(root, name), 'utf8')) : {};
16
+ const id = read('rer-project.json').projectId ?? read('OPERATIONS.json').project;
17
+ if (typeof id !== 'string' || !/^[a-zA-Z0-9][a-zA-Z0-9._-]*\/[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(id)) throw Error('Declare a publisher-qualified projectId in rer-project.json before rer adopt-edition.');
18
+ const files = tracked(root);
19
+ const paths = Object.keys(files).filter(name => !['edition.json', 'sources.lock.json'].includes(name) && !name.startsWith('.edition'));
20
+ if (!paths.length) throw Error('Adoption needs tracked edition source. Add the intended source with git add, then repeat rer adopt-edition.');
21
+ const hasRecord = fs.existsSync(path.join(root, 'base-copies.json'));
22
+ if (hasRecord) validate(read('base-copies.json'));
23
+ const recipe = {schemaVersion: 1, id, toolchain: {id: 'runeditrun/edition-authoring', version: VERSION}, parent: null,
24
+ components: [{id, role: 'edition', source: {kind: 'local', paths}}]};
25
+ const created = [];
26
+ try {
27
+ const put = (name, value) => { writeTree(root, {[name]: {data: Buffer.from(json(value)).toString('base64'), executable: false}}); created.push(name); };
28
+ put('edition.json', recipe);
29
+ if (!hasRecord) put('base-copies.json', {schemaVersion: 1, copies: []});
30
+ const record = path.join(root, 'base-copies.json');
31
+ const additional = {'base-copies.json': {data: fs.readFileSync(record).toString('base64'), executable: !!(fs.statSync(record).mode & 0o111)}};
32
+ put('sources.lock.json', resolveSources(root, false, false, additional));
33
+ } catch (error) {
34
+ for (const name of created) fs.rmSync(path.join(root, name));
35
+ throw error;
36
+ }
37
+ return {adopted: id, created, record: 'base-copies.json', preservedCopyRecord: hasRecord,
38
+ next: 'Review git diff and git status; stage edition.json, sources.lock.json and any untracked base-copies.json. Existing copy and composition provenance is preserved. An empty copy record claims no Base copies; record known copies before refreshing. Run the edition tests before committing.'};
39
+ }
@@ -0,0 +1,24 @@
1
+ import path from 'node:path';
2
+ import {fileURLToPath} from 'node:url';
3
+ import {hash} from './files.mjs';
4
+
5
+ const cli = fileURLToPath(new URL('./cli.mjs', import.meta.url));
6
+ const quote = value => /^[a-zA-Z0-9_./:-]+$/.test(value) ? value : `'${value.replaceAll("'", "'\\''")}'`;
7
+
8
+ export const snapshot = file => ({sha256: hash(file.read()), mode: file.executable ? '100755' : '100644'});
9
+
10
+ // Keep the upstream baseline separate from the local bytes the owner accepted.
11
+ // Legacy declarations remain readable, but cannot silently acknowledge new bytes.
12
+ export function acknowledgementDrift(root, copy, name, file, recordPath) {
13
+ const relative = path.relative(root, cli);
14
+ const command = ['node', relative.startsWith('..') ? cli : relative, 'adapt-base', name,
15
+ ...(recordPath === 'base-copies.json' ? [] : ['--record', recordPath])].map(quote).join(' ');
16
+ const detail = {path: name, copy: copy.path, acknowledge: command};
17
+ const expected = copy.acknowledged?.[name];
18
+ if (!expected) return [{kind: 'adaptation-unacknowledged', ...detail}];
19
+ const actual = snapshot(file);
20
+ const drift = [];
21
+ if (actual.sha256 !== expected.sha256) drift.push({kind: 'adaptation-modified', ...detail, expected: expected.sha256, actual: actual.sha256});
22
+ if (actual.mode !== expected.mode) drift.push({kind: 'adaptation-mode', ...detail, expected: expected.mode, actual: actual.mode});
23
+ return drift;
24
+ }