JSPM

artha-js

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q36396F
  • License MIT

Artha JS Library - Complete billing and pricing infrastructure SDK

Package Exports

  • artha-js
  • artha-js/backend
  • artha-js/better-auth
  • artha-js/convex
  • artha-js/elysia
  • artha-js/express
  • artha-js/fastify
  • artha-js/hono
  • artha-js/next
  • artha-js/react
  • artha-js/react-router
  • artha-js/supabase
  • artha-js/tanstack

Readme

Artha JS SDK

The official JavaScript/TypeScript SDK for Artha billing infrastructure. Build powerful billing and pricing systems with ease.

Installation

npm install artha-js

Quick Start

Basic Usage

import { Artha } from 'artha-js';

// Initialize with your backend URL and API key
const artha = new Artha('https://your-backend-url.com', 'your-api-key');

// Check feature access
const checkResult = await artha.check({
  featureId: 'premium-feature',
  productId: 'pro-plan'
});

// Track usage
await artha.track({
  featureId: 'api-calls',
  value: 1,
  entityId: 'optional-entity-id'
});

// Attach product to customer
const attachResult = await artha.attach({
  productId: 'pro-plan',
  customerId: 'customer-123'
});

React Integration

import { ArthaProvider, useCustomer, usePricingTable } from 'artha-js/react';

function App() {
  return (
    <ArthaProvider 
      backendUrl={process.env.REACT_APP_ARTHA_BACKEND_URL} 
      apiKey={process.env.REACT_APP_ARTHA_API_KEY}
    >
      <CustomerDashboard />
    </ArthaProvider>
  );
}

function CustomerDashboard() {
  const { customer, loading } = useCustomer();
  const { products } = usePricingTable();

  if (loading) return <div>Loading...</div>;

  return (
    <div>
      <h1>Welcome, {customer?.name}</h1>
      {/* Your billing UI here */}
    </div>
  );
}

Backend Integration

Next.js

import { createArthaHandler } from 'artha-js/next';

export const { GET, POST } = createArthaHandler({
  backendUrl: process.env.ARTHA_BACKEND_URL!,
  getCustomerId: (request) => {
    // Extract customer ID from your auth system
    return request.headers.get('x-customer-id');
  },
  getCustomerData: async (customerId) => {
    // Fetch customer data from your database
    return { name: 'John Doe', email: 'john@example.com' };
  }
});

Express.js

import express from 'express';
import { createArthaMiddleware } from 'artha-js/express';

const app = express();

app.use('/api/artha', createArthaMiddleware({
  backendUrl: process.env.ARTHA_BACKEND_URL!,
  getCustomerId: (req) => req.user?.id,
  getCustomerData: async (customerId) => {
    return await User.findById(customerId);
  }
}));

Framework Support

  • React - Full support with hooks and components
  • Next.js - API route handlers and client components
  • Express.js - Middleware support
  • Fastify - Plugin support
  • Hono - Middleware support
  • Elysia - Plugin support
  • Vanilla JS/TS - Core SDK

Features

  • 🚀 Complete Billing Infrastructure - Handle subscriptions, usage tracking, and payments
  • 🎨 Pre-built UI Components - Checkout dialogs, pricing tables, and paywall components
  • 🔒 Type-safe - Full TypeScript support with comprehensive type definitions
  • 🌐 Multi-framework - Works with React, Next.js, Express, and more
  • 📊 Analytics - Built-in usage tracking and analytics
  • 🎯 Feature Gating - Control access to features based on customer plans
  • 💳 Payment Processing - Integrated payment handling
  • 🔄 Real-time Updates - Live subscription and usage updates

Documentation

For comprehensive documentation, visit docs.artha.com

License

MIT

Support

For support, email support@artha.com or visit our documentation.