@giaeulate/baas-sdk 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -59,8 +59,10 @@ declare class HttpClient {
59
59
  apiKey: string;
60
60
  keyType: KeyType;
61
61
  token: string | null;
62
+ refreshToken: string | null;
62
63
  private environment;
63
64
  private _onForceLogout;
65
+ private _refreshing;
64
66
  constructor(url?: string, apiKey?: string, options?: ClientOptions);
65
67
  /** SECURITY: a service_role key bypasses RLS and grants admin over every
66
68
  * tenant. If it ends up in a browser bundle, anyone can extract it. Warn
@@ -71,6 +73,15 @@ declare class HttpClient {
71
73
  * Persists to both the in-memory property and localStorage so getDynamicToken() works.
72
74
  */
73
75
  setToken(token: string | null): void;
76
+ /** Persist the rotating refresh token (used by auto-refresh on 401). In the
77
+ * browser the server also sets an HttpOnly `baas_refresh` cookie, so storing
78
+ * it here is mainly for non-cookie clients (React Native). */
79
+ setRefreshToken(token: string | null): void;
80
+ private getRefreshToken;
81
+ /** Attempts a single token refresh, deduped across concurrent 401s. Sends the
82
+ * stored refresh token (falls back to the HttpOnly cookie in browsers). */
83
+ private tryRefresh;
84
+ private doRefresh;
74
85
  /**
75
86
  * Register a callback invoked on forced logout (401).
76
87
  * Use this in React Native instead of the default window.location redirect.
@@ -85,7 +96,7 @@ declare class HttpClient {
85
96
  /**
86
97
  * Core HTTP request method - DRY principle
87
98
  */
88
- protected request<T = any>(endpoint: string, options?: RequestOptions): Promise<T>;
99
+ protected request<T = any>(endpoint: string, options?: RequestOptions, _isRetry?: boolean): Promise<T>;
89
100
  protected get<T = any>(endpoint: string): Promise<T>;
90
101
  protected post<T = any>(endpoint: string, body?: unknown): Promise<T>;
91
102
  protected put<T = any>(endpoint: string, body?: unknown): Promise<T>;
@@ -242,6 +253,7 @@ interface MFASetupResponse {
242
253
  }
243
254
  interface AuthModule {
244
255
  login(email: string, password: string): Promise<any>;
256
+ refresh(): Promise<any>;
245
257
  logout(): Promise<void>;
246
258
  verifyMFA(mfaToken: string, code: string): Promise<any>;
247
259
  verifyMFAWithRecoveryCode(mfaToken: string, recoveryCode: string): Promise<any>;
@@ -357,6 +369,8 @@ interface StorageBucket {
357
369
  id: string;
358
370
  name: string;
359
371
  is_public: boolean;
372
+ /** Per-bucket upload cap in bytes (absent = no bucket-specific cap). */
373
+ max_bytes?: number;
360
374
  created_at: string;
361
375
  }
362
376
  interface StorageModule {
@@ -373,11 +387,12 @@ interface StorageModule {
373
387
  }>;
374
388
  /** Delete a file by ID. */
375
389
  deleteFile(fileId: string): Promise<void>;
376
- /** Create a new bucket. */
377
- createBucket(name: string, isPublic?: boolean): Promise<StorageBucket>;
378
- /** Update mutable bucket fields (is_public). */
390
+ /** Create a new bucket. maxBytes sets a per-bucket upload cap (omit for none). */
391
+ createBucket(name: string, isPublic?: boolean, maxBytes?: number): Promise<StorageBucket>;
392
+ /** Update mutable bucket fields (is_public, max_bytes). */
379
393
  updateBucket(bucketId: string, opts: {
380
394
  isPublic?: boolean;
395
+ maxBytes?: number;
381
396
  }): Promise<StorageBucket>;
382
397
  /** List all buckets. */
383
398
  listBuckets(): Promise<StorageBucket[]>;
@@ -517,21 +532,26 @@ interface EnvVarsModule {
517
532
  */
518
533
 
519
534
  interface EmailConfig {
535
+ id?: string;
520
536
  provider: string;
521
537
  smtp_host?: string;
522
538
  smtp_port?: number;
523
539
  smtp_user?: string;
524
540
  smtp_password?: string;
541
+ smtp_secure?: boolean;
525
542
  sendgrid_api_key?: string;
526
543
  resend_api_key?: string;
527
544
  from_email: string;
528
545
  from_name?: string;
546
+ label?: string;
547
+ is_default?: boolean;
529
548
  }
530
549
  interface EmailTemplate {
531
550
  name: string;
532
551
  subject: string;
533
552
  text_body?: string;
534
553
  html_body?: string;
554
+ email_config_id?: string | null;
535
555
  }
536
556
  interface SendEmailInput {
537
557
  to: string[];
@@ -539,12 +559,16 @@ interface SendEmailInput {
539
559
  text_body?: string;
540
560
  html_body?: string;
541
561
  template_id?: string;
562
+ config_id?: string;
542
563
  template_data?: Record<string, any>;
543
564
  }
544
565
  interface EmailModule {
545
566
  send(input: SendEmailInput): Promise<any>;
546
567
  getConfig(): Promise<any>;
568
+ listConfigs(): Promise<any>;
547
569
  saveConfig(config: EmailConfig): Promise<any>;
570
+ setDefaultConfig(id: string): Promise<any>;
571
+ deleteConfig(id: string): Promise<any>;
548
572
  createTemplate(template: EmailTemplate): Promise<any>;
549
573
  listTemplates(): Promise<any>;
550
574
  getTemplate(id: string): Promise<any>;
@@ -632,6 +656,7 @@ interface AuditModule {
632
656
  exportLogs(format: 'csv' | 'json', options?: AuditLogsOptions): Promise<any>;
633
657
  purgePreview(olderThanDays: number): Promise<any>;
634
658
  purge(olderThanDays: number): Promise<any>;
659
+ clearAll(): Promise<any>;
635
660
  }
636
661
 
637
662
  /**
@@ -709,14 +734,26 @@ interface BranchesModule {
709
734
  }
710
735
 
711
736
  /**
712
- * Realtime Module - WebSocket subscriptions
737
+ * Realtime Module - WebSocket subscriptions (CDC tables, Broadcast, Presence)
713
738
  */
714
739
 
715
740
  interface Subscription {
716
741
  unsubscribe: () => void;
717
742
  }
743
+ interface PresenceHandle {
744
+ leave: () => void;
745
+ }
718
746
  interface RealtimeModule {
719
- subscribe<T = any>(table: string, action: RealtimeAction, callback: RealtimeCallback<T>): Promise<Subscription>;
747
+ /** Subscribe to table changes. `filter` narrows delivery per-subscription
748
+ * (PostgREST-style "op.value" specs, e.g. { status: 'eq.pending' }). */
749
+ subscribe<T = any>(table: string, action: RealtimeAction, callback: RealtimeCallback<T>, filter?: Record<string, string>): Promise<Subscription>;
750
+ /** Subscribe to an ephemeral Broadcast channel (no DB, no RLS). */
751
+ subscribeBroadcast(channel: string, callback: (payload: any) => void): Promise<Subscription>;
752
+ /** Publish a message to a Broadcast channel. */
753
+ broadcast(channel: string, payload: unknown): void;
754
+ /** Join a Presence channel with an arbitrary state object. The callback
755
+ * receives sync/join/leave events with the member list. */
756
+ subscribePresence(channel: string, state: unknown, callback: (msg: any) => void): Promise<PresenceHandle>;
720
757
  }
721
758
 
722
759
  /**
@@ -728,6 +765,7 @@ interface ApiKeysModule {
728
765
  list(): Promise<any>;
729
766
  revoke(keyId: string): Promise<any>;
730
767
  delete(keyId: string): Promise<any>;
768
+ setBrand(keyId: string, emailConfigId: string): Promise<any>;
731
769
  getInstanceToken(): Promise<any>;
732
770
  regenerateInstanceToken(): Promise<any>;
733
771
  }
@@ -937,7 +975,7 @@ declare class BaasClient extends HttpClient {
937
975
  listStorageFiles(): Promise<StorageFile[]>;
938
976
  getStorageFile(fileId: string): Promise<StorageFileWithUrl>;
939
977
  deleteStorageFile(fileId: string): Promise<void>;
940
- createStorageBucket(name: string, isPublic?: boolean): Promise<StorageBucket>;
978
+ createStorageBucket(name: string, isPublic?: boolean, maxBytes?: number): Promise<StorageBucket>;
941
979
  listStorageBuckets(): Promise<StorageBucket[]>;
942
980
  getStorageBucket(bucketId: string): Promise<StorageBucket>;
943
981
  deleteStorageBucket(bucketId: string): Promise<void>;
@@ -947,6 +985,7 @@ declare class BaasClient extends HttpClient {
947
985
  listApiKeys(): Promise<any>;
948
986
  revokeApiKey(keyId: string): Promise<any>;
949
987
  deleteApiKey(keyId: string): Promise<any>;
988
+ setApiKeyBrand(keyId: string, emailConfigId: string): Promise<any>;
950
989
  getInstanceToken(): Promise<any>;
951
990
  regenerateInstanceToken(): Promise<any>;
952
991
  createBackup(options?: any): Promise<any>;
@@ -970,7 +1009,10 @@ declare class BaasClient extends HttpClient {
970
1009
  generateMigration(tableName: string, changes: any[]): Promise<any>;
971
1010
  sendEmail(input: any): Promise<any>;
972
1011
  getEmailConfig(): Promise<any>;
1012
+ listEmailConfigs(): Promise<any>;
973
1013
  saveEmailConfig(config: any): Promise<any>;
1014
+ setDefaultEmailConfig(id: string): Promise<any>;
1015
+ deleteEmailConfig(id: string): Promise<any>;
974
1016
  createEmailTemplate(template: any): Promise<any>;
975
1017
  listEmailTemplates(): Promise<any>;
976
1018
  getEmailTemplate(id: string): Promise<any>;
@@ -1018,7 +1060,8 @@ declare class BaasClient extends HttpClient {
1018
1060
  exportAuditLogs(format: 'csv' | 'json', options?: any): Promise<any>;
1019
1061
  previewPurgeAuditLogs(olderThanDays: number): Promise<any>;
1020
1062
  purgeAuditLogs(olderThanDays: number): Promise<any>;
1021
- subscribe<T = any>(table: string, action: RealtimeAction, callback: RealtimeCallback<T>): Promise<Subscription>;
1063
+ clearAllAuditLogs(): Promise<any>;
1064
+ subscribe<T = any>(table: string, action: RealtimeAction, callback: RealtimeCallback<T>, filter?: Record<string, string>): Promise<Subscription>;
1022
1065
  getEnvironmentStatus(): Promise<EnvironmentStatus>;
1023
1066
  initTestEnvironment(): Promise<any>;
1024
1067
  promoteTestToProd(): Promise<PromoteResult>;
package/dist/index.d.ts CHANGED
@@ -59,8 +59,10 @@ declare class HttpClient {
59
59
  apiKey: string;
60
60
  keyType: KeyType;
61
61
  token: string | null;
62
+ refreshToken: string | null;
62
63
  private environment;
63
64
  private _onForceLogout;
65
+ private _refreshing;
64
66
  constructor(url?: string, apiKey?: string, options?: ClientOptions);
65
67
  /** SECURITY: a service_role key bypasses RLS and grants admin over every
66
68
  * tenant. If it ends up in a browser bundle, anyone can extract it. Warn
@@ -71,6 +73,15 @@ declare class HttpClient {
71
73
  * Persists to both the in-memory property and localStorage so getDynamicToken() works.
72
74
  */
73
75
  setToken(token: string | null): void;
76
+ /** Persist the rotating refresh token (used by auto-refresh on 401). In the
77
+ * browser the server also sets an HttpOnly `baas_refresh` cookie, so storing
78
+ * it here is mainly for non-cookie clients (React Native). */
79
+ setRefreshToken(token: string | null): void;
80
+ private getRefreshToken;
81
+ /** Attempts a single token refresh, deduped across concurrent 401s. Sends the
82
+ * stored refresh token (falls back to the HttpOnly cookie in browsers). */
83
+ private tryRefresh;
84
+ private doRefresh;
74
85
  /**
75
86
  * Register a callback invoked on forced logout (401).
76
87
  * Use this in React Native instead of the default window.location redirect.
@@ -85,7 +96,7 @@ declare class HttpClient {
85
96
  /**
86
97
  * Core HTTP request method - DRY principle
87
98
  */
88
- protected request<T = any>(endpoint: string, options?: RequestOptions): Promise<T>;
99
+ protected request<T = any>(endpoint: string, options?: RequestOptions, _isRetry?: boolean): Promise<T>;
89
100
  protected get<T = any>(endpoint: string): Promise<T>;
90
101
  protected post<T = any>(endpoint: string, body?: unknown): Promise<T>;
91
102
  protected put<T = any>(endpoint: string, body?: unknown): Promise<T>;
@@ -242,6 +253,7 @@ interface MFASetupResponse {
242
253
  }
243
254
  interface AuthModule {
244
255
  login(email: string, password: string): Promise<any>;
256
+ refresh(): Promise<any>;
245
257
  logout(): Promise<void>;
246
258
  verifyMFA(mfaToken: string, code: string): Promise<any>;
247
259
  verifyMFAWithRecoveryCode(mfaToken: string, recoveryCode: string): Promise<any>;
@@ -357,6 +369,8 @@ interface StorageBucket {
357
369
  id: string;
358
370
  name: string;
359
371
  is_public: boolean;
372
+ /** Per-bucket upload cap in bytes (absent = no bucket-specific cap). */
373
+ max_bytes?: number;
360
374
  created_at: string;
361
375
  }
362
376
  interface StorageModule {
@@ -373,11 +387,12 @@ interface StorageModule {
373
387
  }>;
374
388
  /** Delete a file by ID. */
375
389
  deleteFile(fileId: string): Promise<void>;
376
- /** Create a new bucket. */
377
- createBucket(name: string, isPublic?: boolean): Promise<StorageBucket>;
378
- /** Update mutable bucket fields (is_public). */
390
+ /** Create a new bucket. maxBytes sets a per-bucket upload cap (omit for none). */
391
+ createBucket(name: string, isPublic?: boolean, maxBytes?: number): Promise<StorageBucket>;
392
+ /** Update mutable bucket fields (is_public, max_bytes). */
379
393
  updateBucket(bucketId: string, opts: {
380
394
  isPublic?: boolean;
395
+ maxBytes?: number;
381
396
  }): Promise<StorageBucket>;
382
397
  /** List all buckets. */
383
398
  listBuckets(): Promise<StorageBucket[]>;
@@ -517,21 +532,26 @@ interface EnvVarsModule {
517
532
  */
518
533
 
519
534
  interface EmailConfig {
535
+ id?: string;
520
536
  provider: string;
521
537
  smtp_host?: string;
522
538
  smtp_port?: number;
523
539
  smtp_user?: string;
524
540
  smtp_password?: string;
541
+ smtp_secure?: boolean;
525
542
  sendgrid_api_key?: string;
526
543
  resend_api_key?: string;
527
544
  from_email: string;
528
545
  from_name?: string;
546
+ label?: string;
547
+ is_default?: boolean;
529
548
  }
530
549
  interface EmailTemplate {
531
550
  name: string;
532
551
  subject: string;
533
552
  text_body?: string;
534
553
  html_body?: string;
554
+ email_config_id?: string | null;
535
555
  }
536
556
  interface SendEmailInput {
537
557
  to: string[];
@@ -539,12 +559,16 @@ interface SendEmailInput {
539
559
  text_body?: string;
540
560
  html_body?: string;
541
561
  template_id?: string;
562
+ config_id?: string;
542
563
  template_data?: Record<string, any>;
543
564
  }
544
565
  interface EmailModule {
545
566
  send(input: SendEmailInput): Promise<any>;
546
567
  getConfig(): Promise<any>;
568
+ listConfigs(): Promise<any>;
547
569
  saveConfig(config: EmailConfig): Promise<any>;
570
+ setDefaultConfig(id: string): Promise<any>;
571
+ deleteConfig(id: string): Promise<any>;
548
572
  createTemplate(template: EmailTemplate): Promise<any>;
549
573
  listTemplates(): Promise<any>;
550
574
  getTemplate(id: string): Promise<any>;
@@ -632,6 +656,7 @@ interface AuditModule {
632
656
  exportLogs(format: 'csv' | 'json', options?: AuditLogsOptions): Promise<any>;
633
657
  purgePreview(olderThanDays: number): Promise<any>;
634
658
  purge(olderThanDays: number): Promise<any>;
659
+ clearAll(): Promise<any>;
635
660
  }
636
661
 
637
662
  /**
@@ -709,14 +734,26 @@ interface BranchesModule {
709
734
  }
710
735
 
711
736
  /**
712
- * Realtime Module - WebSocket subscriptions
737
+ * Realtime Module - WebSocket subscriptions (CDC tables, Broadcast, Presence)
713
738
  */
714
739
 
715
740
  interface Subscription {
716
741
  unsubscribe: () => void;
717
742
  }
743
+ interface PresenceHandle {
744
+ leave: () => void;
745
+ }
718
746
  interface RealtimeModule {
719
- subscribe<T = any>(table: string, action: RealtimeAction, callback: RealtimeCallback<T>): Promise<Subscription>;
747
+ /** Subscribe to table changes. `filter` narrows delivery per-subscription
748
+ * (PostgREST-style "op.value" specs, e.g. { status: 'eq.pending' }). */
749
+ subscribe<T = any>(table: string, action: RealtimeAction, callback: RealtimeCallback<T>, filter?: Record<string, string>): Promise<Subscription>;
750
+ /** Subscribe to an ephemeral Broadcast channel (no DB, no RLS). */
751
+ subscribeBroadcast(channel: string, callback: (payload: any) => void): Promise<Subscription>;
752
+ /** Publish a message to a Broadcast channel. */
753
+ broadcast(channel: string, payload: unknown): void;
754
+ /** Join a Presence channel with an arbitrary state object. The callback
755
+ * receives sync/join/leave events with the member list. */
756
+ subscribePresence(channel: string, state: unknown, callback: (msg: any) => void): Promise<PresenceHandle>;
720
757
  }
721
758
 
722
759
  /**
@@ -728,6 +765,7 @@ interface ApiKeysModule {
728
765
  list(): Promise<any>;
729
766
  revoke(keyId: string): Promise<any>;
730
767
  delete(keyId: string): Promise<any>;
768
+ setBrand(keyId: string, emailConfigId: string): Promise<any>;
731
769
  getInstanceToken(): Promise<any>;
732
770
  regenerateInstanceToken(): Promise<any>;
733
771
  }
@@ -937,7 +975,7 @@ declare class BaasClient extends HttpClient {
937
975
  listStorageFiles(): Promise<StorageFile[]>;
938
976
  getStorageFile(fileId: string): Promise<StorageFileWithUrl>;
939
977
  deleteStorageFile(fileId: string): Promise<void>;
940
- createStorageBucket(name: string, isPublic?: boolean): Promise<StorageBucket>;
978
+ createStorageBucket(name: string, isPublic?: boolean, maxBytes?: number): Promise<StorageBucket>;
941
979
  listStorageBuckets(): Promise<StorageBucket[]>;
942
980
  getStorageBucket(bucketId: string): Promise<StorageBucket>;
943
981
  deleteStorageBucket(bucketId: string): Promise<void>;
@@ -947,6 +985,7 @@ declare class BaasClient extends HttpClient {
947
985
  listApiKeys(): Promise<any>;
948
986
  revokeApiKey(keyId: string): Promise<any>;
949
987
  deleteApiKey(keyId: string): Promise<any>;
988
+ setApiKeyBrand(keyId: string, emailConfigId: string): Promise<any>;
950
989
  getInstanceToken(): Promise<any>;
951
990
  regenerateInstanceToken(): Promise<any>;
952
991
  createBackup(options?: any): Promise<any>;
@@ -970,7 +1009,10 @@ declare class BaasClient extends HttpClient {
970
1009
  generateMigration(tableName: string, changes: any[]): Promise<any>;
971
1010
  sendEmail(input: any): Promise<any>;
972
1011
  getEmailConfig(): Promise<any>;
1012
+ listEmailConfigs(): Promise<any>;
973
1013
  saveEmailConfig(config: any): Promise<any>;
1014
+ setDefaultEmailConfig(id: string): Promise<any>;
1015
+ deleteEmailConfig(id: string): Promise<any>;
974
1016
  createEmailTemplate(template: any): Promise<any>;
975
1017
  listEmailTemplates(): Promise<any>;
976
1018
  getEmailTemplate(id: string): Promise<any>;
@@ -1018,7 +1060,8 @@ declare class BaasClient extends HttpClient {
1018
1060
  exportAuditLogs(format: 'csv' | 'json', options?: any): Promise<any>;
1019
1061
  previewPurgeAuditLogs(olderThanDays: number): Promise<any>;
1020
1062
  purgeAuditLogs(olderThanDays: number): Promise<any>;
1021
- subscribe<T = any>(table: string, action: RealtimeAction, callback: RealtimeCallback<T>): Promise<Subscription>;
1063
+ clearAllAuditLogs(): Promise<any>;
1064
+ subscribe<T = any>(table: string, action: RealtimeAction, callback: RealtimeCallback<T>, filter?: Record<string, string>): Promise<Subscription>;
1022
1065
  getEnvironmentStatus(): Promise<EnvironmentStatus>;
1023
1066
  initTestEnvironment(): Promise<any>;
1024
1067
  promoteTestToProd(): Promise<PromoteResult>;