smartystreets-javascript-sdk 5.1.0 → 5.1.2

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.
@@ -15,7 +15,8 @@ const credentials = new SmartyCore.SharedCredentials(key);
15
15
  // can be found on the Subscription page of the account dashboard.
16
16
  // https://www.smarty.com/docs/cloud/licensing
17
17
  const clientBuilder = new SmartyCore.ClientBuilder(credentials).withLicenses(["international-autocomplete-v2-cloud"])
18
- // .withBaseUrl("");
18
+ // .withBaseUrl("YOUR URL") // withBaseUrl() should be used if you are self-hosting the Smarty API
19
+
19
20
  const client = clientBuilder.buildInternationalAddressAutocompleteClient();
20
21
 
21
22
  // Documentation for input fields can be found at:
@@ -15,6 +15,8 @@ const credentials = new SmartyCore.SharedCredentials(key);
15
15
  // can be found on the Subscription page of the account dashboard.
16
16
  // https://www.smarty.com/docs/cloud/licensing
17
17
  let clientBuilder = new SmartyCore.ClientBuilder(credentials).withLicenses(["international-global-plus-cloud"]);
18
+ // .withBaseUrl("YOUR URL") // withBaseUrl() should be used if you are self-hosting the Smarty API
19
+
18
20
  let client = clientBuilder.buildInternationalStreetClient();
19
21
 
20
22
  // Documentation for input fields can be found at:
@@ -15,7 +15,8 @@ const credentials = new SmartyCore.SharedCredentials(key);
15
15
  // can be found on the Subscription page of the account dashboard.
16
16
  // https://www.smarty.com/docs/cloud/licensing
17
17
  let clientBuilder = new SmartyCore.ClientBuilder(credentials).withLicenses(["us-autocomplete-pro-cloud"]);
18
- // .withBaseUrl("");
18
+ // .withBaseUrl("YOUR URL") // withBaseUrl() should be used if you are self-hosting the Smarty API
19
+
19
20
  let client = clientBuilder.buildUsAutocompleteProClient();
20
21
 
21
22
  // Documentation for input fields can be found at:
@@ -0,0 +1,36 @@
1
+ const SmartySDK = require("smartystreets-javascript-sdk");
2
+ const SmartyCore = SmartySDK.core;
3
+ const Lookup = SmartySDK.usEnrichment.Lookup;
4
+
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:
11
+ let key = process.env.SMARTY_EMBEDDED_KEY;
12
+ const credentials = new SmartyCore.SharedCredentials(key);
13
+
14
+ // The appropriate license values to be used for your subscriptions
15
+ // can be found on the Subscription page of the account dashboard.
16
+ // https://www.smarty.com/docs/cloud/licensing
17
+ let clientBuilder = new SmartyCore.ClientBuilder(credentials).withLicenses(["us-property-data-principal-cloud"]);
18
+ // .withBaseUrl("YOUR URL") // withBaseUrl() should be used if you are self-hosting the Smarty API
19
+
20
+ let client = clientBuilder.buildUsEnrichmentClient();
21
+
22
+ // Documentation for input fields can be found at:
23
+ // https://www.smarty.com/docs/us-street-api#input-fields
24
+
25
+ let lookup = new Lookup("334968275");
26
+
27
+ handleResponse(lookup).then();
28
+
29
+ async function handleResponse(lookup) {
30
+ try {
31
+ const result = await client.sendPrincipal(lookup);
32
+ console.log(result.response);
33
+ } catch (err) {
34
+ console.log(err);
35
+ }
36
+ }
@@ -12,7 +12,8 @@ let key = process.env.SMARTY_EMBEDDED_KEY;
12
12
  const credentials = new SmartyCore.SharedCredentials(key);
13
13
 
14
14
  let clientBuilder = new SmartyCore.ClientBuilder(credentials);
15
- // .withBaseUrl("");
15
+ // .withBaseUrl("YOUR URL") // withBaseUrl() should be used if you are self-hosting the Smarty API
16
+
16
17
  let client = clientBuilder.buildUsExtractClient();
17
18
 
18
19
  // Documentation for input fields can be found at:
@@ -15,7 +15,7 @@ const credentials = new SmartyCore.SharedCredentials(key);
15
15
  // can be found on the Subscription page of the account dashboard.
16
16
  // https://www.smarty.com/docs/cloud/licensing
17
17
  let clientBuilder = new SmartyCore.ClientBuilder(credentials).withLicenses(["us-reverse-geocoding-cloud"]);
18
- // .withBaseUrl("");
18
+ // .withBaseUrl("YOUR URL") // withBaseUrl() should be used if you are self-hosting the Smarty API
19
19
  let client = clientBuilder.buildUsReverseGeoClient();
20
20
 
21
21
  let lookup1 = new Lookup(40.27644, -111.65747, "all");
@@ -14,7 +14,9 @@ const credentials = new SmartyCore.SharedCredentials(key);
14
14
  // The appropriate license values to be used for your subscriptions
15
15
  // can be found on the Subscription page of the account dashboard.
16
16
  // https://www.smarty.com/docs/cloud/licensing
17
- let clientBuilder = new SmartyCore.ClientBuilder(credentials).withBaseUrl("YOUR URL").withLicenses(["us-rooftop-geocoding-cloud"]);
17
+ let clientBuilder = new SmartyCore.ClientBuilder(credentials).withLicenses(["us-rooftop-geocoding-cloud"]);
18
+ // .withBaseUrl("YOUR URL") // withBaseUrl() should be used if you are self-hosting the Smarty API
19
+
18
20
  let client = clientBuilder.buildUsStreetApiClient();
19
21
 
20
22
  // Documentation for input fields can be found at:
@@ -12,7 +12,8 @@ let key = process.env.SMARTY_EMBEDDED_KEY;
12
12
  const credentials = new SmartyCore.SharedCredentials(key);
13
13
 
14
14
  let clientBuilder = new SmartyCore.ClientBuilder(credentials);
15
- // .withBaseUrl("");
15
+ // .withBaseUrl("YOUR URL") // withBaseUrl() should be used if you are self-hosting the Smarty API
16
+
16
17
  let client = clientBuilder.buildUsZipcodeClient();
17
18
 
18
19
  // Documentation for input fields can be found at:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smartystreets-javascript-sdk",
3
- "version": "5.1.0",
3
+ "version": "5.1.2",
4
4
  "description": "Quick and easy Smarty address validation.",
5
5
  "keywords": [
6
6
  "smarty",
@@ -37,6 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "axios": "^1.6.2",
40
- "axios-retry": "4.0.0"
40
+ "axios-retry": "4.0.0",
41
+ "smartystreets-javascript-sdk": "^5.1.1"
41
42
  }
42
43
  }
@@ -14,11 +14,7 @@ class Client {
14
14
  let request = new Request();
15
15
  request.parameters = buildInputData(lookup, keyTranslationFormat);
16
16
 
17
- if (lookup.smartyKey) {
18
- request.baseUrlParam = lookup.smartyKey;
19
- }
20
-
21
- request.baseUrlParam = "property/principal";
17
+ request.baseUrlParam = lookup.smartyKey + "/property/principal";
22
18
 
23
19
  return new Promise((resolve, reject) => {
24
20
  this.sender.send(request)
@@ -38,11 +34,7 @@ class Client {
38
34
  let request = new Request();
39
35
  request.parameters = buildInputData(lookup, keyTranslationFormat);
40
36
 
41
- if (lookup.smartyKey) {
42
- request.baseUrlParam = lookup.smartyKey;
43
- }
44
-
45
- request.baseUrlParam = "property/financial";
37
+ request.baseUrlParam = lookup.smartyKey + "/property/financial";
46
38
 
47
39
  return new Promise((resolve, reject) => {
48
40
  this.sender.send(request)
@@ -62,11 +54,7 @@ class Client {
62
54
  let request = new Request();
63
55
  request.parameters = buildInputData(lookup, keyTranslationFormat);
64
56
 
65
- if (lookup.smartyKey) {
66
- request.baseUrlParam = lookup.smartyKey;
67
- }
68
-
69
- request.baseUrlParam = "geo-reference";
57
+ request.baseUrlParam = lookup.smartyKey + "/geo-reference";
70
58
 
71
59
  return new Promise((resolve, reject) => {
72
60
  this.sender.send(request)
@@ -6,12 +6,14 @@ module.exports = {
6
6
  let request = {
7
7
  payload: undefined,
8
8
  parameters: undefined,
9
+ baseUrlParam: undefined,
9
10
  };
10
11
  this.request = request;
11
12
 
12
13
  this.send = function (clientRequest) {
13
14
  request.payload = clientRequest.payload;
14
15
  request.parameters = clientRequest.parameters;
16
+ request.baseUrlParam = clientRequest.baseUrlParam;
15
17
  }
16
18
  },
17
19
  MockSenderWithResponse: function (expectedPayload, expectedError) {
@@ -8,6 +8,39 @@ const MockSenderWithResponse = require("../fixtures/mock_senders").MockSenderWit
8
8
  const {Response, FinancialResponse, GeoResponse} = require("../../src/us_enrichment/Response");
9
9
 
10
10
  describe("A US Enrichment Client", function () {
11
+ it("composes principal url path properly", function () {
12
+ let mockSender = new MockSender();
13
+ let client = new Client(mockSender);
14
+ let smartyKey = "0";
15
+ let lookup = new Lookup(smartyKey);
16
+
17
+ client.sendPrincipal(lookup);
18
+
19
+ expect(mockSender.request.baseUrlParam).to.deep.equal("0/property/principal");
20
+ })
21
+
22
+ it("composes financial url path properly", function () {
23
+ let mockSender = new MockSender();
24
+ let client = new Client(mockSender);
25
+ let smartyKey = "0";
26
+ let lookup = new Lookup(smartyKey);
27
+
28
+ client.sendFinancial(lookup);
29
+
30
+ expect(mockSender.request.baseUrlParam).to.deep.equal("0/property/financial");
31
+ })
32
+
33
+ it("composes geo url path properly", function () {
34
+ let mockSender = new MockSender();
35
+ let client = new Client(mockSender);
36
+ let smartyKey = "0";
37
+ let lookup = new Lookup(smartyKey);
38
+
39
+ client.sendGeo(lookup);
40
+
41
+ expect(mockSender.request.baseUrlParam).to.deep.equal("0/geo-reference");
42
+ })
43
+
11
44
  it("correctly builds parameters for a smartyKey only principal lookup.", function () {
12
45
  let mockSender = new MockSender();
13
46
  let client = new Client(mockSender);