@giaeulate/baas-sdk 1.0.3 → 1.0.4

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.cjs ADDED
@@ -0,0 +1,1494 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ BaasClient: () => BaasClient,
24
+ HttpClient: () => HttpClient,
25
+ QueryBuilder: () => QueryBuilder
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+
29
+ // src/http-client.ts
30
+ var HttpClient = class {
31
+ url;
32
+ apiKey = "";
33
+ token = null;
34
+ environment = "prod";
35
+ constructor(url, apiKey) {
36
+ let baseUrl = url || (typeof window !== "undefined" ? window.location.origin : "http://localhost:8080");
37
+ this.url = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
38
+ if (apiKey) this.apiKey = apiKey;
39
+ this.token = this.cleanValue(localStorage.getItem("baas_token"));
40
+ }
41
+ cleanValue(val) {
42
+ if (!val || val === "null" || val === "undefined") return null;
43
+ return val.trim();
44
+ }
45
+ /**
46
+ * Public header generator for adapters
47
+ */
48
+ getHeaders(contentType = "application/json") {
49
+ const dynamicToken = this.getDynamicToken();
50
+ const headers = {
51
+ "apikey": this.apiKey
52
+ };
53
+ if (contentType) {
54
+ headers["Content-Type"] = contentType;
55
+ }
56
+ if (dynamicToken) {
57
+ headers["Authorization"] = `Bearer ${dynamicToken}`;
58
+ }
59
+ if (this.environment && this.environment !== "prod") {
60
+ headers["X-Environment"] = this.environment;
61
+ }
62
+ return headers;
63
+ }
64
+ getDynamicToken() {
65
+ return this.cleanValue(this.token || localStorage.getItem("baas_token"));
66
+ }
67
+ /**
68
+ * Core HTTP request method - DRY principle
69
+ */
70
+ async request(endpoint, options = {}) {
71
+ const { method = "GET", body, headers: customHeaders, skipAuth = false } = options;
72
+ const headers = { ...this.getHeaders(), ...customHeaders };
73
+ const fetchOptions = {
74
+ method,
75
+ headers
76
+ };
77
+ if (body !== void 0) {
78
+ fetchOptions.body = JSON.stringify(body);
79
+ }
80
+ const res = await fetch(`${this.url}${endpoint}`, fetchOptions);
81
+ if (res.status === 204) {
82
+ return { success: true };
83
+ }
84
+ const data = await res.json().catch(() => null);
85
+ if (!res.ok) {
86
+ if (res.status === 401 && !skipAuth) {
87
+ this.forceLogout();
88
+ }
89
+ if (res.status === 403 && data?.error === "ip_not_allowed") {
90
+ this.handleIPBlocked(data.ip);
91
+ }
92
+ return { error: data?.error || `Request failed: ${res.status}`, ...data };
93
+ }
94
+ return data;
95
+ }
96
+ get(endpoint) {
97
+ return this.request(endpoint);
98
+ }
99
+ post(endpoint, body) {
100
+ return this.request(endpoint, { method: "POST", body });
101
+ }
102
+ put(endpoint, body) {
103
+ return this.request(endpoint, { method: "PUT", body });
104
+ }
105
+ patch(endpoint, body) {
106
+ return this.request(endpoint, { method: "PATCH", body });
107
+ }
108
+ delete(endpoint) {
109
+ return this.request(endpoint, { method: "DELETE" });
110
+ }
111
+ setEnvironment(env) {
112
+ this.environment = env;
113
+ }
114
+ getEnvironment() {
115
+ return this.environment;
116
+ }
117
+ logout() {
118
+ this.token = null;
119
+ localStorage.removeItem("baas_token");
120
+ }
121
+ forceLogout() {
122
+ this.logout();
123
+ if (typeof window !== "undefined") {
124
+ if (!window.location.search.includes("expired")) {
125
+ window.location.href = "/auth/login?reason=expired";
126
+ }
127
+ }
128
+ }
129
+ handleIPBlocked(ip) {
130
+ if (typeof window !== "undefined") {
131
+ const params = ip ? `?ip=${encodeURIComponent(ip)}` : "";
132
+ if (!window.location.pathname.includes("/blocked")) {
133
+ window.location.href = `/blocked${params}`;
134
+ }
135
+ }
136
+ }
137
+ };
138
+
139
+ // src/query-builder.ts
140
+ var QueryBuilder = class {
141
+ table;
142
+ url;
143
+ client;
144
+ queryParams = new URLSearchParams();
145
+ // @ts-ignore - used for future filter improvements
146
+ filters = [];
147
+ constructor(table, url, client) {
148
+ this.table = table;
149
+ this.url = url;
150
+ this.client = client;
151
+ }
152
+ select(columns = "*") {
153
+ this.queryParams.set("select", columns);
154
+ return this;
155
+ }
156
+ eq(column, value) {
157
+ this.queryParams.set(column, `eq.${value}`);
158
+ return this;
159
+ }
160
+ neq(column, value) {
161
+ this.queryParams.set(column, `neq.${value}`);
162
+ return this;
163
+ }
164
+ gt(column, value) {
165
+ this.queryParams.set(column, `gt.${value}`);
166
+ return this;
167
+ }
168
+ gte(column, value) {
169
+ this.queryParams.set(column, `gte.${value}`);
170
+ return this;
171
+ }
172
+ lt(column, value) {
173
+ this.queryParams.set(column, `lt.${value}`);
174
+ return this;
175
+ }
176
+ lte(column, value) {
177
+ this.queryParams.set(column, `lte.${value}`);
178
+ return this;
179
+ }
180
+ like(column, value) {
181
+ this.queryParams.set(column, `like.${value}`);
182
+ return this;
183
+ }
184
+ ilike(column, value) {
185
+ this.queryParams.set(column, `ilike.${value}`);
186
+ return this;
187
+ }
188
+ is(column, value) {
189
+ this.queryParams.set(column, `is.${value}`);
190
+ return this;
191
+ }
192
+ in(column, values) {
193
+ this.queryParams.set(column, `in.(${values.join(",")})`);
194
+ return this;
195
+ }
196
+ not(column, operator, value) {
197
+ this.queryParams.set(column, `not.${operator}.${value}`);
198
+ return this;
199
+ }
200
+ or(filters) {
201
+ this.queryParams.set("or", `(${filters})`);
202
+ return this;
203
+ }
204
+ order(column, { ascending = true } = {}) {
205
+ this.queryParams.set("order", `${column}.${ascending ? "asc" : "desc"}`);
206
+ return this;
207
+ }
208
+ limit(count) {
209
+ this.queryParams.set("limit", count.toString());
210
+ return this;
211
+ }
212
+ offset(count) {
213
+ this.queryParams.set("offset", count.toString());
214
+ return this;
215
+ }
216
+ async get() {
217
+ const res = await fetch(`${this.url}/api/v1/data/${this.table}?${this.queryParams.toString()}`, {
218
+ headers: this.getHeaders()
219
+ });
220
+ return await this.handleResponse(res);
221
+ }
222
+ async insert(data) {
223
+ const res = await fetch(`${this.url}/api/v1/data/${this.table}`, {
224
+ method: "POST",
225
+ headers: this.getHeaders(),
226
+ body: JSON.stringify(data)
227
+ });
228
+ return await this.handleResponse(res);
229
+ }
230
+ async update(id, data) {
231
+ const res = await fetch(`${this.url}/api/v1/data/${this.table}/${id}`, {
232
+ method: "PATCH",
233
+ headers: this.getHeaders(),
234
+ body: JSON.stringify(data)
235
+ });
236
+ return await this.handleResponse(res);
237
+ }
238
+ async delete(id) {
239
+ const res = await fetch(`${this.url}/api/v1/data/${this.table}/${id}`, {
240
+ method: "DELETE",
241
+ headers: this.getHeaders()
242
+ });
243
+ if (res.status === 204) return { success: true };
244
+ return await this.handleResponse(res);
245
+ }
246
+ getHeaders() {
247
+ return this.client.getHeaders();
248
+ }
249
+ async handleResponse(res) {
250
+ const text = await res.text();
251
+ let data = null;
252
+ try {
253
+ data = text ? JSON.parse(text) : null;
254
+ } catch {
255
+ }
256
+ if (!res.ok) {
257
+ if (res.status === 401) {
258
+ this.client.forceLogout();
259
+ }
260
+ return { data: null, error: data?.error || "Request failed", status: res.status };
261
+ }
262
+ return { data, error: null, status: res.status };
263
+ }
264
+ };
265
+
266
+ // src/modules/auth.ts
267
+ function createAuthModule(client) {
268
+ const get = (endpoint) => client.get(endpoint);
269
+ const post = (endpoint, body) => client.post(endpoint, body);
270
+ return {
271
+ async login(email, password) {
272
+ const res = await fetch(`${client.url}/api/login`, {
273
+ method: "POST",
274
+ headers: client.getHeaders(),
275
+ body: JSON.stringify({ email, password })
276
+ });
277
+ const contentType = res.headers.get("content-type");
278
+ if (!contentType?.includes("application/json")) {
279
+ throw new Error(`Login failed: Server returned ${res.status}. Please check your connection.`);
280
+ }
281
+ const data = await res.json().catch(() => {
282
+ throw new Error(`Login failed: Invalid JSON response (status ${res.status})`);
283
+ });
284
+ if (!res.ok) {
285
+ throw new Error(data?.error || `Login failed: ${res.status}`);
286
+ }
287
+ if (data.token) {
288
+ client.token = data.token;
289
+ localStorage.setItem("baas_token", data.token);
290
+ }
291
+ return data;
292
+ },
293
+ async logout() {
294
+ try {
295
+ await post("/api/logout");
296
+ } finally {
297
+ client.token = null;
298
+ localStorage.removeItem("baas_token");
299
+ }
300
+ },
301
+ async verifyMFA(mfaToken, code) {
302
+ const data = await post("/api/mfa/finalize", { mfa_token: mfaToken, code });
303
+ if (data.token) {
304
+ client.token = data.token;
305
+ localStorage.setItem("baas_token", data.token);
306
+ }
307
+ return data;
308
+ },
309
+ async verifyMFAWithRecoveryCode(mfaToken, recoveryCode) {
310
+ const data = await post("/api/mfa/finalize", { mfa_token: mfaToken, recovery_code: recoveryCode });
311
+ if (data.token) {
312
+ client.token = data.token;
313
+ localStorage.setItem("baas_token", data.token);
314
+ }
315
+ return data;
316
+ },
317
+ async setupMFA() {
318
+ return post("/api/mfa/setup");
319
+ },
320
+ async enableMFA(secret, code, recoveryCodes) {
321
+ const body = { secret, code };
322
+ if (recoveryCodes) {
323
+ body.recovery_codes = recoveryCodes;
324
+ }
325
+ return post("/api/mfa/enable", body);
326
+ },
327
+ async disableMFA(code) {
328
+ return post("/api/mfa/disable", { code });
329
+ },
330
+ async getProfile() {
331
+ return get("/api/profile");
332
+ },
333
+ async register(email, password) {
334
+ const data = await post("/api/register", { email, password });
335
+ if (data.error) {
336
+ throw new Error(data.error);
337
+ }
338
+ return data;
339
+ },
340
+ async forgotPassword(email) {
341
+ return post("/api/auth/forgot-password", { email });
342
+ },
343
+ async resetPassword(token, newPassword) {
344
+ return post("/api/auth/reset-password", { token, new_password: newPassword });
345
+ },
346
+ async validateResetToken(token) {
347
+ return get(`/api/auth/validate-reset-token?token=${token}`);
348
+ },
349
+ async verifyEmail(token) {
350
+ return post("/api/auth/verify-email", { token });
351
+ },
352
+ async requestEmailVerification() {
353
+ return post("/api/auth/request-verification");
354
+ },
355
+ async getAuthProviders() {
356
+ return get("/api/auth/providers");
357
+ },
358
+ async getAuthProvider(provider) {
359
+ return get(`/api/auth/providers/${provider}`);
360
+ },
361
+ async configureAuthProvider(provider, clientID, clientSecret, enabled) {
362
+ return post("/api/auth/providers", {
363
+ provider,
364
+ client_id: clientID,
365
+ client_secret: clientSecret,
366
+ enabled
367
+ });
368
+ }
369
+ };
370
+ }
371
+
372
+ // src/modules/users.ts
373
+ function createUsersModule(client) {
374
+ const get = (endpoint) => client.get(endpoint);
375
+ const put = (endpoint, body) => client.put(endpoint, body);
376
+ const del = (endpoint) => client.delete(endpoint);
377
+ return {
378
+ async list(limit = 20, offset = 0) {
379
+ return get(`/api/users?limit=${limit}&offset=${offset}`);
380
+ },
381
+ async update(id, updates) {
382
+ return put(`/api/users/${id}`, updates);
383
+ },
384
+ async delete(id) {
385
+ return del(`/api/users/${id}`);
386
+ }
387
+ };
388
+ }
389
+
390
+ // src/modules/database.ts
391
+ function createDatabaseModule(client) {
392
+ const get = (endpoint) => client.get(endpoint);
393
+ const post = (endpoint, body) => client.post(endpoint, body);
394
+ const patch = (endpoint, body) => client.patch(endpoint, body);
395
+ const del = (endpoint) => client.delete(endpoint);
396
+ return {
397
+ // Schemas
398
+ async getSchemas(options) {
399
+ const params = new URLSearchParams();
400
+ if (options?.search) params.append("search", options.search);
401
+ if (options?.limit) params.append("limit", options.limit.toString());
402
+ if (options?.offset) params.append("offset", options.offset.toString());
403
+ const query = params.toString();
404
+ return get(`/api/schemas${query ? `?${query}` : ""}`);
405
+ },
406
+ async getSchema(name) {
407
+ return get(`/api/schemas/${name}`);
408
+ },
409
+ // Tables
410
+ async createTable(tableName, definition) {
411
+ return post("/api/schemas/tables", { table_name: tableName, definition });
412
+ },
413
+ async dropTable(tableName) {
414
+ return del(`/api/schemas/tables/${tableName}`);
415
+ },
416
+ async renameTable(tableName, newName) {
417
+ return post(`/api/schemas/tables/${tableName}/rename`, { new_name: newName });
418
+ },
419
+ // Columns
420
+ async addColumn(tableName, column) {
421
+ return post(`/api/schemas/tables/${tableName}/columns`, column);
422
+ },
423
+ async dropColumn(tableName, columnName) {
424
+ return del(`/api/schemas/tables/${tableName}/columns/${columnName}`);
425
+ },
426
+ async modifyColumn(tableName, columnName, changes) {
427
+ return patch(`/api/schemas/tables/${tableName}/columns/${columnName}`, changes);
428
+ },
429
+ async renameColumn(tableName, columnName, newName) {
430
+ return post(`/api/schemas/tables/${tableName}/columns/${columnName}/rename`, { new_name: newName });
431
+ },
432
+ async setColumnDefault(tableName, columnName, defaultValue) {
433
+ return patch(`/api/schemas/tables/${tableName}/columns/${columnName}/default`, { default_value: defaultValue });
434
+ },
435
+ // Foreign Keys
436
+ async addForeignKey(tableName, fk) {
437
+ return post(`/api/schemas/tables/${tableName}/foreign-keys`, fk);
438
+ },
439
+ async listForeignKeys(tableName) {
440
+ return get(`/api/schemas/tables/${tableName}/foreign-keys`);
441
+ },
442
+ async dropForeignKey(tableName, constraintName) {
443
+ return del(`/api/schemas/tables/${tableName}/foreign-keys/${constraintName}`);
444
+ },
445
+ // Constraints
446
+ async addUniqueConstraint(tableName, columnName) {
447
+ return post(`/api/schemas/tables/${tableName}/constraints/unique`, { column: columnName });
448
+ },
449
+ async dropConstraint(tableName, constraintName) {
450
+ return del(`/api/schemas/tables/${tableName}/constraints/${constraintName}`);
451
+ },
452
+ // Data operations
453
+ async raw(query) {
454
+ return post("/api/v1/sql", { query });
455
+ },
456
+ async queryData(tableName, options) {
457
+ const params = new URLSearchParams();
458
+ if (options.page) params.append("page", options.page.toString());
459
+ if (options.limit) params.append("limit", options.limit.toString());
460
+ if (options.filters && options.filters.length > 0) {
461
+ params.append("filters", JSON.stringify(options.filters));
462
+ }
463
+ return get(`/api/v1/data/${tableName}/query?${params.toString()}`);
464
+ },
465
+ async downloadExport(tableName, format, filters) {
466
+ const params = new URLSearchParams();
467
+ if (filters && filters.length > 0) {
468
+ params.append("filters", JSON.stringify(filters));
469
+ }
470
+ const res = await fetch(`${client.url}/api/v1/export/${tableName}/${format}?${params.toString()}`, {
471
+ headers: client.getHeaders()
472
+ });
473
+ if (!res.ok) {
474
+ const data = await res.json();
475
+ return { error: data.error || `Export failed: ${res.status}` };
476
+ }
477
+ const blob = await res.blob();
478
+ const url = window.URL.createObjectURL(blob);
479
+ const a = document.createElement("a");
480
+ a.href = url;
481
+ a.download = `${tableName}_${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}.${format === "backup" ? "dump" : format}`;
482
+ document.body.appendChild(a);
483
+ a.click();
484
+ window.URL.revokeObjectURL(url);
485
+ document.body.removeChild(a);
486
+ return { success: true };
487
+ }
488
+ };
489
+ }
490
+
491
+ // src/modules/storage.ts
492
+ function createStorageModule(client) {
493
+ return {
494
+ async upload(_table, file) {
495
+ const formData = new FormData();
496
+ formData.append("file", file);
497
+ const res = await fetch(`${client.url}/api/storage/upload`, {
498
+ method: "POST",
499
+ headers: client.getHeaders(""),
500
+ body: formData
501
+ });
502
+ const data = await res.json();
503
+ if (!res.ok && res.status === 401) client.forceLogout();
504
+ return data;
505
+ }
506
+ };
507
+ }
508
+
509
+ // src/modules/backups.ts
510
+ function createBackupsModule(client) {
511
+ const get = (endpoint) => client.get(endpoint);
512
+ const post = (endpoint, body) => client.post(endpoint, body);
513
+ const del = (endpoint) => client.delete(endpoint);
514
+ return {
515
+ async create(options) {
516
+ return post("/api/backups", options || {});
517
+ },
518
+ async list() {
519
+ return get("/api/backups");
520
+ },
521
+ async get(backupId) {
522
+ return get(`/api/backups/${backupId}`);
523
+ },
524
+ async restore(backupId) {
525
+ return post(`/api/backups/${backupId}/restore`, {});
526
+ },
527
+ async delete(backupId) {
528
+ return del(`/api/backups/${backupId}`);
529
+ },
530
+ getDownloadUrl(backupId) {
531
+ const token = client.getDynamicToken();
532
+ return `${client.url}/api/backups/${backupId}/download?access_token=${token}&apikey=${client.apiKey}`;
533
+ },
534
+ async listTables() {
535
+ return get("/api/backups/tables");
536
+ },
537
+ async importFile(formData) {
538
+ const headers = client.getHeaders();
539
+ delete headers["Content-Type"];
540
+ const res = await fetch(`${client.url}/api/import`, {
541
+ method: "POST",
542
+ headers,
543
+ body: formData
544
+ });
545
+ const data = await res.json();
546
+ if (!res.ok && res.status === 401) client.forceLogout();
547
+ return data;
548
+ }
549
+ };
550
+ }
551
+
552
+ // src/modules/migrations.ts
553
+ function createMigrationsModule(client) {
554
+ const get = (endpoint) => client.get(endpoint);
555
+ const post = (endpoint, body) => client.post(endpoint, body);
556
+ const del = (endpoint) => client.delete(endpoint);
557
+ return {
558
+ async create(input) {
559
+ return post("/api/migrations", input);
560
+ },
561
+ async list() {
562
+ return get("/api/migrations");
563
+ },
564
+ async get(id) {
565
+ return get(`/api/migrations/${id}`);
566
+ },
567
+ async apply(id) {
568
+ return post(`/api/migrations/${id}/apply`, {});
569
+ },
570
+ async rollback(id) {
571
+ return post(`/api/migrations/${id}/rollback`, {});
572
+ },
573
+ async delete(id) {
574
+ return del(`/api/migrations/${id}`);
575
+ },
576
+ async generate(tableName, changes) {
577
+ return post("/api/migrations/generate", { table_name: tableName, changes });
578
+ }
579
+ };
580
+ }
581
+
582
+ // src/modules/functions.ts
583
+ function createFunctionsModule(client) {
584
+ const post = (endpoint, body) => client.post(endpoint, body);
585
+ const get = (endpoint) => client.get(endpoint);
586
+ const del = (endpoint) => client.delete(endpoint);
587
+ const put = (endpoint, body) => client.put(endpoint, body);
588
+ return {
589
+ async invoke(id, data = {}) {
590
+ return post(`/api/functions/${id}/execute`, data);
591
+ },
592
+ async list() {
593
+ return get("/api/functions");
594
+ },
595
+ async create(name, code) {
596
+ return post("/api/functions", { name, code });
597
+ },
598
+ async delete(id) {
599
+ return del(`/api/functions/${id}`);
600
+ },
601
+ async update(id, code) {
602
+ return put(`/api/functions/${id}`, { code });
603
+ },
604
+ async listHooks() {
605
+ return get("/api/hooks");
606
+ },
607
+ async createHook(data) {
608
+ return post("/api/hooks", data);
609
+ },
610
+ async deleteHook(id) {
611
+ return del(`/api/hooks/${id}`);
612
+ }
613
+ };
614
+ }
615
+
616
+ // src/modules/jobs.ts
617
+ function createJobsModule(client) {
618
+ const get = (endpoint) => client.get(endpoint);
619
+ const post = (endpoint, body) => client.post(endpoint, body);
620
+ const put = (endpoint, body) => client.put(endpoint, body);
621
+ const del = (endpoint) => client.delete(endpoint);
622
+ return {
623
+ async create(input) {
624
+ return post("/api/jobs", input);
625
+ },
626
+ async list() {
627
+ return get("/api/jobs");
628
+ },
629
+ async get(id) {
630
+ return get(`/api/jobs/${id}`);
631
+ },
632
+ async update(id, input) {
633
+ return put(`/api/jobs/${id}`, input);
634
+ },
635
+ async delete(id) {
636
+ return del(`/api/jobs/${id}`);
637
+ },
638
+ async toggle(id, enabled) {
639
+ return post(`/api/jobs/${id}/toggle`, { enabled });
640
+ },
641
+ async runNow(id) {
642
+ return post(`/api/jobs/${id}/run`);
643
+ },
644
+ async getExecutions(id, limit) {
645
+ const params = new URLSearchParams();
646
+ if (limit) params.set("limit", limit.toString());
647
+ return get(`/api/jobs/${id}/executions?${params.toString()}`);
648
+ }
649
+ };
650
+ }
651
+
652
+ // src/modules/env-vars.ts
653
+ function createEnvVarsModule(client) {
654
+ const get = (endpoint) => client.get(endpoint);
655
+ const post = (endpoint, body) => client.post(endpoint, body);
656
+ const put = (endpoint, body) => client.put(endpoint, body);
657
+ const del = (endpoint) => client.delete(endpoint);
658
+ return {
659
+ async create(input) {
660
+ return post("/api/env-vars", input);
661
+ },
662
+ async list() {
663
+ return get("/api/env-vars");
664
+ },
665
+ async get(id) {
666
+ return get(`/api/env-vars/${id}`);
667
+ },
668
+ async update(id, value) {
669
+ return put(`/api/env-vars/${id}`, { value });
670
+ },
671
+ async delete(id) {
672
+ return del(`/api/env-vars/${id}`);
673
+ }
674
+ };
675
+ }
676
+
677
+ // src/modules/email.ts
678
+ function createEmailModule(client) {
679
+ const get = (endpoint) => client.get(endpoint);
680
+ const post = (endpoint, body) => client.post(endpoint, body);
681
+ const put = (endpoint, body) => client.put(endpoint, body);
682
+ const del = (endpoint) => client.delete(endpoint);
683
+ return {
684
+ async send(input) {
685
+ return post("/api/email/send", input);
686
+ },
687
+ async getConfig() {
688
+ return get("/api/email/config");
689
+ },
690
+ async saveConfig(config) {
691
+ return post("/api/email/config", config);
692
+ },
693
+ async createTemplate(template) {
694
+ return post("/api/email/templates", template);
695
+ },
696
+ async listTemplates() {
697
+ return get("/api/email/templates");
698
+ },
699
+ async getTemplate(id) {
700
+ return get(`/api/email/templates/${id}`);
701
+ },
702
+ async updateTemplate(id, template) {
703
+ return put(`/api/email/templates/${id}`, template);
704
+ },
705
+ async deleteTemplate(id) {
706
+ return del(`/api/email/templates/${id}`);
707
+ },
708
+ async getLogs(options) {
709
+ const params = new URLSearchParams();
710
+ if (options?.limit) params.set("limit", options.limit.toString());
711
+ if (options?.offset) params.set("offset", options.offset.toString());
712
+ return get(`/api/email/logs?${params.toString()}`);
713
+ }
714
+ };
715
+ }
716
+
717
+ // src/modules/search.ts
718
+ function createSearchModule(client) {
719
+ const post = (endpoint, body) => client.post(endpoint, body);
720
+ return {
721
+ async search(query, options) {
722
+ return post("/api/search", {
723
+ query,
724
+ tables: options?.tables,
725
+ columns: options?.columns,
726
+ limit: options?.limit,
727
+ offset: options?.offset
728
+ });
729
+ },
730
+ async createIndex(table, columns) {
731
+ return post("/api/search/index", { table, columns });
732
+ }
733
+ };
734
+ }
735
+
736
+ // src/modules/graphql.ts
737
+ function createGraphQLModule(client) {
738
+ const post = (endpoint, body) => client.post(endpoint, body);
739
+ return {
740
+ async query(query, variables) {
741
+ return post("/api/graphql", { query, variables });
742
+ },
743
+ getPlaygroundUrl() {
744
+ return `${client.url}/api/graphql/playground`;
745
+ }
746
+ };
747
+ }
748
+
749
+ // src/modules/metrics.ts
750
+ function createMetricsModule(client) {
751
+ const get = (endpoint) => client.get(endpoint);
752
+ return {
753
+ async getDashboardStats() {
754
+ return get("/api/metrics/dashboard");
755
+ },
756
+ async getRequestLogs(options) {
757
+ const params = new URLSearchParams();
758
+ if (options?.limit) params.set("limit", options.limit.toString());
759
+ if (options?.offset) params.set("offset", options.offset.toString());
760
+ if (options?.method) params.set("method", options.method);
761
+ if (options?.status) params.set("status", options.status);
762
+ if (options?.path) params.set("path", options.path);
763
+ return get(`/api/metrics/requests?${params.toString()}`);
764
+ },
765
+ async getApplicationLogs(options) {
766
+ const params = new URLSearchParams();
767
+ if (options?.limit) params.set("limit", options.limit.toString());
768
+ if (options?.offset) params.set("offset", options.offset.toString());
769
+ if (options?.level) params.set("level", options.level);
770
+ if (options?.source) params.set("source", options.source);
771
+ if (options?.search) params.set("search", options.search);
772
+ return get(`/api/metrics/logs?${params.toString()}`);
773
+ },
774
+ async getTimeseries(metric, options) {
775
+ const params = new URLSearchParams({ metric });
776
+ if (options?.interval) params.set("interval", options.interval);
777
+ if (options?.start) params.set("start", options.start);
778
+ if (options?.end) params.set("end", options.end);
779
+ return get(`/api/metrics/timeseries?${params.toString()}`);
780
+ }
781
+ };
782
+ }
783
+
784
+ // src/modules/audit.ts
785
+ function createAuditModule(client) {
786
+ const get = (endpoint) => client.get(endpoint);
787
+ return {
788
+ async list(options) {
789
+ const params = new URLSearchParams();
790
+ if (options?.limit) params.set("limit", options.limit.toString());
791
+ if (options?.offset) params.set("offset", options.offset.toString());
792
+ if (options?.action) params.set("action", options.action);
793
+ if (options?.user_id) params.set("user_id", options.user_id);
794
+ if (options?.method) params.set("method", options.method);
795
+ if (options?.path) params.set("path", options.path);
796
+ if (options?.status_code) params.set("status_code", options.status_code.toString());
797
+ if (options?.start_date) params.set("start_date", options.start_date);
798
+ if (options?.end_date) params.set("end_date", options.end_date);
799
+ return get(`/api/audit/logs?${params.toString()}`);
800
+ },
801
+ async getActions() {
802
+ return get("/api/audit/actions");
803
+ }
804
+ };
805
+ }
806
+
807
+ // src/modules/webhooks.ts
808
+ function createWebhooksModule(client) {
809
+ const get = (endpoint) => client.get(endpoint);
810
+ const post = (endpoint, body) => client.post(endpoint, body);
811
+ const put = (endpoint, body) => client.put(endpoint, body);
812
+ const del = (endpoint) => client.delete(endpoint);
813
+ return {
814
+ async list() {
815
+ return get("/api/webhooks");
816
+ },
817
+ async get(id) {
818
+ return get(`/api/webhooks/${id}`);
819
+ },
820
+ async create(input) {
821
+ return post("/api/webhooks", input);
822
+ },
823
+ async update(id, input) {
824
+ return put(`/api/webhooks/${id}`, input);
825
+ },
826
+ async delete(id) {
827
+ return del(`/api/webhooks/${id}`);
828
+ },
829
+ async test(id) {
830
+ return post(`/api/webhooks/${id}/test`);
831
+ }
832
+ };
833
+ }
834
+
835
+ // src/modules/log-drains.ts
836
+ function createLogDrainsModule(client) {
837
+ const get = (endpoint) => client.get(endpoint);
838
+ const post = (endpoint, body) => client.post(endpoint, body);
839
+ const put = (endpoint, body) => client.put(endpoint, body);
840
+ const del = (endpoint) => client.delete(endpoint);
841
+ return {
842
+ async create(input) {
843
+ return post("/api/log-drains", input);
844
+ },
845
+ async list() {
846
+ return get("/api/log-drains");
847
+ },
848
+ async get(id) {
849
+ return get(`/api/log-drains/${id}`);
850
+ },
851
+ async update(id, input) {
852
+ return put(`/api/log-drains/${id}`, input);
853
+ },
854
+ async delete(id) {
855
+ return del(`/api/log-drains/${id}`);
856
+ },
857
+ async toggle(id, enabled) {
858
+ return post(`/api/log-drains/${id}/toggle`, { enabled });
859
+ },
860
+ async test(id) {
861
+ return post(`/api/log-drains/${id}/test`);
862
+ }
863
+ };
864
+ }
865
+
866
+ // src/modules/branches.ts
867
+ function createBranchesModule(client) {
868
+ const get = (endpoint) => client.get(endpoint);
869
+ const post = (endpoint, body) => client.post(endpoint, body);
870
+ const del = (endpoint) => client.delete(endpoint);
871
+ return {
872
+ async create(input) {
873
+ return post("/api/branches", input);
874
+ },
875
+ async list() {
876
+ return get("/api/branches");
877
+ },
878
+ async get(id) {
879
+ return get(`/api/branches/${id}`);
880
+ },
881
+ async delete(id) {
882
+ return del(`/api/branches/${id}`);
883
+ },
884
+ async merge(id, targetBranchId) {
885
+ return post(`/api/branches/${id}/merge`, { target_branch_id: targetBranchId });
886
+ },
887
+ async reset(id) {
888
+ return post(`/api/branches/${id}/reset`);
889
+ }
890
+ };
891
+ }
892
+
893
+ // src/realtime.ts
894
+ var RealtimeService = class {
895
+ constructor(url, apiKey, tokenProvider, wsConstructor = typeof WebSocket !== "undefined" ? WebSocket : null) {
896
+ this.url = url;
897
+ this.apiKey = apiKey;
898
+ this.tokenProvider = tokenProvider;
899
+ this.wsConstructor = wsConstructor;
900
+ }
901
+ socket = null;
902
+ subscribers = /* @__PURE__ */ new Map();
903
+ reconnectAttempts = 0;
904
+ maxReconnectAttempts = 5;
905
+ reconnectInterval = 3e3;
906
+ /**
907
+ * Initialize the WebSocket connection
908
+ */
909
+ connect() {
910
+ if (this.socket?.readyState === WebSocket.OPEN) return Promise.resolve();
911
+ return new Promise((resolve, reject) => {
912
+ const token = this.tokenProvider();
913
+ if (!this.apiKey || !token) {
914
+ reject(new Error("Missing API key or authentication token for Realtime connection"));
915
+ return;
916
+ }
917
+ const wsUrl = this.url.replace(/^http/, "ws") + "/ws";
918
+ const fullUrl = `${wsUrl}?apikey=${this.apiKey}&token=${token}`;
919
+ if (!this.wsConstructor) {
920
+ reject(new Error("WebSocket constructor not provided or available in this environment"));
921
+ return;
922
+ }
923
+ const socket = new this.wsConstructor(fullUrl);
924
+ this.socket = socket;
925
+ socket.onopen = () => {
926
+ console.log("BaaS Realtime: Connected");
927
+ this.reconnectAttempts = 0;
928
+ resolve();
929
+ };
930
+ socket.onmessage = (event) => {
931
+ try {
932
+ const payload = JSON.parse(event.data);
933
+ this.handleEvent(payload);
934
+ } catch (err) {
935
+ console.error("BaaS Realtime: Failed to parse message", err);
936
+ }
937
+ };
938
+ socket.onerror = (error) => {
939
+ console.error("BaaS Realtime: WebSocket Error", error);
940
+ reject(error);
941
+ };
942
+ socket.onclose = () => {
943
+ console.log("BaaS Realtime: Disconnected");
944
+ this.socket = null;
945
+ this.attemptReconnect();
946
+ };
947
+ });
948
+ }
949
+ /**
950
+ * Subscribe to changes on a specific table
951
+ */
952
+ async subscribe(table, action, callback) {
953
+ await this.connect();
954
+ if (!this.subscribers.has(table)) {
955
+ this.subscribers.set(table, /* @__PURE__ */ new Set());
956
+ }
957
+ const sub = { action, callback };
958
+ this.subscribers.get(table).add(sub);
959
+ return {
960
+ unsubscribe: () => {
961
+ const tableSubs = this.subscribers.get(table);
962
+ if (tableSubs) {
963
+ tableSubs.delete(sub);
964
+ if (tableSubs.size === 0) {
965
+ this.subscribers.delete(table);
966
+ }
967
+ }
968
+ }
969
+ };
970
+ }
971
+ /**
972
+ * Handle incoming CDC events from the server
973
+ */
974
+ handleEvent(payload) {
975
+ const tableSubs = this.subscribers.get(payload.table);
976
+ if (tableSubs) {
977
+ for (const sub of tableSubs) {
978
+ if (sub.action === "*" || sub.action.toLowerCase() === payload.action.toLowerCase()) {
979
+ sub.callback(payload);
980
+ }
981
+ }
982
+ }
983
+ const wildcardSubs = this.subscribers.get("*");
984
+ if (wildcardSubs) {
985
+ for (const sub of wildcardSubs) {
986
+ if (sub.action === "*" || sub.action.toLowerCase() === payload.action.toLowerCase()) {
987
+ sub.callback(payload);
988
+ }
989
+ }
990
+ }
991
+ }
992
+ /**
993
+ * Attempt to reconnect on connection loss
994
+ */
995
+ attemptReconnect() {
996
+ if (this.reconnectAttempts < this.maxReconnectAttempts) {
997
+ this.reconnectAttempts++;
998
+ console.log(`BaaS Realtime: Attempting reconnect ${this.reconnectAttempts}/${this.maxReconnectAttempts}...`);
999
+ setTimeout(() => this.connect(), this.reconnectInterval);
1000
+ } else {
1001
+ console.error("BaaS Realtime: Max reconnect attempts reached");
1002
+ }
1003
+ }
1004
+ /**
1005
+ * Close the connection
1006
+ */
1007
+ disconnect() {
1008
+ if (this.socket) {
1009
+ this.socket.onclose = null;
1010
+ this.socket.close();
1011
+ this.socket = null;
1012
+ }
1013
+ }
1014
+ /** @internal - For testing only */
1015
+ get _socket() {
1016
+ return this.socket;
1017
+ }
1018
+ };
1019
+
1020
+ // src/modules/realtime.ts
1021
+ function createRealtimeModule(client) {
1022
+ const service = new RealtimeService(
1023
+ client.url,
1024
+ client.apiKey,
1025
+ () => client.getDynamicToken(),
1026
+ typeof WebSocket !== "undefined" ? WebSocket : void 0
1027
+ );
1028
+ return {
1029
+ async subscribe(table, action, callback) {
1030
+ return service.subscribe(table, action, callback);
1031
+ }
1032
+ };
1033
+ }
1034
+
1035
+ // src/modules/api-keys.ts
1036
+ function createApiKeysModule(client) {
1037
+ const get = (endpoint) => client.get(endpoint);
1038
+ const post = (endpoint, body) => client.post(endpoint, body);
1039
+ const del = (endpoint) => client.delete(endpoint);
1040
+ return {
1041
+ async create(name, permissions, expiresAt) {
1042
+ return post("/api/api-keys", { name, permissions, expires_at: expiresAt });
1043
+ },
1044
+ async list() {
1045
+ return get("/api/api-keys");
1046
+ },
1047
+ async revoke(keyId) {
1048
+ return post(`/api/api-keys/${keyId}/revoke`, {});
1049
+ },
1050
+ async delete(keyId) {
1051
+ return del(`/api/api-keys/${keyId}`);
1052
+ }
1053
+ };
1054
+ }
1055
+
1056
+ // src/modules/environments.ts
1057
+ function createEnvironmentsModule(client) {
1058
+ const get = (endpoint) => client.get(endpoint);
1059
+ const post = (endpoint, body) => client.post(endpoint, body);
1060
+ return {
1061
+ async status() {
1062
+ return get("/api/environments/status");
1063
+ },
1064
+ async init() {
1065
+ return post("/api/environments/init");
1066
+ },
1067
+ async promote() {
1068
+ return post("/api/environments/promote");
1069
+ },
1070
+ async revert() {
1071
+ return post("/api/environments/revert");
1072
+ },
1073
+ setActive(env) {
1074
+ client.setEnvironment(env);
1075
+ },
1076
+ getActive() {
1077
+ return client.getEnvironment();
1078
+ }
1079
+ };
1080
+ }
1081
+
1082
+ // src/client.ts
1083
+ var BaasClient = class extends HttpClient {
1084
+ // Feature modules
1085
+ auth;
1086
+ users;
1087
+ database;
1088
+ storage;
1089
+ backups;
1090
+ migrations;
1091
+ functions;
1092
+ jobs;
1093
+ envVars;
1094
+ email;
1095
+ searchService;
1096
+ graphqlService;
1097
+ metrics;
1098
+ audit;
1099
+ webhooks;
1100
+ logDrains;
1101
+ branches;
1102
+ realtime;
1103
+ apiKeys;
1104
+ environments;
1105
+ constructor(url, apiKey) {
1106
+ super(url, apiKey);
1107
+ this.auth = createAuthModule(this);
1108
+ this.users = createUsersModule(this);
1109
+ this.database = createDatabaseModule(this);
1110
+ this.storage = createStorageModule(this);
1111
+ this.backups = createBackupsModule(this);
1112
+ this.migrations = createMigrationsModule(this);
1113
+ this.functions = createFunctionsModule(this);
1114
+ this.jobs = createJobsModule(this);
1115
+ this.envVars = createEnvVarsModule(this);
1116
+ this.email = createEmailModule(this);
1117
+ this.searchService = createSearchModule(this);
1118
+ this.graphqlService = createGraphQLModule(this);
1119
+ this.metrics = createMetricsModule(this);
1120
+ this.audit = createAuditModule(this);
1121
+ this.webhooks = createWebhooksModule(this);
1122
+ this.logDrains = createLogDrainsModule(this);
1123
+ this.branches = createBranchesModule(this);
1124
+ this.realtime = createRealtimeModule(this);
1125
+ this.apiKeys = createApiKeysModule(this);
1126
+ this.environments = createEnvironmentsModule(this);
1127
+ }
1128
+ /**
1129
+ * Create a query builder for fluent data queries
1130
+ */
1131
+ from(table) {
1132
+ return new QueryBuilder(table, this.url, this);
1133
+ }
1134
+ // ============================================
1135
+ // BACKWARD COMPATIBILITY METHODS
1136
+ // These delegate to the appropriate modules
1137
+ // ============================================
1138
+ // Auth shortcuts
1139
+ async login(email, password) {
1140
+ return this.auth.login(email, password);
1141
+ }
1142
+ async verifyMFA(mfaToken, code) {
1143
+ return this.auth.verifyMFA(mfaToken, code);
1144
+ }
1145
+ async getProfile() {
1146
+ return this.auth.getProfile();
1147
+ }
1148
+ async register(email, password) {
1149
+ return this.auth.register(email, password);
1150
+ }
1151
+ async forgotPassword(email) {
1152
+ return this.auth.forgotPassword(email);
1153
+ }
1154
+ async resetPassword(token, newPassword) {
1155
+ return this.auth.resetPassword(token, newPassword);
1156
+ }
1157
+ async validateResetToken(token) {
1158
+ return this.auth.validateResetToken(token);
1159
+ }
1160
+ async verifyEmail(token) {
1161
+ return this.auth.verifyEmail(token);
1162
+ }
1163
+ async requestEmailVerification() {
1164
+ return this.auth.requestEmailVerification();
1165
+ }
1166
+ async getAuthProviders() {
1167
+ return this.auth.getAuthProviders();
1168
+ }
1169
+ async getAuthProvider(provider) {
1170
+ return this.auth.getAuthProvider(provider);
1171
+ }
1172
+ async configureAuthProvider(provider, clientID, clientSecret, enabled) {
1173
+ return this.auth.configureAuthProvider(provider, clientID, clientSecret, enabled);
1174
+ }
1175
+ // Users shortcuts
1176
+ async listUsers(limit = 20, offset = 0) {
1177
+ return this.users.list(limit, offset);
1178
+ }
1179
+ async updateUser(id, updates) {
1180
+ return this.users.update(id, updates);
1181
+ }
1182
+ async deleteUser(id) {
1183
+ return this.users.delete(id);
1184
+ }
1185
+ // Database shortcuts
1186
+ async raw(query) {
1187
+ return this.database.raw(query);
1188
+ }
1189
+ async getSchemas(options) {
1190
+ return this.database.getSchemas(options);
1191
+ }
1192
+ async getSchema(name) {
1193
+ return this.database.getSchema(name);
1194
+ }
1195
+ async createTable(tableName, definition) {
1196
+ return this.database.createTable(tableName, definition);
1197
+ }
1198
+ async dropTable(tableName) {
1199
+ return this.database.dropTable(tableName);
1200
+ }
1201
+ async renameTable(tableName, newName) {
1202
+ return this.database.renameTable(tableName, newName);
1203
+ }
1204
+ async addColumn(tableName, column) {
1205
+ return this.database.addColumn(tableName, column);
1206
+ }
1207
+ async dropColumn(tableName, columnName) {
1208
+ return this.database.dropColumn(tableName, columnName);
1209
+ }
1210
+ async modifyColumn(tableName, columnName, changes) {
1211
+ return this.database.modifyColumn(tableName, columnName, changes);
1212
+ }
1213
+ async renameColumn(tableName, columnName, newName) {
1214
+ return this.database.renameColumn(tableName, columnName, newName);
1215
+ }
1216
+ async setColumnDefault(tableName, columnName, defaultValue) {
1217
+ return this.database.setColumnDefault(tableName, columnName, defaultValue);
1218
+ }
1219
+ async addForeignKey(tableName, fk) {
1220
+ return this.database.addForeignKey(tableName, fk);
1221
+ }
1222
+ async listForeignKeys(tableName) {
1223
+ return this.database.listForeignKeys(tableName);
1224
+ }
1225
+ async dropForeignKey(tableName, constraintName) {
1226
+ return this.database.dropForeignKey(tableName, constraintName);
1227
+ }
1228
+ async addUniqueConstraint(tableName, columnName) {
1229
+ return this.database.addUniqueConstraint(tableName, columnName);
1230
+ }
1231
+ async dropConstraint(tableName, constraintName) {
1232
+ return this.database.dropConstraint(tableName, constraintName);
1233
+ }
1234
+ async queryData(tableName, options) {
1235
+ return this.database.queryData(tableName, options);
1236
+ }
1237
+ async downloadExport(tableName, format, filters) {
1238
+ return this.database.downloadExport(tableName, format, filters);
1239
+ }
1240
+ // Storage shortcuts
1241
+ async upload(table, file) {
1242
+ return this.storage.upload(table, file);
1243
+ }
1244
+ // Functions shortcuts
1245
+ async invokeFunction(id, data) {
1246
+ return this.functions.invoke(id, data);
1247
+ }
1248
+ // API Keys shortcuts
1249
+ async createApiKey(name, permissions, expiresAt) {
1250
+ return this.apiKeys.create(name, permissions, expiresAt);
1251
+ }
1252
+ async listApiKeys() {
1253
+ return this.apiKeys.list();
1254
+ }
1255
+ async revokeApiKey(keyId) {
1256
+ return this.apiKeys.revoke(keyId);
1257
+ }
1258
+ async deleteApiKey(keyId) {
1259
+ return this.apiKeys.delete(keyId);
1260
+ }
1261
+ // Backups shortcuts
1262
+ async createBackup(options) {
1263
+ return this.backups.create(options);
1264
+ }
1265
+ async listBackups() {
1266
+ return this.backups.list();
1267
+ }
1268
+ async getBackup(backupId) {
1269
+ return this.backups.get(backupId);
1270
+ }
1271
+ async restoreBackup(backupId) {
1272
+ return this.backups.restore(backupId);
1273
+ }
1274
+ async deleteBackup(backupId) {
1275
+ return this.backups.delete(backupId);
1276
+ }
1277
+ getBackupDownloadUrl(backupId) {
1278
+ return this.backups.getDownloadUrl(backupId);
1279
+ }
1280
+ async listBackupTables() {
1281
+ return this.backups.listTables();
1282
+ }
1283
+ async importFile(formData) {
1284
+ return this.backups.importFile(formData);
1285
+ }
1286
+ // Search shortcuts
1287
+ async search(query, options) {
1288
+ return this.searchService.search(query, options);
1289
+ }
1290
+ async createSearchIndex(table, columns) {
1291
+ return this.searchService.createIndex(table, columns);
1292
+ }
1293
+ // GraphQL shortcuts
1294
+ async graphql(query, variables) {
1295
+ return this.graphqlService.query(query, variables);
1296
+ }
1297
+ getGraphQLPlaygroundUrl() {
1298
+ return this.graphqlService.getPlaygroundUrl();
1299
+ }
1300
+ // Migrations shortcuts
1301
+ async createMigration(input) {
1302
+ return this.migrations.create(input);
1303
+ }
1304
+ async listMigrations() {
1305
+ return this.migrations.list();
1306
+ }
1307
+ async getMigration(id) {
1308
+ return this.migrations.get(id);
1309
+ }
1310
+ async applyMigration(id) {
1311
+ return this.migrations.apply(id);
1312
+ }
1313
+ async rollbackMigration(id) {
1314
+ return this.migrations.rollback(id);
1315
+ }
1316
+ async deleteMigration(id) {
1317
+ return this.migrations.delete(id);
1318
+ }
1319
+ async generateMigration(tableName, changes) {
1320
+ return this.migrations.generate(tableName, changes);
1321
+ }
1322
+ // Email shortcuts
1323
+ async sendEmail(input) {
1324
+ return this.email.send(input);
1325
+ }
1326
+ async getEmailConfig() {
1327
+ return this.email.getConfig();
1328
+ }
1329
+ async saveEmailConfig(config) {
1330
+ return this.email.saveConfig(config);
1331
+ }
1332
+ async createEmailTemplate(template) {
1333
+ return this.email.createTemplate(template);
1334
+ }
1335
+ async listEmailTemplates() {
1336
+ return this.email.listTemplates();
1337
+ }
1338
+ async getEmailTemplate(id) {
1339
+ return this.email.getTemplate(id);
1340
+ }
1341
+ async updateEmailTemplate(id, template) {
1342
+ return this.email.updateTemplate(id, template);
1343
+ }
1344
+ async deleteEmailTemplate(id) {
1345
+ return this.email.deleteTemplate(id);
1346
+ }
1347
+ async getEmailLogs(options) {
1348
+ return this.email.getLogs(options);
1349
+ }
1350
+ // Metrics shortcuts
1351
+ async getDashboardStats() {
1352
+ return this.metrics.getDashboardStats();
1353
+ }
1354
+ async getRequestLogs(options) {
1355
+ return this.metrics.getRequestLogs(options);
1356
+ }
1357
+ async getApplicationLogs(options) {
1358
+ return this.metrics.getApplicationLogs(options);
1359
+ }
1360
+ async getMetricTimeseries(metric, options) {
1361
+ return this.metrics.getTimeseries(metric, options);
1362
+ }
1363
+ // Jobs shortcuts
1364
+ async createJob(input) {
1365
+ return this.jobs.create(input);
1366
+ }
1367
+ async listJobs() {
1368
+ return this.jobs.list();
1369
+ }
1370
+ async getJob(id) {
1371
+ return this.jobs.get(id);
1372
+ }
1373
+ async updateJob(id, input) {
1374
+ return this.jobs.update(id, input);
1375
+ }
1376
+ async deleteJob(id) {
1377
+ return this.jobs.delete(id);
1378
+ }
1379
+ async toggleJob(id, enabled) {
1380
+ return this.jobs.toggle(id, enabled);
1381
+ }
1382
+ async runJobNow(id) {
1383
+ return this.jobs.runNow(id);
1384
+ }
1385
+ async getJobExecutions(id, limit) {
1386
+ return this.jobs.getExecutions(id, limit);
1387
+ }
1388
+ // Env Vars shortcuts
1389
+ async createEnvVar(input) {
1390
+ return this.envVars.create(input);
1391
+ }
1392
+ async listEnvVars() {
1393
+ return this.envVars.list();
1394
+ }
1395
+ async getEnvVar(id) {
1396
+ return this.envVars.get(id);
1397
+ }
1398
+ async updateEnvVar(id, value) {
1399
+ return this.envVars.update(id, value);
1400
+ }
1401
+ async deleteEnvVar(id) {
1402
+ return this.envVars.delete(id);
1403
+ }
1404
+ // Branches shortcuts
1405
+ async createBranch(input) {
1406
+ return this.branches.create(input);
1407
+ }
1408
+ async listBranches() {
1409
+ return this.branches.list();
1410
+ }
1411
+ async getBranch(id) {
1412
+ return this.branches.get(id);
1413
+ }
1414
+ async deleteBranch(id) {
1415
+ return this.branches.delete(id);
1416
+ }
1417
+ async mergeBranch(id, targetBranchId) {
1418
+ return this.branches.merge(id, targetBranchId);
1419
+ }
1420
+ async resetBranch(id) {
1421
+ return this.branches.reset(id);
1422
+ }
1423
+ // Log Drains shortcuts
1424
+ async createLogDrain(input) {
1425
+ return this.logDrains.create(input);
1426
+ }
1427
+ async listLogDrains() {
1428
+ return this.logDrains.list();
1429
+ }
1430
+ async getLogDrain(id) {
1431
+ return this.logDrains.get(id);
1432
+ }
1433
+ async updateLogDrain(id, input) {
1434
+ return this.logDrains.update(id, input);
1435
+ }
1436
+ async deleteLogDrain(id) {
1437
+ return this.logDrains.delete(id);
1438
+ }
1439
+ async toggleLogDrain(id, enabled) {
1440
+ return this.logDrains.toggle(id, enabled);
1441
+ }
1442
+ async testLogDrain(id) {
1443
+ return this.logDrains.test(id);
1444
+ }
1445
+ // Webhooks shortcuts
1446
+ async listWebhooks() {
1447
+ return this.webhooks.list();
1448
+ }
1449
+ async getWebhook(id) {
1450
+ return this.webhooks.get(id);
1451
+ }
1452
+ async createWebhook(input) {
1453
+ return this.webhooks.create(input);
1454
+ }
1455
+ async updateWebhook(id, input) {
1456
+ return this.webhooks.update(id, input);
1457
+ }
1458
+ async deleteWebhook(id) {
1459
+ return this.webhooks.delete(id);
1460
+ }
1461
+ async testWebhook(id) {
1462
+ return this.webhooks.test(id);
1463
+ }
1464
+ // Audit shortcuts
1465
+ async listAuditLogs(options) {
1466
+ return this.audit.list(options);
1467
+ }
1468
+ async getAuditActions() {
1469
+ return this.audit.getActions();
1470
+ }
1471
+ // Realtime shortcuts
1472
+ subscribe(table, action, callback) {
1473
+ return this.realtime.subscribe(table, action, callback);
1474
+ }
1475
+ // Environment shortcuts
1476
+ async getEnvironmentStatus() {
1477
+ return this.environments.status();
1478
+ }
1479
+ async initTestEnvironment() {
1480
+ return this.environments.init();
1481
+ }
1482
+ async promoteTestToProd() {
1483
+ return this.environments.promote();
1484
+ }
1485
+ async revertTestEnvironment() {
1486
+ return this.environments.revert();
1487
+ }
1488
+ };
1489
+ // Annotate the CommonJS export names for ESM import in node:
1490
+ 0 && (module.exports = {
1491
+ BaasClient,
1492
+ HttpClient,
1493
+ QueryBuilder
1494
+ });