@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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest } from '@insforge/shared-schemas';
1
+ import { UserSchema, CreateUserRequest, CreateUserResponse, CreateSessionRequest, CreateSessionResponse, OAuthProvidersSchema, PublicOAuthProvider, GetPublicEmailAuthConfigResponse, UserIdSchema, EmailSchema, RoleSchema, ProfileSchema, UpdateProfileSchema, StorageFileSchema, ListObjectsResponseSchema, ChatCompletionRequest, ImageGenerationRequest } from '@insforge/shared-schemas';
2
2
  export { AuthErrorResponse, CreateSessionRequest, CreateUserRequest, UserSchema } from '@insforge/shared-schemas';
3
3
  import * as _supabase_postgrest_js from '@supabase/postgrest-js';
4
4
 
@@ -151,14 +151,59 @@ declare class Auth {
151
151
  signOut(): Promise<{
152
152
  error: InsForgeError | null;
153
153
  }>;
154
+ /**
155
+ * Get list of available OAuth providers
156
+ * Returns the list of OAuth providers configured on the backend
157
+ * This is a public endpoint that doesn't require authentication
158
+ *
159
+ * @returns Array of configured OAuth providers with their configuration status
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * const { data, error } = await insforge.auth.getOAuthProviders();
164
+ * if (data) {
165
+ * // data is an array of PublicOAuthProvider: [{ provider: 'google', isConfigured: true }, ...]
166
+ * data.forEach(p => console.log(`${p.provider}: ${p.isConfigured ? 'configured' : 'not configured'}`));
167
+ * }
168
+ * ```
169
+ */
170
+ getOAuthProviders(): Promise<{
171
+ data: PublicOAuthProvider[] | null;
172
+ error: InsForgeError | null;
173
+ }>;
174
+ /**
175
+ * Get public email authentication configuration
176
+ * Returns email authentication settings configured on the backend
177
+ * This is a public endpoint that doesn't require authentication
178
+ *
179
+ * @returns Email authentication configuration including password requirements and email verification settings
180
+ *
181
+ * @example
182
+ * ```ts
183
+ * const { data, error } = await insforge.auth.getEmailAuthConfig();
184
+ * if (data) {
185
+ * console.log(`Password min length: ${data.passwordMinLength}`);
186
+ * console.log(`Requires email verification: ${data.requireEmailVerification}`);
187
+ * console.log(`Requires uppercase: ${data.requireUppercase}`);
188
+ * }
189
+ * ```
190
+ */
191
+ getEmailAuthConfig(): Promise<{
192
+ data: GetPublicEmailAuthConfigResponse | null;
193
+ error: InsForgeError | null;
194
+ }>;
154
195
  /**
155
196
  * Get the current user with full profile information
156
197
  * Returns both auth info (id, email, role) and profile data (nickname, avatar_url, bio, etc.)
157
198
  */
158
199
  getCurrentUser(): Promise<{
159
200
  data: {
160
- user: any;
161
- profile: any;
201
+ user: {
202
+ id: UserIdSchema;
203
+ email: EmailSchema;
204
+ role: RoleSchema;
205
+ };
206
+ profile: ProfileSchema | null;
162
207
  } | null;
163
208
  error: any | null;
164
209
  }>;
@@ -167,7 +212,7 @@ declare class Auth {
167
212
  * Returns profile information from the users table (nickname, avatar_url, bio, etc.)
168
213
  */
169
214
  getProfile(userId: string): Promise<{
170
- data: any | null;
215
+ data: ProfileSchema | null;
171
216
  error: any | null;
172
217
  }>;
173
218
  /**
@@ -184,61 +229,10 @@ declare class Auth {
184
229
  * Set/Update the current user's profile
185
230
  * Updates profile information in the users table (nickname, avatar_url, bio, etc.)
186
231
  */
187
- setProfile(profile: {
188
- nickname?: string;
189
- avatar_url?: string;
190
- bio?: string;
191
- birthday?: string;
192
- [key: string]: any;
193
- }): Promise<{
194
- data: any | null;
232
+ setProfile(profile: UpdateProfileSchema): Promise<{
233
+ data: ProfileSchema | null;
195
234
  error: any | null;
196
235
  }>;
197
- /**
198
- * Send email verification code or link
199
- * @param type - 'code' for numeric OTP (6 digits) or 'link' for verification link
200
- * @param email - Email address to send verification to
201
- */
202
- sendEmailVerification(type: 'code' | 'link', email: string): Promise<{
203
- data: {
204
- success: boolean;
205
- message: string;
206
- } | null;
207
- error: InsForgeError | null;
208
- }>;
209
- /**
210
- * Verify email with OTP
211
- * @param otp - 6-digit numeric code (with email) or 64-char hex token (without email)
212
- * @param email - Optional email address (required for code verification)
213
- */
214
- verifyEmail(otp: string, email?: string): Promise<{
215
- data: CreateSessionResponse | null;
216
- error: InsForgeError | null;
217
- }>;
218
- /**
219
- * Send password reset code or link
220
- * @param type - 'code' for numeric OTP (6 digits) or 'link' for reset link
221
- * @param email - Email address to send reset instructions to
222
- */
223
- sendResetPasswordEmail(type: 'code' | 'link', email: string): Promise<{
224
- data: {
225
- success: boolean;
226
- message: string;
227
- } | null;
228
- error: InsForgeError | null;
229
- }>;
230
- /**
231
- * Reset password with OTP
232
- * @param otp - 6-digit numeric code (with email) or 64-char hex token (without email)
233
- * @param newPassword - New password to set
234
- * @param email - Optional email address (required for code-based reset)
235
- */
236
- resetPassword(otp: string, newPassword: string, email?: string): Promise<{
237
- data: {
238
- message: string;
239
- } | null;
240
- error: InsForgeError | null;
241
- }>;
242
236
  }
243
237
 
244
238
  /**
package/dist/index.js CHANGED
@@ -381,11 +381,18 @@ var Auth = class {
381
381
  try {
382
382
  const response = await this.http.post("/api/auth/sessions", request);
383
383
  const session = {
384
- accessToken: response.accessToken,
385
- user: response.user
384
+ accessToken: response.accessToken || "",
385
+ user: response.user || {
386
+ id: "",
387
+ email: "",
388
+ name: "",
389
+ emailVerified: false,
390
+ createdAt: "",
391
+ updatedAt: ""
392
+ }
386
393
  };
387
394
  this.tokenManager.saveSession(session);
388
- this.http.setAuthToken(response.accessToken);
395
+ this.http.setAuthToken(response.accessToken || "");
389
396
  return {
390
397
  data: response,
391
398
  error: null
@@ -456,6 +463,81 @@ var Auth = class {
456
463
  };
457
464
  }
458
465
  }
466
+ /**
467
+ * Get list of available OAuth providers
468
+ * Returns the list of OAuth providers configured on the backend
469
+ * This is a public endpoint that doesn't require authentication
470
+ *
471
+ * @returns Array of configured OAuth providers with their configuration status
472
+ *
473
+ * @example
474
+ * ```ts
475
+ * const { data, error } = await insforge.auth.getOAuthProviders();
476
+ * if (data) {
477
+ * // data is an array of PublicOAuthProvider: [{ provider: 'google', isConfigured: true }, ...]
478
+ * data.forEach(p => console.log(`${p.provider}: ${p.isConfigured ? 'configured' : 'not configured'}`));
479
+ * }
480
+ * ```
481
+ */
482
+ async getOAuthProviders() {
483
+ try {
484
+ const response = await this.http.get("/api/auth/oauth/providers");
485
+ return {
486
+ data: response.data,
487
+ error: null
488
+ };
489
+ } catch (error) {
490
+ if (error instanceof InsForgeError) {
491
+ return { data: null, error };
492
+ }
493
+ return {
494
+ data: null,
495
+ error: new InsForgeError(
496
+ "An unexpected error occurred while fetching OAuth providers",
497
+ 500,
498
+ "UNEXPECTED_ERROR"
499
+ )
500
+ };
501
+ }
502
+ }
503
+ /**
504
+ * Get public email authentication configuration
505
+ * Returns email authentication settings configured on the backend
506
+ * This is a public endpoint that doesn't require authentication
507
+ *
508
+ * @returns Email authentication configuration including password requirements and email verification settings
509
+ *
510
+ * @example
511
+ * ```ts
512
+ * const { data, error } = await insforge.auth.getEmailAuthConfig();
513
+ * if (data) {
514
+ * console.log(`Password min length: ${data.passwordMinLength}`);
515
+ * console.log(`Requires email verification: ${data.requireEmailVerification}`);
516
+ * console.log(`Requires uppercase: ${data.requireUppercase}`);
517
+ * }
518
+ * ```
519
+ */
520
+ async getEmailAuthConfig() {
521
+ try {
522
+ const response = await this.http.get("/api/auth/email/public-config");
523
+ return {
524
+ data: response,
525
+ error: null
526
+ };
527
+ } catch (error) {
528
+ if (error instanceof InsForgeError) {
529
+ return { data: null, error };
530
+ }
531
+ return {
532
+ data: null,
533
+ error: new InsForgeError(
534
+ "An unexpected error occurred while fetching email authentication configuration",
535
+ 500,
536
+ "UNEXPECTED_ERROR"
537
+ )
538
+ };
539
+ }
540
+ }
459
541
  /**
460
542
  * Get the current user with full profile information
461
543
  * Returns both auth info (id, email, role) and profile data (nickname, avatar_url, bio, etc.)
@@ -556,130 +638,24 @@ var Auth = class {
556
638
  return { data: null, error: error2 };
557
639
  }
558
640
  if (data2?.user) {
559
- session.user = data2.user;
641
+ session.user = {
642
+ id: data2.user.id,
643
+ email: data2.user.email,
644
+ name: data2.profile?.nickname || "",
645
+ // Not available from API, but required by UserSchema
646
+ emailVerified: false,
647
+ // Not available from API, but required by UserSchema
648
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
649
+ // Fallback
650
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
651
+ // Fallback
652
+ };
560
653
  this.tokenManager.saveSession(session);
561
654
  }
562
655
  }
563
656
  const { data, error } = await this.database.from("users").update(profile).eq("id", session.user.id).select().single();
564
657
  return { data, error };
565
658
  }
566
- /**
567
- * Send email verification code or link
568
- * @param type - 'code' for numeric OTP (6 digits) or 'link' for verification link
569
- * @param email - Email address to send verification to
570
- */
571
- async sendEmailVerification(type, email) {
572
- try {
573
- const request = { email };
574
- const endpoint = type === "code" ? "/api/auth/email/send-verification-code" : "/api/auth/email/send-verification-link";
575
- const response = await this.http.post(endpoint, request);
576
- return {
577
- data: response,
578
- error: null
579
- };
580
- } catch (error) {
581
- if (error instanceof InsForgeError) {
582
- return { data: null, error };
583
- }
584
- return {
585
- data: null,
586
- error: new InsForgeError(
587
- "An unexpected error occurred while sending verification email",
588
- 500,
589
- "UNEXPECTED_ERROR"
590
- )
591
- };
592
- }
593
- }
594
- /**
595
- * Verify email with OTP
596
- * @param otp - 6-digit numeric code (with email) or 64-char hex token (without email)
597
- * @param email - Optional email address (required for code verification)
598
- */
599
- async verifyEmail(otp, email) {
600
- try {
601
- const request = { otp, email };
602
- const response = await this.http.post("/api/auth/verify-email", request);
603
- const session = {
604
- accessToken: response.accessToken,
605
- user: response.user
606
- };
607
- this.tokenManager.saveSession(session);
608
- this.http.setAuthToken(response.accessToken);
609
- return {
610
- data: response,
611
- error: null
612
- };
613
- } catch (error) {
614
- if (error instanceof InsForgeError) {
615
- return { data: null, error };
616
- }
617
- return {
618
- data: null,
619
- error: new InsForgeError(
620
- "An unexpected error occurred while verifying email",
621
- 500,
622
- "UNEXPECTED_ERROR"
623
- )
624
- };
625
- }
626
- }
627
- /**
628
- * Send password reset code or link
629
- * @param type - 'code' for numeric OTP (6 digits) or 'link' for reset link
630
- * @param email - Email address to send reset instructions to
631
- */
632
- async sendResetPasswordEmail(type, email) {
633
- try {
634
- const request = { email };
635
- const endpoint = type === "code" ? "/api/auth/email/send-reset-password-code" : "/api/auth/email/send-reset-password-link";
636
- const response = await this.http.post(endpoint, request);
637
- return {
638
- data: response,
639
- error: null
640
- };
641
- } catch (error) {
642
- if (error instanceof InsForgeError) {
643
- return { data: null, error };
644
- }
645
- return {
646
- data: null,
647
- error: new InsForgeError(
648
- "An unexpected error occurred while sending reset password email",
649
- 500,
650
- "UNEXPECTED_ERROR"
651
- )
652
- };
653
- }
654
- }
655
- /**
656
- * Reset password with OTP
657
- * @param otp - 6-digit numeric code (with email) or 64-char hex token (without email)
658
- * @param newPassword - New password to set
659
- * @param email - Optional email address (required for code-based reset)
660
- */
661
- async resetPassword(otp, newPassword, email) {
662
- try {
663
- const request = { otp, newPassword, email };
664
- const response = await this.http.post("/api/auth/reset-password", request);
665
- return {
666
- data: response,
667
- error: null
668
- };
669
- } catch (error) {
670
- if (error instanceof InsForgeError) {
671
- return { data: null, error };
672
- }
673
- return {
674
- data: null,
675
- error: new InsForgeError(
676
- "An unexpected error occurred while resetting password",
677
- 500,
678
- "UNEXPECTED_ERROR"
679
- )
680
- };
681
- }
682
- }
683
659
  };
684
660
 
685
661
  // src/modules/storage.ts