@insforge/sdk 0.0.58-dev.4 → 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 CHANGED
@@ -1,4 +1,4 @@
1
- import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, PublicOAuthProvider, GetPublicEmailAuthConfigResponse, UserIdSchema, EmailSchema, RoleSchema, ProfileSchema, UpdateProfileSchema, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest } from '@insforge/shared-schemas';
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 list of available OAuth providers
156
- * Returns the list of OAuth providers configured on the backend
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 Array of configured OAuth providers with their configuration status
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.getOAuthProviders();
178
+ * const { data, error } = await insforge.auth.getPublicAuthConfig();
164
179
  * if (data) {
165
- * // data is an array of PublicOAuthProvider: [{ provider: 'google', isConfigured: true }, ...]
166
- * data.forEach(p => console.log(`${p.provider}: ${p.isConfigured ? 'configured' : 'not configured'}`));
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
- getOAuthProviders(): Promise<{
171
- data: PublicOAuthProvider[] | null;
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 (nickname, avatar_url, bio, etc.)
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: ProfileSchema | null;
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 (nickname, avatarUrl, bio, etc.)
206
+ * Returns profile information from the users table (dynamic fields)
213
207
  */
214
208
  getProfile(userId: string): Promise<{
215
- data: ProfileSchema | null;
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 (nickname, avatarUrl, bio, etc.)
224
+ * Updates profile information in the users table (supports any dynamic fields)
231
225
  */
232
- setProfile(profile: UpdateProfileSchema): Promise<{
233
- data: ProfileSchema | null;
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, PublicOAuthProvider, GetPublicEmailAuthConfigResponse, UserIdSchema, EmailSchema, RoleSchema, ProfileSchema, UpdateProfileSchema, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest } from '@insforge/shared-schemas';
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 list of available OAuth providers
156
- * Returns the list of OAuth providers configured on the backend
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 Array of configured OAuth providers with their configuration status
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.getOAuthProviders();
178
+ * const { data, error } = await insforge.auth.getPublicAuthConfig();
164
179
  * if (data) {
165
- * // data is an array of PublicOAuthProvider: [{ provider: 'google', isConfigured: true }, ...]
166
- * data.forEach(p => console.log(`${p.provider}: ${p.isConfigured ? 'configured' : 'not configured'}`));
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
- getOAuthProviders(): Promise<{
171
- data: PublicOAuthProvider[] | null;
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 (nickname, avatar_url, bio, etc.)
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: ProfileSchema | null;
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 (nickname, avatarUrl, bio, etc.)
206
+ * Returns profile information from the users table (dynamic fields)
213
207
  */
214
208
  getProfile(userId: string): Promise<{
215
- data: ProfileSchema | null;
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 (nickname, avatarUrl, bio, etc.)
224
+ * Updates profile information in the users table (supports any dynamic fields)
231
225
  */
232
- setProfile(profile: UpdateProfileSchema): Promise<{
233
- data: ProfileSchema | null;
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,23 +292,26 @@ var Database = class {
292
292
  };
293
293
 
294
294
  // src/modules/auth.ts
295
- function convertDbProfileToSchema(dbProfile) {
296
- return {
297
- id: dbProfile.id,
298
- nickname: dbProfile.nickname,
299
- avatarUrl: dbProfile.avatar_url,
300
- bio: dbProfile.bio,
301
- birthday: dbProfile.birthday,
302
- createdAt: dbProfile.created_at,
303
- updatedAt: dbProfile.updated_at
295
+ function convertDbProfileToCamelCase(dbProfile) {
296
+ const result = {
297
+ id: dbProfile.id
304
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;
305
307
  }
306
- function convertSchemaToDbProfile(profile) {
308
+ function convertCamelCaseToDbProfile(profile) {
307
309
  const dbProfile = {};
308
- if (profile.nickname !== void 0) dbProfile.nickname = profile.nickname;
309
- if (profile.avatarUrl !== void 0) dbProfile.avatar_url = profile.avatarUrl;
310
- if (profile.bio !== void 0) dbProfile.bio = profile.bio;
311
- if (profile.birthday !== void 0) dbProfile.birthday = profile.birthday;
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
+ });
312
315
  return dbProfile;
313
316
  }
314
317
  var Auth = class {
@@ -483,62 +486,24 @@ var Auth = class {
483
486
  }
484
487
  }
485
488
  /**
486
- * Get list of available OAuth providers
487
- * Returns the list of OAuth providers configured on the backend
489
+ * Get all public authentication configuration (OAuth + Email)
490
+ * Returns both OAuth providers and email authentication settings in one request
488
491
  * This is a public endpoint that doesn't require authentication
489
492
  *
490
- * @returns Array of configured OAuth providers with their configuration status
493
+ * @returns Complete public authentication configuration including OAuth providers and email auth settings
491
494
  *
492
495
  * @example
493
496
  * ```ts
494
- * const { data, error } = await insforge.auth.getOAuthProviders();
497
+ * const { data, error } = await insforge.auth.getPublicAuthConfig();
495
498
  * if (data) {
496
- * // data is an array of PublicOAuthProvider: [{ provider: 'google', isConfigured: true }, ...]
497
- * data.forEach(p => console.log(`${p.provider}: ${p.isConfigured ? 'configured' : 'not configured'}`));
499
+ * console.log(`OAuth providers: ${data.oauth.data.length}`);
500
+ * console.log(`Password min length: ${data.email.passwordMinLength}`);
498
501
  * }
499
502
  * ```
500
503
  */
501
- async getOAuthProviders() {
504
+ async getPublicAuthConfig() {
502
505
  try {
503
- const response = await this.http.get("/api/auth/oauth/providers");
504
- return {
505
- data: response.data,
506
- error: null
507
- };
508
- } catch (error) {
509
- if (error instanceof InsForgeError) {
510
- return { data: null, error };
511
- }
512
- return {
513
- data: null,
514
- error: new InsForgeError(
515
- "An unexpected error occurred while fetching OAuth providers",
516
- 500,
517
- "UNEXPECTED_ERROR"
518
- )
519
- };
520
- }
521
- }
522
- /**
523
- * Get public email authentication configuration
524
- * Returns email authentication settings configured on the backend
525
- * This is a public endpoint that doesn't require authentication
526
- *
527
- * @returns Email authentication configuration including password requirements and email verification settings
528
- *
529
- * @example
530
- * ```ts
531
- * const { data, error } = await insforge.auth.getEmailAuthConfig();
532
- * if (data) {
533
- * console.log(`Password min length: ${data.passwordMinLength}`);
534
- * console.log(`Requires email verification: ${data.requireEmailVerification}`);
535
- * console.log(`Requires uppercase: ${data.requireUppercase}`);
536
- * }
537
- * ```
538
- */
539
- async getEmailAuthConfig() {
540
- try {
541
- const response = await this.http.get("/api/auth/email/public-config");
506
+ const response = await this.http.get("/api/auth/public-config");
542
507
  return {
543
508
  data: response,
544
509
  error: null
@@ -550,7 +515,7 @@ var Auth = class {
550
515
  return {
551
516
  data: null,
552
517
  error: new InsForgeError(
553
- "An unexpected error occurred while fetching email authentication configuration",
518
+ "An unexpected error occurred while fetching public authentication configuration",
554
519
  500,
555
520
  "UNEXPECTED_ERROR"
556
521
  )
@@ -559,7 +524,7 @@ var Auth = class {
559
524
  }
560
525
  /**
561
526
  * Get the current user with full profile information
562
- * Returns both auth info (id, email, role) and profile data (nickname, avatar_url, bio, etc.)
527
+ * Returns both auth info (id, email, role) and profile data (dynamic fields from users table)
563
528
  */
564
529
  async getCurrentUser() {
565
530
  try {
@@ -576,7 +541,7 @@ var Auth = class {
576
541
  return {
577
542
  data: {
578
543
  user: authResponse.user,
579
- profile: profile ? convertDbProfileToSchema(profile) : null
544
+ profile: profile ? convertDbProfileToCamelCase(profile) : null
580
545
  },
581
546
  error: null
582
547
  };
@@ -600,7 +565,7 @@ var Auth = class {
600
565
  }
601
566
  /**
602
567
  * Get any user's profile by ID
603
- * Returns profile information from the users table (nickname, avatarUrl, bio, etc.)
568
+ * Returns profile information from the users table (dynamic fields)
604
569
  */
605
570
  async getProfile(userId) {
606
571
  const { data, error } = await this.database.from("users").select("*").eq("id", userId).single();
@@ -608,7 +573,7 @@ var Auth = class {
608
573
  return { data: null, error: null };
609
574
  }
610
575
  if (data) {
611
- return { data: convertDbProfileToSchema(data), error: null };
576
+ return { data: convertDbProfileToCamelCase(data), error: null };
612
577
  }
613
578
  return { data: null, error };
614
579
  }
@@ -640,7 +605,7 @@ var Auth = class {
640
605
  }
641
606
  /**
642
607
  * Set/Update the current user's profile
643
- * Updates profile information in the users table (nickname, avatarUrl, bio, etc.)
608
+ * Updates profile information in the users table (supports any dynamic fields)
644
609
  */
645
610
  async setProfile(profile) {
646
611
  const session = this.tokenManager.getSession();
@@ -664,7 +629,7 @@ var Auth = class {
664
629
  id: data2.user.id,
665
630
  email: data2.user.email,
666
631
  name: data2.profile?.nickname || "",
667
- // Not available from API, but required by UserSchema
632
+ // Fallback - profile structure is dynamic
668
633
  emailVerified: false,
669
634
  // Not available from API, but required by UserSchema
670
635
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -675,13 +640,106 @@ var Auth = class {
675
640
  this.tokenManager.saveSession(session);
676
641
  }
677
642
  }
678
- const dbProfile = convertSchemaToDbProfile(profile);
643
+ const dbProfile = convertCamelCaseToDbProfile(profile);
679
644
  const { data, error } = await this.database.from("users").update(dbProfile).eq("id", session.user.id).select().single();
680
645
  if (data) {
681
- return { data: convertDbProfileToSchema(data), error: null };
646
+ return { data: convertDbProfileToCamelCase(data), error: null };
682
647
  }
683
648
  return { data: null, error };
684
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
+ }
685
743
  };
686
744
 
687
745
  // src/modules/storage.ts