@insforge/sdk 0.0.58-dev.1 → 0.0.58-dev.10
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 +85 -46
- package/dist/index.d.ts +85 -46
- package/dist/index.js +174 -68
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +174 -68
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema,
|
|
1
|
+
import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetPublicAuthConfigResponse, UserIdSchema, EmailSchema, RoleSchema, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest } from '@insforge/shared-schemas';
|
|
2
2
|
export { AuthErrorResponse, CreateSessionRequest, CreateUserRequest, UserSchema } from '@insforge/shared-schemas';
|
|
3
3
|
import * as _supabase_postgrest_js from '@supabase/postgrest-js';
|
|
4
4
|
|
|
@@ -106,6 +106,21 @@ declare class TokenManager {
|
|
|
106
106
|
* Uses shared schemas for type safety
|
|
107
107
|
*/
|
|
108
108
|
|
|
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>>;
|
|
109
124
|
declare class Auth {
|
|
110
125
|
private http;
|
|
111
126
|
private tokenManager;
|
|
@@ -152,63 +167,46 @@ declare class Auth {
|
|
|
152
167
|
error: InsForgeError | null;
|
|
153
168
|
}>;
|
|
154
169
|
/**
|
|
155
|
-
* Get
|
|
156
|
-
* Returns
|
|
170
|
+
* Get all public authentication configuration (OAuth + Email)
|
|
171
|
+
* Returns both OAuth providers and email authentication settings in one request
|
|
157
172
|
* This is a public endpoint that doesn't require authentication
|
|
158
173
|
*
|
|
159
|
-
* @returns
|
|
174
|
+
* @returns Complete public authentication configuration including OAuth providers and email auth settings
|
|
160
175
|
*
|
|
161
176
|
* @example
|
|
162
177
|
* ```ts
|
|
163
|
-
* const { data, error } = await insforge.auth.
|
|
178
|
+
* const { data, error } = await insforge.auth.getPublicAuthConfig();
|
|
164
179
|
* if (data) {
|
|
165
|
-
*
|
|
166
|
-
*
|
|
180
|
+
* console.log(`OAuth providers: ${data.oauth.data.length}`);
|
|
181
|
+
* console.log(`Password min length: ${data.email.passwordMinLength}`);
|
|
167
182
|
* }
|
|
168
183
|
* ```
|
|
169
184
|
*/
|
|
170
|
-
|
|
171
|
-
data:
|
|
172
|
-
error: InsForgeError | null;
|
|
173
|
-
}>;
|
|
174
|
-
/**
|
|
175
|
-
* Get public email authentication configuration
|
|
176
|
-
* Returns email authentication settings configured on the backend
|
|
177
|
-
* This is a public endpoint that doesn't require authentication
|
|
178
|
-
*
|
|
179
|
-
* @returns Email authentication configuration including password requirements and email verification settings
|
|
180
|
-
*
|
|
181
|
-
* @example
|
|
182
|
-
* ```ts
|
|
183
|
-
* const { data, error } = await insforge.auth.getEmailAuthConfig();
|
|
184
|
-
* if (data) {
|
|
185
|
-
* console.log(`Password min length: ${data.passwordMinLength}`);
|
|
186
|
-
* console.log(`Requires email verification: ${data.requireEmailVerification}`);
|
|
187
|
-
* console.log(`Requires uppercase: ${data.requireUppercase}`);
|
|
188
|
-
* }
|
|
189
|
-
* ```
|
|
190
|
-
*/
|
|
191
|
-
getEmailAuthConfig(): Promise<{
|
|
192
|
-
data: GetPublicEmailAuthConfigResponse | null;
|
|
185
|
+
getPublicAuthConfig(): Promise<{
|
|
186
|
+
data: GetPublicAuthConfigResponse | null;
|
|
193
187
|
error: InsForgeError | null;
|
|
194
188
|
}>;
|
|
195
189
|
/**
|
|
196
190
|
* Get the current user with full profile information
|
|
197
|
-
* Returns both auth info (id, email, role) and profile data (
|
|
191
|
+
* Returns both auth info (id, email, role) and profile data (dynamic fields from users table)
|
|
198
192
|
*/
|
|
199
193
|
getCurrentUser(): Promise<{
|
|
200
194
|
data: {
|
|
201
|
-
user:
|
|
202
|
-
|
|
195
|
+
user: {
|
|
196
|
+
id: UserIdSchema;
|
|
197
|
+
email: EmailSchema;
|
|
198
|
+
role: RoleSchema;
|
|
199
|
+
};
|
|
200
|
+
profile: ProfileData | null;
|
|
203
201
|
} | null;
|
|
204
202
|
error: any | null;
|
|
205
203
|
}>;
|
|
206
204
|
/**
|
|
207
205
|
* Get any user's profile by ID
|
|
208
|
-
* Returns profile information from the users table (
|
|
206
|
+
* Returns profile information from the users table (dynamic fields)
|
|
209
207
|
*/
|
|
210
208
|
getProfile(userId: string): Promise<{
|
|
211
|
-
data:
|
|
209
|
+
data: ProfileData | null;
|
|
212
210
|
error: any | null;
|
|
213
211
|
}>;
|
|
214
212
|
/**
|
|
@@ -223,18 +221,59 @@ declare class Auth {
|
|
|
223
221
|
};
|
|
224
222
|
/**
|
|
225
223
|
* Set/Update the current user's profile
|
|
226
|
-
* Updates profile information in the users table (
|
|
227
|
-
*/
|
|
228
|
-
setProfile(profile: {
|
|
229
|
-
|
|
230
|
-
avatar_url?: string;
|
|
231
|
-
bio?: string;
|
|
232
|
-
birthday?: string;
|
|
233
|
-
[key: string]: any;
|
|
234
|
-
}): Promise<{
|
|
235
|
-
data: any | null;
|
|
224
|
+
* Updates profile information in the users table (supports any dynamic fields)
|
|
225
|
+
*/
|
|
226
|
+
setProfile(profile: UpdateProfileData): Promise<{
|
|
227
|
+
data: ProfileData | null;
|
|
236
228
|
error: any | null;
|
|
237
229
|
}>;
|
|
230
|
+
/**
|
|
231
|
+
* Send password reset code to user's email
|
|
232
|
+
* Always returns success to prevent user enumeration
|
|
233
|
+
*/
|
|
234
|
+
sendPasswordResetCode(request: {
|
|
235
|
+
email: string;
|
|
236
|
+
}): Promise<{
|
|
237
|
+
data: {
|
|
238
|
+
success: boolean;
|
|
239
|
+
message: string;
|
|
240
|
+
} | null;
|
|
241
|
+
error: InsForgeError | null;
|
|
242
|
+
}>;
|
|
243
|
+
/**
|
|
244
|
+
* Reset password with OTP token
|
|
245
|
+
* Token can be from magic link or from code verification
|
|
246
|
+
*/
|
|
247
|
+
resetPassword(request: {
|
|
248
|
+
newPassword: string;
|
|
249
|
+
otp: string;
|
|
250
|
+
}): Promise<{
|
|
251
|
+
data: {
|
|
252
|
+
message: string;
|
|
253
|
+
redirectTo?: string;
|
|
254
|
+
} | null;
|
|
255
|
+
error: InsForgeError | null;
|
|
256
|
+
}>;
|
|
257
|
+
/**
|
|
258
|
+
* Verify email with OTP token
|
|
259
|
+
* If email is provided: uses numeric OTP verification (6-digit code)
|
|
260
|
+
* If email is NOT provided: uses link OTP verification (64-char token)
|
|
261
|
+
*/
|
|
262
|
+
verifyEmail(request: {
|
|
263
|
+
email?: string;
|
|
264
|
+
otp: string;
|
|
265
|
+
}): Promise<{
|
|
266
|
+
data: {
|
|
267
|
+
accessToken: string;
|
|
268
|
+
user?: any;
|
|
269
|
+
} | null;
|
|
270
|
+
error: InsForgeError | null;
|
|
271
|
+
}>;
|
|
272
|
+
/**
|
|
273
|
+
* Set the current session
|
|
274
|
+
* This is used to set the session from the OAuth callback
|
|
275
|
+
*/
|
|
276
|
+
setSession(session: AuthSession): Promise<void>;
|
|
238
277
|
}
|
|
239
278
|
|
|
240
279
|
/**
|
|
@@ -568,4 +607,4 @@ declare class InsForgeClient {
|
|
|
568
607
|
|
|
569
608
|
declare function createClient(config: InsForgeConfig): InsForgeClient;
|
|
570
609
|
|
|
571
|
-
export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, Database, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError, Storage, StorageBucket, type StorageResponse, TokenManager, type TokenStorage, createClient, InsForgeClient as default };
|
|
610
|
+
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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema,
|
|
1
|
+
import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetPublicAuthConfigResponse, UserIdSchema, EmailSchema, RoleSchema, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest } from '@insforge/shared-schemas';
|
|
2
2
|
export { AuthErrorResponse, CreateSessionRequest, CreateUserRequest, UserSchema } from '@insforge/shared-schemas';
|
|
3
3
|
import * as _supabase_postgrest_js from '@supabase/postgrest-js';
|
|
4
4
|
|
|
@@ -106,6 +106,21 @@ declare class TokenManager {
|
|
|
106
106
|
* Uses shared schemas for type safety
|
|
107
107
|
*/
|
|
108
108
|
|
|
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>>;
|
|
109
124
|
declare class Auth {
|
|
110
125
|
private http;
|
|
111
126
|
private tokenManager;
|
|
@@ -152,63 +167,46 @@ declare class Auth {
|
|
|
152
167
|
error: InsForgeError | null;
|
|
153
168
|
}>;
|
|
154
169
|
/**
|
|
155
|
-
* Get
|
|
156
|
-
* Returns
|
|
170
|
+
* Get all public authentication configuration (OAuth + Email)
|
|
171
|
+
* Returns both OAuth providers and email authentication settings in one request
|
|
157
172
|
* This is a public endpoint that doesn't require authentication
|
|
158
173
|
*
|
|
159
|
-
* @returns
|
|
174
|
+
* @returns Complete public authentication configuration including OAuth providers and email auth settings
|
|
160
175
|
*
|
|
161
176
|
* @example
|
|
162
177
|
* ```ts
|
|
163
|
-
* const { data, error } = await insforge.auth.
|
|
178
|
+
* const { data, error } = await insforge.auth.getPublicAuthConfig();
|
|
164
179
|
* if (data) {
|
|
165
|
-
*
|
|
166
|
-
*
|
|
180
|
+
* console.log(`OAuth providers: ${data.oauth.data.length}`);
|
|
181
|
+
* console.log(`Password min length: ${data.email.passwordMinLength}`);
|
|
167
182
|
* }
|
|
168
183
|
* ```
|
|
169
184
|
*/
|
|
170
|
-
|
|
171
|
-
data:
|
|
172
|
-
error: InsForgeError | null;
|
|
173
|
-
}>;
|
|
174
|
-
/**
|
|
175
|
-
* Get public email authentication configuration
|
|
176
|
-
* Returns email authentication settings configured on the backend
|
|
177
|
-
* This is a public endpoint that doesn't require authentication
|
|
178
|
-
*
|
|
179
|
-
* @returns Email authentication configuration including password requirements and email verification settings
|
|
180
|
-
*
|
|
181
|
-
* @example
|
|
182
|
-
* ```ts
|
|
183
|
-
* const { data, error } = await insforge.auth.getEmailAuthConfig();
|
|
184
|
-
* if (data) {
|
|
185
|
-
* console.log(`Password min length: ${data.passwordMinLength}`);
|
|
186
|
-
* console.log(`Requires email verification: ${data.requireEmailVerification}`);
|
|
187
|
-
* console.log(`Requires uppercase: ${data.requireUppercase}`);
|
|
188
|
-
* }
|
|
189
|
-
* ```
|
|
190
|
-
*/
|
|
191
|
-
getEmailAuthConfig(): Promise<{
|
|
192
|
-
data: GetPublicEmailAuthConfigResponse | null;
|
|
185
|
+
getPublicAuthConfig(): Promise<{
|
|
186
|
+
data: GetPublicAuthConfigResponse | null;
|
|
193
187
|
error: InsForgeError | null;
|
|
194
188
|
}>;
|
|
195
189
|
/**
|
|
196
190
|
* Get the current user with full profile information
|
|
197
|
-
* Returns both auth info (id, email, role) and profile data (
|
|
191
|
+
* Returns both auth info (id, email, role) and profile data (dynamic fields from users table)
|
|
198
192
|
*/
|
|
199
193
|
getCurrentUser(): Promise<{
|
|
200
194
|
data: {
|
|
201
|
-
user:
|
|
202
|
-
|
|
195
|
+
user: {
|
|
196
|
+
id: UserIdSchema;
|
|
197
|
+
email: EmailSchema;
|
|
198
|
+
role: RoleSchema;
|
|
199
|
+
};
|
|
200
|
+
profile: ProfileData | null;
|
|
203
201
|
} | null;
|
|
204
202
|
error: any | null;
|
|
205
203
|
}>;
|
|
206
204
|
/**
|
|
207
205
|
* Get any user's profile by ID
|
|
208
|
-
* Returns profile information from the users table (
|
|
206
|
+
* Returns profile information from the users table (dynamic fields)
|
|
209
207
|
*/
|
|
210
208
|
getProfile(userId: string): Promise<{
|
|
211
|
-
data:
|
|
209
|
+
data: ProfileData | null;
|
|
212
210
|
error: any | null;
|
|
213
211
|
}>;
|
|
214
212
|
/**
|
|
@@ -223,18 +221,59 @@ declare class Auth {
|
|
|
223
221
|
};
|
|
224
222
|
/**
|
|
225
223
|
* Set/Update the current user's profile
|
|
226
|
-
* Updates profile information in the users table (
|
|
227
|
-
*/
|
|
228
|
-
setProfile(profile: {
|
|
229
|
-
|
|
230
|
-
avatar_url?: string;
|
|
231
|
-
bio?: string;
|
|
232
|
-
birthday?: string;
|
|
233
|
-
[key: string]: any;
|
|
234
|
-
}): Promise<{
|
|
235
|
-
data: any | null;
|
|
224
|
+
* Updates profile information in the users table (supports any dynamic fields)
|
|
225
|
+
*/
|
|
226
|
+
setProfile(profile: UpdateProfileData): Promise<{
|
|
227
|
+
data: ProfileData | null;
|
|
236
228
|
error: any | null;
|
|
237
229
|
}>;
|
|
230
|
+
/**
|
|
231
|
+
* Send password reset code to user's email
|
|
232
|
+
* Always returns success to prevent user enumeration
|
|
233
|
+
*/
|
|
234
|
+
sendPasswordResetCode(request: {
|
|
235
|
+
email: string;
|
|
236
|
+
}): Promise<{
|
|
237
|
+
data: {
|
|
238
|
+
success: boolean;
|
|
239
|
+
message: string;
|
|
240
|
+
} | null;
|
|
241
|
+
error: InsForgeError | null;
|
|
242
|
+
}>;
|
|
243
|
+
/**
|
|
244
|
+
* Reset password with OTP token
|
|
245
|
+
* Token can be from magic link or from code verification
|
|
246
|
+
*/
|
|
247
|
+
resetPassword(request: {
|
|
248
|
+
newPassword: string;
|
|
249
|
+
otp: string;
|
|
250
|
+
}): Promise<{
|
|
251
|
+
data: {
|
|
252
|
+
message: string;
|
|
253
|
+
redirectTo?: string;
|
|
254
|
+
} | null;
|
|
255
|
+
error: InsForgeError | null;
|
|
256
|
+
}>;
|
|
257
|
+
/**
|
|
258
|
+
* Verify email with OTP token
|
|
259
|
+
* If email is provided: uses numeric OTP verification (6-digit code)
|
|
260
|
+
* If email is NOT provided: uses link OTP verification (64-char token)
|
|
261
|
+
*/
|
|
262
|
+
verifyEmail(request: {
|
|
263
|
+
email?: string;
|
|
264
|
+
otp: string;
|
|
265
|
+
}): Promise<{
|
|
266
|
+
data: {
|
|
267
|
+
accessToken: string;
|
|
268
|
+
user?: any;
|
|
269
|
+
} | null;
|
|
270
|
+
error: InsForgeError | null;
|
|
271
|
+
}>;
|
|
272
|
+
/**
|
|
273
|
+
* Set the current session
|
|
274
|
+
* This is used to set the session from the OAuth callback
|
|
275
|
+
*/
|
|
276
|
+
setSession(session: AuthSession): Promise<void>;
|
|
238
277
|
}
|
|
239
278
|
|
|
240
279
|
/**
|
|
@@ -568,4 +607,4 @@ declare class InsForgeClient {
|
|
|
568
607
|
|
|
569
608
|
declare function createClient(config: InsForgeConfig): InsForgeClient;
|
|
570
609
|
|
|
571
|
-
export { AI, type ApiError, Auth, type AuthSession, type InsForgeConfig as ClientOptions, Database, type FunctionInvokeOptions, Functions, HttpClient, InsForgeClient, type InsForgeConfig, InsForgeError, Storage, StorageBucket, type StorageResponse, TokenManager, type TokenStorage, createClient, InsForgeClient as default };
|
|
610
|
+
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.js
CHANGED
|
@@ -292,6 +292,28 @@ var Database = class {
|
|
|
292
292
|
};
|
|
293
293
|
|
|
294
294
|
// src/modules/auth.ts
|
|
295
|
+
function convertDbProfileToCamelCase(dbProfile) {
|
|
296
|
+
const result = {
|
|
297
|
+
id: dbProfile.id
|
|
298
|
+
};
|
|
299
|
+
if (dbProfile.created_at !== void 0) result.createdAt = dbProfile.created_at;
|
|
300
|
+
if (dbProfile.updated_at !== void 0) result.updatedAt = dbProfile.updated_at;
|
|
301
|
+
Object.keys(dbProfile).forEach((key) => {
|
|
302
|
+
if (key === "id" || key === "created_at" || key === "updated_at") return;
|
|
303
|
+
const camelKey = key.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
304
|
+
result[camelKey] = dbProfile[key];
|
|
305
|
+
});
|
|
306
|
+
return result;
|
|
307
|
+
}
|
|
308
|
+
function convertCamelCaseToDbProfile(profile) {
|
|
309
|
+
const dbProfile = {};
|
|
310
|
+
Object.keys(profile).forEach((key) => {
|
|
311
|
+
if (profile[key] === void 0) return;
|
|
312
|
+
const snakeKey = key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
313
|
+
dbProfile[snakeKey] = profile[key];
|
|
314
|
+
});
|
|
315
|
+
return dbProfile;
|
|
316
|
+
}
|
|
295
317
|
var Auth = class {
|
|
296
318
|
constructor(http, tokenManager) {
|
|
297
319
|
this.http = http;
|
|
@@ -348,19 +370,14 @@ var Auth = class {
|
|
|
348
370
|
async signUp(request) {
|
|
349
371
|
try {
|
|
350
372
|
const response = await this.http.post("/api/auth/users", request);
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
updatedAt: ""
|
|
360
|
-
}
|
|
361
|
-
};
|
|
362
|
-
this.tokenManager.saveSession(session);
|
|
363
|
-
this.http.setAuthToken(response.accessToken || "");
|
|
373
|
+
if (response.accessToken && response.user) {
|
|
374
|
+
const session = {
|
|
375
|
+
accessToken: response.accessToken,
|
|
376
|
+
user: response.user
|
|
377
|
+
};
|
|
378
|
+
this.tokenManager.saveSession(session);
|
|
379
|
+
this.http.setAuthToken(response.accessToken);
|
|
380
|
+
}
|
|
364
381
|
return {
|
|
365
382
|
data: response,
|
|
366
383
|
error: null
|
|
@@ -469,62 +486,24 @@ var Auth = class {
|
|
|
469
486
|
}
|
|
470
487
|
}
|
|
471
488
|
/**
|
|
472
|
-
* Get
|
|
473
|
-
* Returns
|
|
489
|
+
* Get all public authentication configuration (OAuth + Email)
|
|
490
|
+
* Returns both OAuth providers and email authentication settings in one request
|
|
474
491
|
* This is a public endpoint that doesn't require authentication
|
|
475
492
|
*
|
|
476
|
-
* @returns
|
|
493
|
+
* @returns Complete public authentication configuration including OAuth providers and email auth settings
|
|
477
494
|
*
|
|
478
495
|
* @example
|
|
479
496
|
* ```ts
|
|
480
|
-
* const { data, error } = await insforge.auth.
|
|
497
|
+
* const { data, error } = await insforge.auth.getPublicAuthConfig();
|
|
481
498
|
* if (data) {
|
|
482
|
-
*
|
|
483
|
-
*
|
|
499
|
+
* console.log(`OAuth providers: ${data.oauth.data.length}`);
|
|
500
|
+
* console.log(`Password min length: ${data.email.passwordMinLength}`);
|
|
484
501
|
* }
|
|
485
502
|
* ```
|
|
486
503
|
*/
|
|
487
|
-
async
|
|
504
|
+
async getPublicAuthConfig() {
|
|
488
505
|
try {
|
|
489
|
-
const response = await this.http.get("/api/auth/
|
|
490
|
-
return {
|
|
491
|
-
data: response.data,
|
|
492
|
-
error: null
|
|
493
|
-
};
|
|
494
|
-
} catch (error) {
|
|
495
|
-
if (error instanceof InsForgeError) {
|
|
496
|
-
return { data: null, error };
|
|
497
|
-
}
|
|
498
|
-
return {
|
|
499
|
-
data: null,
|
|
500
|
-
error: new InsForgeError(
|
|
501
|
-
"An unexpected error occurred while fetching OAuth providers",
|
|
502
|
-
500,
|
|
503
|
-
"UNEXPECTED_ERROR"
|
|
504
|
-
)
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
/**
|
|
509
|
-
* Get public email authentication configuration
|
|
510
|
-
* Returns email authentication settings configured on the backend
|
|
511
|
-
* This is a public endpoint that doesn't require authentication
|
|
512
|
-
*
|
|
513
|
-
* @returns Email authentication configuration including password requirements and email verification settings
|
|
514
|
-
*
|
|
515
|
-
* @example
|
|
516
|
-
* ```ts
|
|
517
|
-
* const { data, error } = await insforge.auth.getEmailAuthConfig();
|
|
518
|
-
* if (data) {
|
|
519
|
-
* console.log(`Password min length: ${data.passwordMinLength}`);
|
|
520
|
-
* console.log(`Requires email verification: ${data.requireEmailVerification}`);
|
|
521
|
-
* console.log(`Requires uppercase: ${data.requireUppercase}`);
|
|
522
|
-
* }
|
|
523
|
-
* ```
|
|
524
|
-
*/
|
|
525
|
-
async getEmailAuthConfig() {
|
|
526
|
-
try {
|
|
527
|
-
const response = await this.http.get("/api/auth/email/public-config");
|
|
506
|
+
const response = await this.http.get("/api/auth/public-config");
|
|
528
507
|
return {
|
|
529
508
|
data: response,
|
|
530
509
|
error: null
|
|
@@ -536,7 +515,7 @@ var Auth = class {
|
|
|
536
515
|
return {
|
|
537
516
|
data: null,
|
|
538
517
|
error: new InsForgeError(
|
|
539
|
-
"An unexpected error occurred while fetching
|
|
518
|
+
"An unexpected error occurred while fetching public authentication configuration",
|
|
540
519
|
500,
|
|
541
520
|
"UNEXPECTED_ERROR"
|
|
542
521
|
)
|
|
@@ -545,7 +524,7 @@ var Auth = class {
|
|
|
545
524
|
}
|
|
546
525
|
/**
|
|
547
526
|
* Get the current user with full profile information
|
|
548
|
-
* Returns both auth info (id, email, role) and profile data (
|
|
527
|
+
* Returns both auth info (id, email, role) and profile data (dynamic fields from users table)
|
|
549
528
|
*/
|
|
550
529
|
async getCurrentUser() {
|
|
551
530
|
try {
|
|
@@ -562,7 +541,7 @@ var Auth = class {
|
|
|
562
541
|
return {
|
|
563
542
|
data: {
|
|
564
543
|
user: authResponse.user,
|
|
565
|
-
profile
|
|
544
|
+
profile: profile ? convertDbProfileToCamelCase(profile) : null
|
|
566
545
|
},
|
|
567
546
|
error: null
|
|
568
547
|
};
|
|
@@ -586,14 +565,17 @@ var Auth = class {
|
|
|
586
565
|
}
|
|
587
566
|
/**
|
|
588
567
|
* Get any user's profile by ID
|
|
589
|
-
* Returns profile information from the users table (
|
|
568
|
+
* Returns profile information from the users table (dynamic fields)
|
|
590
569
|
*/
|
|
591
570
|
async getProfile(userId) {
|
|
592
571
|
const { data, error } = await this.database.from("users").select("*").eq("id", userId).single();
|
|
593
572
|
if (error && error.code === "PGRST116") {
|
|
594
573
|
return { data: null, error: null };
|
|
595
574
|
}
|
|
596
|
-
|
|
575
|
+
if (data) {
|
|
576
|
+
return { data: convertDbProfileToCamelCase(data), error: null };
|
|
577
|
+
}
|
|
578
|
+
return { data: null, error };
|
|
597
579
|
}
|
|
598
580
|
/**
|
|
599
581
|
* Get the current session (only session data, no API call)
|
|
@@ -623,7 +605,7 @@ var Auth = class {
|
|
|
623
605
|
}
|
|
624
606
|
/**
|
|
625
607
|
* Set/Update the current user's profile
|
|
626
|
-
* Updates profile information in the users table (
|
|
608
|
+
* Updates profile information in the users table (supports any dynamic fields)
|
|
627
609
|
*/
|
|
628
610
|
async setProfile(profile) {
|
|
629
611
|
const session = this.tokenManager.getSession();
|
|
@@ -643,12 +625,136 @@ var Auth = class {
|
|
|
643
625
|
return { data: null, error: error2 };
|
|
644
626
|
}
|
|
645
627
|
if (data2?.user) {
|
|
646
|
-
session.user =
|
|
628
|
+
session.user = {
|
|
629
|
+
id: data2.user.id,
|
|
630
|
+
email: data2.user.email,
|
|
631
|
+
name: data2.profile?.nickname || "",
|
|
632
|
+
// Fallback - profile structure is dynamic
|
|
633
|
+
emailVerified: false,
|
|
634
|
+
// Not available from API, but required by UserSchema
|
|
635
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
636
|
+
// Fallback
|
|
637
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
638
|
+
// Fallback
|
|
639
|
+
};
|
|
647
640
|
this.tokenManager.saveSession(session);
|
|
648
641
|
}
|
|
649
642
|
}
|
|
650
|
-
const
|
|
651
|
-
|
|
643
|
+
const dbProfile = convertCamelCaseToDbProfile(profile);
|
|
644
|
+
const { data, error } = await this.database.from("users").update(dbProfile).eq("id", session.user.id).select().single();
|
|
645
|
+
if (data) {
|
|
646
|
+
return { data: convertDbProfileToCamelCase(data), error: null };
|
|
647
|
+
}
|
|
648
|
+
return { data: null, error };
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Send password reset code to user's email
|
|
652
|
+
* Always returns success to prevent user enumeration
|
|
653
|
+
*/
|
|
654
|
+
async sendPasswordResetCode(request) {
|
|
655
|
+
try {
|
|
656
|
+
const response = await this.http.post(
|
|
657
|
+
"/api/auth/email/send-reset-password-code",
|
|
658
|
+
request
|
|
659
|
+
);
|
|
660
|
+
return {
|
|
661
|
+
data: response,
|
|
662
|
+
error: null
|
|
663
|
+
};
|
|
664
|
+
} catch (error) {
|
|
665
|
+
if (error instanceof InsForgeError) {
|
|
666
|
+
return { data: null, error };
|
|
667
|
+
}
|
|
668
|
+
return {
|
|
669
|
+
data: null,
|
|
670
|
+
error: new InsForgeError(
|
|
671
|
+
"An unexpected error occurred while sending password reset code",
|
|
672
|
+
500,
|
|
673
|
+
"UNEXPECTED_ERROR"
|
|
674
|
+
)
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* Reset password with OTP token
|
|
680
|
+
* Token can be from magic link or from code verification
|
|
681
|
+
*/
|
|
682
|
+
async resetPassword(request) {
|
|
683
|
+
try {
|
|
684
|
+
const response = await this.http.post(
|
|
685
|
+
"/api/auth/reset-password",
|
|
686
|
+
request
|
|
687
|
+
);
|
|
688
|
+
return {
|
|
689
|
+
data: response,
|
|
690
|
+
error: null
|
|
691
|
+
};
|
|
692
|
+
} catch (error) {
|
|
693
|
+
if (error instanceof InsForgeError) {
|
|
694
|
+
return { data: null, error };
|
|
695
|
+
}
|
|
696
|
+
return {
|
|
697
|
+
data: null,
|
|
698
|
+
error: new InsForgeError(
|
|
699
|
+
"An unexpected error occurred while resetting password",
|
|
700
|
+
500,
|
|
701
|
+
"UNEXPECTED_ERROR"
|
|
702
|
+
)
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Verify email with OTP token
|
|
708
|
+
* If email is provided: uses numeric OTP verification (6-digit code)
|
|
709
|
+
* If email is NOT provided: uses link OTP verification (64-char token)
|
|
710
|
+
*/
|
|
711
|
+
async verifyEmail(request) {
|
|
712
|
+
try {
|
|
713
|
+
const response = await this.http.post(
|
|
714
|
+
"/api/auth/verify-email",
|
|
715
|
+
request
|
|
716
|
+
);
|
|
717
|
+
if (response.accessToken) {
|
|
718
|
+
const session = {
|
|
719
|
+
accessToken: response.accessToken,
|
|
720
|
+
user: response.user || {}
|
|
721
|
+
};
|
|
722
|
+
this.tokenManager.saveSession(session);
|
|
723
|
+
this.http.setAuthToken(response.accessToken);
|
|
724
|
+
}
|
|
725
|
+
return {
|
|
726
|
+
data: response,
|
|
727
|
+
error: null
|
|
728
|
+
};
|
|
729
|
+
} catch (error) {
|
|
730
|
+
if (error instanceof InsForgeError) {
|
|
731
|
+
return { data: null, error };
|
|
732
|
+
}
|
|
733
|
+
return {
|
|
734
|
+
data: null,
|
|
735
|
+
error: new InsForgeError(
|
|
736
|
+
"An unexpected error occurred while verifying email",
|
|
737
|
+
500,
|
|
738
|
+
"UNEXPECTED_ERROR"
|
|
739
|
+
)
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Set the current session
|
|
745
|
+
* This is used to set the session from the OAuth callback
|
|
746
|
+
*/
|
|
747
|
+
async setSession(session) {
|
|
748
|
+
try {
|
|
749
|
+
this.tokenManager.saveSession(session);
|
|
750
|
+
this.http.setAuthToken(session.accessToken);
|
|
751
|
+
} catch (error) {
|
|
752
|
+
throw new InsForgeError(
|
|
753
|
+
"An unexpected error occurred while setting session",
|
|
754
|
+
500,
|
|
755
|
+
"UNEXPECTED_ERROR"
|
|
756
|
+
);
|
|
757
|
+
}
|
|
652
758
|
}
|
|
653
759
|
};
|
|
654
760
|
|