@trigger.dev/sdk 2.2.10 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +2694 -0
- package/dist/index.d.ts +34 -32
- package/dist/index.js +532 -349
- 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 node_process = require('node:process');
|
|
6
|
+
var zod = require('zod');
|
|
7
|
+
var coreBackend = require('@trigger.dev/core-backend');
|
|
8
|
+
var crypto = require('node:crypto');
|
|
9
|
+
var node_buffer = require('node:buffer');
|
|
10
|
+
var cronstrue = require('cronstrue');
|
|
11
|
+
var EventEmitter = require('node:events');
|
|
12
|
+
|
|
13
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
|
|
15
|
+
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
16
|
+
var cronstrue__default = /*#__PURE__*/_interopDefault(cronstrue);
|
|
17
|
+
var EventEmitter__default = /*#__PURE__*/_interopDefault(EventEmitter);
|
|
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,64 @@ 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");
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
var import_core8 = require("@trigger.dev/core");
|
|
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");
|
|
265
|
+
__name(_Job, "Job");
|
|
266
|
+
var Job = _Job;
|
|
310
267
|
|
|
311
268
|
// src/errors.ts
|
|
312
|
-
var
|
|
269
|
+
var _ResumeWithTaskError = class _ResumeWithTaskError {
|
|
313
270
|
constructor(task) {
|
|
314
271
|
this.task = task;
|
|
315
272
|
}
|
|
316
273
|
};
|
|
317
|
-
__name(
|
|
318
|
-
var
|
|
274
|
+
__name(_ResumeWithTaskError, "ResumeWithTaskError");
|
|
275
|
+
var ResumeWithTaskError = _ResumeWithTaskError;
|
|
276
|
+
var _ResumeWithParallelTaskError = class _ResumeWithParallelTaskError {
|
|
319
277
|
constructor(task, childErrors) {
|
|
320
278
|
this.task = task;
|
|
321
279
|
this.childErrors = childErrors;
|
|
322
280
|
}
|
|
323
281
|
};
|
|
324
|
-
__name(
|
|
325
|
-
var
|
|
282
|
+
__name(_ResumeWithParallelTaskError, "ResumeWithParallelTaskError");
|
|
283
|
+
var ResumeWithParallelTaskError = _ResumeWithParallelTaskError;
|
|
284
|
+
var _RetryWithTaskError = class _RetryWithTaskError {
|
|
326
285
|
constructor(cause, task, retryAt) {
|
|
327
286
|
this.cause = cause;
|
|
328
287
|
this.task = task;
|
|
329
288
|
this.retryAt = retryAt;
|
|
330
289
|
}
|
|
331
290
|
};
|
|
332
|
-
__name(
|
|
333
|
-
var
|
|
291
|
+
__name(_RetryWithTaskError, "RetryWithTaskError");
|
|
292
|
+
var RetryWithTaskError = _RetryWithTaskError;
|
|
293
|
+
var _CanceledWithTaskError = class _CanceledWithTaskError {
|
|
334
294
|
constructor(task) {
|
|
335
295
|
this.task = task;
|
|
336
296
|
}
|
|
337
297
|
};
|
|
338
|
-
__name(
|
|
339
|
-
var
|
|
298
|
+
__name(_CanceledWithTaskError, "CanceledWithTaskError");
|
|
299
|
+
var CanceledWithTaskError = _CanceledWithTaskError;
|
|
300
|
+
var _YieldExecutionError = class _YieldExecutionError {
|
|
340
301
|
constructor(key) {
|
|
341
302
|
this.key = key;
|
|
342
303
|
}
|
|
343
304
|
};
|
|
344
|
-
__name(
|
|
345
|
-
var
|
|
305
|
+
__name(_YieldExecutionError, "YieldExecutionError");
|
|
306
|
+
var YieldExecutionError = _YieldExecutionError;
|
|
307
|
+
var _AutoYieldExecutionError = class _AutoYieldExecutionError {
|
|
346
308
|
constructor(location, timeRemaining, timeElapsed) {
|
|
347
309
|
this.location = location;
|
|
348
310
|
this.timeRemaining = timeRemaining;
|
|
349
311
|
this.timeElapsed = timeElapsed;
|
|
350
312
|
}
|
|
351
313
|
};
|
|
352
|
-
__name(
|
|
353
|
-
var
|
|
314
|
+
__name(_AutoYieldExecutionError, "AutoYieldExecutionError");
|
|
315
|
+
var AutoYieldExecutionError = _AutoYieldExecutionError;
|
|
316
|
+
var _AutoYieldWithCompletedTaskExecutionError = class _AutoYieldWithCompletedTaskExecutionError {
|
|
354
317
|
constructor(id, properties, data, output) {
|
|
355
318
|
this.id = id;
|
|
356
319
|
this.properties = properties;
|
|
@@ -358,27 +321,27 @@ var AutoYieldWithCompletedTaskExecutionError = class {
|
|
|
358
321
|
this.output = output;
|
|
359
322
|
}
|
|
360
323
|
};
|
|
361
|
-
__name(
|
|
362
|
-
var
|
|
324
|
+
__name(_AutoYieldWithCompletedTaskExecutionError, "AutoYieldWithCompletedTaskExecutionError");
|
|
325
|
+
var AutoYieldWithCompletedTaskExecutionError = _AutoYieldWithCompletedTaskExecutionError;
|
|
326
|
+
var _ParsedPayloadSchemaError = class _ParsedPayloadSchemaError {
|
|
363
327
|
constructor(schemaErrors) {
|
|
364
328
|
this.schemaErrors = schemaErrors;
|
|
365
329
|
}
|
|
366
330
|
};
|
|
367
|
-
__name(
|
|
331
|
+
__name(_ParsedPayloadSchemaError, "ParsedPayloadSchemaError");
|
|
332
|
+
var ParsedPayloadSchemaError = _ParsedPayloadSchemaError;
|
|
368
333
|
function isTriggerError(err) {
|
|
369
334
|
return err instanceof ResumeWithTaskError || err instanceof RetryWithTaskError || err instanceof CanceledWithTaskError || err instanceof YieldExecutionError || err instanceof AutoYieldExecutionError || err instanceof AutoYieldWithCompletedTaskExecutionError || err instanceof ResumeWithParallelTaskError;
|
|
370
335
|
}
|
|
371
336
|
__name(isTriggerError, "isTriggerError");
|
|
372
|
-
var
|
|
337
|
+
var _ErrorWithTask = class _ErrorWithTask extends Error {
|
|
373
338
|
constructor(cause, message) {
|
|
374
339
|
super(message);
|
|
375
340
|
this.cause = cause;
|
|
376
341
|
}
|
|
377
342
|
};
|
|
378
|
-
__name(
|
|
379
|
-
|
|
380
|
-
// src/retry.ts
|
|
381
|
-
var import_core = require("@trigger.dev/core");
|
|
343
|
+
__name(_ErrorWithTask, "ErrorWithTask");
|
|
344
|
+
var ErrorWithTask = _ErrorWithTask;
|
|
382
345
|
var retry = {
|
|
383
346
|
standardBackoff: {
|
|
384
347
|
limit: 8,
|
|
@@ -397,7 +360,7 @@ var retry = {
|
|
|
397
360
|
};
|
|
398
361
|
|
|
399
362
|
// src/status.ts
|
|
400
|
-
var
|
|
363
|
+
var _TriggerStatus = class _TriggerStatus {
|
|
401
364
|
constructor(id, io) {
|
|
402
365
|
this.id = id;
|
|
403
366
|
this.io = io;
|
|
@@ -428,35 +391,30 @@ var TriggerStatus = class {
|
|
|
428
391
|
});
|
|
429
392
|
}
|
|
430
393
|
};
|
|
431
|
-
__name(
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
icon: import_zod.z.string().optional(),
|
|
439
|
-
payload: import_zod.z.any()
|
|
394
|
+
__name(_TriggerStatus, "TriggerStatus");
|
|
395
|
+
var TriggerStatus = _TriggerStatus;
|
|
396
|
+
var EventSpecificationExampleSchema = zod.z.object({
|
|
397
|
+
id: zod.z.string(),
|
|
398
|
+
name: zod.z.string(),
|
|
399
|
+
icon: zod.z.string().optional(),
|
|
400
|
+
payload: zod.z.any()
|
|
440
401
|
});
|
|
441
402
|
function waitForEventSchema(schema) {
|
|
442
|
-
return
|
|
443
|
-
id:
|
|
444
|
-
name:
|
|
445
|
-
source:
|
|
403
|
+
return zod.z.object({
|
|
404
|
+
id: zod.z.string(),
|
|
405
|
+
name: zod.z.string(),
|
|
406
|
+
source: zod.z.string(),
|
|
446
407
|
payload: schema,
|
|
447
|
-
timestamp:
|
|
448
|
-
context:
|
|
449
|
-
accountId:
|
|
408
|
+
timestamp: zod.z.coerce.date(),
|
|
409
|
+
context: zod.z.any().optional(),
|
|
410
|
+
accountId: zod.z.string().optional()
|
|
450
411
|
});
|
|
451
412
|
}
|
|
452
413
|
__name(waitForEventSchema, "waitForEventSchema");
|
|
453
414
|
|
|
454
|
-
// src/io.ts
|
|
455
|
-
var import_zod2 = require("zod");
|
|
456
|
-
|
|
457
415
|
// src/store/keyValueStore.ts
|
|
458
416
|
var _namespacedKey, namespacedKey_fn, _sharedProperties, sharedProperties_fn;
|
|
459
|
-
var
|
|
417
|
+
var _KeyValueStore = class _KeyValueStore {
|
|
460
418
|
constructor(apiClient, type = null, namespace = "") {
|
|
461
419
|
__privateAdd(this, _namespacedKey);
|
|
462
420
|
__privateAdd(this, _sharedProperties);
|
|
@@ -579,7 +537,6 @@ var KeyValueStore = class {
|
|
|
579
537
|
});
|
|
580
538
|
}
|
|
581
539
|
};
|
|
582
|
-
__name(KeyValueStore, "KeyValueStore");
|
|
583
540
|
_namespacedKey = new WeakSet();
|
|
584
541
|
namespacedKey_fn = /* @__PURE__ */ __name(function(key) {
|
|
585
542
|
const parts = [];
|
|
@@ -605,9 +562,9 @@ sharedProperties_fn = /* @__PURE__ */ __name(function(key1) {
|
|
|
605
562
|
}
|
|
606
563
|
];
|
|
607
564
|
}, "#sharedProperties");
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
var
|
|
565
|
+
__name(_KeyValueStore, "KeyValueStore");
|
|
566
|
+
var KeyValueStore = _KeyValueStore;
|
|
567
|
+
var _JSONOutputSerializer = class _JSONOutputSerializer {
|
|
611
568
|
serialize(value) {
|
|
612
569
|
return JSON.stringify(value);
|
|
613
570
|
}
|
|
@@ -615,9 +572,10 @@ var JSONOutputSerializer = class {
|
|
|
615
572
|
return value ? JSON.parse(value) : void 0;
|
|
616
573
|
}
|
|
617
574
|
};
|
|
618
|
-
__name(
|
|
575
|
+
__name(_JSONOutputSerializer, "JSONOutputSerializer");
|
|
576
|
+
var JSONOutputSerializer = _JSONOutputSerializer;
|
|
619
577
|
var _addToCachedTasks, addToCachedTasks_fn, _detectAutoYield, detectAutoYield_fn, _forceYield, forceYield_fn, _getTimeElapsed, getTimeElapsed_fn, _getRemainingTimeInMillis, getRemainingTimeInMillis_fn;
|
|
620
|
-
var
|
|
578
|
+
var _IO = class _IO {
|
|
621
579
|
constructor(options) {
|
|
622
580
|
__privateAdd(this, _addToCachedTasks);
|
|
623
581
|
__privateAdd(this, _detectAutoYield);
|
|
@@ -626,12 +584,15 @@ var IO = class {
|
|
|
626
584
|
__privateAdd(this, _getRemainingTimeInMillis);
|
|
627
585
|
__publicField(this, "_outputSerializer", new JSONOutputSerializer());
|
|
628
586
|
__publicField(this, "_visitedCacheKeys", /* @__PURE__ */ new Set());
|
|
587
|
+
/**
|
|
588
|
+
* `io.brb()` is an alias of `io.yield()`
|
|
589
|
+
*/
|
|
629
590
|
__publicField(this, "brb", this.yield.bind(this));
|
|
630
591
|
this._id = options.id;
|
|
631
592
|
this._jobId = options.jobId;
|
|
632
593
|
this._apiClient = options.apiClient;
|
|
633
594
|
this._triggerClient = options.client;
|
|
634
|
-
this._logger = options.logger ?? new
|
|
595
|
+
this._logger = options.logger ?? new core.Logger("trigger.dev", options.logLevel);
|
|
635
596
|
this._cachedTasks = /* @__PURE__ */ new Map();
|
|
636
597
|
this._jobLogger = options.jobLogger;
|
|
637
598
|
this._jobLogLevel = options.jobLogLevel;
|
|
@@ -655,11 +616,11 @@ var IO = class {
|
|
|
655
616
|
});
|
|
656
617
|
this._stats.initialCachedTasks = options.cachedTasks.length;
|
|
657
618
|
}
|
|
658
|
-
this._taskStorage = new
|
|
619
|
+
this._taskStorage = new node_async_hooks.AsyncLocalStorage();
|
|
659
620
|
this._context = options.context;
|
|
660
621
|
this._yieldedExecutions = options.yieldedExecutions ?? [];
|
|
661
622
|
if (options.noopTasksSet) {
|
|
662
|
-
this._noopTasksBloomFilter =
|
|
623
|
+
this._noopTasksBloomFilter = coreBackend.BloomFilter.deserialize(options.noopTasksSet, coreBackend.BloomFilter.NOOP_TASK_SET_SIZE);
|
|
663
624
|
}
|
|
664
625
|
this._cachedTasksCursor = options.cachedTasksCursor;
|
|
665
626
|
this._serverVersion = options.serverVersion ?? "unversioned";
|
|
@@ -667,16 +628,19 @@ var IO = class {
|
|
|
667
628
|
get stats() {
|
|
668
629
|
return this._stats;
|
|
669
630
|
}
|
|
631
|
+
/** @internal */
|
|
670
632
|
get runId() {
|
|
671
633
|
return this._id;
|
|
672
634
|
}
|
|
635
|
+
/** @internal */
|
|
673
636
|
get triggerClient() {
|
|
674
637
|
return this._triggerClient;
|
|
675
638
|
}
|
|
639
|
+
/** Used to send log messages to the [Run log](https://trigger.dev/docs/documentation/guides/viewing-runs). */
|
|
676
640
|
get logger() {
|
|
677
641
|
return new IOLogger(async (level, message, data) => {
|
|
678
642
|
let logLevel = "info";
|
|
679
|
-
if (
|
|
643
|
+
if (core.Logger.satisfiesLogLevel(logLevel, this._jobLogLevel)) {
|
|
680
644
|
await this.runTask([
|
|
681
645
|
message,
|
|
682
646
|
level
|
|
@@ -728,6 +692,12 @@ var IO = class {
|
|
|
728
692
|
}
|
|
729
693
|
});
|
|
730
694
|
}
|
|
695
|
+
/** `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.
|
|
696
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
697
|
+
* @param min Sets the lower bound (inclusive). Can't be higher than `max`.
|
|
698
|
+
* @param max Sets the upper bound (exclusive). Can't be lower than `min`.
|
|
699
|
+
* @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.
|
|
700
|
+
*/
|
|
731
701
|
async random(cacheKey, { min = 0, max = 1, round = false } = {}) {
|
|
732
702
|
return await this.runTask(cacheKey, async (task) => {
|
|
733
703
|
if (min > max) {
|
|
@@ -778,6 +748,10 @@ var IO = class {
|
|
|
778
748
|
}
|
|
779
749
|
});
|
|
780
750
|
}
|
|
751
|
+
/** `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.
|
|
752
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
753
|
+
* @param seconds The number of seconds to wait. This can be very long, serverless timeouts are not an issue.
|
|
754
|
+
*/
|
|
781
755
|
async wait(cacheKey, seconds) {
|
|
782
756
|
return await this.runTask(cacheKey, async (task) => {
|
|
783
757
|
}, {
|
|
@@ -846,10 +820,29 @@ var IO = class {
|
|
|
846
820
|
] : []
|
|
847
821
|
],
|
|
848
822
|
parseOutput: (output) => {
|
|
849
|
-
return waitForEventSchema(event.schema ??
|
|
823
|
+
return waitForEventSchema(event.schema ?? zod.z.any()).parse(output);
|
|
850
824
|
}
|
|
851
825
|
});
|
|
852
826
|
}
|
|
827
|
+
/** `io.waitForRequest()` allows you to pause the execution of a run until the url provided in the callback is POSTed to.
|
|
828
|
+
* 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.
|
|
829
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
830
|
+
* @param callback A callback function that will provide the unique URL to POST to.
|
|
831
|
+
* @param options Options for the callback.
|
|
832
|
+
* @param options.timeoutInSeconds How long to wait for the request to be POSTed to the callback URL before timing out. Defaults to 1hr.
|
|
833
|
+
* @returns The POSTed request JSON body.
|
|
834
|
+
* @example
|
|
835
|
+
* ```ts
|
|
836
|
+
const result = await io.waitForRequest<{ message: string }>(
|
|
837
|
+
"wait-for-request",
|
|
838
|
+
async (url, task) => {
|
|
839
|
+
// Save the URL somewhere so you can POST to it later
|
|
840
|
+
// Or send it to an external service that will POST to it
|
|
841
|
+
},
|
|
842
|
+
{ timeoutInSeconds: 60 } // wait 60 seconds
|
|
843
|
+
);
|
|
844
|
+
* ```
|
|
845
|
+
*/
|
|
853
846
|
async waitForRequest(cacheKey, callback, options) {
|
|
854
847
|
const timeoutInSeconds = options?.timeoutInSeconds ?? 60 * 60;
|
|
855
848
|
return await this.runTask(cacheKey, async (task, io) => {
|
|
@@ -878,12 +871,55 @@ var IO = class {
|
|
|
878
871
|
]
|
|
879
872
|
});
|
|
880
873
|
}
|
|
874
|
+
/** `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
|
|
875
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
876
|
+
* @param initialStatus The initial status you want this status to have. You can update it during the rub using the returned object.
|
|
877
|
+
* @returns a TriggerStatus object that you can call `update()` on, to update the status.
|
|
878
|
+
* @example
|
|
879
|
+
* ```ts
|
|
880
|
+
* client.defineJob(
|
|
881
|
+
//...
|
|
882
|
+
run: async (payload, io, ctx) => {
|
|
883
|
+
const generatingImages = await io.createStatus("generating-images", {
|
|
884
|
+
label: "Generating Images",
|
|
885
|
+
state: "loading",
|
|
886
|
+
data: {
|
|
887
|
+
progress: 0.1,
|
|
888
|
+
},
|
|
889
|
+
});
|
|
890
|
+
|
|
891
|
+
//...do stuff
|
|
892
|
+
|
|
893
|
+
await generatingImages.update("completed-generation", {
|
|
894
|
+
label: "Generated images",
|
|
895
|
+
state: "success",
|
|
896
|
+
data: {
|
|
897
|
+
progress: 1.0,
|
|
898
|
+
urls: ["http://..."]
|
|
899
|
+
},
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
//...
|
|
903
|
+
});
|
|
904
|
+
* ```
|
|
905
|
+
*/
|
|
881
906
|
async createStatus(cacheKey, initialStatus) {
|
|
882
907
|
const id = typeof cacheKey === "string" ? cacheKey : cacheKey.join("-");
|
|
883
908
|
const status = new TriggerStatus(id, this);
|
|
884
909
|
await status.update(cacheKey, initialStatus);
|
|
885
910
|
return status;
|
|
886
911
|
}
|
|
912
|
+
/** `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.
|
|
913
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
914
|
+
* @param url The URL to fetch from.
|
|
915
|
+
* @param requestInit The options for the request
|
|
916
|
+
* @param retry The options for retrying the request if it fails
|
|
917
|
+
* An object where the key is a status code pattern and the value is a retrying strategy.
|
|
918
|
+
* Supported patterns are:
|
|
919
|
+
* - Specific status codes: 429
|
|
920
|
+
* - Ranges: 500-599
|
|
921
|
+
* - Wildcards: 2xx, 3xx, 4xx, 5xx
|
|
922
|
+
*/
|
|
887
923
|
async backgroundFetch(cacheKey, url, requestInit, options) {
|
|
888
924
|
const urlObject = new URL(url);
|
|
889
925
|
return await this.runTask(cacheKey, async (task) => {
|
|
@@ -926,6 +962,39 @@ var IO = class {
|
|
|
926
962
|
}
|
|
927
963
|
});
|
|
928
964
|
}
|
|
965
|
+
/** `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.
|
|
966
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
967
|
+
* @param params The options for the background poll
|
|
968
|
+
* @param params.url The URL to fetch from.
|
|
969
|
+
* @param params.requestInit The options for the request, like headers and method
|
|
970
|
+
* @param params.responseFilter An [EventFilter](https://trigger.dev/docs/documentation/guides/event-filter) that allows you to specify when to stop polling.
|
|
971
|
+
* @param params.interval The interval in seconds to poll the URL in seconds. Defaults to 10 seconds which is the minimum.
|
|
972
|
+
* @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
|
|
973
|
+
* @param params.requestTimeout An optional object that allows you to timeout individual fetch requests
|
|
974
|
+
* @param params.requestTimeout An optional object that allows you to timeout individual fetch requests
|
|
975
|
+
* @param params.requestTimeout.durationInMs The duration in milliseconds to timeout the request
|
|
976
|
+
*
|
|
977
|
+
* @example
|
|
978
|
+
* ```ts
|
|
979
|
+
* const result = await io.backgroundPoll<{ id: string; status: string; }>("poll", {
|
|
980
|
+
url: `http://localhost:3030/api/v1/runs/${run.id}`,
|
|
981
|
+
requestInit: {
|
|
982
|
+
headers: {
|
|
983
|
+
Accept: "application/json",
|
|
984
|
+
Authorization: redactString`Bearer ${process.env["TRIGGER_API_KEY"]!}`,
|
|
985
|
+
},
|
|
986
|
+
},
|
|
987
|
+
interval: 10,
|
|
988
|
+
timeout: 600,
|
|
989
|
+
responseFilter: {
|
|
990
|
+
status: [200],
|
|
991
|
+
body: {
|
|
992
|
+
status: ["SUCCESS"],
|
|
993
|
+
},
|
|
994
|
+
},
|
|
995
|
+
});
|
|
996
|
+
* ```
|
|
997
|
+
*/
|
|
929
998
|
async backgroundPoll(cacheKey, params) {
|
|
930
999
|
const urlObject = new URL(params.url);
|
|
931
1000
|
return await this.runTask(cacheKey, async (task) => {
|
|
@@ -955,6 +1024,17 @@ var IO = class {
|
|
|
955
1024
|
}
|
|
956
1025
|
});
|
|
957
1026
|
}
|
|
1027
|
+
/** `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.
|
|
1028
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1029
|
+
* @param url The URL to fetch from.
|
|
1030
|
+
* @param requestInit The options for the request
|
|
1031
|
+
* @param retry The options for retrying the request if it fails
|
|
1032
|
+
* An object where the key is a status code pattern and the value is a retrying strategy.
|
|
1033
|
+
* Supported patterns are:
|
|
1034
|
+
* - Specific status codes: 429
|
|
1035
|
+
* - Ranges: 500-599
|
|
1036
|
+
* - Wildcards: 2xx, 3xx, 4xx, 5xx
|
|
1037
|
+
*/
|
|
958
1038
|
async backgroundFetchResponse(cacheKey, url, requestInit, options) {
|
|
959
1039
|
const urlObject = new URL(url);
|
|
960
1040
|
return await this.runTask(cacheKey, async (task) => {
|
|
@@ -996,6 +1076,11 @@ var IO = class {
|
|
|
996
1076
|
}
|
|
997
1077
|
});
|
|
998
1078
|
}
|
|
1079
|
+
/** `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).
|
|
1080
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1081
|
+
* @param event The event to send. The event name must match the name of the event that your Jobs are listening for.
|
|
1082
|
+
* @param options Options for sending the event.
|
|
1083
|
+
*/
|
|
999
1084
|
async sendEvent(cacheKey, event, options) {
|
|
1000
1085
|
return await this.runTask(cacheKey, async (task) => {
|
|
1001
1086
|
return await this._triggerClient.sendEvent(event, options);
|
|
@@ -1021,6 +1106,11 @@ var IO = class {
|
|
|
1021
1106
|
]
|
|
1022
1107
|
});
|
|
1023
1108
|
}
|
|
1109
|
+
/** `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).
|
|
1110
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1111
|
+
* @param event The events to send. The event names must match the names of the events that your Jobs are listening for.
|
|
1112
|
+
* @param options Options for sending the events.
|
|
1113
|
+
*/
|
|
1024
1114
|
async sendEvents(cacheKey, events, options) {
|
|
1025
1115
|
return await this.runTask(cacheKey, async (task) => {
|
|
1026
1116
|
return await this._triggerClient.sendEvents(events, options);
|
|
@@ -1056,6 +1146,11 @@ var IO = class {
|
|
|
1056
1146
|
]
|
|
1057
1147
|
});
|
|
1058
1148
|
}
|
|
1149
|
+
/** `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
|
|
1150
|
+
* @param cacheKey
|
|
1151
|
+
* @param eventId
|
|
1152
|
+
* @returns
|
|
1153
|
+
*/
|
|
1059
1154
|
async cancelEvent(cacheKey, eventId) {
|
|
1060
1155
|
return await this.runTask(cacheKey, async (task) => {
|
|
1061
1156
|
return await this._triggerClient.cancelEvent(eventId);
|
|
@@ -1107,6 +1202,14 @@ var IO = class {
|
|
|
1107
1202
|
params: options
|
|
1108
1203
|
});
|
|
1109
1204
|
}
|
|
1205
|
+
/** `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.
|
|
1206
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1207
|
+
* @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to register a new schedule on.
|
|
1208
|
+
* @param id A unique id for the interval. This is used to identify and unregister the interval later.
|
|
1209
|
+
* @param options The options for the interval.
|
|
1210
|
+
* @returns A promise that has information about the interval.
|
|
1211
|
+
* @deprecated Use `DynamicSchedule.register` instead.
|
|
1212
|
+
*/
|
|
1110
1213
|
async registerInterval(cacheKey, dynamicSchedule, id, options) {
|
|
1111
1214
|
return await this.runTask(cacheKey, async (task) => {
|
|
1112
1215
|
return dynamicSchedule.register(id, {
|
|
@@ -1132,6 +1235,12 @@ var IO = class {
|
|
|
1132
1235
|
params: options
|
|
1133
1236
|
});
|
|
1134
1237
|
}
|
|
1238
|
+
/** `io.unregisterInterval()` allows you to unregister a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that was previously registered with `io.registerInterval()`.
|
|
1239
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1240
|
+
* @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
|
|
1241
|
+
* @param id A unique id for the interval. This is used to identify and unregister the interval later.
|
|
1242
|
+
* @deprecated Use `DynamicSchedule.unregister` instead.
|
|
1243
|
+
*/
|
|
1135
1244
|
async unregisterInterval(cacheKey, dynamicSchedule, id) {
|
|
1136
1245
|
return await this.runTask(cacheKey, async (task) => {
|
|
1137
1246
|
return dynamicSchedule.unregister(id);
|
|
@@ -1149,6 +1258,13 @@ var IO = class {
|
|
|
1149
1258
|
]
|
|
1150
1259
|
});
|
|
1151
1260
|
}
|
|
1261
|
+
/** `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.
|
|
1262
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1263
|
+
* @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to register a new schedule on.
|
|
1264
|
+
* @param id A unique id for the schedule. This is used to identify and unregister the schedule later.
|
|
1265
|
+
* @param options The options for the CRON schedule.
|
|
1266
|
+
* @deprecated Use `DynamicSchedule.register` instead.
|
|
1267
|
+
*/
|
|
1152
1268
|
async registerCron(cacheKey, dynamicSchedule, id, options) {
|
|
1153
1269
|
return await this.runTask(cacheKey, async (task) => {
|
|
1154
1270
|
return dynamicSchedule.register(id, {
|
|
@@ -1174,6 +1290,12 @@ var IO = class {
|
|
|
1174
1290
|
params: options
|
|
1175
1291
|
});
|
|
1176
1292
|
}
|
|
1293
|
+
/** `io.unregisterCron()` allows you to unregister a [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) that was previously registered with `io.registerCron()`.
|
|
1294
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1295
|
+
* @param dynamicSchedule The [DynamicSchedule](https://trigger.dev/docs/sdk/dynamicschedule) to unregister a schedule on.
|
|
1296
|
+
* @param id A unique id for the interval. This is used to identify and unregister the interval later.
|
|
1297
|
+
* @deprecated Use `DynamicSchedule.unregister` instead.
|
|
1298
|
+
*/
|
|
1177
1299
|
async unregisterCron(cacheKey, dynamicSchedule, id) {
|
|
1178
1300
|
return await this.runTask(cacheKey, async (task) => {
|
|
1179
1301
|
return dynamicSchedule.unregister(id);
|
|
@@ -1191,6 +1313,13 @@ var IO = class {
|
|
|
1191
1313
|
]
|
|
1192
1314
|
});
|
|
1193
1315
|
}
|
|
1316
|
+
/** `io.registerTrigger()` allows you to register a [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger) with the specified trigger params.
|
|
1317
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1318
|
+
* @param trigger The [DynamicTrigger](https://trigger.dev/docs/sdk/dynamictrigger) to register.
|
|
1319
|
+
* @param id A unique id for the trigger. This is used to identify and unregister the trigger later.
|
|
1320
|
+
* @param params The params for the trigger.
|
|
1321
|
+
* @deprecated Use `DynamicTrigger.register` instead.
|
|
1322
|
+
*/
|
|
1194
1323
|
async registerTrigger(cacheKey, trigger, id, params) {
|
|
1195
1324
|
return await this.runTask(cacheKey, async (task) => {
|
|
1196
1325
|
const registration = await this.runTask("register-source", async (subtask1) => {
|
|
@@ -1246,6 +1375,14 @@ var IO = class {
|
|
|
1246
1375
|
});
|
|
1247
1376
|
return results;
|
|
1248
1377
|
}
|
|
1378
|
+
/** `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.
|
|
1379
|
+
*
|
|
1380
|
+
* @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.
|
|
1381
|
+
* @param callback The callback that will be called when the Task is run. The callback receives the Task and the IO as parameters.
|
|
1382
|
+
* @param options The options of how you'd like to run and log the Task.
|
|
1383
|
+
* @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.
|
|
1384
|
+
* @returns A Promise that resolves with the returned value of the callback.
|
|
1385
|
+
*/
|
|
1249
1386
|
async runTask(cacheKey, callback, options, onError) {
|
|
1250
1387
|
__privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "start_task", 500);
|
|
1251
1388
|
const parentId = this._taskStorage.getStore()?.taskId;
|
|
@@ -1299,14 +1436,14 @@ var IO = class {
|
|
|
1299
1436
|
}, {
|
|
1300
1437
|
cachedTasksCursor: this._cachedTasksCursor
|
|
1301
1438
|
});
|
|
1302
|
-
const task = response.version ===
|
|
1439
|
+
const task = response.version === core.API_VERSIONS.LAZY_LOADED_CACHED_TASKS ? response.body.task : response.body;
|
|
1303
1440
|
if (task.forceYield) {
|
|
1304
1441
|
this._logger.debug("Forcing yield after run task", {
|
|
1305
1442
|
idempotencyKey
|
|
1306
1443
|
});
|
|
1307
1444
|
__privateMethod(this, _forceYield, forceYield_fn).call(this, "after_run_task");
|
|
1308
1445
|
}
|
|
1309
|
-
if (response.version ===
|
|
1446
|
+
if (response.version === core.API_VERSIONS.LAZY_LOADED_CACHED_TASKS) {
|
|
1310
1447
|
this._cachedTasksCursor = response.body.cachedTasks?.cursor;
|
|
1311
1448
|
for (const cachedTask2 of response.body.cachedTasks?.tasks ?? []) {
|
|
1312
1449
|
if (!this._cachedTasks.has(cachedTask2.idempotencyKey)) {
|
|
@@ -1395,7 +1532,7 @@ var IO = class {
|
|
|
1395
1532
|
} else {
|
|
1396
1533
|
skipRetrying = !!onErrorResult.skipRetrying;
|
|
1397
1534
|
if (onErrorResult.retryAt && !skipRetrying) {
|
|
1398
|
-
const parsedError2 =
|
|
1535
|
+
const parsedError2 = core.ErrorWithStackSchema.safeParse(onErrorResult.error);
|
|
1399
1536
|
throw new RetryWithTaskError(parsedError2.success ? parsedError2.data : {
|
|
1400
1537
|
message: "Unknown error"
|
|
1401
1538
|
}, task, onErrorResult.retryAt);
|
|
@@ -1414,9 +1551,9 @@ var IO = class {
|
|
|
1414
1551
|
error: error.cause.output
|
|
1415
1552
|
});
|
|
1416
1553
|
}
|
|
1417
|
-
const parsedError =
|
|
1554
|
+
const parsedError = core.ErrorWithStackSchema.safeParse(error);
|
|
1418
1555
|
if (options?.retry && !skipRetrying) {
|
|
1419
|
-
const retryAt =
|
|
1556
|
+
const retryAt = core.calculateRetryAt(options.retry, task.attempts - 1);
|
|
1420
1557
|
if (retryAt) {
|
|
1421
1558
|
throw new RetryWithTaskError(parsedError.success ? parsedError.data : {
|
|
1422
1559
|
message: "Unknown error"
|
|
@@ -1462,8 +1599,11 @@ var IO = class {
|
|
|
1462
1599
|
taskId: task.id
|
|
1463
1600
|
}, executeTask);
|
|
1464
1601
|
}
|
|
1602
|
+
/**
|
|
1603
|
+
* `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.
|
|
1604
|
+
*/
|
|
1465
1605
|
yield(cacheKey) {
|
|
1466
|
-
if (!
|
|
1606
|
+
if (!core.supportsFeature("yieldExecution", this._serverVersion)) {
|
|
1467
1607
|
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
1608
|
return;
|
|
1469
1609
|
}
|
|
@@ -1472,6 +1612,12 @@ var IO = class {
|
|
|
1472
1612
|
}
|
|
1473
1613
|
throw new YieldExecutionError(cacheKey);
|
|
1474
1614
|
}
|
|
1615
|
+
/** `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).
|
|
1616
|
+
* 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.
|
|
1617
|
+
* @param tryCallback The code you wish to run
|
|
1618
|
+
* @param catchCallback Thhis will be called if the Task fails. The callback receives the error
|
|
1619
|
+
* @returns A Promise that resolves with the returned value or the error
|
|
1620
|
+
*/
|
|
1475
1621
|
async try(tryCallback, catchCallback) {
|
|
1476
1622
|
try {
|
|
1477
1623
|
return await tryCallback();
|
|
@@ -1490,7 +1636,6 @@ var IO = class {
|
|
|
1490
1636
|
};
|
|
1491
1637
|
}
|
|
1492
1638
|
};
|
|
1493
|
-
__name(IO, "IO");
|
|
1494
1639
|
_addToCachedTasks = new WeakSet();
|
|
1495
1640
|
addToCachedTasks_fn = /* @__PURE__ */ __name(function(task) {
|
|
1496
1641
|
this._cachedTasks.set(task.idempotencyKey, task);
|
|
@@ -1528,6 +1673,8 @@ getRemainingTimeInMillis_fn = /* @__PURE__ */ __name(function() {
|
|
|
1528
1673
|
}
|
|
1529
1674
|
return void 0;
|
|
1530
1675
|
}, "#getRemainingTimeInMillis");
|
|
1676
|
+
__name(_IO, "IO");
|
|
1677
|
+
var IO = _IO;
|
|
1531
1678
|
async function generateIdempotencyKey(keyMaterial) {
|
|
1532
1679
|
const keys = keyMaterial.map((key2) => {
|
|
1533
1680
|
if (typeof key2 === "string") {
|
|
@@ -1536,8 +1683,8 @@ async function generateIdempotencyKey(keyMaterial) {
|
|
|
1536
1683
|
return stableStringify(key2);
|
|
1537
1684
|
});
|
|
1538
1685
|
const key = keys.join(":");
|
|
1539
|
-
const hash = await
|
|
1540
|
-
return Buffer.from(hash).toString("hex");
|
|
1686
|
+
const hash = await crypto.webcrypto.subtle.digest("SHA-256", node_buffer.Buffer.from(key));
|
|
1687
|
+
return node_buffer.Buffer.from(hash).toString("hex");
|
|
1541
1688
|
}
|
|
1542
1689
|
__name(generateIdempotencyKey, "generateIdempotencyKey");
|
|
1543
1690
|
function stableStringify(obj) {
|
|
@@ -1560,27 +1707,33 @@ function stableStringify(obj) {
|
|
|
1560
1707
|
return JSON.stringify(sortedObj);
|
|
1561
1708
|
}
|
|
1562
1709
|
__name(stableStringify, "stableStringify");
|
|
1563
|
-
var
|
|
1710
|
+
var _IOLogger = class _IOLogger {
|
|
1564
1711
|
constructor(callback) {
|
|
1565
1712
|
this.callback = callback;
|
|
1566
1713
|
}
|
|
1714
|
+
/** Log: essential messages */
|
|
1567
1715
|
log(message, properties) {
|
|
1568
1716
|
return this.callback("LOG", message, properties);
|
|
1569
1717
|
}
|
|
1718
|
+
/** For debugging: the least important log level */
|
|
1570
1719
|
debug(message, properties) {
|
|
1571
1720
|
return this.callback("DEBUG", message, properties);
|
|
1572
1721
|
}
|
|
1722
|
+
/** Info: the second least important log level */
|
|
1573
1723
|
info(message, properties) {
|
|
1574
1724
|
return this.callback("INFO", message, properties);
|
|
1575
1725
|
}
|
|
1726
|
+
/** Warnings: the third most important log level */
|
|
1576
1727
|
warn(message, properties) {
|
|
1577
1728
|
return this.callback("WARN", message, properties);
|
|
1578
1729
|
}
|
|
1730
|
+
/** Error: The second most important log level */
|
|
1579
1731
|
error(message, properties) {
|
|
1580
1732
|
return this.callback("ERROR", message, properties);
|
|
1581
1733
|
}
|
|
1582
1734
|
};
|
|
1583
|
-
__name(
|
|
1735
|
+
__name(_IOLogger, "IOLogger");
|
|
1736
|
+
var IOLogger = _IOLogger;
|
|
1584
1737
|
async function spaceOut(callback, index, delay) {
|
|
1585
1738
|
await new Promise((resolve) => setTimeout(resolve, index * delay));
|
|
1586
1739
|
return await callback();
|
|
@@ -1612,7 +1765,7 @@ __name(sendEventOptionsProperties, "sendEventOptionsProperties");
|
|
|
1612
1765
|
|
|
1613
1766
|
// src/store/keyValueStoreClient.ts
|
|
1614
1767
|
var _serializer, _namespacedKey2, namespacedKey_fn2;
|
|
1615
|
-
var
|
|
1768
|
+
var _KeyValueStoreClient = class _KeyValueStoreClient {
|
|
1616
1769
|
constructor(queryStore, type = null, namespace = "") {
|
|
1617
1770
|
__privateAdd(this, _namespacedKey2);
|
|
1618
1771
|
__privateAdd(this, _serializer, void 0);
|
|
@@ -1659,7 +1812,6 @@ var KeyValueStoreClient = class {
|
|
|
1659
1812
|
return __privateGet(this, _serializer).deserialize(result.value);
|
|
1660
1813
|
}
|
|
1661
1814
|
};
|
|
1662
|
-
__name(KeyValueStoreClient, "KeyValueStoreClient");
|
|
1663
1815
|
_serializer = new WeakMap();
|
|
1664
1816
|
_namespacedKey2 = new WeakSet();
|
|
1665
1817
|
namespacedKey_fn2 = /* @__PURE__ */ __name(function(key) {
|
|
@@ -1673,10 +1825,12 @@ namespacedKey_fn2 = /* @__PURE__ */ __name(function(key) {
|
|
|
1673
1825
|
parts.push(key);
|
|
1674
1826
|
return parts.join(":");
|
|
1675
1827
|
}, "#namespacedKey");
|
|
1828
|
+
__name(_KeyValueStoreClient, "KeyValueStoreClient");
|
|
1829
|
+
var KeyValueStoreClient = _KeyValueStoreClient;
|
|
1676
1830
|
|
|
1677
1831
|
// src/apiClient.ts
|
|
1678
1832
|
var _apiUrl, _options, _logger, _storeClient, _queryKeyValueStore, queryKeyValueStore_fn, _apiKey, apiKey_fn;
|
|
1679
|
-
var
|
|
1833
|
+
var _ApiClient = class _ApiClient {
|
|
1680
1834
|
constructor(options) {
|
|
1681
1835
|
__privateAdd(this, _queryKeyValueStore);
|
|
1682
1836
|
__privateAdd(this, _apiKey);
|
|
@@ -1685,8 +1839,8 @@ var ApiClient = class {
|
|
|
1685
1839
|
__privateAdd(this, _logger, void 0);
|
|
1686
1840
|
__privateAdd(this, _storeClient, void 0);
|
|
1687
1841
|
__privateSet(this, _options, options);
|
|
1688
|
-
__privateSet(this, _apiUrl, __privateGet(this, _options).apiUrl ??
|
|
1689
|
-
__privateSet(this, _logger, new
|
|
1842
|
+
__privateSet(this, _apiUrl, __privateGet(this, _options).apiUrl ?? node_process.env.TRIGGER_API_URL ?? "https://api.trigger.dev");
|
|
1843
|
+
__privateSet(this, _logger, new core.Logger("trigger.dev", __privateGet(this, _options).logLevel));
|
|
1690
1844
|
__privateSet(this, _storeClient, new KeyValueStoreClient(__privateMethod(this, _queryKeyValueStore, queryKeyValueStore_fn).bind(this)));
|
|
1691
1845
|
}
|
|
1692
1846
|
async registerEndpoint(options) {
|
|
@@ -1721,15 +1875,15 @@ var ApiClient = class {
|
|
|
1721
1875
|
task
|
|
1722
1876
|
});
|
|
1723
1877
|
return await zodfetchWithVersions({
|
|
1724
|
-
[
|
|
1725
|
-
},
|
|
1878
|
+
[core.API_VERSIONS.LAZY_LOADED_CACHED_TASKS]: core.RunTaskResponseWithCachedTasksBodySchema
|
|
1879
|
+
}, core.ServerTaskSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/tasks`, {
|
|
1726
1880
|
method: "POST",
|
|
1727
1881
|
headers: {
|
|
1728
1882
|
"Content-Type": "application/json",
|
|
1729
1883
|
Authorization: `Bearer ${apiKey}`,
|
|
1730
1884
|
"Idempotency-Key": task.idempotencyKey,
|
|
1731
1885
|
"X-Cached-Tasks-Cursor": options.cachedTasksCursor ?? "",
|
|
1732
|
-
"Trigger-Version":
|
|
1886
|
+
"Trigger-Version": core.API_VERSIONS.LAZY_LOADED_CACHED_TASKS
|
|
1733
1887
|
},
|
|
1734
1888
|
body: JSON.stringify(task)
|
|
1735
1889
|
});
|
|
@@ -1739,12 +1893,12 @@ var ApiClient = class {
|
|
|
1739
1893
|
__privateGet(this, _logger).debug("Complete Task", {
|
|
1740
1894
|
task
|
|
1741
1895
|
});
|
|
1742
|
-
return await zodfetch(
|
|
1896
|
+
return await zodfetch(core.ServerTaskSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/tasks/${id}/complete`, {
|
|
1743
1897
|
method: "POST",
|
|
1744
1898
|
headers: {
|
|
1745
1899
|
"Content-Type": "application/json",
|
|
1746
1900
|
Authorization: `Bearer ${apiKey}`,
|
|
1747
|
-
"Trigger-Version":
|
|
1901
|
+
"Trigger-Version": core.API_VERSIONS.SERIALIZED_TASK_OUTPUT
|
|
1748
1902
|
},
|
|
1749
1903
|
body: JSON.stringify(task)
|
|
1750
1904
|
});
|
|
@@ -1756,7 +1910,7 @@ var ApiClient = class {
|
|
|
1756
1910
|
runId,
|
|
1757
1911
|
body
|
|
1758
1912
|
});
|
|
1759
|
-
return await zodfetch(
|
|
1913
|
+
return await zodfetch(core.ServerTaskSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/tasks/${id}/fail`, {
|
|
1760
1914
|
method: "POST",
|
|
1761
1915
|
headers: {
|
|
1762
1916
|
"Content-Type": "application/json",
|
|
@@ -1770,7 +1924,7 @@ var ApiClient = class {
|
|
|
1770
1924
|
__privateGet(this, _logger).debug("Sending event", {
|
|
1771
1925
|
event
|
|
1772
1926
|
});
|
|
1773
|
-
return await zodfetch(
|
|
1927
|
+
return await zodfetch(core.ApiEventLogSchema, `${__privateGet(this, _apiUrl)}/api/v1/events`, {
|
|
1774
1928
|
method: "POST",
|
|
1775
1929
|
headers: {
|
|
1776
1930
|
"Content-Type": "application/json",
|
|
@@ -1787,7 +1941,7 @@ var ApiClient = class {
|
|
|
1787
1941
|
__privateGet(this, _logger).debug("Sending multiple events", {
|
|
1788
1942
|
events
|
|
1789
1943
|
});
|
|
1790
|
-
return await zodfetch(
|
|
1944
|
+
return await zodfetch(core.ApiEventLogSchema.array(), `${__privateGet(this, _apiUrl)}/api/v1/events/bulk`, {
|
|
1791
1945
|
method: "POST",
|
|
1792
1946
|
headers: {
|
|
1793
1947
|
"Content-Type": "application/json",
|
|
@@ -1804,7 +1958,7 @@ var ApiClient = class {
|
|
|
1804
1958
|
__privateGet(this, _logger).debug("Cancelling event", {
|
|
1805
1959
|
eventId
|
|
1806
1960
|
});
|
|
1807
|
-
return await zodfetch(
|
|
1961
|
+
return await zodfetch(core.ApiEventLogSchema, `${__privateGet(this, _apiUrl)}/api/v1/events/${eventId}/cancel`, {
|
|
1808
1962
|
method: "POST",
|
|
1809
1963
|
headers: {
|
|
1810
1964
|
"Content-Type": "application/json",
|
|
@@ -1817,7 +1971,7 @@ var ApiClient = class {
|
|
|
1817
1971
|
__privateGet(this, _logger).debug("Cancelling runs for event", {
|
|
1818
1972
|
eventId
|
|
1819
1973
|
});
|
|
1820
|
-
return await zodfetch(
|
|
1974
|
+
return await zodfetch(core.CancelRunsForEventSchema, `${__privateGet(this, _apiUrl)}/api/v1/events/${eventId}/cancel-runs`, {
|
|
1821
1975
|
method: "POST",
|
|
1822
1976
|
headers: {
|
|
1823
1977
|
"Content-Type": "application/json",
|
|
@@ -1831,7 +1985,7 @@ var ApiClient = class {
|
|
|
1831
1985
|
id,
|
|
1832
1986
|
status
|
|
1833
1987
|
});
|
|
1834
|
-
return await zodfetch(
|
|
1988
|
+
return await zodfetch(core.JobRunStatusRecordSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/statuses/${id}`, {
|
|
1835
1989
|
method: "PUT",
|
|
1836
1990
|
headers: {
|
|
1837
1991
|
"Content-Type": "application/json",
|
|
@@ -1845,7 +1999,7 @@ var ApiClient = class {
|
|
|
1845
1999
|
__privateGet(this, _logger).debug("activating http source", {
|
|
1846
2000
|
source
|
|
1847
2001
|
});
|
|
1848
|
-
const response = await zodfetch(
|
|
2002
|
+
const response = await zodfetch(core.TriggerSourceSchema, `${__privateGet(this, _apiUrl)}/api/v2/${client}/sources/${key}`, {
|
|
1849
2003
|
method: "PUT",
|
|
1850
2004
|
headers: {
|
|
1851
2005
|
"Content-Type": "application/json",
|
|
@@ -1860,7 +2014,7 @@ var ApiClient = class {
|
|
|
1860
2014
|
__privateGet(this, _logger).debug("activating webhook", {
|
|
1861
2015
|
webhookData
|
|
1862
2016
|
});
|
|
1863
|
-
const response = await zodfetch(
|
|
2017
|
+
const response = await zodfetch(core.TriggerSourceSchema, `${__privateGet(this, _apiUrl)}/api/v1/webhooks/${key}`, {
|
|
1864
2018
|
method: "PUT",
|
|
1865
2019
|
headers: {
|
|
1866
2020
|
"Content-Type": "application/json",
|
|
@@ -1883,7 +2037,7 @@ var ApiClient = class {
|
|
|
1883
2037
|
if (idempotencyKey) {
|
|
1884
2038
|
headers["Idempotency-Key"] = idempotencyKey;
|
|
1885
2039
|
}
|
|
1886
|
-
const response = await zodfetch(
|
|
2040
|
+
const response = await zodfetch(core.RegisterSourceEventSchemaV2, `${__privateGet(this, _apiUrl)}/api/v2/${client}/triggers/${id}/registrations/${key}`, {
|
|
1887
2041
|
method: "PUT",
|
|
1888
2042
|
headers,
|
|
1889
2043
|
body: JSON.stringify(payload)
|
|
@@ -1896,7 +2050,7 @@ var ApiClient = class {
|
|
|
1896
2050
|
id,
|
|
1897
2051
|
payload
|
|
1898
2052
|
});
|
|
1899
|
-
const response = await zodfetch(
|
|
2053
|
+
const response = await zodfetch(core.RegisterScheduleResponseBodySchema, `${__privateGet(this, _apiUrl)}/api/v1/${client}/schedules/${id}/registrations`, {
|
|
1900
2054
|
method: "POST",
|
|
1901
2055
|
headers: {
|
|
1902
2056
|
"Content-Type": "application/json",
|
|
@@ -1914,8 +2068,8 @@ var ApiClient = class {
|
|
|
1914
2068
|
__privateGet(this, _logger).debug("unregistering schedule", {
|
|
1915
2069
|
id
|
|
1916
2070
|
});
|
|
1917
|
-
const response = await zodfetch(
|
|
1918
|
-
ok:
|
|
2071
|
+
const response = await zodfetch(zod.z.object({
|
|
2072
|
+
ok: zod.z.boolean()
|
|
1919
2073
|
}), `${__privateGet(this, _apiUrl)}/api/v1/${client}/schedules/${id}/registrations/${encodeURIComponent(key)}`, {
|
|
1920
2074
|
method: "DELETE",
|
|
1921
2075
|
headers: {
|
|
@@ -1930,7 +2084,7 @@ var ApiClient = class {
|
|
|
1930
2084
|
__privateGet(this, _logger).debug("getting auth", {
|
|
1931
2085
|
id
|
|
1932
2086
|
});
|
|
1933
|
-
const response = await zodfetch(
|
|
2087
|
+
const response = await zodfetch(core.ConnectionAuthSchema, `${__privateGet(this, _apiUrl)}/api/v1/${client}/auth/${id}`, {
|
|
1934
2088
|
method: "GET",
|
|
1935
2089
|
headers: {
|
|
1936
2090
|
Accept: "application/json",
|
|
@@ -1946,7 +2100,7 @@ var ApiClient = class {
|
|
|
1946
2100
|
__privateGet(this, _logger).debug("Getting Event", {
|
|
1947
2101
|
eventId
|
|
1948
2102
|
});
|
|
1949
|
-
return await zodfetch(
|
|
2103
|
+
return await zodfetch(core.GetEventSchema, `${__privateGet(this, _apiUrl)}/api/v1/events/${eventId}`, {
|
|
1950
2104
|
method: "GET",
|
|
1951
2105
|
headers: {
|
|
1952
2106
|
Authorization: `Bearer ${apiKey}`
|
|
@@ -1958,7 +2112,7 @@ var ApiClient = class {
|
|
|
1958
2112
|
__privateGet(this, _logger).debug("Getting Run", {
|
|
1959
2113
|
runId
|
|
1960
2114
|
});
|
|
1961
|
-
return await zodfetch(
|
|
2115
|
+
return await zodfetch(core.GetRunSchema, core.urlWithSearchParams(`${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}`, options), {
|
|
1962
2116
|
method: "GET",
|
|
1963
2117
|
headers: {
|
|
1964
2118
|
Authorization: `Bearer ${apiKey}`
|
|
@@ -1970,7 +2124,7 @@ var ApiClient = class {
|
|
|
1970
2124
|
__privateGet(this, _logger).debug("Cancelling Run", {
|
|
1971
2125
|
runId
|
|
1972
2126
|
});
|
|
1973
|
-
return await zodfetch(
|
|
2127
|
+
return await zodfetch(core.GetRunSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/cancel`, {
|
|
1974
2128
|
method: "POST",
|
|
1975
2129
|
headers: {
|
|
1976
2130
|
"Content-Type": "application/json",
|
|
@@ -1983,7 +2137,7 @@ var ApiClient = class {
|
|
|
1983
2137
|
__privateGet(this, _logger).debug("Getting Run statuses", {
|
|
1984
2138
|
runId
|
|
1985
2139
|
});
|
|
1986
|
-
return await zodfetch(
|
|
2140
|
+
return await zodfetch(core.GetRunStatusesSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/statuses`, {
|
|
1987
2141
|
method: "GET",
|
|
1988
2142
|
headers: {
|
|
1989
2143
|
Authorization: `Bearer ${apiKey}`
|
|
@@ -1995,7 +2149,7 @@ var ApiClient = class {
|
|
|
1995
2149
|
__privateGet(this, _logger).debug("Getting Runs", {
|
|
1996
2150
|
jobSlug
|
|
1997
2151
|
});
|
|
1998
|
-
return await zodfetch(
|
|
2152
|
+
return await zodfetch(core.GetRunsSchema, core.urlWithSearchParams(`${__privateGet(this, _apiUrl)}/api/v1/jobs/${jobSlug}/runs`, options), {
|
|
1999
2153
|
method: "GET",
|
|
2000
2154
|
headers: {
|
|
2001
2155
|
Authorization: `Bearer ${apiKey}`
|
|
@@ -2015,7 +2169,7 @@ var ApiClient = class {
|
|
|
2015
2169
|
callbackUrl: options.callbackUrl
|
|
2016
2170
|
}
|
|
2017
2171
|
};
|
|
2018
|
-
return await zodfetch(
|
|
2172
|
+
return await zodfetch(core.InvokeJobResponseSchema, `${__privateGet(this, _apiUrl)}/api/v1/jobs/${jobId}/invoke`, {
|
|
2019
2173
|
method: "POST",
|
|
2020
2174
|
headers: {
|
|
2021
2175
|
"Content-Type": "application/json",
|
|
@@ -2032,7 +2186,7 @@ var ApiClient = class {
|
|
|
2032
2186
|
__privateGet(this, _logger).debug("Creating ephemeral event dispatcher", {
|
|
2033
2187
|
payload
|
|
2034
2188
|
});
|
|
2035
|
-
const response = await zodfetch(
|
|
2189
|
+
const response = await zodfetch(core.EphemeralEventDispatcherResponseBodySchema, `${__privateGet(this, _apiUrl)}/api/v1/event-dispatchers/ephemeral`, {
|
|
2036
2190
|
method: "POST",
|
|
2037
2191
|
headers: {
|
|
2038
2192
|
"Content-Type": "application/json",
|
|
@@ -2046,7 +2200,6 @@ var ApiClient = class {
|
|
|
2046
2200
|
return __privateGet(this, _storeClient);
|
|
2047
2201
|
}
|
|
2048
2202
|
};
|
|
2049
|
-
__name(ApiClient, "ApiClient");
|
|
2050
2203
|
_apiUrl = new WeakMap();
|
|
2051
2204
|
_options = new WeakMap();
|
|
2052
2205
|
_logger = new WeakMap();
|
|
@@ -2105,10 +2258,10 @@ queryKeyValueStore_fn = /* @__PURE__ */ __name(async function(action, data) {
|
|
|
2105
2258
|
break;
|
|
2106
2259
|
}
|
|
2107
2260
|
default: {
|
|
2108
|
-
|
|
2261
|
+
core.assertExhaustive(action);
|
|
2109
2262
|
}
|
|
2110
2263
|
}
|
|
2111
|
-
const response = await zodfetch(
|
|
2264
|
+
const response = await zodfetch(core.KeyValueStoreResponseBodySchema, STORE_URL, requestInit);
|
|
2112
2265
|
return response;
|
|
2113
2266
|
}, "#queryKeyValueStore");
|
|
2114
2267
|
_apiKey = new WeakSet();
|
|
@@ -2121,8 +2274,10 @@ apiKey_fn = /* @__PURE__ */ __name(async function() {
|
|
|
2121
2274
|
}
|
|
2122
2275
|
return apiKey.apiKey;
|
|
2123
2276
|
}, "#apiKey");
|
|
2277
|
+
__name(_ApiClient, "ApiClient");
|
|
2278
|
+
var ApiClient = _ApiClient;
|
|
2124
2279
|
function getApiKey(key) {
|
|
2125
|
-
const apiKey = key ??
|
|
2280
|
+
const apiKey = key ?? node_process.env.TRIGGER_API_KEY;
|
|
2126
2281
|
if (!apiKey) {
|
|
2127
2282
|
return {
|
|
2128
2283
|
status: "missing"
|
|
@@ -2142,10 +2297,7 @@ function getApiKey(key) {
|
|
|
2142
2297
|
}
|
|
2143
2298
|
__name(getApiKey, "getApiKey");
|
|
2144
2299
|
async function zodfetchWithVersions(versionedSchemaMap, unversionedSchema, url, requestInit, options, retryCount = 0) {
|
|
2145
|
-
const response = await fetch(url,
|
|
2146
|
-
...requestInit,
|
|
2147
|
-
cache: "no-cache"
|
|
2148
|
-
});
|
|
2300
|
+
const response = await fetch(url, requestInitWithCache(requestInit));
|
|
2149
2301
|
if ((!requestInit || requestInit.method === "GET") && response.status === 404 && options?.optional) {
|
|
2150
2302
|
return;
|
|
2151
2303
|
}
|
|
@@ -2179,15 +2331,25 @@ async function zodfetchWithVersions(versionedSchemaMap, unversionedSchema, url,
|
|
|
2179
2331
|
};
|
|
2180
2332
|
}
|
|
2181
2333
|
__name(zodfetchWithVersions, "zodfetchWithVersions");
|
|
2334
|
+
function requestInitWithCache(requestInit) {
|
|
2335
|
+
try {
|
|
2336
|
+
const withCache = {
|
|
2337
|
+
...requestInit,
|
|
2338
|
+
cache: "no-cache"
|
|
2339
|
+
};
|
|
2340
|
+
const _ = new Request("http://localhost", withCache);
|
|
2341
|
+
return withCache;
|
|
2342
|
+
} catch (error) {
|
|
2343
|
+
return requestInit ?? {};
|
|
2344
|
+
}
|
|
2345
|
+
}
|
|
2346
|
+
__name(requestInitWithCache, "requestInitWithCache");
|
|
2182
2347
|
async function fetchHead(url, requestInitWithoutMethod, retryCount = 0) {
|
|
2183
2348
|
const requestInit = {
|
|
2184
2349
|
...requestInitWithoutMethod,
|
|
2185
2350
|
method: "HEAD"
|
|
2186
2351
|
};
|
|
2187
|
-
const response = await fetch(url,
|
|
2188
|
-
...requestInit,
|
|
2189
|
-
cache: "no-cache"
|
|
2190
|
-
});
|
|
2352
|
+
const response = await fetch(url, requestInitWithCache(requestInit));
|
|
2191
2353
|
if (response.status >= 500 && retryCount < 6) {
|
|
2192
2354
|
const delay = exponentialBackoff(retryCount + 1, 2, 50, 1150, 50);
|
|
2193
2355
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
@@ -2197,10 +2359,7 @@ async function fetchHead(url, requestInitWithoutMethod, retryCount = 0) {
|
|
|
2197
2359
|
}
|
|
2198
2360
|
__name(fetchHead, "fetchHead");
|
|
2199
2361
|
async function zodfetch(schema, url, requestInit, options, retryCount = 0) {
|
|
2200
|
-
const response = await fetch(url,
|
|
2201
|
-
...requestInit,
|
|
2202
|
-
cache: "no-cache"
|
|
2203
|
-
});
|
|
2362
|
+
const response = await fetch(url, requestInitWithCache(requestInit));
|
|
2204
2363
|
if ((!requestInit || requestInit.method === "GET") && response.status === 404 && options?.optional) {
|
|
2205
2364
|
return;
|
|
2206
2365
|
}
|
|
@@ -2227,9 +2386,6 @@ function exponentialBackoff(retryCount, exponential, minDelay, maxDelay, jitter)
|
|
|
2227
2386
|
}
|
|
2228
2387
|
__name(exponentialBackoff, "exponentialBackoff");
|
|
2229
2388
|
|
|
2230
|
-
// src/httpEndpoint.ts
|
|
2231
|
-
var import_core4 = require("@trigger.dev/core");
|
|
2232
|
-
|
|
2233
2389
|
// src/utils/formatSchemaErrors.ts
|
|
2234
2390
|
function formatSchemaErrors(errors) {
|
|
2235
2391
|
return errors.map((error) => {
|
|
@@ -2243,7 +2399,7 @@ function formatSchemaErrors(errors) {
|
|
|
2243
2399
|
__name(formatSchemaErrors, "formatSchemaErrors");
|
|
2244
2400
|
|
|
2245
2401
|
// src/httpEndpoint.ts
|
|
2246
|
-
var
|
|
2402
|
+
var _HttpEndpoint = class _HttpEndpoint {
|
|
2247
2403
|
constructor(options) {
|
|
2248
2404
|
this.options = options;
|
|
2249
2405
|
}
|
|
@@ -2258,6 +2414,7 @@ var HttpEndpoint = class {
|
|
|
2258
2414
|
verify: this.options.verify
|
|
2259
2415
|
});
|
|
2260
2416
|
}
|
|
2417
|
+
// @internal
|
|
2261
2418
|
async handleRequest(request) {
|
|
2262
2419
|
if (!this.options.respondWith)
|
|
2263
2420
|
return;
|
|
@@ -2279,8 +2436,10 @@ var HttpEndpoint = class {
|
|
|
2279
2436
|
};
|
|
2280
2437
|
}
|
|
2281
2438
|
};
|
|
2282
|
-
__name(
|
|
2283
|
-
var
|
|
2439
|
+
__name(_HttpEndpoint, "HttpEndpoint");
|
|
2440
|
+
var HttpEndpoint = _HttpEndpoint;
|
|
2441
|
+
var _a;
|
|
2442
|
+
var HttpTrigger = (_a = class {
|
|
2284
2443
|
constructor(options) {
|
|
2285
2444
|
this.options = options;
|
|
2286
2445
|
}
|
|
@@ -2315,7 +2474,7 @@ var HttpTrigger = /* @__PURE__ */ __name(class HttpTrigger2 {
|
|
|
2315
2474
|
const clonedRequest = payload.clone();
|
|
2316
2475
|
return this.options.verify(clonedRequest);
|
|
2317
2476
|
}
|
|
2318
|
-
}, "HttpTrigger");
|
|
2477
|
+
}, __name(_a, "HttpTrigger"), _a);
|
|
2319
2478
|
function httpEndpoint(options) {
|
|
2320
2479
|
const id = slugifyId(options.id);
|
|
2321
2480
|
return new HttpEndpoint({
|
|
@@ -2347,7 +2506,7 @@ function httpEndpoint(options) {
|
|
|
2347
2506
|
}
|
|
2348
2507
|
],
|
|
2349
2508
|
parsePayload: (rawPayload) => {
|
|
2350
|
-
const result =
|
|
2509
|
+
const result = core.RequestWithRawBodySchema.safeParse(rawPayload);
|
|
2351
2510
|
if (!result.success) {
|
|
2352
2511
|
throw new ParsedPayloadSchemaError(formatSchemaErrors(result.error.issues));
|
|
2353
2512
|
}
|
|
@@ -2390,11 +2549,12 @@ function createIOWithIntegrations(io, auths, integrations) {
|
|
|
2390
2549
|
});
|
|
2391
2550
|
}
|
|
2392
2551
|
__name(createIOWithIntegrations, "createIOWithIntegrations");
|
|
2393
|
-
|
|
2394
|
-
// src/triggers/dynamic.ts
|
|
2395
|
-
var import_core5 = require("@trigger.dev/core");
|
|
2396
2552
|
var _client, _options2;
|
|
2397
|
-
var
|
|
2553
|
+
var _DynamicTrigger = class _DynamicTrigger {
|
|
2554
|
+
/** `DynamicTrigger` allows you to define a trigger that can be configured dynamically at runtime.
|
|
2555
|
+
* @param client The `TriggerClient` instance to use for registering the trigger.
|
|
2556
|
+
* @param options The options for the dynamic trigger.
|
|
2557
|
+
* */
|
|
2398
2558
|
constructor(client, options) {
|
|
2399
2559
|
__privateAdd(this, _client, void 0);
|
|
2400
2560
|
__privateAdd(this, _options2, void 0);
|
|
@@ -2415,19 +2575,21 @@ var DynamicTrigger = class {
|
|
|
2415
2575
|
get event() {
|
|
2416
2576
|
return __privateGet(this, _options2).event;
|
|
2417
2577
|
}
|
|
2578
|
+
// @internal
|
|
2418
2579
|
registeredTriggerForParams(params, options = {}) {
|
|
2419
2580
|
const key = slugifyId(this.source.key(params));
|
|
2420
2581
|
return {
|
|
2421
2582
|
rule: {
|
|
2422
2583
|
event: this.event.name,
|
|
2423
2584
|
source: this.event.source,
|
|
2424
|
-
payload:
|
|
2585
|
+
payload: core.deepMergeFilters(this.source.filter(params), this.event.filter ?? {}, options.filter ?? {})
|
|
2425
2586
|
},
|
|
2426
2587
|
source: {
|
|
2427
2588
|
version: "2",
|
|
2428
2589
|
key,
|
|
2429
2590
|
channel: this.source.channel,
|
|
2430
2591
|
params,
|
|
2592
|
+
//todo add other options here
|
|
2431
2593
|
options: {
|
|
2432
2594
|
event: typeof this.event.name === "string" ? [
|
|
2433
2595
|
this.event.name
|
|
@@ -2442,6 +2604,14 @@ var DynamicTrigger = class {
|
|
|
2442
2604
|
accountId: options.accountId
|
|
2443
2605
|
};
|
|
2444
2606
|
}
|
|
2607
|
+
/** Use this method to register a new configuration with the DynamicTrigger.
|
|
2608
|
+
* @param key The key for the configuration. This will be used to identify the configuration when it is triggered.
|
|
2609
|
+
* @param params The params for the configuration.
|
|
2610
|
+
* @param options Options for the configuration.
|
|
2611
|
+
* @param options.accountId The accountId to associate with the configuration.
|
|
2612
|
+
* @param options.filter The filter to use for the configuration.
|
|
2613
|
+
*
|
|
2614
|
+
*/
|
|
2445
2615
|
async register(key, params, options = {}) {
|
|
2446
2616
|
const runStore = runLocalStorage.getStore();
|
|
2447
2617
|
if (!runStore) {
|
|
@@ -2480,14 +2650,12 @@ var DynamicTrigger = class {
|
|
|
2480
2650
|
};
|
|
2481
2651
|
}
|
|
2482
2652
|
};
|
|
2483
|
-
__name(DynamicTrigger, "DynamicTrigger");
|
|
2484
2653
|
_client = new WeakMap();
|
|
2485
2654
|
_options2 = new WeakMap();
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
var import_core6 = require("@trigger.dev/core");
|
|
2655
|
+
__name(_DynamicTrigger, "DynamicTrigger");
|
|
2656
|
+
var DynamicTrigger = _DynamicTrigger;
|
|
2489
2657
|
var _options3;
|
|
2490
|
-
var
|
|
2658
|
+
var _EventTrigger = class _EventTrigger {
|
|
2491
2659
|
constructor(options) {
|
|
2492
2660
|
__privateAdd(this, _options3, void 0);
|
|
2493
2661
|
__privateSet(this, _options3, options);
|
|
@@ -2499,7 +2667,7 @@ var EventTrigger = class {
|
|
|
2499
2667
|
rule: {
|
|
2500
2668
|
event: __privateGet(this, _options3).name ?? __privateGet(this, _options3).event.name,
|
|
2501
2669
|
source: __privateGet(this, _options3).source ?? "trigger.dev",
|
|
2502
|
-
payload:
|
|
2670
|
+
payload: core.deepMergeFilters(__privateGet(this, _options3).filter ?? {}, __privateGet(this, _options3).event.filter ?? {})
|
|
2503
2671
|
}
|
|
2504
2672
|
};
|
|
2505
2673
|
}
|
|
@@ -2523,8 +2691,9 @@ var EventTrigger = class {
|
|
|
2523
2691
|
};
|
|
2524
2692
|
}
|
|
2525
2693
|
};
|
|
2526
|
-
__name(EventTrigger, "EventTrigger");
|
|
2527
2694
|
_options3 = new WeakMap();
|
|
2695
|
+
__name(_EventTrigger, "EventTrigger");
|
|
2696
|
+
var EventTrigger = _EventTrigger;
|
|
2528
2697
|
function eventTrigger(options) {
|
|
2529
2698
|
return new EventTrigger({
|
|
2530
2699
|
name: options.name,
|
|
@@ -2549,22 +2718,18 @@ function eventTrigger(options) {
|
|
|
2549
2718
|
});
|
|
2550
2719
|
}
|
|
2551
2720
|
__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
2721
|
var examples = [
|
|
2557
2722
|
{
|
|
2558
2723
|
id: "now",
|
|
2559
2724
|
name: "Now",
|
|
2560
2725
|
icon: "clock",
|
|
2561
2726
|
payload: {
|
|
2562
|
-
ts:
|
|
2563
|
-
lastTimestamp:
|
|
2727
|
+
ts: core.currentDate.marker,
|
|
2728
|
+
lastTimestamp: core.currentDate.marker
|
|
2564
2729
|
}
|
|
2565
2730
|
}
|
|
2566
2731
|
];
|
|
2567
|
-
var
|
|
2732
|
+
var _IntervalTrigger = class _IntervalTrigger {
|
|
2568
2733
|
constructor(options) {
|
|
2569
2734
|
this.options = options;
|
|
2570
2735
|
}
|
|
@@ -2575,7 +2740,7 @@ var IntervalTrigger = class {
|
|
|
2575
2740
|
source: "trigger.dev",
|
|
2576
2741
|
icon: "schedule-interval",
|
|
2577
2742
|
examples,
|
|
2578
|
-
parsePayload:
|
|
2743
|
+
parsePayload: core.ScheduledPayloadSchema.parse,
|
|
2579
2744
|
properties: [
|
|
2580
2745
|
{
|
|
2581
2746
|
label: "Interval",
|
|
@@ -2606,17 +2771,18 @@ var IntervalTrigger = class {
|
|
|
2606
2771
|
};
|
|
2607
2772
|
}
|
|
2608
2773
|
};
|
|
2609
|
-
__name(
|
|
2774
|
+
__name(_IntervalTrigger, "IntervalTrigger");
|
|
2775
|
+
var IntervalTrigger = _IntervalTrigger;
|
|
2610
2776
|
function intervalTrigger(options) {
|
|
2611
2777
|
return new IntervalTrigger(options);
|
|
2612
2778
|
}
|
|
2613
2779
|
__name(intervalTrigger, "intervalTrigger");
|
|
2614
|
-
var
|
|
2780
|
+
var _CronTrigger = class _CronTrigger {
|
|
2615
2781
|
constructor(options) {
|
|
2616
2782
|
this.options = options;
|
|
2617
2783
|
}
|
|
2618
2784
|
get event() {
|
|
2619
|
-
const humanReadable =
|
|
2785
|
+
const humanReadable = cronstrue__default.default.toString(this.options.cron, {
|
|
2620
2786
|
throwExceptionOnParseError: false
|
|
2621
2787
|
});
|
|
2622
2788
|
return {
|
|
@@ -2625,7 +2791,7 @@ var CronTrigger = class {
|
|
|
2625
2791
|
source: "trigger.dev",
|
|
2626
2792
|
icon: "schedule-cron",
|
|
2627
2793
|
examples,
|
|
2628
|
-
parsePayload:
|
|
2794
|
+
parsePayload: core.ScheduledPayloadSchema.parse,
|
|
2629
2795
|
properties: [
|
|
2630
2796
|
{
|
|
2631
2797
|
label: "cron",
|
|
@@ -2660,12 +2826,17 @@ var CronTrigger = class {
|
|
|
2660
2826
|
};
|
|
2661
2827
|
}
|
|
2662
2828
|
};
|
|
2663
|
-
__name(
|
|
2829
|
+
__name(_CronTrigger, "CronTrigger");
|
|
2830
|
+
var CronTrigger = _CronTrigger;
|
|
2664
2831
|
function cronTrigger(options) {
|
|
2665
2832
|
return new CronTrigger(options);
|
|
2666
2833
|
}
|
|
2667
2834
|
__name(cronTrigger, "cronTrigger");
|
|
2668
|
-
var
|
|
2835
|
+
var _DynamicSchedule = class _DynamicSchedule {
|
|
2836
|
+
/**
|
|
2837
|
+
* @param client The `TriggerClient` instance to use for registering the trigger.
|
|
2838
|
+
* @param options The options for the schedule.
|
|
2839
|
+
*/
|
|
2669
2840
|
constructor(client, options) {
|
|
2670
2841
|
this.client = client;
|
|
2671
2842
|
this.options = options;
|
|
@@ -2681,7 +2852,7 @@ var DynamicSchedule = class {
|
|
|
2681
2852
|
source: "trigger.dev",
|
|
2682
2853
|
icon: "schedule-dynamic",
|
|
2683
2854
|
examples,
|
|
2684
|
-
parsePayload:
|
|
2855
|
+
parsePayload: core.ScheduledPayloadSchema.parse
|
|
2685
2856
|
};
|
|
2686
2857
|
}
|
|
2687
2858
|
async register(key, metadata) {
|
|
@@ -2755,16 +2926,14 @@ var DynamicSchedule = class {
|
|
|
2755
2926
|
};
|
|
2756
2927
|
}
|
|
2757
2928
|
};
|
|
2758
|
-
__name(
|
|
2759
|
-
|
|
2760
|
-
// src/triggerClient.ts
|
|
2761
|
-
var import_node_events = __toESM(require("events"));
|
|
2929
|
+
__name(_DynamicSchedule, "DynamicSchedule");
|
|
2930
|
+
var DynamicSchedule = _DynamicSchedule;
|
|
2762
2931
|
|
|
2763
2932
|
// package.json
|
|
2764
|
-
var version = "2.
|
|
2933
|
+
var version = "2.3.0";
|
|
2765
2934
|
|
|
2766
2935
|
// src/concurrencyLimit.ts
|
|
2767
|
-
var
|
|
2936
|
+
var _ConcurrencyLimit = class _ConcurrencyLimit {
|
|
2768
2937
|
constructor(options) {
|
|
2769
2938
|
this.options = options;
|
|
2770
2939
|
}
|
|
@@ -2775,25 +2944,26 @@ var ConcurrencyLimit = class {
|
|
|
2775
2944
|
return this.options.limit;
|
|
2776
2945
|
}
|
|
2777
2946
|
};
|
|
2778
|
-
__name(
|
|
2947
|
+
__name(_ConcurrencyLimit, "ConcurrencyLimit");
|
|
2948
|
+
var ConcurrencyLimit = _ConcurrencyLimit;
|
|
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 core.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 core.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
|