@theholocron/holocron-plugin-vercel 5.0.0-alpha.5 → 5.0.0-alpha.500

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
@@ -55,10 +57,42 @@ Capability covers:
55
57
  - `updateProjectSettings()` — toggle preview deploys, git-creates-deploys
56
58
  - `setEnvVar()` / `listEnvVars()` — per-target env vars
57
59
  - `triggerDeployment()` — branch deploys with optional named target
60
+ (requires a project already linked to a Git repo)
61
+ - `deployFunction()` — deploy directly from source files, bypassing Git
62
+ entirely: `POST /v13/deployments` with an inline `files` array, no
63
+ linked repo required. For a consumer with no repo to deploy from — a
64
+ webhook receiver shipped as an npm package, for instance. Always
65
+ deploys with `projectSettings.framework: null` (a bare function, not
66
+ an app) — `defaultFramework` only applies to `ensureProject()`'s
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.
58
71
  - `getDeployment()` — fetch a deployment by id
72
+ - `ensureCustomDomain()` — idempotent add (list → add-if-missing →
73
+ check DNS routing). Ownership (`verified`) and DNS routing are
74
+ separate: once a team already owns a domain's apex, every new
75
+ subdomain auto-verifies immediately with no fresh challenge, so
76
+ attachment alone can't tell you whether traffic is actually routed
77
+ to Vercel yet. `domains.config()` answers that regardless of
78
+ ownership state, returning a per-project CNAME target — never a
79
+ fixed well-known host — only when DNS isn't already configured. The
80
+ returned DNS record is handed to the configured `dns` provider by
81
+ `holocron setup`.
82
+
83
+ Declare the production domain in the Vercel provider options. On `holocron setup`,
84
+ the domain is attached to the project and any Vercel verification CNAME is
85
+ upserted through the configured DNS provider:
86
+
87
+ ```ts
88
+ providers: {
89
+ deployment: ["vercel", { teamId: "team_…", domain: "sentinel.example.com" }],
90
+ dns: "cloudflare",
91
+ }
92
+ ```
59
93
 
60
94
  Out of scope for alpha.0 (file a follow-up if needed):
61
95
 
62
- - Domain management (`addDomain` / `removeDomain`)
96
+ - Domain removal (`removeDomain`)
63
97
  - Deletion (`deleteProject`)
64
98
  - Marketplace integrations (e.g. `vercel install neon` for vault-managed databases)
package/dist/index.d.mts CHANGED
@@ -1,19 +1,32 @@
1
- import { AuthError, Deployment, DeploymentProject, DeploymentProjectSettings, DeploymentRecord, DeploymentTarget, DeploymentTrigger, 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, PluginToken, 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;
16
+ /** Custom domain that `holocron setup` should attach to this project. */
17
+ domain?: string;
10
18
  }
11
- 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 {
12
21
  private readonly client;
22
+ /** The capability key, always `deployment`. */
13
23
  readonly key: "deployment";
24
+ /** The provider name, `vercel`. */
14
25
  readonly providerName = "vercel";
26
+ readonly domain?: string;
15
27
  private readonly defaultFramework;
16
28
  constructor(client: () => VercelClient$1, opts?: DeploymentOptions);
29
+ /** Lists the projects the token can see, mapped to the provider-neutral shape. */
17
30
  listProjects(): Promise<DeploymentProject[]>;
18
31
  ensureProject(input: {
19
32
  name: string;
@@ -21,66 +34,105 @@ declare class VercelDeployment implements Deployment {
21
34
  repo?: string;
22
35
  rootDirectory?: string;
23
36
  }): Promise<DeploymentProject>;
37
+ /** Updates a project's preview-deployment and Git-provider deployment settings and returns the updated project. */
24
38
  updateProjectSettings(projectId: string, settings: DeploymentProjectSettings): Promise<DeploymentProject>;
39
+ /** Lists the names of the project's environment variables that apply to `target`. */
25
40
  listEnvVars(projectId: string, target: DeploymentTarget): Promise<string[]>;
41
+ /** Creates or updates (upsert) an environment variable on the project for `target`. */
26
42
  setEnvVar(projectId: string, target: DeploymentTarget, name: string, value: string): Promise<void>;
27
43
  triggerDeployment(input: {
28
44
  projectId: string;
29
45
  branch: string;
30
46
  target?: DeploymentTrigger;
31
47
  }): Promise<DeploymentRecord>;
48
+ /** Fetches a deployment by id; the record's branch is the deployment's Git commit ref, or `null` when it has none. */
32
49
  getDeployment(deploymentId: string): Promise<DeploymentRecord>;
50
+ deployFunction(projectId: string, config: DeployFunctionConfig): Promise<DeployFunctionResult>;
51
+ /**
52
+ * The project's preview deployments tagged for `branch` (the `<repo>-pr-<number>` alias a file deploy puts in its
53
+ * `meta.holocronPreview`), found by reading the project's deployments page by page and matching the tag here, so
54
+ * only this project's deployments are ever candidates. A production or staging deployment is never one.
55
+ */
56
+ listPreviewDeployments(projectId: string, branch: string): Promise<DeploymentRecord[]>;
57
+ /** The newest production deployment of the project in its latest page of deployments, or null. Reads only. */
58
+ latestDeployment(projectId: string): Promise<DeploymentRecord | null>;
59
+ /** The hostnames attached to the project. Reads only. */
60
+ listDomains(projectId: string): Promise<string[]>;
61
+ /** Deletes the deployments by id; one already gone (404) is not counted and is not an error. */
62
+ deletePreviewDeployments(_projectId: string, deploymentIds: string[]): Promise<number>;
63
+ /**
64
+ * Idempotent — matches `Deployment.ensureCustomDomain`'s contract
65
+ * (never break on re-runs, per CLAUDE.md's probe-then-act standard).
66
+ *
67
+ * Ownership (`domains.add`'s `verified`) and DNS routing are separate
68
+ * concerns: once a team already owns the domain's apex (true for any
69
+ * org with more than one project on the same domain), every new
70
+ * subdomain auto-verifies immediately with no `verification`
71
+ * challenge — re-adding an already-attached domain returns 409, not
72
+ * a fresh one. So attachment alone can't tell us whether traffic is
73
+ * actually routed to Vercel yet. `domains.config()` (Vercel's DNS
74
+ * *configuration* check) answers that regardless of ownership state:
75
+ * `misconfigured` + a `recommendedCNAME`, per-project, never a fixed
76
+ * well-known host — always read it from this response, never
77
+ * hardcode it. Returned as a `DnsRecordRequest` — the caller (e.g.
78
+ * `holocron setup`'s custom-domain step) hands it straight to
79
+ * `dns.upsertRecord()`, same as `Wiki.dnsRecord()` already does for
80
+ * the wiki's own domain.
81
+ */
82
+ ensureCustomDomain(projectId: string, hostname: string): Promise<DnsRecordRequest | null>;
83
+ /**
84
+ * Read-only: the CNAME Vercel recommends for `hostname`, whether or not the domain already resolves. Unlike
85
+ * `ensureCustomDomain` it never attaches the domain, and it keeps the answer when `misconfigured` is false, so
86
+ * `holocron doctor dns` can compare it with the zone. The record is DNS-only: a proxied record breaks Vercel's
87
+ * certificate issuance.
88
+ */
89
+ expectedDomainRecord(projectId: string, hostname: string): Promise<DnsRecordRequest | null>;
33
90
  private getProjectByName;
34
91
  }
35
- //#endregion
36
- //#region src/verify-token.d.ts
37
- /**
38
- * `verifyToken` — plugin-level export used by `holocron auth set` +
39
- * `holocron auth check`. Hits `GET /v2/user` and translates the
40
- * response into the normalized `VerifyTokenResult` shape.
41
- */
42
- interface VerifyTokenSuccess {
43
- ok: true;
44
- subject: string;
45
- }
46
- interface VerifyTokenFailure {
47
- ok: false;
48
- message: string;
49
- }
50
- type VerifyTokenResult = VerifyTokenSuccess | VerifyTokenFailure;
51
92
  interface VerifyTokenOptions {
52
93
  baseUrl?: string;
53
94
  fetch?: typeof fetch;
54
95
  }
55
- declare function verifyToken(token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult>;
56
- //#endregion
57
- //#region src/index.d.ts
58
- interface VercelPluginOptions extends ResolveTokenInput {
96
+ /** 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. */
97
+ export declare function verifyToken(token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult$1>;
98
+ /** Options for the Vercel plugin: token resolution, team, defaults for new projects and test overrides. */
99
+ export interface VercelPluginOptions extends ResolveTokenInput {
59
100
  /** Vercel team id. Set when working with a team-owned project. */
60
101
  teamId?: string;
61
102
  /** Default framework slug for new project creates. Defaults to "nextjs". */
62
103
  defaultFramework?: string;
104
+ /** Custom domain that `holocron setup` should attach to the Vercel project. */
105
+ domain?: string;
63
106
  /** Override base URL for tests. */
64
107
  baseUrl?: string;
65
108
  /** Override `fetch` for tests. */
66
109
  fetch?: typeof fetch;
67
110
  }
68
- interface PluginContext {
111
+ /** What the plugin's capabilities share: the options and a lazily built client. */
112
+ export interface PluginContext {
113
+ /** The options the plugin was created with. */
69
114
  options: VercelPluginOptions;
115
+ /** Builds the Vercel client on first call and reuses it; the token is resolved then, not at plugin load. */
70
116
  client: () => VercelClient;
71
117
  }
72
- declare function createContext(options?: VercelPluginOptions): PluginContext;
73
- declare function deployment(ctx: PluginContext): Deployment;
74
- declare function createPlugin(options?: VercelPluginOptions): {
118
+ /** Creates the shared context for the given options; no token is resolved until `client()` is first called. */
119
+ export declare function createContext(options?: VercelPluginOptions): PluginContext;
120
+ /** Builds the `deployment` capability from a plugin context, passing on `defaultFramework` and `domain` when set. */
121
+ export declare function deployment(ctx: PluginContext): Deployment;
122
+ /** Creates the Vercel plugin: `connection` and `token` probes and the `deployment` capability. */
123
+ export declare function createPlugin(options?: VercelPluginOptions): {
75
124
  name: string;
125
+ probes: {
126
+ connection: import("@theholocron/cli").Probe;
127
+ token: import("@theholocron/cli").Probe;
128
+ };
76
129
  capabilities: {
77
130
  deployment: () => Deployment;
78
131
  };
79
132
  };
80
133
  /**
81
- * One-line hint printed by `holocron auth set vercel` when no token
134
+ * One-line hint printed by `holocron new token vercel` when no token
82
135
  * is supplied or the supplied token is rejected.
83
136
  */
84
- declare const AUTH_HINT: string;
85
- //#endregion
86
- 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 };
137
+ export declare const AUTH_HINT: string;
138
+ export { AuthError, type ResolveTokenInput, type VercelClient, type VercelClientOptions, type VerifyTokenFailure, type VerifyTokenResult, type VerifyTokenSuccess, createVercelClient };
package/dist/index.mjs CHANGED
@@ -1,23 +1,51 @@
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. Vercel does not report a token's scope (a personal
7
+ * access token's "Full Account" is a setting, not something the API answers), so no permissions are declared and the
8
+ * probe says so instead of guessing. This is the plugin's `tokens` declaration, read through `tokenExpectations()`;
9
+ * change it and the Vercel note in `docs/src/content/docs/tokens.mdx` together.
10
+ */
11
+ const EXPECTED = { layers: [
12
+ "local",
13
+ "dev",
14
+ "ci"
15
+ ] };
16
+ // src/auth.ts
17
+ /** Resolves the Vercel token from `--token`, `HOLOCRON_VERCEL_TOKEN`, `VERCEL_TOKEN` or the keyring, and throws an `AuthError` when none is set. */
4
18
  const resolveToken = createResolveToken({
5
19
  envName: "HOLOCRON_VERCEL_TOKEN",
6
20
  vendorEnvName: "VERCEL_TOKEN",
7
21
  keyringService: "vercel",
8
- errorMessage: "no Vercel token found. Pass --token <PAT>, set HOLOCRON_VERCEL_TOKEN / VERCEL_TOKEN, or run: holocron auth set vercel <PAT>"
22
+ errorMessage: "no Vercel token found. Pass --token <PAT>, set HOLOCRON_VERCEL_TOKEN / VERCEL_TOKEN, or run: holocron new token vercel <PAT>"
9
23
  });
10
- //#endregion
11
- //#region src/capabilities/deployment.ts
24
+ /** Every token this plugin takes, for `holocron doctor secrets --verify`, with the layers that hold it. */
25
+ const tokens = [{
26
+ ...resolveToken.token,
27
+ expect: EXPECTED
28
+ }];
29
+ // src/capabilities/deployment.ts
30
+ /** The `meta` key a file deploy tags a preview with: the pull request it belongs to, as `<repo>-pr-<number>`. */
31
+ const PREVIEW_META_KEY = "holocronPreview";
32
+ /** How many pages of a project's deployments a cleanup reads (100 to a page) before it stops looking. */
33
+ const MAX_LIST_PAGES = 20;
34
+ /** The `deployment` capability for Vercel: projects, environment variables, deployments, functions and custom domains. */
12
35
  var VercelDeployment = class {
13
36
  client;
37
+ /** The capability key, always `deployment`. */
14
38
  key = "deployment";
39
+ /** The provider name, `vercel`. */
15
40
  providerName = "vercel";
41
+ domain;
16
42
  defaultFramework;
17
43
  constructor(client, opts = {}) {
18
44
  this.client = client;
19
45
  this.defaultFramework = opts.defaultFramework ?? "nextjs";
46
+ this.domain = opts.domain;
20
47
  }
48
+ /** Lists the projects the token can see, mapped to the provider-neutral shape. */
21
49
  async listProjects() {
22
50
  const { projects } = await this.client().projects.list();
23
51
  return projects.map(mapProject);
@@ -32,16 +60,19 @@ var VercelDeployment = class {
32
60
  rootDirectory: input.rootDirectory
33
61
  }));
34
62
  }
63
+ /** Updates a project's preview-deployment and Git-provider deployment settings and returns the updated project. */
35
64
  async updateProjectSettings(projectId, settings) {
36
65
  return mapProject(await this.client().projects.update(projectId, {
37
66
  previewDeploymentsDisabled: settings.previewDeploymentsDisabled,
38
67
  gitProviderOptions: settings.gitProviderCreateDeployments !== void 0 ? { createDeployments: settings.gitProviderCreateDeployments } : void 0
39
68
  }));
40
69
  }
70
+ /** Lists the names of the project's environment variables that apply to `target`. */
41
71
  async listEnvVars(projectId, target) {
42
72
  const { envs } = await this.client().env.list(projectId);
43
73
  return envs.filter((e) => e.target.includes(target)).map((e) => e.key);
44
74
  }
75
+ /** Creates or updates (upsert) an environment variable on the project for `target`. */
45
76
  async setEnvVar(projectId, target, name, value) {
46
77
  await this.client().env.set(projectId, target, name, value);
47
78
  }
@@ -56,10 +87,141 @@ var VercelDeployment = class {
56
87
  target: input.target
57
88
  }), input.branch);
58
89
  }
90
+ /** Fetches a deployment by id; the record's branch is the deployment's Git commit ref, or `null` when it has none. */
59
91
  async getDeployment(deploymentId) {
60
92
  const raw = await this.client().deployments.get(deploymentId);
61
93
  return mapDeployment(raw, raw.meta?.githubCommitRef ?? null);
62
94
  }
95
+ async deployFunction(projectId, config) {
96
+ const raw = await this.client().deployments.create({
97
+ projectName: projectId,
98
+ files: Object.entries(config.files).map(([file, content]) => ({
99
+ file,
100
+ content
101
+ })),
102
+ framework: null,
103
+ ...installCommandOf(config.files),
104
+ target: config.target,
105
+ ...config.meta ? { meta: config.meta } : {}
106
+ });
107
+ return {
108
+ deploymentId: raw.id,
109
+ url: raw.url
110
+ };
111
+ }
112
+ /**
113
+ * The project's preview deployments tagged for `branch` (the `<repo>-pr-<number>` alias a file deploy puts in its
114
+ * `meta.holocronPreview`), found by reading the project's deployments page by page and matching the tag here, so
115
+ * only this project's deployments are ever candidates. A production or staging deployment is never one.
116
+ */
117
+ async listPreviewDeployments(projectId, branch) {
118
+ const found = [];
119
+ let until;
120
+ for (let page = 0; page < MAX_LIST_PAGES; page++) {
121
+ const { deployments, pagination } = await this.client().deployments.list({
122
+ projectId,
123
+ ...until !== void 0 ? { until } : {}
124
+ });
125
+ for (const raw of deployments) {
126
+ if (raw.target || raw.meta?.[PREVIEW_META_KEY] !== branch) continue;
127
+ found.push({
128
+ ...mapDeployment(raw, raw.meta?.githubCommitRef ?? null),
129
+ ...raw.createdAt ? { createdAt: new Date(raw.createdAt).toISOString() } : {}
130
+ });
131
+ }
132
+ const next = pagination?.next;
133
+ if (!next) break;
134
+ until = next;
135
+ }
136
+ return found;
137
+ }
138
+ /** The newest production deployment of the project in its latest page of deployments, or null. Reads only. */
139
+ async latestDeployment(projectId) {
140
+ const { deployments } = await this.client().deployments.list({ projectId });
141
+ const newest = deployments.find((d) => d.target === "production");
142
+ if (!newest) return null;
143
+ return {
144
+ ...mapDeployment(newest, newest.meta?.githubCommitRef ?? null),
145
+ ...newest.createdAt ? { createdAt: new Date(newest.createdAt).toISOString() } : {}
146
+ };
147
+ }
148
+ /** The hostnames attached to the project. Reads only. */
149
+ async listDomains(projectId) {
150
+ return (await this.client().domains.list(projectId)).domains.map((d) => d.name);
151
+ }
152
+ /** Deletes the deployments by id; one already gone (404) is not counted and is not an error. */
153
+ async deletePreviewDeployments(_projectId, deploymentIds) {
154
+ let deleted = 0;
155
+ for (const id of deploymentIds) try {
156
+ await this.client().deployments.remove(id);
157
+ deleted++;
158
+ } catch (err) {
159
+ if (!(err instanceof ProviderApiError && err.status === 404)) throw err;
160
+ }
161
+ return deleted;
162
+ }
163
+ /**
164
+ * Idempotent — matches `Deployment.ensureCustomDomain`'s contract
165
+ * (never break on re-runs, per CLAUDE.md's probe-then-act standard).
166
+ *
167
+ * Ownership (`domains.add`'s `verified`) and DNS routing are separate
168
+ * concerns: once a team already owns the domain's apex (true for any
169
+ * org with more than one project on the same domain), every new
170
+ * subdomain auto-verifies immediately with no `verification`
171
+ * challenge — re-adding an already-attached domain returns 409, not
172
+ * a fresh one. So attachment alone can't tell us whether traffic is
173
+ * actually routed to Vercel yet. `domains.config()` (Vercel's DNS
174
+ * *configuration* check) answers that regardless of ownership state:
175
+ * `misconfigured` + a `recommendedCNAME`, per-project, never a fixed
176
+ * well-known host — always read it from this response, never
177
+ * hardcode it. Returned as a `DnsRecordRequest` — the caller (e.g.
178
+ * `holocron setup`'s custom-domain step) hands it straight to
179
+ * `dns.upsertRecord()`, same as `Wiki.dnsRecord()` already does for
180
+ * the wiki's own domain.
181
+ */
182
+ async ensureCustomDomain(projectId, hostname) {
183
+ const { domains: existing } = await this.client().domains.list(projectId);
184
+ let apexName = existing.find((d) => d.name === hostname)?.apexName;
185
+ if (!apexName) try {
186
+ apexName = (await this.client().domains.add(projectId, hostname)).apexName;
187
+ } catch (err) {
188
+ if (!(err instanceof ProviderApiError && err.status === 409)) throw err;
189
+ const { domains: refreshed } = await this.client().domains.list(projectId);
190
+ apexName = refreshed.find((d) => d.name === hostname)?.apexName;
191
+ }
192
+ if (!apexName) return null;
193
+ const config = await this.client().domains.config(hostname, projectId);
194
+ if (!config.misconfigured) return null;
195
+ const cname = config.recommendedCNAME[0]?.value;
196
+ if (!cname) return null;
197
+ return {
198
+ zone: apexName,
199
+ record: {
200
+ type: "CNAME",
201
+ name: hostname,
202
+ content: cname
203
+ }
204
+ };
205
+ }
206
+ /**
207
+ * Read-only: the CNAME Vercel recommends for `hostname`, whether or not the domain already resolves. Unlike
208
+ * `ensureCustomDomain` it never attaches the domain, and it keeps the answer when `misconfigured` is false, so
209
+ * `holocron doctor dns` can compare it with the zone. The record is DNS-only: a proxied record breaks Vercel's
210
+ * certificate issuance.
211
+ */
212
+ async expectedDomainRecord(projectId, hostname) {
213
+ const cname = (await this.client().domains.config(hostname, projectId)).recommendedCNAME[0]?.value;
214
+ if (!cname) return null;
215
+ return {
216
+ zone: hostname,
217
+ record: {
218
+ type: "CNAME",
219
+ name: hostname,
220
+ content: cname,
221
+ proxied: false
222
+ }
223
+ };
224
+ }
63
225
  async getProjectByName(name) {
64
226
  try {
65
227
  return mapProject(await this.client().projects.get(name));
@@ -69,6 +231,22 @@ var VercelDeployment = class {
69
231
  }
70
232
  }
71
233
  };
234
+ /**
235
+ * The `installCommand` of an uploaded `vercel.json`, as the field `deployments.create()` takes.
236
+ * A deployment made from uploaded files ignores the file's `installCommand` in favour of the
237
+ * project's setting, so it is sent in the request too. Empty when there is no such file, it is
238
+ * not JSON, or it sets none.
239
+ */
240
+ function installCommandOf(files) {
241
+ const raw = files["vercel.json"];
242
+ if (raw === void 0) return {};
243
+ try {
244
+ const { installCommand } = JSON.parse(raw);
245
+ return typeof installCommand === "string" && installCommand ? { installCommand } : {};
246
+ } catch {
247
+ return {};
248
+ }
249
+ }
72
250
  function mapProject(raw) {
73
251
  const project = {
74
252
  id: raw.id,
@@ -87,6 +265,7 @@ function mapDeployment(raw, branch) {
87
265
  status: normalizeState(raw.readyState)
88
266
  };
89
267
  if (raw.target) record.target = raw.target;
268
+ if (raw.errorMessage) record.errorMessage = raw.errorMessage;
90
269
  return record;
91
270
  }
92
271
  function normalizeState(s) {
@@ -99,13 +278,87 @@ function normalizeState(s) {
99
278
  case "CANCELED": return "cancelled";
100
279
  }
101
280
  }
102
- //#endregion
103
- //#region src/verify-token.ts
281
+ // src/probes/token/parse-layer.ts
282
+ /** Reads `--layer <word>` (or `--layer=<word>`) from the words after the probe name, which the CLI passes when `--environment` named a layer. */
283
+ function parseLayer(args) {
284
+ for (let i = 0; i < args.length; i++) {
285
+ const arg = args[i];
286
+ if (arg === "--layer") return args[i + 1];
287
+ if (arg.startsWith("--layer=")) return arg.slice(8);
288
+ }
289
+ }
290
+ // src/probes/token/token.ts
104
291
  /**
105
- * `verifyToken` — plugin-level export used by `holocron auth set` +
106
- * `holocron auth check`. Hits `GET /v2/user` and translates the
107
- * response into the normalized `VerifyTokenResult` shape.
292
+ * 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
293
+ * are reads and change nothing. Vercel does not report a token's scope, so the probe cannot judge permissions: it says
294
+ * so, and with `--layer` (passed because `--environment` named a layer) it only says whether that layer is one that
295
+ * should hold the token, from the plugin's `tokens` declaration. The token is never printed.
108
296
  */
297
+ function tokenProbe(ctx) {
298
+ return {
299
+ summary: "Check a Vercel token with the current user and the project list, and for a layer that it is one that should hold the token. Vercel cannot report a token's scope, so permissions are not checked. Read-only.",
300
+ writes: false,
301
+ acceptsToken: true,
302
+ async run(probe) {
303
+ const token = ctx.token();
304
+ probe.secret(token);
305
+ const client = ctx.client();
306
+ const layer = parseLayer(probe.args ?? []);
307
+ if (layer) {
308
+ const declared = tokenExpectations(tokens, { layer }).length > 0;
309
+ probe.say(declared ? {
310
+ status: "ok",
311
+ label: layer,
312
+ detail: "a layer that should hold this token"
313
+ } : {
314
+ status: "info",
315
+ label: layer,
316
+ detail: "not a layer this token is declared for, so it is only described"
317
+ });
318
+ }
319
+ const who = await ctx.verify(token);
320
+ if (!who.ok) {
321
+ probe.say({
322
+ status: "fail",
323
+ label: "token",
324
+ detail: who.message
325
+ });
326
+ return;
327
+ }
328
+ probe.say({
329
+ status: "ok",
330
+ label: "token",
331
+ detail: who.subject
332
+ });
333
+ try {
334
+ const { projects } = await client.projects.list();
335
+ probe.say({
336
+ status: "ok",
337
+ label: "Projects: Read",
338
+ detail: `${projects.length} projects`
339
+ });
340
+ } catch (err) {
341
+ if (err instanceof ProviderApiError && (err.status === 401 || err.status === 403)) probe.say({
342
+ status: "info",
343
+ label: "Projects: Read",
344
+ detail: `no access (${err.status})`
345
+ });
346
+ else probe.say({
347
+ status: "fail",
348
+ label: "Projects: Read",
349
+ detail: errorMessage(err)
350
+ });
351
+ }
352
+ probe.say({
353
+ status: "info",
354
+ label: "permissions",
355
+ detail: "Vercel cannot report a token's scope, so it is not checked"
356
+ });
357
+ }
358
+ };
359
+ }
360
+ // src/verify-token.ts
361
+ /** 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. */
109
362
  async function verifyToken(token, opts = {}) {
110
363
  const client = createVercelClient({
111
364
  token,
@@ -121,12 +374,12 @@ async function verifyToken(token, opts = {}) {
121
374
  } catch (err) {
122
375
  return {
123
376
  ok: false,
124
- message: err instanceof Error ? err.message : String(err)
377
+ message: errorMessage(err)
125
378
  };
126
379
  }
127
380
  }
128
- //#endregion
129
- //#region src/index.ts
381
+ // src/index.ts
382
+ /** Creates the shared context for the given options; no token is resolved until `client()` is first called. */
130
383
  function createContext(options = {}) {
131
384
  let client;
132
385
  return {
@@ -139,22 +392,44 @@ function createContext(options = {}) {
139
392
  })
140
393
  };
141
394
  }
395
+ /** Builds the `deployment` capability from a plugin context, passing on `defaultFramework` and `domain` when set. */
142
396
  function deployment(ctx) {
143
397
  const opts = {};
144
398
  if (ctx.options.defaultFramework !== void 0) opts.defaultFramework = ctx.options.defaultFramework;
399
+ if (ctx.options.domain !== void 0) opts.domain = ctx.options.domain;
145
400
  return new VercelDeployment(ctx.client, opts);
146
401
  }
402
+ /** Creates the Vercel plugin: `connection` and `token` probes and the `deployment` capability. */
147
403
  function createPlugin(options = {}) {
148
404
  const ctx = createContext(options);
149
405
  return {
150
406
  name: "@theholocron/holocron-plugin-vercel",
407
+ probes: {
408
+ connection: connectionProbe({
409
+ provider: "Vercel",
410
+ url: options.baseUrl ?? "https://api.vercel.com",
411
+ fetch: options.fetch,
412
+ token: () => resolveToken(options),
413
+ verify: (token) => verifyToken(token, {
414
+ baseUrl: options.baseUrl,
415
+ fetch: options.fetch
416
+ })
417
+ }),
418
+ token: tokenProbe({
419
+ client: ctx.client,
420
+ token: () => resolveToken(options),
421
+ verify: (token) => verifyToken(token, {
422
+ baseUrl: options.baseUrl,
423
+ fetch: options.fetch
424
+ })
425
+ })
426
+ },
151
427
  capabilities: { deployment: () => deployment(ctx) }
152
428
  };
153
429
  }
154
430
  /**
155
- * One-line hint printed by `holocron auth set vercel` when no token
431
+ * One-line hint printed by `holocron new token vercel` when no token
156
432
  * is supplied or the supplied token is rejected.
157
433
  */
158
- 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>";
159
- //#endregion
160
- export { AUTH_HINT, AuthError, VercelDeployment, createContext, createPlugin, createVercelClient, deployment, resolveToken, verifyToken };
434
+ 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>";
435
+ 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.5",
3
+ "version": "5.0.0-alpha.500",
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,26 +30,29 @@
30
30
  "dist"
31
31
  ],
32
32
  "devDependencies": {
33
- "@theholocron/eslint-config": "^8.0.0",
34
- "@theholocron/tsconfig": "^8.0.0",
35
- "@theholocron/tsdown-config": "^8.0.0",
36
- "@theholocron/vercel-client": "^1.14.2",
37
- "@theholocron/vitest-config": "^8.0.0",
38
33
  "@types/node": "^26",
39
- "@vitest/coverage-v8": "^4.1.11",
40
- "@vitest/eslint-plugin": "^1.6.27",
41
- "eslint": "^10.8.1",
42
- "eslint-plugin-n": "^18.3.0",
43
- "globals": "^17.11.0",
44
- "tsdown": "^0.22.14",
45
- "tsx": "4.23.12",
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",
46
41
  "typescript": "^5.9.3",
47
- "vitest": "^4.1.11",
48
- "@theholocron/cli": "5.0.0-alpha.5"
42
+ "vitest": "^5.1.0",
43
+ "@theholocron/cli": "5.0.0-alpha.500",
44
+ "@theholocron/http-client": "^1.58.0-alpha.45",
45
+ "@theholocron/misc-utils": "^1.17.0-alpha.5",
46
+ "@theholocron/tsconfig": "^8.9.0-alpha.21",
47
+ "@theholocron/vercel-client": "^1.58.0-alpha.45",
48
+ "@theholocron/eslint-config": "^8.9.0-alpha.21",
49
+ "@theholocron/vitest-config": "^8.9.0-alpha.21",
50
+ "@theholocron/tsdown-config": "^8.9.0-alpha.21"
49
51
  },
50
52
  "peerDependencies": {
51
- "@theholocron/vercel-client": "^1.14.2",
52
- "@theholocron/cli": "5.0.0-alpha.5"
53
+ "@theholocron/misc-utils": "^1.16.0",
54
+ "@theholocron/vercel-client": "^1.43.1",
55
+ "@theholocron/cli": "5.0.0-alpha.500"
53
56
  },
54
57
  "peerDependenciesMeta": {
55
58
  "@theholocron/vercel-client": {}
@@ -61,11 +64,11 @@
61
64
  "access": "public"
62
65
  },
63
66
  "scripts": {
64
- "delivery.build": "tsdown",
65
- "sourceQuality.staticAnalysis": "holocron run sourceQuality.staticAnalysis --",
67
+ "build": "tsdown",
68
+ "lint:code": "eslint .",
69
+ "test:unit": "vitest run --coverage",
66
70
  "test:watch": "vitest",
67
- "validate": "tsx scripts/validate.mjs",
68
- "verification.typeSafety": "holocron run verification.typeSafety --",
69
- "verification.unitTests": "holocron run verification.unitTests --"
71
+ "typecheck": "tsc --noEmit",
72
+ "validate:plugin": "tsx scripts/validate.mjs"
70
73
  }
71
74
  }