@insforge/sdk 0.0.58-dev.3 → 0.0.58-dev.5
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 +74 -38
- package/dist/index.d.ts +74 -38
- package/dist/index.js +139 -55
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +139 -55
- 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,49 +167,28 @@ 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: {
|
|
@@ -203,16 +197,16 @@ declare class Auth {
|
|
|
203
197
|
email: EmailSchema;
|
|
204
198
|
role: RoleSchema;
|
|
205
199
|
};
|
|
206
|
-
profile:
|
|
200
|
+
profile: ProfileData | null;
|
|
207
201
|
} | null;
|
|
208
202
|
error: any | null;
|
|
209
203
|
}>;
|
|
210
204
|
/**
|
|
211
205
|
* Get any user's profile by ID
|
|
212
|
-
* Returns profile information from the users table (
|
|
206
|
+
* Returns profile information from the users table (dynamic fields)
|
|
213
207
|
*/
|
|
214
208
|
getProfile(userId: string): Promise<{
|
|
215
|
-
data:
|
|
209
|
+
data: ProfileData | null;
|
|
216
210
|
error: any | null;
|
|
217
211
|
}>;
|
|
218
212
|
/**
|
|
@@ -227,12 +221,54 @@ declare class Auth {
|
|
|
227
221
|
};
|
|
228
222
|
/**
|
|
229
223
|
* Set/Update the current user's profile
|
|
230
|
-
* Updates profile information in the users table (
|
|
224
|
+
* Updates profile information in the users table (supports any dynamic fields)
|
|
231
225
|
*/
|
|
232
|
-
setProfile(profile:
|
|
233
|
-
data:
|
|
226
|
+
setProfile(profile: UpdateProfileData): Promise<{
|
|
227
|
+
data: ProfileData | null;
|
|
234
228
|
error: any | null;
|
|
235
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
|
+
}>;
|
|
236
272
|
}
|
|
237
273
|
|
|
238
274
|
/**
|
|
@@ -566,4 +602,4 @@ declare class InsForgeClient {
|
|
|
566
602
|
|
|
567
603
|
declare function createClient(config: InsForgeConfig): InsForgeClient;
|
|
568
604
|
|
|
569
|
-
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 };
|
|
605
|
+
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,49 +167,28 @@ 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: {
|
|
@@ -203,16 +197,16 @@ declare class Auth {
|
|
|
203
197
|
email: EmailSchema;
|
|
204
198
|
role: RoleSchema;
|
|
205
199
|
};
|
|
206
|
-
profile:
|
|
200
|
+
profile: ProfileData | null;
|
|
207
201
|
} | null;
|
|
208
202
|
error: any | null;
|
|
209
203
|
}>;
|
|
210
204
|
/**
|
|
211
205
|
* Get any user's profile by ID
|
|
212
|
-
* Returns profile information from the users table (
|
|
206
|
+
* Returns profile information from the users table (dynamic fields)
|
|
213
207
|
*/
|
|
214
208
|
getProfile(userId: string): Promise<{
|
|
215
|
-
data:
|
|
209
|
+
data: ProfileData | null;
|
|
216
210
|
error: any | null;
|
|
217
211
|
}>;
|
|
218
212
|
/**
|
|
@@ -227,12 +221,54 @@ declare class Auth {
|
|
|
227
221
|
};
|
|
228
222
|
/**
|
|
229
223
|
* Set/Update the current user's profile
|
|
230
|
-
* Updates profile information in the users table (
|
|
224
|
+
* Updates profile information in the users table (supports any dynamic fields)
|
|
231
225
|
*/
|
|
232
|
-
setProfile(profile:
|
|
233
|
-
data:
|
|
226
|
+
setProfile(profile: UpdateProfileData): Promise<{
|
|
227
|
+
data: ProfileData | null;
|
|
234
228
|
error: any | null;
|
|
235
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
|
+
}>;
|
|
236
272
|
}
|
|
237
273
|
|
|
238
274
|
/**
|
|
@@ -566,4 +602,4 @@ declare class InsForgeClient {
|
|
|
566
602
|
|
|
567
603
|
declare function createClient(config: InsForgeConfig): InsForgeClient;
|
|
568
604
|
|
|
569
|
-
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 };
|
|
605
|
+
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;
|
|
@@ -464,62 +486,24 @@ var Auth = class {
|
|
|
464
486
|
}
|
|
465
487
|
}
|
|
466
488
|
/**
|
|
467
|
-
* Get
|
|
468
|
-
* Returns
|
|
489
|
+
* Get all public authentication configuration (OAuth + Email)
|
|
490
|
+
* Returns both OAuth providers and email authentication settings in one request
|
|
469
491
|
* This is a public endpoint that doesn't require authentication
|
|
470
492
|
*
|
|
471
|
-
* @returns
|
|
493
|
+
* @returns Complete public authentication configuration including OAuth providers and email auth settings
|
|
472
494
|
*
|
|
473
495
|
* @example
|
|
474
496
|
* ```ts
|
|
475
|
-
* const { data, error } = await insforge.auth.
|
|
497
|
+
* const { data, error } = await insforge.auth.getPublicAuthConfig();
|
|
476
498
|
* if (data) {
|
|
477
|
-
*
|
|
478
|
-
*
|
|
499
|
+
* console.log(`OAuth providers: ${data.oauth.data.length}`);
|
|
500
|
+
* console.log(`Password min length: ${data.email.passwordMinLength}`);
|
|
479
501
|
* }
|
|
480
502
|
* ```
|
|
481
503
|
*/
|
|
482
|
-
async
|
|
504
|
+
async getPublicAuthConfig() {
|
|
483
505
|
try {
|
|
484
|
-
const response = await this.http.get("/api/auth/
|
|
485
|
-
return {
|
|
486
|
-
data: response.data,
|
|
487
|
-
error: null
|
|
488
|
-
};
|
|
489
|
-
} catch (error) {
|
|
490
|
-
if (error instanceof InsForgeError) {
|
|
491
|
-
return { data: null, error };
|
|
492
|
-
}
|
|
493
|
-
return {
|
|
494
|
-
data: null,
|
|
495
|
-
error: new InsForgeError(
|
|
496
|
-
"An unexpected error occurred while fetching OAuth providers",
|
|
497
|
-
500,
|
|
498
|
-
"UNEXPECTED_ERROR"
|
|
499
|
-
)
|
|
500
|
-
};
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
/**
|
|
504
|
-
* Get public email authentication configuration
|
|
505
|
-
* Returns email authentication settings configured on the backend
|
|
506
|
-
* This is a public endpoint that doesn't require authentication
|
|
507
|
-
*
|
|
508
|
-
* @returns Email authentication configuration including password requirements and email verification settings
|
|
509
|
-
*
|
|
510
|
-
* @example
|
|
511
|
-
* ```ts
|
|
512
|
-
* const { data, error } = await insforge.auth.getEmailAuthConfig();
|
|
513
|
-
* if (data) {
|
|
514
|
-
* console.log(`Password min length: ${data.passwordMinLength}`);
|
|
515
|
-
* console.log(`Requires email verification: ${data.requireEmailVerification}`);
|
|
516
|
-
* console.log(`Requires uppercase: ${data.requireUppercase}`);
|
|
517
|
-
* }
|
|
518
|
-
* ```
|
|
519
|
-
*/
|
|
520
|
-
async getEmailAuthConfig() {
|
|
521
|
-
try {
|
|
522
|
-
const response = await this.http.get("/api/auth/email/public-config");
|
|
506
|
+
const response = await this.http.get("/api/auth/public-config");
|
|
523
507
|
return {
|
|
524
508
|
data: response,
|
|
525
509
|
error: null
|
|
@@ -531,7 +515,7 @@ var Auth = class {
|
|
|
531
515
|
return {
|
|
532
516
|
data: null,
|
|
533
517
|
error: new InsForgeError(
|
|
534
|
-
"An unexpected error occurred while fetching
|
|
518
|
+
"An unexpected error occurred while fetching public authentication configuration",
|
|
535
519
|
500,
|
|
536
520
|
"UNEXPECTED_ERROR"
|
|
537
521
|
)
|
|
@@ -540,7 +524,7 @@ var Auth = class {
|
|
|
540
524
|
}
|
|
541
525
|
/**
|
|
542
526
|
* Get the current user with full profile information
|
|
543
|
-
* 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)
|
|
544
528
|
*/
|
|
545
529
|
async getCurrentUser() {
|
|
546
530
|
try {
|
|
@@ -557,7 +541,7 @@ var Auth = class {
|
|
|
557
541
|
return {
|
|
558
542
|
data: {
|
|
559
543
|
user: authResponse.user,
|
|
560
|
-
profile
|
|
544
|
+
profile: profile ? convertDbProfileToCamelCase(profile) : null
|
|
561
545
|
},
|
|
562
546
|
error: null
|
|
563
547
|
};
|
|
@@ -581,14 +565,17 @@ var Auth = class {
|
|
|
581
565
|
}
|
|
582
566
|
/**
|
|
583
567
|
* Get any user's profile by ID
|
|
584
|
-
* Returns profile information from the users table (
|
|
568
|
+
* Returns profile information from the users table (dynamic fields)
|
|
585
569
|
*/
|
|
586
570
|
async getProfile(userId) {
|
|
587
571
|
const { data, error } = await this.database.from("users").select("*").eq("id", userId).single();
|
|
588
572
|
if (error && error.code === "PGRST116") {
|
|
589
573
|
return { data: null, error: null };
|
|
590
574
|
}
|
|
591
|
-
|
|
575
|
+
if (data) {
|
|
576
|
+
return { data: convertDbProfileToCamelCase(data), error: null };
|
|
577
|
+
}
|
|
578
|
+
return { data: null, error };
|
|
592
579
|
}
|
|
593
580
|
/**
|
|
594
581
|
* Get the current session (only session data, no API call)
|
|
@@ -618,7 +605,7 @@ var Auth = class {
|
|
|
618
605
|
}
|
|
619
606
|
/**
|
|
620
607
|
* Set/Update the current user's profile
|
|
621
|
-
* Updates profile information in the users table (
|
|
608
|
+
* Updates profile information in the users table (supports any dynamic fields)
|
|
622
609
|
*/
|
|
623
610
|
async setProfile(profile) {
|
|
624
611
|
const session = this.tokenManager.getSession();
|
|
@@ -642,7 +629,7 @@ var Auth = class {
|
|
|
642
629
|
id: data2.user.id,
|
|
643
630
|
email: data2.user.email,
|
|
644
631
|
name: data2.profile?.nickname || "",
|
|
645
|
-
//
|
|
632
|
+
// Fallback - profile structure is dynamic
|
|
646
633
|
emailVerified: false,
|
|
647
634
|
// Not available from API, but required by UserSchema
|
|
648
635
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -653,8 +640,105 @@ var Auth = class {
|
|
|
653
640
|
this.tokenManager.saveSession(session);
|
|
654
641
|
}
|
|
655
642
|
}
|
|
656
|
-
const
|
|
657
|
-
|
|
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
|
+
}
|
|
658
742
|
}
|
|
659
743
|
};
|
|
660
744
|
|