@seaverse/auth-sdk 0.4.4 → 0.4.6
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.cjs +370 -139
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +241 -4
- package/dist/index.js +370 -119
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -88,12 +88,16 @@ declare class AuthFactory {
|
|
|
88
88
|
static fromEnv(): AuthProvider;
|
|
89
89
|
/**
|
|
90
90
|
* 从配置文件创建认证提供者
|
|
91
|
+
* @deprecated This method requires Node.js fs module and should not be used in browser environments.
|
|
92
|
+
* Use AuthFactory.create() with a config object instead.
|
|
91
93
|
*/
|
|
92
|
-
static fromFile(
|
|
94
|
+
static fromFile(_path: string): Promise<AuthProvider>;
|
|
93
95
|
/**
|
|
94
96
|
* 从profile创建认证提供者
|
|
97
|
+
* @deprecated This method requires Node.js fs module and should not be used in browser environments.
|
|
98
|
+
* Use AuthFactory.create() with a config object instead.
|
|
95
99
|
*/
|
|
96
|
-
static fromProfile(
|
|
100
|
+
static fromProfile(_profileName?: string): Promise<AuthProvider>;
|
|
97
101
|
}
|
|
98
102
|
|
|
99
103
|
type HookType = 'beforeRequest' | 'afterResponse' | 'onError' | 'onRetry';
|
|
@@ -1647,5 +1651,238 @@ declare class Toast {
|
|
|
1647
1651
|
private static injectCSS;
|
|
1648
1652
|
}
|
|
1649
1653
|
|
|
1650
|
-
|
|
1651
|
-
|
|
1654
|
+
/**
|
|
1655
|
+
* Google One-Tap Sign-In SDK
|
|
1656
|
+
*
|
|
1657
|
+
* 用于在用户未登录 SeaVerse 但已登录 Google 的情况下,
|
|
1658
|
+
* 自动显示 Google One-Tap 快速登录界面
|
|
1659
|
+
*/
|
|
1660
|
+
declare global {
|
|
1661
|
+
interface Window {
|
|
1662
|
+
google?: {
|
|
1663
|
+
accounts: {
|
|
1664
|
+
id: {
|
|
1665
|
+
initialize(config: GoogleIdConfiguration): void;
|
|
1666
|
+
prompt(momentListener?: (notification: PromptMomentNotification) => void): void;
|
|
1667
|
+
cancel(): void;
|
|
1668
|
+
renderButton(parent: HTMLElement, options: GsiButtonConfiguration): void;
|
|
1669
|
+
disableAutoSelect(): void;
|
|
1670
|
+
};
|
|
1671
|
+
};
|
|
1672
|
+
};
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
interface GoogleIdConfiguration {
|
|
1676
|
+
client_id: string;
|
|
1677
|
+
callback: (response: CredentialResponse) => void;
|
|
1678
|
+
auto_select?: boolean;
|
|
1679
|
+
cancel_on_tap_outside?: boolean;
|
|
1680
|
+
context?: 'signin' | 'signup' | 'use';
|
|
1681
|
+
use_fedcm_for_prompt?: boolean;
|
|
1682
|
+
}
|
|
1683
|
+
interface CredentialResponse {
|
|
1684
|
+
credential: string;
|
|
1685
|
+
select_by?: string;
|
|
1686
|
+
}
|
|
1687
|
+
interface PromptMomentNotification {
|
|
1688
|
+
isDisplayMoment(): boolean;
|
|
1689
|
+
isDisplayed(): boolean;
|
|
1690
|
+
isNotDisplayed(): boolean;
|
|
1691
|
+
getNotDisplayedReason(): string;
|
|
1692
|
+
isSkippedMoment(): boolean;
|
|
1693
|
+
getSkippedReason(): string;
|
|
1694
|
+
isDismissedMoment(): boolean;
|
|
1695
|
+
getDismissedReason(): string;
|
|
1696
|
+
}
|
|
1697
|
+
interface GsiButtonConfiguration {
|
|
1698
|
+
type?: 'standard' | 'icon';
|
|
1699
|
+
theme?: 'outline' | 'filled_blue' | 'filled_black';
|
|
1700
|
+
size?: 'large' | 'medium' | 'small';
|
|
1701
|
+
text?: 'signin_with' | 'signup_with' | 'continue_with' | 'signin';
|
|
1702
|
+
shape?: 'rectangular' | 'pill' | 'circle' | 'square';
|
|
1703
|
+
logo_alignment?: 'left' | 'center';
|
|
1704
|
+
width?: number;
|
|
1705
|
+
locale?: string;
|
|
1706
|
+
}
|
|
1707
|
+
/**
|
|
1708
|
+
* Google One-Tap 配置选项
|
|
1709
|
+
*/
|
|
1710
|
+
interface GoogleOneTapOptions {
|
|
1711
|
+
/**
|
|
1712
|
+
* Google OAuth Client ID(必需)
|
|
1713
|
+
* 从 Google Cloud Console 获取
|
|
1714
|
+
*
|
|
1715
|
+
* @example '827924048330-xxxxxx.apps.googleusercontent.com'
|
|
1716
|
+
*/
|
|
1717
|
+
clientId: string;
|
|
1718
|
+
/**
|
|
1719
|
+
* 检查用户是否已登录 SeaVerse(必需)
|
|
1720
|
+
* SDK 会在初始化时和显示 One-Tap 前调用此函数
|
|
1721
|
+
* 只有返回 false 时才会显示 Google One-Tap
|
|
1722
|
+
*
|
|
1723
|
+
* @returns true - 已登录,SDK 不显示 One-Tap
|
|
1724
|
+
* false - 未登录,SDK 显示 One-Tap
|
|
1725
|
+
*
|
|
1726
|
+
* @example
|
|
1727
|
+
* isLoggedIn: () => !!localStorage.getItem('seaverse_token')
|
|
1728
|
+
*
|
|
1729
|
+
* @example
|
|
1730
|
+
* isLoggedIn: () => document.cookie.includes('auth_token')
|
|
1731
|
+
*/
|
|
1732
|
+
isLoggedIn: () => boolean;
|
|
1733
|
+
/**
|
|
1734
|
+
* 获取到 Google credential 后的回调(必需)
|
|
1735
|
+
* SDK 获取到 Google 返回的 JWT credential 后会调用此函数
|
|
1736
|
+
* 前端在此函数中决定如何处理 credential(调用后端验证、保存 token 等)
|
|
1737
|
+
*
|
|
1738
|
+
* @param credential - Google 返回的 JWT token
|
|
1739
|
+
*
|
|
1740
|
+
* @example
|
|
1741
|
+
* onCredentialReceived: async (credential) => {
|
|
1742
|
+
* const res = await fetch('/api/auth/google/verify', {
|
|
1743
|
+
* method: 'POST',
|
|
1744
|
+
* body: JSON.stringify({ credential })
|
|
1745
|
+
* });
|
|
1746
|
+
* const data = await res.json();
|
|
1747
|
+
* localStorage.setItem('token', data.token);
|
|
1748
|
+
* window.location.href = '/dashboard';
|
|
1749
|
+
* }
|
|
1750
|
+
*/
|
|
1751
|
+
onCredentialReceived: (credential: string) => void | Promise<void>;
|
|
1752
|
+
/**
|
|
1753
|
+
* 错误回调(可选)
|
|
1754
|
+
*
|
|
1755
|
+
* @param error - 错误对象
|
|
1756
|
+
*/
|
|
1757
|
+
onError?: (error: Error) => void;
|
|
1758
|
+
/**
|
|
1759
|
+
* 是否自动显示 One-Tap 提示(可选,默认 true)
|
|
1760
|
+
* 注意:即使设置为 true,也只在 isLoggedIn() 返回 false 时才显示
|
|
1761
|
+
*/
|
|
1762
|
+
autoPrompt?: boolean;
|
|
1763
|
+
/**
|
|
1764
|
+
* 点击 One-Tap 弹窗外部时是否取消(可选,默认 true)
|
|
1765
|
+
*/
|
|
1766
|
+
cancelOnTapOutside?: boolean;
|
|
1767
|
+
/**
|
|
1768
|
+
* 登录上下文(可选,默认 'signin')
|
|
1769
|
+
*/
|
|
1770
|
+
context?: 'signin' | 'signup' | 'use';
|
|
1771
|
+
/**
|
|
1772
|
+
* 自定义按钮配置(可选)
|
|
1773
|
+
* 用于 renderButton() 方法
|
|
1774
|
+
*/
|
|
1775
|
+
button?: {
|
|
1776
|
+
type?: 'standard' | 'icon';
|
|
1777
|
+
theme?: 'outline' | 'filled_blue' | 'filled_black';
|
|
1778
|
+
size?: 'large' | 'medium' | 'small';
|
|
1779
|
+
text?: 'signin_with' | 'signup_with' | 'continue_with' | 'signin';
|
|
1780
|
+
shape?: 'rectangular' | 'pill' | 'circle' | 'square';
|
|
1781
|
+
logoAlignment?: 'left' | 'center';
|
|
1782
|
+
width?: number;
|
|
1783
|
+
locale?: string;
|
|
1784
|
+
};
|
|
1785
|
+
/**
|
|
1786
|
+
* 是否启用调试日志(可选,默认 false)
|
|
1787
|
+
*/
|
|
1788
|
+
debug?: boolean;
|
|
1789
|
+
/**
|
|
1790
|
+
* 是否使用 FedCM (Federated Credential Management) 进行提示(可选,默认 false)
|
|
1791
|
+
*
|
|
1792
|
+
* FedCM 是 Chrome 的新 API,用于替代第三方 Cookie。
|
|
1793
|
+
* 如果遇到 CORS 错误或 FedCM 请求失败,可以设置为 false 使用传统的 iframe 方式。
|
|
1794
|
+
*
|
|
1795
|
+
* @default false
|
|
1796
|
+
*
|
|
1797
|
+
* @example
|
|
1798
|
+
* useFedcmForPrompt: false // 禁用 FedCM,使用传统方式
|
|
1799
|
+
*/
|
|
1800
|
+
useFedcmForPrompt?: boolean;
|
|
1801
|
+
}
|
|
1802
|
+
/**
|
|
1803
|
+
* Google One-Tap 快速登录
|
|
1804
|
+
*
|
|
1805
|
+
* 用法示例:
|
|
1806
|
+
* ```typescript
|
|
1807
|
+
* const googleLogin = new GoogleOneTap({
|
|
1808
|
+
* clientId: 'YOUR_GOOGLE_CLIENT_ID',
|
|
1809
|
+
* isLoggedIn: () => !!localStorage.getItem('token'),
|
|
1810
|
+
* onCredentialReceived: async (credential) => {
|
|
1811
|
+
* // 调用后端验证
|
|
1812
|
+
* const res = await fetch('/api/auth/google', {
|
|
1813
|
+
* method: 'POST',
|
|
1814
|
+
* body: JSON.stringify({ credential })
|
|
1815
|
+
* });
|
|
1816
|
+
* const data = await res.json();
|
|
1817
|
+
* localStorage.setItem('token', data.token);
|
|
1818
|
+
* window.location.reload();
|
|
1819
|
+
* }
|
|
1820
|
+
* });
|
|
1821
|
+
* ```
|
|
1822
|
+
*/
|
|
1823
|
+
declare class GoogleOneTap {
|
|
1824
|
+
private options;
|
|
1825
|
+
private isInitialized;
|
|
1826
|
+
private scriptLoaded;
|
|
1827
|
+
private static scriptLoadPromise;
|
|
1828
|
+
constructor(options: GoogleOneTapOptions);
|
|
1829
|
+
/**
|
|
1830
|
+
* 检查登录状态并初始化
|
|
1831
|
+
*/
|
|
1832
|
+
private checkAndInit;
|
|
1833
|
+
/**
|
|
1834
|
+
* 初始化 Google One-Tap API
|
|
1835
|
+
*/
|
|
1836
|
+
private init;
|
|
1837
|
+
/**
|
|
1838
|
+
* 处理 Google 返回的 credential
|
|
1839
|
+
*/
|
|
1840
|
+
private handleCredentialResponse;
|
|
1841
|
+
/**
|
|
1842
|
+
* 显示 Google One-Tap 提示
|
|
1843
|
+
* 会先检查登录状态
|
|
1844
|
+
*/
|
|
1845
|
+
prompt(): void;
|
|
1846
|
+
/**
|
|
1847
|
+
* 取消 Google One-Tap 提示
|
|
1848
|
+
*/
|
|
1849
|
+
cancel(): void;
|
|
1850
|
+
/**
|
|
1851
|
+
* 渲染 Google 登录按钮到指定元素
|
|
1852
|
+
*
|
|
1853
|
+
* @param element - 要渲染按钮的 HTML 元素
|
|
1854
|
+
*
|
|
1855
|
+
* @example
|
|
1856
|
+
* const container = document.getElementById('google-btn');
|
|
1857
|
+
* googleLogin.renderButton(container);
|
|
1858
|
+
*/
|
|
1859
|
+
renderButton(element: HTMLElement): void;
|
|
1860
|
+
/**
|
|
1861
|
+
* 禁用自动选择
|
|
1862
|
+
* 用户关闭 One-Tap 后,下次不会自动选择账号
|
|
1863
|
+
*/
|
|
1864
|
+
disableAutoSelect(): void;
|
|
1865
|
+
/**
|
|
1866
|
+
* 等待 Google API 完全就绪
|
|
1867
|
+
*/
|
|
1868
|
+
private waitForGoogleAPI;
|
|
1869
|
+
/**
|
|
1870
|
+
* 加载 Google One-Tap 脚本
|
|
1871
|
+
*/
|
|
1872
|
+
private loadGoogleScript;
|
|
1873
|
+
/**
|
|
1874
|
+
* 处理错误
|
|
1875
|
+
*/
|
|
1876
|
+
private handleError;
|
|
1877
|
+
/**
|
|
1878
|
+
* 调试日志
|
|
1879
|
+
*/
|
|
1880
|
+
private log;
|
|
1881
|
+
/**
|
|
1882
|
+
* 检查 Google One-Tap 是否可用
|
|
1883
|
+
*/
|
|
1884
|
+
static isAvailable(): boolean;
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
export { AuthFactory, AuthModal, AuthProvider, BuiltInHooks, ENVIRONMENT_CONFIGS, ErrorCode, GoogleOneTap, SeaVerseBackendAPIClient, Toast, createAuthModal, detectEnvironment, getEnvironmentConfig, models };
|
|
1888
|
+
export type { AccountExistsErrorDetails, ApiError, ApiServiceTokenResponse, ApplyInviteResponse, AuthModalOptions, AuthModalResult, BindInviteCodeRequest, BindInviteCodeResponse, Container, ContainerDetailResponse, ContainerListResponse, ContainerStatsResponse, ConversationStatus, CreateMarketplaceSkillRequest, CreateVideoShareRequest, CreateVideoShareResponse, EmailVerificationResponse, Environment, EnvironmentConfig, ForgotPasswordRequest, ForkProjectRequest, ForkProjectResponse, GoogleOneTapOptions, HealthResponse, HubProject, HubProjectsListResponse, IframeTokenErrorMessage, IframeTokenRequestMessage, IframeTokenResponseMessage, InviteApplication, InviteApplicationListResponse, InviteCode, InviteCodeBindRequest, InviteCodeDetailResponse, InviteCodeGenerateResponse, InviteCodeRequiredErrorData, InviteCodeVerifyResponse, InviteStats, InviteStatsResponse, InviteUsage, ListInviteUsagesRequest, ListInviteUsagesResponse, ListInvitesRequest, ListInvitesResponse, LoginRequest, LoginResponse, MarketplaceSkill, MarketplaceSkillsListResponse, OAuthAuthorizeRequest, OAuthAuthorizeResponse, PublishProjectRequest, PublishSkillRequest, RegisterContainerRequest, RegisterContainerResponse, RegisterRequest, RegisterResponse, ResetPasswordRequest, RetryOptions, SeaVerseBackendAPIClientOptions, SocialMediaLink, SocialMediaLinksResponse, SpeechTokenResponse, SubmitInviteApplicationRequest, SuccessResponse, ToastOptions, ToastType, TrackAppTypeRequest, User, UserInstalledSkill, UserInstalledSkillsListResponse, VideoDetails };
|