@insforge/sdk 1.2.0-dev.0 → 1.2.0-dev.1

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, GetProfileResponse, SendVerificationEmailRequest, VerifyEmailRequest, VerifyEmailResponse, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, GetPublicAuthConfigResponse, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, EmbeddingsRequest, SubscribeResponse, SocketMessage, SendRawEmailRequest, SendEmailResponse } from '@insforge/shared-schemas';
1
+ import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, RefreshSessionResponse, GetProfileResponse, SendVerificationEmailRequest, VerifyEmailRequest, VerifyEmailResponse, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, GetPublicAuthConfigResponse, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, EmbeddingsRequest, SubscribeResponse, SocketMessage, SendRawEmailRequest, SendEmailResponse } from '@insforge/shared-schemas';
2
2
  export { AuthErrorResponse, CreateSessionRequest, CreateUserRequest, RealtimeErrorPayload, SendRawEmailRequest as SendEmailOptions, SendEmailResponse, SocketMessage, SubscribeResponse, UserSchema } from '@insforge/shared-schemas';
3
3
  import * as _supabase_postgrest_js from '@supabase/postgrest-js';
4
4
 
@@ -209,6 +209,21 @@ declare class Auth {
209
209
  } | null;
210
210
  error: InsForgeError | null;
211
211
  }>;
212
+ /**
213
+ * Refresh the current auth session.
214
+ *
215
+ * Browser mode:
216
+ * - Uses httpOnly refresh cookie and optional CSRF header.
217
+ *
218
+ * Server mode (`isServerMode: true`):
219
+ * - Uses mobile auth flow and requires `refreshToken` in request body.
220
+ */
221
+ refreshSession(options?: {
222
+ refreshToken?: string;
223
+ }): Promise<{
224
+ data: RefreshSessionResponse | null;
225
+ error: InsForgeError | null;
226
+ }>;
212
227
  /**
213
228
  * Get current user, automatically waits for pending OAuth callback
214
229
  */
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetProfileResponse, SendVerificationEmailRequest, VerifyEmailRequest, VerifyEmailResponse, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, GetPublicAuthConfigResponse, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, EmbeddingsRequest, SubscribeResponse, SocketMessage, SendRawEmailRequest, SendEmailResponse } from '@insforge/shared-schemas';
1
+ import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, RefreshSessionResponse, GetProfileResponse, SendVerificationEmailRequest, VerifyEmailRequest, VerifyEmailResponse, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, GetPublicAuthConfigResponse, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, EmbeddingsRequest, SubscribeResponse, SocketMessage, SendRawEmailRequest, SendEmailResponse } from '@insforge/shared-schemas';
2
2
  export { AuthErrorResponse, CreateSessionRequest, CreateUserRequest, RealtimeErrorPayload, SendRawEmailRequest as SendEmailOptions, SendEmailResponse, SocketMessage, SubscribeResponse, UserSchema } from '@insforge/shared-schemas';
3
3
  import * as _supabase_postgrest_js from '@supabase/postgrest-js';
4
4
 
@@ -209,6 +209,21 @@ declare class Auth {
209
209
  } | null;
210
210
  error: InsForgeError | null;
211
211
  }>;
212
+ /**
213
+ * Refresh the current auth session.
214
+ *
215
+ * Browser mode:
216
+ * - Uses httpOnly refresh cookie and optional CSRF header.
217
+ *
218
+ * Server mode (`isServerMode: true`):
219
+ * - Uses mobile auth flow and requires `refreshToken` in request body.
220
+ */
221
+ refreshSession(options?: {
222
+ refreshToken?: string;
223
+ }): Promise<{
224
+ data: RefreshSessionResponse | null;
225
+ error: InsForgeError | null;
226
+ }>;
212
227
  /**
213
228
  * Get current user, automatically waits for pending OAuth callback
214
229
  */
package/dist/index.js CHANGED
@@ -560,6 +560,44 @@ var Auth = class {
560
560
  // ============================================================================
561
561
  // Session Management
562
562
  // ============================================================================
563
+ /**
564
+ * Refresh the current auth session.
565
+ *
566
+ * Browser mode:
567
+ * - Uses httpOnly refresh cookie and optional CSRF header.
568
+ *
569
+ * Server mode (`isServerMode: true`):
570
+ * - Uses mobile auth flow and requires `refreshToken` in request body.
571
+ */
572
+ async refreshSession(options) {
573
+ try {
574
+ if (this.isServerMode() && !options?.refreshToken) {
575
+ return {
576
+ data: null,
577
+ error: new InsForgeError(
578
+ "refreshToken is required when refreshing session in server mode",
579
+ 400,
580
+ "REFRESH_TOKEN_REQUIRED"
581
+ )
582
+ };
583
+ }
584
+ const csrfToken = !this.isServerMode() ? getCsrfToken() : null;
585
+ const response = await this.http.post(
586
+ this.isServerMode() ? "/api/auth/refresh?client_type=mobile" : "/api/auth/refresh",
587
+ this.isServerMode() ? { refreshToken: options?.refreshToken } : void 0,
588
+ {
589
+ headers: csrfToken ? { "X-CSRF-Token": csrfToken } : {},
590
+ credentials: "include"
591
+ }
592
+ );
593
+ if (response.accessToken) {
594
+ this.saveSessionFromResponse(response);
595
+ }
596
+ return { data: response, error: null };
597
+ } catch (error) {
598
+ return wrapError(error, "An unexpected error occurred during session refresh");
599
+ }
600
+ }
563
601
  /**
564
602
  * Get current user, automatically waits for pending OAuth callback
565
603
  */
@@ -580,20 +618,12 @@ var Auth = class {
580
618
  return { data: { user: session.user }, error: null };
581
619
  }
582
620
  if (typeof window !== "undefined") {
583
- try {
584
- const csrfToken = getCsrfToken();
585
- const response = await this.http.post("/api/auth/refresh", void 0, {
586
- headers: csrfToken ? { "X-CSRF-Token": csrfToken } : {},
587
- credentials: "include"
588
- });
589
- if (response.accessToken) {
590
- this.saveSessionFromResponse(response);
591
- return { data: { user: response.user ?? null }, error: null };
592
- }
593
- } catch (error) {
594
- if (error instanceof InsForgeError) {
595
- return { data: { user: null }, error };
596
- }
621
+ const { data: refreshed, error: refreshError } = await this.refreshSession();
622
+ if (refreshError) {
623
+ return { data: { user: null }, error: refreshError };
624
+ }
625
+ if (refreshed?.accessToken) {
626
+ return { data: { user: refreshed.user ?? null }, error: null };
597
627
  }
598
628
  }
599
629
  return { data: { user: null }, error: null };