@trigger.dev/sdk 2.0.0-next.1 → 2.0.0-next.10
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/LICENSE +201 -25
- package/dist/index.d.ts +776 -291
- package/dist/index.js +365 -163
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
9
|
var __export = (target, all) => {
|
|
@@ -16,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
18
|
}
|
|
17
19
|
return to;
|
|
18
20
|
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
19
25
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
26
|
var __accessCheck = (obj, member, msg) => {
|
|
21
27
|
if (!member.has(obj))
|
|
@@ -64,7 +70,7 @@ __export(src_exports, {
|
|
|
64
70
|
missingConnectionNotification: () => missingConnectionNotification,
|
|
65
71
|
missingConnectionResolvedNotification: () => missingConnectionResolvedNotification,
|
|
66
72
|
omit: () => omit,
|
|
67
|
-
|
|
73
|
+
redactString: () => redactString
|
|
68
74
|
});
|
|
69
75
|
module.exports = __toCommonJS(src_exports);
|
|
70
76
|
|
|
@@ -104,15 +110,17 @@ var Job = class {
|
|
|
104
110
|
get integrations() {
|
|
105
111
|
return Object.keys(this.options.integrations ?? {}).reduce((acc, key) => {
|
|
106
112
|
const integration = this.options.integrations[key];
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
+
acc[key] = {
|
|
114
|
+
id: integration.id,
|
|
115
|
+
metadata: integration.metadata,
|
|
116
|
+
authSource: integration.client.usesLocalAuth ? "LOCAL" : "HOSTED"
|
|
117
|
+
};
|
|
113
118
|
return acc;
|
|
114
119
|
}, {});
|
|
115
120
|
}
|
|
121
|
+
get logLevel() {
|
|
122
|
+
return this.options.logLevel;
|
|
123
|
+
}
|
|
116
124
|
toJSON() {
|
|
117
125
|
const internal = this.options.__internal;
|
|
118
126
|
return {
|
|
@@ -146,18 +154,23 @@ var logLevels = [
|
|
|
146
154
|
"info",
|
|
147
155
|
"debug"
|
|
148
156
|
];
|
|
149
|
-
var _name, _level, _filteredKeys;
|
|
157
|
+
var _name, _level, _filteredKeys, _jsonReplacer;
|
|
150
158
|
var _Logger = class {
|
|
151
|
-
constructor(name, level = "info", filteredKeys = []) {
|
|
159
|
+
constructor(name, level = "info", filteredKeys = [], jsonReplacer) {
|
|
152
160
|
__privateAdd(this, _name, void 0);
|
|
153
161
|
__privateAdd(this, _level, void 0);
|
|
154
162
|
__privateAdd(this, _filteredKeys, []);
|
|
163
|
+
__privateAdd(this, _jsonReplacer, void 0);
|
|
155
164
|
__privateSet(this, _name, name);
|
|
156
165
|
__privateSet(this, _level, logLevels.indexOf(process.env.TRIGGER_LOG_LEVEL ?? level));
|
|
157
166
|
__privateSet(this, _filteredKeys, filteredKeys);
|
|
167
|
+
__privateSet(this, _jsonReplacer, jsonReplacer);
|
|
158
168
|
}
|
|
159
169
|
filter(...keys) {
|
|
160
|
-
return new _Logger(__privateGet(this, _name), logLevels[__privateGet(this, _level)], keys);
|
|
170
|
+
return new _Logger(__privateGet(this, _name), logLevels[__privateGet(this, _level)], keys, __privateGet(this, _jsonReplacer));
|
|
171
|
+
}
|
|
172
|
+
static satisfiesLogLevel(logLevel, setLevel) {
|
|
173
|
+
return logLevels.indexOf(logLevel) <= logLevels.indexOf(setLevel);
|
|
161
174
|
}
|
|
162
175
|
log(...args) {
|
|
163
176
|
if (__privateGet(this, _level) < 0)
|
|
@@ -188,7 +201,7 @@ var _Logger = class {
|
|
|
188
201
|
message,
|
|
189
202
|
args: structureArgs(safeJsonClone(args), __privateGet(this, _filteredKeys))
|
|
190
203
|
};
|
|
191
|
-
console.debug(JSON.stringify(structuredLog,
|
|
204
|
+
console.debug(JSON.stringify(structuredLog, createReplacer(__privateGet(this, _jsonReplacer))));
|
|
192
205
|
}
|
|
193
206
|
};
|
|
194
207
|
var Logger = _Logger;
|
|
@@ -196,6 +209,19 @@ __name(Logger, "Logger");
|
|
|
196
209
|
_name = new WeakMap();
|
|
197
210
|
_level = new WeakMap();
|
|
198
211
|
_filteredKeys = new WeakMap();
|
|
212
|
+
_jsonReplacer = new WeakMap();
|
|
213
|
+
function createReplacer(replacer) {
|
|
214
|
+
return (key, value) => {
|
|
215
|
+
if (typeof value === "bigint") {
|
|
216
|
+
return value.toString();
|
|
217
|
+
}
|
|
218
|
+
if (replacer) {
|
|
219
|
+
return replacer(key, value);
|
|
220
|
+
}
|
|
221
|
+
return value;
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
__name(createReplacer, "createReplacer");
|
|
199
225
|
function bigIntReplacer(_key, value) {
|
|
200
226
|
if (typeof value === "bigint") {
|
|
201
227
|
return value.toString();
|
|
@@ -293,13 +319,17 @@ var ConnectionAuthSchema = import_zod3.z.object({
|
|
|
293
319
|
additionalFields: import_zod3.z.record(import_zod3.z.string()).optional()
|
|
294
320
|
});
|
|
295
321
|
var IntegrationMetadataSchema = import_zod3.z.object({
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
322
|
+
id: import_zod3.z.string(),
|
|
323
|
+
name: import_zod3.z.string(),
|
|
324
|
+
instructions: import_zod3.z.string().optional()
|
|
299
325
|
});
|
|
300
326
|
var IntegrationConfigSchema = import_zod3.z.object({
|
|
301
327
|
id: import_zod3.z.string(),
|
|
302
|
-
metadata: IntegrationMetadataSchema
|
|
328
|
+
metadata: IntegrationMetadataSchema,
|
|
329
|
+
authSource: import_zod3.z.enum([
|
|
330
|
+
"HOSTED",
|
|
331
|
+
"LOCAL"
|
|
332
|
+
])
|
|
303
333
|
});
|
|
304
334
|
|
|
305
335
|
// ../internal/src/schemas/json.ts
|
|
@@ -404,7 +434,8 @@ var TaskSchema = import_zod7.z.object({
|
|
|
404
434
|
output: DeserializedJsonSchema.optional().nullable(),
|
|
405
435
|
error: import_zod7.z.string().optional().nullable(),
|
|
406
436
|
parentId: import_zod7.z.string().optional().nullable(),
|
|
407
|
-
style: StyleSchema.optional().nullable()
|
|
437
|
+
style: StyleSchema.optional().nullable(),
|
|
438
|
+
operation: import_zod7.z.string().optional().nullable()
|
|
408
439
|
});
|
|
409
440
|
var ServerTaskSchema = TaskSchema.extend({
|
|
410
441
|
idempotencyKey: import_zod7.z.string(),
|
|
@@ -527,9 +558,17 @@ var HttpSourceRequestHeadersSchema = import_zod9.z.object({
|
|
|
527
558
|
"x-ts-http-method": import_zod9.z.string(),
|
|
528
559
|
"x-ts-http-headers": import_zod9.z.string().transform((s) => import_zod9.z.record(import_zod9.z.string()).parse(JSON.parse(s)))
|
|
529
560
|
});
|
|
530
|
-
var
|
|
531
|
-
|
|
561
|
+
var PongSuccessResponseSchema = import_zod9.z.object({
|
|
562
|
+
ok: import_zod9.z.literal(true)
|
|
563
|
+
});
|
|
564
|
+
var PongErrorResponseSchema = import_zod9.z.object({
|
|
565
|
+
ok: import_zod9.z.literal(false),
|
|
566
|
+
error: import_zod9.z.string()
|
|
532
567
|
});
|
|
568
|
+
var PongResponseSchema = import_zod9.z.discriminatedUnion("ok", [
|
|
569
|
+
PongSuccessResponseSchema,
|
|
570
|
+
PongErrorResponseSchema
|
|
571
|
+
]);
|
|
533
572
|
var QueueOptionsSchema = import_zod9.z.object({
|
|
534
573
|
name: import_zod9.z.string(),
|
|
535
574
|
maxConcurrent: import_zod9.z.number().optional()
|
|
@@ -559,10 +598,10 @@ var SourceMetadataSchema = import_zod9.z.object({
|
|
|
559
598
|
"SQS",
|
|
560
599
|
"SMTP"
|
|
561
600
|
]),
|
|
601
|
+
integration: IntegrationConfigSchema,
|
|
562
602
|
key: import_zod9.z.string(),
|
|
563
603
|
params: import_zod9.z.any(),
|
|
564
|
-
events: import_zod9.z.array(import_zod9.z.string())
|
|
565
|
-
clientId: import_zod9.z.string().optional()
|
|
604
|
+
events: import_zod9.z.array(import_zod9.z.string())
|
|
566
605
|
});
|
|
567
606
|
var DynamicTriggerEndpointMetadataSchema = import_zod9.z.object({
|
|
568
607
|
id: import_zod9.z.string(),
|
|
@@ -571,19 +610,19 @@ var DynamicTriggerEndpointMetadataSchema = import_zod9.z.object({
|
|
|
571
610
|
version: true
|
|
572
611
|
}))
|
|
573
612
|
});
|
|
574
|
-
var
|
|
613
|
+
var IndexEndpointResponseSchema = import_zod9.z.object({
|
|
575
614
|
jobs: import_zod9.z.array(JobMetadataSchema),
|
|
576
615
|
sources: import_zod9.z.array(SourceMetadataSchema),
|
|
577
616
|
dynamicTriggers: import_zod9.z.array(DynamicTriggerEndpointMetadataSchema),
|
|
578
617
|
dynamicSchedules: import_zod9.z.array(RegisterDynamicSchedulePayloadSchema)
|
|
579
618
|
});
|
|
580
619
|
var RawEventSchema = import_zod9.z.object({
|
|
581
|
-
id: import_zod9.z.string().default(() => (0, import_ulid.ulid)()),
|
|
582
620
|
name: import_zod9.z.string(),
|
|
583
|
-
source: import_zod9.z.string().optional(),
|
|
584
621
|
payload: import_zod9.z.any(),
|
|
585
622
|
context: import_zod9.z.any().optional(),
|
|
586
|
-
|
|
623
|
+
id: import_zod9.z.string().default(() => (0, import_ulid.ulid)()),
|
|
624
|
+
timestamp: import_zod9.z.coerce.date().optional(),
|
|
625
|
+
source: import_zod9.z.string().optional()
|
|
587
626
|
});
|
|
588
627
|
var ApiEventLogSchema = import_zod9.z.object({
|
|
589
628
|
id: import_zod9.z.string(),
|
|
@@ -595,7 +634,7 @@ var ApiEventLogSchema = import_zod9.z.object({
|
|
|
595
634
|
deliveredAt: import_zod9.z.coerce.date().optional().nullable()
|
|
596
635
|
});
|
|
597
636
|
var SendEventOptionsSchema = import_zod9.z.object({
|
|
598
|
-
deliverAt: import_zod9.z.
|
|
637
|
+
deliverAt: import_zod9.z.coerce.date().optional(),
|
|
599
638
|
deliverAfter: import_zod9.z.number().int().optional(),
|
|
600
639
|
accountId: import_zod9.z.string().optional()
|
|
601
640
|
});
|
|
@@ -612,6 +651,10 @@ var RuntimeEnvironmentTypeSchema = import_zod9.z.enum([
|
|
|
612
651
|
"DEVELOPMENT",
|
|
613
652
|
"PREVIEW"
|
|
614
653
|
]);
|
|
654
|
+
var RunSourceContextSchema = import_zod9.z.object({
|
|
655
|
+
id: import_zod9.z.string(),
|
|
656
|
+
metadata: import_zod9.z.any()
|
|
657
|
+
});
|
|
615
658
|
var RunJobBodySchema = import_zod9.z.object({
|
|
616
659
|
event: ApiEventLogSchema,
|
|
617
660
|
job: import_zod9.z.object({
|
|
@@ -637,6 +680,7 @@ var RunJobBodySchema = import_zod9.z.object({
|
|
|
637
680
|
id: import_zod9.z.string(),
|
|
638
681
|
metadata: import_zod9.z.any()
|
|
639
682
|
}).optional(),
|
|
683
|
+
source: RunSourceContextSchema.optional(),
|
|
640
684
|
tasks: import_zod9.z.array(CachedTaskSchema).optional(),
|
|
641
685
|
connections: import_zod9.z.record(ConnectionAuthSchema).optional()
|
|
642
686
|
});
|
|
@@ -714,8 +758,8 @@ var CreateRunResponseBodySchema = import_zod9.z.discriminatedUnion("ok", [
|
|
|
714
758
|
CreateRunResponseOkSchema,
|
|
715
759
|
CreateRunResponseErrorSchema
|
|
716
760
|
]);
|
|
717
|
-
var
|
|
718
|
-
|
|
761
|
+
var RedactStringSchema = import_zod9.z.object({
|
|
762
|
+
__redactedString: import_zod9.z.literal(true),
|
|
719
763
|
strings: import_zod9.z.array(import_zod9.z.string()),
|
|
720
764
|
interpolations: import_zod9.z.array(import_zod9.z.string())
|
|
721
765
|
});
|
|
@@ -741,18 +785,21 @@ var RetryOptionsSchema = import_zod9.z.object({
|
|
|
741
785
|
});
|
|
742
786
|
var RunTaskOptionsSchema = import_zod9.z.object({
|
|
743
787
|
name: import_zod9.z.string(),
|
|
788
|
+
delayUntil: import_zod9.z.coerce.date().optional(),
|
|
789
|
+
retry: RetryOptionsSchema.optional(),
|
|
744
790
|
icon: import_zod9.z.string().optional(),
|
|
745
791
|
displayKey: import_zod9.z.string().optional(),
|
|
746
|
-
noop: import_zod9.z.boolean().default(false),
|
|
747
|
-
delayUntil: import_zod9.z.coerce.date().optional(),
|
|
748
792
|
description: import_zod9.z.string().optional(),
|
|
749
793
|
properties: import_zod9.z.array(DisplayPropertySchema).optional(),
|
|
750
|
-
params:
|
|
751
|
-
trigger: TriggerMetadataSchema.optional(),
|
|
752
|
-
redact: RedactSchema.optional(),
|
|
753
|
-
connectionKey: import_zod9.z.string().optional(),
|
|
794
|
+
params: import_zod9.z.any(),
|
|
754
795
|
style: StyleSchema.optional(),
|
|
755
|
-
|
|
796
|
+
connectionKey: import_zod9.z.string().optional(),
|
|
797
|
+
operation: import_zod9.z.enum([
|
|
798
|
+
"fetch"
|
|
799
|
+
]).optional(),
|
|
800
|
+
noop: import_zod9.z.boolean().default(false),
|
|
801
|
+
redact: RedactSchema.optional(),
|
|
802
|
+
trigger: TriggerMetadataSchema.optional()
|
|
756
803
|
});
|
|
757
804
|
var RunTaskBodyInputSchema = RunTaskOptionsSchema.extend({
|
|
758
805
|
idempotencyKey: import_zod9.z.string(),
|
|
@@ -794,7 +841,8 @@ var RegisterTriggerBodySchema = import_zod9.z.object({
|
|
|
794
841
|
var InitializeTriggerBodySchema = import_zod9.z.object({
|
|
795
842
|
id: import_zod9.z.string(),
|
|
796
843
|
params: import_zod9.z.any(),
|
|
797
|
-
accountId: import_zod9.z.string().optional()
|
|
844
|
+
accountId: import_zod9.z.string().optional(),
|
|
845
|
+
metadata: import_zod9.z.any().optional()
|
|
798
846
|
});
|
|
799
847
|
var RegisterCommonScheduleBodySchema = import_zod9.z.object({
|
|
800
848
|
id: import_zod9.z.string(),
|
|
@@ -833,9 +881,7 @@ var CommonMissingConnectionNotificationPayloadSchema = import_zod10.z.object({
|
|
|
833
881
|
title: import_zod10.z.string(),
|
|
834
882
|
scopes: import_zod10.z.array(import_zod10.z.string()),
|
|
835
883
|
createdAt: import_zod10.z.coerce.date(),
|
|
836
|
-
updatedAt: import_zod10.z.coerce.date()
|
|
837
|
-
integrationIdentifier: import_zod10.z.string(),
|
|
838
|
-
integrationAuthMethod: import_zod10.z.string()
|
|
884
|
+
updatedAt: import_zod10.z.coerce.date()
|
|
839
885
|
}),
|
|
840
886
|
authorizationUrl: import_zod10.z.string()
|
|
841
887
|
});
|
|
@@ -881,6 +927,39 @@ var MissingConnectionResolvedNotificationPayloadSchema = import_zod10.z.discrimi
|
|
|
881
927
|
MissingExternalConnectionResolvedNotificationPayloadSchema
|
|
882
928
|
]);
|
|
883
929
|
|
|
930
|
+
// ../internal/src/schemas/fetch.ts
|
|
931
|
+
var import_zod11 = require("zod");
|
|
932
|
+
var FetchRetryHeadersStrategySchema = import_zod11.z.object({
|
|
933
|
+
strategy: import_zod11.z.literal("headers"),
|
|
934
|
+
limitHeader: import_zod11.z.string(),
|
|
935
|
+
remainingHeader: import_zod11.z.string(),
|
|
936
|
+
resetHeader: import_zod11.z.string()
|
|
937
|
+
});
|
|
938
|
+
var FetchRetryBackoffStrategySchema = RetryOptionsSchema.extend({
|
|
939
|
+
strategy: import_zod11.z.literal("backoff")
|
|
940
|
+
});
|
|
941
|
+
var FetchRetryStrategySchema = import_zod11.z.discriminatedUnion("strategy", [
|
|
942
|
+
FetchRetryHeadersStrategySchema,
|
|
943
|
+
FetchRetryBackoffStrategySchema
|
|
944
|
+
]);
|
|
945
|
+
var FetchRequestInitSchema = import_zod11.z.object({
|
|
946
|
+
method: import_zod11.z.string().optional(),
|
|
947
|
+
headers: import_zod11.z.record(import_zod11.z.union([
|
|
948
|
+
import_zod11.z.string(),
|
|
949
|
+
RedactStringSchema
|
|
950
|
+
])).optional(),
|
|
951
|
+
body: import_zod11.z.union([
|
|
952
|
+
import_zod11.z.string(),
|
|
953
|
+
import_zod11.z.instanceof(ArrayBuffer)
|
|
954
|
+
]).optional()
|
|
955
|
+
});
|
|
956
|
+
var FetchRetryOptionsSchema = import_zod11.z.record(FetchRetryStrategySchema);
|
|
957
|
+
var FetchOperationSchema = import_zod11.z.object({
|
|
958
|
+
url: import_zod11.z.string(),
|
|
959
|
+
requestInit: FetchRequestInitSchema.optional(),
|
|
960
|
+
retry: import_zod11.z.record(FetchRetryStrategySchema).optional()
|
|
961
|
+
});
|
|
962
|
+
|
|
884
963
|
// ../internal/src/utils.ts
|
|
885
964
|
function deepMergeFilters(filter, other) {
|
|
886
965
|
const result = {
|
|
@@ -907,8 +986,40 @@ function deepMergeFilters(filter, other) {
|
|
|
907
986
|
}
|
|
908
987
|
__name(deepMergeFilters, "deepMergeFilters");
|
|
909
988
|
|
|
989
|
+
// ../internal/src/retry.ts
|
|
990
|
+
var DEFAULT_RETRY_OPTIONS = {
|
|
991
|
+
limit: 5,
|
|
992
|
+
factor: 1.8,
|
|
993
|
+
minTimeoutInMs: 1e3,
|
|
994
|
+
maxTimeoutInMs: 6e4,
|
|
995
|
+
randomize: true
|
|
996
|
+
};
|
|
997
|
+
function calculateRetryAt(retryOptions, attempts) {
|
|
998
|
+
const options = {
|
|
999
|
+
...DEFAULT_RETRY_OPTIONS,
|
|
1000
|
+
...retryOptions
|
|
1001
|
+
};
|
|
1002
|
+
const retryCount = attempts + 1;
|
|
1003
|
+
if (retryCount >= options.limit) {
|
|
1004
|
+
return;
|
|
1005
|
+
}
|
|
1006
|
+
const random = options.randomize ? Math.random() + 1 : 1;
|
|
1007
|
+
let timeoutInMs = Math.round(random * Math.max(options.minTimeoutInMs, 1) * Math.pow(options.factor, Math.max(attempts - 1, 0)));
|
|
1008
|
+
timeoutInMs = Math.min(timeoutInMs, options.maxTimeoutInMs);
|
|
1009
|
+
return new Date(Date.now() + timeoutInMs);
|
|
1010
|
+
}
|
|
1011
|
+
__name(calculateRetryAt, "calculateRetryAt");
|
|
1012
|
+
|
|
1013
|
+
// ../internal/src/replacements.ts
|
|
1014
|
+
var currentDate = {
|
|
1015
|
+
marker: "__CURRENT_DATE__",
|
|
1016
|
+
replace({ data: { now } }) {
|
|
1017
|
+
return now.toISOString();
|
|
1018
|
+
}
|
|
1019
|
+
};
|
|
1020
|
+
|
|
910
1021
|
// src/apiClient.ts
|
|
911
|
-
var
|
|
1022
|
+
var import_zod12 = require("zod");
|
|
912
1023
|
var _apiUrl, _options, _logger, _apiKey, apiKey_fn;
|
|
913
1024
|
var ApiClient = class {
|
|
914
1025
|
constructor(options) {
|
|
@@ -1077,8 +1188,8 @@ var ApiClient = class {
|
|
|
1077
1188
|
__privateGet(this, _logger).debug("unregistering schedule", {
|
|
1078
1189
|
id
|
|
1079
1190
|
});
|
|
1080
|
-
const response = await zodfetch(
|
|
1081
|
-
ok:
|
|
1191
|
+
const response = await zodfetch(import_zod12.z.object({
|
|
1192
|
+
ok: import_zod12.z.boolean()
|
|
1082
1193
|
}), `${__privateGet(this, _apiUrl)}/api/v1/${client}/schedules/${id}/registrations/${encodeURIComponent(key)}`, {
|
|
1083
1194
|
method: "DELETE",
|
|
1084
1195
|
headers: {
|
|
@@ -1186,11 +1297,12 @@ function createIOWithIntegrations(io, auths, integrations) {
|
|
|
1186
1297
|
return io;
|
|
1187
1298
|
}
|
|
1188
1299
|
const connections = Object.entries(integrations).reduce((acc, [connectionKey, integration]) => {
|
|
1189
|
-
|
|
1190
|
-
const client =
|
|
1300
|
+
let auth = auths?.[connectionKey];
|
|
1301
|
+
const client = integration.client.usesLocalAuth ? integration.client.client : auth ? integration.client.clientFactory?.(auth) : void 0;
|
|
1191
1302
|
if (!client) {
|
|
1192
1303
|
return acc;
|
|
1193
1304
|
}
|
|
1305
|
+
auth = integration.client.usesLocalAuth ? integration.client.auth : auth;
|
|
1194
1306
|
const ioConnection = {
|
|
1195
1307
|
client
|
|
1196
1308
|
};
|
|
@@ -1202,7 +1314,7 @@ function createIOWithIntegrations(io, auths, integrations) {
|
|
|
1202
1314
|
const options = authenticatedTask2.init(params);
|
|
1203
1315
|
options.connectionKey = connectionKey;
|
|
1204
1316
|
return await io.runTask(key, options, async (ioTask) => {
|
|
1205
|
-
return authenticatedTask2.run(params, client, ioTask, io);
|
|
1317
|
+
return authenticatedTask2.run(params, client, ioTask, io, auth);
|
|
1206
1318
|
}, authenticatedTask2.onError);
|
|
1207
1319
|
};
|
|
1208
1320
|
});
|
|
@@ -1225,30 +1337,6 @@ function createIOWithIntegrations(io, auths, integrations) {
|
|
|
1225
1337
|
}
|
|
1226
1338
|
__name(createIOWithIntegrations, "createIOWithIntegrations");
|
|
1227
1339
|
|
|
1228
|
-
// src/retry.ts
|
|
1229
|
-
var DEFAULT_RETRY_OPTIONS = {
|
|
1230
|
-
limit: 5,
|
|
1231
|
-
factor: 1.8,
|
|
1232
|
-
minTimeoutInMs: 1e3,
|
|
1233
|
-
maxTimeoutInMs: 6e4,
|
|
1234
|
-
randomize: true
|
|
1235
|
-
};
|
|
1236
|
-
function calculateRetryAt(retryOptions, attempts) {
|
|
1237
|
-
const options = {
|
|
1238
|
-
...DEFAULT_RETRY_OPTIONS,
|
|
1239
|
-
...retryOptions
|
|
1240
|
-
};
|
|
1241
|
-
const retryCount = attempts + 1;
|
|
1242
|
-
if (retryCount > options.limit) {
|
|
1243
|
-
return;
|
|
1244
|
-
}
|
|
1245
|
-
const random = options.randomize ? Math.random() + 1 : 1;
|
|
1246
|
-
let timeoutInMs = Math.round(random * Math.max(options.minTimeoutInMs, 1) * Math.pow(options.factor, Math.max(attempts - 1, 0)));
|
|
1247
|
-
timeoutInMs = Math.min(timeoutInMs, options.maxTimeoutInMs);
|
|
1248
|
-
return new Date(Date.now() + timeoutInMs);
|
|
1249
|
-
}
|
|
1250
|
-
__name(calculateRetryAt, "calculateRetryAt");
|
|
1251
|
-
|
|
1252
1340
|
// src/io.ts
|
|
1253
1341
|
var _addToCachedTasks, addToCachedTasks_fn;
|
|
1254
1342
|
var IO = class {
|
|
@@ -1259,6 +1347,8 @@ var IO = class {
|
|
|
1259
1347
|
this._triggerClient = options.client;
|
|
1260
1348
|
this._logger = options.logger ?? new Logger("trigger.dev", options.logLevel);
|
|
1261
1349
|
this._cachedTasks = /* @__PURE__ */ new Map();
|
|
1350
|
+
this._jobLogger = options.jobLogger;
|
|
1351
|
+
this._jobLogLevel = options.jobLogLevel;
|
|
1262
1352
|
if (options.cachedTasks) {
|
|
1263
1353
|
options.cachedTasks.forEach((task) => {
|
|
1264
1354
|
this._cachedTasks.set(task.id, task);
|
|
@@ -1269,45 +1359,57 @@ var IO = class {
|
|
|
1269
1359
|
}
|
|
1270
1360
|
get logger() {
|
|
1271
1361
|
return new IOLogger(async (level, message, data) => {
|
|
1362
|
+
let logLevel = "info";
|
|
1272
1363
|
switch (level) {
|
|
1364
|
+
case "LOG": {
|
|
1365
|
+
this._jobLogger?.log(message, data);
|
|
1366
|
+
logLevel = "log";
|
|
1367
|
+
break;
|
|
1368
|
+
}
|
|
1273
1369
|
case "DEBUG": {
|
|
1274
|
-
this.
|
|
1370
|
+
this._jobLogger?.debug(message, data);
|
|
1371
|
+
logLevel = "debug";
|
|
1275
1372
|
break;
|
|
1276
1373
|
}
|
|
1277
1374
|
case "INFO": {
|
|
1278
|
-
this.
|
|
1375
|
+
this._jobLogger?.info(message, data);
|
|
1376
|
+
logLevel = "info";
|
|
1279
1377
|
break;
|
|
1280
1378
|
}
|
|
1281
1379
|
case "WARN": {
|
|
1282
|
-
this.
|
|
1380
|
+
this._jobLogger?.warn(message, data);
|
|
1381
|
+
logLevel = "warn";
|
|
1283
1382
|
break;
|
|
1284
1383
|
}
|
|
1285
1384
|
case "ERROR": {
|
|
1286
|
-
this.
|
|
1385
|
+
this._jobLogger?.error(message, data);
|
|
1386
|
+
logLevel = "error";
|
|
1287
1387
|
break;
|
|
1288
1388
|
}
|
|
1289
1389
|
}
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
style:
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1390
|
+
if (Logger.satisfiesLogLevel(logLevel, this._jobLogLevel)) {
|
|
1391
|
+
await this.runTask([
|
|
1392
|
+
message,
|
|
1393
|
+
level
|
|
1394
|
+
], {
|
|
1395
|
+
name: "log",
|
|
1396
|
+
icon: "log",
|
|
1397
|
+
description: message,
|
|
1398
|
+
params: data,
|
|
1399
|
+
properties: [
|
|
1400
|
+
{
|
|
1401
|
+
label: "Level",
|
|
1402
|
+
text: level
|
|
1403
|
+
}
|
|
1404
|
+
],
|
|
1405
|
+
style: {
|
|
1406
|
+
style: "minimal",
|
|
1407
|
+
variant: level.toLowerCase()
|
|
1408
|
+
},
|
|
1409
|
+
noop: true
|
|
1410
|
+
}, async (task) => {
|
|
1411
|
+
});
|
|
1412
|
+
}
|
|
1311
1413
|
});
|
|
1312
1414
|
}
|
|
1313
1415
|
async wait(key, seconds) {
|
|
@@ -1325,13 +1427,56 @@ var IO = class {
|
|
|
1325
1427
|
}, async (task) => {
|
|
1326
1428
|
});
|
|
1327
1429
|
}
|
|
1430
|
+
async backgroundFetch(key, url, requestInit, retry) {
|
|
1431
|
+
const urlObject = new URL(url);
|
|
1432
|
+
return await this.runTask(key, {
|
|
1433
|
+
name: `fetch ${urlObject.hostname}${urlObject.pathname}`,
|
|
1434
|
+
params: {
|
|
1435
|
+
url,
|
|
1436
|
+
requestInit,
|
|
1437
|
+
retry
|
|
1438
|
+
},
|
|
1439
|
+
operation: "fetch",
|
|
1440
|
+
icon: "background",
|
|
1441
|
+
noop: false,
|
|
1442
|
+
properties: [
|
|
1443
|
+
{
|
|
1444
|
+
label: "url",
|
|
1445
|
+
text: url,
|
|
1446
|
+
url
|
|
1447
|
+
},
|
|
1448
|
+
{
|
|
1449
|
+
label: "method",
|
|
1450
|
+
text: requestInit?.method ?? "GET"
|
|
1451
|
+
},
|
|
1452
|
+
{
|
|
1453
|
+
label: "background",
|
|
1454
|
+
text: "true"
|
|
1455
|
+
}
|
|
1456
|
+
]
|
|
1457
|
+
}, async (task) => {
|
|
1458
|
+
return task.output;
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1328
1461
|
async sendEvent(key, event, options) {
|
|
1329
1462
|
return await this.runTask(key, {
|
|
1330
1463
|
name: "sendEvent",
|
|
1331
1464
|
params: {
|
|
1332
1465
|
event,
|
|
1333
1466
|
options
|
|
1334
|
-
}
|
|
1467
|
+
},
|
|
1468
|
+
properties: [
|
|
1469
|
+
{
|
|
1470
|
+
label: "name",
|
|
1471
|
+
text: event.name
|
|
1472
|
+
},
|
|
1473
|
+
...event?.id ? [
|
|
1474
|
+
{
|
|
1475
|
+
label: "ID",
|
|
1476
|
+
text: event.id
|
|
1477
|
+
}
|
|
1478
|
+
] : []
|
|
1479
|
+
]
|
|
1335
1480
|
}, async (task) => {
|
|
1336
1481
|
return await this._triggerClient.sendEvent(event, options);
|
|
1337
1482
|
});
|
|
@@ -1540,6 +1685,13 @@ var IO = class {
|
|
|
1540
1685
|
});
|
|
1541
1686
|
throw new ResumeWithTaskError(task);
|
|
1542
1687
|
}
|
|
1688
|
+
if (task.status === "RUNNING" && typeof task.operation === "string") {
|
|
1689
|
+
this._logger.debug("Task running operation", {
|
|
1690
|
+
idempotencyKey,
|
|
1691
|
+
task
|
|
1692
|
+
});
|
|
1693
|
+
throw new ResumeWithTaskError(task);
|
|
1694
|
+
}
|
|
1543
1695
|
const executeTask = /* @__PURE__ */ __name(async () => {
|
|
1544
1696
|
try {
|
|
1545
1697
|
const result = await callback(task, this);
|
|
@@ -1552,6 +1704,9 @@ var IO = class {
|
|
|
1552
1704
|
});
|
|
1553
1705
|
return result;
|
|
1554
1706
|
} catch (error) {
|
|
1707
|
+
if (isTriggerError(error)) {
|
|
1708
|
+
throw error;
|
|
1709
|
+
}
|
|
1555
1710
|
if (onError) {
|
|
1556
1711
|
const onErrorResult = onError(error, task, this);
|
|
1557
1712
|
if (onErrorResult) {
|
|
@@ -1563,7 +1718,7 @@ var IO = class {
|
|
|
1563
1718
|
}
|
|
1564
1719
|
const parsedError = ErrorWithStackSchema.safeParse(error);
|
|
1565
1720
|
if (options.retry) {
|
|
1566
|
-
const retryAt = calculateRetryAt(options.retry, task.attempts);
|
|
1721
|
+
const retryAt = calculateRetryAt(options.retry, task.attempts - 1);
|
|
1567
1722
|
if (retryAt) {
|
|
1568
1723
|
throw new RetryWithTaskError(parsedError.success ? parsedError.data : {
|
|
1569
1724
|
message: "Unknown error"
|
|
@@ -1641,6 +1796,9 @@ var IOLogger = class {
|
|
|
1641
1796
|
constructor(callback) {
|
|
1642
1797
|
this.callback = callback;
|
|
1643
1798
|
}
|
|
1799
|
+
log(message, properties) {
|
|
1800
|
+
return this.callback("LOG", message, properties);
|
|
1801
|
+
}
|
|
1644
1802
|
debug(message, properties) {
|
|
1645
1803
|
return this.callback("DEBUG", message, properties);
|
|
1646
1804
|
}
|
|
@@ -1713,7 +1871,7 @@ var registerSourceEvent = {
|
|
|
1713
1871
|
icon: "register-source",
|
|
1714
1872
|
parsePayload: RegisterSourceEventSchema.parse
|
|
1715
1873
|
};
|
|
1716
|
-
var _options3, _registeredJobs, _registeredSources, _registeredHttpSourceHandlers, _registeredDynamicTriggers, _jobMetadataByDynamicTriggers, _registeredSchedules, _client,
|
|
1874
|
+
var _options3, _registeredJobs, _registeredSources, _registeredHttpSourceHandlers, _registeredDynamicTriggers, _jobMetadataByDynamicTriggers, _registeredSchedules, _client, _internalLogger, _preprocessRun, preprocessRun_fn, _executeJob, executeJob_fn, _createRunContext, createRunContext_fn, _createPreprocessRunContext, createPreprocessRunContext_fn, _handleHttpSourceRequest, handleHttpSourceRequest_fn;
|
|
1717
1875
|
var TriggerClient = class {
|
|
1718
1876
|
constructor(options) {
|
|
1719
1877
|
__privateAdd(this, _preprocessRun);
|
|
@@ -1729,36 +1887,54 @@ var TriggerClient = class {
|
|
|
1729
1887
|
__privateAdd(this, _jobMetadataByDynamicTriggers, {});
|
|
1730
1888
|
__privateAdd(this, _registeredSchedules, {});
|
|
1731
1889
|
__privateAdd(this, _client, void 0);
|
|
1732
|
-
__privateAdd(this,
|
|
1890
|
+
__privateAdd(this, _internalLogger, void 0);
|
|
1733
1891
|
this.id = options.id;
|
|
1734
|
-
this._url = buildClientUrl(options.url);
|
|
1735
1892
|
__privateSet(this, _options3, options);
|
|
1736
1893
|
__privateSet(this, _client, new ApiClient(__privateGet(this, _options3)));
|
|
1737
|
-
__privateSet(this,
|
|
1738
|
-
}
|
|
1739
|
-
get url() {
|
|
1740
|
-
return `${this._url}${this.path ? `${this.path.startsWith("/") ? "" : "/"}${this.path}` : ""}`;
|
|
1894
|
+
__privateSet(this, _internalLogger, new Logger("trigger.dev", __privateGet(this, _options3).verbose ? "debug" : "log"));
|
|
1741
1895
|
}
|
|
1742
1896
|
async handleRequest(request) {
|
|
1743
|
-
__privateGet(this,
|
|
1897
|
+
__privateGet(this, _internalLogger).debug("handling request", {
|
|
1744
1898
|
url: request.url,
|
|
1745
1899
|
headers: Object.fromEntries(request.headers.entries()),
|
|
1746
1900
|
method: request.method
|
|
1747
1901
|
});
|
|
1748
1902
|
const apiKey = request.headers.get("x-trigger-api-key");
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1903
|
+
const authorization = this.authorized(apiKey);
|
|
1904
|
+
switch (authorization) {
|
|
1905
|
+
case "authorized": {
|
|
1906
|
+
break;
|
|
1907
|
+
}
|
|
1908
|
+
case "missing-client": {
|
|
1909
|
+
return {
|
|
1910
|
+
status: 401,
|
|
1911
|
+
body: {
|
|
1912
|
+
message: "Unauthorized: client missing apiKey"
|
|
1913
|
+
}
|
|
1914
|
+
};
|
|
1915
|
+
}
|
|
1916
|
+
case "missing-header": {
|
|
1917
|
+
return {
|
|
1918
|
+
status: 401,
|
|
1919
|
+
body: {
|
|
1920
|
+
message: "Unauthorized: missing x-trigger-api-key header"
|
|
1921
|
+
}
|
|
1922
|
+
};
|
|
1923
|
+
}
|
|
1924
|
+
case "unauthorized": {
|
|
1925
|
+
return {
|
|
1926
|
+
status: 401,
|
|
1927
|
+
body: {
|
|
1928
|
+
message: `Forbidden: client apiKey mismatch: Expected ${__privateGet(this, _options3).apiKey}, got ${apiKey}`
|
|
1929
|
+
}
|
|
1930
|
+
};
|
|
1931
|
+
}
|
|
1756
1932
|
}
|
|
1757
1933
|
if (request.method !== "POST") {
|
|
1758
1934
|
return {
|
|
1759
1935
|
status: 405,
|
|
1760
1936
|
body: {
|
|
1761
|
-
message: "Method not allowed"
|
|
1937
|
+
message: "Method not allowed (only POST is allowed)"
|
|
1762
1938
|
}
|
|
1763
1939
|
};
|
|
1764
1940
|
}
|
|
@@ -1773,14 +1949,33 @@ var TriggerClient = class {
|
|
|
1773
1949
|
}
|
|
1774
1950
|
switch (action) {
|
|
1775
1951
|
case "PING": {
|
|
1952
|
+
const endpointId = request.headers.get("x-trigger-endpoint-id");
|
|
1953
|
+
if (!endpointId) {
|
|
1954
|
+
return {
|
|
1955
|
+
status: 200,
|
|
1956
|
+
body: {
|
|
1957
|
+
ok: false,
|
|
1958
|
+
error: "Missing endpoint ID"
|
|
1959
|
+
}
|
|
1960
|
+
};
|
|
1961
|
+
}
|
|
1962
|
+
if (this.id !== endpointId) {
|
|
1963
|
+
return {
|
|
1964
|
+
status: 200,
|
|
1965
|
+
body: {
|
|
1966
|
+
ok: false,
|
|
1967
|
+
error: `Endpoint ID mismatch error. Expected ${this.id}, got ${endpointId}`
|
|
1968
|
+
}
|
|
1969
|
+
};
|
|
1970
|
+
}
|
|
1776
1971
|
return {
|
|
1777
1972
|
status: 200,
|
|
1778
1973
|
body: {
|
|
1779
|
-
|
|
1974
|
+
ok: true
|
|
1780
1975
|
}
|
|
1781
1976
|
};
|
|
1782
1977
|
}
|
|
1783
|
-
case "
|
|
1978
|
+
case "INDEX_ENDPOINT": {
|
|
1784
1979
|
const jobId = request.headers.get("x-trigger-job-id");
|
|
1785
1980
|
if (jobId) {
|
|
1786
1981
|
const job = __privateGet(this, _registeredJobs)[jobId];
|
|
@@ -1814,15 +2009,6 @@ var TriggerClient = class {
|
|
|
1814
2009
|
body
|
|
1815
2010
|
};
|
|
1816
2011
|
}
|
|
1817
|
-
case "INITIALIZE": {
|
|
1818
|
-
await this.listen();
|
|
1819
|
-
return {
|
|
1820
|
-
status: 200,
|
|
1821
|
-
body: {
|
|
1822
|
-
message: "Initialized"
|
|
1823
|
-
}
|
|
1824
|
-
};
|
|
1825
|
-
}
|
|
1826
2012
|
case "INITIALIZE_TRIGGER": {
|
|
1827
2013
|
const json = await request.json();
|
|
1828
2014
|
const body = InitializeTriggerBodySchema.safeParse(json);
|
|
@@ -1994,7 +2180,7 @@ var TriggerClient = class {
|
|
|
1994
2180
|
}
|
|
1995
2181
|
attachSource(options) {
|
|
1996
2182
|
__privateGet(this, _registeredHttpSourceHandlers)[options.key] = async (s, r) => {
|
|
1997
|
-
return await options.source.handle(s, r, __privateGet(this,
|
|
2183
|
+
return await options.source.handle(s, r, __privateGet(this, _internalLogger));
|
|
1998
2184
|
};
|
|
1999
2185
|
let registeredSource = __privateGet(this, _registeredSources)[options.key];
|
|
2000
2186
|
if (!registeredSource) {
|
|
@@ -2003,7 +2189,11 @@ var TriggerClient = class {
|
|
|
2003
2189
|
key: options.key,
|
|
2004
2190
|
params: options.params,
|
|
2005
2191
|
events: [],
|
|
2006
|
-
|
|
2192
|
+
integration: {
|
|
2193
|
+
id: options.source.integration.id,
|
|
2194
|
+
metadata: options.source.integration.metadata,
|
|
2195
|
+
authSource: options.source.integration.client.usesLocalAuth ? "LOCAL" : "HOSTED"
|
|
2196
|
+
}
|
|
2007
2197
|
};
|
|
2008
2198
|
}
|
|
2009
2199
|
registeredSource.events = Array.from(/* @__PURE__ */ new Set([
|
|
@@ -2070,21 +2260,18 @@ var TriggerClient = class {
|
|
|
2070
2260
|
return __privateGet(this, _client).unregisterSchedule(this.id, id, key);
|
|
2071
2261
|
}
|
|
2072
2262
|
authorized(apiKey) {
|
|
2263
|
+
if (typeof apiKey !== "string") {
|
|
2264
|
+
return "missing-header";
|
|
2265
|
+
}
|
|
2073
2266
|
const localApiKey = __privateGet(this, _options3).apiKey ?? process.env.TRIGGER_API_KEY;
|
|
2074
2267
|
if (!localApiKey) {
|
|
2075
|
-
return
|
|
2268
|
+
return "missing-client";
|
|
2076
2269
|
}
|
|
2077
|
-
return apiKey === localApiKey;
|
|
2270
|
+
return apiKey === localApiKey ? "authorized" : "unauthorized";
|
|
2078
2271
|
}
|
|
2079
2272
|
apiKey() {
|
|
2080
2273
|
return __privateGet(this, _options3).apiKey ?? process.env.TRIGGER_API_KEY;
|
|
2081
2274
|
}
|
|
2082
|
-
async listen() {
|
|
2083
|
-
await __privateGet(this, _client).registerEndpoint({
|
|
2084
|
-
url: this.url,
|
|
2085
|
-
name: this.id
|
|
2086
|
-
});
|
|
2087
|
-
}
|
|
2088
2275
|
};
|
|
2089
2276
|
__name(TriggerClient, "TriggerClient");
|
|
2090
2277
|
_options3 = new WeakMap();
|
|
@@ -2095,7 +2282,7 @@ _registeredDynamicTriggers = new WeakMap();
|
|
|
2095
2282
|
_jobMetadataByDynamicTriggers = new WeakMap();
|
|
2096
2283
|
_registeredSchedules = new WeakMap();
|
|
2097
2284
|
_client = new WeakMap();
|
|
2098
|
-
|
|
2285
|
+
_internalLogger = new WeakMap();
|
|
2099
2286
|
_preprocessRun = new WeakSet();
|
|
2100
2287
|
preprocessRun_fn = /* @__PURE__ */ __name(async function(body, job) {
|
|
2101
2288
|
const context = __privateMethod(this, _createPreprocessRunContext, createPreprocessRunContext_fn).call(this, body);
|
|
@@ -2108,7 +2295,7 @@ preprocessRun_fn = /* @__PURE__ */ __name(async function(body, job) {
|
|
|
2108
2295
|
}, "#preprocessRun");
|
|
2109
2296
|
_executeJob = new WeakSet();
|
|
2110
2297
|
executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
|
|
2111
|
-
__privateGet(this,
|
|
2298
|
+
__privateGet(this, _internalLogger).debug("executing job", {
|
|
2112
2299
|
execution: body1,
|
|
2113
2300
|
job: job1.toJSON()
|
|
2114
2301
|
});
|
|
@@ -2117,9 +2304,11 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
|
|
|
2117
2304
|
id: body1.run.id,
|
|
2118
2305
|
cachedTasks: body1.tasks,
|
|
2119
2306
|
apiClient: __privateGet(this, _client),
|
|
2120
|
-
logger: __privateGet(this,
|
|
2307
|
+
logger: __privateGet(this, _internalLogger),
|
|
2121
2308
|
client: this,
|
|
2122
|
-
context
|
|
2309
|
+
context,
|
|
2310
|
+
jobLogLevel: job1.logLevel ?? __privateGet(this, _options3).logLevel ?? "info",
|
|
2311
|
+
jobLogger: __privateGet(this, _options3).ioLogLocalEnabled ? new Logger(job1.id, job1.logLevel ?? __privateGet(this, _options3).logLevel ?? "info") : void 0
|
|
2123
2312
|
});
|
|
2124
2313
|
const ioWithConnections = createIOWithIntegrations(io, body1.connections, job1.options.integrations);
|
|
2125
2314
|
try {
|
|
@@ -2177,7 +2366,7 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
|
|
|
2177
2366
|
}, "#executeJob");
|
|
2178
2367
|
_createRunContext = new WeakSet();
|
|
2179
2368
|
createRunContext_fn = /* @__PURE__ */ __name(function(execution) {
|
|
2180
|
-
const { event, organization, environment, job, run } = execution;
|
|
2369
|
+
const { event, organization, environment, job, run, source } = execution;
|
|
2181
2370
|
return {
|
|
2182
2371
|
event: {
|
|
2183
2372
|
id: event.id,
|
|
@@ -2189,7 +2378,8 @@ createRunContext_fn = /* @__PURE__ */ __name(function(execution) {
|
|
|
2189
2378
|
environment,
|
|
2190
2379
|
job,
|
|
2191
2380
|
run,
|
|
2192
|
-
account: execution.account
|
|
2381
|
+
account: execution.account,
|
|
2382
|
+
source
|
|
2193
2383
|
};
|
|
2194
2384
|
}, "#createRunContext");
|
|
2195
2385
|
_createPreprocessRunContext = new WeakSet();
|
|
@@ -2211,13 +2401,13 @@ createPreprocessRunContext_fn = /* @__PURE__ */ __name(function(body2) {
|
|
|
2211
2401
|
}, "#createPreprocessRunContext");
|
|
2212
2402
|
_handleHttpSourceRequest = new WeakSet();
|
|
2213
2403
|
handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourceRequest) {
|
|
2214
|
-
__privateGet(this,
|
|
2404
|
+
__privateGet(this, _internalLogger).debug("Handling HTTP source request", {
|
|
2215
2405
|
source
|
|
2216
2406
|
});
|
|
2217
2407
|
if (source.dynamicId) {
|
|
2218
2408
|
const dynamicTrigger = __privateGet(this, _registeredDynamicTriggers)[source.dynamicId];
|
|
2219
2409
|
if (!dynamicTrigger) {
|
|
2220
|
-
__privateGet(this,
|
|
2410
|
+
__privateGet(this, _internalLogger).debug("No dynamic trigger registered for HTTP source", {
|
|
2221
2411
|
source
|
|
2222
2412
|
});
|
|
2223
2413
|
return {
|
|
@@ -2230,7 +2420,7 @@ handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourc
|
|
|
2230
2420
|
events: []
|
|
2231
2421
|
};
|
|
2232
2422
|
}
|
|
2233
|
-
const results2 = await dynamicTrigger.source.handle(source, sourceRequest, __privateGet(this,
|
|
2423
|
+
const results2 = await dynamicTrigger.source.handle(source, sourceRequest, __privateGet(this, _internalLogger));
|
|
2234
2424
|
if (!results2) {
|
|
2235
2425
|
return {
|
|
2236
2426
|
events: [],
|
|
@@ -2254,7 +2444,7 @@ handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourc
|
|
|
2254
2444
|
}
|
|
2255
2445
|
const handler = __privateGet(this, _registeredHttpSourceHandlers)[source.key];
|
|
2256
2446
|
if (!handler) {
|
|
2257
|
-
__privateGet(this,
|
|
2447
|
+
__privateGet(this, _internalLogger).debug("No handler registered for HTTP source", {
|
|
2258
2448
|
source
|
|
2259
2449
|
});
|
|
2260
2450
|
return {
|
|
@@ -2289,20 +2479,6 @@ handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourc
|
|
|
2289
2479
|
}
|
|
2290
2480
|
};
|
|
2291
2481
|
}, "#handleHttpSourceRequest");
|
|
2292
|
-
function buildClientUrl(url) {
|
|
2293
|
-
if (!url) {
|
|
2294
|
-
const host = process.env.TRIGGER_CLIENT_HOST ?? process.env.HOST ?? process.env.HOSTNAME ?? process.env.NOW_URL ?? process.env.VERCEL_URL;
|
|
2295
|
-
if (host) {
|
|
2296
|
-
return "https://" + host;
|
|
2297
|
-
}
|
|
2298
|
-
throw new Error("Could not determine the url for this TriggerClient. Please set the TRIGGER_CLIENT_HOST environment variable or pass in the `url` option to the TriggerClient constructor.");
|
|
2299
|
-
}
|
|
2300
|
-
if (!url.startsWith("http")) {
|
|
2301
|
-
return "https://" + url;
|
|
2302
|
-
}
|
|
2303
|
-
return url;
|
|
2304
|
-
}
|
|
2305
|
-
__name(buildClientUrl, "buildClientUrl");
|
|
2306
2482
|
|
|
2307
2483
|
// src/integrations.ts
|
|
2308
2484
|
function authenticatedTask(options) {
|
|
@@ -2454,7 +2630,11 @@ var DynamicTrigger = class {
|
|
|
2454
2630
|
events: [
|
|
2455
2631
|
this.event.name
|
|
2456
2632
|
],
|
|
2457
|
-
|
|
2633
|
+
integration: {
|
|
2634
|
+
id: this.source.integration.id,
|
|
2635
|
+
metadata: this.source.integration.metadata,
|
|
2636
|
+
authSource: this.source.integration.client.usesLocalAuth ? "LOCAL" : "HOSTED"
|
|
2637
|
+
}
|
|
2458
2638
|
}
|
|
2459
2639
|
};
|
|
2460
2640
|
}
|
|
@@ -2465,7 +2645,7 @@ var DynamicTrigger = class {
|
|
|
2465
2645
|
triggerClient.attachJobToDynamicTrigger(job, this);
|
|
2466
2646
|
}
|
|
2467
2647
|
get preprocessRuns() {
|
|
2468
|
-
return
|
|
2648
|
+
return true;
|
|
2469
2649
|
}
|
|
2470
2650
|
};
|
|
2471
2651
|
__name(DynamicTrigger, "DynamicTrigger");
|
|
@@ -2473,6 +2653,18 @@ _client2 = new WeakMap();
|
|
|
2473
2653
|
_options4 = new WeakMap();
|
|
2474
2654
|
|
|
2475
2655
|
// src/triggers/scheduled.ts
|
|
2656
|
+
var import_cronstrue = __toESM(require("cronstrue"));
|
|
2657
|
+
var examples = [
|
|
2658
|
+
{
|
|
2659
|
+
id: "now",
|
|
2660
|
+
name: "Now",
|
|
2661
|
+
icon: "clock",
|
|
2662
|
+
payload: {
|
|
2663
|
+
ts: currentDate.marker,
|
|
2664
|
+
lastTimestamp: currentDate.marker
|
|
2665
|
+
}
|
|
2666
|
+
}
|
|
2667
|
+
];
|
|
2476
2668
|
var IntervalTrigger = class {
|
|
2477
2669
|
constructor(options) {
|
|
2478
2670
|
this.options = options;
|
|
@@ -2483,6 +2675,7 @@ var IntervalTrigger = class {
|
|
|
2483
2675
|
title: "Schedule",
|
|
2484
2676
|
source: "trigger.dev",
|
|
2485
2677
|
icon: "schedule-interval",
|
|
2678
|
+
examples,
|
|
2486
2679
|
parsePayload: ScheduledPayloadSchema.parse,
|
|
2487
2680
|
properties: [
|
|
2488
2681
|
{
|
|
@@ -2519,16 +2712,24 @@ var CronTrigger = class {
|
|
|
2519
2712
|
this.options = options;
|
|
2520
2713
|
}
|
|
2521
2714
|
get event() {
|
|
2715
|
+
const humanReadable = import_cronstrue.default.toString(this.options.cron, {
|
|
2716
|
+
throwExceptionOnParseError: false
|
|
2717
|
+
});
|
|
2522
2718
|
return {
|
|
2523
2719
|
name: "trigger.scheduled",
|
|
2524
2720
|
title: "Cron Schedule",
|
|
2525
2721
|
source: "trigger.dev",
|
|
2526
2722
|
icon: "schedule-cron",
|
|
2723
|
+
examples,
|
|
2527
2724
|
parsePayload: ScheduledPayloadSchema.parse,
|
|
2528
2725
|
properties: [
|
|
2529
2726
|
{
|
|
2530
|
-
label: "
|
|
2727
|
+
label: "cron",
|
|
2531
2728
|
text: this.options.cron
|
|
2729
|
+
},
|
|
2730
|
+
{
|
|
2731
|
+
label: "Schedule",
|
|
2732
|
+
text: humanReadable
|
|
2532
2733
|
}
|
|
2533
2734
|
]
|
|
2534
2735
|
};
|
|
@@ -2569,6 +2770,7 @@ var DynamicSchedule = class {
|
|
|
2569
2770
|
title: "Dynamic Schedule",
|
|
2570
2771
|
source: "trigger.dev",
|
|
2571
2772
|
icon: "schedule-dynamic",
|
|
2773
|
+
examples,
|
|
2572
2774
|
parsePayload: ScheduledPayloadSchema.parse
|
|
2573
2775
|
};
|
|
2574
2776
|
}
|
|
@@ -2690,14 +2892,14 @@ var MissingConnectionResolvedNotification = class {
|
|
|
2690
2892
|
__name(MissingConnectionResolvedNotification, "MissingConnectionResolvedNotification");
|
|
2691
2893
|
|
|
2692
2894
|
// src/index.ts
|
|
2693
|
-
function
|
|
2895
|
+
function redactString(strings, ...interpolations) {
|
|
2694
2896
|
return {
|
|
2695
|
-
|
|
2897
|
+
__redactedString: true,
|
|
2696
2898
|
strings: strings.raw,
|
|
2697
2899
|
interpolations
|
|
2698
2900
|
};
|
|
2699
2901
|
}
|
|
2700
|
-
__name(
|
|
2902
|
+
__name(redactString, "redactString");
|
|
2701
2903
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2702
2904
|
0 && (module.exports = {
|
|
2703
2905
|
CronTrigger,
|
|
@@ -2721,6 +2923,6 @@ __name(secureString, "secureString");
|
|
|
2721
2923
|
missingConnectionNotification,
|
|
2722
2924
|
missingConnectionResolvedNotification,
|
|
2723
2925
|
omit,
|
|
2724
|
-
|
|
2926
|
+
redactString
|
|
2725
2927
|
});
|
|
2726
2928
|
//# sourceMappingURL=index.js.map
|