smartystreets-javascript-sdk 5.1.0 → 5.1.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.
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
let client = clientBuilder.buildUsEnrichmentClient();
|
|
19
|
+
console.log(client);
|
|
20
|
+
|
|
21
|
+
// Documentation for input fields can be found at:
|
|
22
|
+
// https://www.smarty.com/docs/us-street-api#input-fields
|
|
23
|
+
|
|
24
|
+
let lookup = new Lookup("7");
|
|
25
|
+
|
|
26
|
+
handleResponse(lookup).then();
|
|
27
|
+
|
|
28
|
+
function handleSuccess(response) {
|
|
29
|
+
response.lookups.map(lookup => console.log(lookup.result));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function handleError(response) {
|
|
33
|
+
console.log(response);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function handleResponse(lookup) {
|
|
37
|
+
try {
|
|
38
|
+
const result = await client.sendPrincipal(lookup);
|
|
39
|
+
handleSuccess(result);
|
|
40
|
+
} catch(err) {
|
|
41
|
+
handleError(err);
|
|
42
|
+
}
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smartystreets-javascript-sdk",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.1",
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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);
|