@trigger.dev/core 0.0.0-v3-prerelease-20240703181409 → 0.0.0-v3-prerelease-20240708162325

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 +466 -303
  18. package/dist/v3/index.js.map +1 -1
  19. package/dist/v3/index.mjs +463 -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 +246 -96
  36. package/dist/v3/workers/index.js.map +1 -1
  37. package/dist/v3/workers/index.mjs +246 -96
  38. package/dist/v3/workers/index.mjs.map +1 -1
  39. package/dist/v3/zodfetch.d.mts +14 -2
  40. package/dist/v3/zodfetch.d.ts +14 -2
  41. package/dist/v3/zodfetch.js +244 -28
  42. package/dist/v3/zodfetch.js.map +1 -1
  43. package/dist/v3/zodfetch.mjs +242 -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 } 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,13 @@ 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;
84
91
  };
92
+ type ApiRequestOptions = Pick<ZodFetchOptions, "retry">;
93
+ declare const isRequestOptions: (obj: unknown) => obj is ApiRequestOptions;
85
94
  interface FetchCursorPageParams extends CursorPageParams {
86
95
  query?: URLSearchParams;
87
96
  }
@@ -159,6 +168,8 @@ declare class OffsetLimitPagePromise<TItemSchema extends z.ZodTypeAny> extends A
159
168
  */
160
169
  [Symbol.asyncIterator](): AsyncGenerator<Awaited<z.output<TItemSchema>>, void, unknown>;
161
170
  }
171
+ declare function isEmptyObj(obj: Object | null | undefined): boolean;
172
+ declare function hasOwn(obj: Object, key: string): boolean;
162
173
 
163
174
  type APIHeaders = Record<string, string | null | undefined>;
164
175
  declare class ApiError extends Error {
@@ -199,8 +210,9 @@ declare class UnprocessableEntityError extends ApiError {
199
210
  }
200
211
  declare class RateLimitError extends ApiError {
201
212
  readonly status: 429;
213
+ get millisecondsUntilReset(): number | undefined;
202
214
  }
203
215
  declare class InternalServerError extends ApiError {
204
216
  }
205
217
 
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 };
218
+ 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 } 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,13 @@ 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;
84
91
  };
92
+ type ApiRequestOptions = Pick<ZodFetchOptions, "retry">;
93
+ declare const isRequestOptions: (obj: unknown) => obj is ApiRequestOptions;
85
94
  interface FetchCursorPageParams extends CursorPageParams {
86
95
  query?: URLSearchParams;
87
96
  }
@@ -159,6 +168,8 @@ declare class OffsetLimitPagePromise<TItemSchema extends z.ZodTypeAny> extends A
159
168
  */
160
169
  [Symbol.asyncIterator](): AsyncGenerator<Awaited<z.output<TItemSchema>>, void, unknown>;
161
170
  }
171
+ declare function isEmptyObj(obj: Object | null | undefined): boolean;
172
+ declare function hasOwn(obj: Object, key: string): boolean;
162
173
 
163
174
  type APIHeaders = Record<string, string | null | undefined>;
164
175
  declare class ApiError extends Error {
@@ -199,8 +210,9 @@ declare class UnprocessableEntityError extends ApiError {
199
210
  }
200
211
  declare class RateLimitError extends ApiError {
201
212
  readonly status: 429;
213
+ get millisecondsUntilReset(): number | undefined;
202
214
  }
203
215
  declare class InternalServerError extends ApiError {
204
216
  }
205
217
 
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 };
218
+ 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,43 @@ 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
+ return await _doZodFetchWithRetries(schema, url, $requestInit, options);
505
+ });
506
+ }
507
+ __name(_doZodFetch, "_doZodFetch");
508
+ async function _doZodFetchWithRetries(schema, url, requestInit, options, attempt = 1) {
347
509
  try {
348
- const $requestInit = await requestInit;
349
- const response = await fetch(url, requestInitWithCache($requestInit));
510
+ const response = await fetch(url, requestInitWithCache(requestInit));
350
511
  const responseHeaders = createResponseHeaders(response.headers);
351
512
  if (!response.ok) {
352
513
  const retryResult = shouldRetry(response, attempt, options?.retry);
353
514
  if (retryResult.retry) {
354
- await new Promise((resolve) => setTimeout(resolve, retryResult.delay));
355
- return await _doZodFetch(schema, url, requestInit, options, attempt + 1);
515
+ await waitForRetry(url, attempt + 1, retryResult.delay, options, requestInit, response);
516
+ return await _doZodFetchWithRetries(schema, url, requestInit, options, attempt + 1);
356
517
  } else {
357
518
  const errText = await response.text().catch((e) => castToError2(e).message);
358
519
  const errJSON = safeJsonParse(errText);
@@ -380,8 +541,8 @@ async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
380
541
  };
381
542
  const delay = calculateNextRetryDelay(retry, attempt);
382
543
  if (delay) {
383
- await new Promise((resolve) => setTimeout(resolve, delay));
384
- return await _doZodFetch(schema, url, requestInit, options, attempt + 1);
544
+ await waitForRetry(url, attempt + 1, delay, options, requestInit);
545
+ return await _doZodFetchWithRetries(schema, url, requestInit, options, attempt + 1);
385
546
  }
386
547
  }
387
548
  throw new ApiConnectionError({
@@ -389,7 +550,7 @@ async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
389
550
  });
390
551
  }
391
552
  }
392
- __name(_doZodFetch, "_doZodFetch");
553
+ __name(_doZodFetchWithRetries, "_doZodFetchWithRetries");
393
554
  function castToError2(err) {
394
555
  if (err instanceof Error)
395
556
  return err;
@@ -426,8 +587,25 @@ function shouldRetry(response, attempt, retryOptions) {
426
587
  return shouldRetryForOptions();
427
588
  if (response.status === 409)
428
589
  return shouldRetryForOptions();
429
- if (response.status === 429)
590
+ if (response.status === 429) {
591
+ if (attempt >= (typeof retryOptions?.maxAttempts === "number" ? retryOptions?.maxAttempts : 3)) {
592
+ return {
593
+ retry: false
594
+ };
595
+ }
596
+ const resetAtUnixEpochMs = response.headers.get("x-ratelimit-reset");
597
+ if (resetAtUnixEpochMs) {
598
+ const resetAtUnixEpoch = parseInt(resetAtUnixEpochMs, 10);
599
+ const delay = resetAtUnixEpoch - Date.now() + Math.floor(Math.random() * 1e3);
600
+ if (delay > 0) {
601
+ return {
602
+ retry: true,
603
+ delay
604
+ };
605
+ }
606
+ }
430
607
  return shouldRetryForOptions();
608
+ }
431
609
  if (response.status >= 500)
432
610
  return shouldRetryForOptions();
433
611
  return {
@@ -590,6 +768,41 @@ fetchPage_fn2 = /* @__PURE__ */ __name(function(params1) {
590
768
  }, "#fetchPage");
591
769
  __name(_OffsetLimitPagePromise, "OffsetLimitPagePromise");
592
770
  var OffsetLimitPagePromise = _OffsetLimitPagePromise;
771
+ async function waitForRetry(url, attempt, delay, options, requestInit, response) {
772
+ if (options?.tracer) {
773
+ const method = requestInit?.method ?? "GET";
774
+ return options.tracer.startActiveSpan(response ? `wait after ${response.status}` : `wait after error`, async (span) => {
775
+ await new Promise((resolve) => setTimeout(resolve, delay));
776
+ }, {
777
+ attributes: {
778
+ [SemanticInternalAttributes.STYLE_ICON]: "wait",
779
+ ...accessoryAttributes({
780
+ items: [
781
+ {
782
+ text: `retrying ${options?.name ?? method.toUpperCase()} in ${delay}ms`,
783
+ variant: "normal"
784
+ }
785
+ ],
786
+ style: "codepath"
787
+ })
788
+ }
789
+ });
790
+ }
791
+ await new Promise((resolve) => setTimeout(resolve, delay));
792
+ }
793
+ __name(waitForRetry, "waitForRetry");
794
+ function isEmptyObj(obj) {
795
+ if (!obj)
796
+ return true;
797
+ for (const _k in obj)
798
+ return false;
799
+ return true;
800
+ }
801
+ __name(isEmptyObj, "isEmptyObj");
802
+ function hasOwn(obj, key) {
803
+ return Object.prototype.hasOwnProperty.call(obj, key);
804
+ }
805
+ __name(hasOwn, "hasOwn");
593
806
 
594
807
  exports.ApiConnectionError = ApiConnectionError;
595
808
  exports.ApiError = ApiError;
@@ -607,6 +820,9 @@ exports.PermissionDeniedError = PermissionDeniedError;
607
820
  exports.RateLimitError = RateLimitError;
608
821
  exports.UnprocessableEntityError = UnprocessableEntityError;
609
822
  exports.defaultRetryOptions = defaultRetryOptions2;
823
+ exports.hasOwn = hasOwn;
824
+ exports.isEmptyObj = isEmptyObj;
825
+ exports.isRequestOptions = isRequestOptions;
610
826
  exports.zodfetch = zodfetch;
611
827
  exports.zodfetchCursorPage = zodfetchCursorPage;
612
828
  exports.zodfetchOffsetLimitPage = zodfetchOffsetLimitPage;