@theholocron/holocron-plugin-vercel 5.0.0-alpha.426 → 5.0.0-alpha.429
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/dist/index.d.mts +3 -2
- package/dist/index.mjs +118 -14
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import { AuthError, DeployFunctionConfig, DeployFunctionResult, Deployment, Depl
|
|
|
2
2
|
import { VercelClient, VercelClient as VercelClient$1, VercelClientOptions, createVercelClient } from "@theholocron/vercel-client";
|
|
3
3
|
/** Resolves the Vercel token from `--token`, `HOLOCRON_VERCEL_TOKEN`, `VERCEL_TOKEN` or the keyring, and throws an `AuthError` when none is set. */
|
|
4
4
|
export declare const resolveToken: import("@theholocron/cli").TokenResolver;
|
|
5
|
-
/** Every token this plugin takes, for `holocron doctor tokens
|
|
5
|
+
/** Every token this plugin takes, for `holocron doctor tokens`, with the layers that hold it. */
|
|
6
6
|
export declare const tokens: PluginToken[];
|
|
7
7
|
interface DeploymentOptions {
|
|
8
8
|
/** Optional framework hint passed to project creates. Defaults to "nextjs". */
|
|
@@ -101,11 +101,12 @@ export interface PluginContext {
|
|
|
101
101
|
export declare function createContext(options?: VercelPluginOptions): PluginContext;
|
|
102
102
|
/** Builds the `deployment` capability from a plugin context, passing on `defaultFramework` and `domain` when set. */
|
|
103
103
|
export declare function deployment(ctx: PluginContext): Deployment;
|
|
104
|
-
/** Creates the Vercel plugin:
|
|
104
|
+
/** Creates the Vercel plugin: `connection` and `token` probes and the `deployment` capability. */
|
|
105
105
|
export declare function createPlugin(options?: VercelPluginOptions): {
|
|
106
106
|
name: string;
|
|
107
107
|
probes: {
|
|
108
108
|
connection: import("@theholocron/cli").Probe;
|
|
109
|
+
token: import("@theholocron/cli").Probe;
|
|
109
110
|
};
|
|
110
111
|
capabilities: {
|
|
111
112
|
deployment: () => Deployment;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
import { AuthError, ProviderApiError, connectionProbe, createResolveToken } from "@theholocron/cli";
|
|
2
|
-
import { createVercelClient } from "@theholocron/vercel-client";
|
|
1
|
+
import { AuthError, ProviderApiError, connectionProbe, createResolveToken, tokenExpectations } from "@theholocron/cli";
|
|
3
2
|
import { errorMessage } from "@theholocron/misc-utils";
|
|
3
|
+
import { createVercelClient } from "@theholocron/vercel-client";
|
|
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
|
+
] };
|
|
4
16
|
// src/auth.ts
|
|
5
17
|
/** Resolves the Vercel token from `--token`, `HOLOCRON_VERCEL_TOKEN`, `VERCEL_TOKEN` or the keyring, and throws an `AuthError` when none is set. */
|
|
6
18
|
const resolveToken = createResolveToken({
|
|
@@ -9,8 +21,11 @@ const resolveToken = createResolveToken({
|
|
|
9
21
|
keyringService: "vercel",
|
|
10
22
|
errorMessage: "no Vercel token found. Pass --token <PAT>, set HOLOCRON_VERCEL_TOKEN / VERCEL_TOKEN, or run: holocron new token vercel <PAT>"
|
|
11
23
|
});
|
|
12
|
-
/** Every token this plugin takes, for `holocron doctor tokens
|
|
13
|
-
const tokens = [
|
|
24
|
+
/** Every token this plugin takes, for `holocron doctor tokens`, with the layers that hold it. */
|
|
25
|
+
const tokens = [{
|
|
26
|
+
...resolveToken.token,
|
|
27
|
+
expect: EXPECTED
|
|
28
|
+
}];
|
|
14
29
|
// src/capabilities/deployment.ts
|
|
15
30
|
/** The `deployment` capability for Vercel: projects, environment variables, deployments, functions and custom domains. */
|
|
16
31
|
var VercelDeployment = class {
|
|
@@ -207,6 +222,85 @@ function normalizeState(s) {
|
|
|
207
222
|
case "CANCELED": return "cancelled";
|
|
208
223
|
}
|
|
209
224
|
}
|
|
225
|
+
// src/probes/token/parse-layer.ts
|
|
226
|
+
/** Reads `--layer <word>` (or `--layer=<word>`) from the words after the probe name, which the CLI passes when `--environment` named a layer. */
|
|
227
|
+
function parseLayer(args) {
|
|
228
|
+
for (let i = 0; i < args.length; i++) {
|
|
229
|
+
const arg = args[i];
|
|
230
|
+
if (arg === "--layer") return args[i + 1];
|
|
231
|
+
if (arg.startsWith("--layer=")) return arg.slice(8);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
// src/probes/token/token.ts
|
|
235
|
+
/**
|
|
236
|
+
* 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
|
|
237
|
+
* are reads and change nothing. Vercel does not report a token's scope, so the probe cannot judge permissions: it says
|
|
238
|
+
* so, and with `--layer` (passed because `--environment` named a layer) it only says whether that layer is one that
|
|
239
|
+
* should hold the token, from the plugin's `tokens` declaration. The token is never printed.
|
|
240
|
+
*/
|
|
241
|
+
function tokenProbe(ctx) {
|
|
242
|
+
return {
|
|
243
|
+
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.",
|
|
244
|
+
writes: false,
|
|
245
|
+
acceptsToken: true,
|
|
246
|
+
async run(probe) {
|
|
247
|
+
const token = ctx.token();
|
|
248
|
+
probe.secret(token);
|
|
249
|
+
const client = ctx.client();
|
|
250
|
+
const layer = parseLayer(probe.args ?? []);
|
|
251
|
+
if (layer) {
|
|
252
|
+
const declared = tokenExpectations(tokens, { layer }).length > 0;
|
|
253
|
+
probe.say(declared ? {
|
|
254
|
+
status: "ok",
|
|
255
|
+
label: layer,
|
|
256
|
+
detail: "a layer that should hold this token"
|
|
257
|
+
} : {
|
|
258
|
+
status: "info",
|
|
259
|
+
label: layer,
|
|
260
|
+
detail: "not a layer this token is declared for, so it is only described"
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
const who = await ctx.verify(token);
|
|
264
|
+
if (!who.ok) {
|
|
265
|
+
probe.say({
|
|
266
|
+
status: "fail",
|
|
267
|
+
label: "token",
|
|
268
|
+
detail: who.message
|
|
269
|
+
});
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
probe.say({
|
|
273
|
+
status: "ok",
|
|
274
|
+
label: "token",
|
|
275
|
+
detail: who.subject
|
|
276
|
+
});
|
|
277
|
+
try {
|
|
278
|
+
const { projects } = await client.projects.list();
|
|
279
|
+
probe.say({
|
|
280
|
+
status: "ok",
|
|
281
|
+
label: "Projects: Read",
|
|
282
|
+
detail: `${projects.length} projects`
|
|
283
|
+
});
|
|
284
|
+
} catch (err) {
|
|
285
|
+
if (err instanceof ProviderApiError && (err.status === 401 || err.status === 403)) probe.say({
|
|
286
|
+
status: "info",
|
|
287
|
+
label: "Projects: Read",
|
|
288
|
+
detail: `no access (${err.status})`
|
|
289
|
+
});
|
|
290
|
+
else probe.say({
|
|
291
|
+
status: "fail",
|
|
292
|
+
label: "Projects: Read",
|
|
293
|
+
detail: errorMessage(err)
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
probe.say({
|
|
297
|
+
status: "info",
|
|
298
|
+
label: "permissions",
|
|
299
|
+
detail: "Vercel cannot report a token's scope, so it is not checked"
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
}
|
|
210
304
|
// src/verify-token.ts
|
|
211
305
|
/** 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. */
|
|
212
306
|
async function verifyToken(token, opts = {}) {
|
|
@@ -249,21 +343,31 @@ function deployment(ctx) {
|
|
|
249
343
|
if (ctx.options.domain !== void 0) opts.domain = ctx.options.domain;
|
|
250
344
|
return new VercelDeployment(ctx.client, opts);
|
|
251
345
|
}
|
|
252
|
-
/** Creates the Vercel plugin:
|
|
346
|
+
/** Creates the Vercel plugin: `connection` and `token` probes and the `deployment` capability. */
|
|
253
347
|
function createPlugin(options = {}) {
|
|
254
348
|
const ctx = createContext(options);
|
|
255
349
|
return {
|
|
256
350
|
name: "@theholocron/holocron-plugin-vercel",
|
|
257
|
-
probes: {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
351
|
+
probes: {
|
|
352
|
+
connection: connectionProbe({
|
|
353
|
+
provider: "Vercel",
|
|
354
|
+
url: options.baseUrl ?? "https://api.vercel.com",
|
|
355
|
+
fetch: options.fetch,
|
|
356
|
+
token: () => resolveToken(options),
|
|
357
|
+
verify: (token) => verifyToken(token, {
|
|
358
|
+
baseUrl: options.baseUrl,
|
|
359
|
+
fetch: options.fetch
|
|
360
|
+
})
|
|
361
|
+
}),
|
|
362
|
+
token: tokenProbe({
|
|
363
|
+
client: ctx.client,
|
|
364
|
+
token: () => resolveToken(options),
|
|
365
|
+
verify: (token) => verifyToken(token, {
|
|
366
|
+
baseUrl: options.baseUrl,
|
|
367
|
+
fetch: options.fetch
|
|
368
|
+
})
|
|
265
369
|
})
|
|
266
|
-
}
|
|
370
|
+
},
|
|
267
371
|
capabilities: { deployment: () => deployment(ctx) }
|
|
268
372
|
};
|
|
269
373
|
}
|
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.429",
|
|
4
4
|
"description": "Holocron plugin for Vercel. Implements the deployment capability against the Vercel REST API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deployment",
|
|
@@ -40,19 +40,19 @@
|
|
|
40
40
|
"tsx": "4.23.15",
|
|
41
41
|
"typescript": "^5.9.3",
|
|
42
42
|
"vitest": "^5.1.0",
|
|
43
|
-
"@theholocron/cli": "5.0.0-alpha.426",
|
|
44
|
-
"@theholocron/http-client": "^1.58.0-alpha.29",
|
|
45
43
|
"@theholocron/eslint-config": "^8.9.0-alpha.17",
|
|
44
|
+
"@theholocron/http-client": "^1.58.0-alpha.29",
|
|
45
|
+
"@theholocron/tsconfig": "^8.9.0-alpha.17",
|
|
46
46
|
"@theholocron/misc-utils": "^1.17.0-alpha.4",
|
|
47
|
+
"@theholocron/cli": "5.0.0-alpha.429",
|
|
47
48
|
"@theholocron/tsdown-config": "^8.9.0-alpha.17",
|
|
48
49
|
"@theholocron/vercel-client": "^1.58.0-alpha.29",
|
|
49
|
-
"@theholocron/tsconfig": "^8.9.0-alpha.17",
|
|
50
50
|
"@theholocron/vitest-config": "^8.9.0-alpha.17"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"@theholocron/misc-utils": "^1.16.0",
|
|
54
54
|
"@theholocron/vercel-client": "^1.43.1",
|
|
55
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
55
|
+
"@theholocron/cli": "5.0.0-alpha.429"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
58
58
|
"@theholocron/vercel-client": {}
|