@internxt/sdk 1.15.13 → 1.16.0
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/auth/index.js +180 -262
- package/dist/auth/types.js +2 -22
- package/dist/drive/backups/index.js +34 -32
- package/dist/drive/payments/index.js +96 -149
- package/dist/drive/payments/object-storage.js +34 -36
- package/dist/drive/referrals/index.js +19 -17
- package/dist/drive/share/index.js +168 -235
- package/dist/drive/storage/index.js +213 -302
- package/dist/drive/trash/index.js +40 -84
- package/dist/drive/users/index.js +95 -140
- package/dist/mail/index.d.ts +124 -2
- package/dist/mail/index.js +170 -16
- package/dist/mail/types.d.ts +50 -0
- package/dist/mail/types.js +6 -0
- package/dist/meet/index.js +31 -99
- package/dist/misc/location/index.js +10 -50
- package/dist/network/download.js +38 -107
- package/dist/network/errors/codes.js +8 -24
- package/dist/network/errors/context.js +9 -26
- package/dist/network/errors/download.js +6 -24
- package/dist/network/errors/upload.js +21 -48
- package/dist/network/index.js +120 -277
- package/dist/network/types.js +3 -4
- package/dist/network/upload.js +63 -133
- package/dist/payments/checkout.js +57 -69
- package/dist/send/send.js +17 -27
- package/dist/shared/headers/index.js +56 -42
- package/dist/shared/http/client.d.ts +7 -0
- package/dist/shared/http/client.js +101 -188
- package/dist/shared/http/retryWithBackoff.js +36 -110
- package/dist/shared/types/errors.js +37 -51
- package/dist/workspaces/index.js +224 -264
- package/package.json +14 -15
- package/dist/mail/api.d.ts +0 -126
- package/dist/mail/api.js +0 -288
- package/dist/mail/crypto.d.ts +0 -66
- package/dist/mail/crypto.js +0 -156
- package/dist/mail/mail.d.ts +0 -162
- package/dist/mail/mail.js +0 -382
|
@@ -1,287 +1,202 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
4
|
};
|
|
41
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
6
|
exports.HttpClient = void 0;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const errors_1 = require("../types/errors");
|
|
9
|
+
const retryWithBackoff_1 = require("./retryWithBackoff");
|
|
10
|
+
class HttpClient {
|
|
11
|
+
axios;
|
|
12
|
+
unauthorizedCallback;
|
|
13
|
+
retryOptions;
|
|
14
|
+
static globalInterceptors = [];
|
|
15
|
+
static globalRetryOptions;
|
|
16
|
+
static setGlobalInterceptors(interceptors) {
|
|
17
|
+
HttpClient.globalInterceptors = interceptors;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Enables global retry with backoff for rate limit errors (429) across every HttpClient instance.
|
|
21
|
+
* @param [options] - Optional retry configuration options
|
|
22
|
+
* @param [options.maxRetries] - Maximum number of retry attempts (default: 5)
|
|
23
|
+
* @param [options.maxRetryAfter] - Maximum wait time in ms regardless of retry-after header value (default: 70000)
|
|
24
|
+
* @param [options.onRetry] - Callback invoked before each retry with the attempt number and delay in ms
|
|
25
|
+
*/
|
|
26
|
+
static enableGlobalRetry(options) {
|
|
27
|
+
HttpClient.globalRetryOptions = (options ?? {});
|
|
28
|
+
}
|
|
29
|
+
static create(baseURL, unauthorizedCallback, retryOptions) {
|
|
30
|
+
if (unauthorizedCallback === undefined) {
|
|
31
|
+
unauthorizedCallback = () => null;
|
|
32
|
+
}
|
|
33
|
+
return new HttpClient(baseURL, unauthorizedCallback, retryOptions);
|
|
34
|
+
}
|
|
35
|
+
constructor(baseURL, unauthorizedCallback, retryOptions) {
|
|
49
36
|
this.axios = axios_1.default.create({
|
|
50
37
|
baseURL: baseURL,
|
|
51
38
|
});
|
|
52
39
|
this.unauthorizedCallback = unauthorizedCallback;
|
|
53
40
|
this.retryOptions = retryOptions;
|
|
54
|
-
HttpClient.globalInterceptors.forEach(
|
|
41
|
+
HttpClient.globalInterceptors.forEach((interceptor) => {
|
|
55
42
|
if (interceptor.request) {
|
|
56
|
-
|
|
43
|
+
this.axios.interceptors.request.use(interceptor.request.onFulfilled, interceptor.request.onRejected);
|
|
57
44
|
}
|
|
58
45
|
if (interceptor.response) {
|
|
59
|
-
|
|
46
|
+
this.axios.interceptors.response.use(interceptor.response.onFulfilled, interceptor.response.onRejected);
|
|
60
47
|
}
|
|
61
48
|
});
|
|
62
49
|
this.initializeMiddleware();
|
|
63
50
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* Enables global retry with backoff for rate limit errors (429) across every HttpClient instance.
|
|
69
|
-
* @param [options] - Optional retry configuration options
|
|
70
|
-
* @param [options.maxRetries] - Maximum number of retry attempts (default: 5)
|
|
71
|
-
* @param [options.maxRetryAfter] - Maximum wait time in ms regardless of retry-after header value (default: 70000)
|
|
72
|
-
* @param [options.onRetry] - Callback invoked before each retry with the attempt number and delay in ms
|
|
73
|
-
*/
|
|
74
|
-
HttpClient.enableGlobalRetry = function (options) {
|
|
75
|
-
HttpClient.globalRetryOptions = (options !== null && options !== void 0 ? options : {});
|
|
76
|
-
};
|
|
77
|
-
HttpClient.create = function (baseURL, unauthorizedCallback, retryOptions) {
|
|
78
|
-
if (unauthorizedCallback === undefined) {
|
|
79
|
-
unauthorizedCallback = function () { return null; };
|
|
80
|
-
}
|
|
81
|
-
return new HttpClient(baseURL, unauthorizedCallback, retryOptions);
|
|
82
|
-
};
|
|
83
|
-
HttpClient.prototype.execute = function (fn) {
|
|
84
|
-
var _a;
|
|
85
|
-
var options = (_a = this.retryOptions) !== null && _a !== void 0 ? _a : HttpClient.globalRetryOptions;
|
|
51
|
+
execute(fn) {
|
|
52
|
+
const options = this.retryOptions ?? HttpClient.globalRetryOptions;
|
|
86
53
|
if (!options) {
|
|
87
54
|
return fn();
|
|
88
55
|
}
|
|
89
56
|
return (0, retryWithBackoff_1.retryWithBackoff)(fn, options);
|
|
90
|
-
}
|
|
57
|
+
}
|
|
91
58
|
/**
|
|
92
59
|
* Requests a GET
|
|
93
60
|
* @param url
|
|
94
61
|
* @param headers
|
|
95
62
|
*/
|
|
96
|
-
|
|
97
|
-
return
|
|
98
|
-
|
|
99
|
-
return __generator(this, function (_a) {
|
|
100
|
-
switch (_a.label) {
|
|
101
|
-
case 0: return [4 /*yield*/, this.execute(function () { return _this.axios.get(url, { headers: headers }); })];
|
|
102
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
};
|
|
63
|
+
async get(url, headers) {
|
|
64
|
+
return await this.execute(() => this.axios.get(url, { headers }));
|
|
65
|
+
}
|
|
107
66
|
/**
|
|
108
67
|
* Requests a GET
|
|
109
68
|
* @param url
|
|
110
69
|
* @param params
|
|
111
70
|
* @param headers
|
|
112
71
|
*/
|
|
113
|
-
|
|
114
|
-
return
|
|
115
|
-
|
|
116
|
-
return __generator(this, function (_a) {
|
|
117
|
-
switch (_a.label) {
|
|
118
|
-
case 0: return [4 /*yield*/, this.execute(function () { return _this.axios.get(url, { params: params, headers: headers }); })];
|
|
119
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
};
|
|
72
|
+
async getWithParams(url, params, headers) {
|
|
73
|
+
return await this.execute(() => this.axios.get(url, { params, headers }));
|
|
74
|
+
}
|
|
124
75
|
/**
|
|
125
76
|
* Requests a GET with option to cancel
|
|
126
77
|
* @param url
|
|
127
78
|
* @param headers
|
|
128
79
|
*/
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
var source = axios_1.default.CancelToken.source();
|
|
80
|
+
getCancellable(url, headers) {
|
|
81
|
+
let currentCancel = () => { };
|
|
82
|
+
const requestCanceler = { cancel: (message) => currentCancel(message) };
|
|
83
|
+
const promise = this.execute(() => {
|
|
84
|
+
const source = axios_1.default.CancelToken.source();
|
|
135
85
|
currentCancel = source.cancel;
|
|
136
|
-
return
|
|
86
|
+
return this.axios.get(url, { headers, cancelToken: source.token });
|
|
137
87
|
});
|
|
138
|
-
return { promise
|
|
139
|
-
}
|
|
88
|
+
return { promise, requestCanceler };
|
|
89
|
+
}
|
|
140
90
|
/**
|
|
141
91
|
* Requests a POST
|
|
142
92
|
* @param url
|
|
143
93
|
* @param params
|
|
144
94
|
* @param headers
|
|
145
95
|
*/
|
|
146
|
-
|
|
147
|
-
return
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
96
|
+
async post(url, params, headers, signal) {
|
|
97
|
+
return await this.execute(() => this.axios.post(url, params, { headers, signal }));
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Requests a POST with fetch adapter and keep-alive option
|
|
101
|
+
* @param url
|
|
102
|
+
* @param params
|
|
103
|
+
* @param headers
|
|
104
|
+
*/
|
|
105
|
+
async postWithKeepAlive(url, params, headers) {
|
|
106
|
+
return await this.execute(() => this.axios.post(url, params, {
|
|
107
|
+
headers,
|
|
108
|
+
adapter: 'fetch',
|
|
109
|
+
fetchOptions: {
|
|
110
|
+
keepalive: true,
|
|
111
|
+
},
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
157
114
|
/**
|
|
158
115
|
* Requests a POST FORM
|
|
159
116
|
* @param url
|
|
160
117
|
* @param params
|
|
161
118
|
* @param headers
|
|
162
119
|
*/
|
|
163
|
-
|
|
164
|
-
return
|
|
165
|
-
|
|
166
|
-
return __generator(this, function (_a) {
|
|
167
|
-
switch (_a.label) {
|
|
168
|
-
case 0: return [4 /*yield*/, this.execute(function () { return _this.axios.postForm(url, params, { headers: headers }); })];
|
|
169
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
};
|
|
120
|
+
async postForm(url, params, headers) {
|
|
121
|
+
return await this.execute(() => this.axios.postForm(url, params, { headers }));
|
|
122
|
+
}
|
|
174
123
|
/**
|
|
175
124
|
* Requests a POST with option to cancel
|
|
176
125
|
* @param url
|
|
177
126
|
* @param params
|
|
178
127
|
* @param headers
|
|
179
128
|
*/
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
var source = axios_1.default.CancelToken.source();
|
|
129
|
+
postCancellable(url, params, headers) {
|
|
130
|
+
let currentCancel = () => { };
|
|
131
|
+
const requestCanceler = { cancel: (message) => currentCancel(message) };
|
|
132
|
+
const promise = this.execute(() => {
|
|
133
|
+
const source = axios_1.default.CancelToken.source();
|
|
186
134
|
currentCancel = source.cancel;
|
|
187
|
-
return
|
|
135
|
+
return this.axios.post(url, params, { headers, cancelToken: source.token });
|
|
188
136
|
});
|
|
189
|
-
return { promise
|
|
190
|
-
}
|
|
137
|
+
return { promise, requestCanceler };
|
|
138
|
+
}
|
|
191
139
|
/**
|
|
192
140
|
* Requests PATCH
|
|
193
141
|
* @param url
|
|
194
142
|
* @param params
|
|
195
143
|
* @param headers
|
|
196
144
|
*/
|
|
197
|
-
|
|
198
|
-
return
|
|
199
|
-
|
|
200
|
-
return __generator(this, function (_a) {
|
|
201
|
-
switch (_a.label) {
|
|
202
|
-
case 0: return [4 /*yield*/, this.execute(function () { return _this.axios.patch(url, params, { headers: headers }); })];
|
|
203
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
};
|
|
145
|
+
async patch(url, params, headers) {
|
|
146
|
+
return await this.execute(() => this.axios.patch(url, params, { headers }));
|
|
147
|
+
}
|
|
208
148
|
/**
|
|
209
149
|
* Requests a PUT
|
|
210
150
|
* @param url
|
|
211
151
|
* @param params
|
|
212
152
|
* @param headers
|
|
213
153
|
*/
|
|
214
|
-
|
|
215
|
-
return
|
|
216
|
-
|
|
217
|
-
return __generator(this, function (_a) {
|
|
218
|
-
switch (_a.label) {
|
|
219
|
-
case 0: return [4 /*yield*/, this.execute(function () { return _this.axios.put(url, params, { headers: headers }); })];
|
|
220
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
};
|
|
154
|
+
async put(url, params, headers) {
|
|
155
|
+
return await this.execute(() => this.axios.put(url, params, { headers }));
|
|
156
|
+
}
|
|
225
157
|
/**
|
|
226
158
|
* Requests a PUT FORM
|
|
227
159
|
* @param url
|
|
228
160
|
* @param params
|
|
229
161
|
* @param headers
|
|
230
162
|
*/
|
|
231
|
-
|
|
232
|
-
return
|
|
233
|
-
|
|
234
|
-
return __generator(this, function (_a) {
|
|
235
|
-
switch (_a.label) {
|
|
236
|
-
case 0: return [4 /*yield*/, this.execute(function () { return _this.axios.putForm(url, params, { headers: headers }); })];
|
|
237
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
};
|
|
163
|
+
async putForm(url, params, headers) {
|
|
164
|
+
return await this.execute(() => this.axios.putForm(url, params, { headers }));
|
|
165
|
+
}
|
|
242
166
|
/**
|
|
243
167
|
* Requests a DELETE
|
|
244
168
|
* @param url
|
|
245
169
|
* @param headers
|
|
246
170
|
* @param params
|
|
247
171
|
*/
|
|
248
|
-
|
|
249
|
-
return
|
|
250
|
-
|
|
251
|
-
return __generator(this, function (_a) {
|
|
252
|
-
switch (_a.label) {
|
|
253
|
-
case 0: return [4 /*yield*/, this.execute(function () { return _this.axios.delete(url, { headers: headers, data: params }); })];
|
|
254
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
};
|
|
172
|
+
async delete(url, headers, params) {
|
|
173
|
+
return await this.execute(() => this.axios.delete(url, { headers, data: params }));
|
|
174
|
+
}
|
|
259
175
|
/**
|
|
260
176
|
* Sets middlewares into the client for common behaviour managing
|
|
261
177
|
* @private
|
|
262
178
|
*/
|
|
263
|
-
|
|
179
|
+
initializeMiddleware() {
|
|
264
180
|
this.axios.interceptors.response.use(HttpClient.extractData, this.normalizeError.bind(this));
|
|
265
|
-
}
|
|
181
|
+
}
|
|
266
182
|
/**
|
|
267
183
|
* Extracts the valuable data from the server's response
|
|
268
184
|
* @param response
|
|
269
185
|
* @private
|
|
270
186
|
*/
|
|
271
|
-
|
|
187
|
+
static extractData(response) {
|
|
272
188
|
return response.data;
|
|
273
|
-
}
|
|
189
|
+
}
|
|
274
190
|
/**
|
|
275
191
|
* Converts the specific client error into a proprietary error for our apps
|
|
276
192
|
* @param error
|
|
277
193
|
* @private
|
|
278
194
|
*/
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
var request = "".concat(method, " ").concat(baseUrl).concat(url);
|
|
195
|
+
normalizeError(error) {
|
|
196
|
+
const baseUrl = error.config?.baseURL ?? '';
|
|
197
|
+
const url = error.config?.url ?? '';
|
|
198
|
+
const method = error.config?.method ?? '';
|
|
199
|
+
const request = `${method} ${baseUrl}${url}`;
|
|
285
200
|
if (error.response) {
|
|
286
201
|
if (error.response.status === 401) {
|
|
287
202
|
this.unauthorizedCallback();
|
|
@@ -291,8 +206,6 @@ var HttpClient = /** @class */ (function () {
|
|
|
291
206
|
else {
|
|
292
207
|
throw new errors_1.AxiosUnknownError(error.message, request, error);
|
|
293
208
|
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
return HttpClient;
|
|
297
|
-
}());
|
|
209
|
+
}
|
|
210
|
+
}
|
|
298
211
|
exports.HttpClient = HttpClient;
|
|
@@ -1,80 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
50
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
51
|
-
if (ar || !(i in from)) {
|
|
52
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
53
|
-
ar[i] = from[i];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
57
|
-
};
|
|
58
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
3
|
exports.retryWithBackoff = void 0;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
4
|
+
const HTTP_STATUS_TOO_MANY_REQUESTS = 429;
|
|
5
|
+
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
6
|
+
const isErrorWithStatus = (error) => {
|
|
63
7
|
return typeof error === 'object' && error !== null;
|
|
64
8
|
};
|
|
65
|
-
|
|
9
|
+
const isRateLimitError = (error) => {
|
|
66
10
|
if (!isErrorWithStatus(error)) {
|
|
67
11
|
return false;
|
|
68
12
|
}
|
|
69
13
|
return error.status === HTTP_STATUS_TOO_MANY_REQUESTS;
|
|
70
14
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
15
|
+
const extractRetryAfter = (error) => {
|
|
16
|
+
const headers = error.headers;
|
|
17
|
+
const resetHeader = headers?.['retry-after'];
|
|
74
18
|
if (!resetHeader) {
|
|
75
19
|
return undefined;
|
|
76
20
|
}
|
|
77
|
-
|
|
21
|
+
const resetValueInSeconds = Number.parseInt(resetHeader, 10);
|
|
78
22
|
if (Number.isNaN(resetValueInSeconds)) {
|
|
79
23
|
return undefined;
|
|
80
24
|
}
|
|
@@ -92,52 +36,34 @@ var extractRetryAfter = function (error) {
|
|
|
92
36
|
* @returns The result of the function if successful
|
|
93
37
|
* @throws The original error if it's not a rate limit error, if max retries exceeded, or if retry-after header is missing
|
|
94
38
|
*/
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return [4 /*yield*/, fn()];
|
|
115
|
-
case 3: return [2 /*return*/, _a.sent()];
|
|
116
|
-
case 4:
|
|
117
|
-
error_1 = _a.sent();
|
|
118
|
-
if (!isRateLimitError(error_1)) {
|
|
119
|
-
throw error_1;
|
|
120
|
-
}
|
|
121
|
-
retryAfter = extractRetryAfter(error_1);
|
|
122
|
-
if (!retryAfter) {
|
|
123
|
-
throw error_1;
|
|
124
|
-
}
|
|
125
|
-
delay = Math.min(retryAfter, opts.maxRetryAfter);
|
|
126
|
-
opts.onRetry(attempt, delay);
|
|
127
|
-
lastError = error_1;
|
|
128
|
-
return [4 /*yield*/, wait(delay)];
|
|
129
|
-
case 5:
|
|
130
|
-
_a.sent();
|
|
131
|
-
return [3 /*break*/, 6];
|
|
132
|
-
case 6:
|
|
133
|
-
attempt++;
|
|
134
|
-
return [3 /*break*/, 1];
|
|
135
|
-
case 7:
|
|
136
|
-
err = lastError;
|
|
137
|
-
err.message = "Max retries exceeded: ".concat(err.message);
|
|
138
|
-
throw err;
|
|
39
|
+
const retryWithBackoff = async (fn, options = {}) => {
|
|
40
|
+
const opts = {
|
|
41
|
+
maxRetries: 5,
|
|
42
|
+
maxRetryAfter: 70_000,
|
|
43
|
+
onRetry: () => { },
|
|
44
|
+
...options,
|
|
45
|
+
};
|
|
46
|
+
let lastError;
|
|
47
|
+
for (let attempt = 1; attempt <= opts.maxRetries; attempt++) {
|
|
48
|
+
try {
|
|
49
|
+
return await fn();
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (!isRateLimitError(error)) {
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
const retryAfter = extractRetryAfter(error);
|
|
56
|
+
if (!retryAfter) {
|
|
57
|
+
throw error;
|
|
139
58
|
}
|
|
140
|
-
|
|
141
|
-
|
|
59
|
+
const delay = Math.min(retryAfter, opts.maxRetryAfter);
|
|
60
|
+
opts.onRetry(attempt, delay);
|
|
61
|
+
lastError = error;
|
|
62
|
+
await wait(delay);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const err = lastError;
|
|
66
|
+
err.message = `Max retries exceeded: ${err.message}`;
|
|
67
|
+
throw err;
|
|
142
68
|
};
|
|
143
69
|
exports.retryWithBackoff = retryWithBackoff;
|