@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.
@@ -0,0 +1,169 @@
1
+ /** 道具类型 */
2
+ export declare const enum GamerItemType {
3
+ /** 活动道具 */
4
+ EventItem = "event_item",
5
+ /** 游戏内道具 */
6
+ GameItem = "game_item",
7
+ /** 实物 */
8
+ PhysicalItem = "physical_item",
9
+ /** 微信红包 */
10
+ WeixinHongbao = "weixin_hongbao",
11
+ /** 礼包码 */
12
+ GiftCode = "gift_code",
13
+ /** 抽奖券 */
14
+ LotteryTicket = "lottery_ticket",
15
+ /** 空奖励 */
16
+ VoidItem = "void_item"
17
+ }
18
+ /** 参与活动的账号类型 */
19
+ export declare const enum EngageAccountType {
20
+ /** 世游通行证 ID / Combo ID */
21
+ UserId = "user_id",
22
+ /** 游戏角色 ID */
23
+ RoleId = "role_id"
24
+ }
25
+ /** 玩法刷新周期类型 */
26
+ export declare const enum EventPeriodType {
27
+ None = "none",
28
+ Daily = "daily",
29
+ Weekly = "weekly",
30
+ Monthly = "monthly"
31
+ }
32
+ /** 活动玩法类型 */
33
+ export declare const enum FeatureType {
34
+ /** 预约 */
35
+ Preregister = "preregister",
36
+ /** 抽奖 */
37
+ Lottery = "lottery",
38
+ /** 问卷 */
39
+ Survey = "survey",
40
+ /** 邀请 */
41
+ Invite = "invite",
42
+ /** 分享 */
43
+ Share = "share",
44
+ /** 关注社交媒体 */
45
+ Follow = "follow",
46
+ /** 微信小程序订阅消息 */
47
+ Subscribe = "weixin_subscribe",
48
+ /** 弹幕/评论 */
49
+ Comment = "comment",
50
+ /** 投票 */
51
+ Vote = "vote",
52
+ /** 礼包码 */
53
+ GiftCode = "gift_code",
54
+ /** 注册 */
55
+ Register = "register",
56
+ /** 受邀注册 */
57
+ InvitedRegister = "invited_register",
58
+ /** 领奖 */
59
+ ClaimRewards = "claim_rewards",
60
+ /** 充值返还 */
61
+ Cashback = "cashback",
62
+ /** 任务 */
63
+ Quest = "quest",
64
+ /** 组队 */
65
+ Team = "team",
66
+ /** 开奖 */
67
+ LotteryDraw = "lottery_draw"
68
+ }
69
+ /** 任务玩法的目标类型 */
70
+ export declare const enum QuestObjective {
71
+ /** 累计游戏内活跃值 */
72
+ Active = "player_active_points",
73
+ /** 累计登录,单位 人天 */
74
+ Login = "player_login_days",
75
+ /** 累计充值金额 */
76
+ OrderAmount = "order_total_amount",
77
+ /** 社区发帖数量 */
78
+ Posts = "community_posts",
79
+ /** 社区评论数量 */
80
+ Comments = "community_comments"
81
+ }
82
+ /** 投票数据来源 */
83
+ export declare const enum VoteOptionSource {
84
+ /** 官方上传 */
85
+ System = "system",
86
+ /** 用户投稿 */
87
+ UserSubmission = "user_submission",
88
+ /** 投票入围 */
89
+ Shortlisted = "shortlisted"
90
+ }
91
+ /** 奖励领取状态(不含发货状态和领取失败) */
92
+ export declare const enum RewardStatusPrefix {
93
+ /** 未获得奖励 */
94
+ Ineligible = "ineligible",
95
+ /** 奖励未领取 */
96
+ Unaccalimed = "unaccalimed",
97
+ /** 奖励已领取 */
98
+ Received = "received"
99
+ }
100
+ /** 已获得实物奖励的奖励状态 */
101
+ export declare const enum RewardStatusSuffix {
102
+ /** 奖励未领取 */
103
+ Unaccalimed = "unaccalimed",
104
+ /** 奖励已领取 */
105
+ Received = "received",
106
+ /** 奖励发放失败 */
107
+ Failed = "failed",
108
+ /** 奖励已发货 */
109
+ Delivered = "delivered"
110
+ }
111
+ export declare const enum CliamRewardStatus {
112
+ /** 未获得奖励 */
113
+ Ineligible = "ineligible",
114
+ /** 奖励未领取 */
115
+ Unaccalimed = "unaccalimed",
116
+ /** 奖励已领取 */
117
+ Received = "received",
118
+ /** 奖励发放失败 */
119
+ Failed = "failed"
120
+ }
121
+ /** 奖励来源 */
122
+ export declare const enum RewardSoure {
123
+ /** 玩法产出奖励 */
124
+ Output = "output",
125
+ /** 玩法参与奖励 */
126
+ Engage = "engage"
127
+ }
128
+ /** 组队玩法中队伍的可见性 */
129
+ export declare const enum TeamVisibility {
130
+ /** 私有队伍 */
131
+ Private = "private",
132
+ /** 公开队伍 */
133
+ Public = "public"
134
+ }
135
+ /** 抽奖券状态 */
136
+ export declare const enum LotteryTicketStatus {
137
+ /** 未知状态 */
138
+ Unknown = "unknown",
139
+ /** 等待开奖 */
140
+ Pending = "pending",
141
+ /** 已开奖,待领奖 */
142
+ Drawn = "drawn",
143
+ /** 已领奖 */
144
+ Claimed = "claimed",
145
+ /** 领奖失败 */
146
+ Fail = "fail"
147
+ }
148
+ /** 组队玩法队伍操作类型 */
149
+ export declare const enum TeamAction {
150
+ /** 发起组队 */
151
+ Assemble = "assemble",
152
+ /** 加入队伍 */
153
+ Join = "join",
154
+ /** 解散队伍 */
155
+ Disband = "disband",
156
+ /** 修改队伍可见性 */
157
+ ChangeVisibility = "change_visibility",
158
+ /** 查询组队信息 */
159
+ Query = "query"
160
+ }
161
+ /** 抽奖券玩法操作类型 */
162
+ export declare const enum LotteryDrawAction {
163
+ /** 查询抽奖券 */
164
+ Query = "query",
165
+ /** 开奖 */
166
+ Draw = "draw",
167
+ /** 领奖 */
168
+ Claim = "claim"
169
+ }
@@ -0,0 +1,37 @@
1
+ import type { ClaimedItem, CommentEngagement, EngageResponse, TeamEngagement, UserEngagement, UserFeatureStatus, UserReward, VerifyMobileResult } from "./event.define";
2
+ import type { CliamRewardStatus } from "./event.enums";
3
+ export declare function isVerifyMobileResponse(data: unknown): data is VerifyMobileResult;
4
+ export declare function isCommonCountResponse(data: unknown): data is {
5
+ count: number;
6
+ };
7
+ export declare function isEngamentsResponse(data: unknown): data is {
8
+ engagements: CommentEngagement[] | TeamEngagement[];
9
+ };
10
+ export declare function isUserVisitResponse(data: unknown): data is {
11
+ first_visit: boolean;
12
+ };
13
+ export declare function isUserFeatureStatusResponse(data: unknown): data is {
14
+ status: UserFeatureStatus[];
15
+ };
16
+ export declare function isUserEngagementsResponse(data: unknown): data is {
17
+ engagements: UserEngagement[];
18
+ };
19
+ export declare function isEngageResponse(data: unknown): data is EngageResponse;
20
+ export declare function isClaimRewardsResponse(data: unknown): data is {
21
+ claimed_items: ClaimedItem[];
22
+ };
23
+ export declare function isClaimWeixinHongbaoResponse(data: unknown): data is {
24
+ reward_status: CliamRewardStatus;
25
+ };
26
+ export declare function isGetUserRewardsResponse(data: unknown): data is {
27
+ user_rewards: UserReward[];
28
+ };
29
+ export declare function isGetUnlimitQrcodeSceneResponse(data: unknown): data is {
30
+ scene: string;
31
+ };
32
+ export declare function isGetParamsByQrcodeSceneResponse(data: unknown): data is {
33
+ params: string;
34
+ };
35
+ export declare function isGenerateUnlimitQrcodeResponse(data: unknown): data is {
36
+ img: string;
37
+ };
@@ -0,0 +1,82 @@
1
+ import type { StorageHelper } from "./token.define";
2
+ import type { NetRequestFactory } from "@seayoo-web/request";
3
+ export * from "./token.define";
4
+ /**
5
+ * auth 管理工具 + request 工具
6
+ *
7
+ * 核心概念如下:
8
+ *
9
+ * - [ID Token](https://365.kdocs.cn/l/ctrXywvA1Wfd)
10
+ * - [Gamer Token](https://365.kdocs.cn/l/crZwOsI54RBH)
11
+ * - [Weixin Token](https://kdocs.cn/l/cf2mO2uRLqh9?linkname=YtzQpmRQ0v)
12
+ */
13
+ export declare class AuthToken {
14
+ private $idToken;
15
+ private $weixinToken;
16
+ private $gamerToken;
17
+ private inWxMiniProgram;
18
+ req: ReturnType<NetRequestFactory>;
19
+ storage: StorageHelper;
20
+ constructor({ endpoint, NetRequest, storage, }: {
21
+ /**
22
+ * 服务端点
23
+ *
24
+ * https://kdocs.cn/l/cf2mO2uRLqh9?linkname=k2iGGXbfov
25
+ */
26
+ endpoint: string;
27
+ /** request 工具 */
28
+ NetRequest: NetRequestFactory;
29
+ /** 本地存储服务 */
30
+ storage: StorageHelper;
31
+ });
32
+ /** 当前是否为登录状态,即是否拥有 gamerToken */
33
+ get isLogined(): boolean;
34
+ /** 读取已经设置的 idToken */
35
+ get idToken(): string;
36
+ /** 设置从登录组件获取的 Id Token,用于后续请求自动置换 Gamer Token */
37
+ set idToken(value: string);
38
+ /** 读取设置 wexinToken */
39
+ get weixinToken(): string;
40
+ /**
41
+ * 设置 Weixin Token,用于后续请求自动置换 Gamer Token
42
+ *
43
+ * 仅仅在微信小程序模式下有效
44
+ */
45
+ set weixinToken(value: string);
46
+ /** 读取自动置换的 gamerToken */
47
+ get gamerToken(): string;
48
+ /** 直接写入 Gamer Token,通常在 ComboWebView 中读取 url 中的 gamer_token 传入 */
49
+ set gamerToken(value: string);
50
+ /**
51
+ * 用世游通行证统一登录能力签发的 ID Token / Weixin Token,自动置换 Gamer Token,成功后会自动设置后续 Request Headers
52
+ *
53
+ * [世游通行证统一登录](https://kdocs.cn/l/cf2mO2uRLqh9?linkname=FJXYgqvLHs)
54
+ *
55
+ * [世游通行证统一登录 - Web 站点](https://365.kdocs.cn/l/cf57sp1qLlZh)
56
+ *
57
+ * [世游通行证统一登录 - 微信小程序](https://365.kdocs.cn/l/ccHVuUs0UsZs)
58
+ *
59
+ * - 此方法通常不需要手动调用,在需要登录的接口调用时会自动执行
60
+ * - 为了提高页面执行速度,可以在设置 Token 后立即调用 autoLogin
61
+ */
62
+ autoLogin(): Promise<boolean>;
63
+ /**
64
+ * 获取当前 Session 的信息
65
+ *
66
+ * https://kdocs.cn/l/cf2mO2uRLqh9?linkname=OdGVCdQxEu
67
+ */
68
+ getSession(): Promise<import("./token.define").GamerSession | null>;
69
+ /**
70
+ * 实名认证
71
+ *
72
+ * https://kdocs.cn/l/cf2mO2uRLqh9?linkname=kZYnwX6RcF
73
+ */
74
+ authRealName(option: {
75
+ /** 用户输入的真实姓名。明文或者密文 */
76
+ real_name: string;
77
+ /** 用户输入的身份证号码。明文或者密文 */
78
+ identity_card: string;
79
+ /** 预留参数,是否加密 real_name 和 identity_card,加密的密钥应当使用 api 服务的 ECDSA Public Key */
80
+ encrypted?: boolean;
81
+ }): Promise<import("./token.define").GamerSession | null>;
82
+ }
@@ -0,0 +1,29 @@
1
+ export type PopupFn = (option: {
2
+ title?: string;
3
+ content: string;
4
+ cancelText?: string;
5
+ confirmText: string;
6
+ onCancel?: () => void;
7
+ onConfirm: () => void;
8
+ }) => void;
9
+ export type ToastFn = (content: string, timeout?: number) => void;
10
+ export type StorageHelper = {
11
+ set(key: string, value: string): Promise<boolean>;
12
+ get(key: string): Promise<string | null>;
13
+ };
14
+ export interface GamerSession {
15
+ /** 世游通行证 ID */
16
+ seayoo_user_id?: string;
17
+ /** 手机号码(掩码形式) */
18
+ seayoo_mobile?: string;
19
+ /** 世游通行证用户实名信息(掩码形式) */
20
+ seayoo_real_name?: string;
21
+ /** Combo ID */
22
+ combo_id?: string;
23
+ /**
24
+ * combo_id 背后的 IdP
25
+ *
26
+ * 取值参见 [Combo Client REST API 中的 idp](https://kdocs.cn/l/cg0cfHzazsta?linkname=ZVDdf1pe48),仅当 combo_id 有值时才有值
27
+ */
28
+ combo_idp?: string;
29
+ }
@@ -0,0 +1,5 @@
1
+ import type { GamerSession } from "./token.define";
2
+ export declare function isGamerTokenResponse(data: unknown): data is {
3
+ gamer_token: string;
4
+ };
5
+ export declare function isGetSessionResponse(data: unknown): data is GamerSession;
@@ -1,9 +1,5 @@
1
- /**
2
- * 自动登录函数(获取 Gamer Token)
3
- */
4
- export type AutoLoginHandler = () => Promise<boolean>;
5
- /**
6
- * 将 endpoint & verison 转成 request base url
7
- */
8
- export declare function getBaseUrl(endpoint: string, version?: string): string;
9
1
  export declare const console: Pick<Console, "log" | "error" | "warn">;
2
+ /** 检测是否在 combo webview */
3
+ export declare function inComboWebview(): boolean;
4
+ /** 检测是否为微信小程序环境 */
5
+ export declare function isWeixinMiniProgram(): boolean;
@@ -0,0 +1,83 @@
1
+ import type { AuthToken } from "./token";
2
+ import type { WeixinWebLoginErrorCode } from "./weixin.define";
3
+ import type { RequestInteralError } from "@seayoo-web/request";
4
+ export * from "./weixin.define";
5
+ export declare class WeixinApi {
6
+ private token;
7
+ private appid;
8
+ private req;
9
+ /**
10
+ * 创建微信相关功能接口
11
+ *
12
+ * - authToken 需要导入 AuthToken 进行初始化后传入
13
+ * - appid 可以静态设置,也可以在小程序中动态获取,见下示例代码
14
+ *
15
+ * ```js
16
+ * const info = wx.getAccountInfoSync();
17
+ * console.log(info.miniProgram.appId)
18
+ * ```
19
+ *
20
+ * https://developers.weixin.qq.com/miniprogram/dev/api/open-api/account-info/wx.getAccountInfoSync.html
21
+ */
22
+ constructor(authToken: AuthToken, appid: string);
23
+ /**
24
+ * 检查缓存中的登录数据
25
+ *
26
+ * 如果没有缓存或缓存数据错误,则需要调用 [wx.login](https://developers.weixin.qq.com/miniprogram/dev/api/open-api/login/wx.login.html) 后调用 login 方法
27
+ *
28
+ * 也可以直接调用 login 方法,并传入 wxcode 的读取函数
29
+ */
30
+ getLoginCache(): Promise<import("./weixin.define").WeixinLoginResponse | null>;
31
+ /**
32
+ * 小程序页面微信静默登录,获取 weixinToken / openid / unionid。
33
+ *
34
+ * 使用场景:
35
+ *
36
+ * - 小程序的任意页面打开后应该优先调用此方法以获取登录状态
37
+ *
38
+ * 注意:
39
+ *
40
+ * - 登录成功后会将登录信息缓存到本地,重复或并发调用不会引起任何副作用。
41
+ * - 由于小程序的存储是以用户维度隔离的,每个微信用户在每个小程序下只要成功调用一次此 API 就会缓存请求结果。
42
+ * - 微信公众号网页授权请使用 webLogin 方法
43
+ *
44
+ * https://kdocs.cn/l/cf2mO2uRLqh9?linkname=GwIZ0givCb
45
+ *
46
+ * @param wxLoginCodeGetter - 微信小程序调用 [wx.login](https://developers.weixin.qq.com/miniprogram/dev/api/open-api/login/wx.login.html) 获得的登录凭证
47
+ */
48
+ login(wxLoginCodeGetter: () => Promise<string>): Promise<import("./weixin.define").WeixinLoginResponse | {
49
+ error: RequestInteralError | "invalid_weixin_appid" | "invalid_weixin_code";
50
+ }>;
51
+ /**
52
+ * 在微信内嵌网页中调用微信公众号授权登录【暂未启用】
53
+ *
54
+ * 注意:
55
+ *
56
+ * - 登录回调地址强制是当前页面,包括 location search 和 location hash 部分
57
+ * - 登录跳转返回 code 后,会将 code 从 url 中删除以防止 code 泄露,如需设置分享则需要在此方法执行完毕之后
58
+ *
59
+ * 官方参考资料:
60
+ *
61
+ * - [微信网页开发 / 网页授权](https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html)
62
+ *
63
+ * @param scope - 网页授权作用域
64
+ * - snsapi_base 不弹出授权页面,用户无感知,只能获取用户 openid,如果需要获取 unionid 则需要 snsapi_userinfo
65
+ * - snsapi_userinfo 【默认】弹出授权页面,可拿到 openid、unionid、昵称、头像等信息,但用户也可能会拒绝授权
66
+ */
67
+ webLogin(scope?: "snsapi_base" | "snsapi_userinfo"): Promise<import("./weixin.define").WeixinLoginResponse | {
68
+ error: WeixinWebLoginErrorCode;
69
+ } | {
70
+ error: RequestInteralError | "invalid_weixin_appid" | "invalid_weixin_code";
71
+ } | undefined>;
72
+ /**
73
+ * 关联游戏账号,无返回值,全程静默
74
+ *
75
+ * 用于从游戏内跳转至小程序时,将微信用户身份和游戏内身份关联起来,使得后续的企业微信客服流程能够知道该微信用户在游戏内的身份。
76
+ *
77
+ * https://kdocs.cn/l/cf2mO2uRLqh9?linkname=ci73N833Mk
78
+ *
79
+ * @param weixinToken 调用 login 后,得到的 weixinToken,如果 weixinToken 为空则跳过不处理
80
+ * @param gameCode 从游戏内跳转至小程序时,通过请求参数 query 携带的 game_code,如果值为空则跳过不处理
81
+ */
82
+ linkPlayer(weixinToken: string, gameCode: string): Promise<void>;
83
+ }
@@ -0,0 +1,41 @@
1
+ export interface WeixinLoginResponse {
2
+ /** 微信小程序下,用户的 openid */
3
+ openid: string;
4
+ /** 微信小程序所在的微信开放平台账号下,用户的 unionid */
5
+ unionid: string;
6
+ /**
7
+ * Gamer 为这个微信小程序用户签发的 Weixin Token。长期有效
8
+ *
9
+ * 对 Weixin Token 的详细描述请阅读 [世游用户运营 - JWT 场景与规范](https://365.kdocs.cn/l/cbxbzWc6zSgY)
10
+ */
11
+ weixin_token: string;
12
+ }
13
+ /**
14
+ * 微信web登录错误码
15
+ *
16
+ * https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html
17
+ */
18
+ export declare const enum WeixinWebLoginErrorCode {
19
+ /** redirect_uri域名与后台配置不一致 */
20
+ RedirectUriDisMatch = "10003",
21
+ /** 不支持微信开放平台的 Appid,请使用公众号Appid */
22
+ AppidError = "10016",
23
+ /** 公众号未授权第三方平台,请检查授权状态 */
24
+ AuthorizationError = "10015",
25
+ /** 此公众号并没有这些 scope 的权限 */
26
+ NoRightForScope = "10005",
27
+ /** 操作太频繁了,请稍后重试 */
28
+ Frequently = "10009",
29
+ /** 此公众号被封禁 */
30
+ AppBanded = "10004",
31
+ /** 必须关注此测试号 */
32
+ ShouldFllow = "10006",
33
+ /** scope不能为空 */
34
+ ScopeNull = "10010",
35
+ /** redirect_uri不能为空 */
36
+ RedirectUriNull = "10011",
37
+ /** appid不能为空 */
38
+ AppidNull = "10012",
39
+ /** state不能为空 */
40
+ StateNull = "10013"
41
+ }
@@ -1,13 +1,2 @@
1
- export interface WeixinLoginResponse {
2
- /** 微信小程序下,用户的 openid */
3
- openid: string;
4
- /** 微信小程序所在的微信开放平台账号下,用户的 unionid */
5
- unionid: string;
6
- /**
7
- * Gamer 为这个微信小程序用户签发的 Weixin Token。长期有效
8
- *
9
- * 对 Weixin Token 的详细描述请阅读 [世游用户运营 - JWT 场景与规范](https://365.kdocs.cn/l/cbxbzWc6zSgY)
10
- */
11
- weixin_token: string;
12
- }
1
+ import type { WeixinLoginResponse } from "./weixin.define";
13
2
  export declare function isWeixinLoginResponse(data: unknown): data is WeixinLoginResponse;