UNPKG

@atomixdesign/nodepay-core

Version:
61 lines (60 loc) 2.85 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HttpClientFactory = void 0; var typedi_1 = require("typedi"); var axios_1 = __importDefault(require("axios")); var network_client_factory_1 = require("./types/network-client-factory"); var debug_1 = __importDefault(require("debug")); var log = debug_1.default('nodepay:core'); var HttpClientFactory = /** @class */ (function (_super) { __extends(HttpClientFactory, _super); function HttpClientFactory() { return _super !== null && _super.apply(this, arguments) || this; } HttpClientFactory.prototype.create = function (config) { var httpClient = axios_1.default.create(config); httpClient.interceptors.request.use(function (config) { // TODO: Allow custom interceptor callbacks. log({ config: config }); return config; }, function (error) { // Do something with request error log({ error: error }); return Promise.reject(error); }); // Add a response interceptor httpClient.interceptors.response.use(function (response) { return response; }, function (error) { return Promise.reject(error); }); return httpClient; }; HttpClientFactory = __decorate([ typedi_1.Service('http.client') ], HttpClientFactory); return HttpClientFactory; }(network_client_factory_1.NetworkClientFactory)); exports.HttpClientFactory = HttpClientFactory;