smartystreets-javascript-sdk 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Makefile CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/make -f
2
2
 
3
- VERSION := $(shell tagit -M --dry-run)
3
+ VERSION := $(shell tagit -p --dry-run)
4
4
  VERSION_FILE1 := package.json
5
5
  VERSION_FILE2 := package-lock.json
6
6
 
@@ -11,7 +11,7 @@ node_modules:
11
11
  npm install
12
12
 
13
13
  publish: test version upload unversion
14
- tagit -M
14
+ tagit -p
15
15
  git push origin --tags
16
16
 
17
17
  upload:
@@ -2,7 +2,12 @@ const SmartySDK = require("smartystreets-javascript-sdk");
2
2
  const SmartyCore = SmartySDK.core;
3
3
  const Lookup = SmartySDK.internationalAddressAutocomplete.Lookup;
4
4
 
5
- // International Autocomplete only supports using Embedded Keys
5
+ // for Server-to-server requests, use this code:
6
+ // let authId = process.env.SMARTY_AUTH_ID;
7
+ // let authToken = process.env.SMARTY_AUTH_TOKEN;
8
+ // const credentials = new SmartyCore.StaticCredentials(authId, authToken);
9
+
10
+ // for client-side requests (browser/mobile), use this code:
6
11
  const key = process.env.SMARTY_EMBEDDED_KEY;
7
12
  const credentials = new SmartyCore.SharedCredentials(key);
8
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smartystreets-javascript-sdk",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "Quick and easy Smarty address validation.",
5
5
  "keywords": [
6
6
  "smarty",
@@ -33,10 +33,10 @@
33
33
  },
34
34
  "devDependencies": {
35
35
  "chai": "^4.3.6",
36
- "mocha": "^9.2.2"
36
+ "mocha": "^10.2.0"
37
37
  },
38
38
  "dependencies": {
39
- "axios": "^0.26.1",
40
- "axios-retry": "3.2.0"
39
+ "axios": "^1.6.2",
40
+ "axios-retry": "4.0.0"
41
41
  }
42
42
  }
@@ -6,7 +6,7 @@ class BaseUrlSender {
6
6
 
7
7
  send(request) {
8
8
  return new Promise((resolve, reject) => {
9
- request.baseUrl = `${this.urlOverride}${request.baseUrlParams ? `/${request.baseUrlParams}` : ""}`;
9
+ request.baseUrl = `${this.urlOverride}${request.baseUrlParam ? `/${request.baseUrlParam}` : ""}`;
10
10
 
11
11
  this.sender.send(request)
12
12
  .then(resolve)
package/src/InputData.js CHANGED
@@ -5,7 +5,12 @@ class InputData {
5
5
  }
6
6
 
7
7
  add(apiField, lookupField) {
8
- if (this.lookupFieldIsPopulated(lookupField)) this.data[apiField] = this.lookup[lookupField];
8
+ if (this.lookupFieldIsPopulated(lookupField)) this.data[apiField] = this.formatData(this.lookup[lookupField]);
9
+ }
10
+
11
+ formatData(field) {
12
+ if (Array.isArray(field)) return field.join(";");
13
+ else return field;
9
14
  }
10
15
 
11
16
  lookupFieldIsPopulated(lookupField) {
package/src/Request.js CHANGED
@@ -1,7 +1,7 @@
1
1
  class Request {
2
2
  constructor(payload) {
3
3
  this.baseUrl = "";
4
- this.baseUrlParams = "";
4
+ this.baseUrlParam = "";
5
5
  this.payload = payload;
6
6
  this.headers = {
7
7
  "Content-Type": "application/json; charset=utf-8",
@@ -1,6 +1,8 @@
1
1
  const Errors = require("../Errors");
2
2
  const Request = require("../Request");
3
3
  const Suggestion = require("./Suggestion");
4
+ const buildInputData = require("../util/buildInputData");
5
+ const keyTranslationFormat = require("../util/apiToSDKKeyMap").internationalAddressAutocomplete;
4
6
 
5
7
  class Client {
6
8
  constructor(sender) {
@@ -11,16 +13,10 @@ class Client {
11
13
  if (typeof lookup === "undefined") throw new Errors.UndefinedLookupError();
12
14
 
13
15
  let request = new Request();
14
- request.parameters = {
15
- search: lookup.search,
16
- country: lookup.country,
17
- max_results: lookup.maxResults,
18
- include_only_locality: lookup.includeOnlyLocality,
19
- include_only_postal_code: lookup.includeOnlyPostalCode,
20
- };
16
+ request.parameters = buildInputData(lookup, keyTranslationFormat);
21
17
 
22
18
  if (lookup.addressId) {
23
- request.baseUrlParams = lookup.addressId;
19
+ request.baseUrlParam = lookup.addressId;
24
20
  }
25
21
 
26
22
  return new Promise((resolve, reject) => {
@@ -1,6 +1,8 @@
1
1
  const Errors = require("../Errors");
2
2
  const Request = require("../Request");
3
3
  const Suggestion = require("./Suggestion");
4
+ const buildInputData = require("../util/buildInputData");
5
+ const keyTranslationFormat = require("../util/apiToSDKKeyMap").usAutocompletePro;
4
6
 
5
7
  /**
6
8
  * This client sends lookups to the Smarty US Autocomplete Pro API, <br>
@@ -15,7 +17,7 @@ class Client {
15
17
  if (typeof lookup === "undefined") throw new Errors.UndefinedLookupError();
16
18
 
17
19
  let request = new Request();
18
- request.parameters = buildRequestParameters(lookup);
20
+ request.parameters = buildInputData(lookup, keyTranslationFormat);
19
21
 
20
22
  return new Promise((resolve, reject) => {
21
23
  this.sender.send(request)
@@ -28,28 +30,6 @@ class Client {
28
30
  .catch(reject);
29
31
  });
30
32
 
31
- function buildRequestParameters(lookup) {
32
- return {
33
- search: lookup.search,
34
- selected: lookup.selected,
35
- max_results: lookup.maxResults,
36
- include_only_cities: joinFieldWith(lookup.includeOnlyCities, ";"),
37
- include_only_states: joinFieldWith(lookup.includeOnlyStates, ";"),
38
- include_only_zip_codes: joinFieldWith(lookup.includeOnlyZIPCodes, ";"),
39
- exclude_states: joinFieldWith(lookup.excludeStates, ";"),
40
- prefer_cities: joinFieldWith(lookup.preferCities, ";"),
41
- prefer_states: joinFieldWith(lookup.preferStates, ";"),
42
- prefer_zip_codes: joinFieldWith(lookup.preferZIPCodes, ";"),
43
- prefer_ratio: lookup.preferRatio,
44
- prefer_geolocation: lookup.preferGeolocation,
45
- source: lookup.source,
46
- };
47
-
48
- function joinFieldWith(field, delimiter) {
49
- if (field.length) return field.join(delimiter);
50
- }
51
- }
52
-
53
33
  function buildSuggestionsFromResponse(payload) {
54
34
  if (payload.suggestions === null) return [];
55
35
 
@@ -1,6 +1,8 @@
1
1
  const Errors = require("../Errors");
2
2
  const Request = require("../Request");
3
3
  const Result = require("./Result");
4
+ const buildInputData = require("../util/buildInputData");
5
+ const keyTranslationFormat = require("../util/apiToSDKKeyMap").usExtract;
4
6
 
5
7
  /**
6
8
  * This client sends lookups to the Smarty US Extract API, <br>
@@ -15,7 +17,7 @@ class Client {
15
17
  if (typeof lookup === "undefined") throw new Errors.UndefinedLookupError();
16
18
 
17
19
  let request = new Request(lookup.text);
18
- request.parameters = buildRequestParams(lookup);
20
+ request.parameters = buildInputData(lookup, keyTranslationFormat);
19
21
 
20
22
  return new Promise((resolve, reject) => {
21
23
  this.sender.send(request)
@@ -27,15 +29,6 @@ class Client {
27
29
  })
28
30
  .catch(reject);
29
31
  });
30
-
31
- function buildRequestParams(lookup) {
32
- return {
33
- html: lookup.html,
34
- aggressive: lookup.aggressive,
35
- addr_line_breaks: lookup.addressesHaveLineBreaks,
36
- addr_per_line: lookup.addressesPerLine,
37
- };
38
- }
39
32
  }
40
33
  }
41
34
 
@@ -13,6 +13,21 @@ module.exports = {
13
13
  "format": "format",
14
14
  "candidates": "maxCandidates",
15
15
  },
16
+ usAutocompletePro: {
17
+ search: "search",
18
+ selected: "selected",
19
+ max_results: "maxResults",
20
+ include_only_cities: "includeOnlyCities",
21
+ include_only_states: "includeOnlyStates",
22
+ include_only_zip_codes: "includeOnlyZIPCodes",
23
+ exclude_states: "excludeStates",
24
+ prefer_cities: "preferCities",
25
+ prefer_states: "preferStates",
26
+ prefer_zip_codes: "preferZIPCodes",
27
+ prefer_ratio: "preferRatio",
28
+ prefer_geolocation: "preferGeolocation",
29
+ source: "source",
30
+ },
16
31
  usZipcode: {
17
32
  "city": "city",
18
33
  "state": "state",
@@ -32,9 +47,23 @@ module.exports = {
32
47
  "geocode": "geocode",
33
48
  "language": "language",
34
49
  },
50
+ internationalAddressAutocomplete: {
51
+ search: "search",
52
+ country: "country",
53
+ max_results: "maxResults",
54
+ include_only_administrative_area: "includeOnlyAdministrativeArea",
55
+ include_only_locality: "includeOnlyLocality",
56
+ include_only_postal_code: "includeOnlyPostalCode",
57
+ },
35
58
  usReverseGeo: {
36
59
  "latitude": "latitude",
37
60
  "longitude": "longitude",
38
61
  "source": "source"
62
+ },
63
+ usExtract: {
64
+ html: "html",
65
+ aggressive: "aggressive",
66
+ addr_line_breaks: "addressesHaveLineBreaks",
67
+ addr_per_line: "addressesPerLine",
39
68
  }
40
69
  };
@@ -14,9 +14,6 @@ describe("An International Address Autocomplete Client", function () {
14
14
  let search = "(";
15
15
  let lookup = new Lookup({search});
16
16
  let expectedParameters = {
17
- country: undefined,
18
- include_only_locality: undefined,
19
- include_only_postal_code: undefined,
20
17
  max_results: 5,
21
18
  search: "(",
22
19
  };
@@ -35,8 +32,6 @@ describe("An International Address Autocomplete Client", function () {
35
32
  let expectedParameters = {
36
33
  country: "Russia",
37
34
  max_results: 5,
38
- include_only_locality: undefined,
39
- include_only_postal_code: undefined,
40
35
  search: search,
41
36
  };
42
37
 
@@ -52,10 +47,7 @@ describe("An International Address Autocomplete Client", function () {
52
47
  lookup.search = search;
53
48
  lookup.maxResults = 10;
54
49
  let expectedParameters = {
55
- country: undefined,
56
50
  max_results: 10,
57
- include_only_locality: undefined,
58
- include_only_postal_code: undefined,
59
51
  search: search,
60
52
  };
61
53
 
@@ -14,19 +14,14 @@ describe("A US Autocomplete Pro Client", function () {
14
14
  let search = '(>")>#';
15
15
  let lookup = new Lookup(search);
16
16
  let expectedParameters = {
17
+ exclude_states: "",
18
+ include_only_cities: "",
19
+ include_only_states: "",
20
+ include_only_zip_codes: "",
21
+ prefer_cities: "",
22
+ prefer_states: "",
23
+ prefer_zip_codes: "",
17
24
  search: search,
18
- selected: undefined,
19
- max_results: undefined,
20
- include_only_cities: undefined,
21
- include_only_states: undefined,
22
- include_only_zip_codes: undefined,
23
- exclude_states: undefined,
24
- prefer_cities: undefined,
25
- prefer_states: undefined,
26
- prefer_zip_codes: undefined,
27
- prefer_ratio: undefined,
28
- prefer_geolocation: undefined,
29
- source: undefined,
30
25
  };
31
26
 
32
27
  client.send(lookup);