@trigger.dev/sdk 2.0.0-next.1 → 2.0.0-next.3
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 +309 -133
- package/dist/index.js +229 -85
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -64,7 +64,7 @@ __export(src_exports, {
|
|
|
64
64
|
missingConnectionNotification: () => missingConnectionNotification,
|
|
65
65
|
missingConnectionResolvedNotification: () => missingConnectionResolvedNotification,
|
|
66
66
|
omit: () => omit,
|
|
67
|
-
|
|
67
|
+
redactString: () => redactString
|
|
68
68
|
});
|
|
69
69
|
module.exports = __toCommonJS(src_exports);
|
|
70
70
|
|
|
@@ -104,12 +104,11 @@ var Job = class {
|
|
|
104
104
|
get integrations() {
|
|
105
105
|
return Object.keys(this.options.integrations ?? {}).reduce((acc, key) => {
|
|
106
106
|
const integration = this.options.integrations[key];
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
107
|
+
acc[key] = {
|
|
108
|
+
id: integration.id,
|
|
109
|
+
metadata: integration.metadata,
|
|
110
|
+
authSource: integration.client.usesLocalAuth ? "LOCAL" : "HOSTED"
|
|
111
|
+
};
|
|
113
112
|
return acc;
|
|
114
113
|
}, {});
|
|
115
114
|
}
|
|
@@ -146,18 +145,20 @@ var logLevels = [
|
|
|
146
145
|
"info",
|
|
147
146
|
"debug"
|
|
148
147
|
];
|
|
149
|
-
var _name, _level, _filteredKeys;
|
|
148
|
+
var _name, _level, _filteredKeys, _jsonReplacer;
|
|
150
149
|
var _Logger = class {
|
|
151
|
-
constructor(name, level = "info", filteredKeys = []) {
|
|
150
|
+
constructor(name, level = "info", filteredKeys = [], jsonReplacer) {
|
|
152
151
|
__privateAdd(this, _name, void 0);
|
|
153
152
|
__privateAdd(this, _level, void 0);
|
|
154
153
|
__privateAdd(this, _filteredKeys, []);
|
|
154
|
+
__privateAdd(this, _jsonReplacer, void 0);
|
|
155
155
|
__privateSet(this, _name, name);
|
|
156
156
|
__privateSet(this, _level, logLevels.indexOf(process.env.TRIGGER_LOG_LEVEL ?? level));
|
|
157
157
|
__privateSet(this, _filteredKeys, filteredKeys);
|
|
158
|
+
__privateSet(this, _jsonReplacer, jsonReplacer);
|
|
158
159
|
}
|
|
159
160
|
filter(...keys) {
|
|
160
|
-
return new _Logger(__privateGet(this, _name), logLevels[__privateGet(this, _level)], keys);
|
|
161
|
+
return new _Logger(__privateGet(this, _name), logLevels[__privateGet(this, _level)], keys, __privateGet(this, _jsonReplacer));
|
|
161
162
|
}
|
|
162
163
|
log(...args) {
|
|
163
164
|
if (__privateGet(this, _level) < 0)
|
|
@@ -188,7 +189,7 @@ var _Logger = class {
|
|
|
188
189
|
message,
|
|
189
190
|
args: structureArgs(safeJsonClone(args), __privateGet(this, _filteredKeys))
|
|
190
191
|
};
|
|
191
|
-
console.debug(JSON.stringify(structuredLog,
|
|
192
|
+
console.debug(JSON.stringify(structuredLog, createReplacer(__privateGet(this, _jsonReplacer))));
|
|
192
193
|
}
|
|
193
194
|
};
|
|
194
195
|
var Logger = _Logger;
|
|
@@ -196,6 +197,19 @@ __name(Logger, "Logger");
|
|
|
196
197
|
_name = new WeakMap();
|
|
197
198
|
_level = new WeakMap();
|
|
198
199
|
_filteredKeys = new WeakMap();
|
|
200
|
+
_jsonReplacer = new WeakMap();
|
|
201
|
+
function createReplacer(replacer) {
|
|
202
|
+
return (key, value) => {
|
|
203
|
+
if (typeof value === "bigint") {
|
|
204
|
+
return value.toString();
|
|
205
|
+
}
|
|
206
|
+
if (replacer) {
|
|
207
|
+
return replacer(key, value);
|
|
208
|
+
}
|
|
209
|
+
return value;
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
__name(createReplacer, "createReplacer");
|
|
199
213
|
function bigIntReplacer(_key, value) {
|
|
200
214
|
if (typeof value === "bigint") {
|
|
201
215
|
return value.toString();
|
|
@@ -293,13 +307,17 @@ var ConnectionAuthSchema = import_zod3.z.object({
|
|
|
293
307
|
additionalFields: import_zod3.z.record(import_zod3.z.string()).optional()
|
|
294
308
|
});
|
|
295
309
|
var IntegrationMetadataSchema = import_zod3.z.object({
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
310
|
+
id: import_zod3.z.string(),
|
|
311
|
+
name: import_zod3.z.string(),
|
|
312
|
+
instructions: import_zod3.z.string().optional()
|
|
299
313
|
});
|
|
300
314
|
var IntegrationConfigSchema = import_zod3.z.object({
|
|
301
315
|
id: import_zod3.z.string(),
|
|
302
|
-
metadata: IntegrationMetadataSchema
|
|
316
|
+
metadata: IntegrationMetadataSchema,
|
|
317
|
+
authSource: import_zod3.z.enum([
|
|
318
|
+
"HOSTED",
|
|
319
|
+
"LOCAL"
|
|
320
|
+
])
|
|
303
321
|
});
|
|
304
322
|
|
|
305
323
|
// ../internal/src/schemas/json.ts
|
|
@@ -404,7 +422,8 @@ var TaskSchema = import_zod7.z.object({
|
|
|
404
422
|
output: DeserializedJsonSchema.optional().nullable(),
|
|
405
423
|
error: import_zod7.z.string().optional().nullable(),
|
|
406
424
|
parentId: import_zod7.z.string().optional().nullable(),
|
|
407
|
-
style: StyleSchema.optional().nullable()
|
|
425
|
+
style: StyleSchema.optional().nullable(),
|
|
426
|
+
operation: import_zod7.z.string().optional().nullable()
|
|
408
427
|
});
|
|
409
428
|
var ServerTaskSchema = TaskSchema.extend({
|
|
410
429
|
idempotencyKey: import_zod7.z.string(),
|
|
@@ -527,9 +546,17 @@ var HttpSourceRequestHeadersSchema = import_zod9.z.object({
|
|
|
527
546
|
"x-ts-http-method": import_zod9.z.string(),
|
|
528
547
|
"x-ts-http-headers": import_zod9.z.string().transform((s) => import_zod9.z.record(import_zod9.z.string()).parse(JSON.parse(s)))
|
|
529
548
|
});
|
|
530
|
-
var
|
|
531
|
-
|
|
549
|
+
var PongSuccessResponseSchema = import_zod9.z.object({
|
|
550
|
+
ok: import_zod9.z.literal(true)
|
|
532
551
|
});
|
|
552
|
+
var PongErrorResponseSchema = import_zod9.z.object({
|
|
553
|
+
ok: import_zod9.z.literal(false),
|
|
554
|
+
error: import_zod9.z.string()
|
|
555
|
+
});
|
|
556
|
+
var PongResponseSchema = import_zod9.z.discriminatedUnion("ok", [
|
|
557
|
+
PongSuccessResponseSchema,
|
|
558
|
+
PongErrorResponseSchema
|
|
559
|
+
]);
|
|
533
560
|
var QueueOptionsSchema = import_zod9.z.object({
|
|
534
561
|
name: import_zod9.z.string(),
|
|
535
562
|
maxConcurrent: import_zod9.z.number().optional()
|
|
@@ -559,10 +586,10 @@ var SourceMetadataSchema = import_zod9.z.object({
|
|
|
559
586
|
"SQS",
|
|
560
587
|
"SMTP"
|
|
561
588
|
]),
|
|
589
|
+
integration: IntegrationConfigSchema,
|
|
562
590
|
key: import_zod9.z.string(),
|
|
563
591
|
params: import_zod9.z.any(),
|
|
564
|
-
events: import_zod9.z.array(import_zod9.z.string())
|
|
565
|
-
clientId: import_zod9.z.string().optional()
|
|
592
|
+
events: import_zod9.z.array(import_zod9.z.string())
|
|
566
593
|
});
|
|
567
594
|
var DynamicTriggerEndpointMetadataSchema = import_zod9.z.object({
|
|
568
595
|
id: import_zod9.z.string(),
|
|
@@ -571,7 +598,7 @@ var DynamicTriggerEndpointMetadataSchema = import_zod9.z.object({
|
|
|
571
598
|
version: true
|
|
572
599
|
}))
|
|
573
600
|
});
|
|
574
|
-
var
|
|
601
|
+
var IndexEndpointResponseSchema = import_zod9.z.object({
|
|
575
602
|
jobs: import_zod9.z.array(JobMetadataSchema),
|
|
576
603
|
sources: import_zod9.z.array(SourceMetadataSchema),
|
|
577
604
|
dynamicTriggers: import_zod9.z.array(DynamicTriggerEndpointMetadataSchema),
|
|
@@ -612,6 +639,10 @@ var RuntimeEnvironmentTypeSchema = import_zod9.z.enum([
|
|
|
612
639
|
"DEVELOPMENT",
|
|
613
640
|
"PREVIEW"
|
|
614
641
|
]);
|
|
642
|
+
var RunSourceContextSchema = import_zod9.z.object({
|
|
643
|
+
id: import_zod9.z.string(),
|
|
644
|
+
metadata: import_zod9.z.any()
|
|
645
|
+
});
|
|
615
646
|
var RunJobBodySchema = import_zod9.z.object({
|
|
616
647
|
event: ApiEventLogSchema,
|
|
617
648
|
job: import_zod9.z.object({
|
|
@@ -637,6 +668,7 @@ var RunJobBodySchema = import_zod9.z.object({
|
|
|
637
668
|
id: import_zod9.z.string(),
|
|
638
669
|
metadata: import_zod9.z.any()
|
|
639
670
|
}).optional(),
|
|
671
|
+
source: RunSourceContextSchema.optional(),
|
|
640
672
|
tasks: import_zod9.z.array(CachedTaskSchema).optional(),
|
|
641
673
|
connections: import_zod9.z.record(ConnectionAuthSchema).optional()
|
|
642
674
|
});
|
|
@@ -714,8 +746,8 @@ var CreateRunResponseBodySchema = import_zod9.z.discriminatedUnion("ok", [
|
|
|
714
746
|
CreateRunResponseOkSchema,
|
|
715
747
|
CreateRunResponseErrorSchema
|
|
716
748
|
]);
|
|
717
|
-
var
|
|
718
|
-
|
|
749
|
+
var RedactStringSchema = import_zod9.z.object({
|
|
750
|
+
__redactedString: import_zod9.z.literal(true),
|
|
719
751
|
strings: import_zod9.z.array(import_zod9.z.string()),
|
|
720
752
|
interpolations: import_zod9.z.array(import_zod9.z.string())
|
|
721
753
|
});
|
|
@@ -744,10 +776,13 @@ var RunTaskOptionsSchema = import_zod9.z.object({
|
|
|
744
776
|
icon: import_zod9.z.string().optional(),
|
|
745
777
|
displayKey: import_zod9.z.string().optional(),
|
|
746
778
|
noop: import_zod9.z.boolean().default(false),
|
|
779
|
+
operation: import_zod9.z.enum([
|
|
780
|
+
"fetch"
|
|
781
|
+
]).optional(),
|
|
747
782
|
delayUntil: import_zod9.z.coerce.date().optional(),
|
|
748
783
|
description: import_zod9.z.string().optional(),
|
|
749
784
|
properties: import_zod9.z.array(DisplayPropertySchema).optional(),
|
|
750
|
-
params:
|
|
785
|
+
params: import_zod9.z.any(),
|
|
751
786
|
trigger: TriggerMetadataSchema.optional(),
|
|
752
787
|
redact: RedactSchema.optional(),
|
|
753
788
|
connectionKey: import_zod9.z.string().optional(),
|
|
@@ -794,7 +829,8 @@ var RegisterTriggerBodySchema = import_zod9.z.object({
|
|
|
794
829
|
var InitializeTriggerBodySchema = import_zod9.z.object({
|
|
795
830
|
id: import_zod9.z.string(),
|
|
796
831
|
params: import_zod9.z.any(),
|
|
797
|
-
accountId: import_zod9.z.string().optional()
|
|
832
|
+
accountId: import_zod9.z.string().optional(),
|
|
833
|
+
metadata: import_zod9.z.any().optional()
|
|
798
834
|
});
|
|
799
835
|
var RegisterCommonScheduleBodySchema = import_zod9.z.object({
|
|
800
836
|
id: import_zod9.z.string(),
|
|
@@ -833,9 +869,7 @@ var CommonMissingConnectionNotificationPayloadSchema = import_zod10.z.object({
|
|
|
833
869
|
title: import_zod10.z.string(),
|
|
834
870
|
scopes: import_zod10.z.array(import_zod10.z.string()),
|
|
835
871
|
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()
|
|
872
|
+
updatedAt: import_zod10.z.coerce.date()
|
|
839
873
|
}),
|
|
840
874
|
authorizationUrl: import_zod10.z.string()
|
|
841
875
|
});
|
|
@@ -881,6 +915,39 @@ var MissingConnectionResolvedNotificationPayloadSchema = import_zod10.z.discrimi
|
|
|
881
915
|
MissingExternalConnectionResolvedNotificationPayloadSchema
|
|
882
916
|
]);
|
|
883
917
|
|
|
918
|
+
// ../internal/src/schemas/fetch.ts
|
|
919
|
+
var import_zod11 = require("zod");
|
|
920
|
+
var FetchRetryHeadersStrategySchema = import_zod11.z.object({
|
|
921
|
+
strategy: import_zod11.z.literal("headers"),
|
|
922
|
+
limitHeader: import_zod11.z.string(),
|
|
923
|
+
remainingHeader: import_zod11.z.string(),
|
|
924
|
+
resetHeader: import_zod11.z.string()
|
|
925
|
+
});
|
|
926
|
+
var FetchRetryBackoffStrategySchema = RetryOptionsSchema.extend({
|
|
927
|
+
strategy: import_zod11.z.literal("backoff")
|
|
928
|
+
});
|
|
929
|
+
var FetchRetryStrategySchema = import_zod11.z.discriminatedUnion("strategy", [
|
|
930
|
+
FetchRetryHeadersStrategySchema,
|
|
931
|
+
FetchRetryBackoffStrategySchema
|
|
932
|
+
]);
|
|
933
|
+
var FetchRequestInitSchema = import_zod11.z.object({
|
|
934
|
+
method: import_zod11.z.string().optional(),
|
|
935
|
+
headers: import_zod11.z.record(import_zod11.z.union([
|
|
936
|
+
import_zod11.z.string(),
|
|
937
|
+
RedactStringSchema
|
|
938
|
+
])).optional(),
|
|
939
|
+
body: import_zod11.z.union([
|
|
940
|
+
import_zod11.z.string(),
|
|
941
|
+
import_zod11.z.instanceof(ArrayBuffer)
|
|
942
|
+
]).optional()
|
|
943
|
+
});
|
|
944
|
+
var FetchRetryOptionsSchema = import_zod11.z.record(FetchRetryStrategySchema);
|
|
945
|
+
var FetchOperationSchema = import_zod11.z.object({
|
|
946
|
+
url: import_zod11.z.string(),
|
|
947
|
+
requestInit: FetchRequestInitSchema.optional(),
|
|
948
|
+
retry: import_zod11.z.record(FetchRetryStrategySchema).optional()
|
|
949
|
+
});
|
|
950
|
+
|
|
884
951
|
// ../internal/src/utils.ts
|
|
885
952
|
function deepMergeFilters(filter, other) {
|
|
886
953
|
const result = {
|
|
@@ -907,8 +974,40 @@ function deepMergeFilters(filter, other) {
|
|
|
907
974
|
}
|
|
908
975
|
__name(deepMergeFilters, "deepMergeFilters");
|
|
909
976
|
|
|
977
|
+
// ../internal/src/retry.ts
|
|
978
|
+
var DEFAULT_RETRY_OPTIONS = {
|
|
979
|
+
limit: 5,
|
|
980
|
+
factor: 1.8,
|
|
981
|
+
minTimeoutInMs: 1e3,
|
|
982
|
+
maxTimeoutInMs: 6e4,
|
|
983
|
+
randomize: true
|
|
984
|
+
};
|
|
985
|
+
function calculateRetryAt(retryOptions, attempts) {
|
|
986
|
+
const options = {
|
|
987
|
+
...DEFAULT_RETRY_OPTIONS,
|
|
988
|
+
...retryOptions
|
|
989
|
+
};
|
|
990
|
+
const retryCount = attempts + 1;
|
|
991
|
+
if (retryCount >= options.limit) {
|
|
992
|
+
return;
|
|
993
|
+
}
|
|
994
|
+
const random = options.randomize ? Math.random() + 1 : 1;
|
|
995
|
+
let timeoutInMs = Math.round(random * Math.max(options.minTimeoutInMs, 1) * Math.pow(options.factor, Math.max(attempts - 1, 0)));
|
|
996
|
+
timeoutInMs = Math.min(timeoutInMs, options.maxTimeoutInMs);
|
|
997
|
+
return new Date(Date.now() + timeoutInMs);
|
|
998
|
+
}
|
|
999
|
+
__name(calculateRetryAt, "calculateRetryAt");
|
|
1000
|
+
|
|
1001
|
+
// ../internal/src/replacements.ts
|
|
1002
|
+
var currentDate = {
|
|
1003
|
+
marker: "__CURRENT_DATE__",
|
|
1004
|
+
replace({ data: { now } }) {
|
|
1005
|
+
return now.toISOString();
|
|
1006
|
+
}
|
|
1007
|
+
};
|
|
1008
|
+
|
|
910
1009
|
// src/apiClient.ts
|
|
911
|
-
var
|
|
1010
|
+
var import_zod12 = require("zod");
|
|
912
1011
|
var _apiUrl, _options, _logger, _apiKey, apiKey_fn;
|
|
913
1012
|
var ApiClient = class {
|
|
914
1013
|
constructor(options) {
|
|
@@ -1077,8 +1176,8 @@ var ApiClient = class {
|
|
|
1077
1176
|
__privateGet(this, _logger).debug("unregistering schedule", {
|
|
1078
1177
|
id
|
|
1079
1178
|
});
|
|
1080
|
-
const response = await zodfetch(
|
|
1081
|
-
ok:
|
|
1179
|
+
const response = await zodfetch(import_zod12.z.object({
|
|
1180
|
+
ok: import_zod12.z.boolean()
|
|
1082
1181
|
}), `${__privateGet(this, _apiUrl)}/api/v1/${client}/schedules/${id}/registrations/${encodeURIComponent(key)}`, {
|
|
1083
1182
|
method: "DELETE",
|
|
1084
1183
|
headers: {
|
|
@@ -1186,11 +1285,12 @@ function createIOWithIntegrations(io, auths, integrations) {
|
|
|
1186
1285
|
return io;
|
|
1187
1286
|
}
|
|
1188
1287
|
const connections = Object.entries(integrations).reduce((acc, [connectionKey, integration]) => {
|
|
1189
|
-
|
|
1190
|
-
const client =
|
|
1288
|
+
let auth = auths?.[connectionKey];
|
|
1289
|
+
const client = integration.client.usesLocalAuth ? integration.client.client : auth ? integration.client.clientFactory?.(auth) : void 0;
|
|
1191
1290
|
if (!client) {
|
|
1192
1291
|
return acc;
|
|
1193
1292
|
}
|
|
1293
|
+
auth = integration.client.usesLocalAuth ? integration.client.auth : auth;
|
|
1194
1294
|
const ioConnection = {
|
|
1195
1295
|
client
|
|
1196
1296
|
};
|
|
@@ -1202,7 +1302,7 @@ function createIOWithIntegrations(io, auths, integrations) {
|
|
|
1202
1302
|
const options = authenticatedTask2.init(params);
|
|
1203
1303
|
options.connectionKey = connectionKey;
|
|
1204
1304
|
return await io.runTask(key, options, async (ioTask) => {
|
|
1205
|
-
return authenticatedTask2.run(params, client, ioTask, io);
|
|
1305
|
+
return authenticatedTask2.run(params, client, ioTask, io, auth);
|
|
1206
1306
|
}, authenticatedTask2.onError);
|
|
1207
1307
|
};
|
|
1208
1308
|
});
|
|
@@ -1225,30 +1325,6 @@ function createIOWithIntegrations(io, auths, integrations) {
|
|
|
1225
1325
|
}
|
|
1226
1326
|
__name(createIOWithIntegrations, "createIOWithIntegrations");
|
|
1227
1327
|
|
|
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
1328
|
// src/io.ts
|
|
1253
1329
|
var _addToCachedTasks, addToCachedTasks_fn;
|
|
1254
1330
|
var IO = class {
|
|
@@ -1325,6 +1401,37 @@ var IO = class {
|
|
|
1325
1401
|
}, async (task) => {
|
|
1326
1402
|
});
|
|
1327
1403
|
}
|
|
1404
|
+
async backgroundFetch(key, url, requestInit, retry) {
|
|
1405
|
+
const urlObject = new URL(url);
|
|
1406
|
+
return await this.runTask(key, {
|
|
1407
|
+
name: `fetch ${urlObject.hostname}${urlObject.pathname}`,
|
|
1408
|
+
params: {
|
|
1409
|
+
url,
|
|
1410
|
+
requestInit,
|
|
1411
|
+
retry
|
|
1412
|
+
},
|
|
1413
|
+
operation: "fetch",
|
|
1414
|
+
icon: "background",
|
|
1415
|
+
noop: false,
|
|
1416
|
+
properties: [
|
|
1417
|
+
{
|
|
1418
|
+
label: "url",
|
|
1419
|
+
text: url,
|
|
1420
|
+
url
|
|
1421
|
+
},
|
|
1422
|
+
{
|
|
1423
|
+
label: "method",
|
|
1424
|
+
text: requestInit?.method ?? "GET"
|
|
1425
|
+
},
|
|
1426
|
+
{
|
|
1427
|
+
label: "background",
|
|
1428
|
+
text: "true"
|
|
1429
|
+
}
|
|
1430
|
+
]
|
|
1431
|
+
}, async (task) => {
|
|
1432
|
+
return task.output;
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1328
1435
|
async sendEvent(key, event, options) {
|
|
1329
1436
|
return await this.runTask(key, {
|
|
1330
1437
|
name: "sendEvent",
|
|
@@ -1540,6 +1647,13 @@ var IO = class {
|
|
|
1540
1647
|
});
|
|
1541
1648
|
throw new ResumeWithTaskError(task);
|
|
1542
1649
|
}
|
|
1650
|
+
if (task.status === "RUNNING" && typeof task.operation === "string") {
|
|
1651
|
+
this._logger.debug("Task running operation", {
|
|
1652
|
+
idempotencyKey,
|
|
1653
|
+
task
|
|
1654
|
+
});
|
|
1655
|
+
throw new ResumeWithTaskError(task);
|
|
1656
|
+
}
|
|
1543
1657
|
const executeTask = /* @__PURE__ */ __name(async () => {
|
|
1544
1658
|
try {
|
|
1545
1659
|
const result = await callback(task, this);
|
|
@@ -1552,6 +1666,9 @@ var IO = class {
|
|
|
1552
1666
|
});
|
|
1553
1667
|
return result;
|
|
1554
1668
|
} catch (error) {
|
|
1669
|
+
if (isTriggerError(error)) {
|
|
1670
|
+
throw error;
|
|
1671
|
+
}
|
|
1555
1672
|
if (onError) {
|
|
1556
1673
|
const onErrorResult = onError(error, task, this);
|
|
1557
1674
|
if (onErrorResult) {
|
|
@@ -1563,7 +1680,7 @@ var IO = class {
|
|
|
1563
1680
|
}
|
|
1564
1681
|
const parsedError = ErrorWithStackSchema.safeParse(error);
|
|
1565
1682
|
if (options.retry) {
|
|
1566
|
-
const retryAt = calculateRetryAt(options.retry, task.attempts);
|
|
1683
|
+
const retryAt = calculateRetryAt(options.retry, task.attempts - 1);
|
|
1567
1684
|
if (retryAt) {
|
|
1568
1685
|
throw new RetryWithTaskError(parsedError.success ? parsedError.data : {
|
|
1569
1686
|
message: "Unknown error"
|
|
@@ -1773,14 +1890,33 @@ var TriggerClient = class {
|
|
|
1773
1890
|
}
|
|
1774
1891
|
switch (action) {
|
|
1775
1892
|
case "PING": {
|
|
1893
|
+
const endpointId = request.headers.get("x-trigger-endpoint-id");
|
|
1894
|
+
if (!endpointId) {
|
|
1895
|
+
return {
|
|
1896
|
+
status: 200,
|
|
1897
|
+
body: {
|
|
1898
|
+
ok: false,
|
|
1899
|
+
message: "Missing endpoint ID"
|
|
1900
|
+
}
|
|
1901
|
+
};
|
|
1902
|
+
}
|
|
1903
|
+
if (this.id !== endpointId) {
|
|
1904
|
+
return {
|
|
1905
|
+
status: 200,
|
|
1906
|
+
body: {
|
|
1907
|
+
ok: false,
|
|
1908
|
+
message: `Endpoint ID mismatch error. Expected ${this.id}, got ${endpointId}`
|
|
1909
|
+
}
|
|
1910
|
+
};
|
|
1911
|
+
}
|
|
1776
1912
|
return {
|
|
1777
1913
|
status: 200,
|
|
1778
1914
|
body: {
|
|
1779
|
-
|
|
1915
|
+
ok: true
|
|
1780
1916
|
}
|
|
1781
1917
|
};
|
|
1782
1918
|
}
|
|
1783
|
-
case "
|
|
1919
|
+
case "INDEX_ENDPOINT": {
|
|
1784
1920
|
const jobId = request.headers.get("x-trigger-job-id");
|
|
1785
1921
|
if (jobId) {
|
|
1786
1922
|
const job = __privateGet(this, _registeredJobs)[jobId];
|
|
@@ -1814,15 +1950,6 @@ var TriggerClient = class {
|
|
|
1814
1950
|
body
|
|
1815
1951
|
};
|
|
1816
1952
|
}
|
|
1817
|
-
case "INITIALIZE": {
|
|
1818
|
-
await this.listen();
|
|
1819
|
-
return {
|
|
1820
|
-
status: 200,
|
|
1821
|
-
body: {
|
|
1822
|
-
message: "Initialized"
|
|
1823
|
-
}
|
|
1824
|
-
};
|
|
1825
|
-
}
|
|
1826
1953
|
case "INITIALIZE_TRIGGER": {
|
|
1827
1954
|
const json = await request.json();
|
|
1828
1955
|
const body = InitializeTriggerBodySchema.safeParse(json);
|
|
@@ -2003,7 +2130,11 @@ var TriggerClient = class {
|
|
|
2003
2130
|
key: options.key,
|
|
2004
2131
|
params: options.params,
|
|
2005
2132
|
events: [],
|
|
2006
|
-
|
|
2133
|
+
integration: {
|
|
2134
|
+
id: options.source.integration.id,
|
|
2135
|
+
metadata: options.source.integration.metadata,
|
|
2136
|
+
authSource: options.source.integration.client.usesLocalAuth ? "LOCAL" : "HOSTED"
|
|
2137
|
+
}
|
|
2007
2138
|
};
|
|
2008
2139
|
}
|
|
2009
2140
|
registeredSource.events = Array.from(/* @__PURE__ */ new Set([
|
|
@@ -2079,12 +2210,6 @@ var TriggerClient = class {
|
|
|
2079
2210
|
apiKey() {
|
|
2080
2211
|
return __privateGet(this, _options3).apiKey ?? process.env.TRIGGER_API_KEY;
|
|
2081
2212
|
}
|
|
2082
|
-
async listen() {
|
|
2083
|
-
await __privateGet(this, _client).registerEndpoint({
|
|
2084
|
-
url: this.url,
|
|
2085
|
-
name: this.id
|
|
2086
|
-
});
|
|
2087
|
-
}
|
|
2088
2213
|
};
|
|
2089
2214
|
__name(TriggerClient, "TriggerClient");
|
|
2090
2215
|
_options3 = new WeakMap();
|
|
@@ -2177,7 +2302,7 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
|
|
|
2177
2302
|
}, "#executeJob");
|
|
2178
2303
|
_createRunContext = new WeakSet();
|
|
2179
2304
|
createRunContext_fn = /* @__PURE__ */ __name(function(execution) {
|
|
2180
|
-
const { event, organization, environment, job, run } = execution;
|
|
2305
|
+
const { event, organization, environment, job, run, source } = execution;
|
|
2181
2306
|
return {
|
|
2182
2307
|
event: {
|
|
2183
2308
|
id: event.id,
|
|
@@ -2189,7 +2314,8 @@ createRunContext_fn = /* @__PURE__ */ __name(function(execution) {
|
|
|
2189
2314
|
environment,
|
|
2190
2315
|
job,
|
|
2191
2316
|
run,
|
|
2192
|
-
account: execution.account
|
|
2317
|
+
account: execution.account,
|
|
2318
|
+
source
|
|
2193
2319
|
};
|
|
2194
2320
|
}, "#createRunContext");
|
|
2195
2321
|
_createPreprocessRunContext = new WeakSet();
|
|
@@ -2454,7 +2580,11 @@ var DynamicTrigger = class {
|
|
|
2454
2580
|
events: [
|
|
2455
2581
|
this.event.name
|
|
2456
2582
|
],
|
|
2457
|
-
|
|
2583
|
+
integration: {
|
|
2584
|
+
id: this.source.integration.id,
|
|
2585
|
+
metadata: this.source.integration.metadata,
|
|
2586
|
+
authSource: this.source.integration.client.usesLocalAuth ? "LOCAL" : "HOSTED"
|
|
2587
|
+
}
|
|
2458
2588
|
}
|
|
2459
2589
|
};
|
|
2460
2590
|
}
|
|
@@ -2465,7 +2595,7 @@ var DynamicTrigger = class {
|
|
|
2465
2595
|
triggerClient.attachJobToDynamicTrigger(job, this);
|
|
2466
2596
|
}
|
|
2467
2597
|
get preprocessRuns() {
|
|
2468
|
-
return
|
|
2598
|
+
return true;
|
|
2469
2599
|
}
|
|
2470
2600
|
};
|
|
2471
2601
|
__name(DynamicTrigger, "DynamicTrigger");
|
|
@@ -2473,6 +2603,17 @@ _client2 = new WeakMap();
|
|
|
2473
2603
|
_options4 = new WeakMap();
|
|
2474
2604
|
|
|
2475
2605
|
// src/triggers/scheduled.ts
|
|
2606
|
+
var examples = [
|
|
2607
|
+
{
|
|
2608
|
+
id: "now",
|
|
2609
|
+
name: "Now",
|
|
2610
|
+
icon: "clock",
|
|
2611
|
+
payload: {
|
|
2612
|
+
ts: currentDate.marker,
|
|
2613
|
+
lastTimestamp: currentDate.marker
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
];
|
|
2476
2617
|
var IntervalTrigger = class {
|
|
2477
2618
|
constructor(options) {
|
|
2478
2619
|
this.options = options;
|
|
@@ -2483,6 +2624,7 @@ var IntervalTrigger = class {
|
|
|
2483
2624
|
title: "Schedule",
|
|
2484
2625
|
source: "trigger.dev",
|
|
2485
2626
|
icon: "schedule-interval",
|
|
2627
|
+
examples,
|
|
2486
2628
|
parsePayload: ScheduledPayloadSchema.parse,
|
|
2487
2629
|
properties: [
|
|
2488
2630
|
{
|
|
@@ -2524,6 +2666,7 @@ var CronTrigger = class {
|
|
|
2524
2666
|
title: "Cron Schedule",
|
|
2525
2667
|
source: "trigger.dev",
|
|
2526
2668
|
icon: "schedule-cron",
|
|
2669
|
+
examples,
|
|
2527
2670
|
parsePayload: ScheduledPayloadSchema.parse,
|
|
2528
2671
|
properties: [
|
|
2529
2672
|
{
|
|
@@ -2569,6 +2712,7 @@ var DynamicSchedule = class {
|
|
|
2569
2712
|
title: "Dynamic Schedule",
|
|
2570
2713
|
source: "trigger.dev",
|
|
2571
2714
|
icon: "schedule-dynamic",
|
|
2715
|
+
examples,
|
|
2572
2716
|
parsePayload: ScheduledPayloadSchema.parse
|
|
2573
2717
|
};
|
|
2574
2718
|
}
|
|
@@ -2690,14 +2834,14 @@ var MissingConnectionResolvedNotification = class {
|
|
|
2690
2834
|
__name(MissingConnectionResolvedNotification, "MissingConnectionResolvedNotification");
|
|
2691
2835
|
|
|
2692
2836
|
// src/index.ts
|
|
2693
|
-
function
|
|
2837
|
+
function redactString(strings, ...interpolations) {
|
|
2694
2838
|
return {
|
|
2695
|
-
|
|
2839
|
+
__redactedString: true,
|
|
2696
2840
|
strings: strings.raw,
|
|
2697
2841
|
interpolations
|
|
2698
2842
|
};
|
|
2699
2843
|
}
|
|
2700
|
-
__name(
|
|
2844
|
+
__name(redactString, "redactString");
|
|
2701
2845
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2702
2846
|
0 && (module.exports = {
|
|
2703
2847
|
CronTrigger,
|
|
@@ -2721,6 +2865,6 @@ __name(secureString, "secureString");
|
|
|
2721
2865
|
missingConnectionNotification,
|
|
2722
2866
|
missingConnectionResolvedNotification,
|
|
2723
2867
|
omit,
|
|
2724
|
-
|
|
2868
|
+
redactString
|
|
2725
2869
|
});
|
|
2726
2870
|
//# sourceMappingURL=index.js.map
|