@insforge/sdk 1.0.1-refresh.9 → 1.0.1-schema.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/LICENSE +201 -201
- package/README.md +249 -249
- package/dist/index.d.mts +140 -106
- package/dist/index.d.ts +140 -106
- package/dist/index.js +379 -374
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +378 -374
- 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,
|
|
2
|
-
export { AuthErrorResponse, CreateSessionRequest, CreateUserRequest, UserSchema } from '@insforge/shared-schemas';
|
|
1
|
+
import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetPublicAuthConfigResponse, GetProfileResponse, 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
|
/**
|
|
@@ -162,44 +106,10 @@ declare class TokenManager {
|
|
|
162
106
|
* Uses shared schemas for type safety
|
|
163
107
|
*/
|
|
164
108
|
|
|
165
|
-
/**
|
|
166
|
-
* Dynamic profile type - represents flexible profile data from database
|
|
167
|
-
* Fields can vary based on database schema configuration.
|
|
168
|
-
* All fields are converted from snake_case (database) to camelCase (API)
|
|
169
|
-
*/
|
|
170
|
-
type ProfileData = Record<string, any> & {
|
|
171
|
-
id: string;
|
|
172
|
-
createdAt?: string;
|
|
173
|
-
updatedAt?: string;
|
|
174
|
-
};
|
|
175
|
-
/**
|
|
176
|
-
* Dynamic profile update type - for updating profile fields
|
|
177
|
-
* Supports any fields that exist in the profile table
|
|
178
|
-
*/
|
|
179
|
-
type UpdateProfileData = Partial<Record<string, any>>;
|
|
180
109
|
declare class Auth {
|
|
181
110
|
private http;
|
|
182
111
|
private tokenManager;
|
|
183
|
-
private database;
|
|
184
112
|
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
113
|
/**
|
|
204
114
|
* Automatically detect and handle OAuth callback parameters in the URL
|
|
205
115
|
* This runs on initialization to seamlessly complete the OAuth flow
|
|
@@ -266,22 +176,17 @@ declare class Auth {
|
|
|
266
176
|
*/
|
|
267
177
|
getCurrentUser(): Promise<{
|
|
268
178
|
data: {
|
|
269
|
-
user:
|
|
270
|
-
id: UserIdSchema;
|
|
271
|
-
email: EmailSchema;
|
|
272
|
-
role: RoleSchema;
|
|
273
|
-
};
|
|
274
|
-
profile: ProfileData | null;
|
|
179
|
+
user: UserSchema;
|
|
275
180
|
} | null;
|
|
276
181
|
error: any | null;
|
|
277
182
|
}>;
|
|
278
183
|
/**
|
|
279
184
|
* Get any user's profile by ID
|
|
280
|
-
* Returns profile information from the users table
|
|
185
|
+
* Returns profile information from the users table
|
|
281
186
|
*/
|
|
282
187
|
getProfile(userId: string): Promise<{
|
|
283
|
-
data:
|
|
284
|
-
error:
|
|
188
|
+
data: GetProfileResponse | null;
|
|
189
|
+
error: InsForgeError | null;
|
|
285
190
|
}>;
|
|
286
191
|
/**
|
|
287
192
|
* Get the current session (only session data, no API call)
|
|
@@ -296,10 +201,11 @@ declare class Auth {
|
|
|
296
201
|
/**
|
|
297
202
|
* Set/Update the current user's profile
|
|
298
203
|
* Updates profile information in the users table (supports any dynamic fields)
|
|
204
|
+
* Requires authentication
|
|
299
205
|
*/
|
|
300
|
-
setProfile(profile:
|
|
301
|
-
data:
|
|
302
|
-
error:
|
|
206
|
+
setProfile(profile: Record<string, unknown>): Promise<{
|
|
207
|
+
data: GetProfileResponse | null;
|
|
208
|
+
error: InsForgeError | null;
|
|
303
209
|
}>;
|
|
304
210
|
/**
|
|
305
211
|
* Send email verification (code or link based on config)
|
|
@@ -656,6 +562,133 @@ declare class Functions {
|
|
|
656
562
|
}>;
|
|
657
563
|
}
|
|
658
564
|
|
|
565
|
+
type ConnectionState = 'disconnected' | 'connecting' | 'connected';
|
|
566
|
+
type EventCallback<T = unknown> = (payload: T) => void;
|
|
567
|
+
/**
|
|
568
|
+
* Realtime module for subscribing to channels and handling real-time events
|
|
569
|
+
*
|
|
570
|
+
* @example
|
|
571
|
+
* ```typescript
|
|
572
|
+
* const { realtime } = client;
|
|
573
|
+
*
|
|
574
|
+
* // Connect to the realtime server
|
|
575
|
+
* await realtime.connect();
|
|
576
|
+
*
|
|
577
|
+
* // Subscribe to a channel
|
|
578
|
+
* const response = await realtime.subscribe('orders:123');
|
|
579
|
+
* if (!response.ok) {
|
|
580
|
+
* console.error('Failed to subscribe:', response.error);
|
|
581
|
+
* }
|
|
582
|
+
*
|
|
583
|
+
* // Listen for specific events
|
|
584
|
+
* realtime.on('order_updated', (payload) => {
|
|
585
|
+
* console.log('Order updated:', payload);
|
|
586
|
+
* });
|
|
587
|
+
*
|
|
588
|
+
* // Listen for connection events
|
|
589
|
+
* realtime.on('connect', () => console.log('Connected!'));
|
|
590
|
+
* realtime.on('connect_error', (err) => console.error('Connection failed:', err));
|
|
591
|
+
* realtime.on('disconnect', (reason) => console.log('Disconnected:', reason));
|
|
592
|
+
* realtime.on('error', (error) => console.error('Realtime error:', error));
|
|
593
|
+
*
|
|
594
|
+
* // Publish a message to a channel
|
|
595
|
+
* await realtime.publish('orders:123', 'status_changed', { status: 'shipped' });
|
|
596
|
+
*
|
|
597
|
+
* // Unsubscribe and disconnect when done
|
|
598
|
+
* realtime.unsubscribe('orders:123');
|
|
599
|
+
* realtime.disconnect();
|
|
600
|
+
* ```
|
|
601
|
+
*/
|
|
602
|
+
declare class Realtime {
|
|
603
|
+
private baseUrl;
|
|
604
|
+
private tokenManager;
|
|
605
|
+
private socket;
|
|
606
|
+
private connectPromise;
|
|
607
|
+
private subscribedChannels;
|
|
608
|
+
private eventListeners;
|
|
609
|
+
constructor(baseUrl: string, tokenManager: TokenManager);
|
|
610
|
+
private notifyListeners;
|
|
611
|
+
/**
|
|
612
|
+
* Connect to the realtime server
|
|
613
|
+
* @returns Promise that resolves when connected
|
|
614
|
+
*/
|
|
615
|
+
connect(): Promise<void>;
|
|
616
|
+
/**
|
|
617
|
+
* Disconnect from the realtime server
|
|
618
|
+
*/
|
|
619
|
+
disconnect(): void;
|
|
620
|
+
/**
|
|
621
|
+
* Check if connected to the realtime server
|
|
622
|
+
*/
|
|
623
|
+
get isConnected(): boolean;
|
|
624
|
+
/**
|
|
625
|
+
* Get the current connection state
|
|
626
|
+
*/
|
|
627
|
+
get connectionState(): ConnectionState;
|
|
628
|
+
/**
|
|
629
|
+
* Get the socket ID (if connected)
|
|
630
|
+
*/
|
|
631
|
+
get socketId(): string | undefined;
|
|
632
|
+
/**
|
|
633
|
+
* Subscribe to a channel
|
|
634
|
+
*
|
|
635
|
+
* Automatically connects if not already connected.
|
|
636
|
+
*
|
|
637
|
+
* @param channel - Channel name (e.g., 'orders:123', 'broadcast')
|
|
638
|
+
* @returns Promise with the subscription response
|
|
639
|
+
*/
|
|
640
|
+
subscribe(channel: string): Promise<SubscribeResponse>;
|
|
641
|
+
/**
|
|
642
|
+
* Unsubscribe from a channel (fire-and-forget)
|
|
643
|
+
*
|
|
644
|
+
* @param channel - Channel name to unsubscribe from
|
|
645
|
+
*/
|
|
646
|
+
unsubscribe(channel: string): void;
|
|
647
|
+
/**
|
|
648
|
+
* Publish a message to a channel
|
|
649
|
+
*
|
|
650
|
+
* @param channel - Channel name
|
|
651
|
+
* @param event - Event name
|
|
652
|
+
* @param payload - Message payload
|
|
653
|
+
*/
|
|
654
|
+
publish<T = unknown>(channel: string, event: string, payload: T): Promise<void>;
|
|
655
|
+
/**
|
|
656
|
+
* Listen for events
|
|
657
|
+
*
|
|
658
|
+
* Reserved event names:
|
|
659
|
+
* - 'connect' - Fired when connected to the server
|
|
660
|
+
* - 'connect_error' - Fired when connection fails (payload: Error)
|
|
661
|
+
* - 'disconnect' - Fired when disconnected (payload: reason string)
|
|
662
|
+
* - 'error' - Fired when a realtime error occurs (payload: RealtimeErrorPayload)
|
|
663
|
+
*
|
|
664
|
+
* All other events receive a `SocketMessage` payload with metadata.
|
|
665
|
+
*
|
|
666
|
+
* @param event - Event name to listen for
|
|
667
|
+
* @param callback - Callback function when event is received
|
|
668
|
+
*/
|
|
669
|
+
on<T = SocketMessage>(event: string, callback: EventCallback<T>): void;
|
|
670
|
+
/**
|
|
671
|
+
* Remove a listener for a specific event
|
|
672
|
+
*
|
|
673
|
+
* @param event - Event name
|
|
674
|
+
* @param callback - The callback function to remove
|
|
675
|
+
*/
|
|
676
|
+
off<T = SocketMessage>(event: string, callback: EventCallback<T>): void;
|
|
677
|
+
/**
|
|
678
|
+
* Listen for an event only once, then automatically remove the listener
|
|
679
|
+
*
|
|
680
|
+
* @param event - Event name to listen for
|
|
681
|
+
* @param callback - Callback function when event is received
|
|
682
|
+
*/
|
|
683
|
+
once<T = SocketMessage>(event: string, callback: EventCallback<T>): void;
|
|
684
|
+
/**
|
|
685
|
+
* Get all currently subscribed channels
|
|
686
|
+
*
|
|
687
|
+
* @returns Array of channel names
|
|
688
|
+
*/
|
|
689
|
+
getSubscribedChannels(): string[];
|
|
690
|
+
}
|
|
691
|
+
|
|
659
692
|
/**
|
|
660
693
|
* Main InsForge SDK Client
|
|
661
694
|
*
|
|
@@ -668,7 +701,7 @@ declare class Functions {
|
|
|
668
701
|
* });
|
|
669
702
|
*
|
|
670
703
|
* // Authentication
|
|
671
|
-
* const
|
|
704
|
+
* const session = await client.auth.register({
|
|
672
705
|
* email: 'user@example.com',
|
|
673
706
|
* password: 'password123',
|
|
674
707
|
* name: 'John Doe'
|
|
@@ -702,6 +735,7 @@ declare class InsForgeClient {
|
|
|
702
735
|
readonly storage: Storage;
|
|
703
736
|
readonly ai: AI;
|
|
704
737
|
readonly functions: Functions;
|
|
738
|
+
readonly realtime: Realtime;
|
|
705
739
|
constructor(config?: InsForgeConfig);
|
|
706
740
|
/**
|
|
707
741
|
* Get the underlying HTTP client for custom requests
|
|
@@ -723,4 +757,4 @@ declare class InsForgeClient {
|
|
|
723
757
|
|
|
724
758
|
declare function createClient(config: InsForgeConfig): InsForgeClient;
|
|
725
759
|
|
|
726
|
-
export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, Database, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError,
|
|
760
|
+
export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, type ConnectionState, Database, type EventCallback, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError, Realtime, Storage, StorageBucket, type StorageResponse, TokenManager, type TokenStorage, createClient, InsForgeClient as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetPublicAuthConfigResponse,
|
|
2
|
-
export { AuthErrorResponse, CreateSessionRequest, CreateUserRequest, UserSchema } from '@insforge/shared-schemas';
|
|
1
|
+
import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetPublicAuthConfigResponse, GetProfileResponse, 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
|
/**
|
|
@@ -162,44 +106,10 @@ declare class TokenManager {
|
|
|
162
106
|
* Uses shared schemas for type safety
|
|
163
107
|
*/
|
|
164
108
|
|
|
165
|
-
/**
|
|
166
|
-
* Dynamic profile type - represents flexible profile data from database
|
|
167
|
-
* Fields can vary based on database schema configuration.
|
|
168
|
-
* All fields are converted from snake_case (database) to camelCase (API)
|
|
169
|
-
*/
|
|
170
|
-
type ProfileData = Record<string, any> & {
|
|
171
|
-
id: string;
|
|
172
|
-
createdAt?: string;
|
|
173
|
-
updatedAt?: string;
|
|
174
|
-
};
|
|
175
|
-
/**
|
|
176
|
-
* Dynamic profile update type - for updating profile fields
|
|
177
|
-
* Supports any fields that exist in the profile table
|
|
178
|
-
*/
|
|
179
|
-
type UpdateProfileData = Partial<Record<string, any>>;
|
|
180
109
|
declare class Auth {
|
|
181
110
|
private http;
|
|
182
111
|
private tokenManager;
|
|
183
|
-
private database;
|
|
184
112
|
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
113
|
/**
|
|
204
114
|
* Automatically detect and handle OAuth callback parameters in the URL
|
|
205
115
|
* This runs on initialization to seamlessly complete the OAuth flow
|
|
@@ -266,22 +176,17 @@ declare class Auth {
|
|
|
266
176
|
*/
|
|
267
177
|
getCurrentUser(): Promise<{
|
|
268
178
|
data: {
|
|
269
|
-
user:
|
|
270
|
-
id: UserIdSchema;
|
|
271
|
-
email: EmailSchema;
|
|
272
|
-
role: RoleSchema;
|
|
273
|
-
};
|
|
274
|
-
profile: ProfileData | null;
|
|
179
|
+
user: UserSchema;
|
|
275
180
|
} | null;
|
|
276
181
|
error: any | null;
|
|
277
182
|
}>;
|
|
278
183
|
/**
|
|
279
184
|
* Get any user's profile by ID
|
|
280
|
-
* Returns profile information from the users table
|
|
185
|
+
* Returns profile information from the users table
|
|
281
186
|
*/
|
|
282
187
|
getProfile(userId: string): Promise<{
|
|
283
|
-
data:
|
|
284
|
-
error:
|
|
188
|
+
data: GetProfileResponse | null;
|
|
189
|
+
error: InsForgeError | null;
|
|
285
190
|
}>;
|
|
286
191
|
/**
|
|
287
192
|
* Get the current session (only session data, no API call)
|
|
@@ -296,10 +201,11 @@ declare class Auth {
|
|
|
296
201
|
/**
|
|
297
202
|
* Set/Update the current user's profile
|
|
298
203
|
* Updates profile information in the users table (supports any dynamic fields)
|
|
204
|
+
* Requires authentication
|
|
299
205
|
*/
|
|
300
|
-
setProfile(profile:
|
|
301
|
-
data:
|
|
302
|
-
error:
|
|
206
|
+
setProfile(profile: Record<string, unknown>): Promise<{
|
|
207
|
+
data: GetProfileResponse | null;
|
|
208
|
+
error: InsForgeError | null;
|
|
303
209
|
}>;
|
|
304
210
|
/**
|
|
305
211
|
* Send email verification (code or link based on config)
|
|
@@ -656,6 +562,133 @@ declare class Functions {
|
|
|
656
562
|
}>;
|
|
657
563
|
}
|
|
658
564
|
|
|
565
|
+
type ConnectionState = 'disconnected' | 'connecting' | 'connected';
|
|
566
|
+
type EventCallback<T = unknown> = (payload: T) => void;
|
|
567
|
+
/**
|
|
568
|
+
* Realtime module for subscribing to channels and handling real-time events
|
|
569
|
+
*
|
|
570
|
+
* @example
|
|
571
|
+
* ```typescript
|
|
572
|
+
* const { realtime } = client;
|
|
573
|
+
*
|
|
574
|
+
* // Connect to the realtime server
|
|
575
|
+
* await realtime.connect();
|
|
576
|
+
*
|
|
577
|
+
* // Subscribe to a channel
|
|
578
|
+
* const response = await realtime.subscribe('orders:123');
|
|
579
|
+
* if (!response.ok) {
|
|
580
|
+
* console.error('Failed to subscribe:', response.error);
|
|
581
|
+
* }
|
|
582
|
+
*
|
|
583
|
+
* // Listen for specific events
|
|
584
|
+
* realtime.on('order_updated', (payload) => {
|
|
585
|
+
* console.log('Order updated:', payload);
|
|
586
|
+
* });
|
|
587
|
+
*
|
|
588
|
+
* // Listen for connection events
|
|
589
|
+
* realtime.on('connect', () => console.log('Connected!'));
|
|
590
|
+
* realtime.on('connect_error', (err) => console.error('Connection failed:', err));
|
|
591
|
+
* realtime.on('disconnect', (reason) => console.log('Disconnected:', reason));
|
|
592
|
+
* realtime.on('error', (error) => console.error('Realtime error:', error));
|
|
593
|
+
*
|
|
594
|
+
* // Publish a message to a channel
|
|
595
|
+
* await realtime.publish('orders:123', 'status_changed', { status: 'shipped' });
|
|
596
|
+
*
|
|
597
|
+
* // Unsubscribe and disconnect when done
|
|
598
|
+
* realtime.unsubscribe('orders:123');
|
|
599
|
+
* realtime.disconnect();
|
|
600
|
+
* ```
|
|
601
|
+
*/
|
|
602
|
+
declare class Realtime {
|
|
603
|
+
private baseUrl;
|
|
604
|
+
private tokenManager;
|
|
605
|
+
private socket;
|
|
606
|
+
private connectPromise;
|
|
607
|
+
private subscribedChannels;
|
|
608
|
+
private eventListeners;
|
|
609
|
+
constructor(baseUrl: string, tokenManager: TokenManager);
|
|
610
|
+
private notifyListeners;
|
|
611
|
+
/**
|
|
612
|
+
* Connect to the realtime server
|
|
613
|
+
* @returns Promise that resolves when connected
|
|
614
|
+
*/
|
|
615
|
+
connect(): Promise<void>;
|
|
616
|
+
/**
|
|
617
|
+
* Disconnect from the realtime server
|
|
618
|
+
*/
|
|
619
|
+
disconnect(): void;
|
|
620
|
+
/**
|
|
621
|
+
* Check if connected to the realtime server
|
|
622
|
+
*/
|
|
623
|
+
get isConnected(): boolean;
|
|
624
|
+
/**
|
|
625
|
+
* Get the current connection state
|
|
626
|
+
*/
|
|
627
|
+
get connectionState(): ConnectionState;
|
|
628
|
+
/**
|
|
629
|
+
* Get the socket ID (if connected)
|
|
630
|
+
*/
|
|
631
|
+
get socketId(): string | undefined;
|
|
632
|
+
/**
|
|
633
|
+
* Subscribe to a channel
|
|
634
|
+
*
|
|
635
|
+
* Automatically connects if not already connected.
|
|
636
|
+
*
|
|
637
|
+
* @param channel - Channel name (e.g., 'orders:123', 'broadcast')
|
|
638
|
+
* @returns Promise with the subscription response
|
|
639
|
+
*/
|
|
640
|
+
subscribe(channel: string): Promise<SubscribeResponse>;
|
|
641
|
+
/**
|
|
642
|
+
* Unsubscribe from a channel (fire-and-forget)
|
|
643
|
+
*
|
|
644
|
+
* @param channel - Channel name to unsubscribe from
|
|
645
|
+
*/
|
|
646
|
+
unsubscribe(channel: string): void;
|
|
647
|
+
/**
|
|
648
|
+
* Publish a message to a channel
|
|
649
|
+
*
|
|
650
|
+
* @param channel - Channel name
|
|
651
|
+
* @param event - Event name
|
|
652
|
+
* @param payload - Message payload
|
|
653
|
+
*/
|
|
654
|
+
publish<T = unknown>(channel: string, event: string, payload: T): Promise<void>;
|
|
655
|
+
/**
|
|
656
|
+
* Listen for events
|
|
657
|
+
*
|
|
658
|
+
* Reserved event names:
|
|
659
|
+
* - 'connect' - Fired when connected to the server
|
|
660
|
+
* - 'connect_error' - Fired when connection fails (payload: Error)
|
|
661
|
+
* - 'disconnect' - Fired when disconnected (payload: reason string)
|
|
662
|
+
* - 'error' - Fired when a realtime error occurs (payload: RealtimeErrorPayload)
|
|
663
|
+
*
|
|
664
|
+
* All other events receive a `SocketMessage` payload with metadata.
|
|
665
|
+
*
|
|
666
|
+
* @param event - Event name to listen for
|
|
667
|
+
* @param callback - Callback function when event is received
|
|
668
|
+
*/
|
|
669
|
+
on<T = SocketMessage>(event: string, callback: EventCallback<T>): void;
|
|
670
|
+
/**
|
|
671
|
+
* Remove a listener for a specific event
|
|
672
|
+
*
|
|
673
|
+
* @param event - Event name
|
|
674
|
+
* @param callback - The callback function to remove
|
|
675
|
+
*/
|
|
676
|
+
off<T = SocketMessage>(event: string, callback: EventCallback<T>): void;
|
|
677
|
+
/**
|
|
678
|
+
* Listen for an event only once, then automatically remove the listener
|
|
679
|
+
*
|
|
680
|
+
* @param event - Event name to listen for
|
|
681
|
+
* @param callback - Callback function when event is received
|
|
682
|
+
*/
|
|
683
|
+
once<T = SocketMessage>(event: string, callback: EventCallback<T>): void;
|
|
684
|
+
/**
|
|
685
|
+
* Get all currently subscribed channels
|
|
686
|
+
*
|
|
687
|
+
* @returns Array of channel names
|
|
688
|
+
*/
|
|
689
|
+
getSubscribedChannels(): string[];
|
|
690
|
+
}
|
|
691
|
+
|
|
659
692
|
/**
|
|
660
693
|
* Main InsForge SDK Client
|
|
661
694
|
*
|
|
@@ -668,7 +701,7 @@ declare class Functions {
|
|
|
668
701
|
* });
|
|
669
702
|
*
|
|
670
703
|
* // Authentication
|
|
671
|
-
* const
|
|
704
|
+
* const session = await client.auth.register({
|
|
672
705
|
* email: 'user@example.com',
|
|
673
706
|
* password: 'password123',
|
|
674
707
|
* name: 'John Doe'
|
|
@@ -702,6 +735,7 @@ declare class InsForgeClient {
|
|
|
702
735
|
readonly storage: Storage;
|
|
703
736
|
readonly ai: AI;
|
|
704
737
|
readonly functions: Functions;
|
|
738
|
+
readonly realtime: Realtime;
|
|
705
739
|
constructor(config?: InsForgeConfig);
|
|
706
740
|
/**
|
|
707
741
|
* Get the underlying HTTP client for custom requests
|
|
@@ -723,4 +757,4 @@ declare class InsForgeClient {
|
|
|
723
757
|
|
|
724
758
|
declare function createClient(config: InsForgeConfig): InsForgeClient;
|
|
725
759
|
|
|
726
|
-
export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, Database, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError,
|
|
760
|
+
export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, type ConnectionState, Database, type EventCallback, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError, Realtime, Storage, StorageBucket, type StorageResponse, TokenManager, type TokenStorage, createClient, InsForgeClient as default };
|