@theholocron/holocron-plugin-vercel 5.0.0-alpha.47 → 5.0.0-alpha.470
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 +7 -2
- package/dist/index.d.mts +56 -34
- package/dist/index.mjs +218 -18
- package/package.json +27 -25
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
|
|
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
|
-
|
|
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
|
-
|
|
4
|
-
declare const resolveToken: (
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
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,28 @@ 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
|
+
/** Lists the names of the project's environment variables that apply to `target`. */
|
|
28
40
|
listEnvVars(projectId: string, target: DeploymentTarget): Promise<string[]>;
|
|
41
|
+
/** Creates or updates (upsert) an environment variable on the project for `target`. */
|
|
29
42
|
setEnvVar(projectId: string, target: DeploymentTarget, name: string, value: string): Promise<void>;
|
|
30
43
|
triggerDeployment(input: {
|
|
31
44
|
projectId: string;
|
|
32
45
|
branch: string;
|
|
33
46
|
target?: DeploymentTrigger;
|
|
34
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. */
|
|
35
49
|
getDeployment(deploymentId: string): Promise<DeploymentRecord>;
|
|
36
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
|
+
/** Deletes the deployments by id; one already gone (404) is not counted and is not an error. */
|
|
58
|
+
deletePreviewDeployments(_projectId: string, deploymentIds: string[]): Promise<number>;
|
|
37
59
|
/**
|
|
38
60
|
* Idempotent — matches `Deployment.ensureCustomDomain`'s contract
|
|
39
61
|
* (never break on re-runs, per CLAUDE.md's probe-then-act standard).
|
|
@@ -54,32 +76,23 @@ declare class VercelDeployment implements Deployment {
|
|
|
54
76
|
* the wiki's own domain.
|
|
55
77
|
*/
|
|
56
78
|
ensureCustomDomain(projectId: string, hostname: string): Promise<DnsRecordRequest | null>;
|
|
79
|
+
/**
|
|
80
|
+
* Read-only: the CNAME Vercel recommends for `hostname`, whether or not the domain already resolves. Unlike
|
|
81
|
+
* `ensureCustomDomain` it never attaches the domain, and it keeps the answer when `misconfigured` is false, so
|
|
82
|
+
* `holocron doctor dns` can compare it with the zone. The record is DNS-only: a proxied record breaks Vercel's
|
|
83
|
+
* certificate issuance.
|
|
84
|
+
*/
|
|
85
|
+
expectedDomainRecord(projectId: string, hostname: string): Promise<DnsRecordRequest | null>;
|
|
57
86
|
private getProjectByName;
|
|
58
87
|
}
|
|
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
88
|
interface VerifyTokenOptions {
|
|
76
89
|
baseUrl?: string;
|
|
77
90
|
fetch?: typeof fetch;
|
|
78
91
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
interface VercelPluginOptions extends ResolveTokenInput {
|
|
92
|
+
/** 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. */
|
|
93
|
+
export declare function verifyToken(token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult$1>;
|
|
94
|
+
/** Options for the Vercel plugin: token resolution, team, defaults for new projects and test overrides. */
|
|
95
|
+
export interface VercelPluginOptions extends ResolveTokenInput {
|
|
83
96
|
/** Vercel team id. Set when working with a team-owned project. */
|
|
84
97
|
teamId?: string;
|
|
85
98
|
/** Default framework slug for new project creates. Defaults to "nextjs". */
|
|
@@ -91,22 +104,31 @@ interface VercelPluginOptions extends ResolveTokenInput {
|
|
|
91
104
|
/** Override `fetch` for tests. */
|
|
92
105
|
fetch?: typeof fetch;
|
|
93
106
|
}
|
|
94
|
-
|
|
107
|
+
/** What the plugin's capabilities share: the options and a lazily built client. */
|
|
108
|
+
export interface PluginContext {
|
|
109
|
+
/** The options the plugin was created with. */
|
|
95
110
|
options: VercelPluginOptions;
|
|
111
|
+
/** Builds the Vercel client on first call and reuses it; the token is resolved then, not at plugin load. */
|
|
96
112
|
client: () => VercelClient;
|
|
97
113
|
}
|
|
98
|
-
|
|
99
|
-
declare function
|
|
100
|
-
|
|
114
|
+
/** Creates the shared context for the given options; no token is resolved until `client()` is first called. */
|
|
115
|
+
export declare function createContext(options?: VercelPluginOptions): PluginContext;
|
|
116
|
+
/** Builds the `deployment` capability from a plugin context, passing on `defaultFramework` and `domain` when set. */
|
|
117
|
+
export declare function deployment(ctx: PluginContext): Deployment;
|
|
118
|
+
/** Creates the Vercel plugin: `connection` and `token` probes and the `deployment` capability. */
|
|
119
|
+
export declare function createPlugin(options?: VercelPluginOptions): {
|
|
101
120
|
name: string;
|
|
121
|
+
probes: {
|
|
122
|
+
connection: import("@theholocron/cli").Probe;
|
|
123
|
+
token: import("@theholocron/cli").Probe;
|
|
124
|
+
};
|
|
102
125
|
capabilities: {
|
|
103
126
|
deployment: () => Deployment;
|
|
104
127
|
};
|
|
105
128
|
};
|
|
106
129
|
/**
|
|
107
|
-
* One-line hint printed by `holocron
|
|
130
|
+
* One-line hint printed by `holocron new token vercel` when no token
|
|
108
131
|
* is supplied or the supplied token is rejected.
|
|
109
132
|
*/
|
|
110
|
-
declare const AUTH_HINT: string;
|
|
111
|
-
|
|
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 };
|
|
133
|
+
export declare const AUTH_HINT: string;
|
|
134
|
+
export { AuthError, type ResolveTokenInput, type VercelClient, type VercelClientOptions, type VerifyTokenFailure, type VerifyTokenResult, type VerifyTokenSuccess, createVercelClient };
|
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,42 @@
|
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
11
|
-
|
|
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";
|
|
16
41
|
domain;
|
|
17
42
|
defaultFramework;
|
|
@@ -20,6 +45,7 @@ var VercelDeployment = class {
|
|
|
20
45
|
this.defaultFramework = opts.defaultFramework ?? "nextjs";
|
|
21
46
|
this.domain = opts.domain;
|
|
22
47
|
}
|
|
48
|
+
/** Lists the projects the token can see, mapped to the provider-neutral shape. */
|
|
23
49
|
async listProjects() {
|
|
24
50
|
const { projects } = await this.client().projects.list();
|
|
25
51
|
return projects.map(mapProject);
|
|
@@ -34,16 +60,19 @@ var VercelDeployment = class {
|
|
|
34
60
|
rootDirectory: input.rootDirectory
|
|
35
61
|
}));
|
|
36
62
|
}
|
|
63
|
+
/** Updates a project's preview-deployment and Git-provider deployment settings and returns the updated project. */
|
|
37
64
|
async updateProjectSettings(projectId, settings) {
|
|
38
65
|
return mapProject(await this.client().projects.update(projectId, {
|
|
39
66
|
previewDeploymentsDisabled: settings.previewDeploymentsDisabled,
|
|
40
67
|
gitProviderOptions: settings.gitProviderCreateDeployments !== void 0 ? { createDeployments: settings.gitProviderCreateDeployments } : void 0
|
|
41
68
|
}));
|
|
42
69
|
}
|
|
70
|
+
/** Lists the names of the project's environment variables that apply to `target`. */
|
|
43
71
|
async listEnvVars(projectId, target) {
|
|
44
72
|
const { envs } = await this.client().env.list(projectId);
|
|
45
73
|
return envs.filter((e) => e.target.includes(target)).map((e) => e.key);
|
|
46
74
|
}
|
|
75
|
+
/** Creates or updates (upsert) an environment variable on the project for `target`. */
|
|
47
76
|
async setEnvVar(projectId, target, name, value) {
|
|
48
77
|
await this.client().env.set(projectId, target, name, value);
|
|
49
78
|
}
|
|
@@ -58,6 +87,7 @@ var VercelDeployment = class {
|
|
|
58
87
|
target: input.target
|
|
59
88
|
}), input.branch);
|
|
60
89
|
}
|
|
90
|
+
/** Fetches a deployment by id; the record's branch is the deployment's Git commit ref, or `null` when it has none. */
|
|
61
91
|
async getDeployment(deploymentId) {
|
|
62
92
|
const raw = await this.client().deployments.get(deploymentId);
|
|
63
93
|
return mapDeployment(raw, raw.meta?.githubCommitRef ?? null);
|
|
@@ -70,7 +100,9 @@ var VercelDeployment = class {
|
|
|
70
100
|
content
|
|
71
101
|
})),
|
|
72
102
|
framework: null,
|
|
73
|
-
|
|
103
|
+
...installCommandOf(config.files),
|
|
104
|
+
target: config.target,
|
|
105
|
+
...config.meta ? { meta: config.meta } : {}
|
|
74
106
|
});
|
|
75
107
|
return {
|
|
76
108
|
deploymentId: raw.id,
|
|
@@ -78,6 +110,43 @@ var VercelDeployment = class {
|
|
|
78
110
|
};
|
|
79
111
|
}
|
|
80
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
|
+
/** Deletes the deployments by id; one already gone (404) is not counted and is not an error. */
|
|
139
|
+
async deletePreviewDeployments(_projectId, deploymentIds) {
|
|
140
|
+
let deleted = 0;
|
|
141
|
+
for (const id of deploymentIds) try {
|
|
142
|
+
await this.client().deployments.remove(id);
|
|
143
|
+
deleted++;
|
|
144
|
+
} catch (err) {
|
|
145
|
+
if (!(err instanceof ProviderApiError && err.status === 404)) throw err;
|
|
146
|
+
}
|
|
147
|
+
return deleted;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
81
150
|
* Idempotent — matches `Deployment.ensureCustomDomain`'s contract
|
|
82
151
|
* (never break on re-runs, per CLAUDE.md's probe-then-act standard).
|
|
83
152
|
*
|
|
@@ -120,6 +189,25 @@ var VercelDeployment = class {
|
|
|
120
189
|
}
|
|
121
190
|
};
|
|
122
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Read-only: the CNAME Vercel recommends for `hostname`, whether or not the domain already resolves. Unlike
|
|
194
|
+
* `ensureCustomDomain` it never attaches the domain, and it keeps the answer when `misconfigured` is false, so
|
|
195
|
+
* `holocron doctor dns` can compare it with the zone. The record is DNS-only: a proxied record breaks Vercel's
|
|
196
|
+
* certificate issuance.
|
|
197
|
+
*/
|
|
198
|
+
async expectedDomainRecord(projectId, hostname) {
|
|
199
|
+
const cname = (await this.client().domains.config(hostname, projectId)).recommendedCNAME[0]?.value;
|
|
200
|
+
if (!cname) return null;
|
|
201
|
+
return {
|
|
202
|
+
zone: hostname,
|
|
203
|
+
record: {
|
|
204
|
+
type: "CNAME",
|
|
205
|
+
name: hostname,
|
|
206
|
+
content: cname,
|
|
207
|
+
proxied: false
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
123
211
|
async getProjectByName(name) {
|
|
124
212
|
try {
|
|
125
213
|
return mapProject(await this.client().projects.get(name));
|
|
@@ -129,6 +217,22 @@ var VercelDeployment = class {
|
|
|
129
217
|
}
|
|
130
218
|
}
|
|
131
219
|
};
|
|
220
|
+
/**
|
|
221
|
+
* The `installCommand` of an uploaded `vercel.json`, as the field `deployments.create()` takes.
|
|
222
|
+
* A deployment made from uploaded files ignores the file's `installCommand` in favour of the
|
|
223
|
+
* project's setting, so it is sent in the request too. Empty when there is no such file, it is
|
|
224
|
+
* not JSON, or it sets none.
|
|
225
|
+
*/
|
|
226
|
+
function installCommandOf(files) {
|
|
227
|
+
const raw = files["vercel.json"];
|
|
228
|
+
if (raw === void 0) return {};
|
|
229
|
+
try {
|
|
230
|
+
const { installCommand } = JSON.parse(raw);
|
|
231
|
+
return typeof installCommand === "string" && installCommand ? { installCommand } : {};
|
|
232
|
+
} catch {
|
|
233
|
+
return {};
|
|
234
|
+
}
|
|
235
|
+
}
|
|
132
236
|
function mapProject(raw) {
|
|
133
237
|
const project = {
|
|
134
238
|
id: raw.id,
|
|
@@ -147,6 +251,7 @@ function mapDeployment(raw, branch) {
|
|
|
147
251
|
status: normalizeState(raw.readyState)
|
|
148
252
|
};
|
|
149
253
|
if (raw.target) record.target = raw.target;
|
|
254
|
+
if (raw.errorMessage) record.errorMessage = raw.errorMessage;
|
|
150
255
|
return record;
|
|
151
256
|
}
|
|
152
257
|
function normalizeState(s) {
|
|
@@ -159,13 +264,87 @@ function normalizeState(s) {
|
|
|
159
264
|
case "CANCELED": return "cancelled";
|
|
160
265
|
}
|
|
161
266
|
}
|
|
162
|
-
|
|
163
|
-
|
|
267
|
+
// src/probes/token/parse-layer.ts
|
|
268
|
+
/** Reads `--layer <word>` (or `--layer=<word>`) from the words after the probe name, which the CLI passes when `--environment` named a layer. */
|
|
269
|
+
function parseLayer(args) {
|
|
270
|
+
for (let i = 0; i < args.length; i++) {
|
|
271
|
+
const arg = args[i];
|
|
272
|
+
if (arg === "--layer") return args[i + 1];
|
|
273
|
+
if (arg.startsWith("--layer=")) return arg.slice(8);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
// src/probes/token/token.ts
|
|
164
277
|
/**
|
|
165
|
-
* `
|
|
166
|
-
*
|
|
167
|
-
*
|
|
278
|
+
* 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
|
|
279
|
+
* are reads and change nothing. Vercel does not report a token's scope, so the probe cannot judge permissions: it says
|
|
280
|
+
* so, and with `--layer` (passed because `--environment` named a layer) it only says whether that layer is one that
|
|
281
|
+
* should hold the token, from the plugin's `tokens` declaration. The token is never printed.
|
|
168
282
|
*/
|
|
283
|
+
function tokenProbe(ctx) {
|
|
284
|
+
return {
|
|
285
|
+
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.",
|
|
286
|
+
writes: false,
|
|
287
|
+
acceptsToken: true,
|
|
288
|
+
async run(probe) {
|
|
289
|
+
const token = ctx.token();
|
|
290
|
+
probe.secret(token);
|
|
291
|
+
const client = ctx.client();
|
|
292
|
+
const layer = parseLayer(probe.args ?? []);
|
|
293
|
+
if (layer) {
|
|
294
|
+
const declared = tokenExpectations(tokens, { layer }).length > 0;
|
|
295
|
+
probe.say(declared ? {
|
|
296
|
+
status: "ok",
|
|
297
|
+
label: layer,
|
|
298
|
+
detail: "a layer that should hold this token"
|
|
299
|
+
} : {
|
|
300
|
+
status: "info",
|
|
301
|
+
label: layer,
|
|
302
|
+
detail: "not a layer this token is declared for, so it is only described"
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
const who = await ctx.verify(token);
|
|
306
|
+
if (!who.ok) {
|
|
307
|
+
probe.say({
|
|
308
|
+
status: "fail",
|
|
309
|
+
label: "token",
|
|
310
|
+
detail: who.message
|
|
311
|
+
});
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
probe.say({
|
|
315
|
+
status: "ok",
|
|
316
|
+
label: "token",
|
|
317
|
+
detail: who.subject
|
|
318
|
+
});
|
|
319
|
+
try {
|
|
320
|
+
const { projects } = await client.projects.list();
|
|
321
|
+
probe.say({
|
|
322
|
+
status: "ok",
|
|
323
|
+
label: "Projects: Read",
|
|
324
|
+
detail: `${projects.length} projects`
|
|
325
|
+
});
|
|
326
|
+
} catch (err) {
|
|
327
|
+
if (err instanceof ProviderApiError && (err.status === 401 || err.status === 403)) probe.say({
|
|
328
|
+
status: "info",
|
|
329
|
+
label: "Projects: Read",
|
|
330
|
+
detail: `no access (${err.status})`
|
|
331
|
+
});
|
|
332
|
+
else probe.say({
|
|
333
|
+
status: "fail",
|
|
334
|
+
label: "Projects: Read",
|
|
335
|
+
detail: errorMessage(err)
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
probe.say({
|
|
339
|
+
status: "info",
|
|
340
|
+
label: "permissions",
|
|
341
|
+
detail: "Vercel cannot report a token's scope, so it is not checked"
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
// src/verify-token.ts
|
|
347
|
+
/** 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
348
|
async function verifyToken(token, opts = {}) {
|
|
170
349
|
const client = createVercelClient({
|
|
171
350
|
token,
|
|
@@ -181,12 +360,12 @@ async function verifyToken(token, opts = {}) {
|
|
|
181
360
|
} catch (err) {
|
|
182
361
|
return {
|
|
183
362
|
ok: false,
|
|
184
|
-
message:
|
|
363
|
+
message: errorMessage(err)
|
|
185
364
|
};
|
|
186
365
|
}
|
|
187
366
|
}
|
|
188
|
-
|
|
189
|
-
|
|
367
|
+
// src/index.ts
|
|
368
|
+
/** Creates the shared context for the given options; no token is resolved until `client()` is first called. */
|
|
190
369
|
function createContext(options = {}) {
|
|
191
370
|
let client;
|
|
192
371
|
return {
|
|
@@ -199,23 +378,44 @@ function createContext(options = {}) {
|
|
|
199
378
|
})
|
|
200
379
|
};
|
|
201
380
|
}
|
|
381
|
+
/** Builds the `deployment` capability from a plugin context, passing on `defaultFramework` and `domain` when set. */
|
|
202
382
|
function deployment(ctx) {
|
|
203
383
|
const opts = {};
|
|
204
384
|
if (ctx.options.defaultFramework !== void 0) opts.defaultFramework = ctx.options.defaultFramework;
|
|
205
385
|
if (ctx.options.domain !== void 0) opts.domain = ctx.options.domain;
|
|
206
386
|
return new VercelDeployment(ctx.client, opts);
|
|
207
387
|
}
|
|
388
|
+
/** Creates the Vercel plugin: `connection` and `token` probes and the `deployment` capability. */
|
|
208
389
|
function createPlugin(options = {}) {
|
|
209
390
|
const ctx = createContext(options);
|
|
210
391
|
return {
|
|
211
392
|
name: "@theholocron/holocron-plugin-vercel",
|
|
393
|
+
probes: {
|
|
394
|
+
connection: connectionProbe({
|
|
395
|
+
provider: "Vercel",
|
|
396
|
+
url: options.baseUrl ?? "https://api.vercel.com",
|
|
397
|
+
fetch: options.fetch,
|
|
398
|
+
token: () => resolveToken(options),
|
|
399
|
+
verify: (token) => verifyToken(token, {
|
|
400
|
+
baseUrl: options.baseUrl,
|
|
401
|
+
fetch: options.fetch
|
|
402
|
+
})
|
|
403
|
+
}),
|
|
404
|
+
token: tokenProbe({
|
|
405
|
+
client: ctx.client,
|
|
406
|
+
token: () => resolveToken(options),
|
|
407
|
+
verify: (token) => verifyToken(token, {
|
|
408
|
+
baseUrl: options.baseUrl,
|
|
409
|
+
fetch: options.fetch
|
|
410
|
+
})
|
|
411
|
+
})
|
|
412
|
+
},
|
|
212
413
|
capabilities: { deployment: () => deployment(ctx) }
|
|
213
414
|
};
|
|
214
415
|
}
|
|
215
416
|
/**
|
|
216
|
-
* One-line hint printed by `holocron
|
|
417
|
+
* One-line hint printed by `holocron new token vercel` when no token
|
|
217
418
|
* is supplied or the supplied token is rejected.
|
|
218
419
|
*/
|
|
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
|
|
220
|
-
|
|
221
|
-
export { AUTH_HINT, AuthError, VercelDeployment, createContext, createPlugin, createVercelClient, deployment, resolveToken, verifyToken };
|
|
420
|
+
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>";
|
|
421
|
+
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.
|
|
3
|
+
"version": "5.0.0-alpha.470",
|
|
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://
|
|
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": "
|
|
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": "^
|
|
41
|
-
"@vitest/eslint-plugin": "^1.6.
|
|
42
|
-
"eslint": "^10.
|
|
43
|
-
"eslint-plugin-n": "^18.
|
|
44
|
-
"globals": "^17.
|
|
45
|
-
"tsdown": "^0.
|
|
46
|
-
"tsx": "4.23.
|
|
34
|
+
"@vitest/coverage-v8": "^5.1.0",
|
|
35
|
+
"@vitest/eslint-plugin": "^1.6.28",
|
|
36
|
+
"eslint": "^10.14.0",
|
|
37
|
+
"eslint-plugin-n": "^18.5.0",
|
|
38
|
+
"globals": "^17.14.0",
|
|
39
|
+
"tsdown": "^0.23.7",
|
|
40
|
+
"tsx": "4.23.15",
|
|
47
41
|
"typescript": "^5.9.3",
|
|
48
|
-
"vitest": "^
|
|
49
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
42
|
+
"vitest": "^5.1.0",
|
|
43
|
+
"@theholocron/cli": "5.0.0-alpha.470",
|
|
44
|
+
"@theholocron/eslint-config": "^8.9.0-alpha.20",
|
|
45
|
+
"@theholocron/http-client": "^1.58.0-alpha.40",
|
|
46
|
+
"@theholocron/misc-utils": "^1.17.0-alpha.5",
|
|
47
|
+
"@theholocron/tsconfig": "^8.9.0-alpha.20",
|
|
48
|
+
"@theholocron/tsdown-config": "^8.9.0-alpha.20",
|
|
49
|
+
"@theholocron/vitest-config": "^8.9.0-alpha.20",
|
|
50
|
+
"@theholocron/vercel-client": "^1.58.0-alpha.40"
|
|
50
51
|
},
|
|
51
52
|
"peerDependencies": {
|
|
52
|
-
"@theholocron/
|
|
53
|
-
"@theholocron/
|
|
53
|
+
"@theholocron/misc-utils": "^1.16.0",
|
|
54
|
+
"@theholocron/vercel-client": "^1.43.1",
|
|
55
|
+
"@theholocron/cli": "5.0.0-alpha.470"
|
|
54
56
|
},
|
|
55
57
|
"peerDependenciesMeta": {
|
|
56
58
|
"@theholocron/vercel-client": {}
|
|
@@ -62,11 +64,11 @@
|
|
|
62
64
|
"access": "public"
|
|
63
65
|
},
|
|
64
66
|
"scripts": {
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
+
"build": "tsdown",
|
|
68
|
+
"lint:code": "eslint .",
|
|
69
|
+
"test:unit": "vitest run --coverage",
|
|
67
70
|
"test:watch": "vitest",
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"verification.unitTests": "holocron run verification.unitTests --"
|
|
71
|
+
"typecheck": "tsc --noEmit",
|
|
72
|
+
"validate:plugin": "tsx scripts/validate.mjs"
|
|
71
73
|
}
|
|
72
74
|
}
|