@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.
- package/dist/commonjs/apiClient.d.ts +737 -0
- package/dist/commonjs/apiClient.js +692 -0
- package/dist/commonjs/apiClient.js.map +1 -0
- package/dist/commonjs/concurrencyLimit.d.ts +10 -0
- package/dist/commonjs/concurrencyLimit.js +17 -0
- package/dist/commonjs/concurrencyLimit.js.map +1 -0
- package/dist/commonjs/errors.d.ts +66 -0
- package/dist/commonjs/errors.js +109 -0
- package/dist/commonjs/errors.js.map +1 -0
- package/dist/commonjs/httpEndpoint.d.ts +87 -0
- package/dist/commonjs/httpEndpoint.js +130 -0
- package/dist/commonjs/httpEndpoint.js.map +1 -0
- package/dist/commonjs/index.d.ts +23 -0
- package/dist/commonjs/index.js +55 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/integrations.d.ts +11 -0
- package/dist/commonjs/integrations.js +3 -0
- package/dist/commonjs/integrations.js.map +1 -0
- package/dist/commonjs/io.d.ts +453 -0
- package/dist/commonjs/io.js +1165 -0
- package/dist/commonjs/io.js.map +1 -0
- package/dist/commonjs/ioWithIntegrations.d.ts +4 -0
- package/dist/commonjs/ioWithIntegrations.js +32 -0
- package/dist/commonjs/ioWithIntegrations.js.map +1 -0
- package/dist/commonjs/job.d.ts +96 -0
- package/dist/commonjs/job.js +210 -0
- package/dist/commonjs/job.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/retry.d.ts +20 -0
- package/dist/commonjs/retry.js +22 -0
- package/dist/commonjs/retry.js.map +1 -0
- package/dist/commonjs/runLocalStorage.d.ts +8 -0
- package/dist/commonjs/runLocalStorage.js +6 -0
- package/dist/commonjs/runLocalStorage.js.map +1 -0
- package/dist/commonjs/security.d.ts +18 -0
- package/dist/commonjs/security.js +41 -0
- package/dist/commonjs/security.js.map +1 -0
- package/dist/commonjs/status.d.ts +19 -0
- package/dist/commonjs/status.js +38 -0
- package/dist/commonjs/status.js.map +1 -0
- package/dist/commonjs/store/keyValueStore.d.ts +17 -0
- package/dist/commonjs/store/keyValueStore.js +138 -0
- package/dist/commonjs/store/keyValueStore.js.map +1 -0
- package/dist/commonjs/store/keyValueStoreClient.d.ts +19 -0
- package/dist/commonjs/store/keyValueStoreClient.js +65 -0
- package/dist/commonjs/store/keyValueStoreClient.js.map +1 -0
- package/dist/commonjs/triggerClient.d.ts +300 -0
- package/dist/commonjs/triggerClient.js +1366 -0
- package/dist/commonjs/triggerClient.js.map +1 -0
- package/dist/commonjs/triggers/dynamic.d.ts +56 -0
- package/dist/commonjs/triggers/dynamic.js +97 -0
- package/dist/commonjs/triggers/dynamic.js.map +1 -0
- package/dist/commonjs/triggers/eventTrigger.d.ts +58 -0
- package/dist/commonjs/triggers/eventTrigger.js +69 -0
- package/dist/commonjs/triggers/eventTrigger.js.map +1 -0
- package/dist/commonjs/triggers/externalSource.d.ts +148 -0
- package/dist/commonjs/triggers/externalSource.js +106 -0
- package/dist/commonjs/triggers/externalSource.js.map +1 -0
- package/dist/commonjs/triggers/invokeTrigger.d.ts +39 -0
- package/dist/commonjs/triggers/invokeTrigger.js +58 -0
- package/dist/commonjs/triggers/invokeTrigger.js.map +1 -0
- package/dist/commonjs/triggers/notifications.d.ts +111 -0
- package/dist/commonjs/triggers/notifications.js +101 -0
- package/dist/commonjs/triggers/notifications.js.map +1 -0
- package/dist/commonjs/triggers/scheduled.d.ts +145 -0
- package/dist/commonjs/triggers/scheduled.js +208 -0
- package/dist/commonjs/triggers/scheduled.js.map +1 -0
- package/dist/commonjs/triggers/webhook.d.ts +143 -0
- package/dist/commonjs/triggers/webhook.js +133 -0
- package/dist/commonjs/triggers/webhook.js.map +1 -0
- package/dist/commonjs/typed-emitter.d.ts +37 -0
- package/dist/commonjs/typed-emitter.js +3 -0
- package/dist/commonjs/typed-emitter.js.map +1 -0
- package/dist/commonjs/types.d.ts +204 -0
- package/dist/commonjs/types.js +23 -0
- package/dist/commonjs/types.js.map +1 -0
- package/dist/commonjs/utils/formatSchemaErrors.d.ts +3 -0
- package/dist/commonjs/utils/formatSchemaErrors.js +10 -0
- package/dist/commonjs/utils/formatSchemaErrors.js.map +1 -0
- package/dist/commonjs/utils/typedAsyncLocalStorage.d.ts +6 -0
- package/dist/commonjs/utils/typedAsyncLocalStorage.js +18 -0
- package/dist/commonjs/utils/typedAsyncLocalStorage.js.map +1 -0
- package/dist/commonjs/utils.d.ts +1 -0
- package/dist/commonjs/utils.js +11 -0
- package/dist/commonjs/utils.js.map +1 -0
- package/dist/commonjs/v3/cache.d.ts +28 -0
- package/dist/commonjs/v3/cache.js +63 -0
- package/dist/commonjs/v3/cache.js.map +1 -0
- package/dist/commonjs/v3/config.d.ts +4 -0
- package/dist/commonjs/v3/config.js +7 -0
- package/dist/commonjs/v3/config.js.map +1 -0
- package/dist/commonjs/v3/envvars.d.ts +14 -0
- package/dist/commonjs/v3/envvars.js +246 -0
- package/dist/commonjs/v3/envvars.js.map +1 -0
- package/dist/commonjs/v3/idempotencyKeys.d.ts +49 -0
- package/dist/commonjs/v3/idempotencyKeys.js +76 -0
- package/dist/commonjs/v3/idempotencyKeys.js.map +1 -0
- package/dist/commonjs/v3/index.d.ts +36 -0
- package/dist/commonjs/v3/index.js +79 -0
- package/dist/commonjs/v3/index.js.map +1 -0
- package/dist/commonjs/v3/retry.d.ts +15 -0
- package/dist/commonjs/v3/retry.js +411 -0
- package/dist/commonjs/v3/retry.js.map +1 -0
- package/dist/commonjs/v3/runs.d.ts +345 -0
- package/dist/commonjs/v3/runs.js +195 -0
- package/dist/commonjs/v3/runs.js.map +1 -0
- package/dist/commonjs/v3/schedules/api.d.ts +1 -0
- package/dist/commonjs/v3/schedules/api.js +3 -0
- package/dist/commonjs/v3/schedules/api.js.map +1 -0
- package/dist/commonjs/v3/schedules/index.d.ts +87 -0
- package/dist/commonjs/v3/schedules/index.js +250 -0
- package/dist/commonjs/v3/schedules/index.js.map +1 -0
- package/dist/commonjs/v3/shared.d.ts +443 -0
- package/dist/commonjs/v3/shared.js +547 -0
- package/dist/commonjs/v3/shared.js.map +1 -0
- package/dist/commonjs/v3/tags.d.ts +6 -0
- package/dist/commonjs/v3/tags.js +50 -0
- package/dist/commonjs/v3/tags.js.map +1 -0
- package/dist/commonjs/v3/tasks.d.ts +31 -0
- package/dist/commonjs/v3/tasks.js +35 -0
- package/dist/commonjs/v3/tasks.js.map +1 -0
- package/dist/commonjs/v3/tracer.d.ts +2 -0
- package/dist/commonjs/v3/tracer.js +7 -0
- package/dist/commonjs/v3/tracer.js.map +1 -0
- package/dist/commonjs/v3/usage.d.ts +77 -0
- package/dist/commonjs/v3/usage.js +115 -0
- package/dist/commonjs/v3/usage.js.map +1 -0
- package/dist/commonjs/v3/wait.d.ts +22 -0
- package/dist/commonjs/v3/wait.js +99 -0
- package/dist/commonjs/v3/wait.js.map +1 -0
- package/dist/commonjs/version.d.ts +1 -0
- package/dist/commonjs/version.js +5 -0
- package/dist/commonjs/version.js.map +1 -0
- package/dist/esm/apiClient.d.ts +737 -0
- package/dist/esm/apiClient.js +687 -0
- package/dist/esm/apiClient.js.map +1 -0
- package/dist/esm/concurrencyLimit.d.ts +10 -0
- package/dist/esm/concurrencyLimit.js +13 -0
- package/dist/esm/concurrencyLimit.js.map +1 -0
- package/dist/esm/errors.d.ts +66 -0
- package/dist/esm/errors.js +95 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/httpEndpoint.d.ts +87 -0
- package/dist/esm/httpEndpoint.js +125 -0
- package/dist/esm/httpEndpoint.js.map +1 -0
- package/dist/esm/index.d.ts +23 -0
- package/dist/esm/index.js +35 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/integrations.d.ts +11 -0
- package/dist/esm/integrations.js +2 -0
- package/dist/esm/integrations.js.map +1 -0
- package/dist/esm/io.d.ts +453 -0
- package/dist/esm/io.js +1159 -0
- package/dist/esm/io.js.map +1 -0
- package/dist/esm/ioWithIntegrations.d.ts +4 -0
- package/dist/esm/ioWithIntegrations.js +29 -0
- package/dist/esm/ioWithIntegrations.js.map +1 -0
- package/dist/esm/job.d.ts +96 -0
- package/dist/esm/job.js +206 -0
- package/dist/esm/job.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/retry.d.ts +20 -0
- package/dist/esm/retry.js +19 -0
- package/dist/esm/retry.js.map +1 -0
- package/dist/esm/runLocalStorage.d.ts +8 -0
- package/dist/esm/runLocalStorage.js +3 -0
- package/dist/esm/runLocalStorage.js.map +1 -0
- package/dist/esm/security.d.ts +18 -0
- package/dist/esm/security.js +34 -0
- package/dist/esm/security.js.map +1 -0
- package/dist/esm/status.d.ts +19 -0
- package/dist/esm/status.js +34 -0
- package/dist/esm/status.js.map +1 -0
- package/dist/esm/store/keyValueStore.d.ts +17 -0
- package/dist/esm/store/keyValueStore.js +134 -0
- package/dist/esm/store/keyValueStore.js.map +1 -0
- package/dist/esm/store/keyValueStoreClient.d.ts +19 -0
- package/dist/esm/store/keyValueStoreClient.js +61 -0
- package/dist/esm/store/keyValueStoreClient.js.map +1 -0
- package/dist/esm/triggerClient.d.ts +300 -0
- package/dist/esm/triggerClient.js +1359 -0
- package/dist/esm/triggerClient.js.map +1 -0
- package/dist/esm/triggers/dynamic.d.ts +56 -0
- package/dist/esm/triggers/dynamic.js +93 -0
- package/dist/esm/triggers/dynamic.js.map +1 -0
- package/dist/esm/triggers/eventTrigger.d.ts +58 -0
- package/dist/esm/triggers/eventTrigger.js +64 -0
- package/dist/esm/triggers/eventTrigger.js.map +1 -0
- package/dist/esm/triggers/externalSource.d.ts +148 -0
- package/dist/esm/triggers/externalSource.js +100 -0
- package/dist/esm/triggers/externalSource.js.map +1 -0
- package/dist/esm/triggers/invokeTrigger.d.ts +39 -0
- package/dist/esm/triggers/invokeTrigger.js +53 -0
- package/dist/esm/triggers/invokeTrigger.js.map +1 -0
- package/dist/esm/triggers/notifications.d.ts +111 -0
- package/dist/esm/triggers/notifications.js +94 -0
- package/dist/esm/triggers/notifications.js.map +1 -0
- package/dist/esm/triggers/scheduled.d.ts +145 -0
- package/dist/esm/triggers/scheduled.js +197 -0
- package/dist/esm/triggers/scheduled.js.map +1 -0
- package/dist/esm/triggers/webhook.d.ts +143 -0
- package/dist/esm/triggers/webhook.js +128 -0
- package/dist/esm/triggers/webhook.js.map +1 -0
- package/dist/esm/typed-emitter.d.ts +37 -0
- package/dist/esm/typed-emitter.js +2 -0
- package/dist/esm/typed-emitter.js.map +1 -0
- package/dist/esm/types.d.ts +204 -0
- package/dist/esm/types.js +19 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils/formatSchemaErrors.d.ts +3 -0
- package/dist/esm/utils/formatSchemaErrors.js +7 -0
- package/dist/esm/utils/formatSchemaErrors.js.map +1 -0
- package/dist/esm/utils/typedAsyncLocalStorage.d.ts +6 -0
- package/dist/esm/utils/typedAsyncLocalStorage.js +14 -0
- package/dist/esm/utils/typedAsyncLocalStorage.js.map +1 -0
- package/dist/esm/utils.d.ts +1 -0
- package/dist/esm/utils.js +8 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/esm/v3/cache.d.ts +28 -0
- package/dist/esm/v3/cache.js +58 -0
- package/dist/esm/v3/cache.js.map +1 -0
- package/dist/esm/v3/config.d.ts +4 -0
- package/dist/esm/v3/config.js +4 -0
- package/dist/esm/v3/config.js.map +1 -0
- package/dist/esm/v3/envvars.d.ts +14 -0
- package/dist/esm/v3/envvars.js +238 -0
- package/dist/esm/v3/envvars.js.map +1 -0
- package/dist/esm/v3/idempotencyKeys.d.ts +49 -0
- package/dist/esm/v3/idempotencyKeys.js +72 -0
- package/dist/esm/v3/idempotencyKeys.js.map +1 -0
- package/dist/esm/v3/index.d.ts +36 -0
- package/dist/esm/v3/index.js +35 -0
- package/dist/esm/v3/index.js.map +1 -0
- package/dist/esm/v3/retry.d.ts +15 -0
- package/dist/esm/v3/retry.js +408 -0
- package/dist/esm/v3/retry.js.map +1 -0
- package/dist/esm/v3/runs.d.ts +345 -0
- package/dist/esm/v3/runs.js +192 -0
- package/dist/esm/v3/runs.js.map +1 -0
- package/dist/esm/v3/schedules/api.d.ts +1 -0
- package/dist/esm/v3/schedules/api.js +2 -0
- package/dist/esm/v3/schedules/api.js.map +1 -0
- package/dist/esm/v3/schedules/index.d.ts +87 -0
- package/dist/esm/v3/schedules/index.js +239 -0
- package/dist/esm/v3/schedules/index.js.map +1 -0
- package/dist/esm/v3/shared.d.ts +443 -0
- package/dist/esm/v3/shared.js +534 -0
- package/dist/esm/v3/shared.js.map +1 -0
- package/dist/esm/v3/tags.d.ts +6 -0
- package/dist/esm/v3/tags.js +47 -0
- package/dist/esm/v3/tags.js.map +1 -0
- package/dist/esm/v3/tasks.d.ts +31 -0
- package/dist/esm/v3/tasks.js +31 -0
- package/dist/esm/v3/tasks.js.map +1 -0
- package/dist/esm/v3/tracer.d.ts +2 -0
- package/dist/esm/v3/tracer.js +4 -0
- package/dist/esm/v3/tracer.js.map +1 -0
- package/dist/esm/v3/usage.d.ts +77 -0
- package/dist/esm/v3/usage.js +112 -0
- package/dist/esm/v3/usage.js.map +1 -0
- package/dist/esm/v3/wait.d.ts +22 -0
- package/dist/esm/v3/wait.js +96 -0
- package/dist/esm/v3/wait.js.map +1 -0
- package/dist/esm/version.d.ts +1 -0
- package/dist/esm/version.js +2 -0
- package/dist/esm/version.js.map +1 -0
- package/package.json +62 -47
- package/dist/index.d.mts +0 -2704
- package/dist/index.d.ts +0 -2704
- package/dist/index.js +0 -4886
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -4847
- package/dist/index.mjs.map +0 -1
- package/dist/v3/index.d.mts +0 -261
- package/dist/v3/index.d.ts +0 -261
- package/dist/v3/index.js +0 -921
- package/dist/v3/index.js.map +0 -1
- package/dist/v3/index.mjs +0 -911
- package/dist/v3/index.mjs.map +0 -1
package/dist/v3/index.js
DELETED
|
@@ -1,921 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var api = require('@opentelemetry/api');
|
|
4
|
-
var semanticConventions = require('@opentelemetry/semantic-conventions');
|
|
5
|
-
var v3 = require('@trigger.dev/core/v3');
|
|
6
|
-
var node_async_hooks = require('node:async_hooks');
|
|
7
|
-
|
|
8
|
-
var __defProp = Object.defineProperty;
|
|
9
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
11
|
-
var __publicField = (obj, key, value) => {
|
|
12
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
13
|
-
return value;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
// package.json
|
|
17
|
-
var version = "3.0.0-beta.7";
|
|
18
|
-
var tracer = new v3.TriggerTracer({
|
|
19
|
-
name: "@trigger.dev/sdk",
|
|
20
|
-
version
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
// src/v3/shared.ts
|
|
24
|
-
function createTask(params) {
|
|
25
|
-
const task2 = {
|
|
26
|
-
trigger: async ({ payload, options }) => {
|
|
27
|
-
const apiClient = v3.apiClientManager.client;
|
|
28
|
-
if (!apiClient) {
|
|
29
|
-
throw apiClientMissingError();
|
|
30
|
-
}
|
|
31
|
-
const taskMetadata = v3.runtime.getTaskMetadata(params.id);
|
|
32
|
-
const handle = await tracer.startActiveSpan(taskMetadata ? "Trigger" : `${params.id} trigger()`, async (span) => {
|
|
33
|
-
const response = await apiClient.triggerTask(params.id, {
|
|
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;
|
|
48
|
-
}, {
|
|
49
|
-
kind: api.SpanKind.PRODUCER,
|
|
50
|
-
attributes: {
|
|
51
|
-
[semanticConventions.SEMATTRS_MESSAGING_OPERATION]: "publish",
|
|
52
|
-
[v3.SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
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
|
-
}) : {}
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
return handle;
|
|
69
|
-
},
|
|
70
|
-
batchTrigger: async ({ items }) => {
|
|
71
|
-
const apiClient = v3.apiClientManager.client;
|
|
72
|
-
if (!apiClient) {
|
|
73
|
-
throw apiClientMissingError();
|
|
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
|
|
88
|
-
});
|
|
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
|
-
}, {
|
|
95
|
-
kind: api.SpanKind.PRODUCER,
|
|
96
|
-
attributes: {
|
|
97
|
-
[semanticConventions.SEMATTRS_MESSAGING_OPERATION]: "publish",
|
|
98
|
-
["messaging.batch.message_count"]: items.length,
|
|
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
|
-
}) : {}
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
return response;
|
|
116
|
-
},
|
|
117
|
-
triggerAndWait: async ({ payload, options }) => {
|
|
118
|
-
const ctx = v3.taskContextManager.ctx;
|
|
119
|
-
if (!ctx) {
|
|
120
|
-
throw new Error("triggerAndWait can only be used from inside a task.run()");
|
|
121
|
-
}
|
|
122
|
-
const apiClient = v3.apiClientManager.client;
|
|
123
|
-
if (!apiClient) {
|
|
124
|
-
throw apiClientMissingError();
|
|
125
|
-
}
|
|
126
|
-
const taskMetadata = v3.runtime.getTaskMetadata(params.id);
|
|
127
|
-
return await tracer.startActiveSpan(taskMetadata ? "Trigger" : `${params.id} triggerAndWait()`, async (span) => {
|
|
128
|
-
const response = await apiClient.triggerTask(params.id, {
|
|
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,
|
|
153
|
-
attributes: {
|
|
154
|
-
[v3.SemanticInternalAttributes.STYLE_ICON]: "trigger",
|
|
155
|
-
[semanticConventions.SEMATTRS_MESSAGING_OPERATION]: "publish",
|
|
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({
|
|
160
|
-
items: [
|
|
161
|
-
{
|
|
162
|
-
text: `${taskMetadata.exportName}.triggerAndWait()`,
|
|
163
|
-
variant: "normal"
|
|
164
|
-
}
|
|
165
|
-
],
|
|
166
|
-
style: "codepath"
|
|
167
|
-
}) : {}
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
},
|
|
171
|
-
batchTriggerAndWait: async ({ items }) => {
|
|
172
|
-
const ctx = v3.taskContextManager.ctx;
|
|
173
|
-
if (!ctx) {
|
|
174
|
-
throw new Error("batchTriggerAndWait can only be used from inside a task.run()");
|
|
175
|
-
}
|
|
176
|
-
const apiClient = v3.apiClientManager.client;
|
|
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
|
|
193
|
-
});
|
|
194
|
-
if (!response.ok) {
|
|
195
|
-
throw new Error(response.error);
|
|
196
|
-
}
|
|
197
|
-
span.setAttribute("messaging.message.id", response.data.batchId);
|
|
198
|
-
const result = await v3.runtime.waitForBatch({
|
|
199
|
-
id: response.data.batchId,
|
|
200
|
-
runs: response.data.runs,
|
|
201
|
-
ctx
|
|
202
|
-
});
|
|
203
|
-
const runs2 = await handleBatchTaskRunExecutionResult(result.items);
|
|
204
|
-
return {
|
|
205
|
-
id: result.id,
|
|
206
|
-
runs: runs2
|
|
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
|
-
}) : {}
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
Object.defineProperty(task2, "__trigger", {
|
|
232
|
-
value: {
|
|
233
|
-
id: params.id,
|
|
234
|
-
packageVersion: version,
|
|
235
|
-
queue: params.queue,
|
|
236
|
-
retry: params.retry ? {
|
|
237
|
-
...v3.defaultRetryOptions,
|
|
238
|
-
...params.retry
|
|
239
|
-
} : void 0,
|
|
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
|
|
247
|
-
}
|
|
248
|
-
},
|
|
249
|
-
enumerable: false
|
|
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;
|
|
267
|
-
}, {
|
|
268
|
-
kind: api.SpanKind.INTERNAL,
|
|
269
|
-
[v3.SemanticInternalAttributes.STYLE_ICON]: "cloud-download"
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
__name(handleBatchTaskRunExecutionResult, "handleBatchTaskRunExecutionResult");
|
|
273
|
-
async function handleTaskRunExecutionResult(execution) {
|
|
274
|
-
if (execution.ok) {
|
|
275
|
-
const outputPacket = {
|
|
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);
|
|
528
|
-
}
|
|
529
|
-
if (input instanceof URL) {
|
|
530
|
-
return input;
|
|
531
|
-
}
|
|
532
|
-
return new URL(input.url);
|
|
533
|
-
}, "normalizeUrlFromInput");
|
|
534
|
-
var normalizeHttpMethod = /* @__PURE__ */ __name((input, init) => {
|
|
535
|
-
if (typeof input === "string" || input instanceof URL) {
|
|
536
|
-
return (init?.method || "GET").toUpperCase();
|
|
537
|
-
}
|
|
538
|
-
return (input.method ?? init?.method ?? "GET").toUpperCase();
|
|
539
|
-
}, "normalizeHttpMethod");
|
|
540
|
-
var fetchHttpHandlerStorage = new node_async_hooks.AsyncLocalStorage();
|
|
541
|
-
var fetchWithInterceptors = /* @__PURE__ */ __name(async (input, init) => {
|
|
542
|
-
const handlers = fetchHttpHandlerStorage.getStore();
|
|
543
|
-
if (handlers) {
|
|
544
|
-
try {
|
|
545
|
-
const { getResponse } = await import('msw');
|
|
546
|
-
const request = new Request(input, init);
|
|
547
|
-
const response = await getResponse(handlers, request);
|
|
548
|
-
if (response) {
|
|
549
|
-
return response;
|
|
550
|
-
}
|
|
551
|
-
} catch (e) {
|
|
552
|
-
return fetch(input, init);
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
return fetch(input, init);
|
|
556
|
-
}, "fetchWithInterceptors");
|
|
557
|
-
var _a;
|
|
558
|
-
var FetchErrorWithSpan = (_a = class extends Error {
|
|
559
|
-
constructor(originalError, span) {
|
|
560
|
-
super("Fetch error");
|
|
561
|
-
this.originalError = originalError;
|
|
562
|
-
this.span = span;
|
|
563
|
-
}
|
|
564
|
-
}, __name(_a, "FetchErrorWithSpan"), _a);
|
|
565
|
-
var MAX_ATTEMPTS = 10;
|
|
566
|
-
async function retryFetch(input, init) {
|
|
567
|
-
return tracer.startActiveSpan("retry.fetch()", async (span) => {
|
|
568
|
-
let attempt = 1;
|
|
569
|
-
while (true) {
|
|
570
|
-
try {
|
|
571
|
-
const abortController = new AbortController();
|
|
572
|
-
const timeoutId = init?.timeoutInMs ? setTimeout(() => {
|
|
573
|
-
abortController.abort();
|
|
574
|
-
}, init?.timeoutInMs) : void 0;
|
|
575
|
-
init?.signal?.addEventListener("abort", () => {
|
|
576
|
-
abortController.abort();
|
|
577
|
-
});
|
|
578
|
-
const [response, span2] = await doFetchRequest(input, {
|
|
579
|
-
...init ?? {},
|
|
580
|
-
signal: abortController.signal
|
|
581
|
-
}, attempt);
|
|
582
|
-
if (timeoutId) {
|
|
583
|
-
clearTimeout(timeoutId);
|
|
584
|
-
}
|
|
585
|
-
if (response.ok) {
|
|
586
|
-
span2.setAttributes(createFetchResponseAttributes(response));
|
|
587
|
-
span2.end();
|
|
588
|
-
return response;
|
|
589
|
-
}
|
|
590
|
-
const nextRetry = await calculateRetryDelayForResponse(resolveDefaults(init?.retry, "byStatus", v3.defaultFetchRetryOptions.byStatus), response, attempt);
|
|
591
|
-
if (!nextRetry) {
|
|
592
|
-
span2.setAttributes(createFetchResponseAttributes(response));
|
|
593
|
-
span2.end();
|
|
594
|
-
return response;
|
|
595
|
-
}
|
|
596
|
-
if (attempt >= MAX_ATTEMPTS) {
|
|
597
|
-
span2.setAttributes(createFetchResponseAttributes(response));
|
|
598
|
-
span2.end();
|
|
599
|
-
return response;
|
|
600
|
-
}
|
|
601
|
-
if (nextRetry.type === "delay") {
|
|
602
|
-
span2.setAttribute(v3.SemanticInternalAttributes.RETRY_AT, new Date(Date.now() + nextRetry.value).toISOString());
|
|
603
|
-
span2.setAttribute(v3.SemanticInternalAttributes.RETRY_COUNT, attempt);
|
|
604
|
-
span2.setAttribute(v3.SemanticInternalAttributes.RETRY_DELAY, `${nextRetry.value}ms`);
|
|
605
|
-
span2.end();
|
|
606
|
-
await v3.runtime.waitForDuration(nextRetry.value);
|
|
607
|
-
} else {
|
|
608
|
-
const now = Date.now();
|
|
609
|
-
const nextRetryDate = new Date(nextRetry.value);
|
|
610
|
-
const isInFuture = nextRetryDate.getTime() > now;
|
|
611
|
-
span2.setAttribute(v3.SemanticInternalAttributes.RETRY_AT, new Date(nextRetry.value).toISOString());
|
|
612
|
-
span2.setAttribute(v3.SemanticInternalAttributes.RETRY_COUNT, attempt);
|
|
613
|
-
if (isInFuture) {
|
|
614
|
-
span2.setAttribute(v3.SemanticInternalAttributes.RETRY_DELAY, `${nextRetry.value - now}ms`);
|
|
615
|
-
}
|
|
616
|
-
span2.end();
|
|
617
|
-
await v3.runtime.waitUntil(new Date(nextRetry.value));
|
|
618
|
-
}
|
|
619
|
-
} catch (e) {
|
|
620
|
-
if (e instanceof FetchErrorWithSpan && e.originalError instanceof Error) {
|
|
621
|
-
if (e.originalError.name === "AbortError") {
|
|
622
|
-
const nextRetryDelay = v3.calculateNextRetryDelay(resolveDefaults(init?.retry, "timeout", v3.defaultFetchRetryOptions.timeout), attempt);
|
|
623
|
-
if (!nextRetryDelay) {
|
|
624
|
-
e.span.end();
|
|
625
|
-
throw e;
|
|
626
|
-
}
|
|
627
|
-
if (attempt >= MAX_ATTEMPTS) {
|
|
628
|
-
e.span.end();
|
|
629
|
-
throw e;
|
|
630
|
-
}
|
|
631
|
-
e.span.setAttribute(v3.SemanticInternalAttributes.RETRY_AT, new Date(Date.now() + nextRetryDelay).toISOString());
|
|
632
|
-
e.span.setAttribute(v3.SemanticInternalAttributes.RETRY_COUNT, attempt);
|
|
633
|
-
e.span.setAttribute(v3.SemanticInternalAttributes.RETRY_DELAY, `${nextRetryDelay}ms`);
|
|
634
|
-
e.span.end();
|
|
635
|
-
await v3.runtime.waitForDuration(nextRetryDelay);
|
|
636
|
-
continue;
|
|
637
|
-
} else if (e.originalError.name === "TypeError" && "cause" in e.originalError && e.originalError.cause instanceof Error) {
|
|
638
|
-
const nextRetryDelay = v3.calculateNextRetryDelay(resolveDefaults(init?.retry, "connectionError", v3.defaultFetchRetryOptions.connectionError), attempt);
|
|
639
|
-
if (!nextRetryDelay) {
|
|
640
|
-
e.span.end();
|
|
641
|
-
throw e;
|
|
642
|
-
}
|
|
643
|
-
if (attempt >= MAX_ATTEMPTS) {
|
|
644
|
-
e.span.end();
|
|
645
|
-
throw e;
|
|
646
|
-
}
|
|
647
|
-
e.span.setAttribute(v3.SemanticInternalAttributes.RETRY_AT, new Date(Date.now() + nextRetryDelay).toISOString());
|
|
648
|
-
e.span.setAttribute(v3.SemanticInternalAttributes.RETRY_COUNT, attempt);
|
|
649
|
-
e.span.setAttribute(v3.SemanticInternalAttributes.RETRY_DELAY, `${nextRetryDelay}ms`);
|
|
650
|
-
e.span.end();
|
|
651
|
-
await v3.runtime.waitForDuration(nextRetryDelay);
|
|
652
|
-
continue;
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
if (e instanceof FetchErrorWithSpan) {
|
|
656
|
-
e.span.end();
|
|
657
|
-
}
|
|
658
|
-
throw e;
|
|
659
|
-
} finally {
|
|
660
|
-
attempt++;
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
}, {
|
|
664
|
-
attributes: {
|
|
665
|
-
[v3.SemanticInternalAttributes.STYLE_ICON]: "arrow-capsule",
|
|
666
|
-
...createFetchAttributes(input, init),
|
|
667
|
-
...createFetchRetryOptionsAttributes(init?.retry)
|
|
668
|
-
}
|
|
669
|
-
});
|
|
670
|
-
}
|
|
671
|
-
__name(retryFetch, "retryFetch");
|
|
672
|
-
var doFetchRequest = /* @__PURE__ */ __name(async (input, init, attemptCount = 0) => {
|
|
673
|
-
const httpMethod = normalizeHttpMethod(input, init);
|
|
674
|
-
const span = tracer.startSpan(`HTTP ${httpMethod}`, {
|
|
675
|
-
attributes: {
|
|
676
|
-
[v3.SemanticInternalAttributes.STYLE_ICON]: "world",
|
|
677
|
-
...attemptCount > 1 ? {
|
|
678
|
-
["http.request.resend_count"]: attemptCount - 1
|
|
679
|
-
} : {},
|
|
680
|
-
...createFetchAttributes(input, init)
|
|
681
|
-
}
|
|
682
|
-
});
|
|
683
|
-
try {
|
|
684
|
-
const response = await fetchWithInterceptors(input, {
|
|
685
|
-
...init,
|
|
686
|
-
headers: {
|
|
687
|
-
...init?.headers,
|
|
688
|
-
"x-retry-count": attemptCount.toString()
|
|
689
|
-
}
|
|
690
|
-
});
|
|
691
|
-
span.setAttributes(createFetchResponseAttributes(response));
|
|
692
|
-
if (!response.ok) {
|
|
693
|
-
span.recordException(`${response.status}: ${response.statusText}`);
|
|
694
|
-
span.setStatus({
|
|
695
|
-
code: api.SpanStatusCode.ERROR,
|
|
696
|
-
message: `${response.status}: ${response.statusText}`
|
|
697
|
-
});
|
|
698
|
-
}
|
|
699
|
-
return [
|
|
700
|
-
response,
|
|
701
|
-
span
|
|
702
|
-
];
|
|
703
|
-
} catch (e) {
|
|
704
|
-
if (typeof e === "string" || e instanceof Error) {
|
|
705
|
-
span.recordException(e);
|
|
706
|
-
}
|
|
707
|
-
span.setStatus({
|
|
708
|
-
code: api.SpanStatusCode.ERROR
|
|
709
|
-
});
|
|
710
|
-
span.setAttribute(semanticConventions.SEMATTRS_HTTP_STATUS_CODE, 0);
|
|
711
|
-
span.setAttribute("http.status_text", "This operation was aborted.");
|
|
712
|
-
throw new FetchErrorWithSpan(e, span);
|
|
713
|
-
}
|
|
714
|
-
}, "doFetchRequest");
|
|
715
|
-
var calculateRetryDelayForResponse = /* @__PURE__ */ __name(async (retry2, response, attemptCount) => {
|
|
716
|
-
if (!retry2) {
|
|
717
|
-
return;
|
|
718
|
-
}
|
|
719
|
-
const strategy = await getRetryStrategyForResponse(response, retry2);
|
|
720
|
-
if (!strategy) {
|
|
721
|
-
return;
|
|
722
|
-
}
|
|
723
|
-
switch (strategy.strategy) {
|
|
724
|
-
case "backoff": {
|
|
725
|
-
const value = v3.calculateNextRetryDelay({
|
|
726
|
-
...v3.defaultRetryOptions,
|
|
727
|
-
...strategy
|
|
728
|
-
}, attemptCount);
|
|
729
|
-
if (value) {
|
|
730
|
-
return {
|
|
731
|
-
type: "delay",
|
|
732
|
-
value
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
|
-
break;
|
|
736
|
-
}
|
|
737
|
-
case "headers": {
|
|
738
|
-
const resetAt = response.headers.get(strategy.resetHeader);
|
|
739
|
-
if (typeof resetAt === "string") {
|
|
740
|
-
const resetTimestamp = v3.calculateResetAt(resetAt, strategy.resetFormat ?? "unix_timestamp_in_ms");
|
|
741
|
-
if (resetTimestamp) {
|
|
742
|
-
return {
|
|
743
|
-
type: "timestamp",
|
|
744
|
-
value: resetTimestamp
|
|
745
|
-
};
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
break;
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
}, "calculateRetryDelayForResponse");
|
|
752
|
-
var getRetryStrategyForResponse = /* @__PURE__ */ __name(async (response, retry2) => {
|
|
753
|
-
const statusCodes = Object.keys(retry2);
|
|
754
|
-
const clonedResponse = response.clone();
|
|
755
|
-
for (let i = 0; i < statusCodes.length; i++) {
|
|
756
|
-
const statusRange = statusCodes[i];
|
|
757
|
-
const strategy = retry2[statusRange];
|
|
758
|
-
if (isStatusCodeInRange(response.status, statusRange)) {
|
|
759
|
-
if (strategy.bodyFilter) {
|
|
760
|
-
const body = safeJsonParse(await clonedResponse.text());
|
|
761
|
-
if (!body) {
|
|
762
|
-
continue;
|
|
763
|
-
}
|
|
764
|
-
if (v3.eventFilterMatches(body, strategy.bodyFilter)) {
|
|
765
|
-
return strategy;
|
|
766
|
-
} else {
|
|
767
|
-
continue;
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
return strategy;
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
}, "getRetryStrategyForResponse");
|
|
774
|
-
var isStatusCodeInRange = /* @__PURE__ */ __name((statusCode, statusRange) => {
|
|
775
|
-
if (statusRange === "all") {
|
|
776
|
-
return true;
|
|
777
|
-
}
|
|
778
|
-
if (statusRange.includes(",")) {
|
|
779
|
-
const statusCodes = statusRange.split(",").map((s) => s.trim());
|
|
780
|
-
return statusCodes.some((s) => isStatusCodeInRange(statusCode, s));
|
|
781
|
-
}
|
|
782
|
-
const [start, end] = statusRange.split("-");
|
|
783
|
-
if (end) {
|
|
784
|
-
return statusCode >= parseInt(start, 10) && statusCode <= parseInt(end, 10);
|
|
785
|
-
}
|
|
786
|
-
if (start.endsWith("xx")) {
|
|
787
|
-
const prefix = start.slice(0, -2);
|
|
788
|
-
const statusCodePrefix = Math.floor(statusCode / 100).toString();
|
|
789
|
-
return statusCodePrefix === prefix;
|
|
790
|
-
}
|
|
791
|
-
const statusCodeString = statusCode.toString();
|
|
792
|
-
const rangePrefix = start.slice(0, -1);
|
|
793
|
-
if (start.endsWith("x") && statusCodeString.startsWith(rangePrefix)) {
|
|
794
|
-
return true;
|
|
795
|
-
}
|
|
796
|
-
return statusCode === parseInt(start, 10);
|
|
797
|
-
}, "isStatusCodeInRange");
|
|
798
|
-
var createAttributesFromHeaders = /* @__PURE__ */ __name((headers) => {
|
|
799
|
-
const attributes = {};
|
|
800
|
-
const normalizedHeaderKey = /* @__PURE__ */ __name((key) => {
|
|
801
|
-
return key.toLowerCase();
|
|
802
|
-
}, "normalizedHeaderKey");
|
|
803
|
-
headers.forEach((value, key) => {
|
|
804
|
-
attributes[`http.response.header.${normalizedHeaderKey(key)}`] = value;
|
|
805
|
-
});
|
|
806
|
-
return attributes;
|
|
807
|
-
}, "createAttributesFromHeaders");
|
|
808
|
-
var safeJsonParse = /* @__PURE__ */ __name((json) => {
|
|
809
|
-
try {
|
|
810
|
-
return JSON.parse(json);
|
|
811
|
-
} catch (e) {
|
|
812
|
-
return null;
|
|
813
|
-
}
|
|
814
|
-
}, "safeJsonParse");
|
|
815
|
-
var interceptFetch = /* @__PURE__ */ __name((...handlers) => {
|
|
816
|
-
return {
|
|
817
|
-
run: async (fn) => {
|
|
818
|
-
const current = fetchHttpHandlerStorage.getStore();
|
|
819
|
-
if (current) {
|
|
820
|
-
current.push(...handlers);
|
|
821
|
-
return fn();
|
|
822
|
-
} else {
|
|
823
|
-
return fetchHttpHandlerStorage.run(handlers, fn);
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
};
|
|
827
|
-
}, "interceptFetch");
|
|
828
|
-
var resolveDefaults = /* @__PURE__ */ __name((obj, key, defaults) => {
|
|
829
|
-
if (!obj) {
|
|
830
|
-
return defaults;
|
|
831
|
-
}
|
|
832
|
-
if (obj[key] === void 0 || obj[key] === null) {
|
|
833
|
-
return defaults;
|
|
834
|
-
}
|
|
835
|
-
return obj[key];
|
|
836
|
-
}, "resolveDefaults");
|
|
837
|
-
var createFetchAttributes = /* @__PURE__ */ __name((input, init) => {
|
|
838
|
-
const url = normalizeUrlFromInput(input);
|
|
839
|
-
const httpMethod = normalizeHttpMethod(input, init);
|
|
840
|
-
return {
|
|
841
|
-
[semanticConventions.SEMATTRS_HTTP_METHOD]: httpMethod,
|
|
842
|
-
[semanticConventions.SEMATTRS_HTTP_URL]: url.href,
|
|
843
|
-
[semanticConventions.SEMATTRS_HTTP_HOST]: url.hostname,
|
|
844
|
-
["server.host"]: url.hostname,
|
|
845
|
-
["server.port"]: url.port,
|
|
846
|
-
[semanticConventions.SEMATTRS_HTTP_SCHEME]: url.protocol.replace(":", ""),
|
|
847
|
-
...v3.accessoryAttributes({
|
|
848
|
-
items: [
|
|
849
|
-
{
|
|
850
|
-
text: url.hostname,
|
|
851
|
-
variant: "normal"
|
|
852
|
-
}
|
|
853
|
-
],
|
|
854
|
-
style: "codepath"
|
|
855
|
-
})
|
|
856
|
-
};
|
|
857
|
-
}, "createFetchAttributes");
|
|
858
|
-
var createFetchResponseAttributes = /* @__PURE__ */ __name((response) => {
|
|
859
|
-
return {
|
|
860
|
-
[semanticConventions.SEMATTRS_HTTP_STATUS_CODE]: response.status,
|
|
861
|
-
"http.status_text": response.statusText,
|
|
862
|
-
[semanticConventions.SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH]: response.headers.get("content-length") || "0",
|
|
863
|
-
...createAttributesFromHeaders(response.headers)
|
|
864
|
-
};
|
|
865
|
-
}, "createFetchResponseAttributes");
|
|
866
|
-
var createFetchRetryOptionsAttributes = /* @__PURE__ */ __name((retry2) => {
|
|
867
|
-
const byStatus = resolveDefaults(retry2, "byStatus", v3.defaultFetchRetryOptions.byStatus);
|
|
868
|
-
const connectionError = resolveDefaults(retry2, "connectionError", v3.defaultFetchRetryOptions.connectionError);
|
|
869
|
-
const timeout = resolveDefaults(retry2, "timeout", v3.defaultFetchRetryOptions.timeout);
|
|
870
|
-
return {
|
|
871
|
-
...v3.flattenAttributes(byStatus, "retry.byStatus"),
|
|
872
|
-
...v3.flattenAttributes(connectionError, "retry.connectionError"),
|
|
873
|
-
...v3.flattenAttributes(timeout, "retry.timeout")
|
|
874
|
-
};
|
|
875
|
-
}, "createFetchRetryOptionsAttributes");
|
|
876
|
-
var retry = {
|
|
877
|
-
onThrow,
|
|
878
|
-
fetch: retryFetch,
|
|
879
|
-
interceptFetch
|
|
880
|
-
};
|
|
881
|
-
var runs = {
|
|
882
|
-
replay: replayRun,
|
|
883
|
-
cancel: cancelRun
|
|
884
|
-
};
|
|
885
|
-
async function replayRun(runId) {
|
|
886
|
-
const apiClient = v3.apiClientManager.client;
|
|
887
|
-
if (!apiClient) {
|
|
888
|
-
throw apiClientMissingError();
|
|
889
|
-
}
|
|
890
|
-
const response = await apiClient.replayRun(runId);
|
|
891
|
-
if (!response.ok) {
|
|
892
|
-
throw new Error(response.error);
|
|
893
|
-
}
|
|
894
|
-
return response.data;
|
|
895
|
-
}
|
|
896
|
-
__name(replayRun, "replayRun");
|
|
897
|
-
async function cancelRun(runId) {
|
|
898
|
-
const apiClient = v3.apiClientManager.client;
|
|
899
|
-
if (!apiClient) {
|
|
900
|
-
throw apiClientMissingError();
|
|
901
|
-
}
|
|
902
|
-
const response = await apiClient.cancelRun(runId);
|
|
903
|
-
if (!response.ok) {
|
|
904
|
-
throw new Error(response.error);
|
|
905
|
-
}
|
|
906
|
-
return response.data;
|
|
907
|
-
}
|
|
908
|
-
__name(cancelRun, "cancelRun");
|
|
909
|
-
|
|
910
|
-
Object.defineProperty(exports, 'logger', {
|
|
911
|
-
enumerable: true,
|
|
912
|
-
get: function () { return v3.logger; }
|
|
913
|
-
});
|
|
914
|
-
exports.InMemoryCache = InMemoryCache;
|
|
915
|
-
exports.createCache = createCache;
|
|
916
|
-
exports.retry = retry;
|
|
917
|
-
exports.runs = runs;
|
|
918
|
-
exports.task = task;
|
|
919
|
-
exports.wait = wait;
|
|
920
|
-
//# sourceMappingURL=out.js.map
|
|
921
|
-
//# sourceMappingURL=index.js.map
|