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
Requirements
Uses native fetch. No polyfills required.
Integration client ID/secret, partner ID, and application ID from your Partner Portal.
Installation
npm install mypos-api-gateway
Environment Variables
| Variable | Description |
|---|---|
MYPOS_GATEWAY_URL | Gateway base URL (use DEMO_GATEWAY_URL for testing) |
MYPOS_INTEGRATION_CLIENT_ID | OAuth client ID from Partner Portal |
MYPOS_INTEGRATION_CLIENT_SECRET | OAuth client secret from Partner Portal |
MYPOS_PARTNER_ID | Your partner identifier |
MYPOS_APPLICATION_ID | Your 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:
MyPOSGateway— instantiated once at startup with your integration credentials. Manages the shared OAuth token (1-hour TTL, auto-refreshed 60 seconds before expiry).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',
})