@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
@@ -6,7 +6,10 @@ import { createRequire } from "node:module";
6
6
  import { basename, dirname, join, relative, resolve, sep } from "node:path";
7
7
  import process from "node:process";
8
8
  import { parseArgs } from "node:util";
9
+ import { filesR2PolicyIssues, parseWranglerR2Cors, r2CorsMatchesPolicy, } from "./filesR2Policy.js";
9
10
  import { resolveProductionBranch, } from "./releaseConfig.js";
11
+ import { configureGithubVercelReleaseCredential, } from "./releaseCredentials.js";
12
+ import { runGithubReleaseTrustCommand } from "./releaseTrustCommand.js";
10
13
  import { DEFAULT_API_KEY_AUDIT_RETENTION } from "../apiKeys/retention.js";
11
14
  import { checkProjectSkills, getProjectSkillStatus, LOOM_EXTERNAL_SKILLS_GITIGNORE_LINE, removeLegacyNextSkillLink, setProjectSkillDisabled, syncExternalProjectSkills, syncInstalledPackageSkills, } from "./projectSkills.js";
12
15
  import { resolveMigrationEnvironment, resolveMigrationEnvironmentFromEnvFile, verifyMigrationConnection, verifyMigrationConnectionFromEnvFile, } from "./migrationEnv.js";
@@ -5971,6 +5974,11 @@ export async function setupCloudflareR2(cwd, options = {}) {
5971
5974
  const dbConfig = mergeDbConfig(framework, dbFeature.config);
5972
5975
  const config = getFilesConfig(framework, dbConfig, feature.config);
5973
5976
  const existingProvider = config.storage.provider;
5977
+ if (existingProvider) {
5978
+ const policyIssues = filesR2PolicyIssues(existingProvider);
5979
+ if (policyIssues.length)
5980
+ throw new Error(policyIssues.join(" "));
5981
+ }
5974
5982
  const wranglerCommand = await detectWranglerCommand(cwd, commandRunner, env);
5975
5983
  if (!wranglerCommand) {
5976
5984
  throw new Error("Wrangler is not available. On Arch Linux install it with `sudo pacman -S wrangler`, then run `wrangler login`.");
@@ -6092,7 +6100,13 @@ export async function setupCloudflareR2(cwd, options = {}) {
6092
6100
  buckets,
6093
6101
  connectionStatus: "buckets-ready",
6094
6102
  credentialMode: "manual",
6095
- directBrowserAccess: false,
6103
+ directBrowserAccess: existingProvider?.directBrowserAccess ?? false,
6104
+ ...(existingProvider?.directUpload
6105
+ ? { directUpload: existingProvider.directUpload }
6106
+ : {}),
6107
+ ...(existingProvider?.forcePathStyle !== undefined
6108
+ ? { forcePathStyle: existingProvider.forcePathStyle }
6109
+ : {}),
6096
6110
  endpoint: cloudflareR2Endpoint(accountId, jurisdiction),
6097
6111
  jurisdiction,
6098
6112
  kind: "cloudflare-r2",
@@ -6117,6 +6131,16 @@ export async function setupCloudflareR2(cwd, options = {}) {
6117
6131
  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.`);
6118
6132
  }
6119
6133
  }
6134
+ if (config.storage.provider.directBrowserAccess) {
6135
+ for (const bucket of new Set(Object.values(buckets))) {
6136
+ const cors = await inspectR2BucketCors(cwd, commandRunner, providerEnv, wranglerCommand, bucket, config.storage.provider, options.cloudflareProfile);
6137
+ if (cors !== "matching") {
6138
+ throw new Error(`R2 bucket \`${bucket}\` CORS ${cors === "unknown"
6139
+ ? "could not be verified"
6140
+ : "differs from the declared presigned-PUT policy"}. Review and apply its exact CORS separately, then rerun setup; Loom never applies CORS implicitly.`);
6141
+ }
6142
+ }
6143
+ }
6120
6144
  const dependencyUpdate = await mutateProjectDependencies(cwd, tooling.dependencies, { dependencies: FILES_S3_DEPENDENCIES });
6121
6145
  if (dependencyUpdate.changed) {
6122
6146
  changedFiles.push(dependencyUpdate.config);
@@ -6136,7 +6160,9 @@ export async function setupCloudflareR2(cwd, options = {}) {
6136
6160
  const desiredLocalValues = {
6137
6161
  FILES_S3_BUCKET: localBucket,
6138
6162
  FILES_S3_ENDPOINT: localEndpoint,
6139
- FILES_S3_FORCE_PATH_STYLE: localProvider === "minio" ? "true" : "false",
6163
+ FILES_S3_FORCE_PATH_STYLE: localProvider === "minio"
6164
+ ? "true"
6165
+ : String(config.storage.provider.forcePathStyle ?? false),
6140
6166
  FILES_S3_REGION: "auto",
6141
6167
  FILES_STORAGE_PROVIDER: localProvider === "minio"
6142
6168
  ? "minio"
@@ -6184,6 +6210,7 @@ export async function setupCloudflareR2(cwd, options = {}) {
6184
6210
  FILES_S3_BUCKET: buckets[environment],
6185
6211
  FILES_S3_ENDPOINT: cloudflareR2Endpoint(accountId, jurisdiction),
6186
6212
  ...FILES_S3_NON_SECRET_ENV_VALUES,
6213
+ FILES_S3_FORCE_PATH_STYLE: String(config.storage.provider.forcePathStyle ?? false),
6187
6214
  };
6188
6215
  const existingNonSecretNames = Object.keys(nonSecretValues).filter((name) => hasExactEnvName(listing, name));
6189
6216
  if (existingNonSecretNames.length) {
@@ -6408,62 +6435,6 @@ async function hasProductionPushDbMigrationWorkflow(cwd, productionBranch) {
6408
6435
  }
6409
6436
  return false;
6410
6437
  }
6411
- function findStringPropertyDeep(value, propertyName) {
6412
- if (typeof value !== "object" || value === null) {
6413
- return null;
6414
- }
6415
- if (!Array.isArray(value) &&
6416
- typeof value[propertyName] === "string") {
6417
- return value[propertyName];
6418
- }
6419
- const children = Array.isArray(value)
6420
- ? value
6421
- : Object.values(value);
6422
- for (const child of children) {
6423
- const found = findStringPropertyDeep(child, propertyName);
6424
- if (found) {
6425
- return found;
6426
- }
6427
- }
6428
- return null;
6429
- }
6430
- function parseJsonFromCommandOutput(text) {
6431
- const trimmed = text.trim();
6432
- if (!trimmed) {
6433
- return null;
6434
- }
6435
- try {
6436
- return JSON.parse(trimmed);
6437
- }
6438
- catch {
6439
- // Some CLIs print progress lines before JSON even with --format json.
6440
- }
6441
- const starts = [trimmed.indexOf("{"), trimmed.indexOf("[")]
6442
- .filter((index) => index >= 0)
6443
- .sort((a, b) => a - b);
6444
- for (const start of starts) {
6445
- const close = trimmed[start] === "{" ? "}" : "]";
6446
- const end = trimmed.lastIndexOf(close);
6447
- if (end <= start) {
6448
- continue;
6449
- }
6450
- try {
6451
- return JSON.parse(trimmed.slice(start, end + 1));
6452
- }
6453
- catch {
6454
- // Try the next JSON-looking range.
6455
- }
6456
- }
6457
- return null;
6458
- }
6459
- function parseVercelCreatedToken(text) {
6460
- const parsed = parseJsonFromCommandOutput(text);
6461
- if (!parsed) {
6462
- return null;
6463
- }
6464
- return findStringPropertyDeep(parsed, "bearerToken") ??
6465
- findStringPropertyDeep(parsed, "token");
6466
- }
6467
6438
  function getProjectSlug(cwd, packageJson, manifest) {
6468
6439
  return sanitizeVercelResourceName(manifest?.project?.name ?? packageJson.name ?? basename(cwd));
6469
6440
  }
@@ -6714,7 +6685,7 @@ function createGithubReleaseConfigCheckStep(state, context) {
6714
6685
  return networkCheckResult("warning", "GitHub CLI is not available, so Loom could not inspect GitHub Actions secrets and variables.", {
6715
6686
  suggestions: [
6716
6687
  "Install and authenticate `gh`, then rerun `loom check --network`.",
6717
- "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.",
6688
+ "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.",
6718
6689
  `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}\`.`,
6719
6690
  ],
6720
6691
  warnings: [
@@ -6746,7 +6717,7 @@ function createGithubReleaseConfigCheckStep(state, context) {
6746
6717
  for (const secretName of REQUIRED_GITHUB_VERCEL_SECRET_NAMES) {
6747
6718
  if (!collectionHasName(secretName, environmentSecrets, repoSecrets)) {
6748
6719
  issues.push(`GitHub Actions is missing required production secret: ${secretName}.`);
6749
- 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.");
6720
+ 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.");
6750
6721
  suggestions.add(`Run \`gh secret set ${secretName} --env ${PRODUCTION_GITHUB_ENVIRONMENT}\` from the project root.`);
6751
6722
  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.`);
6752
6723
  }
@@ -6770,7 +6741,7 @@ function createGithubReleaseConfigCheckStep(state, context) {
6770
6741
  else {
6771
6742
  issues.push(`GitHub Actions is missing required production variable: ${name}.`);
6772
6743
  }
6773
- 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.");
6744
+ 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.");
6774
6745
  suggestions.add(`Run \`gh variable set ${name} --env ${PRODUCTION_GITHUB_ENVIRONMENT} --body ${expectedValues[name]}\` from the project root.`);
6775
6746
  }
6776
6747
  for (const staleSecret of STALE_GITHUB_RELEASE_SECRET_NAMES) {
@@ -7007,6 +6978,28 @@ async function inspectR2BucketPrivacy(cwd, commandRunner, env, wranglerCommand,
7007
6978
  }
7008
6979
  return { detail: "No public endpoint detected.", status: "private" };
7009
6980
  }
6981
+ async function inspectR2BucketCors(cwd, commandRunner, env, wranglerCommand, bucket, provider, cloudflareProfile) {
6982
+ const result = await commandRunner(wranglerCommand, r2BucketCommandArgs(["r2", "bucket", "cors", "list", bucket], provider, cloudflareProfile), {
6983
+ cwd,
6984
+ env: {
6985
+ ...env,
6986
+ NO_COLOR: "1",
6987
+ FORCE_COLOR: "0",
6988
+ WRANGLER_HIDE_BANNER: "true",
6989
+ },
6990
+ stdio: "pipe",
6991
+ });
6992
+ const rules = result.code === 0
6993
+ ? parseWranglerR2Cors(result.stdout, bucket)
6994
+ : null;
6995
+ if (rules === null)
6996
+ return "unknown";
6997
+ const environments = FILES_R2_ENVIRONMENTS.filter((environment) => provider.buckets[environment] === bucket);
6998
+ return provider.directUpload &&
6999
+ r2CorsMatchesPolicy(rules, provider.directUpload, environments)
7000
+ ? "matching"
7001
+ : "drift";
7002
+ }
7010
7003
  function checkFilesNetworkFeature(context) {
7011
7004
  const feature = context.manifest.features.files;
7012
7005
  if (!feature || feature.status !== "active")
@@ -7026,6 +7019,13 @@ function checkFilesNetworkFeature(context) {
7026
7019
  })),
7027
7020
  }];
7028
7021
  }
7022
+ const policyIssues = filesR2PolicyIssues(provider);
7023
+ if (policyIssues.length) {
7024
+ return [{
7025
+ label: "Cloudflare R2 private upload policy is valid",
7026
+ run: () => Promise.resolve(networkCheckResult("issue", "Invalid Files R2 policy; provider checks were not attempted.", { issues: policyIssues })),
7027
+ }];
7028
+ }
7029
7029
  const state = {
7030
7030
  accountAvailable: false,
7031
7031
  vercelCommand: null,
@@ -7145,6 +7145,33 @@ function checkFilesNetworkFeature(context) {
7145
7145
  },
7146
7146
  });
7147
7147
  }
7148
+ if (provider.directBrowserAccess) {
7149
+ for (const bucket of new Set(Object.values(provider.buckets))) {
7150
+ steps.push({
7151
+ label: `R2 bucket ${bucket} CORS matches the private presigned-PUT policy`,
7152
+ run: async () => {
7153
+ if (!state.wranglerCommand || !state.accountAvailable) {
7154
+ return networkCheckResult("skipped", "Skipped until Wrangler account access is verified.");
7155
+ }
7156
+ const cors = await inspectR2BucketCors(context.cwd, context.commandRunner, providerEnv, state.wranglerCommand, bucket, provider, context.cloudflareProfile);
7157
+ return cors === "matching"
7158
+ ? networkCheckResult("ok", `R2 bucket \`${bucket}\` CORS matches the declared private presigned-PUT policy.`)
7159
+ : networkCheckResult("issue", `R2 bucket \`${bucket}\` CORS is ${cors === "unknown"
7160
+ ? "unverified"
7161
+ : "different from the declared policy"}.`, {
7162
+ issues: [
7163
+ `Files R2 direct-upload CORS ${cors === "unknown"
7164
+ ? "could not be read or parsed"
7165
+ : "drift detected"}: ${bucket}.`,
7166
+ ],
7167
+ suggestions: [
7168
+ "Review the bucket's exact CORS policy using Wrangler; apply changes separately, then rerun `loom files r2 check`. Loom never applies CORS implicitly.",
7169
+ ],
7170
+ });
7171
+ },
7172
+ });
7173
+ }
7174
+ }
7148
7175
  steps.push({
7149
7176
  label: "Vercel CLI authentication and project link are available",
7150
7177
  run: async () => {
@@ -7220,6 +7247,7 @@ function checkFilesNetworkFeature(context) {
7220
7247
  FILES_S3_BUCKET: provider.buckets[environment],
7221
7248
  FILES_S3_ENDPOINT: provider.endpoint,
7222
7249
  ...FILES_S3_NON_SECRET_ENV_VALUES,
7250
+ FILES_S3_FORCE_PATH_STYLE: String(provider.forcePathStyle ?? false),
7223
7251
  };
7224
7252
  const drift = Object.entries(expectedValues).filter(([name, value]) => actualValues[name] !== value).map(([name]) => name);
7225
7253
  return drift.length
@@ -7471,10 +7499,6 @@ export async function setupGithubVercelRelease(cwd, options = {}) {
7471
7499
  const commandRunner = options.commandRunner ?? defaultCommandRunner;
7472
7500
  const env = options.env ?? process.env;
7473
7501
  const environment = options.environment ?? PRODUCTION_GITHUB_ENVIRONMENT;
7474
- const io = options.io ?? {
7475
- err: (line) => console.error(line),
7476
- out: (line) => console.log(line),
7477
- };
7478
7502
  const { packageJson } = await readProjectPackageJson(cwd);
7479
7503
  const manifestText = await readTextIfExists(join(cwd, "loom.json"));
7480
7504
  const manifest = manifestText
@@ -7495,89 +7519,24 @@ export async function setupGithubVercelRelease(cwd, options = {}) {
7495
7519
  }
7496
7520
  const tokenName = options.tokenName ??
7497
7521
  getDefaultVercelGithubTokenName(cwd, packageJson, manifest);
7498
- const notes = [];
7499
- await requireCommand(`Create GitHub ${environment} environment`, commandRunner, "gh", [
7500
- "api",
7501
- "--method",
7502
- "PUT",
7503
- `repos/:owner/:repo/environments/${environment}`,
7504
- "--input",
7505
- "-",
7506
- ], {
7522
+ return await configureGithubVercelReleaseCredential({
7523
+ commandRunner,
7507
7524
  cwd,
7508
7525
  env,
7509
- input: JSON.stringify({
7510
- deployment_branch_policy: {
7511
- custom_branch_policies: true,
7512
- protected_branches: false,
7513
- },
7514
- }),
7515
- stdio: "pipe",
7516
- });
7517
- const branchPoliciesResult = await requireCommand(`List GitHub ${environment} deployment branches`, commandRunner, "gh", [
7518
- "api",
7519
- `repos/:owner/:repo/environments/${environment}/deployment-branch-policies`,
7520
- ], { cwd, env, stdio: "pipe" });
7521
- const branchPolicies = parseJson(branchPoliciesResult.stdout || "{}", "GitHub deployment branch policies");
7522
- if (!branchPolicies.branch_policies?.some((policy) => policy.name === productionBranch)) {
7523
- await requireCommand(`Allow ${productionBranch} to deploy to GitHub ${environment}`, commandRunner, "gh", [
7524
- "api",
7525
- "--method",
7526
- "POST",
7527
- `repos/:owner/:repo/environments/${environment}/deployment-branch-policies`,
7528
- "--input",
7529
- "-",
7530
- ], {
7531
- cwd,
7532
- env,
7533
- input: JSON.stringify({ name: productionBranch, type: "branch" }),
7534
- stdio: "pipe",
7535
- });
7536
- }
7537
- notes.push(`Ensured GitHub environment \`${environment}\` exists and allows the ${productionBranch} release branch; existing branch policies are preserved.`);
7538
- await requireCommand("Set GitHub VERCEL_ORG_ID variable", commandRunner, "gh", [
7539
- "variable",
7540
- "set",
7541
- "VERCEL_ORG_ID",
7542
- "--env",
7543
7526
  environment,
7544
- "--body",
7545
- vercelLink.orgId,
7546
- ], { cwd, env, stdio: "pipe" });
7547
- await requireCommand("Set GitHub VERCEL_PROJECT_ID variable", commandRunner, "gh", [
7548
- "variable",
7549
- "set",
7550
- "VERCEL_PROJECT_ID",
7551
- "--env",
7552
- environment,
7553
- "--body",
7554
- vercelLink.projectId,
7555
- ], { cwd, env, stdio: "pipe" });
7556
- notes.push("Set GitHub Vercel project ID variables.");
7557
- io.out(`Creating Vercel token \`${tokenName}\` scoped to this team...`);
7558
- const tokenResult = await requireCommand("Create Vercel authentication token", commandRunner, vercelCli.command, [
7559
- "api",
7560
- `/v3/user/tokens?teamId=${encodeURIComponent(vercelLink.orgId)}`,
7561
- "--method",
7562
- "POST",
7563
- "--input",
7564
- "-",
7565
- "--raw",
7566
- ], {
7567
- cwd,
7568
- env,
7569
- input: JSON.stringify({
7570
- name: tokenName,
7571
- }),
7572
- stdio: "pipe",
7527
+ githubCommand: githubCli.command,
7528
+ hasTokenOverrides: options.tokenExpiryDays !== undefined ||
7529
+ options.tokenName !== undefined || options.tokenScope !== undefined,
7530
+ now: options.now,
7531
+ orgId: vercelLink.orgId,
7532
+ productionBranch,
7533
+ projectId: vercelLink.projectId,
7534
+ rotateToken: options.rotateToken ?? false,
7535
+ tokenExpiryDays: options.tokenExpiryDays,
7536
+ tokenName,
7537
+ tokenScope: options.tokenScope,
7538
+ vercelCommand: vercelCli.command,
7573
7539
  });
7574
- const token = parseVercelCreatedToken(tokenResult.stdout);
7575
- if (!token) {
7576
- 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.");
7577
- }
7578
- await requireCommand("Set GitHub VERCEL_TOKEN secret", commandRunner, "gh", ["secret", "set", "VERCEL_TOKEN", "--env", environment], { cwd, env, input: token, stdio: "pipe" });
7579
- notes.push("Stored the new Vercel token as GitHub secret `VERCEL_TOKEN`.");
7580
- return { notes };
7581
7540
  }
7582
7541
  async function applyJobsFeature(cwd, framework, manifest, activate) {
7583
7542
  const changedFiles = [];
@@ -8939,10 +8898,7 @@ async function checkFilesFeature(cwd, framework, manifest, options) {
8939
8898
  if (provider.kind !== "cloudflare-r2") {
8940
8899
  issues.push("Files storage provider kind must be cloudflare-r2.");
8941
8900
  }
8942
- if (provider.accessMode !== "private" || provider.directBrowserAccess ||
8943
- provider.publicUrl !== null) {
8944
- issues.push("Files R2 provider policy must remain private unless a future explicit public-access workflow is adopted.");
8945
- }
8901
+ issues.push(...filesR2PolicyIssues(provider));
8946
8902
  if (!provider.accountId || !provider.buckets.production ||
8947
8903
  !provider.buckets.preview) {
8948
8904
  issues.push("Files R2 provider policy is missing account or bucket identifiers.");
@@ -10677,6 +10633,9 @@ function printHelp({ out }) {
10677
10633
  out(" db migrations verify-env Validate migration URL precedence and role metadata without printing credentials. Add --connect for a live access preflight.");
10678
10634
  out(" db migrations setup-github Store an existing direct migration URL as a protected GitHub Environment secret.");
10679
10635
  out(" db release setup-github Create/update GitHub production release config for staged Vercel deploys.");
10636
+ out(" db release trust-plan <workflow> <plan> Plan exact Vercel Trusted Sources for a GitHub release workflow.");
10637
+ out(" db release trust-apply <plan> <approval-sha256> Apply a reviewed Trusted Sources plan.");
10638
+ out(" db release trust-check <plan> Verify the reviewed Trusted Sources plan is active.");
10680
10639
  out(" db release prepare-build-env <env> <metadata> <policy> <manifest> Prepare metadata-backed placeholders for an external Vercel build.");
10681
10640
  out(" db release verify-build-env <output> <manifest> Reject build-only placeholders in a deployable Vercel artifact.");
10682
10641
  out(" dev local Enable local Loom development using a managed pnpm override or Deno link.");
@@ -10707,6 +10666,9 @@ function printHelp({ out }) {
10707
10666
  out(" --configure-secrets Ask Vercel to prompt securely for missing R2 credentials; never replaces existing credentials.");
10708
10667
  out(" --repair Apply declared non-secret Files provider drift; never deletes resources or rotates credentials.");
10709
10668
  out(" --token-name <name> Override the Vercel token name for `loom db release setup-github`.");
10669
+ out(" --rotate-token Explicitly replace an existing GitHub VERCEL_TOKEN; the old Vercel token remains active.");
10670
+ out(" --token-scope project|team Vercel release token scope (default project; team is compatibility mode).");
10671
+ out(" --token-expiry-days <days> Vercel release token lifetime (default 90).");
10710
10672
  out(" --environment <name> GitHub Environment for migration credential setup (default production).");
10711
10673
  out(" --env-file <path> Preserved env snapshot for `db migrations verify-env`; process values take precedence.");
10712
10674
  out(" --connect Authenticate and check migration database identity and schema privileges.");
@@ -11282,7 +11244,10 @@ async function runDbRelease(cwd, command, args, io, options) {
11282
11244
  const result = await setupGithubVercelRelease(cwd, {
11283
11245
  environment: options.environment,
11284
11246
  io,
11247
+ rotateToken: options.rotateToken,
11248
+ tokenExpiryDays: options.tokenExpiryDays,
11285
11249
  tokenName: options.tokenName,
11250
+ tokenScope: options.tokenScope,
11286
11251
  });
11287
11252
  for (const note of result.notes) {
11288
11253
  io.out(`Note: ${note}`);
@@ -11290,6 +11255,31 @@ async function runDbRelease(cwd, command, args, io, options) {
11290
11255
  io.out("Next step: run `loom check --production --network` to verify the release configuration.");
11291
11256
  return 0;
11292
11257
  }
11258
+ case "trust-plan":
11259
+ case "trust-apply":
11260
+ case "trust-check": {
11261
+ const vercelCli = await detectVercelCliCommand(cwd, defaultCommandRunner, process.env);
11262
+ if (!vercelCli.command) {
11263
+ throw new Error("Vercel CLI is not available. Install it or make `vercel`/`vc` available on PATH.");
11264
+ }
11265
+ const action = command === "trust-plan"
11266
+ ? "plan"
11267
+ : command === "trust-apply"
11268
+ ? "apply"
11269
+ : "check";
11270
+ const notes = await runGithubReleaseTrustCommand(action, args, {
11271
+ commandRunner: defaultCommandRunner,
11272
+ cwd,
11273
+ env: process.env,
11274
+ environment: action === "plan"
11275
+ ? options.environment ?? PRODUCTION_GITHUB_ENVIRONMENT
11276
+ : options.environment,
11277
+ vercelCli: vercelCli.command,
11278
+ });
11279
+ for (const note of notes)
11280
+ io.out(`Note: ${note}`);
11281
+ return 0;
11282
+ }
11293
11283
  default:
11294
11284
  io.err(`Unknown release subcommand: ${command}`);
11295
11285
  io.err("Run `loom --help` for usage.");
@@ -11534,6 +11524,9 @@ export async function runCli(args = process.argv.slice(2), io = {
11534
11524
  "strict-skills": { type: "boolean" },
11535
11525
  "shared-bucket": { type: "string" },
11536
11526
  "token-name": { type: "string" },
11527
+ "token-expiry-days": { type: "string" },
11528
+ "token-scope": { type: "string" },
11529
+ "rotate-token": { type: "boolean" },
11537
11530
  version: { type: "string" },
11538
11531
  },
11539
11532
  });
@@ -11620,6 +11613,9 @@ export async function runCli(args = process.argv.slice(2), io = {
11620
11613
  plan: parsed.values.plan,
11621
11614
  region: parsed.values.region,
11622
11615
  tokenName: parsed.values["token-name"],
11616
+ tokenScope: parsed.values["token-scope"],
11617
+ tokenExpiryDays: parsed.values["token-expiry-days"],
11618
+ rotateToken: parsed.values["rotate-token"],
11623
11619
  });
11624
11620
  case "dev":
11625
11621
  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"}