@trigger.dev/sdk 3.3.14 → 3.3.16

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uncrypto-cjs.cjs","sourceRoot":"","sources":["../../../src/imports/uncrypto-cjs.cts"],"names":[],"mappings":";;AAAA,aAAa;AACb,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEvC,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // @ts-ignore
4
+ const { subtle } = require("uncrypto");
5
+ // @ts-ignore
6
+ module.exports.subtle = subtle;
7
+ //# sourceMappingURL=uncrypto-cjs.cjs.map
@@ -11,12 +11,12 @@ export * from "./idempotencyKeys.js";
11
11
  export * from "./tags.js";
12
12
  export * from "./metadata.js";
13
13
  export * from "./timeout.js";
14
- export * from "./waitUntil.js";
14
+ export * from "./webhooks.js";
15
15
  export type { Context };
16
16
  import type { Context } from "./shared.js";
17
17
  import type { ApiClientConfiguration } from "@trigger.dev/core/v3";
18
18
  export type { ApiClientConfiguration };
19
- export { ApiError, AuthenticationError, BadRequestError, ConflictError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, UnprocessableEntityError, AbortTaskRunError, logger, type LogLevel, } from "@trigger.dev/core/v3";
19
+ export { ApiError, AuthenticationError, BadRequestError, ConflictError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, UnprocessableEntityError, AbortTaskRunError, OutOfMemoryError, logger, type LogLevel, } from "@trigger.dev/core/v3";
20
20
  export { runs, type RunShape, type AnyRunShape, type TaskRunShape, type RealtimeRun, type AnyRealtimeRun, type RetrieveRunResult, type AnyRetrieveRunResult, } from "./runs.js";
21
21
  export * as schedules from "./schedules/index.js";
22
22
  export * as envvars from "./envvars.js";
@@ -26,7 +26,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
26
26
  return result;
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.auth = exports.configure = exports.envvars = exports.schedules = exports.runs = exports.logger = exports.AbortTaskRunError = exports.UnprocessableEntityError = exports.RateLimitError = exports.PermissionDeniedError = exports.NotFoundError = exports.InternalServerError = exports.ConflictError = exports.BadRequestError = exports.AuthenticationError = exports.ApiError = exports.queue = exports.retry = void 0;
29
+ exports.auth = exports.configure = exports.envvars = exports.schedules = exports.runs = exports.logger = exports.OutOfMemoryError = exports.AbortTaskRunError = exports.UnprocessableEntityError = exports.RateLimitError = exports.PermissionDeniedError = exports.NotFoundError = exports.InternalServerError = exports.ConflictError = exports.BadRequestError = exports.AuthenticationError = exports.ApiError = exports.queue = exports.retry = void 0;
30
30
  __exportStar(require("./cache.js"), exports);
31
31
  __exportStar(require("./config.js"), exports);
32
32
  var retry_js_1 = require("./retry.js");
@@ -42,7 +42,7 @@ __exportStar(require("./idempotencyKeys.js"), exports);
42
42
  __exportStar(require("./tags.js"), exports);
43
43
  __exportStar(require("./metadata.js"), exports);
44
44
  __exportStar(require("./timeout.js"), exports);
45
- __exportStar(require("./waitUntil.js"), exports);
45
+ __exportStar(require("./webhooks.js"), exports);
46
46
  var v3_1 = require("@trigger.dev/core/v3");
47
47
  Object.defineProperty(exports, "ApiError", { enumerable: true, get: function () { return v3_1.ApiError; } });
48
48
  Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return v3_1.AuthenticationError; } });
@@ -54,6 +54,7 @@ Object.defineProperty(exports, "PermissionDeniedError", { enumerable: true, get:
54
54
  Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return v3_1.RateLimitError; } });
55
55
  Object.defineProperty(exports, "UnprocessableEntityError", { enumerable: true, get: function () { return v3_1.UnprocessableEntityError; } });
56
56
  Object.defineProperty(exports, "AbortTaskRunError", { enumerable: true, get: function () { return v3_1.AbortTaskRunError; } });
57
+ Object.defineProperty(exports, "OutOfMemoryError", { enumerable: true, get: function () { return v3_1.OutOfMemoryError; } });
57
58
  Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return v3_1.logger; } });
58
59
  var runs_js_1 = require("./runs.js");
59
60
  Object.defineProperty(exports, "runs", { enumerable: true, get: function () { return runs_js_1.runs; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v3/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,8CAA4B;AAC5B,uCAAsD;AAA7C,iGAAA,KAAK,OAAA;AACd,yCAAoC;AAA3B,kGAAA,KAAK,OAAA;AACd,6CAA2B;AAC3B,6CAA2B;AAC3B,4CAA0B;AAC1B,iDAA+B;AAC/B,6CAA2B;AAC3B,uDAAqC;AACrC,4CAA0B;AAC1B,gDAA8B;AAC9B,+CAA6B;AAC7B,iDAA+B;AAS/B,2CAa8B;AAZ5B,8FAAA,QAAQ,OAAA;AACR,yGAAA,mBAAmB,OAAA;AACnB,qGAAA,eAAe,OAAA;AACf,mGAAA,aAAa,OAAA;AACb,yGAAA,mBAAmB,OAAA;AACnB,mGAAA,aAAa,OAAA;AACb,2GAAA,qBAAqB,OAAA;AACrB,oGAAA,cAAc,OAAA;AACd,8GAAA,wBAAwB,OAAA;AACxB,uGAAA,iBAAiB,OAAA;AACjB,4FAAA,MAAM,OAAA;AAIR,qCASmB;AARjB,+FAAA,IAAI,OAAA;AASN,kEAAkD;AAClD,wDAAwC;AAGxC,qCAA4C;AAAnC,oGAAA,SAAS,OAAA;AAAE,+FAAA,IAAI,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v3/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,8CAA4B;AAC5B,uCAAsD;AAA7C,iGAAA,KAAK,OAAA;AACd,yCAAoC;AAA3B,kGAAA,KAAK,OAAA;AACd,6CAA2B;AAC3B,6CAA2B;AAC3B,4CAA0B;AAC1B,iDAA+B;AAC/B,6CAA2B;AAC3B,uDAAqC;AACrC,4CAA0B;AAC1B,gDAA8B;AAC9B,+CAA6B;AAC7B,gDAA8B;AAS9B,2CAc8B;AAb5B,8FAAA,QAAQ,OAAA;AACR,yGAAA,mBAAmB,OAAA;AACnB,qGAAA,eAAe,OAAA;AACf,mGAAA,aAAa,OAAA;AACb,yGAAA,mBAAmB,OAAA;AACnB,mGAAA,aAAa,OAAA;AACb,2GAAA,qBAAqB,OAAA;AACrB,oGAAA,cAAc,OAAA;AACd,8GAAA,wBAAwB,OAAA;AACxB,uGAAA,iBAAiB,OAAA;AACjB,sGAAA,gBAAgB,OAAA;AAChB,4FAAA,MAAM,OAAA;AAIR,qCASmB;AARjB,+FAAA,IAAI,OAAA;AASN,kEAAkD;AAClD,wDAAwC;AAGxC,qCAA4C;AAAnC,oGAAA,SAAS,OAAA;AAAE,+FAAA,IAAI,OAAA"}
@@ -0,0 +1,47 @@
1
+ import { Webhook } from "@trigger.dev/core/v3";
2
+ /**
3
+ * The type of error thrown when a webhook fails to parse or verify
4
+ */
5
+ export declare class WebhookError extends Error {
6
+ constructor(message: string);
7
+ }
8
+ /**
9
+ * Options for constructing a webhook event
10
+ */
11
+ type ConstructEventOptions = {
12
+ /** Raw payload as string or Buffer */
13
+ payload: string | Buffer;
14
+ /** Signature header as string, Buffer, or string array */
15
+ header: string | Buffer | Array<string>;
16
+ };
17
+ /**
18
+ * Interface describing the webhook utilities
19
+ */
20
+ interface Webhooks {
21
+ /**
22
+ * Constructs and validates a webhook event from an incoming request
23
+ * @param request - Either a Request object or ConstructEventOptions containing the payload and signature
24
+ * @param secret - Secret key used to verify the webhook signature
25
+ * @returns Promise resolving to a validated AlertWebhook object
26
+ * @throws {WebhookError} If validation fails or payload can't be parsed
27
+ *
28
+ * @example
29
+ * // Using with Request object
30
+ * const event = await webhooks.constructEvent(request, "webhook_secret");
31
+ *
32
+ * @example
33
+ * // Using with manual options
34
+ * const event = await webhooks.constructEvent({
35
+ * payload: rawBody,
36
+ * header: signatureHeader
37
+ * }, "webhook_secret");
38
+ */
39
+ constructEvent(request: ConstructEventOptions | Request, secret: string): Promise<Webhook>;
40
+ /** Header name used for webhook signatures */
41
+ SIGNATURE_HEADER_NAME: string;
42
+ }
43
+ /**
44
+ * Webhook utilities for handling incoming webhook requests
45
+ */
46
+ export declare const webhooks: Webhooks;
47
+ export {};
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.webhooks = exports.WebhookError = void 0;
4
+ const v3_1 = require("@trigger.dev/core/v3");
5
+ const uncrypto_js_1 = require("../imports/uncrypto.js");
6
+ /**
7
+ * The type of error thrown when a webhook fails to parse or verify
8
+ */
9
+ class WebhookError extends Error {
10
+ constructor(message) {
11
+ super(message);
12
+ this.name = "WebhookError";
13
+ }
14
+ }
15
+ exports.WebhookError = WebhookError;
16
+ /** Header name used for webhook signatures */
17
+ const SIGNATURE_HEADER_NAME = "x-trigger-signature-hmacsha256";
18
+ /**
19
+ * Webhook utilities for handling incoming webhook requests
20
+ */
21
+ exports.webhooks = {
22
+ constructEvent,
23
+ SIGNATURE_HEADER_NAME,
24
+ };
25
+ async function constructEvent(request, secret) {
26
+ let payload;
27
+ let signature;
28
+ if (request instanceof Request) {
29
+ if (!secret) {
30
+ throw new WebhookError("Secret is required when passing a Request object");
31
+ }
32
+ const signatureHeader = request.headers.get(SIGNATURE_HEADER_NAME);
33
+ if (!signatureHeader) {
34
+ throw new WebhookError("No signature header found");
35
+ }
36
+ signature = signatureHeader;
37
+ payload = await request.text();
38
+ }
39
+ else {
40
+ payload = request.payload.toString();
41
+ if (Array.isArray(request.header)) {
42
+ throw new WebhookError("Signature header cannot be an array");
43
+ }
44
+ signature = request.header.toString();
45
+ }
46
+ // Verify the signature
47
+ const isValid = await verifySignature(payload, signature, secret);
48
+ if (!isValid) {
49
+ throw new WebhookError("Invalid signature");
50
+ }
51
+ // Parse and validate the payload
52
+ try {
53
+ const jsonPayload = JSON.parse(payload);
54
+ const parsedPayload = v3_1.Webhook.parse(jsonPayload);
55
+ return parsedPayload;
56
+ }
57
+ catch (error) {
58
+ if (error instanceof Error) {
59
+ throw new WebhookError(`Webhook parsing failed: ${error.message}`);
60
+ }
61
+ throw new WebhookError("Webhook parsing failed");
62
+ }
63
+ }
64
+ /**
65
+ * Verifies the signature of a webhook payload
66
+ * @param payload - Raw payload string to verify
67
+ * @param signature - Expected signature to check against
68
+ * @param secret - Secret key used to generate the signature
69
+ * @returns Promise resolving to boolean indicating if signature is valid
70
+ * @throws {WebhookError} If signature verification process fails
71
+ *
72
+ * @example
73
+ * const isValid = await verifySignature(
74
+ * '{"event": "test"}',
75
+ * "abc123signature",
76
+ * "webhook_secret"
77
+ * );
78
+ */
79
+ async function verifySignature(payload, signature, secret) {
80
+ try {
81
+ if (!secret) {
82
+ throw new WebhookError("Secret is required for signature verification");
83
+ }
84
+ // Convert the payload and secret to buffers
85
+ const hashPayload = Buffer.from(payload, "utf-8");
86
+ const hmacSecret = Buffer.from(secret, "utf-8");
87
+ // Import the secret key
88
+ const key = await uncrypto_js_1.subtle.importKey("raw", hmacSecret, { name: "HMAC", hash: "SHA-256" }, false, ["sign", "verify"]);
89
+ // Calculate the expected signature
90
+ const actualSignature = await uncrypto_js_1.subtle.sign("HMAC", key, hashPayload);
91
+ const actualSignatureHex = Buffer.from(actualSignature).toString("hex");
92
+ // Compare signatures using timing-safe comparison
93
+ return timingSafeEqual(signature, actualSignatureHex);
94
+ }
95
+ catch (error) {
96
+ throw new WebhookError("Signature verification failed");
97
+ }
98
+ }
99
+ // Timing-safe comparison to prevent timing attacks
100
+ function timingSafeEqual(a, b) {
101
+ if (a.length !== b.length) {
102
+ return false;
103
+ }
104
+ let result = 0;
105
+ for (let i = 0; i < a.length; i++) {
106
+ result |= a.charCodeAt(i) ^ b.charCodeAt(i);
107
+ }
108
+ return result === 0;
109
+ }
110
+ //# sourceMappingURL=webhooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../../../src/v3/webhooks.ts"],"names":[],"mappings":";;;AAAA,6CAA+C;AAC/C,wDAAgD;AAEhD;;GAEG;AACH,MAAa,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AALD,oCAKC;AAED,8CAA8C;AAC9C,MAAM,qBAAqB,GAAG,gCAAgC,CAAC;AAwC/D;;GAEG;AACU,QAAA,QAAQ,GAAa;IAChC,cAAc;IACd,qBAAqB;CACtB,CAAC;AAEF,KAAK,UAAU,cAAc,CAC3B,OAAwC,EACxC,MAAc;IAEd,IAAI,OAAe,CAAC;IACpB,IAAI,SAAiB,CAAC;IAEtB,IAAI,OAAO,YAAY,OAAO,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,YAAY,CAAC,kDAAkD,CAAC,CAAC;QAC7E,CAAC;QAED,MAAM,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;QACnE,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,MAAM,IAAI,YAAY,CAAC,2BAA2B,CAAC,CAAC;QACtD,CAAC;QACD,SAAS,GAAG,eAAe,CAAC;QAE5B,OAAO,GAAG,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC;IACjC,CAAC;SAAM,CAAC;QACN,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;QAErC,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAClC,MAAM,IAAI,YAAY,CAAC,qCAAqC,CAAC,CAAC;QAChE,CAAC;QACD,SA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C,MAAM,EAAE,QAAQ,CAAC,CACnB,CAAC;QAEF,mCAAmC;QACnC,MAAM,eAAe,GAAG,MAAM,oBAAM,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;QACpE,MAAM,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAExE,kDAAkD;QAClD,OAAO,eAAe,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAC;IACxD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,YAAY,CAAC,+BAA+B,CAAC,CAAC;IAC1D,CAAC;AACH,CAAC;AAED,mDAAmD;AACnD,SAAS,eAAe,CAAC,CAAS,EAAE,CAAS;IAC3C,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,MAAM,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,MAAM,KAAK,CAAC,CAAC;AACtB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = "3.3.14";
4
+ exports.VERSION = "3.3.16";
5
5
  //# sourceMappingURL=version.js.map
@@ -0,0 +1,2 @@
1
+ import { subtle } from "uncrypto";
2
+ export { subtle };
@@ -0,0 +1,5 @@
1
+ // @ts-ignore
2
+ import { subtle } from "uncrypto";
3
+ // @ts-ignore
4
+ export { subtle };
5
+ //# sourceMappingURL=uncrypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uncrypto.js","sourceRoot":"","sources":["../../../src/imports/uncrypto.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,aAAa;AACb,OAAO,EAAE,MAAM,EAAE,CAAC"}
@@ -11,12 +11,12 @@ export * from "./idempotencyKeys.js";
11
11
  export * from "./tags.js";
12
12
  export * from "./metadata.js";
13
13
  export * from "./timeout.js";
14
- export * from "./waitUntil.js";
14
+ export * from "./webhooks.js";
15
15
  export type { Context };
16
16
  import type { Context } from "./shared.js";
17
17
  import type { ApiClientConfiguration } from "@trigger.dev/core/v3";
18
18
  export type { ApiClientConfiguration };
19
- export { ApiError, AuthenticationError, BadRequestError, ConflictError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, UnprocessableEntityError, AbortTaskRunError, logger, type LogLevel, } from "@trigger.dev/core/v3";
19
+ export { ApiError, AuthenticationError, BadRequestError, ConflictError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, UnprocessableEntityError, AbortTaskRunError, OutOfMemoryError, logger, type LogLevel, } from "@trigger.dev/core/v3";
20
20
  export { runs, type RunShape, type AnyRunShape, type TaskRunShape, type RealtimeRun, type AnyRealtimeRun, type RetrieveRunResult, type AnyRetrieveRunResult, } from "./runs.js";
21
21
  export * as schedules from "./schedules/index.js";
22
22
  export * as envvars from "./envvars.js";
@@ -11,8 +11,8 @@ export * from "./idempotencyKeys.js";
11
11
  export * from "./tags.js";
12
12
  export * from "./metadata.js";
13
13
  export * from "./timeout.js";
14
- export * from "./waitUntil.js";
15
- export { ApiError, AuthenticationError, BadRequestError, ConflictError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, UnprocessableEntityError, AbortTaskRunError, logger, } from "@trigger.dev/core/v3";
14
+ export * from "./webhooks.js";
15
+ export { ApiError, AuthenticationError, BadRequestError, ConflictError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, UnprocessableEntityError, AbortTaskRunError, OutOfMemoryError, logger, } from "@trigger.dev/core/v3";
16
16
  export { runs, } from "./runs.js";
17
17
  export * as schedules from "./schedules/index.js";
18
18
  export * as envvars from "./envvars.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v3/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAqB,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAS/B,OAAO,EACL,QAAQ,EACR,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,qBAAqB,EACrB,cAAc,EACd,wBAAwB,EACxB,iBAAiB,EACjB,MAAM,GAEP,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,IAAI,GAQL,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAGxC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v3/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAqB,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAS9B,OAAO,EACL,QAAQ,EACR,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,qBAAqB,EACrB,cAAc,EACd,wBAAwB,EACxB,iBAAiB,EACjB,gBAAgB,EAChB,MAAM,GAEP,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,IAAI,GAQL,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAGxC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { Webhook } from "@trigger.dev/core/v3";
2
+ /**
3
+ * The type of error thrown when a webhook fails to parse or verify
4
+ */
5
+ export declare class WebhookError extends Error {
6
+ constructor(message: string);
7
+ }
8
+ /**
9
+ * Options for constructing a webhook event
10
+ */
11
+ type ConstructEventOptions = {
12
+ /** Raw payload as string or Buffer */
13
+ payload: string | Buffer;
14
+ /** Signature header as string, Buffer, or string array */
15
+ header: string | Buffer | Array<string>;
16
+ };
17
+ /**
18
+ * Interface describing the webhook utilities
19
+ */
20
+ interface Webhooks {
21
+ /**
22
+ * Constructs and validates a webhook event from an incoming request
23
+ * @param request - Either a Request object or ConstructEventOptions containing the payload and signature
24
+ * @param secret - Secret key used to verify the webhook signature
25
+ * @returns Promise resolving to a validated AlertWebhook object
26
+ * @throws {WebhookError} If validation fails or payload can't be parsed
27
+ *
28
+ * @example
29
+ * // Using with Request object
30
+ * const event = await webhooks.constructEvent(request, "webhook_secret");
31
+ *
32
+ * @example
33
+ * // Using with manual options
34
+ * const event = await webhooks.constructEvent({
35
+ * payload: rawBody,
36
+ * header: signatureHeader
37
+ * }, "webhook_secret");
38
+ */
39
+ constructEvent(request: ConstructEventOptions | Request, secret: string): Promise<Webhook>;
40
+ /** Header name used for webhook signatures */
41
+ SIGNATURE_HEADER_NAME: string;
42
+ }
43
+ /**
44
+ * Webhook utilities for handling incoming webhook requests
45
+ */
46
+ export declare const webhooks: Webhooks;
47
+ export {};
@@ -0,0 +1,106 @@
1
+ import { Webhook } from "@trigger.dev/core/v3";
2
+ import { subtle } from "../imports/uncrypto.js";
3
+ /**
4
+ * The type of error thrown when a webhook fails to parse or verify
5
+ */
6
+ export class WebhookError extends Error {
7
+ constructor(message) {
8
+ super(message);
9
+ this.name = "WebhookError";
10
+ }
11
+ }
12
+ /** Header name used for webhook signatures */
13
+ const SIGNATURE_HEADER_NAME = "x-trigger-signature-hmacsha256";
14
+ /**
15
+ * Webhook utilities for handling incoming webhook requests
16
+ */
17
+ export const webhooks = {
18
+ constructEvent,
19
+ SIGNATURE_HEADER_NAME,
20
+ };
21
+ async function constructEvent(request, secret) {
22
+ let payload;
23
+ let signature;
24
+ if (request instanceof Request) {
25
+ if (!secret) {
26
+ throw new WebhookError("Secret is required when passing a Request object");
27
+ }
28
+ const signatureHeader = request.headers.get(SIGNATURE_HEADER_NAME);
29
+ if (!signatureHeader) {
30
+ throw new WebhookError("No signature header found");
31
+ }
32
+ signature = signatureHeader;
33
+ payload = await request.text();
34
+ }
35
+ else {
36
+ payload = request.payload.toString();
37
+ if (Array.isArray(request.header)) {
38
+ throw new WebhookError("Signature header cannot be an array");
39
+ }
40
+ signature = request.header.toString();
41
+ }
42
+ // Verify the signature
43
+ const isValid = await verifySignature(payload, signature, secret);
44
+ if (!isValid) {
45
+ throw new WebhookError("Invalid signature");
46
+ }
47
+ // Parse and validate the payload
48
+ try {
49
+ const jsonPayload = JSON.parse(payload);
50
+ const parsedPayload = Webhook.parse(jsonPayload);
51
+ return parsedPayload;
52
+ }
53
+ catch (error) {
54
+ if (error instanceof Error) {
55
+ throw new WebhookError(`Webhook parsing failed: ${error.message}`);
56
+ }
57
+ throw new WebhookError("Webhook parsing failed");
58
+ }
59
+ }
60
+ /**
61
+ * Verifies the signature of a webhook payload
62
+ * @param payload - Raw payload string to verify
63
+ * @param signature - Expected signature to check against
64
+ * @param secret - Secret key used to generate the signature
65
+ * @returns Promise resolving to boolean indicating if signature is valid
66
+ * @throws {WebhookError} If signature verification process fails
67
+ *
68
+ * @example
69
+ * const isValid = await verifySignature(
70
+ * '{"event": "test"}',
71
+ * "abc123signature",
72
+ * "webhook_secret"
73
+ * );
74
+ */
75
+ async function verifySignature(payload, signature, secret) {
76
+ try {
77
+ if (!secret) {
78
+ throw new WebhookError("Secret is required for signature verification");
79
+ }
80
+ // Convert the payload and secret to buffers
81
+ const hashPayload = Buffer.from(payload, "utf-8");
82
+ const hmacSecret = Buffer.from(secret, "utf-8");
83
+ // Import the secret key
84
+ const key = await subtle.importKey("raw", hmacSecret, { name: "HMAC", hash: "SHA-256" }, false, ["sign", "verify"]);
85
+ // Calculate the expected signature
86
+ const actualSignature = await subtle.sign("HMAC", key, hashPayload);
87
+ const actualSignatureHex = Buffer.from(actualSignature).toString("hex");
88
+ // Compare signatures using timing-safe comparison
89
+ return timingSafeEqual(signature, actualSignatureHex);
90
+ }
91
+ catch (error) {
92
+ throw new WebhookError("Signature verification failed");
93
+ }
94
+ }
95
+ // Timing-safe comparison to prevent timing attacks
96
+ function timingSafeEqual(a, b) {
97
+ if (a.length !== b.length) {
98
+ return false;
99
+ }
100
+ let result = 0;
101
+ for (let i = 0; i < a.length; i++) {
102
+ result |= a.charCodeAt(i) ^ b.charCodeAt(i);
103
+ }
104
+ return result === 0;
105
+ }
106
+ //# sourceMappingURL=webhooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../../../src/v3/webhooks.ts"],"names":[],"mappings":"AAAA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,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;QACpE,MAAM,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAExE,kDAAkD;QAClD,OAAO,eAAe,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAC;IACxD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,YAAY,CAAC,+BAA+B,CAAC,CAAC;IAC1D,CAAC;AACH,CAAC;AAED,mDAAmD;AACnD,SAAS,eAAe,CAAC,CAAS,EAAE,CAAS;IAC3C,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,MAAM,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,MAAM,KAAK,CAAC,CAAC;AACtB,CAAC"}
@@ -1,2 +1,2 @@
1
- export const VERSION = "3.3.14";
1
+ export const VERSION = "3.3.16";
2
2
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trigger.dev/sdk",
3
- "version": "3.3.14",
3
+ "version": "3.3.16",
4
4
  "description": "trigger.dev Node.JS SDK",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -40,7 +40,7 @@
40
40
  "@opentelemetry/api": "1.9.0",
41
41
  "@opentelemetry/api-logs": "0.52.1",
42
42
  "@opentelemetry/semantic-conventions": "1.25.1",
43
- "@trigger.dev/core": "3.3.14",
43
+ "@trigger.dev/core": "3.3.16",
44
44
  "chalk": "^5.2.0",
45
45
  "cronstrue": "^2.21.0",
46
46
  "debug": "^4.3.4",
@@ -48,6 +48,7 @@
48
48
  "slug": "^6.0.0",
49
49
  "terminal-link": "^3.0.0",
50
50
  "ulid": "^2.3.0",
51
+ "uncrypto": "^0.1.3",
51
52
  "uuid": "^9.0.0",
52
53
  "ws": "^8.11.0"
53
54
  },