supabase-management-js
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

supabase-management-js

A convenience wrapper for the Supabase Management API written in TypeScript.

Status

The Management API is in beta. It is usable in it's current state, but it's likely that there will be breaking changes.

Installation

To install supabase-management-js in a Node.js project:

npm install supabase-management-js

supabase-management-js requires Node.js 18 and above because it relies on the native fetch client.

Authentication

You can configure the SupabaseManagementAPI class with an access token, retrieved either through OAuth or by generating an API token in your account page. Your API tokens carry the same privileges as your user account, so be sure to keep it secret.

import { SupabaseManagementAPI } from "supabase-management-js";

const client = new SupabaseManagementAPI({ accessToken: "<access token>" });

Usage

The SupabaseManagementAPI class exposes each API endpoint of the Management API as a function that returns a Promise with the corresponding response data type.

import { SupabaseManagementAPI } from "supabase-management-js";

const client = new SupabaseManagementAPI({ accessToken: "<access token>" });

const projects = await client.getProjects();

if (projects) {
  console.log(`Found ${projects.length} projects`);
}

Handling errors

Response errors are thrown as an instance of SupabaseManagementAPIError which is a subclass of Error. You can use the exported isSupabaseError guard function to narrow the type of an unknown error object:

import { SupabaseManagementAPI, isSupabaseError } from "supabase-management-js";

const client = new SupabaseManagementAPI({ accessToken: "<access token>" });

try {
  await client.getProjects();
} catch (error) {
  if (isSupabaseError(error)) {
    // error is now typed as SupabaseManagementAPI
    console.log(
      `Supabase Error:  ${error.message}, response status: ${error.response.status}`
    );
  }
}

Contributing

Contributions to this project are very welcome and greatly appreciated!

  1. Clone the repo into a public GitHub repo (or fork https://github.com/supabase-community/supabase-management-js/fork).

  2. Go to the project folder.

cd supabase-management-js
  1. Install packages with npm:
npm install
  1. Make your changes

  2. Make sure types are correct

npm run typecheck
  1. Create a changeset to describe your changes if you are making changes to the source code that effects its public API
npm exec changeset
  1. Create a branch, commit your changes, and open a Pull Request against the main branch in this repo.

Regenerating types

The v1.d.ts file is auto-generated based on the Supabase OpenAPI spec file with the following command:

npm run generate

Readme

Keywords

none

Package Sidebar

Install

npm i supabase-management-js

Weekly Downloads

1,627

Version

1.0.0

License

none

Unpacked Size

352 kB

Total Files

8

Last publish

Collaborators

  • ericallam