smartystreets-javascript-sdk 5.2.0 → 6.0.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/examples/us_extract.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const SmartySDK = require("smartystreets-javascript-sdk");
|
|
2
|
-
const SmartyCore = SmartySDK.core;
|
|
3
|
-
const Lookup = SmartySDK.usExtract.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
|
-
let clientBuilder = new SmartyCore.ClientBuilder(credentials);
|
|
15
|
-
// .withBaseUrl("YOUR URL") // withBaseUrl() should be used if you are self-hosting the Smarty API
|
|
16
|
-
|
|
17
|
-
let client = clientBuilder.buildUsExtractClient();
|
|
18
|
-
|
|
19
|
-
// Documentation for input fields can be found at:
|
|
20
|
-
// https://www.smarty.com/docs/cloud/us-extract-api#http-request-input-fields
|
|
21
|
-
|
|
22
|
-
let lookup = new Lookup("If you work at 1600 Pennsylvania Ave NW, Washington DC you're gonna have a hard time.");
|
|
23
|
-
lookup.aggressive = true;
|
|
24
|
-
lookup.addressesHaveLineBreaks = false;
|
|
25
|
-
lookup.addressesPerLine = 1;
|
|
26
|
-
|
|
27
|
-
await handleRequest(lookup);
|
|
28
|
-
|
|
29
|
-
function logResult(response) {
|
|
30
|
-
console.log(response.result);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async function handleRequest(lookup) {
|
|
34
|
-
try {
|
|
35
|
-
const response = await client.send(lookup);
|
|
36
|
-
logResult(response);
|
|
37
|
-
} catch(err) {
|
|
38
|
-
console.log(err);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const SmartySDK = require("smartystreets-javascript-sdk");
|
|
2
|
-
const SmartyCore = SmartySDK.core;
|
|
3
|
-
const Lookup = SmartySDK.usReverseGeo.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-reverse-geocoding-cloud"]);
|
|
18
|
-
// .withBaseUrl("YOUR URL") // withBaseUrl() should be used if you are self-hosting the Smarty API
|
|
19
|
-
let client = clientBuilder.buildUsReverseGeoClient();
|
|
20
|
-
|
|
21
|
-
let lookup1 = new Lookup(40.27644, -111.65747, "all");
|
|
22
|
-
|
|
23
|
-
await handleResponse(lookup1);
|
|
24
|
-
|
|
25
|
-
function displayResult(result) {
|
|
26
|
-
console.log(result.response.results[0].address);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function handleError(error) {
|
|
30
|
-
console.log("ERROR:", error);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async function handleResponse(lookup) {
|
|
34
|
-
try {
|
|
35
|
-
const result = await client.send(lookup);
|
|
36
|
-
displayResult(result);
|
|
37
|
-
} catch(err) {
|
|
38
|
-
handleError(err);
|
|
39
|
-
}
|
|
40
|
-
}
|
package/examples/us_street.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
const SmartySDK = require("smartystreets-javascript-sdk");
|
|
2
|
-
const SmartyCore = SmartySDK.core;
|
|
3
|
-
const Lookup = SmartySDK.usStreet.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-rooftop-geocoding-cloud"]);
|
|
18
|
-
// .withBaseUrl("YOUR URL") // withBaseUrl() should be used if you are self-hosting the Smarty API
|
|
19
|
-
|
|
20
|
-
let client = clientBuilder.buildUsStreetApiClient();
|
|
21
|
-
|
|
22
|
-
// Documentation for input fields can be found at:
|
|
23
|
-
// https://www.smarty.com/docs/us-street-api#input-fields
|
|
24
|
-
|
|
25
|
-
let lookup1 = new Lookup();
|
|
26
|
-
lookup1.inputId = "24601"; // Optional ID from your system
|
|
27
|
-
lookup1.addressee = "John Doe";
|
|
28
|
-
lookup1.street = "330 N 100 W";
|
|
29
|
-
lookup1.street2 = "closet under the stairs";
|
|
30
|
-
lookup1.secondary = "APT 2";
|
|
31
|
-
lookup1.urbanization = ""; // Only applies to Puerto Rico addresses
|
|
32
|
-
lookup1.city = "Provo";
|
|
33
|
-
lookup1.state = "Utah";
|
|
34
|
-
lookup1.zipCode = "84601";
|
|
35
|
-
lookup1.maxCandidates = 3;
|
|
36
|
-
lookup1.match = "invalid"; // "invalid" is the most permissive match,
|
|
37
|
-
// this will always return at least one result even if the address is invalid.
|
|
38
|
-
// Refer to the documentation for additional MatchStrategy options.
|
|
39
|
-
|
|
40
|
-
let lookup2 = new Lookup();
|
|
41
|
-
lookup2.street = "1600 Amphitheater Pkwy";
|
|
42
|
-
lookup2.lastLine = "Mountainview, CA";
|
|
43
|
-
lookup2.maxCandidates = 5;
|
|
44
|
-
|
|
45
|
-
let lookup3 = new Lookup();
|
|
46
|
-
lookup3.inputId = "8675309";
|
|
47
|
-
lookup3.street = "1600 Amphitheatre Parkway Mountain View, CA 94043";
|
|
48
|
-
lookup3.maxCandidates = 1;
|
|
49
|
-
|
|
50
|
-
// NOTE: batches are not supported when using SharedCredentials.
|
|
51
|
-
let batch = new SmartyCore.Batch();
|
|
52
|
-
batch.add(lookup1);
|
|
53
|
-
batch.add(lookup2);
|
|
54
|
-
batch.add(lookup3);
|
|
55
|
-
|
|
56
|
-
await handleResponse(batch);
|
|
57
|
-
|
|
58
|
-
function handleSuccess(response) {
|
|
59
|
-
response.lookups.map(lookup => console.log(lookup.result));
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function handleError(response) {
|
|
63
|
-
console.log(response);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async function handleResponse(lookup) {
|
|
67
|
-
try {
|
|
68
|
-
const result = await client.send(lookup);
|
|
69
|
-
handleSuccess(result);
|
|
70
|
-
} catch(err) {
|
|
71
|
-
handleError(err);
|
|
72
|
-
}
|
|
73
|
-
}
|
package/examples/us_zipcode.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
const SmartySDK = require("smartystreets-javascript-sdk");
|
|
2
|
-
const SmartyCore = SmartySDK.core;
|
|
3
|
-
const Lookup = SmartySDK.usZipcode.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
|
-
let clientBuilder = new SmartyCore.ClientBuilder(credentials);
|
|
15
|
-
// .withBaseUrl("YOUR URL") // withBaseUrl() should be used if you are self-hosting the Smarty API
|
|
16
|
-
|
|
17
|
-
let client = clientBuilder.buildUsZipcodeClient();
|
|
18
|
-
|
|
19
|
-
// Documentation for input fields can be found at:
|
|
20
|
-
// https://www.smarty.com/docs/us-zipcode-api#input-fields
|
|
21
|
-
|
|
22
|
-
let lookup1 = new Lookup();
|
|
23
|
-
lookup1.inputId = "01189998819991197253"; // Optional ID from your system
|
|
24
|
-
lookup1.zipCode = "49786";
|
|
25
|
-
|
|
26
|
-
let lookup2 = new Lookup();
|
|
27
|
-
lookup2.inputId = "dfc33cb6-829e-4fea-aa1b-b6d6580f0817";
|
|
28
|
-
lookup2.city = "Provo";
|
|
29
|
-
lookup2.state = "UT";
|
|
30
|
-
lookup2.zipCode = "84604";
|
|
31
|
-
|
|
32
|
-
let lookup3 = new Lookup();
|
|
33
|
-
lookup3.city = "Phoenix";
|
|
34
|
-
lookup3.state = "AZ";
|
|
35
|
-
|
|
36
|
-
let batch = new SmartyCore.Batch();
|
|
37
|
-
batch.add(lookup1);
|
|
38
|
-
batch.add(lookup2);
|
|
39
|
-
batch.add(lookup3);
|
|
40
|
-
|
|
41
|
-
await handleResponse(batch);
|
|
42
|
-
|
|
43
|
-
function viewResults(response) {
|
|
44
|
-
response.lookups.map(lookup => lookup.result.map(candidate => {
|
|
45
|
-
candidate.cities.map(city => console.log(city.city));
|
|
46
|
-
// candidate.zipcodes.map(zipcode => console.log(zipcode.zipcode));
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async function handleResponse(lookup) {
|
|
51
|
-
try {
|
|
52
|
-
const result = await client.send(lookup);
|
|
53
|
-
viewResults(result);
|
|
54
|
-
} catch(err) {
|
|
55
|
-
console.log(err);
|
|
56
|
-
}
|
|
57
|
-
}
|
package/index.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
core: {
|
|
3
|
-
Batch: require("./src/Batch"),
|
|
4
|
-
ClientBuilder: require("./src/ClientBuilder"),
|
|
5
|
-
buildClient: require("./src/util/buildClients"),
|
|
6
|
-
SharedCredentials: require("./src/SharedCredentials"),
|
|
7
|
-
StaticCredentials: require("./src/StaticCredentials"),
|
|
8
|
-
Errors: require("./src/Errors"),
|
|
9
|
-
},
|
|
10
|
-
usStreet: {
|
|
11
|
-
Lookup: require("./src/us_street/Lookup"),
|
|
12
|
-
Candidate: require("./src/us_street/Candidate"),
|
|
13
|
-
},
|
|
14
|
-
usZipcode: {
|
|
15
|
-
Lookup: require("./src/us_zipcode/Lookup"),
|
|
16
|
-
Result: require("./src/us_zipcode/Result"),
|
|
17
|
-
},
|
|
18
|
-
usAutocompletePro: {
|
|
19
|
-
Lookup: require("./src/us_autocomplete_pro/Lookup"),
|
|
20
|
-
Suggestion: require("./src/us_autocomplete_pro/Suggestion"),
|
|
21
|
-
},
|
|
22
|
-
usExtract: {
|
|
23
|
-
Lookup: require("./src/us_extract/Lookup"),
|
|
24
|
-
Result: require("./src/us_extract/Result"),
|
|
25
|
-
},
|
|
26
|
-
internationalStreet: {
|
|
27
|
-
Lookup: require("./src/international_street/Lookup"),
|
|
28
|
-
Candidate: require("./src/international_street/Candidate"),
|
|
29
|
-
},
|
|
30
|
-
usReverseGeo: {
|
|
31
|
-
Lookup: require("./src/us_reverse_geo/Lookup"),
|
|
32
|
-
},
|
|
33
|
-
internationalAddressAutocomplete: {
|
|
34
|
-
Lookup: require("./src/international_address_autocomplete/Lookup"),
|
|
35
|
-
Suggestion: require("./src/international_address_autocomplete/Suggestion"),
|
|
36
|
-
},
|
|
37
|
-
usEnrichment: {
|
|
38
|
-
Lookup: require("./src/us_enrichment/Lookup"),
|
|
39
|
-
Response: require("./src/us_enrichment/Response"),
|
|
40
|
-
},
|
|
41
|
-
};
|
package/js-sdk-demo.cast
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
{"version": 2, "width": 117, "height": 45, "timestamp": 1530134182, "idle_time_limit": 1.0, "env": {"SHELL": "/bin/bash", "TERM": "xterm-256color"}}
|
|
2
|
-
[0.010229, "o", "\u001b[?1034h$ "]
|
|
3
|
-
[0.467947, "o", "n"]
|
|
4
|
-
[0.524226, "o", "p"]
|
|
5
|
-
[0.70808, "o", "m"]
|
|
6
|
-
[1.052436, "o", " "]
|
|
7
|
-
[1.348151, "o", "i"]
|
|
8
|
-
[1.452182, "o", "n"]
|
|
9
|
-
[1.523968, "o", "s"]
|
|
10
|
-
[1.667973, "o", "t"]
|
|
11
|
-
[1.764448, "o", "a"]
|
|
12
|
-
[1.907995, "o", "l"]
|
|
13
|
-
[2.052337, "o", "l"]
|
|
14
|
-
[2.196398, "o", " "]
|
|
15
|
-
[2.68405, "o", "s"]
|
|
16
|
-
[2.804179, "o", "m"]
|
|
17
|
-
[2.915962, "o", "a"]
|
|
18
|
-
[3.10013, "o", "r"]
|
|
19
|
-
[3.315956, "o", "t"]
|
|
20
|
-
[3.796418, "o", "y"]
|
|
21
|
-
[4.068496, "o", "s"]
|
|
22
|
-
[4.244361, "o", "t"]
|
|
23
|
-
[4.332117, "o", "r"]
|
|
24
|
-
[4.620157, "o", "e"]
|
|
25
|
-
[4.748372, "o", "e"]
|
|
26
|
-
[4.93247, "o", "t"]
|
|
27
|
-
[5.756319, "o", "s"]
|
|
28
|
-
[6.340584, "o", "-"]
|
|
29
|
-
[6.860414, "o", "j"]
|
|
30
|
-
[6.971776, "o", "a"]
|
|
31
|
-
[7.268031, "o", "v"]
|
|
32
|
-
[7.427947, "o", "a"]
|
|
33
|
-
[7.900124, "o", "s"]
|
|
34
|
-
[8.06054, "o", "c"]
|
|
35
|
-
[8.340057, "o", "r"]
|
|
36
|
-
[8.604094, "o", "i"]
|
|
37
|
-
[8.708032, "o", "p"]
|
|
38
|
-
[9.020098, "o", "t"]
|
|
39
|
-
[9.443566, "o", "-"]
|
|
40
|
-
[10.420419, "o", "s"]
|
|
41
|
-
[10.578756, "o", "d"]
|
|
42
|
-
[11.075609, "o", "k"]
|
|
43
|
-
[11.619051, "o", "\r\n"]
|
|
44
|
-
[11.994868, "o", "\u001b[?25l"]
|
|
45
|
-
[11.997323, "o", "⸨\u001b[90m░░░░░░░░░░░░░░░░░░\u001b[0m⸩ ⠇ rollbackFailedOptional: \u001b[34;40mverb\u001b[0m \u001b[35mnpm-session\u001b[0m 80cbcd75622a93e0\u001b[0m\u001b[K\r"]
|
|
46
|
-
[12.392273, "o", "⸨\u001b[90m░░░░░░░░░░░░░░░░░░\u001b[0m⸩ ⠇ rollbackFailedOptional: \u001b[34;40mverb\u001b[0m \u001b[35mnpm-session\u001b[0m 80cbcd75622a93e0\u001b[0m\u001b[K\r"]
|
|
47
|
-
[12.443351, "o", "⸨\u001b[90m░░░░░░░░░░░░░░░░░░\u001b[0m⸩ ⠇ rollbackFailedOptional: \u001b[34;40mverb\u001b[0m \u001b[35mnpm-session\u001b[0m 80cbcd75622a93e0\u001b[0m\u001b[K\r"]
|
|
48
|
-
[12.493195, "o", "⸨\u001b[90m░░░░░░░░░░░░░░░░░░\u001b[0m⸩ ⠇ rollbackFailedOptional: \u001b[34;40mverb\u001b[0m \u001b[35mnpm-session\u001b[0m 80cbcd75622a93e0\u001b[0m\u001b[K\r"]
|
|
49
|
-
[12.547335, "o", "⸨\u001b[90m░░░░░░░░░░░░░░░░░░\u001b[0m⸩ ⠴ loadDep:promise: \u001b[7msill\u001b[0m \u001b[35mresolveWithNewModule\u001b[0m smartystreets-javascript-sdk@1.0.\u001b[0m\u001b[K\r"]
|
|
50
|
-
[12.601971, "o", "⸨\u001b[7m \u001b[27m\u001b[90m░░░░░░░░░░░\u001b[0m⸩ ⠴ extract:smartystreets-javascript-sdk: \u001b[34;40mverb\u001b[0m \u001b[35mlock\u001b[0m using /Users/Neo/.npm/_locks\u001b[0m\u001b[K\r"]
|
|
51
|
-
[12.656729, "o", "⸨\u001b[7m \u001b[27m\u001b[90m░░░░░░░░░░░\u001b[0m⸩ ⠴ extract:smartystreets-javascript-sdk: \u001b[34;40mverb\u001b[0m \u001b[35mlock\u001b[0m using /Users/Neo/.npm/_locks\u001b[0m\u001b[K\r"]
|
|
52
|
-
[12.712334, "o", "⸨\u001b[7m \u001b[27m\u001b[90m░░░░░░░░░░░\u001b[0m⸩ ⠴ extract:smartystreets-javascript-sdk: \u001b[34;40mverb\u001b[0m \u001b[35mlock\u001b[0m using /Users/Neo/.npm/_locks\u001b[0m\u001b[K\r"]
|
|
53
|
-
[12.765091, "o", "⸨\u001b[7m \u001b[27m\u001b[90m░░░░░░░░░░░\u001b[0m⸩ ⠴ extract:smartystreets-javascript-sdk: \u001b[34;40mverb\u001b[0m \u001b[35mlock\u001b[0m using /Users/Neo/.npm/_locks\u001b[0m\u001b[K\r"]
|
|
54
|
-
[12.815536, "o", "⸨\u001b[7m \u001b[27m\u001b[90m░░░░░░░░░░░\u001b[0m⸩ ⠴ extract:smartystreets-javascript-sdk: \u001b[34;40mverb\u001b[0m \u001b[35mlock\u001b[0m using /Users/Neo/.npm/_locks\u001b[0m\u001b[K\r"]
|
|
55
|
-
[12.837371, "o", "\r\u001b[K\u001b[?25h"]
|
|
56
|
-
[12.854763, "o", "\r\n"]
|
|
57
|
-
[12.855413, "o", "+ smartystreets-javascript-sdk@1.0.4\r\nadded 1 package in 0.872s\r\n"]
|
|
58
|
-
[12.863697, "o", "$ "]
|
|
59
|
-
[14.195072, "o", "\r\n"]
|
|
60
|
-
[14.195235, "o", "$ "]
|
|
61
|
-
[14.354464, "o", "\r\n"]
|
|
62
|
-
[14.354626, "o", "$ "]
|
|
63
|
-
[14.546544, "o", "\r\n"]
|
|
64
|
-
[14.546779, "o", "$ "]
|
|
65
|
-
[15.211593, "o", "c"]
|
|
66
|
-
[15.355119, "o", "a"]
|
|
67
|
-
[15.692111, "o", "t"]
|
|
68
|
-
[15.892141, "o", " "]
|
|
69
|
-
[16.956311, "o", "e"]
|
|
70
|
-
[17.788102, "o", "x"]
|
|
71
|
-
[18.03553, "o", "ample.js "]
|
|
72
|
-
[18.522916, "o", "\r\n"]
|
|
73
|
-
[18.527357, "o", "const SmartyStreetsSDK = require(\"smartystreets-javascript-sdk\");\r\nconst SmartyStreetsCore = SmartyStreetsSDK.core;\r\nconst Lookup = SmartyStreetsSDK.usStreet.Lookup;\r\n\r\n// This keypair will have been deleted by the time you are watching this video...\r\nlet authId = \"41c45025-e7a5-1ae5-bb76-8647a26f45ba\";\r\nlet authToken = \"xmztSBdqN6TVO5nUvAa8\";\r\n\r\nconsole.log(\"Step 0. Wire up the client with your keypair.\");\r\nlet clientBuilder = new SmartyStreetsCore.ClientBuilder(new SmartyStreetsCore.StaticCredentials(authId, authToken));\r\nlet client = clientBuilder.buildUsStreetApiClient();\r\n\r\nconsole.log(\"Step 1. Make a lookup. (BTW, you can also send entire batches of lookups...)\");\r\nlet lookup = new Lookup();\r\nlookup.street = \"1 Rosedale\";\r\nlookup.city = \"Baltimore\";\r\nlookup.state = \"MD\";\r\nlookup.maxCandidates = 10;\r\n\r\nconsole.log(\"Step 2. Send the lookup.\");\r\nclient.send(lookup)\r\n\t.then(handleSuccess)\r\n\t.catch(handleError);\r\n\r\nfunction handleSuccess(response) {\r\n\tconsole.log(\"Step 3. Show the resulting candidate address"]
|
|
74
|
-
[18.527549, "o", "es:\");\r\n\tlet lookup = response.lookups[0];\r\n\tlookup.result.map(candidate => console.log(` ${candidate.deliveryLine1}, ${candidate.lastLine}`));\r\n}\r\n\r\nfunction handleError(response) {\r\n\tconsole.log(response);\r\n}\r\n"]
|
|
75
|
-
[18.527961, "o", "$ "]
|
|
76
|
-
[20.515216, "o", "\r\n"]
|
|
77
|
-
[20.515496, "o", "$ "]
|
|
78
|
-
[20.698906, "o", "\r\n"]
|
|
79
|
-
[20.698986, "o", "$ "]
|
|
80
|
-
[23.308251, "o", "n"]
|
|
81
|
-
[23.396131, "o", "o"]
|
|
82
|
-
[23.492332, "o", "d"]
|
|
83
|
-
[23.587821, "o", "e"]
|
|
84
|
-
[23.940086, "o", " "]
|
|
85
|
-
[25.244151, "o", "e"]
|
|
86
|
-
[25.476053, "o", "x"]
|
|
87
|
-
[25.627144, "o", "ample.js "]
|
|
88
|
-
[26.819458, "o", "\r\n"]
|
|
89
|
-
[26.925891, "o", "Step 0. Wire up the client with your keypair.\r\n"]
|
|
90
|
-
[26.926939, "o", "Step 1. Make a lookup. (BTW, you can also send entire batches of lookups...)\r\n"]
|
|
91
|
-
[26.927133, "o", "Step 2. Send the lookup.\r\n"]
|
|
92
|
-
[27.183185, "o", "Step 3. Show the resulting candidate addresses:\r\n"]
|
|
93
|
-
[27.183252, "o", " 1 N Rosedale St, Baltimore MD 21229-3737\r\n 1 S Rosedale St, Baltimore MD 21229-3739\r\n"]
|
|
94
|
-
[27.18749, "o", "$ "]
|
|
95
|
-
[32.083944, "o", "exit\r\n"]
|
package/src/AgentSender.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
class AgentSender {
|
|
2
|
-
constructor(innerSender) {
|
|
3
|
-
this.sender = innerSender;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
send(request) {
|
|
7
|
-
request.parameters.agent = "smarty (sdk:javascript@" + require("../package.json").version + ")";
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
this.sender.send(request)
|
|
10
|
-
.then(resolve)
|
|
11
|
-
.catch(reject);
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
module.exports = AgentSender;
|
package/src/BaseUrlSender.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
class BaseUrlSender {
|
|
2
|
-
constructor(innerSender, urlOverride) {
|
|
3
|
-
this.urlOverride = urlOverride;
|
|
4
|
-
this.sender = innerSender;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
send(request) {
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
request.baseUrl = `${this.urlOverride}${request.baseUrlParam ? `/${request.baseUrlParam}` : ""}`;
|
|
10
|
-
|
|
11
|
-
this.sender.send(request)
|
|
12
|
-
.then(resolve)
|
|
13
|
-
.catch(reject);
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
module.exports = BaseUrlSender;
|
package/src/Batch.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
const BatchFullError = require("./Errors").BatchFullError;
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This class contains a collection of up to 100 lookups to be sent to one of the Smarty APIs<br>
|
|
5
|
-
* all at once. This is more efficient than sending them one at a time.
|
|
6
|
-
*/
|
|
7
|
-
class Batch {
|
|
8
|
-
constructor () {
|
|
9
|
-
this.lookups = [];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
add (lookup) {
|
|
13
|
-
if (this.lookupsHasRoomForLookup()) this.lookups.push(lookup);
|
|
14
|
-
else throw new BatchFullError();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
lookupsHasRoomForLookup() {
|
|
18
|
-
const maxNumberOfLookups = 100;
|
|
19
|
-
return this.lookups.length < maxNumberOfLookups;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
length() {
|
|
23
|
-
return this.lookups.length;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
getByIndex(index) {
|
|
27
|
-
return this.lookups[index];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
getByInputId(inputId) {
|
|
31
|
-
return this.lookups.filter(lookup => {
|
|
32
|
-
return lookup.inputId === inputId;
|
|
33
|
-
})[0];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Clears the lookups stored in the batch so it can be used again.<br>
|
|
38
|
-
* This helps avoid the overhead of building a new Batch object for each group of lookups.
|
|
39
|
-
*/
|
|
40
|
-
clear () {
|
|
41
|
-
this.lookups = [];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
isEmpty () {
|
|
45
|
-
return this.length() === 0;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
module.exports = Batch;
|
package/src/ClientBuilder.js
DELETED
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
const HttpSender = require("./HttpSender");
|
|
2
|
-
const SigningSender = require("./SigningSender");
|
|
3
|
-
const BaseUrlSender = require("./BaseUrlSender");
|
|
4
|
-
const AgentSender = require("./AgentSender");
|
|
5
|
-
const StaticCredentials = require("./StaticCredentials");
|
|
6
|
-
const SharedCredentials = require("./SharedCredentials");
|
|
7
|
-
const CustomHeaderSender = require("./CustomHeaderSender");
|
|
8
|
-
const StatusCodeSender = require("./StatusCodeSender");
|
|
9
|
-
const LicenseSender = require("./LicenseSender");
|
|
10
|
-
const BadCredentialsError = require("./Errors").BadCredentialsError;
|
|
11
|
-
const RetrySender = require("./RetrySender.js");
|
|
12
|
-
const Sleeper = require("./util/Sleeper.js");
|
|
13
|
-
|
|
14
|
-
//TODO: refactor this to work more cleanly with a bundler.
|
|
15
|
-
const UsStreetClient = require("./us_street/Client");
|
|
16
|
-
const UsZipcodeClient = require("./us_zipcode/Client");
|
|
17
|
-
const UsAutocompleteProClient = require("./us_autocomplete_pro/Client");
|
|
18
|
-
const UsExtractClient = require("./us_extract/Client");
|
|
19
|
-
const InternationalStreetClient = require("./international_street/Client");
|
|
20
|
-
const UsReverseGeoClient = require("./us_reverse_geo/Client");
|
|
21
|
-
const InternationalAddressAutocompleteClient = require("./international_address_autocomplete/Client");
|
|
22
|
-
const UsEnrichmentClient = require("./us_enrichment/Client");
|
|
23
|
-
|
|
24
|
-
const INTERNATIONAL_STREET_API_URI = "https://international-street.api.smarty.com/verify";
|
|
25
|
-
const US_AUTOCOMPLETE_PRO_API_URL = "https://us-autocomplete-pro.api.smarty.com/lookup";
|
|
26
|
-
const US_EXTRACT_API_URL = "https://us-extract.api.smarty.com/";
|
|
27
|
-
const US_STREET_API_URL = "https://us-street.api.smarty.com/street-address";
|
|
28
|
-
const US_ZIP_CODE_API_URL = "https://us-zipcode.api.smarty.com/lookup";
|
|
29
|
-
const US_REVERSE_GEO_API_URL = "https://us-reverse-geo.api.smarty.com/lookup";
|
|
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";
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* The ClientBuilder class helps you build a client object for one of the supported Smarty APIs.<br>
|
|
35
|
-
* You can use ClientBuilder's methods to customize settings like maximum retries or timeout duration. These methods<br>
|
|
36
|
-
* are chainable, so you can usually get set up with one line of code.
|
|
37
|
-
*/
|
|
38
|
-
class ClientBuilder {
|
|
39
|
-
constructor(signer) {
|
|
40
|
-
if (noCredentialsProvided()) throw new BadCredentialsError();
|
|
41
|
-
|
|
42
|
-
this.signer = signer;
|
|
43
|
-
this.httpSender = undefined;
|
|
44
|
-
this.maxRetries = 5;
|
|
45
|
-
this.maxTimeout = 10000;
|
|
46
|
-
this.baseUrl = undefined;
|
|
47
|
-
this.proxy = undefined;
|
|
48
|
-
this.customHeaders = {};
|
|
49
|
-
this.debug = undefined;
|
|
50
|
-
this.licenses = [];
|
|
51
|
-
|
|
52
|
-
function noCredentialsProvided() {
|
|
53
|
-
return !signer instanceof StaticCredentials || !signer instanceof SharedCredentials;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @param retries The maximum number of times to retry sending the request to the API. (Default is 5)
|
|
59
|
-
* @return Returns <b>this</b> to accommodate method chaining.
|
|
60
|
-
*/
|
|
61
|
-
withMaxRetries(retries) {
|
|
62
|
-
this.maxRetries = retries;
|
|
63
|
-
return this;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* @param timeout The maximum time (in milliseconds) to wait for a connection, and also to wait for <br>
|
|
68
|
-
* the response to be read. (Default is 10000)
|
|
69
|
-
* @return Returns <b>this</b> to accommodate method chaining.
|
|
70
|
-
*/
|
|
71
|
-
withMaxTimeout(timeout) {
|
|
72
|
-
this.maxTimeout = timeout;
|
|
73
|
-
return this;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* @param sender Default is a series of nested senders. See <b>buildSender()</b>.
|
|
78
|
-
* @return Returns <b>this</b> to accommodate method chaining.
|
|
79
|
-
*/
|
|
80
|
-
withSender(sender) {
|
|
81
|
-
this.httpSender = sender;
|
|
82
|
-
return this;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* This may be useful when using a local installation of the Smarty APIs.
|
|
87
|
-
* @param url Defaults to the URL for the API corresponding to the <b>Client</b> object being built.
|
|
88
|
-
* @return Returns <b>this</b> to accommodate method chaining.
|
|
89
|
-
*/
|
|
90
|
-
withBaseUrl(url) {
|
|
91
|
-
this.baseUrl = url;
|
|
92
|
-
return this;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Use this to specify a proxy through which to send all lookups.
|
|
97
|
-
* @param host The host of the proxy server (do not include the port).
|
|
98
|
-
* @param port The port on the proxy server to which you wish to connect.
|
|
99
|
-
* @param protocol The protocol on the proxy server to which you wish to connect. If the proxy server uses HTTPS, then you must set the protocol to 'https'.
|
|
100
|
-
* @param username The username to login to the proxy.
|
|
101
|
-
* @param password The password to login to the proxy.
|
|
102
|
-
* @return Returns <b>this</b> to accommodate method chaining.
|
|
103
|
-
*/
|
|
104
|
-
withProxy(host, port, protocol, username, password) {
|
|
105
|
-
this.proxy = {
|
|
106
|
-
host: host,
|
|
107
|
-
port: port,
|
|
108
|
-
protocol: protocol,
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
if (username && password) {
|
|
112
|
-
this.proxy.auth = {
|
|
113
|
-
username: username,
|
|
114
|
-
password: password,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return this;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Use this to add any additional headers you need.
|
|
123
|
-
* @param customHeaders A String to Object <b>Map</b> of header name/value pairs.
|
|
124
|
-
* @return Returns <b>this</b> to accommodate method chaining.
|
|
125
|
-
*/
|
|
126
|
-
withCustomHeaders(customHeaders) {
|
|
127
|
-
this.customHeaders = customHeaders;
|
|
128
|
-
|
|
129
|
-
return this;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Enables debug mode, which will print information about the HTTP request and response to console.log
|
|
134
|
-
* @return Returns <b>this</b> to accommodate method chaining.
|
|
135
|
-
*/
|
|
136
|
-
withDebug() {
|
|
137
|
-
this.debug = true;
|
|
138
|
-
|
|
139
|
-
return this;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Allows the caller to specify the subscription license (aka "track") they wish to use.
|
|
144
|
-
* @param licenses A String Array of licenses.
|
|
145
|
-
* @returns Returns <b>this</b> to accommodate method chaining.
|
|
146
|
-
*/
|
|
147
|
-
withLicenses(licenses) {
|
|
148
|
-
this.licenses = licenses;
|
|
149
|
-
|
|
150
|
-
return this;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
buildSender() {
|
|
154
|
-
if (this.httpSender) return this.httpSender;
|
|
155
|
-
|
|
156
|
-
const httpSender = new HttpSender(this.maxTimeout, this.proxy, this.debug);
|
|
157
|
-
const statusCodeSender = new StatusCodeSender(httpSender);
|
|
158
|
-
const signingSender = new SigningSender(statusCodeSender, this.signer);
|
|
159
|
-
let agentSender = new AgentSender(signingSender);
|
|
160
|
-
if (this.maxRetries > 0) {
|
|
161
|
-
const retrySender = new RetrySender(this.maxRetries, signingSender, new Sleeper());
|
|
162
|
-
agentSender = new AgentSender(retrySender);
|
|
163
|
-
}
|
|
164
|
-
const customHeaderSender = new CustomHeaderSender(agentSender, this.customHeaders);
|
|
165
|
-
const baseUrlSender = new BaseUrlSender(customHeaderSender, this.baseUrl);
|
|
166
|
-
const licenseSender = new LicenseSender(baseUrlSender, this.licenses);
|
|
167
|
-
|
|
168
|
-
return licenseSender;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
buildClient(baseUrl, Client) {
|
|
172
|
-
if (!this.baseUrl) {
|
|
173
|
-
this.baseUrl = baseUrl;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return new Client(this.buildSender());
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
buildUsStreetApiClient() {
|
|
180
|
-
return this.buildClient(US_STREET_API_URL, UsStreetClient);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
buildUsZipcodeClient() {
|
|
184
|
-
return this.buildClient(US_ZIP_CODE_API_URL, UsZipcodeClient);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
buildUsAutocompleteProClient() {
|
|
188
|
-
return this.buildClient(US_AUTOCOMPLETE_PRO_API_URL, UsAutocompleteProClient);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
buildUsExtractClient() {
|
|
192
|
-
return this.buildClient(US_EXTRACT_API_URL, UsExtractClient);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
buildInternationalStreetClient() {
|
|
196
|
-
return this.buildClient(INTERNATIONAL_STREET_API_URI, InternationalStreetClient);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
buildUsReverseGeoClient() {
|
|
200
|
-
return this.buildClient(US_REVERSE_GEO_API_URL, UsReverseGeoClient);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
buildInternationalAddressAutocompleteClient() {
|
|
204
|
-
return this.buildClient(INTERNATIONAL_ADDRESS_AUTOCOMPLETE_API_URL, InternationalAddressAutocompleteClient);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
buildUsEnrichmentClient() {
|
|
208
|
-
return this.buildClient(US_ENRICHMENT_API_URL, UsEnrichmentClient);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
module.exports = ClientBuilder;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
class CustomHeaderSender {
|
|
2
|
-
constructor(innerSender, customHeaders) {
|
|
3
|
-
this.sender = innerSender;
|
|
4
|
-
this.customHeaders = customHeaders;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
send(request) {
|
|
8
|
-
for (let key in this.customHeaders) {
|
|
9
|
-
request.headers[key] = this.customHeaders[key];
|
|
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 = CustomHeaderSender;
|