Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
406bdaa
Export TypeScript types (Request, Response, Sender, Sleeper) from SDK
RyanLCox1 Feb 27, 2026
e7a2c0f
Prettier formatting.
RyanLCox1 Feb 27, 2026
729ca7b
Add return after reject() in all Client Promise handlers
RyanLCox1 Mar 2, 2026
44c6dcd
Fix withCustomCommaSeperatedQuery undefined bug and HttpSender missin…
RyanLCox1 Mar 2, 2026
7ea4487
Fix async test assertions that were silently passing
RyanLCox1 Mar 2, 2026
5bc1e43
Replace type-unsafe statusCode values with 0 sentinel
RyanLCox1 Mar 2, 2026
adb1369
Make sender private in remaining Client classes
RyanLCox1 Mar 2, 2026
d5a9474
Replace as any payload casts with specific types
RyanLCox1 Mar 2, 2026
0fe766a
Fix typos and inconsistencies in us_enrichment Response
RyanLCox1 Mar 2, 2026
afe7d46
Map state_abbreviation to stateAbbreviation in us_reverse_geo Result
RyanLCox1 Mar 2, 2026
abb7e46
Add null guards for payload access in Client and Address
RyanLCox1 Mar 2, 2026
216939a
Remove unnecessary Promise constructor wrapping in senders
RyanLCox1 Mar 2, 2026
7ec944d
Replace .map() with .forEach() where return value is discarded
RyanLCox1 Mar 2, 2026
b109f7a
Add implements to Request/Response classes and simplify error type to…
RyanLCox1 Mar 2, 2026
06ef75a
Move Signer interface to types.ts and fix statusCodes to number[]
RyanLCox1 Mar 2, 2026
76c3fad
Export SmartyError and Signer type from public API
RyanLCox1 Mar 2, 2026
87fa47b
Convert remaining source and test files from JavaScript to TypeScript
RyanLCox1 Mar 2, 2026
c023e87
Type Lookup result fields and narrow customParameters from any to string
RyanLCox1 Mar 2, 2026
a9c10a5
Add exported interfaces for Candidate/Result/Suggestion output fields
RyanLCox1 Mar 2, 2026
862e197
Type Batch with BaseLookup, narrow sendBatch and InputData signatures
RyanLCox1 Mar 2, 2026
7d44aa2
Type Client response params and narrow us_enrichment attributes
RyanLCox1 Mar 2, 2026
7933958
Type ClientBuilder proxy as AxiosProxyConfig and genericize buildClient
RyanLCox1 Mar 2, 2026
0b12e86
Type test fixture mock senders
RyanLCox1 Mar 2, 2026
76f04d2
Wire up us_enrichment Response constructors in Client
RyanLCox1 Mar 3, 2026
071da4b
Replace Record<string, any> with named interfaces, enable noPropertyA…
RyanLCox1 Mar 3, 2026
aa3288a
A little more strict on the types.
RyanLCox1 Mar 3, 2026
f18c6e1
Run prettier.
RyanLCox1 Mar 3, 2026
b1311db
Updated README
RyanLCox1 Mar 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions .claude/settings.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
{
"permissions": {
"allow": [
"Edit",
"Write",
"Bash(rm:./*)",
"Bash(git *)",
"Bash(make *)",
"Bash(npm *)"
]
},
"attribution": {
"commit": "",
"pr": ""
}
"permissions": {
"allow": ["Edit", "Write", "Bash(rm:./*)", "Bash(git *)", "Bash(make *)", "Bash(npm *)"]
},
"attribution": {
"commit": "",
"pr": ""
}
}
25 changes: 12 additions & 13 deletions .github/workflows/node-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@ name: Node Tests

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x, 22.x, 24.x]

steps:
- uses: actions/checkout@v6
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build
- run: npm test
env:
CI: true
- uses: actions/checkout@v6
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build
- run: npm test
env:
CI: true
10 changes: 5 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Publish to npm
on:
push:
tags:
- '*'
- "*"

permissions:
id-token: write # Required for OIDC
id-token: write # Required for OIDC
contents: read

jobs:
Expand All @@ -19,8 +19,8 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
node-version: "20.x"
registry-url: "https://registry.npmjs.org"

- name: Update npm
run: npm install -g npm@'>=11.5.1'
Expand All @@ -44,4 +44,4 @@ jobs:
run: npm publish
env:
NPM_CONFIG_PROVENANCE: true
NPM_TOKEN: ''
NPM_TOKEN: ""
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

See the changelog repository:

github.com/smartystreets/changelog/blob/master/sdk/javascript.md
github.com/smartystreets/changelog/blob/master/sdk/javascript.md
36 changes: 19 additions & 17 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,23 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co

```bash
npm install # Install dependencies
npm test # Run all tests (JS + TS)
npm run test:js # Run JavaScript tests only
npm run test:ts # Run TypeScript tests only
npm test # Run all tests
npm run build # Build the library (outputs to dist/)
npx tsc --noEmit # Type-check without emitting
npx prettier --write src/ # Format source files
```

To run a single test file:

```bash
npx mocha tests/us_street/test_Client.js # JS test
npx mocha --require tsx/cjs tests/test_RetrySender.ts # TS test
npx mocha --require tsx/cjs tests/test_RetrySender.ts
```

Build outputs dual formats via Rollup: `dist/cjs/` (CommonJS), `dist/esm/` (ESM), and `dist/types/` (declarations). Axios and axios-retry are external dependencies (not bundled).

## Architecture

This is the official JavaScript SDK for Smarty address validation APIs. It supports both Node.js (CommonJS/ESM) and browser environments.
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.

### Sender Chain Pattern

Expand All @@ -41,44 +39,48 @@ Each sender adds specific functionality (authentication, retries, headers, etc.)

- **ClientBuilder**: Fluent API for configuring and building API-specific clients. Accepts either `StaticCredentials` (server-side: auth-id + auth-token) or `SharedCredentials` (client-side: embedded key).

- **Lookup classes**: Each API has a `Lookup` that holds both input parameters and results after the API call. Located in `src/<api_name>/Lookup.js`.
- **Lookup classes**: Each API has a `Lookup` that holds both input parameters and results after the API call. Located in `src/<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 `Client` in `src/<api_name>/Client.js` that handles domain-specific request building and response parsing.
- **Client classes**: Each API has a `Client` in `src/<api_name>/Client.ts` that handles domain-specific request building and response parsing.

### API Modules

Each API follows the same structure in `src/<api_name>/`:
- `Lookup.js` - Input/output container
- `Client.js` - Request/response handling
- `Candidate.js`, `Result.js`, or `Suggestion.js` - Response data structures

- `Lookup.ts` - Input/output container
- `Client.ts` - Request/response handling
- `Candidate.ts`, `Result.ts`, or `Suggestion.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`

### Credentials

Three credential types, each implementing a `sign(request)` method used by `SigningSender`:
- **StaticCredentials** (TS) - Server-side: adds `auth-id` + `auth-token` query params
- **SharedCredentials** (TS) - Client-side/browser: adds embedded `key` param + `Referer` header. Cannot be used with POST (batch) requests.
- **BasicAuthCredentials** (TS) - Adds HTTP Basic Auth `Authorization` header

- **StaticCredentials** - Server-side: adds `auth-id` + `auth-token` query params
- **SharedCredentials** - Client-side/browser: adds embedded `key` param + `Referer` header. Cannot be used with POST (batch) requests.
- **BasicAuthCredentials** - Adds HTTP Basic Auth `Authorization` header

### Entry Point

`index.mjs` exports all public classes organized by API namespace (e.g., `core`, `usStreet`, `usZipcode`).
`index.ts` exports all public classes organized by API namespace (e.g., `core`, `usStreet`, `usZipcode`).

### Test Infrastructure

Tests use Mocha + Chai (`expect` style). Test files are prefixed with `test_` and mirror the source structure under `tests/`.

`tests/fixtures/mock_senders.js` provides reusable mocks:
`tests/fixtures/mock_senders.ts` provides reusable mocks:

- `MockSender` - Captures the request for inspection
- `MockSenderWithResponse` - Returns a fixed payload/error
- `MockSenderWithStatusCodesAndHeaders` - Iterates through status codes (useful for retry tests)

## Code Style

- Uses Prettier: tabs, double quotes, 100 char line width, trailing commas
- Mixed JS/TS: Business logic (clients, lookups, results) in JS; infrastructure (credentials, senders, types) in TS
- All source and test files are TypeScript with ES module syntax (`import`/`export`)
- Import paths use `.js` extensions (TypeScript resolves `.js` to `.ts`)
- Tests use Mocha + Chai with `expect` style assertions
- Test files are prefixed with `test_` and mirror the source structure
Loading