This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
npm install # Install dependencies
npm test # Run all tests
npm run build # Build the library (outputs to dist/)
npx tsc --noEmit # Type-check without emitting
npx prettier --write . # Format all files (respects .prettierignore)Makefile targets (used by CI):
make test # fmt + test (installs deps if needed)
make build # Rollup build
make fmt # Prettier format
make integrate # Run all example files against built dist/To run a single test file:
npx mocha --require tsx/cjs tests/test_RetrySender.tsBuild outputs dual formats via Rollup: dist/cjs/ (CommonJS), dist/esm/ (ESM), and dist/types/ (declarations). Rollup preserves module structure (preserveModules: true). undici is the only external dependency (not bundled).
This is the official JavaScript SDK for Smarty address validation APIs. It supports both Node.js (CommonJS/ESM) and browser environments. The entire codebase is TypeScript.
The core architecture uses a chain-of-responsibility/middleware pattern for HTTP requests. Each "Sender" wraps another Sender, processing requests through this chain:
CustomQuerySender → LicenseSender → BaseUrlSender → CustomHeaderSender
→ AgentSender → RetrySender → SigningSender → StatusCodeSender → HttpSender
Each sender adds specific functionality (authentication, retries, headers, etc.). The HttpSender at the end uses the Fetch API for HTTP transport (with optional undici ProxyAgent for proxy support in Node.js).
All senders implement the Sender interface from src/types.ts, which also defines the core Request and Response contracts that flow through the chain.
-
ClientBuilder: Fluent API for configuring and building API-specific clients. Accepts either
StaticCredentials(server-side: auth-id + auth-token) orSharedCredentials(client-side: embedded key). -
Lookup classes: Each API has a
Lookupthat holds both input parameters and results after the API call. Located insrc/<api_name>/Lookup.ts. -
Batch: Container for up to 100 lookups. Single lookups use GET requests; batches with 2+ lookups use POST.
-
Client classes: Each API has a
Clientinsrc/<api_name>/Client.tsthat handles domain-specific request building and response parsing.
Each API follows the same structure in src/<api_name>/:
Lookup.ts- Input/output containerClient.ts- Request/response handlingCandidate.ts,Result.ts, orSuggestion.ts- Response data structures
Supported APIs: us_street, us_zipcode, us_autocomplete_pro, us_extract, us_enrichment, us_reverse_geo, international_street, international_address_autocomplete, international_postal_code
Three credential types, each implementing a sign(request) method used by SigningSender:
- StaticCredentials - Server-side: adds
auth-id+auth-tokenquery params - SharedCredentials - Client-side/browser: adds embedded
keyparam +Refererheader. Cannot be used with POST (batch) requests. - BasicAuthCredentials - Adds HTTP Basic Auth
Authorizationheader
index.ts exports all public classes organized by API namespace (e.g., core, usStreet, usZipcode).
Tests use Mocha + Chai (expect style). Test files are prefixed with test_ and mirror the source structure under tests/.
tests/fixtures/mock_senders.ts provides reusable mocks:
MockSender- Captures the request for inspectionMockSenderWithResponse- Returns a fixed payload/errorMockSenderWithStatusCodesAndHeaders- Iterates through status codes (useful for retry tests)
- Uses Prettier: tabs, double quotes, 100 char line width, trailing commas
- All source and test files are TypeScript with ES module syntax (
import/export) - Import paths use
.jsextensions (TypeScript resolves.jsto.ts) - TypeScript is configured with
strict: true,exactOptionalPropertyTypes, andnoPropertyAccessFromIndexSignature - Tests use Mocha + Chai with
expectstyle assertions - Test files are prefixed with
test_and mirror the source structure