From b645d766e57ad52f24687024980e184ae4c184d4 Mon Sep 17 00:00:00 2001 From: Mae Evans Date: Tue, 9 Jun 2026 09:56:13 -0600 Subject: [PATCH 1/2] Integrated the business_name input field --- Makefile | 2 + .../us_enrichment_business_name_search.mjs | 35 +++++++++++++++++ .../us_enrichment_business_name_search.ts | 38 +++++++++++++++++++ src/us_enrichment/Client.ts | 5 ++- src/us_enrichment/business/SummaryLookup.ts | 1 + tests/us_enrichment/test_BusinessClient.ts | 26 +++++++++++++ tests/us_enrichment/test_BusinessLookups.ts | 1 + 7 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 examples/us_enrichment_business_name_search.mjs create mode 100644 examples/us_enrichment_business_name_search.ts diff --git a/Makefile b/Makefile index 8946b02b..0aa184fe 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,7 @@ examples-ts: build @npx tsx examples/us_reverse_geo.ts || true @npx tsx examples/us_enrichment.ts || true @npx tsx examples/us_enrichment_business.ts || true + @npx tsx examples/us_enrichment_business_name_search.ts || true @npx tsx examples/us_enrichment_etag.ts || true @npx tsx examples/international_street.ts || true @npx tsx examples/international_address_autocomplete.ts || true @@ -48,6 +49,7 @@ examples-js: build @node examples/us_reverse_geo.mjs || true @node examples/us_enrichment.mjs || true @node examples/us_enrichment_business.mjs || true + @node examples/us_enrichment_business_name_search.mjs || true @node examples/us_enrichment_etag.mjs || true @node examples/international_street.mjs || true @node examples/international_address_autocomplete.mjs || true diff --git a/examples/us_enrichment_business_name_search.mjs b/examples/us_enrichment_business_name_search.mjs new file mode 100644 index 00000000..62059deb --- /dev/null +++ b/examples/us_enrichment_business_name_search.mjs @@ -0,0 +1,35 @@ +import SmartySDK, { NotModifiedError } from "smartystreets-javascript-sdk"; + +const SmartyCore = SmartySDK.core; +const { BusinessSummaryLookup, BusinessDetailLookup } = SmartySDK.usEnrichment; + +const authId = process.env.SMARTY_AUTH_ID; +const authToken = process.env.SMARTY_AUTH_TOKEN; +const credentials = new SmartyCore.BasicAuthCredentials(authId, authToken); + +const client = new SmartyCore.ClientBuilder(credentials).buildUsEnrichmentClient(); + +async function main() { + const summaryLookup = new BusinessSummaryLookup(); + summaryLookup.businessName = "Smarty"; + summaryLookup.city = "atlanta"; + + const summary = await client.sendBusinessSummary(summaryLookup); + const firstResult = summary.results?.[0]; + if (!firstResult || firstResult.businesses.length === 0) { + console.log("No businesses found for this business-name search"); + return; + } + + for (const entry of firstResult.businesses) { + console.log(`${entry.businessId}\t${entry.companyName}`); + } + + const firstBusinessId = firstResult.businesses[0].businessId; + const detailLookup = new BusinessDetailLookup(firstBusinessId); + const detail = await client.sendBusinessDetail(detailLookup); + console.log("\n--- Detail for", firstBusinessId, "---"); + console.log(detail.result); +} + +main().catch((err) => console.error(err)); diff --git a/examples/us_enrichment_business_name_search.ts b/examples/us_enrichment_business_name_search.ts new file mode 100644 index 00000000..dfa86bc9 --- /dev/null +++ b/examples/us_enrichment_business_name_search.ts @@ -0,0 +1,38 @@ +import { + ClientBuilder, + BasicAuthCredentials, + BusinessSummaryLookup, + BusinessDetailLookup, + NotModifiedError, +} from "smartystreets-javascript-sdk"; + +const authId = process.env.SMARTY_AUTH_ID!; +const authToken = process.env.SMARTY_AUTH_TOKEN!; +const credentials = new BasicAuthCredentials(authId, authToken); + +const client = new ClientBuilder(credentials).buildUsEnrichmentClient(); + +async function main(): Promise { + const summaryLookup = new BusinessSummaryLookup(); + summaryLookup.businessName = "delta air"; + summaryLookup.city = "atlanta"; + + const summary = await client.sendBusinessSummary(summaryLookup); + const firstResult = summary.results?.[0]; + if (!firstResult || firstResult.businesses.length === 0) { + console.log("No businesses found for this business-name search"); + return; + } + + for (const entry of firstResult.businesses) { + console.log(`${entry.businessId}\t${entry.companyName}`); + } + + const firstBusinessId = firstResult.businesses[0]!.businessId!; + const detailLookup = new BusinessDetailLookup(firstBusinessId); + const detail = await client.sendBusinessDetail(detailLookup); + console.log("\n--- Detail for", firstBusinessId, "---"); + console.log(detail.result); +} + +main().catch((err) => console.error(err)); diff --git a/src/us_enrichment/Client.ts b/src/us_enrichment/Client.ts index 2b598d5a..debae707 100644 --- a/src/us_enrichment/Client.ts +++ b/src/us_enrichment/Client.ts @@ -76,9 +76,9 @@ export default class Client { sendBusinessSummary(lookup: SummaryLookup): Promise { if (!lookup) throw new UndefinedLookupError(); - if (isBlank(lookup.smartyKey) && isBlank(lookup.street) && isBlank(lookup.freeform)) { + if (isBlank(lookup.smartyKey) && isBlank(lookup.street) && isBlank(lookup.freeform) && isBlank(lookup.businessName)) { throw new SmartyError( - "Business.Summary lookup requires one of 'smartyKey', 'street', or 'freeform' to be set", + "Business.Summary lookup requires one of 'smartyKey', 'street', 'freeform', or 'business_name' to be set", ); } @@ -88,6 +88,7 @@ export default class Client { } else { request.baseUrlParam = "search/business"; if (!isBlank(lookup.freeform)) request.parameters["freeform"] = lookup.freeform!; + if (!isBlank(lookup.businessName)) request.parameters["business_name"] = lookup.businessName!; if (!isBlank(lookup.street)) request.parameters["street"] = lookup.street!; if (!isBlank(lookup.city)) request.parameters["city"] = lookup.city!; if (!isBlank(lookup.state)) request.parameters["state"] = lookup.state!; diff --git a/src/us_enrichment/business/SummaryLookup.ts b/src/us_enrichment/business/SummaryLookup.ts index 9bdcc4e4..4839f20d 100644 --- a/src/us_enrichment/business/SummaryLookup.ts +++ b/src/us_enrichment/business/SummaryLookup.ts @@ -4,6 +4,7 @@ import SummaryResult from "./SummaryResult.js"; export default class SummaryLookup extends EnrichmentLookupBase { smartyKey: string | undefined; freeform: string | undefined; + businessName: string | undefined; street: string | undefined; city: string | undefined; state: string | undefined; diff --git a/tests/us_enrichment/test_BusinessClient.ts b/tests/us_enrichment/test_BusinessClient.ts index 4cfa757d..4d43e43f 100644 --- a/tests/us_enrichment/test_BusinessClient.ts +++ b/tests/us_enrichment/test_BusinessClient.ts @@ -52,6 +52,32 @@ describe("Client.sendBusinessSummary", function () { }); }); + it("targets /search/business with a business_name param", function () { + const mockSender = new MockSender(); + const client = new Client(mockSender); + const lookup = new SummaryLookup(); + lookup.businessName = "Style Studio"; + + client.sendBusinessSummary(lookup); + + expect(mockSender.request.baseUrlParam).to.equal("search/business"); + expect(mockSender.request.parameters).to.deep.equal({ + business_name: "Style Studio", + }); + }); + + it("omits the business_name param when businessName is blank", function () { + const mockSender = new MockSender(); + const client = new Client(mockSender); + const lookup = new SummaryLookup(); + lookup.freeform = "1 Rosedale, Baltimore, Maryland"; + lookup.businessName = ""; + + client.sendBusinessSummary(lookup); + + expect(mockSender.request.parameters).to.not.have.property("business_name"); + }); + it("sends include, exclude, and custom parameters when set", function () { const mockSender = new MockSender(); const client = new Client(mockSender); diff --git a/tests/us_enrichment/test_BusinessLookups.ts b/tests/us_enrichment/test_BusinessLookups.ts index 7c8755c0..209ca62e 100644 --- a/tests/us_enrichment/test_BusinessLookups.ts +++ b/tests/us_enrichment/test_BusinessLookups.ts @@ -17,6 +17,7 @@ describe("Business SummaryLookup", function () { expect(l.state).to.equal(undefined); expect(l.zipcode).to.equal(undefined); expect(l.freeform).to.equal(undefined); + expect(l.businessName).to.equal(undefined); expect(l.results).to.equal(undefined); expect(l.customParameters).to.deep.equal({}); }); From a4b8d7a550a81a9adada3847df8f0bb74c7e4c9a Mon Sep 17 00:00:00 2001 From: Mae Evans Date: Fri, 12 Jun 2026 10:29:47 -0600 Subject: [PATCH 2/2] unused import removal --- examples/us_enrichment_business_name_search.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/us_enrichment_business_name_search.ts b/examples/us_enrichment_business_name_search.ts index dfa86bc9..c890be01 100644 --- a/examples/us_enrichment_business_name_search.ts +++ b/examples/us_enrichment_business_name_search.ts @@ -3,7 +3,6 @@ import { BasicAuthCredentials, BusinessSummaryLookup, BusinessDetailLookup, - NotModifiedError, } from "smartystreets-javascript-sdk"; const authId = process.env.SMARTY_AUTH_ID!;