@seayoo-web/gamer-api 2.0.16 → 2.0.18
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 +36 -54
- package/dist/index.js +1 -0
- package/package.json +10 -9
- package/types/src/community.define.d.ts +2 -0
package/README.md
CHANGED
|
@@ -6,11 +6,17 @@
|
|
|
6
6
|
import { NetRequest } from "@seayoo-web/request";
|
|
7
7
|
import { AuthToken, EventApi, ClubApi, CommunityApi } from "@seayoo-web/gamer-api";
|
|
8
8
|
import { captureException } from "@sentry/vue";
|
|
9
|
+
import { GamerWebAuth } from "@seayoo-web/login";
|
|
9
10
|
|
|
10
11
|
const authToken = new AuthToken(SY_GAMER_API, NetRequest);
|
|
11
12
|
const eventApi = new EventApi(authToken, SY_EVENT_ID);
|
|
12
13
|
const clubApi = new ClubApi(authToken);
|
|
13
14
|
const communityApi = new CommunityApi(authToken);
|
|
15
|
+
const loginSDK = new GamerWebAuth(autoToken, {
|
|
16
|
+
anonymous: false,
|
|
17
|
+
hidePasswordLogin: false,
|
|
18
|
+
// 更多配置 @seayoo-web/login
|
|
19
|
+
});
|
|
14
20
|
|
|
15
21
|
// 调整请求配置
|
|
16
22
|
authToken.req.setConfig({
|
|
@@ -19,9 +25,8 @@ authToken.req.setConfig({
|
|
|
19
25
|
},
|
|
20
26
|
errorHandler({ status, rawError, sentryError, sentryTags, sentryExtra }) {
|
|
21
27
|
if (status === 401) {
|
|
22
|
-
|
|
23
|
-
//
|
|
24
|
-
//
|
|
28
|
+
// 提示或直接登录
|
|
29
|
+
// loginSDK.login()
|
|
25
30
|
return;
|
|
26
31
|
}
|
|
27
32
|
// 意外错误进行上报
|
|
@@ -34,29 +39,8 @@ authToken.req.setConfig({
|
|
|
34
39
|
},
|
|
35
40
|
});
|
|
36
41
|
|
|
37
|
-
// 触发登录
|
|
38
|
-
export async function login() {
|
|
39
|
-
// idToken 通过通行证登录组件获取
|
|
40
|
-
const idToken = await accountLogin();
|
|
41
|
-
if (idToken) {
|
|
42
|
-
authToken.idToken = idToken;
|
|
43
|
-
// 可选自动登录调用,后续每个 api 都会自动检查并 autoLogin
|
|
44
|
-
authToken.autoLogin();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// 获取用户数据
|
|
49
|
-
export async function getUserInfo() {
|
|
50
|
-
return authToken.isLoggedIn ? await authToken.getSession() : null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// 退出登录(同步操作)
|
|
54
|
-
export function logout() {
|
|
55
|
-
authToken.logout();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
42
|
// 导出供其他功能使用
|
|
59
|
-
export { eventApi, clubApi, communityApi };
|
|
43
|
+
export { eventApi, clubApi, communityApi, loginSDK };
|
|
60
44
|
```
|
|
61
45
|
|
|
62
46
|
## 小程序初始化
|
|
@@ -64,42 +48,40 @@ export { eventApi, clubApi, communityApi };
|
|
|
64
48
|
```js
|
|
65
49
|
import { NetRequest } from "@seayoo-web/request/wx";
|
|
66
50
|
import { AuthToken, EventApi, ClubApi, WeixinApi } from "@seayoo-web/gamer-api";
|
|
51
|
+
import { GamerWeixinAuth } from "@seayoo-web/login";
|
|
67
52
|
|
|
68
53
|
const authToken = new AuthToken(SY_GAMER_API, NetRequest);
|
|
69
|
-
const eventApi = new EventApi(authToken,
|
|
54
|
+
const eventApi = new EventApi(authToken, SY_EVENT_ID);
|
|
70
55
|
const clubApi = new ClubApi(authToken);
|
|
71
56
|
const communityApi = new CommunityApi(authToken);
|
|
72
|
-
const weixinApi = new WeixinApi(authToken,
|
|
57
|
+
const weixinApi = new WeixinApi(authToken, SY_APP_ID);
|
|
58
|
+
const loginSDK = new GamerWeixinAuth(authToken, weixinApi);
|
|
73
59
|
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
60
|
+
// 调整请求配置
|
|
61
|
+
authToken.req.setConfig({
|
|
62
|
+
messageHandler(_, message) {
|
|
63
|
+
toast(message);
|
|
64
|
+
},
|
|
65
|
+
errorHandler({ status, rawError, sentryError, sentryTags, sentryExtra }) {
|
|
66
|
+
if (status === 401) {
|
|
67
|
+
// 提示或直接登录
|
|
68
|
+
if(loginSDK.hasLoginToken) {
|
|
69
|
+
loginSDK.login()
|
|
70
|
+
} else {
|
|
71
|
+
// 跳转到用户手机号授权页面
|
|
72
|
+
}
|
|
73
|
+
return;
|
|
80
74
|
}
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
75
|
+
// 意外错误进行上报
|
|
76
|
+
if (rawError) {
|
|
77
|
+
captureException(sentryError, {
|
|
78
|
+
extra: sentryExtra,
|
|
79
|
+
tags: sentryTags,
|
|
80
|
+
});
|
|
85
81
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
authToken.weixinToken = result.weixin_token;
|
|
89
|
-
// 可选自动登录调用,后续每个 api 都会自动检查并 autoLogin
|
|
90
|
-
authToken.autoLogin();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// 获取用户数据
|
|
94
|
-
export async function getUserInfo() {
|
|
95
|
-
return authToken.isLoggedIn ? await authToken.getSession() : null;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// 退出登录(同步操作)
|
|
99
|
-
export function logout() {
|
|
100
|
-
authToken.logout();
|
|
101
|
-
}
|
|
82
|
+
},
|
|
83
|
+
});
|
|
102
84
|
|
|
103
85
|
// 导出供其他功能使用
|
|
104
|
-
export { eventApi, clubApi, communityApi, weixinApi };
|
|
86
|
+
export { eventApi, clubApi, communityApi, weixinApi, loginSDK };
|
|
105
87
|
```
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seayoo-web/gamer-api",
|
|
3
3
|
"description": "agent for gamer api",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.18",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "index.ts",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"module": "./dist/index.js",
|
|
9
9
|
"types": "./types/index.d.ts",
|
|
10
|
+
"sideEffects": false,
|
|
10
11
|
"files": [
|
|
11
12
|
"dist",
|
|
12
13
|
"types",
|
|
@@ -22,16 +23,16 @@
|
|
|
22
23
|
"license": "MIT",
|
|
23
24
|
"devDependencies": {
|
|
24
25
|
"@types/node": "^22.13.1",
|
|
25
|
-
"@seayoo-web/combo-webview": "^2.5.
|
|
26
|
-
"@seayoo-web/
|
|
27
|
-
"@seayoo-web/request": "^3.0.
|
|
28
|
-
"@seayoo-web/
|
|
29
|
-
"@seayoo-web/
|
|
26
|
+
"@seayoo-web/combo-webview": "^2.5.4",
|
|
27
|
+
"@seayoo-web/utils": "^3.5.1",
|
|
28
|
+
"@seayoo-web/request": "^3.0.4",
|
|
29
|
+
"@seayoo-web/scripts": "^2.4.0",
|
|
30
|
+
"@seayoo-web/tsconfig": "^1.0.3"
|
|
30
31
|
},
|
|
31
32
|
"peerDependencies": {
|
|
32
|
-
"@seayoo-web/combo-webview": "^2.5.
|
|
33
|
-
"@seayoo-web/request": "^3.0.
|
|
34
|
-
"@seayoo-web/utils": "^3.
|
|
33
|
+
"@seayoo-web/combo-webview": "^2.5.4",
|
|
34
|
+
"@seayoo-web/request": "^3.0.4",
|
|
35
|
+
"@seayoo-web/utils": "^3.5.1"
|
|
35
36
|
},
|
|
36
37
|
"scripts": {
|
|
37
38
|
"prebuild": "pnpm -F request build && pnpm -F combo-webview build",
|