supabase-management-js
v1.0.0
Published
Convenience wrapper for the Supabase Management API
Downloads
6,331
Readme
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!
Clone the repo into a public GitHub repo (or fork https://github.com/supabase-community/supabase-management-js/fork).
Go to the project folder.
cd supabase-management-js
- Install packages with
npm
:
npm install
Make your changes
Make sure types are correct
npm run typecheck
- Create a changeset to describe your changes if you are making changes to the source code that effects its public API
npm exec changeset
- 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