TypeScript SDK
npm install mca2-sdkWorks in Node.js (≥20) and modern browsers. No runtime dependencies -- built on native fetch. Ships ESM, CJS, and full type declarations.
Quickstart
import { MCA2Client } from "mca2-sdk";
const client = new MCA2Client({
clientId: "YOUR_CLIENT_ID",
clientSecret: "YOUR_CLIENT_SECRET",
audience: "YOUR_AUDIENCE",
// baseUrl defaults to the sandbox host: https://testapi.mcasuite.co
});Leads
const lead = await client.leads.add({
companyName: "Acme Inc",
companyDba: "Acme",
firstName: "Jane",
lastName: "Doe",
email: "jane@acme.com",
});Deals
const deal = await client.deals.add({
amountRequested: 50000,
stage: "Application",
company: { name: "Acme Inc", dba: "Acme" },
owner1: { firstName: "Jane", lastName: "Doe", ownership: "100" },
tags: ["Offer", "New"],
});
await client.deals.addNote({ dealId: deal.id!, status: "Paying On Time", note: "CEO approval received." });
const fetchedDeal = await client.deals.get(deal.id!);
import { readFile } from "node:fs/promises";
const bytes = await readFile("./statement.pdf");
await client.deals.addAttachment({ dealId: deal.id!, file: bytes, filename: "statement.pdf" });Companies
const company = await client.companies.add({ name: "Acme Inc", dba: "Acme", contactTypes: ["Merchant"] });
const fetchedCompany = await client.companies.get(company.id!);
await client.companies.update(company.id!, { website: "https://acme.example.com" });Submissions and submission loans
const submission = await client.submissions.add({
dealId: deal.id!, funder: "Acme Funding", advanceAmount: 50000.25, frequency: "1x/week",
});
const submissionLoan = await client.submissionLoans.add({
dealId: deal.id!, funder: "Acme Funding", loanAmount: 50000.25, frequency: "monthly",
});Bulk transactions
const result = await client.transactions.addBulk([
{ dealId: deal.id, type: "payment", amount: 10.25, date: "2024-01-15" },
]);Loan balances
const balances = await client.loans.getBalances({ limit: 100 });
for (const loan of balances.data) {
console.log(loan.dealId, loan.loanBalance);
}
// Page through further results
if (balances.nextId) {
const nextPage = await client.loans.getBalances({ limit: 100, nextId: balances.nextId });
}Error handling
All API errors throw a subclass of MCA2APIError (itself a subclass of MCA2Error), with .statusCode, .responseBody, and .requestUrl:
import { MCA2NotFoundError } from "mca2-sdk";
try {
await client.deals.get("does-not-exist");
} catch (err) {
if (err instanceof MCA2NotFoundError) {
console.log(err.statusCode, err.responseBody);
}
}See the full error reference for the exception-to-status-code mapping.
A complete runnable example lives at sdks/typescript/examples/quickstart.ts in the repository.