Production-grade TypeScript SDK for the Setu API platform.
This SDK provides:
- Typed configuration management
- Automatic OAuth token management with caching
- Retry + exponential backoff handling
- Built-in client-side rate limiting
- Structured error handling
- Telemetry hooks for observability
- Webhook dispatch utilities
- Validation helpers
- UPI, BBPS, KYC, AA, and eSign integrations
Located in config/index.ts
- Environment-aware URL resolution
- Immutable validated SDK configuration
- Sandbox and production support
- Request timeout and retry configuration
- Built-in rate limiting configuration
Located in token/index.ts
- Automatic access token fetching
- In-memory token caching
- Token refresh buffering
- Singleflight refresh deduplication
- Cache invalidation helpers
Located in http/index.ts
- Typed request wrappers
- Automatic retries
- Full-jitter exponential backoff
- Timeout handling
- Structured API error decoding
- Integrated telemetry and rate limiting
Located in ratelimit/index.ts
- Token bucket implementation
- Per-client/environment buckets
- Configurable burst limits
- Request throttling with timeout support
Located in telemetry/index.ts
Event-based observability layer using Node.js EventEmitter.
Supported events:
request:startrequest:stoprequest:exceptiontoken:refreshratelimit:wait
npm install setu-clientimport { createConfig } from "setu-client";
import { createDqr } from "setu-client/payments/upi";
const cfg = createConfig({
clientId: process.env.SETU_CLIENT_ID!,
clientSecret: process.env.SETU_CLIENT_SECRET!,
environment: "sandbox",
});
const result = await createDqr(cfg, "merchant-id", {
merchantVpa: "shop@upi",
amount: 10_000,
});
if (result.ok) {
console.log(result.data);
} else {
console.error(result.error);
}setu-client/
├── config/
├── data/
│ ├── aa.ts
│ ├── esign.ts
│ └── kyc/
├── error/
├── http/
├── payments/
│ ├── bbps.ts
│ └── upi.ts
├── ratelimit/
├── telemetry/
├── token/
├── validation/
├── webhook/
└── index.ts
import { createConfig } from "setu-client";
const cfg = createConfig({
clientId: "your-client-id",
clientSecret: "your-client-secret",
environment: "sandbox",
});| Option | Description | Default |
|---|---|---|
clientId |
Setu client ID | Required |
clientSecret |
Setu client secret | Required |
productInstanceId |
Product instance ID | Optional |
environment |
sandbox or production |
sandbox |
timeoutMs |
Request timeout | 30000 |
maxRetries |
Maximum retry attempts | 3 |
retryBaseDelayMs |
Base retry delay | 500 |
retryMaxDelayMs |
Max retry delay | 10000 |
rateLimitRps |
Requests per second | 100 |
rateLimitBurst |
Burst capacity | 20 |
Located in error/index.ts
All SDK operations return:
type SetuResult<T> =
| { ok: true; data: T }
| { ok: false; error: SetuError };| Type | Description |
|---|---|
api |
Non-2xx API response |
auth |
Authentication failure |
rate_limit |
HTTP 429 response |
network |
Network or timeout issue |
validation |
Local validation failure |
decode |
JSON decoding failure |
if (!result.ok) {
console.error(result.error.type);
console.error(result.error.message);
}Located in validation/index.ts
Available helpers:
requireParam()requirePositive()requireId()requireMerchant()chain()
const validation = chain(
requireMerchant(merchantId),
requirePositive(amount, "amount")
);
if (!validation.ok) {
return validation.error;
}Located in telemetry/index.ts
import { telemetry } from "setu-client";
telemetry.on("request:start", (event) => {
console.log(event.method, event.url);
});{
method: string;
url: string;
attempt: number;
startTimeMs: number;
}{
method: string;
url: string;
attempt: number;
durationMs: number;
httpStatus?: number;
}{
method: string;
url: string;
attempt: number;
durationMs: number;
error: SetuError;
}Located in token/index.ts
- Automatic token refresh
- Token caching
- Refresh buffering
- Concurrent request deduplication
import {
getToken,
invalidateToken,
clearTokenCache,
} from "setu-client";Located in webhook/index.ts
Unified webhook dispatcher for all Setu events.
payment.initiatedpayment.pendingpayment.successpayment.failed
mandate.initiatedmandate.livemandate.rejectedmandate.pausedmandate.revoked- Mandate operation lifecycle events
refund.pendingrefund.successful
dispute_createddispute_opendispute_closeddispute_in_reviewdispute_wondispute_lost
CONSENT_STATUS_UPDATESESSION_STATUS_UPDATE
Automatically detected using payload structure.
import { dispatchRaw } from "setu-client/webhook";
await dispatchRaw(rawBody, {
async handlePayment(event) {
console.log("Payment event", event);
},
async handleConsent(event) {
console.log("Consent update", event);
},
});eventType()consentId()sessionId()consentStatus()sessionStatus()isPaymentSuccessful()isConsentActive()isSessionCompleted()
Located in payments/
File: payments/upi.ts
Provides helpers for:
- Dynamic QR creation
- Payment link generation
- Transaction retrieval
- UPI collect flows
- Merchant transaction history
File: payments/bbps.ts
Provides helpers for:
- Bill payment flows
- Settlement history
- BBPS transaction management
Located in data/
File: data/aa.ts
Features:
- Consent creation
- Session handling
- Financial information retrieval
- Consent status tracking
File: data/esign.ts
Features:
- Electronic signature workflows
- Document signing integration
- Status retrieval
Located in data/kyc/
Supported integrations:
| File | Purpose |
|---|---|
bav.ts |
Bank account verification |
digilocker.ts |
DigiLocker integration |
ekyc.ts |
Electronic KYC workflows |
gst.ts |
GST verification |
namematch.ts |
Name matching utilities |
pan.ts |
PAN verification |
The SDK automatically handles:
- Retries for retryable status codes
- Retryable network errors
- Exponential backoff
- Rate limiting
- Request timeout handling
- Structured error decoding
Retryable HTTP statuses:
429500502503504
The SDK avoids throwing for expected operational errors.
Instead:
const result = await someSdkCall();
if (result.ok) {
// success
} else {
// handle error
}createConfig() returns a frozen configuration object.
Token refresh requests are deduplicated to prevent token stampedes.
The SDK includes:
- Retry strategies
- Rate limiting
- Telemetry hooks
- Timeout handling
- Structured errors
- Validation helpers
- Account Service:
https://accountservice.setu.co - UMAP API:
https://umap.setu.co/api - Data Gateway:
https://dg-sandbox.setu.co - FIU:
https://fiu-sandbox.setu.co
- Account Service:
https://accountservice.setu.co - UMAP API:
https://umap.setu.co/api - Data Gateway:
https://dg.setu.co - FIU:
https://fiu.setu.co
- Reuse a single
SetuConfiginstance - Attach telemetry listeners for monitoring
- Handle all
SetuResultfailures explicitly - Use sandbox before production rollout
- Tune retry and rate-limit settings based on traffic
import express from "express";
import { dispatchRaw } from "setu-client/webhook";
const app = express();
app.post(
"/webhooks/setu",
express.raw({ type: "application/json" }),
async (req, res) => {
const ok = await dispatchRaw(req.body.toString(), {
async handlePayment(event) {
console.log("payment", event);
},
});
res.sendStatus(ok ? 200 : 400);
}
);The root index.ts re-exports:
- Configuration helpers
- Error utilities
- Telemetry
- Token helpers
- Rate limiter helpers
- Validation helpers
- Webhook helpers
- Payments APIs
- KYC APIs
- AA APIs
- eSign APIs
This SDK is structured as a production-ready foundation for integrating with the Setu ecosystem.
It provides:
- Strong TypeScript ergonomics
- Safe and predictable error handling
- Scalable networking primitives
- Observability support
- Modular API integrations
- Built-in resiliency patterns
Suitable for:
- Payment gateways
- Fintech backends
- KYC pipelines
- Account Aggregator integrations
- BBPS workflows
- Enterprise API platforms