@seaverse/auth-sdk 0.1.5 → 0.2.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/dist/index.d.ts CHANGED
@@ -208,12 +208,23 @@ declare class BuiltInHooks {
208
208
  */
209
209
  interface User {
210
210
  id?: string;
211
+ app_id?: string | null;
211
212
  email?: string;
212
213
  username?: string;
214
+ created_at?: number;
215
+ email_verified?: boolean;
216
+ google_id?: string | null;
217
+ discord_id?: string | null;
218
+ github_id?: string | null;
219
+ /** @deprecated Use created_at instead */
213
220
  createdAt?: number;
221
+ /** @deprecated Use email_verified instead */
214
222
  emailVerified?: boolean;
223
+ /** @deprecated Use google_id instead */
215
224
  googleId?: string;
225
+ /** @deprecated Use discord_id instead */
216
226
  discordId?: string;
227
+ /** @deprecated Use github_id instead */
217
228
  githubId?: string;
218
229
  }
219
230
  /**
@@ -236,6 +247,9 @@ interface LoginResponse {
236
247
  interface RegisterRequest {
237
248
  email: string;
238
249
  password: string;
250
+ username?: string;
251
+ invitation_code?: string;
252
+ /** @deprecated Use invitation_code instead */
239
253
  invitationCode?: string;
240
254
  fromShareAppId?: string;
241
255
  }
@@ -258,7 +272,9 @@ interface ForgotPasswordRequest {
258
272
  */
259
273
  interface ResetPasswordRequest {
260
274
  token: string;
261
- newPassword: string;
275
+ new_password: string;
276
+ /** @deprecated Use new_password instead */
277
+ newPassword?: string;
262
278
  }
263
279
  /**
264
280
  * OAuth code exchange request
@@ -686,6 +702,14 @@ declare function getEnvironmentConfig(env?: Environment): EnvironmentConfig;
686
702
  * SeaVerse Backend API Client 配置选项
687
703
  */
688
704
  interface SeaVerseBackendAPIClientOptions {
705
+ /**
706
+ * 应用 ID(必需)
707
+ * 用于标识应用身份,支持多租户架构
708
+ * - SeaVerse 平台: 'seaverse'
709
+ * - 第三方应用: 'game-abc123', 'social-xyz789' 等
710
+ * @example 'seaverse' | 'game-abc123'
711
+ */
712
+ appId: string;
689
713
  /**
690
714
  * API Base URL
691
715
  * 如果提供,将覆盖 environment 配置
@@ -723,24 +747,29 @@ interface SeaVerseBackendAPIClientOptions {
723
747
  * @version 2.0.0
724
748
  *
725
749
  * @example
726
- * // 方式 1: 自动检测环境(推荐本地开发)
727
- * const client = new SeaVerseBackendAPIClient();
750
+ * // 方式 1: SeaVerse 平台应用(自动检测环境)
751
+ * const client = new SeaVerseBackendAPIClient({
752
+ * appId: 'your-app-id',
753
+ * });
728
754
  *
729
755
  * @example
730
- * // 方式 2: 指定环境(推荐生产部署)
756
+ * // 方式 2: 第三方应用(指定环境)
731
757
  * const client = new SeaVerseBackendAPIClient({
758
+ * appId: 'game-abc123',
732
759
  * environment: 'production',
733
760
  * });
734
761
  *
735
762
  * @example
736
763
  * // 方式 3: 自定义 URL(特殊需求)
737
764
  * const client = new SeaVerseBackendAPIClient({
765
+ * appId: 'my-app',
738
766
  * baseURL: 'https://custom-api.example.com',
739
767
  * });
740
768
  */
741
769
  declare class SeaVerseBackendAPIClient {
742
770
  private httpClient;
743
- constructor(options?: SeaVerseBackendAPIClientOptions);
771
+ private appId;
772
+ constructor(options: SeaVerseBackendAPIClientOptions);
744
773
  /**
745
774
  * Get default authentication configuration
746
775
  */
@@ -900,17 +929,17 @@ declare class SeaVerseBackendAPIClient {
900
929
  interface OAuthConfig {
901
930
  google?: {
902
931
  clientId: string;
903
- redirectUri: string;
932
+ redirectUri?: string;
904
933
  scope?: string;
905
934
  };
906
935
  discord?: {
907
936
  clientId: string;
908
- redirectUri: string;
937
+ redirectUri?: string;
909
938
  scope?: string;
910
939
  };
911
940
  github?: {
912
941
  clientId: string;
913
- redirectUri: string;
942
+ redirectUri?: string;
914
943
  scope?: string;
915
944
  };
916
945
  }
package/dist/index.js CHANGED
@@ -1019,7 +1019,7 @@ class AuthFactory {
1019
1019
  const ENVIRONMENT_CONFIGS = {
1020
1020
  production: {
1021
1021
  name: 'production',
1022
- baseURL: 'https://api.seaverse.com',
1022
+ baseURL: 'https://account-hub.seaverse.ai',
1023
1023
  wsURL: 'wss://api.seaverse.com',
1024
1024
  isProduction: true,
1025
1025
  },
@@ -1125,23 +1125,32 @@ var models = /*#__PURE__*/Object.freeze({
1125
1125
  * @version 2.0.0
1126
1126
  *
1127
1127
  * @example
1128
- * // 方式 1: 自动检测环境(推荐本地开发)
1129
- * const client = new SeaVerseBackendAPIClient();
1128
+ * // 方式 1: SeaVerse 平台应用(自动检测环境)
1129
+ * const client = new SeaVerseBackendAPIClient({
1130
+ * appId: 'your-app-id',
1131
+ * });
1130
1132
  *
1131
1133
  * @example
1132
- * // 方式 2: 指定环境(推荐生产部署)
1134
+ * // 方式 2: 第三方应用(指定环境)
1133
1135
  * const client = new SeaVerseBackendAPIClient({
1136
+ * appId: 'game-abc123',
1134
1137
  * environment: 'production',
1135
1138
  * });
1136
1139
  *
1137
1140
  * @example
1138
1141
  * // 方式 3: 自定义 URL(特殊需求)
1139
1142
  * const client = new SeaVerseBackendAPIClient({
1143
+ * appId: 'my-app',
1140
1144
  * baseURL: 'https://custom-api.example.com',
1141
1145
  * });
1142
1146
  */
1143
1147
  class SeaVerseBackendAPIClient {
1144
- constructor(options = {}) {
1148
+ constructor(options) {
1149
+ // 验证必需的 appId 参数
1150
+ if (!options.appId) {
1151
+ throw new Error('appId is required. Please provide an appId when initializing SeaVerseBackendAPIClient.');
1152
+ }
1153
+ this.appId = options.appId;
1145
1154
  // 使用智能配置解析,支持三种优先级:
1146
1155
  // 1. 显式 baseURL(最高)
1147
1156
  // 2. environment 参数
@@ -1150,10 +1159,15 @@ class SeaVerseBackendAPIClient {
1150
1159
  baseURL: options.baseURL,
1151
1160
  environment: options.environment,
1152
1161
  });
1162
+ // 合并用户提供的 headers 和必需的 X-App-ID header
1163
+ const headers = {
1164
+ 'X-App-ID': this.appId,
1165
+ ...options.headers,
1166
+ };
1153
1167
  const httpOptions = {
1154
1168
  baseURL: finalBaseURL,
1155
1169
  timeout: options.timeout,
1156
- headers: options.headers,
1170
+ headers,
1157
1171
  auth: options.auth || this.getDefaultAuth(),
1158
1172
  hooks: options.hooks || this.getDefaultHooks(),
1159
1173
  };
@@ -1216,7 +1230,7 @@ class SeaVerseBackendAPIClient {
1216
1230
  async register(data, options) {
1217
1231
  const config = {
1218
1232
  method: 'POST',
1219
- url: `/api/auth/register`,
1233
+ url: `/sdk/v1/auth/register`,
1220
1234
  data,
1221
1235
  headers: {
1222
1236
  'X-Operation-Id': 'register',
@@ -1234,7 +1248,7 @@ class SeaVerseBackendAPIClient {
1234
1248
  async login(data, options) {
1235
1249
  const config = {
1236
1250
  method: 'POST',
1237
- url: `/api/auth/login`,
1251
+ url: `/sdk/v1/auth/login`,
1238
1252
  data,
1239
1253
  headers: {
1240
1254
  'X-Operation-Id': 'login',
@@ -1252,7 +1266,7 @@ class SeaVerseBackendAPIClient {
1252
1266
  async getCurrentUser(options) {
1253
1267
  const config = {
1254
1268
  method: 'GET',
1255
- url: `/api/auth/me`,
1269
+ url: `/sdk/v1/auth/me`,
1256
1270
  headers: {
1257
1271
  'X-Operation-Id': 'getCurrentUser',
1258
1272
  ...options?.headers,
@@ -1269,7 +1283,7 @@ class SeaVerseBackendAPIClient {
1269
1283
  async logout(options) {
1270
1284
  const config = {
1271
1285
  method: 'POST',
1272
- url: `/api/auth/logout`,
1286
+ url: `/sdk/v1/auth/logout`,
1273
1287
  headers: {
1274
1288
  'X-Operation-Id': 'logout',
1275
1289
  ...options?.headers,
@@ -1286,7 +1300,7 @@ class SeaVerseBackendAPIClient {
1286
1300
  async forgotPassword(data, options) {
1287
1301
  const config = {
1288
1302
  method: 'POST',
1289
- url: `/api/auth/forgot-password`,
1303
+ url: `/sdk/v1/auth/forgot-password`,
1290
1304
  data,
1291
1305
  headers: {
1292
1306
  'X-Operation-Id': 'forgotPassword',
@@ -1304,7 +1318,7 @@ class SeaVerseBackendAPIClient {
1304
1318
  async resetPassword(data, options) {
1305
1319
  const config = {
1306
1320
  method: 'POST',
1307
- url: `/api/auth/reset-password`,
1321
+ url: `/sdk/v1/auth/reset-password`,
1308
1322
  data,
1309
1323
  headers: {
1310
1324
  'X-Operation-Id': 'resetPassword',
@@ -1342,7 +1356,7 @@ class SeaVerseBackendAPIClient {
1342
1356
  async googleCodeToToken(data, options) {
1343
1357
  const config = {
1344
1358
  method: 'POST',
1345
- url: `/api/auth/google/code2token`,
1359
+ url: `/sdk/v1/auth/google/code2token`,
1346
1360
  data,
1347
1361
  headers: {
1348
1362
  'X-Operation-Id': 'googleCodeToToken',
@@ -1374,7 +1388,7 @@ class SeaVerseBackendAPIClient {
1374
1388
  async unlinkGoogle(options) {
1375
1389
  const config = {
1376
1390
  method: 'POST',
1377
- url: `/api/auth/google/unlink`,
1391
+ url: `/sdk/v1/auth/google/unlink`,
1378
1392
  headers: {
1379
1393
  'X-Operation-Id': 'unlinkGoogle',
1380
1394
  ...options?.headers,
@@ -1390,7 +1404,7 @@ class SeaVerseBackendAPIClient {
1390
1404
  async discordCodeToToken(data, options) {
1391
1405
  const config = {
1392
1406
  method: 'POST',
1393
- url: `/api/auth/discord/code2token`,
1407
+ url: `/sdk/v1/auth/discord/code2token`,
1394
1408
  data,
1395
1409
  headers: {
1396
1410
  'X-Operation-Id': 'discordCodeToToken',
@@ -1421,7 +1435,7 @@ class SeaVerseBackendAPIClient {
1421
1435
  async unlinkDiscord(options) {
1422
1436
  const config = {
1423
1437
  method: 'POST',
1424
- url: `/api/auth/discord/unlink`,
1438
+ url: `/sdk/v1/auth/discord/unlink`,
1425
1439
  headers: {
1426
1440
  'X-Operation-Id': 'unlinkDiscord',
1427
1441
  ...options?.headers,
@@ -1437,7 +1451,7 @@ class SeaVerseBackendAPIClient {
1437
1451
  async githubCodeToToken(data, options) {
1438
1452
  const config = {
1439
1453
  method: 'POST',
1440
- url: `/api/auth/github/code2token`,
1454
+ url: `/sdk/v1/auth/github/code2token`,
1441
1455
  data,
1442
1456
  headers: {
1443
1457
  'X-Operation-Id': 'githubCodeToToken',
@@ -1479,7 +1493,7 @@ class SeaVerseBackendAPIClient {
1479
1493
  async unlinkGithub(options) {
1480
1494
  const config = {
1481
1495
  method: 'POST',
1482
- url: `/api/auth/github/unlink`,
1496
+ url: `/sdk/v1/auth/github/unlink`,
1483
1497
  headers: {
1484
1498
  'X-Operation-Id': 'unlinkGithub',
1485
1499
  ...options?.headers,
@@ -1925,24 +1939,38 @@ class AuthModal {
1925
1939
  submitBtn.appendChild(btnText);
1926
1940
  submitBtn.appendChild(btnLoader);
1927
1941
  form.appendChild(submitBtn);
1928
- // Divider
1929
- const divider = document.createElement('div');
1930
- divider.className = 'divider';
1931
- divider.textContent = 'OR SIGN IN WITH';
1932
- form.appendChild(divider);
1933
- // Social buttons grid (Google + GitHub)
1934
- const socialGrid = document.createElement('div');
1935
- socialGrid.className = 'social-buttons-grid';
1936
- // Google button
1937
- const googleBtn = this.createSocialButton('google', 'Google', 'login');
1938
- socialGrid.appendChild(googleBtn);
1939
- // GitHub button
1940
- const githubBtn = this.createSocialButton('github', 'Github', 'login');
1941
- socialGrid.appendChild(githubBtn);
1942
- form.appendChild(socialGrid);
1943
- // Discord button (full width)
1944
- const discordBtn = this.createSocialButton('discord', 'Discord', 'login', true);
1945
- form.appendChild(discordBtn);
1942
+ // OAuth buttons - only show if configured
1943
+ const hasOAuth = this.options.oauthConfig &&
1944
+ (this.options.oauthConfig.google || this.options.oauthConfig.discord || this.options.oauthConfig.github);
1945
+ if (hasOAuth) {
1946
+ // Divider
1947
+ const divider = document.createElement('div');
1948
+ divider.className = 'divider';
1949
+ divider.textContent = 'OR SIGN IN WITH';
1950
+ form.appendChild(divider);
1951
+ // Social buttons grid (Google + GitHub)
1952
+ const socialGrid = document.createElement('div');
1953
+ socialGrid.className = 'social-buttons-grid';
1954
+ // Google button - only if configured
1955
+ if (this.options.oauthConfig?.google) {
1956
+ const googleBtn = this.createSocialButton('google', 'Google', 'login');
1957
+ socialGrid.appendChild(googleBtn);
1958
+ }
1959
+ // GitHub button - only if configured
1960
+ if (this.options.oauthConfig?.github) {
1961
+ const githubBtn = this.createSocialButton('github', 'Github', 'login');
1962
+ socialGrid.appendChild(githubBtn);
1963
+ }
1964
+ // Only add grid if it has buttons
1965
+ if (socialGrid.children.length > 0) {
1966
+ form.appendChild(socialGrid);
1967
+ }
1968
+ // Discord button (full width) - only if configured
1969
+ if (this.options.oauthConfig?.discord) {
1970
+ const discordBtn = this.createSocialButton('discord', 'Discord', 'login', true);
1971
+ form.appendChild(discordBtn);
1972
+ }
1973
+ }
1946
1974
  container.appendChild(form);
1947
1975
  return container;
1948
1976
  }
@@ -2015,24 +2043,38 @@ class AuthModal {
2015
2043
  submitBtn.appendChild(btnText);
2016
2044
  submitBtn.appendChild(btnLoader);
2017
2045
  form.appendChild(submitBtn);
2018
- // Divider
2019
- const divider = document.createElement('div');
2020
- divider.className = 'divider';
2021
- divider.textContent = 'OR SIGN UP WITH';
2022
- form.appendChild(divider);
2023
- // Social buttons grid (Google + GitHub)
2024
- const socialGrid = document.createElement('div');
2025
- socialGrid.className = 'social-buttons-grid';
2026
- // Google button
2027
- const googleBtn = this.createSocialButton('google', 'Google', 'signup');
2028
- socialGrid.appendChild(googleBtn);
2029
- // GitHub button
2030
- const githubBtn = this.createSocialButton('github', 'Github', 'signup');
2031
- socialGrid.appendChild(githubBtn);
2032
- form.appendChild(socialGrid);
2033
- // Discord button (full width)
2034
- const discordBtn = this.createSocialButton('discord', 'Discord', 'signup', true);
2035
- form.appendChild(discordBtn);
2046
+ // OAuth buttons - only show if configured
2047
+ const hasOAuth = this.options.oauthConfig &&
2048
+ (this.options.oauthConfig.google || this.options.oauthConfig.discord || this.options.oauthConfig.github);
2049
+ if (hasOAuth) {
2050
+ // Divider
2051
+ const divider = document.createElement('div');
2052
+ divider.className = 'divider';
2053
+ divider.textContent = 'OR SIGN UP WITH';
2054
+ form.appendChild(divider);
2055
+ // Social buttons grid (Google + GitHub)
2056
+ const socialGrid = document.createElement('div');
2057
+ socialGrid.className = 'social-buttons-grid';
2058
+ // Google button - only if configured
2059
+ if (this.options.oauthConfig?.google) {
2060
+ const googleBtn = this.createSocialButton('google', 'Google', 'signup');
2061
+ socialGrid.appendChild(googleBtn);
2062
+ }
2063
+ // GitHub button - only if configured
2064
+ if (this.options.oauthConfig?.github) {
2065
+ const githubBtn = this.createSocialButton('github', 'Github', 'signup');
2066
+ socialGrid.appendChild(githubBtn);
2067
+ }
2068
+ // Only add grid if it has buttons
2069
+ if (socialGrid.children.length > 0) {
2070
+ form.appendChild(socialGrid);
2071
+ }
2072
+ // Discord button (full width) - only if configured
2073
+ if (this.options.oauthConfig?.discord) {
2074
+ const discordBtn = this.createSocialButton('discord', 'Discord', 'signup', true);
2075
+ form.appendChild(discordBtn);
2076
+ }
2077
+ }
2036
2078
  container.appendChild(form);
2037
2079
  return container;
2038
2080
  }
@@ -2478,9 +2520,11 @@ class AuthModal {
2478
2520
  * Build authorization URL for each provider
2479
2521
  */
2480
2522
  buildAuthUrl(provider, config, state) {
2523
+ // Use default redirectUri if not provided
2524
+ const redirectUri = config.redirectUri || window.location.origin;
2481
2525
  const params = new URLSearchParams({
2482
2526
  client_id: config.clientId,
2483
- redirect_uri: config.redirectUri,
2527
+ redirect_uri: redirectUri,
2484
2528
  state,
2485
2529
  response_type: 'code',
2486
2530
  });