smartystreets-javascript-sdk
Advanced tools
Comparing version 1.13.7 to 2.0.0
{ | ||
"name": "smartystreets-javascript-sdk", | ||
"version": "1.13.7", | ||
"version": "2.0.0", | ||
"description": "Quick and easy Smarty address validation.", | ||
@@ -35,4 +35,4 @@ "keywords": [ | ||
"devDependencies": { | ||
"chai": "^4.2.0", | ||
"mocha": "^9.2.1" | ||
"chai": "^4.3.6", | ||
"mocha": "^9.2.2" | ||
}, | ||
@@ -39,0 +39,0 @@ "dependencies": { |
@@ -11,2 +11,4 @@ const HttpSender = require("./HttpSender"); | ||
const BadCredentialsError = require("./Errors").BadCredentialsError; | ||
const RetrySender = require("./RetrySender.js"); | ||
const Sleeper = require("./util/Sleeper.js"); | ||
@@ -155,6 +157,10 @@ //TODO: refactor this to work more cleanly with a bundler. | ||
const httpSender = new HttpSender(this.maxTimeout, this.maxRetries, this.proxy, this.debug); | ||
const httpSender = new HttpSender(this.maxTimeout, this.proxy, this.debug); | ||
const statusCodeSender = new StatusCodeSender(httpSender); | ||
const signingSender = new SigningSender(statusCodeSender, this.signer); | ||
const agentSender = new AgentSender(signingSender); | ||
let agentSender = new AgentSender(signingSender); | ||
if (this.maxRetries > 0) { | ||
const retrySender = new RetrySender(this.maxRetries, signingSender, new Sleeper()); | ||
agentSender = new AgentSender(retrySender); | ||
} | ||
const customHeaderSender = new CustomHeaderSender(agentSender, this.customHeaders); | ||
@@ -161,0 +167,0 @@ const baseUrlSender = new BaseUrlSender(customHeaderSender, this.baseUrl); |
const Response = require("./Response"); | ||
const Axios = require("axios"); | ||
const axiosRetry = require("axios-retry"); | ||
const {buildSmartyResponse} = require("../src/util/buildSmartyResponse"); | ||
class HttpSender { | ||
constructor(timeout = 10000, retries = 5, proxyConfig, debug = false) { | ||
axiosRetry(Axios, { | ||
retries: retries, | ||
}); | ||
constructor(timeout = 10000, proxyConfig, debug = false) { | ||
this.timeout = timeout; | ||
@@ -36,7 +33,2 @@ this.proxyConfig = proxyConfig; | ||
buildSmartyResponse(response, error) { | ||
if (response) return new Response(response.status, response.data); | ||
return new Response(undefined, undefined, error) | ||
} | ||
send(request) { | ||
@@ -48,3 +40,3 @@ return new Promise((resolve, reject) => { | ||
.then(response => { | ||
let smartyResponse = this.buildSmartyResponse(response); | ||
let smartyResponse = buildSmartyResponse(response); | ||
@@ -55,3 +47,3 @@ if (smartyResponse.statusCode >= 400) reject(smartyResponse); | ||
}) | ||
.catch(error => reject(this.buildSmartyResponse(undefined, error))); | ||
.catch(error => reject(buildSmartyResponse(undefined, error))); | ||
}); | ||
@@ -58,0 +50,0 @@ } |
class Response { | ||
constructor (statusCode, payload, error = undefined) { | ||
constructor (statusCode, payload, error, headers) { | ||
this.statusCode = statusCode; | ||
this.payload = payload; | ||
this.error = error; | ||
this.headers = headers; | ||
} | ||
@@ -7,0 +8,0 @@ } |
@@ -0,1 +1,2 @@ | ||
const {buildSmartyResponse} = require("../../src/util/buildSmartyResponse.js"); | ||
const Response = require("../../src/Response"); | ||
@@ -23,2 +24,19 @@ | ||
}, | ||
}; | ||
MockSenderWithStatusCodesAndHeaders: function (statusCodes, headers = undefined, error = undefined) { | ||
this.statusCodes = statusCodes; | ||
this.headers = headers; | ||
this.error = error; | ||
this.currentStatusCodeIndex = 0; | ||
this.send = function (request) { | ||
let mockResponse = { | ||
status: this.statusCodes[this.currentStatusCodeIndex], | ||
headers: this.headers, | ||
error: this.error, | ||
}; | ||
const response = buildSmartyResponse(mockResponse); | ||
this.currentStatusCodeIndex += 1; | ||
return response; | ||
} | ||
} | ||
}; |
@@ -5,2 +5,3 @@ const chai = require("chai"); | ||
const HttpSender = require("../src/HttpSender"); | ||
const {buildSmartyResponse} = require("../src/util/buildSmartyResponse"); | ||
@@ -75,3 +76,3 @@ describe ("An Axios implementation of a HTTP sender", function () { | ||
}; | ||
let smartyResponse = sender.buildSmartyResponse(mockResponse); | ||
let smartyResponse = buildSmartyResponse(mockResponse); | ||
@@ -89,3 +90,3 @@ expect(smartyResponse.hasOwnProperty("statusCode")).to.equal(true); | ||
}; | ||
let smartyResponse = sender.buildSmartyResponse(mockResponse); | ||
let smartyResponse = buildSmartyResponse(mockResponse); | ||
@@ -92,0 +93,0 @@ expect(smartyResponse.hasOwnProperty("payload")).to.equal(true); |
Sorry, the diff of this file is not supported yet
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
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
170741
97
3920
1