Skip to content

Node.js / TypeScript SDK

Install

bash
npm install @appitude/sendivent

Requires Node.js 18+ (native fetch).

Quickstart

typescript
import { Sendivent } from '@appitude/sendivent';

const client = new Sendivent(process.env.SENDIVENT_API_KEY!);

const res = await client
  .event('welcome')
  .to('user@example.com')
  .payload({ name: 'Alice' })
  .send();

if (!res.isSuccess()) {
  console.error(res.error);
}

Configuration

Set SENDIVENT_API_KEY in your environment. The SDK automatically routes requests to the correct API based on your key prefix: test_ → sandbox, live_ → production. See Sandbox vs Production.

Common tasks

Send with payload

typescript
await client.event('order-shipped')
  .to('user@example.com')
  .payload({ order_id: '12345', tracking_url: 'https://...' })
  .send();

Send to a contact object

typescript
await client.event('welcome')
  .to({
    email: 'user@example.com',
    name: 'Alice',
    id: 'user_123',
    plan: 'premium'
  })
  .send();

See Contacts for identifier rules and meta fields.

Force a channel

typescript
await client.event('verification')
  .channel('sms')
  .to('+46701234567')
  .send();

See Routing.

Set language

typescript
await client.event('welcome')
  .language('sv')
  .to('anders@example.com')
  .send();

See Templates for language variants.

Send to multiple recipients

typescript
await client.event('newsletter')
  .to(['user1@example.com', 'user2@example.com'])
  .payload({ subject: 'Monthly Update' })
  .send();

Override template settings

typescript
await client.event('invoice')
  .to('user@example.com')
  .overrides({
    email: {
      subject: 'Your Invoice',
      reply_to: 'billing@yourcompany.com'
    }
  })
  .send();

Prevent duplicates

typescript
await client.event('order-confirmation')
  .to('user@example.com')
  .idempotencyKey('order-12345')
  .send();

Fire-and-forget

Skip await to send without waiting for the response. The request is sent immediately and your code continues.

typescript
client.event('welcome')
  .to('user@example.com')
  .send(); // No await — non-blocking

// Code continues immediately

Ideal for non-critical notifications where you don't need delivery confirmation.

Response and delivery tracking

send() returns a response object. On success, it includes delivery identifiers you can look up in the dashboard Activity log.

typescript
const res = await client.event('welcome').to('user@example.com').send();
if (res.isSuccess()) console.log(res.data);

See Send API for the full response format.

Error handling

typescript
try {
  const res = await client.event('welcome').to('user@example.com').send();
  if (!res.isSuccess()) console.error(res.error);
} catch (err: unknown) {
  console.error('Request failed:', err instanceof Error ? err.message : err);
}

TypeScript types

The package exports types for contacts and responses:

typescript
import type { Contact } from '@appitude/sendivent';

const contact: Contact = {
  email: 'user@example.com',
  name: 'Alice',
  id: 'user_123'
};

Methods

MethodDescription
event(name)Set event name
to(recipient)Set recipient(s)
from(sender)Set custom sender (verified)
payload(data)Set template data
channel(name)Force channel (email, sms, slack)
language(code)Set language code
overrides(obj)Override template settings
idempotencyKey(key)Prevent duplicate sends
send()Send (returns Promise)

Common pitfalls

  • Using test_ key in production — lower rate limits and separate database (see Sandbox)
  • Forcing sms without a phone number — send fails (see Routing)
  • Blank template variables — you didn't send required payload/meta fields (see Templates)

See also

Released under the MIT License.