@runeditrun/rer 0.2.80 → 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 (57) hide show
  1. package/cli/deploy-needs.mjs +4 -2
  2. package/cli/export.mjs +1 -1
  3. package/cli/ledger-refusal.mjs +18 -0
  4. package/cli/portability-migrations.mjs +30 -11
  5. package/cli/portability-worker.mjs +3 -1
  6. package/cli/portability.mjs +2 -0
  7. package/cli/release.mjs +4 -4
  8. package/cli/site-hosting.mjs +90 -0
  9. package/cli/site-render.mjs +3 -2
  10. package/cli/site.mjs +5 -2
  11. package/edition-authoring/base-copies.mjs +9 -0
  12. package/edition-authoring/runtime-dependencies.mjs +108 -0
  13. package/global/CHANGELOG.md +12 -0
  14. package/modules/demo/README.md +8 -0
  15. package/modules/demo/navigation.mjs +131 -15
  16. package/modules/dependencies/auth.mjs +2 -2
  17. package/modules/deploy-kit/owner.mjs +8 -1
  18. package/modules/import-kit/src/d1/apply-effects.ts +33 -0
  19. package/modules/import-kit/src/d1/apply.ts +38 -10
  20. package/modules/import-kit/src/types.ts +3 -1
  21. package/modules/operator-auth/README.md +92 -3
  22. package/modules/operator-auth/accounts/admin.mjs +52 -20
  23. package/modules/operator-auth/accounts/audit.mjs +24 -0
  24. package/modules/operator-auth/accounts/business-team.mjs +91 -0
  25. package/modules/operator-auth/accounts/domain-audit.mjs +24 -0
  26. package/modules/operator-auth/accounts/native.mjs +3 -1
  27. package/modules/operator-auth/accounts/settings-page.mjs +15 -2
  28. package/modules/operator-auth/accounts/status.mjs +7 -2
  29. package/modules/operator-auth/accounts/store.mjs +32 -6
  30. package/modules/operator-auth/business-settings.mjs +40 -0
  31. package/modules/operator-auth/identity/email-link/index.mjs +1 -1
  32. package/modules/operator-auth/identity/oidc/admin-audit.mjs +31 -0
  33. package/modules/operator-auth/identity/oidc/index.mjs +12 -5
  34. package/modules/operator-auth/identity/oidc/store.mjs +2 -0
  35. package/modules/operator-auth/index.d.mts +40 -1
  36. package/modules/operator-auth/routes.mjs +11 -6
  37. package/modules/operator-auth/service.mjs +8 -3
  38. package/modules/operator-auth/signin/index.mjs +1 -1
  39. package/modules/portability/README.md +82 -1
  40. package/modules/portability/export.mjs +6 -4
  41. package/modules/portability/format.mjs +5 -0
  42. package/modules/portability/index.d.mts +10 -2
  43. package/modules/portability/index.mjs +3 -2
  44. package/modules/portability/ledgers.mjs +27 -4
  45. package/modules/release/README.md +74 -2
  46. package/modules/release/sign.mjs +4 -2
  47. package/modules/release/signature.mjs +14 -7
  48. package/modules/release/signing-cli.mjs +2 -1
  49. package/modules/release/statement.mjs +2 -2
  50. package/modules/release/vectors/generate.mjs +1 -0
  51. package/modules/release/vectors/publisher-projects.mjs +133 -0
  52. package/modules/release/vectors/release-signature-vectors.json +5195 -0
  53. package/modules/release/verify.mjs +5 -1
  54. package/onboarding/schema/SETUP.schema.json +43 -1
  55. package/onboarding/schema/business-field-inputs.mjs +0 -1
  56. package/onboarding/schema/setup-validation.mjs +3 -0
  57. package/package.json +1 -1
@@ -21,12 +21,14 @@ export function deployGuide(declaration) {
21
21
  return value;
22
22
  }
23
23
 
24
+ /** The account permissions an API token needs to deploy this declaration (the run site's /docs/hosting lists the same). */
25
+ export const deployPermissions = declaration => permissions.filter(([, used]) => used(declaration)).map(([name]) => name);
26
+
24
27
  // Where a person gets the Cloudflare values: the project's guide, else the token page and the permissions.
25
28
  function credentialHelp(declaration) {
26
29
  const guide = deployGuide(declaration);
27
30
  if (guide) return [`Follow this project's deploy guide: ${guide}`];
28
- const needed = permissions.filter(([, used]) => used(declaration)).map(([name]) => name);
29
- return [`Create an account API token at ${tokenPage} with these account permissions: ${needed.join(', ')}. Copy your account ID from the Cloudflare dashboard.`];
31
+ return [`Create an account API token at ${tokenPage} with these account permissions: ${deployPermissions(declaration).join(', ')}. Copy your account ID from the Cloudflare dashboard.`];
30
32
  }
31
33
 
32
34
  export function missingCredentialsMessage(declaration, env, { dryRun = false, signIn } = {}) {
package/cli/export.mjs CHANGED
@@ -6,7 +6,7 @@ import { cliVersion } from './version.mjs';
6
6
 
7
7
  // Copy whole maintained source/tooling directories. Python publication scans
8
8
  // load sibling modules and data dynamically; they belong in the inventory too.
9
- export const sourceRoots = ['default-seed/public/rer-theme.css', 'default-seed/public/brand/mark.svg', 'default-seed/public/fonts/outfit', 'bin/rer.mjs', 'cli', 'modules/delivery-producer/declarations.mjs', 'modules/delivery-producer/bindings.mjs', 'modules/delivery-producer/migrations.mjs', 'modules/delivery-producer/mail.mjs', 'modules/job-queue', 'modules/release', 'modules/deploy-kit', 'modules/site', 'modules/container', 'modules/demo-host', 'modules/demo', 'modules/integrations/core', 'modules/mail', 'modules/ai', 'modules/portability', 'modules/d1-transport', 'modules/import-kit/src/d1', 'modules/import-kit/src/types.ts', 'modules/import-kit/src/plan', 'modules/import-kit/src/provenance/canonical-hash.ts', 'modules/import-kit/src/provenance/canonical-stream.ts', 'modules/import-kit/src/provenance/credential-names.ts', 'modules/import-kit/src/provenance/credentials.ts', 'modules/import-kit/src/provenance/identity.ts', 'modules/import-kit/src/provenance/json-snapshot.ts', 'modules/import-kit/src/provenance/resumable-sha256.ts', 'modules/import-kit/src/provenance/validate-json.ts', 'modules/import-kit/src/journal/authority.ts', 'modules/import-kit/src/storage/originals.ts', 'modules/import-kit/src/storage/provenance.ts', 'modules/import-kit/src/storage/schema.ts', 'modules/erasure', 'modules/dependencies', 'modules/operator-auth', 'modules/owner-claim', 'operations', 'scripts/publish-check', 'scripts/publish-check.mjs', 'composition/git-source.mjs', 'edition-authoring/adopt.mjs', 'edition-authoring/base-acknowledgements.mjs', 'edition-authoring/base-copies.mjs', 'edition-authoring/cli.mjs', 'edition-authoring/copy-checkout.mjs', 'edition-authoring/files.mjs', 'edition-authoring/lock.mjs', 'edition-authoring/manifest.mjs', 'edition-authoring/offline-git.mjs', 'edition-authoring/parent-comparison.mjs', 'edition-authoring/projection-lock.mjs', 'edition-authoring/release.mjs', 'edition-authoring/sources.mjs', 'edition-authoring/updates.mjs', 'foundation/runtime/seed-contract.mjs'];
9
+ export const sourceRoots = ['default-seed/public/rer-theme.css', 'default-seed/public/brand/mark.svg', 'default-seed/public/fonts/outfit', 'bin/rer.mjs', 'cli', 'modules/delivery-producer/declarations.mjs', 'modules/delivery-producer/bindings.mjs', 'modules/delivery-producer/migrations.mjs', 'modules/delivery-producer/mail.mjs', 'modules/job-queue', 'modules/release', 'modules/deploy-kit', 'modules/site', 'modules/container', 'modules/demo-host', 'modules/demo', 'modules/integrations/core', 'modules/mail', 'modules/ai', 'modules/portability', 'modules/d1-transport', 'modules/import-kit/src/d1', 'modules/import-kit/src/types.ts', 'modules/import-kit/src/plan', 'modules/import-kit/src/provenance/canonical-hash.ts', 'modules/import-kit/src/provenance/canonical-stream.ts', 'modules/import-kit/src/provenance/credential-names.ts', 'modules/import-kit/src/provenance/credentials.ts', 'modules/import-kit/src/provenance/identity.ts', 'modules/import-kit/src/provenance/json-snapshot.ts', 'modules/import-kit/src/provenance/resumable-sha256.ts', 'modules/import-kit/src/provenance/validate-json.ts', 'modules/import-kit/src/journal/authority.ts', 'modules/import-kit/src/storage/originals.ts', 'modules/import-kit/src/storage/provenance.ts', 'modules/import-kit/src/storage/schema.ts', 'modules/erasure', 'modules/dependencies', 'modules/operator-auth', 'modules/owner-claim', 'operations', 'scripts/publish-check', 'scripts/publish-check.mjs', 'composition/git-source.mjs', 'edition-authoring/adopt.mjs', 'edition-authoring/base-acknowledgements.mjs', 'edition-authoring/base-copies.mjs', 'edition-authoring/cli.mjs', 'edition-authoring/copy-checkout.mjs', 'edition-authoring/files.mjs', 'edition-authoring/lock.mjs', 'edition-authoring/manifest.mjs', 'edition-authoring/offline-git.mjs', 'edition-authoring/parent-comparison.mjs', 'edition-authoring/projection-lock.mjs', 'edition-authoring/release.mjs', 'edition-authoring/runtime-dependencies.mjs', 'edition-authoring/sources.mjs', 'edition-authoring/updates.mjs', 'foundation/runtime/seed-contract.mjs'];
10
10
  export async function inventory(base, roots = sourceRoots) {
11
11
  const files = [];
12
12
  async function walk(path) {
@@ -0,0 +1,18 @@
1
+ // What a person does about each migration-history refusal (portability-migrations.mjs, modules/portability/ledgers.mjs).
2
+ // Codes are constant categories; a migration named by an archive or the checkout follows the second colon.
3
+ const fixes = {
4
+ unknown: 'the archive records a migration whose file name or content this checkout does not have. Restore with the checkout version that exported it (or a later one), with its migration files unchanged.',
5
+ conflict: 'a migration in the archive has the name of one checkout file and the content of another. Restore with the checkout version that exported it, with its migration files unchanged.',
6
+ ambiguous: 'one migration identity matches several checkout files or ledger entries. Keep a single file per migration and declare the seed\'s migration prefix.',
7
+ unapplied: 'the installation\'s history lacks a migration this checkout ships. Apply it with the runner that owns the history (RER Platform for a Managed installation), then retry.',
8
+ multiple: 'the database holds more than one migration ledger. Reconcile its history with the runner that owns it.',
9
+ uncertain: 'a migration was left partly applied. Finish or roll back that operation with its runner, then retry.',
10
+ runner: 'the history belongs to the older Base deploy runner, which can adopt it. Use that runner first.',
11
+ incompatible: 'the migration ledger or the checkout declaration has an unsupported shape. Use the matching checkout and its declaration.',
12
+ binding: 'the checkout declares no single D1 binding with that name. Use the matching checkout.',
13
+ };
14
+ export function ledgerRefusal(receipt) {
15
+ const [, kind, ...name] = receipt.reason.split(':');
16
+ const named = receipt.unapplied ?? (name.length ? name.join(':') : undefined);
17
+ return `Migration history refused (${receipt.reason}): ${named ? `migration ${named}: ` : ''}${fixes[kind] ?? 'its history does not match this checkout.'}`;
18
+ }
@@ -35,6 +35,33 @@ export async function appliedMigrations(root,db,binding,declaration,split) {
35
35
  return matchMigrationLedger(ledger,files,declaration).map(name=>files.find(file=>file.name===name));
36
36
  }
37
37
 
38
+ // Ledger contents can contain private values. Report constant categories,
39
+ // retaining the transfer's canonical compatibility and hash-matching policy.
40
+ function constantRefusal(error) {
41
+ if(!(error instanceof PortabilityError))return error;
42
+ const code=error.code.startsWith('migration_ledger:')?error.code.split(':').slice(0,2).join(':')
43
+ :error.code==='schema_mismatch:uncertain_migrations'?'migration_ledger:uncertain':'migration_ledger:incompatible';
44
+ return Object.assign(new PortabilityError(code,409),error.migration===undefined?{}:{migration:error.migration});
45
+ }
46
+
47
+ // For adapters with their own archive format: the entries of a migration ledger
48
+ // ([{name,sha256}], as RER Platform's rer_migrations records them or as an
49
+ // archive carries them) named by the checkout's migration files, matched by
50
+ // SHA-256 and refused when a name or hash differs from the checkout's. The
51
+ // result is the native-equivalent ledger: write it to an export, or compare it
52
+ // with the archive on import, instead of comparing ledger controllers.
53
+ // Declared data-only entries keep their own names. Reads files only.
54
+ export async function mapMigrationLedger({root,binding='DB',platformMigrations,entries}) {
55
+ const declaration=platformMigrationDeclaration(platformMigrations);
56
+ insist(Array.isArray(entries) && entries.every(entry=>entry && typeof entry.name==='string' && typeof entry.sha256==='string' && /^[a-f0-9]{64}$/.test(entry.sha256)) && new Set(entries.map(entry=>entry.name)).size===entries.length,'migration_ledger:incompatible',409);
57
+ const files=await inventory(root,binding,declaration);
58
+ try {
59
+ const mapped=entries.map(({name,sha256})=>({name:matchMigrationLedger([{name,sha256}],files,declaration)[0]??name,sha256}));
60
+ insist(new Set(mapped.map(entry=>entry.name)).size===mapped.length,'migration_ledger:ambiguous',409);
61
+ return mapped;
62
+ } catch(error) { throw constantRefusal(error); }
63
+ }
64
+
38
65
  // Adapter entry point, before *any* native Wrangler apply. The caller supplies
39
66
  // the real target binding and keeps its writers stopped through apply/transfer.
40
67
  // This only reads: it never repairs history or creates a second ledger.
@@ -52,16 +79,8 @@ export async function nativeMigrationPreflight({root,db,binding='DB',platformMig
52
79
  const ledger=await destinationLedger(db),applied=matchMigrationLedger(ledger,files,declaration);
53
80
  // Wrangler skips only literal filenames, not transfer aliases or hashes.
54
81
  if(table==='d1_migrations')insist(ledger.every(row=>files.some(file=>file.name===row.name)),'migration_ledger:incompatible',409);
55
- if(table==='rer_migrations')for(const file of files)insist(applied.includes(file.name),'migration_ledger:unapplied',409);
56
- } catch(error) {
57
- // Ledger contents can contain private values. Report constant categories,
58
- // retaining the transfer's canonical compatibility and hash-matching policy.
59
- if(error instanceof PortabilityError) {
60
- const code=error.code.startsWith('migration_ledger:')?error.code.split(':').slice(0,2).join(':')
61
- :error.code==='schema_mismatch:uncertain_migrations'?'migration_ledger:uncertain':'migration_ledger:incompatible';
62
- throw new PortabilityError(code,409);
63
- }
64
- throw error;
65
- }
82
+ // The checkout file is named: it is the seed's own, never a ledger value.
83
+ if(table==='rer_migrations')for(const file of files)if(!applied.includes(file.name))throw Object.assign(new PortabilityError('migration_ledger:unapplied',409),{migration:file.name});
84
+ } catch(error) { throw constantRefusal(error); }
66
85
  return {nativeApply:table==='d1_migrations'};
67
86
  }
@@ -74,6 +74,8 @@ catch (error) {
74
74
  const reason = error instanceof PortabilityError ? (error.code.startsWith('migration_ledger:') ? error.code : error.code.split(':')[0]) : /^[A-Z_]+$/.test(error.code ?? '') ? error.code : error.message === 'archive_json' ? 'archive_json' : 'native_error';
75
75
  // A later migration that changes restorable data is named: it is a file of this installation.
76
76
  const migration = error instanceof PortabilityError && error.code.startsWith('schema_mismatch:migration_data:') ? error.code.slice('schema_mismatch:migration_data:'.length) : undefined;
77
+ // An unapplied migration is a file of this checkout: it is named so it can be applied.
78
+ const unapplied = error instanceof PortabilityError && error.code === 'migration_ledger:unapplied' ? error.migration : undefined;
77
79
  const reExport = error instanceof PortabilityError && ['schema_mismatch:legacy_schema','schema_mismatch:unsupported_sql'].includes(error.code);
78
80
  // A populated destination names its table or bucket: schema names, never row data.
79
81
  const occupied = error instanceof PortabilityError && /^(target|bucket)_not_empty:/.test(error.code) ? error.code.slice(error.code.indexOf(':') + 1) : undefined;
@@ -82,5 +84,5 @@ catch (error) {
82
84
  // Anything that is not a portability refusal names its class and code, never its message: that can hold row data.
83
85
  const native = error instanceof PortabilityError || error.message === 'archive_json' ? undefined : nativeFailure(error);
84
86
  process.exitCode = exitCode;
85
- await reply({ ok: false, code: exitCode === 2 ? 'invalid_archive' : exitCode === 4 ? 'restore_refused' : 'transfer_failed', reason, ...(reExport ? { reExport: true } : {}), ...(migration ? { migration } : {}), ...(occupied ? { occupied } : {}), ...(safety ? { safety } : {}), ...(native ? { native } : {}), exitCode });
87
+ await reply({ ok: false, code: exitCode === 2 ? 'invalid_archive' : exitCode === 4 ? 'restore_refused' : 'transfer_failed', reason, ...(reExport ? { reExport: true } : {}), ...(migration ? { migration } : {}), ...(unapplied ? { unapplied } : {}), ...(occupied ? { occupied } : {}), ...(safety ? { safety } : {}), ...(native ? { native } : {}), exitCode });
86
88
  }
@@ -7,6 +7,7 @@ import { fileRecords } from '../modules/portability/files.mjs';
7
7
  import { RerError, refuse } from './errors.mjs';
8
8
  import { policyModuleURL, serializablePolicy } from './portability-policy.mjs';
9
9
  import { shared } from './shared.mjs';
10
+ import { ledgerRefusal } from './ledger-refusal.mjs';
10
11
 
11
12
  const reExport = 'Re-export from the original installation with rer export --output exports/recovered.rer (add --target remote for a hosted installation), then retry rer import --input exports/recovered.rer --yes. Keep the original archive until recovery succeeds.';
12
13
 
@@ -88,6 +89,7 @@ async function nativeWorker(store,direction,input,signal) {
88
89
  : receipt.reason === 'archive_json' ? `Restore refused: the archive is damaged or incomplete. ${reExport}`
89
90
  : receipt.reExport ? `Restore refused (schema_mismatch): the schema definitions cannot be safely verified by this version. ${reExport}`
90
91
  : receipt.safety ? `Restore refused (${receipt.reason}): safety normalization for ${receipt.safety} violates the declared import policy.`
92
+ : receipt.reason?.startsWith('migration_ledger:') ? ledgerRefusal(receipt)
91
93
  : receipt.migration ? `Restore refused (schema_mismatch:migration_data): migration ${receipt.migration} changed data after this archive was made, so its rows would skip that change. Restore an archive made after it.`
92
94
  : receipt.occupied ? `Restore refused (${receipt.reason}): ${receipt.reason === 'bucket_not_empty' ? `storage bucket ${receipt.occupied} in this installation already holds files` : `table ${receipt.occupied} in this installation already holds rows its migrations did not insert`}, and a restore only goes into an empty installation. To replace this installation's data with the archive, keep a copy with rer export --output exports/before-restore.rer, then run rer reset --yes and rer import --input ${relative(input.root, input.path)} --yes again.`
93
95
  : `The portability module refused or failed the archive operation (${receipt.reason ?? 'incomplete'}${receipt.native ? `: ${receipt.native.class}${receipt.native.code && receipt.native.code !== receipt.reason ? `, code ${receipt.native.code}` : ''}` : ''}).${receipt.native && receipt.exitCode === 1 ? ' Run the same command again; it starts over.' : ''}`, receipt.exitCode ?? 1);
package/cli/release.mjs CHANGED
@@ -2,15 +2,14 @@ import { releaseVerb } from './contract.mjs';
2
2
  import { parseTimeoutSeconds, timeoutBounds } from '../scripts/publish-check/timeout.mjs';
3
3
 
4
4
  // Preserve release's accepted parser, producer, receipt and validation exits.
5
- 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]
6
6
 
7
7
  Produce local artifacts using the exact source commit's green GitHub Verify,
8
8
  frozen installation, local build and publication checks.
9
9
  Without --tag, write a preview. This command never pushes, uploads or deploys.
10
10
 
11
11
  --repo DIR Source Git repository.
12
- --project PUBLISHER/NAME
13
- Publishing identity.
12
+ --project OWNER/NAME Project identity recorded by the edition.
14
13
  --repository GITHUB_URL
15
14
  Credential-free https://github.com/<owner>/<repository> destination.
16
15
  --output NEW_DIR New output directory outside the source repository.
@@ -40,13 +39,14 @@ Without --tag, write a preview. This command never pushes, uploads or deploys.
40
39
  --help Print this help without performing release work.
41
40
 
42
41
  Signing and receipt commands:
43
- 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]
44
43
  rer release receipt --artifact DIR --anchors FILE [--environment test] [--after VERSION:SHA256]
45
44
  rer release keygen --scope test|rer --publisher NAMESPACE --github-owner LOGIN --github-owner-id ID --anchor-out FILE
46
45
  [--not-before YYYY-MM-DDTHH:MM:SSZ] [--not-after YYYY-MM-DDTHH:MM:SSZ]
47
46
  [--unsigned-through PROJECT:VERSION ...]
48
47
 
49
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.
50
50
  Key generation requires non-terminal stdout; --key-stdin requires non-terminal stdin.
51
51
  `;
52
52
 
@@ -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
+ }
@@ -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);
@@ -13,6 +13,7 @@ import {execFileSync} from 'node:child_process';
13
13
  import {hash, json, git, raw, gitReader, safe, noLinks, testSource} from './files.mjs';
14
14
  import {snapshot, acknowledgementDrift} from './base-acknowledgements.mjs';
15
15
  import {requireMaterializedCopies} from './copy-checkout.mjs';
16
+ import {completeRuntimeCopies} from './runtime-dependencies.mjs';
16
17
 
17
18
  export const RECORD = 'base-copies.json';
18
19
  const commit = /^[a-f0-9]{40}$/, sha256 = /^[a-f0-9]{64}$/;
@@ -382,6 +383,14 @@ export function refreshCopies(root, {positional: [revision], record: recordPath,
382
383
  if (!sources.length && !Object.keys(copy.adapted || {}).length) throw Error(`No Base source at ${copy.originPath} in ${revision}`);
383
384
  return {copy, sources, retired, removed: Object.keys(copy.files).filter(name => !Object.hasOwn(copy.adapted || {}, name) && !sources.some(([source]) => mapped(source, copy.originPath, copy.path) === name))};
384
385
  });
386
+ completeRuntimeCopies(plans, {tree: next, read, local, upstream, revision, checkTarget(name) {
387
+ safe(name); noLinks(root, name);
388
+ const target = path.join(root, name);
389
+ if (fs.existsSync(target) && !fs.lstatSync(target).isFile()) throw Error(`Runtime dependency is not a regular file: ${name}`);
390
+ }});
391
+ // Closure may add individually recorded siblings when the seed originally
392
+ // selected runtime files one at a time instead of copying the directory.
393
+ record.copies = plans.map(plan => plan.copy).sort((a, b) => a.path.localeCompare(b.path));
385
394
  // A migration a database may already have applied is never rewritten in place:
386
395
  // the schema change it brings belongs in a new migration of the seed's own.
387
396
  const applied = plans.flatMap(({copy, sources}) => sources.map(([source, {object}]) => [mapped(source, copy.originPath, copy.path), object])
@@ -0,0 +1,108 @@
1
+ // Keep partial and single-file runtime copies closed over their relative imports.
2
+ // Both maintained exporters already ship the whole foundation/runtime directory;
3
+ // refresh must also recover siblings omitted by an older seed's copy selection.
4
+ import path from 'node:path';
5
+
6
+ const runtime = 'foundation/runtime/';
7
+ const code = /\.(?:[cm]?[jt]s|[jt]sx)$/;
8
+ const inside = (name, prefix) => name === prefix || name.startsWith(prefix + '/');
9
+ const mapped = (name, from, to) => to + name.slice(from.length);
10
+
11
+ // Tokenize enough module syntax to ignore comments and quoted page/CSS content.
12
+ // Static imports (including type imports), re-exports and literal import() /
13
+ // require() calls share the same relative resolution below. Templates are page
14
+ // content, never static module declarations.
15
+ function specifiers(source) {
16
+ const tokens = [...source.matchAll(/\/\/[^\n]*|\/\*[\s\S]*?\*\/|`(?:\\[\s\S]|[^`\\])*`|'(?:\\[\s\S]|[^'\\])*'|"(?:\\[\s\S]|[^"\\])*"|[\w$]+|[^\s]/g)]
17
+ .map(match => match[0]).filter(token => !token.startsWith('//') && !token.startsWith('/*') && !token.startsWith('`'));
18
+ const result = [];
19
+ const literal = token => /^['"]\.{1,2}\//.test(token || '') ? token.slice(1, -1) : null;
20
+ for (let i = 0; i < tokens.length; i++) {
21
+ if (!['import', 'export', 'require'].includes(tokens[i])) continue;
22
+ if (tokens[i - 1] === '.' || (tokens[i] === 'require' && tokens[i + 1] !== '(')) continue;
23
+ if (tokens[i] === 'export' && !['{', '*', 'type'].includes(tokens[i + 1])) continue;
24
+ let value = literal(tokens[i + 1]);
25
+ if (tokens[i + 1] === '(') value = literal(tokens[i + 2]);
26
+ else if (!value) {
27
+ for (let j = i + 1; j < tokens.length && ![';', 'import', 'export'].includes(tokens[j]); j++) {
28
+ if (tokens[j] === 'from') { value = literal(tokens[j + 1]); break; }
29
+ }
30
+ }
31
+ if (value) result.push(value);
32
+ }
33
+ return result;
34
+ }
35
+
36
+ function resolve(tree, source, specifier) {
37
+ const name = path.posix.normalize(path.posix.join(path.posix.dirname(source), specifier));
38
+ const candidates = [name];
39
+ // TypeScript source commonly uses its emitted JS extension in imports.
40
+ const replacement = {'.js': ['.ts', '.tsx', '.d.ts'], '.mjs': ['.mts', '.d.mts'], '.cjs': ['.cts', '.d.cts']}[path.posix.extname(name)];
41
+ if (replacement) candidates.push(...replacement.map(extension => name.slice(0, -path.posix.extname(name).length) + extension));
42
+ if (!path.posix.extname(name)) {
43
+ for (const suffix of ['.ts', '.tsx', '.mts', '.mjs', '.js', '.jsx', '.cts', '.cjs', '.json']) candidates.push(name + suffix, name + '/index' + suffix);
44
+ }
45
+ const found = candidates.find(candidate => tree.has(candidate));
46
+ if (!found || !found.startsWith(runtime)) throw Error(`Cannot ship runtime dependency ${specifier} from ${source}; keep its source inside foundation/runtime`);
47
+ return found;
48
+ }
49
+
50
+ export function completeRuntimeCopies(plans, {tree, read, local, upstream, revision, checkTarget}) {
51
+ const queue = plans.flatMap(plan => plan.sources.filter(([source]) => source.startsWith(runtime) && code.test(source))
52
+ .map(([source]) => ({source, target: mapped(source, plan.copy.originPath, plan.copy.path), baseline: plan.copy.revision})));
53
+ const seen = new Set();
54
+ const blobs = new Map();
55
+ function bytes(source) {
56
+ const object = tree.get(source).object;
57
+ if (!blobs.has(object)) blobs.set(object, read.blobs([object]).get(object));
58
+ return blobs.get(object).toString('utf8');
59
+ }
60
+ function include(source, target, baseline) {
61
+ checkTarget(target);
62
+ let plan = plans.find(plan => inside(target, plan.copy.path));
63
+ if (plan && mapped(target, plan.copy.path, plan.copy.originPath) !== source) throw Error(`Runtime dependency ${target} conflicts with its Base copy mapping`);
64
+ // A missing recorded file is a removal, not an omitted sibling. Restoring
65
+ // it here would bypass refresh's retirement/removal plan and could leave
66
+ // the recreated source outside its record. Refuse before any writes.
67
+ if (plan?.removed.includes(target)) throw Error(`Runtime dependency ${target} was removed locally but is still imported; no files were refreshed. Restore it or adapt the importing module before refreshing.`);
68
+ if (plan?.copy.adapted?.[target]) {
69
+ queue.push({source, target, baseline});
70
+ return; // Keep seed bytes while supplying the shipped module's dependencies.
71
+ }
72
+ if (!plan?.sources.some(([name]) => name === source)) {
73
+ const actual = local(target);
74
+ const previous = actual && read.tree(baseline).get(source);
75
+ const previousDigest = previous && read.digests([previous.object]).get(previous.object);
76
+ if (actual && actual !== upstream.get(tree.get(source).object) && actual !== previousDigest) {
77
+ // Existing unrecorded siblings belong to the seed, just as in the
78
+ // ordinary copy selection. They already satisfy this import's presence;
79
+ // only an absent sibling needs to be supplied by Base. Keep traversing
80
+ // the shipped graph so a later adoption cannot omit its dependencies.
81
+ // Recorded edits and acknowledgements were checked before planning.
82
+ queue.push({source, target, baseline});
83
+ return;
84
+ }
85
+ if (!plan) {
86
+ if (plans.some(plan => inside(plan.copy.path, target))) throw Error(`Runtime dependency ${target} overlaps an existing Base copy`);
87
+ plan = {copy: {path: target, originPath: source, revision, files: {}, modes: {}}, sources: [], removed: []};
88
+ plans.push(plan);
89
+ }
90
+ plan.sources.push([source, tree.get(source)]);
91
+ plan.removed = plan.removed.filter(name => name !== target);
92
+ }
93
+ queue.push({source, target, baseline});
94
+ }
95
+ for (let i = 0; i < queue.length; i++) {
96
+ const {source, target, baseline} = queue[i];
97
+ const key = source + '\0' + target;
98
+ if (seen.has(key)) continue;
99
+ seen.add(key);
100
+ if (code.test(source)) for (const specifier of specifiers(bytes(source))) {
101
+ const dependency = resolve(tree, source, specifier);
102
+ include(dependency, path.posix.join(path.posix.dirname(target), path.posix.relative(path.posix.dirname(source), dependency)), baseline);
103
+ }
104
+ // JS type imports also need the declaration file used by edition typechecks.
105
+ const declaration = source.replace(/\.mjs$/, '.d.mts').replace(/\.cjs$/, '.d.cts');
106
+ if (declaration !== source && tree.has(declaration)) include(declaration, target.replace(/\.mjs$/, '.d.mts').replace(/\.cjs$/, '.d.cts'), baseline);
107
+ }
108
+ }
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.81
4
+
5
+ - Import RER Platform archives into native installations by migration hash, recording `rer_migrations` as the source ledger without restoring it as product data; expose `mapMigrationLedger` for custom archive adapters and name unapplied files in preflight refusals.
6
+ - Project declared import intake fields before storing chunks, keeping excluded values such as Auth0 password hashes and Okta credentials and factors out of custody.
7
+ - Validate preserving import adapters before every apply batch, including resumed work; retain earlier admitted batches for Undo when later preparation is refused.
8
+ - Deliver the shared three-way Run chooser and hosting guide through Base refresh, with byte-exact Copy, listing-aware Assisted and Managed links, and commands that wrap under adopted seed themes.
9
+ - Keep demo Run exits within available header space and reveal the full accessible link on keyboard focus without moving host controls.
10
+ - Add transactional audit hooks for native operator administration and direct installation exports; audit provider unlink only for a new pin generation.
11
+ - Apply signed runtime Business settings, same-origin logos, app accents, local overrides and owner-scoped team reconciliation; allow owners to stop settings with fresh sign-in proof.
12
+ - Authorize explicit publisher project lists with version 2 signing anchors and an optional signing publisher, while retaining version 1 verification.
13
+ - Simplify the shared Run invocation, show the public Roadmap without repository citations, and preserve retained runtime dependencies during Base copy refresh.
14
+
3
15
  ## 0.2.80
4
16
 
5
17
  - Healthy doctor now exits 0 when local settings are present.
@@ -37,6 +37,14 @@ Production build/deploy refuses that setting; ordinary builds keep real effects.
37
37
  local and hosted demos. No per-seed link is required. CSS adds the label suffix without
38
38
  changing the application's hydrated text; CSP allows exact hashes only.
39
39
 
40
+ The exit uses only spare space beside or directly below the label and truncates its own text.
41
+ It stays out of the host layout, preserving sibling rectangles and document
42
+ width relative to the same header with the Demo suffix but no exit. It never
43
+ repairs an already overflowing host header. With no readable room it remains
44
+ a keyboard stop; keyboard focus reveals the full link above clipping ancestors.
45
+ The full name is also its accessible name and title. The host keeps ownership
46
+ of its responsive layout.
47
+
40
48
  Public sockets, WebSockets and event streams remain usable for checks. The
41
49
  local sockets guard and hosted egress retain a small direct mail/SMS denylist;
42
50
  use the effect helper for such sends. Hosted demos keep their isolated