@fluxbase/sdk 0.0.1-rc.27 → 0.0.1-rc.28

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
@@ -131,7 +131,7 @@ interface OrderBy {
131
131
  nulls?: 'first' | 'last';
132
132
  }
133
133
  interface RealtimeMessage {
134
- type: 'subscribe' | 'unsubscribe' | 'heartbeat' | 'broadcast' | 'ack' | 'error';
134
+ type: 'subscribe' | 'unsubscribe' | 'heartbeat' | 'broadcast' | 'presence' | 'ack' | 'error';
135
135
  channel?: string;
136
136
  event?: string;
137
137
  schema?: string;
@@ -140,6 +140,8 @@ interface RealtimeMessage {
140
140
  payload?: unknown;
141
141
  error?: string;
142
142
  config?: PostgresChangesConfig;
143
+ presence?: any;
144
+ broadcast?: any;
143
145
  }
144
146
  interface PostgresChangesConfig {
145
147
  event: 'INSERT' | 'UPDATE' | 'DELETE' | '*';
@@ -183,6 +185,57 @@ interface RealtimeChangePayload {
183
185
  timestamp: string;
184
186
  }
185
187
  type RealtimeCallback = (payload: RealtimePostgresChangesPayload) => void;
188
+ /**
189
+ * Realtime channel configuration options
190
+ */
191
+ interface RealtimeChannelConfig {
192
+ broadcast?: {
193
+ self?: boolean;
194
+ ack?: boolean;
195
+ };
196
+ presence?: {
197
+ key?: string;
198
+ };
199
+ }
200
+ /**
201
+ * Presence state for a user
202
+ */
203
+ interface PresenceState {
204
+ [key: string]: any;
205
+ }
206
+ /**
207
+ * Realtime presence payload structure
208
+ */
209
+ interface RealtimePresencePayload {
210
+ event: 'sync' | 'join' | 'leave';
211
+ key?: string;
212
+ newPresences?: PresenceState[];
213
+ leftPresences?: PresenceState[];
214
+ currentPresences?: Record<string, PresenceState[]>;
215
+ }
216
+ /**
217
+ * Presence callback type
218
+ */
219
+ type PresenceCallback = (payload: RealtimePresencePayload) => void;
220
+ /**
221
+ * Broadcast message structure
222
+ */
223
+ interface BroadcastMessage {
224
+ type: 'broadcast';
225
+ event: string;
226
+ payload: any;
227
+ }
228
+ /**
229
+ * Realtime broadcast payload structure
230
+ */
231
+ interface RealtimeBroadcastPayload {
232
+ event: string;
233
+ payload: any;
234
+ }
235
+ /**
236
+ * Broadcast callback type
237
+ */
238
+ type BroadcastCallback = (payload: RealtimeBroadcastPayload) => void;
186
239
  /**
187
240
  * File object returned by storage operations
188
241
  * Compatible with Supabase FileObject structure
@@ -1137,12 +1190,17 @@ declare class RealtimeChannel {
1137
1190
  private token;
1138
1191
  private channelName;
1139
1192
  private callbacks;
1193
+ private presenceCallbacks;
1194
+ private broadcastCallbacks;
1140
1195
  private subscriptionConfig;
1196
+ private _presenceState;
1197
+ private myPresenceKey;
1198
+ private config;
1141
1199
  private reconnectAttempts;
1142
1200
  private maxReconnectAttempts;
1143
1201
  private reconnectDelay;
1144
1202
  private heartbeatInterval;
1145
- constructor(url: string, channelName: string, token?: string | null);
1203
+ constructor(url: string, channelName: string, token?: string | null, config?: RealtimeChannelConfig);
1146
1204
  /**
1147
1205
  * Listen to postgres_changes with optional row-level filtering
1148
1206
  *
@@ -1179,6 +1237,42 @@ declare class RealtimeChannel {
1179
1237
  * ```
1180
1238
  */
1181
1239
  on(event: "INSERT" | "UPDATE" | "DELETE" | "*", callback: RealtimeCallback): this;
1240
+ /**
1241
+ * Listen to broadcast messages
1242
+ *
1243
+ * @param event - 'broadcast'
1244
+ * @param config - Configuration with event name
1245
+ * @param callback - Function to call when broadcast received
1246
+ * @returns This channel for chaining
1247
+ *
1248
+ * @example
1249
+ * ```typescript
1250
+ * channel.on('broadcast', { event: 'cursor-pos' }, (payload) => {
1251
+ * console.log('Cursor moved:', payload)
1252
+ * })
1253
+ * ```
1254
+ */
1255
+ on(event: "broadcast", config: {
1256
+ event: string;
1257
+ }, callback: BroadcastCallback): this;
1258
+ /**
1259
+ * Listen to presence events
1260
+ *
1261
+ * @param event - 'presence'
1262
+ * @param config - Configuration with event type (sync, join, leave)
1263
+ * @param callback - Function to call when presence changes
1264
+ * @returns This channel for chaining
1265
+ *
1266
+ * @example
1267
+ * ```typescript
1268
+ * channel.on('presence', { event: 'sync' }, (payload) => {
1269
+ * console.log('Presence synced:', payload)
1270
+ * })
1271
+ * ```
1272
+ */
1273
+ on(event: "presence", config: {
1274
+ event: "sync" | "join" | "leave";
1275
+ }, callback: PresenceCallback): this;
1182
1276
  /**
1183
1277
  * Remove a callback
1184
1278
  */
@@ -1195,6 +1289,60 @@ declare class RealtimeChannel {
1195
1289
  * @returns Promise resolving to status string (Supabase-compatible)
1196
1290
  */
1197
1291
  unsubscribe(timeout?: number): Promise<"ok" | "timed out" | "error">;
1292
+ /**
1293
+ * Send a broadcast message to all subscribers on this channel
1294
+ *
1295
+ * @param message - Broadcast message with type, event, and payload
1296
+ * @returns Promise resolving to status
1297
+ *
1298
+ * @example
1299
+ * ```typescript
1300
+ * await channel.send({
1301
+ * type: 'broadcast',
1302
+ * event: 'cursor-pos',
1303
+ * payload: { x: 100, y: 200 }
1304
+ * })
1305
+ * ```
1306
+ */
1307
+ send(message: BroadcastMessage): Promise<"ok" | "error">;
1308
+ /**
1309
+ * Track user presence on this channel
1310
+ *
1311
+ * @param state - Presence state to track
1312
+ * @returns Promise resolving to status
1313
+ *
1314
+ * @example
1315
+ * ```typescript
1316
+ * await channel.track({
1317
+ * user_id: 123,
1318
+ * status: 'online'
1319
+ * })
1320
+ * ```
1321
+ */
1322
+ track(state: PresenceState): Promise<"ok" | "error">;
1323
+ /**
1324
+ * Stop tracking presence on this channel
1325
+ *
1326
+ * @returns Promise resolving to status
1327
+ *
1328
+ * @example
1329
+ * ```typescript
1330
+ * await channel.untrack()
1331
+ * ```
1332
+ */
1333
+ untrack(): Promise<"ok" | "error">;
1334
+ /**
1335
+ * Get current presence state for all users on this channel
1336
+ *
1337
+ * @returns Current presence state
1338
+ *
1339
+ * @example
1340
+ * ```typescript
1341
+ * const state = channel.presenceState()
1342
+ * console.log('Online users:', Object.keys(state).length)
1343
+ * ```
1344
+ */
1345
+ presenceState(): Record<string, PresenceState[]>;
1198
1346
  /**
1199
1347
  * Internal: Connect to WebSocket
1200
1348
  */
@@ -1206,7 +1354,7 @@ declare class RealtimeChannel {
1206
1354
  /**
1207
1355
  * Internal: Send a message
1208
1356
  */
1209
- private send;
1357
+ private sendMessage;
1210
1358
  /**
1211
1359
  * Internal: Handle incoming message
1212
1360
  */
@@ -1214,7 +1362,15 @@ declare class RealtimeChannel {
1214
1362
  /**
1215
1363
  * Internal: Handle broadcast message
1216
1364
  */
1217
- private handleBroadcast;
1365
+ private handleBroadcastMessage;
1366
+ /**
1367
+ * Internal: Handle presence message
1368
+ */
1369
+ private handlePresenceMessage;
1370
+ /**
1371
+ * Internal: Handle postgres_changes message
1372
+ */
1373
+ private handlePostgresChanges;
1218
1374
  /**
1219
1375
  * Internal: Start heartbeat interval
1220
1376
  */
@@ -1234,18 +1390,43 @@ declare class FluxbaseRealtime {
1234
1390
  private channels;
1235
1391
  constructor(url: string, token?: string | null);
1236
1392
  /**
1237
- * Create or get a channel
1393
+ * Create or get a channel with optional configuration
1394
+ *
1238
1395
  * @param channelName - Channel name (e.g., 'table:public.products')
1396
+ * @param config - Optional channel configuration
1397
+ * @returns RealtimeChannel instance
1398
+ *
1399
+ * @example
1400
+ * ```typescript
1401
+ * const channel = realtime.channel('room-1', {
1402
+ * broadcast: { self: true, ack: true },
1403
+ * presence: { key: 'user-123' }
1404
+ * })
1405
+ * ```
1239
1406
  */
1240
- channel(channelName: string): RealtimeChannel;
1407
+ channel(channelName: string, config?: RealtimeChannelConfig): RealtimeChannel;
1408
+ /**
1409
+ * Remove a specific channel
1410
+ *
1411
+ * @param channel - The channel to remove
1412
+ * @returns Promise resolving to status
1413
+ *
1414
+ * @example
1415
+ * ```typescript
1416
+ * const channel = realtime.channel('room-1')
1417
+ * await realtime.removeChannel(channel)
1418
+ * ```
1419
+ */
1420
+ removeChannel(channel: RealtimeChannel): Promise<"ok" | "error">;
1241
1421
  /**
1242
1422
  * Remove all channels
1243
1423
  */
1244
1424
  removeAllChannels(): void;
1245
1425
  /**
1246
1426
  * Update auth token for all channels
1427
+ * @param token - The new auth token
1247
1428
  */
1248
- setToken(token: string | null): void;
1429
+ setAuth(token: string | null): void;
1249
1430
  }
1250
1431
 
1251
1432
  /**
@@ -4422,33 +4603,42 @@ declare class FluxbaseClient<Database = any, _SchemaName extends string & keyof
4422
4603
  */
4423
4604
  setAuthToken(token: string | null): void;
4424
4605
  /**
4425
- * Create or get a realtime channel (Supabase-compatible alias)
4426
- *
4427
- * This is a convenience method that delegates to client.realtime.channel().
4428
- * Both patterns work identically:
4429
- * - client.channel('room-1') - Supabase-style
4430
- * - client.realtime.channel('room-1') - Fluxbase-style
4606
+ * Create or get a realtime channel (Supabase-compatible)
4431
4607
  *
4432
4608
  * @param name - Channel name
4609
+ * @param config - Optional channel configuration
4433
4610
  * @returns RealtimeChannel instance
4434
4611
  *
4435
4612
  * @example
4436
4613
  * ```typescript
4437
- * // Supabase-compatible usage
4438
- * const channel = client.channel('room-1')
4439
- * .on('postgres_changes', {
4440
- * event: '*',
4441
- * schema: 'public',
4442
- * table: 'messages'
4443
- * }, (payload) => {
4444
- * console.log('Change:', payload)
4614
+ * const channel = client.channel('room-1', {
4615
+ * broadcast: { self: true },
4616
+ * presence: { key: 'user-123' }
4617
+ * })
4618
+ * .on('broadcast', { event: 'message' }, (payload) => {
4619
+ * console.log('Message:', payload)
4445
4620
  * })
4446
4621
  * .subscribe()
4447
4622
  * ```
4448
4623
  *
4449
4624
  * @category Realtime
4450
4625
  */
4451
- channel(name: string): RealtimeChannel;
4626
+ channel(name: string, config?: RealtimeChannelConfig): RealtimeChannel;
4627
+ /**
4628
+ * Remove a realtime channel (Supabase-compatible)
4629
+ *
4630
+ * @param channel - The channel to remove
4631
+ * @returns Promise resolving to status
4632
+ *
4633
+ * @example
4634
+ * ```typescript
4635
+ * const channel = client.channel('room-1')
4636
+ * await client.removeChannel(channel)
4637
+ * ```
4638
+ *
4639
+ * @category Realtime
4640
+ */
4641
+ removeChannel(channel: RealtimeChannel): Promise<"error" | "ok">;
4452
4642
  /**
4453
4643
  * Get the internal HTTP client
4454
4644
  *
@@ -4504,4 +4694,4 @@ declare class FluxbaseClient<Database = any, _SchemaName extends string & keyof
4504
4694
  */
4505
4695
  declare function createClient<Database = any, SchemaName extends string & keyof Database = any>(fluxbaseUrl: string, fluxbaseKey: string, options?: FluxbaseClientOptions): FluxbaseClient<Database, SchemaName>;
4506
4696
 
4507
- export { type APIKey, APIKeysManager, type AcceptInvitationRequest, type AcceptInvitationResponse, type AdminAuthResponse, type AdminLoginRequest, type AdminMeResponse, type AdminRefreshRequest, type AdminRefreshResponse, type AdminSetupRequest, type AdminSetupStatusResponse, type AdminUser, type AppSettings, AppSettingsManager, type AuthResponse, type AuthSession, type AuthSettings, AuthSettingsManager, type AuthenticationSettings, type Column, type CreateAPIKeyRequest, type CreateAPIKeyResponse, type CreateColumnRequest, type CreateFunctionRequest, type CreateInvitationRequest, type CreateInvitationResponse, type CreateOAuthProviderRequest, type CreateOAuthProviderResponse, type CreateSchemaRequest, type CreateSchemaResponse, type CreateTableRequest, type CreateTableResponse, type CreateWebhookRequest, DDLManager, type DataResponse, type DeleteAPIKeyResponse, type DeleteOAuthProviderResponse, type DeleteTableResponse, type DeleteUserResponse, type DeleteWebhookResponse, type EdgeFunction, type EdgeFunctionExecution, type EmailSettings, type EmailTemplate, EmailTemplateManager, type EmailTemplateType, type EnrichedUser, type FeatureSettings, type FileObject, type FilterOperator, FluxbaseAdmin, FluxbaseAuth, type FluxbaseAuthResponse, FluxbaseClient, type FluxbaseClientOptions, type FluxbaseError, FluxbaseFetch, FluxbaseFunctions, FluxbaseManagement, FluxbaseOAuth, FluxbaseRealtime, type FluxbaseResponse, FluxbaseSettings, FluxbaseStorage, type FunctionInvokeOptions, type GetImpersonationResponse, type HttpMethod, type ImpersonateAnonRequest, type ImpersonateServiceRequest, type ImpersonateUserRequest, ImpersonationManager, type ImpersonationSession, type ImpersonationTargetUser, type ImpersonationType, type Invitation, InvitationsManager, type InviteUserRequest, type InviteUserResponse, type ListAPIKeysResponse, type ListEmailTemplatesResponse, type ListImpersonationSessionsOptions, type ListImpersonationSessionsResponse, type ListInvitationsOptions, type ListInvitationsResponse, type ListOAuthProvidersResponse, type ListOptions, type ListSchemasResponse, type ListSystemSettingsResponse, type ListTablesResponse, type ListUsersOptions, type ListUsersResponse, type ListWebhookDeliveriesResponse, type ListWebhooksResponse, type MailgunSettings, type OAuthProvider, OAuthProviderManager, type OrderBy, type OrderDirection, type PostgresChangesConfig, type PostgrestError, type PostgrestResponse, QueryBuilder, type QueryFilter, type RealtimeCallback, type RealtimeChangePayload, RealtimeChannel, type RealtimeMessage, type RealtimePostgresChangesPayload, type RequestOptions, type ResetUserPasswordResponse, type RevokeAPIKeyResponse, type RevokeInvitationResponse, type SESSettings, type SMTPSettings, type Schema, type SecuritySettings, type SendGridSettings, type SessionResponse, SettingsClient, type SignInCredentials, type SignInWith2FAResponse, type SignUpCredentials, type SignedUrlOptions, type StartImpersonationResponse, type StopImpersonationResponse, StorageBucket, type StorageObject, type SupabaseAuthResponse, type SupabaseResponse, type SystemSetting, SystemSettingsManager, type Table, type TestEmailTemplateRequest, type TestWebhookResponse, type TwoFactorEnableResponse, type TwoFactorSetupResponse, type TwoFactorStatusResponse, type TwoFactorVerifyRequest, type UpdateAPIKeyRequest, type UpdateAppSettingsRequest, type UpdateAuthSettingsRequest, type UpdateAuthSettingsResponse, type UpdateEmailTemplateRequest, type UpdateFunctionRequest, type UpdateOAuthProviderRequest, type UpdateOAuthProviderResponse, type UpdateSystemSettingRequest, type UpdateUserRoleRequest, type UpdateWebhookRequest, type UploadOptions, type UploadProgress, type User, type UserResponse, type ValidateInvitationResponse, type VoidResponse, type Webhook, type WebhookDelivery, WebhooksManager, createClient };
4697
+ export { type APIKey, APIKeysManager, type AcceptInvitationRequest, type AcceptInvitationResponse, type AdminAuthResponse, type AdminLoginRequest, type AdminMeResponse, type AdminRefreshRequest, type AdminRefreshResponse, type AdminSetupRequest, type AdminSetupStatusResponse, type AdminUser, type AppSettings, AppSettingsManager, type AuthResponse, type AuthSession, type AuthSettings, AuthSettingsManager, type AuthenticationSettings, type BroadcastCallback, type BroadcastMessage, type Column, type CreateAPIKeyRequest, type CreateAPIKeyResponse, type CreateColumnRequest, type CreateFunctionRequest, type CreateInvitationRequest, type CreateInvitationResponse, type CreateOAuthProviderRequest, type CreateOAuthProviderResponse, type CreateSchemaRequest, type CreateSchemaResponse, type CreateTableRequest, type CreateTableResponse, type CreateWebhookRequest, DDLManager, type DataResponse, type DeleteAPIKeyResponse, type DeleteOAuthProviderResponse, type DeleteTableResponse, type DeleteUserResponse, type DeleteWebhookResponse, type EdgeFunction, type EdgeFunctionExecution, type EmailSettings, type EmailTemplate, EmailTemplateManager, type EmailTemplateType, type EnrichedUser, type FeatureSettings, type FileObject, type FilterOperator, FluxbaseAdmin, FluxbaseAuth, type FluxbaseAuthResponse, FluxbaseClient, type FluxbaseClientOptions, type FluxbaseError, FluxbaseFetch, FluxbaseFunctions, FluxbaseManagement, FluxbaseOAuth, FluxbaseRealtime, type FluxbaseResponse, FluxbaseSettings, FluxbaseStorage, type FunctionInvokeOptions, type GetImpersonationResponse, type HttpMethod, type ImpersonateAnonRequest, type ImpersonateServiceRequest, type ImpersonateUserRequest, ImpersonationManager, type ImpersonationSession, type ImpersonationTargetUser, type ImpersonationType, type Invitation, InvitationsManager, type InviteUserRequest, type InviteUserResponse, type ListAPIKeysResponse, type ListEmailTemplatesResponse, type ListImpersonationSessionsOptions, type ListImpersonationSessionsResponse, type ListInvitationsOptions, type ListInvitationsResponse, type ListOAuthProvidersResponse, type ListOptions, type ListSchemasResponse, type ListSystemSettingsResponse, type ListTablesResponse, type ListUsersOptions, type ListUsersResponse, type ListWebhookDeliveriesResponse, type ListWebhooksResponse, type MailgunSettings, type OAuthProvider, OAuthProviderManager, type OrderBy, type OrderDirection, type PostgresChangesConfig, type PostgrestError, type PostgrestResponse, type PresenceCallback, type PresenceState, QueryBuilder, type QueryFilter, type RealtimeBroadcastPayload, type RealtimeCallback, type RealtimeChangePayload, RealtimeChannel, type RealtimeChannelConfig, type RealtimeMessage, type RealtimePostgresChangesPayload, type RealtimePresencePayload, type RequestOptions, type ResetUserPasswordResponse, type RevokeAPIKeyResponse, type RevokeInvitationResponse, type SESSettings, type SMTPSettings, type Schema, type SecuritySettings, type SendGridSettings, type SessionResponse, SettingsClient, type SignInCredentials, type SignInWith2FAResponse, type SignUpCredentials, type SignedUrlOptions, type StartImpersonationResponse, type StopImpersonationResponse, StorageBucket, type StorageObject, type SupabaseAuthResponse, type SupabaseResponse, type SystemSetting, SystemSettingsManager, type Table, type TestEmailTemplateRequest, type TestWebhookResponse, type TwoFactorEnableResponse, type TwoFactorSetupResponse, type TwoFactorStatusResponse, type TwoFactorVerifyRequest, type UpdateAPIKeyRequest, type UpdateAppSettingsRequest, type UpdateAuthSettingsRequest, type UpdateAuthSettingsResponse, type UpdateEmailTemplateRequest, type UpdateFunctionRequest, type UpdateOAuthProviderRequest, type UpdateOAuthProviderResponse, type UpdateSystemSettingRequest, type UpdateUserRoleRequest, type UpdateWebhookRequest, type UploadOptions, type UploadProgress, type User, type UserResponse, type ValidateInvitationResponse, type VoidResponse, type Webhook, type WebhookDelivery, WebhooksManager, createClient };
package/dist/index.d.ts CHANGED
@@ -131,7 +131,7 @@ interface OrderBy {
131
131
  nulls?: 'first' | 'last';
132
132
  }
133
133
  interface RealtimeMessage {
134
- type: 'subscribe' | 'unsubscribe' | 'heartbeat' | 'broadcast' | 'ack' | 'error';
134
+ type: 'subscribe' | 'unsubscribe' | 'heartbeat' | 'broadcast' | 'presence' | 'ack' | 'error';
135
135
  channel?: string;
136
136
  event?: string;
137
137
  schema?: string;
@@ -140,6 +140,8 @@ interface RealtimeMessage {
140
140
  payload?: unknown;
141
141
  error?: string;
142
142
  config?: PostgresChangesConfig;
143
+ presence?: any;
144
+ broadcast?: any;
143
145
  }
144
146
  interface PostgresChangesConfig {
145
147
  event: 'INSERT' | 'UPDATE' | 'DELETE' | '*';
@@ -183,6 +185,57 @@ interface RealtimeChangePayload {
183
185
  timestamp: string;
184
186
  }
185
187
  type RealtimeCallback = (payload: RealtimePostgresChangesPayload) => void;
188
+ /**
189
+ * Realtime channel configuration options
190
+ */
191
+ interface RealtimeChannelConfig {
192
+ broadcast?: {
193
+ self?: boolean;
194
+ ack?: boolean;
195
+ };
196
+ presence?: {
197
+ key?: string;
198
+ };
199
+ }
200
+ /**
201
+ * Presence state for a user
202
+ */
203
+ interface PresenceState {
204
+ [key: string]: any;
205
+ }
206
+ /**
207
+ * Realtime presence payload structure
208
+ */
209
+ interface RealtimePresencePayload {
210
+ event: 'sync' | 'join' | 'leave';
211
+ key?: string;
212
+ newPresences?: PresenceState[];
213
+ leftPresences?: PresenceState[];
214
+ currentPresences?: Record<string, PresenceState[]>;
215
+ }
216
+ /**
217
+ * Presence callback type
218
+ */
219
+ type PresenceCallback = (payload: RealtimePresencePayload) => void;
220
+ /**
221
+ * Broadcast message structure
222
+ */
223
+ interface BroadcastMessage {
224
+ type: 'broadcast';
225
+ event: string;
226
+ payload: any;
227
+ }
228
+ /**
229
+ * Realtime broadcast payload structure
230
+ */
231
+ interface RealtimeBroadcastPayload {
232
+ event: string;
233
+ payload: any;
234
+ }
235
+ /**
236
+ * Broadcast callback type
237
+ */
238
+ type BroadcastCallback = (payload: RealtimeBroadcastPayload) => void;
186
239
  /**
187
240
  * File object returned by storage operations
188
241
  * Compatible with Supabase FileObject structure
@@ -1137,12 +1190,17 @@ declare class RealtimeChannel {
1137
1190
  private token;
1138
1191
  private channelName;
1139
1192
  private callbacks;
1193
+ private presenceCallbacks;
1194
+ private broadcastCallbacks;
1140
1195
  private subscriptionConfig;
1196
+ private _presenceState;
1197
+ private myPresenceKey;
1198
+ private config;
1141
1199
  private reconnectAttempts;
1142
1200
  private maxReconnectAttempts;
1143
1201
  private reconnectDelay;
1144
1202
  private heartbeatInterval;
1145
- constructor(url: string, channelName: string, token?: string | null);
1203
+ constructor(url: string, channelName: string, token?: string | null, config?: RealtimeChannelConfig);
1146
1204
  /**
1147
1205
  * Listen to postgres_changes with optional row-level filtering
1148
1206
  *
@@ -1179,6 +1237,42 @@ declare class RealtimeChannel {
1179
1237
  * ```
1180
1238
  */
1181
1239
  on(event: "INSERT" | "UPDATE" | "DELETE" | "*", callback: RealtimeCallback): this;
1240
+ /**
1241
+ * Listen to broadcast messages
1242
+ *
1243
+ * @param event - 'broadcast'
1244
+ * @param config - Configuration with event name
1245
+ * @param callback - Function to call when broadcast received
1246
+ * @returns This channel for chaining
1247
+ *
1248
+ * @example
1249
+ * ```typescript
1250
+ * channel.on('broadcast', { event: 'cursor-pos' }, (payload) => {
1251
+ * console.log('Cursor moved:', payload)
1252
+ * })
1253
+ * ```
1254
+ */
1255
+ on(event: "broadcast", config: {
1256
+ event: string;
1257
+ }, callback: BroadcastCallback): this;
1258
+ /**
1259
+ * Listen to presence events
1260
+ *
1261
+ * @param event - 'presence'
1262
+ * @param config - Configuration with event type (sync, join, leave)
1263
+ * @param callback - Function to call when presence changes
1264
+ * @returns This channel for chaining
1265
+ *
1266
+ * @example
1267
+ * ```typescript
1268
+ * channel.on('presence', { event: 'sync' }, (payload) => {
1269
+ * console.log('Presence synced:', payload)
1270
+ * })
1271
+ * ```
1272
+ */
1273
+ on(event: "presence", config: {
1274
+ event: "sync" | "join" | "leave";
1275
+ }, callback: PresenceCallback): this;
1182
1276
  /**
1183
1277
  * Remove a callback
1184
1278
  */
@@ -1195,6 +1289,60 @@ declare class RealtimeChannel {
1195
1289
  * @returns Promise resolving to status string (Supabase-compatible)
1196
1290
  */
1197
1291
  unsubscribe(timeout?: number): Promise<"ok" | "timed out" | "error">;
1292
+ /**
1293
+ * Send a broadcast message to all subscribers on this channel
1294
+ *
1295
+ * @param message - Broadcast message with type, event, and payload
1296
+ * @returns Promise resolving to status
1297
+ *
1298
+ * @example
1299
+ * ```typescript
1300
+ * await channel.send({
1301
+ * type: 'broadcast',
1302
+ * event: 'cursor-pos',
1303
+ * payload: { x: 100, y: 200 }
1304
+ * })
1305
+ * ```
1306
+ */
1307
+ send(message: BroadcastMessage): Promise<"ok" | "error">;
1308
+ /**
1309
+ * Track user presence on this channel
1310
+ *
1311
+ * @param state - Presence state to track
1312
+ * @returns Promise resolving to status
1313
+ *
1314
+ * @example
1315
+ * ```typescript
1316
+ * await channel.track({
1317
+ * user_id: 123,
1318
+ * status: 'online'
1319
+ * })
1320
+ * ```
1321
+ */
1322
+ track(state: PresenceState): Promise<"ok" | "error">;
1323
+ /**
1324
+ * Stop tracking presence on this channel
1325
+ *
1326
+ * @returns Promise resolving to status
1327
+ *
1328
+ * @example
1329
+ * ```typescript
1330
+ * await channel.untrack()
1331
+ * ```
1332
+ */
1333
+ untrack(): Promise<"ok" | "error">;
1334
+ /**
1335
+ * Get current presence state for all users on this channel
1336
+ *
1337
+ * @returns Current presence state
1338
+ *
1339
+ * @example
1340
+ * ```typescript
1341
+ * const state = channel.presenceState()
1342
+ * console.log('Online users:', Object.keys(state).length)
1343
+ * ```
1344
+ */
1345
+ presenceState(): Record<string, PresenceState[]>;
1198
1346
  /**
1199
1347
  * Internal: Connect to WebSocket
1200
1348
  */
@@ -1206,7 +1354,7 @@ declare class RealtimeChannel {
1206
1354
  /**
1207
1355
  * Internal: Send a message
1208
1356
  */
1209
- private send;
1357
+ private sendMessage;
1210
1358
  /**
1211
1359
  * Internal: Handle incoming message
1212
1360
  */
@@ -1214,7 +1362,15 @@ declare class RealtimeChannel {
1214
1362
  /**
1215
1363
  * Internal: Handle broadcast message
1216
1364
  */
1217
- private handleBroadcast;
1365
+ private handleBroadcastMessage;
1366
+ /**
1367
+ * Internal: Handle presence message
1368
+ */
1369
+ private handlePresenceMessage;
1370
+ /**
1371
+ * Internal: Handle postgres_changes message
1372
+ */
1373
+ private handlePostgresChanges;
1218
1374
  /**
1219
1375
  * Internal: Start heartbeat interval
1220
1376
  */
@@ -1234,18 +1390,43 @@ declare class FluxbaseRealtime {
1234
1390
  private channels;
1235
1391
  constructor(url: string, token?: string | null);
1236
1392
  /**
1237
- * Create or get a channel
1393
+ * Create or get a channel with optional configuration
1394
+ *
1238
1395
  * @param channelName - Channel name (e.g., 'table:public.products')
1396
+ * @param config - Optional channel configuration
1397
+ * @returns RealtimeChannel instance
1398
+ *
1399
+ * @example
1400
+ * ```typescript
1401
+ * const channel = realtime.channel('room-1', {
1402
+ * broadcast: { self: true, ack: true },
1403
+ * presence: { key: 'user-123' }
1404
+ * })
1405
+ * ```
1239
1406
  */
1240
- channel(channelName: string): RealtimeChannel;
1407
+ channel(channelName: string, config?: RealtimeChannelConfig): RealtimeChannel;
1408
+ /**
1409
+ * Remove a specific channel
1410
+ *
1411
+ * @param channel - The channel to remove
1412
+ * @returns Promise resolving to status
1413
+ *
1414
+ * @example
1415
+ * ```typescript
1416
+ * const channel = realtime.channel('room-1')
1417
+ * await realtime.removeChannel(channel)
1418
+ * ```
1419
+ */
1420
+ removeChannel(channel: RealtimeChannel): Promise<"ok" | "error">;
1241
1421
  /**
1242
1422
  * Remove all channels
1243
1423
  */
1244
1424
  removeAllChannels(): void;
1245
1425
  /**
1246
1426
  * Update auth token for all channels
1427
+ * @param token - The new auth token
1247
1428
  */
1248
- setToken(token: string | null): void;
1429
+ setAuth(token: string | null): void;
1249
1430
  }
1250
1431
 
1251
1432
  /**
@@ -4422,33 +4603,42 @@ declare class FluxbaseClient<Database = any, _SchemaName extends string & keyof
4422
4603
  */
4423
4604
  setAuthToken(token: string | null): void;
4424
4605
  /**
4425
- * Create or get a realtime channel (Supabase-compatible alias)
4426
- *
4427
- * This is a convenience method that delegates to client.realtime.channel().
4428
- * Both patterns work identically:
4429
- * - client.channel('room-1') - Supabase-style
4430
- * - client.realtime.channel('room-1') - Fluxbase-style
4606
+ * Create or get a realtime channel (Supabase-compatible)
4431
4607
  *
4432
4608
  * @param name - Channel name
4609
+ * @param config - Optional channel configuration
4433
4610
  * @returns RealtimeChannel instance
4434
4611
  *
4435
4612
  * @example
4436
4613
  * ```typescript
4437
- * // Supabase-compatible usage
4438
- * const channel = client.channel('room-1')
4439
- * .on('postgres_changes', {
4440
- * event: '*',
4441
- * schema: 'public',
4442
- * table: 'messages'
4443
- * }, (payload) => {
4444
- * console.log('Change:', payload)
4614
+ * const channel = client.channel('room-1', {
4615
+ * broadcast: { self: true },
4616
+ * presence: { key: 'user-123' }
4617
+ * })
4618
+ * .on('broadcast', { event: 'message' }, (payload) => {
4619
+ * console.log('Message:', payload)
4445
4620
  * })
4446
4621
  * .subscribe()
4447
4622
  * ```
4448
4623
  *
4449
4624
  * @category Realtime
4450
4625
  */
4451
- channel(name: string): RealtimeChannel;
4626
+ channel(name: string, config?: RealtimeChannelConfig): RealtimeChannel;
4627
+ /**
4628
+ * Remove a realtime channel (Supabase-compatible)
4629
+ *
4630
+ * @param channel - The channel to remove
4631
+ * @returns Promise resolving to status
4632
+ *
4633
+ * @example
4634
+ * ```typescript
4635
+ * const channel = client.channel('room-1')
4636
+ * await client.removeChannel(channel)
4637
+ * ```
4638
+ *
4639
+ * @category Realtime
4640
+ */
4641
+ removeChannel(channel: RealtimeChannel): Promise<"error" | "ok">;
4452
4642
  /**
4453
4643
  * Get the internal HTTP client
4454
4644
  *
@@ -4504,4 +4694,4 @@ declare class FluxbaseClient<Database = any, _SchemaName extends string & keyof
4504
4694
  */
4505
4695
  declare function createClient<Database = any, SchemaName extends string & keyof Database = any>(fluxbaseUrl: string, fluxbaseKey: string, options?: FluxbaseClientOptions): FluxbaseClient<Database, SchemaName>;
4506
4696
 
4507
- export { type APIKey, APIKeysManager, type AcceptInvitationRequest, type AcceptInvitationResponse, type AdminAuthResponse, type AdminLoginRequest, type AdminMeResponse, type AdminRefreshRequest, type AdminRefreshResponse, type AdminSetupRequest, type AdminSetupStatusResponse, type AdminUser, type AppSettings, AppSettingsManager, type AuthResponse, type AuthSession, type AuthSettings, AuthSettingsManager, type AuthenticationSettings, type Column, type CreateAPIKeyRequest, type CreateAPIKeyResponse, type CreateColumnRequest, type CreateFunctionRequest, type CreateInvitationRequest, type CreateInvitationResponse, type CreateOAuthProviderRequest, type CreateOAuthProviderResponse, type CreateSchemaRequest, type CreateSchemaResponse, type CreateTableRequest, type CreateTableResponse, type CreateWebhookRequest, DDLManager, type DataResponse, type DeleteAPIKeyResponse, type DeleteOAuthProviderResponse, type DeleteTableResponse, type DeleteUserResponse, type DeleteWebhookResponse, type EdgeFunction, type EdgeFunctionExecution, type EmailSettings, type EmailTemplate, EmailTemplateManager, type EmailTemplateType, type EnrichedUser, type FeatureSettings, type FileObject, type FilterOperator, FluxbaseAdmin, FluxbaseAuth, type FluxbaseAuthResponse, FluxbaseClient, type FluxbaseClientOptions, type FluxbaseError, FluxbaseFetch, FluxbaseFunctions, FluxbaseManagement, FluxbaseOAuth, FluxbaseRealtime, type FluxbaseResponse, FluxbaseSettings, FluxbaseStorage, type FunctionInvokeOptions, type GetImpersonationResponse, type HttpMethod, type ImpersonateAnonRequest, type ImpersonateServiceRequest, type ImpersonateUserRequest, ImpersonationManager, type ImpersonationSession, type ImpersonationTargetUser, type ImpersonationType, type Invitation, InvitationsManager, type InviteUserRequest, type InviteUserResponse, type ListAPIKeysResponse, type ListEmailTemplatesResponse, type ListImpersonationSessionsOptions, type ListImpersonationSessionsResponse, type ListInvitationsOptions, type ListInvitationsResponse, type ListOAuthProvidersResponse, type ListOptions, type ListSchemasResponse, type ListSystemSettingsResponse, type ListTablesResponse, type ListUsersOptions, type ListUsersResponse, type ListWebhookDeliveriesResponse, type ListWebhooksResponse, type MailgunSettings, type OAuthProvider, OAuthProviderManager, type OrderBy, type OrderDirection, type PostgresChangesConfig, type PostgrestError, type PostgrestResponse, QueryBuilder, type QueryFilter, type RealtimeCallback, type RealtimeChangePayload, RealtimeChannel, type RealtimeMessage, type RealtimePostgresChangesPayload, type RequestOptions, type ResetUserPasswordResponse, type RevokeAPIKeyResponse, type RevokeInvitationResponse, type SESSettings, type SMTPSettings, type Schema, type SecuritySettings, type SendGridSettings, type SessionResponse, SettingsClient, type SignInCredentials, type SignInWith2FAResponse, type SignUpCredentials, type SignedUrlOptions, type StartImpersonationResponse, type StopImpersonationResponse, StorageBucket, type StorageObject, type SupabaseAuthResponse, type SupabaseResponse, type SystemSetting, SystemSettingsManager, type Table, type TestEmailTemplateRequest, type TestWebhookResponse, type TwoFactorEnableResponse, type TwoFactorSetupResponse, type TwoFactorStatusResponse, type TwoFactorVerifyRequest, type UpdateAPIKeyRequest, type UpdateAppSettingsRequest, type UpdateAuthSettingsRequest, type UpdateAuthSettingsResponse, type UpdateEmailTemplateRequest, type UpdateFunctionRequest, type UpdateOAuthProviderRequest, type UpdateOAuthProviderResponse, type UpdateSystemSettingRequest, type UpdateUserRoleRequest, type UpdateWebhookRequest, type UploadOptions, type UploadProgress, type User, type UserResponse, type ValidateInvitationResponse, type VoidResponse, type Webhook, type WebhookDelivery, WebhooksManager, createClient };
4697
+ export { type APIKey, APIKeysManager, type AcceptInvitationRequest, type AcceptInvitationResponse, type AdminAuthResponse, type AdminLoginRequest, type AdminMeResponse, type AdminRefreshRequest, type AdminRefreshResponse, type AdminSetupRequest, type AdminSetupStatusResponse, type AdminUser, type AppSettings, AppSettingsManager, type AuthResponse, type AuthSession, type AuthSettings, AuthSettingsManager, type AuthenticationSettings, type BroadcastCallback, type BroadcastMessage, type Column, type CreateAPIKeyRequest, type CreateAPIKeyResponse, type CreateColumnRequest, type CreateFunctionRequest, type CreateInvitationRequest, type CreateInvitationResponse, type CreateOAuthProviderRequest, type CreateOAuthProviderResponse, type CreateSchemaRequest, type CreateSchemaResponse, type CreateTableRequest, type CreateTableResponse, type CreateWebhookRequest, DDLManager, type DataResponse, type DeleteAPIKeyResponse, type DeleteOAuthProviderResponse, type DeleteTableResponse, type DeleteUserResponse, type DeleteWebhookResponse, type EdgeFunction, type EdgeFunctionExecution, type EmailSettings, type EmailTemplate, EmailTemplateManager, type EmailTemplateType, type EnrichedUser, type FeatureSettings, type FileObject, type FilterOperator, FluxbaseAdmin, FluxbaseAuth, type FluxbaseAuthResponse, FluxbaseClient, type FluxbaseClientOptions, type FluxbaseError, FluxbaseFetch, FluxbaseFunctions, FluxbaseManagement, FluxbaseOAuth, FluxbaseRealtime, type FluxbaseResponse, FluxbaseSettings, FluxbaseStorage, type FunctionInvokeOptions, type GetImpersonationResponse, type HttpMethod, type ImpersonateAnonRequest, type ImpersonateServiceRequest, type ImpersonateUserRequest, ImpersonationManager, type ImpersonationSession, type ImpersonationTargetUser, type ImpersonationType, type Invitation, InvitationsManager, type InviteUserRequest, type InviteUserResponse, type ListAPIKeysResponse, type ListEmailTemplatesResponse, type ListImpersonationSessionsOptions, type ListImpersonationSessionsResponse, type ListInvitationsOptions, type ListInvitationsResponse, type ListOAuthProvidersResponse, type ListOptions, type ListSchemasResponse, type ListSystemSettingsResponse, type ListTablesResponse, type ListUsersOptions, type ListUsersResponse, type ListWebhookDeliveriesResponse, type ListWebhooksResponse, type MailgunSettings, type OAuthProvider, OAuthProviderManager, type OrderBy, type OrderDirection, type PostgresChangesConfig, type PostgrestError, type PostgrestResponse, type PresenceCallback, type PresenceState, QueryBuilder, type QueryFilter, type RealtimeBroadcastPayload, type RealtimeCallback, type RealtimeChangePayload, RealtimeChannel, type RealtimeChannelConfig, type RealtimeMessage, type RealtimePostgresChangesPayload, type RealtimePresencePayload, type RequestOptions, type ResetUserPasswordResponse, type RevokeAPIKeyResponse, type RevokeInvitationResponse, type SESSettings, type SMTPSettings, type Schema, type SecuritySettings, type SendGridSettings, type SessionResponse, SettingsClient, type SignInCredentials, type SignInWith2FAResponse, type SignUpCredentials, type SignedUrlOptions, type StartImpersonationResponse, type StopImpersonationResponse, StorageBucket, type StorageObject, type SupabaseAuthResponse, type SupabaseResponse, type SystemSetting, SystemSettingsManager, type Table, type TestEmailTemplateRequest, type TestWebhookResponse, type TwoFactorEnableResponse, type TwoFactorSetupResponse, type TwoFactorStatusResponse, type TwoFactorVerifyRequest, type UpdateAPIKeyRequest, type UpdateAppSettingsRequest, type UpdateAuthSettingsRequest, type UpdateAuthSettingsResponse, type UpdateEmailTemplateRequest, type UpdateFunctionRequest, type UpdateOAuthProviderRequest, type UpdateOAuthProviderResponse, type UpdateSystemSettingRequest, type UpdateUserRoleRequest, type UpdateWebhookRequest, type UploadOptions, type UploadProgress, type User, type UserResponse, type ValidateInvitationResponse, type VoidResponse, type Webhook, type WebhookDelivery, WebhooksManager, createClient };