JSPM

pushfire

0.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q79747F
  • License MIT

Official Node.js client for Pushfire - Push notification and workflow automation platform

Package Exports

  • pushfire

Readme

Pushfire - Official Node.js Client

A product of Flywheel Studio

npm version License: MIT Node.js Version

Official Node.js client for Pushfire - the powerful push notification and workflow automation platform.

Features

  • 🚀 Easy device registration and management
  • 👤 Subscriber authentication and profiling
  • 🏷️ Tagging system for targeted notifications
  • 📊 Workflow automation for engagement
  • 🔒 Secure API communication
  • 🌐 Cross-platform support (Browser, Node.js, React Native)

Installation

npm install pushfire
# or
yarn add pushfire
# or
pnpm add pushfire

Quick Start

Client-side Usage

import { createClient } from 'pushfire';

// Initialize the client
const pushfire = createClient({
  token: 'your_project_token',
});

// Register a device with FCM token
async function registerDevice(fcmToken) {
  try {
    const result = await pushfire.init(fcmToken);
    console.log('Device registered:', result.deviceId);
    console.log('Subscriber ID:', result.subscriberId);
  } catch (error) {
    console.error('Registration failed:', error);
  }
}

// Login a subscriber
async function loginSubscriber(externalId, name, email) {
  try {
    const deviceId = pushfire.getStoredDeviceId();
    if (!deviceId) {
      throw new Error('Device not registered');
    }

    const result = await pushfire.subscribers.login({
      deviceId,
      externalId,
      name,
      email,
    });

    console.log('Subscriber logged in:', result.subscriberId);
  } catch (error) {
    console.error('Login failed:', error);
  }
}

Server-side Usage

import { createServer } from 'pushfire';

// Initialize the server
const pushfireServer = createServer({
  token: 'your_project_token',
});

// Example in Express.js - Login subscriber with cookie context
app.post('/api/login', async (req, res) => {
  try {
    const cookieHeader = req.headers.cookie || '';
    const { externalId, name, email } = req.body;

    const { response, cookieHeaders } = await pushfireServer.loginSubscriberFromContext(
      cookieHeader,
      {
        externalId,
        name,
        email,
      }
    );

    // Set cookies in response
    cookieHeaders.forEach(header => {
      res.setHeader('Set-Cookie', header);
    });

    res.status(200).json({
      success: true,
      subscriberId: response.subscriberId,
    });
  } catch (error) {
    res.status(500).json({
      success: false,
      error: error.message,
    });
  }
});

// Add tag to subscriber using cookie context
app.post('/api/add-tag', async (req, res) => {
  try {
    const cookieHeader = req.headers.cookie || '';
    const { tagId, value } = req.body;

    await pushfireServer.addTagFromContext(cookieHeader, tagId, value);

    res.status(200).json({ success: true });
  } catch (error) {
    res.status(500).json({
      success: false,
      error: error.message,
    });
  }
});

API Reference

Client

  • createClient(config) - Creates a new Pushfire client instance
  • client.init(fcmToken, options?) - Initializes Pushfire by registering the device
  • client.devices.register(data) - Registers a new device
  • client.devices.update(data) - Updates an existing device
  • client.subscribers.login(data) - Logs in a subscriber
  • client.subscribers.logout(data) - Logs out a subscriber
  • client.subscribers.update(data) - Updates subscriber information
  • client.subscriberTags.add(data) - Adds a tag to a subscriber
  • client.subscriberTags.update(data) - Updates a subscriber tag
  • client.subscriberTags.remove(data) - Removes a tag from a subscriber
  • client.workflowExecutions.create(data) - Creates a workflow execution

Server

The server instance provides two types of functionality:

1. Direct Resource Access

All client resources are directly accessible through the server instance:

  • server.devices - Device operations
  • server.subscribers - Subscriber operations
  • server.subscriberTags - Tag operations
  • server.workflowExecutions - Workflow operations

2. Context-Aware Methods

These methods use cookie headers to extract device and subscriber context:

  • server.extractContext(cookieHeader) - Extracts device context from cookies
  • server.createCookieHeaders(data) - Creates Set-Cookie headers for device data

Device Operations:

  • server.registerDeviceWithContext(data) - Registers a device and returns cookie headers
  • server.updateDeviceFromContext(cookieHeader, data) - Updates a device using cookie context

Subscriber Operations:

  • server.loginSubscriberFromContext(cookieHeader, data) - Logs in a subscriber and returns cookie headers
  • server.logoutSubscriberFromContext(cookieHeader) - Logs out a subscriber and returns cookie headers
  • server.updateSubscriberFromContext(cookieHeader, data) - Updates a subscriber using cookie context

Tag Operations:

  • server.addTagFromContext(cookieHeader, tagId, value) - Adds a tag using cookie context
  • server.updateTagFromContext(cookieHeader, tagId, value) - Updates a tag using cookie context
  • server.removeTagFromContext(cookieHeader, tagId) - Removes a tag using cookie context

Workflow Operations:

  • server.createWorkflowExecutionFromContext(data) - Creates a workflow execution

MIT © Pushfire


Pushfire is a product of Flywheel Studio