@giaeulate/baas-sdk 1.0.7 → 1.0.9

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 CHANGED
@@ -490,18 +490,62 @@ function createDatabaseModule(client) {
490
490
 
491
491
  // src/modules/storage.ts
492
492
  function createStorageModule(client) {
493
+ const get = (endpoint) => client.get(endpoint);
494
+ const post = (endpoint, body) => client.post(endpoint, body);
495
+ const del = (endpoint) => client.delete(endpoint);
496
+ async function uploadFile(fileOrTable, fileOrBucketId) {
497
+ let file;
498
+ let bucketId;
499
+ if (fileOrTable instanceof File) {
500
+ file = fileOrTable;
501
+ bucketId = typeof fileOrBucketId === "string" ? fileOrBucketId : void 0;
502
+ } else {
503
+ file = fileOrBucketId;
504
+ bucketId = void 0;
505
+ }
506
+ const formData = new FormData();
507
+ formData.append("file", file);
508
+ if (bucketId) {
509
+ formData.append("bucket_id", bucketId);
510
+ }
511
+ const headers = client.getHeaders("");
512
+ const res = await fetch(`${client.url}/api/storage/upload`, {
513
+ method: "POST",
514
+ headers,
515
+ body: formData
516
+ });
517
+ if (!res.ok) {
518
+ if (res.status === 401) client.forceLogout();
519
+ const err = await res.json().catch(() => ({ error: `Upload failed: ${res.status}` }));
520
+ throw new Error(err.error ?? `Upload failed: ${res.status}`);
521
+ }
522
+ return res.json();
523
+ }
493
524
  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;
525
+ upload: uploadFile,
526
+ async listFiles() {
527
+ return get("/api/storage/files");
528
+ },
529
+ async getFile(fileId) {
530
+ return get(`/api/storage/files/${fileId}`);
531
+ },
532
+ async deleteFile(fileId) {
533
+ return del(`/api/storage/files/${fileId}`);
534
+ },
535
+ async createBucket(name, isPublic = false) {
536
+ return post("/api/storage/buckets", { name, is_public: isPublic });
537
+ },
538
+ async listBuckets() {
539
+ return get("/api/storage/buckets");
540
+ },
541
+ async getBucket(bucketId) {
542
+ return get(`/api/storage/buckets/${bucketId}`);
543
+ },
544
+ async deleteBucket(bucketId) {
545
+ return del(`/api/storage/buckets/${bucketId}`);
546
+ },
547
+ async listBucketFiles(bucketId) {
548
+ return get(`/api/storage/buckets/${bucketId}/files`);
505
549
  }
506
550
  };
507
551
  }
@@ -914,7 +958,7 @@ var RealtimeService = class {
914
958
  reject(new Error("Missing authentication token for Realtime connection"));
915
959
  return;
916
960
  }
917
- const wsUrl = this.url.replace(/^http/, "ws") + "/ws";
961
+ const wsUrl = this.url.replace(/^http/, "ws") + "/api/ws";
918
962
  const fullUrl = this.apiKey ? `${wsUrl}?apikey=${this.apiKey}&token=${token}` : `${wsUrl}?token=${token}`;
919
963
  if (!this.wsConstructor) {
920
964
  reject(new Error("WebSocket constructor not provided or available in this environment"));
@@ -1264,8 +1308,32 @@ var BaasClient = class extends HttpClient {
1264
1308
  return this.database.downloadExport(tableName, format, filters);
1265
1309
  }
1266
1310
  // Storage shortcuts
1267
- async upload(table, file) {
1268
- return this.storage.upload(table, file);
1311
+ async upload(file, bucketId) {
1312
+ return this.storage.upload(file, bucketId);
1313
+ }
1314
+ async listStorageFiles() {
1315
+ return this.storage.listFiles();
1316
+ }
1317
+ async getStorageFile(fileId) {
1318
+ return this.storage.getFile(fileId);
1319
+ }
1320
+ async deleteStorageFile(fileId) {
1321
+ return this.storage.deleteFile(fileId);
1322
+ }
1323
+ async createStorageBucket(name, isPublic) {
1324
+ return this.storage.createBucket(name, isPublic);
1325
+ }
1326
+ async listStorageBuckets() {
1327
+ return this.storage.listBuckets();
1328
+ }
1329
+ async getStorageBucket(bucketId) {
1330
+ return this.storage.getBucket(bucketId);
1331
+ }
1332
+ async deleteStorageBucket(bucketId) {
1333
+ return this.storage.deleteBucket(bucketId);
1334
+ }
1335
+ async listStorageBucketFiles(bucketId) {
1336
+ return this.storage.listBucketFiles(bucketId);
1269
1337
  }
1270
1338
  // Functions shortcuts
1271
1339
  async invokeFunction(id, data) {
package/dist/index.d.cts CHANGED
@@ -265,10 +265,50 @@ interface DatabaseModule {
265
265
  }
266
266
 
267
267
  /**
268
- * Storage Module - File storage operations
268
+ * Storage Module - File & bucket operations (MinIO-backed)
269
+ *
270
+ * Files: upload, list, get (metadata + presigned URL), delete
271
+ * Buckets: create, list, get, delete, listFiles
269
272
  */
270
273
 
274
+ interface StorageFile {
275
+ id: string;
276
+ bucket_id: string;
277
+ name: string;
278
+ mime_type: string;
279
+ size: number;
280
+ created_at: string;
281
+ }
282
+ interface StorageFileWithUrl {
283
+ metadata: StorageFile;
284
+ url: string;
285
+ }
286
+ interface StorageBucket {
287
+ id: string;
288
+ name: string;
289
+ is_public: boolean;
290
+ created_at: string;
291
+ }
271
292
  interface StorageModule {
293
+ /** Upload a file. Optionally target a specific bucket by ID. */
294
+ upload(file: File, bucketId?: string): Promise<StorageFile>;
295
+ /** List all files across buckets. */
296
+ listFiles(): Promise<StorageFile[]>;
297
+ /** Get file metadata + a 15-min presigned download URL. */
298
+ getFile(fileId: string): Promise<StorageFileWithUrl>;
299
+ /** Delete a file by ID. */
300
+ deleteFile(fileId: string): Promise<void>;
301
+ /** Create a new bucket. */
302
+ createBucket(name: string, isPublic?: boolean): Promise<StorageBucket>;
303
+ /** List all buckets. */
304
+ listBuckets(): Promise<StorageBucket[]>;
305
+ /** Get bucket info by ID. */
306
+ getBucket(bucketId: string): Promise<StorageBucket>;
307
+ /** Delete an empty bucket. */
308
+ deleteBucket(bucketId: string): Promise<void>;
309
+ /** List files inside a specific bucket. */
310
+ listBucketFiles(bucketId: string): Promise<StorageFile[]>;
311
+ /** @deprecated Use upload(file, bucketId?) instead. */
272
312
  upload(table: string, file: File): Promise<any>;
273
313
  }
274
314
 
@@ -680,7 +720,15 @@ declare class BaasClient extends HttpClient {
680
720
  dropConstraint(tableName: string, constraintName: string): Promise<any>;
681
721
  queryData(tableName: string, options: any): Promise<any>;
682
722
  downloadExport(tableName: string, format: 'sql' | 'csv' | 'backup', filters?: any[]): Promise<any>;
683
- upload(table: string, file: File): Promise<any>;
723
+ upload(file: File, bucketId?: string): Promise<StorageFile>;
724
+ listStorageFiles(): Promise<StorageFile[]>;
725
+ getStorageFile(fileId: string): Promise<StorageFileWithUrl>;
726
+ deleteStorageFile(fileId: string): Promise<void>;
727
+ createStorageBucket(name: string, isPublic?: boolean): Promise<StorageBucket>;
728
+ listStorageBuckets(): Promise<StorageBucket[]>;
729
+ getStorageBucket(bucketId: string): Promise<StorageBucket>;
730
+ deleteStorageBucket(bucketId: string): Promise<void>;
731
+ listStorageBucketFiles(bucketId: string): Promise<StorageFile[]>;
684
732
  invokeFunction(id: string, data?: any): Promise<any>;
685
733
  createApiKey(name: string, permissions?: string[], expiresAt?: string): Promise<any>;
686
734
  listApiKeys(): Promise<any>;
@@ -764,4 +812,4 @@ declare class BaasClient extends HttpClient {
764
812
  deleteCorsOrigin(id: string): Promise<any>;
765
813
  }
766
814
 
767
- export { type ApiKeysModule, type ApiResponse, type ApplicationLogsOptions, type AuditLogsOptions, type AuditModule, type AuthModule, BaasClient, type BackupsModule, type BranchesModule, type CorsOriginsModule, type DatabaseModule, type EmailConfig, type EmailModule, type EmailTemplate, type EnvVarsModule, type FunctionsModule, type GraphQLModule, HttpClient, type HttpMethod, type JobInput, type JobUpdateInput, type JobsModule, type LogDrainInput, type LogDrainUpdateInput, type LogDrainsModule, type MetricsModule, type MigrationsModule, type PaginationOptions, QueryBuilder, type QueryFilter, type RealtimeModule, type RequestLogsOptions, type RequestOptions, type SearchModule, type SearchOptions, type SendEmailInput, type StorageModule, type Subscription, type TimeseriesOptions, type UsersModule, type WebhookInput, type WebhookUpdateInput, type WebhooksModule };
815
+ export { type ApiKeysModule, type ApiResponse, type ApplicationLogsOptions, type AuditLogsOptions, type AuditModule, type AuthModule, BaasClient, type BackupsModule, type BranchesModule, type CorsOriginsModule, type DatabaseModule, type EmailConfig, type EmailModule, type EmailTemplate, type EnvVarsModule, type FunctionsModule, type GraphQLModule, HttpClient, type HttpMethod, type JobInput, type JobUpdateInput, type JobsModule, type LogDrainInput, type LogDrainUpdateInput, type LogDrainsModule, type MetricsModule, type MigrationsModule, type PaginationOptions, QueryBuilder, type QueryFilter, type RealtimeModule, type RequestLogsOptions, type RequestOptions, type SearchModule, type SearchOptions, type SendEmailInput, type StorageBucket, type StorageFile, type StorageFileWithUrl, type StorageModule, type Subscription, type TimeseriesOptions, type UsersModule, type WebhookInput, type WebhookUpdateInput, type WebhooksModule };
package/dist/index.d.ts CHANGED
@@ -265,10 +265,50 @@ interface DatabaseModule {
265
265
  }
266
266
 
267
267
  /**
268
- * Storage Module - File storage operations
268
+ * Storage Module - File & bucket operations (MinIO-backed)
269
+ *
270
+ * Files: upload, list, get (metadata + presigned URL), delete
271
+ * Buckets: create, list, get, delete, listFiles
269
272
  */
270
273
 
274
+ interface StorageFile {
275
+ id: string;
276
+ bucket_id: string;
277
+ name: string;
278
+ mime_type: string;
279
+ size: number;
280
+ created_at: string;
281
+ }
282
+ interface StorageFileWithUrl {
283
+ metadata: StorageFile;
284
+ url: string;
285
+ }
286
+ interface StorageBucket {
287
+ id: string;
288
+ name: string;
289
+ is_public: boolean;
290
+ created_at: string;
291
+ }
271
292
  interface StorageModule {
293
+ /** Upload a file. Optionally target a specific bucket by ID. */
294
+ upload(file: File, bucketId?: string): Promise<StorageFile>;
295
+ /** List all files across buckets. */
296
+ listFiles(): Promise<StorageFile[]>;
297
+ /** Get file metadata + a 15-min presigned download URL. */
298
+ getFile(fileId: string): Promise<StorageFileWithUrl>;
299
+ /** Delete a file by ID. */
300
+ deleteFile(fileId: string): Promise<void>;
301
+ /** Create a new bucket. */
302
+ createBucket(name: string, isPublic?: boolean): Promise<StorageBucket>;
303
+ /** List all buckets. */
304
+ listBuckets(): Promise<StorageBucket[]>;
305
+ /** Get bucket info by ID. */
306
+ getBucket(bucketId: string): Promise<StorageBucket>;
307
+ /** Delete an empty bucket. */
308
+ deleteBucket(bucketId: string): Promise<void>;
309
+ /** List files inside a specific bucket. */
310
+ listBucketFiles(bucketId: string): Promise<StorageFile[]>;
311
+ /** @deprecated Use upload(file, bucketId?) instead. */
272
312
  upload(table: string, file: File): Promise<any>;
273
313
  }
274
314
 
@@ -680,7 +720,15 @@ declare class BaasClient extends HttpClient {
680
720
  dropConstraint(tableName: string, constraintName: string): Promise<any>;
681
721
  queryData(tableName: string, options: any): Promise<any>;
682
722
  downloadExport(tableName: string, format: 'sql' | 'csv' | 'backup', filters?: any[]): Promise<any>;
683
- upload(table: string, file: File): Promise<any>;
723
+ upload(file: File, bucketId?: string): Promise<StorageFile>;
724
+ listStorageFiles(): Promise<StorageFile[]>;
725
+ getStorageFile(fileId: string): Promise<StorageFileWithUrl>;
726
+ deleteStorageFile(fileId: string): Promise<void>;
727
+ createStorageBucket(name: string, isPublic?: boolean): Promise<StorageBucket>;
728
+ listStorageBuckets(): Promise<StorageBucket[]>;
729
+ getStorageBucket(bucketId: string): Promise<StorageBucket>;
730
+ deleteStorageBucket(bucketId: string): Promise<void>;
731
+ listStorageBucketFiles(bucketId: string): Promise<StorageFile[]>;
684
732
  invokeFunction(id: string, data?: any): Promise<any>;
685
733
  createApiKey(name: string, permissions?: string[], expiresAt?: string): Promise<any>;
686
734
  listApiKeys(): Promise<any>;
@@ -764,4 +812,4 @@ declare class BaasClient extends HttpClient {
764
812
  deleteCorsOrigin(id: string): Promise<any>;
765
813
  }
766
814
 
767
- export { type ApiKeysModule, type ApiResponse, type ApplicationLogsOptions, type AuditLogsOptions, type AuditModule, type AuthModule, BaasClient, type BackupsModule, type BranchesModule, type CorsOriginsModule, type DatabaseModule, type EmailConfig, type EmailModule, type EmailTemplate, type EnvVarsModule, type FunctionsModule, type GraphQLModule, HttpClient, type HttpMethod, type JobInput, type JobUpdateInput, type JobsModule, type LogDrainInput, type LogDrainUpdateInput, type LogDrainsModule, type MetricsModule, type MigrationsModule, type PaginationOptions, QueryBuilder, type QueryFilter, type RealtimeModule, type RequestLogsOptions, type RequestOptions, type SearchModule, type SearchOptions, type SendEmailInput, type StorageModule, type Subscription, type TimeseriesOptions, type UsersModule, type WebhookInput, type WebhookUpdateInput, type WebhooksModule };
815
+ export { type ApiKeysModule, type ApiResponse, type ApplicationLogsOptions, type AuditLogsOptions, type AuditModule, type AuthModule, BaasClient, type BackupsModule, type BranchesModule, type CorsOriginsModule, type DatabaseModule, type EmailConfig, type EmailModule, type EmailTemplate, type EnvVarsModule, type FunctionsModule, type GraphQLModule, HttpClient, type HttpMethod, type JobInput, type JobUpdateInput, type JobsModule, type LogDrainInput, type LogDrainUpdateInput, type LogDrainsModule, type MetricsModule, type MigrationsModule, type PaginationOptions, QueryBuilder, type QueryFilter, type RealtimeModule, type RequestLogsOptions, type RequestOptions, type SearchModule, type SearchOptions, type SendEmailInput, type StorageBucket, type StorageFile, type StorageFileWithUrl, type StorageModule, type Subscription, type TimeseriesOptions, type UsersModule, type WebhookInput, type WebhookUpdateInput, type WebhooksModule };
package/dist/index.js CHANGED
@@ -462,18 +462,62 @@ function createDatabaseModule(client) {
462
462
 
463
463
  // src/modules/storage.ts
464
464
  function createStorageModule(client) {
465
+ const get = (endpoint) => client.get(endpoint);
466
+ const post = (endpoint, body) => client.post(endpoint, body);
467
+ const del = (endpoint) => client.delete(endpoint);
468
+ async function uploadFile(fileOrTable, fileOrBucketId) {
469
+ let file;
470
+ let bucketId;
471
+ if (fileOrTable instanceof File) {
472
+ file = fileOrTable;
473
+ bucketId = typeof fileOrBucketId === "string" ? fileOrBucketId : void 0;
474
+ } else {
475
+ file = fileOrBucketId;
476
+ bucketId = void 0;
477
+ }
478
+ const formData = new FormData();
479
+ formData.append("file", file);
480
+ if (bucketId) {
481
+ formData.append("bucket_id", bucketId);
482
+ }
483
+ const headers = client.getHeaders("");
484
+ const res = await fetch(`${client.url}/api/storage/upload`, {
485
+ method: "POST",
486
+ headers,
487
+ body: formData
488
+ });
489
+ if (!res.ok) {
490
+ if (res.status === 401) client.forceLogout();
491
+ const err = await res.json().catch(() => ({ error: `Upload failed: ${res.status}` }));
492
+ throw new Error(err.error ?? `Upload failed: ${res.status}`);
493
+ }
494
+ return res.json();
495
+ }
465
496
  return {
466
- async upload(_table, file) {
467
- const formData = new FormData();
468
- formData.append("file", file);
469
- const res = await fetch(`${client.url}/api/storage/upload`, {
470
- method: "POST",
471
- headers: client.getHeaders(""),
472
- body: formData
473
- });
474
- const data = await res.json();
475
- if (!res.ok && res.status === 401) client.forceLogout();
476
- return data;
497
+ upload: uploadFile,
498
+ async listFiles() {
499
+ return get("/api/storage/files");
500
+ },
501
+ async getFile(fileId) {
502
+ return get(`/api/storage/files/${fileId}`);
503
+ },
504
+ async deleteFile(fileId) {
505
+ return del(`/api/storage/files/${fileId}`);
506
+ },
507
+ async createBucket(name, isPublic = false) {
508
+ return post("/api/storage/buckets", { name, is_public: isPublic });
509
+ },
510
+ async listBuckets() {
511
+ return get("/api/storage/buckets");
512
+ },
513
+ async getBucket(bucketId) {
514
+ return get(`/api/storage/buckets/${bucketId}`);
515
+ },
516
+ async deleteBucket(bucketId) {
517
+ return del(`/api/storage/buckets/${bucketId}`);
518
+ },
519
+ async listBucketFiles(bucketId) {
520
+ return get(`/api/storage/buckets/${bucketId}/files`);
477
521
  }
478
522
  };
479
523
  }
@@ -886,7 +930,7 @@ var RealtimeService = class {
886
930
  reject(new Error("Missing authentication token for Realtime connection"));
887
931
  return;
888
932
  }
889
- const wsUrl = this.url.replace(/^http/, "ws") + "/ws";
933
+ const wsUrl = this.url.replace(/^http/, "ws") + "/api/ws";
890
934
  const fullUrl = this.apiKey ? `${wsUrl}?apikey=${this.apiKey}&token=${token}` : `${wsUrl}?token=${token}`;
891
935
  if (!this.wsConstructor) {
892
936
  reject(new Error("WebSocket constructor not provided or available in this environment"));
@@ -1236,8 +1280,32 @@ var BaasClient = class extends HttpClient {
1236
1280
  return this.database.downloadExport(tableName, format, filters);
1237
1281
  }
1238
1282
  // Storage shortcuts
1239
- async upload(table, file) {
1240
- return this.storage.upload(table, file);
1283
+ async upload(file, bucketId) {
1284
+ return this.storage.upload(file, bucketId);
1285
+ }
1286
+ async listStorageFiles() {
1287
+ return this.storage.listFiles();
1288
+ }
1289
+ async getStorageFile(fileId) {
1290
+ return this.storage.getFile(fileId);
1291
+ }
1292
+ async deleteStorageFile(fileId) {
1293
+ return this.storage.deleteFile(fileId);
1294
+ }
1295
+ async createStorageBucket(name, isPublic) {
1296
+ return this.storage.createBucket(name, isPublic);
1297
+ }
1298
+ async listStorageBuckets() {
1299
+ return this.storage.listBuckets();
1300
+ }
1301
+ async getStorageBucket(bucketId) {
1302
+ return this.storage.getBucket(bucketId);
1303
+ }
1304
+ async deleteStorageBucket(bucketId) {
1305
+ return this.storage.deleteBucket(bucketId);
1306
+ }
1307
+ async listStorageBucketFiles(bucketId) {
1308
+ return this.storage.listBucketFiles(bucketId);
1241
1309
  }
1242
1310
  // Functions shortcuts
1243
1311
  async invokeFunction(id, data) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giaeulate/baas-sdk",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Standalone SDK for BaaS Golang",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",