@silas-sh/supabase-management-js 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs ADDED
@@ -0,0 +1,1201 @@
1
+ var __accessCheck = (obj, member, msg) => {
2
+ if (!member.has(obj))
3
+ throw TypeError("Cannot " + msg);
4
+ };
5
+ var __privateAdd = (obj, member, value) => {
6
+ if (member.has(obj))
7
+ throw TypeError("Cannot add the same private member more than once");
8
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
9
+ };
10
+ var __privateMethod = (obj, member, method) => {
11
+ __accessCheck(obj, member, "access private method");
12
+ return method;
13
+ };
14
+
15
+ // node_modules/openapi-fetch/dist/index.js
16
+ var DEFAULT_HEADERS = {
17
+ "Content-Type": "application/json"
18
+ };
19
+ var TRAILING_SLASH_RE = /\/*$/;
20
+ function defaultQuerySerializer(q) {
21
+ const search = new URLSearchParams();
22
+ if (q && typeof q === "object") {
23
+ for (const [k, v] of Object.entries(q)) {
24
+ if (v === void 0 || v === null)
25
+ continue;
26
+ search.set(k, v);
27
+ }
28
+ }
29
+ return search.toString();
30
+ }
31
+ function defaultBodySerializer(body) {
32
+ return JSON.stringify(body);
33
+ }
34
+ function createFinalURL(url, options) {
35
+ let finalURL = `${options.baseUrl ? options.baseUrl.replace(TRAILING_SLASH_RE, "") : ""}${url}`;
36
+ if (options.params.path) {
37
+ for (const [k, v] of Object.entries(options.params.path))
38
+ finalURL = finalURL.replace(`{${k}}`, encodeURIComponent(String(v)));
39
+ }
40
+ if (options.params.query) {
41
+ const search = options.querySerializer(options.params.query);
42
+ if (search)
43
+ finalURL += `?${search}`;
44
+ }
45
+ return finalURL;
46
+ }
47
+ function createClient(clientOptions = {}) {
48
+ const { fetch = globalThis.fetch, querySerializer: globalQuerySerializer, bodySerializer: globalBodySerializer, ...options } = clientOptions;
49
+ const defaultHeaders = new Headers({
50
+ ...DEFAULT_HEADERS,
51
+ ...options.headers ?? {}
52
+ });
53
+ async function coreFetch(url, fetchOptions) {
54
+ const { headers, body: requestBody, params = {}, parseAs = "json", querySerializer = globalQuerySerializer ?? defaultQuerySerializer, bodySerializer = globalBodySerializer ?? defaultBodySerializer, ...init } = fetchOptions || {};
55
+ const finalURL = createFinalURL(url, { baseUrl: options.baseUrl, params, querySerializer });
56
+ const baseHeaders = new Headers(defaultHeaders);
57
+ const headerOverrides = new Headers(headers);
58
+ for (const [k, v] of headerOverrides.entries()) {
59
+ if (v === void 0 || v === null)
60
+ baseHeaders.delete(k);
61
+ else
62
+ baseHeaders.set(k, v);
63
+ }
64
+ const requestInit = {
65
+ redirect: "follow",
66
+ ...options,
67
+ ...init,
68
+ headers: baseHeaders
69
+ };
70
+ if (requestBody)
71
+ requestInit.body = bodySerializer(requestBody);
72
+ if (requestInit.body instanceof FormData)
73
+ baseHeaders.delete("Content-Type");
74
+ const response = await fetch(finalURL, requestInit);
75
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
76
+ return response.ok ? { data: {}, response } : { error: {}, response };
77
+ }
78
+ if (response.ok) {
79
+ let data = response.body;
80
+ if (parseAs !== "stream") {
81
+ const cloned = response.clone();
82
+ data = typeof cloned[parseAs] === "function" ? await cloned[parseAs]() : await cloned.text();
83
+ }
84
+ return { data, response };
85
+ }
86
+ let error = {};
87
+ try {
88
+ error = await response.clone().json();
89
+ } catch {
90
+ error = await response.clone().text();
91
+ }
92
+ return { error, response };
93
+ }
94
+ return {
95
+ /** Call a GET endpoint */
96
+ async get(url, init) {
97
+ return coreFetch(url, { ...init, method: "GET" });
98
+ },
99
+ /** Call a PUT endpoint */
100
+ async put(url, init) {
101
+ return coreFetch(url, { ...init, method: "PUT" });
102
+ },
103
+ /** Call a POST endpoint */
104
+ async post(url, init) {
105
+ return coreFetch(url, { ...init, method: "POST" });
106
+ },
107
+ /** Call a DELETE endpoint */
108
+ async del(url, init) {
109
+ return coreFetch(url, { ...init, method: "DELETE" });
110
+ },
111
+ /** Call a OPTIONS endpoint */
112
+ async options(url, init) {
113
+ return coreFetch(url, { ...init, method: "OPTIONS" });
114
+ },
115
+ /** Call a HEAD endpoint */
116
+ async head(url, init) {
117
+ return coreFetch(url, { ...init, method: "HEAD" });
118
+ },
119
+ /** Call a PATCH endpoint */
120
+ async patch(url, init) {
121
+ return coreFetch(url, { ...init, method: "PATCH" });
122
+ },
123
+ /** Call a TRACE endpoint */
124
+ async trace(url, init) {
125
+ return coreFetch(url, { ...init, method: "TRACE" });
126
+ }
127
+ };
128
+ }
129
+
130
+ // src/api/consts.ts
131
+ var SUPABASE_API_URL = "https://api.supabase.com";
132
+
133
+ // src/index.ts
134
+ var SupabaseManagementAPIError = class extends Error {
135
+ constructor(message, response) {
136
+ super(message);
137
+ this.response = response;
138
+ }
139
+ };
140
+ function isSupabaseError(error) {
141
+ return error instanceof SupabaseManagementAPIError;
142
+ }
143
+ var _createResponseError, createResponseError_fn;
144
+ var SupabaseManagementAPI = class {
145
+ constructor(options) {
146
+ this.options = options;
147
+ __privateAdd(this, _createResponseError);
148
+ }
149
+ /**
150
+ * List all organizations
151
+ * @description Returns a list of organizations that you currently belong to.
152
+ */
153
+ async getOrganizations() {
154
+ const { data, response } = await this.client.get("/v1/organizations", {});
155
+ if (response.status !== 200) {
156
+ throw new SupabaseManagementAPIError(
157
+ `Failed to get organizations: ${response.statusText} (${response.status})`,
158
+ response
159
+ );
160
+ }
161
+ return data;
162
+ }
163
+ /** Create an organization */
164
+ async createOrganization(body) {
165
+ const { data, response } = await this.client.post("/v1/organizations", {
166
+ body
167
+ });
168
+ if (response.status !== 201) {
169
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "create organization");
170
+ }
171
+ return data;
172
+ }
173
+ /**
174
+ * Get database branch config
175
+ * @description Fetches configurations of the specified database branch
176
+ */
177
+ async getBranchDetails(branchId) {
178
+ const { data, response } = await this.client.get(
179
+ "/v1/branches/{branch_id}",
180
+ {
181
+ params: {
182
+ path: {
183
+ branch_id: branchId
184
+ }
185
+ }
186
+ }
187
+ );
188
+ if (response.status !== 200) {
189
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "get branch details");
190
+ }
191
+ return data;
192
+ }
193
+ async deleteBranch(branchId) {
194
+ const { response } = await this.client.del("/v1/branches/{branch_id}", {
195
+ params: {
196
+ path: {
197
+ branch_id: branchId
198
+ }
199
+ }
200
+ });
201
+ if (response.status !== 200) {
202
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "delete branch");
203
+ }
204
+ }
205
+ async updateBranch(branchId, body) {
206
+ const { data, response } = await this.client.patch(
207
+ "/v1/branches/{branch_id}",
208
+ {
209
+ params: {
210
+ path: {
211
+ branch_id: branchId
212
+ }
213
+ },
214
+ body
215
+ }
216
+ );
217
+ if (response.status !== 200) {
218
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "update branch");
219
+ }
220
+ return data;
221
+ }
222
+ /**
223
+ * List all projects
224
+ * @description Returns a list of all projects you've previously created.
225
+ */
226
+ async getProjects() {
227
+ const { data, response } = await this.client.get("/v1/projects", {});
228
+ if (response.status !== 200) {
229
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "get projects");
230
+ }
231
+ return data;
232
+ }
233
+ /** Create a project */
234
+ async createProject(body) {
235
+ const { data, response } = await this.client.post("/v1/projects", {
236
+ body
237
+ });
238
+ if (response.status !== 201) {
239
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "create project");
240
+ }
241
+ return data;
242
+ }
243
+ /** Delete a project */
244
+ async deleteProject(ref) {
245
+ const { data, response } = await this.client.del("/v1/projects/{ref}", {
246
+ params: {
247
+ path: {
248
+ ref
249
+ }
250
+ }
251
+ });
252
+ if (response.status !== 200) {
253
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "delete project");
254
+ }
255
+ return data;
256
+ }
257
+ /**
258
+ * Check service health
259
+ * @description Checks the health of the specified service.
260
+ */
261
+ async checkServiceHealth(ref, query) {
262
+ const { data, response } = await this.client.get(
263
+ "/v1/projects/{ref}/health",
264
+ {
265
+ params: {
266
+ query,
267
+ path: {
268
+ ref
269
+ }
270
+ }
271
+ }
272
+ );
273
+ if (response.status !== 200) {
274
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "check service health");
275
+ }
276
+ return data;
277
+ }
278
+ /**
279
+ * List all functions
280
+ * @description Returns all functions you've previously added to the specified project.
281
+ */
282
+ async listFunctions(ref) {
283
+ const { data, response } = await this.client.get(
284
+ "/v1/projects/{ref}/functions",
285
+ {
286
+ params: {
287
+ path: {
288
+ ref
289
+ }
290
+ }
291
+ }
292
+ );
293
+ if (response.status !== 200) {
294
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "list functions");
295
+ }
296
+ return data;
297
+ }
298
+ /**
299
+ * Create a function
300
+ * @description Creates a function and adds it to the specified project.
301
+ */
302
+ async createFunction(ref, body) {
303
+ const { data, response } = await this.client.post(
304
+ "/v1/projects/{ref}/functions",
305
+ {
306
+ params: {
307
+ path: {
308
+ ref
309
+ }
310
+ },
311
+ body
312
+ }
313
+ );
314
+ if (response.status !== 201) {
315
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "create function");
316
+ }
317
+ return data;
318
+ }
319
+ /**
320
+ * Deploy function
321
+ * @description Deploys a function and adds it to the specified project.
322
+ */
323
+ async deployFunction(ref, body) {
324
+ const { data, response } = await this.client.post(
325
+ "/v1/projects/{ref}/functions/deploy",
326
+ {
327
+ params: {
328
+ path: {
329
+ ref
330
+ }
331
+ },
332
+ body
333
+ }
334
+ );
335
+ if (response.status !== 201) {
336
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "create function");
337
+ }
338
+ return data;
339
+ }
340
+ /**
341
+ * Retrieve a function
342
+ * @description Retrieves a function with the specified slug and project.
343
+ */
344
+ async getFunction(ref, slug) {
345
+ const { data, response } = await this.client.get(
346
+ "/v1/projects/{ref}/functions/{function_slug}",
347
+ {
348
+ params: {
349
+ path: {
350
+ ref,
351
+ function_slug: slug
352
+ }
353
+ }
354
+ }
355
+ );
356
+ if (response.status !== 200) {
357
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "get function");
358
+ }
359
+ return data;
360
+ }
361
+ /**
362
+ * Update a function
363
+ * @description Updates a function with the specified slug and project.
364
+ */
365
+ async updateFunction(ref, slug, body) {
366
+ const { data, response } = await this.client.patch(
367
+ "/v1/projects/{ref}/functions/{function_slug}",
368
+ {
369
+ params: {
370
+ path: {
371
+ ref,
372
+ function_slug: slug
373
+ }
374
+ },
375
+ body
376
+ }
377
+ );
378
+ if (response.status !== 200) {
379
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "update function");
380
+ }
381
+ return data;
382
+ }
383
+ /**
384
+ * Delete a function
385
+ * @description Deletes a function with the specified slug from the specified project.
386
+ */
387
+ async deleteFunction(ref, slug) {
388
+ const { response } = await this.client.del(
389
+ "/v1/projects/{ref}/functions/{function_slug}",
390
+ {
391
+ params: {
392
+ path: {
393
+ ref,
394
+ function_slug: slug
395
+ }
396
+ }
397
+ }
398
+ );
399
+ if (response.status !== 200) {
400
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "delete function");
401
+ }
402
+ }
403
+ /**
404
+ * Retrieve a function body
405
+ * @description Retrieves a function body for the specified slug and project.
406
+ */
407
+ async getFunctionBody(ref, slug) {
408
+ const { data, response } = await this.client.get(
409
+ "/v1/projects/{ref}/functions/{function_slug}/body",
410
+ {
411
+ params: {
412
+ path: {
413
+ ref,
414
+ function_slug: slug
415
+ }
416
+ }
417
+ }
418
+ );
419
+ if (response.status !== 200) {
420
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "get function body");
421
+ }
422
+ return data;
423
+ }
424
+ async getProjectApiKeys(ref) {
425
+ const { data, response } = await this.client.get(
426
+ "/v1/projects/{ref}/api-keys",
427
+ {
428
+ params: {
429
+ path: {
430
+ ref
431
+ }
432
+ }
433
+ }
434
+ );
435
+ if (response.status !== 200) {
436
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "get project api keys");
437
+ }
438
+ return data;
439
+ }
440
+ /** Gets project's custom hostname config */
441
+ async getCustomHostnameConfig(ref) {
442
+ const { data, response } = await this.client.get(
443
+ "/v1/projects/{ref}/custom-hostname",
444
+ {
445
+ params: {
446
+ path: {
447
+ ref
448
+ }
449
+ }
450
+ }
451
+ );
452
+ if (response.status !== 200) {
453
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "get custom hostname");
454
+ }
455
+ return data;
456
+ }
457
+ /** Deletes a project's custom hostname configuration */
458
+ async removeCustomHostnameConfig(ref) {
459
+ const { response } = await this.client.del(
460
+ "/v1/projects/{ref}/custom-hostname",
461
+ {
462
+ params: {
463
+ path: {
464
+ ref
465
+ }
466
+ }
467
+ }
468
+ );
469
+ if (response.status !== 200) {
470
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "remove custom hostname config");
471
+ }
472
+ }
473
+ /** Updates project's custom hostname configuration */
474
+ async createCustomHostnameConfig(ref, body) {
475
+ const { data, response } = await this.client.post(
476
+ "/v1/projects/{ref}/custom-hostname/initialize",
477
+ {
478
+ params: {
479
+ path: {
480
+ ref
481
+ }
482
+ },
483
+ body
484
+ }
485
+ );
486
+ if (response.status !== 201) {
487
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "create custom hostname config");
488
+ }
489
+ return data;
490
+ }
491
+ /** Attempts to verify the DNS configuration for project's custom hostname configuration */
492
+ async reverifyCustomHostnameConfig(ref) {
493
+ const { data, response } = await this.client.post(
494
+ "/v1/projects/{ref}/custom-hostname/reverify",
495
+ {
496
+ params: {
497
+ path: {
498
+ ref
499
+ }
500
+ }
501
+ }
502
+ );
503
+ if (response.status !== 200) {
504
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "reverify custom hostname config");
505
+ }
506
+ return data;
507
+ }
508
+ /** Activates a custom hostname for a project. */
509
+ async activateCustomHostnameConfig(ref) {
510
+ const { data, response } = await this.client.post(
511
+ "/v1/projects/{ref}/custom-hostname/activate",
512
+ {
513
+ params: {
514
+ path: {
515
+ ref
516
+ }
517
+ }
518
+ }
519
+ );
520
+ if (response.status !== 200) {
521
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "activate custom hostname config");
522
+ }
523
+ return data;
524
+ }
525
+ /** Gets project's network bans */
526
+ async getNetworkBans(ref) {
527
+ const { data, response } = await this.client.post(
528
+ "/v1/projects/{ref}/network-bans/retrieve",
529
+ {
530
+ params: {
531
+ path: {
532
+ ref
533
+ }
534
+ }
535
+ }
536
+ );
537
+ if (response.status !== 200) {
538
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "get network bans");
539
+ }
540
+ return data;
541
+ }
542
+ /** Remove network bans. */
543
+ async removeNetworkBan(ref, body) {
544
+ const { response } = await this.client.del(
545
+ "/v1/projects/{ref}/network-bans",
546
+ {
547
+ params: {
548
+ path: {
549
+ ref
550
+ }
551
+ },
552
+ body
553
+ }
554
+ );
555
+ if (response.status !== 200) {
556
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "remove network ban");
557
+ }
558
+ }
559
+ /** Gets project's network restrictions */
560
+ async getNetworkRestrictions(ref) {
561
+ const { data, response } = await this.client.get(
562
+ "/v1/projects/{ref}/network-restrictions",
563
+ {
564
+ params: {
565
+ path: {
566
+ ref
567
+ }
568
+ }
569
+ }
570
+ );
571
+ if (response.status !== 200) {
572
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "get network restrictions");
573
+ }
574
+ return data;
575
+ }
576
+ /** Updates project's network restrictions */
577
+ async applyNetworkRestrictions(ref, body) {
578
+ const { data, response } = await this.client.post(
579
+ "/v1/projects/{ref}/network-restrictions/apply",
580
+ {
581
+ params: {
582
+ path: {
583
+ ref
584
+ }
585
+ },
586
+ body
587
+ }
588
+ );
589
+ if (response.status !== 200) {
590
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "apply network restrictions");
591
+ }
592
+ return data;
593
+ }
594
+ /** Gets project's pgsodium config */
595
+ async getPgsodiumConfig(ref) {
596
+ const { data, response } = await this.client.get(
597
+ "/v1/projects/{ref}/pgsodium",
598
+ {
599
+ params: {
600
+ path: {
601
+ ref
602
+ }
603
+ }
604
+ }
605
+ );
606
+ if (response.status !== 200) {
607
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "get pg sodium config");
608
+ }
609
+ return data;
610
+ }
611
+ /** Updates project's pgsodium config. Updating the root_key can cause all data encrypted with the older key to become inaccessible. */
612
+ async updatePgSodiumConfig(ref, body) {
613
+ const { data, response } = await this.client.put(
614
+ "/v1/projects/{ref}/pgsodium",
615
+ {
616
+ params: {
617
+ path: {
618
+ ref
619
+ }
620
+ },
621
+ body
622
+ }
623
+ );
624
+ if (response.status !== 200) {
625
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "update pg sodium config");
626
+ }
627
+ return data;
628
+ }
629
+ /** Gets project's postgrest config */
630
+ async getPostgRESTConfig(ref) {
631
+ const { data, response } = await this.client.get(
632
+ "/v1/projects/{ref}/postgrest",
633
+ {
634
+ params: {
635
+ path: {
636
+ ref
637
+ }
638
+ }
639
+ }
640
+ );
641
+ if (response.status !== 200) {
642
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "get postgrest config");
643
+ }
644
+ return data;
645
+ }
646
+ /** Updates project's postgrest config */
647
+ async updatePostgRESTConfig(ref, body) {
648
+ const { data, response } = await this.client.patch(
649
+ "/v1/projects/{ref}/postgrest",
650
+ {
651
+ params: {
652
+ path: {
653
+ ref
654
+ }
655
+ },
656
+ body
657
+ }
658
+ );
659
+ if (response.status !== 200) {
660
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "update postgrest config");
661
+ }
662
+ return data;
663
+ }
664
+ /** Run sql query */
665
+ async runQuery(ref, query) {
666
+ const { data, response } = await this.client.post(
667
+ "/v1/projects/{ref}/database/query",
668
+ {
669
+ params: {
670
+ path: {
671
+ ref
672
+ }
673
+ },
674
+ body: {
675
+ query
676
+ }
677
+ }
678
+ );
679
+ if (response.status !== 201 && response.status !== 200) {
680
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "run query");
681
+ }
682
+ return data;
683
+ }
684
+ async enableWebhooks(ref) {
685
+ const { data, response } = await this.client.post(
686
+ "/v1/projects/{ref}/database/webhooks/enable",
687
+ {
688
+ params: {
689
+ path: {
690
+ ref
691
+ }
692
+ }
693
+ }
694
+ );
695
+ if (response.status !== 201) {
696
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "enable webhooks");
697
+ }
698
+ }
699
+ /**
700
+ * List all secrets
701
+ * @description Returns all secrets you've previously added to the specified project.
702
+ */
703
+ async getSecrets(ref) {
704
+ const { data, response } = await this.client.get(
705
+ "/v1/projects/{ref}/secrets",
706
+ {
707
+ params: {
708
+ path: {
709
+ ref
710
+ }
711
+ }
712
+ }
713
+ );
714
+ if (response.status !== 200) {
715
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "get secrets");
716
+ }
717
+ return data;
718
+ }
719
+ /**
720
+ * Bulk create secrets
721
+ * @description Creates multiple secrets and adds them to the specified project.
722
+ */
723
+ async createSecrets(ref, body) {
724
+ const { response } = await this.client.post("/v1/projects/{ref}/secrets", {
725
+ params: {
726
+ path: {
727
+ ref
728
+ }
729
+ },
730
+ body
731
+ });
732
+ if (response.status !== 201) {
733
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "create secrets");
734
+ }
735
+ }
736
+ /**
737
+ * Bulk delete secrets
738
+ * @description Deletes all secrets with the given names from the specified project
739
+ */
740
+ async deleteSecrets(ref, body) {
741
+ const { data, response } = await this.client.del(
742
+ "/v1/projects/{ref}/secrets",
743
+ {
744
+ params: {
745
+ path: {
746
+ ref
747
+ }
748
+ },
749
+ body
750
+ }
751
+ );
752
+ if (response.status !== 200) {
753
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "delete secrets");
754
+ }
755
+ return data;
756
+ }
757
+ /** Get project's SSL enforcement configuration. */
758
+ async getSSLEnforcementConfig(ref) {
759
+ const { data, response } = await this.client.get(
760
+ "/v1/projects/{ref}/ssl-enforcement",
761
+ {
762
+ params: {
763
+ path: {
764
+ ref
765
+ }
766
+ }
767
+ }
768
+ );
769
+ if (response.status !== 200) {
770
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "get ssl enforcement config");
771
+ }
772
+ return data;
773
+ }
774
+ /** Update project's SSL enforcement configuration. */
775
+ async updateSSLEnforcementConfig(ref, body) {
776
+ const { data, response } = await this.client.put(
777
+ "/v1/projects/{ref}/ssl-enforcement",
778
+ {
779
+ params: {
780
+ path: {
781
+ ref
782
+ }
783
+ },
784
+ body
785
+ }
786
+ );
787
+ if (response.status !== 200) {
788
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "update ssl enforcement config");
789
+ }
790
+ return data;
791
+ }
792
+ /**
793
+ * Generate TypeScript types
794
+ * @description Returns the TypeScript types of your schema for use with supabase-js.
795
+ */
796
+ async getTypescriptTypes(ref) {
797
+ const { data, response } = await this.client.get(
798
+ "/v1/projects/{ref}/types/typescript",
799
+ {
800
+ params: {
801
+ path: {
802
+ ref
803
+ }
804
+ }
805
+ }
806
+ );
807
+ if (response.status !== 200) {
808
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "get typescript types");
809
+ }
810
+ return data;
811
+ }
812
+ /** Gets current vanity subdomain config */
813
+ async getVanitySubdomainConfig(ref) {
814
+ const { data, response } = await this.client.get(
815
+ "/v1/projects/{ref}/vanity-subdomain",
816
+ {
817
+ params: {
818
+ path: {
819
+ ref
820
+ }
821
+ }
822
+ }
823
+ );
824
+ if (response.status !== 200) {
825
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "get vanity subdomain config");
826
+ }
827
+ return data;
828
+ }
829
+ /** Deletes a project's vanity subdomain configuration */
830
+ async removeVanitySubdomainConfig(ref) {
831
+ const { response } = await this.client.del(
832
+ "/v1/projects/{ref}/vanity-subdomain",
833
+ {
834
+ params: {
835
+ path: {
836
+ ref
837
+ }
838
+ }
839
+ }
840
+ );
841
+ if (response.status !== 200) {
842
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "remove vanity subdomain config");
843
+ }
844
+ }
845
+ /** Checks vanity subdomain availability */
846
+ async checkVanitySubdomainAvailability(ref, subdomain) {
847
+ const { data, response } = await this.client.post(
848
+ "/v1/projects/{ref}/vanity-subdomain/check-availability",
849
+ {
850
+ params: {
851
+ path: {
852
+ ref
853
+ }
854
+ },
855
+ body: {
856
+ vanity_subdomain: subdomain
857
+ }
858
+ }
859
+ );
860
+ if (response.status !== 200) {
861
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "check vanity subdomain availability");
862
+ }
863
+ return typeof data === "undefined" ? false : data.available;
864
+ }
865
+ /** Activates a vanity subdomain for a project. */
866
+ async activateVanitySubdomainPlease(ref, subdomain) {
867
+ const { response, data } = await this.client.post(
868
+ "/v1/projects/{ref}/vanity-subdomain/activate",
869
+ {
870
+ params: {
871
+ path: {
872
+ ref
873
+ }
874
+ },
875
+ body: {
876
+ vanity_subdomain: subdomain
877
+ }
878
+ }
879
+ );
880
+ if (response.status !== 200) {
881
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "activate vanity subdomain");
882
+ }
883
+ return data?.custom_domain;
884
+ }
885
+ /** Upgrades the project's Postgres version */
886
+ async upgradeProject(ref, targetVersion) {
887
+ const { response } = await this.client.post("/v1/projects/{ref}/upgrade", {
888
+ params: {
889
+ path: {
890
+ ref
891
+ }
892
+ },
893
+ body: {
894
+ target_version: targetVersion
895
+ }
896
+ });
897
+ if (response.status !== 200) {
898
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "upgrade project");
899
+ }
900
+ }
901
+ /** Returns the project's eligibility for upgrades */
902
+ async getUpgradeEligibility(ref) {
903
+ const { data, response } = await this.client.get(
904
+ "/v1/projects/{ref}/upgrade/eligibility",
905
+ {
906
+ params: {
907
+ path: {
908
+ ref
909
+ }
910
+ }
911
+ }
912
+ );
913
+ if (response.status !== 200) {
914
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "get upgrade eligibility");
915
+ }
916
+ return data;
917
+ }
918
+ /** Gets the latest status of the project's upgrade */
919
+ async getUpgradeStatus(ref) {
920
+ const { data, response } = await this.client.get(
921
+ "/v1/projects/{ref}/upgrade/status",
922
+ {
923
+ params: {
924
+ path: {
925
+ ref
926
+ }
927
+ }
928
+ }
929
+ );
930
+ if (response.status !== 200) {
931
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "get upgrade status");
932
+ }
933
+ return data;
934
+ }
935
+ /** Returns project's readonly mode status */
936
+ async getReadOnlyModeStatus(ref) {
937
+ const { data, response } = await this.client.get(
938
+ "/v1/projects/{ref}/readonly",
939
+ {
940
+ params: {
941
+ path: {
942
+ ref
943
+ }
944
+ }
945
+ }
946
+ );
947
+ if (response.status !== 200) {
948
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "get readonly mode status");
949
+ }
950
+ return data;
951
+ }
952
+ /** Disables project's readonly mode for the next 15 minutes */
953
+ async temporarilyDisableReadonlyMode(ref) {
954
+ const { response } = await this.client.post(
955
+ "/v1/projects/{ref}/readonly/temporary-disable",
956
+ {
957
+ params: {
958
+ path: {
959
+ ref
960
+ }
961
+ }
962
+ }
963
+ );
964
+ if (response.status !== 200) {
965
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "temporarily disable readonly mode");
966
+ }
967
+ }
968
+ /** Gets project's Postgres config */
969
+ async getPGConfig(ref) {
970
+ const { data, response } = await this.client.get(
971
+ "/v1/projects/{ref}/config/database/postgres",
972
+ {
973
+ params: {
974
+ path: {
975
+ ref
976
+ }
977
+ }
978
+ }
979
+ );
980
+ if (response.status !== 200) {
981
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "get PG config");
982
+ }
983
+ return data;
984
+ }
985
+ /** Updates project's Postgres config */
986
+ async updatePGConfig(ref, body) {
987
+ const { data, response } = await this.client.put(
988
+ "/v1/projects/{ref}/config/database/postgres",
989
+ {
990
+ params: {
991
+ path: {
992
+ ref
993
+ }
994
+ },
995
+ body
996
+ }
997
+ );
998
+ if (response.status !== 200) {
999
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "update PG config");
1000
+ }
1001
+ return data;
1002
+ }
1003
+ /** Gets project's pgbouncer config */
1004
+ async getPgBouncerConfig(ref) {
1005
+ const { data, response } = await this.client.get(
1006
+ "/v1/projects/{ref}/config/database/pgbouncer",
1007
+ {
1008
+ params: {
1009
+ path: {
1010
+ ref
1011
+ }
1012
+ }
1013
+ }
1014
+ );
1015
+ if (response.status !== 200) {
1016
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "get Pgbouncer config");
1017
+ }
1018
+ return data;
1019
+ }
1020
+ /** Gets project's auth config */
1021
+ async getProjectAuthConfig(ref) {
1022
+ const { data, response } = await this.client.get(
1023
+ "/v1/projects/{ref}/config/auth",
1024
+ {
1025
+ params: {
1026
+ path: {
1027
+ ref
1028
+ }
1029
+ }
1030
+ }
1031
+ );
1032
+ if (response.status !== 200) {
1033
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "get project auth config");
1034
+ }
1035
+ return data;
1036
+ }
1037
+ /** Updates a project's auth config */
1038
+ async updateProjectAuthConfig(ref, body) {
1039
+ const { data, response } = await this.client.patch(
1040
+ "/v1/projects/{ref}/config/auth",
1041
+ {
1042
+ params: {
1043
+ path: {
1044
+ ref
1045
+ }
1046
+ },
1047
+ body
1048
+ }
1049
+ );
1050
+ if (response.status !== 200) {
1051
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "update project auth config");
1052
+ }
1053
+ return data;
1054
+ }
1055
+ /** Lists all SSO providers */
1056
+ async getSSOProviders(ref) {
1057
+ const { data, response } = await this.client.get(
1058
+ "/v1/projects/{ref}/config/auth/sso/providers",
1059
+ {
1060
+ params: {
1061
+ path: {
1062
+ ref
1063
+ }
1064
+ }
1065
+ }
1066
+ );
1067
+ if (response.status !== 200) {
1068
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "get SSO providers");
1069
+ }
1070
+ return data;
1071
+ }
1072
+ /** Creates a new SSO provider */
1073
+ async createSSOProvider(ref, body) {
1074
+ const { data, response } = await this.client.post(
1075
+ "/v1/projects/{ref}/config/auth/sso/providers",
1076
+ {
1077
+ params: {
1078
+ path: {
1079
+ ref
1080
+ }
1081
+ },
1082
+ body
1083
+ }
1084
+ );
1085
+ if (response.status !== 201) {
1086
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "create SSO provider");
1087
+ }
1088
+ return data;
1089
+ }
1090
+ /** Gets a SSO provider by its UUID */
1091
+ async getSSOProvider(ref, uuid) {
1092
+ const { data, response } = await this.client.get(
1093
+ "/v1/projects/{ref}/config/auth/sso/providers/{provider_id}",
1094
+ {
1095
+ params: {
1096
+ path: {
1097
+ ref,
1098
+ provider_id: uuid
1099
+ }
1100
+ }
1101
+ }
1102
+ );
1103
+ if (response.status !== 200) {
1104
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "get SSO provider");
1105
+ }
1106
+ return data;
1107
+ }
1108
+ /** Updates a SSO provider by its UUID */
1109
+ async updateSSOProvider(ref, uuid, body) {
1110
+ const { data, response } = await this.client.put(
1111
+ "/v1/projects/{ref}/config/auth/sso/providers/{provider_id}",
1112
+ {
1113
+ params: {
1114
+ path: {
1115
+ ref,
1116
+ provider_id: uuid
1117
+ }
1118
+ },
1119
+ body
1120
+ }
1121
+ );
1122
+ if (response.status !== 200) {
1123
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "update SSO provider");
1124
+ }
1125
+ return data;
1126
+ }
1127
+ /** Removes a SSO provider by its UUID */
1128
+ async deleteSSOProvider(ref, uuid) {
1129
+ const { response } = await this.client.del(
1130
+ "/v1/projects/{ref}/config/auth/sso/providers/{provider_id}",
1131
+ {
1132
+ params: {
1133
+ path: {
1134
+ ref,
1135
+ provider_id: uuid
1136
+ }
1137
+ }
1138
+ }
1139
+ );
1140
+ if (response.status !== 204) {
1141
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "delete SSO provider");
1142
+ }
1143
+ }
1144
+ /** List snippets */
1145
+ async listSnippets(projectRef) {
1146
+ const { data, response } = await this.client.get("/v1/snippets", {
1147
+ params: {
1148
+ query: {
1149
+ project_ref: projectRef
1150
+ }
1151
+ }
1152
+ });
1153
+ if (response.status !== 200) {
1154
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "list snippets");
1155
+ }
1156
+ return data;
1157
+ }
1158
+ async getSnippet(id) {
1159
+ const { data, response } = await this.client.get("/v1/snippets/{id}", {
1160
+ params: {
1161
+ path: {
1162
+ id
1163
+ }
1164
+ }
1165
+ });
1166
+ if (response.status !== 200) {
1167
+ throw await __privateMethod(this, _createResponseError, createResponseError_fn).call(this, response, "get snippet");
1168
+ }
1169
+ return data;
1170
+ }
1171
+ get client() {
1172
+ return createClient({
1173
+ baseUrl: this.options.baseUrl || SUPABASE_API_URL,
1174
+ headers: {
1175
+ Authorization: `Bearer ${this.options.accessToken}`
1176
+ }
1177
+ });
1178
+ }
1179
+ };
1180
+ _createResponseError = new WeakSet();
1181
+ createResponseError_fn = async function(response, action) {
1182
+ const errorBody = await safeParseErrorResponseBody(response);
1183
+ return new SupabaseManagementAPIError(
1184
+ `Failed to ${action}: ${response.statusText} (${response.status})${errorBody ? `: ${errorBody.message}` : ""}`,
1185
+ response
1186
+ );
1187
+ };
1188
+ async function safeParseErrorResponseBody(response) {
1189
+ try {
1190
+ const body = await response.json();
1191
+ if (typeof body === "object" && body !== null && "message" in body && typeof body.message === "string") {
1192
+ return { message: body.message };
1193
+ }
1194
+ } catch (error) {
1195
+ return;
1196
+ }
1197
+ }
1198
+
1199
+ export { SupabaseManagementAPI, SupabaseManagementAPIError, isSupabaseError };
1200
+ //# sourceMappingURL=out.js.map
1201
+ //# sourceMappingURL=index.mjs.map