@or-sdk/base
Advanced tools
Comparing version 0.16.0 to 0.17.1
@@ -193,2 +193,37 @@ "use strict"; | ||
}; | ||
Base.prototype.callApiV2 = function (params) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var query, data; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!(this.status === constants_1.SdkStatus.NEW)) return [3, 2]; | ||
return [4, this.init()]; | ||
case 1: | ||
_a.sent(); | ||
_a.label = 2; | ||
case 2: | ||
query = params.params || {}; | ||
if (this._isCrossAccount && this._currentAccountId) { | ||
query.accountId = this._currentAccountId; | ||
} | ||
return [4, this.axios({ | ||
url: this._serviceUrl + "/" + (0, utils_1.normalizeRoute)(params.route), | ||
method: params.method || 'GET', | ||
data: params.data, | ||
params: query, | ||
headers: this.getHeaders(), | ||
signal: params.signal, | ||
}) | ||
.catch(function (e) { | ||
throw _this.parseError(e); | ||
})]; | ||
case 3: | ||
data = (_a.sent()).data; | ||
return [2, data]; | ||
} | ||
}); | ||
}); | ||
}; | ||
return Base; | ||
@@ -195,0 +230,0 @@ }()); |
@@ -112,3 +112,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
callApiV2(params) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this.status === SdkStatus.NEW) { | ||
yield this.init(); | ||
} | ||
const query = params.params || {}; | ||
if (this._isCrossAccount && this._currentAccountId) { | ||
query.accountId = this._currentAccountId; | ||
} | ||
const { data } = yield this.axios({ | ||
url: `${this._serviceUrl}/${normalizeRoute(params.route)}`, | ||
method: params.method || 'GET', | ||
data: params.data, | ||
params: query, | ||
headers: this.getHeaders(), | ||
signal: params.signal, | ||
}) | ||
.catch(e => { | ||
throw this.parseError(e); | ||
}); | ||
return data; | ||
}); | ||
} | ||
} | ||
//# sourceMappingURL=Base.js.map |
@@ -28,2 +28,3 @@ import { AxiosRequestHeaders, AxiosError } from 'axios'; | ||
protected callApi<T>(params: CalApiParams): Promise<T>; | ||
protected callApiV2<T>(params: CalApiParams): Promise<T>; | ||
} |
{ | ||
"version": "0.16.0", | ||
"version": "0.17.1", | ||
"name": "@or-sdk/base", | ||
@@ -31,3 +31,3 @@ "main": "dist/cjs/index.js", | ||
}, | ||
"gitHead": "f855bf3ee6b361c5831479cee5cde6f7702b6ced" | ||
"gitHead": "61ede4c3b5e828ea61a8bb78a4bfc4f06852885d" | ||
} |
@@ -7,3 +7,3 @@ import axios, { AxiosInstance, AxiosRequestHeaders, AxiosError } from 'axios'; | ||
export abstract class Base { | ||
private readonly token: string | (()=> string); | ||
private readonly token: string | (() => string); | ||
private readonly axios: AxiosInstance; | ||
@@ -154,2 +154,37 @@ private readonly discoveryUrl: string; | ||
} | ||
/** | ||
* Make api request | ||
* ```typescript | ||
* const result = await instance.callApi({ | ||
* route: '/route', | ||
* method: 'GET', | ||
* data: requestData, | ||
* params: queryParams, | ||
* }); | ||
* ``` | ||
*/ | ||
protected async callApiV2<T>(params: CalApiParams): Promise<T> { | ||
if (this.status === SdkStatus.NEW) { | ||
await this.init(); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const query: any = params.params || {}; | ||
if (this._isCrossAccount && this._currentAccountId) { | ||
query.accountId = this._currentAccountId; | ||
} | ||
const { data } = await this.axios({ | ||
url: `${this._serviceUrl}/${normalizeRoute(params.route)}`, | ||
method: params.method || 'GET', | ||
data: params.data, | ||
params: query, | ||
headers: this.getHeaders(), | ||
signal: params.signal, | ||
}) | ||
.catch(e => { | ||
throw this.parseError(e); | ||
}); | ||
return data; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
53173
11634
986
94