@trigger.dev/sdk 3.0.0-beta.5 → 3.0.0-beta.50
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 +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +221 -69
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +221 -69
- package/dist/index.mjs.map +1 -1
- package/dist/v3/index.d.mts +780 -81
- package/dist/v3/index.d.ts +780 -81
- package/dist/v3/index.js +1567 -482
- package/dist/v3/index.js.map +1 -1
- package/dist/v3/index.mjs +1519 -483
- package/dist/v3/index.mjs.map +1 -1
- package/package.json +5 -12
package/dist/v3/index.js
CHANGED
|
@@ -1,530 +1,158 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var v3 = require('@trigger.dev/core/v3');
|
|
3
4
|
var api = require('@opentelemetry/api');
|
|
4
5
|
var semanticConventions = require('@opentelemetry/semantic-conventions');
|
|
5
|
-
var v3 = require('@trigger.dev/core/v3');
|
|
6
6
|
var node_async_hooks = require('node:async_hooks');
|
|
7
|
+
var zodfetch = require('@trigger.dev/core/v3/zodfetch');
|
|
7
8
|
|
|
8
9
|
var __defProp = Object.defineProperty;
|
|
9
10
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
11
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name2 in all)
|
|
14
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
15
|
+
};
|
|
11
16
|
var __publicField = (obj, key, value) => {
|
|
12
17
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
13
18
|
return value;
|
|
14
19
|
};
|
|
15
20
|
|
|
16
21
|
// package.json
|
|
17
|
-
var version = "3.0.0-beta.
|
|
22
|
+
var version = "3.0.0-beta.50";
|
|
23
|
+
|
|
24
|
+
// src/v3/tracer.ts
|
|
18
25
|
var tracer = new v3.TriggerTracer({
|
|
19
26
|
name: "@trigger.dev/sdk",
|
|
20
27
|
version
|
|
21
28
|
});
|
|
22
29
|
|
|
23
|
-
// src/v3/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
// src/v3/cache.ts
|
|
31
|
+
var _InMemoryCache = class _InMemoryCache {
|
|
32
|
+
constructor() {
|
|
33
|
+
__publicField(this, "_cache", /* @__PURE__ */ new Map());
|
|
34
|
+
}
|
|
35
|
+
get(key) {
|
|
36
|
+
return this._cache.get(key);
|
|
37
|
+
}
|
|
38
|
+
set(key, value) {
|
|
39
|
+
this._cache.set(key, value);
|
|
40
|
+
return void 0;
|
|
41
|
+
}
|
|
42
|
+
delete(key) {
|
|
43
|
+
this._cache.delete(key);
|
|
44
|
+
return void 0;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
__name(_InMemoryCache, "InMemoryCache");
|
|
48
|
+
var InMemoryCache = _InMemoryCache;
|
|
49
|
+
function createCache(store) {
|
|
50
|
+
return /* @__PURE__ */ __name(function cache(cacheKey, fn) {
|
|
51
|
+
return tracer.startActiveSpan("cache", async (span) => {
|
|
52
|
+
span.setAttribute("cache.key", cacheKey);
|
|
53
|
+
span.setAttribute(v3.SemanticInternalAttributes.STYLE_ICON, "device-sd-card");
|
|
54
|
+
const cacheEntry = await store.get(cacheKey);
|
|
55
|
+
if (cacheEntry) {
|
|
56
|
+
span.updateName(`cache.hit ${cacheKey}`);
|
|
57
|
+
return cacheEntry.value;
|
|
30
58
|
}
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
payload,
|
|
35
|
-
options: {
|
|
36
|
-
queue: params.queue,
|
|
37
|
-
concurrencyKey: options?.concurrencyKey,
|
|
38
|
-
test: v3.taskContextManager.ctx?.run.isTest
|
|
39
|
-
}
|
|
40
|
-
}, {
|
|
41
|
-
spanParentAsLink: true
|
|
42
|
-
});
|
|
43
|
-
if (!response.ok) {
|
|
44
|
-
throw new Error(response.error);
|
|
45
|
-
}
|
|
46
|
-
span.setAttribute("messaging.message.id", response.data.id);
|
|
47
|
-
return response.data;
|
|
59
|
+
span.updateName(`cache.miss ${cacheKey}`);
|
|
60
|
+
const value = await tracer.startActiveSpan("cache.getFreshValue", async (span2) => {
|
|
61
|
+
return await fn();
|
|
48
62
|
}, {
|
|
49
|
-
kind: api.SpanKind.PRODUCER,
|
|
50
63
|
attributes: {
|
|
51
|
-
|
|
52
|
-
[v3.SemanticInternalAttributes.STYLE_ICON]: "
|
|
53
|
-
["messaging.client_id"]: v3.taskContextManager.worker?.id,
|
|
54
|
-
[semanticConventions.SEMATTRS_MESSAGING_DESTINATION]: params.queue?.name ?? params.id,
|
|
55
|
-
["messaging.message.body.size"]: JSON.stringify(payload).length,
|
|
56
|
-
[semanticConventions.SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
|
|
57
|
-
...taskMetadata ? v3.accessoryAttributes({
|
|
58
|
-
items: [
|
|
59
|
-
{
|
|
60
|
-
text: `${taskMetadata.exportName}.trigger()`,
|
|
61
|
-
variant: "normal"
|
|
62
|
-
}
|
|
63
|
-
],
|
|
64
|
-
style: "codepath"
|
|
65
|
-
}) : {}
|
|
64
|
+
"cache.key": cacheKey,
|
|
65
|
+
[v3.SemanticInternalAttributes.STYLE_ICON]: "device-sd-card"
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
const taskMetadata = v3.runtime.getTaskMetadata(params.id);
|
|
76
|
-
const response = await tracer.startActiveSpan(taskMetadata ? "Batch trigger" : `${params.id} batchTrigger()`, async (span) => {
|
|
77
|
-
const response2 = await apiClient.batchTriggerTask(params.id, {
|
|
78
|
-
items: items.map((item) => ({
|
|
79
|
-
payload: item.payload,
|
|
80
|
-
options: {
|
|
81
|
-
queue: item.options?.queue ?? params.queue,
|
|
82
|
-
concurrencyKey: item.options?.concurrencyKey,
|
|
83
|
-
test: v3.taskContextManager.ctx?.run.isTest
|
|
84
|
-
}
|
|
85
|
-
}))
|
|
86
|
-
}, {
|
|
87
|
-
spanParentAsLink: true
|
|
68
|
+
await tracer.startActiveSpan("cache.set", async (span2) => {
|
|
69
|
+
await store.set(cacheKey, {
|
|
70
|
+
value,
|
|
71
|
+
metadata: {
|
|
72
|
+
createdTime: Date.now()
|
|
73
|
+
}
|
|
88
74
|
});
|
|
89
|
-
if (!response2.ok) {
|
|
90
|
-
throw new Error(response2.error);
|
|
91
|
-
}
|
|
92
|
-
span.setAttribute("messaging.message.id", response2.data.batchId);
|
|
93
|
-
return response2.data;
|
|
94
75
|
}, {
|
|
95
|
-
kind: api.SpanKind.PRODUCER,
|
|
96
76
|
attributes: {
|
|
97
|
-
|
|
98
|
-
[
|
|
99
|
-
["messaging.client_id"]: v3.taskContextManager.worker?.id,
|
|
100
|
-
[semanticConventions.SEMATTRS_MESSAGING_DESTINATION]: params.queue?.name ?? params.id,
|
|
101
|
-
["messaging.message.body.size"]: items.map((item) => JSON.stringify(item.payload)).join("").length,
|
|
102
|
-
[semanticConventions.SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
|
|
103
|
-
[v3.SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
104
|
-
...taskMetadata ? v3.accessoryAttributes({
|
|
105
|
-
items: [
|
|
106
|
-
{
|
|
107
|
-
text: `${taskMetadata.exportName}.batchTrigger()`,
|
|
108
|
-
variant: "normal"
|
|
109
|
-
}
|
|
110
|
-
],
|
|
111
|
-
style: "codepath"
|
|
112
|
-
}) : {}
|
|
77
|
+
"cache.key": cacheKey,
|
|
78
|
+
[v3.SemanticInternalAttributes.STYLE_ICON]: "device-sd-card"
|
|
113
79
|
}
|
|
114
80
|
});
|
|
115
|
-
return
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
payload,
|
|
130
|
-
options: {
|
|
131
|
-
dependentAttempt: ctx.attempt.id,
|
|
132
|
-
lockToVersion: v3.taskContextManager.worker?.version,
|
|
133
|
-
queue: params.queue,
|
|
134
|
-
concurrencyKey: options?.concurrencyKey,
|
|
135
|
-
test: v3.taskContextManager.ctx?.run.isTest
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
if (!response.ok) {
|
|
139
|
-
throw new Error(response.error);
|
|
140
|
-
}
|
|
141
|
-
span.setAttribute("messaging.message.id", response.data.id);
|
|
142
|
-
const result = await v3.runtime.waitForTask({
|
|
143
|
-
id: response.data.id,
|
|
144
|
-
ctx
|
|
145
|
-
});
|
|
146
|
-
const runResult = await handleTaskRunExecutionResult(result);
|
|
147
|
-
if (!runResult.ok) {
|
|
148
|
-
throw runResult.error;
|
|
149
|
-
}
|
|
150
|
-
return runResult.output;
|
|
151
|
-
}, {
|
|
152
|
-
kind: api.SpanKind.PRODUCER,
|
|
81
|
+
return value;
|
|
82
|
+
});
|
|
83
|
+
}, "cache");
|
|
84
|
+
}
|
|
85
|
+
__name(createCache, "createCache");
|
|
86
|
+
function onThrow(fn, options) {
|
|
87
|
+
const opts = {
|
|
88
|
+
...v3.defaultRetryOptions,
|
|
89
|
+
...options
|
|
90
|
+
};
|
|
91
|
+
return tracer.startActiveSpan(`retry.onThrow()`, async (span) => {
|
|
92
|
+
let attempt = 1;
|
|
93
|
+
while (attempt <= opts.maxAttempts) {
|
|
94
|
+
const innerSpan = tracer.startSpan("retry.fn()", {
|
|
153
95
|
attributes: {
|
|
154
|
-
[v3.SemanticInternalAttributes.STYLE_ICON]: "
|
|
155
|
-
|
|
156
|
-
["messaging.client_id"]: v3.taskContextManager.worker?.id,
|
|
157
|
-
[semanticConventions.SEMATTRS_MESSAGING_DESTINATION]: params.queue?.name ?? params.id,
|
|
158
|
-
[semanticConventions.SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
|
|
159
|
-
...taskMetadata ? v3.accessoryAttributes({
|
|
96
|
+
[v3.SemanticInternalAttributes.STYLE_ICON]: "function",
|
|
97
|
+
...v3.accessoryAttributes({
|
|
160
98
|
items: [
|
|
161
99
|
{
|
|
162
|
-
text: `${
|
|
100
|
+
text: `${attempt}/${opts.maxAttempts}`,
|
|
163
101
|
variant: "normal"
|
|
164
102
|
}
|
|
165
103
|
],
|
|
166
104
|
style: "codepath"
|
|
167
|
-
})
|
|
105
|
+
})
|
|
168
106
|
}
|
|
169
107
|
});
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (!apiClient) {
|
|
178
|
-
throw apiClientMissingError();
|
|
179
|
-
}
|
|
180
|
-
const taskMetadata = v3.runtime.getTaskMetadata(params.id);
|
|
181
|
-
return await tracer.startActiveSpan(taskMetadata ? "Batch trigger" : `${params.id} batchTriggerAndWait()`, async (span) => {
|
|
182
|
-
const response = await apiClient.batchTriggerTask(params.id, {
|
|
183
|
-
items: items.map((item) => ({
|
|
184
|
-
payload: item.payload,
|
|
185
|
-
options: {
|
|
186
|
-
lockToVersion: v3.taskContextManager.worker?.version,
|
|
187
|
-
queue: item.options?.queue ?? params.queue,
|
|
188
|
-
concurrencyKey: item.options?.concurrencyKey,
|
|
189
|
-
test: v3.taskContextManager.ctx?.run.isTest
|
|
190
|
-
}
|
|
191
|
-
})),
|
|
192
|
-
dependentAttempt: ctx.attempt.id
|
|
108
|
+
const contextWithSpanSet = api.trace.setSpan(api.context.active(), innerSpan);
|
|
109
|
+
try {
|
|
110
|
+
const result = await api.context.with(contextWithSpanSet, async () => {
|
|
111
|
+
return fn({
|
|
112
|
+
attempt,
|
|
113
|
+
maxAttempts: opts.maxAttempts
|
|
114
|
+
});
|
|
193
115
|
});
|
|
194
|
-
|
|
195
|
-
|
|
116
|
+
innerSpan.end();
|
|
117
|
+
return result;
|
|
118
|
+
} catch (e) {
|
|
119
|
+
if (e instanceof Error || typeof e === "string") {
|
|
120
|
+
innerSpan.recordException(e);
|
|
121
|
+
} else {
|
|
122
|
+
innerSpan.recordException(String(e));
|
|
196
123
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
id: response.data.batchId,
|
|
200
|
-
runs: response.data.runs,
|
|
201
|
-
ctx
|
|
124
|
+
innerSpan.setStatus({
|
|
125
|
+
code: api.SpanStatusCode.ERROR
|
|
202
126
|
});
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
runs
|
|
207
|
-
};
|
|
208
|
-
}, {
|
|
209
|
-
kind: api.SpanKind.PRODUCER,
|
|
210
|
-
attributes: {
|
|
211
|
-
[semanticConventions.SEMATTRS_MESSAGING_OPERATION]: "publish",
|
|
212
|
-
["messaging.batch.message_count"]: items.length,
|
|
213
|
-
["messaging.client_id"]: v3.taskContextManager.worker?.id,
|
|
214
|
-
[semanticConventions.SEMATTRS_MESSAGING_DESTINATION]: params.queue?.name ?? params.id,
|
|
215
|
-
["messaging.message.body.size"]: items.map((item) => JSON.stringify(item.payload)).join("").length,
|
|
216
|
-
[semanticConventions.SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
|
|
217
|
-
[v3.SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
218
|
-
...taskMetadata ? v3.accessoryAttributes({
|
|
219
|
-
items: [
|
|
220
|
-
{
|
|
221
|
-
text: `${taskMetadata.exportName}.batchTriggerAndWait()`,
|
|
222
|
-
variant: "normal"
|
|
223
|
-
}
|
|
224
|
-
],
|
|
225
|
-
style: "codepath"
|
|
226
|
-
}) : {}
|
|
127
|
+
if (e instanceof Error && e.name === "AbortTaskRunError") {
|
|
128
|
+
innerSpan.end();
|
|
129
|
+
throw e;
|
|
227
130
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
machine: params.machine,
|
|
241
|
-
fns: {
|
|
242
|
-
run: params.run,
|
|
243
|
-
init: params.init,
|
|
244
|
-
cleanup: params.cleanup,
|
|
245
|
-
middleware: params.middleware,
|
|
246
|
-
handleError: params.handleError
|
|
131
|
+
const nextRetryDelay = v3.calculateNextRetryDelay(opts, attempt);
|
|
132
|
+
if (!nextRetryDelay) {
|
|
133
|
+
innerSpan.end();
|
|
134
|
+
throw e;
|
|
135
|
+
}
|
|
136
|
+
innerSpan.setAttribute(v3.SemanticInternalAttributes.RETRY_AT, new Date(Date.now() + nextRetryDelay).toISOString());
|
|
137
|
+
innerSpan.setAttribute(v3.SemanticInternalAttributes.RETRY_COUNT, attempt);
|
|
138
|
+
innerSpan.setAttribute(v3.SemanticInternalAttributes.RETRY_DELAY, `${nextRetryDelay}ms`);
|
|
139
|
+
innerSpan.end();
|
|
140
|
+
await v3.runtime.waitForDuration(nextRetryDelay);
|
|
141
|
+
} finally {
|
|
142
|
+
attempt++;
|
|
247
143
|
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
});
|
|
251
|
-
return task2;
|
|
252
|
-
}
|
|
253
|
-
__name(createTask, "createTask");
|
|
254
|
-
async function handleBatchTaskRunExecutionResult(items) {
|
|
255
|
-
const someObjectStoreOutputs = items.some((item) => item.ok && item.outputType === "application/store");
|
|
256
|
-
if (!someObjectStoreOutputs) {
|
|
257
|
-
const results = await Promise.all(items.map(async (item) => {
|
|
258
|
-
return await handleTaskRunExecutionResult(item);
|
|
259
|
-
}));
|
|
260
|
-
return results;
|
|
261
|
-
}
|
|
262
|
-
return await tracer.startActiveSpan("store.downloadPayloads", async (span) => {
|
|
263
|
-
const results = await Promise.all(items.map(async (item) => {
|
|
264
|
-
return await handleTaskRunExecutionResult(item);
|
|
265
|
-
}));
|
|
266
|
-
return results;
|
|
144
|
+
}
|
|
145
|
+
throw new Error("Max attempts reached");
|
|
267
146
|
}, {
|
|
268
|
-
|
|
269
|
-
|
|
147
|
+
attributes: {
|
|
148
|
+
[v3.SemanticInternalAttributes.STYLE_ICON]: "arrow-capsule"
|
|
149
|
+
}
|
|
270
150
|
});
|
|
271
151
|
}
|
|
272
|
-
__name(
|
|
273
|
-
|
|
274
|
-
if (
|
|
275
|
-
|
|
276
|
-
data: execution.output,
|
|
277
|
-
dataType: execution.outputType
|
|
278
|
-
};
|
|
279
|
-
const importedPacket = await v3.conditionallyImportPacket(outputPacket, tracer);
|
|
280
|
-
return {
|
|
281
|
-
ok: true,
|
|
282
|
-
id: execution.id,
|
|
283
|
-
output: await v3.parsePacket(importedPacket)
|
|
284
|
-
};
|
|
285
|
-
} else {
|
|
286
|
-
return {
|
|
287
|
-
ok: false,
|
|
288
|
-
id: execution.id,
|
|
289
|
-
error: v3.createErrorTaskError(execution.error)
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
__name(handleTaskRunExecutionResult, "handleTaskRunExecutionResult");
|
|
294
|
-
function apiClientMissingError() {
|
|
295
|
-
const hasBaseUrl = !!v3.apiClientManager.baseURL;
|
|
296
|
-
const hasAccessToken = !!v3.apiClientManager.accessToken;
|
|
297
|
-
if (!hasBaseUrl && !hasAccessToken) {
|
|
298
|
-
return `You need to set the TRIGGER_API_URL and TRIGGER_SECRET_KEY environment variables.`;
|
|
299
|
-
} else if (!hasBaseUrl) {
|
|
300
|
-
return `You need to set the TRIGGER_API_URL environment variable.`;
|
|
301
|
-
} else if (!hasAccessToken) {
|
|
302
|
-
return `You need to set the TRIGGER_SECRET_KEY environment variable.`;
|
|
303
|
-
}
|
|
304
|
-
return `Unknown error`;
|
|
305
|
-
}
|
|
306
|
-
__name(apiClientMissingError, "apiClientMissingError");
|
|
307
|
-
|
|
308
|
-
// src/v3/tasks.ts
|
|
309
|
-
function task(options) {
|
|
310
|
-
return createTask(options);
|
|
311
|
-
}
|
|
312
|
-
__name(task, "task");
|
|
313
|
-
var wait = {
|
|
314
|
-
for: async (options) => {
|
|
315
|
-
return tracer.startActiveSpan(`wait.for()`, async (span) => {
|
|
316
|
-
const durationInMs = calculateDurationInMs(options);
|
|
317
|
-
await v3.runtime.waitForDuration(durationInMs);
|
|
318
|
-
}, {
|
|
319
|
-
attributes: {
|
|
320
|
-
[v3.SemanticInternalAttributes.STYLE_ICON]: "wait",
|
|
321
|
-
...v3.accessoryAttributes({
|
|
322
|
-
items: [
|
|
323
|
-
{
|
|
324
|
-
text: nameForWaitOptions(options),
|
|
325
|
-
variant: "normal"
|
|
326
|
-
}
|
|
327
|
-
],
|
|
328
|
-
style: "codepath"
|
|
329
|
-
})
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
},
|
|
333
|
-
until: async (options) => {
|
|
334
|
-
return tracer.startActiveSpan(`wait.until()`, async (span) => {
|
|
335
|
-
const start = Date.now();
|
|
336
|
-
if (options.throwIfInThePast && options.date < /* @__PURE__ */ new Date()) {
|
|
337
|
-
throw new Error("Date is in the past");
|
|
338
|
-
}
|
|
339
|
-
const durationInMs = options.date.getTime() - start;
|
|
340
|
-
await v3.runtime.waitForDuration(durationInMs);
|
|
341
|
-
}, {
|
|
342
|
-
attributes: {
|
|
343
|
-
[v3.SemanticInternalAttributes.STYLE_ICON]: "wait",
|
|
344
|
-
...v3.accessoryAttributes({
|
|
345
|
-
items: [
|
|
346
|
-
{
|
|
347
|
-
text: options.date.toISOString(),
|
|
348
|
-
variant: "normal"
|
|
349
|
-
}
|
|
350
|
-
],
|
|
351
|
-
style: "codepath"
|
|
352
|
-
})
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
};
|
|
357
|
-
function nameForWaitOptions(options) {
|
|
358
|
-
if ("seconds" in options) {
|
|
359
|
-
return options.seconds === 1 ? `1 second` : `${options.seconds} seconds`;
|
|
360
|
-
}
|
|
361
|
-
if ("minutes" in options) {
|
|
362
|
-
return options.minutes === 1 ? `1 minute` : `${options.minutes} minutes`;
|
|
363
|
-
}
|
|
364
|
-
if ("hours" in options) {
|
|
365
|
-
return options.hours === 1 ? `1 hour` : `${options.hours} hours`;
|
|
366
|
-
}
|
|
367
|
-
if ("days" in options) {
|
|
368
|
-
return options.days === 1 ? `1 day` : `${options.days} days`;
|
|
369
|
-
}
|
|
370
|
-
if ("weeks" in options) {
|
|
371
|
-
return options.weeks === 1 ? `1 week` : `${options.weeks} weeks`;
|
|
372
|
-
}
|
|
373
|
-
if ("months" in options) {
|
|
374
|
-
return options.months === 1 ? `1 month` : `${options.months} months`;
|
|
375
|
-
}
|
|
376
|
-
if ("years" in options) {
|
|
377
|
-
return options.years === 1 ? `1 year` : `${options.years} years`;
|
|
378
|
-
}
|
|
379
|
-
return "NaN";
|
|
380
|
-
}
|
|
381
|
-
__name(nameForWaitOptions, "nameForWaitOptions");
|
|
382
|
-
function calculateDurationInMs(options) {
|
|
383
|
-
if ("seconds" in options) {
|
|
384
|
-
return options.seconds * 1e3;
|
|
385
|
-
}
|
|
386
|
-
if ("minutes" in options) {
|
|
387
|
-
return options.minutes * 1e3 * 60;
|
|
388
|
-
}
|
|
389
|
-
if ("hours" in options) {
|
|
390
|
-
return options.hours * 1e3 * 60 * 60;
|
|
391
|
-
}
|
|
392
|
-
if ("days" in options) {
|
|
393
|
-
return options.days * 1e3 * 60 * 60 * 24;
|
|
394
|
-
}
|
|
395
|
-
if ("weeks" in options) {
|
|
396
|
-
return options.weeks * 1e3 * 60 * 60 * 24 * 7;
|
|
397
|
-
}
|
|
398
|
-
if ("months" in options) {
|
|
399
|
-
return options.months * 1e3 * 60 * 60 * 24 * 30;
|
|
400
|
-
}
|
|
401
|
-
if ("years" in options) {
|
|
402
|
-
return options.years * 1e3 * 60 * 60 * 24 * 365;
|
|
403
|
-
}
|
|
404
|
-
throw new Error("Invalid options");
|
|
405
|
-
}
|
|
406
|
-
__name(calculateDurationInMs, "calculateDurationInMs");
|
|
407
|
-
var _InMemoryCache = class _InMemoryCache {
|
|
408
|
-
constructor() {
|
|
409
|
-
__publicField(this, "_cache", /* @__PURE__ */ new Map());
|
|
410
|
-
}
|
|
411
|
-
get(key) {
|
|
412
|
-
return this._cache.get(key);
|
|
413
|
-
}
|
|
414
|
-
set(key, value) {
|
|
415
|
-
this._cache.set(key, value);
|
|
416
|
-
return void 0;
|
|
417
|
-
}
|
|
418
|
-
delete(key) {
|
|
419
|
-
this._cache.delete(key);
|
|
420
|
-
return void 0;
|
|
421
|
-
}
|
|
422
|
-
};
|
|
423
|
-
__name(_InMemoryCache, "InMemoryCache");
|
|
424
|
-
var InMemoryCache = _InMemoryCache;
|
|
425
|
-
function createCache(store) {
|
|
426
|
-
return /* @__PURE__ */ __name(function cache(cacheKey, fn) {
|
|
427
|
-
return tracer.startActiveSpan("cache", async (span) => {
|
|
428
|
-
span.setAttribute("cache.key", cacheKey);
|
|
429
|
-
span.setAttribute(v3.SemanticInternalAttributes.STYLE_ICON, "device-sd-card");
|
|
430
|
-
const cacheEntry = await store.get(cacheKey);
|
|
431
|
-
if (cacheEntry) {
|
|
432
|
-
span.updateName(`cache.hit ${cacheKey}`);
|
|
433
|
-
return cacheEntry.value;
|
|
434
|
-
}
|
|
435
|
-
span.updateName(`cache.miss ${cacheKey}`);
|
|
436
|
-
const value = await tracer.startActiveSpan("cache.getFreshValue", async (span2) => {
|
|
437
|
-
return await fn();
|
|
438
|
-
}, {
|
|
439
|
-
attributes: {
|
|
440
|
-
"cache.key": cacheKey,
|
|
441
|
-
[v3.SemanticInternalAttributes.STYLE_ICON]: "device-sd-card"
|
|
442
|
-
}
|
|
443
|
-
});
|
|
444
|
-
await tracer.startActiveSpan("cache.set", async (span2) => {
|
|
445
|
-
await store.set(cacheKey, {
|
|
446
|
-
value,
|
|
447
|
-
metadata: {
|
|
448
|
-
createdTime: Date.now()
|
|
449
|
-
}
|
|
450
|
-
});
|
|
451
|
-
}, {
|
|
452
|
-
attributes: {
|
|
453
|
-
"cache.key": cacheKey,
|
|
454
|
-
[v3.SemanticInternalAttributes.STYLE_ICON]: "device-sd-card"
|
|
455
|
-
}
|
|
456
|
-
});
|
|
457
|
-
return value;
|
|
458
|
-
});
|
|
459
|
-
}, "cache");
|
|
460
|
-
}
|
|
461
|
-
__name(createCache, "createCache");
|
|
462
|
-
function onThrow(fn, options) {
|
|
463
|
-
const opts = {
|
|
464
|
-
...v3.defaultRetryOptions,
|
|
465
|
-
...options
|
|
466
|
-
};
|
|
467
|
-
return tracer.startActiveSpan(`retry.onThrow()`, async (span) => {
|
|
468
|
-
let attempt = 1;
|
|
469
|
-
while (attempt <= opts.maxAttempts) {
|
|
470
|
-
const innerSpan = tracer.startSpan("retry.fn()", {
|
|
471
|
-
attributes: {
|
|
472
|
-
[v3.SemanticInternalAttributes.STYLE_ICON]: "function",
|
|
473
|
-
...v3.accessoryAttributes({
|
|
474
|
-
items: [
|
|
475
|
-
{
|
|
476
|
-
text: `${attempt}/${opts.maxAttempts}`,
|
|
477
|
-
variant: "normal"
|
|
478
|
-
}
|
|
479
|
-
],
|
|
480
|
-
style: "codepath"
|
|
481
|
-
})
|
|
482
|
-
}
|
|
483
|
-
});
|
|
484
|
-
const contextWithSpanSet = api.trace.setSpan(api.context.active(), innerSpan);
|
|
485
|
-
try {
|
|
486
|
-
const result = await api.context.with(contextWithSpanSet, async () => {
|
|
487
|
-
return fn({
|
|
488
|
-
attempt,
|
|
489
|
-
maxAttempts: opts.maxAttempts
|
|
490
|
-
});
|
|
491
|
-
});
|
|
492
|
-
innerSpan.end();
|
|
493
|
-
return result;
|
|
494
|
-
} catch (e) {
|
|
495
|
-
if (e instanceof Error || typeof e === "string") {
|
|
496
|
-
innerSpan.recordException(e);
|
|
497
|
-
} else {
|
|
498
|
-
innerSpan.recordException(String(e));
|
|
499
|
-
}
|
|
500
|
-
innerSpan.setStatus({
|
|
501
|
-
code: api.SpanStatusCode.ERROR
|
|
502
|
-
});
|
|
503
|
-
const nextRetryDelay = v3.calculateNextRetryDelay(opts, attempt);
|
|
504
|
-
if (!nextRetryDelay) {
|
|
505
|
-
innerSpan.end();
|
|
506
|
-
throw e;
|
|
507
|
-
}
|
|
508
|
-
innerSpan.setAttribute(v3.SemanticInternalAttributes.RETRY_AT, new Date(Date.now() + nextRetryDelay).toISOString());
|
|
509
|
-
innerSpan.setAttribute(v3.SemanticInternalAttributes.RETRY_COUNT, attempt);
|
|
510
|
-
innerSpan.setAttribute(v3.SemanticInternalAttributes.RETRY_DELAY, `${nextRetryDelay}ms`);
|
|
511
|
-
innerSpan.end();
|
|
512
|
-
await v3.runtime.waitForDuration(nextRetryDelay);
|
|
513
|
-
} finally {
|
|
514
|
-
attempt++;
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
throw new Error("Max attempts reached");
|
|
518
|
-
}, {
|
|
519
|
-
attributes: {
|
|
520
|
-
[v3.SemanticInternalAttributes.STYLE_ICON]: "arrow-capsule"
|
|
521
|
-
}
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
|
-
__name(onThrow, "onThrow");
|
|
525
|
-
var normalizeUrlFromInput = /* @__PURE__ */ __name((input) => {
|
|
526
|
-
if (typeof input === "string") {
|
|
527
|
-
return new URL(input);
|
|
152
|
+
__name(onThrow, "onThrow");
|
|
153
|
+
var normalizeUrlFromInput = /* @__PURE__ */ __name((input) => {
|
|
154
|
+
if (typeof input === "string") {
|
|
155
|
+
return new URL(input);
|
|
528
156
|
}
|
|
529
157
|
if (input instanceof URL) {
|
|
530
158
|
return input;
|
|
@@ -878,15 +506,1472 @@ var retry = {
|
|
|
878
506
|
fetch: retryFetch,
|
|
879
507
|
interceptFetch
|
|
880
508
|
};
|
|
881
|
-
|
|
882
|
-
|
|
509
|
+
var runs = {
|
|
510
|
+
replay: replayRun,
|
|
511
|
+
cancel: cancelRun,
|
|
512
|
+
retrieve: retrieveRun,
|
|
513
|
+
list: listRuns,
|
|
514
|
+
reschedule: rescheduleRun,
|
|
515
|
+
poll
|
|
516
|
+
};
|
|
517
|
+
function listRuns(paramsOrProjectRef, paramsOrOptions, requestOptions) {
|
|
518
|
+
const apiClient = v3.apiClientManager.client;
|
|
519
|
+
if (!apiClient) {
|
|
520
|
+
throw apiClientMissingError();
|
|
521
|
+
}
|
|
522
|
+
const $requestOptions = listRunsRequestOptions(paramsOrProjectRef, paramsOrOptions, requestOptions);
|
|
523
|
+
if (typeof paramsOrProjectRef === "string") {
|
|
524
|
+
if (v3.isRequestOptions(paramsOrOptions)) {
|
|
525
|
+
return apiClient.listProjectRuns(paramsOrProjectRef, {}, $requestOptions);
|
|
526
|
+
} else {
|
|
527
|
+
return apiClient.listProjectRuns(paramsOrProjectRef, paramsOrOptions, $requestOptions);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
return apiClient.listRuns(paramsOrProjectRef, $requestOptions);
|
|
531
|
+
}
|
|
532
|
+
__name(listRuns, "listRuns");
|
|
533
|
+
function listRunsRequestOptions(paramsOrProjectRef, paramsOrOptions, requestOptions) {
|
|
534
|
+
if (typeof paramsOrProjectRef === "string") {
|
|
535
|
+
if (v3.isRequestOptions(paramsOrOptions)) {
|
|
536
|
+
return v3.mergeRequestOptions({
|
|
537
|
+
tracer,
|
|
538
|
+
name: "runs.list()",
|
|
539
|
+
icon: "runs",
|
|
540
|
+
attributes: {
|
|
541
|
+
projectRef: paramsOrProjectRef,
|
|
542
|
+
...v3.accessoryAttributes({
|
|
543
|
+
items: [
|
|
544
|
+
{
|
|
545
|
+
text: paramsOrProjectRef,
|
|
546
|
+
variant: "normal"
|
|
547
|
+
}
|
|
548
|
+
],
|
|
549
|
+
style: "codepath"
|
|
550
|
+
})
|
|
551
|
+
}
|
|
552
|
+
}, paramsOrOptions);
|
|
553
|
+
} else {
|
|
554
|
+
return v3.mergeRequestOptions({
|
|
555
|
+
tracer,
|
|
556
|
+
name: "runs.list()",
|
|
557
|
+
icon: "runs",
|
|
558
|
+
attributes: {
|
|
559
|
+
projectRef: paramsOrProjectRef,
|
|
560
|
+
...v3.flattenAttributes(paramsOrOptions, "queryParams"),
|
|
561
|
+
...v3.accessoryAttributes({
|
|
562
|
+
items: [
|
|
563
|
+
{
|
|
564
|
+
text: paramsOrProjectRef,
|
|
565
|
+
variant: "normal"
|
|
566
|
+
}
|
|
567
|
+
],
|
|
568
|
+
style: "codepath"
|
|
569
|
+
})
|
|
570
|
+
}
|
|
571
|
+
}, requestOptions);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
return v3.mergeRequestOptions({
|
|
575
|
+
tracer,
|
|
576
|
+
name: "runs.list()",
|
|
577
|
+
icon: "runs",
|
|
578
|
+
attributes: {
|
|
579
|
+
...v3.flattenAttributes(paramsOrProjectRef, "queryParams")
|
|
580
|
+
}
|
|
581
|
+
}, v3.isRequestOptions(paramsOrOptions) ? paramsOrOptions : requestOptions);
|
|
582
|
+
}
|
|
583
|
+
__name(listRunsRequestOptions, "listRunsRequestOptions");
|
|
584
|
+
function retrieveRun(runId, requestOptions) {
|
|
585
|
+
const apiClient = v3.apiClientManager.client;
|
|
586
|
+
if (!apiClient) {
|
|
587
|
+
throw apiClientMissingError();
|
|
588
|
+
}
|
|
589
|
+
const $requestOptions = v3.mergeRequestOptions({
|
|
590
|
+
tracer,
|
|
591
|
+
name: "runs.retrieve()",
|
|
592
|
+
icon: "runs",
|
|
593
|
+
attributes: {
|
|
594
|
+
runId: typeof runId === "string" ? runId : runId.id,
|
|
595
|
+
...v3.accessoryAttributes({
|
|
596
|
+
items: [
|
|
597
|
+
{
|
|
598
|
+
text: typeof runId === "string" ? runId : runId.id,
|
|
599
|
+
variant: "normal"
|
|
600
|
+
}
|
|
601
|
+
],
|
|
602
|
+
style: "codepath"
|
|
603
|
+
})
|
|
604
|
+
}
|
|
605
|
+
}, requestOptions);
|
|
606
|
+
if (typeof runId === "string") {
|
|
607
|
+
return apiClient.retrieveRun(runId, $requestOptions);
|
|
608
|
+
} else {
|
|
609
|
+
return apiClient.retrieveRun(runId.id, $requestOptions);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
__name(retrieveRun, "retrieveRun");
|
|
613
|
+
function replayRun(runId, requestOptions) {
|
|
614
|
+
const apiClient = v3.apiClientManager.client;
|
|
615
|
+
if (!apiClient) {
|
|
616
|
+
throw apiClientMissingError();
|
|
617
|
+
}
|
|
618
|
+
const $requestOptions = v3.mergeRequestOptions({
|
|
619
|
+
tracer,
|
|
620
|
+
name: "runs.replay()",
|
|
621
|
+
icon: "runs",
|
|
622
|
+
attributes: {
|
|
623
|
+
runId,
|
|
624
|
+
...v3.accessoryAttributes({
|
|
625
|
+
items: [
|
|
626
|
+
{
|
|
627
|
+
text: runId,
|
|
628
|
+
variant: "normal"
|
|
629
|
+
}
|
|
630
|
+
],
|
|
631
|
+
style: "codepath"
|
|
632
|
+
})
|
|
633
|
+
}
|
|
634
|
+
}, requestOptions);
|
|
635
|
+
return apiClient.replayRun(runId, $requestOptions);
|
|
636
|
+
}
|
|
637
|
+
__name(replayRun, "replayRun");
|
|
638
|
+
function cancelRun(runId, requestOptions) {
|
|
639
|
+
const apiClient = v3.apiClientManager.client;
|
|
640
|
+
if (!apiClient) {
|
|
641
|
+
throw apiClientMissingError();
|
|
642
|
+
}
|
|
643
|
+
const $requestOptions = v3.mergeRequestOptions({
|
|
644
|
+
tracer,
|
|
645
|
+
name: "runs.cancel()",
|
|
646
|
+
icon: "runs",
|
|
647
|
+
attributes: {
|
|
648
|
+
runId,
|
|
649
|
+
...v3.accessoryAttributes({
|
|
650
|
+
items: [
|
|
651
|
+
{
|
|
652
|
+
text: runId,
|
|
653
|
+
variant: "normal"
|
|
654
|
+
}
|
|
655
|
+
],
|
|
656
|
+
style: "codepath"
|
|
657
|
+
})
|
|
658
|
+
}
|
|
659
|
+
}, requestOptions);
|
|
660
|
+
return apiClient.cancelRun(runId, $requestOptions);
|
|
661
|
+
}
|
|
662
|
+
__name(cancelRun, "cancelRun");
|
|
663
|
+
function rescheduleRun(runId, body, requestOptions) {
|
|
664
|
+
const apiClient = v3.apiClientManager.client;
|
|
665
|
+
if (!apiClient) {
|
|
666
|
+
throw apiClientMissingError();
|
|
667
|
+
}
|
|
668
|
+
const $requestOptions = v3.mergeRequestOptions({
|
|
669
|
+
tracer,
|
|
670
|
+
name: "runs.reschedule()",
|
|
671
|
+
icon: "runs",
|
|
672
|
+
attributes: {
|
|
673
|
+
runId,
|
|
674
|
+
...v3.accessoryAttributes({
|
|
675
|
+
items: [
|
|
676
|
+
{
|
|
677
|
+
text: runId,
|
|
678
|
+
variant: "normal"
|
|
679
|
+
}
|
|
680
|
+
],
|
|
681
|
+
style: "codepath"
|
|
682
|
+
})
|
|
683
|
+
}
|
|
684
|
+
}, requestOptions);
|
|
685
|
+
return apiClient.rescheduleRun(runId, body, $requestOptions);
|
|
686
|
+
}
|
|
687
|
+
__name(rescheduleRun, "rescheduleRun");
|
|
688
|
+
var MAX_POLL_ATTEMPTS = 500;
|
|
689
|
+
async function poll(handle, options, requestOptions) {
|
|
690
|
+
let attempts = 0;
|
|
691
|
+
while (attempts++ < MAX_POLL_ATTEMPTS) {
|
|
692
|
+
const run = await runs.retrieve(handle, requestOptions);
|
|
693
|
+
if (run.isCompleted) {
|
|
694
|
+
return run;
|
|
695
|
+
}
|
|
696
|
+
await new Promise((resolve) => setTimeout(resolve, options?.pollIntervalMs ?? 1e3));
|
|
697
|
+
}
|
|
698
|
+
throw new Error(`Run ${handle} did not complete after ${MAX_POLL_ATTEMPTS} attempts`);
|
|
699
|
+
}
|
|
700
|
+
__name(poll, "poll");
|
|
701
|
+
var idempotencyKeys = {
|
|
702
|
+
create: createIdempotencyKey
|
|
703
|
+
};
|
|
704
|
+
function isIdempotencyKey(value) {
|
|
705
|
+
return typeof value === "string" && value.length === 64;
|
|
706
|
+
}
|
|
707
|
+
__name(isIdempotencyKey, "isIdempotencyKey");
|
|
708
|
+
async function createIdempotencyKey(key, options) {
|
|
709
|
+
const idempotencyKey = await generateIdempotencyKey([
|
|
710
|
+
...Array.isArray(key) ? key : [
|
|
711
|
+
key
|
|
712
|
+
]
|
|
713
|
+
].concat(injectScope(options?.scope ?? "run")));
|
|
714
|
+
return idempotencyKey;
|
|
715
|
+
}
|
|
716
|
+
__name(createIdempotencyKey, "createIdempotencyKey");
|
|
717
|
+
function injectScope(scope) {
|
|
718
|
+
switch (scope) {
|
|
719
|
+
case "run": {
|
|
720
|
+
if (v3.taskContext?.ctx) {
|
|
721
|
+
return [
|
|
722
|
+
v3.taskContext.ctx.run.id
|
|
723
|
+
];
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
case "attempt": {
|
|
727
|
+
if (v3.taskContext?.ctx) {
|
|
728
|
+
return [
|
|
729
|
+
v3.taskContext.ctx.attempt.id
|
|
730
|
+
];
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
return [];
|
|
735
|
+
}
|
|
736
|
+
__name(injectScope, "injectScope");
|
|
737
|
+
async function generateIdempotencyKey(keyMaterial) {
|
|
738
|
+
const hash = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(keyMaterial.join("-")));
|
|
739
|
+
return Array.from(new Uint8Array(hash)).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
740
|
+
}
|
|
741
|
+
__name(generateIdempotencyKey, "generateIdempotencyKey");
|
|
742
|
+
|
|
743
|
+
// src/v3/shared.ts
|
|
744
|
+
function queue(options) {
|
|
745
|
+
return options;
|
|
746
|
+
}
|
|
747
|
+
__name(queue, "queue");
|
|
748
|
+
function createTask(params) {
|
|
749
|
+
const task3 = {
|
|
750
|
+
id: params.id,
|
|
751
|
+
trigger: async (payload, options) => {
|
|
752
|
+
const apiClient = v3.apiClientManager.client;
|
|
753
|
+
if (!apiClient) {
|
|
754
|
+
throw apiClientMissingError();
|
|
755
|
+
}
|
|
756
|
+
const taskMetadata = v3.taskCatalog.getTaskMetadata(params.id);
|
|
757
|
+
const payloadPacket = await v3.stringifyIO(payload);
|
|
758
|
+
const handle = await apiClient.triggerTask(params.id, {
|
|
759
|
+
payload: payloadPacket.data,
|
|
760
|
+
options: {
|
|
761
|
+
queue: options?.queue ?? params.queue,
|
|
762
|
+
concurrencyKey: options?.concurrencyKey,
|
|
763
|
+
test: v3.taskContext.ctx?.run.isTest,
|
|
764
|
+
payloadType: payloadPacket.dataType,
|
|
765
|
+
idempotencyKey: await makeKey(options?.idempotencyKey),
|
|
766
|
+
delay: options?.delay,
|
|
767
|
+
ttl: options?.ttl,
|
|
768
|
+
maxAttempts: options?.maxAttempts
|
|
769
|
+
}
|
|
770
|
+
}, {
|
|
771
|
+
spanParentAsLink: true
|
|
772
|
+
}, {
|
|
773
|
+
name: taskMetadata ? `${taskMetadata.exportName}.trigger()` : `trigger()`,
|
|
774
|
+
tracer,
|
|
775
|
+
icon: "trigger",
|
|
776
|
+
attributes: {
|
|
777
|
+
[semanticConventions.SEMATTRS_MESSAGING_OPERATION]: "publish",
|
|
778
|
+
["messaging.client_id"]: v3.taskContext.worker?.id,
|
|
779
|
+
[semanticConventions.SEMATTRS_MESSAGING_DESTINATION]: params.queue?.name ?? params.id,
|
|
780
|
+
[semanticConventions.SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
|
|
781
|
+
...v3.accessoryAttributes({
|
|
782
|
+
items: [
|
|
783
|
+
{
|
|
784
|
+
text: params.id,
|
|
785
|
+
variant: "normal"
|
|
786
|
+
}
|
|
787
|
+
],
|
|
788
|
+
style: "codepath"
|
|
789
|
+
})
|
|
790
|
+
},
|
|
791
|
+
onResponseBody: (body, span) => {
|
|
792
|
+
body && typeof body === "object" && !Array.isArray(body) && "id" in body && typeof body.id === "string" && span.setAttribute("messaging.message.id", body.id);
|
|
793
|
+
}
|
|
794
|
+
});
|
|
795
|
+
return handle;
|
|
796
|
+
},
|
|
797
|
+
batchTrigger: async (items) => {
|
|
798
|
+
const apiClient = v3.apiClientManager.client;
|
|
799
|
+
if (!apiClient) {
|
|
800
|
+
throw apiClientMissingError();
|
|
801
|
+
}
|
|
802
|
+
const taskMetadata = v3.taskCatalog.getTaskMetadata(params.id);
|
|
803
|
+
const response = await apiClient.batchTriggerTask(params.id, {
|
|
804
|
+
items: await Promise.all(items.map(async (item) => {
|
|
805
|
+
const payloadPacket = await v3.stringifyIO(item.payload);
|
|
806
|
+
return {
|
|
807
|
+
payload: payloadPacket.data,
|
|
808
|
+
options: {
|
|
809
|
+
queue: item.options?.queue ?? params.queue,
|
|
810
|
+
concurrencyKey: item.options?.concurrencyKey,
|
|
811
|
+
test: v3.taskContext.ctx?.run.isTest,
|
|
812
|
+
payloadType: payloadPacket.dataType,
|
|
813
|
+
idempotencyKey: await makeKey(item.options?.idempotencyKey),
|
|
814
|
+
delay: item.options?.delay,
|
|
815
|
+
ttl: item.options?.ttl,
|
|
816
|
+
maxAttempts: item.options?.maxAttempts
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
}))
|
|
820
|
+
}, {
|
|
821
|
+
spanParentAsLink: true
|
|
822
|
+
}, {
|
|
823
|
+
name: taskMetadata ? `${taskMetadata.exportName}.batchTrigger()` : `batchTrigger()`,
|
|
824
|
+
icon: "trigger",
|
|
825
|
+
tracer,
|
|
826
|
+
attributes: {
|
|
827
|
+
[semanticConventions.SEMATTRS_MESSAGING_OPERATION]: "publish",
|
|
828
|
+
["messaging.batch.message_count"]: items.length,
|
|
829
|
+
["messaging.client_id"]: v3.taskContext.worker?.id,
|
|
830
|
+
[semanticConventions.SEMATTRS_MESSAGING_DESTINATION]: params.queue?.name ?? params.id,
|
|
831
|
+
[semanticConventions.SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
|
|
832
|
+
...v3.accessoryAttributes({
|
|
833
|
+
items: [
|
|
834
|
+
{
|
|
835
|
+
text: params.id,
|
|
836
|
+
variant: "normal"
|
|
837
|
+
}
|
|
838
|
+
],
|
|
839
|
+
style: "codepath"
|
|
840
|
+
})
|
|
841
|
+
}
|
|
842
|
+
});
|
|
843
|
+
const handle = {
|
|
844
|
+
batchId: response.batchId,
|
|
845
|
+
runs: response.runs.map((id) => ({
|
|
846
|
+
id
|
|
847
|
+
}))
|
|
848
|
+
};
|
|
849
|
+
return handle;
|
|
850
|
+
},
|
|
851
|
+
triggerAndWait: async (payload, options) => {
|
|
852
|
+
const ctx = v3.taskContext.ctx;
|
|
853
|
+
if (!ctx) {
|
|
854
|
+
throw new Error("triggerAndWait can only be used from inside a task.run()");
|
|
855
|
+
}
|
|
856
|
+
const apiClient = v3.apiClientManager.client;
|
|
857
|
+
if (!apiClient) {
|
|
858
|
+
throw apiClientMissingError();
|
|
859
|
+
}
|
|
860
|
+
const taskMetadata = v3.taskCatalog.getTaskMetadata(params.id);
|
|
861
|
+
const payloadPacket = await v3.stringifyIO(payload);
|
|
862
|
+
return await tracer.startActiveSpan(taskMetadata ? `${taskMetadata.exportName}.triggerAndWait()` : `triggerAndWait()`, async (span) => {
|
|
863
|
+
const response = await apiClient.triggerTask(params.id, {
|
|
864
|
+
payload: payloadPacket.data,
|
|
865
|
+
options: {
|
|
866
|
+
dependentAttempt: ctx.attempt.id,
|
|
867
|
+
lockToVersion: v3.taskContext.worker?.version,
|
|
868
|
+
queue: options?.queue ?? params.queue,
|
|
869
|
+
concurrencyKey: options?.concurrencyKey,
|
|
870
|
+
test: v3.taskContext.ctx?.run.isTest,
|
|
871
|
+
payloadType: payloadPacket.dataType,
|
|
872
|
+
idempotencyKey: await makeKey(options?.idempotencyKey),
|
|
873
|
+
delay: options?.delay,
|
|
874
|
+
ttl: options?.ttl,
|
|
875
|
+
maxAttempts: options?.maxAttempts
|
|
876
|
+
}
|
|
877
|
+
});
|
|
878
|
+
span.setAttribute("messaging.message.id", response.id);
|
|
879
|
+
if (options?.idempotencyKey) {
|
|
880
|
+
const result2 = await apiClient.getRunResult(response.id);
|
|
881
|
+
if (result2) {
|
|
882
|
+
v3.logger.log(`Result reused from previous task run with idempotency key '${options.idempotencyKey}'.`, {
|
|
883
|
+
runId: response.id,
|
|
884
|
+
idempotencyKey: options.idempotencyKey
|
|
885
|
+
});
|
|
886
|
+
return await handleTaskRunExecutionResult(result2);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
const result = await v3.runtime.waitForTask({
|
|
890
|
+
id: response.id,
|
|
891
|
+
ctx
|
|
892
|
+
});
|
|
893
|
+
return await handleTaskRunExecutionResult(result);
|
|
894
|
+
}, {
|
|
895
|
+
kind: api.SpanKind.PRODUCER,
|
|
896
|
+
attributes: {
|
|
897
|
+
[v3.SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
898
|
+
[semanticConventions.SEMATTRS_MESSAGING_OPERATION]: "publish",
|
|
899
|
+
["messaging.client_id"]: v3.taskContext.worker?.id,
|
|
900
|
+
[semanticConventions.SEMATTRS_MESSAGING_DESTINATION]: params.queue?.name ?? params.id,
|
|
901
|
+
[semanticConventions.SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
|
|
902
|
+
...v3.accessoryAttributes({
|
|
903
|
+
items: [
|
|
904
|
+
{
|
|
905
|
+
text: params.id,
|
|
906
|
+
variant: "normal"
|
|
907
|
+
}
|
|
908
|
+
],
|
|
909
|
+
style: "codepath"
|
|
910
|
+
})
|
|
911
|
+
}
|
|
912
|
+
});
|
|
913
|
+
},
|
|
914
|
+
batchTriggerAndWait: async (items) => {
|
|
915
|
+
const ctx = v3.taskContext.ctx;
|
|
916
|
+
if (!ctx) {
|
|
917
|
+
throw new Error("batchTriggerAndWait can only be used from inside a task.run()");
|
|
918
|
+
}
|
|
919
|
+
const apiClient = v3.apiClientManager.client;
|
|
920
|
+
if (!apiClient) {
|
|
921
|
+
throw apiClientMissingError();
|
|
922
|
+
}
|
|
923
|
+
const taskMetadata = v3.taskCatalog.getTaskMetadata(params.id);
|
|
924
|
+
return await tracer.startActiveSpan(taskMetadata ? `${taskMetadata.exportName}.batchTriggerAndWait()` : `batchTriggerAndWait()`, async (span) => {
|
|
925
|
+
const response = await apiClient.batchTriggerTask(params.id, {
|
|
926
|
+
items: await Promise.all(items.map(async (item) => {
|
|
927
|
+
const payloadPacket = await v3.stringifyIO(item.payload);
|
|
928
|
+
return {
|
|
929
|
+
payload: payloadPacket.data,
|
|
930
|
+
options: {
|
|
931
|
+
lockToVersion: v3.taskContext.worker?.version,
|
|
932
|
+
queue: item.options?.queue ?? params.queue,
|
|
933
|
+
concurrencyKey: item.options?.concurrencyKey,
|
|
934
|
+
test: v3.taskContext.ctx?.run.isTest,
|
|
935
|
+
payloadType: payloadPacket.dataType,
|
|
936
|
+
idempotencyKey: await makeKey(item.options?.idempotencyKey),
|
|
937
|
+
delay: item.options?.delay,
|
|
938
|
+
ttl: item.options?.ttl,
|
|
939
|
+
maxAttempts: item.options?.maxAttempts
|
|
940
|
+
}
|
|
941
|
+
};
|
|
942
|
+
})),
|
|
943
|
+
dependentAttempt: ctx.attempt.id
|
|
944
|
+
});
|
|
945
|
+
span.setAttribute("messaging.message.id", response.batchId);
|
|
946
|
+
const getBatchResults = /* @__PURE__ */ __name(async () => {
|
|
947
|
+
const hasIdempotencyKey = items.some((item) => item.options?.idempotencyKey);
|
|
948
|
+
if (hasIdempotencyKey) {
|
|
949
|
+
const results = await apiClient.getBatchResults(response.batchId);
|
|
950
|
+
if (results) {
|
|
951
|
+
return results;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
return {
|
|
955
|
+
id: response.batchId,
|
|
956
|
+
items: []
|
|
957
|
+
};
|
|
958
|
+
}, "getBatchResults");
|
|
959
|
+
const existingResults = await getBatchResults();
|
|
960
|
+
const incompleteRuns = response.runs.filter((runId) => !existingResults.items.some((item) => item.id === runId));
|
|
961
|
+
if (incompleteRuns.length === 0) {
|
|
962
|
+
v3.logger.log(`Results reused from previous task runs because of the provided idempotency keys.`);
|
|
963
|
+
const runs3 = await handleBatchTaskRunExecutionResult(existingResults.items);
|
|
964
|
+
return {
|
|
965
|
+
id: existingResults.id,
|
|
966
|
+
runs: runs3
|
|
967
|
+
};
|
|
968
|
+
}
|
|
969
|
+
const result = await v3.runtime.waitForBatch({
|
|
970
|
+
id: response.batchId,
|
|
971
|
+
runs: incompleteRuns,
|
|
972
|
+
ctx
|
|
973
|
+
});
|
|
974
|
+
const combinedItems = [];
|
|
975
|
+
for (const runId of response.runs) {
|
|
976
|
+
const existingItem = existingResults.items.find((item) => item.id === runId);
|
|
977
|
+
if (existingItem) {
|
|
978
|
+
combinedItems.push(existingItem);
|
|
979
|
+
} else {
|
|
980
|
+
const newItem = result.items.find((item) => item.id === runId);
|
|
981
|
+
if (newItem) {
|
|
982
|
+
combinedItems.push(newItem);
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
const runs2 = await handleBatchTaskRunExecutionResult(combinedItems);
|
|
987
|
+
return {
|
|
988
|
+
id: result.id,
|
|
989
|
+
runs: runs2
|
|
990
|
+
};
|
|
991
|
+
}, {
|
|
992
|
+
kind: api.SpanKind.PRODUCER,
|
|
993
|
+
attributes: {
|
|
994
|
+
[semanticConventions.SEMATTRS_MESSAGING_OPERATION]: "publish",
|
|
995
|
+
["messaging.batch.message_count"]: items.length,
|
|
996
|
+
["messaging.client_id"]: v3.taskContext.worker?.id,
|
|
997
|
+
[semanticConventions.SEMATTRS_MESSAGING_DESTINATION]: params.queue?.name ?? params.id,
|
|
998
|
+
[semanticConventions.SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
|
|
999
|
+
[v3.SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
1000
|
+
...v3.accessoryAttributes({
|
|
1001
|
+
items: [
|
|
1002
|
+
{
|
|
1003
|
+
text: params.id,
|
|
1004
|
+
variant: "normal"
|
|
1005
|
+
}
|
|
1006
|
+
],
|
|
1007
|
+
style: "codepath"
|
|
1008
|
+
})
|
|
1009
|
+
}
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
v3.taskCatalog.registerTaskMetadata({
|
|
1014
|
+
id: params.id,
|
|
1015
|
+
packageVersion: version,
|
|
1016
|
+
queue: params.queue,
|
|
1017
|
+
retry: params.retry ? {
|
|
1018
|
+
...v3.defaultRetryOptions,
|
|
1019
|
+
...params.retry
|
|
1020
|
+
} : void 0,
|
|
1021
|
+
machine: params.machine,
|
|
1022
|
+
fns: {
|
|
1023
|
+
run: params.run,
|
|
1024
|
+
init: params.init,
|
|
1025
|
+
cleanup: params.cleanup,
|
|
1026
|
+
middleware: params.middleware,
|
|
1027
|
+
handleError: params.handleError,
|
|
1028
|
+
onSuccess: params.onSuccess,
|
|
1029
|
+
onFailure: params.onFailure,
|
|
1030
|
+
onStart: params.onStart
|
|
1031
|
+
}
|
|
1032
|
+
});
|
|
1033
|
+
return task3;
|
|
1034
|
+
}
|
|
1035
|
+
__name(createTask, "createTask");
|
|
1036
|
+
async function trigger(id, payload, options, requestOptions) {
|
|
1037
|
+
const apiClient = v3.apiClientManager.client;
|
|
1038
|
+
if (!apiClient) {
|
|
1039
|
+
throw apiClientMissingError();
|
|
1040
|
+
}
|
|
1041
|
+
const payloadPacket = await v3.stringifyIO(payload);
|
|
1042
|
+
const handle = await apiClient.triggerTask(id, {
|
|
1043
|
+
payload: payloadPacket.data,
|
|
1044
|
+
options: {
|
|
1045
|
+
queue: options?.queue,
|
|
1046
|
+
concurrencyKey: options?.concurrencyKey,
|
|
1047
|
+
test: v3.taskContext.ctx?.run.isTest,
|
|
1048
|
+
payloadType: payloadPacket.dataType,
|
|
1049
|
+
idempotencyKey: await makeKey(options?.idempotencyKey),
|
|
1050
|
+
delay: options?.delay,
|
|
1051
|
+
ttl: options?.ttl,
|
|
1052
|
+
maxAttempts: options?.maxAttempts
|
|
1053
|
+
}
|
|
1054
|
+
}, {
|
|
1055
|
+
spanParentAsLink: true
|
|
1056
|
+
}, {
|
|
1057
|
+
name: `tasks.trigger()`,
|
|
1058
|
+
tracer,
|
|
1059
|
+
icon: "trigger",
|
|
1060
|
+
attributes: {
|
|
1061
|
+
[semanticConventions.SEMATTRS_MESSAGING_OPERATION]: "publish",
|
|
1062
|
+
["messaging.client_id"]: v3.taskContext.worker?.id,
|
|
1063
|
+
[semanticConventions.SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
|
|
1064
|
+
...v3.accessoryAttributes({
|
|
1065
|
+
items: [
|
|
1066
|
+
{
|
|
1067
|
+
text: id,
|
|
1068
|
+
variant: "normal"
|
|
1069
|
+
}
|
|
1070
|
+
],
|
|
1071
|
+
style: "codepath"
|
|
1072
|
+
})
|
|
1073
|
+
},
|
|
1074
|
+
onResponseBody: (body, span) => {
|
|
1075
|
+
body && typeof body === "object" && !Array.isArray(body) && "id" in body && typeof body.id === "string" && span.setAttribute("messaging.message.id", body.id);
|
|
1076
|
+
},
|
|
1077
|
+
...requestOptions
|
|
1078
|
+
});
|
|
1079
|
+
return handle;
|
|
1080
|
+
}
|
|
1081
|
+
__name(trigger, "trigger");
|
|
1082
|
+
async function triggerAndWait(id, payload, options, requestOptions) {
|
|
1083
|
+
const ctx = v3.taskContext.ctx;
|
|
1084
|
+
if (!ctx) {
|
|
1085
|
+
throw new Error("tasks.triggerAndWait can only be used from inside a task.run()");
|
|
1086
|
+
}
|
|
1087
|
+
const apiClient = v3.apiClientManager.client;
|
|
1088
|
+
if (!apiClient) {
|
|
1089
|
+
throw apiClientMissingError();
|
|
1090
|
+
}
|
|
1091
|
+
const payloadPacket = await v3.stringifyIO(payload);
|
|
1092
|
+
return await tracer.startActiveSpan("tasks.triggerAndWait()", async (span) => {
|
|
1093
|
+
const response = await apiClient.triggerTask(id, {
|
|
1094
|
+
payload: payloadPacket.data,
|
|
1095
|
+
options: {
|
|
1096
|
+
dependentAttempt: ctx.attempt.id,
|
|
1097
|
+
lockToVersion: v3.taskContext.worker?.version,
|
|
1098
|
+
queue: options?.queue,
|
|
1099
|
+
concurrencyKey: options?.concurrencyKey,
|
|
1100
|
+
test: v3.taskContext.ctx?.run.isTest,
|
|
1101
|
+
payloadType: payloadPacket.dataType,
|
|
1102
|
+
idempotencyKey: await makeKey(options?.idempotencyKey),
|
|
1103
|
+
delay: options?.delay,
|
|
1104
|
+
ttl: options?.ttl,
|
|
1105
|
+
maxAttempts: options?.maxAttempts
|
|
1106
|
+
}
|
|
1107
|
+
}, {}, requestOptions);
|
|
1108
|
+
span.setAttribute("messaging.message.id", response.id);
|
|
1109
|
+
if (options?.idempotencyKey) {
|
|
1110
|
+
const result2 = await apiClient.getRunResult(response.id);
|
|
1111
|
+
if (result2) {
|
|
1112
|
+
v3.logger.log(`Result reused from previous task run with idempotency key '${options.idempotencyKey}'.`, {
|
|
1113
|
+
runId: response.id,
|
|
1114
|
+
idempotencyKey: options.idempotencyKey
|
|
1115
|
+
});
|
|
1116
|
+
return await handleTaskRunExecutionResult(result2);
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
const result = await v3.runtime.waitForTask({
|
|
1120
|
+
id: response.id,
|
|
1121
|
+
ctx
|
|
1122
|
+
});
|
|
1123
|
+
return await handleTaskRunExecutionResult(result);
|
|
1124
|
+
}, {
|
|
1125
|
+
kind: api.SpanKind.PRODUCER,
|
|
1126
|
+
attributes: {
|
|
1127
|
+
[v3.SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
1128
|
+
[semanticConventions.SEMATTRS_MESSAGING_OPERATION]: "publish",
|
|
1129
|
+
["messaging.client_id"]: v3.taskContext.worker?.id,
|
|
1130
|
+
[semanticConventions.SEMATTRS_MESSAGING_DESTINATION]: id,
|
|
1131
|
+
[semanticConventions.SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
|
|
1132
|
+
...v3.accessoryAttributes({
|
|
1133
|
+
items: [
|
|
1134
|
+
{
|
|
1135
|
+
text: id,
|
|
1136
|
+
variant: "normal"
|
|
1137
|
+
}
|
|
1138
|
+
],
|
|
1139
|
+
style: "codepath"
|
|
1140
|
+
})
|
|
1141
|
+
}
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
__name(triggerAndWait, "triggerAndWait");
|
|
1145
|
+
async function triggerAndPoll(id, payload, options, requestOptions) {
|
|
1146
|
+
const handle = await trigger(id, payload, options, requestOptions);
|
|
1147
|
+
return runs.poll(handle, options, requestOptions);
|
|
1148
|
+
}
|
|
1149
|
+
__name(triggerAndPoll, "triggerAndPoll");
|
|
1150
|
+
async function batchTrigger(id, items, requestOptions) {
|
|
1151
|
+
const apiClient = v3.apiClientManager.client;
|
|
1152
|
+
if (!apiClient) {
|
|
1153
|
+
throw apiClientMissingError();
|
|
1154
|
+
}
|
|
1155
|
+
const response = await apiClient.batchTriggerTask(id, {
|
|
1156
|
+
items: await Promise.all(items.map(async (item) => {
|
|
1157
|
+
const payloadPacket = await v3.stringifyIO(item.payload);
|
|
1158
|
+
return {
|
|
1159
|
+
payload: payloadPacket.data,
|
|
1160
|
+
options: {
|
|
1161
|
+
queue: item.options?.queue,
|
|
1162
|
+
concurrencyKey: item.options?.concurrencyKey,
|
|
1163
|
+
test: v3.taskContext.ctx?.run.isTest,
|
|
1164
|
+
payloadType: payloadPacket.dataType,
|
|
1165
|
+
idempotencyKey: await makeKey(item.options?.idempotencyKey),
|
|
1166
|
+
delay: item.options?.delay,
|
|
1167
|
+
ttl: item.options?.ttl,
|
|
1168
|
+
maxAttempts: item.options?.maxAttempts
|
|
1169
|
+
}
|
|
1170
|
+
};
|
|
1171
|
+
}))
|
|
1172
|
+
}, {
|
|
1173
|
+
spanParentAsLink: true
|
|
1174
|
+
}, {
|
|
1175
|
+
name: `tasks.batchTrigger()`,
|
|
1176
|
+
tracer,
|
|
1177
|
+
icon: "trigger",
|
|
1178
|
+
attributes: {
|
|
1179
|
+
[semanticConventions.SEMATTRS_MESSAGING_OPERATION]: "publish",
|
|
1180
|
+
["messaging.client_id"]: v3.taskContext.worker?.id,
|
|
1181
|
+
[semanticConventions.SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
|
|
1182
|
+
...v3.accessoryAttributes({
|
|
1183
|
+
items: [
|
|
1184
|
+
{
|
|
1185
|
+
text: id,
|
|
1186
|
+
variant: "normal"
|
|
1187
|
+
}
|
|
1188
|
+
],
|
|
1189
|
+
style: "codepath"
|
|
1190
|
+
})
|
|
1191
|
+
},
|
|
1192
|
+
...requestOptions
|
|
1193
|
+
});
|
|
1194
|
+
const handle = {
|
|
1195
|
+
batchId: response.batchId,
|
|
1196
|
+
runs: response.runs.map((id2) => ({
|
|
1197
|
+
id: id2
|
|
1198
|
+
}))
|
|
1199
|
+
};
|
|
1200
|
+
return handle;
|
|
1201
|
+
}
|
|
1202
|
+
__name(batchTrigger, "batchTrigger");
|
|
1203
|
+
async function handleBatchTaskRunExecutionResult(items) {
|
|
1204
|
+
const someObjectStoreOutputs = items.some((item) => item.ok && item.outputType === "application/store");
|
|
1205
|
+
if (!someObjectStoreOutputs) {
|
|
1206
|
+
const results = await Promise.all(items.map(async (item) => {
|
|
1207
|
+
return await handleTaskRunExecutionResult(item);
|
|
1208
|
+
}));
|
|
1209
|
+
return results;
|
|
1210
|
+
}
|
|
1211
|
+
return await tracer.startActiveSpan("store.downloadPayloads", async (span) => {
|
|
1212
|
+
const results = await Promise.all(items.map(async (item) => {
|
|
1213
|
+
return await handleTaskRunExecutionResult(item);
|
|
1214
|
+
}));
|
|
1215
|
+
return results;
|
|
1216
|
+
}, {
|
|
1217
|
+
kind: api.SpanKind.INTERNAL,
|
|
1218
|
+
[v3.SemanticInternalAttributes.STYLE_ICON]: "cloud-download"
|
|
1219
|
+
});
|
|
1220
|
+
}
|
|
1221
|
+
__name(handleBatchTaskRunExecutionResult, "handleBatchTaskRunExecutionResult");
|
|
1222
|
+
async function handleTaskRunExecutionResult(execution) {
|
|
1223
|
+
if (execution.ok) {
|
|
1224
|
+
const outputPacket = {
|
|
1225
|
+
data: execution.output,
|
|
1226
|
+
dataType: execution.outputType
|
|
1227
|
+
};
|
|
1228
|
+
const importedPacket = await v3.conditionallyImportPacket(outputPacket, tracer);
|
|
1229
|
+
return {
|
|
1230
|
+
ok: true,
|
|
1231
|
+
id: execution.id,
|
|
1232
|
+
output: await v3.parsePacket(importedPacket)
|
|
1233
|
+
};
|
|
1234
|
+
} else {
|
|
1235
|
+
return {
|
|
1236
|
+
ok: false,
|
|
1237
|
+
id: execution.id,
|
|
1238
|
+
error: v3.createErrorTaskError(execution.error)
|
|
1239
|
+
};
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
__name(handleTaskRunExecutionResult, "handleTaskRunExecutionResult");
|
|
1243
|
+
function apiClientMissingError() {
|
|
1244
|
+
const hasBaseUrl = !!v3.apiClientManager.baseURL;
|
|
1245
|
+
const hasAccessToken = !!v3.apiClientManager.accessToken;
|
|
1246
|
+
if (!hasBaseUrl && !hasAccessToken) {
|
|
1247
|
+
return `You need to set the TRIGGER_API_URL and TRIGGER_SECRET_KEY environment variables.`;
|
|
1248
|
+
} else if (!hasBaseUrl) {
|
|
1249
|
+
return `You need to set the TRIGGER_API_URL environment variable.`;
|
|
1250
|
+
} else if (!hasAccessToken) {
|
|
1251
|
+
return `You need to set the TRIGGER_SECRET_KEY environment variable.`;
|
|
1252
|
+
}
|
|
1253
|
+
return `Unknown error`;
|
|
1254
|
+
}
|
|
1255
|
+
__name(apiClientMissingError, "apiClientMissingError");
|
|
1256
|
+
async function makeKey(idempotencyKey) {
|
|
1257
|
+
if (!idempotencyKey) {
|
|
1258
|
+
return;
|
|
1259
|
+
}
|
|
1260
|
+
if (isIdempotencyKey(idempotencyKey)) {
|
|
1261
|
+
return idempotencyKey;
|
|
1262
|
+
}
|
|
1263
|
+
return await idempotencyKeys.create(idempotencyKey, {
|
|
1264
|
+
scope: "global"
|
|
1265
|
+
});
|
|
1266
|
+
}
|
|
1267
|
+
__name(makeKey, "makeKey");
|
|
1268
|
+
|
|
1269
|
+
// src/v3/tasks.ts
|
|
1270
|
+
function task(options) {
|
|
1271
|
+
return createTask(options);
|
|
1272
|
+
}
|
|
1273
|
+
__name(task, "task");
|
|
1274
|
+
var tasks = {
|
|
1275
|
+
trigger,
|
|
1276
|
+
triggerAndPoll,
|
|
1277
|
+
batchTrigger,
|
|
1278
|
+
triggerAndWait
|
|
1279
|
+
};
|
|
1280
|
+
var wait = {
|
|
1281
|
+
for: async (options) => {
|
|
1282
|
+
return tracer.startActiveSpan(`wait.for()`, async (span) => {
|
|
1283
|
+
const durationInMs = calculateDurationInMs(options);
|
|
1284
|
+
await v3.runtime.waitForDuration(durationInMs);
|
|
1285
|
+
}, {
|
|
1286
|
+
attributes: {
|
|
1287
|
+
[v3.SemanticInternalAttributes.STYLE_ICON]: "wait",
|
|
1288
|
+
...v3.accessoryAttributes({
|
|
1289
|
+
items: [
|
|
1290
|
+
{
|
|
1291
|
+
text: nameForWaitOptions(options),
|
|
1292
|
+
variant: "normal"
|
|
1293
|
+
}
|
|
1294
|
+
],
|
|
1295
|
+
style: "codepath"
|
|
1296
|
+
})
|
|
1297
|
+
}
|
|
1298
|
+
});
|
|
1299
|
+
},
|
|
1300
|
+
until: async (options) => {
|
|
1301
|
+
return tracer.startActiveSpan(`wait.until()`, async (span) => {
|
|
1302
|
+
const start = Date.now();
|
|
1303
|
+
if (options.throwIfInThePast && options.date < /* @__PURE__ */ new Date()) {
|
|
1304
|
+
throw new Error("Date is in the past");
|
|
1305
|
+
}
|
|
1306
|
+
const durationInMs = options.date.getTime() - start;
|
|
1307
|
+
await v3.runtime.waitForDuration(durationInMs);
|
|
1308
|
+
}, {
|
|
1309
|
+
attributes: {
|
|
1310
|
+
[v3.SemanticInternalAttributes.STYLE_ICON]: "wait",
|
|
1311
|
+
...v3.accessoryAttributes({
|
|
1312
|
+
items: [
|
|
1313
|
+
{
|
|
1314
|
+
text: options.date.toISOString(),
|
|
1315
|
+
variant: "normal"
|
|
1316
|
+
}
|
|
1317
|
+
],
|
|
1318
|
+
style: "codepath"
|
|
1319
|
+
})
|
|
1320
|
+
}
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1323
|
+
};
|
|
1324
|
+
function nameForWaitOptions(options) {
|
|
1325
|
+
if ("seconds" in options) {
|
|
1326
|
+
return options.seconds === 1 ? `1 second` : `${options.seconds} seconds`;
|
|
1327
|
+
}
|
|
1328
|
+
if ("minutes" in options) {
|
|
1329
|
+
return options.minutes === 1 ? `1 minute` : `${options.minutes} minutes`;
|
|
1330
|
+
}
|
|
1331
|
+
if ("hours" in options) {
|
|
1332
|
+
return options.hours === 1 ? `1 hour` : `${options.hours} hours`;
|
|
1333
|
+
}
|
|
1334
|
+
if ("days" in options) {
|
|
1335
|
+
return options.days === 1 ? `1 day` : `${options.days} days`;
|
|
1336
|
+
}
|
|
1337
|
+
if ("weeks" in options) {
|
|
1338
|
+
return options.weeks === 1 ? `1 week` : `${options.weeks} weeks`;
|
|
1339
|
+
}
|
|
1340
|
+
if ("months" in options) {
|
|
1341
|
+
return options.months === 1 ? `1 month` : `${options.months} months`;
|
|
1342
|
+
}
|
|
1343
|
+
if ("years" in options) {
|
|
1344
|
+
return options.years === 1 ? `1 year` : `${options.years} years`;
|
|
1345
|
+
}
|
|
1346
|
+
return "NaN";
|
|
1347
|
+
}
|
|
1348
|
+
__name(nameForWaitOptions, "nameForWaitOptions");
|
|
1349
|
+
function calculateDurationInMs(options) {
|
|
1350
|
+
if ("seconds" in options) {
|
|
1351
|
+
return options.seconds * 1e3;
|
|
1352
|
+
}
|
|
1353
|
+
if ("minutes" in options) {
|
|
1354
|
+
return options.minutes * 1e3 * 60;
|
|
1355
|
+
}
|
|
1356
|
+
if ("hours" in options) {
|
|
1357
|
+
return options.hours * 1e3 * 60 * 60;
|
|
1358
|
+
}
|
|
1359
|
+
if ("days" in options) {
|
|
1360
|
+
return options.days * 1e3 * 60 * 60 * 24;
|
|
1361
|
+
}
|
|
1362
|
+
if ("weeks" in options) {
|
|
1363
|
+
return options.weeks * 1e3 * 60 * 60 * 24 * 7;
|
|
1364
|
+
}
|
|
1365
|
+
if ("months" in options) {
|
|
1366
|
+
return options.months * 1e3 * 60 * 60 * 24 * 30;
|
|
1367
|
+
}
|
|
1368
|
+
if ("years" in options) {
|
|
1369
|
+
return options.years * 1e3 * 60 * 60 * 24 * 365;
|
|
1370
|
+
}
|
|
1371
|
+
throw new Error("Invalid options");
|
|
1372
|
+
}
|
|
1373
|
+
__name(calculateDurationInMs, "calculateDurationInMs");
|
|
1374
|
+
var usage = {
|
|
1375
|
+
/**
|
|
1376
|
+
* Get the current running usage of this task run.
|
|
1377
|
+
*
|
|
1378
|
+
* @example
|
|
1379
|
+
*
|
|
1380
|
+
* ```typescript
|
|
1381
|
+
* import { usage, task } from "@trigger.dev/sdk/v3";
|
|
1382
|
+
*
|
|
1383
|
+
* export const myTask = task({
|
|
1384
|
+
* id: "my-task",
|
|
1385
|
+
* run: async (payload, { ctx }) => {
|
|
1386
|
+
* // ... Do a bunch of work
|
|
1387
|
+
*
|
|
1388
|
+
* const currentUsage = usage.getCurrent();
|
|
1389
|
+
*
|
|
1390
|
+
* // You have access to the current compute cost and duration up to this point
|
|
1391
|
+
* console.log("Current attempt compute cost and duration", {
|
|
1392
|
+
* cost: currentUsage.compute.attempt.costInCents,
|
|
1393
|
+
* duration: currentUsage.compute.attempt.durationMs,
|
|
1394
|
+
* });
|
|
1395
|
+
*
|
|
1396
|
+
* // You also can see the total compute cost and duration up to this point in the run, across all attempts
|
|
1397
|
+
* console.log("Current total compute cost and duration", {
|
|
1398
|
+
* cost: currentUsage.compute.total.costInCents,
|
|
1399
|
+
* duration: currentUsage.compute.total.durationMs,
|
|
1400
|
+
* });
|
|
1401
|
+
*
|
|
1402
|
+
* // You can see the base cost of the run, which is the cost of the run before any compute costs
|
|
1403
|
+
* console.log("Total cost", {
|
|
1404
|
+
* cost: currentUsage.totalCostInCents,
|
|
1405
|
+
* baseCost: currentUsage.baseCostInCents,
|
|
1406
|
+
* });
|
|
1407
|
+
* },
|
|
1408
|
+
* });
|
|
1409
|
+
* ```
|
|
1410
|
+
*/
|
|
1411
|
+
getCurrent: () => {
|
|
1412
|
+
const sample = v3.usage.sample();
|
|
1413
|
+
const machine = v3.taskContext.ctx?.machine;
|
|
1414
|
+
const run = v3.taskContext.ctx?.run;
|
|
1415
|
+
if (!sample) {
|
|
1416
|
+
return {
|
|
1417
|
+
compute: {
|
|
1418
|
+
attempt: {
|
|
1419
|
+
costInCents: 0,
|
|
1420
|
+
durationMs: 0
|
|
1421
|
+
},
|
|
1422
|
+
total: {
|
|
1423
|
+
costInCents: run?.costInCents ?? 0,
|
|
1424
|
+
durationMs: run?.durationMs ?? 0
|
|
1425
|
+
}
|
|
1426
|
+
},
|
|
1427
|
+
baseCostInCents: run?.baseCostInCents ?? 0,
|
|
1428
|
+
totalCostInCents: (run?.costInCents ?? 0) + (run?.baseCostInCents ?? 0)
|
|
1429
|
+
};
|
|
1430
|
+
}
|
|
1431
|
+
const currentCostInCents = machine?.centsPerMs ? sample.cpuTime * machine.centsPerMs : 0;
|
|
1432
|
+
return {
|
|
1433
|
+
compute: {
|
|
1434
|
+
attempt: {
|
|
1435
|
+
costInCents: currentCostInCents,
|
|
1436
|
+
durationMs: sample.cpuTime
|
|
1437
|
+
},
|
|
1438
|
+
total: {
|
|
1439
|
+
costInCents: (run?.costInCents ?? 0) + currentCostInCents,
|
|
1440
|
+
durationMs: (run?.durationMs ?? 0) + sample.cpuTime
|
|
1441
|
+
}
|
|
1442
|
+
},
|
|
1443
|
+
baseCostInCents: run?.baseCostInCents ?? 0,
|
|
1444
|
+
totalCostInCents: (run?.costInCents ?? 0) + currentCostInCents + (run?.baseCostInCents ?? 0)
|
|
1445
|
+
};
|
|
1446
|
+
},
|
|
1447
|
+
/**
|
|
1448
|
+
* Measure the cost and duration of a function.
|
|
1449
|
+
*
|
|
1450
|
+
* @example
|
|
1451
|
+
*
|
|
1452
|
+
* ```typescript
|
|
1453
|
+
* import { usage } from "@trigger.dev/sdk/v3";
|
|
1454
|
+
*
|
|
1455
|
+
* export const myTask = task({
|
|
1456
|
+
* id: "my-task",
|
|
1457
|
+
* run: async (payload, { ctx }) => {
|
|
1458
|
+
* const { result, compute } = await usage.measure(async () => {
|
|
1459
|
+
* // Do some work
|
|
1460
|
+
* return "result";
|
|
1461
|
+
* });
|
|
1462
|
+
*
|
|
1463
|
+
* console.log("Result", result);
|
|
1464
|
+
* console.log("Cost and duration", { cost: compute.costInCents, duration: compute.durationMs });
|
|
1465
|
+
* },
|
|
1466
|
+
* });
|
|
1467
|
+
* ```
|
|
1468
|
+
*/
|
|
1469
|
+
measure: async (cb) => {
|
|
1470
|
+
const measurement = v3.usage.start();
|
|
1471
|
+
const result = await cb();
|
|
1472
|
+
const sample = v3.usage.stop(measurement);
|
|
1473
|
+
const machine = v3.taskContext.ctx?.machine;
|
|
1474
|
+
const costInCents = machine?.centsPerMs ? sample.cpuTime * machine.centsPerMs : 0;
|
|
1475
|
+
return {
|
|
1476
|
+
result,
|
|
1477
|
+
compute: {
|
|
1478
|
+
costInCents,
|
|
1479
|
+
durationMs: sample.cpuTime
|
|
1480
|
+
}
|
|
1481
|
+
};
|
|
1482
|
+
}
|
|
1483
|
+
};
|
|
1484
|
+
|
|
1485
|
+
// src/v3/schedules/index.ts
|
|
1486
|
+
var schedules_exports = {};
|
|
1487
|
+
__export(schedules_exports, {
|
|
1488
|
+
activate: () => activate,
|
|
1489
|
+
create: () => create,
|
|
1490
|
+
deactivate: () => deactivate,
|
|
1491
|
+
del: () => del,
|
|
1492
|
+
list: () => list,
|
|
1493
|
+
retrieve: () => retrieve,
|
|
1494
|
+
task: () => task2,
|
|
1495
|
+
timezones: () => timezones,
|
|
1496
|
+
update: () => update
|
|
1497
|
+
});
|
|
1498
|
+
function task2(params) {
|
|
1499
|
+
const task3 = createTask(params);
|
|
1500
|
+
const cron = params.cron ? typeof params.cron === "string" ? params.cron : params.cron.pattern : void 0;
|
|
1501
|
+
const timezone = (params.cron && typeof params.cron !== "string" ? params.cron.timezone : "UTC") ?? "UTC";
|
|
1502
|
+
v3.taskCatalog.updateTaskMetadata(task3.id, {
|
|
1503
|
+
triggerSource: "schedule",
|
|
1504
|
+
schedule: cron ? {
|
|
1505
|
+
cron,
|
|
1506
|
+
timezone
|
|
1507
|
+
} : void 0
|
|
1508
|
+
});
|
|
1509
|
+
return task3;
|
|
1510
|
+
}
|
|
1511
|
+
__name(task2, "task");
|
|
1512
|
+
function create(options, requestOptions) {
|
|
1513
|
+
const apiClient = v3.apiClientManager.client;
|
|
1514
|
+
if (!apiClient) {
|
|
1515
|
+
throw apiClientMissingError();
|
|
1516
|
+
}
|
|
1517
|
+
const $requestOptions = v3.mergeRequestOptions({
|
|
1518
|
+
tracer,
|
|
1519
|
+
name: "schedules.create()",
|
|
1520
|
+
icon: "clock",
|
|
1521
|
+
attributes: {
|
|
1522
|
+
...v3.accessoryAttributes({
|
|
1523
|
+
items: [
|
|
1524
|
+
{
|
|
1525
|
+
text: options.cron,
|
|
1526
|
+
variant: "normal"
|
|
1527
|
+
}
|
|
1528
|
+
],
|
|
1529
|
+
style: "codepath"
|
|
1530
|
+
})
|
|
1531
|
+
}
|
|
1532
|
+
}, requestOptions);
|
|
1533
|
+
return apiClient.createSchedule(options, $requestOptions);
|
|
1534
|
+
}
|
|
1535
|
+
__name(create, "create");
|
|
1536
|
+
function retrieve(scheduleId, requestOptions) {
|
|
1537
|
+
const apiClient = v3.apiClientManager.client;
|
|
1538
|
+
if (!apiClient) {
|
|
1539
|
+
throw apiClientMissingError();
|
|
1540
|
+
}
|
|
1541
|
+
const $requestOptions = v3.mergeRequestOptions({
|
|
1542
|
+
tracer,
|
|
1543
|
+
name: "schedules.retrieve()",
|
|
1544
|
+
icon: "clock",
|
|
1545
|
+
attributes: {
|
|
1546
|
+
scheduleId,
|
|
1547
|
+
...v3.accessoryAttributes({
|
|
1548
|
+
items: [
|
|
1549
|
+
{
|
|
1550
|
+
text: scheduleId,
|
|
1551
|
+
variant: "normal"
|
|
1552
|
+
}
|
|
1553
|
+
],
|
|
1554
|
+
style: "codepath"
|
|
1555
|
+
})
|
|
1556
|
+
}
|
|
1557
|
+
}, requestOptions);
|
|
1558
|
+
return apiClient.retrieveSchedule(scheduleId, $requestOptions);
|
|
1559
|
+
}
|
|
1560
|
+
__name(retrieve, "retrieve");
|
|
1561
|
+
function update(scheduleId, options, requestOptions) {
|
|
1562
|
+
const apiClient = v3.apiClientManager.client;
|
|
1563
|
+
if (!apiClient) {
|
|
1564
|
+
throw apiClientMissingError();
|
|
1565
|
+
}
|
|
1566
|
+
const $requestOptions = v3.mergeRequestOptions({
|
|
1567
|
+
tracer,
|
|
1568
|
+
name: "schedules.update()",
|
|
1569
|
+
icon: "clock",
|
|
1570
|
+
attributes: {
|
|
1571
|
+
scheduleId,
|
|
1572
|
+
...v3.accessoryAttributes({
|
|
1573
|
+
items: [
|
|
1574
|
+
{
|
|
1575
|
+
text: scheduleId,
|
|
1576
|
+
variant: "normal"
|
|
1577
|
+
}
|
|
1578
|
+
],
|
|
1579
|
+
style: "codepath"
|
|
1580
|
+
})
|
|
1581
|
+
}
|
|
1582
|
+
}, requestOptions);
|
|
1583
|
+
return apiClient.updateSchedule(scheduleId, options, $requestOptions);
|
|
1584
|
+
}
|
|
1585
|
+
__name(update, "update");
|
|
1586
|
+
function del(scheduleId, requestOptions) {
|
|
1587
|
+
const apiClient = v3.apiClientManager.client;
|
|
1588
|
+
if (!apiClient) {
|
|
1589
|
+
throw apiClientMissingError();
|
|
1590
|
+
}
|
|
1591
|
+
const $requestOptions = v3.mergeRequestOptions({
|
|
1592
|
+
tracer,
|
|
1593
|
+
name: "schedules.delete()",
|
|
1594
|
+
icon: "clock",
|
|
1595
|
+
attributes: {
|
|
1596
|
+
scheduleId,
|
|
1597
|
+
...v3.accessoryAttributes({
|
|
1598
|
+
items: [
|
|
1599
|
+
{
|
|
1600
|
+
text: scheduleId,
|
|
1601
|
+
variant: "normal"
|
|
1602
|
+
}
|
|
1603
|
+
],
|
|
1604
|
+
style: "codepath"
|
|
1605
|
+
})
|
|
1606
|
+
}
|
|
1607
|
+
}, requestOptions);
|
|
1608
|
+
return apiClient.deleteSchedule(scheduleId, $requestOptions);
|
|
1609
|
+
}
|
|
1610
|
+
__name(del, "del");
|
|
1611
|
+
function deactivate(scheduleId, requestOptions) {
|
|
1612
|
+
const apiClient = v3.apiClientManager.client;
|
|
1613
|
+
if (!apiClient) {
|
|
1614
|
+
throw apiClientMissingError();
|
|
1615
|
+
}
|
|
1616
|
+
const $requestOptions = v3.mergeRequestOptions({
|
|
1617
|
+
tracer,
|
|
1618
|
+
name: "schedules.deactivate()",
|
|
1619
|
+
icon: "clock",
|
|
1620
|
+
attributes: {
|
|
1621
|
+
scheduleId,
|
|
1622
|
+
...v3.accessoryAttributes({
|
|
1623
|
+
items: [
|
|
1624
|
+
{
|
|
1625
|
+
text: scheduleId,
|
|
1626
|
+
variant: "normal"
|
|
1627
|
+
}
|
|
1628
|
+
],
|
|
1629
|
+
style: "codepath"
|
|
1630
|
+
})
|
|
1631
|
+
}
|
|
1632
|
+
}, requestOptions);
|
|
1633
|
+
return apiClient.deactivateSchedule(scheduleId, $requestOptions);
|
|
1634
|
+
}
|
|
1635
|
+
__name(deactivate, "deactivate");
|
|
1636
|
+
function activate(scheduleId, requestOptions) {
|
|
1637
|
+
const apiClient = v3.apiClientManager.client;
|
|
1638
|
+
if (!apiClient) {
|
|
1639
|
+
throw apiClientMissingError();
|
|
1640
|
+
}
|
|
1641
|
+
const $requestOptions = v3.mergeRequestOptions({
|
|
1642
|
+
tracer,
|
|
1643
|
+
name: "schedules.activate()",
|
|
1644
|
+
icon: "clock",
|
|
1645
|
+
attributes: {
|
|
1646
|
+
scheduleId,
|
|
1647
|
+
...v3.accessoryAttributes({
|
|
1648
|
+
items: [
|
|
1649
|
+
{
|
|
1650
|
+
text: scheduleId,
|
|
1651
|
+
variant: "normal"
|
|
1652
|
+
}
|
|
1653
|
+
],
|
|
1654
|
+
style: "codepath"
|
|
1655
|
+
})
|
|
1656
|
+
}
|
|
1657
|
+
}, requestOptions);
|
|
1658
|
+
return apiClient.activateSchedule(scheduleId, $requestOptions);
|
|
1659
|
+
}
|
|
1660
|
+
__name(activate, "activate");
|
|
1661
|
+
function list(options, requestOptions) {
|
|
1662
|
+
const apiClient = v3.apiClientManager.client;
|
|
1663
|
+
if (!apiClient) {
|
|
1664
|
+
throw apiClientMissingError();
|
|
1665
|
+
}
|
|
1666
|
+
const $requestOptions = v3.mergeRequestOptions({
|
|
1667
|
+
tracer,
|
|
1668
|
+
name: "schedules.list()",
|
|
1669
|
+
icon: "clock"
|
|
1670
|
+
}, requestOptions);
|
|
1671
|
+
return apiClient.listSchedules(options, $requestOptions);
|
|
1672
|
+
}
|
|
1673
|
+
__name(list, "list");
|
|
1674
|
+
function timezones(options) {
|
|
1675
|
+
const baseUrl = v3.apiClientManager.baseURL;
|
|
1676
|
+
if (!baseUrl) {
|
|
1677
|
+
throw apiClientMissingError();
|
|
1678
|
+
}
|
|
1679
|
+
return zodfetch.zodfetch(v3.TimezonesResult, `${baseUrl}/api/v1/timezones${options?.excludeUtc === true ? "?excludeUtc=true" : ""}`, {
|
|
1680
|
+
method: "GET",
|
|
1681
|
+
headers: {
|
|
1682
|
+
"Content-Type": "application/json"
|
|
1683
|
+
}
|
|
1684
|
+
});
|
|
1685
|
+
}
|
|
1686
|
+
__name(timezones, "timezones");
|
|
1687
|
+
|
|
1688
|
+
// src/v3/envvars.ts
|
|
1689
|
+
var envvars_exports = {};
|
|
1690
|
+
__export(envvars_exports, {
|
|
1691
|
+
create: () => create2,
|
|
1692
|
+
del: () => del2,
|
|
1693
|
+
list: () => list2,
|
|
1694
|
+
retrieve: () => retrieve2,
|
|
1695
|
+
update: () => update2,
|
|
1696
|
+
upload: () => upload
|
|
1697
|
+
});
|
|
1698
|
+
function upload(projectRefOrParams, slugOrRequestOptions, params, requestOptions) {
|
|
1699
|
+
let $projectRef;
|
|
1700
|
+
let $params;
|
|
1701
|
+
let $slug;
|
|
1702
|
+
const $requestOptions = overloadRequestOptions("upload", slugOrRequestOptions, requestOptions);
|
|
1703
|
+
if (v3.taskContext.ctx) {
|
|
1704
|
+
if (typeof projectRefOrParams === "string") {
|
|
1705
|
+
$projectRef = projectRefOrParams;
|
|
1706
|
+
$slug = typeof slugOrRequestOptions === "string" ? slugOrRequestOptions : v3.taskContext.ctx.environment.slug;
|
|
1707
|
+
if (!params) {
|
|
1708
|
+
throw new Error("params is required");
|
|
1709
|
+
}
|
|
1710
|
+
$params = params;
|
|
1711
|
+
} else {
|
|
1712
|
+
$params = projectRefOrParams;
|
|
1713
|
+
$projectRef = v3.taskContext.ctx.project.ref;
|
|
1714
|
+
$slug = v3.taskContext.ctx.environment.slug;
|
|
1715
|
+
}
|
|
1716
|
+
} else {
|
|
1717
|
+
if (typeof projectRefOrParams !== "string") {
|
|
1718
|
+
throw new Error("projectRef is required");
|
|
1719
|
+
}
|
|
1720
|
+
if (!slugOrRequestOptions || typeof slugOrRequestOptions !== "string") {
|
|
1721
|
+
throw new Error("slug is required");
|
|
1722
|
+
}
|
|
1723
|
+
if (!params) {
|
|
1724
|
+
throw new Error("params is required");
|
|
1725
|
+
}
|
|
1726
|
+
$projectRef = projectRefOrParams;
|
|
1727
|
+
$slug = slugOrRequestOptions;
|
|
1728
|
+
$params = params;
|
|
1729
|
+
}
|
|
1730
|
+
const apiClient = v3.apiClientManager.client;
|
|
1731
|
+
if (!apiClient) {
|
|
1732
|
+
throw apiClientMissingError();
|
|
1733
|
+
}
|
|
1734
|
+
return apiClient.importEnvVars($projectRef, $slug, $params, $requestOptions);
|
|
1735
|
+
}
|
|
1736
|
+
__name(upload, "upload");
|
|
1737
|
+
function list2(projectRefOrRequestOptions, slug, requestOptions) {
|
|
1738
|
+
const $projectRef = !v3.isRequestOptions(projectRefOrRequestOptions) ? projectRefOrRequestOptions : v3.taskContext.ctx?.project.ref;
|
|
1739
|
+
const $slug = slug ?? v3.taskContext.ctx?.environment.slug;
|
|
1740
|
+
let $requestOptions = v3.isRequestOptions(projectRefOrRequestOptions) ? projectRefOrRequestOptions : requestOptions;
|
|
1741
|
+
if (!$projectRef) {
|
|
1742
|
+
throw new Error("projectRef is required");
|
|
1743
|
+
}
|
|
1744
|
+
if (!$slug) {
|
|
1745
|
+
throw new Error("slug is required");
|
|
1746
|
+
}
|
|
1747
|
+
$requestOptions = v3.mergeRequestOptions({
|
|
1748
|
+
tracer,
|
|
1749
|
+
name: "envvars.list()",
|
|
1750
|
+
icon: "id-badge"
|
|
1751
|
+
}, $requestOptions);
|
|
1752
|
+
const apiClient = v3.apiClientManager.client;
|
|
1753
|
+
if (!apiClient) {
|
|
1754
|
+
throw apiClientMissingError();
|
|
1755
|
+
}
|
|
1756
|
+
return apiClient.listEnvVars($projectRef, $slug, $requestOptions);
|
|
1757
|
+
}
|
|
1758
|
+
__name(list2, "list");
|
|
1759
|
+
function create2(projectRefOrParams, slugOrRequestOptions, params, requestOptions) {
|
|
1760
|
+
let $projectRef;
|
|
1761
|
+
let $slug;
|
|
1762
|
+
let $params;
|
|
1763
|
+
const $requestOptions = overloadRequestOptions("create", slugOrRequestOptions, requestOptions);
|
|
1764
|
+
if (v3.taskContext.ctx) {
|
|
1765
|
+
if (typeof projectRefOrParams === "string") {
|
|
1766
|
+
$projectRef = projectRefOrParams;
|
|
1767
|
+
$slug = typeof slugOrRequestOptions === "string" ? slugOrRequestOptions : v3.taskContext.ctx.environment.slug;
|
|
1768
|
+
if (!params) {
|
|
1769
|
+
throw new Error("params is required");
|
|
1770
|
+
}
|
|
1771
|
+
$params = params;
|
|
1772
|
+
} else {
|
|
1773
|
+
$params = projectRefOrParams;
|
|
1774
|
+
$projectRef = v3.taskContext.ctx.project.ref;
|
|
1775
|
+
$slug = v3.taskContext.ctx.environment.slug;
|
|
1776
|
+
}
|
|
1777
|
+
} else {
|
|
1778
|
+
if (typeof projectRefOrParams !== "string") {
|
|
1779
|
+
throw new Error("projectRef is required");
|
|
1780
|
+
}
|
|
1781
|
+
if (!slugOrRequestOptions || typeof slugOrRequestOptions !== "string") {
|
|
1782
|
+
throw new Error("slug is required");
|
|
1783
|
+
}
|
|
1784
|
+
if (!params) {
|
|
1785
|
+
throw new Error("params is required");
|
|
1786
|
+
}
|
|
1787
|
+
$projectRef = projectRefOrParams;
|
|
1788
|
+
$slug = slugOrRequestOptions;
|
|
1789
|
+
$params = params;
|
|
1790
|
+
}
|
|
1791
|
+
const apiClient = v3.apiClientManager.client;
|
|
1792
|
+
if (!apiClient) {
|
|
1793
|
+
throw apiClientMissingError();
|
|
1794
|
+
}
|
|
1795
|
+
return apiClient.createEnvVar($projectRef, $slug, $params, $requestOptions);
|
|
1796
|
+
}
|
|
1797
|
+
__name(create2, "create");
|
|
1798
|
+
function retrieve2(projectRefOrName, slugOrRequestOptions, name1, requestOptions) {
|
|
1799
|
+
let $projectRef;
|
|
1800
|
+
let $slug;
|
|
1801
|
+
let $name;
|
|
1802
|
+
const $requestOptions = overloadRequestOptions("retrieve", slugOrRequestOptions, requestOptions);
|
|
1803
|
+
if (typeof name1 === "string") {
|
|
1804
|
+
$projectRef = projectRefOrName;
|
|
1805
|
+
$slug = typeof slugOrRequestOptions === "string" ? slugOrRequestOptions : v3.taskContext.ctx?.environment.slug;
|
|
1806
|
+
$name = name1;
|
|
1807
|
+
} else {
|
|
1808
|
+
$projectRef = v3.taskContext.ctx?.project.ref;
|
|
1809
|
+
$slug = v3.taskContext.ctx?.environment.slug;
|
|
1810
|
+
$name = projectRefOrName;
|
|
1811
|
+
}
|
|
1812
|
+
if (!$projectRef) {
|
|
1813
|
+
throw new Error("projectRef is required");
|
|
1814
|
+
}
|
|
1815
|
+
if (!$slug) {
|
|
1816
|
+
throw new Error("slug is required");
|
|
1817
|
+
}
|
|
1818
|
+
const apiClient = v3.apiClientManager.client;
|
|
1819
|
+
if (!apiClient) {
|
|
1820
|
+
throw apiClientMissingError();
|
|
1821
|
+
}
|
|
1822
|
+
return apiClient.retrieveEnvVar($projectRef, $slug, $name, $requestOptions);
|
|
1823
|
+
}
|
|
1824
|
+
__name(retrieve2, "retrieve");
|
|
1825
|
+
function del2(projectRefOrName, slugOrRequestOptions, name1, requestOptions) {
|
|
1826
|
+
let $projectRef;
|
|
1827
|
+
let $slug;
|
|
1828
|
+
let $name;
|
|
1829
|
+
const $requestOptions = overloadRequestOptions("del", slugOrRequestOptions, requestOptions);
|
|
1830
|
+
if (typeof name1 === "string") {
|
|
1831
|
+
$projectRef = projectRefOrName;
|
|
1832
|
+
$slug = typeof slugOrRequestOptions === "string" ? slugOrRequestOptions : v3.taskContext.ctx?.environment.slug;
|
|
1833
|
+
$name = name1;
|
|
1834
|
+
} else {
|
|
1835
|
+
$projectRef = v3.taskContext.ctx?.project.ref;
|
|
1836
|
+
$slug = v3.taskContext.ctx?.environment.slug;
|
|
1837
|
+
$name = projectRefOrName;
|
|
1838
|
+
}
|
|
1839
|
+
if (!$projectRef) {
|
|
1840
|
+
throw new Error("projectRef is required");
|
|
1841
|
+
}
|
|
1842
|
+
if (!$slug) {
|
|
1843
|
+
throw new Error("slug is required");
|
|
1844
|
+
}
|
|
1845
|
+
const apiClient = v3.apiClientManager.client;
|
|
1846
|
+
if (!apiClient) {
|
|
1847
|
+
throw apiClientMissingError();
|
|
1848
|
+
}
|
|
1849
|
+
return apiClient.deleteEnvVar($projectRef, $slug, $name, $requestOptions);
|
|
1850
|
+
}
|
|
1851
|
+
__name(del2, "del");
|
|
1852
|
+
function update2(projectRefOrName, slugOrParams, nameOrRequestOptions, params, requestOptions) {
|
|
1853
|
+
let $projectRef;
|
|
1854
|
+
let $slug;
|
|
1855
|
+
let $name;
|
|
1856
|
+
let $params;
|
|
1857
|
+
const $requestOptions = overloadRequestOptions("update", nameOrRequestOptions, requestOptions);
|
|
1858
|
+
if (v3.taskContext.ctx) {
|
|
1859
|
+
if (typeof slugOrParams === "string") {
|
|
1860
|
+
$projectRef = slugOrParams;
|
|
1861
|
+
$slug = slugOrParams ?? v3.taskContext.ctx.environment.slug;
|
|
1862
|
+
$name = typeof nameOrRequestOptions === "string" ? nameOrRequestOptions : v3.taskContext.ctx.environment.slug;
|
|
1863
|
+
if (!params) {
|
|
1864
|
+
throw new Error("params is required");
|
|
1865
|
+
}
|
|
1866
|
+
$params = params;
|
|
1867
|
+
} else {
|
|
1868
|
+
$params = slugOrParams;
|
|
1869
|
+
$projectRef = v3.taskContext.ctx.project.ref;
|
|
1870
|
+
$slug = v3.taskContext.ctx.environment.slug;
|
|
1871
|
+
$name = projectRefOrName;
|
|
1872
|
+
}
|
|
1873
|
+
} else {
|
|
1874
|
+
if (typeof slugOrParams !== "string") {
|
|
1875
|
+
throw new Error("slug is required");
|
|
1876
|
+
}
|
|
1877
|
+
if (!projectRefOrName) {
|
|
1878
|
+
throw new Error("projectRef is required");
|
|
1879
|
+
}
|
|
1880
|
+
if (!params) {
|
|
1881
|
+
throw new Error("params is required");
|
|
1882
|
+
}
|
|
1883
|
+
$projectRef = projectRefOrName;
|
|
1884
|
+
$slug = slugOrParams;
|
|
1885
|
+
$name = name;
|
|
1886
|
+
$params = params;
|
|
1887
|
+
}
|
|
1888
|
+
const apiClient = v3.apiClientManager.client;
|
|
1889
|
+
if (!apiClient) {
|
|
1890
|
+
throw apiClientMissingError();
|
|
1891
|
+
}
|
|
1892
|
+
return apiClient.updateEnvVar($projectRef, $slug, $name, $params, $requestOptions);
|
|
1893
|
+
}
|
|
1894
|
+
__name(update2, "update");
|
|
1895
|
+
function overloadRequestOptions(name1, slugOrRequestOptions, requestOptions) {
|
|
1896
|
+
if (v3.isRequestOptions(slugOrRequestOptions)) {
|
|
1897
|
+
return v3.mergeRequestOptions({
|
|
1898
|
+
tracer,
|
|
1899
|
+
name: `envvars.${name1}()`,
|
|
1900
|
+
icon: "id-badge"
|
|
1901
|
+
}, slugOrRequestOptions);
|
|
1902
|
+
} else {
|
|
1903
|
+
return v3.mergeRequestOptions({
|
|
1904
|
+
tracer,
|
|
1905
|
+
name: `envvars.${name1}()`,
|
|
1906
|
+
icon: "id-badge"
|
|
1907
|
+
}, requestOptions);
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
__name(overloadRequestOptions, "overloadRequestOptions");
|
|
1911
|
+
|
|
1912
|
+
// src/v3/index.ts
|
|
1913
|
+
function configure(options) {
|
|
1914
|
+
v3.apiClientManager.setGlobalAPIClientConfiguration(options);
|
|
1915
|
+
}
|
|
1916
|
+
__name(configure, "configure");
|
|
1917
|
+
|
|
1918
|
+
Object.defineProperty(exports, "AbortTaskRunError", {
|
|
1919
|
+
enumerable: true,
|
|
1920
|
+
get: function () { return v3.AbortTaskRunError; }
|
|
1921
|
+
});
|
|
1922
|
+
Object.defineProperty(exports, "ApiError", {
|
|
1923
|
+
enumerable: true,
|
|
1924
|
+
get: function () { return v3.ApiError; }
|
|
1925
|
+
});
|
|
1926
|
+
Object.defineProperty(exports, "AuthenticationError", {
|
|
1927
|
+
enumerable: true,
|
|
1928
|
+
get: function () { return v3.AuthenticationError; }
|
|
1929
|
+
});
|
|
1930
|
+
Object.defineProperty(exports, "BadRequestError", {
|
|
1931
|
+
enumerable: true,
|
|
1932
|
+
get: function () { return v3.BadRequestError; }
|
|
1933
|
+
});
|
|
1934
|
+
Object.defineProperty(exports, "ConflictError", {
|
|
1935
|
+
enumerable: true,
|
|
1936
|
+
get: function () { return v3.ConflictError; }
|
|
1937
|
+
});
|
|
1938
|
+
Object.defineProperty(exports, "InternalServerError", {
|
|
1939
|
+
enumerable: true,
|
|
1940
|
+
get: function () { return v3.InternalServerError; }
|
|
1941
|
+
});
|
|
1942
|
+
Object.defineProperty(exports, "NotFoundError", {
|
|
1943
|
+
enumerable: true,
|
|
1944
|
+
get: function () { return v3.NotFoundError; }
|
|
1945
|
+
});
|
|
1946
|
+
Object.defineProperty(exports, "PermissionDeniedError", {
|
|
1947
|
+
enumerable: true,
|
|
1948
|
+
get: function () { return v3.PermissionDeniedError; }
|
|
1949
|
+
});
|
|
1950
|
+
Object.defineProperty(exports, "RateLimitError", {
|
|
1951
|
+
enumerable: true,
|
|
1952
|
+
get: function () { return v3.RateLimitError; }
|
|
1953
|
+
});
|
|
1954
|
+
Object.defineProperty(exports, "UnprocessableEntityError", {
|
|
1955
|
+
enumerable: true,
|
|
1956
|
+
get: function () { return v3.UnprocessableEntityError; }
|
|
1957
|
+
});
|
|
1958
|
+
Object.defineProperty(exports, "logger", {
|
|
883
1959
|
enumerable: true,
|
|
884
1960
|
get: function () { return v3.logger; }
|
|
885
1961
|
});
|
|
886
1962
|
exports.InMemoryCache = InMemoryCache;
|
|
1963
|
+
exports.configure = configure;
|
|
887
1964
|
exports.createCache = createCache;
|
|
1965
|
+
exports.envvars = envvars_exports;
|
|
1966
|
+
exports.idempotencyKeys = idempotencyKeys;
|
|
1967
|
+
exports.isIdempotencyKey = isIdempotencyKey;
|
|
1968
|
+
exports.queue = queue;
|
|
888
1969
|
exports.retry = retry;
|
|
1970
|
+
exports.runs = runs;
|
|
1971
|
+
exports.schedules = schedules_exports;
|
|
889
1972
|
exports.task = task;
|
|
1973
|
+
exports.tasks = tasks;
|
|
1974
|
+
exports.usage = usage;
|
|
890
1975
|
exports.wait = wait;
|
|
891
1976
|
//# sourceMappingURL=out.js.map
|
|
892
1977
|
//# sourceMappingURL=index.js.map
|