@insforge/sdk 1.0.1-refresh.8 → 1.0.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/LICENSE +201 -201
- package/README.md +249 -249
- package/dist/index.d.mts +132 -78
- package/dist/index.d.ts +132 -78
- package/dist/index.js +273 -201
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +272 -201
- package/dist/index.mjs.map +1 -1
- package/package.json +68 -67
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetPublicAuthConfigResponse, UserIdSchema, EmailSchema, RoleSchema, SendVerificationEmailRequest, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, VerifyEmailRequest, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest } from '@insforge/shared-schemas';
|
|
2
|
-
export { AuthErrorResponse, CreateSessionRequest, CreateUserRequest, UserSchema } from '@insforge/shared-schemas';
|
|
1
|
+
import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetPublicAuthConfigResponse, UserIdSchema, EmailSchema, RoleSchema, SendVerificationEmailRequest, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, VerifyEmailRequest, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, SubscribeResponse, SocketMessage } from '@insforge/shared-schemas';
|
|
2
|
+
export { AuthErrorResponse, CreateSessionRequest, CreateUserRequest, RealtimeErrorPayload, SocketMessage, SubscribeResponse, UserSchema } from '@insforge/shared-schemas';
|
|
3
3
|
import * as _supabase_postgrest_js from '@supabase/postgrest-js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -92,69 +92,13 @@ declare class HttpClient {
|
|
|
92
92
|
getHeaders(): Record<string, string>;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
/**
|
|
96
|
-
* Token Manager for InsForge SDK
|
|
97
|
-
*
|
|
98
|
-
* Simple token storage that supports two modes:
|
|
99
|
-
* - Memory mode (new backend): tokens stored in memory only, more secure
|
|
100
|
-
* - Storage mode (legacy backend): tokens persisted in localStorage
|
|
101
|
-
*/
|
|
102
|
-
|
|
103
95
|
declare class TokenManager {
|
|
104
|
-
private accessToken;
|
|
105
|
-
private user;
|
|
106
96
|
private storage;
|
|
107
|
-
private _mode;
|
|
108
97
|
constructor(storage?: TokenStorage);
|
|
109
|
-
/**
|
|
110
|
-
* Get current mode
|
|
111
|
-
*/
|
|
112
|
-
get mode(): 'memory' | 'storage';
|
|
113
|
-
/**
|
|
114
|
-
* Set mode to memory (new backend with cookies + memory)
|
|
115
|
-
*/
|
|
116
|
-
setMemoryMode(): void;
|
|
117
|
-
/**
|
|
118
|
-
* Set mode to storage (legacy backend with localStorage)
|
|
119
|
-
* Also loads existing session from localStorage
|
|
120
|
-
*/
|
|
121
|
-
setStorageMode(): void;
|
|
122
|
-
/**
|
|
123
|
-
* Load session from localStorage
|
|
124
|
-
*/
|
|
125
|
-
private loadFromStorage;
|
|
126
|
-
/**
|
|
127
|
-
* Save session (memory always, localStorage only in storage mode)
|
|
128
|
-
*/
|
|
129
98
|
saveSession(session: AuthSession): void;
|
|
130
|
-
/**
|
|
131
|
-
* Get current session
|
|
132
|
-
*/
|
|
133
99
|
getSession(): AuthSession | null;
|
|
134
|
-
/**
|
|
135
|
-
* Get access token
|
|
136
|
-
*/
|
|
137
100
|
getAccessToken(): string | null;
|
|
138
|
-
/**
|
|
139
|
-
* Set access token
|
|
140
|
-
*/
|
|
141
|
-
setAccessToken(token: string): void;
|
|
142
|
-
/**
|
|
143
|
-
* Get user
|
|
144
|
-
*/
|
|
145
|
-
getUser(): UserSchema | null;
|
|
146
|
-
/**
|
|
147
|
-
* Set user
|
|
148
|
-
*/
|
|
149
|
-
setUser(user: UserSchema): void;
|
|
150
|
-
/**
|
|
151
|
-
* Clear session (both memory and localStorage)
|
|
152
|
-
*/
|
|
153
101
|
clearSession(): void;
|
|
154
|
-
/**
|
|
155
|
-
* Check if there's a session in localStorage (for legacy detection)
|
|
156
|
-
*/
|
|
157
|
-
hasStoredSession(): boolean;
|
|
158
102
|
}
|
|
159
103
|
|
|
160
104
|
/**
|
|
@@ -182,24 +126,6 @@ declare class Auth {
|
|
|
182
126
|
private tokenManager;
|
|
183
127
|
private database;
|
|
184
128
|
constructor(http: HttpClient, tokenManager: TokenManager);
|
|
185
|
-
/**
|
|
186
|
-
* Restore session on app initialization
|
|
187
|
-
*
|
|
188
|
-
* @returns Object with isLoggedIn status
|
|
189
|
-
*
|
|
190
|
-
* @example
|
|
191
|
-
* ```typescript
|
|
192
|
-
* const client = new InsForgeClient({ baseUrl: '...' });
|
|
193
|
-
* const { isLoggedIn } = await client.auth.restoreSession();
|
|
194
|
-
*
|
|
195
|
-
* if (isLoggedIn) {
|
|
196
|
-
* const { data } = await client.auth.getCurrentUser();
|
|
197
|
-
* }
|
|
198
|
-
* ```
|
|
199
|
-
*/
|
|
200
|
-
restoreSession(): Promise<{
|
|
201
|
-
isLoggedIn: boolean;
|
|
202
|
-
}>;
|
|
203
129
|
/**
|
|
204
130
|
* Automatically detect and handle OAuth callback parameters in the URL
|
|
205
131
|
* This runs on initialization to seamlessly complete the OAuth flow
|
|
@@ -656,6 +582,133 @@ declare class Functions {
|
|
|
656
582
|
}>;
|
|
657
583
|
}
|
|
658
584
|
|
|
585
|
+
type ConnectionState = 'disconnected' | 'connecting' | 'connected';
|
|
586
|
+
type EventCallback<T = unknown> = (payload: T) => void;
|
|
587
|
+
/**
|
|
588
|
+
* Realtime module for subscribing to channels and handling real-time events
|
|
589
|
+
*
|
|
590
|
+
* @example
|
|
591
|
+
* ```typescript
|
|
592
|
+
* const { realtime } = client;
|
|
593
|
+
*
|
|
594
|
+
* // Connect to the realtime server
|
|
595
|
+
* await realtime.connect();
|
|
596
|
+
*
|
|
597
|
+
* // Subscribe to a channel
|
|
598
|
+
* const response = await realtime.subscribe('orders:123');
|
|
599
|
+
* if (!response.ok) {
|
|
600
|
+
* console.error('Failed to subscribe:', response.error);
|
|
601
|
+
* }
|
|
602
|
+
*
|
|
603
|
+
* // Listen for specific events
|
|
604
|
+
* realtime.on('order_updated', (payload) => {
|
|
605
|
+
* console.log('Order updated:', payload);
|
|
606
|
+
* });
|
|
607
|
+
*
|
|
608
|
+
* // Listen for connection events
|
|
609
|
+
* realtime.on('connect', () => console.log('Connected!'));
|
|
610
|
+
* realtime.on('connect_error', (err) => console.error('Connection failed:', err));
|
|
611
|
+
* realtime.on('disconnect', (reason) => console.log('Disconnected:', reason));
|
|
612
|
+
* realtime.on('error', (error) => console.error('Realtime error:', error));
|
|
613
|
+
*
|
|
614
|
+
* // Publish a message to a channel
|
|
615
|
+
* await realtime.publish('orders:123', 'status_changed', { status: 'shipped' });
|
|
616
|
+
*
|
|
617
|
+
* // Unsubscribe and disconnect when done
|
|
618
|
+
* realtime.unsubscribe('orders:123');
|
|
619
|
+
* realtime.disconnect();
|
|
620
|
+
* ```
|
|
621
|
+
*/
|
|
622
|
+
declare class Realtime {
|
|
623
|
+
private baseUrl;
|
|
624
|
+
private tokenManager;
|
|
625
|
+
private socket;
|
|
626
|
+
private connectPromise;
|
|
627
|
+
private subscribedChannels;
|
|
628
|
+
private eventListeners;
|
|
629
|
+
constructor(baseUrl: string, tokenManager: TokenManager);
|
|
630
|
+
private notifyListeners;
|
|
631
|
+
/**
|
|
632
|
+
* Connect to the realtime server
|
|
633
|
+
* @returns Promise that resolves when connected
|
|
634
|
+
*/
|
|
635
|
+
connect(): Promise<void>;
|
|
636
|
+
/**
|
|
637
|
+
* Disconnect from the realtime server
|
|
638
|
+
*/
|
|
639
|
+
disconnect(): void;
|
|
640
|
+
/**
|
|
641
|
+
* Check if connected to the realtime server
|
|
642
|
+
*/
|
|
643
|
+
get isConnected(): boolean;
|
|
644
|
+
/**
|
|
645
|
+
* Get the current connection state
|
|
646
|
+
*/
|
|
647
|
+
get connectionState(): ConnectionState;
|
|
648
|
+
/**
|
|
649
|
+
* Get the socket ID (if connected)
|
|
650
|
+
*/
|
|
651
|
+
get socketId(): string | undefined;
|
|
652
|
+
/**
|
|
653
|
+
* Subscribe to a channel
|
|
654
|
+
*
|
|
655
|
+
* Automatically connects if not already connected.
|
|
656
|
+
*
|
|
657
|
+
* @param channel - Channel name (e.g., 'orders:123', 'broadcast')
|
|
658
|
+
* @returns Promise with the subscription response
|
|
659
|
+
*/
|
|
660
|
+
subscribe(channel: string): Promise<SubscribeResponse>;
|
|
661
|
+
/**
|
|
662
|
+
* Unsubscribe from a channel (fire-and-forget)
|
|
663
|
+
*
|
|
664
|
+
* @param channel - Channel name to unsubscribe from
|
|
665
|
+
*/
|
|
666
|
+
unsubscribe(channel: string): void;
|
|
667
|
+
/**
|
|
668
|
+
* Publish a message to a channel
|
|
669
|
+
*
|
|
670
|
+
* @param channel - Channel name
|
|
671
|
+
* @param event - Event name
|
|
672
|
+
* @param payload - Message payload
|
|
673
|
+
*/
|
|
674
|
+
publish<T = unknown>(channel: string, event: string, payload: T): Promise<void>;
|
|
675
|
+
/**
|
|
676
|
+
* Listen for events
|
|
677
|
+
*
|
|
678
|
+
* Reserved event names:
|
|
679
|
+
* - 'connect' - Fired when connected to the server
|
|
680
|
+
* - 'connect_error' - Fired when connection fails (payload: Error)
|
|
681
|
+
* - 'disconnect' - Fired when disconnected (payload: reason string)
|
|
682
|
+
* - 'error' - Fired when a realtime error occurs (payload: RealtimeErrorPayload)
|
|
683
|
+
*
|
|
684
|
+
* All other events receive a `SocketMessage` payload with metadata.
|
|
685
|
+
*
|
|
686
|
+
* @param event - Event name to listen for
|
|
687
|
+
* @param callback - Callback function when event is received
|
|
688
|
+
*/
|
|
689
|
+
on<T = SocketMessage>(event: string, callback: EventCallback<T>): void;
|
|
690
|
+
/**
|
|
691
|
+
* Remove a listener for a specific event
|
|
692
|
+
*
|
|
693
|
+
* @param event - Event name
|
|
694
|
+
* @param callback - The callback function to remove
|
|
695
|
+
*/
|
|
696
|
+
off<T = SocketMessage>(event: string, callback: EventCallback<T>): void;
|
|
697
|
+
/**
|
|
698
|
+
* Listen for an event only once, then automatically remove the listener
|
|
699
|
+
*
|
|
700
|
+
* @param event - Event name to listen for
|
|
701
|
+
* @param callback - Callback function when event is received
|
|
702
|
+
*/
|
|
703
|
+
once<T = SocketMessage>(event: string, callback: EventCallback<T>): void;
|
|
704
|
+
/**
|
|
705
|
+
* Get all currently subscribed channels
|
|
706
|
+
*
|
|
707
|
+
* @returns Array of channel names
|
|
708
|
+
*/
|
|
709
|
+
getSubscribedChannels(): string[];
|
|
710
|
+
}
|
|
711
|
+
|
|
659
712
|
/**
|
|
660
713
|
* Main InsForge SDK Client
|
|
661
714
|
*
|
|
@@ -668,7 +721,7 @@ declare class Functions {
|
|
|
668
721
|
* });
|
|
669
722
|
*
|
|
670
723
|
* // Authentication
|
|
671
|
-
* const
|
|
724
|
+
* const session = await client.auth.register({
|
|
672
725
|
* email: 'user@example.com',
|
|
673
726
|
* password: 'password123',
|
|
674
727
|
* name: 'John Doe'
|
|
@@ -702,6 +755,7 @@ declare class InsForgeClient {
|
|
|
702
755
|
readonly storage: Storage;
|
|
703
756
|
readonly ai: AI;
|
|
704
757
|
readonly functions: Functions;
|
|
758
|
+
readonly realtime: Realtime;
|
|
705
759
|
constructor(config?: InsForgeConfig);
|
|
706
760
|
/**
|
|
707
761
|
* Get the underlying HTTP client for custom requests
|
|
@@ -723,4 +777,4 @@ declare class InsForgeClient {
|
|
|
723
777
|
|
|
724
778
|
declare function createClient(config: InsForgeConfig): InsForgeClient;
|
|
725
779
|
|
|
726
|
-
export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, Database, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError, type ProfileData, Storage, StorageBucket, type StorageResponse, TokenManager, type TokenStorage, type UpdateProfileData, createClient, InsForgeClient as default };
|
|
780
|
+
export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, type ConnectionState, Database, type EventCallback, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError, type ProfileData, Realtime, Storage, StorageBucket, type StorageResponse, TokenManager, type TokenStorage, type UpdateProfileData, createClient, InsForgeClient as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetPublicAuthConfigResponse, UserIdSchema, EmailSchema, RoleSchema, SendVerificationEmailRequest, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, VerifyEmailRequest, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest } from '@insforge/shared-schemas';
|
|
2
|
-
export { AuthErrorResponse, CreateSessionRequest, CreateUserRequest, UserSchema } from '@insforge/shared-schemas';
|
|
1
|
+
import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetPublicAuthConfigResponse, UserIdSchema, EmailSchema, RoleSchema, SendVerificationEmailRequest, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, VerifyEmailRequest, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, SubscribeResponse, SocketMessage } from '@insforge/shared-schemas';
|
|
2
|
+
export { AuthErrorResponse, CreateSessionRequest, CreateUserRequest, RealtimeErrorPayload, SocketMessage, SubscribeResponse, UserSchema } from '@insforge/shared-schemas';
|
|
3
3
|
import * as _supabase_postgrest_js from '@supabase/postgrest-js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -92,69 +92,13 @@ declare class HttpClient {
|
|
|
92
92
|
getHeaders(): Record<string, string>;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
/**
|
|
96
|
-
* Token Manager for InsForge SDK
|
|
97
|
-
*
|
|
98
|
-
* Simple token storage that supports two modes:
|
|
99
|
-
* - Memory mode (new backend): tokens stored in memory only, more secure
|
|
100
|
-
* - Storage mode (legacy backend): tokens persisted in localStorage
|
|
101
|
-
*/
|
|
102
|
-
|
|
103
95
|
declare class TokenManager {
|
|
104
|
-
private accessToken;
|
|
105
|
-
private user;
|
|
106
96
|
private storage;
|
|
107
|
-
private _mode;
|
|
108
97
|
constructor(storage?: TokenStorage);
|
|
109
|
-
/**
|
|
110
|
-
* Get current mode
|
|
111
|
-
*/
|
|
112
|
-
get mode(): 'memory' | 'storage';
|
|
113
|
-
/**
|
|
114
|
-
* Set mode to memory (new backend with cookies + memory)
|
|
115
|
-
*/
|
|
116
|
-
setMemoryMode(): void;
|
|
117
|
-
/**
|
|
118
|
-
* Set mode to storage (legacy backend with localStorage)
|
|
119
|
-
* Also loads existing session from localStorage
|
|
120
|
-
*/
|
|
121
|
-
setStorageMode(): void;
|
|
122
|
-
/**
|
|
123
|
-
* Load session from localStorage
|
|
124
|
-
*/
|
|
125
|
-
private loadFromStorage;
|
|
126
|
-
/**
|
|
127
|
-
* Save session (memory always, localStorage only in storage mode)
|
|
128
|
-
*/
|
|
129
98
|
saveSession(session: AuthSession): void;
|
|
130
|
-
/**
|
|
131
|
-
* Get current session
|
|
132
|
-
*/
|
|
133
99
|
getSession(): AuthSession | null;
|
|
134
|
-
/**
|
|
135
|
-
* Get access token
|
|
136
|
-
*/
|
|
137
100
|
getAccessToken(): string | null;
|
|
138
|
-
/**
|
|
139
|
-
* Set access token
|
|
140
|
-
*/
|
|
141
|
-
setAccessToken(token: string): void;
|
|
142
|
-
/**
|
|
143
|
-
* Get user
|
|
144
|
-
*/
|
|
145
|
-
getUser(): UserSchema | null;
|
|
146
|
-
/**
|
|
147
|
-
* Set user
|
|
148
|
-
*/
|
|
149
|
-
setUser(user: UserSchema): void;
|
|
150
|
-
/**
|
|
151
|
-
* Clear session (both memory and localStorage)
|
|
152
|
-
*/
|
|
153
101
|
clearSession(): void;
|
|
154
|
-
/**
|
|
155
|
-
* Check if there's a session in localStorage (for legacy detection)
|
|
156
|
-
*/
|
|
157
|
-
hasStoredSession(): boolean;
|
|
158
102
|
}
|
|
159
103
|
|
|
160
104
|
/**
|
|
@@ -182,24 +126,6 @@ declare class Auth {
|
|
|
182
126
|
private tokenManager;
|
|
183
127
|
private database;
|
|
184
128
|
constructor(http: HttpClient, tokenManager: TokenManager);
|
|
185
|
-
/**
|
|
186
|
-
* Restore session on app initialization
|
|
187
|
-
*
|
|
188
|
-
* @returns Object with isLoggedIn status
|
|
189
|
-
*
|
|
190
|
-
* @example
|
|
191
|
-
* ```typescript
|
|
192
|
-
* const client = new InsForgeClient({ baseUrl: '...' });
|
|
193
|
-
* const { isLoggedIn } = await client.auth.restoreSession();
|
|
194
|
-
*
|
|
195
|
-
* if (isLoggedIn) {
|
|
196
|
-
* const { data } = await client.auth.getCurrentUser();
|
|
197
|
-
* }
|
|
198
|
-
* ```
|
|
199
|
-
*/
|
|
200
|
-
restoreSession(): Promise<{
|
|
201
|
-
isLoggedIn: boolean;
|
|
202
|
-
}>;
|
|
203
129
|
/**
|
|
204
130
|
* Automatically detect and handle OAuth callback parameters in the URL
|
|
205
131
|
* This runs on initialization to seamlessly complete the OAuth flow
|
|
@@ -656,6 +582,133 @@ declare class Functions {
|
|
|
656
582
|
}>;
|
|
657
583
|
}
|
|
658
584
|
|
|
585
|
+
type ConnectionState = 'disconnected' | 'connecting' | 'connected';
|
|
586
|
+
type EventCallback<T = unknown> = (payload: T) => void;
|
|
587
|
+
/**
|
|
588
|
+
* Realtime module for subscribing to channels and handling real-time events
|
|
589
|
+
*
|
|
590
|
+
* @example
|
|
591
|
+
* ```typescript
|
|
592
|
+
* const { realtime } = client;
|
|
593
|
+
*
|
|
594
|
+
* // Connect to the realtime server
|
|
595
|
+
* await realtime.connect();
|
|
596
|
+
*
|
|
597
|
+
* // Subscribe to a channel
|
|
598
|
+
* const response = await realtime.subscribe('orders:123');
|
|
599
|
+
* if (!response.ok) {
|
|
600
|
+
* console.error('Failed to subscribe:', response.error);
|
|
601
|
+
* }
|
|
602
|
+
*
|
|
603
|
+
* // Listen for specific events
|
|
604
|
+
* realtime.on('order_updated', (payload) => {
|
|
605
|
+
* console.log('Order updated:', payload);
|
|
606
|
+
* });
|
|
607
|
+
*
|
|
608
|
+
* // Listen for connection events
|
|
609
|
+
* realtime.on('connect', () => console.log('Connected!'));
|
|
610
|
+
* realtime.on('connect_error', (err) => console.error('Connection failed:', err));
|
|
611
|
+
* realtime.on('disconnect', (reason) => console.log('Disconnected:', reason));
|
|
612
|
+
* realtime.on('error', (error) => console.error('Realtime error:', error));
|
|
613
|
+
*
|
|
614
|
+
* // Publish a message to a channel
|
|
615
|
+
* await realtime.publish('orders:123', 'status_changed', { status: 'shipped' });
|
|
616
|
+
*
|
|
617
|
+
* // Unsubscribe and disconnect when done
|
|
618
|
+
* realtime.unsubscribe('orders:123');
|
|
619
|
+
* realtime.disconnect();
|
|
620
|
+
* ```
|
|
621
|
+
*/
|
|
622
|
+
declare class Realtime {
|
|
623
|
+
private baseUrl;
|
|
624
|
+
private tokenManager;
|
|
625
|
+
private socket;
|
|
626
|
+
private connectPromise;
|
|
627
|
+
private subscribedChannels;
|
|
628
|
+
private eventListeners;
|
|
629
|
+
constructor(baseUrl: string, tokenManager: TokenManager);
|
|
630
|
+
private notifyListeners;
|
|
631
|
+
/**
|
|
632
|
+
* Connect to the realtime server
|
|
633
|
+
* @returns Promise that resolves when connected
|
|
634
|
+
*/
|
|
635
|
+
connect(): Promise<void>;
|
|
636
|
+
/**
|
|
637
|
+
* Disconnect from the realtime server
|
|
638
|
+
*/
|
|
639
|
+
disconnect(): void;
|
|
640
|
+
/**
|
|
641
|
+
* Check if connected to the realtime server
|
|
642
|
+
*/
|
|
643
|
+
get isConnected(): boolean;
|
|
644
|
+
/**
|
|
645
|
+
* Get the current connection state
|
|
646
|
+
*/
|
|
647
|
+
get connectionState(): ConnectionState;
|
|
648
|
+
/**
|
|
649
|
+
* Get the socket ID (if connected)
|
|
650
|
+
*/
|
|
651
|
+
get socketId(): string | undefined;
|
|
652
|
+
/**
|
|
653
|
+
* Subscribe to a channel
|
|
654
|
+
*
|
|
655
|
+
* Automatically connects if not already connected.
|
|
656
|
+
*
|
|
657
|
+
* @param channel - Channel name (e.g., 'orders:123', 'broadcast')
|
|
658
|
+
* @returns Promise with the subscription response
|
|
659
|
+
*/
|
|
660
|
+
subscribe(channel: string): Promise<SubscribeResponse>;
|
|
661
|
+
/**
|
|
662
|
+
* Unsubscribe from a channel (fire-and-forget)
|
|
663
|
+
*
|
|
664
|
+
* @param channel - Channel name to unsubscribe from
|
|
665
|
+
*/
|
|
666
|
+
unsubscribe(channel: string): void;
|
|
667
|
+
/**
|
|
668
|
+
* Publish a message to a channel
|
|
669
|
+
*
|
|
670
|
+
* @param channel - Channel name
|
|
671
|
+
* @param event - Event name
|
|
672
|
+
* @param payload - Message payload
|
|
673
|
+
*/
|
|
674
|
+
publish<T = unknown>(channel: string, event: string, payload: T): Promise<void>;
|
|
675
|
+
/**
|
|
676
|
+
* Listen for events
|
|
677
|
+
*
|
|
678
|
+
* Reserved event names:
|
|
679
|
+
* - 'connect' - Fired when connected to the server
|
|
680
|
+
* - 'connect_error' - Fired when connection fails (payload: Error)
|
|
681
|
+
* - 'disconnect' - Fired when disconnected (payload: reason string)
|
|
682
|
+
* - 'error' - Fired when a realtime error occurs (payload: RealtimeErrorPayload)
|
|
683
|
+
*
|
|
684
|
+
* All other events receive a `SocketMessage` payload with metadata.
|
|
685
|
+
*
|
|
686
|
+
* @param event - Event name to listen for
|
|
687
|
+
* @param callback - Callback function when event is received
|
|
688
|
+
*/
|
|
689
|
+
on<T = SocketMessage>(event: string, callback: EventCallback<T>): void;
|
|
690
|
+
/**
|
|
691
|
+
* Remove a listener for a specific event
|
|
692
|
+
*
|
|
693
|
+
* @param event - Event name
|
|
694
|
+
* @param callback - The callback function to remove
|
|
695
|
+
*/
|
|
696
|
+
off<T = SocketMessage>(event: string, callback: EventCallback<T>): void;
|
|
697
|
+
/**
|
|
698
|
+
* Listen for an event only once, then automatically remove the listener
|
|
699
|
+
*
|
|
700
|
+
* @param event - Event name to listen for
|
|
701
|
+
* @param callback - Callback function when event is received
|
|
702
|
+
*/
|
|
703
|
+
once<T = SocketMessage>(event: string, callback: EventCallback<T>): void;
|
|
704
|
+
/**
|
|
705
|
+
* Get all currently subscribed channels
|
|
706
|
+
*
|
|
707
|
+
* @returns Array of channel names
|
|
708
|
+
*/
|
|
709
|
+
getSubscribedChannels(): string[];
|
|
710
|
+
}
|
|
711
|
+
|
|
659
712
|
/**
|
|
660
713
|
* Main InsForge SDK Client
|
|
661
714
|
*
|
|
@@ -668,7 +721,7 @@ declare class Functions {
|
|
|
668
721
|
* });
|
|
669
722
|
*
|
|
670
723
|
* // Authentication
|
|
671
|
-
* const
|
|
724
|
+
* const session = await client.auth.register({
|
|
672
725
|
* email: 'user@example.com',
|
|
673
726
|
* password: 'password123',
|
|
674
727
|
* name: 'John Doe'
|
|
@@ -702,6 +755,7 @@ declare class InsForgeClient {
|
|
|
702
755
|
readonly storage: Storage;
|
|
703
756
|
readonly ai: AI;
|
|
704
757
|
readonly functions: Functions;
|
|
758
|
+
readonly realtime: Realtime;
|
|
705
759
|
constructor(config?: InsForgeConfig);
|
|
706
760
|
/**
|
|
707
761
|
* Get the underlying HTTP client for custom requests
|
|
@@ -723,4 +777,4 @@ declare class InsForgeClient {
|
|
|
723
777
|
|
|
724
778
|
declare function createClient(config: InsForgeConfig): InsForgeClient;
|
|
725
779
|
|
|
726
|
-
export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, Database, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError, type ProfileData, Storage, StorageBucket, type StorageResponse, TokenManager, type TokenStorage, type UpdateProfileData, createClient, InsForgeClient as default };
|
|
780
|
+
export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, type ConnectionState, Database, type EventCallback, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError, type ProfileData, Realtime, Storage, StorageBucket, type StorageResponse, TokenManager, type TokenStorage, type UpdateProfileData, createClient, InsForgeClient as default };
|