@trigger.dev/sdk 0.0.0-prerelease-20250212002625 → 0.0.0-prerelease-20250213143202
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/commonjs/imports/uncrypto-cjs.cjs.map +1 -0
- package/dist/commonjs/imports/uncrypto.d.ts +1 -0
- package/dist/commonjs/imports/uncrypto.js +7 -0
- package/dist/commonjs/v3/index.d.ts +1 -1
- package/dist/commonjs/v3/index.js +1 -1
- package/dist/commonjs/v3/index.js.map +1 -1
- package/dist/commonjs/v3/runs.d.ts +26 -26
- package/dist/commonjs/v3/webhooks.d.ts +47 -0
- package/dist/commonjs/v3/webhooks.js +110 -0
- package/dist/commonjs/v3/webhooks.js.map +1 -0
- package/dist/esm/imports/uncrypto.d.ts +2 -0
- package/dist/esm/imports/uncrypto.js +5 -0
- package/dist/esm/imports/uncrypto.js.map +1 -0
- package/dist/esm/v3/index.d.ts +1 -1
- package/dist/esm/v3/index.js +1 -1
- package/dist/esm/v3/index.js.map +1 -1
- package/dist/esm/v3/runs.d.ts +38 -38
- package/dist/esm/v3/webhooks.d.ts +47 -0
- package/dist/esm/v3/webhooks.js +106 -0
- package/dist/esm/v3/webhooks.js.map +1 -0
- package/package.json +3 -2
|
@@ -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 {};
|
|
@@ -11,7 +11,7 @@ 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 "./
|
|
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";
|
|
@@ -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("./
|
|
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; } });
|
|
@@ -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,
|
|
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"}
|
|
@@ -28,20 +28,10 @@ export type PollOptions = {
|
|
|
28
28
|
declare function poll<TRunId extends AnyRunHandle | AnyTask | string>(runId: RunId<TRunId>, options?: {
|
|
29
29
|
pollIntervalMs?: number;
|
|
30
30
|
}, requestOptions?: ApiRequestOptions): Promise<{
|
|
31
|
+
tags: string[];
|
|
31
32
|
status: "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "COMPLETED" | "CANCELED" | "FAILED" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE" | "DELAYED" | "EXPIRED" | "TIMED_OUT";
|
|
32
|
-
|
|
33
|
-
error?: {
|
|
34
|
-
message: string;
|
|
35
|
-
stackTrace?: string | undefined;
|
|
36
|
-
name?: string | undefined;
|
|
37
|
-
} | undefined;
|
|
38
|
-
idempotencyKey?: string | undefined;
|
|
39
|
-
startedAt?: Date | undefined;
|
|
40
|
-
updatedAt: Date;
|
|
41
|
-
isTest: boolean;
|
|
33
|
+
taskIdentifier: string;
|
|
42
34
|
version?: string | undefined;
|
|
43
|
-
metadata?: Record<string, any> | undefined;
|
|
44
|
-
createdAt: Date;
|
|
45
35
|
schedule?: {
|
|
46
36
|
id: string;
|
|
47
37
|
generator: {
|
|
@@ -52,18 +42,19 @@ declare function poll<TRunId extends AnyRunHandle | AnyTask | string>(runId: Run
|
|
|
52
42
|
externalId?: string | undefined;
|
|
53
43
|
deduplicationKey?: string | undefined;
|
|
54
44
|
} | undefined;
|
|
55
|
-
|
|
56
|
-
|
|
45
|
+
isTest: boolean;
|
|
46
|
+
id: string;
|
|
47
|
+
createdAt: Date;
|
|
57
48
|
durationMs: number;
|
|
58
49
|
costInCents: number;
|
|
59
50
|
baseCostInCents: number;
|
|
60
51
|
relatedRuns: {
|
|
61
52
|
root?: {
|
|
62
|
-
id: string;
|
|
63
53
|
status: "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "COMPLETED" | "CANCELED" | "FAILED" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE" | "DELAYED" | "EXPIRED" | "TIMED_OUT";
|
|
64
|
-
|
|
65
|
-
isTest: boolean;
|
|
54
|
+
id: string;
|
|
66
55
|
createdAt: Date;
|
|
56
|
+
isTest: boolean;
|
|
57
|
+
tags: string[];
|
|
67
58
|
durationMs: number;
|
|
68
59
|
costInCents: number;
|
|
69
60
|
baseCostInCents: number;
|
|
@@ -88,11 +79,11 @@ declare function poll<TRunId extends AnyRunHandle | AnyTask | string>(runId: Run
|
|
|
88
79
|
expiredAt?: Date | undefined;
|
|
89
80
|
} | undefined;
|
|
90
81
|
parent?: {
|
|
91
|
-
id: string;
|
|
92
82
|
status: "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "COMPLETED" | "CANCELED" | "FAILED" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE" | "DELAYED" | "EXPIRED" | "TIMED_OUT";
|
|
93
|
-
|
|
94
|
-
isTest: boolean;
|
|
83
|
+
id: string;
|
|
95
84
|
createdAt: Date;
|
|
85
|
+
isTest: boolean;
|
|
86
|
+
tags: string[];
|
|
96
87
|
durationMs: number;
|
|
97
88
|
costInCents: number;
|
|
98
89
|
baseCostInCents: number;
|
|
@@ -117,11 +108,11 @@ declare function poll<TRunId extends AnyRunHandle | AnyTask | string>(runId: Run
|
|
|
117
108
|
expiredAt?: Date | undefined;
|
|
118
109
|
} | undefined;
|
|
119
110
|
children?: {
|
|
120
|
-
id: string;
|
|
121
111
|
status: "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "COMPLETED" | "CANCELED" | "FAILED" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE" | "DELAYED" | "EXPIRED" | "TIMED_OUT";
|
|
122
|
-
|
|
123
|
-
isTest: boolean;
|
|
112
|
+
id: string;
|
|
124
113
|
createdAt: Date;
|
|
114
|
+
isTest: boolean;
|
|
115
|
+
tags: string[];
|
|
125
116
|
durationMs: number;
|
|
126
117
|
costInCents: number;
|
|
127
118
|
baseCostInCents: number;
|
|
@@ -154,20 +145,29 @@ declare function poll<TRunId extends AnyRunHandle | AnyTask | string>(runId: Run
|
|
|
154
145
|
isSuccess: boolean;
|
|
155
146
|
isFailed: boolean;
|
|
156
147
|
isCancelled: boolean;
|
|
148
|
+
updatedAt: Date;
|
|
157
149
|
attempts: ({
|
|
158
|
-
id: string;
|
|
159
150
|
status: "EXECUTING" | "COMPLETED" | "CANCELED" | "FAILED" | "PENDING" | "PAUSED";
|
|
151
|
+
id: string;
|
|
160
152
|
createdAt: Date;
|
|
161
153
|
updatedAt: Date;
|
|
162
|
-
startedAt?: Date | undefined;
|
|
163
154
|
error?: {
|
|
164
155
|
message: string;
|
|
165
|
-
stackTrace?: string | undefined;
|
|
166
156
|
name?: string | undefined;
|
|
157
|
+
stackTrace?: string | undefined;
|
|
167
158
|
} | undefined;
|
|
159
|
+
startedAt?: Date | undefined;
|
|
168
160
|
completedAt?: Date | undefined;
|
|
169
161
|
} | undefined)[];
|
|
170
162
|
attemptCount: number;
|
|
163
|
+
error?: {
|
|
164
|
+
message: string;
|
|
165
|
+
name?: string | undefined;
|
|
166
|
+
stackTrace?: string | undefined;
|
|
167
|
+
} | undefined;
|
|
168
|
+
startedAt?: Date | undefined;
|
|
169
|
+
idempotencyKey?: string | undefined;
|
|
170
|
+
metadata?: Record<string, any> | undefined;
|
|
171
171
|
ttl?: string | undefined;
|
|
172
172
|
payloadPresignedUrl?: string | undefined;
|
|
173
173
|
outputPresignedUrl?: string | undefined;
|
|
@@ -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,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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"}
|
|
@@ -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"}
|
package/dist/esm/v3/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ 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 "./
|
|
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";
|
package/dist/esm/v3/index.js
CHANGED
|
@@ -11,7 +11,7 @@ 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 "./
|
|
14
|
+
export * from "./webhooks.js";
|
|
15
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";
|
package/dist/esm/v3/index.js.map
CHANGED
|
@@ -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,
|
|
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"}
|
package/dist/esm/v3/runs.d.ts
CHANGED
|
@@ -28,30 +28,25 @@ export type PollOptions = {
|
|
|
28
28
|
declare function poll<TRunId extends AnyRunHandle | AnyTask | string>(runId: RunId<TRunId>, options?: {
|
|
29
29
|
pollIntervalMs?: number;
|
|
30
30
|
}, requestOptions?: ApiRequestOptions): Promise<{
|
|
31
|
-
|
|
32
|
-
status: "COMPLETED" | "CANCELED" | "QUEUED" | "TIMED_OUT" | "EXECUTING" | "WAITING_FOR_DEPLOY" | "REATTEMPTING" | "FROZEN" | "FAILED" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE" | "DELAYED" | "EXPIRED";
|
|
31
|
+
status: "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "COMPLETED" | "CANCELED" | "FAILED" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE" | "DELAYED" | "EXPIRED" | "TIMED_OUT";
|
|
33
32
|
id: string;
|
|
34
|
-
|
|
33
|
+
version?: string | undefined;
|
|
34
|
+
createdAt: Date;
|
|
35
35
|
startedAt?: Date | undefined;
|
|
36
|
+
isTest: boolean;
|
|
37
|
+
idempotencyKey?: string | undefined;
|
|
38
|
+
tags: string[];
|
|
36
39
|
error?: {
|
|
37
40
|
message: string;
|
|
38
41
|
name?: string | undefined;
|
|
39
42
|
stackTrace?: string | undefined;
|
|
40
43
|
} | undefined;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
startedAt?: Date | undefined;
|
|
48
|
-
completedAt?: Date | undefined;
|
|
49
|
-
error?: {
|
|
50
|
-
message: string;
|
|
51
|
-
name?: string | undefined;
|
|
52
|
-
stackTrace?: string | undefined;
|
|
53
|
-
} | undefined;
|
|
54
|
-
} | undefined)[];
|
|
44
|
+
durationMs: number;
|
|
45
|
+
costInCents: number;
|
|
46
|
+
baseCostInCents: number;
|
|
47
|
+
metadata?: Record<string, any> | undefined;
|
|
48
|
+
ttl?: string | undefined;
|
|
49
|
+
taskIdentifier: string;
|
|
55
50
|
schedule?: {
|
|
56
51
|
id: string;
|
|
57
52
|
generator: {
|
|
@@ -62,24 +57,14 @@ declare function poll<TRunId extends AnyRunHandle | AnyTask | string>(runId: Run
|
|
|
62
57
|
externalId?: string | undefined;
|
|
63
58
|
deduplicationKey?: string | undefined;
|
|
64
59
|
} | undefined;
|
|
65
|
-
updatedAt: Date;
|
|
66
|
-
isTest: boolean;
|
|
67
|
-
createdAt: Date;
|
|
68
|
-
tags: string[];
|
|
69
|
-
durationMs: number;
|
|
70
|
-
costInCents: number;
|
|
71
|
-
baseCostInCents: number;
|
|
72
|
-
taskIdentifier: string;
|
|
73
|
-
ttl?: string | undefined;
|
|
74
60
|
payloadPresignedUrl?: string | undefined;
|
|
75
61
|
outputPresignedUrl?: string | undefined;
|
|
76
62
|
relatedRuns: {
|
|
77
63
|
root?: {
|
|
78
|
-
status: "
|
|
64
|
+
status: "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "COMPLETED" | "CANCELED" | "FAILED" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE" | "DELAYED" | "EXPIRED" | "TIMED_OUT";
|
|
79
65
|
id: string;
|
|
80
|
-
updatedAt: Date;
|
|
81
|
-
isTest: boolean;
|
|
82
66
|
createdAt: Date;
|
|
67
|
+
isTest: boolean;
|
|
83
68
|
tags: string[];
|
|
84
69
|
durationMs: number;
|
|
85
70
|
costInCents: number;
|
|
@@ -93,10 +78,11 @@ declare function poll<TRunId extends AnyRunHandle | AnyTask | string>(runId: Run
|
|
|
93
78
|
isSuccess: boolean;
|
|
94
79
|
isFailed: boolean;
|
|
95
80
|
isCancelled: boolean;
|
|
81
|
+
updatedAt: Date;
|
|
96
82
|
version?: string | undefined;
|
|
97
|
-
metadata?: Record<string, any> | undefined;
|
|
98
83
|
startedAt?: Date | undefined;
|
|
99
84
|
idempotencyKey?: string | undefined;
|
|
85
|
+
metadata?: Record<string, any> | undefined;
|
|
100
86
|
ttl?: string | undefined;
|
|
101
87
|
batchId?: string | undefined;
|
|
102
88
|
finishedAt?: Date | undefined;
|
|
@@ -104,11 +90,10 @@ declare function poll<TRunId extends AnyRunHandle | AnyTask | string>(runId: Run
|
|
|
104
90
|
expiredAt?: Date | undefined;
|
|
105
91
|
} | undefined;
|
|
106
92
|
parent?: {
|
|
107
|
-
status: "
|
|
93
|
+
status: "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "COMPLETED" | "CANCELED" | "FAILED" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE" | "DELAYED" | "EXPIRED" | "TIMED_OUT";
|
|
108
94
|
id: string;
|
|
109
|
-
updatedAt: Date;
|
|
110
|
-
isTest: boolean;
|
|
111
95
|
createdAt: Date;
|
|
96
|
+
isTest: boolean;
|
|
112
97
|
tags: string[];
|
|
113
98
|
durationMs: number;
|
|
114
99
|
costInCents: number;
|
|
@@ -122,10 +107,11 @@ declare function poll<TRunId extends AnyRunHandle | AnyTask | string>(runId: Run
|
|
|
122
107
|
isSuccess: boolean;
|
|
123
108
|
isFailed: boolean;
|
|
124
109
|
isCancelled: boolean;
|
|
110
|
+
updatedAt: Date;
|
|
125
111
|
version?: string | undefined;
|
|
126
|
-
metadata?: Record<string, any> | undefined;
|
|
127
112
|
startedAt?: Date | undefined;
|
|
128
113
|
idempotencyKey?: string | undefined;
|
|
114
|
+
metadata?: Record<string, any> | undefined;
|
|
129
115
|
ttl?: string | undefined;
|
|
130
116
|
batchId?: string | undefined;
|
|
131
117
|
finishedAt?: Date | undefined;
|
|
@@ -133,11 +119,10 @@ declare function poll<TRunId extends AnyRunHandle | AnyTask | string>(runId: Run
|
|
|
133
119
|
expiredAt?: Date | undefined;
|
|
134
120
|
} | undefined;
|
|
135
121
|
children?: {
|
|
136
|
-
status: "
|
|
122
|
+
status: "WAITING_FOR_DEPLOY" | "QUEUED" | "EXECUTING" | "REATTEMPTING" | "FROZEN" | "COMPLETED" | "CANCELED" | "FAILED" | "CRASHED" | "INTERRUPTED" | "SYSTEM_FAILURE" | "DELAYED" | "EXPIRED" | "TIMED_OUT";
|
|
137
123
|
id: string;
|
|
138
|
-
updatedAt: Date;
|
|
139
|
-
isTest: boolean;
|
|
140
124
|
createdAt: Date;
|
|
125
|
+
isTest: boolean;
|
|
141
126
|
tags: string[];
|
|
142
127
|
durationMs: number;
|
|
143
128
|
costInCents: number;
|
|
@@ -151,10 +136,11 @@ declare function poll<TRunId extends AnyRunHandle | AnyTask | string>(runId: Run
|
|
|
151
136
|
isSuccess: boolean;
|
|
152
137
|
isFailed: boolean;
|
|
153
138
|
isCancelled: boolean;
|
|
139
|
+
updatedAt: Date;
|
|
154
140
|
version?: string | undefined;
|
|
155
|
-
metadata?: Record<string, any> | undefined;
|
|
156
141
|
startedAt?: Date | undefined;
|
|
157
142
|
idempotencyKey?: string | undefined;
|
|
143
|
+
metadata?: Record<string, any> | undefined;
|
|
158
144
|
ttl?: string | undefined;
|
|
159
145
|
batchId?: string | undefined;
|
|
160
146
|
finishedAt?: Date | undefined;
|
|
@@ -171,9 +157,23 @@ declare function poll<TRunId extends AnyRunHandle | AnyTask | string>(runId: Run
|
|
|
171
157
|
isSuccess: boolean;
|
|
172
158
|
isFailed: boolean;
|
|
173
159
|
isCancelled: boolean;
|
|
160
|
+
updatedAt: Date;
|
|
174
161
|
finishedAt?: Date | undefined;
|
|
175
162
|
delayedUntil?: Date | undefined;
|
|
176
163
|
expiredAt?: Date | undefined;
|
|
164
|
+
attempts: ({
|
|
165
|
+
status: "EXECUTING" | "COMPLETED" | "CANCELED" | "FAILED" | "PENDING" | "PAUSED";
|
|
166
|
+
id: string;
|
|
167
|
+
createdAt: Date;
|
|
168
|
+
updatedAt: Date;
|
|
169
|
+
startedAt?: Date | undefined;
|
|
170
|
+
completedAt?: Date | undefined;
|
|
171
|
+
error?: {
|
|
172
|
+
message: string;
|
|
173
|
+
name?: string | undefined;
|
|
174
|
+
stackTrace?: string | undefined;
|
|
175
|
+
} | undefined;
|
|
176
|
+
} | undefined)[];
|
|
177
177
|
attemptCount: number;
|
|
178
178
|
output?: InferRunTypes<TRunId>["output"] | undefined;
|
|
179
179
|
payload?: InferRunTypes<TRunId>["payload"] | undefined;
|
|
@@ -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,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe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AkD;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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trigger.dev/sdk",
|
|
3
|
-
"version": "0.0.0-prerelease-
|
|
3
|
+
"version": "0.0.0-prerelease-20250213143202",
|
|
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": "0.0.0-prerelease-
|
|
43
|
+
"@trigger.dev/core": "0.0.0-prerelease-20250213143202",
|
|
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
|
},
|