@apimatic/core
Advanced tools
Comparing version 0.7.0 to 0.7.1
@@ -35,6 +35,11 @@ import { __assign, __values, __awaiter, __generator } from 'tslib'; | ||
_c = _b.timeout, | ||
timeout = _c === void 0 ? DEFAULT_TIMEOUT : _c; | ||
timeout = _c === void 0 ? DEFAULT_TIMEOUT : _c, | ||
httpAgent = _b.httpAgent, | ||
httpsAgent = _b.httpsAgent; | ||
this._timeout = timeout; | ||
this._axiosInstance = axios.create(__assign(__assign({}, DEFAULT_AXIOS_CONFIG_OVERRIDES), clientConfigOverrides)); | ||
this._axiosInstance = axios.create(__assign(__assign(__assign({}, DEFAULT_AXIOS_CONFIG_OVERRIDES), clientConfigOverrides), { | ||
httpAgent: httpAgent, | ||
httpsAgent: httpsAgent | ||
})); | ||
} | ||
@@ -41,0 +46,0 @@ /** Converts an HttpRequest object to an Axios request. */ |
@@ -13,2 +13,3 @@ import { __spreadArray, __read, __assign, __awaiter, __generator } from 'tslib'; | ||
import { prepareArgs } from './validate.js'; | ||
import { getRetryWaitTime } from './retryConfiguration.js'; | ||
/** | ||
@@ -31,3 +32,3 @@ * bandwidthLib | ||
function () { | ||
function DefaultRequestBuilder(_httpClient, _baseUrlProvider, _apiErrorFactory, _authenticationProvider, _httpMethod, _xmlSerializer, _path) { | ||
function DefaultRequestBuilder(_httpClient, _baseUrlProvider, _apiErrorFactory, _authenticationProvider, _httpMethod, _xmlSerializer, _retryConfig, _path) { | ||
this._httpClient = _httpClient; | ||
@@ -39,2 +40,3 @@ this._baseUrlProvider = _baseUrlProvider; | ||
this._xmlSerializer = _xmlSerializer; | ||
this._retryConfig = _retryConfig; | ||
this._path = _path; | ||
@@ -50,2 +52,4 @@ this._headers = {}; | ||
this._addRetryInterceptor(); | ||
this.prepareArgs = prepareArgs.bind(this); | ||
@@ -560,8 +564,94 @@ } | ||
DefaultRequestBuilder.prototype._addRetryInterceptor = function () { | ||
var _this = this; | ||
this.intercept(function (request, options, next) { | ||
return __awaiter(_this, void 0, void 0, function () { | ||
var context, allowedWaitTime, retryCount, waitTime, timeoutError, error_2; | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
allowedWaitTime = this._retryConfig.maximumRetryWaitTime; | ||
retryCount = 0; | ||
waitTime = 0; | ||
_b.label = 1; | ||
case 1: | ||
timeoutError = undefined; | ||
if (!(retryCount > 0)) return [3 | ||
/*break*/ | ||
, 3]; | ||
return [4 | ||
/*yield*/ | ||
, new Promise(function (res) { | ||
return setTimeout(res, waitTime * 1000); | ||
})]; | ||
case 2: | ||
_b.sent(); | ||
allowedWaitTime -= waitTime; | ||
_b.label = 3; | ||
case 3: | ||
_b.trys.push([3, 5,, 6]); | ||
return [4 | ||
/*yield*/ | ||
, next(request, options)]; | ||
case 4: | ||
context = _b.sent(); | ||
return [3 | ||
/*break*/ | ||
, 6]; | ||
case 5: | ||
error_2 = _b.sent(); | ||
timeoutError = error_2; | ||
return [3 | ||
/*break*/ | ||
, 6]; | ||
case 6: | ||
waitTime = getRetryWaitTime(this._retryConfig, this._httpMethod, allowedWaitTime, retryCount, context === null || context === void 0 ? void 0 : context.response.statusCode, (_a = context === null || context === void 0 ? void 0 : context.response) === null || _a === void 0 ? void 0 : _a.headers, timeoutError); | ||
retryCount++; | ||
_b.label = 7; | ||
case 7: | ||
if (waitTime > 0) return [3 | ||
/*break*/ | ||
, 1]; | ||
_b.label = 8; | ||
case 8: | ||
if (timeoutError) { | ||
throw timeoutError; | ||
} | ||
if (typeof (context === null || context === void 0 ? void 0 : context.response) === 'undefined') { | ||
throw new Error('Response is undefined.'); | ||
} | ||
return [2 | ||
/*return*/ | ||
, { | ||
request: request, | ||
response: context.response | ||
}]; | ||
} | ||
}); | ||
}); | ||
}); | ||
}; | ||
return DefaultRequestBuilder; | ||
}(); | ||
function createRequestBuilderFactory(httpClient, baseUrlProvider, apiErrorFactory, authenticationProvider, xmlSerializer) { | ||
function createRequestBuilderFactory(httpClient, baseUrlProvider, apiErrorFactory, authenticationProvider, xmlSerializer, retryConfig) { | ||
return function (httpMethod, path) { | ||
return new DefaultRequestBuilder(httpClient, baseUrlProvider, apiErrorFactory, authenticationProvider, httpMethod, xmlSerializer, path); | ||
return new DefaultRequestBuilder(httpClient, baseUrlProvider, apiErrorFactory, authenticationProvider, httpMethod, xmlSerializer, retryConfig, path); | ||
}; | ||
@@ -568,0 +658,0 @@ } |
@@ -19,5 +19,7 @@ /** | ||
private _timeout; | ||
constructor({ clientConfigOverrides, timeout, }?: { | ||
constructor({ clientConfigOverrides, timeout, httpAgent, httpsAgent, }?: { | ||
clientConfigOverrides?: AxiosRequestConfig; | ||
timeout?: number; | ||
httpAgent?: any; | ||
httpsAgent?: any; | ||
}); | ||
@@ -37,2 +39,11 @@ /** Converts an HttpRequest object to an Axios request. */ | ||
} | ||
/** Stable configurable http client options. */ | ||
export interface HttpClientOptions { | ||
/** Timeout in milliseconds. */ | ||
timeout: number; | ||
/** Custom http agent to be used when performing http requests. */ | ||
httpAgent?: any; | ||
/** Custom https agent to be used when performing https requests. */ | ||
httpsAgent?: any; | ||
} | ||
//# sourceMappingURL=httpClient.d.ts.map |
@@ -29,5 +29,5 @@ "use strict"; | ||
function HttpClient(_a) { | ||
var _b = _a === void 0 ? {} : _a, clientConfigOverrides = _b.clientConfigOverrides, _c = _b.timeout, timeout = _c === void 0 ? exports.DEFAULT_TIMEOUT : _c; | ||
var _b = _a === void 0 ? {} : _a, clientConfigOverrides = _b.clientConfigOverrides, _c = _b.timeout, timeout = _c === void 0 ? exports.DEFAULT_TIMEOUT : _c, httpAgent = _b.httpAgent, httpsAgent = _b.httpsAgent; | ||
this._timeout = timeout; | ||
this._axiosInstance = axios_1.default.create(tslib_1.__assign(tslib_1.__assign({}, exports.DEFAULT_AXIOS_CONFIG_OVERRIDES), clientConfigOverrides)); | ||
this._axiosInstance = axios_1.default.create(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, exports.DEFAULT_AXIOS_CONFIG_OVERRIDES), clientConfigOverrides), { httpAgent: httpAgent, httpsAgent: httpsAgent })); | ||
} | ||
@@ -34,0 +34,0 @@ /** Converts an HttpRequest object to an Axios request. */ |
@@ -16,2 +16,3 @@ /** | ||
import { prepareArgs } from './validate'; | ||
import { RetryConfiguration } from './retryConfiguration'; | ||
export declare type RequestBuilderFactory<BaseUrlParamType, AuthParams> = (httpMethod: HttpMethod, path?: string) => RequestBuilder<BaseUrlParamType, AuthParams>; | ||
@@ -83,2 +84,3 @@ declare type QueryValue = string | string[] | number | number[] | bigint | Array<bigint> | boolean | null | undefined; | ||
protected _xmlSerializer: XmlSerializerInterface; | ||
protected _retryConfig: RetryConfiguration; | ||
protected _path?: string | undefined; | ||
@@ -98,3 +100,3 @@ protected _accept?: string; | ||
prepareArgs: typeof prepareArgs; | ||
constructor(_httpClient: HttpClientInterface, _baseUrlProvider: (arg?: BaseUrlParamType) => string, _apiErrorFactory: ApiErrorConstructor, _authenticationProvider: AuthenticatorInterface<AuthParams>, _httpMethod: HttpMethod, _xmlSerializer: XmlSerializerInterface, _path?: string | undefined); | ||
constructor(_httpClient: HttpClientInterface, _baseUrlProvider: (arg?: BaseUrlParamType) => string, _apiErrorFactory: ApiErrorConstructor, _authenticationProvider: AuthenticatorInterface<AuthParams>, _httpMethod: HttpMethod, _xmlSerializer: XmlSerializerInterface, _retryConfig: RetryConfiguration, _path?: string | undefined); | ||
authenticate(params: AuthParams): void; | ||
@@ -135,6 +137,7 @@ deprecated(methodName: string, message?: string): void; | ||
private _addAuthentication; | ||
private _addRetryInterceptor; | ||
} | ||
export declare function createRequestBuilderFactory<BaseUrlParamType, AuthParams>(httpClient: HttpClientInterface, baseUrlProvider: (arg?: BaseUrlParamType) => string, apiErrorFactory: ApiErrorConstructor, authenticationProvider: AuthenticatorInterface<AuthParams>, xmlSerializer: XmlSerializerInterface): RequestBuilderFactory<BaseUrlParamType, AuthParams>; | ||
export declare function createRequestBuilderFactory<BaseUrlParamType, AuthParams>(httpClient: HttpClientInterface, baseUrlProvider: (arg?: BaseUrlParamType) => string, apiErrorFactory: ApiErrorConstructor, authenticationProvider: AuthenticatorInterface<AuthParams>, xmlSerializer: XmlSerializerInterface, retryConfig: RetryConfiguration): RequestBuilderFactory<BaseUrlParamType, AuthParams>; | ||
export declare function convertToStream(content: string | Blob | NodeJS.ReadableStream): Blob | NodeJS.ReadableStream; | ||
export {}; | ||
//# sourceMappingURL=requestBuilder.d.ts.map |
@@ -21,2 +21,3 @@ "use strict"; | ||
var validate_1 = require("./validate"); | ||
var retryConfiguration_1 = require("./retryConfiguration"); | ||
var JSON = json_bigint_1.default(); | ||
@@ -28,3 +29,3 @@ function skipEncode(value) { | ||
var DefaultRequestBuilder = /** @class */ (function () { | ||
function DefaultRequestBuilder(_httpClient, _baseUrlProvider, _apiErrorFactory, _authenticationProvider, _httpMethod, _xmlSerializer, _path) { | ||
function DefaultRequestBuilder(_httpClient, _baseUrlProvider, _apiErrorFactory, _authenticationProvider, _httpMethod, _xmlSerializer, _retryConfig, _path) { | ||
this._httpClient = _httpClient; | ||
@@ -36,2 +37,3 @@ this._baseUrlProvider = _baseUrlProvider; | ||
this._xmlSerializer = _xmlSerializer; | ||
this._retryConfig = _retryConfig; | ||
this._path = _path; | ||
@@ -44,2 +46,3 @@ this._headers = {}; | ||
this._addAuthentication(); | ||
this._addRetryInterceptor(); | ||
this.prepareArgs = validate_1.prepareArgs.bind(this); | ||
@@ -380,8 +383,57 @@ } | ||
}; | ||
DefaultRequestBuilder.prototype._addRetryInterceptor = function () { | ||
var _this = this; | ||
this.intercept(function (request, options, next) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var context, allowedWaitTime, retryCount, waitTime, timeoutError, error_2; | ||
var _a; | ||
return tslib_1.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
allowedWaitTime = this._retryConfig.maximumRetryWaitTime; | ||
retryCount = 0; | ||
waitTime = 0; | ||
_b.label = 1; | ||
case 1: | ||
timeoutError = undefined; | ||
if (!(retryCount > 0)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, new Promise(function (res) { return setTimeout(res, waitTime * 1000); })]; | ||
case 2: | ||
_b.sent(); | ||
allowedWaitTime -= waitTime; | ||
_b.label = 3; | ||
case 3: | ||
_b.trys.push([3, 5, , 6]); | ||
return [4 /*yield*/, next(request, options)]; | ||
case 4: | ||
context = _b.sent(); | ||
return [3 /*break*/, 6]; | ||
case 5: | ||
error_2 = _b.sent(); | ||
timeoutError = error_2; | ||
return [3 /*break*/, 6]; | ||
case 6: | ||
waitTime = retryConfiguration_1.getRetryWaitTime(this._retryConfig, this._httpMethod, allowedWaitTime, retryCount, context === null || context === void 0 ? void 0 : context.response.statusCode, (_a = context === null || context === void 0 ? void 0 : context.response) === null || _a === void 0 ? void 0 : _a.headers, timeoutError); | ||
retryCount++; | ||
_b.label = 7; | ||
case 7: | ||
if (waitTime > 0) return [3 /*break*/, 1]; | ||
_b.label = 8; | ||
case 8: | ||
if (timeoutError) { | ||
throw timeoutError; | ||
} | ||
if (typeof (context === null || context === void 0 ? void 0 : context.response) === 'undefined') { | ||
throw new Error('Response is undefined.'); | ||
} | ||
return [2 /*return*/, { request: request, response: context.response }]; | ||
} | ||
}); | ||
}); }); | ||
}; | ||
return DefaultRequestBuilder; | ||
}()); | ||
exports.DefaultRequestBuilder = DefaultRequestBuilder; | ||
function createRequestBuilderFactory(httpClient, baseUrlProvider, apiErrorFactory, authenticationProvider, xmlSerializer) { | ||
function createRequestBuilderFactory(httpClient, baseUrlProvider, apiErrorFactory, authenticationProvider, xmlSerializer, retryConfig) { | ||
return function (httpMethod, path) { | ||
return new DefaultRequestBuilder(httpClient, baseUrlProvider, apiErrorFactory, authenticationProvider, httpMethod, xmlSerializer, path); | ||
return new DefaultRequestBuilder(httpClient, baseUrlProvider, apiErrorFactory, authenticationProvider, httpMethod, xmlSerializer, retryConfig, path); | ||
}; | ||
@@ -388,0 +440,0 @@ } |
@@ -16,2 +16,3 @@ /// <reference path="shim/index.d.ts" /> | ||
export * from './http/pathTemplate'; | ||
export { RetryConfiguration } from './http/retryConfiguration'; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@apimatic/core", | ||
"author": "Wajahat Iqbal", | ||
"version": "0.7.0", | ||
"version": "0.7.1", | ||
"license": "SEE LICENSE IN LICENSE.md", | ||
@@ -78,3 +78,4 @@ "sideEffects": false, | ||
"directory": "packages/core" | ||
} | ||
}, | ||
"gitHead": "7eb4aaeaa7e30190f6b3cbd2b9dabec5389b91a7" | ||
} |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ /** |
@@ -42,3 +42,10 @@ /** | ||
timeout = DEFAULT_TIMEOUT, | ||
}: { clientConfigOverrides?: AxiosRequestConfig; timeout?: number } = {}) { | ||
httpAgent, | ||
httpsAgent, | ||
}: { | ||
clientConfigOverrides?: AxiosRequestConfig; | ||
timeout?: number; | ||
httpAgent?: any; | ||
httpsAgent?: any; | ||
} = {}) { | ||
this._timeout = timeout; | ||
@@ -48,2 +55,3 @@ this._axiosInstance = axios.create({ | ||
...clientConfigOverrides, | ||
...{ httpAgent, httpsAgent }, | ||
}); | ||
@@ -184,1 +192,11 @@ } | ||
} | ||
/** Stable configurable http client options. */ | ||
export interface HttpClientOptions { | ||
/** Timeout in milliseconds. */ | ||
timeout: number; | ||
/** Custom http agent to be used when performing http requests. */ | ||
httpAgent?: any; | ||
/** Custom https agent to be used when performing https requests. */ | ||
httpsAgent?: any; | ||
} |
@@ -55,2 +55,3 @@ /** | ||
import { prepareArgs } from './validate'; | ||
import { RetryConfiguration, getRetryWaitTime } from './retryConfiguration'; | ||
@@ -208,2 +209,3 @@ export type RequestBuilderFactory<BaseUrlParamType, AuthParams> = ( | ||
protected _xmlSerializer: XmlSerializerInterface, | ||
protected _retryConfig: RetryConfiguration, | ||
protected _path?: string | ||
@@ -217,2 +219,3 @@ ) { | ||
this._addAuthentication(); | ||
this._addRetryInterceptor(); | ||
this.prepareArgs = prepareArgs.bind(this); | ||
@@ -542,2 +545,40 @@ } | ||
} | ||
private _addRetryInterceptor() { | ||
this.intercept(async (request, options, next) => { | ||
let context: HttpContext | undefined; | ||
let allowedWaitTime = this._retryConfig.maximumRetryWaitTime; | ||
let retryCount = 0; | ||
let waitTime = 0; | ||
let timeoutError: Error | undefined; | ||
do { | ||
timeoutError = undefined; | ||
if (retryCount > 0) { | ||
await new Promise((res) => setTimeout(res, waitTime * 1000)); | ||
allowedWaitTime -= waitTime; | ||
} | ||
try { | ||
context = await next(request, options); | ||
} catch (error) { | ||
timeoutError = error; | ||
} | ||
waitTime = getRetryWaitTime( | ||
this._retryConfig, | ||
this._httpMethod, | ||
allowedWaitTime, | ||
retryCount, | ||
context?.response.statusCode, | ||
context?.response?.headers, | ||
timeoutError | ||
); | ||
retryCount++; | ||
} while (waitTime > 0); | ||
if (timeoutError) { | ||
throw timeoutError; | ||
} | ||
if (typeof context?.response === 'undefined') { | ||
throw new Error('Response is undefined.'); | ||
} | ||
return { request, response: context.response }; | ||
}); | ||
} | ||
} | ||
@@ -550,3 +591,4 @@ | ||
authenticationProvider: AuthenticatorInterface<AuthParams>, | ||
xmlSerializer: XmlSerializerInterface | ||
xmlSerializer: XmlSerializerInterface, | ||
retryConfig: RetryConfiguration | ||
): RequestBuilderFactory<BaseUrlParamType, AuthParams> { | ||
@@ -561,2 +603,3 @@ return (httpMethod, path?) => { | ||
xmlSerializer, | ||
retryConfig, | ||
path | ||
@@ -563,0 +606,0 @@ ); |
@@ -18,1 +18,2 @@ // tslint:disable-next-line:no-reference | ||
export * from './http/pathTemplate'; | ||
export { RetryConfiguration } from './http/retryConfiguration'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
203221
82
5405