@sentry/junior-vercel 0.302.0 → 0.303.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,332 +0,0 @@
1
- // src/events/deployment.ts
2
- import {
3
- eventMatchFieldsSchema
4
- } from "@sentry/junior-plugin-api";
5
- var VERCEL_DEPLOYMENT_EVENTS = [
6
- "deployment.succeeded",
7
- "deployment.error",
8
- "deployment.canceled"
9
- ];
10
- var VERCEL_DEPLOYMENT_SUGGESTED_EVENTS = [
11
- "deployment.succeeded",
12
- "deployment.error",
13
- "deployment.canceled"
14
- ];
15
- var VERCEL_DEPLOYMENT_TARGETS = [
16
- "preview",
17
- "production",
18
- "staging"
19
- ];
20
- var VERCEL_DEPLOYMENT_MATCH_FIELDS = eventMatchFieldsSchema.parse({
21
- projectId: {
22
- kind: "string",
23
- description: "Vercel project id, such as prj_abc123",
24
- events: [...VERCEL_DEPLOYMENT_EVENTS]
25
- },
26
- deploymentId: {
27
- kind: "string",
28
- description: "Vercel deployment id, such as dpl_abc123",
29
- events: [...VERCEL_DEPLOYMENT_EVENTS]
30
- },
31
- target: {
32
- kind: "string",
33
- description: "where Vercel deployed: preview, production, or staging",
34
- enum: [...VERCEL_DEPLOYMENT_TARGETS],
35
- events: [...VERCEL_DEPLOYMENT_EVENTS]
36
- },
37
- commitSha: {
38
- kind: "string",
39
- case: "lower",
40
- description: "full lowercase Git commit SHA of the deployment, when it came from a Git commit",
41
- events: [...VERCEL_DEPLOYMENT_EVENTS]
42
- }
43
- });
44
- function vercelDeploymentResource(input) {
45
- const commitSha = input.commitSha?.toLowerCase();
46
- const target = input.target;
47
- const parts = [input.projectId];
48
- if (target) parts.push(target);
49
- if (commitSha) parts.push(commitSha);
50
- let label;
51
- if (target && commitSha) {
52
- label = `Vercel ${target} deployment for ${input.projectId} at ${commitSha.slice(0, 12)}`;
53
- } else if (target) {
54
- label = `Vercel ${target} deployments for ${input.projectId}`;
55
- } else {
56
- label = `Vercel deployments for ${input.projectId}`;
57
- }
58
- return {
59
- label,
60
- namespace: "vercel",
61
- identifier: parts.join(":")
62
- };
63
- }
64
- function vercelDeploymentSubscribable(input) {
65
- if (!input.canSubscribe) return void 0;
66
- if (input.commitSha && !input.target) return void 0;
67
- return {
68
- ...vercelDeploymentResource(input),
69
- match: {
70
- project_id: input.projectId,
71
- ...input.target ? { target: input.target } : void 0,
72
- ...input.commitSha ? { commit_sha: input.commitSha.toLowerCase() } : void 0
73
- },
74
- suggested_events: VERCEL_DEPLOYMENT_SUGGESTED_EVENTS,
75
- supported_events: [...VERCEL_DEPLOYMENT_EVENTS],
76
- type: "deployment"
77
- };
78
- }
79
-
80
- // src/tools/deployment.ts
81
- import {
82
- definePluginTool,
83
- PluginToolInputError,
84
- pluginToolOutputSchema,
85
- subscribableResourceSchema
86
- } from "@sentry/junior-plugin-api";
87
- import * as z2 from "zod";
88
-
89
- // src/project.ts
90
- import * as z from "zod";
91
- var vercelProjectIdSchema = z.string().trim().min(1);
92
-
93
- // src/tools/deployment.ts
94
- var commitShaSchema = z2.string().regex(/^[0-9a-f]{40}$/i);
95
- var targetSchema = z2.enum(["preview", "production", "staging"]);
96
- var nonEmptyStringSchema = z2.string().trim().min(1);
97
- var inputSchema = z2.object({
98
- commit_sha: commitShaSchema.describe(
99
- "Optional full 40-character Git commit SHA. Provide it to watch one deployment; omit it to watch every matching deployment for the project."
100
- ).optional(),
101
- project: nonEmptyStringSchema.describe("Vercel project name or prj_ ID."),
102
- target: targetSchema.describe(
103
- 'Optional deployment target such as "production". Omit to watch every target for the project. Defaults to "production" when commit_sha is set.'
104
- ).optional(),
105
- team: nonEmptyStringSchema.describe("Optional Vercel team slug or team_ ID that owns the project.").optional()
106
- }).strict();
107
- var deploymentSchema = z2.object({
108
- commit_sha: commitShaSchema.nullable(),
109
- deployment_target: targetSchema.nullable(),
110
- project_id: vercelProjectIdSchema,
111
- subscribable: subscribableResourceSchema.optional()
112
- });
113
- var outputSchema = pluginToolOutputSchema.merge(
114
- deploymentSchema.extend({
115
- target: z2.literal("deployment")
116
- })
117
- );
118
- async function readJson(response) {
119
- const text = await response.text();
120
- if (!text) return void 0;
121
- try {
122
- return JSON.parse(text);
123
- } catch {
124
- return text;
125
- }
126
- }
127
- function projectLookupUrl(project, team) {
128
- const url = new URL(
129
- `https://api.vercel.com/v9/projects/${encodeURIComponent(project)}`
130
- );
131
- if (team) {
132
- url.searchParams.set(team.startsWith("team_") ? "teamId" : "slug", team);
133
- }
134
- return url.toString();
135
- }
136
- var vercelDeploymentTool = definePluginTool({
137
- annotations: {
138
- destructiveHint: false,
139
- idempotentHint: true,
140
- openWorldHint: true,
141
- readOnlyHint: true
142
- },
143
- description: "Resolve a Vercel project name or ID and describe a subscribable deployment resource for one deployment or every deployment of the project. Use the user's explicit project and team, otherwise the vercel.project and vercel.team conversation defaults.",
144
- inputSchema,
145
- outputSchema,
146
- async execute(input, _options, ctx) {
147
- const response = await ctx.egress.fetch({
148
- operation: "vercel.project.get",
149
- provider: "vercel",
150
- request: new Request(projectLookupUrl(input.project, input.team))
151
- });
152
- const parsed = await readJson(response);
153
- if (!response.ok) {
154
- const message = `Vercel project lookup failed with HTTP ${response.status}`;
155
- if (response.status === 404) {
156
- throw new PluginToolInputError(message);
157
- }
158
- throw new Error(message);
159
- }
160
- const projectId = z2.object({ id: vercelProjectIdSchema }).parse(parsed).id;
161
- const commitSha = input.commit_sha?.toLowerCase();
162
- const deploymentTarget = input.target ?? (commitSha ? "production" : void 0);
163
- const subscribable = vercelDeploymentSubscribable({
164
- canSubscribe: ctx.events.canSubscribe,
165
- commitSha,
166
- projectId,
167
- target: deploymentTarget
168
- });
169
- const data = {
170
- commit_sha: commitSha ?? null,
171
- deployment_target: deploymentTarget ?? null,
172
- project_id: projectId,
173
- ...subscribable ? { subscribable } : void 0
174
- };
175
- return {
176
- target: "deployment",
177
- ...data
178
- };
179
- }
180
- });
181
-
182
- // src/webhooks/events.ts
183
- import * as z3 from "zod";
184
- var deploymentIdSchema = z3.string().regex(/^dpl_[A-Za-z0-9]+$/);
185
- var commitShaSchema2 = z3.string().regex(/^[0-9a-f]{40}$/i).transform((sha) => sha.toLowerCase());
186
- var deploymentTargetSchema = z3.string().nullable().transform((target) => target ?? "preview").pipe(z3.enum(VERCEL_DEPLOYMENT_TARGETS));
187
- var metaCommitShaSchema = commitShaSchema2.optional().catch(void 0);
188
- var deploymentMetaSchema = z3.object({
189
- githubCommitSha: metaCommitShaSchema,
190
- gitlabCommitSha: metaCommitShaSchema,
191
- bitbucketCommitSha: metaCommitShaSchema,
192
- gitCommitSha: metaCommitShaSchema
193
- }).transform((meta) => ({
194
- commitSha: meta.githubCommitSha ?? meta.gitlabCommitSha ?? meta.bitbucketCommitSha ?? meta.gitCommitSha
195
- }));
196
- var webhookEnvelopeSchema = z3.object({
197
- createdAt: z3.number().finite(),
198
- id: z3.string().min(1),
199
- payload: z3.unknown(),
200
- type: z3.enum(VERCEL_DEPLOYMENT_EVENTS)
201
- });
202
- var deploymentPayloadSchema = z3.object({
203
- deployment: z3.object({
204
- id: deploymentIdSchema,
205
- meta: deploymentMetaSchema
206
- }),
207
- project: z3.object({
208
- id: vercelProjectIdSchema
209
- }),
210
- target: deploymentTargetSchema
211
- }).transform((payload) => ({
212
- commitSha: payload.deployment.meta.commitSha,
213
- deploymentId: payload.deployment.id,
214
- projectId: payload.project.id,
215
- target: payload.target
216
- }));
217
- var deploymentEventDataSchema = z3.object({
218
- projectId: vercelProjectIdSchema,
219
- deploymentId: deploymentIdSchema,
220
- target: z3.enum(VERCEL_DEPLOYMENT_TARGETS),
221
- commitSha: commitShaSchema2.optional()
222
- }).strict();
223
- var DEPLOYMENT_OUTCOMES = {
224
- "deployment.succeeded": "succeeded",
225
- "deployment.error": "failed",
226
- "deployment.canceled": "was canceled"
227
- };
228
- function deploymentTargets(input) {
229
- const targets = [
230
- {
231
- completeOnTerminalEvent: false,
232
- resource: vercelDeploymentResource({
233
- projectId: input.projectId
234
- })
235
- },
236
- {
237
- completeOnTerminalEvent: false,
238
- resource: vercelDeploymentResource({
239
- projectId: input.projectId,
240
- target: input.target
241
- })
242
- }
243
- ];
244
- if (input.commitSha) {
245
- targets.push({
246
- completeOnTerminalEvent: true,
247
- resource: vercelDeploymentResource({
248
- commitSha: input.commitSha,
249
- projectId: input.projectId,
250
- target: input.target
251
- })
252
- });
253
- }
254
- return targets;
255
- }
256
- function normalizeVercelEvents(args) {
257
- const envelope = webhookEnvelopeSchema.safeParse(args.body);
258
- if (!envelope.success) return [];
259
- const payload = deploymentPayloadSchema.safeParse(envelope.data.payload);
260
- if (!payload.success) return [];
261
- const eventType = envelope.data.type;
262
- const { commitSha, deploymentId, projectId, target } = payload.data;
263
- const data = deploymentEventDataSchema.parse({
264
- projectId,
265
- deploymentId,
266
- target,
267
- ...commitSha ? { commitSha } : void 0
268
- });
269
- return deploymentTargets({ commitSha, projectId, target }).map(
270
- ({ completeOnTerminalEvent, resource }) => ({
271
- data,
272
- eventKey: `vercel:${envelope.data.id}:${eventType}`,
273
- eventType,
274
- identifier: resource.identifier,
275
- objectType: "deployment",
276
- occurredAtMs: envelope.data.createdAt,
277
- ...completeOnTerminalEvent ? { terminal: true } : void 0,
278
- trustedSummary: `${resource.label} (${deploymentId}) ${DEPLOYMENT_OUTCOMES[eventType]}.`
279
- })
280
- );
281
- }
282
-
283
- // src/webhooks/handler.ts
284
- import { createHmac, timingSafeEqual } from "crypto";
285
- function verifyVercelSignature(body, signature, secret) {
286
- if (!secret || !/^[0-9a-f]{40}$/i.test(signature)) return false;
287
- const actual = Buffer.from(signature.toLowerCase());
288
- const expected = Buffer.from(
289
- createHmac("sha1", secret).update(body).digest("hex")
290
- );
291
- return actual.length === expected.length && timingSafeEqual(actual, expected);
292
- }
293
- function parseJson(body) {
294
- try {
295
- return JSON.parse(body);
296
- } catch {
297
- return void 0;
298
- }
299
- }
300
- function createVercelWebhookRoute(args) {
301
- return {
302
- method: "POST",
303
- path: "/api/webhooks/vercel",
304
- async handler(request) {
305
- const rawBody = await request.text();
306
- const signature = request.headers.get("x-vercel-signature") ?? "";
307
- if (!verifyVercelSignature(rawBody, signature, args.webhookSecret())) {
308
- return new Response("Unauthorized", { status: 401 });
309
- }
310
- const body = parseJson(rawBody);
311
- if (body === void 0) {
312
- return new Response("Malformed Vercel webhook", { status: 400 });
313
- }
314
- const events = normalizeVercelEvents({ body });
315
- for (const event of events) {
316
- await args.events.publish(event);
317
- }
318
- return new Response(events.length ? "Accepted" : "Ignored", {
319
- status: 202
320
- });
321
- }
322
- };
323
- }
324
-
325
- export {
326
- VERCEL_DEPLOYMENT_EVENTS,
327
- VERCEL_DEPLOYMENT_SUGGESTED_EVENTS,
328
- VERCEL_DEPLOYMENT_MATCH_FIELDS,
329
- vercelDeploymentTool,
330
- normalizeVercelEvents,
331
- createVercelWebhookRoute
332
- };
@@ -1,37 +0,0 @@
1
- import { type SubscribableResource } from "@sentry/junior-plugin-api";
2
- export declare const VERCEL_DEPLOYMENT_EVENTS: readonly ["deployment.succeeded", "deployment.error", "deployment.canceled"];
3
- export declare const VERCEL_DEPLOYMENT_SUGGESTED_EVENTS: string[];
4
- /** The deployment targets that Vercel webhooks report. */
5
- export declare const VERCEL_DEPLOYMENT_TARGETS: readonly ["preview", "production", "staging"];
6
- export type VercelDeploymentTarget = (typeof VERCEL_DEPLOYMENT_TARGETS)[number];
7
- /**
8
- * Trusted values that every Vercel deployment event sets. `commitSha` is left
9
- * out when the deployment has no Git commit, so a filter on it does not match.
10
- * Vercel ids keep the case that Vercel sends, the same as identifiers,
11
- * because they are case-sensitive.
12
- */
13
- export declare const VERCEL_DEPLOYMENT_MATCH_FIELDS: Record<string, {
14
- kind: "boolean" | "number" | "string";
15
- description: string;
16
- enum?: string[] | undefined;
17
- list?: true | undefined;
18
- case?: "lower" | "upper" | undefined;
19
- events?: string[] | undefined;
20
- }>;
21
- /** Build the stable deployment identity shared by tools and webhooks. */
22
- export declare function vercelDeploymentResource(input: {
23
- commitSha?: string;
24
- projectId: string;
25
- target?: VercelDeploymentTarget;
26
- }): Pick<SubscribableResource, "label" | "namespace" | "identifier">;
27
- /**
28
- * Describe a deployment resource that a conversation can watch.
29
- * Return undefined when the host cannot create Watches.
30
- */
31
- export declare function vercelDeploymentSubscribable(input: {
32
- /** `ctx.events.canSubscribe` from the tool context. */
33
- canSubscribe: boolean;
34
- commitSha?: string;
35
- projectId: string;
36
- target?: VercelDeploymentTarget;
37
- }): SubscribableResource | undefined;
package/dist/project.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import * as z from "zod";
2
- /** Accept the opaque project identifier returned by Vercel. */
3
- export declare const vercelProjectIdSchema: z.ZodString;