@gadicc/loom 1.25.0 → 1.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runGithubReleaseTrustCommand = runGithubReleaseTrustCommand;
4
+ const promises_1 = require("node:fs/promises");
5
+ const node_path_1 = require("node:path");
6
+ const releaseConfig_js_1 = require("./releaseConfig.js");
7
+ const releaseTrust_js_1 = require("./releaseTrust.js");
8
+ function object(value) {
9
+ return value !== null && typeof value === "object" && !Array.isArray(value);
10
+ }
11
+ function json(text, description) {
12
+ try {
13
+ const value = JSON.parse(text);
14
+ if (object(value))
15
+ return value;
16
+ }
17
+ catch {
18
+ // Provider stdout can contain credentials; never reproduce it in an error.
19
+ }
20
+ throw new Error(`Invalid ${description} JSON.`);
21
+ }
22
+ /**
23
+ * Plan, apply, or verify one reviewed GitHub production HTTP trust rule.
24
+ * Planning only reads providers and writes an exclusive local proposal file.
25
+ * Apply checks current state twice, requires the reviewed proposal digest, and
26
+ * verifies the exact resulting provider state. It never creates a deploy token.
27
+ */
28
+ async function runGithubReleaseTrustCommand(action, args, options) {
29
+ const requiredCount = action === "plan" || action === "apply" ? 2 : 1;
30
+ if (args.length !== requiredCount) {
31
+ throw new Error(action === "plan"
32
+ ? "Usage: loom db release trust-plan <workflow-path> <plan-file> [--environment <name>]"
33
+ : action === "apply"
34
+ ? "Usage: loom db release trust-apply <plan-file> <reviewed-plan-sha256>"
35
+ : "Usage: loom db release trust-check <plan-file>");
36
+ }
37
+ const { cwd, env, commandRunner, vercelCli } = options;
38
+ async function command(command, args, input) {
39
+ let result;
40
+ try {
41
+ result = await commandRunner(command, args, {
42
+ cwd,
43
+ env,
44
+ ...(input === undefined ? {} : { input }),
45
+ stdio: "pipe",
46
+ });
47
+ }
48
+ catch {
49
+ throw new Error("Trusted Sources provider command did not complete.");
50
+ }
51
+ if (result.code !== 0) {
52
+ throw new Error(`Trusted Sources provider command failed (exit ${result.code}); inspect provider state before retrying an apply.`);
53
+ }
54
+ return result.stdout;
55
+ }
56
+ const link = json(await (0, promises_1.readFile)((0, node_path_1.resolve)(cwd, ".vercel/project.json"), "utf8"), "local Vercel project link");
57
+ if (typeof link.orgId !== "string" ||
58
+ typeof link.projectId !== "string" ||
59
+ !/^[A-Za-z0-9_-]+(?![\s\S])/.test(link.orgId) ||
60
+ !/^[A-Za-z0-9_-]+(?![\s\S])/.test(link.projectId))
61
+ throw new Error("Invalid local Vercel project link.");
62
+ const manifest = json(await (0, promises_1.readFile)((0, node_path_1.resolve)(cwd, "loom.json"), "utf8"), "Loom manifest");
63
+ const db = object(manifest.features) && object(manifest.features.db)
64
+ ? manifest.features.db
65
+ : undefined;
66
+ const release = db && object(db.config) ? db.config.release : undefined;
67
+ const productionBranch = (0, releaseConfig_js_1.resolveProductionBranch)(release);
68
+ const repository = json(await command("gh", ["api", "repos/:owner/:repo"]), "GitHub repository");
69
+ if (typeof repository.full_name !== "string" ||
70
+ (typeof repository.id !== "string" &&
71
+ !(typeof repository.id === "number" &&
72
+ Number.isSafeInteger(repository.id))))
73
+ throw new Error("Invalid canonical GitHub repository identity.");
74
+ const providerPath = (version) => `/v${version}/projects/${link.projectId}?teamId=${encodeURIComponent(link.orgId)}`;
75
+ const readProject = async () => json(await command(vercelCli, [
76
+ "api",
77
+ providerPath(10),
78
+ "--method",
79
+ "GET",
80
+ "--raw",
81
+ ]), "Vercel project");
82
+ if (action === "plan") {
83
+ if (typeof options.environment !== "string") {
84
+ throw new Error("A resolved GitHub environment is required for planning.");
85
+ }
86
+ // Requiring a local file avoids authorizing a misspelled/nonexistent workflow.
87
+ const workflowPath = args[0];
88
+ const target = {
89
+ projectId: link.projectId,
90
+ teamId: link.orgId,
91
+ repository: repository.full_name,
92
+ repositoryId: String(repository.id),
93
+ productionBranch,
94
+ githubEnvironment: options.environment,
95
+ workflowPath,
96
+ };
97
+ const plan = (0, releaseTrust_js_1.prepareGithubReleaseTrust)(await readProject(), target);
98
+ await (0, promises_1.readFile)((0, node_path_1.resolve)(cwd, workflowPath), "utf8");
99
+ const planFile = (0, node_path_1.resolve)(cwd, args[1]);
100
+ await (0, promises_1.writeFile)(planFile, `${JSON.stringify(plan, null, 2)}\n`, {
101
+ flag: "wx",
102
+ mode: 0o600,
103
+ });
104
+ return [
105
+ `Wrote Trusted Sources proposal: ${planFile}`,
106
+ `Reviewed proposal SHA-256: ${plan.approvalSha256}`,
107
+ "No provider settings changed. Review the proposal before trust-apply.",
108
+ ];
109
+ }
110
+ const value = json(await (0, promises_1.readFile)((0, node_path_1.resolve)(cwd, args[0]), "utf8"), "trust proposal");
111
+ if (value.profile !== "loom-github-release-trust-v1" || !object(value.target) ||
112
+ !object(value.patch) || !object(value.patch.trustedSources) ||
113
+ typeof value.approvalSha256 !== "string" ||
114
+ !/^[a-f0-9]{64}$/.test(value.approvalSha256) ||
115
+ value.target.projectId !== link.projectId ||
116
+ value.target.teamId !== link.orgId ||
117
+ value.target.repository !== repository.full_name ||
118
+ value.target.repositoryId !== String(repository.id) ||
119
+ value.target.productionBranch !== productionBranch ||
120
+ (options.environment !== undefined &&
121
+ value.target.githubEnvironment !== options.environment)) {
122
+ throw new Error("Trust proposal does not match this linked project and repository.");
123
+ }
124
+ const plan = value;
125
+ // Validate the workflow path before resolving untrusted proposal contents.
126
+ if (typeof plan.target.workflowPath !== "string" ||
127
+ !/^\.github\/workflows\/[A-Za-z0-9_.-]+\.ya?ml(?![\s\S])/.test(plan.target.workflowPath))
128
+ throw new Error("Invalid workflow path in trust proposal.");
129
+ await (0, promises_1.readFile)((0, node_path_1.resolve)(cwd, plan.target.workflowPath), "utf8");
130
+ if (action === "check") {
131
+ (0, releaseTrust_js_1.verifyGithubReleaseTrustApplied)(await readProject(), plan);
132
+ return ["Verified production Trusted Sources matches the local proposal."];
133
+ }
134
+ (0, releaseTrust_js_1.verifyGithubReleaseTrustPlan)(await readProject(), plan, args[1]);
135
+ if (plan.changed) {
136
+ (0, releaseTrust_js_1.verifyGithubReleaseTrustPlan)(await readProject(), plan, args[1]);
137
+ await command(vercelCli, ["api", providerPath(9), "--method", "PATCH", "--input", "-", "--raw"], JSON.stringify(plan.patch));
138
+ }
139
+ (0, releaseTrust_js_1.verifyGithubReleaseTrustApplied)(await readProject(), plan);
140
+ return [
141
+ plan.changed
142
+ ? "Applied and verified the reviewed production Trusted Sources rule."
143
+ : "Trusted Sources already matched; no provider settings changed.",
144
+ ];
145
+ }
@@ -113,16 +113,24 @@ Use this skill when working on the shared DB stack from a consuming app.
113
113
  skill links are hydrated. Initialization preserves an equivalent formatted
114
114
  `loom.json` instead of creating formatting-only drift.
115
115
  - Use `loom db release setup-github` to create/update that GitHub release
116
- configuration from the linked Vercel project, including storing a Vercel token
117
- scoped to the linked team as the GitHub `VERCEL_TOKEN` environment secret.
118
- Vercel CLI 55 advertised project-scoped token creation but the service
119
- rejected it during verification on 2026-07-21; treat project scope as an
120
- availability-dependent improvement and verify a replacement before revoking
121
- the working team-scoped token.
116
+ configuration from the linked Vercel project. A normal rerun preserves an
117
+ existing write-only GitHub `VERCEL_TOKEN` and refuses to associate it with a
118
+ different linked org or project. New credentials default to project scope and
119
+ expire after 90 days; use `--rotate-token` for explicit replacement,
120
+ `--token-expiry-days` for another bounded lifetime, or `--token-scope team`
121
+ only as an explicit compatibility option. Keep the previous token active until
122
+ a full release succeeds with its replacement. If the current Vercel login
123
+ cannot mint tokens, create a bounded project token in Vercel and install it
124
+ through GitHub's hidden environment-secret input rather than broadening its
125
+ scope.
122
126
  - Smoke check the staged deployment URL after promotion with normal `curl`.
123
- Create a short-lived Vercel Protection Bypass for Automation secret through
124
- the Vercel API, send it as the `x-vercel-protection-bypass` header, and revoke
125
- it in the same step. Avoid the beta `vercel curl` command in CI.
127
+ Existing workflows may continue to create a short-lived Vercel Protection
128
+ Bypass for Automation secret through the Vercel API, send it as the
129
+ `x-vercel-protection-bypass` header, and revoke it in the same step. Apps may
130
+ instead adopt the reviewed GitHub OIDC Trusted Sources flow with
131
+ `loom db release trust-plan`, `trust-apply`, and `trust-check`; see
132
+ `docs/release-trusted-sources.md`. Keep either change app-owned and
133
+ deliberate. Avoid the beta `vercel curl` command in CI.
126
134
  - Production migrations must remain backward-compatible with the currently live
127
135
  app because old code continues serving traffic until the staged deployment is
128
136
  promoted. Use expand/contract migrations for destructive schema changes.