@codeduet-sh/supabase-management-js
v1.0.0
Published
Convenience wrapper for the Supabase Management API
Maintainers
Readme
@codeduet-sh/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 @codeduet-sh/supabase-management-js in a Node.js project:
npm install @codeduet-sh/supabase-management-js@codeduet-sh/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 "@codeduet-sh/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 "@codeduet-sh/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 "@codeduet-sh/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}`
);
}
}Regenerating types
The types are auto-generated based on the Supabase OpenAPI spec file with the following command:
npm run generate