diff --git a/examples/international_address_autocomplete.js b/examples/international_address_autocomplete.js index a222573..d256227 100644 --- a/examples/international_address_autocomplete.js +++ b/examples/international_address_autocomplete.js @@ -24,6 +24,9 @@ const client = clientBuilder.buildInternationalAddressAutocompleteClient(); const country = "CAN"; const summaryLookup = new Lookup({search: "123 Anson", country}); +// uncomment the following line to add a custom parameter +// summaryLookup.addCustomParameter("max_results", 1); + await handleRequest(summaryLookup, "Response of summary results"); const detailedLookup = new Lookup({addressId: summaryLookup.result[0].addressId, country}); diff --git a/examples/international_street.js b/examples/international_street.js index 8062d63..c3f4478 100644 --- a/examples/international_street.js +++ b/examples/international_street.js @@ -23,6 +23,8 @@ let client = clientBuilder.buildInternationalStreetClient(); // https://www.smarty.com/docs/cloud/international-street-api#http-input-fields let lookup1 = new Lookup("CA", "262 Browndale Cr, Richmond Hill, ON"); +// uncomment the following line to add a custom parameter +// lookup1.addCustomParameter("input_id", 1234); let lookup2 = new Lookup(); lookup2.inputId = "ID-8675309"; diff --git a/examples/us_autocomplete_pro.js b/examples/us_autocomplete_pro.js index 2107091..52a8321 100644 --- a/examples/us_autocomplete_pro.js +++ b/examples/us_autocomplete_pro.js @@ -24,6 +24,8 @@ let client = clientBuilder.buildUsAutocompleteProClient(); // *** Simple Lookup *** let lookup = new Lookup("4770 Lincoln"); +// uncomment the following line to add a custom parameter +// lookup.addCustomParameter("max_results", 3); await handleRequest(lookup, "Simple Lookup"); @@ -60,4 +62,4 @@ async function handleRequest(lookup, lookupType) { } catch(err) { console.log(err) } -} +} \ No newline at end of file diff --git a/examples/us_enrichment.js b/examples/us_enrichment.js index e3778df..1a07371 100644 --- a/examples/us_enrichment.js +++ b/examples/us_enrichment.js @@ -23,6 +23,8 @@ let client = clientBuilder.buildUsEnrichmentClient(); // https://www.smarty.com/docs/us-street-api#input-fields let lookup = new Lookup("334968275"); +// uncomment the following line to add a custom parameter +// lookup.addCustomParameter("include", "group_financial"); handleResponse(lookup).then(); diff --git a/examples/us_extract.js b/examples/us_extract.js index 533b1fe..80bc579 100644 --- a/examples/us_extract.js +++ b/examples/us_extract.js @@ -24,6 +24,9 @@ lookup.aggressive = true; lookup.addressesHaveLineBreaks = false; lookup.addressesPerLine = 1; +// uncomment the following line to add a custom parameter +// lookup.addCustomParameter("addr_line_breaks", false); + await handleRequest(lookup); function logResult(response) { diff --git a/examples/us_reverse_geo.js b/examples/us_reverse_geo.js index 1bc76c3..01ab814 100644 --- a/examples/us_reverse_geo.js +++ b/examples/us_reverse_geo.js @@ -18,7 +18,9 @@ let clientBuilder = new SmartyCore.ClientBuilder(credentials).withLicenses(["us- // .withBaseUrl("YOUR URL") // withBaseUrl() should be used if you are self-hosting the Smarty API let client = clientBuilder.buildUsReverseGeoClient(); -let lookup1 = new Lookup(40.27644, -111.65747, "all"); +let lookup1 = new Lookup(40.27644, -111.65747); +// uncomment the following line to add a custom parameter +// lookup1.addCustomParameter("source", "all"); await handleResponse(lookup1); diff --git a/examples/us_street.js b/examples/us_street.js index 4a22e2b..e09211e 100644 --- a/examples/us_street.js +++ b/examples/us_street.js @@ -45,7 +45,9 @@ lookup2.maxCandidates = 5; let lookup3 = new Lookup(); lookup3.inputId = "8675309"; lookup3.street = "1600 Amphitheatre Parkway Mountain View, CA 94043"; -lookup3.maxCandidates = 1; + +// uncomment the following line to add a custom parameter +// lookup3.addCustomParameter("max_candidates", 1); // NOTE: batches are not supported when using SharedCredentials. let batch = new SmartyCore.Batch(); diff --git a/examples/us_zipcode.js b/examples/us_zipcode.js index 86cdac7..5167f5e 100644 --- a/examples/us_zipcode.js +++ b/examples/us_zipcode.js @@ -33,6 +33,9 @@ let lookup3 = new Lookup(); lookup3.city = "Phoenix"; lookup3.state = "AZ"; +// uncomment the following line to add a custom parameter +// lookup3.addCustomParameter("input_id", 1234); + let batch = new SmartyCore.Batch(); batch.add(lookup1); batch.add(lookup2); diff --git a/src/InputData.js b/src/InputData.js index 4680ea6..1115738 100644 --- a/src/InputData.js +++ b/src/InputData.js @@ -8,6 +8,10 @@ class InputData { if (this.lookupFieldIsPopulated(lookupField)) this.data[apiField] = this.formatData(this.lookup[lookupField]); } + addCustomParameter(key, value) { + this.data[key] = value; + } + formatData(field) { if (Array.isArray(field)) return field.join(";"); else return field; diff --git a/src/international_address_autocomplete/Lookup.js b/src/international_address_autocomplete/Lookup.js index 5af6fcb..ea4df48 100644 --- a/src/international_address_autocomplete/Lookup.js +++ b/src/international_address_autocomplete/Lookup.js @@ -8,6 +8,11 @@ class Lookup { this.maxResults = maxResults; this.includeOnlyLocality = includeOnlyLocality; this.includeOnlyPostalCode = includeOnlyPostalCode; + this.customParameters = {}; + } + + addCustomParameter(key, value) { + this.customParameters[key] = value; } } diff --git a/src/international_street/Lookup.js b/src/international_street/Lookup.js index 7292c26..4357ccb 100644 --- a/src/international_street/Lookup.js +++ b/src/international_street/Lookup.js @@ -35,6 +35,11 @@ class Lookup { this.ensureEnoughInfo = this.ensureEnoughInfo.bind(this); this.ensureValidData = this.ensureValidData.bind(this); + this.customParameters = {}; + } + + addCustomParameter(key, value) { + this.customParameters[key] = value; } ensureEnoughInfo() { diff --git a/src/us_autocomplete_pro/Lookup.js b/src/us_autocomplete_pro/Lookup.js index bdeaafc..f316c96 100644 --- a/src/us_autocomplete_pro/Lookup.js +++ b/src/us_autocomplete_pro/Lookup.js @@ -22,7 +22,12 @@ class Lookup { this.preferZIPCodes = []; this.preferRatio = undefined; this.preferGeolocation = undefined; - this.source = undefined + this.source = undefined; + this.customParameters = {}; + } + + addCustomParameter(key, value) { + this.customParameters[key] = value; } } diff --git a/src/us_enrichment/Lookup.js b/src/us_enrichment/Lookup.js index e61f07b..b1ebe89 100644 --- a/src/us_enrichment/Lookup.js +++ b/src/us_enrichment/Lookup.js @@ -7,7 +7,12 @@ class Lookup { this.dataSubset = dataSubset; this.response = {}; + this.customParameters = {}; }; + + addCustomParameter(key, value) { + this.customParameters[key] = value; + } } module.exports = Lookup; \ No newline at end of file diff --git a/src/us_extract/Lookup.js b/src/us_extract/Lookup.js index 11de6ec..adf43d4 100644 --- a/src/us_extract/Lookup.js +++ b/src/us_extract/Lookup.js @@ -18,6 +18,11 @@ class Lookup { this.aggressive = undefined; this.addressesHaveLineBreaks = undefined; this.addressesPerLine = undefined; + this.customParameters = {}; + } + + addCustomParameter(key, value) { + this.customParameters[key] = value; } } diff --git a/src/us_reverse_geo/Lookup.js b/src/us_reverse_geo/Lookup.js index 67b6e26..abb36da 100644 --- a/src/us_reverse_geo/Lookup.js +++ b/src/us_reverse_geo/Lookup.js @@ -11,6 +11,11 @@ class Lookup { this.longitude = longitude.toFixed(8); this.source = source; this.response = new Response(); + this.customParameters = {}; + } + + addCustomParameter(key, value) { + this.customParameters[key] = value; } } diff --git a/src/us_street/Lookup.js b/src/us_street/Lookup.js index 3a582c4..59d2a61 100644 --- a/src/us_street/Lookup.js +++ b/src/us_street/Lookup.js @@ -35,7 +35,13 @@ class Lookup { this.format = format; this.countySource = countySource; this.result = []; + this.customParameters = {}; } + + addCustomParameter(key, value) { + this.customParameters[key] = value; + } + } module.exports = Lookup; diff --git a/src/us_zipcode/Lookup.js b/src/us_zipcode/Lookup.js index c4d8633..d74c4b4 100644 --- a/src/us_zipcode/Lookup.js +++ b/src/us_zipcode/Lookup.js @@ -10,6 +10,11 @@ class Lookup { this.zipCode = zipCode; this.inputId = inputId; this.result = []; + this.customParameters = {}; + } + + addCustomParameter(key, value) { + this.customParameters[key] = value; } } diff --git a/src/util/buildInputData.js b/src/util/buildInputData.js index 586698b..de254e8 100644 --- a/src/util/buildInputData.js +++ b/src/util/buildInputData.js @@ -3,9 +3,17 @@ const InputData = require("../InputData"); module.exports = (lookup, keyTranslationFormat) => { let inputData = new InputData(lookup); + const hasCustomParameters = Object.keys(lookup.customParameters ?? {}).length > 0; + for (let key in keyTranslationFormat) { inputData.add(key, keyTranslationFormat[key]); } + if (hasCustomParameters) { + for (let key in lookup.customParameters) { + inputData.addCustomParameter(key, lookup.customParameters[key]); + } + } + return inputData.data; }; diff --git a/tests/international_address_autocomplete/test_Lookup.js b/tests/international_address_autocomplete/test_Lookup.js index 0674a09..7d47618 100644 --- a/tests/international_address_autocomplete/test_Lookup.js +++ b/tests/international_address_autocomplete/test_Lookup.js @@ -48,6 +48,7 @@ describe("An International Address Autocomplete lookup", function () { maxResults: 5, includeOnlyLocality: undefined, includeOnlyPostalCode: undefined, + customParameters: {}, }; let lookup = new Lookup(); expect(lookup).to.deep.equal(defaultLookup);