@seayoo-web/gamer-api 1.0.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 +11 -0
- package/dist/event-CXcuEQsA.js +648 -0
- package/dist/index.js +42 -0
- package/dist/wx.js +119 -0
- package/package.json +52 -0
- package/types/index.d.ts +29 -0
- package/types/src/base.d.ts +64 -0
- package/types/src/club.d.ts +67 -0
- package/types/src/club.guards.d.ts +75 -0
- package/types/src/community.d.ts +0 -0
- package/types/src/community.guards.d.ts +0 -0
- package/types/src/event.config.d.ts +228 -0
- package/types/src/event.d.ts +151 -0
- package/types/src/event.other.d.ts +151 -0
- package/types/src/utils.d.ts +9 -0
- package/types/src/weixin.guards.d.ts +13 -0
- package/types/src/wexin.d.ts +48 -0
- package/types/wx.d.ts +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,648 @@
|
|
|
1
|
+
var m = Object.defineProperty;
|
|
2
|
+
var g = (e, r, t) => r in e ? m(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
|
|
3
|
+
var s = (e, r, t) => g(e, typeof r != "symbol" ? r + "" : r, t);
|
|
4
|
+
import { useConsole as f, isPlainObject as n, pruneObject as u } from "@seayoo-web/utils";
|
|
5
|
+
function y(e, r) {
|
|
6
|
+
const t = e.replace(/(?:^https?:\/\/|\/*$)/gi, ""), i = r ? `/${r}` : "";
|
|
7
|
+
return `https://${(t + i).replace(/\/{2,}/g, "")}`;
|
|
8
|
+
}
|
|
9
|
+
const _e = f("GamerApiSDK");
|
|
10
|
+
class me {
|
|
11
|
+
constructor(r, t, i) {
|
|
12
|
+
s(this, "idToken", "");
|
|
13
|
+
s(this, "gamerToken", "");
|
|
14
|
+
s(this, "req");
|
|
15
|
+
this.req = i({
|
|
16
|
+
baseURL: y(r, t),
|
|
17
|
+
timeout: 1e4,
|
|
18
|
+
responseRule: {
|
|
19
|
+
ok: { resolve: "body" },
|
|
20
|
+
failed: {
|
|
21
|
+
resolve: "json",
|
|
22
|
+
statusField: "error",
|
|
23
|
+
messageField: "message"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
requestTransformer: (_) => {
|
|
27
|
+
this.gamerToken && (_.headers.Authorization = `Bearer ${this.gamerToken}`);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/** 设置从登录组件获取的 Id Token,用于后续请求自动置换 Gamer Token */
|
|
32
|
+
setIdToken(r) {
|
|
33
|
+
return r !== this.idToken && (this.gamerToken = "", this.idToken = r), this;
|
|
34
|
+
}
|
|
35
|
+
/** 读取已经设置的 idToken */
|
|
36
|
+
getIdToken() {
|
|
37
|
+
return this.idToken;
|
|
38
|
+
}
|
|
39
|
+
/** 读取自动置换的 gamerToken */
|
|
40
|
+
getGamerToken() {
|
|
41
|
+
return this.gamerToken;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 获取当前 Session 的信息
|
|
45
|
+
*
|
|
46
|
+
* https://kdocs.cn/l/cf2mO2uRLqh9?linkname=OdGVCdQxEu
|
|
47
|
+
*/
|
|
48
|
+
async getSession() {
|
|
49
|
+
if (await this.autoLogin()) return null;
|
|
50
|
+
const { data: r } = await this.req.get("session", p);
|
|
51
|
+
return r;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 根据手机号白名单,检查手机号是否允许登录某个游戏
|
|
55
|
+
*
|
|
56
|
+
* https://kdocs.cn/l/cf2mO2uRLqh9?linkname=OWGSPF3Ysl
|
|
57
|
+
*/
|
|
58
|
+
async verifyMobileAllowed(r) {
|
|
59
|
+
const { data: t } = await this.req.get("verify-mobile-allowed", v, {
|
|
60
|
+
params: { mobile: r }
|
|
61
|
+
});
|
|
62
|
+
return t;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function ge(e) {
|
|
66
|
+
return n(e, "gamer_token") && typeof e.gamer_token == "string";
|
|
67
|
+
}
|
|
68
|
+
function p(e) {
|
|
69
|
+
return n(e);
|
|
70
|
+
}
|
|
71
|
+
function v(e) {
|
|
72
|
+
return n(e, "allowed", "registered");
|
|
73
|
+
}
|
|
74
|
+
function w(e) {
|
|
75
|
+
return n(
|
|
76
|
+
e,
|
|
77
|
+
"default_avatar_url",
|
|
78
|
+
"official_avatar_urls",
|
|
79
|
+
"default_nickname",
|
|
80
|
+
"default_bio",
|
|
81
|
+
"default_role_avatar_url",
|
|
82
|
+
"level_configs",
|
|
83
|
+
"level_valid_days",
|
|
84
|
+
"benefit_description",
|
|
85
|
+
"exp_description",
|
|
86
|
+
"credit_description",
|
|
87
|
+
"send_role_mail_rate_limit"
|
|
88
|
+
) && Array.isArray(e.level_configs) && e.level_configs.every(
|
|
89
|
+
(r) => n(r, "exp", "level", "title")
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
function l(e) {
|
|
93
|
+
return n(
|
|
94
|
+
e,
|
|
95
|
+
"member_id",
|
|
96
|
+
"player_id",
|
|
97
|
+
"type",
|
|
98
|
+
"exp",
|
|
99
|
+
"level",
|
|
100
|
+
"credit",
|
|
101
|
+
"credit_expiring",
|
|
102
|
+
"level_change_time",
|
|
103
|
+
"level_expire_time"
|
|
104
|
+
) && typeof e.player_id == "string";
|
|
105
|
+
}
|
|
106
|
+
function a(e) {
|
|
107
|
+
return n(e, "player") && l(e.player);
|
|
108
|
+
}
|
|
109
|
+
function d(e) {
|
|
110
|
+
return n(e, "players") && Array.isArray(e.players) && e.players.every(l);
|
|
111
|
+
}
|
|
112
|
+
function h(e) {
|
|
113
|
+
return n(e, "servers") && Array.isArray(e.servers) && e.servers.every((r) => n(r, "server_id", "server_name"));
|
|
114
|
+
}
|
|
115
|
+
function A(e) {
|
|
116
|
+
return n(e, "ticket") && typeof e.ticket == "string";
|
|
117
|
+
}
|
|
118
|
+
function b(e) {
|
|
119
|
+
return n(e, "role_id", "role_name", "server_id", "server_name");
|
|
120
|
+
}
|
|
121
|
+
class fe {
|
|
122
|
+
/**
|
|
123
|
+
* 创建 ClubApi 实例
|
|
124
|
+
*
|
|
125
|
+
* @param baseRequest - Gamer 通用的 request 工具实例,baseUrl 仅仅包含 endpoint + version
|
|
126
|
+
* @param autoLogin - 自动登录函数,由上层组件提供
|
|
127
|
+
*/
|
|
128
|
+
constructor(r, t) {
|
|
129
|
+
s(this, "req");
|
|
130
|
+
s(this, "autoLogin");
|
|
131
|
+
this.req = r, this.autoLogin = t;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* 获取俱乐部配置
|
|
135
|
+
*
|
|
136
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=tuhsPt3ihp
|
|
137
|
+
*/
|
|
138
|
+
async getClubConfig() {
|
|
139
|
+
const { data: r } = await this.req.get("club/config", w);
|
|
140
|
+
return r;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* 用于游戏内嵌 Web 页面获取当前登录的游戏账号在俱乐部中的信息
|
|
144
|
+
*
|
|
145
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=hIDfaMlT7m
|
|
146
|
+
*/
|
|
147
|
+
async getCurrentPlayer() {
|
|
148
|
+
if (!await this.autoLogin()) return null;
|
|
149
|
+
const { data: r } = await this.req.get("club/current-player", a);
|
|
150
|
+
return (r == null ? void 0 : r.player) ?? null;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* 获取俱乐部当前关联的所有游戏账号
|
|
154
|
+
*
|
|
155
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=yccPUuagkA
|
|
156
|
+
*/
|
|
157
|
+
async getPlayers() {
|
|
158
|
+
if (!await this.autoLogin()) return null;
|
|
159
|
+
const { data: r } = await this.req.get("club/players", d);
|
|
160
|
+
return (r == null ? void 0 : r.players) || [];
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* 俱乐部关联游戏主账号。在俱乐部查询不到主游戏账号信息时,前端自行调用。
|
|
164
|
+
*
|
|
165
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=SfGAm3mOyp
|
|
166
|
+
*/
|
|
167
|
+
async linkPrimaryPlayer() {
|
|
168
|
+
if (!await this.autoLogin()) return null;
|
|
169
|
+
const { data: r } = await this.req.post("club/link-primary-player", {}, a);
|
|
170
|
+
return (r == null ? void 0 : r.player) ?? null;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* 获取关联副游戏账号时所需的游戏服务器列表
|
|
174
|
+
*
|
|
175
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=cBqJkplCAN
|
|
176
|
+
*/
|
|
177
|
+
async getSecondaryServers() {
|
|
178
|
+
if (!await this.autoLogin()) return [];
|
|
179
|
+
const { data: r } = await this.req.get("club/secondary-servers", h);
|
|
180
|
+
return (r == null ? void 0 : r.servers) || [];
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* 通过角色邮件,向游戏角色发送验证码,用于游戏外关联副游戏账号至俱乐部会员
|
|
184
|
+
*
|
|
185
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=mG7yRPapRv
|
|
186
|
+
*/
|
|
187
|
+
async createLinkSecondaryPlayerOtp(r, t) {
|
|
188
|
+
if (!await this.autoLogin()) return null;
|
|
189
|
+
const { data: i } = await this.req.post(
|
|
190
|
+
"club/create-link-secondary-player-otp",
|
|
191
|
+
{
|
|
192
|
+
server_id: r,
|
|
193
|
+
role_id: t
|
|
194
|
+
},
|
|
195
|
+
A
|
|
196
|
+
);
|
|
197
|
+
return (i == null ? void 0 : i.ticket) ?? null;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* 验证角色邮件收到的验证码
|
|
201
|
+
*
|
|
202
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=BhEdxXC5E4
|
|
203
|
+
*/
|
|
204
|
+
async verifyLinkSecondaryPlayerOtp(r, t) {
|
|
205
|
+
if (!await this.autoLogin()) return null;
|
|
206
|
+
const { data: i } = await this.req.post(
|
|
207
|
+
"club/verify-link-secondary-player-otp",
|
|
208
|
+
{ ticket: r, otp: t },
|
|
209
|
+
b
|
|
210
|
+
);
|
|
211
|
+
return i;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* 关联副游戏账号至俱乐部会员,适用于游戏外环境
|
|
215
|
+
*
|
|
216
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=QNi2C2D0vO
|
|
217
|
+
*/
|
|
218
|
+
async linkSecondaryPlayerWithTicket(r) {
|
|
219
|
+
if (!await this.autoLogin()) return null;
|
|
220
|
+
const { data: t } = await this.req.post("club/link-secondary-player", { ticket: r }, a);
|
|
221
|
+
return (t == null ? void 0 : t.player) || null;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* 关联副游戏账号至俱乐部会员,适用于游戏内嵌页环境
|
|
225
|
+
*
|
|
226
|
+
* https://kdocs.cn/l/cgp4gSBMbOf1?linkname=QNi2C2D0vO
|
|
227
|
+
*/
|
|
228
|
+
async linkSecondaryPlayerWithIdToken(r) {
|
|
229
|
+
if (!await this.autoLogin()) return null;
|
|
230
|
+
const { data: t } = await this.req.post("club/link-secondary-player", { id_token: r }, a);
|
|
231
|
+
return (t == null ? void 0 : t.player) || null;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function k(e) {
|
|
235
|
+
return n(e, "event_name", "rules", "since", "until", "visit_count", "features") && Array.isArray(e.features) && e.features.every(C);
|
|
236
|
+
}
|
|
237
|
+
function C(e) {
|
|
238
|
+
if (!L(e))
|
|
239
|
+
return !1;
|
|
240
|
+
switch (e.feature_type) {
|
|
241
|
+
case "preregister":
|
|
242
|
+
case "claim_rewards":
|
|
243
|
+
case "register":
|
|
244
|
+
case "invited_register":
|
|
245
|
+
return !0;
|
|
246
|
+
case "lottery":
|
|
247
|
+
return S(e.config);
|
|
248
|
+
case "survey":
|
|
249
|
+
return F(e.config);
|
|
250
|
+
case "invite":
|
|
251
|
+
return R(e.config);
|
|
252
|
+
case "share":
|
|
253
|
+
return P(e.config);
|
|
254
|
+
case "follow":
|
|
255
|
+
return T(e.config);
|
|
256
|
+
case "weixin_subscribe":
|
|
257
|
+
return x(e.config);
|
|
258
|
+
case "comment":
|
|
259
|
+
return D(e.config);
|
|
260
|
+
case "vote":
|
|
261
|
+
return U(e.config);
|
|
262
|
+
case "cashback":
|
|
263
|
+
return $(e.config);
|
|
264
|
+
case "gift_code":
|
|
265
|
+
return I(e.config);
|
|
266
|
+
case "quest":
|
|
267
|
+
return j(e.config);
|
|
268
|
+
case "team":
|
|
269
|
+
return O(e.config);
|
|
270
|
+
case "lottery_draw":
|
|
271
|
+
return V(e.config);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
function c(e) {
|
|
275
|
+
return n(
|
|
276
|
+
e,
|
|
277
|
+
"reward_item_id",
|
|
278
|
+
"reward_amount",
|
|
279
|
+
"reward_item_name",
|
|
280
|
+
"reward_item_icon_url",
|
|
281
|
+
"reward_item_type"
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
function q(e) {
|
|
285
|
+
return n(e, "feature_reward_type", "reward_details") && (e.feature_reward_type === "every" ? Array.isArray(e.reward_details) && e.reward_details.every(c) : e.feature_reward_type === "regular" ? n(e.reward_details, "engage_count", "rewards") && Array.isArray(e.reward_details.rewards) && e.reward_details.rewards.every(c) : !1);
|
|
286
|
+
}
|
|
287
|
+
function L(e) {
|
|
288
|
+
return n(
|
|
289
|
+
e,
|
|
290
|
+
"feature_id",
|
|
291
|
+
"feature_name",
|
|
292
|
+
"feature_type",
|
|
293
|
+
"cycle",
|
|
294
|
+
"description",
|
|
295
|
+
"limit",
|
|
296
|
+
"since",
|
|
297
|
+
"until",
|
|
298
|
+
"engage_account_type",
|
|
299
|
+
"feature_rewards"
|
|
300
|
+
) && Array.isArray(e.feature_rewards) && e.feature_rewards.every(q);
|
|
301
|
+
}
|
|
302
|
+
function E(e) {
|
|
303
|
+
return n(
|
|
304
|
+
e,
|
|
305
|
+
"reward_item_id",
|
|
306
|
+
"reward_item_name",
|
|
307
|
+
"reward_item_type",
|
|
308
|
+
"reward_item_icon_url",
|
|
309
|
+
"reward_amount",
|
|
310
|
+
"reward_remaining_stock"
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
function S(e) {
|
|
314
|
+
return n(
|
|
315
|
+
e,
|
|
316
|
+
"consume_item_id",
|
|
317
|
+
"consume_item_name",
|
|
318
|
+
"consume_item_icon_url",
|
|
319
|
+
"consume_item_count",
|
|
320
|
+
"rewards"
|
|
321
|
+
) && Array.isArray(e.rewards) && e.rewards.every(E);
|
|
322
|
+
}
|
|
323
|
+
function F(e) {
|
|
324
|
+
return n(e, "survey_id", "survey_url");
|
|
325
|
+
}
|
|
326
|
+
function R(e) {
|
|
327
|
+
return n(e, "share_url");
|
|
328
|
+
}
|
|
329
|
+
function P(e) {
|
|
330
|
+
return n(e, "share_platform");
|
|
331
|
+
}
|
|
332
|
+
function T(e) {
|
|
333
|
+
return n(e, "platform");
|
|
334
|
+
}
|
|
335
|
+
function x(e) {
|
|
336
|
+
return n(e, "weixin_template_ids") && Array.isArray(e.weixin_template_ids) && e.weixin_template_ids.every((r) => typeof r == "string");
|
|
337
|
+
}
|
|
338
|
+
function D(e) {
|
|
339
|
+
return n(e, "comments", "send_rate") && Array.isArray(e.comments) && e.comments.every((r) => typeof r == "string");
|
|
340
|
+
}
|
|
341
|
+
function U(e) {
|
|
342
|
+
return n(
|
|
343
|
+
e,
|
|
344
|
+
"vote_feature_ids",
|
|
345
|
+
"submission_feature_ids",
|
|
346
|
+
"finalists_amount",
|
|
347
|
+
"source",
|
|
348
|
+
"options",
|
|
349
|
+
"rewards"
|
|
350
|
+
) && Array.isArray(e.vote_feature_ids) && Array.isArray(e.submission_feature_ids) && Array.isArray(e.options) && e.options.every(G) && Array.isArray(e.rewards) && e.rewards.every(c);
|
|
351
|
+
}
|
|
352
|
+
function G(e) {
|
|
353
|
+
return n(e, "sn", "name", "amount", "jump_url", "last_vote_time", "finalists") && ("img_urls" in e ? Array.isArray(e.img_urls) : !0) && ("video_urls" in e ? Array.isArray(e.video_urls) : !0) && ("descriptions" in e ? Array.isArray(e.descriptions) : !0);
|
|
354
|
+
}
|
|
355
|
+
function $(e) {
|
|
356
|
+
return n(
|
|
357
|
+
e,
|
|
358
|
+
"order_start_time",
|
|
359
|
+
"order_end_time",
|
|
360
|
+
"claim_rewards_start_time",
|
|
361
|
+
"claim_rewards_end_time"
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
function I(e) {
|
|
365
|
+
return n(e, "gift_items") && Array.isArray(e.gift_items) && e.gift_items.every(Q);
|
|
366
|
+
}
|
|
367
|
+
function Q(e) {
|
|
368
|
+
return n(e, "name", "count", "icon_url");
|
|
369
|
+
}
|
|
370
|
+
function j(e) {
|
|
371
|
+
return n(e, "objective", "completion_value") && ("team" in e ? n(e.team, "completion_value") : !0);
|
|
372
|
+
}
|
|
373
|
+
function O(e) {
|
|
374
|
+
return n(e, "min_members", "max_members");
|
|
375
|
+
}
|
|
376
|
+
function V(e) {
|
|
377
|
+
return n(e, "draw_not_after", "draw_not_before");
|
|
378
|
+
}
|
|
379
|
+
function o(e) {
|
|
380
|
+
return n(e, "count");
|
|
381
|
+
}
|
|
382
|
+
function B(e) {
|
|
383
|
+
return n(e, "engagements") && Array.isArray(e.engagements) && (e.engagements.every(
|
|
384
|
+
(r) => n(r, "user_id", "name", "avatar_url", "comment", "video_note", "created_at")
|
|
385
|
+
) || e.engagements.every((r) => n(r, "objective", "leader_name", "total_members")));
|
|
386
|
+
}
|
|
387
|
+
function W(e) {
|
|
388
|
+
return n(e, "first_visit") && typeof e.first_visit == "boolean";
|
|
389
|
+
}
|
|
390
|
+
function M(e) {
|
|
391
|
+
return n(e, "status") && Array.isArray(e.status) && e.status.every((r) => n(r, "feature_id", "can_engage", "has_unclaimed_rewards"));
|
|
392
|
+
}
|
|
393
|
+
function z(e) {
|
|
394
|
+
return n(e, "engagements") && Array.isArray(e.engagements) && e.engagements.every(K);
|
|
395
|
+
}
|
|
396
|
+
function K(e) {
|
|
397
|
+
if (!n(
|
|
398
|
+
e,
|
|
399
|
+
"engagement_id",
|
|
400
|
+
"sequence",
|
|
401
|
+
"feature_id",
|
|
402
|
+
"reward_id",
|
|
403
|
+
"reward_status",
|
|
404
|
+
"reward_source",
|
|
405
|
+
"created_at"
|
|
406
|
+
))
|
|
407
|
+
return !1;
|
|
408
|
+
if (!("data" in e))
|
|
409
|
+
return !0;
|
|
410
|
+
const r = e.data;
|
|
411
|
+
return H(r) || J(r) || N(r) || X(r) || Y(r) || Z(r) || ee(r) || re(r) || te(r) || ne(r) || ie(r) || se(r);
|
|
412
|
+
}
|
|
413
|
+
function H(e) {
|
|
414
|
+
return n(e, "platforms") && Array.isArray(e.platforms);
|
|
415
|
+
}
|
|
416
|
+
function J(e) {
|
|
417
|
+
return n(e, "lottery_count");
|
|
418
|
+
}
|
|
419
|
+
function N(e) {
|
|
420
|
+
return n(e, "serial_number");
|
|
421
|
+
}
|
|
422
|
+
function X(e) {
|
|
423
|
+
return n(e, "user_id", "name", "avatar_url");
|
|
424
|
+
}
|
|
425
|
+
function Y(e) {
|
|
426
|
+
return n(e, "platform");
|
|
427
|
+
}
|
|
428
|
+
function Z(e) {
|
|
429
|
+
return n(e, "option_sn");
|
|
430
|
+
}
|
|
431
|
+
function ee(e) {
|
|
432
|
+
return n(e, "weixin_openid");
|
|
433
|
+
}
|
|
434
|
+
function re(e) {
|
|
435
|
+
return n(e, "cashback_total_amount", "game_item_count", "order_total_amount");
|
|
436
|
+
}
|
|
437
|
+
function te(e) {
|
|
438
|
+
return n(e, "gift_code");
|
|
439
|
+
}
|
|
440
|
+
function ne(e) {
|
|
441
|
+
return n(e, "team_code", "visibility", "members") && Array.isArray(e.members) && e.members.every(
|
|
442
|
+
(r) => n(r, "is_leader", "role_name", "server_name")
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
function ie(e) {
|
|
446
|
+
return n(e, "objective", "progress") ? "team" in e ? n(e.team, "progress", "players") && Array.isArray(e.team.players) && e.team.players.every(
|
|
447
|
+
(r) => n(
|
|
448
|
+
r,
|
|
449
|
+
"user_id",
|
|
450
|
+
"role_name",
|
|
451
|
+
"is_leader"
|
|
452
|
+
)
|
|
453
|
+
) : !0 : !1;
|
|
454
|
+
}
|
|
455
|
+
function se(e) {
|
|
456
|
+
return !n(e, "tickets") || !("status" in e) ? !1 : e.status === "unknown" || e.status === "pending" ? !0 : "reward" in e ? n(
|
|
457
|
+
e.reward,
|
|
458
|
+
"reward_id",
|
|
459
|
+
"reward_item_id",
|
|
460
|
+
"reward_item_name",
|
|
461
|
+
"reward_source",
|
|
462
|
+
"reward_item_type",
|
|
463
|
+
"reward_item_icon_url",
|
|
464
|
+
"reward_amount",
|
|
465
|
+
"reward_status",
|
|
466
|
+
"event_id",
|
|
467
|
+
"event_name",
|
|
468
|
+
"feature_id",
|
|
469
|
+
"engagement_id",
|
|
470
|
+
"feature_type",
|
|
471
|
+
"receive_time"
|
|
472
|
+
) && ("extra_data" in e.reward ? n(e.reward.extra_data) : !0) : !1;
|
|
473
|
+
}
|
|
474
|
+
function ae(e) {
|
|
475
|
+
return n(e, "scene");
|
|
476
|
+
}
|
|
477
|
+
function ue(e) {
|
|
478
|
+
return n(e, "params");
|
|
479
|
+
}
|
|
480
|
+
function oe(e) {
|
|
481
|
+
return n(e, "img") && typeof e.img == "string";
|
|
482
|
+
}
|
|
483
|
+
class ye {
|
|
484
|
+
/**
|
|
485
|
+
* 创建 EventApi 实例
|
|
486
|
+
*
|
|
487
|
+
* @param baseRequest - Gamer 通用的 request 工具实例,baseUrl 仅仅包含 endpoint + version
|
|
488
|
+
* @param autoLogin - 自动登录函数,由上层组件提供
|
|
489
|
+
*/
|
|
490
|
+
constructor(r, t) {
|
|
491
|
+
s(this, "req");
|
|
492
|
+
s(this, "autoLogin");
|
|
493
|
+
s(this, "event", 0);
|
|
494
|
+
this.req = r, this.autoLogin = t;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* 设置 Event Id,以供后续 api 请求中使用
|
|
498
|
+
*/
|
|
499
|
+
setEventId(r) {
|
|
500
|
+
return this.event = r, this;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* 获取运营活动的基础配置信息
|
|
504
|
+
*
|
|
505
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=wFXxtdNKPm
|
|
506
|
+
*/
|
|
507
|
+
async getEventConfig() {
|
|
508
|
+
const { data: r } = await this.req.get(`event/${this.event}/event-config`, k);
|
|
509
|
+
return r;
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* 获取某个玩法参与用户数量
|
|
513
|
+
*
|
|
514
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=ejPOcWMvT1
|
|
515
|
+
*/
|
|
516
|
+
async getEngagementsUserCount(r) {
|
|
517
|
+
const { data: t } = await this.req.get(`event/${this.event}/feature-engagement-count`, o, {
|
|
518
|
+
params: { feature_id: r, type: "user" }
|
|
519
|
+
});
|
|
520
|
+
return (t == null ? void 0 : t.count) ?? null;
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* 获取某个玩法参与次数
|
|
524
|
+
*
|
|
525
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=ejPOcWMvT1
|
|
526
|
+
*/
|
|
527
|
+
async getEngagementsCount(r) {
|
|
528
|
+
const { data: t } = await this.req.get(`event/${this.event}/feature-engagement-count`, o, {
|
|
529
|
+
params: { feature_id: r, type: "engagement" }
|
|
530
|
+
});
|
|
531
|
+
return (t == null ? void 0 : t.count) ?? null;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* 获取某个玩法的参与记录(和特定用户无关)
|
|
535
|
+
*
|
|
536
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=THtZ4ewIQW
|
|
537
|
+
*/
|
|
538
|
+
async getEngagements(r) {
|
|
539
|
+
const { data: t } = await this.req.get(`event/${this.event}/feature-engagements`, B, {
|
|
540
|
+
params: { feature_id: r }
|
|
541
|
+
});
|
|
542
|
+
return (t == null ? void 0 : t.engagements) || [];
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* 用户访问某个活动,需要先设置 idToken / weixinToken,返回是否
|
|
546
|
+
*
|
|
547
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=DWtJrnrBCn
|
|
548
|
+
*/
|
|
549
|
+
async userVisit(r) {
|
|
550
|
+
if (!await this.autoLogin()) return null;
|
|
551
|
+
const { data: t } = await this.req.post(`event/${this.event}/visit`, u(r || {}), W);
|
|
552
|
+
return t ? { ...t } : null;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* 获取用户在目标活动下的所有玩法的参与状态,用于前端进一步确定如何执行交互逻辑
|
|
556
|
+
*
|
|
557
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=WzX5BrMNpL
|
|
558
|
+
*/
|
|
559
|
+
async getUserFeatureStatus(r, t) {
|
|
560
|
+
if (!await this.autoLogin()) return [];
|
|
561
|
+
const { data: i } = await this.req.get("event/user-feature-status", M, {
|
|
562
|
+
params: u({
|
|
563
|
+
event_id: this.event,
|
|
564
|
+
server_id: r,
|
|
565
|
+
role_id: t
|
|
566
|
+
})
|
|
567
|
+
});
|
|
568
|
+
return (i == null ? void 0 : i.status) || [];
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* 获取当前登录用户参与某个玩法的记录
|
|
572
|
+
*
|
|
573
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=WSbAeDZc8F
|
|
574
|
+
*/
|
|
575
|
+
async getUserEngagements(r) {
|
|
576
|
+
if (!await this.autoLogin()) return [];
|
|
577
|
+
const { data: t } = await this.req.get(`event/${this.event}/user-engagements`, z, {
|
|
578
|
+
params: { feature_id: r }
|
|
579
|
+
});
|
|
580
|
+
return (t == null ? void 0 : t.engagements) || [];
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* 查询用户活动道具数量。注意,这里只能是活动道具
|
|
584
|
+
*
|
|
585
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=mnGCTeTgMb
|
|
586
|
+
*/
|
|
587
|
+
async getUserItemCount(r) {
|
|
588
|
+
if (!await this.autoLogin()) return null;
|
|
589
|
+
const { data: t } = await this.req.get(`event/${this.event}/user-item-count`, o, {
|
|
590
|
+
params: { item_id: r }
|
|
591
|
+
});
|
|
592
|
+
return (t == null ? void 0 : t.count) ?? null;
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* 填写实物奖励收货地址
|
|
596
|
+
*
|
|
597
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=QIwGhnaexb
|
|
598
|
+
*/
|
|
599
|
+
async submitUserRewardAddress(r) {
|
|
600
|
+
if (!await this.autoLogin()) return null;
|
|
601
|
+
const { ok: t } = await this.req.post(`event/${this.event}/user-reward-address`, r);
|
|
602
|
+
return t;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* 小程序码携带参数最多 32 个可见字符,若前端携带参数过长,则将参数保存在 api 中,并返回符合小程序码要求的 scene
|
|
606
|
+
*
|
|
607
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=TbEeyUmZzN
|
|
608
|
+
*
|
|
609
|
+
* @param params - 前端扫描二维码打开小程序所需参数
|
|
610
|
+
*/
|
|
611
|
+
async getUnlimitQrcodeScene(r) {
|
|
612
|
+
if (!await this.autoLogin()) return null;
|
|
613
|
+
const { data: t } = await this.req.get("event/unlimit-qrcode-scene", ae, {
|
|
614
|
+
params: { params: r }
|
|
615
|
+
});
|
|
616
|
+
return (t == null ? void 0 : t.scene) ?? null;
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* 根据小程序码携带 scene 值,获取对应的前端所需参数
|
|
620
|
+
*
|
|
621
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=SzWPFZDQBV
|
|
622
|
+
*
|
|
623
|
+
* @param scene - 小程序码 scene 值
|
|
624
|
+
*/
|
|
625
|
+
async getParamsByQrcodeScene(r) {
|
|
626
|
+
const { data: t } = await this.req.get("event/params-by-qrcode-scene", ue, {
|
|
627
|
+
params: { scene: r }
|
|
628
|
+
});
|
|
629
|
+
return (t == null ? void 0 : t.params) ?? null;
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* 生成不限制的带参数的小程序码
|
|
633
|
+
*
|
|
634
|
+
* https://kdocs.cn/l/ckWFDcOsYEUA?linkname=Rvmoq8iIy0
|
|
635
|
+
*/
|
|
636
|
+
async generateUnlimitQrcode(r) {
|
|
637
|
+
if (!await this.autoLogin()) return null;
|
|
638
|
+
const { data: t } = await this.req.post("event/unlimit-qrcode", u(r), oe);
|
|
639
|
+
return (t == null ? void 0 : t.img) ?? null;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
export {
|
|
643
|
+
fe as C,
|
|
644
|
+
ye as E,
|
|
645
|
+
me as G,
|
|
646
|
+
_e as c,
|
|
647
|
+
ge as i
|
|
648
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var a = Object.defineProperty;
|
|
2
|
+
var h = (i, s, e) => s in i ? a(i, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[s] = e;
|
|
3
|
+
var r = (i, s, e) => h(i, typeof s != "symbol" ? s + "" : s, e);
|
|
4
|
+
import { NetRequest as o } from "@seayoo-web/request";
|
|
5
|
+
import { G as u, E as c, C as m, c as g, i as k } from "./event-CXcuEQsA.js";
|
|
6
|
+
class T extends u {
|
|
7
|
+
constructor(e, t) {
|
|
8
|
+
super(e, (t == null ? void 0 : t.version) || "v1", o);
|
|
9
|
+
/** event api 集合 */
|
|
10
|
+
r(this, "event");
|
|
11
|
+
/** club api 集合 */
|
|
12
|
+
r(this, "club");
|
|
13
|
+
const n = this.autoLogin.bind(this);
|
|
14
|
+
this.event = new c(this.req, n), this.club = new m(this.req, n), t != null && t.eventId && this.event.setEventId(t.eventId);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 用世游通行证统一登录能力签发的 ID Token,自动置换 Gamer Token,成功后会自动设置后续 Request Headers
|
|
18
|
+
*
|
|
19
|
+
* [世游通行证统一登录](https://kdocs.cn/l/cf2mO2uRLqh9?linkname=FJXYgqvLHs)
|
|
20
|
+
*
|
|
21
|
+
* [世游通行证统一登录 - Web 站点](https://365.kdocs.cn/l/cf57sp1qLlZh)
|
|
22
|
+
*
|
|
23
|
+
* - 此方法通常不需要手动调用,在需要登录的接口调用时会自动执行
|
|
24
|
+
* - 为了提高页面执行速度,可以在 setIdToken 后立即调用 autoLogin,比如
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ``` js
|
|
28
|
+
* gamerApi.setIdToken("xxxxx").autoLogin()
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
async autoLogin() {
|
|
32
|
+
if (this.gamerToken)
|
|
33
|
+
return !0;
|
|
34
|
+
if (!this.idToken)
|
|
35
|
+
return g.error("Missing idToken when call autoLogin()"), !1;
|
|
36
|
+
const { data: e } = await this.req.post("login-with-token", { id_token: this.idToken }, k);
|
|
37
|
+
return this.gamerToken = (e == null ? void 0 : e.gamer_token) || "", !!this.gamerToken;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
T as GamerApi
|
|
42
|
+
};
|