@trigger.dev/core 3.0.0-beta.34 → 3.0.0-beta.36
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/catalog-XTlJQaMn.d.mts +202 -0
- package/dist/catalog-dRKTgwQ7.d.ts +202 -0
- package/dist/{manager-WNMVbgHf.d.mts → manager-JkbddlcO.d.mts} +43 -42
- package/dist/{manager-WNMVbgHf.d.ts → manager-JkbddlcO.d.ts} +43 -42
- package/dist/{messages-vq7Bk4Ap.d.mts → messages-6_-q72KG.d.mts} +5970 -2067
- package/dist/{messages-vq7Bk4Ap.d.ts → messages-6_-q72KG.d.ts} +5970 -2067
- package/dist/{catalog-tX1P4jZQ.d.ts → schemas-r4ZP9S-F.d.mts} +22 -201
- package/dist/{catalog-Y8FyPWvh.d.mts → schemas-r4ZP9S-F.d.ts} +22 -201
- package/dist/v3/dev/index.d.mts +2 -2
- package/dist/v3/dev/index.d.ts +2 -2
- package/dist/v3/dev/index.js +4 -4
- package/dist/v3/dev/index.js.map +1 -1
- package/dist/v3/dev/index.mjs +4 -4
- package/dist/v3/dev/index.mjs.map +1 -1
- package/dist/v3/index.d.mts +584 -152
- package/dist/v3/index.d.ts +584 -152
- package/dist/v3/index.js +962 -350
- package/dist/v3/index.js.map +1 -1
- package/dist/v3/index.mjs +953 -350
- package/dist/v3/index.mjs.map +1 -1
- package/dist/v3/otel/index.js +1 -1
- package/dist/v3/otel/index.js.map +1 -1
- package/dist/v3/otel/index.mjs +1 -1
- package/dist/v3/otel/index.mjs.map +1 -1
- package/dist/v3/prod/index.d.mts +3 -3
- package/dist/v3/prod/index.d.ts +3 -3
- package/dist/v3/prod/index.js +90 -15
- package/dist/v3/prod/index.js.map +1 -1
- package/dist/v3/prod/index.mjs +90 -15
- package/dist/v3/prod/index.mjs.map +1 -1
- package/dist/v3/workers/index.d.mts +6 -5
- package/dist/v3/workers/index.d.ts +6 -5
- package/dist/v3/workers/index.js +476 -53
- package/dist/v3/workers/index.js.map +1 -1
- package/dist/v3/workers/index.mjs +477 -54
- package/dist/v3/workers/index.mjs.map +1 -1
- package/dist/v3/zodMessageHandler.d.mts +1 -1
- package/dist/v3/zodMessageHandler.d.ts +1 -1
- package/dist/v3/zodNamespace.js +16 -6
- package/dist/v3/zodNamespace.js.map +1 -1
- package/dist/v3/zodNamespace.mjs +17 -7
- package/dist/v3/zodNamespace.mjs.map +1 -1
- package/dist/v3/zodSocket.js +16 -6
- package/dist/v3/zodSocket.js.map +1 -1
- package/dist/v3/zodSocket.mjs +17 -7
- package/dist/v3/zodSocket.mjs.map +1 -1
- package/dist/v3/zodfetch.d.mts +262 -0
- package/dist/v3/zodfetch.d.ts +262 -0
- package/dist/v3/zodfetch.js +744 -0
- package/dist/v3/zodfetch.js.map +1 -0
- package/dist/v3/zodfetch.mjs +716 -0
- package/dist/v3/zodfetch.mjs.map +1 -0
- package/package.json +9 -1
|
@@ -0,0 +1,744 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var zod = require('zod');
|
|
4
|
+
var zodValidationError = require('zod-validation-error');
|
|
5
|
+
var formDataEncoder = require('form-data-encoder');
|
|
6
|
+
var stream = require('stream');
|
|
7
|
+
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
11
|
+
var __publicField = (obj, key, value) => {
|
|
12
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
13
|
+
return value;
|
|
14
|
+
};
|
|
15
|
+
var __accessCheck = (obj, member, msg) => {
|
|
16
|
+
if (!member.has(obj))
|
|
17
|
+
throw TypeError("Cannot " + msg);
|
|
18
|
+
};
|
|
19
|
+
var __privateAdd = (obj, member, value) => {
|
|
20
|
+
if (member.has(obj))
|
|
21
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
22
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
23
|
+
};
|
|
24
|
+
var __privateMethod = (obj, member, method) => {
|
|
25
|
+
__accessCheck(obj, member, "access private method");
|
|
26
|
+
return method;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/v3/apiClient/errors.ts
|
|
30
|
+
var _ApiError = class _ApiError extends Error {
|
|
31
|
+
constructor(status, error, message, headers) {
|
|
32
|
+
super(`${_ApiError.makeMessage(status, error, message)}`);
|
|
33
|
+
this.status = status;
|
|
34
|
+
this.headers = headers;
|
|
35
|
+
const data = error;
|
|
36
|
+
this.error = data;
|
|
37
|
+
this.code = data?.["code"];
|
|
38
|
+
this.param = data?.["param"];
|
|
39
|
+
this.type = data?.["type"];
|
|
40
|
+
}
|
|
41
|
+
static makeMessage(status, error, message) {
|
|
42
|
+
const msg = error?.message ? typeof error.message === "string" ? error.message : JSON.stringify(error.message) : error ? JSON.stringify(error) : message;
|
|
43
|
+
if (status && msg) {
|
|
44
|
+
return `${status} ${msg}`;
|
|
45
|
+
}
|
|
46
|
+
if (status) {
|
|
47
|
+
return `${status} status code (no body)`;
|
|
48
|
+
}
|
|
49
|
+
if (msg) {
|
|
50
|
+
return msg;
|
|
51
|
+
}
|
|
52
|
+
return "(no status code or body)";
|
|
53
|
+
}
|
|
54
|
+
static generate(status, errorResponse, message, headers) {
|
|
55
|
+
if (!status) {
|
|
56
|
+
return new ApiConnectionError({
|
|
57
|
+
cause: castToError(errorResponse)
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const error = errorResponse?.["error"];
|
|
61
|
+
if (status === 400) {
|
|
62
|
+
return new BadRequestError(status, error, message, headers);
|
|
63
|
+
}
|
|
64
|
+
if (status === 401) {
|
|
65
|
+
return new AuthenticationError(status, error, message, headers);
|
|
66
|
+
}
|
|
67
|
+
if (status === 403) {
|
|
68
|
+
return new PermissionDeniedError(status, error, message, headers);
|
|
69
|
+
}
|
|
70
|
+
if (status === 404) {
|
|
71
|
+
return new NotFoundError(status, error, message, headers);
|
|
72
|
+
}
|
|
73
|
+
if (status === 409) {
|
|
74
|
+
return new ConflictError(status, error, message, headers);
|
|
75
|
+
}
|
|
76
|
+
if (status === 422) {
|
|
77
|
+
return new UnprocessableEntityError(status, error, message, headers);
|
|
78
|
+
}
|
|
79
|
+
if (status === 429) {
|
|
80
|
+
return new RateLimitError(status, error, message, headers);
|
|
81
|
+
}
|
|
82
|
+
if (status >= 500) {
|
|
83
|
+
return new InternalServerError(status, error, message, headers);
|
|
84
|
+
}
|
|
85
|
+
return new _ApiError(status, error, message, headers);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
__name(_ApiError, "ApiError");
|
|
89
|
+
var ApiError = _ApiError;
|
|
90
|
+
var _ApiConnectionError = class _ApiConnectionError extends ApiError {
|
|
91
|
+
constructor({ message, cause }) {
|
|
92
|
+
super(void 0, void 0, message || "Connection error.", void 0);
|
|
93
|
+
__publicField(this, "status");
|
|
94
|
+
if (cause)
|
|
95
|
+
this.cause = cause;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
__name(_ApiConnectionError, "ApiConnectionError");
|
|
99
|
+
var ApiConnectionError = _ApiConnectionError;
|
|
100
|
+
var _BadRequestError = class _BadRequestError extends ApiError {
|
|
101
|
+
constructor() {
|
|
102
|
+
super(...arguments);
|
|
103
|
+
__publicField(this, "status", 400);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
__name(_BadRequestError, "BadRequestError");
|
|
107
|
+
var BadRequestError = _BadRequestError;
|
|
108
|
+
var _AuthenticationError = class _AuthenticationError extends ApiError {
|
|
109
|
+
constructor() {
|
|
110
|
+
super(...arguments);
|
|
111
|
+
__publicField(this, "status", 401);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
__name(_AuthenticationError, "AuthenticationError");
|
|
115
|
+
var AuthenticationError = _AuthenticationError;
|
|
116
|
+
var _PermissionDeniedError = class _PermissionDeniedError extends ApiError {
|
|
117
|
+
constructor() {
|
|
118
|
+
super(...arguments);
|
|
119
|
+
__publicField(this, "status", 403);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
__name(_PermissionDeniedError, "PermissionDeniedError");
|
|
123
|
+
var PermissionDeniedError = _PermissionDeniedError;
|
|
124
|
+
var _NotFoundError = class _NotFoundError extends ApiError {
|
|
125
|
+
constructor() {
|
|
126
|
+
super(...arguments);
|
|
127
|
+
__publicField(this, "status", 404);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
__name(_NotFoundError, "NotFoundError");
|
|
131
|
+
var NotFoundError = _NotFoundError;
|
|
132
|
+
var _ConflictError = class _ConflictError extends ApiError {
|
|
133
|
+
constructor() {
|
|
134
|
+
super(...arguments);
|
|
135
|
+
__publicField(this, "status", 409);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
__name(_ConflictError, "ConflictError");
|
|
139
|
+
var ConflictError = _ConflictError;
|
|
140
|
+
var _UnprocessableEntityError = class _UnprocessableEntityError extends ApiError {
|
|
141
|
+
constructor() {
|
|
142
|
+
super(...arguments);
|
|
143
|
+
__publicField(this, "status", 422);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
__name(_UnprocessableEntityError, "UnprocessableEntityError");
|
|
147
|
+
var UnprocessableEntityError = _UnprocessableEntityError;
|
|
148
|
+
var _RateLimitError = class _RateLimitError extends ApiError {
|
|
149
|
+
constructor() {
|
|
150
|
+
super(...arguments);
|
|
151
|
+
__publicField(this, "status", 429);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
__name(_RateLimitError, "RateLimitError");
|
|
155
|
+
var RateLimitError = _RateLimitError;
|
|
156
|
+
var _InternalServerError = class _InternalServerError extends ApiError {
|
|
157
|
+
};
|
|
158
|
+
__name(_InternalServerError, "InternalServerError");
|
|
159
|
+
var InternalServerError = _InternalServerError;
|
|
160
|
+
function castToError(err) {
|
|
161
|
+
if (err instanceof Error)
|
|
162
|
+
return err;
|
|
163
|
+
return new Error(err);
|
|
164
|
+
}
|
|
165
|
+
__name(castToError, "castToError");
|
|
166
|
+
|
|
167
|
+
// src/v3/utils/retries.ts
|
|
168
|
+
var defaultRetryOptions = {
|
|
169
|
+
maxAttempts: 3,
|
|
170
|
+
factor: 2,
|
|
171
|
+
minTimeoutInMs: 1e3,
|
|
172
|
+
maxTimeoutInMs: 6e4,
|
|
173
|
+
randomize: true
|
|
174
|
+
};
|
|
175
|
+
function calculateNextRetryDelay(options, attempt) {
|
|
176
|
+
const opts = {
|
|
177
|
+
...defaultRetryOptions,
|
|
178
|
+
...options
|
|
179
|
+
};
|
|
180
|
+
if (attempt >= opts.maxAttempts) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const { factor, minTimeoutInMs, maxTimeoutInMs, randomize } = opts;
|
|
184
|
+
const random = randomize ? Math.random() + 1 : 1;
|
|
185
|
+
const timeout = Math.min(maxTimeoutInMs, random * minTimeoutInMs * Math.pow(factor, attempt - 1));
|
|
186
|
+
return Math.round(timeout);
|
|
187
|
+
}
|
|
188
|
+
__name(calculateNextRetryDelay, "calculateNextRetryDelay");
|
|
189
|
+
|
|
190
|
+
// src/v3/apiClient/pagination.ts
|
|
191
|
+
var _CursorPage = class _CursorPage {
|
|
192
|
+
constructor(data, pagination, pageFetcher) {
|
|
193
|
+
this.pageFetcher = pageFetcher;
|
|
194
|
+
this.data = data;
|
|
195
|
+
this.pagination = pagination;
|
|
196
|
+
}
|
|
197
|
+
getPaginatedItems() {
|
|
198
|
+
return this.data ?? [];
|
|
199
|
+
}
|
|
200
|
+
hasNextPage() {
|
|
201
|
+
return !!this.pagination.next;
|
|
202
|
+
}
|
|
203
|
+
hasPreviousPage() {
|
|
204
|
+
return !!this.pagination.previous;
|
|
205
|
+
}
|
|
206
|
+
getNextPage() {
|
|
207
|
+
if (!this.pagination.next) {
|
|
208
|
+
throw new Error("No next page available");
|
|
209
|
+
}
|
|
210
|
+
return this.pageFetcher({
|
|
211
|
+
after: this.pagination.next
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
getPreviousPage() {
|
|
215
|
+
if (!this.pagination.previous) {
|
|
216
|
+
throw new Error("No previous page available");
|
|
217
|
+
}
|
|
218
|
+
return this.pageFetcher({
|
|
219
|
+
before: this.pagination.previous
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
async *iterPages() {
|
|
223
|
+
let page = this;
|
|
224
|
+
yield page;
|
|
225
|
+
while (page.hasNextPage()) {
|
|
226
|
+
page = await page.getNextPage();
|
|
227
|
+
yield page;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
async *[Symbol.asyncIterator]() {
|
|
231
|
+
for await (const page of this.iterPages()) {
|
|
232
|
+
for (const item of page.getPaginatedItems()) {
|
|
233
|
+
yield item;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
__name(_CursorPage, "CursorPage");
|
|
239
|
+
var CursorPage = _CursorPage;
|
|
240
|
+
var _OffsetLimitPage = class _OffsetLimitPage {
|
|
241
|
+
constructor(data, pagination, pageFetcher) {
|
|
242
|
+
this.pageFetcher = pageFetcher;
|
|
243
|
+
this.data = data;
|
|
244
|
+
this.pagination = pagination;
|
|
245
|
+
}
|
|
246
|
+
getPaginatedItems() {
|
|
247
|
+
return this.data ?? [];
|
|
248
|
+
}
|
|
249
|
+
hasNextPage() {
|
|
250
|
+
return this.pagination.currentPage < this.pagination.totalPages;
|
|
251
|
+
}
|
|
252
|
+
hasPreviousPage() {
|
|
253
|
+
return this.pagination.currentPage > 1;
|
|
254
|
+
}
|
|
255
|
+
getNextPage() {
|
|
256
|
+
if (!this.hasNextPage()) {
|
|
257
|
+
throw new Error("No next page available");
|
|
258
|
+
}
|
|
259
|
+
return this.pageFetcher({
|
|
260
|
+
page: this.pagination.currentPage + 1
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
getPreviousPage() {
|
|
264
|
+
if (!this.hasPreviousPage()) {
|
|
265
|
+
throw new Error("No previous page available");
|
|
266
|
+
}
|
|
267
|
+
return this.pageFetcher({
|
|
268
|
+
page: this.pagination.currentPage - 1
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
async *iterPages() {
|
|
272
|
+
let page = this;
|
|
273
|
+
yield page;
|
|
274
|
+
while (page.hasNextPage()) {
|
|
275
|
+
page = await page.getNextPage();
|
|
276
|
+
yield page;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
async *[Symbol.asyncIterator]() {
|
|
280
|
+
for await (const page of this.iterPages()) {
|
|
281
|
+
for (const item of page.getPaginatedItems()) {
|
|
282
|
+
yield item;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
__name(_OffsetLimitPage, "OffsetLimitPage");
|
|
288
|
+
var OffsetLimitPage = _OffsetLimitPage;
|
|
289
|
+
|
|
290
|
+
// src/v3/apiClient/core.ts
|
|
291
|
+
var defaultRetryOptions2 = {
|
|
292
|
+
maxAttempts: 3,
|
|
293
|
+
factor: 2,
|
|
294
|
+
minTimeoutInMs: 1e3,
|
|
295
|
+
maxTimeoutInMs: 6e4,
|
|
296
|
+
randomize: false
|
|
297
|
+
};
|
|
298
|
+
function zodfetch(schema, url, requestInit, options) {
|
|
299
|
+
return new ApiPromise(_doZodFetch(schema, url, requestInit, options));
|
|
300
|
+
}
|
|
301
|
+
__name(zodfetch, "zodfetch");
|
|
302
|
+
function zodfetchCursorPage(schema, url, params, requestInit, options) {
|
|
303
|
+
const query = new URLSearchParams(params.query);
|
|
304
|
+
if (params.limit) {
|
|
305
|
+
query.set("page[size]", String(params.limit));
|
|
306
|
+
}
|
|
307
|
+
if (params.after) {
|
|
308
|
+
query.set("page[after]", params.after);
|
|
309
|
+
}
|
|
310
|
+
if (params.before) {
|
|
311
|
+
query.set("page[before]", params.before);
|
|
312
|
+
}
|
|
313
|
+
const cursorPageSchema = zod.z.object({
|
|
314
|
+
data: zod.z.array(schema),
|
|
315
|
+
pagination: zod.z.object({
|
|
316
|
+
next: zod.z.string().optional(),
|
|
317
|
+
previous: zod.z.string().optional()
|
|
318
|
+
})
|
|
319
|
+
});
|
|
320
|
+
const $url = new URL(url);
|
|
321
|
+
$url.search = query.toString();
|
|
322
|
+
const fetchResult = _doZodFetch(cursorPageSchema, $url.href, requestInit, options);
|
|
323
|
+
return new CursorPagePromise(fetchResult, schema, url, params, requestInit, options);
|
|
324
|
+
}
|
|
325
|
+
__name(zodfetchCursorPage, "zodfetchCursorPage");
|
|
326
|
+
function zodfetchOffsetLimitPage(schema, url, params, requestInit, options) {
|
|
327
|
+
const query = new URLSearchParams(params.query);
|
|
328
|
+
if (params.limit) {
|
|
329
|
+
query.set("perPage", String(params.limit));
|
|
330
|
+
}
|
|
331
|
+
if (params.page) {
|
|
332
|
+
query.set("page", String(params.page));
|
|
333
|
+
}
|
|
334
|
+
const offsetLimitPageSchema = zod.z.object({
|
|
335
|
+
data: zod.z.array(schema),
|
|
336
|
+
pagination: zod.z.object({
|
|
337
|
+
currentPage: zod.z.coerce.number(),
|
|
338
|
+
totalPages: zod.z.coerce.number(),
|
|
339
|
+
count: zod.z.coerce.number()
|
|
340
|
+
})
|
|
341
|
+
});
|
|
342
|
+
const $url = new URL(url);
|
|
343
|
+
$url.search = query.toString();
|
|
344
|
+
const fetchResult = _doZodFetch(offsetLimitPageSchema, $url.href, requestInit, options);
|
|
345
|
+
return new OffsetLimitPagePromise(fetchResult, schema, url, params, requestInit, options);
|
|
346
|
+
}
|
|
347
|
+
__name(zodfetchOffsetLimitPage, "zodfetchOffsetLimitPage");
|
|
348
|
+
function zodupload(schema, url, body, requestInit, options) {
|
|
349
|
+
const finalRequestInit = createMultipartFormRequestInit(body, requestInit);
|
|
350
|
+
return new ApiPromise(_doZodFetch(schema, url, finalRequestInit, options));
|
|
351
|
+
}
|
|
352
|
+
__name(zodupload, "zodupload");
|
|
353
|
+
async function createMultipartFormRequestInit(body, requestInit) {
|
|
354
|
+
const form = await createForm(body);
|
|
355
|
+
const encoder = new formDataEncoder.FormDataEncoder(form);
|
|
356
|
+
const finalHeaders = {};
|
|
357
|
+
for (const [key, value] of Object.entries(requestInit?.headers || {})) {
|
|
358
|
+
finalHeaders[key] = value;
|
|
359
|
+
}
|
|
360
|
+
for (const [key, value] of Object.entries(encoder.headers)) {
|
|
361
|
+
finalHeaders[key] = value;
|
|
362
|
+
}
|
|
363
|
+
finalHeaders["Content-Length"] = String(encoder.contentLength);
|
|
364
|
+
const finalRequestInit = {
|
|
365
|
+
...requestInit,
|
|
366
|
+
headers: finalHeaders,
|
|
367
|
+
body: stream.Readable.from(encoder),
|
|
368
|
+
// @ts-expect-error
|
|
369
|
+
duplex: "half"
|
|
370
|
+
};
|
|
371
|
+
return finalRequestInit;
|
|
372
|
+
}
|
|
373
|
+
__name(createMultipartFormRequestInit, "createMultipartFormRequestInit");
|
|
374
|
+
var createForm = /* @__PURE__ */ __name(async (body) => {
|
|
375
|
+
const form = new FormData();
|
|
376
|
+
await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));
|
|
377
|
+
return form;
|
|
378
|
+
}, "createForm");
|
|
379
|
+
async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
|
|
380
|
+
try {
|
|
381
|
+
const $requestInit = await requestInit;
|
|
382
|
+
const response = await fetch(url, requestInitWithCache($requestInit));
|
|
383
|
+
const responseHeaders = createResponseHeaders(response.headers);
|
|
384
|
+
if (!response.ok) {
|
|
385
|
+
const retryResult = shouldRetry(response, attempt, options?.retry);
|
|
386
|
+
if (retryResult.retry) {
|
|
387
|
+
await new Promise((resolve) => setTimeout(resolve, retryResult.delay));
|
|
388
|
+
return await _doZodFetch(schema, url, requestInit, options, attempt + 1);
|
|
389
|
+
} else {
|
|
390
|
+
const errText = await response.text().catch((e) => castToError2(e).message);
|
|
391
|
+
const errJSON = safeJsonParse(errText);
|
|
392
|
+
const errMessage = errJSON ? void 0 : errText;
|
|
393
|
+
throw ApiError.generate(response.status, errJSON, errMessage, responseHeaders);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
const jsonBody = await response.json();
|
|
397
|
+
const parsedResult = schema.safeParse(jsonBody);
|
|
398
|
+
if (parsedResult.success) {
|
|
399
|
+
return {
|
|
400
|
+
data: parsedResult.data,
|
|
401
|
+
response
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
throw zodValidationError.fromZodError(parsedResult.error);
|
|
405
|
+
} catch (error) {
|
|
406
|
+
if (error instanceof ApiError) {
|
|
407
|
+
throw error;
|
|
408
|
+
}
|
|
409
|
+
if (options?.retry) {
|
|
410
|
+
const retry = {
|
|
411
|
+
...defaultRetryOptions2,
|
|
412
|
+
...options.retry
|
|
413
|
+
};
|
|
414
|
+
const delay = calculateNextRetryDelay(retry, attempt);
|
|
415
|
+
if (delay) {
|
|
416
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
417
|
+
return await _doZodFetch(schema, url, requestInit, options, attempt + 1);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
throw new ApiConnectionError({
|
|
421
|
+
cause: castToError2(error)
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
__name(_doZodFetch, "_doZodFetch");
|
|
426
|
+
function castToError2(err) {
|
|
427
|
+
if (err instanceof Error)
|
|
428
|
+
return err;
|
|
429
|
+
return new Error(err);
|
|
430
|
+
}
|
|
431
|
+
__name(castToError2, "castToError");
|
|
432
|
+
function shouldRetry(response, attempt, retryOptions) {
|
|
433
|
+
function shouldRetryForOptions() {
|
|
434
|
+
const retry = {
|
|
435
|
+
...defaultRetryOptions2,
|
|
436
|
+
...retryOptions
|
|
437
|
+
};
|
|
438
|
+
const delay = calculateNextRetryDelay(retry, attempt);
|
|
439
|
+
if (delay) {
|
|
440
|
+
return {
|
|
441
|
+
retry: true,
|
|
442
|
+
delay
|
|
443
|
+
};
|
|
444
|
+
} else {
|
|
445
|
+
return {
|
|
446
|
+
retry: false
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
__name(shouldRetryForOptions, "shouldRetryForOptions");
|
|
451
|
+
const shouldRetryHeader = response.headers.get("x-should-retry");
|
|
452
|
+
if (shouldRetryHeader === "true")
|
|
453
|
+
return shouldRetryForOptions();
|
|
454
|
+
if (shouldRetryHeader === "false")
|
|
455
|
+
return {
|
|
456
|
+
retry: false
|
|
457
|
+
};
|
|
458
|
+
if (response.status === 408)
|
|
459
|
+
return shouldRetryForOptions();
|
|
460
|
+
if (response.status === 409)
|
|
461
|
+
return shouldRetryForOptions();
|
|
462
|
+
if (response.status === 429)
|
|
463
|
+
return shouldRetryForOptions();
|
|
464
|
+
if (response.status >= 500)
|
|
465
|
+
return shouldRetryForOptions();
|
|
466
|
+
return {
|
|
467
|
+
retry: false
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
__name(shouldRetry, "shouldRetry");
|
|
471
|
+
function safeJsonParse(text) {
|
|
472
|
+
try {
|
|
473
|
+
return JSON.parse(text);
|
|
474
|
+
} catch (e) {
|
|
475
|
+
return void 0;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
__name(safeJsonParse, "safeJsonParse");
|
|
479
|
+
function createResponseHeaders(headers) {
|
|
480
|
+
return new Proxy(Object.fromEntries(
|
|
481
|
+
// @ts-ignore
|
|
482
|
+
headers.entries()
|
|
483
|
+
), {
|
|
484
|
+
get(target, name) {
|
|
485
|
+
const key = name.toString();
|
|
486
|
+
return target[key.toLowerCase()] || target[key];
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
__name(createResponseHeaders, "createResponseHeaders");
|
|
491
|
+
function requestInitWithCache(requestInit) {
|
|
492
|
+
try {
|
|
493
|
+
const withCache = {
|
|
494
|
+
...requestInit,
|
|
495
|
+
cache: "no-cache"
|
|
496
|
+
};
|
|
497
|
+
const _ = new Request("http://localhost", withCache);
|
|
498
|
+
return withCache;
|
|
499
|
+
} catch (error) {
|
|
500
|
+
return requestInit ?? {};
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
__name(requestInitWithCache, "requestInitWithCache");
|
|
504
|
+
var addFormValue = /* @__PURE__ */ __name(async (form, key, value) => {
|
|
505
|
+
if (value === void 0)
|
|
506
|
+
return;
|
|
507
|
+
if (value == null) {
|
|
508
|
+
throw new TypeError(`Received null for "${key}"; to pass null in FormData, you must use the string 'null'`);
|
|
509
|
+
}
|
|
510
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
511
|
+
form.append(key, String(value));
|
|
512
|
+
} else if (isUploadable(value) || isBlobLike(value) || value instanceof Buffer || value instanceof ArrayBuffer) {
|
|
513
|
+
const file = await toFile(value);
|
|
514
|
+
form.append(key, file);
|
|
515
|
+
} else if (Array.isArray(value)) {
|
|
516
|
+
await Promise.all(value.map((entry) => addFormValue(form, key + "[]", entry)));
|
|
517
|
+
} else if (typeof value === "object") {
|
|
518
|
+
await Promise.all(Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop)));
|
|
519
|
+
} else {
|
|
520
|
+
throw new TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`);
|
|
521
|
+
}
|
|
522
|
+
}, "addFormValue");
|
|
523
|
+
async function toFile(value, name, options) {
|
|
524
|
+
value = await value;
|
|
525
|
+
options ??= isFileLike(value) ? {
|
|
526
|
+
lastModified: value.lastModified,
|
|
527
|
+
type: value.type
|
|
528
|
+
} : {};
|
|
529
|
+
if (isResponseLike(value)) {
|
|
530
|
+
const blob = await value.blob();
|
|
531
|
+
name ||= new URL(value.url).pathname.split(/[\\/]/).pop() ?? "unknown_file";
|
|
532
|
+
return new File([
|
|
533
|
+
blob
|
|
534
|
+
], name, options);
|
|
535
|
+
}
|
|
536
|
+
const bits = await getBytes(value);
|
|
537
|
+
name ||= getName(value) ?? "unknown_file";
|
|
538
|
+
if (!options.type) {
|
|
539
|
+
const type = bits[0]?.type;
|
|
540
|
+
if (typeof type === "string") {
|
|
541
|
+
options = {
|
|
542
|
+
...options,
|
|
543
|
+
type
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
return new File(bits, name, options);
|
|
548
|
+
}
|
|
549
|
+
__name(toFile, "toFile");
|
|
550
|
+
function getName(value) {
|
|
551
|
+
return getStringFromMaybeBuffer(value.name) || getStringFromMaybeBuffer(value.filename) || // For fs.ReadStream
|
|
552
|
+
getStringFromMaybeBuffer(value.path)?.split(/[\\/]/).pop();
|
|
553
|
+
}
|
|
554
|
+
__name(getName, "getName");
|
|
555
|
+
var getStringFromMaybeBuffer = /* @__PURE__ */ __name((x) => {
|
|
556
|
+
if (typeof x === "string")
|
|
557
|
+
return x;
|
|
558
|
+
if (typeof Buffer !== "undefined" && x instanceof Buffer)
|
|
559
|
+
return String(x);
|
|
560
|
+
return void 0;
|
|
561
|
+
}, "getStringFromMaybeBuffer");
|
|
562
|
+
async function getBytes(value) {
|
|
563
|
+
let parts = [];
|
|
564
|
+
if (typeof value === "string" || ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.
|
|
565
|
+
value instanceof ArrayBuffer) {
|
|
566
|
+
parts.push(value);
|
|
567
|
+
} else if (isBlobLike(value)) {
|
|
568
|
+
parts.push(await value.arrayBuffer());
|
|
569
|
+
} else if (isAsyncIterableIterator(value)) {
|
|
570
|
+
for await (const chunk of value) {
|
|
571
|
+
parts.push(chunk);
|
|
572
|
+
}
|
|
573
|
+
} else {
|
|
574
|
+
throw new Error(`Unexpected data type: ${typeof value}; constructor: ${value?.constructor?.name}; props: ${propsForError(value)}`);
|
|
575
|
+
}
|
|
576
|
+
return parts;
|
|
577
|
+
}
|
|
578
|
+
__name(getBytes, "getBytes");
|
|
579
|
+
function propsForError(value) {
|
|
580
|
+
const props = Object.getOwnPropertyNames(value);
|
|
581
|
+
return `[${props.map((p) => `"${p}"`).join(", ")}]`;
|
|
582
|
+
}
|
|
583
|
+
__name(propsForError, "propsForError");
|
|
584
|
+
var isAsyncIterableIterator = /* @__PURE__ */ __name((value) => value != null && typeof value === "object" && typeof value[Symbol.asyncIterator] === "function", "isAsyncIterableIterator");
|
|
585
|
+
var isResponseLike = /* @__PURE__ */ __name((value) => value != null && typeof value === "object" && typeof value.url === "string" && typeof value.blob === "function", "isResponseLike");
|
|
586
|
+
var isFileLike = /* @__PURE__ */ __name((value) => value != null && typeof value === "object" && typeof value.name === "string" && typeof value.lastModified === "number" && isBlobLike(value), "isFileLike");
|
|
587
|
+
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");
|
|
588
|
+
var isFsReadStream = /* @__PURE__ */ __name((value) => value instanceof stream.Readable, "isFsReadStream");
|
|
589
|
+
var isUploadable = /* @__PURE__ */ __name((value) => {
|
|
590
|
+
return isFileLike(value) || isResponseLike(value) || isFsReadStream(value);
|
|
591
|
+
}, "isUploadable");
|
|
592
|
+
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");
|
|
593
|
+
var _ApiPromise = class _ApiPromise extends Promise {
|
|
594
|
+
constructor(responsePromise) {
|
|
595
|
+
super((resolve) => {
|
|
596
|
+
resolve(null);
|
|
597
|
+
});
|
|
598
|
+
this.responsePromise = responsePromise;
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Gets the raw `Response` instance instead of parsing the response
|
|
602
|
+
* data.
|
|
603
|
+
*
|
|
604
|
+
* If you want to parse the response body but still get the `Response`
|
|
605
|
+
* instance, you can use {@link withResponse()}.
|
|
606
|
+
*/
|
|
607
|
+
asResponse() {
|
|
608
|
+
return this.responsePromise.then((p) => p.response);
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Gets the parsed response data and the raw `Response` instance.
|
|
612
|
+
*
|
|
613
|
+
* If you just want to get the raw `Response` instance without parsing it,
|
|
614
|
+
* you can use {@link asResponse()}.
|
|
615
|
+
*/
|
|
616
|
+
async withResponse() {
|
|
617
|
+
const [data, response] = await Promise.all([
|
|
618
|
+
this.parse(),
|
|
619
|
+
this.asResponse()
|
|
620
|
+
]);
|
|
621
|
+
return {
|
|
622
|
+
data,
|
|
623
|
+
response
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
parse() {
|
|
627
|
+
return this.responsePromise.then((result) => result.data);
|
|
628
|
+
}
|
|
629
|
+
then(onfulfilled, onrejected) {
|
|
630
|
+
return this.parse().then(onfulfilled, onrejected);
|
|
631
|
+
}
|
|
632
|
+
catch(onrejected) {
|
|
633
|
+
return this.parse().catch(onrejected);
|
|
634
|
+
}
|
|
635
|
+
finally(onfinally) {
|
|
636
|
+
return this.parse().finally(onfinally);
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
__name(_ApiPromise, "ApiPromise");
|
|
640
|
+
var ApiPromise = _ApiPromise;
|
|
641
|
+
var _fetchPage, fetchPage_fn;
|
|
642
|
+
var _CursorPagePromise = class _CursorPagePromise extends ApiPromise {
|
|
643
|
+
constructor(result, schema, url, params, requestInit, options) {
|
|
644
|
+
super(result.then((result2) => ({
|
|
645
|
+
data: new CursorPage(result2.data.data, result2.data.pagination, __privateMethod(this, _fetchPage, fetchPage_fn).bind(this)),
|
|
646
|
+
response: result2.response
|
|
647
|
+
})));
|
|
648
|
+
__privateAdd(this, _fetchPage);
|
|
649
|
+
this.schema = schema;
|
|
650
|
+
this.url = url;
|
|
651
|
+
this.params = params;
|
|
652
|
+
this.requestInit = requestInit;
|
|
653
|
+
this.options = options;
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Allow auto-paginating iteration on an unawaited list call, eg:
|
|
657
|
+
*
|
|
658
|
+
* for await (const item of client.items.list()) {
|
|
659
|
+
* console.log(item)
|
|
660
|
+
* }
|
|
661
|
+
*/
|
|
662
|
+
async *[Symbol.asyncIterator]() {
|
|
663
|
+
const page = await this;
|
|
664
|
+
for await (const item of page) {
|
|
665
|
+
yield item;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
};
|
|
669
|
+
_fetchPage = new WeakSet();
|
|
670
|
+
fetchPage_fn = /* @__PURE__ */ __name(function(params) {
|
|
671
|
+
return zodfetchCursorPage(this.schema, this.url, {
|
|
672
|
+
...this.params,
|
|
673
|
+
...params
|
|
674
|
+
}, this.requestInit, this.options);
|
|
675
|
+
}, "#fetchPage");
|
|
676
|
+
__name(_CursorPagePromise, "CursorPagePromise");
|
|
677
|
+
var CursorPagePromise = _CursorPagePromise;
|
|
678
|
+
var _fetchPage2, fetchPage_fn2;
|
|
679
|
+
var _OffsetLimitPagePromise = class _OffsetLimitPagePromise extends ApiPromise {
|
|
680
|
+
constructor(result, schema, url, params, requestInit, options) {
|
|
681
|
+
super(result.then((result2) => ({
|
|
682
|
+
data: new OffsetLimitPage(result2.data.data, result2.data.pagination, __privateMethod(this, _fetchPage2, fetchPage_fn2).bind(this)),
|
|
683
|
+
response: result2.response
|
|
684
|
+
})));
|
|
685
|
+
__privateAdd(this, _fetchPage2);
|
|
686
|
+
this.schema = schema;
|
|
687
|
+
this.url = url;
|
|
688
|
+
this.params = params;
|
|
689
|
+
this.requestInit = requestInit;
|
|
690
|
+
this.options = options;
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* Allow auto-paginating iteration on an unawaited list call, eg:
|
|
694
|
+
*
|
|
695
|
+
* for await (const item of client.items.list()) {
|
|
696
|
+
* console.log(item)
|
|
697
|
+
* }
|
|
698
|
+
*/
|
|
699
|
+
async *[Symbol.asyncIterator]() {
|
|
700
|
+
const page = await this;
|
|
701
|
+
for await (const item of page) {
|
|
702
|
+
yield item;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
_fetchPage2 = new WeakSet();
|
|
707
|
+
fetchPage_fn2 = /* @__PURE__ */ __name(function(params1) {
|
|
708
|
+
return zodfetchOffsetLimitPage(this.schema, this.url, {
|
|
709
|
+
...this.params,
|
|
710
|
+
...params1
|
|
711
|
+
}, this.requestInit, this.options);
|
|
712
|
+
}, "#fetchPage");
|
|
713
|
+
__name(_OffsetLimitPagePromise, "OffsetLimitPagePromise");
|
|
714
|
+
var OffsetLimitPagePromise = _OffsetLimitPagePromise;
|
|
715
|
+
|
|
716
|
+
exports.ApiConnectionError = ApiConnectionError;
|
|
717
|
+
exports.ApiError = ApiError;
|
|
718
|
+
exports.ApiPromise = ApiPromise;
|
|
719
|
+
exports.AuthenticationError = AuthenticationError;
|
|
720
|
+
exports.BadRequestError = BadRequestError;
|
|
721
|
+
exports.ConflictError = ConflictError;
|
|
722
|
+
exports.CursorPage = CursorPage;
|
|
723
|
+
exports.CursorPagePromise = CursorPagePromise;
|
|
724
|
+
exports.InternalServerError = InternalServerError;
|
|
725
|
+
exports.NotFoundError = NotFoundError;
|
|
726
|
+
exports.OffsetLimitPage = OffsetLimitPage;
|
|
727
|
+
exports.OffsetLimitPagePromise = OffsetLimitPagePromise;
|
|
728
|
+
exports.PermissionDeniedError = PermissionDeniedError;
|
|
729
|
+
exports.RateLimitError = RateLimitError;
|
|
730
|
+
exports.UnprocessableEntityError = UnprocessableEntityError;
|
|
731
|
+
exports.defaultRetryOptions = defaultRetryOptions2;
|
|
732
|
+
exports.isBlobLike = isBlobLike;
|
|
733
|
+
exports.isFileLike = isFileLike;
|
|
734
|
+
exports.isFsReadStream = isFsReadStream;
|
|
735
|
+
exports.isRecordLike = isRecordLike;
|
|
736
|
+
exports.isResponseLike = isResponseLike;
|
|
737
|
+
exports.isUploadable = isUploadable;
|
|
738
|
+
exports.toFile = toFile;
|
|
739
|
+
exports.zodfetch = zodfetch;
|
|
740
|
+
exports.zodfetchCursorPage = zodfetchCursorPage;
|
|
741
|
+
exports.zodfetchOffsetLimitPage = zodfetchOffsetLimitPage;
|
|
742
|
+
exports.zodupload = zodupload;
|
|
743
|
+
//# sourceMappingURL=out.js.map
|
|
744
|
+
//# sourceMappingURL=zodfetch.js.map
|