@insforge/sdk 0.0.58-dev.4 → 0.0.58-dev.6

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.mjs CHANGED
@@ -255,23 +255,26 @@ var Database = class {
255
255
  };
256
256
 
257
257
  // src/modules/auth.ts
258
- function convertDbProfileToSchema(dbProfile) {
259
- return {
260
- id: dbProfile.id,
261
- nickname: dbProfile.nickname,
262
- avatarUrl: dbProfile.avatar_url,
263
- bio: dbProfile.bio,
264
- birthday: dbProfile.birthday,
265
- createdAt: dbProfile.created_at,
266
- updatedAt: dbProfile.updated_at
258
+ function convertDbProfileToCamelCase(dbProfile) {
259
+ const result = {
260
+ id: dbProfile.id
267
261
  };
262
+ if (dbProfile.created_at !== void 0) result.createdAt = dbProfile.created_at;
263
+ if (dbProfile.updated_at !== void 0) result.updatedAt = dbProfile.updated_at;
264
+ Object.keys(dbProfile).forEach((key) => {
265
+ if (key === "id" || key === "created_at" || key === "updated_at") return;
266
+ const camelKey = key.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
267
+ result[camelKey] = dbProfile[key];
268
+ });
269
+ return result;
268
270
  }
269
- function convertSchemaToDbProfile(profile) {
271
+ function convertCamelCaseToDbProfile(profile) {
270
272
  const dbProfile = {};
271
- if (profile.nickname !== void 0) dbProfile.nickname = profile.nickname;
272
- if (profile.avatarUrl !== void 0) dbProfile.avatar_url = profile.avatarUrl;
273
- if (profile.bio !== void 0) dbProfile.bio = profile.bio;
274
- if (profile.birthday !== void 0) dbProfile.birthday = profile.birthday;
273
+ Object.keys(profile).forEach((key) => {
274
+ if (profile[key] === void 0) return;
275
+ const snakeKey = key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
276
+ dbProfile[snakeKey] = profile[key];
277
+ });
275
278
  return dbProfile;
276
279
  }
277
280
  var Auth = class {
@@ -446,62 +449,24 @@ var Auth = class {
446
449
  }
447
450
  }
448
451
  /**
449
- * Get list of available OAuth providers
450
- * Returns the list of OAuth providers configured on the backend
452
+ * Get all public authentication configuration (OAuth + Email)
453
+ * Returns both OAuth providers and email authentication settings in one request
451
454
  * This is a public endpoint that doesn't require authentication
452
455
  *
453
- * @returns Array of configured OAuth providers with their configuration status
456
+ * @returns Complete public authentication configuration including OAuth providers and email auth settings
454
457
  *
455
458
  * @example
456
459
  * ```ts
457
- * const { data, error } = await insforge.auth.getOAuthProviders();
460
+ * const { data, error } = await insforge.auth.getPublicAuthConfig();
458
461
  * if (data) {
459
- * // data is an array of PublicOAuthProvider: [{ provider: 'google', isConfigured: true }, ...]
460
- * data.forEach(p => console.log(`${p.provider}: ${p.isConfigured ? 'configured' : 'not configured'}`));
462
+ * console.log(`OAuth providers: ${data.oauth.data.length}`);
463
+ * console.log(`Password min length: ${data.email.passwordMinLength}`);
461
464
  * }
462
465
  * ```
463
466
  */
464
- async getOAuthProviders() {
467
+ async getPublicAuthConfig() {
465
468
  try {
466
- const response = await this.http.get("/api/auth/oauth/providers");
467
- return {
468
- data: response.data,
469
- error: null
470
- };
471
- } catch (error) {
472
- if (error instanceof InsForgeError) {
473
- return { data: null, error };
474
- }
475
- return {
476
- data: null,
477
- error: new InsForgeError(
478
- "An unexpected error occurred while fetching OAuth providers",
479
- 500,
480
- "UNEXPECTED_ERROR"
481
- )
482
- };
483
- }
484
- }
485
- /**
486
- * Get public email authentication configuration
487
- * Returns email authentication settings configured on the backend
488
- * This is a public endpoint that doesn't require authentication
489
- *
490
- * @returns Email authentication configuration including password requirements and email verification settings
491
- *
492
- * @example
493
- * ```ts
494
- * const { data, error } = await insforge.auth.getEmailAuthConfig();
495
- * if (data) {
496
- * console.log(`Password min length: ${data.passwordMinLength}`);
497
- * console.log(`Requires email verification: ${data.requireEmailVerification}`);
498
- * console.log(`Requires uppercase: ${data.requireUppercase}`);
499
- * }
500
- * ```
501
- */
502
- async getEmailAuthConfig() {
503
- try {
504
- const response = await this.http.get("/api/auth/email/public-config");
469
+ const response = await this.http.get("/api/auth/public-config");
505
470
  return {
506
471
  data: response,
507
472
  error: null
@@ -513,7 +478,7 @@ var Auth = class {
513
478
  return {
514
479
  data: null,
515
480
  error: new InsForgeError(
516
- "An unexpected error occurred while fetching email authentication configuration",
481
+ "An unexpected error occurred while fetching public authentication configuration",
517
482
  500,
518
483
  "UNEXPECTED_ERROR"
519
484
  )
@@ -522,7 +487,7 @@ var Auth = class {
522
487
  }
523
488
  /**
524
489
  * Get the current user with full profile information
525
- * Returns both auth info (id, email, role) and profile data (nickname, avatar_url, bio, etc.)
490
+ * Returns both auth info (id, email, role) and profile data (dynamic fields from users table)
526
491
  */
527
492
  async getCurrentUser() {
528
493
  try {
@@ -539,7 +504,7 @@ var Auth = class {
539
504
  return {
540
505
  data: {
541
506
  user: authResponse.user,
542
- profile: profile ? convertDbProfileToSchema(profile) : null
507
+ profile: profile ? convertDbProfileToCamelCase(profile) : null
543
508
  },
544
509
  error: null
545
510
  };
@@ -563,7 +528,7 @@ var Auth = class {
563
528
  }
564
529
  /**
565
530
  * Get any user's profile by ID
566
- * Returns profile information from the users table (nickname, avatarUrl, bio, etc.)
531
+ * Returns profile information from the users table (dynamic fields)
567
532
  */
568
533
  async getProfile(userId) {
569
534
  const { data, error } = await this.database.from("users").select("*").eq("id", userId).single();
@@ -571,7 +536,7 @@ var Auth = class {
571
536
  return { data: null, error: null };
572
537
  }
573
538
  if (data) {
574
- return { data: convertDbProfileToSchema(data), error: null };
539
+ return { data: convertDbProfileToCamelCase(data), error: null };
575
540
  }
576
541
  return { data: null, error };
577
542
  }
@@ -603,7 +568,7 @@ var Auth = class {
603
568
  }
604
569
  /**
605
570
  * Set/Update the current user's profile
606
- * Updates profile information in the users table (nickname, avatarUrl, bio, etc.)
571
+ * Updates profile information in the users table (supports any dynamic fields)
607
572
  */
608
573
  async setProfile(profile) {
609
574
  const session = this.tokenManager.getSession();
@@ -627,7 +592,7 @@ var Auth = class {
627
592
  id: data2.user.id,
628
593
  email: data2.user.email,
629
594
  name: data2.profile?.nickname || "",
630
- // Not available from API, but required by UserSchema
595
+ // Fallback - profile structure is dynamic
631
596
  emailVerified: false,
632
597
  // Not available from API, but required by UserSchema
633
598
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -638,13 +603,106 @@ var Auth = class {
638
603
  this.tokenManager.saveSession(session);
639
604
  }
640
605
  }
641
- const dbProfile = convertSchemaToDbProfile(profile);
606
+ const dbProfile = convertCamelCaseToDbProfile(profile);
642
607
  const { data, error } = await this.database.from("users").update(dbProfile).eq("id", session.user.id).select().single();
643
608
  if (data) {
644
- return { data: convertDbProfileToSchema(data), error: null };
609
+ return { data: convertDbProfileToCamelCase(data), error: null };
645
610
  }
646
611
  return { data: null, error };
647
612
  }
613
+ /**
614
+ * Send password reset code to user's email
615
+ * Always returns success to prevent user enumeration
616
+ */
617
+ async sendPasswordResetCode(request) {
618
+ try {
619
+ const response = await this.http.post(
620
+ "/api/auth/email/send-reset-password-code",
621
+ request
622
+ );
623
+ return {
624
+ data: response,
625
+ error: null
626
+ };
627
+ } catch (error) {
628
+ if (error instanceof InsForgeError) {
629
+ return { data: null, error };
630
+ }
631
+ return {
632
+ data: null,
633
+ error: new InsForgeError(
634
+ "An unexpected error occurred while sending password reset code",
635
+ 500,
636
+ "UNEXPECTED_ERROR"
637
+ )
638
+ };
639
+ }
640
+ }
641
+ /**
642
+ * Reset password with OTP token
643
+ * Token can be from magic link or from code verification
644
+ */
645
+ async resetPassword(request) {
646
+ try {
647
+ const response = await this.http.post(
648
+ "/api/auth/reset-password",
649
+ request
650
+ );
651
+ return {
652
+ data: response,
653
+ error: null
654
+ };
655
+ } catch (error) {
656
+ if (error instanceof InsForgeError) {
657
+ return { data: null, error };
658
+ }
659
+ return {
660
+ data: null,
661
+ error: new InsForgeError(
662
+ "An unexpected error occurred while resetting password",
663
+ 500,
664
+ "UNEXPECTED_ERROR"
665
+ )
666
+ };
667
+ }
668
+ }
669
+ /**
670
+ * Verify email with OTP token
671
+ * If email is provided: uses numeric OTP verification (6-digit code)
672
+ * If email is NOT provided: uses link OTP verification (64-char token)
673
+ */
674
+ async verifyEmail(request) {
675
+ try {
676
+ const response = await this.http.post(
677
+ "/api/auth/verify-email",
678
+ request
679
+ );
680
+ if (response.accessToken) {
681
+ const session = {
682
+ accessToken: response.accessToken,
683
+ user: response.user || {}
684
+ };
685
+ this.tokenManager.saveSession(session);
686
+ this.http.setAuthToken(response.accessToken);
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 verifying email",
700
+ 500,
701
+ "UNEXPECTED_ERROR"
702
+ )
703
+ };
704
+ }
705
+ }
648
706
  };
649
707
 
650
708
  // src/modules/storage.ts