TypeScript SDK
Install @emitkit/js and send events from TypeScript or JavaScript.
The @emitkit/js package wraps EmitKit’s HTTP API for server-side TypeScript
and JavaScript. Keep the API key on the server; never include it in a browser
bundle or public environment variable.
Install
npm install @emitkit/jspnpm add @emitkit/jsyarn add @emitkit/jsSend an event
import { EmitKit } from '@emitkit/js';
const client = new EmitKit(process.env.EMITKIT_API_KEY!);
const result = await client.events.create({
channelName: 'general',
title: 'Hello from EmitKit',
description: 'My first event',
});
console.log(result.data.id);
The API key selects the Project. channelName selects or creates a Channel in
that Project, so the request body doesn’t contain an Organization or Project
identifier.
Add monetary context
metadata accepts arbitrary JSON. This makes it useful for monetary context
such as an amount, currency, and plan:
const result = await client.events.create({
channelName: 'payments',
title: 'Payment Received',
description: 'User upgraded to Pro plan',
icon: '💰',
tags: ['payment', 'upgrade'],
metadata: {
amount: 99.99,
currency: 'USD',
plan: 'pro',
},
userId: 'user_123',
notify: true,
});
notify defaults to true: the event sends a
push notification to members who turned
notifications on. Set it to false for routine events.
Safe retries
Supply an idempotency key when the caller may retry the same occurrence:
await client.events.create(
{
channelName: 'payments',
title: 'Payment Received',
metadata: { paymentId: 'pay_123' },
},
{ idempotencyKey: 'payment-pay_123' },
);
An idempotency key is kept for 24 hours per API key. Repeating the request
returns the first response; reusing the key with a different body returns
409 Conflict.