@fluxbase/sdk 0.0.1-rc.28 → 0.0.1-rc.30

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.cjs CHANGED
@@ -210,8 +210,8 @@ var FluxbaseAuth = class {
210
210
  return { data: { subscription } };
211
211
  }
212
212
  /**
213
- * Sign in with email and password
214
- * Returns AuthSession if successful, or SignInWith2FAResponse if 2FA is required
213
+ * Sign in with email and password (Supabase-compatible)
214
+ * Returns { user, session } if successful, or SignInWith2FAResponse if 2FA is required
215
215
  */
216
216
  async signIn(credentials) {
217
217
  return wrapAsync(async () => {
@@ -225,19 +225,21 @@ var FluxbaseAuth = class {
225
225
  expires_at: Date.now() + authResponse.expires_in * 1e3
226
226
  };
227
227
  this.setSessionInternal(session);
228
- return session;
228
+ return { user: session.user, session };
229
229
  });
230
230
  }
231
231
  /**
232
- * Sign in with email and password
232
+ * Sign in with email and password (Supabase-compatible)
233
233
  * Alias for signIn() to maintain compatibility with common authentication patterns
234
- * Returns AuthSession if successful, or SignInWith2FAResponse if 2FA is required
234
+ * Returns { user, session } if successful, or SignInWith2FAResponse if 2FA is required
235
235
  */
236
236
  async signInWithPassword(credentials) {
237
237
  return this.signIn(credentials);
238
238
  }
239
239
  /**
240
- * Sign up with email and password
240
+ * Sign up with email and password (Supabase-compatible)
241
+ * Returns session when email confirmation is disabled
242
+ * Returns null session when email confirmation is required
241
243
  */
242
244
  async signUp(credentials) {
243
245
  return wrapAsync(async () => {
@@ -245,12 +247,15 @@ var FluxbaseAuth = class {
245
247
  "/api/v1/auth/signup",
246
248
  credentials
247
249
  );
248
- const session = {
249
- ...response,
250
- expires_at: Date.now() + response.expires_in * 1e3
251
- };
252
- this.setSessionInternal(session);
253
- return { user: session.user, session };
250
+ if (response.access_token && response.refresh_token) {
251
+ const session = {
252
+ ...response,
253
+ expires_at: Date.now() + response.expires_in * 1e3
254
+ };
255
+ this.setSessionInternal(session);
256
+ return { user: response.user, session };
257
+ }
258
+ return { user: response.user, session: null };
254
259
  });
255
260
  }
256
261
  /**
@@ -285,7 +290,7 @@ var FluxbaseAuth = class {
285
290
  expires_at: Date.now() + response.expires_in * 1e3
286
291
  };
287
292
  this.setSessionInternal(session, "TOKEN_REFRESHED");
288
- return { session, user: session.user };
293
+ return { user: session.user, session };
289
294
  });
290
295
  }
291
296
  /**
@@ -342,8 +347,9 @@ var FluxbaseAuth = class {
342
347
  });
343
348
  }
344
349
  /**
345
- * Setup 2FA for the current user
346
- * Returns TOTP secret and QR code URL
350
+ * Setup 2FA for the current user (Supabase-compatible)
351
+ * Enrolls a new MFA factor and returns TOTP details
352
+ * @returns Promise with factor id, type, and TOTP setup details
347
353
  */
348
354
  async setup2FA() {
349
355
  return wrapAsync(async () => {
@@ -356,8 +362,10 @@ var FluxbaseAuth = class {
356
362
  });
357
363
  }
358
364
  /**
359
- * Enable 2FA after verifying the TOTP code
360
- * Returns backup codes that should be saved by the user
365
+ * Enable 2FA after verifying the TOTP code (Supabase-compatible)
366
+ * Verifies the TOTP code and returns new tokens with MFA session
367
+ * @param code - TOTP code from authenticator app
368
+ * @returns Promise with access_token, refresh_token, and user
361
369
  */
362
370
  async enable2FA(code) {
363
371
  return wrapAsync(async () => {
@@ -371,8 +379,10 @@ var FluxbaseAuth = class {
371
379
  });
372
380
  }
373
381
  /**
374
- * Disable 2FA for the current user
375
- * Requires password confirmation
382
+ * Disable 2FA for the current user (Supabase-compatible)
383
+ * Unenrolls the MFA factor
384
+ * @param password - User password for confirmation
385
+ * @returns Promise with unenrolled factor id
376
386
  */
377
387
  async disable2FA(password) {
378
388
  return wrapAsync(async () => {
@@ -386,7 +396,9 @@ var FluxbaseAuth = class {
386
396
  });
387
397
  }
388
398
  /**
389
- * Check 2FA status for the current user
399
+ * Check 2FA status for the current user (Supabase-compatible)
400
+ * Lists all enrolled MFA factors
401
+ * @returns Promise with all factors and TOTP factors
390
402
  */
391
403
  async get2FAStatus() {
392
404
  return wrapAsync(async () => {
@@ -399,8 +411,10 @@ var FluxbaseAuth = class {
399
411
  });
400
412
  }
401
413
  /**
402
- * Verify 2FA code during login
414
+ * Verify 2FA code during login (Supabase-compatible)
403
415
  * Call this after signIn returns requires_2fa: true
416
+ * @param request - User ID and TOTP code
417
+ * @returns Promise with access_token, refresh_token, and user
404
418
  */
405
419
  async verify2FA(request) {
406
420
  return wrapAsync(async () => {
@@ -408,31 +422,36 @@ var FluxbaseAuth = class {
408
422
  "/api/v1/auth/2fa/verify",
409
423
  request
410
424
  );
411
- const session = {
412
- ...response,
413
- expires_at: Date.now() + response.expires_in * 1e3
414
- };
415
- this.setSessionInternal(session, "MFA_CHALLENGE_VERIFIED");
416
- return { user: session.user, session };
425
+ if (response.access_token && response.refresh_token) {
426
+ const session = {
427
+ user: response.user,
428
+ access_token: response.access_token,
429
+ refresh_token: response.refresh_token,
430
+ expires_in: response.expires_in || 3600,
431
+ expires_at: Date.now() + (response.expires_in || 3600) * 1e3
432
+ };
433
+ this.setSessionInternal(session, "MFA_CHALLENGE_VERIFIED");
434
+ }
435
+ return response;
417
436
  });
418
437
  }
419
438
  /**
420
- * Send password reset email
439
+ * Send password reset email (Supabase-compatible)
421
440
  * Sends a password reset link to the provided email address
422
441
  * @param email - Email address to send reset link to
442
+ * @returns Promise with OTP-style response
423
443
  */
424
444
  async sendPasswordReset(email) {
425
445
  return wrapAsync(async () => {
426
- return await this.fetch.post(
427
- "/api/v1/auth/password/reset",
428
- { email }
429
- );
446
+ await this.fetch.post("/api/v1/auth/password/reset", { email });
447
+ return { user: null, session: null };
430
448
  });
431
449
  }
432
450
  /**
433
451
  * Supabase-compatible alias for sendPasswordReset()
434
452
  * @param email - Email address to send reset link to
435
453
  * @param _options - Optional redirect configuration (currently not used)
454
+ * @returns Promise with OTP-style response
436
455
  */
437
456
  async resetPasswordForEmail(email, _options) {
438
457
  return this.sendPasswordReset(email);
@@ -453,36 +472,42 @@ var FluxbaseAuth = class {
453
472
  });
454
473
  }
455
474
  /**
456
- * Reset password with token
475
+ * Reset password with token (Supabase-compatible)
457
476
  * Complete the password reset process with a valid token
458
477
  * @param token - Password reset token
459
478
  * @param newPassword - New password to set
479
+ * @returns Promise with user and new session
460
480
  */
461
481
  async resetPassword(token, newPassword) {
462
482
  return wrapAsync(async () => {
463
- return await this.fetch.post(
483
+ const response = await this.fetch.post(
464
484
  "/api/v1/auth/password/reset/confirm",
465
485
  {
466
486
  token,
467
487
  new_password: newPassword
468
488
  }
469
489
  );
490
+ const session = {
491
+ ...response,
492
+ expires_at: Date.now() + response.expires_in * 1e3
493
+ };
494
+ this.setSessionInternal(session, "PASSWORD_RECOVERY");
495
+ return { user: session.user, session };
470
496
  });
471
497
  }
472
498
  /**
473
- * Send magic link for passwordless authentication
499
+ * Send magic link for passwordless authentication (Supabase-compatible)
474
500
  * @param email - Email address to send magic link to
475
501
  * @param options - Optional configuration for magic link
502
+ * @returns Promise with OTP-style response
476
503
  */
477
504
  async sendMagicLink(email, options) {
478
505
  return wrapAsync(async () => {
479
- return await this.fetch.post(
480
- "/api/v1/auth/magiclink",
481
- {
482
- email,
483
- redirect_to: options?.redirect_to
484
- }
485
- );
506
+ await this.fetch.post("/api/v1/auth/magiclink", {
507
+ email,
508
+ redirect_to: options?.redirect_to
509
+ });
510
+ return { user: null, session: null };
486
511
  });
487
512
  }
488
513
  /**