Skip to content

Adjanour/mnotify-ts-sdk

Repository files navigation

mNotify TypeScript SDK

npm version JSR CI License

Zero-dependency TypeScript SDK for mNotify BMS API — send SMS, manage contacts and groups, and handle account operations with railway-oriented programming.

  • Zero runtime dependencies — uses native fetch
  • Runtime-agnostic — Node 18+, Deno, Bun, Cloudflare Workers, browsers
  • Functional error handling — every method returns a Result type
  • Dual-publishednpm + JSR

Quick Start

npm install mnotify-ts-sdk
import { MNotify } from "mnotify-ts-sdk";

const mnotify = new MNotify({
  apiKey: process.env.MNOTIFY_API_KEY!,
});

const result = await mnotify.sms.send({
  recipient: "233200000000",
  sender: "MyApp",
  message: "Hello from mNotify!",
});

result.match({
  ok: (res) => console.log(`Sent! Campaign: ${res.summary._id}`),
  err: (err) => console.error(`Failed: ${err.message}`),
});

Services

Service Methods Description
mnotify.sms send, getStatus Send SMS and check delivery
mnotify.contacts create, list Manage contacts
mnotify.groups create, list, get, addContact, removeContact, delete Contact groups
mnotify.templates create, list, get, delete SMS templates
mnotify.account getBalance, registerSender, checkSender Account & sender IDs

Every method returns Result<T, MNotifyError> — see Error Handling.

Error Handling

No try/catch needed. Every method returns a Result type:

const result = await mnotify.account.getBalance();

if (result.isOk()) {
  console.log(`Balance: ${result.value.balance}`);
  console.log(`Bonus: ${result.value.bonus ?? 0}`);
} else {
  console.error(result.error.message, result.error.statusCode);
}

Chain operations with .map() and .andThen():

import { ok, err, tryCatch, combine } from "mnotify-ts-sdk";

const final = await result
  .map((data) => transform(data))
  .andThen((transformed) => doMore(transformed));

Installation

Node / npm

npm install mnotify-ts-sdk
import { MNotify } from "mnotify-ts-sdk";

Bun

bun add mnotify-ts-sdk
import { MNotify } from "mnotify-ts-sdk";

JSR

npx jsr add @adjarnor/mnotify-ts-sdk

Deno

deno add jsr:@adjarnor/mnotify-ts-sdk
import { MNotify } from "jsr:@adjarnor/mnotify-ts-sdk";

Configuration

const mnotify = new MNotify({
  apiKey: "your-api-key",     // required
  baseUrl: "https://...",      // optional (default: https://api.mnotify.com/api)
  timeout: 10000,              // optional (default: 10000ms)
  maxRetries: 3,               // optional (default: 3, only on 429)
});

Docs

Full documentation at https://adjanour.github.io/mnotify-ts-sdk or run locally:

npm run docs:dev

Examples

Runnable examples live in examples/:

  • npm run example:sms
  • npm run example:railway
  • npm run example:content

Cross-runtime example commands:

  • Node: npm run build && npm run example:smoke
  • Bun: npm run build && MNOTIFY_EXAMPLE_MODE=smoke bun run examples/sendSMS.ts
  • Deno: npm run build && MNOTIFY_EXAMPLE_MODE=smoke deno run --allow-env examples/sendSMS.ts

Scripts

Script Description
npm run build Build ESM + CJS
npm test Run tests
npm run lint Biome lint
npm run format Biome format
npm run example:sms Run the SMS example
npm run example:railway Run the Result-pattern example
npm run example:content Run the groups/templates example
npm run example:smoke Smoke-run all examples in Node
npm run docs:dev Start docs dev server
npm run docs:build Build static docs

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors