@trigger.dev/core 0.0.0-prerelease-20240603154820 → 0.0.0-prerelease-20240723165848
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/api-Pl9fxB8v.d.mts +13879 -0
- package/dist/api-sNoooMbT.d.ts +13879 -0
- package/dist/{catalog-dRKTgwQ7.d.ts → catalog-H7yFiZ60.d.mts} +52 -52
- package/dist/{catalog-XTlJQaMn.d.mts → catalog-h79CG5Wy.d.ts} +52 -52
- package/dist/{manager-JkbddlcO.d.mts → common-CLW82lkt.d.mts} +280 -16
- package/dist/{manager-JkbddlcO.d.ts → common-CLW82lkt.d.ts} +280 -16
- package/dist/{eventFilterMatches-2kHImluE.d.mts → eventFilter-66NaBAMi.d.mts} +1 -3
- package/dist/{eventFilterMatches-2kHImluE.d.ts → eventFilter-66NaBAMi.d.ts} +1 -3
- package/dist/eventFilterMatches.d.mts +6 -0
- package/dist/eventFilterMatches.d.ts +6 -0
- package/dist/eventFilterMatches.js +165 -0
- package/dist/eventFilterMatches.js.map +1 -0
- package/dist/eventFilterMatches.mjs +163 -0
- package/dist/eventFilterMatches.mjs.map +1 -0
- package/dist/index.d.mts +14 -16716
- package/dist/index.d.ts +14 -16716
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/json-DBPEJQRe.d.mts +16 -0
- package/dist/json-DBPEJQRe.d.ts +16 -0
- package/dist/manager-KvCabW1a.d.mts +18 -0
- package/dist/manager-OBA35PzR.d.ts +18 -0
- package/dist/{messages-6_-q72KG.d.mts → messages-JvHJ83wv.d.mts} +2978 -291
- package/dist/{messages-6_-q72KG.d.ts → messages-JvHJ83wv.d.ts} +2978 -291
- package/dist/replacements.d.mts +22 -0
- package/dist/replacements.d.ts +22 -0
- package/dist/replacements.js +33 -0
- package/dist/replacements.js.map +1 -0
- package/dist/replacements.mjs +28 -0
- package/dist/replacements.mjs.map +1 -0
- package/dist/requestFilter-HNZQEpQb.d.ts +180 -0
- package/dist/requestFilter-b5W2_1oP.d.mts +180 -0
- package/dist/requestFilterMatches.d.mts +13 -0
- package/dist/requestFilterMatches.d.ts +13 -0
- package/dist/requestFilterMatches.js +238 -0
- package/dist/requestFilterMatches.js.map +1 -0
- package/dist/requestFilterMatches.mjs +235 -0
- package/dist/requestFilterMatches.mjs.map +1 -0
- package/dist/retry.d.mts +10 -0
- package/dist/retry.d.ts +10 -0
- package/dist/retry.js +100 -0
- package/dist/retry.js.map +1 -0
- package/dist/retry.mjs +97 -0
- package/dist/retry.mjs.map +1 -0
- package/dist/schemas/index.d.mts +2611 -0
- package/dist/schemas/index.d.ts +2611 -0
- package/dist/schemas/index.js +1630 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/index.mjs +1463 -0
- package/dist/schemas/index.mjs.map +1 -0
- package/dist/{schemas-r4ZP9S-F.d.mts → schemas-C9ssfehv.d.mts} +270 -33
- package/dist/{schemas-r4ZP9S-F.d.ts → schemas-C9ssfehv.d.ts} +270 -33
- package/dist/taskLogger-CzADe4je.d.ts +33 -0
- package/dist/taskLogger-r_AFTX45.d.mts +33 -0
- package/dist/tracer-N0p2Fuuv.d.mts +23 -0
- package/dist/tracer-N0p2Fuuv.d.ts +23 -0
- package/dist/types.d.mts +11 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/dist/types.mjs +3 -0
- package/dist/types.mjs.map +1 -0
- package/dist/utils.d.mts +7 -0
- package/dist/utils.d.ts +7 -0
- package/dist/utils.js +33 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.mjs +30 -0
- package/dist/utils.mjs.map +1 -0
- package/dist/v3/dev/index.d.mts +2 -1
- package/dist/v3/dev/index.d.ts +2 -1
- package/dist/v3/dev/index.js.map +1 -1
- package/dist/v3/dev/index.mjs.map +1 -1
- package/dist/v3/errors.d.mts +39 -0
- package/dist/v3/errors.d.ts +39 -0
- package/dist/v3/errors.js +204 -0
- package/dist/v3/errors.js.map +1 -0
- package/dist/v3/errors.mjs +195 -0
- package/dist/v3/errors.mjs.map +1 -0
- package/dist/v3/index.d.mts +172 -4737
- package/dist/v3/index.d.ts +172 -4737
- package/dist/v3/index.js +871 -620
- package/dist/v3/index.js.map +1 -1
- package/dist/v3/index.mjs +856 -620
- package/dist/v3/index.mjs.map +1 -1
- package/dist/v3/logger-api.d.mts +24 -0
- package/dist/v3/logger-api.d.ts +24 -0
- package/dist/v3/logger-api.js +118 -0
- package/dist/v3/logger-api.js.map +1 -0
- package/dist/v3/logger-api.mjs +116 -0
- package/dist/v3/logger-api.mjs.map +1 -0
- package/dist/v3/otel/index.js +36 -12
- package/dist/v3/otel/index.js.map +1 -1
- package/dist/v3/otel/index.mjs +36 -12
- package/dist/v3/otel/index.mjs.map +1 -1
- package/dist/v3/prod/index.d.mts +4 -3
- package/dist/v3/prod/index.d.ts +4 -3
- package/dist/v3/prod/index.js +7 -131
- package/dist/v3/prod/index.js.map +1 -1
- package/dist/v3/prod/index.mjs +7 -131
- package/dist/v3/prod/index.mjs.map +1 -1
- package/dist/v3/schemas/index.d.mts +4807 -0
- package/dist/v3/schemas/index.d.ts +4807 -0
- package/dist/v3/schemas/index.js +2065 -0
- package/dist/v3/schemas/index.js.map +1 -0
- package/dist/v3/schemas/index.mjs +1924 -0
- package/dist/v3/schemas/index.mjs.map +1 -0
- package/dist/v3/semanticInternalAttributes.d.mts +56 -0
- package/dist/v3/semanticInternalAttributes.d.ts +56 -0
- package/dist/v3/semanticInternalAttributes.js +61 -0
- package/dist/v3/semanticInternalAttributes.js.map +1 -0
- package/dist/v3/semanticInternalAttributes.mjs +59 -0
- package/dist/v3/semanticInternalAttributes.mjs.map +1 -0
- package/dist/v3/utils/durations.d.mts +15 -0
- package/dist/v3/utils/durations.d.ts +15 -0
- package/dist/v3/utils/durations.js +93 -0
- package/dist/v3/utils/durations.js.map +1 -0
- package/dist/v3/utils/durations.mjs +82 -0
- package/dist/v3/utils/durations.mjs.map +1 -0
- package/dist/v3/utils/flattenAttributes.d.mts +8 -0
- package/dist/v3/utils/flattenAttributes.d.ts +8 -0
- package/dist/v3/utils/flattenAttributes.js +131 -0
- package/dist/v3/utils/flattenAttributes.js.map +1 -0
- package/dist/v3/utils/flattenAttributes.mjs +126 -0
- package/dist/v3/utils/flattenAttributes.mjs.map +1 -0
- package/dist/v3/utils/ioSerialization.d.mts +21 -0
- package/dist/v3/utils/ioSerialization.d.ts +21 -0
- package/dist/v3/utils/ioSerialization.js +2403 -0
- package/dist/v3/utils/ioSerialization.js.map +1 -0
- package/dist/v3/utils/ioSerialization.mjs +2394 -0
- package/dist/v3/utils/ioSerialization.mjs.map +1 -0
- package/dist/v3/utils/omit.d.mts +3 -0
- package/dist/v3/utils/omit.d.ts +3 -0
- package/dist/v3/utils/omit.js +20 -0
- package/dist/v3/utils/omit.js.map +1 -0
- package/dist/v3/utils/omit.mjs +18 -0
- package/dist/v3/utils/omit.mjs.map +1 -0
- package/dist/v3/utils/retries.d.mts +46 -0
- package/dist/v3/utils/retries.d.ts +46 -0
- package/dist/v3/utils/retries.js +118 -0
- package/dist/v3/utils/retries.js.map +1 -0
- package/dist/v3/utils/retries.mjs +113 -0
- package/dist/v3/utils/retries.mjs.map +1 -0
- package/dist/v3/utils/timers.d.mts +6 -0
- package/dist/v3/utils/timers.d.ts +6 -0
- package/dist/v3/utils/timers.js +31 -0
- package/dist/v3/utils/timers.js.map +1 -0
- package/dist/v3/utils/timers.mjs +28 -0
- package/dist/v3/utils/timers.mjs.map +1 -0
- package/dist/v3/workers/index.d.mts +56 -8
- package/dist/v3/workers/index.d.ts +56 -8
- package/dist/v3/workers/index.js +755 -279
- package/dist/v3/workers/index.js.map +1 -1
- package/dist/v3/workers/index.mjs +753 -280
- package/dist/v3/workers/index.mjs.map +1 -1
- package/dist/v3/zodIpc.js.map +1 -1
- package/dist/v3/zodIpc.mjs.map +1 -1
- package/dist/v3/zodMessageHandler.d.mts +16 -3
- package/dist/v3/zodMessageHandler.d.ts +16 -3
- package/dist/v3/zodMessageHandler.js +77 -23
- package/dist/v3/zodMessageHandler.js.map +1 -1
- package/dist/v3/zodMessageHandler.mjs +77 -23
- package/dist/v3/zodMessageHandler.mjs.map +1 -1
- package/dist/v3/zodNamespace.js +59 -28
- package/dist/v3/zodNamespace.js.map +1 -1
- package/dist/v3/zodNamespace.mjs +60 -29
- package/dist/v3/zodNamespace.mjs.map +1 -1
- package/dist/v3/zodSocket.d.mts +8 -3
- package/dist/v3/zodSocket.d.ts +8 -3
- package/dist/v3/zodSocket.js +56 -25
- package/dist/v3/zodSocket.js.map +1 -1
- package/dist/v3/zodSocket.mjs +57 -26
- package/dist/v3/zodSocket.mjs.map +1 -1
- package/dist/v3/zodfetch.d.mts +15 -58
- package/dist/v3/zodfetch.d.ts +15 -58
- package/dist/v3/zodfetch.js +246 -156
- package/dist/v3/zodfetch.js.map +1 -1
- package/dist/v3/zodfetch.mjs +244 -149
- package/dist/v3/zodfetch.mjs.map +1 -1
- package/dist/versions.d.mts +11 -0
- package/dist/versions.d.ts +11 -0
- package/dist/versions.js +31 -0
- package/dist/versions.js.map +1 -0
- package/dist/versions.mjs +27 -0
- package/dist/versions.mjs.map +1 -0
- package/package.json +154 -10
package/dist/v3/zodfetch.mjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { fromZodError } from 'zod-validation-error';
|
|
3
|
-
import { FormDataEncoder } from 'form-data-encoder';
|
|
4
|
-
import { Readable } from 'node:stream';
|
|
5
3
|
|
|
6
4
|
var __defProp = Object.defineProperty;
|
|
7
5
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -24,10 +22,34 @@ var __privateMethod = (obj, member, method) => {
|
|
|
24
22
|
return method;
|
|
25
23
|
};
|
|
26
24
|
|
|
25
|
+
// src/v3/utils/retries.ts
|
|
26
|
+
var defaultRetryOptions = {
|
|
27
|
+
maxAttempts: 3,
|
|
28
|
+
factor: 2,
|
|
29
|
+
minTimeoutInMs: 1e3,
|
|
30
|
+
maxTimeoutInMs: 6e4,
|
|
31
|
+
randomize: true
|
|
32
|
+
};
|
|
33
|
+
function calculateNextRetryDelay(options, attempt) {
|
|
34
|
+
const opts = {
|
|
35
|
+
...defaultRetryOptions,
|
|
36
|
+
...options
|
|
37
|
+
};
|
|
38
|
+
if (attempt >= opts.maxAttempts) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const { factor, minTimeoutInMs, maxTimeoutInMs, randomize } = opts;
|
|
42
|
+
const random = randomize ? Math.random() + 1 : 1;
|
|
43
|
+
const timeout = Math.min(maxTimeoutInMs, random * minTimeoutInMs * Math.pow(factor, attempt - 1));
|
|
44
|
+
return Math.round(timeout);
|
|
45
|
+
}
|
|
46
|
+
__name(calculateNextRetryDelay, "calculateNextRetryDelay");
|
|
47
|
+
|
|
27
48
|
// src/v3/apiClient/errors.ts
|
|
28
49
|
var _ApiError = class _ApiError extends Error {
|
|
29
50
|
constructor(status, error, message, headers) {
|
|
30
51
|
super(`${_ApiError.makeMessage(status, error, message)}`);
|
|
52
|
+
this.name = "TriggerApiError";
|
|
31
53
|
this.status = status;
|
|
32
54
|
this.headers = headers;
|
|
33
55
|
const data = error;
|
|
@@ -148,6 +170,16 @@ var _RateLimitError = class _RateLimitError extends ApiError {
|
|
|
148
170
|
super(...arguments);
|
|
149
171
|
__publicField(this, "status", 429);
|
|
150
172
|
}
|
|
173
|
+
get millisecondsUntilReset() {
|
|
174
|
+
const resetAtUnixEpochMs = (this.headers ?? {})["x-ratelimit-reset"];
|
|
175
|
+
if (typeof resetAtUnixEpochMs === "string") {
|
|
176
|
+
const resetAtUnixEpoch = parseInt(resetAtUnixEpochMs, 10);
|
|
177
|
+
if (isNaN(resetAtUnixEpoch)) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
return Math.max(resetAtUnixEpoch - Date.now() + Math.floor(Math.random() * 2e3), 0);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
151
183
|
};
|
|
152
184
|
__name(_RateLimitError, "RateLimitError");
|
|
153
185
|
var RateLimitError = _RateLimitError;
|
|
@@ -162,28 +194,122 @@ function castToError(err) {
|
|
|
162
194
|
}
|
|
163
195
|
__name(castToError, "castToError");
|
|
164
196
|
|
|
165
|
-
// src/v3/
|
|
166
|
-
var
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
197
|
+
// src/v3/semanticInternalAttributes.ts
|
|
198
|
+
var SemanticInternalAttributes = {
|
|
199
|
+
ENVIRONMENT_ID: "ctx.environment.id",
|
|
200
|
+
ENVIRONMENT_TYPE: "ctx.environment.type",
|
|
201
|
+
ORGANIZATION_ID: "ctx.organization.id",
|
|
202
|
+
ORGANIZATION_SLUG: "ctx.organization.slug",
|
|
203
|
+
ORGANIZATION_NAME: "ctx.organization.name",
|
|
204
|
+
PROJECT_ID: "ctx.project.id",
|
|
205
|
+
PROJECT_REF: "ctx.project.ref",
|
|
206
|
+
PROJECT_NAME: "ctx.project.title",
|
|
207
|
+
PROJECT_DIR: "project.dir",
|
|
208
|
+
ATTEMPT_ID: "ctx.attempt.id",
|
|
209
|
+
ATTEMPT_NUMBER: "ctx.attempt.number",
|
|
210
|
+
RUN_ID: "ctx.run.id",
|
|
211
|
+
RUN_IS_TEST: "ctx.run.isTest",
|
|
212
|
+
BATCH_ID: "ctx.batch.id",
|
|
213
|
+
TASK_SLUG: "ctx.task.id",
|
|
214
|
+
TASK_PATH: "ctx.task.filePath",
|
|
215
|
+
TASK_EXPORT_NAME: "ctx.task.exportName",
|
|
216
|
+
QUEUE_NAME: "ctx.queue.name",
|
|
217
|
+
QUEUE_ID: "ctx.queue.id",
|
|
218
|
+
MACHINE_PRESET_NAME: "ctx.machine.name",
|
|
219
|
+
MACHINE_PRESET_CPU: "ctx.machine.cpu",
|
|
220
|
+
MACHINE_PRESET_MEMORY: "ctx.machine.memory",
|
|
221
|
+
MACHINE_PRESET_CENTS_PER_MS: "ctx.machine.centsPerMs",
|
|
222
|
+
SPAN_PARTIAL: "$span.partial",
|
|
223
|
+
SPAN_ID: "$span.span_id",
|
|
224
|
+
OUTPUT: "$output",
|
|
225
|
+
OUTPUT_TYPE: "$mime_type_output",
|
|
226
|
+
STYLE: "$style",
|
|
227
|
+
STYLE_ICON: "$style.icon",
|
|
228
|
+
STYLE_VARIANT: "$style.variant",
|
|
229
|
+
STYLE_ACCESSORY: "$style.accessory",
|
|
230
|
+
METADATA: "$metadata",
|
|
231
|
+
TRIGGER: "$trigger",
|
|
232
|
+
PAYLOAD: "$payload",
|
|
233
|
+
PAYLOAD_TYPE: "$mime_type_payload",
|
|
234
|
+
SHOW: "$show",
|
|
235
|
+
SHOW_ACTIONS: "$show.actions",
|
|
236
|
+
WORKER_ID: "worker.id",
|
|
237
|
+
WORKER_VERSION: "worker.version",
|
|
238
|
+
CLI_VERSION: "cli.version",
|
|
239
|
+
SDK_VERSION: "sdk.version",
|
|
240
|
+
SDK_LANGUAGE: "sdk.language",
|
|
241
|
+
RETRY_AT: "retry.at",
|
|
242
|
+
RETRY_DELAY: "retry.delay",
|
|
243
|
+
RETRY_COUNT: "retry.count",
|
|
244
|
+
LINK_TITLE: "$link.title",
|
|
245
|
+
IDEMPOTENCY_KEY: "ctx.run.idempotencyKey",
|
|
246
|
+
USAGE_DURATION_MS: "$usage.durationMs",
|
|
247
|
+
USAGE_COST_IN_CENTS: "$usage.costInCents",
|
|
248
|
+
RATE_LIMIT_LIMIT: "response.rateLimit.limit",
|
|
249
|
+
RATE_LIMIT_REMAINING: "response.rateLimit.remaining",
|
|
250
|
+
RATE_LIMIT_RESET: "response.rateLimit.reset"
|
|
172
251
|
};
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
};
|
|
178
|
-
if (
|
|
179
|
-
return;
|
|
252
|
+
|
|
253
|
+
// src/v3/utils/flattenAttributes.ts
|
|
254
|
+
var NULL_SENTINEL = "$@null((";
|
|
255
|
+
function flattenAttributes(obj, prefix) {
|
|
256
|
+
const result = {};
|
|
257
|
+
if (obj === void 0) {
|
|
258
|
+
return result;
|
|
259
|
+
}
|
|
260
|
+
if (obj === null) {
|
|
261
|
+
result[prefix || ""] = NULL_SENTINEL;
|
|
262
|
+
return result;
|
|
263
|
+
}
|
|
264
|
+
if (typeof obj === "string") {
|
|
265
|
+
result[prefix || ""] = obj;
|
|
266
|
+
return result;
|
|
267
|
+
}
|
|
268
|
+
if (typeof obj === "number") {
|
|
269
|
+
result[prefix || ""] = obj;
|
|
270
|
+
return result;
|
|
271
|
+
}
|
|
272
|
+
if (typeof obj === "boolean") {
|
|
273
|
+
result[prefix || ""] = obj;
|
|
274
|
+
return result;
|
|
275
|
+
}
|
|
276
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
277
|
+
const newPrefix = `${prefix ? `${prefix}.` : ""}${Array.isArray(obj) ? `[${key}]` : key}`;
|
|
278
|
+
if (Array.isArray(value)) {
|
|
279
|
+
for (let i = 0; i < value.length; i++) {
|
|
280
|
+
if (typeof value[i] === "object" && value[i] !== null) {
|
|
281
|
+
Object.assign(result, flattenAttributes(value[i], `${newPrefix}.[${i}]`));
|
|
282
|
+
} else {
|
|
283
|
+
if (value[i] === null) {
|
|
284
|
+
result[`${newPrefix}.[${i}]`] = NULL_SENTINEL;
|
|
285
|
+
} else {
|
|
286
|
+
result[`${newPrefix}.[${i}]`] = value[i];
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
} else if (isRecord(value)) {
|
|
291
|
+
Object.assign(result, flattenAttributes(value, newPrefix));
|
|
292
|
+
} else {
|
|
293
|
+
if (typeof value === "number" || typeof value === "string" || typeof value === "boolean") {
|
|
294
|
+
result[newPrefix] = value;
|
|
295
|
+
} else if (value === null) {
|
|
296
|
+
result[newPrefix] = NULL_SENTINEL;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
180
299
|
}
|
|
181
|
-
|
|
182
|
-
const random = randomize ? Math.random() + 1 : 1;
|
|
183
|
-
const timeout = Math.min(maxTimeoutInMs, random * minTimeoutInMs * Math.pow(factor, attempt - 1));
|
|
184
|
-
return Math.round(timeout);
|
|
300
|
+
return result;
|
|
185
301
|
}
|
|
186
|
-
__name(
|
|
302
|
+
__name(flattenAttributes, "flattenAttributes");
|
|
303
|
+
function isRecord(value) {
|
|
304
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
305
|
+
}
|
|
306
|
+
__name(isRecord, "isRecord");
|
|
307
|
+
|
|
308
|
+
// src/v3/utils/styleAttributes.ts
|
|
309
|
+
function accessoryAttributes(accessory) {
|
|
310
|
+
return flattenAttributes(accessory, SemanticInternalAttributes.STYLE_ACCESSORY);
|
|
311
|
+
}
|
|
312
|
+
__name(accessoryAttributes, "accessoryAttributes");
|
|
187
313
|
|
|
188
314
|
// src/v3/apiClient/pagination.ts
|
|
189
315
|
var _CursorPage = class _CursorPage {
|
|
@@ -293,6 +419,12 @@ var defaultRetryOptions2 = {
|
|
|
293
419
|
maxTimeoutInMs: 6e4,
|
|
294
420
|
randomize: false
|
|
295
421
|
};
|
|
422
|
+
var requestOptionsKeys = {
|
|
423
|
+
retry: true
|
|
424
|
+
};
|
|
425
|
+
var isRequestOptions = /* @__PURE__ */ __name((obj) => {
|
|
426
|
+
return typeof obj === "object" && obj !== null && !isEmptyObj(obj) && Object.keys(obj).every((k) => hasOwn(requestOptionsKeys, k));
|
|
427
|
+
}, "isRequestOptions");
|
|
296
428
|
function zodfetch(schema, url, requestInit, options) {
|
|
297
429
|
return new ApiPromise(_doZodFetch(schema, url, requestInit, options));
|
|
298
430
|
}
|
|
@@ -343,47 +475,47 @@ function zodfetchOffsetLimitPage(schema, url, params, requestInit, options) {
|
|
|
343
475
|
return new OffsetLimitPagePromise(fetchResult, schema, url, params, requestInit, options);
|
|
344
476
|
}
|
|
345
477
|
__name(zodfetchOffsetLimitPage, "zodfetchOffsetLimitPage");
|
|
346
|
-
function
|
|
347
|
-
|
|
348
|
-
|
|
478
|
+
async function traceZodFetch(params, callback) {
|
|
479
|
+
if (!params.options?.tracer) {
|
|
480
|
+
return callback();
|
|
481
|
+
}
|
|
482
|
+
const url = new URL(params.url);
|
|
483
|
+
const method = params.requestInit?.method ?? "GET";
|
|
484
|
+
const name = params.options.name ?? `${method} ${url.pathname}`;
|
|
485
|
+
return await params.options.tracer.startActiveSpan(name, async (span) => {
|
|
486
|
+
return await callback(span);
|
|
487
|
+
}, {
|
|
488
|
+
attributes: {
|
|
489
|
+
[SemanticInternalAttributes.STYLE_ICON]: params.options?.icon ?? "api",
|
|
490
|
+
...params.options.attributes
|
|
491
|
+
}
|
|
492
|
+
});
|
|
349
493
|
}
|
|
350
|
-
__name(
|
|
351
|
-
async function
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
headers: finalHeaders,
|
|
365
|
-
body: Readable.from(encoder),
|
|
366
|
-
// @ts-expect-error
|
|
367
|
-
duplex: "half"
|
|
368
|
-
};
|
|
369
|
-
return finalRequestInit;
|
|
494
|
+
__name(traceZodFetch, "traceZodFetch");
|
|
495
|
+
async function _doZodFetch(schema, url, requestInit, options) {
|
|
496
|
+
const $requestInit = await requestInit;
|
|
497
|
+
return traceZodFetch({
|
|
498
|
+
url,
|
|
499
|
+
requestInit: $requestInit,
|
|
500
|
+
options
|
|
501
|
+
}, async (span) => {
|
|
502
|
+
const result = await _doZodFetchWithRetries(schema, url, $requestInit, options);
|
|
503
|
+
if (options?.onResponseBody && span) {
|
|
504
|
+
options.onResponseBody(result.data, span);
|
|
505
|
+
}
|
|
506
|
+
return result;
|
|
507
|
+
});
|
|
370
508
|
}
|
|
371
|
-
__name(
|
|
372
|
-
|
|
373
|
-
const form = new FormData();
|
|
374
|
-
await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));
|
|
375
|
-
return form;
|
|
376
|
-
}, "createForm");
|
|
377
|
-
async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
|
|
509
|
+
__name(_doZodFetch, "_doZodFetch");
|
|
510
|
+
async function _doZodFetchWithRetries(schema, url, requestInit, options, attempt = 1) {
|
|
378
511
|
try {
|
|
379
|
-
const
|
|
380
|
-
const response = await fetch(url, requestInitWithCache($requestInit));
|
|
512
|
+
const response = await fetch(url, requestInitWithCache(requestInit));
|
|
381
513
|
const responseHeaders = createResponseHeaders(response.headers);
|
|
382
514
|
if (!response.ok) {
|
|
383
515
|
const retryResult = shouldRetry(response, attempt, options?.retry);
|
|
384
516
|
if (retryResult.retry) {
|
|
385
|
-
await
|
|
386
|
-
return await
|
|
517
|
+
await waitForRetry(url, attempt + 1, retryResult.delay, options, requestInit, response);
|
|
518
|
+
return await _doZodFetchWithRetries(schema, url, requestInit, options, attempt + 1);
|
|
387
519
|
} else {
|
|
388
520
|
const errText = await response.text().catch((e) => castToError2(e).message);
|
|
389
521
|
const errJSON = safeJsonParse(errText);
|
|
@@ -411,8 +543,8 @@ async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
|
|
|
411
543
|
};
|
|
412
544
|
const delay = calculateNextRetryDelay(retry, attempt);
|
|
413
545
|
if (delay) {
|
|
414
|
-
await
|
|
415
|
-
return await
|
|
546
|
+
await waitForRetry(url, attempt + 1, delay, options, requestInit);
|
|
547
|
+
return await _doZodFetchWithRetries(schema, url, requestInit, options, attempt + 1);
|
|
416
548
|
}
|
|
417
549
|
}
|
|
418
550
|
throw new ApiConnectionError({
|
|
@@ -420,7 +552,7 @@ async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
|
|
|
420
552
|
});
|
|
421
553
|
}
|
|
422
554
|
}
|
|
423
|
-
__name(
|
|
555
|
+
__name(_doZodFetchWithRetries, "_doZodFetchWithRetries");
|
|
424
556
|
function castToError2(err) {
|
|
425
557
|
if (err instanceof Error)
|
|
426
558
|
return err;
|
|
@@ -457,8 +589,25 @@ function shouldRetry(response, attempt, retryOptions) {
|
|
|
457
589
|
return shouldRetryForOptions();
|
|
458
590
|
if (response.status === 409)
|
|
459
591
|
return shouldRetryForOptions();
|
|
460
|
-
if (response.status === 429)
|
|
592
|
+
if (response.status === 429) {
|
|
593
|
+
if (attempt >= (typeof retryOptions?.maxAttempts === "number" ? retryOptions?.maxAttempts : 3)) {
|
|
594
|
+
return {
|
|
595
|
+
retry: false
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
const resetAtUnixEpochMs = response.headers.get("x-ratelimit-reset");
|
|
599
|
+
if (resetAtUnixEpochMs) {
|
|
600
|
+
const resetAtUnixEpoch = parseInt(resetAtUnixEpochMs, 10);
|
|
601
|
+
const delay = resetAtUnixEpoch - Date.now() + Math.floor(Math.random() * 1e3);
|
|
602
|
+
if (delay > 0) {
|
|
603
|
+
return {
|
|
604
|
+
retry: true,
|
|
605
|
+
delay
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
}
|
|
461
609
|
return shouldRetryForOptions();
|
|
610
|
+
}
|
|
462
611
|
if (response.status >= 500)
|
|
463
612
|
return shouldRetryForOptions();
|
|
464
613
|
return {
|
|
@@ -499,95 +648,6 @@ function requestInitWithCache(requestInit) {
|
|
|
499
648
|
}
|
|
500
649
|
}
|
|
501
650
|
__name(requestInitWithCache, "requestInitWithCache");
|
|
502
|
-
var addFormValue = /* @__PURE__ */ __name(async (form, key, value) => {
|
|
503
|
-
if (value === void 0)
|
|
504
|
-
return;
|
|
505
|
-
if (value == null) {
|
|
506
|
-
throw new TypeError(`Received null for "${key}"; to pass null in FormData, you must use the string 'null'`);
|
|
507
|
-
}
|
|
508
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
509
|
-
form.append(key, String(value));
|
|
510
|
-
} else if (isUploadable(value) || isBlobLike(value) || value instanceof Buffer || value instanceof ArrayBuffer) {
|
|
511
|
-
const file = await toFile(value);
|
|
512
|
-
form.append(key, file);
|
|
513
|
-
} else if (Array.isArray(value)) {
|
|
514
|
-
await Promise.all(value.map((entry) => addFormValue(form, key + "[]", entry)));
|
|
515
|
-
} else if (typeof value === "object") {
|
|
516
|
-
await Promise.all(Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop)));
|
|
517
|
-
} else {
|
|
518
|
-
throw new TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`);
|
|
519
|
-
}
|
|
520
|
-
}, "addFormValue");
|
|
521
|
-
async function toFile(value, name, options) {
|
|
522
|
-
value = await value;
|
|
523
|
-
options ??= isFileLike(value) ? {
|
|
524
|
-
lastModified: value.lastModified,
|
|
525
|
-
type: value.type
|
|
526
|
-
} : {};
|
|
527
|
-
if (isResponseLike(value)) {
|
|
528
|
-
const blob = await value.blob();
|
|
529
|
-
name ||= new URL(value.url).pathname.split(/[\\/]/).pop() ?? "unknown_file";
|
|
530
|
-
return new File([
|
|
531
|
-
blob
|
|
532
|
-
], name, options);
|
|
533
|
-
}
|
|
534
|
-
const bits = await getBytes(value);
|
|
535
|
-
name ||= getName(value) ?? "unknown_file";
|
|
536
|
-
if (!options.type) {
|
|
537
|
-
const type = bits[0]?.type;
|
|
538
|
-
if (typeof type === "string") {
|
|
539
|
-
options = {
|
|
540
|
-
...options,
|
|
541
|
-
type
|
|
542
|
-
};
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
return new File(bits, name, options);
|
|
546
|
-
}
|
|
547
|
-
__name(toFile, "toFile");
|
|
548
|
-
function getName(value) {
|
|
549
|
-
return getStringFromMaybeBuffer(value.name) || getStringFromMaybeBuffer(value.filename) || // For fs.ReadStream
|
|
550
|
-
getStringFromMaybeBuffer(value.path)?.split(/[\\/]/).pop();
|
|
551
|
-
}
|
|
552
|
-
__name(getName, "getName");
|
|
553
|
-
var getStringFromMaybeBuffer = /* @__PURE__ */ __name((x) => {
|
|
554
|
-
if (typeof x === "string")
|
|
555
|
-
return x;
|
|
556
|
-
if (typeof Buffer !== "undefined" && x instanceof Buffer)
|
|
557
|
-
return String(x);
|
|
558
|
-
return void 0;
|
|
559
|
-
}, "getStringFromMaybeBuffer");
|
|
560
|
-
async function getBytes(value) {
|
|
561
|
-
let parts = [];
|
|
562
|
-
if (typeof value === "string" || ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.
|
|
563
|
-
value instanceof ArrayBuffer) {
|
|
564
|
-
parts.push(value);
|
|
565
|
-
} else if (isBlobLike(value)) {
|
|
566
|
-
parts.push(await value.arrayBuffer());
|
|
567
|
-
} else if (isAsyncIterableIterator(value)) {
|
|
568
|
-
for await (const chunk of value) {
|
|
569
|
-
parts.push(chunk);
|
|
570
|
-
}
|
|
571
|
-
} else {
|
|
572
|
-
throw new Error(`Unexpected data type: ${typeof value}; constructor: ${value?.constructor?.name}; props: ${propsForError(value)}`);
|
|
573
|
-
}
|
|
574
|
-
return parts;
|
|
575
|
-
}
|
|
576
|
-
__name(getBytes, "getBytes");
|
|
577
|
-
function propsForError(value) {
|
|
578
|
-
const props = Object.getOwnPropertyNames(value);
|
|
579
|
-
return `[${props.map((p) => `"${p}"`).join(", ")}]`;
|
|
580
|
-
}
|
|
581
|
-
__name(propsForError, "propsForError");
|
|
582
|
-
var isAsyncIterableIterator = /* @__PURE__ */ __name((value) => value != null && typeof value === "object" && typeof value[Symbol.asyncIterator] === "function", "isAsyncIterableIterator");
|
|
583
|
-
var isResponseLike = /* @__PURE__ */ __name((value) => value != null && typeof value === "object" && typeof value.url === "string" && typeof value.blob === "function", "isResponseLike");
|
|
584
|
-
var isFileLike = /* @__PURE__ */ __name((value) => value != null && typeof value === "object" && typeof value.name === "string" && typeof value.lastModified === "number" && isBlobLike(value), "isFileLike");
|
|
585
|
-
var isBlobLike = /* @__PURE__ */ __name((value) => value != null && typeof value === "object" && typeof value.size === "number" && typeof value.type === "string" && typeof value.text === "function" && typeof value.slice === "function" && typeof value.arrayBuffer === "function", "isBlobLike");
|
|
586
|
-
var isFsReadStream = /* @__PURE__ */ __name((value) => value instanceof Readable, "isFsReadStream");
|
|
587
|
-
var isUploadable = /* @__PURE__ */ __name((value) => {
|
|
588
|
-
return isFileLike(value) || isResponseLike(value) || isFsReadStream(value);
|
|
589
|
-
}, "isUploadable");
|
|
590
|
-
var isRecordLike = /* @__PURE__ */ __name((value) => value != null && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length > 0 && Object.keys(value).every((key) => typeof key === "string" && typeof value[key] === "string"), "isRecordLike");
|
|
591
651
|
var _ApiPromise = class _ApiPromise extends Promise {
|
|
592
652
|
constructor(responsePromise) {
|
|
593
653
|
super((resolve) => {
|
|
@@ -710,7 +770,42 @@ fetchPage_fn2 = /* @__PURE__ */ __name(function(params1) {
|
|
|
710
770
|
}, "#fetchPage");
|
|
711
771
|
__name(_OffsetLimitPagePromise, "OffsetLimitPagePromise");
|
|
712
772
|
var OffsetLimitPagePromise = _OffsetLimitPagePromise;
|
|
773
|
+
async function waitForRetry(url, attempt, delay, options, requestInit, response) {
|
|
774
|
+
if (options?.tracer) {
|
|
775
|
+
const method = requestInit?.method ?? "GET";
|
|
776
|
+
return options.tracer.startActiveSpan(response ? `wait after ${response.status}` : `wait after error`, async (span) => {
|
|
777
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
778
|
+
}, {
|
|
779
|
+
attributes: {
|
|
780
|
+
[SemanticInternalAttributes.STYLE_ICON]: "wait",
|
|
781
|
+
...accessoryAttributes({
|
|
782
|
+
items: [
|
|
783
|
+
{
|
|
784
|
+
text: `retrying ${options?.name ?? method.toUpperCase()} in ${delay}ms`,
|
|
785
|
+
variant: "normal"
|
|
786
|
+
}
|
|
787
|
+
],
|
|
788
|
+
style: "codepath"
|
|
789
|
+
})
|
|
790
|
+
}
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
794
|
+
}
|
|
795
|
+
__name(waitForRetry, "waitForRetry");
|
|
796
|
+
function isEmptyObj(obj) {
|
|
797
|
+
if (!obj)
|
|
798
|
+
return true;
|
|
799
|
+
for (const _k in obj)
|
|
800
|
+
return false;
|
|
801
|
+
return true;
|
|
802
|
+
}
|
|
803
|
+
__name(isEmptyObj, "isEmptyObj");
|
|
804
|
+
function hasOwn(obj, key) {
|
|
805
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
806
|
+
}
|
|
807
|
+
__name(hasOwn, "hasOwn");
|
|
713
808
|
|
|
714
|
-
export { ApiConnectionError, ApiError, ApiPromise, AuthenticationError, BadRequestError, ConflictError, CursorPage, CursorPagePromise, InternalServerError, NotFoundError, OffsetLimitPage, OffsetLimitPagePromise, PermissionDeniedError, RateLimitError, UnprocessableEntityError, defaultRetryOptions2 as defaultRetryOptions,
|
|
809
|
+
export { ApiConnectionError, ApiError, ApiPromise, AuthenticationError, BadRequestError, ConflictError, CursorPage, CursorPagePromise, InternalServerError, NotFoundError, OffsetLimitPage, OffsetLimitPagePromise, PermissionDeniedError, RateLimitError, UnprocessableEntityError, defaultRetryOptions2 as defaultRetryOptions, hasOwn, isEmptyObj, isRequestOptions, zodfetch, zodfetchCursorPage, zodfetchOffsetLimitPage };
|
|
715
810
|
//# sourceMappingURL=out.js.map
|
|
716
811
|
//# sourceMappingURL=zodfetch.mjs.map
|