@gadicc/loom 1.24.0 → 1.26.0

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 (43) hide show
  1. package/README.md +18 -4
  2. package/db/databaseTls.js +42 -0
  3. package/db/databaseTls.test.ts +171 -0
  4. package/db/neonFull.js +2 -4
  5. package/esm/_dnt.polyfills.d.ts +11 -0
  6. package/esm/_dnt.polyfills.d.ts.map +1 -1
  7. package/esm/_dnt.polyfills.js +14 -0
  8. package/esm/src/cli/filesR2Policy.d.ts +33 -0
  9. package/esm/src/cli/filesR2Policy.d.ts.map +1 -0
  10. package/esm/src/cli/filesR2Policy.js +130 -0
  11. package/esm/src/cli/mod.d.ts +5 -0
  12. package/esm/src/cli/mod.d.ts.map +1 -1
  13. package/esm/src/cli/mod.js +144 -148
  14. package/esm/src/cli/releaseCredentials.d.ts +32 -0
  15. package/esm/src/cli/releaseCredentials.d.ts.map +1 -0
  16. package/esm/src/cli/releaseCredentials.js +388 -0
  17. package/esm/src/cli/releaseTrust.d.ts +39 -0
  18. package/esm/src/cli/releaseTrust.d.ts.map +1 -0
  19. package/esm/src/cli/releaseTrust.js +125 -0
  20. package/esm/src/cli/releaseTrustCommand.d.ts +18 -0
  21. package/esm/src/cli/releaseTrustCommand.d.ts.map +1 -0
  22. package/esm/src/cli/releaseTrustCommand.js +142 -0
  23. package/package.json +2 -2
  24. package/script/_dnt.polyfills.d.ts +11 -0
  25. package/script/_dnt.polyfills.d.ts.map +1 -1
  26. package/script/_dnt.polyfills.js +14 -0
  27. package/script/src/cli/filesR2Policy.d.ts +33 -0
  28. package/script/src/cli/filesR2Policy.d.ts.map +1 -0
  29. package/script/src/cli/filesR2Policy.js +135 -0
  30. package/script/src/cli/mod.d.ts +5 -0
  31. package/script/src/cli/mod.d.ts.map +1 -1
  32. package/script/src/cli/mod.js +144 -148
  33. package/script/src/cli/releaseCredentials.d.ts +32 -0
  34. package/script/src/cli/releaseCredentials.d.ts.map +1 -0
  35. package/script/src/cli/releaseCredentials.js +392 -0
  36. package/script/src/cli/releaseTrust.d.ts +39 -0
  37. package/script/src/cli/releaseTrust.d.ts.map +1 -0
  38. package/script/src/cli/releaseTrust.js +130 -0
  39. package/script/src/cli/releaseTrustCommand.d.ts +18 -0
  40. package/script/src/cli/releaseTrustCommand.d.ts.map +1 -0
  41. package/script/src/cli/releaseTrustCommand.js +145 -0
  42. package/skills/loom-db/SKILL.md +17 -9
  43. package/skills/loom-files/SKILL.md +12 -1
@@ -77,7 +77,10 @@ const node_module_1 = require("node:module");
77
77
  const node_path_1 = require("node:path");
78
78
  const node_process_1 = __importDefault(require("node:process"));
79
79
  const node_util_1 = require("node:util");
80
+ const filesR2Policy_js_1 = require("./filesR2Policy.js");
80
81
  const releaseConfig_js_1 = require("./releaseConfig.js");
82
+ const releaseCredentials_js_1 = require("./releaseCredentials.js");
83
+ const releaseTrustCommand_js_1 = require("./releaseTrustCommand.js");
81
84
  const retention_js_1 = require("../apiKeys/retention.js");
82
85
  const projectSkills_js_1 = require("./projectSkills.js");
83
86
  const migrationEnv_js_1 = require("./migrationEnv.js");
@@ -6042,6 +6045,11 @@ async function setupCloudflareR2(cwd, options = {}) {
6042
6045
  const dbConfig = mergeDbConfig(framework, dbFeature.config);
6043
6046
  const config = getFilesConfig(framework, dbConfig, feature.config);
6044
6047
  const existingProvider = config.storage.provider;
6048
+ if (existingProvider) {
6049
+ const policyIssues = (0, filesR2Policy_js_1.filesR2PolicyIssues)(existingProvider);
6050
+ if (policyIssues.length)
6051
+ throw new Error(policyIssues.join(" "));
6052
+ }
6045
6053
  const wranglerCommand = await detectWranglerCommand(cwd, commandRunner, env);
6046
6054
  if (!wranglerCommand) {
6047
6055
  throw new Error("Wrangler is not available. On Arch Linux install it with `sudo pacman -S wrangler`, then run `wrangler login`.");
@@ -6163,7 +6171,13 @@ async function setupCloudflareR2(cwd, options = {}) {
6163
6171
  buckets,
6164
6172
  connectionStatus: "buckets-ready",
6165
6173
  credentialMode: "manual",
6166
- directBrowserAccess: false,
6174
+ directBrowserAccess: existingProvider?.directBrowserAccess ?? false,
6175
+ ...(existingProvider?.directUpload
6176
+ ? { directUpload: existingProvider.directUpload }
6177
+ : {}),
6178
+ ...(existingProvider?.forcePathStyle !== undefined
6179
+ ? { forcePathStyle: existingProvider.forcePathStyle }
6180
+ : {}),
6167
6181
  endpoint: cloudflareR2Endpoint(accountId, jurisdiction),
6168
6182
  jurisdiction,
6169
6183
  kind: "cloudflare-r2",
@@ -6188,6 +6202,16 @@ async function setupCloudflareR2(cwd, options = {}) {
6188
6202
  throw new Error(`R2 bucket \`${bucket}\` exists, but Loom could not verify its private-access policy: ${privacy.detail}. Rerun after Wrangler can inspect public URL and custom-domain settings.`);
6189
6203
  }
6190
6204
  }
6205
+ if (config.storage.provider.directBrowserAccess) {
6206
+ for (const bucket of new Set(Object.values(buckets))) {
6207
+ const cors = await inspectR2BucketCors(cwd, commandRunner, providerEnv, wranglerCommand, bucket, config.storage.provider, options.cloudflareProfile);
6208
+ if (cors !== "matching") {
6209
+ throw new Error(`R2 bucket \`${bucket}\` CORS ${cors === "unknown"
6210
+ ? "could not be verified"
6211
+ : "differs from the declared presigned-PUT policy"}. Review and apply its exact CORS separately, then rerun setup; Loom never applies CORS implicitly.`);
6212
+ }
6213
+ }
6214
+ }
6191
6215
  const dependencyUpdate = await (0, projectTooling_js_1.mutateProjectDependencies)(cwd, tooling.dependencies, { dependencies: FILES_S3_DEPENDENCIES });
6192
6216
  if (dependencyUpdate.changed) {
6193
6217
  changedFiles.push(dependencyUpdate.config);
@@ -6207,7 +6231,9 @@ async function setupCloudflareR2(cwd, options = {}) {
6207
6231
  const desiredLocalValues = {
6208
6232
  FILES_S3_BUCKET: localBucket,
6209
6233
  FILES_S3_ENDPOINT: localEndpoint,
6210
- FILES_S3_FORCE_PATH_STYLE: localProvider === "minio" ? "true" : "false",
6234
+ FILES_S3_FORCE_PATH_STYLE: localProvider === "minio"
6235
+ ? "true"
6236
+ : String(config.storage.provider.forcePathStyle ?? false),
6211
6237
  FILES_S3_REGION: "auto",
6212
6238
  FILES_STORAGE_PROVIDER: localProvider === "minio"
6213
6239
  ? "minio"
@@ -6255,6 +6281,7 @@ async function setupCloudflareR2(cwd, options = {}) {
6255
6281
  FILES_S3_BUCKET: buckets[environment],
6256
6282
  FILES_S3_ENDPOINT: cloudflareR2Endpoint(accountId, jurisdiction),
6257
6283
  ...FILES_S3_NON_SECRET_ENV_VALUES,
6284
+ FILES_S3_FORCE_PATH_STYLE: String(config.storage.provider.forcePathStyle ?? false),
6258
6285
  };
6259
6286
  const existingNonSecretNames = Object.keys(nonSecretValues).filter((name) => hasExactEnvName(listing, name));
6260
6287
  if (existingNonSecretNames.length) {
@@ -6479,62 +6506,6 @@ async function hasProductionPushDbMigrationWorkflow(cwd, productionBranch) {
6479
6506
  }
6480
6507
  return false;
6481
6508
  }
6482
- function findStringPropertyDeep(value, propertyName) {
6483
- if (typeof value !== "object" || value === null) {
6484
- return null;
6485
- }
6486
- if (!Array.isArray(value) &&
6487
- typeof value[propertyName] === "string") {
6488
- return value[propertyName];
6489
- }
6490
- const children = Array.isArray(value)
6491
- ? value
6492
- : Object.values(value);
6493
- for (const child of children) {
6494
- const found = findStringPropertyDeep(child, propertyName);
6495
- if (found) {
6496
- return found;
6497
- }
6498
- }
6499
- return null;
6500
- }
6501
- function parseJsonFromCommandOutput(text) {
6502
- const trimmed = text.trim();
6503
- if (!trimmed) {
6504
- return null;
6505
- }
6506
- try {
6507
- return JSON.parse(trimmed);
6508
- }
6509
- catch {
6510
- // Some CLIs print progress lines before JSON even with --format json.
6511
- }
6512
- const starts = [trimmed.indexOf("{"), trimmed.indexOf("[")]
6513
- .filter((index) => index >= 0)
6514
- .sort((a, b) => a - b);
6515
- for (const start of starts) {
6516
- const close = trimmed[start] === "{" ? "}" : "]";
6517
- const end = trimmed.lastIndexOf(close);
6518
- if (end <= start) {
6519
- continue;
6520
- }
6521
- try {
6522
- return JSON.parse(trimmed.slice(start, end + 1));
6523
- }
6524
- catch {
6525
- // Try the next JSON-looking range.
6526
- }
6527
- }
6528
- return null;
6529
- }
6530
- function parseVercelCreatedToken(text) {
6531
- const parsed = parseJsonFromCommandOutput(text);
6532
- if (!parsed) {
6533
- return null;
6534
- }
6535
- return findStringPropertyDeep(parsed, "bearerToken") ??
6536
- findStringPropertyDeep(parsed, "token");
6537
- }
6538
6509
  function getProjectSlug(cwd, packageJson, manifest) {
6539
6510
  return sanitizeVercelResourceName(manifest?.project?.name ?? packageJson.name ?? (0, node_path_1.basename)(cwd));
6540
6511
  }
@@ -6785,7 +6756,7 @@ function createGithubReleaseConfigCheckStep(state, context) {
6785
6756
  return networkCheckResult("warning", "GitHub CLI is not available, so Loom could not inspect GitHub Actions secrets and variables.", {
6786
6757
  suggestions: [
6787
6758
  "Install and authenticate `gh`, then rerun `loom check --network`.",
6788
- "After `gh` is available, run `loom db release setup-github` from the project root to create a team-scoped Vercel token and store the required GitHub release configuration.",
6759
+ "After `gh` is available, run `loom db release setup-github` from the project root to create a bounded project-scoped Vercel token and store the required GitHub release configuration.",
6789
6760
  `Set production release config with \`gh secret set VERCEL_TOKEN --env ${PRODUCTION_GITHUB_ENVIRONMENT}\`, \`gh variable set VERCEL_ORG_ID --env ${PRODUCTION_GITHUB_ENVIRONMENT} --body ${state.vercelOrgId}\`, and \`gh variable set VERCEL_PROJECT_ID --env ${PRODUCTION_GITHUB_ENVIRONMENT} --body ${state.vercelProjectId}\`.`,
6790
6761
  ],
6791
6762
  warnings: [
@@ -6817,7 +6788,7 @@ function createGithubReleaseConfigCheckStep(state, context) {
6817
6788
  for (const secretName of REQUIRED_GITHUB_VERCEL_SECRET_NAMES) {
6818
6789
  if (!collectionHasName(secretName, environmentSecrets, repoSecrets)) {
6819
6790
  issues.push(`GitHub Actions is missing required production secret: ${secretName}.`);
6820
- suggestions.add("Run `loom db release setup-github` from the project root to create a team-scoped Vercel token and store the required GitHub release configuration.");
6791
+ suggestions.add("Run `loom db release setup-github` from the project root to create or preserve the bounded project-scoped Vercel release credential and store the required GitHub configuration.");
6821
6792
  suggestions.add(`Run \`gh secret set ${secretName} --env ${PRODUCTION_GITHUB_ENVIRONMENT}\` from the project root.`);
6822
6793
  suggestions.add(`If GitHub reports that the ${PRODUCTION_GITHUB_ENVIRONMENT} environment does not exist, create it with \`gh api --method PUT repos/:owner/:repo/environments/${PRODUCTION_GITHUB_ENVIRONMENT}\`, then rerun the secret command.`);
6823
6794
  }
@@ -6841,7 +6812,7 @@ function createGithubReleaseConfigCheckStep(state, context) {
6841
6812
  else {
6842
6813
  issues.push(`GitHub Actions is missing required production variable: ${name}.`);
6843
6814
  }
6844
- suggestions.add("Run `loom db release setup-github` from the project root to create a team-scoped Vercel token and store the required GitHub release configuration.");
6815
+ suggestions.add("Run `loom db release setup-github` from the project root to create or preserve the bounded project-scoped Vercel release credential and store the required GitHub configuration.");
6845
6816
  suggestions.add(`Run \`gh variable set ${name} --env ${PRODUCTION_GITHUB_ENVIRONMENT} --body ${expectedValues[name]}\` from the project root.`);
6846
6817
  }
6847
6818
  for (const staleSecret of STALE_GITHUB_RELEASE_SECRET_NAMES) {
@@ -7078,6 +7049,28 @@ async function inspectR2BucketPrivacy(cwd, commandRunner, env, wranglerCommand,
7078
7049
  }
7079
7050
  return { detail: "No public endpoint detected.", status: "private" };
7080
7051
  }
7052
+ async function inspectR2BucketCors(cwd, commandRunner, env, wranglerCommand, bucket, provider, cloudflareProfile) {
7053
+ const result = await commandRunner(wranglerCommand, r2BucketCommandArgs(["r2", "bucket", "cors", "list", bucket], provider, cloudflareProfile), {
7054
+ cwd,
7055
+ env: {
7056
+ ...env,
7057
+ NO_COLOR: "1",
7058
+ FORCE_COLOR: "0",
7059
+ WRANGLER_HIDE_BANNER: "true",
7060
+ },
7061
+ stdio: "pipe",
7062
+ });
7063
+ const rules = result.code === 0
7064
+ ? (0, filesR2Policy_js_1.parseWranglerR2Cors)(result.stdout, bucket)
7065
+ : null;
7066
+ if (rules === null)
7067
+ return "unknown";
7068
+ const environments = FILES_R2_ENVIRONMENTS.filter((environment) => provider.buckets[environment] === bucket);
7069
+ return provider.directUpload &&
7070
+ (0, filesR2Policy_js_1.r2CorsMatchesPolicy)(rules, provider.directUpload, environments)
7071
+ ? "matching"
7072
+ : "drift";
7073
+ }
7081
7074
  function checkFilesNetworkFeature(context) {
7082
7075
  const feature = context.manifest.features.files;
7083
7076
  if (!feature || feature.status !== "active")
@@ -7097,6 +7090,13 @@ function checkFilesNetworkFeature(context) {
7097
7090
  })),
7098
7091
  }];
7099
7092
  }
7093
+ const policyIssues = (0, filesR2Policy_js_1.filesR2PolicyIssues)(provider);
7094
+ if (policyIssues.length) {
7095
+ return [{
7096
+ label: "Cloudflare R2 private upload policy is valid",
7097
+ run: () => Promise.resolve(networkCheckResult("issue", "Invalid Files R2 policy; provider checks were not attempted.", { issues: policyIssues })),
7098
+ }];
7099
+ }
7100
7100
  const state = {
7101
7101
  accountAvailable: false,
7102
7102
  vercelCommand: null,
@@ -7216,6 +7216,33 @@ function checkFilesNetworkFeature(context) {
7216
7216
  },
7217
7217
  });
7218
7218
  }
7219
+ if (provider.directBrowserAccess) {
7220
+ for (const bucket of new Set(Object.values(provider.buckets))) {
7221
+ steps.push({
7222
+ label: `R2 bucket ${bucket} CORS matches the private presigned-PUT policy`,
7223
+ run: async () => {
7224
+ if (!state.wranglerCommand || !state.accountAvailable) {
7225
+ return networkCheckResult("skipped", "Skipped until Wrangler account access is verified.");
7226
+ }
7227
+ const cors = await inspectR2BucketCors(context.cwd, context.commandRunner, providerEnv, state.wranglerCommand, bucket, provider, context.cloudflareProfile);
7228
+ return cors === "matching"
7229
+ ? networkCheckResult("ok", `R2 bucket \`${bucket}\` CORS matches the declared private presigned-PUT policy.`)
7230
+ : networkCheckResult("issue", `R2 bucket \`${bucket}\` CORS is ${cors === "unknown"
7231
+ ? "unverified"
7232
+ : "different from the declared policy"}.`, {
7233
+ issues: [
7234
+ `Files R2 direct-upload CORS ${cors === "unknown"
7235
+ ? "could not be read or parsed"
7236
+ : "drift detected"}: ${bucket}.`,
7237
+ ],
7238
+ suggestions: [
7239
+ "Review the bucket's exact CORS policy using Wrangler; apply changes separately, then rerun `loom files r2 check`. Loom never applies CORS implicitly.",
7240
+ ],
7241
+ });
7242
+ },
7243
+ });
7244
+ }
7245
+ }
7219
7246
  steps.push({
7220
7247
  label: "Vercel CLI authentication and project link are available",
7221
7248
  run: async () => {
@@ -7291,6 +7318,7 @@ function checkFilesNetworkFeature(context) {
7291
7318
  FILES_S3_BUCKET: provider.buckets[environment],
7292
7319
  FILES_S3_ENDPOINT: provider.endpoint,
7293
7320
  ...FILES_S3_NON_SECRET_ENV_VALUES,
7321
+ FILES_S3_FORCE_PATH_STYLE: String(provider.forcePathStyle ?? false),
7294
7322
  };
7295
7323
  const drift = Object.entries(expectedValues).filter(([name, value]) => actualValues[name] !== value).map(([name]) => name);
7296
7324
  return drift.length
@@ -7542,10 +7570,6 @@ async function setupGithubVercelRelease(cwd, options = {}) {
7542
7570
  const commandRunner = options.commandRunner ?? defaultCommandRunner;
7543
7571
  const env = options.env ?? node_process_1.default.env;
7544
7572
  const environment = options.environment ?? PRODUCTION_GITHUB_ENVIRONMENT;
7545
- const io = options.io ?? {
7546
- err: (line) => console.error(line),
7547
- out: (line) => console.log(line),
7548
- };
7549
7573
  const { packageJson } = await readProjectPackageJson(cwd);
7550
7574
  const manifestText = await readTextIfExists((0, node_path_1.join)(cwd, "loom.json"));
7551
7575
  const manifest = manifestText
@@ -7566,89 +7590,24 @@ async function setupGithubVercelRelease(cwd, options = {}) {
7566
7590
  }
7567
7591
  const tokenName = options.tokenName ??
7568
7592
  getDefaultVercelGithubTokenName(cwd, packageJson, manifest);
7569
- const notes = [];
7570
- await requireCommand(`Create GitHub ${environment} environment`, commandRunner, "gh", [
7571
- "api",
7572
- "--method",
7573
- "PUT",
7574
- `repos/:owner/:repo/environments/${environment}`,
7575
- "--input",
7576
- "-",
7577
- ], {
7593
+ return await (0, releaseCredentials_js_1.configureGithubVercelReleaseCredential)({
7594
+ commandRunner,
7578
7595
  cwd,
7579
7596
  env,
7580
- input: JSON.stringify({
7581
- deployment_branch_policy: {
7582
- custom_branch_policies: true,
7583
- protected_branches: false,
7584
- },
7585
- }),
7586
- stdio: "pipe",
7587
- });
7588
- const branchPoliciesResult = await requireCommand(`List GitHub ${environment} deployment branches`, commandRunner, "gh", [
7589
- "api",
7590
- `repos/:owner/:repo/environments/${environment}/deployment-branch-policies`,
7591
- ], { cwd, env, stdio: "pipe" });
7592
- const branchPolicies = parseJson(branchPoliciesResult.stdout || "{}", "GitHub deployment branch policies");
7593
- if (!branchPolicies.branch_policies?.some((policy) => policy.name === productionBranch)) {
7594
- await requireCommand(`Allow ${productionBranch} to deploy to GitHub ${environment}`, commandRunner, "gh", [
7595
- "api",
7596
- "--method",
7597
- "POST",
7598
- `repos/:owner/:repo/environments/${environment}/deployment-branch-policies`,
7599
- "--input",
7600
- "-",
7601
- ], {
7602
- cwd,
7603
- env,
7604
- input: JSON.stringify({ name: productionBranch, type: "branch" }),
7605
- stdio: "pipe",
7606
- });
7607
- }
7608
- notes.push(`Ensured GitHub environment \`${environment}\` exists and allows the ${productionBranch} release branch; existing branch policies are preserved.`);
7609
- await requireCommand("Set GitHub VERCEL_ORG_ID variable", commandRunner, "gh", [
7610
- "variable",
7611
- "set",
7612
- "VERCEL_ORG_ID",
7613
- "--env",
7614
7597
  environment,
7615
- "--body",
7616
- vercelLink.orgId,
7617
- ], { cwd, env, stdio: "pipe" });
7618
- await requireCommand("Set GitHub VERCEL_PROJECT_ID variable", commandRunner, "gh", [
7619
- "variable",
7620
- "set",
7621
- "VERCEL_PROJECT_ID",
7622
- "--env",
7623
- environment,
7624
- "--body",
7625
- vercelLink.projectId,
7626
- ], { cwd, env, stdio: "pipe" });
7627
- notes.push("Set GitHub Vercel project ID variables.");
7628
- io.out(`Creating Vercel token \`${tokenName}\` scoped to this team...`);
7629
- const tokenResult = await requireCommand("Create Vercel authentication token", commandRunner, vercelCli.command, [
7630
- "api",
7631
- `/v3/user/tokens?teamId=${encodeURIComponent(vercelLink.orgId)}`,
7632
- "--method",
7633
- "POST",
7634
- "--input",
7635
- "-",
7636
- "--raw",
7637
- ], {
7638
- cwd,
7639
- env,
7640
- input: JSON.stringify({
7641
- name: tokenName,
7642
- }),
7643
- stdio: "pipe",
7598
+ githubCommand: githubCli.command,
7599
+ hasTokenOverrides: options.tokenExpiryDays !== undefined ||
7600
+ options.tokenName !== undefined || options.tokenScope !== undefined,
7601
+ now: options.now,
7602
+ orgId: vercelLink.orgId,
7603
+ productionBranch,
7604
+ projectId: vercelLink.projectId,
7605
+ rotateToken: options.rotateToken ?? false,
7606
+ tokenExpiryDays: options.tokenExpiryDays,
7607
+ tokenName,
7608
+ tokenScope: options.tokenScope,
7609
+ vercelCommand: vercelCli.command,
7644
7610
  });
7645
- const token = parseVercelCreatedToken(tokenResult.stdout);
7646
- if (!token) {
7647
- throw new Error("Vercel token was created, but Loom could not find a token value in the CLI JSON output. Open the Vercel dashboard token page and set `gh secret set VERCEL_TOKEN --env production` manually.");
7648
- }
7649
- await requireCommand("Set GitHub VERCEL_TOKEN secret", commandRunner, "gh", ["secret", "set", "VERCEL_TOKEN", "--env", environment], { cwd, env, input: token, stdio: "pipe" });
7650
- notes.push("Stored the new Vercel token as GitHub secret `VERCEL_TOKEN`.");
7651
- return { notes };
7652
7611
  }
7653
7612
  async function applyJobsFeature(cwd, framework, manifest, activate) {
7654
7613
  const changedFiles = [];
@@ -9010,10 +8969,7 @@ async function checkFilesFeature(cwd, framework, manifest, options) {
9010
8969
  if (provider.kind !== "cloudflare-r2") {
9011
8970
  issues.push("Files storage provider kind must be cloudflare-r2.");
9012
8971
  }
9013
- if (provider.accessMode !== "private" || provider.directBrowserAccess ||
9014
- provider.publicUrl !== null) {
9015
- issues.push("Files R2 provider policy must remain private unless a future explicit public-access workflow is adopted.");
9016
- }
8972
+ issues.push(...(0, filesR2Policy_js_1.filesR2PolicyIssues)(provider));
9017
8973
  if (!provider.accountId || !provider.buckets.production ||
9018
8974
  !provider.buckets.preview) {
9019
8975
  issues.push("Files R2 provider policy is missing account or bucket identifiers.");
@@ -10748,6 +10704,9 @@ function printHelp({ out }) {
10748
10704
  out(" db migrations verify-env Validate migration URL precedence and role metadata without printing credentials. Add --connect for a live access preflight.");
10749
10705
  out(" db migrations setup-github Store an existing direct migration URL as a protected GitHub Environment secret.");
10750
10706
  out(" db release setup-github Create/update GitHub production release config for staged Vercel deploys.");
10707
+ out(" db release trust-plan <workflow> <plan> Plan exact Vercel Trusted Sources for a GitHub release workflow.");
10708
+ out(" db release trust-apply <plan> <approval-sha256> Apply a reviewed Trusted Sources plan.");
10709
+ out(" db release trust-check <plan> Verify the reviewed Trusted Sources plan is active.");
10751
10710
  out(" db release prepare-build-env <env> <metadata> <policy> <manifest> Prepare metadata-backed placeholders for an external Vercel build.");
10752
10711
  out(" db release verify-build-env <output> <manifest> Reject build-only placeholders in a deployable Vercel artifact.");
10753
10712
  out(" dev local Enable local Loom development using a managed pnpm override or Deno link.");
@@ -10778,6 +10737,9 @@ function printHelp({ out }) {
10778
10737
  out(" --configure-secrets Ask Vercel to prompt securely for missing R2 credentials; never replaces existing credentials.");
10779
10738
  out(" --repair Apply declared non-secret Files provider drift; never deletes resources or rotates credentials.");
10780
10739
  out(" --token-name <name> Override the Vercel token name for `loom db release setup-github`.");
10740
+ out(" --rotate-token Explicitly replace an existing GitHub VERCEL_TOKEN; the old Vercel token remains active.");
10741
+ out(" --token-scope project|team Vercel release token scope (default project; team is compatibility mode).");
10742
+ out(" --token-expiry-days <days> Vercel release token lifetime (default 90).");
10781
10743
  out(" --environment <name> GitHub Environment for migration credential setup (default production).");
10782
10744
  out(" --env-file <path> Preserved env snapshot for `db migrations verify-env`; process values take precedence.");
10783
10745
  out(" --connect Authenticate and check migration database identity and schema privileges.");
@@ -11353,7 +11315,10 @@ async function runDbRelease(cwd, command, args, io, options) {
11353
11315
  const result = await setupGithubVercelRelease(cwd, {
11354
11316
  environment: options.environment,
11355
11317
  io,
11318
+ rotateToken: options.rotateToken,
11319
+ tokenExpiryDays: options.tokenExpiryDays,
11356
11320
  tokenName: options.tokenName,
11321
+ tokenScope: options.tokenScope,
11357
11322
  });
11358
11323
  for (const note of result.notes) {
11359
11324
  io.out(`Note: ${note}`);
@@ -11361,6 +11326,31 @@ async function runDbRelease(cwd, command, args, io, options) {
11361
11326
  io.out("Next step: run `loom check --production --network` to verify the release configuration.");
11362
11327
  return 0;
11363
11328
  }
11329
+ case "trust-plan":
11330
+ case "trust-apply":
11331
+ case "trust-check": {
11332
+ const vercelCli = await detectVercelCliCommand(cwd, defaultCommandRunner, node_process_1.default.env);
11333
+ if (!vercelCli.command) {
11334
+ throw new Error("Vercel CLI is not available. Install it or make `vercel`/`vc` available on PATH.");
11335
+ }
11336
+ const action = command === "trust-plan"
11337
+ ? "plan"
11338
+ : command === "trust-apply"
11339
+ ? "apply"
11340
+ : "check";
11341
+ const notes = await (0, releaseTrustCommand_js_1.runGithubReleaseTrustCommand)(action, args, {
11342
+ commandRunner: defaultCommandRunner,
11343
+ cwd,
11344
+ env: node_process_1.default.env,
11345
+ environment: action === "plan"
11346
+ ? options.environment ?? PRODUCTION_GITHUB_ENVIRONMENT
11347
+ : options.environment,
11348
+ vercelCli: vercelCli.command,
11349
+ });
11350
+ for (const note of notes)
11351
+ io.out(`Note: ${note}`);
11352
+ return 0;
11353
+ }
11364
11354
  default:
11365
11355
  io.err(`Unknown release subcommand: ${command}`);
11366
11356
  io.err("Run `loom --help` for usage.");
@@ -11605,6 +11595,9 @@ async function runCli(args = node_process_1.default.argv.slice(2), io = {
11605
11595
  "strict-skills": { type: "boolean" },
11606
11596
  "shared-bucket": { type: "string" },
11607
11597
  "token-name": { type: "string" },
11598
+ "token-expiry-days": { type: "string" },
11599
+ "token-scope": { type: "string" },
11600
+ "rotate-token": { type: "boolean" },
11608
11601
  version: { type: "string" },
11609
11602
  },
11610
11603
  });
@@ -11691,6 +11684,9 @@ async function runCli(args = node_process_1.default.argv.slice(2), io = {
11691
11684
  plan: parsed.values.plan,
11692
11685
  region: parsed.values.region,
11693
11686
  tokenName: parsed.values["token-name"],
11687
+ tokenScope: parsed.values["token-scope"],
11688
+ tokenExpiryDays: parsed.values["token-expiry-days"],
11689
+ rotateToken: parsed.values["rotate-token"],
11694
11690
  });
11695
11691
  case "dev":
11696
11692
  return await runDev(cwd, arg1, arg2, io, {
@@ -0,0 +1,32 @@
1
+ import type { CommandRunner } from "./mod.js";
2
+ export declare const DEFAULT_VERCEL_TOKEN_EXPIRY_DAYS = 90;
3
+ export declare const VERCEL_TOKEN_EXPIRY_VARIABLE = "LOOM_VERCEL_TOKEN_EXPIRES_AT";
4
+ export declare const VERCEL_TOKEN_ID_VARIABLE = "LOOM_VERCEL_TOKEN_ID";
5
+ export declare const VERCEL_TOKEN_SCOPE_VARIABLE = "LOOM_VERCEL_TOKEN_SCOPE";
6
+ export type VercelReleaseTokenScope = "project" | "team";
7
+ type ReleaseCredentialSetupOptions = {
8
+ commandRunner: CommandRunner;
9
+ cwd: string;
10
+ env: Record<string, string | undefined>;
11
+ environment: string;
12
+ githubCommand: string;
13
+ hasTokenOverrides: boolean;
14
+ now?: () => Date;
15
+ orgId: string;
16
+ productionBranch: string;
17
+ projectId: string;
18
+ rotateToken: boolean;
19
+ tokenExpiryDays?: number | string;
20
+ tokenName: string;
21
+ tokenScope?: string;
22
+ vercelCommand: string;
23
+ };
24
+ /**
25
+ * Audits GitHub release protections and installs a bounded Vercel credential
26
+ * without exposing token values in arguments or provider failures.
27
+ */
28
+ export declare function configureGithubVercelReleaseCredential(options: ReleaseCredentialSetupOptions): Promise<{
29
+ notes: string[];
30
+ }>;
31
+ export {};
32
+ //# sourceMappingURL=releaseCredentials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"releaseCredentials.d.ts","sourceRoot":"","sources":["../../../src/src/cli/releaseCredentials.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,eAAO,MAAM,gCAAgC,KAAK,CAAC;AACnD,eAAO,MAAM,4BAA4B,iCAAiC,CAAC;AAC3E,eAAO,MAAM,wBAAwB,yBAAyB,CAAC;AAC/D,eAAO,MAAM,2BAA2B,4BAA4B,CAAC;AAErE,MAAM,MAAM,uBAAuB,GAAG,SAAS,GAAG,MAAM,CAAC;AAEzD,KAAK,6BAA6B,GAAG;IACnC,aAAa,EAAE,aAAa,CAAC;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,OAAO,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AA+eF;;;GAGG;AACH,wBAAsB,sCAAsC,CAC1D,OAAO,EAAE,6BAA6B;;GAuHvC"}