@trigger.dev/sdk 2.2.5 → 2.2.6
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 +211 -5
- package/dist/index.js +257 -22
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -81,7 +81,8 @@ __export(src_exports, {
|
|
|
81
81
|
redactString: () => redactString,
|
|
82
82
|
retry: () => retry,
|
|
83
83
|
verifyHmacSha256: () => verifyHmacSha256,
|
|
84
|
-
verifyRequestSignature: () => verifyRequestSignature
|
|
84
|
+
verifyRequestSignature: () => verifyRequestSignature,
|
|
85
|
+
waitForEventSchema: () => waitForEventSchema
|
|
85
86
|
});
|
|
86
87
|
module.exports = __toCommonJS(src_exports);
|
|
87
88
|
|
|
@@ -397,6 +398,23 @@ var ApiClient = class {
|
|
|
397
398
|
})
|
|
398
399
|
});
|
|
399
400
|
}
|
|
401
|
+
async sendEvents(events, options = {}) {
|
|
402
|
+
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
403
|
+
__privateGet(this, _logger).debug("Sending multiple events", {
|
|
404
|
+
events
|
|
405
|
+
});
|
|
406
|
+
return await zodfetch(import_core.ApiEventLogSchema.array(), `${__privateGet(this, _apiUrl)}/api/v1/events/bulk`, {
|
|
407
|
+
method: "POST",
|
|
408
|
+
headers: {
|
|
409
|
+
"Content-Type": "application/json",
|
|
410
|
+
Authorization: `Bearer ${apiKey}`
|
|
411
|
+
},
|
|
412
|
+
body: JSON.stringify({
|
|
413
|
+
events,
|
|
414
|
+
options
|
|
415
|
+
})
|
|
416
|
+
});
|
|
417
|
+
}
|
|
400
418
|
async cancelEvent(eventId) {
|
|
401
419
|
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
402
420
|
__privateGet(this, _logger).debug("Cancelling event", {
|
|
@@ -610,6 +628,21 @@ var ApiClient = class {
|
|
|
610
628
|
body: JSON.stringify(body)
|
|
611
629
|
});
|
|
612
630
|
}
|
|
631
|
+
async createEphemeralEventDispatcher(payload) {
|
|
632
|
+
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
633
|
+
__privateGet(this, _logger).debug("Creating ephemeral event dispatcher", {
|
|
634
|
+
payload
|
|
635
|
+
});
|
|
636
|
+
const response = await zodfetch(import_core.EphemeralEventDispatcherResponseBodySchema, `${__privateGet(this, _apiUrl)}/api/v1/event-dispatchers/ephemeral`, {
|
|
637
|
+
method: "POST",
|
|
638
|
+
headers: {
|
|
639
|
+
"Content-Type": "application/json",
|
|
640
|
+
Authorization: `Bearer ${apiKey}`
|
|
641
|
+
},
|
|
642
|
+
body: JSON.stringify(payload)
|
|
643
|
+
});
|
|
644
|
+
return response;
|
|
645
|
+
}
|
|
613
646
|
};
|
|
614
647
|
__name(ApiClient, "ApiClient");
|
|
615
648
|
_apiUrl = new WeakMap();
|
|
@@ -933,6 +966,13 @@ var retry = {
|
|
|
933
966
|
minTimeoutInMs: 500,
|
|
934
967
|
maxTimeoutInMs: 3e4,
|
|
935
968
|
randomize: true
|
|
969
|
+
},
|
|
970
|
+
exponentialBackoff: {
|
|
971
|
+
limit: 8,
|
|
972
|
+
factor: 2,
|
|
973
|
+
minTimeoutInMs: 1e3,
|
|
974
|
+
maxTimeoutInMs: 3e4,
|
|
975
|
+
randomize: true
|
|
936
976
|
}
|
|
937
977
|
};
|
|
938
978
|
|
|
@@ -970,7 +1010,29 @@ var TriggerStatus = class {
|
|
|
970
1010
|
};
|
|
971
1011
|
__name(TriggerStatus, "TriggerStatus");
|
|
972
1012
|
|
|
1013
|
+
// src/types.ts
|
|
1014
|
+
var import_zod2 = require("zod");
|
|
1015
|
+
var EventSpecificationExampleSchema = import_zod2.z.object({
|
|
1016
|
+
id: import_zod2.z.string(),
|
|
1017
|
+
name: import_zod2.z.string(),
|
|
1018
|
+
icon: import_zod2.z.string().optional(),
|
|
1019
|
+
payload: import_zod2.z.any()
|
|
1020
|
+
});
|
|
1021
|
+
function waitForEventSchema(schema) {
|
|
1022
|
+
return import_zod2.z.object({
|
|
1023
|
+
id: import_zod2.z.string(),
|
|
1024
|
+
name: import_zod2.z.string(),
|
|
1025
|
+
source: import_zod2.z.string(),
|
|
1026
|
+
payload: schema,
|
|
1027
|
+
timestamp: import_zod2.z.coerce.date(),
|
|
1028
|
+
context: import_zod2.z.any().optional(),
|
|
1029
|
+
accountId: import_zod2.z.string().optional()
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
__name(waitForEventSchema, "waitForEventSchema");
|
|
1033
|
+
|
|
973
1034
|
// src/io.ts
|
|
1035
|
+
var import_zod3 = require("zod");
|
|
974
1036
|
var JSONOutputSerializer = class {
|
|
975
1037
|
serialize(value) {
|
|
976
1038
|
return JSON.stringify(value);
|
|
@@ -1153,6 +1215,63 @@ var IO = class {
|
|
|
1153
1215
|
}
|
|
1154
1216
|
});
|
|
1155
1217
|
}
|
|
1218
|
+
async waitForEvent(cacheKey, event, options) {
|
|
1219
|
+
const timeoutInSeconds = options?.timeoutInSeconds ?? 60 * 60;
|
|
1220
|
+
return await this.runTask(cacheKey, async (task, io) => {
|
|
1221
|
+
if (!task.callbackUrl) {
|
|
1222
|
+
throw new Error("No callbackUrl found on task");
|
|
1223
|
+
}
|
|
1224
|
+
await this.triggerClient.createEphemeralEventDispatcher({
|
|
1225
|
+
url: task.callbackUrl,
|
|
1226
|
+
name: event.name,
|
|
1227
|
+
filter: event.filter,
|
|
1228
|
+
contextFilter: event.contextFilter,
|
|
1229
|
+
source: event.source,
|
|
1230
|
+
accountId: event.accountId,
|
|
1231
|
+
timeoutInSeconds
|
|
1232
|
+
});
|
|
1233
|
+
return {};
|
|
1234
|
+
}, {
|
|
1235
|
+
name: "Wait for Event",
|
|
1236
|
+
icon: "custom-event",
|
|
1237
|
+
params: {
|
|
1238
|
+
name: event.name,
|
|
1239
|
+
source: event.source,
|
|
1240
|
+
filter: event.filter,
|
|
1241
|
+
contextFilter: event.contextFilter,
|
|
1242
|
+
accountId: event.accountId
|
|
1243
|
+
},
|
|
1244
|
+
callback: {
|
|
1245
|
+
enabled: true,
|
|
1246
|
+
timeoutInSeconds
|
|
1247
|
+
},
|
|
1248
|
+
properties: [
|
|
1249
|
+
{
|
|
1250
|
+
label: "Event",
|
|
1251
|
+
text: event.name
|
|
1252
|
+
},
|
|
1253
|
+
{
|
|
1254
|
+
label: "Timeout",
|
|
1255
|
+
text: `${timeoutInSeconds}s`
|
|
1256
|
+
},
|
|
1257
|
+
...event.source ? [
|
|
1258
|
+
{
|
|
1259
|
+
label: "Source",
|
|
1260
|
+
text: event.source
|
|
1261
|
+
}
|
|
1262
|
+
] : [],
|
|
1263
|
+
...event.accountId ? [
|
|
1264
|
+
{
|
|
1265
|
+
label: "Account ID",
|
|
1266
|
+
text: event.accountId
|
|
1267
|
+
}
|
|
1268
|
+
] : []
|
|
1269
|
+
],
|
|
1270
|
+
parseOutput: (output) => {
|
|
1271
|
+
return waitForEventSchema(event.schema ?? import_zod3.z.any()).parse(output);
|
|
1272
|
+
}
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1156
1275
|
async waitForRequest(cacheKey, callback, options) {
|
|
1157
1276
|
const timeoutInSeconds = options?.timeoutInSeconds ?? 60 * 60;
|
|
1158
1277
|
return await this.runTask(cacheKey, async (task, io) => {
|
|
@@ -1187,17 +1306,18 @@ var IO = class {
|
|
|
1187
1306
|
await status.update(cacheKey, initialStatus);
|
|
1188
1307
|
return status;
|
|
1189
1308
|
}
|
|
1190
|
-
async backgroundFetch(cacheKey, url, requestInit,
|
|
1309
|
+
async backgroundFetch(cacheKey, url, requestInit, options) {
|
|
1191
1310
|
const urlObject = new URL(url);
|
|
1192
1311
|
return await this.runTask(cacheKey, async (task) => {
|
|
1312
|
+
console.log("task context", task.context);
|
|
1193
1313
|
return task.output;
|
|
1194
1314
|
}, {
|
|
1195
1315
|
name: `fetch ${urlObject.hostname}${urlObject.pathname}`,
|
|
1196
1316
|
params: {
|
|
1197
1317
|
url,
|
|
1198
1318
|
requestInit,
|
|
1199
|
-
retry:
|
|
1200
|
-
timeout
|
|
1319
|
+
retry: options?.retry,
|
|
1320
|
+
timeout: options?.timeout
|
|
1201
1321
|
},
|
|
1202
1322
|
operation: "fetch",
|
|
1203
1323
|
icon: "background",
|
|
@@ -1216,10 +1336,80 @@ var IO = class {
|
|
|
1216
1336
|
label: "background",
|
|
1217
1337
|
text: "true"
|
|
1218
1338
|
},
|
|
1219
|
-
...timeout ? [
|
|
1339
|
+
...options?.timeout ? [
|
|
1220
1340
|
{
|
|
1221
1341
|
label: "timeout",
|
|
1222
|
-
text: `${timeout.durationInMs}ms`
|
|
1342
|
+
text: `${options.timeout.durationInMs}ms`
|
|
1343
|
+
}
|
|
1344
|
+
] : []
|
|
1345
|
+
],
|
|
1346
|
+
retry: {
|
|
1347
|
+
limit: 0
|
|
1348
|
+
}
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1351
|
+
async backgroundPoll(cacheKey, params) {
|
|
1352
|
+
const urlObject = new URL(params.url);
|
|
1353
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
1354
|
+
return task.output;
|
|
1355
|
+
}, {
|
|
1356
|
+
name: `poll ${urlObject.hostname}${urlObject.pathname}`,
|
|
1357
|
+
params,
|
|
1358
|
+
operation: "fetch-poll",
|
|
1359
|
+
icon: "clock-bolt",
|
|
1360
|
+
noop: false,
|
|
1361
|
+
properties: [
|
|
1362
|
+
{
|
|
1363
|
+
label: "url",
|
|
1364
|
+
text: params.url
|
|
1365
|
+
},
|
|
1366
|
+
{
|
|
1367
|
+
label: "interval",
|
|
1368
|
+
text: `${params.interval}s`
|
|
1369
|
+
},
|
|
1370
|
+
{
|
|
1371
|
+
label: "timeout",
|
|
1372
|
+
text: `${params.timeout}s`
|
|
1373
|
+
}
|
|
1374
|
+
],
|
|
1375
|
+
retry: {
|
|
1376
|
+
limit: 0
|
|
1377
|
+
}
|
|
1378
|
+
});
|
|
1379
|
+
}
|
|
1380
|
+
async backgroundFetchResponse(cacheKey, url, requestInit, options) {
|
|
1381
|
+
const urlObject = new URL(url);
|
|
1382
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
1383
|
+
return task.output;
|
|
1384
|
+
}, {
|
|
1385
|
+
name: `fetch response ${urlObject.hostname}${urlObject.pathname}`,
|
|
1386
|
+
params: {
|
|
1387
|
+
url,
|
|
1388
|
+
requestInit,
|
|
1389
|
+
retry: options?.retry,
|
|
1390
|
+
timeout: options?.timeout
|
|
1391
|
+
},
|
|
1392
|
+
operation: "fetch-response",
|
|
1393
|
+
icon: "background",
|
|
1394
|
+
noop: false,
|
|
1395
|
+
properties: [
|
|
1396
|
+
{
|
|
1397
|
+
label: "url",
|
|
1398
|
+
text: url,
|
|
1399
|
+
url
|
|
1400
|
+
},
|
|
1401
|
+
{
|
|
1402
|
+
label: "method",
|
|
1403
|
+
text: requestInit?.method ?? "GET"
|
|
1404
|
+
},
|
|
1405
|
+
{
|
|
1406
|
+
label: "background",
|
|
1407
|
+
text: "true"
|
|
1408
|
+
},
|
|
1409
|
+
...options?.timeout ? [
|
|
1410
|
+
{
|
|
1411
|
+
label: "timeout",
|
|
1412
|
+
text: `${options.timeout.durationInMs}ms`
|
|
1223
1413
|
}
|
|
1224
1414
|
] : []
|
|
1225
1415
|
],
|
|
@@ -1247,7 +1437,26 @@ var IO = class {
|
|
|
1247
1437
|
label: "ID",
|
|
1248
1438
|
text: event.id
|
|
1249
1439
|
}
|
|
1250
|
-
] : []
|
|
1440
|
+
] : [],
|
|
1441
|
+
...sendEventOptionsProperties(options)
|
|
1442
|
+
]
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
async sendEvents(cacheKey, events, options) {
|
|
1446
|
+
return await this.runTask(cacheKey, async (task) => {
|
|
1447
|
+
return await this._triggerClient.sendEvents(events, options);
|
|
1448
|
+
}, {
|
|
1449
|
+
name: "sendEvents",
|
|
1450
|
+
params: {
|
|
1451
|
+
events,
|
|
1452
|
+
options
|
|
1453
|
+
},
|
|
1454
|
+
properties: [
|
|
1455
|
+
{
|
|
1456
|
+
label: "Total Events",
|
|
1457
|
+
text: String(events.length)
|
|
1458
|
+
},
|
|
1459
|
+
...sendEventOptionsProperties(options)
|
|
1251
1460
|
]
|
|
1252
1461
|
});
|
|
1253
1462
|
}
|
|
@@ -1471,7 +1680,7 @@ var IO = class {
|
|
|
1471
1680
|
idempotencyKey
|
|
1472
1681
|
});
|
|
1473
1682
|
this._stats.cachedTaskHits++;
|
|
1474
|
-
return cachedTask.output;
|
|
1683
|
+
return options?.parseOutput ? options.parseOutput(cachedTask.output) : cachedTask.output;
|
|
1475
1684
|
}
|
|
1476
1685
|
if (options?.noop && this._noopTasksBloomFilter) {
|
|
1477
1686
|
if (this._noopTasksBloomFilter.test(idempotencyKey)) {
|
|
@@ -1482,11 +1691,15 @@ var IO = class {
|
|
|
1482
1691
|
return {};
|
|
1483
1692
|
}
|
|
1484
1693
|
}
|
|
1694
|
+
const runOptions = {
|
|
1695
|
+
...options ?? {},
|
|
1696
|
+
parseOutput: void 0
|
|
1697
|
+
};
|
|
1485
1698
|
const response = await this._apiClient.runTask(this._id, {
|
|
1486
1699
|
idempotencyKey,
|
|
1487
1700
|
displayKey: typeof cacheKey === "string" ? cacheKey : void 0,
|
|
1488
1701
|
noop: false,
|
|
1489
|
-
...
|
|
1702
|
+
...runOptions ?? {},
|
|
1490
1703
|
parentId
|
|
1491
1704
|
}, {
|
|
1492
1705
|
cachedTasksCursor: this._cachedTasksCursor
|
|
@@ -1530,7 +1743,7 @@ var IO = class {
|
|
|
1530
1743
|
this._stats.cachedTaskMisses++;
|
|
1531
1744
|
__privateMethod(this, _addToCachedTasks, addToCachedTasks_fn).call(this, task);
|
|
1532
1745
|
}
|
|
1533
|
-
return task.output;
|
|
1746
|
+
return options?.parseOutput ? options.parseOutput(task.output) : task.output;
|
|
1534
1747
|
}
|
|
1535
1748
|
if (task.status === "ERRORED") {
|
|
1536
1749
|
this._logger.debug("Task errored", {
|
|
@@ -1571,7 +1784,8 @@ var IO = class {
|
|
|
1571
1784
|
throw new CanceledWithTaskError(completedTask);
|
|
1572
1785
|
}
|
|
1573
1786
|
__privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "after_complete_task", 500);
|
|
1574
|
-
|
|
1787
|
+
const deserializedOutput = this._outputSerializer.deserialize(output);
|
|
1788
|
+
return options?.parseOutput ? options.parseOutput(deserializedOutput) : deserializedOutput;
|
|
1575
1789
|
} catch (error) {
|
|
1576
1790
|
if (isTriggerError(error)) {
|
|
1577
1791
|
throw error;
|
|
@@ -1770,6 +1984,29 @@ async function spaceOut(callback, index, delay) {
|
|
|
1770
1984
|
return await callback();
|
|
1771
1985
|
}
|
|
1772
1986
|
__name(spaceOut, "spaceOut");
|
|
1987
|
+
function sendEventOptionsProperties(options) {
|
|
1988
|
+
return [
|
|
1989
|
+
...options?.accountId ? [
|
|
1990
|
+
{
|
|
1991
|
+
label: "Account ID",
|
|
1992
|
+
text: options.accountId
|
|
1993
|
+
}
|
|
1994
|
+
] : [],
|
|
1995
|
+
...options?.deliverAfter ? [
|
|
1996
|
+
{
|
|
1997
|
+
label: "Deliver After",
|
|
1998
|
+
text: `${options.deliverAfter}s`
|
|
1999
|
+
}
|
|
2000
|
+
] : [],
|
|
2001
|
+
...options?.deliverAt ? [
|
|
2002
|
+
{
|
|
2003
|
+
label: "Deliver At",
|
|
2004
|
+
text: options.deliverAt.toISOString()
|
|
2005
|
+
}
|
|
2006
|
+
] : []
|
|
2007
|
+
];
|
|
2008
|
+
}
|
|
2009
|
+
__name(sendEventOptionsProperties, "sendEventOptionsProperties");
|
|
1773
2010
|
|
|
1774
2011
|
// src/ioWithIntegrations.ts
|
|
1775
2012
|
function createIOWithIntegrations(io, auths, integrations) {
|
|
@@ -2161,7 +2398,7 @@ var DynamicSchedule = class {
|
|
|
2161
2398
|
__name(DynamicSchedule, "DynamicSchedule");
|
|
2162
2399
|
|
|
2163
2400
|
// package.json
|
|
2164
|
-
var version = "2.2.
|
|
2401
|
+
var version = "2.2.6";
|
|
2165
2402
|
|
|
2166
2403
|
// src/triggerClient.ts
|
|
2167
2404
|
var registerSourceEvent = {
|
|
@@ -2675,6 +2912,9 @@ var TriggerClient = class {
|
|
|
2675
2912
|
async sendEvent(event, options) {
|
|
2676
2913
|
return __privateGet(this, _client2).sendEvent(event, options);
|
|
2677
2914
|
}
|
|
2915
|
+
async sendEvents(events, options) {
|
|
2916
|
+
return __privateGet(this, _client2).sendEvents(events, options);
|
|
2917
|
+
}
|
|
2678
2918
|
async cancelEvent(eventId) {
|
|
2679
2919
|
return __privateGet(this, _client2).cancelEvent(eventId);
|
|
2680
2920
|
}
|
|
@@ -2708,6 +2948,9 @@ var TriggerClient = class {
|
|
|
2708
2948
|
async invokeJob(jobId, payload, options) {
|
|
2709
2949
|
return __privateGet(this, _client2).invokeJob(jobId, payload, options);
|
|
2710
2950
|
}
|
|
2951
|
+
async createEphemeralEventDispatcher(payload) {
|
|
2952
|
+
return __privateGet(this, _client2).createEphemeralEventDispatcher(payload);
|
|
2953
|
+
}
|
|
2711
2954
|
authorized(apiKey) {
|
|
2712
2955
|
if (typeof apiKey !== "string") {
|
|
2713
2956
|
return "missing-header";
|
|
@@ -3565,15 +3808,6 @@ function invokeTrigger(options) {
|
|
|
3565
3808
|
}
|
|
3566
3809
|
__name(invokeTrigger, "invokeTrigger");
|
|
3567
3810
|
|
|
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
3811
|
// src/security.ts
|
|
3578
3812
|
var import_crypto = __toESM(require("crypto"));
|
|
3579
3813
|
async function verifyRequestSignature({ request, headerName, secret, algorithm }) {
|
|
@@ -3653,6 +3887,7 @@ __name(redactString, "redactString");
|
|
|
3653
3887
|
redactString,
|
|
3654
3888
|
retry,
|
|
3655
3889
|
verifyHmacSha256,
|
|
3656
|
-
verifyRequestSignature
|
|
3890
|
+
verifyRequestSignature,
|
|
3891
|
+
waitForEventSchema
|
|
3657
3892
|
});
|
|
3658
3893
|
//# sourceMappingURL=index.js.map
|