@infosel-sdk/core
Version:
Core SDK for Infosel financial services platform. Provides essential infrastructure for authentication, HTTP/GraphQL communication, storage management, and error handling.
59 lines • 2.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const axios_1 = tslib_1.__importDefault(require("axios"));
const errors_1 = require("../../errors");
class InfoselHttpClient {
constructor(axiosInstance) {
this.axiosInstance = axiosInstance;
}
static newInstance(baseURL, sdkManager) {
const axiosInstance = axios_1.default.create({
baseURL,
timeout: 60000,
});
// Request interceptor
axiosInstance.interceptors.request.use(config => sdkManager.authInterceptor.tokenInterceptor(config), error => Promise.reject((0, errors_1.parseSdkError)(error)));
// Response interceptor
axiosInstance.interceptors.response.use(response => response, (error) => tslib_1.__awaiter(this, void 0, void 0, function* () { return sdkManager.authInterceptor.errorInterceptor(axiosInstance, error); }));
return new InfoselHttpClient(axiosInstance);
}
request(config) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosInstance.request(config);
return response.data;
});
}
get(url, config) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosInstance.get(url, config);
return response.data;
});
}
post(url, data, config) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosInstance.post(url, data, config);
return response.data;
});
}
put(url, data, config) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosInstance.put(url, data, config);
return response.data;
});
}
patch(url, data, config) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosInstance.patch(url, data, config);
return response.data;
});
}
delete(url, config) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const response = yield this.axiosInstance.delete(url, config);
return response.data;
});
}
}
exports.default = InfoselHttpClient;
//# sourceMappingURL=infosel_http_client.js.map