@raybase/cli 0.3.4 → 0.3.6

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.4";
56
+ const CLI_VERSION = "0.3.6";
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."],
@@ -1795,6 +1786,15 @@ async function hostingSecrets(cwd, profile, summary) {
1795
1786
  declared
1796
1787
  });
1797
1788
  }
1789
+ /** The names raybase.requirements.json lists; empty when the app's config cannot be read, which doctor then reports. */
1790
+ async function hostSuppliedSecretNames(cwd, profile, summary) {
1791
+ try {
1792
+ return new Set((await hostingSecrets(cwd, profile, summary)).map((secret) => secret.name));
1793
+ }
1794
+ catch {
1795
+ return new Set();
1796
+ }
1797
+ }
1798
1798
  program
1799
1799
  .command("build")
1800
1800
  .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 +1805,18 @@ program
1805
1805
  const summary = await loadSchema(cwd, profile);
1806
1806
  const webAdminPanelEnabled = adminPanelEnabled(summary);
1807
1807
  syncRaybaseAdminAssets(cwd, webAdminPanelEnabled);
1808
- const issues = await doctor(cwd, { skipMigrationSync: true }, profile);
1808
+ // The build signs in to nothing and holds no secrets: the host supplies the
1809
+ // ones raybase.requirements.json lists when it uploads. A fresh clone has
1810
+ // none of them on disk, so their local checks are notes here, not errors.
1811
+ const issues = await doctor(cwd, { skipMigrationSync: true, hostSuppliedSecrets: await hostSuppliedSecretNames(cwd, profile, summary) }, profile);
1809
1812
  const blocking = issues.filter((issue) => issue.level === "error" && issue.check !== "migration-sync");
1810
1813
  if (blocking.length) {
1811
1814
  printDoctor(blocking);
1812
1815
  process.exit(1);
1813
1816
  }
1814
- await runPackageScript(cwd, "build");
1817
+ const json = Boolean(options.json || program.opts().json);
1818
+ // With --json the requirements are the only thing on stdout.
1819
+ await runPackageScript(cwd, "build", {}, { stdoutToStderr: json });
1815
1820
  const builtAdminAssets = verifyBuiltRaybaseAdminAssets(cwd, profile, webAdminPanelEnabled);
1816
1821
  if (!builtAdminAssets.ok) {
1817
1822
  printDoctor(adminAssetIssuesToDoctor(builtAdminAssets.issues));
@@ -1830,7 +1835,7 @@ program
1830
1835
  generatedBy: `@raybase/cli ${CLI_VERSION}`
1831
1836
  });
1832
1837
  const file = writeBuildRequirements(built, requirements);
1833
- if (options.json || program.opts().json) {
1838
+ if (json) {
1834
1839
  console.log(JSON.stringify({ ...requirements, requirementsFile: relative(cwd, file) }, null, 2));
1835
1840
  return;
1836
1841
  }
@@ -1852,16 +1857,16 @@ secretsCommand
1852
1857
  return;
1853
1858
  }
1854
1859
  for (const secret of secrets)
1855
- console.log(`${secret.name}${secret.required ? "" : " (optional)"}: ${secret.purpose} Form: ${secret.form}.`);
1860
+ console.log(`${secret.name}${secret.required ? "" : " (optional)"}: ${secret.purpose} Form: ${secret.form} (kind ${secret.kind}).`);
1856
1861
  });
1857
1862
  secretsCommand
1858
1863
  .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.")
1864
+ .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
1865
  .action(async () => {
1861
1866
  const cwd = process.cwd();
1862
1867
  const profile = resolveFrameworkProfile(cwd);
1863
1868
  const secrets = await hostingSecrets(cwd, profile, await loadSchema(cwd, profile));
1864
- console.log(JSON.stringify(freshSecretValues(secrets, generateHandoffPrivateJwk), null, 2));
1869
+ console.log(JSON.stringify(freshSecretValues(secrets), null, 2));
1865
1870
  });
1866
1871
  program
1867
1872
  .command("deploy")
@@ -3028,7 +3033,7 @@ export function emailCapabilityDoctor(cwd, summary) {
3028
3033
  * register a resource for the CMS or for anything behind a pass, so these
3029
3034
  * checks run for every framework.
3030
3035
  */
3031
- function handoffDoctor(cwd, summary, profile) {
3036
+ function handoffDoctor(cwd, summary, profile, options = {}) {
3032
3037
  const issues = [];
3033
3038
  const handoff = summary.config.handoff;
3034
3039
  const resources = Array.isArray(handoff?.resources) ? handoff.resources : [];
@@ -3060,7 +3065,7 @@ function handoffDoctor(cwd, summary, profile) {
3060
3065
  }
3061
3066
  }
3062
3067
  if (handoff?.enabled === true && !readDevVars(cwd).RAYBASE_HANDOFF_PRIVATE_JWK) {
3063
- issues.push({
3068
+ issues.push(suppliedByHost(options, ["RAYBASE_HANDOFF_PRIVATE_JWK"]) ? hostSuppliedSecretIssue("handoff-key", ["RAYBASE_HANDOFF_PRIVATE_JWK"]) : {
3064
3069
  level: "error",
3065
3070
  check: "handoff-key",
3066
3071
  message: ".dev.vars is missing RAYBASE_HANDOFF_PRIVATE_JWK.",
@@ -3809,6 +3814,19 @@ export function devRestartGuardIssues(cwd, summary) {
3809
3814
  fix: "Import raybaseDevRestartGuard from \"@raybase/core/vite\" and add it last in the plugins array."
3810
3815
  }];
3811
3816
  }
3817
+ /** A local secret the host supplies at upload: noted under raybase build, not refused. */
3818
+ function hostSuppliedSecretIssue(check, names) {
3819
+ const one = names.length === 1;
3820
+ return {
3821
+ level: "info",
3822
+ check,
3823
+ 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.`,
3824
+ 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.`
3825
+ };
3826
+ }
3827
+ function suppliedByHost(options, names) {
3828
+ return Boolean(options.hostSuppliedSecrets) && names.every((name) => options.hostSuppliedSecrets.has(name));
3829
+ }
3812
3830
  async function doctor(cwd, options = {}, resolvedProfile) {
3813
3831
  const issues = [];
3814
3832
  if (!existsSync(join(cwd, "package.json"))) {
@@ -3906,7 +3924,7 @@ async function doctor(cwd, options = {}, resolvedProfile) {
3906
3924
  issues.push(...emailCapabilityDoctor(cwd, summary));
3907
3925
  issues.push(...authInviteRuntimeDoctor(cwd, profile));
3908
3926
  issues.push(...authSignInLinksDoctor(cwd, summary, profile));
3909
- issues.push(...handoffDoctor(cwd, summary, profile));
3927
+ issues.push(...handoffDoctor(cwd, summary, profile, options));
3910
3928
  issues.push(...contentSiteDoctor(cwd, summary, profile));
3911
3929
  issues.push(...localDevOperatorPersonaIssues(summary, profile));
3912
3930
  const reservedAppRole = summary.config.roles?.find((role) => ["owner", "admin", "operator"].includes(String(role).toLowerCase()));
@@ -4007,7 +4025,7 @@ async function doctor(cwd, options = {}, resolvedProfile) {
4007
4025
  issues.push(...aiDoctor(cwd, summary, profile, appManifest));
4008
4026
  issues.push(...guideDoctor(cwd, summary, profile, packageDocsEnabled(cwd)));
4009
4027
  issues.push(...searchDoctor(cwd, summary, profile, appManifest));
4010
- issues.push(...notificationsDoctor(cwd, summary, profile, appManifest));
4028
+ issues.push(...notificationsDoctor(cwd, summary, profile, appManifest, options));
4011
4029
  issues.push(...emailDoctor(cwd, summary));
4012
4030
  if (summary.config.realtime?.enabled === true) {
4013
4031
  const realtime = summary.config.realtime;
@@ -4459,7 +4477,7 @@ async function doctor(cwd, options = {}, resolvedProfile) {
4459
4477
  try {
4460
4478
  const localBackupKeys = configuredBackupSecrets(cwd);
4461
4479
  if (backups.enabled && !localBackupKeys.secret) {
4462
- issues.push({
4480
+ issues.push(suppliedByHost(options, ["RAYBASE_BACKUPS_KEY"]) ? hostSuppliedSecretIssue("backups-key", ["RAYBASE_BACKUPS_KEY"]) : {
4463
4481
  level: "error",
4464
4482
  check: "backups-key",
4465
4483
  message: "Encrypted backups are enabled but the managed current backup key is missing locally.",
@@ -4567,7 +4585,7 @@ async function doctor(cwd, options = {}, resolvedProfile) {
4567
4585
  }
4568
4586
  issues.push(...starterDoctor(cwd, CLI_VERSION, profile.kind));
4569
4587
  issues.push(...templatePatternTestsDoctor(cwd, profile, appManifest, summary));
4570
- pushUniqueDoctorIssues(issues, doctorInstalledModules(cwd, { profile, summary, appManifest, suppressAppManifestIssue: !manifestRefresh.ok }).issues);
4588
+ pushUniqueDoctorIssues(issues, doctorInstalledModules(cwd, { profile, summary, appManifest, suppressAppManifestIssue: !manifestRefresh.ok, hostSuppliedSecrets: options.hostSuppliedSecrets }).issues);
4571
4589
  issues.push(...doctorKits(cwd, { framework: profile.kind, cliVersion: CLI_VERSION, proVersion: proDeclaredVersion(cwd) }).issues);
4572
4590
  issues.push(...doctorInstalledTemplates(cwd, { framework: profile.kind === "astro-emdash" ? "astro-emdash" : undefined }).issues);
4573
4591
  issues.push(...skillsFreshnessDoctor(cwd));
@@ -5883,7 +5901,7 @@ function hasWebPushPrivateKeyRuntimePlacement(cwd, profile) {
5883
5901
  return false;
5884
5902
  }
5885
5903
  }
5886
- function notificationsDoctor(cwd, summary, profile, appManifest) {
5904
+ function notificationsDoctor(cwd, summary, profile, appManifest, options = {}) {
5887
5905
  const issues = [];
5888
5906
  const cfg = summary.config.notifications;
5889
5907
  const webPushEnabled = cfg?.webpush?.enabled === true;
@@ -5928,8 +5946,9 @@ function notificationsDoctor(cwd, summary, profile, appManifest) {
5928
5946
  });
5929
5947
  }
5930
5948
  const devVars = readDevVars(cwd);
5931
- if (!devVars.RAYBASE_VAPID_PUBLIC_KEY || !devVars.RAYBASE_VAPID_PRIVATE_KEY) {
5932
- issues.push({
5949
+ const missingVapidKeys = ["RAYBASE_VAPID_PUBLIC_KEY", "RAYBASE_VAPID_PRIVATE_KEY"].filter((name) => !devVars[name]);
5950
+ if (missingVapidKeys.length) {
5951
+ issues.push(suppliedByHost(options, missingVapidKeys) ? hostSuppliedSecretIssue("webpush-keys", missingVapidKeys) : {
5933
5952
  level: "error",
5934
5953
  check: "webpush-keys",
5935
5954
  message: ".dev.vars is missing one or both Web Push VAPID keys.",
@@ -8036,7 +8055,7 @@ function rotateBackupKey(cwd) {
8036
8055
  const configured = configuredBackupSecrets(cwd);
8037
8056
  if (!configured.secret)
8038
8057
  throw new Error("No managed backup key exists. Run raybase backups enable first.");
8039
- const secret = randomBytes(32).toString("base64url");
8058
+ const secret = generateRandom32Secret();
8040
8059
  const retainedSecrets = [configured.secret, ...configured.retainedSecrets.filter((candidate) => candidate !== configured.secret)];
8041
8060
  persistBackupSecrets(cwd, secret, retainedSecrets);
8042
8061
  return {
@@ -8093,7 +8112,7 @@ function enableDataSecrets(cwd, options) {
8093
8112
  if (!configured.secret && options.refuseDeployedKey && deployedWorkerSecretNames(cwd)?.includes(dataSecretsKeyName)) {
8094
8113
  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
8114
  }
8096
- const secret = configured.secret ?? randomBytes(32).toString("base64url");
8115
+ const secret = configured.secret ?? generateRandom32Secret();
8097
8116
  const declared = persistDataSecretsKeys(cwd, secret, configured.retainedSecrets);
8098
8117
  return {
8099
8118
  ok: true,
@@ -8112,7 +8131,7 @@ function rotateDataSecretsKey(cwd) {
8112
8131
  const configured = configuredDataSecretsKeys(cwd);
8113
8132
  if (!configured.secret)
8114
8133
  throw new Error("No secret() column key exists. Run raybase data-secrets enable first.");
8115
- const secret = randomBytes(32).toString("base64url");
8134
+ const secret = generateRandom32Secret();
8116
8135
  const retainedSecrets = [configured.secret, ...configured.retainedSecrets.filter((candidate) => candidate !== configured.secret)];
8117
8136
  const declared = persistDataSecretsKeys(cwd, secret, retainedSecrets);
8118
8137
  return {
@@ -8223,7 +8242,7 @@ function enableBackups(cwd, options) {
8223
8242
  editWranglerConfig(cwd, ["vars", "RAYBASE_BACKUPS_ENABLED"], "true");
8224
8243
  editWranglerConfig(cwd, ["vars", "RAYBASE_BACKUPS_RETAIN"], String(retain));
8225
8244
  const configured = configuredBackupSecrets(cwd);
8226
- const secret = configured.secret ?? randomBytes(32).toString("base64url");
8245
+ const secret = configured.secret ?? generateRandom32Secret();
8227
8246
  persistBackupSecrets(cwd, secret, configured.retainedSecrets);
8228
8247
  return {
8229
8248
  ok: true,
@@ -9293,7 +9312,7 @@ function ensureAuthSecret(cwd) {
9293
9312
  writeFileSync(file, `${value}\n`, { mode: 0o600 });
9294
9313
  return value;
9295
9314
  }
9296
- const value = randomBytes(32).toString("base64url");
9315
+ const value = generateRandom32Secret();
9297
9316
  writeFileSync(file, `${value}\n`, { mode: 0o600 });
9298
9317
  return value;
9299
9318
  }
@@ -9532,21 +9551,13 @@ function inferWorkersUrl(cwd) {
9532
9551
  function inferWorkersUrlFromDeployOutput(output) {
9533
9552
  return output.match(/https:\/\/[a-z0-9-]+(?:\.[a-z0-9-]+)*\.workers\.dev\b/i)?.[0] ?? null;
9534
9553
  }
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
9554
  function ensureHandoffPrivateJwk(cwd) {
9544
9555
  const dir = join(cwd, ".raybase");
9545
9556
  const file = join(dir, "handoff-private-jwk");
9546
9557
  if (existsSync(file))
9547
9558
  return readFileSync(file, "utf8").trim();
9548
9559
  const existing = readDevVars(cwd).RAYBASE_HANDOFF_PRIVATE_JWK;
9549
- const value = existing || generateHandoffPrivateJwk();
9560
+ const value = existing || generateEcP256PrivateJwk();
9550
9561
  mkdirSync(dir, { recursive: true });
9551
9562
  writeFileSync(file, `${value}\n`, { mode: 0o600 });
9552
9563
  return value;
@@ -9957,6 +9968,56 @@ function licenseSummary(status) {
9957
9968
  source: status.source
9958
9969
  };
9959
9970
  }
9971
+ /**
9972
+ * The registry lines account use, pro activate, pro refresh and pro registry
9973
+ * login write: the project's .npmrc unless --no-project-npmrc, ~/.npmrc with
9974
+ * --user-npmrc. Each says what it did, so nothing changes in silence.
9975
+ */
9976
+ function writeRegistryNpmrcFiles(options, registryUrl, registryToken, command) {
9977
+ const writeOptions = { replaceOtherRegistry: Boolean(options.replaceOtherRegistry) };
9978
+ const projectNpmrc = options.projectNpmrc === false
9979
+ ? { outcome: "skipped", reason: "--no-project-npmrc" }
9980
+ : registryUrl
9981
+ ? writeProjectNpmrc(process.cwd(), registryUrl, writeOptions)
9982
+ : { outcome: "skipped", reason: "the licensing service named no registry" };
9983
+ const data = { projectNpmrc };
9984
+ const text = [formatNpmrcResult("Project .npmrc", projectNpmrc, command)];
9985
+ if (options.userNpmrc) {
9986
+ const userNpmrc = !registryUrl
9987
+ ? { outcome: "skipped", reason: "the licensing service named no registry" }
9988
+ : !registryToken
9989
+ ? { outcome: "skipped", reason: "no registry token is stored on this machine" }
9990
+ : writeUserNpmrc(registryUrl, registryToken, writeOptions);
9991
+ data.userNpmrc = userNpmrc;
9992
+ text.push(formatNpmrcResult("~/.npmrc", userNpmrc, `${command} --user-npmrc`));
9993
+ }
9994
+ return { data, text };
9995
+ }
9996
+ function formatNpmrcResult(label, result, command) {
9997
+ if (result.outcome === "skipped")
9998
+ return `${label}: not touched (${result.reason}).`;
9999
+ const scopeNames = (scopes) => scopes.map((scope) => scope.scope).join(" and ");
10000
+ const byAction = (action) => result.scopes.filter((scope) => scope.action === action);
10001
+ const written = [...byAction("added"), ...byAction("replaced")];
10002
+ const kept = byAction("kept");
10003
+ const leftAlone = byAction("left-alone");
10004
+ const parts = [];
10005
+ if (written.length) {
10006
+ parts.push(`${scopeNames(written)} now from ${result.registryUrl}${byAction("replaced").map((scope) => ` (${scope.scope} was ${scope.before})`).join("")}`);
10007
+ }
10008
+ if (kept.length)
10009
+ parts.push(`${scopeNames(kept)} already from ${result.registryUrl}`);
10010
+ if (result.tokenLine === "added" || result.tokenLine === "updated") {
10011
+ parts.push(label === "Project .npmrc" ? "the registry token read from RAYBASE_REGISTRY_TOKEN at install" : "the registry token written");
10012
+ }
10013
+ const verb = result.outcome === "created" ? "written" : result.outcome === "updated" ? "updated" : leftAlone.length && !kept.length ? "left alone" : "unchanged";
10014
+ let line = `${label} ${verb} (${result.file})${parts.length ? `: ${parts.join("; ")}` : ""}.`;
10015
+ if (leftAlone.length) {
10016
+ const registries = [...new Set(leftAlone.map((scope) => scope.before))].join(", ");
10017
+ 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.`;
10018
+ }
10019
+ return line;
10020
+ }
9960
10021
  function registrySummary(registry) {
9961
10022
  return {
9962
10023
  configured: Boolean(registry?.registryUrl),
@@ -11452,9 +11513,9 @@ async function runToolWithOutput(cwd, args, env = {}) {
11452
11513
  const command = execCommand(cwd, args);
11453
11514
  return runWithOutput(command.command, command.args, cwd, env);
11454
11515
  }
11455
- async function runPackageScript(cwd, script, env = {}) {
11516
+ async function runPackageScript(cwd, script, env = {}, options = {}) {
11456
11517
  const command = runScriptCommand(cwd, script);
11457
- await run(command.command, command.args, cwd, env);
11518
+ await run(command.command, command.args, cwd, env, options);
11458
11519
  }
11459
11520
  function spawnToolSync(cwd, args, options = {}) {
11460
11521
  const command = execCommand(cwd, args);