@trigger.dev/sdk 0.0.0-canary-20231128163224 → 0.0.0-cli-e2e-20240910161832
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 +19 -0
- package/dist/commonjs/v3/retry.js +447 -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 +432 -0
- package/dist/commonjs/v3/shared.js +494 -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 +30 -0
- package/dist/commonjs/v3/tasks.js +34 -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 +19 -0
- package/dist/esm/v3/retry.js +444 -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 +432 -0
- package/dist/esm/v3/shared.js +484 -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 +30 -0
- package/dist/esm/v3/tasks.js +30 -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 +71 -23
- package/dist/index.d.ts +0 -2692
- package/dist/index.js +0 -4673
- package/dist/index.js.map +0 -1
package/dist/index.js
DELETED
|
@@ -1,4673 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
-
var __export = (target, all) => {
|
|
11
|
-
for (var name in all)
|
|
12
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
-
};
|
|
14
|
-
var __copyProps = (to, from, except, desc) => {
|
|
15
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
-
for (let key of __getOwnPropNames(from))
|
|
17
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
-
mod
|
|
25
|
-
));
|
|
26
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
-
var __publicField = (obj, key, value) => {
|
|
28
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
29
|
-
return value;
|
|
30
|
-
};
|
|
31
|
-
var __accessCheck = (obj, member, msg) => {
|
|
32
|
-
if (!member.has(obj))
|
|
33
|
-
throw TypeError("Cannot " + msg);
|
|
34
|
-
};
|
|
35
|
-
var __privateGet = (obj, member, getter) => {
|
|
36
|
-
__accessCheck(obj, member, "read from private field");
|
|
37
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
38
|
-
};
|
|
39
|
-
var __privateAdd = (obj, member, value) => {
|
|
40
|
-
if (member.has(obj))
|
|
41
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
42
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
43
|
-
};
|
|
44
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
45
|
-
__accessCheck(obj, member, "write to private field");
|
|
46
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
47
|
-
return value;
|
|
48
|
-
};
|
|
49
|
-
var __privateMethod = (obj, member, method) => {
|
|
50
|
-
__accessCheck(obj, member, "access private method");
|
|
51
|
-
return method;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// src/index.ts
|
|
55
|
-
var src_exports = {};
|
|
56
|
-
__export(src_exports, {
|
|
57
|
-
CronTrigger: () => CronTrigger,
|
|
58
|
-
DynamicSchedule: () => DynamicSchedule,
|
|
59
|
-
DynamicTrigger: () => DynamicTrigger,
|
|
60
|
-
EventSpecificationExampleSchema: () => EventSpecificationExampleSchema,
|
|
61
|
-
EventTrigger: () => EventTrigger,
|
|
62
|
-
ExternalSource: () => ExternalSource,
|
|
63
|
-
ExternalSourceTrigger: () => ExternalSourceTrigger,
|
|
64
|
-
IO: () => IO,
|
|
65
|
-
IOLogger: () => IOLogger,
|
|
66
|
-
IntervalTrigger: () => IntervalTrigger,
|
|
67
|
-
InvokeTrigger: () => InvokeTrigger,
|
|
68
|
-
JSONOutputSerializer: () => JSONOutputSerializer,
|
|
69
|
-
Job: () => Job,
|
|
70
|
-
MissingConnectionNotification: () => MissingConnectionNotification,
|
|
71
|
-
MissingConnectionResolvedNotification: () => MissingConnectionResolvedNotification,
|
|
72
|
-
TriggerClient: () => TriggerClient,
|
|
73
|
-
WebhookSource: () => WebhookSource,
|
|
74
|
-
WebhookTrigger: () => WebhookTrigger,
|
|
75
|
-
cronTrigger: () => cronTrigger,
|
|
76
|
-
eventTrigger: () => eventTrigger,
|
|
77
|
-
intervalTrigger: () => intervalTrigger,
|
|
78
|
-
invokeTrigger: () => invokeTrigger,
|
|
79
|
-
isTriggerError: () => isTriggerError,
|
|
80
|
-
missingConnectionNotification: () => missingConnectionNotification,
|
|
81
|
-
missingConnectionResolvedNotification: () => missingConnectionResolvedNotification,
|
|
82
|
-
omit: () => omit,
|
|
83
|
-
redactString: () => redactString,
|
|
84
|
-
retry: () => retry,
|
|
85
|
-
slugifyId: () => slugifyId,
|
|
86
|
-
verifyHmacSha256: () => verifyHmacSha256,
|
|
87
|
-
verifyRequestSignature: () => verifyRequestSignature,
|
|
88
|
-
waitForEventSchema: () => waitForEventSchema
|
|
89
|
-
});
|
|
90
|
-
module.exports = __toCommonJS(src_exports);
|
|
91
|
-
|
|
92
|
-
// src/utils.ts
|
|
93
|
-
function slugifyId(input) {
|
|
94
|
-
const replaceSpacesWithDash = input.toLowerCase().replace(/\s+/g, "-");
|
|
95
|
-
const removeNonUrlSafeChars = replaceSpacesWithDash.replace(/[^a-zA-Z0-9-._~]/g, "");
|
|
96
|
-
return removeNonUrlSafeChars;
|
|
97
|
-
}
|
|
98
|
-
__name(slugifyId, "slugifyId");
|
|
99
|
-
|
|
100
|
-
// src/utils/typedAsyncLocalStorage.ts
|
|
101
|
-
var import_node_async_hooks = require("async_hooks");
|
|
102
|
-
var TypedAsyncLocalStorage = class {
|
|
103
|
-
constructor() {
|
|
104
|
-
this.storage = new import_node_async_hooks.AsyncLocalStorage();
|
|
105
|
-
}
|
|
106
|
-
runWith(context, fn) {
|
|
107
|
-
return this.storage.run(context, fn);
|
|
108
|
-
}
|
|
109
|
-
getStore() {
|
|
110
|
-
return this.storage.getStore();
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
__name(TypedAsyncLocalStorage, "TypedAsyncLocalStorage");
|
|
114
|
-
|
|
115
|
-
// src/runLocalStorage.ts
|
|
116
|
-
var runLocalStorage = new TypedAsyncLocalStorage();
|
|
117
|
-
|
|
118
|
-
// src/job.ts
|
|
119
|
-
var _validate, validate_fn;
|
|
120
|
-
var Job = class {
|
|
121
|
-
constructor(client, options) {
|
|
122
|
-
__privateAdd(this, _validate);
|
|
123
|
-
this.client = client;
|
|
124
|
-
this.options = options;
|
|
125
|
-
__privateMethod(this, _validate, validate_fn).call(this);
|
|
126
|
-
client.attach(this);
|
|
127
|
-
}
|
|
128
|
-
get id() {
|
|
129
|
-
return slugifyId(this.options.id);
|
|
130
|
-
}
|
|
131
|
-
get enabled() {
|
|
132
|
-
return typeof this.options.enabled === "boolean" ? this.options.enabled : true;
|
|
133
|
-
}
|
|
134
|
-
get name() {
|
|
135
|
-
return this.options.name;
|
|
136
|
-
}
|
|
137
|
-
get trigger() {
|
|
138
|
-
return this.options.trigger;
|
|
139
|
-
}
|
|
140
|
-
get version() {
|
|
141
|
-
return this.options.version;
|
|
142
|
-
}
|
|
143
|
-
get logLevel() {
|
|
144
|
-
return this.options.logLevel;
|
|
145
|
-
}
|
|
146
|
-
get integrations() {
|
|
147
|
-
return Object.keys(this.options.integrations ?? {}).reduce((acc, key) => {
|
|
148
|
-
const integration = this.options.integrations[key];
|
|
149
|
-
acc[key] = {
|
|
150
|
-
id: integration.id,
|
|
151
|
-
metadata: integration.metadata,
|
|
152
|
-
authSource: integration.authSource
|
|
153
|
-
};
|
|
154
|
-
return acc;
|
|
155
|
-
}, {});
|
|
156
|
-
}
|
|
157
|
-
toJSON() {
|
|
158
|
-
const internal = this.options.__internal;
|
|
159
|
-
return {
|
|
160
|
-
id: this.id,
|
|
161
|
-
name: this.name,
|
|
162
|
-
version: this.version,
|
|
163
|
-
event: this.trigger.event,
|
|
164
|
-
trigger: this.trigger.toJSON(),
|
|
165
|
-
integrations: this.integrations,
|
|
166
|
-
startPosition: "latest",
|
|
167
|
-
enabled: this.enabled,
|
|
168
|
-
preprocessRuns: this.trigger.preprocessRuns,
|
|
169
|
-
internal,
|
|
170
|
-
concurrencyLimit: typeof this.options.concurrencyLimit === "number" ? this.options.concurrencyLimit : typeof this.options.concurrencyLimit === "object" ? {
|
|
171
|
-
id: this.options.concurrencyLimit.id,
|
|
172
|
-
limit: this.options.concurrencyLimit.limit
|
|
173
|
-
} : void 0
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
async invoke(param1, param2 = void 0, param3 = void 0) {
|
|
177
|
-
const runStore = runLocalStorage.getStore();
|
|
178
|
-
if (typeof param1 === "string") {
|
|
179
|
-
if (!runStore) {
|
|
180
|
-
throw new Error("Cannot invoke a job from outside of a run when passing a cacheKey. Make sure you are running the job from within a run or use the invoke method without the cacheKey.");
|
|
181
|
-
}
|
|
182
|
-
const options = param3 ?? {};
|
|
183
|
-
return await runStore.io.runTask(param1, async (task) => {
|
|
184
|
-
const result = await this.client.invokeJob(this.id, param2, {
|
|
185
|
-
idempotencyKey: task.idempotencyKey,
|
|
186
|
-
...options
|
|
187
|
-
});
|
|
188
|
-
task.outputProperties = [
|
|
189
|
-
{
|
|
190
|
-
label: "Run",
|
|
191
|
-
text: result.id,
|
|
192
|
-
url: `/orgs/${runStore.ctx.organization.slug}/projects/${runStore.ctx.project.slug}/jobs/${this.id}/runs/${result.id}/trigger`
|
|
193
|
-
}
|
|
194
|
-
];
|
|
195
|
-
return result;
|
|
196
|
-
}, {
|
|
197
|
-
name: `Manually Invoke '${this.name}'`,
|
|
198
|
-
params: param2,
|
|
199
|
-
properties: [
|
|
200
|
-
{
|
|
201
|
-
label: "Job",
|
|
202
|
-
text: this.id,
|
|
203
|
-
url: `/orgs/${runStore.ctx.organization.slug}/projects/${runStore.ctx.project.slug}/jobs/${this.id}`
|
|
204
|
-
},
|
|
205
|
-
{
|
|
206
|
-
label: "Env",
|
|
207
|
-
text: runStore.ctx.environment.slug
|
|
208
|
-
}
|
|
209
|
-
]
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
if (runStore) {
|
|
213
|
-
throw new Error("Cannot invoke a job from within a run without a cacheKey.");
|
|
214
|
-
}
|
|
215
|
-
return await this.client.invokeJob(this.id, param1, param3);
|
|
216
|
-
}
|
|
217
|
-
async invokeAndWaitForCompletion(cacheKey, payload, timeoutInSeconds = 60 * 60, options = {}) {
|
|
218
|
-
const runStore = runLocalStorage.getStore();
|
|
219
|
-
if (!runStore) {
|
|
220
|
-
throw new Error("Cannot invoke a job from outside of a run using invokeAndWaitForCompletion. Make sure you are running the job from within a run or use the invoke method instead.");
|
|
221
|
-
}
|
|
222
|
-
const { io, ctx } = runStore;
|
|
223
|
-
return await io.runTask(cacheKey, async (task) => {
|
|
224
|
-
const parsedPayload = this.trigger.event.parseInvokePayload ? this.trigger.event.parseInvokePayload(payload) ? payload : void 0 : payload;
|
|
225
|
-
const result = await this.client.invokeJob(this.id, parsedPayload, {
|
|
226
|
-
idempotencyKey: task.idempotencyKey,
|
|
227
|
-
callbackUrl: task.callbackUrl ?? void 0,
|
|
228
|
-
...options
|
|
229
|
-
});
|
|
230
|
-
task.outputProperties = [
|
|
231
|
-
{
|
|
232
|
-
label: "Run",
|
|
233
|
-
text: result.id,
|
|
234
|
-
url: `/orgs/${ctx.organization.slug}/projects/${ctx.project.slug}/jobs/${this.id}/runs/${result.id}/trigger`
|
|
235
|
-
}
|
|
236
|
-
];
|
|
237
|
-
return {};
|
|
238
|
-
}, {
|
|
239
|
-
name: `Manually Invoke '${this.name}' and wait for completion`,
|
|
240
|
-
params: payload,
|
|
241
|
-
properties: [
|
|
242
|
-
{
|
|
243
|
-
label: "Job",
|
|
244
|
-
text: this.id,
|
|
245
|
-
url: `/orgs/${ctx.organization.slug}/projects/${ctx.project.slug}/jobs/${this.id}`
|
|
246
|
-
},
|
|
247
|
-
{
|
|
248
|
-
label: "Env",
|
|
249
|
-
text: ctx.environment.slug
|
|
250
|
-
}
|
|
251
|
-
],
|
|
252
|
-
callback: {
|
|
253
|
-
enabled: true,
|
|
254
|
-
timeoutInSeconds
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
async batchInvokeAndWaitForCompletion(cacheKey, batch) {
|
|
259
|
-
const runStore = runLocalStorage.getStore();
|
|
260
|
-
if (!runStore) {
|
|
261
|
-
throw new Error("Cannot invoke a job from outside of a run using batchInvokeAndWaitForCompletion.");
|
|
262
|
-
}
|
|
263
|
-
if (batch.length === 0) {
|
|
264
|
-
return [];
|
|
265
|
-
}
|
|
266
|
-
if (batch.length > 25) {
|
|
267
|
-
throw new Error(`Cannot batch invoke more than 25 items. You tried to batch invoke ${batch.length} items.`);
|
|
268
|
-
}
|
|
269
|
-
const { io, ctx } = runStore;
|
|
270
|
-
const results = await io.parallel(cacheKey, batch, async (item, index) => {
|
|
271
|
-
return await this.invokeAndWaitForCompletion(String(index), item.payload, item.timeoutInSeconds ?? 60 * 60, item.options);
|
|
272
|
-
}, {
|
|
273
|
-
name: `Batch Invoke '${this.name}'`,
|
|
274
|
-
properties: [
|
|
275
|
-
{
|
|
276
|
-
label: "Job",
|
|
277
|
-
text: this.id,
|
|
278
|
-
url: `/orgs/${ctx.organization.slug}/projects/${ctx.project.slug}/jobs/${this.id}`
|
|
279
|
-
},
|
|
280
|
-
{
|
|
281
|
-
label: "Env",
|
|
282
|
-
text: ctx.environment.slug
|
|
283
|
-
}
|
|
284
|
-
]
|
|
285
|
-
});
|
|
286
|
-
return results;
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
__name(Job, "Job");
|
|
290
|
-
_validate = new WeakSet();
|
|
291
|
-
validate_fn = /* @__PURE__ */ __name(function() {
|
|
292
|
-
if (!this.version.match(/^(\d+)\.(\d+)\.(\d+)$/)) {
|
|
293
|
-
throw new Error(`Invalid job version: "${this.version}". Job versions must be valid semver versions.`);
|
|
294
|
-
}
|
|
295
|
-
}, "#validate");
|
|
296
|
-
|
|
297
|
-
// src/triggerClient.ts
|
|
298
|
-
var import_core8 = require("@trigger.dev/core");
|
|
299
|
-
var import_colorette = require("colorette");
|
|
300
|
-
|
|
301
|
-
// src/apiClient.ts
|
|
302
|
-
var import_core3 = require("@trigger.dev/core");
|
|
303
|
-
var import_zod3 = require("zod");
|
|
304
|
-
|
|
305
|
-
// src/io.ts
|
|
306
|
-
var import_core2 = require("@trigger.dev/core");
|
|
307
|
-
var import_core_backend = require("@trigger.dev/core-backend");
|
|
308
|
-
var import_node_async_hooks2 = require("async_hooks");
|
|
309
|
-
var import_node_crypto = require("crypto");
|
|
310
|
-
|
|
311
|
-
// src/errors.ts
|
|
312
|
-
var ResumeWithTaskError = class {
|
|
313
|
-
constructor(task) {
|
|
314
|
-
this.task = task;
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
__name(ResumeWithTaskError, "ResumeWithTaskError");
|
|
318
|
-
var ResumeWithParallelTaskError = class {
|
|
319
|
-
constructor(task, childErrors) {
|
|
320
|
-
this.task = task;
|
|
321
|
-
this.childErrors = childErrors;
|
|
322
|
-
}
|
|
323
|
-
};
|
|
324
|
-
__name(ResumeWithParallelTaskError, "ResumeWithParallelTaskError");
|
|
325
|
-
var RetryWithTaskError = class {
|
|
326
|
-
constructor(cause, task, retryAt) {
|
|
327
|
-
this.cause = cause;
|
|
328
|
-
this.task = task;
|
|
329
|
-
this.retryAt = retryAt;
|
|
330
|
-
}
|
|
331
|
-
};
|
|
332
|
-
__name(RetryWithTaskError, "RetryWithTaskError");
|
|
333
|
-
var CanceledWithTaskError = class {
|
|
334
|
-
constructor(task) {
|
|
335
|
-
this.task = task;
|
|
336
|
-
}
|
|
337
|
-
};
|
|
338
|
-
__name(CanceledWithTaskError, "CanceledWithTaskError");
|
|
339
|
-
var YieldExecutionError = class {
|
|
340
|
-
constructor(key) {
|
|
341
|
-
this.key = key;
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
__name(YieldExecutionError, "YieldExecutionError");
|
|
345
|
-
var AutoYieldExecutionError = class {
|
|
346
|
-
constructor(location, timeRemaining, timeElapsed) {
|
|
347
|
-
this.location = location;
|
|
348
|
-
this.timeRemaining = timeRemaining;
|
|
349
|
-
this.timeElapsed = timeElapsed;
|
|
350
|
-
}
|
|
351
|
-
};
|
|
352
|
-
__name(AutoYieldExecutionError, "AutoYieldExecutionError");
|
|
353
|
-
var AutoYieldWithCompletedTaskExecutionError = class {
|
|
354
|
-
constructor(id, properties, data, output) {
|
|
355
|
-
this.id = id;
|
|
356
|
-
this.properties = properties;
|
|
357
|
-
this.data = data;
|
|
358
|
-
this.output = output;
|
|
359
|
-
}
|
|
360
|
-
};
|
|
361
|
-
__name(AutoYieldWithCompletedTaskExecutionError, "AutoYieldWithCompletedTaskExecutionError");
|
|
362
|
-
var ParsedPayloadSchemaError = class {
|
|
363
|
-
constructor(schemaErrors) {
|
|
364
|
-
this.schemaErrors = schemaErrors;
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
__name(ParsedPayloadSchemaError, "ParsedPayloadSchemaError");
|
|
368
|
-
function isTriggerError(err) {
|
|
369
|
-
return err instanceof ResumeWithTaskError || err instanceof RetryWithTaskError || err instanceof CanceledWithTaskError || err instanceof YieldExecutionError || err instanceof AutoYieldExecutionError || err instanceof AutoYieldWithCompletedTaskExecutionError || err instanceof ResumeWithParallelTaskError;
|
|
370
|
-
}
|
|
371
|
-
__name(isTriggerError, "isTriggerError");
|
|
372
|
-
var ErrorWithTask = class extends Error {
|
|
373
|
-
constructor(cause, message) {
|
|
374
|
-
super(message);
|
|
375
|
-
this.cause = cause;
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
__name(ErrorWithTask, "ErrorWithTask");
|
|
379
|
-
|
|
380
|
-
// src/retry.ts
|
|
381
|
-
var import_core = require("@trigger.dev/core");
|
|
382
|
-
var retry = {
|
|
383
|
-
standardBackoff: {
|
|
384
|
-
limit: 8,
|
|
385
|
-
factor: 1.8,
|
|
386
|
-
minTimeoutInMs: 500,
|
|
387
|
-
maxTimeoutInMs: 3e4,
|
|
388
|
-
randomize: true
|
|
389
|
-
},
|
|
390
|
-
exponentialBackoff: {
|
|
391
|
-
limit: 8,
|
|
392
|
-
factor: 2,
|
|
393
|
-
minTimeoutInMs: 1e3,
|
|
394
|
-
maxTimeoutInMs: 3e4,
|
|
395
|
-
randomize: true
|
|
396
|
-
}
|
|
397
|
-
};
|
|
398
|
-
|
|
399
|
-
// src/status.ts
|
|
400
|
-
var TriggerStatus = class {
|
|
401
|
-
constructor(id, io) {
|
|
402
|
-
this.id = id;
|
|
403
|
-
this.io = io;
|
|
404
|
-
}
|
|
405
|
-
async update(key, status) {
|
|
406
|
-
const properties = [];
|
|
407
|
-
if (status.label) {
|
|
408
|
-
properties.push({
|
|
409
|
-
label: "Label",
|
|
410
|
-
text: status.label
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
if (status.state) {
|
|
414
|
-
properties.push({
|
|
415
|
-
label: "State",
|
|
416
|
-
text: status.state
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
return await this.io.runTask(key, async (task) => {
|
|
420
|
-
return await this.io.triggerClient.updateStatus(this.io.runId, this.id, status);
|
|
421
|
-
}, {
|
|
422
|
-
name: status.label ?? `Status update`,
|
|
423
|
-
icon: "bell",
|
|
424
|
-
params: {
|
|
425
|
-
...status
|
|
426
|
-
},
|
|
427
|
-
properties
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
};
|
|
431
|
-
__name(TriggerStatus, "TriggerStatus");
|
|
432
|
-
|
|
433
|
-
// src/types.ts
|
|
434
|
-
var import_zod = require("zod");
|
|
435
|
-
var EventSpecificationExampleSchema = import_zod.z.object({
|
|
436
|
-
id: import_zod.z.string(),
|
|
437
|
-
name: import_zod.z.string(),
|
|
438
|
-
icon: import_zod.z.string().optional(),
|
|
439
|
-
payload: import_zod.z.any()
|
|
440
|
-
});
|
|
441
|
-
function waitForEventSchema(schema) {
|
|
442
|
-
return import_zod.z.object({
|
|
443
|
-
id: import_zod.z.string(),
|
|
444
|
-
name: import_zod.z.string(),
|
|
445
|
-
source: import_zod.z.string(),
|
|
446
|
-
payload: schema,
|
|
447
|
-
timestamp: import_zod.z.coerce.date(),
|
|
448
|
-
context: import_zod.z.any().optional(),
|
|
449
|
-
accountId: import_zod.z.string().optional()
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
__name(waitForEventSchema, "waitForEventSchema");
|
|
453
|
-
|
|
454
|
-
// src/io.ts
|
|
455
|
-
var import_zod2 = require("zod");
|
|
456
|
-
|
|
457
|
-
// src/store/keyValueStore.ts
|
|
458
|
-
var _namespacedKey, namespacedKey_fn, _sharedProperties, sharedProperties_fn;
|
|
459
|
-
var KeyValueStore = class {
|
|
460
|
-
constructor(apiClient, type = null, namespace = "") {
|
|
461
|
-
__privateAdd(this, _namespacedKey);
|
|
462
|
-
__privateAdd(this, _sharedProperties);
|
|
463
|
-
this.apiClient = apiClient;
|
|
464
|
-
this.type = type;
|
|
465
|
-
this.namespace = namespace;
|
|
466
|
-
}
|
|
467
|
-
async delete(param1, param2) {
|
|
468
|
-
const runStore = runLocalStorage.getStore();
|
|
469
|
-
if (!runStore) {
|
|
470
|
-
if (typeof param1 !== "string") {
|
|
471
|
-
throw new Error("Please use the store without a cacheKey when accessing from outside a run.");
|
|
472
|
-
}
|
|
473
|
-
return await this.apiClient.store.delete(__privateMethod(this, _namespacedKey, namespacedKey_fn).call(this, param1));
|
|
474
|
-
}
|
|
475
|
-
const { io } = runStore;
|
|
476
|
-
if (!param2) {
|
|
477
|
-
throw new Error("Please provide a non-empty key when accessing the store from inside a run.");
|
|
478
|
-
}
|
|
479
|
-
return await io.runTask(param1, async (task) => {
|
|
480
|
-
return await this.apiClient.store.delete(__privateMethod(this, _namespacedKey, namespacedKey_fn).call(this, param2));
|
|
481
|
-
}, {
|
|
482
|
-
name: "Key-Value Store Delete",
|
|
483
|
-
icon: "database-minus",
|
|
484
|
-
params: {
|
|
485
|
-
key: param2
|
|
486
|
-
},
|
|
487
|
-
properties: __privateMethod(this, _sharedProperties, sharedProperties_fn).call(this, param2),
|
|
488
|
-
style: {
|
|
489
|
-
style: "minimal"
|
|
490
|
-
}
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
async get(param1, param2) {
|
|
494
|
-
const runStore = runLocalStorage.getStore();
|
|
495
|
-
if (!runStore) {
|
|
496
|
-
if (typeof param1 !== "string") {
|
|
497
|
-
throw new Error("Please use the store without a cacheKey when accessing from outside a run.");
|
|
498
|
-
}
|
|
499
|
-
return await this.apiClient.store.get(__privateMethod(this, _namespacedKey, namespacedKey_fn).call(this, param1));
|
|
500
|
-
}
|
|
501
|
-
const { io } = runStore;
|
|
502
|
-
if (!param2) {
|
|
503
|
-
throw new Error("Please provide a non-empty key when accessing the store from inside a run.");
|
|
504
|
-
}
|
|
505
|
-
return await io.runTask(param1, async (task) => {
|
|
506
|
-
return await this.apiClient.store.get(__privateMethod(this, _namespacedKey, namespacedKey_fn).call(this, param2));
|
|
507
|
-
}, {
|
|
508
|
-
name: "Key-Value Store Get",
|
|
509
|
-
icon: "database-export",
|
|
510
|
-
params: {
|
|
511
|
-
key: param2
|
|
512
|
-
},
|
|
513
|
-
properties: __privateMethod(this, _sharedProperties, sharedProperties_fn).call(this, param2),
|
|
514
|
-
style: {
|
|
515
|
-
style: "minimal"
|
|
516
|
-
}
|
|
517
|
-
});
|
|
518
|
-
}
|
|
519
|
-
async has(param1, param2) {
|
|
520
|
-
const runStore = runLocalStorage.getStore();
|
|
521
|
-
if (!runStore) {
|
|
522
|
-
if (typeof param1 !== "string") {
|
|
523
|
-
throw new Error("Please use the store without a cacheKey when accessing from outside a run.");
|
|
524
|
-
}
|
|
525
|
-
return await this.apiClient.store.has(__privateMethod(this, _namespacedKey, namespacedKey_fn).call(this, param1));
|
|
526
|
-
}
|
|
527
|
-
const { io } = runStore;
|
|
528
|
-
if (!param2) {
|
|
529
|
-
throw new Error("Please provide a non-empty key when accessing the store from inside a run.");
|
|
530
|
-
}
|
|
531
|
-
return await io.runTask(param1, async (task) => {
|
|
532
|
-
return await this.apiClient.store.has(__privateMethod(this, _namespacedKey, namespacedKey_fn).call(this, param2));
|
|
533
|
-
}, {
|
|
534
|
-
name: "Key-Value Store Has",
|
|
535
|
-
icon: "database-search",
|
|
536
|
-
params: {
|
|
537
|
-
key: param2
|
|
538
|
-
},
|
|
539
|
-
properties: __privateMethod(this, _sharedProperties, sharedProperties_fn).call(this, param2),
|
|
540
|
-
style: {
|
|
541
|
-
style: "minimal"
|
|
542
|
-
}
|
|
543
|
-
});
|
|
544
|
-
}
|
|
545
|
-
async set(param1, param2, param3) {
|
|
546
|
-
const runStore = runLocalStorage.getStore();
|
|
547
|
-
if (!runStore) {
|
|
548
|
-
if (typeof param1 !== "string") {
|
|
549
|
-
throw new Error("Please use the store without a cacheKey when accessing from outside a run.");
|
|
550
|
-
}
|
|
551
|
-
return await this.apiClient.store.set(__privateMethod(this, _namespacedKey, namespacedKey_fn).call(this, param1), param2);
|
|
552
|
-
}
|
|
553
|
-
const { io } = runStore;
|
|
554
|
-
if (!param2 || typeof param2 !== "string") {
|
|
555
|
-
throw new Error("Please provide a non-empty key when accessing the store from inside a run.");
|
|
556
|
-
}
|
|
557
|
-
const value = param3;
|
|
558
|
-
return await io.runTask(param1, async (task) => {
|
|
559
|
-
return await this.apiClient.store.set(__privateMethod(this, _namespacedKey, namespacedKey_fn).call(this, param2), value);
|
|
560
|
-
}, {
|
|
561
|
-
name: "Key-Value Store Set",
|
|
562
|
-
icon: "database-plus",
|
|
563
|
-
params: {
|
|
564
|
-
key: param2,
|
|
565
|
-
value
|
|
566
|
-
},
|
|
567
|
-
properties: [
|
|
568
|
-
...__privateMethod(this, _sharedProperties, sharedProperties_fn).call(this, param2),
|
|
569
|
-
...typeof value !== "object" || value === null ? [
|
|
570
|
-
{
|
|
571
|
-
label: "value",
|
|
572
|
-
text: String(value) ?? "undefined"
|
|
573
|
-
}
|
|
574
|
-
] : []
|
|
575
|
-
],
|
|
576
|
-
style: {
|
|
577
|
-
style: "minimal"
|
|
578
|
-
}
|
|
579
|
-
});
|
|
580
|
-
}
|
|
581
|
-
};
|
|
582
|
-
__name(KeyValueStore, "KeyValueStore");
|
|
583
|
-
_namespacedKey = new WeakSet();
|
|
584
|
-
namespacedKey_fn = /* @__PURE__ */ __name(function(key) {
|
|
585
|
-
const parts = [];
|
|
586
|
-
if (this.type) {
|
|
587
|
-
parts.push(this.type);
|
|
588
|
-
}
|
|
589
|
-
if (this.namespace) {
|
|
590
|
-
parts.push(this.namespace);
|
|
591
|
-
}
|
|
592
|
-
parts.push(key);
|
|
593
|
-
return parts.join(":");
|
|
594
|
-
}, "#namespacedKey");
|
|
595
|
-
_sharedProperties = new WeakSet();
|
|
596
|
-
sharedProperties_fn = /* @__PURE__ */ __name(function(key1) {
|
|
597
|
-
return [
|
|
598
|
-
{
|
|
599
|
-
label: "namespace",
|
|
600
|
-
text: this.type ?? "env"
|
|
601
|
-
},
|
|
602
|
-
{
|
|
603
|
-
label: "key",
|
|
604
|
-
text: key1
|
|
605
|
-
}
|
|
606
|
-
];
|
|
607
|
-
}, "#sharedProperties");
|
|
608
|
-
|
|
609
|
-
// src/io.ts
|
|
610
|
-
var JSONOutputSerializer = class {
|
|
611
|
-
serialize(value) {
|
|
612
|
-
return JSON.stringify(value);
|
|
613
|
-
}
|
|
614
|
-
deserialize(value) {
|
|
615
|
-
return value ? JSON.parse(value) : void 0;
|
|
616
|
-
}
|
|
617
|
-
};
|
|
618
|
-
__name(JSONOutputSerializer, "JSONOutputSerializer");
|
|
619
|
-
var _addToCachedTasks, addToCachedTasks_fn, _detectAutoYield, detectAutoYield_fn, _forceYield, forceYield_fn, _getTimeElapsed, getTimeElapsed_fn, _getRemainingTimeInMillis, getRemainingTimeInMillis_fn;
|
|
620
|
-
var IO = class {
|
|
621
|
-
constructor(options) {
|
|
622
|
-
__privateAdd(this, _addToCachedTasks);
|
|
623
|
-
__privateAdd(this, _detectAutoYield);
|
|
624
|
-
__privateAdd(this, _forceYield);
|
|
625
|
-
__privateAdd(this, _getTimeElapsed);
|
|
626
|
-
__privateAdd(this, _getRemainingTimeInMillis);
|
|
627
|
-
__publicField(this, "_outputSerializer", new JSONOutputSerializer());
|
|
628
|
-
__publicField(this, "_visitedCacheKeys", /* @__PURE__ */ new Set());
|
|
629
|
-
__publicField(this, "brb", this.yield.bind(this));
|
|
630
|
-
this._id = options.id;
|
|
631
|
-
this._jobId = options.jobId;
|
|
632
|
-
this._apiClient = options.apiClient;
|
|
633
|
-
this._triggerClient = options.client;
|
|
634
|
-
this._logger = options.logger ?? new import_core2.Logger("trigger.dev", options.logLevel);
|
|
635
|
-
this._cachedTasks = /* @__PURE__ */ new Map();
|
|
636
|
-
this._jobLogger = options.jobLogger;
|
|
637
|
-
this._jobLogLevel = options.jobLogLevel;
|
|
638
|
-
this._timeOrigin = options.timeOrigin;
|
|
639
|
-
this._executionTimeout = options.executionTimeout;
|
|
640
|
-
this._envStore = new KeyValueStore(options.apiClient);
|
|
641
|
-
this._jobStore = new KeyValueStore(options.apiClient, "job", options.jobId);
|
|
642
|
-
this._runStore = new KeyValueStore(options.apiClient, "run", options.id);
|
|
643
|
-
this._stats = {
|
|
644
|
-
initialCachedTasks: 0,
|
|
645
|
-
lazyLoadedCachedTasks: 0,
|
|
646
|
-
executedTasks: 0,
|
|
647
|
-
cachedTaskHits: 0,
|
|
648
|
-
cachedTaskMisses: 0,
|
|
649
|
-
noopCachedTaskHits: 0,
|
|
650
|
-
noopCachedTaskMisses: 0
|
|
651
|
-
};
|
|
652
|
-
if (options.cachedTasks) {
|
|
653
|
-
options.cachedTasks.forEach((task) => {
|
|
654
|
-
this._cachedTasks.set(task.idempotencyKey, task);
|
|
655
|
-
});
|
|
656
|
-
this._stats.initialCachedTasks = options.cachedTasks.length;
|
|
657
|
-
}
|
|
658
|
-
this._taskStorage = new import_node_async_hooks2.AsyncLocalStorage();
|
|
659
|
-
this._context = options.context;
|
|
660
|
-
this._yieldedExecutions = options.yieldedExecutions ?? [];
|
|
661
|
-
if (options.noopTasksSet) {
|
|
662
|
-
this._noopTasksBloomFilter = import_core_backend.BloomFilter.deserialize(options.noopTasksSet, import_core_backend.BloomFilter.NOOP_TASK_SET_SIZE);
|
|
663
|
-
}
|
|
664
|
-
this._cachedTasksCursor = options.cachedTasksCursor;
|
|
665
|
-
this._serverVersion = options.serverVersion ?? "unversioned";
|
|
666
|
-
}
|
|
667
|
-
get stats() {
|
|
668
|
-
return this._stats;
|
|
669
|
-
}
|
|
670
|
-
get runId() {
|
|
671
|
-
return this._id;
|
|
672
|
-
}
|
|
673
|
-
get triggerClient() {
|
|
674
|
-
return this._triggerClient;
|
|
675
|
-
}
|
|
676
|
-
get logger() {
|
|
677
|
-
return new IOLogger(async (level, message, data) => {
|
|
678
|
-
let logLevel = "info";
|
|
679
|
-
if (import_core2.Logger.satisfiesLogLevel(logLevel, this._jobLogLevel)) {
|
|
680
|
-
await this.runTask([
|
|
681
|
-
message,
|
|
682
|
-
level
|
|
683
|
-
], async (task) => {
|
|
684
|
-
switch (level) {
|
|
685
|
-
case "LOG": {
|
|
686
|
-
this._jobLogger?.log(message, data);
|
|
687
|
-
logLevel = "log";
|
|
688
|
-
break;
|
|
689
|
-
}
|
|
690
|
-
case "DEBUG": {
|
|
691
|
-
this._jobLogger?.debug(message, data);
|
|
692
|
-
logLevel = "debug";
|
|
693
|
-
break;
|
|
694
|
-
}
|
|
695
|
-
case "INFO": {
|
|
696
|
-
this._jobLogger?.info(message, data);
|
|
697
|
-
logLevel = "info";
|
|
698
|
-
break;
|
|
699
|
-
}
|
|
700
|
-
case "WARN": {
|
|
701
|
-
this._jobLogger?.warn(message, data);
|
|
702
|
-
logLevel = "warn";
|
|
703
|
-
break;
|
|
704
|
-
}
|
|
705
|
-
case "ERROR": {
|
|
706
|
-
this._jobLogger?.error(message, data);
|
|
707
|
-
logLevel = "error";
|
|
708
|
-
break;
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
}, {
|
|
712
|
-
name: "log",
|
|
713
|
-
icon: "log",
|
|
714
|
-
description: message,
|
|
715
|
-
params: data,
|
|
716
|
-
properties: [
|
|
717
|
-
{
|
|
718
|
-
label: "Level",
|
|
719
|
-
text: level
|
|
720
|
-
}
|
|
721
|
-
],
|
|
722
|
-
style: {
|
|
723
|
-
style: "minimal",
|
|
724
|
-
variant: level.toLowerCase()
|
|
725
|
-
},
|
|
726
|
-
noop: true
|
|
727
|
-
});
|
|
728
|
-
}
|
|
729
|
-
});
|
|
730
|
-
}
|
|
731
|
-
async random(cacheKey, { min = 0, max = 1, round = false } = {}) {
|
|
732
|
-
return await this.runTask(cacheKey, async (task) => {
|
|
733
|
-
if (min > max) {
|
|
734
|
-
throw new Error(`Lower bound can't be higher than upper bound - min: ${min}, max: ${max}`);
|
|
735
|
-
}
|
|
736
|
-
if (min === max) {
|
|
737
|
-
await this.logger.warn(`Lower and upper bounds are identical. The return value is not random and will always be: ${min}`);
|
|
738
|
-
}
|
|
739
|
-
const withinBounds = (max - min) * Math.random() + min;
|
|
740
|
-
if (!round) {
|
|
741
|
-
return withinBounds;
|
|
742
|
-
}
|
|
743
|
-
if (!Number.isInteger(min) || !Number.isInteger(max)) {
|
|
744
|
-
await this.logger.warn("Rounding enabled with floating-point bounds. This may cause unexpected skew and boundary inclusivity.");
|
|
745
|
-
}
|
|
746
|
-
const rounded = Math.round(withinBounds);
|
|
747
|
-
return rounded;
|
|
748
|
-
}, {
|
|
749
|
-
name: "random",
|
|
750
|
-
icon: "dice-5-filled",
|
|
751
|
-
params: {
|
|
752
|
-
min,
|
|
753
|
-
max,
|
|
754
|
-
round
|
|
755
|
-
},
|
|
756
|
-
properties: [
|
|
757
|
-
...min === 0 ? [] : [
|
|
758
|
-
{
|
|
759
|
-
label: "min",
|
|
760
|
-
text: String(min)
|
|
761
|
-
}
|
|
762
|
-
],
|
|
763
|
-
...max === 1 ? [] : [
|
|
764
|
-
{
|
|
765
|
-
label: "max",
|
|
766
|
-
text: String(max)
|
|
767
|
-
}
|
|
768
|
-
],
|
|
769
|
-
...round === false ? [] : [
|
|
770
|
-
{
|
|
771
|
-
label: "round",
|
|
772
|
-
text: String(round)
|
|
773
|
-
}
|
|
774
|
-
]
|
|
775
|
-
],
|
|
776
|
-
style: {
|
|
777
|
-
style: "minimal"
|
|
778
|
-
}
|
|
779
|
-
});
|
|
780
|
-
}
|
|
781
|
-
async wait(cacheKey, seconds) {
|
|
782
|
-
return await this.runTask(cacheKey, async (task) => {
|
|
783
|
-
}, {
|
|
784
|
-
name: "wait",
|
|
785
|
-
icon: "clock",
|
|
786
|
-
params: {
|
|
787
|
-
seconds
|
|
788
|
-
},
|
|
789
|
-
noop: true,
|
|
790
|
-
delayUntil: new Date(Date.now() + seconds * 1e3),
|
|
791
|
-
style: {
|
|
792
|
-
style: "minimal"
|
|
793
|
-
}
|
|
794
|
-
});
|
|
795
|
-
}
|
|
796
|
-
async waitForEvent(cacheKey, event, options) {
|
|
797
|
-
const timeoutInSeconds = options?.timeoutInSeconds ?? 60 * 60;
|
|
798
|
-
return await this.runTask(cacheKey, async (task, io) => {
|
|
799
|
-
if (!task.callbackUrl) {
|
|
800
|
-
throw new Error("No callbackUrl found on task");
|
|
801
|
-
}
|
|
802
|
-
await this.triggerClient.createEphemeralEventDispatcher({
|
|
803
|
-
url: task.callbackUrl,
|
|
804
|
-
name: event.name,
|
|
805
|
-
filter: event.filter,
|
|
806
|
-
contextFilter: event.contextFilter,
|
|
807
|
-
source: event.source,
|
|
808
|
-
accountId: event.accountId,
|
|
809
|
-
timeoutInSeconds
|
|
810
|
-
});
|
|
811
|
-
return {};
|
|
812
|
-
}, {
|
|
813
|
-
name: "Wait for Event",
|
|
814
|
-
icon: "custom-event",
|
|
815
|
-
params: {
|
|
816
|
-
name: event.name,
|
|
817
|
-
source: event.source,
|
|
818
|
-
filter: event.filter,
|
|
819
|
-
contextFilter: event.contextFilter,
|
|
820
|
-
accountId: event.accountId
|
|
821
|
-
},
|
|
822
|
-
callback: {
|
|
823
|
-
enabled: true,
|
|
824
|
-
timeoutInSeconds
|
|
825
|
-
},
|
|
826
|
-
properties: [
|
|
827
|
-
{
|
|
828
|
-
label: "Event",
|
|
829
|
-
text: event.name
|
|
830
|
-
},
|
|
831
|
-
{
|
|
832
|
-
label: "Timeout",
|
|
833
|
-
text: `${timeoutInSeconds}s`
|
|
834
|
-
},
|
|
835
|
-
...event.source ? [
|
|
836
|
-
{
|
|
837
|
-
label: "Source",
|
|
838
|
-
text: event.source
|
|
839
|
-
}
|
|
840
|
-
] : [],
|
|
841
|
-
...event.accountId ? [
|
|
842
|
-
{
|
|
843
|
-
label: "Account ID",
|
|
844
|
-
text: event.accountId
|
|
845
|
-
}
|
|
846
|
-
] : []
|
|
847
|
-
],
|
|
848
|
-
parseOutput: (output) => {
|
|
849
|
-
return waitForEventSchema(event.schema ?? import_zod2.z.any()).parse(output);
|
|
850
|
-
}
|
|
851
|
-
});
|
|
852
|
-
}
|
|
853
|
-
async waitForRequest(cacheKey, callback, options) {
|
|
854
|
-
const timeoutInSeconds = options?.timeoutInSeconds ?? 60 * 60;
|
|
855
|
-
return await this.runTask(cacheKey, async (task, io) => {
|
|
856
|
-
if (!task.callbackUrl) {
|
|
857
|
-
throw new Error("No callbackUrl found on task");
|
|
858
|
-
}
|
|
859
|
-
task.outputProperties = [
|
|
860
|
-
{
|
|
861
|
-
label: "Callback URL",
|
|
862
|
-
text: task.callbackUrl
|
|
863
|
-
}
|
|
864
|
-
];
|
|
865
|
-
return callback(task.callbackUrl);
|
|
866
|
-
}, {
|
|
867
|
-
name: "Wait for Request",
|
|
868
|
-
icon: "clock",
|
|
869
|
-
callback: {
|
|
870
|
-
enabled: true,
|
|
871
|
-
timeoutInSeconds: options?.timeoutInSeconds
|
|
872
|
-
},
|
|
873
|
-
properties: [
|
|
874
|
-
{
|
|
875
|
-
label: "Timeout",
|
|
876
|
-
text: `${timeoutInSeconds}s`
|
|
877
|
-
}
|
|
878
|
-
]
|
|
879
|
-
});
|
|
880
|
-
}
|
|
881
|
-
async createStatus(cacheKey, initialStatus) {
|
|
882
|
-
const id = typeof cacheKey === "string" ? cacheKey : cacheKey.join("-");
|
|
883
|
-
const status = new TriggerStatus(id, this);
|
|
884
|
-
await status.update(cacheKey, initialStatus);
|
|
885
|
-
return status;
|
|
886
|
-
}
|
|
887
|
-
async backgroundFetch(cacheKey, url, requestInit, options) {
|
|
888
|
-
const urlObject = new URL(url);
|
|
889
|
-
return await this.runTask(cacheKey, async (task) => {
|
|
890
|
-
console.log("task context", task.context);
|
|
891
|
-
return task.output;
|
|
892
|
-
}, {
|
|
893
|
-
name: `fetch ${urlObject.hostname}${urlObject.pathname}`,
|
|
894
|
-
params: {
|
|
895
|
-
url,
|
|
896
|
-
requestInit,
|
|
897
|
-
retry: options?.retry,
|
|
898
|
-
timeout: options?.timeout
|
|
899
|
-
},
|
|
900
|
-
operation: "fetch",
|
|
901
|
-
icon: "background",
|
|
902
|
-
noop: false,
|
|
903
|
-
properties: [
|
|
904
|
-
{
|
|
905
|
-
label: "url",
|
|
906
|
-
text: url,
|
|
907
|
-
url
|
|
908
|
-
},
|
|
909
|
-
{
|
|
910
|
-
label: "method",
|
|
911
|
-
text: requestInit?.method ?? "GET"
|
|
912
|
-
},
|
|
913
|
-
{
|
|
914
|
-
label: "background",
|
|
915
|
-
text: "true"
|
|
916
|
-
},
|
|
917
|
-
...options?.timeout ? [
|
|
918
|
-
{
|
|
919
|
-
label: "timeout",
|
|
920
|
-
text: `${options.timeout.durationInMs}ms`
|
|
921
|
-
}
|
|
922
|
-
] : []
|
|
923
|
-
],
|
|
924
|
-
retry: {
|
|
925
|
-
limit: 0
|
|
926
|
-
}
|
|
927
|
-
});
|
|
928
|
-
}
|
|
929
|
-
async backgroundPoll(cacheKey, params) {
|
|
930
|
-
const urlObject = new URL(params.url);
|
|
931
|
-
return await this.runTask(cacheKey, async (task) => {
|
|
932
|
-
return task.output;
|
|
933
|
-
}, {
|
|
934
|
-
name: `poll ${urlObject.hostname}${urlObject.pathname}`,
|
|
935
|
-
params,
|
|
936
|
-
operation: "fetch-poll",
|
|
937
|
-
icon: "clock-bolt",
|
|
938
|
-
noop: false,
|
|
939
|
-
properties: [
|
|
940
|
-
{
|
|
941
|
-
label: "url",
|
|
942
|
-
text: params.url
|
|
943
|
-
},
|
|
944
|
-
{
|
|
945
|
-
label: "interval",
|
|
946
|
-
text: `${params.interval}s`
|
|
947
|
-
},
|
|
948
|
-
{
|
|
949
|
-
label: "timeout",
|
|
950
|
-
text: `${params.timeout}s`
|
|
951
|
-
}
|
|
952
|
-
],
|
|
953
|
-
retry: {
|
|
954
|
-
limit: 0
|
|
955
|
-
}
|
|
956
|
-
});
|
|
957
|
-
}
|
|
958
|
-
async backgroundFetchResponse(cacheKey, url, requestInit, options) {
|
|
959
|
-
const urlObject = new URL(url);
|
|
960
|
-
return await this.runTask(cacheKey, async (task) => {
|
|
961
|
-
return task.output;
|
|
962
|
-
}, {
|
|
963
|
-
name: `fetch response ${urlObject.hostname}${urlObject.pathname}`,
|
|
964
|
-
params: {
|
|
965
|
-
url,
|
|
966
|
-
requestInit,
|
|
967
|
-
retry: options?.retry,
|
|
968
|
-
timeout: options?.timeout
|
|
969
|
-
},
|
|
970
|
-
operation: "fetch-response",
|
|
971
|
-
icon: "background",
|
|
972
|
-
noop: false,
|
|
973
|
-
properties: [
|
|
974
|
-
{
|
|
975
|
-
label: "url",
|
|
976
|
-
text: url,
|
|
977
|
-
url
|
|
978
|
-
},
|
|
979
|
-
{
|
|
980
|
-
label: "method",
|
|
981
|
-
text: requestInit?.method ?? "GET"
|
|
982
|
-
},
|
|
983
|
-
{
|
|
984
|
-
label: "background",
|
|
985
|
-
text: "true"
|
|
986
|
-
},
|
|
987
|
-
...options?.timeout ? [
|
|
988
|
-
{
|
|
989
|
-
label: "timeout",
|
|
990
|
-
text: `${options.timeout.durationInMs}ms`
|
|
991
|
-
}
|
|
992
|
-
] : []
|
|
993
|
-
],
|
|
994
|
-
retry: {
|
|
995
|
-
limit: 0
|
|
996
|
-
}
|
|
997
|
-
});
|
|
998
|
-
}
|
|
999
|
-
async sendEvent(cacheKey, event, options) {
|
|
1000
|
-
return await this.runTask(cacheKey, async (task) => {
|
|
1001
|
-
return await this._triggerClient.sendEvent(event, options);
|
|
1002
|
-
}, {
|
|
1003
|
-
name: "Send Event",
|
|
1004
|
-
params: {
|
|
1005
|
-
event,
|
|
1006
|
-
options
|
|
1007
|
-
},
|
|
1008
|
-
icon: "send",
|
|
1009
|
-
properties: [
|
|
1010
|
-
{
|
|
1011
|
-
label: "name",
|
|
1012
|
-
text: event.name
|
|
1013
|
-
},
|
|
1014
|
-
...event?.id ? [
|
|
1015
|
-
{
|
|
1016
|
-
label: "ID",
|
|
1017
|
-
text: event.id
|
|
1018
|
-
}
|
|
1019
|
-
] : [],
|
|
1020
|
-
...sendEventOptionsProperties(options)
|
|
1021
|
-
]
|
|
1022
|
-
});
|
|
1023
|
-
}
|
|
1024
|
-
async sendEvents(cacheKey, events, options) {
|
|
1025
|
-
return await this.runTask(cacheKey, async (task) => {
|
|
1026
|
-
return await this._triggerClient.sendEvents(events, options);
|
|
1027
|
-
}, {
|
|
1028
|
-
name: "Send Multiple Events",
|
|
1029
|
-
params: {
|
|
1030
|
-
events,
|
|
1031
|
-
options
|
|
1032
|
-
},
|
|
1033
|
-
icon: "send",
|
|
1034
|
-
properties: [
|
|
1035
|
-
{
|
|
1036
|
-
label: "Total Events",
|
|
1037
|
-
text: String(events.length)
|
|
1038
|
-
},
|
|
1039
|
-
...sendEventOptionsProperties(options)
|
|
1040
|
-
]
|
|
1041
|
-
});
|
|
1042
|
-
}
|
|
1043
|
-
async getEvent(cacheKey, id) {
|
|
1044
|
-
return await this.runTask(cacheKey, async (task) => {
|
|
1045
|
-
return await this._triggerClient.getEvent(id);
|
|
1046
|
-
}, {
|
|
1047
|
-
name: "getEvent",
|
|
1048
|
-
params: {
|
|
1049
|
-
id
|
|
1050
|
-
},
|
|
1051
|
-
properties: [
|
|
1052
|
-
{
|
|
1053
|
-
label: "id",
|
|
1054
|
-
text: id
|
|
1055
|
-
}
|
|
1056
|
-
]
|
|
1057
|
-
});
|
|
1058
|
-
}
|
|
1059
|
-
async cancelEvent(cacheKey, eventId) {
|
|
1060
|
-
return await this.runTask(cacheKey, async (task) => {
|
|
1061
|
-
return await this._triggerClient.cancelEvent(eventId);
|
|
1062
|
-
}, {
|
|
1063
|
-
name: "cancelEvent",
|
|
1064
|
-
params: {
|
|
1065
|
-
eventId
|
|
1066
|
-
},
|
|
1067
|
-
properties: [
|
|
1068
|
-
{
|
|
1069
|
-
label: "id",
|
|
1070
|
-
text: eventId
|
|
1071
|
-
}
|
|
1072
|
-
]
|
|
1073
|
-
});
|
|
1074
|
-
}
|
|
1075
|
-
async updateSource(cacheKey, options) {
|
|
1076
|
-
return this.runTask(cacheKey, async (task) => {
|
|
1077
|
-
return await this._apiClient.updateSource(this._triggerClient.id, options.key, options);
|
|
1078
|
-
}, {
|
|
1079
|
-
name: "Update Source",
|
|
1080
|
-
description: "Update Source",
|
|
1081
|
-
properties: [
|
|
1082
|
-
{
|
|
1083
|
-
label: "key",
|
|
1084
|
-
text: options.key
|
|
1085
|
-
}
|
|
1086
|
-
],
|
|
1087
|
-
params: options,
|
|
1088
|
-
redact: {
|
|
1089
|
-
paths: [
|
|
1090
|
-
"secret"
|
|
1091
|
-
]
|
|
1092
|
-
}
|
|
1093
|
-
});
|
|
1094
|
-
}
|
|
1095
|
-
async updateWebhook(cacheKey, options) {
|
|
1096
|
-
return this.runTask(cacheKey, async (task) => {
|
|
1097
|
-
return await this._apiClient.updateWebhook(options.key, options);
|
|
1098
|
-
}, {
|
|
1099
|
-
name: "Update Webhook Source",
|
|
1100
|
-
icon: "refresh",
|
|
1101
|
-
properties: [
|
|
1102
|
-
{
|
|
1103
|
-
label: "key",
|
|
1104
|
-
text: options.key
|
|
1105
|
-
}
|
|
1106
|
-
],
|
|
1107
|
-
params: options
|
|
1108
|
-
});
|
|
1109
|
-
}
|
|
1110
|
-
async registerInterval(cacheKey, dynamicSchedule, id, options) {
|
|
1111
|
-
return await this.runTask(cacheKey, async (task) => {
|
|
1112
|
-
return dynamicSchedule.register(id, {
|
|
1113
|
-
type: "interval",
|
|
1114
|
-
options
|
|
1115
|
-
});
|
|
1116
|
-
}, {
|
|
1117
|
-
name: "register-interval",
|
|
1118
|
-
properties: [
|
|
1119
|
-
{
|
|
1120
|
-
label: "schedule",
|
|
1121
|
-
text: dynamicSchedule.id
|
|
1122
|
-
},
|
|
1123
|
-
{
|
|
1124
|
-
label: "id",
|
|
1125
|
-
text: id
|
|
1126
|
-
},
|
|
1127
|
-
{
|
|
1128
|
-
label: "seconds",
|
|
1129
|
-
text: options.seconds.toString()
|
|
1130
|
-
}
|
|
1131
|
-
],
|
|
1132
|
-
params: options
|
|
1133
|
-
});
|
|
1134
|
-
}
|
|
1135
|
-
async unregisterInterval(cacheKey, dynamicSchedule, id) {
|
|
1136
|
-
return await this.runTask(cacheKey, async (task) => {
|
|
1137
|
-
return dynamicSchedule.unregister(id);
|
|
1138
|
-
}, {
|
|
1139
|
-
name: "unregister-interval",
|
|
1140
|
-
properties: [
|
|
1141
|
-
{
|
|
1142
|
-
label: "schedule",
|
|
1143
|
-
text: dynamicSchedule.id
|
|
1144
|
-
},
|
|
1145
|
-
{
|
|
1146
|
-
label: "id",
|
|
1147
|
-
text: id
|
|
1148
|
-
}
|
|
1149
|
-
]
|
|
1150
|
-
});
|
|
1151
|
-
}
|
|
1152
|
-
async registerCron(cacheKey, dynamicSchedule, id, options) {
|
|
1153
|
-
return await this.runTask(cacheKey, async (task) => {
|
|
1154
|
-
return dynamicSchedule.register(id, {
|
|
1155
|
-
type: "cron",
|
|
1156
|
-
options
|
|
1157
|
-
});
|
|
1158
|
-
}, {
|
|
1159
|
-
name: "register-cron",
|
|
1160
|
-
properties: [
|
|
1161
|
-
{
|
|
1162
|
-
label: "schedule",
|
|
1163
|
-
text: dynamicSchedule.id
|
|
1164
|
-
},
|
|
1165
|
-
{
|
|
1166
|
-
label: "id",
|
|
1167
|
-
text: id
|
|
1168
|
-
},
|
|
1169
|
-
{
|
|
1170
|
-
label: "cron",
|
|
1171
|
-
text: options.cron
|
|
1172
|
-
}
|
|
1173
|
-
],
|
|
1174
|
-
params: options
|
|
1175
|
-
});
|
|
1176
|
-
}
|
|
1177
|
-
async unregisterCron(cacheKey, dynamicSchedule, id) {
|
|
1178
|
-
return await this.runTask(cacheKey, async (task) => {
|
|
1179
|
-
return dynamicSchedule.unregister(id);
|
|
1180
|
-
}, {
|
|
1181
|
-
name: "unregister-cron",
|
|
1182
|
-
properties: [
|
|
1183
|
-
{
|
|
1184
|
-
label: "schedule",
|
|
1185
|
-
text: dynamicSchedule.id
|
|
1186
|
-
},
|
|
1187
|
-
{
|
|
1188
|
-
label: "id",
|
|
1189
|
-
text: id
|
|
1190
|
-
}
|
|
1191
|
-
]
|
|
1192
|
-
});
|
|
1193
|
-
}
|
|
1194
|
-
async registerTrigger(cacheKey, trigger, id, params) {
|
|
1195
|
-
return await this.runTask(cacheKey, async (task) => {
|
|
1196
|
-
const registration = await this.runTask("register-source", async (subtask1) => {
|
|
1197
|
-
return trigger.register(id, params);
|
|
1198
|
-
}, {
|
|
1199
|
-
name: "register-source"
|
|
1200
|
-
});
|
|
1201
|
-
return {
|
|
1202
|
-
id: registration.id,
|
|
1203
|
-
key: registration.source.key
|
|
1204
|
-
};
|
|
1205
|
-
}, {
|
|
1206
|
-
name: "register-trigger",
|
|
1207
|
-
properties: [
|
|
1208
|
-
{
|
|
1209
|
-
label: "trigger",
|
|
1210
|
-
text: trigger.id
|
|
1211
|
-
},
|
|
1212
|
-
{
|
|
1213
|
-
label: "id",
|
|
1214
|
-
text: id
|
|
1215
|
-
}
|
|
1216
|
-
],
|
|
1217
|
-
params
|
|
1218
|
-
});
|
|
1219
|
-
}
|
|
1220
|
-
async getAuth(cacheKey, clientId) {
|
|
1221
|
-
if (!clientId) {
|
|
1222
|
-
return;
|
|
1223
|
-
}
|
|
1224
|
-
return this.runTask(cacheKey, async (task) => {
|
|
1225
|
-
return await this._triggerClient.getAuth(clientId);
|
|
1226
|
-
}, {
|
|
1227
|
-
name: "get-auth"
|
|
1228
|
-
});
|
|
1229
|
-
}
|
|
1230
|
-
async parallel(cacheKey, items, callback, options) {
|
|
1231
|
-
const results = await this.runTask(cacheKey, async (task) => {
|
|
1232
|
-
const outcomes = await Promise.allSettled(items.map((item, index) => spaceOut(() => callback(item, index), index, 15)));
|
|
1233
|
-
if (outcomes.every((outcome) => outcome.status === "fulfilled")) {
|
|
1234
|
-
return outcomes.map((outcome) => outcome.value);
|
|
1235
|
-
}
|
|
1236
|
-
const nonInternalErrors = outcomes.filter((outcome) => outcome.status === "rejected" && !isTriggerError(outcome.reason)).map((outcome) => outcome);
|
|
1237
|
-
if (nonInternalErrors.length > 0) {
|
|
1238
|
-
throw nonInternalErrors[0].reason;
|
|
1239
|
-
}
|
|
1240
|
-
const internalErrors = outcomes.filter((outcome) => outcome.status === "rejected" && isTriggerError(outcome.reason)).map((outcome) => outcome).map((outcome) => outcome.reason);
|
|
1241
|
-
throw new ResumeWithParallelTaskError(task, internalErrors);
|
|
1242
|
-
}, {
|
|
1243
|
-
name: "parallel",
|
|
1244
|
-
parallel: true,
|
|
1245
|
-
...options ?? {}
|
|
1246
|
-
});
|
|
1247
|
-
return results;
|
|
1248
|
-
}
|
|
1249
|
-
async runTask(cacheKey, callback, options, onError) {
|
|
1250
|
-
__privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "start_task", 500);
|
|
1251
|
-
const parentId = this._taskStorage.getStore()?.taskId;
|
|
1252
|
-
if (parentId) {
|
|
1253
|
-
this._logger.debug("Using parent task", {
|
|
1254
|
-
parentId,
|
|
1255
|
-
cacheKey,
|
|
1256
|
-
options
|
|
1257
|
-
});
|
|
1258
|
-
}
|
|
1259
|
-
const idempotencyKey = await generateIdempotencyKey([
|
|
1260
|
-
this._id,
|
|
1261
|
-
parentId ?? "",
|
|
1262
|
-
cacheKey
|
|
1263
|
-
].flat());
|
|
1264
|
-
if (this._visitedCacheKeys.has(idempotencyKey)) {
|
|
1265
|
-
if (typeof cacheKey === "string") {
|
|
1266
|
-
throw new Error(`Task with cacheKey "${cacheKey}" has already been executed in this run. Each task must have a unique cacheKey.`);
|
|
1267
|
-
} else {
|
|
1268
|
-
throw new Error(`Task with cacheKey "${cacheKey.join("-")}" has already been executed in this run. Each task must have a unique cacheKey.`);
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
this._visitedCacheKeys.add(idempotencyKey);
|
|
1272
|
-
const cachedTask = this._cachedTasks.get(idempotencyKey);
|
|
1273
|
-
if (cachedTask && cachedTask.status === "COMPLETED") {
|
|
1274
|
-
this._logger.debug("Using completed cached task", {
|
|
1275
|
-
idempotencyKey
|
|
1276
|
-
});
|
|
1277
|
-
this._stats.cachedTaskHits++;
|
|
1278
|
-
return options?.parseOutput ? options.parseOutput(cachedTask.output) : cachedTask.output;
|
|
1279
|
-
}
|
|
1280
|
-
if (options?.noop && this._noopTasksBloomFilter) {
|
|
1281
|
-
if (this._noopTasksBloomFilter.test(idempotencyKey)) {
|
|
1282
|
-
this._logger.debug("task idempotency key exists in noopTasksBloomFilter", {
|
|
1283
|
-
idempotencyKey
|
|
1284
|
-
});
|
|
1285
|
-
this._stats.noopCachedTaskHits++;
|
|
1286
|
-
return {};
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
const runOptions = {
|
|
1290
|
-
...options ?? {},
|
|
1291
|
-
parseOutput: void 0
|
|
1292
|
-
};
|
|
1293
|
-
const response = await this._apiClient.runTask(this._id, {
|
|
1294
|
-
idempotencyKey,
|
|
1295
|
-
displayKey: typeof cacheKey === "string" ? cacheKey : void 0,
|
|
1296
|
-
noop: false,
|
|
1297
|
-
...runOptions ?? {},
|
|
1298
|
-
parentId
|
|
1299
|
-
}, {
|
|
1300
|
-
cachedTasksCursor: this._cachedTasksCursor
|
|
1301
|
-
});
|
|
1302
|
-
const task = response.version === import_core2.API_VERSIONS.LAZY_LOADED_CACHED_TASKS ? response.body.task : response.body;
|
|
1303
|
-
if (task.forceYield) {
|
|
1304
|
-
this._logger.debug("Forcing yield after run task", {
|
|
1305
|
-
idempotencyKey
|
|
1306
|
-
});
|
|
1307
|
-
__privateMethod(this, _forceYield, forceYield_fn).call(this, "after_run_task");
|
|
1308
|
-
}
|
|
1309
|
-
if (response.version === import_core2.API_VERSIONS.LAZY_LOADED_CACHED_TASKS) {
|
|
1310
|
-
this._cachedTasksCursor = response.body.cachedTasks?.cursor;
|
|
1311
|
-
for (const cachedTask2 of response.body.cachedTasks?.tasks ?? []) {
|
|
1312
|
-
if (!this._cachedTasks.has(cachedTask2.idempotencyKey)) {
|
|
1313
|
-
this._cachedTasks.set(cachedTask2.idempotencyKey, cachedTask2);
|
|
1314
|
-
this._logger.debug("Injecting lazy loaded task into task cache", {
|
|
1315
|
-
idempotencyKey: cachedTask2.idempotencyKey
|
|
1316
|
-
});
|
|
1317
|
-
this._stats.lazyLoadedCachedTasks++;
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
}
|
|
1321
|
-
if (task.status === "CANCELED") {
|
|
1322
|
-
this._logger.debug("Task canceled", {
|
|
1323
|
-
idempotencyKey,
|
|
1324
|
-
task
|
|
1325
|
-
});
|
|
1326
|
-
throw new CanceledWithTaskError(task);
|
|
1327
|
-
}
|
|
1328
|
-
if (task.status === "COMPLETED") {
|
|
1329
|
-
if (task.noop) {
|
|
1330
|
-
this._logger.debug("Noop Task completed", {
|
|
1331
|
-
idempotencyKey
|
|
1332
|
-
});
|
|
1333
|
-
this._noopTasksBloomFilter?.add(task.idempotencyKey);
|
|
1334
|
-
} else {
|
|
1335
|
-
this._logger.debug("Cache miss", {
|
|
1336
|
-
idempotencyKey
|
|
1337
|
-
});
|
|
1338
|
-
this._stats.cachedTaskMisses++;
|
|
1339
|
-
__privateMethod(this, _addToCachedTasks, addToCachedTasks_fn).call(this, task);
|
|
1340
|
-
}
|
|
1341
|
-
return options?.parseOutput ? options.parseOutput(task.output) : task.output;
|
|
1342
|
-
}
|
|
1343
|
-
if (task.status === "ERRORED") {
|
|
1344
|
-
this._logger.debug("Task errored", {
|
|
1345
|
-
idempotencyKey,
|
|
1346
|
-
task
|
|
1347
|
-
});
|
|
1348
|
-
throw new ErrorWithTask(task, task.error ?? task?.output ? JSON.stringify(task.output) : "Task errored");
|
|
1349
|
-
}
|
|
1350
|
-
__privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "before_execute_task", 1500);
|
|
1351
|
-
const executeTask = /* @__PURE__ */ __name(async () => {
|
|
1352
|
-
try {
|
|
1353
|
-
const result = await callback(task, this);
|
|
1354
|
-
if (task.status === "WAITING" && task.callbackUrl) {
|
|
1355
|
-
this._logger.debug("Waiting for remote callback", {
|
|
1356
|
-
idempotencyKey,
|
|
1357
|
-
task
|
|
1358
|
-
});
|
|
1359
|
-
return {};
|
|
1360
|
-
}
|
|
1361
|
-
const output = this._outputSerializer.serialize(result);
|
|
1362
|
-
this._logger.debug("Completing using output", {
|
|
1363
|
-
idempotencyKey,
|
|
1364
|
-
task
|
|
1365
|
-
});
|
|
1366
|
-
__privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "before_complete_task", 500, task, output);
|
|
1367
|
-
const completedTask = await this._apiClient.completeTask(this._id, task.id, {
|
|
1368
|
-
output,
|
|
1369
|
-
properties: task.outputProperties ?? void 0
|
|
1370
|
-
});
|
|
1371
|
-
if (completedTask.forceYield) {
|
|
1372
|
-
this._logger.debug("Forcing yield after task completed", {
|
|
1373
|
-
idempotencyKey
|
|
1374
|
-
});
|
|
1375
|
-
__privateMethod(this, _forceYield, forceYield_fn).call(this, "after_complete_task");
|
|
1376
|
-
}
|
|
1377
|
-
this._stats.executedTasks++;
|
|
1378
|
-
if (completedTask.status === "CANCELED") {
|
|
1379
|
-
throw new CanceledWithTaskError(completedTask);
|
|
1380
|
-
}
|
|
1381
|
-
__privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "after_complete_task", 500);
|
|
1382
|
-
const deserializedOutput = this._outputSerializer.deserialize(output);
|
|
1383
|
-
return options?.parseOutput ? options.parseOutput(deserializedOutput) : deserializedOutput;
|
|
1384
|
-
} catch (error) {
|
|
1385
|
-
if (isTriggerError(error)) {
|
|
1386
|
-
throw error;
|
|
1387
|
-
}
|
|
1388
|
-
let skipRetrying = false;
|
|
1389
|
-
if (onError) {
|
|
1390
|
-
try {
|
|
1391
|
-
const onErrorResult = onError(error, task, this);
|
|
1392
|
-
if (onErrorResult) {
|
|
1393
|
-
if (onErrorResult instanceof Error) {
|
|
1394
|
-
error = onErrorResult;
|
|
1395
|
-
} else {
|
|
1396
|
-
skipRetrying = !!onErrorResult.skipRetrying;
|
|
1397
|
-
if (onErrorResult.retryAt && !skipRetrying) {
|
|
1398
|
-
const parsedError2 = import_core2.ErrorWithStackSchema.safeParse(onErrorResult.error);
|
|
1399
|
-
throw new RetryWithTaskError(parsedError2.success ? parsedError2.data : {
|
|
1400
|
-
message: "Unknown error"
|
|
1401
|
-
}, task, onErrorResult.retryAt);
|
|
1402
|
-
}
|
|
1403
|
-
}
|
|
1404
|
-
}
|
|
1405
|
-
} catch (innerError) {
|
|
1406
|
-
if (isTriggerError(innerError)) {
|
|
1407
|
-
throw innerError;
|
|
1408
|
-
}
|
|
1409
|
-
error = innerError;
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
if (error instanceof ErrorWithTask) {
|
|
1413
|
-
await this._apiClient.failTask(this._id, task.id, {
|
|
1414
|
-
error: error.cause.output
|
|
1415
|
-
});
|
|
1416
|
-
}
|
|
1417
|
-
const parsedError = import_core2.ErrorWithStackSchema.safeParse(error);
|
|
1418
|
-
if (options?.retry && !skipRetrying) {
|
|
1419
|
-
const retryAt = (0, import_core.calculateRetryAt)(options.retry, task.attempts - 1);
|
|
1420
|
-
if (retryAt) {
|
|
1421
|
-
throw new RetryWithTaskError(parsedError.success ? parsedError.data : {
|
|
1422
|
-
message: "Unknown error"
|
|
1423
|
-
}, task, retryAt);
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1426
|
-
if (parsedError.success) {
|
|
1427
|
-
await this._apiClient.failTask(this._id, task.id, {
|
|
1428
|
-
error: parsedError.data
|
|
1429
|
-
});
|
|
1430
|
-
} else {
|
|
1431
|
-
const message = typeof error === "string" ? error : JSON.stringify(error);
|
|
1432
|
-
await this._apiClient.failTask(this._id, task.id, {
|
|
1433
|
-
error: {
|
|
1434
|
-
name: "Unknown error",
|
|
1435
|
-
message
|
|
1436
|
-
}
|
|
1437
|
-
});
|
|
1438
|
-
}
|
|
1439
|
-
throw error;
|
|
1440
|
-
}
|
|
1441
|
-
}, "executeTask");
|
|
1442
|
-
if (task.status === "WAITING") {
|
|
1443
|
-
this._logger.debug("Task waiting", {
|
|
1444
|
-
idempotencyKey,
|
|
1445
|
-
task
|
|
1446
|
-
});
|
|
1447
|
-
if (task.callbackUrl) {
|
|
1448
|
-
await this._taskStorage.run({
|
|
1449
|
-
taskId: task.id
|
|
1450
|
-
}, executeTask);
|
|
1451
|
-
}
|
|
1452
|
-
throw new ResumeWithTaskError(task);
|
|
1453
|
-
}
|
|
1454
|
-
if (task.status === "RUNNING" && typeof task.operation === "string") {
|
|
1455
|
-
this._logger.debug("Task running operation", {
|
|
1456
|
-
idempotencyKey,
|
|
1457
|
-
task
|
|
1458
|
-
});
|
|
1459
|
-
throw new ResumeWithTaskError(task);
|
|
1460
|
-
}
|
|
1461
|
-
return this._taskStorage.run({
|
|
1462
|
-
taskId: task.id
|
|
1463
|
-
}, executeTask);
|
|
1464
|
-
}
|
|
1465
|
-
yield(cacheKey) {
|
|
1466
|
-
if (!(0, import_core2.supportsFeature)("yieldExecution", this._serverVersion)) {
|
|
1467
|
-
console.warn("[trigger.dev] io.yield() is not support by the version of the Trigger.dev server you are using, you will need to upgrade your self-hosted Trigger.dev instance.");
|
|
1468
|
-
return;
|
|
1469
|
-
}
|
|
1470
|
-
if (this._yieldedExecutions.includes(cacheKey)) {
|
|
1471
|
-
return;
|
|
1472
|
-
}
|
|
1473
|
-
throw new YieldExecutionError(cacheKey);
|
|
1474
|
-
}
|
|
1475
|
-
async try(tryCallback, catchCallback) {
|
|
1476
|
-
try {
|
|
1477
|
-
return await tryCallback();
|
|
1478
|
-
} catch (error) {
|
|
1479
|
-
if (isTriggerError(error)) {
|
|
1480
|
-
throw error;
|
|
1481
|
-
}
|
|
1482
|
-
return await catchCallback(error);
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1485
|
-
get store() {
|
|
1486
|
-
return {
|
|
1487
|
-
env: this._envStore,
|
|
1488
|
-
job: this._jobStore,
|
|
1489
|
-
run: this._runStore
|
|
1490
|
-
};
|
|
1491
|
-
}
|
|
1492
|
-
};
|
|
1493
|
-
__name(IO, "IO");
|
|
1494
|
-
_addToCachedTasks = new WeakSet();
|
|
1495
|
-
addToCachedTasks_fn = /* @__PURE__ */ __name(function(task) {
|
|
1496
|
-
this._cachedTasks.set(task.idempotencyKey, task);
|
|
1497
|
-
}, "#addToCachedTasks");
|
|
1498
|
-
_detectAutoYield = new WeakSet();
|
|
1499
|
-
detectAutoYield_fn = /* @__PURE__ */ __name(function(location, threshold = 1500, task1, output) {
|
|
1500
|
-
const timeRemaining = __privateMethod(this, _getRemainingTimeInMillis, getRemainingTimeInMillis_fn).call(this);
|
|
1501
|
-
if (timeRemaining && timeRemaining < threshold) {
|
|
1502
|
-
if (task1) {
|
|
1503
|
-
throw new AutoYieldWithCompletedTaskExecutionError(task1.id, task1.outputProperties ?? [], {
|
|
1504
|
-
location,
|
|
1505
|
-
timeRemaining,
|
|
1506
|
-
timeElapsed: __privateMethod(this, _getTimeElapsed, getTimeElapsed_fn).call(this)
|
|
1507
|
-
}, output);
|
|
1508
|
-
} else {
|
|
1509
|
-
throw new AutoYieldExecutionError(location, timeRemaining, __privateMethod(this, _getTimeElapsed, getTimeElapsed_fn).call(this));
|
|
1510
|
-
}
|
|
1511
|
-
}
|
|
1512
|
-
}, "#detectAutoYield");
|
|
1513
|
-
_forceYield = new WeakSet();
|
|
1514
|
-
forceYield_fn = /* @__PURE__ */ __name(function(location1) {
|
|
1515
|
-
const timeRemaining = __privateMethod(this, _getRemainingTimeInMillis, getRemainingTimeInMillis_fn).call(this);
|
|
1516
|
-
if (timeRemaining) {
|
|
1517
|
-
throw new AutoYieldExecutionError(location1, timeRemaining, __privateMethod(this, _getTimeElapsed, getTimeElapsed_fn).call(this));
|
|
1518
|
-
}
|
|
1519
|
-
}, "#forceYield");
|
|
1520
|
-
_getTimeElapsed = new WeakSet();
|
|
1521
|
-
getTimeElapsed_fn = /* @__PURE__ */ __name(function() {
|
|
1522
|
-
return performance.now() - this._timeOrigin;
|
|
1523
|
-
}, "#getTimeElapsed");
|
|
1524
|
-
_getRemainingTimeInMillis = new WeakSet();
|
|
1525
|
-
getRemainingTimeInMillis_fn = /* @__PURE__ */ __name(function() {
|
|
1526
|
-
if (this._executionTimeout) {
|
|
1527
|
-
return this._executionTimeout - (performance.now() - this._timeOrigin);
|
|
1528
|
-
}
|
|
1529
|
-
return void 0;
|
|
1530
|
-
}, "#getRemainingTimeInMillis");
|
|
1531
|
-
async function generateIdempotencyKey(keyMaterial) {
|
|
1532
|
-
const keys = keyMaterial.map((key2) => {
|
|
1533
|
-
if (typeof key2 === "string") {
|
|
1534
|
-
return key2;
|
|
1535
|
-
}
|
|
1536
|
-
return stableStringify(key2);
|
|
1537
|
-
});
|
|
1538
|
-
const key = keys.join(":");
|
|
1539
|
-
const hash = await import_node_crypto.webcrypto.subtle.digest("SHA-256", Buffer.from(key));
|
|
1540
|
-
return Buffer.from(hash).toString("hex");
|
|
1541
|
-
}
|
|
1542
|
-
__name(generateIdempotencyKey, "generateIdempotencyKey");
|
|
1543
|
-
function stableStringify(obj) {
|
|
1544
|
-
function sortKeys(obj2) {
|
|
1545
|
-
if (typeof obj2 !== "object" || obj2 === null) {
|
|
1546
|
-
return obj2;
|
|
1547
|
-
}
|
|
1548
|
-
if (Array.isArray(obj2)) {
|
|
1549
|
-
return obj2.map(sortKeys);
|
|
1550
|
-
}
|
|
1551
|
-
const sortedKeys = Object.keys(obj2).sort();
|
|
1552
|
-
const sortedObj2 = {};
|
|
1553
|
-
for (const key of sortedKeys) {
|
|
1554
|
-
sortedObj2[key] = sortKeys(obj2[key]);
|
|
1555
|
-
}
|
|
1556
|
-
return sortedObj2;
|
|
1557
|
-
}
|
|
1558
|
-
__name(sortKeys, "sortKeys");
|
|
1559
|
-
const sortedObj = sortKeys(obj);
|
|
1560
|
-
return JSON.stringify(sortedObj);
|
|
1561
|
-
}
|
|
1562
|
-
__name(stableStringify, "stableStringify");
|
|
1563
|
-
var IOLogger = class {
|
|
1564
|
-
constructor(callback) {
|
|
1565
|
-
this.callback = callback;
|
|
1566
|
-
}
|
|
1567
|
-
log(message, properties) {
|
|
1568
|
-
return this.callback("LOG", message, properties);
|
|
1569
|
-
}
|
|
1570
|
-
debug(message, properties) {
|
|
1571
|
-
return this.callback("DEBUG", message, properties);
|
|
1572
|
-
}
|
|
1573
|
-
info(message, properties) {
|
|
1574
|
-
return this.callback("INFO", message, properties);
|
|
1575
|
-
}
|
|
1576
|
-
warn(message, properties) {
|
|
1577
|
-
return this.callback("WARN", message, properties);
|
|
1578
|
-
}
|
|
1579
|
-
error(message, properties) {
|
|
1580
|
-
return this.callback("ERROR", message, properties);
|
|
1581
|
-
}
|
|
1582
|
-
};
|
|
1583
|
-
__name(IOLogger, "IOLogger");
|
|
1584
|
-
async function spaceOut(callback, index, delay) {
|
|
1585
|
-
await new Promise((resolve) => setTimeout(resolve, index * delay));
|
|
1586
|
-
return await callback();
|
|
1587
|
-
}
|
|
1588
|
-
__name(spaceOut, "spaceOut");
|
|
1589
|
-
function sendEventOptionsProperties(options) {
|
|
1590
|
-
return [
|
|
1591
|
-
...options?.accountId ? [
|
|
1592
|
-
{
|
|
1593
|
-
label: "Account ID",
|
|
1594
|
-
text: options.accountId
|
|
1595
|
-
}
|
|
1596
|
-
] : [],
|
|
1597
|
-
...options?.deliverAfter ? [
|
|
1598
|
-
{
|
|
1599
|
-
label: "Deliver After",
|
|
1600
|
-
text: `${options.deliverAfter}s`
|
|
1601
|
-
}
|
|
1602
|
-
] : [],
|
|
1603
|
-
...options?.deliverAt ? [
|
|
1604
|
-
{
|
|
1605
|
-
label: "Deliver At",
|
|
1606
|
-
text: options.deliverAt.toISOString()
|
|
1607
|
-
}
|
|
1608
|
-
] : []
|
|
1609
|
-
];
|
|
1610
|
-
}
|
|
1611
|
-
__name(sendEventOptionsProperties, "sendEventOptionsProperties");
|
|
1612
|
-
|
|
1613
|
-
// src/store/keyValueStoreClient.ts
|
|
1614
|
-
var _serializer, _namespacedKey2, namespacedKey_fn2;
|
|
1615
|
-
var KeyValueStoreClient = class {
|
|
1616
|
-
constructor(queryStore, type = null, namespace = "") {
|
|
1617
|
-
__privateAdd(this, _namespacedKey2);
|
|
1618
|
-
__privateAdd(this, _serializer, void 0);
|
|
1619
|
-
this.queryStore = queryStore;
|
|
1620
|
-
this.type = type;
|
|
1621
|
-
this.namespace = namespace;
|
|
1622
|
-
__privateSet(this, _serializer, new JSONOutputSerializer());
|
|
1623
|
-
}
|
|
1624
|
-
async delete(key) {
|
|
1625
|
-
const result = await this.queryStore("DELETE", {
|
|
1626
|
-
key: __privateMethod(this, _namespacedKey2, namespacedKey_fn2).call(this, key)
|
|
1627
|
-
});
|
|
1628
|
-
if (result.action !== "DELETE") {
|
|
1629
|
-
throw new Error(`Unexpected key-value store response: ${result.action}`);
|
|
1630
|
-
}
|
|
1631
|
-
return result.deleted;
|
|
1632
|
-
}
|
|
1633
|
-
async get(key) {
|
|
1634
|
-
const result = await this.queryStore("GET", {
|
|
1635
|
-
key: __privateMethod(this, _namespacedKey2, namespacedKey_fn2).call(this, key)
|
|
1636
|
-
});
|
|
1637
|
-
if (result.action !== "GET") {
|
|
1638
|
-
throw new Error(`Unexpected key-value store response: ${result.action}`);
|
|
1639
|
-
}
|
|
1640
|
-
return __privateGet(this, _serializer).deserialize(result.value);
|
|
1641
|
-
}
|
|
1642
|
-
async has(key) {
|
|
1643
|
-
const result = await this.queryStore("HAS", {
|
|
1644
|
-
key: __privateMethod(this, _namespacedKey2, namespacedKey_fn2).call(this, key)
|
|
1645
|
-
});
|
|
1646
|
-
if (result.action !== "HAS") {
|
|
1647
|
-
throw new Error(`Unexpected key-value store response: ${result.action}`);
|
|
1648
|
-
}
|
|
1649
|
-
return result.has;
|
|
1650
|
-
}
|
|
1651
|
-
async set(key, value) {
|
|
1652
|
-
const result = await this.queryStore("SET", {
|
|
1653
|
-
key: __privateMethod(this, _namespacedKey2, namespacedKey_fn2).call(this, key),
|
|
1654
|
-
value: __privateGet(this, _serializer).serialize(value)
|
|
1655
|
-
});
|
|
1656
|
-
if (result.action !== "SET") {
|
|
1657
|
-
throw new Error(`Unexpected key-value store response: ${result.action}`);
|
|
1658
|
-
}
|
|
1659
|
-
return __privateGet(this, _serializer).deserialize(result.value);
|
|
1660
|
-
}
|
|
1661
|
-
};
|
|
1662
|
-
__name(KeyValueStoreClient, "KeyValueStoreClient");
|
|
1663
|
-
_serializer = new WeakMap();
|
|
1664
|
-
_namespacedKey2 = new WeakSet();
|
|
1665
|
-
namespacedKey_fn2 = /* @__PURE__ */ __name(function(key) {
|
|
1666
|
-
const parts = [];
|
|
1667
|
-
if (this.type) {
|
|
1668
|
-
parts.push(this.type);
|
|
1669
|
-
}
|
|
1670
|
-
if (this.namespace) {
|
|
1671
|
-
parts.push(this.namespace);
|
|
1672
|
-
}
|
|
1673
|
-
parts.push(key);
|
|
1674
|
-
return parts.join(":");
|
|
1675
|
-
}, "#namespacedKey");
|
|
1676
|
-
|
|
1677
|
-
// src/apiClient.ts
|
|
1678
|
-
var _apiUrl, _options, _logger, _storeClient, _queryKeyValueStore, queryKeyValueStore_fn, _apiKey, apiKey_fn;
|
|
1679
|
-
var ApiClient = class {
|
|
1680
|
-
constructor(options) {
|
|
1681
|
-
__privateAdd(this, _queryKeyValueStore);
|
|
1682
|
-
__privateAdd(this, _apiKey);
|
|
1683
|
-
__privateAdd(this, _apiUrl, void 0);
|
|
1684
|
-
__privateAdd(this, _options, void 0);
|
|
1685
|
-
__privateAdd(this, _logger, void 0);
|
|
1686
|
-
__privateAdd(this, _storeClient, void 0);
|
|
1687
|
-
__privateSet(this, _options, options);
|
|
1688
|
-
__privateSet(this, _apiUrl, __privateGet(this, _options).apiUrl ?? process.env.TRIGGER_API_URL ?? "https://api.trigger.dev");
|
|
1689
|
-
__privateSet(this, _logger, new import_core3.Logger("trigger.dev", __privateGet(this, _options).logLevel));
|
|
1690
|
-
__privateSet(this, _storeClient, new KeyValueStoreClient(__privateMethod(this, _queryKeyValueStore, queryKeyValueStore_fn).bind(this)));
|
|
1691
|
-
}
|
|
1692
|
-
async registerEndpoint(options) {
|
|
1693
|
-
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1694
|
-
__privateGet(this, _logger).debug("Registering endpoint", {
|
|
1695
|
-
url: options.url,
|
|
1696
|
-
name: options.name
|
|
1697
|
-
});
|
|
1698
|
-
const response = await fetch(`${__privateGet(this, _apiUrl)}/api/v1/endpoints`, {
|
|
1699
|
-
method: "POST",
|
|
1700
|
-
headers: {
|
|
1701
|
-
"Content-Type": "application/json",
|
|
1702
|
-
Authorization: `Bearer ${apiKey}`
|
|
1703
|
-
},
|
|
1704
|
-
body: JSON.stringify({
|
|
1705
|
-
url: options.url,
|
|
1706
|
-
name: options.name
|
|
1707
|
-
})
|
|
1708
|
-
});
|
|
1709
|
-
if (response.status >= 400 && response.status < 500) {
|
|
1710
|
-
const body = await response.json();
|
|
1711
|
-
throw new Error(body.error);
|
|
1712
|
-
}
|
|
1713
|
-
if (response.status !== 200) {
|
|
1714
|
-
throw new Error(`Failed to register entry point, got status code ${response.status}`);
|
|
1715
|
-
}
|
|
1716
|
-
return await response.json();
|
|
1717
|
-
}
|
|
1718
|
-
async runTask(runId, task, options = {}) {
|
|
1719
|
-
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1720
|
-
__privateGet(this, _logger).debug("Running Task", {
|
|
1721
|
-
task
|
|
1722
|
-
});
|
|
1723
|
-
return await zodfetchWithVersions({
|
|
1724
|
-
[import_core3.API_VERSIONS.LAZY_LOADED_CACHED_TASKS]: import_core3.RunTaskResponseWithCachedTasksBodySchema
|
|
1725
|
-
}, import_core3.ServerTaskSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/tasks`, {
|
|
1726
|
-
method: "POST",
|
|
1727
|
-
headers: {
|
|
1728
|
-
"Content-Type": "application/json",
|
|
1729
|
-
Authorization: `Bearer ${apiKey}`,
|
|
1730
|
-
"Idempotency-Key": task.idempotencyKey,
|
|
1731
|
-
"X-Cached-Tasks-Cursor": options.cachedTasksCursor ?? "",
|
|
1732
|
-
"Trigger-Version": import_core3.API_VERSIONS.LAZY_LOADED_CACHED_TASKS
|
|
1733
|
-
},
|
|
1734
|
-
body: JSON.stringify(task)
|
|
1735
|
-
});
|
|
1736
|
-
}
|
|
1737
|
-
async completeTask(runId, id, task) {
|
|
1738
|
-
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1739
|
-
__privateGet(this, _logger).debug("Complete Task", {
|
|
1740
|
-
task
|
|
1741
|
-
});
|
|
1742
|
-
return await zodfetch(import_core3.ServerTaskSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/tasks/${id}/complete`, {
|
|
1743
|
-
method: "POST",
|
|
1744
|
-
headers: {
|
|
1745
|
-
"Content-Type": "application/json",
|
|
1746
|
-
Authorization: `Bearer ${apiKey}`,
|
|
1747
|
-
"Trigger-Version": import_core3.API_VERSIONS.SERIALIZED_TASK_OUTPUT
|
|
1748
|
-
},
|
|
1749
|
-
body: JSON.stringify(task)
|
|
1750
|
-
});
|
|
1751
|
-
}
|
|
1752
|
-
async failTask(runId, id, body) {
|
|
1753
|
-
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1754
|
-
__privateGet(this, _logger).debug("Fail Task", {
|
|
1755
|
-
id,
|
|
1756
|
-
runId,
|
|
1757
|
-
body
|
|
1758
|
-
});
|
|
1759
|
-
return await zodfetch(import_core3.ServerTaskSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/tasks/${id}/fail`, {
|
|
1760
|
-
method: "POST",
|
|
1761
|
-
headers: {
|
|
1762
|
-
"Content-Type": "application/json",
|
|
1763
|
-
Authorization: `Bearer ${apiKey}`
|
|
1764
|
-
},
|
|
1765
|
-
body: JSON.stringify(body)
|
|
1766
|
-
});
|
|
1767
|
-
}
|
|
1768
|
-
async sendEvent(event, options = {}) {
|
|
1769
|
-
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1770
|
-
__privateGet(this, _logger).debug("Sending event", {
|
|
1771
|
-
event
|
|
1772
|
-
});
|
|
1773
|
-
return await zodfetch(import_core3.ApiEventLogSchema, `${__privateGet(this, _apiUrl)}/api/v1/events`, {
|
|
1774
|
-
method: "POST",
|
|
1775
|
-
headers: {
|
|
1776
|
-
"Content-Type": "application/json",
|
|
1777
|
-
Authorization: `Bearer ${apiKey}`
|
|
1778
|
-
},
|
|
1779
|
-
body: JSON.stringify({
|
|
1780
|
-
event,
|
|
1781
|
-
options
|
|
1782
|
-
})
|
|
1783
|
-
});
|
|
1784
|
-
}
|
|
1785
|
-
async sendEvents(events, options = {}) {
|
|
1786
|
-
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1787
|
-
__privateGet(this, _logger).debug("Sending multiple events", {
|
|
1788
|
-
events
|
|
1789
|
-
});
|
|
1790
|
-
return await zodfetch(import_core3.ApiEventLogSchema.array(), `${__privateGet(this, _apiUrl)}/api/v1/events/bulk`, {
|
|
1791
|
-
method: "POST",
|
|
1792
|
-
headers: {
|
|
1793
|
-
"Content-Type": "application/json",
|
|
1794
|
-
Authorization: `Bearer ${apiKey}`
|
|
1795
|
-
},
|
|
1796
|
-
body: JSON.stringify({
|
|
1797
|
-
events,
|
|
1798
|
-
options
|
|
1799
|
-
})
|
|
1800
|
-
});
|
|
1801
|
-
}
|
|
1802
|
-
async cancelEvent(eventId) {
|
|
1803
|
-
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1804
|
-
__privateGet(this, _logger).debug("Cancelling event", {
|
|
1805
|
-
eventId
|
|
1806
|
-
});
|
|
1807
|
-
return await zodfetch(import_core3.ApiEventLogSchema, `${__privateGet(this, _apiUrl)}/api/v1/events/${eventId}/cancel`, {
|
|
1808
|
-
method: "POST",
|
|
1809
|
-
headers: {
|
|
1810
|
-
"Content-Type": "application/json",
|
|
1811
|
-
Authorization: `Bearer ${apiKey}`
|
|
1812
|
-
}
|
|
1813
|
-
});
|
|
1814
|
-
}
|
|
1815
|
-
async cancelRunsForEvent(eventId) {
|
|
1816
|
-
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1817
|
-
__privateGet(this, _logger).debug("Cancelling runs for event", {
|
|
1818
|
-
eventId
|
|
1819
|
-
});
|
|
1820
|
-
return await zodfetch(import_core3.CancelRunsForEventSchema, `${__privateGet(this, _apiUrl)}/api/v1/events/${eventId}/cancel-runs`, {
|
|
1821
|
-
method: "POST",
|
|
1822
|
-
headers: {
|
|
1823
|
-
"Content-Type": "application/json",
|
|
1824
|
-
Authorization: `Bearer ${apiKey}`
|
|
1825
|
-
}
|
|
1826
|
-
});
|
|
1827
|
-
}
|
|
1828
|
-
async updateStatus(runId, id, status) {
|
|
1829
|
-
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1830
|
-
__privateGet(this, _logger).debug("Update status", {
|
|
1831
|
-
id,
|
|
1832
|
-
status
|
|
1833
|
-
});
|
|
1834
|
-
return await zodfetch(import_core3.JobRunStatusRecordSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/statuses/${id}`, {
|
|
1835
|
-
method: "PUT",
|
|
1836
|
-
headers: {
|
|
1837
|
-
"Content-Type": "application/json",
|
|
1838
|
-
Authorization: `Bearer ${apiKey}`
|
|
1839
|
-
},
|
|
1840
|
-
body: JSON.stringify(status)
|
|
1841
|
-
});
|
|
1842
|
-
}
|
|
1843
|
-
async updateSource(client, key, source) {
|
|
1844
|
-
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1845
|
-
__privateGet(this, _logger).debug("activating http source", {
|
|
1846
|
-
source
|
|
1847
|
-
});
|
|
1848
|
-
const response = await zodfetch(import_core3.TriggerSourceSchema, `${__privateGet(this, _apiUrl)}/api/v2/${client}/sources/${key}`, {
|
|
1849
|
-
method: "PUT",
|
|
1850
|
-
headers: {
|
|
1851
|
-
"Content-Type": "application/json",
|
|
1852
|
-
Authorization: `Bearer ${apiKey}`
|
|
1853
|
-
},
|
|
1854
|
-
body: JSON.stringify(source)
|
|
1855
|
-
});
|
|
1856
|
-
return response;
|
|
1857
|
-
}
|
|
1858
|
-
async updateWebhook(key, webhookData) {
|
|
1859
|
-
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1860
|
-
__privateGet(this, _logger).debug("activating webhook", {
|
|
1861
|
-
webhookData
|
|
1862
|
-
});
|
|
1863
|
-
const response = await zodfetch(import_core3.TriggerSourceSchema, `${__privateGet(this, _apiUrl)}/api/v1/webhooks/${key}`, {
|
|
1864
|
-
method: "PUT",
|
|
1865
|
-
headers: {
|
|
1866
|
-
"Content-Type": "application/json",
|
|
1867
|
-
Authorization: `Bearer ${apiKey}`
|
|
1868
|
-
},
|
|
1869
|
-
body: JSON.stringify(webhookData)
|
|
1870
|
-
});
|
|
1871
|
-
return response;
|
|
1872
|
-
}
|
|
1873
|
-
async registerTrigger(client, id, key, payload, idempotencyKey) {
|
|
1874
|
-
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1875
|
-
__privateGet(this, _logger).debug("registering trigger", {
|
|
1876
|
-
id,
|
|
1877
|
-
payload
|
|
1878
|
-
});
|
|
1879
|
-
const headers = {
|
|
1880
|
-
"Content-Type": "application/json",
|
|
1881
|
-
Authorization: `Bearer ${apiKey}`
|
|
1882
|
-
};
|
|
1883
|
-
if (idempotencyKey) {
|
|
1884
|
-
headers["Idempotency-Key"] = idempotencyKey;
|
|
1885
|
-
}
|
|
1886
|
-
const response = await zodfetch(import_core3.RegisterSourceEventSchemaV2, `${__privateGet(this, _apiUrl)}/api/v2/${client}/triggers/${id}/registrations/${key}`, {
|
|
1887
|
-
method: "PUT",
|
|
1888
|
-
headers,
|
|
1889
|
-
body: JSON.stringify(payload)
|
|
1890
|
-
});
|
|
1891
|
-
return response;
|
|
1892
|
-
}
|
|
1893
|
-
async registerSchedule(client, id, key, payload) {
|
|
1894
|
-
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1895
|
-
__privateGet(this, _logger).debug("registering schedule", {
|
|
1896
|
-
id,
|
|
1897
|
-
payload
|
|
1898
|
-
});
|
|
1899
|
-
const response = await zodfetch(import_core3.RegisterScheduleResponseBodySchema, `${__privateGet(this, _apiUrl)}/api/v1/${client}/schedules/${id}/registrations`, {
|
|
1900
|
-
method: "POST",
|
|
1901
|
-
headers: {
|
|
1902
|
-
"Content-Type": "application/json",
|
|
1903
|
-
Authorization: `Bearer ${apiKey}`
|
|
1904
|
-
},
|
|
1905
|
-
body: JSON.stringify({
|
|
1906
|
-
id: key,
|
|
1907
|
-
...payload
|
|
1908
|
-
})
|
|
1909
|
-
});
|
|
1910
|
-
return response;
|
|
1911
|
-
}
|
|
1912
|
-
async unregisterSchedule(client, id, key) {
|
|
1913
|
-
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1914
|
-
__privateGet(this, _logger).debug("unregistering schedule", {
|
|
1915
|
-
id
|
|
1916
|
-
});
|
|
1917
|
-
const response = await zodfetch(import_zod3.z.object({
|
|
1918
|
-
ok: import_zod3.z.boolean()
|
|
1919
|
-
}), `${__privateGet(this, _apiUrl)}/api/v1/${client}/schedules/${id}/registrations/${encodeURIComponent(key)}`, {
|
|
1920
|
-
method: "DELETE",
|
|
1921
|
-
headers: {
|
|
1922
|
-
"Content-Type": "application/json",
|
|
1923
|
-
Authorization: `Bearer ${apiKey}`
|
|
1924
|
-
}
|
|
1925
|
-
});
|
|
1926
|
-
return response;
|
|
1927
|
-
}
|
|
1928
|
-
async getAuth(client, id) {
|
|
1929
|
-
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1930
|
-
__privateGet(this, _logger).debug("getting auth", {
|
|
1931
|
-
id
|
|
1932
|
-
});
|
|
1933
|
-
const response = await zodfetch(import_core3.ConnectionAuthSchema, `${__privateGet(this, _apiUrl)}/api/v1/${client}/auth/${id}`, {
|
|
1934
|
-
method: "GET",
|
|
1935
|
-
headers: {
|
|
1936
|
-
Accept: "application/json",
|
|
1937
|
-
Authorization: `Bearer ${apiKey}`
|
|
1938
|
-
}
|
|
1939
|
-
}, {
|
|
1940
|
-
optional: true
|
|
1941
|
-
});
|
|
1942
|
-
return response;
|
|
1943
|
-
}
|
|
1944
|
-
async getEvent(eventId) {
|
|
1945
|
-
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1946
|
-
__privateGet(this, _logger).debug("Getting Event", {
|
|
1947
|
-
eventId
|
|
1948
|
-
});
|
|
1949
|
-
return await zodfetch(import_core3.GetEventSchema, `${__privateGet(this, _apiUrl)}/api/v1/events/${eventId}`, {
|
|
1950
|
-
method: "GET",
|
|
1951
|
-
headers: {
|
|
1952
|
-
Authorization: `Bearer ${apiKey}`
|
|
1953
|
-
}
|
|
1954
|
-
});
|
|
1955
|
-
}
|
|
1956
|
-
async getRun(runId, options) {
|
|
1957
|
-
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1958
|
-
__privateGet(this, _logger).debug("Getting Run", {
|
|
1959
|
-
runId
|
|
1960
|
-
});
|
|
1961
|
-
return await zodfetch(import_core3.GetRunSchema, (0, import_core3.urlWithSearchParams)(`${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}`, options), {
|
|
1962
|
-
method: "GET",
|
|
1963
|
-
headers: {
|
|
1964
|
-
Authorization: `Bearer ${apiKey}`
|
|
1965
|
-
}
|
|
1966
|
-
});
|
|
1967
|
-
}
|
|
1968
|
-
async cancelRun(runId) {
|
|
1969
|
-
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1970
|
-
__privateGet(this, _logger).debug("Cancelling Run", {
|
|
1971
|
-
runId
|
|
1972
|
-
});
|
|
1973
|
-
return await zodfetch(import_core3.GetRunSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/cancel`, {
|
|
1974
|
-
method: "POST",
|
|
1975
|
-
headers: {
|
|
1976
|
-
"Content-Type": "application/json",
|
|
1977
|
-
Authorization: `Bearer ${apiKey}`
|
|
1978
|
-
}
|
|
1979
|
-
});
|
|
1980
|
-
}
|
|
1981
|
-
async getRunStatuses(runId) {
|
|
1982
|
-
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1983
|
-
__privateGet(this, _logger).debug("Getting Run statuses", {
|
|
1984
|
-
runId
|
|
1985
|
-
});
|
|
1986
|
-
return await zodfetch(import_core3.GetRunStatusesSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/statuses`, {
|
|
1987
|
-
method: "GET",
|
|
1988
|
-
headers: {
|
|
1989
|
-
Authorization: `Bearer ${apiKey}`
|
|
1990
|
-
}
|
|
1991
|
-
});
|
|
1992
|
-
}
|
|
1993
|
-
async getRuns(jobSlug, options) {
|
|
1994
|
-
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
1995
|
-
__privateGet(this, _logger).debug("Getting Runs", {
|
|
1996
|
-
jobSlug
|
|
1997
|
-
});
|
|
1998
|
-
return await zodfetch(import_core3.GetRunsSchema, (0, import_core3.urlWithSearchParams)(`${__privateGet(this, _apiUrl)}/api/v1/jobs/${jobSlug}/runs`, options), {
|
|
1999
|
-
method: "GET",
|
|
2000
|
-
headers: {
|
|
2001
|
-
Authorization: `Bearer ${apiKey}`
|
|
2002
|
-
}
|
|
2003
|
-
});
|
|
2004
|
-
}
|
|
2005
|
-
async invokeJob(jobId, payload, options = {}) {
|
|
2006
|
-
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
2007
|
-
__privateGet(this, _logger).debug("Invoking Job", {
|
|
2008
|
-
jobId
|
|
2009
|
-
});
|
|
2010
|
-
const body = {
|
|
2011
|
-
payload,
|
|
2012
|
-
context: options.context ?? {},
|
|
2013
|
-
options: {
|
|
2014
|
-
accountId: options.accountId,
|
|
2015
|
-
callbackUrl: options.callbackUrl
|
|
2016
|
-
}
|
|
2017
|
-
};
|
|
2018
|
-
return await zodfetch(import_core3.InvokeJobResponseSchema, `${__privateGet(this, _apiUrl)}/api/v1/jobs/${jobId}/invoke`, {
|
|
2019
|
-
method: "POST",
|
|
2020
|
-
headers: {
|
|
2021
|
-
"Content-Type": "application/json",
|
|
2022
|
-
Authorization: `Bearer ${apiKey}`,
|
|
2023
|
-
...options.idempotencyKey ? {
|
|
2024
|
-
"Idempotency-Key": options.idempotencyKey
|
|
2025
|
-
} : {}
|
|
2026
|
-
},
|
|
2027
|
-
body: JSON.stringify(body)
|
|
2028
|
-
});
|
|
2029
|
-
}
|
|
2030
|
-
async createEphemeralEventDispatcher(payload) {
|
|
2031
|
-
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
2032
|
-
__privateGet(this, _logger).debug("Creating ephemeral event dispatcher", {
|
|
2033
|
-
payload
|
|
2034
|
-
});
|
|
2035
|
-
const response = await zodfetch(import_core3.EphemeralEventDispatcherResponseBodySchema, `${__privateGet(this, _apiUrl)}/api/v1/event-dispatchers/ephemeral`, {
|
|
2036
|
-
method: "POST",
|
|
2037
|
-
headers: {
|
|
2038
|
-
"Content-Type": "application/json",
|
|
2039
|
-
Authorization: `Bearer ${apiKey}`
|
|
2040
|
-
},
|
|
2041
|
-
body: JSON.stringify(payload)
|
|
2042
|
-
});
|
|
2043
|
-
return response;
|
|
2044
|
-
}
|
|
2045
|
-
get store() {
|
|
2046
|
-
return __privateGet(this, _storeClient);
|
|
2047
|
-
}
|
|
2048
|
-
};
|
|
2049
|
-
__name(ApiClient, "ApiClient");
|
|
2050
|
-
_apiUrl = new WeakMap();
|
|
2051
|
-
_options = new WeakMap();
|
|
2052
|
-
_logger = new WeakMap();
|
|
2053
|
-
_storeClient = new WeakMap();
|
|
2054
|
-
_queryKeyValueStore = new WeakSet();
|
|
2055
|
-
queryKeyValueStore_fn = /* @__PURE__ */ __name(async function(action, data) {
|
|
2056
|
-
const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
|
|
2057
|
-
__privateGet(this, _logger).debug("accessing key-value store", {
|
|
2058
|
-
action,
|
|
2059
|
-
data
|
|
2060
|
-
});
|
|
2061
|
-
const STORE_URL = `${__privateGet(this, _apiUrl)}/api/v1/store/${data.key}`;
|
|
2062
|
-
const authHeader = {
|
|
2063
|
-
Authorization: `Bearer ${apiKey}`
|
|
2064
|
-
};
|
|
2065
|
-
let requestInit;
|
|
2066
|
-
switch (action) {
|
|
2067
|
-
case "DELETE": {
|
|
2068
|
-
requestInit = {
|
|
2069
|
-
method: "DELETE",
|
|
2070
|
-
headers: authHeader
|
|
2071
|
-
};
|
|
2072
|
-
break;
|
|
2073
|
-
}
|
|
2074
|
-
case "GET": {
|
|
2075
|
-
requestInit = {
|
|
2076
|
-
method: "GET",
|
|
2077
|
-
headers: authHeader
|
|
2078
|
-
};
|
|
2079
|
-
break;
|
|
2080
|
-
}
|
|
2081
|
-
case "HAS": {
|
|
2082
|
-
const headResponse = await fetchHead(STORE_URL, {
|
|
2083
|
-
headers: authHeader
|
|
2084
|
-
});
|
|
2085
|
-
return {
|
|
2086
|
-
action: "HAS",
|
|
2087
|
-
key: data.key,
|
|
2088
|
-
has: !!headResponse.ok
|
|
2089
|
-
};
|
|
2090
|
-
}
|
|
2091
|
-
case "SET": {
|
|
2092
|
-
const MAX_BODY_BYTE_LENGTH = 256 * 1024;
|
|
2093
|
-
if ((data.value?.length ?? 0) > MAX_BODY_BYTE_LENGTH) {
|
|
2094
|
-
throw new Error(`Max request body size exceeded: ${MAX_BODY_BYTE_LENGTH} bytes`);
|
|
2095
|
-
}
|
|
2096
|
-
requestInit = {
|
|
2097
|
-
method: "PUT",
|
|
2098
|
-
headers: {
|
|
2099
|
-
...authHeader,
|
|
2100
|
-
"Content-Type": "text/plain"
|
|
2101
|
-
},
|
|
2102
|
-
body: data.value
|
|
2103
|
-
};
|
|
2104
|
-
break;
|
|
2105
|
-
}
|
|
2106
|
-
default: {
|
|
2107
|
-
(0, import_core3.assertExhaustive)(action);
|
|
2108
|
-
}
|
|
2109
|
-
}
|
|
2110
|
-
const response = await zodfetch(import_core3.KeyValueStoreResponseBodySchema, STORE_URL, requestInit);
|
|
2111
|
-
return response;
|
|
2112
|
-
}, "#queryKeyValueStore");
|
|
2113
|
-
_apiKey = new WeakSet();
|
|
2114
|
-
apiKey_fn = /* @__PURE__ */ __name(async function() {
|
|
2115
|
-
const apiKey = getApiKey(__privateGet(this, _options).apiKey);
|
|
2116
|
-
if (apiKey.status === "invalid") {
|
|
2117
|
-
throw new Error("Invalid API key");
|
|
2118
|
-
} else if (apiKey.status === "missing") {
|
|
2119
|
-
throw new Error("Missing API key");
|
|
2120
|
-
}
|
|
2121
|
-
return apiKey.apiKey;
|
|
2122
|
-
}, "#apiKey");
|
|
2123
|
-
function getApiKey(key) {
|
|
2124
|
-
const apiKey = key ?? process.env.TRIGGER_API_KEY;
|
|
2125
|
-
if (!apiKey) {
|
|
2126
|
-
return {
|
|
2127
|
-
status: "missing"
|
|
2128
|
-
};
|
|
2129
|
-
}
|
|
2130
|
-
const isValid = apiKey.match(/^tr_[a-z]+_[a-zA-Z0-9]+$/);
|
|
2131
|
-
if (!isValid) {
|
|
2132
|
-
return {
|
|
2133
|
-
status: "invalid",
|
|
2134
|
-
apiKey
|
|
2135
|
-
};
|
|
2136
|
-
}
|
|
2137
|
-
return {
|
|
2138
|
-
status: "valid",
|
|
2139
|
-
apiKey
|
|
2140
|
-
};
|
|
2141
|
-
}
|
|
2142
|
-
__name(getApiKey, "getApiKey");
|
|
2143
|
-
async function zodfetchWithVersions(versionedSchemaMap, unversionedSchema, url, requestInit, options, retryCount = 0) {
|
|
2144
|
-
const response = await fetch(url, {
|
|
2145
|
-
...requestInit,
|
|
2146
|
-
cache: "no-cache"
|
|
2147
|
-
});
|
|
2148
|
-
if ((!requestInit || requestInit.method === "GET") && response.status === 404 && options?.optional) {
|
|
2149
|
-
return;
|
|
2150
|
-
}
|
|
2151
|
-
if (response.status >= 400 && response.status < 500) {
|
|
2152
|
-
const body = await response.json();
|
|
2153
|
-
throw new Error(body.error);
|
|
2154
|
-
}
|
|
2155
|
-
if (response.status >= 500 && retryCount < 6) {
|
|
2156
|
-
const delay = exponentialBackoff(retryCount + 1, 2, 50, 1150, 50);
|
|
2157
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
2158
|
-
return zodfetchWithVersions(versionedSchemaMap, unversionedSchema, url, requestInit, options, retryCount + 1);
|
|
2159
|
-
}
|
|
2160
|
-
if (response.status !== 200) {
|
|
2161
|
-
throw new Error(options?.errorMessage ?? `Failed to fetch ${url}, got status code ${response.status}`);
|
|
2162
|
-
}
|
|
2163
|
-
const jsonBody = await response.json();
|
|
2164
|
-
const version2 = response.headers.get("trigger-version");
|
|
2165
|
-
if (!version2) {
|
|
2166
|
-
return {
|
|
2167
|
-
version: "unversioned",
|
|
2168
|
-
body: unversionedSchema.parse(jsonBody)
|
|
2169
|
-
};
|
|
2170
|
-
}
|
|
2171
|
-
const versionedSchema = versionedSchemaMap[version2];
|
|
2172
|
-
if (!versionedSchema) {
|
|
2173
|
-
throw new Error(`Unknown version ${version2}`);
|
|
2174
|
-
}
|
|
2175
|
-
return {
|
|
2176
|
-
version: version2,
|
|
2177
|
-
body: versionedSchema.parse(jsonBody)
|
|
2178
|
-
};
|
|
2179
|
-
}
|
|
2180
|
-
__name(zodfetchWithVersions, "zodfetchWithVersions");
|
|
2181
|
-
async function fetchHead(url, requestInitWithoutMethod, retryCount = 0) {
|
|
2182
|
-
const requestInit = {
|
|
2183
|
-
...requestInitWithoutMethod,
|
|
2184
|
-
method: "HEAD"
|
|
2185
|
-
};
|
|
2186
|
-
const response = await fetch(url, {
|
|
2187
|
-
...requestInit,
|
|
2188
|
-
cache: "no-cache"
|
|
2189
|
-
});
|
|
2190
|
-
if (response.status >= 500 && retryCount < 6) {
|
|
2191
|
-
const delay = exponentialBackoff(retryCount + 1, 2, 50, 1150, 50);
|
|
2192
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
2193
|
-
return fetchHead(url, requestInitWithoutMethod, retryCount + 1);
|
|
2194
|
-
}
|
|
2195
|
-
return response;
|
|
2196
|
-
}
|
|
2197
|
-
__name(fetchHead, "fetchHead");
|
|
2198
|
-
async function zodfetch(schema, url, requestInit, options, retryCount = 0) {
|
|
2199
|
-
const response = await fetch(url, {
|
|
2200
|
-
...requestInit,
|
|
2201
|
-
cache: "no-cache"
|
|
2202
|
-
});
|
|
2203
|
-
if ((!requestInit || requestInit.method === "GET") && response.status === 404 && options?.optional) {
|
|
2204
|
-
return;
|
|
2205
|
-
}
|
|
2206
|
-
if (response.status >= 400 && response.status < 500) {
|
|
2207
|
-
const body = await response.json();
|
|
2208
|
-
throw new Error(body.error);
|
|
2209
|
-
}
|
|
2210
|
-
if (response.status >= 500 && retryCount < 6) {
|
|
2211
|
-
const delay = exponentialBackoff(retryCount + 1, 2, 50, 1150, 50);
|
|
2212
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
2213
|
-
return zodfetch(schema, url, requestInit, options, retryCount + 1);
|
|
2214
|
-
}
|
|
2215
|
-
if (response.status !== 200) {
|
|
2216
|
-
throw new Error(options?.errorMessage ?? `Failed to fetch ${url}, got status code ${response.status}`);
|
|
2217
|
-
}
|
|
2218
|
-
const jsonBody = await response.json();
|
|
2219
|
-
return schema.parse(jsonBody);
|
|
2220
|
-
}
|
|
2221
|
-
__name(zodfetch, "zodfetch");
|
|
2222
|
-
function exponentialBackoff(retryCount, exponential, minDelay, maxDelay, jitter) {
|
|
2223
|
-
const delay = Math.min(Math.pow(exponential, retryCount) * minDelay, maxDelay);
|
|
2224
|
-
const jitterValue = Math.random() * jitter;
|
|
2225
|
-
return delay + jitterValue;
|
|
2226
|
-
}
|
|
2227
|
-
__name(exponentialBackoff, "exponentialBackoff");
|
|
2228
|
-
|
|
2229
|
-
// src/httpEndpoint.ts
|
|
2230
|
-
var import_core4 = require("@trigger.dev/core");
|
|
2231
|
-
|
|
2232
|
-
// src/utils/formatSchemaErrors.ts
|
|
2233
|
-
function formatSchemaErrors(errors) {
|
|
2234
|
-
return errors.map((error) => {
|
|
2235
|
-
const { path, message } = error;
|
|
2236
|
-
return {
|
|
2237
|
-
path: path.map(String),
|
|
2238
|
-
message
|
|
2239
|
-
};
|
|
2240
|
-
});
|
|
2241
|
-
}
|
|
2242
|
-
__name(formatSchemaErrors, "formatSchemaErrors");
|
|
2243
|
-
|
|
2244
|
-
// src/httpEndpoint.ts
|
|
2245
|
-
var HttpEndpoint = class {
|
|
2246
|
-
constructor(options) {
|
|
2247
|
-
this.options = options;
|
|
2248
|
-
}
|
|
2249
|
-
get id() {
|
|
2250
|
-
return this.options.id;
|
|
2251
|
-
}
|
|
2252
|
-
onRequest(options) {
|
|
2253
|
-
return new HttpTrigger({
|
|
2254
|
-
endpointId: this.id,
|
|
2255
|
-
event: this.options.event,
|
|
2256
|
-
filter: options?.filter,
|
|
2257
|
-
verify: this.options.verify
|
|
2258
|
-
});
|
|
2259
|
-
}
|
|
2260
|
-
async handleRequest(request) {
|
|
2261
|
-
if (!this.options.respondWith)
|
|
2262
|
-
return;
|
|
2263
|
-
return this.options.respondWith.handler(request, () => {
|
|
2264
|
-
const clonedRequest = request.clone();
|
|
2265
|
-
return this.options.verify(clonedRequest);
|
|
2266
|
-
});
|
|
2267
|
-
}
|
|
2268
|
-
toJSON() {
|
|
2269
|
-
return {
|
|
2270
|
-
id: this.id,
|
|
2271
|
-
icon: this.options.event.icon,
|
|
2272
|
-
version: "1",
|
|
2273
|
-
enabled: this.options.enabled ?? true,
|
|
2274
|
-
event: this.options.event,
|
|
2275
|
-
immediateResponseFilter: this.options.respondWith?.filter,
|
|
2276
|
-
skipTriggeringRuns: this.options.respondWith?.skipTriggeringRuns,
|
|
2277
|
-
source: this.options.event.source
|
|
2278
|
-
};
|
|
2279
|
-
}
|
|
2280
|
-
};
|
|
2281
|
-
__name(HttpEndpoint, "HttpEndpoint");
|
|
2282
|
-
var HttpTrigger = /* @__PURE__ */ __name(class HttpTrigger2 {
|
|
2283
|
-
constructor(options) {
|
|
2284
|
-
this.options = options;
|
|
2285
|
-
}
|
|
2286
|
-
toJSON() {
|
|
2287
|
-
return {
|
|
2288
|
-
type: "static",
|
|
2289
|
-
title: this.options.endpointId,
|
|
2290
|
-
properties: this.options.event.properties,
|
|
2291
|
-
rule: {
|
|
2292
|
-
event: `httpendpoint.${this.options.endpointId}`,
|
|
2293
|
-
payload: this.options.filter ?? {},
|
|
2294
|
-
source: this.options.event.source
|
|
2295
|
-
},
|
|
2296
|
-
link: `http-endpoints/${this.options.endpointId}`,
|
|
2297
|
-
help: {
|
|
2298
|
-
noRuns: {
|
|
2299
|
-
text: "To start triggering runs click here to setup your HTTP Endpoint with the external API service you want to receive webhooks from.",
|
|
2300
|
-
link: `http-endpoints/${this.options.endpointId}`
|
|
2301
|
-
}
|
|
2302
|
-
}
|
|
2303
|
-
};
|
|
2304
|
-
}
|
|
2305
|
-
get event() {
|
|
2306
|
-
return this.options.event;
|
|
2307
|
-
}
|
|
2308
|
-
attachToJob(triggerClient, job) {
|
|
2309
|
-
}
|
|
2310
|
-
get preprocessRuns() {
|
|
2311
|
-
return false;
|
|
2312
|
-
}
|
|
2313
|
-
async verifyPayload(payload) {
|
|
2314
|
-
const clonedRequest = payload.clone();
|
|
2315
|
-
return this.options.verify(clonedRequest);
|
|
2316
|
-
}
|
|
2317
|
-
}, "HttpTrigger");
|
|
2318
|
-
function httpEndpoint(options) {
|
|
2319
|
-
const id = slugifyId(options.id);
|
|
2320
|
-
return new HttpEndpoint({
|
|
2321
|
-
id,
|
|
2322
|
-
enabled: options.enabled,
|
|
2323
|
-
respondWith: options.respondWith,
|
|
2324
|
-
verify: options.verify,
|
|
2325
|
-
event: {
|
|
2326
|
-
name: id,
|
|
2327
|
-
title: options.title ?? "HTTP Trigger",
|
|
2328
|
-
source: options.source,
|
|
2329
|
-
icon: options.icon ?? "webhook",
|
|
2330
|
-
properties: options.properties,
|
|
2331
|
-
examples: options.examples ? options.examples : [
|
|
2332
|
-
{
|
|
2333
|
-
id: "basic-request",
|
|
2334
|
-
name: "Basic Request",
|
|
2335
|
-
icon: "http-post",
|
|
2336
|
-
payload: {
|
|
2337
|
-
url: "https://cloud.trigger.dev",
|
|
2338
|
-
method: "POST",
|
|
2339
|
-
headers: {
|
|
2340
|
-
"Content-Type": "application/json"
|
|
2341
|
-
},
|
|
2342
|
-
rawBody: JSON.stringify({
|
|
2343
|
-
foo: "bar"
|
|
2344
|
-
})
|
|
2345
|
-
}
|
|
2346
|
-
}
|
|
2347
|
-
],
|
|
2348
|
-
parsePayload: (rawPayload) => {
|
|
2349
|
-
const result = import_core4.RequestWithRawBodySchema.safeParse(rawPayload);
|
|
2350
|
-
if (!result.success) {
|
|
2351
|
-
throw new ParsedPayloadSchemaError(formatSchemaErrors(result.error.issues));
|
|
2352
|
-
}
|
|
2353
|
-
return new Request(new URL(result.data.url), {
|
|
2354
|
-
method: result.data.method,
|
|
2355
|
-
headers: result.data.headers,
|
|
2356
|
-
body: result.data.rawBody
|
|
2357
|
-
});
|
|
2358
|
-
}
|
|
2359
|
-
}
|
|
2360
|
-
});
|
|
2361
|
-
}
|
|
2362
|
-
__name(httpEndpoint, "httpEndpoint");
|
|
2363
|
-
|
|
2364
|
-
// src/ioWithIntegrations.ts
|
|
2365
|
-
function createIOWithIntegrations(io, auths, integrations) {
|
|
2366
|
-
if (!integrations) {
|
|
2367
|
-
return io;
|
|
2368
|
-
}
|
|
2369
|
-
const connections = Object.entries(integrations).reduce((acc, [connectionKey, integration]) => {
|
|
2370
|
-
let auth = auths?.[connectionKey];
|
|
2371
|
-
acc[connectionKey] = {
|
|
2372
|
-
integration,
|
|
2373
|
-
auth
|
|
2374
|
-
};
|
|
2375
|
-
return acc;
|
|
2376
|
-
}, {});
|
|
2377
|
-
return new Proxy(io, {
|
|
2378
|
-
get(target, prop, receiver) {
|
|
2379
|
-
if (prop === "__io") {
|
|
2380
|
-
return io;
|
|
2381
|
-
}
|
|
2382
|
-
if (typeof prop === "string" && prop in connections) {
|
|
2383
|
-
const { integration, auth } = connections[prop];
|
|
2384
|
-
return integration.cloneForRun(io, prop, auth);
|
|
2385
|
-
}
|
|
2386
|
-
const value = Reflect.get(target, prop, receiver);
|
|
2387
|
-
return typeof value == "function" ? value.bind(target) : value;
|
|
2388
|
-
}
|
|
2389
|
-
});
|
|
2390
|
-
}
|
|
2391
|
-
__name(createIOWithIntegrations, "createIOWithIntegrations");
|
|
2392
|
-
|
|
2393
|
-
// src/triggers/dynamic.ts
|
|
2394
|
-
var import_core5 = require("@trigger.dev/core");
|
|
2395
|
-
var _client, _options2;
|
|
2396
|
-
var DynamicTrigger = class {
|
|
2397
|
-
constructor(client, options) {
|
|
2398
|
-
__privateAdd(this, _client, void 0);
|
|
2399
|
-
__privateAdd(this, _options2, void 0);
|
|
2400
|
-
__privateSet(this, _client, client);
|
|
2401
|
-
__privateSet(this, _options2, options);
|
|
2402
|
-
this.source = options.source;
|
|
2403
|
-
client.attachDynamicTrigger(this);
|
|
2404
|
-
}
|
|
2405
|
-
toJSON() {
|
|
2406
|
-
return {
|
|
2407
|
-
type: "dynamic",
|
|
2408
|
-
id: __privateGet(this, _options2).id
|
|
2409
|
-
};
|
|
2410
|
-
}
|
|
2411
|
-
get id() {
|
|
2412
|
-
return __privateGet(this, _options2).id;
|
|
2413
|
-
}
|
|
2414
|
-
get event() {
|
|
2415
|
-
return __privateGet(this, _options2).event;
|
|
2416
|
-
}
|
|
2417
|
-
registeredTriggerForParams(params, options = {}) {
|
|
2418
|
-
const key = slugifyId(this.source.key(params));
|
|
2419
|
-
return {
|
|
2420
|
-
rule: {
|
|
2421
|
-
event: this.event.name,
|
|
2422
|
-
source: this.event.source,
|
|
2423
|
-
payload: (0, import_core5.deepMergeFilters)(this.source.filter(params), this.event.filter ?? {}, options.filter ?? {})
|
|
2424
|
-
},
|
|
2425
|
-
source: {
|
|
2426
|
-
version: "2",
|
|
2427
|
-
key,
|
|
2428
|
-
channel: this.source.channel,
|
|
2429
|
-
params,
|
|
2430
|
-
options: {
|
|
2431
|
-
event: typeof this.event.name === "string" ? [
|
|
2432
|
-
this.event.name
|
|
2433
|
-
] : this.event.name
|
|
2434
|
-
},
|
|
2435
|
-
integration: {
|
|
2436
|
-
id: this.source.integration.id,
|
|
2437
|
-
metadata: this.source.integration.metadata,
|
|
2438
|
-
authSource: this.source.integration.authSource
|
|
2439
|
-
}
|
|
2440
|
-
},
|
|
2441
|
-
accountId: options.accountId
|
|
2442
|
-
};
|
|
2443
|
-
}
|
|
2444
|
-
async register(key, params, options = {}) {
|
|
2445
|
-
const runStore = runLocalStorage.getStore();
|
|
2446
|
-
if (!runStore) {
|
|
2447
|
-
return __privateGet(this, _client).registerTrigger(this.id, key, this.registeredTriggerForParams(params, options));
|
|
2448
|
-
}
|
|
2449
|
-
const { io } = runStore;
|
|
2450
|
-
return await io.runTask([
|
|
2451
|
-
key,
|
|
2452
|
-
"register"
|
|
2453
|
-
], async (task) => {
|
|
2454
|
-
return __privateGet(this, _client).registerTrigger(this.id, key, this.registeredTriggerForParams(params, options), task.idempotencyKey);
|
|
2455
|
-
}, {
|
|
2456
|
-
name: "Register Dynamic Trigger",
|
|
2457
|
-
properties: [
|
|
2458
|
-
{
|
|
2459
|
-
label: "Dynamic Trigger ID",
|
|
2460
|
-
text: this.id
|
|
2461
|
-
},
|
|
2462
|
-
{
|
|
2463
|
-
label: "ID",
|
|
2464
|
-
text: key
|
|
2465
|
-
}
|
|
2466
|
-
],
|
|
2467
|
-
params
|
|
2468
|
-
});
|
|
2469
|
-
}
|
|
2470
|
-
attachToJob(triggerClient, job) {
|
|
2471
|
-
triggerClient.attachJobToDynamicTrigger(job, this);
|
|
2472
|
-
}
|
|
2473
|
-
get preprocessRuns() {
|
|
2474
|
-
return true;
|
|
2475
|
-
}
|
|
2476
|
-
async verifyPayload(payload) {
|
|
2477
|
-
return {
|
|
2478
|
-
success: true
|
|
2479
|
-
};
|
|
2480
|
-
}
|
|
2481
|
-
};
|
|
2482
|
-
__name(DynamicTrigger, "DynamicTrigger");
|
|
2483
|
-
_client = new WeakMap();
|
|
2484
|
-
_options2 = new WeakMap();
|
|
2485
|
-
|
|
2486
|
-
// src/triggers/eventTrigger.ts
|
|
2487
|
-
var import_core6 = require("@trigger.dev/core");
|
|
2488
|
-
var _options3;
|
|
2489
|
-
var EventTrigger = class {
|
|
2490
|
-
constructor(options) {
|
|
2491
|
-
__privateAdd(this, _options3, void 0);
|
|
2492
|
-
__privateSet(this, _options3, options);
|
|
2493
|
-
}
|
|
2494
|
-
toJSON() {
|
|
2495
|
-
return {
|
|
2496
|
-
type: "static",
|
|
2497
|
-
title: __privateGet(this, _options3).name ?? __privateGet(this, _options3).event.title,
|
|
2498
|
-
rule: {
|
|
2499
|
-
event: __privateGet(this, _options3).name ?? __privateGet(this, _options3).event.name,
|
|
2500
|
-
source: __privateGet(this, _options3).source ?? "trigger.dev",
|
|
2501
|
-
payload: (0, import_core6.deepMergeFilters)(__privateGet(this, _options3).filter ?? {}, __privateGet(this, _options3).event.filter ?? {})
|
|
2502
|
-
}
|
|
2503
|
-
};
|
|
2504
|
-
}
|
|
2505
|
-
get event() {
|
|
2506
|
-
return __privateGet(this, _options3).event;
|
|
2507
|
-
}
|
|
2508
|
-
attachToJob(triggerClient, job) {
|
|
2509
|
-
}
|
|
2510
|
-
get preprocessRuns() {
|
|
2511
|
-
return false;
|
|
2512
|
-
}
|
|
2513
|
-
async verifyPayload(payload) {
|
|
2514
|
-
if (__privateGet(this, _options3).verify) {
|
|
2515
|
-
if (payload instanceof Request) {
|
|
2516
|
-
const clonedRequest = payload.clone();
|
|
2517
|
-
return __privateGet(this, _options3).verify(clonedRequest);
|
|
2518
|
-
}
|
|
2519
|
-
}
|
|
2520
|
-
return {
|
|
2521
|
-
success: true
|
|
2522
|
-
};
|
|
2523
|
-
}
|
|
2524
|
-
};
|
|
2525
|
-
__name(EventTrigger, "EventTrigger");
|
|
2526
|
-
_options3 = new WeakMap();
|
|
2527
|
-
function eventTrigger(options) {
|
|
2528
|
-
return new EventTrigger({
|
|
2529
|
-
name: options.name,
|
|
2530
|
-
filter: options.filter,
|
|
2531
|
-
event: {
|
|
2532
|
-
name: options.name,
|
|
2533
|
-
title: "Event",
|
|
2534
|
-
source: options.source ?? "trigger.dev",
|
|
2535
|
-
icon: "custom-event",
|
|
2536
|
-
examples: options.examples,
|
|
2537
|
-
parsePayload: (rawPayload) => {
|
|
2538
|
-
if (options.schema) {
|
|
2539
|
-
const results = options.schema.safeParse(rawPayload);
|
|
2540
|
-
if (!results.success) {
|
|
2541
|
-
throw new ParsedPayloadSchemaError(formatSchemaErrors(results.error.issues));
|
|
2542
|
-
}
|
|
2543
|
-
return results.data;
|
|
2544
|
-
}
|
|
2545
|
-
return rawPayload;
|
|
2546
|
-
}
|
|
2547
|
-
}
|
|
2548
|
-
});
|
|
2549
|
-
}
|
|
2550
|
-
__name(eventTrigger, "eventTrigger");
|
|
2551
|
-
|
|
2552
|
-
// src/triggers/scheduled.ts
|
|
2553
|
-
var import_core7 = require("@trigger.dev/core");
|
|
2554
|
-
var import_cronstrue = __toESM(require("cronstrue"));
|
|
2555
|
-
var examples = [
|
|
2556
|
-
{
|
|
2557
|
-
id: "now",
|
|
2558
|
-
name: "Now",
|
|
2559
|
-
icon: "clock",
|
|
2560
|
-
payload: {
|
|
2561
|
-
ts: import_core7.currentDate.marker,
|
|
2562
|
-
lastTimestamp: import_core7.currentDate.marker
|
|
2563
|
-
}
|
|
2564
|
-
}
|
|
2565
|
-
];
|
|
2566
|
-
var IntervalTrigger = class {
|
|
2567
|
-
constructor(options) {
|
|
2568
|
-
this.options = options;
|
|
2569
|
-
}
|
|
2570
|
-
get event() {
|
|
2571
|
-
return {
|
|
2572
|
-
name: "trigger.scheduled",
|
|
2573
|
-
title: "Schedule",
|
|
2574
|
-
source: "trigger.dev",
|
|
2575
|
-
icon: "schedule-interval",
|
|
2576
|
-
examples,
|
|
2577
|
-
parsePayload: import_core7.ScheduledPayloadSchema.parse,
|
|
2578
|
-
properties: [
|
|
2579
|
-
{
|
|
2580
|
-
label: "Interval",
|
|
2581
|
-
text: `${this.options.seconds}s`
|
|
2582
|
-
}
|
|
2583
|
-
]
|
|
2584
|
-
};
|
|
2585
|
-
}
|
|
2586
|
-
attachToJob(triggerClient, job) {
|
|
2587
|
-
}
|
|
2588
|
-
get preprocessRuns() {
|
|
2589
|
-
return false;
|
|
2590
|
-
}
|
|
2591
|
-
async verifyPayload(payload) {
|
|
2592
|
-
return {
|
|
2593
|
-
success: true
|
|
2594
|
-
};
|
|
2595
|
-
}
|
|
2596
|
-
toJSON() {
|
|
2597
|
-
return {
|
|
2598
|
-
type: "scheduled",
|
|
2599
|
-
schedule: {
|
|
2600
|
-
type: "interval",
|
|
2601
|
-
options: {
|
|
2602
|
-
seconds: this.options.seconds
|
|
2603
|
-
}
|
|
2604
|
-
}
|
|
2605
|
-
};
|
|
2606
|
-
}
|
|
2607
|
-
};
|
|
2608
|
-
__name(IntervalTrigger, "IntervalTrigger");
|
|
2609
|
-
function intervalTrigger(options) {
|
|
2610
|
-
return new IntervalTrigger(options);
|
|
2611
|
-
}
|
|
2612
|
-
__name(intervalTrigger, "intervalTrigger");
|
|
2613
|
-
var CronTrigger = class {
|
|
2614
|
-
constructor(options) {
|
|
2615
|
-
this.options = options;
|
|
2616
|
-
}
|
|
2617
|
-
get event() {
|
|
2618
|
-
const humanReadable = import_cronstrue.default.toString(this.options.cron, {
|
|
2619
|
-
throwExceptionOnParseError: false
|
|
2620
|
-
});
|
|
2621
|
-
return {
|
|
2622
|
-
name: "trigger.scheduled",
|
|
2623
|
-
title: "Cron Schedule",
|
|
2624
|
-
source: "trigger.dev",
|
|
2625
|
-
icon: "schedule-cron",
|
|
2626
|
-
examples,
|
|
2627
|
-
parsePayload: import_core7.ScheduledPayloadSchema.parse,
|
|
2628
|
-
properties: [
|
|
2629
|
-
{
|
|
2630
|
-
label: "cron",
|
|
2631
|
-
text: this.options.cron
|
|
2632
|
-
},
|
|
2633
|
-
{
|
|
2634
|
-
label: "Schedule",
|
|
2635
|
-
text: humanReadable
|
|
2636
|
-
}
|
|
2637
|
-
]
|
|
2638
|
-
};
|
|
2639
|
-
}
|
|
2640
|
-
attachToJob(triggerClient, job) {
|
|
2641
|
-
}
|
|
2642
|
-
get preprocessRuns() {
|
|
2643
|
-
return false;
|
|
2644
|
-
}
|
|
2645
|
-
async verifyPayload(payload) {
|
|
2646
|
-
return {
|
|
2647
|
-
success: true
|
|
2648
|
-
};
|
|
2649
|
-
}
|
|
2650
|
-
toJSON() {
|
|
2651
|
-
return {
|
|
2652
|
-
type: "scheduled",
|
|
2653
|
-
schedule: {
|
|
2654
|
-
type: "cron",
|
|
2655
|
-
options: {
|
|
2656
|
-
cron: this.options.cron
|
|
2657
|
-
}
|
|
2658
|
-
}
|
|
2659
|
-
};
|
|
2660
|
-
}
|
|
2661
|
-
};
|
|
2662
|
-
__name(CronTrigger, "CronTrigger");
|
|
2663
|
-
function cronTrigger(options) {
|
|
2664
|
-
return new CronTrigger(options);
|
|
2665
|
-
}
|
|
2666
|
-
__name(cronTrigger, "cronTrigger");
|
|
2667
|
-
var DynamicSchedule = class {
|
|
2668
|
-
constructor(client, options) {
|
|
2669
|
-
this.client = client;
|
|
2670
|
-
this.options = options;
|
|
2671
|
-
client.attachDynamicSchedule(this.options.id);
|
|
2672
|
-
}
|
|
2673
|
-
get id() {
|
|
2674
|
-
return this.options.id;
|
|
2675
|
-
}
|
|
2676
|
-
get event() {
|
|
2677
|
-
return {
|
|
2678
|
-
name: "trigger.scheduled",
|
|
2679
|
-
title: "Dynamic Schedule",
|
|
2680
|
-
source: "trigger.dev",
|
|
2681
|
-
icon: "schedule-dynamic",
|
|
2682
|
-
examples,
|
|
2683
|
-
parsePayload: import_core7.ScheduledPayloadSchema.parse
|
|
2684
|
-
};
|
|
2685
|
-
}
|
|
2686
|
-
async register(key, metadata) {
|
|
2687
|
-
const runStore = runLocalStorage.getStore();
|
|
2688
|
-
if (!runStore) {
|
|
2689
|
-
return this.client.registerSchedule(this.id, key, metadata);
|
|
2690
|
-
}
|
|
2691
|
-
const { io } = runStore;
|
|
2692
|
-
return await io.runTask([
|
|
2693
|
-
key,
|
|
2694
|
-
"register"
|
|
2695
|
-
], async (task) => {
|
|
2696
|
-
return this.client.registerSchedule(this.id, key, metadata);
|
|
2697
|
-
}, {
|
|
2698
|
-
name: "Register Schedule",
|
|
2699
|
-
icon: metadata.type === "cron" ? "schedule-cron" : "schedule-interval",
|
|
2700
|
-
properties: [
|
|
2701
|
-
{
|
|
2702
|
-
label: "Dynamic Schedule",
|
|
2703
|
-
text: this.id
|
|
2704
|
-
},
|
|
2705
|
-
{
|
|
2706
|
-
label: "Schedule ID",
|
|
2707
|
-
text: key
|
|
2708
|
-
}
|
|
2709
|
-
],
|
|
2710
|
-
params: metadata
|
|
2711
|
-
});
|
|
2712
|
-
}
|
|
2713
|
-
async unregister(key) {
|
|
2714
|
-
const runStore = runLocalStorage.getStore();
|
|
2715
|
-
if (!runStore) {
|
|
2716
|
-
return this.client.unregisterSchedule(this.id, key);
|
|
2717
|
-
}
|
|
2718
|
-
const { io } = runStore;
|
|
2719
|
-
return await io.runTask([
|
|
2720
|
-
key,
|
|
2721
|
-
"unregister"
|
|
2722
|
-
], async (task) => {
|
|
2723
|
-
return this.client.unregisterSchedule(this.id, key);
|
|
2724
|
-
}, {
|
|
2725
|
-
name: "Unregister Schedule",
|
|
2726
|
-
icon: "schedule",
|
|
2727
|
-
properties: [
|
|
2728
|
-
{
|
|
2729
|
-
label: "Dynamic Schedule",
|
|
2730
|
-
text: this.id
|
|
2731
|
-
},
|
|
2732
|
-
{
|
|
2733
|
-
label: "Schedule ID",
|
|
2734
|
-
text: key
|
|
2735
|
-
}
|
|
2736
|
-
]
|
|
2737
|
-
});
|
|
2738
|
-
}
|
|
2739
|
-
attachToJob(triggerClient, job) {
|
|
2740
|
-
triggerClient.attachDynamicScheduleToJob(this.options.id, job);
|
|
2741
|
-
}
|
|
2742
|
-
get preprocessRuns() {
|
|
2743
|
-
return false;
|
|
2744
|
-
}
|
|
2745
|
-
async verifyPayload(payload) {
|
|
2746
|
-
return {
|
|
2747
|
-
success: true
|
|
2748
|
-
};
|
|
2749
|
-
}
|
|
2750
|
-
toJSON() {
|
|
2751
|
-
return {
|
|
2752
|
-
type: "dynamic",
|
|
2753
|
-
id: this.options.id
|
|
2754
|
-
};
|
|
2755
|
-
}
|
|
2756
|
-
};
|
|
2757
|
-
__name(DynamicSchedule, "DynamicSchedule");
|
|
2758
|
-
|
|
2759
|
-
// src/triggerClient.ts
|
|
2760
|
-
var import_node_events = __toESM(require("events"));
|
|
2761
|
-
|
|
2762
|
-
// package.json
|
|
2763
|
-
var version = "0.0.0-canary-20231128163224";
|
|
2764
|
-
|
|
2765
|
-
// src/concurrencyLimit.ts
|
|
2766
|
-
var ConcurrencyLimit = class {
|
|
2767
|
-
constructor(options) {
|
|
2768
|
-
this.options = options;
|
|
2769
|
-
}
|
|
2770
|
-
get id() {
|
|
2771
|
-
return this.options.id;
|
|
2772
|
-
}
|
|
2773
|
-
get limit() {
|
|
2774
|
-
return this.options.limit;
|
|
2775
|
-
}
|
|
2776
|
-
};
|
|
2777
|
-
__name(ConcurrencyLimit, "ConcurrencyLimit");
|
|
2778
|
-
|
|
2779
|
-
// src/triggerClient.ts
|
|
2780
|
-
var registerWebhookEvent = /* @__PURE__ */ __name((key) => ({
|
|
2781
|
-
name: `${import_core8.REGISTER_WEBHOOK}.${key}`,
|
|
2782
|
-
title: "Register Webhook",
|
|
2783
|
-
source: "internal",
|
|
2784
|
-
icon: "webhook",
|
|
2785
|
-
parsePayload: import_core8.RegisterWebhookPayloadSchema.parse
|
|
2786
|
-
}), "registerWebhookEvent");
|
|
2787
|
-
var registerSourceEvent = {
|
|
2788
|
-
name: import_core8.REGISTER_SOURCE_EVENT_V2,
|
|
2789
|
-
title: "Register Source",
|
|
2790
|
-
source: "internal",
|
|
2791
|
-
icon: "register-source",
|
|
2792
|
-
parsePayload: import_core8.RegisterSourceEventSchemaV2.parse
|
|
2793
|
-
};
|
|
2794
|
-
var _options4, _registeredJobs, _registeredSources, _registeredWebhooks, _registeredHttpSourceHandlers, _registeredWebhookSourceHandlers, _registeredDynamicTriggers, _jobMetadataByDynamicTriggers, _registeredSchedules, _registeredHttpEndpoints, _authResolvers, _envStore, _eventEmitter, _client2, _internalLogger, _preprocessRun, preprocessRun_fn, _executeJob, executeJob_fn, _convertErrorToExecutionResponse, convertErrorToExecutionResponse_fn, _createRunContext, createRunContext_fn, _createPreprocessRunContext, createPreprocessRunContext_fn, _handleHttpSourceRequest, handleHttpSourceRequest_fn, _handleHttpEndpointRequestForResponse, handleHttpEndpointRequestForResponse_fn, _handleWebhookRequest, handleWebhookRequest_fn, _resolveConnections, resolveConnections_fn, _resolveConnection, resolveConnection_fn, _buildJobsIndex, buildJobsIndex_fn, _buildJobIndex, buildJobIndex_fn, _buildJobIntegrations, buildJobIntegrations_fn, _buildJobIntegration, buildJobIntegration_fn, _logIOStats, logIOStats_fn, _standardResponseHeaders, standardResponseHeaders_fn, _serializeRunMetadata, serializeRunMetadata_fn, _deliverSuccessfulRunNotification, deliverSuccessfulRunNotification_fn, _deliverFailedRunNotification, deliverFailedRunNotification_fn;
|
|
2795
|
-
var TriggerClient = class {
|
|
2796
|
-
constructor(options) {
|
|
2797
|
-
__privateAdd(this, _preprocessRun);
|
|
2798
|
-
__privateAdd(this, _executeJob);
|
|
2799
|
-
__privateAdd(this, _convertErrorToExecutionResponse);
|
|
2800
|
-
__privateAdd(this, _createRunContext);
|
|
2801
|
-
__privateAdd(this, _createPreprocessRunContext);
|
|
2802
|
-
__privateAdd(this, _handleHttpSourceRequest);
|
|
2803
|
-
__privateAdd(this, _handleHttpEndpointRequestForResponse);
|
|
2804
|
-
__privateAdd(this, _handleWebhookRequest);
|
|
2805
|
-
__privateAdd(this, _resolveConnections);
|
|
2806
|
-
__privateAdd(this, _resolveConnection);
|
|
2807
|
-
__privateAdd(this, _buildJobsIndex);
|
|
2808
|
-
__privateAdd(this, _buildJobIndex);
|
|
2809
|
-
__privateAdd(this, _buildJobIntegrations);
|
|
2810
|
-
__privateAdd(this, _buildJobIntegration);
|
|
2811
|
-
__privateAdd(this, _logIOStats);
|
|
2812
|
-
__privateAdd(this, _standardResponseHeaders);
|
|
2813
|
-
__privateAdd(this, _serializeRunMetadata);
|
|
2814
|
-
__privateAdd(this, _deliverSuccessfulRunNotification);
|
|
2815
|
-
__privateAdd(this, _deliverFailedRunNotification);
|
|
2816
|
-
__privateAdd(this, _options4, void 0);
|
|
2817
|
-
__privateAdd(this, _registeredJobs, {});
|
|
2818
|
-
__privateAdd(this, _registeredSources, {});
|
|
2819
|
-
__privateAdd(this, _registeredWebhooks, {});
|
|
2820
|
-
__privateAdd(this, _registeredHttpSourceHandlers, {});
|
|
2821
|
-
__privateAdd(this, _registeredWebhookSourceHandlers, {});
|
|
2822
|
-
__privateAdd(this, _registeredDynamicTriggers, {});
|
|
2823
|
-
__privateAdd(this, _jobMetadataByDynamicTriggers, {});
|
|
2824
|
-
__privateAdd(this, _registeredSchedules, {});
|
|
2825
|
-
__privateAdd(this, _registeredHttpEndpoints, {});
|
|
2826
|
-
__privateAdd(this, _authResolvers, {});
|
|
2827
|
-
__privateAdd(this, _envStore, void 0);
|
|
2828
|
-
__privateAdd(this, _eventEmitter, new import_node_events.default());
|
|
2829
|
-
__privateAdd(this, _client2, void 0);
|
|
2830
|
-
__privateAdd(this, _internalLogger, void 0);
|
|
2831
|
-
__publicField(this, "on", __privateGet(this, _eventEmitter).on.bind(__privateGet(this, _eventEmitter)));
|
|
2832
|
-
this.id = options.id;
|
|
2833
|
-
__privateSet(this, _options4, options);
|
|
2834
|
-
__privateSet(this, _client2, new ApiClient(__privateGet(this, _options4)));
|
|
2835
|
-
__privateSet(this, _internalLogger, new import_core8.Logger("trigger.dev", __privateGet(this, _options4).verbose ? "debug" : "log", [
|
|
2836
|
-
"output",
|
|
2837
|
-
"noopTasksSet"
|
|
2838
|
-
]));
|
|
2839
|
-
__privateSet(this, _envStore, new KeyValueStore(__privateGet(this, _client2)));
|
|
2840
|
-
}
|
|
2841
|
-
async handleRequest(request, timeOrigin = performance.now()) {
|
|
2842
|
-
__privateGet(this, _internalLogger).debug("handling request", {
|
|
2843
|
-
url: request.url,
|
|
2844
|
-
headers: Object.fromEntries(request.headers.entries()),
|
|
2845
|
-
method: request.method
|
|
2846
|
-
});
|
|
2847
|
-
const apiKey = request.headers.get("x-trigger-api-key");
|
|
2848
|
-
const triggerVersion = request.headers.get("x-trigger-version");
|
|
2849
|
-
const authorization = this.authorized(apiKey);
|
|
2850
|
-
switch (authorization) {
|
|
2851
|
-
case "authorized": {
|
|
2852
|
-
break;
|
|
2853
|
-
}
|
|
2854
|
-
case "missing-client": {
|
|
2855
|
-
return {
|
|
2856
|
-
status: 401,
|
|
2857
|
-
body: {
|
|
2858
|
-
message: "Unauthorized: client missing apiKey"
|
|
2859
|
-
},
|
|
2860
|
-
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
2861
|
-
};
|
|
2862
|
-
}
|
|
2863
|
-
case "missing-header": {
|
|
2864
|
-
return {
|
|
2865
|
-
status: 401,
|
|
2866
|
-
body: {
|
|
2867
|
-
message: "Unauthorized: missing x-trigger-api-key header"
|
|
2868
|
-
},
|
|
2869
|
-
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
2870
|
-
};
|
|
2871
|
-
}
|
|
2872
|
-
case "unauthorized": {
|
|
2873
|
-
return {
|
|
2874
|
-
status: 401,
|
|
2875
|
-
body: {
|
|
2876
|
-
message: `Forbidden: client apiKey mismatch: Make sure you are using the correct API Key for your environment`
|
|
2877
|
-
},
|
|
2878
|
-
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
2879
|
-
};
|
|
2880
|
-
}
|
|
2881
|
-
}
|
|
2882
|
-
if (request.method !== "POST") {
|
|
2883
|
-
return {
|
|
2884
|
-
status: 405,
|
|
2885
|
-
body: {
|
|
2886
|
-
message: "Method not allowed (only POST is allowed)"
|
|
2887
|
-
},
|
|
2888
|
-
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
2889
|
-
};
|
|
2890
|
-
}
|
|
2891
|
-
const action = request.headers.get("x-trigger-action");
|
|
2892
|
-
if (!action) {
|
|
2893
|
-
return {
|
|
2894
|
-
status: 400,
|
|
2895
|
-
body: {
|
|
2896
|
-
message: "Missing x-trigger-action header"
|
|
2897
|
-
},
|
|
2898
|
-
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
2899
|
-
};
|
|
2900
|
-
}
|
|
2901
|
-
switch (action) {
|
|
2902
|
-
case "PING": {
|
|
2903
|
-
const endpointId = request.headers.get("x-trigger-endpoint-id");
|
|
2904
|
-
if (!endpointId) {
|
|
2905
|
-
return {
|
|
2906
|
-
status: 200,
|
|
2907
|
-
body: {
|
|
2908
|
-
ok: false,
|
|
2909
|
-
error: "Missing endpoint ID"
|
|
2910
|
-
},
|
|
2911
|
-
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
2912
|
-
};
|
|
2913
|
-
}
|
|
2914
|
-
if (this.id !== endpointId) {
|
|
2915
|
-
return {
|
|
2916
|
-
status: 200,
|
|
2917
|
-
body: {
|
|
2918
|
-
ok: false,
|
|
2919
|
-
error: `Endpoint ID mismatch error. Expected ${this.id}, got ${endpointId}`
|
|
2920
|
-
},
|
|
2921
|
-
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
2922
|
-
};
|
|
2923
|
-
}
|
|
2924
|
-
return {
|
|
2925
|
-
status: 200,
|
|
2926
|
-
body: {
|
|
2927
|
-
ok: true
|
|
2928
|
-
},
|
|
2929
|
-
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
2930
|
-
};
|
|
2931
|
-
}
|
|
2932
|
-
case "INDEX_ENDPOINT": {
|
|
2933
|
-
const body = {
|
|
2934
|
-
jobs: __privateMethod(this, _buildJobsIndex, buildJobsIndex_fn).call(this),
|
|
2935
|
-
sources: Object.values(__privateGet(this, _registeredSources)),
|
|
2936
|
-
webhooks: Object.values(__privateGet(this, _registeredWebhooks)),
|
|
2937
|
-
dynamicTriggers: Object.values(__privateGet(this, _registeredDynamicTriggers)).map((trigger) => ({
|
|
2938
|
-
id: trigger.id,
|
|
2939
|
-
jobs: __privateGet(this, _jobMetadataByDynamicTriggers)[trigger.id] ?? [],
|
|
2940
|
-
registerSourceJob: {
|
|
2941
|
-
id: dynamicTriggerRegisterSourceJobId(trigger.id),
|
|
2942
|
-
version: trigger.source.version
|
|
2943
|
-
}
|
|
2944
|
-
})),
|
|
2945
|
-
dynamicSchedules: Object.entries(__privateGet(this, _registeredSchedules)).map(([id, jobs]) => ({
|
|
2946
|
-
id,
|
|
2947
|
-
jobs
|
|
2948
|
-
})),
|
|
2949
|
-
httpEndpoints: Object.entries(__privateGet(this, _registeredHttpEndpoints)).map(([id, endpoint]) => endpoint.toJSON())
|
|
2950
|
-
};
|
|
2951
|
-
return {
|
|
2952
|
-
status: 200,
|
|
2953
|
-
body,
|
|
2954
|
-
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
2955
|
-
};
|
|
2956
|
-
}
|
|
2957
|
-
case "INITIALIZE_TRIGGER": {
|
|
2958
|
-
const json = await request.json();
|
|
2959
|
-
const body = import_core8.InitializeTriggerBodySchema.safeParse(json);
|
|
2960
|
-
if (!body.success) {
|
|
2961
|
-
return {
|
|
2962
|
-
status: 400,
|
|
2963
|
-
body: {
|
|
2964
|
-
message: "Invalid trigger body"
|
|
2965
|
-
}
|
|
2966
|
-
};
|
|
2967
|
-
}
|
|
2968
|
-
const dynamicTrigger = __privateGet(this, _registeredDynamicTriggers)[body.data.id];
|
|
2969
|
-
if (!dynamicTrigger) {
|
|
2970
|
-
return {
|
|
2971
|
-
status: 404,
|
|
2972
|
-
body: {
|
|
2973
|
-
message: "Dynamic trigger not found"
|
|
2974
|
-
}
|
|
2975
|
-
};
|
|
2976
|
-
}
|
|
2977
|
-
return {
|
|
2978
|
-
status: 200,
|
|
2979
|
-
body: dynamicTrigger.registeredTriggerForParams(body.data.params),
|
|
2980
|
-
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
2981
|
-
};
|
|
2982
|
-
}
|
|
2983
|
-
case "EXECUTE_JOB": {
|
|
2984
|
-
const json = await request.json();
|
|
2985
|
-
const execution = import_core8.RunJobBodySchema.safeParse(json);
|
|
2986
|
-
if (!execution.success) {
|
|
2987
|
-
return {
|
|
2988
|
-
status: 400,
|
|
2989
|
-
body: {
|
|
2990
|
-
message: "Invalid execution"
|
|
2991
|
-
}
|
|
2992
|
-
};
|
|
2993
|
-
}
|
|
2994
|
-
const job = __privateGet(this, _registeredJobs)[execution.data.job.id];
|
|
2995
|
-
if (!job) {
|
|
2996
|
-
return {
|
|
2997
|
-
status: 404,
|
|
2998
|
-
body: {
|
|
2999
|
-
message: "Job not found"
|
|
3000
|
-
}
|
|
3001
|
-
};
|
|
3002
|
-
}
|
|
3003
|
-
const results = await __privateMethod(this, _executeJob, executeJob_fn).call(this, execution.data, job, timeOrigin, triggerVersion);
|
|
3004
|
-
__privateGet(this, _internalLogger).debug("executed job", {
|
|
3005
|
-
results,
|
|
3006
|
-
job: job.id,
|
|
3007
|
-
version: job.version,
|
|
3008
|
-
triggerVersion
|
|
3009
|
-
});
|
|
3010
|
-
const standardHeaders = __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin);
|
|
3011
|
-
standardHeaders["x-trigger-run-metadata"] = __privateMethod(this, _serializeRunMetadata, serializeRunMetadata_fn).call(this, job);
|
|
3012
|
-
return {
|
|
3013
|
-
status: 200,
|
|
3014
|
-
body: results,
|
|
3015
|
-
headers: standardHeaders
|
|
3016
|
-
};
|
|
3017
|
-
}
|
|
3018
|
-
case "PREPROCESS_RUN": {
|
|
3019
|
-
const json = await request.json();
|
|
3020
|
-
const body = import_core8.PreprocessRunBodySchema.safeParse(json);
|
|
3021
|
-
if (!body.success) {
|
|
3022
|
-
return {
|
|
3023
|
-
status: 400,
|
|
3024
|
-
body: {
|
|
3025
|
-
message: "Invalid body"
|
|
3026
|
-
}
|
|
3027
|
-
};
|
|
3028
|
-
}
|
|
3029
|
-
const job = __privateGet(this, _registeredJobs)[body.data.job.id];
|
|
3030
|
-
if (!job) {
|
|
3031
|
-
return {
|
|
3032
|
-
status: 404,
|
|
3033
|
-
body: {
|
|
3034
|
-
message: "Job not found"
|
|
3035
|
-
}
|
|
3036
|
-
};
|
|
3037
|
-
}
|
|
3038
|
-
const results = await __privateMethod(this, _preprocessRun, preprocessRun_fn).call(this, body.data, job);
|
|
3039
|
-
return {
|
|
3040
|
-
status: 200,
|
|
3041
|
-
body: {
|
|
3042
|
-
abort: results.abort,
|
|
3043
|
-
properties: results.properties
|
|
3044
|
-
},
|
|
3045
|
-
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
3046
|
-
};
|
|
3047
|
-
}
|
|
3048
|
-
case "DELIVER_HTTP_SOURCE_REQUEST": {
|
|
3049
|
-
const headers = import_core8.HttpSourceRequestHeadersSchema.safeParse(Object.fromEntries(request.headers.entries()));
|
|
3050
|
-
if (!headers.success) {
|
|
3051
|
-
return {
|
|
3052
|
-
status: 400,
|
|
3053
|
-
body: {
|
|
3054
|
-
message: "Invalid headers"
|
|
3055
|
-
}
|
|
3056
|
-
};
|
|
3057
|
-
}
|
|
3058
|
-
const sourceRequestNeedsBody = headers.data["x-ts-http-method"] !== "GET";
|
|
3059
|
-
const sourceRequestInit = {
|
|
3060
|
-
method: headers.data["x-ts-http-method"],
|
|
3061
|
-
headers: headers.data["x-ts-http-headers"],
|
|
3062
|
-
body: sourceRequestNeedsBody ? request.body : void 0
|
|
3063
|
-
};
|
|
3064
|
-
if (sourceRequestNeedsBody) {
|
|
3065
|
-
try {
|
|
3066
|
-
sourceRequestInit.duplex = "half";
|
|
3067
|
-
} catch (error) {
|
|
3068
|
-
}
|
|
3069
|
-
}
|
|
3070
|
-
const sourceRequest = new Request(headers.data["x-ts-http-url"], sourceRequestInit);
|
|
3071
|
-
const key = headers.data["x-ts-key"];
|
|
3072
|
-
const dynamicId = headers.data["x-ts-dynamic-id"];
|
|
3073
|
-
const secret = headers.data["x-ts-secret"];
|
|
3074
|
-
const params = headers.data["x-ts-params"];
|
|
3075
|
-
const data = headers.data["x-ts-data"];
|
|
3076
|
-
const auth = headers.data["x-ts-auth"];
|
|
3077
|
-
const inputMetadata = headers.data["x-ts-metadata"];
|
|
3078
|
-
const source = {
|
|
3079
|
-
key,
|
|
3080
|
-
dynamicId,
|
|
3081
|
-
secret,
|
|
3082
|
-
params,
|
|
3083
|
-
data,
|
|
3084
|
-
auth,
|
|
3085
|
-
metadata: inputMetadata
|
|
3086
|
-
};
|
|
3087
|
-
const { response, events, metadata } = await __privateMethod(this, _handleHttpSourceRequest, handleHttpSourceRequest_fn).call(this, source, sourceRequest);
|
|
3088
|
-
return {
|
|
3089
|
-
status: 200,
|
|
3090
|
-
body: {
|
|
3091
|
-
events,
|
|
3092
|
-
response,
|
|
3093
|
-
metadata
|
|
3094
|
-
},
|
|
3095
|
-
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
3096
|
-
};
|
|
3097
|
-
}
|
|
3098
|
-
case "DELIVER_HTTP_ENDPOINT_REQUEST_FOR_RESPONSE": {
|
|
3099
|
-
const headers = import_core8.HttpEndpointRequestHeadersSchema.safeParse(Object.fromEntries(request.headers.entries()));
|
|
3100
|
-
if (!headers.success) {
|
|
3101
|
-
return {
|
|
3102
|
-
status: 400,
|
|
3103
|
-
body: {
|
|
3104
|
-
message: "Invalid headers"
|
|
3105
|
-
}
|
|
3106
|
-
};
|
|
3107
|
-
}
|
|
3108
|
-
const sourceRequestNeedsBody = headers.data["x-ts-http-method"] !== "GET";
|
|
3109
|
-
const sourceRequestInit = {
|
|
3110
|
-
method: headers.data["x-ts-http-method"],
|
|
3111
|
-
headers: headers.data["x-ts-http-headers"],
|
|
3112
|
-
body: sourceRequestNeedsBody ? request.body : void 0
|
|
3113
|
-
};
|
|
3114
|
-
if (sourceRequestNeedsBody) {
|
|
3115
|
-
try {
|
|
3116
|
-
sourceRequestInit.duplex = "half";
|
|
3117
|
-
} catch (error) {
|
|
3118
|
-
}
|
|
3119
|
-
}
|
|
3120
|
-
const sourceRequest = new Request(headers.data["x-ts-http-url"], sourceRequestInit);
|
|
3121
|
-
const key = headers.data["x-ts-key"];
|
|
3122
|
-
const { response } = await __privateMethod(this, _handleHttpEndpointRequestForResponse, handleHttpEndpointRequestForResponse_fn).call(this, {
|
|
3123
|
-
key
|
|
3124
|
-
}, sourceRequest);
|
|
3125
|
-
return {
|
|
3126
|
-
status: 200,
|
|
3127
|
-
body: response,
|
|
3128
|
-
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
3129
|
-
};
|
|
3130
|
-
}
|
|
3131
|
-
case "DELIVER_WEBHOOK_REQUEST": {
|
|
3132
|
-
const headers = import_core8.WebhookSourceRequestHeadersSchema.safeParse(Object.fromEntries(request.headers.entries()));
|
|
3133
|
-
if (!headers.success) {
|
|
3134
|
-
return {
|
|
3135
|
-
status: 400,
|
|
3136
|
-
body: {
|
|
3137
|
-
message: "Invalid headers"
|
|
3138
|
-
}
|
|
3139
|
-
};
|
|
3140
|
-
}
|
|
3141
|
-
const sourceRequestNeedsBody = headers.data["x-ts-http-method"] !== "GET";
|
|
3142
|
-
const sourceRequestInit = {
|
|
3143
|
-
method: headers.data["x-ts-http-method"],
|
|
3144
|
-
headers: headers.data["x-ts-http-headers"],
|
|
3145
|
-
body: sourceRequestNeedsBody ? request.body : void 0
|
|
3146
|
-
};
|
|
3147
|
-
if (sourceRequestNeedsBody) {
|
|
3148
|
-
try {
|
|
3149
|
-
sourceRequestInit.duplex = "half";
|
|
3150
|
-
} catch (error2) {
|
|
3151
|
-
}
|
|
3152
|
-
}
|
|
3153
|
-
const webhookRequest = new Request(headers.data["x-ts-http-url"], sourceRequestInit);
|
|
3154
|
-
const key = headers.data["x-ts-key"];
|
|
3155
|
-
const secret = headers.data["x-ts-secret"];
|
|
3156
|
-
const params = headers.data["x-ts-params"];
|
|
3157
|
-
const ctx = {
|
|
3158
|
-
key,
|
|
3159
|
-
secret,
|
|
3160
|
-
params
|
|
3161
|
-
};
|
|
3162
|
-
const { response, verified, error } = await __privateMethod(this, _handleWebhookRequest, handleWebhookRequest_fn).call(this, webhookRequest, ctx);
|
|
3163
|
-
return {
|
|
3164
|
-
status: 200,
|
|
3165
|
-
body: {
|
|
3166
|
-
response,
|
|
3167
|
-
verified,
|
|
3168
|
-
error
|
|
3169
|
-
},
|
|
3170
|
-
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
3171
|
-
};
|
|
3172
|
-
}
|
|
3173
|
-
case "VALIDATE": {
|
|
3174
|
-
return {
|
|
3175
|
-
status: 200,
|
|
3176
|
-
body: {
|
|
3177
|
-
ok: true,
|
|
3178
|
-
endpointId: this.id
|
|
3179
|
-
},
|
|
3180
|
-
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
3181
|
-
};
|
|
3182
|
-
}
|
|
3183
|
-
case "PROBE_EXECUTION_TIMEOUT": {
|
|
3184
|
-
const json = await request.json();
|
|
3185
|
-
const timeout = json?.timeout ?? 15 * 60 * 1e3;
|
|
3186
|
-
await new Promise((resolve) => setTimeout(resolve, timeout));
|
|
3187
|
-
return {
|
|
3188
|
-
status: 200,
|
|
3189
|
-
body: {
|
|
3190
|
-
ok: true
|
|
3191
|
-
},
|
|
3192
|
-
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
3193
|
-
};
|
|
3194
|
-
}
|
|
3195
|
-
case "RUN_NOTIFICATION": {
|
|
3196
|
-
const rawJson = await request.json();
|
|
3197
|
-
const runNotification = rawJson;
|
|
3198
|
-
if (runNotification.ok) {
|
|
3199
|
-
await __privateMethod(this, _deliverSuccessfulRunNotification, deliverSuccessfulRunNotification_fn).call(this, runNotification);
|
|
3200
|
-
} else {
|
|
3201
|
-
await __privateMethod(this, _deliverFailedRunNotification, deliverFailedRunNotification_fn).call(this, runNotification);
|
|
3202
|
-
}
|
|
3203
|
-
return {
|
|
3204
|
-
status: 200,
|
|
3205
|
-
body: {
|
|
3206
|
-
ok: true
|
|
3207
|
-
},
|
|
3208
|
-
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
3209
|
-
};
|
|
3210
|
-
}
|
|
3211
|
-
}
|
|
3212
|
-
return {
|
|
3213
|
-
status: 405,
|
|
3214
|
-
body: {
|
|
3215
|
-
message: "Method not allowed"
|
|
3216
|
-
},
|
|
3217
|
-
headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
|
|
3218
|
-
};
|
|
3219
|
-
}
|
|
3220
|
-
defineJob(options) {
|
|
3221
|
-
const existingRegisteredJob = __privateGet(this, _registeredJobs)[options.id];
|
|
3222
|
-
if (existingRegisteredJob) {
|
|
3223
|
-
console.warn((0, import_colorette.yellow)(`[@trigger.dev/sdk] Warning: The Job "${existingRegisteredJob.id}" you're attempting to define has already been defined. Please assign a different ID to the job.`));
|
|
3224
|
-
}
|
|
3225
|
-
return new Job(this, options);
|
|
3226
|
-
}
|
|
3227
|
-
defineAuthResolver(integration, resolver) {
|
|
3228
|
-
__privateGet(this, _authResolvers)[integration.id] = resolver;
|
|
3229
|
-
return this;
|
|
3230
|
-
}
|
|
3231
|
-
defineDynamicSchedule(options) {
|
|
3232
|
-
return new DynamicSchedule(this, options);
|
|
3233
|
-
}
|
|
3234
|
-
defineDynamicTrigger(options) {
|
|
3235
|
-
return new DynamicTrigger(this, options);
|
|
3236
|
-
}
|
|
3237
|
-
defineHttpEndpoint(options, suppressWarnings = false) {
|
|
3238
|
-
const existingHttpEndpoint = __privateGet(this, _registeredHttpEndpoints)[options.id];
|
|
3239
|
-
if (!suppressWarnings && existingHttpEndpoint) {
|
|
3240
|
-
console.warn((0, import_colorette.yellow)(`[@trigger.dev/sdk] Warning: The HttpEndpoint "${existingHttpEndpoint.id}" you're attempting to define has already been defined. Please assign a different ID to the HttpEndpoint.`));
|
|
3241
|
-
}
|
|
3242
|
-
const endpoint = httpEndpoint(options);
|
|
3243
|
-
__privateGet(this, _registeredHttpEndpoints)[endpoint.id] = endpoint;
|
|
3244
|
-
return endpoint;
|
|
3245
|
-
}
|
|
3246
|
-
defineConcurrencyLimit(options) {
|
|
3247
|
-
return new ConcurrencyLimit(options);
|
|
3248
|
-
}
|
|
3249
|
-
attach(job) {
|
|
3250
|
-
__privateGet(this, _registeredJobs)[job.id] = job;
|
|
3251
|
-
job.trigger.attachToJob(this, job);
|
|
3252
|
-
}
|
|
3253
|
-
attachDynamicTrigger(trigger) {
|
|
3254
|
-
__privateGet(this, _registeredDynamicTriggers)[trigger.id] = trigger;
|
|
3255
|
-
this.defineJob({
|
|
3256
|
-
id: dynamicTriggerRegisterSourceJobId(trigger.id),
|
|
3257
|
-
name: `Register dynamic trigger ${trigger.id}`,
|
|
3258
|
-
version: trigger.source.version,
|
|
3259
|
-
trigger: new EventTrigger({
|
|
3260
|
-
event: registerSourceEvent,
|
|
3261
|
-
filter: {
|
|
3262
|
-
dynamicTriggerId: [
|
|
3263
|
-
trigger.id
|
|
3264
|
-
]
|
|
3265
|
-
}
|
|
3266
|
-
}),
|
|
3267
|
-
integrations: {
|
|
3268
|
-
integration: trigger.source.integration
|
|
3269
|
-
},
|
|
3270
|
-
run: async (event, io, ctx) => {
|
|
3271
|
-
const updates = await trigger.source.register(event.source.params, event, io, ctx);
|
|
3272
|
-
if (!updates) {
|
|
3273
|
-
return;
|
|
3274
|
-
}
|
|
3275
|
-
return await io.updateSource("update-source", {
|
|
3276
|
-
key: event.source.key,
|
|
3277
|
-
...updates
|
|
3278
|
-
});
|
|
3279
|
-
},
|
|
3280
|
-
__internal: true
|
|
3281
|
-
});
|
|
3282
|
-
}
|
|
3283
|
-
attachJobToDynamicTrigger(job, trigger) {
|
|
3284
|
-
const jobs = __privateGet(this, _jobMetadataByDynamicTriggers)[trigger.id] ?? [];
|
|
3285
|
-
jobs.push({
|
|
3286
|
-
id: job.id,
|
|
3287
|
-
version: job.version
|
|
3288
|
-
});
|
|
3289
|
-
__privateGet(this, _jobMetadataByDynamicTriggers)[trigger.id] = jobs;
|
|
3290
|
-
}
|
|
3291
|
-
attachSource(options) {
|
|
3292
|
-
__privateGet(this, _registeredHttpSourceHandlers)[options.key] = async (s, r) => {
|
|
3293
|
-
return await options.source.handle(s, r, __privateGet(this, _internalLogger));
|
|
3294
|
-
};
|
|
3295
|
-
let registeredSource = __privateGet(this, _registeredSources)[options.key];
|
|
3296
|
-
if (!registeredSource) {
|
|
3297
|
-
registeredSource = {
|
|
3298
|
-
version: "2",
|
|
3299
|
-
channel: options.source.channel,
|
|
3300
|
-
key: options.key,
|
|
3301
|
-
params: options.params,
|
|
3302
|
-
options: {},
|
|
3303
|
-
integration: {
|
|
3304
|
-
id: options.source.integration.id,
|
|
3305
|
-
metadata: options.source.integration.metadata,
|
|
3306
|
-
authSource: options.source.integration.authSource
|
|
3307
|
-
},
|
|
3308
|
-
registerSourceJob: {
|
|
3309
|
-
id: options.key,
|
|
3310
|
-
version: options.source.version
|
|
3311
|
-
}
|
|
3312
|
-
};
|
|
3313
|
-
}
|
|
3314
|
-
const newOptions = deepMergeOptions({
|
|
3315
|
-
event: typeof options.event.name === "string" ? [
|
|
3316
|
-
options.event.name
|
|
3317
|
-
] : options.event.name
|
|
3318
|
-
}, options.options ?? {});
|
|
3319
|
-
registeredSource.options = deepMergeOptions(registeredSource.options, newOptions);
|
|
3320
|
-
__privateGet(this, _registeredSources)[options.key] = registeredSource;
|
|
3321
|
-
new Job(this, {
|
|
3322
|
-
id: options.key,
|
|
3323
|
-
name: options.key,
|
|
3324
|
-
version: options.source.version,
|
|
3325
|
-
trigger: new EventTrigger({
|
|
3326
|
-
event: registerSourceEvent,
|
|
3327
|
-
filter: {
|
|
3328
|
-
source: {
|
|
3329
|
-
key: [
|
|
3330
|
-
options.key
|
|
3331
|
-
]
|
|
3332
|
-
}
|
|
3333
|
-
}
|
|
3334
|
-
}),
|
|
3335
|
-
integrations: {
|
|
3336
|
-
integration: options.source.integration
|
|
3337
|
-
},
|
|
3338
|
-
run: async (event, io, ctx) => {
|
|
3339
|
-
const updates = await options.source.register(options.params, event, io, ctx);
|
|
3340
|
-
if (!updates) {
|
|
3341
|
-
return;
|
|
3342
|
-
}
|
|
3343
|
-
return await io.updateSource("update-source", {
|
|
3344
|
-
key: options.key,
|
|
3345
|
-
...updates
|
|
3346
|
-
});
|
|
3347
|
-
},
|
|
3348
|
-
__internal: true
|
|
3349
|
-
});
|
|
3350
|
-
}
|
|
3351
|
-
attachDynamicSchedule(key) {
|
|
3352
|
-
const jobs = __privateGet(this, _registeredSchedules)[key] ?? [];
|
|
3353
|
-
__privateGet(this, _registeredSchedules)[key] = jobs;
|
|
3354
|
-
}
|
|
3355
|
-
attachDynamicScheduleToJob(key, job) {
|
|
3356
|
-
const jobs = __privateGet(this, _registeredSchedules)[key] ?? [];
|
|
3357
|
-
jobs.push({
|
|
3358
|
-
id: job.id,
|
|
3359
|
-
version: job.version
|
|
3360
|
-
});
|
|
3361
|
-
__privateGet(this, _registeredSchedules)[key] = jobs;
|
|
3362
|
-
}
|
|
3363
|
-
attachWebhook(options) {
|
|
3364
|
-
const { source } = options;
|
|
3365
|
-
__privateGet(this, _registeredWebhookSourceHandlers)[options.key] = {
|
|
3366
|
-
verify: source.verify.bind(source),
|
|
3367
|
-
generateEvents: source.generateEvents.bind(source)
|
|
3368
|
-
};
|
|
3369
|
-
let registeredWebhook = __privateGet(this, _registeredWebhooks)[options.key];
|
|
3370
|
-
if (!registeredWebhook) {
|
|
3371
|
-
registeredWebhook = {
|
|
3372
|
-
key: options.key,
|
|
3373
|
-
params: options.params,
|
|
3374
|
-
config: options.config,
|
|
3375
|
-
integration: {
|
|
3376
|
-
id: source.integration.id,
|
|
3377
|
-
metadata: source.integration.metadata,
|
|
3378
|
-
authSource: source.integration.authSource
|
|
3379
|
-
},
|
|
3380
|
-
httpEndpoint: {
|
|
3381
|
-
id: options.key
|
|
3382
|
-
}
|
|
3383
|
-
};
|
|
3384
|
-
} else {
|
|
3385
|
-
registeredWebhook.config = deepMergeOptions(registeredWebhook.config, options.config);
|
|
3386
|
-
}
|
|
3387
|
-
__privateGet(this, _registeredWebhooks)[options.key] = registeredWebhook;
|
|
3388
|
-
new Job(this, {
|
|
3389
|
-
id: `webhook.register.${options.key}`,
|
|
3390
|
-
name: `webhook.register.${options.key}`,
|
|
3391
|
-
version: source.version,
|
|
3392
|
-
trigger: new EventTrigger({
|
|
3393
|
-
event: registerWebhookEvent(options.key)
|
|
3394
|
-
}),
|
|
3395
|
-
integrations: {
|
|
3396
|
-
integration: source.integration
|
|
3397
|
-
},
|
|
3398
|
-
run: async (registerPayload, io, ctx) => {
|
|
3399
|
-
return await io.try(async () => {
|
|
3400
|
-
__privateGet(this, _internalLogger).debug("[webhook.register] Start");
|
|
3401
|
-
const crudOptions = {
|
|
3402
|
-
io,
|
|
3403
|
-
ctx: registerPayload
|
|
3404
|
-
};
|
|
3405
|
-
if (!registerPayload.active) {
|
|
3406
|
-
__privateGet(this, _internalLogger).debug("[webhook.register] Not active, run create");
|
|
3407
|
-
await io.try(async () => {
|
|
3408
|
-
await source.crud.create(crudOptions);
|
|
3409
|
-
}, async (error) => {
|
|
3410
|
-
__privateGet(this, _internalLogger).debug("[webhook.register] Error during create, re-trying with delete first", {
|
|
3411
|
-
error
|
|
3412
|
-
});
|
|
3413
|
-
await io.runTask("create-retry", async () => {
|
|
3414
|
-
await source.crud.delete(crudOptions);
|
|
3415
|
-
await source.crud.create(crudOptions);
|
|
3416
|
-
});
|
|
3417
|
-
});
|
|
3418
|
-
return await io.updateWebhook("update-webhook-success", {
|
|
3419
|
-
key: options.key,
|
|
3420
|
-
active: true,
|
|
3421
|
-
config: registerPayload.config.desired
|
|
3422
|
-
});
|
|
3423
|
-
}
|
|
3424
|
-
__privateGet(this, _internalLogger).debug("[webhook.register] Already active, run update");
|
|
3425
|
-
if (source.crud.update) {
|
|
3426
|
-
await source.crud.update(crudOptions);
|
|
3427
|
-
} else {
|
|
3428
|
-
__privateGet(this, _internalLogger).debug("[webhook.register] Run delete and create instead of update");
|
|
3429
|
-
await source.crud.delete(crudOptions);
|
|
3430
|
-
await source.crud.create(crudOptions);
|
|
3431
|
-
}
|
|
3432
|
-
return await io.updateWebhook("update-webhook-success", {
|
|
3433
|
-
key: options.key,
|
|
3434
|
-
active: true,
|
|
3435
|
-
config: registerPayload.config.desired
|
|
3436
|
-
});
|
|
3437
|
-
}, async (error) => {
|
|
3438
|
-
__privateGet(this, _internalLogger).debug("[webhook.register] Error", {
|
|
3439
|
-
error
|
|
3440
|
-
});
|
|
3441
|
-
await io.updateWebhook("update-webhook-error", {
|
|
3442
|
-
key: options.key,
|
|
3443
|
-
active: false
|
|
3444
|
-
});
|
|
3445
|
-
throw error;
|
|
3446
|
-
});
|
|
3447
|
-
},
|
|
3448
|
-
__internal: true
|
|
3449
|
-
});
|
|
3450
|
-
}
|
|
3451
|
-
async registerTrigger(id, key, options, idempotencyKey) {
|
|
3452
|
-
return __privateGet(this, _client2).registerTrigger(this.id, id, key, options, idempotencyKey);
|
|
3453
|
-
}
|
|
3454
|
-
async getAuth(id) {
|
|
3455
|
-
return __privateGet(this, _client2).getAuth(this.id, id);
|
|
3456
|
-
}
|
|
3457
|
-
async sendEvent(event, options) {
|
|
3458
|
-
return __privateGet(this, _client2).sendEvent(event, options);
|
|
3459
|
-
}
|
|
3460
|
-
async sendEvents(events, options) {
|
|
3461
|
-
return __privateGet(this, _client2).sendEvents(events, options);
|
|
3462
|
-
}
|
|
3463
|
-
async cancelEvent(eventId) {
|
|
3464
|
-
return __privateGet(this, _client2).cancelEvent(eventId);
|
|
3465
|
-
}
|
|
3466
|
-
async cancelRunsForEvent(eventId) {
|
|
3467
|
-
return __privateGet(this, _client2).cancelRunsForEvent(eventId);
|
|
3468
|
-
}
|
|
3469
|
-
async updateStatus(runId, id, status) {
|
|
3470
|
-
return __privateGet(this, _client2).updateStatus(runId, id, status);
|
|
3471
|
-
}
|
|
3472
|
-
async registerSchedule(id, key, schedule) {
|
|
3473
|
-
return __privateGet(this, _client2).registerSchedule(this.id, id, key, schedule);
|
|
3474
|
-
}
|
|
3475
|
-
async unregisterSchedule(id, key) {
|
|
3476
|
-
return __privateGet(this, _client2).unregisterSchedule(this.id, id, key);
|
|
3477
|
-
}
|
|
3478
|
-
async getEvent(eventId) {
|
|
3479
|
-
return __privateGet(this, _client2).getEvent(eventId);
|
|
3480
|
-
}
|
|
3481
|
-
async getRun(runId, options) {
|
|
3482
|
-
return __privateGet(this, _client2).getRun(runId, options);
|
|
3483
|
-
}
|
|
3484
|
-
async cancelRun(runId) {
|
|
3485
|
-
return __privateGet(this, _client2).cancelRun(runId);
|
|
3486
|
-
}
|
|
3487
|
-
async getRuns(jobSlug, options) {
|
|
3488
|
-
return __privateGet(this, _client2).getRuns(jobSlug, options);
|
|
3489
|
-
}
|
|
3490
|
-
async getRunStatuses(runId) {
|
|
3491
|
-
return __privateGet(this, _client2).getRunStatuses(runId);
|
|
3492
|
-
}
|
|
3493
|
-
async invokeJob(jobId, payload, options) {
|
|
3494
|
-
return __privateGet(this, _client2).invokeJob(jobId, payload, options);
|
|
3495
|
-
}
|
|
3496
|
-
async createEphemeralEventDispatcher(payload) {
|
|
3497
|
-
return __privateGet(this, _client2).createEphemeralEventDispatcher(payload);
|
|
3498
|
-
}
|
|
3499
|
-
get store() {
|
|
3500
|
-
return {
|
|
3501
|
-
env: __privateGet(this, _envStore)
|
|
3502
|
-
};
|
|
3503
|
-
}
|
|
3504
|
-
authorized(apiKey) {
|
|
3505
|
-
if (typeof apiKey !== "string") {
|
|
3506
|
-
return "missing-header";
|
|
3507
|
-
}
|
|
3508
|
-
const localApiKey = __privateGet(this, _options4).apiKey ?? process.env.TRIGGER_API_KEY;
|
|
3509
|
-
if (!localApiKey) {
|
|
3510
|
-
return "missing-client";
|
|
3511
|
-
}
|
|
3512
|
-
return apiKey === localApiKey ? "authorized" : "unauthorized";
|
|
3513
|
-
}
|
|
3514
|
-
apiKey() {
|
|
3515
|
-
return __privateGet(this, _options4).apiKey ?? process.env.TRIGGER_API_KEY;
|
|
3516
|
-
}
|
|
3517
|
-
};
|
|
3518
|
-
__name(TriggerClient, "TriggerClient");
|
|
3519
|
-
_options4 = new WeakMap();
|
|
3520
|
-
_registeredJobs = new WeakMap();
|
|
3521
|
-
_registeredSources = new WeakMap();
|
|
3522
|
-
_registeredWebhooks = new WeakMap();
|
|
3523
|
-
_registeredHttpSourceHandlers = new WeakMap();
|
|
3524
|
-
_registeredWebhookSourceHandlers = new WeakMap();
|
|
3525
|
-
_registeredDynamicTriggers = new WeakMap();
|
|
3526
|
-
_jobMetadataByDynamicTriggers = new WeakMap();
|
|
3527
|
-
_registeredSchedules = new WeakMap();
|
|
3528
|
-
_registeredHttpEndpoints = new WeakMap();
|
|
3529
|
-
_authResolvers = new WeakMap();
|
|
3530
|
-
_envStore = new WeakMap();
|
|
3531
|
-
_eventEmitter = new WeakMap();
|
|
3532
|
-
_client2 = new WeakMap();
|
|
3533
|
-
_internalLogger = new WeakMap();
|
|
3534
|
-
_preprocessRun = new WeakSet();
|
|
3535
|
-
preprocessRun_fn = /* @__PURE__ */ __name(async function(body, job) {
|
|
3536
|
-
const context = __privateMethod(this, _createPreprocessRunContext, createPreprocessRunContext_fn).call(this, body);
|
|
3537
|
-
const parsedPayload = job.trigger.event.parsePayload(body.event.payload ?? {});
|
|
3538
|
-
const properties = job.trigger.event.runProperties?.(parsedPayload) ?? [];
|
|
3539
|
-
return {
|
|
3540
|
-
abort: false,
|
|
3541
|
-
properties
|
|
3542
|
-
};
|
|
3543
|
-
}, "#preprocessRun");
|
|
3544
|
-
_executeJob = new WeakSet();
|
|
3545
|
-
executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1, timeOrigin, triggerVersion) {
|
|
3546
|
-
__privateGet(this, _internalLogger).debug("executing job", {
|
|
3547
|
-
execution: body1,
|
|
3548
|
-
job: job1.id,
|
|
3549
|
-
version: job1.version,
|
|
3550
|
-
triggerVersion
|
|
3551
|
-
});
|
|
3552
|
-
const context = __privateMethod(this, _createRunContext, createRunContext_fn).call(this, body1);
|
|
3553
|
-
const io = new IO({
|
|
3554
|
-
id: body1.run.id,
|
|
3555
|
-
jobId: job1.id,
|
|
3556
|
-
cachedTasks: body1.tasks,
|
|
3557
|
-
cachedTasksCursor: body1.cachedTaskCursor,
|
|
3558
|
-
yieldedExecutions: body1.yieldedExecutions ?? [],
|
|
3559
|
-
noopTasksSet: body1.noopTasksSet,
|
|
3560
|
-
apiClient: __privateGet(this, _client2),
|
|
3561
|
-
logger: __privateGet(this, _internalLogger),
|
|
3562
|
-
client: this,
|
|
3563
|
-
context,
|
|
3564
|
-
jobLogLevel: job1.logLevel ?? __privateGet(this, _options4).logLevel ?? "info",
|
|
3565
|
-
jobLogger: __privateGet(this, _options4).ioLogLocalEnabled ? new import_core8.Logger(job1.id, job1.logLevel ?? __privateGet(this, _options4).logLevel ?? "info") : void 0,
|
|
3566
|
-
serverVersion: triggerVersion,
|
|
3567
|
-
timeOrigin,
|
|
3568
|
-
executionTimeout: body1.runChunkExecutionLimit
|
|
3569
|
-
});
|
|
3570
|
-
const resolvedConnections = await __privateMethod(this, _resolveConnections, resolveConnections_fn).call(this, context, job1.options.integrations, body1.connections);
|
|
3571
|
-
if (!resolvedConnections.ok) {
|
|
3572
|
-
return {
|
|
3573
|
-
status: "UNRESOLVED_AUTH_ERROR",
|
|
3574
|
-
issues: resolvedConnections.issues
|
|
3575
|
-
};
|
|
3576
|
-
}
|
|
3577
|
-
const ioWithConnections = createIOWithIntegrations(io, resolvedConnections.data, job1.options.integrations);
|
|
3578
|
-
try {
|
|
3579
|
-
const parsedPayload = job1.trigger.event.parsePayload(body1.event.payload ?? {});
|
|
3580
|
-
if (!context.run.isTest) {
|
|
3581
|
-
const verified = await job1.trigger.verifyPayload(parsedPayload);
|
|
3582
|
-
if (!verified.success) {
|
|
3583
|
-
return {
|
|
3584
|
-
status: "ERROR",
|
|
3585
|
-
error: {
|
|
3586
|
-
message: `Payload verification failed. ${verified.reason}`
|
|
3587
|
-
}
|
|
3588
|
-
};
|
|
3589
|
-
}
|
|
3590
|
-
}
|
|
3591
|
-
const output = await runLocalStorage.runWith({
|
|
3592
|
-
io,
|
|
3593
|
-
ctx: context
|
|
3594
|
-
}, () => {
|
|
3595
|
-
return job1.options.run(parsedPayload, ioWithConnections, context);
|
|
3596
|
-
});
|
|
3597
|
-
if (__privateGet(this, _options4).verbose) {
|
|
3598
|
-
__privateMethod(this, _logIOStats, logIOStats_fn).call(this, io.stats);
|
|
3599
|
-
}
|
|
3600
|
-
return {
|
|
3601
|
-
status: "SUCCESS",
|
|
3602
|
-
output
|
|
3603
|
-
};
|
|
3604
|
-
} catch (error) {
|
|
3605
|
-
if (__privateGet(this, _options4).verbose) {
|
|
3606
|
-
__privateMethod(this, _logIOStats, logIOStats_fn).call(this, io.stats);
|
|
3607
|
-
}
|
|
3608
|
-
if (error instanceof ResumeWithParallelTaskError) {
|
|
3609
|
-
return {
|
|
3610
|
-
status: "RESUME_WITH_PARALLEL_TASK",
|
|
3611
|
-
task: error.task,
|
|
3612
|
-
childErrors: error.childErrors.map((childError) => {
|
|
3613
|
-
return __privateMethod(this, _convertErrorToExecutionResponse, convertErrorToExecutionResponse_fn).call(this, childError, body1);
|
|
3614
|
-
})
|
|
3615
|
-
};
|
|
3616
|
-
}
|
|
3617
|
-
return __privateMethod(this, _convertErrorToExecutionResponse, convertErrorToExecutionResponse_fn).call(this, error, body1);
|
|
3618
|
-
}
|
|
3619
|
-
}, "#executeJob");
|
|
3620
|
-
_convertErrorToExecutionResponse = new WeakSet();
|
|
3621
|
-
convertErrorToExecutionResponse_fn = /* @__PURE__ */ __name(function(error, body2) {
|
|
3622
|
-
if (error instanceof AutoYieldExecutionError) {
|
|
3623
|
-
return {
|
|
3624
|
-
status: "AUTO_YIELD_EXECUTION",
|
|
3625
|
-
location: error.location,
|
|
3626
|
-
timeRemaining: error.timeRemaining,
|
|
3627
|
-
timeElapsed: error.timeElapsed,
|
|
3628
|
-
limit: body2.runChunkExecutionLimit
|
|
3629
|
-
};
|
|
3630
|
-
}
|
|
3631
|
-
if (error instanceof AutoYieldWithCompletedTaskExecutionError) {
|
|
3632
|
-
return {
|
|
3633
|
-
status: "AUTO_YIELD_EXECUTION_WITH_COMPLETED_TASK",
|
|
3634
|
-
id: error.id,
|
|
3635
|
-
properties: error.properties,
|
|
3636
|
-
output: error.output,
|
|
3637
|
-
data: {
|
|
3638
|
-
...error.data,
|
|
3639
|
-
limit: body2.runChunkExecutionLimit
|
|
3640
|
-
}
|
|
3641
|
-
};
|
|
3642
|
-
}
|
|
3643
|
-
if (error instanceof YieldExecutionError) {
|
|
3644
|
-
return {
|
|
3645
|
-
status: "YIELD_EXECUTION",
|
|
3646
|
-
key: error.key
|
|
3647
|
-
};
|
|
3648
|
-
}
|
|
3649
|
-
if (error instanceof ParsedPayloadSchemaError) {
|
|
3650
|
-
return {
|
|
3651
|
-
status: "INVALID_PAYLOAD",
|
|
3652
|
-
errors: error.schemaErrors
|
|
3653
|
-
};
|
|
3654
|
-
}
|
|
3655
|
-
if (error instanceof ResumeWithTaskError) {
|
|
3656
|
-
return {
|
|
3657
|
-
status: "RESUME_WITH_TASK",
|
|
3658
|
-
task: error.task
|
|
3659
|
-
};
|
|
3660
|
-
}
|
|
3661
|
-
if (error instanceof RetryWithTaskError) {
|
|
3662
|
-
return {
|
|
3663
|
-
status: "RETRY_WITH_TASK",
|
|
3664
|
-
task: error.task,
|
|
3665
|
-
error: error.cause,
|
|
3666
|
-
retryAt: error.retryAt
|
|
3667
|
-
};
|
|
3668
|
-
}
|
|
3669
|
-
if (error instanceof CanceledWithTaskError) {
|
|
3670
|
-
return {
|
|
3671
|
-
status: "CANCELED",
|
|
3672
|
-
task: error.task
|
|
3673
|
-
};
|
|
3674
|
-
}
|
|
3675
|
-
if (error instanceof ErrorWithTask) {
|
|
3676
|
-
const errorWithStack2 = import_core8.ErrorWithStackSchema.safeParse(error.cause.output);
|
|
3677
|
-
if (errorWithStack2.success) {
|
|
3678
|
-
return {
|
|
3679
|
-
status: "ERROR",
|
|
3680
|
-
error: errorWithStack2.data,
|
|
3681
|
-
task: error.cause
|
|
3682
|
-
};
|
|
3683
|
-
}
|
|
3684
|
-
return {
|
|
3685
|
-
status: "ERROR",
|
|
3686
|
-
error: {
|
|
3687
|
-
message: JSON.stringify(error.cause.output)
|
|
3688
|
-
},
|
|
3689
|
-
task: error.cause
|
|
3690
|
-
};
|
|
3691
|
-
}
|
|
3692
|
-
if (error instanceof RetryWithTaskError) {
|
|
3693
|
-
const errorWithStack2 = import_core8.ErrorWithStackSchema.safeParse(error.cause);
|
|
3694
|
-
if (errorWithStack2.success) {
|
|
3695
|
-
return {
|
|
3696
|
-
status: "ERROR",
|
|
3697
|
-
error: errorWithStack2.data,
|
|
3698
|
-
task: error.task
|
|
3699
|
-
};
|
|
3700
|
-
}
|
|
3701
|
-
return {
|
|
3702
|
-
status: "ERROR",
|
|
3703
|
-
error: {
|
|
3704
|
-
message: "Unknown error"
|
|
3705
|
-
},
|
|
3706
|
-
task: error.task
|
|
3707
|
-
};
|
|
3708
|
-
}
|
|
3709
|
-
const errorWithStack = import_core8.ErrorWithStackSchema.safeParse(error);
|
|
3710
|
-
if (errorWithStack.success) {
|
|
3711
|
-
return {
|
|
3712
|
-
status: "ERROR",
|
|
3713
|
-
error: errorWithStack.data
|
|
3714
|
-
};
|
|
3715
|
-
}
|
|
3716
|
-
const message = typeof error === "string" ? error : JSON.stringify(error);
|
|
3717
|
-
return {
|
|
3718
|
-
status: "ERROR",
|
|
3719
|
-
error: {
|
|
3720
|
-
name: "Unknown error",
|
|
3721
|
-
message
|
|
3722
|
-
}
|
|
3723
|
-
};
|
|
3724
|
-
}, "#convertErrorToExecutionResponse");
|
|
3725
|
-
_createRunContext = new WeakSet();
|
|
3726
|
-
createRunContext_fn = /* @__PURE__ */ __name(function(execution) {
|
|
3727
|
-
const { event, organization, project, environment, job, run, source } = execution;
|
|
3728
|
-
return {
|
|
3729
|
-
event: {
|
|
3730
|
-
id: event.id,
|
|
3731
|
-
name: event.name,
|
|
3732
|
-
context: event.context,
|
|
3733
|
-
timestamp: event.timestamp
|
|
3734
|
-
},
|
|
3735
|
-
organization,
|
|
3736
|
-
project: project ?? {
|
|
3737
|
-
id: "unknown",
|
|
3738
|
-
name: "unknown",
|
|
3739
|
-
slug: "unknown"
|
|
3740
|
-
},
|
|
3741
|
-
environment,
|
|
3742
|
-
job,
|
|
3743
|
-
run,
|
|
3744
|
-
account: execution.account,
|
|
3745
|
-
source
|
|
3746
|
-
};
|
|
3747
|
-
}, "#createRunContext");
|
|
3748
|
-
_createPreprocessRunContext = new WeakSet();
|
|
3749
|
-
createPreprocessRunContext_fn = /* @__PURE__ */ __name(function(body3) {
|
|
3750
|
-
const { event, organization, environment, job, run, account } = body3;
|
|
3751
|
-
return {
|
|
3752
|
-
event: {
|
|
3753
|
-
id: event.id,
|
|
3754
|
-
name: event.name,
|
|
3755
|
-
context: event.context,
|
|
3756
|
-
timestamp: event.timestamp
|
|
3757
|
-
},
|
|
3758
|
-
organization,
|
|
3759
|
-
environment,
|
|
3760
|
-
job,
|
|
3761
|
-
run,
|
|
3762
|
-
account
|
|
3763
|
-
};
|
|
3764
|
-
}, "#createPreprocessRunContext");
|
|
3765
|
-
_handleHttpSourceRequest = new WeakSet();
|
|
3766
|
-
handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourceRequest) {
|
|
3767
|
-
__privateGet(this, _internalLogger).debug("Handling HTTP source request", {
|
|
3768
|
-
source
|
|
3769
|
-
});
|
|
3770
|
-
if (source.dynamicId) {
|
|
3771
|
-
const dynamicTrigger = __privateGet(this, _registeredDynamicTriggers)[source.dynamicId];
|
|
3772
|
-
if (!dynamicTrigger) {
|
|
3773
|
-
__privateGet(this, _internalLogger).debug("No dynamic trigger registered for HTTP source", {
|
|
3774
|
-
source
|
|
3775
|
-
});
|
|
3776
|
-
return {
|
|
3777
|
-
response: {
|
|
3778
|
-
status: 200,
|
|
3779
|
-
body: {
|
|
3780
|
-
ok: true
|
|
3781
|
-
}
|
|
3782
|
-
},
|
|
3783
|
-
events: []
|
|
3784
|
-
};
|
|
3785
|
-
}
|
|
3786
|
-
const results2 = await dynamicTrigger.source.handle(source, sourceRequest, __privateGet(this, _internalLogger));
|
|
3787
|
-
if (!results2) {
|
|
3788
|
-
return {
|
|
3789
|
-
events: [],
|
|
3790
|
-
response: {
|
|
3791
|
-
status: 200,
|
|
3792
|
-
body: {
|
|
3793
|
-
ok: true
|
|
3794
|
-
}
|
|
3795
|
-
}
|
|
3796
|
-
};
|
|
3797
|
-
}
|
|
3798
|
-
return {
|
|
3799
|
-
events: results2.events,
|
|
3800
|
-
response: results2.response ?? {
|
|
3801
|
-
status: 200,
|
|
3802
|
-
body: {
|
|
3803
|
-
ok: true
|
|
3804
|
-
}
|
|
3805
|
-
},
|
|
3806
|
-
metadata: results2.metadata
|
|
3807
|
-
};
|
|
3808
|
-
}
|
|
3809
|
-
const handler = __privateGet(this, _registeredHttpSourceHandlers)[source.key];
|
|
3810
|
-
if (!handler) {
|
|
3811
|
-
__privateGet(this, _internalLogger).debug("No handler registered for HTTP source", {
|
|
3812
|
-
source
|
|
3813
|
-
});
|
|
3814
|
-
return {
|
|
3815
|
-
response: {
|
|
3816
|
-
status: 200,
|
|
3817
|
-
body: {
|
|
3818
|
-
ok: true
|
|
3819
|
-
}
|
|
3820
|
-
},
|
|
3821
|
-
events: []
|
|
3822
|
-
};
|
|
3823
|
-
}
|
|
3824
|
-
const results = await handler(source, sourceRequest);
|
|
3825
|
-
if (!results) {
|
|
3826
|
-
return {
|
|
3827
|
-
events: [],
|
|
3828
|
-
response: {
|
|
3829
|
-
status: 200,
|
|
3830
|
-
body: {
|
|
3831
|
-
ok: true
|
|
3832
|
-
}
|
|
3833
|
-
}
|
|
3834
|
-
};
|
|
3835
|
-
}
|
|
3836
|
-
return {
|
|
3837
|
-
events: results.events,
|
|
3838
|
-
response: results.response ?? {
|
|
3839
|
-
status: 200,
|
|
3840
|
-
body: {
|
|
3841
|
-
ok: true
|
|
3842
|
-
}
|
|
3843
|
-
},
|
|
3844
|
-
metadata: results.metadata
|
|
3845
|
-
};
|
|
3846
|
-
}, "#handleHttpSourceRequest");
|
|
3847
|
-
_handleHttpEndpointRequestForResponse = new WeakSet();
|
|
3848
|
-
handleHttpEndpointRequestForResponse_fn = /* @__PURE__ */ __name(async function(data, sourceRequest1) {
|
|
3849
|
-
__privateGet(this, _internalLogger).debug("Handling HTTP Endpoint request for response", {
|
|
3850
|
-
data
|
|
3851
|
-
});
|
|
3852
|
-
const httpEndpoint2 = __privateGet(this, _registeredHttpEndpoints)[data.key];
|
|
3853
|
-
if (!httpEndpoint2) {
|
|
3854
|
-
__privateGet(this, _internalLogger).debug("No handler registered for HTTP Endpoint", {
|
|
3855
|
-
data
|
|
3856
|
-
});
|
|
3857
|
-
return {
|
|
3858
|
-
response: {
|
|
3859
|
-
status: 200,
|
|
3860
|
-
body: {
|
|
3861
|
-
ok: true
|
|
3862
|
-
}
|
|
3863
|
-
}
|
|
3864
|
-
};
|
|
3865
|
-
}
|
|
3866
|
-
const handledResponse = await httpEndpoint2.handleRequest(sourceRequest1);
|
|
3867
|
-
if (!handledResponse) {
|
|
3868
|
-
__privateGet(this, _internalLogger).debug("There's no HTTP Endpoint respondWith.handler()", {
|
|
3869
|
-
data
|
|
3870
|
-
});
|
|
3871
|
-
return {
|
|
3872
|
-
response: {
|
|
3873
|
-
status: 200,
|
|
3874
|
-
body: {
|
|
3875
|
-
ok: true
|
|
3876
|
-
}
|
|
3877
|
-
}
|
|
3878
|
-
};
|
|
3879
|
-
}
|
|
3880
|
-
let body;
|
|
3881
|
-
try {
|
|
3882
|
-
body = await handledResponse.text();
|
|
3883
|
-
} catch (error) {
|
|
3884
|
-
__privateGet(this, _internalLogger).error(`Error reading httpEndpoint ${httpEndpoint2.id} respondWith.handler Response`, {
|
|
3885
|
-
error
|
|
3886
|
-
});
|
|
3887
|
-
}
|
|
3888
|
-
const response = {
|
|
3889
|
-
status: handledResponse.status,
|
|
3890
|
-
headers: handledResponse.headers ? Object.fromEntries(handledResponse.headers.entries()) : void 0,
|
|
3891
|
-
body
|
|
3892
|
-
};
|
|
3893
|
-
__privateGet(this, _internalLogger).info(`httpEndpoint ${httpEndpoint2.id} respondWith.handler response`, {
|
|
3894
|
-
response
|
|
3895
|
-
});
|
|
3896
|
-
return {
|
|
3897
|
-
response
|
|
3898
|
-
};
|
|
3899
|
-
}, "#handleHttpEndpointRequestForResponse");
|
|
3900
|
-
_handleWebhookRequest = new WeakSet();
|
|
3901
|
-
handleWebhookRequest_fn = /* @__PURE__ */ __name(async function(request, ctx) {
|
|
3902
|
-
__privateGet(this, _internalLogger).debug("Handling webhook request", {
|
|
3903
|
-
ctx
|
|
3904
|
-
});
|
|
3905
|
-
const okResponse = {
|
|
3906
|
-
status: 200,
|
|
3907
|
-
body: {
|
|
3908
|
-
ok: true
|
|
3909
|
-
}
|
|
3910
|
-
};
|
|
3911
|
-
const handlers = __privateGet(this, _registeredWebhookSourceHandlers)[ctx.key];
|
|
3912
|
-
if (!handlers) {
|
|
3913
|
-
__privateGet(this, _internalLogger).debug("No handler registered for webhook", {
|
|
3914
|
-
ctx
|
|
3915
|
-
});
|
|
3916
|
-
return {
|
|
3917
|
-
response: okResponse,
|
|
3918
|
-
verified: false
|
|
3919
|
-
};
|
|
3920
|
-
}
|
|
3921
|
-
const { verify, generateEvents } = handlers;
|
|
3922
|
-
const verifyResult = await verify(request, this, ctx);
|
|
3923
|
-
if (!verifyResult.success) {
|
|
3924
|
-
return {
|
|
3925
|
-
response: okResponse,
|
|
3926
|
-
verified: false,
|
|
3927
|
-
error: verifyResult.reason
|
|
3928
|
-
};
|
|
3929
|
-
}
|
|
3930
|
-
await generateEvents(request, this, ctx);
|
|
3931
|
-
return {
|
|
3932
|
-
response: okResponse,
|
|
3933
|
-
verified: true
|
|
3934
|
-
};
|
|
3935
|
-
}, "#handleWebhookRequest");
|
|
3936
|
-
_resolveConnections = new WeakSet();
|
|
3937
|
-
resolveConnections_fn = /* @__PURE__ */ __name(async function(ctx1, integrations, connections) {
|
|
3938
|
-
if (!integrations) {
|
|
3939
|
-
return {
|
|
3940
|
-
ok: true,
|
|
3941
|
-
data: {}
|
|
3942
|
-
};
|
|
3943
|
-
}
|
|
3944
|
-
const resolvedAuthResults = await Promise.all(Object.keys(integrations).map(async (key) => {
|
|
3945
|
-
const integration = integrations[key];
|
|
3946
|
-
const auth = (connections ?? {})[key];
|
|
3947
|
-
const result = await __privateMethod(this, _resolveConnection, resolveConnection_fn).call(this, ctx1, integration, auth);
|
|
3948
|
-
if (result.ok) {
|
|
3949
|
-
return {
|
|
3950
|
-
ok: true,
|
|
3951
|
-
auth: result.auth,
|
|
3952
|
-
key
|
|
3953
|
-
};
|
|
3954
|
-
} else {
|
|
3955
|
-
return {
|
|
3956
|
-
ok: false,
|
|
3957
|
-
error: result.error,
|
|
3958
|
-
key
|
|
3959
|
-
};
|
|
3960
|
-
}
|
|
3961
|
-
}));
|
|
3962
|
-
const allResolved = resolvedAuthResults.every((result) => result.ok);
|
|
3963
|
-
if (allResolved) {
|
|
3964
|
-
return {
|
|
3965
|
-
ok: true,
|
|
3966
|
-
data: resolvedAuthResults.reduce((acc, result) => {
|
|
3967
|
-
acc[result.key] = result.auth;
|
|
3968
|
-
return acc;
|
|
3969
|
-
}, {})
|
|
3970
|
-
};
|
|
3971
|
-
} else {
|
|
3972
|
-
return {
|
|
3973
|
-
ok: false,
|
|
3974
|
-
issues: resolvedAuthResults.reduce((acc, result) => {
|
|
3975
|
-
if (result.ok) {
|
|
3976
|
-
return acc;
|
|
3977
|
-
}
|
|
3978
|
-
const integration = integrations[result.key];
|
|
3979
|
-
acc[result.key] = {
|
|
3980
|
-
id: integration.id,
|
|
3981
|
-
error: result.error
|
|
3982
|
-
};
|
|
3983
|
-
return acc;
|
|
3984
|
-
}, {})
|
|
3985
|
-
};
|
|
3986
|
-
}
|
|
3987
|
-
}, "#resolveConnections");
|
|
3988
|
-
_resolveConnection = new WeakSet();
|
|
3989
|
-
resolveConnection_fn = /* @__PURE__ */ __name(async function(ctx2, integration, auth) {
|
|
3990
|
-
if (auth) {
|
|
3991
|
-
return {
|
|
3992
|
-
ok: true,
|
|
3993
|
-
auth
|
|
3994
|
-
};
|
|
3995
|
-
}
|
|
3996
|
-
const authResolver = __privateGet(this, _authResolvers)[integration.id];
|
|
3997
|
-
if (!authResolver) {
|
|
3998
|
-
if (integration.authSource === "HOSTED") {
|
|
3999
|
-
return {
|
|
4000
|
-
ok: false,
|
|
4001
|
-
error: `Something went wrong: Integration ${integration.id} is missing auth credentials from Trigger.dev`
|
|
4002
|
-
};
|
|
4003
|
-
}
|
|
4004
|
-
return {
|
|
4005
|
-
ok: true,
|
|
4006
|
-
auth: void 0
|
|
4007
|
-
};
|
|
4008
|
-
}
|
|
4009
|
-
try {
|
|
4010
|
-
const resolvedAuth = await authResolver(ctx2, integration);
|
|
4011
|
-
if (!resolvedAuth) {
|
|
4012
|
-
return {
|
|
4013
|
-
ok: false,
|
|
4014
|
-
error: `Auth could not be resolved for ${integration.id}: auth resolver returned null or undefined`
|
|
4015
|
-
};
|
|
4016
|
-
}
|
|
4017
|
-
return {
|
|
4018
|
-
ok: true,
|
|
4019
|
-
auth: resolvedAuth.type === "apiKey" ? {
|
|
4020
|
-
type: "apiKey",
|
|
4021
|
-
accessToken: resolvedAuth.token,
|
|
4022
|
-
additionalFields: resolvedAuth.additionalFields
|
|
4023
|
-
} : {
|
|
4024
|
-
type: "oauth2",
|
|
4025
|
-
accessToken: resolvedAuth.token,
|
|
4026
|
-
additionalFields: resolvedAuth.additionalFields
|
|
4027
|
-
}
|
|
4028
|
-
};
|
|
4029
|
-
} catch (resolverError) {
|
|
4030
|
-
if (resolverError instanceof Error) {
|
|
4031
|
-
return {
|
|
4032
|
-
ok: false,
|
|
4033
|
-
error: `Auth could not be resolved for ${integration.id}: auth resolver threw. ${resolverError.name}: ${resolverError.message}`
|
|
4034
|
-
};
|
|
4035
|
-
} else if (typeof resolverError === "string") {
|
|
4036
|
-
return {
|
|
4037
|
-
ok: false,
|
|
4038
|
-
error: `Auth could not be resolved for ${integration.id}: auth resolver threw an error: ${resolverError}`
|
|
4039
|
-
};
|
|
4040
|
-
}
|
|
4041
|
-
return {
|
|
4042
|
-
ok: false,
|
|
4043
|
-
error: `Auth could not be resolved for ${integration.id}: auth resolver threw an unknown error: ${JSON.stringify(resolverError)}`
|
|
4044
|
-
};
|
|
4045
|
-
}
|
|
4046
|
-
}, "#resolveConnection");
|
|
4047
|
-
_buildJobsIndex = new WeakSet();
|
|
4048
|
-
buildJobsIndex_fn = /* @__PURE__ */ __name(function() {
|
|
4049
|
-
return Object.values(__privateGet(this, _registeredJobs)).map((job) => __privateMethod(this, _buildJobIndex, buildJobIndex_fn).call(this, job));
|
|
4050
|
-
}, "#buildJobsIndex");
|
|
4051
|
-
_buildJobIndex = new WeakSet();
|
|
4052
|
-
buildJobIndex_fn = /* @__PURE__ */ __name(function(job2) {
|
|
4053
|
-
const internal = job2.options.__internal;
|
|
4054
|
-
return {
|
|
4055
|
-
id: job2.id,
|
|
4056
|
-
name: job2.name,
|
|
4057
|
-
version: job2.version,
|
|
4058
|
-
event: job2.trigger.event,
|
|
4059
|
-
trigger: job2.trigger.toJSON(),
|
|
4060
|
-
integrations: __privateMethod(this, _buildJobIntegrations, buildJobIntegrations_fn).call(this, job2),
|
|
4061
|
-
startPosition: "latest",
|
|
4062
|
-
enabled: job2.enabled,
|
|
4063
|
-
preprocessRuns: job2.trigger.preprocessRuns,
|
|
4064
|
-
internal,
|
|
4065
|
-
concurrencyLimit: typeof job2.options.concurrencyLimit === "number" ? job2.options.concurrencyLimit : typeof job2.options.concurrencyLimit === "object" ? {
|
|
4066
|
-
id: job2.options.concurrencyLimit.id,
|
|
4067
|
-
limit: job2.options.concurrencyLimit.limit
|
|
4068
|
-
} : void 0
|
|
4069
|
-
};
|
|
4070
|
-
}, "#buildJobIndex");
|
|
4071
|
-
_buildJobIntegrations = new WeakSet();
|
|
4072
|
-
buildJobIntegrations_fn = /* @__PURE__ */ __name(function(job3) {
|
|
4073
|
-
return Object.keys(job3.options.integrations ?? {}).reduce((acc, key) => {
|
|
4074
|
-
const integration = job3.options.integrations[key];
|
|
4075
|
-
acc[key] = __privateMethod(this, _buildJobIntegration, buildJobIntegration_fn).call(this, integration);
|
|
4076
|
-
return acc;
|
|
4077
|
-
}, {});
|
|
4078
|
-
}, "#buildJobIntegrations");
|
|
4079
|
-
_buildJobIntegration = new WeakSet();
|
|
4080
|
-
buildJobIntegration_fn = /* @__PURE__ */ __name(function(integration1) {
|
|
4081
|
-
const authSource = __privateGet(this, _authResolvers)[integration1.id] ? "RESOLVER" : integration1.authSource;
|
|
4082
|
-
return {
|
|
4083
|
-
id: integration1.id,
|
|
4084
|
-
metadata: integration1.metadata,
|
|
4085
|
-
authSource
|
|
4086
|
-
};
|
|
4087
|
-
}, "#buildJobIntegration");
|
|
4088
|
-
_logIOStats = new WeakSet();
|
|
4089
|
-
logIOStats_fn = /* @__PURE__ */ __name(function(stats) {
|
|
4090
|
-
__privateGet(this, _internalLogger).debug("IO stats", {
|
|
4091
|
-
stats
|
|
4092
|
-
});
|
|
4093
|
-
}, "#logIOStats");
|
|
4094
|
-
_standardResponseHeaders = new WeakSet();
|
|
4095
|
-
standardResponseHeaders_fn = /* @__PURE__ */ __name(function(start) {
|
|
4096
|
-
return {
|
|
4097
|
-
"Trigger-Version": import_core8.API_VERSIONS.LAZY_LOADED_CACHED_TASKS,
|
|
4098
|
-
"Trigger-SDK-Version": version,
|
|
4099
|
-
"X-Trigger-Request-Timing": `dur=${performance.now() - start / 1e3}`
|
|
4100
|
-
};
|
|
4101
|
-
}, "#standardResponseHeaders");
|
|
4102
|
-
_serializeRunMetadata = new WeakSet();
|
|
4103
|
-
serializeRunMetadata_fn = /* @__PURE__ */ __name(function(job4) {
|
|
4104
|
-
const metadata = {};
|
|
4105
|
-
if (__privateGet(this, _eventEmitter).listenerCount("runSucceeeded") > 0 || typeof job4.options.onSuccess === "function") {
|
|
4106
|
-
metadata["successSubscription"] = true;
|
|
4107
|
-
}
|
|
4108
|
-
if (__privateGet(this, _eventEmitter).listenerCount("runFailed") > 0 || typeof job4.options.onFailure === "function") {
|
|
4109
|
-
metadata["failedSubscription"] = true;
|
|
4110
|
-
}
|
|
4111
|
-
return JSON.stringify(metadata);
|
|
4112
|
-
}, "#serializeRunMetadata");
|
|
4113
|
-
_deliverSuccessfulRunNotification = new WeakSet();
|
|
4114
|
-
deliverSuccessfulRunNotification_fn = /* @__PURE__ */ __name(async function(notification) {
|
|
4115
|
-
__privateGet(this, _internalLogger).debug("delivering successful run notification", {
|
|
4116
|
-
notification
|
|
4117
|
-
});
|
|
4118
|
-
__privateGet(this, _eventEmitter).emit("runSucceeeded", notification);
|
|
4119
|
-
const job = __privateGet(this, _registeredJobs)[notification.job.id];
|
|
4120
|
-
if (!job) {
|
|
4121
|
-
return;
|
|
4122
|
-
}
|
|
4123
|
-
if (typeof job.options.onSuccess === "function") {
|
|
4124
|
-
await job.options.onSuccess(notification);
|
|
4125
|
-
}
|
|
4126
|
-
}, "#deliverSuccessfulRunNotification");
|
|
4127
|
-
_deliverFailedRunNotification = new WeakSet();
|
|
4128
|
-
deliverFailedRunNotification_fn = /* @__PURE__ */ __name(async function(notification1) {
|
|
4129
|
-
__privateGet(this, _internalLogger).debug("delivering failed run notification", {
|
|
4130
|
-
notification: notification1
|
|
4131
|
-
});
|
|
4132
|
-
__privateGet(this, _eventEmitter).emit("runFailed", notification1);
|
|
4133
|
-
const job = __privateGet(this, _registeredJobs)[notification1.job.id];
|
|
4134
|
-
if (!job) {
|
|
4135
|
-
return;
|
|
4136
|
-
}
|
|
4137
|
-
if (typeof job.options.onFailure === "function") {
|
|
4138
|
-
await job.options.onFailure(notification1);
|
|
4139
|
-
}
|
|
4140
|
-
}, "#deliverFailedRunNotification");
|
|
4141
|
-
function dynamicTriggerRegisterSourceJobId(id) {
|
|
4142
|
-
return `register-dynamic-trigger-${id}`;
|
|
4143
|
-
}
|
|
4144
|
-
__name(dynamicTriggerRegisterSourceJobId, "dynamicTriggerRegisterSourceJobId");
|
|
4145
|
-
function deepMergeOptions(obj1, obj2) {
|
|
4146
|
-
const mergedOptions = {
|
|
4147
|
-
...obj1
|
|
4148
|
-
};
|
|
4149
|
-
for (const key in obj2) {
|
|
4150
|
-
if (obj2.hasOwnProperty(key)) {
|
|
4151
|
-
if (key in mergedOptions) {
|
|
4152
|
-
mergedOptions[key] = [
|
|
4153
|
-
...mergedOptions[key],
|
|
4154
|
-
...obj2[key]
|
|
4155
|
-
];
|
|
4156
|
-
} else {
|
|
4157
|
-
mergedOptions[key] = obj2[key];
|
|
4158
|
-
}
|
|
4159
|
-
}
|
|
4160
|
-
}
|
|
4161
|
-
return mergedOptions;
|
|
4162
|
-
}
|
|
4163
|
-
__name(deepMergeOptions, "deepMergeOptions");
|
|
4164
|
-
|
|
4165
|
-
// src/triggers/externalSource.ts
|
|
4166
|
-
var import_core9 = require("@trigger.dev/core");
|
|
4167
|
-
var ExternalSource = class {
|
|
4168
|
-
constructor(channel, options) {
|
|
4169
|
-
this.options = options;
|
|
4170
|
-
this.channel = channel;
|
|
4171
|
-
}
|
|
4172
|
-
async handle(source, rawEvent, logger) {
|
|
4173
|
-
return this.options.handler({
|
|
4174
|
-
source: {
|
|
4175
|
-
...source,
|
|
4176
|
-
params: source.params
|
|
4177
|
-
},
|
|
4178
|
-
rawEvent
|
|
4179
|
-
}, logger, this.options.integration);
|
|
4180
|
-
}
|
|
4181
|
-
filter(params, options) {
|
|
4182
|
-
return this.options.filter?.(params, options) ?? {};
|
|
4183
|
-
}
|
|
4184
|
-
properties(params) {
|
|
4185
|
-
return this.options.properties?.(params) ?? [];
|
|
4186
|
-
}
|
|
4187
|
-
async register(params, registerEvent, io, ctx) {
|
|
4188
|
-
const { result: event, ommited: source } = omit(registerEvent, "source");
|
|
4189
|
-
const { result: sourceWithoutChannel, ommited: channel } = omit(source, "channel");
|
|
4190
|
-
const { result: channelWithoutType } = omit(channel, "type");
|
|
4191
|
-
const updates = await this.options.register({
|
|
4192
|
-
...event,
|
|
4193
|
-
source: {
|
|
4194
|
-
...sourceWithoutChannel,
|
|
4195
|
-
...channelWithoutType
|
|
4196
|
-
},
|
|
4197
|
-
params
|
|
4198
|
-
}, io, ctx);
|
|
4199
|
-
return updates;
|
|
4200
|
-
}
|
|
4201
|
-
key(params) {
|
|
4202
|
-
const parts = [
|
|
4203
|
-
this.options.id,
|
|
4204
|
-
this.channel
|
|
4205
|
-
];
|
|
4206
|
-
parts.push(this.options.key(params));
|
|
4207
|
-
parts.push(this.integration.id);
|
|
4208
|
-
return parts.join("-");
|
|
4209
|
-
}
|
|
4210
|
-
get integration() {
|
|
4211
|
-
return this.options.integration;
|
|
4212
|
-
}
|
|
4213
|
-
get integrationConfig() {
|
|
4214
|
-
return {
|
|
4215
|
-
id: this.integration.id,
|
|
4216
|
-
metadata: this.integration.metadata
|
|
4217
|
-
};
|
|
4218
|
-
}
|
|
4219
|
-
get id() {
|
|
4220
|
-
return this.options.id;
|
|
4221
|
-
}
|
|
4222
|
-
get version() {
|
|
4223
|
-
return this.options.version;
|
|
4224
|
-
}
|
|
4225
|
-
};
|
|
4226
|
-
__name(ExternalSource, "ExternalSource");
|
|
4227
|
-
var ExternalSourceTrigger = class {
|
|
4228
|
-
constructor(options) {
|
|
4229
|
-
this.options = options;
|
|
4230
|
-
}
|
|
4231
|
-
get event() {
|
|
4232
|
-
return this.options.event;
|
|
4233
|
-
}
|
|
4234
|
-
toJSON() {
|
|
4235
|
-
return {
|
|
4236
|
-
type: "static",
|
|
4237
|
-
title: "External Source",
|
|
4238
|
-
rule: {
|
|
4239
|
-
event: this.event.name,
|
|
4240
|
-
payload: (0, import_core9.deepMergeFilters)(this.options.source.filter(this.options.params, this.options.options), this.event.filter ?? {}, this.options.params.filter ?? {}),
|
|
4241
|
-
source: this.event.source
|
|
4242
|
-
},
|
|
4243
|
-
properties: this.options.source.properties(this.options.params)
|
|
4244
|
-
};
|
|
4245
|
-
}
|
|
4246
|
-
attachToJob(triggerClient, job) {
|
|
4247
|
-
triggerClient.attachSource({
|
|
4248
|
-
key: slugifyId(this.options.source.key(this.options.params)),
|
|
4249
|
-
source: this.options.source,
|
|
4250
|
-
event: this.options.event,
|
|
4251
|
-
params: this.options.params,
|
|
4252
|
-
options: this.options.options
|
|
4253
|
-
});
|
|
4254
|
-
}
|
|
4255
|
-
get preprocessRuns() {
|
|
4256
|
-
return true;
|
|
4257
|
-
}
|
|
4258
|
-
async verifyPayload(payload) {
|
|
4259
|
-
return {
|
|
4260
|
-
success: true
|
|
4261
|
-
};
|
|
4262
|
-
}
|
|
4263
|
-
};
|
|
4264
|
-
__name(ExternalSourceTrigger, "ExternalSourceTrigger");
|
|
4265
|
-
function omit(obj, key) {
|
|
4266
|
-
const result = {};
|
|
4267
|
-
for (const k of Object.keys(obj)) {
|
|
4268
|
-
if (k === key)
|
|
4269
|
-
continue;
|
|
4270
|
-
result[k] = obj[k];
|
|
4271
|
-
}
|
|
4272
|
-
return {
|
|
4273
|
-
result,
|
|
4274
|
-
ommited: obj[key]
|
|
4275
|
-
};
|
|
4276
|
-
}
|
|
4277
|
-
__name(omit, "omit");
|
|
4278
|
-
|
|
4279
|
-
// src/triggers/notifications.ts
|
|
4280
|
-
var import_core10 = require("@trigger.dev/core");
|
|
4281
|
-
function missingConnectionNotification(integrations) {
|
|
4282
|
-
return new MissingConnectionNotification({
|
|
4283
|
-
integrations
|
|
4284
|
-
});
|
|
4285
|
-
}
|
|
4286
|
-
__name(missingConnectionNotification, "missingConnectionNotification");
|
|
4287
|
-
function missingConnectionResolvedNotification(integrations) {
|
|
4288
|
-
return new MissingConnectionResolvedNotification({
|
|
4289
|
-
integrations
|
|
4290
|
-
});
|
|
4291
|
-
}
|
|
4292
|
-
__name(missingConnectionResolvedNotification, "missingConnectionResolvedNotification");
|
|
4293
|
-
var MissingConnectionNotification = class {
|
|
4294
|
-
constructor(options) {
|
|
4295
|
-
this.options = options;
|
|
4296
|
-
}
|
|
4297
|
-
get event() {
|
|
4298
|
-
return {
|
|
4299
|
-
name: import_core10.MISSING_CONNECTION_NOTIFICATION,
|
|
4300
|
-
title: "Missing Connection Notification",
|
|
4301
|
-
source: "trigger.dev",
|
|
4302
|
-
icon: "connection-alert",
|
|
4303
|
-
parsePayload: import_core10.MissingConnectionNotificationPayloadSchema.parse,
|
|
4304
|
-
properties: [
|
|
4305
|
-
{
|
|
4306
|
-
label: "Integrations",
|
|
4307
|
-
text: this.options.integrations.map((i) => i.id).join(", ")
|
|
4308
|
-
}
|
|
4309
|
-
]
|
|
4310
|
-
};
|
|
4311
|
-
}
|
|
4312
|
-
attachToJob(triggerClient, job) {
|
|
4313
|
-
}
|
|
4314
|
-
get preprocessRuns() {
|
|
4315
|
-
return false;
|
|
4316
|
-
}
|
|
4317
|
-
async verifyPayload(payload) {
|
|
4318
|
-
return {
|
|
4319
|
-
success: true
|
|
4320
|
-
};
|
|
4321
|
-
}
|
|
4322
|
-
toJSON() {
|
|
4323
|
-
return {
|
|
4324
|
-
type: "static",
|
|
4325
|
-
title: this.event.title,
|
|
4326
|
-
rule: {
|
|
4327
|
-
event: this.event.name,
|
|
4328
|
-
source: "trigger.dev",
|
|
4329
|
-
payload: {
|
|
4330
|
-
client: {
|
|
4331
|
-
id: this.options.integrations.map((i) => i.id)
|
|
4332
|
-
}
|
|
4333
|
-
}
|
|
4334
|
-
}
|
|
4335
|
-
};
|
|
4336
|
-
}
|
|
4337
|
-
};
|
|
4338
|
-
__name(MissingConnectionNotification, "MissingConnectionNotification");
|
|
4339
|
-
var MissingConnectionResolvedNotification = class {
|
|
4340
|
-
constructor(options) {
|
|
4341
|
-
this.options = options;
|
|
4342
|
-
}
|
|
4343
|
-
get event() {
|
|
4344
|
-
return {
|
|
4345
|
-
name: import_core10.MISSING_CONNECTION_RESOLVED_NOTIFICATION,
|
|
4346
|
-
title: "Missing Connection Resolved Notification",
|
|
4347
|
-
source: "trigger.dev",
|
|
4348
|
-
icon: "connection-alert",
|
|
4349
|
-
parsePayload: import_core10.MissingConnectionResolvedNotificationPayloadSchema.parse,
|
|
4350
|
-
properties: [
|
|
4351
|
-
{
|
|
4352
|
-
label: "Integrations",
|
|
4353
|
-
text: this.options.integrations.map((i) => i.id).join(", ")
|
|
4354
|
-
}
|
|
4355
|
-
]
|
|
4356
|
-
};
|
|
4357
|
-
}
|
|
4358
|
-
attachToJob(triggerClient, job) {
|
|
4359
|
-
}
|
|
4360
|
-
get preprocessRuns() {
|
|
4361
|
-
return false;
|
|
4362
|
-
}
|
|
4363
|
-
async verifyPayload(payload) {
|
|
4364
|
-
return {
|
|
4365
|
-
success: true
|
|
4366
|
-
};
|
|
4367
|
-
}
|
|
4368
|
-
toJSON() {
|
|
4369
|
-
return {
|
|
4370
|
-
type: "static",
|
|
4371
|
-
title: this.event.title,
|
|
4372
|
-
rule: {
|
|
4373
|
-
event: this.event.name,
|
|
4374
|
-
source: "trigger.dev",
|
|
4375
|
-
payload: {
|
|
4376
|
-
client: {
|
|
4377
|
-
id: this.options.integrations.map((i) => i.id)
|
|
4378
|
-
}
|
|
4379
|
-
}
|
|
4380
|
-
}
|
|
4381
|
-
};
|
|
4382
|
-
}
|
|
4383
|
-
};
|
|
4384
|
-
__name(MissingConnectionResolvedNotification, "MissingConnectionResolvedNotification");
|
|
4385
|
-
|
|
4386
|
-
// src/triggers/invokeTrigger.ts
|
|
4387
|
-
var _options5;
|
|
4388
|
-
var InvokeTrigger = class {
|
|
4389
|
-
constructor(options) {
|
|
4390
|
-
__privateAdd(this, _options5, void 0);
|
|
4391
|
-
__privateSet(this, _options5, options);
|
|
4392
|
-
}
|
|
4393
|
-
toJSON() {
|
|
4394
|
-
return {
|
|
4395
|
-
type: "invoke"
|
|
4396
|
-
};
|
|
4397
|
-
}
|
|
4398
|
-
get event() {
|
|
4399
|
-
return {
|
|
4400
|
-
name: "invoke",
|
|
4401
|
-
title: "Manual Invoke",
|
|
4402
|
-
source: "trigger.dev",
|
|
4403
|
-
examples: __privateGet(this, _options5).examples ?? [],
|
|
4404
|
-
icon: "trigger",
|
|
4405
|
-
parsePayload: (rawPayload) => {
|
|
4406
|
-
if (__privateGet(this, _options5).schema) {
|
|
4407
|
-
const results = __privateGet(this, _options5).schema.safeParse(rawPayload);
|
|
4408
|
-
if (!results.success) {
|
|
4409
|
-
throw new ParsedPayloadSchemaError(formatSchemaErrors(results.error.issues));
|
|
4410
|
-
}
|
|
4411
|
-
return results.data;
|
|
4412
|
-
}
|
|
4413
|
-
return rawPayload;
|
|
4414
|
-
},
|
|
4415
|
-
parseInvokePayload: (rawPayload) => {
|
|
4416
|
-
if (__privateGet(this, _options5).schema) {
|
|
4417
|
-
const results = __privateGet(this, _options5).schema.safeParse(rawPayload);
|
|
4418
|
-
if (!results.success) {
|
|
4419
|
-
throw new ParsedPayloadSchemaError(formatSchemaErrors(results.error.issues));
|
|
4420
|
-
}
|
|
4421
|
-
return results.data;
|
|
4422
|
-
}
|
|
4423
|
-
return rawPayload;
|
|
4424
|
-
}
|
|
4425
|
-
};
|
|
4426
|
-
}
|
|
4427
|
-
attachToJob(triggerClient, job) {
|
|
4428
|
-
}
|
|
4429
|
-
get preprocessRuns() {
|
|
4430
|
-
return false;
|
|
4431
|
-
}
|
|
4432
|
-
async verifyPayload() {
|
|
4433
|
-
return {
|
|
4434
|
-
success: true
|
|
4435
|
-
};
|
|
4436
|
-
}
|
|
4437
|
-
};
|
|
4438
|
-
__name(InvokeTrigger, "InvokeTrigger");
|
|
4439
|
-
_options5 = new WeakMap();
|
|
4440
|
-
function invokeTrigger(options) {
|
|
4441
|
-
return new InvokeTrigger(options ?? {});
|
|
4442
|
-
}
|
|
4443
|
-
__name(invokeTrigger, "invokeTrigger");
|
|
4444
|
-
|
|
4445
|
-
// src/triggers/webhook.ts
|
|
4446
|
-
var import_core11 = require("@trigger.dev/core");
|
|
4447
|
-
var import_node_crypto2 = require("crypto");
|
|
4448
|
-
var _shortHash, shortHash_fn;
|
|
4449
|
-
var WebhookSource = class {
|
|
4450
|
-
constructor(options) {
|
|
4451
|
-
__privateAdd(this, _shortHash);
|
|
4452
|
-
this.options = options;
|
|
4453
|
-
}
|
|
4454
|
-
async generateEvents(request, client, ctx) {
|
|
4455
|
-
return this.options.generateEvents({
|
|
4456
|
-
request,
|
|
4457
|
-
client,
|
|
4458
|
-
ctx
|
|
4459
|
-
});
|
|
4460
|
-
}
|
|
4461
|
-
filter(params, config) {
|
|
4462
|
-
return this.options.filter?.(params, config) ?? {};
|
|
4463
|
-
}
|
|
4464
|
-
properties(params) {
|
|
4465
|
-
return this.options.properties?.(params) ?? [];
|
|
4466
|
-
}
|
|
4467
|
-
get crud() {
|
|
4468
|
-
return this.options.crud;
|
|
4469
|
-
}
|
|
4470
|
-
async register(params, registerEvent, io, ctx) {
|
|
4471
|
-
if (!this.options.register) {
|
|
4472
|
-
return;
|
|
4473
|
-
}
|
|
4474
|
-
const updates = await this.options.register({
|
|
4475
|
-
...registerEvent,
|
|
4476
|
-
params
|
|
4477
|
-
}, io, ctx);
|
|
4478
|
-
return updates;
|
|
4479
|
-
}
|
|
4480
|
-
async verify(request, client, ctx) {
|
|
4481
|
-
if (this.options.verify) {
|
|
4482
|
-
const clonedRequest = request.clone();
|
|
4483
|
-
return this.options.verify({
|
|
4484
|
-
request: clonedRequest,
|
|
4485
|
-
client,
|
|
4486
|
-
ctx
|
|
4487
|
-
});
|
|
4488
|
-
}
|
|
4489
|
-
return {
|
|
4490
|
-
success: true
|
|
4491
|
-
};
|
|
4492
|
-
}
|
|
4493
|
-
key(params) {
|
|
4494
|
-
const parts = [
|
|
4495
|
-
"webhook"
|
|
4496
|
-
];
|
|
4497
|
-
parts.push(this.options.key(params));
|
|
4498
|
-
parts.push(this.integration.id);
|
|
4499
|
-
return `${this.options.id}-${__privateMethod(this, _shortHash, shortHash_fn).call(this, parts.join(""))}`;
|
|
4500
|
-
}
|
|
4501
|
-
get integration() {
|
|
4502
|
-
return this.options.integration;
|
|
4503
|
-
}
|
|
4504
|
-
get integrationConfig() {
|
|
4505
|
-
return {
|
|
4506
|
-
id: this.integration.id,
|
|
4507
|
-
metadata: this.integration.metadata
|
|
4508
|
-
};
|
|
4509
|
-
}
|
|
4510
|
-
get id() {
|
|
4511
|
-
return this.options.id;
|
|
4512
|
-
}
|
|
4513
|
-
get version() {
|
|
4514
|
-
return this.options.version;
|
|
4515
|
-
}
|
|
4516
|
-
};
|
|
4517
|
-
__name(WebhookSource, "WebhookSource");
|
|
4518
|
-
_shortHash = new WeakSet();
|
|
4519
|
-
shortHash_fn = /* @__PURE__ */ __name(function(str) {
|
|
4520
|
-
const hash = (0, import_node_crypto2.createHash)("sha1").update(str).digest("hex");
|
|
4521
|
-
return hash.slice(0, 7);
|
|
4522
|
-
}, "#shortHash");
|
|
4523
|
-
var WebhookTrigger = class {
|
|
4524
|
-
constructor(options) {
|
|
4525
|
-
this.options = options;
|
|
4526
|
-
}
|
|
4527
|
-
get event() {
|
|
4528
|
-
return this.options.event;
|
|
4529
|
-
}
|
|
4530
|
-
get source() {
|
|
4531
|
-
return this.options.source;
|
|
4532
|
-
}
|
|
4533
|
-
get key() {
|
|
4534
|
-
return slugifyId(this.options.source.key(this.options.params));
|
|
4535
|
-
}
|
|
4536
|
-
toJSON() {
|
|
4537
|
-
return {
|
|
4538
|
-
type: "static",
|
|
4539
|
-
title: "Webhook",
|
|
4540
|
-
rule: {
|
|
4541
|
-
event: this.event.name,
|
|
4542
|
-
payload: (0, import_core11.deepMergeFilters)(this.options.source.filter(this.options.params, this.options.config), this.event.filter ?? {}),
|
|
4543
|
-
source: this.event.source
|
|
4544
|
-
},
|
|
4545
|
-
properties: this.options.source.properties(this.options.params),
|
|
4546
|
-
link: `http-endpoints/${this.key}`
|
|
4547
|
-
};
|
|
4548
|
-
}
|
|
4549
|
-
filter(eventFilter) {
|
|
4550
|
-
const { event, ...optionsWithoutEvent } = this.options;
|
|
4551
|
-
const { filter, ...eventWithoutFilter } = event;
|
|
4552
|
-
return new WebhookTrigger({
|
|
4553
|
-
...optionsWithoutEvent,
|
|
4554
|
-
event: {
|
|
4555
|
-
...eventWithoutFilter,
|
|
4556
|
-
filter: (0, import_core11.deepMergeFilters)(filter ?? {}, eventFilter)
|
|
4557
|
-
}
|
|
4558
|
-
});
|
|
4559
|
-
}
|
|
4560
|
-
attachToJob(triggerClient, job) {
|
|
4561
|
-
triggerClient.defineHttpEndpoint({
|
|
4562
|
-
id: this.key,
|
|
4563
|
-
source: "trigger.dev",
|
|
4564
|
-
icon: this.event.icon,
|
|
4565
|
-
verify: async () => ({
|
|
4566
|
-
success: true
|
|
4567
|
-
})
|
|
4568
|
-
}, true);
|
|
4569
|
-
triggerClient.attachWebhook({
|
|
4570
|
-
key: this.key,
|
|
4571
|
-
source: this.options.source,
|
|
4572
|
-
event: this.options.event,
|
|
4573
|
-
params: this.options.params,
|
|
4574
|
-
config: this.options.config
|
|
4575
|
-
});
|
|
4576
|
-
}
|
|
4577
|
-
get preprocessRuns() {
|
|
4578
|
-
return true;
|
|
4579
|
-
}
|
|
4580
|
-
async verifyPayload(payload) {
|
|
4581
|
-
return {
|
|
4582
|
-
success: true
|
|
4583
|
-
};
|
|
4584
|
-
}
|
|
4585
|
-
};
|
|
4586
|
-
__name(WebhookTrigger, "WebhookTrigger");
|
|
4587
|
-
|
|
4588
|
-
// src/security.ts
|
|
4589
|
-
var import_crypto = __toESM(require("crypto"));
|
|
4590
|
-
async function verifyRequestSignature({ request, headerName, headerEncoding = "hex", secret, algorithm }) {
|
|
4591
|
-
if (!secret) {
|
|
4592
|
-
return {
|
|
4593
|
-
success: false,
|
|
4594
|
-
reason: "Missing secret \u2013 you've probably not set an environment variable."
|
|
4595
|
-
};
|
|
4596
|
-
}
|
|
4597
|
-
const headerValue = request.headers.get(headerName);
|
|
4598
|
-
if (!headerValue) {
|
|
4599
|
-
return {
|
|
4600
|
-
success: false,
|
|
4601
|
-
reason: "Missing header"
|
|
4602
|
-
};
|
|
4603
|
-
}
|
|
4604
|
-
switch (algorithm) {
|
|
4605
|
-
case "sha256":
|
|
4606
|
-
const success = verifyHmacSha256(headerValue, headerEncoding, secret, await request.text());
|
|
4607
|
-
if (success) {
|
|
4608
|
-
return {
|
|
4609
|
-
success
|
|
4610
|
-
};
|
|
4611
|
-
} else {
|
|
4612
|
-
return {
|
|
4613
|
-
success: false,
|
|
4614
|
-
reason: "Failed sha256 verification"
|
|
4615
|
-
};
|
|
4616
|
-
}
|
|
4617
|
-
default:
|
|
4618
|
-
throw new Error(`Unsupported algorithm: ${algorithm}`);
|
|
4619
|
-
}
|
|
4620
|
-
}
|
|
4621
|
-
__name(verifyRequestSignature, "verifyRequestSignature");
|
|
4622
|
-
function verifyHmacSha256(headerValue, headerEncoding, secret, body) {
|
|
4623
|
-
const bodyDigest = import_crypto.default.createHmac("sha256", secret).update(body).digest(headerEncoding);
|
|
4624
|
-
const signature = headerValue?.replace("hmac-sha256=", "").replace("sha256=", "") ?? "";
|
|
4625
|
-
return signature === bodyDigest;
|
|
4626
|
-
}
|
|
4627
|
-
__name(verifyHmacSha256, "verifyHmacSha256");
|
|
4628
|
-
|
|
4629
|
-
// src/index.ts
|
|
4630
|
-
function redactString(strings, ...interpolations) {
|
|
4631
|
-
return {
|
|
4632
|
-
__redactedString: true,
|
|
4633
|
-
strings: strings.raw,
|
|
4634
|
-
interpolations
|
|
4635
|
-
};
|
|
4636
|
-
}
|
|
4637
|
-
__name(redactString, "redactString");
|
|
4638
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
4639
|
-
0 && (module.exports = {
|
|
4640
|
-
CronTrigger,
|
|
4641
|
-
DynamicSchedule,
|
|
4642
|
-
DynamicTrigger,
|
|
4643
|
-
EventSpecificationExampleSchema,
|
|
4644
|
-
EventTrigger,
|
|
4645
|
-
ExternalSource,
|
|
4646
|
-
ExternalSourceTrigger,
|
|
4647
|
-
IO,
|
|
4648
|
-
IOLogger,
|
|
4649
|
-
IntervalTrigger,
|
|
4650
|
-
InvokeTrigger,
|
|
4651
|
-
JSONOutputSerializer,
|
|
4652
|
-
Job,
|
|
4653
|
-
MissingConnectionNotification,
|
|
4654
|
-
MissingConnectionResolvedNotification,
|
|
4655
|
-
TriggerClient,
|
|
4656
|
-
WebhookSource,
|
|
4657
|
-
WebhookTrigger,
|
|
4658
|
-
cronTrigger,
|
|
4659
|
-
eventTrigger,
|
|
4660
|
-
intervalTrigger,
|
|
4661
|
-
invokeTrigger,
|
|
4662
|
-
isTriggerError,
|
|
4663
|
-
missingConnectionNotification,
|
|
4664
|
-
missingConnectionResolvedNotification,
|
|
4665
|
-
omit,
|
|
4666
|
-
redactString,
|
|
4667
|
-
retry,
|
|
4668
|
-
slugifyId,
|
|
4669
|
-
verifyHmacSha256,
|
|
4670
|
-
verifyRequestSignature,
|
|
4671
|
-
waitForEventSchema
|
|
4672
|
-
});
|
|
4673
|
-
//# sourceMappingURL=index.js.map
|