@trigger.dev/sdk 2.0.0-next.4 → 2.0.0-next.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +184 -21
- package/dist/index.js +97 -64
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
9
|
var __export = (target, all) => {
|
|
@@ -16,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
18
|
}
|
|
17
19
|
return to;
|
|
18
20
|
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
19
25
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
26
|
var __accessCheck = (obj, member, msg) => {
|
|
21
27
|
if (!member.has(obj))
|
|
@@ -112,6 +118,9 @@ var Job = class {
|
|
|
112
118
|
return acc;
|
|
113
119
|
}, {});
|
|
114
120
|
}
|
|
121
|
+
get logLevel() {
|
|
122
|
+
return this.options.logLevel;
|
|
123
|
+
}
|
|
115
124
|
toJSON() {
|
|
116
125
|
const internal = this.options.__internal;
|
|
117
126
|
return {
|
|
@@ -160,6 +169,9 @@ var _Logger = class {
|
|
|
160
169
|
filter(...keys) {
|
|
161
170
|
return new _Logger(__privateGet(this, _name), logLevels[__privateGet(this, _level)], keys, __privateGet(this, _jsonReplacer));
|
|
162
171
|
}
|
|
172
|
+
static satisfiesLogLevel(logLevel, setLevel) {
|
|
173
|
+
return logLevels.indexOf(logLevel) <= logLevels.indexOf(setLevel);
|
|
174
|
+
}
|
|
163
175
|
log(...args) {
|
|
164
176
|
if (__privateGet(this, _level) < 0)
|
|
165
177
|
return;
|
|
@@ -605,12 +617,12 @@ var IndexEndpointResponseSchema = import_zod9.z.object({
|
|
|
605
617
|
dynamicSchedules: import_zod9.z.array(RegisterDynamicSchedulePayloadSchema)
|
|
606
618
|
});
|
|
607
619
|
var RawEventSchema = import_zod9.z.object({
|
|
608
|
-
id: import_zod9.z.string().default(() => (0, import_ulid.ulid)()),
|
|
609
620
|
name: import_zod9.z.string(),
|
|
610
|
-
source: import_zod9.z.string().optional(),
|
|
611
621
|
payload: import_zod9.z.any(),
|
|
612
622
|
context: import_zod9.z.any().optional(),
|
|
613
|
-
|
|
623
|
+
id: import_zod9.z.string().default(() => (0, import_ulid.ulid)()),
|
|
624
|
+
timestamp: import_zod9.z.coerce.date().optional(),
|
|
625
|
+
source: import_zod9.z.string().optional()
|
|
614
626
|
});
|
|
615
627
|
var ApiEventLogSchema = import_zod9.z.object({
|
|
616
628
|
id: import_zod9.z.string(),
|
|
@@ -622,7 +634,7 @@ var ApiEventLogSchema = import_zod9.z.object({
|
|
|
622
634
|
deliveredAt: import_zod9.z.coerce.date().optional().nullable()
|
|
623
635
|
});
|
|
624
636
|
var SendEventOptionsSchema = import_zod9.z.object({
|
|
625
|
-
deliverAt: import_zod9.z.
|
|
637
|
+
deliverAt: import_zod9.z.coerce.date().optional(),
|
|
626
638
|
deliverAfter: import_zod9.z.number().int().optional(),
|
|
627
639
|
accountId: import_zod9.z.string().optional()
|
|
628
640
|
});
|
|
@@ -1335,6 +1347,8 @@ var IO = class {
|
|
|
1335
1347
|
this._triggerClient = options.client;
|
|
1336
1348
|
this._logger = options.logger ?? new Logger("trigger.dev", options.logLevel);
|
|
1337
1349
|
this._cachedTasks = /* @__PURE__ */ new Map();
|
|
1350
|
+
this._jobLogger = options.jobLogger;
|
|
1351
|
+
this._jobLogLevel = options.jobLogLevel;
|
|
1338
1352
|
if (options.cachedTasks) {
|
|
1339
1353
|
options.cachedTasks.forEach((task) => {
|
|
1340
1354
|
this._cachedTasks.set(task.id, task);
|
|
@@ -1345,45 +1359,57 @@ var IO = class {
|
|
|
1345
1359
|
}
|
|
1346
1360
|
get logger() {
|
|
1347
1361
|
return new IOLogger(async (level, message, data) => {
|
|
1362
|
+
let logLevel = "info";
|
|
1348
1363
|
switch (level) {
|
|
1364
|
+
case "LOG": {
|
|
1365
|
+
this._jobLogger?.log(message, data);
|
|
1366
|
+
logLevel = "log";
|
|
1367
|
+
break;
|
|
1368
|
+
}
|
|
1349
1369
|
case "DEBUG": {
|
|
1350
|
-
this.
|
|
1370
|
+
this._jobLogger?.debug(message, data);
|
|
1371
|
+
logLevel = "debug";
|
|
1351
1372
|
break;
|
|
1352
1373
|
}
|
|
1353
1374
|
case "INFO": {
|
|
1354
|
-
this.
|
|
1375
|
+
this._jobLogger?.info(message, data);
|
|
1376
|
+
logLevel = "info";
|
|
1355
1377
|
break;
|
|
1356
1378
|
}
|
|
1357
1379
|
case "WARN": {
|
|
1358
|
-
this.
|
|
1380
|
+
this._jobLogger?.warn(message, data);
|
|
1381
|
+
logLevel = "warn";
|
|
1359
1382
|
break;
|
|
1360
1383
|
}
|
|
1361
1384
|
case "ERROR": {
|
|
1362
|
-
this.
|
|
1385
|
+
this._jobLogger?.error(message, data);
|
|
1386
|
+
logLevel = "error";
|
|
1363
1387
|
break;
|
|
1364
1388
|
}
|
|
1365
1389
|
}
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
style:
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1390
|
+
if (Logger.satisfiesLogLevel(logLevel, this._jobLogLevel)) {
|
|
1391
|
+
await this.runTask([
|
|
1392
|
+
message,
|
|
1393
|
+
level
|
|
1394
|
+
], {
|
|
1395
|
+
name: "log",
|
|
1396
|
+
icon: "log",
|
|
1397
|
+
description: message,
|
|
1398
|
+
params: data,
|
|
1399
|
+
properties: [
|
|
1400
|
+
{
|
|
1401
|
+
label: "Level",
|
|
1402
|
+
text: level
|
|
1403
|
+
}
|
|
1404
|
+
],
|
|
1405
|
+
style: {
|
|
1406
|
+
style: "minimal",
|
|
1407
|
+
variant: level.toLowerCase()
|
|
1408
|
+
},
|
|
1409
|
+
noop: true
|
|
1410
|
+
}, async (task) => {
|
|
1411
|
+
});
|
|
1412
|
+
}
|
|
1387
1413
|
});
|
|
1388
1414
|
}
|
|
1389
1415
|
async wait(key, seconds) {
|
|
@@ -1438,7 +1464,19 @@ var IO = class {
|
|
|
1438
1464
|
params: {
|
|
1439
1465
|
event,
|
|
1440
1466
|
options
|
|
1441
|
-
}
|
|
1467
|
+
},
|
|
1468
|
+
properties: [
|
|
1469
|
+
{
|
|
1470
|
+
label: "name",
|
|
1471
|
+
text: event.name
|
|
1472
|
+
},
|
|
1473
|
+
...event?.id ? [
|
|
1474
|
+
{
|
|
1475
|
+
label: "ID",
|
|
1476
|
+
text: event.id
|
|
1477
|
+
}
|
|
1478
|
+
] : []
|
|
1479
|
+
]
|
|
1442
1480
|
}, async (task) => {
|
|
1443
1481
|
return await this._triggerClient.sendEvent(event, options);
|
|
1444
1482
|
});
|
|
@@ -1758,6 +1796,9 @@ var IOLogger = class {
|
|
|
1758
1796
|
constructor(callback) {
|
|
1759
1797
|
this.callback = callback;
|
|
1760
1798
|
}
|
|
1799
|
+
log(message, properties) {
|
|
1800
|
+
return this.callback("LOG", message, properties);
|
|
1801
|
+
}
|
|
1761
1802
|
debug(message, properties) {
|
|
1762
1803
|
return this.callback("DEBUG", message, properties);
|
|
1763
1804
|
}
|
|
@@ -1830,7 +1871,7 @@ var registerSourceEvent = {
|
|
|
1830
1871
|
icon: "register-source",
|
|
1831
1872
|
parsePayload: RegisterSourceEventSchema.parse
|
|
1832
1873
|
};
|
|
1833
|
-
var _options3, _registeredJobs, _registeredSources, _registeredHttpSourceHandlers, _registeredDynamicTriggers, _jobMetadataByDynamicTriggers, _registeredSchedules, _client,
|
|
1874
|
+
var _options3, _registeredJobs, _registeredSources, _registeredHttpSourceHandlers, _registeredDynamicTriggers, _jobMetadataByDynamicTriggers, _registeredSchedules, _client, _internalLogger, _preprocessRun, preprocessRun_fn, _executeJob, executeJob_fn, _createRunContext, createRunContext_fn, _createPreprocessRunContext, createPreprocessRunContext_fn, _handleHttpSourceRequest, handleHttpSourceRequest_fn;
|
|
1834
1875
|
var TriggerClient = class {
|
|
1835
1876
|
constructor(options) {
|
|
1836
1877
|
__privateAdd(this, _preprocessRun);
|
|
@@ -1846,18 +1887,14 @@ var TriggerClient = class {
|
|
|
1846
1887
|
__privateAdd(this, _jobMetadataByDynamicTriggers, {});
|
|
1847
1888
|
__privateAdd(this, _registeredSchedules, {});
|
|
1848
1889
|
__privateAdd(this, _client, void 0);
|
|
1849
|
-
__privateAdd(this,
|
|
1890
|
+
__privateAdd(this, _internalLogger, void 0);
|
|
1850
1891
|
this.id = options.id;
|
|
1851
|
-
this._url = buildClientUrl(options.url);
|
|
1852
1892
|
__privateSet(this, _options3, options);
|
|
1853
1893
|
__privateSet(this, _client, new ApiClient(__privateGet(this, _options3)));
|
|
1854
|
-
__privateSet(this,
|
|
1855
|
-
}
|
|
1856
|
-
get url() {
|
|
1857
|
-
return `${this._url}${this.path ? `${this.path.startsWith("/") ? "" : "/"}${this.path}` : ""}`;
|
|
1894
|
+
__privateSet(this, _internalLogger, new Logger("trigger.dev", __privateGet(this, _options3).verbose ? "debug" : "log"));
|
|
1858
1895
|
}
|
|
1859
1896
|
async handleRequest(request) {
|
|
1860
|
-
__privateGet(this,
|
|
1897
|
+
__privateGet(this, _internalLogger).debug("handling request", {
|
|
1861
1898
|
url: request.url,
|
|
1862
1899
|
headers: Object.fromEntries(request.headers.entries()),
|
|
1863
1900
|
method: request.method
|
|
@@ -1918,7 +1955,7 @@ var TriggerClient = class {
|
|
|
1918
1955
|
status: 200,
|
|
1919
1956
|
body: {
|
|
1920
1957
|
ok: false,
|
|
1921
|
-
|
|
1958
|
+
error: "Missing endpoint ID"
|
|
1922
1959
|
}
|
|
1923
1960
|
};
|
|
1924
1961
|
}
|
|
@@ -1927,7 +1964,7 @@ var TriggerClient = class {
|
|
|
1927
1964
|
status: 200,
|
|
1928
1965
|
body: {
|
|
1929
1966
|
ok: false,
|
|
1930
|
-
|
|
1967
|
+
error: `Endpoint ID mismatch error. Expected ${this.id}, got ${endpointId}`
|
|
1931
1968
|
}
|
|
1932
1969
|
};
|
|
1933
1970
|
}
|
|
@@ -2143,7 +2180,7 @@ var TriggerClient = class {
|
|
|
2143
2180
|
}
|
|
2144
2181
|
attachSource(options) {
|
|
2145
2182
|
__privateGet(this, _registeredHttpSourceHandlers)[options.key] = async (s, r) => {
|
|
2146
|
-
return await options.source.handle(s, r, __privateGet(this,
|
|
2183
|
+
return await options.source.handle(s, r, __privateGet(this, _internalLogger));
|
|
2147
2184
|
};
|
|
2148
2185
|
let registeredSource = __privateGet(this, _registeredSources)[options.key];
|
|
2149
2186
|
if (!registeredSource) {
|
|
@@ -2245,7 +2282,7 @@ _registeredDynamicTriggers = new WeakMap();
|
|
|
2245
2282
|
_jobMetadataByDynamicTriggers = new WeakMap();
|
|
2246
2283
|
_registeredSchedules = new WeakMap();
|
|
2247
2284
|
_client = new WeakMap();
|
|
2248
|
-
|
|
2285
|
+
_internalLogger = new WeakMap();
|
|
2249
2286
|
_preprocessRun = new WeakSet();
|
|
2250
2287
|
preprocessRun_fn = /* @__PURE__ */ __name(async function(body, job) {
|
|
2251
2288
|
const context = __privateMethod(this, _createPreprocessRunContext, createPreprocessRunContext_fn).call(this, body);
|
|
@@ -2258,7 +2295,7 @@ preprocessRun_fn = /* @__PURE__ */ __name(async function(body, job) {
|
|
|
2258
2295
|
}, "#preprocessRun");
|
|
2259
2296
|
_executeJob = new WeakSet();
|
|
2260
2297
|
executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
|
|
2261
|
-
__privateGet(this,
|
|
2298
|
+
__privateGet(this, _internalLogger).debug("executing job", {
|
|
2262
2299
|
execution: body1,
|
|
2263
2300
|
job: job1.toJSON()
|
|
2264
2301
|
});
|
|
@@ -2267,9 +2304,11 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
|
|
|
2267
2304
|
id: body1.run.id,
|
|
2268
2305
|
cachedTasks: body1.tasks,
|
|
2269
2306
|
apiClient: __privateGet(this, _client),
|
|
2270
|
-
logger: __privateGet(this,
|
|
2307
|
+
logger: __privateGet(this, _internalLogger),
|
|
2271
2308
|
client: this,
|
|
2272
|
-
context
|
|
2309
|
+
context,
|
|
2310
|
+
jobLogLevel: job1.logLevel ?? __privateGet(this, _options3).logLevel ?? "info",
|
|
2311
|
+
jobLogger: __privateGet(this, _options3).ioLogLocalEnabled ? new Logger(job1.id, job1.logLevel ?? __privateGet(this, _options3).logLevel ?? "info") : void 0
|
|
2273
2312
|
});
|
|
2274
2313
|
const ioWithConnections = createIOWithIntegrations(io, body1.connections, job1.options.integrations);
|
|
2275
2314
|
try {
|
|
@@ -2362,13 +2401,13 @@ createPreprocessRunContext_fn = /* @__PURE__ */ __name(function(body2) {
|
|
|
2362
2401
|
}, "#createPreprocessRunContext");
|
|
2363
2402
|
_handleHttpSourceRequest = new WeakSet();
|
|
2364
2403
|
handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourceRequest) {
|
|
2365
|
-
__privateGet(this,
|
|
2404
|
+
__privateGet(this, _internalLogger).debug("Handling HTTP source request", {
|
|
2366
2405
|
source
|
|
2367
2406
|
});
|
|
2368
2407
|
if (source.dynamicId) {
|
|
2369
2408
|
const dynamicTrigger = __privateGet(this, _registeredDynamicTriggers)[source.dynamicId];
|
|
2370
2409
|
if (!dynamicTrigger) {
|
|
2371
|
-
__privateGet(this,
|
|
2410
|
+
__privateGet(this, _internalLogger).debug("No dynamic trigger registered for HTTP source", {
|
|
2372
2411
|
source
|
|
2373
2412
|
});
|
|
2374
2413
|
return {
|
|
@@ -2381,7 +2420,7 @@ handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourc
|
|
|
2381
2420
|
events: []
|
|
2382
2421
|
};
|
|
2383
2422
|
}
|
|
2384
|
-
const results2 = await dynamicTrigger.source.handle(source, sourceRequest, __privateGet(this,
|
|
2423
|
+
const results2 = await dynamicTrigger.source.handle(source, sourceRequest, __privateGet(this, _internalLogger));
|
|
2385
2424
|
if (!results2) {
|
|
2386
2425
|
return {
|
|
2387
2426
|
events: [],
|
|
@@ -2405,7 +2444,7 @@ handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourc
|
|
|
2405
2444
|
}
|
|
2406
2445
|
const handler = __privateGet(this, _registeredHttpSourceHandlers)[source.key];
|
|
2407
2446
|
if (!handler) {
|
|
2408
|
-
__privateGet(this,
|
|
2447
|
+
__privateGet(this, _internalLogger).debug("No handler registered for HTTP source", {
|
|
2409
2448
|
source
|
|
2410
2449
|
});
|
|
2411
2450
|
return {
|
|
@@ -2440,20 +2479,6 @@ handleHttpSourceRequest_fn = /* @__PURE__ */ __name(async function(source, sourc
|
|
|
2440
2479
|
}
|
|
2441
2480
|
};
|
|
2442
2481
|
}, "#handleHttpSourceRequest");
|
|
2443
|
-
function buildClientUrl(url) {
|
|
2444
|
-
if (!url) {
|
|
2445
|
-
const host = process.env.TRIGGER_CLIENT_HOST ?? process.env.HOST ?? process.env.HOSTNAME ?? process.env.NOW_URL ?? process.env.VERCEL_URL;
|
|
2446
|
-
if (host) {
|
|
2447
|
-
return "https://" + host;
|
|
2448
|
-
}
|
|
2449
|
-
throw new Error("Could not determine the url for this TriggerClient. Please set the TRIGGER_CLIENT_HOST environment variable or pass in the `url` option to the TriggerClient constructor.");
|
|
2450
|
-
}
|
|
2451
|
-
if (!url.startsWith("http")) {
|
|
2452
|
-
return "https://" + url;
|
|
2453
|
-
}
|
|
2454
|
-
return url;
|
|
2455
|
-
}
|
|
2456
|
-
__name(buildClientUrl, "buildClientUrl");
|
|
2457
2482
|
|
|
2458
2483
|
// src/integrations.ts
|
|
2459
2484
|
function authenticatedTask(options) {
|
|
@@ -2628,6 +2653,7 @@ _client2 = new WeakMap();
|
|
|
2628
2653
|
_options4 = new WeakMap();
|
|
2629
2654
|
|
|
2630
2655
|
// src/triggers/scheduled.ts
|
|
2656
|
+
var import_cronstrue = __toESM(require("cronstrue"));
|
|
2631
2657
|
var examples = [
|
|
2632
2658
|
{
|
|
2633
2659
|
id: "now",
|
|
@@ -2686,6 +2712,9 @@ var CronTrigger = class {
|
|
|
2686
2712
|
this.options = options;
|
|
2687
2713
|
}
|
|
2688
2714
|
get event() {
|
|
2715
|
+
const humanReadable = import_cronstrue.default.toString(this.options.cron, {
|
|
2716
|
+
throwExceptionOnParseError: false
|
|
2717
|
+
});
|
|
2689
2718
|
return {
|
|
2690
2719
|
name: "trigger.scheduled",
|
|
2691
2720
|
title: "Cron Schedule",
|
|
@@ -2695,8 +2724,12 @@ var CronTrigger = class {
|
|
|
2695
2724
|
parsePayload: ScheduledPayloadSchema.parse,
|
|
2696
2725
|
properties: [
|
|
2697
2726
|
{
|
|
2698
|
-
label: "
|
|
2727
|
+
label: "cron",
|
|
2699
2728
|
text: this.options.cron
|
|
2729
|
+
},
|
|
2730
|
+
{
|
|
2731
|
+
label: "Schedule",
|
|
2732
|
+
text: humanReadable
|
|
2700
2733
|
}
|
|
2701
2734
|
]
|
|
2702
2735
|
};
|