@alphatango/httpclient
Advanced tools
Comparing version 0.0.11 to 1.0.0
"use strict"; | ||
/* eslint-disable no-param-reassign */ | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -7,2 +6,4 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const exceptions_1 = require("@alphatango/exceptions"); | ||
const url_1 = require("url"); | ||
const axios_1 = __importDefault(require("axios")); | ||
@@ -19,2 +20,3 @@ const cacheAdapterEnhancer_1 = __importDefault(require("axios-extensions/lib/cacheAdapterEnhancer")); | ||
var _a, _b, _c, _d; | ||
// eslint-disable-next-line no-console | ||
this.logFunction = (_a = options === null || options === void 0 ? void 0 : options.logFunction) !== null && _a !== void 0 ? _a : console.log; | ||
@@ -44,6 +46,7 @@ this.tokenResolverFunction = options === null || options === void 0 ? void 0 : options.tokenResolver; | ||
if (!config.url) { | ||
throw new Error('HttpClient Error: "url" must be defined'); | ||
throw new exceptions_1.InternalException('HttpClient Error: "url" must be defined'); | ||
} | ||
return config; | ||
}, (error) => { | ||
var _a; | ||
this.logFunction({ | ||
@@ -54,5 +57,7 @@ title: 'HTTP Request Error', | ||
}); | ||
throw error; | ||
const hostname = ((_a = error.config) === null || _a === void 0 ? void 0 : _a.url) ? new url_1.URL(error.config.url).hostname : 'N/A'; | ||
throw new exceptions_1.ClientException(hostname, error); | ||
}); | ||
this.client.interceptors.response.use((response) => response, (error) => { | ||
var _a; | ||
if (error.message === invalidToken) { | ||
@@ -72,3 +77,4 @@ this.logFunction({ | ||
} | ||
throw error; | ||
const hostname = ((_a = error.config) === null || _a === void 0 ? void 0 : _a.url) ? new url_1.URL(error.config.url).hostname : 'N/A'; | ||
throw new exceptions_1.ClientException(hostname, error); | ||
}); | ||
@@ -82,3 +88,3 @@ } | ||
if (headers.Authorization) { | ||
throw new Error('Authorization header already specified, please create a new HttpClient with a different (or without a) tokenResolver'); | ||
throw new exceptions_1.InternalException('Authorization header already specified, please create a new HttpClient with a different (or without a) tokenResolver'); | ||
} | ||
@@ -109,4 +115,4 @@ else { | ||
async post(url, data, config = {}) { | ||
config.headers = await this.createHeadersWithResolvedToken(config.headers); | ||
return this.client.post(url, data, config); | ||
const headers = await this.createHeadersWithResolvedToken(config.headers); | ||
return this.client.post(url, data, { ...config, headers }); | ||
} | ||
@@ -117,4 +123,4 @@ /** | ||
async put(url, data, config = {}) { | ||
config.headers = await this.createHeadersWithResolvedToken(config.headers); | ||
return this.client.put(url, data, config); | ||
const headers = await this.createHeadersWithResolvedToken(config.headers); | ||
return this.client.put(url, data, { ...config, headers }); | ||
} | ||
@@ -125,4 +131,4 @@ /** | ||
async patch(url, data, config = {}) { | ||
config.headers = await this.createHeadersWithResolvedToken(config.headers); | ||
return this.client.patch(url, data, config); | ||
const headers = await this.createHeadersWithResolvedToken(config.headers); | ||
return this.client.patch(url, data, { ...config, headers }); | ||
} | ||
@@ -133,4 +139,4 @@ /** | ||
async delete(url, config = {}) { | ||
config.headers = await this.createHeadersWithResolvedToken(config.headers); | ||
return this.client.delete(url, config); | ||
const headers = await this.createHeadersWithResolvedToken(config.headers); | ||
return this.client.delete(url, { ...config, headers }); | ||
} | ||
@@ -141,4 +147,4 @@ /** | ||
async head(url, config = {}) { | ||
config.headers = await this.createHeadersWithResolvedToken(config.headers); | ||
return this.client.head(url, config); | ||
const headers = await this.createHeadersWithResolvedToken(config.headers); | ||
return this.client.head(url, { ...config, headers }); | ||
} | ||
@@ -149,6 +155,6 @@ /** | ||
async options(url, config = {}) { | ||
config.headers = await this.createHeadersWithResolvedToken(config.headers); | ||
return this.client.options(url, config); | ||
const headers = await this.createHeadersWithResolvedToken(config.headers); | ||
return this.client.options(url, { ...config, headers }); | ||
} | ||
} | ||
exports.default = HttpClient; |
{ | ||
"name": "@alphatango/httpclient", | ||
"version": "0.0.11", | ||
"version": "1.0.0", | ||
"description": "A wrapper around axios with retry and caching logic, bearer token injection through custom resolvers and extended logging", | ||
@@ -32,5 +32,7 @@ "main": "lib/httpClient.js", | ||
"peerDependencies": { | ||
"aws-sdk": "^2.0.0" | ||
"aws-sdk": "^2.0.0", | ||
"@alphatango/exceptions": "^0.0.4" | ||
}, | ||
"devDependencies": { | ||
"@alphatango/exceptions": "^0.0.4", | ||
"@types/jest": "26.0.8", | ||
@@ -37,0 +39,0 @@ "@types/uuid": "8.3.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
15030
247
0
0
5
13