@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/LICENSE +201 -201
- package/README.md +249 -249
- package/dist/index.d.mts +42 -46
- package/dist/index.d.ts +42 -46
- package/dist/index.js +98 -128
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +98 -128
- package/dist/index.mjs.map +1 -1
- package/package.json +67 -67
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, 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,6 +151,47 @@ 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.)
|
|
@@ -194,51 +235,6 @@ declare class Auth {
|
|
|
194
235
|
data: any | null;
|
|
195
236
|
error: any | null;
|
|
196
237
|
}>;
|
|
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
238
|
}
|
|
243
239
|
|
|
244
240
|
/**
|
package/dist/index.js
CHANGED
|
@@ -348,14 +348,19 @@ var Auth = class {
|
|
|
348
348
|
async signUp(request) {
|
|
349
349
|
try {
|
|
350
350
|
const response = await this.http.post("/api/auth/users", request);
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
351
|
+
const session = {
|
|
352
|
+
accessToken: response.accessToken || "",
|
|
353
|
+
user: response.user || {
|
|
354
|
+
id: "",
|
|
355
|
+
email: "",
|
|
356
|
+
name: "",
|
|
357
|
+
emailVerified: false,
|
|
358
|
+
createdAt: "",
|
|
359
|
+
updatedAt: ""
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
this.tokenManager.saveSession(session);
|
|
363
|
+
this.http.setAuthToken(response.accessToken || "");
|
|
359
364
|
return {
|
|
360
365
|
data: response,
|
|
361
366
|
error: null
|
|
@@ -381,11 +386,18 @@ var Auth = class {
|
|
|
381
386
|
try {
|
|
382
387
|
const response = await this.http.post("/api/auth/sessions", request);
|
|
383
388
|
const session = {
|
|
384
|
-
accessToken: response.accessToken,
|
|
385
|
-
user: response.user
|
|
389
|
+
accessToken: response.accessToken || "",
|
|
390
|
+
user: response.user || {
|
|
391
|
+
id: "",
|
|
392
|
+
email: "",
|
|
393
|
+
name: "",
|
|
394
|
+
emailVerified: false,
|
|
395
|
+
createdAt: "",
|
|
396
|
+
updatedAt: ""
|
|
397
|
+
}
|
|
386
398
|
};
|
|
387
399
|
this.tokenManager.saveSession(session);
|
|
388
|
-
this.http.setAuthToken(response.accessToken);
|
|
400
|
+
this.http.setAuthToken(response.accessToken || "");
|
|
389
401
|
return {
|
|
390
402
|
data: response,
|
|
391
403
|
error: null
|
|
@@ -456,6 +468,81 @@ var Auth = class {
|
|
|
456
468
|
};
|
|
457
469
|
}
|
|
458
470
|
}
|
|
471
|
+
/**
|
|
472
|
+
* Get list of available OAuth providers
|
|
473
|
+
* Returns the list of OAuth providers configured on the backend
|
|
474
|
+
* This is a public endpoint that doesn't require authentication
|
|
475
|
+
*
|
|
476
|
+
* @returns Array of configured OAuth providers with their configuration status
|
|
477
|
+
*
|
|
478
|
+
* @example
|
|
479
|
+
* ```ts
|
|
480
|
+
* const { data, error } = await insforge.auth.getOAuthProviders();
|
|
481
|
+
* if (data) {
|
|
482
|
+
* // data is an array of PublicOAuthProvider: [{ provider: 'google', isConfigured: true }, ...]
|
|
483
|
+
* data.forEach(p => console.log(`${p.provider}: ${p.isConfigured ? 'configured' : 'not configured'}`));
|
|
484
|
+
* }
|
|
485
|
+
* ```
|
|
486
|
+
*/
|
|
487
|
+
async getOAuthProviders() {
|
|
488
|
+
try {
|
|
489
|
+
const response = await this.http.get("/api/auth/oauth/providers");
|
|
490
|
+
return {
|
|
491
|
+
data: response.data,
|
|
492
|
+
error: null
|
|
493
|
+
};
|
|
494
|
+
} catch (error) {
|
|
495
|
+
if (error instanceof InsForgeError) {
|
|
496
|
+
return { data: null, error };
|
|
497
|
+
}
|
|
498
|
+
return {
|
|
499
|
+
data: null,
|
|
500
|
+
error: new InsForgeError(
|
|
501
|
+
"An unexpected error occurred while fetching OAuth providers",
|
|
502
|
+
500,
|
|
503
|
+
"UNEXPECTED_ERROR"
|
|
504
|
+
)
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Get public email authentication configuration
|
|
510
|
+
* Returns email authentication settings configured on the backend
|
|
511
|
+
* This is a public endpoint that doesn't require authentication
|
|
512
|
+
*
|
|
513
|
+
* @returns Email authentication configuration including password requirements and email verification settings
|
|
514
|
+
*
|
|
515
|
+
* @example
|
|
516
|
+
* ```ts
|
|
517
|
+
* const { data, error } = await insforge.auth.getEmailAuthConfig();
|
|
518
|
+
* if (data) {
|
|
519
|
+
* console.log(`Password min length: ${data.passwordMinLength}`);
|
|
520
|
+
* console.log(`Requires email verification: ${data.requireEmailVerification}`);
|
|
521
|
+
* console.log(`Requires uppercase: ${data.requireUppercase}`);
|
|
522
|
+
* }
|
|
523
|
+
* ```
|
|
524
|
+
*/
|
|
525
|
+
async getEmailAuthConfig() {
|
|
526
|
+
try {
|
|
527
|
+
const response = await this.http.get("/api/auth/email/public-config");
|
|
528
|
+
return {
|
|
529
|
+
data: response,
|
|
530
|
+
error: null
|
|
531
|
+
};
|
|
532
|
+
} catch (error) {
|
|
533
|
+
if (error instanceof InsForgeError) {
|
|
534
|
+
return { data: null, error };
|
|
535
|
+
}
|
|
536
|
+
return {
|
|
537
|
+
data: null,
|
|
538
|
+
error: new InsForgeError(
|
|
539
|
+
"An unexpected error occurred while fetching email authentication configuration",
|
|
540
|
+
500,
|
|
541
|
+
"UNEXPECTED_ERROR"
|
|
542
|
+
)
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
}
|
|
459
546
|
/**
|
|
460
547
|
* Get the current user with full profile information
|
|
461
548
|
* Returns both auth info (id, email, role) and profile data (nickname, avatar_url, bio, etc.)
|
|
@@ -563,123 +650,6 @@ var Auth = class {
|
|
|
563
650
|
const { data, error } = await this.database.from("users").update(profile).eq("id", session.user.id).select().single();
|
|
564
651
|
return { data, error };
|
|
565
652
|
}
|
|
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
653
|
};
|
|
684
654
|
|
|
685
655
|
// src/modules/storage.ts
|