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

editia-core

v2.1.1

Published

Core services and utilities for Editia applications - Authentication, Monetization, Video Generation Types, and Database Management

Readme

Editia Core

A TypeScript package for unified authentication, monetization, and database management for all Editia applications.

🚀 Installation

npm install editia-core

📦 Features

  • Clerk + Supabase Authentication: JWT verification and user management.
  • Express Middleware: Protect your routes with authentication and monetization middleware.
  • TypeScript: Full type safety and autocompletion.
  • No Logging: Delegates logging to the main application for greater flexibility.

🔧 Initialization

To use the package, you must first initialize it with your environment variables.

import { initializeEditiaCore } from 'editia-core';

// Initialize the package with your environment variables
initializeEditiaCore({
  clerkSecretKey: process.env.CLERK_SECRET_KEY!,
  supabaseUrl: process.env.SUPABASE_URL!,
  supabaseServiceRoleKey: process.env.SUPABASE_SERVICE_ROLE_KEY!, // Use the service role key for backend operations
  environment: process.env.NODE_ENV || 'development',
});

🔐 Authentication

Using the Service Directly

You can use the ClerkAuthService directly in your route handlers to verify users.

import { ClerkAuthService } from 'editia-core';

// In an Express endpoint
app.get('/api/user-voices', async (req, res) => {
  try {
    const authHeader = req.headers.authorization;
    const { user, clerkUser, errorResponse } =
      await ClerkAuthService.verifyUser(authHeader);

    if (errorResponse) {
      return res.status(errorResponse.status).json(errorResponse);
    }

    // user contains the user data from Supabase
    // clerkUser contains the user data from Clerk

    res.json({
      success: true,
      data: {
        userId: user.id,
        email: user.email,
        clerkId: clerkUser.id,
      },
    });
  } catch (error) {
    res.status(500).json({
      success: false,
      error: 'Internal server error',
    });
  }
});

Using the Middleware

The package provides a set of Express middleware functions to simplify route protection.

import { authenticateUser } from 'editia-core';

// Protect a route with the middleware
app.get('/api/protected', authenticateUser, (req, res) => {
  // req.user contains the authenticated user
  res.json({
    success: true,
    user: {
      id: req.user?.id,
      email: req.user?.email,
    },
  });
});

💰 Monetization

The package includes a powerful monetization system that allows you to protect routes based on user subscriptions and usage limits.

Using the Monetization Middleware

import {
  authenticateUser,
  videoGenerationMiddleware,
  createUsageIncrementMiddleware,
} from 'editia-core';

// Protect the video generation route
app.post(
  '/api/videos/generate',
  authenticateUser, // 1. Authenticate the user
  videoGenerationMiddleware, // 2. Check monetization
  createUsageIncrementMiddleware(), // 3. Increment usage on success
  async (req, res) => {
    // Your video generation logic here
    res.json({ success: true, videoUrl: '...' });
  }
);

For more details on the monetization system, see the Backend Monetization System documentation.

📋 API Reference

initializeEditiaCore(config: AuthConfig)

Initializes the package with your environment variables. This must be called before any other methods.

Parameters:

  • config (AuthConfig): An object containing your Clerk and Supabase credentials.

ClerkAuthService

verifyUser(authHeader?: string)

Verifies a Clerk JWT and returns the corresponding user information from both Clerk and Supabase.

Parameters:

  • authHeader (string, optional): The Authorization header (e.g., "Bearer ").

Returns:

{
  user: DatabaseUser | null; // The user from Supabase
  clerkUser: ClerkUser | null; // The user from Clerk
  errorResponse: AuthErrorResponse | null; // An error object if verification fails
}

getDatabaseUserId(authHeader?: string)

Retrieves only the user ID from the database.

Returns: string | null

Middleware

authenticateUser

An Express middleware that protects routes by requiring a valid Clerk JWT.

Usage:

app.get('/protected', authenticateUser, (req, res) => {
  // req.user contains the authenticated user
});

videoGenerationMiddleware

An Express middleware that protects video generation routes based on the user's subscription plan and usage limits.

createUsageIncrementMiddleware()

An Express middleware that increments a user's usage for a specific action after a successful operation.

Types

interface DatabaseUser {
  id: string;
  email: string;
  full_name?: string;
  clerk_user_id: string;
  created_at: string;
  updated_at: string;
}

interface AuthErrorResponse {
  success: false;
  error: string;
  status: number;
}

interface AuthenticatedRequest extends Request {
  user?: DatabaseUser;
}

🧪 Tests

The package includes a comprehensive test suite using Vitest.

npm test

📝 Logging

Important: This package does not handle logging. It is the responsibility of the consuming application to implement a logging solution.

🤝 Contributing

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature/amazing-feature).
  3. Commit your changes (git commit -m 'Add amazing feature').
  4. Push to the branch (git push origin feature/amazing-feature).
  5. Open a Pull Request.

📄 License

MIT License - see the LICENSE file for more details.