@or-sdk/base
Advanced tools
Comparing version 0.29.2-beta.2355.0 to 0.29.2-beta.2356.0
@@ -54,3 +54,2 @@ "use strict"; | ||
exports.Base = void 0; | ||
var path_1 = require("path"); | ||
var axios_1 = __importDefault(require("axios")); | ||
@@ -286,7 +285,7 @@ var utils_1 = require("./utils"); | ||
conf = { | ||
url: this.getUrl(params), | ||
url: "".concat(this._serviceUrl, "/").concat(this.normalizeRoute(params.route)), | ||
method: params.method || 'GET', | ||
data: params.data, | ||
params: params.params, | ||
headers: __assign(__assign({}, this.getHeaders()), params.customHeaders ? params.customHeaders : {}), | ||
headers: __assign(__assign({}, this.getHeaders()), params.customHeaders), | ||
signal: params.signal, | ||
@@ -336,7 +335,7 @@ }; | ||
return [4 /*yield*/, this.axios({ | ||
url: this.getUrl(params), | ||
url: "".concat(params.url || this._serviceUrl, "/").concat(this.normalizeRoute(params.route)), | ||
method: params.method || 'GET', | ||
data: params.data, | ||
params: query, | ||
headers: __assign(__assign({}, this.getHeaders()), params.customHeaders ? params.customHeaders : {}), | ||
headers: __assign(__assign({}, this.getHeaders()), params.customHeaders), | ||
signal: params.signal, | ||
@@ -354,3 +353,3 @@ }).catch(function (e) { | ||
/** | ||
* Normalize route ro remove spaces from param | ||
* Normalize route ro remove splace from param | ||
* ```typescript | ||
@@ -364,17 +363,2 @@ * const result = await instance.normalizeRoute('/route'); | ||
}; | ||
/** | ||
* Normalize URL for API request | ||
* @param {CalApiParams} params request params | ||
* @returns {string} normalized URL | ||
* @ignore | ||
*/ | ||
Base.prototype.getUrl = function (params) { | ||
if (params.url) | ||
return params.url; | ||
if (!this.serviceUrl) | ||
throw new Error('serviceUrl is not defined'); | ||
var url = new URL(this.serviceUrl); | ||
url.pathname = (0, path_1.join)(url.pathname, (0, utils_1.normalizeRoute)(params.route)); | ||
return url.toString(); | ||
}; | ||
return Base; | ||
@@ -381,0 +365,0 @@ }()); |
@@ -10,3 +10,2 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { join } from 'path'; | ||
import axios from 'axios'; | ||
@@ -184,7 +183,7 @@ import { normalizeRoute, normalizeUrl, paramsSerializer, parseAxiosError } from './utils'; | ||
const conf = { | ||
url: this.getUrl(params), | ||
url: `${this._serviceUrl}/${this.normalizeRoute(params.route)}`, | ||
method: params.method || 'GET', | ||
data: params.data, | ||
params: params.params, | ||
headers: Object.assign(Object.assign({}, this.getHeaders()), params.customHeaders ? params.customHeaders : {}), | ||
headers: Object.assign(Object.assign({}, this.getHeaders()), params.customHeaders), | ||
signal: params.signal, | ||
@@ -223,7 +222,7 @@ }; | ||
const { data } = yield this.axios({ | ||
url: this.getUrl(params), | ||
url: `${params.url || this._serviceUrl}/${this.normalizeRoute(params.route)}`, | ||
method: params.method || 'GET', | ||
data: params.data, | ||
params: query, | ||
headers: Object.assign(Object.assign({}, this.getHeaders()), params.customHeaders ? params.customHeaders : {}), | ||
headers: Object.assign(Object.assign({}, this.getHeaders()), params.customHeaders), | ||
signal: params.signal, | ||
@@ -237,3 +236,3 @@ }).catch(e => { | ||
/** | ||
* Normalize route ro remove spaces from param | ||
* Normalize route ro remove splace from param | ||
* ```typescript | ||
@@ -247,18 +246,3 @@ * const result = await instance.normalizeRoute('/route'); | ||
} | ||
/** | ||
* Normalize URL for API request | ||
* @param {CalApiParams} params request params | ||
* @returns {string} normalized URL | ||
* @ignore | ||
*/ | ||
getUrl(params) { | ||
if (params.url) | ||
return params.url; | ||
if (!this.serviceUrl) | ||
throw new Error('serviceUrl is not defined'); | ||
const url = new URL(this.serviceUrl); | ||
url.pathname = join(url.pathname, normalizeRoute(params.route)); | ||
return url.toString(); | ||
} | ||
} | ||
//# sourceMappingURL=Base.js.map |
@@ -87,3 +87,3 @@ import { RawAxiosRequestHeaders, AxiosError } from 'axios'; | ||
/** | ||
* Normalize route ro remove spaces from param | ||
* Normalize route ro remove splace from param | ||
* ```typescript | ||
@@ -95,10 +95,3 @@ * const result = await instance.normalizeRoute('/route'); | ||
protected normalizeRoute(data: string): string; | ||
/** | ||
* Normalize URL for API request | ||
* @param {CalApiParams} params request params | ||
* @returns {string} normalized URL | ||
* @ignore | ||
*/ | ||
protected getUrl(params: CalApiParams): string; | ||
} | ||
//# sourceMappingURL=Base.d.ts.map |
{ | ||
"name": "@or-sdk/base", | ||
"version": "0.29.2-beta.2355.0", | ||
"version": "0.29.2-beta.2356.0", | ||
"main": "dist/cjs/index.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/esm/index.js", |
@@ -1,2 +0,1 @@ | ||
import { join } from 'path'; | ||
import axios, { AxiosInstance, RawAxiosRequestHeaders, AxiosRequestConfig, AxiosError } from 'axios'; | ||
@@ -224,3 +223,3 @@ import { BaseConfig, CalApiParams, MakeApiUrlData, ServiceDiscoveryResponse } from './types'; | ||
const conf: AxiosRequestConfig = { | ||
url: this.getUrl(params), | ||
url: `${this._serviceUrl}/${this.normalizeRoute(params.route)}`, | ||
method: params.method || 'GET', | ||
@@ -231,3 +230,3 @@ data: params.data, | ||
...this.getHeaders(), | ||
... params.customHeaders ? params.customHeaders : {}, | ||
...params.customHeaders, | ||
}, | ||
@@ -265,3 +264,3 @@ signal: params.signal, | ||
const { data } = await this.axios({ | ||
url: this.getUrl(params), | ||
url: `${params.url || this._serviceUrl}/${this.normalizeRoute(params.route)}`, | ||
method: params.method || 'GET', | ||
@@ -272,3 +271,3 @@ data: params.data, | ||
...this.getHeaders(), | ||
...params.customHeaders ? params.customHeaders : {}, | ||
...params.customHeaders, | ||
}, | ||
@@ -284,3 +283,3 @@ signal: params.signal, | ||
/** | ||
* Normalize route ro remove spaces from param | ||
* Normalize route ro remove splace from param | ||
* ```typescript | ||
@@ -291,22 +290,5 @@ * const result = await instance.normalizeRoute('/route'); | ||
*/ | ||
protected normalizeRoute(data: string): string { | ||
protected normalizeRoute(data: string) { | ||
return normalizeRoute(data); | ||
} | ||
/** | ||
* Normalize URL for API request | ||
* @param {CalApiParams} params request params | ||
* @returns {string} normalized URL | ||
* @ignore | ||
*/ | ||
protected getUrl(params: CalApiParams): string { | ||
if (params.url) return params.url; | ||
if (!this.serviceUrl) throw new Error('serviceUrl is not defined'); | ||
const url = new URL(this.serviceUrl); | ||
url.pathname = join(url.pathname, normalizeRoute(params.route)); | ||
return url.toString(); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
90190
1529