npm.io
0.2.0 • Published yesterdayCLI

@birrjs/core

Licence
MIT
Version
0.2.0
Deps
16
Size
1.4 MB
Vulns
0
Weekly
0
BirrJS Logo

BirrJS Core

Ethiopian payment billing and subscription management for TypeScript

npm version MIT license

GitHub · Documentation · Issues

About

BirrJS sits between your app and local/regional payment providers (Chapa, etc.) providing a unified API for subscriptions, entitlements, and billing.Tailored for Ethiopian payment providers and similar markets.

Features

  • Subscription management with automatic status tracking
  • Entitlement/feature-gating system
  • Multi-tenant customer management
  • Cron-based subscription expiry and reminder sweeps
  • Provider-agnostic adapter pattern (Chapa included)
  • Plugin system for extensibility
  • TypeScript-first with full type safety
  • PostgreSQL + Drizzle ORM

Installation

npm install @birrjs/core
# or
pnpm add @birrjs/core

Quick Start

import { createBirr, feature, plan } from "@birrjs/core";
import { chapa } from "@birrjs/chapa";

const messages = feature({ id: "messages", type: "metered" });

const free = plan({
  id: "free",
  name: "Free",
  default: true,
  includes: [messages({ limit: 100, reset: "month" })],
});

const pro = plan({
  id: "pro",
  name: "Pro",
  price: { amount: 29, interval: "monthly" },
  includes: [messages({ limit: 5000, reset: "month" })],
});

const birr = createBirr({
  database: process.env.DATABASE_URL!,
  provider: chapa({
    secretKey: process.env.CHAPA_SECRET_KEY!,
    webhookSecret: process.env.CHAPA_WEBHOOK_SECRET!,
    callbackUrl: process.env.CALLBACK_URL!,
    returnUrl: process.env.RETURN_URL!,
  }),
  plans: [free, pro],
  identify: async (request) => {
    const session = await auth.api.getSession({ headers: request.headers });
    if (!session) return null;
    return { customerId: session.user.id, email: session.user.email };
  },
});

License

MIT