@credal/sdk 0.1.9 → 0.1.11
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/cjs/BaseClient.d.ts +4 -0
- package/dist/cjs/Client.js +3 -3
- package/dist/cjs/api/resources/copilots/client/Client.js +27 -9
- package/dist/cjs/api/resources/documentCatalog/client/Client.d.ts +8 -0
- package/dist/cjs/api/resources/documentCatalog/client/Client.js +95 -3
- package/dist/cjs/api/resources/documentCatalog/client/requests/UploadFileRequest.d.ts +27 -0
- package/dist/cjs/api/resources/documentCatalog/client/requests/UploadFileRequest.js +3 -0
- package/dist/cjs/api/resources/documentCatalog/client/requests/index.d.ts +1 -0
- package/dist/cjs/api/resources/documentCollections/client/Client.js +21 -7
- package/dist/cjs/api/resources/search/client/Client.js +3 -1
- package/dist/cjs/api/resources/users/client/Client.js +3 -1
- package/dist/cjs/core/exports.d.ts +2 -0
- package/dist/cjs/core/exports.js +18 -0
- package/dist/cjs/core/fetcher/Fetcher.d.ts +4 -1
- package/dist/cjs/core/fetcher/Fetcher.js +202 -9
- package/dist/cjs/core/fetcher/getRequestBody.d.ts +1 -1
- package/dist/cjs/core/fetcher/getRequestBody.js +4 -0
- package/dist/cjs/core/fetcher/makeRequest.d.ts +1 -1
- package/dist/cjs/core/fetcher/makeRequest.js +0 -2
- package/dist/cjs/core/fetcher/requestWithRetries.js +0 -9
- package/dist/cjs/core/fetcher/signals.d.ts +0 -6
- package/dist/cjs/core/fetcher/signals.js +0 -12
- package/dist/cjs/core/file/exports.d.ts +1 -0
- package/dist/cjs/core/file/exports.js +2 -0
- package/dist/cjs/core/file/file.d.ts +10 -0
- package/dist/cjs/core/file/file.js +221 -0
- package/dist/cjs/core/file/index.d.ts +2 -0
- package/dist/cjs/core/file/index.js +18 -0
- package/dist/cjs/core/file/types.d.ts +66 -0
- package/dist/cjs/core/file/types.js +2 -0
- package/dist/cjs/core/form-data-utils/FormDataWrapper.d.ts +15 -0
- package/dist/cjs/core/form-data-utils/FormDataWrapper.js +185 -0
- package/dist/cjs/core/form-data-utils/encodeAsFormParameter.d.ts +1 -0
- package/dist/cjs/core/form-data-utils/encodeAsFormParameter.js +12 -0
- package/dist/cjs/core/form-data-utils/index.d.ts +2 -0
- package/dist/cjs/core/form-data-utils/index.js +20 -0
- package/dist/cjs/core/headers.js +6 -4
- package/dist/cjs/core/index.d.ts +3 -0
- package/dist/cjs/core/index.js +4 -1
- package/dist/cjs/core/logging/exports.d.ts +18 -0
- package/dist/cjs/core/logging/exports.js +45 -0
- package/dist/cjs/core/logging/index.d.ts +1 -0
- package/dist/cjs/core/logging/index.js +17 -0
- package/dist/cjs/core/logging/logger.d.ts +126 -0
- package/dist/cjs/core/logging/logger.js +144 -0
- package/dist/cjs/core/url/join.js +0 -1
- package/dist/cjs/exports.d.ts +1 -0
- package/dist/cjs/exports.js +17 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.d.mts +4 -0
- package/dist/esm/Client.mjs +3 -3
- package/dist/esm/api/resources/copilots/client/Client.mjs +27 -9
- package/dist/esm/api/resources/documentCatalog/client/Client.d.mts +8 -0
- package/dist/esm/api/resources/documentCatalog/client/Client.mjs +95 -3
- package/dist/esm/api/resources/documentCatalog/client/requests/UploadFileRequest.d.mts +27 -0
- package/dist/esm/api/resources/documentCatalog/client/requests/UploadFileRequest.mjs +2 -0
- package/dist/esm/api/resources/documentCatalog/client/requests/index.d.mts +1 -0
- package/dist/esm/api/resources/documentCollections/client/Client.mjs +21 -7
- package/dist/esm/api/resources/search/client/Client.mjs +3 -1
- package/dist/esm/api/resources/users/client/Client.mjs +3 -1
- package/dist/esm/core/exports.d.mts +2 -0
- package/dist/esm/core/exports.mjs +2 -0
- package/dist/esm/core/fetcher/Fetcher.d.mts +4 -1
- package/dist/esm/core/fetcher/Fetcher.mjs +202 -9
- package/dist/esm/core/fetcher/getRequestBody.d.mts +1 -1
- package/dist/esm/core/fetcher/getRequestBody.mjs +4 -0
- package/dist/esm/core/fetcher/makeRequest.d.mts +1 -1
- package/dist/esm/core/fetcher/makeRequest.mjs +0 -2
- package/dist/esm/core/fetcher/requestWithRetries.mjs +0 -9
- package/dist/esm/core/fetcher/signals.d.mts +0 -6
- package/dist/esm/core/fetcher/signals.mjs +0 -12
- package/dist/esm/core/file/exports.d.mts +1 -0
- package/dist/esm/core/file/exports.mjs +1 -0
- package/dist/esm/core/file/file.d.mts +10 -0
- package/dist/esm/core/file/file.mjs +184 -0
- package/dist/esm/core/file/index.d.mts +2 -0
- package/dist/esm/core/file/index.mjs +2 -0
- package/dist/esm/core/file/types.d.mts +66 -0
- package/dist/esm/core/file/types.mjs +1 -0
- package/dist/esm/core/form-data-utils/FormDataWrapper.d.mts +15 -0
- package/dist/esm/core/form-data-utils/FormDataWrapper.mjs +147 -0
- package/dist/esm/core/form-data-utils/encodeAsFormParameter.d.mts +1 -0
- package/dist/esm/core/form-data-utils/encodeAsFormParameter.mjs +9 -0
- package/dist/esm/core/form-data-utils/index.d.mts +2 -0
- package/dist/esm/core/form-data-utils/index.mjs +2 -0
- package/dist/esm/core/headers.mjs +6 -4
- package/dist/esm/core/index.d.mts +3 -0
- package/dist/esm/core/index.mjs +3 -0
- package/dist/esm/core/logging/exports.d.mts +18 -0
- package/dist/esm/core/logging/exports.mjs +9 -0
- package/dist/esm/core/logging/index.d.mts +1 -0
- package/dist/esm/core/logging/index.mjs +1 -0
- package/dist/esm/core/logging/logger.d.mts +126 -0
- package/dist/esm/core/logging/logger.mjs +138 -0
- package/dist/esm/core/url/join.mjs +0 -1
- package/dist/esm/exports.d.mts +1 -0
- package/dist/esm/exports.mjs +1 -0
- package/dist/esm/index.d.mts +1 -0
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +3 -2
|
@@ -41,7 +41,7 @@ export class DocumentCollections {
|
|
|
41
41
|
}
|
|
42
42
|
__addDocumentsToCollection(request, requestOptions) {
|
|
43
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
44
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
45
45
|
const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
46
46
|
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
|
|
47
47
|
url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.CredalEnvironment.Production, "/v0/documentCollections/addDocumentsToCollection"),
|
|
@@ -54,6 +54,8 @@ export class DocumentCollections {
|
|
|
54
54
|
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
|
|
55
55
|
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
|
|
56
56
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
57
|
+
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
|
|
58
|
+
logging: this._options.logging,
|
|
57
59
|
});
|
|
58
60
|
if (_response.ok) {
|
|
59
61
|
return { data: undefined, rawResponse: _response.rawResponse };
|
|
@@ -107,7 +109,7 @@ export class DocumentCollections {
|
|
|
107
109
|
}
|
|
108
110
|
__removeDocumentsFromCollection(request, requestOptions) {
|
|
109
111
|
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
112
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
111
113
|
const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
112
114
|
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
|
|
113
115
|
url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.CredalEnvironment.Production, "/v0/documentCollections/removeDocumentsFromCollection"),
|
|
@@ -120,6 +122,8 @@ export class DocumentCollections {
|
|
|
120
122
|
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
|
|
121
123
|
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
|
|
122
124
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
125
|
+
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
|
|
126
|
+
logging: this._options.logging,
|
|
123
127
|
});
|
|
124
128
|
if (_response.ok) {
|
|
125
129
|
return { data: undefined, rawResponse: _response.rawResponse };
|
|
@@ -164,7 +168,7 @@ export class DocumentCollections {
|
|
|
164
168
|
}
|
|
165
169
|
__listDocumentsInCollection(request, requestOptions) {
|
|
166
170
|
return __awaiter(this, void 0, void 0, function* () {
|
|
167
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
171
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
168
172
|
const { collectionId } = request;
|
|
169
173
|
const _queryParams = {};
|
|
170
174
|
_queryParams.collectionId = collectionId;
|
|
@@ -177,6 +181,8 @@ export class DocumentCollections {
|
|
|
177
181
|
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
|
|
178
182
|
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
|
|
179
183
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
184
|
+
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
|
|
185
|
+
logging: this._options.logging,
|
|
180
186
|
});
|
|
181
187
|
if (_response.ok) {
|
|
182
188
|
return {
|
|
@@ -229,7 +235,7 @@ export class DocumentCollections {
|
|
|
229
235
|
}
|
|
230
236
|
__createCollection(request, requestOptions) {
|
|
231
237
|
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
238
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
233
239
|
const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
234
240
|
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
|
|
235
241
|
url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.CredalEnvironment.Production, "/v0/documentCollections/createCollection"),
|
|
@@ -242,6 +248,8 @@ export class DocumentCollections {
|
|
|
242
248
|
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
|
|
243
249
|
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
|
|
244
250
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
251
|
+
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
|
|
252
|
+
logging: this._options.logging,
|
|
245
253
|
});
|
|
246
254
|
if (_response.ok) {
|
|
247
255
|
return { data: _response.body, rawResponse: _response.rawResponse };
|
|
@@ -286,7 +294,7 @@ export class DocumentCollections {
|
|
|
286
294
|
}
|
|
287
295
|
__deleteCollection(request, requestOptions) {
|
|
288
296
|
return __awaiter(this, void 0, void 0, function* () {
|
|
289
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
297
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
290
298
|
const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
291
299
|
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
|
|
292
300
|
url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.CredalEnvironment.Production, "/v0/documentCollections/deleteCollection"),
|
|
@@ -299,6 +307,8 @@ export class DocumentCollections {
|
|
|
299
307
|
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
|
|
300
308
|
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
|
|
301
309
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
310
|
+
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
|
|
311
|
+
logging: this._options.logging,
|
|
302
312
|
});
|
|
303
313
|
if (_response.ok) {
|
|
304
314
|
return { data: _response.body, rawResponse: _response.rawResponse };
|
|
@@ -359,7 +369,7 @@ export class DocumentCollections {
|
|
|
359
369
|
}
|
|
360
370
|
__createMongoCollectionSync(request, requestOptions) {
|
|
361
371
|
return __awaiter(this, void 0, void 0, function* () {
|
|
362
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
372
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
363
373
|
const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
364
374
|
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
|
|
365
375
|
url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.CredalEnvironment.Production, "/v0/documentCollections/mongodb/createMongoSync"),
|
|
@@ -372,6 +382,8 @@ export class DocumentCollections {
|
|
|
372
382
|
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
|
|
373
383
|
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
|
|
374
384
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
385
|
+
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
|
|
386
|
+
logging: this._options.logging,
|
|
375
387
|
});
|
|
376
388
|
if (_response.ok) {
|
|
377
389
|
return { data: _response.body, rawResponse: _response.rawResponse };
|
|
@@ -432,7 +444,7 @@ export class DocumentCollections {
|
|
|
432
444
|
}
|
|
433
445
|
__updateMongoCollectionSync(request, requestOptions) {
|
|
434
446
|
return __awaiter(this, void 0, void 0, function* () {
|
|
435
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
447
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
436
448
|
const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
437
449
|
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
|
|
438
450
|
url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.CredalEnvironment.Production, "/v0/documentCollections/mongodb/updateMongoSync"),
|
|
@@ -445,6 +457,8 @@ export class DocumentCollections {
|
|
|
445
457
|
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
|
|
446
458
|
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
|
|
447
459
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
460
|
+
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
|
|
461
|
+
logging: this._options.logging,
|
|
448
462
|
});
|
|
449
463
|
if (_response.ok) {
|
|
450
464
|
return { data: _response.body, rawResponse: _response.rawResponse };
|
|
@@ -47,7 +47,7 @@ export class Search {
|
|
|
47
47
|
}
|
|
48
48
|
__searchDocumentCollection(request, requestOptions) {
|
|
49
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
50
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
51
51
|
const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
52
52
|
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
|
|
53
53
|
url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.CredalEnvironment.Production, "/v0/search/searchDocumentCollection"),
|
|
@@ -60,6 +60,8 @@ export class Search {
|
|
|
60
60
|
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
|
|
61
61
|
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
|
|
62
62
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
63
|
+
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
|
|
64
|
+
logging: this._options.logging,
|
|
63
65
|
});
|
|
64
66
|
if (_response.ok) {
|
|
65
67
|
return {
|
|
@@ -42,7 +42,7 @@ export class Users {
|
|
|
42
42
|
}
|
|
43
43
|
__metadata(request, requestOptions) {
|
|
44
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
45
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
46
46
|
const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
47
47
|
const _response = yield ((_b = this._options.fetcher) !== null && _b !== void 0 ? _b : core.fetcher)({
|
|
48
48
|
url: core.url.join((_d = (_c = (yield core.Supplier.get(this._options.baseUrl))) !== null && _c !== void 0 ? _c : (yield core.Supplier.get(this._options.environment))) !== null && _d !== void 0 ? _d : environments.CredalEnvironment.Production, "/v0/users/metadata"),
|
|
@@ -55,6 +55,8 @@ export class Users {
|
|
|
55
55
|
timeoutMs: ((_g = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _e !== void 0 ? _e : (_f = this._options) === null || _f === void 0 ? void 0 : _f.timeoutInSeconds) !== null && _g !== void 0 ? _g : 60) * 1000,
|
|
56
56
|
maxRetries: (_h = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _h !== void 0 ? _h : (_j = this._options) === null || _j === void 0 ? void 0 : _j.maxRetries,
|
|
57
57
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
58
|
+
fetchFn: (_k = this._options) === null || _k === void 0 ? void 0 : _k.fetch,
|
|
59
|
+
logging: this._options.logging,
|
|
58
60
|
});
|
|
59
61
|
if (_response.ok) {
|
|
60
62
|
return { data: undefined, rawResponse: _response.rawResponse };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type LogConfig, type Logger } from "../logging/logger.mjs";
|
|
1
2
|
import type { APIResponse } from "./APIResponse.mjs";
|
|
2
3
|
import type { EndpointMetadata } from "./EndpointMetadata.mjs";
|
|
3
4
|
import { EndpointSupplier } from "./EndpointSupplier.mjs";
|
|
@@ -14,10 +15,12 @@ export declare namespace Fetcher {
|
|
|
14
15
|
maxRetries?: number;
|
|
15
16
|
withCredentials?: boolean;
|
|
16
17
|
abortSignal?: AbortSignal;
|
|
17
|
-
requestType?: "json" | "file" | "bytes";
|
|
18
|
+
requestType?: "json" | "file" | "bytes" | "form" | "other";
|
|
18
19
|
responseType?: "json" | "blob" | "sse" | "streaming" | "text" | "arrayBuffer" | "binary-response";
|
|
19
20
|
duplex?: "half";
|
|
20
21
|
endpointMetadata?: EndpointMetadata;
|
|
22
|
+
fetchFn?: typeof fetch;
|
|
23
|
+
logging?: LogConfig | Logger;
|
|
21
24
|
}
|
|
22
25
|
type Error = FailedStatusCodeError | NonJsonError | TimeoutError | UnknownError;
|
|
23
26
|
interface FailedStatusCodeError {
|
|
@@ -8,21 +8,153 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { toJson } from "../json.mjs";
|
|
11
|
+
import { createLogger } from "../logging/logger.mjs";
|
|
11
12
|
import { createRequestUrl } from "./createRequestUrl.mjs";
|
|
12
13
|
import { EndpointSupplier } from "./EndpointSupplier.mjs";
|
|
13
14
|
import { getErrorResponseBody } from "./getErrorResponseBody.mjs";
|
|
14
15
|
import { getFetchFn } from "./getFetchFn.mjs";
|
|
15
16
|
import { getRequestBody } from "./getRequestBody.mjs";
|
|
16
17
|
import { getResponseBody } from "./getResponseBody.mjs";
|
|
18
|
+
import { Headers } from "./Headers.mjs";
|
|
17
19
|
import { makeRequest } from "./makeRequest.mjs";
|
|
18
20
|
import { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse.mjs";
|
|
19
21
|
import { requestWithRetries } from "./requestWithRetries.mjs";
|
|
22
|
+
const SENSITIVE_HEADERS = new Set([
|
|
23
|
+
"authorization",
|
|
24
|
+
"www-authenticate",
|
|
25
|
+
"x-api-key",
|
|
26
|
+
"api-key",
|
|
27
|
+
"apikey",
|
|
28
|
+
"x-api-token",
|
|
29
|
+
"x-auth-token",
|
|
30
|
+
"auth-token",
|
|
31
|
+
"cookie",
|
|
32
|
+
"set-cookie",
|
|
33
|
+
"proxy-authorization",
|
|
34
|
+
"proxy-authenticate",
|
|
35
|
+
"x-csrf-token",
|
|
36
|
+
"x-xsrf-token",
|
|
37
|
+
"x-session-token",
|
|
38
|
+
"x-access-token",
|
|
39
|
+
]);
|
|
40
|
+
function redactHeaders(headers) {
|
|
41
|
+
const filtered = {};
|
|
42
|
+
for (const [key, value] of headers instanceof Headers ? headers.entries() : Object.entries(headers)) {
|
|
43
|
+
if (SENSITIVE_HEADERS.has(key.toLowerCase())) {
|
|
44
|
+
filtered[key] = "[REDACTED]";
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
filtered[key] = value;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return filtered;
|
|
51
|
+
}
|
|
52
|
+
const SENSITIVE_QUERY_PARAMS = new Set([
|
|
53
|
+
"api_key",
|
|
54
|
+
"api-key",
|
|
55
|
+
"apikey",
|
|
56
|
+
"token",
|
|
57
|
+
"access_token",
|
|
58
|
+
"access-token",
|
|
59
|
+
"auth_token",
|
|
60
|
+
"auth-token",
|
|
61
|
+
"password",
|
|
62
|
+
"passwd",
|
|
63
|
+
"secret",
|
|
64
|
+
"api_secret",
|
|
65
|
+
"api-secret",
|
|
66
|
+
"apisecret",
|
|
67
|
+
"key",
|
|
68
|
+
"session",
|
|
69
|
+
"session_id",
|
|
70
|
+
"session-id",
|
|
71
|
+
]);
|
|
72
|
+
function redactQueryParameters(queryParameters) {
|
|
73
|
+
if (queryParameters == null) {
|
|
74
|
+
return queryParameters;
|
|
75
|
+
}
|
|
76
|
+
const redacted = {};
|
|
77
|
+
for (const [key, value] of Object.entries(queryParameters)) {
|
|
78
|
+
if (SENSITIVE_QUERY_PARAMS.has(key.toLowerCase())) {
|
|
79
|
+
redacted[key] = "[REDACTED]";
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
redacted[key] = value;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return redacted;
|
|
86
|
+
}
|
|
87
|
+
function redactUrl(url) {
|
|
88
|
+
const protocolIndex = url.indexOf("://");
|
|
89
|
+
if (protocolIndex === -1)
|
|
90
|
+
return url;
|
|
91
|
+
const afterProtocol = protocolIndex + 3;
|
|
92
|
+
// Find the first delimiter that marks the end of the authority section
|
|
93
|
+
const pathStart = url.indexOf("/", afterProtocol);
|
|
94
|
+
let queryStart = url.indexOf("?", afterProtocol);
|
|
95
|
+
let fragmentStart = url.indexOf("#", afterProtocol);
|
|
96
|
+
const firstDelimiter = Math.min(pathStart === -1 ? url.length : pathStart, queryStart === -1 ? url.length : queryStart, fragmentStart === -1 ? url.length : fragmentStart);
|
|
97
|
+
// Find the LAST @ before the delimiter (handles multiple @ in credentials)
|
|
98
|
+
let atIndex = -1;
|
|
99
|
+
for (let i = afterProtocol; i < firstDelimiter; i++) {
|
|
100
|
+
if (url[i] === "@") {
|
|
101
|
+
atIndex = i;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (atIndex !== -1) {
|
|
105
|
+
url = `${url.slice(0, afterProtocol)}[REDACTED]@${url.slice(atIndex + 1)}`;
|
|
106
|
+
}
|
|
107
|
+
// Recalculate queryStart since url might have changed
|
|
108
|
+
queryStart = url.indexOf("?");
|
|
109
|
+
if (queryStart === -1)
|
|
110
|
+
return url;
|
|
111
|
+
fragmentStart = url.indexOf("#", queryStart);
|
|
112
|
+
const queryEnd = fragmentStart !== -1 ? fragmentStart : url.length;
|
|
113
|
+
const queryString = url.slice(queryStart + 1, queryEnd);
|
|
114
|
+
if (queryString.length === 0)
|
|
115
|
+
return url;
|
|
116
|
+
// FAST PATH: Quick check if any sensitive keywords present
|
|
117
|
+
// Using indexOf is faster than regex for simple substring matching
|
|
118
|
+
const lower = queryString.toLowerCase();
|
|
119
|
+
const hasSensitive = lower.includes("token") ||
|
|
120
|
+
lower.includes("key") ||
|
|
121
|
+
lower.includes("password") ||
|
|
122
|
+
lower.includes("passwd") ||
|
|
123
|
+
lower.includes("secret") ||
|
|
124
|
+
lower.includes("session") ||
|
|
125
|
+
lower.includes("auth");
|
|
126
|
+
if (!hasSensitive) {
|
|
127
|
+
return url;
|
|
128
|
+
}
|
|
129
|
+
// SLOW PATH: Parse and redact
|
|
130
|
+
const redactedParams = [];
|
|
131
|
+
const params = queryString.split("&");
|
|
132
|
+
for (const param of params) {
|
|
133
|
+
const equalIndex = param.indexOf("=");
|
|
134
|
+
if (equalIndex === -1) {
|
|
135
|
+
redactedParams.push(param);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const key = param.slice(0, equalIndex);
|
|
139
|
+
let shouldRedact = SENSITIVE_QUERY_PARAMS.has(key.toLowerCase());
|
|
140
|
+
if (!shouldRedact && key.includes("%")) {
|
|
141
|
+
try {
|
|
142
|
+
const decodedKey = decodeURIComponent(key);
|
|
143
|
+
shouldRedact = SENSITIVE_QUERY_PARAMS.has(decodedKey.toLowerCase());
|
|
144
|
+
}
|
|
145
|
+
catch (_a) { }
|
|
146
|
+
}
|
|
147
|
+
redactedParams.push(shouldRedact ? `${key}=[REDACTED]` : param);
|
|
148
|
+
}
|
|
149
|
+
return url.slice(0, queryStart + 1) + redactedParams.join("&") + url.slice(queryEnd);
|
|
150
|
+
}
|
|
20
151
|
function getHeaders(args) {
|
|
21
152
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
153
|
var _a;
|
|
23
|
-
const newHeaders =
|
|
154
|
+
const newHeaders = new Headers();
|
|
155
|
+
newHeaders.set("Accept", args.responseType === "json" ? "application/json" : args.responseType === "text" ? "text/plain" : "*/*");
|
|
24
156
|
if (args.body !== undefined && args.contentType != null) {
|
|
25
|
-
newHeaders
|
|
157
|
+
newHeaders.set("Content-Type", args.contentType);
|
|
26
158
|
}
|
|
27
159
|
if (args.headers == null) {
|
|
28
160
|
return newHeaders;
|
|
@@ -30,31 +162,52 @@ function getHeaders(args) {
|
|
|
30
162
|
for (const [key, value] of Object.entries(args.headers)) {
|
|
31
163
|
const result = yield EndpointSupplier.get(value, { endpointMetadata: (_a = args.endpointMetadata) !== null && _a !== void 0 ? _a : {} });
|
|
32
164
|
if (typeof result === "string") {
|
|
33
|
-
newHeaders
|
|
165
|
+
newHeaders.set(key, result);
|
|
34
166
|
continue;
|
|
35
167
|
}
|
|
36
168
|
if (result == null) {
|
|
37
169
|
continue;
|
|
38
170
|
}
|
|
39
|
-
newHeaders
|
|
171
|
+
newHeaders.set(key, `${result}`);
|
|
40
172
|
}
|
|
41
173
|
return newHeaders;
|
|
42
174
|
});
|
|
43
175
|
}
|
|
44
176
|
export function fetcherImpl(args) {
|
|
45
177
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
var _a;
|
|
178
|
+
var _a, _b, _c;
|
|
47
179
|
const url = createRequestUrl(args.url, args.queryParameters);
|
|
48
180
|
const requestBody = yield getRequestBody({
|
|
49
181
|
body: args.body,
|
|
50
|
-
type: args.requestType
|
|
182
|
+
type: (_a = args.requestType) !== null && _a !== void 0 ? _a : "other",
|
|
51
183
|
});
|
|
52
|
-
const fetchFn = yield getFetchFn();
|
|
184
|
+
const fetchFn = (_b = args.fetchFn) !== null && _b !== void 0 ? _b : (yield getFetchFn());
|
|
185
|
+
const headers = yield getHeaders(args);
|
|
186
|
+
const logger = createLogger(args.logging);
|
|
187
|
+
if (logger.isDebug()) {
|
|
188
|
+
const metadata = {
|
|
189
|
+
method: args.method,
|
|
190
|
+
url: redactUrl(url),
|
|
191
|
+
headers: redactHeaders(headers),
|
|
192
|
+
queryParameters: redactQueryParameters(args.queryParameters),
|
|
193
|
+
hasBody: requestBody != null,
|
|
194
|
+
};
|
|
195
|
+
logger.debug("Making HTTP request", metadata);
|
|
196
|
+
}
|
|
53
197
|
try {
|
|
54
198
|
const response = yield requestWithRetries(() => __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
return makeRequest(fetchFn, url, args.method,
|
|
199
|
+
return makeRequest(fetchFn, url, args.method, headers, requestBody, args.timeoutMs, args.abortSignal, args.withCredentials, args.duplex);
|
|
56
200
|
}), args.maxRetries);
|
|
57
201
|
if (response.status >= 200 && response.status < 400) {
|
|
202
|
+
if (logger.isDebug()) {
|
|
203
|
+
const metadata = {
|
|
204
|
+
method: args.method,
|
|
205
|
+
url: redactUrl(url),
|
|
206
|
+
statusCode: response.status,
|
|
207
|
+
responseHeaders: redactHeaders(response.headers),
|
|
208
|
+
};
|
|
209
|
+
logger.debug("HTTP request succeeded", metadata);
|
|
210
|
+
}
|
|
58
211
|
return {
|
|
59
212
|
ok: true,
|
|
60
213
|
body: (yield getResponseBody(response, args.responseType)),
|
|
@@ -63,6 +216,15 @@ export function fetcherImpl(args) {
|
|
|
63
216
|
};
|
|
64
217
|
}
|
|
65
218
|
else {
|
|
219
|
+
if (logger.isError()) {
|
|
220
|
+
const metadata = {
|
|
221
|
+
method: args.method,
|
|
222
|
+
url: redactUrl(url),
|
|
223
|
+
statusCode: response.status,
|
|
224
|
+
responseHeaders: redactHeaders(Object.fromEntries(response.headers.entries())),
|
|
225
|
+
};
|
|
226
|
+
logger.error("HTTP request failed with error status", metadata);
|
|
227
|
+
}
|
|
66
228
|
return {
|
|
67
229
|
ok: false,
|
|
68
230
|
error: {
|
|
@@ -75,7 +237,14 @@ export function fetcherImpl(args) {
|
|
|
75
237
|
}
|
|
76
238
|
}
|
|
77
239
|
catch (error) {
|
|
78
|
-
if ((
|
|
240
|
+
if ((_c = args.abortSignal) === null || _c === void 0 ? void 0 : _c.aborted) {
|
|
241
|
+
if (logger.isError()) {
|
|
242
|
+
const metadata = {
|
|
243
|
+
method: args.method,
|
|
244
|
+
url: redactUrl(url),
|
|
245
|
+
};
|
|
246
|
+
logger.error("HTTP request was aborted", metadata);
|
|
247
|
+
}
|
|
79
248
|
return {
|
|
80
249
|
ok: false,
|
|
81
250
|
error: {
|
|
@@ -86,6 +255,14 @@ export function fetcherImpl(args) {
|
|
|
86
255
|
};
|
|
87
256
|
}
|
|
88
257
|
else if (error instanceof Error && error.name === "AbortError") {
|
|
258
|
+
if (logger.isError()) {
|
|
259
|
+
const metadata = {
|
|
260
|
+
method: args.method,
|
|
261
|
+
url: redactUrl(url),
|
|
262
|
+
timeoutMs: args.timeoutMs,
|
|
263
|
+
};
|
|
264
|
+
logger.error("HTTP request timed out", metadata);
|
|
265
|
+
}
|
|
89
266
|
return {
|
|
90
267
|
ok: false,
|
|
91
268
|
error: {
|
|
@@ -95,6 +272,14 @@ export function fetcherImpl(args) {
|
|
|
95
272
|
};
|
|
96
273
|
}
|
|
97
274
|
else if (error instanceof Error) {
|
|
275
|
+
if (logger.isError()) {
|
|
276
|
+
const metadata = {
|
|
277
|
+
method: args.method,
|
|
278
|
+
url: redactUrl(url),
|
|
279
|
+
errorMessage: error.message,
|
|
280
|
+
};
|
|
281
|
+
logger.error("HTTP request failed with error", metadata);
|
|
282
|
+
}
|
|
98
283
|
return {
|
|
99
284
|
ok: false,
|
|
100
285
|
error: {
|
|
@@ -104,6 +289,14 @@ export function fetcherImpl(args) {
|
|
|
104
289
|
rawResponse: unknownRawResponse,
|
|
105
290
|
};
|
|
106
291
|
}
|
|
292
|
+
if (logger.isError()) {
|
|
293
|
+
const metadata = {
|
|
294
|
+
method: args.method,
|
|
295
|
+
url: redactUrl(url),
|
|
296
|
+
error: toJson(error),
|
|
297
|
+
};
|
|
298
|
+
logger.error("HTTP request failed with unknown error", metadata);
|
|
299
|
+
}
|
|
107
300
|
return {
|
|
108
301
|
ok: false,
|
|
109
302
|
error: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare namespace GetRequestBody {
|
|
2
2
|
interface Args {
|
|
3
3
|
body: unknown;
|
|
4
|
-
type: "json" | "file" | "bytes" | "other";
|
|
4
|
+
type: "json" | "file" | "bytes" | "form" | "other";
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
7
|
export declare function getRequestBody({ body, type }: GetRequestBody.Args): Promise<BodyInit | undefined>;
|
|
@@ -8,8 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { toJson } from "../json.mjs";
|
|
11
|
+
import { toQueryString } from "../url/qs.mjs";
|
|
11
12
|
export function getRequestBody(_a) {
|
|
12
13
|
return __awaiter(this, arguments, void 0, function* ({ body, type }) {
|
|
14
|
+
if (type === "form") {
|
|
15
|
+
return toQueryString(body, { arrayFormat: "repeat", encode: true });
|
|
16
|
+
}
|
|
13
17
|
if (type.includes("json")) {
|
|
14
18
|
return toJson(body);
|
|
15
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const makeRequest: (fetchFn: (url: string, init: RequestInit) => Promise<Response>, url: string, method: string, headers: Record<string, string>, requestBody: BodyInit | undefined, timeoutMs?: number, abortSignal?: AbortSignal, withCredentials?: boolean, duplex?: "half") => Promise<Response>;
|
|
1
|
+
export declare const makeRequest: (fetchFn: (url: string, init: RequestInit) => Promise<Response>, url: string, method: string, headers: Headers | Record<string, string>, requestBody: BodyInit | undefined, timeoutMs?: number, abortSignal?: AbortSignal, withCredentials?: boolean, duplex?: "half") => Promise<Response>;
|
|
@@ -10,14 +10,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { anySignal, getTimeoutSignal } from "./signals.mjs";
|
|
11
11
|
export const makeRequest = (fetchFn, url, method, headers, requestBody, timeoutMs, abortSignal, withCredentials, duplex) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
12
|
const signals = [];
|
|
13
|
-
// Add timeout signal
|
|
14
13
|
let timeoutAbortId;
|
|
15
14
|
if (timeoutMs != null) {
|
|
16
15
|
const { signal, abortId } = getTimeoutSignal(timeoutMs);
|
|
17
16
|
timeoutAbortId = abortId;
|
|
18
17
|
signals.push(signal);
|
|
19
18
|
}
|
|
20
|
-
// Add arbitrary signal
|
|
21
19
|
if (abortSignal != null) {
|
|
22
20
|
signals.push(abortSignal);
|
|
23
21
|
}
|
|
@@ -12,25 +12,20 @@ const MAX_RETRY_DELAY = 60000; // in milliseconds
|
|
|
12
12
|
const DEFAULT_MAX_RETRIES = 2;
|
|
13
13
|
const JITTER_FACTOR = 0.2; // 20% random jitter
|
|
14
14
|
function addPositiveJitter(delay) {
|
|
15
|
-
// Generate a random value between 0 and +JITTER_FACTOR
|
|
16
15
|
const jitterMultiplier = 1 + Math.random() * JITTER_FACTOR;
|
|
17
16
|
return delay * jitterMultiplier;
|
|
18
17
|
}
|
|
19
18
|
function addSymmetricJitter(delay) {
|
|
20
|
-
// Generate a random value in a JITTER_FACTOR-sized percentage range around delay
|
|
21
19
|
const jitterMultiplier = 1 + (Math.random() - 0.5) * JITTER_FACTOR;
|
|
22
20
|
return delay * jitterMultiplier;
|
|
23
21
|
}
|
|
24
22
|
function getRetryDelayFromHeaders(response, retryAttempt) {
|
|
25
|
-
// Check for Retry-After header first (RFC 7231), with no jitter
|
|
26
23
|
const retryAfter = response.headers.get("Retry-After");
|
|
27
24
|
if (retryAfter) {
|
|
28
|
-
// Parse as number of seconds...
|
|
29
25
|
const retryAfterSeconds = parseInt(retryAfter, 10);
|
|
30
26
|
if (!Number.isNaN(retryAfterSeconds) && retryAfterSeconds > 0) {
|
|
31
27
|
return Math.min(retryAfterSeconds * 1000, MAX_RETRY_DELAY);
|
|
32
28
|
}
|
|
33
|
-
// ...or as an HTTP date; both are valid
|
|
34
29
|
const retryAfterDate = new Date(retryAfter);
|
|
35
30
|
if (!Number.isNaN(retryAfterDate.getTime())) {
|
|
36
31
|
const delay = retryAfterDate.getTime() - Date.now();
|
|
@@ -39,19 +34,16 @@ function getRetryDelayFromHeaders(response, retryAttempt) {
|
|
|
39
34
|
}
|
|
40
35
|
}
|
|
41
36
|
}
|
|
42
|
-
// Then check for industry-standard X-RateLimit-Reset header, with positive jitter
|
|
43
37
|
const rateLimitReset = response.headers.get("X-RateLimit-Reset");
|
|
44
38
|
if (rateLimitReset) {
|
|
45
39
|
const resetTime = parseInt(rateLimitReset, 10);
|
|
46
40
|
if (!Number.isNaN(resetTime)) {
|
|
47
|
-
// Assume Unix timestamp in epoch seconds
|
|
48
41
|
const delay = resetTime * 1000 - Date.now();
|
|
49
42
|
if (delay > 0) {
|
|
50
43
|
return addPositiveJitter(Math.min(delay, MAX_RETRY_DELAY));
|
|
51
44
|
}
|
|
52
45
|
}
|
|
53
46
|
}
|
|
54
|
-
// Fall back to exponential backoff, with symmetric jitter
|
|
55
47
|
return addSymmetricJitter(Math.min(INITIAL_RETRY_DELAY * Math.pow(2, retryAttempt), MAX_RETRY_DELAY));
|
|
56
48
|
}
|
|
57
49
|
export function requestWithRetries(requestFn_1) {
|
|
@@ -59,7 +51,6 @@ export function requestWithRetries(requestFn_1) {
|
|
|
59
51
|
let response = yield requestFn();
|
|
60
52
|
for (let i = 0; i < maxRetries; ++i) {
|
|
61
53
|
if ([408, 429].includes(response.status) || response.status >= 500) {
|
|
62
|
-
// Get delay with appropriate jitter applied
|
|
63
54
|
const delay = getRetryDelayFromHeaders(response, i);
|
|
64
55
|
yield new Promise((resolve) => setTimeout(resolve, delay));
|
|
65
56
|
response = yield requestFn();
|
|
@@ -2,10 +2,4 @@ export declare function getTimeoutSignal(timeoutMs: number): {
|
|
|
2
2
|
signal: AbortSignal;
|
|
3
3
|
abortId: NodeJS.Timeout;
|
|
4
4
|
};
|
|
5
|
-
/**
|
|
6
|
-
* Returns an abort signal that is getting aborted when
|
|
7
|
-
* at least one of the specified abort signals is aborted.
|
|
8
|
-
*
|
|
9
|
-
* Requires at least node.js 18.
|
|
10
|
-
*/
|
|
11
5
|
export declare function anySignal(...args: AbortSignal[] | [AbortSignal[]]): AbortSignal;
|
|
@@ -4,26 +4,14 @@ export function getTimeoutSignal(timeoutMs) {
|
|
|
4
4
|
const abortId = setTimeout(() => controller.abort(TIMEOUT), timeoutMs);
|
|
5
5
|
return { signal: controller.signal, abortId };
|
|
6
6
|
}
|
|
7
|
-
/**
|
|
8
|
-
* Returns an abort signal that is getting aborted when
|
|
9
|
-
* at least one of the specified abort signals is aborted.
|
|
10
|
-
*
|
|
11
|
-
* Requires at least node.js 18.
|
|
12
|
-
*/
|
|
13
7
|
export function anySignal(...args) {
|
|
14
|
-
// Allowing signals to be passed either as array
|
|
15
|
-
// of signals or as multiple arguments.
|
|
16
8
|
const signals = (args.length === 1 && Array.isArray(args[0]) ? args[0] : args);
|
|
17
9
|
const controller = new AbortController();
|
|
18
10
|
for (const signal of signals) {
|
|
19
11
|
if (signal.aborted) {
|
|
20
|
-
// Exiting early if one of the signals
|
|
21
|
-
// is already aborted.
|
|
22
12
|
controller.abort(signal === null || signal === void 0 ? void 0 : signal.reason);
|
|
23
13
|
break;
|
|
24
14
|
}
|
|
25
|
-
// Listening for signals and removing the listeners
|
|
26
|
-
// when at least one symbol is aborted.
|
|
27
15
|
signal.addEventListener("abort", () => controller.abort(signal === null || signal === void 0 ? void 0 : signal.reason), {
|
|
28
16
|
signal: controller.signal,
|
|
29
17
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { Uploadable } from "./types.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Uploadable } from "./types.mjs";
|
|
2
|
+
export declare function toBinaryUploadRequest(file: Uploadable): Promise<{
|
|
3
|
+
body: Uploadable.FileLike;
|
|
4
|
+
headers?: Record<string, string>;
|
|
5
|
+
}>;
|
|
6
|
+
export declare function toMultipartDataPart(file: Uploadable): Promise<{
|
|
7
|
+
data: Uploadable.FileLike;
|
|
8
|
+
filename?: string;
|
|
9
|
+
contentType?: string;
|
|
10
|
+
}>;
|