smartystreets-javascript-sdk 5.0.0 → 5.1.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.
- package/Makefile +2 -2
- package/index.js +4 -0
- package/package.json +1 -1
- package/src/ClientBuilder.js +6 -0
- package/src/Request.js +2 -4
- package/src/us_enrichment/Client.js +84 -0
- package/src/us_enrichment/Lookup.js +13 -0
- package/src/us_enrichment/Response.js +559 -0
- package/src/us_extract/Client.js +1 -1
- package/src/util/apiToSDKKeyMap.js +6 -0
- package/src/util/buildClients.js +5 -0
- package/tests/test_ExtractExample.js +167 -0
- package/tests/us_enrichment/test_Client.js +238 -0
- package/tests/us_enrichment/test_Lookup.js +22 -0
- package/tests/us_enrichment/test_Response.js +739 -0
package/Makefile
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/make -f
|
|
2
2
|
|
|
3
|
-
VERSION := $(shell tagit -
|
|
3
|
+
VERSION := $(shell tagit -p --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 -
|
|
14
|
+
tagit -p
|
|
15
15
|
git push origin --tags
|
|
16
16
|
|
|
17
17
|
upload:
|
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
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;
|
package/src/Request.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
class Request {
|
|
2
|
-
constructor(payload) {
|
|
2
|
+
constructor(payload, headers = {"Content-Type": "application/json; charset=utf-8"}) {
|
|
3
3
|
this.baseUrl = "";
|
|
4
4
|
this.baseUrlParam = "";
|
|
5
5
|
this.payload = payload;
|
|
6
|
-
this.headers =
|
|
7
|
-
"Content-Type": "application/json; charset=utf-8",
|
|
8
|
-
};
|
|
6
|
+
this.headers = headers;
|
|
9
7
|
|
|
10
8
|
this.parameters = {};
|
|
11
9
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
if (lookup.smartyKey) {
|
|
18
|
+
request.baseUrlParam = lookup.smartyKey;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
request.baseUrlParam = "property/principal";
|
|
22
|
+
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
this.sender.send(request)
|
|
25
|
+
.then(response => {
|
|
26
|
+
if (response.error) reject(response.error);
|
|
27
|
+
|
|
28
|
+
lookup.response = response.payload;
|
|
29
|
+
resolve(lookup);
|
|
30
|
+
})
|
|
31
|
+
.catch(reject);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
sendFinancial(lookup) {
|
|
36
|
+
if (typeof lookup === "undefined") throw new Errors.UndefinedLookupError();
|
|
37
|
+
|
|
38
|
+
let request = new Request();
|
|
39
|
+
request.parameters = buildInputData(lookup, keyTranslationFormat);
|
|
40
|
+
|
|
41
|
+
if (lookup.smartyKey) {
|
|
42
|
+
request.baseUrlParam = lookup.smartyKey;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
request.baseUrlParam = "property/financial";
|
|
46
|
+
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
this.sender.send(request)
|
|
49
|
+
.then(response => {
|
|
50
|
+
if (response.error) reject(response.error);
|
|
51
|
+
|
|
52
|
+
lookup.response = response.payload;
|
|
53
|
+
resolve(lookup);
|
|
54
|
+
})
|
|
55
|
+
.catch(reject);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
sendGeo(lookup) {
|
|
60
|
+
if (typeof lookup === "undefined") throw new Errors.UndefinedLookupError();
|
|
61
|
+
|
|
62
|
+
let request = new Request();
|
|
63
|
+
request.parameters = buildInputData(lookup, keyTranslationFormat);
|
|
64
|
+
|
|
65
|
+
if (lookup.smartyKey) {
|
|
66
|
+
request.baseUrlParam = lookup.smartyKey;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
request.baseUrlParam = "geo-reference";
|
|
70
|
+
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
this.sender.send(request)
|
|
73
|
+
.then(response => {
|
|
74
|
+
if (response.error) reject(response.error);
|
|
75
|
+
|
|
76
|
+
lookup.response = response.payload;
|
|
77
|
+
resolve(lookup);
|
|
78
|
+
})
|
|
79
|
+
.catch(reject);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
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;
|