@giaeulate/baas-sdk 1.1.0 → 1.1.1

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