Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Supported APIs: `us_street`, `us_zipcode`, `us_autocomplete`, `us_autocomplete_p
Three credential types, each implementing a `sign(request)` method used by `SigningSender`:

- **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.
- **SharedCredentials** - Client-side/browser: adds embedded `key` param + `Referer` header. Cannot be used with POST (batch) requests or the US Extract API (POST-only).
- **BasicAuthCredentials** - Adds HTTP Basic Auth `Authorization` header

### Entry Point
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ console.log(response.result); // Array of address suggestions
Three credential types are available:

- **`StaticCredentials(authId, authToken)`** — Server-side authentication using auth-id and auth-token.
- **`SharedCredentials(key)`** — Client-side (browser) authentication using an embedded key. Does not support batch (POST) requests.
- **`SharedCredentials(key)`** — Client-side (browser) authentication using an embedded key. Embedded keys are restricted to HTTP GET, so they cannot be used for batch (POST) requests or with the US Extract API, which is POST-only.
- **`BasicAuthCredentials(authId, authToken)`** — HTTP Basic Auth.

## Browser Usage
Expand All @@ -84,7 +84,7 @@ const credentials = new SmartySDK.core.SharedCredentials("YOUR_EMBEDDED_KEY");
const client = new SmartySDK.core.ClientBuilder(credentials).buildUsStreetApiClient();
```

Note that `SharedCredentials` does not support batch (POST) requests — send one lookup at a time.
Note that `SharedCredentials` does not support batch (POST) requests — send one lookup at a time. The US Extract API is POST-only and so is unavailable with an embedded key.

### Features not available in the browser

Expand Down Expand Up @@ -129,7 +129,7 @@ esbuild app.js --bundle --external:undici

### Batch Requests

Send up to 100 lookups in a single request (not available with `SharedCredentials`):
Send up to 100 lookups in a single request (requires `StaticCredentials` or `BasicAuthCredentials`; not available with `SharedCredentials`):

```javascript
const batch = new SmartySDK.core.Batch();
Expand Down
7 changes: 2 additions & 5 deletions examples/us_extract.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import SmartySDK from "smartystreets-javascript-sdk";
const SmartyCore = SmartySDK.core;
const Lookup = SmartySDK.usExtract.Lookup;

// for client-side requests (browser/mobile), use this code:
// let key = process.env.SMARTY_EMBEDDED_KEY;
// const credentials = new SmartyCore.SharedCredentials(key);

// for Server-to-server requests, use this code:
// The US Extract API is POST-only and embedded keys are restricted to GET, so this
// API requires secret keys: https://www.smarty.com/docs/cloud/authentication
let authId = process.env.SMARTY_AUTH_ID;
let authToken = process.env.SMARTY_AUTH_TOKEN;
const credentials = new SmartyCore.BasicAuthCredentials(authId, authToken);
Expand Down
8 changes: 2 additions & 6 deletions examples/us_extract.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { ClientBuilder, BasicAuthCredentials, LookupUSExtract } from "smartystreets-javascript-sdk";

// for client-side requests (browser/mobile), use this code:
// import { SharedCredentials } from "smartystreets-javascript-sdk";
// const key: string = process.env.SMARTY_EMBEDDED_KEY!;
// const credentials = new SharedCredentials(key);

// for Server-to-server requests, use this code:
// The US Extract API is POST-only and embedded keys are restricted to GET, so this
// API requires secret keys: https://www.smarty.com/docs/cloud/authentication
const authId = process.env.SMARTY_AUTH_ID!;
const authToken = process.env.SMARTY_AUTH_TOKEN!;
const credentials = new BasicAuthCredentials(authId, authToken);
Expand Down
9 changes: 3 additions & 6 deletions examples/us_street.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import SmartySDK from "smartystreets-javascript-sdk";
const SmartyCore = SmartySDK.core;
const Lookup = SmartySDK.usStreet.Lookup;

// for client-side requests (browser/mobile), use this code:
// let key = process.env.SMARTY_EMBEDDED_KEY;
// const credentials = new SmartyCore.SharedCredentials(key);

// for Server-to-server requests, use this code:
// Batch requests are sent via HTTP POST. Embedded keys are restricted to GET, so
// batches require secret keys: https://www.smarty.com/docs/cloud/authentication
let authId = process.env.SMARTY_AUTH_ID;
let authToken = process.env.SMARTY_AUTH_TOKEN;
const credentials = new SmartyCore.BasicAuthCredentials(authId, authToken);
Expand Down Expand Up @@ -49,7 +46,7 @@ lookup3.street = "1600 Amphitheatre Parkway Mountain View, CA 94043";
// uncomment the following line to add a custom parameter
// lookup3.addCustomParameter("max_candidates", 1);

// NOTE: batches are not supported when using SharedCredentials.
// NOTE: batch requests require secret keys; embedded keys cannot be used here.
let batch = new SmartyCore.Batch();
batch.add(lookup1);
batch.add(lookup2);
Expand Down
10 changes: 3 additions & 7 deletions examples/us_street.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ import {
Batch,
} from "smartystreets-javascript-sdk";

// for client-side requests (browser/mobile), use this code:
// import { SharedCredentials } from "smartystreets-javascript-sdk";
// const key: string = process.env.SMARTY_EMBEDDED_KEY!;
// const credentials = new SharedCredentials(key);

// for Server-to-server requests, use this code:
// Batch requests are sent via HTTP POST. Embedded keys are restricted to GET, so
// batches require secret keys: https://www.smarty.com/docs/cloud/authentication
const authId = process.env.SMARTY_AUTH_ID!;
const authToken = process.env.SMARTY_AUTH_TOKEN!;
const credentials = new BasicAuthCredentials(authId, authToken);
Expand Down Expand Up @@ -66,7 +62,7 @@ async function main(): Promise<void> {
// uncomment the following line to add a custom parameter
// lookup3.addCustomParameter("max_candidates", 1);

// NOTE: batches are not supported when using SharedCredentials.
// NOTE: batch requests require secret keys; embedded keys cannot be used here.
const batch = new Batch();
batch.add(lookup1);
batch.add(lookup2);
Expand Down
8 changes: 3 additions & 5 deletions examples/us_zipcode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import SmartySDK from "smartystreets-javascript-sdk";
const SmartyCore = SmartySDK.core;
const Lookup = SmartySDK.usZipcode.Lookup;

// for client-side requests (browser/mobile), use this code:
// let key = process.env.SMARTY_EMBEDDED_KEY;
// const credentials = new SmartyCore.SharedCredentials(key);

// for Server-to-server requests, use this code:
// Batch requests are sent via HTTP POST. Embedded keys are restricted to GET, so
// batches require secret keys: https://www.smarty.com/docs/cloud/authentication
let authId = process.env.SMARTY_AUTH_ID;
let authToken = process.env.SMARTY_AUTH_TOKEN;
const credentials = new SmartyCore.BasicAuthCredentials(authId, authToken);
Expand Down Expand Up @@ -37,6 +34,7 @@ lookup3.state = "AZ";
// uncomment the following line to add a custom parameter
// lookup3.addCustomParameter("input_id", 1234);

// NOTE: batch requests require secret keys; embedded keys cannot be used here.
let batch = new SmartyCore.Batch();
batch.add(lookup1);
batch.add(lookup2);
Expand Down
9 changes: 3 additions & 6 deletions examples/us_zipcode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ import {
Batch,
} from "smartystreets-javascript-sdk";

// for client-side requests (browser/mobile), use this code:
// import { SharedCredentials } from "smartystreets-javascript-sdk";
// const key: string = process.env.SMARTY_EMBEDDED_KEY!;
// const credentials = new SharedCredentials(key);

// for Server-to-server requests, use this code:
// Batch requests are sent via HTTP POST. Embedded keys are restricted to GET, so
// batches require secret keys: https://www.smarty.com/docs/cloud/authentication
const authId = process.env.SMARTY_AUTH_ID!;
const authToken = process.env.SMARTY_AUTH_TOKEN!;
const credentials = new BasicAuthCredentials(authId, authToken);
Expand Down Expand Up @@ -60,6 +56,7 @@ async function main(): Promise<void> {
// uncomment the following line to add a custom parameter
// lookup3.addCustomParameter("input_id", 1234);

// NOTE: batch requests require secret keys; embedded keys cannot be used here.
const batch = new Batch();
batch.add(lookup1);
batch.add(lookup2);
Expand Down