@trigger.dev/sdk 0.0.0-prerelease-20231208101523 → 0.0.0-prerelease-20240219135254

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.mts CHANGED
@@ -728,6 +728,10 @@ declare class ApiClient {
728
728
  invokeJob(jobId: string, payload: any, options?: InvokeOptions): Promise<{
729
729
  id: string;
730
730
  }>;
731
+ cancelRunsForJob(jobId: string): Promise<{
732
+ cancelledRunIds: string[];
733
+ failedToCancelRunIds: string[];
734
+ }>;
731
735
  createEphemeralEventDispatcher(payload: EphemeralEventDispatcherRequestBody): Promise<{
732
736
  id: string;
733
737
  }>;
@@ -895,7 +899,7 @@ type PreprocessResults = {
895
899
  properties: DisplayProperty[];
896
900
  };
897
901
  type TriggerEventType<TTrigger extends Trigger<any>> = TTrigger extends Trigger<infer TEventSpec> ? ReturnType<TEventSpec["parsePayload"]> : never;
898
- type TriggerInvokeType<TTrigger extends Trigger<any>> = TTrigger extends Trigger<infer TEventSpec> ? TEventSpec["parseInvokePayload"] extends (payload: unknown) => infer TInvoke ? TInvoke : any : never;
902
+ type TriggerInvokeType<TTrigger extends Trigger<any>> = TTrigger extends Trigger<EventSpecification<any, infer TInvoke>> ? TInvoke : any;
899
903
  type VerifyResult = {
900
904
  success: true;
901
905
  } | {
@@ -1855,6 +1859,10 @@ declare class TriggerClient {
1855
1859
  invokeJob(jobId: string, payload: any, options?: InvokeOptions): Promise<{
1856
1860
  id: string;
1857
1861
  }>;
1862
+ cancelRunsForJob(jobId: string): Promise<{
1863
+ cancelledRunIds: string[];
1864
+ failedToCancelRunIds: string[];
1865
+ }>;
1858
1866
  createEphemeralEventDispatcher(payload: EphemeralEventDispatcherRequestBody): Promise<{
1859
1867
  id: string;
1860
1868
  }>;
package/dist/index.d.ts CHANGED
@@ -728,6 +728,10 @@ declare class ApiClient {
728
728
  invokeJob(jobId: string, payload: any, options?: InvokeOptions): Promise<{
729
729
  id: string;
730
730
  }>;
731
+ cancelRunsForJob(jobId: string): Promise<{
732
+ cancelledRunIds: string[];
733
+ failedToCancelRunIds: string[];
734
+ }>;
731
735
  createEphemeralEventDispatcher(payload: EphemeralEventDispatcherRequestBody): Promise<{
732
736
  id: string;
733
737
  }>;
@@ -895,7 +899,7 @@ type PreprocessResults = {
895
899
  properties: DisplayProperty[];
896
900
  };
897
901
  type TriggerEventType<TTrigger extends Trigger<any>> = TTrigger extends Trigger<infer TEventSpec> ? ReturnType<TEventSpec["parsePayload"]> : never;
898
- type TriggerInvokeType<TTrigger extends Trigger<any>> = TTrigger extends Trigger<infer TEventSpec> ? TEventSpec["parseInvokePayload"] extends (payload: unknown) => infer TInvoke ? TInvoke : any : never;
902
+ type TriggerInvokeType<TTrigger extends Trigger<any>> = TTrigger extends Trigger<EventSpecification<any, infer TInvoke>> ? TInvoke : any;
899
903
  type VerifyResult = {
900
904
  success: true;
901
905
  } | {
@@ -1855,6 +1859,10 @@ declare class TriggerClient {
1855
1859
  invokeJob(jobId: string, payload: any, options?: InvokeOptions): Promise<{
1856
1860
  id: string;
1857
1861
  }>;
1862
+ cancelRunsForJob(jobId: string): Promise<{
1863
+ cancelledRunIds: string[];
1864
+ failedToCancelRunIds: string[];
1865
+ }>;
1858
1866
  createEphemeralEventDispatcher(payload: EphemeralEventDispatcherRequestBody): Promise<{
1859
1867
  id: string;
1860
1868
  }>;
package/dist/index.js CHANGED
@@ -178,7 +178,7 @@ var _Job = class _Job {
178
178
  if (runStore) {
179
179
  throw new Error("Cannot invoke a job from within a run without a cacheKey.");
180
180
  }
181
- return await triggerClient.invokeJob(this.id, param1, param3);
181
+ return await triggerClient.invokeJob(this.id, param1, param2);
182
182
  }
183
183
  async invokeAndWaitForCompletion(cacheKey, payload, timeoutInSeconds = 60 * 60, options = {}) {
184
184
  const triggerClient = this.client;
@@ -266,7 +266,7 @@ __name(_Job, "Job");
266
266
  var Job = _Job;
267
267
 
268
268
  // package.json
269
- var version = "0.0.0-prerelease-20231208101523";
269
+ var version = "0.0.0-prerelease-20240219135254";
270
270
 
271
271
  // src/errors.ts
272
272
  var _ResumeWithTaskError = class _ResumeWithTaskError {
@@ -643,6 +643,13 @@ var _IO = class _IO {
643
643
  get logger() {
644
644
  return new IOLogger(async (level, message, data) => {
645
645
  let logLevel = "info";
646
+ if (data instanceof Error) {
647
+ data = {
648
+ name: data.name,
649
+ message: data.message,
650
+ stack: data.stack
651
+ };
652
+ }
646
653
  if (coreBackend.Logger.satisfiesLogLevel(logLevel, this._jobLogLevel)) {
647
654
  await this.runTask([
648
655
  message,
@@ -1387,7 +1394,6 @@ var _IO = class _IO {
1387
1394
  * @returns A Promise that resolves with the returned value of the callback.
1388
1395
  */
1389
1396
  async runTask(cacheKey, callback, options, onError) {
1390
- __privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "start_task", 500);
1391
1397
  const parentId = this._taskStorage.getStore()?.taskId;
1392
1398
  if (parentId) {
1393
1399
  this._logger.debug("Using parent task", {
@@ -1396,6 +1402,10 @@ var _IO = class _IO {
1396
1402
  options
1397
1403
  });
1398
1404
  }
1405
+ const isSubtaskNoop = options?.noop === true && parentId !== void 0;
1406
+ if (!isSubtaskNoop) {
1407
+ __privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "start_task", 500);
1408
+ }
1399
1409
  const idempotencyKey = await generateIdempotencyKey([
1400
1410
  this._id,
1401
1411
  parentId ?? "",
@@ -1553,6 +1563,7 @@ var _IO = class _IO {
1553
1563
  await this._apiClient.failTask(this._id, task.id, {
1554
1564
  error: error.cause.output
1555
1565
  });
1566
+ throw error;
1556
1567
  }
1557
1568
  const parsedError = core.ErrorWithStackSchema.safeParse(error);
1558
1569
  if (options?.retry && !skipRetrying) {
@@ -2103,7 +2114,7 @@ var _ApiClient = class _ApiClient {
2103
2114
  __privateGet(this, _logger).debug("Getting Event", {
2104
2115
  eventId
2105
2116
  });
2106
- return await zodfetch(core.GetEventSchema, `${__privateGet(this, _apiUrl)}/api/v1/events/${eventId}`, {
2117
+ return await zodfetch(core.GetEventSchema, `${__privateGet(this, _apiUrl)}/api/v2/events/${eventId}`, {
2107
2118
  method: "GET",
2108
2119
  headers: {
2109
2120
  Authorization: `Bearer ${apiKey}`
@@ -2115,7 +2126,7 @@ var _ApiClient = class _ApiClient {
2115
2126
  __privateGet(this, _logger).debug("Getting Run", {
2116
2127
  runId
2117
2128
  });
2118
- return await zodfetch(core.GetRunSchema, core.urlWithSearchParams(`${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}`, options), {
2129
+ return await zodfetch(core.GetRunSchema, core.urlWithSearchParams(`${__privateGet(this, _apiUrl)}/api/v2/runs/${runId}`, options), {
2119
2130
  method: "GET",
2120
2131
  headers: {
2121
2132
  Authorization: `Bearer ${apiKey}`
@@ -2140,7 +2151,7 @@ var _ApiClient = class _ApiClient {
2140
2151
  __privateGet(this, _logger).debug("Getting Run statuses", {
2141
2152
  runId
2142
2153
  });
2143
- return await zodfetch(core.GetRunStatusesSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/statuses`, {
2154
+ return await zodfetch(core.GetRunStatusesSchema, `${__privateGet(this, _apiUrl)}/api/v2/runs/${runId}/statuses`, {
2144
2155
  method: "GET",
2145
2156
  headers: {
2146
2157
  Authorization: `Bearer ${apiKey}`
@@ -2184,6 +2195,19 @@ var _ApiClient = class _ApiClient {
2184
2195
  body: JSON.stringify(body)
2185
2196
  });
2186
2197
  }
2198
+ async cancelRunsForJob(jobId) {
2199
+ const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
2200
+ __privateGet(this, _logger).debug("Cancelling Runs for Job", {
2201
+ jobId
2202
+ });
2203
+ return await zodfetch(core.CancelRunsForJobSchema, `${__privateGet(this, _apiUrl)}/api/v1/jobs/${jobId}/cancel-runs`, {
2204
+ method: "POST",
2205
+ headers: {
2206
+ "Content-Type": "application/json",
2207
+ Authorization: `Bearer ${apiKey}`
2208
+ }
2209
+ });
2210
+ }
2187
2211
  async createEphemeralEventDispatcher(payload) {
2188
2212
  const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
2189
2213
  __privateGet(this, _logger).debug("Creating ephemeral event dispatcher", {
@@ -2716,6 +2740,7 @@ function eventTrigger(options) {
2716
2740
  return new EventTrigger({
2717
2741
  name: options.name,
2718
2742
  filter: options.filter,
2743
+ source: options.source,
2719
2744
  event: {
2720
2745
  name: options.name,
2721
2746
  title: "Event",
@@ -2802,7 +2827,7 @@ var _CronTrigger = class _CronTrigger {
2802
2827
  get event() {
2803
2828
  const humanReadable = cronstrue__default.default.toString(this.options.cron, {
2804
2829
  throwExceptionOnParseError: false
2805
- });
2830
+ }).concat(" (UTC)");
2806
2831
  return {
2807
2832
  name: "trigger.scheduled",
2808
2833
  title: "Cron Schedule",
@@ -3390,7 +3415,7 @@ var _TriggerClient = class _TriggerClient {
3390
3415
  }
3391
3416
  defineJob(options) {
3392
3417
  const existingRegisteredJob = __privateGet(this, _registeredJobs)[options.id];
3393
- if (existingRegisteredJob) {
3418
+ if (existingRegisteredJob && options.__internal !== true) {
3394
3419
  console.warn(`[@trigger.dev/sdk] Warning: The Job "${existingRegisteredJob.id}" you're attempting to define has already been defined. Please assign a different ID to the job.`);
3395
3420
  }
3396
3421
  const job = new Job(options);
@@ -3684,6 +3709,9 @@ var _TriggerClient = class _TriggerClient {
3684
3709
  async invokeJob(jobId, payload, options) {
3685
3710
  return __privateGet(this, _client2).invokeJob(jobId, payload, options);
3686
3711
  }
3712
+ async cancelRunsForJob(jobId) {
3713
+ return __privateGet(this, _client2).cancelRunsForJob(jobId);
3714
+ }
3687
3715
  async createEphemeralEventDispatcher(payload) {
3688
3716
  return __privateGet(this, _client2).createEphemeralEventDispatcher(payload);
3689
3717
  }