@insforge/sdk 1.1.6 → 1.2.0-dev.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/README.md CHANGED
@@ -170,8 +170,29 @@ The SDK supports the following configuration options:
170
170
 
171
171
  ```javascript
172
172
  const insforge = createClient({
173
- baseUrl: 'http://localhost:7130', // Required: Your InsForge backend URL
174
- storageStrategy: 'localStorage' // Optional: 'localStorage' or 'memory' (default: 'localStorage')
173
+ baseUrl: 'http://localhost:7130', // Your InsForge backend URL
174
+ anonKey: 'your-anon-key', // Optional
175
+ isServerMode: false // Optional (set true in SSR/server runtime)
176
+ });
177
+ ```
178
+
179
+ ### SSR / Next.js
180
+
181
+ For SSR apps, configure `isServerMode: true`.
182
+ In this mode, auth requests use `client_type=mobile` so auth methods return `refreshToken` in the response body.
183
+ The SDK does not auto-refresh in server mode; your Next.js app should manage refresh token flow.
184
+ In server mode, the SDK does not persist session/user state.
185
+ Read your access token from cookies in Next.js and pass it as `edgeFunctionToken` per request.
186
+ Your app should write/update cookies itself after login/refresh.
187
+
188
+ ```typescript
189
+ import { createClient } from '@insforge/sdk';
190
+ const accessToken = /* read access token from request cookies */ null;
191
+
192
+ const insforge = createClient({
193
+ baseUrl: process.env.INSFORGE_URL!,
194
+ isServerMode: true,
195
+ edgeFunctionToken: accessToken ?? undefined,
175
196
  });
176
197
  ```
177
198
 
@@ -211,7 +232,7 @@ if (error) {
211
232
  The SDK works in all modern browsers that support:
212
233
  - ES6+ features
213
234
  - Fetch API
214
- - LocalStorage (for session management)
235
+ - Cookies (for refresh token flow)
215
236
 
216
237
  For Node.js environments, ensure you're using Node.js 18 or higher.
217
238
 
package/dist/index.d.mts CHANGED
@@ -36,29 +36,16 @@ interface InsForgeConfig {
36
36
  */
37
37
  fetch?: typeof fetch;
38
38
  /**
39
- * Storage adapter for persisting tokens
39
+ * Enable server-side auth mode (SSR/Node runtime)
40
+ * In this mode auth endpoints use `client_type=mobile` and refresh_token body flow.
41
+ * @default false
40
42
  */
41
- storage?: TokenStorage;
42
- /**
43
- * Whether to automatically refresh tokens before they expire
44
- * @default true
45
- */
46
- autoRefreshToken?: boolean;
47
- /**
48
- * Whether to persist session in storage
49
- * @default true
50
- */
51
- persistSession?: boolean;
43
+ isServerMode?: boolean;
52
44
  /**
53
45
  * Custom headers to include with every request
54
46
  */
55
47
  headers?: Record<string, string>;
56
48
  }
57
- interface TokenStorage {
58
- getItem(key: string): string | null | Promise<string | null>;
59
- setItem(key: string, value: string): void | Promise<void>;
60
- removeItem(key: string): void | Promise<void>;
61
- }
62
49
  interface AuthSession {
63
50
  user: UserSchema;
64
51
  accessToken: string;
@@ -102,37 +89,16 @@ declare class HttpClient {
102
89
  /**
103
90
  * Token Manager for InsForge SDK
104
91
  *
105
- * Simple token storage that supports two modes:
106
- * - Memory mode (new backend): tokens stored in memory only, more secure
107
- * - Storage mode (legacy backend): tokens persisted in localStorage
92
+ * Memory-only token storage.
108
93
  */
109
94
 
110
95
  declare class TokenManager {
111
96
  private accessToken;
112
97
  private user;
113
- private storage;
114
- private _mode;
115
98
  onTokenChange: (() => void) | null;
116
- constructor(storage?: TokenStorage);
117
- /**
118
- * Get current mode
119
- */
120
- get mode(): 'memory' | 'storage';
121
- /**
122
- * Set mode to memory (new backend with cookies + memory)
123
- */
124
- setMemoryMode(): void;
125
- /**
126
- * Set mode to storage (legacy backend with localStorage)
127
- * Also loads existing session from localStorage
128
- */
129
- setStorageMode(): void;
99
+ constructor();
130
100
  /**
131
- * Load session from localStorage
132
- */
133
- private loadFromStorage;
134
- /**
135
- * Save session (memory always, localStorage only in storage mode)
101
+ * Save session in memory
136
102
  */
137
103
  saveSession(session: AuthSession): void;
138
104
  /**
@@ -156,13 +122,9 @@ declare class TokenManager {
156
122
  */
157
123
  setUser(user: UserSchema): void;
158
124
  /**
159
- * Clear session (both memory and localStorage)
125
+ * Clear in-memory session
160
126
  */
161
127
  clearSession(): void;
162
- /**
163
- * Check if there's a session in localStorage (for legacy detection)
164
- */
165
- hasStoredSession(): boolean;
166
128
  }
167
129
 
168
130
  /**
@@ -170,14 +132,19 @@ declare class TokenManager {
170
132
  * Handles authentication, sessions, profiles, and email verification
171
133
  */
172
134
 
135
+ interface AuthOptions {
136
+ isServerMode?: boolean;
137
+ }
173
138
  declare class Auth {
174
139
  private http;
175
140
  private tokenManager;
141
+ private options;
176
142
  private authCallbackHandled;
177
- constructor(http: HttpClient, tokenManager: TokenManager);
143
+ constructor(http: HttpClient, tokenManager: TokenManager, options?: AuthOptions);
144
+ private isServerMode;
178
145
  /**
179
146
  * Save session from API response
180
- * Handles token storage, CSRF token, and HTTP client auth header
147
+ * Handles token storage, CSRF token, and HTTP auth header
181
148
  */
182
149
  private saveSessionFromResponse;
183
150
  /**
@@ -218,6 +185,7 @@ declare class Auth {
218
185
  exchangeOAuthCode(code: string, codeVerifier?: string): Promise<{
219
186
  data: {
220
187
  accessToken: string;
188
+ refreshToken?: string;
221
189
  user: UserSchema;
222
190
  redirectTo?: string;
223
191
  } | null;
@@ -242,18 +210,8 @@ declare class Auth {
242
210
  error: InsForgeError | null;
243
211
  }>;
244
212
  /**
245
- * Get current session, automatically waits for pending OAuth callback
246
- * @deprecated Use `getCurrentUser` instead
213
+ * Get current user, automatically waits for pending OAuth callback
247
214
  */
248
- getCurrentSession(): Promise<{
249
- data: {
250
- session: AuthSession | null;
251
- };
252
- error: InsForgeError | null;
253
- }>;
254
- /**
255
- * Get current user, automatically waits for pending OAuth callback
256
- */
257
215
  getCurrentUser(): Promise<{
258
216
  data: {
259
217
  user: UserSchema | null;
@@ -930,4 +888,4 @@ declare class InsForgeClient {
930
888
 
931
889
  declare function createClient(config: InsForgeConfig): InsForgeClient;
932
890
 
933
- export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, type ConnectionState, Database, Emails, type EventCallback, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError, Realtime, Storage, StorageBucket, type StorageResponse, TokenManager, type TokenStorage, createClient, InsForgeClient as default };
891
+ export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, type ConnectionState, Database, Emails, type EventCallback, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError, Realtime, Storage, StorageBucket, type StorageResponse, TokenManager, createClient, InsForgeClient as default };
package/dist/index.d.ts CHANGED
@@ -36,29 +36,16 @@ interface InsForgeConfig {
36
36
  */
37
37
  fetch?: typeof fetch;
38
38
  /**
39
- * Storage adapter for persisting tokens
39
+ * Enable server-side auth mode (SSR/Node runtime)
40
+ * In this mode auth endpoints use `client_type=mobile` and refresh_token body flow.
41
+ * @default false
40
42
  */
41
- storage?: TokenStorage;
42
- /**
43
- * Whether to automatically refresh tokens before they expire
44
- * @default true
45
- */
46
- autoRefreshToken?: boolean;
47
- /**
48
- * Whether to persist session in storage
49
- * @default true
50
- */
51
- persistSession?: boolean;
43
+ isServerMode?: boolean;
52
44
  /**
53
45
  * Custom headers to include with every request
54
46
  */
55
47
  headers?: Record<string, string>;
56
48
  }
57
- interface TokenStorage {
58
- getItem(key: string): string | null | Promise<string | null>;
59
- setItem(key: string, value: string): void | Promise<void>;
60
- removeItem(key: string): void | Promise<void>;
61
- }
62
49
  interface AuthSession {
63
50
  user: UserSchema;
64
51
  accessToken: string;
@@ -102,37 +89,16 @@ declare class HttpClient {
102
89
  /**
103
90
  * Token Manager for InsForge SDK
104
91
  *
105
- * Simple token storage that supports two modes:
106
- * - Memory mode (new backend): tokens stored in memory only, more secure
107
- * - Storage mode (legacy backend): tokens persisted in localStorage
92
+ * Memory-only token storage.
108
93
  */
109
94
 
110
95
  declare class TokenManager {
111
96
  private accessToken;
112
97
  private user;
113
- private storage;
114
- private _mode;
115
98
  onTokenChange: (() => void) | null;
116
- constructor(storage?: TokenStorage);
117
- /**
118
- * Get current mode
119
- */
120
- get mode(): 'memory' | 'storage';
121
- /**
122
- * Set mode to memory (new backend with cookies + memory)
123
- */
124
- setMemoryMode(): void;
125
- /**
126
- * Set mode to storage (legacy backend with localStorage)
127
- * Also loads existing session from localStorage
128
- */
129
- setStorageMode(): void;
99
+ constructor();
130
100
  /**
131
- * Load session from localStorage
132
- */
133
- private loadFromStorage;
134
- /**
135
- * Save session (memory always, localStorage only in storage mode)
101
+ * Save session in memory
136
102
  */
137
103
  saveSession(session: AuthSession): void;
138
104
  /**
@@ -156,13 +122,9 @@ declare class TokenManager {
156
122
  */
157
123
  setUser(user: UserSchema): void;
158
124
  /**
159
- * Clear session (both memory and localStorage)
125
+ * Clear in-memory session
160
126
  */
161
127
  clearSession(): void;
162
- /**
163
- * Check if there's a session in localStorage (for legacy detection)
164
- */
165
- hasStoredSession(): boolean;
166
128
  }
167
129
 
168
130
  /**
@@ -170,14 +132,19 @@ declare class TokenManager {
170
132
  * Handles authentication, sessions, profiles, and email verification
171
133
  */
172
134
 
135
+ interface AuthOptions {
136
+ isServerMode?: boolean;
137
+ }
173
138
  declare class Auth {
174
139
  private http;
175
140
  private tokenManager;
141
+ private options;
176
142
  private authCallbackHandled;
177
- constructor(http: HttpClient, tokenManager: TokenManager);
143
+ constructor(http: HttpClient, tokenManager: TokenManager, options?: AuthOptions);
144
+ private isServerMode;
178
145
  /**
179
146
  * Save session from API response
180
- * Handles token storage, CSRF token, and HTTP client auth header
147
+ * Handles token storage, CSRF token, and HTTP auth header
181
148
  */
182
149
  private saveSessionFromResponse;
183
150
  /**
@@ -218,6 +185,7 @@ declare class Auth {
218
185
  exchangeOAuthCode(code: string, codeVerifier?: string): Promise<{
219
186
  data: {
220
187
  accessToken: string;
188
+ refreshToken?: string;
221
189
  user: UserSchema;
222
190
  redirectTo?: string;
223
191
  } | null;
@@ -242,18 +210,8 @@ declare class Auth {
242
210
  error: InsForgeError | null;
243
211
  }>;
244
212
  /**
245
- * Get current session, automatically waits for pending OAuth callback
246
- * @deprecated Use `getCurrentUser` instead
213
+ * Get current user, automatically waits for pending OAuth callback
247
214
  */
248
- getCurrentSession(): Promise<{
249
- data: {
250
- session: AuthSession | null;
251
- };
252
- error: InsForgeError | null;
253
- }>;
254
- /**
255
- * Get current user, automatically waits for pending OAuth callback
256
- */
257
215
  getCurrentUser(): Promise<{
258
216
  data: {
259
217
  user: UserSchema | null;
@@ -930,4 +888,4 @@ declare class InsForgeClient {
930
888
 
931
889
  declare function createClient(config: InsForgeConfig): InsForgeClient;
932
890
 
933
- export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, type ConnectionState, Database, Emails, type EventCallback, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError, Realtime, Storage, StorageBucket, type StorageResponse, TokenManager, type TokenStorage, createClient, InsForgeClient as default };
891
+ export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, type ConnectionState, Database, Emails, type EventCallback, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError, Realtime, Storage, StorageBucket, type StorageResponse, TokenManager, createClient, InsForgeClient as default };