npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

bazik-sdk

v1.0.2

Published

Unofficial JavaScript/Node.js SDK for the Bazik API — MonCash & NatCash payments, transfers, and wallet management for Haiti.

Downloads

270

Readme


Features

  • Zero dependencies — Uses native fetch (Node.js 18+)
  • ESM & CommonJS — Works with import and require out of the box
  • Automatic token management — Handles auth token lifecycle, refresh, and retry
  • Full TypeScript support — Complete .d.ts type definitions included
  • Input validation — Catches errors before they hit the API
  • Structured errors — Typed error classes for every failure mode
  • MonCash payments — Create, verify, and poll payment status
  • MonCash & NatCash transfers — Send money to wallets directly
  • Wallet management — Check balance, get fee quotes

Installation

npm install bazik-sdk

Quick Start

// ESM
import { Bazik } from "bazik-sdk";

// CommonJS
const { Bazik } = require("bazik-sdk");

const bazik = new Bazik({
  userID: "bzk_c5b754a0_1757383229",
  secretKey: "sk_5b0ff521b331c73db55313dc82f17cab",
});

// Authentication happens automatically on first API call.
// You can also authenticate explicitly:
await bazik.authenticate();

Accept a Payment

// 1. Create the payment
const payment = await bazik.payments.create({
  gdes: 1284.0,
  successUrl: "https://mysite.com/success",
  errorUrl: "https://mysite.com/error",
  description: "iPhone Pro Max",
  referenceId: "ORDER-001",
  customerFirstName: "Franck",
  customerLastName: "Jean",
  customerEmail: "[email protected]",
  webhookUrl: "https://mysite.com/webhook",
});

// 2. Redirect customer to MonCash payment page
console.log("Redirect →", payment.redirectUrl);

// 3. Verify the payment (after redirect or via webhook)
const status = await bazik.payments.verify(payment.orderId);
console.log("Status:", status.status); // "successful" | "pending" | "failed"

Send Money (Transfer)

// Check recipient wallet first
const customer = await bazik.transfers.checkCustomer("37123456");
console.log("KYC:", customer.customerStatus.type);

// Get a fee quote
const quote = await bazik.transfers.getQuote(500, "moncash");
console.log(`Fee: ${quote.fee} HTG | Total: ${quote.total_cost} HTG`);

// Send via MonCash
const transfer = await bazik.transfers.moncash({
  gdes: 500,
  wallet: "47556677",
  customerFirstName: "Melissa",
  customerLastName: "Francois",
  description: "Salary payment",
});

console.log("Transaction:", transfer.transaction_id);

// Or send via NatCash
const natTransfer = await bazik.transfers.natcash({
  gdes: 50,
  wallet: "44556677",
  customerFirstName: "Marie",
  customerLastName: "Pierre",
});

Withdraw to a MonCash Wallet

Send money from your Bazik account to a customer's MonCash wallet (payout).

const withdrawal = await bazik.payments.withdraw({
  gdes: 500,                            // amount in HTG
  wallet: "47556677",                   // recipient phone (8 or 11 digits)
  customerFirstName: "Melissa",
  customerLastName: "Francois",
  description: "Weekly earnings",
  referenceId: "PAYOUT-001",
  customerEmail: "[email protected]",
  webhookUrl: "https://mysite.com/webhook",
});

console.log("Transaction:", withdrawal.transaction_id);
console.log("Status:     ", withdrawal.status);
console.log("Total cost: ", withdrawal.total, withdrawal.currency);

Required fields: gdes, wallet, customerFirstName, customerLastName. The other fields are optional. The same typed errors apply — wrap calls in try/catch to handle BazikInsufficientFundsError, BazikValidationError, etc.

Check Balance

const wallet = await bazik.wallet.getBalance();
console.log(`Available: ${wallet.available} ${wallet.currency}`);
console.log(`Reserved: ${wallet.reserved} ${wallet.currency}`);

API Reference

new Bazik(config)

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | userID | string | required | Your Bazik user ID | | secretKey | string | required | Your secret key | | baseURL | string | https://api.bazik.io | API base URL | | autoRefresh | boolean | true | Auto-refresh token before expiry | | timeout | number | 30000 | Request timeout (ms) | | onTokenRefresh | function | — | Callback when token refreshes |

bazik.payments

| Method | Description | |--------|-------------| | .create(params) | Create a MonCash payment (max 75,000 HTG) | | .verify(orderId) | Get payment status by order ID | | .waitForCompletion(orderId, opts?) | Poll until payment resolves | | .withdraw(params) | Send money to a MonCash wallet | | .getBalance() | Get account balance |

bazik.transfers

| Method | Description | |--------|-------------| | .checkCustomer(wallet) | Check MonCash wallet KYC status | | .moncash(params) | Create a MonCash transfer | | .natcash(params) | Create a NatCash transfer | | .getStatus(transactionId) | Get transfer status | | .getQuote(amount, provider) | Get fee quote before transfer |

bazik.wallet

| Method | Description | |--------|-------------| | .getBalance() | Get wallet balance (available + reserved) |

Error Handling

The SDK provides typed error classes for precise error handling:

import {
  Bazik,
  BazikError,                  // Base error
  BazikAuthError,              // 401 — Invalid credentials
  BazikValidationError,        // 400 — Invalid input
  BazikInsufficientFundsError, // 402 — Not enough balance
  BazikRateLimitError,         // 429 — Too many requests
} from "bazik-sdk";

try {
  await bazik.payments.create({ gdes: 500 });
} catch (err) {
  if (err instanceof BazikInsufficientFundsError) {
    console.error("Top up your account!");
  } else if (err instanceof BazikAuthError) {
    console.error("Check your credentials.");
  } else if (err instanceof BazikValidationError) {
    console.error("Invalid input:", err.details);
  } else if (err instanceof BazikRateLimitError) {
    console.error("Slow down — retry later.");
  } else {
    console.error("Unexpected:", err.message);
  }
}

Every error has these properties:

| Property | Type | Description | |----------|------|-------------| | message | string | Human-readable description | | status | number \| null | HTTP status code | | code | string \| null | Machine-readable error code | | details | any | Additional context |

Polling Payment Status

Instead of using webhooks, you can poll for payment completion:

try {
  const result = await bazik.payments.waitForCompletion(payment.orderId, {
    intervalMs: 5000,  // check every 5s
    timeoutMs: 120000, // give up after 2min
  });
  console.log("Final status:", result.status);
} catch (err) {
  if (err.code === "timeout") {
    console.log("Customer hasn't completed payment yet.");
  }
}

Testing

node --test tests/

No external test framework required — uses Node.js built-in test runner.

Requirements

  • Node.js >= 18.0.0 (for native fetch)

Links

License

MIT — see LICENSE for details.