@or-sdk/base
Advanced tools
Comparing version 0.29.2-beta.2367.0 to 0.29.2-beta.2373.0
@@ -284,3 +284,3 @@ "use strict"; | ||
conf = { | ||
url: this.getUrl(params), | ||
url: "".concat(this._serviceUrl, "/").concat(this.normalizeRoute(params.route)), | ||
method: params.method || 'GET', | ||
@@ -304,17 +304,5 @@ data: params.data, | ||
}; | ||
/** | ||
* Make api request | ||
* ```typescript | ||
* const result = await instance.callApi({ | ||
* route: '/route', | ||
* method: 'GET', | ||
* data: requestData, | ||
* params: queryParams, | ||
* }); | ||
* ``` | ||
* @ignore | ||
*/ | ||
Base.prototype.callApiV2 = function (params) { | ||
Base.prototype.doApiRequest = function (params) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var query, data; | ||
var query; | ||
var _this = this; | ||
@@ -334,8 +322,8 @@ return __generator(this, function (_a) { | ||
} | ||
return [4 /*yield*/, this.axios({ | ||
url: this.getUrl(params), | ||
return [2 /*return*/, this.axios({ | ||
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 ? params.customHeaders : {})), | ||
signal: params.signal, | ||
@@ -345,3 +333,25 @@ }).catch(function (e) { | ||
})]; | ||
case 3: | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Make api request | ||
* ```typescript | ||
* const result = await instance.callApi({ | ||
* route: '/route', | ||
* method: 'GET', | ||
* data: requestData, | ||
* params: queryParams, | ||
* }); | ||
* ``` | ||
* @ignore | ||
*/ | ||
Base.prototype.callApiV2 = function (params) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var data; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.doApiRequest(params)]; | ||
case 1: | ||
data = (_a.sent()).data; | ||
@@ -354,3 +364,3 @@ return [2 /*return*/, data]; | ||
/** | ||
* Normalize route ro remove spaces from param | ||
* Normalize route ro remove splace from param | ||
* ```typescript | ||
@@ -364,15 +374,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 or not discovered'); | ||
return (0, utils_1.getServiceUrlWithRoute)(this.serviceUrl, this.normalizeRoute(params.route)); | ||
}; | ||
return Base; | ||
@@ -379,0 +376,0 @@ }()); |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -33,3 +19,2 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "makeList", { enumerable: true, get: function () { return __importDefault(makeList_1).default; } }); | ||
__exportStar(require("./url"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -11,3 +11,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import axios from 'axios'; | ||
import { normalizeRoute, normalizeUrl, paramsSerializer, parseAxiosError, getServiceUrlWithRoute } from './utils'; | ||
import { normalizeRoute, normalizeUrl, paramsSerializer, parseAxiosError } from './utils'; | ||
import { DISCOVERY_ROUTE, DISCOVERY_ROUTE_ACCOUNTID, DISCOVERY_ROUTE_PROVIDERS_ACCOUNT_ID, SdkStatus, } from './constants'; | ||
@@ -183,3 +183,3 @@ export class Base { | ||
const conf = { | ||
url: this.getUrl(params), | ||
url: `${this._serviceUrl}/${this.normalizeRoute(params.route)}`, | ||
method: params.method || 'GET', | ||
@@ -199,15 +199,3 @@ data: params.data, | ||
} | ||
/** | ||
* Make api request | ||
* ```typescript | ||
* const result = await instance.callApi({ | ||
* route: '/route', | ||
* method: 'GET', | ||
* data: requestData, | ||
* params: queryParams, | ||
* }); | ||
* ``` | ||
* @ignore | ||
*/ | ||
callApiV2(params) { | ||
doApiRequest(params) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -222,8 +210,8 @@ if (this.status === SdkStatus.NEW) { | ||
} | ||
const { data } = yield this.axios({ | ||
url: this.getUrl(params), | ||
return this.axios({ | ||
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 ? params.customHeaders : {})), | ||
signal: params.signal, | ||
@@ -233,2 +221,19 @@ }).catch(e => { | ||
}); | ||
}); | ||
} | ||
/** | ||
* Make api request | ||
* ```typescript | ||
* const result = await instance.callApi({ | ||
* route: '/route', | ||
* method: 'GET', | ||
* data: requestData, | ||
* params: queryParams, | ||
* }); | ||
* ``` | ||
* @ignore | ||
*/ | ||
callApiV2(params) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { data } = yield this.doApiRequest(params); | ||
return data; | ||
@@ -238,3 +243,3 @@ }); | ||
/** | ||
* Normalize route ro remove spaces from param | ||
* Normalize route ro remove splace from param | ||
* ```typescript | ||
@@ -248,16 +253,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 or not discovered'); | ||
return getServiceUrlWithRoute(this.serviceUrl, this.normalizeRoute(params.route)); | ||
} | ||
} | ||
//# sourceMappingURL=Base.js.map |
@@ -7,3 +7,2 @@ export { default as paramsSerializer } from './paramsSerializer'; | ||
export { default as makeList } from './makeList'; | ||
export * from './url'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { RawAxiosRequestHeaders, AxiosError } from 'axios'; | ||
import { RawAxiosRequestHeaders, AxiosError, AxiosResponse } from 'axios'; | ||
import { BaseConfig, CalApiParams, MakeApiUrlData } from './types'; | ||
@@ -73,2 +73,3 @@ export declare abstract class Base { | ||
protected callApi<T>(params: CalApiParams): Promise<T>; | ||
protected doApiRequest<T>(params: CalApiParams): Promise<AxiosResponse<T>>; | ||
/** | ||
@@ -88,3 +89,3 @@ * Make api request | ||
/** | ||
* Normalize route ro remove spaces from param | ||
* Normalize route ro remove splace from param | ||
* ```typescript | ||
@@ -96,10 +97,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 |
@@ -7,3 +7,2 @@ export { default as paramsSerializer } from './paramsSerializer'; | ||
export { default as makeList } from './makeList'; | ||
export * from './url'; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@or-sdk/base", | ||
"version": "0.29.2-beta.2367.0", | ||
"version": "0.29.2-beta.2373.0", | ||
"main": "dist/cjs/index.js", | ||
@@ -17,5 +17,3 @@ "module": "dist/esm/index.js", | ||
"clean": "rm -rf ./dist", | ||
"dev": "pnpm build:watch:esm", | ||
"test": "vitest --run", | ||
"test:watch": "vitest --watch" | ||
"dev": "pnpm build:watch:esm" | ||
}, | ||
@@ -31,4 +29,3 @@ "dependencies": { | ||
"concurrently": "^6.4.0", | ||
"typescript": "^4.4.4", | ||
"vitest": "^0.31.1" | ||
"typescript": "^4.4.4" | ||
}, | ||
@@ -35,0 +32,0 @@ "publishConfig": { |
@@ -1,4 +0,4 @@ | ||
import axios, { AxiosInstance, RawAxiosRequestHeaders, AxiosRequestConfig, AxiosError } from 'axios'; | ||
import axios, { AxiosInstance, RawAxiosRequestHeaders, AxiosRequestConfig, AxiosError, AxiosResponse } from 'axios'; | ||
import { BaseConfig, CalApiParams, MakeApiUrlData, ServiceDiscoveryResponse } from './types'; | ||
import { normalizeRoute, normalizeUrl, paramsSerializer, parseAxiosError, getServiceUrlWithRoute } from './utils'; | ||
import { normalizeRoute, normalizeUrl, paramsSerializer, parseAxiosError } from './utils'; | ||
import { | ||
@@ -223,3 +223,3 @@ DISCOVERY_ROUTE, | ||
const conf: AxiosRequestConfig = { | ||
url: this.getUrl(params), | ||
url: `${this._serviceUrl}/${this.normalizeRoute(params.route)}`, | ||
method: params.method || 'GET', | ||
@@ -241,15 +241,3 @@ data: params.data, | ||
/** | ||
* Make api request | ||
* ```typescript | ||
* const result = await instance.callApi({ | ||
* route: '/route', | ||
* method: 'GET', | ||
* data: requestData, | ||
* params: queryParams, | ||
* }); | ||
* ``` | ||
* @ignore | ||
*/ | ||
protected async callApiV2<T>(params: CalApiParams): Promise<T> { | ||
protected async doApiRequest<T>(params: CalApiParams): Promise<AxiosResponse<T>> { | ||
if (this.status === SdkStatus.NEW) { | ||
@@ -263,4 +251,5 @@ await this.init(); | ||
} | ||
const { data } = await this.axios({ | ||
url: this.getUrl(params), | ||
return this.axios({ | ||
url: `${params.url || this._serviceUrl}/${this.normalizeRoute(params.route)}`, | ||
method: params.method || 'GET', | ||
@@ -271,3 +260,3 @@ data: params.data, | ||
...this.getHeaders(), | ||
...params.customHeaders ? params.customHeaders : {}, | ||
...(params.customHeaders ? params.customHeaders : {}), | ||
}, | ||
@@ -278,30 +267,31 @@ signal: params.signal, | ||
}); | ||
return data; | ||
} | ||
/** | ||
* Normalize route ro remove spaces from param | ||
* Make api request | ||
* ```typescript | ||
* const result = await instance.normalizeRoute('/route'); | ||
* const result = await instance.callApi({ | ||
* route: '/route', | ||
* method: 'GET', | ||
* data: requestData, | ||
* params: queryParams, | ||
* }); | ||
* ``` | ||
* @ignore | ||
*/ | ||
protected normalizeRoute(data: string): string { | ||
return normalizeRoute(data); | ||
protected async callApiV2<T>(params: CalApiParams): Promise<T> { | ||
const { data } = await this.doApiRequest<T>(params); | ||
return data; | ||
} | ||
/** | ||
* Normalize URL for API request | ||
* @param {CalApiParams} params request params | ||
* @returns {string} normalized URL | ||
* Normalize route ro remove splace from param | ||
* ```typescript | ||
* const result = await instance.normalizeRoute('/route'); | ||
* ``` | ||
* @ignore | ||
*/ | ||
protected getUrl(params: CalApiParams): string { | ||
if (params.url) return params.url; | ||
if (!this.serviceUrl) throw new Error('serviceUrl is not defined or not discovered'); | ||
return getServiceUrlWithRoute(this.serviceUrl, this.normalizeRoute(params.route)); | ||
protected normalizeRoute(data: string) { | ||
return normalizeRoute(data); | ||
} | ||
} |
@@ -7,3 +7,1 @@ export { default as paramsSerializer } from './paramsSerializer'; | ||
export { default as makeList } from './makeList'; | ||
export * from './url'; | ||
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
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
4
91596
83
1548