@insforge/sdk 1.1.6 → 1.2.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -3
- package/dist/index.d.mts +31 -58
- package/dist/index.d.ts +31 -58
- package/dist/index.js +93 -210
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +93 -210
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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',
|
|
174
|
-
|
|
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
|
-
-
|
|
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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetProfileResponse, SendVerificationEmailRequest, VerifyEmailRequest, VerifyEmailResponse, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, GetPublicAuthConfigResponse, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, EmbeddingsRequest, SubscribeResponse, SocketMessage, SendRawEmailRequest, SendEmailResponse } from '@insforge/shared-schemas';
|
|
1
|
+
import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, RefreshSessionResponse, GetProfileResponse, SendVerificationEmailRequest, VerifyEmailRequest, VerifyEmailResponse, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, GetPublicAuthConfigResponse, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, EmbeddingsRequest, SubscribeResponse, SocketMessage, SendRawEmailRequest, SendEmailResponse } from '@insforge/shared-schemas';
|
|
2
2
|
export { AuthErrorResponse, CreateSessionRequest, CreateUserRequest, RealtimeErrorPayload, SendRawEmailRequest as SendEmailOptions, SendEmailResponse, SocketMessage, SubscribeResponse, UserSchema } from '@insforge/shared-schemas';
|
|
3
3
|
import * as _supabase_postgrest_js from '@supabase/postgrest-js';
|
|
4
4
|
|
|
@@ -36,29 +36,16 @@ interface InsForgeConfig {
|
|
|
36
36
|
*/
|
|
37
37
|
fetch?: typeof fetch;
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
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(
|
|
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;
|
|
99
|
+
constructor();
|
|
125
100
|
/**
|
|
126
|
-
*
|
|
127
|
-
* Also loads existing session from localStorage
|
|
128
|
-
*/
|
|
129
|
-
setStorageMode(): void;
|
|
130
|
-
/**
|
|
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
|
|
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
|
|
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,23 @@ declare class Auth {
|
|
|
242
210
|
error: InsForgeError | null;
|
|
243
211
|
}>;
|
|
244
212
|
/**
|
|
245
|
-
*
|
|
246
|
-
*
|
|
213
|
+
* Refresh the current auth session.
|
|
214
|
+
*
|
|
215
|
+
* Browser mode:
|
|
216
|
+
* - Uses httpOnly refresh cookie and optional CSRF header.
|
|
217
|
+
*
|
|
218
|
+
* Server mode (`isServerMode: true`):
|
|
219
|
+
* - Uses mobile auth flow and requires `refreshToken` in request body.
|
|
247
220
|
*/
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
221
|
+
refreshSession(options?: {
|
|
222
|
+
refreshToken?: string;
|
|
223
|
+
}): Promise<{
|
|
224
|
+
data: RefreshSessionResponse | null;
|
|
252
225
|
error: InsForgeError | null;
|
|
253
226
|
}>;
|
|
254
227
|
/**
|
|
255
|
-
|
|
256
|
-
|
|
228
|
+
* Get current user, automatically waits for pending OAuth callback
|
|
229
|
+
*/
|
|
257
230
|
getCurrentUser(): Promise<{
|
|
258
231
|
data: {
|
|
259
232
|
user: UserSchema | null;
|
|
@@ -930,4 +903,4 @@ declare class InsForgeClient {
|
|
|
930
903
|
|
|
931
904
|
declare function createClient(config: InsForgeConfig): InsForgeClient;
|
|
932
905
|
|
|
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,
|
|
906
|
+
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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetProfileResponse, SendVerificationEmailRequest, VerifyEmailRequest, VerifyEmailResponse, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, GetPublicAuthConfigResponse, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, EmbeddingsRequest, SubscribeResponse, SocketMessage, SendRawEmailRequest, SendEmailResponse } from '@insforge/shared-schemas';
|
|
1
|
+
import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, RefreshSessionResponse, GetProfileResponse, SendVerificationEmailRequest, VerifyEmailRequest, VerifyEmailResponse, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, GetPublicAuthConfigResponse, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, EmbeddingsRequest, SubscribeResponse, SocketMessage, SendRawEmailRequest, SendEmailResponse } from '@insforge/shared-schemas';
|
|
2
2
|
export { AuthErrorResponse, CreateSessionRequest, CreateUserRequest, RealtimeErrorPayload, SendRawEmailRequest as SendEmailOptions, SendEmailResponse, SocketMessage, SubscribeResponse, UserSchema } from '@insforge/shared-schemas';
|
|
3
3
|
import * as _supabase_postgrest_js from '@supabase/postgrest-js';
|
|
4
4
|
|
|
@@ -36,29 +36,16 @@ interface InsForgeConfig {
|
|
|
36
36
|
*/
|
|
37
37
|
fetch?: typeof fetch;
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
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(
|
|
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;
|
|
99
|
+
constructor();
|
|
125
100
|
/**
|
|
126
|
-
*
|
|
127
|
-
* Also loads existing session from localStorage
|
|
128
|
-
*/
|
|
129
|
-
setStorageMode(): void;
|
|
130
|
-
/**
|
|
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
|
|
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
|
|
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,23 @@ declare class Auth {
|
|
|
242
210
|
error: InsForgeError | null;
|
|
243
211
|
}>;
|
|
244
212
|
/**
|
|
245
|
-
*
|
|
246
|
-
*
|
|
213
|
+
* Refresh the current auth session.
|
|
214
|
+
*
|
|
215
|
+
* Browser mode:
|
|
216
|
+
* - Uses httpOnly refresh cookie and optional CSRF header.
|
|
217
|
+
*
|
|
218
|
+
* Server mode (`isServerMode: true`):
|
|
219
|
+
* - Uses mobile auth flow and requires `refreshToken` in request body.
|
|
247
220
|
*/
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
221
|
+
refreshSession(options?: {
|
|
222
|
+
refreshToken?: string;
|
|
223
|
+
}): Promise<{
|
|
224
|
+
data: RefreshSessionResponse | null;
|
|
252
225
|
error: InsForgeError | null;
|
|
253
226
|
}>;
|
|
254
227
|
/**
|
|
255
|
-
|
|
256
|
-
|
|
228
|
+
* Get current user, automatically waits for pending OAuth callback
|
|
229
|
+
*/
|
|
257
230
|
getCurrentUser(): Promise<{
|
|
258
231
|
data: {
|
|
259
232
|
user: UserSchema | null;
|
|
@@ -930,4 +903,4 @@ declare class InsForgeClient {
|
|
|
930
903
|
|
|
931
904
|
declare function createClient(config: InsForgeConfig): InsForgeClient;
|
|
932
905
|
|
|
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,
|
|
906
|
+
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 };
|