@giaeulate/baas-sdk 1.1.1 → 1.3.0

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,1956 @@
1
+ // src/http-client.ts
2
+ var HttpClient = class {
3
+ url;
4
+ apiKey = "";
5
+ keyType;
6
+ token = null;
7
+ environment = "prod";
8
+ _onForceLogout = null;
9
+ constructor(url, apiKey, options) {
10
+ let baseUrl = url || (typeof window !== "undefined" ? window.location.origin : "http://localhost:8080");
11
+ this.url = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
12
+ if (apiKey) this.apiKey = apiKey;
13
+ this.keyType = options?.keyType ?? "service_role";
14
+ this.warnIfUnsafeKey();
15
+ this.token = typeof localStorage !== "undefined" ? this.cleanValue(localStorage.getItem("baas_token")) : null;
16
+ }
17
+ /** SECURITY: a service_role key bypasses RLS and grants admin over every
18
+ * tenant. If it ends up in a browser bundle, anyone can extract it. Warn
19
+ * loudly when a non-anon key is constructed in a browser context. */
20
+ warnIfUnsafeKey() {
21
+ const inBrowser = typeof window !== "undefined" && typeof document !== "undefined";
22
+ if (inBrowser && this.apiKey && this.keyType !== "anon") {
23
+ console.warn(
24
+ '[baas-sdk] SECURITY WARNING: a non-anon (service_role) key is running in a browser. It bypasses Row-Level Security and grants admin over ALL tenants, and is extractable from the bundle. Mint an anon key in the dashboard and construct the client with { keyType: "anon" }.'
25
+ );
26
+ }
27
+ }
28
+ /**
29
+ * Set the auth token manually (e.g. restoring from SecureStore in React Native).
30
+ * Persists to both the in-memory property and localStorage so getDynamicToken() works.
31
+ */
32
+ setToken(token) {
33
+ this.token = token;
34
+ if (token) {
35
+ localStorage.setItem("baas_token", token);
36
+ } else {
37
+ localStorage.removeItem("baas_token");
38
+ }
39
+ }
40
+ /**
41
+ * Register a callback invoked on forced logout (401).
42
+ * Use this in React Native instead of the default window.location redirect.
43
+ */
44
+ onForceLogout(callback) {
45
+ this._onForceLogout = callback;
46
+ }
47
+ cleanValue(val) {
48
+ if (!val || val === "null" || val === "undefined") return null;
49
+ return val.trim();
50
+ }
51
+ /**
52
+ * Public header generator for adapters
53
+ */
54
+ getHeaders(contentType = "application/json") {
55
+ const dynamicToken = this.getDynamicToken();
56
+ const headers = {
57
+ "apikey": this.apiKey
58
+ };
59
+ if (contentType) {
60
+ headers["Content-Type"] = contentType;
61
+ }
62
+ if (dynamicToken) {
63
+ headers["Authorization"] = `Bearer ${dynamicToken}`;
64
+ }
65
+ if (this.environment && this.environment !== "prod") {
66
+ headers["X-Environment"] = this.environment;
67
+ }
68
+ const csrfToken = this.getCSRFToken();
69
+ if (csrfToken) {
70
+ headers["X-CSRF-Token"] = csrfToken;
71
+ }
72
+ return headers;
73
+ }
74
+ getDynamicToken() {
75
+ return this.cleanValue(this.token || localStorage.getItem("baas_token"));
76
+ }
77
+ /**
78
+ * Core HTTP request method - DRY principle
79
+ */
80
+ async request(endpoint, options = {}) {
81
+ const { method = "GET", body, headers: customHeaders, skipAuth = false } = options;
82
+ const headers = { ...this.getHeaders(), ...customHeaders };
83
+ const fetchOptions = {
84
+ method,
85
+ headers,
86
+ credentials: "include"
87
+ };
88
+ if (body !== void 0) {
89
+ fetchOptions.body = JSON.stringify(body);
90
+ }
91
+ const res = await fetch(`${this.url}${endpoint}`, fetchOptions);
92
+ if (res.status === 204) {
93
+ return { success: true };
94
+ }
95
+ const data = await res.json().catch(() => null);
96
+ if (!res.ok) {
97
+ if (res.status === 401 && !skipAuth) {
98
+ this.forceLogout();
99
+ }
100
+ if (res.status === 403 && data?.error === "ip_not_allowed") {
101
+ this.handleIPBlocked(data.ip);
102
+ }
103
+ const rateLimited = res.status === 429;
104
+ const retryHint = res.headers.get("retry-after") || res.headers.get("x-ratelimit-reset");
105
+ return {
106
+ error: data?.error || `Request failed: ${res.status}`,
107
+ status: res.status,
108
+ ...rateLimited ? { rateLimited: true, retryAfter: retryHint ? parseInt(retryHint, 10) : void 0 } : {},
109
+ ...data
110
+ };
111
+ }
112
+ return data;
113
+ }
114
+ get(endpoint) {
115
+ return this.request(endpoint);
116
+ }
117
+ post(endpoint, body) {
118
+ return this.request(endpoint, { method: "POST", body });
119
+ }
120
+ put(endpoint, body) {
121
+ return this.request(endpoint, { method: "PUT", body });
122
+ }
123
+ patch(endpoint, body) {
124
+ return this.request(endpoint, { method: "PATCH", body });
125
+ }
126
+ delete(endpoint) {
127
+ return this.request(endpoint, { method: "DELETE" });
128
+ }
129
+ getCSRFToken() {
130
+ if (typeof document === "undefined") return null;
131
+ const match = document.cookie.match(/(?:^|;\s*)csrf_token=([^;]*)/);
132
+ return match ? decodeURIComponent(match[1]) : null;
133
+ }
134
+ setEnvironment(env) {
135
+ this.environment = env;
136
+ }
137
+ getEnvironment() {
138
+ return this.environment;
139
+ }
140
+ logout() {
141
+ this.token = null;
142
+ localStorage.removeItem("baas_token");
143
+ }
144
+ forceLogout() {
145
+ this.logout();
146
+ if (this._onForceLogout) {
147
+ this._onForceLogout();
148
+ return;
149
+ }
150
+ if (typeof window !== "undefined" && window.location && window.location.search !== void 0) {
151
+ if (!window.location.search.includes("expired")) {
152
+ window.location.href = "/authentication/login?reason=expired";
153
+ }
154
+ }
155
+ }
156
+ handleIPBlocked(ip) {
157
+ if (typeof window !== "undefined") {
158
+ const params = ip ? `?ip=${encodeURIComponent(ip)}` : "";
159
+ if (!window.location.pathname.includes("/blocked")) {
160
+ window.location.href = `/blocked${params}`;
161
+ }
162
+ }
163
+ }
164
+ };
165
+
166
+ // src/query-builder.ts
167
+ var QueryBuilder = class {
168
+ table;
169
+ url;
170
+ client;
171
+ queryParams = new URLSearchParams();
172
+ // @ts-ignore - used for future filter improvements
173
+ filters = [];
174
+ constructor(table, url, client) {
175
+ this.table = table;
176
+ this.url = url;
177
+ this.client = client;
178
+ }
179
+ select(columns = "*") {
180
+ this.queryParams.set("select", columns);
181
+ return this;
182
+ }
183
+ eq(column, value) {
184
+ this.queryParams.set(column, `eq.${value}`);
185
+ return this;
186
+ }
187
+ neq(column, value) {
188
+ this.queryParams.set(column, `neq.${value}`);
189
+ return this;
190
+ }
191
+ gt(column, value) {
192
+ this.queryParams.set(column, `gt.${value}`);
193
+ return this;
194
+ }
195
+ gte(column, value) {
196
+ this.queryParams.set(column, `gte.${value}`);
197
+ return this;
198
+ }
199
+ lt(column, value) {
200
+ this.queryParams.set(column, `lt.${value}`);
201
+ return this;
202
+ }
203
+ lte(column, value) {
204
+ this.queryParams.set(column, `lte.${value}`);
205
+ return this;
206
+ }
207
+ like(column, value) {
208
+ this.queryParams.set(column, `like.${value}`);
209
+ return this;
210
+ }
211
+ ilike(column, value) {
212
+ this.queryParams.set(column, `ilike.${value}`);
213
+ return this;
214
+ }
215
+ is(column, value) {
216
+ this.queryParams.set(column, `is.${value}`);
217
+ return this;
218
+ }
219
+ in(column, values) {
220
+ this.queryParams.set(column, `in.(${values.join(",")})`);
221
+ return this;
222
+ }
223
+ not(column, operator, value) {
224
+ this.queryParams.set(column, `not.${operator}.${value}`);
225
+ return this;
226
+ }
227
+ /** Array/jsonb/range contains (@>). Arrays become a `{a,b}` literal. */
228
+ contains(column, values) {
229
+ this.queryParams.set(column, `cs.${this.arrayLiteral(values)}`);
230
+ return this;
231
+ }
232
+ /** Array/jsonb/range contained-by (<@). */
233
+ containedBy(column, values) {
234
+ this.queryParams.set(column, `cd.${this.arrayLiteral(values)}`);
235
+ return this;
236
+ }
237
+ /** Array/range overlap (&&). */
238
+ overlaps(column, values) {
239
+ this.queryParams.set(column, `ov.${this.arrayLiteral(values)}`);
240
+ return this;
241
+ }
242
+ /** Full-text search (@@). type: fts|plfts|phfts|wfts (tsquery flavour). */
243
+ textSearch(column, query, type = "fts") {
244
+ this.queryParams.set(column, `${type}.${query}`);
245
+ return this;
246
+ }
247
+ arrayLiteral(values) {
248
+ return Array.isArray(values) ? `{${values.join(",")}}` : `${values}`;
249
+ }
250
+ /** OR group: `or=(c1,c2)`. Members are dotted `col.op.value` strings. */
251
+ or(filters) {
252
+ this.queryParams.set("or", `(${filters})`);
253
+ return this;
254
+ }
255
+ /** AND group: `and=(c1,c2)` — e.g. a range `qty.gt.5,qty.lt.20`. */
256
+ and(filters) {
257
+ this.queryParams.set("and", `(${filters})`);
258
+ return this;
259
+ }
260
+ /** Negated AND group: `not.and=(...)`. */
261
+ notAnd(filters) {
262
+ this.queryParams.set("not.and", `(${filters})`);
263
+ return this;
264
+ }
265
+ /** Negated OR group: `not.or=(...)`. */
266
+ notOr(filters) {
267
+ this.queryParams.set("not.or", `(${filters})`);
268
+ return this;
269
+ }
270
+ order(column, { ascending = true } = {}) {
271
+ this.queryParams.set("order", `${column}.${ascending ? "asc" : "desc"}`);
272
+ return this;
273
+ }
274
+ limit(count) {
275
+ this.queryParams.set("limit", count.toString());
276
+ return this;
277
+ }
278
+ offset(count) {
279
+ this.queryParams.set("offset", count.toString());
280
+ return this;
281
+ }
282
+ async get() {
283
+ const res = await fetch(`${this.url}/api/v1/data/${this.table}?${this.queryParams.toString()}`, {
284
+ headers: { ...this.getHeaders(), "Cache-Control": "no-cache" },
285
+ cache: "no-store"
286
+ });
287
+ return await this.handleResponse(res);
288
+ }
289
+ async insert(data) {
290
+ const res = await fetch(`${this.url}/api/v1/data/${this.table}`, {
291
+ method: "POST",
292
+ headers: this.getHeaders(),
293
+ body: JSON.stringify(data)
294
+ });
295
+ return await this.handleResponse(res);
296
+ }
297
+ async update(id, data) {
298
+ const res = await fetch(`${this.url}/api/v1/data/${this.table}/${id}`, {
299
+ method: "PATCH",
300
+ headers: this.getHeaders(),
301
+ body: JSON.stringify(data)
302
+ });
303
+ return await this.handleResponse(res);
304
+ }
305
+ async delete(id) {
306
+ const res = await fetch(`${this.url}/api/v1/data/${this.table}/${id}`, {
307
+ method: "DELETE",
308
+ headers: this.getHeaders()
309
+ });
310
+ if (res.status === 204) return { success: true };
311
+ return await this.handleResponse(res);
312
+ }
313
+ /** Insert-or-update on conflict. [onConflict] is the conflict-target column(s). */
314
+ async upsert(data, onConflict) {
315
+ const res = await fetch(`${this.url}/api/v1/data/${this.table}/upsert`, {
316
+ method: "POST",
317
+ headers: this.getHeaders(),
318
+ body: JSON.stringify({ ...data, on_conflict: onConflict })
319
+ });
320
+ return await this.handleResponse(res);
321
+ }
322
+ /**
323
+ * Count rows matching the current filters (PostgREST parity). Sends
324
+ * `Prefer: count=exact` and parses the total from the `Content-Range`
325
+ * response header. Returns `{ count, error, status }`.
326
+ */
327
+ async count() {
328
+ const res = await fetch(`${this.url}/api/v1/data/${this.table}?${this.queryParams.toString()}`, {
329
+ headers: { ...this.getHeaders(), Prefer: "count=exact", "Cache-Control": "no-cache" },
330
+ cache: "no-store"
331
+ });
332
+ if (!res.ok) {
333
+ if (res.status === 401) this.client.forceLogout();
334
+ const body = await res.json().catch(() => null);
335
+ return { count: 0, error: body?.error || "Request failed", status: res.status };
336
+ }
337
+ const cr = res.headers.get("content-range");
338
+ const total = cr && cr.includes("/") ? parseInt(cr.split("/").pop() || "", 10) : NaN;
339
+ return { count: Number.isNaN(total) ? 0 : total, error: null, status: res.status };
340
+ }
341
+ getHeaders() {
342
+ return this.client.getHeaders();
343
+ }
344
+ async handleResponse(res) {
345
+ const text = await res.text();
346
+ let data = null;
347
+ try {
348
+ data = text ? JSON.parse(text) : null;
349
+ } catch {
350
+ }
351
+ if (!res.ok) {
352
+ if (res.status === 401) {
353
+ this.client.forceLogout();
354
+ }
355
+ return { data: null, error: data?.error || "Request failed", status: res.status };
356
+ }
357
+ return { data, error: null, status: res.status };
358
+ }
359
+ };
360
+
361
+ // src/modules/auth.ts
362
+ function createAuthModule(client) {
363
+ const get = (endpoint) => client.get(endpoint);
364
+ const post = (endpoint, body) => client.post(endpoint, body);
365
+ return {
366
+ async login(email, password) {
367
+ const res = await fetch(`${client.url}/api/login`, {
368
+ method: "POST",
369
+ headers: client.getHeaders(),
370
+ body: JSON.stringify({ email, password })
371
+ });
372
+ const contentType = res.headers.get("content-type");
373
+ if (!contentType?.includes("application/json")) {
374
+ throw new Error(`Login failed: Server returned ${res.status}. Please check your connection.`);
375
+ }
376
+ const data = await res.json().catch(() => {
377
+ throw new Error(`Login failed: Invalid JSON response (status ${res.status})`);
378
+ });
379
+ if (!res.ok) {
380
+ throw new Error(data?.error || `Login failed: ${res.status}`);
381
+ }
382
+ if (data.token) {
383
+ client.token = data.token;
384
+ localStorage.setItem("baas_token", data.token);
385
+ }
386
+ return data;
387
+ },
388
+ async logout() {
389
+ try {
390
+ await post("/api/logout");
391
+ } finally {
392
+ client.token = null;
393
+ localStorage.removeItem("baas_token");
394
+ }
395
+ },
396
+ // Anonymous sign-in (Supabase parity). Response carries access_token (+ a
397
+ // back-compat `token`); store whichever is present.
398
+ async signInAnonymous() {
399
+ const data = await post("/api/auth/anonymous");
400
+ const tok = data?.access_token || data?.token;
401
+ if (tok) {
402
+ client.token = tok;
403
+ localStorage.setItem("baas_token", tok);
404
+ }
405
+ return data;
406
+ },
407
+ // Passwordless: request a magic link + 6-digit email OTP. Always resolves on
408
+ // a well-formed request (no account enumeration).
409
+ async requestOtp(email, createUser = true) {
410
+ return post("/api/auth/otp", { email, create_user: createUser });
411
+ },
412
+ // Verify a passwordless OTP/magic-link and complete sign-in.
413
+ async verifyOtp(type, email, token) {
414
+ const data = await post("/api/auth/verify", { type, email, token });
415
+ const tok = data?.access_token || data?.token;
416
+ if (tok) {
417
+ client.token = tok;
418
+ localStorage.setItem("baas_token", tok);
419
+ }
420
+ return data;
421
+ },
422
+ // Upgrade the current anonymous guest to a real account (preserves user id).
423
+ // Requires the anonymous Bearer to be set (call after signInAnonymous).
424
+ async upgradeAnonymous(email, password) {
425
+ const data = await post("/api/auth/upgrade", { email, password });
426
+ const tok = data?.access_token || data?.token;
427
+ if (tok) {
428
+ client.token = tok;
429
+ localStorage.setItem("baas_token", tok);
430
+ }
431
+ return data;
432
+ },
433
+ async verifyMFA(mfaToken, code) {
434
+ const data = await post("/api/mfa/finalize", { mfa_token: mfaToken, code });
435
+ if (data.token) {
436
+ client.token = data.token;
437
+ localStorage.setItem("baas_token", data.token);
438
+ }
439
+ return data;
440
+ },
441
+ async verifyMFAWithRecoveryCode(mfaToken, recoveryCode) {
442
+ const data = await post("/api/mfa/finalize", { mfa_token: mfaToken, recovery_code: recoveryCode });
443
+ if (data.token) {
444
+ client.token = data.token;
445
+ localStorage.setItem("baas_token", data.token);
446
+ }
447
+ return data;
448
+ },
449
+ async setupMFA() {
450
+ return post("/api/mfa/setup");
451
+ },
452
+ async enableMFA(secret, code, recoveryCodes) {
453
+ const body = { secret, code };
454
+ if (recoveryCodes) {
455
+ body.recovery_codes = recoveryCodes;
456
+ }
457
+ return post("/api/mfa/enable", body);
458
+ },
459
+ async disableMFA(code) {
460
+ return post("/api/mfa/disable", { code });
461
+ },
462
+ async getProfile() {
463
+ return get("/api/profile");
464
+ },
465
+ async register(email, password) {
466
+ const data = await post("/api/register", { email, password });
467
+ if (data.error) {
468
+ throw new Error(data.error);
469
+ }
470
+ return data;
471
+ },
472
+ async forgotPassword(email) {
473
+ return post("/api/auth/forgot-password", { email });
474
+ },
475
+ async resetPassword(token, newPassword) {
476
+ return post("/api/auth/reset-password", { token, new_password: newPassword });
477
+ },
478
+ async validateResetToken(token) {
479
+ return get(`/api/auth/validate-reset-token?token=${token}`);
480
+ },
481
+ async verifyEmail(token) {
482
+ return post("/api/auth/verify-email", { token });
483
+ },
484
+ async requestEmailVerification() {
485
+ return post("/api/auth/request-verification");
486
+ },
487
+ async getAuthProviders() {
488
+ return get("/api/auth/providers");
489
+ },
490
+ async getAuthProvider(provider) {
491
+ return get(`/api/auth/providers/${provider}`);
492
+ },
493
+ async configureAuthProvider(provider, clientID, clientSecret, enabled) {
494
+ return post("/api/auth/providers", {
495
+ provider,
496
+ client_id: clientID,
497
+ client_secret: clientSecret,
498
+ enabled
499
+ });
500
+ }
501
+ };
502
+ }
503
+
504
+ // src/modules/users.ts
505
+ function createUsersModule(client) {
506
+ const get = (endpoint) => client.get(endpoint);
507
+ const put = (endpoint, body) => client.put(endpoint, body);
508
+ const del = (endpoint) => client.delete(endpoint);
509
+ return {
510
+ async list(limit = 20, offset = 0) {
511
+ return get(`/api/users?limit=${limit}&offset=${offset}`);
512
+ },
513
+ async update(id, updates) {
514
+ return put(`/api/users/${id}`, updates);
515
+ },
516
+ async delete(id) {
517
+ return del(`/api/users/${id}`);
518
+ }
519
+ };
520
+ }
521
+
522
+ // src/modules/database.ts
523
+ function createDatabaseModule(client) {
524
+ const get = (endpoint) => client.get(endpoint);
525
+ const post = (endpoint, body) => client.post(endpoint, body);
526
+ const patch = (endpoint, body) => client.patch(endpoint, body);
527
+ const del = (endpoint) => client.delete(endpoint);
528
+ return {
529
+ // Schemas
530
+ async getSchemas(options) {
531
+ const params = new URLSearchParams();
532
+ if (options?.search) params.append("search", options.search);
533
+ if (options?.limit) params.append("limit", options.limit.toString());
534
+ if (options?.offset) params.append("offset", options.offset.toString());
535
+ const query = params.toString();
536
+ return get(`/api/schemas${query ? `?${query}` : ""}`);
537
+ },
538
+ async getSchema(name) {
539
+ return get(`/api/schemas/${name}`);
540
+ },
541
+ async saveSchemas(data) {
542
+ return post("/api/schemas", data);
543
+ },
544
+ // Tables
545
+ async createTable(tableName, definition) {
546
+ return post("/api/schemas/tables", { table_name: tableName, definition });
547
+ },
548
+ async dropTable(tableName) {
549
+ return del(`/api/schemas/tables/${tableName}`);
550
+ },
551
+ async renameTable(tableName, newName) {
552
+ return post(`/api/schemas/tables/${tableName}/rename`, { new_name: newName });
553
+ },
554
+ // Columns
555
+ async addColumn(tableName, column) {
556
+ return post(`/api/schemas/tables/${tableName}/columns`, column);
557
+ },
558
+ async dropColumn(tableName, columnName) {
559
+ return del(`/api/schemas/tables/${tableName}/columns/${columnName}`);
560
+ },
561
+ async modifyColumn(tableName, columnName, changes) {
562
+ return patch(`/api/schemas/tables/${tableName}/columns/${columnName}`, changes);
563
+ },
564
+ async renameColumn(tableName, columnName, newName) {
565
+ return post(`/api/schemas/tables/${tableName}/columns/${columnName}/rename`, { new_name: newName });
566
+ },
567
+ async setColumnDefault(tableName, columnName, defaultValue) {
568
+ return patch(`/api/schemas/tables/${tableName}/columns/${columnName}/default`, { default_value: defaultValue });
569
+ },
570
+ // Foreign Keys
571
+ async addForeignKey(tableName, fk) {
572
+ return post(`/api/schemas/tables/${tableName}/foreign-keys`, fk);
573
+ },
574
+ async listForeignKeys(tableName) {
575
+ return get(`/api/schemas/tables/${tableName}/foreign-keys`);
576
+ },
577
+ async dropForeignKey(tableName, constraintName) {
578
+ return del(`/api/schemas/tables/${tableName}/foreign-keys/${constraintName}`);
579
+ },
580
+ // Constraints
581
+ async addUniqueConstraint(tableName, columnName) {
582
+ return post(`/api/schemas/tables/${tableName}/constraints/unique`, { column: columnName });
583
+ },
584
+ async dropConstraint(tableName, constraintName) {
585
+ return del(`/api/schemas/tables/${tableName}/constraints/${constraintName}`);
586
+ },
587
+ // Data operations
588
+ async raw(query) {
589
+ return post("/api/v1/sql", { query });
590
+ },
591
+ async queryData(tableName, options) {
592
+ const params = new URLSearchParams();
593
+ if (options.page) params.append("page", options.page.toString());
594
+ if (options.limit) params.append("limit", options.limit.toString());
595
+ if (options.filters && options.filters.length > 0) {
596
+ params.append("filters", JSON.stringify(options.filters));
597
+ }
598
+ return get(`/api/v1/data/${tableName}/query?${params.toString()}`);
599
+ },
600
+ async downloadExport(tableName, format, filters) {
601
+ const params = new URLSearchParams();
602
+ if (filters && filters.length > 0) {
603
+ params.append("filters", JSON.stringify(filters));
604
+ }
605
+ const res = await fetch(`${client.url}/api/v1/export/${tableName}/${format}?${params.toString()}`, {
606
+ headers: client.getHeaders()
607
+ });
608
+ if (!res.ok) {
609
+ const data = await res.json();
610
+ return { error: data.error || `Export failed: ${res.status}` };
611
+ }
612
+ const blob = await res.blob();
613
+ const url = window.URL.createObjectURL(blob);
614
+ const a = document.createElement("a");
615
+ a.href = url;
616
+ a.download = `${tableName}_${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}.${format === "backup" ? "dump" : format}`;
617
+ document.body.appendChild(a);
618
+ a.click();
619
+ window.URL.revokeObjectURL(url);
620
+ document.body.removeChild(a);
621
+ return { success: true };
622
+ }
623
+ };
624
+ }
625
+
626
+ // src/modules/storage.ts
627
+ function createStorageModule(client) {
628
+ const get = (endpoint) => client.get(endpoint);
629
+ const post = (endpoint, body) => client.post(endpoint, body);
630
+ const put = (endpoint, body) => client.put(endpoint, body);
631
+ const del = (endpoint) => client.delete(endpoint);
632
+ async function uploadFile(fileOrTable, fileOrBucketId) {
633
+ let file;
634
+ let bucketId;
635
+ if (fileOrTable instanceof File) {
636
+ file = fileOrTable;
637
+ bucketId = typeof fileOrBucketId === "string" ? fileOrBucketId : void 0;
638
+ } else {
639
+ file = fileOrBucketId;
640
+ bucketId = void 0;
641
+ }
642
+ const formData = new FormData();
643
+ formData.append("file", file);
644
+ if (bucketId) {
645
+ formData.append("bucket_id", bucketId);
646
+ }
647
+ const headers = client.getHeaders("");
648
+ const res = await fetch(`${client.url}/api/storage/upload`, {
649
+ method: "POST",
650
+ headers,
651
+ body: formData
652
+ });
653
+ if (!res.ok) {
654
+ if (res.status === 401) client.forceLogout();
655
+ const err = await res.json().catch(() => ({ error: `Upload failed: ${res.status}` }));
656
+ throw new Error(err.error ?? `Upload failed: ${res.status}`);
657
+ }
658
+ return res.json();
659
+ }
660
+ return {
661
+ upload: uploadFile,
662
+ async listFiles() {
663
+ return get("/api/storage/files");
664
+ },
665
+ async getFile(fileId, expiresIn) {
666
+ const q = expiresIn && expiresIn > 0 ? `?expiresIn=${expiresIn}` : "";
667
+ return get(`/api/storage/files/${fileId}${q}`);
668
+ },
669
+ async createSignedUrl(fileId, expiresIn) {
670
+ const res = await get(
671
+ `/api/storage/files/${fileId}${expiresIn && expiresIn > 0 ? `?expiresIn=${expiresIn}` : ""}`
672
+ );
673
+ return { signedUrl: res?.url };
674
+ },
675
+ async deleteFile(fileId) {
676
+ return del(`/api/storage/files/${fileId}`);
677
+ },
678
+ async createBucket(name, isPublic = false) {
679
+ return post("/api/storage/buckets", { name, is_public: isPublic });
680
+ },
681
+ async updateBucket(bucketId, opts) {
682
+ return put(`/api/storage/buckets/${bucketId}`, { is_public: opts.isPublic });
683
+ },
684
+ async listBuckets() {
685
+ return get("/api/storage/buckets");
686
+ },
687
+ async getBucket(bucketId) {
688
+ return get(`/api/storage/buckets/${bucketId}`);
689
+ },
690
+ async deleteBucket(bucketId) {
691
+ return del(`/api/storage/buckets/${bucketId}`);
692
+ },
693
+ async listBucketFiles(bucketId) {
694
+ return get(`/api/storage/buckets/${bucketId}/files`);
695
+ },
696
+ async download(fileId) {
697
+ const res = await fetch(`${client.url}/api/storage/files/${fileId}/download`, {
698
+ headers: client.getHeaders("")
699
+ });
700
+ if (!res.ok) {
701
+ if (res.status === 401) client.forceLogout();
702
+ const err = await res.json().catch(() => ({ error: `Download failed: ${res.status}` }));
703
+ throw new Error(err.error ?? `Download failed: ${res.status}`);
704
+ }
705
+ return res.blob();
706
+ }
707
+ };
708
+ }
709
+
710
+ // src/modules/backups.ts
711
+ function createBackupsModule(client) {
712
+ const get = (endpoint) => client.get(endpoint);
713
+ const post = (endpoint, body) => client.post(endpoint, body);
714
+ const del = (endpoint) => client.delete(endpoint);
715
+ return {
716
+ async create(options) {
717
+ return post("/api/backups", options || {});
718
+ },
719
+ async list() {
720
+ return get("/api/backups");
721
+ },
722
+ async get(backupId) {
723
+ return get(`/api/backups/${backupId}`);
724
+ },
725
+ async restore(backupId) {
726
+ return post(`/api/backups/${backupId}/restore`, {});
727
+ },
728
+ async delete(backupId) {
729
+ return del(`/api/backups/${backupId}`);
730
+ },
731
+ getDownloadUrl(backupId) {
732
+ const token = client.getDynamicToken();
733
+ return `${client.url}/api/backups/${backupId}/download?access_token=${token}&apikey=${client.apiKey}`;
734
+ },
735
+ async listTables() {
736
+ return get("/api/backups/tables");
737
+ },
738
+ async importFile(formData) {
739
+ const headers = client.getHeaders();
740
+ delete headers["Content-Type"];
741
+ const res = await fetch(`${client.url}/api/import`, {
742
+ method: "POST",
743
+ headers,
744
+ body: formData
745
+ });
746
+ const data = await res.json();
747
+ if (!res.ok && res.status === 401) client.forceLogout();
748
+ return data;
749
+ }
750
+ };
751
+ }
752
+
753
+ // src/modules/migrations.ts
754
+ function createMigrationsModule(client) {
755
+ const get = (endpoint) => client.get(endpoint);
756
+ const post = (endpoint, body) => client.post(endpoint, body);
757
+ const del = (endpoint) => client.delete(endpoint);
758
+ return {
759
+ async create(input) {
760
+ return post("/api/migrations", input);
761
+ },
762
+ async list() {
763
+ return get("/api/migrations");
764
+ },
765
+ async get(id) {
766
+ return get(`/api/migrations/${id}`);
767
+ },
768
+ async apply(id) {
769
+ return post(`/api/migrations/${id}/apply`, {});
770
+ },
771
+ async rollback(id) {
772
+ return post(`/api/migrations/${id}/rollback`, {});
773
+ },
774
+ async delete(id) {
775
+ return del(`/api/migrations/${id}`);
776
+ },
777
+ async generate(tableName, changes) {
778
+ return post("/api/migrations/generate", { table_name: tableName, changes });
779
+ }
780
+ };
781
+ }
782
+
783
+ // src/modules/functions.ts
784
+ function createFunctionsModule(client) {
785
+ const post = (endpoint, body) => client.post(endpoint, body);
786
+ const get = (endpoint) => client.get(endpoint);
787
+ const del = (endpoint) => client.delete(endpoint);
788
+ const put = (endpoint, body) => client.put(endpoint, body);
789
+ return {
790
+ async invoke(id, data = {}) {
791
+ return post(`/api/functions/${id}/execute`, data);
792
+ },
793
+ async get(id) {
794
+ return get(`/api/functions/${id}`);
795
+ },
796
+ async list() {
797
+ return get("/api/functions");
798
+ },
799
+ async create(name, code, options) {
800
+ return post("/api/functions", { name, code, ...options });
801
+ },
802
+ async delete(id) {
803
+ return del(`/api/functions/${id}`);
804
+ },
805
+ async update(id, code, options) {
806
+ const current = await get(`/api/functions/${id}`);
807
+ const name = current?.name ?? current?.data?.name;
808
+ return post("/api/functions", { name, code, ...options });
809
+ },
810
+ async executeCode(code, options) {
811
+ return post("/api/functions/execute", { code, ...options });
812
+ },
813
+ async listHooks() {
814
+ return get("/api/hooks");
815
+ },
816
+ async createHook(data) {
817
+ return post("/api/hooks", data);
818
+ },
819
+ async deleteHook(id) {
820
+ return del(`/api/hooks/${id}`);
821
+ }
822
+ };
823
+ }
824
+
825
+ // src/modules/jobs.ts
826
+ function createJobsModule(client) {
827
+ const get = (endpoint) => client.get(endpoint);
828
+ const post = (endpoint, body) => client.post(endpoint, body);
829
+ const put = (endpoint, body) => client.put(endpoint, body);
830
+ const del = (endpoint) => client.delete(endpoint);
831
+ return {
832
+ async create(input) {
833
+ return post("/api/jobs", input);
834
+ },
835
+ async list() {
836
+ return get("/api/jobs");
837
+ },
838
+ async get(id) {
839
+ return get(`/api/jobs/${id}`);
840
+ },
841
+ async update(id, input) {
842
+ return put(`/api/jobs/${id}`, input);
843
+ },
844
+ async delete(id) {
845
+ return del(`/api/jobs/${id}`);
846
+ },
847
+ async toggle(id, enabled) {
848
+ return post(`/api/jobs/${id}/toggle`, { enabled });
849
+ },
850
+ async runNow(id) {
851
+ return post(`/api/jobs/${id}/run`);
852
+ },
853
+ async getExecutions(id, limit) {
854
+ const params = new URLSearchParams();
855
+ if (limit) params.set("limit", limit.toString());
856
+ return get(`/api/jobs/${id}/executions?${params.toString()}`);
857
+ }
858
+ };
859
+ }
860
+
861
+ // src/modules/env-vars.ts
862
+ function createEnvVarsModule(client) {
863
+ const get = (endpoint) => client.get(endpoint);
864
+ const post = (endpoint, body) => client.post(endpoint, body);
865
+ const put = (endpoint, body) => client.put(endpoint, body);
866
+ const del = (endpoint) => client.delete(endpoint);
867
+ return {
868
+ async create(input) {
869
+ return post("/api/env-vars", input);
870
+ },
871
+ async list() {
872
+ return get("/api/env-vars");
873
+ },
874
+ async get(id) {
875
+ return get(`/api/env-vars/${id}`);
876
+ },
877
+ async update(id, value) {
878
+ return put(`/api/env-vars/${id}`, { value });
879
+ },
880
+ async delete(id) {
881
+ return del(`/api/env-vars/${id}`);
882
+ }
883
+ };
884
+ }
885
+
886
+ // src/modules/email.ts
887
+ function createEmailModule(client) {
888
+ const get = (endpoint) => client.get(endpoint);
889
+ const post = (endpoint, body) => client.post(endpoint, body);
890
+ const put = (endpoint, body) => client.put(endpoint, body);
891
+ const del = (endpoint) => client.delete(endpoint);
892
+ return {
893
+ async send(input) {
894
+ return post("/api/email/send", input);
895
+ },
896
+ async getConfig() {
897
+ return get("/api/email/config");
898
+ },
899
+ async saveConfig(config) {
900
+ return post("/api/email/config", config);
901
+ },
902
+ async createTemplate(template) {
903
+ return post("/api/email/templates", template);
904
+ },
905
+ async listTemplates() {
906
+ return get("/api/email/templates");
907
+ },
908
+ async getTemplate(id) {
909
+ return get(`/api/email/templates/${id}`);
910
+ },
911
+ async updateTemplate(id, template) {
912
+ return put(`/api/email/templates/${id}`, template);
913
+ },
914
+ async deleteTemplate(id) {
915
+ return del(`/api/email/templates/${id}`);
916
+ },
917
+ async getLogs(options) {
918
+ const params = new URLSearchParams();
919
+ if (options?.limit) params.set("limit", options.limit.toString());
920
+ if (options?.offset) params.set("offset", options.offset.toString());
921
+ return get(`/api/email/logs?${params.toString()}`);
922
+ }
923
+ };
924
+ }
925
+
926
+ // src/modules/search.ts
927
+ function createSearchModule(client) {
928
+ const post = (endpoint, body) => client.post(endpoint, body);
929
+ return {
930
+ async search(query, options) {
931
+ return post("/api/search", {
932
+ query,
933
+ tables: options?.tables,
934
+ columns: options?.columns,
935
+ limit: options?.limit,
936
+ offset: options?.offset
937
+ });
938
+ },
939
+ async createIndex(table, columns) {
940
+ return post("/api/search/index", { table, columns });
941
+ }
942
+ };
943
+ }
944
+
945
+ // src/modules/graphql.ts
946
+ function createGraphQLModule(client) {
947
+ const get = (endpoint) => client.get(endpoint);
948
+ const post = (endpoint, body) => client.post(endpoint, body);
949
+ return {
950
+ async query(query, variables) {
951
+ return post("/api/graphql", { query, variables });
952
+ },
953
+ async getSchema() {
954
+ return post("/api/graphql", {
955
+ query: "{ __schema { queryType { name } mutationType { name } types { name kind } } }"
956
+ });
957
+ },
958
+ getPlaygroundUrl() {
959
+ return `${client.url}/api/graphql/playground`;
960
+ }
961
+ };
962
+ }
963
+
964
+ // src/modules/metrics.ts
965
+ function createMetricsModule(client) {
966
+ const get = (endpoint) => client.get(endpoint);
967
+ return {
968
+ async getDashboardStats() {
969
+ return get("/api/metrics/dashboard");
970
+ },
971
+ async getRequestLogs(options) {
972
+ const params = new URLSearchParams();
973
+ if (options?.limit) params.set("limit", options.limit.toString());
974
+ if (options?.offset) params.set("offset", options.offset.toString());
975
+ if (options?.method) params.set("method", options.method);
976
+ if (options?.status) params.set("status", options.status);
977
+ if (options?.path) params.set("path", options.path);
978
+ return get(`/api/metrics/requests?${params.toString()}`);
979
+ },
980
+ async getApplicationLogs(options) {
981
+ const params = new URLSearchParams();
982
+ if (options?.limit) params.set("limit", options.limit.toString());
983
+ if (options?.offset) params.set("offset", options.offset.toString());
984
+ if (options?.level) params.set("level", options.level);
985
+ if (options?.source) params.set("source", options.source);
986
+ if (options?.search) params.set("search", options.search);
987
+ return get(`/api/metrics/logs?${params.toString()}`);
988
+ },
989
+ async getTimeseries(metric, options) {
990
+ const params = new URLSearchParams({ metric });
991
+ if (options?.interval) params.set("interval", options.interval);
992
+ if (options?.start) params.set("start", options.start);
993
+ if (options?.end) params.set("end", options.end);
994
+ return get(`/api/metrics/timeseries?${params.toString()}`);
995
+ }
996
+ };
997
+ }
998
+
999
+ // src/modules/audit.ts
1000
+ function createAuditModule(client) {
1001
+ const get = (endpoint) => client.get(endpoint);
1002
+ const del = (endpoint) => client.delete(endpoint);
1003
+ return {
1004
+ async list(options) {
1005
+ const params = new URLSearchParams();
1006
+ if (options?.limit) params.set("limit", options.limit.toString());
1007
+ if (options?.offset) params.set("offset", options.offset.toString());
1008
+ if (options?.action) params.set("action", options.action);
1009
+ if (options?.user_id) params.set("user_id", options.user_id);
1010
+ if (options?.method) params.set("method", options.method);
1011
+ if (options?.path) params.set("path", options.path);
1012
+ if (options?.status_code) params.set("status_code", options.status_code.toString());
1013
+ if (options?.start_date) params.set("start_date", options.start_date);
1014
+ if (options?.end_date) params.set("end_date", options.end_date);
1015
+ return get(`/api/audit/logs?${params.toString()}`);
1016
+ },
1017
+ async getActions() {
1018
+ return get("/api/audit/actions");
1019
+ },
1020
+ async exportLogs(format, options) {
1021
+ const params = new URLSearchParams();
1022
+ params.set("format", format);
1023
+ if (options?.action) params.set("action", options.action);
1024
+ if (options?.method) params.set("method", options.method);
1025
+ if (options?.path) params.set("path", options.path);
1026
+ if (options?.status_code) params.set("status_code", options.status_code.toString());
1027
+ if (options?.start_date) params.set("start_date", options.start_date);
1028
+ if (options?.end_date) params.set("end_date", options.end_date);
1029
+ const res = await fetch(`${client.url}/api/audit/export?${params.toString()}`, {
1030
+ headers: client.getHeaders(),
1031
+ credentials: "include"
1032
+ });
1033
+ if (!res.ok) {
1034
+ const data = await res.json();
1035
+ return { error: data.error || `Export failed: ${res.status}` };
1036
+ }
1037
+ const blob = await res.blob();
1038
+ const url = window.URL.createObjectURL(blob);
1039
+ const a = document.createElement("a");
1040
+ a.href = url;
1041
+ a.download = `audit_logs_${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}.${format}`;
1042
+ document.body.appendChild(a);
1043
+ a.click();
1044
+ window.URL.revokeObjectURL(url);
1045
+ document.body.removeChild(a);
1046
+ return { success: true };
1047
+ },
1048
+ async purgePreview(olderThanDays) {
1049
+ return get(`/api/audit/purge/preview?older_than_days=${olderThanDays}`);
1050
+ },
1051
+ async purge(olderThanDays) {
1052
+ return del(`/api/audit/purge?older_than_days=${olderThanDays}`);
1053
+ }
1054
+ };
1055
+ }
1056
+
1057
+ // src/modules/webhooks.ts
1058
+ function createWebhooksModule(client) {
1059
+ const get = (endpoint) => client.get(endpoint);
1060
+ const post = (endpoint, body) => client.post(endpoint, body);
1061
+ const put = (endpoint, body) => client.put(endpoint, body);
1062
+ const del = (endpoint) => client.delete(endpoint);
1063
+ return {
1064
+ async list() {
1065
+ return get("/api/webhooks");
1066
+ },
1067
+ async get(id) {
1068
+ return get(`/api/webhooks/${id}`);
1069
+ },
1070
+ async create(input) {
1071
+ return post("/api/webhooks", input);
1072
+ },
1073
+ async update(id, input) {
1074
+ return put(`/api/webhooks/${id}`, input);
1075
+ },
1076
+ async delete(id) {
1077
+ return del(`/api/webhooks/${id}`);
1078
+ },
1079
+ async test(id) {
1080
+ return post(`/api/webhooks/${id}/test`);
1081
+ }
1082
+ };
1083
+ }
1084
+
1085
+ // src/modules/log-drains.ts
1086
+ function createLogDrainsModule(client) {
1087
+ const get = (endpoint) => client.get(endpoint);
1088
+ const post = (endpoint, body) => client.post(endpoint, body);
1089
+ const put = (endpoint, body) => client.put(endpoint, body);
1090
+ const del = (endpoint) => client.delete(endpoint);
1091
+ return {
1092
+ async create(input) {
1093
+ return post("/api/log-drains", input);
1094
+ },
1095
+ async list() {
1096
+ return get("/api/log-drains");
1097
+ },
1098
+ async get(id) {
1099
+ return get(`/api/log-drains/${id}`);
1100
+ },
1101
+ async update(id, input) {
1102
+ return put(`/api/log-drains/${id}`, input);
1103
+ },
1104
+ async delete(id) {
1105
+ return del(`/api/log-drains/${id}`);
1106
+ },
1107
+ async toggle(id, enabled) {
1108
+ return post(`/api/log-drains/${id}/toggle`, { enabled });
1109
+ },
1110
+ async test(id) {
1111
+ return post(`/api/log-drains/${id}/test`);
1112
+ }
1113
+ };
1114
+ }
1115
+
1116
+ // src/modules/branches.ts
1117
+ function createBranchesModule(client) {
1118
+ const get = (endpoint) => client.get(endpoint);
1119
+ const post = (endpoint, body) => client.post(endpoint, body);
1120
+ const del = (endpoint) => client.delete(endpoint);
1121
+ return {
1122
+ async create(input) {
1123
+ return post("/api/branches", input);
1124
+ },
1125
+ async list() {
1126
+ return get("/api/branches");
1127
+ },
1128
+ async get(id) {
1129
+ return get(`/api/branches/${id}`);
1130
+ },
1131
+ async delete(id) {
1132
+ return del(`/api/branches/${id}`);
1133
+ },
1134
+ async merge(id, targetBranchId) {
1135
+ return post(`/api/branches/${id}/merge`, { target_branch_id: targetBranchId });
1136
+ },
1137
+ async reset(id) {
1138
+ return post(`/api/branches/${id}/reset`);
1139
+ }
1140
+ };
1141
+ }
1142
+
1143
+ // src/realtime.ts
1144
+ var RealtimeService = class {
1145
+ constructor(url, apiKey, tokenProvider, wsConstructor = typeof WebSocket !== "undefined" ? WebSocket : null) {
1146
+ this.url = url;
1147
+ this.apiKey = apiKey;
1148
+ this.tokenProvider = tokenProvider;
1149
+ this.wsConstructor = wsConstructor;
1150
+ }
1151
+ socket = null;
1152
+ subscribers = /* @__PURE__ */ new Map();
1153
+ reconnectAttempts = 0;
1154
+ maxReconnectAttempts = 5;
1155
+ reconnectInterval = 3e3;
1156
+ /**
1157
+ * Initialize the WebSocket connection
1158
+ */
1159
+ connect() {
1160
+ if (this.socket?.readyState === WebSocket.OPEN) return Promise.resolve();
1161
+ return new Promise((resolve, reject) => {
1162
+ const token = this.tokenProvider();
1163
+ if (!token) {
1164
+ reject(new Error("Missing authentication token for Realtime connection"));
1165
+ return;
1166
+ }
1167
+ const wsUrl = this.url.replace(/^http/, "ws") + "/api/ws";
1168
+ const fullUrl = this.apiKey ? `${wsUrl}?apikey=${this.apiKey}&token=${token}` : `${wsUrl}?token=${token}`;
1169
+ if (!this.wsConstructor) {
1170
+ reject(new Error("WebSocket constructor not provided or available in this environment"));
1171
+ return;
1172
+ }
1173
+ const socket = new this.wsConstructor(fullUrl);
1174
+ this.socket = socket;
1175
+ socket.onopen = () => {
1176
+ console.log("BaaS Realtime: Connected");
1177
+ this.reconnectAttempts = 0;
1178
+ for (const table of this.subscribers.keys()) {
1179
+ this.sendSub("subscribe", table);
1180
+ }
1181
+ resolve();
1182
+ };
1183
+ socket.onmessage = (event) => {
1184
+ const raw = event.data;
1185
+ const parts = raw.split("\n").filter((s) => s.trim());
1186
+ for (const part of parts) {
1187
+ try {
1188
+ const payload = JSON.parse(part);
1189
+ this.handleEvent(payload);
1190
+ } catch {
1191
+ const chunks = part.replace(/\}\s*\{/g, "}\n{").split("\n");
1192
+ for (const chunk of chunks) {
1193
+ try {
1194
+ const payload = JSON.parse(chunk);
1195
+ this.handleEvent(payload);
1196
+ } catch {
1197
+ }
1198
+ }
1199
+ }
1200
+ }
1201
+ };
1202
+ socket.onerror = (error) => {
1203
+ console.error("BaaS Realtime: WebSocket Error", error);
1204
+ reject(error);
1205
+ };
1206
+ socket.onclose = () => {
1207
+ console.log("BaaS Realtime: Disconnected");
1208
+ this.socket = null;
1209
+ this.attemptReconnect();
1210
+ };
1211
+ });
1212
+ }
1213
+ /**
1214
+ * Subscribe to changes on a specific table
1215
+ */
1216
+ async subscribe(table, action, callback) {
1217
+ await this.connect();
1218
+ const isNewTable = !this.subscribers.has(table);
1219
+ if (isNewTable) {
1220
+ this.subscribers.set(table, /* @__PURE__ */ new Set());
1221
+ }
1222
+ const sub = { action, callback };
1223
+ this.subscribers.get(table).add(sub);
1224
+ if (isNewTable && table !== "*") {
1225
+ this.sendSub("subscribe", table);
1226
+ }
1227
+ return {
1228
+ unsubscribe: () => {
1229
+ const tableSubs = this.subscribers.get(table);
1230
+ if (tableSubs) {
1231
+ tableSubs.delete(sub);
1232
+ if (tableSubs.size === 0) {
1233
+ this.subscribers.delete(table);
1234
+ if (table !== "*") this.sendSub("unsubscribe", table);
1235
+ }
1236
+ }
1237
+ }
1238
+ };
1239
+ }
1240
+ /** Send a subscribe/unsubscribe control frame to the server. */
1241
+ sendSub(event, table) {
1242
+ if (this.socket?.readyState === WebSocket.OPEN) {
1243
+ this.socket.send(JSON.stringify({ event, table }));
1244
+ }
1245
+ }
1246
+ /**
1247
+ * Handle incoming CDC events from the server
1248
+ */
1249
+ handleEvent(payload) {
1250
+ const tableSubs = this.subscribers.get(payload.table);
1251
+ if (tableSubs) {
1252
+ for (const sub of tableSubs) {
1253
+ if (sub.action === "*" || sub.action.toLowerCase() === payload.action.toLowerCase()) {
1254
+ sub.callback(payload);
1255
+ }
1256
+ }
1257
+ }
1258
+ const wildcardSubs = this.subscribers.get("*");
1259
+ if (wildcardSubs) {
1260
+ for (const sub of wildcardSubs) {
1261
+ if (sub.action === "*" || sub.action.toLowerCase() === payload.action.toLowerCase()) {
1262
+ sub.callback(payload);
1263
+ }
1264
+ }
1265
+ }
1266
+ }
1267
+ /**
1268
+ * Attempt to reconnect on connection loss
1269
+ */
1270
+ attemptReconnect() {
1271
+ if (this.reconnectAttempts < this.maxReconnectAttempts) {
1272
+ this.reconnectAttempts++;
1273
+ console.log(`BaaS Realtime: Attempting reconnect ${this.reconnectAttempts}/${this.maxReconnectAttempts}...`);
1274
+ setTimeout(() => this.connect(), this.reconnectInterval);
1275
+ } else {
1276
+ console.error("BaaS Realtime: Max reconnect attempts reached");
1277
+ }
1278
+ }
1279
+ /**
1280
+ * Close the connection
1281
+ */
1282
+ disconnect() {
1283
+ if (this.socket) {
1284
+ this.socket.onclose = null;
1285
+ this.socket.close();
1286
+ this.socket = null;
1287
+ }
1288
+ }
1289
+ /** @internal - For testing only */
1290
+ get _socket() {
1291
+ return this.socket;
1292
+ }
1293
+ };
1294
+
1295
+ // src/modules/realtime.ts
1296
+ function createRealtimeModule(client) {
1297
+ const service = new RealtimeService(
1298
+ client.url,
1299
+ client.apiKey,
1300
+ () => client.getDynamicToken(),
1301
+ typeof WebSocket !== "undefined" ? WebSocket : void 0
1302
+ );
1303
+ return {
1304
+ async subscribe(table, action, callback) {
1305
+ return service.subscribe(table, action, callback);
1306
+ }
1307
+ };
1308
+ }
1309
+
1310
+ // src/modules/api-keys.ts
1311
+ function createApiKeysModule(client) {
1312
+ const get = (endpoint) => client.get(endpoint);
1313
+ const post = (endpoint, body) => client.post(endpoint, body);
1314
+ const del = (endpoint) => client.delete(endpoint);
1315
+ return {
1316
+ async create(name, permissions, expiresAt) {
1317
+ return post("/api/api-keys", { name, permissions, expires_at: expiresAt });
1318
+ },
1319
+ async list() {
1320
+ return get("/api/api-keys");
1321
+ },
1322
+ async revoke(keyId) {
1323
+ return post(`/api/api-keys/${keyId}/revoke`, {});
1324
+ },
1325
+ async delete(keyId) {
1326
+ return del(`/api/api-keys/${keyId}`);
1327
+ },
1328
+ async getInstanceToken() {
1329
+ return get("/api/api-keys/instance");
1330
+ },
1331
+ async regenerateInstanceToken() {
1332
+ return post("/api/api-keys/instance/regenerate", {});
1333
+ }
1334
+ };
1335
+ }
1336
+
1337
+ // src/modules/environments.ts
1338
+ function createEnvironmentsModule(client) {
1339
+ const get = (endpoint) => client.get(endpoint);
1340
+ const post = (endpoint, body) => client.post(endpoint, body);
1341
+ return {
1342
+ async status() {
1343
+ return get("/api/environments/status");
1344
+ },
1345
+ async init() {
1346
+ return post("/api/environments/init");
1347
+ },
1348
+ async promote() {
1349
+ return post("/api/environments/promote");
1350
+ },
1351
+ async revert() {
1352
+ return post("/api/environments/revert");
1353
+ },
1354
+ setActive(env) {
1355
+ client.setEnvironment(env);
1356
+ },
1357
+ getActive() {
1358
+ return client.getEnvironment();
1359
+ }
1360
+ };
1361
+ }
1362
+
1363
+ // src/modules/cors-origins.ts
1364
+ function createCorsOriginsModule(client) {
1365
+ const get = (endpoint) => client.get(endpoint);
1366
+ const post = (endpoint, body) => client.post(endpoint, body);
1367
+ const del = (endpoint) => client.delete(endpoint);
1368
+ return {
1369
+ async list() {
1370
+ return get("/api/cors-origins");
1371
+ },
1372
+ async create(origin, description) {
1373
+ return post("/api/cors-origins", { origin, description: description || "" });
1374
+ },
1375
+ async delete(id) {
1376
+ return del(`/api/cors-origins/${id}`);
1377
+ }
1378
+ };
1379
+ }
1380
+
1381
+ // src/modules/policies.ts
1382
+ function createPoliciesModule(client) {
1383
+ const get = (endpoint) => client.get(endpoint);
1384
+ const post = (endpoint, body) => client.post(endpoint, body);
1385
+ const del = (endpoint) => client.delete(endpoint);
1386
+ return {
1387
+ async create(input) {
1388
+ return post("/api/policies", input);
1389
+ },
1390
+ async list() {
1391
+ return get("/api/policies");
1392
+ },
1393
+ async delete(id) {
1394
+ return del(`/api/policies/${id}`);
1395
+ }
1396
+ };
1397
+ }
1398
+
1399
+ // src/modules/ip-whitelist.ts
1400
+ function createIPWhitelistModule(client) {
1401
+ const get = (endpoint) => client.get(endpoint);
1402
+ const post = (endpoint, body) => client.post(endpoint, body);
1403
+ const del = (endpoint) => client.delete(endpoint);
1404
+ return {
1405
+ async list() {
1406
+ return get("/api/ip-whitelist");
1407
+ },
1408
+ async create(ipAddress, description) {
1409
+ return post("/api/ip-whitelist", { ip_address: ipAddress, description: description || "" });
1410
+ },
1411
+ async delete(id) {
1412
+ return del(`/api/ip-whitelist/${id}`);
1413
+ }
1414
+ };
1415
+ }
1416
+
1417
+ // src/modules/cache.ts
1418
+ function createCacheModule(client) {
1419
+ const get = (endpoint) => client.get(endpoint);
1420
+ const post = (endpoint, body) => client.post(endpoint, body);
1421
+ const patch = (endpoint, body) => client.patch(endpoint, body);
1422
+ const del = (endpoint) => client.delete(endpoint);
1423
+ return {
1424
+ async getStatus() {
1425
+ return get("/api/cache/status");
1426
+ },
1427
+ async getStats() {
1428
+ return get("/api/cache/stats");
1429
+ },
1430
+ async listPolicies() {
1431
+ return get("/api/cache/policies");
1432
+ },
1433
+ async updatePolicy(namespace, body) {
1434
+ return patch(`/api/cache/policies/${encodeURIComponent(namespace)}`, body);
1435
+ },
1436
+ async removePolicy(namespace) {
1437
+ return del(`/api/cache/policies/${encodeURIComponent(namespace)}`);
1438
+ },
1439
+ async invalidateNamespace(namespace) {
1440
+ return post(`/api/cache/invalidate/${encodeURIComponent(namespace)}`);
1441
+ },
1442
+ async invalidateAll() {
1443
+ return post("/api/cache/invalidate-all");
1444
+ },
1445
+ async listKeys(prefix, cursor = 0, count = 100) {
1446
+ const params = new URLSearchParams({ prefix, cursor: String(cursor), count: String(count) });
1447
+ return get(`/api/cache/keys?${params}`);
1448
+ },
1449
+ async inspectKey(key) {
1450
+ return get(`/api/cache/keys/inspect?key=${encodeURIComponent(key)}`);
1451
+ }
1452
+ };
1453
+ }
1454
+
1455
+ // src/client.ts
1456
+ var BaasClient = class extends HttpClient {
1457
+ // Feature modules
1458
+ auth;
1459
+ users;
1460
+ database;
1461
+ storage;
1462
+ backups;
1463
+ migrations;
1464
+ functions;
1465
+ jobs;
1466
+ envVars;
1467
+ email;
1468
+ searchService;
1469
+ graphqlService;
1470
+ metrics;
1471
+ audit;
1472
+ webhooks;
1473
+ logDrains;
1474
+ branches;
1475
+ realtime;
1476
+ apiKeys;
1477
+ environments;
1478
+ corsOrigins;
1479
+ policies;
1480
+ ipWhitelist;
1481
+ cache;
1482
+ constructor(url, apiKey, options) {
1483
+ super(url, apiKey, options);
1484
+ this.auth = createAuthModule(this);
1485
+ this.users = createUsersModule(this);
1486
+ this.database = createDatabaseModule(this);
1487
+ this.storage = createStorageModule(this);
1488
+ this.backups = createBackupsModule(this);
1489
+ this.migrations = createMigrationsModule(this);
1490
+ this.functions = createFunctionsModule(this);
1491
+ this.jobs = createJobsModule(this);
1492
+ this.envVars = createEnvVarsModule(this);
1493
+ this.email = createEmailModule(this);
1494
+ this.searchService = createSearchModule(this);
1495
+ this.graphqlService = createGraphQLModule(this);
1496
+ this.metrics = createMetricsModule(this);
1497
+ this.audit = createAuditModule(this);
1498
+ this.webhooks = createWebhooksModule(this);
1499
+ this.logDrains = createLogDrainsModule(this);
1500
+ this.branches = createBranchesModule(this);
1501
+ this.realtime = createRealtimeModule(this);
1502
+ this.apiKeys = createApiKeysModule(this);
1503
+ this.environments = createEnvironmentsModule(this);
1504
+ this.corsOrigins = createCorsOriginsModule(this);
1505
+ this.policies = createPoliciesModule(this);
1506
+ this.ipWhitelist = createIPWhitelistModule(this);
1507
+ this.cache = createCacheModule(this);
1508
+ }
1509
+ /**
1510
+ * Create a query builder for fluent data queries
1511
+ */
1512
+ from(table) {
1513
+ return new QueryBuilder(table, this.url, this);
1514
+ }
1515
+ /**
1516
+ * Invoke a PL/pgSQL function (PostgREST `.rpc()` parity). Runs under the
1517
+ * caller's RLS context; args bind by name and are $N-safe. Pass [params] for
1518
+ * POST (named args in the body) or set `opts.get = true` for the GET variant.
1519
+ */
1520
+ async rpc(fn, params, opts) {
1521
+ if (opts?.get) {
1522
+ const qs = params ? "?" + new URLSearchParams(Object.entries(params).map(([k, v]) => [k, String(v)])).toString() : "";
1523
+ return this.get(`/api/v1/rpc/${fn}${qs}`);
1524
+ }
1525
+ return this.post(`/api/v1/rpc/${fn}`, params ?? {});
1526
+ }
1527
+ // ============================================
1528
+ // BACKWARD COMPATIBILITY METHODS
1529
+ // These delegate to the appropriate modules
1530
+ // ============================================
1531
+ // Auth shortcuts
1532
+ async login(email, password) {
1533
+ return this.auth.login(email, password);
1534
+ }
1535
+ async verifyMFA(mfaToken, code) {
1536
+ return this.auth.verifyMFA(mfaToken, code);
1537
+ }
1538
+ async getProfile() {
1539
+ return this.auth.getProfile();
1540
+ }
1541
+ async register(email, password) {
1542
+ return this.auth.register(email, password);
1543
+ }
1544
+ async forgotPassword(email) {
1545
+ return this.auth.forgotPassword(email);
1546
+ }
1547
+ async resetPassword(token, newPassword) {
1548
+ return this.auth.resetPassword(token, newPassword);
1549
+ }
1550
+ async validateResetToken(token) {
1551
+ return this.auth.validateResetToken(token);
1552
+ }
1553
+ async verifyEmail(token) {
1554
+ return this.auth.verifyEmail(token);
1555
+ }
1556
+ async requestEmailVerification() {
1557
+ return this.auth.requestEmailVerification();
1558
+ }
1559
+ async getAuthProviders() {
1560
+ return this.auth.getAuthProviders();
1561
+ }
1562
+ async getAuthProvider(provider) {
1563
+ return this.auth.getAuthProvider(provider);
1564
+ }
1565
+ async configureAuthProvider(provider, clientID, clientSecret, enabled) {
1566
+ return this.auth.configureAuthProvider(provider, clientID, clientSecret, enabled);
1567
+ }
1568
+ // Users shortcuts
1569
+ async listUsers(limit = 20, offset = 0) {
1570
+ return this.users.list(limit, offset);
1571
+ }
1572
+ async updateUser(id, updates) {
1573
+ return this.users.update(id, updates);
1574
+ }
1575
+ async deleteUser(id) {
1576
+ return this.users.delete(id);
1577
+ }
1578
+ // Database shortcuts
1579
+ async raw(query) {
1580
+ return this.database.raw(query);
1581
+ }
1582
+ async getSchemas(options) {
1583
+ return this.database.getSchemas(options);
1584
+ }
1585
+ async getSchema(name) {
1586
+ return this.database.getSchema(name);
1587
+ }
1588
+ async createTable(tableName, definition) {
1589
+ return this.database.createTable(tableName, definition);
1590
+ }
1591
+ async dropTable(tableName) {
1592
+ return this.database.dropTable(tableName);
1593
+ }
1594
+ async renameTable(tableName, newName) {
1595
+ return this.database.renameTable(tableName, newName);
1596
+ }
1597
+ async addColumn(tableName, column) {
1598
+ return this.database.addColumn(tableName, column);
1599
+ }
1600
+ async dropColumn(tableName, columnName) {
1601
+ return this.database.dropColumn(tableName, columnName);
1602
+ }
1603
+ async modifyColumn(tableName, columnName, changes) {
1604
+ return this.database.modifyColumn(tableName, columnName, changes);
1605
+ }
1606
+ async renameColumn(tableName, columnName, newName) {
1607
+ return this.database.renameColumn(tableName, columnName, newName);
1608
+ }
1609
+ async setColumnDefault(tableName, columnName, defaultValue) {
1610
+ return this.database.setColumnDefault(tableName, columnName, defaultValue);
1611
+ }
1612
+ async addForeignKey(tableName, fk) {
1613
+ return this.database.addForeignKey(tableName, fk);
1614
+ }
1615
+ async listForeignKeys(tableName) {
1616
+ return this.database.listForeignKeys(tableName);
1617
+ }
1618
+ async dropForeignKey(tableName, constraintName) {
1619
+ return this.database.dropForeignKey(tableName, constraintName);
1620
+ }
1621
+ async addUniqueConstraint(tableName, columnName) {
1622
+ return this.database.addUniqueConstraint(tableName, columnName);
1623
+ }
1624
+ async dropConstraint(tableName, constraintName) {
1625
+ return this.database.dropConstraint(tableName, constraintName);
1626
+ }
1627
+ async queryData(tableName, options) {
1628
+ return this.database.queryData(tableName, options);
1629
+ }
1630
+ async downloadExport(tableName, format, filters) {
1631
+ return this.database.downloadExport(tableName, format, filters);
1632
+ }
1633
+ // Storage shortcuts
1634
+ async upload(file, bucketId) {
1635
+ return this.storage.upload(file, bucketId);
1636
+ }
1637
+ async listStorageFiles() {
1638
+ return this.storage.listFiles();
1639
+ }
1640
+ async getStorageFile(fileId) {
1641
+ return this.storage.getFile(fileId);
1642
+ }
1643
+ async deleteStorageFile(fileId) {
1644
+ return this.storage.deleteFile(fileId);
1645
+ }
1646
+ async createStorageBucket(name, isPublic) {
1647
+ return this.storage.createBucket(name, isPublic);
1648
+ }
1649
+ async listStorageBuckets() {
1650
+ return this.storage.listBuckets();
1651
+ }
1652
+ async getStorageBucket(bucketId) {
1653
+ return this.storage.getBucket(bucketId);
1654
+ }
1655
+ async deleteStorageBucket(bucketId) {
1656
+ return this.storage.deleteBucket(bucketId);
1657
+ }
1658
+ async listStorageBucketFiles(bucketId) {
1659
+ return this.storage.listBucketFiles(bucketId);
1660
+ }
1661
+ // Functions shortcuts
1662
+ async invokeFunction(id, data) {
1663
+ return this.functions.invoke(id, data);
1664
+ }
1665
+ // API Keys shortcuts
1666
+ async createApiKey(name, permissions, expiresAt) {
1667
+ return this.apiKeys.create(name, permissions, expiresAt);
1668
+ }
1669
+ async listApiKeys() {
1670
+ return this.apiKeys.list();
1671
+ }
1672
+ async revokeApiKey(keyId) {
1673
+ return this.apiKeys.revoke(keyId);
1674
+ }
1675
+ async deleteApiKey(keyId) {
1676
+ return this.apiKeys.delete(keyId);
1677
+ }
1678
+ async getInstanceToken() {
1679
+ return this.apiKeys.getInstanceToken();
1680
+ }
1681
+ async regenerateInstanceToken() {
1682
+ return this.apiKeys.regenerateInstanceToken();
1683
+ }
1684
+ // Backups shortcuts
1685
+ async createBackup(options) {
1686
+ return this.backups.create(options);
1687
+ }
1688
+ async listBackups() {
1689
+ return this.backups.list();
1690
+ }
1691
+ async getBackup(backupId) {
1692
+ return this.backups.get(backupId);
1693
+ }
1694
+ async restoreBackup(backupId) {
1695
+ return this.backups.restore(backupId);
1696
+ }
1697
+ async deleteBackup(backupId) {
1698
+ return this.backups.delete(backupId);
1699
+ }
1700
+ getBackupDownloadUrl(backupId) {
1701
+ return this.backups.getDownloadUrl(backupId);
1702
+ }
1703
+ async listBackupTables() {
1704
+ return this.backups.listTables();
1705
+ }
1706
+ async importFile(formData) {
1707
+ return this.backups.importFile(formData);
1708
+ }
1709
+ // Search shortcuts
1710
+ async search(query, options) {
1711
+ return this.searchService.search(query, options);
1712
+ }
1713
+ async createSearchIndex(table, columns) {
1714
+ return this.searchService.createIndex(table, columns);
1715
+ }
1716
+ // GraphQL shortcuts
1717
+ async graphql(query, variables) {
1718
+ return this.graphqlService.query(query, variables);
1719
+ }
1720
+ getGraphQLPlaygroundUrl() {
1721
+ return this.graphqlService.getPlaygroundUrl();
1722
+ }
1723
+ // Migrations shortcuts
1724
+ async createMigration(input) {
1725
+ return this.migrations.create(input);
1726
+ }
1727
+ async listMigrations() {
1728
+ return this.migrations.list();
1729
+ }
1730
+ async getMigration(id) {
1731
+ return this.migrations.get(id);
1732
+ }
1733
+ async applyMigration(id) {
1734
+ return this.migrations.apply(id);
1735
+ }
1736
+ async rollbackMigration(id) {
1737
+ return this.migrations.rollback(id);
1738
+ }
1739
+ async deleteMigration(id) {
1740
+ return this.migrations.delete(id);
1741
+ }
1742
+ async generateMigration(tableName, changes) {
1743
+ return this.migrations.generate(tableName, changes);
1744
+ }
1745
+ // Email shortcuts
1746
+ async sendEmail(input) {
1747
+ return this.email.send(input);
1748
+ }
1749
+ async getEmailConfig() {
1750
+ return this.email.getConfig();
1751
+ }
1752
+ async saveEmailConfig(config) {
1753
+ return this.email.saveConfig(config);
1754
+ }
1755
+ async createEmailTemplate(template) {
1756
+ return this.email.createTemplate(template);
1757
+ }
1758
+ async listEmailTemplates() {
1759
+ return this.email.listTemplates();
1760
+ }
1761
+ async getEmailTemplate(id) {
1762
+ return this.email.getTemplate(id);
1763
+ }
1764
+ async updateEmailTemplate(id, template) {
1765
+ return this.email.updateTemplate(id, template);
1766
+ }
1767
+ async deleteEmailTemplate(id) {
1768
+ return this.email.deleteTemplate(id);
1769
+ }
1770
+ async getEmailLogs(options) {
1771
+ return this.email.getLogs(options);
1772
+ }
1773
+ // Metrics shortcuts
1774
+ async getDashboardStats() {
1775
+ return this.metrics.getDashboardStats();
1776
+ }
1777
+ async getRequestLogs(options) {
1778
+ return this.metrics.getRequestLogs(options);
1779
+ }
1780
+ async getApplicationLogs(options) {
1781
+ return this.metrics.getApplicationLogs(options);
1782
+ }
1783
+ async getMetricTimeseries(metric, options) {
1784
+ return this.metrics.getTimeseries(metric, options);
1785
+ }
1786
+ // Jobs shortcuts
1787
+ async createJob(input) {
1788
+ return this.jobs.create(input);
1789
+ }
1790
+ async listJobs() {
1791
+ return this.jobs.list();
1792
+ }
1793
+ async getJob(id) {
1794
+ return this.jobs.get(id);
1795
+ }
1796
+ async updateJob(id, input) {
1797
+ return this.jobs.update(id, input);
1798
+ }
1799
+ async deleteJob(id) {
1800
+ return this.jobs.delete(id);
1801
+ }
1802
+ async toggleJob(id, enabled) {
1803
+ return this.jobs.toggle(id, enabled);
1804
+ }
1805
+ async runJobNow(id) {
1806
+ return this.jobs.runNow(id);
1807
+ }
1808
+ async getJobExecutions(id, limit) {
1809
+ return this.jobs.getExecutions(id, limit);
1810
+ }
1811
+ // Env Vars shortcuts
1812
+ async createEnvVar(input) {
1813
+ return this.envVars.create(input);
1814
+ }
1815
+ async listEnvVars() {
1816
+ return this.envVars.list();
1817
+ }
1818
+ async getEnvVar(id) {
1819
+ return this.envVars.get(id);
1820
+ }
1821
+ async updateEnvVar(id, value) {
1822
+ return this.envVars.update(id, value);
1823
+ }
1824
+ async deleteEnvVar(id) {
1825
+ return this.envVars.delete(id);
1826
+ }
1827
+ // Branches shortcuts
1828
+ async createBranch(input) {
1829
+ return this.branches.create(input);
1830
+ }
1831
+ async listBranches() {
1832
+ return this.branches.list();
1833
+ }
1834
+ async getBranch(id) {
1835
+ return this.branches.get(id);
1836
+ }
1837
+ async deleteBranch(id) {
1838
+ return this.branches.delete(id);
1839
+ }
1840
+ async mergeBranch(id, targetBranchId) {
1841
+ return this.branches.merge(id, targetBranchId);
1842
+ }
1843
+ async resetBranch(id) {
1844
+ return this.branches.reset(id);
1845
+ }
1846
+ // Log Drains shortcuts
1847
+ async createLogDrain(input) {
1848
+ return this.logDrains.create(input);
1849
+ }
1850
+ async listLogDrains() {
1851
+ return this.logDrains.list();
1852
+ }
1853
+ async getLogDrain(id) {
1854
+ return this.logDrains.get(id);
1855
+ }
1856
+ async updateLogDrain(id, input) {
1857
+ return this.logDrains.update(id, input);
1858
+ }
1859
+ async deleteLogDrain(id) {
1860
+ return this.logDrains.delete(id);
1861
+ }
1862
+ async toggleLogDrain(id, enabled) {
1863
+ return this.logDrains.toggle(id, enabled);
1864
+ }
1865
+ async testLogDrain(id) {
1866
+ return this.logDrains.test(id);
1867
+ }
1868
+ // Webhooks shortcuts
1869
+ async listWebhooks() {
1870
+ return this.webhooks.list();
1871
+ }
1872
+ async getWebhook(id) {
1873
+ return this.webhooks.get(id);
1874
+ }
1875
+ async createWebhook(input) {
1876
+ return this.webhooks.create(input);
1877
+ }
1878
+ async updateWebhook(id, input) {
1879
+ return this.webhooks.update(id, input);
1880
+ }
1881
+ async deleteWebhook(id) {
1882
+ return this.webhooks.delete(id);
1883
+ }
1884
+ async testWebhook(id) {
1885
+ return this.webhooks.test(id);
1886
+ }
1887
+ // Audit shortcuts
1888
+ async listAuditLogs(options) {
1889
+ return this.audit.list(options);
1890
+ }
1891
+ async getAuditActions() {
1892
+ return this.audit.getActions();
1893
+ }
1894
+ async exportAuditLogs(format, options) {
1895
+ return this.audit.exportLogs(format, options);
1896
+ }
1897
+ async previewPurgeAuditLogs(olderThanDays) {
1898
+ return this.audit.purgePreview(olderThanDays);
1899
+ }
1900
+ async purgeAuditLogs(olderThanDays) {
1901
+ return this.audit.purge(olderThanDays);
1902
+ }
1903
+ // Realtime shortcuts
1904
+ subscribe(table, action, callback) {
1905
+ return this.realtime.subscribe(table, action, callback);
1906
+ }
1907
+ // Environment shortcuts
1908
+ async getEnvironmentStatus() {
1909
+ return this.environments.status();
1910
+ }
1911
+ async initTestEnvironment() {
1912
+ return this.environments.init();
1913
+ }
1914
+ async promoteTestToProd() {
1915
+ return this.environments.promote();
1916
+ }
1917
+ async revertTestEnvironment() {
1918
+ return this.environments.revert();
1919
+ }
1920
+ // CORS Origins shortcuts
1921
+ async listCorsOrigins() {
1922
+ return this.corsOrigins.list();
1923
+ }
1924
+ async addCorsOrigin(origin, description) {
1925
+ return this.corsOrigins.create(origin, description);
1926
+ }
1927
+ async deleteCorsOrigin(id) {
1928
+ return this.corsOrigins.delete(id);
1929
+ }
1930
+ // Policies shortcuts
1931
+ async listPolicies() {
1932
+ return this.policies.list();
1933
+ }
1934
+ async createPolicy(input) {
1935
+ return this.policies.create(input);
1936
+ }
1937
+ async deletePolicy(id) {
1938
+ return this.policies.delete(id);
1939
+ }
1940
+ // IP Whitelist shortcuts
1941
+ async listIPWhitelist() {
1942
+ return this.ipWhitelist.list();
1943
+ }
1944
+ async addIPWhitelistEntry(ipAddress, description) {
1945
+ return this.ipWhitelist.create(ipAddress, description);
1946
+ }
1947
+ async deleteIPWhitelistEntry(id) {
1948
+ return this.ipWhitelist.delete(id);
1949
+ }
1950
+ };
1951
+ export {
1952
+ BaasClient,
1953
+ HttpClient,
1954
+ QueryBuilder
1955
+ };
1956
+ //# sourceMappingURL=index.js.map