@trigger.dev/core 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 +1131 -11
- package/dist/index.js +164 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -66,6 +66,8 @@ __export(src_exports, {
|
|
|
66
66
|
DynamicTriggerMetadataSchema: () => DynamicTriggerMetadataSchema,
|
|
67
67
|
EndpointHeadersSchema: () => EndpointHeadersSchema,
|
|
68
68
|
EndpointIndexErrorSchema: () => EndpointIndexErrorSchema,
|
|
69
|
+
EphemeralEventDispatcherRequestBodySchema: () => EphemeralEventDispatcherRequestBodySchema,
|
|
70
|
+
EphemeralEventDispatcherResponseBodySchema: () => EphemeralEventDispatcherResponseBodySchema,
|
|
69
71
|
ErrorWithStackSchema: () => ErrorWithStackSchema,
|
|
70
72
|
EventExampleSchema: () => EventExampleSchema,
|
|
71
73
|
EventFilterSchema: () => EventFilterSchema,
|
|
@@ -73,6 +75,7 @@ __export(src_exports, {
|
|
|
73
75
|
EventSpecificationSchema: () => EventSpecificationSchema,
|
|
74
76
|
FailTaskBodyInputSchema: () => FailTaskBodyInputSchema,
|
|
75
77
|
FetchOperationSchema: () => FetchOperationSchema,
|
|
78
|
+
FetchPollOperationSchema: () => FetchPollOperationSchema,
|
|
76
79
|
FetchRequestInitSchema: () => FetchRequestInitSchema,
|
|
77
80
|
FetchRetryBackoffStrategySchema: () => FetchRetryBackoffStrategySchema,
|
|
78
81
|
FetchRetryHeadersStrategySchema: () => FetchRetryHeadersStrategySchema,
|
|
@@ -141,6 +144,7 @@ __export(src_exports, {
|
|
|
141
144
|
RegisterTriggerSourceSchema: () => RegisterTriggerSourceSchema,
|
|
142
145
|
RequestFilterSchema: () => RequestFilterSchema,
|
|
143
146
|
RequestWithRawBodySchema: () => RequestWithRawBodySchema,
|
|
147
|
+
ResponseFilterSchema: () => ResponseFilterSchema,
|
|
144
148
|
RetryOptionsSchema: () => RetryOptionsSchema,
|
|
145
149
|
RunJobAutoYieldExecutionErrorSchema: () => RunJobAutoYieldExecutionErrorSchema,
|
|
146
150
|
RunJobAutoYieldWithCompletedTaskExecutionErrorSchema: () => RunJobAutoYieldWithCompletedTaskExecutionErrorSchema,
|
|
@@ -169,6 +173,7 @@ __export(src_exports, {
|
|
|
169
173
|
ScheduledPayloadSchema: () => ScheduledPayloadSchema,
|
|
170
174
|
ScheduledTriggerMetadataSchema: () => ScheduledTriggerMetadataSchema,
|
|
171
175
|
SchemaErrorSchema: () => SchemaErrorSchema,
|
|
176
|
+
SendBulkEventsBodySchema: () => SendBulkEventsBodySchema,
|
|
172
177
|
SendEventBodySchema: () => SendEventBodySchema,
|
|
173
178
|
SendEventOptionsSchema: () => SendEventOptionsSchema,
|
|
174
179
|
SerializableJsonSchema: () => SerializableJsonSchema,
|
|
@@ -190,6 +195,7 @@ __export(src_exports, {
|
|
|
190
195
|
ValidateResponseSchema: () => ValidateResponseSchema,
|
|
191
196
|
ValidateSuccessResponseSchema: () => ValidateSuccessResponseSchema,
|
|
192
197
|
addMissingVersionField: () => addMissingVersionField,
|
|
198
|
+
calculateResetAt: () => calculateResetAt,
|
|
193
199
|
calculateRetryAt: () => calculateRetryAt,
|
|
194
200
|
currentDate: () => currentDate,
|
|
195
201
|
currentTimestampMilliseconds: () => currentTimestampMilliseconds,
|
|
@@ -199,6 +205,7 @@ __export(src_exports, {
|
|
|
199
205
|
parseEndpointIndexStats: () => parseEndpointIndexStats,
|
|
200
206
|
replacements: () => replacements,
|
|
201
207
|
requestFilterMatches: () => requestFilterMatches,
|
|
208
|
+
responseFilterMatches: () => responseFilterMatches,
|
|
202
209
|
stringPatternMatchers: () => stringPatternMatchers,
|
|
203
210
|
supportsFeature: () => supportsFeature,
|
|
204
211
|
urlWithSearchParams: () => urlWithSearchParams
|
|
@@ -224,7 +231,7 @@ var _Logger = class _Logger {
|
|
|
224
231
|
__privateSet(this, _name, name);
|
|
225
232
|
__privateSet(this, _level, logLevels.indexOf(process.env.TRIGGER_LOG_LEVEL ?? level));
|
|
226
233
|
__privateSet(this, _filteredKeys, filteredKeys);
|
|
227
|
-
__privateSet(this, _jsonReplacer, jsonReplacer);
|
|
234
|
+
__privateSet(this, _jsonReplacer, createReplacer(jsonReplacer));
|
|
228
235
|
}
|
|
229
236
|
// Return a new Logger instance with the same name and a new log level
|
|
230
237
|
// but filter out the keys from the log messages (at any level)
|
|
@@ -273,7 +280,7 @@ structuredLog_fn = /* @__PURE__ */ __name(function(loggerFunction, message, leve
|
|
|
273
280
|
message,
|
|
274
281
|
level
|
|
275
282
|
};
|
|
276
|
-
loggerFunction(JSON.stringify(structuredLog,
|
|
283
|
+
loggerFunction(JSON.stringify(structuredLog, __privateGet(this, _jsonReplacer)));
|
|
277
284
|
}, "#structuredLog");
|
|
278
285
|
__name(_Logger, "Logger");
|
|
279
286
|
var Logger = _Logger;
|
|
@@ -300,11 +307,14 @@ function safeJsonClone(obj) {
|
|
|
300
307
|
try {
|
|
301
308
|
return JSON.parse(JSON.stringify(obj, bigIntReplacer));
|
|
302
309
|
} catch (e) {
|
|
303
|
-
return
|
|
310
|
+
return;
|
|
304
311
|
}
|
|
305
312
|
}
|
|
306
313
|
__name(safeJsonClone, "safeJsonClone");
|
|
307
314
|
function structureArgs(args, filteredKeys = []) {
|
|
315
|
+
if (!args) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
308
318
|
if (args.length === 0) {
|
|
309
319
|
return;
|
|
310
320
|
}
|
|
@@ -533,7 +543,9 @@ var DisplayPropertySchema = import_zod5.z.object({
|
|
|
533
543
|
/** The value of the property */
|
|
534
544
|
text: import_zod5.z.string(),
|
|
535
545
|
/** The URL to link to when the property is clicked */
|
|
536
|
-
url: import_zod5.z.string().optional()
|
|
546
|
+
url: import_zod5.z.string().optional(),
|
|
547
|
+
/** The URL to a list of images to display next to the property */
|
|
548
|
+
imageUrl: import_zod5.z.array(import_zod5.z.string()).optional()
|
|
537
549
|
});
|
|
538
550
|
var DisplayPropertiesSchema = import_zod5.z.array(DisplayPropertySchema);
|
|
539
551
|
var StyleSchema = import_zod5.z.object({
|
|
@@ -616,6 +628,7 @@ var TaskSchema = import_zod7.z.object({
|
|
|
616
628
|
outputProperties: import_zod7.z.array(DisplayPropertySchema).optional().nullable(),
|
|
617
629
|
params: DeserializedJsonSchema.optional().nullable(),
|
|
618
630
|
output: DeserializedJsonSchema.optional().nullable(),
|
|
631
|
+
context: DeserializedJsonSchema.optional().nullable(),
|
|
619
632
|
error: import_zod7.z.string().optional().nullable(),
|
|
620
633
|
parentId: import_zod7.z.string().optional().nullable(),
|
|
621
634
|
style: StyleSchema.optional().nullable(),
|
|
@@ -850,6 +863,12 @@ var RequestFilterSchema = import_zod11.z.object({
|
|
|
850
863
|
*/
|
|
851
864
|
body: EventFilterSchema.optional()
|
|
852
865
|
});
|
|
866
|
+
var ResponseFilterSchema = RequestFilterSchema.omit({
|
|
867
|
+
method: true,
|
|
868
|
+
query: true
|
|
869
|
+
}).extend({
|
|
870
|
+
status: import_zod11.z.array(import_zod11.z.number()).optional()
|
|
871
|
+
});
|
|
853
872
|
|
|
854
873
|
// src/schemas/api.ts
|
|
855
874
|
var UpdateTriggerSourceBodyV1Schema = import_zod12.z.object({
|
|
@@ -1188,6 +1207,10 @@ var SendEventBodySchema = import_zod12.z.object({
|
|
|
1188
1207
|
event: RawEventSchema,
|
|
1189
1208
|
options: SendEventOptionsSchema.optional()
|
|
1190
1209
|
});
|
|
1210
|
+
var SendBulkEventsBodySchema = import_zod12.z.object({
|
|
1211
|
+
events: RawEventSchema.array(),
|
|
1212
|
+
options: SendEventOptionsSchema.optional()
|
|
1213
|
+
});
|
|
1191
1214
|
var DeliverEventResponseSchema = import_zod12.z.object({
|
|
1192
1215
|
deliveredAt: import_zod12.z.string().datetime()
|
|
1193
1216
|
});
|
|
@@ -1433,9 +1456,11 @@ var RunTaskOptionsSchema = import_zod12.z.object({
|
|
|
1433
1456
|
}).partial().optional(),
|
|
1434
1457
|
/** Allows you to link the Integration connection in the logs. This is handled automatically in integrations. */
|
|
1435
1458
|
connectionKey: import_zod12.z.string().optional(),
|
|
1436
|
-
/** An operation you want to perform on the Trigger.dev platform, current only "fetch" is supported. If you wish to `fetch` use [`io.backgroundFetch()`](https://trigger.dev/docs/sdk/io/backgroundfetch) instead. */
|
|
1459
|
+
/** An operation you want to perform on the Trigger.dev platform, current only "fetch", "fetch-response", and "fetch-poll" is supported. If you wish to `fetch` use [`io.backgroundFetch()`](https://trigger.dev/docs/sdk/io/backgroundfetch) instead. */
|
|
1437
1460
|
operation: import_zod12.z.enum([
|
|
1438
|
-
"fetch"
|
|
1461
|
+
"fetch",
|
|
1462
|
+
"fetch-response",
|
|
1463
|
+
"fetch-poll"
|
|
1439
1464
|
]).optional(),
|
|
1440
1465
|
/** A No Operation means that the code won't be executed. This is used internally to implement features like [io.wait()](https://trigger.dev/docs/sdk/io/wait). */
|
|
1441
1466
|
noop: import_zod12.z.boolean().default(false),
|
|
@@ -1564,6 +1589,18 @@ var InvokeOptionsSchema = import_zod12.z.object({
|
|
|
1564
1589
|
context: import_zod12.z.any().optional(),
|
|
1565
1590
|
callbackUrl: import_zod12.z.string().optional()
|
|
1566
1591
|
});
|
|
1592
|
+
var EphemeralEventDispatcherRequestBodySchema = import_zod12.z.object({
|
|
1593
|
+
url: import_zod12.z.string(),
|
|
1594
|
+
name: import_zod12.z.string().or(import_zod12.z.array(import_zod12.z.string())),
|
|
1595
|
+
source: import_zod12.z.string().optional(),
|
|
1596
|
+
filter: EventFilterSchema.optional(),
|
|
1597
|
+
contextFilter: EventFilterSchema.optional(),
|
|
1598
|
+
accountId: import_zod12.z.string().optional(),
|
|
1599
|
+
timeoutInSeconds: import_zod12.z.number().int().positive().min(10).max(60 * 60 * 24 * 365).default(3600)
|
|
1600
|
+
});
|
|
1601
|
+
var EphemeralEventDispatcherResponseBodySchema = import_zod12.z.object({
|
|
1602
|
+
id: import_zod12.z.string()
|
|
1603
|
+
});
|
|
1567
1604
|
|
|
1568
1605
|
// src/schemas/notifications.ts
|
|
1569
1606
|
var import_zod13 = require("zod");
|
|
@@ -1632,11 +1669,22 @@ var FetchRetryHeadersStrategySchema = import_zod14.z.object({
|
|
|
1632
1669
|
/** The header to use to determine the number of remaining retries. */
|
|
1633
1670
|
remainingHeader: import_zod14.z.string(),
|
|
1634
1671
|
/** The header to use to determine the time when the number of remaining retries will be reset. */
|
|
1635
|
-
resetHeader: import_zod14.z.string()
|
|
1672
|
+
resetHeader: import_zod14.z.string(),
|
|
1673
|
+
/** The event filter to use to determine if the request should be retried. */
|
|
1674
|
+
bodyFilter: EventFilterSchema.optional(),
|
|
1675
|
+
/** The format of the `resetHeader` value. */
|
|
1676
|
+
resetFormat: import_zod14.z.enum([
|
|
1677
|
+
"unix_timestamp",
|
|
1678
|
+
"unix_timestamp_in_ms",
|
|
1679
|
+
"iso_8601",
|
|
1680
|
+
"iso_8601_duration_openai_variant"
|
|
1681
|
+
]).default("unix_timestamp")
|
|
1636
1682
|
});
|
|
1637
1683
|
var FetchRetryBackoffStrategySchema = RetryOptionsSchema.extend({
|
|
1638
1684
|
/** The `backoff` strategy retries the request with an exponential backoff. */
|
|
1639
|
-
strategy: import_zod14.z.literal("backoff")
|
|
1685
|
+
strategy: import_zod14.z.literal("backoff"),
|
|
1686
|
+
/** The event filter to use to determine if the request should be retried. */
|
|
1687
|
+
bodyFilter: EventFilterSchema.optional()
|
|
1640
1688
|
});
|
|
1641
1689
|
var FetchRetryStrategySchema = import_zod14.z.discriminatedUnion("strategy", [
|
|
1642
1690
|
FetchRetryHeadersStrategySchema,
|
|
@@ -1667,6 +1715,14 @@ var FetchOperationSchema = import_zod14.z.object({
|
|
|
1667
1715
|
retry: import_zod14.z.record(FetchRetryStrategySchema).optional(),
|
|
1668
1716
|
timeout: FetchTimeoutOptionsSchema.optional()
|
|
1669
1717
|
});
|
|
1718
|
+
var FetchPollOperationSchema = import_zod14.z.object({
|
|
1719
|
+
url: import_zod14.z.string(),
|
|
1720
|
+
interval: import_zod14.z.number().int().positive().min(10).max(600).default(10),
|
|
1721
|
+
timeout: import_zod14.z.number().int().positive().min(30).max(3600).default(600),
|
|
1722
|
+
responseFilter: ResponseFilterSchema,
|
|
1723
|
+
requestInit: FetchRequestInitSchema.optional(),
|
|
1724
|
+
requestTimeout: FetchTimeoutOptionsSchema.optional()
|
|
1725
|
+
});
|
|
1670
1726
|
|
|
1671
1727
|
// src/schemas/events.ts
|
|
1672
1728
|
var import_zod15 = require("zod");
|
|
@@ -1748,6 +1804,73 @@ function calculateRetryAt(retryOptions, attempts) {
|
|
|
1748
1804
|
return new Date(Date.now() + timeoutInMs);
|
|
1749
1805
|
}
|
|
1750
1806
|
__name(calculateRetryAt, "calculateRetryAt");
|
|
1807
|
+
function calculateResetAt(resets, format, now = /* @__PURE__ */ new Date()) {
|
|
1808
|
+
if (!resets)
|
|
1809
|
+
return;
|
|
1810
|
+
switch (format) {
|
|
1811
|
+
case "iso_8601_duration_openai_variant": {
|
|
1812
|
+
return calculateISO8601DurationOpenAIVariantResetAt(resets, now);
|
|
1813
|
+
}
|
|
1814
|
+
case "iso_8601": {
|
|
1815
|
+
return calculateISO8601ResetAt(resets, now);
|
|
1816
|
+
}
|
|
1817
|
+
case "unix_timestamp": {
|
|
1818
|
+
return calculateUnixTimestampResetAt(resets, now);
|
|
1819
|
+
}
|
|
1820
|
+
case "unix_timestamp_in_ms": {
|
|
1821
|
+
return calculateUnixTimestampInMsResetAt(resets, now);
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
__name(calculateResetAt, "calculateResetAt");
|
|
1826
|
+
function calculateUnixTimestampResetAt(resets, now = /* @__PURE__ */ new Date()) {
|
|
1827
|
+
if (!resets)
|
|
1828
|
+
return void 0;
|
|
1829
|
+
const resetAt = parseInt(resets, 10);
|
|
1830
|
+
if (isNaN(resetAt))
|
|
1831
|
+
return void 0;
|
|
1832
|
+
return new Date(resetAt * 1e3);
|
|
1833
|
+
}
|
|
1834
|
+
__name(calculateUnixTimestampResetAt, "calculateUnixTimestampResetAt");
|
|
1835
|
+
function calculateUnixTimestampInMsResetAt(resets, now = /* @__PURE__ */ new Date()) {
|
|
1836
|
+
if (!resets)
|
|
1837
|
+
return void 0;
|
|
1838
|
+
const resetAt = parseInt(resets, 10);
|
|
1839
|
+
if (isNaN(resetAt))
|
|
1840
|
+
return void 0;
|
|
1841
|
+
return new Date(resetAt);
|
|
1842
|
+
}
|
|
1843
|
+
__name(calculateUnixTimestampInMsResetAt, "calculateUnixTimestampInMsResetAt");
|
|
1844
|
+
function calculateISO8601ResetAt(resets, now = /* @__PURE__ */ new Date()) {
|
|
1845
|
+
if (!resets)
|
|
1846
|
+
return void 0;
|
|
1847
|
+
const resetAt = new Date(resets);
|
|
1848
|
+
if (isNaN(resetAt.getTime()))
|
|
1849
|
+
return void 0;
|
|
1850
|
+
return resetAt;
|
|
1851
|
+
}
|
|
1852
|
+
__name(calculateISO8601ResetAt, "calculateISO8601ResetAt");
|
|
1853
|
+
function calculateISO8601DurationOpenAIVariantResetAt(resets, now = /* @__PURE__ */ new Date()) {
|
|
1854
|
+
if (!resets)
|
|
1855
|
+
return void 0;
|
|
1856
|
+
const pattern = /^(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+(?:\.\d+)?)s)?(?:(\d+)ms)?$/;
|
|
1857
|
+
const match = resets.match(pattern);
|
|
1858
|
+
if (!match)
|
|
1859
|
+
return void 0;
|
|
1860
|
+
const days = parseInt(match[1], 10) || 0;
|
|
1861
|
+
const hours = parseInt(match[2], 10) || 0;
|
|
1862
|
+
const minutes = parseInt(match[3], 10) || 0;
|
|
1863
|
+
const seconds = parseFloat(match[4]) || 0;
|
|
1864
|
+
const milliseconds = parseInt(match[5], 10) || 0;
|
|
1865
|
+
const resetAt = new Date(now);
|
|
1866
|
+
resetAt.setDate(resetAt.getDate() + days);
|
|
1867
|
+
resetAt.setHours(resetAt.getHours() + hours);
|
|
1868
|
+
resetAt.setMinutes(resetAt.getMinutes() + minutes);
|
|
1869
|
+
resetAt.setSeconds(resetAt.getSeconds() + Math.floor(seconds));
|
|
1870
|
+
resetAt.setMilliseconds(resetAt.getMilliseconds() + (seconds - Math.floor(seconds)) * 1e3 + milliseconds);
|
|
1871
|
+
return resetAt;
|
|
1872
|
+
}
|
|
1873
|
+
__name(calculateISO8601DurationOpenAIVariantResetAt, "calculateISO8601DurationOpenAIVariantResetAt");
|
|
1751
1874
|
|
|
1752
1875
|
// src/replacements.ts
|
|
1753
1876
|
var currentDate = {
|
|
@@ -1966,6 +2089,39 @@ async function requestFilterMatches(request, filter) {
|
|
|
1966
2089
|
return true;
|
|
1967
2090
|
}
|
|
1968
2091
|
__name(requestFilterMatches, "requestFilterMatches");
|
|
2092
|
+
async function responseFilterMatches(response, filter) {
|
|
2093
|
+
if (filter.headers && !eventFilterMatches(response.headers, filter.headers)) {
|
|
2094
|
+
return {
|
|
2095
|
+
match: false
|
|
2096
|
+
};
|
|
2097
|
+
}
|
|
2098
|
+
try {
|
|
2099
|
+
const json = await response.json();
|
|
2100
|
+
if (filter.body && !eventFilterMatches(json, filter.body)) {
|
|
2101
|
+
return {
|
|
2102
|
+
match: false,
|
|
2103
|
+
body: json
|
|
2104
|
+
};
|
|
2105
|
+
} else {
|
|
2106
|
+
return {
|
|
2107
|
+
match: true,
|
|
2108
|
+
body: json
|
|
2109
|
+
};
|
|
2110
|
+
}
|
|
2111
|
+
} catch (e) {
|
|
2112
|
+
if (filter.body) {
|
|
2113
|
+
return {
|
|
2114
|
+
match: false,
|
|
2115
|
+
body: void 0
|
|
2116
|
+
};
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
return {
|
|
2120
|
+
match: true,
|
|
2121
|
+
body: void 0
|
|
2122
|
+
};
|
|
2123
|
+
}
|
|
2124
|
+
__name(responseFilterMatches, "responseFilterMatches");
|
|
1969
2125
|
function requestMethodMatches(method, filter) {
|
|
1970
2126
|
if (!filter) {
|
|
1971
2127
|
return true;
|