@seayoo-web/gamer-api 1.0.0 → 1.0.3

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/wx.js DELETED
@@ -1,119 +0,0 @@
1
- var a = Object.defineProperty;
2
- var h = (n, i, e) => i in n ? a(n, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[i] = e;
3
- var o = (n, i, e) => h(n, typeof i != "symbol" ? i + "" : i, e);
4
- import { NetRequest as k } from "@seayoo-web/request/wx";
5
- import { G as c, E as u, C as g, c as w, i as x } from "./event-CXcuEQsA.js";
6
- import { isPlainObject as l } from "@seayoo-web/utils";
7
- function m(n) {
8
- return l(n, "openid", "unionid", "weixin_token");
9
- }
10
- class T {
11
- /**
12
- * 创建 WeixinApi 实例
13
- *
14
- * @param baseRequest - Gamer 通用的 request 工具实例,baseUrl 仅仅包含 endpoint + version
15
- * @param autoLogin - 自动登录函数,由上层组件提供
16
- */
17
- constructor(i, e) {
18
- o(this, "req");
19
- o(this, "autoLogin");
20
- this.req = i, this.autoLogin = e;
21
- }
22
- /**
23
- * 微信静默登录,获取 weixinToken / openid / unionid,其中 weixinToken 应该被缓存
24
- *
25
- * 使用场景为:
26
- *
27
- * - 用户通过任意途径打开小程序的任意页面后,如果本地缓存中不存在微信用户身份信息,则自动调用此 API。
28
- * - 调用成功后,应当使用存储能力将 response 中的微信用户身份信息缓存在本地。
29
- *
30
- * 小程序不应当频繁调用此 API。
31
- *
32
- * 由于小程序的存储是以用户维度隔离的,每个微信用户在每个小程序下只需要成功调用一次此 API。
33
- *
34
- * [API文档 weixin/login](https://kdocs.cn/l/cf2mO2uRLqh9?linkname=x17CeNlDQx)
35
- *
36
- * @param wxcode - 微信小程序调用 wx.login 获得的登录凭证
37
- * @param appid - 微信小程序的 Appid,后端 api 可以从请求的 referer 中提取,后续会删除此参数
38
- */
39
- async login(i, e) {
40
- const { data: t, code: s, message: r } = await this.req.post(
41
- "weixin/login",
42
- { code: i, appid: e },
43
- m,
44
- {
45
- message: !1
46
- }
47
- );
48
- return t ?? { error: s, message: r };
49
- }
50
- /**
51
- * 关联游戏账号
52
- *
53
- * 用于从游戏内跳转至小程序时,将微信用户身份和游戏内身份关联起来,使得后续的企业微信客服流程能够知道该微信用户在游戏内的身份。
54
- *
55
- * https://kdocs.cn/l/cf2mO2uRLqh9?linkname=ci73N833Mk
56
- *
57
- * @param weixinToken 调用 login 后,得到的 Weixin Token
58
- * @param gameCode 从游戏内跳转至小程序时,通过请求参数 query 携带的 game_code
59
- */
60
- async linkPlayer(i, e) {
61
- const { ok: t, code: s, message: r } = await this.req.post("weixin/link-player", {
62
- weixin_token: i,
63
- game_code: e
64
- });
65
- return t || { error: s, message: r };
66
- }
67
- }
68
- class L extends c {
69
- constructor(e, t) {
70
- super(e, (t == null ? void 0 : t.version) || "v1", k);
71
- o(this, "weixinToken", "");
72
- /** event api 集合 */
73
- o(this, "event");
74
- /** club api 集合 */
75
- o(this, "club");
76
- /** weixin api 集合 */
77
- o(this, "weixin");
78
- const s = this.autoLogin.bind(this);
79
- this.event = new u(this.req, s), this.club = new g(this.req, s), this.weixin = new T(this.req, s);
80
- }
81
- /**设置 Weixin Token,用于后续请求自动置换 Gamer Token */
82
- setWeixinToken(e) {
83
- return this.weixinToken !== e && (this.weixinToken = e, this.gamerToken = ""), this;
84
- }
85
- /** 读取设置 wexinToken */
86
- getWexinToken() {
87
- return this.weixinToken;
88
- }
89
- /**
90
- * 用世游通行证统一登录能力签发的 idToken 和 weixinToken,自动置换 gamerToken,成功后会自动设置后续 Request Headers
91
- *
92
- * [世游通行证统一登录](https://kdocs.cn/l/cf2mO2uRLqh9?linkname=FJXYgqvLHs)
93
- *
94
- * [世游通行证统一登录 - 微信小程序](https://365.kdocs.cn/l/ccHVuUs0UsZs)
95
- *
96
- * - 此方法通常不需要手动调用,在需要登录的接口调用时会自动执行
97
- * - 为了提高页面执行速度,可以在 setIdToken + setWeixinToken 后立即调用 autoLogin,比如
98
- *
99
- * @example
100
- * ``` js
101
- * gamerApi.setIdToken("xxxxx").setWeixinToken("yyyyyy").autoLogin()
102
- * ```
103
- */
104
- async autoLogin() {
105
- if (this.gamerToken)
106
- return !0;
107
- if (!this.weixinToken || !this.idToken)
108
- return w.error("Missing idToken / weixinToken when call autoLogin()"), !1;
109
- const { data: e } = await this.req.post(
110
- "login-with-token",
111
- { id_token: this.idToken, weixin_token: this.weixinToken },
112
- x
113
- );
114
- return this.gamerToken = (e == null ? void 0 : e.gamer_token) || "", !!this.gamerToken;
115
- }
116
- }
117
- export {
118
- L as GamerApi
119
- };
@@ -1,64 +0,0 @@
1
- import type { NetRequestFactory } from "@seayoo-web/request";
2
- /**
3
- * [Gamer 系统架构](https://365.kdocs.cn/l/chWSTMvxyyCW?from=koa)
4
- *
5
- * [世游用户运营 api 服务](https://365.kdocs.cn/l/cf2mO2uRLqh9)
6
- */
7
- export declare abstract class GamerBaseApi {
8
- protected idToken: string;
9
- protected gamerToken: string;
10
- protected req: ReturnType<NetRequestFactory>;
11
- constructor(endpoint: string, version: string, request: NetRequestFactory);
12
- /** 设置从登录组件获取的 Id Token,用于后续请求自动置换 Gamer Token */
13
- setIdToken(idToken: string): this;
14
- /** 读取已经设置的 idToken */
15
- getIdToken(): string;
16
- /** 读取自动置换的 gamerToken */
17
- getGamerToken(): string;
18
- /**
19
- * 根据 ID Token / Weixin Token 自动置换 Gamer Token
20
- *
21
- * ⚠️ 此方法需要覆盖,根据不同的场景 token 做具体实现
22
- *
23
- * [世游通行证的统一登录机制](https://kdocs.cn/l/cf2mO2uRLqh9?linkname=FJXYgqvLHs)
24
- */
25
- abstract autoLogin(): Promise<boolean>;
26
- /**
27
- * 获取当前 Session 的信息
28
- *
29
- * https://kdocs.cn/l/cf2mO2uRLqh9?linkname=OdGVCdQxEu
30
- */
31
- getSession(): Promise<GamerSession | null>;
32
- /**
33
- * 根据手机号白名单,检查手机号是否允许登录某个游戏
34
- *
35
- * https://kdocs.cn/l/cf2mO2uRLqh9?linkname=OWGSPF3Ysl
36
- */
37
- verifyMobileAllowed(mobile: string): Promise<VerifyMobileResult | null>;
38
- }
39
- export declare function isGamerTokenResponse(data: unknown): data is {
40
- gamer_token: string;
41
- };
42
- interface GamerSession {
43
- /** 世游通行证 ID */
44
- seayoo_user_id?: string;
45
- /** 手机号码(掩码形式) */
46
- seayoo_mobile?: string;
47
- /** 世游通行证用户实名信息(掩码形式) */
48
- seayoo_real_name?: string;
49
- /** Combo ID */
50
- combo_id?: string;
51
- /**
52
- * combo_id 背后的 IdP
53
- *
54
- * 取值参见 [Combo Client REST API 中的 idp](https://kdocs.cn/l/cg0cfHzazsta?linkname=ZVDdf1pe48),仅当 combo_id 有值时才有值
55
- */
56
- combo_idp?: string;
57
- }
58
- interface VerifyMobileResult {
59
- /** 手机号是否允许登录此游戏(游戏 ID 由 Request Header 的 Origin 或 Referer 决定) */
60
- allowed: boolean;
61
- /** 手机号是否已注册世游通行证 */
62
- registered: boolean;
63
- }
64
- export {};
@@ -1,151 +0,0 @@
1
- import type { EFeatureType, EGameItemType, EQuestObjective } from "./event.config";
2
- export declare function isCommonCountResponse(data: unknown): data is {
3
- count: number;
4
- };
5
- interface EngamentsResponse {
6
- engagements: CommentEngagement[] | TeamEngagement[];
7
- }
8
- export interface CommentEngagement {
9
- /** 用户世游通行证 ID */
10
- user_id: string;
11
- /** 用户昵称 */
12
- name: string;
13
- /** 用户头像地址 */
14
- avatar_url: string;
15
- /** 评论信息 */
16
- comment: string;
17
- /** 用户发布弹幕的视频点 */
18
- video_note: number;
19
- /** 用户发布弹幕的时间 */
20
- created_at: number;
21
- }
22
- export interface TeamEngagement {
23
- /** 组队码 */
24
- objective: string;
25
- /** 队长角色名称 */
26
- leader_name: string;
27
- /** 队员数量 */
28
- total_members: number;
29
- }
30
- export declare function isEngamentsResponse(data: unknown): data is EngamentsResponse;
31
- export declare function isUserVisitResponse(data: unknown): data is {
32
- first_visit: boolean;
33
- };
34
- interface UserFeatureStatusResponse {
35
- status: UserFeatureStatus[];
36
- }
37
- export interface UserFeatureStatus {
38
- feature_id: number;
39
- can_engage: boolean;
40
- has_unclaimed_rewards: boolean;
41
- }
42
- export declare function isUserFeatureStatusResponse(data: unknown): data is UserFeatureStatusResponse;
43
- interface UserEngagementsResponse {
44
- engagements: UserEngagement[];
45
- }
46
- export declare function isUserEngagementsResponse(data: unknown): data is UserEngagementsResponse;
47
- export interface UserEngagement {
48
- engagement_id: number;
49
- sequence: number;
50
- feature_id: number;
51
- reward_id: number;
52
- reward_status: "ineligible" | "unaccalimed" | "received";
53
- reward_source: "output" | "engage";
54
- data?: PreregisterEngagementData | LotteryEngagementData | SurveyEngagementData | InviteEngagementData | ShareEngagementData | VoteEngagementData | WeixinSubscribeEngagementData | CashbackEngagementData | GiftCodeEngagementData | TeamEngagementData | QuestEngagementData | LotteryDrawEngagementData;
55
- server_id?: string;
56
- role_id?: string;
57
- created_at: number;
58
- }
59
- interface PreregisterEngagementData {
60
- platforms: string[];
61
- }
62
- interface LotteryEngagementData {
63
- lottery_count: number;
64
- }
65
- interface SurveyEngagementData {
66
- serial_number: number;
67
- }
68
- interface InviteEngagementData {
69
- user_id: string;
70
- name: string;
71
- avatar_url: string;
72
- }
73
- interface ShareEngagementData {
74
- platform: string;
75
- }
76
- interface VoteEngagementData {
77
- option_sn: string;
78
- }
79
- interface WeixinSubscribeEngagementData {
80
- weixin_openid: string;
81
- }
82
- interface CashbackEngagementData {
83
- order_total_amount: string | number;
84
- cashback_total_amount: string | number;
85
- game_item_count: string | number;
86
- }
87
- interface GiftCodeEngagementData {
88
- gift_code: string;
89
- }
90
- interface TeamEngagementData {
91
- team_code: string;
92
- visibility: "private" | "public";
93
- members: {
94
- is_leader: boolean;
95
- role_name: string;
96
- server_name: string;
97
- }[];
98
- }
99
- interface QuestEngagementData {
100
- objective: EQuestObjective;
101
- progress: number;
102
- completion_value?: number;
103
- team?: {
104
- progress: number;
105
- completion_value?: number;
106
- players: {
107
- user_id: number;
108
- role_name: string;
109
- is_leader: boolean;
110
- progress?: number;
111
- }[];
112
- };
113
- }
114
- interface LotteryDrawEngagementData {
115
- tickets: ({
116
- ticket: string;
117
- status: "unknown" | "pending";
118
- } | {
119
- ticket: string;
120
- status: "drawn" | "claimed" | "fail";
121
- reward: LotteryDrawUserReward;
122
- })[];
123
- }
124
- interface LotteryDrawUserReward {
125
- reward_id: number;
126
- reward_item_id: number;
127
- reward_item_name: string;
128
- reward_source: "output" | "engage";
129
- reward_item_type: EGameItemType;
130
- reward_item_icon_url: string;
131
- reward_item_desc?: string;
132
- reward_amount: number;
133
- reward_status: "unaccalimed" | "received" | "failed" | "delivered";
134
- event_id: number;
135
- event_name: string;
136
- feature_id: number;
137
- engagement_id: number;
138
- feature_type: EFeatureType;
139
- receive_time: number;
140
- extra_data?: Record<string, unknown>;
141
- }
142
- export declare function isGetUnlimitQrcodeSceneResponse(data: unknown): data is {
143
- scene: string;
144
- };
145
- export declare function isGetParamsByQrcodeSceneResponse(data: unknown): data is {
146
- params: string;
147
- };
148
- export declare function isGenerateUnlimitQrcodeResponse(data: unknown): data is {
149
- img: string;
150
- };
151
- export {};
@@ -1,48 +0,0 @@
1
- import { type AutoLoginHandler } from "./utils";
2
- import type { NetRequestFactory } from "@seayoo-web/request";
3
- export declare class WeixinApi {
4
- private req;
5
- private autoLogin;
6
- /**
7
- * 创建 WeixinApi 实例
8
- *
9
- * @param baseRequest - Gamer 通用的 request 工具实例,baseUrl 仅仅包含 endpoint + version
10
- * @param autoLogin - 自动登录函数,由上层组件提供
11
- */
12
- constructor(baseRequest: ReturnType<NetRequestFactory>, autoLogin: AutoLoginHandler);
13
- /**
14
- * 微信静默登录,获取 weixinToken / openid / unionid,其中 weixinToken 应该被缓存
15
- *
16
- * 使用场景为:
17
- *
18
- * - 用户通过任意途径打开小程序的任意页面后,如果本地缓存中不存在微信用户身份信息,则自动调用此 API。
19
- * - 调用成功后,应当使用存储能力将 response 中的微信用户身份信息缓存在本地。
20
- *
21
- * 小程序不应当频繁调用此 API。
22
- *
23
- * 由于小程序的存储是以用户维度隔离的,每个微信用户在每个小程序下只需要成功调用一次此 API。
24
- *
25
- * [API文档 weixin/login](https://kdocs.cn/l/cf2mO2uRLqh9?linkname=x17CeNlDQx)
26
- *
27
- * @param wxcode - 微信小程序调用 wx.login 获得的登录凭证
28
- * @param appid - 微信小程序的 Appid,后端 api 可以从请求的 referer 中提取,后续会删除此参数
29
- */
30
- login(wxcode: string, appid: string): Promise<import("./weixin.guards").WeixinLoginResponse | {
31
- error: string;
32
- message: string;
33
- }>;
34
- /**
35
- * 关联游戏账号
36
- *
37
- * 用于从游戏内跳转至小程序时,将微信用户身份和游戏内身份关联起来,使得后续的企业微信客服流程能够知道该微信用户在游戏内的身份。
38
- *
39
- * https://kdocs.cn/l/cf2mO2uRLqh9?linkname=ci73N833Mk
40
- *
41
- * @param weixinToken 调用 login 后,得到的 Weixin Token
42
- * @param gameCode 从游戏内跳转至小程序时,通过请求参数 query 携带的 game_code
43
- */
44
- linkPlayer(weixinToken: string, gameCode: string): Promise<true | {
45
- error: string;
46
- message: string;
47
- }>;
48
- }
package/types/wx.d.ts DELETED
@@ -1,36 +0,0 @@
1
- import { GamerBaseApi } from "./src/base";
2
- import { ClubApi } from "./src/club";
3
- import { EventApi } from "./src/event";
4
- import { WeixinApi } from "./src/wexin";
5
- export declare class GamerApi extends GamerBaseApi {
6
- private weixinToken;
7
- /** event api 集合 */
8
- event: EventApi;
9
- /** club api 集合 */
10
- club: ClubApi;
11
- /** weixin api 集合 */
12
- weixin: WeixinApi;
13
- constructor(endpoint: string, option?: {
14
- version?: string;
15
- });
16
- /**设置 Weixin Token,用于后续请求自动置换 Gamer Token */
17
- setWeixinToken(weixinToken: string): this;
18
- /** 读取设置 wexinToken */
19
- getWexinToken(): string;
20
- /**
21
- * 用世游通行证统一登录能力签发的 idToken 和 weixinToken,自动置换 gamerToken,成功后会自动设置后续 Request Headers
22
- *
23
- * [世游通行证统一登录](https://kdocs.cn/l/cf2mO2uRLqh9?linkname=FJXYgqvLHs)
24
- *
25
- * [世游通行证统一登录 - 微信小程序](https://365.kdocs.cn/l/ccHVuUs0UsZs)
26
- *
27
- * - 此方法通常不需要手动调用,在需要登录的接口调用时会自动执行
28
- * - 为了提高页面执行速度,可以在 setIdToken + setWeixinToken 后立即调用 autoLogin,比如
29
- *
30
- * @example
31
- * ``` js
32
- * gamerApi.setIdToken("xxxxx").setWeixinToken("yyyyyy").autoLogin()
33
- * ```
34
- */
35
- autoLogin(): Promise<boolean>;
36
- }