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

lightswitch-sdk-edge

v1.0.6

Published

SDK for Supabase Edge Functions

Readme

Lightswitch SDK Edge

A minimal TypeScript SDK for integrating Lightswitch feature flags and entitlements into Supabase Edge Functions.

Installation

npm install lightswitch-sdk-edge

Quick Start

Configuration

import { LightswitchConfig } from 'lightswitch-sdk-edge';

const config: LightswitchConfig = {
  appSlug: 'your-app-slug',
  secretKey: 'your-secret-key',
  jwt: 'your-jwt-token'
};

Basic Usage

import { getCurrentUser, requireEntitlement, logUsage } from 'lightswitch-sdk-edge';

// Get current user
const user = await getCurrentUser(config);

// Check feature access
const hasAccess = await requireEntitlement(config, 'premium-feature');

if (hasAccess) {
  // Log usage when feature is accessed
  await logUsage(config, 'premium-feature', {
    timestamp: new Date().toISOString()
  });
  console.log('Access granted!');
} else {
  console.log('Access denied');
}

Edge Function Example

import { serve } from 'https://deno.land/[email protected]/http/server.ts';
import { requireEntitlement, logUsage } from 'lightswitch-sdk-edge';

serve(async (req) => {
  const body = await req.json();
  const config = {
    appSlug: body.appSlug,
    secretKey: body.secretKey,
    jwt: body.jwt
  };

  const entitled = await requireEntitlement(config, 'api-access');
  
  if (entitled) {
    await logUsage(config, 'api-access');
    return new Response(JSON.stringify({ message: 'Access granted' }));
  } else {
    return new Response(JSON.stringify({ error: 'Access denied' }), { status: 403 });
  }
});

API Reference

Core Functions

buildHeaders(config, extraHeaders?)

Builds authentication headers for API calls.

Parameters:

  • config: LightswitchConfig - Lightswitch configuration
  • extraHeaders?: Record<string, string> - Optional additional headers

Returns: Promise<Record<string, string>>

getCurrentUser(config)

Gets the current user's information.

Parameters:

  • config: LightswitchConfig - Lightswitch configuration

Returns: Promise<any> - User object

requireEntitlement(config, feature)

Checks if the user is entitled to a specific feature.

Parameters:

  • config: LightswitchConfig - Lightswitch configuration
  • feature: string - Feature identifier

Returns: Promise<boolean> - true if entitled, false if not

logUsage(config, feature, extraData?)

Logs usage of a feature.

Parameters:

  • config: LightswitchConfig - Lightswitch configuration
  • feature: string - Feature identifier
  • extraData?: Record<string, any> - Optional additional data

Returns: Promise<boolean> - true if logged successfully

Types

LightswitchConfig

interface LightswitchConfig {
  appSlug: string;    // Your app identifier
  secretKey: string;  // Your secret key
  jwt: string;        // User JWT token
}

License

MIT