@insforge/sdk 1.0.1-refresh.7 → 1.0.1-refresh.8
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 +46 -169
- package/dist/index.d.ts +46 -169
- package/dist/index.js +170 -406
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +170 -404
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -74,33 +74,15 @@ declare class InsForgeError extends Error {
|
|
|
74
74
|
interface RequestOptions extends RequestInit {
|
|
75
75
|
params?: Record<string, string>;
|
|
76
76
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Callback type for token refresh
|
|
79
|
-
* Returns new access token or null if refresh failed
|
|
80
|
-
*/
|
|
81
|
-
type RefreshCallback = () => Promise<string | null>;
|
|
82
77
|
declare class HttpClient {
|
|
83
78
|
readonly baseUrl: string;
|
|
84
79
|
readonly fetch: typeof fetch;
|
|
85
80
|
private defaultHeaders;
|
|
86
81
|
private anonKey;
|
|
87
82
|
private userToken;
|
|
88
|
-
private refreshCallback?;
|
|
89
|
-
private isRefreshing;
|
|
90
|
-
private refreshQueue;
|
|
91
83
|
constructor(config: InsForgeConfig);
|
|
92
|
-
/**
|
|
93
|
-
* Set the refresh callback for automatic token refresh on 401
|
|
94
|
-
*/
|
|
95
|
-
setRefreshCallback(callback: RefreshCallback): void;
|
|
96
84
|
private buildUrl;
|
|
97
85
|
request<T>(method: string, path: string, options?: RequestOptions): Promise<T>;
|
|
98
|
-
private performRequest;
|
|
99
|
-
/**
|
|
100
|
-
* Handle token refresh with queue to prevent duplicate refreshes
|
|
101
|
-
* Multiple concurrent 401s will wait for a single refresh to complete
|
|
102
|
-
*/
|
|
103
|
-
private handleTokenRefresh;
|
|
104
86
|
get<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
105
87
|
post<T>(path: string, body?: any, options?: RequestOptions): Promise<T>;
|
|
106
88
|
put<T>(path: string, body?: any, options?: RequestOptions): Promise<T>;
|
|
@@ -111,118 +93,38 @@ declare class HttpClient {
|
|
|
111
93
|
}
|
|
112
94
|
|
|
113
95
|
/**
|
|
114
|
-
*
|
|
96
|
+
* Token Manager for InsForge SDK
|
|
115
97
|
*
|
|
116
|
-
*
|
|
117
|
-
* -
|
|
118
|
-
* -
|
|
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
|
|
119
101
|
*/
|
|
120
102
|
|
|
121
|
-
|
|
122
|
-
* Strategy interface for session storage
|
|
123
|
-
* All storage implementations must conform to this interface
|
|
124
|
-
*/
|
|
125
|
-
interface SessionStorageStrategy {
|
|
126
|
-
/** Save complete session (token + user) */
|
|
127
|
-
saveSession(session: AuthSession): void;
|
|
128
|
-
/** Get current session */
|
|
129
|
-
getSession(): AuthSession | null;
|
|
130
|
-
/** Get access token only */
|
|
131
|
-
getAccessToken(): string | null;
|
|
132
|
-
/** Update access token (e.g., after refresh) */
|
|
133
|
-
setAccessToken(token: string): void;
|
|
134
|
-
/** Get user data */
|
|
135
|
-
getUser(): UserSchema | null;
|
|
136
|
-
/** Update user data */
|
|
137
|
-
setUser(user: UserSchema): void;
|
|
138
|
-
/** Clear all session data */
|
|
139
|
-
clearSession(): void;
|
|
140
|
-
/** Check if token refresh should be attempted (e.g., on page reload) */
|
|
141
|
-
shouldAttemptRefresh(): boolean;
|
|
142
|
-
/** Get strategy identifier for debugging */
|
|
143
|
-
readonly strategyId: string;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Secure Session Storage Strategy
|
|
147
|
-
*
|
|
148
|
-
* Stores access token in memory only (cleared on page refresh).
|
|
149
|
-
* Refresh token is stored in httpOnly cookie by the backend (on backend domain).
|
|
150
|
-
* The `isAuthenticated` cookie is set by the SDK on the frontend domain to signal
|
|
151
|
-
* that a secure session exists and token refresh should be attempted on page reload.
|
|
152
|
-
*
|
|
153
|
-
* Security benefits:
|
|
154
|
-
* - Access token not accessible to XSS attacks (in memory only)
|
|
155
|
-
* - Refresh token completely inaccessible to JavaScript (httpOnly)
|
|
156
|
-
*/
|
|
157
|
-
declare class SecureSessionStorage implements SessionStorageStrategy {
|
|
158
|
-
readonly strategyId = "secure";
|
|
103
|
+
declare class TokenManager {
|
|
159
104
|
private accessToken;
|
|
160
105
|
private user;
|
|
161
|
-
saveSession(session: AuthSession): void;
|
|
162
|
-
getSession(): AuthSession | null;
|
|
163
|
-
getAccessToken(): string | null;
|
|
164
|
-
setAccessToken(token: string): void;
|
|
165
|
-
getUser(): UserSchema | null;
|
|
166
|
-
setUser(user: UserSchema): void;
|
|
167
|
-
clearSession(): void;
|
|
168
|
-
shouldAttemptRefresh(): boolean;
|
|
169
|
-
private hasAuthFlag;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Local Session Storage Strategy
|
|
173
|
-
*
|
|
174
|
-
* Stores tokens in localStorage for persistence across page reloads.
|
|
175
|
-
* Used for legacy backends or environments where httpOnly cookies aren't available.
|
|
176
|
-
*
|
|
177
|
-
* Note: This approach exposes tokens to XSS attacks. Use SecureSessionStorage
|
|
178
|
-
* when possible.
|
|
179
|
-
*/
|
|
180
|
-
declare class LocalSessionStorage implements SessionStorageStrategy {
|
|
181
|
-
readonly strategyId = "local";
|
|
182
106
|
private storage;
|
|
107
|
+
private _mode;
|
|
183
108
|
constructor(storage?: TokenStorage);
|
|
184
|
-
saveSession(session: AuthSession): void;
|
|
185
|
-
getSession(): AuthSession | null;
|
|
186
|
-
getAccessToken(): string | null;
|
|
187
|
-
setAccessToken(token: string): void;
|
|
188
|
-
getUser(): UserSchema | null;
|
|
189
|
-
setUser(user: UserSchema): void;
|
|
190
|
-
clearSession(): void;
|
|
191
|
-
shouldAttemptRefresh(): boolean;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Token Manager for InsForge SDK
|
|
196
|
-
*
|
|
197
|
-
* A thin wrapper that delegates to the underlying SessionStorageStrategy.
|
|
198
|
-
* This class maintains backward compatibility while using the Strategy Pattern internally.
|
|
199
|
-
*/
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* TokenManager - Manages session storage using the Strategy Pattern
|
|
203
|
-
*
|
|
204
|
-
* The actual storage implementation is delegated to a SessionStorageStrategy.
|
|
205
|
-
* By default, uses LocalSessionStorage until a strategy is explicitly set
|
|
206
|
-
* via setStrategy() during client initialization.
|
|
207
|
-
*/
|
|
208
|
-
declare class TokenManager {
|
|
209
|
-
private strategy;
|
|
210
109
|
/**
|
|
211
|
-
*
|
|
212
|
-
* @param storage - Optional custom storage adapter (used for initial LocalSessionStorage)
|
|
110
|
+
* Get current mode
|
|
213
111
|
*/
|
|
214
|
-
|
|
112
|
+
get mode(): 'memory' | 'storage';
|
|
113
|
+
/**
|
|
114
|
+
* Set mode to memory (new backend with cookies + memory)
|
|
115
|
+
*/
|
|
116
|
+
setMemoryMode(): void;
|
|
215
117
|
/**
|
|
216
|
-
* Set
|
|
217
|
-
*
|
|
118
|
+
* Set mode to storage (legacy backend with localStorage)
|
|
119
|
+
* Also loads existing session from localStorage
|
|
218
120
|
*/
|
|
219
|
-
|
|
121
|
+
setStorageMode(): void;
|
|
220
122
|
/**
|
|
221
|
-
*
|
|
123
|
+
* Load session from localStorage
|
|
222
124
|
*/
|
|
223
|
-
|
|
125
|
+
private loadFromStorage;
|
|
224
126
|
/**
|
|
225
|
-
* Save session
|
|
127
|
+
* Save session (memory always, localStorage only in storage mode)
|
|
226
128
|
*/
|
|
227
129
|
saveSession(session: AuthSession): void;
|
|
228
130
|
/**
|
|
@@ -234,26 +136,25 @@ declare class TokenManager {
|
|
|
234
136
|
*/
|
|
235
137
|
getAccessToken(): string | null;
|
|
236
138
|
/**
|
|
237
|
-
*
|
|
139
|
+
* Set access token
|
|
238
140
|
*/
|
|
239
141
|
setAccessToken(token: string): void;
|
|
240
142
|
/**
|
|
241
|
-
* Get user
|
|
143
|
+
* Get user
|
|
242
144
|
*/
|
|
243
145
|
getUser(): UserSchema | null;
|
|
244
146
|
/**
|
|
245
|
-
*
|
|
147
|
+
* Set user
|
|
246
148
|
*/
|
|
247
149
|
setUser(user: UserSchema): void;
|
|
248
150
|
/**
|
|
249
|
-
* Clear
|
|
151
|
+
* Clear session (both memory and localStorage)
|
|
250
152
|
*/
|
|
251
153
|
clearSession(): void;
|
|
252
154
|
/**
|
|
253
|
-
* Check if
|
|
254
|
-
* (e.g., on page reload in secure mode)
|
|
155
|
+
* Check if there's a session in localStorage (for legacy detection)
|
|
255
156
|
*/
|
|
256
|
-
|
|
157
|
+
hasStoredSession(): boolean;
|
|
257
158
|
}
|
|
258
159
|
|
|
259
160
|
/**
|
|
@@ -282,38 +183,29 @@ declare class Auth {
|
|
|
282
183
|
private database;
|
|
283
184
|
constructor(http: HttpClient, tokenManager: TokenManager);
|
|
284
185
|
/**
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
* @internal
|
|
303
|
-
*/
|
|
304
|
-
_switchToLocalStorage(): void;
|
|
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
|
+
}>;
|
|
305
203
|
/**
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
204
|
+
* Automatically detect and handle OAuth callback parameters in the URL
|
|
205
|
+
* This runs on initialization to seamlessly complete the OAuth flow
|
|
206
|
+
* Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)
|
|
309
207
|
*/
|
|
310
|
-
private
|
|
311
|
-
/**
|
|
312
|
-
* Automatically detect and handle OAuth callback parameters in the URL
|
|
313
|
-
* This runs on initialization to seamlessly complete the OAuth flow
|
|
314
|
-
* Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)
|
|
315
|
-
*/
|
|
316
|
-
detectAuthCallback(): void;
|
|
208
|
+
private detectAuthCallback;
|
|
317
209
|
/**
|
|
318
210
|
* Sign up a new user
|
|
319
211
|
*/
|
|
@@ -344,18 +236,10 @@ declare class Auth {
|
|
|
344
236
|
}>;
|
|
345
237
|
/**
|
|
346
238
|
* Sign out the current user
|
|
347
|
-
* In modern mode, also calls backend to clear the refresh token cookie
|
|
348
239
|
*/
|
|
349
240
|
signOut(): Promise<{
|
|
350
241
|
error: InsForgeError | null;
|
|
351
242
|
}>;
|
|
352
|
-
/**
|
|
353
|
-
* Refresh the access token using the httpOnly refresh token cookie
|
|
354
|
-
* Only works when backend supports secure session storage (httpOnly cookies)
|
|
355
|
-
*
|
|
356
|
-
* @returns New access token or throws an error
|
|
357
|
-
*/
|
|
358
|
-
refreshToken(): Promise<string>;
|
|
359
243
|
/**
|
|
360
244
|
* Get all public authentication configuration (OAuth + Email)
|
|
361
245
|
* Returns both OAuth providers and email authentication settings in one request
|
|
@@ -379,9 +263,6 @@ declare class Auth {
|
|
|
379
263
|
/**
|
|
380
264
|
* Get the current user with full profile information
|
|
381
265
|
* Returns both auth info (id, email, role) and profile data (dynamic fields from users table)
|
|
382
|
-
*
|
|
383
|
-
* In secure session mode (httpOnly cookie), this method will automatically attempt
|
|
384
|
-
* to refresh the session if no access token is available (e.g., after page reload).
|
|
385
266
|
*/
|
|
386
267
|
getCurrentUser(): Promise<{
|
|
387
268
|
data: {
|
|
@@ -832,10 +713,6 @@ declare class InsForgeClient {
|
|
|
832
713
|
* ```
|
|
833
714
|
*/
|
|
834
715
|
getHttpClient(): HttpClient;
|
|
835
|
-
/**
|
|
836
|
-
* Get the current storage strategy identifier
|
|
837
|
-
*/
|
|
838
|
-
getStorageStrategy(): string;
|
|
839
716
|
}
|
|
840
717
|
|
|
841
718
|
/**
|
|
@@ -846,4 +723,4 @@ declare class InsForgeClient {
|
|
|
846
723
|
|
|
847
724
|
declare function createClient(config: InsForgeConfig): InsForgeClient;
|
|
848
725
|
|
|
849
|
-
export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, Database, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError,
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -74,33 +74,15 @@ declare class InsForgeError extends Error {
|
|
|
74
74
|
interface RequestOptions extends RequestInit {
|
|
75
75
|
params?: Record<string, string>;
|
|
76
76
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Callback type for token refresh
|
|
79
|
-
* Returns new access token or null if refresh failed
|
|
80
|
-
*/
|
|
81
|
-
type RefreshCallback = () => Promise<string | null>;
|
|
82
77
|
declare class HttpClient {
|
|
83
78
|
readonly baseUrl: string;
|
|
84
79
|
readonly fetch: typeof fetch;
|
|
85
80
|
private defaultHeaders;
|
|
86
81
|
private anonKey;
|
|
87
82
|
private userToken;
|
|
88
|
-
private refreshCallback?;
|
|
89
|
-
private isRefreshing;
|
|
90
|
-
private refreshQueue;
|
|
91
83
|
constructor(config: InsForgeConfig);
|
|
92
|
-
/**
|
|
93
|
-
* Set the refresh callback for automatic token refresh on 401
|
|
94
|
-
*/
|
|
95
|
-
setRefreshCallback(callback: RefreshCallback): void;
|
|
96
84
|
private buildUrl;
|
|
97
85
|
request<T>(method: string, path: string, options?: RequestOptions): Promise<T>;
|
|
98
|
-
private performRequest;
|
|
99
|
-
/**
|
|
100
|
-
* Handle token refresh with queue to prevent duplicate refreshes
|
|
101
|
-
* Multiple concurrent 401s will wait for a single refresh to complete
|
|
102
|
-
*/
|
|
103
|
-
private handleTokenRefresh;
|
|
104
86
|
get<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
105
87
|
post<T>(path: string, body?: any, options?: RequestOptions): Promise<T>;
|
|
106
88
|
put<T>(path: string, body?: any, options?: RequestOptions): Promise<T>;
|
|
@@ -111,118 +93,38 @@ declare class HttpClient {
|
|
|
111
93
|
}
|
|
112
94
|
|
|
113
95
|
/**
|
|
114
|
-
*
|
|
96
|
+
* Token Manager for InsForge SDK
|
|
115
97
|
*
|
|
116
|
-
*
|
|
117
|
-
* -
|
|
118
|
-
* -
|
|
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
|
|
119
101
|
*/
|
|
120
102
|
|
|
121
|
-
|
|
122
|
-
* Strategy interface for session storage
|
|
123
|
-
* All storage implementations must conform to this interface
|
|
124
|
-
*/
|
|
125
|
-
interface SessionStorageStrategy {
|
|
126
|
-
/** Save complete session (token + user) */
|
|
127
|
-
saveSession(session: AuthSession): void;
|
|
128
|
-
/** Get current session */
|
|
129
|
-
getSession(): AuthSession | null;
|
|
130
|
-
/** Get access token only */
|
|
131
|
-
getAccessToken(): string | null;
|
|
132
|
-
/** Update access token (e.g., after refresh) */
|
|
133
|
-
setAccessToken(token: string): void;
|
|
134
|
-
/** Get user data */
|
|
135
|
-
getUser(): UserSchema | null;
|
|
136
|
-
/** Update user data */
|
|
137
|
-
setUser(user: UserSchema): void;
|
|
138
|
-
/** Clear all session data */
|
|
139
|
-
clearSession(): void;
|
|
140
|
-
/** Check if token refresh should be attempted (e.g., on page reload) */
|
|
141
|
-
shouldAttemptRefresh(): boolean;
|
|
142
|
-
/** Get strategy identifier for debugging */
|
|
143
|
-
readonly strategyId: string;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Secure Session Storage Strategy
|
|
147
|
-
*
|
|
148
|
-
* Stores access token in memory only (cleared on page refresh).
|
|
149
|
-
* Refresh token is stored in httpOnly cookie by the backend (on backend domain).
|
|
150
|
-
* The `isAuthenticated` cookie is set by the SDK on the frontend domain to signal
|
|
151
|
-
* that a secure session exists and token refresh should be attempted on page reload.
|
|
152
|
-
*
|
|
153
|
-
* Security benefits:
|
|
154
|
-
* - Access token not accessible to XSS attacks (in memory only)
|
|
155
|
-
* - Refresh token completely inaccessible to JavaScript (httpOnly)
|
|
156
|
-
*/
|
|
157
|
-
declare class SecureSessionStorage implements SessionStorageStrategy {
|
|
158
|
-
readonly strategyId = "secure";
|
|
103
|
+
declare class TokenManager {
|
|
159
104
|
private accessToken;
|
|
160
105
|
private user;
|
|
161
|
-
saveSession(session: AuthSession): void;
|
|
162
|
-
getSession(): AuthSession | null;
|
|
163
|
-
getAccessToken(): string | null;
|
|
164
|
-
setAccessToken(token: string): void;
|
|
165
|
-
getUser(): UserSchema | null;
|
|
166
|
-
setUser(user: UserSchema): void;
|
|
167
|
-
clearSession(): void;
|
|
168
|
-
shouldAttemptRefresh(): boolean;
|
|
169
|
-
private hasAuthFlag;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Local Session Storage Strategy
|
|
173
|
-
*
|
|
174
|
-
* Stores tokens in localStorage for persistence across page reloads.
|
|
175
|
-
* Used for legacy backends or environments where httpOnly cookies aren't available.
|
|
176
|
-
*
|
|
177
|
-
* Note: This approach exposes tokens to XSS attacks. Use SecureSessionStorage
|
|
178
|
-
* when possible.
|
|
179
|
-
*/
|
|
180
|
-
declare class LocalSessionStorage implements SessionStorageStrategy {
|
|
181
|
-
readonly strategyId = "local";
|
|
182
106
|
private storage;
|
|
107
|
+
private _mode;
|
|
183
108
|
constructor(storage?: TokenStorage);
|
|
184
|
-
saveSession(session: AuthSession): void;
|
|
185
|
-
getSession(): AuthSession | null;
|
|
186
|
-
getAccessToken(): string | null;
|
|
187
|
-
setAccessToken(token: string): void;
|
|
188
|
-
getUser(): UserSchema | null;
|
|
189
|
-
setUser(user: UserSchema): void;
|
|
190
|
-
clearSession(): void;
|
|
191
|
-
shouldAttemptRefresh(): boolean;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Token Manager for InsForge SDK
|
|
196
|
-
*
|
|
197
|
-
* A thin wrapper that delegates to the underlying SessionStorageStrategy.
|
|
198
|
-
* This class maintains backward compatibility while using the Strategy Pattern internally.
|
|
199
|
-
*/
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* TokenManager - Manages session storage using the Strategy Pattern
|
|
203
|
-
*
|
|
204
|
-
* The actual storage implementation is delegated to a SessionStorageStrategy.
|
|
205
|
-
* By default, uses LocalSessionStorage until a strategy is explicitly set
|
|
206
|
-
* via setStrategy() during client initialization.
|
|
207
|
-
*/
|
|
208
|
-
declare class TokenManager {
|
|
209
|
-
private strategy;
|
|
210
109
|
/**
|
|
211
|
-
*
|
|
212
|
-
* @param storage - Optional custom storage adapter (used for initial LocalSessionStorage)
|
|
110
|
+
* Get current mode
|
|
213
111
|
*/
|
|
214
|
-
|
|
112
|
+
get mode(): 'memory' | 'storage';
|
|
113
|
+
/**
|
|
114
|
+
* Set mode to memory (new backend with cookies + memory)
|
|
115
|
+
*/
|
|
116
|
+
setMemoryMode(): void;
|
|
215
117
|
/**
|
|
216
|
-
* Set
|
|
217
|
-
*
|
|
118
|
+
* Set mode to storage (legacy backend with localStorage)
|
|
119
|
+
* Also loads existing session from localStorage
|
|
218
120
|
*/
|
|
219
|
-
|
|
121
|
+
setStorageMode(): void;
|
|
220
122
|
/**
|
|
221
|
-
*
|
|
123
|
+
* Load session from localStorage
|
|
222
124
|
*/
|
|
223
|
-
|
|
125
|
+
private loadFromStorage;
|
|
224
126
|
/**
|
|
225
|
-
* Save session
|
|
127
|
+
* Save session (memory always, localStorage only in storage mode)
|
|
226
128
|
*/
|
|
227
129
|
saveSession(session: AuthSession): void;
|
|
228
130
|
/**
|
|
@@ -234,26 +136,25 @@ declare class TokenManager {
|
|
|
234
136
|
*/
|
|
235
137
|
getAccessToken(): string | null;
|
|
236
138
|
/**
|
|
237
|
-
*
|
|
139
|
+
* Set access token
|
|
238
140
|
*/
|
|
239
141
|
setAccessToken(token: string): void;
|
|
240
142
|
/**
|
|
241
|
-
* Get user
|
|
143
|
+
* Get user
|
|
242
144
|
*/
|
|
243
145
|
getUser(): UserSchema | null;
|
|
244
146
|
/**
|
|
245
|
-
*
|
|
147
|
+
* Set user
|
|
246
148
|
*/
|
|
247
149
|
setUser(user: UserSchema): void;
|
|
248
150
|
/**
|
|
249
|
-
* Clear
|
|
151
|
+
* Clear session (both memory and localStorage)
|
|
250
152
|
*/
|
|
251
153
|
clearSession(): void;
|
|
252
154
|
/**
|
|
253
|
-
* Check if
|
|
254
|
-
* (e.g., on page reload in secure mode)
|
|
155
|
+
* Check if there's a session in localStorage (for legacy detection)
|
|
255
156
|
*/
|
|
256
|
-
|
|
157
|
+
hasStoredSession(): boolean;
|
|
257
158
|
}
|
|
258
159
|
|
|
259
160
|
/**
|
|
@@ -282,38 +183,29 @@ declare class Auth {
|
|
|
282
183
|
private database;
|
|
283
184
|
constructor(http: HttpClient, tokenManager: TokenManager);
|
|
284
185
|
/**
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
* @internal
|
|
303
|
-
*/
|
|
304
|
-
_switchToLocalStorage(): void;
|
|
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
|
+
}>;
|
|
305
203
|
/**
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
204
|
+
* Automatically detect and handle OAuth callback parameters in the URL
|
|
205
|
+
* This runs on initialization to seamlessly complete the OAuth flow
|
|
206
|
+
* Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)
|
|
309
207
|
*/
|
|
310
|
-
private
|
|
311
|
-
/**
|
|
312
|
-
* Automatically detect and handle OAuth callback parameters in the URL
|
|
313
|
-
* This runs on initialization to seamlessly complete the OAuth flow
|
|
314
|
-
* Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)
|
|
315
|
-
*/
|
|
316
|
-
detectAuthCallback(): void;
|
|
208
|
+
private detectAuthCallback;
|
|
317
209
|
/**
|
|
318
210
|
* Sign up a new user
|
|
319
211
|
*/
|
|
@@ -344,18 +236,10 @@ declare class Auth {
|
|
|
344
236
|
}>;
|
|
345
237
|
/**
|
|
346
238
|
* Sign out the current user
|
|
347
|
-
* In modern mode, also calls backend to clear the refresh token cookie
|
|
348
239
|
*/
|
|
349
240
|
signOut(): Promise<{
|
|
350
241
|
error: InsForgeError | null;
|
|
351
242
|
}>;
|
|
352
|
-
/**
|
|
353
|
-
* Refresh the access token using the httpOnly refresh token cookie
|
|
354
|
-
* Only works when backend supports secure session storage (httpOnly cookies)
|
|
355
|
-
*
|
|
356
|
-
* @returns New access token or throws an error
|
|
357
|
-
*/
|
|
358
|
-
refreshToken(): Promise<string>;
|
|
359
243
|
/**
|
|
360
244
|
* Get all public authentication configuration (OAuth + Email)
|
|
361
245
|
* Returns both OAuth providers and email authentication settings in one request
|
|
@@ -379,9 +263,6 @@ declare class Auth {
|
|
|
379
263
|
/**
|
|
380
264
|
* Get the current user with full profile information
|
|
381
265
|
* Returns both auth info (id, email, role) and profile data (dynamic fields from users table)
|
|
382
|
-
*
|
|
383
|
-
* In secure session mode (httpOnly cookie), this method will automatically attempt
|
|
384
|
-
* to refresh the session if no access token is available (e.g., after page reload).
|
|
385
266
|
*/
|
|
386
267
|
getCurrentUser(): Promise<{
|
|
387
268
|
data: {
|
|
@@ -832,10 +713,6 @@ declare class InsForgeClient {
|
|
|
832
713
|
* ```
|
|
833
714
|
*/
|
|
834
715
|
getHttpClient(): HttpClient;
|
|
835
|
-
/**
|
|
836
|
-
* Get the current storage strategy identifier
|
|
837
|
-
*/
|
|
838
|
-
getStorageStrategy(): string;
|
|
839
716
|
}
|
|
840
717
|
|
|
841
718
|
/**
|
|
@@ -846,4 +723,4 @@ declare class InsForgeClient {
|
|
|
846
723
|
|
|
847
724
|
declare function createClient(config: InsForgeConfig): InsForgeClient;
|
|
848
725
|
|
|
849
|
-
export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, Database, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError,
|
|
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 };
|