@insforge/sdk 1.1.2-pkce.0 → 1.1.2-pkce.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, GetPublicAuthConfigResponse, GetProfileResponse, SendVerificationEmailRequest, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, VerifyEmailRequest, VerifyEmailResponse, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, SubscribeResponse, SocketMessage, SendRawEmailRequest, SendEmailResponse } from '@insforge/shared-schemas';
1
+ import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetProfileResponse, SendVerificationEmailRequest, VerifyEmailRequest, VerifyEmailResponse, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, GetPublicAuthConfigResponse, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, 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
 
@@ -160,44 +160,37 @@ declare class TokenManager {
160
160
 
161
161
  /**
162
162
  * Auth module for InsForge SDK
163
- * Uses shared schemas for type safety
163
+ * Handles authentication, sessions, profiles, and email verification
164
164
  */
165
165
 
166
166
  declare class Auth {
167
167
  private http;
168
168
  private tokenManager;
169
- /**
170
- * Promise that resolves when OAuth callback handling is complete.
171
- * Resolves immediately if no OAuth callback is detected in the URL.
172
- */
173
169
  private authCallbackHandled;
174
170
  constructor(http: HttpClient, tokenManager: TokenManager);
175
171
  /**
176
- * Automatically detect and handle OAuth callback parameters in the URL
177
- * This runs after initialization to seamlessly complete the OAuth flow
178
- *
179
- * Supports two flows:
180
- * - PKCE flow (new): Backend returns `insforge_code` param, exchanged for tokens
181
- * - Legacy flow: Backend returns tokens directly in URL (backward compatible)
172
+ * Save session from API response
173
+ * Handles token storage, CSRF token, and HTTP client auth header
182
174
  */
183
- private detectAuthCallback;
175
+ private saveSessionFromResponse;
184
176
  /**
185
- * Sign up a new user
177
+ * Detect and handle OAuth callback parameters in URL
178
+ * Supports PKCE flow (insforge_code) and legacy flow (access_token in URL)
186
179
  */
180
+ private detectAuthCallback;
187
181
  signUp(request: CreateUserRequest): Promise<{
188
182
  data: CreateUserResponse | null;
189
183
  error: InsForgeError | null;
190
184
  }>;
191
- /**
192
- * Sign in with email and password
193
- */
194
185
  signInWithPassword(request: CreateSessionRequest): Promise<{
195
186
  data: CreateSessionResponse | null;
196
187
  error: InsForgeError | null;
197
188
  }>;
189
+ signOut(): Promise<{
190
+ error: InsForgeError | null;
191
+ }>;
198
192
  /**
199
- * Sign in with OAuth provider
200
- * Uses PKCE (Proof Key for Code Exchange) for enhanced security
193
+ * Sign in with OAuth provider using PKCE flow
201
194
  */
202
195
  signInWithOAuth(options: {
203
196
  provider: OAuthProvidersSchema;
@@ -213,30 +206,7 @@ declare class Auth {
213
206
  }>;
214
207
  /**
215
208
  * Exchange OAuth authorization code for tokens (PKCE flow)
216
- *
217
- * After OAuth callback redirects with an `insforge_code` parameter, call this method
218
- * to exchange it for access tokens. The code verifier is automatically
219
- * retrieved from sessionStorage if available.
220
- *
221
- * Note: This is called automatically by the SDK on initialization. You typically
222
- * don't need to call this directly unless using `skipBrowserRedirect: true`.
223
- *
224
- * @param code - The authorization code from OAuth callback URL
225
- * @param codeVerifier - Optional code verifier (auto-retrieved from sessionStorage if not provided)
226
- * @returns Session data with access token and user info
227
- *
228
- * @example
229
- * ```ts
230
- * // Automatic verifier retrieval (recommended for browser)
231
- * const params = new URLSearchParams(window.location.search);
232
- * const code = params.get('insforge_code');
233
- * if (code) {
234
- * const { data, error } = await insforge.auth.exchangeOAuthCode(code);
235
- * }
236
- *
237
- * // Manual verifier (for custom flows)
238
- * const { data, error } = await insforge.auth.exchangeOAuthCode(code, codeVerifier);
239
- * ```
209
+ * Called automatically on initialization when insforge_code is in URL
240
210
  */
241
211
  exchangeOAuthCode(code: string, codeVerifier?: string): Promise<{
242
212
  data: {
@@ -247,43 +217,7 @@ declare class Auth {
247
217
  error: InsForgeError | null;
248
218
  }>;
249
219
  /**
250
- * Sign out the current user
251
- */
252
- signOut(): Promise<{
253
- error: InsForgeError | null;
254
- }>;
255
- /**
256
- * Get all public authentication configuration (OAuth + Email)
257
- * Returns both OAuth providers and email authentication settings in one request
258
- * This is a public endpoint that doesn't require authentication
259
- *
260
- * @returns Complete public authentication configuration including OAuth providers and email auth settings
261
- *
262
- * @example
263
- * ```ts
264
- * const { data, error } = await insforge.auth.getPublicAuthConfig();
265
- * if (data) {
266
- * console.log(`OAuth providers: ${data.oauth.data.length}`);
267
- * console.log(`Password min length: ${data.email.passwordMinLength}`);
268
- * }
269
- * ```
270
- */
271
- getPublicAuthConfig(): Promise<{
272
- data: GetPublicAuthConfigResponse | null;
273
- error: InsForgeError | null;
274
- }>;
275
- /**
276
- * Get any user's profile by ID
277
- * Returns profile information from the users table
278
- */
279
- getProfile(userId: string): Promise<{
280
- data: GetProfileResponse | null;
281
- error: InsForgeError | null;
282
- }>;
283
- /**
284
- * Get the current session (only session data, no API call)
285
- * Returns the stored JWT token and basic user info from local storage
286
- * Automatically waits for any pending OAuth callback to complete first
220
+ * Get current session, automatically waits for pending OAuth callback
287
221
  */
288
222
  getCurrentSession(): Promise<{
289
223
  data: {
@@ -291,23 +225,14 @@ declare class Auth {
291
225
  };
292
226
  error: InsForgeError | null;
293
227
  }>;
294
- /**
295
- * Set/Update the current user's profile
296
- * Updates profile information in the users table (supports any dynamic fields)
297
- * Requires authentication
298
- */
228
+ getProfile(userId: string): Promise<{
229
+ data: GetProfileResponse | null;
230
+ error: InsForgeError | null;
231
+ }>;
299
232
  setProfile(profile: Record<string, unknown>): Promise<{
300
233
  data: GetProfileResponse | null;
301
234
  error: InsForgeError | null;
302
235
  }>;
303
- /**
304
- * Resend email verification (code or link based on config)
305
- *
306
- * Resend email verification when the previous OTP has expired or was not received.
307
- * Uses the method configured in auth settings (verifyEmailMethod).
308
- * When method is 'code', sends a 6-digit numeric code. When method is 'link', sends a magic link.
309
- * Prevents user enumeration by returning success even if email doesn't exist.
310
- */
311
236
  resendVerificationEmail(request: SendVerificationEmailRequest): Promise<{
312
237
  data: {
313
238
  success: boolean;
@@ -315,9 +240,7 @@ declare class Auth {
315
240
  } | null;
316
241
  error: InsForgeError | null;
317
242
  }>;
318
- /**
319
- * @deprecated Use `resendVerificationEmail` instead. This method will be removed in a future version.
320
- */
243
+ /** @deprecated Use `resendVerificationEmail` instead */
321
244
  sendVerificationEmail(request: SendVerificationEmailRequest): Promise<{
322
245
  data: {
323
246
  success: boolean;
@@ -325,14 +248,10 @@ declare class Auth {
325
248
  } | null;
326
249
  error: InsForgeError | null;
327
250
  }>;
328
- /**
329
- * Send password reset (code or link based on config)
330
- *
331
- * Send password reset email using the method configured in auth settings (resetPasswordMethod).
332
- * When method is 'code', sends a 6-digit numeric code for two-step flow.
333
- * When method is 'link', sends a magic link.
334
- * Prevents user enumeration by returning success even if email doesn't exist.
335
- */
251
+ verifyEmail(request: VerifyEmailRequest): Promise<{
252
+ data: VerifyEmailResponse | null;
253
+ error: InsForgeError | null;
254
+ }>;
336
255
  sendResetPasswordEmail(request: SendResetPasswordEmailRequest): Promise<{
337
256
  data: {
338
257
  success: boolean;
@@ -340,15 +259,6 @@ declare class Auth {
340
259
  } | null;
341
260
  error: InsForgeError | null;
342
261
  }>;
343
- /**
344
- * Exchange reset password code for reset token
345
- *
346
- * Step 1 of two-step password reset flow (only used when resetPasswordMethod is 'code'):
347
- * 1. Verify the 6-digit code sent to user's email
348
- * 2. Return a reset token that can be used to actually reset the password
349
- *
350
- * This endpoint is not used when resetPasswordMethod is 'link' (magic link flow is direct).
351
- */
352
262
  exchangeResetPasswordToken(request: ExchangeResetPasswordTokenRequest): Promise<{
353
263
  data: {
354
264
  token: string;
@@ -356,19 +266,6 @@ declare class Auth {
356
266
  } | null;
357
267
  error: InsForgeError | null;
358
268
  }>;
359
- /**
360
- * Reset password with token
361
- *
362
- * Reset user password with a token. The token can be:
363
- * - Magic link token (64-character hex token from send-reset-password when method is 'link')
364
- * - Reset token (from exchange-reset-password-token after code verification when method is 'code')
365
- *
366
- * Both token types use RESET_PASSWORD purpose and are verified the same way.
367
- *
368
- * Flow summary:
369
- * - Code method: send-reset-password → exchange-reset-password-token → reset-password (with resetToken)
370
- * - Link method: send-reset-password → reset-password (with link token directly)
371
- */
372
269
  resetPassword(request: {
373
270
  newPassword: string;
374
271
  otp: string;
@@ -379,21 +276,8 @@ declare class Auth {
379
276
  } | null;
380
277
  error: InsForgeError | null;
381
278
  }>;
382
- /**
383
- * Verify email with code or link
384
- *
385
- * Verify email address using the method configured in auth settings (verifyEmailMethod):
386
- * - Code verification: Provide both `email` and `otp` (6-digit numeric code)
387
- * - Link verification: Provide only `otp` (64-character hex token from magic link)
388
- *
389
- * Successfully verified users will receive a session token.
390
- *
391
- * The email verification link sent to users always points to the backend API endpoint.
392
- * If `verifyEmailRedirectTo` is configured, the backend will redirect to that URL after successful verification.
393
- * Otherwise, a default success page is displayed.
394
- */
395
- verifyEmail(request: VerifyEmailRequest): Promise<{
396
- data: VerifyEmailResponse | null;
279
+ getPublicAuthConfig(): Promise<{
280
+ data: GetPublicAuthConfigResponse | null;
397
281
  error: InsForgeError | null;
398
282
  }>;
399
283
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetPublicAuthConfigResponse, GetProfileResponse, SendVerificationEmailRequest, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, VerifyEmailRequest, VerifyEmailResponse, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, SubscribeResponse, SocketMessage, SendRawEmailRequest, SendEmailResponse } from '@insforge/shared-schemas';
1
+ import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, GetProfileResponse, SendVerificationEmailRequest, VerifyEmailRequest, VerifyEmailResponse, SendResetPasswordEmailRequest, ExchangeResetPasswordTokenRequest, GetPublicAuthConfigResponse, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest, 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
 
@@ -160,44 +160,37 @@ declare class TokenManager {
160
160
 
161
161
  /**
162
162
  * Auth module for InsForge SDK
163
- * Uses shared schemas for type safety
163
+ * Handles authentication, sessions, profiles, and email verification
164
164
  */
165
165
 
166
166
  declare class Auth {
167
167
  private http;
168
168
  private tokenManager;
169
- /**
170
- * Promise that resolves when OAuth callback handling is complete.
171
- * Resolves immediately if no OAuth callback is detected in the URL.
172
- */
173
169
  private authCallbackHandled;
174
170
  constructor(http: HttpClient, tokenManager: TokenManager);
175
171
  /**
176
- * Automatically detect and handle OAuth callback parameters in the URL
177
- * This runs after initialization to seamlessly complete the OAuth flow
178
- *
179
- * Supports two flows:
180
- * - PKCE flow (new): Backend returns `insforge_code` param, exchanged for tokens
181
- * - Legacy flow: Backend returns tokens directly in URL (backward compatible)
172
+ * Save session from API response
173
+ * Handles token storage, CSRF token, and HTTP client auth header
182
174
  */
183
- private detectAuthCallback;
175
+ private saveSessionFromResponse;
184
176
  /**
185
- * Sign up a new user
177
+ * Detect and handle OAuth callback parameters in URL
178
+ * Supports PKCE flow (insforge_code) and legacy flow (access_token in URL)
186
179
  */
180
+ private detectAuthCallback;
187
181
  signUp(request: CreateUserRequest): Promise<{
188
182
  data: CreateUserResponse | null;
189
183
  error: InsForgeError | null;
190
184
  }>;
191
- /**
192
- * Sign in with email and password
193
- */
194
185
  signInWithPassword(request: CreateSessionRequest): Promise<{
195
186
  data: CreateSessionResponse | null;
196
187
  error: InsForgeError | null;
197
188
  }>;
189
+ signOut(): Promise<{
190
+ error: InsForgeError | null;
191
+ }>;
198
192
  /**
199
- * Sign in with OAuth provider
200
- * Uses PKCE (Proof Key for Code Exchange) for enhanced security
193
+ * Sign in with OAuth provider using PKCE flow
201
194
  */
202
195
  signInWithOAuth(options: {
203
196
  provider: OAuthProvidersSchema;
@@ -213,30 +206,7 @@ declare class Auth {
213
206
  }>;
214
207
  /**
215
208
  * Exchange OAuth authorization code for tokens (PKCE flow)
216
- *
217
- * After OAuth callback redirects with an `insforge_code` parameter, call this method
218
- * to exchange it for access tokens. The code verifier is automatically
219
- * retrieved from sessionStorage if available.
220
- *
221
- * Note: This is called automatically by the SDK on initialization. You typically
222
- * don't need to call this directly unless using `skipBrowserRedirect: true`.
223
- *
224
- * @param code - The authorization code from OAuth callback URL
225
- * @param codeVerifier - Optional code verifier (auto-retrieved from sessionStorage if not provided)
226
- * @returns Session data with access token and user info
227
- *
228
- * @example
229
- * ```ts
230
- * // Automatic verifier retrieval (recommended for browser)
231
- * const params = new URLSearchParams(window.location.search);
232
- * const code = params.get('insforge_code');
233
- * if (code) {
234
- * const { data, error } = await insforge.auth.exchangeOAuthCode(code);
235
- * }
236
- *
237
- * // Manual verifier (for custom flows)
238
- * const { data, error } = await insforge.auth.exchangeOAuthCode(code, codeVerifier);
239
- * ```
209
+ * Called automatically on initialization when insforge_code is in URL
240
210
  */
241
211
  exchangeOAuthCode(code: string, codeVerifier?: string): Promise<{
242
212
  data: {
@@ -247,43 +217,7 @@ declare class Auth {
247
217
  error: InsForgeError | null;
248
218
  }>;
249
219
  /**
250
- * Sign out the current user
251
- */
252
- signOut(): Promise<{
253
- error: InsForgeError | null;
254
- }>;
255
- /**
256
- * Get all public authentication configuration (OAuth + Email)
257
- * Returns both OAuth providers and email authentication settings in one request
258
- * This is a public endpoint that doesn't require authentication
259
- *
260
- * @returns Complete public authentication configuration including OAuth providers and email auth settings
261
- *
262
- * @example
263
- * ```ts
264
- * const { data, error } = await insforge.auth.getPublicAuthConfig();
265
- * if (data) {
266
- * console.log(`OAuth providers: ${data.oauth.data.length}`);
267
- * console.log(`Password min length: ${data.email.passwordMinLength}`);
268
- * }
269
- * ```
270
- */
271
- getPublicAuthConfig(): Promise<{
272
- data: GetPublicAuthConfigResponse | null;
273
- error: InsForgeError | null;
274
- }>;
275
- /**
276
- * Get any user's profile by ID
277
- * Returns profile information from the users table
278
- */
279
- getProfile(userId: string): Promise<{
280
- data: GetProfileResponse | null;
281
- error: InsForgeError | null;
282
- }>;
283
- /**
284
- * Get the current session (only session data, no API call)
285
- * Returns the stored JWT token and basic user info from local storage
286
- * Automatically waits for any pending OAuth callback to complete first
220
+ * Get current session, automatically waits for pending OAuth callback
287
221
  */
288
222
  getCurrentSession(): Promise<{
289
223
  data: {
@@ -291,23 +225,14 @@ declare class Auth {
291
225
  };
292
226
  error: InsForgeError | null;
293
227
  }>;
294
- /**
295
- * Set/Update the current user's profile
296
- * Updates profile information in the users table (supports any dynamic fields)
297
- * Requires authentication
298
- */
228
+ getProfile(userId: string): Promise<{
229
+ data: GetProfileResponse | null;
230
+ error: InsForgeError | null;
231
+ }>;
299
232
  setProfile(profile: Record<string, unknown>): Promise<{
300
233
  data: GetProfileResponse | null;
301
234
  error: InsForgeError | null;
302
235
  }>;
303
- /**
304
- * Resend email verification (code or link based on config)
305
- *
306
- * Resend email verification when the previous OTP has expired or was not received.
307
- * Uses the method configured in auth settings (verifyEmailMethod).
308
- * When method is 'code', sends a 6-digit numeric code. When method is 'link', sends a magic link.
309
- * Prevents user enumeration by returning success even if email doesn't exist.
310
- */
311
236
  resendVerificationEmail(request: SendVerificationEmailRequest): Promise<{
312
237
  data: {
313
238
  success: boolean;
@@ -315,9 +240,7 @@ declare class Auth {
315
240
  } | null;
316
241
  error: InsForgeError | null;
317
242
  }>;
318
- /**
319
- * @deprecated Use `resendVerificationEmail` instead. This method will be removed in a future version.
320
- */
243
+ /** @deprecated Use `resendVerificationEmail` instead */
321
244
  sendVerificationEmail(request: SendVerificationEmailRequest): Promise<{
322
245
  data: {
323
246
  success: boolean;
@@ -325,14 +248,10 @@ declare class Auth {
325
248
  } | null;
326
249
  error: InsForgeError | null;
327
250
  }>;
328
- /**
329
- * Send password reset (code or link based on config)
330
- *
331
- * Send password reset email using the method configured in auth settings (resetPasswordMethod).
332
- * When method is 'code', sends a 6-digit numeric code for two-step flow.
333
- * When method is 'link', sends a magic link.
334
- * Prevents user enumeration by returning success even if email doesn't exist.
335
- */
251
+ verifyEmail(request: VerifyEmailRequest): Promise<{
252
+ data: VerifyEmailResponse | null;
253
+ error: InsForgeError | null;
254
+ }>;
336
255
  sendResetPasswordEmail(request: SendResetPasswordEmailRequest): Promise<{
337
256
  data: {
338
257
  success: boolean;
@@ -340,15 +259,6 @@ declare class Auth {
340
259
  } | null;
341
260
  error: InsForgeError | null;
342
261
  }>;
343
- /**
344
- * Exchange reset password code for reset token
345
- *
346
- * Step 1 of two-step password reset flow (only used when resetPasswordMethod is 'code'):
347
- * 1. Verify the 6-digit code sent to user's email
348
- * 2. Return a reset token that can be used to actually reset the password
349
- *
350
- * This endpoint is not used when resetPasswordMethod is 'link' (magic link flow is direct).
351
- */
352
262
  exchangeResetPasswordToken(request: ExchangeResetPasswordTokenRequest): Promise<{
353
263
  data: {
354
264
  token: string;
@@ -356,19 +266,6 @@ declare class Auth {
356
266
  } | null;
357
267
  error: InsForgeError | null;
358
268
  }>;
359
- /**
360
- * Reset password with token
361
- *
362
- * Reset user password with a token. The token can be:
363
- * - Magic link token (64-character hex token from send-reset-password when method is 'link')
364
- * - Reset token (from exchange-reset-password-token after code verification when method is 'code')
365
- *
366
- * Both token types use RESET_PASSWORD purpose and are verified the same way.
367
- *
368
- * Flow summary:
369
- * - Code method: send-reset-password → exchange-reset-password-token → reset-password (with resetToken)
370
- * - Link method: send-reset-password → reset-password (with link token directly)
371
- */
372
269
  resetPassword(request: {
373
270
  newPassword: string;
374
271
  otp: string;
@@ -379,21 +276,8 @@ declare class Auth {
379
276
  } | null;
380
277
  error: InsForgeError | null;
381
278
  }>;
382
- /**
383
- * Verify email with code or link
384
- *
385
- * Verify email address using the method configured in auth settings (verifyEmailMethod):
386
- * - Code verification: Provide both `email` and `otp` (6-digit numeric code)
387
- * - Link verification: Provide only `otp` (64-character hex token from magic link)
388
- *
389
- * Successfully verified users will receive a session token.
390
- *
391
- * The email verification link sent to users always points to the backend API endpoint.
392
- * If `verifyEmailRedirectTo` is configured, the backend will redirect to that URL after successful verification.
393
- * Otherwise, a default success page is displayed.
394
- */
395
- verifyEmail(request: VerifyEmailRequest): Promise<{
396
- data: VerifyEmailResponse | null;
279
+ getPublicAuthConfig(): Promise<{
280
+ data: GetPublicAuthConfigResponse | null;
397
281
  error: InsForgeError | null;
398
282
  }>;
399
283
  }