@mintlify/common 1.0.669 → 1.0.670

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.
@@ -0,0 +1 @@
1
+ export declare function exponentialBackoff<T>(operation: () => Promise<T>, retries?: number, delay?: number, factor?: number): Promise<T>;
@@ -0,0 +1,23 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ export function exponentialBackoff(operation_1) {
11
+ return __awaiter(this, arguments, void 0, function* (operation, retries = 3, delay = 1000, factor = 2) {
12
+ try {
13
+ return yield operation();
14
+ }
15
+ catch (error) {
16
+ if (retries > 0) {
17
+ yield new Promise((resolve) => setTimeout(resolve, delay));
18
+ return exponentialBackoff(operation, retries - 1, delay * factor, factor);
19
+ }
20
+ throw error;
21
+ }
22
+ });
23
+ }
package/dist/index.d.ts CHANGED
@@ -27,3 +27,4 @@ export * from './truncateAtWordBoundary.js';
27
27
  export * from './api-reference/parseApiTargetFromMetadata.js';
28
28
  export * from './mintIgnore.js';
29
29
  export * from './getDisplayDomain.js';
30
+ export * from './exponentialBackoff.js';
package/dist/index.js CHANGED
@@ -27,3 +27,4 @@ export * from './truncateAtWordBoundary.js';
27
27
  export * from './api-reference/parseApiTargetFromMetadata.js';
28
28
  export * from './mintIgnore.js';
29
29
  export * from './getDisplayDomain.js';
30
+ export * from './exponentialBackoff.js';
@@ -8,9 +8,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import yaml from 'js-yaml';
11
+ import { exponentialBackoff } from '../exponentialBackoff.js';
11
12
  import { validate } from './validate.js';
12
13
  export const getOpenApiDocumentFromUrl = (url) => __awaiter(void 0, void 0, void 0, function* () {
13
- const response = yield fetch(url);
14
+ const response = yield exponentialBackoff(() => __awaiter(void 0, void 0, void 0, function* () {
15
+ const res = yield fetch(url);
16
+ if (!res.ok) {
17
+ throw new Error(`${res.status} ${res.statusText}`);
18
+ }
19
+ return res;
20
+ }));
14
21
  const data = yield response.text();
15
22
  const openApiDocument = yaml.load(data);
16
23
  if (openApiDocument == undefined) {