@insforge/sdk 1.0.2-dev.0 → 1.0.3-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/LICENSE +201 -201
- package/README.md +259 -249
- package/dist/index.d.mts +71 -39
- package/dist/index.d.ts +71 -39
- package/dist/index.js +299 -172
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +299 -172
- package/dist/index.mjs.map +1 -1
- package/package.json +68 -68
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetPublicAuthConfigResponse,
|
|
1
|
+
import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetPublicAuthConfigResponse, GetProfileResponse, SendVerificationEmailRequest, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, VerifyEmailRequest, VerifyEmailResponse, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, 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
|
|
|
@@ -92,13 +92,69 @@ 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
|
+
|
|
95
103
|
declare class TokenManager {
|
|
104
|
+
private accessToken;
|
|
105
|
+
private user;
|
|
96
106
|
private storage;
|
|
107
|
+
private _mode;
|
|
97
108
|
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
|
+
*/
|
|
98
129
|
saveSession(session: AuthSession): void;
|
|
130
|
+
/**
|
|
131
|
+
* Get current session
|
|
132
|
+
*/
|
|
99
133
|
getSession(): AuthSession | null;
|
|
134
|
+
/**
|
|
135
|
+
* Get access token
|
|
136
|
+
*/
|
|
100
137
|
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
|
+
*/
|
|
101
153
|
clearSession(): void;
|
|
154
|
+
/**
|
|
155
|
+
* Check if there's a session in localStorage (for legacy detection)
|
|
156
|
+
*/
|
|
157
|
+
hasStoredSession(): boolean;
|
|
102
158
|
}
|
|
103
159
|
|
|
104
160
|
/**
|
|
@@ -106,29 +162,13 @@ declare class TokenManager {
|
|
|
106
162
|
* Uses shared schemas for type safety
|
|
107
163
|
*/
|
|
108
164
|
|
|
109
|
-
/**
|
|
110
|
-
* Dynamic profile type - represents flexible profile data from database
|
|
111
|
-
* Fields can vary based on database schema configuration.
|
|
112
|
-
* All fields are converted from snake_case (database) to camelCase (API)
|
|
113
|
-
*/
|
|
114
|
-
type ProfileData = Record<string, any> & {
|
|
115
|
-
id: string;
|
|
116
|
-
createdAt?: string;
|
|
117
|
-
updatedAt?: string;
|
|
118
|
-
};
|
|
119
|
-
/**
|
|
120
|
-
* Dynamic profile update type - for updating profile fields
|
|
121
|
-
* Supports any fields that exist in the profile table
|
|
122
|
-
*/
|
|
123
|
-
type UpdateProfileData = Partial<Record<string, any>>;
|
|
124
165
|
declare class Auth {
|
|
125
166
|
private http;
|
|
126
167
|
private tokenManager;
|
|
127
|
-
private database;
|
|
128
168
|
constructor(http: HttpClient, tokenManager: TokenManager);
|
|
129
169
|
/**
|
|
130
170
|
* Automatically detect and handle OAuth callback parameters in the URL
|
|
131
|
-
* This runs
|
|
171
|
+
* This runs after initialization to seamlessly complete the OAuth flow
|
|
132
172
|
* Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)
|
|
133
173
|
*/
|
|
134
174
|
private detectAuthCallback;
|
|
@@ -192,40 +232,36 @@ declare class Auth {
|
|
|
192
232
|
*/
|
|
193
233
|
getCurrentUser(): Promise<{
|
|
194
234
|
data: {
|
|
195
|
-
user:
|
|
196
|
-
id: UserIdSchema;
|
|
197
|
-
email: EmailSchema;
|
|
198
|
-
role: RoleSchema;
|
|
199
|
-
};
|
|
200
|
-
profile: ProfileData | null;
|
|
235
|
+
user: UserSchema;
|
|
201
236
|
} | null;
|
|
202
237
|
error: any | null;
|
|
203
238
|
}>;
|
|
204
239
|
/**
|
|
205
240
|
* Get any user's profile by ID
|
|
206
|
-
* Returns profile information from the users table
|
|
241
|
+
* Returns profile information from the users table
|
|
207
242
|
*/
|
|
208
243
|
getProfile(userId: string): Promise<{
|
|
209
|
-
data:
|
|
210
|
-
error:
|
|
244
|
+
data: GetProfileResponse | null;
|
|
245
|
+
error: InsForgeError | null;
|
|
211
246
|
}>;
|
|
212
247
|
/**
|
|
213
248
|
* Get the current session (only session data, no API call)
|
|
214
249
|
* Returns the stored JWT token and basic user info from local storage
|
|
215
250
|
*/
|
|
216
|
-
getCurrentSession(): {
|
|
251
|
+
getCurrentSession(): Promise<{
|
|
217
252
|
data: {
|
|
218
253
|
session: AuthSession | null;
|
|
219
254
|
};
|
|
220
255
|
error: InsForgeError | null;
|
|
221
|
-
}
|
|
256
|
+
}>;
|
|
222
257
|
/**
|
|
223
258
|
* Set/Update the current user's profile
|
|
224
259
|
* Updates profile information in the users table (supports any dynamic fields)
|
|
260
|
+
* Requires authentication
|
|
225
261
|
*/
|
|
226
|
-
setProfile(profile:
|
|
227
|
-
data:
|
|
228
|
-
error:
|
|
262
|
+
setProfile(profile: Record<string, unknown>): Promise<{
|
|
263
|
+
data: GetProfileResponse | null;
|
|
264
|
+
error: InsForgeError | null;
|
|
229
265
|
}>;
|
|
230
266
|
/**
|
|
231
267
|
* Send email verification (code or link based on config)
|
|
@@ -309,11 +345,7 @@ declare class Auth {
|
|
|
309
345
|
* Otherwise, a default success page is displayed.
|
|
310
346
|
*/
|
|
311
347
|
verifyEmail(request: VerifyEmailRequest): Promise<{
|
|
312
|
-
data:
|
|
313
|
-
accessToken: string;
|
|
314
|
-
user?: any;
|
|
315
|
-
redirectTo?: string;
|
|
316
|
-
} | null;
|
|
348
|
+
data: VerifyEmailResponse | null;
|
|
317
349
|
error: InsForgeError | null;
|
|
318
350
|
}>;
|
|
319
351
|
}
|
|
@@ -762,7 +794,7 @@ declare class Emails {
|
|
|
762
794
|
* });
|
|
763
795
|
*
|
|
764
796
|
* // Authentication
|
|
765
|
-
* const
|
|
797
|
+
* const { data, error } = await client.auth.signUp({
|
|
766
798
|
* email: 'user@example.com',
|
|
767
799
|
* password: 'password123',
|
|
768
800
|
* name: 'John Doe'
|
|
@@ -819,4 +851,4 @@ declare class InsForgeClient {
|
|
|
819
851
|
|
|
820
852
|
declare function createClient(config: InsForgeConfig): InsForgeClient;
|
|
821
853
|
|
|
822
|
-
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,
|
|
854
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetPublicAuthConfigResponse,
|
|
1
|
+
import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetPublicAuthConfigResponse, GetProfileResponse, SendVerificationEmailRequest, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, VerifyEmailRequest, VerifyEmailResponse, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, 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
|
|
|
@@ -92,13 +92,69 @@ 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
|
+
|
|
95
103
|
declare class TokenManager {
|
|
104
|
+
private accessToken;
|
|
105
|
+
private user;
|
|
96
106
|
private storage;
|
|
107
|
+
private _mode;
|
|
97
108
|
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
|
+
*/
|
|
98
129
|
saveSession(session: AuthSession): void;
|
|
130
|
+
/**
|
|
131
|
+
* Get current session
|
|
132
|
+
*/
|
|
99
133
|
getSession(): AuthSession | null;
|
|
134
|
+
/**
|
|
135
|
+
* Get access token
|
|
136
|
+
*/
|
|
100
137
|
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
|
+
*/
|
|
101
153
|
clearSession(): void;
|
|
154
|
+
/**
|
|
155
|
+
* Check if there's a session in localStorage (for legacy detection)
|
|
156
|
+
*/
|
|
157
|
+
hasStoredSession(): boolean;
|
|
102
158
|
}
|
|
103
159
|
|
|
104
160
|
/**
|
|
@@ -106,29 +162,13 @@ declare class TokenManager {
|
|
|
106
162
|
* Uses shared schemas for type safety
|
|
107
163
|
*/
|
|
108
164
|
|
|
109
|
-
/**
|
|
110
|
-
* Dynamic profile type - represents flexible profile data from database
|
|
111
|
-
* Fields can vary based on database schema configuration.
|
|
112
|
-
* All fields are converted from snake_case (database) to camelCase (API)
|
|
113
|
-
*/
|
|
114
|
-
type ProfileData = Record<string, any> & {
|
|
115
|
-
id: string;
|
|
116
|
-
createdAt?: string;
|
|
117
|
-
updatedAt?: string;
|
|
118
|
-
};
|
|
119
|
-
/**
|
|
120
|
-
* Dynamic profile update type - for updating profile fields
|
|
121
|
-
* Supports any fields that exist in the profile table
|
|
122
|
-
*/
|
|
123
|
-
type UpdateProfileData = Partial<Record<string, any>>;
|
|
124
165
|
declare class Auth {
|
|
125
166
|
private http;
|
|
126
167
|
private tokenManager;
|
|
127
|
-
private database;
|
|
128
168
|
constructor(http: HttpClient, tokenManager: TokenManager);
|
|
129
169
|
/**
|
|
130
170
|
* Automatically detect and handle OAuth callback parameters in the URL
|
|
131
|
-
* This runs
|
|
171
|
+
* This runs after initialization to seamlessly complete the OAuth flow
|
|
132
172
|
* Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)
|
|
133
173
|
*/
|
|
134
174
|
private detectAuthCallback;
|
|
@@ -192,40 +232,36 @@ declare class Auth {
|
|
|
192
232
|
*/
|
|
193
233
|
getCurrentUser(): Promise<{
|
|
194
234
|
data: {
|
|
195
|
-
user:
|
|
196
|
-
id: UserIdSchema;
|
|
197
|
-
email: EmailSchema;
|
|
198
|
-
role: RoleSchema;
|
|
199
|
-
};
|
|
200
|
-
profile: ProfileData | null;
|
|
235
|
+
user: UserSchema;
|
|
201
236
|
} | null;
|
|
202
237
|
error: any | null;
|
|
203
238
|
}>;
|
|
204
239
|
/**
|
|
205
240
|
* Get any user's profile by ID
|
|
206
|
-
* Returns profile information from the users table
|
|
241
|
+
* Returns profile information from the users table
|
|
207
242
|
*/
|
|
208
243
|
getProfile(userId: string): Promise<{
|
|
209
|
-
data:
|
|
210
|
-
error:
|
|
244
|
+
data: GetProfileResponse | null;
|
|
245
|
+
error: InsForgeError | null;
|
|
211
246
|
}>;
|
|
212
247
|
/**
|
|
213
248
|
* Get the current session (only session data, no API call)
|
|
214
249
|
* Returns the stored JWT token and basic user info from local storage
|
|
215
250
|
*/
|
|
216
|
-
getCurrentSession(): {
|
|
251
|
+
getCurrentSession(): Promise<{
|
|
217
252
|
data: {
|
|
218
253
|
session: AuthSession | null;
|
|
219
254
|
};
|
|
220
255
|
error: InsForgeError | null;
|
|
221
|
-
}
|
|
256
|
+
}>;
|
|
222
257
|
/**
|
|
223
258
|
* Set/Update the current user's profile
|
|
224
259
|
* Updates profile information in the users table (supports any dynamic fields)
|
|
260
|
+
* Requires authentication
|
|
225
261
|
*/
|
|
226
|
-
setProfile(profile:
|
|
227
|
-
data:
|
|
228
|
-
error:
|
|
262
|
+
setProfile(profile: Record<string, unknown>): Promise<{
|
|
263
|
+
data: GetProfileResponse | null;
|
|
264
|
+
error: InsForgeError | null;
|
|
229
265
|
}>;
|
|
230
266
|
/**
|
|
231
267
|
* Send email verification (code or link based on config)
|
|
@@ -309,11 +345,7 @@ declare class Auth {
|
|
|
309
345
|
* Otherwise, a default success page is displayed.
|
|
310
346
|
*/
|
|
311
347
|
verifyEmail(request: VerifyEmailRequest): Promise<{
|
|
312
|
-
data:
|
|
313
|
-
accessToken: string;
|
|
314
|
-
user?: any;
|
|
315
|
-
redirectTo?: string;
|
|
316
|
-
} | null;
|
|
348
|
+
data: VerifyEmailResponse | null;
|
|
317
349
|
error: InsForgeError | null;
|
|
318
350
|
}>;
|
|
319
351
|
}
|
|
@@ -762,7 +794,7 @@ declare class Emails {
|
|
|
762
794
|
* });
|
|
763
795
|
*
|
|
764
796
|
* // Authentication
|
|
765
|
-
* const
|
|
797
|
+
* const { data, error } = await client.auth.signUp({
|
|
766
798
|
* email: 'user@example.com',
|
|
767
799
|
* password: 'password123',
|
|
768
800
|
* name: 'John Doe'
|
|
@@ -819,4 +851,4 @@ declare class InsForgeClient {
|
|
|
819
851
|
|
|
820
852
|
declare function createClient(config: InsForgeConfig): InsForgeClient;
|
|
821
853
|
|
|
822
|
-
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,
|
|
854
|
+
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 };
|