TypeScript & JavaScript SDK
Send email, manage domains, contacts, templates, and webhooks from Node and the browser with the official @taifamail/sdk SDK.
The official TypeScript and JavaScript SDK is published as @taifamail/sdk on npm. Source lives in the taifa-mail-sdks repository.
The SDK is fully typed, ships its own type definitions, and works in any runtime with a global fetch (Node 18+, Deno, Bun, Cloudflare Workers, and modern browsers).
Installation
It also installs cleanly with pnpm or yarn:
The SDK uses the runtime's global fetch, which is available on Node 18 and later. On older Node versions, pass a fetch implementation (for example from node-fetch or undici) through the client options (see below).
Authentication and client setup
Create an API key in the dashboard under Settings -> API Keys. Keys start with tfm_k_. Construct the client with that key:
The constructor accepts these options:
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | (required) | Your API key. Starts with tfm_k_. |
baseUrl | string | https://govconnect.ke | Override the API base URL. |
maxRetries | number | 3 | Total attempts on 429 / 5xx, including the first. |
timeoutMs | number | 30000 | Per-request timeout in milliseconds. |
fetch | function | global fetch | A custom fetch implementation (for Node < 18 or testing). |
Send an email
emails.send queues a single message and returns its id and initial status.
The response is a SendEmailResponse:
A few conveniences worth knowing:
- The SDK exposes a clean
fromfield, then maps it to the wire fieldfrom_for you. You never writefrom_. - Any address field (
from,to,cc,bcc,replyTo) accepts a bare string like'customer@example.com', a{ email, name }object, or an array of either. A bare string is treated as{ email }. - Provide
html,text, or both. sendAtaccepts an ISO 8601 string or aDateand schedules the message for later (Starter plan and up).
Emails
Scheduled emails:
Saved searches (named filter sets stored per user):
Domains
Contacts
Subscriber lists, their contacts, CSV imports, and templated bulk sends.
uploadCsv takes the raw file bytes (a Uint8Array) and a filename, sent as a single multipart field named file:
bulkSend mails a templated message to every contact in a list. Subject, html, and text may use {{email}}, {{name}}, and {{metadata_key}} placeholders:
Suppressions
The do-not-send list. list returns a paginated Page envelope ({ items, total, page, limit }).
Templates
Reusable email templates. html maps to the wire field html_body and text to text_body for you.
A template's variables are derived server-side from the {{name}} placeholders in its bodies, so you do not pass them when creating or updating.
Webhooks
Error handling
Every non-2xx response, and any transport failure that survives all retries, throws an TaifaMailError. Inspect status and code to branch on specific failures.
TaifaMailError also carries a detail field with the raw parsed response body for debugging.
Configuration
- Retries. Requests that return
429or5xxare retried with exponential backoff, honoring theRetry-Afterheader when present. Control the total attempt count (including the first) withmaxRetries(default3). Multipart uploads are not retried because they are not idempotent. - Timeout. Each request is aborted after
timeoutMs(default30000). A timeout is treated as a transport failure and is retried while attempts remain. - Custom base URL. Point the client at a staging or self-hosted host with
baseUrl. A trailing slash is trimmed automatically.
Next steps
- SDKs overview for the full list of official SDKs.
- Emails API reference for the underlying HTTP endpoints, fields, and limits.