@pushary/server
v1.0.0
Published
Pushary Server SDK - Manage subscribers, campaigns, templates, and send notifications
Downloads
46
Maintainers
Readme
@pushary/server
Server-side SDK for Pushary - Manage subscribers, campaigns, templates, and send push notifications from your backend.
Installation
npm install @pushary/server
# or
yarn add @pushary/server
# or
pnpm add @pushary/server
# or
bun add @pushary/serverQuick Start
import { createPusharyServer } from '@pushary/server'
const pushary = createPusharyServer({
apiKey: process.env.PUSHARY_API_KEY, // Required: pk_xxx.sk_xxx
})
// Send a notification
await pushary.notifications.send({
title: 'Hello!',
body: 'Your order has shipped',
subscriberIds: ['sub_123'],
})API Key
The server SDK requires your full API key (pk_xxx.sk_xxx) which includes the secret portion. Never expose this in client-side code.
Get your API key from your Pushary Dashboard.
Resources
Subscribers
// List subscribers
const { data, hasMore, nextCursor } = await pushary.subscribers.list({
limit: 100,
status: 'active',
})
// Get a subscriber
const subscriber = await pushary.subscribers.get('sub_123')
// Update subscriber
await pushary.subscribers.update('sub_123', {
tags: ['vip', 'newsletter'],
externalId: 'user-456',
})
// Delete subscriber
await pushary.subscribers.delete('sub_123')
// Get subscriber count
const count = await pushary.subscribers.count()Campaigns
// List campaigns
const { data } = await pushary.campaigns.list()
// Create campaign
const campaign = await pushary.campaigns.create({
name: 'Welcome Campaign',
title: 'Welcome!',
body: 'Thanks for subscribing',
actionUrl: 'https://example.com/welcome',
})
// Send campaign
await pushary.campaigns.send(campaign.id)
// Pause/Resume
await pushary.campaigns.pause(campaign.id)
await pushary.campaigns.resume(campaign.id)
// Get stats
const stats = await pushary.campaigns.stats(campaign.id)Templates
// List templates
const { data } = await pushary.templates.list()
// Create template
const template = await pushary.templates.create({
name: 'Order Update',
title: 'Order {{orderId}} Update',
body: 'Your order status: {{status}}',
})
// Update template
await pushary.templates.update(template.id, {
body: 'Your order {{orderId}} is now {{status}}',
})
// Delete template
await pushary.templates.delete(template.id)Notifications (Direct Send)
// Send to specific subscribers
await pushary.notifications.send({
title: 'Flash Sale!',
body: '50% off everything',
url: 'https://example.com/sale',
subscriberIds: ['sub_123', 'sub_456'],
})
// Send to external IDs (your user IDs)
await pushary.notifications.send({
title: 'New Message',
body: 'You have a new message',
externalIds: ['user-123'],
})
// Send to subscribers with tags
await pushary.notifications.send({
title: 'VIP Exclusive',
body: 'Special offer just for you',
tags: ['vip'],
})TypeScript
Full TypeScript support with exported types:
import {
createPusharyServer,
type Subscriber,
type Campaign,
type Template,
type SendNotification,
} from '@pushary/server'License
MIT
