├── .changeset ├── README.md └── config.json ├── .github └── workflows │ └── release.yml ├── .gitignore ├── CHANGELOG.md ├── README.md ├── package-lock.json ├── package.json ├── src ├── api │ ├── consts.ts │ ├── types.ts │ ├── utils.ts │ └── v1.d.ts └── index.ts ├── tsconfig.json └── tsup.config.ts /.changeset/README.md: -------------------------------------------------------------------------------- 1 | # Changesets 2 | 3 | Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works 4 | with multi-package repos, or single-package repos to help you version and publish your code. You can 5 | find the full documentation for it [in our repository](https://github.com/changesets/changesets) 6 | 7 | We have a quick list of common questions to get you started engaging with this project in 8 | [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) 9 | -------------------------------------------------------------------------------- /.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json", 3 | "changelog": "@changesets/cli/changelog", 4 | "commit": false, 5 | "fixed": [], 6 | "linked": [], 7 | "access": "restricted", 8 | "baseBranch": "main", 9 | "updateInternalDependencies": "patch", 10 | "ignore": [] 11 | } 12 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: 🦋 Changesets Release 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | jobs: 9 | release: 10 | name: 🦋 Changesets Release 11 | runs-on: ubuntu-latest 12 | if: | 13 | github.repository == 'supabase-community/supabase-management-js' 14 | outputs: 15 | published_packages: ${{ steps.changesets.outputs.publishedPackages }} 16 | published: ${{ steps.changesets.outputs.published }} 17 | steps: 18 | - name: 🛑 Cancel Previous Runs 19 | uses: styfle/cancel-workflow-action@0.11.0 20 | 21 | - name: ⬇️ Checkout repo 22 | uses: actions/checkout@v3 23 | with: 24 | fetch-depth: 0 25 | 26 | - name: ⎔ Setup node 27 | uses: actions/setup-node@v2 28 | with: 29 | node-version: 18 30 | cache: "npm" 31 | 32 | - name: 📥 Download deps 33 | run: npm install 34 | 35 | - name: 🔎 Type check 36 | run: npm run typecheck 37 | 38 | - name: 🔐 Setup npm auth 39 | run: | 40 | echo "registry=https://registry.npmjs.org" >> ~/.npmrc 41 | echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc 42 | 43 | # This action has two responsibilities. The first time the workflow runs 44 | # (initial push to the `main` branch) it will create a new branch and 45 | # then open a PR with the related changes for the new version. After the 46 | # PR is merged, the workflow will run again and this action will build + 47 | # publish to npm. 48 | - name: 🚀 PR / Publish 49 | id: changesets 50 | uses: changesets/action@v1 51 | with: 52 | version: npm run changeset:version 53 | commit: "chore: Update version for release" 54 | title: "chore: Update version for release" 55 | publish: npm run changeset:release 56 | createGithubReleases: true 57 | env: 58 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 59 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 60 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | node_modules 5 | .pnp 6 | .pnp.js 7 | 8 | # testing 9 | coverage 10 | 11 | # misc 12 | .DS_Store 13 | *.pem 14 | 15 | # debug 16 | npm-debug.log* 17 | yarn-debug.log* 18 | yarn-error.log* 19 | 20 | # local env files 21 | .env.docker 22 | .docker/*.env 23 | .env.local 24 | .env.development.local 25 | .env.test.local 26 | .env.production.local 27 | 28 | dist -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # supabase-management-js 2 | 3 | ## 1.0.0 4 | 5 | ### Major Changes 6 | 7 | - 5056f36: Add support for ESM and CommonJS through conditional exports 8 | 9 | ### Patch Changes 10 | 11 | - 4efa1bc: Update to latest Supabase management API 12 | 13 | - Added Snippet endpoints 14 | - Add ability to check service health status 15 | - Added ability to delete projects 16 | 17 | ## 0.1.6 18 | 19 | ### Patch Changes 20 | 21 | - d2db1ce: Update to the newest API spec, removing updatePgBouncerConfig endpoint 22 | 23 | ## 0.1.5 24 | 25 | ### Patch Changes 26 | 27 | - ea4937a: Update types to the newest OpenAPI spec 28 | 29 | ## 0.1.4 30 | 31 | ### Patch Changes 32 | 33 | - 1a29f25: Adding enableWebhooks endpoint 34 | 35 | ## 0.1.3 36 | 37 | ### Patch Changes 38 | 39 | - c79f01c: Adding auth config endpoints and update to the latest OpenAPI spec 40 | 41 | ## 0.1.2 42 | 43 | ### Patch Changes 44 | 45 | - 0753620: Fix for the update run query path 46 | - daa7771: Add branch endpoints 47 | 48 | ## 0.1.1 49 | 50 | ### Patch Changes 51 | 52 | - 4824568: Initial release of the Supabase Management API TS wrapper 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 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: "" }); 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: "" }); 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: "" }); 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 | ``` 107 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "supabase-management-js", 3 | "version": "1.0.0", 4 | "description": "Convenience wrapper for the Supabase Management API", 5 | "main": "./dist/index.js", 6 | "types": "./dist/index.d.ts", 7 | "module": "./dist/index.mjs", 8 | "publishConfig": { 9 | "access": "public" 10 | }, 11 | "files": [ 12 | "dist" 13 | ], 14 | "exports": { 15 | ".": { 16 | "import": { 17 | "types": "./dist/index.d.mts", 18 | "default": "./dist/index.mjs" 19 | }, 20 | "require": "./dist/index.js", 21 | "types": "./dist/index.d.ts" 22 | }, 23 | "./package.json": "./package.json" 24 | }, 25 | "scripts": { 26 | "clean": "rimraf dist", 27 | "build": "npm run clean && npm run build:tsup", 28 | "build:tsup": "tsup --dts-resolve", 29 | "typecheck": "tsc --noEmit", 30 | "generate": "openapi-typescript https://api.supabase.com/api/v1-json -o ./src/api/v1.d.ts", 31 | "changeset:version": "changeset version", 32 | "changeset:release": "npm run build && changeset publish" 33 | }, 34 | "dependencies": { 35 | "openapi-fetch": "^0.6.1" 36 | }, 37 | "devDependencies": { 38 | "@changesets/cli": "^2.26.2", 39 | "@types/node": "18", 40 | "esbuild": "^0.19.2", 41 | "openapi-typescript": "^6.3.4", 42 | "rimraf": "^3.0.2", 43 | "tsup": "^8.0.1", 44 | "tsx": "^4.6.2", 45 | "typescript": "^4.8.4" 46 | }, 47 | "engines": { 48 | "node": ">=18.0.0" 49 | } 50 | } -------------------------------------------------------------------------------- /src/api/consts.ts: -------------------------------------------------------------------------------- 1 | export const SUPABASE_API_URL = "https://api.supabase.com"; 2 | -------------------------------------------------------------------------------- /src/api/types.ts: -------------------------------------------------------------------------------- 1 | import { paths } from "./v1"; 2 | import { 3 | ExtractRequestBody, 4 | ExtractRequestQuery, 5 | ExtractResponseContent, 6 | } from "./utils"; 7 | 8 | export type GetOrganizationsResponseData = ExtractResponseContent< 9 | paths["/v1/organizations"], 10 | "get", 11 | 200 12 | >; 13 | 14 | export type CreateOrganizationRequestBody = ExtractRequestBody< 15 | paths["/v1/organizations"], 16 | "post" 17 | >; 18 | 19 | export type CreateOrganizationResponseData = ExtractResponseContent< 20 | paths["/v1/organizations"], 21 | "post", 22 | 201 23 | >; 24 | 25 | export type GetBranchDetailsResponseData = ExtractResponseContent< 26 | paths["/v1/branches/{branch_id}"], 27 | "get", 28 | 200 29 | >; 30 | 31 | export type UpdateBranchRequestBody = ExtractRequestBody< 32 | paths["/v1/branches/{branch_id}"], 33 | "patch" 34 | >; 35 | 36 | export type UpdateBranchResponseData = ExtractResponseContent< 37 | paths["/v1/branches/{branch_id}"], 38 | "patch", 39 | 200 40 | >; 41 | 42 | export type GetProjectsResponseData = ExtractResponseContent< 43 | paths["/v1/projects"], 44 | "get", 45 | 200 46 | >; 47 | 48 | export type CreateProjectResponseData = ExtractResponseContent< 49 | paths["/v1/projects"], 50 | "post", 51 | 201 52 | >; 53 | 54 | export type CreateProjectRequestBody = ExtractRequestBody< 55 | paths["/v1/projects"], 56 | "post" 57 | >; 58 | 59 | export type DeleteProjectResponseBody = ExtractResponseContent< 60 | paths["/v1/projects/{ref}"], 61 | "delete", 62 | 200 63 | >; 64 | 65 | export type ListFunctionsResponseData = ExtractResponseContent< 66 | paths["/v1/projects/{ref}/functions"], 67 | "get", 68 | 200 69 | >; 70 | 71 | export type CreateFunctionRequestBody = ExtractRequestBody< 72 | paths["/v1/projects/{ref}/functions"], 73 | "post" 74 | >; 75 | 76 | export type CreateFunctionResponseData = ExtractResponseContent< 77 | paths["/v1/projects/{ref}/functions"], 78 | "post", 79 | 201 80 | >; 81 | 82 | export type GetFunctionResponseData = ExtractResponseContent< 83 | paths["/v1/projects/{ref}/functions/{function_slug}"], 84 | "get", 85 | 200 86 | >; 87 | 88 | export type UpdateFunctionRequestBody = ExtractRequestBody< 89 | paths["/v1/projects/{ref}/functions/{function_slug}"], 90 | "patch" 91 | >; 92 | 93 | export type UpdateFunctionResponseData = ExtractResponseContent< 94 | paths["/v1/projects/{ref}/functions/{function_slug}"], 95 | "patch", 96 | 200 97 | >; 98 | 99 | export type GetFunctionBodyResponseData = ExtractResponseContent< 100 | paths["/v1/projects/{ref}/functions/{function_slug}/body"], 101 | "get", 102 | 200 103 | >; 104 | 105 | export type GetProjectApiKeysResponseData = ExtractResponseContent< 106 | paths["/v1/projects/{ref}/api-keys"], 107 | "get", 108 | 200 109 | >; 110 | 111 | export type GetCustomHostnameResponseData = ExtractResponseContent< 112 | paths["/v1/projects/{ref}/custom-hostname"], 113 | "get", 114 | 200 115 | >; 116 | 117 | export type CreateCustomHostnameRequestBody = ExtractRequestBody< 118 | paths["/v1/projects/{ref}/custom-hostname/initialize"], 119 | "post" 120 | >; 121 | 122 | export type CreateCustomHostnameResponseData = ExtractResponseContent< 123 | paths["/v1/projects/{ref}/custom-hostname/initialize"], 124 | "post", 125 | 201 126 | >; 127 | 128 | export type ReverifyCustomHostnameResponseData = ExtractResponseContent< 129 | paths["/v1/projects/{ref}/custom-hostname/reverify"], 130 | "post", 131 | 201 132 | >; 133 | 134 | export type ActivateCustomHostnameResponseData = ExtractResponseContent< 135 | paths["/v1/projects/{ref}/custom-hostname/activate"], 136 | "post", 137 | 201 138 | >; 139 | 140 | export type GetNetworkBansResponseData = ExtractResponseContent< 141 | paths["/v1/projects/{ref}/network-bans/retrieve"], 142 | "post", 143 | 201 144 | >; 145 | 146 | export type RemoveNetworkBanRequestBody = ExtractRequestBody< 147 | paths["/v1/projects/{ref}/network-bans"], 148 | "delete" 149 | >; 150 | 151 | export type GetNetworkRestrictionsResponseData = ExtractResponseContent< 152 | paths["/v1/projects/{ref}/network-restrictions"], 153 | "get", 154 | 200 155 | >; 156 | 157 | export type ApplyNetworkRestrictionsRequestBody = ExtractRequestBody< 158 | paths["/v1/projects/{ref}/network-restrictions/apply"], 159 | "post" 160 | >; 161 | 162 | export type ApplyNetworkRestrictionsResponseData = ExtractResponseContent< 163 | paths["/v1/projects/{ref}/network-restrictions/apply"], 164 | "post", 165 | 201 166 | >; 167 | 168 | export type GetPgsodiumConfigResponseData = ExtractResponseContent< 169 | paths["/v1/projects/{ref}/pgsodium"], 170 | "get", 171 | 200 172 | >; 173 | 174 | export type UpdatePgSodiumConfigRequestBody = ExtractRequestBody< 175 | paths["/v1/projects/{ref}/pgsodium"], 176 | "put" 177 | >; 178 | 179 | export type UpdatePgSodiumConfigResponseData = ExtractResponseContent< 180 | paths["/v1/projects/{ref}/pgsodium"], 181 | "put", 182 | 200 183 | >; 184 | 185 | export type GetPostgRESTConfigResponseData = ExtractResponseContent< 186 | paths["/v1/projects/{ref}/postgrest"], 187 | "get", 188 | 200 189 | >; 190 | 191 | export type UpdatePostgRESTConfigRequestBody = ExtractRequestBody< 192 | paths["/v1/projects/{ref}/postgrest"], 193 | "patch" 194 | >; 195 | 196 | export type UpdatePostgRESTConfigResponseData = ExtractResponseContent< 197 | paths["/v1/projects/{ref}/postgrest"], 198 | "patch", 199 | 200 200 | >; 201 | 202 | export type RunQueryResponseData = ExtractResponseContent< 203 | paths["/v1/projects/{ref}/database/query"], 204 | "post", 205 | 201 206 | >; 207 | 208 | export type GetSecretsResponseData = ExtractResponseContent< 209 | paths["/v1/projects/{ref}/secrets"], 210 | "get", 211 | 200 212 | >; 213 | 214 | export type CreateSecretsRequestBody = ExtractRequestBody< 215 | paths["/v1/projects/{ref}/secrets"], 216 | "post" 217 | >; 218 | 219 | export type DeleteSecretsRequestBody = ExtractRequestBody< 220 | paths["/v1/projects/{ref}/secrets"], 221 | "delete" 222 | >; 223 | 224 | export type DeleteSecretsResponseData = ExtractResponseContent< 225 | paths["/v1/projects/{ref}/secrets"], 226 | "delete", 227 | 200 228 | >; 229 | 230 | export type GetSSLEnforcementConfigResponseData = ExtractResponseContent< 231 | paths["/v1/projects/{ref}/ssl-enforcement"], 232 | "get", 233 | 200 234 | >; 235 | 236 | export type UpdateSSLEnforcementConfigRequestBody = ExtractRequestBody< 237 | paths["/v1/projects/{ref}/ssl-enforcement"], 238 | "put" 239 | >; 240 | 241 | export type UpdateSSLEnforcementConfigResponseData = ExtractResponseContent< 242 | paths["/v1/projects/{ref}/ssl-enforcement"], 243 | "put", 244 | 200 245 | >; 246 | 247 | export type GetTypescriptTypesResponseData = ExtractResponseContent< 248 | paths["/v1/projects/{ref}/types/typescript"], 249 | "get", 250 | 200 251 | >; 252 | 253 | export type GetVanitySubdomainResponseData = ExtractResponseContent< 254 | paths["/v1/projects/{ref}/vanity-subdomain"], 255 | "get", 256 | 200 257 | >; 258 | 259 | export type GetUpgradeEligibilityResponseData = ExtractResponseContent< 260 | paths["/v1/projects/{ref}/upgrade/eligibility"], 261 | "get", 262 | 200 263 | >; 264 | 265 | export type GetUpgradeStatusResponseData = ExtractResponseContent< 266 | paths["/v1/projects/{ref}/upgrade/status"], 267 | "get", 268 | 200 269 | >; 270 | 271 | export type GetReadonlyModeStatusResponseData = ExtractResponseContent< 272 | paths["/v1/projects/{ref}/readonly"], 273 | "get", 274 | 200 275 | >; 276 | 277 | export type GetProjectPGConfigResponseData = ExtractResponseContent< 278 | paths["/v1/projects/{ref}/config/database/postgres"], 279 | "get", 280 | 200 281 | >; 282 | 283 | export type UpdateProjectPGConfigRequestBody = ExtractRequestBody< 284 | paths["/v1/projects/{ref}/config/database/postgres"], 285 | "put" 286 | >; 287 | 288 | export type UpdateProjectPGConfigResponseData = ExtractResponseContent< 289 | paths["/v1/projects/{ref}/config/database/postgres"], 290 | "put", 291 | 200 292 | >; 293 | 294 | export type GetProjectPgBouncerConfigResponseData = ExtractResponseContent< 295 | paths["/v1/projects/{ref}/config/database/pgbouncer"], 296 | "get", 297 | 200 298 | >; 299 | 300 | export type GetSSOProvidersResponseData = ExtractResponseContent< 301 | paths["/v1/projects/{ref}/config/auth/sso/providers"], 302 | "get", 303 | 200 304 | >; 305 | 306 | export type GetProjectAuthConfigResponseData = ExtractResponseContent< 307 | paths["/v1/projects/{ref}/config/auth"], 308 | "get", 309 | 200 310 | >; 311 | 312 | export type UpdateProjectAuthConfigRequestBody = ExtractRequestBody< 313 | paths["/v1/projects/{ref}/config/auth"], 314 | "patch" 315 | >; 316 | 317 | export type UpdateProjectAuthConfigResponseData = ExtractResponseContent< 318 | paths["/v1/projects/{ref}/config/auth"], 319 | "patch", 320 | 200 321 | >; 322 | 323 | export type CreateSSOProviderRequestBody = ExtractRequestBody< 324 | paths["/v1/projects/{ref}/config/auth/sso/providers"], 325 | "post" 326 | >; 327 | 328 | export type CreateSSOProviderResponseData = ExtractResponseContent< 329 | paths["/v1/projects/{ref}/config/auth/sso/providers"], 330 | "post", 331 | 201 332 | >; 333 | 334 | export type GetSSOProviderResponseData = ExtractResponseContent< 335 | paths["/v1/projects/{ref}/config/auth/sso/providers/{provider_id}"], 336 | "get", 337 | 200 338 | >; 339 | 340 | export type UpdateSSOProviderRequestBody = ExtractRequestBody< 341 | paths["/v1/projects/{ref}/config/auth/sso/providers/{provider_id}"], 342 | "put" 343 | >; 344 | 345 | export type UpdateSSOProviderResponseData = ExtractResponseContent< 346 | paths["/v1/projects/{ref}/config/auth/sso/providers/{provider_id}"], 347 | "put", 348 | 200 349 | >; 350 | 351 | export type ListSnippetsResponseData = ExtractResponseContent< 352 | paths["/v1/snippets"], 353 | "get", 354 | 200 355 | >; 356 | 357 | export type GetSnippetResponseData = ExtractResponseContent< 358 | paths["/v1/snippets/{id}"], 359 | "get", 360 | 200 361 | >; 362 | 363 | export type CheckServiceQuery = ExtractRequestQuery< 364 | paths["/v1/projects/{ref}/health"], 365 | "get" 366 | >; 367 | 368 | export type CheckServiceHealthResponseData = ExtractResponseContent< 369 | paths["/v1/projects/{ref}/health"], 370 | "get", 371 | 200 372 | >; 373 | -------------------------------------------------------------------------------- /src/api/utils.ts: -------------------------------------------------------------------------------- 1 | type Prettify = { 2 | [K in keyof T]: T[K]; 3 | } & {}; 4 | 5 | export type ExtractResponseContent< 6 | TOperation, 7 | TMethod extends "get" | "post" | "put" | "patch" | "delete", 8 | TStatus extends number, 9 | TMime extends string = "application/json" 10 | > = TOperation extends { 11 | [method in TMethod]: { 12 | responses: { 13 | [status in TStatus]: { 14 | content: { 15 | [mime in TMime]: infer TData; 16 | }; 17 | }; 18 | }; 19 | }; 20 | } 21 | ? Prettify | undefined 22 | : never; 23 | 24 | export type ExtractRequestBody< 25 | TOperation, 26 | TMethod extends "put" | "post" | "patch" | "delete", 27 | TMime extends string = "application/json" 28 | > = TOperation extends { 29 | [method in TMethod]: { 30 | requestBody: { 31 | content: { 32 | [mime in TMime]: infer TData; 33 | }; 34 | }; 35 | }; 36 | } 37 | ? Prettify 38 | : never; 39 | 40 | export type ExtractRequestQuery< 41 | TOperation, 42 | TMethod extends "put" | "post" | "patch" | "delete" | "get" 43 | > = TOperation extends { 44 | [method in TMethod]: { 45 | parameters: { 46 | query: infer TQuery; 47 | }; 48 | }; 49 | } 50 | ? Prettify 51 | : never; 52 | -------------------------------------------------------------------------------- /src/api/v1.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file was auto-generated by openapi-typescript. 3 | * Do not make direct changes to the file. 4 | */ 5 | 6 | 7 | export interface paths { 8 | "/v1/branches/{branch_id}": { 9 | /** 10 | * Get database branch config 11 | * @description Fetches configurations of the specified database branch 12 | */ 13 | get: operations["getBranchDetails"]; 14 | /** 15 | * Delete a database branch 16 | * @description Deletes the specified database branch 17 | */ 18 | delete: operations["deleteBranch"]; 19 | /** 20 | * Update database branch config 21 | * @description Updates the configuration of the specified database branch 22 | */ 23 | patch: operations["updateBranch"]; 24 | }; 25 | "/v1/projects": { 26 | /** 27 | * List all projects 28 | * @description Returns a list of all projects you've previously created. 29 | */ 30 | get: operations["getProjects"]; 31 | /** Create a project */ 32 | post: operations["createProject"]; 33 | }; 34 | "/v1/organizations": { 35 | /** 36 | * List all organizations 37 | * @description Returns a list of organizations that you currently belong to. 38 | */ 39 | get: operations["getOrganizations"]; 40 | /** Create an organization */ 41 | post: operations["createOrganization"]; 42 | }; 43 | "/v1/oauth/authorize": { 44 | /** Authorize user through oauth */ 45 | get: operations["authorize"]; 46 | }; 47 | "/v1/oauth/token": { 48 | /** Exchange auth code for user's access and refresh token */ 49 | post: operations["token"]; 50 | }; 51 | "/v1/snippets": { 52 | /** Lists SQL snippets for the logged in user */ 53 | get: operations["listSnippets"]; 54 | }; 55 | "/v1/snippets/{id}": { 56 | /** Gets a specific SQL snippet */ 57 | get: operations["getSnippet"]; 58 | }; 59 | "/v1/projects/{ref}/api-keys": { 60 | get: operations["getProjectApiKeys"]; 61 | }; 62 | "/v1/projects/{ref}/branches": { 63 | /** 64 | * List all database branches 65 | * @description Returns all database branches of the specified project. 66 | */ 67 | get: operations["getBranches"]; 68 | /** 69 | * Create a database branch 70 | * @description Creates a database branch from the specified project. 71 | */ 72 | post: operations["createBranch"]; 73 | /** 74 | * Disables preview branching 75 | * @description Disables preview branching for the specified project 76 | */ 77 | delete: operations["disableBranch"]; 78 | }; 79 | "/v1/projects/{ref}/custom-hostname": { 80 | /** Gets project's custom hostname config */ 81 | get: operations["getCustomHostnameConfig"]; 82 | /** Deletes a project's custom hostname configuration */ 83 | delete: operations["removeCustomHostnameConfig"]; 84 | }; 85 | "/v1/projects/{ref}/custom-hostname/initialize": { 86 | /** Updates project's custom hostname configuration */ 87 | post: operations["createCustomHostnameConfig"]; 88 | }; 89 | "/v1/projects/{ref}/custom-hostname/reverify": { 90 | /** Attempts to verify the DNS configuration for project's custom hostname configuration */ 91 | post: operations["reverify"]; 92 | }; 93 | "/v1/projects/{ref}/custom-hostname/activate": { 94 | /** Activates a custom hostname for a project. */ 95 | post: operations["activate"]; 96 | }; 97 | "/v1/projects/{ref}/network-bans/retrieve": { 98 | /** Gets project's network bans */ 99 | post: operations["getNetworkBans"]; 100 | }; 101 | "/v1/projects/{ref}/network-bans": { 102 | /** Remove network bans. */ 103 | delete: operations["removeNetworkBan"]; 104 | }; 105 | "/v1/projects/{ref}/network-restrictions": { 106 | /** Gets project's network restrictions */ 107 | get: operations["getNetworkRestrictions"]; 108 | }; 109 | "/v1/projects/{ref}/network-restrictions/apply": { 110 | /** Updates project's network restrictions */ 111 | post: operations["applyNetworkRestrictions"]; 112 | }; 113 | "/v1/projects/{ref}/pgsodium": { 114 | /** Gets project's pgsodium config */ 115 | get: operations["getPgsodiumConfig"]; 116 | /** Updates project's pgsodium config. Updating the root_key can cause all data encrypted with the older key to become inaccessible. */ 117 | put: operations["updatePgsodiumConfig"]; 118 | }; 119 | "/v1/projects/{ref}/postgrest": { 120 | /** Gets project's postgrest config */ 121 | get: operations["getPostgRESTConfig"]; 122 | /** Updates project's postgrest config */ 123 | patch: operations["updatePostgRESTConfig"]; 124 | }; 125 | "/v1/projects/{ref}": { 126 | /** Deletes the given project */ 127 | delete: operations["deleteProject"]; 128 | }; 129 | "/v1/projects/{ref}/secrets": { 130 | /** 131 | * List all secrets 132 | * @description Returns all secrets you've previously added to the specified project. 133 | */ 134 | get: operations["getSecrets"]; 135 | /** 136 | * Bulk create secrets 137 | * @description Creates multiple secrets and adds them to the specified project. 138 | */ 139 | post: operations["createSecrets"]; 140 | /** 141 | * Bulk delete secrets 142 | * @description Deletes all secrets with the given names from the specified project 143 | */ 144 | delete: operations["deleteSecrets"]; 145 | }; 146 | "/v1/projects/{ref}/ssl-enforcement": { 147 | /** Get project's SSL enforcement configuration. */ 148 | get: operations["getSslEnforcementConfig"]; 149 | /** Update project's SSL enforcement configuration. */ 150 | put: operations["updateSslEnforcementConfig"]; 151 | }; 152 | "/v1/projects/{ref}/types/typescript": { 153 | /** 154 | * Generate TypeScript types 155 | * @description Returns the TypeScript types of your schema for use with supabase-js. 156 | */ 157 | get: operations["getTypescriptTypes"]; 158 | }; 159 | "/v1/projects/{ref}/vanity-subdomain": { 160 | /** Gets current vanity subdomain config */ 161 | get: operations["getVanitySubdomainConfig"]; 162 | /** Deletes a project's vanity subdomain configuration */ 163 | delete: operations["removeVanitySubdomainConfig"]; 164 | }; 165 | "/v1/projects/{ref}/vanity-subdomain/check-availability": { 166 | /** Checks vanity subdomain availability */ 167 | post: operations["checkVanitySubdomainAvailability"]; 168 | }; 169 | "/v1/projects/{ref}/vanity-subdomain/activate": { 170 | /** Activates a vanity subdomain for a project. */ 171 | post: operations["activateVanitySubdomainPlease"]; 172 | }; 173 | "/v1/projects/{ref}/upgrade": { 174 | /** Upgrades the project's Postgres version */ 175 | post: operations["upgradeProject"]; 176 | }; 177 | "/v1/projects/{ref}/upgrade/eligibility": { 178 | /** Returns the project's eligibility for upgrades */ 179 | get: operations["upgradeEligibilityInformation"]; 180 | }; 181 | "/v1/projects/{ref}/upgrade/status": { 182 | /** Gets the latest status of the project's upgrade */ 183 | get: operations["getUpgradeStatus"]; 184 | }; 185 | "/v1/projects/{ref}/readonly": { 186 | /** Returns project's readonly mode status */ 187 | get: operations["getReadOnlyModeStatus"]; 188 | }; 189 | "/v1/projects/{ref}/readonly/temporary-disable": { 190 | /** Disables project's readonly mode for the next 15 minutes */ 191 | post: operations["temporarilyDisableReadonlyMode"]; 192 | }; 193 | "/v1/projects/{ref}/health": { 194 | /** Gets project's service health status */ 195 | get: operations["checkServiceHealth"]; 196 | }; 197 | "/v1/projects/{ref}/config/database/postgres": { 198 | /** Gets project's Postgres config */ 199 | get: operations["getConfig"]; 200 | /** Updates project's Postgres config */ 201 | put: operations["updateConfig"]; 202 | }; 203 | "/v1/projects/{ref}/config/database/pgbouncer": { 204 | /** Get project's pgbouncer config */ 205 | get: operations["v1GetPgbouncerConfig"]; 206 | }; 207 | "/v1/projects/{ref}/config/auth": { 208 | /** Gets project's auth config */ 209 | get: operations["getV1AuthConfig"]; 210 | /** Updates a project's auth config */ 211 | patch: operations["updateV1AuthConfig"]; 212 | }; 213 | "/v1/projects/{ref}/database/query": { 214 | /** Run sql query */ 215 | post: operations["v1RunQuery"]; 216 | }; 217 | "/v1/projects/{ref}/database/webhooks/enable": { 218 | /** Enables Database Webhooks on the project */ 219 | post: operations["v1EnableDatabaseWebhooks"]; 220 | }; 221 | "/v1/projects/{ref}/functions": { 222 | /** 223 | * List all functions 224 | * @description Returns all functions you've previously added to the specified project. 225 | */ 226 | get: operations["getFunctions"]; 227 | /** 228 | * Create a function 229 | * @description Creates a function and adds it to the specified project. 230 | */ 231 | post: operations["createFunction"]; 232 | }; 233 | "/v1/projects/{ref}/functions/{function_slug}": { 234 | /** 235 | * Retrieve a function 236 | * @description Retrieves a function with the specified slug and project. 237 | */ 238 | get: operations["getFunction"]; 239 | /** 240 | * Delete a function 241 | * @description Deletes a function with the specified slug from the specified project. 242 | */ 243 | delete: operations["deleteFunction"]; 244 | /** 245 | * Update a function 246 | * @description Updates a function with the specified slug and project. 247 | */ 248 | patch: operations["updateFunction"]; 249 | }; 250 | "/v1/projects/{ref}/functions/{function_slug}/body": { 251 | /** 252 | * Retrieve a function body 253 | * @description Retrieves a function body for the specified slug and project. 254 | */ 255 | get: operations["getFunctionBody"]; 256 | }; 257 | "/v1/projects/{ref}/config/auth/sso/providers": { 258 | /** Lists all SSO providers */ 259 | get: operations["listAllProviders"]; 260 | /** Creates a new SSO provider */ 261 | post: operations["createProviderForProject"]; 262 | }; 263 | "/v1/projects/{ref}/config/auth/sso/providers/{provider_id}": { 264 | /** Gets a SSO provider by its UUID */ 265 | get: operations["getProviderById"]; 266 | /** Updates a SSO provider by its UUID */ 267 | put: operations["updateProviderById"]; 268 | /** Removes a SSO provider by its UUID */ 269 | delete: operations["removeProviderById"]; 270 | }; 271 | "/v1/projects/{ref}/database/backups/restore-pitr": { 272 | /** Restores a PITR backup for a database */ 273 | post: operations["v1RestorePitr"]; 274 | }; 275 | "/v1/organizations/{slug}/members": { 276 | /** List members of an organization */ 277 | get: operations["v1ListOrganizationMembers"]; 278 | }; 279 | } 280 | 281 | export type webhooks = Record; 282 | 283 | export interface components { 284 | schemas: { 285 | BranchDetailResponse: { 286 | db_port: number; 287 | ref: string; 288 | postgres_version: string; 289 | /** @enum {string} */ 290 | status: "ACTIVE_HEALTHY" | "ACTIVE_UNHEALTHY" | "COMING_UP" | "GOING_DOWN" | "INACTIVE" | "INIT_FAILED" | "REMOVED" | "RESTORING" | "UNKNOWN" | "UPGRADING" | "PAUSING"; 291 | db_host: string; 292 | db_user?: string; 293 | db_pass?: string; 294 | jwt_secret?: string; 295 | }; 296 | UpdateBranchBody: { 297 | branch_name?: string; 298 | git_branch?: string; 299 | reset_on_push?: boolean; 300 | }; 301 | BranchResponse: { 302 | id: string; 303 | name: string; 304 | project_ref: string; 305 | parent_project_ref: string; 306 | is_default: boolean; 307 | git_branch?: string; 308 | pr_number?: number; 309 | reset_on_push: boolean; 310 | created_at: string; 311 | updated_at: string; 312 | }; 313 | DatabaseResponse: { 314 | /** @description Database host */ 315 | host: string; 316 | /** @description Database version */ 317 | version: string; 318 | }; 319 | ProjectResponse: { 320 | /** @description Id of your project */ 321 | id: string; 322 | /** @description Slug of your organization */ 323 | organization_id: string; 324 | /** @description Name of your project */ 325 | name: string; 326 | /** 327 | * @description Region of your project 328 | * @example us-east-1 329 | */ 330 | region: string; 331 | /** 332 | * @description Creation timestamp 333 | * @example 2023-03-29T16:32:59Z 334 | */ 335 | created_at: string; 336 | database?: components["schemas"]["DatabaseResponse"]; 337 | }; 338 | CreateProjectBody: { 339 | /** @description Database password */ 340 | db_pass: string; 341 | /** @description Name of your project, should not contain dots */ 342 | name: string; 343 | /** @description Slug of your organization */ 344 | organization_id: string; 345 | /** 346 | * @deprecated 347 | * @description Subscription plan is now set on organization level and is ignored in this request 348 | * @example free 349 | * @enum {string} 350 | */ 351 | plan: "free" | "pro"; 352 | /** 353 | * @description Region you want your server to reside in 354 | * @example us-east-1 355 | * @enum {string} 356 | */ 357 | region: "us-east-1" | "us-west-1" | "us-west-2" | "ap-southeast-1" | "ap-northeast-1" | "ap-northeast-2" | "ap-southeast-2" | "eu-west-1" | "eu-west-2" | "eu-west-3" | "eu-central-1" | "ca-central-1" | "ap-south-1" | "sa-east-1"; 358 | /** @deprecated */ 359 | kps_enabled?: boolean; 360 | }; 361 | OrganizationResponseV1: { 362 | id: string; 363 | name: string; 364 | }; 365 | CreateOrganizationBodyV1: { 366 | name: string; 367 | }; 368 | OAuthTokenBody: { 369 | /** @enum {string} */ 370 | grant_type: "authorization_code" | "refresh_token"; 371 | client_id: string; 372 | client_secret: string; 373 | code?: string; 374 | code_verifier?: string; 375 | redirect_uri?: string; 376 | refresh_token?: string; 377 | }; 378 | OAuthTokenResponse: { 379 | /** @enum {string} */ 380 | token_type: "Bearer"; 381 | access_token: string; 382 | refresh_token: string; 383 | expires_in: number; 384 | }; 385 | SnippetProject: { 386 | id: number; 387 | name: string; 388 | }; 389 | SnippetUser: { 390 | id: number; 391 | username: string; 392 | }; 393 | SnippetMeta: { 394 | id: string; 395 | inserted_at: string; 396 | updated_at: string; 397 | /** @enum {string} */ 398 | type: "sql"; 399 | /** @enum {string} */ 400 | visibility: "user" | "project" | "org" | "public"; 401 | name: string; 402 | description: string | null; 403 | project: components["schemas"]["SnippetProject"]; 404 | owner: components["schemas"]["SnippetUser"]; 405 | updated_by: components["schemas"]["SnippetUser"]; 406 | }; 407 | SnippetList: { 408 | data: (components["schemas"]["SnippetMeta"])[]; 409 | }; 410 | SnippetContent: { 411 | favorite: boolean; 412 | schema_version: string; 413 | sql: string; 414 | }; 415 | SnippetResponse: { 416 | id: string; 417 | inserted_at: string; 418 | updated_at: string; 419 | /** @enum {string} */ 420 | type: "sql"; 421 | /** @enum {string} */ 422 | visibility: "user" | "project" | "org" | "public"; 423 | name: string; 424 | description: string | null; 425 | project: components["schemas"]["SnippetProject"]; 426 | owner: components["schemas"]["SnippetUser"]; 427 | updated_by: components["schemas"]["SnippetUser"]; 428 | content: components["schemas"]["SnippetContent"]; 429 | }; 430 | ApiKeyResponse: { 431 | name: string; 432 | api_key: string; 433 | }; 434 | CreateBranchBody: { 435 | branch_name: string; 436 | git_branch?: string; 437 | region?: string; 438 | }; 439 | UpdateCustomHostnameResponse: { 440 | /** @enum {string} */ 441 | status: "1_not_started" | "2_initiated" | "3_challenge_verified" | "4_origin_setup_completed" | "5_services_reconfigured"; 442 | custom_hostname: string; 443 | data: Record; 444 | }; 445 | UpdateCustomHostnameBody: { 446 | custom_hostname: string; 447 | }; 448 | NetworkBanResponse: { 449 | banned_ipv4_addresses: (string)[]; 450 | }; 451 | RemoveNetworkBanRequest: { 452 | ipv4_addresses: (string)[]; 453 | }; 454 | NetworkRestrictionsRequest: { 455 | dbAllowedCidrs: (string)[]; 456 | }; 457 | NetworkRestrictionsResponse: { 458 | /** @enum {string} */ 459 | entitlement: "disallowed" | "allowed"; 460 | config: components["schemas"]["NetworkRestrictionsRequest"]; 461 | old_config?: components["schemas"]["NetworkRestrictionsRequest"]; 462 | /** @enum {string} */ 463 | status: "stored" | "applied"; 464 | }; 465 | PgsodiumConfigResponse: { 466 | root_key: string; 467 | }; 468 | UpdatePgsodiumConfigBody: { 469 | root_key: string; 470 | }; 471 | PostgrestConfigWithJWTSecretResponse: { 472 | max_rows: number; 473 | db_schema: string; 474 | db_extra_search_path: string; 475 | jwt_secret?: string; 476 | }; 477 | UpdatePostgrestConfigBody: { 478 | max_rows?: number; 479 | db_extra_search_path?: string; 480 | db_schema?: string; 481 | }; 482 | PostgrestConfigResponse: { 483 | max_rows: number; 484 | db_schema: string; 485 | db_extra_search_path: string; 486 | }; 487 | ProjectRefResponse: { 488 | id: number; 489 | ref: string; 490 | name: string; 491 | }; 492 | SecretResponse: { 493 | name: string; 494 | value: string; 495 | }; 496 | CreateSecretBody: { 497 | /** 498 | * @description Secret name must not start with the SUPABASE_ prefix. 499 | * @example string 500 | */ 501 | name: string; 502 | value: string; 503 | }; 504 | SslEnforcements: { 505 | database: boolean; 506 | }; 507 | SslEnforcementResponse: { 508 | currentConfig: components["schemas"]["SslEnforcements"]; 509 | appliedSuccessfully: boolean; 510 | }; 511 | SslEnforcementRequest: { 512 | requestedConfig: components["schemas"]["SslEnforcements"]; 513 | }; 514 | TypescriptResponse: { 515 | types: string; 516 | }; 517 | VanitySubdomainConfigResponse: { 518 | /** @enum {string} */ 519 | status: "not-used" | "custom-domain-used" | "active"; 520 | custom_domain?: string; 521 | }; 522 | VanitySubdomainBody: { 523 | vanity_subdomain: string; 524 | }; 525 | SubdomainAvailabilityResponse: { 526 | available: boolean; 527 | }; 528 | ActivateVanitySubdomainResponse: { 529 | custom_domain: string; 530 | }; 531 | UpgradeDatabaseBody: { 532 | target_version: number; 533 | }; 534 | ProjectUpgradeInitiateResponse: { 535 | tracking_id: string; 536 | }; 537 | ProjectVersion: { 538 | postgres_version: number; 539 | app_version: string; 540 | }; 541 | ProjectUpgradeEligibilityResponse: { 542 | eligible: boolean; 543 | current_app_version: string; 544 | latest_app_version: string; 545 | target_upgrade_versions: (components["schemas"]["ProjectVersion"])[]; 546 | requires_manual_intervention: string | null; 547 | potential_breaking_changes: (string)[]; 548 | duration_estimate_hours: number; 549 | legacy_auth_custom_roles: (string)[]; 550 | extension_dependent_objects: (string)[]; 551 | }; 552 | DatabaseUpgradeStatus: { 553 | initiated_at: string; 554 | target_version: number; 555 | /** @enum {string} */ 556 | error?: "1_upgraded_instance_launch_failed" | "2_volume_detachchment_from_upgraded_instance_failed" | "3_volume_attachment_to_original_instance_failed" | "4_data_upgrade_initiation_failed" | "5_data_upgrade_completion_failed" | "6_volume_detachchment_from_original_instance_failed" | "7_volume_attachment_to_upgraded_instance_failed" | "8_upgrade_completion_failed"; 557 | /** @enum {string} */ 558 | progress?: "1_started" | "2_launched_upgraded_instance" | "3_detached_volume_from_upgraded_instance" | "4_attached_volume_to_original_instance" | "5_initiated_data_upgrade" | "6_completed_data_upgrade" | "7_detached_volume_from_original_instance" | "8_attached_volume_to_upgraded_instance" | "9_completed_upgrade"; 559 | /** @enum {number} */ 560 | status: 0 | 1 | 2; 561 | }; 562 | DatabaseUpgradeStatusResponse: { 563 | databaseUpgradeStatus: components["schemas"]["DatabaseUpgradeStatus"] | null; 564 | }; 565 | ReadOnlyStatusResponse: { 566 | enabled: boolean; 567 | override_enabled: boolean; 568 | override_active_until: string; 569 | }; 570 | AuthHealthResponse: { 571 | name: string; 572 | version: string; 573 | description: string; 574 | }; 575 | RealtimeHealthResponse: { 576 | healthy: boolean; 577 | db_connected: boolean; 578 | connected_cluster: number; 579 | }; 580 | ServiceHealthResponse: { 581 | info?: components["schemas"]["AuthHealthResponse"] | components["schemas"]["RealtimeHealthResponse"]; 582 | /** @enum {string} */ 583 | name: "auth" | "db" | "realtime" | "rest" | "storage"; 584 | healthy: boolean; 585 | error?: string; 586 | }; 587 | PostgresConfigResponse: { 588 | statement_timeout?: string; 589 | effective_cache_size?: string; 590 | maintenance_work_mem?: string; 591 | max_connections?: number; 592 | max_parallel_maintenance_workers?: number; 593 | max_parallel_workers?: number; 594 | max_parallel_workers_per_gather?: number; 595 | max_worker_processes?: number; 596 | shared_buffers?: string; 597 | work_mem?: string; 598 | /** @enum {string} */ 599 | session_replication_role?: "origin" | "replica" | "local"; 600 | }; 601 | UpdatePostgresConfigBody: { 602 | statement_timeout?: string; 603 | effective_cache_size?: string; 604 | maintenance_work_mem?: string; 605 | max_connections?: number; 606 | max_parallel_maintenance_workers?: number; 607 | max_parallel_workers?: number; 608 | max_parallel_workers_per_gather?: number; 609 | max_worker_processes?: number; 610 | shared_buffers?: string; 611 | work_mem?: string; 612 | /** @enum {string} */ 613 | session_replication_role?: "origin" | "replica" | "local"; 614 | }; 615 | V1PgbouncerConfigResponse: { 616 | /** @enum {string} */ 617 | pool_mode?: "transaction" | "session" | "statement"; 618 | default_pool_size?: number; 619 | ignore_startup_parameters?: string; 620 | max_client_conn?: number; 621 | }; 622 | AuthConfigResponse: { 623 | smtp_admin_email?: string; 624 | smtp_host?: string; 625 | smtp_port?: string; 626 | smtp_user?: string; 627 | smtp_pass?: string; 628 | smtp_max_frequency?: number; 629 | smtp_sender_name?: string; 630 | rate_limit_email_sent?: number; 631 | }; 632 | UpdateAuthConfigBody: { 633 | smtp_admin_email?: string; 634 | smtp_host?: string; 635 | smtp_port?: string; 636 | smtp_user?: string; 637 | smtp_pass?: string; 638 | smtp_max_frequency?: number; 639 | smtp_sender_name?: string; 640 | rate_limit_email_sent?: number; 641 | }; 642 | RunQueryBody: { 643 | query: string; 644 | }; 645 | CreateFunctionBody: { 646 | slug: string; 647 | name: string; 648 | body: string; 649 | verify_jwt?: boolean; 650 | }; 651 | FunctionResponse: { 652 | id: string; 653 | slug: string; 654 | name: string; 655 | /** @enum {string} */ 656 | status: "ACTIVE" | "REMOVED" | "THROTTLED"; 657 | version: number; 658 | created_at: number; 659 | updated_at: number; 660 | verify_jwt?: boolean; 661 | import_map?: boolean; 662 | entrypoint_path?: string; 663 | import_map_path?: string; 664 | }; 665 | FunctionSlugResponse: { 666 | id: string; 667 | slug: string; 668 | name: string; 669 | /** @enum {string} */ 670 | status: "ACTIVE" | "REMOVED" | "THROTTLED"; 671 | version: number; 672 | created_at: number; 673 | updated_at: number; 674 | verify_jwt?: boolean; 675 | import_map?: boolean; 676 | entrypoint_path?: string; 677 | import_map_path?: string; 678 | }; 679 | UpdateFunctionBody: { 680 | name?: string; 681 | body?: string; 682 | verify_jwt?: boolean; 683 | }; 684 | AttributeValue: { 685 | default?: Record | number | string | boolean; 686 | name?: string; 687 | names?: (string)[]; 688 | }; 689 | AttributeMapping: { 690 | keys: { 691 | [key: string]: components["schemas"]["AttributeValue"] | undefined; 692 | }; 693 | }; 694 | CreateProviderBody: { 695 | /** 696 | * @description What type of provider will be created 697 | * @enum {string} 698 | */ 699 | type: "saml"; 700 | metadata_xml?: string; 701 | metadata_url?: string; 702 | domains?: (string)[]; 703 | attribute_mapping?: components["schemas"]["AttributeMapping"]; 704 | }; 705 | SamlDescriptor: { 706 | id: string; 707 | entity_id: string; 708 | metadata_url?: string; 709 | metadata_xml?: string; 710 | attribute_mapping?: components["schemas"]["AttributeMapping"]; 711 | }; 712 | Domain: { 713 | id: string; 714 | domain?: string; 715 | created_at?: string; 716 | updated_at?: string; 717 | }; 718 | CreateProviderResponse: { 719 | id: string; 720 | saml?: components["schemas"]["SamlDescriptor"]; 721 | domains?: (components["schemas"]["Domain"])[]; 722 | created_at?: string; 723 | updated_at?: string; 724 | }; 725 | Provider: { 726 | id: string; 727 | saml?: components["schemas"]["SamlDescriptor"]; 728 | domains?: (components["schemas"]["Domain"])[]; 729 | created_at?: string; 730 | updated_at?: string; 731 | }; 732 | ListProvidersResponse: { 733 | items: (components["schemas"]["Provider"])[]; 734 | }; 735 | GetProviderResponse: { 736 | id: string; 737 | saml?: components["schemas"]["SamlDescriptor"]; 738 | domains?: (components["schemas"]["Domain"])[]; 739 | created_at?: string; 740 | updated_at?: string; 741 | }; 742 | UpdateProviderBody: { 743 | metadata_xml?: string; 744 | metadata_url?: string; 745 | domains?: (string)[]; 746 | attribute_mapping?: components["schemas"]["AttributeMapping"]; 747 | }; 748 | UpdateProviderResponse: { 749 | id: string; 750 | saml?: components["schemas"]["SamlDescriptor"]; 751 | domains?: (components["schemas"]["Domain"])[]; 752 | created_at?: string; 753 | updated_at?: string; 754 | }; 755 | DeleteProviderResponse: { 756 | id: string; 757 | saml?: components["schemas"]["SamlDescriptor"]; 758 | domains?: (components["schemas"]["Domain"])[]; 759 | created_at?: string; 760 | updated_at?: string; 761 | }; 762 | V1RestorePitrBody: { 763 | recovery_time_target_unix: number; 764 | }; 765 | V1OrganizationMemberResponse: { 766 | user_id: string; 767 | user_name: string; 768 | email?: string; 769 | role_name: string; 770 | mfa_enabled: boolean; 771 | }; 772 | }; 773 | responses: never; 774 | parameters: never; 775 | requestBodies: never; 776 | headers: never; 777 | pathItems: never; 778 | } 779 | 780 | export type external = Record; 781 | 782 | export interface operations { 783 | 784 | /** 785 | * Get database branch config 786 | * @description Fetches configurations of the specified database branch 787 | */ 788 | getBranchDetails: { 789 | parameters: { 790 | path: { 791 | /** @description Branch ID */ 792 | branch_id: string; 793 | }; 794 | }; 795 | responses: { 796 | 200: { 797 | content: { 798 | "application/json": components["schemas"]["BranchDetailResponse"]; 799 | }; 800 | }; 801 | /** @description Failed to retrieve database branch */ 802 | 500: never; 803 | }; 804 | }; 805 | /** 806 | * Delete a database branch 807 | * @description Deletes the specified database branch 808 | */ 809 | deleteBranch: { 810 | parameters: { 811 | path: { 812 | /** @description Branch ID */ 813 | branch_id: string; 814 | }; 815 | }; 816 | responses: { 817 | 200: never; 818 | /** @description Failed to delete database branch */ 819 | 500: never; 820 | }; 821 | }; 822 | /** 823 | * Update database branch config 824 | * @description Updates the configuration of the specified database branch 825 | */ 826 | updateBranch: { 827 | parameters: { 828 | path: { 829 | /** @description Branch ID */ 830 | branch_id: string; 831 | }; 832 | }; 833 | requestBody: { 834 | content: { 835 | "application/json": components["schemas"]["UpdateBranchBody"]; 836 | }; 837 | }; 838 | responses: { 839 | 200: { 840 | content: { 841 | "application/json": components["schemas"]["BranchResponse"]; 842 | }; 843 | }; 844 | /** @description Failed to update database branch */ 845 | 500: never; 846 | }; 847 | }; 848 | /** 849 | * List all projects 850 | * @description Returns a list of all projects you've previously created. 851 | */ 852 | getProjects: { 853 | responses: { 854 | 200: { 855 | content: { 856 | "application/json": (components["schemas"]["ProjectResponse"])[]; 857 | }; 858 | }; 859 | }; 860 | }; 861 | /** Create a project */ 862 | createProject: { 863 | requestBody: { 864 | content: { 865 | "application/json": components["schemas"]["CreateProjectBody"]; 866 | }; 867 | }; 868 | responses: { 869 | 200: { 870 | content: { 871 | "application/json": components["schemas"]["ProjectResponse"]; 872 | }; 873 | }; 874 | 201: { 875 | content: { 876 | "application/json": components["schemas"]["ProjectResponse"]; 877 | }; 878 | }; 879 | }; 880 | }; 881 | /** 882 | * List all organizations 883 | * @description Returns a list of organizations that you currently belong to. 884 | */ 885 | getOrganizations: { 886 | responses: { 887 | 200: { 888 | content: { 889 | "application/json": (components["schemas"]["OrganizationResponseV1"])[]; 890 | }; 891 | }; 892 | /** @description Unexpected error listing organizations */ 893 | 500: never; 894 | }; 895 | }; 896 | /** Create an organization */ 897 | createOrganization: { 898 | requestBody: { 899 | content: { 900 | "application/json": components["schemas"]["CreateOrganizationBodyV1"]; 901 | }; 902 | }; 903 | responses: { 904 | 201: { 905 | content: { 906 | "application/json": components["schemas"]["OrganizationResponseV1"]; 907 | }; 908 | }; 909 | /** @description Unexpected error creating an organization */ 910 | 500: never; 911 | }; 912 | }; 913 | /** Authorize user through oauth */ 914 | authorize: { 915 | parameters: { 916 | query: { 917 | client_id: string; 918 | response_type: "code" | "token" | "id_token token"; 919 | redirect_uri: string; 920 | scope?: string; 921 | state?: string; 922 | response_mode?: string; 923 | code_challenge?: string; 924 | code_challenge_method?: "plain" | "sha256" | "S256"; 925 | }; 926 | }; 927 | responses: { 928 | 303: never; 929 | }; 930 | }; 931 | /** Exchange auth code for user's access and refresh token */ 932 | token: { 933 | requestBody: { 934 | content: { 935 | "application/x-www-form-urlencoded": components["schemas"]["OAuthTokenBody"]; 936 | }; 937 | }; 938 | responses: { 939 | 201: { 940 | content: { 941 | "application/json": components["schemas"]["OAuthTokenResponse"]; 942 | }; 943 | }; 944 | }; 945 | }; 946 | /** Lists SQL snippets for the logged in user */ 947 | listSnippets: { 948 | parameters: { 949 | query?: { 950 | project_ref?: string; 951 | }; 952 | }; 953 | responses: { 954 | 200: { 955 | content: { 956 | "application/json": components["schemas"]["SnippetList"]; 957 | }; 958 | }; 959 | /** @description Failed to list user's SQL snippets */ 960 | 500: never; 961 | }; 962 | }; 963 | /** Gets a specific SQL snippet */ 964 | getSnippet: { 965 | parameters: { 966 | path: { 967 | id: string; 968 | }; 969 | }; 970 | responses: { 971 | 200: { 972 | content: { 973 | "application/json": components["schemas"]["SnippetResponse"]; 974 | }; 975 | }; 976 | /** @description Failed to retrieve SQL snippet */ 977 | 500: never; 978 | }; 979 | }; 980 | getProjectApiKeys: { 981 | parameters: { 982 | path: { 983 | /** @description Project ref */ 984 | ref: string; 985 | }; 986 | }; 987 | responses: { 988 | 200: { 989 | content: { 990 | "application/json": (components["schemas"]["ApiKeyResponse"])[]; 991 | }; 992 | }; 993 | 403: never; 994 | }; 995 | }; 996 | /** 997 | * List all database branches 998 | * @description Returns all database branches of the specified project. 999 | */ 1000 | getBranches: { 1001 | parameters: { 1002 | path: { 1003 | /** @description Project ref */ 1004 | ref: string; 1005 | }; 1006 | }; 1007 | responses: { 1008 | 200: { 1009 | content: { 1010 | "application/json": (components["schemas"]["BranchResponse"])[]; 1011 | }; 1012 | }; 1013 | /** @description Failed to retrieve database branches */ 1014 | 500: never; 1015 | }; 1016 | }; 1017 | /** 1018 | * Create a database branch 1019 | * @description Creates a database branch from the specified project. 1020 | */ 1021 | createBranch: { 1022 | parameters: { 1023 | path: { 1024 | /** @description Project ref */ 1025 | ref: string; 1026 | }; 1027 | }; 1028 | requestBody: { 1029 | content: { 1030 | "application/json": components["schemas"]["CreateBranchBody"]; 1031 | }; 1032 | }; 1033 | responses: { 1034 | 201: { 1035 | content: { 1036 | "application/json": components["schemas"]["BranchResponse"]; 1037 | }; 1038 | }; 1039 | /** @description Failed to create database branch */ 1040 | 500: never; 1041 | }; 1042 | }; 1043 | /** 1044 | * Disables preview branching 1045 | * @description Disables preview branching for the specified project 1046 | */ 1047 | disableBranch: { 1048 | parameters: { 1049 | path: { 1050 | /** @description Project ref */ 1051 | ref: string; 1052 | }; 1053 | }; 1054 | responses: { 1055 | 200: never; 1056 | /** @description Failed to disable preview branching */ 1057 | 500: never; 1058 | }; 1059 | }; 1060 | /** Gets project's custom hostname config */ 1061 | getCustomHostnameConfig: { 1062 | parameters: { 1063 | path: { 1064 | /** @description Project ref */ 1065 | ref: string; 1066 | }; 1067 | }; 1068 | responses: { 1069 | 200: { 1070 | content: { 1071 | "application/json": components["schemas"]["UpdateCustomHostnameResponse"]; 1072 | }; 1073 | }; 1074 | 403: never; 1075 | /** @description Failed to retrieve project's custom hostname config */ 1076 | 500: never; 1077 | }; 1078 | }; 1079 | /** Deletes a project's custom hostname configuration */ 1080 | removeCustomHostnameConfig: { 1081 | parameters: { 1082 | path: { 1083 | /** @description Project ref */ 1084 | ref: string; 1085 | }; 1086 | }; 1087 | responses: { 1088 | 200: never; 1089 | 403: never; 1090 | /** @description Failed to delete project custom hostname configuration */ 1091 | 500: never; 1092 | }; 1093 | }; 1094 | /** Updates project's custom hostname configuration */ 1095 | createCustomHostnameConfig: { 1096 | parameters: { 1097 | path: { 1098 | /** @description Project ref */ 1099 | ref: string; 1100 | }; 1101 | }; 1102 | requestBody: { 1103 | content: { 1104 | "application/json": components["schemas"]["UpdateCustomHostnameBody"]; 1105 | }; 1106 | }; 1107 | responses: { 1108 | 201: { 1109 | content: { 1110 | "application/json": components["schemas"]["UpdateCustomHostnameResponse"]; 1111 | }; 1112 | }; 1113 | 403: never; 1114 | /** @description Failed to update project custom hostname configuration */ 1115 | 500: never; 1116 | }; 1117 | }; 1118 | /** Attempts to verify the DNS configuration for project's custom hostname configuration */ 1119 | reverify: { 1120 | parameters: { 1121 | path: { 1122 | /** @description Project ref */ 1123 | ref: string; 1124 | }; 1125 | }; 1126 | responses: { 1127 | 201: { 1128 | content: { 1129 | "application/json": components["schemas"]["UpdateCustomHostnameResponse"]; 1130 | }; 1131 | }; 1132 | 403: never; 1133 | /** @description Failed to verify project custom hostname configuration */ 1134 | 500: never; 1135 | }; 1136 | }; 1137 | /** Activates a custom hostname for a project. */ 1138 | activate: { 1139 | parameters: { 1140 | path: { 1141 | /** @description Project ref */ 1142 | ref: string; 1143 | }; 1144 | }; 1145 | responses: { 1146 | 201: { 1147 | content: { 1148 | "application/json": components["schemas"]["UpdateCustomHostnameResponse"]; 1149 | }; 1150 | }; 1151 | 403: never; 1152 | /** @description Failed to activate project custom hostname configuration */ 1153 | 500: never; 1154 | }; 1155 | }; 1156 | /** Gets project's network bans */ 1157 | getNetworkBans: { 1158 | parameters: { 1159 | path: { 1160 | /** @description Project ref */ 1161 | ref: string; 1162 | }; 1163 | }; 1164 | responses: { 1165 | 201: { 1166 | content: { 1167 | "application/json": components["schemas"]["NetworkBanResponse"]; 1168 | }; 1169 | }; 1170 | 403: never; 1171 | /** @description Failed to retrieve project's network bans */ 1172 | 500: never; 1173 | }; 1174 | }; 1175 | /** Remove network bans. */ 1176 | removeNetworkBan: { 1177 | parameters: { 1178 | path: { 1179 | /** @description Project ref */ 1180 | ref: string; 1181 | }; 1182 | }; 1183 | requestBody: { 1184 | content: { 1185 | "application/json": components["schemas"]["RemoveNetworkBanRequest"]; 1186 | }; 1187 | }; 1188 | responses: { 1189 | 200: never; 1190 | 403: never; 1191 | /** @description Failed to remove network bans. */ 1192 | 500: never; 1193 | }; 1194 | }; 1195 | /** Gets project's network restrictions */ 1196 | getNetworkRestrictions: { 1197 | parameters: { 1198 | path: { 1199 | /** @description Project ref */ 1200 | ref: string; 1201 | }; 1202 | }; 1203 | responses: { 1204 | 200: { 1205 | content: { 1206 | "application/json": components["schemas"]["NetworkRestrictionsResponse"]; 1207 | }; 1208 | }; 1209 | 403: never; 1210 | /** @description Failed to retrieve project's network restrictions */ 1211 | 500: never; 1212 | }; 1213 | }; 1214 | /** Updates project's network restrictions */ 1215 | applyNetworkRestrictions: { 1216 | parameters: { 1217 | path: { 1218 | /** @description Project ref */ 1219 | ref: string; 1220 | }; 1221 | }; 1222 | requestBody: { 1223 | content: { 1224 | "application/json": components["schemas"]["NetworkRestrictionsRequest"]; 1225 | }; 1226 | }; 1227 | responses: { 1228 | 201: { 1229 | content: { 1230 | "application/json": components["schemas"]["NetworkRestrictionsResponse"]; 1231 | }; 1232 | }; 1233 | 403: never; 1234 | /** @description Failed to update project network restrictions */ 1235 | 500: never; 1236 | }; 1237 | }; 1238 | /** Gets project's pgsodium config */ 1239 | getPgsodiumConfig: { 1240 | parameters: { 1241 | path: { 1242 | /** @description Project ref */ 1243 | ref: string; 1244 | }; 1245 | }; 1246 | responses: { 1247 | 200: { 1248 | content: { 1249 | "application/json": components["schemas"]["PgsodiumConfigResponse"]; 1250 | }; 1251 | }; 1252 | 403: never; 1253 | /** @description Failed to retrieve project's pgsodium config */ 1254 | 500: never; 1255 | }; 1256 | }; 1257 | /** Updates project's pgsodium config. Updating the root_key can cause all data encrypted with the older key to become inaccessible. */ 1258 | updatePgsodiumConfig: { 1259 | parameters: { 1260 | path: { 1261 | /** @description Project ref */ 1262 | ref: string; 1263 | }; 1264 | }; 1265 | requestBody: { 1266 | content: { 1267 | "application/json": components["schemas"]["UpdatePgsodiumConfigBody"]; 1268 | }; 1269 | }; 1270 | responses: { 1271 | 200: { 1272 | content: { 1273 | "application/json": components["schemas"]["PgsodiumConfigResponse"]; 1274 | }; 1275 | }; 1276 | 403: never; 1277 | /** @description Failed to update project's pgsodium config */ 1278 | 500: never; 1279 | }; 1280 | }; 1281 | /** Gets project's postgrest config */ 1282 | getPostgRESTConfig: { 1283 | parameters: { 1284 | path: { 1285 | /** @description Project ref */ 1286 | ref: string; 1287 | }; 1288 | }; 1289 | responses: { 1290 | 200: { 1291 | content: { 1292 | "application/json": components["schemas"]["PostgrestConfigWithJWTSecretResponse"]; 1293 | }; 1294 | }; 1295 | 403: never; 1296 | /** @description Failed to retrieve project's postgrest config */ 1297 | 500: never; 1298 | }; 1299 | }; 1300 | /** Updates project's postgrest config */ 1301 | updatePostgRESTConfig: { 1302 | parameters: { 1303 | path: { 1304 | /** @description Project ref */ 1305 | ref: string; 1306 | }; 1307 | }; 1308 | requestBody: { 1309 | content: { 1310 | "application/json": components["schemas"]["UpdatePostgrestConfigBody"]; 1311 | }; 1312 | }; 1313 | responses: { 1314 | 200: { 1315 | content: { 1316 | "application/json": components["schemas"]["PostgrestConfigResponse"]; 1317 | }; 1318 | }; 1319 | 403: never; 1320 | /** @description Failed to update project's postgrest config */ 1321 | 500: never; 1322 | }; 1323 | }; 1324 | /** Deletes the given project */ 1325 | deleteProject: { 1326 | parameters: { 1327 | path: { 1328 | /** @description Project ref */ 1329 | ref: string; 1330 | }; 1331 | }; 1332 | responses: { 1333 | 200: { 1334 | content: { 1335 | "application/json": components["schemas"]["ProjectRefResponse"]; 1336 | }; 1337 | }; 1338 | 403: never; 1339 | }; 1340 | }; 1341 | /** 1342 | * List all secrets 1343 | * @description Returns all secrets you've previously added to the specified project. 1344 | */ 1345 | getSecrets: { 1346 | parameters: { 1347 | path: { 1348 | /** @description Project ref */ 1349 | ref: string; 1350 | }; 1351 | }; 1352 | responses: { 1353 | 200: { 1354 | content: { 1355 | "application/json": (components["schemas"]["SecretResponse"])[]; 1356 | }; 1357 | }; 1358 | 403: never; 1359 | /** @description Failed to retrieve project's secrets */ 1360 | 500: never; 1361 | }; 1362 | }; 1363 | /** 1364 | * Bulk create secrets 1365 | * @description Creates multiple secrets and adds them to the specified project. 1366 | */ 1367 | createSecrets: { 1368 | parameters: { 1369 | path: { 1370 | /** @description Project ref */ 1371 | ref: string; 1372 | }; 1373 | }; 1374 | requestBody: { 1375 | content: { 1376 | "application/json": (components["schemas"]["CreateSecretBody"])[]; 1377 | }; 1378 | }; 1379 | responses: { 1380 | 201: never; 1381 | 403: never; 1382 | /** @description Failed to create project's secrets */ 1383 | 500: never; 1384 | }; 1385 | }; 1386 | /** 1387 | * Bulk delete secrets 1388 | * @description Deletes all secrets with the given names from the specified project 1389 | */ 1390 | deleteSecrets: { 1391 | parameters: { 1392 | path: { 1393 | /** @description Project ref */ 1394 | ref: string; 1395 | }; 1396 | }; 1397 | requestBody: { 1398 | content: { 1399 | "application/json": (string)[]; 1400 | }; 1401 | }; 1402 | responses: { 1403 | 200: { 1404 | content: { 1405 | "application/json": Record; 1406 | }; 1407 | }; 1408 | 403: never; 1409 | /** @description Failed to delete secrets with given names */ 1410 | 500: never; 1411 | }; 1412 | }; 1413 | /** Get project's SSL enforcement configuration. */ 1414 | getSslEnforcementConfig: { 1415 | parameters: { 1416 | path: { 1417 | /** @description Project ref */ 1418 | ref: string; 1419 | }; 1420 | }; 1421 | responses: { 1422 | 200: { 1423 | content: { 1424 | "application/json": components["schemas"]["SslEnforcementResponse"]; 1425 | }; 1426 | }; 1427 | 403: never; 1428 | /** @description Failed to retrieve project's SSL enforcement config */ 1429 | 500: never; 1430 | }; 1431 | }; 1432 | /** Update project's SSL enforcement configuration. */ 1433 | updateSslEnforcementConfig: { 1434 | parameters: { 1435 | path: { 1436 | /** @description Project ref */ 1437 | ref: string; 1438 | }; 1439 | }; 1440 | requestBody: { 1441 | content: { 1442 | "application/json": components["schemas"]["SslEnforcementRequest"]; 1443 | }; 1444 | }; 1445 | responses: { 1446 | 200: { 1447 | content: { 1448 | "application/json": components["schemas"]["SslEnforcementResponse"]; 1449 | }; 1450 | }; 1451 | 403: never; 1452 | /** @description Failed to update project's SSL enforcement configuration. */ 1453 | 500: never; 1454 | }; 1455 | }; 1456 | /** 1457 | * Generate TypeScript types 1458 | * @description Returns the TypeScript types of your schema for use with supabase-js. 1459 | */ 1460 | getTypescriptTypes: { 1461 | parameters: { 1462 | query?: { 1463 | included_schemas?: string; 1464 | }; 1465 | path: { 1466 | /** @description Project ref */ 1467 | ref: string; 1468 | }; 1469 | }; 1470 | responses: { 1471 | 200: { 1472 | content: { 1473 | "application/json": components["schemas"]["TypescriptResponse"]; 1474 | }; 1475 | }; 1476 | 403: never; 1477 | /** @description Failed to generate TypeScript types */ 1478 | 500: never; 1479 | }; 1480 | }; 1481 | /** Gets current vanity subdomain config */ 1482 | getVanitySubdomainConfig: { 1483 | parameters: { 1484 | path: { 1485 | /** @description Project ref */ 1486 | ref: string; 1487 | }; 1488 | }; 1489 | responses: { 1490 | 200: { 1491 | content: { 1492 | "application/json": components["schemas"]["VanitySubdomainConfigResponse"]; 1493 | }; 1494 | }; 1495 | 403: never; 1496 | /** @description Failed to get project vanity subdomain configuration */ 1497 | 500: never; 1498 | }; 1499 | }; 1500 | /** Deletes a project's vanity subdomain configuration */ 1501 | removeVanitySubdomainConfig: { 1502 | parameters: { 1503 | path: { 1504 | /** @description Project ref */ 1505 | ref: string; 1506 | }; 1507 | }; 1508 | responses: { 1509 | 200: never; 1510 | 403: never; 1511 | /** @description Failed to delete project vanity subdomain configuration */ 1512 | 500: never; 1513 | }; 1514 | }; 1515 | /** Checks vanity subdomain availability */ 1516 | checkVanitySubdomainAvailability: { 1517 | parameters: { 1518 | path: { 1519 | /** @description Project ref */ 1520 | ref: string; 1521 | }; 1522 | }; 1523 | requestBody: { 1524 | content: { 1525 | "application/json": components["schemas"]["VanitySubdomainBody"]; 1526 | }; 1527 | }; 1528 | responses: { 1529 | 201: { 1530 | content: { 1531 | "application/json": components["schemas"]["SubdomainAvailabilityResponse"]; 1532 | }; 1533 | }; 1534 | 403: never; 1535 | /** @description Failed to check project vanity subdomain configuration */ 1536 | 500: never; 1537 | }; 1538 | }; 1539 | /** Activates a vanity subdomain for a project. */ 1540 | activateVanitySubdomainPlease: { 1541 | parameters: { 1542 | path: { 1543 | /** @description Project ref */ 1544 | ref: string; 1545 | }; 1546 | }; 1547 | requestBody: { 1548 | content: { 1549 | "application/json": components["schemas"]["VanitySubdomainBody"]; 1550 | }; 1551 | }; 1552 | responses: { 1553 | 201: { 1554 | content: { 1555 | "application/json": components["schemas"]["ActivateVanitySubdomainResponse"]; 1556 | }; 1557 | }; 1558 | 403: never; 1559 | /** @description Failed to activate project vanity subdomain configuration */ 1560 | 500: never; 1561 | }; 1562 | }; 1563 | /** Upgrades the project's Postgres version */ 1564 | upgradeProject: { 1565 | parameters: { 1566 | path: { 1567 | /** @description Project ref */ 1568 | ref: string; 1569 | }; 1570 | }; 1571 | requestBody: { 1572 | content: { 1573 | "application/json": components["schemas"]["UpgradeDatabaseBody"]; 1574 | }; 1575 | }; 1576 | responses: { 1577 | 201: { 1578 | content: { 1579 | "application/json": components["schemas"]["ProjectUpgradeInitiateResponse"]; 1580 | }; 1581 | }; 1582 | 403: never; 1583 | /** @description Failed to initiate project upgrade */ 1584 | 500: never; 1585 | }; 1586 | }; 1587 | /** Returns the project's eligibility for upgrades */ 1588 | upgradeEligibilityInformation: { 1589 | parameters: { 1590 | path: { 1591 | /** @description Project ref */ 1592 | ref: string; 1593 | }; 1594 | }; 1595 | responses: { 1596 | 200: { 1597 | content: { 1598 | "application/json": components["schemas"]["ProjectUpgradeEligibilityResponse"]; 1599 | }; 1600 | }; 1601 | 403: never; 1602 | /** @description Failed to determine project upgrade eligibility */ 1603 | 500: never; 1604 | }; 1605 | }; 1606 | /** Gets the latest status of the project's upgrade */ 1607 | getUpgradeStatus: { 1608 | parameters: { 1609 | path: { 1610 | /** @description Project ref */ 1611 | ref: string; 1612 | }; 1613 | }; 1614 | responses: { 1615 | 200: { 1616 | content: { 1617 | "application/json": components["schemas"]["DatabaseUpgradeStatusResponse"]; 1618 | }; 1619 | }; 1620 | 403: never; 1621 | /** @description Failed to retrieve project upgrade status */ 1622 | 500: never; 1623 | }; 1624 | }; 1625 | /** Returns project's readonly mode status */ 1626 | getReadOnlyModeStatus: { 1627 | parameters: { 1628 | path: { 1629 | /** @description Project ref */ 1630 | ref: string; 1631 | }; 1632 | }; 1633 | responses: { 1634 | 200: { 1635 | content: { 1636 | "application/json": components["schemas"]["ReadOnlyStatusResponse"]; 1637 | }; 1638 | }; 1639 | /** @description Failed to get project readonly mode status */ 1640 | 500: never; 1641 | }; 1642 | }; 1643 | /** Disables project's readonly mode for the next 15 minutes */ 1644 | temporarilyDisableReadonlyMode: { 1645 | parameters: { 1646 | path: { 1647 | /** @description Project ref */ 1648 | ref: string; 1649 | }; 1650 | }; 1651 | responses: { 1652 | 201: never; 1653 | /** @description Failed to disable project's readonly mode */ 1654 | 500: never; 1655 | }; 1656 | }; 1657 | /** Gets project's service health status */ 1658 | checkServiceHealth: { 1659 | parameters: { 1660 | query: { 1661 | timeout_ms?: number; 1662 | services: ("auth" | "db" | "realtime" | "rest" | "storage")[]; 1663 | }; 1664 | path: { 1665 | /** @description Project ref */ 1666 | ref: string; 1667 | }; 1668 | }; 1669 | responses: { 1670 | 200: { 1671 | content: { 1672 | "application/json": (components["schemas"]["ServiceHealthResponse"])[]; 1673 | }; 1674 | }; 1675 | /** @description Failed to retrieve project's service health status */ 1676 | 500: never; 1677 | }; 1678 | }; 1679 | /** Gets project's Postgres config */ 1680 | getConfig: { 1681 | parameters: { 1682 | path: { 1683 | /** @description Project ref */ 1684 | ref: string; 1685 | }; 1686 | }; 1687 | responses: { 1688 | 200: { 1689 | content: { 1690 | "application/json": components["schemas"]["PostgresConfigResponse"]; 1691 | }; 1692 | }; 1693 | /** @description Failed to retrieve project's Postgres config */ 1694 | 500: never; 1695 | }; 1696 | }; 1697 | /** Updates project's Postgres config */ 1698 | updateConfig: { 1699 | parameters: { 1700 | path: { 1701 | /** @description Project ref */ 1702 | ref: string; 1703 | }; 1704 | }; 1705 | requestBody: { 1706 | content: { 1707 | "application/json": components["schemas"]["UpdatePostgresConfigBody"]; 1708 | }; 1709 | }; 1710 | responses: { 1711 | 200: { 1712 | content: { 1713 | "application/json": components["schemas"]["PostgresConfigResponse"]; 1714 | }; 1715 | }; 1716 | /** @description Failed to update project's Postgres config */ 1717 | 500: never; 1718 | }; 1719 | }; 1720 | /** Get project's pgbouncer config */ 1721 | v1GetPgbouncerConfig: { 1722 | parameters: { 1723 | path: { 1724 | /** @description Project ref */ 1725 | ref: string; 1726 | }; 1727 | }; 1728 | responses: { 1729 | 200: { 1730 | content: { 1731 | "application/json": components["schemas"]["V1PgbouncerConfigResponse"]; 1732 | }; 1733 | }; 1734 | /** @description Failed to retrieve project's pgbouncer config */ 1735 | 500: never; 1736 | }; 1737 | }; 1738 | /** Gets project's auth config */ 1739 | getV1AuthConfig: { 1740 | parameters: { 1741 | path: { 1742 | /** @description Project ref */ 1743 | ref: string; 1744 | }; 1745 | }; 1746 | responses: { 1747 | 200: { 1748 | content: { 1749 | "application/json": components["schemas"]["AuthConfigResponse"]; 1750 | }; 1751 | }; 1752 | 403: never; 1753 | /** @description Failed to retrieve project's auth config */ 1754 | 500: never; 1755 | }; 1756 | }; 1757 | /** Updates a project's auth config */ 1758 | updateV1AuthConfig: { 1759 | parameters: { 1760 | path: { 1761 | /** @description Project ref */ 1762 | ref: string; 1763 | }; 1764 | }; 1765 | requestBody: { 1766 | content: { 1767 | "application/json": components["schemas"]["UpdateAuthConfigBody"]; 1768 | }; 1769 | }; 1770 | responses: { 1771 | 200: { 1772 | content: { 1773 | "application/json": components["schemas"]["AuthConfigResponse"]; 1774 | }; 1775 | }; 1776 | 403: never; 1777 | /** @description Failed to update project's auth config */ 1778 | 500: never; 1779 | }; 1780 | }; 1781 | /** Run sql query */ 1782 | v1RunQuery: { 1783 | parameters: { 1784 | path: { 1785 | /** @description Project ref */ 1786 | ref: string; 1787 | }; 1788 | }; 1789 | requestBody: { 1790 | content: { 1791 | "application/json": components["schemas"]["RunQueryBody"]; 1792 | }; 1793 | }; 1794 | responses: { 1795 | 201: { 1796 | content: { 1797 | "application/json": Record; 1798 | }; 1799 | }; 1800 | 403: never; 1801 | /** @description Failed to run sql query */ 1802 | 500: never; 1803 | }; 1804 | }; 1805 | /** Enables Database Webhooks on the project */ 1806 | v1EnableDatabaseWebhooks: { 1807 | parameters: { 1808 | path: { 1809 | /** @description Project ref */ 1810 | ref: string; 1811 | }; 1812 | }; 1813 | responses: { 1814 | 201: never; 1815 | 403: never; 1816 | /** @description Failed to enable Database Webhooks on the project */ 1817 | 500: never; 1818 | }; 1819 | }; 1820 | /** 1821 | * List all functions 1822 | * @description Returns all functions you've previously added to the specified project. 1823 | */ 1824 | getFunctions: { 1825 | parameters: { 1826 | path: { 1827 | /** @description Project ref */ 1828 | ref: string; 1829 | }; 1830 | }; 1831 | responses: { 1832 | 200: { 1833 | content: { 1834 | "application/json": (components["schemas"]["FunctionResponse"])[]; 1835 | }; 1836 | }; 1837 | 403: never; 1838 | /** @description Failed to retrieve project's functions */ 1839 | 500: never; 1840 | }; 1841 | }; 1842 | /** 1843 | * Create a function 1844 | * @description Creates a function and adds it to the specified project. 1845 | */ 1846 | createFunction: { 1847 | parameters: { 1848 | query?: { 1849 | slug?: string; 1850 | name?: string; 1851 | verify_jwt?: boolean; 1852 | import_map?: boolean; 1853 | entrypoint_path?: string; 1854 | import_map_path?: string; 1855 | }; 1856 | path: { 1857 | /** @description Project ref */ 1858 | ref: string; 1859 | }; 1860 | }; 1861 | requestBody: { 1862 | content: { 1863 | "application/json": components["schemas"]["CreateFunctionBody"]; 1864 | "application/vnd.denoland.eszip": components["schemas"]["CreateFunctionBody"]; 1865 | }; 1866 | }; 1867 | responses: { 1868 | 201: { 1869 | content: { 1870 | "application/json": components["schemas"]["FunctionResponse"]; 1871 | }; 1872 | }; 1873 | 403: never; 1874 | /** @description Failed to create project's function */ 1875 | 500: never; 1876 | }; 1877 | }; 1878 | /** 1879 | * Retrieve a function 1880 | * @description Retrieves a function with the specified slug and project. 1881 | */ 1882 | getFunction: { 1883 | parameters: { 1884 | path: { 1885 | /** @description Project ref */ 1886 | ref: string; 1887 | /** @description Function slug */ 1888 | function_slug: string; 1889 | }; 1890 | }; 1891 | responses: { 1892 | 200: { 1893 | content: { 1894 | "application/json": components["schemas"]["FunctionSlugResponse"]; 1895 | }; 1896 | }; 1897 | 403: never; 1898 | /** @description Failed to retrieve function with given slug */ 1899 | 500: never; 1900 | }; 1901 | }; 1902 | /** 1903 | * Delete a function 1904 | * @description Deletes a function with the specified slug from the specified project. 1905 | */ 1906 | deleteFunction: { 1907 | parameters: { 1908 | path: { 1909 | /** @description Project ref */ 1910 | ref: string; 1911 | /** @description Function slug */ 1912 | function_slug: string; 1913 | }; 1914 | }; 1915 | responses: { 1916 | 200: never; 1917 | 403: never; 1918 | /** @description Failed to delete function with given slug */ 1919 | 500: never; 1920 | }; 1921 | }; 1922 | /** 1923 | * Update a function 1924 | * @description Updates a function with the specified slug and project. 1925 | */ 1926 | updateFunction: { 1927 | parameters: { 1928 | query?: { 1929 | slug?: string; 1930 | name?: string; 1931 | verify_jwt?: boolean; 1932 | import_map?: boolean; 1933 | entrypoint_path?: string; 1934 | import_map_path?: string; 1935 | }; 1936 | path: { 1937 | /** @description Project ref */ 1938 | ref: string; 1939 | /** @description Function slug */ 1940 | function_slug: string; 1941 | }; 1942 | }; 1943 | requestBody: { 1944 | content: { 1945 | "application/json": components["schemas"]["UpdateFunctionBody"]; 1946 | "application/vnd.denoland.eszip": components["schemas"]["UpdateFunctionBody"]; 1947 | }; 1948 | }; 1949 | responses: { 1950 | 200: { 1951 | content: { 1952 | "application/json": components["schemas"]["FunctionResponse"]; 1953 | }; 1954 | }; 1955 | 403: never; 1956 | /** @description Failed to update function with given slug */ 1957 | 500: never; 1958 | }; 1959 | }; 1960 | /** 1961 | * Retrieve a function body 1962 | * @description Retrieves a function body for the specified slug and project. 1963 | */ 1964 | getFunctionBody: { 1965 | parameters: { 1966 | path: { 1967 | /** @description Project ref */ 1968 | ref: string; 1969 | /** @description Function slug */ 1970 | function_slug: string; 1971 | }; 1972 | }; 1973 | responses: { 1974 | 200: never; 1975 | 403: never; 1976 | /** @description Failed to retrieve function body with given slug */ 1977 | 500: never; 1978 | }; 1979 | }; 1980 | /** Lists all SSO providers */ 1981 | listAllProviders: { 1982 | parameters: { 1983 | path: { 1984 | /** @description Project ref */ 1985 | ref: string; 1986 | }; 1987 | }; 1988 | responses: { 1989 | 200: { 1990 | content: { 1991 | "application/json": components["schemas"]["ListProvidersResponse"]; 1992 | }; 1993 | }; 1994 | 403: never; 1995 | /** @description SAML 2.0 support is not enabled for this project */ 1996 | 404: never; 1997 | }; 1998 | }; 1999 | /** Creates a new SSO provider */ 2000 | createProviderForProject: { 2001 | parameters: { 2002 | path: { 2003 | /** @description Project ref */ 2004 | ref: string; 2005 | }; 2006 | }; 2007 | requestBody: { 2008 | content: { 2009 | "application/json": components["schemas"]["CreateProviderBody"]; 2010 | }; 2011 | }; 2012 | responses: { 2013 | 201: { 2014 | content: { 2015 | "application/json": components["schemas"]["CreateProviderResponse"]; 2016 | }; 2017 | }; 2018 | 403: never; 2019 | /** @description SAML 2.0 support is not enabled for this project */ 2020 | 404: never; 2021 | }; 2022 | }; 2023 | /** Gets a SSO provider by its UUID */ 2024 | getProviderById: { 2025 | parameters: { 2026 | path: { 2027 | /** @description Project ref */ 2028 | ref: string; 2029 | provider_id: string; 2030 | }; 2031 | }; 2032 | responses: { 2033 | 200: { 2034 | content: { 2035 | "application/json": components["schemas"]["GetProviderResponse"]; 2036 | }; 2037 | }; 2038 | 403: never; 2039 | /** @description Either SAML 2.0 was not enabled for this project, or the provider does not exist */ 2040 | 404: never; 2041 | }; 2042 | }; 2043 | /** Updates a SSO provider by its UUID */ 2044 | updateProviderById: { 2045 | parameters: { 2046 | path: { 2047 | /** @description Project ref */ 2048 | ref: string; 2049 | provider_id: string; 2050 | }; 2051 | }; 2052 | requestBody: { 2053 | content: { 2054 | "application/json": components["schemas"]["UpdateProviderBody"]; 2055 | }; 2056 | }; 2057 | responses: { 2058 | 200: { 2059 | content: { 2060 | "application/json": components["schemas"]["UpdateProviderResponse"]; 2061 | }; 2062 | }; 2063 | 403: never; 2064 | /** @description Either SAML 2.0 was not enabled for this project, or the provider does not exist */ 2065 | 404: never; 2066 | }; 2067 | }; 2068 | /** Removes a SSO provider by its UUID */ 2069 | removeProviderById: { 2070 | parameters: { 2071 | path: { 2072 | /** @description Project ref */ 2073 | ref: string; 2074 | provider_id: string; 2075 | }; 2076 | }; 2077 | responses: { 2078 | 200: { 2079 | content: { 2080 | "application/json": components["schemas"]["DeleteProviderResponse"]; 2081 | }; 2082 | }; 2083 | 403: never; 2084 | /** @description Either SAML 2.0 was not enabled for this project, or the provider does not exist */ 2085 | 404: never; 2086 | }; 2087 | }; 2088 | /** Restores a PITR backup for a database */ 2089 | v1RestorePitr: { 2090 | parameters: { 2091 | path: { 2092 | /** @description Project ref */ 2093 | ref: string; 2094 | }; 2095 | }; 2096 | requestBody: { 2097 | content: { 2098 | "application/json": components["schemas"]["V1RestorePitrBody"]; 2099 | }; 2100 | }; 2101 | responses: { 2102 | 201: never; 2103 | }; 2104 | }; 2105 | /** List members of an organization */ 2106 | v1ListOrganizationMembers: { 2107 | parameters: { 2108 | path: { 2109 | slug: string; 2110 | }; 2111 | }; 2112 | responses: { 2113 | 200: { 2114 | content: { 2115 | "application/json": (components["schemas"]["V1OrganizationMemberResponse"])[]; 2116 | }; 2117 | }; 2118 | }; 2119 | }; 2120 | } 2121 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import createClient from "openapi-fetch"; 2 | import { SUPABASE_API_URL } from "./api/consts"; 3 | import { 4 | ActivateCustomHostnameResponseData, 5 | ApplyNetworkRestrictionsRequestBody, 6 | ApplyNetworkRestrictionsResponseData, 7 | CheckServiceHealthResponseData, 8 | CheckServiceQuery, 9 | CreateCustomHostnameRequestBody, 10 | CreateCustomHostnameResponseData, 11 | CreateFunctionRequestBody, 12 | CreateFunctionResponseData, 13 | CreateOrganizationRequestBody, 14 | CreateOrganizationResponseData, 15 | CreateProjectRequestBody, 16 | CreateProjectResponseData, 17 | CreateSSOProviderRequestBody, 18 | CreateSSOProviderResponseData, 19 | CreateSecretsRequestBody, 20 | DeleteProjectResponseBody, 21 | DeleteSecretsRequestBody, 22 | DeleteSecretsResponseData, 23 | GetBranchDetailsResponseData, 24 | GetCustomHostnameResponseData, 25 | GetFunctionBodyResponseData, 26 | GetFunctionResponseData, 27 | GetNetworkBansResponseData, 28 | GetNetworkRestrictionsResponseData, 29 | GetOrganizationsResponseData, 30 | GetPgsodiumConfigResponseData, 31 | GetPostgRESTConfigResponseData, 32 | GetProjectApiKeysResponseData, 33 | GetProjectAuthConfigResponseData, 34 | GetProjectPGConfigResponseData, 35 | GetProjectPgBouncerConfigResponseData, 36 | GetProjectsResponseData, 37 | GetReadonlyModeStatusResponseData, 38 | GetSSLEnforcementConfigResponseData, 39 | GetSSOProviderResponseData, 40 | GetSSOProvidersResponseData, 41 | GetSecretsResponseData, 42 | GetTypescriptTypesResponseData, 43 | GetUpgradeEligibilityResponseData, 44 | GetUpgradeStatusResponseData, 45 | GetVanitySubdomainResponseData, 46 | RemoveNetworkBanRequestBody, 47 | ReverifyCustomHostnameResponseData, 48 | RunQueryResponseData, 49 | UpdateBranchRequestBody, 50 | UpdateBranchResponseData, 51 | UpdateFunctionRequestBody, 52 | UpdateFunctionResponseData, 53 | UpdatePgSodiumConfigRequestBody, 54 | UpdatePgSodiumConfigResponseData, 55 | UpdatePostgRESTConfigRequestBody, 56 | UpdatePostgRESTConfigResponseData, 57 | UpdateProjectAuthConfigRequestBody, 58 | UpdateProjectAuthConfigResponseData, 59 | UpdateProjectPGConfigRequestBody, 60 | UpdateProjectPGConfigResponseData, 61 | UpdateSSLEnforcementConfigRequestBody, 62 | UpdateSSLEnforcementConfigResponseData, 63 | UpdateSSOProviderRequestBody, 64 | UpdateSSOProviderResponseData, 65 | } from "./api/types"; 66 | import { paths } from "./api/v1"; 67 | 68 | export * from "./api/types"; 69 | 70 | export type SupabaseManagementAPIOptions = { 71 | accessToken: string; 72 | baseUrl?: string; 73 | }; 74 | 75 | export class SupabaseManagementAPIError extends Error { 76 | constructor(message: string, public readonly response: Response) { 77 | super(message); 78 | } 79 | } 80 | 81 | export function isSupabaseError( 82 | error: unknown 83 | ): error is SupabaseManagementAPIError { 84 | return error instanceof SupabaseManagementAPIError; 85 | } 86 | 87 | export class SupabaseManagementAPI { 88 | constructor(private readonly options: SupabaseManagementAPIOptions) {} 89 | 90 | /** 91 | * List all organizations 92 | * @description Returns a list of organizations that you currently belong to. 93 | */ 94 | async getOrganizations(): Promise { 95 | const { data, response } = await this.client.get("/v1/organizations", {}); 96 | 97 | if (response.status !== 200) { 98 | throw new SupabaseManagementAPIError( 99 | `Failed to get organizations: ${response.statusText} (${response.status})`, 100 | response 101 | ); 102 | } 103 | 104 | return data; 105 | } 106 | 107 | /** Create an organization */ 108 | async createOrganization( 109 | body: CreateOrganizationRequestBody 110 | ): Promise { 111 | const { data, response } = await this.client.post("/v1/organizations", { 112 | body, 113 | }); 114 | 115 | if (response.status !== 201) { 116 | throw await this.#createResponseError(response, "create organization"); 117 | } 118 | 119 | return data; 120 | } 121 | 122 | /** 123 | * Get database branch config 124 | * @description Fetches configurations of the specified database branch 125 | */ 126 | async getBranchDetails( 127 | branchId: string 128 | ): Promise { 129 | const { data, response } = await this.client.get( 130 | "/v1/branches/{branch_id}", 131 | { 132 | params: { 133 | path: { 134 | branch_id: branchId, 135 | }, 136 | }, 137 | } 138 | ); 139 | 140 | if (response.status !== 200) { 141 | throw await this.#createResponseError(response, "get branch details"); 142 | } 143 | 144 | return data; 145 | } 146 | 147 | async deleteBranch(branchId: string) { 148 | const { response } = await this.client.del("/v1/branches/{branch_id}", { 149 | params: { 150 | path: { 151 | branch_id: branchId, 152 | }, 153 | }, 154 | }); 155 | 156 | if (response.status !== 200) { 157 | throw await this.#createResponseError(response, "delete branch"); 158 | } 159 | } 160 | 161 | async updateBranch( 162 | branchId: string, 163 | body: UpdateBranchRequestBody 164 | ): Promise { 165 | const { data, response } = await this.client.patch( 166 | "/v1/branches/{branch_id}", 167 | { 168 | params: { 169 | path: { 170 | branch_id: branchId, 171 | }, 172 | }, 173 | body, 174 | } 175 | ); 176 | 177 | if (response.status !== 200) { 178 | throw await this.#createResponseError(response, "update branch"); 179 | } 180 | 181 | return data; 182 | } 183 | 184 | /** 185 | * List all projects 186 | * @description Returns a list of all projects you've previously created. 187 | */ 188 | async getProjects(): Promise { 189 | const { data, response } = await this.client.get("/v1/projects", {}); 190 | 191 | if (response.status !== 200) { 192 | throw await this.#createResponseError(response, "get projects"); 193 | } 194 | 195 | return data; 196 | } 197 | 198 | /** Create a project */ 199 | async createProject( 200 | body: CreateProjectRequestBody 201 | ): Promise { 202 | const { data, response } = await this.client.post("/v1/projects", { 203 | body, 204 | }); 205 | 206 | if (response.status !== 201) { 207 | throw await this.#createResponseError(response, "create project"); 208 | } 209 | 210 | return data; 211 | } 212 | 213 | /** Delete a project */ 214 | async deleteProject(ref: string): Promise { 215 | const { data, response } = await this.client.del("/v1/projects/{ref}", { 216 | params: { 217 | path: { 218 | ref, 219 | }, 220 | }, 221 | }); 222 | 223 | if (response.status !== 200) { 224 | throw await this.#createResponseError(response, "delete project"); 225 | } 226 | 227 | return data; 228 | } 229 | 230 | /** 231 | * Check service health 232 | * @description Checks the health of the specified service. 233 | */ 234 | async checkServiceHealth( 235 | ref: string, 236 | query: CheckServiceQuery 237 | ): Promise { 238 | const { data, response } = await this.client.get( 239 | "/v1/projects/{ref}/health", 240 | { 241 | params: { 242 | query: query, 243 | path: { 244 | ref, 245 | }, 246 | }, 247 | } 248 | ); 249 | 250 | if (response.status !== 200) { 251 | throw await this.#createResponseError(response, "check service health"); 252 | } 253 | 254 | return data; 255 | } 256 | 257 | /** 258 | * List all functions 259 | * @description Returns all functions you've previously added to the specified project. 260 | */ 261 | async listFunctions(ref: string) { 262 | const { data, response } = await this.client.get( 263 | "/v1/projects/{ref}/functions", 264 | { 265 | params: { 266 | path: { 267 | ref, 268 | }, 269 | }, 270 | } 271 | ); 272 | 273 | if (response.status !== 200) { 274 | throw await this.#createResponseError(response, "list functions"); 275 | } 276 | 277 | return data; 278 | } 279 | 280 | /** 281 | * Create a function 282 | * @description Creates a function and adds it to the specified project. 283 | */ 284 | async createFunction( 285 | ref: string, 286 | body: CreateFunctionRequestBody 287 | ): Promise { 288 | const { data, response } = await this.client.post( 289 | "/v1/projects/{ref}/functions", 290 | { 291 | params: { 292 | path: { 293 | ref, 294 | }, 295 | }, 296 | body, 297 | } 298 | ); 299 | 300 | if (response.status !== 201) { 301 | throw await this.#createResponseError(response, "create function"); 302 | } 303 | 304 | return data; 305 | } 306 | 307 | /** 308 | * Retrieve a function 309 | * @description Retrieves a function with the specified slug and project. 310 | */ 311 | async getFunction( 312 | ref: string, 313 | slug: string 314 | ): Promise { 315 | const { data, response } = await this.client.get( 316 | "/v1/projects/{ref}/functions/{function_slug}", 317 | { 318 | params: { 319 | path: { 320 | ref, 321 | function_slug: slug, 322 | }, 323 | }, 324 | } 325 | ); 326 | 327 | if (response.status !== 200) { 328 | throw await this.#createResponseError(response, "get function"); 329 | } 330 | 331 | return data; 332 | } 333 | 334 | /** 335 | * Update a function 336 | * @description Updates a function with the specified slug and project. 337 | */ 338 | async updateFunction( 339 | ref: string, 340 | slug: string, 341 | body: UpdateFunctionRequestBody 342 | ): Promise { 343 | const { data, response } = await this.client.patch( 344 | "/v1/projects/{ref}/functions/{function_slug}", 345 | { 346 | params: { 347 | path: { 348 | ref, 349 | function_slug: slug, 350 | }, 351 | }, 352 | body, 353 | } 354 | ); 355 | 356 | if (response.status !== 200) { 357 | throw await this.#createResponseError(response, "update function"); 358 | } 359 | 360 | return data; 361 | } 362 | 363 | /** 364 | * Delete a function 365 | * @description Deletes a function with the specified slug from the specified project. 366 | */ 367 | async deleteFunction(ref: string, slug: string) { 368 | const { response } = await this.client.del( 369 | "/v1/projects/{ref}/functions/{function_slug}", 370 | { 371 | params: { 372 | path: { 373 | ref, 374 | function_slug: slug, 375 | }, 376 | }, 377 | } 378 | ); 379 | 380 | if (response.status !== 200) { 381 | throw await this.#createResponseError(response, "delete function"); 382 | } 383 | } 384 | 385 | /** 386 | * Retrieve a function body 387 | * @description Retrieves a function body for the specified slug and project. 388 | */ 389 | async getFunctionBody( 390 | ref: string, 391 | slug: string 392 | ): Promise { 393 | const { data, response } = await this.client.get( 394 | "/v1/projects/{ref}/functions/{function_slug}/body", 395 | { 396 | params: { 397 | path: { 398 | ref, 399 | function_slug: slug, 400 | }, 401 | }, 402 | } 403 | ); 404 | 405 | if (response.status !== 200) { 406 | throw await this.#createResponseError(response, "get function body"); 407 | } 408 | 409 | return data; 410 | } 411 | 412 | async getProjectApiKeys(ref: string): Promise { 413 | const { data, response } = await this.client.get( 414 | "/v1/projects/{ref}/api-keys", 415 | { 416 | params: { 417 | path: { 418 | ref, 419 | }, 420 | }, 421 | } 422 | ); 423 | 424 | if (response.status !== 200) { 425 | throw await this.#createResponseError(response, "get project api keys"); 426 | } 427 | 428 | return data; 429 | } 430 | 431 | /** Gets project's custom hostname config */ 432 | async getCustomHostnameConfig( 433 | ref: string 434 | ): Promise { 435 | const { data, response } = await this.client.get( 436 | "/v1/projects/{ref}/custom-hostname", 437 | { 438 | params: { 439 | path: { 440 | ref, 441 | }, 442 | }, 443 | } 444 | ); 445 | 446 | if (response.status !== 200) { 447 | throw await this.#createResponseError(response, "get custom hostname"); 448 | } 449 | 450 | return data; 451 | } 452 | 453 | /** Deletes a project's custom hostname configuration */ 454 | async removeCustomHostnameConfig(ref: string) { 455 | const { response } = await this.client.del( 456 | "/v1/projects/{ref}/custom-hostname", 457 | { 458 | params: { 459 | path: { 460 | ref, 461 | }, 462 | }, 463 | } 464 | ); 465 | 466 | if (response.status !== 200) { 467 | throw await this.#createResponseError( 468 | response, 469 | "remove custom hostname config" 470 | ); 471 | } 472 | } 473 | 474 | /** Updates project's custom hostname configuration */ 475 | async createCustomHostnameConfig( 476 | ref: string, 477 | body: CreateCustomHostnameRequestBody 478 | ): Promise { 479 | const { data, response } = await this.client.post( 480 | "/v1/projects/{ref}/custom-hostname/initialize", 481 | { 482 | params: { 483 | path: { 484 | ref, 485 | }, 486 | }, 487 | body, 488 | } 489 | ); 490 | 491 | if (response.status !== 201) { 492 | throw await this.#createResponseError( 493 | response, 494 | "create custom hostname config" 495 | ); 496 | } 497 | 498 | return data; 499 | } 500 | 501 | /** Attempts to verify the DNS configuration for project's custom hostname configuration */ 502 | async reverifyCustomHostnameConfig( 503 | ref: string 504 | ): Promise { 505 | const { data, response } = await this.client.post( 506 | "/v1/projects/{ref}/custom-hostname/reverify", 507 | { 508 | params: { 509 | path: { 510 | ref, 511 | }, 512 | }, 513 | } 514 | ); 515 | 516 | if (response.status !== 200) { 517 | throw await this.#createResponseError( 518 | response, 519 | "reverify custom hostname config" 520 | ); 521 | } 522 | 523 | return data; 524 | } 525 | 526 | /** Activates a custom hostname for a project. */ 527 | async activateCustomHostnameConfig( 528 | ref: string 529 | ): Promise { 530 | const { data, response } = await this.client.post( 531 | "/v1/projects/{ref}/custom-hostname/activate", 532 | { 533 | params: { 534 | path: { 535 | ref, 536 | }, 537 | }, 538 | } 539 | ); 540 | 541 | if (response.status !== 200) { 542 | throw await this.#createResponseError( 543 | response, 544 | "activate custom hostname config" 545 | ); 546 | } 547 | 548 | return data; 549 | } 550 | 551 | /** Gets project's network bans */ 552 | async getNetworkBans(ref: string): Promise { 553 | const { data, response } = await this.client.post( 554 | "/v1/projects/{ref}/network-bans/retrieve", 555 | { 556 | params: { 557 | path: { 558 | ref, 559 | }, 560 | }, 561 | } 562 | ); 563 | 564 | if (response.status !== 200) { 565 | throw await this.#createResponseError(response, "get network bans"); 566 | } 567 | 568 | return data; 569 | } 570 | 571 | /** Remove network bans. */ 572 | async removeNetworkBan(ref: string, body: RemoveNetworkBanRequestBody) { 573 | const { response } = await this.client.del( 574 | "/v1/projects/{ref}/network-bans", 575 | { 576 | params: { 577 | path: { 578 | ref, 579 | }, 580 | }, 581 | body, 582 | } 583 | ); 584 | 585 | if (response.status !== 200) { 586 | throw await this.#createResponseError(response, "remove network ban"); 587 | } 588 | } 589 | 590 | /** Gets project's network restrictions */ 591 | async getNetworkRestrictions( 592 | ref: string 593 | ): Promise { 594 | const { data, response } = await this.client.get( 595 | "/v1/projects/{ref}/network-restrictions", 596 | { 597 | params: { 598 | path: { 599 | ref, 600 | }, 601 | }, 602 | } 603 | ); 604 | 605 | if (response.status !== 200) { 606 | throw await this.#createResponseError( 607 | response, 608 | "get network restrictions" 609 | ); 610 | } 611 | 612 | return data; 613 | } 614 | 615 | /** Updates project's network restrictions */ 616 | async applyNetworkRestrictions( 617 | ref: string, 618 | body: ApplyNetworkRestrictionsRequestBody 619 | ): Promise { 620 | const { data, response } = await this.client.post( 621 | "/v1/projects/{ref}/network-restrictions/apply", 622 | { 623 | params: { 624 | path: { 625 | ref, 626 | }, 627 | }, 628 | body, 629 | } 630 | ); 631 | 632 | if (response.status !== 200) { 633 | throw await this.#createResponseError( 634 | response, 635 | "apply network restrictions" 636 | ); 637 | } 638 | 639 | return data; 640 | } 641 | 642 | /** Gets project's pgsodium config */ 643 | async getPgsodiumConfig(ref: string): Promise { 644 | const { data, response } = await this.client.get( 645 | "/v1/projects/{ref}/pgsodium", 646 | { 647 | params: { 648 | path: { 649 | ref, 650 | }, 651 | }, 652 | } 653 | ); 654 | 655 | if (response.status !== 200) { 656 | throw await this.#createResponseError(response, "get pg sodium config"); 657 | } 658 | 659 | return data; 660 | } 661 | 662 | /** Updates project's pgsodium config. Updating the root_key can cause all data encrypted with the older key to become inaccessible. */ 663 | async updatePgSodiumConfig( 664 | ref: string, 665 | body: UpdatePgSodiumConfigRequestBody 666 | ): Promise { 667 | const { data, response } = await this.client.put( 668 | "/v1/projects/{ref}/pgsodium", 669 | { 670 | params: { 671 | path: { 672 | ref, 673 | }, 674 | }, 675 | body, 676 | } 677 | ); 678 | 679 | if (response.status !== 200) { 680 | throw await this.#createResponseError( 681 | response, 682 | "update pg sodium config" 683 | ); 684 | } 685 | 686 | return data; 687 | } 688 | 689 | /** Gets project's postgrest config */ 690 | async getPostgRESTConfig( 691 | ref: string 692 | ): Promise { 693 | const { data, response } = await this.client.get( 694 | "/v1/projects/{ref}/postgrest", 695 | { 696 | params: { 697 | path: { 698 | ref, 699 | }, 700 | }, 701 | } 702 | ); 703 | 704 | if (response.status !== 200) { 705 | throw await this.#createResponseError(response, "get postgrest config"); 706 | } 707 | 708 | return data; 709 | } 710 | 711 | /** Updates project's postgrest config */ 712 | async updatePostgRESTConfig( 713 | ref: string, 714 | body: UpdatePostgRESTConfigRequestBody 715 | ): Promise { 716 | const { data, response } = await this.client.patch( 717 | "/v1/projects/{ref}/postgrest", 718 | { 719 | params: { 720 | path: { 721 | ref, 722 | }, 723 | }, 724 | body, 725 | } 726 | ); 727 | 728 | if (response.status !== 200) { 729 | throw await this.#createResponseError( 730 | response, 731 | "update postgrest config" 732 | ); 733 | } 734 | 735 | return data; 736 | } 737 | 738 | /** Run sql query */ 739 | async runQuery(ref: string, query: string): Promise { 740 | const { data, response } = await this.client.post( 741 | "/v1/projects/{ref}/database/query", 742 | { 743 | params: { 744 | path: { 745 | ref, 746 | }, 747 | }, 748 | body: { 749 | query, 750 | }, 751 | } 752 | ); 753 | 754 | if (response.status !== 201) { 755 | throw await this.#createResponseError(response, "run query"); 756 | } 757 | 758 | return data; 759 | } 760 | 761 | async enableWebhooks(ref: string) { 762 | const { data, response } = await this.client.post( 763 | "/v1/projects/{ref}/database/webhooks/enable", 764 | { 765 | params: { 766 | path: { 767 | ref, 768 | }, 769 | }, 770 | } 771 | ); 772 | 773 | if (response.status !== 201) { 774 | throw await this.#createResponseError(response, "enable webhooks"); 775 | } 776 | } 777 | 778 | /** 779 | * List all secrets 780 | * @description Returns all secrets you've previously added to the specified project. 781 | */ 782 | async getSecrets(ref: string): Promise { 783 | const { data, response } = await this.client.get( 784 | "/v1/projects/{ref}/secrets", 785 | { 786 | params: { 787 | path: { 788 | ref, 789 | }, 790 | }, 791 | } 792 | ); 793 | 794 | if (response.status !== 200) { 795 | throw await this.#createResponseError(response, "get secrets"); 796 | } 797 | 798 | return data; 799 | } 800 | 801 | /** 802 | * Bulk create secrets 803 | * @description Creates multiple secrets and adds them to the specified project. 804 | */ 805 | async createSecrets(ref: string, body: CreateSecretsRequestBody) { 806 | const { response } = await this.client.post("/v1/projects/{ref}/secrets", { 807 | params: { 808 | path: { 809 | ref, 810 | }, 811 | }, 812 | body, 813 | }); 814 | 815 | if (response.status !== 201) { 816 | throw await this.#createResponseError(response, "create secrets"); 817 | } 818 | } 819 | 820 | /** 821 | * Bulk delete secrets 822 | * @description Deletes all secrets with the given names from the specified project 823 | */ 824 | async deleteSecrets( 825 | ref: string, 826 | body: DeleteSecretsRequestBody 827 | ): Promise { 828 | const { data, response } = await this.client.del( 829 | "/v1/projects/{ref}/secrets", 830 | { 831 | params: { 832 | path: { 833 | ref, 834 | }, 835 | }, 836 | body, 837 | } 838 | ); 839 | 840 | if (response.status !== 200) { 841 | throw await this.#createResponseError(response, "delete secrets"); 842 | } 843 | 844 | return data; 845 | } 846 | 847 | /** Get project's SSL enforcement configuration. */ 848 | async getSSLEnforcementConfig( 849 | ref: string 850 | ): Promise { 851 | const { data, response } = await this.client.get( 852 | "/v1/projects/{ref}/ssl-enforcement", 853 | { 854 | params: { 855 | path: { 856 | ref, 857 | }, 858 | }, 859 | } 860 | ); 861 | 862 | if (response.status !== 200) { 863 | throw await this.#createResponseError( 864 | response, 865 | "get ssl enforcement config" 866 | ); 867 | } 868 | 869 | return data; 870 | } 871 | 872 | /** Update project's SSL enforcement configuration. */ 873 | async updateSSLEnforcementConfig( 874 | ref: string, 875 | body: UpdateSSLEnforcementConfigRequestBody 876 | ): Promise { 877 | const { data, response } = await this.client.put( 878 | "/v1/projects/{ref}/ssl-enforcement", 879 | { 880 | params: { 881 | path: { 882 | ref, 883 | }, 884 | }, 885 | body, 886 | } 887 | ); 888 | 889 | if (response.status !== 200) { 890 | throw await this.#createResponseError( 891 | response, 892 | "update ssl enforcement config" 893 | ); 894 | } 895 | 896 | return data; 897 | } 898 | 899 | /** 900 | * Generate TypeScript types 901 | * @description Returns the TypeScript types of your schema for use with supabase-js. 902 | */ 903 | async getTypescriptTypes( 904 | ref: string 905 | ): Promise { 906 | const { data, response } = await this.client.get( 907 | "/v1/projects/{ref}/types/typescript", 908 | { 909 | params: { 910 | path: { 911 | ref, 912 | }, 913 | }, 914 | } 915 | ); 916 | 917 | if (response.status !== 200) { 918 | throw await this.#createResponseError(response, "get typescript types"); 919 | } 920 | 921 | return data; 922 | } 923 | 924 | /** Gets current vanity subdomain config */ 925 | async getVanitySubdomainConfig( 926 | ref: string 927 | ): Promise { 928 | const { data, response } = await this.client.get( 929 | "/v1/projects/{ref}/vanity-subdomain", 930 | { 931 | params: { 932 | path: { 933 | ref, 934 | }, 935 | }, 936 | } 937 | ); 938 | 939 | if (response.status !== 200) { 940 | throw await this.#createResponseError( 941 | response, 942 | "get vanity subdomain config" 943 | ); 944 | } 945 | 946 | return data; 947 | } 948 | 949 | /** Deletes a project's vanity subdomain configuration */ 950 | async removeVanitySubdomainConfig(ref: string) { 951 | const { response } = await this.client.del( 952 | "/v1/projects/{ref}/vanity-subdomain", 953 | { 954 | params: { 955 | path: { 956 | ref, 957 | }, 958 | }, 959 | } 960 | ); 961 | 962 | if (response.status !== 200) { 963 | throw await this.#createResponseError( 964 | response, 965 | "remove vanity subdomain config" 966 | ); 967 | } 968 | } 969 | 970 | /** Checks vanity subdomain availability */ 971 | async checkVanitySubdomainAvailability( 972 | ref: string, 973 | subdomain: string 974 | ): Promise { 975 | const { data, response } = await this.client.post( 976 | "/v1/projects/{ref}/vanity-subdomain/check-availability", 977 | { 978 | params: { 979 | path: { 980 | ref, 981 | }, 982 | }, 983 | body: { 984 | vanity_subdomain: subdomain, 985 | }, 986 | } 987 | ); 988 | 989 | if (response.status !== 200) { 990 | throw await this.#createResponseError( 991 | response, 992 | "check vanity subdomain availability" 993 | ); 994 | } 995 | 996 | return typeof data === "undefined" ? false : data.available; 997 | } 998 | 999 | /** Activates a vanity subdomain for a project. */ 1000 | async activateVanitySubdomainPlease( 1001 | ref: string, 1002 | subdomain: string 1003 | ): Promise { 1004 | const { response, data } = await this.client.post( 1005 | "/v1/projects/{ref}/vanity-subdomain/activate", 1006 | { 1007 | params: { 1008 | path: { 1009 | ref, 1010 | }, 1011 | }, 1012 | body: { 1013 | vanity_subdomain: subdomain, 1014 | }, 1015 | } 1016 | ); 1017 | 1018 | if (response.status !== 200) { 1019 | throw await this.#createResponseError( 1020 | response, 1021 | "activate vanity subdomain" 1022 | ); 1023 | } 1024 | 1025 | return data?.custom_domain; 1026 | } 1027 | 1028 | /** Upgrades the project's Postgres version */ 1029 | async upgradeProject(ref: string, targetVersion: number) { 1030 | const { response } = await this.client.post("/v1/projects/{ref}/upgrade", { 1031 | params: { 1032 | path: { 1033 | ref, 1034 | }, 1035 | }, 1036 | body: { 1037 | target_version: targetVersion, 1038 | }, 1039 | }); 1040 | 1041 | if (response.status !== 200) { 1042 | throw await this.#createResponseError(response, "upgrade project"); 1043 | } 1044 | } 1045 | 1046 | /** Returns the project's eligibility for upgrades */ 1047 | async getUpgradeEligibility( 1048 | ref: string 1049 | ): Promise { 1050 | const { data, response } = await this.client.get( 1051 | "/v1/projects/{ref}/upgrade/eligibility", 1052 | { 1053 | params: { 1054 | path: { 1055 | ref, 1056 | }, 1057 | }, 1058 | } 1059 | ); 1060 | 1061 | if (response.status !== 200) { 1062 | throw await this.#createResponseError( 1063 | response, 1064 | "get upgrade eligibility" 1065 | ); 1066 | } 1067 | 1068 | return data; 1069 | } 1070 | 1071 | /** Gets the latest status of the project's upgrade */ 1072 | async getUpgradeStatus(ref: string): Promise { 1073 | const { data, response } = await this.client.get( 1074 | "/v1/projects/{ref}/upgrade/status", 1075 | { 1076 | params: { 1077 | path: { 1078 | ref, 1079 | }, 1080 | }, 1081 | } 1082 | ); 1083 | 1084 | if (response.status !== 200) { 1085 | throw await this.#createResponseError(response, "get upgrade status"); 1086 | } 1087 | 1088 | return data; 1089 | } 1090 | 1091 | /** Returns project's readonly mode status */ 1092 | async getReadOnlyModeStatus( 1093 | ref: string 1094 | ): Promise { 1095 | const { data, response } = await this.client.get( 1096 | "/v1/projects/{ref}/readonly", 1097 | { 1098 | params: { 1099 | path: { 1100 | ref, 1101 | }, 1102 | }, 1103 | } 1104 | ); 1105 | 1106 | if (response.status !== 200) { 1107 | throw await this.#createResponseError( 1108 | response, 1109 | "get readonly mode status" 1110 | ); 1111 | } 1112 | 1113 | return data; 1114 | } 1115 | 1116 | /** Disables project's readonly mode for the next 15 minutes */ 1117 | async temporarilyDisableReadonlyMode(ref: string) { 1118 | const { response } = await this.client.post( 1119 | "/v1/projects/{ref}/readonly/temporary-disable", 1120 | { 1121 | params: { 1122 | path: { 1123 | ref, 1124 | }, 1125 | }, 1126 | } 1127 | ); 1128 | 1129 | if (response.status !== 200) { 1130 | throw await this.#createResponseError( 1131 | response, 1132 | "temporarily disable readonly mode" 1133 | ); 1134 | } 1135 | } 1136 | 1137 | /** Gets project's Postgres config */ 1138 | async getPGConfig(ref: string): Promise { 1139 | const { data, response } = await this.client.get( 1140 | "/v1/projects/{ref}/config/database/postgres", 1141 | { 1142 | params: { 1143 | path: { 1144 | ref, 1145 | }, 1146 | }, 1147 | } 1148 | ); 1149 | 1150 | if (response.status !== 200) { 1151 | throw await this.#createResponseError(response, "get PG config"); 1152 | } 1153 | 1154 | return data; 1155 | } 1156 | 1157 | /** Updates project's Postgres config */ 1158 | async updatePGConfig( 1159 | ref: string, 1160 | body: UpdateProjectPGConfigRequestBody 1161 | ): Promise { 1162 | const { data, response } = await this.client.put( 1163 | "/v1/projects/{ref}/config/database/postgres", 1164 | { 1165 | params: { 1166 | path: { 1167 | ref, 1168 | }, 1169 | }, 1170 | body, 1171 | } 1172 | ); 1173 | 1174 | if (response.status !== 200) { 1175 | throw await this.#createResponseError(response, "update PG config"); 1176 | } 1177 | 1178 | return data; 1179 | } 1180 | 1181 | /** Gets project's pgbouncer config */ 1182 | async getPgBouncerConfig( 1183 | ref: string 1184 | ): Promise { 1185 | const { data, response } = await this.client.get( 1186 | "/v1/projects/{ref}/config/database/pgbouncer", 1187 | { 1188 | params: { 1189 | path: { 1190 | ref, 1191 | }, 1192 | }, 1193 | } 1194 | ); 1195 | 1196 | if (response.status !== 200) { 1197 | throw await this.#createResponseError(response, "get Pgbouncer config"); 1198 | } 1199 | 1200 | return data; 1201 | } 1202 | 1203 | /** Gets project's auth config */ 1204 | async getProjectAuthConfig( 1205 | ref: string 1206 | ): Promise { 1207 | const { data, response } = await this.client.get( 1208 | "/v1/projects/{ref}/config/auth", 1209 | { 1210 | params: { 1211 | path: { 1212 | ref, 1213 | }, 1214 | }, 1215 | } 1216 | ); 1217 | 1218 | if (response.status !== 200) { 1219 | throw await this.#createResponseError( 1220 | response, 1221 | "get project auth config" 1222 | ); 1223 | } 1224 | 1225 | return data; 1226 | } 1227 | 1228 | /** Updates a project's auth config */ 1229 | async updateProjectAuthConfig( 1230 | ref: string, 1231 | body: UpdateProjectAuthConfigRequestBody 1232 | ): Promise { 1233 | const { data, response } = await this.client.patch( 1234 | "/v1/projects/{ref}/config/auth", 1235 | { 1236 | params: { 1237 | path: { 1238 | ref, 1239 | }, 1240 | }, 1241 | body, 1242 | } 1243 | ); 1244 | 1245 | if (response.status !== 200) { 1246 | throw await this.#createResponseError( 1247 | response, 1248 | "update project auth config" 1249 | ); 1250 | } 1251 | 1252 | return data; 1253 | } 1254 | 1255 | /** Lists all SSO providers */ 1256 | async getSSOProviders(ref: string): Promise { 1257 | const { data, response } = await this.client.get( 1258 | "/v1/projects/{ref}/config/auth/sso/providers", 1259 | { 1260 | params: { 1261 | path: { 1262 | ref, 1263 | }, 1264 | }, 1265 | } 1266 | ); 1267 | 1268 | if (response.status !== 200) { 1269 | throw await this.#createResponseError(response, "get SSO providers"); 1270 | } 1271 | 1272 | return data; 1273 | } 1274 | 1275 | /** Creates a new SSO provider */ 1276 | async createSSOProvider( 1277 | ref: string, 1278 | body: CreateSSOProviderRequestBody 1279 | ): Promise { 1280 | const { data, response } = await this.client.post( 1281 | "/v1/projects/{ref}/config/auth/sso/providers", 1282 | { 1283 | params: { 1284 | path: { 1285 | ref, 1286 | }, 1287 | }, 1288 | body, 1289 | } 1290 | ); 1291 | 1292 | if (response.status !== 201) { 1293 | throw await this.#createResponseError(response, "create SSO provider"); 1294 | } 1295 | 1296 | return data; 1297 | } 1298 | 1299 | /** Gets a SSO provider by its UUID */ 1300 | async getSSOProvider( 1301 | ref: string, 1302 | uuid: string 1303 | ): Promise { 1304 | const { data, response } = await this.client.get( 1305 | "/v1/projects/{ref}/config/auth/sso/providers/{provider_id}", 1306 | { 1307 | params: { 1308 | path: { 1309 | ref, 1310 | provider_id: uuid, 1311 | }, 1312 | }, 1313 | } 1314 | ); 1315 | 1316 | if (response.status !== 200) { 1317 | throw await this.#createResponseError(response, "get SSO provider"); 1318 | } 1319 | 1320 | return data; 1321 | } 1322 | 1323 | /** Updates a SSO provider by its UUID */ 1324 | async updateSSOProvider( 1325 | ref: string, 1326 | uuid: string, 1327 | body: UpdateSSOProviderRequestBody 1328 | ): Promise { 1329 | const { data, response } = await this.client.put( 1330 | "/v1/projects/{ref}/config/auth/sso/providers/{provider_id}", 1331 | { 1332 | params: { 1333 | path: { 1334 | ref, 1335 | provider_id: uuid, 1336 | }, 1337 | }, 1338 | body, 1339 | } 1340 | ); 1341 | 1342 | if (response.status !== 200) { 1343 | throw await this.#createResponseError(response, "update SSO provider"); 1344 | } 1345 | 1346 | return data; 1347 | } 1348 | 1349 | /** Removes a SSO provider by its UUID */ 1350 | async deleteSSOProvider(ref: string, uuid: string) { 1351 | const { response } = await this.client.del( 1352 | "/v1/projects/{ref}/config/auth/sso/providers/{provider_id}", 1353 | { 1354 | params: { 1355 | path: { 1356 | ref, 1357 | provider_id: uuid, 1358 | }, 1359 | }, 1360 | } 1361 | ); 1362 | 1363 | if (response.status !== 204) { 1364 | throw await this.#createResponseError(response, "delete SSO provider"); 1365 | } 1366 | } 1367 | 1368 | /** List snippets */ 1369 | async listSnippets(projectRef?: string) { 1370 | const { data, response } = await this.client.get("/v1/snippets", { 1371 | params: { 1372 | query: { 1373 | project_ref: projectRef, 1374 | }, 1375 | }, 1376 | }); 1377 | 1378 | if (response.status !== 200) { 1379 | throw await this.#createResponseError(response, "list snippets"); 1380 | } 1381 | 1382 | return data; 1383 | } 1384 | 1385 | async getSnippet(id: string) { 1386 | const { data, response } = await this.client.get("/v1/snippets/{id}", { 1387 | params: { 1388 | path: { 1389 | id, 1390 | }, 1391 | }, 1392 | }); 1393 | 1394 | if (response.status !== 200) { 1395 | throw await this.#createResponseError(response, "get snippet"); 1396 | } 1397 | 1398 | return data; 1399 | } 1400 | 1401 | get client() { 1402 | return createClient({ 1403 | baseUrl: this.options.baseUrl || SUPABASE_API_URL, 1404 | headers: { 1405 | Authorization: `Bearer ${this.options.accessToken}`, 1406 | }, 1407 | }); 1408 | } 1409 | 1410 | async #createResponseError(response: Response, action: string) { 1411 | const errorBody = await safeParseErrorResponseBody(response); 1412 | 1413 | return new SupabaseManagementAPIError( 1414 | `Failed to ${action}: ${response.statusText} (${response.status})${ 1415 | errorBody ? `: ${errorBody.message}` : "" 1416 | }`, 1417 | response 1418 | ); 1419 | } 1420 | } 1421 | 1422 | async function safeParseErrorResponseBody( 1423 | response: Response 1424 | ): Promise<{ message: string } | undefined> { 1425 | try { 1426 | const body = await response.json(); 1427 | 1428 | if ( 1429 | typeof body === "object" && 1430 | body !== null && 1431 | "message" in body && 1432 | typeof body.message === "string" 1433 | ) { 1434 | return { message: body.message }; 1435 | } 1436 | } catch (error) { 1437 | return; 1438 | } 1439 | } 1440 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": false, 4 | "declaration": false, 5 | "declarationMap": false, 6 | "esModuleInterop": true, 7 | "forceConsistentCasingInFileNames": true, 8 | "inlineSources": false, 9 | "isolatedModules": true, 10 | "moduleResolution": "node", 11 | "noUnusedLocals": false, 12 | "noUnusedParameters": false, 13 | "preserveWatchOutput": true, 14 | "skipLibCheck": true, 15 | "strict": true, 16 | "experimentalDecorators": true, 17 | "emitDecoratorMetadata": true, 18 | "sourceMap": true, 19 | "resolveJsonModule": false, 20 | "lib": ["es2019", "dom"], 21 | "module": "commonjs", 22 | "target": "es2021" 23 | }, 24 | "include": ["./src/**/*.ts", "tsup.config.ts"], 25 | "exclude": ["node_modules"] 26 | } 27 | -------------------------------------------------------------------------------- /tsup.config.ts: -------------------------------------------------------------------------------- 1 | import { Plugin } from "esbuild"; 2 | import { Options, defineConfig } from "tsup"; 3 | 4 | const restoreNodeProtocolPlugin = (): Plugin => { 5 | return { 6 | name: "node-protocol-plugin-restorer", 7 | setup(build) { 8 | build.onResolve( 9 | { 10 | filter: /node:/, 11 | }, 12 | async (args) => { 13 | return { path: args.path, external: true }; 14 | } 15 | ); 16 | }, 17 | }; 18 | }; 19 | 20 | export const options: Options = { 21 | name: "main", 22 | config: "tsconfig.json", 23 | entry: ["./src/index.ts"], 24 | outDir: "./dist", 25 | platform: "node", 26 | format: ["cjs", "esm"], 27 | legacyOutput: false, 28 | sourcemap: true, 29 | clean: true, 30 | bundle: true, 31 | splitting: false, 32 | dts: true, 33 | treeshake: { 34 | preset: "recommended", 35 | }, 36 | esbuildPlugins: [restoreNodeProtocolPlugin()], 37 | noExternal: ["openapi-fetch"], 38 | }; 39 | 40 | export default defineConfig(options); 41 | --------------------------------------------------------------------------------