@apimatic/core
Advanced tools
Comparing version 0.8.0 to 0.9.0
import { detect } from 'detect-browser'; | ||
import warning from 'tiny-warning'; | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
/** | ||
* Validates the protocol and removes duplicate forward slashes | ||
@@ -31,23 +25,2 @@ * | ||
/** | ||
* Check whether value is an instance of Blob | ||
* | ||
* @remark | ||
* Reference: https://github.com/sindresorhus/is-blob/blob/master/index.js | ||
* | ||
* @param value Value to check | ||
* @returns True if the value is a Blob instance | ||
*/ | ||
function isBlob(value) { | ||
if (typeof Blob === 'undefined') { | ||
return false; | ||
} | ||
return value instanceof Blob || Object.prototype.toString.call(value) === '[object Blob]'; | ||
} // This is used by deprecated() to keep track of "hits". | ||
var deprecatedHits = {}; | ||
/** | ||
* Create warning for deprecated method usage. | ||
@@ -62,2 +35,3 @@ * | ||
function deprecated(methodName, notice) { | ||
@@ -70,8 +44,2 @@ var message = "Method " + methodName + " is deprecated."; | ||
if (deprecatedHits[message]) { | ||
return; | ||
} | ||
deprecatedHits[message] = true; | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -123,2 +91,2 @@ warning(false, message); | ||
export { deprecated, isBlob, sanitizeUrl, updateUserAgent }; | ||
export { deprecated, sanitizeUrl, updateUserAgent }; |
import { __extends } from 'tslib'; | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
/** | ||
* Thrown when the API call is aborted by the caller. | ||
@@ -15,16 +9,17 @@ * | ||
var AbortError = | ||
/*#__PURE__*/ | ||
/** @class */ | ||
/** @class */ | ||
function (_super) { | ||
(function (_super) { | ||
__extends(AbortError, _super); | ||
function AbortError() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
function AbortError(message) { | ||
var _newTarget = this.constructor; | ||
var _this = _super.call(this, message) || this; | ||
Object.setPrototypeOf(_this, _newTarget.prototype); | ||
return _this; | ||
} | ||
return AbortError; | ||
}(Error); | ||
export { AbortError }; | ||
})(Error); |
import { __extends } from 'tslib'; | ||
import JSONBig from '@apimatic/json-bigint'; | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
/** | ||
* Thrown when the HTTP status code is not okay. | ||
@@ -16,12 +10,13 @@ * | ||
var ApiError = | ||
/*#__PURE__*/ | ||
/** @class */ | ||
/** @class */ | ||
function (_super) { | ||
(function (_super) { | ||
__extends(ApiError, _super); | ||
function ApiError(context, message) { | ||
var _newTarget = this.constructor; | ||
var _this = _super.call(this, message) || this; | ||
Object.setPrototypeOf(_this, _newTarget.prototype); | ||
var request = context.request, | ||
@@ -53,4 +48,2 @@ response = context.response; | ||
return ApiError; | ||
}(Error); | ||
export { ApiError }; | ||
})(Error); |
@@ -6,7 +6,5 @@ import { __extends, __values } from 'tslib'; | ||
var ArgumentsValidationError = | ||
/*#__PURE__*/ | ||
/** @class */ | ||
/** @class */ | ||
function (_super) { | ||
(function (_super) { | ||
__extends(ArgumentsValidationError, _super); | ||
@@ -17,2 +15,4 @@ | ||
var _newTarget = this.constructor; | ||
var _this = this; | ||
@@ -61,2 +61,3 @@ | ||
_this = _super.call(this, message) || this; | ||
Object.setPrototypeOf(_this, _newTarget.prototype); | ||
_this.errors = errors; | ||
@@ -67,4 +68,2 @@ return _this; | ||
return ArgumentsValidationError; | ||
}(Error); | ||
export { ArgumentsValidationError }; | ||
})(Error); |
@@ -6,10 +6,10 @@ import { __extends } from 'tslib'; | ||
var ResponseValidationError = | ||
/*#__PURE__*/ | ||
/** @class */ | ||
/** @class */ | ||
function (_super) { | ||
(function (_super) { | ||
__extends(ResponseValidationError, _super); | ||
function ResponseValidationError(apiResponse, errors) { | ||
var _newTarget = this.constructor; | ||
var _this = this; | ||
@@ -28,2 +28,3 @@ | ||
_this = _super.call(this, message) || this; | ||
Object.setPrototypeOf(_this, _newTarget.prototype); | ||
_this.request = apiResponse.request; | ||
@@ -38,4 +39,2 @@ _this.statusCode = apiResponse.statusCode; | ||
return ResponseValidationError; | ||
}(Error); | ||
export { ResponseValidationError }; | ||
})(Error); |
@@ -1,678 +0,13 @@ | ||
import { __spreadArray, __read, __assign, __awaiter, __generator } from 'tslib'; | ||
import 'tslib'; | ||
import JSONBig from '@apimatic/json-bigint'; | ||
import { deprecated, sanitizeUrl } from '../apiHelper.js'; | ||
import { ArgumentsValidationError } from '../errors/argumentsValidationError.js'; | ||
import { ResponseValidationError } from '../errors/responseValidationError.js'; | ||
import { validateAndUnmapXml, validateAndMap, validateAndMapXml } from '@apimatic/schema'; | ||
import { JSON_CONTENT_TYPE, setHeader, mergeHeaders, TEXT_CONTENT_TYPE, XML_CONTENT_TYPE, ACCEPT_HEADER, CONTENT_TYPE_HEADER, setHeaderIfNotSet, CONTENT_LENGTH_HEADER } from './httpHeaders.js'; | ||
import { callHttpInterceptors } from './httpInterceptor.js'; | ||
import { SkipEncode, pathTemplate } from './pathTemplate.js'; | ||
import { urlEncodeObject, filterFileWrapperFromKeyValuePairs, formDataEncodeObject } from './queryString.js'; | ||
import { prepareArgs } from './validate.js'; | ||
import { shouldRetryRequest, RequestRetryOption, getRetryWaitTime } from './retryConfiguration.js'; | ||
import { convertToStream } from '@apimatic/convert-to-stream'; | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
var JSON = /*#__PURE__*/JSONBig(); | ||
function skipEncode(value) { | ||
return new SkipEncode(value); | ||
} | ||
var DefaultRequestBuilder = | ||
/*#__PURE__*/ | ||
/** @class */ | ||
function () { | ||
function DefaultRequestBuilder(_httpClient, _baseUrlProvider, _apiErrorFactory, _authenticationProvider, _httpMethod, _xmlSerializer, _retryConfig, _path) { | ||
this._httpClient = _httpClient; | ||
this._baseUrlProvider = _baseUrlProvider; | ||
this._apiErrorFactory = _apiErrorFactory; | ||
this._authenticationProvider = _authenticationProvider; | ||
this._httpMethod = _httpMethod; | ||
this._xmlSerializer = _xmlSerializer; | ||
this._retryConfig = _retryConfig; | ||
this._path = _path; | ||
this._headers = {}; | ||
this._query = []; | ||
this._interceptors = []; | ||
this._validateResponse = true; | ||
this._addResponseValidator(); | ||
this._addAuthentication(); | ||
this._addRetryInterceptor(); | ||
this._retryOption = RequestRetryOption.Default; | ||
this.prepareArgs = prepareArgs.bind(this); | ||
} | ||
DefaultRequestBuilder.prototype.authenticate = function (params) { | ||
this._authParams = params; | ||
}; | ||
DefaultRequestBuilder.prototype.requestRetryOption = function (option) { | ||
this._retryOption = option; | ||
}; | ||
DefaultRequestBuilder.prototype.deprecated = function (methodName, message) { | ||
deprecated(methodName, message); | ||
}; | ||
DefaultRequestBuilder.prototype.appendTemplatePath = function (strings) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
var pathSegment = pathTemplate.apply(void 0, __spreadArray([strings], __read(args))); | ||
this.appendPath(pathSegment); | ||
}; | ||
DefaultRequestBuilder.prototype.method = function (httpMethodName) { | ||
this._httpMethod = httpMethodName; | ||
}; | ||
DefaultRequestBuilder.prototype.baseUrl = function (arg) { | ||
this._baseUrlArg = arg; | ||
}; | ||
DefaultRequestBuilder.prototype.appendPath = function (path) { | ||
this._path = this._path ? mergePath(this._path, path) : path; | ||
}; | ||
DefaultRequestBuilder.prototype.acceptJson = function () { | ||
this._accept = JSON_CONTENT_TYPE; | ||
}; | ||
DefaultRequestBuilder.prototype.accept = function (acceptHeaderValue) { | ||
this._accept = acceptHeaderValue; | ||
}; | ||
DefaultRequestBuilder.prototype.contentType = function (contentTypeHeaderValue) { | ||
this._contentType = contentTypeHeaderValue; | ||
}; | ||
DefaultRequestBuilder.prototype.header = function (name, value) { | ||
if (value === undefined) { | ||
return; | ||
} | ||
setHeader(this._headers, name, value.toString()); | ||
}; | ||
DefaultRequestBuilder.prototype.headers = function (headersToMerge) { | ||
mergeHeaders(this._headers, headersToMerge); | ||
}; | ||
DefaultRequestBuilder.prototype.query = function (nameOrParameters, value, prefixFormat) { | ||
var _a; | ||
if (nameOrParameters === null || nameOrParameters === undefined) { | ||
return; | ||
} | ||
var queryString = typeof nameOrParameters === 'string' ? urlEncodeObject((_a = {}, _a[nameOrParameters] = value, _a), prefixFormat) : urlEncodeObject(nameOrParameters, prefixFormat); | ||
if (queryString) { | ||
this._query.push(queryString); | ||
} | ||
}; | ||
DefaultRequestBuilder.prototype.text = function (body) { | ||
this._body = body; | ||
this._setContentTypeIfNotSet(TEXT_CONTENT_TYPE); | ||
}; | ||
DefaultRequestBuilder.prototype.json = function (data) { | ||
this._body = JSON.stringify(data); | ||
this._setContentTypeIfNotSet(JSON_CONTENT_TYPE); | ||
}; | ||
DefaultRequestBuilder.prototype.xml = function (argName, data, rootName, schema) { | ||
var _a; | ||
var mappingResult = validateAndUnmapXml(data, schema); | ||
if (mappingResult.errors) { | ||
throw new ArgumentsValidationError((_a = {}, _a[argName] = mappingResult.errors, _a)); | ||
} | ||
this._body = this._xmlSerializer.xmlSerialize(rootName, mappingResult.result); | ||
this._setContentTypeIfNotSet(XML_CONTENT_TYPE); | ||
}; | ||
DefaultRequestBuilder.prototype.stream = function (file) { | ||
this._stream = file; | ||
}; | ||
DefaultRequestBuilder.prototype.form = function (parameters, prefixFormat) { | ||
this._form = filterFileWrapperFromKeyValuePairs(formDataEncodeObject(parameters, prefixFormat)); | ||
}; | ||
DefaultRequestBuilder.prototype.formData = function (parameters, prefixFormat) { | ||
this._formData = formDataEncodeObject(parameters, prefixFormat); | ||
}; | ||
DefaultRequestBuilder.prototype.toRequest = function () { | ||
var request = { | ||
method: this._httpMethod, | ||
url: mergePath(this._baseUrlProvider(this._baseUrlArg), this._path) | ||
}; | ||
if (this._query.length > 0) { | ||
var queryString = this._query.join('&'); | ||
request.url += (request.url.indexOf('?') === -1 ? '?' : '&') + queryString; | ||
} | ||
request.url = sanitizeUrl(request.url); // defensively copy headers | ||
var headers = __assign({}, this._headers); | ||
if (this._accept) { | ||
setHeader(headers, ACCEPT_HEADER, this._accept); | ||
} | ||
if (this._contentType) { | ||
setHeader(headers, CONTENT_TYPE_HEADER, this._contentType); | ||
} | ||
setHeader(headers, CONTENT_LENGTH_HEADER); | ||
request.headers = headers; | ||
if (this._body !== undefined) { | ||
request.body = { | ||
type: 'text', | ||
content: this._body | ||
}; | ||
} else if (this._form !== undefined) { | ||
request.body = { | ||
type: 'form', | ||
content: this._form | ||
}; | ||
} else if (this._formData !== undefined) { | ||
request.body = { | ||
type: 'form-data', | ||
content: this._formData | ||
}; | ||
} else if (this._stream !== undefined) { | ||
request.body = { | ||
type: 'stream', | ||
content: this._stream | ||
}; | ||
} | ||
return request; | ||
}; | ||
DefaultRequestBuilder.prototype.intercept = function (interceptor) { | ||
this._interceptors.push(interceptor); | ||
}; | ||
DefaultRequestBuilder.prototype.interceptRequest = function (interceptor) { | ||
this.intercept(function (req, opt, next) { | ||
return next(interceptor(req), opt); | ||
}); | ||
}; | ||
DefaultRequestBuilder.prototype.interceptResponse = function (interceptor) { | ||
var _this = this; | ||
this.intercept(function (req, opt, next) { | ||
return __awaiter(_this, void 0, void 0, function () { | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_a = interceptor; | ||
return [4 | ||
/*yield*/ | ||
, next(req, opt)]; | ||
case 1: | ||
return [2 | ||
/*return*/ | ||
, _a.apply(void 0, [_b.sent()])]; | ||
} | ||
}); | ||
}); | ||
}); | ||
}; | ||
DefaultRequestBuilder.prototype.defaultToError = function (apiErrorCtor) { | ||
this._apiErrorFactory = apiErrorCtor; | ||
}; | ||
DefaultRequestBuilder.prototype.validateResponse = function (validate) { | ||
this._validateResponse = validate; | ||
}; | ||
DefaultRequestBuilder.prototype.throwOn = function (statusCode, errorConstructor) { | ||
var args = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
args[_i - 2] = arguments[_i]; | ||
} | ||
this.interceptResponse(function (context) { | ||
var response = context.response; | ||
if (typeof statusCode === 'number' && response.statusCode === statusCode || typeof statusCode !== 'number' && response.statusCode >= statusCode[0] && response.statusCode <= statusCode[1]) { | ||
throw new (errorConstructor.bind.apply(errorConstructor, __spreadArray([void 0, context], __read(args))))(); | ||
} | ||
return context; | ||
}); | ||
}; | ||
DefaultRequestBuilder.prototype.call = function (requestOptions) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var pipeline, _a, request, response; | ||
var _this = this; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
pipeline = callHttpInterceptors(this._interceptors, // tslint:disable-next-line:no-shadowed-variable | ||
function (request, opt) { | ||
return __awaiter(_this, void 0, void 0, function () { | ||
var response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
return [4 | ||
/*yield*/ | ||
, this._httpClient(request, opt)]; | ||
case 1: | ||
response = _a.sent(); | ||
return [2 | ||
/*return*/ | ||
, { | ||
request: request, | ||
response: response | ||
}]; | ||
} | ||
}); | ||
}); | ||
}); | ||
return [4 | ||
/*yield*/ | ||
, pipeline(this.toRequest(), requestOptions)]; | ||
case 1: | ||
_a = _b.sent(), request = _a.request, response = _a.response; | ||
return [2 | ||
/*return*/ | ||
, __assign(__assign({}, response), { | ||
request: request, | ||
result: undefined | ||
})]; | ||
} | ||
}); | ||
}); | ||
}; | ||
DefaultRequestBuilder.prototype.callAsText = function (requestOptions) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
return [4 | ||
/*yield*/ | ||
, this.call(requestOptions)]; | ||
case 1: | ||
result = _a.sent(); | ||
if (typeof result.body !== 'string') { | ||
throw new Error('Could not parse body as string.'); // TODO: Replace with SDK error | ||
} | ||
return [2 | ||
/*return*/ | ||
, __assign(__assign({}, result), { | ||
result: result.body | ||
})]; | ||
} | ||
}); | ||
}); | ||
}; | ||
DefaultRequestBuilder.prototype.callAsOptionalText = function (requestOptions) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
return [4 | ||
/*yield*/ | ||
, this.call(requestOptions)]; | ||
case 1: | ||
result = _a.sent(); | ||
if (typeof result.body !== 'string') { | ||
return [2 | ||
/*return*/ | ||
, __assign(__assign({}, result), { | ||
result: undefined | ||
})]; | ||
} | ||
return [2 | ||
/*return*/ | ||
, __assign(__assign({}, result), { | ||
result: result.body | ||
})]; | ||
} | ||
}); | ||
}); | ||
}; | ||
DefaultRequestBuilder.prototype.callAsStream = function (requestOptions) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
this.interceptRequest(function (req) { | ||
return __assign(__assign({}, req), { | ||
responseType: 'stream' | ||
}); | ||
}); | ||
return [4 | ||
/*yield*/ | ||
, this.call(requestOptions)]; | ||
case 1: | ||
result = _a.sent(); | ||
return [2 | ||
/*return*/ | ||
, __assign(__assign({}, result), { | ||
result: convertToStream(result.body) | ||
})]; | ||
} | ||
}); | ||
}); | ||
}; | ||
DefaultRequestBuilder.prototype.callAsJson = function (schema, requestOptions) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result, parsed, mappingResult; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
this.interceptRequest(function (request) { | ||
var headers = __assign({}, request.headers); | ||
setHeaderIfNotSet(headers, ACCEPT_HEADER, JSON_CONTENT_TYPE); | ||
return __assign(__assign({}, request), { | ||
headers: headers | ||
}); | ||
}); | ||
return [4 | ||
/*yield*/ | ||
, this.call(requestOptions)]; | ||
case 1: | ||
result = _a.sent(); | ||
if (result.body === '') { | ||
throw new Error('Could not parse body as JSON. The response body is empty.'); | ||
} | ||
if (typeof result.body !== 'string') { | ||
throw new Error('Could not parse body as JSON. The response body is not a string.'); | ||
} | ||
try { | ||
parsed = JSON.parse(result.body); | ||
} catch (error) { | ||
throw new Error("Could not parse body as JSON.\n\n" + error.message); | ||
} | ||
mappingResult = validateAndMap(parsed, schema); | ||
if (mappingResult.errors) { | ||
throw new ResponseValidationError(result, mappingResult.errors); | ||
} | ||
return [2 | ||
/*return*/ | ||
, __assign(__assign({}, result), { | ||
result: mappingResult.result | ||
})]; | ||
} | ||
}); | ||
}); | ||
}; | ||
DefaultRequestBuilder.prototype.callAsXml = function (rootName, schema, requestOptions) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result, xmlObject, error_1, mappingResult; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
this.interceptRequest(function (request) { | ||
var headers = __assign({}, request.headers); | ||
setHeaderIfNotSet(headers, ACCEPT_HEADER, XML_CONTENT_TYPE); | ||
return __assign(__assign({}, request), { | ||
headers: headers | ||
}); | ||
}); | ||
return [4 | ||
/*yield*/ | ||
, this.call(requestOptions)]; | ||
case 1: | ||
result = _a.sent(); | ||
if (result.body === '') { | ||
throw new Error('Could not parse body as XML. The response body is empty.'); | ||
} | ||
if (typeof result.body !== 'string') { | ||
throw new Error('Could not parse body as XML. The response body is not a string.'); | ||
} | ||
_a.label = 2; | ||
case 2: | ||
_a.trys.push([2, 4,, 5]); | ||
return [4 | ||
/*yield*/ | ||
, this._xmlSerializer.xmlDeserialize(rootName, result.body)]; | ||
case 3: | ||
xmlObject = _a.sent(); | ||
return [3 | ||
/*break*/ | ||
, 5]; | ||
case 4: | ||
error_1 = _a.sent(); | ||
throw new Error("Could not parse body as XML.\n\n" + error_1.message); | ||
case 5: | ||
mappingResult = validateAndMapXml(xmlObject, schema); | ||
if (mappingResult.errors) { | ||
throw new ResponseValidationError(result, mappingResult.errors); | ||
} | ||
return [2 | ||
/*return*/ | ||
, __assign(__assign({}, result), { | ||
result: mappingResult.result | ||
})]; | ||
} | ||
}); | ||
}); | ||
}; | ||
DefaultRequestBuilder.prototype._setContentTypeIfNotSet = function (contentType) { | ||
if (!this._contentType) { | ||
setHeaderIfNotSet(this._headers, CONTENT_TYPE_HEADER, contentType); | ||
} | ||
}; | ||
DefaultRequestBuilder.prototype._addResponseValidator = function () { | ||
var _this = this; | ||
this.interceptResponse(function (context) { | ||
var response = context.response; | ||
if (_this._validateResponse && (response.statusCode < 200 || response.statusCode >= 300)) { | ||
throw new _this._apiErrorFactory(context, "Response status code was not ok: " + response.statusCode + "."); | ||
} | ||
return context; | ||
}); | ||
}; | ||
DefaultRequestBuilder.prototype._addAuthentication = function () { | ||
var _this = this; | ||
this.intercept(function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var handler = _this._authenticationProvider(_this._authParams); | ||
return handler.apply(void 0, __spreadArray([], __read(args))); | ||
}); | ||
}; | ||
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, shouldRetry, error_2; | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
allowedWaitTime = this._retryConfig.maximumRetryWaitTime; | ||
retryCount = 0; | ||
waitTime = 0; | ||
shouldRetry = shouldRetryRequest(this._retryConfig, this._retryOption, this._httpMethod); | ||
_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: | ||
if (shouldRetry) { | ||
waitTime = getRetryWaitTime(this._retryConfig, 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, retryConfig) { | ||
return function (httpMethod, path) { | ||
return new DefaultRequestBuilder(httpClient, baseUrlProvider, apiErrorFactory, authenticationProvider, httpMethod, xmlSerializer, retryConfig, path); | ||
}; | ||
} | ||
function mergePath(left, right) { | ||
if (!right || right === '') { | ||
return left; | ||
} | ||
if (left[left.length - 1] === '/' && right[0] === '/') { | ||
return left + right.substr(1); | ||
} else if (left[left.length - 1] === '/' || right[0] === '/') { | ||
return left + right; | ||
} else { | ||
return left + "/" + right; | ||
} | ||
} | ||
export { DefaultRequestBuilder, createRequestBuilderFactory, skipEncode }; | ||
import 'detect-browser'; | ||
import 'tiny-warning'; | ||
import '../errors/argumentsValidationError.js'; | ||
import '../errors/responseValidationError.js'; | ||
import '@apimatic/schema'; | ||
import '@apimatic/http-headers'; | ||
import 'lodash.flatmap'; | ||
import '@apimatic/http-query'; | ||
import './retryConfiguration.js'; | ||
import '@apimatic/convert-to-stream'; | ||
JSONBig(); |
@@ -1,2 +0,2 @@ | ||
import { getHeader } from './httpHeaders.js'; | ||
import '@apimatic/http-headers'; | ||
/** | ||
@@ -13,68 +13,3 @@ * An enum to override retries for any endpoint. | ||
})(RequestRetryOption || (RequestRetryOption = {})); | ||
/** | ||
* Returns wait time for the request | ||
* @param retryConfig Configuration for retry | ||
* @param method HttpMethod of the request | ||
* @param allowedWaitTime Remaining allowed wait time | ||
* @param retryCount Retry attempt number | ||
* @param httpCode Status code received | ||
* @param headers Response headers | ||
* @param timeoutError Error from the server | ||
* @returns Wait time before the retry | ||
*/ | ||
function getRetryWaitTime(retryConfig, allowedWaitTime, retryCount, httpCode, headers, timeoutError) { | ||
var retryWaitTime = 0.0; | ||
var retry = false; | ||
var retryAfter = 0; | ||
if (retryCount < retryConfig.maxNumberOfRetries) { | ||
if (timeoutError) { | ||
retry = retryConfig.retryOnTimeout; | ||
} else if (typeof headers !== 'undefined' && typeof httpCode !== 'undefined') { | ||
retryAfter = getRetryAfterSeconds(getHeader(headers, 'retry-after')); | ||
retry = retryAfter > 0 || retryConfig.httpStatusCodesToRetry.includes(httpCode); | ||
} | ||
if (retry) { | ||
var noise = +(Math.random() / 100).toFixed(3); | ||
var waitTime = retryConfig.retryInterval * Math.pow(retryConfig.backoffFactor, retryCount) + noise; | ||
waitTime = Math.max(waitTime, retryAfter); | ||
if (waitTime <= allowedWaitTime) { | ||
retryWaitTime = waitTime; | ||
} | ||
} | ||
} | ||
return retryWaitTime; | ||
} | ||
function getRetryAfterSeconds(retryAfter) { | ||
if (retryAfter == null) { | ||
return 0; | ||
} | ||
if (isNaN(+retryAfter)) { | ||
var timeDifference = (new Date(retryAfter).getTime() - Date.now()) / 1000; | ||
return isNaN(timeDifference) ? 0 : timeDifference; | ||
} | ||
return +retryAfter; | ||
} | ||
function shouldRetryRequest(retryConfig, retryOption, httpMethod) { | ||
switch (retryOption) { | ||
case RequestRetryOption.Default: | ||
return retryConfig.httpMethodsToRetry.includes(httpMethod); | ||
case RequestRetryOption.Enable: | ||
return true; | ||
case RequestRetryOption.Disable: | ||
return false; | ||
} | ||
} | ||
export { RequestRetryOption, getRetryWaitTime, shouldRetryRequest }; | ||
export { RequestRetryOption }; |
@@ -1,13 +0,13 @@ | ||
export { deprecated, isBlob, sanitizeUrl, updateUserAgent } from './apiHelper.js'; | ||
export { FileWrapper, cloneFileWrapper, isFileWrapper } from './fileWrapper.js'; | ||
export { AbortError } from './errors/abortError.js'; | ||
export { ArgumentsValidationError } from './errors/argumentsValidationError.js'; | ||
export { ResponseValidationError } from './errors/responseValidationError.js'; | ||
export { ApiError } from './errors/apiError.js'; | ||
export { DEFAULT_AXIOS_CONFIG_OVERRIDES, DEFAULT_TIMEOUT, HttpClient } from './http/httpClient.js'; | ||
export { ACCEPT_HEADER, AUTHORIZATION_HEADER, CONTENT_LENGTH_HEADER, CONTENT_TYPE_HEADER, FORM_URLENCODED_CONTENT_TYPE, JSON_CONTENT_TYPE, TEXT_CONTENT_TYPE, XML_CONTENT_TYPE, assertHeaders, getHeader, isValidHeaderName, lookupCaseInsensitive, mergeHeaders, setHeader, setHeaderIfNotSet } from './http/httpHeaders.js'; | ||
export { callHttpInterceptors, passThroughInterceptor } from './http/httpInterceptor.js'; | ||
export { DefaultRequestBuilder, createRequestBuilderFactory, skipEncode } from './http/requestBuilder.js'; | ||
export { SkipEncode, pathTemplate } from './http/pathTemplate.js'; | ||
export { deprecated, sanitizeUrl, updateUserAgent } from './apiHelper.js'; | ||
export * from '@apimatic/core-interfaces'; | ||
export { AbortError, ApiError, ArgumentsValidationError, DefaultRequestBuilder, ResponseValidationError, SkipEncode, callHttpInterceptors, createRequestBuilderFactory, pathTemplate, skipEncode } from '@apimatic/core-interfaces'; | ||
export * from '@apimatic/file-wrapper'; | ||
import './errors/abortError.js'; | ||
import './errors/argumentsValidationError.js'; | ||
import './errors/responseValidationError.js'; | ||
import './errors/apiError.js'; | ||
export * from '@apimatic/http-headers'; | ||
import './http/requestBuilder.js'; | ||
import 'lodash.flatmap'; | ||
export { RequestRetryOption } from './http/retryConfiguration.js'; | ||
export { commaPrefix, indexedPrefix, pipePrefix, plainPrefix, tabPrefix, unindexedPrefix } from './http/queryString.js'; | ||
export { commaPrefix, indexedPrefix, pipePrefix, plainPrefix, tabPrefix, unindexedPrefix } from '@apimatic/http-query'; |
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
/** | ||
* Validates the protocol and removes duplicate forward slashes | ||
@@ -14,12 +9,2 @@ * | ||
/** | ||
* Check whether value is an instance of Blob | ||
* | ||
* @remark | ||
* Reference: https://github.com/sindresorhus/is-blob/blob/master/index.js | ||
* | ||
* @param value Value to check | ||
* @returns True if the value is a Blob instance | ||
*/ | ||
export declare function isBlob(value: unknown): value is Blob; | ||
/** | ||
* Create warning for deprecated method usage. | ||
@@ -26,0 +11,0 @@ * |
"use strict"; | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.updateUserAgent = exports.deprecated = exports.isBlob = exports.sanitizeUrl = void 0; | ||
exports.updateUserAgent = exports.deprecated = exports.sanitizeUrl = void 0; | ||
var tslib_1 = require("tslib"); | ||
@@ -32,21 +27,2 @@ var detect_browser_1 = require("detect-browser"); | ||
/** | ||
* Check whether value is an instance of Blob | ||
* | ||
* @remark | ||
* Reference: https://github.com/sindresorhus/is-blob/blob/master/index.js | ||
* | ||
* @param value Value to check | ||
* @returns True if the value is a Blob instance | ||
*/ | ||
function isBlob(value) { | ||
if (typeof Blob === 'undefined') { | ||
return false; | ||
} | ||
return (value instanceof Blob || | ||
Object.prototype.toString.call(value) === '[object Blob]'); | ||
} | ||
exports.isBlob = isBlob; | ||
// This is used by deprecated() to keep track of "hits". | ||
var deprecatedHits = {}; | ||
/** | ||
* Create warning for deprecated method usage. | ||
@@ -65,6 +41,2 @@ * | ||
} | ||
if (deprecatedHits[message]) { | ||
return; | ||
} | ||
deprecatedHits[message] = true; | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -71,0 +43,0 @@ tiny_warning_1.default(false, message); |
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
/** | ||
* Thrown when the API call is aborted by the caller. | ||
@@ -13,3 +8,4 @@ * | ||
export declare class AbortError extends Error { | ||
constructor(message?: string); | ||
} | ||
//# sourceMappingURL=abortError.d.ts.map |
"use strict"; | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -18,4 +13,7 @@ exports.AbortError = void 0; | ||
tslib_1.__extends(AbortError, _super); | ||
function AbortError() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
function AbortError(message) { | ||
var _newTarget = this.constructor; | ||
var _this = _super.call(this, message) || this; | ||
Object.setPrototypeOf(_this, _newTarget.prototype); | ||
return _this; | ||
} | ||
@@ -22,0 +20,0 @@ return AbortError; |
@@ -1,10 +0,3 @@ | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
/// <reference types="node" /> | ||
import { HttpContext } from '../http/httpContext'; | ||
import { HttpRequest } from '../http/httpRequest'; | ||
import { ApiResponse } from '../apiResponse'; | ||
import { ApiResponse, HttpContext, HttpRequest } from '@apimatic/core-interfaces'; | ||
/** | ||
@@ -11,0 +4,0 @@ * Thrown when the HTTP status code is not okay. |
"use strict"; | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -20,3 +15,5 @@ exports.ApiError = void 0; | ||
function ApiError(context, message) { | ||
var _newTarget = this.constructor; | ||
var _this = _super.call(this, message) || this; | ||
Object.setPrototypeOf(_this, _newTarget.prototype); | ||
var request = context.request, response = context.response; | ||
@@ -23,0 +20,0 @@ _this.request = request; |
@@ -12,2 +12,3 @@ "use strict"; | ||
var e_1, _a; | ||
var _newTarget = this.constructor; | ||
var _this = this; | ||
@@ -50,2 +51,3 @@ var errorKeys = Object.keys(errors); | ||
_this = _super.call(this, message) || this; | ||
Object.setPrototypeOf(_this, _newTarget.prototype); | ||
_this.errors = errors; | ||
@@ -52,0 +54,0 @@ return _this; |
/// <reference types="node" /> | ||
import { HttpRequest } from '../http/httpRequest'; | ||
import { ApiResponse } from '../apiResponse'; | ||
import { ApiResponse, HttpRequest } from '../coreInterfaces'; | ||
import { SchemaValidationError } from '../schema'; | ||
@@ -5,0 +4,0 @@ /** |
@@ -11,2 +11,3 @@ "use strict"; | ||
function ResponseValidationError(apiResponse, errors) { | ||
var _newTarget = this.constructor; | ||
var _this = this; | ||
@@ -23,2 +24,3 @@ var message = 'The response did not match the response schema.'; | ||
_this = _super.call(this, message) || this; | ||
Object.setPrototypeOf(_this, _newTarget.prototype); | ||
_this.request = apiResponse.request; | ||
@@ -25,0 +27,0 @@ _this.statusCode = apiResponse.statusCode; |
@@ -1,32 +0,2 @@ | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
/** | ||
* Wraps file with mime-type and filename to be sent as part of an HTTP request. | ||
*/ | ||
export declare class FileWrapper { | ||
file: Blob | import('stream').Readable; | ||
options?: FileWrapperOptions | undefined; | ||
constructor(file: Blob | import('stream').Readable, options?: FileWrapperOptions | undefined); | ||
} | ||
/** File upload options such as filename and mime-type */ | ||
interface FileWrapperOptions { | ||
/** Mime-type to be sent with the file */ | ||
contentType?: string; | ||
/** Name of the file to be used in the upload data */ | ||
filename?: string; | ||
/** Headers to be used in the multipart request */ | ||
headers?: Record<string, string>; | ||
} | ||
/** Returns true if value is a FileWrapper */ | ||
export declare function isFileWrapper(value: unknown): value is FileWrapper; | ||
/** | ||
* Returns a deep clone of the FileWrapper instance | ||
* | ||
* @param fileWrapper FileWrapper instance to copy | ||
*/ | ||
export declare function cloneFileWrapper(fileWrapper: FileWrapper): FileWrapper; | ||
export {}; | ||
export * from '@apimatic/file-wrapper'; | ||
//# sourceMappingURL=fileWrapper.d.ts.map |
"use strict"; | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.cloneFileWrapper = exports.isFileWrapper = exports.FileWrapper = void 0; | ||
var tslib_1 = require("tslib"); | ||
/** | ||
* Wraps file with mime-type and filename to be sent as part of an HTTP request. | ||
*/ | ||
var FileWrapper = /** @class */ (function () { | ||
function FileWrapper(file, options) { | ||
this.file = file; | ||
this.options = options; | ||
this.file = file; | ||
} | ||
return FileWrapper; | ||
}()); | ||
exports.FileWrapper = FileWrapper; | ||
/** Returns true if value is a FileWrapper */ | ||
function isFileWrapper(value) { | ||
return value instanceof FileWrapper; | ||
} | ||
exports.isFileWrapper = isFileWrapper; | ||
/** | ||
* Returns a deep clone of the FileWrapper instance | ||
* | ||
* @param fileWrapper FileWrapper instance to copy | ||
*/ | ||
function cloneFileWrapper(fileWrapper) { | ||
var options; | ||
if (fileWrapper.options) { | ||
options = cloneFileWrapperOptions(fileWrapper.options); | ||
} | ||
return new FileWrapper(fileWrapper.file, options); | ||
} | ||
exports.cloneFileWrapper = cloneFileWrapper; | ||
function cloneFileWrapperOptions(fileWrapperOptions) { | ||
var clone = tslib_1.__assign({}, fileWrapperOptions); | ||
if (fileWrapperOptions.headers) { | ||
clone.headers = tslib_1.__assign({}, fileWrapperOptions.headers); | ||
} | ||
return clone; | ||
} | ||
tslib_1.__exportStar(require("@apimatic/file-wrapper"), exports); |
@@ -1,73 +0,2 @@ | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
/** | ||
* Set a header in the headers map. | ||
* | ||
* This method performs case-insensitive handling of header names. | ||
* | ||
* @param headers Map of headers | ||
* @param name Header name | ||
* @param value Header value | ||
*/ | ||
export declare function setHeader(headers: Record<string, string>, name: string, value?: string): void; | ||
/** | ||
* Set a header in the headers map if it is not already set. | ||
* | ||
* This method performs case-insensitive handling of header names. | ||
* | ||
* @param headers Map of headers | ||
* @param name Header name | ||
* @param value Header value | ||
*/ | ||
export declare function setHeaderIfNotSet(headers: Record<string, string>, name: string, value?: string): void; | ||
/** | ||
* Get header from a map of headers. | ||
* | ||
* This method performs case-insensitive handling of header names. | ||
* | ||
* @param headers Map of headers | ||
* @param name Header name | ||
*/ | ||
export declare function getHeader(headers: Record<string, string>, name: string): string | null; | ||
/** | ||
* Looks up and returns the matching property name from the object. | ||
* | ||
* This method returns the matching property name in the object which might or might | ||
* not have the same case as the prop argument. | ||
* | ||
* @param obj Object with string property names | ||
* @param prop Property to lookup | ||
*/ | ||
export declare function lookupCaseInsensitive(obj: Record<string, unknown>, prop: string): string | null; | ||
/** | ||
* Merge headers | ||
* | ||
* Header names are compared using case-insensitive comparison. This method | ||
* preserves the original header name. If the headersToMerge overrides an existing | ||
* header, then the new header name (with its casing) is used. | ||
* | ||
* @param headers Headers to merge into | ||
* @param headersToMerge Headers to set | ||
*/ | ||
export declare function mergeHeaders(headers: Record<string, string>, headersToMerge: Record<string, string>): void; | ||
/** | ||
* Assert headers object is valid | ||
*/ | ||
export declare function assertHeaders(headers: unknown): asserts headers is Record<string, string>; | ||
/** | ||
* Return true if header name is valid | ||
* @param headerName Header name | ||
*/ | ||
export declare function isValidHeaderName(headerName: string): boolean; | ||
export declare const CONTENT_TYPE_HEADER = "content-type"; | ||
export declare const ACCEPT_HEADER = "accept"; | ||
export declare const CONTENT_LENGTH_HEADER = "content-length"; | ||
export declare const AUTHORIZATION_HEADER = "authorization"; | ||
export declare const FORM_URLENCODED_CONTENT_TYPE = "application/x-www-form-urlencoded"; | ||
export declare const JSON_CONTENT_TYPE = "application/json"; | ||
export declare const TEXT_CONTENT_TYPE = "text/plain; charset=utf-8"; | ||
export declare const XML_CONTENT_TYPE = "application/xml"; | ||
export * from '@apimatic/http-headers'; | ||
//# sourceMappingURL=httpHeaders.d.ts.map |
"use strict"; | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.XML_CONTENT_TYPE = exports.TEXT_CONTENT_TYPE = exports.JSON_CONTENT_TYPE = exports.FORM_URLENCODED_CONTENT_TYPE = exports.AUTHORIZATION_HEADER = exports.CONTENT_LENGTH_HEADER = exports.ACCEPT_HEADER = exports.CONTENT_TYPE_HEADER = exports.isValidHeaderName = exports.assertHeaders = exports.mergeHeaders = exports.lookupCaseInsensitive = exports.getHeader = exports.setHeaderIfNotSet = exports.setHeader = void 0; | ||
var tslib_1 = require("tslib"); | ||
/** | ||
* Set a header in the headers map. | ||
* | ||
* This method performs case-insensitive handling of header names. | ||
* | ||
* @param headers Map of headers | ||
* @param name Header name | ||
* @param value Header value | ||
*/ | ||
function setHeader(headers, name, value) { | ||
var realHeaderName = lookupCaseInsensitive(headers, name); | ||
setHeaderInternal(headers, realHeaderName, name, value); | ||
} | ||
exports.setHeader = setHeader; | ||
function setHeaderInternal(headers, realHeaderName, name, value) { | ||
if (realHeaderName) { | ||
delete headers[realHeaderName]; | ||
} | ||
if (value) { | ||
headers[name] = value; | ||
} | ||
} | ||
/** | ||
* Set a header in the headers map if it is not already set. | ||
* | ||
* This method performs case-insensitive handling of header names. | ||
* | ||
* @param headers Map of headers | ||
* @param name Header name | ||
* @param value Header value | ||
*/ | ||
function setHeaderIfNotSet(headers, name, value) { | ||
var realHeaderName = lookupCaseInsensitive(headers, name); | ||
if (!realHeaderName) { | ||
setHeaderInternal(headers, realHeaderName, name, value); | ||
} | ||
} | ||
exports.setHeaderIfNotSet = setHeaderIfNotSet; | ||
/** | ||
* Get header from a map of headers. | ||
* | ||
* This method performs case-insensitive handling of header names. | ||
* | ||
* @param headers Map of headers | ||
* @param name Header name | ||
*/ | ||
function getHeader(headers, name) { | ||
var prop = lookupCaseInsensitive(headers, name); | ||
if (prop) { | ||
return headers[prop]; | ||
} | ||
return null; | ||
} | ||
exports.getHeader = getHeader; | ||
/** | ||
* Looks up and returns the matching property name from the object. | ||
* | ||
* This method returns the matching property name in the object which might or might | ||
* not have the same case as the prop argument. | ||
* | ||
* @param obj Object with string property names | ||
* @param prop Property to lookup | ||
*/ | ||
function lookupCaseInsensitive(obj, prop) { | ||
prop = prop.toLowerCase(); | ||
for (var p in obj) { | ||
if (Object.prototype.hasOwnProperty.call(obj, p) && | ||
prop === p.toLowerCase()) { | ||
return p; | ||
} | ||
} | ||
return null; | ||
} | ||
exports.lookupCaseInsensitive = lookupCaseInsensitive; | ||
/** | ||
* Merge headers | ||
* | ||
* Header names are compared using case-insensitive comparison. This method | ||
* preserves the original header name. If the headersToMerge overrides an existing | ||
* header, then the new header name (with its casing) is used. | ||
* | ||
* @param headers Headers to merge into | ||
* @param headersToMerge Headers to set | ||
*/ | ||
function mergeHeaders(headers, headersToMerge) { | ||
var e_1, _a, e_2, _b; | ||
var headerKeys = {}; | ||
try { | ||
// Create a map of lower-cased-header-name to original-header-names | ||
for (var _c = tslib_1.__values(Object.getOwnPropertyNames(headers)), _d = _c.next(); !_d.done; _d = _c.next()) { | ||
var headerName = _d.value; | ||
headerKeys[headerName.toLowerCase()] = headerName; | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_d && !_d.done && (_a = _c.return)) _a.call(_c); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
try { | ||
// Override headers with new values | ||
for (var _e = tslib_1.__values(Object.getOwnPropertyNames(headersToMerge)), _f = _e.next(); !_f.done; _f = _e.next()) { | ||
var headerName = _f.value; | ||
var lowerCasedName = headerName.toLowerCase(); | ||
if (headerKeys[lowerCasedName]) { | ||
delete headers[headerKeys[lowerCasedName]]; | ||
} | ||
headerKeys[lowerCasedName] = headerName; | ||
headers[headerName] = headersToMerge[headerName]; | ||
} | ||
} | ||
catch (e_2_1) { e_2 = { error: e_2_1 }; } | ||
finally { | ||
try { | ||
if (_f && !_f.done && (_b = _e.return)) _b.call(_e); | ||
} | ||
finally { if (e_2) throw e_2.error; } | ||
} | ||
} | ||
exports.mergeHeaders = mergeHeaders; | ||
/** | ||
* Assert headers object is valid | ||
*/ | ||
function assertHeaders(headers) { | ||
var e_3, _a; | ||
if (headers === null || typeof headers !== 'object') { | ||
throw new TypeError('Headers must be an object.'); | ||
} | ||
try { | ||
for (var _b = tslib_1.__values(Object.getOwnPropertyNames(headers)), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var headerName = _c.value; | ||
if (!isValidHeaderName(headerName)) { | ||
throw new Error("\"" + headerName + "\" is not a valid header name."); | ||
} | ||
var headerValue = headers[headerName]; | ||
if (typeof headerValue !== 'string') { | ||
throw new TypeError("Header value must be string but " + typeof headerValue + " provided."); | ||
} | ||
} | ||
} | ||
catch (e_3_1) { e_3 = { error: e_3_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_3) throw e_3.error; } | ||
} | ||
} | ||
exports.assertHeaders = assertHeaders; | ||
/** | ||
* Return true if header name is valid | ||
* @param headerName Header name | ||
*/ | ||
function isValidHeaderName(headerName) { | ||
return /^[\w!#$%&'*+.^`|~-]+$/.test(headerName); | ||
} | ||
exports.isValidHeaderName = isValidHeaderName; | ||
exports.CONTENT_TYPE_HEADER = 'content-type'; | ||
exports.ACCEPT_HEADER = 'accept'; | ||
exports.CONTENT_LENGTH_HEADER = 'content-length'; | ||
exports.AUTHORIZATION_HEADER = 'authorization'; | ||
exports.FORM_URLENCODED_CONTENT_TYPE = 'application/x-www-form-urlencoded'; | ||
exports.JSON_CONTENT_TYPE = 'application/json'; | ||
exports.TEXT_CONTENT_TYPE = 'text/plain; charset=utf-8'; | ||
exports.XML_CONTENT_TYPE = 'application/xml'; | ||
tslib_1.__exportStar(require("@apimatic/http-headers"), exports); |
@@ -0,28 +1,3 @@ | ||
import { HttpInterceptorInterface, HttpCallExecutor } from '@apimatic/core-interfaces'; | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
import { HttpContext } from './httpContext'; | ||
import { HttpRequest } from './httpRequest'; | ||
/** | ||
* Interface for a method that executes an HTTP request and returns the HTTP context. | ||
* | ||
* The context contains the HTTP response and the HTTP request (which may or may not be the same | ||
* as the original HTTP request). | ||
*/ | ||
export declare type HttpCallExecutor<T> = (request: HttpRequest, requestOptions: T) => Promise<HttpContext>; | ||
/** | ||
* Interface representing an HTTP interceptor method. | ||
* | ||
* HTTP interceptors are used to extend the HTTP call pipeline with new behavior or | ||
* features. | ||
* | ||
* An HTTP interceptor receives an HTTP request. It can modify the | ||
* HTTP request and then pass it along to the next HTTP interceptor in the chain which | ||
* then returns an HTTP response. It then returns this HTTP response, after optionally | ||
* modifying it. | ||
*/ | ||
export declare type HttpInterceptorInterface<T> = (request: HttpRequest, requestOptions: T, next: HttpCallExecutor<T>) => Promise<HttpContext>; | ||
/** | ||
* Calls HTTP interceptor chain | ||
@@ -34,4 +9,2 @@ * | ||
export declare function callHttpInterceptors<T>(interceptors: Array<HttpInterceptorInterface<T>>, client: HttpCallExecutor<T>): HttpCallExecutor<T>; | ||
/** Pass-through HTTP interceptor. */ | ||
export declare function passThroughInterceptor<T>(request: HttpRequest, requestOptions: T, next: HttpCallExecutor<T>): Promise<HttpContext>; | ||
//# sourceMappingURL=httpInterceptor.d.ts.map |
"use strict"; | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.passThroughInterceptor = exports.callHttpInterceptors = void 0; | ||
exports.callHttpInterceptors = void 0; | ||
/** | ||
@@ -28,6 +23,1 @@ * Calls HTTP interceptor chain | ||
exports.callHttpInterceptors = callHttpInterceptors; | ||
/** Pass-through HTTP interceptor. */ | ||
function passThroughInterceptor(request, requestOptions, next) { | ||
return next(request, requestOptions); | ||
} | ||
exports.passThroughInterceptor = passThroughInterceptor; |
@@ -1,6 +0,1 @@ | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
/** Marker for skipping URL-encoding when used with Path templating */ | ||
@@ -7,0 +2,0 @@ export declare class SkipEncode<T extends PathTemplatePrimitiveTypes> { |
"use strict"; | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -8,0 +3,0 @@ exports.pathTemplate = exports.SkipEncode = void 0; |
@@ -1,81 +0,2 @@ | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
import { FileWrapper } from '../fileWrapper'; | ||
/** | ||
* Type for Key-value pair for form-urlencoded serialization | ||
*/ | ||
export interface FormKeyValuePair { | ||
key: string; | ||
value: string | FileWrapper; | ||
} | ||
/** | ||
* Type for list of key-value pairs for form-urlencoded serialization | ||
*/ | ||
export declare type FormKeyValuePairList = FormKeyValuePair[]; | ||
/** | ||
* Type for formatting function used to create key for nested arrays | ||
*/ | ||
export declare type ArrayPrefixFunction = (key: string, value: any[], result: FormKeyValuePairList) => void; | ||
export declare function objectEncoding(key: string, iter: number, value: any, prefixFormat: ArrayPrefixFunction): FormKeyValuePairList; | ||
export declare function objectArrayEncoding(key: string, value: any[], prefixFormat: ArrayPrefixFunction, result: FormKeyValuePairList): void; | ||
/** | ||
* Array prefix format: item[1]=1&item[2]=2 | ||
*/ | ||
export declare const indexedPrefix: ArrayPrefixFunction; | ||
/** | ||
* Array prefix format: item[]=1&item[]=2 | ||
*/ | ||
export declare const unindexedPrefix: ArrayPrefixFunction; | ||
/** | ||
* Array prefix format: item=1&item=2 | ||
*/ | ||
export declare const plainPrefix: ArrayPrefixFunction; | ||
/** | ||
* Array prefix format: item=1\t2 | ||
*/ | ||
export declare const tabPrefix: ArrayPrefixFunction; | ||
/** | ||
* Array prefix format: item=1,2 | ||
*/ | ||
export declare const commaPrefix: ArrayPrefixFunction; | ||
/** | ||
* Array prefix format: item=1|2 | ||
*/ | ||
export declare const pipePrefix: ArrayPrefixFunction; | ||
/** | ||
* Converts an object to a list of key-value pairs for form-urlencoded serialization. | ||
* | ||
* @param obj The object to serialize | ||
* @param prefixFormat Formatting function to create key for nested arrays | ||
* @return Result of serialization | ||
*/ | ||
export declare function formDataEncodeObject(obj: Record<string, unknown>, prefixFormat?: ArrayPrefixFunction): FormKeyValuePairList; | ||
/** | ||
* Return a new list with all key-value pairs, which have a FileWrapper as value, removed | ||
* | ||
* @param params List of key-value pairs | ||
*/ | ||
export declare function filterFileWrapperFromKeyValuePairs(params: FormKeyValuePairList): Array<{ | ||
key: string; | ||
value: string; | ||
}>; | ||
/** | ||
* Serializes an object for a form-urlencoded request. | ||
* | ||
* Nested and complex types in values will be flattened using {@link formDataEncodeObject() function} method. | ||
* | ||
* @param obj The object to be serialized | ||
* @return The result of serialization | ||
*/ | ||
export declare function urlEncodeObject(obj: Record<string, unknown>, prefixFormat?: ArrayPrefixFunction): string; | ||
/** | ||
* Serializes a list of key-value pairs for a form-urlencoded request. | ||
* | ||
* @param params List of key-value pairs to serialize | ||
* @return The result of serialization | ||
*/ | ||
export declare function urlEncodeKeyValuePairs(params: FormKeyValuePairList | undefined): string; | ||
export * from '@apimatic/http-query'; | ||
//# sourceMappingURL=queryString.d.ts.map |
"use strict"; | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.urlEncodeKeyValuePairs = exports.urlEncodeObject = exports.filterFileWrapperFromKeyValuePairs = exports.formDataEncodeObject = exports.pipePrefix = exports.commaPrefix = exports.tabPrefix = exports.plainPrefix = exports.unindexedPrefix = exports.indexedPrefix = exports.objectArrayEncoding = exports.objectEncoding = void 0; | ||
var tslib_1 = require("tslib"); | ||
var fileWrapper_1 = require("../fileWrapper"); | ||
function objectEncoding(key, iter, value, prefixFormat) { | ||
var _a; | ||
return formDataEncodeObject((_a = {}, _a[key + "[" + iter + "]"] = value, _a), prefixFormat); | ||
} | ||
exports.objectEncoding = objectEncoding; | ||
function objectArrayEncoding(key, value, prefixFormat, result) { | ||
for (var iter = 0; iter < value.length; iter += 1) { | ||
result.push.apply(result, tslib_1.__spreadArray([], tslib_1.__read(objectEncoding(key, iter, value[iter], prefixFormat)))); | ||
} | ||
} | ||
exports.objectArrayEncoding = objectArrayEncoding; | ||
/** | ||
* Array prefix format: item[1]=1&item[2]=2 | ||
*/ | ||
var indexedPrefix = function (key, value, result) { | ||
for (var iter = 0; iter < value.length; iter += 1) { | ||
result.push.apply(result, tslib_1.__spreadArray([], tslib_1.__read(objectEncoding(key, iter, value[iter], exports.indexedPrefix)))); | ||
} | ||
}; | ||
exports.indexedPrefix = indexedPrefix; | ||
/** | ||
* Array prefix format: item[]=1&item[]=2 | ||
*/ | ||
var unindexedPrefix = function (key, value, result) { | ||
var e_1, _a, _b; | ||
if (value.some(function (val) { return typeof val === 'object'; })) { | ||
objectArrayEncoding(key, value, exports.unindexedPrefix, result); | ||
} | ||
else { | ||
try { | ||
for (var value_1 = tslib_1.__values(value), value_1_1 = value_1.next(); !value_1_1.done; value_1_1 = value_1.next()) { | ||
var val = value_1_1.value; | ||
result.push.apply(result, tslib_1.__spreadArray([], tslib_1.__read(formDataEncodeObject((_b = {}, _b[key + '[]'] = val, _b), exports.unindexedPrefix)))); | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (value_1_1 && !value_1_1.done && (_a = value_1.return)) _a.call(value_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
} | ||
}; | ||
exports.unindexedPrefix = unindexedPrefix; | ||
/** | ||
* Array prefix format: item=1&item=2 | ||
*/ | ||
var plainPrefix = function (key, value, result) { | ||
var e_2, _a, _b; | ||
if (value.some(function (val) { return typeof val === 'object'; })) { | ||
objectArrayEncoding(key, value, exports.plainPrefix, result); | ||
} | ||
else { | ||
try { | ||
for (var value_2 = tslib_1.__values(value), value_2_1 = value_2.next(); !value_2_1.done; value_2_1 = value_2.next()) { | ||
var val = value_2_1.value; | ||
result.push.apply(result, tslib_1.__spreadArray([], tslib_1.__read(formDataEncodeObject((_b = {}, _b[key] = val, _b), exports.plainPrefix)))); | ||
} | ||
} | ||
catch (e_2_1) { e_2 = { error: e_2_1 }; } | ||
finally { | ||
try { | ||
if (value_2_1 && !value_2_1.done && (_a = value_2.return)) _a.call(value_2); | ||
} | ||
finally { if (e_2) throw e_2.error; } | ||
} | ||
} | ||
}; | ||
exports.plainPrefix = plainPrefix; | ||
/** | ||
* Array prefix format: item=1\t2 | ||
*/ | ||
var tabPrefix = function (key, value, result) { | ||
if (value.some(function (val) { return typeof val === 'object'; })) { | ||
objectArrayEncoding(key, value, exports.tabPrefix, result); | ||
} | ||
else { | ||
var prefixedArray = value.map(function (element) { return element.toString(); }).join('\t'); | ||
result.push.apply(result, [{ key: key, value: prefixedArray }]); | ||
} | ||
}; | ||
exports.tabPrefix = tabPrefix; | ||
/** | ||
* Array prefix format: item=1,2 | ||
*/ | ||
var commaPrefix = function (key, value, result) { | ||
if (value.some(function (val) { return typeof val === 'object'; })) { | ||
objectArrayEncoding(key, value, exports.commaPrefix, result); | ||
} | ||
else { | ||
var prefixedArray = value.map(function (element) { return element.toString(); }).join(','); | ||
result.push.apply(result, [{ key: key, value: prefixedArray }]); | ||
} | ||
}; | ||
exports.commaPrefix = commaPrefix; | ||
/** | ||
* Array prefix format: item=1|2 | ||
*/ | ||
var pipePrefix = function (key, value, result) { | ||
if (value.some(function (val) { return typeof val === 'object'; })) { | ||
objectArrayEncoding(key, value, exports.pipePrefix, result); | ||
} | ||
else { | ||
var prefixedArray = value.map(function (element) { return element.toString(); }).join('|'); | ||
result.push.apply(result, [{ key: key, value: prefixedArray }]); | ||
} | ||
}; | ||
exports.pipePrefix = pipePrefix; | ||
/** | ||
* Converts an object to a list of key-value pairs for form-urlencoded serialization. | ||
* | ||
* @param obj The object to serialize | ||
* @param prefixFormat Formatting function to create key for nested arrays | ||
* @return Result of serialization | ||
*/ | ||
function formDataEncodeObject(obj, prefixFormat) { | ||
var e_3, _a, _b; | ||
if (prefixFormat === void 0) { prefixFormat = exports.indexedPrefix; } | ||
var result = []; | ||
try { | ||
for (var _c = tslib_1.__values(Object.keys(obj)), _d = _c.next(); !_d.done; _d = _c.next()) { | ||
var key = _d.value; | ||
var value = obj[key]; | ||
if (value === null || value === undefined) { | ||
continue; | ||
} | ||
else if (typeof value === 'string' || | ||
typeof value === 'number' || | ||
typeof value === 'boolean' || | ||
typeof value === 'bigint') { | ||
result.push({ key: key, value: value.toString() }); | ||
} | ||
else if (fileWrapper_1.isFileWrapper(value)) { | ||
result.push({ key: key, value: fileWrapper_1.cloneFileWrapper(value) }); | ||
} | ||
else if (Array.isArray(value)) { | ||
prefixFormat(key, value, result); | ||
} | ||
else if (typeof value === 'object') { | ||
for (var objectKey in value) { | ||
if (Object.prototype.hasOwnProperty.call(value, objectKey)) { | ||
var element = value[objectKey]; | ||
result.push.apply(result, tslib_1.__spreadArray([], tslib_1.__read(formDataEncodeObject((_b = {}, | ||
_b[key + "[" + objectKey + "]"] = element, | ||
_b), prefixFormat)))); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
catch (e_3_1) { e_3 = { error: e_3_1 }; } | ||
finally { | ||
try { | ||
if (_d && !_d.done && (_a = _c.return)) _a.call(_c); | ||
} | ||
finally { if (e_3) throw e_3.error; } | ||
} | ||
return result; | ||
} | ||
exports.formDataEncodeObject = formDataEncodeObject; | ||
/** | ||
* Return a new list with all key-value pairs, which have a FileWrapper as value, removed | ||
* | ||
* @param params List of key-value pairs | ||
*/ | ||
function filterFileWrapperFromKeyValuePairs(params) { | ||
return params.filter(function (p) { return !fileWrapper_1.isFileWrapper(p.value); }); | ||
} | ||
exports.filterFileWrapperFromKeyValuePairs = filterFileWrapperFromKeyValuePairs; | ||
/** | ||
* Serializes an object for a form-urlencoded request. | ||
* | ||
* Nested and complex types in values will be flattened using {@link formDataEncodeObject() function} method. | ||
* | ||
* @param obj The object to be serialized | ||
* @return The result of serialization | ||
*/ | ||
function urlEncodeObject(obj, prefixFormat) { | ||
var params = formDataEncodeObject(obj, prefixFormat); | ||
return urlEncodeKeyValuePairs(params); | ||
} | ||
exports.urlEncodeObject = urlEncodeObject; | ||
/** | ||
* Serializes a list of key-value pairs for a form-urlencoded request. | ||
* | ||
* @param params List of key-value pairs to serialize | ||
* @return The result of serialization | ||
*/ | ||
function urlEncodeKeyValuePairs(params) { | ||
var encode = encodeURIComponent; | ||
return (params || []) | ||
.map(function (p) { return encode(p.key) + "=" + encode(p.value.toString()); }) | ||
.join('&'); | ||
} | ||
exports.urlEncodeKeyValuePairs = urlEncodeKeyValuePairs; | ||
tslib_1.__exportStar(require("@apimatic/http-query"), exports); |
@@ -1,41 +0,15 @@ | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
/// <reference types="node" /> | ||
import { FileWrapper } from '../fileWrapper'; | ||
import { ApiResponse } from '../apiResponse'; | ||
import { FileWrapper } from '@apimatic/file-wrapper'; | ||
import { ApiResponse, AuthenticatorInterface, HttpContext, HttpMethod, HttpRequest, HttpRequestMultipartFormBody, HttpRequestUrlEncodedFormBody, HttpResponse, HttpInterceptorInterface, RequestOptions, RetryConfiguration } from '../coreInterfaces'; | ||
import { Schema } from '../schema'; | ||
import { HttpContext } from './httpContext'; | ||
import { HttpInterceptorInterface } from './httpInterceptor'; | ||
import { HttpMethod, HttpRequest, HttpRequestMultipartFormBody, HttpRequestUrlEncodedFormBody } from './httpRequest'; | ||
import { HttpResponse } from './httpResponse'; | ||
import { PathTemplatePrimitiveTypes, PathTemplateTypes, SkipEncode } from './pathTemplate'; | ||
import { ArrayPrefixFunction } from './queryString'; | ||
import { prepareArgs } from './validate'; | ||
import { RetryConfiguration, RequestRetryOption } from './retryConfiguration'; | ||
import { RequestRetryOption } from './retryConfiguration'; | ||
import { XmlSerializerInterface } from '../xml/xmlSerializer'; | ||
export declare type RequestBuilderFactory<BaseUrlParamType, AuthParams> = (httpMethod: HttpMethod, path?: string) => RequestBuilder<BaseUrlParamType, AuthParams>; | ||
declare type QueryValue = string | string[] | number | number[] | bigint | Array<bigint> | boolean | boolean[] | null | undefined; | ||
export declare function skipEncode<T extends PathTemplatePrimitiveTypes>(value: T): SkipEncode<T>; | ||
/** Optional API call options such as the Abort Signal. */ | ||
export interface RequestOptions { | ||
/** | ||
* Allows cancelling the API call using an Abort Signal. | ||
* | ||
* This must be set to an instance compatible with the | ||
* [WHATWG AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). The | ||
* AbortSignal comes built-in in modern browsers and can be polyfilled for older browser versions | ||
* and Node.js using the | ||
* [abort-controller](https://github.com/mysticatea/abort-controller) package. | ||
*/ | ||
abortSignal?: AbortSignal; | ||
} | ||
export interface XmlSerializerInterface { | ||
xmlSerialize: (rootName: string, value: unknown) => string; | ||
xmlDeserialize: (rootName: string, xmlString: string) => Promise<any>; | ||
} | ||
export declare type HttpClientInterface = (request: HttpRequest, requestOptions?: RequestOptions) => Promise<HttpResponse>; | ||
export declare type ApiErrorConstructor = new (response: HttpContext, message: string) => any; | ||
export declare type AuthenticatorInterface<AuthParams> = (authParams?: AuthParams) => HttpInterceptorInterface<RequestOptions | undefined>; | ||
export interface RequestBuilder<BaseUrlParamType, AuthParams> { | ||
@@ -140,4 +114,4 @@ deprecated(methodName: string, message?: string): void; | ||
} | ||
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 createRequestBuilderFactory<BaseUrlParamType, AuthParams>(httpClient: HttpClientInterface, baseUrlProvider: (arg?: BaseUrlParamType) => string, apiErrorFactory: ApiErrorConstructor, authenticationProvider: AuthenticatorInterface<AuthParams>, retryConfig: RetryConfiguration, xmlSerializer?: XmlSerializerInterface): RequestBuilderFactory<BaseUrlParamType, AuthParams>; | ||
export {}; | ||
//# sourceMappingURL=requestBuilder.d.ts.map |
"use strict"; | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -22,2 +17,3 @@ exports.createRequestBuilderFactory = exports.DefaultRequestBuilder = exports.skipEncode = void 0; | ||
var convert_to_stream_1 = require("@apimatic/convert-to-stream"); | ||
var xmlSerializer_1 = require("../xml/xmlSerializer"); | ||
var JSON = json_bigint_1.default(); | ||
@@ -388,5 +384,5 @@ function skipEncode(value) { | ||
var context, allowedWaitTime, retryCount, waitTime, timeoutError, shouldRetry, error_2; | ||
var _a; | ||
return tslib_1.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
var _a, _b; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
@@ -396,4 +392,4 @@ allowedWaitTime = this._retryConfig.maximumRetryWaitTime; | ||
waitTime = 0; | ||
shouldRetry = retryConfiguration_1.shouldRetryRequest(this._retryConfig, this._retryOption, this._httpMethod); | ||
_b.label = 1; | ||
shouldRetry = retryConfiguration_1.shouldRetryRequest(this._retryOption, this._retryConfig, this._httpMethod); | ||
_c.label = 1; | ||
case 1: | ||
@@ -404,13 +400,13 @@ timeoutError = undefined; | ||
case 2: | ||
_b.sent(); | ||
_c.sent(); | ||
allowedWaitTime -= waitTime; | ||
_b.label = 3; | ||
_c.label = 3; | ||
case 3: | ||
_b.trys.push([3, 5, , 6]); | ||
_c.trys.push([3, 5, , 6]); | ||
return [4 /*yield*/, next(request, options)]; | ||
case 4: | ||
context = _b.sent(); | ||
context = _c.sent(); | ||
return [3 /*break*/, 6]; | ||
case 5: | ||
error_2 = _b.sent(); | ||
error_2 = _c.sent(); | ||
timeoutError = error_2; | ||
@@ -420,9 +416,9 @@ return [3 /*break*/, 6]; | ||
if (shouldRetry) { | ||
waitTime = retryConfiguration_1.getRetryWaitTime(this._retryConfig, 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); | ||
waitTime = retryConfiguration_1.getRetryWaitTime(this._retryConfig, allowedWaitTime, retryCount, (_a = context === null || context === void 0 ? void 0 : context.response) === null || _a === void 0 ? void 0 : _a.statusCode, (_b = context === null || context === void 0 ? void 0 : context.response) === null || _b === void 0 ? void 0 : _b.headers, timeoutError); | ||
retryCount++; | ||
} | ||
_b.label = 7; | ||
_c.label = 7; | ||
case 7: | ||
if (waitTime > 0) return [3 /*break*/, 1]; | ||
_b.label = 8; | ||
_c.label = 8; | ||
case 8: | ||
@@ -443,3 +439,4 @@ if (timeoutError) { | ||
exports.DefaultRequestBuilder = DefaultRequestBuilder; | ||
function createRequestBuilderFactory(httpClient, baseUrlProvider, apiErrorFactory, authenticationProvider, xmlSerializer, retryConfig) { | ||
function createRequestBuilderFactory(httpClient, baseUrlProvider, apiErrorFactory, authenticationProvider, retryConfig, xmlSerializer) { | ||
if (xmlSerializer === void 0) { xmlSerializer = new xmlSerializer_1.XmlSerialization(); } | ||
return function (httpMethod, path) { | ||
@@ -446,0 +443,0 @@ return new DefaultRequestBuilder(httpClient, baseUrlProvider, apiErrorFactory, authenticationProvider, httpMethod, xmlSerializer, retryConfig, path); |
@@ -1,25 +0,3 @@ | ||
import { HttpMethod } from './httpRequest'; | ||
import { HttpMethod, RetryConfiguration } from '../coreInterfaces'; | ||
/** | ||
* An interface for all configuration parameters needed for retrying in case of transient failures. | ||
*/ | ||
export interface RetryConfiguration { | ||
/** Maximum number of retries. */ | ||
maxNumberOfRetries: number; | ||
/** Whether to retry on request timeout. */ | ||
retryOnTimeout: boolean; | ||
/** | ||
* Interval before next retry. | ||
* Used in calculation of wait time for next request in case of failure. | ||
*/ | ||
retryInterval: number; | ||
/** Overall wait time for the requests getting retried. */ | ||
maximumRetryWaitTime: number; | ||
/** Used in calculation of wait time for next request in case of failure. */ | ||
backoffFactor: number; | ||
/** Http status codes to retry against. */ | ||
httpStatusCodesToRetry: number[]; | ||
/** Http methods to retry against. */ | ||
httpMethodsToRetry: HttpMethod[]; | ||
} | ||
/** | ||
* An enum to override retries for any endpoint. | ||
@@ -44,3 +22,3 @@ */ | ||
export declare function getRetryWaitTime(retryConfig: RetryConfiguration, allowedWaitTime: number, retryCount: number, httpCode?: number, headers?: Record<string, string>, timeoutError?: Error): number; | ||
export declare function shouldRetryRequest(retryConfig: RetryConfiguration, retryOption: RequestRetryOption, httpMethod: HttpMethod): boolean; | ||
export declare function shouldRetryRequest(retryOption: RequestRetryOption, retryConfig?: RetryConfiguration, httpMethod?: HttpMethod): boolean; | ||
//# sourceMappingURL=retryConfiguration.d.ts.map |
@@ -63,6 +63,8 @@ "use strict"; | ||
} | ||
function shouldRetryRequest(retryConfig, retryOption, httpMethod) { | ||
function shouldRetryRequest(retryOption, retryConfig, httpMethod) { | ||
switch (retryOption) { | ||
case RequestRetryOption.Default: | ||
return retryConfig.httpMethodsToRetry.includes(httpMethod); | ||
return retryConfig !== undefined && httpMethod !== undefined | ||
? retryConfig.httpMethodsToRetry.includes(httpMethod) | ||
: false; | ||
case RequestRetryOption.Enable: | ||
@@ -69,0 +71,0 @@ return true; |
@@ -1,6 +0,1 @@ | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
import { Schema, SchemaMappedType, SchemaType } from '../schema'; | ||
@@ -7,0 +2,0 @@ /** |
"use strict"; | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -8,0 +3,0 @@ exports.prepareArgs = void 0; |
/// <reference path="shim/index.d.ts" /> | ||
export * from './apiHelper'; | ||
export * from './apiResponse'; | ||
export * from './coreInterfaces'; | ||
export * from './fileWrapper'; | ||
@@ -9,11 +9,9 @@ export * from './errors/abortError'; | ||
export * from './errors/apiError'; | ||
export * from './http/httpClient'; | ||
export * from './http/httpContext'; | ||
export * from './http/httpHeaders'; | ||
export * from './http/httpInterceptor'; | ||
export * from './http/httpRequest'; | ||
export * from './http/requestBuilder'; | ||
export * from './http/pathTemplate'; | ||
export { RetryConfiguration, RequestRetryOption, } from './http/retryConfiguration'; | ||
export { RequestRetryOption } from './http/retryConfiguration'; | ||
export { indexedPrefix, unindexedPrefix, plainPrefix, commaPrefix, tabPrefix, pipePrefix, } from './http/queryString'; | ||
export { XmlSerializerInterface } from './xml/xmlSerializer'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -8,3 +8,3 @@ "use strict"; | ||
tslib_1.__exportStar(require("./apiHelper"), exports); | ||
tslib_1.__exportStar(require("./apiResponse"), exports); | ||
tslib_1.__exportStar(require("./coreInterfaces"), exports); | ||
tslib_1.__exportStar(require("./fileWrapper"), exports); | ||
@@ -15,7 +15,4 @@ tslib_1.__exportStar(require("./errors/abortError"), exports); | ||
tslib_1.__exportStar(require("./errors/apiError"), exports); | ||
tslib_1.__exportStar(require("./http/httpClient"), exports); | ||
tslib_1.__exportStar(require("./http/httpContext"), exports); | ||
tslib_1.__exportStar(require("./http/httpHeaders"), exports); | ||
tslib_1.__exportStar(require("./http/httpInterceptor"), exports); | ||
tslib_1.__exportStar(require("./http/httpRequest"), exports); | ||
tslib_1.__exportStar(require("./http/requestBuilder"), exports); | ||
@@ -22,0 +19,0 @@ tslib_1.__exportStar(require("./http/pathTemplate"), exports); |
@@ -1,7 +0,2 @@ | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
export * from '@apimatic/schema'; | ||
//# sourceMappingURL=schema.d.ts.map |
"use strict"; | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("@apimatic/schema"), exports); |
@@ -1,10 +0,3 @@ | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
interface Blob { | ||
} | ||
interface AbortSignal { | ||
} | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@apimatic/core", | ||
"author": "Wajahat Iqbal", | ||
"version": "0.8.0", | ||
"author": "APIMatic Ltd.", | ||
"version": "0.9.0", | ||
"license": "SEE LICENSE IN LICENSE.md", | ||
@@ -51,3 +51,3 @@ "sideEffects": false, | ||
"jest": "^26.4.2", | ||
"jsdom": "^14.0.0", | ||
"jsdom": "^16.5.0", | ||
"jsdom-global": "^3.0.2", | ||
@@ -62,4 +62,8 @@ "lerna-alias": "3.0.3-0", | ||
"dependencies": { | ||
"@apimatic/convert-to-stream": "0.0.2", | ||
"@apimatic/convert-to-stream": "~0.0.2", | ||
"@apimatic/core-interfaces": "^0.1.0", | ||
"@apimatic/file-wrapper": "^0.1.0", | ||
"@apimatic/http-headers": "^0.1.0", | ||
"@apimatic/json-bigint": "^1.2.0", | ||
"@apimatic/http-query": "^0.1.0", | ||
"@apimatic/schema": "^0.6.0", | ||
@@ -66,0 +70,0 @@ "axios": "^0.21.1", |
@@ -1,7 +0,1 @@ | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
import { detect } from 'detect-browser'; | ||
@@ -31,25 +25,2 @@ import warning from 'tiny-warning'; | ||
/** | ||
* Check whether value is an instance of Blob | ||
* | ||
* @remark | ||
* Reference: https://github.com/sindresorhus/is-blob/blob/master/index.js | ||
* | ||
* @param value Value to check | ||
* @returns True if the value is a Blob instance | ||
*/ | ||
export function isBlob(value: unknown): value is Blob { | ||
if (typeof Blob === 'undefined') { | ||
return false; | ||
} | ||
return ( | ||
value instanceof Blob || | ||
Object.prototype.toString.call(value) === '[object Blob]' | ||
); | ||
} | ||
// This is used by deprecated() to keep track of "hits". | ||
const deprecatedHits: Record<string, boolean> = {}; | ||
/** | ||
* Create warning for deprecated method usage. | ||
@@ -68,6 +39,3 @@ * | ||
} | ||
if (deprecatedHits[message]) { | ||
return; | ||
} | ||
deprecatedHits[message] = true; | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -74,0 +42,0 @@ warning(false, message); |
@@ -1,7 +0,1 @@ | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
/// <reference lib="dom" /> |
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
/** | ||
* Thrown when the API call is aborted by the caller. | ||
@@ -13,2 +7,7 @@ * | ||
*/ | ||
export class AbortError extends Error {} | ||
export class AbortError extends Error { | ||
constructor(message?: string) { | ||
super(message); | ||
Object.setPrototypeOf(this, new.target.prototype); | ||
} | ||
} |
@@ -1,11 +0,7 @@ | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
import JSONBig from '@apimatic/json-bigint'; | ||
import { HttpContext } from '../http/httpContext'; | ||
import { HttpRequest } from '../http/httpRequest'; | ||
import { ApiResponse } from '../apiResponse'; | ||
import { | ||
ApiResponse, | ||
HttpContext, | ||
HttpRequest, | ||
} from '@apimatic/core-interfaces'; | ||
@@ -29,2 +25,3 @@ /** | ||
super(message); | ||
Object.setPrototypeOf(this, new.target.prototype); | ||
@@ -31,0 +28,0 @@ const { request, response } = context; |
@@ -40,4 +40,5 @@ import { SchemaValidationError } from '../schema'; | ||
super(message); | ||
Object.setPrototypeOf(this, new.target.prototype); | ||
this.errors = errors; | ||
} | ||
} |
@@ -1,3 +0,2 @@ | ||
import { HttpRequest } from '../http/httpRequest'; | ||
import { ApiResponse } from '../apiResponse'; | ||
import { ApiResponse, HttpRequest } from '../coreInterfaces'; | ||
import { SchemaValidationError } from '../schema'; | ||
@@ -30,2 +29,3 @@ | ||
super(message); | ||
Object.setPrototypeOf(this, new.target.prototype); | ||
@@ -32,0 +32,0 @@ this.request = apiResponse.request; |
@@ -1,55 +0,1 @@ | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
/** | ||
* Wraps file with mime-type and filename to be sent as part of an HTTP request. | ||
*/ | ||
export class FileWrapper { | ||
constructor( | ||
public file: Blob | import('stream').Readable, | ||
public options?: FileWrapperOptions | ||
) { | ||
this.file = file; | ||
} | ||
} | ||
/** File upload options such as filename and mime-type */ | ||
interface FileWrapperOptions { | ||
/** Mime-type to be sent with the file */ | ||
contentType?: string; | ||
/** Name of the file to be used in the upload data */ | ||
filename?: string; | ||
/** Headers to be used in the multipart request */ | ||
headers?: Record<string, string>; | ||
} | ||
/** Returns true if value is a FileWrapper */ | ||
export function isFileWrapper(value: unknown): value is FileWrapper { | ||
return value instanceof FileWrapper; | ||
} | ||
/** | ||
* Returns a deep clone of the FileWrapper instance | ||
* | ||
* @param fileWrapper FileWrapper instance to copy | ||
*/ | ||
export function cloneFileWrapper(fileWrapper: FileWrapper): FileWrapper { | ||
let options: FileWrapperOptions | undefined; | ||
if (fileWrapper.options) { | ||
options = cloneFileWrapperOptions(fileWrapper.options); | ||
} | ||
return new FileWrapper(fileWrapper.file, options); | ||
} | ||
function cloneFileWrapperOptions( | ||
fileWrapperOptions: FileWrapperOptions | ||
): FileWrapperOptions { | ||
const clone = { ...fileWrapperOptions }; | ||
if (fileWrapperOptions.headers) { | ||
clone.headers = { ...fileWrapperOptions.headers }; | ||
} | ||
return clone; | ||
} | ||
export * from '@apimatic/file-wrapper'; |
@@ -1,173 +0,1 @@ | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
/** | ||
* Set a header in the headers map. | ||
* | ||
* This method performs case-insensitive handling of header names. | ||
* | ||
* @param headers Map of headers | ||
* @param name Header name | ||
* @param value Header value | ||
*/ | ||
export function setHeader( | ||
headers: Record<string, string>, | ||
name: string, | ||
value?: string | ||
): void { | ||
const realHeaderName = lookupCaseInsensitive(headers, name); | ||
setHeaderInternal(headers, realHeaderName, name, value); | ||
} | ||
function setHeaderInternal( | ||
headers: Record<string, string>, | ||
realHeaderName: string | null, | ||
name: string, | ||
value: string | undefined | ||
): void { | ||
if (realHeaderName) { | ||
delete headers[realHeaderName]; | ||
} | ||
if (value) { | ||
headers[name] = value; | ||
} | ||
} | ||
/** | ||
* Set a header in the headers map if it is not already set. | ||
* | ||
* This method performs case-insensitive handling of header names. | ||
* | ||
* @param headers Map of headers | ||
* @param name Header name | ||
* @param value Header value | ||
*/ | ||
export function setHeaderIfNotSet( | ||
headers: Record<string, string>, | ||
name: string, | ||
value?: string | ||
): void { | ||
const realHeaderName = lookupCaseInsensitive(headers, name); | ||
if (!realHeaderName) { | ||
setHeaderInternal(headers, realHeaderName, name, value); | ||
} | ||
} | ||
/** | ||
* Get header from a map of headers. | ||
* | ||
* This method performs case-insensitive handling of header names. | ||
* | ||
* @param headers Map of headers | ||
* @param name Header name | ||
*/ | ||
export function getHeader( | ||
headers: Record<string, string>, | ||
name: string | ||
): string | null { | ||
const prop = lookupCaseInsensitive(headers, name); | ||
if (prop) { | ||
return headers[prop]; | ||
} | ||
return null; | ||
} | ||
/** | ||
* Looks up and returns the matching property name from the object. | ||
* | ||
* This method returns the matching property name in the object which might or might | ||
* not have the same case as the prop argument. | ||
* | ||
* @param obj Object with string property names | ||
* @param prop Property to lookup | ||
*/ | ||
export function lookupCaseInsensitive( | ||
obj: Record<string, unknown>, | ||
prop: string | ||
): string | null { | ||
prop = prop.toLowerCase(); | ||
for (const p in obj) { | ||
if ( | ||
Object.prototype.hasOwnProperty.call(obj, p) && | ||
prop === p.toLowerCase() | ||
) { | ||
return p; | ||
} | ||
} | ||
return null; | ||
} | ||
/** | ||
* Merge headers | ||
* | ||
* Header names are compared using case-insensitive comparison. This method | ||
* preserves the original header name. If the headersToMerge overrides an existing | ||
* header, then the new header name (with its casing) is used. | ||
* | ||
* @param headers Headers to merge into | ||
* @param headersToMerge Headers to set | ||
*/ | ||
export function mergeHeaders( | ||
headers: Record<string, string>, | ||
headersToMerge: Record<string, string> | ||
): void { | ||
const headerKeys: Record<string, string> = {}; | ||
// Create a map of lower-cased-header-name to original-header-names | ||
for (const headerName of Object.getOwnPropertyNames(headers)) { | ||
headerKeys[headerName.toLowerCase()] = headerName; | ||
} | ||
// Override headers with new values | ||
for (const headerName of Object.getOwnPropertyNames(headersToMerge)) { | ||
const lowerCasedName = headerName.toLowerCase(); | ||
if (headerKeys[lowerCasedName]) { | ||
delete headers[headerKeys[lowerCasedName]]; | ||
} | ||
headerKeys[lowerCasedName] = headerName; | ||
headers[headerName] = headersToMerge[headerName]; | ||
} | ||
} | ||
/** | ||
* Assert headers object is valid | ||
*/ | ||
export function assertHeaders( | ||
headers: unknown | ||
): asserts headers is Record<string, string> { | ||
if (headers === null || typeof headers !== 'object') { | ||
throw new TypeError('Headers must be an object.'); | ||
} | ||
for (const headerName of Object.getOwnPropertyNames(headers)) { | ||
if (!isValidHeaderName(headerName)) { | ||
throw new Error(`"${headerName}" is not a valid header name.`); | ||
} | ||
const headerValue = (headers as Record<string, unknown>)[headerName]; | ||
if (typeof headerValue !== 'string') { | ||
throw new TypeError( | ||
`Header value must be string but ${typeof headerValue} provided.` | ||
); | ||
} | ||
} | ||
} | ||
/** | ||
* Return true if header name is valid | ||
* @param headerName Header name | ||
*/ | ||
export function isValidHeaderName(headerName: string): boolean { | ||
return /^[\w!#$%&'*+.^`|~-]+$/.test(headerName); | ||
} | ||
export const CONTENT_TYPE_HEADER = 'content-type'; | ||
export const ACCEPT_HEADER = 'accept'; | ||
export const CONTENT_LENGTH_HEADER = 'content-length'; | ||
export const AUTHORIZATION_HEADER = 'authorization'; | ||
export const FORM_URLENCODED_CONTENT_TYPE = 'application/x-www-form-urlencoded'; | ||
export const JSON_CONTENT_TYPE = 'application/json'; | ||
export const TEXT_CONTENT_TYPE = 'text/plain; charset=utf-8'; | ||
export const XML_CONTENT_TYPE = 'application/xml'; | ||
export * from '@apimatic/http-headers'; |
@@ -0,39 +1,6 @@ | ||
import { | ||
HttpInterceptorInterface, | ||
HttpCallExecutor, | ||
} from '@apimatic/core-interfaces'; | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
import { HttpContext } from './httpContext'; | ||
import { HttpRequest } from './httpRequest'; | ||
/** | ||
* Interface for a method that executes an HTTP request and returns the HTTP context. | ||
* | ||
* The context contains the HTTP response and the HTTP request (which may or may not be the same | ||
* as the original HTTP request). | ||
*/ | ||
export type HttpCallExecutor<T> = ( | ||
request: HttpRequest, | ||
requestOptions: T | ||
) => Promise<HttpContext>; | ||
/** | ||
* Interface representing an HTTP interceptor method. | ||
* | ||
* HTTP interceptors are used to extend the HTTP call pipeline with new behavior or | ||
* features. | ||
* | ||
* An HTTP interceptor receives an HTTP request. It can modify the | ||
* HTTP request and then pass it along to the next HTTP interceptor in the chain which | ||
* then returns an HTTP response. It then returns this HTTP response, after optionally | ||
* modifying it. | ||
*/ | ||
export type HttpInterceptorInterface<T> = ( | ||
request: HttpRequest, | ||
requestOptions: T, | ||
next: HttpCallExecutor<T> | ||
) => Promise<HttpContext>; | ||
/** | ||
* Calls HTTP interceptor chain | ||
@@ -56,10 +23,1 @@ * | ||
} | ||
/** Pass-through HTTP interceptor. */ | ||
export function passThroughInterceptor<T>( | ||
request: HttpRequest, | ||
requestOptions: T, | ||
next: HttpCallExecutor<T> | ||
): Promise<HttpContext> { | ||
return next(request, requestOptions); | ||
} |
@@ -1,7 +0,1 @@ | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
import flatMap from 'lodash.flatmap'; | ||
@@ -8,0 +2,0 @@ |
@@ -1,212 +0,1 @@ | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
import { FileWrapper, isFileWrapper, cloneFileWrapper } from '../fileWrapper'; | ||
/** | ||
* Type for Key-value pair for form-urlencoded serialization | ||
*/ | ||
export interface FormKeyValuePair { | ||
key: string; | ||
value: string | FileWrapper; | ||
} | ||
/** | ||
* Type for list of key-value pairs for form-urlencoded serialization | ||
*/ | ||
export type FormKeyValuePairList = FormKeyValuePair[]; | ||
/** | ||
* Type for formatting function used to create key for nested arrays | ||
*/ | ||
export type ArrayPrefixFunction = ( | ||
key: string, | ||
value: any[], | ||
result: FormKeyValuePairList | ||
) => void; | ||
export function objectEncoding( | ||
key: string, | ||
iter: number, | ||
value: any, | ||
prefixFormat: ArrayPrefixFunction | ||
): FormKeyValuePairList { | ||
return formDataEncodeObject({ [`${key}[${iter}]`]: value }, prefixFormat); | ||
} | ||
export function objectArrayEncoding( | ||
key: string, | ||
value: any[], | ||
prefixFormat: ArrayPrefixFunction, | ||
result: FormKeyValuePairList | ||
) { | ||
for (let iter = 0; iter < value.length; iter += 1) { | ||
result.push(...objectEncoding(key, iter, value[iter], prefixFormat)); | ||
} | ||
} | ||
/** | ||
* Array prefix format: item[1]=1&item[2]=2 | ||
*/ | ||
export const indexedPrefix: ArrayPrefixFunction = (key, value, result) => { | ||
for (let iter = 0; iter < value.length; iter += 1) { | ||
result.push(...objectEncoding(key, iter, value[iter], indexedPrefix)); | ||
} | ||
}; | ||
/** | ||
* Array prefix format: item[]=1&item[]=2 | ||
*/ | ||
export const unindexedPrefix: ArrayPrefixFunction = (key, value, result) => { | ||
if (value.some((val) => typeof val === 'object')) { | ||
objectArrayEncoding(key, value, unindexedPrefix, result); | ||
} else { | ||
for (const val of value) { | ||
result.push( | ||
...formDataEncodeObject({ [key + '[]']: val }, unindexedPrefix) | ||
); | ||
} | ||
} | ||
}; | ||
/** | ||
* Array prefix format: item=1&item=2 | ||
*/ | ||
export const plainPrefix: ArrayPrefixFunction = (key, value, result) => { | ||
if (value.some((val) => typeof val === 'object')) { | ||
objectArrayEncoding(key, value, plainPrefix, result); | ||
} else { | ||
for (const val of value) { | ||
result.push(...formDataEncodeObject({ [key]: val }, plainPrefix)); | ||
} | ||
} | ||
}; | ||
/** | ||
* Array prefix format: item=1\t2 | ||
*/ | ||
export const tabPrefix: ArrayPrefixFunction = (key, value, result) => { | ||
if (value.some((val) => typeof val === 'object')) { | ||
objectArrayEncoding(key, value, tabPrefix, result); | ||
} else { | ||
const prefixedArray = value.map((element) => element.toString()).join('\t'); | ||
result.push(...[{ key, value: prefixedArray }]); | ||
} | ||
}; | ||
/** | ||
* Array prefix format: item=1,2 | ||
*/ | ||
export const commaPrefix: ArrayPrefixFunction = (key, value, result) => { | ||
if (value.some((val) => typeof val === 'object')) { | ||
objectArrayEncoding(key, value, commaPrefix, result); | ||
} else { | ||
const prefixedArray = value.map((element) => element.toString()).join(','); | ||
result.push(...[{ key, value: prefixedArray }]); | ||
} | ||
}; | ||
/** | ||
* Array prefix format: item=1|2 | ||
*/ | ||
export const pipePrefix: ArrayPrefixFunction = (key, value, result) => { | ||
if (value.some((val) => typeof val === 'object')) { | ||
objectArrayEncoding(key, value, pipePrefix, result); | ||
} else { | ||
const prefixedArray = value.map((element) => element.toString()).join('|'); | ||
result.push(...[{ key, value: prefixedArray }]); | ||
} | ||
}; | ||
/** | ||
* Converts an object to a list of key-value pairs for form-urlencoded serialization. | ||
* | ||
* @param obj The object to serialize | ||
* @param prefixFormat Formatting function to create key for nested arrays | ||
* @return Result of serialization | ||
*/ | ||
export function formDataEncodeObject( | ||
obj: Record<string, unknown>, | ||
prefixFormat: ArrayPrefixFunction = indexedPrefix | ||
): FormKeyValuePairList { | ||
const result: FormKeyValuePairList = []; | ||
for (const key of Object.keys(obj)) { | ||
const value = obj[key]; | ||
if (value === null || value === undefined) { | ||
continue; | ||
} else if ( | ||
typeof value === 'string' || | ||
typeof value === 'number' || | ||
typeof value === 'boolean' || | ||
typeof value === 'bigint' | ||
) { | ||
result.push({ key, value: value.toString() }); | ||
} else if (isFileWrapper(value)) { | ||
result.push({ key, value: cloneFileWrapper(value) }); | ||
} else if (Array.isArray(value)) { | ||
prefixFormat(key, value, result); | ||
} else if (typeof value === 'object') { | ||
for (const objectKey in value) { | ||
if (Object.prototype.hasOwnProperty.call(value, objectKey)) { | ||
const element = value[objectKey as keyof typeof value]; | ||
result.push( | ||
...formDataEncodeObject( | ||
{ | ||
[`${key}[${objectKey}]`]: element, | ||
}, | ||
prefixFormat | ||
) | ||
); | ||
} | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
/** | ||
* Return a new list with all key-value pairs, which have a FileWrapper as value, removed | ||
* | ||
* @param params List of key-value pairs | ||
*/ | ||
export function filterFileWrapperFromKeyValuePairs( | ||
params: FormKeyValuePairList | ||
): Array<{ key: string; value: string }> { | ||
return params.filter((p) => !isFileWrapper(p.value)) as any; | ||
} | ||
/** | ||
* Serializes an object for a form-urlencoded request. | ||
* | ||
* Nested and complex types in values will be flattened using {@link formDataEncodeObject() function} method. | ||
* | ||
* @param obj The object to be serialized | ||
* @return The result of serialization | ||
*/ | ||
export function urlEncodeObject( | ||
obj: Record<string, unknown>, | ||
prefixFormat?: ArrayPrefixFunction | ||
): string { | ||
const params = formDataEncodeObject(obj, prefixFormat); | ||
return urlEncodeKeyValuePairs(params); | ||
} | ||
/** | ||
* Serializes a list of key-value pairs for a form-urlencoded request. | ||
* | ||
* @param params List of key-value pairs to serialize | ||
* @return The result of serialization | ||
*/ | ||
export function urlEncodeKeyValuePairs( | ||
params: FormKeyValuePairList | undefined | ||
): string { | ||
const encode = encodeURIComponent; | ||
return (params || []) | ||
.map((p) => `${encode(p.key)}=${encode(p.value.toString())}`) | ||
.join('&'); | ||
} | ||
export * from '@apimatic/http-query'; |
@@ -1,11 +0,17 @@ | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
import JSONBig from '@apimatic/json-bigint'; | ||
import { FileWrapper } from '../fileWrapper'; | ||
import { FileWrapper } from '@apimatic/file-wrapper'; | ||
import { deprecated, sanitizeUrl } from '../apiHelper'; | ||
import { ApiResponse } from '../apiResponse'; | ||
import { | ||
ApiResponse, | ||
AuthenticatorInterface, | ||
HttpContext, | ||
HttpMethod, | ||
HttpRequest, | ||
HttpRequestMultipartFormBody, | ||
HttpRequestUrlEncodedFormBody, | ||
HttpResponse, | ||
HttpInterceptorInterface, | ||
RequestOptions, | ||
RetryConfiguration, | ||
} from '../coreInterfaces'; | ||
import { ArgumentsValidationError } from '../errors/argumentsValidationError'; | ||
@@ -19,3 +25,2 @@ import { ResponseValidationError } from '../errors/responseValidationError'; | ||
} from '../schema'; | ||
import { HttpContext } from './httpContext'; | ||
import { | ||
@@ -32,14 +37,4 @@ ACCEPT_HEADER, | ||
} from './httpHeaders'; | ||
import { callHttpInterceptors } from './httpInterceptor'; | ||
import { | ||
callHttpInterceptors, | ||
HttpInterceptorInterface, | ||
} from './httpInterceptor'; | ||
import { | ||
HttpMethod, | ||
HttpRequest, | ||
HttpRequestMultipartFormBody, | ||
HttpRequestUrlEncodedFormBody, | ||
} from './httpRequest'; | ||
import { HttpResponse } from './httpResponse'; | ||
import { | ||
pathTemplate, | ||
@@ -58,3 +53,2 @@ PathTemplatePrimitiveTypes, | ||
import { | ||
RetryConfiguration, | ||
getRetryWaitTime, | ||
@@ -65,2 +59,3 @@ shouldRetryRequest, | ||
import { convertToStream } from '@apimatic/convert-to-stream'; | ||
import { XmlSerializerInterface, XmlSerialization } from '../xml/xmlSerializer'; | ||
@@ -92,21 +87,2 @@ export type RequestBuilderFactory<BaseUrlParamType, AuthParams> = ( | ||
/** Optional API call options such as the Abort Signal. */ | ||
export interface RequestOptions { | ||
/** | ||
* Allows cancelling the API call using an Abort Signal. | ||
* | ||
* This must be set to an instance compatible with the | ||
* [WHATWG AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal). The | ||
* AbortSignal comes built-in in modern browsers and can be polyfilled for older browser versions | ||
* and Node.js using the | ||
* [abort-controller](https://github.com/mysticatea/abort-controller) package. | ||
*/ | ||
abortSignal?: AbortSignal; | ||
} | ||
export interface XmlSerializerInterface { | ||
xmlSerialize: (rootName: string, value: unknown) => string; | ||
xmlDeserialize: (rootName: string, xmlString: string) => Promise<any>; | ||
} | ||
export type HttpClientInterface = ( | ||
@@ -122,6 +98,2 @@ request: HttpRequest, | ||
export type AuthenticatorInterface<AuthParams> = ( | ||
authParams?: AuthParams | ||
) => HttpInterceptorInterface<RequestOptions | undefined>; | ||
export interface RequestBuilder<BaseUrlParamType, AuthParams> { | ||
@@ -599,4 +571,4 @@ deprecated(methodName: string, message?: string): void; | ||
const shouldRetry = shouldRetryRequest( | ||
this._retryOption, | ||
this._retryConfig, | ||
this._retryOption, | ||
this._httpMethod | ||
@@ -620,3 +592,3 @@ ); | ||
retryCount, | ||
context?.response.statusCode, | ||
context?.response?.statusCode, | ||
context?.response?.headers, | ||
@@ -645,4 +617,4 @@ timeoutError | ||
authenticationProvider: AuthenticatorInterface<AuthParams>, | ||
xmlSerializer: XmlSerializerInterface, | ||
retryConfig: RetryConfiguration | ||
retryConfig: RetryConfiguration, | ||
xmlSerializer: XmlSerializerInterface = new XmlSerialization() | ||
): RequestBuilderFactory<BaseUrlParamType, AuthParams> { | ||
@@ -649,0 +621,0 @@ return (httpMethod, path?) => { |
import { getHeader } from './httpHeaders'; | ||
import { HttpMethod } from './httpRequest'; | ||
import { HttpMethod, RetryConfiguration } from '../coreInterfaces'; | ||
/** | ||
* An interface for all configuration parameters needed for retrying in case of transient failures. | ||
*/ | ||
export interface RetryConfiguration { | ||
/** Maximum number of retries. */ | ||
maxNumberOfRetries: number; | ||
/** Whether to retry on request timeout. */ | ||
retryOnTimeout: boolean; | ||
/** | ||
* Interval before next retry. | ||
* Used in calculation of wait time for next request in case of failure. | ||
*/ | ||
retryInterval: number; | ||
/** Overall wait time for the requests getting retried. */ | ||
maximumRetryWaitTime: number; | ||
/** Used in calculation of wait time for next request in case of failure. */ | ||
backoffFactor: number; | ||
/** Http status codes to retry against. */ | ||
httpStatusCodesToRetry: number[]; | ||
/** Http methods to retry against. */ | ||
httpMethodsToRetry: HttpMethod[]; | ||
} | ||
/** | ||
* An enum to override retries for any endpoint. | ||
@@ -97,9 +74,11 @@ */ | ||
export function shouldRetryRequest( | ||
retryConfig: RetryConfiguration, | ||
retryOption: RequestRetryOption, | ||
httpMethod: HttpMethod | ||
retryConfig?: RetryConfiguration, | ||
httpMethod?: HttpMethod | ||
): boolean { | ||
switch (retryOption) { | ||
case RequestRetryOption.Default: | ||
return retryConfig.httpMethodsToRetry.includes(httpMethod); | ||
return retryConfig !== undefined && httpMethod !== undefined | ||
? retryConfig.httpMethodsToRetry.includes(httpMethod) | ||
: false; | ||
case RequestRetryOption.Enable: | ||
@@ -106,0 +85,0 @@ return true; |
@@ -1,7 +0,1 @@ | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
import { | ||
@@ -8,0 +2,0 @@ Schema, |
@@ -5,3 +5,3 @@ // tslint:disable-next-line:no-reference | ||
export * from './apiHelper'; | ||
export * from './apiResponse'; | ||
export * from './coreInterfaces'; | ||
export * from './fileWrapper'; | ||
@@ -12,14 +12,8 @@ export * from './errors/abortError'; | ||
export * from './errors/apiError'; | ||
export * from './http/httpClient'; | ||
export * from './http/httpContext'; | ||
export * from './http/httpHeaders'; | ||
export * from './http/httpInterceptor'; | ||
export * from './http/httpRequest'; | ||
export * from './http/requestBuilder'; | ||
export * from './http/pathTemplate'; | ||
export { RequestRetryOption } from './http/retryConfiguration'; | ||
export { | ||
RetryConfiguration, | ||
RequestRetryOption, | ||
} from './http/retryConfiguration'; | ||
export { | ||
indexedPrefix, | ||
@@ -32,1 +26,2 @@ unindexedPrefix, | ||
} from './http/queryString'; | ||
export { XmlSerializerInterface } from './xml/xmlSerializer'; |
@@ -1,7 +0,1 @@ | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
export * from '@apimatic/schema'; |
@@ -1,10 +0,2 @@ | ||
/** | ||
* bandwidthLib | ||
* | ||
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ). | ||
*/ | ||
// tslint:disable-next-line:no-empty-interface | ||
interface Blob {} | ||
// tslint:disable-next-line:no-empty-interface | ||
interface AbortSignal {} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
106710
14
66
2550
1
+ Added@apimatic/http-query@^0.1.0
+ Added@apimatic/core-interfaces@0.1.0(transitive)
+ Added@apimatic/file-wrapper@0.1.0(transitive)
+ Added@apimatic/http-headers@0.1.0(transitive)
+ Added@apimatic/http-query@0.1.0(transitive)