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