Skip to content

Node.js SDK

The PulseRoute Node.js SDK provides a lightweight client for integrating intelligent payment routing into Node.js applications. Zero dependencies, TypeScript support, fire-and-forget outcome reporting.

Install

npm install @pulseroute/sdk

Quick Start

const PulseRoute = require('@pulseroute/sdk');

const client = PulseRoute.init({
  apiKey: process.env.PULSEROUTE_API_KEY,
  baseUrl: 'http://localhost:8080',
});

// Get routing decision
const decision = await client.getRoute({
  country: 'US',
  currency: 'USD',
  paymentMethod: 'card',
  amount: 99.99,
});

console.log(`Route to: ${decision.processorId}`);
// => Route to: stripe

// Report outcome (fire-and-forget)
client.reportOutcome({
  ruleId: 'us_usd_card',
  processorId: decision.processorId,
  success: true,
  latencyMs: 120,
});

TypeScript

import { init, RoutingDecision, Outcome } from '@pulseroute/sdk';

const client = init({ apiKey: process.env.PULSEROUTE_API_KEY! });

const decision: RoutingDecision = await client.getRoute({
  country: 'US',
  currency: 'USD',
  amount: 49.99,
});

Configuration

Option Type Default Description
apiKey string required API key for authentication
baseUrl string http://localhost:8080 PulseRoute API URL
timeout number 3000 HTTP timeout (ms)
flushInterval number 1000 Outcome flush interval (ms)
maxBufferSize number 500 Max buffered outcomes
enableCache boolean true Cache routing decisions locally

Programmatic Onboarding

Set up routing rules from code instead of the dashboard wizard:

const result = await client.onboard({
  processors: [
    {
      processorId: 'stripe',
      name: 'Stripe',
      countries: ['US', 'GB'],
      currencies: ['USD', 'GBP'],
      paymentMethods: ['card', 'wallet'],
      priority: 1,
    },
    {
      processorId: 'adyen',
      name: 'Adyen',
      countries: ['US', 'GB', 'DE'],
      currencies: ['USD', 'GBP', 'EUR'],
      priority: 2,
    },
  ],
});

console.log(`${result.rulesCreated} rules created`);

Resilience

The SDK is designed to never block your payment path:

  • Outcome buffering: reportOutcome() returns immediately. Outcomes are flushed in the background.
  • Local caching: If the API is unreachable, getRoute() returns the last known good decision.
  • Graceful shutdown: await client.shutdown() flushes remaining outcomes before exit.
  • Timeout protection: All API calls have a configurable timeout (default 3s).

API Reference

See the full Node.js SDK README for detailed API documentation.