@trigger.dev/sdk 2.2.11 → 2.3.1
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 +2696 -0
- package/dist/index.d.ts +39 -35
- package/dist/index.js +544 -361
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4818 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +14 -10
package/dist/index.js
CHANGED
|
@@ -1,29 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var node_async_hooks = require('node:async_hooks');
|
|
4
|
+
var core = require('@trigger.dev/core');
|
|
5
|
+
var coreBackend = require('@trigger.dev/core-backend');
|
|
6
|
+
var EventEmitter = require('node:events');
|
|
7
|
+
var node_process = require('node:process');
|
|
8
|
+
var zod = require('zod');
|
|
9
|
+
var crypto = require('node:crypto');
|
|
10
|
+
var node_buffer = require('node:buffer');
|
|
11
|
+
var cronstrue = require('cronstrue');
|
|
12
|
+
|
|
13
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
|
|
15
|
+
var EventEmitter__default = /*#__PURE__*/_interopDefault(EventEmitter);
|
|
16
|
+
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
17
|
+
var cronstrue__default = /*#__PURE__*/_interopDefault(cronstrue);
|
|
18
|
+
|
|
3
19
|
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
20
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
21
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
-
var __export = (target, all) => {
|
|
11
|
-
for (var name in all)
|
|
12
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
-
};
|
|
14
|
-
var __copyProps = (to, from, except, desc) => {
|
|
15
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
-
for (let key of __getOwnPropNames(from))
|
|
17
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
-
mod
|
|
25
|
-
));
|
|
26
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
22
|
var __publicField = (obj, key, value) => {
|
|
28
23
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
29
24
|
return value;
|
|
@@ -50,58 +45,9 @@ var __privateMethod = (obj, member, method) => {
|
|
|
50
45
|
__accessCheck(obj, member, "access private method");
|
|
51
46
|
return method;
|
|
52
47
|
};
|
|
53
|
-
|
|
54
|
-
// src/index.ts
|
|
55
|
-
var src_exports = {};
|
|
56
|
-
__export(src_exports, {
|
|
57
|
-
CronTrigger: () => CronTrigger,
|
|
58
|
-
DynamicSchedule: () => DynamicSchedule,
|
|
59
|
-
DynamicTrigger: () => DynamicTrigger,
|
|
60
|
-
EventSpecificationExampleSchema: () => EventSpecificationExampleSchema,
|
|
61
|
-
EventTrigger: () => EventTrigger,
|
|
62
|
-
ExternalSource: () => ExternalSource,
|
|
63
|
-
ExternalSourceTrigger: () => ExternalSourceTrigger,
|
|
64
|
-
IO: () => IO,
|
|
65
|
-
IOLogger: () => IOLogger,
|
|
66
|
-
IntervalTrigger: () => IntervalTrigger,
|
|
67
|
-
InvokeTrigger: () => InvokeTrigger,
|
|
68
|
-
JSONOutputSerializer: () => JSONOutputSerializer,
|
|
69
|
-
Job: () => Job,
|
|
70
|
-
MissingConnectionNotification: () => MissingConnectionNotification,
|
|
71
|
-
MissingConnectionResolvedNotification: () => MissingConnectionResolvedNotification,
|
|
72
|
-
TriggerClient: () => TriggerClient,
|
|
73
|
-
WebhookSource: () => WebhookSource,
|
|
74
|
-
WebhookTrigger: () => WebhookTrigger,
|
|
75
|
-
cronTrigger: () => cronTrigger,
|
|
76
|
-
eventTrigger: () => eventTrigger,
|
|
77
|
-
intervalTrigger: () => intervalTrigger,
|
|
78
|
-
invokeTrigger: () => invokeTrigger,
|
|
79
|
-
isTriggerError: () => isTriggerError,
|
|
80
|
-
missingConnectionNotification: () => missingConnectionNotification,
|
|
81
|
-
missingConnectionResolvedNotification: () => missingConnectionResolvedNotification,
|
|
82
|
-
omit: () => omit,
|
|
83
|
-
redactString: () => redactString,
|
|
84
|
-
retry: () => retry,
|
|
85
|
-
slugifyId: () => slugifyId,
|
|
86
|
-
verifyHmacSha256: () => verifyHmacSha256,
|
|
87
|
-
verifyRequestSignature: () => verifyRequestSignature,
|
|
88
|
-
waitForEventSchema: () => waitForEventSchema
|
|
89
|
-
});
|
|
90
|
-
module.exports = __toCommonJS(src_exports);
|
|
91
|
-
|
|
92
|
-
// src/utils.ts
|
|
93
|
-
function slugifyId(input) {
|
|
94
|
-
const replaceSpacesWithDash = input.toLowerCase().replace(/\s+/g, "-");
|
|
95
|
-
const removeNonUrlSafeChars = replaceSpacesWithDash.replace(/[^a-zA-Z0-9-._~]/g, "");
|
|
96
|
-
return removeNonUrlSafeChars;
|
|
97
|
-
}
|
|
98
|
-
__name(slugifyId, "slugifyId");
|
|
99
|
-
|
|
100
|
-
// src/utils/typedAsyncLocalStorage.ts
|
|
101
|
-
var import_node_async_hooks = require("async_hooks");
|
|
102
|
-
var TypedAsyncLocalStorage = class {
|
|
48
|
+
var _TypedAsyncLocalStorage = class _TypedAsyncLocalStorage {
|
|
103
49
|
constructor() {
|
|
104
|
-
this.storage = new
|
|
50
|
+
this.storage = new node_async_hooks.AsyncLocalStorage();
|
|
105
51
|
}
|
|
106
52
|
runWith(context, fn) {
|
|
107
53
|
return this.storage.run(context, fn);
|
|
@@ -110,20 +56,36 @@ var TypedAsyncLocalStorage = class {
|
|
|
110
56
|
return this.storage.getStore();
|
|
111
57
|
}
|
|
112
58
|
};
|
|
113
|
-
__name(
|
|
59
|
+
__name(_TypedAsyncLocalStorage, "TypedAsyncLocalStorage");
|
|
60
|
+
var TypedAsyncLocalStorage = _TypedAsyncLocalStorage;
|
|
114
61
|
|
|
115
62
|
// src/runLocalStorage.ts
|
|
116
63
|
var runLocalStorage = new TypedAsyncLocalStorage();
|
|
117
64
|
|
|
65
|
+
// src/utils.ts
|
|
66
|
+
function slugifyId(input) {
|
|
67
|
+
const replaceSpacesWithDash = input.toLowerCase().replace(/\s+/g, "-");
|
|
68
|
+
const removeNonUrlSafeChars = replaceSpacesWithDash.replace(/[^a-zA-Z0-9-._~]/g, "");
|
|
69
|
+
return removeNonUrlSafeChars;
|
|
70
|
+
}
|
|
71
|
+
__name(slugifyId, "slugifyId");
|
|
72
|
+
|
|
118
73
|
// src/job.ts
|
|
119
74
|
var _validate, validate_fn;
|
|
120
|
-
var
|
|
121
|
-
constructor(
|
|
75
|
+
var _Job = class _Job {
|
|
76
|
+
constructor(options) {
|
|
77
|
+
// Make sure the id is valid (must only contain alphanumeric characters and dashes)
|
|
78
|
+
// Make sure the version is valid (must be a valid semver version)
|
|
122
79
|
__privateAdd(this, _validate);
|
|
123
|
-
this.client = client;
|
|
124
80
|
this.options = options;
|
|
125
81
|
__privateMethod(this, _validate, validate_fn).call(this);
|
|
126
|
-
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Attaches the job to a client. This is called automatically when you define a job using `client.defineJob()`.
|
|
85
|
+
*/
|
|
86
|
+
attachToClient(client) {
|
|
87
|
+
this.client = client;
|
|
88
|
+
this.trigger.attachToJob(client, this);
|
|
127
89
|
}
|
|
128
90
|
get id() {
|
|
129
91
|
return slugifyId(this.options.id);
|
|
@@ -174,6 +136,10 @@ var Job = class {
|
|
|
174
136
|
};
|
|
175
137
|
}
|
|
176
138
|
async invoke(param1, param2 = void 0, param3 = void 0) {
|
|
139
|
+
const triggerClient = this.client;
|
|
140
|
+
if (!triggerClient) {
|
|
141
|
+
throw new Error("Cannot invoke a job that is not attached to a client. Make sure you attach the job to a client before invoking it.");
|
|
142
|
+
}
|
|
177
143
|
const runStore = runLocalStorage.getStore();
|
|
178
144
|
if (typeof param1 === "string") {
|
|
179
145
|
if (!runStore) {
|
|
@@ -181,7 +147,7 @@ var Job = class {
|
|
|
181
147
|
}
|
|
182
148
|
const options = param3 ?? {};
|
|
183
149
|
return await runStore.io.runTask(param1, async (task) => {
|
|
184
|
-
const result = await
|
|
150
|
+
const result = await triggerClient.invokeJob(this.id, param2, {
|
|
185
151
|
idempotencyKey: task.idempotencyKey,
|
|
186
152
|
...options
|
|
187
153
|
});
|
|
@@ -212,9 +178,13 @@ var Job = class {
|
|
|
212
178
|
if (runStore) {
|
|
213
179
|
throw new Error("Cannot invoke a job from within a run without a cacheKey.");
|
|
214
180
|
}
|
|
215
|
-
return await
|
|
181
|
+
return await triggerClient.invokeJob(this.id, param1, param3);
|
|
216
182
|
}
|
|
217
183
|
async invokeAndWaitForCompletion(cacheKey, payload, timeoutInSeconds = 60 * 60, options = {}) {
|
|
184
|
+
const triggerClient = this.client;
|
|
185
|
+
if (!triggerClient) {
|
|
186
|
+
throw new Error("Cannot invoke a job that is not attached to a client. Make sure you attach the job to a client before invoking it.");
|
|
187
|
+
}
|
|
218
188
|
const runStore = runLocalStorage.getStore();
|
|
219
189
|
if (!runStore) {
|
|
220
190
|
throw new Error("Cannot invoke a job from outside of a run using invokeAndWaitForCompletion. Make sure you are running the job from within a run or use the invoke method instead.");
|
|
@@ -222,7 +192,7 @@ var Job = class {
|
|
|
222
192
|
const { io, ctx } = runStore;
|
|
223
193
|
return await io.runTask(cacheKey, async (task) => {
|
|
224
194
|
const parsedPayload = this.trigger.event.parseInvokePayload ? this.trigger.event.parseInvokePayload(payload) ? payload : void 0 : payload;
|
|
225
|
-
const result = await
|
|
195
|
+
const result = await triggerClient.invokeJob(this.id, parsedPayload, {
|
|
226
196
|
idempotencyKey: task.idempotencyKey,
|
|
227
197
|
callbackUrl: task.callbackUrl ?? void 0,
|
|
228
198
|
...options
|
|
@@ -286,71 +256,67 @@ var Job = class {
|
|
|
286
256
|
return results;
|
|
287
257
|
}
|
|
288
258
|
};
|
|
289
|
-
__name(Job, "Job");
|
|
290
259
|
_validate = new WeakSet();
|
|
291
260
|
validate_fn = /* @__PURE__ */ __name(function() {
|
|
292
261
|
if (!this.version.match(/^(\d+)\.(\d+)\.(\d+)$/)) {
|
|
293
262
|
throw new Error(`Invalid job version: "${this.version}". Job versions must be valid semver versions.`);
|
|
294
263
|
}
|
|
295
264
|
}, "#validate");
|
|
265
|
+
__name(_Job, "Job");
|
|
266
|
+
var Job = _Job;
|
|
296
267
|
|
|
297
|
-
//
|
|
298
|
-
var
|
|
299
|
-
var import_colorette = require("colorette");
|
|
300
|
-
|
|
301
|
-
// src/apiClient.ts
|
|
302
|
-
var import_core3 = require("@trigger.dev/core");
|
|
303
|
-
var import_zod3 = require("zod");
|
|
304
|
-
|
|
305
|
-
// src/io.ts
|
|
306
|
-
var import_core2 = require("@trigger.dev/core");
|
|
307
|
-
var import_core_backend = require("@trigger.dev/core-backend");
|
|
308
|
-
var import_node_async_hooks2 = require("async_hooks");
|
|
309
|
-
var import_node_crypto = require("crypto");
|
|
268
|
+
// package.json
|
|
269
|
+
var version = "2.3.1";
|
|
310
270
|
|
|
311
271
|
// src/errors.ts
|
|
312
|
-
var
|
|
272
|
+
var _ResumeWithTaskError = class _ResumeWithTaskError {
|
|
313
273
|
constructor(task) {
|
|
314
274
|
this.task = task;
|
|
315
275
|
}
|
|
316
276
|
};
|
|
317
|
-
__name(
|
|
318
|
-
var
|
|
277
|
+
__name(_ResumeWithTaskError, "ResumeWithTaskError");
|
|
278
|
+
var ResumeWithTaskError = _ResumeWithTaskError;
|
|
279
|
+
var _ResumeWithParallelTaskError = class _ResumeWithParallelTaskError {
|
|
319
280
|
constructor(task, childErrors) {
|
|
320
281
|
this.task = task;
|
|
321
282
|
this.childErrors = childErrors;
|
|
322
283
|
}
|
|
323
284
|
};
|
|
324
|
-
__name(
|
|
325
|
-
var
|
|
285
|
+
__name(_ResumeWithParallelTaskError, "ResumeWithParallelTaskError");
|
|
286
|
+
var ResumeWithParallelTaskError = _ResumeWithParallelTaskError;
|
|
287
|
+
var _RetryWithTaskError = class _RetryWithTaskError {
|
|
326
288
|
constructor(cause, task, retryAt) {
|
|
327
289
|
this.cause = cause;
|
|
328
290
|
this.task = task;
|
|
329
291
|
this.retryAt = retryAt;
|
|
330
292
|
}
|
|
331
293
|
};
|
|
332
|
-
__name(
|
|
333
|
-
var
|
|
294
|
+
__name(_RetryWithTaskError, "RetryWithTaskError");
|
|
295
|
+
var RetryWithTaskError = _RetryWithTaskError;
|
|
296
|
+
var _CanceledWithTaskError = class _CanceledWithTaskError {
|
|
334
297
|
constructor(task) {
|
|
335
298
|
this.task = task;
|
|
336
299
|
}
|
|
337
300
|
};
|
|
338
|
-
__name(
|
|
339
|
-
var
|
|
301
|
+
__name(_CanceledWithTaskError, "CanceledWithTaskError");
|
|
302
|
+
var CanceledWithTaskError = _CanceledWithTaskError;
|
|
303
|
+
var _YieldExecutionError = class _YieldExecutionError {
|
|
340
304
|
constructor(key) {
|
|
341
305
|
this.key = key;
|
|
342
306
|
}
|
|
343
307
|
};
|
|
344
|
-
__name(
|
|
345
|
-
var
|
|
308
|
+
__name(_YieldExecutionError, "YieldExecutionError");
|
|
309
|
+
var YieldExecutionError = _YieldExecutionError;
|
|
310
|
+
var _AutoYieldExecutionError = class _AutoYieldExecutionError {
|
|
346
311
|
constructor(location, timeRemaining, timeElapsed) {
|
|
347
312
|
this.location = location;
|
|
348
313
|
this.timeRemaining = timeRemaining;
|
|
349
314
|
this.timeElapsed = timeElapsed;
|
|
350
315
|
}
|
|
351
316
|
};
|
|
352
|
-
__name(
|
|
353
|
-
var
|
|
317
|
+
__name(_AutoYieldExecutionError, "AutoYieldExecutionError");
|
|
318
|
+
var AutoYieldExecutionError = _AutoYieldExecutionError;
|
|
319
|
+
var _AutoYieldWithCompletedTaskExecutionError = class _AutoYieldWithCompletedTaskExecutionError {
|
|
354
320
|
constructor(id, properties, data, output) {
|
|
355
321
|
this.id = id;
|
|
356
322
|
this.properties = properties;
|
|
@@ -358,27 +324,27 @@ var AutoYieldWithCompletedTaskExecutionError = class {
|
|
|
358
324
|
this.output = output;
|
|
359
325
|
}
|
|
360
326
|
};
|
|
361
|
-
__name(
|
|
362
|
-
var
|
|
327
|
+
__name(_AutoYieldWithCompletedTaskExecutionError, "AutoYieldWithCompletedTaskExecutionError");
|
|
328
|
+
var AutoYieldWithCompletedTaskExecutionError = _AutoYieldWithCompletedTaskExecutionError;
|
|
329
|
+
var _ParsedPayloadSchemaError = class _ParsedPayloadSchemaError {
|
|
363
330
|
constructor(schemaErrors) {
|
|
364
331
|
this.schemaErrors = schemaErrors;
|
|
365
332
|
}
|
|
366
333
|
};
|
|
367
|
-
__name(
|
|
334
|
+
__name(_ParsedPayloadSchemaError, "ParsedPayloadSchemaError");
|
|
335
|
+
var ParsedPayloadSchemaError = _ParsedPayloadSchemaError;
|
|
368
336
|
function isTriggerError(err) {
|
|
369
337
|
return err instanceof ResumeWithTaskError || err instanceof RetryWithTaskError || err instanceof CanceledWithTaskError || err instanceof YieldExecutionError || err instanceof AutoYieldExecutionError || err instanceof AutoYieldWithCompletedTaskExecutionError || err instanceof ResumeWithParallelTaskError;
|
|
370
338
|
}
|
|
371
339
|
__name(isTriggerError, "isTriggerError");
|
|
372
|
-
var
|
|
340
|
+
var _ErrorWithTask = class _ErrorWithTask extends Error {
|
|
373
341
|
constructor(cause, message) {
|
|
374
342
|
super(message);
|
|
375
343
|
this.cause = cause;
|
|
376
344
|
}
|
|
377
345
|
};
|
|
378
|
-
__name(
|
|
379
|
-
|
|
380
|
-
// src/retry.ts
|
|
381
|
-
var import_core = require("@trigger.dev/core");
|
|
346
|
+
__name(_ErrorWithTask, "ErrorWithTask");
|
|
347
|
+
var ErrorWithTask = _ErrorWithTask;
|
|
382
348
|
var retry = {
|
|
383
349
|
standardBackoff: {
|
|
384
350
|
limit: 8,
|
|
@@ -397,7 +363,7 @@ var retry = {
|
|
|
397
363
|
};
|
|
398
364
|
|
|
399
365
|
// src/status.ts
|
|
400
|
-
var
|
|
366
|
+
var _TriggerStatus = class _TriggerStatus {
|
|
401
367
|
constructor(id, io) {
|
|
402
368
|
this.id = id;
|
|
403
369
|
this.io = io;
|
|
@@ -428,35 +394,30 @@ var TriggerStatus = class {
|
|
|
428
394
|
});
|
|
429
395
|
}
|
|
430
396
|
};
|
|
431
|
-
__name(
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
icon: import_zod.z.string().optional(),
|
|
439
|
-
payload: import_zod.z.any()
|
|
397
|
+
__name(_TriggerStatus, "TriggerStatus");
|
|
398
|
+
var TriggerStatus = _TriggerStatus;
|
|
399
|
+
var EventSpecificationExampleSchema = zod.z.object({
|
|
400
|
+
id: zod.z.string(),
|
|
401
|
+
name: zod.z.string(),
|
|
402
|
+
icon: zod.z.string().optional(),
|
|
403
|
+
payload: zod.z.any()
|
|
440
404
|
});
|
|
441
405
|
function waitForEventSchema(schema) {
|
|
442
|
-
return
|
|
443
|
-
id:
|
|
444
|
-
name:
|
|
445
|
-
source:
|
|
406
|
+
return zod.z.object({
|
|
407
|
+
id: zod.z.string(),
|
|
408
|
+
name: zod.z.string(),
|
|
409
|
+
source: zod.z.string(),
|
|
446
410
|
payload: schema,
|
|
447
|
-
timestamp:
|
|
448
|
-
context:
|
|
449
|
-
accountId:
|
|
411
|
+
timestamp: zod.z.coerce.date(),
|
|
412
|
+
context: zod.z.any().optional(),
|
|
413
|
+
accountId: zod.z.string().optional()
|
|
450
414
|
});
|
|
451
415
|
}
|
|
452
416
|
__name(waitForEventSchema, "waitForEventSchema");
|
|
453
417
|
|
|
454
|
-
// src/io.ts
|
|
455
|
-
var import_zod2 = require("zod");
|
|
456
|
-
|
|
457
418
|
// src/store/keyValueStore.ts
|
|
458
419
|
var _namespacedKey, namespacedKey_fn, _sharedProperties, sharedProperties_fn;
|
|
459
|
-
var
|
|
420
|
+
var _KeyValueStore = class _KeyValueStore {
|
|
460
421
|
constructor(apiClient, type = null, namespace = "") {
|
|
461
422
|
__privateAdd(this, _namespacedKey);
|
|
462
423
|
__privateAdd(this, _sharedProperties);
|
|
@@ -579,7 +540,6 @@ var KeyValueStore = class {
|
|
|
579
540
|
});
|
|
580
541
|
}
|
|
581
542
|
};
|
|
582
|
-
__name(KeyValueStore, "KeyValueStore");
|
|
583
543
|
_namespacedKey = new WeakSet();
|
|
584
544
|
namespacedKey_fn = /* @__PURE__ */ __name(function(key) {
|
|
585
545
|
const parts = [];
|
|
@@ -605,9 +565,9 @@ sharedProperties_fn = /* @__PURE__ */ __name(function(key1) {
|
|
|
605
565
|
}
|
|
606
566
|
];
|
|
607
567
|
}, "#sharedProperties");
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
var
|
|
568
|
+
__name(_KeyValueStore, "KeyValueStore");
|
|
569
|
+
var KeyValueStore = _KeyValueStore;
|
|
570
|
+
var _JSONOutputSerializer = class _JSONOutputSerializer {
|
|
611
571
|
serialize(value) {
|
|
612
572
|
return JSON.stringify(value);
|
|
613
573
|
}
|
|
@@ -615,9 +575,10 @@ var JSONOutputSerializer = class {
|
|
|
615
575
|
return value ? JSON.parse(value) : void 0;
|
|
616
576
|
}
|
|
617
577
|
};
|
|
618
|
-
__name(
|
|
578
|
+
__name(_JSONOutputSerializer, "JSONOutputSerializer");
|
|
579
|
+
var JSONOutputSerializer = _JSONOutputSerializer;
|
|
619
580
|
var _addToCachedTasks, addToCachedTasks_fn, _detectAutoYield, detectAutoYield_fn, _forceYield, forceYield_fn, _getTimeElapsed, getTimeElapsed_fn, _getRemainingTimeInMillis, getRemainingTimeInMillis_fn;
|
|
620
|
-
var
|
|
581
|
+
var _IO = class _IO {
|
|
621
582
|
constructor(options) {
|
|
622
583
|
__privateAdd(this, _addToCachedTasks);
|
|
623
584
|
__privateAdd(this, _detectAutoYield);
|
|
@@ -626,12 +587,15 @@ var IO = class {
|
|
|
626
587
|
__privateAdd(this, _getRemainingTimeInMillis);
|
|
627
588
|
__publicField(this, "_outputSerializer", new JSONOutputSerializer());
|
|
628
589
|
__publicField(this, "_visitedCacheKeys", /* @__PURE__ */ new Set());
|
|
590
|
+
/**
|
|
591
|
+
* `io.brb()` is an alias of `io.yield()`
|
|
592
|
+
*/
|
|
629
593
|
__publicField(this, "brb", this.yield.bind(this));
|
|
630
594
|
this._id = options.id;
|
|
631
595
|
this._jobId = options.jobId;
|
|
632
596
|
this._apiClient = options.apiClient;
|
|
633
597
|
this._triggerClient = options.client;
|
|
634
|
-
this._logger = options.logger ?? new
|
|
598
|
+
this._logger = options.logger ?? new coreBackend.Logger("trigger.dev", options.logLevel);
|
|
635
599
|
this._cachedTasks = /* @__PURE__ */ new Map();
|
|
636
600
|
this._jobLogger = options.jobLogger;
|
|
637
601
|
this._jobLogLevel = options.jobLogLevel;
|
|
@@ -655,11 +619,11 @@ var IO = class {
|
|
|
655
619
|
});
|
|
656
620
|
this._stats.initialCachedTasks = options.cachedTasks.length;
|
|
657
621
|
}
|
|
658
|
-
this._taskStorage = new
|
|
622
|
+
this._taskStorage = new node_async_hooks.AsyncLocalStorage();
|
|
659
623
|
this._context = options.context;
|
|
660
624
|
this._yieldedExecutions = options.yieldedExecutions ?? [];
|
|
661
625
|
if (options.noopTasksSet) {
|
|
662
|
-
this._noopTasksBloomFilter =
|
|
626
|
+
this._noopTasksBloomFilter = coreBackend.BloomFilter.deserialize(options.noopTasksSet, coreBackend.BloomFilter.NOOP_TASK_SET_SIZE);
|
|
663
627
|
}
|
|
664
628
|
this._cachedTasksCursor = options.cachedTasksCursor;
|
|
665
629
|
this._serverVersion = options.serverVersion ?? "unversioned";
|
|
@@ -667,16 +631,19 @@ var IO = class {
|
|
|
667
631
|
get stats() {
|
|
668
632
|
return this._stats;
|
|
669
633
|
}
|
|
634
|
+
/** @internal */
|
|
670
635
|
get runId() {
|
|
671
636
|
return this._id;
|
|
672
637
|
}
|
|
638
|
+
/** @internal */
|
|
673
639
|
get triggerClient() {
|
|
674
640
|
return this._triggerClient;
|
|
675
641
|
}
|
|
642
|
+
/** Used to send log messages to the [Run log](https://trigger.dev/docs/documentation/guides/viewing-runs). */
|
|
676
643
|
get logger() {
|
|
677
644
|
return new IOLogger(async (level, message, data) => {
|
|
678
645
|
let logLevel = "info";
|
|
679
|
-
if (
|
|
646
|
+
if (coreBackend.Logger.satisfiesLogLevel(logLevel, this._jobLogLevel)) {
|
|
680
647
|
await this.runTask([
|
|
681
648
|
message,
|
|
682
649
|
level
|
|
@@ -728,6 +695,12 @@ var IO = class {
|
|
|
728
695
|
}
|
|
729
696
|
});
|
|
730
697
|
}
|
|
698
|
+
/** `io.random()` is identical to `Math.random()` when called without options but ensures your random numbers are not regenerated on resume or retry. It will return a pseudo-random floating-point number between optional `min` (default: 0, inclusive) and `max` (default: 1, exclusive). Can optionally `round` to the nearest integer.
|
|
699
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
700
|
+
* @param min Sets the lower bound (inclusive). Can't be higher than `max`.
|
|
701
|
+
* @param max Sets the upper bound (exclusive). Can't be lower than `min`.
|
|
702
|
+
* @param round Controls rounding to the nearest integer. Any `max` integer will become inclusive when enabled. Rounding with floating-point bounds may cause unexpected skew and boundary inclusivity.
|
|
703
|
+
*/
|
|
731
704
|
async random(cacheKey, { min = 0, max = 1, round = false } = {}) {
|
|
732
705
|
return await this.runTask(cacheKey, async (task) => {
|
|
733
706
|
if (min > max) {
|
|
@@ -778,6 +751,10 @@ var IO = class {
|
|
|
778
751
|
}
|
|
779
752
|
});
|
|
780
753
|
}
|
|
754
|
+
/** `io.wait()` waits for the specified amount of time before continuing the Job. Delays work even if you're on a serverless platform with timeouts, or if your server goes down. They utilize [resumability](https://trigger.dev/docs/documentation/concepts/resumability) to ensure that the Run can be resumed after the delay.
|
|
755
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
756
|
+
* @param seconds The number of seconds to wait. This can be very long, serverless timeouts are not an issue.
|
|
757
|
+
*/
|
|
781
758
|
async wait(cacheKey, seconds) {
|
|
782
759
|
return await this.runTask(cacheKey, async (task) => {
|
|
783
760
|
}, {
|
|
@@ -846,10 +823,29 @@ var IO = class {
|
|
|
846
823
|
] : []
|
|
847
824
|
],
|
|
848
825
|
parseOutput: (output) => {
|
|
849
|
-
return waitForEventSchema(event.schema ??
|
|
826
|
+
return waitForEventSchema(event.schema ?? zod.z.any()).parse(output);
|
|
850
827
|
}
|
|
851
828
|
});
|
|
852
829
|
}
|
|
830
|
+
/** `io.waitForRequest()` allows you to pause the execution of a run until the url provided in the callback is POSTed to.
|
|
831
|
+
* This is useful for integrating with external services that require a callback URL to be provided, or if you want to be able to wait until an action is performed somewhere else in your system.
|
|
832
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
833
|
+
* @param callback A callback function that will provide the unique URL to POST to.
|
|
834
|
+
* @param options Options for the callback.
|
|
835
|
+
* @param options.timeoutInSeconds How long to wait for the request to be POSTed to the callback URL before timing out. Defaults to 1hr.
|
|
836
|
+
* @returns The POSTed request JSON body.
|
|
837
|
+
* @example
|
|
838
|
+
* ```ts
|
|
839
|
+
const result = await io.waitForRequest<{ message: string }>(
|
|
840
|
+
"wait-for-request",
|
|
841
|
+
async (url, task) => {
|
|
842
|
+
// Save the URL somewhere so you can POST to it later
|
|
843
|
+
// Or send it to an external service that will POST to it
|
|
844
|
+
},
|
|
845
|
+
{ timeoutInSeconds: 60 } // wait 60 seconds
|
|
846
|
+
);
|
|
847
|
+
* ```
|
|
848
|
+
*/
|
|
853
849
|
async waitForRequest(cacheKey, callback, options) {
|
|
854
850
|
const timeoutInSeconds = options?.timeoutInSeconds ?? 60 * 60;
|
|
855
851
|
return await this.runTask(cacheKey, async (task, io) => {
|
|
@@ -878,12 +874,55 @@ var IO = class {
|
|
|
878
874
|
]
|
|
879
875
|
});
|
|
880
876
|
}
|
|
877
|
+
/** `io.createStatus()` allows you to set a status with associated data during the Run. Statuses can be used by your UI using the react package
|
|
878
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
879
|
+
* @param initialStatus The initial status you want this status to have. You can update it during the rub using the returned object.
|
|
880
|
+
* @returns a TriggerStatus object that you can call `update()` on, to update the status.
|
|
881
|
+
* @example
|
|
882
|
+
* ```ts
|
|
883
|
+
* client.defineJob(
|
|
884
|
+
//...
|
|
885
|
+
run: async (payload, io, ctx) => {
|
|
886
|
+
const generatingImages = await io.createStatus("generating-images", {
|
|
887
|
+
label: "Generating Images",
|
|
888
|
+
state: "loading",
|
|
889
|
+
data: {
|
|
890
|
+
progress: 0.1,
|
|
891
|
+
},
|
|
892
|
+
});
|
|
893
|
+
|
|
894
|
+
//...do stuff
|
|
895
|
+
|
|
896
|
+
await generatingImages.update("completed-generation", {
|
|
897
|
+
label: "Generated images",
|
|
898
|
+
state: "success",
|
|
899
|
+
data: {
|
|
900
|
+
progress: 1.0,
|
|
901
|
+
urls: ["http://..."]
|
|
902
|
+
},
|
|
903
|
+
});
|
|
904
|
+
|
|
905
|
+
//...
|
|
906
|
+
});
|
|
907
|
+
* ```
|
|
908
|
+
*/
|
|
881
909
|
async createStatus(cacheKey, initialStatus) {
|
|
882
910
|
const id = typeof cacheKey === "string" ? cacheKey : cacheKey.join("-");
|
|
883
911
|
const status = new TriggerStatus(id, this);
|
|
884
912
|
await status.update(cacheKey, initialStatus);
|
|
885
913
|
return status;
|
|
886
914
|
}
|
|
915
|
+
/** `io.backgroundFetch()` fetches data from a URL that can take longer that the serverless timeout. The actual `fetch` request is performed on the Trigger.dev platform, and the response is sent back to you.
|
|
916
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
917
|
+
* @param url The URL to fetch from.
|
|
918
|
+
* @param requestInit The options for the request
|
|
919
|
+
* @param retry The options for retrying the request if it fails
|
|
920
|
+
* An object where the key is a status code pattern and the value is a retrying strategy.
|
|
921
|
+
* Supported patterns are:
|
|
922
|
+
* - Specific status codes: 429
|
|
923
|
+
* - Ranges: 500-599
|
|
924
|
+
* - Wildcards: 2xx, 3xx, 4xx, 5xx
|
|
925
|
+
*/
|
|
887
926
|
async backgroundFetch(cacheKey, url, requestInit, options) {
|
|
888
927
|
const urlObject = new URL(url);
|
|
889
928
|
return await this.runTask(cacheKey, async (task) => {
|
|
@@ -926,6 +965,39 @@ var IO = class {
|
|
|
926
965
|
}
|
|
927
966
|
});
|
|
928
967
|
}
|
|
968
|
+
/** `io.backgroundPoll()` will fetch data from a URL on an interval. The actual `fetch` requests are performed on the Trigger.dev server, so you don't have to worry about serverless function timeouts.
|
|
969
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
970
|
+
* @param params The options for the background poll
|
|
971
|
+
* @param params.url The URL to fetch from.
|
|
972
|
+
* @param params.requestInit The options for the request, like headers and method
|
|
973
|
+
* @param params.responseFilter An [EventFilter](https://trigger.dev/docs/documentation/guides/event-filter) that allows you to specify when to stop polling.
|
|
974
|
+
* @param params.interval The interval in seconds to poll the URL in seconds. Defaults to 10 seconds which is the minimum.
|
|
975
|
+
* @param params.timeout The timeout in seconds for each request in seconds. Defaults to 10 minutes. Minimum is 60 seconds and max is 1 hour
|
|
976
|
+
* @param params.requestTimeout An optional object that allows you to timeout individual fetch requests
|
|
977
|
+
* @param params.requestTimeout An optional object that allows you to timeout individual fetch requests
|
|
978
|
+
* @param params.requestTimeout.durationInMs The duration in milliseconds to timeout the request
|
|
979
|
+
*
|
|
980
|
+
* @example
|
|
981
|
+
* ```ts
|
|
982
|
+
* const result = await io.backgroundPoll<{ id: string; status: string; }>("poll", {
|
|
983
|
+
url: `http://localhost:3030/api/v1/runs/${run.id}`,
|
|
984
|
+
requestInit: {
|
|
985
|
+
headers: {
|
|
986
|
+
Accept: "application/json",
|
|
987
|
+
Authorization: redactString`Bearer ${process.env["TRIGGER_API_KEY"]!}`,
|
|
988
|
+
},
|
|
989
|
+
},
|
|
990
|
+
interval: 10,
|
|
991
|
+
timeout: 600,
|
|
992
|
+
responseFilter: {
|
|
993
|
+
status: [200],
|
|
994
|
+
body: {
|
|
995
|
+
status: ["SUCCESS"],
|
|
996
|
+
},
|
|
997
|
+
},
|
|
998
|
+
});
|
|
999
|
+
* ```
|
|
1000
|
+
*/
|
|
929
1001
|
async backgroundPoll(cacheKey, params) {
|
|
930
1002
|
const urlObject = new URL(params.url);
|
|
931
1003
|
return await this.runTask(cacheKey, async (task) => {
|
|
@@ -955,6 +1027,17 @@ var IO = class {
|
|
|
955
1027
|
}
|
|
956
1028
|
});
|
|
957
1029
|
}
|
|
1030
|
+
/** `io.backgroundFetchResponse()` fetches data from a URL that can take longer that the serverless timeout. The actual `fetch` request is performed on the Trigger.dev platform, and the response is sent back to you.
|
|
1031
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1032
|
+
* @param url The URL to fetch from.
|
|
1033
|
+
* @param requestInit The options for the request
|
|
1034
|
+
* @param retry The options for retrying the request if it fails
|
|
1035
|
+
* An object where the key is a status code pattern and the value is a retrying strategy.
|
|
1036
|
+
* Supported patterns are:
|
|
1037
|
+
* - Specific status codes: 429
|
|
1038
|
+
* - Ranges: 500-599
|
|
1039
|
+
* - Wildcards: 2xx, 3xx, 4xx, 5xx
|
|
1040
|
+
*/
|
|
958
1041
|
async backgroundFetchResponse(cacheKey, url, requestInit, options) {
|
|
959
1042
|
const urlObject = new URL(url);
|
|
960
1043
|
return await this.runTask(cacheKey, async (task) => {
|
|
@@ -996,6 +1079,11 @@ var IO = class {
|
|
|
996
1079
|
}
|
|
997
1080
|
});
|
|
998
1081
|
}
|
|
1082
|
+
/** `io.sendEvent()` allows you to send an event from inside a Job run. The sent event will trigger any Jobs that are listening for that event (based on the name).
|
|
1083
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1084
|
+
* @param event The event to send. The event name must match the name of the event that your Jobs are listening for.
|
|
1085
|
+
* @param options Options for sending the event.
|
|
1086
|
+
*/
|
|
999
1087
|
async sendEvent(cacheKey, event, options) {
|
|
1000
1088
|
return await this.runTask(cacheKey, async (task) => {
|
|
1001
1089
|
return await this._triggerClient.sendEvent(event, options);
|
|
@@ -1021,6 +1109,11 @@ var IO = class {
|
|
|
1021
1109
|
]
|
|
1022
1110
|
});
|
|
1023
1111
|
}
|
|
1112
|
+
/** `io.sendEvents()` allows you to send multiple events from inside a Job run. The sent events will trigger any Jobs that are listening for those events (based on the name).
|
|
1113
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1114
|
+
* @param event The events to send. The event names must match the names of the events that your Jobs are listening for.
|
|
1115
|
+
* @param options Options for sending the events.
|
|
1116
|
+
*/
|
|
1024
1117
|
async sendEvents(cacheKey, events, options) {
|
|
1025
1118
|
return await this.runTask(cacheKey, async (task) => {
|
|
1026
1119
|
return await this._triggerClient.sendEvents(events, options);
|
|
@@ -1056,6 +1149,11 @@ var IO = class {
|
|
|
1056
1149
|
]
|
|
1057
1150
|
});
|
|
1058
1151
|
}
|
|
1152
|
+
/** `io.cancelEvent()` allows you to cancel an event that was previously sent with `io.sendEvent()`. This will prevent any Jobs from running that are listening for that event if the event was sent with a delay
|
|
1153
|
+
* @param cacheKey
|
|
1154
|
+
* @param eventId
|
|
1155
|
+
* @returns
|
|
1156
|
+
*/
|
|
1059
1157
|
async cancelEvent(cacheKey, eventId) {
|
|
1060
1158
|
return await this.runTask(cacheKey, async (task) => {
|
|
1061
1159
|
return await this._triggerClient.cancelEvent(eventId);
|
|
@@ -1107,6 +1205,14 @@ var IO = class {
|
|
|
1107
1205
|
params: options
|
|
1108
1206
|
});
|
|
1109
1207
|
}
|
|
1208
|
+
/** `io.registerInterval()` allows you to register a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that will trigger any jobs it's attached to on a regular interval.
|
|
1209
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1210
|
+
* @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to register a new schedule on.
|
|
1211
|
+
* @param id A unique id for the interval. This is used to identify and unregister the interval later.
|
|
1212
|
+
* @param options The options for the interval.
|
|
1213
|
+
* @returns A promise that has information about the interval.
|
|
1214
|
+
* @deprecated Use `DynamicSchedule.register` instead.
|
|
1215
|
+
*/
|
|
1110
1216
|
async registerInterval(cacheKey, dynamicSchedule, id, options) {
|
|
1111
1217
|
return await this.runTask(cacheKey, async (task) => {
|
|
1112
1218
|
return dynamicSchedule.register(id, {
|
|
@@ -1132,6 +1238,12 @@ var IO = class {
|
|
|
1132
1238
|
params: options
|
|
1133
1239
|
});
|
|
1134
1240
|
}
|
|
1241
|
+
/** `io.unregisterInterval()` allows you to unregister a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that was previously registered with `io.registerInterval()`.
|
|
1242
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1243
|
+
* @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
|
|
1244
|
+
* @param id A unique id for the interval. This is used to identify and unregister the interval later.
|
|
1245
|
+
* @deprecated Use `DynamicSchedule.unregister` instead.
|
|
1246
|
+
*/
|
|
1135
1247
|
async unregisterInterval(cacheKey, dynamicSchedule, id) {
|
|
1136
1248
|
return await this.runTask(cacheKey, async (task) => {
|
|
1137
1249
|
return dynamicSchedule.unregister(id);
|
|
@@ -1149,6 +1261,13 @@ var IO = class {
|
|
|
1149
1261
|
]
|
|
1150
1262
|
});
|
|
1151
1263
|
}
|
|
1264
|
+
/** `io.registerCron()` allows you to register a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that will trigger any jobs it's attached to on a regular CRON schedule.
|
|
1265
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1266
|
+
* @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to register a new schedule on.
|
|
1267
|
+
* @param id A unique id for the schedule. This is used to identify and unregister the schedule later.
|
|
1268
|
+
* @param options The options for the CRON schedule.
|
|
1269
|
+
* @deprecated Use `DynamicSchedule.register` instead.
|
|
1270
|
+
*/
|
|
1152
1271
|
async registerCron(cacheKey, dynamicSchedule, id, options) {
|
|
1153
1272
|
return await this.runTask(cacheKey, async (task) => {
|
|
1154
1273
|
return dynamicSchedule.register(id, {
|
|
@@ -1174,6 +1293,12 @@ var IO = class {
|
|
|
1174
1293
|
params: options
|
|
1175
1294
|
});
|
|
1176
1295
|
}
|
|
1296
|
+
/** `io.unregisterCron()` allows you to unregister a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that was previously registered with `io.registerCron()`.
|
|
1297
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1298
|
+
* @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
|
|
1299
|
+
* @param id A unique id for the interval. This is used to identify and unregister the interval later.
|
|
1300
|
+
* @deprecated Use `DynamicSchedule.unregister` instead.
|
|
1301
|
+
*/
|
|
1177
1302
|
async unregisterCron(cacheKey, dynamicSchedule, id) {
|
|
1178
1303
|
return await this.runTask(cacheKey, async (task) => {
|
|
1179
1304
|
return dynamicSchedule.unregister(id);
|
|
@@ -1191,6 +1316,13 @@ var IO = class {
|
|
|
1191
1316
|
]
|
|
1192
1317
|
});
|
|
1193
1318
|
}
|
|
1319
|
+
/** `io.registerTrigger()` allows you to register a [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger) with the specified trigger params.
|
|
1320
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1321
|
+
* @param trigger The [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger) to register.
|
|
1322
|
+
* @param id A unique id for the trigger. This is used to identify and unregister the trigger later.
|
|
1323
|
+
* @param params The params for the trigger.
|
|
1324
|
+
* @deprecated Use `DynamicTrigger.register` instead.
|
|
1325
|
+
*/
|
|
1194
1326
|
async registerTrigger(cacheKey, trigger, id, params) {
|
|
1195
1327
|
return await this.runTask(cacheKey, async (task) => {
|
|
1196
1328
|
const registration = await this.runTask("register-source", async (subtask1) => {
|
|
@@ -1246,6 +1378,14 @@ var IO = class {
|
|
|
1246
1378
|
});
|
|
1247
1379
|
return results;
|
|
1248
1380
|
}
|
|
1381
|
+
/** `io.runTask()` allows you to run a [Task](https://trigger.dev/docs/documentation/concepts/tasks) from inside a Job run. A Task is a resumable unit of a Run that can be retried, resumed and is logged. [Integrations](https://trigger.dev/docs/integrations) use Tasks internally to perform their actions.
|
|
1382
|
+
*
|
|
1383
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1384
|
+
* @param callback The callback that will be called when the Task is run. The callback receives the Task and the IO as parameters.
|
|
1385
|
+
* @param options The options of how you'd like to run and log the Task.
|
|
1386
|
+
* @param onError The callback that will be called when the Task fails. The callback receives the error, the Task and the IO as parameters. If you wish to retry then return an object with a `retryAt` property.
|
|
1387
|
+
* @returns A Promise that resolves with the returned value of the callback.
|
|
1388
|
+
*/
|
|
1249
1389
|
async runTask(cacheKey, callback, options, onError) {
|
|
1250
1390
|
__privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "start_task", 500);
|
|
1251
1391
|
const parentId = this._taskStorage.getStore()?.taskId;
|
|
@@ -1299,14 +1439,14 @@ var IO = class {
|
|
|
1299
1439
|
}, {
|
|
1300
1440
|
cachedTasksCursor: this._cachedTasksCursor
|
|
1301
1441
|
});
|
|
1302
|
-
const task = response.version ===
|
|
1442
|
+
const task = response.version === core.API_VERSIONS.LAZY_LOADED_CACHED_TASKS ? response.body.task : response.body;
|
|
1303
1443
|
if (task.forceYield) {
|
|
1304
1444
|
this._logger.debug("Forcing yield after run task", {
|
|
1305
1445
|
idempotencyKey
|
|
1306
1446
|
});
|
|
1307
1447
|
__privateMethod(this, _forceYield, forceYield_fn).call(this, "after_run_task");
|
|
1308
1448
|
}
|
|
1309
|
-
if (response.version ===
|
|
1449
|
+
if (response.version === core.API_VERSIONS.LAZY_LOADED_CACHED_TASKS) {
|
|
1310
1450
|
this._cachedTasksCursor = response.body.cachedTasks?.cursor;
|
|
1311
1451
|
for (const cachedTask2 of response.body.cachedTasks?.tasks ?? []) {
|
|
1312
1452
|
if (!this._cachedTasks.has(cachedTask2.idempotencyKey)) {
|
|
@@ -1395,7 +1535,7 @@ var IO = class {
|
|
|
1395
1535
|
} else {
|
|
1396
1536
|
skipRetrying = !!onErrorResult.skipRetrying;
|
|
1397
1537
|
if (onErrorResult.retryAt && !skipRetrying) {
|
|
1398
|
-
const parsedError2 =
|
|
1538
|
+
const parsedError2 = core.ErrorWithStackSchema.safeParse(onErrorResult.error);
|
|
1399
1539
|
throw new RetryWithTaskError(parsedError2.success ? parsedError2.data : {
|
|
1400
1540
|
message: "Unknown error"
|
|
1401
1541
|
}, task, onErrorResult.retryAt);
|
|
@@ -1414,9 +1554,9 @@ var IO = class {
|
|
|
1414
1554
|
error: error.cause.output
|
|
1415
1555
|
});
|
|
1416
1556
|
}
|
|
1417
|
-
const parsedError =
|
|
1557
|
+
const parsedError = core.ErrorWithStackSchema.safeParse(error);
|
|
1418
1558
|
if (options?.retry && !skipRetrying) {
|
|
1419
|
-
const retryAt =
|
|
1559
|
+
const retryAt = core.calculateRetryAt(options.retry, task.attempts - 1);
|
|
1420
1560
|
if (retryAt) {
|
|
1421
1561
|
throw new RetryWithTaskError(parsedError.success ? parsedError.data : {
|
|
1422
1562
|
message: "Unknown error"
|
|
@@ -1462,8 +1602,11 @@ var IO = class {
|
|
|
1462
1602
|
taskId: task.id
|
|
1463
1603
|
}, executeTask);
|
|
1464
1604
|
}
|
|
1605
|
+
/**
|
|
1606
|
+
* `io.yield()` allows you to yield execution of the current run and resume it in a new function execution. Similar to `io.wait()` but does not create a task and resumes execution immediately.
|
|
1607
|
+
*/
|
|
1465
1608
|
yield(cacheKey) {
|
|
1466
|
-
if (!
|
|
1609
|
+
if (!core.supportsFeature("yieldExecution", this._serverVersion)) {
|
|
1467
1610
|
console.warn("[trigger.dev] io.yield() is not support by the version of the Trigger.dev server you are using, you will need to upgrade your self-hosted Trigger.dev instance.");
|
|
1468
1611
|
return;
|
|
1469
1612
|
}
|
|
@@ -1472,6 +1615,12 @@ var IO = class {
|
|
|
1472
1615
|
}
|
|
1473
1616
|
throw new YieldExecutionError(cacheKey);
|
|
1474
1617
|
}
|
|
1618
|
+
/** `io.try()` allows you to run Tasks and catch any errors that are thrown, it's similar to a normal `try/catch` block but works with [io.runTask()](https://trigger.dev/docs/sdk/io/runtask).
|
|
1619
|
+
* A regular `try/catch` block on its own won't work as expected with Tasks. Internally `runTask()` throws some special errors to control flow execution. This is necessary to deal with resumability, serverless timeouts, and retrying Tasks.
|
|
1620
|
+
* @param tryCallback The code you wish to run
|
|
1621
|
+
* @param catchCallback Thhis will be called if the Task fails. The callback receives the error
|
|
1622
|
+
* @returns A Promise that resolves with the returned value or the error
|
|
1623
|
+
*/
|
|
1475
1624
|
async try(tryCallback, catchCallback) {
|
|
1476
1625
|
try {
|
|
1477
1626
|
return await tryCallback();
|
|
@@ -1490,7 +1639,6 @@ var IO = class {
|
|
|
1490
1639
|
};
|
|
1491
1640
|
}
|
|
1492
1641
|
};
|
|
1493
|
-
__name(IO, "IO");
|
|
1494
1642
|
_addToCachedTasks = new WeakSet();
|
|
1495
1643
|
addToCachedTasks_fn = /* @__PURE__ */ __name(function(task) {
|
|
1496
1644
|
this._cachedTasks.set(task.idempotencyKey, task);
|
|
@@ -1528,6 +1676,8 @@ getRemainingTimeInMillis_fn = /* @__PURE__ */ __name(function() {
|
|
|
1528
1676
|
}
|
|
1529
1677
|
return void 0;
|
|
1530
1678
|
}, "#getRemainingTimeInMillis");
|
|
1679
|
+
__name(_IO, "IO");
|
|
1680
|
+
var IO = _IO;
|
|
1531
1681
|
async function generateIdempotencyKey(keyMaterial) {
|
|
1532
1682
|
const keys = keyMaterial.map((key2) => {
|
|
1533
1683
|
if (typeof key2 === "string") {
|
|
@@ -1536,8 +1686,8 @@ async function generateIdempotencyKey(keyMaterial) {
|
|
|
1536
1686
|
return stableStringify(key2);
|
|
1537
1687
|
});
|
|
1538
1688
|
const key = keys.join(":");
|
|
1539
|
-
const hash = await
|
|
1540
|
-
return Buffer.from(hash).toString("hex");
|
|
1689
|
+
const hash = await crypto.webcrypto.subtle.digest("SHA-256", node_buffer.Buffer.from(key));
|
|
1690
|
+
return node_buffer.Buffer.from(hash).toString("hex");
|
|
1541
1691
|
}
|
|
1542
1692
|
__name(generateIdempotencyKey, "generateIdempotencyKey");
|
|
1543
1693
|
function stableStringify(obj) {
|
|
@@ -1560,27 +1710,33 @@ function stableStringify(obj) {
|
|
|
1560
1710
|
return JSON.stringify(sortedObj);
|
|
1561
1711
|
}
|
|
1562
1712
|
__name(stableStringify, "stableStringify");
|
|
1563
|
-
var
|
|
1713
|
+
var _IOLogger = class _IOLogger {
|
|
1564
1714
|
constructor(callback) {
|
|
1565
1715
|
this.callback = callback;
|
|
1566
1716
|
}
|
|
1717
|
+
/** Log: essential messages */
|
|
1567
1718
|
log(message, properties) {
|
|
1568
1719
|
return this.callback("LOG", message, properties);
|
|
1569
1720
|
}
|
|
1721
|
+
/** For debugging: the least important log level */
|
|
1570
1722
|
debug(message, properties) {
|
|
1571
1723
|
return this.callback("DEBUG", message, properties);
|
|
1572
1724
|
}
|
|
1725
|
+
/** Info: the second least important log level */
|
|
1573
1726
|
info(message, properties) {
|
|
1574
1727
|
return this.callback("INFO", message, properties);
|
|
1575
1728
|
}
|
|
1729
|
+
/** Warnings: the third most important log level */
|
|
1576
1730
|
warn(message, properties) {
|
|
1577
1731
|
return this.callback("WARN", message, properties);
|
|
1578
1732
|
}
|
|
1733
|
+
/** Error: The second most important log level */
|
|
1579
1734
|
error(message, properties) {
|
|
1580
1735
|
return this.callback("ERROR", message, properties);
|
|
1581
1736
|
}
|
|
1582
1737
|
};
|
|
1583
|
-
__name(
|
|
1738
|
+
__name(_IOLogger, "IOLogger");
|
|
1739
|
+
var IOLogger = _IOLogger;
|
|
1584
1740
|
async function spaceOut(callback, index, delay) {
|
|
1585
1741
|
await new Promise((resolve) => setTimeout(resolve, index * delay));
|
|
1586
1742
|
return await callback();
|
|
@@ -1612,7 +1768,7 @@ __name(sendEventOptionsProperties, "sendEventOptionsProperties");
|
|
|
1612
1768
|
|
|
1613
1769
|
// src/store/keyValueStoreClient.ts
|
|
1614
1770
|
var _serializer, _namespacedKey2, namespacedKey_fn2;
|
|
1615
|
-
var
|
|
1771
|
+
var _KeyValueStoreClient = class _KeyValueStoreClient {
|
|
1616
1772
|
constructor(queryStore, type = null, namespace = "") {
|
|
1617
1773
|
__privateAdd(this, _namespacedKey2);
|
|
1618
1774
|
__privateAdd(this, _serializer, void 0);
|
|
@@ -1659,7 +1815,6 @@ var KeyValueStoreClient = class {
|
|
|
1659
1815
|
return __privateGet(this, _serializer).deserialize(result.value);
|
|
1660
1816
|
}
|
|
1661
1817
|
};
|
|
1662
|
-
__name(KeyValueStoreClient, "KeyValueStoreClient");
|
|
1663
1818
|
_serializer = new WeakMap();
|
|
1664
1819
|
_namespacedKey2 = new WeakSet();
|
|
1665
1820
|
namespacedKey_fn2 = /* @__PURE__ */ __name(function(key) {
|
|
@@ -1673,10 +1828,12 @@ namespacedKey_fn2 = /* @__PURE__ */ __name(function(key) {
|
|
|
1673
1828
|
parts.push(key);
|
|
1674
1829
|
return parts.join(":");
|
|
1675
1830
|
}, "#namespacedKey");
|
|
1831
|
+
__name(_KeyValueStoreClient, "KeyValueStoreClient");
|
|
1832
|
+
var KeyValueStoreClient = _KeyValueStoreClient;
|
|
1676
1833
|
|
|
1677
1834
|
// src/apiClient.ts
|
|
1678
1835
|
var _apiUrl, _options, _logger, _storeClient, _queryKeyValueStore, queryKeyValueStore_fn, _apiKey, apiKey_fn;
|
|
1679
|
-
var
|
|
1836
|
+
var _ApiClient = class _ApiClient {
|
|
1680
1837
|
constructor(options) {
|
|
1681
1838
|
__privateAdd(this, _queryKeyValueStore);
|
|
1682
1839
|
__privateAdd(this, _apiKey);
|
|
@@ -1685,8 +1842,8 @@ var ApiClient = class {
|
|
|
1685
1842
|
__privateAdd(this, _logger, void 0);
|
|
1686
1843
|
__privateAdd(this, _storeClient, void 0);
|
|
1687
1844
|
__privateSet(this, _options, options);
|
|
1688
|
-
__privateSet(this, _apiUrl, __privateGet(this, _options).apiUrl ??
|
|
1689
|
-
__privateSet(this, _logger, new
|
|
1845
|
+
__privateSet(this, _apiUrl, __privateGet(this, _options).apiUrl ?? node_process.env.TRIGGER_API_URL ?? "https://api.trigger.dev");
|
|
1846
|
+
__privateSet(this, _logger, new coreBackend.Logger("trigger.dev", __privateGet(this, _options).logLevel));
|
|
1690
1847
|
__privateSet(this, _storeClient, new KeyValueStoreClient(__privateMethod(this, _queryKeyValueStore, queryKeyValueStore_fn).bind(this)));
|
|
1691
1848
|
}
|
|
1692
1849
|
async registerEndpoint(options) {
|
|
@@ -1721,15 +1878,15 @@ var ApiClient = class {
|
|
|
1721
1878
|
task
|
|
1722
1879
|
});
|
|
1723
1880
|
return await zodfetchWithVersions({
|
|
1724
|
-
[
|
|
1725
|
-
},
|
|
1881
|
+
[core.API_VERSIONS.LAZY_LOADED_CACHED_TASKS]: core.RunTaskResponseWithCachedTasksBodySchema
|
|
1882
|
+
}, core.ServerTaskSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/tasks`, {
|
|
1726
1883
|
method: "POST",
|
|
1727
1884
|
headers: {
|
|
1728
1885
|
"Content-Type": "application/json",
|
|
1729
1886
|
Authorization: `Bearer ${apiKey}`,
|
|
1730
1887
|
"Idempotency-Key": task.idempotencyKey,
|
|
1731
1888
|
"X-Cached-Tasks-Cursor": options.cachedTasksCursor ?? "",
|
|
1732
|
-
"Trigger-Version":
|
|
1889
|
+
"Trigger-Version": core.API_VERSIONS.LAZY_LOADED_CACHED_TASKS
|
|
1733
1890
|
},
|
|
1734
1891
|
body: JSON.stringify(task)
|
|
1735
1892
|
});
|
|
@@ -1739,12 +1896,12 @@ var ApiClient = class {
|
|
|
1739
1896
|
__privateGet(this, _logger).debug("Complete Task", {
|
|
1740
1897
|
task
|
|
1741
1898
|
});
|
|
1742
|
-
return await zodfetch(
|
|
1899
|
+
return await zodfetch(core.ServerTaskSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/tasks/${id}/complete`, {
|
|
1743
1900
|
method: "POST",
|
|
1744
1901
|
headers: {
|
|
1745
1902
|
"Content-Type": "application/json",
|
|
1746
1903
|
Authorization: `Bearer ${apiKey}`,
|
|
1747
|
-
"Trigger-Version":
|
|
1904
|
+
"Trigger-Version": core.API_VERSIONS.SERIALIZED_TASK_OUTPUT
|
|
1748
1905
|
},
|
|
1749
1906
|
body: JSON.stringify(task)
|
|
1750
1907
|
});
|
|
@@ -1756,7 +1913,7 @@ var ApiClient = class {
|
|
|
1756
1913
|
runId,
|
|
1757
1914
|
body
|
|
1758
1915
|
});
|
|
1759
|
-
return await zodfetch(
|
|
1916
|
+
return await zodfetch(core.ServerTaskSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/tasks/${id}/fail`, {
|
|
1760
1917
|
method: "POST",
|
|
1761
1918
|
headers: {
|
|
1762
1919
|
"Content-Type": "application/json",
|
|
@@ -1770,7 +1927,7 @@ var ApiClient = class {
|
|
|
1770
1927
|
__privateGet(this, _logger).debug("Sending event", {
|
|
1771
1928
|
event
|
|
1772
1929
|
});
|
|
1773
|
-
return await zodfetch(
|
|
1930
|
+
return await zodfetch(core.ApiEventLogSchema, `${__privateGet(this, _apiUrl)}/api/v1/events`, {
|
|
1774
1931
|
method: "POST",
|
|
1775
1932
|
headers: {
|
|
1776
1933
|
"Content-Type": "application/json",
|
|
@@ -1787,7 +1944,7 @@ var ApiClient = class {
|
|
|
1787
1944
|
__privateGet(this, _logger).debug("Sending multiple events", {
|
|
1788
1945
|
events
|
|
1789
1946
|
});
|
|
1790
|
-
return await zodfetch(
|
|
1947
|
+
return await zodfetch(core.ApiEventLogSchema.array(), `${__privateGet(this, _apiUrl)}/api/v1/events/bulk`, {
|
|
1791
1948
|
method: "POST",
|
|
1792
1949
|
headers: {
|
|
1793
1950
|
"Content-Type": "application/json",
|
|
@@ -1804,7 +1961,7 @@ var ApiClient = class {
|
|
|
1804
1961
|
__privateGet(this, _logger).debug("Cancelling event", {
|
|
1805
1962
|
eventId
|
|
1806
1963
|
});
|
|
1807
|
-
return await zodfetch(
|
|
1964
|
+
return await zodfetch(core.ApiEventLogSchema, `${__privateGet(this, _apiUrl)}/api/v1/events/${eventId}/cancel`, {
|
|
1808
1965
|
method: "POST",
|
|
1809
1966
|
headers: {
|
|
1810
1967
|
"Content-Type": "application/json",
|
|
@@ -1817,7 +1974,7 @@ var ApiClient = class {
|
|
|
1817
1974
|
__privateGet(this, _logger).debug("Cancelling runs for event", {
|
|
1818
1975
|
eventId
|
|
1819
1976
|
});
|
|
1820
|
-
return await zodfetch(
|
|
1977
|
+
return await zodfetch(core.CancelRunsForEventSchema, `${__privateGet(this, _apiUrl)}/api/v1/events/${eventId}/cancel-runs`, {
|
|
1821
1978
|
method: "POST",
|
|
1822
1979
|
headers: {
|
|
1823
1980
|
"Content-Type": "application/json",
|
|
@@ -1831,7 +1988,7 @@ var ApiClient = class {
|
|
|
1831
1988
|
id,
|
|
1832
1989
|
status
|
|
1833
1990
|
});
|
|
1834
|
-
return await zodfetch(
|
|
1991
|
+
return await zodfetch(core.JobRunStatusRecordSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/statuses/${id}`, {
|
|
1835
1992
|
method: "PUT",
|
|
1836
1993
|
headers: {
|
|
1837
1994
|
"Content-Type": "application/json",
|
|
@@ -1845,7 +2002,7 @@ var ApiClient = class {
|
|
|
1845
2002
|
__privateGet(this, _logger).debug("activating http source", {
|
|
1846
2003
|
source
|
|
1847
2004
|
});
|
|
1848
|
-
const response = await zodfetch(
|
|
2005
|
+
const response = await zodfetch(core.TriggerSourceSchema, `${__privateGet(this, _apiUrl)}/api/v2/${client}/sources/${key}`, {
|
|
1849
2006
|
method: "PUT",
|
|
1850
2007
|
headers: {
|
|
1851
2008
|
"Content-Type": "application/json",
|
|
@@ -1860,7 +2017,7 @@ var ApiClient = class {
|
|
|
1860
2017
|
__privateGet(this, _logger).debug("activating webhook", {
|
|
1861
2018
|
webhookData
|
|
1862
2019
|
});
|
|
1863
|
-
const response = await zodfetch(
|
|
2020
|
+
const response = await zodfetch(core.TriggerSourceSchema, `${__privateGet(this, _apiUrl)}/api/v1/webhooks/${key}`, {
|
|
1864
2021
|
method: "PUT",
|
|
1865
2022
|
headers: {
|
|
1866
2023
|
"Content-Type": "application/json",
|
|
@@ -1883,7 +2040,7 @@ var ApiClient = class {
|
|
|
1883
2040
|
if (idempotencyKey) {
|
|
1884
2041
|
headers["Idempotency-Key"] = idempotencyKey;
|
|
1885
2042
|
}
|
|
1886
|
-
const response = await zodfetch(
|
|
2043
|
+
const response = await zodfetch(core.RegisterSourceEventSchemaV2, `${__privateGet(this, _apiUrl)}/api/v2/${client}/triggers/${id}/registrations/${key}`, {
|
|
1887
2044
|
method: "PUT",
|
|
1888
2045
|
headers,
|
|
1889
2046
|
body: JSON.stringify(payload)
|
|
@@ -1896,7 +2053,7 @@ var ApiClient = class {
|
|
|
1896
2053
|
id,
|
|
1897
2054
|
payload
|
|
1898
2055
|
});
|
|
1899
|
-
const response = await zodfetch(
|
|
2056
|
+
const response = await zodfetch(core.RegisterScheduleResponseBodySchema, `${__privateGet(this, _apiUrl)}/api/v1/${client}/schedules/${id}/registrations`, {
|
|
1900
2057
|
method: "POST",
|
|
1901
2058
|
headers: {
|
|
1902
2059
|
"Content-Type": "application/json",
|
|
@@ -1914,8 +2071,8 @@ var ApiClient = class {
|
|
|
1914
2071
|
__privateGet(this, _logger).debug("unregistering schedule", {
|
|
1915
2072
|
id
|
|
1916
2073
|
});
|
|
1917
|
-
const response = await zodfetch(
|
|
1918
|
-
ok:
|
|
2074
|
+
const response = await zodfetch(zod.z.object({
|
|
2075
|
+
ok: zod.z.boolean()
|
|
1919
2076
|
}), `${__privateGet(this, _apiUrl)}/api/v1/${client}/schedules/${id}/registrations/${encodeURIComponent(key)}`, {
|
|
1920
2077
|
method: "DELETE",
|
|
1921
2078
|
headers: {
|
|
@@ -1930,7 +2087,7 @@ var ApiClient = class {
|
|
|
1930
2087
|
__privateGet(this, _logger).debug("getting auth", {
|
|
1931
2088
|
id
|
|
1932
2089
|
});
|
|
1933
|
-
const response = await zodfetch(
|
|
2090
|
+
const response = await zodfetch(core.ConnectionAuthSchema, `${__privateGet(this, _apiUrl)}/api/v1/${client}/auth/${id}`, {
|
|
1934
2091
|
method: "GET",
|
|
1935
2092
|
headers: {
|
|
1936
2093
|
Accept: "application/json",
|
|
@@ -1946,7 +2103,7 @@ var ApiClient = class {
|
|
|
1946
2103
|
__privateGet(this, _logger).debug("Getting Event", {
|
|
1947
2104
|
eventId
|
|
1948
2105
|
});
|
|
1949
|
-
return await zodfetch(
|
|
2106
|
+
return await zodfetch(core.GetEventSchema, `${__privateGet(this, _apiUrl)}/api/v1/events/${eventId}`, {
|
|
1950
2107
|
method: "GET",
|
|
1951
2108
|
headers: {
|
|
1952
2109
|
Authorization: `Bearer ${apiKey}`
|
|
@@ -1958,7 +2115,7 @@ var ApiClient = class {
|
|
|
1958
2115
|
__privateGet(this, _logger).debug("Getting Run", {
|
|
1959
2116
|
runId
|
|
1960
2117
|
});
|
|
1961
|
-
return await zodfetch(
|
|
2118
|
+
return await zodfetch(core.GetRunSchema, core.urlWithSearchParams(`${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}`, options), {
|
|
1962
2119
|
method: "GET",
|
|
1963
2120
|
headers: {
|
|
1964
2121
|
Authorization: `Bearer ${apiKey}`
|
|
@@ -1970,7 +2127,7 @@ var ApiClient = class {
|
|
|
1970
2127
|
__privateGet(this, _logger).debug("Cancelling Run", {
|
|
1971
2128
|
runId
|
|
1972
2129
|
});
|
|
1973
|
-
return await zodfetch(
|
|
2130
|
+
return await zodfetch(core.GetRunSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/cancel`, {
|
|
1974
2131
|
method: "POST",
|
|
1975
2132
|
headers: {
|
|
1976
2133
|
"Content-Type": "application/json",
|
|
@@ -1983,7 +2140,7 @@ var ApiClient = class {
|
|
|
1983
2140
|
__privateGet(this, _logger).debug("Getting Run statuses", {
|
|
1984
2141
|
runId
|
|
1985
2142
|
});
|
|
1986
|
-
return await zodfetch(
|
|
2143
|
+
return await zodfetch(core.GetRunStatusesSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/statuses`, {
|
|
1987
2144
|
method: "GET",
|
|
1988
2145
|
headers: {
|
|
1989
2146
|
Authorization: `Bearer ${apiKey}`
|
|
@@ -1995,7 +2152,7 @@ var ApiClient = class {
|
|
|
1995
2152
|
__privateGet(this, _logger).debug("Getting Runs", {
|
|
1996
2153
|
jobSlug
|
|
1997
2154
|
});
|
|
1998
|
-
return await zodfetch(
|
|
2155
|
+
return await zodfetch(core.GetRunsSchema, core.urlWithSearchParams(`${__privateGet(this, _apiUrl)}/api/v1/jobs/${jobSlug}/runs`, options), {
|
|
1999
2156
|
method: "GET",
|
|
2000
2157
|
headers: {
|
|
2001
2158
|
Authorization: `Bearer ${apiKey}`
|
|
@@ -2015,7 +2172,7 @@ var ApiClient = class {
|
|
|
2015
2172
|
callbackUrl: options.callbackUrl
|
|
2016
2173
|
}
|
|
2017
2174
|
};
|
|
2018
|
-
return await zodfetch(
|
|
2175
|
+
return await zodfetch(core.InvokeJobResponseSchema, `${__privateGet(this, _apiUrl)}/api/v1/jobs/${jobId}/invoke`, {
|
|
2019
2176
|
method: "POST",
|
|
2020
2177
|
headers: {
|
|
2021
2178
|
"Content-Type": "application/json",
|
|
@@ -2032,7 +2189,7 @@ var ApiClient = class {
|
|
|
2032
2189
|
__privateGet(this, _logger).debug("Creating ephemeral event dispatcher", {
|
|
2033
2190
|
payload
|
|
2034
2191
|
});
|
|
2035
|
-
const response = await zodfetch(
|
|
2192
|
+
const response = await zodfetch(core.EphemeralEventDispatcherResponseBodySchema, `${__privateGet(this, _apiUrl)}/api/v1/event-dispatchers/ephemeral`, {
|
|
2036
2193
|
method: "POST",
|
|
2037
2194
|
headers: {
|
|
2038
2195
|
"Content-Type": "application/json",
|
|
@@ -2046,7 +2203,6 @@ var ApiClient = class {
|
|
|
2046
2203
|
return __privateGet(this, _storeClient);
|
|
2047
2204
|
}
|
|
2048
2205
|
};
|
|
2049
|
-
__name(ApiClient, "ApiClient");
|
|
2050
2206
|
_apiUrl = new WeakMap();
|
|
2051
2207
|
_options = new WeakMap();
|
|
2052
2208
|
_logger = new WeakMap();
|
|
@@ -2105,10 +2261,10 @@ queryKeyValueStore_fn = /* @__PURE__ */ __name(async function(action, data) {
|
|
|
2105
2261
|
break;
|
|
2106
2262
|
}
|
|
2107
2263
|
default: {
|
|
2108
|
-
|
|
2264
|
+
core.assertExhaustive(action);
|
|
2109
2265
|
}
|
|
2110
2266
|
}
|
|
2111
|
-
const response = await zodfetch(
|
|
2267
|
+
const response = await zodfetch(core.KeyValueStoreResponseBodySchema, STORE_URL, requestInit);
|
|
2112
2268
|
return response;
|
|
2113
2269
|
}, "#queryKeyValueStore");
|
|
2114
2270
|
_apiKey = new WeakSet();
|
|
@@ -2121,8 +2277,10 @@ apiKey_fn = /* @__PURE__ */ __name(async function() {
|
|
|
2121
2277
|
}
|
|
2122
2278
|
return apiKey.apiKey;
|
|
2123
2279
|
}, "#apiKey");
|
|
2280
|
+
__name(_ApiClient, "ApiClient");
|
|
2281
|
+
var ApiClient = _ApiClient;
|
|
2124
2282
|
function getApiKey(key) {
|
|
2125
|
-
const apiKey = key ??
|
|
2283
|
+
const apiKey = key ?? node_process.env.TRIGGER_API_KEY;
|
|
2126
2284
|
if (!apiKey) {
|
|
2127
2285
|
return {
|
|
2128
2286
|
status: "missing"
|
|
@@ -2142,10 +2300,7 @@ function getApiKey(key) {
|
|
|
2142
2300
|
}
|
|
2143
2301
|
__name(getApiKey, "getApiKey");
|
|
2144
2302
|
async function zodfetchWithVersions(versionedSchemaMap, unversionedSchema, url, requestInit, options, retryCount = 0) {
|
|
2145
|
-
const response = await fetch(url,
|
|
2146
|
-
...requestInit,
|
|
2147
|
-
cache: "no-cache"
|
|
2148
|
-
});
|
|
2303
|
+
const response = await fetch(url, requestInitWithCache(requestInit));
|
|
2149
2304
|
if ((!requestInit || requestInit.method === "GET") && response.status === 404 && options?.optional) {
|
|
2150
2305
|
return;
|
|
2151
2306
|
}
|
|
@@ -2179,15 +2334,25 @@ async function zodfetchWithVersions(versionedSchemaMap, unversionedSchema, url,
|
|
|
2179
2334
|
};
|
|
2180
2335
|
}
|
|
2181
2336
|
__name(zodfetchWithVersions, "zodfetchWithVersions");
|
|
2337
|
+
function requestInitWithCache(requestInit) {
|
|
2338
|
+
try {
|
|
2339
|
+
const withCache = {
|
|
2340
|
+
...requestInit,
|
|
2341
|
+
cache: "no-cache"
|
|
2342
|
+
};
|
|
2343
|
+
const _ = new Request("http://localhost", withCache);
|
|
2344
|
+
return withCache;
|
|
2345
|
+
} catch (error) {
|
|
2346
|
+
return requestInit ?? {};
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
__name(requestInitWithCache, "requestInitWithCache");
|
|
2182
2350
|
async function fetchHead(url, requestInitWithoutMethod, retryCount = 0) {
|
|
2183
2351
|
const requestInit = {
|
|
2184
2352
|
...requestInitWithoutMethod,
|
|
2185
2353
|
method: "HEAD"
|
|
2186
2354
|
};
|
|
2187
|
-
const response = await fetch(url,
|
|
2188
|
-
...requestInit,
|
|
2189
|
-
cache: "no-cache"
|
|
2190
|
-
});
|
|
2355
|
+
const response = await fetch(url, requestInitWithCache(requestInit));
|
|
2191
2356
|
if (response.status >= 500 && retryCount < 6) {
|
|
2192
2357
|
const delay = exponentialBackoff(retryCount + 1, 2, 50, 1150, 50);
|
|
2193
2358
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
@@ -2197,10 +2362,7 @@ async function fetchHead(url, requestInitWithoutMethod, retryCount = 0) {
|
|
|
2197
2362
|
}
|
|
2198
2363
|
__name(fetchHead, "fetchHead");
|
|
2199
2364
|
async function zodfetch(schema, url, requestInit, options, retryCount = 0) {
|
|
2200
|
-
const response = await fetch(url,
|
|
2201
|
-
...requestInit,
|
|
2202
|
-
cache: "no-cache"
|
|
2203
|
-
});
|
|
2365
|
+
const response = await fetch(url, requestInitWithCache(requestInit));
|
|
2204
2366
|
if ((!requestInit || requestInit.method === "GET") && response.status === 404 && options?.optional) {
|
|
2205
2367
|
return;
|
|
2206
2368
|
}
|
|
@@ -2227,8 +2389,20 @@ function exponentialBackoff(retryCount, exponential, minDelay, maxDelay, jitter)
|
|
|
2227
2389
|
}
|
|
2228
2390
|
__name(exponentialBackoff, "exponentialBackoff");
|
|
2229
2391
|
|
|
2230
|
-
// src/
|
|
2231
|
-
var
|
|
2392
|
+
// src/concurrencyLimit.ts
|
|
2393
|
+
var _ConcurrencyLimit = class _ConcurrencyLimit {
|
|
2394
|
+
constructor(options) {
|
|
2395
|
+
this.options = options;
|
|
2396
|
+
}
|
|
2397
|
+
get id() {
|
|
2398
|
+
return this.options.id;
|
|
2399
|
+
}
|
|
2400
|
+
get limit() {
|
|
2401
|
+
return this.options.limit;
|
|
2402
|
+
}
|
|
2403
|
+
};
|
|
2404
|
+
__name(_ConcurrencyLimit, "ConcurrencyLimit");
|
|
2405
|
+
var ConcurrencyLimit = _ConcurrencyLimit;
|
|
2232
2406
|
|
|
2233
2407
|
// src/utils/formatSchemaErrors.ts
|
|
2234
2408
|
function formatSchemaErrors(errors) {
|
|
@@ -2243,7 +2417,7 @@ function formatSchemaErrors(errors) {
|
|
|
2243
2417
|
__name(formatSchemaErrors, "formatSchemaErrors");
|
|
2244
2418
|
|
|
2245
2419
|
// src/httpEndpoint.ts
|
|
2246
|
-
var
|
|
2420
|
+
var _HttpEndpoint = class _HttpEndpoint {
|
|
2247
2421
|
constructor(options) {
|
|
2248
2422
|
this.options = options;
|
|
2249
2423
|
}
|
|
@@ -2258,6 +2432,7 @@ var HttpEndpoint = class {
|
|
|
2258
2432
|
verify: this.options.verify
|
|
2259
2433
|
});
|
|
2260
2434
|
}
|
|
2435
|
+
// @internal
|
|
2261
2436
|
async handleRequest(request) {
|
|
2262
2437
|
if (!this.options.respondWith)
|
|
2263
2438
|
return;
|
|
@@ -2279,8 +2454,10 @@ var HttpEndpoint = class {
|
|
|
2279
2454
|
};
|
|
2280
2455
|
}
|
|
2281
2456
|
};
|
|
2282
|
-
__name(
|
|
2283
|
-
var
|
|
2457
|
+
__name(_HttpEndpoint, "HttpEndpoint");
|
|
2458
|
+
var HttpEndpoint = _HttpEndpoint;
|
|
2459
|
+
var _a;
|
|
2460
|
+
var HttpTrigger = (_a = class {
|
|
2284
2461
|
constructor(options) {
|
|
2285
2462
|
this.options = options;
|
|
2286
2463
|
}
|
|
@@ -2315,7 +2492,7 @@ var HttpTrigger = /* @__PURE__ */ __name(class HttpTrigger2 {
|
|
|
2315
2492
|
const clonedRequest = payload.clone();
|
|
2316
2493
|
return this.options.verify(clonedRequest);
|
|
2317
2494
|
}
|
|
2318
|
-
}, "HttpTrigger");
|
|
2495
|
+
}, __name(_a, "HttpTrigger"), _a);
|
|
2319
2496
|
function httpEndpoint(options) {
|
|
2320
2497
|
const id = slugifyId(options.id);
|
|
2321
2498
|
return new HttpEndpoint({
|
|
@@ -2347,7 +2524,7 @@ function httpEndpoint(options) {
|
|
|
2347
2524
|
}
|
|
2348
2525
|
],
|
|
2349
2526
|
parsePayload: (rawPayload) => {
|
|
2350
|
-
const result =
|
|
2527
|
+
const result = core.RequestWithRawBodySchema.safeParse(rawPayload);
|
|
2351
2528
|
if (!result.success) {
|
|
2352
2529
|
throw new ParsedPayloadSchemaError(formatSchemaErrors(result.error.issues));
|
|
2353
2530
|
}
|
|
@@ -2390,11 +2567,12 @@ function createIOWithIntegrations(io, auths, integrations) {
|
|
|
2390
2567
|
});
|
|
2391
2568
|
}
|
|
2392
2569
|
__name(createIOWithIntegrations, "createIOWithIntegrations");
|
|
2393
|
-
|
|
2394
|
-
// src/triggers/dynamic.ts
|
|
2395
|
-
var import_core5 = require("@trigger.dev/core");
|
|
2396
2570
|
var _client, _options2;
|
|
2397
|
-
var
|
|
2571
|
+
var _DynamicTrigger = class _DynamicTrigger {
|
|
2572
|
+
/** `DynamicTrigger` allows you to define a trigger that can be configured dynamically at runtime.
|
|
2573
|
+
* @param client The `TriggerClient` instance to use for registering the trigger.
|
|
2574
|
+
* @param options The options for the dynamic trigger.
|
|
2575
|
+
* */
|
|
2398
2576
|
constructor(client, options) {
|
|
2399
2577
|
__privateAdd(this, _client, void 0);
|
|
2400
2578
|
__privateAdd(this, _options2, void 0);
|
|
@@ -2415,19 +2593,21 @@ var DynamicTrigger = class {
|
|
|
2415
2593
|
get event() {
|
|
2416
2594
|
return __privateGet(this, _options2).event;
|
|
2417
2595
|
}
|
|
2596
|
+
// @internal
|
|
2418
2597
|
registeredTriggerForParams(params, options = {}) {
|
|
2419
2598
|
const key = slugifyId(this.source.key(params));
|
|
2420
2599
|
return {
|
|
2421
2600
|
rule: {
|
|
2422
2601
|
event: this.event.name,
|
|
2423
2602
|
source: this.event.source,
|
|
2424
|
-
payload:
|
|
2603
|
+
payload: core.deepMergeFilters(this.source.filter(params), this.event.filter ?? {}, options.filter ?? {})
|
|
2425
2604
|
},
|
|
2426
2605
|
source: {
|
|
2427
2606
|
version: "2",
|
|
2428
2607
|
key,
|
|
2429
2608
|
channel: this.source.channel,
|
|
2430
2609
|
params,
|
|
2610
|
+
//todo add other options here
|
|
2431
2611
|
options: {
|
|
2432
2612
|
event: typeof this.event.name === "string" ? [
|
|
2433
2613
|
this.event.name
|
|
@@ -2442,6 +2622,14 @@ var DynamicTrigger = class {
|
|
|
2442
2622
|
accountId: options.accountId
|
|
2443
2623
|
};
|
|
2444
2624
|
}
|
|
2625
|
+
/** Use this method to register a new configuration with the DynamicTrigger.
|
|
2626
|
+
* @param key The key for the configuration. This will be used to identify the configuration when it is triggered.
|
|
2627
|
+
* @param params The params for the configuration.
|
|
2628
|
+
* @param options Options for the configuration.
|
|
2629
|
+
* @param options.accountId The accountId to associate with the configuration.
|
|
2630
|
+
* @param options.filter The filter to use for the configuration.
|
|
2631
|
+
*
|
|
2632
|
+
*/
|
|
2445
2633
|
async register(key, params, options = {}) {
|
|
2446
2634
|
const runStore = runLocalStorage.getStore();
|
|
2447
2635
|
if (!runStore) {
|
|
@@ -2480,14 +2668,12 @@ var DynamicTrigger = class {
|
|
|
2480
2668
|
};
|
|
2481
2669
|
}
|
|
2482
2670
|
};
|
|
2483
|
-
__name(DynamicTrigger, "DynamicTrigger");
|
|
2484
2671
|
_client = new WeakMap();
|
|
2485
2672
|
_options2 = new WeakMap();
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
var import_core6 = require("@trigger.dev/core");
|
|
2673
|
+
__name(_DynamicTrigger, "DynamicTrigger");
|
|
2674
|
+
var DynamicTrigger = _DynamicTrigger;
|
|
2489
2675
|
var _options3;
|
|
2490
|
-
var
|
|
2676
|
+
var _EventTrigger = class _EventTrigger {
|
|
2491
2677
|
constructor(options) {
|
|
2492
2678
|
__privateAdd(this, _options3, void 0);
|
|
2493
2679
|
__privateSet(this, _options3, options);
|
|
@@ -2499,7 +2685,7 @@ var EventTrigger = class {
|
|
|
2499
2685
|
rule: {
|
|
2500
2686
|
event: __privateGet(this, _options3).name ?? __privateGet(this, _options3).event.name,
|
|
2501
2687
|
source: __privateGet(this, _options3).source ?? "trigger.dev",
|
|
2502
|
-
payload:
|
|
2688
|
+
payload: core.deepMergeFilters(__privateGet(this, _options3).filter ?? {}, __privateGet(this, _options3).event.filter ?? {})
|
|
2503
2689
|
}
|
|
2504
2690
|
};
|
|
2505
2691
|
}
|
|
@@ -2523,8 +2709,9 @@ var EventTrigger = class {
|
|
|
2523
2709
|
};
|
|
2524
2710
|
}
|
|
2525
2711
|
};
|
|
2526
|
-
__name(EventTrigger, "EventTrigger");
|
|
2527
2712
|
_options3 = new WeakMap();
|
|
2713
|
+
__name(_EventTrigger, "EventTrigger");
|
|
2714
|
+
var EventTrigger = _EventTrigger;
|
|
2528
2715
|
function eventTrigger(options) {
|
|
2529
2716
|
return new EventTrigger({
|
|
2530
2717
|
name: options.name,
|
|
@@ -2549,22 +2736,18 @@ function eventTrigger(options) {
|
|
|
2549
2736
|
});
|
|
2550
2737
|
}
|
|
2551
2738
|
__name(eventTrigger, "eventTrigger");
|
|
2552
|
-
|
|
2553
|
-
// src/triggers/scheduled.ts
|
|
2554
|
-
var import_core7 = require("@trigger.dev/core");
|
|
2555
|
-
var import_cronstrue = __toESM(require("cronstrue"));
|
|
2556
2739
|
var examples = [
|
|
2557
2740
|
{
|
|
2558
2741
|
id: "now",
|
|
2559
2742
|
name: "Now",
|
|
2560
2743
|
icon: "clock",
|
|
2561
2744
|
payload: {
|
|
2562
|
-
ts:
|
|
2563
|
-
lastTimestamp:
|
|
2745
|
+
ts: core.currentDate.marker,
|
|
2746
|
+
lastTimestamp: core.currentDate.marker
|
|
2564
2747
|
}
|
|
2565
2748
|
}
|
|
2566
2749
|
];
|
|
2567
|
-
var
|
|
2750
|
+
var _IntervalTrigger = class _IntervalTrigger {
|
|
2568
2751
|
constructor(options) {
|
|
2569
2752
|
this.options = options;
|
|
2570
2753
|
}
|
|
@@ -2575,7 +2758,7 @@ var IntervalTrigger = class {
|
|
|
2575
2758
|
source: "trigger.dev",
|
|
2576
2759
|
icon: "schedule-interval",
|
|
2577
2760
|
examples,
|
|
2578
|
-
parsePayload:
|
|
2761
|
+
parsePayload: core.ScheduledPayloadSchema.parse,
|
|
2579
2762
|
properties: [
|
|
2580
2763
|
{
|
|
2581
2764
|
label: "Interval",
|
|
@@ -2606,17 +2789,18 @@ var IntervalTrigger = class {
|
|
|
2606
2789
|
};
|
|
2607
2790
|
}
|
|
2608
2791
|
};
|
|
2609
|
-
__name(
|
|
2792
|
+
__name(_IntervalTrigger, "IntervalTrigger");
|
|
2793
|
+
var IntervalTrigger = _IntervalTrigger;
|
|
2610
2794
|
function intervalTrigger(options) {
|
|
2611
2795
|
return new IntervalTrigger(options);
|
|
2612
2796
|
}
|
|
2613
2797
|
__name(intervalTrigger, "intervalTrigger");
|
|
2614
|
-
var
|
|
2798
|
+
var _CronTrigger = class _CronTrigger {
|
|
2615
2799
|
constructor(options) {
|
|
2616
2800
|
this.options = options;
|
|
2617
2801
|
}
|
|
2618
2802
|
get event() {
|
|
2619
|
-
const humanReadable =
|
|
2803
|
+
const humanReadable = cronstrue__default.default.toString(this.options.cron, {
|
|
2620
2804
|
throwExceptionOnParseError: false
|
|
2621
2805
|
});
|
|
2622
2806
|
return {
|
|
@@ -2625,7 +2809,7 @@ var CronTrigger = class {
|
|
|
2625
2809
|
source: "trigger.dev",
|
|
2626
2810
|
icon: "schedule-cron",
|
|
2627
2811
|
examples,
|
|
2628
|
-
parsePayload:
|
|
2812
|
+
parsePayload: core.ScheduledPayloadSchema.parse,
|
|
2629
2813
|
properties: [
|
|
2630
2814
|
{
|
|
2631
2815
|
label: "cron",
|
|
@@ -2660,12 +2844,17 @@ var CronTrigger = class {
|
|
|
2660
2844
|
};
|
|
2661
2845
|
}
|
|
2662
2846
|
};
|
|
2663
|
-
__name(
|
|
2847
|
+
__name(_CronTrigger, "CronTrigger");
|
|
2848
|
+
var CronTrigger = _CronTrigger;
|
|
2664
2849
|
function cronTrigger(options) {
|
|
2665
2850
|
return new CronTrigger(options);
|
|
2666
2851
|
}
|
|
2667
2852
|
__name(cronTrigger, "cronTrigger");
|
|
2668
|
-
var
|
|
2853
|
+
var _DynamicSchedule = class _DynamicSchedule {
|
|
2854
|
+
/**
|
|
2855
|
+
* @param client The `TriggerClient` instance to use for registering the trigger.
|
|
2856
|
+
* @param options The options for the schedule.
|
|
2857
|
+
*/
|
|
2669
2858
|
constructor(client, options) {
|
|
2670
2859
|
this.client = client;
|
|
2671
2860
|
this.options = options;
|
|
@@ -2681,7 +2870,7 @@ var DynamicSchedule = class {
|
|
|
2681
2870
|
source: "trigger.dev",
|
|
2682
2871
|
icon: "schedule-dynamic",
|
|
2683
2872
|
examples,
|
|
2684
|
-
parsePayload:
|
|
2873
|
+
parsePayload: core.ScheduledPayloadSchema.parse
|
|
2685
2874
|
};
|
|
2686
2875
|
}
|
|
2687
2876
|
async register(key, metadata) {
|
|
@@ -2755,45 +2944,26 @@ var DynamicSchedule = class {
|
|
|
2755
2944
|
};
|
|
2756
2945
|
}
|
|
2757
2946
|
};
|
|
2758
|
-
__name(
|
|
2759
|
-
|
|
2760
|
-
// src/triggerClient.ts
|
|
2761
|
-
var import_node_events = __toESM(require("events"));
|
|
2762
|
-
|
|
2763
|
-
// package.json
|
|
2764
|
-
var version = "2.2.11";
|
|
2765
|
-
|
|
2766
|
-
// src/concurrencyLimit.ts
|
|
2767
|
-
var ConcurrencyLimit = class {
|
|
2768
|
-
constructor(options) {
|
|
2769
|
-
this.options = options;
|
|
2770
|
-
}
|
|
2771
|
-
get id() {
|
|
2772
|
-
return this.options.id;
|
|
2773
|
-
}
|
|
2774
|
-
get limit() {
|
|
2775
|
-
return this.options.limit;
|
|
2776
|
-
}
|
|
2777
|
-
};
|
|
2778
|
-
__name(ConcurrencyLimit, "ConcurrencyLimit");
|
|
2947
|
+
__name(_DynamicSchedule, "DynamicSchedule");
|
|
2948
|
+
var DynamicSchedule = _DynamicSchedule;
|
|
2779
2949
|
|
|
2780
2950
|
// src/triggerClient.ts
|
|
2781
2951
|
var registerWebhookEvent = /* @__PURE__ */ __name((key) => ({
|
|
2782
|
-
name: `${
|
|
2952
|
+
name: `${core.REGISTER_WEBHOOK}.${key}`,
|
|
2783
2953
|
title: "Register Webhook",
|
|
2784
2954
|
source: "internal",
|
|
2785
2955
|
icon: "webhook",
|
|
2786
|
-
parsePayload:
|
|
2956
|
+
parsePayload: core.RegisterWebhookPayloadSchema.parse
|
|
2787
2957
|
}), "registerWebhookEvent");
|
|
2788
2958
|
var registerSourceEvent = {
|
|
2789
|
-
name:
|
|
2959
|
+
name: core.REGISTER_SOURCE_EVENT_V2,
|
|
2790
2960
|
title: "Register Source",
|
|
2791
2961
|
source: "internal",
|
|
2792
2962
|
icon: "register-source",
|
|
2793
|
-
parsePayload:
|
|
2963
|
+
parsePayload: core.RegisterSourceEventSchemaV2.parse
|
|
2794
2964
|
};
|
|
2795
2965
|
var _options4, _registeredJobs, _registeredSources, _registeredWebhooks, _registeredHttpSourceHandlers, _registeredWebhookSourceHandlers, _registeredDynamicTriggers, _jobMetadataByDynamicTriggers, _registeredSchedules, _registeredHttpEndpoints, _authResolvers, _envStore, _eventEmitter, _client2, _internalLogger, _preprocessRun, preprocessRun_fn, _executeJob, executeJob_fn, _convertErrorToExecutionResponse, convertErrorToExecutionResponse_fn, _createRunContext, createRunContext_fn, _createPreprocessRunContext, createPreprocessRunContext_fn, _handleHttpSourceRequest, handleHttpSourceRequest_fn, _handleHttpEndpointRequestForResponse, handleHttpEndpointRequestForResponse_fn, _handleWebhookRequest, handleWebhookRequest_fn, _resolveConnections, resolveConnections_fn, _resolveConnection, resolveConnection_fn, _buildJobsIndex, buildJobsIndex_fn, _buildJobIndex, buildJobIndex_fn, _buildJobIntegrations, buildJobIntegrations_fn, _buildJobIntegration, buildJobIntegration_fn, _logIOStats, logIOStats_fn, _standardResponseHeaders, standardResponseHeaders_fn, _serializeRunMetadata, serializeRunMetadata_fn, _deliverSuccessfulRunNotification, deliverSuccessfulRunNotification_fn, _deliverFailedRunNotification, deliverFailedRunNotification_fn;
|
|
2796
|
-
var
|
|
2966
|
+
var _TriggerClient = class _TriggerClient {
|
|
2797
2967
|
constructor(options) {
|
|
2798
2968
|
__privateAdd(this, _preprocessRun);
|
|
2799
2969
|
__privateAdd(this, _executeJob);
|
|
@@ -2826,14 +2996,14 @@ var TriggerClient = class {
|
|
|
2826
2996
|
__privateAdd(this, _registeredHttpEndpoints, {});
|
|
2827
2997
|
__privateAdd(this, _authResolvers, {});
|
|
2828
2998
|
__privateAdd(this, _envStore, void 0);
|
|
2829
|
-
__privateAdd(this, _eventEmitter, new
|
|
2999
|
+
__privateAdd(this, _eventEmitter, new EventEmitter__default.default());
|
|
2830
3000
|
__privateAdd(this, _client2, void 0);
|
|
2831
3001
|
__privateAdd(this, _internalLogger, void 0);
|
|
2832
3002
|
__publicField(this, "on", __privateGet(this, _eventEmitter).on.bind(__privateGet(this, _eventEmitter)));
|
|
2833
3003
|
this.id = options.id;
|
|
2834
3004
|
__privateSet(this, _options4, options);
|
|
2835
3005
|
__privateSet(this, _client2, new ApiClient(__privateGet(this, _options4)));
|
|
2836
|
-
__privateSet(this, _internalLogger, new
|
|
3006
|
+
__privateSet(this, _internalLogger, new coreBackend.Logger("trigger.dev", __privateGet(this, _options4).verbose ? "debug" : "log", [
|
|
2837
3007
|
"output",
|
|
2838
3008
|
"noopTasksSet"
|
|
2839
3009
|
]));
|
|
@@ -2957,7 +3127,7 @@ var TriggerClient = class {
|
|
|
2957
3127
|
}
|
|
2958
3128
|
case "INITIALIZE_TRIGGER": {
|
|
2959
3129
|
const json = await request.json();
|
|
2960
|
-
const body =
|
|
3130
|
+
const body = core.InitializeTriggerBodySchema.safeParse(json);
|
|
2961
3131
|
if (!body.success) {
|
|
2962
3132
|
return {
|
|
2963
3133
|
status: 400,
|
|
@@ -2983,7 +3153,7 @@ var TriggerClient = class {
|
|
|
2983
3153
|
}
|
|
2984
3154
|
case "EXECUTE_JOB": {
|
|
2985
3155
|
const json = await request.json();
|
|
2986
|
-
const execution =
|
|
3156
|
+
const execution = core.RunJobBodySchema.safeParse(json);
|
|
2987
3157
|
if (!execution.success) {
|
|
2988
3158
|
return {
|
|
2989
3159
|
status: 400,
|
|
@@ -3018,7 +3188,7 @@ var TriggerClient = class {
|
|
|
3018
3188
|
}
|
|
3019
3189
|
case "PREPROCESS_RUN": {
|
|
3020
3190
|
const json = await request.json();
|
|
3021
|
-
const body =
|
|
3191
|
+
const body = core.PreprocessRunBodySchema.safeParse(json);
|
|
3022
3192
|
if (!body.success) {
|
|
3023
3193
|
return {
|
|
3024
3194
|
status: 400,
|
|
@@ -3047,7 +3217,7 @@ var TriggerClient = class {
|
|
|
3047
3217
|
};
|
|
3048
3218
|
}
|
|
3049
3219
|
case "DELIVER_HTTP_SOURCE_REQUEST": {
|
|
3050
|
-
const headers =
|
|
3220
|
+
const headers = core.HttpSourceRequestHeadersSchema.safeParse(Object.fromEntries(request.headers.entries()));
|
|
3051
3221
|
if (!headers.success) {
|
|
3052
3222
|
return {
|
|
3053
3223
|
status: 400,
|
|
@@ -3097,7 +3267,7 @@ var TriggerClient = class {
|
|
|
3097
3267
|
};
|
|
3098
3268
|
}
|
|
3099
3269
|
case "DELIVER_HTTP_ENDPOINT_REQUEST_FOR_RESPONSE": {
|
|
3100
|
-
const headers =
|
|
3270
|
+
const headers = core.HttpEndpointRequestHeadersSchema.safeParse(Object.fromEntries(request.headers.entries()));
|
|
3101
3271
|
if (!headers.success) {
|
|
3102
3272
|
return {
|
|
3103
3273
|
status: 400,
|
|
@@ -3130,7 +3300,7 @@ var TriggerClient = class {
|
|
|
3130
3300
|
};
|
|
3131
3301
|
}
|
|
3132
3302
|
case "DELIVER_WEBHOOK_REQUEST": {
|
|
3133
|
-
const headers =
|
|
3303
|
+
const headers = core.WebhookSourceRequestHeadersSchema.safeParse(Object.fromEntries(request.headers.entries()));
|
|
3134
3304
|
if (!headers.success) {
|
|
3135
3305
|
return {
|
|
3136
3306
|
status: 400,
|
|
@@ -3221,9 +3391,11 @@ var TriggerClient = class {
|
|
|
3221
3391
|
defineJob(options) {
|
|
3222
3392
|
const existingRegisteredJob = __privateGet(this, _registeredJobs)[options.id];
|
|
3223
3393
|
if (existingRegisteredJob) {
|
|
3224
|
-
console.warn(
|
|
3394
|
+
console.warn(`[@trigger.dev/sdk] Warning: The Job "${existingRegisteredJob.id}" you're attempting to define has already been defined. Please assign a different ID to the job.`);
|
|
3225
3395
|
}
|
|
3226
|
-
|
|
3396
|
+
const job = new Job(options);
|
|
3397
|
+
this.attach(job);
|
|
3398
|
+
return job;
|
|
3227
3399
|
}
|
|
3228
3400
|
defineAuthResolver(integration, resolver) {
|
|
3229
3401
|
__privateGet(this, _authResolvers)[integration.id] = resolver;
|
|
@@ -3235,10 +3407,16 @@ var TriggerClient = class {
|
|
|
3235
3407
|
defineDynamicTrigger(options) {
|
|
3236
3408
|
return new DynamicTrigger(this, options);
|
|
3237
3409
|
}
|
|
3410
|
+
/**
|
|
3411
|
+
* An [HTTP endpoint](https://trigger.dev/docs/documentation/concepts/http-endpoints) allows you to create a [HTTP Trigger](https://trigger.dev/docs/documentation/concepts/triggers/http), which means you can trigger your Jobs from any webhooks.
|
|
3412
|
+
* @param options The Endpoint options
|
|
3413
|
+
* @returns An HTTP Endpoint, that can be used to create an HTTP Trigger.
|
|
3414
|
+
* @link https://trigger.dev/docs/documentation/concepts/http-endpoints
|
|
3415
|
+
*/
|
|
3238
3416
|
defineHttpEndpoint(options, suppressWarnings = false) {
|
|
3239
3417
|
const existingHttpEndpoint = __privateGet(this, _registeredHttpEndpoints)[options.id];
|
|
3240
3418
|
if (!suppressWarnings && existingHttpEndpoint) {
|
|
3241
|
-
console.warn(
|
|
3419
|
+
console.warn(`[@trigger.dev/sdk] Warning: The HttpEndpoint "${existingHttpEndpoint.id}" you're attempting to define has already been defined. Please assign a different ID to the HttpEndpoint.`);
|
|
3242
3420
|
}
|
|
3243
3421
|
const endpoint = httpEndpoint(options);
|
|
3244
3422
|
__privateGet(this, _registeredHttpEndpoints)[endpoint.id] = endpoint;
|
|
@@ -3249,7 +3427,7 @@ var TriggerClient = class {
|
|
|
3249
3427
|
}
|
|
3250
3428
|
attach(job) {
|
|
3251
3429
|
__privateGet(this, _registeredJobs)[job.id] = job;
|
|
3252
|
-
job.
|
|
3430
|
+
job.attachToClient(this);
|
|
3253
3431
|
}
|
|
3254
3432
|
attachDynamicTrigger(trigger) {
|
|
3255
3433
|
__privateGet(this, _registeredDynamicTriggers)[trigger.id] = trigger;
|
|
@@ -3319,7 +3497,7 @@ var TriggerClient = class {
|
|
|
3319
3497
|
}, options.options ?? {});
|
|
3320
3498
|
registeredSource.options = deepMergeOptions(registeredSource.options, newOptions);
|
|
3321
3499
|
__privateGet(this, _registeredSources)[options.key] = registeredSource;
|
|
3322
|
-
|
|
3500
|
+
this.defineJob({
|
|
3323
3501
|
id: options.key,
|
|
3324
3502
|
name: options.key,
|
|
3325
3503
|
version: options.source.version,
|
|
@@ -3386,7 +3564,7 @@ var TriggerClient = class {
|
|
|
3386
3564
|
registeredWebhook.config = deepMergeOptions(registeredWebhook.config, options.config);
|
|
3387
3565
|
}
|
|
3388
3566
|
__privateGet(this, _registeredWebhooks)[options.key] = registeredWebhook;
|
|
3389
|
-
|
|
3567
|
+
this.defineJob({
|
|
3390
3568
|
id: `webhook.register.${options.key}`,
|
|
3391
3569
|
name: `webhook.register.${options.key}`,
|
|
3392
3570
|
version: source.version,
|
|
@@ -3401,6 +3579,7 @@ var TriggerClient = class {
|
|
|
3401
3579
|
__privateGet(this, _internalLogger).debug("[webhook.register] Start");
|
|
3402
3580
|
const crudOptions = {
|
|
3403
3581
|
io,
|
|
3582
|
+
// this is just a more strongly typed payload
|
|
3404
3583
|
ctx: registerPayload
|
|
3405
3584
|
};
|
|
3406
3585
|
if (!registerPayload.active) {
|
|
@@ -3455,9 +3634,19 @@ var TriggerClient = class {
|
|
|
3455
3634
|
async getAuth(id) {
|
|
3456
3635
|
return __privateGet(this, _client2).getAuth(this.id, id);
|
|
3457
3636
|
}
|
|
3637
|
+
/** You can call this function from anywhere in your backend to send an event. The other way to send an event is by using [`io.sendEvent()`](https://trigger.dev/docs/sdk/io/sendevent) from inside a `run()` function.
|
|
3638
|
+
* @param event The event to send.
|
|
3639
|
+
* @param options Options for sending the event.
|
|
3640
|
+
* @returns A promise that resolves to the event details
|
|
3641
|
+
*/
|
|
3458
3642
|
async sendEvent(event, options) {
|
|
3459
3643
|
return __privateGet(this, _client2).sendEvent(event, options);
|
|
3460
3644
|
}
|
|
3645
|
+
/** You can call this function from anywhere in your backend to send multiple events. The other way to send multiple events is by using [`io.sendEvents()`](https://trigger.dev/docs/sdk/io/sendevents) from inside a `run()` function.
|
|
3646
|
+
* @param events The events to send.
|
|
3647
|
+
* @param options Options for sending the events.
|
|
3648
|
+
* @returns A promise that resolves to an array of event details
|
|
3649
|
+
*/
|
|
3461
3650
|
async sendEvents(events, options) {
|
|
3462
3651
|
return __privateGet(this, _client2).sendEvents(events, options);
|
|
3463
3652
|
}
|
|
@@ -3506,17 +3695,16 @@ var TriggerClient = class {
|
|
|
3506
3695
|
if (typeof apiKey !== "string") {
|
|
3507
3696
|
return "missing-header";
|
|
3508
3697
|
}
|
|
3509
|
-
const localApiKey = __privateGet(this, _options4).apiKey ??
|
|
3698
|
+
const localApiKey = __privateGet(this, _options4).apiKey ?? node_process.env.TRIGGER_API_KEY;
|
|
3510
3699
|
if (!localApiKey) {
|
|
3511
3700
|
return "missing-client";
|
|
3512
3701
|
}
|
|
3513
3702
|
return apiKey === localApiKey ? "authorized" : "unauthorized";
|
|
3514
3703
|
}
|
|
3515
3704
|
apiKey() {
|
|
3516
|
-
return __privateGet(this, _options4).apiKey ??
|
|
3705
|
+
return __privateGet(this, _options4).apiKey ?? node_process.env.TRIGGER_API_KEY;
|
|
3517
3706
|
}
|
|
3518
3707
|
};
|
|
3519
|
-
__name(TriggerClient, "TriggerClient");
|
|
3520
3708
|
_options4 = new WeakMap();
|
|
3521
3709
|
_registeredJobs = new WeakMap();
|
|
3522
3710
|
_registeredSources = new WeakMap();
|
|
@@ -3534,7 +3722,7 @@ _client2 = new WeakMap();
|
|
|
3534
3722
|
_internalLogger = new WeakMap();
|
|
3535
3723
|
_preprocessRun = new WeakSet();
|
|
3536
3724
|
preprocessRun_fn = /* @__PURE__ */ __name(async function(body, job) {
|
|
3537
|
-
|
|
3725
|
+
__privateMethod(this, _createPreprocessRunContext, createPreprocessRunContext_fn).call(this, body);
|
|
3538
3726
|
const parsedPayload = job.trigger.event.parsePayload(body.event.payload ?? {});
|
|
3539
3727
|
const properties = job.trigger.event.runProperties?.(parsedPayload) ?? [];
|
|
3540
3728
|
return {
|
|
@@ -3563,7 +3751,7 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1, timeOrigin, t
|
|
|
3563
3751
|
client: this,
|
|
3564
3752
|
context,
|
|
3565
3753
|
jobLogLevel: job1.logLevel ?? __privateGet(this, _options4).logLevel ?? "info",
|
|
3566
|
-
jobLogger: __privateGet(this, _options4).ioLogLocalEnabled ? new
|
|
3754
|
+
jobLogger: __privateGet(this, _options4).ioLogLocalEnabled ? new coreBackend.Logger(job1.id, job1.logLevel ?? __privateGet(this, _options4).logLevel ?? "info") : void 0,
|
|
3567
3755
|
serverVersion: triggerVersion,
|
|
3568
3756
|
timeOrigin,
|
|
3569
3757
|
executionTimeout: body1.runChunkExecutionLimit
|
|
@@ -3674,7 +3862,7 @@ convertErrorToExecutionResponse_fn = /* @__PURE__ */ __name(function(error, body
|
|
|
3674
3862
|
};
|
|
3675
3863
|
}
|
|
3676
3864
|
if (error instanceof ErrorWithTask) {
|
|
3677
|
-
const errorWithStack2 =
|
|
3865
|
+
const errorWithStack2 = core.ErrorWithStackSchema.safeParse(error.cause.output);
|
|
3678
3866
|
if (errorWithStack2.success) {
|
|
3679
3867
|
return {
|
|
3680
3868
|
status: "ERROR",
|
|
@@ -3691,7 +3879,7 @@ convertErrorToExecutionResponse_fn = /* @__PURE__ */ __name(function(error, body
|
|
|
3691
3879
|
};
|
|
3692
3880
|
}
|
|
3693
3881
|
if (error instanceof RetryWithTaskError) {
|
|
3694
|
-
const errorWithStack2 =
|
|
3882
|
+
const errorWithStack2 = core.ErrorWithStackSchema.safeParse(error.cause);
|
|
3695
3883
|
if (errorWithStack2.success) {
|
|
3696
3884
|
return {
|
|
3697
3885
|
status: "ERROR",
|
|
@@ -3707,7 +3895,7 @@ convertErrorToExecutionResponse_fn = /* @__PURE__ */ __name(function(error, body
|
|
|
3707
3895
|
task: error.task
|
|
3708
3896
|
};
|
|
3709
3897
|
}
|
|
3710
|
-
const errorWithStack =
|
|
3898
|
+
const errorWithStack = core.ErrorWithStackSchema.safeParse(error);
|
|
3711
3899
|
if (errorWithStack.success) {
|
|
3712
3900
|
return {
|
|
3713
3901
|
status: "ERROR",
|
|
@@ -4095,7 +4283,7 @@ logIOStats_fn = /* @__PURE__ */ __name(function(stats) {
|
|
|
4095
4283
|
_standardResponseHeaders = new WeakSet();
|
|
4096
4284
|
standardResponseHeaders_fn = /* @__PURE__ */ __name(function(start) {
|
|
4097
4285
|
return {
|
|
4098
|
-
"Trigger-Version":
|
|
4286
|
+
"Trigger-Version": core.API_VERSIONS.LAZY_LOADED_CACHED_TASKS,
|
|
4099
4287
|
"Trigger-SDK-Version": version,
|
|
4100
4288
|
"X-Trigger-Request-Timing": `dur=${performance.now() - start / 1e3}`
|
|
4101
4289
|
};
|
|
@@ -4139,6 +4327,8 @@ deliverFailedRunNotification_fn = /* @__PURE__ */ __name(async function(notifica
|
|
|
4139
4327
|
await job.options.onFailure(notification1);
|
|
4140
4328
|
}
|
|
4141
4329
|
}, "#deliverFailedRunNotification");
|
|
4330
|
+
__name(_TriggerClient, "TriggerClient");
|
|
4331
|
+
var TriggerClient = _TriggerClient;
|
|
4142
4332
|
function dynamicTriggerRegisterSourceJobId(id) {
|
|
4143
4333
|
return `register-dynamic-trigger-${id}`;
|
|
4144
4334
|
}
|
|
@@ -4162,10 +4352,7 @@ function deepMergeOptions(obj1, obj2) {
|
|
|
4162
4352
|
return mergedOptions;
|
|
4163
4353
|
}
|
|
4164
4354
|
__name(deepMergeOptions, "deepMergeOptions");
|
|
4165
|
-
|
|
4166
|
-
// src/triggers/externalSource.ts
|
|
4167
|
-
var import_core9 = require("@trigger.dev/core");
|
|
4168
|
-
var ExternalSource = class {
|
|
4355
|
+
var _ExternalSource = class _ExternalSource {
|
|
4169
4356
|
constructor(channel, options) {
|
|
4170
4357
|
this.options = options;
|
|
4171
4358
|
this.channel = channel;
|
|
@@ -4224,8 +4411,9 @@ var ExternalSource = class {
|
|
|
4224
4411
|
return this.options.version;
|
|
4225
4412
|
}
|
|
4226
4413
|
};
|
|
4227
|
-
__name(
|
|
4228
|
-
var
|
|
4414
|
+
__name(_ExternalSource, "ExternalSource");
|
|
4415
|
+
var ExternalSource = _ExternalSource;
|
|
4416
|
+
var _ExternalSourceTrigger = class _ExternalSourceTrigger {
|
|
4229
4417
|
constructor(options) {
|
|
4230
4418
|
this.options = options;
|
|
4231
4419
|
}
|
|
@@ -4238,7 +4426,7 @@ var ExternalSourceTrigger = class {
|
|
|
4238
4426
|
title: "External Source",
|
|
4239
4427
|
rule: {
|
|
4240
4428
|
event: this.event.name,
|
|
4241
|
-
payload:
|
|
4429
|
+
payload: core.deepMergeFilters(this.options.source.filter(this.options.params, this.options.options), this.event.filter ?? {}, this.options.params.filter ?? {}),
|
|
4242
4430
|
source: this.event.source
|
|
4243
4431
|
},
|
|
4244
4432
|
properties: this.options.source.properties(this.options.params)
|
|
@@ -4262,7 +4450,8 @@ var ExternalSourceTrigger = class {
|
|
|
4262
4450
|
};
|
|
4263
4451
|
}
|
|
4264
4452
|
};
|
|
4265
|
-
__name(
|
|
4453
|
+
__name(_ExternalSourceTrigger, "ExternalSourceTrigger");
|
|
4454
|
+
var ExternalSourceTrigger = _ExternalSourceTrigger;
|
|
4266
4455
|
function omit(obj, key) {
|
|
4267
4456
|
const result = {};
|
|
4268
4457
|
for (const k of Object.keys(obj)) {
|
|
@@ -4276,9 +4465,6 @@ function omit(obj, key) {
|
|
|
4276
4465
|
};
|
|
4277
4466
|
}
|
|
4278
4467
|
__name(omit, "omit");
|
|
4279
|
-
|
|
4280
|
-
// src/triggers/notifications.ts
|
|
4281
|
-
var import_core10 = require("@trigger.dev/core");
|
|
4282
4468
|
function missingConnectionNotification(integrations) {
|
|
4283
4469
|
return new MissingConnectionNotification({
|
|
4284
4470
|
integrations
|
|
@@ -4291,17 +4477,17 @@ function missingConnectionResolvedNotification(integrations) {
|
|
|
4291
4477
|
});
|
|
4292
4478
|
}
|
|
4293
4479
|
__name(missingConnectionResolvedNotification, "missingConnectionResolvedNotification");
|
|
4294
|
-
var
|
|
4480
|
+
var _MissingConnectionNotification = class _MissingConnectionNotification {
|
|
4295
4481
|
constructor(options) {
|
|
4296
4482
|
this.options = options;
|
|
4297
4483
|
}
|
|
4298
4484
|
get event() {
|
|
4299
4485
|
return {
|
|
4300
|
-
name:
|
|
4486
|
+
name: core.MISSING_CONNECTION_NOTIFICATION,
|
|
4301
4487
|
title: "Missing Connection Notification",
|
|
4302
4488
|
source: "trigger.dev",
|
|
4303
4489
|
icon: "connection-alert",
|
|
4304
|
-
parsePayload:
|
|
4490
|
+
parsePayload: core.MissingConnectionNotificationPayloadSchema.parse,
|
|
4305
4491
|
properties: [
|
|
4306
4492
|
{
|
|
4307
4493
|
label: "Integrations",
|
|
@@ -4336,18 +4522,19 @@ var MissingConnectionNotification = class {
|
|
|
4336
4522
|
};
|
|
4337
4523
|
}
|
|
4338
4524
|
};
|
|
4339
|
-
__name(
|
|
4340
|
-
var
|
|
4525
|
+
__name(_MissingConnectionNotification, "MissingConnectionNotification");
|
|
4526
|
+
var MissingConnectionNotification = _MissingConnectionNotification;
|
|
4527
|
+
var _MissingConnectionResolvedNotification = class _MissingConnectionResolvedNotification {
|
|
4341
4528
|
constructor(options) {
|
|
4342
4529
|
this.options = options;
|
|
4343
4530
|
}
|
|
4344
4531
|
get event() {
|
|
4345
4532
|
return {
|
|
4346
|
-
name:
|
|
4533
|
+
name: core.MISSING_CONNECTION_RESOLVED_NOTIFICATION,
|
|
4347
4534
|
title: "Missing Connection Resolved Notification",
|
|
4348
4535
|
source: "trigger.dev",
|
|
4349
4536
|
icon: "connection-alert",
|
|
4350
|
-
parsePayload:
|
|
4537
|
+
parsePayload: core.MissingConnectionResolvedNotificationPayloadSchema.parse,
|
|
4351
4538
|
properties: [
|
|
4352
4539
|
{
|
|
4353
4540
|
label: "Integrations",
|
|
@@ -4382,11 +4569,12 @@ var MissingConnectionResolvedNotification = class {
|
|
|
4382
4569
|
};
|
|
4383
4570
|
}
|
|
4384
4571
|
};
|
|
4385
|
-
__name(
|
|
4572
|
+
__name(_MissingConnectionResolvedNotification, "MissingConnectionResolvedNotification");
|
|
4573
|
+
var MissingConnectionResolvedNotification = _MissingConnectionResolvedNotification;
|
|
4386
4574
|
|
|
4387
4575
|
// src/triggers/invokeTrigger.ts
|
|
4388
4576
|
var _options5;
|
|
4389
|
-
var
|
|
4577
|
+
var _InvokeTrigger = class _InvokeTrigger {
|
|
4390
4578
|
constructor(options) {
|
|
4391
4579
|
__privateAdd(this, _options5, void 0);
|
|
4392
4580
|
__privateSet(this, _options5, options);
|
|
@@ -4436,18 +4624,15 @@ var InvokeTrigger = class {
|
|
|
4436
4624
|
};
|
|
4437
4625
|
}
|
|
4438
4626
|
};
|
|
4439
|
-
__name(InvokeTrigger, "InvokeTrigger");
|
|
4440
4627
|
_options5 = new WeakMap();
|
|
4628
|
+
__name(_InvokeTrigger, "InvokeTrigger");
|
|
4629
|
+
var InvokeTrigger = _InvokeTrigger;
|
|
4441
4630
|
function invokeTrigger(options) {
|
|
4442
4631
|
return new InvokeTrigger(options ?? {});
|
|
4443
4632
|
}
|
|
4444
4633
|
__name(invokeTrigger, "invokeTrigger");
|
|
4445
|
-
|
|
4446
|
-
// src/triggers/webhook.ts
|
|
4447
|
-
var import_core11 = require("@trigger.dev/core");
|
|
4448
|
-
var import_node_crypto2 = require("crypto");
|
|
4449
4634
|
var _shortHash, shortHash_fn;
|
|
4450
|
-
var
|
|
4635
|
+
var _WebhookSource = class _WebhookSource {
|
|
4451
4636
|
constructor(options) {
|
|
4452
4637
|
__privateAdd(this, _shortHash);
|
|
4453
4638
|
this.options = options;
|
|
@@ -4515,13 +4700,14 @@ var WebhookSource = class {
|
|
|
4515
4700
|
return this.options.version;
|
|
4516
4701
|
}
|
|
4517
4702
|
};
|
|
4518
|
-
__name(WebhookSource, "WebhookSource");
|
|
4519
4703
|
_shortHash = new WeakSet();
|
|
4520
4704
|
shortHash_fn = /* @__PURE__ */ __name(function(str) {
|
|
4521
|
-
const hash =
|
|
4705
|
+
const hash = crypto.createHash("sha1").update(str).digest("hex");
|
|
4522
4706
|
return hash.slice(0, 7);
|
|
4523
4707
|
}, "#shortHash");
|
|
4524
|
-
|
|
4708
|
+
__name(_WebhookSource, "WebhookSource");
|
|
4709
|
+
var WebhookSource = _WebhookSource;
|
|
4710
|
+
var _WebhookTrigger = class _WebhookTrigger {
|
|
4525
4711
|
constructor(options) {
|
|
4526
4712
|
this.options = options;
|
|
4527
4713
|
}
|
|
@@ -4540,7 +4726,7 @@ var WebhookTrigger = class {
|
|
|
4540
4726
|
title: "Webhook",
|
|
4541
4727
|
rule: {
|
|
4542
4728
|
event: this.event.name,
|
|
4543
|
-
payload:
|
|
4729
|
+
payload: core.deepMergeFilters(this.options.source.filter(this.options.params, this.options.config), this.event.filter ?? {}),
|
|
4544
4730
|
source: this.event.source
|
|
4545
4731
|
},
|
|
4546
4732
|
properties: this.options.source.properties(this.options.params),
|
|
@@ -4550,11 +4736,11 @@ var WebhookTrigger = class {
|
|
|
4550
4736
|
filter(eventFilter) {
|
|
4551
4737
|
const { event, ...optionsWithoutEvent } = this.options;
|
|
4552
4738
|
const { filter, ...eventWithoutFilter } = event;
|
|
4553
|
-
return new
|
|
4739
|
+
return new _WebhookTrigger({
|
|
4554
4740
|
...optionsWithoutEvent,
|
|
4555
4741
|
event: {
|
|
4556
4742
|
...eventWithoutFilter,
|
|
4557
|
-
filter:
|
|
4743
|
+
filter: core.deepMergeFilters(filter ?? {}, eventFilter)
|
|
4558
4744
|
}
|
|
4559
4745
|
});
|
|
4560
4746
|
}
|
|
@@ -4584,10 +4770,8 @@ var WebhookTrigger = class {
|
|
|
4584
4770
|
};
|
|
4585
4771
|
}
|
|
4586
4772
|
};
|
|
4587
|
-
__name(
|
|
4588
|
-
|
|
4589
|
-
// src/security.ts
|
|
4590
|
-
var import_crypto = __toESM(require("crypto"));
|
|
4773
|
+
__name(_WebhookTrigger, "WebhookTrigger");
|
|
4774
|
+
var WebhookTrigger = _WebhookTrigger;
|
|
4591
4775
|
async function verifyRequestSignature({ request, headerName, headerEncoding = "hex", secret, algorithm }) {
|
|
4592
4776
|
if (!secret) {
|
|
4593
4777
|
return {
|
|
@@ -4621,7 +4805,7 @@ async function verifyRequestSignature({ request, headerName, headerEncoding = "h
|
|
|
4621
4805
|
}
|
|
4622
4806
|
__name(verifyRequestSignature, "verifyRequestSignature");
|
|
4623
4807
|
function verifyHmacSha256(headerValue, headerEncoding, secret, body) {
|
|
4624
|
-
const bodyDigest =
|
|
4808
|
+
const bodyDigest = crypto__default.default.createHmac("sha256", secret).update(body).digest(headerEncoding);
|
|
4625
4809
|
const signature = headerValue?.replace("hmac-sha256=", "").replace("sha256=", "") ?? "";
|
|
4626
4810
|
return signature === bodyDigest;
|
|
4627
4811
|
}
|
|
@@ -4636,39 +4820,38 @@ function redactString(strings, ...interpolations) {
|
|
|
4636
4820
|
};
|
|
4637
4821
|
}
|
|
4638
4822
|
__name(redactString, "redactString");
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
});
|
|
4823
|
+
|
|
4824
|
+
exports.CronTrigger = CronTrigger;
|
|
4825
|
+
exports.DynamicSchedule = DynamicSchedule;
|
|
4826
|
+
exports.DynamicTrigger = DynamicTrigger;
|
|
4827
|
+
exports.EventSpecificationExampleSchema = EventSpecificationExampleSchema;
|
|
4828
|
+
exports.EventTrigger = EventTrigger;
|
|
4829
|
+
exports.ExternalSource = ExternalSource;
|
|
4830
|
+
exports.ExternalSourceTrigger = ExternalSourceTrigger;
|
|
4831
|
+
exports.IO = IO;
|
|
4832
|
+
exports.IOLogger = IOLogger;
|
|
4833
|
+
exports.IntervalTrigger = IntervalTrigger;
|
|
4834
|
+
exports.InvokeTrigger = InvokeTrigger;
|
|
4835
|
+
exports.JSONOutputSerializer = JSONOutputSerializer;
|
|
4836
|
+
exports.Job = Job;
|
|
4837
|
+
exports.MissingConnectionNotification = MissingConnectionNotification;
|
|
4838
|
+
exports.MissingConnectionResolvedNotification = MissingConnectionResolvedNotification;
|
|
4839
|
+
exports.TriggerClient = TriggerClient;
|
|
4840
|
+
exports.WebhookSource = WebhookSource;
|
|
4841
|
+
exports.WebhookTrigger = WebhookTrigger;
|
|
4842
|
+
exports.cronTrigger = cronTrigger;
|
|
4843
|
+
exports.eventTrigger = eventTrigger;
|
|
4844
|
+
exports.intervalTrigger = intervalTrigger;
|
|
4845
|
+
exports.invokeTrigger = invokeTrigger;
|
|
4846
|
+
exports.isTriggerError = isTriggerError;
|
|
4847
|
+
exports.missingConnectionNotification = missingConnectionNotification;
|
|
4848
|
+
exports.missingConnectionResolvedNotification = missingConnectionResolvedNotification;
|
|
4849
|
+
exports.omit = omit;
|
|
4850
|
+
exports.redactString = redactString;
|
|
4851
|
+
exports.retry = retry;
|
|
4852
|
+
exports.slugifyId = slugifyId;
|
|
4853
|
+
exports.verifyHmacSha256 = verifyHmacSha256;
|
|
4854
|
+
exports.verifyRequestSignature = verifyRequestSignature;
|
|
4855
|
+
exports.waitForEventSchema = waitForEventSchema;
|
|
4856
|
+
//# sourceMappingURL=out.js.map
|
|
4674
4857
|
//# sourceMappingURL=index.js.map
|