nodejs-cryptomus
Version:
A comprehensive Node.js client for the Cryptomus API
129 lines (118 loc) • 2.79 kB
text/typescript
/**
* API configuration options
*/
export interface CryptomusOptions {
/** Merchant/payment API key */
merchantId: string;
/** Payment API key */
paymentKey: string;
/** Payout API key (required for payout operations) */
payoutKey?: string;
/** API base URL (default: 'https://api.cryptomus.com/v1') */
apiUrl?: string;
}
/**
* API request options
*/
export interface RequestOptions {
/** Request headers */
headers?: Record<string, string>;
/** Request timeout in milliseconds */
timeout?: number;
}
/**
* Base API response structure
*/
export interface ApiResponse<T> {
/** Status of the request */
state: 0 | 1;
/** Status message */
message?: string;
/** Response data */
result: T;
}
/**
* Error response
*/
export interface ApiErrorResponse {
/** Status of the request */
state: 0;
/** Error message */
message: string;
/** Error details */
errors?: Record<string, string[]>;
}
/**
* Supported currencies and networks
*/
export interface CurrencyInfo {
/** Currency code */
currency: string;
/** Currency network */
network: string;
}
/**
* Balance information
*/
export interface BalanceInfo {
/** Currency code */
currency: string;
/** Current balance */
balance: string;
/** Whether the currency is active */
is_active: boolean;
}
/**
* Currency information
*/
export interface CurrencyNetworkInfo {
/** Network identifier */
network: string;
/** Currency code */
currency: string;
/** Network name */
name: string;
/** Smart contract address (if applicable) */
contract?: string;
/** Minimum payment amount */
min_amount: string;
/** Maximum payment amount */
max_amount: string;
/** Minimum payout amount */
min_payout_amount?: string;
/** Maximum payout amount */
max_payout_amount?: string;
/** Whether the currency is active */
is_active: boolean;
}
/**
* Payment limit information
*/
export interface PaymentLimitInfo {
/** Currency code */
currency: string;
/** Minimum payment amount */
min_amount: string;
/** Maximum payment amount */
max_amount: string;
}
/**
* Cryptomus API error
*/
export class CryptomusError extends Error {
/** Error details */
public readonly errors?: Record<string, string[]>;
/** HTTP status code */
public readonly statusCode?: number;
constructor(message: string, errors?: Record<string, string[]>, statusCode?: number) {
super(message);
this.name = 'CryptomusError';
this.errors = errors;
this.statusCode = statusCode;
// Maintains proper stack trace for where our error was thrown
// Check if Error.captureStackTrace exists before calling it
if (typeof Error.captureStackTrace === 'function') {
Error.captureStackTrace(this, CryptomusError);
}
}
}