@augstash/sdk
v0.2.0
Published
Node / TypeScript client for the Augstash messaging API
Readme
@augstash/sdk
Node / TypeScript client for the Augstash API. Not published yet - see ../README.md.
npm install # dev dependencies
python ../tools/refresh.py --base-url http://localhost:8086 node # generate the client
npm test
npm run buildUsing it
import { AugstashClient, AugstashError, ContactApi, SmsApi, WalletApi } from '@augstash/sdk';
const client = new AugstashClient({
baseUrl: process.env.AUGSTASH_BASE_URL!, // required - there is no default host
apiKey: process.env.AUGSTASH_API_KEY!, // ask_live_<keyId>.<secret>
});
const wallet = await client.api(WalletApi).balance();
try {
await client.api(SmsApi).sendSms({ sendSmsRequest: { to: '+919000000000', body: 'hello' } });
} catch (error) {
if (error instanceof AugstashError && error.code === 'WALLET_INSUFFICIENT_FUNDS') {
// branch on `code`, never on `message` - message is localized
console.error(error.detail, error.traceId);
}
}client.api(X) takes any of the 154 generated API classes and hands back a cached, configured
instance. There is no hand-written list of accessors: one would drift the moment an endpoint is
added.
Paging
import { collect, paginateCursor, paginatePages } from '@augstash/sdk';
const contacts = client.api(ContactApi);
for await (const contact of paginatePages((page) => contacts.listContacts({ page, limit: 100 }))) {
// ...
}Use paginateCursor for message, conversation and event history - those endpoints are cursor-paged
because an offset page over a table that grows at the top repeats and skips rows mid-scroll.
Webhooks
import { verifyWebhookSignature, SIGNATURE_HEADER } from '@augstash/sdk';
app.post('/hooks/augstash', express.raw({ type: 'application/json' }), async (req, res) => {
const ok = await verifyWebhookSignature(secret, req.body, req.header(SIGNATURE_HEADER));
if (!ok) return res.sendStatus(401);
// req.body is the raw Buffer - `express.json()` would re-serialize and the check would fail
res.sendStatus(204);
});Options
| Option | Default | |
|---|---|---|
| baseUrl | - | required |
| apiKey / bearerToken | - | one is required; a bearer token reaches endpoints a key cannot |
| timeoutMs | 30000 | per attempt |
| retry | 3 attempts, 0.5s-8s | {maxAttempts: 1} disables |
| idempotency | true | off also stops mutating calls being retried |
| headers, fetch, middleware | - | escape hatches |
Build notes
Compiled to CommonJS so both bundlers and plain Node consumers work without extension-ful imports;
an ESM build is worth adding before publishing. src/generated/ is machine-written and gitignored -
edit src/*.ts only.
