@mandai/sdk
v0.1.2
Published
Official dependency-free JavaScript and TypeScript SDK for the Mandaí transactional SMS API
Readme
@mandai/sdk
Official dependency-free JavaScript and TypeScript client for the Mandaí API. Use it in a trusted server environment; never expose a Mandaí API key in browser code.
npm install @mandai/sdkimport { MandaiClient, createIdempotencyKey } from '@mandai/sdk';
const mandai = new MandaiClient({
apiKey: process.env.MANDAI_API_KEY!,
environment: 'sandbox',
});
const preview = await mandai.messages.preview({
to: '+5511988887777',
body: 'Seu pedido BR-1842 foi confirmado.',
});
const message = await mandai.messages.create(
{
to: '+5511988887777',
body: 'Seu pedido BR-1842 foi confirmado.',
metadata: { order_id: 'BR-1842' },
},
{ idempotencyKey: createIdempotencyKey('order-BR-1842') },
);The client never retries message creation automatically. If a network outcome is ambiguous, reuse the same idempotency key and inspect the original result rather than generating another SMS attempt.
Webhook signatures can be verified against the exact raw request body:
import { verifyWebhookSignature } from '@mandai/sdk';
const valid = await verifyWebhookSignature({
secret: process.env.MANDAI_WEBHOOK_SECRET!,
timestamp: request.headers.get('x-mandai-timestamp') ?? '',
signature: request.headers.get('x-mandai-signature') ?? '',
rawBody: await request.text(),
});License
MIT. See LICENSE.
