@journiq/node-sdk
v0.3.3
Published
Journiq Server-Side Node.js SDK — deep linking, event tracking, user identity, and notifications
Downloads
82
Maintainers
Readme
Installation
npm install @journiq/node-sdkQuick Start
import { Journiq } from '@journiq/node-sdk';
const journiq = new Journiq({
apiKey: 'jq_app_your_secret_key',
});
// Create a deep link
const link = await journiq.links.create({
title: 'Summer Sale',
redirectUrl: 'https://yourapp.com/sale',
data: { promoCode: 'SUMMER25' },
});
// Track an event
await journiq.events.track({
userId: 'user_123',
event: 'purchase',
properties: { amount: 49.99, currency: 'USD' },
});API Keys
| Key Prefix | Type | Access |
|---|---|---|
| jq_pub_ | Public | Events, Users, Notifications |
| jq_app_ | Secret | Full access (includes Links CRUD) |
Secret keys should only be used server-side. Never expose them in client code.
API Reference
Links (requires secret key)
// Create
const link = await journiq.links.create({ title: 'My Link', redirectUrl: 'https://example.com' });
// List
const { data, total } = await journiq.links.list({ page: 1, limit: 20 });
// Get by ID
const link = await journiq.links.get('link_id');
// Update
const updated = await journiq.links.update('link_id', { title: 'New Title' });
// Delete
await journiq.links.delete('link_id');
// Get stats
const stats = await journiq.links.getStats('link_id');Events
// Track single event
await journiq.events.track({
userId: 'user_123',
event: 'sign_up',
properties: { plan: 'pro' },
});
// Track batch
const result = await journiq.events.trackBatch([
{ userId: 'user_1', event: 'page_view', properties: { page: '/home' } },
{ userId: 'user_2', event: 'page_view', properties: { page: '/pricing' } },
]);Users
// Set identity
await journiq.users.setIdentity({ userId: 'user_123', deviceId: 'device_abc' });
// Remove identity
await journiq.users.removeIdentity({ userId: 'user_123', deviceId: 'device_abc' });
// Set user properties
await journiq.users.setProperties({
userId: 'user_123',
properties: { name: 'John', plan: 'enterprise' },
});Notifications
// List notifications
const { notifications, total } = await journiq.notifications.list({
userId: 'user_123',
unreadOnly: true,
limit: 10,
});
// Mark as read
await journiq.notifications.markRead('notification_id', 'user_123');
// Get unread count
const { count } = await journiq.notifications.getUnreadCount('user_123');Configuration
const journiq = new Journiq({
apiKey: 'jq_app_xxx',
baseUrl: 'https://api.getjourniq.com', // default
});Error Handling
import { JourniqError, SecretKeyRequiredError } from '@journiq/node-sdk';
try {
await journiq.links.create({ title: 'Test', redirectUrl: 'https://example.com' });
} catch (err) {
if (err instanceof SecretKeyRequiredError) {
// Called a secret-key-only method with a public key
} else if (err instanceof JourniqError) {
console.error(err.status, err.message);
}
}Requirements
- Node.js 18+
License
MIT
