@trigger.dev/sdk 3.0.0-beta.7 → 3.0.0

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.
Files changed (279) hide show
  1. package/dist/commonjs/apiClient.d.ts +737 -0
  2. package/dist/commonjs/apiClient.js +692 -0
  3. package/dist/commonjs/apiClient.js.map +1 -0
  4. package/dist/commonjs/concurrencyLimit.d.ts +10 -0
  5. package/dist/commonjs/concurrencyLimit.js +17 -0
  6. package/dist/commonjs/concurrencyLimit.js.map +1 -0
  7. package/dist/commonjs/errors.d.ts +66 -0
  8. package/dist/commonjs/errors.js +109 -0
  9. package/dist/commonjs/errors.js.map +1 -0
  10. package/dist/commonjs/httpEndpoint.d.ts +87 -0
  11. package/dist/commonjs/httpEndpoint.js +130 -0
  12. package/dist/commonjs/httpEndpoint.js.map +1 -0
  13. package/dist/commonjs/index.d.ts +23 -0
  14. package/dist/commonjs/index.js +55 -0
  15. package/dist/commonjs/index.js.map +1 -0
  16. package/dist/commonjs/integrations.d.ts +11 -0
  17. package/dist/commonjs/integrations.js +3 -0
  18. package/dist/commonjs/integrations.js.map +1 -0
  19. package/dist/commonjs/io.d.ts +453 -0
  20. package/dist/commonjs/io.js +1165 -0
  21. package/dist/commonjs/io.js.map +1 -0
  22. package/dist/commonjs/ioWithIntegrations.d.ts +4 -0
  23. package/dist/commonjs/ioWithIntegrations.js +32 -0
  24. package/dist/commonjs/ioWithIntegrations.js.map +1 -0
  25. package/dist/commonjs/job.d.ts +96 -0
  26. package/dist/commonjs/job.js +210 -0
  27. package/dist/commonjs/job.js.map +1 -0
  28. package/dist/commonjs/package.json +3 -0
  29. package/dist/commonjs/retry.d.ts +20 -0
  30. package/dist/commonjs/retry.js +22 -0
  31. package/dist/commonjs/retry.js.map +1 -0
  32. package/dist/commonjs/runLocalStorage.d.ts +8 -0
  33. package/dist/commonjs/runLocalStorage.js +6 -0
  34. package/dist/commonjs/runLocalStorage.js.map +1 -0
  35. package/dist/commonjs/security.d.ts +18 -0
  36. package/dist/commonjs/security.js +41 -0
  37. package/dist/commonjs/security.js.map +1 -0
  38. package/dist/commonjs/status.d.ts +19 -0
  39. package/dist/commonjs/status.js +38 -0
  40. package/dist/commonjs/status.js.map +1 -0
  41. package/dist/commonjs/store/keyValueStore.d.ts +17 -0
  42. package/dist/commonjs/store/keyValueStore.js +138 -0
  43. package/dist/commonjs/store/keyValueStore.js.map +1 -0
  44. package/dist/commonjs/store/keyValueStoreClient.d.ts +19 -0
  45. package/dist/commonjs/store/keyValueStoreClient.js +65 -0
  46. package/dist/commonjs/store/keyValueStoreClient.js.map +1 -0
  47. package/dist/commonjs/triggerClient.d.ts +300 -0
  48. package/dist/commonjs/triggerClient.js +1366 -0
  49. package/dist/commonjs/triggerClient.js.map +1 -0
  50. package/dist/commonjs/triggers/dynamic.d.ts +56 -0
  51. package/dist/commonjs/triggers/dynamic.js +97 -0
  52. package/dist/commonjs/triggers/dynamic.js.map +1 -0
  53. package/dist/commonjs/triggers/eventTrigger.d.ts +58 -0
  54. package/dist/commonjs/triggers/eventTrigger.js +69 -0
  55. package/dist/commonjs/triggers/eventTrigger.js.map +1 -0
  56. package/dist/commonjs/triggers/externalSource.d.ts +148 -0
  57. package/dist/commonjs/triggers/externalSource.js +106 -0
  58. package/dist/commonjs/triggers/externalSource.js.map +1 -0
  59. package/dist/commonjs/triggers/invokeTrigger.d.ts +39 -0
  60. package/dist/commonjs/triggers/invokeTrigger.js +58 -0
  61. package/dist/commonjs/triggers/invokeTrigger.js.map +1 -0
  62. package/dist/commonjs/triggers/notifications.d.ts +111 -0
  63. package/dist/commonjs/triggers/notifications.js +101 -0
  64. package/dist/commonjs/triggers/notifications.js.map +1 -0
  65. package/dist/commonjs/triggers/scheduled.d.ts +145 -0
  66. package/dist/commonjs/triggers/scheduled.js +208 -0
  67. package/dist/commonjs/triggers/scheduled.js.map +1 -0
  68. package/dist/commonjs/triggers/webhook.d.ts +143 -0
  69. package/dist/commonjs/triggers/webhook.js +133 -0
  70. package/dist/commonjs/triggers/webhook.js.map +1 -0
  71. package/dist/commonjs/typed-emitter.d.ts +37 -0
  72. package/dist/commonjs/typed-emitter.js +3 -0
  73. package/dist/commonjs/typed-emitter.js.map +1 -0
  74. package/dist/commonjs/types.d.ts +204 -0
  75. package/dist/commonjs/types.js +23 -0
  76. package/dist/commonjs/types.js.map +1 -0
  77. package/dist/commonjs/utils/formatSchemaErrors.d.ts +3 -0
  78. package/dist/commonjs/utils/formatSchemaErrors.js +10 -0
  79. package/dist/commonjs/utils/formatSchemaErrors.js.map +1 -0
  80. package/dist/commonjs/utils/typedAsyncLocalStorage.d.ts +6 -0
  81. package/dist/commonjs/utils/typedAsyncLocalStorage.js +18 -0
  82. package/dist/commonjs/utils/typedAsyncLocalStorage.js.map +1 -0
  83. package/dist/commonjs/utils.d.ts +1 -0
  84. package/dist/commonjs/utils.js +11 -0
  85. package/dist/commonjs/utils.js.map +1 -0
  86. package/dist/commonjs/v3/cache.d.ts +28 -0
  87. package/dist/commonjs/v3/cache.js +63 -0
  88. package/dist/commonjs/v3/cache.js.map +1 -0
  89. package/dist/commonjs/v3/config.d.ts +4 -0
  90. package/dist/commonjs/v3/config.js +7 -0
  91. package/dist/commonjs/v3/config.js.map +1 -0
  92. package/dist/commonjs/v3/envvars.d.ts +14 -0
  93. package/dist/commonjs/v3/envvars.js +246 -0
  94. package/dist/commonjs/v3/envvars.js.map +1 -0
  95. package/dist/commonjs/v3/idempotencyKeys.d.ts +49 -0
  96. package/dist/commonjs/v3/idempotencyKeys.js +76 -0
  97. package/dist/commonjs/v3/idempotencyKeys.js.map +1 -0
  98. package/dist/commonjs/v3/index.d.ts +36 -0
  99. package/dist/commonjs/v3/index.js +79 -0
  100. package/dist/commonjs/v3/index.js.map +1 -0
  101. package/dist/commonjs/v3/retry.d.ts +15 -0
  102. package/dist/commonjs/v3/retry.js +411 -0
  103. package/dist/commonjs/v3/retry.js.map +1 -0
  104. package/dist/commonjs/v3/runs.d.ts +345 -0
  105. package/dist/commonjs/v3/runs.js +195 -0
  106. package/dist/commonjs/v3/runs.js.map +1 -0
  107. package/dist/commonjs/v3/schedules/api.d.ts +1 -0
  108. package/dist/commonjs/v3/schedules/api.js +3 -0
  109. package/dist/commonjs/v3/schedules/api.js.map +1 -0
  110. package/dist/commonjs/v3/schedules/index.d.ts +87 -0
  111. package/dist/commonjs/v3/schedules/index.js +250 -0
  112. package/dist/commonjs/v3/schedules/index.js.map +1 -0
  113. package/dist/commonjs/v3/shared.d.ts +443 -0
  114. package/dist/commonjs/v3/shared.js +547 -0
  115. package/dist/commonjs/v3/shared.js.map +1 -0
  116. package/dist/commonjs/v3/tags.d.ts +6 -0
  117. package/dist/commonjs/v3/tags.js +50 -0
  118. package/dist/commonjs/v3/tags.js.map +1 -0
  119. package/dist/commonjs/v3/tasks.d.ts +31 -0
  120. package/dist/commonjs/v3/tasks.js +35 -0
  121. package/dist/commonjs/v3/tasks.js.map +1 -0
  122. package/dist/commonjs/v3/tracer.d.ts +2 -0
  123. package/dist/commonjs/v3/tracer.js +7 -0
  124. package/dist/commonjs/v3/tracer.js.map +1 -0
  125. package/dist/commonjs/v3/usage.d.ts +77 -0
  126. package/dist/commonjs/v3/usage.js +115 -0
  127. package/dist/commonjs/v3/usage.js.map +1 -0
  128. package/dist/commonjs/v3/wait.d.ts +22 -0
  129. package/dist/commonjs/v3/wait.js +99 -0
  130. package/dist/commonjs/v3/wait.js.map +1 -0
  131. package/dist/commonjs/version.d.ts +1 -0
  132. package/dist/commonjs/version.js +5 -0
  133. package/dist/commonjs/version.js.map +1 -0
  134. package/dist/esm/apiClient.d.ts +737 -0
  135. package/dist/esm/apiClient.js +687 -0
  136. package/dist/esm/apiClient.js.map +1 -0
  137. package/dist/esm/concurrencyLimit.d.ts +10 -0
  138. package/dist/esm/concurrencyLimit.js +13 -0
  139. package/dist/esm/concurrencyLimit.js.map +1 -0
  140. package/dist/esm/errors.d.ts +66 -0
  141. package/dist/esm/errors.js +95 -0
  142. package/dist/esm/errors.js.map +1 -0
  143. package/dist/esm/httpEndpoint.d.ts +87 -0
  144. package/dist/esm/httpEndpoint.js +125 -0
  145. package/dist/esm/httpEndpoint.js.map +1 -0
  146. package/dist/esm/index.d.ts +23 -0
  147. package/dist/esm/index.js +35 -0
  148. package/dist/esm/index.js.map +1 -0
  149. package/dist/esm/integrations.d.ts +11 -0
  150. package/dist/esm/integrations.js +2 -0
  151. package/dist/esm/integrations.js.map +1 -0
  152. package/dist/esm/io.d.ts +453 -0
  153. package/dist/esm/io.js +1159 -0
  154. package/dist/esm/io.js.map +1 -0
  155. package/dist/esm/ioWithIntegrations.d.ts +4 -0
  156. package/dist/esm/ioWithIntegrations.js +29 -0
  157. package/dist/esm/ioWithIntegrations.js.map +1 -0
  158. package/dist/esm/job.d.ts +96 -0
  159. package/dist/esm/job.js +206 -0
  160. package/dist/esm/job.js.map +1 -0
  161. package/dist/esm/package.json +3 -0
  162. package/dist/esm/retry.d.ts +20 -0
  163. package/dist/esm/retry.js +19 -0
  164. package/dist/esm/retry.js.map +1 -0
  165. package/dist/esm/runLocalStorage.d.ts +8 -0
  166. package/dist/esm/runLocalStorage.js +3 -0
  167. package/dist/esm/runLocalStorage.js.map +1 -0
  168. package/dist/esm/security.d.ts +18 -0
  169. package/dist/esm/security.js +34 -0
  170. package/dist/esm/security.js.map +1 -0
  171. package/dist/esm/status.d.ts +19 -0
  172. package/dist/esm/status.js +34 -0
  173. package/dist/esm/status.js.map +1 -0
  174. package/dist/esm/store/keyValueStore.d.ts +17 -0
  175. package/dist/esm/store/keyValueStore.js +134 -0
  176. package/dist/esm/store/keyValueStore.js.map +1 -0
  177. package/dist/esm/store/keyValueStoreClient.d.ts +19 -0
  178. package/dist/esm/store/keyValueStoreClient.js +61 -0
  179. package/dist/esm/store/keyValueStoreClient.js.map +1 -0
  180. package/dist/esm/triggerClient.d.ts +300 -0
  181. package/dist/esm/triggerClient.js +1359 -0
  182. package/dist/esm/triggerClient.js.map +1 -0
  183. package/dist/esm/triggers/dynamic.d.ts +56 -0
  184. package/dist/esm/triggers/dynamic.js +93 -0
  185. package/dist/esm/triggers/dynamic.js.map +1 -0
  186. package/dist/esm/triggers/eventTrigger.d.ts +58 -0
  187. package/dist/esm/triggers/eventTrigger.js +64 -0
  188. package/dist/esm/triggers/eventTrigger.js.map +1 -0
  189. package/dist/esm/triggers/externalSource.d.ts +148 -0
  190. package/dist/esm/triggers/externalSource.js +100 -0
  191. package/dist/esm/triggers/externalSource.js.map +1 -0
  192. package/dist/esm/triggers/invokeTrigger.d.ts +39 -0
  193. package/dist/esm/triggers/invokeTrigger.js +53 -0
  194. package/dist/esm/triggers/invokeTrigger.js.map +1 -0
  195. package/dist/esm/triggers/notifications.d.ts +111 -0
  196. package/dist/esm/triggers/notifications.js +94 -0
  197. package/dist/esm/triggers/notifications.js.map +1 -0
  198. package/dist/esm/triggers/scheduled.d.ts +145 -0
  199. package/dist/esm/triggers/scheduled.js +197 -0
  200. package/dist/esm/triggers/scheduled.js.map +1 -0
  201. package/dist/esm/triggers/webhook.d.ts +143 -0
  202. package/dist/esm/triggers/webhook.js +128 -0
  203. package/dist/esm/triggers/webhook.js.map +1 -0
  204. package/dist/esm/typed-emitter.d.ts +37 -0
  205. package/dist/esm/typed-emitter.js +2 -0
  206. package/dist/esm/typed-emitter.js.map +1 -0
  207. package/dist/esm/types.d.ts +204 -0
  208. package/dist/esm/types.js +19 -0
  209. package/dist/esm/types.js.map +1 -0
  210. package/dist/esm/utils/formatSchemaErrors.d.ts +3 -0
  211. package/dist/esm/utils/formatSchemaErrors.js +7 -0
  212. package/dist/esm/utils/formatSchemaErrors.js.map +1 -0
  213. package/dist/esm/utils/typedAsyncLocalStorage.d.ts +6 -0
  214. package/dist/esm/utils/typedAsyncLocalStorage.js +14 -0
  215. package/dist/esm/utils/typedAsyncLocalStorage.js.map +1 -0
  216. package/dist/esm/utils.d.ts +1 -0
  217. package/dist/esm/utils.js +8 -0
  218. package/dist/esm/utils.js.map +1 -0
  219. package/dist/esm/v3/cache.d.ts +28 -0
  220. package/dist/esm/v3/cache.js +58 -0
  221. package/dist/esm/v3/cache.js.map +1 -0
  222. package/dist/esm/v3/config.d.ts +4 -0
  223. package/dist/esm/v3/config.js +4 -0
  224. package/dist/esm/v3/config.js.map +1 -0
  225. package/dist/esm/v3/envvars.d.ts +14 -0
  226. package/dist/esm/v3/envvars.js +238 -0
  227. package/dist/esm/v3/envvars.js.map +1 -0
  228. package/dist/esm/v3/idempotencyKeys.d.ts +49 -0
  229. package/dist/esm/v3/idempotencyKeys.js +72 -0
  230. package/dist/esm/v3/idempotencyKeys.js.map +1 -0
  231. package/dist/esm/v3/index.d.ts +36 -0
  232. package/dist/esm/v3/index.js +35 -0
  233. package/dist/esm/v3/index.js.map +1 -0
  234. package/dist/esm/v3/retry.d.ts +15 -0
  235. package/dist/esm/v3/retry.js +408 -0
  236. package/dist/esm/v3/retry.js.map +1 -0
  237. package/dist/esm/v3/runs.d.ts +345 -0
  238. package/dist/esm/v3/runs.js +192 -0
  239. package/dist/esm/v3/runs.js.map +1 -0
  240. package/dist/esm/v3/schedules/api.d.ts +1 -0
  241. package/dist/esm/v3/schedules/api.js +2 -0
  242. package/dist/esm/v3/schedules/api.js.map +1 -0
  243. package/dist/esm/v3/schedules/index.d.ts +87 -0
  244. package/dist/esm/v3/schedules/index.js +239 -0
  245. package/dist/esm/v3/schedules/index.js.map +1 -0
  246. package/dist/esm/v3/shared.d.ts +443 -0
  247. package/dist/esm/v3/shared.js +534 -0
  248. package/dist/esm/v3/shared.js.map +1 -0
  249. package/dist/esm/v3/tags.d.ts +6 -0
  250. package/dist/esm/v3/tags.js +47 -0
  251. package/dist/esm/v3/tags.js.map +1 -0
  252. package/dist/esm/v3/tasks.d.ts +31 -0
  253. package/dist/esm/v3/tasks.js +31 -0
  254. package/dist/esm/v3/tasks.js.map +1 -0
  255. package/dist/esm/v3/tracer.d.ts +2 -0
  256. package/dist/esm/v3/tracer.js +4 -0
  257. package/dist/esm/v3/tracer.js.map +1 -0
  258. package/dist/esm/v3/usage.d.ts +77 -0
  259. package/dist/esm/v3/usage.js +112 -0
  260. package/dist/esm/v3/usage.js.map +1 -0
  261. package/dist/esm/v3/wait.d.ts +22 -0
  262. package/dist/esm/v3/wait.js +96 -0
  263. package/dist/esm/v3/wait.js.map +1 -0
  264. package/dist/esm/version.d.ts +1 -0
  265. package/dist/esm/version.js +2 -0
  266. package/dist/esm/version.js.map +1 -0
  267. package/package.json +62 -47
  268. package/dist/index.d.mts +0 -2704
  269. package/dist/index.d.ts +0 -2704
  270. package/dist/index.js +0 -4886
  271. package/dist/index.js.map +0 -1
  272. package/dist/index.mjs +0 -4847
  273. package/dist/index.mjs.map +0 -1
  274. package/dist/v3/index.d.mts +0 -261
  275. package/dist/v3/index.d.ts +0 -261
  276. package/dist/v3/index.js +0 -921
  277. package/dist/v3/index.js.map +0 -1
  278. package/dist/v3/index.mjs +0 -911
  279. package/dist/v3/index.mjs.map +0 -1
@@ -0,0 +1,239 @@
1
+ import { TimezonesResult, accessoryAttributes, apiClientManager, mergeRequestOptions, taskCatalog, } from "@trigger.dev/core/v3";
2
+ import { zodfetch } from "@trigger.dev/core/v3/zodfetch";
3
+ import { apiClientMissingError, createTask } from "../shared.js";
4
+ import { tracer } from "../tracer.js";
5
+ export function task(params) {
6
+ const task = createTask(params);
7
+ const cron = params.cron
8
+ ? typeof params.cron === "string"
9
+ ? params.cron
10
+ : params.cron.pattern
11
+ : undefined;
12
+ const timezone = (params.cron && typeof params.cron !== "string" ? params.cron.timezone : "UTC") ?? "UTC";
13
+ taskCatalog.updateTaskMetadata(task.id, {
14
+ triggerSource: "schedule",
15
+ schedule: cron
16
+ ? {
17
+ cron: cron,
18
+ timezone,
19
+ }
20
+ : undefined,
21
+ });
22
+ return task;
23
+ }
24
+ /**
25
+ * Creates a new schedule
26
+ * @param options
27
+ * @param options.task - The identifier of the task to be scheduled (Must already exist and be a scheduled task)
28
+ * @param options.cron - The cron expression for the schedule (e.g. `0 0 * * *`)
29
+ * @param options.timezone - An optional timezone for the schedule in the IANA format (e.g. `America/Los_Angeles`). Defaults to "UTC".
30
+ * @param options.externalId - An optional external identifier for the schedule
31
+ * @param options.deduplicationKey - An optional deduplication key for the schedule
32
+ * @returns The created schedule
33
+ */
34
+ export function create(options, requestOptions) {
35
+ const apiClient = apiClientManager.client;
36
+ if (!apiClient) {
37
+ throw apiClientMissingError();
38
+ }
39
+ const $requestOptions = mergeRequestOptions({
40
+ tracer,
41
+ name: "schedules.create()",
42
+ icon: "clock",
43
+ attributes: {
44
+ ...accessoryAttributes({
45
+ items: [
46
+ {
47
+ text: options.cron,
48
+ variant: "normal",
49
+ },
50
+ ],
51
+ style: "codepath",
52
+ }),
53
+ },
54
+ }, requestOptions);
55
+ return apiClient.createSchedule(options, $requestOptions);
56
+ }
57
+ /**
58
+ * Retrieves a schedule
59
+ * @param scheduleId - The ID of the schedule to retrieve
60
+ * @returns The retrieved schedule
61
+ */
62
+ export function retrieve(scheduleId, requestOptions) {
63
+ const apiClient = apiClientManager.client;
64
+ if (!apiClient) {
65
+ throw apiClientMissingError();
66
+ }
67
+ const $requestOptions = mergeRequestOptions({
68
+ tracer,
69
+ name: "schedules.retrieve()",
70
+ icon: "clock",
71
+ attributes: {
72
+ scheduleId,
73
+ ...accessoryAttributes({
74
+ items: [
75
+ {
76
+ text: scheduleId,
77
+ variant: "normal",
78
+ },
79
+ ],
80
+ style: "codepath",
81
+ }),
82
+ },
83
+ }, requestOptions);
84
+ return apiClient.retrieveSchedule(scheduleId, $requestOptions);
85
+ }
86
+ /**
87
+ * Updates a schedule
88
+ * @param scheduleId - The ID of the schedule to update
89
+ * @param options - The updated schedule options
90
+ * @param options.task - The identifier of the task to be scheduled (Must already exist and be a scheduled task)
91
+ * @param options.cron - The cron expression for the schedule (e.g. `0 0 * * *`)
92
+ * @param options.timezone - An optional timezone for the schedule in the IANA format (e.g. `America/Los_Angeles`). Defaults to "UTC".
93
+ * @param options.externalId - An optional external identifier for the schedule
94
+ * @returns The updated schedule
95
+ */
96
+ export function update(scheduleId, options, requestOptions) {
97
+ const apiClient = apiClientManager.client;
98
+ if (!apiClient) {
99
+ throw apiClientMissingError();
100
+ }
101
+ const $requestOptions = mergeRequestOptions({
102
+ tracer,
103
+ name: "schedules.update()",
104
+ icon: "clock",
105
+ attributes: {
106
+ scheduleId,
107
+ ...accessoryAttributes({
108
+ items: [
109
+ {
110
+ text: scheduleId,
111
+ variant: "normal",
112
+ },
113
+ ],
114
+ style: "codepath",
115
+ }),
116
+ },
117
+ }, requestOptions);
118
+ return apiClient.updateSchedule(scheduleId, options, $requestOptions);
119
+ }
120
+ /**
121
+ * Deletes a schedule
122
+ * @param scheduleId - The ID of the schedule to delete
123
+ */
124
+ export function del(scheduleId, requestOptions) {
125
+ const apiClient = apiClientManager.client;
126
+ if (!apiClient) {
127
+ throw apiClientMissingError();
128
+ }
129
+ const $requestOptions = mergeRequestOptions({
130
+ tracer,
131
+ name: "schedules.delete()",
132
+ icon: "clock",
133
+ attributes: {
134
+ scheduleId,
135
+ ...accessoryAttributes({
136
+ items: [
137
+ {
138
+ text: scheduleId,
139
+ variant: "normal",
140
+ },
141
+ ],
142
+ style: "codepath",
143
+ }),
144
+ },
145
+ }, requestOptions);
146
+ return apiClient.deleteSchedule(scheduleId, $requestOptions);
147
+ }
148
+ /**
149
+ * Deactivates a schedule
150
+ * @param scheduleId - The ID of the schedule to deactivate
151
+ */
152
+ export function deactivate(scheduleId, requestOptions) {
153
+ const apiClient = apiClientManager.client;
154
+ if (!apiClient) {
155
+ throw apiClientMissingError();
156
+ }
157
+ const $requestOptions = mergeRequestOptions({
158
+ tracer,
159
+ name: "schedules.deactivate()",
160
+ icon: "clock",
161
+ attributes: {
162
+ scheduleId,
163
+ ...accessoryAttributes({
164
+ items: [
165
+ {
166
+ text: scheduleId,
167
+ variant: "normal",
168
+ },
169
+ ],
170
+ style: "codepath",
171
+ }),
172
+ },
173
+ }, requestOptions);
174
+ return apiClient.deactivateSchedule(scheduleId, $requestOptions);
175
+ }
176
+ /**
177
+ * Activates a schedule
178
+ * @param scheduleId - The ID of the schedule to activate
179
+ */
180
+ export function activate(scheduleId, requestOptions) {
181
+ const apiClient = apiClientManager.client;
182
+ if (!apiClient) {
183
+ throw apiClientMissingError();
184
+ }
185
+ const $requestOptions = mergeRequestOptions({
186
+ tracer,
187
+ name: "schedules.activate()",
188
+ icon: "clock",
189
+ attributes: {
190
+ scheduleId,
191
+ ...accessoryAttributes({
192
+ items: [
193
+ {
194
+ text: scheduleId,
195
+ variant: "normal",
196
+ },
197
+ ],
198
+ style: "codepath",
199
+ }),
200
+ },
201
+ }, requestOptions);
202
+ return apiClient.activateSchedule(scheduleId, $requestOptions);
203
+ }
204
+ /**
205
+ * Lists schedules
206
+ * @param options - The list options
207
+ * @param options.page - The page number
208
+ * @param options.perPage - The number of schedules per page
209
+ * @returns The list of schedules
210
+ */
211
+ export function list(options, requestOptions) {
212
+ const apiClient = apiClientManager.client;
213
+ if (!apiClient) {
214
+ throw apiClientMissingError();
215
+ }
216
+ const $requestOptions = mergeRequestOptions({
217
+ tracer,
218
+ name: "schedules.list()",
219
+ icon: "clock",
220
+ }, requestOptions);
221
+ return apiClient.listSchedules(options, $requestOptions);
222
+ }
223
+ /**
224
+ * Lists the possible timezones we support
225
+ * @param excludeUtc - By default "UTC" is included and is first. If true, "UTC" will be excluded.
226
+ */
227
+ export function timezones(options) {
228
+ const baseUrl = apiClientManager.baseURL;
229
+ if (!baseUrl) {
230
+ throw apiClientMissingError();
231
+ }
232
+ return zodfetch(TimezonesResult, `${baseUrl}/api/v1/timezones${options?.excludeUtc === true ? "?excludeUtc=true" : ""}`, {
233
+ method: "GET",
234
+ headers: {
235
+ "Content-Type": "application/json",
236
+ },
237
+ });
238
+ }
239
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/v3/schedules/index.ts"],"names":[],"mappings":"AAAA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AC3D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,OAAkC;IAC1D,MAAM,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC;IAEzC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,qBAAqB,EAAE,CAAC;IAChC,CAAC;IAED,OAAO,QAAQ,CACb,eAAe,EACf,GAAG,OAAO,oBAAoB,OAAO,EAAE,UAAU,KAAK,IAAI,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,EAAE,EACtF;QACE,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;SACnC;KACF,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,443 @@
1
+ import { ApiRequestOptions, FailureFnParams, HandleErrorFnParams, HandleErrorResult, InitFnParams, InitOutput, MachineCpu, MachineMemory, MiddlewareFnParams, QueueOptions, RetryOptions, RunFnParams, RunTags, StartFnParams, SuccessFnParams, TaskRunContext } from "@trigger.dev/core/v3";
2
+ import { IdempotencyKey } from "./idempotencyKeys.js";
3
+ import { PollOptions, RetrieveRunResult } from "./runs.js";
4
+ export type Context = TaskRunContext;
5
+ type RequireOne<T, K extends keyof T> = {
6
+ [X in Exclude<keyof T, K>]?: T[X];
7
+ } & {
8
+ [P in K]-?: T[P];
9
+ };
10
+ export type Queue = RequireOne<QueueOptions, "name">;
11
+ export declare function queue(options: {
12
+ name: string;
13
+ } & QueueOptions): Queue;
14
+ export type TaskOptions<TIdentifier extends string, TPayload = void, TOutput = unknown, TInitOutput extends InitOutput = any> = {
15
+ /** An id for your task. This must be unique inside your project and not change between versions. */
16
+ id: TIdentifier;
17
+ /** The retry settings when an uncaught error is thrown.
18
+ *
19
+ * If omitted it will use the values in your `trigger.config.ts` file.
20
+ *
21
+ * @example
22
+ *
23
+ * ```
24
+ * export const taskWithRetries = task({
25
+ id: "task-with-retries",
26
+ retry: {
27
+ maxAttempts: 10,
28
+ factor: 1.8,
29
+ minTimeoutInMs: 500,
30
+ maxTimeoutInMs: 30_000,
31
+ randomize: false,
32
+ },
33
+ run: async ({ payload, ctx }) => {
34
+ //...
35
+ },
36
+ });
37
+ * ```
38
+ * */
39
+ retry?: RetryOptions;
40
+ /** Used to configure what should happen when more than one run is triggered at the same time.
41
+ *
42
+ * @example
43
+ * one at a time execution
44
+ *
45
+ * ```ts
46
+ * export const oneAtATime = task({
47
+ id: "one-at-a-time",
48
+ queue: {
49
+ concurrencyLimit: 1,
50
+ },
51
+ run: async ({ payload, ctx }) => {
52
+ //...
53
+ },
54
+ });
55
+ * ```
56
+ */
57
+ queue?: QueueOptions;
58
+ /** Configure the spec of the machine you want your task to run on.
59
+ *
60
+ * @example
61
+ *
62
+ * ```ts
63
+ * export const heavyTask = task({
64
+ id: "heavy-task",
65
+ machine: {
66
+ cpu: 2,
67
+ memory: 4,
68
+ },
69
+ run: async ({ payload, ctx }) => {
70
+ //...
71
+ },
72
+ });
73
+ * ```
74
+ */
75
+ machine?: {
76
+ /** vCPUs. The default is 0.5.
77
+ *
78
+ * Possible values:
79
+ * - 0.25
80
+ * - 0.5
81
+ * - 1
82
+ * - 2
83
+ * - 4
84
+ * @deprecated use preset instead
85
+ */
86
+ cpu?: MachineCpu;
87
+ /** In GBs of RAM. The default is 1.
88
+ *
89
+ * Possible values:
90
+ * - 0.25
91
+ * - 0.5
92
+ * - 1
93
+ * - 2
94
+ * - 4
95
+ * - 8
96
+ * * @deprecated use preset instead
97
+ */
98
+ memory?: MachineMemory;
99
+ /** Preset to use for the machine. Defaults to small-1x */
100
+ preset?: "micro" | "small-1x" | "small-2x" | "medium-1x" | "medium-2x" | "large-1x" | "large-2x";
101
+ };
102
+ /** This gets called when a task is triggered. It's where you put the code you want to execute.
103
+ *
104
+ * @param payload - The payload that is passed to your task when it's triggered. This must be JSON serializable.
105
+ * @param params - Metadata about the run.
106
+ */
107
+ run: (payload: TPayload, params: RunFnParams<TInitOutput>) => Promise<TOutput>;
108
+ /**
109
+ * init is called before the run function is called. It's useful for setting up any global state.
110
+ */
111
+ init?: (payload: TPayload, params: InitFnParams) => Promise<TInitOutput>;
112
+ /**
113
+ * cleanup is called after the run function has completed.
114
+ */
115
+ cleanup?: (payload: TPayload, params: RunFnParams<TInitOutput>) => Promise<void>;
116
+ /**
117
+ * handleError is called when the run function throws an error. It can be used to modify the error or return new retry options.
118
+ */
119
+ handleError?: (payload: TPayload, error: unknown, params: HandleErrorFnParams<TInitOutput>) => HandleErrorResult;
120
+ /**
121
+ * middleware allows you to run code "around" the run function. This can be useful for logging, metrics, or other cross-cutting concerns.
122
+ *
123
+ * When writing middleware, you should always call `next()` to continue the execution of the task:
124
+ *
125
+ * ```ts
126
+ * export const middlewareTask = task({
127
+ * id: "middleware-task",
128
+ * middleware: async (payload, { ctx, next }) => {
129
+ * console.log("Before run");
130
+ * await next();
131
+ * console.log("After run");
132
+ * },
133
+ * run: async (payload, { ctx }) => {}
134
+ * });
135
+ * ```
136
+ */
137
+ middleware?: (payload: TPayload, params: MiddlewareFnParams) => Promise<void>;
138
+ /**
139
+ * onStart is called the first time a task is executed in a run (not before every retry)
140
+ */
141
+ onStart?: (payload: TPayload, params: StartFnParams) => Promise<void>;
142
+ /**
143
+ * onSuccess is called after the run function has successfully completed.
144
+ */
145
+ onSuccess?: (payload: TPayload, output: TOutput, params: SuccessFnParams<TInitOutput>) => Promise<void>;
146
+ /**
147
+ * onFailure is called after a task run has failed (meaning the run function threw an error and won't be retried anymore)
148
+ */
149
+ onFailure?: (payload: TPayload, error: unknown, params: FailureFnParams<TInitOutput>) => Promise<void>;
150
+ };
151
+ declare const __output: unique symbol;
152
+ type BrandOutput<B> = {
153
+ [__output]: B;
154
+ };
155
+ export type BrandedOutput<T, B> = T & BrandOutput<B>;
156
+ export type RunHandle<TOutput> = BrandedOutput<{
157
+ id: string;
158
+ }, TOutput>;
159
+ /**
160
+ * A BatchRunHandle can be used to retrieve the runs of a batch trigger in a typesafe manner.
161
+ */
162
+ export type BatchRunHandle<TOutput> = BrandedOutput<{
163
+ batchId: string;
164
+ runs: Array<RunHandle<TOutput>>;
165
+ }, TOutput>;
166
+ export type RunHandleOutput<TRunHandle> = TRunHandle extends RunHandle<infer TOutput> ? TOutput : never;
167
+ export type TaskRunResult<TOutput = any> = {
168
+ ok: true;
169
+ id: string;
170
+ output: TOutput;
171
+ } | {
172
+ ok: false;
173
+ id: string;
174
+ error: unknown;
175
+ };
176
+ export declare class SubtaskUnwrapError extends Error {
177
+ readonly taskId: string;
178
+ readonly runId: string;
179
+ readonly cause?: unknown;
180
+ constructor(taskId: string, runId: string, subtaskError: unknown);
181
+ }
182
+ export declare class TaskRunPromise<T> extends Promise<TaskRunResult<T>> {
183
+ private readonly taskId;
184
+ constructor(executor: (resolve: (value: TaskRunResult<T> | PromiseLike<TaskRunResult<T>>) => void, reject: (reason?: any) => void) => void, taskId: string);
185
+ unwrap(): Promise<T>;
186
+ }
187
+ export type BatchResult<TOutput = any> = {
188
+ id: string;
189
+ runs: TaskRunResult<TOutput>[];
190
+ };
191
+ export type BatchItem<TInput> = TInput extends void ? {
192
+ payload?: TInput;
193
+ options?: TaskRunOptions;
194
+ } : {
195
+ payload: TInput;
196
+ options?: TaskRunOptions;
197
+ };
198
+ export interface Task<TIdentifier extends string, TInput = void, TOutput = any> {
199
+ /**
200
+ * The id of the task.
201
+ */
202
+ id: TIdentifier;
203
+ /**
204
+ * Trigger a task with the given payload, and continue without waiting for the result. If you want to wait for the result, use `triggerAndWait`. Returns the id of the triggered task run.
205
+ * @param payload
206
+ * @param options
207
+ * @returns RunHandle
208
+ * - `id` - The id of the triggered task run.
209
+ */
210
+ trigger: (payload: TInput, options?: TaskRunOptions) => Promise<RunHandle<TOutput>>;
211
+ /**
212
+ * Batch trigger multiple task runs with the given payloads, and continue without waiting for the results. If you want to wait for the results, use `batchTriggerAndWait`. Returns the id of the triggered batch.
213
+ * @param items
214
+ * @returns InvokeBatchHandle
215
+ * - `batchId` - The id of the triggered batch.
216
+ * - `runs` - The ids of the triggered task runs.
217
+ */
218
+ batchTrigger: (items: Array<BatchItem<TInput>>) => Promise<BatchRunHandle<TOutput>>;
219
+ /**
220
+ * Trigger a task with the given payload, and wait for the result. Returns the result of the task run
221
+ * @param payload
222
+ * @param options - Options for the task run
223
+ * @returns TaskRunResult
224
+ * @example
225
+ * ```
226
+ * const result = await task.triggerAndWait({ foo: "bar" });
227
+ *
228
+ * if (result.ok) {
229
+ * console.log(result.output);
230
+ * } else {
231
+ * console.error(result.error);
232
+ * }
233
+ * ```
234
+ */
235
+ triggerAndWait: (payload: TInput, options?: TaskRunOptions) => TaskRunPromise<TOutput>;
236
+ /**
237
+ * Batch trigger multiple task runs with the given payloads, and wait for the results. Returns the results of the task runs.
238
+ * @param items
239
+ * @returns BatchResult
240
+ * @example
241
+ * ```
242
+ * const result = await task.batchTriggerAndWait([
243
+ * { payload: { foo: "bar" } },
244
+ * { payload: { foo: "baz" } },
245
+ * ]);
246
+ *
247
+ * for (const run of result.runs) {
248
+ * if (run.ok) {
249
+ * console.log(run.output);
250
+ * } else {
251
+ * console.error(run.error);
252
+ * }
253
+ * }
254
+ * ```
255
+ */
256
+ batchTriggerAndWait: (items: Array<BatchItem<TInput>>) => Promise<BatchResult<TOutput>>;
257
+ }
258
+ export type AnyTask = Task<string, any, any>;
259
+ export type TaskPayload<TTask extends AnyTask> = TTask extends Task<string, infer TInput, any> ? TInput : never;
260
+ export type TaskOutput<TTask extends AnyTask> = TTask extends Task<string, any, infer TOutput> ? TOutput : never;
261
+ export type TaskOutputHandle<TTask extends AnyTask> = TTask extends Task<string, any, infer TOutput> ? RunHandle<TOutput> : never;
262
+ export type TaskBatchOutputHandle<TTask extends AnyTask> = TTask extends Task<string, any, infer TOutput> ? BatchRunHandle<TOutput> : never;
263
+ export type TaskIdentifier<TTask extends AnyTask> = TTask extends Task<infer TIdentifier, any, any> ? TIdentifier : never;
264
+ export type TaskRunOptions = {
265
+ /**
266
+ * A unique key that can be used to ensure that a task is only triggered once per key.
267
+ *
268
+ * You can use `idempotencyKeys.create` to create an idempotency key first, and then pass it to the task options.
269
+ *
270
+ * @example
271
+ *
272
+ * ```typescript
273
+ * import { idempotencyKeys, task } from "@trigger.dev/sdk/v3";
274
+ *
275
+ * export const myTask = task({
276
+ * id: "my-task",
277
+ * run: async (payload: any) => {
278
+ * // scoped to the task run by default
279
+ * const idempotencyKey = await idempotencyKeys.create("my-task-key");
280
+ *
281
+ * // Use the idempotency key when triggering child tasks
282
+ * await childTask.triggerAndWait(payload, { idempotencyKey });
283
+ *
284
+ * // scoped globally, does not include the task run ID
285
+ * const globalIdempotencyKey = await idempotencyKeys.create("my-task-key", { scope: "global" });
286
+ *
287
+ * await childTask.triggerAndWait(payload, { idempotencyKey: globalIdempotencyKey });
288
+ *
289
+ * // You can also pass a string directly, which is the same as a global idempotency key
290
+ * await childTask.triggerAndWait(payload, { idempotencyKey: "my-very-unique-key" });
291
+ * }
292
+ * });
293
+ * ```
294
+ *
295
+ * When triggering a task inside another task, we automatically inject the run ID into the key material.
296
+ *
297
+ * If you are triggering a task from your backend, ensure you include some sufficiently unique key material to prevent collisions.
298
+ *
299
+ * @example
300
+ *
301
+ * ```typescript
302
+ * import { idempotencyKeys, tasks } from "@trigger.dev/sdk/v3";
303
+ *
304
+ * // Somewhere in your backend
305
+ * const idempotencyKey = await idempotenceKeys.create(["my-task-trigger", "user-123"]);
306
+ * await tasks.trigger("my-task", { foo: "bar" }, { idempotencyKey });
307
+ * ```
308
+ *
309
+ */
310
+ idempotencyKey?: IdempotencyKey | string | string[];
311
+ maxAttempts?: number;
312
+ queue?: TaskRunConcurrencyOptions;
313
+ concurrencyKey?: string;
314
+ /**
315
+ * The delay before the task is executed. This can be a string like "1h" or a Date object.
316
+ *
317
+ * @example
318
+ * "1h" - 1 hour
319
+ * "30d" - 30 days
320
+ * "15m" - 15 minutes
321
+ * "2w" - 2 weeks
322
+ * "60s" - 60 seconds
323
+ * new Date("2025-01-01T00:00:00Z")
324
+ */
325
+ delay?: string | Date;
326
+ /**
327
+ * Set a time-to-live for this run. If the run is not executed within this time, it will be removed from the queue and never execute.
328
+ *
329
+ * @example
330
+ *
331
+ * ```ts
332
+ * await myTask.trigger({ foo: "bar" }, { ttl: "1h" });
333
+ * await myTask.trigger({ foo: "bar" }, { ttl: 60 * 60 }); // 1 hour
334
+ * ```
335
+ *
336
+ * The minimum value is 1 second. Setting the `ttl` to `0` will disable the TTL and the run will never expire.
337
+ *
338
+ * **Note:** Runs in development have a default `ttl` of 10 minutes. You can override this by setting the `ttl` option.
339
+ */
340
+ ttl?: string | number;
341
+ /**
342
+ * Tags to attach to the run. Tags can be used to filter runs in the dashboard and using the SDK.
343
+ *
344
+ * You can set up to 5 tags per run, they must be less than 64 characters each.
345
+ *
346
+ * We recommend prefixing tags with a namespace using an underscore or colon, like `user_1234567` or `org:9876543`.
347
+ *
348
+ * @example
349
+ *
350
+ * ```ts
351
+ * await myTask.trigger({ foo: "bar" }, { tags: ["user:1234567", "org:9876543"] });
352
+ * ```
353
+ */
354
+ tags?: RunTags;
355
+ };
356
+ type TaskRunConcurrencyOptions = Queue;
357
+ export type Prettify<T> = {
358
+ [K in keyof T]: T[K];
359
+ } & {};
360
+ export type DynamicBaseOptions = {
361
+ id: string;
362
+ };
363
+ export declare function createTask<TIdentifier extends string, TInput = void, TOutput = unknown, TInitOutput extends InitOutput = any>(params: TaskOptions<TIdentifier, TInput, TOutput, TInitOutput>): Task<TIdentifier, TInput, TOutput>;
364
+ /**
365
+ * Trigger a task by its identifier with the given payload. Returns a typesafe `RunHandle`.
366
+ *
367
+ * @example
368
+ *
369
+ * ```ts
370
+ * import { tasks, runs } from "@trigger.dev/sdk/v3";
371
+ * import type { myTask } from "./myTasks"; // Import just the type of the task
372
+ *
373
+ * const handle = await tasks.trigger<typeof myTask>("my-task", { foo: "bar" }); // The id and payload are fully typesafe
374
+ * const run = await runs.retrieve(handle);
375
+ * console.log(run.output) // The output is also fully typed
376
+ * ```
377
+ *
378
+ * @returns {RunHandle} An object with the `id` of the run. Can be used to retrieve the completed run output in a typesafe manner.
379
+ */
380
+ export declare function trigger<TTask extends AnyTask>(id: TaskIdentifier<TTask>, payload: TaskPayload<TTask>, options?: TaskRunOptions, requestOptions?: ApiRequestOptions): Promise<RunHandle<TaskOutput<TTask>>>;
381
+ /**
382
+ * Trigger a task with the given payload, and wait for the result. Returns the result of the task run
383
+ * @param id - The id of the task to trigger
384
+ * @param payload
385
+ * @param options - Options for the task run
386
+ * @returns TaskRunResult
387
+ * @example
388
+ * ```ts
389
+ * import { tasks } from "@trigger.dev/sdk/v3";
390
+ * const result = await tasks.triggerAndWait("my-task", { foo: "bar" });
391
+ *
392
+ * if (result.ok) {
393
+ * console.log(result.output);
394
+ * } else {
395
+ * console.error(result.error);
396
+ * }
397
+ * ```
398
+ */
399
+ export declare function triggerAndWait<TTask extends AnyTask>(id: TaskIdentifier<TTask>, payload: TaskPayload<TTask>, options?: TaskRunOptions, requestOptions?: ApiRequestOptions): TaskRunPromise<TaskOutput<TTask>>;
400
+ /**
401
+ * Batch trigger multiple task runs with the given payloads, and wait for the results. Returns the results of the task runs.
402
+ * @param id - The id of the task to trigger
403
+ * @param items
404
+ * @returns BatchResult
405
+ * @example
406
+ *
407
+ * ```ts
408
+ * import { tasks } from "@trigger.dev/sdk/v3";
409
+ *
410
+ * const result = await tasks.batchTriggerAndWait("my-task", [
411
+ * { payload: { foo: "bar" } },
412
+ * { payload: { foo: "baz" } },
413
+ * ]);
414
+ *
415
+ * for (const run of result.runs) {
416
+ * if (run.ok) {
417
+ * console.log(run.output);
418
+ * } else {
419
+ * console.error(run.error);
420
+ * }
421
+ * }
422
+ * ```
423
+ */
424
+ export declare function batchTriggerAndWait<TTask extends AnyTask>(id: TaskIdentifier<TTask>, items: Array<BatchItem<TaskPayload<TTask>>>, requestOptions?: ApiRequestOptions): Promise<BatchResult<TaskOutput<TTask>>>;
425
+ /**
426
+ * Trigger a task by its identifier with the given payload and poll until the run is completed.
427
+ *
428
+ * @example
429
+ *
430
+ * ```ts
431
+ * import { tasks, runs } from "@trigger.dev/sdk/v3";
432
+ * import type { myTask } from "./myTasks"; // Import just the type of the task
433
+ *
434
+ * const run = await tasks.triggerAndPoll<typeof myTask>("my-task", { foo: "bar" }); // The id and payload are fully typesafe
435
+ * console.log(run.output) // The output is also fully typed
436
+ * ```
437
+ *
438
+ * @returns {Run} The completed run, either successful or failed.
439
+ */
440
+ export declare function triggerAndPoll<TTask extends AnyTask>(id: TaskIdentifier<TTask>, payload: TaskPayload<TTask>, options?: TaskRunOptions & PollOptions, requestOptions?: ApiRequestOptions): Promise<RetrieveRunResult<RunHandle<TaskOutput<TTask>>>>;
441
+ export declare function batchTrigger<TTask extends AnyTask>(id: TaskIdentifier<TTask>, items: Array<BatchItem<TaskPayload<TTask>>>, requestOptions?: ApiRequestOptions): Promise<BatchRunHandle<TaskOutput<TTask>>>;
442
+ export declare function apiClientMissingError(): "Unknown error" | "You need to set the TRIGGER_API_URL and TRIGGER_SECRET_KEY environment variables." | "You need to set the TRIGGER_API_URL environment variable." | "You need to set the TRIGGER_SECRET_KEY environment variable.";
443
+ export {};