@sendflit/sdk. It has no runtime dependencies, uses the built-in fetch, and works in Node.js 18 and later, in TypeScript and in plain JavaScript.
Looking for another language? See the SDK overview.
Install
Create a client
Read your key from the environment. Never put a live key in source code.Send an email
Callsend with an email object. It returns the stored email’s id and status.
The SDK converts camelCase names to the API’s snake_case names for you.
Send with a template
Attachments
Each attachment is an object with afilename, content and an optional contentType. A string is encoded as UTF-8 and a Buffer or Uint8Array is encoded as-is.
- Up to 10 attachments per message.
- Up to 10 MB per attachment. Larger files are rejected with
422.
Safe retries with idempotency keys
A network timeout doesn’t tell you whether the server sent the email. Pass an idempotency key so a retry can’t send it twice.409. That means your code has a bug, so generate a new key for a new email. For the full rules, see Idempotency.
Send a batch
batch sends up to 100 emails in one request. The response has a results array with one entry per email, in the order you sent them, and a count.
TypeError or RangeError before any request is made. See Batch sending.
Manage emails
cancelEmail removes an email that is still scheduled. If the email has already been sent, the API returns an error, which the SDK throws as a SendFlitError with the status and body.
Domains
Add the domain, publish the DNS records it returns, then verify it. You can send only from a verified domain.Suppressions
Suppressed addresses never receive email from your account. Add an address when a recipient unsubscribes or complains.suppress takes one object. reason is optional and defaults to "unsubscribe". See Emails for how suppressions interact with sending.
Usage and health
health doesn’t need a valid key. Use it in a readiness probe or a startup check.
Verify webhooks
SendFlit signs every webhook request. The signature is an HMAC-SHA256 of the raw request body, sent in theX-Sendflit-Signature header as sha256=<hex>.
webhookMiddleware(secret). It checks the signature on req.body, which must be the raw Buffer, returns 401 if the check fails, and otherwise sets req.sendflitEvent to the parsed event and calls next(). Keep the body raw until verification finishes. If you parse it first, the signature won’t match. See Webhooks for the event list.
Errors and retries
Every failed request throws aSendFlitError:
A request that times out throws
SendFlitTimeoutError, a subclass of SendFlitError.
429 or a 5xx status are retried up to maxRetries times. The SDK waits for the Retry-After header when it’s present, and otherwise backs off exponentially. Other 4xx responses are not retried. Network failures are thrown right away with status 0. See Errors, retries and limits.
Method reference
Next steps
- Quickstart: send your first email from the command line.
- Batch sending: limits and per-item results.
- Idempotency: the full retry rules.
- Webhooks: events and payloads.