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 🙏

© 2024 – Pkg Stats / Ryan Hefner

supabase-ai-rls-tests-generator

v1.0.28

Published

Claude Sonnet will fetch your RLS policies from Supabase, then generate test cases (including edge cases), run the tests and save the tests and results specific files.

Downloads

549

Readme

Supabase AI RLS Tests Generator

An AI-powered tool that automatically generates and runs comprehensive test cases for your Supabase Row Level Security (RLS) policies. Using Claude AI, it analyzes your policies and creates test scenarios to verify their effectiveness.

Features

  • 🤖 AI-powered test case generation
  • 🔒 Comprehensive RLS policy testing
  • 📊 Detailed test reports
  • 🚀 Easy setup and configuration
  • 💾 Automatic test case storage
  • 📝 Human-readable results

Prerequisites

Before using this package, you need to:

  1. Have a Supabase project with RLS policies you want to test
  2. Install the required database function by running this SQL in your Supabase SQL editor:

```sql CREATE OR REPLACE FUNCTION public.get_policies(target_table text) RETURNS TABLE ( table_name text, policy_name text, definition text, command text, permissive text ) LANGUAGE SQL SECURITY DEFINER AS $$ SELECT schemaname || '.' || tablename as table_name, policyname as policy_name, regexp_replace(regexp_replace(coalesce(qual, ''), '\n', ' ', 'g'), '\s+', ' ', 'g') as definition, cmd as command, permissive FROM pg_policies WHERE (schemaname || '.' || tablename) = target_table OR tablename = target_table; $$; ```

Installation

npm install supabase-ai-rls-tests-generator

Quick Start

  1. Run the setup wizard:
npx setup-tests
  1. Enter your credentials when prompted:
  • Supabase URL
  • Supabase service role key
  • Claude API key
  1. Run the tests:
npx test-rls

Configuration

The package uses a separate `.env.rls-test` file to store its configuration, ensuring it doesn't interfere with your project's existing `.env` file. The setup wizard will create this file for you with the following variables:

SUPABASE_RLS_URL=your_supabase_url
SUPABASE_RLS_KEY=your_supabase_key
SUPABASE_RLS_CLAUDE_KEY=your_claude_key

This file is automatically added to `.gitignore` to prevent accidentally committing sensitive information.

Test Results

Test results are stored in the `generated` folder:

  • `generated/tests`: Contains the generated test cases
  • `generated/results`: Contains the test execution results

Each test run creates timestamped files so you can track changes over time.

Example Test Output

{
  "timestamp": "2024-02-25T14-30-45-789Z",
  "total": 10,
  "passed": 8,
  "failed": 2,
  "details": [
    {
      "test": {
        "description": "User can read their own posts",
        "method": "select",
        "path": "posts",
        "expectedStatus": 200
      },
      "success": true,
      "actual": 200,
      "expected": 200
    }
    // ... more test results
  ]
}

API Usage

You can also use the package programmatically:

import { SupabaseAITester } from 'supabase-ai-rls-tests-generator';

const tester = new SupabaseAITester({
  supabaseUrl: process.env.SUPABASE_RLS_URL,
  supabaseKey: process.env.SUPABASE_RLS_KEY,
  claudeKey: process.env.SUPABASE_RLS_CLAUDE_KEY,
  config: {
    verbose: true
  }
});

async function runTests() {
  try {
    const results = await tester.runRLSTests('your_table_name');
    console.log('Test Results:', results);
  } catch (error) {
    console.error('Test Error:', error);
  }
}

Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

If you encounter any issues or have questions:

  1. Check the Issues page
  2. Open a new issue if needed
  3. Join the discussion in existing issues

Authors

Acknowledgments

  • Thanks to Supabase for their amazing platform
  • Thanks to Anthropic for Claude AI
  • Thanks to all contributors who help improve this project