smartystreets-javascript-sdk 1.11.3 → 1.11.7

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.
@@ -0,0 +1,46 @@
1
+ const SmartyStreetsSDK = require("smartystreets-javascript-sdk");
2
+ const SmartyStreetsCore = SmartyStreetsSDK.core;
3
+ const Lookup = SmartyStreetsSDK.internationalAddressAutocomplete.Lookup;
4
+
5
+ // US Autocomplete Pro only supports using Website Keys
6
+ let key = process.env.SMARTY_WEBSITE_KEY;
7
+ const credentials = new SmartyStreetsCore.SharedCredentials(key);
8
+
9
+ // The appropriate license values to be used for your subscriptions
10
+ // can be found on the Subscription page of the account dashboard.
11
+ // https://www.smartystreets.com/docs/cloud/licensing
12
+ let clientBuilder = new SmartyStreetsCore.ClientBuilder(credentials).withLicenses(["international-autocomplete-cloud"])
13
+ // .withBaseUrl("");
14
+ let client = clientBuilder.buildInternationalAddressAutocompleteClient();
15
+
16
+ // Documentation for input fields can be found at:
17
+ //www.smartystreets.com/docs/cloud/international-address-autocomplete-api#pro-http-request-input-fields
18
+
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");
31
+
32
+
33
+ function logSuggestions(response, message) {
34
+ console.log(message);
35
+ console.log(response.result);
36
+ console.log("*********************");
37
+ }
38
+
39
+ async function handleRequest(lookup, lookupType) {
40
+ try {
41
+ const results = await client.send(lookup);
42
+ logSuggestions(results, lookupType);
43
+ } catch(err) {
44
+ console.log(err)
45
+ }
46
+ }
@@ -33,12 +33,8 @@ lookup2.administrativeArea = "SP";
33
33
  lookup2.country = "Brazil";
34
34
  lookup2.postalCode = "02516-050";
35
35
 
36
- client.send(lookup1)
37
- .then(displayResult)
38
- .catch(handleError);
39
- client.send(lookup2)
40
- .then(displayResult)
41
- .catch(handleError);
36
+ await handleRequest(lookup1)
37
+ await handleRequest(lookup2)
42
38
 
43
39
  function displayResult(result) {
44
40
  console.log(result.result[0].components);
@@ -46,4 +42,13 @@ function displayResult(result) {
46
42
 
47
43
  function handleError(error) {
48
44
  console.log("ERROR:", error);
45
+ }
46
+
47
+ async function handleRequest(lookup) {
48
+ try {
49
+ const result = await client.send(lookup);
50
+ displayResult(result);
51
+ } catch(err) {
52
+ handleError(err);
53
+ }
49
54
  }
@@ -16,14 +16,10 @@ let client = clientBuilder.buildUsAutocompleteProClient();
16
16
  // Documentation for input fields can be found at:
17
17
  // https://smartystreets.com/docs/cloud/us-autocomplete-api#pro-http-request-input-fields
18
18
 
19
-
20
19
  // *** Simple Lookup ***
21
20
  let lookup = new Lookup("4770 Lincoln");
22
21
 
23
- client.send(lookup)
24
- .then(function(results) { logSuggestions(results, "Simple Lookup") })
25
- .catch(console.log);
26
-
22
+ await handleRequest(lookup, "Simple Lookup");
27
23
 
28
24
  // *** Using Filter and Prefer ***
29
25
  lookup = new Lookup("4770 Lincoln");
@@ -34,20 +30,14 @@ lookup.preferStates = ["IL"];
34
30
  lookup.preferRatio = 33;
35
31
  lookup.source = "all";
36
32
 
37
- client.send(lookup)
38
- .then(function(results) { logSuggestions(results, "Using Filter and Prefer") })
39
- .catch(console.log);
40
-
33
+ await handleRequest(lookup, "Using Filter and Prefer");
41
34
 
42
35
  // *** Using 'selected' to Expand Secondaries ***
43
36
  lookup = new Lookup("4770 Lincoln");
44
37
 
45
38
  lookup.selected = "4770 N Lincoln Ave Ste 2 (3) Chicago, IL 60625";
46
39
 
47
- client.send(lookup)
48
- .then(function(results) { logSuggestions(results, "Using 'selected' to Expand Secondaries") })
49
- .catch(console.log);
50
-
40
+ await handleRequest(lookup, "Using 'selected' to Expand Secondaries")
51
41
 
52
42
  // ************************************************
53
43
 
@@ -55,4 +45,13 @@ function logSuggestions(response, message) {
55
45
  console.log(message);
56
46
  console.log(response.result);
57
47
  console.log("*********************");
48
+ }
49
+
50
+ async function handleRequest(lookup, lookupType) {
51
+ try {
52
+ const results = await client.send(lookup);
53
+ logSuggestions(results, lookupType);
54
+ } catch(err) {
55
+ console.log(err)
56
+ }
58
57
  }
@@ -23,10 +23,17 @@ lookup.aggressive = true;
23
23
  lookup.addressesHaveLineBreaks = false;
24
24
  lookup.addressesPerLine = 1;
25
25
 
26
- client.send(lookup)
27
- .then(logResult)
28
- .catch(console.log);
26
+ await handleRequest(lookup);
29
27
 
30
28
  function logResult(response) {
31
29
  console.log(response.result);
30
+ }
31
+
32
+ async function handleRequest(lookup) {
33
+ try {
34
+ const response = await client.send(lookup);
35
+ logResult(response);
36
+ } catch(err) {
37
+ console.log(err);
38
+ }
32
39
  }
@@ -20,9 +20,7 @@ let client = clientBuilder.buildUsReverseGeoClient();
20
20
 
21
21
  let lookup1 = new Lookup(40.27644, -111.65747);
22
22
 
23
- client.send(lookup1)
24
- .then(displayResult)
25
- .catch(handleError);
23
+ await handleResponse(lookup1);
26
24
 
27
25
  function displayResult(result) {
28
26
  console.log(result.result[0].address);
@@ -31,3 +29,12 @@ function displayResult(result) {
31
29
  function handleError(error) {
32
30
  console.log("ERROR:", error);
33
31
  }
32
+
33
+ async function handleResponse(lookup) {
34
+ try {
35
+ const result = await client.send(lookup);
36
+ displayResult(result);
37
+ } catch(err) {
38
+ handleError(err);
39
+ }
40
+ }
@@ -51,9 +51,7 @@ batch.add(lookup1);
51
51
  batch.add(lookup2);
52
52
  batch.add(lookup3);
53
53
 
54
- client.send(batch)
55
- .then(handleSuccess)
56
- .catch(handleError);
54
+ await handleResponse(batch);
57
55
 
58
56
  function handleSuccess(response) {
59
57
  response.lookups.map(lookup => console.log(lookup.result));
@@ -61,4 +59,13 @@ function handleSuccess(response) {
61
59
 
62
60
  function handleError(response) {
63
61
  console.log(response);
62
+ }
63
+
64
+ async function handleResponse(lookup) {
65
+ try {
66
+ const result = await client.send(lookup);
67
+ handleSuccess(result);
68
+ } catch(err) {
69
+ handleError(err);
70
+ }
64
71
  }
@@ -37,13 +37,20 @@ batch.add(lookup1);
37
37
  batch.add(lookup2);
38
38
  batch.add(lookup3);
39
39
 
40
- client.send(batch)
41
- .then(viewResults)
42
- .catch(console.log);
40
+ await handleResponse(batch);
43
41
 
44
42
  function viewResults(response) {
45
43
  response.lookups.map(lookup => lookup.result.map(candidate => {
46
44
  candidate.cities.map(city => console.log(city.city));
47
45
  // candidate.zipcodes.map(zipcode => console.log(zipcode.zipcode));
48
46
  }));
47
+ }
48
+
49
+ async function handleResponse(lookup) {
50
+ try {
51
+ const result = await client.send(lookup);
52
+ viewResults(result);
53
+ } catch(err) {
54
+ console.log(err);
55
+ }
49
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smartystreets-javascript-sdk",
3
- "version": "1.11.3",
3
+ "version": "1.11.7",
4
4
  "description": "Quick and easy SmartyStreets address validation.",
5
5
  "keywords": [
6
6
  "smartystreets",
@@ -15,6 +15,9 @@ class Client {
15
15
  request.parameters = {
16
16
  search: lookup.search,
17
17
  country: lookup.country,
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,
18
21
  };
19
22
 
20
23
  return new Promise((resolve, reject) => {
@@ -17,6 +17,9 @@ describe("An International Address Autocomplete Client", function () {
17
17
  let lookup = new Lookup(search);
18
18
  let expectedParameters = {
19
19
  search: search,
20
+ include_only_administrative_area: "",
21
+ include_only_locality: "",
22
+ include_only_postal_code: "",
20
23
  country: "United States",
21
24
  };
22
25
 
@@ -32,8 +35,11 @@ describe("An International Address Autocomplete Client", function () {
32
35
  lookup.search = search;
33
36
  lookup.country = "Russia";
34
37
  let expectedParameters = {
35
- search: search,
36
38
  country: "Russia",
39
+ include_only_administrative_area: "",
40
+ include_only_locality: "",
41
+ include_only_postal_code: "",
42
+ search: search,
37
43
  };
38
44
 
39
45
  client.send(lookup);