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
package/src/Errors.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
class SmartyError extends Error {
|
|
2
|
-
constructor(message = "unexpected error") {
|
|
3
|
-
super(message);
|
|
4
|
-
}
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
class DefaultError extends SmartyError {
|
|
8
|
-
constructor(message) {
|
|
9
|
-
super(message);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
class BatchFullError extends SmartyError {
|
|
15
|
-
constructor() {
|
|
16
|
-
super("A batch can contain a max of 100 lookups.");
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
class BatchEmptyError extends SmartyError {
|
|
21
|
-
constructor() {
|
|
22
|
-
super("A batch must contain at least 1 lookup.");
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
class UndefinedLookupError extends SmartyError {
|
|
27
|
-
constructor() {
|
|
28
|
-
super("The lookup provided is missing or undefined. Make sure you're passing a Lookup object.");
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
class BadCredentialsError extends SmartyError {
|
|
33
|
-
constructor() {
|
|
34
|
-
super("Unauthorized: The credentials were provided incorrectly or did not match any existing active credentials.");
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
class PaymentRequiredError extends SmartyError {
|
|
39
|
-
constructor() {
|
|
40
|
-
super("Payment Required: There is no active subscription for the account associated with the credentials submitted with the request.");
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
class RequestEntityTooLargeError extends SmartyError {
|
|
45
|
-
constructor() {
|
|
46
|
-
super("Request Entity Too Large: The request body has exceeded the maximum size.");
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
class BadRequestError extends SmartyError {
|
|
51
|
-
constructor() {
|
|
52
|
-
super("Bad Request (Malformed Payload): A GET request lacked a street field or the request body of a POST request contained malformed JSON.");
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
class UnprocessableEntityError extends SmartyError {
|
|
57
|
-
constructor(message) {
|
|
58
|
-
super(message);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
class TooManyRequestsError extends SmartyError {
|
|
63
|
-
constructor() {
|
|
64
|
-
super("When using the public 'embedded key' authentication, we restrict the number of requests coming from a given source over too short of a time.");
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
class InternalServerError extends SmartyError {
|
|
69
|
-
constructor() {
|
|
70
|
-
super("Internal Server Error.");
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
class ServiceUnavailableError extends SmartyError {
|
|
75
|
-
constructor() {
|
|
76
|
-
super("Service Unavailable. Try again later.");
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
class GatewayTimeoutError extends SmartyError {
|
|
81
|
-
constructor() {
|
|
82
|
-
super("The upstream data provider did not respond in a timely fashion and the request failed. A serious, yet rare occurrence indeed.");
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
module.exports = {
|
|
87
|
-
BatchFullError: BatchFullError,
|
|
88
|
-
BatchEmptyError: BatchEmptyError,
|
|
89
|
-
UndefinedLookupError: UndefinedLookupError,
|
|
90
|
-
BadCredentialsError: BadCredentialsError,
|
|
91
|
-
PaymentRequiredError: PaymentRequiredError,
|
|
92
|
-
RequestEntityTooLargeError: RequestEntityTooLargeError,
|
|
93
|
-
BadRequestError: BadRequestError,
|
|
94
|
-
UnprocessableEntityError: UnprocessableEntityError,
|
|
95
|
-
TooManyRequestsError: TooManyRequestsError,
|
|
96
|
-
InternalServerError: InternalServerError,
|
|
97
|
-
ServiceUnavailableError: ServiceUnavailableError,
|
|
98
|
-
GatewayTimeoutError: GatewayTimeoutError,
|
|
99
|
-
DefaultError: DefaultError
|
|
100
|
-
};
|
package/src/HttpSender.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
const Axios = require("axios").default;
|
|
2
|
-
const {buildSmartyResponse} = require("../src/util/buildSmartyResponse");
|
|
3
|
-
|
|
4
|
-
class HttpSender {
|
|
5
|
-
constructor(timeout = 10000, proxyConfig, debug = false) {
|
|
6
|
-
this.axiosInstance = Axios.create();
|
|
7
|
-
this.timeout = timeout;
|
|
8
|
-
this.proxyConfig = proxyConfig;
|
|
9
|
-
if (debug) this.enableDebug();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
buildRequestConfig({payload, parameters, headers, baseUrl}) {
|
|
13
|
-
let config = {
|
|
14
|
-
method: "GET",
|
|
15
|
-
timeout: this.timeout,
|
|
16
|
-
params: parameters,
|
|
17
|
-
headers: headers,
|
|
18
|
-
baseURL: baseUrl,
|
|
19
|
-
validateStatus: function (status) {
|
|
20
|
-
return status < 500;
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
if (payload) {
|
|
25
|
-
config.method = "POST";
|
|
26
|
-
config.data = payload;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (this.proxyConfig) config.proxy = this.proxyConfig;
|
|
30
|
-
return config;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
send(request) {
|
|
34
|
-
return new Promise((resolve, reject) => {
|
|
35
|
-
let requestConfig = this.buildRequestConfig(request);
|
|
36
|
-
|
|
37
|
-
this.axiosInstance(requestConfig)
|
|
38
|
-
.then(response => {
|
|
39
|
-
let smartyResponse = buildSmartyResponse(response);
|
|
40
|
-
|
|
41
|
-
if (smartyResponse.statusCode >= 400) reject(smartyResponse);
|
|
42
|
-
|
|
43
|
-
resolve(smartyResponse);
|
|
44
|
-
})
|
|
45
|
-
.catch(error => reject(buildSmartyResponse(undefined, error)));
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
enableDebug() {
|
|
50
|
-
this.axiosInstance.interceptors.request.use(request => {
|
|
51
|
-
console.log('Request:\r\n', request);
|
|
52
|
-
console.log('\r\n*******************************************\r\n');
|
|
53
|
-
return request
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
this.axiosInstance.interceptors.response.use(response => {
|
|
57
|
-
console.log('Response:\r\n');
|
|
58
|
-
console.log('Status:', response.status, response.statusText);
|
|
59
|
-
console.log('Headers:', response.headers);
|
|
60
|
-
console.log('Data:', response.data);
|
|
61
|
-
return response
|
|
62
|
-
})
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
module.exports = HttpSender;
|
package/src/InputData.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
class InputData {
|
|
2
|
-
constructor(lookup) {
|
|
3
|
-
this.lookup = lookup;
|
|
4
|
-
this.data = {};
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
add(apiField, lookupField) {
|
|
8
|
-
if (this.lookupFieldIsPopulated(lookupField)) this.data[apiField] = this.formatData(this.lookup[lookupField]);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
formatData(field) {
|
|
12
|
-
if (Array.isArray(field)) return field.join(";");
|
|
13
|
-
else return field;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
lookupFieldIsPopulated(lookupField) {
|
|
17
|
-
return this.lookup[lookupField] !== "" && this.lookup[lookupField] !== undefined;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
module.exports = InputData;
|
package/src/LicenseSender.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
class LicenseSender {
|
|
2
|
-
constructor(innerSender, licenses) {
|
|
3
|
-
this.sender = innerSender;
|
|
4
|
-
this.licenses = licenses;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
send(request) {
|
|
8
|
-
if (this.licenses.length !== 0) {
|
|
9
|
-
request.parameters["license"] = this.licenses.join(",");
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return new Promise((resolve, reject) => {
|
|
13
|
-
this.sender.send(request)
|
|
14
|
-
.then(resolve)
|
|
15
|
-
.catch(reject);
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
module.exports = LicenseSender;
|
package/src/Request.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
class Request {
|
|
2
|
-
constructor(payload, headers = {"Content-Type": "application/json; charset=utf-8"}) {
|
|
3
|
-
this.baseUrl = "";
|
|
4
|
-
this.baseUrlParam = "";
|
|
5
|
-
this.payload = payload;
|
|
6
|
-
this.headers = headers;
|
|
7
|
-
|
|
8
|
-
this.parameters = {};
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
module.exports = Request;
|
package/src/Response.js
DELETED
package/src/RetrySender.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
class RetrySender {
|
|
2
|
-
constructor(maxRetires = 5, inner, sleeper) {
|
|
3
|
-
this.maxRetries = maxRetires;
|
|
4
|
-
this.statusToRetry = [408, 429, 500, 502, 503, 504];
|
|
5
|
-
this.statusTooManyRequests = 429;
|
|
6
|
-
this.maxBackoffDuration = 10;
|
|
7
|
-
this.inner = inner;
|
|
8
|
-
this.sleeper = sleeper;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
async send(request) {
|
|
12
|
-
let response = await this.inner.send(request);
|
|
13
|
-
|
|
14
|
-
for (let i = 0; i < this.maxRetries; i++) {
|
|
15
|
-
|
|
16
|
-
if (!this.statusToRetry.includes(parseInt(response.statusCode))) {
|
|
17
|
-
break;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (parseInt(response.statusCode) === this.statusTooManyRequests) {
|
|
21
|
-
let secondsToBackoff = 10;
|
|
22
|
-
if (response.headers) {
|
|
23
|
-
const retryAfterHeader = response.headers["Retry-After"];
|
|
24
|
-
if (Number.isInteger(retryAfterHeader)) {
|
|
25
|
-
secondsToBackoff = retryAfterHeader;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
await this.rateLimitBackOff(secondsToBackoff);
|
|
29
|
-
} else {
|
|
30
|
-
await this.backoff(i);
|
|
31
|
-
}
|
|
32
|
-
response = await this.inner.send(request);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return response;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
async backoff(attempt) {
|
|
39
|
-
const backoffDuration = Math.min(attempt, this.maxBackoffDuration);
|
|
40
|
-
console.log(`There was an error processing the request. Retrying in ${backoffDuration} seconds...`);
|
|
41
|
-
await this.sleeper.sleep(backoffDuration);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
async rateLimitBackOff(backoffDuration) {
|
|
45
|
-
console.log(`Rate limit reached. Retrying in ${backoffDuration} seconds...`);
|
|
46
|
-
await this.sleeper.sleep(backoffDuration);
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
module.exports = RetrySender;
|
package/src/SharedCredentials.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
class SharedCredentials {
|
|
2
|
-
constructor(authId, hostName) {
|
|
3
|
-
this.authId = authId;
|
|
4
|
-
this.hostName = hostName;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
sign(request) {
|
|
8
|
-
request.parameters["key"] = this.authId;
|
|
9
|
-
if (this.hostName) request.headers["Referer"] = "https://" + this.hostName;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
module.exports = SharedCredentials;
|
package/src/SigningSender.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const UnprocessableEntityError = require("./Errors").UnprocessableEntityError;
|
|
2
|
-
const SharedCredentials = require("./SharedCredentials");
|
|
3
|
-
|
|
4
|
-
class SigningSender {
|
|
5
|
-
constructor(innerSender, signer) {
|
|
6
|
-
this.signer = signer;
|
|
7
|
-
this.sender = innerSender;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
send(request) {
|
|
11
|
-
const sendingPostWithSharedCredentials = request.payload && this.signer instanceof SharedCredentials;
|
|
12
|
-
if (sendingPostWithSharedCredentials) {
|
|
13
|
-
const message = "Shared credentials cannot be used in batches with a length greater than 1 or when using the US Extract API.";
|
|
14
|
-
throw new UnprocessableEntityError(message);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return new Promise((resolve, reject) => {
|
|
18
|
-
this.signer.sign(request);
|
|
19
|
-
this.sender.send(request)
|
|
20
|
-
.then(resolve)
|
|
21
|
-
.catch(reject);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
module.exports = SigningSender;
|
package/src/StaticCredentials.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
class StaticCredentials {
|
|
2
|
-
constructor (authId, authToken) {
|
|
3
|
-
this.authId = authId;
|
|
4
|
-
this.authToken = authToken;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
sign (request) {
|
|
8
|
-
request.parameters["auth-id"] = this.authId;
|
|
9
|
-
request.parameters["auth-token"] = this.authToken;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
module.exports = StaticCredentials;
|
package/src/StatusCodeSender.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
const Errors = require("./Errors");
|
|
2
|
-
|
|
3
|
-
class StatusCodeSender {
|
|
4
|
-
constructor(innerSender) {
|
|
5
|
-
this.sender = innerSender;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
send(request) {
|
|
9
|
-
return new Promise((resolve, reject) => {
|
|
10
|
-
this.sender.send(request)
|
|
11
|
-
.then(resolve)
|
|
12
|
-
.catch(error => {
|
|
13
|
-
switch (error.statusCode) {
|
|
14
|
-
case 500:
|
|
15
|
-
error.error = new Errors.InternalServerError();
|
|
16
|
-
break;
|
|
17
|
-
|
|
18
|
-
case 503:
|
|
19
|
-
error.error = new Errors.ServiceUnavailableError();
|
|
20
|
-
break;
|
|
21
|
-
|
|
22
|
-
case 504:
|
|
23
|
-
error.error = new Errors.GatewayTimeoutError();
|
|
24
|
-
break;
|
|
25
|
-
|
|
26
|
-
default:
|
|
27
|
-
error.error = new Errors.DefaultError(error && error.payload && error.payload.errors[0] && error.payload.errors[0].message);
|
|
28
|
-
}
|
|
29
|
-
reject(error);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
module.exports = StatusCodeSender;
|
|
@@ -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").internationalAddressAutocomplete;
|
|
6
|
-
|
|
7
|
-
class Client {
|
|
8
|
-
constructor(sender) {
|
|
9
|
-
this.sender = sender;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
send(lookup) {
|
|
13
|
-
if (typeof lookup === "undefined") throw new Errors.UndefinedLookupError();
|
|
14
|
-
|
|
15
|
-
let request = new Request();
|
|
16
|
-
request.parameters = buildInputData(lookup, keyTranslationFormat);
|
|
17
|
-
|
|
18
|
-
if (lookup.addressId) {
|
|
19
|
-
request.baseUrlParam = lookup.addressId;
|
|
20
|
-
}
|
|
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 && payload.candidates === null) return [];
|
|
35
|
-
|
|
36
|
-
return payload.candidates.map(suggestion => new Suggestion(suggestion));
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
module.exports = Client;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
class Lookup {
|
|
2
|
-
constructor({search, addressId, country, maxResults = 5, includeOnlyLocality, includeOnlyPostalCode} = {}) {
|
|
3
|
-
this.result = [];
|
|
4
|
-
|
|
5
|
-
this.search = search;
|
|
6
|
-
this.addressId = addressId;
|
|
7
|
-
this.country = country;
|
|
8
|
-
this.maxResults = maxResults;
|
|
9
|
-
this.includeOnlyLocality = includeOnlyLocality;
|
|
10
|
-
this.includeOnlyPostalCode = includeOnlyPostalCode;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
module.exports = Lookup;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
class Suggestion {
|
|
2
|
-
constructor(responseData) {
|
|
3
|
-
this.street = responseData.street;
|
|
4
|
-
this.locality = responseData.locality;
|
|
5
|
-
this.administrativeArea = responseData.administrative_area;
|
|
6
|
-
this.postalCode = responseData.postal_code;
|
|
7
|
-
this.countryIso3 = responseData.country_iso3;
|
|
8
|
-
this.entries = responseData.entries;
|
|
9
|
-
this.addressText = responseData.address_text;
|
|
10
|
-
this.addressId = responseData.address_id;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
module.exports = Suggestion;
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A candidate is a possible match for an address that was submitted.<br>
|
|
3
|
-
* A lookup can have multiple candidates if the address was ambiguous.
|
|
4
|
-
*
|
|
5
|
-
* @see "https://www.smarty.com/docs/cloud/international-street-api#root"
|
|
6
|
-
*/
|
|
7
|
-
class Candidate {
|
|
8
|
-
constructor(responseData) {
|
|
9
|
-
this.organization = responseData.organization;
|
|
10
|
-
this.address1 = responseData.address1;
|
|
11
|
-
this.address2 = responseData.address2;
|
|
12
|
-
this.address3 = responseData.address3;
|
|
13
|
-
this.address4 = responseData.address4;
|
|
14
|
-
this.address5 = responseData.address5;
|
|
15
|
-
this.address6 = responseData.address6;
|
|
16
|
-
this.address7 = responseData.address7;
|
|
17
|
-
this.address8 = responseData.address8;
|
|
18
|
-
this.address9 = responseData.address9;
|
|
19
|
-
this.address10 = responseData.address10;
|
|
20
|
-
this.address11 = responseData.address11;
|
|
21
|
-
this.address12 = responseData.address12;
|
|
22
|
-
|
|
23
|
-
this.components = {};
|
|
24
|
-
if (responseData.components !== undefined) {
|
|
25
|
-
this.components.countryIso3 = responseData.components.country_iso_3;
|
|
26
|
-
this.components.superAdministrativeArea = responseData.components.super_administrative_area;
|
|
27
|
-
this.components.administrativeArea = responseData.components.administrative_area;
|
|
28
|
-
this.components.administrativeAreaShort = responseData.components.administrative_area_short;
|
|
29
|
-
this.components.administrativeAreaLong = responseData.components.administrative_area_long;
|
|
30
|
-
this.components.subAdministrativeArea = responseData.components.sub_administrative_area;
|
|
31
|
-
this.components.dependentLocality = responseData.components.dependent_locality;
|
|
32
|
-
this.components.dependentLocalityName = responseData.components.dependent_locality_name;
|
|
33
|
-
this.components.doubleDependentLocality = responseData.components.double_dependent_locality;
|
|
34
|
-
this.components.locality = responseData.components.locality;
|
|
35
|
-
this.components.postalCode = responseData.components.postal_code;
|
|
36
|
-
this.components.postalCodeShort = responseData.components.postal_code_short;
|
|
37
|
-
this.components.postalCodeExtra = responseData.components.postal_code_extra;
|
|
38
|
-
this.components.premise = responseData.components.premise;
|
|
39
|
-
this.components.premiseExtra = responseData.components.premise_extra;
|
|
40
|
-
this.components.premisePrefixNumber = responseData.components.premise_prefix_number;
|
|
41
|
-
this.components.premiseNumber = responseData.components.premise_number;
|
|
42
|
-
this.components.premiseType = responseData.components.premise_type;
|
|
43
|
-
this.components.thoroughfare = responseData.components.thoroughfare;
|
|
44
|
-
this.components.thoroughfarePredirection = responseData.components.thoroughfare_predirection;
|
|
45
|
-
this.components.thoroughfarePostdirection = responseData.components.thoroughfare_postdirection;
|
|
46
|
-
this.components.thoroughfareName = responseData.components.thoroughfare_name;
|
|
47
|
-
this.components.thoroughfareTrailingType = responseData.components.thoroughfare_trailing_type;
|
|
48
|
-
this.components.thoroughfareType = responseData.components.thoroughfare_type;
|
|
49
|
-
this.components.dependentThoroughfare = responseData.components.dependent_thoroughfare;
|
|
50
|
-
this.components.dependentThoroughfarePredirection = responseData.components.dependent_thoroughfare_predirection;
|
|
51
|
-
this.components.dependentThoroughfarePostdirection = responseData.components.dependent_thoroughfare_postdirection;
|
|
52
|
-
this.components.dependentThoroughfareName = responseData.components.dependent_thoroughfare_name;
|
|
53
|
-
this.components.dependentThoroughfareTrailingType = responseData.components.dependent_thoroughfare_trailing_type;
|
|
54
|
-
this.components.dependentThoroughfareType = responseData.components.dependent_thoroughfare_type;
|
|
55
|
-
this.components.building = responseData.components.building;
|
|
56
|
-
this.components.buildingLeadingType = responseData.components.building_leading_type;
|
|
57
|
-
this.components.buildingName = responseData.components.building_name;
|
|
58
|
-
this.components.buildingTrailingType = responseData.components.building_trailing_type;
|
|
59
|
-
this.components.subBuildingType = responseData.components.sub_building_type;
|
|
60
|
-
this.components.subBuildingNumber = responseData.components.sub_building_number;
|
|
61
|
-
this.components.subBuildingName = responseData.components.sub_building_name;
|
|
62
|
-
this.components.subBuilding = responseData.components.sub_building;
|
|
63
|
-
this.components.levelType = responseData.components.level_type;
|
|
64
|
-
this.components.levelNumber = responseData.components.level_number;
|
|
65
|
-
this.components.postBox = responseData.components.post_box;
|
|
66
|
-
this.components.postBoxType = responseData.components.post_box_type;
|
|
67
|
-
this.components.postBoxNumber = responseData.components.post_box_number;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
this.analysis = {};
|
|
71
|
-
if (responseData.analysis !== undefined) {
|
|
72
|
-
this.analysis.verificationStatus = responseData.analysis.verification_status;
|
|
73
|
-
this.analysis.addressPrecision = responseData.analysis.address_precision;
|
|
74
|
-
this.analysis.maxAddressPrecision = responseData.analysis.max_address_precision;
|
|
75
|
-
|
|
76
|
-
this.analysis.changes = {};
|
|
77
|
-
if (responseData.analysis.changes !== undefined) {
|
|
78
|
-
this.analysis.changes.organization = responseData.analysis.changes.organization;
|
|
79
|
-
this.analysis.changes.address1 = responseData.analysis.changes.address1;
|
|
80
|
-
this.analysis.changes.address2 = responseData.analysis.changes.address2;
|
|
81
|
-
this.analysis.changes.address3 = responseData.analysis.changes.address3;
|
|
82
|
-
this.analysis.changes.address4 = responseData.analysis.changes.address4;
|
|
83
|
-
this.analysis.changes.address5 = responseData.analysis.changes.address5;
|
|
84
|
-
this.analysis.changes.address6 = responseData.analysis.changes.address6;
|
|
85
|
-
this.analysis.changes.address7 = responseData.analysis.changes.address7;
|
|
86
|
-
this.analysis.changes.address8 = responseData.analysis.changes.address8;
|
|
87
|
-
this.analysis.changes.address9 = responseData.analysis.changes.address9;
|
|
88
|
-
this.analysis.changes.address10 = responseData.analysis.changes.address10;
|
|
89
|
-
this.analysis.changes.address11 = responseData.analysis.changes.address11;
|
|
90
|
-
this.analysis.changes.address12 = responseData.analysis.changes.address12;
|
|
91
|
-
|
|
92
|
-
this.analysis.changes.components = {};
|
|
93
|
-
if (responseData.analysis.changes.components !== undefined) {
|
|
94
|
-
this.analysis.changes.components.countryIso3 = responseData.analysis.changes.components.country_iso_3;
|
|
95
|
-
this.analysis.changes.components.superAdministrativeArea = responseData.analysis.changes.components.super_administrative_area;
|
|
96
|
-
this.analysis.changes.components.administrativeArea = responseData.analysis.changes.components.administrative_area;
|
|
97
|
-
this.analysis.changes.components.administrativeAreaShort = responseData.analysis.changes.components.administrative_area_short;
|
|
98
|
-
this.analysis.changes.components.administrativeAreaLong = responseData.analysis.changes.components.administrative_area_long;
|
|
99
|
-
this.analysis.changes.components.subAdministrativeArea = responseData.analysis.changes.components.sub_administrative_area;
|
|
100
|
-
this.analysis.changes.components.dependentLocality = responseData.analysis.changes.components.dependent_locality;
|
|
101
|
-
this.analysis.changes.components.dependentLocalityName = responseData.analysis.changes.components.dependent_locality_name;
|
|
102
|
-
this.analysis.changes.components.doubleDependentLocality = responseData.analysis.changes.components.double_dependent_locality;
|
|
103
|
-
this.analysis.changes.components.locality = responseData.analysis.changes.components.locality;
|
|
104
|
-
this.analysis.changes.components.postalCode = responseData.analysis.changes.components.postal_code;
|
|
105
|
-
this.analysis.changes.components.postalCodeShort = responseData.analysis.changes.components.postal_code_short;
|
|
106
|
-
this.analysis.changes.components.postalCodeExtra = responseData.analysis.changes.components.postal_code_extra;
|
|
107
|
-
this.analysis.changes.components.premise = responseData.analysis.changes.components.premise;
|
|
108
|
-
this.analysis.changes.components.premiseExtra = responseData.analysis.changes.components.premise_extra;
|
|
109
|
-
this.analysis.changes.components.premisePrefixNumber = responseData.analysis.changes.components.premise_prefix_number;
|
|
110
|
-
this.analysis.changes.components.premiseNumber = responseData.analysis.changes.components.premise_number;
|
|
111
|
-
this.analysis.changes.components.premiseType = responseData.analysis.changes.components.premise_type;
|
|
112
|
-
this.analysis.changes.components.thoroughfare = responseData.analysis.changes.components.thoroughfare;
|
|
113
|
-
this.analysis.changes.components.thoroughfarePredirection = responseData.analysis.changes.components.thoroughfare_predirection;
|
|
114
|
-
this.analysis.changes.components.thoroughfarePostdirection = responseData.analysis.changes.components.thoroughfare_postdirection;
|
|
115
|
-
this.analysis.changes.components.thoroughfareName = responseData.analysis.changes.components.thoroughfare_name;
|
|
116
|
-
this.analysis.changes.components.thoroughfareTrailingType = responseData.analysis.changes.components.thoroughfare_trailing_type;
|
|
117
|
-
this.analysis.changes.components.thoroughfareType = responseData.analysis.changes.components.thoroughfare_type;
|
|
118
|
-
this.analysis.changes.components.dependentThoroughfare = responseData.analysis.changes.components.dependent_thoroughfare;
|
|
119
|
-
this.analysis.changes.components.dependentThoroughfarePredirection = responseData.analysis.changes.components.dependent_thoroughfare_predirection;
|
|
120
|
-
this.analysis.changes.components.dependentThoroughfarePostdirection = responseData.analysis.changes.components.dependent_thoroughfare_postdirection;
|
|
121
|
-
this.analysis.changes.components.dependentThoroughfareName = responseData.analysis.changes.components.dependent_thoroughfare_name;
|
|
122
|
-
this.analysis.changes.components.dependentThoroughfareTrailingType = responseData.analysis.changes.components.dependent_thoroughfare_trailing_type;
|
|
123
|
-
this.analysis.changes.components.dependentThoroughfareType = responseData.analysis.changes.components.dependent_thoroughfare_type;
|
|
124
|
-
this.analysis.changes.components.building = responseData.analysis.changes.components.building;
|
|
125
|
-
this.analysis.changes.components.buildingLeadingType = responseData.analysis.changes.components.building_leading_type;
|
|
126
|
-
this.analysis.changes.components.buildingName = responseData.analysis.changes.components.building_name;
|
|
127
|
-
this.analysis.changes.components.buildingTrailingType = responseData.analysis.changes.components.building_trailing_type;
|
|
128
|
-
this.analysis.changes.components.subBuildingType = responseData.analysis.changes.components.sub_building_type;
|
|
129
|
-
this.analysis.changes.components.subBuildingNumber = responseData.analysis.changes.components.sub_building_number;
|
|
130
|
-
this.analysis.changes.components.subBuildingName = responseData.analysis.changes.components.sub_building_name;
|
|
131
|
-
this.analysis.changes.components.subBuilding = responseData.analysis.changes.components.sub_building;
|
|
132
|
-
this.analysis.changes.components.levelType = responseData.analysis.changes.components.level_type;
|
|
133
|
-
this.analysis.changes.components.levelNumber = responseData.analysis.changes.components.level_number;
|
|
134
|
-
this.analysis.changes.components.postBox = responseData.analysis.changes.components.post_box;
|
|
135
|
-
this.analysis.changes.components.postBoxType = responseData.analysis.changes.components.post_box_type;
|
|
136
|
-
this.analysis.changes.components.postBoxNumber = responseData.analysis.changes.components.post_box_number;
|
|
137
|
-
}
|
|
138
|
-
//TODO: Fill in the rest of these fields and their corresponding tests.
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
this.metadata = {};
|
|
143
|
-
if (responseData.metadata !== undefined) {
|
|
144
|
-
this.metadata.latitude = responseData.metadata.latitude;
|
|
145
|
-
this.metadata.longitude = responseData.metadata.longitude;
|
|
146
|
-
this.metadata.geocodePrecision = responseData.metadata.geocode_precision;
|
|
147
|
-
this.metadata.maxGeocodePrecision = responseData.metadata.max_geocode_precision;
|
|
148
|
-
this.metadata.addressFormat = responseData.metadata.address_format;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
module.exports = Candidate;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
const Request = require("../Request");
|
|
2
|
-
const Errors = require("../Errors");
|
|
3
|
-
const Candidate = require("./Candidate");
|
|
4
|
-
const buildInputData = require("../util/buildInputData");
|
|
5
|
-
const keyTranslationFormat = require("../util/apiToSDKKeyMap").internationalStreet;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* This client sends lookups to the Smarty International Street API, <br>
|
|
9
|
-
* and attaches the results 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
|
-
resolve(attachLookupCandidates(response, lookup));
|
|
28
|
-
})
|
|
29
|
-
.catch(reject);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
function attachLookupCandidates(response, lookup) {
|
|
33
|
-
response.payload.map(rawCandidate => {
|
|
34
|
-
lookup.result.push(new Candidate(rawCandidate));
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
return lookup;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
module.exports = Client;
|