@internxt/sdk 1.14.2 → 1.15.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 +1 -1
- package/dist/drive/backups/index.js +1 -1
- package/dist/drive/payments/index.js +1 -1
- package/dist/drive/referrals/index.js +1 -1
- package/dist/drive/share/index.js +1 -1
- package/dist/drive/storage/index.js +1 -1
- package/dist/drive/trash/index.js +1 -1
- package/dist/drive/users/index.js +1 -1
- package/dist/meet/index.js +1 -1
- package/dist/payments/checkout.js +1 -1
- package/dist/shared/http/client.d.ts +17 -1
- package/dist/shared/http/client.js +57 -53
- package/dist/shared/http/retryWithBackoff.d.ts +18 -0
- package/dist/shared/http/retryWithBackoff.js +143 -0
- package/dist/shared/index.d.ts +3 -0
- package/dist/shared/index.js +5 -1
- package/dist/shared/types/apiConnection.d.ts +2 -0
- package/dist/workspaces/index.js +1 -1
- package/package.json +1 -1
package/dist/auth/index.js
CHANGED
|
@@ -56,7 +56,7 @@ var client_1 = require("../shared/http/client");
|
|
|
56
56
|
__exportStar(require("./types"), exports);
|
|
57
57
|
var Auth = /** @class */ (function () {
|
|
58
58
|
function Auth(apiUrl, appDetails, apiSecurity) {
|
|
59
|
-
this.client = client_1.HttpClient.create(apiUrl, apiSecurity === null || apiSecurity === void 0 ? void 0 : apiSecurity.unauthorizedCallback);
|
|
59
|
+
this.client = client_1.HttpClient.create(apiUrl, apiSecurity === null || apiSecurity === void 0 ? void 0 : apiSecurity.unauthorizedCallback, apiSecurity === null || apiSecurity === void 0 ? void 0 : apiSecurity.retryOptions);
|
|
60
60
|
this.appDetails = appDetails;
|
|
61
61
|
this.apiSecurity = apiSecurity;
|
|
62
62
|
this.apiUrl = apiUrl;
|
|
@@ -5,7 +5,7 @@ var client_1 = require("../../shared/http/client");
|
|
|
5
5
|
var headers_1 = require("../../shared/headers");
|
|
6
6
|
var Backups = /** @class */ (function () {
|
|
7
7
|
function Backups(apiUrl, appDetails, apiSecurity) {
|
|
8
|
-
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback);
|
|
8
|
+
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback, apiSecurity.retryOptions);
|
|
9
9
|
this.appDetails = appDetails;
|
|
10
10
|
this.apiSecurity = apiSecurity;
|
|
11
11
|
}
|
|
@@ -53,7 +53,7 @@ var client_1 = require("../../shared/http/client");
|
|
|
53
53
|
var types_1 = require("./types/types");
|
|
54
54
|
var Payments = /** @class */ (function () {
|
|
55
55
|
function Payments(apiUrl, appDetails, apiSecurity) {
|
|
56
|
-
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback);
|
|
56
|
+
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback, apiSecurity.retryOptions);
|
|
57
57
|
this.appDetails = appDetails;
|
|
58
58
|
this.apiSecurity = apiSecurity;
|
|
59
59
|
}
|
|
@@ -39,7 +39,7 @@ var client_1 = require("../../shared/http/client");
|
|
|
39
39
|
exports.ReferralTypes = __importStar(require("./types"));
|
|
40
40
|
var Referrals = /** @class */ (function () {
|
|
41
41
|
function Referrals(apiUrl, appDetails, apiSecurity) {
|
|
42
|
-
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback);
|
|
42
|
+
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback, apiSecurity.retryOptions);
|
|
43
43
|
this.appDetails = appDetails;
|
|
44
44
|
this.apiSecurity = apiSecurity;
|
|
45
45
|
}
|
|
@@ -86,7 +86,7 @@ var client_1 = require("../../shared/http/client");
|
|
|
86
86
|
exports.ShareTypes = __importStar(require("./types"));
|
|
87
87
|
var Share = /** @class */ (function () {
|
|
88
88
|
function Share(apiUrl, appDetails, apiSecurity) {
|
|
89
|
-
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback);
|
|
89
|
+
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback, apiSecurity.retryOptions);
|
|
90
90
|
this.appDetails = appDetails;
|
|
91
91
|
this.apiSecurity = apiSecurity;
|
|
92
92
|
}
|
|
@@ -86,7 +86,7 @@ var client_1 = require("../../shared/http/client");
|
|
|
86
86
|
exports.StorageTypes = __importStar(require("./types"));
|
|
87
87
|
var Storage = /** @class */ (function () {
|
|
88
88
|
function Storage(apiUrl, appDetails, apiSecurity) {
|
|
89
|
-
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback);
|
|
89
|
+
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback, apiSecurity.retryOptions);
|
|
90
90
|
this.appDetails = appDetails;
|
|
91
91
|
this.apiSecurity = apiSecurity;
|
|
92
92
|
}
|
|
@@ -75,7 +75,7 @@ var client_1 = require("../../shared/http/client");
|
|
|
75
75
|
exports.TrashTypes = __importStar(require("./types"));
|
|
76
76
|
var Trash = /** @class */ (function () {
|
|
77
77
|
function Trash(apiUrl, appDetails, apiSecurity) {
|
|
78
|
-
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback);
|
|
78
|
+
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback, apiSecurity.retryOptions);
|
|
79
79
|
this.appDetails = appDetails;
|
|
80
80
|
this.apiSecurity = apiSecurity;
|
|
81
81
|
}
|
|
@@ -75,7 +75,7 @@ var client_1 = require("../../shared/http/client");
|
|
|
75
75
|
exports.UserTypes = __importStar(require("./types"));
|
|
76
76
|
var Users = /** @class */ (function () {
|
|
77
77
|
function Users(apiUrl, appDetails, apiSecurity) {
|
|
78
|
-
this.client = client_1.HttpClient.create(apiUrl, apiSecurity === null || apiSecurity === void 0 ? void 0 : apiSecurity.unauthorizedCallback);
|
|
78
|
+
this.client = client_1.HttpClient.create(apiUrl, apiSecurity === null || apiSecurity === void 0 ? void 0 : apiSecurity.unauthorizedCallback, apiSecurity === null || apiSecurity === void 0 ? void 0 : apiSecurity.retryOptions);
|
|
79
79
|
this.appDetails = appDetails;
|
|
80
80
|
this.apiSecurity = apiSecurity;
|
|
81
81
|
}
|
package/dist/meet/index.js
CHANGED
|
@@ -52,7 +52,7 @@ var headers_1 = require("../shared/headers");
|
|
|
52
52
|
var client_1 = require("../shared/http/client");
|
|
53
53
|
var Meet = /** @class */ (function () {
|
|
54
54
|
function Meet(apiUrl, appDetails, apiSecurity) {
|
|
55
|
-
this.client = client_1.HttpClient.create(apiUrl, apiSecurity === null || apiSecurity === void 0 ? void 0 : apiSecurity.unauthorizedCallback);
|
|
55
|
+
this.client = client_1.HttpClient.create(apiUrl, apiSecurity === null || apiSecurity === void 0 ? void 0 : apiSecurity.unauthorizedCallback, apiSecurity === null || apiSecurity === void 0 ? void 0 : apiSecurity.retryOptions);
|
|
56
56
|
this.appDetails = appDetails;
|
|
57
57
|
this.apiSecurity = apiSecurity;
|
|
58
58
|
}
|
|
@@ -16,7 +16,7 @@ var headers_1 = require("../shared/headers");
|
|
|
16
16
|
var client_1 = require("../shared/http/client");
|
|
17
17
|
var Checkout = /** @class */ (function () {
|
|
18
18
|
function Checkout(apiUrl, appDetails, apiSecurity) {
|
|
19
|
-
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback);
|
|
19
|
+
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback, apiSecurity.retryOptions);
|
|
20
20
|
this.appDetails = appDetails;
|
|
21
21
|
this.apiSecurity = apiSecurity;
|
|
22
22
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
|
2
2
|
import { Headers, Parameters, RequestCanceler, URL, UnauthorizedCallback } from './types';
|
|
3
|
+
import { RetryOptions } from './retryWithBackoff';
|
|
3
4
|
export { RequestCanceler } from './types';
|
|
4
5
|
export interface CustomInterceptor {
|
|
5
6
|
request?: {
|
|
@@ -11,13 +12,28 @@ export interface CustomInterceptor {
|
|
|
11
12
|
onRejected?: (error: unknown) => unknown;
|
|
12
13
|
};
|
|
13
14
|
}
|
|
15
|
+
type NonZero<N extends number> = N extends 0 ? never : N;
|
|
16
|
+
type GlobalRetryOptions<M extends number = number> = Omit<RetryOptions, 'maxRetries'> & {
|
|
17
|
+
maxRetries?: NonZero<M>;
|
|
18
|
+
};
|
|
14
19
|
export declare class HttpClient {
|
|
15
20
|
private readonly axios;
|
|
16
21
|
private readonly unauthorizedCallback;
|
|
22
|
+
private retryOptions?;
|
|
17
23
|
static globalInterceptors: CustomInterceptor[];
|
|
24
|
+
static globalRetryOptions?: RetryOptions;
|
|
18
25
|
static setGlobalInterceptors(interceptors: CustomInterceptor[]): void;
|
|
19
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Enables global retry with backoff for rate limit errors (429) across every HttpClient instance.
|
|
28
|
+
* @param [options] - Optional retry configuration options
|
|
29
|
+
* @param [options.maxRetries] - Maximum number of retry attempts (default: 5)
|
|
30
|
+
* @param [options.maxRetryAfter] - Maximum wait time in ms regardless of retry-after header value (default: 70000)
|
|
31
|
+
* @param [options.onRetry] - Callback invoked before each retry with the attempt number and delay in ms
|
|
32
|
+
*/
|
|
33
|
+
static enableGlobalRetry<M extends number = number>(options?: GlobalRetryOptions<M>): void;
|
|
34
|
+
static create(baseURL: URL, unauthorizedCallback?: UnauthorizedCallback, retryOptions?: RetryOptions): HttpClient;
|
|
20
35
|
private constructor();
|
|
36
|
+
private execute;
|
|
21
37
|
/**
|
|
22
38
|
* Requests a GET
|
|
23
39
|
* @param url
|
|
@@ -6,13 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.HttpClient = void 0;
|
|
7
7
|
var axios_1 = __importDefault(require("axios"));
|
|
8
8
|
var errors_1 = __importDefault(require("../types/errors"));
|
|
9
|
+
var retryWithBackoff_1 = require("./retryWithBackoff");
|
|
9
10
|
var HttpClient = /** @class */ (function () {
|
|
10
|
-
function HttpClient(baseURL, unauthorizedCallback) {
|
|
11
|
+
function HttpClient(baseURL, unauthorizedCallback, retryOptions) {
|
|
11
12
|
var _this = this;
|
|
12
13
|
this.axios = axios_1.default.create({
|
|
13
14
|
baseURL: baseURL,
|
|
14
15
|
});
|
|
15
16
|
this.unauthorizedCallback = unauthorizedCallback;
|
|
17
|
+
this.retryOptions = retryOptions;
|
|
16
18
|
HttpClient.globalInterceptors.forEach(function (interceptor) {
|
|
17
19
|
if (interceptor.request) {
|
|
18
20
|
_this.axios.interceptors.request.use(interceptor.request.onFulfilled, interceptor.request.onRejected);
|
|
@@ -26,11 +28,29 @@ var HttpClient = /** @class */ (function () {
|
|
|
26
28
|
HttpClient.setGlobalInterceptors = function (interceptors) {
|
|
27
29
|
HttpClient.globalInterceptors = interceptors;
|
|
28
30
|
};
|
|
29
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Enables global retry with backoff for rate limit errors (429) across every HttpClient instance.
|
|
33
|
+
* @param [options] - Optional retry configuration options
|
|
34
|
+
* @param [options.maxRetries] - Maximum number of retry attempts (default: 5)
|
|
35
|
+
* @param [options.maxRetryAfter] - Maximum wait time in ms regardless of retry-after header value (default: 70000)
|
|
36
|
+
* @param [options.onRetry] - Callback invoked before each retry with the attempt number and delay in ms
|
|
37
|
+
*/
|
|
38
|
+
HttpClient.enableGlobalRetry = function (options) {
|
|
39
|
+
HttpClient.globalRetryOptions = (options !== null && options !== void 0 ? options : {});
|
|
40
|
+
};
|
|
41
|
+
HttpClient.create = function (baseURL, unauthorizedCallback, retryOptions) {
|
|
30
42
|
if (unauthorizedCallback === undefined) {
|
|
31
43
|
unauthorizedCallback = function () { return null; };
|
|
32
44
|
}
|
|
33
|
-
return new HttpClient(baseURL, unauthorizedCallback);
|
|
45
|
+
return new HttpClient(baseURL, unauthorizedCallback, retryOptions);
|
|
46
|
+
};
|
|
47
|
+
HttpClient.prototype.execute = function (fn) {
|
|
48
|
+
var _a;
|
|
49
|
+
var options = (_a = this.retryOptions) !== null && _a !== void 0 ? _a : HttpClient.globalRetryOptions;
|
|
50
|
+
if (!options) {
|
|
51
|
+
return fn();
|
|
52
|
+
}
|
|
53
|
+
return (0, retryWithBackoff_1.retryWithBackoff)(fn, options);
|
|
34
54
|
};
|
|
35
55
|
/**
|
|
36
56
|
* Requests a GET
|
|
@@ -38,9 +58,8 @@ var HttpClient = /** @class */ (function () {
|
|
|
38
58
|
* @param headers
|
|
39
59
|
*/
|
|
40
60
|
HttpClient.prototype.get = function (url, headers) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
});
|
|
61
|
+
var _this = this;
|
|
62
|
+
return this.execute(function () { return _this.axios.get(url, { headers: headers }); });
|
|
44
63
|
};
|
|
45
64
|
/**
|
|
46
65
|
* Requests a GET
|
|
@@ -49,10 +68,8 @@ var HttpClient = /** @class */ (function () {
|
|
|
49
68
|
* @param headers
|
|
50
69
|
*/
|
|
51
70
|
HttpClient.prototype.getWithParams = function (url, params, headers) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
headers: headers,
|
|
55
|
-
});
|
|
71
|
+
var _this = this;
|
|
72
|
+
return this.execute(function () { return _this.axios.get(url, { params: params, headers: headers }); });
|
|
56
73
|
};
|
|
57
74
|
/**
|
|
58
75
|
* Requests a GET with option to cancel
|
|
@@ -60,18 +77,15 @@ var HttpClient = /** @class */ (function () {
|
|
|
60
77
|
* @param headers
|
|
61
78
|
*/
|
|
62
79
|
HttpClient.prototype.getCancellable = function (url, headers) {
|
|
63
|
-
var
|
|
64
|
-
var
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
cancel: cancelTokenSource.cancel,
|
|
73
|
-
},
|
|
74
|
-
};
|
|
80
|
+
var _this = this;
|
|
81
|
+
var currentCancel = function () { };
|
|
82
|
+
var requestCanceler = { cancel: function (message) { return currentCancel(message); } };
|
|
83
|
+
var promise = this.execute(function () {
|
|
84
|
+
var source = axios_1.default.CancelToken.source();
|
|
85
|
+
currentCancel = source.cancel;
|
|
86
|
+
return _this.axios.get(url, { headers: headers, cancelToken: source.token });
|
|
87
|
+
});
|
|
88
|
+
return { promise: promise, requestCanceler: requestCanceler };
|
|
75
89
|
};
|
|
76
90
|
/**
|
|
77
91
|
* Requests a POST
|
|
@@ -80,9 +94,8 @@ var HttpClient = /** @class */ (function () {
|
|
|
80
94
|
* @param headers
|
|
81
95
|
*/
|
|
82
96
|
HttpClient.prototype.post = function (url, params, headers) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
});
|
|
97
|
+
var _this = this;
|
|
98
|
+
return this.execute(function () { return _this.axios.post(url, params, { headers: headers }); });
|
|
86
99
|
};
|
|
87
100
|
/**
|
|
88
101
|
* Requests a POST FORM
|
|
@@ -91,9 +104,8 @@ var HttpClient = /** @class */ (function () {
|
|
|
91
104
|
* @param headers
|
|
92
105
|
*/
|
|
93
106
|
HttpClient.prototype.postForm = function (url, params, headers) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
});
|
|
107
|
+
var _this = this;
|
|
108
|
+
return this.execute(function () { return _this.axios.postForm(url, params, { headers: headers }); });
|
|
97
109
|
};
|
|
98
110
|
/**
|
|
99
111
|
* Requests a POST with option to cancel
|
|
@@ -102,18 +114,15 @@ var HttpClient = /** @class */ (function () {
|
|
|
102
114
|
* @param headers
|
|
103
115
|
*/
|
|
104
116
|
HttpClient.prototype.postCancellable = function (url, params, headers) {
|
|
105
|
-
var
|
|
106
|
-
var
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
cancel: cancelTokenSource.cancel,
|
|
115
|
-
},
|
|
116
|
-
};
|
|
117
|
+
var _this = this;
|
|
118
|
+
var currentCancel = function () { };
|
|
119
|
+
var requestCanceler = { cancel: function (message) { return currentCancel(message); } };
|
|
120
|
+
var promise = this.execute(function () {
|
|
121
|
+
var source = axios_1.default.CancelToken.source();
|
|
122
|
+
currentCancel = source.cancel;
|
|
123
|
+
return _this.axios.post(url, params, { headers: headers, cancelToken: source.token });
|
|
124
|
+
});
|
|
125
|
+
return { promise: promise, requestCanceler: requestCanceler };
|
|
117
126
|
};
|
|
118
127
|
/**
|
|
119
128
|
* Requests PATCH
|
|
@@ -122,9 +131,8 @@ var HttpClient = /** @class */ (function () {
|
|
|
122
131
|
* @param headers
|
|
123
132
|
*/
|
|
124
133
|
HttpClient.prototype.patch = function (url, params, headers) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
});
|
|
134
|
+
var _this = this;
|
|
135
|
+
return this.execute(function () { return _this.axios.patch(url, params, { headers: headers }); });
|
|
128
136
|
};
|
|
129
137
|
/**
|
|
130
138
|
* Requests a PUT
|
|
@@ -133,9 +141,8 @@ var HttpClient = /** @class */ (function () {
|
|
|
133
141
|
* @param headers
|
|
134
142
|
*/
|
|
135
143
|
HttpClient.prototype.put = function (url, params, headers) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
});
|
|
144
|
+
var _this = this;
|
|
145
|
+
return this.execute(function () { return _this.axios.put(url, params, { headers: headers }); });
|
|
139
146
|
};
|
|
140
147
|
/**
|
|
141
148
|
* Requests a PUT FORM
|
|
@@ -144,9 +151,8 @@ var HttpClient = /** @class */ (function () {
|
|
|
144
151
|
* @param headers
|
|
145
152
|
*/
|
|
146
153
|
HttpClient.prototype.putForm = function (url, params, headers) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
});
|
|
154
|
+
var _this = this;
|
|
155
|
+
return this.execute(function () { return _this.axios.putForm(url, params, { headers: headers }); });
|
|
150
156
|
};
|
|
151
157
|
/**
|
|
152
158
|
* Requests a DELETE
|
|
@@ -155,10 +161,8 @@ var HttpClient = /** @class */ (function () {
|
|
|
155
161
|
* @param params
|
|
156
162
|
*/
|
|
157
163
|
HttpClient.prototype.delete = function (url, headers, params) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
data: params,
|
|
161
|
-
});
|
|
164
|
+
var _this = this;
|
|
165
|
+
return this.execute(function () { return _this.axios.delete(url, { headers: headers, data: params }); });
|
|
162
166
|
};
|
|
163
167
|
/**
|
|
164
168
|
* Sets middlewares into the client for common behaviour managing
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface RetryOptions {
|
|
2
|
+
maxRetries?: number;
|
|
3
|
+
maxRetryAfter?: number;
|
|
4
|
+
onRetry?: (attempt: number, delay: number) => void;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Retries a function when it encounters a rate limit error (429).
|
|
8
|
+
* Uses the retry-after header to determine how long to wait before retrying.
|
|
9
|
+
*
|
|
10
|
+
* @param fn - The async function to execute with retry logic
|
|
11
|
+
* @param options - Configuration options for retry behavior
|
|
12
|
+
* @param options.maxRetries - Maximum number of retry attempts (default: 5)
|
|
13
|
+
* @param options.maxRetryAfter - Maximum wait time in ms regardless of retry-after header value (default: 70000)
|
|
14
|
+
* @param options.onRetry - Optional callback invoked before each retry with attempt number and delay in ms
|
|
15
|
+
* @returns The result of the function if successful
|
|
16
|
+
* @throws The original error if it's not a rate limit error, if max retries exceeded, or if retry-after header is missing
|
|
17
|
+
*/
|
|
18
|
+
export declare const retryWithBackoff: <T>(fn: () => Promise<T>, options?: RetryOptions) => Promise<T>;
|
|
@@ -0,0 +1,143 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
|
+
exports.retryWithBackoff = void 0;
|
|
60
|
+
var HTTP_STATUS_TOO_MANY_REQUESTS = 429;
|
|
61
|
+
var wait = function (ms) { return new Promise(function (resolve) { return setTimeout(resolve, ms); }); };
|
|
62
|
+
var isErrorWithStatus = function (error) {
|
|
63
|
+
return typeof error === 'object' && error !== null;
|
|
64
|
+
};
|
|
65
|
+
var isRateLimitError = function (error) {
|
|
66
|
+
if (!isErrorWithStatus(error)) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return error.status === HTTP_STATUS_TOO_MANY_REQUESTS;
|
|
70
|
+
};
|
|
71
|
+
var extractRetryAfter = function (error) {
|
|
72
|
+
var headers = error.headers;
|
|
73
|
+
var resetHeader = headers === null || headers === void 0 ? void 0 : headers['retry-after'];
|
|
74
|
+
if (!resetHeader) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
var resetValueInSeconds = Number.parseInt(resetHeader, 10);
|
|
78
|
+
if (Number.isNaN(resetValueInSeconds)) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
return resetValueInSeconds * 1000;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Retries a function when it encounters a rate limit error (429).
|
|
85
|
+
* Uses the retry-after header to determine how long to wait before retrying.
|
|
86
|
+
*
|
|
87
|
+
* @param fn - The async function to execute with retry logic
|
|
88
|
+
* @param options - Configuration options for retry behavior
|
|
89
|
+
* @param options.maxRetries - Maximum number of retry attempts (default: 5)
|
|
90
|
+
* @param options.maxRetryAfter - Maximum wait time in ms regardless of retry-after header value (default: 70000)
|
|
91
|
+
* @param options.onRetry - Optional callback invoked before each retry with attempt number and delay in ms
|
|
92
|
+
* @returns The result of the function if successful
|
|
93
|
+
* @throws The original error if it's not a rate limit error, if max retries exceeded, or if retry-after header is missing
|
|
94
|
+
*/
|
|
95
|
+
var retryWithBackoff = function (fn_1) {
|
|
96
|
+
var args_1 = [];
|
|
97
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
98
|
+
args_1[_i - 1] = arguments[_i];
|
|
99
|
+
}
|
|
100
|
+
return __awaiter(void 0, __spreadArray([fn_1], args_1, true), void 0, function (fn, options) {
|
|
101
|
+
var opts, lastError, attempt, error_1, retryAfter, delay, err;
|
|
102
|
+
if (options === void 0) { options = {}; }
|
|
103
|
+
return __generator(this, function (_a) {
|
|
104
|
+
switch (_a.label) {
|
|
105
|
+
case 0:
|
|
106
|
+
opts = __assign({ maxRetries: 5, maxRetryAfter: 70000, onRetry: function () { } }, options);
|
|
107
|
+
attempt = 1;
|
|
108
|
+
_a.label = 1;
|
|
109
|
+
case 1:
|
|
110
|
+
if (!(attempt <= opts.maxRetries)) return [3 /*break*/, 7];
|
|
111
|
+
_a.label = 2;
|
|
112
|
+
case 2:
|
|
113
|
+
_a.trys.push([2, 4, , 6]);
|
|
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;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
exports.retryWithBackoff = retryWithBackoff;
|
package/dist/shared/index.d.ts
CHANGED
package/dist/shared/index.js
CHANGED
|
@@ -17,7 +17,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.AppError = void 0;
|
|
20
|
+
exports.retryWithBackoff = exports.HttpClient = exports.AppError = void 0;
|
|
21
21
|
__exportStar(require("./types/apiConnection"), exports);
|
|
22
22
|
var errors_1 = require("./types/errors");
|
|
23
23
|
Object.defineProperty(exports, "AppError", { enumerable: true, get: function () { return __importDefault(errors_1).default; } });
|
|
24
|
+
var client_1 = require("./http/client");
|
|
25
|
+
Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return client_1.HttpClient; } });
|
|
26
|
+
var retryWithBackoff_1 = require("./http/retryWithBackoff");
|
|
27
|
+
Object.defineProperty(exports, "retryWithBackoff", { enumerable: true, get: function () { return retryWithBackoff_1.retryWithBackoff; } });
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Token } from '../../auth';
|
|
2
|
+
import { RetryOptions } from '../http/retryWithBackoff';
|
|
2
3
|
import { UnauthorizedCallback } from '../http/types';
|
|
3
4
|
export type ApiUrl = string;
|
|
4
5
|
export interface AppDetails {
|
|
@@ -11,4 +12,5 @@ export interface ApiSecurity {
|
|
|
11
12
|
token: Token;
|
|
12
13
|
workspaceToken?: Token;
|
|
13
14
|
unauthorizedCallback?: UnauthorizedCallback;
|
|
15
|
+
retryOptions?: RetryOptions;
|
|
14
16
|
}
|
package/dist/workspaces/index.js
CHANGED
|
@@ -41,7 +41,7 @@ var headers_1 = require("../shared/headers");
|
|
|
41
41
|
var client_1 = require("../shared/http/client");
|
|
42
42
|
var Workspaces = /** @class */ (function () {
|
|
43
43
|
function Workspaces(apiUrl, appDetails, apiSecurity) {
|
|
44
|
-
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback);
|
|
44
|
+
this.client = client_1.HttpClient.create(apiUrl, apiSecurity.unauthorizedCallback, apiSecurity.retryOptions);
|
|
45
45
|
this.appDetails = appDetails;
|
|
46
46
|
this.apiSecurity = apiSecurity;
|
|
47
47
|
}
|