@trigger.dev/sdk 2.2.3 → 2.2.5
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.ts +308 -40
- package/dist/index.js +934 -176
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/dist/index.js
CHANGED
|
@@ -57,12 +57,15 @@ __export(src_exports, {
|
|
|
57
57
|
CronTrigger: () => CronTrigger,
|
|
58
58
|
DynamicSchedule: () => DynamicSchedule,
|
|
59
59
|
DynamicTrigger: () => DynamicTrigger,
|
|
60
|
+
EventSpecificationExampleSchema: () => EventSpecificationExampleSchema,
|
|
60
61
|
EventTrigger: () => EventTrigger,
|
|
61
62
|
ExternalSource: () => ExternalSource,
|
|
62
63
|
ExternalSourceTrigger: () => ExternalSourceTrigger,
|
|
63
64
|
IO: () => IO,
|
|
64
65
|
IOLogger: () => IOLogger,
|
|
65
66
|
IntervalTrigger: () => IntervalTrigger,
|
|
67
|
+
InvokeTrigger: () => InvokeTrigger,
|
|
68
|
+
JSONOutputSerializer: () => JSONOutputSerializer,
|
|
66
69
|
Job: () => Job,
|
|
67
70
|
MissingConnectionNotification: () => MissingConnectionNotification,
|
|
68
71
|
MissingConnectionResolvedNotification: () => MissingConnectionResolvedNotification,
|
|
@@ -70,12 +73,15 @@ __export(src_exports, {
|
|
|
70
73
|
cronTrigger: () => cronTrigger,
|
|
71
74
|
eventTrigger: () => eventTrigger,
|
|
72
75
|
intervalTrigger: () => intervalTrigger,
|
|
76
|
+
invokeTrigger: () => invokeTrigger,
|
|
73
77
|
isTriggerError: () => isTriggerError,
|
|
74
78
|
missingConnectionNotification: () => missingConnectionNotification,
|
|
75
79
|
missingConnectionResolvedNotification: () => missingConnectionResolvedNotification,
|
|
76
80
|
omit: () => omit,
|
|
77
81
|
redactString: () => redactString,
|
|
78
|
-
retry: () => retry
|
|
82
|
+
retry: () => retry,
|
|
83
|
+
verifyHmacSha256: () => verifyHmacSha256,
|
|
84
|
+
verifyRequestSignature: () => verifyRequestSignature
|
|
79
85
|
});
|
|
80
86
|
module.exports = __toCommonJS(src_exports);
|
|
81
87
|
|
|
@@ -87,6 +93,24 @@ function slugifyId(input) {
|
|
|
87
93
|
}
|
|
88
94
|
__name(slugifyId, "slugifyId");
|
|
89
95
|
|
|
96
|
+
// src/utils/typedAsyncLocalStorage.ts
|
|
97
|
+
var import_node_async_hooks = require("async_hooks");
|
|
98
|
+
var TypedAsyncLocalStorage = class {
|
|
99
|
+
constructor() {
|
|
100
|
+
this.storage = new import_node_async_hooks.AsyncLocalStorage();
|
|
101
|
+
}
|
|
102
|
+
runWith(context, fn) {
|
|
103
|
+
return this.storage.run(context, fn);
|
|
104
|
+
}
|
|
105
|
+
getStore() {
|
|
106
|
+
return this.storage.getStore();
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
__name(TypedAsyncLocalStorage, "TypedAsyncLocalStorage");
|
|
110
|
+
|
|
111
|
+
// src/runLocalStorage.ts
|
|
112
|
+
var runLocalStorage = new TypedAsyncLocalStorage();
|
|
113
|
+
|
|
90
114
|
// src/job.ts
|
|
91
115
|
var _validate, validate_fn;
|
|
92
116
|
var Job = class {
|
|
@@ -141,6 +165,118 @@ var Job = class {
|
|
|
141
165
|
internal
|
|
142
166
|
};
|
|
143
167
|
}
|
|
168
|
+
async invoke(param1, param2 = void 0, param3 = void 0) {
|
|
169
|
+
const runStore = runLocalStorage.getStore();
|
|
170
|
+
if (typeof param1 === "string") {
|
|
171
|
+
if (!runStore) {
|
|
172
|
+
throw new Error("Cannot invoke a job from outside of a run when passing a cacheKey. Make sure you are running the job from within a run or use the invoke method without the cacheKey.");
|
|
173
|
+
}
|
|
174
|
+
const options = param3 ?? {};
|
|
175
|
+
return await runStore.io.runTask(param1, async (task) => {
|
|
176
|
+
const result = await this.client.invokeJob(this.id, param2, {
|
|
177
|
+
idempotencyKey: task.idempotencyKey,
|
|
178
|
+
...options
|
|
179
|
+
});
|
|
180
|
+
task.outputProperties = [
|
|
181
|
+
{
|
|
182
|
+
label: "Run",
|
|
183
|
+
text: result.id,
|
|
184
|
+
url: `/orgs/${runStore.ctx.organization.slug}/projects/${runStore.ctx.project.slug}/jobs/${this.id}/runs/${result.id}/trigger`
|
|
185
|
+
}
|
|
186
|
+
];
|
|
187
|
+
return result;
|
|
188
|
+
}, {
|
|
189
|
+
name: `Manually Invoke '${this.name}'`,
|
|
190
|
+
params: param2,
|
|
191
|
+
properties: [
|
|
192
|
+
{
|
|
193
|
+
label: "Job",
|
|
194
|
+
text: this.id,
|
|
195
|
+
url: `/orgs/${runStore.ctx.organization.slug}/projects/${runStore.ctx.project.slug}/jobs/${this.id}`
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
label: "Env",
|
|
199
|
+
text: runStore.ctx.environment.slug
|
|
200
|
+
}
|
|
201
|
+
]
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
if (runStore) {
|
|
205
|
+
throw new Error("Cannot invoke a job from within a run without a cacheKey.");
|
|
206
|
+
}
|
|
207
|
+
return await this.client.invokeJob(this.id, param1, param3);
|
|
208
|
+
}
|
|
209
|
+
async invokeAndWaitForCompletion(cacheKey, payload, timeoutInSeconds = 60 * 60, options = {}) {
|
|
210
|
+
const runStore = runLocalStorage.getStore();
|
|
211
|
+
if (!runStore) {
|
|
212
|
+
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.");
|
|
213
|
+
}
|
|
214
|
+
const { io, ctx } = runStore;
|
|
215
|
+
return await io.runTask(cacheKey, async (task) => {
|
|
216
|
+
const parsedPayload = this.trigger.event.parseInvokePayload ? this.trigger.event.parseInvokePayload(payload) ? payload : void 0 : payload;
|
|
217
|
+
const result = await this.client.invokeJob(this.id, parsedPayload, {
|
|
218
|
+
idempotencyKey: task.idempotencyKey,
|
|
219
|
+
callbackUrl: task.callbackUrl ?? void 0,
|
|
220
|
+
...options
|
|
221
|
+
});
|
|
222
|
+
task.outputProperties = [
|
|
223
|
+
{
|
|
224
|
+
label: "Run",
|
|
225
|
+
text: result.id,
|
|
226
|
+
url: `/orgs/${ctx.organization.slug}/projects/${ctx.project.slug}/jobs/${this.id}/runs/${result.id}/trigger`
|
|
227
|
+
}
|
|
228
|
+
];
|
|
229
|
+
return {};
|
|
230
|
+
}, {
|
|
231
|
+
name: `Manually Invoke '${this.name}' and wait for completion`,
|
|
232
|
+
params: payload,
|
|
233
|
+
properties: [
|
|
234
|
+
{
|
|
235
|
+
label: "Job",
|
|
236
|
+
text: this.id,
|
|
237
|
+
url: `/orgs/${ctx.organization.slug}/projects/${ctx.project.slug}/jobs/${this.id}`
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
label: "Env",
|
|
241
|
+
text: ctx.environment.slug
|
|
242
|
+
}
|
|
243
|
+
],
|
|
244
|
+
callback: {
|
|
245
|
+
enabled: true,
|
|
246
|
+
timeoutInSeconds
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
async batchInvokeAndWaitForCompletion(cacheKey, batch) {
|
|
251
|
+
const runStore = runLocalStorage.getStore();
|
|
252
|
+
if (!runStore) {
|
|
253
|
+
throw new Error("Cannot invoke a job from outside of a run using batchInvokeAndWaitForCompletion.");
|
|
254
|
+
}
|
|
255
|
+
if (batch.length === 0) {
|
|
256
|
+
return [];
|
|
257
|
+
}
|
|
258
|
+
if (batch.length > 25) {
|
|
259
|
+
throw new Error(`Cannot batch invoke more than 25 items. You tried to batch invoke ${batch.length} items.`);
|
|
260
|
+
}
|
|
261
|
+
const { io, ctx } = runStore;
|
|
262
|
+
const results = await io.parallel(cacheKey, batch, async (item, index) => {
|
|
263
|
+
return await this.invokeAndWaitForCompletion(String(index), item.payload, item.timeoutInSeconds ?? 60 * 60, item.options);
|
|
264
|
+
}, {
|
|
265
|
+
name: `Batch Invoke '${this.name}'`,
|
|
266
|
+
properties: [
|
|
267
|
+
{
|
|
268
|
+
label: "Job",
|
|
269
|
+
text: this.id,
|
|
270
|
+
url: `/orgs/${ctx.organization.slug}/projects/${ctx.project.slug}/jobs/${this.id}`
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
label: "Env",
|
|
274
|
+
text: ctx.environment.slug
|
|
275
|
+
}
|
|
276
|
+
]
|
|
277
|
+
});
|
|
278
|
+
return results;
|
|
279
|
+
}
|
|
144
280
|
};
|
|
145
281
|
__name(Job, "Job");
|
|
146
282
|
_validate = new WeakSet();
|
|
@@ -151,7 +287,8 @@ validate_fn = /* @__PURE__ */ __name(function() {
|
|
|
151
287
|
}, "#validate");
|
|
152
288
|
|
|
153
289
|
// src/triggerClient.ts
|
|
154
|
-
var
|
|
290
|
+
var import_core8 = require("@trigger.dev/core");
|
|
291
|
+
var import_colorette = require("colorette");
|
|
155
292
|
|
|
156
293
|
// src/apiClient.ts
|
|
157
294
|
var import_core = require("@trigger.dev/core");
|
|
@@ -221,7 +358,8 @@ var ApiClient = class {
|
|
|
221
358
|
method: "POST",
|
|
222
359
|
headers: {
|
|
223
360
|
"Content-Type": "application/json",
|
|
224
|
-
Authorization: `Bearer ${apiKey}
|
|
361
|
+
Authorization: `Bearer ${apiKey}`,
|
|
362
|
+
"Trigger-Version": import_core.API_VERSIONS.SERIALIZED_TASK_OUTPUT
|
|
225
363
|
},
|
|
226
364
|
body: JSON.stringify(task)
|
|
227
365
|
});
|
|
@@ -315,18 +453,22 @@ var ApiClient = class {
|
|
|
315
453
|
});
|
|
316
454
|
return response;
|
|
317
455
|
}
|
|
318
|
-
async registerTrigger(client, id, key, payload) {
|
|
456
|
+
async registerTrigger(client, id, key, payload, idempotencyKey) {
|
|
319
457
|
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
320
458
|
__privateGet(this, _logger).debug("registering trigger", {
|
|
321
459
|
id,
|
|
322
460
|
payload
|
|
323
461
|
});
|
|
462
|
+
const headers = {
|
|
463
|
+
"Content-Type": "application/json",
|
|
464
|
+
Authorization: `Bearer ${apiKey}`
|
|
465
|
+
};
|
|
466
|
+
if (idempotencyKey) {
|
|
467
|
+
headers["Idempotency-Key"] = idempotencyKey;
|
|
468
|
+
}
|
|
324
469
|
const response = await zodfetch(import_core.RegisterSourceEventSchemaV2, `${__privateGet(this, _apiUrl)}/api/v2/${client}/triggers/${id}/registrations/${key}`, {
|
|
325
470
|
method: "PUT",
|
|
326
|
-
headers
|
|
327
|
-
"Content-Type": "application/json",
|
|
328
|
-
Authorization: `Bearer ${apiKey}`
|
|
329
|
-
},
|
|
471
|
+
headers,
|
|
330
472
|
body: JSON.stringify(payload)
|
|
331
473
|
});
|
|
332
474
|
return response;
|
|
@@ -443,6 +585,31 @@ var ApiClient = class {
|
|
|
443
585
|
}
|
|
444
586
|
});
|
|
445
587
|
}
|
|
588
|
+
async invokeJob(jobId, payload, options = {}) {
|
|
589
|
+
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
590
|
+
__privateGet(this, _logger).debug("Invoking Job", {
|
|
591
|
+
jobId
|
|
592
|
+
});
|
|
593
|
+
const body = {
|
|
594
|
+
payload,
|
|
595
|
+
context: options.context ?? {},
|
|
596
|
+
options: {
|
|
597
|
+
accountId: options.accountId,
|
|
598
|
+
callbackUrl: options.callbackUrl
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
return await zodfetch(import_core.InvokeJobResponseSchema, `${__privateGet(this, _apiUrl)}/api/v1/jobs/${jobId}/invoke`, {
|
|
602
|
+
method: "POST",
|
|
603
|
+
headers: {
|
|
604
|
+
"Content-Type": "application/json",
|
|
605
|
+
Authorization: `Bearer ${apiKey}`,
|
|
606
|
+
...options.idempotencyKey ? {
|
|
607
|
+
"Idempotency-Key": options.idempotencyKey
|
|
608
|
+
} : {}
|
|
609
|
+
},
|
|
610
|
+
body: JSON.stringify(body)
|
|
611
|
+
});
|
|
612
|
+
}
|
|
446
613
|
};
|
|
447
614
|
__name(ApiClient, "ApiClient");
|
|
448
615
|
_apiUrl = new WeakMap();
|
|
@@ -478,8 +645,11 @@ function getApiKey(key) {
|
|
|
478
645
|
};
|
|
479
646
|
}
|
|
480
647
|
__name(getApiKey, "getApiKey");
|
|
481
|
-
async function zodfetchWithVersions(versionedSchemaMap, unversionedSchema, url, requestInit, options) {
|
|
482
|
-
const response = await fetch(url,
|
|
648
|
+
async function zodfetchWithVersions(versionedSchemaMap, unversionedSchema, url, requestInit, options, retryCount = 0) {
|
|
649
|
+
const response = await fetch(url, {
|
|
650
|
+
...requestInit,
|
|
651
|
+
cache: "no-cache"
|
|
652
|
+
});
|
|
483
653
|
if ((!requestInit || requestInit.method === "GET") && response.status === 404 && options?.optional) {
|
|
484
654
|
return;
|
|
485
655
|
}
|
|
@@ -487,6 +657,11 @@ async function zodfetchWithVersions(versionedSchemaMap, unversionedSchema, url,
|
|
|
487
657
|
const body = await response.json();
|
|
488
658
|
throw new Error(body.error);
|
|
489
659
|
}
|
|
660
|
+
if (response.status >= 500 && retryCount < 6) {
|
|
661
|
+
const delay = exponentialBackoff(retryCount + 1, 2, 50, 1150, 50);
|
|
662
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
663
|
+
return zodfetchWithVersions(versionedSchemaMap, unversionedSchema, url, requestInit, options, retryCount + 1);
|
|
664
|
+
}
|
|
490
665
|
if (response.status !== 200) {
|
|
491
666
|
throw new Error(options?.errorMessage ?? `Failed to fetch ${url}, got status code ${response.status}`);
|
|
492
667
|
}
|
|
@@ -508,8 +683,11 @@ async function zodfetchWithVersions(versionedSchemaMap, unversionedSchema, url,
|
|
|
508
683
|
};
|
|
509
684
|
}
|
|
510
685
|
__name(zodfetchWithVersions, "zodfetchWithVersions");
|
|
511
|
-
async function zodfetch(schema, url, requestInit, options) {
|
|
512
|
-
const response = await fetch(url,
|
|
686
|
+
async function zodfetch(schema, url, requestInit, options, retryCount = 0) {
|
|
687
|
+
const response = await fetch(url, {
|
|
688
|
+
...requestInit,
|
|
689
|
+
cache: "no-cache"
|
|
690
|
+
});
|
|
513
691
|
if ((!requestInit || requestInit.method === "GET") && response.status === 404 && options?.optional) {
|
|
514
692
|
return;
|
|
515
693
|
}
|
|
@@ -517,6 +695,11 @@ async function zodfetch(schema, url, requestInit, options) {
|
|
|
517
695
|
const body = await response.json();
|
|
518
696
|
throw new Error(body.error);
|
|
519
697
|
}
|
|
698
|
+
if (response.status >= 500 && retryCount < 6) {
|
|
699
|
+
const delay = exponentialBackoff(retryCount + 1, 2, 50, 1150, 50);
|
|
700
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
701
|
+
return zodfetch(schema, url, requestInit, options, retryCount + 1);
|
|
702
|
+
}
|
|
520
703
|
if (response.status !== 200) {
|
|
521
704
|
throw new Error(options?.errorMessage ?? `Failed to fetch ${url}, got status code ${response.status}`);
|
|
522
705
|
}
|
|
@@ -524,6 +707,12 @@ async function zodfetch(schema, url, requestInit, options) {
|
|
|
524
707
|
return schema.parse(jsonBody);
|
|
525
708
|
}
|
|
526
709
|
__name(zodfetch, "zodfetch");
|
|
710
|
+
function exponentialBackoff(retryCount, exponential, minDelay, maxDelay, jitter) {
|
|
711
|
+
const delay = Math.min(Math.pow(exponential, retryCount) * minDelay, maxDelay);
|
|
712
|
+
const jitterValue = Math.random() * jitter;
|
|
713
|
+
return delay + jitterValue;
|
|
714
|
+
}
|
|
715
|
+
__name(exponentialBackoff, "exponentialBackoff");
|
|
527
716
|
|
|
528
717
|
// src/errors.ts
|
|
529
718
|
var ResumeWithTaskError = class {
|
|
@@ -532,6 +721,13 @@ var ResumeWithTaskError = class {
|
|
|
532
721
|
}
|
|
533
722
|
};
|
|
534
723
|
__name(ResumeWithTaskError, "ResumeWithTaskError");
|
|
724
|
+
var ResumeWithParallelTaskError = class {
|
|
725
|
+
constructor(task, childErrors) {
|
|
726
|
+
this.task = task;
|
|
727
|
+
this.childErrors = childErrors;
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
__name(ResumeWithParallelTaskError, "ResumeWithParallelTaskError");
|
|
535
731
|
var RetryWithTaskError = class {
|
|
536
732
|
constructor(cause, task, retryAt) {
|
|
537
733
|
this.cause = cause;
|
|
@@ -561,11 +757,11 @@ var AutoYieldExecutionError = class {
|
|
|
561
757
|
};
|
|
562
758
|
__name(AutoYieldExecutionError, "AutoYieldExecutionError");
|
|
563
759
|
var AutoYieldWithCompletedTaskExecutionError = class {
|
|
564
|
-
constructor(id, properties,
|
|
760
|
+
constructor(id, properties, data, output) {
|
|
565
761
|
this.id = id;
|
|
566
762
|
this.properties = properties;
|
|
567
|
-
this.output = output;
|
|
568
763
|
this.data = data;
|
|
764
|
+
this.output = output;
|
|
569
765
|
}
|
|
570
766
|
};
|
|
571
767
|
__name(AutoYieldWithCompletedTaskExecutionError, "AutoYieldWithCompletedTaskExecutionError");
|
|
@@ -576,17 +772,160 @@ var ParsedPayloadSchemaError = class {
|
|
|
576
772
|
};
|
|
577
773
|
__name(ParsedPayloadSchemaError, "ParsedPayloadSchemaError");
|
|
578
774
|
function isTriggerError(err) {
|
|
579
|
-
return err instanceof ResumeWithTaskError || err instanceof RetryWithTaskError || err instanceof CanceledWithTaskError || err instanceof YieldExecutionError || err instanceof AutoYieldExecutionError || err instanceof AutoYieldWithCompletedTaskExecutionError;
|
|
775
|
+
return err instanceof ResumeWithTaskError || err instanceof RetryWithTaskError || err instanceof CanceledWithTaskError || err instanceof YieldExecutionError || err instanceof AutoYieldExecutionError || err instanceof AutoYieldWithCompletedTaskExecutionError || err instanceof ResumeWithParallelTaskError;
|
|
580
776
|
}
|
|
581
777
|
__name(isTriggerError, "isTriggerError");
|
|
778
|
+
var ErrorWithTask = class extends Error {
|
|
779
|
+
constructor(cause, message) {
|
|
780
|
+
super(message);
|
|
781
|
+
this.cause = cause;
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
__name(ErrorWithTask, "ErrorWithTask");
|
|
785
|
+
|
|
786
|
+
// src/httpEndpoint.ts
|
|
787
|
+
var import_core2 = require("@trigger.dev/core");
|
|
788
|
+
|
|
789
|
+
// src/utils/formatSchemaErrors.ts
|
|
790
|
+
function formatSchemaErrors(errors) {
|
|
791
|
+
return errors.map((error) => {
|
|
792
|
+
const { path, message } = error;
|
|
793
|
+
return {
|
|
794
|
+
path: path.map(String),
|
|
795
|
+
message
|
|
796
|
+
};
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
__name(formatSchemaErrors, "formatSchemaErrors");
|
|
800
|
+
|
|
801
|
+
// src/httpEndpoint.ts
|
|
802
|
+
var HttpEndpoint = class {
|
|
803
|
+
constructor(options) {
|
|
804
|
+
this.options = options;
|
|
805
|
+
}
|
|
806
|
+
get id() {
|
|
807
|
+
return this.options.id;
|
|
808
|
+
}
|
|
809
|
+
onRequest(options) {
|
|
810
|
+
return new HttpTrigger({
|
|
811
|
+
endpointId: this.id,
|
|
812
|
+
event: this.options.event,
|
|
813
|
+
filter: options?.filter,
|
|
814
|
+
verify: this.options.verify
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
async handleRequest(request) {
|
|
818
|
+
if (!this.options.respondWith)
|
|
819
|
+
return;
|
|
820
|
+
return this.options.respondWith.handler(request, () => {
|
|
821
|
+
const clonedRequest = request.clone();
|
|
822
|
+
return this.options.verify(clonedRequest);
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
toJSON() {
|
|
826
|
+
return {
|
|
827
|
+
id: this.id,
|
|
828
|
+
icon: this.options.event.icon,
|
|
829
|
+
version: "1",
|
|
830
|
+
enabled: this.options.enabled ?? true,
|
|
831
|
+
event: this.options.event,
|
|
832
|
+
immediateResponseFilter: this.options.respondWith?.filter,
|
|
833
|
+
skipTriggeringRuns: this.options.respondWith?.skipTriggeringRuns,
|
|
834
|
+
source: this.options.event.source
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
};
|
|
838
|
+
__name(HttpEndpoint, "HttpEndpoint");
|
|
839
|
+
var HttpTrigger = /* @__PURE__ */ __name(class HttpTrigger2 {
|
|
840
|
+
constructor(options) {
|
|
841
|
+
this.options = options;
|
|
842
|
+
}
|
|
843
|
+
toJSON() {
|
|
844
|
+
return {
|
|
845
|
+
type: "static",
|
|
846
|
+
title: this.options.endpointId,
|
|
847
|
+
properties: this.options.event.properties,
|
|
848
|
+
rule: {
|
|
849
|
+
event: `httpendpoint.${this.options.endpointId}`,
|
|
850
|
+
payload: this.options.filter ?? {},
|
|
851
|
+
source: this.options.event.source
|
|
852
|
+
},
|
|
853
|
+
link: `http-endpoints/${this.options.endpointId}`,
|
|
854
|
+
help: {
|
|
855
|
+
noRuns: {
|
|
856
|
+
text: "To start triggering runs click here to setup your HTTP Endpoint with the external API service you want to receive webhooks from.",
|
|
857
|
+
link: `http-endpoints/${this.options.endpointId}`
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
get event() {
|
|
863
|
+
return this.options.event;
|
|
864
|
+
}
|
|
865
|
+
attachToJob(triggerClient, job) {
|
|
866
|
+
}
|
|
867
|
+
get preprocessRuns() {
|
|
868
|
+
return false;
|
|
869
|
+
}
|
|
870
|
+
async verifyPayload(payload) {
|
|
871
|
+
const clonedRequest = payload.clone();
|
|
872
|
+
return this.options.verify(clonedRequest);
|
|
873
|
+
}
|
|
874
|
+
}, "HttpTrigger");
|
|
875
|
+
function httpEndpoint(options) {
|
|
876
|
+
const id = slugifyId(options.id);
|
|
877
|
+
return new HttpEndpoint({
|
|
878
|
+
id,
|
|
879
|
+
enabled: options.enabled,
|
|
880
|
+
respondWith: options.respondWith,
|
|
881
|
+
verify: options.verify,
|
|
882
|
+
event: {
|
|
883
|
+
name: id,
|
|
884
|
+
title: options.title ?? "HTTP Trigger",
|
|
885
|
+
source: options.source,
|
|
886
|
+
icon: options.icon ?? "webhook",
|
|
887
|
+
properties: options.properties,
|
|
888
|
+
examples: options.examples ? options.examples : [
|
|
889
|
+
{
|
|
890
|
+
id: "basic-request",
|
|
891
|
+
name: "Basic Request",
|
|
892
|
+
icon: "http-post",
|
|
893
|
+
payload: {
|
|
894
|
+
url: "https://cloud.trigger.dev",
|
|
895
|
+
method: "POST",
|
|
896
|
+
headers: {
|
|
897
|
+
"Content-Type": "application/json"
|
|
898
|
+
},
|
|
899
|
+
rawBody: JSON.stringify({
|
|
900
|
+
foo: "bar"
|
|
901
|
+
})
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
],
|
|
905
|
+
parsePayload: (rawPayload) => {
|
|
906
|
+
const result = import_core2.RequestWithRawBodySchema.safeParse(rawPayload);
|
|
907
|
+
if (!result.success) {
|
|
908
|
+
throw new ParsedPayloadSchemaError(formatSchemaErrors(result.error.issues));
|
|
909
|
+
}
|
|
910
|
+
return new Request(new URL(result.data.url), {
|
|
911
|
+
method: result.data.method,
|
|
912
|
+
headers: result.data.headers,
|
|
913
|
+
body: result.data.rawBody
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
__name(httpEndpoint, "httpEndpoint");
|
|
582
920
|
|
|
583
921
|
// src/io.ts
|
|
584
|
-
var
|
|
585
|
-
var
|
|
922
|
+
var import_core4 = require("@trigger.dev/core");
|
|
923
|
+
var import_core_backend = require("@trigger.dev/core-backend");
|
|
924
|
+
var import_node_async_hooks2 = require("async_hooks");
|
|
586
925
|
var import_node_crypto = require("crypto");
|
|
587
926
|
|
|
588
927
|
// src/retry.ts
|
|
589
|
-
var
|
|
928
|
+
var import_core3 = require("@trigger.dev/core");
|
|
590
929
|
var retry = {
|
|
591
930
|
standardBackoff: {
|
|
592
931
|
limit: 8,
|
|
@@ -632,6 +971,15 @@ var TriggerStatus = class {
|
|
|
632
971
|
__name(TriggerStatus, "TriggerStatus");
|
|
633
972
|
|
|
634
973
|
// src/io.ts
|
|
974
|
+
var JSONOutputSerializer = class {
|
|
975
|
+
serialize(value) {
|
|
976
|
+
return JSON.stringify(value);
|
|
977
|
+
}
|
|
978
|
+
deserialize(value) {
|
|
979
|
+
return value ? JSON.parse(value) : void 0;
|
|
980
|
+
}
|
|
981
|
+
};
|
|
982
|
+
__name(JSONOutputSerializer, "JSONOutputSerializer");
|
|
635
983
|
var _addToCachedTasks, addToCachedTasks_fn, _detectAutoYield, detectAutoYield_fn, _forceYield, forceYield_fn, _getTimeElapsed, getTimeElapsed_fn, _getRemainingTimeInMillis, getRemainingTimeInMillis_fn;
|
|
636
984
|
var IO = class {
|
|
637
985
|
constructor(options) {
|
|
@@ -640,11 +988,13 @@ var IO = class {
|
|
|
640
988
|
__privateAdd(this, _forceYield);
|
|
641
989
|
__privateAdd(this, _getTimeElapsed);
|
|
642
990
|
__privateAdd(this, _getRemainingTimeInMillis);
|
|
991
|
+
__publicField(this, "_outputSerializer", new JSONOutputSerializer());
|
|
992
|
+
__publicField(this, "_visitedCacheKeys", /* @__PURE__ */ new Set());
|
|
643
993
|
__publicField(this, "brb", this.yield.bind(this));
|
|
644
994
|
this._id = options.id;
|
|
645
995
|
this._apiClient = options.apiClient;
|
|
646
996
|
this._triggerClient = options.client;
|
|
647
|
-
this._logger = options.logger ?? new
|
|
997
|
+
this._logger = options.logger ?? new import_core4.Logger("trigger.dev", options.logLevel);
|
|
648
998
|
this._cachedTasks = /* @__PURE__ */ new Map();
|
|
649
999
|
this._jobLogger = options.jobLogger;
|
|
650
1000
|
this._jobLogLevel = options.jobLogLevel;
|
|
@@ -665,11 +1015,11 @@ var IO = class {
|
|
|
665
1015
|
});
|
|
666
1016
|
this._stats.initialCachedTasks = options.cachedTasks.length;
|
|
667
1017
|
}
|
|
668
|
-
this._taskStorage = new
|
|
1018
|
+
this._taskStorage = new import_node_async_hooks2.AsyncLocalStorage();
|
|
669
1019
|
this._context = options.context;
|
|
670
1020
|
this._yieldedExecutions = options.yieldedExecutions ?? [];
|
|
671
1021
|
if (options.noopTasksSet) {
|
|
672
|
-
this._noopTasksBloomFilter =
|
|
1022
|
+
this._noopTasksBloomFilter = import_core_backend.BloomFilter.deserialize(options.noopTasksSet, import_core_backend.BloomFilter.NOOP_TASK_SET_SIZE);
|
|
673
1023
|
}
|
|
674
1024
|
this._cachedTasksCursor = options.cachedTasksCursor;
|
|
675
1025
|
this._serverVersion = options.serverVersion ?? "unversioned";
|
|
@@ -686,7 +1036,7 @@ var IO = class {
|
|
|
686
1036
|
get logger() {
|
|
687
1037
|
return new IOLogger(async (level, message, data) => {
|
|
688
1038
|
let logLevel = "info";
|
|
689
|
-
if (
|
|
1039
|
+
if (import_core4.Logger.satisfiesLogLevel(logLevel, this._jobLogLevel)) {
|
|
690
1040
|
await this.runTask([
|
|
691
1041
|
message,
|
|
692
1042
|
level
|
|
@@ -738,6 +1088,56 @@ var IO = class {
|
|
|
738
1088
|
}
|
|
739
1089
|
});
|
|
740
1090
|
}
|
|
1091
|
+
async random(cacheKey, { min = 0, max = 1, round = false } = {}) {
|
|
1092
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
1093
|
+
if (min > max) {
|
|
1094
|
+
throw new Error(`Lower bound can't be higher than upper bound - min: ${min}, max: ${max}`);
|
|
1095
|
+
}
|
|
1096
|
+
if (min === max) {
|
|
1097
|
+
await this.logger.warn(`Lower and upper bounds are identical. The return value is not random and will always be: ${min}`);
|
|
1098
|
+
}
|
|
1099
|
+
const withinBounds = (max - min) * Math.random() + min;
|
|
1100
|
+
if (!round) {
|
|
1101
|
+
return withinBounds;
|
|
1102
|
+
}
|
|
1103
|
+
if (!Number.isInteger(min) || !Number.isInteger(max)) {
|
|
1104
|
+
await this.logger.warn("Rounding enabled with floating-point bounds. This may cause unexpected skew and boundary inclusivity.");
|
|
1105
|
+
}
|
|
1106
|
+
const rounded = Math.round(withinBounds);
|
|
1107
|
+
return rounded;
|
|
1108
|
+
}, {
|
|
1109
|
+
name: "random",
|
|
1110
|
+
icon: "dice-5-filled",
|
|
1111
|
+
params: {
|
|
1112
|
+
min,
|
|
1113
|
+
max,
|
|
1114
|
+
round
|
|
1115
|
+
},
|
|
1116
|
+
properties: [
|
|
1117
|
+
...min === 0 ? [] : [
|
|
1118
|
+
{
|
|
1119
|
+
label: "min",
|
|
1120
|
+
text: String(min)
|
|
1121
|
+
}
|
|
1122
|
+
],
|
|
1123
|
+
...max === 1 ? [] : [
|
|
1124
|
+
{
|
|
1125
|
+
label: "max",
|
|
1126
|
+
text: String(max)
|
|
1127
|
+
}
|
|
1128
|
+
],
|
|
1129
|
+
...round === false ? [] : [
|
|
1130
|
+
{
|
|
1131
|
+
label: "round",
|
|
1132
|
+
text: String(round)
|
|
1133
|
+
}
|
|
1134
|
+
]
|
|
1135
|
+
],
|
|
1136
|
+
style: {
|
|
1137
|
+
style: "minimal"
|
|
1138
|
+
}
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
741
1141
|
async wait(cacheKey, seconds) {
|
|
742
1142
|
return await this.runTask(cacheKey, async (task) => {
|
|
743
1143
|
}, {
|
|
@@ -753,13 +1153,41 @@ var IO = class {
|
|
|
753
1153
|
}
|
|
754
1154
|
});
|
|
755
1155
|
}
|
|
1156
|
+
async waitForRequest(cacheKey, callback, options) {
|
|
1157
|
+
const timeoutInSeconds = options?.timeoutInSeconds ?? 60 * 60;
|
|
1158
|
+
return await this.runTask(cacheKey, async (task, io) => {
|
|
1159
|
+
if (!task.callbackUrl) {
|
|
1160
|
+
throw new Error("No callbackUrl found on task");
|
|
1161
|
+
}
|
|
1162
|
+
task.outputProperties = [
|
|
1163
|
+
{
|
|
1164
|
+
label: "Callback URL",
|
|
1165
|
+
text: task.callbackUrl
|
|
1166
|
+
}
|
|
1167
|
+
];
|
|
1168
|
+
return callback(task.callbackUrl);
|
|
1169
|
+
}, {
|
|
1170
|
+
name: "Wait for Request",
|
|
1171
|
+
icon: "clock",
|
|
1172
|
+
callback: {
|
|
1173
|
+
enabled: true,
|
|
1174
|
+
timeoutInSeconds: options?.timeoutInSeconds
|
|
1175
|
+
},
|
|
1176
|
+
properties: [
|
|
1177
|
+
{
|
|
1178
|
+
label: "Timeout",
|
|
1179
|
+
text: `${timeoutInSeconds}s`
|
|
1180
|
+
}
|
|
1181
|
+
]
|
|
1182
|
+
});
|
|
1183
|
+
}
|
|
756
1184
|
async createStatus(cacheKey, initialStatus) {
|
|
757
1185
|
const id = typeof cacheKey === "string" ? cacheKey : cacheKey.join("-");
|
|
758
1186
|
const status = new TriggerStatus(id, this);
|
|
759
1187
|
await status.update(cacheKey, initialStatus);
|
|
760
1188
|
return status;
|
|
761
1189
|
}
|
|
762
|
-
async backgroundFetch(cacheKey, url, requestInit, retry2) {
|
|
1190
|
+
async backgroundFetch(cacheKey, url, requestInit, retry2, timeout) {
|
|
763
1191
|
const urlObject = new URL(url);
|
|
764
1192
|
return await this.runTask(cacheKey, async (task) => {
|
|
765
1193
|
return task.output;
|
|
@@ -768,7 +1196,8 @@ var IO = class {
|
|
|
768
1196
|
params: {
|
|
769
1197
|
url,
|
|
770
1198
|
requestInit,
|
|
771
|
-
retry: retry2
|
|
1199
|
+
retry: retry2,
|
|
1200
|
+
timeout
|
|
772
1201
|
},
|
|
773
1202
|
operation: "fetch",
|
|
774
1203
|
icon: "background",
|
|
@@ -786,8 +1215,17 @@ var IO = class {
|
|
|
786
1215
|
{
|
|
787
1216
|
label: "background",
|
|
788
1217
|
text: "true"
|
|
789
|
-
}
|
|
790
|
-
|
|
1218
|
+
},
|
|
1219
|
+
...timeout ? [
|
|
1220
|
+
{
|
|
1221
|
+
label: "timeout",
|
|
1222
|
+
text: `${timeout.durationInMs}ms`
|
|
1223
|
+
}
|
|
1224
|
+
] : []
|
|
1225
|
+
],
|
|
1226
|
+
retry: {
|
|
1227
|
+
limit: 0
|
|
1228
|
+
}
|
|
791
1229
|
});
|
|
792
1230
|
}
|
|
793
1231
|
async sendEvent(cacheKey, event, options) {
|
|
@@ -985,6 +1423,25 @@ var IO = class {
|
|
|
985
1423
|
name: "get-auth"
|
|
986
1424
|
});
|
|
987
1425
|
}
|
|
1426
|
+
async parallel(cacheKey, items, callback, options) {
|
|
1427
|
+
const results = await this.runTask(cacheKey, async (task) => {
|
|
1428
|
+
const outcomes = await Promise.allSettled(items.map((item, index) => spaceOut(() => callback(item, index), index, 15)));
|
|
1429
|
+
if (outcomes.every((outcome) => outcome.status === "fulfilled")) {
|
|
1430
|
+
return outcomes.map((outcome) => outcome.value);
|
|
1431
|
+
}
|
|
1432
|
+
const nonInternalErrors = outcomes.filter((outcome) => outcome.status === "rejected" && !isTriggerError(outcome.reason)).map((outcome) => outcome);
|
|
1433
|
+
if (nonInternalErrors.length > 0) {
|
|
1434
|
+
throw nonInternalErrors[0].reason;
|
|
1435
|
+
}
|
|
1436
|
+
const internalErrors = outcomes.filter((outcome) => outcome.status === "rejected" && isTriggerError(outcome.reason)).map((outcome) => outcome).map((outcome) => outcome.reason);
|
|
1437
|
+
throw new ResumeWithParallelTaskError(task, internalErrors);
|
|
1438
|
+
}, {
|
|
1439
|
+
name: "parallel",
|
|
1440
|
+
parallel: true,
|
|
1441
|
+
...options ?? {}
|
|
1442
|
+
});
|
|
1443
|
+
return results;
|
|
1444
|
+
}
|
|
988
1445
|
async runTask(cacheKey, callback, options, onError) {
|
|
989
1446
|
__privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "start_task", 500);
|
|
990
1447
|
const parentId = this._taskStorage.getStore()?.taskId;
|
|
@@ -1000,6 +1457,14 @@ var IO = class {
|
|
|
1000
1457
|
parentId ?? "",
|
|
1001
1458
|
cacheKey
|
|
1002
1459
|
].flat());
|
|
1460
|
+
if (this._visitedCacheKeys.has(idempotencyKey)) {
|
|
1461
|
+
if (typeof cacheKey === "string") {
|
|
1462
|
+
throw new Error(`Task with cacheKey "${cacheKey}" has already been executed in this run. Each task must have a unique cacheKey.`);
|
|
1463
|
+
} else {
|
|
1464
|
+
throw new Error(`Task with cacheKey "${cacheKey.join("-")}" has already been executed in this run. Each task must have a unique cacheKey.`);
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
this._visitedCacheKeys.add(idempotencyKey);
|
|
1003
1468
|
const cachedTask = this._cachedTasks.get(idempotencyKey);
|
|
1004
1469
|
if (cachedTask && cachedTask.status === "COMPLETED") {
|
|
1005
1470
|
this._logger.debug("Using completed cached task", {
|
|
@@ -1026,14 +1491,14 @@ var IO = class {
|
|
|
1026
1491
|
}, {
|
|
1027
1492
|
cachedTasksCursor: this._cachedTasksCursor
|
|
1028
1493
|
});
|
|
1029
|
-
const task = response.version ===
|
|
1494
|
+
const task = response.version === import_core4.API_VERSIONS.LAZY_LOADED_CACHED_TASKS ? response.body.task : response.body;
|
|
1030
1495
|
if (task.forceYield) {
|
|
1031
1496
|
this._logger.debug("Forcing yield after run task", {
|
|
1032
1497
|
idempotencyKey
|
|
1033
1498
|
});
|
|
1034
1499
|
__privateMethod(this, _forceYield, forceYield_fn).call(this, "after_run_task");
|
|
1035
1500
|
}
|
|
1036
|
-
if (response.version ===
|
|
1501
|
+
if (response.version === import_core4.API_VERSIONS.LAZY_LOADED_CACHED_TASKS) {
|
|
1037
1502
|
this._cachedTasksCursor = response.body.cachedTasks?.cursor;
|
|
1038
1503
|
for (const cachedTask2 of response.body.cachedTasks?.tasks ?? []) {
|
|
1039
1504
|
if (!this._cachedTasks.has(cachedTask2.idempotencyKey)) {
|
|
@@ -1072,7 +1537,7 @@ var IO = class {
|
|
|
1072
1537
|
idempotencyKey,
|
|
1073
1538
|
task
|
|
1074
1539
|
});
|
|
1075
|
-
throw new
|
|
1540
|
+
throw new ErrorWithTask(task, task.error ?? task?.output ? JSON.stringify(task.output) : "Task errored");
|
|
1076
1541
|
}
|
|
1077
1542
|
__privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "before_execute_task", 1500);
|
|
1078
1543
|
const executeTask = /* @__PURE__ */ __name(async () => {
|
|
@@ -1085,14 +1550,14 @@ var IO = class {
|
|
|
1085
1550
|
});
|
|
1086
1551
|
return {};
|
|
1087
1552
|
}
|
|
1088
|
-
const output =
|
|
1553
|
+
const output = this._outputSerializer.serialize(result);
|
|
1089
1554
|
this._logger.debug("Completing using output", {
|
|
1090
1555
|
idempotencyKey,
|
|
1091
1556
|
task
|
|
1092
1557
|
});
|
|
1093
1558
|
__privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "before_complete_task", 500, task, output);
|
|
1094
1559
|
const completedTask = await this._apiClient.completeTask(this._id, task.id, {
|
|
1095
|
-
output
|
|
1560
|
+
output,
|
|
1096
1561
|
properties: task.outputProperties ?? void 0
|
|
1097
1562
|
});
|
|
1098
1563
|
if (completedTask.forceYield) {
|
|
@@ -1106,7 +1571,7 @@ var IO = class {
|
|
|
1106
1571
|
throw new CanceledWithTaskError(completedTask);
|
|
1107
1572
|
}
|
|
1108
1573
|
__privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "after_complete_task", 500);
|
|
1109
|
-
return output;
|
|
1574
|
+
return this._outputSerializer.deserialize(output);
|
|
1110
1575
|
} catch (error) {
|
|
1111
1576
|
if (isTriggerError(error)) {
|
|
1112
1577
|
throw error;
|
|
@@ -1121,7 +1586,7 @@ var IO = class {
|
|
|
1121
1586
|
} else {
|
|
1122
1587
|
skipRetrying = !!onErrorResult.skipRetrying;
|
|
1123
1588
|
if (onErrorResult.retryAt && !skipRetrying) {
|
|
1124
|
-
const parsedError2 =
|
|
1589
|
+
const parsedError2 = import_core4.ErrorWithStackSchema.safeParse(onErrorResult.error);
|
|
1125
1590
|
throw new RetryWithTaskError(parsedError2.success ? parsedError2.data : {
|
|
1126
1591
|
message: "Unknown error"
|
|
1127
1592
|
}, task, onErrorResult.retryAt);
|
|
@@ -1135,9 +1600,14 @@ var IO = class {
|
|
|
1135
1600
|
error = innerError;
|
|
1136
1601
|
}
|
|
1137
1602
|
}
|
|
1138
|
-
|
|
1603
|
+
if (error instanceof ErrorWithTask) {
|
|
1604
|
+
await this._apiClient.failTask(this._id, task.id, {
|
|
1605
|
+
error: error.cause.output
|
|
1606
|
+
});
|
|
1607
|
+
}
|
|
1608
|
+
const parsedError = import_core4.ErrorWithStackSchema.safeParse(error);
|
|
1139
1609
|
if (options?.retry && !skipRetrying) {
|
|
1140
|
-
const retryAt = (0,
|
|
1610
|
+
const retryAt = (0, import_core3.calculateRetryAt)(options.retry, task.attempts - 1);
|
|
1141
1611
|
if (retryAt) {
|
|
1142
1612
|
throw new RetryWithTaskError(parsedError.success ? parsedError.data : {
|
|
1143
1613
|
message: "Unknown error"
|
|
@@ -1184,7 +1654,7 @@ var IO = class {
|
|
|
1184
1654
|
}, executeTask);
|
|
1185
1655
|
}
|
|
1186
1656
|
yield(cacheKey) {
|
|
1187
|
-
if (!(0,
|
|
1657
|
+
if (!(0, import_core4.supportsFeature)("yieldExecution", this._serverVersion)) {
|
|
1188
1658
|
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.");
|
|
1189
1659
|
return;
|
|
1190
1660
|
}
|
|
@@ -1214,11 +1684,11 @@ detectAutoYield_fn = /* @__PURE__ */ __name(function(location, threshold = 1500,
|
|
|
1214
1684
|
const timeRemaining = __privateMethod(this, _getRemainingTimeInMillis, getRemainingTimeInMillis_fn).call(this);
|
|
1215
1685
|
if (timeRemaining && timeRemaining < threshold) {
|
|
1216
1686
|
if (task1) {
|
|
1217
|
-
throw new AutoYieldWithCompletedTaskExecutionError(task1.id, task1.outputProperties ?? [],
|
|
1687
|
+
throw new AutoYieldWithCompletedTaskExecutionError(task1.id, task1.outputProperties ?? [], {
|
|
1218
1688
|
location,
|
|
1219
1689
|
timeRemaining,
|
|
1220
1690
|
timeElapsed: __privateMethod(this, _getTimeElapsed, getTimeElapsed_fn).call(this)
|
|
1221
|
-
});
|
|
1691
|
+
}, output);
|
|
1222
1692
|
} else {
|
|
1223
1693
|
throw new AutoYieldExecutionError(location, timeRemaining, __privateMethod(this, _getTimeElapsed, getTimeElapsed_fn).call(this));
|
|
1224
1694
|
}
|
|
@@ -1295,6 +1765,11 @@ var IOLogger = class {
|
|
|
1295
1765
|
}
|
|
1296
1766
|
};
|
|
1297
1767
|
__name(IOLogger, "IOLogger");
|
|
1768
|
+
async function spaceOut(callback, index, delay) {
|
|
1769
|
+
await new Promise((resolve) => setTimeout(resolve, index * delay));
|
|
1770
|
+
return await callback();
|
|
1771
|
+
}
|
|
1772
|
+
__name(spaceOut, "spaceOut");
|
|
1298
1773
|
|
|
1299
1774
|
// src/ioWithIntegrations.ts
|
|
1300
1775
|
function createIOWithIntegrations(io, auths, integrations) {
|
|
@@ -1325,26 +1800,8 @@ function createIOWithIntegrations(io, auths, integrations) {
|
|
|
1325
1800
|
}
|
|
1326
1801
|
__name(createIOWithIntegrations, "createIOWithIntegrations");
|
|
1327
1802
|
|
|
1328
|
-
// src/utils/typedAsyncLocalStorage.ts
|
|
1329
|
-
var import_node_async_hooks2 = require("async_hooks");
|
|
1330
|
-
var TypedAsyncLocalStorage = class {
|
|
1331
|
-
constructor() {
|
|
1332
|
-
this.storage = new import_node_async_hooks2.AsyncLocalStorage();
|
|
1333
|
-
}
|
|
1334
|
-
runWith(context, fn) {
|
|
1335
|
-
return this.storage.run(context, fn);
|
|
1336
|
-
}
|
|
1337
|
-
getStore() {
|
|
1338
|
-
return this.storage.getStore();
|
|
1339
|
-
}
|
|
1340
|
-
};
|
|
1341
|
-
__name(TypedAsyncLocalStorage, "TypedAsyncLocalStorage");
|
|
1342
|
-
|
|
1343
|
-
// src/runLocalStorage.ts
|
|
1344
|
-
var runLocalStorage = new TypedAsyncLocalStorage();
|
|
1345
|
-
|
|
1346
1803
|
// src/triggers/dynamic.ts
|
|
1347
|
-
var
|
|
1804
|
+
var import_core5 = require("@trigger.dev/core");
|
|
1348
1805
|
var _client, _options2;
|
|
1349
1806
|
var DynamicTrigger = class {
|
|
1350
1807
|
constructor(client, options) {
|
|
@@ -1373,7 +1830,7 @@ var DynamicTrigger = class {
|
|
|
1373
1830
|
rule: {
|
|
1374
1831
|
event: this.event.name,
|
|
1375
1832
|
source: this.event.source,
|
|
1376
|
-
payload: (0,
|
|
1833
|
+
payload: (0, import_core5.deepMergeFilters)(this.source.filter(params), this.event.filter ?? {}, options.filter ?? {})
|
|
1377
1834
|
},
|
|
1378
1835
|
source: {
|
|
1379
1836
|
version: "2",
|
|
@@ -1404,7 +1861,7 @@ var DynamicTrigger = class {
|
|
|
1404
1861
|
key,
|
|
1405
1862
|
"register"
|
|
1406
1863
|
], async (task) => {
|
|
1407
|
-
return __privateGet(this, _client).registerTrigger(this.id, key, this.registeredTriggerForParams(params, options));
|
|
1864
|
+
return __privateGet(this, _client).registerTrigger(this.id, key, this.registeredTriggerForParams(params, options), task.idempotencyKey);
|
|
1408
1865
|
}, {
|
|
1409
1866
|
name: "Register Dynamic Trigger",
|
|
1410
1867
|
properties: [
|
|
@@ -1426,27 +1883,18 @@ var DynamicTrigger = class {
|
|
|
1426
1883
|
get preprocessRuns() {
|
|
1427
1884
|
return true;
|
|
1428
1885
|
}
|
|
1886
|
+
async verifyPayload(payload) {
|
|
1887
|
+
return {
|
|
1888
|
+
success: true
|
|
1889
|
+
};
|
|
1890
|
+
}
|
|
1429
1891
|
};
|
|
1430
1892
|
__name(DynamicTrigger, "DynamicTrigger");
|
|
1431
1893
|
_client = new WeakMap();
|
|
1432
1894
|
_options2 = new WeakMap();
|
|
1433
1895
|
|
|
1434
1896
|
// src/triggers/eventTrigger.ts
|
|
1435
|
-
var
|
|
1436
|
-
|
|
1437
|
-
// src/utils/formatSchemaErrors.ts
|
|
1438
|
-
function formatSchemaErrors(errors) {
|
|
1439
|
-
return errors.map((error) => {
|
|
1440
|
-
const { path, message } = error;
|
|
1441
|
-
return {
|
|
1442
|
-
path: path.map(String),
|
|
1443
|
-
message
|
|
1444
|
-
};
|
|
1445
|
-
});
|
|
1446
|
-
}
|
|
1447
|
-
__name(formatSchemaErrors, "formatSchemaErrors");
|
|
1448
|
-
|
|
1449
|
-
// src/triggers/eventTrigger.ts
|
|
1897
|
+
var import_core6 = require("@trigger.dev/core");
|
|
1450
1898
|
var _options3;
|
|
1451
1899
|
var EventTrigger = class {
|
|
1452
1900
|
constructor(options) {
|
|
@@ -1460,7 +1908,7 @@ var EventTrigger = class {
|
|
|
1460
1908
|
rule: {
|
|
1461
1909
|
event: __privateGet(this, _options3).name ?? __privateGet(this, _options3).event.name,
|
|
1462
1910
|
source: __privateGet(this, _options3).source ?? "trigger.dev",
|
|
1463
|
-
payload: (0,
|
|
1911
|
+
payload: (0, import_core6.deepMergeFilters)(__privateGet(this, _options3).filter ?? {}, __privateGet(this, _options3).event.filter ?? {})
|
|
1464
1912
|
}
|
|
1465
1913
|
};
|
|
1466
1914
|
}
|
|
@@ -1472,6 +1920,11 @@ var EventTrigger = class {
|
|
|
1472
1920
|
get preprocessRuns() {
|
|
1473
1921
|
return false;
|
|
1474
1922
|
}
|
|
1923
|
+
async verifyPayload(payload) {
|
|
1924
|
+
return {
|
|
1925
|
+
success: true
|
|
1926
|
+
};
|
|
1927
|
+
}
|
|
1475
1928
|
};
|
|
1476
1929
|
__name(EventTrigger, "EventTrigger");
|
|
1477
1930
|
_options3 = new WeakMap();
|
|
@@ -1501,7 +1954,7 @@ function eventTrigger(options) {
|
|
|
1501
1954
|
__name(eventTrigger, "eventTrigger");
|
|
1502
1955
|
|
|
1503
1956
|
// src/triggers/scheduled.ts
|
|
1504
|
-
var
|
|
1957
|
+
var import_core7 = require("@trigger.dev/core");
|
|
1505
1958
|
var import_cronstrue = __toESM(require("cronstrue"));
|
|
1506
1959
|
var examples = [
|
|
1507
1960
|
{
|
|
@@ -1509,8 +1962,8 @@ var examples = [
|
|
|
1509
1962
|
name: "Now",
|
|
1510
1963
|
icon: "clock",
|
|
1511
1964
|
payload: {
|
|
1512
|
-
ts:
|
|
1513
|
-
lastTimestamp:
|
|
1965
|
+
ts: import_core7.currentDate.marker,
|
|
1966
|
+
lastTimestamp: import_core7.currentDate.marker
|
|
1514
1967
|
}
|
|
1515
1968
|
}
|
|
1516
1969
|
];
|
|
@@ -1525,7 +1978,7 @@ var IntervalTrigger = class {
|
|
|
1525
1978
|
source: "trigger.dev",
|
|
1526
1979
|
icon: "schedule-interval",
|
|
1527
1980
|
examples,
|
|
1528
|
-
parsePayload:
|
|
1981
|
+
parsePayload: import_core7.ScheduledPayloadSchema.parse,
|
|
1529
1982
|
properties: [
|
|
1530
1983
|
{
|
|
1531
1984
|
label: "Interval",
|
|
@@ -1539,6 +1992,11 @@ var IntervalTrigger = class {
|
|
|
1539
1992
|
get preprocessRuns() {
|
|
1540
1993
|
return false;
|
|
1541
1994
|
}
|
|
1995
|
+
async verifyPayload(payload) {
|
|
1996
|
+
return {
|
|
1997
|
+
success: true
|
|
1998
|
+
};
|
|
1999
|
+
}
|
|
1542
2000
|
toJSON() {
|
|
1543
2001
|
return {
|
|
1544
2002
|
type: "scheduled",
|
|
@@ -1570,7 +2028,7 @@ var CronTrigger = class {
|
|
|
1570
2028
|
source: "trigger.dev",
|
|
1571
2029
|
icon: "schedule-cron",
|
|
1572
2030
|
examples,
|
|
1573
|
-
parsePayload:
|
|
2031
|
+
parsePayload: import_core7.ScheduledPayloadSchema.parse,
|
|
1574
2032
|
properties: [
|
|
1575
2033
|
{
|
|
1576
2034
|
label: "cron",
|
|
@@ -1588,6 +2046,11 @@ var CronTrigger = class {
|
|
|
1588
2046
|
get preprocessRuns() {
|
|
1589
2047
|
return false;
|
|
1590
2048
|
}
|
|
2049
|
+
async verifyPayload(payload) {
|
|
2050
|
+
return {
|
|
2051
|
+
success: true
|
|
2052
|
+
};
|
|
2053
|
+
}
|
|
1591
2054
|
toJSON() {
|
|
1592
2055
|
return {
|
|
1593
2056
|
type: "scheduled",
|
|
@@ -1621,7 +2084,7 @@ var DynamicSchedule = class {
|
|
|
1621
2084
|
source: "trigger.dev",
|
|
1622
2085
|
icon: "schedule-dynamic",
|
|
1623
2086
|
examples,
|
|
1624
|
-
parsePayload:
|
|
2087
|
+
parsePayload: import_core7.ScheduledPayloadSchema.parse
|
|
1625
2088
|
};
|
|
1626
2089
|
}
|
|
1627
2090
|
async register(key, metadata) {
|
|
@@ -1683,6 +2146,11 @@ var DynamicSchedule = class {
|
|
|
1683
2146
|
get preprocessRuns() {
|
|
1684
2147
|
return false;
|
|
1685
2148
|
}
|
|
2149
|
+
async verifyPayload(payload) {
|
|
2150
|
+
return {
|
|
2151
|
+
success: true
|
|
2152
|
+
};
|
|
2153
|
+
}
|
|
1686
2154
|
toJSON() {
|
|
1687
2155
|
return {
|
|
1688
2156
|
type: "dynamic",
|
|
@@ -1693,24 +2161,26 @@ var DynamicSchedule = class {
|
|
|
1693
2161
|
__name(DynamicSchedule, "DynamicSchedule");
|
|
1694
2162
|
|
|
1695
2163
|
// package.json
|
|
1696
|
-
var version = "2.2.
|
|
2164
|
+
var version = "2.2.5";
|
|
1697
2165
|
|
|
1698
2166
|
// src/triggerClient.ts
|
|
1699
2167
|
var registerSourceEvent = {
|
|
1700
|
-
name:
|
|
2168
|
+
name: import_core8.REGISTER_SOURCE_EVENT_V2,
|
|
1701
2169
|
title: "Register Source",
|
|
1702
2170
|
source: "internal",
|
|
1703
2171
|
icon: "register-source",
|
|
1704
|
-
parsePayload:
|
|
2172
|
+
parsePayload: import_core8.RegisterSourceEventSchemaV2.parse
|
|
1705
2173
|
};
|
|
1706
|
-
var _options4, _registeredJobs, _registeredSources, _registeredHttpSourceHandlers, _registeredDynamicTriggers, _jobMetadataByDynamicTriggers, _registeredSchedules, _authResolvers, _client2, _internalLogger, _preprocessRun, preprocessRun_fn, _executeJob, executeJob_fn, _createRunContext, createRunContext_fn, _createPreprocessRunContext, createPreprocessRunContext_fn, _handleHttpSourceRequest, handleHttpSourceRequest_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;
|
|
2174
|
+
var _options4, _registeredJobs, _registeredSources, _registeredHttpSourceHandlers, _registeredDynamicTriggers, _jobMetadataByDynamicTriggers, _registeredSchedules, _registeredHttpEndpoints, _authResolvers, _client2, _internalLogger, _preprocessRun, preprocessRun_fn, _executeJob, executeJob_fn, _convertErrorToExecutionResponse, convertErrorToExecutionResponse_fn, _createRunContext, createRunContext_fn, _createPreprocessRunContext, createPreprocessRunContext_fn, _handleHttpSourceRequest, handleHttpSourceRequest_fn, _handleHttpEndpointRequestForResponse, handleHttpEndpointRequestForResponse_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;
|
|
1707
2175
|
var TriggerClient = class {
|
|
1708
2176
|
constructor(options) {
|
|
1709
2177
|
__privateAdd(this, _preprocessRun);
|
|
1710
2178
|
__privateAdd(this, _executeJob);
|
|
2179
|
+
__privateAdd(this, _convertErrorToExecutionResponse);
|
|
1711
2180
|
__privateAdd(this, _createRunContext);
|
|
1712
2181
|
__privateAdd(this, _createPreprocessRunContext);
|
|
1713
2182
|
__privateAdd(this, _handleHttpSourceRequest);
|
|
2183
|
+
__privateAdd(this, _handleHttpEndpointRequestForResponse);
|
|
1714
2184
|
__privateAdd(this, _resolveConnections);
|
|
1715
2185
|
__privateAdd(this, _resolveConnection);
|
|
1716
2186
|
__privateAdd(this, _buildJobsIndex);
|
|
@@ -1726,13 +2196,14 @@ var TriggerClient = class {
|
|
|
1726
2196
|
__privateAdd(this, _registeredDynamicTriggers, {});
|
|
1727
2197
|
__privateAdd(this, _jobMetadataByDynamicTriggers, {});
|
|
1728
2198
|
__privateAdd(this, _registeredSchedules, {});
|
|
2199
|
+
__privateAdd(this, _registeredHttpEndpoints, {});
|
|
1729
2200
|
__privateAdd(this, _authResolvers, {});
|
|
1730
2201
|
__privateAdd(this, _client2, void 0);
|
|
1731
2202
|
__privateAdd(this, _internalLogger, void 0);
|
|
1732
2203
|
this.id = options.id;
|
|
1733
2204
|
__privateSet(this, _options4, options);
|
|
1734
2205
|
__privateSet(this, _client2, new ApiClient(__privateGet(this, _options4)));
|
|
1735
|
-
__privateSet(this, _internalLogger, new
|
|
2206
|
+
__privateSet(this, _internalLogger, new import_core8.Logger("trigger.dev", __privateGet(this, _options4).verbose ? "debug" : "log", [
|
|
1736
2207
|
"output",
|
|
1737
2208
|
"noopTasksSet"
|
|
1738
2209
|
]));
|
|
@@ -1843,7 +2314,8 @@ var TriggerClient = class {
|
|
|
1843
2314
|
dynamicSchedules: Object.entries(__privateGet(this, _registeredSchedules)).map(([id, jobs]) => ({
|
|
1844
2315
|
id,
|
|
1845
2316
|
jobs
|
|
1846
|
-
}))
|
|
2317
|
+
})),
|
|
2318
|
+
httpEndpoints: Object.entries(__privateGet(this, _registeredHttpEndpoints)).map(([id, endpoint]) => endpoint.toJSON())
|
|
1847
2319
|
};
|
|
1848
2320
|
return {
|
|
1849
2321
|
status: 200,
|
|
@@ -1853,7 +2325,7 @@ var TriggerClient = class {
|
|
|
1853
2325
|
}
|
|
1854
2326
|
case "INITIALIZE_TRIGGER": {
|
|
1855
2327
|
const json = await request.json();
|
|
1856
|
-
const body =
|
|
2328
|
+
const body = import_core8.InitializeTriggerBodySchema.safeParse(json);
|
|
1857
2329
|
if (!body.success) {
|
|
1858
2330
|
return {
|
|
1859
2331
|
status: 400,
|
|
@@ -1879,7 +2351,7 @@ var TriggerClient = class {
|
|
|
1879
2351
|
}
|
|
1880
2352
|
case "EXECUTE_JOB": {
|
|
1881
2353
|
const json = await request.json();
|
|
1882
|
-
const execution =
|
|
2354
|
+
const execution = import_core8.RunJobBodySchema.safeParse(json);
|
|
1883
2355
|
if (!execution.success) {
|
|
1884
2356
|
return {
|
|
1885
2357
|
status: 400,
|
|
@@ -1898,6 +2370,12 @@ var TriggerClient = class {
|
|
|
1898
2370
|
};
|
|
1899
2371
|
}
|
|
1900
2372
|
const results = await __privateMethod(this, _executeJob, executeJob_fn).call(this, execution.data, job, timeOrigin, triggerVersion);
|
|
2373
|
+
__privateGet(this, _internalLogger).debug("executed job", {
|
|
2374
|
+
results,
|
|
2375
|
+
job: job.id,
|
|
2376
|
+
version: job.version,
|
|
2377
|
+
triggerVersion
|
|
2378
|
+
});
|
|
1901
2379
|
return {
|
|
1902
2380
|
status: 200,
|
|
1903
2381
|
body: results,
|
|
@@ -1906,7 +2384,7 @@ var TriggerClient = class {
|
|
|
1906
2384
|
}
|
|
1907
2385
|
case "PREPROCESS_RUN": {
|
|
1908
2386
|
const json = await request.json();
|
|
1909
|
-
const body =
|
|
2387
|
+
const body = import_core8.PreprocessRunBodySchema.safeParse(json);
|
|
1910
2388
|
if (!body.success) {
|
|
1911
2389
|
return {
|
|
1912
2390
|
status: 400,
|
|
@@ -1935,7 +2413,7 @@ var TriggerClient = class {
|
|
|
1935
2413
|
};
|
|
1936
2414
|
}
|
|
1937
2415
|
case "DELIVER_HTTP_SOURCE_REQUEST": {
|
|
1938
|
-
const headers =
|
|
2416
|
+
const headers = import_core8.HttpSourceRequestHeadersSchema.safeParse(Object.fromEntries(request.headers.entries()));
|
|
1939
2417
|
if (!headers.success) {
|
|
1940
2418
|
return {
|
|
1941
2419
|
status: 400,
|
|
@@ -1984,6 +2462,39 @@ var TriggerClient = class {
|
|
|
1984
2462
|
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
1985
2463
|
};
|
|
1986
2464
|
}
|
|
2465
|
+
case "DELIVER_HTTP_ENDPOINT_REQUEST_FOR_RESPONSE": {
|
|
2466
|
+
const headers = import_core8.HttpEndpointRequestHeadersSchema.safeParse(Object.fromEntries(request.headers.entries()));
|
|
2467
|
+
if (!headers.success) {
|
|
2468
|
+
return {
|
|
2469
|
+
status: 400,
|
|
2470
|
+
body: {
|
|
2471
|
+
message: "Invalid headers"
|
|
2472
|
+
}
|
|
2473
|
+
};
|
|
2474
|
+
}
|
|
2475
|
+
const sourceRequestNeedsBody = headers.data["x-ts-http-method"] !== "GET";
|
|
2476
|
+
const sourceRequestInit = {
|
|
2477
|
+
method: headers.data["x-ts-http-method"],
|
|
2478
|
+
headers: headers.data["x-ts-http-headers"],
|
|
2479
|
+
body: sourceRequestNeedsBody ? request.body : void 0
|
|
2480
|
+
};
|
|
2481
|
+
if (sourceRequestNeedsBody) {
|
|
2482
|
+
try {
|
|
2483
|
+
sourceRequestInit.duplex = "half";
|
|
2484
|
+
} catch (error) {
|
|
2485
|
+
}
|
|
2486
|
+
}
|
|
2487
|
+
const sourceRequest = new Request(headers.data["x-ts-http-url"], sourceRequestInit);
|
|
2488
|
+
const key = headers.data["x-ts-key"];
|
|
2489
|
+
const { response } = await __privateMethod(this, _handleHttpEndpointRequestForResponse, handleHttpEndpointRequestForResponse_fn).call(this, {
|
|
2490
|
+
key
|
|
2491
|
+
}, sourceRequest);
|
|
2492
|
+
return {
|
|
2493
|
+
status: 200,
|
|
2494
|
+
body: response,
|
|
2495
|
+
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
2496
|
+
};
|
|
2497
|
+
}
|
|
1987
2498
|
case "VALIDATE": {
|
|
1988
2499
|
return {
|
|
1989
2500
|
status: 200,
|
|
@@ -2016,6 +2527,10 @@ var TriggerClient = class {
|
|
|
2016
2527
|
};
|
|
2017
2528
|
}
|
|
2018
2529
|
defineJob(options) {
|
|
2530
|
+
const existingRegisteredJob = __privateGet(this, _registeredJobs)[options.id];
|
|
2531
|
+
if (existingRegisteredJob) {
|
|
2532
|
+
console.warn((0, import_colorette.yellow)(`[@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.`));
|
|
2533
|
+
}
|
|
2019
2534
|
return new Job(this, options);
|
|
2020
2535
|
}
|
|
2021
2536
|
defineAuthResolver(integration, resolver) {
|
|
@@ -2028,6 +2543,15 @@ var TriggerClient = class {
|
|
|
2028
2543
|
defineDynamicTrigger(options) {
|
|
2029
2544
|
return new DynamicTrigger(this, options);
|
|
2030
2545
|
}
|
|
2546
|
+
defineHttpEndpoint(options) {
|
|
2547
|
+
const existingHttpEndpoint = __privateGet(this, _registeredHttpEndpoints)[options.id];
|
|
2548
|
+
if (existingHttpEndpoint) {
|
|
2549
|
+
console.warn((0, import_colorette.yellow)(`[@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.`));
|
|
2550
|
+
}
|
|
2551
|
+
const endpoint = httpEndpoint(options);
|
|
2552
|
+
__privateGet(this, _registeredHttpEndpoints)[endpoint.id] = endpoint;
|
|
2553
|
+
return endpoint;
|
|
2554
|
+
}
|
|
2031
2555
|
attach(job) {
|
|
2032
2556
|
__privateGet(this, _registeredJobs)[job.id] = job;
|
|
2033
2557
|
job.trigger.attachToJob(this, job);
|
|
@@ -2142,8 +2666,8 @@ var TriggerClient = class {
|
|
|
2142
2666
|
});
|
|
2143
2667
|
__privateGet(this, _registeredSchedules)[key] = jobs;
|
|
2144
2668
|
}
|
|
2145
|
-
async registerTrigger(id, key, options) {
|
|
2146
|
-
return __privateGet(this, _client2).registerTrigger(this.id, id, key, options);
|
|
2669
|
+
async registerTrigger(id, key, options, idempotencyKey) {
|
|
2670
|
+
return __privateGet(this, _client2).registerTrigger(this.id, id, key, options, idempotencyKey);
|
|
2147
2671
|
}
|
|
2148
2672
|
async getAuth(id) {
|
|
2149
2673
|
return __privateGet(this, _client2).getAuth(this.id, id);
|
|
@@ -2181,6 +2705,9 @@ var TriggerClient = class {
|
|
|
2181
2705
|
async getRunStatuses(runId) {
|
|
2182
2706
|
return __privateGet(this, _client2).getRunStatuses(runId);
|
|
2183
2707
|
}
|
|
2708
|
+
async invokeJob(jobId, payload, options) {
|
|
2709
|
+
return __privateGet(this, _client2).invokeJob(jobId, payload, options);
|
|
2710
|
+
}
|
|
2184
2711
|
authorized(apiKey) {
|
|
2185
2712
|
if (typeof apiKey !== "string") {
|
|
2186
2713
|
return "missing-header";
|
|
@@ -2203,6 +2730,7 @@ _registeredHttpSourceHandlers = new WeakMap();
|
|
|
2203
2730
|
_registeredDynamicTriggers = new WeakMap();
|
|
2204
2731
|
_jobMetadataByDynamicTriggers = new WeakMap();
|
|
2205
2732
|
_registeredSchedules = new WeakMap();
|
|
2733
|
+
_registeredHttpEndpoints = new WeakMap();
|
|
2206
2734
|
_authResolvers = new WeakMap();
|
|
2207
2735
|
_client2 = new WeakMap();
|
|
2208
2736
|
_internalLogger = new WeakMap();
|
|
@@ -2236,7 +2764,7 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1, timeOrigin, t
|
|
|
2236
2764
|
client: this,
|
|
2237
2765
|
context,
|
|
2238
2766
|
jobLogLevel: job1.logLevel ?? __privateGet(this, _options4).logLevel ?? "info",
|
|
2239
|
-
jobLogger: __privateGet(this, _options4).ioLogLocalEnabled ? new
|
|
2767
|
+
jobLogger: __privateGet(this, _options4).ioLogLocalEnabled ? new import_core8.Logger(job1.id, job1.logLevel ?? __privateGet(this, _options4).logLevel ?? "info") : void 0,
|
|
2240
2768
|
serverVersion: triggerVersion,
|
|
2241
2769
|
timeOrigin,
|
|
2242
2770
|
executionTimeout: body1.runChunkExecutionLimit
|
|
@@ -2250,11 +2778,23 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1, timeOrigin, t
|
|
|
2250
2778
|
}
|
|
2251
2779
|
const ioWithConnections = createIOWithIntegrations(io, resolvedConnections.data, job1.options.integrations);
|
|
2252
2780
|
try {
|
|
2781
|
+
const parsedPayload = job1.trigger.event.parsePayload(body1.event.payload ?? {});
|
|
2782
|
+
if (!context.run.isTest) {
|
|
2783
|
+
const verified = await job1.trigger.verifyPayload(parsedPayload);
|
|
2784
|
+
if (!verified.success) {
|
|
2785
|
+
return {
|
|
2786
|
+
status: "ERROR",
|
|
2787
|
+
error: {
|
|
2788
|
+
message: `Payload verification failed. ${verified.reason}`
|
|
2789
|
+
}
|
|
2790
|
+
};
|
|
2791
|
+
}
|
|
2792
|
+
}
|
|
2253
2793
|
const output = await runLocalStorage.runWith({
|
|
2254
2794
|
io,
|
|
2255
2795
|
ctx: context
|
|
2256
2796
|
}, () => {
|
|
2257
|
-
return job1.options.run(
|
|
2797
|
+
return job1.options.run(parsedPayload, ioWithConnections, context);
|
|
2258
2798
|
});
|
|
2259
2799
|
if (__privateGet(this, _options4).verbose) {
|
|
2260
2800
|
__privateMethod(this, _logIOStats, logIOStats_fn).call(this, io.stats);
|
|
@@ -2267,96 +2807,126 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1, timeOrigin, t
|
|
|
2267
2807
|
if (__privateGet(this, _options4).verbose) {
|
|
2268
2808
|
__privateMethod(this, _logIOStats, logIOStats_fn).call(this, io.stats);
|
|
2269
2809
|
}
|
|
2270
|
-
if (error instanceof
|
|
2271
|
-
return {
|
|
2272
|
-
status: "AUTO_YIELD_EXECUTION",
|
|
2273
|
-
location: error.location,
|
|
2274
|
-
timeRemaining: error.timeRemaining,
|
|
2275
|
-
timeElapsed: error.timeElapsed,
|
|
2276
|
-
limit: body1.runChunkExecutionLimit
|
|
2277
|
-
};
|
|
2278
|
-
}
|
|
2279
|
-
if (error instanceof AutoYieldWithCompletedTaskExecutionError) {
|
|
2280
|
-
return {
|
|
2281
|
-
status: "AUTO_YIELD_EXECUTION_WITH_COMPLETED_TASK",
|
|
2282
|
-
id: error.id,
|
|
2283
|
-
properties: error.properties,
|
|
2284
|
-
output: error.output,
|
|
2285
|
-
data: {
|
|
2286
|
-
...error.data,
|
|
2287
|
-
limit: body1.runChunkExecutionLimit
|
|
2288
|
-
}
|
|
2289
|
-
};
|
|
2290
|
-
}
|
|
2291
|
-
if (error instanceof YieldExecutionError) {
|
|
2292
|
-
return {
|
|
2293
|
-
status: "YIELD_EXECUTION",
|
|
2294
|
-
key: error.key
|
|
2295
|
-
};
|
|
2296
|
-
}
|
|
2297
|
-
if (error instanceof ParsedPayloadSchemaError) {
|
|
2298
|
-
return {
|
|
2299
|
-
status: "INVALID_PAYLOAD",
|
|
2300
|
-
errors: error.schemaErrors
|
|
2301
|
-
};
|
|
2302
|
-
}
|
|
2303
|
-
if (error instanceof ResumeWithTaskError) {
|
|
2810
|
+
if (error instanceof ResumeWithParallelTaskError) {
|
|
2304
2811
|
return {
|
|
2305
|
-
status: "
|
|
2306
|
-
task: error.task
|
|
2307
|
-
};
|
|
2308
|
-
}
|
|
2309
|
-
if (error instanceof RetryWithTaskError) {
|
|
2310
|
-
return {
|
|
2311
|
-
status: "RETRY_WITH_TASK",
|
|
2812
|
+
status: "RESUME_WITH_PARALLEL_TASK",
|
|
2312
2813
|
task: error.task,
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
}
|
|
2317
|
-
if (error instanceof CanceledWithTaskError) {
|
|
2318
|
-
return {
|
|
2319
|
-
status: "CANCELED",
|
|
2320
|
-
task: error.task
|
|
2814
|
+
childErrors: error.childErrors.map((childError) => {
|
|
2815
|
+
return __privateMethod(this, _convertErrorToExecutionResponse, convertErrorToExecutionResponse_fn).call(this, childError, body1);
|
|
2816
|
+
})
|
|
2321
2817
|
};
|
|
2322
2818
|
}
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2819
|
+
return __privateMethod(this, _convertErrorToExecutionResponse, convertErrorToExecutionResponse_fn).call(this, error, body1);
|
|
2820
|
+
}
|
|
2821
|
+
}, "#executeJob");
|
|
2822
|
+
_convertErrorToExecutionResponse = new WeakSet();
|
|
2823
|
+
convertErrorToExecutionResponse_fn = /* @__PURE__ */ __name(function(error, body2) {
|
|
2824
|
+
if (error instanceof AutoYieldExecutionError) {
|
|
2825
|
+
return {
|
|
2826
|
+
status: "AUTO_YIELD_EXECUTION",
|
|
2827
|
+
location: error.location,
|
|
2828
|
+
timeRemaining: error.timeRemaining,
|
|
2829
|
+
timeElapsed: error.timeElapsed,
|
|
2830
|
+
limit: body2.runChunkExecutionLimit
|
|
2831
|
+
};
|
|
2832
|
+
}
|
|
2833
|
+
if (error instanceof AutoYieldWithCompletedTaskExecutionError) {
|
|
2834
|
+
return {
|
|
2835
|
+
status: "AUTO_YIELD_EXECUTION_WITH_COMPLETED_TASK",
|
|
2836
|
+
id: error.id,
|
|
2837
|
+
properties: error.properties,
|
|
2838
|
+
output: error.output,
|
|
2839
|
+
data: {
|
|
2840
|
+
...error.data,
|
|
2841
|
+
limit: body2.runChunkExecutionLimit
|
|
2331
2842
|
}
|
|
2843
|
+
};
|
|
2844
|
+
}
|
|
2845
|
+
if (error instanceof YieldExecutionError) {
|
|
2846
|
+
return {
|
|
2847
|
+
status: "YIELD_EXECUTION",
|
|
2848
|
+
key: error.key
|
|
2849
|
+
};
|
|
2850
|
+
}
|
|
2851
|
+
if (error instanceof ParsedPayloadSchemaError) {
|
|
2852
|
+
return {
|
|
2853
|
+
status: "INVALID_PAYLOAD",
|
|
2854
|
+
errors: error.schemaErrors
|
|
2855
|
+
};
|
|
2856
|
+
}
|
|
2857
|
+
if (error instanceof ResumeWithTaskError) {
|
|
2858
|
+
return {
|
|
2859
|
+
status: "RESUME_WITH_TASK",
|
|
2860
|
+
task: error.task
|
|
2861
|
+
};
|
|
2862
|
+
}
|
|
2863
|
+
if (error instanceof RetryWithTaskError) {
|
|
2864
|
+
return {
|
|
2865
|
+
status: "RETRY_WITH_TASK",
|
|
2866
|
+
task: error.task,
|
|
2867
|
+
error: error.cause,
|
|
2868
|
+
retryAt: error.retryAt
|
|
2869
|
+
};
|
|
2870
|
+
}
|
|
2871
|
+
if (error instanceof CanceledWithTaskError) {
|
|
2872
|
+
return {
|
|
2873
|
+
status: "CANCELED",
|
|
2874
|
+
task: error.task
|
|
2875
|
+
};
|
|
2876
|
+
}
|
|
2877
|
+
if (error instanceof ErrorWithTask) {
|
|
2878
|
+
const errorWithStack2 = import_core8.ErrorWithStackSchema.safeParse(error.cause.output);
|
|
2879
|
+
if (errorWithStack2.success) {
|
|
2332
2880
|
return {
|
|
2333
2881
|
status: "ERROR",
|
|
2334
|
-
error:
|
|
2335
|
-
|
|
2336
|
-
},
|
|
2337
|
-
task: error.task
|
|
2882
|
+
error: errorWithStack2.data,
|
|
2883
|
+
task: error.cause
|
|
2338
2884
|
};
|
|
2339
2885
|
}
|
|
2340
|
-
|
|
2341
|
-
|
|
2886
|
+
return {
|
|
2887
|
+
status: "ERROR",
|
|
2888
|
+
error: {
|
|
2889
|
+
message: JSON.stringify(error.cause.output)
|
|
2890
|
+
},
|
|
2891
|
+
task: error.cause
|
|
2892
|
+
};
|
|
2893
|
+
}
|
|
2894
|
+
if (error instanceof RetryWithTaskError) {
|
|
2895
|
+
const errorWithStack2 = import_core8.ErrorWithStackSchema.safeParse(error.cause);
|
|
2896
|
+
if (errorWithStack2.success) {
|
|
2342
2897
|
return {
|
|
2343
2898
|
status: "ERROR",
|
|
2344
|
-
error:
|
|
2899
|
+
error: errorWithStack2.data,
|
|
2900
|
+
task: error.task
|
|
2345
2901
|
};
|
|
2346
2902
|
}
|
|
2347
|
-
const message = typeof error === "string" ? error : JSON.stringify(error);
|
|
2348
2903
|
return {
|
|
2349
2904
|
status: "ERROR",
|
|
2350
2905
|
error: {
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2906
|
+
message: "Unknown error"
|
|
2907
|
+
},
|
|
2908
|
+
task: error.task
|
|
2354
2909
|
};
|
|
2355
2910
|
}
|
|
2356
|
-
|
|
2911
|
+
const errorWithStack = import_core8.ErrorWithStackSchema.safeParse(error);
|
|
2912
|
+
if (errorWithStack.success) {
|
|
2913
|
+
return {
|
|
2914
|
+
status: "ERROR",
|
|
2915
|
+
error: errorWithStack.data
|
|
2916
|
+
};
|
|
2917
|
+
}
|
|
2918
|
+
const message = typeof error === "string" ? error : JSON.stringify(error);
|
|
2919
|
+
return {
|
|
2920
|
+
status: "ERROR",
|
|
2921
|
+
error: {
|
|
2922
|
+
name: "Unknown error",
|
|
2923
|
+
message
|
|
2924
|
+
}
|
|
2925
|
+
};
|
|
2926
|
+
}, "#convertErrorToExecutionResponse");
|
|
2357
2927
|
_createRunContext = new WeakSet();
|
|
2358
2928
|
createRunContext_fn = /* @__PURE__ */ __name(function(execution) {
|
|
2359
|
-
const { event, organization, environment, job, run, source } = execution;
|
|
2929
|
+
const { event, organization, project, environment, job, run, source } = execution;
|
|
2360
2930
|
return {
|
|
2361
2931
|
event: {
|
|
2362
2932
|
id: event.id,
|
|
@@ -2365,6 +2935,11 @@ createRunContext_fn = /* @__PURE__ */ __name(function(execution) {
|
|
|
2365
2935
|
timestamp: event.timestamp
|
|
2366
2936
|
},
|
|
2367
2937
|
organization,
|
|
2938
|
+
project: project ?? {
|
|
2939
|
+
id: "unknown",
|
|
2940
|
+
name: "unknown",
|
|
2941
|
+
slug: "unknown"
|
|
2942
|
+
},
|
|
2368
2943
|
environment,
|
|
2369
2944
|
job,
|
|
2370
2945
|
run,
|
|
@@ -2373,8 +2948,8 @@ createRunContext_fn = /* @__PURE__ */ __name(function(execution) {
|
|
|
2373
2948
|
};
|
|
2374
2949
|
}, "#createRunContext");
|
|
2375
2950
|
_createPreprocessRunContext = new WeakSet();
|
|
2376
|
-
createPreprocessRunContext_fn = /* @__PURE__ */ __name(function(
|
|
2377
|
-
const { event, organization, environment, job, run, account } =
|
|
2951
|
+
createPreprocessRunContext_fn = /* @__PURE__ */ __name(function(body3) {
|
|
2952
|
+
const { event, organization, environment, job, run, account } = body3;
|
|
2378
2953
|
return {
|
|
2379
2954
|
event: {
|
|
2380
2955
|
id: event.id,
|
|
@@ -2471,6 +3046,59 @@ handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourc
|
|
|
2471
3046
|
metadata: results.metadata
|
|
2472
3047
|
};
|
|
2473
3048
|
}, "#handleHttpSourceRequest");
|
|
3049
|
+
_handleHttpEndpointRequestForResponse = new WeakSet();
|
|
3050
|
+
handleHttpEndpointRequestForResponse_fn = /* @__PURE__ */ __name(async function(data, sourceRequest1) {
|
|
3051
|
+
__privateGet(this, _internalLogger).debug("Handling HTTP Endpoint request for response", {
|
|
3052
|
+
data
|
|
3053
|
+
});
|
|
3054
|
+
const httpEndpoint2 = __privateGet(this, _registeredHttpEndpoints)[data.key];
|
|
3055
|
+
if (!httpEndpoint2) {
|
|
3056
|
+
__privateGet(this, _internalLogger).debug("No handler registered for HTTP Endpoint", {
|
|
3057
|
+
data
|
|
3058
|
+
});
|
|
3059
|
+
return {
|
|
3060
|
+
response: {
|
|
3061
|
+
status: 200,
|
|
3062
|
+
body: {
|
|
3063
|
+
ok: true
|
|
3064
|
+
}
|
|
3065
|
+
}
|
|
3066
|
+
};
|
|
3067
|
+
}
|
|
3068
|
+
const handledResponse = await httpEndpoint2.handleRequest(sourceRequest1);
|
|
3069
|
+
if (!handledResponse) {
|
|
3070
|
+
__privateGet(this, _internalLogger).debug("There's no HTTP Endpoint respondWith.handler()", {
|
|
3071
|
+
data
|
|
3072
|
+
});
|
|
3073
|
+
return {
|
|
3074
|
+
response: {
|
|
3075
|
+
status: 200,
|
|
3076
|
+
body: {
|
|
3077
|
+
ok: true
|
|
3078
|
+
}
|
|
3079
|
+
}
|
|
3080
|
+
};
|
|
3081
|
+
}
|
|
3082
|
+
let body;
|
|
3083
|
+
try {
|
|
3084
|
+
body = await handledResponse.text();
|
|
3085
|
+
} catch (error) {
|
|
3086
|
+
__privateGet(this, _internalLogger).error(`Error reading httpEndpoint ${httpEndpoint2.id} respondWith.handler Response`, {
|
|
3087
|
+
error
|
|
3088
|
+
});
|
|
3089
|
+
}
|
|
3090
|
+
const response = {
|
|
3091
|
+
status: handledResponse.status,
|
|
3092
|
+
headers: handledResponse.headers ? Object.fromEntries(handledResponse.headers.entries()) : void 0,
|
|
3093
|
+
body
|
|
3094
|
+
};
|
|
3095
|
+
__privateGet(this, _internalLogger).info(`httpEndpoint ${httpEndpoint2.id} respondWith.handler response`, {
|
|
3096
|
+
response
|
|
3097
|
+
});
|
|
3098
|
+
return {
|
|
3099
|
+
response
|
|
3100
|
+
};
|
|
3101
|
+
}, "#handleHttpEndpointRequestForResponse");
|
|
2474
3102
|
_resolveConnections = new WeakSet();
|
|
2475
3103
|
resolveConnections_fn = /* @__PURE__ */ __name(async function(ctx, integrations, connections) {
|
|
2476
3104
|
if (!integrations) {
|
|
@@ -2628,7 +3256,7 @@ logIOStats_fn = /* @__PURE__ */ __name(function(stats) {
|
|
|
2628
3256
|
_standardResponseHeaders = new WeakSet();
|
|
2629
3257
|
standardResponseHeaders_fn = /* @__PURE__ */ __name(function(start) {
|
|
2630
3258
|
return {
|
|
2631
|
-
"Trigger-Version":
|
|
3259
|
+
"Trigger-Version": import_core8.API_VERSIONS.LAZY_LOADED_CACHED_TASKS,
|
|
2632
3260
|
"Trigger-SDK-Version": version,
|
|
2633
3261
|
"X-Trigger-Request-Timing": `dur=${performance.now() - start / 1e3}`
|
|
2634
3262
|
};
|
|
@@ -2658,7 +3286,7 @@ function deepMergeOptions(obj1, obj2) {
|
|
|
2658
3286
|
__name(deepMergeOptions, "deepMergeOptions");
|
|
2659
3287
|
|
|
2660
3288
|
// src/triggers/externalSource.ts
|
|
2661
|
-
var
|
|
3289
|
+
var import_core9 = require("@trigger.dev/core");
|
|
2662
3290
|
var ExternalSource = class {
|
|
2663
3291
|
constructor(channel, options) {
|
|
2664
3292
|
this.options = options;
|
|
@@ -2732,7 +3360,7 @@ var ExternalSourceTrigger = class {
|
|
|
2732
3360
|
title: "External Source",
|
|
2733
3361
|
rule: {
|
|
2734
3362
|
event: this.event.name,
|
|
2735
|
-
payload: (0,
|
|
3363
|
+
payload: (0, import_core9.deepMergeFilters)(this.options.source.filter(this.options.params, this.options.options), this.event.filter ?? {}, this.options.params.filter ?? {}),
|
|
2736
3364
|
source: this.event.source
|
|
2737
3365
|
},
|
|
2738
3366
|
properties: this.options.source.properties(this.options.params)
|
|
@@ -2750,6 +3378,11 @@ var ExternalSourceTrigger = class {
|
|
|
2750
3378
|
get preprocessRuns() {
|
|
2751
3379
|
return true;
|
|
2752
3380
|
}
|
|
3381
|
+
async verifyPayload(payload) {
|
|
3382
|
+
return {
|
|
3383
|
+
success: true
|
|
3384
|
+
};
|
|
3385
|
+
}
|
|
2753
3386
|
};
|
|
2754
3387
|
__name(ExternalSourceTrigger, "ExternalSourceTrigger");
|
|
2755
3388
|
function omit(obj, key) {
|
|
@@ -2767,7 +3400,7 @@ function omit(obj, key) {
|
|
|
2767
3400
|
__name(omit, "omit");
|
|
2768
3401
|
|
|
2769
3402
|
// src/triggers/notifications.ts
|
|
2770
|
-
var
|
|
3403
|
+
var import_core10 = require("@trigger.dev/core");
|
|
2771
3404
|
function missingConnectionNotification(integrations) {
|
|
2772
3405
|
return new MissingConnectionNotification({
|
|
2773
3406
|
integrations
|
|
@@ -2786,11 +3419,11 @@ var MissingConnectionNotification = class {
|
|
|
2786
3419
|
}
|
|
2787
3420
|
get event() {
|
|
2788
3421
|
return {
|
|
2789
|
-
name:
|
|
3422
|
+
name: import_core10.MISSING_CONNECTION_NOTIFICATION,
|
|
2790
3423
|
title: "Missing Connection Notification",
|
|
2791
3424
|
source: "trigger.dev",
|
|
2792
3425
|
icon: "connection-alert",
|
|
2793
|
-
parsePayload:
|
|
3426
|
+
parsePayload: import_core10.MissingConnectionNotificationPayloadSchema.parse,
|
|
2794
3427
|
properties: [
|
|
2795
3428
|
{
|
|
2796
3429
|
label: "Integrations",
|
|
@@ -2804,6 +3437,11 @@ var MissingConnectionNotification = class {
|
|
|
2804
3437
|
get preprocessRuns() {
|
|
2805
3438
|
return false;
|
|
2806
3439
|
}
|
|
3440
|
+
async verifyPayload(payload) {
|
|
3441
|
+
return {
|
|
3442
|
+
success: true
|
|
3443
|
+
};
|
|
3444
|
+
}
|
|
2807
3445
|
toJSON() {
|
|
2808
3446
|
return {
|
|
2809
3447
|
type: "static",
|
|
@@ -2827,11 +3465,11 @@ var MissingConnectionResolvedNotification = class {
|
|
|
2827
3465
|
}
|
|
2828
3466
|
get event() {
|
|
2829
3467
|
return {
|
|
2830
|
-
name:
|
|
3468
|
+
name: import_core10.MISSING_CONNECTION_RESOLVED_NOTIFICATION,
|
|
2831
3469
|
title: "Missing Connection Resolved Notification",
|
|
2832
3470
|
source: "trigger.dev",
|
|
2833
3471
|
icon: "connection-alert",
|
|
2834
|
-
parsePayload:
|
|
3472
|
+
parsePayload: import_core10.MissingConnectionResolvedNotificationPayloadSchema.parse,
|
|
2835
3473
|
properties: [
|
|
2836
3474
|
{
|
|
2837
3475
|
label: "Integrations",
|
|
@@ -2845,6 +3483,11 @@ var MissingConnectionResolvedNotification = class {
|
|
|
2845
3483
|
get preprocessRuns() {
|
|
2846
3484
|
return false;
|
|
2847
3485
|
}
|
|
3486
|
+
async verifyPayload(payload) {
|
|
3487
|
+
return {
|
|
3488
|
+
success: true
|
|
3489
|
+
};
|
|
3490
|
+
}
|
|
2848
3491
|
toJSON() {
|
|
2849
3492
|
return {
|
|
2850
3493
|
type: "static",
|
|
@@ -2863,6 +3506,115 @@ var MissingConnectionResolvedNotification = class {
|
|
|
2863
3506
|
};
|
|
2864
3507
|
__name(MissingConnectionResolvedNotification, "MissingConnectionResolvedNotification");
|
|
2865
3508
|
|
|
3509
|
+
// src/triggers/invokeTrigger.ts
|
|
3510
|
+
var _options5;
|
|
3511
|
+
var InvokeTrigger = class {
|
|
3512
|
+
constructor(options) {
|
|
3513
|
+
__privateAdd(this, _options5, void 0);
|
|
3514
|
+
__privateSet(this, _options5, options);
|
|
3515
|
+
}
|
|
3516
|
+
toJSON() {
|
|
3517
|
+
return {
|
|
3518
|
+
type: "invoke"
|
|
3519
|
+
};
|
|
3520
|
+
}
|
|
3521
|
+
get event() {
|
|
3522
|
+
return {
|
|
3523
|
+
name: "invoke",
|
|
3524
|
+
title: "Manual Invoke",
|
|
3525
|
+
source: "trigger.dev",
|
|
3526
|
+
examples: __privateGet(this, _options5).examples ?? [],
|
|
3527
|
+
icon: "trigger",
|
|
3528
|
+
parsePayload: (rawPayload) => {
|
|
3529
|
+
if (__privateGet(this, _options5).schema) {
|
|
3530
|
+
const results = __privateGet(this, _options5).schema.safeParse(rawPayload);
|
|
3531
|
+
if (!results.success) {
|
|
3532
|
+
throw new ParsedPayloadSchemaError(formatSchemaErrors(results.error.issues));
|
|
3533
|
+
}
|
|
3534
|
+
return results.data;
|
|
3535
|
+
}
|
|
3536
|
+
return rawPayload;
|
|
3537
|
+
},
|
|
3538
|
+
parseInvokePayload: (rawPayload) => {
|
|
3539
|
+
if (__privateGet(this, _options5).schema) {
|
|
3540
|
+
const results = __privateGet(this, _options5).schema.safeParse(rawPayload);
|
|
3541
|
+
if (!results.success) {
|
|
3542
|
+
throw new ParsedPayloadSchemaError(formatSchemaErrors(results.error.issues));
|
|
3543
|
+
}
|
|
3544
|
+
return results.data;
|
|
3545
|
+
}
|
|
3546
|
+
return rawPayload;
|
|
3547
|
+
}
|
|
3548
|
+
};
|
|
3549
|
+
}
|
|
3550
|
+
attachToJob(triggerClient, job) {
|
|
3551
|
+
}
|
|
3552
|
+
get preprocessRuns() {
|
|
3553
|
+
return false;
|
|
3554
|
+
}
|
|
3555
|
+
async verifyPayload() {
|
|
3556
|
+
return {
|
|
3557
|
+
success: true
|
|
3558
|
+
};
|
|
3559
|
+
}
|
|
3560
|
+
};
|
|
3561
|
+
__name(InvokeTrigger, "InvokeTrigger");
|
|
3562
|
+
_options5 = new WeakMap();
|
|
3563
|
+
function invokeTrigger(options) {
|
|
3564
|
+
return new InvokeTrigger(options ?? {});
|
|
3565
|
+
}
|
|
3566
|
+
__name(invokeTrigger, "invokeTrigger");
|
|
3567
|
+
|
|
3568
|
+
// src/types.ts
|
|
3569
|
+
var import_zod2 = require("zod");
|
|
3570
|
+
var EventSpecificationExampleSchema = import_zod2.z.object({
|
|
3571
|
+
id: import_zod2.z.string(),
|
|
3572
|
+
name: import_zod2.z.string(),
|
|
3573
|
+
icon: import_zod2.z.string().optional(),
|
|
3574
|
+
payload: import_zod2.z.any()
|
|
3575
|
+
});
|
|
3576
|
+
|
|
3577
|
+
// src/security.ts
|
|
3578
|
+
var import_crypto = __toESM(require("crypto"));
|
|
3579
|
+
async function verifyRequestSignature({ request, headerName, secret, algorithm }) {
|
|
3580
|
+
if (!secret) {
|
|
3581
|
+
return {
|
|
3582
|
+
success: false,
|
|
3583
|
+
reason: "Missing secret \u2013 you've probably not set an environment variable."
|
|
3584
|
+
};
|
|
3585
|
+
}
|
|
3586
|
+
const headerValue = request.headers.get(headerName);
|
|
3587
|
+
if (!headerValue) {
|
|
3588
|
+
return {
|
|
3589
|
+
success: false,
|
|
3590
|
+
reason: "Missing header"
|
|
3591
|
+
};
|
|
3592
|
+
}
|
|
3593
|
+
switch (algorithm) {
|
|
3594
|
+
case "sha256":
|
|
3595
|
+
const success = verifyHmacSha256(headerValue, secret, await request.text());
|
|
3596
|
+
if (success) {
|
|
3597
|
+
return {
|
|
3598
|
+
success
|
|
3599
|
+
};
|
|
3600
|
+
} else {
|
|
3601
|
+
return {
|
|
3602
|
+
success: false,
|
|
3603
|
+
reason: "Failed sha256 verification"
|
|
3604
|
+
};
|
|
3605
|
+
}
|
|
3606
|
+
default:
|
|
3607
|
+
throw new Error(`Unsupported algorithm: ${algorithm}`);
|
|
3608
|
+
}
|
|
3609
|
+
}
|
|
3610
|
+
__name(verifyRequestSignature, "verifyRequestSignature");
|
|
3611
|
+
function verifyHmacSha256(headerValue, secret, body) {
|
|
3612
|
+
const bodyDigest = import_crypto.default.createHmac("sha256", secret).update(body).digest("hex");
|
|
3613
|
+
const signature = headerValue?.replace("sha256=", "") ?? "";
|
|
3614
|
+
return signature === bodyDigest;
|
|
3615
|
+
}
|
|
3616
|
+
__name(verifyHmacSha256, "verifyHmacSha256");
|
|
3617
|
+
|
|
2866
3618
|
// src/index.ts
|
|
2867
3619
|
function redactString(strings, ...interpolations) {
|
|
2868
3620
|
return {
|
|
@@ -2877,12 +3629,15 @@ __name(redactString, "redactString");
|
|
|
2877
3629
|
CronTrigger,
|
|
2878
3630
|
DynamicSchedule,
|
|
2879
3631
|
DynamicTrigger,
|
|
3632
|
+
EventSpecificationExampleSchema,
|
|
2880
3633
|
EventTrigger,
|
|
2881
3634
|
ExternalSource,
|
|
2882
3635
|
ExternalSourceTrigger,
|
|
2883
3636
|
IO,
|
|
2884
3637
|
IOLogger,
|
|
2885
3638
|
IntervalTrigger,
|
|
3639
|
+
InvokeTrigger,
|
|
3640
|
+
JSONOutputSerializer,
|
|
2886
3641
|
Job,
|
|
2887
3642
|
MissingConnectionNotification,
|
|
2888
3643
|
MissingConnectionResolvedNotification,
|
|
@@ -2890,11 +3645,14 @@ __name(redactString, "redactString");
|
|
|
2890
3645
|
cronTrigger,
|
|
2891
3646
|
eventTrigger,
|
|
2892
3647
|
intervalTrigger,
|
|
3648
|
+
invokeTrigger,
|
|
2893
3649
|
isTriggerError,
|
|
2894
3650
|
missingConnectionNotification,
|
|
2895
3651
|
missingConnectionResolvedNotification,
|
|
2896
3652
|
omit,
|
|
2897
3653
|
redactString,
|
|
2898
|
-
retry
|
|
3654
|
+
retry,
|
|
3655
|
+
verifyHmacSha256,
|
|
3656
|
+
verifyRequestSignature
|
|
2899
3657
|
});
|
|
2900
3658
|
//# sourceMappingURL=index.js.map
|