@gadicc/loom 1.15.5 → 1.16.1
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/db/drizzle-config.d.ts +2 -1
- package/db/drizzle-config.js +6 -3
- package/esm/src/cli/migrationEnv.d.ts +21 -0
- package/esm/src/cli/migrationEnv.d.ts.map +1 -0
- package/esm/src/cli/migrationEnv.js +56 -0
- package/esm/src/cli/mod.d.ts +12 -0
- package/esm/src/cli/mod.d.ts.map +1 -1
- package/esm/src/cli/mod.js +216 -10
- package/esm/src/cli/vercelBuildEnv.d.ts +30 -0
- package/esm/src/cli/vercelBuildEnv.d.ts.map +1 -0
- package/esm/src/cli/vercelBuildEnv.js +186 -0
- package/package.json +2 -2
- package/script/src/cli/migrationEnv.d.ts +21 -0
- package/script/src/cli/migrationEnv.d.ts.map +1 -0
- package/script/src/cli/migrationEnv.js +60 -0
- package/script/src/cli/mod.d.ts +12 -0
- package/script/src/cli/mod.d.ts.map +1 -1
- package/script/src/cli/mod.js +217 -10
- package/script/src/cli/vercelBuildEnv.d.ts +30 -0
- package/script/src/cli/vercelBuildEnv.d.ts.map +1 -0
- package/script/src/cli/vercelBuildEnv.js +191 -0
- package/skills/loom/SKILL.md +9 -2
- package/skills/loom-db/SKILL.md +23 -9
package/script/src/cli/mod.js
CHANGED
|
@@ -56,6 +56,7 @@ exports.buildVercelFilesEnvProbeArgs = buildVercelFilesEnvProbeArgs;
|
|
|
56
56
|
exports.setupCloudflareR2 = setupCloudflareR2;
|
|
57
57
|
exports.buildVercelNeonSetupCommand = buildVercelNeonSetupCommand;
|
|
58
58
|
exports.setupVercelNeon = setupVercelNeon;
|
|
59
|
+
exports.setupGithubMigrationCredential = setupGithubMigrationCredential;
|
|
59
60
|
exports.setupGithubVercelRelease = setupGithubVercelRelease;
|
|
60
61
|
exports.initProject = initProject;
|
|
61
62
|
exports.addFeature = addFeature;
|
|
@@ -77,6 +78,8 @@ const node_process_1 = __importDefault(require("node:process"));
|
|
|
77
78
|
const node_util_1 = require("node:util");
|
|
78
79
|
const retention_js_1 = require("../apiKeys/retention.js");
|
|
79
80
|
const projectSkills_js_1 = require("./projectSkills.js");
|
|
81
|
+
const migrationEnv_js_1 = require("./migrationEnv.js");
|
|
82
|
+
const vercelBuildEnv_js_1 = require("./vercelBuildEnv.js");
|
|
80
83
|
exports.DEFAULT_LOOM_RANGE = "^1.0.0";
|
|
81
84
|
exports.LOOM_DEPENDENCY = "@gadicc/loom";
|
|
82
85
|
exports.LOOM_MANIFEST_SCHEMA = "https://loom.gadicc.local/project-manifest.schema.json";
|
|
@@ -112,6 +115,15 @@ const REQUIRED_GITHUB_VERCEL_ID_NAMES = [
|
|
|
112
115
|
"VERCEL_ORG_ID",
|
|
113
116
|
"VERCEL_PROJECT_ID",
|
|
114
117
|
];
|
|
118
|
+
const GITHUB_MIGRATION_DATABASE_SECRET_NAME = "MIGRATION_DATABASE_URL_UNPOOLED";
|
|
119
|
+
const GITHUB_MIGRATION_DATABASE_ROLE_VARIABLE_NAME = "LOOM_MIGRATION_DATABASE_ROLE";
|
|
120
|
+
const LEGACY_GITHUB_MIGRATION_DATABASE_SECRET_NAME = "DATABASE_URL_UNPOOLED";
|
|
121
|
+
const GITHUB_DATABASE_URL_VARIABLE_NAMES = [
|
|
122
|
+
"DATABASE_URL",
|
|
123
|
+
"DATABASE_URL_UNPOOLED",
|
|
124
|
+
"MIGRATION_DATABASE_URL",
|
|
125
|
+
"MIGRATION_DATABASE_URL_UNPOOLED",
|
|
126
|
+
];
|
|
115
127
|
const STALE_GITHUB_RELEASE_SECRET_NAMES = [
|
|
116
128
|
"DATABASE_URL",
|
|
117
129
|
"VERCEL_DEPLOY_HOOK",
|
|
@@ -2842,11 +2854,20 @@ function workflowStepQueriesVercelProductionEnvMetadata(block) {
|
|
|
2842
2854
|
/\s--format(?:=|\s+)json\b/.test(block);
|
|
2843
2855
|
}
|
|
2844
2856
|
function workflowStepPreparesVercelBuildEnv(block) {
|
|
2845
|
-
return /\bvercel-build-env(?:\.mjs)?\b[\s\S]*\bprepare\b/.test(block)
|
|
2857
|
+
return (/\bvercel-build-env(?:\.mjs)?\b[\s\S]*\bprepare\b/.test(block) ||
|
|
2858
|
+
/\bloom\b[\s\S]*\bdb\s+release\s+prepare-build-env\b/.test(block));
|
|
2846
2859
|
}
|
|
2847
2860
|
function workflowStepVerifiesVercelBuildEnv(block) {
|
|
2848
|
-
return /\bvercel-build-env(?:\.mjs)?\b[\s\S]*\bverify\b/.test(block)
|
|
2849
|
-
/\.vercel\/output\b/.test(block);
|
|
2861
|
+
return (/\bvercel-build-env(?:\.mjs)?\b[\s\S]*\bverify\b/.test(block) ||
|
|
2862
|
+
/\bloom\b[\s\S]*\bdb\s+release\s+verify-build-env\b/.test(block)) && /\.vercel\/output\b/.test(block);
|
|
2863
|
+
}
|
|
2864
|
+
function workflowStepVerifiesMigrationEnv(block) {
|
|
2865
|
+
return /\bloom\b[\s\S]*\bdb\s+migrations\s+verify-env\b/.test(block);
|
|
2866
|
+
}
|
|
2867
|
+
function workflowStepVerifiesMigrationEnvWithPulledSnapshot(block) {
|
|
2868
|
+
return workflowStepVerifiesMigrationEnv(block) &&
|
|
2869
|
+
/--env-file(?:=|\s+)["']?\$RUNNER_TEMP\/vercel-production\.env["']?/
|
|
2870
|
+
.test(block);
|
|
2850
2871
|
}
|
|
2851
2872
|
function workflowStepStagesVercelProductionDeployment(block) {
|
|
2852
2873
|
return workflowStepUsesVercelCommand(block, "deploy") &&
|
|
@@ -2882,6 +2903,12 @@ function workflowUsesGithubDatabaseUrlSecret(text) {
|
|
|
2882
2903
|
function workflowUsesGithubUnpooledDatabaseUrlSecret(text) {
|
|
2883
2904
|
return /\$\{\{\s*secrets\.DATABASE_URL_UNPOOLED\s*\}\}/.test(text);
|
|
2884
2905
|
}
|
|
2906
|
+
function workflowUsesGithubMigrationDatabaseUrlSecret(text) {
|
|
2907
|
+
return /\$\{\{\s*secrets\.MIGRATION_DATABASE_URL(?:_UNPOOLED)?\s*\}\}/.test(text);
|
|
2908
|
+
}
|
|
2909
|
+
function workflowUsesGithubDatabaseUrlVariable(text) {
|
|
2910
|
+
return /\$\{\{\s*vars\.(?:MIGRATION_)?DATABASE_URL(?:_UNPOOLED)?\s*\}\}/.test(text);
|
|
2911
|
+
}
|
|
2885
2912
|
function getGithubWorkflowJobBlocks(text) {
|
|
2886
2913
|
const lines = normalizeText(text).split("\n");
|
|
2887
2914
|
const jobsIndex = lines.findIndex((line) => /^\s*jobs:\s*(?:#.*)?$/.test(line));
|
|
@@ -2937,6 +2964,7 @@ function inspectDbMigrationWorkflow(relativePath, workflowText) {
|
|
|
2937
2964
|
const metadataStepIndex = job.stepBlocks.findIndex(workflowStepQueriesVercelProductionEnvMetadata);
|
|
2938
2965
|
const prepareBuildEnvStepIndex = job.stepBlocks.findIndex(workflowStepPreparesVercelBuildEnv);
|
|
2939
2966
|
const verifyBuildEnvStepIndex = job.stepBlocks.findIndex(workflowStepVerifiesVercelBuildEnv);
|
|
2967
|
+
const migrationVerifyStepIndex = job.stepBlocks.findIndex(workflowStepVerifiesMigrationEnv);
|
|
2940
2968
|
const stageStepIndex = job.stepBlocks.findIndex(workflowStepStagesVercelProductionDeployment);
|
|
2941
2969
|
const migrateStepIndex = job.stepBlocks.findIndex(workflowStepRunsDbMigrate);
|
|
2942
2970
|
const migrateWithVercelProductionEnvStepIndex = job.stepBlocks.findIndex(workflowStepRunsDbMigrateWithVercelProductionEnv);
|
|
@@ -2945,6 +2973,9 @@ function inspectDbMigrationWorkflow(relativePath, workflowText) {
|
|
|
2945
2973
|
const migrateStep = migrateStepIndex >= 0
|
|
2946
2974
|
? job.stepBlocks[migrateStepIndex]
|
|
2947
2975
|
: "";
|
|
2976
|
+
const migrationVerifyStep = migrationVerifyStepIndex >= 0
|
|
2977
|
+
? job.stepBlocks[migrationVerifyStepIndex]
|
|
2978
|
+
: "";
|
|
2948
2979
|
const promoteStep = promoteStepIndex >= 0
|
|
2949
2980
|
? job.stepBlocks[promoteStepIndex]
|
|
2950
2981
|
: "";
|
|
@@ -2955,6 +2986,8 @@ function inspectDbMigrationWorkflow(relativePath, workflowText) {
|
|
|
2955
2986
|
hasWorkflowEnvBinding(migrateStep, "DATABASE_URL"),
|
|
2956
2987
|
id: job.id,
|
|
2957
2988
|
metadataStepIndex,
|
|
2989
|
+
migrationVerifyStepIndex,
|
|
2990
|
+
migrationVerifyUsesPulledSnapshot: workflowStepVerifiesMigrationEnvWithPulledSnapshot(migrationVerifyStep),
|
|
2958
2991
|
migrateStepIndex,
|
|
2959
2992
|
migrateStepRestoresPulledEnv: workflowStepRestoresVercelMigrationEnv(migrateStep),
|
|
2960
2993
|
migrateWithVercelProductionEnvStepIndex,
|
|
@@ -2973,8 +3006,10 @@ function inspectDbMigrationWorkflow(relativePath, workflowText) {
|
|
|
2973
3006
|
return {
|
|
2974
3007
|
jobs,
|
|
2975
3008
|
mainPush: githubWorkflowRunsOnMainPush(normalized),
|
|
3009
|
+
usesGithubDatabaseUrlVariable: workflowUsesGithubDatabaseUrlVariable(normalized),
|
|
2976
3010
|
relativePath,
|
|
2977
3011
|
usesGithubDatabaseUrlSecret: workflowUsesGithubDatabaseUrlSecret(normalized),
|
|
3012
|
+
usesGithubMigrationDatabaseUrlSecret: workflowUsesGithubMigrationDatabaseUrlSecret(normalized),
|
|
2978
3013
|
usesGithubUnpooledDatabaseUrlSecret: workflowUsesGithubUnpooledDatabaseUrlSecret(normalized),
|
|
2979
3014
|
usesOldVercelDeployHook: workflowUsesOldVercelDeployHook(normalized),
|
|
2980
3015
|
};
|
|
@@ -2994,7 +3029,8 @@ function dbMigrationJobHasOrderedStagedRelease(job) {
|
|
|
2994
3029
|
function dbMigrationWorkflowIsValid(workflow) {
|
|
2995
3030
|
return workflow.jobs.some((job) => dbMigrationJobHasOrderedStagedRelease(job) &&
|
|
2996
3031
|
job.promoteStepUsesExplicitScope &&
|
|
2997
|
-
workflow.
|
|
3032
|
+
(workflow.usesGithubMigrationDatabaseUrlSecret ||
|
|
3033
|
+
workflow.usesGithubUnpooledDatabaseUrlSecret));
|
|
2998
3034
|
}
|
|
2999
3035
|
function isJsonObject(value) {
|
|
3000
3036
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -3052,6 +3088,13 @@ async function checkDbProductionMigrationFlow(cwd, production) {
|
|
|
3052
3088
|
const validMigrationWorkflow = mainPushWorkflows.find(dbMigrationWorkflowIsValid);
|
|
3053
3089
|
const oldDeployHookWorkflows = mainPushWorkflows.filter((inspection) => inspection.usesOldVercelDeployHook);
|
|
3054
3090
|
const duplicatedDatabaseUrlWorkflows = mainPushWorkflows.filter((inspection) => inspection.usesGithubDatabaseUrlSecret);
|
|
3091
|
+
const databaseUrlVariableWorkflows = mainPushWorkflows.filter((inspection) => inspection.usesGithubDatabaseUrlVariable);
|
|
3092
|
+
const legacyUnpooledSecretWorkflows = mainPushWorkflows.filter((inspection) => inspection.usesGithubUnpooledDatabaseUrlSecret &&
|
|
3093
|
+
!inspection.usesGithubMigrationDatabaseUrlSecret);
|
|
3094
|
+
const invalidMigrationValidationPaths = mainPushWorkflows.flatMap((inspection) => inspection.jobs.flatMap((job) => job.migrationVerifyStepIndex >= 0 &&
|
|
3095
|
+
!job.migrationVerifyUsesPulledSnapshot
|
|
3096
|
+
? [inspection.relativePath]
|
|
3097
|
+
: []));
|
|
3055
3098
|
const vercelCurlWorkflowPaths = mainPushWorkflows.flatMap((inspection) => inspection.jobs.some((job) => job.vercelCurlStepIndex >= 0)
|
|
3056
3099
|
? [inspection.relativePath]
|
|
3057
3100
|
: []);
|
|
@@ -3087,8 +3130,9 @@ async function checkDbProductionMigrationFlow(cwd, production) {
|
|
|
3087
3130
|
findings.push("DB production migration flow does not restore the untouched pulled env before migrations: " +
|
|
3088
3131
|
migrationWorkflowPaths.join(", "));
|
|
3089
3132
|
}
|
|
3090
|
-
else if (!mainPushWorkflows.some((inspection) => inspection.
|
|
3091
|
-
|
|
3133
|
+
else if (!mainPushWorkflows.some((inspection) => inspection.usesGithubMigrationDatabaseUrlSecret ||
|
|
3134
|
+
inspection.usesGithubUnpooledDatabaseUrlSecret)) {
|
|
3135
|
+
findings.push("DB production migration flow is not ready for Sensitive database variables because it lacks a GitHub migration-secret binding: " +
|
|
3092
3136
|
migrationWorkflowPaths.join(", "));
|
|
3093
3137
|
}
|
|
3094
3138
|
else if (mainPushWorkflows.some((inspection) => inspection.jobs.some((job) => dbMigrationJobHasOrderedStagedRelease(job) &&
|
|
@@ -3100,7 +3144,24 @@ async function checkDbProductionMigrationFlow(cwd, production) {
|
|
|
3100
3144
|
findings.push("DB production migration flow does not order build, staged deploy, migration, and promotion correctly: " +
|
|
3101
3145
|
migrationWorkflowPaths.join(", "));
|
|
3102
3146
|
}
|
|
3103
|
-
suggestions.add('Add a production GitHub Actions workflow that runs `vercel pull --environment=production --scope "$VERCEL_ORG_ID"`, preserves an untouched migration snapshot, masks usable pulled values, queries `vercel env ls production --format=json`, adds unique placeholders
|
|
3147
|
+
suggestions.add('Add a production GitHub Actions workflow that runs `vercel pull --environment=production --scope "$VERCEL_ORG_ID"`, preserves an untouched migration snapshot, masks usable pulled values, queries `vercel env ls production --format=json`, adds unique build-only placeholders for unreadable Sensitive values, runs `vercel build --prod --scope "$VERCEL_ORG_ID"`, rejects placeholder leakage from `.vercel/output`, stages with `vercel deploy --prebuilt --prod --skip-domain --scope "$VERCEL_ORG_ID"`, restores the migration snapshot with an optional GitHub `MIGRATION_DATABASE_URL_UNPOOLED` override, runs migrations, then runs `vercel promote --scope "$VERCEL_ORG_ID"`.');
|
|
3148
|
+
}
|
|
3149
|
+
if (invalidMigrationValidationPaths.length) {
|
|
3150
|
+
findings.push("DB production migration validation does not load the preserved Vercel production env snapshot: " +
|
|
3151
|
+
[...new Set(invalidMigrationValidationPaths)].join(", "));
|
|
3152
|
+
suggestions.add('Run `loom db migrations verify-env --env-file "$RUNNER_TEMP/vercel-production.env"` so the optional GitHub migration secret overlays the readable gradual-adoption pull snapshot.');
|
|
3153
|
+
}
|
|
3154
|
+
if (legacyUnpooledSecretWorkflows.length) {
|
|
3155
|
+
warnings.push("DB production migration flow still uses the gradual-adoption GitHub secret `DATABASE_URL_UNPOOLED` instead of the migration-scoped `MIGRATION_DATABASE_URL_UNPOOLED`: " +
|
|
3156
|
+
legacyUnpooledSecretWorkflows.map((workflow) => workflow.relativePath)
|
|
3157
|
+
.join(", "));
|
|
3158
|
+
suggestions.add("When rotating the migration credential, store the new direct URL as the protected GitHub Environment secret `MIGRATION_DATABASE_URL_UNPOOLED` and update the workflow binding. The existing `DATABASE_URL_UNPOOLED` flow remains supported during gradual adoption.");
|
|
3159
|
+
}
|
|
3160
|
+
if (databaseUrlVariableWorkflows.length) {
|
|
3161
|
+
warnings.push("DB production migration flow reads a database URL from a readable GitHub Actions variable: " +
|
|
3162
|
+
databaseUrlVariableWorkflows.map((workflow) => workflow.relativePath)
|
|
3163
|
+
.join(", "));
|
|
3164
|
+
suggestions.add("Rotate that credential into the protected GitHub Environment secret `MIGRATION_DATABASE_URL_UNPOOLED`; keep GitHub variables for non-secret IDs and the expected migration role only.");
|
|
3104
3165
|
}
|
|
3105
3166
|
if (oldDeployHookWorkflows.length) {
|
|
3106
3167
|
findings.push("DB production migration flow still references a Vercel Deploy Hook: " +
|
|
@@ -3111,7 +3172,7 @@ async function checkDbProductionMigrationFlow(cwd, production) {
|
|
|
3111
3172
|
findings.push("DB production migration flow still reads `secrets.DATABASE_URL` from GitHub: " +
|
|
3112
3173
|
duplicatedDatabaseUrlWorkflows.map((workflow) => workflow.relativePath)
|
|
3113
3174
|
.join(", "));
|
|
3114
|
-
suggestions.add("Remove the duplicate GitHub `DATABASE_URL`. While Vercel database variables remain readable, migrate with an untouched `vercel pull` snapshot; before making them Sensitive, store only `
|
|
3175
|
+
suggestions.add("Remove the duplicate GitHub `DATABASE_URL`. While Vercel database variables remain readable, migrate with an untouched `vercel pull` snapshot; before making them Sensitive, store only `MIGRATION_DATABASE_URL_UNPOOLED` in the protected GitHub Environment and expose it to the migration step.");
|
|
3115
3176
|
}
|
|
3116
3177
|
if (vercelCurlWorkflowPaths.length) {
|
|
3117
3178
|
findings.push("DB production migration flow still uses beta `vercel curl` for smoke checks: " +
|
|
@@ -5493,6 +5554,32 @@ function createGithubReleaseConfigCheckStep(state, context) {
|
|
|
5493
5554
|
suggestions.add(`After confirming no other workflow uses it, run \`gh secret delete ${staleSecret}\`.`);
|
|
5494
5555
|
}
|
|
5495
5556
|
}
|
|
5557
|
+
const hasCanonicalMigrationSecret = environmentSecrets.names.has(GITHUB_MIGRATION_DATABASE_SECRET_NAME);
|
|
5558
|
+
const hasRepositoryCanonicalMigrationSecret = repoSecrets.names.has(GITHUB_MIGRATION_DATABASE_SECRET_NAME);
|
|
5559
|
+
const hasLegacyMigrationSecret = collectionHasName(LEGACY_GITHUB_MIGRATION_DATABASE_SECRET_NAME, environmentSecrets, repoSecrets);
|
|
5560
|
+
if (!hasCanonicalMigrationSecret) {
|
|
5561
|
+
if (hasRepositoryCanonicalMigrationSecret) {
|
|
5562
|
+
warnings.push(`GitHub Actions stores ${GITHUB_MIGRATION_DATABASE_SECRET_NAME} at repository scope instead of the protected ${PRODUCTION_GITHUB_ENVIRONMENT} environment.`);
|
|
5563
|
+
}
|
|
5564
|
+
else if (hasLegacyMigrationSecret) {
|
|
5565
|
+
warnings.push(`GitHub Actions still uses the gradual-adoption migration secret ${LEGACY_GITHUB_MIGRATION_DATABASE_SECRET_NAME}; rotate into ${GITHUB_MIGRATION_DATABASE_SECRET_NAME} when convenient.`);
|
|
5566
|
+
}
|
|
5567
|
+
else {
|
|
5568
|
+
warnings.push(`GitHub Actions has no dedicated ${GITHUB_MIGRATION_DATABASE_SECRET_NAME} production secret. The existing pulled Vercel URL remains supported while it is readable.`);
|
|
5569
|
+
}
|
|
5570
|
+
suggestions.add("Provision a dedicated direct migration credential, then run `loom db migrations setup-github` to store it without making the Vercel integration variables Sensitive yet.");
|
|
5571
|
+
}
|
|
5572
|
+
if (hasCanonicalMigrationSecret &&
|
|
5573
|
+
findGithubVariableValue(GITHUB_MIGRATION_DATABASE_ROLE_VARIABLE_NAME, environmentVariables, repoVariables) === null) {
|
|
5574
|
+
warnings.push(`GitHub Actions has ${GITHUB_MIGRATION_DATABASE_SECRET_NAME} but no ${GITHUB_MIGRATION_DATABASE_ROLE_VARIABLE_NAME} metadata variable.`);
|
|
5575
|
+
suggestions.add("Run `loom db migrations setup-github` with the migration URL loaded in the environment so Loom can record the expected non-secret role.");
|
|
5576
|
+
}
|
|
5577
|
+
for (const name of GITHUB_DATABASE_URL_VARIABLE_NAMES) {
|
|
5578
|
+
if (collectionHasName(name, environmentVariables, repoVariables)) {
|
|
5579
|
+
warnings.push(`GitHub Actions stores database credential ${name} as a readable variable.`);
|
|
5580
|
+
suggestions.add(`Rotate ${name} into the protected ${PRODUCTION_GITHUB_ENVIRONMENT} Environment secret ${GITHUB_MIGRATION_DATABASE_SECRET_NAME}, then delete the readable variable.`);
|
|
5581
|
+
}
|
|
5582
|
+
}
|
|
5496
5583
|
if (collectionHasName("VERCEL_DEPLOY_HOOK", environmentSecrets, repoSecrets) ||
|
|
5497
5584
|
[...STALE_GITHUB_RELEASE_SECRET_NAMES].some((name) => name.startsWith("VERCEL_DEPLOY") &&
|
|
5498
5585
|
collectionHasName(name, environmentSecrets, repoSecrets))) {
|
|
@@ -6083,6 +6170,54 @@ async function setupVercelNeon(cwd, options = {}) {
|
|
|
6083
6170
|
notes,
|
|
6084
6171
|
};
|
|
6085
6172
|
}
|
|
6173
|
+
/**
|
|
6174
|
+
* Stores an already-provisioned direct migration URL in a protected GitHub
|
|
6175
|
+
* Environment without persisting or printing the credential.
|
|
6176
|
+
*/
|
|
6177
|
+
async function setupGithubMigrationCredential(cwd, options = {}) {
|
|
6178
|
+
const commandRunner = options.commandRunner ?? defaultCommandRunner;
|
|
6179
|
+
const env = options.env ?? node_process_1.default.env;
|
|
6180
|
+
const environment = options.environment ?? PRODUCTION_GITHUB_ENVIRONMENT;
|
|
6181
|
+
const migration = (0, migrationEnv_js_1.resolveMigrationEnvironment)(env);
|
|
6182
|
+
if (!migration.envName.startsWith("MIGRATION_")) {
|
|
6183
|
+
throw new Error(`Load ${GITHUB_MIGRATION_DATABASE_SECRET_NAME} in the process environment before running \`loom db migrations setup-github\`; application database fallbacks are not copied into GitHub.`);
|
|
6184
|
+
}
|
|
6185
|
+
if (!migration.direct) {
|
|
6186
|
+
throw new Error(`${migration.envName} appears pooled. Configure a direct, unpooled migration connection before storing it in GitHub.`);
|
|
6187
|
+
}
|
|
6188
|
+
const githubCli = await detectGithubCliCommand(cwd, commandRunner, env);
|
|
6189
|
+
if (!githubCli.command) {
|
|
6190
|
+
throw new Error("GitHub CLI is not available. Install and authenticate `gh` before running `loom db migrations setup-github`.");
|
|
6191
|
+
}
|
|
6192
|
+
await requireCommand(`Set GitHub ${GITHUB_MIGRATION_DATABASE_SECRET_NAME} secret`, commandRunner, githubCli.command, [
|
|
6193
|
+
"secret",
|
|
6194
|
+
"set",
|
|
6195
|
+
GITHUB_MIGRATION_DATABASE_SECRET_NAME,
|
|
6196
|
+
"--env",
|
|
6197
|
+
environment,
|
|
6198
|
+
], {
|
|
6199
|
+
cwd,
|
|
6200
|
+
env,
|
|
6201
|
+
input: env[migration.envName],
|
|
6202
|
+
stdio: "pipe",
|
|
6203
|
+
});
|
|
6204
|
+
await requireCommand(`Set GitHub ${GITHUB_MIGRATION_DATABASE_ROLE_VARIABLE_NAME} variable`, commandRunner, githubCli.command, [
|
|
6205
|
+
"variable",
|
|
6206
|
+
"set",
|
|
6207
|
+
GITHUB_MIGRATION_DATABASE_ROLE_VARIABLE_NAME,
|
|
6208
|
+
"--env",
|
|
6209
|
+
environment,
|
|
6210
|
+
"--body",
|
|
6211
|
+
migration.role,
|
|
6212
|
+
], { cwd, env, stdio: "pipe" });
|
|
6213
|
+
return {
|
|
6214
|
+
notes: [
|
|
6215
|
+
`Stored ${GITHUB_MIGRATION_DATABASE_SECRET_NAME} in the protected GitHub \`${environment}\` environment.`,
|
|
6216
|
+
`Recorded migration role ${migration.role} as ${GITHUB_MIGRATION_DATABASE_ROLE_VARIABLE_NAME}.`,
|
|
6217
|
+
"Vercel application database variables were not changed.",
|
|
6218
|
+
],
|
|
6219
|
+
};
|
|
6220
|
+
}
|
|
6086
6221
|
async function setupGithubVercelRelease(cwd, options = {}) {
|
|
6087
6222
|
const commandRunner = options.commandRunner ?? defaultCommandRunner;
|
|
6088
6223
|
const env = options.env ?? node_process_1.default.env;
|
|
@@ -8545,7 +8680,11 @@ function printHelp({ out }) {
|
|
|
8545
8680
|
out(" db schemas sync Materialize active Loom-managed DB schema blueprints into app-local schema files.");
|
|
8546
8681
|
out(" db neon setup Provision and connect a Vercel-managed Neon database for Production and Preview.");
|
|
8547
8682
|
out(" db neon check Run the DB/Neon network checks registered for the active DB feature.");
|
|
8683
|
+
out(" db migrations verify-env Validate migration URL precedence and role metadata without printing credentials. Accepts --env-file <path>.");
|
|
8684
|
+
out(" db migrations setup-github Store an existing direct migration URL as a protected GitHub Environment secret.");
|
|
8548
8685
|
out(" db release setup-github Create/update GitHub production release config for staged Vercel deploys.");
|
|
8686
|
+
out(" db release prepare-build-env <env> <metadata> <policy> <manifest> Prepare metadata-backed placeholders for an external Vercel build.");
|
|
8687
|
+
out(" db release verify-build-env <output> <manifest> Reject build-only placeholders in a deployable Vercel artifact.");
|
|
8549
8688
|
out(" dev local Enable local Loom development using a managed file: override in pnpm-workspace.yaml.");
|
|
8550
8689
|
out(" dev sync Rebuild the local Loom package and refresh this project's pnpm install when the managed local-dev override is active.");
|
|
8551
8690
|
out(" dev published Remove the managed local-dev override and return to the published dependency.");
|
|
@@ -8574,6 +8713,8 @@ function printHelp({ out }) {
|
|
|
8574
8713
|
out(" --configure-secrets Ask Vercel to prompt securely for missing R2 credentials; never replaces existing credentials.");
|
|
8575
8714
|
out(" --repair Apply declared non-secret Files provider drift; never deletes resources or rotates credentials.");
|
|
8576
8715
|
out(" --token-name <name> Override the Vercel token name for `loom db release setup-github`.");
|
|
8716
|
+
out(" --environment <name> GitHub Environment for migration credential setup (default production).");
|
|
8717
|
+
out(" --env-file <path> Preserved env snapshot for `db migrations verify-env`; process values take precedence.");
|
|
8577
8718
|
out(" --resource <name> Permission resource for API-key integration.");
|
|
8578
8719
|
out(" --action <name> Permission action for API-key integration.");
|
|
8579
8720
|
out(" --allow-query Allow the integration's explicit query credential transport.");
|
|
@@ -9100,14 +9241,39 @@ async function runDbNeon(cwd, command, io, options) {
|
|
|
9100
9241
|
return 1;
|
|
9101
9242
|
}
|
|
9102
9243
|
}
|
|
9103
|
-
async function runDbRelease(cwd, command, io, options) {
|
|
9244
|
+
async function runDbRelease(cwd, command, args, io, options) {
|
|
9104
9245
|
if (!command) {
|
|
9105
9246
|
io.err("Missing release subcommand. Example: `loom db release setup-github`.");
|
|
9106
9247
|
return 1;
|
|
9107
9248
|
}
|
|
9108
9249
|
switch (command) {
|
|
9250
|
+
case "prepare-build-env": {
|
|
9251
|
+
if (args.length !== 4) {
|
|
9252
|
+
io.err("Usage: loom db release prepare-build-env <env-file> <metadata-file> <policy-file> <manifest-file>");
|
|
9253
|
+
return 1;
|
|
9254
|
+
}
|
|
9255
|
+
(0, vercelBuildEnv_js_1.prepareVercelBuildEnvironment)({
|
|
9256
|
+
envFile: (0, node_path_1.resolve)(cwd, args[0]),
|
|
9257
|
+
manifestFile: (0, node_path_1.resolve)(cwd, args[3]),
|
|
9258
|
+
metadataFile: (0, node_path_1.resolve)(cwd, args[1]),
|
|
9259
|
+
policyFile: (0, node_path_1.resolve)(cwd, args[2]),
|
|
9260
|
+
}, io);
|
|
9261
|
+
return 0;
|
|
9262
|
+
}
|
|
9263
|
+
case "verify-build-env": {
|
|
9264
|
+
if (args.length !== 2) {
|
|
9265
|
+
io.err("Usage: loom db release verify-build-env <output-directory> <manifest-file>");
|
|
9266
|
+
return 1;
|
|
9267
|
+
}
|
|
9268
|
+
(0, vercelBuildEnv_js_1.verifyVercelBuildArtifact)({
|
|
9269
|
+
manifestFile: (0, node_path_1.resolve)(cwd, args[1]),
|
|
9270
|
+
outputDirectory: (0, node_path_1.resolve)(cwd, args[0]),
|
|
9271
|
+
}, io);
|
|
9272
|
+
return 0;
|
|
9273
|
+
}
|
|
9109
9274
|
case "setup-github": {
|
|
9110
9275
|
const result = await setupGithubVercelRelease(cwd, {
|
|
9276
|
+
environment: options.environment,
|
|
9111
9277
|
io,
|
|
9112
9278
|
tokenName: options.tokenName,
|
|
9113
9279
|
});
|
|
@@ -9123,6 +9289,41 @@ async function runDbRelease(cwd, command, io, options) {
|
|
|
9123
9289
|
return 1;
|
|
9124
9290
|
}
|
|
9125
9291
|
}
|
|
9292
|
+
async function runDbMigrations(cwd, command, io, options) {
|
|
9293
|
+
if (!command) {
|
|
9294
|
+
io.err("Missing migrations subcommand. Example: `loom db migrations verify-env`.");
|
|
9295
|
+
return 1;
|
|
9296
|
+
}
|
|
9297
|
+
switch (command) {
|
|
9298
|
+
case "setup-github": {
|
|
9299
|
+
const result = await setupGithubMigrationCredential(cwd, {
|
|
9300
|
+
environment: options.environment,
|
|
9301
|
+
});
|
|
9302
|
+
for (const note of result.notes) {
|
|
9303
|
+
io.out(`Note: ${note}`);
|
|
9304
|
+
}
|
|
9305
|
+
io.out("Next step: update the release workflow to bind `secrets.MIGRATION_DATABASE_URL_UNPOOLED`, then run `loom check --production --network`.");
|
|
9306
|
+
return 0;
|
|
9307
|
+
}
|
|
9308
|
+
case "verify-env": {
|
|
9309
|
+
const result = options.envFile
|
|
9310
|
+
? (0, migrationEnv_js_1.resolveMigrationEnvironmentFromEnvFile)((0, node_path_1.resolve)(cwd, options.envFile), node_process_1.default.env)
|
|
9311
|
+
: (0, migrationEnv_js_1.resolveMigrationEnvironment)(node_process_1.default.env);
|
|
9312
|
+
io.out(`Migration database environment is usable: ${result.envName} selects role ${result.role} and database ${result.database}.`);
|
|
9313
|
+
if (!result.envName.startsWith("MIGRATION_")) {
|
|
9314
|
+
io.out("Warning: using the gradual-adoption application database fallback; prefer MIGRATION_DATABASE_URL_UNPOOLED after provisioning a dedicated migration credential.");
|
|
9315
|
+
}
|
|
9316
|
+
if (!result.direct) {
|
|
9317
|
+
io.out("Warning: the selected URL appears pooled; migrations should prefer a direct, unpooled connection.");
|
|
9318
|
+
}
|
|
9319
|
+
return 0;
|
|
9320
|
+
}
|
|
9321
|
+
default:
|
|
9322
|
+
io.err(`Unknown migrations subcommand: ${command}`);
|
|
9323
|
+
io.err("Run `loom --help` for usage.");
|
|
9324
|
+
return 1;
|
|
9325
|
+
}
|
|
9326
|
+
}
|
|
9126
9327
|
async function runDb(cwd, command, args, io, options = {}) {
|
|
9127
9328
|
if (!command) {
|
|
9128
9329
|
io.err("Missing db subcommand. Example: `loom db schema-gen`.");
|
|
@@ -9137,8 +9338,10 @@ async function runDb(cwd, command, args, io, options = {}) {
|
|
|
9137
9338
|
return await runDbSchemas(cwd, args[0], io);
|
|
9138
9339
|
case "neon":
|
|
9139
9340
|
return await runDbNeon(cwd, args[0], io, options);
|
|
9341
|
+
case "migrations":
|
|
9342
|
+
return await runDbMigrations(cwd, args[0], io, options);
|
|
9140
9343
|
case "release":
|
|
9141
|
-
return await runDbRelease(cwd, args[0], io, options);
|
|
9344
|
+
return await runDbRelease(cwd, args[0], args.slice(1), io, options);
|
|
9142
9345
|
default:
|
|
9143
9346
|
io.err(`Unknown db subcommand: ${command}`);
|
|
9144
9347
|
io.err("Run `loom --help` for usage.");
|
|
@@ -9284,6 +9487,8 @@ async function runCli(args = node_process_1.default.argv.slice(2), io = {
|
|
|
9284
9487
|
"cleanup-batch-size": { type: "string" },
|
|
9285
9488
|
"configure-secrets": { type: "boolean" },
|
|
9286
9489
|
cwd: { type: "string" },
|
|
9490
|
+
environment: { type: "string" },
|
|
9491
|
+
"env-file": { type: "string" },
|
|
9287
9492
|
force: { type: "boolean" },
|
|
9288
9493
|
help: { short: "h", type: "boolean" },
|
|
9289
9494
|
jurisdiction: { type: "string" },
|
|
@@ -9386,6 +9591,8 @@ async function runCli(args = node_process_1.default.argv.slice(2), io = {
|
|
|
9386
9591
|
case "db":
|
|
9387
9592
|
return await runDb(cwd, arg1, [arg2, ...rest].filter(Boolean), io, {
|
|
9388
9593
|
name: parsed.values.name,
|
|
9594
|
+
environment: parsed.values.environment,
|
|
9595
|
+
envFile: parsed.values["env-file"],
|
|
9389
9596
|
noColor: parsed.values["no-color"],
|
|
9390
9597
|
noProgress: parsed.values["no-progress"],
|
|
9391
9598
|
neonAuth: parsed.values["neon-auth"],
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
type BuildPlaceholder = {
|
|
2
|
+
key: string;
|
|
3
|
+
marker: string;
|
|
4
|
+
requirement: string;
|
|
5
|
+
};
|
|
6
|
+
type CliOutput = {
|
|
7
|
+
out: (line: string) => void;
|
|
8
|
+
};
|
|
9
|
+
export declare function isUsablePulledValue(value: string | undefined): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Validates required Production variables and fills unreadable Sensitive values
|
|
12
|
+
* with unique build-only placeholders without replacing readable pulled values.
|
|
13
|
+
*/
|
|
14
|
+
export declare function prepareVercelBuildEnvironment({ envFile, manifestFile, metadataFile, policyFile, }: {
|
|
15
|
+
envFile: string;
|
|
16
|
+
manifestFile: string;
|
|
17
|
+
metadataFile: string;
|
|
18
|
+
policyFile: string;
|
|
19
|
+
}, io?: CliOutput): {
|
|
20
|
+
placeholders: BuildPlaceholder[];
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Rejects a Vercel artifact containing any unique build-only marker.
|
|
24
|
+
*/
|
|
25
|
+
export declare function verifyVercelBuildArtifact({ manifestFile, outputDirectory, }: {
|
|
26
|
+
manifestFile: string;
|
|
27
|
+
outputDirectory: string;
|
|
28
|
+
}, io?: CliOutput): void;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=vercelBuildEnv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vercelBuildEnv.d.ts","sourceRoot":"","sources":["../../../src/src/cli/vercelBuildEnv.ts"],"names":[],"mappings":"AAyBA,KAAK,gBAAgB,GAAG;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAMF,KAAK,SAAS,GAAG;IACf,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7B,CAAC;AAgBF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,WAG5D;AAmFD;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,EACE,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,UAAU,GACX,EAAE;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACpB,EACD,EAAE,GAAE,SAAgD;;EAoGrD;AAeD;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,EACE,YAAY,EACZ,eAAe,GAChB,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;CACzB,EACD,EAAE,GAAE,SAAgD,QAyCrD"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isUsablePulledValue = isUsablePulledValue;
|
|
4
|
+
exports.prepareVercelBuildEnvironment = prepareVercelBuildEnvironment;
|
|
5
|
+
exports.verifyVercelBuildArtifact = verifyVercelBuildArtifact;
|
|
6
|
+
const node_crypto_1 = require("node:crypto");
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const node_path_1 = require("node:path");
|
|
9
|
+
const node_util_1 = require("node:util");
|
|
10
|
+
function readJson(path) {
|
|
11
|
+
return JSON.parse((0, node_fs_1.readFileSync)(path, "utf8"));
|
|
12
|
+
}
|
|
13
|
+
function productionEntries(envs, keys) {
|
|
14
|
+
const keySet = new Set(keys);
|
|
15
|
+
return envs.filter((entry) => {
|
|
16
|
+
const targets = Array.isArray(entry.target) ? entry.target : [entry.target];
|
|
17
|
+
return typeof entry.key === "string" &&
|
|
18
|
+
keySet.has(entry.key) &&
|
|
19
|
+
targets.includes("production");
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function isUsablePulledValue(value) {
|
|
23
|
+
return Boolean(value?.trim()) &&
|
|
24
|
+
!/(?:sensitive|redacted)/i.test(value ?? "");
|
|
25
|
+
}
|
|
26
|
+
function buildPlaceholder(kind) {
|
|
27
|
+
const marker = `loom-build-only-${(0, node_crypto_1.randomBytes)(32).toString("hex")}`;
|
|
28
|
+
if (kind === "secret") {
|
|
29
|
+
return { marker, value: marker };
|
|
30
|
+
}
|
|
31
|
+
if (kind === "postgres-url") {
|
|
32
|
+
return {
|
|
33
|
+
marker,
|
|
34
|
+
value: `postgresql://build:${marker}@127.0.0.1:1/build?sslmode=disable`,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
throw new Error(`Unsupported placeholder kind: ${kind}`);
|
|
38
|
+
}
|
|
39
|
+
function setEnvValue(source, key, value) {
|
|
40
|
+
if (!/^[A-Z_][A-Z0-9_]*$/.test(key)) {
|
|
41
|
+
throw new Error(`Invalid environment variable key in policy: ${key}`);
|
|
42
|
+
}
|
|
43
|
+
const line = `${key}=${JSON.stringify(value)}`;
|
|
44
|
+
const pattern = new RegExp(`^${key}=.*$`, "m");
|
|
45
|
+
if (pattern.test(source)) {
|
|
46
|
+
return source.replace(pattern, line);
|
|
47
|
+
}
|
|
48
|
+
return `${source.trimEnd()}\n${line}\n`;
|
|
49
|
+
}
|
|
50
|
+
function parsePolicyRequirement(value, index) {
|
|
51
|
+
if (typeof value !== "object" || value === null) {
|
|
52
|
+
throw new Error(`Vercel environment requirement ${index + 1} is invalid.`);
|
|
53
|
+
}
|
|
54
|
+
const requirement = value;
|
|
55
|
+
const name = typeof requirement.name === "string" &&
|
|
56
|
+
requirement.name.trim()
|
|
57
|
+
? requirement.name
|
|
58
|
+
: `requirement ${index + 1}`;
|
|
59
|
+
const keys = Array.isArray(requirement.keys)
|
|
60
|
+
? requirement.keys.filter((key) => typeof key === "string" && Boolean(key))
|
|
61
|
+
: [];
|
|
62
|
+
if (keys.length === 0) {
|
|
63
|
+
throw new Error(`Environment requirement "${name}" has no keys.`);
|
|
64
|
+
}
|
|
65
|
+
let placeholder;
|
|
66
|
+
if (requirement.placeholder !== undefined) {
|
|
67
|
+
if (typeof requirement.placeholder !== "object" ||
|
|
68
|
+
requirement.placeholder === null ||
|
|
69
|
+
typeof requirement.placeholder.key !== "string" ||
|
|
70
|
+
typeof requirement.placeholder.kind !== "string") {
|
|
71
|
+
throw new Error(`Environment requirement "${name}" has an invalid placeholder policy.`);
|
|
72
|
+
}
|
|
73
|
+
placeholder = {
|
|
74
|
+
key: requirement.placeholder.key,
|
|
75
|
+
kind: requirement.placeholder.kind,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
keys,
|
|
80
|
+
name,
|
|
81
|
+
placeholder,
|
|
82
|
+
sensitive: requirement.sensitive === true,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Validates required Production variables and fills unreadable Sensitive values
|
|
87
|
+
* with unique build-only placeholders without replacing readable pulled values.
|
|
88
|
+
*/
|
|
89
|
+
function prepareVercelBuildEnvironment({ envFile, manifestFile, metadataFile, policyFile, }, io = { out: (line) => console.log(line) }) {
|
|
90
|
+
let envSource = (0, node_fs_1.readFileSync)(envFile, "utf8");
|
|
91
|
+
const pulledValues = (0, node_util_1.parseEnv)(envSource);
|
|
92
|
+
const metadata = readJson(metadataFile);
|
|
93
|
+
const policy = readJson(policyFile);
|
|
94
|
+
const envs = typeof metadata === "object" && metadata !== null
|
|
95
|
+
? metadata.envs
|
|
96
|
+
: undefined;
|
|
97
|
+
if (!Array.isArray(envs)) {
|
|
98
|
+
throw new Error("Vercel metadata did not contain an envs array.");
|
|
99
|
+
}
|
|
100
|
+
if (!Array.isArray(policy.requirements)) {
|
|
101
|
+
throw new Error("Vercel environment policy has no requirements array.");
|
|
102
|
+
}
|
|
103
|
+
const placeholders = [];
|
|
104
|
+
for (const [index, value] of policy.requirements.entries()) {
|
|
105
|
+
const requirement = parsePolicyRequirement(value, index);
|
|
106
|
+
const entries = productionEntries(envs, requirement.keys);
|
|
107
|
+
if (entries.length === 0) {
|
|
108
|
+
throw new Error(`Missing Vercel Production variable for ${requirement.name}: ${requirement.keys.join(" or ")}`);
|
|
109
|
+
}
|
|
110
|
+
const nonSensitive = entries.filter((entry) => entry.type !== "sensitive");
|
|
111
|
+
if (requirement.sensitive && nonSensitive.length > 0) {
|
|
112
|
+
throw new Error(`Vercel Production variable must be Sensitive for ${requirement.name}: ${nonSensitive
|
|
113
|
+
.map((entry) => entry.key)
|
|
114
|
+
.join(", ")}`);
|
|
115
|
+
}
|
|
116
|
+
const pulledKey = requirement.keys.find((key) => isUsablePulledValue(pulledValues[key]));
|
|
117
|
+
if (pulledKey) {
|
|
118
|
+
io.out(`Verified ${requirement.name} from vercel pull (${pulledKey}).`);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const unreadableSensitive = entries.every((entry) => entry.type === "sensitive");
|
|
122
|
+
if (!unreadableSensitive) {
|
|
123
|
+
throw new Error(`Vercel Production variable is empty after pull for ${requirement.name}: ${requirement.keys.join(" or ")}`);
|
|
124
|
+
}
|
|
125
|
+
if (!requirement.placeholder) {
|
|
126
|
+
throw new Error(`Sensitive Vercel Production variable has no build placeholder policy for ${requirement.name}.`);
|
|
127
|
+
}
|
|
128
|
+
const placeholderKey = requirement.placeholder.key;
|
|
129
|
+
if (isUsablePulledValue(pulledValues[placeholderKey])) {
|
|
130
|
+
io.out(`Preserved pulled ${placeholderKey} for ${requirement.name}.`);
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const placeholder = buildPlaceholder(requirement.placeholder.kind);
|
|
134
|
+
envSource = setEnvValue(envSource, placeholderKey, placeholder.value);
|
|
135
|
+
pulledValues[placeholderKey] = placeholder.value;
|
|
136
|
+
placeholders.push({
|
|
137
|
+
key: placeholderKey,
|
|
138
|
+
marker: placeholder.marker,
|
|
139
|
+
requirement: requirement.name,
|
|
140
|
+
});
|
|
141
|
+
io.out(`Added a build-only ${placeholderKey} placeholder for ${requirement.name}.`);
|
|
142
|
+
}
|
|
143
|
+
(0, node_fs_1.writeFileSync)(envFile, envSource, { mode: 0o600 });
|
|
144
|
+
(0, node_fs_1.writeFileSync)(manifestFile, `${JSON.stringify({ placeholders }, null, 2)}\n`, { mode: 0o600 });
|
|
145
|
+
(0, node_fs_1.chmodSync)(envFile, 0o600);
|
|
146
|
+
(0, node_fs_1.chmodSync)(manifestFile, 0o600);
|
|
147
|
+
return { placeholders };
|
|
148
|
+
}
|
|
149
|
+
function regularFiles(root) {
|
|
150
|
+
const files = [];
|
|
151
|
+
for (const entry of (0, node_fs_1.readdirSync)(root, { withFileTypes: true })) {
|
|
152
|
+
const path = (0, node_path_1.join)(root, entry.name);
|
|
153
|
+
if (entry.isDirectory()) {
|
|
154
|
+
files.push(...regularFiles(path));
|
|
155
|
+
}
|
|
156
|
+
else if (entry.isFile()) {
|
|
157
|
+
files.push(path);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return files;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Rejects a Vercel artifact containing any unique build-only marker.
|
|
164
|
+
*/
|
|
165
|
+
function verifyVercelBuildArtifact({ manifestFile, outputDirectory, }, io = { out: (line) => console.log(line) }) {
|
|
166
|
+
const manifest = readJson(manifestFile);
|
|
167
|
+
if (!Array.isArray(manifest.placeholders)) {
|
|
168
|
+
throw new Error("Build placeholder manifest is invalid.");
|
|
169
|
+
}
|
|
170
|
+
const placeholders = manifest.placeholders.filter((value) => typeof value === "object" &&
|
|
171
|
+
value !== null &&
|
|
172
|
+
typeof value.key === "string" &&
|
|
173
|
+
typeof value.marker === "string" &&
|
|
174
|
+
typeof value.requirement === "string");
|
|
175
|
+
if (placeholders.length !== manifest.placeholders.length) {
|
|
176
|
+
throw new Error("Build placeholder manifest is invalid.");
|
|
177
|
+
}
|
|
178
|
+
const leaks = [];
|
|
179
|
+
for (const path of regularFiles(outputDirectory)) {
|
|
180
|
+
const contents = (0, node_fs_1.readFileSync)(path);
|
|
181
|
+
for (const placeholder of placeholders) {
|
|
182
|
+
if (contents.includes(Buffer.from(placeholder.marker))) {
|
|
183
|
+
leaks.push(`${placeholder.key}: ${path}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (leaks.length > 0) {
|
|
188
|
+
throw new Error(`Build-only environment placeholder reached the deployable artifact:\n${leaks.join("\n")}`);
|
|
189
|
+
}
|
|
190
|
+
io.out(`Verified ${placeholders.length} build-only placeholder(s) are absent from ${(0, node_path_1.basename)(outputDirectory)}.`);
|
|
191
|
+
}
|
package/skills/loom/SKILL.md
CHANGED
|
@@ -68,8 +68,15 @@ from the consumer's working directory.
|
|
|
68
68
|
values, add unique build-only placeholders only for confirmed Sensitive
|
|
69
69
|
entries, and reject an artifact containing any placeholder marker. Preserve an
|
|
70
70
|
untouched pull snapshot for migrations; once database variables are Sensitive,
|
|
71
|
-
overlay a separately governed GitHub `
|
|
72
|
-
the migration command.
|
|
71
|
+
overlay a separately governed GitHub `MIGRATION_DATABASE_URL_UNPOOLED` secret
|
|
72
|
+
only for migration validation and the migration command. Readable pulled URLs
|
|
73
|
+
and the legacy `DATABASE_URL_UNPOOLED` secret remain supported during gradual
|
|
74
|
+
adoption.
|
|
75
|
+
- Validate the migration boundary with
|
|
76
|
+
`loom db migrations verify-env
|
|
77
|
+
--env-file "$RUNNER_TEMP/vercel-production.env"`
|
|
78
|
+
so the optional protected migration secret overlays the untouched readable
|
|
79
|
+
pull snapshot instead of replacing that gradual-adoption fallback.
|
|
73
80
|
|
|
74
81
|
## Re-establishing work context
|
|
75
82
|
|