smartystreets-javascript-sdk 5.2.0 → 6.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/dist/cjs/AgentSender.cjs +1 -0
- package/dist/cjs/BaseUrlSender.cjs +1 -0
- package/dist/cjs/Batch.cjs +1 -0
- package/dist/cjs/ClientBuilder.cjs +1 -0
- package/dist/cjs/CustomHeaderSender.cjs +1 -0
- package/dist/cjs/Errors.cjs +1 -0
- package/dist/cjs/HttpSender.cjs +1 -0
- package/dist/cjs/InputData.cjs +1 -0
- package/dist/cjs/LicenseSender.cjs +1 -0
- package/dist/cjs/Request.cjs +1 -0
- package/dist/cjs/Response.cjs +1 -0
- package/dist/cjs/RetrySender.cjs +1 -0
- package/dist/cjs/SharedCredentials.cjs +1 -0
- package/dist/cjs/SigningSender.cjs +1 -0
- package/dist/cjs/StaticCredentials.cjs +1 -0
- package/dist/cjs/StatusCodeSender.cjs +1 -0
- package/dist/cjs/_virtual/Batch.cjs +1 -0
- package/dist/cjs/_virtual/Candidate.cjs +1 -0
- package/dist/cjs/_virtual/Candidate2.cjs +1 -0
- package/dist/cjs/_virtual/ClientBuilder.cjs +1 -0
- package/dist/cjs/_virtual/Errors.cjs +1 -0
- package/dist/cjs/_virtual/Lookup.cjs +1 -0
- package/dist/cjs/_virtual/Lookup2.cjs +1 -0
- package/dist/cjs/_virtual/Lookup3.cjs +1 -0
- package/dist/cjs/_virtual/Lookup4.cjs +1 -0
- package/dist/cjs/_virtual/Lookup5.cjs +1 -0
- package/dist/cjs/_virtual/Lookup6.cjs +1 -0
- package/dist/cjs/_virtual/Lookup7.cjs +1 -0
- package/dist/cjs/_virtual/Lookup8.cjs +1 -0
- package/dist/cjs/_virtual/Response.cjs +1 -0
- package/dist/cjs/_virtual/Result.cjs +1 -0
- package/dist/cjs/_virtual/Result2.cjs +1 -0
- package/dist/cjs/_virtual/SharedCredentials.cjs +1 -0
- package/dist/cjs/_virtual/StaticCredentials.cjs +1 -0
- package/dist/cjs/_virtual/Suggestion.cjs +1 -0
- package/dist/cjs/_virtual/Suggestion2.cjs +1 -0
- package/dist/cjs/_virtual/_axios.cjs +1 -0
- package/dist/cjs/_virtual/_commonjsHelpers.cjs +1 -0
- package/dist/cjs/_virtual/buildClients.cjs +1 -0
- package/dist/cjs/index.cjs +1 -0
- package/dist/cjs/international_address_autocomplete/Client.cjs +1 -0
- package/dist/cjs/international_address_autocomplete/Lookup.cjs +1 -0
- package/dist/cjs/international_address_autocomplete/Suggestion.cjs +1 -0
- package/dist/cjs/international_street/Candidate.cjs +1 -0
- package/dist/cjs/international_street/Client.cjs +1 -0
- package/dist/cjs/international_street/Lookup.cjs +1 -0
- package/dist/cjs/package.json.cjs +1 -0
- package/dist/cjs/us_autocomplete_pro/Client.cjs +1 -0
- package/dist/cjs/us_autocomplete_pro/Lookup.cjs +1 -0
- package/dist/cjs/us_autocomplete_pro/Suggestion.cjs +1 -0
- package/dist/cjs/us_enrichment/Client.cjs +1 -0
- package/dist/cjs/us_enrichment/Lookup.cjs +1 -0
- package/dist/cjs/us_enrichment/Response.cjs +1 -0
- package/dist/cjs/us_extract/Address.cjs +1 -0
- package/dist/cjs/us_extract/Client.cjs +1 -0
- package/dist/cjs/us_extract/Lookup.cjs +1 -0
- package/dist/cjs/us_extract/Result.cjs +1 -0
- package/dist/cjs/us_reverse_geo/Client.cjs +1 -0
- package/dist/cjs/us_reverse_geo/Lookup.cjs +1 -0
- package/dist/cjs/us_reverse_geo/Response.cjs +1 -0
- package/dist/cjs/us_reverse_geo/Result.cjs +1 -0
- package/dist/cjs/us_street/Candidate.cjs +1 -0
- package/dist/cjs/us_street/Client.cjs +1 -0
- package/dist/cjs/us_street/Lookup.cjs +1 -0
- package/dist/cjs/us_zipcode/Client.cjs +1 -0
- package/dist/cjs/us_zipcode/Lookup.cjs +1 -0
- package/dist/cjs/us_zipcode/Result.cjs +1 -0
- package/dist/cjs/util/Sleeper.cjs +1 -0
- package/dist/cjs/util/apiToSDKKeyMap.cjs +1 -0
- package/dist/cjs/util/buildClients.cjs +1 -0
- package/dist/cjs/util/buildInputData.cjs +1 -0
- package/dist/cjs/util/buildSmartyResponse.cjs +1 -0
- package/dist/cjs/util/sendBatch.cjs +1 -0
- package/dist/esm/AgentSender.mjs +1 -0
- package/dist/esm/BaseUrlSender.mjs +1 -0
- package/dist/esm/Batch.mjs +1 -0
- package/dist/esm/ClientBuilder.mjs +1 -0
- package/dist/esm/CustomHeaderSender.mjs +1 -0
- package/dist/esm/Errors.mjs +1 -0
- package/dist/esm/HttpSender.mjs +1 -0
- package/dist/esm/InputData.mjs +1 -0
- package/dist/esm/LicenseSender.mjs +1 -0
- package/dist/esm/Request.mjs +1 -0
- package/dist/esm/Response.mjs +1 -0
- package/dist/esm/RetrySender.mjs +1 -0
- package/dist/esm/SharedCredentials.mjs +1 -0
- package/dist/esm/SigningSender.mjs +1 -0
- package/dist/esm/StaticCredentials.mjs +1 -0
- package/dist/esm/StatusCodeSender.mjs +1 -0
- package/dist/esm/_virtual/Batch.mjs +1 -0
- package/dist/esm/_virtual/Candidate.mjs +1 -0
- package/dist/esm/_virtual/Candidate2.mjs +1 -0
- package/dist/esm/_virtual/ClientBuilder.mjs +1 -0
- package/dist/esm/_virtual/Errors.mjs +1 -0
- package/dist/esm/_virtual/Lookup.mjs +1 -0
- package/dist/esm/_virtual/Lookup2.mjs +1 -0
- package/dist/esm/_virtual/Lookup3.mjs +1 -0
- package/dist/esm/_virtual/Lookup4.mjs +1 -0
- package/dist/esm/_virtual/Lookup5.mjs +1 -0
- package/dist/esm/_virtual/Lookup6.mjs +1 -0
- package/dist/esm/_virtual/Lookup7.mjs +1 -0
- package/dist/esm/_virtual/Lookup8.mjs +1 -0
- package/dist/esm/_virtual/Response.mjs +1 -0
- package/dist/esm/_virtual/Result.mjs +1 -0
- package/dist/esm/_virtual/Result2.mjs +1 -0
- package/dist/esm/_virtual/SharedCredentials.mjs +1 -0
- package/dist/esm/_virtual/StaticCredentials.mjs +1 -0
- package/dist/esm/_virtual/Suggestion.mjs +1 -0
- package/dist/esm/_virtual/Suggestion2.mjs +1 -0
- package/dist/esm/_virtual/_axios.mjs +1 -0
- package/dist/esm/_virtual/_commonjsHelpers.mjs +1 -0
- package/dist/esm/_virtual/buildClients.mjs +1 -0
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/international_address_autocomplete/Client.mjs +1 -0
- package/dist/esm/international_address_autocomplete/Lookup.mjs +1 -0
- package/dist/esm/international_address_autocomplete/Suggestion.mjs +1 -0
- package/dist/esm/international_street/Candidate.mjs +1 -0
- package/dist/esm/international_street/Client.mjs +1 -0
- package/dist/esm/international_street/Lookup.mjs +1 -0
- package/dist/esm/package.json.mjs +1 -0
- package/dist/esm/us_autocomplete_pro/Client.mjs +1 -0
- package/dist/esm/us_autocomplete_pro/Lookup.mjs +1 -0
- package/dist/esm/us_autocomplete_pro/Suggestion.mjs +1 -0
- package/dist/esm/us_enrichment/Client.mjs +1 -0
- package/dist/esm/us_enrichment/Lookup.mjs +1 -0
- package/dist/esm/us_enrichment/Response.mjs +1 -0
- package/dist/esm/us_extract/Address.mjs +1 -0
- package/dist/esm/us_extract/Client.mjs +1 -0
- package/dist/esm/us_extract/Lookup.mjs +1 -0
- package/dist/esm/us_extract/Result.mjs +1 -0
- package/dist/esm/us_reverse_geo/Client.mjs +1 -0
- package/dist/esm/us_reverse_geo/Lookup.mjs +1 -0
- package/dist/esm/us_reverse_geo/Response.mjs +1 -0
- package/dist/esm/us_reverse_geo/Result.mjs +1 -0
- package/dist/esm/us_street/Candidate.mjs +1 -0
- package/dist/esm/us_street/Client.mjs +1 -0
- package/dist/esm/us_street/Lookup.mjs +1 -0
- package/dist/esm/us_zipcode/Client.mjs +1 -0
- package/dist/esm/us_zipcode/Lookup.mjs +1 -0
- package/dist/esm/us_zipcode/Result.mjs +1 -0
- package/dist/esm/util/Sleeper.mjs +1 -0
- package/dist/esm/util/apiToSDKKeyMap.mjs +1 -0
- package/dist/esm/util/buildClients.mjs +1 -0
- package/dist/esm/util/buildInputData.mjs +1 -0
- package/dist/esm/util/buildSmartyResponse.mjs +1 -0
- package/dist/esm/util/sendBatch.mjs +1 -0
- package/package.json +26 -6
- package/.github/workflows/node-tests.yml +0 -27
- package/CHANGELOG.md +0 -5
- package/Makefile +0 -28
- package/examples/international_address_autocomplete.js +0 -58
- package/examples/international_street.js +0 -56
- package/examples/us_autocomplete_pro.js +0 -63
- package/examples/us_enrichment.js +0 -36
- package/examples/us_extract.js +0 -40
- package/examples/us_reverse_geo.js +0 -40
- package/examples/us_street.js +0 -73
- package/examples/us_zipcode.js +0 -57
- package/index.js +0 -41
- package/js-sdk-demo.cast +0 -95
- package/src/AgentSender.js +0 -16
- package/src/BaseUrlSender.js +0 -18
- package/src/Batch.js +0 -49
- package/src/ClientBuilder.js +0 -212
- package/src/CustomHeaderSender.js +0 -20
- package/src/Errors.js +0 -100
- package/src/HttpSender.js +0 -66
- package/src/InputData.js +0 -21
- package/src/LicenseSender.js +0 -20
- package/src/Request.js +0 -12
- package/src/Response.js +0 -10
- package/src/RetrySender.js +0 -50
- package/src/SharedCredentials.js +0 -13
- package/src/SigningSender.js +0 -26
- package/src/StaticCredentials.js +0 -13
- package/src/StatusCodeSender.js +0 -35
- package/src/international_address_autocomplete/Client.js +0 -41
- package/src/international_address_autocomplete/Lookup.js +0 -14
- package/src/international_address_autocomplete/Suggestion.js +0 -14
- package/src/international_street/Candidate.js +0 -153
- package/src/international_street/Client.js +0 -42
- package/src/international_street/Lookup.js +0 -85
- package/src/us_autocomplete_pro/Client.js +0 -41
- package/src/us_autocomplete_pro/Lookup.js +0 -29
- package/src/us_autocomplete_pro/Suggestion.js +0 -19
- package/src/us_enrichment/Client.js +0 -112
- package/src/us_enrichment/Lookup.js +0 -13
- package/src/us_enrichment/Response.js +0 -559
- package/src/us_extract/Address.js +0 -17
- package/src/us_extract/Client.js +0 -35
- package/src/us_extract/Lookup.js +0 -24
- package/src/us_extract/Result.js +0 -21
- package/src/us_reverse_geo/Client.js +0 -40
- package/src/us_reverse_geo/Lookup.js +0 -17
- package/src/us_reverse_geo/Response.js +0 -17
- package/src/us_reverse_geo/Result.js +0 -36
- package/src/us_street/Candidate.js +0 -89
- package/src/us_street/Client.js +0 -43
- package/src/us_street/Lookup.js +0 -25
- package/src/us_zipcode/Client.js +0 -39
- package/src/us_zipcode/Lookup.js +0 -16
- package/src/us_zipcode/Result.js +0 -45
- package/src/util/Sleeper.js +0 -8
- package/src/util/apiToSDKKeyMap.js +0 -75
- package/src/util/buildClients.js +0 -48
- package/src/util/buildInputData.js +0 -11
- package/src/util/buildSmartyResponse.js +0 -10
- package/src/util/sendBatch.js +0 -39
- package/tests/fixtures/MockSleeper.js +0 -10
- package/tests/fixtures/mock_senders.js +0 -43
- package/tests/international_address_autocomplete/test_Client.js +0 -86
- package/tests/international_address_autocomplete/test_Lookup.js +0 -55
- package/tests/international_street/test_Candidate.js +0 -268
- package/tests/international_street/test_Client.js +0 -70
- package/tests/international_street/test_Lookup.js +0 -108
- package/tests/test_AgentSender.js +0 -25
- package/tests/test_BaseUrlSender.js +0 -31
- package/tests/test_Batch.js +0 -73
- package/tests/test_CustomHeaderSender.js +0 -31
- package/tests/test_ExtractExample.js +0 -167
- package/tests/test_HttpSender.js +0 -93
- package/tests/test_LicenseSender.js +0 -40
- package/tests/test_RetrySender.js +0 -98
- package/tests/test_SigningSender.js +0 -56
- package/tests/test_StatusCodeSender.js +0 -95
- package/tests/us_autocomplete_pro/test_Client.js +0 -116
- package/tests/us_autocomplete_pro/test_Lookup.js +0 -11
- package/tests/us_autocomplete_pro/test_Suggestion.js +0 -24
- package/tests/us_enrichment/test_Client.js +0 -455
- package/tests/us_enrichment/test_Lookup.js +0 -22
- package/tests/us_enrichment/test_Response.js +0 -739
- package/tests/us_extract/test_Address.js +0 -67
- package/tests/us_extract/test_Client.js +0 -148
- package/tests/us_extract/test_Lookup.js +0 -19
- package/tests/us_extract/test_Result.js +0 -39
- package/tests/us_reverse_geo/test_Client.js +0 -48
- package/tests/us_reverse_geo/test_Lookup.js +0 -14
- package/tests/us_reverse_geo/test_Response.js +0 -44
- package/tests/us_street/test_Candidate.js +0 -133
- package/tests/us_street/test_Client.js +0 -150
- package/tests/us_street/test_Lookup.js +0 -29
- package/tests/us_zipcode/test_Client.js +0 -150
- package/tests/us_zipcode/test_Result.js +0 -81
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
const UnprocessableEntityError = require("../Errors").UnprocessableEntityError;
|
|
2
|
-
const messages = {
|
|
3
|
-
countryRequired: "Country field is required.",
|
|
4
|
-
freeformOrAddress1Required: "Either freeform or address1 is required.",
|
|
5
|
-
insufficientInformation: "Insufficient information: One or more required fields were not set on the lookup.",
|
|
6
|
-
badGeocode: "Invalid input: geocode can only be set to 'true' (default is 'false'.",
|
|
7
|
-
invalidLanguage: "Invalid input: language can only be set to 'latin' or 'native'. When not set, the the output language will match the language of the input values."
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* In addition to holding all of the input data for this lookup, this class also<br>
|
|
13
|
-
* will contain the result of the lookup after it comes back from the API.
|
|
14
|
-
* <p><b>Note: </b><i>Lookups must have certain required fields set with non-blank values. <br>
|
|
15
|
-
* These can be found at the URL below.</i></p>
|
|
16
|
-
* @see "https://www.smarty.com/docs/cloud/international-street-api#http-input-fields"
|
|
17
|
-
*/
|
|
18
|
-
class Lookup {
|
|
19
|
-
constructor(country, freeform) {
|
|
20
|
-
this.result = [];
|
|
21
|
-
|
|
22
|
-
this.country = country;
|
|
23
|
-
this.freeform = freeform;
|
|
24
|
-
this.address1 = undefined;
|
|
25
|
-
this.address2 = undefined;
|
|
26
|
-
this.address3 = undefined;
|
|
27
|
-
this.address4 = undefined;
|
|
28
|
-
this.organization = undefined;
|
|
29
|
-
this.locality = undefined;
|
|
30
|
-
this.administrativeArea = undefined;
|
|
31
|
-
this.postalCode = undefined;
|
|
32
|
-
this.geocode = undefined;
|
|
33
|
-
this.language = undefined;
|
|
34
|
-
this.inputId = undefined;
|
|
35
|
-
|
|
36
|
-
this.ensureEnoughInfo = this.ensureEnoughInfo.bind(this);
|
|
37
|
-
this.ensureValidData = this.ensureValidData.bind(this);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
ensureEnoughInfo() {
|
|
41
|
-
if (fieldIsMissing(this.country)) throw new UnprocessableEntityError(messages.countryRequired);
|
|
42
|
-
|
|
43
|
-
if (fieldIsSet(this.freeform)) return true;
|
|
44
|
-
|
|
45
|
-
if (fieldIsMissing(this.address1)) throw new UnprocessableEntityError(messages.freeformOrAddress1Required);
|
|
46
|
-
|
|
47
|
-
if (fieldIsSet(this.postalCode)) return true;
|
|
48
|
-
|
|
49
|
-
if (fieldIsMissing(this.locality) || fieldIsMissing(this.administrativeArea)) throw new UnprocessableEntityError(messages.insufficientInformation);
|
|
50
|
-
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
ensureValidData() {
|
|
55
|
-
let languageIsSetIncorrectly = () => {
|
|
56
|
-
let isLanguage = language => this.language.toLowerCase() === language;
|
|
57
|
-
|
|
58
|
-
return fieldIsSet(this.language) && !(isLanguage("latin") || isLanguage("native"));
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
let geocodeIsSetIncorrectly = () => {
|
|
62
|
-
return fieldIsSet(this.geocode) && this.geocode.toLowerCase() !== "true";
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
if (geocodeIsSetIncorrectly()) throw new UnprocessableEntityError(messages.badGeocode);
|
|
66
|
-
|
|
67
|
-
if (languageIsSetIncorrectly()) throw new UnprocessableEntityError(messages.invalidLanguage);
|
|
68
|
-
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function fieldIsMissing (field) {
|
|
74
|
-
if (!field) return true;
|
|
75
|
-
|
|
76
|
-
const whitespaceCharacters = /\s/g;
|
|
77
|
-
|
|
78
|
-
return field.replace(whitespaceCharacters, "").length < 1;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function fieldIsSet (field) {
|
|
82
|
-
return !fieldIsMissing(field);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
module.exports = Lookup;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const Errors = require("../Errors");
|
|
2
|
-
const Request = require("../Request");
|
|
3
|
-
const Suggestion = require("./Suggestion");
|
|
4
|
-
const buildInputData = require("../util/buildInputData");
|
|
5
|
-
const keyTranslationFormat = require("../util/apiToSDKKeyMap").usAutocompletePro;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* This client sends lookups to the Smarty US Autocomplete Pro API, <br>
|
|
9
|
-
* and attaches the suggestions to the appropriate Lookup objects.
|
|
10
|
-
*/
|
|
11
|
-
class Client {
|
|
12
|
-
constructor(sender) {
|
|
13
|
-
this.sender = sender;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
send(lookup) {
|
|
17
|
-
if (typeof lookup === "undefined") throw new Errors.UndefinedLookupError();
|
|
18
|
-
|
|
19
|
-
let request = new Request();
|
|
20
|
-
request.parameters = buildInputData(lookup, keyTranslationFormat);
|
|
21
|
-
|
|
22
|
-
return new Promise((resolve, reject) => {
|
|
23
|
-
this.sender.send(request)
|
|
24
|
-
.then(response => {
|
|
25
|
-
if (response.error) reject(response.error);
|
|
26
|
-
|
|
27
|
-
lookup.result = buildSuggestionsFromResponse(response.payload);
|
|
28
|
-
resolve(lookup);
|
|
29
|
-
})
|
|
30
|
-
.catch(reject);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
function buildSuggestionsFromResponse(payload) {
|
|
34
|
-
if (payload.suggestions === null) return [];
|
|
35
|
-
|
|
36
|
-
return payload.suggestions.map(suggestion => new Suggestion(suggestion));
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
module.exports = Client;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* In addition to holding all of the input data for this lookup, this class also<br>
|
|
3
|
-
* will contain the result of the lookup after it comes back from the API.
|
|
4
|
-
* @see "https://www.smarty.com/docs/cloud/us-autocomplete-api#pro-http-request-input-fields"
|
|
5
|
-
*/
|
|
6
|
-
class Lookup {
|
|
7
|
-
/**
|
|
8
|
-
* @param search The beginning of an address. This is required to be set.
|
|
9
|
-
*/
|
|
10
|
-
constructor(search) {
|
|
11
|
-
this.result = [];
|
|
12
|
-
|
|
13
|
-
this.search = search;
|
|
14
|
-
this.selected = undefined;
|
|
15
|
-
this.maxResults = undefined;
|
|
16
|
-
this.includeOnlyCities = [];
|
|
17
|
-
this.includeOnlyStates = [];
|
|
18
|
-
this.includeOnlyZIPCodes = [];
|
|
19
|
-
this.excludeStates = [];
|
|
20
|
-
this.preferCities = [];
|
|
21
|
-
this.preferStates = [];
|
|
22
|
-
this.preferZIPCodes = [];
|
|
23
|
-
this.preferRatio = undefined;
|
|
24
|
-
this.preferGeolocation = undefined;
|
|
25
|
-
this.source = undefined
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports = Lookup;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @see "https://www.smarty.com/docs/cloud/us-autocomplete-api#pro-http-response"
|
|
3
|
-
*/
|
|
4
|
-
class Suggestion {
|
|
5
|
-
constructor(responseData) {
|
|
6
|
-
this.streetLine = responseData.street_line;
|
|
7
|
-
this.secondary = responseData.secondary;
|
|
8
|
-
this.city = responseData.city;
|
|
9
|
-
this.state = responseData.state;
|
|
10
|
-
this.zipcode = responseData.zipcode;
|
|
11
|
-
this.entries = responseData.entries;
|
|
12
|
-
|
|
13
|
-
if (responseData.source) {
|
|
14
|
-
this.source = responseData.source;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
module.exports = Suggestion;
|
|
@@ -1,112 +0,0 @@
|
|
|
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
|
-
sendSecondary(lookup) {
|
|
72
|
-
if (typeof lookup === "undefined") throw new Errors.UndefinedLookupError();
|
|
73
|
-
|
|
74
|
-
let request = new Request();
|
|
75
|
-
request.parameters = buildInputData(lookup, keyTranslationFormat);
|
|
76
|
-
|
|
77
|
-
request.baseUrlParam = lookup.smartyKey + "/secondary";
|
|
78
|
-
|
|
79
|
-
return new Promise((resolve, reject) => {
|
|
80
|
-
this.sender.send(request)
|
|
81
|
-
.then(response => {
|
|
82
|
-
if (response.error) reject(response.error);
|
|
83
|
-
|
|
84
|
-
lookup.response = response.payload;
|
|
85
|
-
resolve(lookup);
|
|
86
|
-
})
|
|
87
|
-
.catch(reject);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
sendSecondaryCount(lookup) {
|
|
92
|
-
if (typeof lookup === "undefined") throw new Errors.UndefinedLookupError();
|
|
93
|
-
|
|
94
|
-
let request = new Request();
|
|
95
|
-
request.parameters = buildInputData(lookup, keyTranslationFormat);
|
|
96
|
-
|
|
97
|
-
request.baseUrlParam = lookup.smartyKey + "/secondary/count";
|
|
98
|
-
|
|
99
|
-
return new Promise((resolve, reject) => {
|
|
100
|
-
this.sender.send(request)
|
|
101
|
-
.then(response => {
|
|
102
|
-
if (response.error) reject(response.error);
|
|
103
|
-
|
|
104
|
-
lookup.response = response.payload;
|
|
105
|
-
resolve(lookup);
|
|
106
|
-
})
|
|
107
|
-
.catch(reject);
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
module.exports = Client;
|
|
@@ -1,13 +0,0 @@
|
|
|
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;
|