@trigger.dev/core 3.0.0-beta.46 → 3.0.0-beta.47

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.
Files changed (45) hide show
  1. package/dist/{catalog-9G8AqnI9.d.ts → catalog-N-X0Te3W.d.mts} +5 -23
  2. package/dist/{catalog-Y0mRLMtJ.d.mts → catalog-NxVZnWZh.d.ts} +5 -23
  3. package/dist/{common-55Mqj8JP.d.mts → common-fIyU5pmz.d.mts} +13 -0
  4. package/dist/{common-55Mqj8JP.d.ts → common-fIyU5pmz.d.ts} +13 -0
  5. package/dist/{manager-6NRInm7C.d.ts → manager-2ZQ3_twq.d.ts} +1 -1
  6. package/dist/{manager-2AqSY67c.d.mts → manager-X_HrWQ7_.d.mts} +1 -1
  7. package/dist/{messages-nXkzt5CT.d.mts → messages-Sggr4tid.d.mts} +162 -0
  8. package/dist/{messages-nXkzt5CT.d.ts → messages-Sggr4tid.d.ts} +162 -0
  9. package/dist/{schemas-CeAee_C2.d.mts → schemas-Zy7mGFgD.d.mts} +19 -0
  10. package/dist/{schemas-CeAee_C2.d.ts → schemas-Zy7mGFgD.d.ts} +19 -0
  11. package/dist/tracer-N0p2Fuuv.d.mts +23 -0
  12. package/dist/tracer-N0p2Fuuv.d.ts +23 -0
  13. package/dist/v3/dev/index.d.mts +2 -2
  14. package/dist/v3/dev/index.d.ts +2 -2
  15. package/dist/v3/index.d.mts +50 -38
  16. package/dist/v3/index.d.ts +50 -38
  17. package/dist/v3/index.js +470 -303
  18. package/dist/v3/index.js.map +1 -1
  19. package/dist/v3/index.mjs +467 -304
  20. package/dist/v3/index.mjs.map +1 -1
  21. package/dist/v3/otel/index.js +15 -5
  22. package/dist/v3/otel/index.js.map +1 -1
  23. package/dist/v3/otel/index.mjs +15 -5
  24. package/dist/v3/otel/index.mjs.map +1 -1
  25. package/dist/v3/prod/index.d.mts +3 -3
  26. package/dist/v3/prod/index.d.ts +3 -3
  27. package/dist/v3/schemas/index.d.mts +16 -4
  28. package/dist/v3/schemas/index.d.ts +16 -4
  29. package/dist/v3/schemas/index.js +3 -1
  30. package/dist/v3/schemas/index.js.map +1 -1
  31. package/dist/v3/schemas/index.mjs +3 -1
  32. package/dist/v3/schemas/index.mjs.map +1 -1
  33. package/dist/v3/workers/index.d.mts +7 -6
  34. package/dist/v3/workers/index.d.ts +7 -6
  35. package/dist/v3/workers/index.js +250 -96
  36. package/dist/v3/workers/index.js.map +1 -1
  37. package/dist/v3/workers/index.mjs +250 -96
  38. package/dist/v3/workers/index.mjs.map +1 -1
  39. package/dist/v3/zodfetch.d.mts +15 -2
  40. package/dist/v3/zodfetch.d.ts +15 -2
  41. package/dist/v3/zodfetch.js +248 -28
  42. package/dist/v3/zodfetch.js.map +1 -1
  43. package/dist/v3/zodfetch.mjs +246 -29
  44. package/dist/v3/zodfetch.mjs.map +1 -1
  45. package/package.json +1 -1
@@ -1,5 +1,8 @@
1
1
  import { z } from 'zod';
2
- import { R as RetryOptions } from '../schemas-CeAee_C2.mjs';
2
+ import { R as RetryOptions } from '../schemas-Zy7mGFgD.mjs';
3
+ import { Attributes, Span } from '@opentelemetry/api';
4
+ import { T as TriggerTracer } from '../tracer-N0p2Fuuv.mjs';
5
+ import '@opentelemetry/api-logs';
3
6
 
4
7
  interface CursorPageParams {
5
8
  limit?: number;
@@ -81,7 +84,14 @@ declare const defaultRetryOptions: {
81
84
  };
82
85
  type ZodFetchOptions = {
83
86
  retry?: RetryOptions;
87
+ tracer?: TriggerTracer;
88
+ name?: string;
89
+ attributes?: Attributes;
90
+ icon?: string;
91
+ onResponseBody?: (body: unknown, span: Span) => void;
84
92
  };
93
+ type ApiRequestOptions = Pick<ZodFetchOptions, "retry">;
94
+ declare const isRequestOptions: (obj: unknown) => obj is ApiRequestOptions;
85
95
  interface FetchCursorPageParams extends CursorPageParams {
86
96
  query?: URLSearchParams;
87
97
  }
@@ -159,6 +169,8 @@ declare class OffsetLimitPagePromise<TItemSchema extends z.ZodTypeAny> extends A
159
169
  */
160
170
  [Symbol.asyncIterator](): AsyncGenerator<Awaited<z.output<TItemSchema>>, void, unknown>;
161
171
  }
172
+ declare function isEmptyObj(obj: Object | null | undefined): boolean;
173
+ declare function hasOwn(obj: Object, key: string): boolean;
162
174
 
163
175
  type APIHeaders = Record<string, string | null | undefined>;
164
176
  declare class ApiError extends Error {
@@ -199,8 +211,9 @@ declare class UnprocessableEntityError extends ApiError {
199
211
  }
200
212
  declare class RateLimitError extends ApiError {
201
213
  readonly status: 429;
214
+ get millisecondsUntilReset(): number | undefined;
202
215
  }
203
216
  declare class InternalServerError extends ApiError {
204
217
  }
205
218
 
206
- export { type APIHeaders, ApiConnectionError, ApiError, ApiPromise, AuthenticationError, BadRequestError, ConflictError, CursorPage, type CursorPageParams, CursorPagePromise, type CursorPageResponse, InternalServerError, NotFoundError, OffsetLimitPage, type OffsetLimitPageParams, OffsetLimitPagePromise, type OffsetLimitPageResponse, type Page, type PageResponse, PermissionDeniedError, RateLimitError, UnprocessableEntityError, type ZodFetchOptions, defaultRetryOptions, zodfetch, zodfetchCursorPage, zodfetchOffsetLimitPage };
219
+ export { type APIHeaders, ApiConnectionError, ApiError, ApiPromise, type ApiRequestOptions, AuthenticationError, BadRequestError, ConflictError, CursorPage, type CursorPageParams, CursorPagePromise, type CursorPageResponse, InternalServerError, NotFoundError, OffsetLimitPage, type OffsetLimitPageParams, OffsetLimitPagePromise, type OffsetLimitPageResponse, type Page, type PageResponse, PermissionDeniedError, RateLimitError, UnprocessableEntityError, type ZodFetchOptions, defaultRetryOptions, hasOwn, isEmptyObj, isRequestOptions, zodfetch, zodfetchCursorPage, zodfetchOffsetLimitPage };
@@ -1,5 +1,8 @@
1
1
  import { z } from 'zod';
2
- import { R as RetryOptions } from '../schemas-CeAee_C2.js';
2
+ import { R as RetryOptions } from '../schemas-Zy7mGFgD.js';
3
+ import { Attributes, Span } from '@opentelemetry/api';
4
+ import { T as TriggerTracer } from '../tracer-N0p2Fuuv.js';
5
+ import '@opentelemetry/api-logs';
3
6
 
4
7
  interface CursorPageParams {
5
8
  limit?: number;
@@ -81,7 +84,14 @@ declare const defaultRetryOptions: {
81
84
  };
82
85
  type ZodFetchOptions = {
83
86
  retry?: RetryOptions;
87
+ tracer?: TriggerTracer;
88
+ name?: string;
89
+ attributes?: Attributes;
90
+ icon?: string;
91
+ onResponseBody?: (body: unknown, span: Span) => void;
84
92
  };
93
+ type ApiRequestOptions = Pick<ZodFetchOptions, "retry">;
94
+ declare const isRequestOptions: (obj: unknown) => obj is ApiRequestOptions;
85
95
  interface FetchCursorPageParams extends CursorPageParams {
86
96
  query?: URLSearchParams;
87
97
  }
@@ -159,6 +169,8 @@ declare class OffsetLimitPagePromise<TItemSchema extends z.ZodTypeAny> extends A
159
169
  */
160
170
  [Symbol.asyncIterator](): AsyncGenerator<Awaited<z.output<TItemSchema>>, void, unknown>;
161
171
  }
172
+ declare function isEmptyObj(obj: Object | null | undefined): boolean;
173
+ declare function hasOwn(obj: Object, key: string): boolean;
162
174
 
163
175
  type APIHeaders = Record<string, string | null | undefined>;
164
176
  declare class ApiError extends Error {
@@ -199,8 +211,9 @@ declare class UnprocessableEntityError extends ApiError {
199
211
  }
200
212
  declare class RateLimitError extends ApiError {
201
213
  readonly status: 429;
214
+ get millisecondsUntilReset(): number | undefined;
202
215
  }
203
216
  declare class InternalServerError extends ApiError {
204
217
  }
205
218
 
206
- export { type APIHeaders, ApiConnectionError, ApiError, ApiPromise, AuthenticationError, BadRequestError, ConflictError, CursorPage, type CursorPageParams, CursorPagePromise, type CursorPageResponse, InternalServerError, NotFoundError, OffsetLimitPage, type OffsetLimitPageParams, OffsetLimitPagePromise, type OffsetLimitPageResponse, type Page, type PageResponse, PermissionDeniedError, RateLimitError, UnprocessableEntityError, type ZodFetchOptions, defaultRetryOptions, zodfetch, zodfetchCursorPage, zodfetchOffsetLimitPage };
219
+ export { type APIHeaders, ApiConnectionError, ApiError, ApiPromise, type ApiRequestOptions, AuthenticationError, BadRequestError, ConflictError, CursorPage, type CursorPageParams, CursorPagePromise, type CursorPageResponse, InternalServerError, NotFoundError, OffsetLimitPage, type OffsetLimitPageParams, OffsetLimitPagePromise, type OffsetLimitPageResponse, type Page, type PageResponse, PermissionDeniedError, RateLimitError, UnprocessableEntityError, type ZodFetchOptions, defaultRetryOptions, hasOwn, isEmptyObj, isRequestOptions, zodfetch, zodfetchCursorPage, zodfetchOffsetLimitPage };
@@ -24,10 +24,34 @@ var __privateMethod = (obj, member, method) => {
24
24
  return method;
25
25
  };
26
26
 
27
+ // src/v3/utils/retries.ts
28
+ var defaultRetryOptions = {
29
+ maxAttempts: 3,
30
+ factor: 2,
31
+ minTimeoutInMs: 1e3,
32
+ maxTimeoutInMs: 6e4,
33
+ randomize: true
34
+ };
35
+ function calculateNextRetryDelay(options, attempt) {
36
+ const opts = {
37
+ ...defaultRetryOptions,
38
+ ...options
39
+ };
40
+ if (attempt >= opts.maxAttempts) {
41
+ return;
42
+ }
43
+ const { factor, minTimeoutInMs, maxTimeoutInMs, randomize } = opts;
44
+ const random = randomize ? Math.random() + 1 : 1;
45
+ const timeout = Math.min(maxTimeoutInMs, random * minTimeoutInMs * Math.pow(factor, attempt - 1));
46
+ return Math.round(timeout);
47
+ }
48
+ __name(calculateNextRetryDelay, "calculateNextRetryDelay");
49
+
27
50
  // src/v3/apiClient/errors.ts
28
51
  var _ApiError = class _ApiError extends Error {
29
52
  constructor(status, error, message, headers) {
30
53
  super(`${_ApiError.makeMessage(status, error, message)}`);
54
+ this.name = "TriggerApiError";
31
55
  this.status = status;
32
56
  this.headers = headers;
33
57
  const data = error;
@@ -148,6 +172,16 @@ var _RateLimitError = class _RateLimitError extends ApiError {
148
172
  super(...arguments);
149
173
  __publicField(this, "status", 429);
150
174
  }
175
+ get millisecondsUntilReset() {
176
+ const resetAtUnixEpochMs = (this.headers ?? {})["x-ratelimit-reset"];
177
+ if (typeof resetAtUnixEpochMs === "string") {
178
+ const resetAtUnixEpoch = parseInt(resetAtUnixEpochMs, 10);
179
+ if (isNaN(resetAtUnixEpoch)) {
180
+ return;
181
+ }
182
+ return Math.max(resetAtUnixEpoch - Date.now() + Math.floor(Math.random() * 2e3), 0);
183
+ }
184
+ }
151
185
  };
152
186
  __name(_RateLimitError, "RateLimitError");
153
187
  var RateLimitError = _RateLimitError;
@@ -162,28 +196,122 @@ function castToError(err) {
162
196
  }
163
197
  __name(castToError, "castToError");
164
198
 
165
- // src/v3/utils/retries.ts
166
- var defaultRetryOptions = {
167
- maxAttempts: 3,
168
- factor: 2,
169
- minTimeoutInMs: 1e3,
170
- maxTimeoutInMs: 6e4,
171
- randomize: true
199
+ // src/v3/semanticInternalAttributes.ts
200
+ var SemanticInternalAttributes = {
201
+ ENVIRONMENT_ID: "ctx.environment.id",
202
+ ENVIRONMENT_TYPE: "ctx.environment.type",
203
+ ORGANIZATION_ID: "ctx.organization.id",
204
+ ORGANIZATION_SLUG: "ctx.organization.slug",
205
+ ORGANIZATION_NAME: "ctx.organization.name",
206
+ PROJECT_ID: "ctx.project.id",
207
+ PROJECT_REF: "ctx.project.ref",
208
+ PROJECT_NAME: "ctx.project.title",
209
+ PROJECT_DIR: "project.dir",
210
+ ATTEMPT_ID: "ctx.attempt.id",
211
+ ATTEMPT_NUMBER: "ctx.attempt.number",
212
+ RUN_ID: "ctx.run.id",
213
+ RUN_IS_TEST: "ctx.run.isTest",
214
+ BATCH_ID: "ctx.batch.id",
215
+ TASK_SLUG: "ctx.task.id",
216
+ TASK_PATH: "ctx.task.filePath",
217
+ TASK_EXPORT_NAME: "ctx.task.exportName",
218
+ QUEUE_NAME: "ctx.queue.name",
219
+ QUEUE_ID: "ctx.queue.id",
220
+ MACHINE_PRESET_NAME: "ctx.machine.name",
221
+ MACHINE_PRESET_CPU: "ctx.machine.cpu",
222
+ MACHINE_PRESET_MEMORY: "ctx.machine.memory",
223
+ MACHINE_PRESET_CENTS_PER_MS: "ctx.machine.centsPerMs",
224
+ SPAN_PARTIAL: "$span.partial",
225
+ SPAN_ID: "$span.span_id",
226
+ OUTPUT: "$output",
227
+ OUTPUT_TYPE: "$mime_type_output",
228
+ STYLE: "$style",
229
+ STYLE_ICON: "$style.icon",
230
+ STYLE_VARIANT: "$style.variant",
231
+ STYLE_ACCESSORY: "$style.accessory",
232
+ METADATA: "$metadata",
233
+ TRIGGER: "$trigger",
234
+ PAYLOAD: "$payload",
235
+ PAYLOAD_TYPE: "$mime_type_payload",
236
+ SHOW: "$show",
237
+ SHOW_ACTIONS: "$show.actions",
238
+ WORKER_ID: "worker.id",
239
+ WORKER_VERSION: "worker.version",
240
+ CLI_VERSION: "cli.version",
241
+ SDK_VERSION: "sdk.version",
242
+ SDK_LANGUAGE: "sdk.language",
243
+ RETRY_AT: "retry.at",
244
+ RETRY_DELAY: "retry.delay",
245
+ RETRY_COUNT: "retry.count",
246
+ LINK_TITLE: "$link.title",
247
+ IDEMPOTENCY_KEY: "ctx.run.idempotencyKey",
248
+ USAGE_DURATION_MS: "$usage.durationMs",
249
+ USAGE_COST_IN_CENTS: "$usage.costInCents",
250
+ RATE_LIMIT_LIMIT: "response.rateLimit.limit",
251
+ RATE_LIMIT_REMAINING: "response.rateLimit.remaining",
252
+ RATE_LIMIT_RESET: "response.rateLimit.reset"
172
253
  };
173
- function calculateNextRetryDelay(options, attempt) {
174
- const opts = {
175
- ...defaultRetryOptions,
176
- ...options
177
- };
178
- if (attempt >= opts.maxAttempts) {
179
- return;
254
+
255
+ // src/v3/utils/flattenAttributes.ts
256
+ var NULL_SENTINEL = "$@null((";
257
+ function flattenAttributes(obj, prefix) {
258
+ const result = {};
259
+ if (obj === void 0) {
260
+ return result;
261
+ }
262
+ if (obj === null) {
263
+ result[prefix || ""] = NULL_SENTINEL;
264
+ return result;
265
+ }
266
+ if (typeof obj === "string") {
267
+ result[prefix || ""] = obj;
268
+ return result;
269
+ }
270
+ if (typeof obj === "number") {
271
+ result[prefix || ""] = obj;
272
+ return result;
273
+ }
274
+ if (typeof obj === "boolean") {
275
+ result[prefix || ""] = obj;
276
+ return result;
277
+ }
278
+ for (const [key, value] of Object.entries(obj)) {
279
+ const newPrefix = `${prefix ? `${prefix}.` : ""}${Array.isArray(obj) ? `[${key}]` : key}`;
280
+ if (Array.isArray(value)) {
281
+ for (let i = 0; i < value.length; i++) {
282
+ if (typeof value[i] === "object" && value[i] !== null) {
283
+ Object.assign(result, flattenAttributes(value[i], `${newPrefix}.[${i}]`));
284
+ } else {
285
+ if (value[i] === null) {
286
+ result[`${newPrefix}.[${i}]`] = NULL_SENTINEL;
287
+ } else {
288
+ result[`${newPrefix}.[${i}]`] = value[i];
289
+ }
290
+ }
291
+ }
292
+ } else if (isRecord(value)) {
293
+ Object.assign(result, flattenAttributes(value, newPrefix));
294
+ } else {
295
+ if (typeof value === "number" || typeof value === "string" || typeof value === "boolean") {
296
+ result[newPrefix] = value;
297
+ } else if (value === null) {
298
+ result[newPrefix] = NULL_SENTINEL;
299
+ }
300
+ }
180
301
  }
181
- const { factor, minTimeoutInMs, maxTimeoutInMs, randomize } = opts;
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);
302
+ return result;
185
303
  }
186
- __name(calculateNextRetryDelay, "calculateNextRetryDelay");
304
+ __name(flattenAttributes, "flattenAttributes");
305
+ function isRecord(value) {
306
+ return value !== null && typeof value === "object" && !Array.isArray(value);
307
+ }
308
+ __name(isRecord, "isRecord");
309
+
310
+ // src/v3/utils/styleAttributes.ts
311
+ function accessoryAttributes(accessory) {
312
+ return flattenAttributes(accessory, SemanticInternalAttributes.STYLE_ACCESSORY);
313
+ }
314
+ __name(accessoryAttributes, "accessoryAttributes");
187
315
 
188
316
  // src/v3/apiClient/pagination.ts
189
317
  var _CursorPage = class _CursorPage {
@@ -293,6 +421,12 @@ var defaultRetryOptions2 = {
293
421
  maxTimeoutInMs: 6e4,
294
422
  randomize: false
295
423
  };
424
+ var requestOptionsKeys = {
425
+ retry: true
426
+ };
427
+ var isRequestOptions = /* @__PURE__ */ __name((obj) => {
428
+ return typeof obj === "object" && obj !== null && !isEmptyObj(obj) && Object.keys(obj).every((k) => hasOwn(requestOptionsKeys, k));
429
+ }, "isRequestOptions");
296
430
  function zodfetch(schema, url, requestInit, options) {
297
431
  return new ApiPromise(_doZodFetch(schema, url, requestInit, options));
298
432
  }
@@ -343,16 +477,47 @@ function zodfetchOffsetLimitPage(schema, url, params, requestInit, options) {
343
477
  return new OffsetLimitPagePromise(fetchResult, schema, url, params, requestInit, options);
344
478
  }
345
479
  __name(zodfetchOffsetLimitPage, "zodfetchOffsetLimitPage");
346
- async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
480
+ async function traceZodFetch(params, callback) {
481
+ if (!params.options?.tracer) {
482
+ return callback();
483
+ }
484
+ const url = new URL(params.url);
485
+ const method = params.requestInit?.method ?? "GET";
486
+ const name = params.options.name ?? `${method} ${url.pathname}`;
487
+ return await params.options.tracer.startActiveSpan(name, async (span) => {
488
+ return await callback(span);
489
+ }, {
490
+ attributes: {
491
+ [SemanticInternalAttributes.STYLE_ICON]: params.options?.icon ?? "api",
492
+ ...params.options.attributes
493
+ }
494
+ });
495
+ }
496
+ __name(traceZodFetch, "traceZodFetch");
497
+ async function _doZodFetch(schema, url, requestInit, options) {
498
+ const $requestInit = await requestInit;
499
+ return traceZodFetch({
500
+ url,
501
+ requestInit: $requestInit,
502
+ options
503
+ }, async (span) => {
504
+ const result = await _doZodFetchWithRetries(schema, url, $requestInit, options);
505
+ if (options?.onResponseBody && span) {
506
+ options.onResponseBody(result.data, span);
507
+ }
508
+ return result;
509
+ });
510
+ }
511
+ __name(_doZodFetch, "_doZodFetch");
512
+ async function _doZodFetchWithRetries(schema, url, requestInit, options, attempt = 1) {
347
513
  try {
348
- const $requestInit = await requestInit;
349
- const response = await fetch(url, requestInitWithCache($requestInit));
514
+ const response = await fetch(url, requestInitWithCache(requestInit));
350
515
  const responseHeaders = createResponseHeaders(response.headers);
351
516
  if (!response.ok) {
352
517
  const retryResult = shouldRetry(response, attempt, options?.retry);
353
518
  if (retryResult.retry) {
354
- await new Promise((resolve) => setTimeout(resolve, retryResult.delay));
355
- return await _doZodFetch(schema, url, requestInit, options, attempt + 1);
519
+ await waitForRetry(url, attempt + 1, retryResult.delay, options, requestInit, response);
520
+ return await _doZodFetchWithRetries(schema, url, requestInit, options, attempt + 1);
356
521
  } else {
357
522
  const errText = await response.text().catch((e) => castToError2(e).message);
358
523
  const errJSON = safeJsonParse(errText);
@@ -380,8 +545,8 @@ async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
380
545
  };
381
546
  const delay = calculateNextRetryDelay(retry, attempt);
382
547
  if (delay) {
383
- await new Promise((resolve) => setTimeout(resolve, delay));
384
- return await _doZodFetch(schema, url, requestInit, options, attempt + 1);
548
+ await waitForRetry(url, attempt + 1, delay, options, requestInit);
549
+ return await _doZodFetchWithRetries(schema, url, requestInit, options, attempt + 1);
385
550
  }
386
551
  }
387
552
  throw new ApiConnectionError({
@@ -389,7 +554,7 @@ async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
389
554
  });
390
555
  }
391
556
  }
392
- __name(_doZodFetch, "_doZodFetch");
557
+ __name(_doZodFetchWithRetries, "_doZodFetchWithRetries");
393
558
  function castToError2(err) {
394
559
  if (err instanceof Error)
395
560
  return err;
@@ -426,8 +591,25 @@ function shouldRetry(response, attempt, retryOptions) {
426
591
  return shouldRetryForOptions();
427
592
  if (response.status === 409)
428
593
  return shouldRetryForOptions();
429
- if (response.status === 429)
594
+ if (response.status === 429) {
595
+ if (attempt >= (typeof retryOptions?.maxAttempts === "number" ? retryOptions?.maxAttempts : 3)) {
596
+ return {
597
+ retry: false
598
+ };
599
+ }
600
+ const resetAtUnixEpochMs = response.headers.get("x-ratelimit-reset");
601
+ if (resetAtUnixEpochMs) {
602
+ const resetAtUnixEpoch = parseInt(resetAtUnixEpochMs, 10);
603
+ const delay = resetAtUnixEpoch - Date.now() + Math.floor(Math.random() * 1e3);
604
+ if (delay > 0) {
605
+ return {
606
+ retry: true,
607
+ delay
608
+ };
609
+ }
610
+ }
430
611
  return shouldRetryForOptions();
612
+ }
431
613
  if (response.status >= 500)
432
614
  return shouldRetryForOptions();
433
615
  return {
@@ -590,6 +772,41 @@ fetchPage_fn2 = /* @__PURE__ */ __name(function(params1) {
590
772
  }, "#fetchPage");
591
773
  __name(_OffsetLimitPagePromise, "OffsetLimitPagePromise");
592
774
  var OffsetLimitPagePromise = _OffsetLimitPagePromise;
775
+ async function waitForRetry(url, attempt, delay, options, requestInit, response) {
776
+ if (options?.tracer) {
777
+ const method = requestInit?.method ?? "GET";
778
+ return options.tracer.startActiveSpan(response ? `wait after ${response.status}` : `wait after error`, async (span) => {
779
+ await new Promise((resolve) => setTimeout(resolve, delay));
780
+ }, {
781
+ attributes: {
782
+ [SemanticInternalAttributes.STYLE_ICON]: "wait",
783
+ ...accessoryAttributes({
784
+ items: [
785
+ {
786
+ text: `retrying ${options?.name ?? method.toUpperCase()} in ${delay}ms`,
787
+ variant: "normal"
788
+ }
789
+ ],
790
+ style: "codepath"
791
+ })
792
+ }
793
+ });
794
+ }
795
+ await new Promise((resolve) => setTimeout(resolve, delay));
796
+ }
797
+ __name(waitForRetry, "waitForRetry");
798
+ function isEmptyObj(obj) {
799
+ if (!obj)
800
+ return true;
801
+ for (const _k in obj)
802
+ return false;
803
+ return true;
804
+ }
805
+ __name(isEmptyObj, "isEmptyObj");
806
+ function hasOwn(obj, key) {
807
+ return Object.prototype.hasOwnProperty.call(obj, key);
808
+ }
809
+ __name(hasOwn, "hasOwn");
593
810
 
594
811
  exports.ApiConnectionError = ApiConnectionError;
595
812
  exports.ApiError = ApiError;
@@ -607,6 +824,9 @@ exports.PermissionDeniedError = PermissionDeniedError;
607
824
  exports.RateLimitError = RateLimitError;
608
825
  exports.UnprocessableEntityError = UnprocessableEntityError;
609
826
  exports.defaultRetryOptions = defaultRetryOptions2;
827
+ exports.hasOwn = hasOwn;
828
+ exports.isEmptyObj = isEmptyObj;
829
+ exports.isRequestOptions = isRequestOptions;
610
830
  exports.zodfetch = zodfetch;
611
831
  exports.zodfetchCursorPage = zodfetchCursorPage;
612
832
  exports.zodfetchOffsetLimitPage = zodfetchOffsetLimitPage;