@seaverse/auth-sdk 0.1.5 → 0.2.0
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 +555 -210
- package/dist/auth-modal.css +1 -1
- package/dist/index.cjs +63 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +34 -5
- package/dist/index.js +63 -35
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -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
|
|
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: `/
|
|
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: `/
|
|
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: `/
|
|
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: `/
|
|
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: `/
|
|
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: `/
|
|
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: `/
|
|
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: `/
|
|
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: `/
|
|
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: `/
|
|
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: `/
|
|
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: `/
|
|
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
|
-
//
|
|
1929
|
-
const
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
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
|
}
|