@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 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
- logout();
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, eventId);
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, appId);
57
+ const weixinApi = new WeixinApi(authToken, SY_APP_ID);
58
+ const loginSDK = new GamerWeixinAuth(authToken, weixinApi);
73
59
 
74
- // 登录
75
- export function login() {
76
- // idToken 通过通行证登录组件获取
77
- const idToken = await accountLogin();
78
- if(!idToken) {
79
- return
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
- // 获取 weixinToken,成功时返回 { weixin_token, open_id, union_id }
82
- const result = await weixinApi.login();
83
- if(!("weixin_token" in result)) {
84
- return
75
+ // 意外错误进行上报
76
+ if (rawError) {
77
+ captureException(sentryError, {
78
+ extra: sentryExtra,
79
+ tags: sentryTags,
80
+ });
85
81
  }
86
- // 设置
87
- authToken.idToken = idToken
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
@@ -1501,6 +1501,7 @@ const In = {
1501
1501
  avatar_url: e.string(),
1502
1502
  title: e.string().optional(),
1503
1503
  content: e.string(),
1504
+ content_text_count: e.number(),
1504
1505
  summary: e.string(),
1505
1506
  like_num: e.number(),
1506
1507
  comments_num: e.number(),
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.16",
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.3",
26
- "@seayoo-web/tsconfig": "^1.0.3",
27
- "@seayoo-web/request": "^3.0.3",
28
- "@seayoo-web/utils": "^3.4.4",
29
- "@seayoo-web/scripts": "^2.0.12"
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.3",
33
- "@seayoo-web/request": "^3.0.3",
34
- "@seayoo-web/utils": "^3.4.4"
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",
@@ -57,6 +57,8 @@ export interface Post {
57
57
  title?: string;
58
58
  /** 帖子内容,富文本 HTML 格式 */
59
59
  content: string;
60
+ /** 帖子内容纯文本长度,不含 html 标签部分 */
61
+ content_text_count: number;
60
62
  /** 帖子内容,纯文本格式 */
61
63
  summary: string;
62
64
  /** 点赞数量 */