@gadicc/loom 1.36.0 → 1.38.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.
- package/README.md +25 -5
- package/esm/src/cli/localDb.js +2 -2
- package/esm/src/cli/migrationEnv.js +2 -2
- package/esm/src/cli/mod.d.ts +47 -1
- package/esm/src/cli/mod.d.ts.map +1 -1
- package/esm/src/cli/mod.js +805 -56
- package/esm/src/cli/vercelBuildEnv.d.ts.map +1 -1
- package/esm/src/cli/vercelBuildEnv.js +23 -6
- package/esm/src/cli/vercelEnvMask.d.ts +38 -0
- package/esm/src/cli/vercelEnvMask.d.ts.map +1 -0
- package/esm/src/cli/vercelEnvMask.js +136 -0
- package/esm/src/cli/vercelProjectRelease.js +2 -2
- package/esm/src/cli/vercelPulledEnv.d.ts +65 -0
- package/esm/src/cli/vercelPulledEnv.d.ts.map +1 -0
- package/esm/src/cli/vercelPulledEnv.js +132 -0
- package/package.json +2 -2
- package/script/src/cli/localDb.js +2 -2
- package/script/src/cli/migrationEnv.js +2 -2
- package/script/src/cli/mod.d.ts +47 -1
- package/script/src/cli/mod.d.ts.map +1 -1
- package/script/src/cli/mod.js +808 -56
- package/script/src/cli/vercelBuildEnv.d.ts.map +1 -1
- package/script/src/cli/vercelBuildEnv.js +23 -6
- package/script/src/cli/vercelEnvMask.d.ts +38 -0
- package/script/src/cli/vercelEnvMask.d.ts.map +1 -0
- package/script/src/cli/vercelEnvMask.js +142 -0
- package/script/src/cli/vercelProjectRelease.js +2 -2
- package/script/src/cli/vercelPulledEnv.d.ts +65 -0
- package/script/src/cli/vercelPulledEnv.d.ts.map +1 -0
- package/script/src/cli/vercelPulledEnv.js +138 -0
- package/skills/loom/SKILL.md +5 -0
- package/skills/loom/references/dependency-upgrades.md +4 -0
- package/skills/loom/references/release-safety.md +10 -3
- package/skills/loom-auth/references/secrets-and-rotation.md +2 -1
- package/skills/loom-files/references/provider-configuration.md +8 -0
- package/skills/loom-scaffold/references/greenfield-workflow.md +2 -1
- package/skills/loom-secrets/SKILL.md +27 -13
package/script/src/cli/mod.js
CHANGED
|
@@ -63,6 +63,8 @@ exports.setupGithubMigrationCredential = setupGithubMigrationCredential;
|
|
|
63
63
|
exports.setupGithubVercelRelease = setupGithubVercelRelease;
|
|
64
64
|
exports.initProject = initProject;
|
|
65
65
|
exports.addFeature = addFeature;
|
|
66
|
+
exports.planSecretsKey = planSecretsKey;
|
|
67
|
+
exports.recordedSecretsKey = recordedSecretsKey;
|
|
66
68
|
exports.generateSecretsKey = generateSecretsKey;
|
|
67
69
|
exports.fingerprintSecretsKey = fingerprintSecretsKey;
|
|
68
70
|
exports.activateSecretsKey = activateSecretsKey;
|
|
@@ -73,6 +75,7 @@ exports.addSkills = addSkills;
|
|
|
73
75
|
exports.checkProject = checkProject;
|
|
74
76
|
exports.checkProjectNetwork = checkProjectNetwork;
|
|
75
77
|
exports.formatPlainNetworkCheckLines = formatPlainNetworkCheckLines;
|
|
78
|
+
exports.resolveOutsideChange = resolveOutsideChange;
|
|
76
79
|
exports.runEnvCommand = runEnvCommand;
|
|
77
80
|
exports.runCli = runCli;
|
|
78
81
|
const node_child_process_1 = require("node:child_process");
|
|
@@ -101,6 +104,7 @@ const keyring_js_1 = require("../secrets/keyring.js");
|
|
|
101
104
|
const projectSkills_js_1 = require("./projectSkills.js");
|
|
102
105
|
const migrationEnv_js_1 = require("./migrationEnv.js");
|
|
103
106
|
const vercelBuildEnv_js_1 = require("./vercelBuildEnv.js");
|
|
107
|
+
const vercelEnvMask_js_1 = require("./vercelEnvMask.js");
|
|
104
108
|
const vercelProjectRelease_js_1 = require("./vercelProjectRelease.js");
|
|
105
109
|
const projectTooling_js_1 = require("./projectTooling.js");
|
|
106
110
|
const localDevLock_js_1 = require("./localDevLock.js");
|
|
@@ -4628,6 +4632,30 @@ async function checkPnpm11Compatibility(cwd, packageJson, npmrcText) {
|
|
|
4628
4632
|
warnings: major === null || major < 11 ? findings : [],
|
|
4629
4633
|
};
|
|
4630
4634
|
}
|
|
4635
|
+
/**
|
|
4636
|
+
* Without Corepack, Vercel picks the pnpm version from the lockfile rather than
|
|
4637
|
+
* from `packageManager`, and an `engines.pnpm` range can then reject that pnpm
|
|
4638
|
+
* with ERR_PNPM_UNSUPPORTED_ENGINE. `packageManager` already records the
|
|
4639
|
+
* intended version, so removing the range is the advice; this is a warning
|
|
4640
|
+
* only.
|
|
4641
|
+
*/
|
|
4642
|
+
function checkPnpmEnginesWithPackageManager(packageJson) {
|
|
4643
|
+
const engines = packageJson.engines;
|
|
4644
|
+
if (!packageJson.packageManager?.startsWith("pnpm@") ||
|
|
4645
|
+
typeof engines !== "object" || engines === null ||
|
|
4646
|
+
engines.pnpm === undefined) {
|
|
4647
|
+
return { issues: [], suggestions: [], warnings: [] };
|
|
4648
|
+
}
|
|
4649
|
+
return {
|
|
4650
|
+
issues: [],
|
|
4651
|
+
suggestions: [
|
|
4652
|
+
"Remove package.json#engines.pnpm so it cannot reject the pnpm version Vercel selects; keep packageManager as the project's pnpm pin.",
|
|
4653
|
+
],
|
|
4654
|
+
warnings: [
|
|
4655
|
+
"package.json sets engines.pnpm beside a pnpm packageManager pin; Vercel builds without Corepack choose pnpm from the lockfile version, which engines.pnpm can reject with ERR_PNPM_UNSUPPORTED_ENGINE.",
|
|
4656
|
+
],
|
|
4657
|
+
};
|
|
4658
|
+
}
|
|
4631
4659
|
async function getSkillsContext(cwd, packageJson, manifest) {
|
|
4632
4660
|
const tooling = await (0, projectTooling_js_1.detectProjectTooling)(cwd, manifest?.project?.tooling);
|
|
4633
4661
|
const dependencyConfig = tooling.dependencies.config;
|
|
@@ -5223,6 +5251,124 @@ function workflowStepPreparesVercelProject(block) {
|
|
|
5223
5251
|
/vercel-production-env\.json\b/.test(block) &&
|
|
5224
5252
|
/\.vercel\/project\.json\b/.test(block);
|
|
5225
5253
|
}
|
|
5254
|
+
/**
|
|
5255
|
+
* Ways a workflow runs the Loom CLI: bare `loom`, through a package runner, as
|
|
5256
|
+
* `@gadicc/loom` fetched by `npx`, `pnpm dlx`, `bunx` or Deno, or by path as
|
|
5257
|
+
* `node_modules/.bin/loom`.
|
|
5258
|
+
*/
|
|
5259
|
+
const LOOM_INVOCATION = String
|
|
5260
|
+
.raw `(?:(?:pnpm\s+(?:exec|dlx)|pnpm|npm\s+exec(?:\s+--)?|npx(?:\s+(?:-y|--yes))?|yarn(?:\s+dlx)?|bunx|deno\s+task|deno\s+run\s+-A)\s+)?(?:(?:\.\/)?node_modules\/\.bin\/loom|(?:npm:)?@gadicc\/loom(?:@[^\s]+)?|loom)`;
|
|
5261
|
+
/**
|
|
5262
|
+
* Drops YAML and shell comments so a commented-out step or command is not
|
|
5263
|
+
* mistaken for one that runs. A `#` counts as a comment only at the start of
|
|
5264
|
+
* a line or after whitespace, which leaves URL fragments alone.
|
|
5265
|
+
*/
|
|
5266
|
+
function stripWorkflowComments(text) {
|
|
5267
|
+
return text.split("\n").filter((line) => !line.trim().startsWith("#")).map((line) => line.replace(/\s#.*$/, "")).join("\n");
|
|
5268
|
+
}
|
|
5269
|
+
/** Whether a step's `if:` is literally false, so it never runs. */
|
|
5270
|
+
function workflowStepIsDisabled(block) {
|
|
5271
|
+
return /^\s*(?:-\s+)?if:\s*(?:false|\$\{\{\s*false\s*\}\})\s*$/m.test(block);
|
|
5272
|
+
}
|
|
5273
|
+
/**
|
|
5274
|
+
* File arguments of `loom db release mask-env` commands the step runs. Only a
|
|
5275
|
+
* command in command position counts, so `echo 'loom db release mask-env …'`
|
|
5276
|
+
* does not.
|
|
5277
|
+
*/
|
|
5278
|
+
function loomMaskEnvFileArguments(block) {
|
|
5279
|
+
const joined = block.replace(/\\\r?\n\s*/g, " ");
|
|
5280
|
+
const pattern = new RegExp(String
|
|
5281
|
+
.raw `(?:^\s*(?:-\s+)?(?:run:\s*)?|[;&|]\s*)(?:[A-Za-z_][A-Za-z0-9_]*=\S*\s+)*${LOOM_INVOCATION}\s+db\s+release\s+mask-env\s+("[^"]*"|'[^']*'|[^\s;&|]+)`, "gm");
|
|
5282
|
+
return [...joined.matchAll(pattern)].map((match) => match[1].replace(/^(["'])(.*)\1$/, "$2"));
|
|
5283
|
+
}
|
|
5284
|
+
/**
|
|
5285
|
+
* The env file a `vercel pull` step writes, relative to `.vercel/`, or `null`
|
|
5286
|
+
* when the environment is computed at run time.
|
|
5287
|
+
*/
|
|
5288
|
+
function pulledVercelEnvFileName(block) {
|
|
5289
|
+
const joined = block.replace(/\\\r?\n\s*/g, " ");
|
|
5290
|
+
const environment = joined.match(/\s--environment(?:=|\s+)(["']?)([^\s"']+)\1/)?.[2] ?? (/\s--prod\b/.test(joined) ? "production" : "development");
|
|
5291
|
+
return /[$]/.test(environment) ? null : `.env.${environment}.local`;
|
|
5292
|
+
}
|
|
5293
|
+
/**
|
|
5294
|
+
* Whether masking `file` covers the file a pull wrote. A file named through a
|
|
5295
|
+
* shell variable (such as a copy in `$RUNNER_TEMP`) cannot be checked
|
|
5296
|
+
* statically and is accepted rather than reported.
|
|
5297
|
+
*/
|
|
5298
|
+
function maskedFileCoversPull(file, pulledFile) {
|
|
5299
|
+
if (file.includes("$"))
|
|
5300
|
+
return true;
|
|
5301
|
+
if (pulledFile === null) {
|
|
5302
|
+
return /(?:^|\/)\.vercel\/\.env\.[^/]+\.local$/.test(file);
|
|
5303
|
+
}
|
|
5304
|
+
return file === `.vercel/${pulledFile}` ||
|
|
5305
|
+
file.endsWith(`/.vercel/${pulledFile}`);
|
|
5306
|
+
}
|
|
5307
|
+
/**
|
|
5308
|
+
* `.vercel/.env.*` paths an inline `::add-mask::` step names. Segments such as
|
|
5309
|
+
* `${VERCEL_TARGET_ENV}` are kept, so the path reads as a shell variable.
|
|
5310
|
+
*/
|
|
5311
|
+
function inlineMaskedVercelEnvFiles(block) {
|
|
5312
|
+
if (!block.includes("::add-mask::"))
|
|
5313
|
+
return [];
|
|
5314
|
+
return [
|
|
5315
|
+
...block.matchAll(/[^\s"'`=]*\.vercel\/\.env\.(?:[\w.-]|\$\{[A-Za-z_]\w*\}|\$[A-Za-z_]\w*)+/g),
|
|
5316
|
+
].map((match) => match[0].replace(/[.-]+$/, ""));
|
|
5317
|
+
}
|
|
5318
|
+
/**
|
|
5319
|
+
* Checks that each `vercel pull` step is followed, in the same job, by an
|
|
5320
|
+
* enabled step that masks the file it wrote. Reports pulls that nothing masks,
|
|
5321
|
+
* and an inline `::add-mask::` script that could use `loom db release
|
|
5322
|
+
* mask-env` instead (also when the env file came from another Loom command).
|
|
5323
|
+
*/
|
|
5324
|
+
function checkPulledVercelEnvMasking(workflowText) {
|
|
5325
|
+
let unmaskedPull = false;
|
|
5326
|
+
let inlineMaskBlock;
|
|
5327
|
+
let loomMasksAnyVercelEnv = false;
|
|
5328
|
+
for (const job of getGithubWorkflowJobBlocks(workflowText)) {
|
|
5329
|
+
const steps = job.stepBlocks.map(stripWorkflowComments).filter((block) => !workflowStepIsDisabled(block));
|
|
5330
|
+
for (const block of steps) {
|
|
5331
|
+
if (loomMaskEnvFileArguments(block).some((file) => maskedFileCoversPull(file, null)))
|
|
5332
|
+
loomMasksAnyVercelEnv = true;
|
|
5333
|
+
if (!inlineMaskBlock && !loomMaskEnvFileArguments(block).length &&
|
|
5334
|
+
inlineMaskedVercelEnvFiles(block).length)
|
|
5335
|
+
inlineMaskBlock = block;
|
|
5336
|
+
}
|
|
5337
|
+
steps.forEach((block, index) => {
|
|
5338
|
+
if (!workflowStepUsesVercelCommand(block, "pull"))
|
|
5339
|
+
return;
|
|
5340
|
+
const pulledFile = pulledVercelEnvFileName(block);
|
|
5341
|
+
const later = steps.slice(index + 1);
|
|
5342
|
+
if (later.some((step) => loomMaskEnvFileArguments(step).some((file) => maskedFileCoversPull(file, pulledFile))))
|
|
5343
|
+
return;
|
|
5344
|
+
if (later.some((step) => inlineMaskedVercelEnvFiles(step).some((file) => maskedFileCoversPull(file, pulledFile))))
|
|
5345
|
+
return;
|
|
5346
|
+
unmaskedPull = true;
|
|
5347
|
+
});
|
|
5348
|
+
}
|
|
5349
|
+
return {
|
|
5350
|
+
inlineMaskBlock: loomMasksAnyVercelEnv ? undefined : inlineMaskBlock,
|
|
5351
|
+
unmaskedPull,
|
|
5352
|
+
};
|
|
5353
|
+
}
|
|
5354
|
+
/**
|
|
5355
|
+
* The replacement for an inline masking step, invoking Loom the way the
|
|
5356
|
+
* workflow already does (for example `pnpm exec loom` or `npx @gadicc/loom`)
|
|
5357
|
+
* so the suggestion follows the app's tooling instead of assuming one.
|
|
5358
|
+
*/
|
|
5359
|
+
function loomMaskEnvWorkflowStep(workflowText, inlineMaskBlock) {
|
|
5360
|
+
const envFile = inlineMaskedVercelEnvFiles(inlineMaskBlock)[0] ??
|
|
5361
|
+
".vercel/.env.production.local";
|
|
5362
|
+
const invocation = workflowText.match(new RegExp(String.raw `(?:^|[\s;&|(])(${LOOM_INVOCATION})\s+(?:db|check|init|dev)\b`, "m"))?.[1]?.replace(/\s+/g, " ") ??
|
|
5363
|
+
// No Loom command yet: follow the workflow's pnpm usage when it has one.
|
|
5364
|
+
(/(?:^|[\s;&|(])pnpm\s+(?:install|exec|run|dlx)\b/m.test(workflowText)
|
|
5365
|
+
? "pnpm exec loom"
|
|
5366
|
+
: "loom");
|
|
5367
|
+
return [
|
|
5368
|
+
" - name: Mask pulled Vercel values",
|
|
5369
|
+
` run: ${invocation} db release mask-env ${envFile}`,
|
|
5370
|
+
].join("\n");
|
|
5371
|
+
}
|
|
5226
5372
|
function workflowStepPreparesVercelBuildEnv(block) {
|
|
5227
5373
|
return (/\bvercel-build-env(?:\.mjs)?\b[\s\S]*\bprepare\b/.test(block) ||
|
|
5228
5374
|
/\bloom\b[\s\S]*\bdb\s+release\s+prepare-build-env\b/.test(block));
|
|
@@ -5676,11 +5822,15 @@ async function checkGithubActionsWorkflows(cwd) {
|
|
|
5676
5822
|
warnings.push(`GitHub Actions workflow exposes VERCEL_TOKEN for an entire workflow or job: ${relativePath}`);
|
|
5677
5823
|
suggestions.add("Keep VERCEL_TOKEN in a protected GitHub Environment and bind it only on steps that call Vercel.");
|
|
5678
5824
|
}
|
|
5679
|
-
const
|
|
5680
|
-
|
|
5681
|
-
if (pullsVercelEnv && !masksPulledVercelEnv) {
|
|
5825
|
+
const masking = checkPulledVercelEnvMasking(normalized);
|
|
5826
|
+
if (masking.unmaskedPull) {
|
|
5682
5827
|
warnings.push(`GitHub Actions workflow pulls Vercel secrets without masking the downloaded values: ${relativePath}`);
|
|
5683
|
-
suggestions.add("Immediately after `vercel pull`,
|
|
5828
|
+
suggestions.add("Immediately after `vercel pull`, add a step in the same job that runs `loom db release mask-env .vercel/.env.<target>.local` so GitHub masks every secret-capable pulled value.");
|
|
5829
|
+
}
|
|
5830
|
+
if (masking.inlineMaskBlock) {
|
|
5831
|
+
warnings.push(`GitHub Actions workflow masks pulled Vercel values with its own \`::add-mask::\` script instead of \`loom db release mask-env\`: ${relativePath}`);
|
|
5832
|
+
suggestions.add("Replace the inline Vercel masking step with Loom's shared rule, which reads the file directly, skips only short and public-by-construction values, and masks multi-line values line by line:\n" +
|
|
5833
|
+
loomMaskEnvWorkflowStep(stripWorkflowComments(normalized), masking.inlineMaskBlock));
|
|
5684
5834
|
}
|
|
5685
5835
|
}
|
|
5686
5836
|
return {
|
|
@@ -8059,16 +8209,29 @@ async function listVercelEnvironmentNames(cwd, commandRunner, env, vercelCommand
|
|
|
8059
8209
|
}
|
|
8060
8210
|
return result.stdout;
|
|
8061
8211
|
}
|
|
8062
|
-
|
|
8063
|
-
|
|
8212
|
+
/**
|
|
8213
|
+
* What a failed Vercel CLI call said. In an agent session the CLI reports
|
|
8214
|
+
* errors as JSON on stdout. Vercel does not echo a value it was given, but a
|
|
8215
|
+
* long one is masked anyway, in case a later version does.
|
|
8216
|
+
*/
|
|
8217
|
+
function vercelFailureDetail(result, value) {
|
|
8218
|
+
const detail = result.stderr.trim() || result.stdout.trim() ||
|
|
8219
|
+
`exit code ${result.code}`;
|
|
8220
|
+
return value.length >= 16 ? detail.split(value).join("[redacted]") : detail;
|
|
8221
|
+
}
|
|
8222
|
+
async function addVercelEnvValue(cwd, commandRunner, env, vercelCommand, name, value, environment, extraArgs = []) {
|
|
8223
|
+
// The value goes on stdin, never into the arguments, where the process
|
|
8224
|
+
// list and shell history would show it.
|
|
8225
|
+
const result = await commandRunner(vercelCommand, ["env", "add", name, environment, ...extraArgs], { cwd, env, input: `${value}\n`, stdio: "pipe" });
|
|
8064
8226
|
if (result.code !== 0) {
|
|
8065
|
-
throw new Error(`Could not add ${name} to Vercel ${environment}: ${result
|
|
8227
|
+
throw new Error(`Could not add ${name} to Vercel ${environment}: ${vercelFailureDetail(result, value)}`);
|
|
8066
8228
|
}
|
|
8067
8229
|
}
|
|
8068
8230
|
async function updateVercelEnvValue(cwd, commandRunner, env, vercelCommand, name, value, environment) {
|
|
8231
|
+
// No type flag: `env update` keeps the variable's existing type.
|
|
8069
8232
|
const result = await commandRunner(vercelCommand, ["env", "update", name, environment, "--yes"], { cwd, env, input: `${value}\n`, stdio: "pipe" });
|
|
8070
8233
|
if (result.code !== 0) {
|
|
8071
|
-
throw new Error(`Could not update ${name} in Vercel ${environment}: ${result
|
|
8234
|
+
throw new Error(`Could not update ${name} in Vercel ${environment}: ${vercelFailureDetail(result, value)}`);
|
|
8072
8235
|
}
|
|
8073
8236
|
}
|
|
8074
8237
|
async function promptForVercelSecret(cwd, commandRunner, env, vercelCommand, name, environment) {
|
|
@@ -8106,10 +8269,38 @@ function buildVercelFilesEnvListArgs(environment, project) {
|
|
|
8106
8269
|
}
|
|
8107
8270
|
function withoutInheritedVercelProject(env) {
|
|
8108
8271
|
const result = { ...env };
|
|
8109
|
-
|
|
8110
|
-
|
|
8272
|
+
// The Vercel CLI still honours the older NOW_* names too.
|
|
8273
|
+
for (const name of [
|
|
8274
|
+
"VERCEL_ORG_ID",
|
|
8275
|
+
"VERCEL_PROJECT_ID",
|
|
8276
|
+
"NOW_ORG_ID",
|
|
8277
|
+
"NOW_PROJECT_ID",
|
|
8278
|
+
]) {
|
|
8279
|
+
delete result[name];
|
|
8280
|
+
}
|
|
8111
8281
|
return result;
|
|
8112
8282
|
}
|
|
8283
|
+
/**
|
|
8284
|
+
* Which of `names` Vercel stores as Secrets for `environment`, or null when
|
|
8285
|
+
* the JSON listing is unavailable. A Secret reads back empty, so it looks like
|
|
8286
|
+
* drift, but `vercel env update` keeps a variable's type and cannot fix it.
|
|
8287
|
+
*/
|
|
8288
|
+
async function findVercelFilesValuesStoredAsSecrets(cwd, commandRunner, env, vercelCommand, environment, listArgs, names) {
|
|
8289
|
+
const result = await commandRunner(vercelCommand, [...listArgs, "--format", "json"], { cwd, env, stdio: "pipe" });
|
|
8290
|
+
if (result.code !== 0)
|
|
8291
|
+
return null;
|
|
8292
|
+
const variables = parseVercelEnvListing(result.stdout);
|
|
8293
|
+
if (!variables)
|
|
8294
|
+
return null;
|
|
8295
|
+
return names.filter((name) => variables.some((variable) => variable.key === name && variable.secret &&
|
|
8296
|
+
variable.targets.includes(environment)));
|
|
8297
|
+
}
|
|
8298
|
+
function filesSecretTypeProblem(environment, names) {
|
|
8299
|
+
return `Vercel ${environment} stores ${names.join(", ")} as Secrets, so their values cannot be read back, and \`vercel env update\` keeps a Secret a Secret.`;
|
|
8300
|
+
}
|
|
8301
|
+
function filesSecretTypeFix(environment) {
|
|
8302
|
+
return `Remove them from Vercel ${environment}, then run \`loom files r2 setup\` to add them back as readable values.`;
|
|
8303
|
+
}
|
|
8113
8304
|
async function readVercelFilesNonSecretValues(cwd, commandRunner, env, vercelCommand, environment) {
|
|
8114
8305
|
const link = await readVercelProjectLink(cwd);
|
|
8115
8306
|
if (!link.linked || !link.orgId || !link.projectId)
|
|
@@ -8192,11 +8383,11 @@ async function ensureMinioBucket(cwd, commandRunner, env, endpoint, bucket, acce
|
|
|
8192
8383
|
* is read in raw mode so it is never echoed. Refuses when stdin is not a
|
|
8193
8384
|
* terminal, with the caller's explanation of what to do instead.
|
|
8194
8385
|
*/
|
|
8195
|
-
async function promptForTerminalValue(question, secret, messages) {
|
|
8386
|
+
async function promptForTerminalValue(question, secret, messages, options = {}) {
|
|
8196
8387
|
if (!node_process_1.default.stdin.isTTY) {
|
|
8197
8388
|
throw new Error(messages.notInteractive);
|
|
8198
8389
|
}
|
|
8199
|
-
if (!secret) {
|
|
8390
|
+
if (!secret && !options.rawEcho) {
|
|
8200
8391
|
const input = (0, promises_2.createInterface)({
|
|
8201
8392
|
input: node_process_1.default.stdin,
|
|
8202
8393
|
output: node_process_1.default.stderr,
|
|
@@ -8230,9 +8421,13 @@ async function promptForTerminalValue(question, secret, messages) {
|
|
|
8230
8421
|
return;
|
|
8231
8422
|
}
|
|
8232
8423
|
if (character === "\u007f" || character === "\b") {
|
|
8424
|
+
if (options.rawEcho && value)
|
|
8425
|
+
node_process_1.default.stderr.write("\b \b");
|
|
8233
8426
|
value = value.slice(0, -1);
|
|
8234
8427
|
}
|
|
8235
8428
|
else {
|
|
8429
|
+
if (options.rawEcho)
|
|
8430
|
+
node_process_1.default.stderr.write(character);
|
|
8236
8431
|
value += character;
|
|
8237
8432
|
}
|
|
8238
8433
|
}
|
|
@@ -8910,6 +9105,12 @@ async function setupCloudflareR2(cwd, options = {}) {
|
|
|
8910
9105
|
throw new Error(`Could not inspect existing non-secret Files values in Vercel ${environment}.`);
|
|
8911
9106
|
}
|
|
8912
9107
|
const drift = existingNonSecretNames.filter((name) => actualValues[name] !== nonSecretValues[name]);
|
|
9108
|
+
const storedAsSecrets = drift.length
|
|
9109
|
+
? await findVercelFilesValuesStoredAsSecrets(cwd, commandRunner, providerEnv, vercelCli.command, environment, ["env", "ls", environment], drift)
|
|
9110
|
+
: null;
|
|
9111
|
+
if (storedAsSecrets?.length) {
|
|
9112
|
+
throw new Error(`${filesSecretTypeProblem(environment, storedAsSecrets)} ${filesSecretTypeFix(environment)}`);
|
|
9113
|
+
}
|
|
8913
9114
|
if (drift.length && !options.repair) {
|
|
8914
9115
|
throw new Error(`Vercel ${environment} non-secret Files values differ from the declared R2 policy: ${drift.join(", ")}. Review the drift and rerun with --repair; credentials will not be changed.`);
|
|
8915
9116
|
}
|
|
@@ -8919,7 +9120,11 @@ async function setupCloudflareR2(cwd, options = {}) {
|
|
|
8919
9120
|
}
|
|
8920
9121
|
for (const [name, value] of Object.entries(nonSecretValues)) {
|
|
8921
9122
|
if (!hasExactEnvName(listing, name)) {
|
|
8922
|
-
await addVercelEnvValue(cwd, commandRunner, providerEnv, vercelCli.command, name, value, environment
|
|
9123
|
+
await addVercelEnvValue(cwd, commandRunner, providerEnv, vercelCli.command, name, value, environment,
|
|
9124
|
+
// Vercel CLI stores a Production or Preview value read from
|
|
9125
|
+
// stdin as a Secret unless told otherwise, and the env-run probe
|
|
9126
|
+
// and release env policies must be able to read these back.
|
|
9127
|
+
["--no-sensitive", "--yes"]);
|
|
8923
9128
|
listing += `\n${name}`;
|
|
8924
9129
|
}
|
|
8925
9130
|
}
|
|
@@ -9027,6 +9232,9 @@ async function readVercelProjectLink(cwd) {
|
|
|
9027
9232
|
linked: true,
|
|
9028
9233
|
orgId,
|
|
9029
9234
|
projectId,
|
|
9235
|
+
projectName: typeof project.projectName === "string"
|
|
9236
|
+
? project.projectName
|
|
9237
|
+
: null,
|
|
9030
9238
|
relativePath,
|
|
9031
9239
|
};
|
|
9032
9240
|
}
|
|
@@ -9949,6 +10157,23 @@ function checkFilesNetworkFeature(context) {
|
|
|
9949
10157
|
FILES_S3_FORCE_PATH_STYLE: String(provider.forcePathStyle ?? false),
|
|
9950
10158
|
};
|
|
9951
10159
|
const drift = Object.entries(expectedValues).filter(([name, value]) => actualValues[name] !== value).map(([name]) => name);
|
|
10160
|
+
const storedAsSecrets = drift.length
|
|
10161
|
+
? await findVercelFilesValuesStoredAsSecrets(context.cwd, context.commandRunner, withoutInheritedVercelProject(context.env), state.vercelCommand, environment, buildVercelFilesEnvListArgs(environment, state.vercelProject), drift)
|
|
10162
|
+
: null;
|
|
10163
|
+
if (storedAsSecrets?.length) {
|
|
10164
|
+
const otherDrift = drift.filter((name) => !storedAsSecrets.includes(name));
|
|
10165
|
+
return networkCheckResult("issue", `Vercel ${environment} stores non-secret Files values as Secrets: ${storedAsSecrets.join(", ")}.`, {
|
|
10166
|
+
issues: [
|
|
10167
|
+
filesSecretTypeProblem(environment, storedAsSecrets),
|
|
10168
|
+
...(otherDrift.length
|
|
10169
|
+
? [
|
|
10170
|
+
`Vercel ${environment} has incompatible non-secret Files R2 values: ${otherDrift.join(", ")}.`,
|
|
10171
|
+
]
|
|
10172
|
+
: []),
|
|
10173
|
+
],
|
|
10174
|
+
suggestions: [filesSecretTypeFix(environment)],
|
|
10175
|
+
});
|
|
10176
|
+
}
|
|
9952
10177
|
return drift.length
|
|
9953
10178
|
? networkCheckResult("issue", `Vercel ${environment} Files values drift from loom.json: ${drift.join(", ")}.`, {
|
|
9954
10179
|
issues: [
|
|
@@ -10934,7 +11159,7 @@ async function applySecretsFeature(cwd, framework, manifest, activate, options =
|
|
|
10934
11159
|
changedFiles.push(...localKey.changedFiles);
|
|
10935
11160
|
notes.push(...localKey.notes);
|
|
10936
11161
|
if (!Array.isArray(config.keys.production) || !config.keys.production.length) {
|
|
10937
|
-
notes.push("No production key is recorded yet. Before the first production deploy, an operator runs `loom secrets keygen` in their own terminal; an agent must not run it.");
|
|
11162
|
+
notes.push("No production key is recorded yet. Before the first production deploy, an operator runs `loom secrets keygen` in their own terminal; an agent must not run it. On a linked Vercel project it offers to add the key and pointer there.");
|
|
10938
11163
|
}
|
|
10939
11164
|
}
|
|
10940
11165
|
feature.config = mergeSecretsConfig(currentFeature?.config, config);
|
|
@@ -13789,7 +14014,7 @@ async function checkSecretsFeature(cwd, framework, manifest, options) {
|
|
|
13789
14014
|
}
|
|
13790
14015
|
if (Array.isArray(config.keys.production) && config.keys.production.length === 0) {
|
|
13791
14016
|
releaseBlocking("No production secrets key is recorded in loom.json, so production would run with unverified keys.");
|
|
13792
|
-
suggestions.add("Have an operator run `loom secrets keygen` in their own terminal, then commit the recorded fingerprint.");
|
|
14017
|
+
suggestions.add("Have an operator run `loom secrets keygen` in their own terminal, then commit the recorded fingerprint. On a linked Vercel project it offers to add the key there too.");
|
|
13793
14018
|
}
|
|
13794
14019
|
const policyText = await readTextIfExists((0, node_path_1.join)(cwd, VERCEL_PRODUCTION_ENV_POLICY_PATH));
|
|
13795
14020
|
if (policyText !== null) {
|
|
@@ -14024,15 +14249,18 @@ function recordedSecretKeys(config, environment) {
|
|
|
14024
14249
|
return recorded;
|
|
14025
14250
|
}
|
|
14026
14251
|
/** Validates a changed key list, then records it in loom.json. */
|
|
14027
|
-
|
|
14028
|
-
if (keys.length)
|
|
14029
|
-
|
|
14030
|
-
|
|
14031
|
-
|
|
14032
|
-
catch (error) {
|
|
14033
|
-
throw new Error(`The ${environment} key list in loom.json would be invalid: ${error.message}`);
|
|
14034
|
-
}
|
|
14252
|
+
function validateSecretKeys(environment, keys) {
|
|
14253
|
+
if (!keys.length)
|
|
14254
|
+
return;
|
|
14255
|
+
try {
|
|
14256
|
+
(0, fingerprint_js_1.parseExpectedSecretKeys)(keys);
|
|
14035
14257
|
}
|
|
14258
|
+
catch (error) {
|
|
14259
|
+
throw new Error(`The ${environment} key list in loom.json would be invalid: ${error.message}`);
|
|
14260
|
+
}
|
|
14261
|
+
}
|
|
14262
|
+
async function writeSecretKeys(cwd, loaded, environment, keys) {
|
|
14263
|
+
validateSecretKeys(environment, keys);
|
|
14036
14264
|
// Replaces this one list and nothing else: any other property a user keeps
|
|
14037
14265
|
// under `config` or `config.keys` is theirs, and stays.
|
|
14038
14266
|
const existing = isJsonObject(loaded.feature.config)
|
|
@@ -14050,6 +14278,49 @@ async function writeSecretKeys(cwd, loaded, environment, keys) {
|
|
|
14050
14278
|
? ["loom.json"]
|
|
14051
14279
|
: [];
|
|
14052
14280
|
}
|
|
14281
|
+
function nextSecretsKey(config, environment) {
|
|
14282
|
+
const current = recordedSecretKeys(config, environment);
|
|
14283
|
+
const id = current.reduce((highest, key) => (0, keyring_js_1.isSecretKeyId)(key?.id) ? Math.max(highest, key.id) : highest, 0) + 1;
|
|
14284
|
+
const state = current.some((key) => key?.state === "active")
|
|
14285
|
+
? "decrypt-only"
|
|
14286
|
+
: "active";
|
|
14287
|
+
return { current, id, state };
|
|
14288
|
+
}
|
|
14289
|
+
/**
|
|
14290
|
+
* The version, state and variable names `generateSecretsKey` would use next,
|
|
14291
|
+
* without generating or recording anything.
|
|
14292
|
+
*/
|
|
14293
|
+
async function planSecretsKey(cwd, environment = "production") {
|
|
14294
|
+
const loaded = await readActiveSecretsFeature(cwd);
|
|
14295
|
+
const { id, state } = nextSecretsKey(loaded.config, environment);
|
|
14296
|
+
return {
|
|
14297
|
+
activeKeyName: loaded.config.env.activeKeyName,
|
|
14298
|
+
id,
|
|
14299
|
+
state,
|
|
14300
|
+
variableName: `${loaded.config.env.keyPrefix}${id}`,
|
|
14301
|
+
};
|
|
14302
|
+
}
|
|
14303
|
+
/**
|
|
14304
|
+
* A recorded key that is not retired, with its variable names, for putting it
|
|
14305
|
+
* on a deployment platform. Refuses a version that is not listed or retired.
|
|
14306
|
+
*/
|
|
14307
|
+
async function recordedSecretsKey(cwd, id, environment = "production") {
|
|
14308
|
+
const loaded = await readActiveSecretsFeature(cwd);
|
|
14309
|
+
const key = recordedSecretKeys(loaded.config, environment).find((entry) => entry?.id === id);
|
|
14310
|
+
if (!key) {
|
|
14311
|
+
throw new Error(`Key version ${id} is not listed for ${environment} in loom.json.`);
|
|
14312
|
+
}
|
|
14313
|
+
if (key.state === "retired") {
|
|
14314
|
+
throw new Error(`Key version ${id} is retired for ${environment}.`);
|
|
14315
|
+
}
|
|
14316
|
+
return {
|
|
14317
|
+
activeKeyName: loaded.config.env.activeKeyName,
|
|
14318
|
+
fingerprint: key.fingerprint,
|
|
14319
|
+
id,
|
|
14320
|
+
state: key.state,
|
|
14321
|
+
variableName: `${loaded.config.env.keyPrefix}${id}`,
|
|
14322
|
+
};
|
|
14323
|
+
}
|
|
14053
14324
|
/**
|
|
14054
14325
|
* Generates a key for a deployed environment and records its fingerprint in
|
|
14055
14326
|
* loom.json: `active` when the environment has no active key, otherwise
|
|
@@ -14063,11 +14334,7 @@ async function writeSecretKeys(cwd, loaded, environment, keys) {
|
|
|
14063
14334
|
async function generateSecretsKey(cwd, options = {}) {
|
|
14064
14335
|
const environment = options.environment ?? "production";
|
|
14065
14336
|
const loaded = await readActiveSecretsFeature(cwd);
|
|
14066
|
-
const current =
|
|
14067
|
-
const id = current.reduce((highest, key) => (0, keyring_js_1.isSecretKeyId)(key?.id) ? Math.max(highest, key.id) : highest, 0) + 1;
|
|
14068
|
-
const state = current.some((key) => key?.state === "active")
|
|
14069
|
-
? "decrypt-only"
|
|
14070
|
-
: "active";
|
|
14337
|
+
const { current, id, state } = nextSecretsKey(loaded.config, environment);
|
|
14071
14338
|
const key = globalThis.crypto.getRandomValues(new Uint8Array(keyring_js_1.SECRETS_KEY_BYTES));
|
|
14072
14339
|
const fingerprint = await (0, fingerprint_js_1.secretKeyFingerprint)(key);
|
|
14073
14340
|
const changedFiles = await writeSecretKeys(cwd, loaded, environment, [
|
|
@@ -14097,8 +14364,12 @@ async function fingerprintSecretsKey(value) {
|
|
|
14097
14364
|
/**
|
|
14098
14365
|
* Marks a recorded key `active` in loom.json and the previously active key
|
|
14099
14366
|
* `decrypt-only`. Refuses a version that is not listed or is retired.
|
|
14367
|
+
*
|
|
14368
|
+
* `beforeWrite` runs once those checks pass and before loom.json changes, so
|
|
14369
|
+
* the platform's pointer can be moved first; if it throws, loom.json is left
|
|
14370
|
+
* as it was.
|
|
14100
14371
|
*/
|
|
14101
|
-
async function activateSecretsKey(cwd, id, environment = "production") {
|
|
14372
|
+
async function activateSecretsKey(cwd, id, environment = "production", options = {}) {
|
|
14102
14373
|
const loaded = await readActiveSecretsFeature(cwd);
|
|
14103
14374
|
const current = recordedSecretKeys(loaded.config, environment);
|
|
14104
14375
|
const target = current.find((key) => key?.id === id);
|
|
@@ -14108,11 +14379,36 @@ async function activateSecretsKey(cwd, id, environment = "production") {
|
|
|
14108
14379
|
if (target.state === "retired") {
|
|
14109
14380
|
throw new Error(`Key version ${id} is retired and cannot be activated. Generate a new key with \`loom secrets keygen\`.`);
|
|
14110
14381
|
}
|
|
14111
|
-
const
|
|
14382
|
+
const next = current.map((key) => key?.id === id
|
|
14112
14383
|
? { ...key, state: "active" }
|
|
14113
14384
|
: key?.state === "active"
|
|
14114
14385
|
? { ...key, state: "decrypt-only" }
|
|
14115
|
-
: key)
|
|
14386
|
+
: key);
|
|
14387
|
+
// Checked before the hook, which may change a deployment platform: that
|
|
14388
|
+
// must not happen for a list that could not then be written.
|
|
14389
|
+
validateSecretKeys(environment, next);
|
|
14390
|
+
if (!options.beforeWrite) {
|
|
14391
|
+
return {
|
|
14392
|
+
activeKeyName: loaded.config.env.activeKeyName,
|
|
14393
|
+
changedFiles: await writeSecretKeys(cwd, loaded, environment, next),
|
|
14394
|
+
environment,
|
|
14395
|
+
id,
|
|
14396
|
+
};
|
|
14397
|
+
}
|
|
14398
|
+
const changedOutside = await options.beforeWrite({
|
|
14399
|
+
activeKeyName: loaded.config.env.activeKeyName,
|
|
14400
|
+
id,
|
|
14401
|
+
variableName: `${loaded.config.env.keyPrefix}${id}`,
|
|
14402
|
+
});
|
|
14403
|
+
let changedFiles;
|
|
14404
|
+
try {
|
|
14405
|
+
changedFiles = await writeSecretKeys(cwd, loaded, environment, next);
|
|
14406
|
+
}
|
|
14407
|
+
catch (error) {
|
|
14408
|
+
if (!changedOutside)
|
|
14409
|
+
throw error;
|
|
14410
|
+
throw new Error(`${error.message} The platform was already changed for key version ${id}; fix loom.json and run this again, or put the platform back.`);
|
|
14411
|
+
}
|
|
14116
14412
|
return {
|
|
14117
14413
|
activeKeyName: loaded.config.env.activeKeyName,
|
|
14118
14414
|
changedFiles,
|
|
@@ -14288,6 +14584,11 @@ async function checkProject(cwd, env = node_process_1.default.env, options = {})
|
|
|
14288
14584
|
for (const suggestion of pnpmCompatibilityCheck.suggestions) {
|
|
14289
14585
|
suggestions.add(suggestion);
|
|
14290
14586
|
}
|
|
14587
|
+
const pnpmEnginesCheck = checkPnpmEnginesWithPackageManager(packageJson);
|
|
14588
|
+
warnings.push(...pnpmEnginesCheck.warnings);
|
|
14589
|
+
for (const suggestion of pnpmEnginesCheck.suggestions) {
|
|
14590
|
+
suggestions.add(suggestion);
|
|
14591
|
+
}
|
|
14291
14592
|
const framework = await detectFramework(cwd, packageJson);
|
|
14292
14593
|
const dependency = packageJson.dependencies?.[exports.LOOM_DEPENDENCY];
|
|
14293
14594
|
if (!dependency) {
|
|
@@ -14946,9 +15247,10 @@ function printHelp({ out }) {
|
|
|
14946
15247
|
out(" files r2 check Verify R2 buckets/account/privacy, Vercel env scoping, local storage, and Files adapter wiring.");
|
|
14947
15248
|
out(" api-keys integrate jobs Record an explicit API-key jobs integration after the route has session/admin authorization.");
|
|
14948
15249
|
out(" api-keys retention enable|disable Record API-key audit cleanup policy; scheduling remains app-owned.");
|
|
14949
|
-
out(" secrets keygen Generate a production secrets key, print it once to a terminal, and record its fingerprint in loom.json.");
|
|
15250
|
+
out(" secrets keygen Generate a production secrets key, print it once to a terminal, and record its fingerprint in loom.json. On a linked Vercel project it offers to add the key there.");
|
|
15251
|
+
out(" secrets push <id> Add a recorded secrets key to Vercel Production as a Secret, from a copy pasted back and checked against loom.json.");
|
|
14950
15252
|
out(" secrets fingerprint Read a secrets key from a hidden terminal prompt and print only its fingerprint.");
|
|
14951
|
-
out(" secrets activate <id> Record a listed secrets key as the active one; the previous active key becomes decrypt-only.");
|
|
15253
|
+
out(" secrets activate <id> Record a listed secrets key as the active one; the previous active key becomes decrypt-only. On a linked Vercel project it offers to move the pointer there first.");
|
|
14952
15254
|
out(" secrets retire <id> Record a secrets key that nothing needs any more as retired.");
|
|
14953
15255
|
out(" status Show the Loom package, manifest, active features, local-dev state, and project skill state.");
|
|
14954
15256
|
out(" check Validate project bootstrap, managed guidance, features, skill locks, caches, and links.");
|
|
@@ -14968,6 +15270,7 @@ function printHelp({ out }) {
|
|
|
14968
15270
|
out(" db release trust-apply <plan> <approval-sha256> Apply a reviewed Trusted Sources plan.");
|
|
14969
15271
|
out(" db release trust-check <plan> Verify the reviewed Trusted Sources plan is active.");
|
|
14970
15272
|
out(" db release prepare-build-env <env> <metadata> <policy> <manifest> Prepare metadata-backed placeholders for an external Vercel build.");
|
|
15273
|
+
out(" db release mask-env <env> Print GitHub Actions ::add-mask:: commands for secret-capable pulled Vercel values.");
|
|
14971
15274
|
out(" db release prepare-vercel-project production <env> <metadata> <project> Materialize project-scoped Production release inputs.");
|
|
14972
15275
|
out(" db release promote-vercel <deployment-id> Promote an exact READY Production deployment with project-scoped auth.");
|
|
14973
15276
|
out(" db release verify-build-env <output> <manifest> [deployment-root] Reject build-only placeholders in a deployable Vercel artifact.");
|
|
@@ -14981,6 +15284,7 @@ function printHelp({ out }) {
|
|
|
14981
15284
|
out(" --network Run registered network checks after the local project checks.");
|
|
14982
15285
|
out(" --production Treat local Loom dev overrides and local lockfile resolutions as release-blocking check failures.");
|
|
14983
15286
|
out(" --no-progress Disable the interactive network progress renderer.");
|
|
15287
|
+
out(" --vercel, --no-vercel For secrets keygen and activate: change the linked Vercel project without asking, or never. Without either, only a person at a terminal is asked.");
|
|
14984
15288
|
out(" --local-db-host <host> Local PostgreSQL host (default: db.localtest.me).");
|
|
14985
15289
|
out(" --local-db-port <port> Local PostgreSQL port (default: 5432).");
|
|
14986
15290
|
out(" --replace-local-target Replace an existing development URL during local DB setup.");
|
|
@@ -15053,6 +15357,29 @@ async function runApiKeys(cwd, command, target, options, io) {
|
|
|
15053
15357
|
io.out(`Note: ${note}`);
|
|
15054
15358
|
return 0;
|
|
15055
15359
|
}
|
|
15360
|
+
/**
|
|
15361
|
+
* Whether what follows `loom secrets push` is only a version number and
|
|
15362
|
+
* options Loom knows. Anything else may be a key typed in the wrong place,
|
|
15363
|
+
* which the argument parser would quote back in its error.
|
|
15364
|
+
*/
|
|
15365
|
+
function secretsPushArgumentsAreSafe(rest) {
|
|
15366
|
+
const flags = ["--vercel", "--no-vercel", "--no-color", "--help", "-h"];
|
|
15367
|
+
const withValue = ["--cwd", "--environment"];
|
|
15368
|
+
for (let index = 0; index < rest.length; index += 1) {
|
|
15369
|
+
const arg = rest[index];
|
|
15370
|
+
if (/^[1-9][0-9]{0,8}$/.test(arg) || flags.includes(arg))
|
|
15371
|
+
continue;
|
|
15372
|
+
if (withValue.some((name) => arg.startsWith(`${name}=`)))
|
|
15373
|
+
continue;
|
|
15374
|
+
if (withValue.includes(arg) && index + 1 < rest.length) {
|
|
15375
|
+
index += 1;
|
|
15376
|
+
continue;
|
|
15377
|
+
}
|
|
15378
|
+
return false;
|
|
15379
|
+
}
|
|
15380
|
+
return true;
|
|
15381
|
+
}
|
|
15382
|
+
const SECRETS_PUSH_ARGUMENT_REFUSAL = "loom secrets push takes only a key version number, such as `loom secrets push 1`. A key must never be passed as an argument: if a key was typed there, treat it as exposed, because it is now in the shell history and was visible in the process list. The key is read from a hidden terminal prompt instead.";
|
|
15056
15383
|
const SECRETS_FINGERPRINT_ARGUMENT_REFUSAL = "loom secrets fingerprint takes no arguments. A key must never be passed as an argument: if a key was typed there, treat it as exposed, because it is now in the shell history and was visible in the process list. The key is read from a hidden terminal prompt instead.";
|
|
15057
15384
|
/**
|
|
15058
15385
|
* Variables that an automated or agent session sets. A key must not be shown
|
|
@@ -15068,13 +15395,239 @@ const AUTOMATED_SESSION_ENV_NAMES = [
|
|
|
15068
15395
|
"CURSOR_AGENT",
|
|
15069
15396
|
"GEMINI_CLI",
|
|
15070
15397
|
];
|
|
15071
|
-
|
|
15072
|
-
|
|
15398
|
+
/**
|
|
15399
|
+
* Whether a command may change something outside the repository, such as a
|
|
15400
|
+
* deployment platform's settings. An explicit flag decides. Without one, only
|
|
15401
|
+
* a person at a terminal is asked, and the default answer is no; anywhere
|
|
15402
|
+
* else nothing outside changes and the command says how to do it instead.
|
|
15403
|
+
* See "CLI prompts and outside changes" in AGENTS.md.
|
|
15404
|
+
*/
|
|
15405
|
+
function resolveOutsideChange(flags, interactive) {
|
|
15406
|
+
if (flags.yes)
|
|
15407
|
+
return "yes";
|
|
15408
|
+
if (flags.no)
|
|
15409
|
+
return "no";
|
|
15410
|
+
return interactive ? "ask" : "no";
|
|
15411
|
+
}
|
|
15412
|
+
const isYesAnswer = (answer) => /^y(es)?$/i.test(answer.trim());
|
|
15413
|
+
/**
|
|
15414
|
+
* Parses `vercel env ls --format json` output, or returns null when it is not
|
|
15415
|
+
* that listing. Vercel CLI 54 and newer print it.
|
|
15416
|
+
*/
|
|
15417
|
+
function parseVercelEnvListing(text) {
|
|
15418
|
+
let parsed;
|
|
15419
|
+
try {
|
|
15420
|
+
parsed = JSON.parse(text.slice(text.indexOf("{"), text.lastIndexOf("}") + 1));
|
|
15421
|
+
}
|
|
15422
|
+
catch {
|
|
15423
|
+
return null;
|
|
15424
|
+
}
|
|
15425
|
+
const envs = isJsonObject(parsed) ? parsed.envs : undefined;
|
|
15426
|
+
if (!Array.isArray(envs))
|
|
15427
|
+
return null;
|
|
15428
|
+
return envs.flatMap((entry) => {
|
|
15429
|
+
if (!isJsonObject(entry) || typeof entry.key !== "string")
|
|
15430
|
+
return [];
|
|
15431
|
+
const targets = (Array.isArray(entry.target) ? entry.target : [entry.target])
|
|
15432
|
+
.filter((target) => typeof target === "string");
|
|
15433
|
+
return [{
|
|
15434
|
+
custom: Array.isArray(entry.customEnvironmentIds) &&
|
|
15435
|
+
entry.customEnvironmentIds.length > 0,
|
|
15436
|
+
key: entry.key,
|
|
15437
|
+
secret: entry.type === "sensitive" || entry.visibility === "secret",
|
|
15438
|
+
targets,
|
|
15439
|
+
type: typeof entry.type === "string" ? entry.type : "",
|
|
15440
|
+
}];
|
|
15441
|
+
});
|
|
15442
|
+
}
|
|
15443
|
+
async function listVercelProductionVariables(cwd, commandRunner, command, env) {
|
|
15444
|
+
// JSON, not the table: the table cannot tell a variable that applies to
|
|
15445
|
+
// Production alone from one shared with Preview, and a name could appear
|
|
15446
|
+
// inside another variable's displayed value.
|
|
15447
|
+
const result = await commandRunner(command, ["env", "ls", "production", "--format", "json"], { cwd, env, stdio: "pipe" });
|
|
15448
|
+
if (result.code !== 0) {
|
|
15449
|
+
throw new Error(`Could not list Vercel Production variables: ${vercelFailureDetail(result, "")}`);
|
|
15450
|
+
}
|
|
15451
|
+
const variables = parseVercelEnvListing(result.stdout);
|
|
15452
|
+
if (!variables) {
|
|
15453
|
+
throw new Error("Vercel did not list Production variables as JSON.");
|
|
15454
|
+
}
|
|
15455
|
+
return variables.filter((variable) => variable.targets.includes("production"));
|
|
15456
|
+
}
|
|
15457
|
+
const vercelVariables = (target, key) => target.variables.filter((variable) => variable.key === key);
|
|
15458
|
+
/**
|
|
15459
|
+
* Why the pointer cannot simply be updated for Production, or null when it
|
|
15460
|
+
* can. A variable shared with Preview would move its pointer too, and Preview
|
|
15461
|
+
* has a key list of its own. Sharing with a custom environment is not in
|
|
15462
|
+
* Vercel's listing, so it cannot be seen here.
|
|
15463
|
+
*/
|
|
15464
|
+
function vercelPointerProblem(target, name) {
|
|
15465
|
+
const found = vercelVariables(target, name);
|
|
15466
|
+
if (found.length === 0)
|
|
15467
|
+
return null;
|
|
15468
|
+
const shared = found.find((variable) => variable.custom || variable.targets.some((each) => each !== "production"));
|
|
15469
|
+
return found.length > 1 || shared
|
|
15470
|
+
? `${name} on Vercel is shared with ${shared
|
|
15471
|
+
? shared.targets.filter((each) => each !== "production").join(", ") ||
|
|
15472
|
+
"a custom environment"
|
|
15473
|
+
: "another entry"}. Give Production its own ${name} by hand, so the other environments keep theirs.`
|
|
15474
|
+
: null;
|
|
15475
|
+
}
|
|
15476
|
+
async function findSecretsVercelTarget(cwd, commandRunner) {
|
|
15477
|
+
const link = await readVercelProjectLink(cwd);
|
|
15478
|
+
if (!link.linked || !link.projectId) {
|
|
15479
|
+
return {
|
|
15480
|
+
linked: false,
|
|
15481
|
+
reason: `This project is not linked to Vercel: ${link.detail} Run \`vercel link\` first.`,
|
|
15482
|
+
};
|
|
15483
|
+
}
|
|
15484
|
+
// The link names the project; inherited ids would silently point the
|
|
15485
|
+
// writes somewhere else.
|
|
15486
|
+
const env = withoutInheritedVercelProject(node_process_1.default.env);
|
|
15487
|
+
const cli = await detectVercelCliCommand(cwd, commandRunner, env);
|
|
15488
|
+
if (!cli.command) {
|
|
15489
|
+
return {
|
|
15490
|
+
linked: true,
|
|
15491
|
+
reason: "The Vercel CLI (`vercel` or `vc`) was not found.",
|
|
15492
|
+
};
|
|
15493
|
+
}
|
|
15494
|
+
try {
|
|
15495
|
+
return {
|
|
15496
|
+
target: {
|
|
15497
|
+
command: cli.command,
|
|
15498
|
+
env,
|
|
15499
|
+
project: link.projectName ?? link.projectId,
|
|
15500
|
+
variables: await listVercelProductionVariables(cwd, commandRunner, cli.command, env),
|
|
15501
|
+
},
|
|
15502
|
+
};
|
|
15503
|
+
}
|
|
15504
|
+
catch (error) {
|
|
15505
|
+
return { linked: true, reason: error.message };
|
|
15506
|
+
}
|
|
15507
|
+
}
|
|
15508
|
+
function warnIfPointerSecret(target, name, io) {
|
|
15509
|
+
if (vercelVariables(target, name).some((variable) => variable.secret)) {
|
|
15510
|
+
io.err(`Vercel holds ${name} as a Secret, perhaps by team policy. It is not secret, and the release build cannot read a Secret back: give its release-policy requirement a placeholder, or store it readable.`);
|
|
15511
|
+
}
|
|
15512
|
+
}
|
|
15513
|
+
/** Sets the pointer for Production only, as a readable variable. */
|
|
15514
|
+
async function setVercelPointer(cwd, commandRunner, target, name, id) {
|
|
15515
|
+
if (vercelVariables(target, name).length) {
|
|
15516
|
+
await updateVercelEnvValue(cwd, commandRunner, target.env, target.command, name, String(id), "production");
|
|
15517
|
+
}
|
|
15518
|
+
else {
|
|
15519
|
+
// Without --no-sensitive, a value given on stdin is stored as a Secret,
|
|
15520
|
+
// which `vercel pull` cannot read back for the release build.
|
|
15521
|
+
await addVercelEnvValue(cwd, commandRunner, target.env, target.command, name, String(id), "production", ["--no-sensitive", "--yes"]);
|
|
15522
|
+
}
|
|
15523
|
+
}
|
|
15524
|
+
/**
|
|
15525
|
+
* Puts a secrets key on Vercel Production as a Secret, and the pointer when
|
|
15526
|
+
* the key is the active one, from a copy the operator pastes back from their
|
|
15527
|
+
* password manager. That copy is checked against the fingerprint in loom.json
|
|
15528
|
+
* before Vercel gets it: a key that reached Vercel but not the password
|
|
15529
|
+
* manager could never be recovered, since Vercel never shows a Secret again.
|
|
15530
|
+
* Afterwards Vercel is listed again to confirm how it stored them.
|
|
15531
|
+
*/
|
|
15532
|
+
async function pushSecretsKeyToVercel(cwd, commandRunner, target, key, terminal, io, options) {
|
|
15533
|
+
if (vercelVariables(target, key.variableName).length) {
|
|
15534
|
+
io.err(`${key.variableName} already exists in Vercel Production. Loom never replaces a key there; find out why Vercel and loom.json differ first.`);
|
|
15535
|
+
return false;
|
|
15536
|
+
}
|
|
15537
|
+
io.out(`Paste the key back from your password manager: the value after \`${key.variableName}=\`. Loom checks the saved copy against the fingerprint in loom.json before Vercel gets it.`);
|
|
15538
|
+
let value = null;
|
|
15539
|
+
for (let attempt = 1; attempt <= 3 && value === null; attempt += 1) {
|
|
15540
|
+
let pasted = (await terminal.prompt(`${key.variableName} from your password manager (input is hidden): `)).trim();
|
|
15541
|
+
if (!pasted) {
|
|
15542
|
+
io.err("Nothing was entered, so nothing was sent to Vercel.");
|
|
15543
|
+
return false;
|
|
15544
|
+
}
|
|
15545
|
+
// The whole printed line is a likely thing to have saved.
|
|
15546
|
+
if (pasted.startsWith(`${key.variableName}=`)) {
|
|
15547
|
+
pasted = pasted.slice(key.variableName.length + 1).trim();
|
|
15548
|
+
}
|
|
15549
|
+
let fingerprint = null;
|
|
15550
|
+
try {
|
|
15551
|
+
fingerprint = await fingerprintSecretsKey(pasted);
|
|
15552
|
+
}
|
|
15553
|
+
catch {
|
|
15554
|
+
io.err("That is not a secrets key: it does not decode to 32 bytes. Check the saved copy.");
|
|
15555
|
+
continue;
|
|
15556
|
+
}
|
|
15557
|
+
if (fingerprint === key.fingerprint) {
|
|
15558
|
+
value = pasted;
|
|
15559
|
+
}
|
|
15560
|
+
else {
|
|
15561
|
+
io.err(`That is a different key from version ${key.id}: its fingerprint does not match loom.json. Check the saved copy.`);
|
|
15562
|
+
}
|
|
15563
|
+
}
|
|
15564
|
+
if (value === null) {
|
|
15565
|
+
io.err(`Nothing was sent to Vercel. Fix the saved copy, then run \`loom secrets push ${key.id}\`.`);
|
|
15566
|
+
return false;
|
|
15567
|
+
}
|
|
15568
|
+
let setPointer = key.state === "active";
|
|
15569
|
+
const pointerProblem = setPointer
|
|
15570
|
+
? vercelPointerProblem(target, key.activeKeyName)
|
|
15571
|
+
: null;
|
|
15572
|
+
if (pointerProblem)
|
|
15573
|
+
setPointer = false;
|
|
15574
|
+
else if (setPointer && vercelVariables(target, key.activeKeyName).length) {
|
|
15575
|
+
setPointer = options.replacePointer === "ask" &&
|
|
15576
|
+
isYesAnswer(await terminal.ask(`${key.activeKeyName} already exists in Vercel Production. Set it to ${key.id}? [y/N] `));
|
|
15577
|
+
}
|
|
15578
|
+
try {
|
|
15579
|
+
await addVercelEnvValue(cwd, commandRunner, target.env, target.command, key.variableName, value, "production", ["--sensitive", "--yes"]);
|
|
15580
|
+
}
|
|
15581
|
+
catch (error) {
|
|
15582
|
+
io.err(`${error.message} Nothing else was changed.`);
|
|
15583
|
+
return false;
|
|
15584
|
+
}
|
|
15585
|
+
if (setPointer) {
|
|
15586
|
+
try {
|
|
15587
|
+
await setVercelPointer(cwd, commandRunner, target, key.activeKeyName, key.id);
|
|
15588
|
+
}
|
|
15589
|
+
catch (error) {
|
|
15590
|
+
io.err(`${key.variableName} was added, but ${key.activeKeyName} was not: ${error.message} Set ${key.activeKeyName}=${key.id} in Vercel Production yourself.`);
|
|
15591
|
+
return false;
|
|
15592
|
+
}
|
|
15593
|
+
}
|
|
15594
|
+
// Confirm what Vercel stored, rather than trusting how it was asked.
|
|
15595
|
+
let stored;
|
|
15596
|
+
try {
|
|
15597
|
+
stored = await listVercelProductionVariables(cwd, commandRunner, target.command, target.env);
|
|
15598
|
+
}
|
|
15599
|
+
catch (error) {
|
|
15600
|
+
io.err(`Added ${key.variableName}, but could not confirm how Vercel stored it: ${error.message} Check it is a Secret for Production only.`);
|
|
15601
|
+
return false;
|
|
15602
|
+
}
|
|
15603
|
+
const confirmed = { ...target, variables: stored };
|
|
15604
|
+
const keyEntry = vercelVariables(confirmed, key.variableName);
|
|
15605
|
+
if (keyEntry.length !== 1 || !keyEntry[0].secret ||
|
|
15606
|
+
keyEntry[0].custom || keyEntry[0].targets.join() !== "production") {
|
|
15607
|
+
io.err(`Vercel did not store ${key.variableName} as a Secret for Production only. Fix it in Vercel before deploying.`);
|
|
15608
|
+
return false;
|
|
15609
|
+
}
|
|
15610
|
+
io.out(`Added ${key.variableName} to Vercel project ${target.project}, Production only, as a Secret${setPointer ? `, and set ${key.activeKeyName}=${key.id}` : ""}. Deployments built before this keep their old environment.`);
|
|
15611
|
+
if (setPointer)
|
|
15612
|
+
warnIfPointerSecret(confirmed, key.activeKeyName, io);
|
|
15613
|
+
if (pointerProblem)
|
|
15614
|
+
io.err(pointerProblem);
|
|
15615
|
+
else if (key.state === "active" && !setPointer) {
|
|
15616
|
+
io.out(`Set ${key.activeKeyName}=${key.id} in Vercel Production before deploying.`);
|
|
15617
|
+
}
|
|
15618
|
+
return true;
|
|
15619
|
+
}
|
|
15620
|
+
async function runSecrets(cwd, command, target, options, io, terminal = {}, commandRunner = defaultCommandRunner) {
|
|
15621
|
+
const usage = "Usage: loom secrets keygen [--environment production|preview] [--vercel|--no-vercel]\n or: loom secrets fingerprint\n or: loom secrets push <id>\n or: loom secrets activate <id> [--environment production|preview] [--vercel|--no-vercel]\n or: loom secrets retire <id> [--environment production|preview]";
|
|
15073
15622
|
const environmentOption = options.environment ?? "production";
|
|
15074
15623
|
if (environmentOption !== "production" && environmentOption !== "preview") {
|
|
15075
15624
|
io.err("--environment must be production or preview.");
|
|
15076
15625
|
return 1;
|
|
15077
15626
|
}
|
|
15627
|
+
if (options.vercel && options.noVercel) {
|
|
15628
|
+
io.err("--vercel and --no-vercel cannot be used together.");
|
|
15629
|
+
return 1;
|
|
15630
|
+
}
|
|
15078
15631
|
const environment = environmentOption;
|
|
15079
15632
|
const platformTarget = environment === "production"
|
|
15080
15633
|
? "Production"
|
|
@@ -15083,6 +15636,27 @@ async function runSecrets(cwd, command, target, options, io, terminal = {}) {
|
|
|
15083
15636
|
const stdoutIsTty = terminal.stdoutIsTty ?? Boolean(node_process_1.default.stdout.isTTY);
|
|
15084
15637
|
const sessionEnv = terminal.env ?? node_process_1.default.env;
|
|
15085
15638
|
const automatedMarker = AUTOMATED_SESSION_ENV_NAMES.find((name) => Boolean(sessionEnv[name]));
|
|
15639
|
+
const vercelChoice = resolveOutsideChange({ no: options.noVercel, yes: options.vercel }, stdinIsTty && stdoutIsTty && !automatedMarker);
|
|
15640
|
+
if (options.vercel && environment !== "production") {
|
|
15641
|
+
io.err("--vercel sets Vercel Production only. Set Preview variables yourself.");
|
|
15642
|
+
return 1;
|
|
15643
|
+
}
|
|
15644
|
+
// Raw mode rather than readline: under Deno a readline question never
|
|
15645
|
+
// settles on Ctrl-C, and the command would end without a word.
|
|
15646
|
+
const ask = terminal.ask ??
|
|
15647
|
+
((question) => promptForTerminalValue(question, false, {
|
|
15648
|
+
cancelled: "Cancelled.",
|
|
15649
|
+
notInteractive: "This question needs a terminal.",
|
|
15650
|
+
}, { rawEcho: true }));
|
|
15651
|
+
const prompt = (cancelled, notInteractive) => terminal.prompt ??
|
|
15652
|
+
((question) => promptForTerminalValue(question, true, { cancelled, notInteractive }));
|
|
15653
|
+
// Reading a key is only for a person at a terminal: never a pipe, a file
|
|
15654
|
+
// or an agent's session, whose transcript would then hold the key.
|
|
15655
|
+
const keyReadRefusal = (name) => automatedMarker
|
|
15656
|
+
? `loom secrets ${name} reads a key, so it only runs for a person at a terminal, and this is an automated or agent session. A key must not be typed into, or read by, such a session. An operator runs it personally, in their own terminal.`
|
|
15657
|
+
: !stdinIsTty
|
|
15658
|
+
? `loom secrets ${name} reads the key from a hidden terminal prompt, so its input must be a terminal. Never pass a key as an argument, through a pipe, or from a file. Run it yourself, in your own terminal.`
|
|
15659
|
+
: null;
|
|
15086
15660
|
try {
|
|
15087
15661
|
switch (command) {
|
|
15088
15662
|
case "keygen": {
|
|
@@ -15101,6 +15675,29 @@ async function runSecrets(cwd, command, target, options, io, terminal = {}) {
|
|
|
15101
15675
|
io.err(`loom secrets keygen prints a production key, so it only runs for a person at a terminal, and ${refusal}. A production key must not be written to a pipe, a file, a log or an AI agent transcript. An operator runs it personally, in their own terminal.`);
|
|
15102
15676
|
return 1;
|
|
15103
15677
|
}
|
|
15678
|
+
// Asked for explicitly, Vercel must be reachable before a key exists:
|
|
15679
|
+
// finding out afterwards would leave a recorded key with nowhere to go.
|
|
15680
|
+
let vercel = null;
|
|
15681
|
+
let vercelNote = null;
|
|
15682
|
+
if (vercelChoice !== "no" && environment === "production") {
|
|
15683
|
+
const found = await findSecretsVercelTarget(cwd, commandRunner);
|
|
15684
|
+
const planned = await planSecretsKey(cwd, environment);
|
|
15685
|
+
if ("target" in found &&
|
|
15686
|
+
vercelVariables(found.target, planned.variableName).length) {
|
|
15687
|
+
// Drift between Vercel and loom.json, whether or not Vercel was
|
|
15688
|
+
// asked for; a key generated now would have nowhere to go.
|
|
15689
|
+
io.err(`${planned.variableName} already exists in Vercel Production, but loom.json has no such key. Find out why they differ before generating one. No key was generated.`);
|
|
15690
|
+
return 1;
|
|
15691
|
+
}
|
|
15692
|
+
if (!("target" in found) && vercelChoice === "yes") {
|
|
15693
|
+
io.err(`${found.reason} No key was generated.`);
|
|
15694
|
+
return 1;
|
|
15695
|
+
}
|
|
15696
|
+
if ("target" in found)
|
|
15697
|
+
vercel = found.target;
|
|
15698
|
+
else if (found.linked)
|
|
15699
|
+
vercelNote = found.reason;
|
|
15700
|
+
}
|
|
15104
15701
|
const result = await generateSecretsKey(cwd, { environment });
|
|
15105
15702
|
io.out(`Generated secrets key version ${result.id} for ${environment}. It is shown once and Loom keeps no copy.`);
|
|
15106
15703
|
io.out("");
|
|
@@ -15108,16 +15705,92 @@ async function runSecrets(cwd, command, target, options, io, terminal = {}) {
|
|
|
15108
15705
|
io.out(`Fingerprint: ${result.fingerprint}`);
|
|
15109
15706
|
io.out("");
|
|
15110
15707
|
io.out(`Recorded the fingerprint in loom.json as ${result.state}. Commit loom.json; it holds no key.`);
|
|
15708
|
+
let pushed = false;
|
|
15709
|
+
let go = false;
|
|
15710
|
+
if (vercel) {
|
|
15711
|
+
io.out("Save the key and its fingerprint in your password manager now, before anything else.");
|
|
15712
|
+
try {
|
|
15713
|
+
go = vercelChoice === "yes" || isYesAnswer(await ask(`Add ${result.variableName} (Secret, Production only)${result.state === "active"
|
|
15714
|
+
? ` and ${result.activeKeyName}=${result.id}`
|
|
15715
|
+
: ""} to Vercel project ${vercel.project}? [y/N] `));
|
|
15716
|
+
}
|
|
15717
|
+
catch {
|
|
15718
|
+
// An interrupted question is a no; the next steps still print.
|
|
15719
|
+
}
|
|
15720
|
+
if (go) {
|
|
15721
|
+
pushed = await pushSecretsKeyToVercel(cwd, commandRunner, vercel, result, {
|
|
15722
|
+
ask,
|
|
15723
|
+
prompt: prompt("Nothing was sent to Vercel.", "This needs a terminal."),
|
|
15724
|
+
}, io,
|
|
15725
|
+
// An explicit --vercel asks nothing more, so it leaves an
|
|
15726
|
+
// existing pointer alone and says so.
|
|
15727
|
+
{ replacePointer: vercelChoice === "yes" ? "no" : "ask" }).catch((error) => {
|
|
15728
|
+
io.err(`${error.message} Nothing was sent to Vercel.`);
|
|
15729
|
+
return false;
|
|
15730
|
+
});
|
|
15731
|
+
}
|
|
15732
|
+
}
|
|
15733
|
+
else if (vercelNote) {
|
|
15734
|
+
io.out(`Note: Vercel was not offered: ${vercelNote}`);
|
|
15735
|
+
}
|
|
15111
15736
|
io.out("Next steps:");
|
|
15112
|
-
|
|
15113
|
-
|
|
15114
|
-
|
|
15115
|
-
|
|
15116
|
-
|
|
15117
|
-
|
|
15737
|
+
const steps = [];
|
|
15738
|
+
if (!vercel) {
|
|
15739
|
+
steps.push("Save the key and its fingerprint in your password manager now, before anything else.");
|
|
15740
|
+
}
|
|
15741
|
+
if (!pushed) {
|
|
15742
|
+
steps.push(`Add ${result.variableName} to the deployment platform from the password-manager copy, ${platformTarget} only, as a write-only secret${result.state === "active"
|
|
15743
|
+
? `, and set ${result.activeKeyName}=${result.id} there`
|
|
15744
|
+
: ""}.${environment === "production"
|
|
15745
|
+
? ` On Vercel, \`loom secrets push ${result.id}\` checks the saved copy and does this for you.`
|
|
15746
|
+
: ""}`);
|
|
15747
|
+
}
|
|
15748
|
+
steps.push("Deploy.");
|
|
15749
|
+
steps.push(`Confirm \`secrets.assertReady()\` passes in the deployment: that proves the deployed key is the one you saved.${result.state === "active"
|
|
15118
15750
|
? ""
|
|
15119
15751
|
: ` Then switch to it with \`loom secrets activate ${result.id}\`.`}`);
|
|
15120
|
-
|
|
15752
|
+
steps.forEach((step, index) => io.out(` ${index + 1}. ${step}`));
|
|
15753
|
+
// The key exists either way; a push that was asked for and did not
|
|
15754
|
+
// happen is still a failure for whoever runs this.
|
|
15755
|
+
return go && !pushed ? 1 : 0;
|
|
15756
|
+
}
|
|
15757
|
+
case "push": {
|
|
15758
|
+
const id = target === undefined ? null : (0, keyring_js_1.parseSecretKeyId)(target);
|
|
15759
|
+
if (id === null) {
|
|
15760
|
+
io.err(usage);
|
|
15761
|
+
return 1;
|
|
15762
|
+
}
|
|
15763
|
+
if (options.vercel || options.noVercel) {
|
|
15764
|
+
io.err("loom secrets push always asks first; it takes no --vercel or --no-vercel.");
|
|
15765
|
+
return 1;
|
|
15766
|
+
}
|
|
15767
|
+
const refusal = keyReadRefusal("push");
|
|
15768
|
+
if (refusal) {
|
|
15769
|
+
io.err(refusal);
|
|
15770
|
+
return 1;
|
|
15771
|
+
}
|
|
15772
|
+
if (environment !== "production") {
|
|
15773
|
+
io.err("loom secrets push sets Vercel Production only. Set Preview variables yourself.");
|
|
15774
|
+
return 1;
|
|
15775
|
+
}
|
|
15776
|
+
const key = await recordedSecretsKey(cwd, id, environment);
|
|
15777
|
+
const found = await findSecretsVercelTarget(cwd, commandRunner);
|
|
15778
|
+
if (!("target" in found)) {
|
|
15779
|
+
io.err(found.reason);
|
|
15780
|
+
return 1;
|
|
15781
|
+
}
|
|
15782
|
+
if (!isYesAnswer(await ask(`Add ${key.variableName} (Secret, Production only)${key.state === "active"
|
|
15783
|
+
? ` and ${key.activeKeyName}=${key.id}`
|
|
15784
|
+
: ""} to Vercel project ${found.target.project}? [y/N] `))) {
|
|
15785
|
+
io.out("Nothing was changed.");
|
|
15786
|
+
return 0;
|
|
15787
|
+
}
|
|
15788
|
+
return await pushSecretsKeyToVercel(cwd, commandRunner, found.target, key, {
|
|
15789
|
+
ask,
|
|
15790
|
+
prompt: prompt("Nothing was sent to Vercel.", keyReadRefusal("push") ?? "This needs a terminal."),
|
|
15791
|
+
}, io, { replacePointer: "ask" })
|
|
15792
|
+
? 0
|
|
15793
|
+
: 1;
|
|
15121
15794
|
}
|
|
15122
15795
|
case "fingerprint": {
|
|
15123
15796
|
// Checked before anything else, and never echoed: whatever followed
|
|
@@ -15126,21 +15799,17 @@ async function runSecrets(cwd, command, target, options, io, terminal = {}) {
|
|
|
15126
15799
|
io.err(SECRETS_FINGERPRINT_ARGUMENT_REFUSAL);
|
|
15127
15800
|
return 1;
|
|
15128
15801
|
}
|
|
15129
|
-
if (
|
|
15130
|
-
io.err(
|
|
15802
|
+
if (options.vercel || options.noVercel) {
|
|
15803
|
+
io.err("loom secrets fingerprint changes nothing on Vercel.");
|
|
15131
15804
|
return 1;
|
|
15132
15805
|
}
|
|
15133
|
-
const
|
|
15134
|
-
if (
|
|
15135
|
-
io.err(
|
|
15806
|
+
const refusal = keyReadRefusal("fingerprint");
|
|
15807
|
+
if (refusal) {
|
|
15808
|
+
io.err(refusal);
|
|
15136
15809
|
return 1;
|
|
15137
15810
|
}
|
|
15138
|
-
const
|
|
15139
|
-
|
|
15140
|
-
cancelled: "Fingerprinting was cancelled.",
|
|
15141
|
-
notInteractive,
|
|
15142
|
-
}));
|
|
15143
|
-
io.out(await fingerprintSecretsKey(await prompt("Secrets key (input is hidden): ")));
|
|
15811
|
+
const readKey = prompt("Fingerprinting was cancelled.", "loom secrets fingerprint reads the key from a hidden terminal prompt, so its input must be a terminal. Never pass a key as an argument, through a pipe, or from a file. Run it yourself, in your own terminal.");
|
|
15812
|
+
io.out(await fingerprintSecretsKey(await readKey("Secrets key (input is hidden): ")));
|
|
15144
15813
|
return 0;
|
|
15145
15814
|
}
|
|
15146
15815
|
case "activate":
|
|
@@ -15151,13 +15820,78 @@ async function runSecrets(cwd, command, target, options, io, terminal = {}) {
|
|
|
15151
15820
|
return 1;
|
|
15152
15821
|
}
|
|
15153
15822
|
if (command === "activate") {
|
|
15154
|
-
|
|
15823
|
+
if (environment !== "production" && options.vercel) {
|
|
15824
|
+
io.err("--vercel sets Vercel Production only. Set Preview variables yourself.");
|
|
15825
|
+
return 1;
|
|
15826
|
+
}
|
|
15827
|
+
let pointerSet = false;
|
|
15828
|
+
let vercelNote = null;
|
|
15829
|
+
const result = await activateSecretsKey(cwd, id, environment, {
|
|
15830
|
+
// The platform's pointer moves first: a deployment carrying the
|
|
15831
|
+
// new list with the old pointer would fail every seal. A build
|
|
15832
|
+
// between the two, with the new pointer and the old list, fails
|
|
15833
|
+
// too, so loom.json should follow at once.
|
|
15834
|
+
beforeWrite: async (key) => {
|
|
15835
|
+
if (vercelChoice === "no" || environment !== "production") {
|
|
15836
|
+
return false;
|
|
15837
|
+
}
|
|
15838
|
+
const found = await findSecretsVercelTarget(cwd, commandRunner);
|
|
15839
|
+
const refusal = !("target" in found)
|
|
15840
|
+
? found.reason
|
|
15841
|
+
: !vercelVariables(found.target, key.variableName).length
|
|
15842
|
+
? `${key.variableName} is not in Vercel Production. Add it (\`loom secrets push ${id}\`) and deploy before activating it.`
|
|
15843
|
+
: vercelPointerProblem(found.target, key.activeKeyName);
|
|
15844
|
+
if (refusal) {
|
|
15845
|
+
if (vercelChoice === "yes") {
|
|
15846
|
+
throw new Error(`${refusal} loom.json was not changed.`);
|
|
15847
|
+
}
|
|
15848
|
+
if ("target" in found || found.linked)
|
|
15849
|
+
vercelNote = refusal;
|
|
15850
|
+
return false;
|
|
15851
|
+
}
|
|
15852
|
+
const vercel = found.target;
|
|
15853
|
+
if (vercelChoice === "ask" &&
|
|
15854
|
+
!isYesAnswer(await ask(`Set ${key.activeKeyName}=${id} in Vercel project ${vercel.project}, Production, before loom.json changes? [y/N] `).catch(() => ""))) {
|
|
15855
|
+
return false;
|
|
15856
|
+
}
|
|
15857
|
+
try {
|
|
15858
|
+
await setVercelPointer(cwd, commandRunner, vercel, key.activeKeyName, id);
|
|
15859
|
+
}
|
|
15860
|
+
catch (error) {
|
|
15861
|
+
throw new Error(`${error.message} loom.json was not changed.`);
|
|
15862
|
+
}
|
|
15863
|
+
pointerSet = true;
|
|
15864
|
+
io.out(`Set ${key.activeKeyName}=${id} in Vercel project ${vercel.project}, Production.`);
|
|
15865
|
+
// Team policy, or an existing Secret kept by `env update`, can
|
|
15866
|
+
// leave the pointer unreadable to the release build.
|
|
15867
|
+
try {
|
|
15868
|
+
warnIfPointerSecret({
|
|
15869
|
+
...vercel,
|
|
15870
|
+
variables: await listVercelProductionVariables(cwd, commandRunner, vercel.command, vercel.env),
|
|
15871
|
+
}, key.activeKeyName, io);
|
|
15872
|
+
}
|
|
15873
|
+
catch {
|
|
15874
|
+
// The pointer is set; how it is stored is a warning only.
|
|
15875
|
+
}
|
|
15876
|
+
return true;
|
|
15877
|
+
},
|
|
15878
|
+
});
|
|
15155
15879
|
io.out(result.changedFiles.length
|
|
15156
15880
|
? `Updated ${result.changedFiles.join(", ")}: key version ${id} is now the active ${environment} key.`
|
|
15157
15881
|
: `Key version ${id} is already the active ${environment} key in loom.json.`);
|
|
15158
|
-
|
|
15882
|
+
if (vercelNote)
|
|
15883
|
+
io.out(`Note: Vercel was not changed: ${vercelNote}`);
|
|
15884
|
+
io.out(pointerSet
|
|
15885
|
+
? "Next: run `loom check --production` and push this loom.json now. A production build made before it lands has the new pointer and the old list, and fails every seal."
|
|
15886
|
+
: `Note: Set ${result.activeKeyName}=${id} for ${platformTarget} on the deployment platform, before deploying this loom.json. Until both match, every seal fails (opens still work).${environment === "production"
|
|
15887
|
+
? " On Vercel, `--vercel` does this first."
|
|
15888
|
+
: ""}`);
|
|
15159
15889
|
return 0;
|
|
15160
15890
|
}
|
|
15891
|
+
if (options.vercel || options.noVercel) {
|
|
15892
|
+
io.err("loom secrets retire changes nothing on Vercel; remove the variable there yourself, after deploying the retired list.");
|
|
15893
|
+
return 1;
|
|
15894
|
+
}
|
|
15161
15895
|
const result = await retireSecretsKey(cwd, id, environment);
|
|
15162
15896
|
io.out(result.changedFiles.length
|
|
15163
15897
|
? `Updated ${result.changedFiles.join(", ")}: key version ${id} is now retired for ${environment}.`
|
|
@@ -15796,6 +16530,13 @@ async function runDbRelease(cwd, command, args, io, options) {
|
|
|
15796
16530
|
}, io);
|
|
15797
16531
|
return 0;
|
|
15798
16532
|
}
|
|
16533
|
+
case "mask-env": {
|
|
16534
|
+
if (args.length !== 1) {
|
|
16535
|
+
io.err("Usage: loom db release mask-env <env-file>");
|
|
16536
|
+
return 1;
|
|
16537
|
+
}
|
|
16538
|
+
return (0, vercelEnvMask_js_1.maskVercelPulledEnvironment)({ env: node_process_1.default.env, envFile: (0, node_path_1.resolve)(cwd, args[0]) }, io);
|
|
16539
|
+
}
|
|
15799
16540
|
case "verify-build-env": {
|
|
15800
16541
|
if (args.length < 2 || args.length > 3) {
|
|
15801
16542
|
io.err("Usage: loom db release verify-build-env <output-directory> <manifest-file> [deployment-root]");
|
|
@@ -16080,6 +16821,11 @@ async function runCli(args = node_process_1.default.argv.slice(2), io = {
|
|
|
16080
16821
|
io.err(SECRETS_FINGERPRINT_ARGUMENT_REFUSAL);
|
|
16081
16822
|
return 1;
|
|
16082
16823
|
}
|
|
16824
|
+
if (secretsIndex >= 0 && args[secretsIndex + 1] === "push" &&
|
|
16825
|
+
!secretsPushArgumentsAreSafe(args.slice(secretsIndex + 2))) {
|
|
16826
|
+
io.err(SECRETS_PUSH_ARGUMENT_REFUSAL);
|
|
16827
|
+
return 1;
|
|
16828
|
+
}
|
|
16083
16829
|
const parsed = (0, node_util_1.parseArgs)({
|
|
16084
16830
|
allowPositionals: true,
|
|
16085
16831
|
args,
|
|
@@ -16109,6 +16855,8 @@ async function runCli(args = node_process_1.default.argv.slice(2), io = {
|
|
|
16109
16855
|
"max-requests-per-key": { type: "string" },
|
|
16110
16856
|
"no-color": { type: "boolean" },
|
|
16111
16857
|
"no-progress": { type: "boolean" },
|
|
16858
|
+
"no-vercel": { type: "boolean" },
|
|
16859
|
+
vercel: { type: "boolean" },
|
|
16112
16860
|
"no-sync": { type: "boolean" },
|
|
16113
16861
|
network: { type: "boolean" },
|
|
16114
16862
|
"neon-auth": { type: "boolean" },
|
|
@@ -16215,7 +16963,11 @@ async function runCli(args = node_process_1.default.argv.slice(2), io = {
|
|
|
16215
16963
|
resource: parsed.values.resource,
|
|
16216
16964
|
}, io);
|
|
16217
16965
|
case "secrets":
|
|
16218
|
-
return await runSecrets(cwd, arg1, arg2, {
|
|
16966
|
+
return await runSecrets(cwd, arg1, arg2, {
|
|
16967
|
+
environment: parsed.values.environment,
|
|
16968
|
+
noVercel: parsed.values["no-vercel"],
|
|
16969
|
+
vercel: parsed.values.vercel,
|
|
16970
|
+
}, io, options.secretsTerminal, options.commandRunner);
|
|
16219
16971
|
case "skills":
|
|
16220
16972
|
return await runSkills(cwd, arg1, [arg2, ...rest].filter(Boolean), io, {
|
|
16221
16973
|
acceptUnknownLicense: parsed.values["accept-unknown-license"],
|