@trigger.dev/sdk 3.0.0-beta.12 → 3.0.0-beta.13

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/v3/index.mjs CHANGED
@@ -1,49 +1,58 @@
1
1
  import { SpanKind, trace, context, SpanStatusCode } from '@opentelemetry/api';
2
- import { SEMATTRS_HTTP_STATUS_CODE, SEMATTRS_HTTP_METHOD, SEMATTRS_HTTP_URL, SEMATTRS_HTTP_HOST, SEMATTRS_HTTP_SCHEME, SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH, SEMATTRS_MESSAGING_OPERATION, SEMATTRS_MESSAGING_DESTINATION, SEMATTRS_MESSAGING_SYSTEM } from '@opentelemetry/semantic-conventions';
3
- import { TriggerTracer, runtime, SemanticInternalAttributes, accessoryAttributes, apiClientManager, defaultRetryOptions, conditionallyImportPacket, parsePacket, createErrorTaskError, calculateNextRetryDelay, defaultFetchRetryOptions, calculateResetAt, eventFilterMatches, flattenAttributes, taskContextManager } from '@trigger.dev/core/v3';
4
- export { logger } from '@trigger.dev/core/v3';
2
+ import { SEMATTRS_MESSAGING_OPERATION, SEMATTRS_MESSAGING_DESTINATION, SEMATTRS_MESSAGING_SYSTEM, SEMATTRS_HTTP_STATUS_CODE, SEMATTRS_HTTP_METHOD, SEMATTRS_HTTP_URL, SEMATTRS_HTTP_HOST, SEMATTRS_HTTP_SCHEME, SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH } from '@opentelemetry/semantic-conventions';
3
+ import { TriggerTracer, runtime, SemanticInternalAttributes, accessoryAttributes, apiClientManager, taskCatalog, stringifyIO, taskContextManager, defaultRetryOptions, conditionallyImportPacket, parsePacket, createErrorTaskError, calculateNextRetryDelay, defaultFetchRetryOptions, calculateResetAt, eventFilterMatches, flattenAttributes } from '@trigger.dev/core/v3';
4
+ export { APIError, AuthenticationError, BadRequestError, ConflictError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, UnprocessableEntityError, logger } from '@trigger.dev/core/v3';
5
5
  import { AsyncLocalStorage } from 'node:async_hooks';
6
6
 
7
7
  var __defProp = Object.defineProperty;
8
8
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
9
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
10
14
  var __publicField = (obj, key, value) => {
11
15
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
12
16
  return value;
13
17
  };
14
18
 
15
19
  // package.json
16
- var version = "3.0.0-beta.12";
20
+ var version = "3.0.0-beta.13";
17
21
  var tracer = new TriggerTracer({
18
22
  name: "@trigger.dev/sdk",
19
23
  version
20
24
  });
21
25
 
22
26
  // src/v3/shared.ts
27
+ function queue(options) {
28
+ return options;
29
+ }
30
+ __name(queue, "queue");
23
31
  function createTask(params) {
24
- const task2 = {
32
+ const task3 = {
33
+ id: params.id,
25
34
  trigger: async ({ payload, options }) => {
26
35
  const apiClient = apiClientManager.client;
27
36
  if (!apiClient) {
28
37
  throw apiClientMissingError();
29
38
  }
30
- const taskMetadata = runtime.getTaskMetadata(params.id);
39
+ const taskMetadata = taskCatalog.getTaskMetadata(params.id);
40
+ const payloadPacket = await stringifyIO(payload);
31
41
  const handle = await tracer.startActiveSpan(taskMetadata ? "Trigger" : `${params.id} trigger()`, async (span) => {
32
42
  const response = await apiClient.triggerTask(params.id, {
33
- payload,
43
+ payload: payloadPacket.data,
34
44
  options: {
35
45
  queue: params.queue,
36
46
  concurrencyKey: options?.concurrencyKey,
37
- test: taskContextManager.ctx?.run.isTest
47
+ test: taskContextManager.ctx?.run.isTest,
48
+ payloadType: payloadPacket.dataType,
49
+ idempotencyKey: options?.idempotencyKey
38
50
  }
39
51
  }, {
40
52
  spanParentAsLink: true
41
53
  });
42
- if (!response.ok) {
43
- throw new Error(response.error);
44
- }
45
- span.setAttribute("messaging.message.id", response.data.id);
46
- return response.data;
54
+ span.setAttribute("messaging.message.id", response.id);
55
+ return response;
47
56
  }, {
48
57
  kind: SpanKind.PRODUCER,
49
58
  attributes: {
@@ -71,25 +80,27 @@ function createTask(params) {
71
80
  if (!apiClient) {
72
81
  throw apiClientMissingError();
73
82
  }
74
- const taskMetadata = runtime.getTaskMetadata(params.id);
83
+ const taskMetadata = taskCatalog.getTaskMetadata(params.id);
75
84
  const response = await tracer.startActiveSpan(taskMetadata ? "Batch trigger" : `${params.id} batchTrigger()`, async (span) => {
76
85
  const response2 = await apiClient.batchTriggerTask(params.id, {
77
- items: items.map((item) => ({
78
- payload: item.payload,
79
- options: {
80
- queue: item.options?.queue ?? params.queue,
81
- concurrencyKey: item.options?.concurrencyKey,
82
- test: taskContextManager.ctx?.run.isTest
83
- }
86
+ items: await Promise.all(items.map(async (item) => {
87
+ const payloadPacket = await stringifyIO(item.payload);
88
+ return {
89
+ payload: payloadPacket.data,
90
+ options: {
91
+ queue: item.options?.queue ?? params.queue,
92
+ concurrencyKey: item.options?.concurrencyKey,
93
+ test: taskContextManager.ctx?.run.isTest,
94
+ payloadType: payloadPacket.dataType,
95
+ idempotencyKey: item.options?.idempotencyKey
96
+ }
97
+ };
84
98
  }))
85
99
  }, {
86
100
  spanParentAsLink: true
87
101
  });
88
- if (!response2.ok) {
89
- throw new Error(response2.error);
90
- }
91
- span.setAttribute("messaging.message.id", response2.data.batchId);
92
- return response2.data;
102
+ span.setAttribute("messaging.message.id", response2.batchId);
103
+ return response2;
93
104
  }, {
94
105
  kind: SpanKind.PRODUCER,
95
106
  attributes: {
@@ -122,24 +133,24 @@ function createTask(params) {
122
133
  if (!apiClient) {
123
134
  throw apiClientMissingError();
124
135
  }
125
- const taskMetadata = runtime.getTaskMetadata(params.id);
136
+ const taskMetadata = taskCatalog.getTaskMetadata(params.id);
137
+ const payloadPacket = await stringifyIO(payload);
126
138
  return await tracer.startActiveSpan(taskMetadata ? "Trigger" : `${params.id} triggerAndWait()`, async (span) => {
127
139
  const response = await apiClient.triggerTask(params.id, {
128
- payload,
140
+ payload: payloadPacket.data,
129
141
  options: {
130
142
  dependentAttempt: ctx.attempt.id,
131
143
  lockToVersion: taskContextManager.worker?.version,
132
144
  queue: params.queue,
133
145
  concurrencyKey: options?.concurrencyKey,
134
- test: taskContextManager.ctx?.run.isTest
146
+ test: taskContextManager.ctx?.run.isTest,
147
+ payloadType: payloadPacket.dataType,
148
+ idempotencyKey: options?.idempotencyKey
135
149
  }
136
150
  });
137
- if (!response.ok) {
138
- throw new Error(response.error);
139
- }
140
- span.setAttribute("messaging.message.id", response.data.id);
151
+ span.setAttribute("messaging.message.id", response.id);
141
152
  const result = await runtime.waitForTask({
142
- id: response.data.id,
153
+ id: response.id,
143
154
  ctx
144
155
  });
145
156
  const runResult = await handleTaskRunExecutionResult(result);
@@ -176,27 +187,29 @@ function createTask(params) {
176
187
  if (!apiClient) {
177
188
  throw apiClientMissingError();
178
189
  }
179
- const taskMetadata = runtime.getTaskMetadata(params.id);
190
+ const taskMetadata = taskCatalog.getTaskMetadata(params.id);
180
191
  return await tracer.startActiveSpan(taskMetadata ? "Batch trigger" : `${params.id} batchTriggerAndWait()`, async (span) => {
181
192
  const response = await apiClient.batchTriggerTask(params.id, {
182
- items: items.map((item) => ({
183
- payload: item.payload,
184
- options: {
185
- lockToVersion: taskContextManager.worker?.version,
186
- queue: item.options?.queue ?? params.queue,
187
- concurrencyKey: item.options?.concurrencyKey,
188
- test: taskContextManager.ctx?.run.isTest
189
- }
193
+ items: await Promise.all(items.map(async (item) => {
194
+ const payloadPacket = await stringifyIO(item.payload);
195
+ return {
196
+ payload: payloadPacket.data,
197
+ options: {
198
+ lockToVersion: taskContextManager.worker?.version,
199
+ queue: item.options?.queue ?? params.queue,
200
+ concurrencyKey: item.options?.concurrencyKey,
201
+ test: taskContextManager.ctx?.run.isTest,
202
+ payloadType: payloadPacket.dataType,
203
+ idempotencyKey: item.options?.idempotencyKey
204
+ }
205
+ };
190
206
  })),
191
207
  dependentAttempt: ctx.attempt.id
192
208
  });
193
- if (!response.ok) {
194
- throw new Error(response.error);
195
- }
196
- span.setAttribute("messaging.message.id", response.data.batchId);
209
+ span.setAttribute("messaging.message.id", response.batchId);
197
210
  const result = await runtime.waitForBatch({
198
- id: response.data.batchId,
199
- runs: response.data.runs,
211
+ id: response.batchId,
212
+ runs: response.runs,
200
213
  ctx
201
214
  });
202
215
  const runs2 = await handleBatchTaskRunExecutionResult(result.items);
@@ -227,27 +240,24 @@ function createTask(params) {
227
240
  });
228
241
  }
229
242
  };
230
- Object.defineProperty(task2, "__trigger", {
231
- value: {
232
- id: params.id,
233
- packageVersion: version,
234
- queue: params.queue,
235
- retry: params.retry ? {
236
- ...defaultRetryOptions,
237
- ...params.retry
238
- } : void 0,
239
- machine: params.machine,
240
- fns: {
241
- run: params.run,
242
- init: params.init,
243
- cleanup: params.cleanup,
244
- middleware: params.middleware,
245
- handleError: params.handleError
246
- }
247
- },
248
- enumerable: false
243
+ taskCatalog.registerTaskMetadata({
244
+ id: params.id,
245
+ packageVersion: version,
246
+ queue: params.queue,
247
+ retry: params.retry ? {
248
+ ...defaultRetryOptions,
249
+ ...params.retry
250
+ } : void 0,
251
+ machine: params.machine,
252
+ fns: {
253
+ run: params.run,
254
+ init: params.init,
255
+ cleanup: params.cleanup,
256
+ middleware: params.middleware,
257
+ handleError: params.handleError
258
+ }
249
259
  });
250
- return task2;
260
+ return task3;
251
261
  }
252
262
  __name(createTask, "createTask");
253
263
  async function handleBatchTaskRunExecutionResult(items) {
@@ -886,11 +896,7 @@ async function replayRun(runId) {
886
896
  if (!apiClient) {
887
897
  throw apiClientMissingError();
888
898
  }
889
- const response = await apiClient.replayRun(runId);
890
- if (!response.ok) {
891
- throw new Error(response.error);
892
- }
893
- return response.data;
899
+ return await apiClient.replayRun(runId);
894
900
  }
895
901
  __name(replayRun, "replayRun");
896
902
  async function cancelRun(runId) {
@@ -898,14 +904,87 @@ async function cancelRun(runId) {
898
904
  if (!apiClient) {
899
905
  throw apiClientMissingError();
900
906
  }
901
- const response = await apiClient.cancelRun(runId);
902
- if (!response.ok) {
903
- throw new Error(response.error);
904
- }
905
- return response.data;
907
+ return await apiClient.cancelRun(runId);
906
908
  }
907
909
  __name(cancelRun, "cancelRun");
908
910
 
909
- export { InMemoryCache, createCache, retry, runs, task, wait };
911
+ // src/v3/schedules/index.ts
912
+ var schedules_exports = {};
913
+ __export(schedules_exports, {
914
+ activate: () => activate,
915
+ create: () => create,
916
+ deactivate: () => deactivate,
917
+ del: () => del,
918
+ list: () => list,
919
+ retrieve: () => retrieve,
920
+ task: () => task2,
921
+ update: () => update
922
+ });
923
+ function task2(params) {
924
+ const task3 = createTask(params);
925
+ taskCatalog.updateTaskMetadata(task3.id, {
926
+ triggerSource: "schedule"
927
+ });
928
+ return task3;
929
+ }
930
+ __name(task2, "task");
931
+ async function create(options) {
932
+ const apiClient = apiClientManager.client;
933
+ if (!apiClient) {
934
+ throw apiClientMissingError();
935
+ }
936
+ return apiClient.createSchedule(options);
937
+ }
938
+ __name(create, "create");
939
+ async function retrieve(scheduleId) {
940
+ const apiClient = apiClientManager.client;
941
+ if (!apiClient) {
942
+ throw apiClientMissingError();
943
+ }
944
+ return apiClient.retrieveSchedule(scheduleId);
945
+ }
946
+ __name(retrieve, "retrieve");
947
+ async function update(scheduleId, options) {
948
+ const apiClient = apiClientManager.client;
949
+ if (!apiClient) {
950
+ throw apiClientMissingError();
951
+ }
952
+ return apiClient.updateSchedule(scheduleId, options);
953
+ }
954
+ __name(update, "update");
955
+ async function del(scheduleId) {
956
+ const apiClient = apiClientManager.client;
957
+ if (!apiClient) {
958
+ throw apiClientMissingError();
959
+ }
960
+ return apiClient.deleteSchedule(scheduleId);
961
+ }
962
+ __name(del, "del");
963
+ async function deactivate(scheduleId) {
964
+ const apiClient = apiClientManager.client;
965
+ if (!apiClient) {
966
+ throw apiClientMissingError();
967
+ }
968
+ return apiClient.deactivateSchedule(scheduleId);
969
+ }
970
+ __name(deactivate, "deactivate");
971
+ async function activate(scheduleId) {
972
+ const apiClient = apiClientManager.client;
973
+ if (!apiClient) {
974
+ throw apiClientMissingError();
975
+ }
976
+ return apiClient.activateSchedule(scheduleId);
977
+ }
978
+ __name(activate, "activate");
979
+ async function list(options) {
980
+ const apiClient = apiClientManager.client;
981
+ if (!apiClient) {
982
+ throw apiClientMissingError();
983
+ }
984
+ return apiClient.listSchedules(options);
985
+ }
986
+ __name(list, "list");
987
+
988
+ export { InMemoryCache, createCache, queue, retry, runs, schedules_exports as schedules, task, wait };
910
989
  //# sourceMappingURL=out.js.map
911
990
  //# sourceMappingURL=index.mjs.map