@trigger.dev/core 4.5.7 → 4.5.9
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/logger.d.ts +1 -0
- package/dist/commonjs/logger.js +101 -29
- package/dist/commonjs/logger.js.map +1 -1
- package/dist/commonjs/v3/apiClient/index.d.ts +22 -3
- package/dist/commonjs/v3/apiClient/index.js +73 -4
- package/dist/commonjs/v3/apiClient/index.js.map +1 -1
- package/dist/commonjs/v3/apiKeys.d.ts +7 -0
- package/dist/commonjs/v3/apiKeys.js +14 -0
- package/dist/commonjs/v3/apiKeys.js.map +1 -0
- package/dist/commonjs/v3/apiKeys.test.d.ts +1 -0
- package/dist/commonjs/v3/apiKeys.test.js +19 -0
- package/dist/commonjs/v3/apiKeys.test.js.map +1 -0
- package/dist/commonjs/v3/index.d.ts +1 -0
- package/dist/commonjs/v3/index.js +1 -0
- package/dist/commonjs/v3/index.js.map +1 -1
- package/dist/commonjs/v3/jwt.d.ts +2 -0
- package/dist/commonjs/v3/jwt.js +32 -0
- package/dist/commonjs/v3/jwt.js.map +1 -1
- package/dist/commonjs/v3/runEngineWorker/supervisor/http.d.ts +18 -15
- package/dist/commonjs/v3/runEngineWorker/supervisor/http.js +53 -12
- package/dist/commonjs/v3/runEngineWorker/supervisor/http.js.map +1 -1
- package/dist/commonjs/v3/runEngineWorker/supervisor/schemas.d.ts +24 -24
- package/dist/commonjs/v3/runEngineWorker/supervisor/types.d.ts +8 -0
- package/dist/commonjs/v3/runEngineWorker/workload/http.d.ts +2 -2
- package/dist/commonjs/v3/runEngineWorker/workload/schemas.d.ts +20 -20
- package/dist/commonjs/v3/schemas/api.d.ts +18 -18
- package/dist/commonjs/v3/schemas/checkpoints.d.ts +4 -4
- package/dist/commonjs/v3/schemas/common.d.ts +8 -8
- package/dist/commonjs/v3/schemas/messages.d.ts +8 -8
- package/dist/commonjs/v3/schemas/runEngine.d.ts +10 -10
- package/dist/commonjs/v3/utils/structuredLogger.js +3 -2
- package/dist/commonjs/v3/utils/structuredLogger.js.map +1 -1
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/logger.d.ts +1 -0
- package/dist/esm/logger.js +100 -29
- package/dist/esm/logger.js.map +1 -1
- package/dist/esm/v3/apiClient/index.d.ts +22 -3
- package/dist/esm/v3/apiClient/index.js +73 -4
- package/dist/esm/v3/apiClient/index.js.map +1 -1
- package/dist/esm/v3/apiKeys.d.ts +7 -0
- package/dist/esm/v3/apiKeys.js +11 -0
- package/dist/esm/v3/apiKeys.js.map +1 -0
- package/dist/esm/v3/apiKeys.test.d.ts +1 -0
- package/dist/esm/v3/apiKeys.test.js +17 -0
- package/dist/esm/v3/apiKeys.test.js.map +1 -0
- package/dist/esm/v3/index.d.ts +1 -0
- package/dist/esm/v3/index.js +1 -0
- package/dist/esm/v3/index.js.map +1 -1
- package/dist/esm/v3/jwt.d.ts +2 -0
- package/dist/esm/v3/jwt.js +30 -0
- package/dist/esm/v3/jwt.js.map +1 -1
- package/dist/esm/v3/runEngineWorker/supervisor/http.d.ts +18 -15
- package/dist/esm/v3/runEngineWorker/supervisor/http.js +53 -12
- package/dist/esm/v3/runEngineWorker/supervisor/http.js.map +1 -1
- package/dist/esm/v3/runEngineWorker/supervisor/schemas.d.ts +24 -24
- package/dist/esm/v3/runEngineWorker/supervisor/types.d.ts +8 -0
- package/dist/esm/v3/runEngineWorker/workload/http.d.ts +2 -2
- package/dist/esm/v3/runEngineWorker/workload/schemas.d.ts +20 -20
- package/dist/esm/v3/schemas/api.d.ts +18 -18
- package/dist/esm/v3/schemas/checkpoints.d.ts +4 -4
- package/dist/esm/v3/schemas/common.d.ts +8 -8
- package/dist/esm/v3/schemas/messages.d.ts +8 -8
- package/dist/esm/v3/schemas/runEngine.d.ts +10 -10
- package/dist/esm/v3/utils/structuredLogger.js +3 -2
- package/dist/esm/v3/utils/structuredLogger.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +1 -1
|
@@ -14,3 +14,4 @@ export declare class Logger {
|
|
|
14
14
|
debug(message: string, ...args: Array<Record<string, unknown> | undefined>): void;
|
|
15
15
|
verbose(message: string, ...args: Array<Record<string, unknown> | undefined>): void;
|
|
16
16
|
}
|
|
17
|
+
export declare function redact(value: unknown, filteredKeys?: string[]): unknown;
|
package/dist/commonjs/logger.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var _a;
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.Logger = void 0;
|
|
6
|
+
exports.redact = redact;
|
|
6
7
|
/**
|
|
7
8
|
* Represents different log levels.
|
|
8
9
|
* - `"log"`: Only essential messages.
|
|
@@ -15,10 +16,47 @@ const node_process_1 = require("node:process");
|
|
|
15
16
|
const node_buffer_1 = require("node:buffer");
|
|
16
17
|
const api_1 = require("@opentelemetry/api");
|
|
17
18
|
const logLevels = ["log", "error", "warn", "info", "debug", "verbose"];
|
|
19
|
+
// Applied to every Logger instance, on top of whatever a caller passes in as `filteredKeys`.
|
|
20
|
+
// Keeps the previous "opt-in, per-instance" list from being the only thing standing between a
|
|
21
|
+
// logged object and a credential or piece of customer content that happens to share its name.
|
|
22
|
+
const DEFAULT_FILTERED_KEYS = [
|
|
23
|
+
"authorization",
|
|
24
|
+
"token",
|
|
25
|
+
"apikey",
|
|
26
|
+
"secretkey",
|
|
27
|
+
"accesstoken",
|
|
28
|
+
"refreshtoken",
|
|
29
|
+
"password",
|
|
30
|
+
"jwt",
|
|
31
|
+
"payload",
|
|
32
|
+
"output",
|
|
33
|
+
"metadata",
|
|
34
|
+
"seedmetadata",
|
|
35
|
+
"input",
|
|
36
|
+
"email",
|
|
37
|
+
"headers",
|
|
38
|
+
"completedwaitpoints",
|
|
39
|
+
];
|
|
40
|
+
// Belt-and-braces value-shape check: catches secrets anywhere in values that land under a field
|
|
41
|
+
// name we didn't think to deny-list (a trigger.dev API key, bearer token, or OpenAI-style key).
|
|
42
|
+
const SECRET_VALUE_PATTERN = /(tr_[a-zA-Z0-9_-]{4,}|sk-[a-zA-Z0-9_-]{4,}|Bearer\s+\S+)/;
|
|
43
|
+
// Per-field and per-structure caps so a single unbounded object (a run payload, a batch of
|
|
44
|
+
// items, a DB row) can't blow up log line size or CPU. Truncation keeps the field present and
|
|
45
|
+
// queryable rather than dropping it.
|
|
46
|
+
const MAX_STRING_LENGTH = 8192;
|
|
47
|
+
const MAX_ARRAY_LENGTH = 100;
|
|
48
|
+
const MAX_DEPTH = 10;
|
|
49
|
+
function buildFilteredKeySet(filteredKeys) {
|
|
50
|
+
const set = new Set(DEFAULT_FILTERED_KEYS);
|
|
51
|
+
for (const key of filteredKeys) {
|
|
52
|
+
set.add(key.toLowerCase());
|
|
53
|
+
}
|
|
54
|
+
return set;
|
|
55
|
+
}
|
|
18
56
|
class Logger {
|
|
19
57
|
#name;
|
|
20
58
|
#level;
|
|
21
|
-
#filteredKeys =
|
|
59
|
+
#filteredKeys = new Set(DEFAULT_FILTERED_KEYS);
|
|
22
60
|
#jsonReplacer;
|
|
23
61
|
#additionalFields;
|
|
24
62
|
// Add a static "onError" method that will be called when an error is logged
|
|
@@ -29,12 +67,12 @@ class Logger {
|
|
|
29
67
|
constructor(name, level = "info", filteredKeys = [], jsonReplacer, additionalFields) {
|
|
30
68
|
this.#name = name;
|
|
31
69
|
this.#level = logLevels.indexOf((node_process_1.env.TRIGGER_LOG_LEVEL ?? level));
|
|
32
|
-
this.#filteredKeys = filteredKeys;
|
|
70
|
+
this.#filteredKeys = buildFilteredKeySet(filteredKeys);
|
|
33
71
|
this.#jsonReplacer = createReplacer(jsonReplacer);
|
|
34
72
|
this.#additionalFields = additionalFields ?? (() => ({}));
|
|
35
73
|
}
|
|
36
74
|
child(fields) {
|
|
37
|
-
return new _a(this.#name, logLevels[this.#level], this.#filteredKeys, this.#jsonReplacer, () => ({ ...this.#additionalFields(), ...fields }));
|
|
75
|
+
return new _a(this.#name, logLevels[this.#level], Array.from(this.#filteredKeys), this.#jsonReplacer, () => ({ ...this.#additionalFields(), ...fields }));
|
|
38
76
|
}
|
|
39
77
|
// Return a new Logger instance with the same name and a new log level
|
|
40
78
|
// but filter out the keys from the log messages (at any level)
|
|
@@ -81,8 +119,8 @@ class Logger {
|
|
|
81
119
|
#structuredLog(loggerFunction, message, level, ...args) {
|
|
82
120
|
// Get the current context from trace if it exists
|
|
83
121
|
const currentSpan = api_1.trace.getSpan(api_1.context.active());
|
|
84
|
-
const structuredError = extractStructuredErrorFromArgs(...args);
|
|
85
|
-
const structuredMessage = extractStructuredMessageFromArgs(...args);
|
|
122
|
+
const structuredError = extractStructuredErrorFromArgs(this.#filteredKeys, ...args);
|
|
123
|
+
const structuredMessage = extractStructuredMessageFromArgs(this.#filteredKeys, ...args);
|
|
86
124
|
const structuredLog = {
|
|
87
125
|
...structureArgs(safeJsonClone(args), this.#filteredKeys),
|
|
88
126
|
...this.#additionalFields(),
|
|
@@ -115,32 +153,36 @@ _a = Logger;
|
|
|
115
153
|
// Detect if args is an error object
|
|
116
154
|
// Or if args contains an error object at the "error" key
|
|
117
155
|
// In both cases, return the error object as a structured error
|
|
118
|
-
|
|
156
|
+
// Run every field through the same filter/truncation used for the rest of the log line, so an
|
|
157
|
+
// error's message/stack/metadata (which can embed request or row data verbatim) gets the same
|
|
158
|
+
// treatment as everything else, instead of bypassing it.
|
|
159
|
+
function extractStructuredErrorFromArgs(filteredKeys, ...args) {
|
|
119
160
|
const error = args.find((arg) => arg instanceof Error);
|
|
120
161
|
if (error) {
|
|
121
162
|
return {
|
|
122
|
-
message: error.message,
|
|
123
|
-
stack: error.stack,
|
|
163
|
+
message: filterKeys(error.message, filteredKeys),
|
|
164
|
+
stack: filterKeys(error.stack, filteredKeys),
|
|
124
165
|
name: error.name,
|
|
125
|
-
metadata: "metadata" in error ? error.metadata : undefined,
|
|
166
|
+
metadata: "metadata" in error ? filterKeys(error.metadata, filteredKeys) : undefined,
|
|
126
167
|
};
|
|
127
168
|
}
|
|
128
169
|
const structuredError = args.find((arg) => arg?.error);
|
|
129
170
|
if (structuredError && structuredError.error instanceof Error) {
|
|
171
|
+
const nestedError = structuredError.error;
|
|
130
172
|
return {
|
|
131
|
-
message:
|
|
132
|
-
stack:
|
|
133
|
-
name:
|
|
134
|
-
metadata: "metadata" in
|
|
173
|
+
message: filterKeys(nestedError.message, filteredKeys),
|
|
174
|
+
stack: filterKeys(nestedError.stack, filteredKeys),
|
|
175
|
+
name: nestedError.name,
|
|
176
|
+
metadata: "metadata" in nestedError ? filterKeys(nestedError.metadata, filteredKeys) : undefined,
|
|
135
177
|
};
|
|
136
178
|
}
|
|
137
179
|
return;
|
|
138
180
|
}
|
|
139
|
-
function extractStructuredMessageFromArgs(...args) {
|
|
181
|
+
function extractStructuredMessageFromArgs(filteredKeys, ...args) {
|
|
140
182
|
// Check to see if there is a `message` key in the args, and if so, return it
|
|
141
183
|
const structuredMessage = args.find((arg) => arg?.message);
|
|
142
184
|
if (structuredMessage) {
|
|
143
|
-
return structuredMessage.message;
|
|
185
|
+
return filterKeys(structuredMessage.message, filteredKeys);
|
|
144
186
|
}
|
|
145
187
|
return;
|
|
146
188
|
}
|
|
@@ -170,30 +212,48 @@ function safeJsonClone(obj) {
|
|
|
170
212
|
return;
|
|
171
213
|
}
|
|
172
214
|
}
|
|
173
|
-
//
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
215
|
+
// `args` has already been through safeJsonClone, so this only has to filter/truncate it, not
|
|
216
|
+
// clone it again. If there's exactly one arg, return it directly (unwrapped) so it can be spread
|
|
217
|
+
// onto the structured log; otherwise filter every arg and return the array. Filtering runs
|
|
218
|
+
// regardless of arg count, so a multi-arg call gets the same redaction as the common single-arg
|
|
219
|
+
// case.
|
|
220
|
+
function structureArgs(args, filteredKeys = new Set()) {
|
|
221
|
+
if (!args || args.length === 0) {
|
|
179
222
|
return;
|
|
180
223
|
}
|
|
181
|
-
|
|
182
|
-
|
|
224
|
+
const filteredArgs = args.map((arg) => filterKeys(arg, filteredKeys));
|
|
225
|
+
if (filteredArgs.length === 1) {
|
|
226
|
+
return filteredArgs[0];
|
|
183
227
|
}
|
|
184
|
-
return
|
|
228
|
+
return filteredArgs;
|
|
185
229
|
}
|
|
186
|
-
// Recursively filter out keys from an object, including nested objects
|
|
187
|
-
|
|
230
|
+
// Recursively filter out keys from an object, including nested objects and arrays. Also caps
|
|
231
|
+
// string length, array length and recursion depth, and redacts string values that look like a
|
|
232
|
+
// secret regardless of which key they were found under.
|
|
233
|
+
function filterKeys(obj, keys, depth = 0) {
|
|
234
|
+
if (typeof obj === "string") {
|
|
235
|
+
if (SECRET_VALUE_PATTERN.test(obj)) {
|
|
236
|
+
return `[filtered ${prettyPrintBytes(obj)}]`;
|
|
237
|
+
}
|
|
238
|
+
return truncateString(obj);
|
|
239
|
+
}
|
|
188
240
|
if (typeof obj !== "object" || obj === null) {
|
|
189
241
|
return obj;
|
|
190
242
|
}
|
|
243
|
+
if (depth >= MAX_DEPTH) {
|
|
244
|
+
return "[max depth exceeded]";
|
|
245
|
+
}
|
|
191
246
|
if (Array.isArray(obj)) {
|
|
192
|
-
|
|
247
|
+
const isTruncated = obj.length > MAX_ARRAY_LENGTH;
|
|
248
|
+
const items = (isTruncated ? obj.slice(0, MAX_ARRAY_LENGTH) : obj).map((item) => filterKeys(item, keys, depth + 1));
|
|
249
|
+
if (isTruncated) {
|
|
250
|
+
items.push(`[truncated ${obj.length - MAX_ARRAY_LENGTH} more items]`);
|
|
251
|
+
}
|
|
252
|
+
return items;
|
|
193
253
|
}
|
|
194
254
|
const filteredObj = {};
|
|
195
255
|
for (const [key, value] of Object.entries(obj)) {
|
|
196
|
-
if (keys.
|
|
256
|
+
if (keys.has(key.toLowerCase())) {
|
|
197
257
|
if (value) {
|
|
198
258
|
filteredObj[key] = `[filtered ${prettyPrintBytes(value)}]`;
|
|
199
259
|
}
|
|
@@ -202,10 +262,22 @@ function filterKeys(obj, keys) {
|
|
|
202
262
|
}
|
|
203
263
|
continue;
|
|
204
264
|
}
|
|
205
|
-
filteredObj[key] = filterKeys(value, keys);
|
|
265
|
+
filteredObj[key] = filterKeys(value, keys, depth + 1);
|
|
206
266
|
}
|
|
207
267
|
return filteredObj;
|
|
208
268
|
}
|
|
269
|
+
function truncateString(value) {
|
|
270
|
+
if (value.length <= MAX_STRING_LENGTH) {
|
|
271
|
+
return value;
|
|
272
|
+
}
|
|
273
|
+
return `${value.slice(0, MAX_STRING_LENGTH)}...[truncated ${value.length - MAX_STRING_LENGTH} chars]`;
|
|
274
|
+
}
|
|
275
|
+
// Runs a value through the same default-deny-list + truncation pipeline every Logger applies to
|
|
276
|
+
// its own log lines. For destinations that receive log arguments through a side channel (e.g. an
|
|
277
|
+
// error reporting `onError` hook) rather than through `Logger#structuredLog` itself.
|
|
278
|
+
function redact(value, filteredKeys = []) {
|
|
279
|
+
return filterKeys(value, buildFilteredKeySet(filteredKeys));
|
|
280
|
+
}
|
|
209
281
|
function prettyPrintBytes(value) {
|
|
210
282
|
if (node_process_1.env.NODE_ENV === "production") {
|
|
211
283
|
return "skipped size";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":";AAAA,+DAA+D;;;;
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":";AAAA,+DAA+D;;;;AA8W/D,wBAEC;AA9WD;;;;;;;GAOG;AACH,+CAAmC;AACnC,6CAAqC;AACrC,4CAAoD;AAIpD,MAAM,SAAS,GAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;AAExF,6FAA6F;AAC7F,8FAA8F;AAC9F,8FAA8F;AAC9F,MAAM,qBAAqB,GAAG;IAC5B,eAAe;IACf,OAAO;IACP,QAAQ;IACR,WAAW;IACX,aAAa;IACb,cAAc;IACd,UAAU;IACV,KAAK;I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AAK,EAAE,mBAAmB,CAAC,YAAY,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAc;IACtC,IAAI,kBAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;QAClC,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,MAAM,WAAW,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IAE1C,IAAI,WAAW,GAAG,IAAI,EAAE,CAAC;QACvB,OAAO,GAAG,WAAW,QAAQ,CAAC;IAChC,CAAC;IAED,IAAI,WAAW,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC;QAC9B,OAAO,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;IACjD,CAAC;IAED,IAAI,WAAW,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC;QACrC,OAAO,GAAG,CAAC,WAAW,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;IAC1D,CAAC;IAED,OAAO,GAAG,CAAC,WAAW,GAAG,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;AACjE,CAAC;AAED,SAAS,cAAc,CAAC,KAAc;IACpC,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAEzC,OAAO,oBAAM,CAAC,UAAU,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -34,6 +34,14 @@ export type ApiClientFutureFlags = {
|
|
|
34
34
|
export { SSEStreamSubscription, isRequestOptions };
|
|
35
35
|
export type { AnyRealtimeRun, AnyRunShape, ApiRequestOptions, RealtimeRun, RunShape, RunStreamCallback, RunSubscription, SSEStreamPart, TaskRunShape, };
|
|
36
36
|
export * from "./getBranch.js";
|
|
37
|
+
export type CreatePublicTokenRequestBody = {
|
|
38
|
+
scopes: string[];
|
|
39
|
+
expirationTime?: string | number;
|
|
40
|
+
oneTimeUse?: boolean;
|
|
41
|
+
realtime?: {
|
|
42
|
+
skipColumns?: string[];
|
|
43
|
+
};
|
|
44
|
+
};
|
|
37
45
|
/**
|
|
38
46
|
* Trigger.dev v3 API client
|
|
39
47
|
*/
|
|
@@ -240,12 +248,12 @@ export declare class ApiClient {
|
|
|
240
248
|
name?: string | undefined;
|
|
241
249
|
stackTrace?: string | undefined;
|
|
242
250
|
} | undefined;
|
|
251
|
+
output?: any;
|
|
243
252
|
metadata?: Record<string, any> | undefined;
|
|
244
253
|
startedAt?: Date | undefined;
|
|
245
254
|
idempotencyKey?: string | undefined;
|
|
246
255
|
version?: string | undefined;
|
|
247
256
|
region?: string | undefined;
|
|
248
|
-
output?: any;
|
|
249
257
|
ttl?: string | undefined;
|
|
250
258
|
schedule?: {
|
|
251
259
|
id: string;
|
|
@@ -491,12 +499,12 @@ export declare class ApiClient {
|
|
|
491
499
|
name?: string | undefined;
|
|
492
500
|
stackTrace?: string | undefined;
|
|
493
501
|
} | undefined;
|
|
502
|
+
output?: any;
|
|
494
503
|
metadata?: Record<string, any> | undefined;
|
|
495
504
|
startedAt?: Date | undefined;
|
|
496
505
|
idempotencyKey?: string | undefined;
|
|
497
506
|
version?: string | undefined;
|
|
498
507
|
region?: string | undefined;
|
|
499
|
-
output?: any;
|
|
500
508
|
ttl?: string | undefined;
|
|
501
509
|
schedule?: {
|
|
502
510
|
id: string;
|
|
@@ -887,8 +895,8 @@ export declare class ApiClient {
|
|
|
887
895
|
records: {
|
|
888
896
|
id: string;
|
|
889
897
|
seqNum: number;
|
|
890
|
-
data?: unknown;
|
|
891
898
|
headers?: [string, string][] | undefined;
|
|
899
|
+
data?: unknown;
|
|
892
900
|
}[];
|
|
893
901
|
}>;
|
|
894
902
|
/**
|
|
@@ -1165,6 +1173,9 @@ export declare class ApiClient {
|
|
|
1165
1173
|
waitpointId: string;
|
|
1166
1174
|
}>;
|
|
1167
1175
|
generateJWTClaims(requestOptions?: ZodFetchOptions): Promise<Record<string, any>>;
|
|
1176
|
+
createPublicToken(body: CreatePublicTokenRequestBody, requestOptions?: ZodFetchOptions): Promise<{
|
|
1177
|
+
token: string;
|
|
1178
|
+
}>;
|
|
1168
1179
|
retrieveBatch(batchId: string, requestOptions?: ZodFetchOptions): ApiPromise<{
|
|
1169
1180
|
status: "COMPLETED" | "PENDING" | "ABORTED" | "PROCESSING" | "PARTIAL_FAILED";
|
|
1170
1181
|
id: string;
|
|
@@ -1192,6 +1203,14 @@ export declare class ApiClient {
|
|
|
1192
1203
|
}, requestOptions?: ZodFetchOptions): Promise<QueryExecuteResponseBody>;
|
|
1193
1204
|
getQuerySchema(requestOptions?: ZodFetchOptions): Promise<QuerySchemaResponseBody>;
|
|
1194
1205
|
listDashboards(requestOptions?: ZodFetchOptions): Promise<ListDashboardsResponseBody>;
|
|
1206
|
+
/**
|
|
1207
|
+
* Fetch a server-rendered report (text + sparkline). Thin pass-through — the string
|
|
1208
|
+
* is ready to display. `format`: "markdown" (default, agents/chat) or "ansi" (terminal).
|
|
1209
|
+
*/
|
|
1210
|
+
getReport(key: string, options?: {
|
|
1211
|
+
period?: string;
|
|
1212
|
+
format?: "markdown" | "ansi";
|
|
1213
|
+
}): Promise<string>;
|
|
1195
1214
|
resolvePrompt(slug: string, body: ResolvePromptRequestBody, requestOptions?: ZodFetchOptions): ApiPromise<{
|
|
1196
1215
|
data: {
|
|
1197
1216
|
version: number;
|
|
@@ -19,6 +19,7 @@ exports.mergeRequestOptions = mergeRequestOptions;
|
|
|
19
19
|
const nanoid_1 = require("nanoid");
|
|
20
20
|
const zod_1 = require("zod");
|
|
21
21
|
const version_js_1 = require("../../version.js");
|
|
22
|
+
const apiKeys_js_1 = require("../apiKeys.js");
|
|
22
23
|
const jwt_js_1 = require("../jwt.js");
|
|
23
24
|
const index_js_1 = require("../schemas/index.js");
|
|
24
25
|
const wireProtocol_js_1 = require("../sessionStreams/wireProtocol.js");
|
|
@@ -41,6 +42,7 @@ const DEFAULT_ZOD_FETCH_OPTIONS = {
|
|
|
41
42
|
},
|
|
42
43
|
};
|
|
43
44
|
__exportStar(require("./getBranch.js"), exports);
|
|
45
|
+
const CreatePublicTokenResponseBody = zod_1.z.object({ token: zod_1.z.string() });
|
|
44
46
|
/**
|
|
45
47
|
* Trigger.dev v3 API client
|
|
46
48
|
*/
|
|
@@ -63,6 +65,17 @@ class ApiClient {
|
|
|
63
65
|
this.defaultRequestOptions = mergeRequestOptions(DEFAULT_ZOD_FETCH_OPTIONS, restRequestOptions);
|
|
64
66
|
this.futureFlags = futureFlags;
|
|
65
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Key for signing a public access token locally. Only root keys can do this —
|
|
70
|
+
* an additional key isn't the environment's signing material, so a token
|
|
71
|
+
* signed with one would never verify. Throw rather than return a dead token.
|
|
72
|
+
*/
|
|
73
|
+
get #selfSigningKey() {
|
|
74
|
+
if ((0, apiKeys_js_1.isAdditionalApiKey)(this.accessToken)) {
|
|
75
|
+
throw new Error("This additional API key cannot self-sign public tokens, and the server did not return one. Upgrade the server or use the root API key.");
|
|
76
|
+
}
|
|
77
|
+
return this.accessToken;
|
|
78
|
+
}
|
|
66
79
|
get fetchClient() {
|
|
67
80
|
const headers = this.#getHeaders(false);
|
|
68
81
|
const fetchClient = (input, requestInit) => {
|
|
@@ -121,7 +134,7 @@ class ApiClient {
|
|
|
121
134
|
const claimsHeader = response.headers.get("x-trigger-jwt-claims");
|
|
122
135
|
const claims = claimsHeader ? JSON.parse(claimsHeader) : undefined;
|
|
123
136
|
const jwt = await (0, jwt_js_1.generateJWT)({
|
|
124
|
-
secretKey: this
|
|
137
|
+
secretKey: this.#selfSigningKey,
|
|
125
138
|
payload: {
|
|
126
139
|
...claims,
|
|
127
140
|
scopes: [`read:runs:${data.id}`],
|
|
@@ -144,10 +157,17 @@ class ApiClient {
|
|
|
144
157
|
}, mergeRequestOptions(this.defaultRequestOptions, requestOptions))
|
|
145
158
|
.withResponse()
|
|
146
159
|
.then(async ({ data, response }) => {
|
|
160
|
+
const jwtHeader = response.headers.get("x-trigger-jwt");
|
|
161
|
+
if (typeof jwtHeader === "string") {
|
|
162
|
+
return {
|
|
163
|
+
...data,
|
|
164
|
+
publicAccessToken: jwtHeader,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
147
167
|
const claimsHeader = response.headers.get("x-trigger-jwt-claims");
|
|
148
168
|
const claims = claimsHeader ? JSON.parse(claimsHeader) : undefined;
|
|
149
169
|
const jwt = await (0, jwt_js_1.generateJWT)({
|
|
150
|
-
secretKey: this
|
|
170
|
+
secretKey: this.#selfSigningKey,
|
|
151
171
|
payload: {
|
|
152
172
|
...claims,
|
|
153
173
|
scopes: [`read:batch:${data.id}`],
|
|
@@ -180,10 +200,17 @@ class ApiClient {
|
|
|
180
200
|
}, mergeRequestOptions(this.defaultRequestOptions, requestOptions))
|
|
181
201
|
.withResponse()
|
|
182
202
|
.then(async ({ data, response }) => {
|
|
203
|
+
const jwtHeader = response.headers.get("x-trigger-jwt");
|
|
204
|
+
if (typeof jwtHeader === "string") {
|
|
205
|
+
return {
|
|
206
|
+
...data,
|
|
207
|
+
publicAccessToken: jwtHeader,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
183
210
|
const claimsHeader = response.headers.get("x-trigger-jwt-claims");
|
|
184
211
|
const claims = claimsHeader ? JSON.parse(claimsHeader) : undefined;
|
|
185
212
|
const jwt = await (0, jwt_js_1.generateJWT)({
|
|
186
|
-
secretKey: this
|
|
213
|
+
secretKey: this.#selfSigningKey,
|
|
187
214
|
payload: {
|
|
188
215
|
...claims,
|
|
189
216
|
scopes: [`read:batch:${data.id}`],
|
|
@@ -586,7 +613,7 @@ class ApiClient {
|
|
|
586
613
|
const claimsHeader = response.headers.get("x-trigger-jwt-claims");
|
|
587
614
|
const claims = claimsHeader ? JSON.parse(claimsHeader) : undefined;
|
|
588
615
|
const jwt = await (0, jwt_js_1.generateJWT)({
|
|
589
|
-
secretKey: this
|
|
616
|
+
secretKey: this.#selfSigningKey,
|
|
590
617
|
payload: {
|
|
591
618
|
...claims,
|
|
592
619
|
scopes: [`write:waitpoints:${data.id}`],
|
|
@@ -995,6 +1022,13 @@ class ApiClient {
|
|
|
995
1022
|
headers: this.#getHeaders(false),
|
|
996
1023
|
}, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
|
|
997
1024
|
}
|
|
1025
|
+
async createPublicToken(body, requestOptions) {
|
|
1026
|
+
return (0, core_js_1.zodfetch)(CreatePublicTokenResponseBody, `${this.baseUrl}/api/v1/auth/public-tokens`, {
|
|
1027
|
+
method: "POST",
|
|
1028
|
+
headers: this.#getHeaders(false),
|
|
1029
|
+
body: JSON.stringify(body),
|
|
1030
|
+
}, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
|
|
1031
|
+
}
|
|
998
1032
|
retrieveBatch(batchId, requestOptions) {
|
|
999
1033
|
return (0, core_js_1.zodfetch)(index_js_1.RetrieveBatchV2Response, `${this.baseUrl}/api/v2/batches/${batchId}`, {
|
|
1000
1034
|
method: "GET",
|
|
@@ -1028,6 +1062,25 @@ class ApiClient {
|
|
|
1028
1062
|
headers: this.#getHeaders(false),
|
|
1029
1063
|
}, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
|
|
1030
1064
|
}
|
|
1065
|
+
/**
|
|
1066
|
+
* Fetch a server-rendered report (text + sparkline). Thin pass-through — the string
|
|
1067
|
+
* is ready to display. `format`: "markdown" (default, agents/chat) or "ansi" (terminal).
|
|
1068
|
+
*/
|
|
1069
|
+
async getReport(key, options) {
|
|
1070
|
+
const searchParams = new URLSearchParams({ format: options?.format ?? "markdown" });
|
|
1071
|
+
if (options?.period) {
|
|
1072
|
+
searchParams.set("period", options.period);
|
|
1073
|
+
}
|
|
1074
|
+
const response = await fetch(`${this.baseUrl}/api/v1/reports/${encodeURIComponent(key)}?${searchParams.toString()}`, {
|
|
1075
|
+
method: "GET",
|
|
1076
|
+
headers: this.#getHeaders(false),
|
|
1077
|
+
});
|
|
1078
|
+
if (!response.ok) {
|
|
1079
|
+
const bodySnippet = await readBodySnippet(response);
|
|
1080
|
+
throw new Error(`Failed to fetch report "${key}": ${response.status} ${response.statusText}${bodySnippet ? ` — ${bodySnippet}` : ""}`);
|
|
1081
|
+
}
|
|
1082
|
+
return response.text();
|
|
1083
|
+
}
|
|
1031
1084
|
#getHeaders(spanParentAsLink, additionalHeaders) {
|
|
1032
1085
|
const headers = {
|
|
1033
1086
|
"Content-Type": "application/json",
|
|
@@ -1319,6 +1372,22 @@ function shouldRetryStreamBatchItems(response, attempt, retryOptions) {
|
|
|
1319
1372
|
function sleep(ms) {
|
|
1320
1373
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1321
1374
|
}
|
|
1375
|
+
/**
|
|
1376
|
+
* Best-effort read of a (likely error) response body for inclusion in a thrown Error.
|
|
1377
|
+
* Never throws, and truncates so we don't dump a huge HTML page into an error message.
|
|
1378
|
+
*/
|
|
1379
|
+
async function readBodySnippet(response, maxLength = 500) {
|
|
1380
|
+
try {
|
|
1381
|
+
const text = (await response.text()).trim();
|
|
1382
|
+
if (!text) {
|
|
1383
|
+
return "";
|
|
1384
|
+
}
|
|
1385
|
+
return text.length > maxLength ? `${text.slice(0, maxLength)}…` : text;
|
|
1386
|
+
}
|
|
1387
|
+
catch {
|
|
1388
|
+
return "";
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1322
1391
|
/**
|
|
1323
1392
|
* Safely cancels a ReadableStream, handling the case where it might be locked.
|
|
1324
1393
|
*
|