smartystreets-javascript-sdk
Advanced tools
Comparing version 4.0.0 to 4.0.1
@@ -5,3 +5,8 @@ const SmartySDK = require("smartystreets-javascript-sdk"); | ||
// International Autocomplete only supports using Embedded Keys | ||
// for Server-to-server requests, use this code: | ||
// let authId = process.env.SMARTY_AUTH_ID; | ||
// let authToken = process.env.SMARTY_AUTH_TOKEN; | ||
// const credentials = new SmartyCore.StaticCredentials(authId, authToken); | ||
// for client-side requests (browser/mobile), use this code: | ||
const key = process.env.SMARTY_EMBEDDED_KEY; | ||
@@ -8,0 +13,0 @@ const credentials = new SmartyCore.SharedCredentials(key); |
{ | ||
"name": "smartystreets-javascript-sdk", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "Quick and easy Smarty address validation.", | ||
@@ -36,8 +36,8 @@ "keywords": [ | ||
"chai": "^4.3.6", | ||
"mocha": "^9.2.2" | ||
"mocha": "^10.2.0" | ||
}, | ||
"dependencies": { | ||
"axios": "^0.26.1", | ||
"axios-retry": "3.2.0" | ||
"axios": "^1.6.2", | ||
"axios-retry": "4.0.0" | ||
} | ||
} |
@@ -9,3 +9,3 @@ class BaseUrlSender { | ||
return new Promise((resolve, reject) => { | ||
request.baseUrl = `${this.urlOverride}${request.baseUrlParams ? `/${request.baseUrlParams}` : ""}`; | ||
request.baseUrl = `${this.urlOverride}${request.baseUrlParam ? `/${request.baseUrlParam}` : ""}`; | ||
@@ -12,0 +12,0 @@ this.sender.send(request) |
@@ -8,5 +8,10 @@ class InputData { | ||
add(apiField, lookupField) { | ||
if (this.lookupFieldIsPopulated(lookupField)) this.data[apiField] = this.lookup[lookupField]; | ||
if (this.lookupFieldIsPopulated(lookupField)) this.data[apiField] = this.formatData(this.lookup[lookupField]); | ||
} | ||
formatData(field) { | ||
if (Array.isArray(field)) return field.join(";"); | ||
else return field; | ||
} | ||
lookupFieldIsPopulated(lookupField) { | ||
@@ -13,0 +18,0 @@ return this.lookup[lookupField] !== "" && this.lookup[lookupField] !== undefined; |
const Errors = require("../Errors"); | ||
const Request = require("../Request"); | ||
const Suggestion = require("./Suggestion"); | ||
const buildInputData = require("../util/buildInputData"); | ||
const keyTranslationFormat = require("../util/apiToSDKKeyMap").internationalAddressAutocomplete; | ||
@@ -14,12 +16,6 @@ class Client { | ||
let request = new Request(); | ||
request.parameters = { | ||
search: lookup.search, | ||
country: lookup.country, | ||
max_results: lookup.maxResults, | ||
include_only_locality: lookup.includeOnlyLocality, | ||
include_only_postal_code: lookup.includeOnlyPostalCode, | ||
}; | ||
request.parameters = buildInputData(lookup, keyTranslationFormat); | ||
if (lookup.addressId) { | ||
request.baseUrlParams = lookup.addressId; | ||
request.baseUrlParam = lookup.addressId; | ||
} | ||
@@ -26,0 +22,0 @@ |
class Request { | ||
constructor(payload) { | ||
this.baseUrl = ""; | ||
this.baseUrlParams = ""; | ||
this.baseUrlParam = ""; | ||
this.payload = payload; | ||
@@ -6,0 +6,0 @@ this.headers = { |
const Errors = require("../Errors"); | ||
const Request = require("../Request"); | ||
const Suggestion = require("./Suggestion"); | ||
const buildInputData = require("../util/buildInputData"); | ||
const keyTranslationFormat = require("../util/apiToSDKKeyMap").usAutocompletePro; | ||
@@ -18,3 +20,3 @@ /** | ||
let request = new Request(); | ||
request.parameters = buildRequestParameters(lookup); | ||
request.parameters = buildInputData(lookup, keyTranslationFormat); | ||
@@ -32,24 +34,2 @@ return new Promise((resolve, reject) => { | ||
function buildRequestParameters(lookup) { | ||
return { | ||
search: lookup.search, | ||
selected: lookup.selected, | ||
max_results: lookup.maxResults, | ||
include_only_cities: joinFieldWith(lookup.includeOnlyCities, ";"), | ||
include_only_states: joinFieldWith(lookup.includeOnlyStates, ";"), | ||
include_only_zip_codes: joinFieldWith(lookup.includeOnlyZIPCodes, ";"), | ||
exclude_states: joinFieldWith(lookup.excludeStates, ";"), | ||
prefer_cities: joinFieldWith(lookup.preferCities, ";"), | ||
prefer_states: joinFieldWith(lookup.preferStates, ";"), | ||
prefer_zip_codes: joinFieldWith(lookup.preferZIPCodes, ";"), | ||
prefer_ratio: lookup.preferRatio, | ||
prefer_geolocation: lookup.preferGeolocation, | ||
source: lookup.source, | ||
}; | ||
function joinFieldWith(field, delimiter) { | ||
if (field.length) return field.join(delimiter); | ||
} | ||
} | ||
function buildSuggestionsFromResponse(payload) { | ||
@@ -56,0 +36,0 @@ if (payload.suggestions === null) return []; |
const Errors = require("../Errors"); | ||
const Request = require("../Request"); | ||
const Result = require("./Result"); | ||
const buildInputData = require("../util/buildInputData"); | ||
const keyTranslationFormat = require("../util/apiToSDKKeyMap").usExtract; | ||
@@ -18,3 +20,3 @@ /** | ||
let request = new Request(lookup.text); | ||
request.parameters = buildRequestParams(lookup); | ||
request.parameters = buildInputData(lookup, keyTranslationFormat); | ||
@@ -31,11 +33,2 @@ return new Promise((resolve, reject) => { | ||
}); | ||
function buildRequestParams(lookup) { | ||
return { | ||
html: lookup.html, | ||
aggressive: lookup.aggressive, | ||
addr_line_breaks: lookup.addressesHaveLineBreaks, | ||
addr_per_line: lookup.addressesPerLine, | ||
}; | ||
} | ||
} | ||
@@ -42,0 +35,0 @@ } |
@@ -16,2 +16,17 @@ module.exports = { | ||
}, | ||
usAutocompletePro: { | ||
search: "search", | ||
selected: "selected", | ||
max_results: "maxResults", | ||
include_only_cities: "includeOnlyCities", | ||
include_only_states: "includeOnlyStates", | ||
include_only_zip_codes: "includeOnlyZIPCodes", | ||
exclude_states: "excludeStates", | ||
prefer_cities: "preferCities", | ||
prefer_states: "preferStates", | ||
prefer_zip_codes: "preferZIPCodes", | ||
prefer_ratio: "preferRatio", | ||
prefer_geolocation: "preferGeolocation", | ||
source: "source", | ||
}, | ||
usZipcode: { | ||
@@ -36,2 +51,10 @@ "city": "city", | ||
}, | ||
internationalAddressAutocomplete: { | ||
search: "search", | ||
country: "country", | ||
max_results: "maxResults", | ||
include_only_administrative_area: "includeOnlyAdministrativeArea", | ||
include_only_locality: "includeOnlyLocality", | ||
include_only_postal_code: "includeOnlyPostalCode", | ||
}, | ||
usReverseGeo: { | ||
@@ -41,3 +64,9 @@ "latitude": "latitude", | ||
"source": "source" | ||
}, | ||
usExtract: { | ||
html: "html", | ||
aggressive: "aggressive", | ||
addr_line_breaks: "addressesHaveLineBreaks", | ||
addr_per_line: "addressesPerLine", | ||
} | ||
}; |
@@ -17,5 +17,2 @@ const chai = require("chai"); | ||
let expectedParameters = { | ||
country: undefined, | ||
include_only_locality: undefined, | ||
include_only_postal_code: undefined, | ||
max_results: 5, | ||
@@ -39,4 +36,2 @@ search: "(", | ||
max_results: 5, | ||
include_only_locality: undefined, | ||
include_only_postal_code: undefined, | ||
search: search, | ||
@@ -57,6 +52,3 @@ }; | ||
let expectedParameters = { | ||
country: undefined, | ||
max_results: 10, | ||
include_only_locality: undefined, | ||
include_only_postal_code: undefined, | ||
search: search, | ||
@@ -63,0 +55,0 @@ }; |
@@ -17,15 +17,10 @@ const chai = require("chai"); | ||
let expectedParameters = { | ||
exclude_states: "", | ||
include_only_cities: "", | ||
include_only_states: "", | ||
include_only_zip_codes: "", | ||
prefer_cities: "", | ||
prefer_states: "", | ||
prefer_zip_codes: "", | ||
search: search, | ||
selected: undefined, | ||
max_results: undefined, | ||
include_only_cities: undefined, | ||
include_only_states: undefined, | ||
include_only_zip_codes: undefined, | ||
exclude_states: undefined, | ||
prefer_cities: undefined, | ||
prefer_states: undefined, | ||
prefer_zip_codes: undefined, | ||
prefer_ratio: undefined, | ||
prefer_geolocation: undefined, | ||
source: undefined, | ||
}; | ||
@@ -32,0 +27,0 @@ |
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
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
173377
3980
+ Addedasynckit@0.4.0(transitive)
+ Addedaxios@1.7.7(transitive)
+ Addedaxios-retry@4.0.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedform-data@4.0.1(transitive)
+ Addedis-retry-allowed@2.2.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedproxy-from-env@1.1.0(transitive)
- Removedaxios@0.26.1(transitive)
- Removedaxios-retry@3.2.0(transitive)
- Removedis-retry-allowed@1.2.0(transitive)
Updatedaxios@^1.6.2
Updatedaxios-retry@4.0.0