@insforge/sdk 0.0.58-dev.12 → 0.0.58-dev.14

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.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,13 @@ declare class Auth {
228
228
  error: any | null;
229
229
  }>;
230
230
  /**
231
- * Send email verification code
232
- * Creates a 6-digit OTP and sends it via email for manual entry
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
- sendVerificationCode(request: {
235
- email: string;
236
- }): Promise<{
237
+ sendVerificationEmail(request: SendVerificationEmailRequest): Promise<{
237
238
  data: {
238
239
  success: boolean;
239
240
  message: string;
@@ -241,12 +242,14 @@ declare class Auth {
241
242
  error: InsForgeError | null;
242
243
  }>;
243
244
  /**
244
- * Send email verification link
245
- * Creates a magic link token and sends it via email
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.
246
251
  */
247
- sendVerificationLink(request: {
248
- email: string;
249
- }): Promise<{
252
+ sendResetPasswordEmail(request: SendResetPasswordEmailRequest): Promise<{
250
253
  data: {
251
254
  success: boolean;
252
255
  message: string;
@@ -254,21 +257,33 @@ declare class Auth {
254
257
  error: InsForgeError | null;
255
258
  }>;
256
259
  /**
257
- * Send password reset code to user's email
258
- * Always returns success to prevent user enumeration
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).
259
267
  */
260
- sendPasswordResetCode(request: {
261
- email: string;
262
- }): Promise<{
268
+ exchangeResetPasswordToken(request: ExchangeResetPasswordTokenRequest): Promise<{
263
269
  data: {
264
- success: boolean;
265
- message: string;
270
+ token: string;
271
+ expiresAt: string;
266
272
  } | null;
267
273
  error: InsForgeError | null;
268
274
  }>;
269
275
  /**
270
- * Reset password with OTP token
271
- * Token can be from magic link or from code verification
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)
272
287
  */
273
288
  resetPassword(request: {
274
289
  newPassword: string;
@@ -281,17 +296,23 @@ declare class Auth {
281
296
  error: InsForgeError | null;
282
297
  }>;
283
298
  /**
284
- * Verify email with OTP token
285
- * If email is provided: uses numeric OTP verification (6-digit code)
286
- * 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.
287
310
  */
288
- verifyEmail(request: {
289
- email?: string;
290
- otp: string;
291
- }): Promise<{
311
+ verifyEmail(request: VerifyEmailRequest): Promise<{
292
312
  data: {
293
313
  accessToken: string;
294
314
  user?: any;
315
+ redirectTo?: string;
295
316
  } | null;
296
317
  error: InsForgeError | null;
297
318
  }>;
package/dist/index.js CHANGED
@@ -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);
@@ -648,13 +648,16 @@ var Auth = class {
648
648
  return { data: null, error };
649
649
  }
650
650
  /**
651
- * Send email verification code
652
- * Creates a 6-digit OTP and sends it via email for manual entry
651
+ * Send email verification (code or link based on config)
652
+ *
653
+ * Send email verification using the method configured in auth settings (verifyEmailMethod).
654
+ * When method is 'code', sends a 6-digit numeric code. When method is 'link', sends a magic link.
655
+ * Prevents user enumeration by returning success even if email doesn't exist.
653
656
  */
654
- async sendVerificationCode(request) {
657
+ async sendVerificationEmail(request) {
655
658
  try {
656
659
  const response = await this.http.post(
657
- "/api/auth/email/send-verification-code",
660
+ "/api/auth/email/send-verification",
658
661
  request
659
662
  );
660
663
  return {
@@ -676,13 +679,17 @@ var Auth = class {
676
679
  }
677
680
  }
678
681
  /**
679
- * Send email verification link
680
- * Creates a magic link token and sends it via email
682
+ * Send password reset (code or link based on config)
683
+ *
684
+ * Send password reset email using the method configured in auth settings (resetPasswordMethod).
685
+ * When method is 'code', sends a 6-digit numeric code for two-step flow.
686
+ * When method is 'link', sends a magic link.
687
+ * Prevents user enumeration by returning success even if email doesn't exist.
681
688
  */
682
- async sendVerificationLink(request) {
689
+ async sendResetPasswordEmail(request) {
683
690
  try {
684
691
  const response = await this.http.post(
685
- "/api/auth/email/send-verification-link",
692
+ "/api/auth/email/send-reset-password",
686
693
  request
687
694
  );
688
695
  return {
@@ -696,7 +703,7 @@ var Auth = class {
696
703
  return {
697
704
  data: null,
698
705
  error: new InsForgeError(
699
- "An unexpected error occurred while sending verification link",
706
+ "An unexpected error occurred while sending password reset code",
700
707
  500,
701
708
  "UNEXPECTED_ERROR"
702
709
  )
@@ -704,13 +711,18 @@ var Auth = class {
704
711
  }
705
712
  }
706
713
  /**
707
- * Send password reset code to user's email
708
- * Always returns success to prevent user enumeration
714
+ * Exchange reset password code for reset token
715
+ *
716
+ * Step 1 of two-step password reset flow (only used when resetPasswordMethod is 'code'):
717
+ * 1. Verify the 6-digit code sent to user's email
718
+ * 2. Return a reset token that can be used to actually reset the password
719
+ *
720
+ * This endpoint is not used when resetPasswordMethod is 'link' (magic link flow is direct).
709
721
  */
710
- async sendPasswordResetCode(request) {
722
+ async exchangeResetPasswordToken(request) {
711
723
  try {
712
724
  const response = await this.http.post(
713
- "/api/auth/email/send-reset-password-code",
725
+ "/api/auth/email/exchange-reset-password-token",
714
726
  request
715
727
  );
716
728
  return {
@@ -724,7 +736,7 @@ var Auth = class {
724
736
  return {
725
737
  data: null,
726
738
  error: new InsForgeError(
727
- "An unexpected error occurred while sending password reset code",
739
+ "An unexpected error occurred while verifying reset code",
728
740
  500,
729
741
  "UNEXPECTED_ERROR"
730
742
  )
@@ -732,13 +744,22 @@ var Auth = class {
732
744
  }
733
745
  }
734
746
  /**
735
- * Reset password with OTP token
736
- * Token can be from magic link or from code verification
747
+ * Reset password with token
748
+ *
749
+ * Reset user password with a token. The token can be:
750
+ * - Magic link token (64-character hex token from send-reset-password when method is 'link')
751
+ * - Reset token (from exchange-reset-password-token after code verification when method is 'code')
752
+ *
753
+ * Both token types use RESET_PASSWORD purpose and are verified the same way.
754
+ *
755
+ * Flow summary:
756
+ * - Code method: send-reset-password → exchange-reset-password-token → reset-password (with resetToken)
757
+ * - Link method: send-reset-password → reset-password (with link token directly)
737
758
  */
738
759
  async resetPassword(request) {
739
760
  try {
740
761
  const response = await this.http.post(
741
- "/api/auth/reset-password",
762
+ "/api/auth/email/reset-password",
742
763
  request
743
764
  );
744
765
  return {
@@ -760,14 +781,22 @@ var Auth = class {
760
781
  }
761
782
  }
762
783
  /**
763
- * Verify email with OTP token
764
- * If email is provided: uses numeric OTP verification (6-digit code)
765
- * If email is NOT provided: uses link OTP verification (64-char token)
784
+ * Verify email with code or link
785
+ *
786
+ * Verify email address using the method configured in auth settings (verifyEmailMethod):
787
+ * - Code verification: Provide both `email` and `otp` (6-digit numeric code)
788
+ * - Link verification: Provide only `otp` (64-character hex token from magic link)
789
+ *
790
+ * Successfully verified users will receive a session token.
791
+ *
792
+ * The email verification link sent to users always points to the backend API endpoint.
793
+ * If `verifyEmailRedirectTo` is configured, the backend will redirect to that URL after successful verification.
794
+ * Otherwise, a default success page is displayed.
766
795
  */
767
796
  async verifyEmail(request) {
768
797
  try {
769
798
  const response = await this.http.post(
770
- "/api/auth/verify-email",
799
+ "/api/auth/email/verify",
771
800
  request
772
801
  );
773
802
  if (response.accessToken) {