@theholocron/holocron-plugin-vercel 5.0.0-alpha.53 → 5.0.0-alpha.530

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 CHANGED
@@ -1,3 +1,5 @@
1
+ <!-- alex disable host-hostess -->
2
+
1
3
  <!-- editorconfig-checker-disable-file -->
2
4
 
3
5
  # `@theholocron/holocron-plugin-vercel`
@@ -21,7 +23,7 @@ Token resolution order:
21
23
  2. `HOLOCRON_VERCEL_TOKEN` env var
22
24
  3. `VERCEL_TOKEN` env var (the default the Vercel CLI also reads)
23
25
  4. Keyring `vercel.<org>` — tried first when an org is active via `--org`, `HOLOCRON_ORG`, or `org` in `holocron.config.ts`
24
- 5. Keyring `vercel` — unnamespaced fallback; set via `holocron auth set vercel <token>`
26
+ 5. Keyring `vercel` — unnamespaced fallback; set via `holocron new token vercel <token>`
25
27
 
26
28
  If none are set, the plugin throws a clear error. No `vercel auth`
27
29
  fallback — Vercel's CLI auth is per-account and the scopes don't
@@ -62,7 +64,10 @@ Capability covers:
62
64
  webhook receiver shipped as an npm package, for instance. Always
63
65
  deploys with `projectSettings.framework: null` (a bare function, not
64
66
  an app) — `defaultFramework` only applies to `ensureProject()`'s
65
- Git-linked path.
67
+ Git-linked path. If the files include a `vercel.json` with an
68
+ `installCommand`, it is sent as `projectSettings.installCommand` too,
69
+ because a deployment made from uploaded files takes that setting from
70
+ the project, not from the uploaded file.
66
71
  - `getDeployment()` — fetch a deployment by id
67
72
  - `ensureCustomDomain()` — idempotent add (list → add-if-missing →
68
73
  check DNS routing). Ownership (`verified`) and DNS routing are
package/dist/index.d.mts CHANGED
@@ -1,22 +1,32 @@
1
- import { AuthError, DeployFunctionConfig, DeployFunctionResult, Deployment, DeploymentProject, DeploymentProjectSettings, DeploymentRecord, DeploymentTarget, DeploymentTrigger, DnsRecordRequest, ResolveTokenInput } from "@theholocron/cli";
1
+ /**
2
+ * `@theholocron/holocron-plugin-vercel` — entrypoint.
3
+ *
4
+ * Implements the `deployment` capability against Vercel's REST API.
5
+ * See README for auth + config docs.
6
+ */
7
+ import { AuthError, DeployFunctionConfig, DeployFunctionResult, Deployment, DeploymentProject, DeploymentProjectSettings, DeploymentRecord, DeploymentTarget, DeploymentTrigger, DnsRecordRequest, EnsureRelaySourceInput, EnsureRelaySourceResult, InspectRelaySourceInput, PluginToken, RelaySourceState, ResolveTokenInput, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess } from "@theholocron/cli";
2
8
  import { VercelClient, VercelClient as VercelClient$1, VercelClientOptions, createVercelClient } from "@theholocron/vercel-client";
3
- //#region src/auth.d.ts
4
- declare const resolveToken: (input?: ResolveTokenInput) => string;
5
- //#endregion
6
- //#region src/capabilities/deployment.d.ts
9
+ /** Resolves the Vercel token from `--token`, `HOLOCRON_VERCEL_TOKEN`, `VERCEL_TOKEN` or the keyring, and throws an `AuthError` when none is set. */
10
+ export declare const resolveToken: import("@theholocron/cli").TokenResolver;
11
+ /** Every token this plugin takes, for `holocron doctor secrets --verify`, with the layers that hold it. */
12
+ export declare const tokens: PluginToken[];
7
13
  interface DeploymentOptions {
8
14
  /** Optional framework hint passed to project creates. Defaults to "nextjs". */
9
15
  defaultFramework?: string;
10
16
  /** Custom domain that `holocron setup` should attach to this project. */
11
17
  domain?: string;
12
18
  }
13
- declare class VercelDeployment implements Deployment {
19
+ /** The `deployment` capability for Vercel: projects, environment variables, deployments, functions and custom domains. */
20
+ export declare class VercelDeployment implements Deployment {
14
21
  private readonly client;
22
+ /** The capability key, always `deployment`. */
15
23
  readonly key: "deployment";
24
+ /** The provider name, `vercel`. */
16
25
  readonly providerName = "vercel";
17
26
  readonly domain?: string;
18
27
  private readonly defaultFramework;
19
28
  constructor(client: () => VercelClient$1, opts?: DeploymentOptions);
29
+ /** Lists the projects the token can see, mapped to the provider-neutral shape. */
20
30
  listProjects(): Promise<DeploymentProject[]>;
21
31
  ensureProject(input: {
22
32
  name: string;
@@ -24,16 +34,36 @@ declare class VercelDeployment implements Deployment {
24
34
  repo?: string;
25
35
  rootDirectory?: string;
26
36
  }): Promise<DeploymentProject>;
37
+ /** Updates a project's preview-deployment and Git-provider deployment settings and returns the updated project. */
27
38
  updateProjectSettings(projectId: string, settings: DeploymentProjectSettings): Promise<DeploymentProject>;
39
+ /** Makes (or adopts) the team webhook for a Comlink relay source, found by its URL; returns the secret only when made now. */
40
+ ensureRelaySource(input: EnsureRelaySourceInput): Promise<EnsureRelaySourceResult>;
41
+ /** Reads the relay source's webhook back without changing it. */
42
+ inspectRelaySource(input: InspectRelaySourceInput): Promise<RelaySourceState>;
43
+ /** Lists the names of the project's environment variables that apply to `target`. */
28
44
  listEnvVars(projectId: string, target: DeploymentTarget): Promise<string[]>;
45
+ /** Creates or updates (upsert) an environment variable on the project for `target`. */
29
46
  setEnvVar(projectId: string, target: DeploymentTarget, name: string, value: string): Promise<void>;
30
47
  triggerDeployment(input: {
31
48
  projectId: string;
32
49
  branch: string;
33
50
  target?: DeploymentTrigger;
34
51
  }): Promise<DeploymentRecord>;
52
+ /** Fetches a deployment by id; the record's branch is the deployment's Git commit ref, or `null` when it has none. */
35
53
  getDeployment(deploymentId: string): Promise<DeploymentRecord>;
36
54
  deployFunction(projectId: string, config: DeployFunctionConfig): Promise<DeployFunctionResult>;
55
+ /**
56
+ * The project's preview deployments tagged for `branch` (the `<repo>-pr-<number>` alias a file deploy puts in its
57
+ * `meta.holocronPreview`), found by reading the project's deployments page by page and matching the tag here, so
58
+ * only this project's deployments are ever candidates. A production or staging deployment is never one.
59
+ */
60
+ listPreviewDeployments(projectId: string, branch: string): Promise<DeploymentRecord[]>;
61
+ /** The newest production deployment of the project in its latest page of deployments, or null. Reads only. */
62
+ latestDeployment(projectId: string): Promise<DeploymentRecord | null>;
63
+ /** The hostnames attached to the project. Reads only. */
64
+ listDomains(projectId: string): Promise<string[]>;
65
+ /** Deletes the deployments by id; one already gone (404) is not counted and is not an error. */
66
+ deletePreviewDeployments(_projectId: string, deploymentIds: string[]): Promise<number>;
37
67
  /**
38
68
  * Idempotent — matches `Deployment.ensureCustomDomain`'s contract
39
69
  * (never break on re-runs, per CLAUDE.md's probe-then-act standard).
@@ -54,32 +84,23 @@ declare class VercelDeployment implements Deployment {
54
84
  * the wiki's own domain.
55
85
  */
56
86
  ensureCustomDomain(projectId: string, hostname: string): Promise<DnsRecordRequest | null>;
87
+ /**
88
+ * Read-only: the CNAME Vercel recommends for `hostname`, whether or not the domain already resolves. Unlike
89
+ * `ensureCustomDomain` it never attaches the domain, and it keeps the answer when `misconfigured` is false, so
90
+ * `holocron doctor dns` can compare it with the zone. The record is DNS-only: a proxied record breaks Vercel's
91
+ * certificate issuance.
92
+ */
93
+ expectedDomainRecord(projectId: string, hostname: string): Promise<DnsRecordRequest | null>;
57
94
  private getProjectByName;
58
95
  }
59
- //#endregion
60
- //#region src/verify-token.d.ts
61
- /**
62
- * `verifyToken` — plugin-level export used by `holocron auth set` +
63
- * `holocron auth check`. Hits `GET /v2/user` and translates the
64
- * response into the normalized `VerifyTokenResult` shape.
65
- */
66
- interface VerifyTokenSuccess {
67
- ok: true;
68
- subject: string;
69
- }
70
- interface VerifyTokenFailure {
71
- ok: false;
72
- message: string;
73
- }
74
- type VerifyTokenResult = VerifyTokenSuccess | VerifyTokenFailure;
75
96
  interface VerifyTokenOptions {
76
97
  baseUrl?: string;
77
98
  fetch?: typeof fetch;
78
99
  }
79
- declare function verifyToken(token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult>;
80
- //#endregion
81
- //#region src/index.d.ts
82
- interface VercelPluginOptions extends ResolveTokenInput {
100
+ /** Checks a Vercel token by fetching the current user; the success subject is `user @` followed by the email, username, name or id, the failure carries the error message. */
101
+ export declare function verifyToken(token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult$1>;
102
+ /** Options for the Vercel plugin: token resolution, team, defaults for new projects and test overrides. */
103
+ export interface VercelPluginOptions extends ResolveTokenInput {
83
104
  /** Vercel team id. Set when working with a team-owned project. */
84
105
  teamId?: string;
85
106
  /** Default framework slug for new project creates. Defaults to "nextjs". */
@@ -91,22 +112,31 @@ interface VercelPluginOptions extends ResolveTokenInput {
91
112
  /** Override `fetch` for tests. */
92
113
  fetch?: typeof fetch;
93
114
  }
94
- interface PluginContext {
115
+ /** What the plugin's capabilities share: the options and a lazily built client. */
116
+ export interface PluginContext {
117
+ /** The options the plugin was created with. */
95
118
  options: VercelPluginOptions;
119
+ /** Builds the Vercel client on first call and reuses it; the token is resolved then, not at plugin load. */
96
120
  client: () => VercelClient;
97
121
  }
98
- declare function createContext(options?: VercelPluginOptions): PluginContext;
99
- declare function deployment(ctx: PluginContext): Deployment;
100
- declare function createPlugin(options?: VercelPluginOptions): {
122
+ /** Creates the shared context for the given options; no token is resolved until `client()` is first called. */
123
+ export declare function createContext(options?: VercelPluginOptions): PluginContext;
124
+ /** Builds the `deployment` capability from a plugin context, passing on `defaultFramework` and `domain` when set. */
125
+ export declare function deployment(ctx: PluginContext): Deployment;
126
+ /** Creates the Vercel plugin: `connection` and `token` probes and the `deployment` capability. */
127
+ export declare function createPlugin(options?: VercelPluginOptions): {
101
128
  name: string;
129
+ probes: {
130
+ connection: import("@theholocron/cli").Probe;
131
+ token: import("@theholocron/cli").Probe;
132
+ };
102
133
  capabilities: {
103
134
  deployment: () => Deployment;
104
135
  };
105
136
  };
106
137
  /**
107
- * One-line hint printed by `holocron auth set vercel` when no token
138
+ * One-line hint printed by `holocron new token vercel` when no token
108
139
  * is supplied or the supplied token is rejected.
109
140
  */
110
- declare const AUTH_HINT: string;
111
- //#endregion
112
- export { AUTH_HINT, AuthError, PluginContext, type ResolveTokenInput, type VercelClient, type VercelClientOptions, VercelDeployment, VercelPluginOptions, type VerifyTokenFailure, type VerifyTokenResult, type VerifyTokenSuccess, createContext, createPlugin, createVercelClient, deployment, resolveToken, verifyToken };
141
+ export declare const AUTH_HINT: string;
142
+ export { AuthError, type ResolveTokenInput, type VercelClient, type VercelClientOptions, type VerifyTokenFailure, type VerifyTokenResult, type VerifyTokenSuccess, createVercelClient };
package/dist/index.mjs CHANGED
@@ -1,17 +1,97 @@
1
- import { AuthError, ProviderApiError, createResolveToken } from "@theholocron/cli";
1
+ import { AuthError, ProviderApiError, connectionProbe, createResolveToken, tokenExpectations } from "@theholocron/cli";
2
+ import { errorMessage } from "@theholocron/misc-utils";
2
3
  import { createVercelClient } from "@theholocron/vercel-client";
3
- //#region src/auth.ts
4
+ // src/probes/token/expectations.ts
5
+ /**
6
+ * Where the Vercel token is held: a laptop (`local`, `dev`) and CI. A Vercel token has no per-endpoint scope (a personal
7
+ * access token's "Full Account" or team scope is a setting, not something the API answers), so the only thing the probe
8
+ * can prove is what the token can reach. `webhooks` is the one permission declared: a laptop token makes the team's
9
+ * Comlink relay webhook (`setup notifications`, `POST /v1/webhooks`), and the probe proves it only as far as `GET
10
+ * /v1/webhooks` answers (a read proves the token sees the team's webhooks, not that it may make one). `ci` holds the
11
+ * token with no rule: nothing in CI makes a webhook, but Vercel cannot take the permission off a token, so it is not
12
+ * declared `absent` (the probe would have nothing to prove it with). This is the plugin's `tokens` declaration, read
13
+ * through `tokenExpectations()`; change it and the Vercel table in `docs/src/content/docs/tokens.mdx` together.
14
+ */
15
+ const EXPECTED = {
16
+ layers: [
17
+ "local",
18
+ "dev",
19
+ "ci"
20
+ ],
21
+ permissions: {
22
+ local: { webhooks: "required" },
23
+ dev: { webhooks: "required" }
24
+ }
25
+ };
26
+ // src/auth.ts
27
+ /** Resolves the Vercel token from `--token`, `HOLOCRON_VERCEL_TOKEN`, `VERCEL_TOKEN` or the keyring, and throws an `AuthError` when none is set. */
4
28
  const resolveToken = createResolveToken({
5
29
  envName: "HOLOCRON_VERCEL_TOKEN",
6
30
  vendorEnvName: "VERCEL_TOKEN",
7
31
  keyringService: "vercel",
8
- errorMessage: "no Vercel token found. Pass --token <PAT>, set HOLOCRON_VERCEL_TOKEN / VERCEL_TOKEN, or run: holocron auth set vercel <PAT>"
32
+ errorMessage: "no Vercel token found. Pass --token <PAT>, set HOLOCRON_VERCEL_TOKEN / VERCEL_TOKEN, or run: holocron new token vercel <PAT>"
9
33
  });
10
- //#endregion
11
- //#region src/capabilities/deployment.ts
34
+ /** Every token this plugin takes, for `holocron doctor secrets --verify`, with the layers that hold it. */
35
+ const tokens = [{
36
+ ...resolveToken.token,
37
+ expect: EXPECTED
38
+ }];
39
+ // src/capabilities/relay-source.ts
40
+ async function findByUrl(client, url) {
41
+ return (await client.webhooks.list()).find((w) => w.url === url);
42
+ }
43
+ /** Make the webhook for `input.url`, or adopt the one already there. Returns the secret only when it was made now. */
44
+ async function ensureVercelRelaySource(client, input) {
45
+ if (await findByUrl(client, input.url)) return {
46
+ created: false,
47
+ updated: []
48
+ };
49
+ if (!input.events || input.events.length === 0) return {
50
+ created: false,
51
+ updated: [],
52
+ todo: [`Vercel needs at least one event to make a webhook: set \`events\` on relay.sources.${input.source}.`]
53
+ };
54
+ try {
55
+ const made = await client.webhooks.create({
56
+ url: input.url,
57
+ events: input.events,
58
+ ...input.scope && input.scope.length > 0 ? { projectIds: input.scope } : {}
59
+ });
60
+ return {
61
+ created: true,
62
+ updated: [],
63
+ ...made.secret ? { secret: made.secret } : {}
64
+ };
65
+ } catch (err) {
66
+ if (err instanceof ProviderApiError && (err.status === 402 || err.status === 403)) return {
67
+ created: false,
68
+ updated: [],
69
+ todo: [`Vercel refused to make the webhook (HTTP ${err.status}): account webhooks need a Pro or Enterprise team and a token for that team. Make it in Team Settings, Webhooks, for ${input.url}.`]
70
+ };
71
+ throw err;
72
+ }
73
+ }
74
+ /** Read the webhook for `input.url` back. Vercel's list carries no secret, so `hasSecret` is left out. */
75
+ async function inspectVercelRelaySource(client, input) {
76
+ const found = await findByUrl(client, input.url);
77
+ if (!found) return { exists: false };
78
+ return {
79
+ exists: true,
80
+ events: found.events,
81
+ scope: found.projectIds ?? []
82
+ };
83
+ }
84
+ // src/capabilities/deployment.ts
85
+ /** The `meta` key a file deploy tags a preview with: the pull request it belongs to, as `<repo>-pr-<number>`. */
86
+ const PREVIEW_META_KEY = "holocronPreview";
87
+ /** How many pages of a project's deployments a cleanup reads (100 to a page) before it stops looking. */
88
+ const MAX_LIST_PAGES = 20;
89
+ /** The `deployment` capability for Vercel: projects, environment variables, deployments, functions and custom domains. */
12
90
  var VercelDeployment = class {
13
91
  client;
92
+ /** The capability key, always `deployment`. */
14
93
  key = "deployment";
94
+ /** The provider name, `vercel`. */
15
95
  providerName = "vercel";
16
96
  domain;
17
97
  defaultFramework;
@@ -20,6 +100,7 @@ var VercelDeployment = class {
20
100
  this.defaultFramework = opts.defaultFramework ?? "nextjs";
21
101
  this.domain = opts.domain;
22
102
  }
103
+ /** Lists the projects the token can see, mapped to the provider-neutral shape. */
23
104
  async listProjects() {
24
105
  const { projects } = await this.client().projects.list();
25
106
  return projects.map(mapProject);
@@ -34,16 +115,27 @@ var VercelDeployment = class {
34
115
  rootDirectory: input.rootDirectory
35
116
  }));
36
117
  }
118
+ /** Updates a project's preview-deployment and Git-provider deployment settings and returns the updated project. */
37
119
  async updateProjectSettings(projectId, settings) {
38
120
  return mapProject(await this.client().projects.update(projectId, {
39
121
  previewDeploymentsDisabled: settings.previewDeploymentsDisabled,
40
122
  gitProviderOptions: settings.gitProviderCreateDeployments !== void 0 ? { createDeployments: settings.gitProviderCreateDeployments } : void 0
41
123
  }));
42
124
  }
125
+ /** Makes (or adopts) the team webhook for a Comlink relay source, found by its URL; returns the secret only when made now. */
126
+ ensureRelaySource(input) {
127
+ return ensureVercelRelaySource(this.client(), input);
128
+ }
129
+ /** Reads the relay source's webhook back without changing it. */
130
+ inspectRelaySource(input) {
131
+ return inspectVercelRelaySource(this.client(), input);
132
+ }
133
+ /** Lists the names of the project's environment variables that apply to `target`. */
43
134
  async listEnvVars(projectId, target) {
44
135
  const { envs } = await this.client().env.list(projectId);
45
136
  return envs.filter((e) => e.target.includes(target)).map((e) => e.key);
46
137
  }
138
+ /** Creates or updates (upsert) an environment variable on the project for `target`. */
47
139
  async setEnvVar(projectId, target, name, value) {
48
140
  await this.client().env.set(projectId, target, name, value);
49
141
  }
@@ -58,6 +150,7 @@ var VercelDeployment = class {
58
150
  target: input.target
59
151
  }), input.branch);
60
152
  }
153
+ /** Fetches a deployment by id; the record's branch is the deployment's Git commit ref, or `null` when it has none. */
61
154
  async getDeployment(deploymentId) {
62
155
  const raw = await this.client().deployments.get(deploymentId);
63
156
  return mapDeployment(raw, raw.meta?.githubCommitRef ?? null);
@@ -70,7 +163,9 @@ var VercelDeployment = class {
70
163
  content
71
164
  })),
72
165
  framework: null,
73
- target: config.target
166
+ ...installCommandOf(config.files),
167
+ target: config.target,
168
+ ...config.meta ? { meta: config.meta } : {}
74
169
  });
75
170
  return {
76
171
  deploymentId: raw.id,
@@ -78,6 +173,57 @@ var VercelDeployment = class {
78
173
  };
79
174
  }
80
175
  /**
176
+ * The project's preview deployments tagged for `branch` (the `<repo>-pr-<number>` alias a file deploy puts in its
177
+ * `meta.holocronPreview`), found by reading the project's deployments page by page and matching the tag here, so
178
+ * only this project's deployments are ever candidates. A production or staging deployment is never one.
179
+ */
180
+ async listPreviewDeployments(projectId, branch) {
181
+ const found = [];
182
+ let until;
183
+ for (let page = 0; page < MAX_LIST_PAGES; page++) {
184
+ const { deployments, pagination } = await this.client().deployments.list({
185
+ projectId,
186
+ ...until !== void 0 ? { until } : {}
187
+ });
188
+ for (const raw of deployments) {
189
+ if (raw.target || raw.meta?.[PREVIEW_META_KEY] !== branch) continue;
190
+ found.push({
191
+ ...mapDeployment(raw, raw.meta?.githubCommitRef ?? null),
192
+ ...raw.createdAt ? { createdAt: new Date(raw.createdAt).toISOString() } : {}
193
+ });
194
+ }
195
+ const next = pagination?.next;
196
+ if (!next) break;
197
+ until = next;
198
+ }
199
+ return found;
200
+ }
201
+ /** The newest production deployment of the project in its latest page of deployments, or null. Reads only. */
202
+ async latestDeployment(projectId) {
203
+ const { deployments } = await this.client().deployments.list({ projectId });
204
+ const newest = deployments.find((d) => d.target === "production");
205
+ if (!newest) return null;
206
+ return {
207
+ ...mapDeployment(newest, newest.meta?.githubCommitRef ?? null),
208
+ ...newest.createdAt ? { createdAt: new Date(newest.createdAt).toISOString() } : {}
209
+ };
210
+ }
211
+ /** The hostnames attached to the project. Reads only. */
212
+ async listDomains(projectId) {
213
+ return (await this.client().domains.list(projectId)).domains.map((d) => d.name);
214
+ }
215
+ /** Deletes the deployments by id; one already gone (404) is not counted and is not an error. */
216
+ async deletePreviewDeployments(_projectId, deploymentIds) {
217
+ let deleted = 0;
218
+ for (const id of deploymentIds) try {
219
+ await this.client().deployments.remove(id);
220
+ deleted++;
221
+ } catch (err) {
222
+ if (!(err instanceof ProviderApiError && err.status === 404)) throw err;
223
+ }
224
+ return deleted;
225
+ }
226
+ /**
81
227
  * Idempotent — matches `Deployment.ensureCustomDomain`'s contract
82
228
  * (never break on re-runs, per CLAUDE.md's probe-then-act standard).
83
229
  *
@@ -120,6 +266,25 @@ var VercelDeployment = class {
120
266
  }
121
267
  };
122
268
  }
269
+ /**
270
+ * Read-only: the CNAME Vercel recommends for `hostname`, whether or not the domain already resolves. Unlike
271
+ * `ensureCustomDomain` it never attaches the domain, and it keeps the answer when `misconfigured` is false, so
272
+ * `holocron doctor dns` can compare it with the zone. The record is DNS-only: a proxied record breaks Vercel's
273
+ * certificate issuance.
274
+ */
275
+ async expectedDomainRecord(projectId, hostname) {
276
+ const cname = (await this.client().domains.config(hostname, projectId)).recommendedCNAME[0]?.value;
277
+ if (!cname) return null;
278
+ return {
279
+ zone: hostname,
280
+ record: {
281
+ type: "CNAME",
282
+ name: hostname,
283
+ content: cname,
284
+ proxied: false
285
+ }
286
+ };
287
+ }
123
288
  async getProjectByName(name) {
124
289
  try {
125
290
  return mapProject(await this.client().projects.get(name));
@@ -129,6 +294,22 @@ var VercelDeployment = class {
129
294
  }
130
295
  }
131
296
  };
297
+ /**
298
+ * The `installCommand` of an uploaded `vercel.json`, as the field `deployments.create()` takes.
299
+ * A deployment made from uploaded files ignores the file's `installCommand` in favour of the
300
+ * project's setting, so it is sent in the request too. Empty when there is no such file, it is
301
+ * not JSON, or it sets none.
302
+ */
303
+ function installCommandOf(files) {
304
+ const raw = files["vercel.json"];
305
+ if (raw === void 0) return {};
306
+ try {
307
+ const { installCommand } = JSON.parse(raw);
308
+ return typeof installCommand === "string" && installCommand ? { installCommand } : {};
309
+ } catch {
310
+ return {};
311
+ }
312
+ }
132
313
  function mapProject(raw) {
133
314
  const project = {
134
315
  id: raw.id,
@@ -147,6 +328,7 @@ function mapDeployment(raw, branch) {
147
328
  status: normalizeState(raw.readyState)
148
329
  };
149
330
  if (raw.target) record.target = raw.target;
331
+ if (raw.errorMessage) record.errorMessage = raw.errorMessage;
150
332
  return record;
151
333
  }
152
334
  function normalizeState(s) {
@@ -159,13 +341,104 @@ function normalizeState(s) {
159
341
  case "CANCELED": return "cancelled";
160
342
  }
161
343
  }
162
- //#endregion
163
- //#region src/verify-token.ts
344
+ // src/probes/token/parse-layer.ts
345
+ /** Reads `--layer <word>` (or `--layer=<word>`) from the words after the probe name, which the CLI passes when `--environment` named a layer. */
346
+ function parseLayer(args) {
347
+ for (let i = 0; i < args.length; i++) {
348
+ const arg = args[i];
349
+ if (arg === "--layer") return args[i + 1];
350
+ if (arg.startsWith("--layer=")) return arg.slice(8);
351
+ }
352
+ }
353
+ // src/probes/token/token.ts
164
354
  /**
165
- * `verifyToken` — plugin-level export used by `holocron auth set` +
166
- * `holocron auth check`. Hits `GET /v2/user` and translates the
167
- * response into the normalized `VerifyTokenResult` shape.
355
+ * The `token` probe for Vercel. It asks who the token belongs to (the plugin's `verifyToken`, `/v2/user`) and whether it can list projects, which
356
+ * are reads and change nothing, and the team's webhook list, the read next to making a relay webhook. Vercel does not
357
+ * report a token's scope, so the probe cannot judge permissions beyond that: it says so, and with `--layer` (passed
358
+ * because `--environment` named a layer) it says whether that layer is one that should hold the token and, for a layer
359
+ * that requires `webhooks`, fails when the list is refused. The token is never printed.
168
360
  */
361
+ function tokenProbe(ctx) {
362
+ return {
363
+ summary: "Check a Vercel token with the current user, the project list and the team's webhook list, and for a layer that it is one that should hold the token (a laptop layer must see the webhooks). Vercel cannot report a token's scope, so making a webhook is not tried. Read-only.",
364
+ writes: false,
365
+ acceptsToken: true,
366
+ async run(probe) {
367
+ const token = ctx.token();
368
+ probe.secret(token);
369
+ const client = ctx.client();
370
+ const layer = parseLayer(probe.args ?? []);
371
+ if (layer) {
372
+ const declared = tokenExpectations(tokens, { layer }).length > 0;
373
+ probe.say(declared ? {
374
+ status: "ok",
375
+ label: layer,
376
+ detail: "a layer that should hold this token"
377
+ } : {
378
+ status: "info",
379
+ label: layer,
380
+ detail: "not a layer this token is declared for, so it is only described"
381
+ });
382
+ }
383
+ const who = await ctx.verify(token);
384
+ if (!who.ok) {
385
+ probe.say({
386
+ status: "fail",
387
+ label: "token",
388
+ detail: who.message
389
+ });
390
+ return;
391
+ }
392
+ probe.say({
393
+ status: "ok",
394
+ label: "token",
395
+ detail: who.subject
396
+ });
397
+ try {
398
+ const { projects } = await client.projects.list();
399
+ probe.say({
400
+ status: "ok",
401
+ label: "Projects: Read",
402
+ detail: `${projects.length} projects`
403
+ });
404
+ } catch (err) {
405
+ if (err instanceof ProviderApiError && (err.status === 401 || err.status === 403)) probe.say({
406
+ status: "info",
407
+ label: "Projects: Read",
408
+ detail: `no access (${err.status})`
409
+ });
410
+ else probe.say({
411
+ status: "fail",
412
+ label: "Projects: Read",
413
+ detail: errorMessage(err)
414
+ });
415
+ }
416
+ const needsWebhooks = layer ? tokenExpectations(tokens, { layer }).some((entry) => entry.required.includes("webhooks")) : false;
417
+ try {
418
+ const hooks = await client.webhooks.list();
419
+ probe.say({
420
+ status: "ok",
421
+ label: "Webhooks: Read",
422
+ detail: `${hooks.length} webhooks`
423
+ });
424
+ } catch (err) {
425
+ const noAccess = err instanceof ProviderApiError && (err.status === 401 || err.status === 403);
426
+ probe.say({
427
+ status: noAccess && !needsWebhooks ? "info" : "fail",
428
+ label: "Webhooks: Read",
429
+ detail: noAccess ? `no access (${err.status})` : errorMessage(err)
430
+ });
431
+ }
432
+ probe.say({
433
+ status: "info",
434
+ label: "permissions",
435
+ detail: "Vercel cannot report a token's scope: reading the team's webhooks is proven, making one is not (it would write)"
436
+ });
437
+ }
438
+ };
439
+ }
440
+ // src/verify-token.ts
441
+ /** Checks a Vercel token by fetching the current user; the success subject is `user @` followed by the email, username, name or id, the failure carries the error message. */
169
442
  async function verifyToken(token, opts = {}) {
170
443
  const client = createVercelClient({
171
444
  token,
@@ -181,12 +454,12 @@ async function verifyToken(token, opts = {}) {
181
454
  } catch (err) {
182
455
  return {
183
456
  ok: false,
184
- message: err instanceof Error ? err.message : String(err)
457
+ message: errorMessage(err)
185
458
  };
186
459
  }
187
460
  }
188
- //#endregion
189
- //#region src/index.ts
461
+ // src/index.ts
462
+ /** Creates the shared context for the given options; no token is resolved until `client()` is first called. */
190
463
  function createContext(options = {}) {
191
464
  let client;
192
465
  return {
@@ -199,23 +472,44 @@ function createContext(options = {}) {
199
472
  })
200
473
  };
201
474
  }
475
+ /** Builds the `deployment` capability from a plugin context, passing on `defaultFramework` and `domain` when set. */
202
476
  function deployment(ctx) {
203
477
  const opts = {};
204
478
  if (ctx.options.defaultFramework !== void 0) opts.defaultFramework = ctx.options.defaultFramework;
205
479
  if (ctx.options.domain !== void 0) opts.domain = ctx.options.domain;
206
480
  return new VercelDeployment(ctx.client, opts);
207
481
  }
482
+ /** Creates the Vercel plugin: `connection` and `token` probes and the `deployment` capability. */
208
483
  function createPlugin(options = {}) {
209
484
  const ctx = createContext(options);
210
485
  return {
211
486
  name: "@theholocron/holocron-plugin-vercel",
487
+ probes: {
488
+ connection: connectionProbe({
489
+ provider: "Vercel",
490
+ url: options.baseUrl ?? "https://api.vercel.com",
491
+ fetch: options.fetch,
492
+ token: () => resolveToken(options),
493
+ verify: (token) => verifyToken(token, {
494
+ baseUrl: options.baseUrl,
495
+ fetch: options.fetch
496
+ })
497
+ }),
498
+ token: tokenProbe({
499
+ client: ctx.client,
500
+ token: () => resolveToken(options),
501
+ verify: (token) => verifyToken(token, {
502
+ baseUrl: options.baseUrl,
503
+ fetch: options.fetch
504
+ })
505
+ })
506
+ },
212
507
  capabilities: { deployment: () => deployment(ctx) }
213
508
  };
214
509
  }
215
510
  /**
216
- * One-line hint printed by `holocron auth set vercel` when no token
511
+ * One-line hint printed by `holocron new token vercel` when no token
217
512
  * is supplied or the supplied token is rejected.
218
513
  */
219
- const AUTH_HINT = "generate a Vercel Personal Access Token at https://vercel.com/account/tokens (scope: Full Account for team ops), then run: holocron auth set vercel <PAT>";
220
- //#endregion
221
- export { AUTH_HINT, AuthError, VercelDeployment, createContext, createPlugin, createVercelClient, deployment, resolveToken, verifyToken };
514
+ const AUTH_HINT = "generate a Vercel Personal Access Token at https://vercel.com/account/tokens (scope: Full Account for team ops), then run: holocron new token vercel <PAT>";
515
+ export { AUTH_HINT, AuthError, VercelDeployment, createContext, createPlugin, createVercelClient, deployment, resolveToken, tokens, verifyToken };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-vercel",
3
- "version": "5.0.0-alpha.53",
3
+ "version": "5.0.0-alpha.530",
4
4
  "description": "Holocron plugin for Vercel. Implements the deployment capability against the Vercel REST API.",
5
5
  "keywords": [
6
6
  "deployment",
@@ -8,12 +8,12 @@
8
8
  "plugin",
9
9
  "vercel"
10
10
  ],
11
- "homepage": "https://github.com/theholocron/holocron/tree/main/packages/holocron-plugin-vercel#readme",
11
+ "homepage": "https://docs.theholocron.dev/holocron/plugins/vercel/",
12
12
  "bugs": "https://github.com/theholocron/holocron/issues",
13
13
  "repository": {
14
14
  "type": "git",
15
15
  "url": "git+https://github.com/theholocron/holocron.git",
16
- "directory": "packages/holocron-plugin-vercel"
16
+ "directory": "plugins/holocron-plugin-vercel"
17
17
  },
18
18
  "license": "MIT",
19
19
  "author": "Newton Koumantzelis",
@@ -30,27 +30,29 @@
30
30
  "dist"
31
31
  ],
32
32
  "devDependencies": {
33
- "@theholocron/eslint-config": "^8.4.5",
34
- "@theholocron/http-client": "^1.25.0",
35
- "@theholocron/tsconfig": "^8.4.5",
36
- "@theholocron/tsdown-config": "^8.4.5",
37
- "@theholocron/vercel-client": "^1.25.0",
38
- "@theholocron/vitest-config": "^8.4.5",
39
33
  "@types/node": "^26",
40
- "@vitest/coverage-v8": "^4.1.11",
41
- "@vitest/eslint-plugin": "^1.6.27",
42
- "eslint": "^10.8.1",
43
- "eslint-plugin-n": "^18.3.0",
44
- "globals": "^17.11.0",
45
- "tsdown": "^0.22.14",
46
- "tsx": "4.23.12",
47
- "typescript": "^5.9.3",
48
- "vitest": "^4.1.11",
49
- "@theholocron/cli": "5.0.0-alpha.53"
34
+ "@vitest/coverage-v8": "^5.1.0",
35
+ "@vitest/eslint-plugin": "^1.6.28",
36
+ "eslint": "^10.15.0",
37
+ "eslint-plugin-n": "^18.5.0",
38
+ "globals": "^17.14.0",
39
+ "tsdown": "^0.23.7",
40
+ "tsx": "4.23.15",
41
+ "typescript": "^6.0.3",
42
+ "vitest": "^5.1.0",
43
+ "@theholocron/cli": "5.0.0-alpha.530",
44
+ "@theholocron/http-client": "^1.58.0-alpha.55",
45
+ "@theholocron/misc-utils": "^1.17.0-alpha.5",
46
+ "@theholocron/eslint-config": "^8.9.0-alpha.22",
47
+ "@theholocron/tsdown-config": "^8.9.0-alpha.22",
48
+ "@theholocron/vercel-client": "^1.58.0-alpha.55",
49
+ "@theholocron/vitest-config": "^8.9.0-alpha.22",
50
+ "@theholocron/tsconfig": "^8.9.0-alpha.22"
50
51
  },
51
52
  "peerDependencies": {
52
- "@theholocron/vercel-client": "^1.25.0",
53
- "@theholocron/cli": "5.0.0-alpha.53"
53
+ "@theholocron/misc-utils": "^1.16.0",
54
+ "@theholocron/vercel-client": "^1.43.1",
55
+ "@theholocron/cli": "5.0.0-alpha.530"
54
56
  },
55
57
  "peerDependenciesMeta": {
56
58
  "@theholocron/vercel-client": {}
@@ -62,11 +64,11 @@
62
64
  "access": "public"
63
65
  },
64
66
  "scripts": {
65
- "delivery.build": "tsdown",
66
- "sourceQuality.staticAnalysis": "holocron run sourceQuality.staticAnalysis --",
67
+ "build": "tsdown",
68
+ "lint:code": "eslint .",
69
+ "test:unit": "vitest run --coverage",
67
70
  "test:watch": "vitest",
68
- "validate": "tsx scripts/validate.mjs",
69
- "verification.typeSafety": "holocron run verification.typeSafety --",
70
- "verification.unitTests": "holocron run verification.unitTests --"
71
+ "typecheck": "tsc --noEmit",
72
+ "validate:plugin": "tsx scripts/validate.mjs"
71
73
  }
72
74
  }