@insforge/sdk 0.0.58-dev.0 → 0.0.58-dev.2
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/LICENSE +201 -201
- package/README.md +249 -249
- package/dist/index.d.mts +51 -57
- package/dist/index.d.ts +51 -57
- package/dist/index.js +97 -121
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +97 -121
- package/dist/index.mjs.map +1 -1
- package/package.json +67 -67
package/dist/index.mjs
CHANGED
|
@@ -344,11 +344,18 @@ var Auth = class {
|
|
|
344
344
|
try {
|
|
345
345
|
const response = await this.http.post("/api/auth/sessions", request);
|
|
346
346
|
const session = {
|
|
347
|
-
accessToken: response.accessToken,
|
|
348
|
-
user: response.user
|
|
347
|
+
accessToken: response.accessToken || "",
|
|
348
|
+
user: response.user || {
|
|
349
|
+
id: "",
|
|
350
|
+
email: "",
|
|
351
|
+
name: "",
|
|
352
|
+
emailVerified: false,
|
|
353
|
+
createdAt: "",
|
|
354
|
+
updatedAt: ""
|
|
355
|
+
}
|
|
349
356
|
};
|
|
350
357
|
this.tokenManager.saveSession(session);
|
|
351
|
-
this.http.setAuthToken(response.accessToken);
|
|
358
|
+
this.http.setAuthToken(response.accessToken || "");
|
|
352
359
|
return {
|
|
353
360
|
data: response,
|
|
354
361
|
error: null
|
|
@@ -419,6 +426,81 @@ var Auth = class {
|
|
|
419
426
|
};
|
|
420
427
|
}
|
|
421
428
|
}
|
|
429
|
+
/**
|
|
430
|
+
* Get list of available OAuth providers
|
|
431
|
+
* Returns the list of OAuth providers configured on the backend
|
|
432
|
+
* This is a public endpoint that doesn't require authentication
|
|
433
|
+
*
|
|
434
|
+
* @returns Array of configured OAuth providers with their configuration status
|
|
435
|
+
*
|
|
436
|
+
* @example
|
|
437
|
+
* ```ts
|
|
438
|
+
* const { data, error } = await insforge.auth.getOAuthProviders();
|
|
439
|
+
* if (data) {
|
|
440
|
+
* // data is an array of PublicOAuthProvider: [{ provider: 'google', isConfigured: true }, ...]
|
|
441
|
+
* data.forEach(p => console.log(`${p.provider}: ${p.isConfigured ? 'configured' : 'not configured'}`));
|
|
442
|
+
* }
|
|
443
|
+
* ```
|
|
444
|
+
*/
|
|
445
|
+
async getOAuthProviders() {
|
|
446
|
+
try {
|
|
447
|
+
const response = await this.http.get("/api/auth/oauth/providers");
|
|
448
|
+
return {
|
|
449
|
+
data: response.data,
|
|
450
|
+
error: null
|
|
451
|
+
};
|
|
452
|
+
} catch (error) {
|
|
453
|
+
if (error instanceof InsForgeError) {
|
|
454
|
+
return { data: null, error };
|
|
455
|
+
}
|
|
456
|
+
return {
|
|
457
|
+
data: null,
|
|
458
|
+
error: new InsForgeError(
|
|
459
|
+
"An unexpected error occurred while fetching OAuth providers",
|
|
460
|
+
500,
|
|
461
|
+
"UNEXPECTED_ERROR"
|
|
462
|
+
)
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Get public email authentication configuration
|
|
468
|
+
* Returns email authentication settings configured on the backend
|
|
469
|
+
* This is a public endpoint that doesn't require authentication
|
|
470
|
+
*
|
|
471
|
+
* @returns Email authentication configuration including password requirements and email verification settings
|
|
472
|
+
*
|
|
473
|
+
* @example
|
|
474
|
+
* ```ts
|
|
475
|
+
* const { data, error } = await insforge.auth.getEmailAuthConfig();
|
|
476
|
+
* if (data) {
|
|
477
|
+
* console.log(`Password min length: ${data.passwordMinLength}`);
|
|
478
|
+
* console.log(`Requires email verification: ${data.requireEmailVerification}`);
|
|
479
|
+
* console.log(`Requires uppercase: ${data.requireUppercase}`);
|
|
480
|
+
* }
|
|
481
|
+
* ```
|
|
482
|
+
*/
|
|
483
|
+
async getEmailAuthConfig() {
|
|
484
|
+
try {
|
|
485
|
+
const response = await this.http.get("/api/auth/email/public-config");
|
|
486
|
+
return {
|
|
487
|
+
data: response,
|
|
488
|
+
error: null
|
|
489
|
+
};
|
|
490
|
+
} catch (error) {
|
|
491
|
+
if (error instanceof InsForgeError) {
|
|
492
|
+
return { data: null, error };
|
|
493
|
+
}
|
|
494
|
+
return {
|
|
495
|
+
data: null,
|
|
496
|
+
error: new InsForgeError(
|
|
497
|
+
"An unexpected error occurred while fetching email authentication configuration",
|
|
498
|
+
500,
|
|
499
|
+
"UNEXPECTED_ERROR"
|
|
500
|
+
)
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
}
|
|
422
504
|
/**
|
|
423
505
|
* Get the current user with full profile information
|
|
424
506
|
* Returns both auth info (id, email, role) and profile data (nickname, avatar_url, bio, etc.)
|
|
@@ -519,130 +601,24 @@ var Auth = class {
|
|
|
519
601
|
return { data: null, error: error2 };
|
|
520
602
|
}
|
|
521
603
|
if (data2?.user) {
|
|
522
|
-
session.user =
|
|
604
|
+
session.user = {
|
|
605
|
+
id: data2.user.id,
|
|
606
|
+
email: data2.user.email,
|
|
607
|
+
name: data2.profile?.nickname || "",
|
|
608
|
+
// Not available from API, but required by UserSchema
|
|
609
|
+
emailVerified: false,
|
|
610
|
+
// Not available from API, but required by UserSchema
|
|
611
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
612
|
+
// Fallback
|
|
613
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
614
|
+
// Fallback
|
|
615
|
+
};
|
|
523
616
|
this.tokenManager.saveSession(session);
|
|
524
617
|
}
|
|
525
618
|
}
|
|
526
619
|
const { data, error } = await this.database.from("users").update(profile).eq("id", session.user.id).select().single();
|
|
527
620
|
return { data, error };
|
|
528
621
|
}
|
|
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
622
|
};
|
|
647
623
|
|
|
648
624
|
// src/modules/storage.ts
|