@insforge/sdk 1.0.1-refresh.3 → 1.0.1-refresh.4
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.mts +54 -169
- package/dist/index.d.ts +54 -169
- package/dist/index.js +110 -212
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +109 -208
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -147,7 +147,7 @@ interface SessionStorageStrategy {
|
|
|
147
147
|
*
|
|
148
148
|
* Stores access token in memory only (cleared on page refresh).
|
|
149
149
|
* Refresh token is stored in httpOnly cookie by the backend.
|
|
150
|
-
*
|
|
150
|
+
* The `isAuthenticated` cookie is set by the backend to signal that a refresh token exists.
|
|
151
151
|
*
|
|
152
152
|
* Security benefits:
|
|
153
153
|
* - Access token not accessible to XSS attacks (in memory only)
|
|
@@ -165,7 +165,6 @@ declare class SecureSessionStorage implements SessionStorageStrategy {
|
|
|
165
165
|
setUser(user: UserSchema): void;
|
|
166
166
|
clearSession(): void;
|
|
167
167
|
shouldAttemptRefresh(): boolean;
|
|
168
|
-
private setAuthFlag;
|
|
169
168
|
private hasAuthFlag;
|
|
170
169
|
}
|
|
171
170
|
/**
|
|
@@ -191,64 +190,6 @@ declare class LocalSessionStorage implements SessionStorageStrategy {
|
|
|
191
190
|
shouldAttemptRefresh(): boolean;
|
|
192
191
|
}
|
|
193
192
|
|
|
194
|
-
/**
|
|
195
|
-
* Backend Configuration for InsForge SDK
|
|
196
|
-
*
|
|
197
|
-
* Fetches backend configuration via the /api/health endpoint
|
|
198
|
-
* and creates appropriate storage strategies based on that configuration.
|
|
199
|
-
*/
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Backend configuration returned from /api/health
|
|
203
|
-
*/
|
|
204
|
-
interface BackendConfig {
|
|
205
|
-
/** Whether backend supports secure httpOnly cookie storage for refresh tokens */
|
|
206
|
-
secureSessionStorage: boolean;
|
|
207
|
-
/** Whether backend supports token refresh endpoint */
|
|
208
|
-
refreshTokens: boolean;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Fetch backend configuration from the /api/health endpoint
|
|
212
|
-
*
|
|
213
|
-
* This is the primary method for determining which features the backend supports.
|
|
214
|
-
* The SDK uses this information to select appropriate storage strategies.
|
|
215
|
-
*
|
|
216
|
-
* @param baseUrl - The backend base URL
|
|
217
|
-
* @param fetchImpl - Optional custom fetch implementation
|
|
218
|
-
* @returns Backend configuration object
|
|
219
|
-
*
|
|
220
|
-
* @example
|
|
221
|
-
* ```typescript
|
|
222
|
-
* const config = await discoverBackendConfig('https://api.example.com');
|
|
223
|
-
* if (config.secureSessionStorage) {
|
|
224
|
-
* // Use secure storage strategy
|
|
225
|
-
* }
|
|
226
|
-
* ```
|
|
227
|
-
*/
|
|
228
|
-
declare function discoverBackendConfig(baseUrl: string, fetchImpl?: typeof fetch): Promise<BackendConfig>;
|
|
229
|
-
/**
|
|
230
|
-
* Create the appropriate session storage strategy based on backend configuration
|
|
231
|
-
*
|
|
232
|
-
* This is the factory function that implements the Strategy Pattern.
|
|
233
|
-
* It selects the storage implementation based on what the backend supports.
|
|
234
|
-
*
|
|
235
|
-
* @param config - Backend configuration from discoverBackendConfig()
|
|
236
|
-
* @param storage - Optional custom storage adapter (for LocalSessionStorage)
|
|
237
|
-
* @returns Appropriate SessionStorageStrategy implementation
|
|
238
|
-
*
|
|
239
|
-
* @example
|
|
240
|
-
* ```typescript
|
|
241
|
-
* const config = await discoverBackendConfig(baseUrl);
|
|
242
|
-
* const storage = createSessionStorage(config);
|
|
243
|
-
* storage.saveSession({ accessToken: '...', user: {...} });
|
|
244
|
-
* ```
|
|
245
|
-
*/
|
|
246
|
-
declare function createSessionStorage(config: BackendConfig, storage?: TokenStorage): SessionStorageStrategy;
|
|
247
|
-
/**
|
|
248
|
-
* Get default backend configuration (useful for testing or manual override)
|
|
249
|
-
*/
|
|
250
|
-
declare function getDefaultBackendConfig(): BackendConfig;
|
|
251
|
-
|
|
252
193
|
/**
|
|
253
194
|
* Token Manager for InsForge SDK
|
|
254
195
|
*
|
|
@@ -334,66 +275,38 @@ type ProfileData = Record<string, any> & {
|
|
|
334
275
|
* Supports any fields that exist in the profile table
|
|
335
276
|
*/
|
|
336
277
|
type UpdateProfileData = Partial<Record<string, any>>;
|
|
337
|
-
/**
|
|
338
|
-
* Auth state change event types
|
|
339
|
-
* Following Supabase pattern for consistency
|
|
340
|
-
*/
|
|
341
|
-
type AuthStateChangeEvent = 'INITIAL_SESSION' | 'SIGNED_IN' | 'SIGNED_OUT' | 'TOKEN_REFRESHED';
|
|
342
|
-
/**
|
|
343
|
-
* Auth state change callback type
|
|
344
|
-
*/
|
|
345
|
-
type AuthStateChangeCallback = (event: AuthStateChangeEvent, session: AuthSession | null) => void;
|
|
346
278
|
declare class Auth {
|
|
347
279
|
private http;
|
|
348
280
|
private tokenManager;
|
|
349
281
|
private database;
|
|
350
|
-
|
|
351
|
-
private initializePromise;
|
|
352
|
-
constructor(http: HttpClient, tokenManager: TokenManager, initializePromise?: Promise<void>);
|
|
282
|
+
constructor(http: HttpClient, tokenManager: TokenManager);
|
|
353
283
|
/**
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
* New subscribers will receive an INITIAL_SESSION event after initialization completes.
|
|
357
|
-
* This ensures no race condition where subscribers miss the initial state.
|
|
358
|
-
*
|
|
359
|
-
* @param callback - Function called when auth state changes
|
|
360
|
-
* @returns Unsubscribe function
|
|
361
|
-
*
|
|
362
|
-
* @example
|
|
363
|
-
* ```typescript
|
|
364
|
-
* const { data: { subscription } } = client.auth.onAuthStateChange((event, session) => {
|
|
365
|
-
* if (event === 'SIGNED_IN') {
|
|
366
|
-
* console.log('User signed in:', session?.user.email);
|
|
367
|
-
* } else if (event === 'SIGNED_OUT') {
|
|
368
|
-
* console.log('User signed out');
|
|
369
|
-
* }
|
|
370
|
-
* });
|
|
371
|
-
*
|
|
372
|
-
* // Later: unsubscribe
|
|
373
|
-
* subscription.unsubscribe();
|
|
374
|
-
* ```
|
|
284
|
+
* Check if the isAuthenticated cookie flag exists
|
|
375
285
|
*/
|
|
376
|
-
|
|
377
|
-
data: {
|
|
378
|
-
subscription: {
|
|
379
|
-
unsubscribe: () => void;
|
|
380
|
-
};
|
|
381
|
-
};
|
|
382
|
-
};
|
|
286
|
+
private hasAuthenticatedCookie;
|
|
383
287
|
/**
|
|
384
|
-
*
|
|
288
|
+
* Switch to SecureSessionStorage (cookie-based auth)
|
|
289
|
+
* Called when we detect backend supports secure cookie mode
|
|
385
290
|
* @internal
|
|
386
291
|
*/
|
|
387
|
-
|
|
292
|
+
_switchToSecureStorage(): void;
|
|
388
293
|
/**
|
|
389
|
-
*
|
|
390
|
-
*
|
|
294
|
+
* Switch to LocalSessionStorage (localStorage-based auth)
|
|
295
|
+
* Called when cookie-based auth fails (fallback)
|
|
296
|
+
* @internal
|
|
391
297
|
*/
|
|
392
|
-
|
|
298
|
+
_switchToLocalStorage(): void;
|
|
393
299
|
/**
|
|
394
|
-
* Detect
|
|
395
|
-
*
|
|
300
|
+
* Detect storage strategy after successful auth
|
|
301
|
+
* Checks for isAuthenticated cookie to determine backend mode
|
|
302
|
+
* @internal
|
|
396
303
|
*/
|
|
304
|
+
private _detectStorageAfterAuth;
|
|
305
|
+
/**
|
|
306
|
+
* Automatically detect and handle OAuth callback parameters in the URL
|
|
307
|
+
* This runs on initialization to seamlessly complete the OAuth flow
|
|
308
|
+
* Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)
|
|
309
|
+
*/
|
|
397
310
|
detectAuthCallback(): void;
|
|
398
311
|
/**
|
|
399
312
|
* Sign up a new user
|
|
@@ -460,6 +373,9 @@ declare class Auth {
|
|
|
460
373
|
/**
|
|
461
374
|
* Get the current user with full profile information
|
|
462
375
|
* Returns both auth info (id, email, role) and profile data (dynamic fields from users table)
|
|
376
|
+
*
|
|
377
|
+
* In secure session mode (httpOnly cookie), this method will automatically attempt
|
|
378
|
+
* to refresh the session if no access token is available (e.g., after page reload).
|
|
463
379
|
*/
|
|
464
380
|
getCurrentUser(): Promise<{
|
|
465
381
|
data: {
|
|
@@ -856,98 +772,65 @@ declare class Functions {
|
|
|
856
772
|
/**
|
|
857
773
|
* Main InsForge SDK Client
|
|
858
774
|
*
|
|
859
|
-
* The client automatically initializes in the background and emits auth state changes.
|
|
860
|
-
* Subscribe to `auth.onAuthStateChange` to be notified when initialization completes.
|
|
861
|
-
*
|
|
862
775
|
* @example
|
|
863
776
|
* ```typescript
|
|
864
777
|
* import { InsForgeClient } from '@insforge/sdk';
|
|
865
778
|
*
|
|
866
|
-
* // Create client - synchronous, immediately usable
|
|
867
779
|
* const client = new InsForgeClient({
|
|
868
780
|
* baseUrl: 'http://localhost:7130'
|
|
869
781
|
* });
|
|
870
782
|
*
|
|
871
|
-
* //
|
|
872
|
-
* client.auth.
|
|
873
|
-
*
|
|
874
|
-
*
|
|
875
|
-
*
|
|
876
|
-
* }
|
|
783
|
+
* // Authentication
|
|
784
|
+
* const { data, error } = await client.auth.signUp({
|
|
785
|
+
* email: 'user@example.com',
|
|
786
|
+
* password: 'password123',
|
|
787
|
+
* name: 'John Doe'
|
|
877
788
|
* });
|
|
878
789
|
*
|
|
879
|
-
* //
|
|
880
|
-
* const { data, error } = await client.
|
|
881
|
-
*
|
|
882
|
-
*
|
|
790
|
+
* // Database operations
|
|
791
|
+
* const { data, error } = await client.database
|
|
792
|
+
* .from('posts')
|
|
793
|
+
* .select('*')
|
|
794
|
+
* .eq('user_id', session.user.id)
|
|
795
|
+
* .order('created_at', { ascending: false })
|
|
796
|
+
* .limit(10);
|
|
797
|
+
*
|
|
798
|
+
* // Insert data
|
|
799
|
+
* const { data: newPost } = await client.database
|
|
800
|
+
* .from('posts')
|
|
801
|
+
* .insert({ title: 'Hello', content: 'World' })
|
|
802
|
+
* .single();
|
|
803
|
+
*
|
|
804
|
+
* // Invoke edge functions
|
|
805
|
+
* const { data, error } = await client.functions.invoke('my-function', {
|
|
806
|
+
* body: { message: 'Hello from SDK' }
|
|
883
807
|
* });
|
|
884
808
|
* ```
|
|
885
809
|
*/
|
|
886
810
|
declare class InsForgeClient {
|
|
887
811
|
private http;
|
|
888
812
|
private tokenManager;
|
|
889
|
-
private backendConfig;
|
|
890
|
-
/**
|
|
891
|
-
* Promise that resolves when initialization is complete.
|
|
892
|
-
* Use this to ensure operations wait for the client to be ready.
|
|
893
|
-
*/
|
|
894
|
-
private initializePromise;
|
|
895
|
-
private initializeResolve;
|
|
896
813
|
readonly auth: Auth;
|
|
897
814
|
readonly database: Database;
|
|
898
815
|
readonly storage: Storage;
|
|
899
816
|
readonly ai: AI;
|
|
900
817
|
readonly functions: Functions;
|
|
901
818
|
constructor(config?: InsForgeConfig);
|
|
902
|
-
/**
|
|
903
|
-
* Internal async initialization - discovers backend config and recovers session.
|
|
904
|
-
* Emits INITIAL_SESSION event when complete.
|
|
905
|
-
* @internal
|
|
906
|
-
*/
|
|
907
|
-
private _initializeAsync;
|
|
908
|
-
/**
|
|
909
|
-
* Wait for client initialization to complete
|
|
910
|
-
* @returns Promise that resolves when initialization is done
|
|
911
|
-
*/
|
|
912
|
-
waitForInitialization(): Promise<void>;
|
|
913
819
|
/**
|
|
914
820
|
* Get the underlying HTTP client for custom requests
|
|
821
|
+
*
|
|
822
|
+
* @example
|
|
823
|
+
* ```typescript
|
|
824
|
+
* const httpClient = client.getHttpClient();
|
|
825
|
+
* const customData = await httpClient.get('/api/custom-endpoint');
|
|
826
|
+
* ```
|
|
915
827
|
*/
|
|
916
828
|
getHttpClient(): HttpClient;
|
|
917
|
-
/**
|
|
918
|
-
* Get the discovered backend configuration
|
|
919
|
-
*/
|
|
920
|
-
getBackendConfig(): BackendConfig | null;
|
|
921
829
|
/**
|
|
922
830
|
* Get the current storage strategy identifier
|
|
923
831
|
*/
|
|
924
832
|
getStorageStrategy(): string;
|
|
925
833
|
}
|
|
926
|
-
/**
|
|
927
|
-
* Create an InsForge client.
|
|
928
|
-
* This is a convenience alias for `new InsForgeClient(config)`.
|
|
929
|
-
*
|
|
930
|
-
* Note: The client initializes asynchronously in the background.
|
|
931
|
-
* Subscribe to `auth.onAuthStateChange` to be notified when ready.
|
|
932
|
-
*
|
|
933
|
-
* @example
|
|
934
|
-
* ```typescript
|
|
935
|
-
* import { createClient } from '@insforge/sdk';
|
|
936
|
-
*
|
|
937
|
-
* const client = createClient({
|
|
938
|
-
* baseUrl: 'http://localhost:7130'
|
|
939
|
-
* });
|
|
940
|
-
*
|
|
941
|
-
* // Subscribe to auth state changes
|
|
942
|
-
* client.auth.onAuthStateChange((event, session) => {
|
|
943
|
-
* if (event === 'INITIAL_SESSION') {
|
|
944
|
-
* // Initialization complete
|
|
945
|
-
* console.log('Ready!', session ? 'Logged in' : 'Not logged in');
|
|
946
|
-
* }
|
|
947
|
-
* });
|
|
948
|
-
* ```
|
|
949
|
-
*/
|
|
950
|
-
declare function createClient(config?: InsForgeConfig): InsForgeClient;
|
|
951
834
|
|
|
952
835
|
/**
|
|
953
836
|
* @insforge/sdk - TypeScript SDK for InsForge Backend-as-a-Service
|
|
@@ -955,4 +838,6 @@ declare function createClient(config?: InsForgeConfig): InsForgeClient;
|
|
|
955
838
|
* @packageDocumentation
|
|
956
839
|
*/
|
|
957
840
|
|
|
958
|
-
|
|
841
|
+
declare function createClient(config: InsForgeConfig): InsForgeClient;
|
|
842
|
+
|
|
843
|
+
export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, Database, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError, LocalSessionStorage, type ProfileData, SecureSessionStorage, type SessionStorageStrategy, Storage, StorageBucket, type StorageResponse, TokenManager, type TokenStorage, type UpdateProfileData, createClient, InsForgeClient as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -147,7 +147,7 @@ interface SessionStorageStrategy {
|
|
|
147
147
|
*
|
|
148
148
|
* Stores access token in memory only (cleared on page refresh).
|
|
149
149
|
* Refresh token is stored in httpOnly cookie by the backend.
|
|
150
|
-
*
|
|
150
|
+
* The `isAuthenticated` cookie is set by the backend to signal that a refresh token exists.
|
|
151
151
|
*
|
|
152
152
|
* Security benefits:
|
|
153
153
|
* - Access token not accessible to XSS attacks (in memory only)
|
|
@@ -165,7 +165,6 @@ declare class SecureSessionStorage implements SessionStorageStrategy {
|
|
|
165
165
|
setUser(user: UserSchema): void;
|
|
166
166
|
clearSession(): void;
|
|
167
167
|
shouldAttemptRefresh(): boolean;
|
|
168
|
-
private setAuthFlag;
|
|
169
168
|
private hasAuthFlag;
|
|
170
169
|
}
|
|
171
170
|
/**
|
|
@@ -191,64 +190,6 @@ declare class LocalSessionStorage implements SessionStorageStrategy {
|
|
|
191
190
|
shouldAttemptRefresh(): boolean;
|
|
192
191
|
}
|
|
193
192
|
|
|
194
|
-
/**
|
|
195
|
-
* Backend Configuration for InsForge SDK
|
|
196
|
-
*
|
|
197
|
-
* Fetches backend configuration via the /api/health endpoint
|
|
198
|
-
* and creates appropriate storage strategies based on that configuration.
|
|
199
|
-
*/
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Backend configuration returned from /api/health
|
|
203
|
-
*/
|
|
204
|
-
interface BackendConfig {
|
|
205
|
-
/** Whether backend supports secure httpOnly cookie storage for refresh tokens */
|
|
206
|
-
secureSessionStorage: boolean;
|
|
207
|
-
/** Whether backend supports token refresh endpoint */
|
|
208
|
-
refreshTokens: boolean;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Fetch backend configuration from the /api/health endpoint
|
|
212
|
-
*
|
|
213
|
-
* This is the primary method for determining which features the backend supports.
|
|
214
|
-
* The SDK uses this information to select appropriate storage strategies.
|
|
215
|
-
*
|
|
216
|
-
* @param baseUrl - The backend base URL
|
|
217
|
-
* @param fetchImpl - Optional custom fetch implementation
|
|
218
|
-
* @returns Backend configuration object
|
|
219
|
-
*
|
|
220
|
-
* @example
|
|
221
|
-
* ```typescript
|
|
222
|
-
* const config = await discoverBackendConfig('https://api.example.com');
|
|
223
|
-
* if (config.secureSessionStorage) {
|
|
224
|
-
* // Use secure storage strategy
|
|
225
|
-
* }
|
|
226
|
-
* ```
|
|
227
|
-
*/
|
|
228
|
-
declare function discoverBackendConfig(baseUrl: string, fetchImpl?: typeof fetch): Promise<BackendConfig>;
|
|
229
|
-
/**
|
|
230
|
-
* Create the appropriate session storage strategy based on backend configuration
|
|
231
|
-
*
|
|
232
|
-
* This is the factory function that implements the Strategy Pattern.
|
|
233
|
-
* It selects the storage implementation based on what the backend supports.
|
|
234
|
-
*
|
|
235
|
-
* @param config - Backend configuration from discoverBackendConfig()
|
|
236
|
-
* @param storage - Optional custom storage adapter (for LocalSessionStorage)
|
|
237
|
-
* @returns Appropriate SessionStorageStrategy implementation
|
|
238
|
-
*
|
|
239
|
-
* @example
|
|
240
|
-
* ```typescript
|
|
241
|
-
* const config = await discoverBackendConfig(baseUrl);
|
|
242
|
-
* const storage = createSessionStorage(config);
|
|
243
|
-
* storage.saveSession({ accessToken: '...', user: {...} });
|
|
244
|
-
* ```
|
|
245
|
-
*/
|
|
246
|
-
declare function createSessionStorage(config: BackendConfig, storage?: TokenStorage): SessionStorageStrategy;
|
|
247
|
-
/**
|
|
248
|
-
* Get default backend configuration (useful for testing or manual override)
|
|
249
|
-
*/
|
|
250
|
-
declare function getDefaultBackendConfig(): BackendConfig;
|
|
251
|
-
|
|
252
193
|
/**
|
|
253
194
|
* Token Manager for InsForge SDK
|
|
254
195
|
*
|
|
@@ -334,66 +275,38 @@ type ProfileData = Record<string, any> & {
|
|
|
334
275
|
* Supports any fields that exist in the profile table
|
|
335
276
|
*/
|
|
336
277
|
type UpdateProfileData = Partial<Record<string, any>>;
|
|
337
|
-
/**
|
|
338
|
-
* Auth state change event types
|
|
339
|
-
* Following Supabase pattern for consistency
|
|
340
|
-
*/
|
|
341
|
-
type AuthStateChangeEvent = 'INITIAL_SESSION' | 'SIGNED_IN' | 'SIGNED_OUT' | 'TOKEN_REFRESHED';
|
|
342
|
-
/**
|
|
343
|
-
* Auth state change callback type
|
|
344
|
-
*/
|
|
345
|
-
type AuthStateChangeCallback = (event: AuthStateChangeEvent, session: AuthSession | null) => void;
|
|
346
278
|
declare class Auth {
|
|
347
279
|
private http;
|
|
348
280
|
private tokenManager;
|
|
349
281
|
private database;
|
|
350
|
-
|
|
351
|
-
private initializePromise;
|
|
352
|
-
constructor(http: HttpClient, tokenManager: TokenManager, initializePromise?: Promise<void>);
|
|
282
|
+
constructor(http: HttpClient, tokenManager: TokenManager);
|
|
353
283
|
/**
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
* New subscribers will receive an INITIAL_SESSION event after initialization completes.
|
|
357
|
-
* This ensures no race condition where subscribers miss the initial state.
|
|
358
|
-
*
|
|
359
|
-
* @param callback - Function called when auth state changes
|
|
360
|
-
* @returns Unsubscribe function
|
|
361
|
-
*
|
|
362
|
-
* @example
|
|
363
|
-
* ```typescript
|
|
364
|
-
* const { data: { subscription } } = client.auth.onAuthStateChange((event, session) => {
|
|
365
|
-
* if (event === 'SIGNED_IN') {
|
|
366
|
-
* console.log('User signed in:', session?.user.email);
|
|
367
|
-
* } else if (event === 'SIGNED_OUT') {
|
|
368
|
-
* console.log('User signed out');
|
|
369
|
-
* }
|
|
370
|
-
* });
|
|
371
|
-
*
|
|
372
|
-
* // Later: unsubscribe
|
|
373
|
-
* subscription.unsubscribe();
|
|
374
|
-
* ```
|
|
284
|
+
* Check if the isAuthenticated cookie flag exists
|
|
375
285
|
*/
|
|
376
|
-
|
|
377
|
-
data: {
|
|
378
|
-
subscription: {
|
|
379
|
-
unsubscribe: () => void;
|
|
380
|
-
};
|
|
381
|
-
};
|
|
382
|
-
};
|
|
286
|
+
private hasAuthenticatedCookie;
|
|
383
287
|
/**
|
|
384
|
-
*
|
|
288
|
+
* Switch to SecureSessionStorage (cookie-based auth)
|
|
289
|
+
* Called when we detect backend supports secure cookie mode
|
|
385
290
|
* @internal
|
|
386
291
|
*/
|
|
387
|
-
|
|
292
|
+
_switchToSecureStorage(): void;
|
|
388
293
|
/**
|
|
389
|
-
*
|
|
390
|
-
*
|
|
294
|
+
* Switch to LocalSessionStorage (localStorage-based auth)
|
|
295
|
+
* Called when cookie-based auth fails (fallback)
|
|
296
|
+
* @internal
|
|
391
297
|
*/
|
|
392
|
-
|
|
298
|
+
_switchToLocalStorage(): void;
|
|
393
299
|
/**
|
|
394
|
-
* Detect
|
|
395
|
-
*
|
|
300
|
+
* Detect storage strategy after successful auth
|
|
301
|
+
* Checks for isAuthenticated cookie to determine backend mode
|
|
302
|
+
* @internal
|
|
396
303
|
*/
|
|
304
|
+
private _detectStorageAfterAuth;
|
|
305
|
+
/**
|
|
306
|
+
* Automatically detect and handle OAuth callback parameters in the URL
|
|
307
|
+
* This runs on initialization to seamlessly complete the OAuth flow
|
|
308
|
+
* Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)
|
|
309
|
+
*/
|
|
397
310
|
detectAuthCallback(): void;
|
|
398
311
|
/**
|
|
399
312
|
* Sign up a new user
|
|
@@ -460,6 +373,9 @@ declare class Auth {
|
|
|
460
373
|
/**
|
|
461
374
|
* Get the current user with full profile information
|
|
462
375
|
* Returns both auth info (id, email, role) and profile data (dynamic fields from users table)
|
|
376
|
+
*
|
|
377
|
+
* In secure session mode (httpOnly cookie), this method will automatically attempt
|
|
378
|
+
* to refresh the session if no access token is available (e.g., after page reload).
|
|
463
379
|
*/
|
|
464
380
|
getCurrentUser(): Promise<{
|
|
465
381
|
data: {
|
|
@@ -856,98 +772,65 @@ declare class Functions {
|
|
|
856
772
|
/**
|
|
857
773
|
* Main InsForge SDK Client
|
|
858
774
|
*
|
|
859
|
-
* The client automatically initializes in the background and emits auth state changes.
|
|
860
|
-
* Subscribe to `auth.onAuthStateChange` to be notified when initialization completes.
|
|
861
|
-
*
|
|
862
775
|
* @example
|
|
863
776
|
* ```typescript
|
|
864
777
|
* import { InsForgeClient } from '@insforge/sdk';
|
|
865
778
|
*
|
|
866
|
-
* // Create client - synchronous, immediately usable
|
|
867
779
|
* const client = new InsForgeClient({
|
|
868
780
|
* baseUrl: 'http://localhost:7130'
|
|
869
781
|
* });
|
|
870
782
|
*
|
|
871
|
-
* //
|
|
872
|
-
* client.auth.
|
|
873
|
-
*
|
|
874
|
-
*
|
|
875
|
-
*
|
|
876
|
-
* }
|
|
783
|
+
* // Authentication
|
|
784
|
+
* const { data, error } = await client.auth.signUp({
|
|
785
|
+
* email: 'user@example.com',
|
|
786
|
+
* password: 'password123',
|
|
787
|
+
* name: 'John Doe'
|
|
877
788
|
* });
|
|
878
789
|
*
|
|
879
|
-
* //
|
|
880
|
-
* const { data, error } = await client.
|
|
881
|
-
*
|
|
882
|
-
*
|
|
790
|
+
* // Database operations
|
|
791
|
+
* const { data, error } = await client.database
|
|
792
|
+
* .from('posts')
|
|
793
|
+
* .select('*')
|
|
794
|
+
* .eq('user_id', session.user.id)
|
|
795
|
+
* .order('created_at', { ascending: false })
|
|
796
|
+
* .limit(10);
|
|
797
|
+
*
|
|
798
|
+
* // Insert data
|
|
799
|
+
* const { data: newPost } = await client.database
|
|
800
|
+
* .from('posts')
|
|
801
|
+
* .insert({ title: 'Hello', content: 'World' })
|
|
802
|
+
* .single();
|
|
803
|
+
*
|
|
804
|
+
* // Invoke edge functions
|
|
805
|
+
* const { data, error } = await client.functions.invoke('my-function', {
|
|
806
|
+
* body: { message: 'Hello from SDK' }
|
|
883
807
|
* });
|
|
884
808
|
* ```
|
|
885
809
|
*/
|
|
886
810
|
declare class InsForgeClient {
|
|
887
811
|
private http;
|
|
888
812
|
private tokenManager;
|
|
889
|
-
private backendConfig;
|
|
890
|
-
/**
|
|
891
|
-
* Promise that resolves when initialization is complete.
|
|
892
|
-
* Use this to ensure operations wait for the client to be ready.
|
|
893
|
-
*/
|
|
894
|
-
private initializePromise;
|
|
895
|
-
private initializeResolve;
|
|
896
813
|
readonly auth: Auth;
|
|
897
814
|
readonly database: Database;
|
|
898
815
|
readonly storage: Storage;
|
|
899
816
|
readonly ai: AI;
|
|
900
817
|
readonly functions: Functions;
|
|
901
818
|
constructor(config?: InsForgeConfig);
|
|
902
|
-
/**
|
|
903
|
-
* Internal async initialization - discovers backend config and recovers session.
|
|
904
|
-
* Emits INITIAL_SESSION event when complete.
|
|
905
|
-
* @internal
|
|
906
|
-
*/
|
|
907
|
-
private _initializeAsync;
|
|
908
|
-
/**
|
|
909
|
-
* Wait for client initialization to complete
|
|
910
|
-
* @returns Promise that resolves when initialization is done
|
|
911
|
-
*/
|
|
912
|
-
waitForInitialization(): Promise<void>;
|
|
913
819
|
/**
|
|
914
820
|
* Get the underlying HTTP client for custom requests
|
|
821
|
+
*
|
|
822
|
+
* @example
|
|
823
|
+
* ```typescript
|
|
824
|
+
* const httpClient = client.getHttpClient();
|
|
825
|
+
* const customData = await httpClient.get('/api/custom-endpoint');
|
|
826
|
+
* ```
|
|
915
827
|
*/
|
|
916
828
|
getHttpClient(): HttpClient;
|
|
917
|
-
/**
|
|
918
|
-
* Get the discovered backend configuration
|
|
919
|
-
*/
|
|
920
|
-
getBackendConfig(): BackendConfig | null;
|
|
921
829
|
/**
|
|
922
830
|
* Get the current storage strategy identifier
|
|
923
831
|
*/
|
|
924
832
|
getStorageStrategy(): string;
|
|
925
833
|
}
|
|
926
|
-
/**
|
|
927
|
-
* Create an InsForge client.
|
|
928
|
-
* This is a convenience alias for `new InsForgeClient(config)`.
|
|
929
|
-
*
|
|
930
|
-
* Note: The client initializes asynchronously in the background.
|
|
931
|
-
* Subscribe to `auth.onAuthStateChange` to be notified when ready.
|
|
932
|
-
*
|
|
933
|
-
* @example
|
|
934
|
-
* ```typescript
|
|
935
|
-
* import { createClient } from '@insforge/sdk';
|
|
936
|
-
*
|
|
937
|
-
* const client = createClient({
|
|
938
|
-
* baseUrl: 'http://localhost:7130'
|
|
939
|
-
* });
|
|
940
|
-
*
|
|
941
|
-
* // Subscribe to auth state changes
|
|
942
|
-
* client.auth.onAuthStateChange((event, session) => {
|
|
943
|
-
* if (event === 'INITIAL_SESSION') {
|
|
944
|
-
* // Initialization complete
|
|
945
|
-
* console.log('Ready!', session ? 'Logged in' : 'Not logged in');
|
|
946
|
-
* }
|
|
947
|
-
* });
|
|
948
|
-
* ```
|
|
949
|
-
*/
|
|
950
|
-
declare function createClient(config?: InsForgeConfig): InsForgeClient;
|
|
951
834
|
|
|
952
835
|
/**
|
|
953
836
|
* @insforge/sdk - TypeScript SDK for InsForge Backend-as-a-Service
|
|
@@ -955,4 +838,6 @@ declare function createClient(config?: InsForgeConfig): InsForgeClient;
|
|
|
955
838
|
* @packageDocumentation
|
|
956
839
|
*/
|
|
957
840
|
|
|
958
|
-
|
|
841
|
+
declare function createClient(config: InsForgeConfig): InsForgeClient;
|
|
842
|
+
|
|
843
|
+
export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, Database, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError, LocalSessionStorage, type ProfileData, SecureSessionStorage, type SessionStorageStrategy, Storage, StorageBucket, type StorageResponse, TokenManager, type TokenStorage, type UpdateProfileData, createClient, InsForgeClient as default };
|