Licence
MIT
Version
0.2.3
Deps
0
Size
85 kB
Vulns
0
Weekly
0
NezaHub Node.js SDK
Official Node/TypeScript client for the NezaHub REST API (/api/v1/).
- Developer docs: nezahub.com/docs — authentication, checkout, webhooks, API reference
Install
npm install @nezahub/sdk
Local development (monorepo):
cd sdks/node
npm install && npm run build
# or from repo root:
make sdk-node
Requires Node 18+. ESM ("type": "module").
Subpath exports
| Import | Use |
|---|---|
@nezahub/sdk |
Server API client, tree-shakeable helpers, webhooks |
@nezahub/sdk/checkout |
Browser-safe checkout (no API key) |
@nezahub/sdk/webhooks |
Webhook signature verification |
Environments
| Environment | baseUrl |
|---|---|
| Sandbox | https://sandbox-api.nezahub.com |
| Live | https://api.nezahub.com |
export NEZAHUB_BASE_URL=https://api.nezahub.com
export NEZAHUB_API_KEY=nz_live_...
Server client (API key)
import { NezaHubClient, nezahubSetup } from "@nezahub/sdk";
nezahubSetup({ apiKey: process.env.NEZAHUB_API_KEY!, onError: console.error });
const client = new NezaHubClient();
const health = await client.health();
Server client (JWT login)
import { NezaHubClient } from "@nezahub/sdk";
const bootstrap = new NezaHubClient({ baseUrl: "https://sandbox-api.nezahub.com" });
const { tokens } = await bootstrap.auth.login({
phone: "+254700000099",
password: "demo12345",
});
const client = new NezaHubClient({ accessToken: tokens.access });
const me = await client.auth.me();
Email + password login is supported by the API but not yet on auth.login — call POST /auth/login/ with fetch or extend the client until the SDK adds email.
Tree-shakeable helpers (Lemon Squeezy-style)
import { listProducts, safe } from "@nezahub/sdk";
const products = await listProducts();
const { data, error } = await safe.listProducts();
Browser-safe checkout (Paddle.js-style)
import { NezaHubCheckoutClient } from "@nezahub/sdk/checkout";
const checkout = new NezaHubCheckoutClient({
environment: "test",
baseUrl: "https://sandbox-api.nezahub.com", // optional; for hosted sandbox
});
const session = await checkout.startFromLink("your-link-slug", {
customerPhone: "+254700000099",
});
Never import the main @nezahub/sdk client in browser bundles with an API key.
Resources
| Property | Examples |
|---|---|
client.auth |
login, me, refreshToken, verify2fa |
client.products |
list, create, update, delete |
client.prices |
create, update |
client.paymentLinks |
create, list |
client.checkout |
createSession, confirm |
client.transactions |
list, get |
client.agents |
CRUD, assignments |
client.payouts |
balance, create (2FA) |
client.wallets |
quoteTransfer, createTransfer (2FA) |
Webhooks
import { constructEvent } from "@nezahub/sdk/webhooks";
const event = constructEvent(rawBody, signature, webhookSecret);
Build
npm run build # compile to dist/
npm run dev # watch mode
Integration tests
make dev && make migrate
cd sdks/node
NEZAHUB_INTEGRATION=1 NEZAHUB_2FA_CODE=123456 node tests/integration-flow.mjs
Or from repo root: make test-sdk-node