@insforge/sdk 0.0.58-dev.0 → 0.0.58-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.mjs CHANGED
@@ -311,14 +311,19 @@ var Auth = class {
311
311
  async signUp(request) {
312
312
  try {
313
313
  const response = await this.http.post("/api/auth/users", request);
314
- if (response.accessToken && response.user) {
315
- const session = {
316
- accessToken: response.accessToken,
317
- user: response.user
318
- };
319
- this.tokenManager.saveSession(session);
320
- this.http.setAuthToken(response.accessToken);
321
- }
314
+ const session = {
315
+ accessToken: response.accessToken || "",
316
+ user: response.user || {
317
+ id: "",
318
+ email: "",
319
+ name: "",
320
+ emailVerified: false,
321
+ createdAt: "",
322
+ updatedAt: ""
323
+ }
324
+ };
325
+ this.tokenManager.saveSession(session);
326
+ this.http.setAuthToken(response.accessToken || "");
322
327
  return {
323
328
  data: response,
324
329
  error: null
@@ -344,11 +349,18 @@ var Auth = class {
344
349
  try {
345
350
  const response = await this.http.post("/api/auth/sessions", request);
346
351
  const session = {
347
- accessToken: response.accessToken,
348
- user: response.user
352
+ accessToken: response.accessToken || "",
353
+ user: response.user || {
354
+ id: "",
355
+ email: "",
356
+ name: "",
357
+ emailVerified: false,
358
+ createdAt: "",
359
+ updatedAt: ""
360
+ }
349
361
  };
350
362
  this.tokenManager.saveSession(session);
351
- this.http.setAuthToken(response.accessToken);
363
+ this.http.setAuthToken(response.accessToken || "");
352
364
  return {
353
365
  data: response,
354
366
  error: null
@@ -419,6 +431,81 @@ var Auth = class {
419
431
  };
420
432
  }
421
433
  }
434
+ /**
435
+ * Get list of available OAuth providers
436
+ * Returns the list of OAuth providers configured on the backend
437
+ * This is a public endpoint that doesn't require authentication
438
+ *
439
+ * @returns Array of configured OAuth providers with their configuration status
440
+ *
441
+ * @example
442
+ * ```ts
443
+ * const { data, error } = await insforge.auth.getOAuthProviders();
444
+ * if (data) {
445
+ * // data is an array of PublicOAuthProvider: [{ provider: 'google', isConfigured: true }, ...]
446
+ * data.forEach(p => console.log(`${p.provider}: ${p.isConfigured ? 'configured' : 'not configured'}`));
447
+ * }
448
+ * ```
449
+ */
450
+ async getOAuthProviders() {
451
+ try {
452
+ const response = await this.http.get("/api/auth/oauth/providers");
453
+ return {
454
+ data: response.data,
455
+ error: null
456
+ };
457
+ } catch (error) {
458
+ if (error instanceof InsForgeError) {
459
+ return { data: null, error };
460
+ }
461
+ return {
462
+ data: null,
463
+ error: new InsForgeError(
464
+ "An unexpected error occurred while fetching OAuth providers",
465
+ 500,
466
+ "UNEXPECTED_ERROR"
467
+ )
468
+ };
469
+ }
470
+ }
471
+ /**
472
+ * Get public email authentication configuration
473
+ * Returns email authentication settings configured on the backend
474
+ * This is a public endpoint that doesn't require authentication
475
+ *
476
+ * @returns Email authentication configuration including password requirements and email verification settings
477
+ *
478
+ * @example
479
+ * ```ts
480
+ * const { data, error } = await insforge.auth.getEmailAuthConfig();
481
+ * if (data) {
482
+ * console.log(`Password min length: ${data.passwordMinLength}`);
483
+ * console.log(`Requires email verification: ${data.requireEmailVerification}`);
484
+ * console.log(`Requires uppercase: ${data.requireUppercase}`);
485
+ * }
486
+ * ```
487
+ */
488
+ async getEmailAuthConfig() {
489
+ try {
490
+ const response = await this.http.get("/api/auth/email/public-config");
491
+ return {
492
+ data: response,
493
+ error: null
494
+ };
495
+ } catch (error) {
496
+ if (error instanceof InsForgeError) {
497
+ return { data: null, error };
498
+ }
499
+ return {
500
+ data: null,
501
+ error: new InsForgeError(
502
+ "An unexpected error occurred while fetching email authentication configuration",
503
+ 500,
504
+ "UNEXPECTED_ERROR"
505
+ )
506
+ };
507
+ }
508
+ }
422
509
  /**
423
510
  * Get the current user with full profile information
424
511
  * Returns both auth info (id, email, role) and profile data (nickname, avatar_url, bio, etc.)
@@ -526,123 +613,6 @@ var Auth = class {
526
613
  const { data, error } = await this.database.from("users").update(profile).eq("id", session.user.id).select().single();
527
614
  return { data, error };
528
615
  }
529
- /**
530
- * Send email verification code or link
531
- * @param type - 'code' for numeric OTP (6 digits) or 'link' for verification link
532
- * @param email - Email address to send verification to
533
- */
534
- async sendEmailVerification(type, email) {
535
- try {
536
- const request = { email };
537
- const endpoint = type === "code" ? "/api/auth/email/send-verification-code" : "/api/auth/email/send-verification-link";
538
- const response = await this.http.post(endpoint, request);
539
- return {
540
- data: response,
541
- error: null
542
- };
543
- } catch (error) {
544
- if (error instanceof InsForgeError) {
545
- return { data: null, error };
546
- }
547
- return {
548
- data: null,
549
- error: new InsForgeError(
550
- "An unexpected error occurred while sending verification email",
551
- 500,
552
- "UNEXPECTED_ERROR"
553
- )
554
- };
555
- }
556
- }
557
- /**
558
- * Verify email with OTP
559
- * @param otp - 6-digit numeric code (with email) or 64-char hex token (without email)
560
- * @param email - Optional email address (required for code verification)
561
- */
562
- async verifyEmail(otp, email) {
563
- try {
564
- const request = { otp, email };
565
- const response = await this.http.post("/api/auth/verify-email", request);
566
- const session = {
567
- accessToken: response.accessToken,
568
- user: response.user
569
- };
570
- this.tokenManager.saveSession(session);
571
- this.http.setAuthToken(response.accessToken);
572
- return {
573
- data: response,
574
- error: null
575
- };
576
- } catch (error) {
577
- if (error instanceof InsForgeError) {
578
- return { data: null, error };
579
- }
580
- return {
581
- data: null,
582
- error: new InsForgeError(
583
- "An unexpected error occurred while verifying email",
584
- 500,
585
- "UNEXPECTED_ERROR"
586
- )
587
- };
588
- }
589
- }
590
- /**
591
- * Send password reset code or link
592
- * @param type - 'code' for numeric OTP (6 digits) or 'link' for reset link
593
- * @param email - Email address to send reset instructions to
594
- */
595
- async sendResetPasswordEmail(type, email) {
596
- try {
597
- const request = { email };
598
- const endpoint = type === "code" ? "/api/auth/email/send-reset-password-code" : "/api/auth/email/send-reset-password-link";
599
- const response = await this.http.post(endpoint, request);
600
- return {
601
- data: response,
602
- error: null
603
- };
604
- } catch (error) {
605
- if (error instanceof InsForgeError) {
606
- return { data: null, error };
607
- }
608
- return {
609
- data: null,
610
- error: new InsForgeError(
611
- "An unexpected error occurred while sending reset password email",
612
- 500,
613
- "UNEXPECTED_ERROR"
614
- )
615
- };
616
- }
617
- }
618
- /**
619
- * Reset password with OTP
620
- * @param otp - 6-digit numeric code (with email) or 64-char hex token (without email)
621
- * @param newPassword - New password to set
622
- * @param email - Optional email address (required for code-based reset)
623
- */
624
- async resetPassword(otp, newPassword, email) {
625
- try {
626
- const request = { otp, newPassword, email };
627
- const response = await this.http.post("/api/auth/reset-password", request);
628
- return {
629
- data: response,
630
- error: null
631
- };
632
- } catch (error) {
633
- if (error instanceof InsForgeError) {
634
- return { data: null, error };
635
- }
636
- return {
637
- data: null,
638
- error: new InsForgeError(
639
- "An unexpected error occurred while resetting password",
640
- 500,
641
- "UNEXPECTED_ERROR"
642
- )
643
- };
644
- }
645
- }
646
616
  };
647
617
 
648
618
  // src/modules/storage.ts