@trigger.dev/sdk 2.2.4 → 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 +306 -38
- package/dist/index.js +920 -167
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
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
|
});
|
|
@@ -447,6 +585,31 @@ var ApiClient = class {
|
|
|
447
585
|
}
|
|
448
586
|
});
|
|
449
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
|
+
}
|
|
450
613
|
};
|
|
451
614
|
__name(ApiClient, "ApiClient");
|
|
452
615
|
_apiUrl = new WeakMap();
|
|
@@ -482,8 +645,11 @@ function getApiKey(key) {
|
|
|
482
645
|
};
|
|
483
646
|
}
|
|
484
647
|
__name(getApiKey, "getApiKey");
|
|
485
|
-
async function zodfetchWithVersions(versionedSchemaMap, unversionedSchema, url, requestInit, options) {
|
|
486
|
-
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
|
+
});
|
|
487
653
|
if ((!requestInit || requestInit.method === "GET") && response.status === 404 && options?.optional) {
|
|
488
654
|
return;
|
|
489
655
|
}
|
|
@@ -491,6 +657,11 @@ async function zodfetchWithVersions(versionedSchemaMap, unversionedSchema, url,
|
|
|
491
657
|
const body = await response.json();
|
|
492
658
|
throw new Error(body.error);
|
|
493
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
|
+
}
|
|
494
665
|
if (response.status !== 200) {
|
|
495
666
|
throw new Error(options?.errorMessage ?? `Failed to fetch ${url}, got status code ${response.status}`);
|
|
496
667
|
}
|
|
@@ -512,8 +683,11 @@ async function zodfetchWithVersions(versionedSchemaMap, unversionedSchema, url,
|
|
|
512
683
|
};
|
|
513
684
|
}
|
|
514
685
|
__name(zodfetchWithVersions, "zodfetchWithVersions");
|
|
515
|
-
async function zodfetch(schema, url, requestInit, options) {
|
|
516
|
-
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
|
+
});
|
|
517
691
|
if ((!requestInit || requestInit.method === "GET") && response.status === 404 && options?.optional) {
|
|
518
692
|
return;
|
|
519
693
|
}
|
|
@@ -521,6 +695,11 @@ async function zodfetch(schema, url, requestInit, options) {
|
|
|
521
695
|
const body = await response.json();
|
|
522
696
|
throw new Error(body.error);
|
|
523
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
|
+
}
|
|
524
703
|
if (response.status !== 200) {
|
|
525
704
|
throw new Error(options?.errorMessage ?? `Failed to fetch ${url}, got status code ${response.status}`);
|
|
526
705
|
}
|
|
@@ -528,6 +707,12 @@ async function zodfetch(schema, url, requestInit, options) {
|
|
|
528
707
|
return schema.parse(jsonBody);
|
|
529
708
|
}
|
|
530
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");
|
|
531
716
|
|
|
532
717
|
// src/errors.ts
|
|
533
718
|
var ResumeWithTaskError = class {
|
|
@@ -536,6 +721,13 @@ var ResumeWithTaskError = class {
|
|
|
536
721
|
}
|
|
537
722
|
};
|
|
538
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");
|
|
539
731
|
var RetryWithTaskError = class {
|
|
540
732
|
constructor(cause, task, retryAt) {
|
|
541
733
|
this.cause = cause;
|
|
@@ -565,11 +757,11 @@ var AutoYieldExecutionError = class {
|
|
|
565
757
|
};
|
|
566
758
|
__name(AutoYieldExecutionError, "AutoYieldExecutionError");
|
|
567
759
|
var AutoYieldWithCompletedTaskExecutionError = class {
|
|
568
|
-
constructor(id, properties,
|
|
760
|
+
constructor(id, properties, data, output) {
|
|
569
761
|
this.id = id;
|
|
570
762
|
this.properties = properties;
|
|
571
|
-
this.output = output;
|
|
572
763
|
this.data = data;
|
|
764
|
+
this.output = output;
|
|
573
765
|
}
|
|
574
766
|
};
|
|
575
767
|
__name(AutoYieldWithCompletedTaskExecutionError, "AutoYieldWithCompletedTaskExecutionError");
|
|
@@ -580,18 +772,160 @@ var ParsedPayloadSchemaError = class {
|
|
|
580
772
|
};
|
|
581
773
|
__name(ParsedPayloadSchemaError, "ParsedPayloadSchemaError");
|
|
582
774
|
function isTriggerError(err) {
|
|
583
|
-
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;
|
|
584
776
|
}
|
|
585
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");
|
|
586
920
|
|
|
587
921
|
// src/io.ts
|
|
588
|
-
var
|
|
922
|
+
var import_core4 = require("@trigger.dev/core");
|
|
589
923
|
var import_core_backend = require("@trigger.dev/core-backend");
|
|
590
|
-
var
|
|
924
|
+
var import_node_async_hooks2 = require("async_hooks");
|
|
591
925
|
var import_node_crypto = require("crypto");
|
|
592
926
|
|
|
593
927
|
// src/retry.ts
|
|
594
|
-
var
|
|
928
|
+
var import_core3 = require("@trigger.dev/core");
|
|
595
929
|
var retry = {
|
|
596
930
|
standardBackoff: {
|
|
597
931
|
limit: 8,
|
|
@@ -637,6 +971,15 @@ var TriggerStatus = class {
|
|
|
637
971
|
__name(TriggerStatus, "TriggerStatus");
|
|
638
972
|
|
|
639
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");
|
|
640
983
|
var _addToCachedTasks, addToCachedTasks_fn, _detectAutoYield, detectAutoYield_fn, _forceYield, forceYield_fn, _getTimeElapsed, getTimeElapsed_fn, _getRemainingTimeInMillis, getRemainingTimeInMillis_fn;
|
|
641
984
|
var IO = class {
|
|
642
985
|
constructor(options) {
|
|
@@ -645,11 +988,13 @@ var IO = class {
|
|
|
645
988
|
__privateAdd(this, _forceYield);
|
|
646
989
|
__privateAdd(this, _getTimeElapsed);
|
|
647
990
|
__privateAdd(this, _getRemainingTimeInMillis);
|
|
991
|
+
__publicField(this, "_outputSerializer", new JSONOutputSerializer());
|
|
992
|
+
__publicField(this, "_visitedCacheKeys", /* @__PURE__ */ new Set());
|
|
648
993
|
__publicField(this, "brb", this.yield.bind(this));
|
|
649
994
|
this._id = options.id;
|
|
650
995
|
this._apiClient = options.apiClient;
|
|
651
996
|
this._triggerClient = options.client;
|
|
652
|
-
this._logger = options.logger ?? new
|
|
997
|
+
this._logger = options.logger ?? new import_core4.Logger("trigger.dev", options.logLevel);
|
|
653
998
|
this._cachedTasks = /* @__PURE__ */ new Map();
|
|
654
999
|
this._jobLogger = options.jobLogger;
|
|
655
1000
|
this._jobLogLevel = options.jobLogLevel;
|
|
@@ -670,7 +1015,7 @@ var IO = class {
|
|
|
670
1015
|
});
|
|
671
1016
|
this._stats.initialCachedTasks = options.cachedTasks.length;
|
|
672
1017
|
}
|
|
673
|
-
this._taskStorage = new
|
|
1018
|
+
this._taskStorage = new import_node_async_hooks2.AsyncLocalStorage();
|
|
674
1019
|
this._context = options.context;
|
|
675
1020
|
this._yieldedExecutions = options.yieldedExecutions ?? [];
|
|
676
1021
|
if (options.noopTasksSet) {
|
|
@@ -691,7 +1036,7 @@ var IO = class {
|
|
|
691
1036
|
get logger() {
|
|
692
1037
|
return new IOLogger(async (level, message, data) => {
|
|
693
1038
|
let logLevel = "info";
|
|
694
|
-
if (
|
|
1039
|
+
if (import_core4.Logger.satisfiesLogLevel(logLevel, this._jobLogLevel)) {
|
|
695
1040
|
await this.runTask([
|
|
696
1041
|
message,
|
|
697
1042
|
level
|
|
@@ -743,6 +1088,56 @@ var IO = class {
|
|
|
743
1088
|
}
|
|
744
1089
|
});
|
|
745
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
|
+
}
|
|
746
1141
|
async wait(cacheKey, seconds) {
|
|
747
1142
|
return await this.runTask(cacheKey, async (task) => {
|
|
748
1143
|
}, {
|
|
@@ -758,13 +1153,41 @@ var IO = class {
|
|
|
758
1153
|
}
|
|
759
1154
|
});
|
|
760
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
|
+
}
|
|
761
1184
|
async createStatus(cacheKey, initialStatus) {
|
|
762
1185
|
const id = typeof cacheKey === "string" ? cacheKey : cacheKey.join("-");
|
|
763
1186
|
const status = new TriggerStatus(id, this);
|
|
764
1187
|
await status.update(cacheKey, initialStatus);
|
|
765
1188
|
return status;
|
|
766
1189
|
}
|
|
767
|
-
async backgroundFetch(cacheKey, url, requestInit, retry2) {
|
|
1190
|
+
async backgroundFetch(cacheKey, url, requestInit, retry2, timeout) {
|
|
768
1191
|
const urlObject = new URL(url);
|
|
769
1192
|
return await this.runTask(cacheKey, async (task) => {
|
|
770
1193
|
return task.output;
|
|
@@ -773,7 +1196,8 @@ var IO = class {
|
|
|
773
1196
|
params: {
|
|
774
1197
|
url,
|
|
775
1198
|
requestInit,
|
|
776
|
-
retry: retry2
|
|
1199
|
+
retry: retry2,
|
|
1200
|
+
timeout
|
|
777
1201
|
},
|
|
778
1202
|
operation: "fetch",
|
|
779
1203
|
icon: "background",
|
|
@@ -791,8 +1215,17 @@ var IO = class {
|
|
|
791
1215
|
{
|
|
792
1216
|
label: "background",
|
|
793
1217
|
text: "true"
|
|
794
|
-
}
|
|
795
|
-
|
|
1218
|
+
},
|
|
1219
|
+
...timeout ? [
|
|
1220
|
+
{
|
|
1221
|
+
label: "timeout",
|
|
1222
|
+
text: `${timeout.durationInMs}ms`
|
|
1223
|
+
}
|
|
1224
|
+
] : []
|
|
1225
|
+
],
|
|
1226
|
+
retry: {
|
|
1227
|
+
limit: 0
|
|
1228
|
+
}
|
|
796
1229
|
});
|
|
797
1230
|
}
|
|
798
1231
|
async sendEvent(cacheKey, event, options) {
|
|
@@ -990,6 +1423,25 @@ var IO = class {
|
|
|
990
1423
|
name: "get-auth"
|
|
991
1424
|
});
|
|
992
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
|
+
}
|
|
993
1445
|
async runTask(cacheKey, callback, options, onError) {
|
|
994
1446
|
__privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "start_task", 500);
|
|
995
1447
|
const parentId = this._taskStorage.getStore()?.taskId;
|
|
@@ -1005,6 +1457,14 @@ var IO = class {
|
|
|
1005
1457
|
parentId ?? "",
|
|
1006
1458
|
cacheKey
|
|
1007
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);
|
|
1008
1468
|
const cachedTask = this._cachedTasks.get(idempotencyKey);
|
|
1009
1469
|
if (cachedTask && cachedTask.status === "COMPLETED") {
|
|
1010
1470
|
this._logger.debug("Using completed cached task", {
|
|
@@ -1031,14 +1491,14 @@ var IO = class {
|
|
|
1031
1491
|
}, {
|
|
1032
1492
|
cachedTasksCursor: this._cachedTasksCursor
|
|
1033
1493
|
});
|
|
1034
|
-
const task = response.version ===
|
|
1494
|
+
const task = response.version === import_core4.API_VERSIONS.LAZY_LOADED_CACHED_TASKS ? response.body.task : response.body;
|
|
1035
1495
|
if (task.forceYield) {
|
|
1036
1496
|
this._logger.debug("Forcing yield after run task", {
|
|
1037
1497
|
idempotencyKey
|
|
1038
1498
|
});
|
|
1039
1499
|
__privateMethod(this, _forceYield, forceYield_fn).call(this, "after_run_task");
|
|
1040
1500
|
}
|
|
1041
|
-
if (response.version ===
|
|
1501
|
+
if (response.version === import_core4.API_VERSIONS.LAZY_LOADED_CACHED_TASKS) {
|
|
1042
1502
|
this._cachedTasksCursor = response.body.cachedTasks?.cursor;
|
|
1043
1503
|
for (const cachedTask2 of response.body.cachedTasks?.tasks ?? []) {
|
|
1044
1504
|
if (!this._cachedTasks.has(cachedTask2.idempotencyKey)) {
|
|
@@ -1077,7 +1537,7 @@ var IO = class {
|
|
|
1077
1537
|
idempotencyKey,
|
|
1078
1538
|
task
|
|
1079
1539
|
});
|
|
1080
|
-
throw new
|
|
1540
|
+
throw new ErrorWithTask(task, task.error ?? task?.output ? JSON.stringify(task.output) : "Task errored");
|
|
1081
1541
|
}
|
|
1082
1542
|
__privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "before_execute_task", 1500);
|
|
1083
1543
|
const executeTask = /* @__PURE__ */ __name(async () => {
|
|
@@ -1090,14 +1550,14 @@ var IO = class {
|
|
|
1090
1550
|
});
|
|
1091
1551
|
return {};
|
|
1092
1552
|
}
|
|
1093
|
-
const output =
|
|
1553
|
+
const output = this._outputSerializer.serialize(result);
|
|
1094
1554
|
this._logger.debug("Completing using output", {
|
|
1095
1555
|
idempotencyKey,
|
|
1096
1556
|
task
|
|
1097
1557
|
});
|
|
1098
1558
|
__privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "before_complete_task", 500, task, output);
|
|
1099
1559
|
const completedTask = await this._apiClient.completeTask(this._id, task.id, {
|
|
1100
|
-
output
|
|
1560
|
+
output,
|
|
1101
1561
|
properties: task.outputProperties ?? void 0
|
|
1102
1562
|
});
|
|
1103
1563
|
if (completedTask.forceYield) {
|
|
@@ -1111,7 +1571,7 @@ var IO = class {
|
|
|
1111
1571
|
throw new CanceledWithTaskError(completedTask);
|
|
1112
1572
|
}
|
|
1113
1573
|
__privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "after_complete_task", 500);
|
|
1114
|
-
return output;
|
|
1574
|
+
return this._outputSerializer.deserialize(output);
|
|
1115
1575
|
} catch (error) {
|
|
1116
1576
|
if (isTriggerError(error)) {
|
|
1117
1577
|
throw error;
|
|
@@ -1126,7 +1586,7 @@ var IO = class {
|
|
|
1126
1586
|
} else {
|
|
1127
1587
|
skipRetrying = !!onErrorResult.skipRetrying;
|
|
1128
1588
|
if (onErrorResult.retryAt && !skipRetrying) {
|
|
1129
|
-
const parsedError2 =
|
|
1589
|
+
const parsedError2 = import_core4.ErrorWithStackSchema.safeParse(onErrorResult.error);
|
|
1130
1590
|
throw new RetryWithTaskError(parsedError2.success ? parsedError2.data : {
|
|
1131
1591
|
message: "Unknown error"
|
|
1132
1592
|
}, task, onErrorResult.retryAt);
|
|
@@ -1140,9 +1600,14 @@ var IO = class {
|
|
|
1140
1600
|
error = innerError;
|
|
1141
1601
|
}
|
|
1142
1602
|
}
|
|
1143
|
-
|
|
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);
|
|
1144
1609
|
if (options?.retry && !skipRetrying) {
|
|
1145
|
-
const retryAt = (0,
|
|
1610
|
+
const retryAt = (0, import_core3.calculateRetryAt)(options.retry, task.attempts - 1);
|
|
1146
1611
|
if (retryAt) {
|
|
1147
1612
|
throw new RetryWithTaskError(parsedError.success ? parsedError.data : {
|
|
1148
1613
|
message: "Unknown error"
|
|
@@ -1189,7 +1654,7 @@ var IO = class {
|
|
|
1189
1654
|
}, executeTask);
|
|
1190
1655
|
}
|
|
1191
1656
|
yield(cacheKey) {
|
|
1192
|
-
if (!(0,
|
|
1657
|
+
if (!(0, import_core4.supportsFeature)("yieldExecution", this._serverVersion)) {
|
|
1193
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.");
|
|
1194
1659
|
return;
|
|
1195
1660
|
}
|
|
@@ -1219,11 +1684,11 @@ detectAutoYield_fn = /* @__PURE__ */ __name(function(location, threshold = 1500,
|
|
|
1219
1684
|
const timeRemaining = __privateMethod(this, _getRemainingTimeInMillis, getRemainingTimeInMillis_fn).call(this);
|
|
1220
1685
|
if (timeRemaining && timeRemaining < threshold) {
|
|
1221
1686
|
if (task1) {
|
|
1222
|
-
throw new AutoYieldWithCompletedTaskExecutionError(task1.id, task1.outputProperties ?? [],
|
|
1687
|
+
throw new AutoYieldWithCompletedTaskExecutionError(task1.id, task1.outputProperties ?? [], {
|
|
1223
1688
|
location,
|
|
1224
1689
|
timeRemaining,
|
|
1225
1690
|
timeElapsed: __privateMethod(this, _getTimeElapsed, getTimeElapsed_fn).call(this)
|
|
1226
|
-
});
|
|
1691
|
+
}, output);
|
|
1227
1692
|
} else {
|
|
1228
1693
|
throw new AutoYieldExecutionError(location, timeRemaining, __privateMethod(this, _getTimeElapsed, getTimeElapsed_fn).call(this));
|
|
1229
1694
|
}
|
|
@@ -1300,6 +1765,11 @@ var IOLogger = class {
|
|
|
1300
1765
|
}
|
|
1301
1766
|
};
|
|
1302
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");
|
|
1303
1773
|
|
|
1304
1774
|
// src/ioWithIntegrations.ts
|
|
1305
1775
|
function createIOWithIntegrations(io, auths, integrations) {
|
|
@@ -1330,26 +1800,8 @@ function createIOWithIntegrations(io, auths, integrations) {
|
|
|
1330
1800
|
}
|
|
1331
1801
|
__name(createIOWithIntegrations, "createIOWithIntegrations");
|
|
1332
1802
|
|
|
1333
|
-
// src/utils/typedAsyncLocalStorage.ts
|
|
1334
|
-
var import_node_async_hooks2 = require("async_hooks");
|
|
1335
|
-
var TypedAsyncLocalStorage = class {
|
|
1336
|
-
constructor() {
|
|
1337
|
-
this.storage = new import_node_async_hooks2.AsyncLocalStorage();
|
|
1338
|
-
}
|
|
1339
|
-
runWith(context, fn) {
|
|
1340
|
-
return this.storage.run(context, fn);
|
|
1341
|
-
}
|
|
1342
|
-
getStore() {
|
|
1343
|
-
return this.storage.getStore();
|
|
1344
|
-
}
|
|
1345
|
-
};
|
|
1346
|
-
__name(TypedAsyncLocalStorage, "TypedAsyncLocalStorage");
|
|
1347
|
-
|
|
1348
|
-
// src/runLocalStorage.ts
|
|
1349
|
-
var runLocalStorage = new TypedAsyncLocalStorage();
|
|
1350
|
-
|
|
1351
1803
|
// src/triggers/dynamic.ts
|
|
1352
|
-
var
|
|
1804
|
+
var import_core5 = require("@trigger.dev/core");
|
|
1353
1805
|
var _client, _options2;
|
|
1354
1806
|
var DynamicTrigger = class {
|
|
1355
1807
|
constructor(client, options) {
|
|
@@ -1378,7 +1830,7 @@ var DynamicTrigger = class {
|
|
|
1378
1830
|
rule: {
|
|
1379
1831
|
event: this.event.name,
|
|
1380
1832
|
source: this.event.source,
|
|
1381
|
-
payload: (0,
|
|
1833
|
+
payload: (0, import_core5.deepMergeFilters)(this.source.filter(params), this.event.filter ?? {}, options.filter ?? {})
|
|
1382
1834
|
},
|
|
1383
1835
|
source: {
|
|
1384
1836
|
version: "2",
|
|
@@ -1431,27 +1883,18 @@ var DynamicTrigger = class {
|
|
|
1431
1883
|
get preprocessRuns() {
|
|
1432
1884
|
return true;
|
|
1433
1885
|
}
|
|
1886
|
+
async verifyPayload(payload) {
|
|
1887
|
+
return {
|
|
1888
|
+
success: true
|
|
1889
|
+
};
|
|
1890
|
+
}
|
|
1434
1891
|
};
|
|
1435
1892
|
__name(DynamicTrigger, "DynamicTrigger");
|
|
1436
1893
|
_client = new WeakMap();
|
|
1437
1894
|
_options2 = new WeakMap();
|
|
1438
1895
|
|
|
1439
1896
|
// src/triggers/eventTrigger.ts
|
|
1440
|
-
var
|
|
1441
|
-
|
|
1442
|
-
// src/utils/formatSchemaErrors.ts
|
|
1443
|
-
function formatSchemaErrors(errors) {
|
|
1444
|
-
return errors.map((error) => {
|
|
1445
|
-
const { path, message } = error;
|
|
1446
|
-
return {
|
|
1447
|
-
path: path.map(String),
|
|
1448
|
-
message
|
|
1449
|
-
};
|
|
1450
|
-
});
|
|
1451
|
-
}
|
|
1452
|
-
__name(formatSchemaErrors, "formatSchemaErrors");
|
|
1453
|
-
|
|
1454
|
-
// src/triggers/eventTrigger.ts
|
|
1897
|
+
var import_core6 = require("@trigger.dev/core");
|
|
1455
1898
|
var _options3;
|
|
1456
1899
|
var EventTrigger = class {
|
|
1457
1900
|
constructor(options) {
|
|
@@ -1465,7 +1908,7 @@ var EventTrigger = class {
|
|
|
1465
1908
|
rule: {
|
|
1466
1909
|
event: __privateGet(this, _options3).name ?? __privateGet(this, _options3).event.name,
|
|
1467
1910
|
source: __privateGet(this, _options3).source ?? "trigger.dev",
|
|
1468
|
-
payload: (0,
|
|
1911
|
+
payload: (0, import_core6.deepMergeFilters)(__privateGet(this, _options3).filter ?? {}, __privateGet(this, _options3).event.filter ?? {})
|
|
1469
1912
|
}
|
|
1470
1913
|
};
|
|
1471
1914
|
}
|
|
@@ -1477,6 +1920,11 @@ var EventTrigger = class {
|
|
|
1477
1920
|
get preprocessRuns() {
|
|
1478
1921
|
return false;
|
|
1479
1922
|
}
|
|
1923
|
+
async verifyPayload(payload) {
|
|
1924
|
+
return {
|
|
1925
|
+
success: true
|
|
1926
|
+
};
|
|
1927
|
+
}
|
|
1480
1928
|
};
|
|
1481
1929
|
__name(EventTrigger, "EventTrigger");
|
|
1482
1930
|
_options3 = new WeakMap();
|
|
@@ -1506,7 +1954,7 @@ function eventTrigger(options) {
|
|
|
1506
1954
|
__name(eventTrigger, "eventTrigger");
|
|
1507
1955
|
|
|
1508
1956
|
// src/triggers/scheduled.ts
|
|
1509
|
-
var
|
|
1957
|
+
var import_core7 = require("@trigger.dev/core");
|
|
1510
1958
|
var import_cronstrue = __toESM(require("cronstrue"));
|
|
1511
1959
|
var examples = [
|
|
1512
1960
|
{
|
|
@@ -1514,8 +1962,8 @@ var examples = [
|
|
|
1514
1962
|
name: "Now",
|
|
1515
1963
|
icon: "clock",
|
|
1516
1964
|
payload: {
|
|
1517
|
-
ts:
|
|
1518
|
-
lastTimestamp:
|
|
1965
|
+
ts: import_core7.currentDate.marker,
|
|
1966
|
+
lastTimestamp: import_core7.currentDate.marker
|
|
1519
1967
|
}
|
|
1520
1968
|
}
|
|
1521
1969
|
];
|
|
@@ -1530,7 +1978,7 @@ var IntervalTrigger = class {
|
|
|
1530
1978
|
source: "trigger.dev",
|
|
1531
1979
|
icon: "schedule-interval",
|
|
1532
1980
|
examples,
|
|
1533
|
-
parsePayload:
|
|
1981
|
+
parsePayload: import_core7.ScheduledPayloadSchema.parse,
|
|
1534
1982
|
properties: [
|
|
1535
1983
|
{
|
|
1536
1984
|
label: "Interval",
|
|
@@ -1544,6 +1992,11 @@ var IntervalTrigger = class {
|
|
|
1544
1992
|
get preprocessRuns() {
|
|
1545
1993
|
return false;
|
|
1546
1994
|
}
|
|
1995
|
+
async verifyPayload(payload) {
|
|
1996
|
+
return {
|
|
1997
|
+
success: true
|
|
1998
|
+
};
|
|
1999
|
+
}
|
|
1547
2000
|
toJSON() {
|
|
1548
2001
|
return {
|
|
1549
2002
|
type: "scheduled",
|
|
@@ -1575,7 +2028,7 @@ var CronTrigger = class {
|
|
|
1575
2028
|
source: "trigger.dev",
|
|
1576
2029
|
icon: "schedule-cron",
|
|
1577
2030
|
examples,
|
|
1578
|
-
parsePayload:
|
|
2031
|
+
parsePayload: import_core7.ScheduledPayloadSchema.parse,
|
|
1579
2032
|
properties: [
|
|
1580
2033
|
{
|
|
1581
2034
|
label: "cron",
|
|
@@ -1593,6 +2046,11 @@ var CronTrigger = class {
|
|
|
1593
2046
|
get preprocessRuns() {
|
|
1594
2047
|
return false;
|
|
1595
2048
|
}
|
|
2049
|
+
async verifyPayload(payload) {
|
|
2050
|
+
return {
|
|
2051
|
+
success: true
|
|
2052
|
+
};
|
|
2053
|
+
}
|
|
1596
2054
|
toJSON() {
|
|
1597
2055
|
return {
|
|
1598
2056
|
type: "scheduled",
|
|
@@ -1626,7 +2084,7 @@ var DynamicSchedule = class {
|
|
|
1626
2084
|
source: "trigger.dev",
|
|
1627
2085
|
icon: "schedule-dynamic",
|
|
1628
2086
|
examples,
|
|
1629
|
-
parsePayload:
|
|
2087
|
+
parsePayload: import_core7.ScheduledPayloadSchema.parse
|
|
1630
2088
|
};
|
|
1631
2089
|
}
|
|
1632
2090
|
async register(key, metadata) {
|
|
@@ -1688,6 +2146,11 @@ var DynamicSchedule = class {
|
|
|
1688
2146
|
get preprocessRuns() {
|
|
1689
2147
|
return false;
|
|
1690
2148
|
}
|
|
2149
|
+
async verifyPayload(payload) {
|
|
2150
|
+
return {
|
|
2151
|
+
success: true
|
|
2152
|
+
};
|
|
2153
|
+
}
|
|
1691
2154
|
toJSON() {
|
|
1692
2155
|
return {
|
|
1693
2156
|
type: "dynamic",
|
|
@@ -1698,24 +2161,26 @@ var DynamicSchedule = class {
|
|
|
1698
2161
|
__name(DynamicSchedule, "DynamicSchedule");
|
|
1699
2162
|
|
|
1700
2163
|
// package.json
|
|
1701
|
-
var version = "2.2.
|
|
2164
|
+
var version = "2.2.5";
|
|
1702
2165
|
|
|
1703
2166
|
// src/triggerClient.ts
|
|
1704
2167
|
var registerSourceEvent = {
|
|
1705
|
-
name:
|
|
2168
|
+
name: import_core8.REGISTER_SOURCE_EVENT_V2,
|
|
1706
2169
|
title: "Register Source",
|
|
1707
2170
|
source: "internal",
|
|
1708
2171
|
icon: "register-source",
|
|
1709
|
-
parsePayload:
|
|
2172
|
+
parsePayload: import_core8.RegisterSourceEventSchemaV2.parse
|
|
1710
2173
|
};
|
|
1711
|
-
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;
|
|
1712
2175
|
var TriggerClient = class {
|
|
1713
2176
|
constructor(options) {
|
|
1714
2177
|
__privateAdd(this, _preprocessRun);
|
|
1715
2178
|
__privateAdd(this, _executeJob);
|
|
2179
|
+
__privateAdd(this, _convertErrorToExecutionResponse);
|
|
1716
2180
|
__privateAdd(this, _createRunContext);
|
|
1717
2181
|
__privateAdd(this, _createPreprocessRunContext);
|
|
1718
2182
|
__privateAdd(this, _handleHttpSourceRequest);
|
|
2183
|
+
__privateAdd(this, _handleHttpEndpointRequestForResponse);
|
|
1719
2184
|
__privateAdd(this, _resolveConnections);
|
|
1720
2185
|
__privateAdd(this, _resolveConnection);
|
|
1721
2186
|
__privateAdd(this, _buildJobsIndex);
|
|
@@ -1731,13 +2196,14 @@ var TriggerClient = class {
|
|
|
1731
2196
|
__privateAdd(this, _registeredDynamicTriggers, {});
|
|
1732
2197
|
__privateAdd(this, _jobMetadataByDynamicTriggers, {});
|
|
1733
2198
|
__privateAdd(this, _registeredSchedules, {});
|
|
2199
|
+
__privateAdd(this, _registeredHttpEndpoints, {});
|
|
1734
2200
|
__privateAdd(this, _authResolvers, {});
|
|
1735
2201
|
__privateAdd(this, _client2, void 0);
|
|
1736
2202
|
__privateAdd(this, _internalLogger, void 0);
|
|
1737
2203
|
this.id = options.id;
|
|
1738
2204
|
__privateSet(this, _options4, options);
|
|
1739
2205
|
__privateSet(this, _client2, new ApiClient(__privateGet(this, _options4)));
|
|
1740
|
-
__privateSet(this, _internalLogger, new
|
|
2206
|
+
__privateSet(this, _internalLogger, new import_core8.Logger("trigger.dev", __privateGet(this, _options4).verbose ? "debug" : "log", [
|
|
1741
2207
|
"output",
|
|
1742
2208
|
"noopTasksSet"
|
|
1743
2209
|
]));
|
|
@@ -1848,7 +2314,8 @@ var TriggerClient = class {
|
|
|
1848
2314
|
dynamicSchedules: Object.entries(__privateGet(this, _registeredSchedules)).map(([id, jobs]) => ({
|
|
1849
2315
|
id,
|
|
1850
2316
|
jobs
|
|
1851
|
-
}))
|
|
2317
|
+
})),
|
|
2318
|
+
httpEndpoints: Object.entries(__privateGet(this, _registeredHttpEndpoints)).map(([id, endpoint]) => endpoint.toJSON())
|
|
1852
2319
|
};
|
|
1853
2320
|
return {
|
|
1854
2321
|
status: 200,
|
|
@@ -1858,7 +2325,7 @@ var TriggerClient = class {
|
|
|
1858
2325
|
}
|
|
1859
2326
|
case "INITIALIZE_TRIGGER": {
|
|
1860
2327
|
const json = await request.json();
|
|
1861
|
-
const body =
|
|
2328
|
+
const body = import_core8.InitializeTriggerBodySchema.safeParse(json);
|
|
1862
2329
|
if (!body.success) {
|
|
1863
2330
|
return {
|
|
1864
2331
|
status: 400,
|
|
@@ -1884,7 +2351,7 @@ var TriggerClient = class {
|
|
|
1884
2351
|
}
|
|
1885
2352
|
case "EXECUTE_JOB": {
|
|
1886
2353
|
const json = await request.json();
|
|
1887
|
-
const execution =
|
|
2354
|
+
const execution = import_core8.RunJobBodySchema.safeParse(json);
|
|
1888
2355
|
if (!execution.success) {
|
|
1889
2356
|
return {
|
|
1890
2357
|
status: 400,
|
|
@@ -1903,6 +2370,12 @@ var TriggerClient = class {
|
|
|
1903
2370
|
};
|
|
1904
2371
|
}
|
|
1905
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
|
+
});
|
|
1906
2379
|
return {
|
|
1907
2380
|
status: 200,
|
|
1908
2381
|
body: results,
|
|
@@ -1911,7 +2384,7 @@ var TriggerClient = class {
|
|
|
1911
2384
|
}
|
|
1912
2385
|
case "PREPROCESS_RUN": {
|
|
1913
2386
|
const json = await request.json();
|
|
1914
|
-
const body =
|
|
2387
|
+
const body = import_core8.PreprocessRunBodySchema.safeParse(json);
|
|
1915
2388
|
if (!body.success) {
|
|
1916
2389
|
return {
|
|
1917
2390
|
status: 400,
|
|
@@ -1940,7 +2413,7 @@ var TriggerClient = class {
|
|
|
1940
2413
|
};
|
|
1941
2414
|
}
|
|
1942
2415
|
case "DELIVER_HTTP_SOURCE_REQUEST": {
|
|
1943
|
-
const headers =
|
|
2416
|
+
const headers = import_core8.HttpSourceRequestHeadersSchema.safeParse(Object.fromEntries(request.headers.entries()));
|
|
1944
2417
|
if (!headers.success) {
|
|
1945
2418
|
return {
|
|
1946
2419
|
status: 400,
|
|
@@ -1989,6 +2462,39 @@ var TriggerClient = class {
|
|
|
1989
2462
|
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
1990
2463
|
};
|
|
1991
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
|
+
}
|
|
1992
2498
|
case "VALIDATE": {
|
|
1993
2499
|
return {
|
|
1994
2500
|
status: 200,
|
|
@@ -2021,6 +2527,10 @@ var TriggerClient = class {
|
|
|
2021
2527
|
};
|
|
2022
2528
|
}
|
|
2023
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
|
+
}
|
|
2024
2534
|
return new Job(this, options);
|
|
2025
2535
|
}
|
|
2026
2536
|
defineAuthResolver(integration, resolver) {
|
|
@@ -2033,6 +2543,15 @@ var TriggerClient = class {
|
|
|
2033
2543
|
defineDynamicTrigger(options) {
|
|
2034
2544
|
return new DynamicTrigger(this, options);
|
|
2035
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
|
+
}
|
|
2036
2555
|
attach(job) {
|
|
2037
2556
|
__privateGet(this, _registeredJobs)[job.id] = job;
|
|
2038
2557
|
job.trigger.attachToJob(this, job);
|
|
@@ -2186,6 +2705,9 @@ var TriggerClient = class {
|
|
|
2186
2705
|
async getRunStatuses(runId) {
|
|
2187
2706
|
return __privateGet(this, _client2).getRunStatuses(runId);
|
|
2188
2707
|
}
|
|
2708
|
+
async invokeJob(jobId, payload, options) {
|
|
2709
|
+
return __privateGet(this, _client2).invokeJob(jobId, payload, options);
|
|
2710
|
+
}
|
|
2189
2711
|
authorized(apiKey) {
|
|
2190
2712
|
if (typeof apiKey !== "string") {
|
|
2191
2713
|
return "missing-header";
|
|
@@ -2208,6 +2730,7 @@ _registeredHttpSourceHandlers = new WeakMap();
|
|
|
2208
2730
|
_registeredDynamicTriggers = new WeakMap();
|
|
2209
2731
|
_jobMetadataByDynamicTriggers = new WeakMap();
|
|
2210
2732
|
_registeredSchedules = new WeakMap();
|
|
2733
|
+
_registeredHttpEndpoints = new WeakMap();
|
|
2211
2734
|
_authResolvers = new WeakMap();
|
|
2212
2735
|
_client2 = new WeakMap();
|
|
2213
2736
|
_internalLogger = new WeakMap();
|
|
@@ -2241,7 +2764,7 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1, timeOrigin, t
|
|
|
2241
2764
|
client: this,
|
|
2242
2765
|
context,
|
|
2243
2766
|
jobLogLevel: job1.logLevel ?? __privateGet(this, _options4).logLevel ?? "info",
|
|
2244
|
-
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,
|
|
2245
2768
|
serverVersion: triggerVersion,
|
|
2246
2769
|
timeOrigin,
|
|
2247
2770
|
executionTimeout: body1.runChunkExecutionLimit
|
|
@@ -2255,11 +2778,23 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1, timeOrigin, t
|
|
|
2255
2778
|
}
|
|
2256
2779
|
const ioWithConnections = createIOWithIntegrations(io, resolvedConnections.data, job1.options.integrations);
|
|
2257
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
|
+
}
|
|
2258
2793
|
const output = await runLocalStorage.runWith({
|
|
2259
2794
|
io,
|
|
2260
2795
|
ctx: context
|
|
2261
2796
|
}, () => {
|
|
2262
|
-
return job1.options.run(
|
|
2797
|
+
return job1.options.run(parsedPayload, ioWithConnections, context);
|
|
2263
2798
|
});
|
|
2264
2799
|
if (__privateGet(this, _options4).verbose) {
|
|
2265
2800
|
__privateMethod(this, _logIOStats, logIOStats_fn).call(this, io.stats);
|
|
@@ -2272,96 +2807,126 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1, timeOrigin, t
|
|
|
2272
2807
|
if (__privateGet(this, _options4).verbose) {
|
|
2273
2808
|
__privateMethod(this, _logIOStats, logIOStats_fn).call(this, io.stats);
|
|
2274
2809
|
}
|
|
2275
|
-
if (error instanceof
|
|
2276
|
-
return {
|
|
2277
|
-
status: "AUTO_YIELD_EXECUTION",
|
|
2278
|
-
location: error.location,
|
|
2279
|
-
timeRemaining: error.timeRemaining,
|
|
2280
|
-
timeElapsed: error.timeElapsed,
|
|
2281
|
-
limit: body1.runChunkExecutionLimit
|
|
2282
|
-
};
|
|
2283
|
-
}
|
|
2284
|
-
if (error instanceof AutoYieldWithCompletedTaskExecutionError) {
|
|
2285
|
-
return {
|
|
2286
|
-
status: "AUTO_YIELD_EXECUTION_WITH_COMPLETED_TASK",
|
|
2287
|
-
id: error.id,
|
|
2288
|
-
properties: error.properties,
|
|
2289
|
-
output: error.output,
|
|
2290
|
-
data: {
|
|
2291
|
-
...error.data,
|
|
2292
|
-
limit: body1.runChunkExecutionLimit
|
|
2293
|
-
}
|
|
2294
|
-
};
|
|
2295
|
-
}
|
|
2296
|
-
if (error instanceof YieldExecutionError) {
|
|
2297
|
-
return {
|
|
2298
|
-
status: "YIELD_EXECUTION",
|
|
2299
|
-
key: error.key
|
|
2300
|
-
};
|
|
2301
|
-
}
|
|
2302
|
-
if (error instanceof ParsedPayloadSchemaError) {
|
|
2303
|
-
return {
|
|
2304
|
-
status: "INVALID_PAYLOAD",
|
|
2305
|
-
errors: error.schemaErrors
|
|
2306
|
-
};
|
|
2307
|
-
}
|
|
2308
|
-
if (error instanceof ResumeWithTaskError) {
|
|
2309
|
-
return {
|
|
2310
|
-
status: "RESUME_WITH_TASK",
|
|
2311
|
-
task: error.task
|
|
2312
|
-
};
|
|
2313
|
-
}
|
|
2314
|
-
if (error instanceof RetryWithTaskError) {
|
|
2810
|
+
if (error instanceof ResumeWithParallelTaskError) {
|
|
2315
2811
|
return {
|
|
2316
|
-
status: "
|
|
2812
|
+
status: "RESUME_WITH_PARALLEL_TASK",
|
|
2317
2813
|
task: error.task,
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
}
|
|
2322
|
-
if (error instanceof CanceledWithTaskError) {
|
|
2323
|
-
return {
|
|
2324
|
-
status: "CANCELED",
|
|
2325
|
-
task: error.task
|
|
2814
|
+
childErrors: error.childErrors.map((childError) => {
|
|
2815
|
+
return __privateMethod(this, _convertErrorToExecutionResponse, convertErrorToExecutionResponse_fn).call(this, childError, body1);
|
|
2816
|
+
})
|
|
2326
2817
|
};
|
|
2327
2818
|
}
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
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
|
|
2336
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) {
|
|
2337
2880
|
return {
|
|
2338
2881
|
status: "ERROR",
|
|
2339
|
-
error:
|
|
2340
|
-
|
|
2341
|
-
},
|
|
2342
|
-
task: error.task
|
|
2882
|
+
error: errorWithStack2.data,
|
|
2883
|
+
task: error.cause
|
|
2343
2884
|
};
|
|
2344
2885
|
}
|
|
2345
|
-
|
|
2346
|
-
|
|
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) {
|
|
2347
2897
|
return {
|
|
2348
2898
|
status: "ERROR",
|
|
2349
|
-
error:
|
|
2899
|
+
error: errorWithStack2.data,
|
|
2900
|
+
task: error.task
|
|
2350
2901
|
};
|
|
2351
2902
|
}
|
|
2352
|
-
const message = typeof error === "string" ? error : JSON.stringify(error);
|
|
2353
2903
|
return {
|
|
2354
2904
|
status: "ERROR",
|
|
2355
2905
|
error: {
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2906
|
+
message: "Unknown error"
|
|
2907
|
+
},
|
|
2908
|
+
task: error.task
|
|
2359
2909
|
};
|
|
2360
2910
|
}
|
|
2361
|
-
|
|
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");
|
|
2362
2927
|
_createRunContext = new WeakSet();
|
|
2363
2928
|
createRunContext_fn = /* @__PURE__ */ __name(function(execution) {
|
|
2364
|
-
const { event, organization, environment, job, run, source } = execution;
|
|
2929
|
+
const { event, organization, project, environment, job, run, source } = execution;
|
|
2365
2930
|
return {
|
|
2366
2931
|
event: {
|
|
2367
2932
|
id: event.id,
|
|
@@ -2370,6 +2935,11 @@ createRunContext_fn = /* @__PURE__ */ __name(function(execution) {
|
|
|
2370
2935
|
timestamp: event.timestamp
|
|
2371
2936
|
},
|
|
2372
2937
|
organization,
|
|
2938
|
+
project: project ?? {
|
|
2939
|
+
id: "unknown",
|
|
2940
|
+
name: "unknown",
|
|
2941
|
+
slug: "unknown"
|
|
2942
|
+
},
|
|
2373
2943
|
environment,
|
|
2374
2944
|
job,
|
|
2375
2945
|
run,
|
|
@@ -2378,8 +2948,8 @@ createRunContext_fn = /* @__PURE__ */ __name(function(execution) {
|
|
|
2378
2948
|
};
|
|
2379
2949
|
}, "#createRunContext");
|
|
2380
2950
|
_createPreprocessRunContext = new WeakSet();
|
|
2381
|
-
createPreprocessRunContext_fn = /* @__PURE__ */ __name(function(
|
|
2382
|
-
const { event, organization, environment, job, run, account } =
|
|
2951
|
+
createPreprocessRunContext_fn = /* @__PURE__ */ __name(function(body3) {
|
|
2952
|
+
const { event, organization, environment, job, run, account } = body3;
|
|
2383
2953
|
return {
|
|
2384
2954
|
event: {
|
|
2385
2955
|
id: event.id,
|
|
@@ -2476,6 +3046,59 @@ handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourc
|
|
|
2476
3046
|
metadata: results.metadata
|
|
2477
3047
|
};
|
|
2478
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");
|
|
2479
3102
|
_resolveConnections = new WeakSet();
|
|
2480
3103
|
resolveConnections_fn = /* @__PURE__ */ __name(async function(ctx, integrations, connections) {
|
|
2481
3104
|
if (!integrations) {
|
|
@@ -2633,7 +3256,7 @@ logIOStats_fn = /* @__PURE__ */ __name(function(stats) {
|
|
|
2633
3256
|
_standardResponseHeaders = new WeakSet();
|
|
2634
3257
|
standardResponseHeaders_fn = /* @__PURE__ */ __name(function(start) {
|
|
2635
3258
|
return {
|
|
2636
|
-
"Trigger-Version":
|
|
3259
|
+
"Trigger-Version": import_core8.API_VERSIONS.LAZY_LOADED_CACHED_TASKS,
|
|
2637
3260
|
"Trigger-SDK-Version": version,
|
|
2638
3261
|
"X-Trigger-Request-Timing": `dur=${performance.now() - start / 1e3}`
|
|
2639
3262
|
};
|
|
@@ -2663,7 +3286,7 @@ function deepMergeOptions(obj1, obj2) {
|
|
|
2663
3286
|
__name(deepMergeOptions, "deepMergeOptions");
|
|
2664
3287
|
|
|
2665
3288
|
// src/triggers/externalSource.ts
|
|
2666
|
-
var
|
|
3289
|
+
var import_core9 = require("@trigger.dev/core");
|
|
2667
3290
|
var ExternalSource = class {
|
|
2668
3291
|
constructor(channel, options) {
|
|
2669
3292
|
this.options = options;
|
|
@@ -2737,7 +3360,7 @@ var ExternalSourceTrigger = class {
|
|
|
2737
3360
|
title: "External Source",
|
|
2738
3361
|
rule: {
|
|
2739
3362
|
event: this.event.name,
|
|
2740
|
-
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 ?? {}),
|
|
2741
3364
|
source: this.event.source
|
|
2742
3365
|
},
|
|
2743
3366
|
properties: this.options.source.properties(this.options.params)
|
|
@@ -2755,6 +3378,11 @@ var ExternalSourceTrigger = class {
|
|
|
2755
3378
|
get preprocessRuns() {
|
|
2756
3379
|
return true;
|
|
2757
3380
|
}
|
|
3381
|
+
async verifyPayload(payload) {
|
|
3382
|
+
return {
|
|
3383
|
+
success: true
|
|
3384
|
+
};
|
|
3385
|
+
}
|
|
2758
3386
|
};
|
|
2759
3387
|
__name(ExternalSourceTrigger, "ExternalSourceTrigger");
|
|
2760
3388
|
function omit(obj, key) {
|
|
@@ -2772,7 +3400,7 @@ function omit(obj, key) {
|
|
|
2772
3400
|
__name(omit, "omit");
|
|
2773
3401
|
|
|
2774
3402
|
// src/triggers/notifications.ts
|
|
2775
|
-
var
|
|
3403
|
+
var import_core10 = require("@trigger.dev/core");
|
|
2776
3404
|
function missingConnectionNotification(integrations) {
|
|
2777
3405
|
return new MissingConnectionNotification({
|
|
2778
3406
|
integrations
|
|
@@ -2791,11 +3419,11 @@ var MissingConnectionNotification = class {
|
|
|
2791
3419
|
}
|
|
2792
3420
|
get event() {
|
|
2793
3421
|
return {
|
|
2794
|
-
name:
|
|
3422
|
+
name: import_core10.MISSING_CONNECTION_NOTIFICATION,
|
|
2795
3423
|
title: "Missing Connection Notification",
|
|
2796
3424
|
source: "trigger.dev",
|
|
2797
3425
|
icon: "connection-alert",
|
|
2798
|
-
parsePayload:
|
|
3426
|
+
parsePayload: import_core10.MissingConnectionNotificationPayloadSchema.parse,
|
|
2799
3427
|
properties: [
|
|
2800
3428
|
{
|
|
2801
3429
|
label: "Integrations",
|
|
@@ -2809,6 +3437,11 @@ var MissingConnectionNotification = class {
|
|
|
2809
3437
|
get preprocessRuns() {
|
|
2810
3438
|
return false;
|
|
2811
3439
|
}
|
|
3440
|
+
async verifyPayload(payload) {
|
|
3441
|
+
return {
|
|
3442
|
+
success: true
|
|
3443
|
+
};
|
|
3444
|
+
}
|
|
2812
3445
|
toJSON() {
|
|
2813
3446
|
return {
|
|
2814
3447
|
type: "static",
|
|
@@ -2832,11 +3465,11 @@ var MissingConnectionResolvedNotification = class {
|
|
|
2832
3465
|
}
|
|
2833
3466
|
get event() {
|
|
2834
3467
|
return {
|
|
2835
|
-
name:
|
|
3468
|
+
name: import_core10.MISSING_CONNECTION_RESOLVED_NOTIFICATION,
|
|
2836
3469
|
title: "Missing Connection Resolved Notification",
|
|
2837
3470
|
source: "trigger.dev",
|
|
2838
3471
|
icon: "connection-alert",
|
|
2839
|
-
parsePayload:
|
|
3472
|
+
parsePayload: import_core10.MissingConnectionResolvedNotificationPayloadSchema.parse,
|
|
2840
3473
|
properties: [
|
|
2841
3474
|
{
|
|
2842
3475
|
label: "Integrations",
|
|
@@ -2850,6 +3483,11 @@ var MissingConnectionResolvedNotification = class {
|
|
|
2850
3483
|
get preprocessRuns() {
|
|
2851
3484
|
return false;
|
|
2852
3485
|
}
|
|
3486
|
+
async verifyPayload(payload) {
|
|
3487
|
+
return {
|
|
3488
|
+
success: true
|
|
3489
|
+
};
|
|
3490
|
+
}
|
|
2853
3491
|
toJSON() {
|
|
2854
3492
|
return {
|
|
2855
3493
|
type: "static",
|
|
@@ -2868,6 +3506,115 @@ var MissingConnectionResolvedNotification = class {
|
|
|
2868
3506
|
};
|
|
2869
3507
|
__name(MissingConnectionResolvedNotification, "MissingConnectionResolvedNotification");
|
|
2870
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
|
+
|
|
2871
3618
|
// src/index.ts
|
|
2872
3619
|
function redactString(strings, ...interpolations) {
|
|
2873
3620
|
return {
|
|
@@ -2882,12 +3629,15 @@ __name(redactString, "redactString");
|
|
|
2882
3629
|
CronTrigger,
|
|
2883
3630
|
DynamicSchedule,
|
|
2884
3631
|
DynamicTrigger,
|
|
3632
|
+
EventSpecificationExampleSchema,
|
|
2885
3633
|
EventTrigger,
|
|
2886
3634
|
ExternalSource,
|
|
2887
3635
|
ExternalSourceTrigger,
|
|
2888
3636
|
IO,
|
|
2889
3637
|
IOLogger,
|
|
2890
3638
|
IntervalTrigger,
|
|
3639
|
+
InvokeTrigger,
|
|
3640
|
+
JSONOutputSerializer,
|
|
2891
3641
|
Job,
|
|
2892
3642
|
MissingConnectionNotification,
|
|
2893
3643
|
MissingConnectionResolvedNotification,
|
|
@@ -2895,11 +3645,14 @@ __name(redactString, "redactString");
|
|
|
2895
3645
|
cronTrigger,
|
|
2896
3646
|
eventTrigger,
|
|
2897
3647
|
intervalTrigger,
|
|
3648
|
+
invokeTrigger,
|
|
2898
3649
|
isTriggerError,
|
|
2899
3650
|
missingConnectionNotification,
|
|
2900
3651
|
missingConnectionResolvedNotification,
|
|
2901
3652
|
omit,
|
|
2902
3653
|
redactString,
|
|
2903
|
-
retry
|
|
3654
|
+
retry,
|
|
3655
|
+
verifyHmacSha256,
|
|
3656
|
+
verifyRequestSignature
|
|
2904
3657
|
});
|
|
2905
3658
|
//# sourceMappingURL=index.js.map
|