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

@pillexa/medusa-subscription-plugin

v0.1.11

Published

A subscription management plugin for Medusa e-commerce

Readme

@pillexa/medusa-subscription-plugin

A comprehensive subscription management plugin for Medusa e-commerce platform, built with TypeScript.

Features

  • 🚀 Subscription Management: Create, update, and cancel subscriptions
  • 🔄 Recurring Billing: Support for weekly, monthly, and yearly billing cycles
  • 📡 Event-Driven: Automatic subscription creation from orders
  • 🛡️ TypeScript: Full TypeScript support with type safety
  • 🧪 Testing: Comprehensive test coverage
  • 📚 RESTful API: Complete API endpoints for subscription management
  • 🔔 Event Handling: Subscribe to subscription lifecycle events

Installation

npm install @pillexa/medusa-subscription-plugin

Configuration

Add the plugin to your Medusa configuration:

// medusa-config.js
const plugins = [
  // ... other plugins
  {
    resolve: "@pillexa/medusa-subscription-plugin",
    options: {
      // Plugin options can be added here
    }
  }
];

module.exports = {
  projectConfig: {
    // ... your project config
  },
  plugins
};

Usage

Service Usage

import { SubscriptionService } from "@pillexa/medusa-subscription-plugin";

// Create a subscription
const subscription = await subscriptionService.create({
  customer_id: "cust_123",
  product_id: "prod_456",
  interval: "monthly",
  status: "active"
});

// Retrieve a subscription
const subscription = await subscriptionService.retrieve("sub_123");

// List subscriptions
const subscriptions = await subscriptionService.list({
  customer_id: "cust_123",
  status: "active"
});

// Update a subscription
const updatedSubscription = await subscriptionService.update("sub_123", {
  status: "paused",
  interval: "yearly"
});

// Cancel a subscription
const cancelledSubscription = await subscriptionService.cancel("sub_123");

// Process billing
const billingResult = await subscriptionService.processBilling("sub_123");

API Endpoints

The plugin provides the following REST API endpoints:

GET /subscriptions

List all subscriptions with optional filters.

Query Parameters:

  • customer_id (string): Filter by customer ID
  • status (string): Filter by status (active, cancelled, paused, expired)
  • interval (string): Filter by interval (weekly, monthly, yearly)

Example:

GET /subscriptions?customer_id=cust_123&status=active

GET /subscriptions/:id

Get a specific subscription by ID.

Example:

GET /subscriptions/sub_123

POST /subscriptions

Create a new subscription.

Request Body:

{
  "customer_id": "cust_123",
  "product_id": "prod_456",
  "interval": "monthly",
  "status": "active"
}

PUT /subscriptions/:id

Update a subscription.

Request Body:

{
  "status": "paused",
  "interval": "yearly"
}

DELETE /subscriptions/:id

Cancel a subscription.

POST /subscriptions/:id/billing

Process billing for a subscription.

GET /subscriptions/customer/:customer_id

Get all subscriptions for a specific customer.

GET /subscriptions/status/:status

Get all subscriptions with a specific status.

Event Handling

The plugin automatically handles the following events:

Order Events

  • order.placed: Creates subscriptions for subscription products
  • order.payment_captured: Handles payment processing
  • order.cancelled: Handles order cancellation

Subscription Events

  • subscription.created: Triggered when a subscription is created
  • subscription.updated: Triggered when a subscription is updated
  • subscription.cancelled: Triggered when a subscription is cancelled
  • subscription.billing_processed: Triggered when billing is processed

Types

interface Subscription {
  id: string;
  customer_id: string;
  product_id: string;
  interval: 'weekly' | 'monthly' | 'yearly';
  status: 'active' | 'cancelled' | 'paused' | 'expired';
  created_at: Date;
  updated_at: Date;
  next_billing_date: Date;
  order_id?: string;
}

interface CreateSubscriptionData {
  customer_id: string;
  product_id: string;
  interval: SubscriptionInterval;
  status?: SubscriptionStatus;
  order_id?: string;
}

interface UpdateSubscriptionData {
  customer_id?: string;
  product_id?: string;
  interval?: SubscriptionInterval;
  status?: SubscriptionStatus;
  next_billing_date?: Date;
}

Development

Prerequisites

  • Node.js 18+
  • npm or yarn
  • Medusa backend

Setup

  1. Clone the repository

  2. Install dependencies:

    cd packages/subscriptions
    npm install
  3. Build the plugin:

    npm run build
  4. Run tests:

    npm test
  5. Run linting:

    npm run lint

Scripts

  • npm run build: Build the TypeScript code
  • npm run watch: Watch for changes and rebuild
  • npm test: Run tests
  • npm run test:watch: Run tests in watch mode
  • npm run lint: Run ESLint
  • npm run lint:fix: Fix ESLint issues
  • npm run type-check: Run TypeScript type checking

Testing

The plugin includes comprehensive tests covering:

  • Service methods (create, retrieve, list, update, cancel, processBilling)
  • API endpoints
  • Event handling
  • Error cases
  • Type validation

Run tests with:

npm test

Run tests with coverage:

npm test -- --coverage

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

License

MIT

Support

For support, please open an issue on GitHub or contact the Pillexa team.

Changelog

v0.1.0

  • Initial release
  • Basic subscription management
  • TypeScript support
  • RESTful API endpoints
  • Event-driven architecture
  • Comprehensive testing