@trigger.dev/core 2.2.5 → 2.2.7

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.js CHANGED
@@ -66,13 +66,18 @@ __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,
72
74
  EventRuleSchema: () => EventRuleSchema,
73
75
  EventSpecificationSchema: () => EventSpecificationSchema,
76
+ ExecuteJobHeadersSchema: () => ExecuteJobHeadersSchema,
77
+ ExecuteJobRunMetadataSchema: () => ExecuteJobRunMetadataSchema,
74
78
  FailTaskBodyInputSchema: () => FailTaskBodyInputSchema,
75
79
  FetchOperationSchema: () => FetchOperationSchema,
80
+ FetchPollOperationSchema: () => FetchPollOperationSchema,
76
81
  FetchRequestInitSchema: () => FetchRequestInitSchema,
77
82
  FetchRetryBackoffStrategySchema: () => FetchRetryBackoffStrategySchema,
78
83
  FetchRetryHeadersStrategySchema: () => FetchRetryHeadersStrategySchema,
@@ -141,6 +146,7 @@ __export(src_exports, {
141
146
  RegisterTriggerSourceSchema: () => RegisterTriggerSourceSchema,
142
147
  RequestFilterSchema: () => RequestFilterSchema,
143
148
  RequestWithRawBodySchema: () => RequestWithRawBodySchema,
149
+ ResponseFilterSchema: () => ResponseFilterSchema,
144
150
  RetryOptionsSchema: () => RetryOptionsSchema,
145
151
  RunJobAutoYieldExecutionErrorSchema: () => RunJobAutoYieldExecutionErrorSchema,
146
152
  RunJobAutoYieldWithCompletedTaskExecutionErrorSchema: () => RunJobAutoYieldWithCompletedTaskExecutionErrorSchema,
@@ -169,6 +175,7 @@ __export(src_exports, {
169
175
  ScheduledPayloadSchema: () => ScheduledPayloadSchema,
170
176
  ScheduledTriggerMetadataSchema: () => ScheduledTriggerMetadataSchema,
171
177
  SchemaErrorSchema: () => SchemaErrorSchema,
178
+ SendBulkEventsBodySchema: () => SendBulkEventsBodySchema,
172
179
  SendEventBodySchema: () => SendEventBodySchema,
173
180
  SendEventOptionsSchema: () => SendEventOptionsSchema,
174
181
  SerializableJsonSchema: () => SerializableJsonSchema,
@@ -190,6 +197,7 @@ __export(src_exports, {
190
197
  ValidateResponseSchema: () => ValidateResponseSchema,
191
198
  ValidateSuccessResponseSchema: () => ValidateSuccessResponseSchema,
192
199
  addMissingVersionField: () => addMissingVersionField,
200
+ calculateResetAt: () => calculateResetAt,
193
201
  calculateRetryAt: () => calculateRetryAt,
194
202
  currentDate: () => currentDate,
195
203
  currentTimestampMilliseconds: () => currentTimestampMilliseconds,
@@ -199,6 +207,7 @@ __export(src_exports, {
199
207
  parseEndpointIndexStats: () => parseEndpointIndexStats,
200
208
  replacements: () => replacements,
201
209
  requestFilterMatches: () => requestFilterMatches,
210
+ responseFilterMatches: () => responseFilterMatches,
202
211
  stringPatternMatchers: () => stringPatternMatchers,
203
212
  supportsFeature: () => supportsFeature,
204
213
  urlWithSearchParams: () => urlWithSearchParams
@@ -213,18 +222,20 @@ var logLevels = [
213
222
  "info",
214
223
  "debug"
215
224
  ];
216
- var _name, _level, _filteredKeys, _jsonReplacer, _structuredLog, structuredLog_fn;
225
+ var _name, _level, _filteredKeys, _jsonReplacer, _additionalFields, _structuredLog, structuredLog_fn;
217
226
  var _Logger = class _Logger {
218
- constructor(name, level = "info", filteredKeys = [], jsonReplacer) {
227
+ constructor(name, level = "info", filteredKeys = [], jsonReplacer, additionalFields) {
219
228
  __privateAdd(this, _structuredLog);
220
229
  __privateAdd(this, _name, void 0);
221
230
  __privateAdd(this, _level, void 0);
222
231
  __privateAdd(this, _filteredKeys, []);
223
232
  __privateAdd(this, _jsonReplacer, void 0);
233
+ __privateAdd(this, _additionalFields, void 0);
224
234
  __privateSet(this, _name, name);
225
235
  __privateSet(this, _level, logLevels.indexOf(process.env.TRIGGER_LOG_LEVEL ?? level));
226
236
  __privateSet(this, _filteredKeys, filteredKeys);
227
- __privateSet(this, _jsonReplacer, jsonReplacer);
237
+ __privateSet(this, _jsonReplacer, createReplacer(jsonReplacer));
238
+ __privateSet(this, _additionalFields, additionalFields ?? (() => ({})));
228
239
  }
229
240
  // Return a new Logger instance with the same name and a new log level
230
241
  // but filter out the keys from the log messages (at any level)
@@ -264,16 +275,18 @@ _name = new WeakMap();
264
275
  _level = new WeakMap();
265
276
  _filteredKeys = new WeakMap();
266
277
  _jsonReplacer = new WeakMap();
278
+ _additionalFields = new WeakMap();
267
279
  _structuredLog = new WeakSet();
268
280
  structuredLog_fn = /* @__PURE__ */ __name(function(loggerFunction, message, level, ...args) {
269
281
  const structuredLog = {
270
282
  ...structureArgs(safeJsonClone(args), __privateGet(this, _filteredKeys)),
283
+ ...__privateGet(this, _additionalFields).call(this),
271
284
  timestamp: /* @__PURE__ */ new Date(),
272
285
  name: __privateGet(this, _name),
273
286
  message,
274
287
  level
275
288
  };
276
- loggerFunction(JSON.stringify(structuredLog, createReplacer(__privateGet(this, _jsonReplacer))));
289
+ loggerFunction(JSON.stringify(structuredLog, __privateGet(this, _jsonReplacer)));
277
290
  }, "#structuredLog");
278
291
  __name(_Logger, "Logger");
279
292
  var Logger = _Logger;
@@ -300,11 +313,14 @@ function safeJsonClone(obj) {
300
313
  try {
301
314
  return JSON.parse(JSON.stringify(obj, bigIntReplacer));
302
315
  } catch (e) {
303
- return obj;
316
+ return;
304
317
  }
305
318
  }
306
319
  __name(safeJsonClone, "safeJsonClone");
307
320
  function structureArgs(args, filteredKeys = []) {
321
+ if (!args) {
322
+ return;
323
+ }
308
324
  if (args.length === 0) {
309
325
  return;
310
326
  }
@@ -364,7 +380,7 @@ function getSizeInBytes(value) {
364
380
  __name(getSizeInBytes, "getSizeInBytes");
365
381
 
366
382
  // src/schemas/api.ts
367
- var import_ulid = require("ulid");
383
+ var import_ulidx = require("ulidx");
368
384
  var import_zod12 = require("zod");
369
385
 
370
386
  // src/schemas/addMissingVersionField.ts
@@ -533,7 +549,9 @@ var DisplayPropertySchema = import_zod5.z.object({
533
549
  /** The value of the property */
534
550
  text: import_zod5.z.string(),
535
551
  /** The URL to link to when the property is clicked */
536
- url: import_zod5.z.string().optional()
552
+ url: import_zod5.z.string().optional(),
553
+ /** The URL to a list of images to display next to the property */
554
+ imageUrl: import_zod5.z.array(import_zod5.z.string()).optional()
537
555
  });
538
556
  var DisplayPropertiesSchema = import_zod5.z.array(DisplayPropertySchema);
539
557
  var StyleSchema = import_zod5.z.object({
@@ -616,6 +634,7 @@ var TaskSchema = import_zod7.z.object({
616
634
  outputProperties: import_zod7.z.array(DisplayPropertySchema).optional().nullable(),
617
635
  params: DeserializedJsonSchema.optional().nullable(),
618
636
  output: DeserializedJsonSchema.optional().nullable(),
637
+ context: DeserializedJsonSchema.optional().nullable(),
619
638
  error: import_zod7.z.string().optional().nullable(),
620
639
  parentId: import_zod7.z.string().optional().nullable(),
621
640
  style: StyleSchema.optional().nullable(),
@@ -850,6 +869,12 @@ var RequestFilterSchema = import_zod11.z.object({
850
869
  */
851
870
  body: EventFilterSchema.optional()
852
871
  });
872
+ var ResponseFilterSchema = RequestFilterSchema.omit({
873
+ method: true,
874
+ query: true
875
+ }).extend({
876
+ status: import_zod11.z.array(import_zod11.z.number()).optional()
877
+ });
853
878
 
854
879
  // src/schemas/api.ts
855
880
  var UpdateTriggerSourceBodyV1Schema = import_zod12.z.object({
@@ -1116,6 +1141,13 @@ var EndpointHeadersSchema = import_zod12.z.object({
1116
1141
  "trigger-version": import_zod12.z.string().optional(),
1117
1142
  "trigger-sdk-version": import_zod12.z.string().optional()
1118
1143
  });
1144
+ var ExecuteJobRunMetadataSchema = import_zod12.z.object({
1145
+ successSubscription: import_zod12.z.boolean().optional(),
1146
+ failedSubscription: import_zod12.z.boolean().optional()
1147
+ });
1148
+ var ExecuteJobHeadersSchema = EndpointHeadersSchema.extend({
1149
+ "x-trigger-run-metadata": import_zod12.z.preprocess((val) => typeof val === "string" && JSON.parse(val), ExecuteJobRunMetadataSchema).optional()
1150
+ });
1119
1151
  var RawEventSchema = import_zod12.z.object({
1120
1152
  /** The `name` property must exactly match any subscriptions you want to
1121
1153
  trigger. */
@@ -1131,7 +1163,7 @@ var RawEventSchema = import_zod12.z.object({
1131
1163
  context: import_zod12.z.any().optional(),
1132
1164
  /** The `id` property uniquely identify this particular event. If unset it
1133
1165
  will be set automatically using `ulid`. */
1134
- id: import_zod12.z.string().default(() => (0, import_ulid.ulid)()),
1166
+ id: import_zod12.z.string().default(() => (0, import_ulidx.ulid)()),
1135
1167
  /** This is optional, it defaults to the current timestamp. Usually you would
1136
1168
  only set this if you have a timestamp that you wish to pass through, e.g.
1137
1169
  you receive a timestamp from a service and you want the same timestamp to
@@ -1188,6 +1220,10 @@ var SendEventBodySchema = import_zod12.z.object({
1188
1220
  event: RawEventSchema,
1189
1221
  options: SendEventOptionsSchema.optional()
1190
1222
  });
1223
+ var SendBulkEventsBodySchema = import_zod12.z.object({
1224
+ events: RawEventSchema.array(),
1225
+ options: SendEventOptionsSchema.optional()
1226
+ });
1191
1227
  var DeliverEventResponseSchema = import_zod12.z.object({
1192
1228
  deliveredAt: import_zod12.z.string().datetime()
1193
1229
  });
@@ -1433,9 +1469,11 @@ var RunTaskOptionsSchema = import_zod12.z.object({
1433
1469
  }).partial().optional(),
1434
1470
  /** Allows you to link the Integration connection in the logs. This is handled automatically in integrations. */
1435
1471
  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. */
1472
+ /** 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
1473
  operation: import_zod12.z.enum([
1438
- "fetch"
1474
+ "fetch",
1475
+ "fetch-response",
1476
+ "fetch-poll"
1439
1477
  ]).optional(),
1440
1478
  /** 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
1479
  noop: import_zod12.z.boolean().default(false),
@@ -1564,6 +1602,18 @@ var InvokeOptionsSchema = import_zod12.z.object({
1564
1602
  context: import_zod12.z.any().optional(),
1565
1603
  callbackUrl: import_zod12.z.string().optional()
1566
1604
  });
1605
+ var EphemeralEventDispatcherRequestBodySchema = import_zod12.z.object({
1606
+ url: import_zod12.z.string(),
1607
+ name: import_zod12.z.string().or(import_zod12.z.array(import_zod12.z.string())),
1608
+ source: import_zod12.z.string().optional(),
1609
+ filter: EventFilterSchema.optional(),
1610
+ contextFilter: EventFilterSchema.optional(),
1611
+ accountId: import_zod12.z.string().optional(),
1612
+ timeoutInSeconds: import_zod12.z.number().int().positive().min(10).max(60 * 60 * 24 * 365).default(3600)
1613
+ });
1614
+ var EphemeralEventDispatcherResponseBodySchema = import_zod12.z.object({
1615
+ id: import_zod12.z.string()
1616
+ });
1567
1617
 
1568
1618
  // src/schemas/notifications.ts
1569
1619
  var import_zod13 = require("zod");
@@ -1632,11 +1682,22 @@ var FetchRetryHeadersStrategySchema = import_zod14.z.object({
1632
1682
  /** The header to use to determine the number of remaining retries. */
1633
1683
  remainingHeader: import_zod14.z.string(),
1634
1684
  /** The header to use to determine the time when the number of remaining retries will be reset. */
1635
- resetHeader: import_zod14.z.string()
1685
+ resetHeader: import_zod14.z.string(),
1686
+ /** The event filter to use to determine if the request should be retried. */
1687
+ bodyFilter: EventFilterSchema.optional(),
1688
+ /** The format of the `resetHeader` value. */
1689
+ resetFormat: import_zod14.z.enum([
1690
+ "unix_timestamp",
1691
+ "unix_timestamp_in_ms",
1692
+ "iso_8601",
1693
+ "iso_8601_duration_openai_variant"
1694
+ ]).default("unix_timestamp")
1636
1695
  });
1637
1696
  var FetchRetryBackoffStrategySchema = RetryOptionsSchema.extend({
1638
1697
  /** The `backoff` strategy retries the request with an exponential backoff. */
1639
- strategy: import_zod14.z.literal("backoff")
1698
+ strategy: import_zod14.z.literal("backoff"),
1699
+ /** The event filter to use to determine if the request should be retried. */
1700
+ bodyFilter: EventFilterSchema.optional()
1640
1701
  });
1641
1702
  var FetchRetryStrategySchema = import_zod14.z.discriminatedUnion("strategy", [
1642
1703
  FetchRetryHeadersStrategySchema,
@@ -1667,6 +1728,14 @@ var FetchOperationSchema = import_zod14.z.object({
1667
1728
  retry: import_zod14.z.record(FetchRetryStrategySchema).optional(),
1668
1729
  timeout: FetchTimeoutOptionsSchema.optional()
1669
1730
  });
1731
+ var FetchPollOperationSchema = import_zod14.z.object({
1732
+ url: import_zod14.z.string(),
1733
+ interval: import_zod14.z.number().int().positive().min(10).max(600).default(10),
1734
+ timeout: import_zod14.z.number().int().positive().min(30).max(3600).default(600),
1735
+ responseFilter: ResponseFilterSchema,
1736
+ requestInit: FetchRequestInitSchema.optional(),
1737
+ requestTimeout: FetchTimeoutOptionsSchema.optional()
1738
+ });
1670
1739
 
1671
1740
  // src/schemas/events.ts
1672
1741
  var import_zod15 = require("zod");
@@ -1748,6 +1817,73 @@ function calculateRetryAt(retryOptions, attempts) {
1748
1817
  return new Date(Date.now() + timeoutInMs);
1749
1818
  }
1750
1819
  __name(calculateRetryAt, "calculateRetryAt");
1820
+ function calculateResetAt(resets, format, now = /* @__PURE__ */ new Date()) {
1821
+ if (!resets)
1822
+ return;
1823
+ switch (format) {
1824
+ case "iso_8601_duration_openai_variant": {
1825
+ return calculateISO8601DurationOpenAIVariantResetAt(resets, now);
1826
+ }
1827
+ case "iso_8601": {
1828
+ return calculateISO8601ResetAt(resets, now);
1829
+ }
1830
+ case "unix_timestamp": {
1831
+ return calculateUnixTimestampResetAt(resets, now);
1832
+ }
1833
+ case "unix_timestamp_in_ms": {
1834
+ return calculateUnixTimestampInMsResetAt(resets, now);
1835
+ }
1836
+ }
1837
+ }
1838
+ __name(calculateResetAt, "calculateResetAt");
1839
+ function calculateUnixTimestampResetAt(resets, now = /* @__PURE__ */ new Date()) {
1840
+ if (!resets)
1841
+ return void 0;
1842
+ const resetAt = parseInt(resets, 10);
1843
+ if (isNaN(resetAt))
1844
+ return void 0;
1845
+ return new Date(resetAt * 1e3);
1846
+ }
1847
+ __name(calculateUnixTimestampResetAt, "calculateUnixTimestampResetAt");
1848
+ function calculateUnixTimestampInMsResetAt(resets, now = /* @__PURE__ */ new Date()) {
1849
+ if (!resets)
1850
+ return void 0;
1851
+ const resetAt = parseInt(resets, 10);
1852
+ if (isNaN(resetAt))
1853
+ return void 0;
1854
+ return new Date(resetAt);
1855
+ }
1856
+ __name(calculateUnixTimestampInMsResetAt, "calculateUnixTimestampInMsResetAt");
1857
+ function calculateISO8601ResetAt(resets, now = /* @__PURE__ */ new Date()) {
1858
+ if (!resets)
1859
+ return void 0;
1860
+ const resetAt = new Date(resets);
1861
+ if (isNaN(resetAt.getTime()))
1862
+ return void 0;
1863
+ return resetAt;
1864
+ }
1865
+ __name(calculateISO8601ResetAt, "calculateISO8601ResetAt");
1866
+ function calculateISO8601DurationOpenAIVariantResetAt(resets, now = /* @__PURE__ */ new Date()) {
1867
+ if (!resets)
1868
+ return void 0;
1869
+ const pattern = /^(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+(?:\.\d+)?)s)?(?:(\d+)ms)?$/;
1870
+ const match = resets.match(pattern);
1871
+ if (!match)
1872
+ return void 0;
1873
+ const days = parseInt(match[1], 10) || 0;
1874
+ const hours = parseInt(match[2], 10) || 0;
1875
+ const minutes = parseInt(match[3], 10) || 0;
1876
+ const seconds = parseFloat(match[4]) || 0;
1877
+ const milliseconds = parseInt(match[5], 10) || 0;
1878
+ const resetAt = new Date(now);
1879
+ resetAt.setDate(resetAt.getDate() + days);
1880
+ resetAt.setHours(resetAt.getHours() + hours);
1881
+ resetAt.setMinutes(resetAt.getMinutes() + minutes);
1882
+ resetAt.setSeconds(resetAt.getSeconds() + Math.floor(seconds));
1883
+ resetAt.setMilliseconds(resetAt.getMilliseconds() + (seconds - Math.floor(seconds)) * 1e3 + milliseconds);
1884
+ return resetAt;
1885
+ }
1886
+ __name(calculateISO8601DurationOpenAIVariantResetAt, "calculateISO8601DurationOpenAIVariantResetAt");
1751
1887
 
1752
1888
  // src/replacements.ts
1753
1889
  var currentDate = {
@@ -1966,6 +2102,39 @@ async function requestFilterMatches(request, filter) {
1966
2102
  return true;
1967
2103
  }
1968
2104
  __name(requestFilterMatches, "requestFilterMatches");
2105
+ async function responseFilterMatches(response, filter) {
2106
+ if (filter.headers && !eventFilterMatches(response.headers, filter.headers)) {
2107
+ return {
2108
+ match: false
2109
+ };
2110
+ }
2111
+ try {
2112
+ const json = await response.json();
2113
+ if (filter.body && !eventFilterMatches(json, filter.body)) {
2114
+ return {
2115
+ match: false,
2116
+ body: json
2117
+ };
2118
+ } else {
2119
+ return {
2120
+ match: true,
2121
+ body: json
2122
+ };
2123
+ }
2124
+ } catch (e) {
2125
+ if (filter.body) {
2126
+ return {
2127
+ match: false,
2128
+ body: void 0
2129
+ };
2130
+ }
2131
+ }
2132
+ return {
2133
+ match: true,
2134
+ body: void 0
2135
+ };
2136
+ }
2137
+ __name(responseFilterMatches, "responseFilterMatches");
1969
2138
  function requestMethodMatches(method, filter) {
1970
2139
  if (!filter) {
1971
2140
  return true;