API Gateway TypeScript SDK

Access myPOS Banking, Ecommerce, and ePOS services from your Node.js backend!

The myPOS API Gateway TypeScript SDK (mypos-api-gateway) is a server-side package for Node.js that provides a typed client for all three myPOS service namespaces. It handles dual-token authentication (OAuth + session), automatic token refresh, multi-merchant support, and result-based error handling — all with zero external dependencies.

Server-side only: This package uses your Partner Portal credentials. Never import or run it in a browser or client-side bundle.

Key Capabilities

Dual-token auth (OAuth + session)
Multi-merchant support
Auto-retry on 401 (token refresh)
Result-based error handling
ESM/CJS dual build
Zero external dependencies
Full TypeScript definitions
Auto-pagination async generators

Requirements

Node.js 18+

Uses native fetch. No polyfills required.

Partner Portal Credentials

Integration client ID/secret, partner ID, and application ID from your Partner Portal.

Installation

npm install mypos-api-gateway

Environment Variables

VariableDescription
MYPOS_GATEWAY_URLGateway base URL (use DEMO_GATEWAY_URL for testing)
MYPOS_INTEGRATION_CLIENT_IDOAuth client ID from Partner Portal
MYPOS_INTEGRATION_CLIENT_SECRETOAuth client secret from Partner Portal
MYPOS_PARTNER_IDYour partner identifier
MYPOS_APPLICATION_IDYour application identifier

The package exports two URL constants for convenience:

import { DEMO_GATEWAY_URL, PRODUCTION_GATEWAY_URL } from 'mypos-api-gateway'

Gateway & Merchant Clients

The SDK uses a two-level client pattern:

  1. MyPOSGateway — instantiated once at startup with your integration credentials. Manages the shared OAuth token (1-hour TTL, auto-refreshed 60 seconds before expiry).
  2. gateway.createClient() — creates a per-merchant client scoped to a specific merchant's credentials. Manages the per-merchant session token (5-minute TTL, auto-refreshed 30 seconds before expiry).
import { MyPOSGateway, DEMO_GATEWAY_URL } from 'mypos-api-gateway'

const gateway = new MyPOSGateway({
  gatewayUrl: DEMO_GATEWAY_URL,
  integration: {
    clientId: process.env.MYPOS_INTEGRATION_CLIENT_ID!,
    clientSecret: process.env.MYPOS_INTEGRATION_CLIENT_SECRET!,
  },
  partnerId: process.env.MYPOS_PARTNER_ID!,
  applicationId: process.env.MYPOS_APPLICATION_ID!,
})

const client = gateway.createClient({
  clientId: 'cli_merchant123',
  clientSecret: 'sec_abc456',
})

Continue Reading