@silas-sh/supabase-management-js 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,106 @@
1
+ ## supabase-management-js
2
+
3
+ A convenience wrapper for the [Supabase Management API](https://supabase.com/docs/reference/api/introduction) written in TypeScript.
4
+
5
+ ### Status
6
+
7
+ The Management API is in beta. It is usable in it's current state, but it's likely that there will be breaking changes.
8
+
9
+ ### Installation
10
+
11
+ To install `supabase-management-js` in a Node.js project:
12
+
13
+ ```sh
14
+ npm install supabase-management-js
15
+ ```
16
+
17
+ `supabase-management-js` requires Node.js 18 and above because it relies on the native `fetch` client.
18
+
19
+ ### Authentication
20
+
21
+ You can configure the `SupabaseManagementAPI` class with an access token, retrieved either through [OAuth](https://supabase.com/docs/guides/integrations/oauth-apps/authorize-an-oauth-app) or by generating an API token in your [account](https://supabase.com/dashboard/account/tokens) page. Your API tokens carry the same privileges as your user account, so be sure to keep it secret.
22
+
23
+ ```ts
24
+ import { SupabaseManagementAPI } from "supabase-management-js";
25
+
26
+ const client = new SupabaseManagementAPI({ accessToken: "<access token>" });
27
+ ```
28
+
29
+ ### Usage
30
+
31
+ The `SupabaseManagementAPI` class exposes each API endpoint of the [Management API](https://supabase.com/docs/reference/api/introduction) as a function that returns a Promise with the corresponding response data type.
32
+
33
+ ```ts
34
+ import { SupabaseManagementAPI } from "supabase-management-js";
35
+
36
+ const client = new SupabaseManagementAPI({ accessToken: "<access token>" });
37
+
38
+ const projects = await client.getProjects();
39
+
40
+ if (projects) {
41
+ console.log(`Found ${projects.length} projects`);
42
+ }
43
+ ```
44
+
45
+ ### Handling errors
46
+
47
+ 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:
48
+
49
+ ```ts
50
+ import { SupabaseManagementAPI, isSupabaseError } from "supabase-management-js";
51
+
52
+ const client = new SupabaseManagementAPI({ accessToken: "<access token>" });
53
+
54
+ try {
55
+ await client.getProjects();
56
+ } catch (error) {
57
+ if (isSupabaseError(error)) {
58
+ // error is now typed as SupabaseManagementAPI
59
+ console.log(
60
+ `Supabase Error: ${error.message}, response status: ${error.response.status}`
61
+ );
62
+ }
63
+ }
64
+ ```
65
+
66
+ ### Contributing
67
+
68
+ Contributions to this project are very welcome and greatly appreciated!
69
+
70
+ 1. Clone the repo into a public GitHub repo (or fork https://github.com/supabase-community/supabase-management-js/fork).
71
+
72
+ 2. Go to the project folder.
73
+
74
+ ```sh
75
+ cd supabase-management-js
76
+ ```
77
+
78
+ 3. Install packages with `npm`:
79
+
80
+ ```sh
81
+ npm install
82
+ ```
83
+
84
+ 4. Make your changes
85
+
86
+ 5. Make sure types are correct
87
+
88
+ ```sh
89
+ npm run typecheck
90
+ ```
91
+
92
+ 6. Create a changeset to describe your changes if you are making changes to the source code that effects its public API
93
+
94
+ ```sh
95
+ npm exec changeset
96
+ ```
97
+
98
+ 7. Create a branch, commit your changes, and open a Pull Request against the `main` branch in this repo.
99
+
100
+ ### Regenerating types
101
+
102
+ The [v1.d.ts](./src/api/v1.d.ts) file is auto-generated based on the Supabase [OpenAPI spec](https://api.supabase.com/api/v1-json) file with the following command:
103
+
104
+ ```sh
105
+ npm run generate
106
+ ```