SDKs/TypeScript SDK

TypeScript SDK

Package: @mcards/sdkVersion: 2.0.0

Requirements: Node.js >= 16, TypeScript >= 4.7 (optional)

Installation

npm install @mcards/sdk

HMAC Authentication

typescript
import { McardsSdk } from '@mcards/sdk';

// HMAC authentication
const client = new McardsSdk({
  apiKey: process.env.MCARDS_API_KEY!,
  apiSecret: process.env.MCARDS_API_SECRET!,
  baseUrl: 'https://api.mcards.com', // optional
});

// All requests are automatically signed with HMAC-SHA256
const { data: profile } = await client.partner.getProfile();
console.log(`Partner: ${profile.name}`);

OAuth2 Bearer Token

typescript
// OAuth2 Bearer token authentication
const client = new McardsSdk();

// 1. Exchange credentials for token
const { data: token } = await client.oauth.createToken(
  'your-client-id',
  'your-client-secret',
  'partner:read wallets:read cards:read'
);

// 2. Set the Bearer token
client.setBearerToken(token.access_token);

// 3. Make authenticated requests
const { data: wallets } = await client.wallets.list();

Error Handling

typescript
// All methods return ApiResponse<T>
interface ApiResponse<T> {
  data: T;
  status: number;
  headers: Record<string, string>;
  error?: string;
  ok: boolean;
}

// Check response status
const result = await client.cards.get('card-uuid');
if (!result.ok) {
  console.error(`Error ${result.status}: ${result.error}`);
  return;
}
console.log(result.data); // typed as Card

Resource Reference

Partner

client.partner
getProfileGET /partner/profile

Get partner profile

getProfile(): Promise<ApiResponse<PartnerProfile>>
getApiKeysGET /partner/api_keys

List API keys

getApiKeys(): Promise<ApiResponse<{ api_keys: ApiKey[] }>>
getRolesGET /partner/roles

List partner roles

getRoles(): Promise<ApiResponse<{ roles: Role[] }>>

OAuth

client.oauth
createTokenPOST /oauth/token

Exchange credentials for token

createToken(clientId: string, clientSecret: string, scope?: string): Promise<ApiResponse<TokenResponse>>
revokeTokenPOST /oauth/revoke

Revoke an access token

revokeToken(token: string): Promise<ApiResponse<void>>
getTokenInfoGET /oauth/token_info

Introspect current token

getTokenInfo(): Promise<ApiResponse<TokenInfo>>
listScopesGET /oauth/scopes

List available scopes

listScopes(): Promise<ApiResponse<{ scopes: Scope[]; shorthands: Scope[] }>>
getRateLimitGET /oauth/rate_limit

Get rate limit status

getRateLimit(): Promise<ApiResponse<RateLimitInfo>>
listApplicationsGET /oauth/applications

List OAuth apps

listApplications(): Promise<ApiResponse<{ applications: OAuthApplication[] }>>
createApplicationPOST /oauth/applications

Create OAuth app

createApplication(name: string, scopes?: string, sandbox?: boolean): Promise<ApiResponse<OAuthApplicationDetail>>
getApplicationGET /oauth/applications/:uuid

Get app details

getApplication(uuid: string): Promise<ApiResponse<OAuthApplication>>
deleteApplicationDELETE /oauth/applications/:uuid

Revoke OAuth app

deleteApplication(uuid: string): Promise<ApiResponse<void>>

Wallets

client.wallets
listGET /wallets

List wallets

list(params?: { page?: number; per_page?: number }): Promise<ApiResponse<{ wallets: Wallet[]; meta: PaginationMeta }>>
getGET /wallets/:uuid

Get wallet details

get(uuid: string): Promise<ApiResponse<Wallet>>
updatePUT /wallets/:uuid

Update wallet

update(uuid: string, data: { name?: string; description?: string }): Promise<ApiResponse<Wallet>>

Cards

client.cards
listGET /cards

List cards

list(params?: { page?: number; per_page?: number; status?: string }): Promise<ApiResponse<{ cards: Card[]; meta: PaginationMeta }>>
createPOST /cards

Issue a new card

create(data: { cardholder_uuid?: string; program_uuid?: string }): Promise<ApiResponse<Card>>
getGET /cards/:uuid

Get card details

get(uuid: string): Promise<ApiResponse<Card>>
activatePUT /cards/:uuid/activate

Activate a card

activate(uuid: string): Promise<ApiResponse<Card>>
deactivatePUT /cards/:uuid/deactivate

Deactivate a card

deactivate(uuid: string): Promise<ApiResponse<Card>>
getBalanceGET /cards/:uuid/balance

Get card balance

getBalance(uuid: string): Promise<ApiResponse<CardBalance>>

Transactions

client.transactions
listGET /transactions

List transactions

list(params?: { page?: number; per_page?: number; start_date?: string; end_date?: string; card_uuid?: string }): Promise<ApiResponse<{ transactions: Transaction[]; meta: PaginationMeta }>>
getGET /transactions/:uuid

Get transaction details

get(uuid: string): Promise<ApiResponse<Transaction>>

Sandbox

client.sandbox
getEnvironmentGET /sandbox

Get sandbox info

getEnvironment(): Promise<ApiResponse<SandboxEnvironment>>
authorizePOST /sandbox/transactions/authorize

Simulate authorization

authorize(data: { amount: number; currency: string; merchant_name: string }): Promise<ApiResponse<SandboxTransaction>>
settlePOST /sandbox/transactions/settle

Simulate settlement

settle(data: { transaction_id: string; amount?: number }): Promise<ApiResponse<SandboxTransaction>>
refundPOST /sandbox/transactions/refund

Simulate refund

refund(data: { transaction_id: string; amount?: number }): Promise<ApiResponse<SandboxTransaction>>
declinePOST /sandbox/transactions/decline

Simulate decline

decline(data: { amount: number; currency: string; merchant_name: string; reason: string }): Promise<ApiResponse<SandboxTransaction>>