npm.io
0.1.0 • Published 2d ago

@mooj/sdk

Licence
MIT
Version
0.1.0
Deps
0
Size
11 kB
Vulns
0
Weekly
0

@mooj/sdk

The official Mooj SDK. Issue capped virtual cards and let your agent complete real checkouts. Card controls, 3DS, and fraud caps are handled for you.

Install

npm install @mooj/sdk

Requires Node 18+ (uses the built-in fetch).

Quickstart

import { Mooj } from '@mooj/sdk';

const mooj = new Mooj(process.env.MOOJ_API_KEY!); // key looks like mk_live_...

// Issue a single-use card capped at $20
const card = await mooj.cards.create({
  amount: 20,
  merchant: 'namecheap',
  single_use: true,
});
console.log(card.id, card.last4, card.spend_limit);

Get your API key from the Mooj console (Developer -> API keys). Keep it server-side; never commit it.

Tools

Cards
const card = await mooj.cards.create({ amount: 20, merchant: 'namecheap', single_use: true });
const full = await mooj.cards.reveal(card.id);   // { number, cvc, exp, ... } — use at the moment of purchase
const closed = await mooj.cards.close(card.id);  // release the unused reserve back to your wallet
Spend status
const spend = await mooj.spend.get(card.spend_request_id!);
// spend.status: 'not_started' | 'authorized' | 'cleared' | 'declined'
Checkout (Mooj drives the buy)
const run = await mooj.checkout.create({
  task: 'buy the domain mooj.click for 1 year',
  merchant: 'namecheap',
  amount: 20,
  confirm_pay: false, // dry run: stops at the final review. true = pay up to the cap.
});

// poll until it finishes
let status = await mooj.checkout.get(run.checkout_id);
// status.status: 'queued' | 'running' | 'awaiting_approval' | 'needs_login' | 'submitted' | 'blocked'
Connections (login-gated merchants)
const conn = await mooj.connections.create({ merchant: 'namecheap', user_ref: 'user-123' });
// open conn.connect_url so the user signs in, then:
await mooj.connections.complete(conn.connection_id);
// now pass connection_id to checkout.create to run signed-in

Errors

Any non-2xx response throws a MoojError with the HTTP status, the Mooj error code, and the request id.

import { Mooj, MoojError } from '@mooj/sdk';

try {
  await mooj.cards.create({ amount: 999999, merchant: 'namecheap' });
} catch (e) {
  if (e instanceof MoojError) {
    console.error(e.status, e.code, e.requestId, e.message);
    // e.g. 402 insufficient_funds
  }
}

Configuration

new Mooj({
  apiKey: process.env.MOOJ_API_KEY!,
  baseUrl: 'https://mooj-api-277196974190.us-central1.run.app', // optional override
});

Docs

Full API reference: https://storage.googleapis.com/mooj-docs/index.html

Keywords