@raybase/cli 0.3.5 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { spawn, spawnSync } from "node:child_process";
3
- import { createHash, generateKeyPairSync, randomBytes } from "node:crypto";
3
+ import { createHash, randomBytes } from "node:crypto";
4
4
  import { createReadStream, createWriteStream, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, utimesSync, writeFileSync } from "node:fs";
5
5
  import { createRequire } from "node:module";
6
6
  import { dirname, isAbsolute, join, relative as pathRelative, resolve } from "node:path";
@@ -37,7 +37,7 @@ import { checkProjectPalettes, checkPaletteCss, formatPaletteCheck } from "./pal
37
37
  import { compilePalette, formatCompiledPalette, resolveHue } from "./palette-compile.js";
38
38
  import { addModule, doctorInstalledModules, firstPartyModuleEnabled, formatModuleDoctor, formatModuleInstall, formatModuleRemove, formatModuleStatus, formatModuleUpdate, moduleStatus, parseFirstPartyModuleId, removeModule, setFirstPartyModuleEnabled, updateModules } from "./modules.js";
39
39
  import { guideDocsSurfaceCorpusIssue, inspectGuideCorpus } from "./guide-corpus-doctor.js";
40
- import { buildRequirements, freshSecretValues, raybaseProductionSecrets, readBuiltWranglerConfig, writeBuildRequirements } from "./hosting.js";
40
+ import { buildRequirements, freshSecretValues, generateEcP256PrivateJwk, generateRandom32Secret, raybaseProductionSecrets, readBuiltWranglerConfig, writeBuildRequirements } from "./hosting.js";
41
41
  import { declareWranglerRequiredSecrets, missingWranglerRequiredSecretDeclarations, wranglerRequiredSecretsScopes } from "./wrangler-secrets.js";
42
42
  import { readRaybaseAppManifest, raybaseAppManifestFile, encodeRaybaseDevManifest, writeRaybaseAppManifest } from "./app-manifest.js";
43
43
  const program = new Command();
@@ -53,7 +53,7 @@ const FRAMEWORK_HELP = `Frameworks (each has a built-in starter):
53
53
  // through the pro plugin (reapplyProSkillsOverlay).
54
54
  const PRO_PROJECT_COMMANDS = new Set(["doctor", "check", "jobs", "ai", "retrieval", "search", "migrate", "dev", "connect", "deploy", "backup", "backups", "export", "restore", "invite", "update", "modules"]);
55
55
  const PRO_NAMESPACE_DELEGATE_COMMANDS = new Set(["upgrade", "provision", "skills", "attach", "install", "control-plane", "dev", "deploy"]);
56
- const CLI_VERSION = "0.3.5";
56
+ const CLI_VERSION = "0.3.7";
57
57
  // Pro's package took its own scope in 0.3.4. An app made before then declares
58
58
  // the old name; the CLI finds Pro under either, and doctor says which to move to.
59
59
  const PRO_PACKAGE = "@raybase-pro/pro";
@@ -120,6 +120,7 @@ program
120
120
  const removed = logoutLocalCredentials();
121
121
  output(options, { ok: true, removed }, removed.length ? "Removed local Raybase credentials." : "No local Raybase credentials were present.");
122
122
  });
123
+ const replaceOtherRegistryHelp = "Point @raybase and @raybase-pro at Raybase's registry even where the .npmrc sends them to another registry (left alone otherwise)";
123
124
  const accountCommand = program.command("account").description("Manage the active Raybase subscriber account.");
124
125
  accountCommand
125
126
  .command("list")
@@ -135,17 +136,14 @@ accountCommand
135
136
  .argument("<account>", "Account id or slug")
136
137
  .option("--json", "Print machine-readable JSON output")
137
138
  .option("--no-project-npmrc", "Do not write project .npmrc registry lines")
139
+ .option("--replace-other-registry", replaceOtherRegistryHelp)
138
140
  .option("--user-npmrc", "Write the raw registry token to ~/.npmrc")
139
141
  .action(async (account, options) => {
140
142
  const bundle = await useAccount(account);
141
143
  const stored = storeCredentialBundle(bundle);
142
- const registryUrl = stored.registry?.registryUrl ?? bundle.registryUrl;
143
- if (registryUrl && options.projectNpmrc !== false)
144
- writeProjectNpmrc(process.cwd(), registryUrl);
145
- if (options.userNpmrc && registryUrl && stored.registry?.token)
146
- writeUserNpmrc(registryUrl, stored.registry.token);
147
- const result = { ok: true, account: stored.account, registry: registrySummary(stored.registry), license: stored.license?.ok ? licenseSummary(stored.license) : stored.license };
148
- output(options, result, `Active Raybase account set to ${stored.account?.accountSlug ?? stored.account?.accountId ?? account}.`);
144
+ const npmrc = writeRegistryNpmrcFiles(options, stored.registry?.registryUrl ?? bundle.registryUrl, stored.registry?.token, `raybase account use ${account}`);
145
+ const result = { ok: true, account: stored.account, registry: registrySummary(stored.registry), license: stored.license?.ok ? licenseSummary(stored.license) : stored.license, ...npmrc.data };
146
+ output(options, result, [`Active Raybase account set to ${stored.account?.accountSlug ?? stored.account?.accountId ?? account}.`, ...npmrc.text].join("\n"));
149
147
  });
150
148
  accountCommand
151
149
  .command("billing")
@@ -286,40 +284,35 @@ proCommand
286
284
  .argument("<activation-code>", "Activation code from Raybase")
287
285
  .option("--json", "Print machine-readable JSON output")
288
286
  .option("--no-project-npmrc", "Do not write project .npmrc registry lines")
287
+ .option("--replace-other-registry", replaceOtherRegistryHelp)
289
288
  .option("--user-npmrc", "Write the raw registry token to ~/.npmrc")
290
289
  .action(async (activationCode, options) => {
291
290
  const bundle = await activateLicense(String(activationCode));
292
291
  const stored = storeCredentialBundle(bundle);
293
- const registryUrl = stored.registry?.registryUrl ?? bundle.registryUrl;
294
- if (registryUrl && options.projectNpmrc !== false)
295
- writeProjectNpmrc(process.cwd(), registryUrl);
296
- if (options.userNpmrc && registryUrl && stored.registry?.token)
297
- writeUserNpmrc(registryUrl, stored.registry.token);
292
+ const npmrc = writeRegistryNpmrcFiles(options, stored.registry?.registryUrl ?? bundle.registryUrl, stored.registry?.token, "raybase pro activate <activation-code>");
298
293
  const result = {
299
294
  ok: true,
300
295
  account: stored.account,
301
296
  license: stored.license?.ok ? licenseSummary(stored.license) : stored.license,
302
297
  registry: registrySummary(stored.registry),
303
- recommendedNpmrc: bundle.recommendedNpmrc
298
+ recommendedNpmrc: bundle.recommendedNpmrc,
299
+ ...npmrc.data
304
300
  };
305
- output(options, result, `Raybase Pro activated${stored.account?.accountSlug ? ` for ${stored.account.accountSlug}` : ""}.`);
301
+ output(options, result, [`Raybase Pro activated${stored.account?.accountSlug ? ` for ${stored.account.accountSlug}` : ""}.`, ...npmrc.text].join("\n"));
306
302
  });
307
303
  proCommand
308
304
  .command("refresh")
309
305
  .description("Refresh local Raybase Pro license state.")
310
306
  .option("--json", "Print machine-readable JSON output")
311
307
  .option("--no-project-npmrc", "Do not write project .npmrc registry lines")
308
+ .option("--replace-other-registry", replaceOtherRegistryHelp)
312
309
  .option("--user-npmrc", "Write the raw registry token to ~/.npmrc")
313
310
  .action(async (options) => {
314
311
  const bundle = await refreshLicense();
315
312
  const stored = storeCredentialBundle(bundle);
316
- const registryUrl = stored.registry?.registryUrl ?? bundle.registryUrl;
317
- if (registryUrl && options.projectNpmrc !== false)
318
- writeProjectNpmrc(process.cwd(), registryUrl);
319
- if (options.userNpmrc && registryUrl && stored.registry?.token)
320
- writeUserNpmrc(registryUrl, stored.registry.token);
321
- const result = { ok: true, account: stored.account, license: stored.license?.ok ? licenseSummary(stored.license) : stored.license, registry: registrySummary(stored.registry) };
322
- output(options, result, "Raybase Pro license refreshed.");
313
+ const npmrc = writeRegistryNpmrcFiles(options, stored.registry?.registryUrl ?? bundle.registryUrl, stored.registry?.token, "raybase pro refresh");
314
+ const result = { ok: true, account: stored.account, license: stored.license?.ok ? licenseSummary(stored.license) : stored.license, registry: registrySummary(stored.registry), ...npmrc.data };
315
+ output(options, result, ["Raybase Pro license refreshed.", ...npmrc.text].join("\n"));
323
316
  });
324
317
  const proRegistryCommand = proCommand.command("registry").description("Manage private Raybase Pro registry access.");
325
318
  proRegistryCommand
@@ -327,6 +320,7 @@ proRegistryCommand
327
320
  .description("Configure npm-compatible registry credentials for Raybase Pro packages.")
328
321
  .option("--json", "Print machine-readable JSON output")
329
322
  .option("--no-project-npmrc", "Do not write project .npmrc registry lines")
323
+ .option("--replace-other-registry", replaceOtherRegistryHelp)
330
324
  .option("--user-npmrc", "Write the raw registry token to ~/.npmrc")
331
325
  .action(async (options) => {
332
326
  const current = readRegistryState();
@@ -335,11 +329,8 @@ proRegistryCommand
335
329
  const registryUrl = stored.registry?.registryUrl;
336
330
  if (!registryUrl)
337
331
  throw new Error("No Raybase registry URL is configured. Run raybase pro refresh or raybase pro activate first.");
338
- if (options.projectNpmrc !== false)
339
- writeProjectNpmrc(process.cwd(), registryUrl);
340
- if (options.userNpmrc && stored.registry?.token)
341
- writeUserNpmrc(registryUrl, stored.registry.token);
342
- output(options, { ok: true, registry: registrySummary(stored.registry) }, "Raybase Pro registry configuration is ready.");
332
+ const npmrc = writeRegistryNpmrcFiles(options, registryUrl, stored.registry?.token, "raybase pro registry login");
333
+ output(options, { ok: true, registry: registrySummary(stored.registry), ...npmrc.data }, ["Raybase Pro registry configuration is ready.", ...npmrc.text].join("\n"));
343
334
  });
344
335
  for (const [name, description] of [
345
336
  ["upgrade", "Migrate a Raybase core project to the installed Pro package."],
@@ -1559,6 +1550,8 @@ program
1559
1550
  const ai = await projectAiSummary(projectRoot, profile);
1560
1551
  const localAiMode = resolveLocalAiMode(projectRoot, ai.enabled, options.ai);
1561
1552
  await preflightRaybaseDev(projectRoot, profile, ai, localAiMode);
1553
+ for (const issue of devToolsGuardIssues(projectRoot, profile))
1554
+ console.warn(`Warning: ${issue.message} ${issue.fix}`);
1562
1555
  const devManifest = await writeRaybaseAppManifest(projectRoot, profile);
1563
1556
  if (!devManifest.ok)
1564
1557
  throw new Error(`Unable to prepare ${raybaseAppManifestFile}: ${devManifest.error}`);
@@ -1795,6 +1788,15 @@ async function hostingSecrets(cwd, profile, summary) {
1795
1788
  declared
1796
1789
  });
1797
1790
  }
1791
+ /** The names raybase.requirements.json lists; empty when the app's config cannot be read, which doctor then reports. */
1792
+ async function hostSuppliedSecretNames(cwd, profile, summary) {
1793
+ try {
1794
+ return new Set((await hostingSecrets(cwd, profile, summary)).map((secret) => secret.name));
1795
+ }
1796
+ catch {
1797
+ return new Set();
1798
+ }
1799
+ }
1798
1800
  program
1799
1801
  .command("build")
1800
1802
  .description("Build the app for any host: the framework build, then the secrets it needs declared in the built Wrangler config and raybase.requirements.json beside it. Signs in to nothing and changes nothing on Cloudflare.")
@@ -1805,13 +1807,18 @@ program
1805
1807
  const summary = await loadSchema(cwd, profile);
1806
1808
  const webAdminPanelEnabled = adminPanelEnabled(summary);
1807
1809
  syncRaybaseAdminAssets(cwd, webAdminPanelEnabled);
1808
- const issues = await doctor(cwd, { skipMigrationSync: true }, profile);
1810
+ // The build signs in to nothing and holds no secrets: the host supplies the
1811
+ // ones raybase.requirements.json lists when it uploads. A fresh clone has
1812
+ // none of them on disk, so their local checks are notes here, not errors.
1813
+ const issues = await doctor(cwd, { skipMigrationSync: true, hostSuppliedSecrets: await hostSuppliedSecretNames(cwd, profile, summary) }, profile);
1809
1814
  const blocking = issues.filter((issue) => issue.level === "error" && issue.check !== "migration-sync");
1810
1815
  if (blocking.length) {
1811
1816
  printDoctor(blocking);
1812
1817
  process.exit(1);
1813
1818
  }
1814
- await runPackageScript(cwd, "build");
1819
+ const json = Boolean(options.json || program.opts().json);
1820
+ // With --json the requirements are the only thing on stdout.
1821
+ await runPackageScript(cwd, "build", {}, { stdoutToStderr: json });
1815
1822
  const builtAdminAssets = verifyBuiltRaybaseAdminAssets(cwd, profile, webAdminPanelEnabled);
1816
1823
  if (!builtAdminAssets.ok) {
1817
1824
  printDoctor(adminAssetIssuesToDoctor(builtAdminAssets.issues));
@@ -1830,7 +1837,7 @@ program
1830
1837
  generatedBy: `@raybase/cli ${CLI_VERSION}`
1831
1838
  });
1832
1839
  const file = writeBuildRequirements(built, requirements);
1833
- if (options.json || program.opts().json) {
1840
+ if (json) {
1834
1841
  console.log(JSON.stringify({ ...requirements, requirementsFile: relative(cwd, file) }, null, 2));
1835
1842
  return;
1836
1843
  }
@@ -1852,16 +1859,16 @@ secretsCommand
1852
1859
  return;
1853
1860
  }
1854
1861
  for (const secret of secrets)
1855
- console.log(`${secret.name}${secret.required ? "" : " (optional)"}: ${secret.purpose} Form: ${secret.form}.`);
1862
+ console.log(`${secret.name}${secret.required ? "" : " (optional)"}: ${secret.purpose} Form: ${secret.form} (kind ${secret.kind}).`);
1856
1863
  });
1857
1864
  secretsCommand
1858
1865
  .command("new")
1859
- .description("Print a fresh value for each required secret Raybase can make, as JSON for wrangler deploy --secrets-file. Writes no file and changes nothing.")
1866
+ .description("Print a fresh value for each required secret whose kind Raybase can make (random-32, ec-p256-jwk), as JSON for wrangler deploy --secrets-file. Writes no file and changes nothing.")
1860
1867
  .action(async () => {
1861
1868
  const cwd = process.cwd();
1862
1869
  const profile = resolveFrameworkProfile(cwd);
1863
1870
  const secrets = await hostingSecrets(cwd, profile, await loadSchema(cwd, profile));
1864
- console.log(JSON.stringify(freshSecretValues(secrets, generateHandoffPrivateJwk), null, 2));
1871
+ console.log(JSON.stringify(freshSecretValues(secrets), null, 2));
1865
1872
  });
1866
1873
  program
1867
1874
  .command("deploy")
@@ -3028,7 +3035,7 @@ export function emailCapabilityDoctor(cwd, summary) {
3028
3035
  * register a resource for the CMS or for anything behind a pass, so these
3029
3036
  * checks run for every framework.
3030
3037
  */
3031
- function handoffDoctor(cwd, summary, profile) {
3038
+ function handoffDoctor(cwd, summary, profile, options = {}) {
3032
3039
  const issues = [];
3033
3040
  const handoff = summary.config.handoff;
3034
3041
  const resources = Array.isArray(handoff?.resources) ? handoff.resources : [];
@@ -3060,7 +3067,7 @@ function handoffDoctor(cwd, summary, profile) {
3060
3067
  }
3061
3068
  }
3062
3069
  if (handoff?.enabled === true && !readDevVars(cwd).RAYBASE_HANDOFF_PRIVATE_JWK) {
3063
- issues.push({
3070
+ issues.push(suppliedByHost(options, ["RAYBASE_HANDOFF_PRIVATE_JWK"]) ? hostSuppliedSecretIssue("handoff-key", ["RAYBASE_HANDOFF_PRIVATE_JWK"]) : {
3064
3071
  level: "error",
3065
3072
  check: "handoff-key",
3066
3073
  message: ".dev.vars is missing RAYBASE_HANDOFF_PRIVATE_JWK.",
@@ -3809,6 +3816,53 @@ export function devRestartGuardIssues(cwd, summary) {
3809
3816
  fix: "Import raybaseDevRestartGuard from \"@raybase/core/vite\" and add it last in the plugins array."
3810
3817
  }];
3811
3818
  }
3819
+ /**
3820
+ * A dev server whose own tools answer requests a tunnel brings in.
3821
+ *
3822
+ * Cloudflare's Vite plugin serves `/__debug` and the local explorer under
3823
+ * `/cdn-cgi/` (it reads and writes the app's local storage and runs SQL on
3824
+ * its Durable Objects) to whoever reaches the dev server's port, and a tunnel
3825
+ * makes that port reachable from anywhere. `raybaseDevToolsGuard()` answers
3826
+ * them only to requests from this machine. Each Vite config the dev server
3827
+ * runs needs it: the spine's `vite.config.ts`, and an Astro/EmDash content
3828
+ * site's `astro.config.mjs`.
3829
+ */
3830
+ export function devToolsGuardIssues(cwd, profile) {
3831
+ const configs = ["vite.config.ts"];
3832
+ if (profile?.contentSite) {
3833
+ const site = profile.contentSite.directory;
3834
+ configs.push(existsSync(join(cwd, site, "astro.config.ts")) ? `${site}/astro.config.ts` : `${site}/astro.config.mjs`);
3835
+ }
3836
+ const unguarded = configs.filter((file) => {
3837
+ try {
3838
+ return !readFileSync(join(cwd, file), "utf8").includes("raybaseDevToolsGuard(");
3839
+ }
3840
+ catch {
3841
+ return false;
3842
+ }
3843
+ });
3844
+ return unguarded.map((file) => ({
3845
+ level: "warning",
3846
+ check: "dev-tools-guard",
3847
+ message: `${file} does not use raybaseDevToolsGuard(), so under raybase dev its dev server answers /__debug and Cloudflare's local explorer (/cdn-cgi/, which reads the app's local data) to requests a tunnel or proxy brings in from other machines.`,
3848
+ fix: file.endsWith("vite.config.ts")
3849
+ ? "Import raybaseDevToolsGuard from \"@raybase/core/vite\" and add raybaseDevToolsGuard() to the plugins array."
3850
+ : "Import raybaseDevToolsGuard from \"@raybase/core/vite\" and add raybaseDevToolsGuard() to vite.plugins."
3851
+ }));
3852
+ }
3853
+ /** A local secret the host supplies at upload: noted under raybase build, not refused. */
3854
+ function hostSuppliedSecretIssue(check, names) {
3855
+ const one = names.length === 1;
3856
+ return {
3857
+ level: "info",
3858
+ check,
3859
+ message: `${names.join(" and ")} ${one ? "is" : "are"} not on this machine. raybase build leaves ${one ? "it" : "them"} to the host, which supplies ${one ? "it" : "them"} at upload, as raybase.requirements.json lists.`,
3860
+ fix: `Nothing to do for the build. raybase doctor and raybase deploy, which runs on this machine's secrets, still ask for ${one ? "it" : "them"} here.`
3861
+ };
3862
+ }
3863
+ function suppliedByHost(options, names) {
3864
+ return Boolean(options.hostSuppliedSecrets) && names.every((name) => options.hostSuppliedSecrets.has(name));
3865
+ }
3812
3866
  async function doctor(cwd, options = {}, resolvedProfile) {
3813
3867
  const issues = [];
3814
3868
  if (!existsSync(join(cwd, "package.json"))) {
@@ -3855,6 +3909,7 @@ async function doctor(cwd, options = {}, resolvedProfile) {
3855
3909
  }
3856
3910
  issues.push(...adminAssetRouteConflictIssues(cwd, profile));
3857
3911
  issues.push(...devRestartGuardIssues(cwd, summary));
3912
+ issues.push(...devToolsGuardIssues(cwd, profile));
3858
3913
  if (profile.kind === "astro-emdash")
3859
3914
  issues.push(...paletteContrastIssues(cwd));
3860
3915
  const manifestRefresh = await writeRaybaseAppManifest(cwd, profile);
@@ -3906,7 +3961,7 @@ async function doctor(cwd, options = {}, resolvedProfile) {
3906
3961
  issues.push(...emailCapabilityDoctor(cwd, summary));
3907
3962
  issues.push(...authInviteRuntimeDoctor(cwd, profile));
3908
3963
  issues.push(...authSignInLinksDoctor(cwd, summary, profile));
3909
- issues.push(...handoffDoctor(cwd, summary, profile));
3964
+ issues.push(...handoffDoctor(cwd, summary, profile, options));
3910
3965
  issues.push(...contentSiteDoctor(cwd, summary, profile));
3911
3966
  issues.push(...localDevOperatorPersonaIssues(summary, profile));
3912
3967
  const reservedAppRole = summary.config.roles?.find((role) => ["owner", "admin", "operator"].includes(String(role).toLowerCase()));
@@ -4007,7 +4062,7 @@ async function doctor(cwd, options = {}, resolvedProfile) {
4007
4062
  issues.push(...aiDoctor(cwd, summary, profile, appManifest));
4008
4063
  issues.push(...guideDoctor(cwd, summary, profile, packageDocsEnabled(cwd)));
4009
4064
  issues.push(...searchDoctor(cwd, summary, profile, appManifest));
4010
- issues.push(...notificationsDoctor(cwd, summary, profile, appManifest));
4065
+ issues.push(...notificationsDoctor(cwd, summary, profile, appManifest, options));
4011
4066
  issues.push(...emailDoctor(cwd, summary));
4012
4067
  if (summary.config.realtime?.enabled === true) {
4013
4068
  const realtime = summary.config.realtime;
@@ -4459,7 +4514,7 @@ async function doctor(cwd, options = {}, resolvedProfile) {
4459
4514
  try {
4460
4515
  const localBackupKeys = configuredBackupSecrets(cwd);
4461
4516
  if (backups.enabled && !localBackupKeys.secret) {
4462
- issues.push({
4517
+ issues.push(suppliedByHost(options, ["RAYBASE_BACKUPS_KEY"]) ? hostSuppliedSecretIssue("backups-key", ["RAYBASE_BACKUPS_KEY"]) : {
4463
4518
  level: "error",
4464
4519
  check: "backups-key",
4465
4520
  message: "Encrypted backups are enabled but the managed current backup key is missing locally.",
@@ -4567,7 +4622,7 @@ async function doctor(cwd, options = {}, resolvedProfile) {
4567
4622
  }
4568
4623
  issues.push(...starterDoctor(cwd, CLI_VERSION, profile.kind));
4569
4624
  issues.push(...templatePatternTestsDoctor(cwd, profile, appManifest, summary));
4570
- pushUniqueDoctorIssues(issues, doctorInstalledModules(cwd, { profile, summary, appManifest, suppressAppManifestIssue: !manifestRefresh.ok }).issues);
4625
+ pushUniqueDoctorIssues(issues, doctorInstalledModules(cwd, { profile, summary, appManifest, suppressAppManifestIssue: !manifestRefresh.ok, hostSuppliedSecrets: options.hostSuppliedSecrets }).issues);
4571
4626
  issues.push(...doctorKits(cwd, { framework: profile.kind, cliVersion: CLI_VERSION, proVersion: proDeclaredVersion(cwd) }).issues);
4572
4627
  issues.push(...doctorInstalledTemplates(cwd, { framework: profile.kind === "astro-emdash" ? "astro-emdash" : undefined }).issues);
4573
4628
  issues.push(...skillsFreshnessDoctor(cwd));
@@ -5883,7 +5938,7 @@ function hasWebPushPrivateKeyRuntimePlacement(cwd, profile) {
5883
5938
  return false;
5884
5939
  }
5885
5940
  }
5886
- function notificationsDoctor(cwd, summary, profile, appManifest) {
5941
+ function notificationsDoctor(cwd, summary, profile, appManifest, options = {}) {
5887
5942
  const issues = [];
5888
5943
  const cfg = summary.config.notifications;
5889
5944
  const webPushEnabled = cfg?.webpush?.enabled === true;
@@ -5928,8 +5983,9 @@ function notificationsDoctor(cwd, summary, profile, appManifest) {
5928
5983
  });
5929
5984
  }
5930
5985
  const devVars = readDevVars(cwd);
5931
- if (!devVars.RAYBASE_VAPID_PUBLIC_KEY || !devVars.RAYBASE_VAPID_PRIVATE_KEY) {
5932
- issues.push({
5986
+ const missingVapidKeys = ["RAYBASE_VAPID_PUBLIC_KEY", "RAYBASE_VAPID_PRIVATE_KEY"].filter((name) => !devVars[name]);
5987
+ if (missingVapidKeys.length) {
5988
+ issues.push(suppliedByHost(options, missingVapidKeys) ? hostSuppliedSecretIssue("webpush-keys", missingVapidKeys) : {
5933
5989
  level: "error",
5934
5990
  check: "webpush-keys",
5935
5991
  message: ".dev.vars is missing one or both Web Push VAPID keys.",
@@ -8036,7 +8092,7 @@ function rotateBackupKey(cwd) {
8036
8092
  const configured = configuredBackupSecrets(cwd);
8037
8093
  if (!configured.secret)
8038
8094
  throw new Error("No managed backup key exists. Run raybase backups enable first.");
8039
- const secret = randomBytes(32).toString("base64url");
8095
+ const secret = generateRandom32Secret();
8040
8096
  const retainedSecrets = [configured.secret, ...configured.retainedSecrets.filter((candidate) => candidate !== configured.secret)];
8041
8097
  persistBackupSecrets(cwd, secret, retainedSecrets);
8042
8098
  return {
@@ -8093,7 +8149,7 @@ function enableDataSecrets(cwd, options) {
8093
8149
  if (!configured.secret && options.refuseDeployedKey && deployedWorkerSecretNames(cwd)?.includes(dataSecretsKeyName)) {
8094
8150
  throw new Error(`${dataSecretsKeyName} is already set on the deployed Worker and this machine has no copy of it. Put the existing key in .raybase/${dataSecretsKeyFileName} and re-run instead of replacing it; values sealed with the deployed key would become unreadable.`);
8095
8151
  }
8096
- const secret = configured.secret ?? randomBytes(32).toString("base64url");
8152
+ const secret = configured.secret ?? generateRandom32Secret();
8097
8153
  const declared = persistDataSecretsKeys(cwd, secret, configured.retainedSecrets);
8098
8154
  return {
8099
8155
  ok: true,
@@ -8112,7 +8168,7 @@ function rotateDataSecretsKey(cwd) {
8112
8168
  const configured = configuredDataSecretsKeys(cwd);
8113
8169
  if (!configured.secret)
8114
8170
  throw new Error("No secret() column key exists. Run raybase data-secrets enable first.");
8115
- const secret = randomBytes(32).toString("base64url");
8171
+ const secret = generateRandom32Secret();
8116
8172
  const retainedSecrets = [configured.secret, ...configured.retainedSecrets.filter((candidate) => candidate !== configured.secret)];
8117
8173
  const declared = persistDataSecretsKeys(cwd, secret, retainedSecrets);
8118
8174
  return {
@@ -8223,7 +8279,7 @@ function enableBackups(cwd, options) {
8223
8279
  editWranglerConfig(cwd, ["vars", "RAYBASE_BACKUPS_ENABLED"], "true");
8224
8280
  editWranglerConfig(cwd, ["vars", "RAYBASE_BACKUPS_RETAIN"], String(retain));
8225
8281
  const configured = configuredBackupSecrets(cwd);
8226
- const secret = configured.secret ?? randomBytes(32).toString("base64url");
8282
+ const secret = configured.secret ?? generateRandom32Secret();
8227
8283
  persistBackupSecrets(cwd, secret, configured.retainedSecrets);
8228
8284
  return {
8229
8285
  ok: true,
@@ -9293,7 +9349,7 @@ function ensureAuthSecret(cwd) {
9293
9349
  writeFileSync(file, `${value}\n`, { mode: 0o600 });
9294
9350
  return value;
9295
9351
  }
9296
- const value = randomBytes(32).toString("base64url");
9352
+ const value = generateRandom32Secret();
9297
9353
  writeFileSync(file, `${value}\n`, { mode: 0o600 });
9298
9354
  return value;
9299
9355
  }
@@ -9532,21 +9588,13 @@ function inferWorkersUrl(cwd) {
9532
9588
  function inferWorkersUrlFromDeployOutput(output) {
9533
9589
  return output.match(/https:\/\/[a-z0-9-]+(?:\.[a-z0-9-]+)*\.workers\.dev\b/i)?.[0] ?? null;
9534
9590
  }
9535
- function generateHandoffPrivateJwk() {
9536
- const { privateKey } = generateKeyPairSync("ec", { namedCurve: "P-256" });
9537
- const jwk = privateKey.export({ format: "jwk" });
9538
- jwk.alg = "ES256";
9539
- jwk.use = "sig";
9540
- jwk.kid = `raybase-handoff-${createHash("sha256").update(JSON.stringify({ crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y })).digest("hex").slice(0, 16)}`;
9541
- return JSON.stringify(jwk);
9542
- }
9543
9591
  function ensureHandoffPrivateJwk(cwd) {
9544
9592
  const dir = join(cwd, ".raybase");
9545
9593
  const file = join(dir, "handoff-private-jwk");
9546
9594
  if (existsSync(file))
9547
9595
  return readFileSync(file, "utf8").trim();
9548
9596
  const existing = readDevVars(cwd).RAYBASE_HANDOFF_PRIVATE_JWK;
9549
- const value = existing || generateHandoffPrivateJwk();
9597
+ const value = existing || generateEcP256PrivateJwk();
9550
9598
  mkdirSync(dir, { recursive: true });
9551
9599
  writeFileSync(file, `${value}\n`, { mode: 0o600 });
9552
9600
  return value;
@@ -9957,6 +10005,56 @@ function licenseSummary(status) {
9957
10005
  source: status.source
9958
10006
  };
9959
10007
  }
10008
+ /**
10009
+ * The registry lines account use, pro activate, pro refresh and pro registry
10010
+ * login write: the project's .npmrc unless --no-project-npmrc, ~/.npmrc with
10011
+ * --user-npmrc. Each says what it did, so nothing changes in silence.
10012
+ */
10013
+ function writeRegistryNpmrcFiles(options, registryUrl, registryToken, command) {
10014
+ const writeOptions = { replaceOtherRegistry: Boolean(options.replaceOtherRegistry) };
10015
+ const projectNpmrc = options.projectNpmrc === false
10016
+ ? { outcome: "skipped", reason: "--no-project-npmrc" }
10017
+ : registryUrl
10018
+ ? writeProjectNpmrc(process.cwd(), registryUrl, writeOptions)
10019
+ : { outcome: "skipped", reason: "the licensing service named no registry" };
10020
+ const data = { projectNpmrc };
10021
+ const text = [formatNpmrcResult("Project .npmrc", projectNpmrc, command)];
10022
+ if (options.userNpmrc) {
10023
+ const userNpmrc = !registryUrl
10024
+ ? { outcome: "skipped", reason: "the licensing service named no registry" }
10025
+ : !registryToken
10026
+ ? { outcome: "skipped", reason: "no registry token is stored on this machine" }
10027
+ : writeUserNpmrc(registryUrl, registryToken, writeOptions);
10028
+ data.userNpmrc = userNpmrc;
10029
+ text.push(formatNpmrcResult("~/.npmrc", userNpmrc, `${command} --user-npmrc`));
10030
+ }
10031
+ return { data, text };
10032
+ }
10033
+ function formatNpmrcResult(label, result, command) {
10034
+ if (result.outcome === "skipped")
10035
+ return `${label}: not touched (${result.reason}).`;
10036
+ const scopeNames = (scopes) => scopes.map((scope) => scope.scope).join(" and ");
10037
+ const byAction = (action) => result.scopes.filter((scope) => scope.action === action);
10038
+ const written = [...byAction("added"), ...byAction("replaced")];
10039
+ const kept = byAction("kept");
10040
+ const leftAlone = byAction("left-alone");
10041
+ const parts = [];
10042
+ if (written.length) {
10043
+ parts.push(`${scopeNames(written)} now from ${result.registryUrl}${byAction("replaced").map((scope) => ` (${scope.scope} was ${scope.before})`).join("")}`);
10044
+ }
10045
+ if (kept.length)
10046
+ parts.push(`${scopeNames(kept)} already from ${result.registryUrl}`);
10047
+ if (result.tokenLine === "added" || result.tokenLine === "updated") {
10048
+ parts.push(label === "Project .npmrc" ? "the registry token read from RAYBASE_REGISTRY_TOKEN at install" : "the registry token written");
10049
+ }
10050
+ const verb = result.outcome === "created" ? "written" : result.outcome === "updated" ? "updated" : leftAlone.length && !kept.length ? "left alone" : "unchanged";
10051
+ let line = `${label} ${verb} (${result.file})${parts.length ? `: ${parts.join("; ")}` : ""}.`;
10052
+ if (leftAlone.length) {
10053
+ const registries = [...new Set(leftAlone.map((scope) => scope.before))].join(", ");
10054
+ line += ` ${scopeNames(leftAlone)} ${leftAlone.length === 1 ? "points" : "point"} at ${registries}, not Raybase's registry ${result.registryUrl}, so ${leftAlone.length === 1 ? "it was" : "they were"} left as ${leftAlone.length === 1 ? "it is" : "they are"}. To point ${leftAlone.length === 1 ? "it" : "them"} at Raybase's registry, run ${command} --replace-other-registry.`;
10055
+ }
10056
+ return line;
10057
+ }
9960
10058
  function registrySummary(registry) {
9961
10059
  return {
9962
10060
  configured: Boolean(registry?.registryUrl),
@@ -11452,9 +11550,9 @@ async function runToolWithOutput(cwd, args, env = {}) {
11452
11550
  const command = execCommand(cwd, args);
11453
11551
  return runWithOutput(command.command, command.args, cwd, env);
11454
11552
  }
11455
- async function runPackageScript(cwd, script, env = {}) {
11553
+ async function runPackageScript(cwd, script, env = {}, options = {}) {
11456
11554
  const command = runScriptCommand(cwd, script);
11457
- await run(command.command, command.args, cwd, env);
11555
+ await run(command.command, command.args, cwd, env, options);
11458
11556
  }
11459
11557
  function spawnToolSync(cwd, args, options = {}) {
11460
11558
  const command = execCommand(cwd, args);