@internxt/sdk 1.15.14 → 1.16.1
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.d.ts +2 -32
- package/dist/drive/payments/index.js +75 -179
- package/dist/drive/payments/object-storage.js +34 -36
- package/dist/drive/payments/types/types.d.ts +6 -0
- 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.d.ts +1 -1
- package/dist/payments/checkout.js +56 -69
- package/dist/payments/types/index.d.ts +0 -3
- package/dist/send/send.js +17 -27
- package/dist/shared/headers/index.js +56 -42
- package/dist/shared/http/client.js +95 -207
- 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,312 +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
|
-
return __generator(this, function (_a) {
|
|
150
|
-
switch (_a.label) {
|
|
151
|
-
case 0: return [4 /*yield*/, this.execute(function () { return _this.axios.post(url, params, { headers: headers, signal: signal }); })];
|
|
152
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
};
|
|
96
|
+
async post(url, params, headers, signal) {
|
|
97
|
+
return await this.execute(() => this.axios.post(url, params, { headers, signal }));
|
|
98
|
+
}
|
|
157
99
|
/**
|
|
158
100
|
* Requests a POST with fetch adapter and keep-alive option
|
|
159
101
|
* @param url
|
|
160
102
|
* @param params
|
|
161
103
|
* @param headers
|
|
162
104
|
*/
|
|
163
|
-
|
|
164
|
-
return
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
fetchOptions: {
|
|
173
|
-
keepalive: true,
|
|
174
|
-
},
|
|
175
|
-
});
|
|
176
|
-
})];
|
|
177
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
};
|
|
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
|
+
}
|
|
182
114
|
/**
|
|
183
115
|
* Requests a POST FORM
|
|
184
116
|
* @param url
|
|
185
117
|
* @param params
|
|
186
118
|
* @param headers
|
|
187
119
|
*/
|
|
188
|
-
|
|
189
|
-
return
|
|
190
|
-
|
|
191
|
-
return __generator(this, function (_a) {
|
|
192
|
-
switch (_a.label) {
|
|
193
|
-
case 0: return [4 /*yield*/, this.execute(function () { return _this.axios.postForm(url, params, { headers: headers }); })];
|
|
194
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
};
|
|
120
|
+
async postForm(url, params, headers) {
|
|
121
|
+
return await this.execute(() => this.axios.postForm(url, params, { headers }));
|
|
122
|
+
}
|
|
199
123
|
/**
|
|
200
124
|
* Requests a POST with option to cancel
|
|
201
125
|
* @param url
|
|
202
126
|
* @param params
|
|
203
127
|
* @param headers
|
|
204
128
|
*/
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
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();
|
|
211
134
|
currentCancel = source.cancel;
|
|
212
|
-
return
|
|
135
|
+
return this.axios.post(url, params, { headers, cancelToken: source.token });
|
|
213
136
|
});
|
|
214
|
-
return { promise
|
|
215
|
-
}
|
|
137
|
+
return { promise, requestCanceler };
|
|
138
|
+
}
|
|
216
139
|
/**
|
|
217
140
|
* Requests PATCH
|
|
218
141
|
* @param url
|
|
219
142
|
* @param params
|
|
220
143
|
* @param headers
|
|
221
144
|
*/
|
|
222
|
-
|
|
223
|
-
return
|
|
224
|
-
|
|
225
|
-
return __generator(this, function (_a) {
|
|
226
|
-
switch (_a.label) {
|
|
227
|
-
case 0: return [4 /*yield*/, this.execute(function () { return _this.axios.patch(url, params, { headers: headers }); })];
|
|
228
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
};
|
|
145
|
+
async patch(url, params, headers) {
|
|
146
|
+
return await this.execute(() => this.axios.patch(url, params, { headers }));
|
|
147
|
+
}
|
|
233
148
|
/**
|
|
234
149
|
* Requests a PUT
|
|
235
150
|
* @param url
|
|
236
151
|
* @param params
|
|
237
152
|
* @param headers
|
|
238
153
|
*/
|
|
239
|
-
|
|
240
|
-
return
|
|
241
|
-
|
|
242
|
-
return __generator(this, function (_a) {
|
|
243
|
-
switch (_a.label) {
|
|
244
|
-
case 0: return [4 /*yield*/, this.execute(function () { return _this.axios.put(url, params, { headers: headers }); })];
|
|
245
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
});
|
|
249
|
-
};
|
|
154
|
+
async put(url, params, headers) {
|
|
155
|
+
return await this.execute(() => this.axios.put(url, params, { headers }));
|
|
156
|
+
}
|
|
250
157
|
/**
|
|
251
158
|
* Requests a PUT FORM
|
|
252
159
|
* @param url
|
|
253
160
|
* @param params
|
|
254
161
|
* @param headers
|
|
255
162
|
*/
|
|
256
|
-
|
|
257
|
-
return
|
|
258
|
-
|
|
259
|
-
return __generator(this, function (_a) {
|
|
260
|
-
switch (_a.label) {
|
|
261
|
-
case 0: return [4 /*yield*/, this.execute(function () { return _this.axios.putForm(url, params, { headers: headers }); })];
|
|
262
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
};
|
|
163
|
+
async putForm(url, params, headers) {
|
|
164
|
+
return await this.execute(() => this.axios.putForm(url, params, { headers }));
|
|
165
|
+
}
|
|
267
166
|
/**
|
|
268
167
|
* Requests a DELETE
|
|
269
168
|
* @param url
|
|
270
169
|
* @param headers
|
|
271
170
|
* @param params
|
|
272
171
|
*/
|
|
273
|
-
|
|
274
|
-
return
|
|
275
|
-
|
|
276
|
-
return __generator(this, function (_a) {
|
|
277
|
-
switch (_a.label) {
|
|
278
|
-
case 0: return [4 /*yield*/, this.execute(function () { return _this.axios.delete(url, { headers: headers, data: params }); })];
|
|
279
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
};
|
|
172
|
+
async delete(url, headers, params) {
|
|
173
|
+
return await this.execute(() => this.axios.delete(url, { headers, data: params }));
|
|
174
|
+
}
|
|
284
175
|
/**
|
|
285
176
|
* Sets middlewares into the client for common behaviour managing
|
|
286
177
|
* @private
|
|
287
178
|
*/
|
|
288
|
-
|
|
179
|
+
initializeMiddleware() {
|
|
289
180
|
this.axios.interceptors.response.use(HttpClient.extractData, this.normalizeError.bind(this));
|
|
290
|
-
}
|
|
181
|
+
}
|
|
291
182
|
/**
|
|
292
183
|
* Extracts the valuable data from the server's response
|
|
293
184
|
* @param response
|
|
294
185
|
* @private
|
|
295
186
|
*/
|
|
296
|
-
|
|
187
|
+
static extractData(response) {
|
|
297
188
|
return response.data;
|
|
298
|
-
}
|
|
189
|
+
}
|
|
299
190
|
/**
|
|
300
191
|
* Converts the specific client error into a proprietary error for our apps
|
|
301
192
|
* @param error
|
|
302
193
|
* @private
|
|
303
194
|
*/
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
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}`;
|
|
310
200
|
if (error.response) {
|
|
311
201
|
if (error.response.status === 401) {
|
|
312
202
|
this.unauthorizedCallback();
|
|
@@ -316,8 +206,6 @@ var HttpClient = /** @class */ (function () {
|
|
|
316
206
|
else {
|
|
317
207
|
throw new errors_1.AxiosUnknownError(error.message, request, error);
|
|
318
208
|
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
return HttpClient;
|
|
322
|
-
}());
|
|
209
|
+
}
|
|
210
|
+
}
|
|
323
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;
|