@seaverse/auth-sdk 0.2.1 → 0.2.3
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/README.md +358 -92
- package/dist/index.cjs +175 -199
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +112 -57
- package/dist/index.js +176 -200
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -258,8 +258,11 @@ interface RegisterRequest {
|
|
|
258
258
|
*/
|
|
259
259
|
interface RegisterResponse {
|
|
260
260
|
success: boolean;
|
|
261
|
-
message
|
|
262
|
-
userId
|
|
261
|
+
message?: string;
|
|
262
|
+
userId?: string;
|
|
263
|
+
error?: string;
|
|
264
|
+
code?: string;
|
|
265
|
+
details?: Record<string, any>;
|
|
263
266
|
}
|
|
264
267
|
/**
|
|
265
268
|
* Forgot password request
|
|
@@ -277,17 +280,16 @@ interface ResetPasswordRequest {
|
|
|
277
280
|
newPassword?: string;
|
|
278
281
|
}
|
|
279
282
|
/**
|
|
280
|
-
* OAuth
|
|
283
|
+
* OAuth authorize request (Backend Proxy Mode)
|
|
281
284
|
*/
|
|
282
|
-
interface
|
|
283
|
-
|
|
285
|
+
interface OAuthAuthorizeRequest {
|
|
286
|
+
return_url?: string;
|
|
284
287
|
}
|
|
285
288
|
/**
|
|
286
|
-
* OAuth
|
|
289
|
+
* OAuth authorize response (Backend Proxy Mode)
|
|
287
290
|
*/
|
|
288
|
-
interface
|
|
289
|
-
|
|
290
|
-
user: User;
|
|
291
|
+
interface OAuthAuthorizeResponse {
|
|
292
|
+
authorize_url: string;
|
|
291
293
|
}
|
|
292
294
|
/**
|
|
293
295
|
* Health check response
|
|
@@ -583,14 +585,40 @@ interface VideoDetails {
|
|
|
583
585
|
thumbnailUrl?: string;
|
|
584
586
|
createdAt: number;
|
|
585
587
|
}
|
|
588
|
+
/**
|
|
589
|
+
* Error codes for authentication system
|
|
590
|
+
*/
|
|
591
|
+
declare enum ErrorCode {
|
|
592
|
+
ACCOUNT_EXISTS = "ACCOUNT_EXISTS",
|
|
593
|
+
ACCOUNT_NOT_FOUND = "ACCOUNT_NOT_FOUND",
|
|
594
|
+
ACCOUNT_SUSPENDED = "ACCOUNT_SUSPENDED",
|
|
595
|
+
INVALID_CREDENTIALS = "INVALID_CREDENTIALS",
|
|
596
|
+
EMAIL_NOT_VERIFIED = "EMAIL_NOT_VERIFIED",
|
|
597
|
+
INVALID_EMAIL = "INVALID_EMAIL",
|
|
598
|
+
INVALID_PASSWORD = "INVALID_PASSWORD",
|
|
599
|
+
PASSWORD_TOO_WEAK = "PASSWORD_TOO_WEAK",
|
|
600
|
+
INVALID_INVITATION_CODE = "INVALID_INVITATION_CODE",
|
|
601
|
+
INVITATION_REQUIRED = "INVITATION_REQUIRED",
|
|
602
|
+
INVALID_TOKEN = "INVALID_TOKEN",
|
|
603
|
+
TOKEN_EXPIRED = "TOKEN_EXPIRED",
|
|
604
|
+
INTERNAL_ERROR = "INTERNAL_ERROR"
|
|
605
|
+
}
|
|
586
606
|
/**
|
|
587
607
|
* API error response
|
|
588
608
|
*/
|
|
589
609
|
interface ApiError {
|
|
610
|
+
success: false;
|
|
590
611
|
error: string;
|
|
591
|
-
code
|
|
612
|
+
code?: string;
|
|
592
613
|
details?: Record<string, any>;
|
|
593
614
|
}
|
|
615
|
+
/**
|
|
616
|
+
* Account exists error details
|
|
617
|
+
*/
|
|
618
|
+
interface AccountExistsErrorDetails {
|
|
619
|
+
email: string;
|
|
620
|
+
app_id?: string;
|
|
621
|
+
}
|
|
594
622
|
/**
|
|
595
623
|
* Standard success response
|
|
596
624
|
*/
|
|
@@ -599,10 +627,9 @@ interface SuccessResponse {
|
|
|
599
627
|
message?: string;
|
|
600
628
|
}
|
|
601
629
|
|
|
630
|
+
type models_AccountExistsErrorDetails = AccountExistsErrorDetails;
|
|
602
631
|
type models_ApiError = ApiError;
|
|
603
632
|
type models_ApiServiceTokenResponse = ApiServiceTokenResponse;
|
|
604
|
-
type models_CodeToTokenRequest = CodeToTokenRequest;
|
|
605
|
-
type models_CodeToTokenResponse = CodeToTokenResponse;
|
|
606
633
|
type models_Container = Container;
|
|
607
634
|
type models_ContainerDetailResponse = ContainerDetailResponse;
|
|
608
635
|
type models_ContainerListResponse = ContainerListResponse;
|
|
@@ -611,6 +638,8 @@ type models_ConversationStatus = ConversationStatus;
|
|
|
611
638
|
type models_CreateMarketplaceSkillRequest = CreateMarketplaceSkillRequest;
|
|
612
639
|
type models_CreateVideoShareRequest = CreateVideoShareRequest;
|
|
613
640
|
type models_CreateVideoShareResponse = CreateVideoShareResponse;
|
|
641
|
+
type models_ErrorCode = ErrorCode;
|
|
642
|
+
declare const models_ErrorCode: typeof ErrorCode;
|
|
614
643
|
type models_ForgotPasswordRequest = ForgotPasswordRequest;
|
|
615
644
|
type models_ForkProjectRequest = ForkProjectRequest;
|
|
616
645
|
type models_ForkProjectResponse = ForkProjectResponse;
|
|
@@ -626,6 +655,8 @@ type models_LoginRequest = LoginRequest;
|
|
|
626
655
|
type models_LoginResponse = LoginResponse;
|
|
627
656
|
type models_MarketplaceSkill = MarketplaceSkill;
|
|
628
657
|
type models_MarketplaceSkillsListResponse = MarketplaceSkillsListResponse;
|
|
658
|
+
type models_OAuthAuthorizeRequest = OAuthAuthorizeRequest;
|
|
659
|
+
type models_OAuthAuthorizeResponse = OAuthAuthorizeResponse;
|
|
629
660
|
type models_PublishProjectRequest = PublishProjectRequest;
|
|
630
661
|
type models_PublishSkillRequest = PublishSkillRequest;
|
|
631
662
|
type models_RegisterContainerRequest = RegisterContainerRequest;
|
|
@@ -644,7 +675,8 @@ type models_UserInstalledSkill = UserInstalledSkill;
|
|
|
644
675
|
type models_UserInstalledSkillsListResponse = UserInstalledSkillsListResponse;
|
|
645
676
|
type models_VideoDetails = VideoDetails;
|
|
646
677
|
declare namespace models {
|
|
647
|
-
export
|
|
678
|
+
export { models_ErrorCode as ErrorCode };
|
|
679
|
+
export type { models_AccountExistsErrorDetails as AccountExistsErrorDetails, models_ApiError as ApiError, models_ApiServiceTokenResponse as ApiServiceTokenResponse, models_Container as Container, models_ContainerDetailResponse as ContainerDetailResponse, models_ContainerListResponse as ContainerListResponse, models_ContainerStatsResponse as ContainerStatsResponse, models_ConversationStatus as ConversationStatus, models_CreateMarketplaceSkillRequest as CreateMarketplaceSkillRequest, models_CreateVideoShareRequest as CreateVideoShareRequest, models_CreateVideoShareResponse as CreateVideoShareResponse, models_ForgotPasswordRequest as ForgotPasswordRequest, models_ForkProjectRequest as ForkProjectRequest, models_ForkProjectResponse as ForkProjectResponse, models_HealthResponse as HealthResponse, models_HubProject as HubProject, models_HubProjectsListResponse as HubProjectsListResponse, models_InviteApplication as InviteApplication, models_InviteApplicationListResponse as InviteApplicationListResponse, models_InviteCodeBindRequest as InviteCodeBindRequest, models_InviteCodeGenerateResponse as InviteCodeGenerateResponse, models_InviteCodeVerifyResponse as InviteCodeVerifyResponse, models_LoginRequest as LoginRequest, models_LoginResponse as LoginResponse, models_MarketplaceSkill as MarketplaceSkill, models_MarketplaceSkillsListResponse as MarketplaceSkillsListResponse, models_OAuthAuthorizeRequest as OAuthAuthorizeRequest, models_OAuthAuthorizeResponse as OAuthAuthorizeResponse, models_PublishProjectRequest as PublishProjectRequest, models_PublishSkillRequest as PublishSkillRequest, models_RegisterContainerRequest as RegisterContainerRequest, models_RegisterContainerResponse as RegisterContainerResponse, models_RegisterRequest as RegisterRequest, models_RegisterResponse as RegisterResponse, models_ResetPasswordRequest as ResetPasswordRequest, models_SocialMediaLink as SocialMediaLink, models_SocialMediaLinksResponse as SocialMediaLinksResponse, models_SpeechTokenResponse as SpeechTokenResponse, models_SubmitInviteApplicationRequest as SubmitInviteApplicationRequest, models_SuccessResponse as SuccessResponse, models_TrackAppTypeRequest as TrackAppTypeRequest, models_User as User, models_UserInstalledSkill as UserInstalledSkill, models_UserInstalledSkillsListResponse as UserInstalledSkillsListResponse, models_VideoDetails as VideoDetails };
|
|
648
680
|
}
|
|
649
681
|
|
|
650
682
|
/**
|
|
@@ -778,6 +810,21 @@ declare class SeaVerseBackendAPIClient {
|
|
|
778
810
|
* Get default hooks configuration
|
|
779
811
|
*/
|
|
780
812
|
private getDefaultHooks;
|
|
813
|
+
/**
|
|
814
|
+
* Set authentication token
|
|
815
|
+
* Update the client's authentication token (useful after OAuth login)
|
|
816
|
+
*
|
|
817
|
+
* @param token - JWT token to set
|
|
818
|
+
*
|
|
819
|
+
* @example
|
|
820
|
+
* // After OAuth login
|
|
821
|
+
* const token = new URLSearchParams(window.location.search).get('token');
|
|
822
|
+
* if (token) {
|
|
823
|
+
* client.setToken(token);
|
|
824
|
+
* localStorage.setItem('token', token);
|
|
825
|
+
* }
|
|
826
|
+
*/
|
|
827
|
+
setToken(token: string): void;
|
|
781
828
|
/**
|
|
782
829
|
* Health check
|
|
783
830
|
* Check if the service is healthy
|
|
@@ -819,27 +866,50 @@ declare class SeaVerseBackendAPIClient {
|
|
|
819
866
|
*/
|
|
820
867
|
getApiServiceToken(options?: AxiosRequestConfig): Promise<ApiServiceTokenResponse>;
|
|
821
868
|
/**
|
|
822
|
-
*
|
|
823
|
-
*
|
|
824
|
-
|
|
825
|
-
|
|
869
|
+
* Google OAuth authorization (Backend Proxy Mode)
|
|
870
|
+
* Generate OAuth authorization URL for Google login
|
|
871
|
+
*
|
|
872
|
+
* @param data - OAuth authorize request (return_url is optional, defaults to window.location.origin)
|
|
873
|
+
* @param options - Additional axios request options
|
|
874
|
+
*
|
|
875
|
+
* @example
|
|
876
|
+
* // 使用默认 return_url (当前页面)
|
|
877
|
+
* const { authorize_url } = await client.googleAuthorize();
|
|
878
|
+
* window.location.href = authorize_url;
|
|
879
|
+
*
|
|
880
|
+
* @example
|
|
881
|
+
* // 自定义 return_url
|
|
882
|
+
* const { authorize_url } = await client.googleAuthorize({
|
|
883
|
+
* return_url: 'https://mygame.com/dashboard'
|
|
884
|
+
* });
|
|
885
|
+
* window.location.href = authorize_url;
|
|
886
|
+
*/
|
|
887
|
+
googleAuthorize(data?: OAuthAuthorizeRequest, options?: AxiosRequestConfig): Promise<OAuthAuthorizeResponse>;
|
|
826
888
|
/**
|
|
827
889
|
* Unlink Google account
|
|
828
890
|
* Unlink the user's Google account
|
|
829
891
|
*/
|
|
830
892
|
unlinkGoogle(options?: AxiosRequestConfig): Promise<SuccessResponse>;
|
|
831
893
|
/**
|
|
832
|
-
*
|
|
894
|
+
* Discord OAuth authorization (Backend Proxy Mode)
|
|
895
|
+
* Generate OAuth authorization URL for Discord login
|
|
896
|
+
*
|
|
897
|
+
* @param data - OAuth authorize request (return_url is optional, defaults to window.location.origin)
|
|
898
|
+
* @param options - Additional axios request options
|
|
833
899
|
*/
|
|
834
|
-
|
|
900
|
+
discordAuthorize(data?: OAuthAuthorizeRequest, options?: AxiosRequestConfig): Promise<OAuthAuthorizeResponse>;
|
|
835
901
|
/**
|
|
836
902
|
* Unlink Discord account
|
|
837
903
|
*/
|
|
838
904
|
unlinkDiscord(options?: AxiosRequestConfig): Promise<SuccessResponse>;
|
|
839
905
|
/**
|
|
840
|
-
*
|
|
906
|
+
* GitHub OAuth authorization (Backend Proxy Mode)
|
|
907
|
+
* Generate OAuth authorization URL for GitHub login
|
|
908
|
+
*
|
|
909
|
+
* @param data - OAuth authorize request (return_url is optional, defaults to window.location.origin)
|
|
910
|
+
* @param options - Additional axios request options
|
|
841
911
|
*/
|
|
842
|
-
|
|
912
|
+
githubAuthorize(data?: OAuthAuthorizeRequest, options?: AxiosRequestConfig): Promise<OAuthAuthorizeResponse>;
|
|
843
913
|
/**
|
|
844
914
|
* Unlink GitHub account
|
|
845
915
|
*/
|
|
@@ -926,30 +996,18 @@ declare class SeaVerseBackendAPIClient {
|
|
|
926
996
|
getapicontainers(options?: AxiosRequestConfig): Promise<any>;
|
|
927
997
|
}
|
|
928
998
|
|
|
929
|
-
interface OAuthConfig {
|
|
930
|
-
google?: {
|
|
931
|
-
clientId: string;
|
|
932
|
-
redirectUri?: string;
|
|
933
|
-
scope?: string;
|
|
934
|
-
};
|
|
935
|
-
discord?: {
|
|
936
|
-
clientId: string;
|
|
937
|
-
redirectUri?: string;
|
|
938
|
-
scope?: string;
|
|
939
|
-
};
|
|
940
|
-
github?: {
|
|
941
|
-
clientId: string;
|
|
942
|
-
redirectUri?: string;
|
|
943
|
-
scope?: string;
|
|
944
|
-
};
|
|
945
|
-
}
|
|
946
999
|
interface AuthModalOptions {
|
|
947
1000
|
client: SeaVerseBackendAPIClient;
|
|
948
1001
|
onLoginSuccess?: (token: string, user: any) => void;
|
|
949
1002
|
onSignupSuccess?: (token: string, user: any) => void;
|
|
950
1003
|
onError?: (error: Error) => void;
|
|
951
1004
|
theme?: 'dark' | 'light';
|
|
952
|
-
|
|
1005
|
+
returnUrl?: string;
|
|
1006
|
+
enableOAuth?: {
|
|
1007
|
+
google?: boolean;
|
|
1008
|
+
discord?: boolean;
|
|
1009
|
+
github?: boolean;
|
|
1010
|
+
};
|
|
953
1011
|
}
|
|
954
1012
|
interface AuthModalResult {
|
|
955
1013
|
success: boolean;
|
|
@@ -997,31 +1055,28 @@ declare class AuthModal {
|
|
|
997
1055
|
private showMessage;
|
|
998
1056
|
private showError;
|
|
999
1057
|
/**
|
|
1000
|
-
* Start OAuth flow for a given provider
|
|
1058
|
+
* Start OAuth flow for a given provider (Backend Proxy Mode)
|
|
1059
|
+
*
|
|
1060
|
+
* This method calls the backend /authorize endpoint to get the OAuth URL,
|
|
1061
|
+
* then redirects the user. The backend handles:
|
|
1062
|
+
* - State token generation and storage
|
|
1063
|
+
* - OAuth callback processing
|
|
1064
|
+
* - JWT token generation
|
|
1065
|
+
* - Redirecting back to returnUrl with token
|
|
1001
1066
|
*/
|
|
1002
1067
|
private startOAuthFlow;
|
|
1003
1068
|
/**
|
|
1004
|
-
*
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
* Build authorization URL for each provider
|
|
1009
|
-
*/
|
|
1010
|
-
private buildAuthUrl;
|
|
1011
|
-
/**
|
|
1012
|
-
* Handle OAuth callback
|
|
1013
|
-
* Call this method from your redirect page with the code and state from URL
|
|
1014
|
-
*/
|
|
1015
|
-
handleOAuthCallback(code: string, state: string): Promise<AuthModalResult>;
|
|
1016
|
-
/**
|
|
1017
|
-
* Check if current page is an OAuth callback and handle it automatically
|
|
1069
|
+
* Handle OAuth callback (Backend Proxy Mode)
|
|
1070
|
+
*
|
|
1071
|
+
* In Backend Proxy Mode, the backend redirects to returnUrl with token in query param.
|
|
1072
|
+
* This static method checks if current URL has a token and processes it.
|
|
1018
1073
|
*/
|
|
1019
|
-
static
|
|
1074
|
+
static handleOAuthCallback(options: AuthModalOptions): AuthModalResult | null;
|
|
1020
1075
|
}
|
|
1021
1076
|
/**
|
|
1022
1077
|
* Create and show auth modal
|
|
1023
1078
|
*/
|
|
1024
1079
|
declare function createAuthModal(options: AuthModalOptions): AuthModal;
|
|
1025
1080
|
|
|
1026
|
-
export { AuthFactory, AuthModal, AuthProvider, BuiltInHooks, ENVIRONMENT_CONFIGS, SeaVerseBackendAPIClient, createAuthModal, detectEnvironment, getEnvironmentConfig, models };
|
|
1027
|
-
export type { ApiError, ApiServiceTokenResponse, AuthModalOptions, AuthModalResult,
|
|
1081
|
+
export { AuthFactory, AuthModal, AuthProvider, BuiltInHooks, ENVIRONMENT_CONFIGS, ErrorCode, SeaVerseBackendAPIClient, createAuthModal, detectEnvironment, getEnvironmentConfig, models };
|
|
1082
|
+
export type { AccountExistsErrorDetails, ApiError, ApiServiceTokenResponse, AuthModalOptions, AuthModalResult, Container, ContainerDetailResponse, ContainerListResponse, ContainerStatsResponse, ConversationStatus, CreateMarketplaceSkillRequest, CreateVideoShareRequest, CreateVideoShareResponse, Environment, EnvironmentConfig, ForgotPasswordRequest, ForkProjectRequest, ForkProjectResponse, HealthResponse, HubProject, HubProjectsListResponse, InviteApplication, InviteApplicationListResponse, InviteCodeBindRequest, InviteCodeGenerateResponse, InviteCodeVerifyResponse, LoginRequest, LoginResponse, MarketplaceSkill, MarketplaceSkillsListResponse, OAuthAuthorizeRequest, OAuthAuthorizeResponse, PublishProjectRequest, PublishSkillRequest, RegisterContainerRequest, RegisterContainerResponse, RegisterRequest, RegisterResponse, ResetPasswordRequest, SeaVerseBackendAPIClientOptions, SocialMediaLink, SocialMediaLinksResponse, SpeechTokenResponse, SubmitInviteApplicationRequest, SuccessResponse, TrackAppTypeRequest, User, UserInstalledSkill, UserInstalledSkillsListResponse, VideoDetails };
|