@seayoo-web/gamer-api 1.0.1 → 1.0.4

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/index.js CHANGED
@@ -1,42 +1,1559 @@
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
1
+ var S = Object.defineProperty;
2
+ var M = (e, t, r) => t in e ? S(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var u = (e, t, r) => M(e, typeof t != "symbol" ? t + "" : t, r);
4
+ import { isComboWebView as B } from "@seayoo-web/combo-webview";
5
+ import { isPlainObject as n, useConsole as V, isObject as Q, pruneURL as j, queryString as f, pruneObject as s, isArray as a, isString as H, isValuedString as z, parseJSON as J, removePara as q } from "@seayoo-web/utils";
6
+ import "@seayoo-web/request";
7
+ function O(e) {
8
+ return n(e, "gamer_token") && typeof e.gamer_token == "string";
9
+ }
10
+ function R(e) {
11
+ return n(e);
12
+ }
13
+ const A = V("GamerApiSDK");
14
+ function K() {
15
+ return typeof wx < "u" && Q(wx) && "getSystemInfo" in wx && !!wx.getSystemInfo;
16
+ }
17
+ class Ot {
18
+ constructor({
19
+ endpoint: t,
20
+ NetRequest: r,
21
+ storage: i
22
+ }) {
23
+ u(this, "$idToken", "");
24
+ u(this, "$weixinToken", "");
25
+ u(this, "$gamerToken", "");
26
+ u(this, "inWxMiniProgram", !1);
27
+ u(this, "req");
28
+ u(this, "storage");
29
+ this.storage = i, this.inWxMiniProgram = K(), this.req = r({
30
+ baseURL: `https://${j(t)}/v1`,
31
+ timeout: 1e4,
32
+ responseRule: {
33
+ ok: { resolve: "body" },
34
+ failed: {
35
+ resolve: "json",
36
+ statusField: "error",
37
+ messageField: "message"
38
+ }
39
+ },
40
+ // 使用箭头函数绑定执行上下文
41
+ requestTransformer: (c) => {
42
+ this.$gamerToken && (c.headers.Authorization = `Bearer ${this.$gamerToken}`);
43
+ }
44
+ }), B() && (this.$gamerToken = f("gamer_token"));
45
+ }
46
+ /** 当前是否为登录状态,即是否拥有 gamerToken */
47
+ get isLogined() {
48
+ return this.$gamerToken !== "";
49
+ }
50
+ /** 读取已经设置的 idToken */
51
+ get idToken() {
52
+ return this.$idToken;
53
+ }
54
+ /** 设置从登录组件获取的 Id Token,用于后续请求自动置换 Gamer Token */
55
+ set idToken(t) {
56
+ t !== this.$idToken && (this.$gamerToken = "", this.$idToken = t);
57
+ }
58
+ /** 读取设置 wexinToken */
59
+ get weixinToken() {
60
+ return this.$weixinToken;
61
+ }
62
+ /**
63
+ * 设置 Weixin Token,用于后续请求自动置换 Gamer Token
64
+ *
65
+ * 仅仅在微信小程序模式下有效
66
+ */
67
+ set weixinToken(t) {
68
+ this.$weixinToken !== t && (this.$weixinToken = t, this.$gamerToken = "");
69
+ }
70
+ /** 读取自动置换的 gamerToken */
71
+ get gamerToken() {
72
+ return this.$gamerToken;
73
+ }
74
+ /** 直接写入 Gamer Token,通常在 ComboWebView 中读取 url 中的 gamer_token 传入 */
75
+ set gamerToken(t) {
76
+ this.$gamerToken = t;
77
+ }
78
+ /**
79
+ * 用世游通行证统一登录能力签发的 ID Token / Weixin Token,自动置换 Gamer Token,成功后会自动设置后续 Request Headers
18
80
  *
19
81
  * [世游通行证统一登录](https://kdocs.cn/l/cf2mO2uRLqh9?linkname=FJXYgqvLHs)
20
82
  *
21
83
  * [世游通行证统一登录 - Web 站点](https://365.kdocs.cn/l/cf57sp1qLlZh)
22
84
  *
23
- * - 此方法通常不需要手动调用,在需要登录的接口调用时会自动执行
24
- * - 为了提高页面执行速度,可以在 setIdToken 后立即调用 autoLogin,比如
85
+ * [世游通行证统一登录 - 微信小程序](https://365.kdocs.cn/l/ccHVuUs0UsZs)
25
86
  *
26
- * @example
27
- * ``` js
28
- * gamerApi.setIdToken("xxxxx").autoLogin()
29
- * ```
87
+ * - 此方法通常不需要手动调用,在需要登录的接口调用时会自动执行
88
+ * - 为了提高页面执行速度,可以在设置 Token 后立即调用 autoLogin
30
89
  */
31
90
  async autoLogin() {
32
91
  if (this.gamerToken)
33
92
  return !0;
34
93
  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;
94
+ return A.error("Missing idToken when call autoLogin()"), !1;
95
+ if (this.inWxMiniProgram && !this.weixinToken)
96
+ return A.error("Missing weixinToken when call autoLogin()"), !1;
97
+ const { data: t } = await this.req.post(
98
+ "login-with-token",
99
+ s({ id_token: this.idToken, weixin_token: this.inWxMiniProgram ? this.weixinToken : null }),
100
+ O
101
+ );
102
+ return this.gamerToken = (t == null ? void 0 : t.gamer_token) || "", !!this.gamerToken;
103
+ }
104
+ /**
105
+ * 获取当前 Session 的信息
106
+ *
107
+ * https://kdocs.cn/l/cf2mO2uRLqh9?linkname=OdGVCdQxEu
108
+ */
109
+ async getSession() {
110
+ if (await this.autoLogin()) return null;
111
+ const { data: t } = await this.req.get("session", R);
112
+ return t;
113
+ }
114
+ /**
115
+ * 实名认证
116
+ *
117
+ * https://kdocs.cn/l/cf2mO2uRLqh9?linkname=kZYnwX6RcF
118
+ */
119
+ async authRealName(t) {
120
+ if (await this.autoLogin()) return null;
121
+ const { data: r } = await this.req.post("auth-real-name", s(t), R);
122
+ return r;
123
+ }
124
+ }
125
+ function N(e) {
126
+ return n(
127
+ e,
128
+ "default_avatar_url",
129
+ "official_avatar_urls",
130
+ "default_nickname",
131
+ "default_bio",
132
+ "default_role_avatar_url",
133
+ "level_configs",
134
+ "level_valid_days",
135
+ "benefit_description",
136
+ "exp_description",
137
+ "credit_description",
138
+ "send_role_mail_rate_limit"
139
+ ) && Array.isArray(e.level_configs) && e.level_configs.every(
140
+ (t) => n(t, "exp", "level", "title")
141
+ );
142
+ }
143
+ function X(e) {
144
+ return n(
145
+ e,
146
+ "member_id",
147
+ "player_id",
148
+ "type",
149
+ "exp",
150
+ "level",
151
+ "credit",
152
+ "credit_expiring",
153
+ "level_change_time",
154
+ "level_expire_time"
155
+ ) && typeof e.player_id == "string";
156
+ }
157
+ function x(e) {
158
+ return n(e, "player") && X(e.player);
159
+ }
160
+ function U(e) {
161
+ return n(
162
+ e,
163
+ "role_id",
164
+ "role_name",
165
+ "role_level",
166
+ "server_id",
167
+ "server_name",
168
+ "last_login_time"
169
+ ) && H(e.server_id) && z(e.role_id);
170
+ }
171
+ function Y(e) {
172
+ return n(e, "roles") && a(e.roles, U);
173
+ }
174
+ function Z(e) {
175
+ return U(e) && n(e, "role_fighting");
176
+ }
177
+ function g(e) {
178
+ return n(e, "role_card") && Z(e.role_card);
179
+ }
180
+ function L(e) {
181
+ return n(e, "name", "avatar_url", "bio", "gender", "birthday") && n(e.birthday, "year", "month", "day");
182
+ }
183
+ function y(e) {
184
+ return n(
185
+ e,
186
+ "address_id",
187
+ "recipient",
188
+ "mobile",
189
+ "province",
190
+ "city",
191
+ "district",
192
+ "address",
193
+ "is_default"
194
+ );
195
+ }
196
+ function T(e) {
197
+ return n(e, "addresses") && a(e.addresses, y);
198
+ }
199
+ function W(e) {
200
+ return n(
201
+ e,
202
+ "increased_credit",
203
+ "decreased_credit",
204
+ "expired_credit",
205
+ "balance_credit"
206
+ );
207
+ }
208
+ function ee(e) {
209
+ return n(
210
+ e,
211
+ "id",
212
+ "change_time",
213
+ "change_type",
214
+ "change_credit",
215
+ "balance",
216
+ "change_scene"
217
+ );
218
+ }
219
+ function te(e) {
220
+ return n(e, "credit_logs") && a(e.credit_logs, ee);
221
+ }
222
+ function re(e) {
223
+ return n(
224
+ e,
225
+ "benefit_id",
226
+ "name",
227
+ "img_url",
228
+ "description",
229
+ "min_level",
230
+ "max_level",
231
+ "product_id",
232
+ "tag"
233
+ );
234
+ }
235
+ function ne(e) {
236
+ return n(e, "benefits") && a(e.benefits, re);
237
+ }
238
+ function ie(e) {
239
+ return n(
240
+ e,
241
+ "benefit_id",
242
+ "name",
243
+ "img_url",
244
+ "description",
245
+ "min_level",
246
+ "max_level",
247
+ "product_id"
248
+ ) && ("product" in e ? $(e.product) : !0);
249
+ }
250
+ function se(e) {
251
+ return n(e, "benefit") && ie(e.benefit);
252
+ }
253
+ function $(e) {
254
+ return n(
255
+ e,
256
+ "product_id",
257
+ "catalog_id",
258
+ "catalog_name",
259
+ "item_type",
260
+ "name",
261
+ "img_url",
262
+ "description",
263
+ "tag",
264
+ "price",
265
+ "stock",
266
+ "redeem_quantity",
267
+ "not_visible_after",
268
+ "not_visible_before",
269
+ "not_after",
270
+ "not_before",
271
+ "min_level",
272
+ "max_level",
273
+ "limit_daily",
274
+ "limit_monthly",
275
+ "limit_yearly",
276
+ "limit_total",
277
+ "weight",
278
+ "created_at",
279
+ "updated_at"
280
+ );
281
+ }
282
+ function oe(e) {
283
+ return n(e, "products") && a(e.products, $);
284
+ }
285
+ function ae(e) {
286
+ return n(
287
+ e,
288
+ "redemption_id",
289
+ "player_id",
290
+ "product_id",
291
+ "name",
292
+ "img_url",
293
+ "item_type",
294
+ "catalog_id",
295
+ "catalog_name",
296
+ "quantity",
297
+ "amount",
298
+ "status",
299
+ "created_at"
300
+ ) && ("extra_data" in e ? ue(e.extra_data) || ce(e.extra_data) : !0);
301
+ }
302
+ function ue(e) {
303
+ return n(
304
+ e,
305
+ "address",
306
+ "recipient",
307
+ "mobile",
308
+ "province",
309
+ "city",
310
+ "district",
311
+ "express_company",
312
+ "express_number"
313
+ );
314
+ }
315
+ function ce(e) {
316
+ return n(e, "server_id", "role_id", "role_name");
317
+ }
318
+ function me(e) {
319
+ return n(e, "redemptions") && a(e.redemptions, ae);
320
+ }
321
+ var le = /* @__PURE__ */ ((e) => (e.Unknown = "unknown", e.Male = "male", e.Female = "female", e))(le || {}), _e = /* @__PURE__ */ ((e) => (e.Increase = "increase", e.Decrease = "decrease", e.Expired = "expired", e))(_e || {}), ge = /* @__PURE__ */ ((e) => (e.Order = "order", e.Consumption = "consumption", e.Redeem = "redeem", e.Expire = "expire", e.Admin = "admin", e.Event = "event", e))(ge || {}), de = /* @__PURE__ */ ((e) => (e.GameReward = "game_reward", e.Physical = "physical", e.Virtual = "virtual", e))(de || {}), pe = /* @__PURE__ */ ((e) => (e.Pending = "pending", e.issued = "issued", e.failed = "failed", e))(pe || {});
322
+ class Kt {
323
+ constructor(t) {
324
+ u(this, "token");
325
+ u(this, "req");
326
+ this.token = t, this.req = t.req;
327
+ }
328
+ /**
329
+ * 获取俱乐部配置
330
+ *
331
+ * https://kdocs.cn/l/cgp4gSBMbOf1?linkname=tuhsPt3ihp
332
+ */
333
+ async getConfig() {
334
+ const { data: t } = await this.req.get("club/config", N);
335
+ return t;
336
+ }
337
+ /**
338
+ * 用于游戏内嵌 Web 页面和微信小程序获取当前登录的游戏账号在俱乐部中的信息。
339
+ *
340
+ * https://kdocs.cn/l/cgp4gSBMbOf1?linkname=hIDfaMlT7m
341
+ */
342
+ async getCurrentPlayer() {
343
+ await this.token.autoLogin();
344
+ const { data: t, code: r } = await this.req.get("club/current-player", x);
345
+ return (t == null ? void 0 : t.player) ?? { error: r };
346
+ }
347
+ /**
348
+ * 俱乐部用户关联游戏账号
349
+ *
350
+ * https://kdocs.cn/l/cgp4gSBMbOf1?linkname=Dpb9JAKqzG
351
+ */
352
+ async linkPlayer() {
353
+ await this.token.autoLogin();
354
+ const { data: t, code: r } = await this.req.post(
355
+ "club/link-player",
356
+ {
357
+ id_token: this.token.idToken
358
+ },
359
+ x
360
+ );
361
+ return (t == null ? void 0 : t.player) ?? {
362
+ error: r
363
+ };
364
+ }
365
+ /**
366
+ * 获取俱乐部关联的游戏账号下的角色列表
367
+ *
368
+ * https://kdocs.cn/l/cgp4gSBMbOf1?linkname=nwu4FiGM9V
369
+ */
370
+ async getRoles(t, r) {
371
+ if (!await this.token.autoLogin()) return [];
372
+ const { data: i } = await this.req.get("club/roles", Y, {
373
+ params: s({ player_id: t, refresh: r })
374
+ });
375
+ return (i == null ? void 0 : i.roles) || [];
376
+ }
377
+ /**
378
+ * 获取俱乐部会员的角色卡片数据
379
+ *
380
+ * https://kdocs.cn/l/cgp4gSBMbOf1?linkname=A1Wr7kUXnS
381
+ */
382
+ async getRoleCard(t) {
383
+ const { data: r } = await this.req.get("club/role-card", g, {
384
+ params: { member_id: t }
385
+ });
386
+ return (r == null ? void 0 : r.role_card) ?? null;
387
+ }
388
+ /**
389
+ * 设置自己的角色卡片
390
+ *
391
+ * https://kdocs.cn/l/cgp4gSBMbOf1?linkname=XgMf6OFE5i
392
+ */
393
+ async setRoleCard(t) {
394
+ if (!await this.token.autoLogin()) return null;
395
+ const { data: r } = await this.req.post("club/role-card", t, g);
396
+ return (r == null ? void 0 : r.role_card) ?? null;
397
+ }
398
+ /**
399
+ * 强制刷新自己的角色卡片,从游戏内获取最新数据
400
+ *
401
+ * https://kdocs.cn/l/cgp4gSBMbOf1?linkname=RPdJquwmgv
402
+ */
403
+ async refreshRoleCard() {
404
+ if (!await this.token.autoLogin()) return null;
405
+ const { data: t } = await this.req.post("club/refresh-role-card", {}, g);
406
+ return (t == null ? void 0 : t.role_card) ?? null;
407
+ }
408
+ /**
409
+ * 获取俱乐部用户的信息
410
+ *
411
+ * https://kdocs.cn/l/cgp4gSBMbOf1?linkname=TMWBCFcOr2
412
+ */
413
+ async getUserProfile(t) {
414
+ const { data: r } = await this.req.get("club/user-profile", L, {
415
+ params: { member_id: t }
416
+ });
417
+ return r;
418
+ }
419
+ /**
420
+ * 修改自己的俱乐部用户信息
421
+ *
422
+ * https://kdocs.cn/l/cgp4gSBMbOf1?linkname=Qt822A57jd
423
+ */
424
+ async updateUserProfile(t) {
425
+ await this.token.autoLogin();
426
+ const { data: r, code: i } = await this.req.post("club/user-profile", t, L);
427
+ return r ?? {
428
+ error: i
429
+ };
430
+ }
431
+ /**
432
+ * 获取自己的俱乐部收货地址列表
433
+ *
434
+ * https://kdocs.cn/l/cgp4gSBMbOf1?linkname=NowUIynMVn
435
+ */
436
+ async getAddresses() {
437
+ if (!await this.token.autoLogin()) return [];
438
+ const { data: t } = await this.req.get("club/addresses", T);
439
+ return (t == null ? void 0 : t.addresses) ?? [];
440
+ }
441
+ /**
442
+ * 增加俱乐部收货地址
443
+ *
444
+ * https://kdocs.cn/l/cgp4gSBMbOf1?linkname=TaGIIYDRYA
445
+ */
446
+ async addAddress(t) {
447
+ if (!await this.token.autoLogin()) return null;
448
+ const { data: r } = await this.req.post("/club/add-address", s(t), y);
449
+ return r;
450
+ }
451
+ /**
452
+ * 修改自己的俱乐部收货地址
453
+ *
454
+ * https://kdocs.cn/l/cgp4gSBMbOf1?linkname=p9FlJhHnWN
455
+ */
456
+ async updateAddress(t) {
457
+ await this.token.autoLogin();
458
+ const { data: r, code: i } = await this.req.post("club/update-address", s(t), y);
459
+ return r ?? { error: i };
460
+ }
461
+ /**
462
+ * 删除自己的俱乐部收货地址
463
+ *
464
+ * https://kdocs.cn/l/cgp4gSBMbOf1?linkname=MEEOBdf8rm
465
+ */
466
+ async deleteAddress(t) {
467
+ if (!await this.token.autoLogin()) return null;
468
+ const { ok: r } = await this.req.post("club/delete-address", { address_id: t });
469
+ return r;
470
+ }
471
+ /**
472
+ * 获取俱乐部积分统计信息
473
+ *
474
+ * https://kdocs.cn/l/cgp4gSBMbOf1?linkname=x4uxtGstRL
475
+ */
476
+ async getUserCredit(t) {
477
+ await this.token.autoLogin();
478
+ const { data: r, code: i } = await this.req.get("club/user-credit", W, { params: s(t) });
479
+ return r ?? { error: i };
480
+ }
481
+ /**
482
+ * 获取自己的俱乐部积分变动记录
483
+ *
484
+ * https://kdocs.cn/l/cgp4gSBMbOf1?linkname=lQFgF689P8
485
+ */
486
+ async getCreditLogs(t) {
487
+ await this.token.autoLogin();
488
+ const { data: r } = await this.req.get("club/credit-logs", te, {
489
+ params: s({ max_results: 20, ...t })
490
+ });
491
+ return r || { credit_logs: [] };
492
+ }
493
+ /**
494
+ * 获取自己的俱乐部权益列表
495
+ *
496
+ * https://kdocs.cn/l/cgp4gSBMbOf1?linkname=UFSDGvqkdV
497
+ */
498
+ async getBenefits() {
499
+ if (!await this.token.autoLogin()) return [];
500
+ const { data: t } = await this.req.get("club/benefits", ne);
501
+ return (t == null ? void 0 : t.benefits) || [];
502
+ }
503
+ /**
504
+ * 获取某个权益详细信息
505
+ *
506
+ * https://kdocs.cn/l/cgp4gSBMbOf1?linkname=XKto0MeaHF
507
+ */
508
+ async getBenefit(t) {
509
+ if (!await this.token.autoLogin()) return null;
510
+ const { data: r } = await this.req.get("club/benefit", se, {
511
+ params: { benefit_id: t }
512
+ });
513
+ return (r == null ? void 0 : r.benefit) || null;
514
+ }
515
+ /**
516
+ * 获取商城商品列表
517
+ *
518
+ * https://kdocs.cn/l/cgp4gSBMbOf1?linkname=r3vC3PzfMQ
519
+ */
520
+ async getProducts() {
521
+ const { data: t } = await this.req.get("club/products", oe);
522
+ return (t == null ? void 0 : t.products) || [];
523
+ }
524
+ /**
525
+ * 兑换商城商品
526
+ *
527
+ * https://kdocs.cn/l/cgp4gSBMbOf1?linkname=LWcMVwX3OY
528
+ */
529
+ async redeemProduct(t) {
530
+ await this.token.autoLogin();
531
+ const { ok: r, code: i } = await this.req.post("club/redeem-product", s(t));
532
+ return r || {
533
+ error: i
534
+ };
535
+ }
536
+ /**
537
+ * 获取兑换记录
538
+ *
539
+ * https://kdocs.cn/l/cgp4gSBMbOf1?linkname=Ml6mLgT4cM
540
+ */
541
+ async getRedemptions(t) {
542
+ await this.token.autoLogin();
543
+ const { data: r } = await this.req.get("club/redemptions", me, {
544
+ params: s({ max_results: 20, ...t })
545
+ });
546
+ return r || { redemptions: [] };
547
+ }
548
+ }
549
+ var fe = /* @__PURE__ */ ((e) => (e.EventItem = "event_item", e.GameItem = "game_item", e.PhysicalItem = "physical_item", e.WeixinHongbao = "weixin_hongbao", e.GiftCode = "gift_code", e.LotteryTicket = "lottery_ticket", e.VoidItem = "void_item", e))(fe || {}), ye = /* @__PURE__ */ ((e) => (e.UserId = "user_id", e.RoleId = "role_id", e))(ye || {}), we = /* @__PURE__ */ ((e) => (e.None = "none", e.Daily = "daily", e.Weekly = "weekly", e.Monthly = "monthly", e))(we || {}), o = /* @__PURE__ */ ((e) => (e.Preregister = "preregister", e.Lottery = "lottery", e.Survey = "survey", e.Invite = "invite", e.Share = "share", e.Follow = "follow", e.Subscribe = "weixin_subscribe", e.Comment = "comment", e.Vote = "vote", e.GiftCode = "gift_code", e.Register = "register", e.InvitedRegister = "invited_register", e.ClaimRewards = "claim_rewards", e.Cashback = "cashback", e.Quest = "quest", e.Team = "team", e.LotteryDraw = "lottery_draw", e))(o || {}), he = /* @__PURE__ */ ((e) => (e.Active = "player_active_points", e.Login = "player_login_days", e.OrderAmount = "order_total_amount", e.Posts = "community_posts", e.Comments = "community_comments", e))(he || {}), ve = /* @__PURE__ */ ((e) => (e.System = "system", e.UserSubmission = "user_submission", e.Shortlisted = "shortlisted", e))(ve || {}), ke = /* @__PURE__ */ ((e) => (e.Ineligible = "ineligible", e.Unaccalimed = "unaccalimed", e.Received = "received", e))(ke || {}), be = /* @__PURE__ */ ((e) => (e.Unaccalimed = "unaccalimed", e.Received = "received", e.Failed = "failed", e.Delivered = "delivered", e))(be || {}), qe = /* @__PURE__ */ ((e) => (e.Ineligible = "ineligible", e.Unaccalimed = "unaccalimed", e.Received = "received", e.Failed = "failed", e))(qe || {}), Re = /* @__PURE__ */ ((e) => (e.Output = "output", e.Engage = "engage", e))(Re || {}), Ae = /* @__PURE__ */ ((e) => (e.Private = "private", e.Public = "public", e))(Ae || {}), xe = /* @__PURE__ */ ((e) => (e.Unknown = "unknown", e.Pending = "pending", e.Drawn = "drawn", e.Claimed = "claimed", e.Fail = "fail", e))(xe || {}), Le = /* @__PURE__ */ ((e) => (e.Assemble = "assemble", e.Join = "join", e.Disband = "disband", e.ChangeVisibility = "change_visibility", e.Query = "query", e))(Le || {}), Ce = /* @__PURE__ */ ((e) => (e.Query = "query", e.Draw = "draw", e.Claim = "claim", e))(Ce || {});
550
+ function Pe(e) {
551
+ return n(e, "event_name", "rules", "since", "until", "visit_count", "features") && Array.isArray(e.features) && e.features.every(Ue);
552
+ }
553
+ function Ue(e) {
554
+ if (!De(e))
555
+ return !1;
556
+ switch (e.feature_type) {
557
+ case o.Preregister:
558
+ case o.ClaimRewards:
559
+ case o.Register:
560
+ case o.InvitedRegister:
561
+ return !0;
562
+ case o.Lottery:
563
+ return Fe(e.config);
564
+ case o.Survey:
565
+ return Ge(e.config);
566
+ case o.Invite:
567
+ return Ie(e.config);
568
+ case o.Share:
569
+ return Se(e.config);
570
+ case o.Follow:
571
+ return Me(e.config);
572
+ case o.Subscribe:
573
+ return Be(e.config);
574
+ case o.Comment:
575
+ return Ve(e.config);
576
+ case o.Vote:
577
+ return Qe(e.config);
578
+ case o.Cashback:
579
+ return He(e.config);
580
+ case o.GiftCode:
581
+ return ze(e.config);
582
+ case o.Quest:
583
+ return Oe(e.config);
584
+ case o.Team:
585
+ return Ke(e.config);
586
+ case o.LotteryDraw:
587
+ return Ne(e.config);
588
+ default:
589
+ return !1;
590
+ }
591
+ }
592
+ function w(e) {
593
+ return n(
594
+ e,
595
+ "reward_item_id",
596
+ "reward_amount",
597
+ "reward_item_name",
598
+ "reward_item_icon_url",
599
+ "reward_item_type"
600
+ );
601
+ }
602
+ function $e(e) {
603
+ return n(e, "feature_reward_type", "reward_details") && (e.feature_reward_type === "every" ? Array.isArray(e.reward_details) && e.reward_details.every(w) : e.feature_reward_type === "regular" ? n(e.reward_details, "engage_count", "rewards") && Array.isArray(e.reward_details.rewards) && e.reward_details.rewards.every(w) : !1);
604
+ }
605
+ function De(e) {
606
+ return n(
607
+ e,
608
+ "feature_id",
609
+ "feature_name",
610
+ "feature_type",
611
+ "cycle",
612
+ "description",
613
+ "limit",
614
+ "since",
615
+ "until",
616
+ "engage_account_type",
617
+ "feature_rewards"
618
+ ) && Array.isArray(e.feature_rewards) && e.feature_rewards.every($e);
619
+ }
620
+ function Ee(e) {
621
+ return n(
622
+ e,
623
+ "reward_item_id",
624
+ "reward_item_name",
625
+ "reward_item_type",
626
+ "reward_item_icon_url",
627
+ "reward_amount",
628
+ "reward_remaining_stock"
629
+ );
630
+ }
631
+ function Fe(e) {
632
+ return n(
633
+ e,
634
+ "consume_item_id",
635
+ "consume_item_name",
636
+ "consume_item_icon_url",
637
+ "consume_item_count",
638
+ "rewards"
639
+ ) && Array.isArray(e.rewards) && e.rewards.every(Ee);
640
+ }
641
+ function Ge(e) {
642
+ return n(e, "survey_id", "survey_url");
643
+ }
644
+ function Ie(e) {
645
+ return n(e, "share_url");
646
+ }
647
+ function Se(e) {
648
+ return n(e, "share_platform");
649
+ }
650
+ function Me(e) {
651
+ return n(e, "platform");
652
+ }
653
+ function Be(e) {
654
+ return n(e, "weixin_template_ids") && Array.isArray(e.weixin_template_ids) && e.weixin_template_ids.every((t) => typeof t == "string");
655
+ }
656
+ function Ve(e) {
657
+ return n(e, "comments", "send_rate") && Array.isArray(e.comments) && e.comments.every((t) => typeof t == "string");
658
+ }
659
+ function Qe(e) {
660
+ return n(
661
+ e,
662
+ "vote_feature_ids",
663
+ "submission_feature_ids",
664
+ "finalists_amount",
665
+ "source",
666
+ "options",
667
+ "rewards"
668
+ ) && Array.isArray(e.vote_feature_ids) && Array.isArray(e.submission_feature_ids) && Array.isArray(e.options) && e.options.every(je) && Array.isArray(e.rewards) && e.rewards.every(w);
669
+ }
670
+ function je(e) {
671
+ 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);
672
+ }
673
+ function He(e) {
674
+ return n(
675
+ e,
676
+ "order_start_time",
677
+ "order_end_time",
678
+ "claim_rewards_start_time",
679
+ "claim_rewards_end_time"
680
+ );
681
+ }
682
+ function ze(e) {
683
+ return n(e, "gift_items") && Array.isArray(e.gift_items) && e.gift_items.every(Je);
684
+ }
685
+ function Je(e) {
686
+ return n(e, "name", "count", "icon_url");
687
+ }
688
+ function Oe(e) {
689
+ return n(e, "objective", "completion_value") && ("team" in e ? n(e.team, "completion_value") : !0);
690
+ }
691
+ function Ke(e) {
692
+ return n(e, "min_members", "max_members");
693
+ }
694
+ function Ne(e) {
695
+ return n(e, "draw_not_after", "draw_not_before");
696
+ }
697
+ function Xe(e) {
698
+ return n(e, "allowed", "registered");
699
+ }
700
+ function d(e) {
701
+ return n(e, "count");
702
+ }
703
+ function Ye(e) {
704
+ return n(e, "engagements") && Array.isArray(e.engagements) && (e.engagements.every(
705
+ (t) => n(t, "user_id", "name", "avatar_url", "comment", "video_note", "created_at")
706
+ ) || e.engagements.every((t) => n(t, "team_code", "leader_name", "total_members")));
707
+ }
708
+ function Ze(e) {
709
+ return n(e, "first_visit") && typeof e.first_visit == "boolean";
710
+ }
711
+ function Te(e) {
712
+ return n(e, "status") && Array.isArray(e.status) && e.status.every((t) => n(t, "feature_id", "can_engage", "has_unclaimed_rewards"));
713
+ }
714
+ function We(e) {
715
+ return n(e, "engagements") && a(e.engagements, D);
716
+ }
717
+ function D(e) {
718
+ if (!n(
719
+ e,
720
+ "engagement_id",
721
+ "sequence",
722
+ "feature_id",
723
+ "reward_id",
724
+ "reward_status",
725
+ "reward_source",
726
+ "created_at"
727
+ ))
728
+ return !1;
729
+ if (!("data" in e))
730
+ return !0;
731
+ const t = e.data;
732
+ return et(t) || tt(t) || rt(t) || nt(t) || it(t) || st(t) || ot(t) || at(t) || ut(t) || ct(t) || mt(t) || lt(t);
733
+ }
734
+ function et(e) {
735
+ return n(e, "platforms") && Array.isArray(e.platforms);
736
+ }
737
+ function tt(e) {
738
+ return n(e, "lottery_count");
739
+ }
740
+ function rt(e) {
741
+ return n(e, "serial_number");
742
+ }
743
+ function nt(e) {
744
+ return n(e, "user_id");
745
+ }
746
+ function it(e) {
747
+ return n(e, "platform");
748
+ }
749
+ function st(e) {
750
+ return n(e, "option_sn");
751
+ }
752
+ function ot(e) {
753
+ return n(e, "weixin_openid");
754
+ }
755
+ function at(e) {
756
+ return n(e, "cashback_total_amount", "game_item_count", "order_total_amount");
757
+ }
758
+ function ut(e) {
759
+ return n(e, "gift_code");
760
+ }
761
+ function ct(e) {
762
+ return n(e, "team_code", "visibility", "members") && Array.isArray(e.members) && e.members.every(
763
+ (t) => n(t, "is_leader", "role_name", "server_name")
764
+ );
765
+ }
766
+ function mt(e) {
767
+ return n(e, "objective", "progress") ? "team" in e ? n(e.team, "progress", "players") && Array.isArray(e.team.players) && e.team.players.every(
768
+ (t) => n(
769
+ t,
770
+ "user_id",
771
+ "role_name",
772
+ "is_leader"
773
+ )
774
+ ) : !0 : !1;
775
+ }
776
+ function E(e) {
777
+ return n(
778
+ e,
779
+ "reward_id",
780
+ "reward_item_id",
781
+ "reward_item_name",
782
+ "reward_source",
783
+ "reward_item_type",
784
+ "reward_item_icon_url",
785
+ "reward_amount",
786
+ "reward_status",
787
+ "event_id",
788
+ "event_name",
789
+ "feature_id",
790
+ "engagement_id",
791
+ "feature_type",
792
+ "receive_time"
793
+ ) && ("extra_data" in e ? n(e.extra_data) : !0);
794
+ }
795
+ function lt(e) {
796
+ return !n(e, "tickets") || !("status" in e) ? !1 : e.status === "unknown" || e.status === "pending" ? !0 : "reward" in e ? E(e.reward) : !1;
797
+ }
798
+ function _t(e) {
799
+ return n(
800
+ e,
801
+ "reward_id",
802
+ "reward_item_id",
803
+ "reward_item_name",
804
+ "reward_item_type",
805
+ "reward_item_icon_url",
806
+ "reward_amount",
807
+ "reward_source",
808
+ "reward_source"
809
+ );
810
+ }
811
+ function gt(e) {
812
+ return n(e, "engagement_id") && ("engagement" in e ? D(e.engagement) : !0) && ("rewards" in e ? a(e.rewards, _t) : !0);
813
+ }
814
+ function dt(e) {
815
+ return n(e, "reward_id", "reward_status");
816
+ }
817
+ function pt(e) {
818
+ return n(e, "claimed_items") && a(e.claimed_items, dt);
819
+ }
820
+ function ft(e) {
821
+ return n(e, "reward_status");
822
+ }
823
+ function yt(e) {
824
+ return n(e, "user_rewards") && a(e.user_rewards, E);
825
+ }
826
+ function wt(e) {
827
+ return n(e, "scene");
828
+ }
829
+ function ht(e) {
830
+ return n(e, "params");
831
+ }
832
+ function vt(e) {
833
+ return n(e, "img") && typeof e.img == "string";
834
+ }
835
+ class Nt {
836
+ constructor(t, r) {
837
+ u(this, "token");
838
+ u(this, "event", 0);
839
+ u(this, "req");
840
+ this.token = t, this.event = r, this.req = t.req;
841
+ }
842
+ /**
843
+ * 根据手机号白名单,检查手机号是否允许登录某个游戏
844
+ *
845
+ * https://kdocs.cn/l/cf2mO2uRLqh9?linkname=OWGSPF3Ysl
846
+ */
847
+ async verifyMobileAllowed(t) {
848
+ const { data: r } = await this.req.get("verify-mobile-allowed", Xe, {
849
+ params: { mobile: t }
850
+ });
851
+ return r;
852
+ }
853
+ /**
854
+ * 获取运营活动的基础配置信息
855
+ *
856
+ * https://kdocs.cn/l/ckWFDcOsYEUA?linkname=wFXxtdNKPm
857
+ */
858
+ async getConfig() {
859
+ const { data: t } = await this.req.get(`event/${this.event}/event-config`, Pe);
860
+ return t;
861
+ }
862
+ /**
863
+ * 获取某个玩法参与用户数量
864
+ *
865
+ * https://kdocs.cn/l/ckWFDcOsYEUA?linkname=ejPOcWMvT1
866
+ */
867
+ async getEngagementsUserCount(t) {
868
+ const { data: r } = await this.req.get(`event/${this.event}/feature-engagement-count`, d, {
869
+ params: { feature_id: t, type: "user" }
870
+ });
871
+ return (r == null ? void 0 : r.count) ?? null;
872
+ }
873
+ /**
874
+ * 获取某个玩法参与次数
875
+ *
876
+ * https://kdocs.cn/l/ckWFDcOsYEUA?linkname=ejPOcWMvT1
877
+ */
878
+ async getEngagementsCount(t) {
879
+ const { data: r } = await this.req.get(`event/${this.event}/feature-engagement-count`, d, {
880
+ params: { feature_id: t, type: "engagement" }
881
+ });
882
+ return (r == null ? void 0 : r.count) ?? null;
883
+ }
884
+ /**
885
+ * 获取某个玩法的参与记录(和特定用户无关)
886
+ *
887
+ * https://kdocs.cn/l/ckWFDcOsYEUA?linkname=THtZ4ewIQW
888
+ */
889
+ async getEngagements(t) {
890
+ const { data: r } = await this.req.get(`event/${this.event}/feature-engagements`, Ye, {
891
+ params: { feature_id: t }
892
+ });
893
+ return (r == null ? void 0 : r.engagements) || [];
894
+ }
895
+ /**
896
+ * 用户访问某个活动或玩法
897
+ *
898
+ * https://kdocs.cn/l/ckWFDcOsYEUA?linkname=DWtJrnrBCn
899
+ */
900
+ async visit(t) {
901
+ await this.token.autoLogin();
902
+ const { data: r, code: i } = await this.req.post(
903
+ `event/${this.event}/visit`,
904
+ s(t || {}),
905
+ Ze
906
+ );
907
+ return r ?? {
908
+ error: i
909
+ };
910
+ }
911
+ /**
912
+ * 获取用户在目标活动下的所有玩法的参与状态,用于前端进一步确定如何执行交互逻辑
913
+ *
914
+ * 💡活动下包含 engage_account_type 为 role_id 的玩法时,前端需要提供 server_id 和 role_id
915
+ *
916
+ * https://kdocs.cn/l/ckWFDcOsYEUA?linkname=WzX5BrMNpL
917
+ */
918
+ async getUserFeatureStatus(t) {
919
+ if (!await this.token.autoLogin()) return [];
920
+ const { data: r } = await this.req.get("event/user-feature-status", Te, {
921
+ params: s({ ...t, event_id: this.event }),
922
+ message: !1
923
+ });
924
+ return (r == null ? void 0 : r.status) || [];
925
+ }
926
+ /**
927
+ * 获取当前登录用户参与某个玩法的记录
928
+ *
929
+ * https://kdocs.cn/l/ckWFDcOsYEUA?linkname=WSbAeDZc8F
930
+ */
931
+ async getUserEngagements(t) {
932
+ if (!await this.token.autoLogin()) return [];
933
+ const { data: r } = await this.req.get(`event/${this.event}/user-engagements`, We, {
934
+ params: { feature_id: t }
935
+ });
936
+ return (r == null ? void 0 : r.engagements) || [];
937
+ }
938
+ /**
939
+ * 用户参与某个玩法(需要先调用 visit 接口)
940
+ *
941
+ * https://kdocs.cn/l/ckWFDcOsYEUA?linkname=vuOyrcry3S
942
+ */
943
+ async engage(t) {
944
+ await this.token.autoLogin();
945
+ const { data: r, code: i } = await this.req.post(`event/${this.event}/engame`, s(t), gt);
946
+ return r ?? {
947
+ error: i
948
+ };
949
+ }
950
+ /**
951
+ * 用户领取除红包和实物奖励以外的所有奖励
952
+ *
953
+ * https://kdocs.cn/l/ckWFDcOsYEUA?linkname=lCGuqgvUDP
954
+ */
955
+ async claimRewards(t) {
956
+ await this.token.autoLogin();
957
+ const { data: r, code: i } = await this.req.post(
958
+ `event/${this.event}/claim-rewards`,
959
+ s(t),
960
+ pt
961
+ );
962
+ return (r == null ? void 0 : r.claimed_items) ?? {
963
+ error: i
964
+ };
965
+ }
966
+ /**
967
+ * 用户领取红包奖励
968
+ *
969
+ * https://kdocs.cn/l/ckWFDcOsYEUA?linkname=aQLhlOAB4Q
970
+ */
971
+ async claimWeixinHongbao(t) {
972
+ await this.token.autoLogin();
973
+ const { data: r, code: i } = await this.req.post(
974
+ `event/${this.event}/claim-weixin-hongbao`,
975
+ { reward_id: t },
976
+ ft
977
+ );
978
+ return r ?? {
979
+ error: i
980
+ };
981
+ }
982
+ /**
983
+ * 查询用户活动奖励列表
984
+ *
985
+ * https://kdocs.cn/l/ckWFDcOsYEUA?linkname=qj12eIgYQG
986
+ */
987
+ async getUserRewards(t) {
988
+ if (!await this.token.autoLogin()) return [];
989
+ const { data: r } = await this.req.post(
990
+ "event/user-rewards",
991
+ s({ ...t, event_id: this.event }),
992
+ yt
993
+ );
994
+ return (r == null ? void 0 : r.user_rewards) || [];
995
+ }
996
+ /**
997
+ * 查询用户活动道具数量。注意,这里只能是活动道具
998
+ *
999
+ * https://kdocs.cn/l/ckWFDcOsYEUA?linkname=mnGCTeTgMb
1000
+ */
1001
+ async getUserItemCount(t) {
1002
+ if (!await this.token.autoLogin()) return null;
1003
+ const { data: r } = await this.req.get(`event/${this.event}/user-item-count`, d, {
1004
+ params: { item_id: t }
1005
+ });
1006
+ return (r == null ? void 0 : r.count) ?? null;
1007
+ }
1008
+ /**
1009
+ * 填写实物奖励收货地址
1010
+ *
1011
+ * https://kdocs.cn/l/ckWFDcOsYEUA?linkname=QIwGhnaexb
1012
+ */
1013
+ async submitUserRewardAddress(t) {
1014
+ if (!await this.token.autoLogin()) return null;
1015
+ const { ok: r } = await this.req.post(`event/${this.event}/user-reward-address`, t);
1016
+ return r;
1017
+ }
1018
+ /**
1019
+ * 小程序码携带参数最多 32 个可见字符,若前端携带参数过长,则将参数保存在 api 中,并返回符合小程序码要求的 scene
1020
+ *
1021
+ * https://kdocs.cn/l/ckWFDcOsYEUA?linkname=TbEeyUmZzN
1022
+ *
1023
+ * @param params - 前端扫描二维码打开小程序所需参数
1024
+ */
1025
+ async getUnlimitQrcodeScene(t) {
1026
+ if (!await this.token.autoLogin()) return null;
1027
+ const { data: r } = await this.req.get("event/unlimit-qrcode-scene", wt, {
1028
+ params: { params: t }
1029
+ });
1030
+ return (r == null ? void 0 : r.scene) ?? null;
1031
+ }
1032
+ /**
1033
+ * 根据小程序码携带 scene 值,获取对应的前端所需参数
1034
+ *
1035
+ * https://kdocs.cn/l/ckWFDcOsYEUA?linkname=SzWPFZDQBV
1036
+ *
1037
+ * @param scene - 小程序码 scene 值
1038
+ */
1039
+ async getParamsByQrcodeScene(t) {
1040
+ const { data: r } = await this.req.get("event/params-by-qrcode-scene", ht, {
1041
+ params: { scene: t }
1042
+ });
1043
+ return (r == null ? void 0 : r.params) ?? null;
1044
+ }
1045
+ /**
1046
+ * 生成不限制的带参数的小程序码(data URI格式的小程序码)
1047
+ *
1048
+ * https://kdocs.cn/l/ckWFDcOsYEUA?linkname=Rvmoq8iIy0
1049
+ */
1050
+ async generateUnlimitQrcode(t) {
1051
+ if (!await this.token.autoLogin()) return null;
1052
+ const { data: r } = await this.req.post("event/unlimit-qrcode", s(t), vt);
1053
+ return (r == null ? void 0 : r.img) ?? null;
1054
+ }
1055
+ }
1056
+ function F(e) {
1057
+ return n(e, "forum_id", "icon_url", "name", "tags", "sort", "mode", "member_ids") && Array.isArray(e.tags) && Array.isArray(e.member_ids);
1058
+ }
1059
+ function kt(e) {
1060
+ return n(e, "forums") && a(e.forums, F);
1061
+ }
1062
+ function h(e) {
1063
+ return n(e, "topic_id", "cover_url", "name", "description", "tags", "post_num") && Array.isArray(e.tags);
1064
+ }
1065
+ function bt(e) {
1066
+ return n(e, "topics") && a(e.topics, h);
1067
+ }
1068
+ function qt(e) {
1069
+ return n(e, "topic") && h(e.topic);
1070
+ }
1071
+ function v(e) {
1072
+ return n(
1073
+ e,
1074
+ "post_id",
1075
+ "forum",
1076
+ "posted_by",
1077
+ "nickname",
1078
+ "avatar_url",
1079
+ "content",
1080
+ "summary",
1081
+ "like_num",
1082
+ "comments_num",
1083
+ "liked",
1084
+ "image_urls",
1085
+ "topics",
1086
+ "event_ids",
1087
+ "is_pinned",
1088
+ "is_highlighted",
1089
+ "status",
1090
+ "create_time"
1091
+ ) && a(e.topics, h) && F(e.forum);
1092
+ }
1093
+ function C(e) {
1094
+ return n(e, "next_token", "posts") && a(e.posts, v);
1095
+ }
1096
+ function Rt(e) {
1097
+ return n(e, "post") && v(e.post);
1098
+ }
1099
+ function k(e) {
1100
+ return n(e);
1101
+ }
1102
+ function At(e) {
1103
+ return n(e) && ("post" in e ? v(e.post) : !0) && ("antispam" in e ? k(e.antispam) : !0);
1104
+ }
1105
+ function l(e) {
1106
+ return n(
1107
+ e,
1108
+ "comment_id",
1109
+ "post_id",
1110
+ "commented_by",
1111
+ "nickname",
1112
+ "avatar_url",
1113
+ "content",
1114
+ "like_num",
1115
+ "reply_num",
1116
+ "liked",
1117
+ "image_url",
1118
+ "create_time",
1119
+ "status"
1120
+ ) && ("replies" in e ? a(e.replies, b) : !0);
1121
+ }
1122
+ function xt(e) {
1123
+ return n(e, "comment") && l(e.comment);
1124
+ }
1125
+ function Lt(e) {
1126
+ return n(e, "comments") && a(e.comments, l);
1127
+ }
1128
+ function b(e) {
1129
+ return n(
1130
+ e,
1131
+ "reply_id",
1132
+ "comment_id",
1133
+ "replied_by",
1134
+ "nickname",
1135
+ "avatar_url",
1136
+ "content",
1137
+ "like_num",
1138
+ "liked",
1139
+ "reply_to",
1140
+ "create_time"
1141
+ ) && Ct(e.reply_to);
1142
+ }
1143
+ function Ct(e) {
1144
+ return n(e, "reply_id", "replied_by", "avatar_url", "nickname");
1145
+ }
1146
+ function Pt(e) {
1147
+ return n(e) && ("comment" in e ? l(e.comment) : !0) && ("antispam" in e ? k(e.antispam) : !0);
1148
+ }
1149
+ function Ut(e) {
1150
+ return n(e, "replies") && a(e.replies, b);
1151
+ }
1152
+ function $t(e) {
1153
+ return n(e, "reply") && b(e.reply);
1154
+ }
1155
+ function Dt(e) {
1156
+ return n(e) && ("reply" in e ? l(e.comment) : !0) && ("antispam" in e ? k(e.antispam) : !0);
1157
+ }
1158
+ function Et(e) {
1159
+ return n(e, "image_url", "upload_url", "existed") && typeof e.existed == "boolean";
1160
+ }
1161
+ function Ft(e) {
1162
+ return n(
1163
+ e,
1164
+ "notification_id",
1165
+ "notification_type",
1166
+ "is_read",
1167
+ "create_time",
1168
+ "origin_user_id",
1169
+ "origin_user_name",
1170
+ "origin_user_avatar_url"
1171
+ );
1172
+ }
1173
+ function Gt(e) {
1174
+ return n(e, "notifications") && a(e.notifications, Ft);
1175
+ }
1176
+ function It(e) {
1177
+ return n(e, "system", "comment", "like");
1178
+ }
1179
+ var St = /* @__PURE__ */ ((e) => (e.All = "all", e.Limit = "limit", e))(St || {}), Mt = /* @__PURE__ */ ((e) => (e.Pending = "pending", e.Approved = "approved", e.Failed = "failed", e.Suspect = "suspect", e))(Mt || {}), Bt = /* @__PURE__ */ ((e) => (e.System = "system", e.Comment = "comment", e.Like = "like", e))(Bt || {}), Vt = /* @__PURE__ */ ((e) => (e.System = "system", e.PostPinned = "post_pinned", e.PostHighlighted = "post_highlighted", e.PostDeleted = "post_deleted", e.PostCommented = "post_commented", e.PostLiked = "post_liked", e.CommentReplied = "comment_replied", e.CommentLiked = "comment_liked", e.CommentDeleted = "comment_deleted", e.ReplyReplied = "reply_replied", e.ReplyLiked = "reply_liked", e.ReplyDeleted = "reply_deleted", e))(Vt || {});
1180
+ class Xt {
1181
+ constructor(t) {
1182
+ u(this, "token");
1183
+ u(this, "req");
1184
+ this.token = t, this.req = t.req;
1185
+ }
1186
+ /**
1187
+ * 获取社区版块列表,仅返回启用状态的版块
1188
+ *
1189
+ * https://kdocs.cn/l/cbggfJodHLIz?linkname=QaqUa2K0z0
1190
+ */
1191
+ async getForums() {
1192
+ const { data: t } = await this.req.get("community/forums", kt);
1193
+ return (t == null ? void 0 : t.forums) || [];
1194
+ }
1195
+ /**
1196
+ * 获取社区话题列表,仅返回启用状态的话题
1197
+ *
1198
+ * https://kdocs.cn/l/cbggfJodHLIz?linkname=mIwpymAQom
1199
+ */
1200
+ async getTopics() {
1201
+ const { data: t } = await this.req.get("community/topics", bt);
1202
+ return (t == null ? void 0 : t.topics) || [];
1203
+ }
1204
+ /**
1205
+ * 根据话题 ID 获取社区话题信息
1206
+ *
1207
+ * https://kdocs.cn/l/cbggfJodHLIz?linkname=Jvw7xMK31K
1208
+ */
1209
+ async getTopic(t) {
1210
+ const { data: r, code: i } = await this.req.get("community/topic", qt, {
1211
+ params: { topic_id: t }
1212
+ });
1213
+ return (r == null ? void 0 : r.topic) ?? { error: i };
1214
+ }
1215
+ /**
1216
+ * 获取社区帖子列表
1217
+ *
1218
+ * https://kdocs.cn/l/cbggfJodHLIz?linkname=XKI9lDVrPq
1219
+ */
1220
+ async getPosts(t) {
1221
+ const { data: r, code: i } = await this.req.get("community/posts", C, {
1222
+ params: s(t)
1223
+ });
1224
+ return r ?? { error: i };
1225
+ }
1226
+ /**
1227
+ * 获取社区置顶帖子列表
1228
+ *
1229
+ * https://kdocs.cn/l/cbggfJodHLIz?linkname=yXubbZuDlC
1230
+ */
1231
+ async getPinnedPosts(t, r, i) {
1232
+ const { data: c, code: m } = await this.req.get("community/pinned-posts", C, {
1233
+ params: s({ forum_id: t, max_results: r, next_token: i })
1234
+ });
1235
+ return c ?? { error: m };
1236
+ }
1237
+ /**
1238
+ * 根据帖子 id 获取帖子详情
1239
+ *
1240
+ * https://kdocs.cn/l/cbggfJodHLIz?linkname=hj1AZy5rcP
1241
+ */
1242
+ async getPost(t) {
1243
+ const { data: r, code: i } = await this.req.get("community/post", Rt, {
1244
+ params: { post_id: t }
1245
+ });
1246
+ return (r == null ? void 0 : r.post) ?? { error: i };
1247
+ }
1248
+ /**
1249
+ * 发布帖子
1250
+ *
1251
+ * https://kdocs.cn/l/cbggfJodHLIz?linkname=M5okHBuaVk
1252
+ */
1253
+ async post(t) {
1254
+ const { data: r, code: i } = await this.req.post("community/post", s(t), At);
1255
+ return r ?? {
1256
+ error: i
1257
+ };
1258
+ }
1259
+ /**
1260
+ * 获取社区帖子评论列表
1261
+ *
1262
+ * https://kdocs.cn/l/cbggfJodHLIz?linkname=djKbX7lFdp
1263
+ */
1264
+ async getComments(t) {
1265
+ const { data: r, code: i } = await this.req.get("community/comments", Lt, {
1266
+ params: s(t)
1267
+ });
1268
+ return r ?? { error: i };
1269
+ }
1270
+ /**
1271
+ * 根据评论 id 获取评论详情
1272
+ *
1273
+ * https://kdocs.cn/l/cbggfJodHLIz?linkname=RIc7oxVGae
1274
+ */
1275
+ async getComment(t) {
1276
+ const { data: r, code: i } = await this.req.get("community/comment", xt, {
1277
+ params: { comment_id: t }
1278
+ });
1279
+ return (r == null ? void 0 : r.comment) ?? { error: i };
1280
+ }
1281
+ /**
1282
+ * 帖子下发表评论
1283
+ *
1284
+ * https://kdocs.cn/l/cbggfJodHLIz?linkname=Nv7lk0nTmr
1285
+ */
1286
+ async comment(t) {
1287
+ await this.token.autoLogin();
1288
+ const { data: r, code: i } = await this.req.post("community/comment", s(t), Pt);
1289
+ return r ?? {
1290
+ error: i
1291
+ };
1292
+ }
1293
+ /**
1294
+ * 获取社区帖子评论回复列表
1295
+ *
1296
+ * https://kdocs.cn/l/cbggfJodHLIz?linkname=sVKBbY83MY
1297
+ */
1298
+ async getReplies(t) {
1299
+ const { data: r } = await this.req.get("community/replies", Ut, {
1300
+ params: s({ max_results: 20, ...t })
1301
+ });
1302
+ return r ?? { replies: [] };
1303
+ }
1304
+ /**
1305
+ * 根据回复 id 获取回复详情
1306
+ *
1307
+ * https://kdocs.cn/l/cbggfJodHLIz?linkname=kxhcSXD3MG
1308
+ */
1309
+ async getReply(t) {
1310
+ const { data: r, code: i } = await this.req.get("community/reply", $t, {
1311
+ params: { reply_id: t }
1312
+ });
1313
+ return (r == null ? void 0 : r.reply) ?? { error: i };
1314
+ }
1315
+ /**
1316
+ * 回复帖子评论或回复
1317
+ *
1318
+ * https://kdocs.cn/l/cbggfJodHLIz?linkname=KA8WpTX2pg
1319
+ */
1320
+ async reply(t) {
1321
+ await this.token.autoLogin();
1322
+ const { data: r, code: i } = await this.req.post("community/reply", s(t), Dt);
1323
+ return r ?? {
1324
+ error: i
1325
+ };
1326
+ }
1327
+ /**
1328
+ * 对 帖子/评论/回复 点赞
1329
+ *
1330
+ * https://kdocs.cn/l/cbggfJodHLIz?linkname=CR3m6PyXfZ
1331
+ */
1332
+ async like(t) {
1333
+ await this.token.autoLogin();
1334
+ const { ok: r, code: i } = await this.req.post("community/like", { ...t, action: "like" });
1335
+ return r || {
1336
+ error: i
1337
+ };
1338
+ }
1339
+ /**
1340
+ * 对 帖子/评论/回复 取消点赞
1341
+ *
1342
+ * https://kdocs.cn/l/cbggfJodHLIz?linkname=CR3m6PyXfZ
1343
+ */
1344
+ async unlike(t) {
1345
+ await this.token.autoLogin();
1346
+ const { ok: r, code: i } = await this.req.post("community/like", { ...t, action: "unlike" });
1347
+ return r || {
1348
+ error: i
1349
+ };
1350
+ }
1351
+ /**
1352
+ * 获取资源预上传地址
1353
+ *
1354
+ * https://kdocs.cn/l/cbggfJodHLIz?linkname=dWWhpoShxZ
1355
+ */
1356
+ async getMediaPresignUrl(t) {
1357
+ await this.token.autoLogin();
1358
+ const { data: r } = await this.req.get("community/media-presign-url", Et, {
1359
+ params: t
1360
+ });
1361
+ return r;
1362
+ }
1363
+ /**
1364
+ * 获取用户社区通知
1365
+ *
1366
+ * 了解更多[通知的分类](https://kdocs.cn/l/cbggfJodHLIz?linkname=AiCR5khgOr)。
1367
+ *
1368
+ * https://kdocs.cn/l/cbggfJodHLIz?linkname=W5lceDgbBG
1369
+ */
1370
+ async getNotifications(t) {
1371
+ await this.token.autoLogin();
1372
+ const { data: r } = await this.req.get("community/notifications", Gt, {
1373
+ params: s({ max_results: 20, ...t })
1374
+ });
1375
+ return r || { notifications: [] };
1376
+ }
1377
+ /**
1378
+ * 获取用户未读通知数量
1379
+ *
1380
+ * https://kdocs.cn/l/cbggfJodHLIz?linkname=CwIOMjAfMU
1381
+ */
1382
+ async getUnreadNotificationsCount() {
1383
+ if (!await this.token.autoLogin()) return null;
1384
+ const { data: t } = await this.req.get("community/unread-notifications-count", It);
1385
+ return t;
1386
+ }
1387
+ /**
1388
+ * 社区用户将通知标为已读
1389
+ *
1390
+ * https://kdocs.cn/l/cbggfJodHLIz?linkname=TCJQxnOjJe
1391
+ */
1392
+ async clearUnreadNotifications(t) {
1393
+ if (!await this.token.autoLogin()) return !1;
1394
+ const { ok: r } = await this.req.post("community/clear-unread-notifications", { category: t });
1395
+ return r;
1396
+ }
1397
+ }
1398
+ function p(e) {
1399
+ return n(e, "openid", "unionid", "weixin_token");
1400
+ }
1401
+ var Qt = /* @__PURE__ */ ((e) => (e.RedirectUriDisMatch = "10003", e.AppidError = "10016", e.AuthorizationError = "10015", e.NoRightForScope = "10005", e.Frequently = "10009", e.AppBanded = "10004", e.ShouldFllow = "10006", e.ScopeNull = "10010", e.RedirectUriNull = "10011", e.AppidNull = "10012", e.StateNull = "10013", e))(Qt || {});
1402
+ const P = "wx_login_cache";
1403
+ class Yt {
1404
+ /**
1405
+ * 创建微信相关功能接口
1406
+ *
1407
+ * - authToken 需要导入 AuthToken 进行初始化后传入
1408
+ * - appid 可以静态设置,也可以在小程序中动态获取,见下示例代码
1409
+ *
1410
+ * ```js
1411
+ * const info = wx.getAccountInfoSync();
1412
+ * console.log(info.miniProgram.appId)
1413
+ * ```
1414
+ *
1415
+ * https://developers.weixin.qq.com/miniprogram/dev/api/open-api/account-info/wx.getAccountInfoSync.html
1416
+ */
1417
+ constructor(t, r) {
1418
+ u(this, "token");
1419
+ u(this, "appid");
1420
+ u(this, "req");
1421
+ this.token = t, this.req = t.req, this.appid = r, this.getLoginCache();
1422
+ }
1423
+ /**
1424
+ * 检查缓存中的登录数据
1425
+ *
1426
+ * 如果没有缓存或缓存数据错误,则需要调用 [wx.login](https://developers.weixin.qq.com/miniprogram/dev/api/open-api/login/wx.login.html) 后调用 login 方法
1427
+ *
1428
+ * 也可以直接调用 login 方法,并传入 wxcode 的读取函数
1429
+ */
1430
+ async getLoginCache() {
1431
+ const t = await this.token.storage.get(P);
1432
+ if (!t)
1433
+ return null;
1434
+ const r = J(t);
1435
+ return p(r) ? (this.token.weixinToken = r.weixin_token, await this.token.autoLogin(), r) : null;
1436
+ }
1437
+ /**
1438
+ * 小程序页面微信静默登录,获取 weixinToken / openid / unionid。
1439
+ *
1440
+ * 使用场景:
1441
+ *
1442
+ * - 小程序的任意页面打开后应该优先调用此方法以获取登录状态
1443
+ *
1444
+ * 注意:
1445
+ *
1446
+ * - 登录成功后会将登录信息缓存到本地,重复或并发调用不会引起任何副作用。
1447
+ * - 由于小程序的存储是以用户维度隔离的,每个微信用户在每个小程序下只要成功调用一次此 API 就会缓存请求结果。
1448
+ * - 微信公众号网页授权请使用 webLogin 方法
1449
+ *
1450
+ * https://kdocs.cn/l/cf2mO2uRLqh9?linkname=GwIZ0givCb
1451
+ *
1452
+ * @param wxLoginCodeGetter - 微信小程序调用 [wx.login](https://developers.weixin.qq.com/miniprogram/dev/api/open-api/login/wx.login.html) 获得的登录凭证
1453
+ */
1454
+ async login(t) {
1455
+ const r = await this.getLoginCache();
1456
+ if (r)
1457
+ return r;
1458
+ const i = await t(), { data: c, code: m } = await this.req.post(
1459
+ "weixin/login",
1460
+ { code: i, appid: this.appid },
1461
+ p,
1462
+ { message: !1 }
1463
+ );
1464
+ return c && (this.token.weixinToken = c.weixin_token, await Promise.all([this.token.autoLogin(), this.token.storage.set(P, JSON.stringify(c))])), c ?? { error: m };
1465
+ }
1466
+ /**
1467
+ * 在微信内嵌网页中调用微信公众号授权登录【暂未启用】
1468
+ *
1469
+ * 注意:
1470
+ *
1471
+ * - 登录回调地址强制是当前页面,包括 location search 和 location hash 部分
1472
+ * - 登录跳转返回 code 后,会将 code 从 url 中删除以防止 code 泄露,如需设置分享则需要在此方法执行完毕之后
1473
+ *
1474
+ * 官方参考资料:
1475
+ *
1476
+ * - [微信网页开发 / 网页授权](https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html)
1477
+ *
1478
+ * @param scope - 网页授权作用域
1479
+ * - snsapi_base 不弹出授权页面,用户无感知,只能获取用户 openid,如果需要获取 unionid 则需要 snsapi_userinfo
1480
+ * - snsapi_userinfo 【默认】弹出授权页面,可拿到 openid、unionid、昵称、头像等信息,但用户也可能会拒绝授权
1481
+ */
1482
+ async webLogin(t = "snsapi_userinfo") {
1483
+ const r = f("code"), i = Date.now(), c = +f("state");
1484
+ if (!r || !c || c < i - 1e3 * 60 * 5 || c > i) {
1485
+ const I = q(["code", "state"]);
1486
+ location.replace(
1487
+ `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${this.appid}&redirect_uri=${encodeURIComponent(I)}&response_type=code&scope=${t}&state=${i}#wechat_redirect`
1488
+ );
1489
+ return;
1490
+ }
1491
+ if (/^100\d{2}$/.test(r))
1492
+ return { error: r };
1493
+ const m = q(["code", "state"]);
1494
+ "replaceState" in history && history.replaceState({}, "", m);
1495
+ const { data: _, code: G } = await this.req.post(
1496
+ "weixin/login",
1497
+ {
1498
+ code: r,
1499
+ appid: this.appid
1500
+ },
1501
+ p
1502
+ );
1503
+ return _ && (this.token.weixinToken = _.weixin_token, await this.token.autoLogin()), _ ?? { error: G };
1504
+ }
1505
+ /**
1506
+ * 关联游戏账号,无返回值,全程静默
1507
+ *
1508
+ * 用于从游戏内跳转至小程序时,将微信用户身份和游戏内身份关联起来,使得后续的企业微信客服流程能够知道该微信用户在游戏内的身份。
1509
+ *
1510
+ * https://kdocs.cn/l/cf2mO2uRLqh9?linkname=ci73N833Mk
1511
+ *
1512
+ * @param weixinToken 调用 login 后,得到的 weixinToken,如果 weixinToken 为空则跳过不处理
1513
+ * @param gameCode 从游戏内跳转至小程序时,通过请求参数 query 携带的 game_code,如果值为空则跳过不处理
1514
+ */
1515
+ async linkPlayer(t, r) {
1516
+ !t || !r || await this.req.post(
1517
+ "weixin/link-player",
1518
+ {
1519
+ weixin_token: t,
1520
+ game_code: r
1521
+ },
1522
+ null,
1523
+ {
1524
+ message: !1
1525
+ }
1526
+ );
38
1527
  }
39
1528
  }
40
1529
  export {
41
- T as GamerApi
1530
+ Ot as AuthToken,
1531
+ qe as CliamRewardStatus,
1532
+ Kt as ClubApi,
1533
+ ge as ClubCreditChangeSence,
1534
+ _e as ClubCreditChangeType,
1535
+ de as ClubItemType,
1536
+ pe as ClubRedemptionStatus,
1537
+ Xt as CommunityApi,
1538
+ ye as EngageAccountType,
1539
+ Nt as EventApi,
1540
+ we as EventPeriodType,
1541
+ o as FeatureType,
1542
+ St as ForumMode,
1543
+ fe as GamerItemType,
1544
+ le as Gender,
1545
+ Ce as LotteryDrawAction,
1546
+ xe as LotteryTicketStatus,
1547
+ Bt as NotificationCategory,
1548
+ Vt as NotificationType,
1549
+ Mt as PostStatus,
1550
+ he as QuestObjective,
1551
+ Re as RewardSoure,
1552
+ ke as RewardStatusPrefix,
1553
+ be as RewardStatusSuffix,
1554
+ Le as TeamAction,
1555
+ Ae as TeamVisibility,
1556
+ ve as VoteOptionSource,
1557
+ Yt as WeixinApi,
1558
+ Qt as WeixinWebLoginErrorCode
42
1559
  };