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

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