smartystreets-javascript-sdk 3.3.0 → 4.0.0

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.
@@ -13,7 +13,7 @@ jobs:
13
13
 
14
14
  strategy:
15
15
  matrix:
16
- node-version: [10.x, 12.x, 14.x, 16.x, 18.x]
16
+ node-version: [14.x, 16.x, 18.x, 20.x]
17
17
 
18
18
  steps:
19
19
  - uses: actions/checkout@v2
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 -M --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 -M
15
15
  git push origin --tags
16
16
 
17
17
  upload:
@@ -2,38 +2,44 @@ const SmartySDK = require("smartystreets-javascript-sdk");
2
2
  const SmartyCore = SmartySDK.core;
3
3
  const Lookup = SmartySDK.internationalAddressAutocomplete.Lookup;
4
4
 
5
- // US Autocomplete Pro only supports using Embedded Keys
6
- let key = process.env.SMARTY_EMBEDDED_KEY;
5
+ // International Autocomplete only supports using Embedded Keys
6
+ const key = process.env.SMARTY_EMBEDDED_KEY;
7
7
  const credentials = new SmartyCore.SharedCredentials(key);
8
8
 
9
9
  // The appropriate license values to be used for your subscriptions
10
10
  // can be found on the Subscription page of the account dashboard.
11
11
  // https://www.smarty.com/docs/cloud/licensing
12
- let clientBuilder = new SmartyCore.ClientBuilder(credentials).withLicenses(["international-autocomplete-cloud"])
12
+ const clientBuilder = new SmartyCore.ClientBuilder(credentials).withLicenses(["international-autocomplete-v2-cloud"])
13
13
  // .withBaseUrl("");
14
- let client = clientBuilder.buildInternationalAddressAutocompleteClient();
14
+ const client = clientBuilder.buildInternationalAddressAutocompleteClient();
15
15
 
16
16
  // Documentation for input fields can be found at:
17
- //www.smarty.com/docs/cloud/international-address-autocomplete-api#pro-http-request-input-fields
17
+ // www.smarty.com/docs/cloud/international-address-autocomplete-api#pro-http-request-input-fields
18
+ const country = "CAN";
18
19
 
19
- let lookup = new Lookup("Ave", "CAN");
20
- await handleRequest(lookup, "Simple Request");
21
-
22
- // *** Using Filter and Prefer ***
23
- lookup = new Lookup("Ave", "CAN");
24
-
25
- lookup.maxResults = 10;
26
- // lookup.include_only_administrative_area = "";
27
- lookup.include_only_locality = "Sherwood Park";
28
- // lookup.include_only_postal_code = "";
29
-
30
- await handleRequest(lookup, "Using Filter and Prefer");
20
+ const summaryLookup = new Lookup({search: "123 Anson", country});
21
+ await handleRequest(summaryLookup, "Response of summary results");
31
22
 
23
+ const detailedLookup = new Lookup({addressId: summaryLookup.result[0].addressId, country});
24
+ await handleRequest(detailedLookup, "Response using an address ID to get detailed results");
32
25
 
33
26
  function logSuggestions(response, message) {
34
- console.log(message);
35
- console.log(response.result);
36
- console.log("*********************");
27
+ console.log("*** " + message + " ***");
28
+
29
+ response.result.forEach(suggestion => {
30
+ if (suggestion.addressText) {
31
+ console.log("Entries: ", suggestion.entries);
32
+ console.log("Address Text: ", suggestion.addressText);
33
+ console.log("Address ID: ", suggestion.addressId);
34
+ } else {
35
+ console.log("Street: ", suggestion.street);
36
+ console.log("Locality: ", suggestion.locality);
37
+ console.log("Administrative Area: ", suggestion.administrativeArea);
38
+ console.log("Postal Code: ", suggestion.postalCode);
39
+ console.log("Country: ", suggestion.countryIso3);
40
+ }
41
+ });
42
+ console.log("\n");
37
43
  }
38
44
 
39
45
  async function handleRequest(lookup, lookupType) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smartystreets-javascript-sdk",
3
- "version": "3.3.0",
3
+ "version": "4.0.0",
4
4
  "description": "Quick and easy Smarty address validation.",
5
5
  "keywords": [
6
6
  "smarty",
@@ -6,7 +6,7 @@ class BaseUrlSender {
6
6
 
7
7
  send(request) {
8
8
  return new Promise((resolve, reject) => {
9
- request.baseUrl = this.urlOverride;
9
+ request.baseUrl = `${this.urlOverride}${request.baseUrlParams ? `/${request.baseUrlParams}` : ""}`;
10
10
 
11
11
  this.sender.send(request)
12
12
  .then(resolve)
@@ -28,7 +28,7 @@ const US_EXTRACT_API_URL = "https://us-extract.api.smarty.com/";
28
28
  const US_STREET_API_URL = "https://us-street.api.smarty.com/street-address";
29
29
  const US_ZIP_CODE_API_URL = "https://us-zipcode.api.smarty.com/lookup";
30
30
  const US_REVERSE_GEO_API_URL = "https://us-reverse-geo.api.smarty.com/lookup";
31
- const INTERNATIONAL_ADDRESS_AUTOCOMPLETE_API_URL = "https://international-autocomplete.api.smarty.com/lookup";
31
+ const INTERNATIONAL_ADDRESS_AUTOCOMPLETE_API_URL = "https://international-autocomplete.api.smarty.com/v2/lookup";
32
32
 
33
33
  /**
34
34
  * The ClientBuilder class helps you build a client object for one of the supported Smarty APIs.<br>
package/src/Request.js CHANGED
@@ -1,6 +1,7 @@
1
1
  class Request {
2
2
  constructor(payload) {
3
3
  this.baseUrl = "";
4
+ this.baseUrlParams = "";
4
5
  this.payload = payload;
5
6
  this.headers = {
6
7
  "Content-Type": "application/json; charset=utf-8",
@@ -14,12 +14,15 @@ class Client {
14
14
  request.parameters = {
15
15
  search: lookup.search,
16
16
  country: lookup.country,
17
- max_results: lookup.max_results,
18
- include_only_administrative_area: lookup.include_only_administrative_area,
19
- include_only_locality: lookup.include_only_locality,
20
- include_only_postal_code: lookup.include_only_postal_code,
17
+ max_results: lookup.maxResults,
18
+ include_only_locality: lookup.includeOnlyLocality,
19
+ include_only_postal_code: lookup.includeOnlyPostalCode,
21
20
  };
22
21
 
22
+ if (lookup.addressId) {
23
+ request.baseUrlParams = lookup.addressId;
24
+ }
25
+
23
26
  return new Promise((resolve, reject) => {
24
27
  this.sender.send(request)
25
28
  .then(response => {
@@ -1,13 +1,13 @@
1
1
  class Lookup {
2
- constructor(search = "", country = "United States", max_results = undefined, include_only_administrative_area = "", include_only_locality = "", include_only_postal_code = "") {
2
+ constructor({search, addressId, country, maxResults = 5, includeOnlyLocality, includeOnlyPostalCode} = {}) {
3
3
  this.result = [];
4
4
 
5
5
  this.search = search;
6
+ this.addressId = addressId;
6
7
  this.country = country;
7
- this.max_results = max_results;
8
- this.include_only_administrative_area = include_only_administrative_area;
9
- this.include_only_locality = include_only_locality;
10
- this.include_only_postal_code = include_only_postal_code;
8
+ this.maxResults = maxResults;
9
+ this.includeOnlyLocality = includeOnlyLocality;
10
+ this.includeOnlyPostalCode = includeOnlyPostalCode;
11
11
  }
12
12
  }
13
13
 
@@ -5,6 +5,9 @@ class Suggestion {
5
5
  this.administrativeArea = responseData.administrative_area;
6
6
  this.postalCode = responseData.postal_code;
7
7
  this.countryIso3 = responseData.country_iso3;
8
+ this.entries = responseData.entries;
9
+ this.addressText = responseData.address_text;
10
+ this.addressId = responseData.address_id;
8
11
  }
9
12
  }
10
13
 
@@ -12,14 +12,13 @@ describe("An International Address Autocomplete Client", function () {
12
12
  let mockSender = new MockSender();
13
13
  let client = new Client(mockSender);
14
14
  let search = "(";
15
- let lookup = new Lookup(search);
15
+ let lookup = new Lookup({search});
16
16
  let expectedParameters = {
17
- search: search,
18
- max_results: undefined,
19
- include_only_administrative_area: "",
20
- include_only_locality: "",
21
- include_only_postal_code: "",
22
- country: "United States",
17
+ country: undefined,
18
+ include_only_locality: undefined,
19
+ include_only_postal_code: undefined,
20
+ max_results: 5,
21
+ search: "(",
23
22
  };
24
23
 
25
24
  client.send(lookup);
@@ -30,15 +29,14 @@ describe("An International Address Autocomplete Client", function () {
30
29
  let mockSender = new MockSender();
31
30
  let client = new Client(mockSender);
32
31
  let search = "(";
33
- let lookup = new Lookup(search);
32
+ let lookup = new Lookup({search});
34
33
  lookup.search = search;
35
34
  lookup.country = "Russia";
36
35
  let expectedParameters = {
37
36
  country: "Russia",
38
- max_results: undefined,
39
- include_only_administrative_area: "",
40
- include_only_locality: "",
41
- include_only_postal_code: "",
37
+ max_results: 5,
38
+ include_only_locality: undefined,
39
+ include_only_postal_code: undefined,
42
40
  search: search,
43
41
  };
44
42
 
@@ -50,15 +48,14 @@ describe("An International Address Autocomplete Client", function () {
50
48
  let mockSender = new MockSender();
51
49
  let client = new Client(mockSender);
52
50
  let search = "(";
53
- let lookup = new Lookup(search);
51
+ let lookup = new Lookup({search});
54
52
  lookup.search = search;
55
- lookup.max_results = 10;
53
+ lookup.maxResults = 10;
56
54
  let expectedParameters = {
57
- country: "United States",
55
+ country: undefined,
58
56
  max_results: 10,
59
- include_only_administrative_area: "",
60
- include_only_locality: "",
61
- include_only_postal_code: "",
57
+ include_only_locality: undefined,
58
+ include_only_postal_code: undefined,
62
59
  search: search,
63
60
  };
64
61
 
@@ -87,7 +84,7 @@ describe("An International Address Autocomplete Client", function () {
87
84
 
88
85
  let mockSender = new MockSenderWithResponse(responseData);
89
86
  let client = new Client(mockSender);
90
- let lookup = new Lookup("f");
87
+ let lookup = new Lookup({search: "f"});
91
88
  let expectedSuggestion = new Suggestion(responseData.candidates[0]);
92
89
 
93
90
  return client.send(lookup).then(() => {
@@ -5,45 +5,50 @@ const Lookup = require("../../src/international_address_autocomplete/Lookup");
5
5
  describe("An International Address Autocomplete lookup", function () {
6
6
  it("Can be newed up with a prefix", function () {
7
7
  const expectedPrefix = "z";
8
- let lookup = new Lookup(expectedPrefix);
8
+ let lookup = new Lookup({search: expectedPrefix});
9
9
  expect(lookup.search).to.equal(expectedPrefix);
10
10
  });
11
11
 
12
- it("Default country parameter should be United States", function () {
13
- let lookup = new Lookup("z");
14
- expect(lookup.country).to.equal("United States");
12
+ it("Set address ID", function () {
13
+ const addressId = "111";
14
+ let lookup = new Lookup({addressId});
15
+ expect(lookup.addressId).to.equal(addressId);
15
16
  });
16
17
 
17
- it("Manually set lookup to be another country", function () {
18
+ it("Set country", function () {
18
19
  const country = "Russia";
19
- const expectedPrefix = "z";
20
- let lookup = new Lookup(expectedPrefix, country);
20
+ let lookup = new Lookup({country});
21
21
  expect(lookup.country).to.equal(country);
22
22
  });
23
23
 
24
- it("Set include only administrative area param", function () {
25
- const administrativeArea = "administrative area";
26
- const expectedPrefix = "z";
27
- let lookup = new Lookup(expectedPrefix, "Utah", "test", administrativeArea);
28
- expect(lookup.include_only_administrative_area).to.equal(administrativeArea);
24
+ it("Set max results", function () {
25
+ const maxResults = 10000;
26
+ let lookup = new Lookup({maxResults});
27
+ expect(lookup.maxResults).to.equal(maxResults);
29
28
  });
30
29
 
31
- it("Set include only locality param", function () {
32
- const locality = "locality";
33
- const expectedPrefix = "z";
34
- let lookup = new Lookup(expectedPrefix, "Utah", "test", "test", locality);
35
- expect(lookup.include_only_locality).to.equal(locality);
30
+ it("Set include only include locality param", function () {
31
+ const onlyIncludeLocality = "locality";
32
+ let lookup = new Lookup({includeOnlyLocality: onlyIncludeLocality});
33
+ expect(lookup.includeOnlyLocality).to.equal(onlyIncludeLocality);
36
34
  });
37
35
 
38
- it("Set include only postal code param", function () {
39
- const postalCode = "locality";
40
- const expectedPrefix = "z";
41
- let lookup = new Lookup(expectedPrefix, "Utah", "test", "test", "test", postalCode);
42
- expect(lookup.include_only_postal_code).to.equal(postalCode);
36
+ it("Set include only include postal code param", function () {
37
+ const onlyIncludePostalCode = "post code";
38
+ let lookup = new Lookup({includeOnlyPostalCode: onlyIncludePostalCode});
39
+ expect(lookup.includeOnlyPostalCode).to.equal(onlyIncludePostalCode);
43
40
  });
44
41
 
45
42
  it("Checking defaults of params on instantiation ", function () {
46
- const defaultLookup = new Lookup("", "United States", undefined, "", "", "");
43
+ const defaultLookup = {
44
+ result: [],
45
+ search: undefined,
46
+ addressId: undefined,
47
+ country: undefined,
48
+ maxResults: 5,
49
+ includeOnlyLocality: undefined,
50
+ includeOnlyPostalCode: undefined,
51
+ };
47
52
  let lookup = new Lookup();
48
53
  expect(lookup).to.deep.equal(defaultLookup);
49
54
  });