@namedone/token
v0.1.0
Published
Client SDK for the Name Done token API — exchange your API key for a short-lived JWT.
Maintainers
Readme
@namedone/token
Client SDK for the Name Done token API. Exchange your long-lived API key for a short-lived JWT used with the autocomplete API.
Name Done is a lightning-fast autocomplete API for UK names, addresses, schools, postcodes, and more. It's a commercial service with a free tier — sign up at auth.namedone.com/signup to get an API key.
- 📋 Pricing — free tier with 10,000 tokens/month
- 📖 API docs
- 📊 Data sources
- 🔑 Get an API key
Install
npm install @namedone/tokenUsage
Simplest
import { createClient } from "@namedone/token";
const tokens = createClient("nd_...");
const { token } = await tokens.getToken();With options
import { CachedTokenClient } from "@namedone/token";
const client = new CachedTokenClient({ apiKey: "nd_...", refreshSkewSeconds: 60 });
const { token, expiresIn } = await client.getToken();With the autocomplete client
When using @namedone/autocomplete, you don't need this package directly — just pass your API key:
import { createClient } from "@namedone/autocomplete";
const nd = createClient("nd_...");API
createClient(apiKey) / createClient(opts)
Creates a CachedTokenClient — the recommended entry point.
CachedTokenClient
Caches the JWT in memory and only calls the token API when the token is missing or about to expire.
| Option | Type | Default | Description |
|---|---|---|---|
| apiKey | string | — | Your Name Done API key (nd_...) |
| baseUrl | string | https://token.namedone.com | Token API base URL |
| fetch | typeof fetch | global fetch | Custom fetch implementation |
| timeoutMs | number | 10000 | Request timeout |
| refreshSkewSeconds | number | 30 | Refresh this many seconds before expiry |
TokenClient
Low-level client — no caching, calls the API on every getToken().
Links
License
MIT
