smartystreets-javascript-sdk 5.0.1 → 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.
- package/examples/us_enrichment.js +43 -0
- package/index.js +4 -0
- package/package.json +3 -2
- package/src/ClientBuilder.js +6 -0
- package/src/us_enrichment/Client.js +72 -0
- package/src/us_enrichment/Lookup.js +13 -0
- package/src/us_enrichment/Response.js +559 -0
- package/src/util/apiToSDKKeyMap.js +6 -0
- package/src/util/buildClients.js +5 -0
- package/tests/fixtures/mock_senders.js +2 -0
- package/tests/us_enrichment/test_Client.js +271 -0
- package/tests/us_enrichment/test_Lookup.js +22 -0
- package/tests/us_enrichment/test_Response.js +739 -0
|
@@ -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/index.js
CHANGED
|
@@ -34,4 +34,8 @@ module.exports = {
|
|
|
34
34
|
Lookup: require("./src/international_address_autocomplete/Lookup"),
|
|
35
35
|
Suggestion: require("./src/international_address_autocomplete/Suggestion"),
|
|
36
36
|
},
|
|
37
|
+
usEnrichment: {
|
|
38
|
+
Lookup: require("./src/us_enrichment/Lookup"),
|
|
39
|
+
Response: require("./src/us_enrichment/Response"),
|
|
40
|
+
},
|
|
37
41
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smartystreets-javascript-sdk",
|
|
3
|
-
"version": "5.
|
|
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
|
}
|
package/src/ClientBuilder.js
CHANGED
|
@@ -19,6 +19,7 @@ const UsExtractClient = require("./us_extract/Client");
|
|
|
19
19
|
const InternationalStreetClient = require("./international_street/Client");
|
|
20
20
|
const UsReverseGeoClient = require("./us_reverse_geo/Client");
|
|
21
21
|
const InternationalAddressAutocompleteClient = require("./international_address_autocomplete/Client");
|
|
22
|
+
const UsEnrichmentClient = require("./us_enrichment/Client");
|
|
22
23
|
|
|
23
24
|
const INTERNATIONAL_STREET_API_URI = "https://international-street.api.smarty.com/verify";
|
|
24
25
|
const US_AUTOCOMPLETE_PRO_API_URL = "https://us-autocomplete-pro.api.smarty.com/lookup";
|
|
@@ -27,6 +28,7 @@ const US_STREET_API_URL = "https://us-street.api.smarty.com/street-address";
|
|
|
27
28
|
const US_ZIP_CODE_API_URL = "https://us-zipcode.api.smarty.com/lookup";
|
|
28
29
|
const US_REVERSE_GEO_API_URL = "https://us-reverse-geo.api.smarty.com/lookup";
|
|
29
30
|
const INTERNATIONAL_ADDRESS_AUTOCOMPLETE_API_URL = "https://international-autocomplete.api.smarty.com/v2/lookup";
|
|
31
|
+
const US_ENRICHMENT_API_URL = "https://us-enrichment.api.smarty.com/lookup";
|
|
30
32
|
|
|
31
33
|
/**
|
|
32
34
|
* The ClientBuilder class helps you build a client object for one of the supported Smarty APIs.<br>
|
|
@@ -201,6 +203,10 @@ class ClientBuilder {
|
|
|
201
203
|
buildInternationalAddressAutocompleteClient() {
|
|
202
204
|
return this.buildClient(INTERNATIONAL_ADDRESS_AUTOCOMPLETE_API_URL, InternationalAddressAutocompleteClient);
|
|
203
205
|
}
|
|
206
|
+
|
|
207
|
+
buildUsEnrichmentClient() {
|
|
208
|
+
return this.buildClient(US_ENRICHMENT_API_URL, UsEnrichmentClient);
|
|
209
|
+
}
|
|
204
210
|
}
|
|
205
211
|
|
|
206
212
|
module.exports = ClientBuilder;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const Errors = require("../Errors");
|
|
2
|
+
const Request = require("../Request");
|
|
3
|
+
const buildInputData = require("../util/buildInputData");
|
|
4
|
+
const {usEnrichment: keyTranslationFormat} = require("../util/apiToSDKKeyMap");
|
|
5
|
+
|
|
6
|
+
class Client {
|
|
7
|
+
constructor(sender) {
|
|
8
|
+
this.sender = sender;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
sendPrincipal(lookup) {
|
|
12
|
+
if (typeof lookup === "undefined") throw new Errors.UndefinedLookupError();
|
|
13
|
+
|
|
14
|
+
let request = new Request();
|
|
15
|
+
request.parameters = buildInputData(lookup, keyTranslationFormat);
|
|
16
|
+
|
|
17
|
+
request.baseUrlParam = lookup.smartyKey + "/property/principal";
|
|
18
|
+
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
this.sender.send(request)
|
|
21
|
+
.then(response => {
|
|
22
|
+
if (response.error) reject(response.error);
|
|
23
|
+
|
|
24
|
+
lookup.response = response.payload;
|
|
25
|
+
resolve(lookup);
|
|
26
|
+
})
|
|
27
|
+
.catch(reject);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
sendFinancial(lookup) {
|
|
32
|
+
if (typeof lookup === "undefined") throw new Errors.UndefinedLookupError();
|
|
33
|
+
|
|
34
|
+
let request = new Request();
|
|
35
|
+
request.parameters = buildInputData(lookup, keyTranslationFormat);
|
|
36
|
+
|
|
37
|
+
request.baseUrlParam = lookup.smartyKey + "/property/financial";
|
|
38
|
+
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
this.sender.send(request)
|
|
41
|
+
.then(response => {
|
|
42
|
+
if (response.error) reject(response.error);
|
|
43
|
+
|
|
44
|
+
lookup.response = response.payload;
|
|
45
|
+
resolve(lookup);
|
|
46
|
+
})
|
|
47
|
+
.catch(reject);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
sendGeo(lookup) {
|
|
52
|
+
if (typeof lookup === "undefined") throw new Errors.UndefinedLookupError();
|
|
53
|
+
|
|
54
|
+
let request = new Request();
|
|
55
|
+
request.parameters = buildInputData(lookup, keyTranslationFormat);
|
|
56
|
+
|
|
57
|
+
request.baseUrlParam = lookup.smartyKey + "/geo-reference";
|
|
58
|
+
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
this.sender.send(request)
|
|
61
|
+
.then(response => {
|
|
62
|
+
if (response.error) reject(response.error);
|
|
63
|
+
|
|
64
|
+
lookup.response = response.payload;
|
|
65
|
+
resolve(lookup);
|
|
66
|
+
})
|
|
67
|
+
.catch(reject);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
module.exports = Client;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
class Lookup {
|
|
2
|
+
constructor(smartyKey, include, exclude, dataset, dataSubset) {
|
|
3
|
+
this.smartyKey = smartyKey;
|
|
4
|
+
this.include = include;
|
|
5
|
+
this.exclude = exclude;
|
|
6
|
+
this.dataset = dataset;
|
|
7
|
+
this.dataSubset = dataSubset;
|
|
8
|
+
|
|
9
|
+
this.response = {};
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = Lookup;
|