@insforge/sdk 0.0.58-dev.8 → 0.0.58

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, GetPublicAuthConfigResponse, UserIdSchema, EmailSchema, RoleSchema, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest } from '@insforge/shared-schemas';
1
+ import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetPublicAuthConfigResponse, UserIdSchema, EmailSchema, RoleSchema, SendVerificationEmailRequest, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, VerifyEmailRequest, 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
 
@@ -131,7 +131,7 @@ declare class Auth {
131
131
  * This runs on initialization to seamlessly complete the OAuth flow
132
132
  * Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)
133
133
  */
134
- private detectOAuthCallback;
134
+ private detectAuthCallback;
135
135
  /**
136
136
  * Sign up a new user
137
137
  */
@@ -228,12 +228,28 @@ declare class Auth {
228
228
  error: any | null;
229
229
  }>;
230
230
  /**
231
- * Send password reset code to user's email
232
- * Always returns success to prevent user enumeration
231
+ * Send email verification (code or link based on config)
232
+ *
233
+ * Send email verification using the method configured in auth settings (verifyEmailMethod).
234
+ * When method is 'code', sends a 6-digit numeric code. When method is 'link', sends a magic link.
235
+ * Prevents user enumeration by returning success even if email doesn't exist.
233
236
  */
234
- sendPasswordResetCode(request: {
235
- email: string;
236
- }): Promise<{
237
+ sendVerificationEmail(request: SendVerificationEmailRequest): Promise<{
238
+ data: {
239
+ success: boolean;
240
+ message: string;
241
+ } | null;
242
+ error: InsForgeError | null;
243
+ }>;
244
+ /**
245
+ * Send password reset (code or link based on config)
246
+ *
247
+ * Send password reset email using the method configured in auth settings (resetPasswordMethod).
248
+ * When method is 'code', sends a 6-digit numeric code for two-step flow.
249
+ * When method is 'link', sends a magic link.
250
+ * Prevents user enumeration by returning success even if email doesn't exist.
251
+ */
252
+ sendResetPasswordEmail(request: SendResetPasswordEmailRequest): Promise<{
237
253
  data: {
238
254
  success: boolean;
239
255
  message: string;
@@ -241,8 +257,33 @@ declare class Auth {
241
257
  error: InsForgeError | null;
242
258
  }>;
243
259
  /**
244
- * Reset password with OTP token
245
- * Token can be from magic link or from code verification
260
+ * Exchange reset password code for reset token
261
+ *
262
+ * Step 1 of two-step password reset flow (only used when resetPasswordMethod is 'code'):
263
+ * 1. Verify the 6-digit code sent to user's email
264
+ * 2. Return a reset token that can be used to actually reset the password
265
+ *
266
+ * This endpoint is not used when resetPasswordMethod is 'link' (magic link flow is direct).
267
+ */
268
+ exchangeResetPasswordToken(request: ExchangeResetPasswordTokenRequest): Promise<{
269
+ data: {
270
+ token: string;
271
+ expiresAt: string;
272
+ } | null;
273
+ error: InsForgeError | null;
274
+ }>;
275
+ /**
276
+ * Reset password with token
277
+ *
278
+ * Reset user password with a token. The token can be:
279
+ * - Magic link token (64-character hex token from send-reset-password when method is 'link')
280
+ * - Reset token (from exchange-reset-password-token after code verification when method is 'code')
281
+ *
282
+ * Both token types use RESET_PASSWORD purpose and are verified the same way.
283
+ *
284
+ * Flow summary:
285
+ * - Code method: send-reset-password → exchange-reset-password-token → reset-password (with resetToken)
286
+ * - Link method: send-reset-password → reset-password (with link token directly)
246
287
  */
247
288
  resetPassword(request: {
248
289
  newPassword: string;
@@ -255,17 +296,23 @@ declare class Auth {
255
296
  error: InsForgeError | null;
256
297
  }>;
257
298
  /**
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)
299
+ * Verify email with code or link
300
+ *
301
+ * Verify email address using the method configured in auth settings (verifyEmailMethod):
302
+ * - Code verification: Provide both `email` and `otp` (6-digit numeric code)
303
+ * - Link verification: Provide only `otp` (64-character hex token from magic link)
304
+ *
305
+ * Successfully verified users will receive a session token.
306
+ *
307
+ * The email verification link sent to users always points to the backend API endpoint.
308
+ * If `verifyEmailRedirectTo` is configured, the backend will redirect to that URL after successful verification.
309
+ * Otherwise, a default success page is displayed.
261
310
  */
262
- verifyEmail(request: {
263
- email?: string;
264
- otp: string;
265
- }): Promise<{
311
+ verifyEmail(request: VerifyEmailRequest): Promise<{
266
312
  data: {
267
313
  accessToken: string;
268
314
  user?: any;
315
+ redirectTo?: string;
269
316
  } | null;
270
317
  error: InsForgeError | null;
271
318
  }>;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetPublicAuthConfigResponse, UserIdSchema, EmailSchema, RoleSchema, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest } from '@insforge/shared-schemas';
1
+ import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetPublicAuthConfigResponse, UserIdSchema, EmailSchema, RoleSchema, SendVerificationEmailRequest, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, VerifyEmailRequest, 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
 
@@ -131,7 +131,7 @@ declare class Auth {
131
131
  * This runs on initialization to seamlessly complete the OAuth flow
132
132
  * Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)
133
133
  */
134
- private detectOAuthCallback;
134
+ private detectAuthCallback;
135
135
  /**
136
136
  * Sign up a new user
137
137
  */
@@ -228,12 +228,28 @@ declare class Auth {
228
228
  error: any | null;
229
229
  }>;
230
230
  /**
231
- * Send password reset code to user's email
232
- * Always returns success to prevent user enumeration
231
+ * Send email verification (code or link based on config)
232
+ *
233
+ * Send email verification using the method configured in auth settings (verifyEmailMethod).
234
+ * When method is 'code', sends a 6-digit numeric code. When method is 'link', sends a magic link.
235
+ * Prevents user enumeration by returning success even if email doesn't exist.
233
236
  */
234
- sendPasswordResetCode(request: {
235
- email: string;
236
- }): Promise<{
237
+ sendVerificationEmail(request: SendVerificationEmailRequest): Promise<{
238
+ data: {
239
+ success: boolean;
240
+ message: string;
241
+ } | null;
242
+ error: InsForgeError | null;
243
+ }>;
244
+ /**
245
+ * Send password reset (code or link based on config)
246
+ *
247
+ * Send password reset email using the method configured in auth settings (resetPasswordMethod).
248
+ * When method is 'code', sends a 6-digit numeric code for two-step flow.
249
+ * When method is 'link', sends a magic link.
250
+ * Prevents user enumeration by returning success even if email doesn't exist.
251
+ */
252
+ sendResetPasswordEmail(request: SendResetPasswordEmailRequest): Promise<{
237
253
  data: {
238
254
  success: boolean;
239
255
  message: string;
@@ -241,8 +257,33 @@ declare class Auth {
241
257
  error: InsForgeError | null;
242
258
  }>;
243
259
  /**
244
- * Reset password with OTP token
245
- * Token can be from magic link or from code verification
260
+ * Exchange reset password code for reset token
261
+ *
262
+ * Step 1 of two-step password reset flow (only used when resetPasswordMethod is 'code'):
263
+ * 1. Verify the 6-digit code sent to user's email
264
+ * 2. Return a reset token that can be used to actually reset the password
265
+ *
266
+ * This endpoint is not used when resetPasswordMethod is 'link' (magic link flow is direct).
267
+ */
268
+ exchangeResetPasswordToken(request: ExchangeResetPasswordTokenRequest): Promise<{
269
+ data: {
270
+ token: string;
271
+ expiresAt: string;
272
+ } | null;
273
+ error: InsForgeError | null;
274
+ }>;
275
+ /**
276
+ * Reset password with token
277
+ *
278
+ * Reset user password with a token. The token can be:
279
+ * - Magic link token (64-character hex token from send-reset-password when method is 'link')
280
+ * - Reset token (from exchange-reset-password-token after code verification when method is 'code')
281
+ *
282
+ * Both token types use RESET_PASSWORD purpose and are verified the same way.
283
+ *
284
+ * Flow summary:
285
+ * - Code method: send-reset-password → exchange-reset-password-token → reset-password (with resetToken)
286
+ * - Link method: send-reset-password → reset-password (with link token directly)
246
287
  */
247
288
  resetPassword(request: {
248
289
  newPassword: string;
@@ -255,17 +296,23 @@ declare class Auth {
255
296
  error: InsForgeError | null;
256
297
  }>;
257
298
  /**
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)
299
+ * Verify email with code or link
300
+ *
301
+ * Verify email address using the method configured in auth settings (verifyEmailMethod):
302
+ * - Code verification: Provide both `email` and `otp` (6-digit numeric code)
303
+ * - Link verification: Provide only `otp` (64-character hex token from magic link)
304
+ *
305
+ * Successfully verified users will receive a session token.
306
+ *
307
+ * The email verification link sent to users always points to the backend API endpoint.
308
+ * If `verifyEmailRedirectTo` is configured, the backend will redirect to that URL after successful verification.
309
+ * Otherwise, a default success page is displayed.
261
310
  */
262
- verifyEmail(request: {
263
- email?: string;
264
- otp: string;
265
- }): Promise<{
311
+ verifyEmail(request: VerifyEmailRequest): Promise<{
266
312
  data: {
267
313
  accessToken: string;
268
314
  user?: any;
315
+ redirectTo?: string;
269
316
  } | null;
270
317
  error: InsForgeError | null;
271
318
  }>;
package/dist/index.js CHANGED
@@ -296,12 +296,12 @@ function convertDbProfileToCamelCase(dbProfile) {
296
296
  const result = {
297
297
  id: dbProfile.id
298
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
299
  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];
300
+ result[key] = dbProfile[key];
301
+ if (key.includes("_")) {
302
+ const camelKey = key.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
303
+ result[camelKey] = dbProfile[key];
304
+ }
305
305
  });
306
306
  return result;
307
307
  }
@@ -319,14 +319,14 @@ var Auth = class {
319
319
  this.http = http;
320
320
  this.tokenManager = tokenManager;
321
321
  this.database = new Database(http, tokenManager);
322
- this.detectOAuthCallback();
322
+ this.detectAuthCallback();
323
323
  }
324
324
  /**
325
325
  * Automatically detect and handle OAuth callback parameters in the URL
326
326
  * This runs on initialization to seamlessly complete the OAuth flow
327
327
  * Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)
328
328
  */
329
- detectOAuthCallback() {
329
+ detectAuthCallback() {
330
330
  if (typeof window === "undefined") return;
331
331
  try {
332
332
  const params = new URLSearchParams(window.location.search);
@@ -628,14 +628,10 @@ var Auth = class {
628
628
  session.user = {
629
629
  id: data2.user.id,
630
630
  email: data2.user.email,
631
- name: data2.profile?.nickname || "",
632
- // Fallback - profile structure is dynamic
631
+ name: "",
633
632
  emailVerified: false,
634
- // Not available from API, but required by UserSchema
635
633
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
636
- // Fallback
637
634
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
638
- // Fallback
639
635
  };
640
636
  this.tokenManager.saveSession(session);
641
637
  }
@@ -648,13 +644,48 @@ var Auth = class {
648
644
  return { data: null, error };
649
645
  }
650
646
  /**
651
- * Send password reset code to user's email
652
- * Always returns success to prevent user enumeration
647
+ * Send email verification (code or link based on config)
648
+ *
649
+ * Send email verification using the method configured in auth settings (verifyEmailMethod).
650
+ * When method is 'code', sends a 6-digit numeric code. When method is 'link', sends a magic link.
651
+ * Prevents user enumeration by returning success even if email doesn't exist.
653
652
  */
654
- async sendPasswordResetCode(request) {
653
+ async sendVerificationEmail(request) {
655
654
  try {
656
655
  const response = await this.http.post(
657
- "/api/auth/email/send-reset-password-code",
656
+ "/api/auth/email/send-verification",
657
+ request
658
+ );
659
+ return {
660
+ data: response,
661
+ error: null
662
+ };
663
+ } catch (error) {
664
+ if (error instanceof InsForgeError) {
665
+ return { data: null, error };
666
+ }
667
+ return {
668
+ data: null,
669
+ error: new InsForgeError(
670
+ "An unexpected error occurred while sending verification code",
671
+ 500,
672
+ "UNEXPECTED_ERROR"
673
+ )
674
+ };
675
+ }
676
+ }
677
+ /**
678
+ * Send password reset (code or link based on config)
679
+ *
680
+ * Send password reset email using the method configured in auth settings (resetPasswordMethod).
681
+ * When method is 'code', sends a 6-digit numeric code for two-step flow.
682
+ * When method is 'link', sends a magic link.
683
+ * Prevents user enumeration by returning success even if email doesn't exist.
684
+ */
685
+ async sendResetPasswordEmail(request) {
686
+ try {
687
+ const response = await this.http.post(
688
+ "/api/auth/email/send-reset-password",
658
689
  request
659
690
  );
660
691
  return {
@@ -676,13 +707,55 @@ var Auth = class {
676
707
  }
677
708
  }
678
709
  /**
679
- * Reset password with OTP token
680
- * Token can be from magic link or from code verification
710
+ * Exchange reset password code for reset token
711
+ *
712
+ * Step 1 of two-step password reset flow (only used when resetPasswordMethod is 'code'):
713
+ * 1. Verify the 6-digit code sent to user's email
714
+ * 2. Return a reset token that can be used to actually reset the password
715
+ *
716
+ * This endpoint is not used when resetPasswordMethod is 'link' (magic link flow is direct).
717
+ */
718
+ async exchangeResetPasswordToken(request) {
719
+ try {
720
+ const response = await this.http.post(
721
+ "/api/auth/email/exchange-reset-password-token",
722
+ request
723
+ );
724
+ return {
725
+ data: response,
726
+ error: null
727
+ };
728
+ } catch (error) {
729
+ if (error instanceof InsForgeError) {
730
+ return { data: null, error };
731
+ }
732
+ return {
733
+ data: null,
734
+ error: new InsForgeError(
735
+ "An unexpected error occurred while verifying reset code",
736
+ 500,
737
+ "UNEXPECTED_ERROR"
738
+ )
739
+ };
740
+ }
741
+ }
742
+ /**
743
+ * Reset password with token
744
+ *
745
+ * Reset user password with a token. The token can be:
746
+ * - Magic link token (64-character hex token from send-reset-password when method is 'link')
747
+ * - Reset token (from exchange-reset-password-token after code verification when method is 'code')
748
+ *
749
+ * Both token types use RESET_PASSWORD purpose and are verified the same way.
750
+ *
751
+ * Flow summary:
752
+ * - Code method: send-reset-password → exchange-reset-password-token → reset-password (with resetToken)
753
+ * - Link method: send-reset-password → reset-password (with link token directly)
681
754
  */
682
755
  async resetPassword(request) {
683
756
  try {
684
757
  const response = await this.http.post(
685
- "/api/auth/reset-password",
758
+ "/api/auth/email/reset-password",
686
759
  request
687
760
  );
688
761
  return {
@@ -704,14 +777,22 @@ var Auth = class {
704
777
  }
705
778
  }
706
779
  /**
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)
780
+ * Verify email with code or link
781
+ *
782
+ * Verify email address using the method configured in auth settings (verifyEmailMethod):
783
+ * - Code verification: Provide both `email` and `otp` (6-digit numeric code)
784
+ * - Link verification: Provide only `otp` (64-character hex token from magic link)
785
+ *
786
+ * Successfully verified users will receive a session token.
787
+ *
788
+ * The email verification link sent to users always points to the backend API endpoint.
789
+ * If `verifyEmailRedirectTo` is configured, the backend will redirect to that URL after successful verification.
790
+ * Otherwise, a default success page is displayed.
710
791
  */
711
792
  async verifyEmail(request) {
712
793
  try {
713
794
  const response = await this.http.post(
714
- "/api/auth/verify-email",
795
+ "/api/auth/email/verify",
715
796
  request
716
797
  );
717
798
  if (response.accessToken) {