@edgepush/sdk
v1.0.0
Published
Official Node/TypeScript SDK for edgepush. Send push notifications to iOS and Android with a single API.
Maintainers
Readme
@edgepush/sdk
Official Node/TypeScript SDK for edgepush. Send native iOS and Android push notifications through a single API.
Install
npm install @edgepush/sdk
# or
pnpm add @edgepush/sdk
# or
bun add @edgepush/sdkQuick start
import { Edgepush } from "@edgepush/sdk";
const client = new Edgepush({
apiKey: "io.akshit.myapp|abc123...", // from the edgepush dashboard
});
// Send a single message
const ticket = await client.send({
to: deviceToken, // APNs hex token or FCM registration token
title: "Hello",
body: "World",
data: { url: "myapp://home" },
});
// Poll the delivery receipt
const receipt = await client.getReceipt(ticket.id);
console.log(receipt.status); // "queued" | "sending" | "delivered" | "failed" | "expired"Batch sends
const tickets = await client.sendBatch([
{ to: token1, title: "Hi", body: "First" },
{ to: token2, title: "Hi", body: "Second" },
]);
// Poll all receipts in a single call
const receipts = await client.getReceipts(tickets.map((t) => t.id));Environments
The SDK is isomorphic. It works in:
- Node.js (>= 18)
- Bun
- Deno
- Cloudflare Workers
- Browsers (CORS allowed, but you should rarely send pushes from a browser)
Error handling
import { Edgepush, EdgepushError } from "@edgepush/sdk";
try {
await client.send({ to: deviceToken, title: "Hi" });
} catch (err) {
if (err instanceof EdgepushError) {
console.error(`edgepush ${err.status}: ${err.code}`);
}
throw err;
}License
MIT
