@seayoo-web/gamer-api 2.5.3 → 2.5.5

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.
Files changed (2) hide show
  1. package/dist/index.js +61 -63
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -2,14 +2,14 @@ var me = Object.defineProperty;
2
2
  var de = (a, t, r) => t in a ? me(a, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : a[t] = r;
3
3
  var d = (a, t, r) => de(a, typeof t != "symbol" ? t + "" : t, r);
4
4
  import { isComboWebView as ge } from "@seayoo-web/combo-webview";
5
- import { isPlainObject as V, useConsole as pe, Support as y, usePromise as _e, pruneURL as be, queryString as P, pruneObject as c, v as e, omitFields as R, typedObjectGuard as s, parseJSON as ye, removePara as M } from "@seayoo-web/utils";
5
+ import { isPlainObject as C, Support as y, useConsole as pe, usePromise as _e, pruneURL as be, queryString as P, pruneObject as c, v as e, omitFields as V, typedObjectGuard as s, parseJSON as ye, removePara as Q } from "@seayoo-web/utils";
6
6
  function fe(a) {
7
- return V(a, "gamer_token") && typeof a.gamer_token == "string";
7
+ return C(a, "gamer_token") && typeof a.gamer_token == "string";
8
8
  }
9
- function Q(a) {
10
- return V(a);
9
+ function M(a) {
10
+ return C(a);
11
11
  }
12
- const w = pe("GamerApiSDK");
12
+ const q = pe("GamerApiSDK");
13
13
  function he(a) {
14
14
  return /^\/[a-z\d-]+$/.test(a);
15
15
  }
@@ -39,7 +39,7 @@ const ke = {
39
39
  try {
40
40
  if (y.wx) return wx.getStorageSync(a) || "";
41
41
  } catch (t) {
42
- w.error("getStorageSyncError", t);
42
+ q.error("getStorageSyncError", t);
43
43
  }
44
44
  return "";
45
45
  },
@@ -47,17 +47,17 @@ const ke = {
47
47
  try {
48
48
  y.wx && wx.setStorageSync(a, t);
49
49
  } catch (r) {
50
- w.error("setStorageSyncError", r);
50
+ q.error("setStorageSyncError", r);
51
51
  }
52
52
  },
53
53
  remove(a) {
54
54
  try {
55
55
  y.wx && wx.removeStorageSync(a);
56
56
  } catch (t) {
57
- w.error("removeStorageSync", t);
57
+ q.error("removeStorageSync", t);
58
58
  }
59
59
  }
60
- }, k = "gamer_token";
60
+ }, w = "gamer_token";
61
61
  class Sr {
62
62
  constructor(t, r) {
63
63
  d(this, "$NetRequest");
@@ -98,7 +98,7 @@ class Sr {
98
98
  return this.$NetRequest;
99
99
  }
100
100
  loadGamerTokenCache() {
101
- const r = this.storage.get(k).match(/^(\d{12,})#(.{8,})$/);
101
+ const r = this.storage.get(w).match(/^(\d{12,})#(.{8,})$/);
102
102
  if (r) {
103
103
  const n = parseInt(r[1]), i = r[2];
104
104
  if (n > Date.now() - (24 * 3600 - 10) * 1e3) {
@@ -106,7 +106,7 @@ class Sr {
106
106
  return;
107
107
  }
108
108
  }
109
- this.storage.remove(k);
109
+ this.storage.remove(w);
110
110
  }
111
111
  /** 当前是否为登录状态,即是否拥有 gamerToken */
112
112
  get isLoggedIn() {
@@ -140,7 +140,7 @@ class Sr {
140
140
  * 直接写入 Gamer Token,并更新缓存
141
141
  */
142
142
  set gamerToken(t) {
143
- this.$gamerToken = t, t ? this.storage.set(k, `${Date.now()}#${t}`) : this.storage.remove(k);
143
+ this.$gamerToken = t, t ? this.storage.set(w, `${Date.now()}#${t}`) : this.storage.remove(w);
144
144
  }
145
145
  /**
146
146
  * 退出登录,销毁相关 Token
@@ -167,10 +167,8 @@ class Sr {
167
167
  async autoLogin() {
168
168
  if (this.gamerToken)
169
169
  return !0;
170
- if (!this.idToken)
171
- return w.error("Missing idToken when call autoLogin()"), !1;
172
- if (y.wx && !this.weixinToken)
173
- return w.error("Missing weixinToken when call autoLogin()"), !1;
170
+ if (!this.idToken || y.wx && !this.weixinToken)
171
+ return !1;
174
172
  const { code: t, data: r } = await this.req.post(
175
173
  "login-with-token",
176
174
  c({ id_token: this.idToken, weixin_token: y.wx ? this.weixinToken : null }),
@@ -196,7 +194,7 @@ class Sr {
196
194
  */
197
195
  async getSession() {
198
196
  if (!await this.autoLogin()) return null;
199
- const { data: t } = await this.req.get("session", Q, {
197
+ const { data: t } = await this.req.get("session", M, {
200
198
  message: !1
201
199
  });
202
200
  return t;
@@ -208,7 +206,7 @@ class Sr {
208
206
  */
209
207
  async authRealName(t) {
210
208
  if (!await this.autoLogin()) return null;
211
- const { data: r } = await this.req.post("auth-real-name", c(t), Q);
209
+ const { data: r } = await this.req.post("auth-real-name", c(t), M);
212
210
  return r;
213
211
  }
214
212
  }
@@ -364,7 +362,7 @@ const Ce = {
364
362
  updated_at: e.number(),
365
363
  redeemable_quantity: e.number().optional()
366
364
  }).lock(), Ae = e.object({
367
- ...R(ee.shape, "tag"),
365
+ ...V(ee.shape, "tag"),
368
366
  product: te.clone().optional()
369
367
  }).lock(), Lr = e.union(
370
368
  e.object({
@@ -401,7 +399,7 @@ const Ce = {
401
399
  status: Le,
402
400
  created_at: e.number(),
403
401
  extra_data: e.union(Ne.clone(), Oe.clone()).satisfies().optional()
404
- }), Me = e.guard(Ee), K = s({ player: Pe }), Qe = s({ roles: e.array(Y) }), x = s({ role_card: Fe }), H = e.guard(De), z = e.guard(W), Ke = s({ addresses: e.array(W) }), He = e.guard(Ie), ze = s({
402
+ }), Qe = e.guard(Ee), K = s({ player: Pe }), Me = s({ roles: e.array(Y) }), x = s({ role_card: Fe }), H = e.guard(De), z = e.guard(W), Ke = s({ addresses: e.array(W) }), He = e.guard(Ie), ze = s({
405
403
  credit_logs: e.array(Ge),
406
404
  next_token: e.string().optional()
407
405
  }), Je = s({ products: e.array(te) }), Ze = s({ benefits: e.array(ee) }), Xe = s({ benefit: Ae }), Ye = s({
@@ -420,7 +418,7 @@ class Er {
420
418
  * https://kdocs.cn/l/cgp4gSBMbOf1?linkname=tuhsPt3ihp
421
419
  */
422
420
  async getConfig(t) {
423
- const { data: r } = await this.req.get("club/config", Me, t);
421
+ const { data: r } = await this.req.get("club/config", Qe, t);
424
422
  return r;
425
423
  }
426
424
  /**
@@ -461,7 +459,7 @@ class Er {
461
459
  */
462
460
  async getRoles(t, r, n) {
463
461
  if (!await this.token.autoLogin()) return [];
464
- const { data: i } = await this.req.get("club/roles", Qe, {
462
+ const { data: i } = await this.req.get("club/roles", Me, {
465
463
  ...n,
466
464
  params: c({ player_id: t, refresh: r })
467
465
  });
@@ -669,7 +667,7 @@ class Er {
669
667
  };
670
668
  }
671
669
  }
672
- const j = {
670
+ const R = {
673
671
  /** 活动道具 */
674
672
  EventItem: "event_item",
675
673
  /** 游戏内道具 */
@@ -690,7 +688,7 @@ const j = {
690
688
  ExternalCode: "external_gift_code",
691
689
  /** 空奖励 */
692
690
  VoidItem: "void_item"
693
- }, ne = e.string().enum(j).lock(), Pr = j, re = ne, We = {
691
+ }, ne = e.string().enum(R).lock(), Pr = R, re = ne, We = {
694
692
  /** 世游通行证 ID / Combo ID */
695
693
  UserId: "user_id",
696
694
  /** 游戏角色 ID */
@@ -816,7 +814,7 @@ const j = {
816
814
  Private: "private",
817
815
  /** 公开队伍 */
818
816
  Public: "public"
819
- }, ut = e.string().enum(ct).lock(), v = {
817
+ }, ut = e.string().enum(ct).lock(), k = {
820
818
  /** 未知状态 */
821
819
  Unknown: "unknown",
822
820
  /** 等待开奖 */
@@ -827,7 +825,7 @@ const j = {
827
825
  Claimed: "claimed",
828
826
  /** 领奖失败 */
829
827
  Fail: "fail"
830
- }, Ur = e.string().enum(v).lock(), lt = {
828
+ }, Ur = e.string().enum(k).lock(), lt = {
831
829
  /** 发起组队 */
832
830
  Assemble: "assemble",
833
831
  /** 加入队伍 */
@@ -845,7 +843,7 @@ const j = {
845
843
  Draw: "draw",
846
844
  /** 领奖 */
847
845
  Claim: "claim"
848
- }, Dr = e.string().enum(mt).lock(), dt = e.string().enum(R(j, "GiftCode", "LotteryTicket")), D = e.object({
846
+ }, Dr = e.string().enum(mt).lock(), dt = e.string().enum(V(R, "GiftCode", "LotteryTicket")), D = e.object({
849
847
  reward_item_id: e.number(),
850
848
  reward_amount: e.number(),
851
849
  reward_item_name: e.string(),
@@ -931,7 +929,7 @@ const j = {
931
929
  }), Et = u.InvitedRegister, Pt = e.object({
932
930
  ...l.shape,
933
931
  feature_type: e.string().enum(Et)
934
- }), $t = e.string().enum(R(j, "GiftCode", "LotteryTicket")), Ut = u.Lottery, Ft = e.object({
932
+ }), $t = e.string().enum(V(R, "GiftCode", "LotteryTicket")), Ut = u.Lottery, Ft = e.object({
935
933
  reward_item_id: e.number(),
936
934
  reward_item_name: e.string(),
937
935
  reward_item_type: $t,
@@ -976,9 +974,9 @@ const j = {
976
974
  required_matches: e.number().min(1).optional()
977
975
  }).optional()
978
976
  })
979
- }), Mt = u.Register, Qt = e.object({
977
+ }), Qt = u.Register, Mt = e.object({
980
978
  ...l.shape,
981
- feature_type: e.string().enum(Mt)
979
+ feature_type: e.string().enum(Qt)
982
980
  }), Kt = u.Share, Ht = e.object({
983
981
  ...l.shape,
984
982
  feature_type: e.string().enum(Kt),
@@ -1044,7 +1042,7 @@ const j = {
1044
1042
  Gt,
1045
1043
  Nt,
1046
1044
  Bt,
1047
- Qt,
1045
+ Mt,
1048
1046
  Ht,
1049
1047
  Jt,
1050
1048
  Xt,
@@ -1091,14 +1089,14 @@ const j = {
1091
1089
  feature_type: rt,
1092
1090
  receive_time: e.number(),
1093
1091
  extra_data: e.record(e.unknown()).optional()
1094
- }), gn = e.string().enum(v.Unknown, v.Pending), pn = e.union(
1092
+ }), gn = e.string().enum(k.Unknown, k.Pending), pn = e.union(
1095
1093
  e.object({
1096
1094
  ticket: e.string(),
1097
1095
  status: gn
1098
1096
  }),
1099
1097
  e.object({
1100
1098
  ticket: e.string(),
1101
- status: e.string().enum(R(v, "Unknown", "Pending")),
1099
+ status: e.string().enum(V(k, "Unknown", "Pending")),
1102
1100
  reward: I
1103
1101
  })
1104
1102
  ).satisfies(), _n = e.object({
@@ -1177,7 +1175,7 @@ const j = {
1177
1175
  Rn,
1178
1176
  e.custom(
1179
1177
  "EmptyObject",
1180
- (a) => V(a) && Object.keys(a).length === 0
1178
+ (a) => C(a) && Object.keys(a).length === 0
1181
1179
  )
1182
1180
  ).satisfies().lock(), Tn = e.object({
1183
1181
  reward_id: e.number(),
@@ -1247,9 +1245,9 @@ const j = {
1247
1245
  claimed_items: e.array(Pn)
1248
1246
  }), Bn = s({
1249
1247
  rewards: e.array(I)
1250
- }), Mn = s({
1251
- reward_status: U
1252
1248
  }), Qn = s({
1249
+ reward_status: U
1250
+ }), Mn = s({
1253
1251
  user_rewards: e.array(I),
1254
1252
  next_token: e.string().optional()
1255
1253
  }), Kn = s({
@@ -1482,7 +1480,7 @@ class Gr {
1482
1480
  const { data: n, code: i, message: o } = await this.req.post(
1483
1481
  "event/claim-weixin-hongbao",
1484
1482
  { reward_id: t },
1485
- Mn,
1483
+ Qn,
1486
1484
  r
1487
1485
  );
1488
1486
  return n ? (n.reward_status = n.reward_status === b.UnclaimedErr ? b.Unclaimed : n.reward_status, n) : {
@@ -1523,7 +1521,7 @@ class Gr {
1523
1521
  const { data: n } = await this.req.post(
1524
1522
  "event/user-rewards",
1525
1523
  c({ max_results: 20, ...t, event_id: this.event }),
1526
- Qn,
1524
+ Mn,
1527
1525
  r
1528
1526
  );
1529
1527
  return {
@@ -1688,7 +1686,7 @@ const Jn = {
1688
1686
  replied_by: e.string(),
1689
1687
  nickname: e.string(),
1690
1688
  avatar_url: e.string()
1691
- }).lock(), T = e.object({
1689
+ }).lock(), j = e.object({
1692
1690
  reply_id: e.number(),
1693
1691
  comment_id: e.number(),
1694
1692
  comment_content: e.string().optional(),
@@ -1703,7 +1701,7 @@ const Jn = {
1703
1701
  liked: e.bool(),
1704
1702
  reply_to: er,
1705
1703
  create_time: e.number()
1706
- }).lock(), C = e.object({
1704
+ }).lock(), v = e.object({
1707
1705
  comment_id: e.number(),
1708
1706
  post_id: e.number(),
1709
1707
  post_subject: e.string().optional(),
@@ -1722,7 +1720,7 @@ const Jn = {
1722
1720
  image_url: e.string(),
1723
1721
  create_time: e.number(),
1724
1722
  status: ae,
1725
- replies: e.array(T).optional()
1723
+ replies: e.array(j).optional()
1726
1724
  }).lock(), tr = e.object({
1727
1725
  image_url: e.string(),
1728
1726
  upload_url: e.string(),
@@ -1743,7 +1741,7 @@ const Jn = {
1743
1741
  post_subject: e.string(),
1744
1742
  post_summary: e.string(),
1745
1743
  post_image_url: e.string()
1746
- }).lock(), q = e.object({
1744
+ }).lock(), T = e.object({
1747
1745
  comment_id: e.number(),
1748
1746
  comment_content: e.string()
1749
1747
  }).lock(), B = e.object({
@@ -1765,16 +1763,16 @@ const Jn = {
1765
1763
  }), or = e.object({
1766
1764
  ...f.shape,
1767
1765
  ...O.shape,
1768
- ...q.shape,
1766
+ ...T.shape,
1769
1767
  notification_type: e.string().enum(p.PostCommented)
1770
1768
  }), ar = e.object({
1771
1769
  ...f.shape,
1772
- ...q.shape,
1770
+ ...T.shape,
1773
1771
  ...B.shape,
1774
1772
  notification_type: e.string().enum(p.CommentReplied)
1775
1773
  }), sr = e.object({
1776
1774
  ...f.shape,
1777
- ...q.shape,
1775
+ ...T.shape,
1778
1776
  ...O.shape,
1779
1777
  notification_type: e.string().enum(p.CommentLiked, p.CommentDeleted)
1780
1778
  }), cr = e.object({
@@ -1787,7 +1785,7 @@ const Jn = {
1787
1785
  }), ur = e.object({
1788
1786
  ...f.shape,
1789
1787
  ...B.shape,
1790
- ...q.shape,
1788
+ ...T.shape,
1791
1789
  notification_type: e.string().enum(p.ReplyLiked, p.ReplyDeleted)
1792
1790
  }), lr = e.union(
1793
1791
  rr,
@@ -1801,17 +1799,17 @@ const Jn = {
1801
1799
  posts: e.array(N),
1802
1800
  next_token: e.string().optional()
1803
1801
  }), _r = s({ post: N, antispam: ce }), br = s({
1804
- replies: e.array(T),
1802
+ replies: e.array(j),
1805
1803
  next_token: e.string().optional()
1806
- }), yr = s({ reply: T }), fr = s({
1807
- reply: T.clone().optional(),
1804
+ }), yr = s({ reply: j }), fr = s({
1805
+ reply: j.clone().optional(),
1808
1806
  antispam: ce.clone().optional()
1809
- }), hr = s({ comment: C }), wr = s({
1810
- comments: e.array(C),
1807
+ }), hr = s({ comment: v }), wr = s({
1808
+ comments: e.array(v),
1811
1809
  next_token: e.string().optional()
1812
1810
  }), kr = s({
1813
- comment: C.clone().optional(),
1814
- antispam: C.clone().optional()
1811
+ comment: v.clone().optional(),
1812
+ antispam: v.clone().optional()
1815
1813
  }), vr = e.guard(tr), Cr = s({
1816
1814
  notifications: e.array(lr),
1817
1815
  next_token: e.string().optional()
@@ -2113,7 +2111,7 @@ const Rr = s({
2113
2111
  });
2114
2112
  var jr = /* @__PURE__ */ ((a) => (a.RedirectUriDisMatch = "10003", a.AppidError = "10016", a.AuthorizationError = "10015", a.NoRightForScope = "10005", a.Frequently = "10009", a.AppBanded = "10004", a.ShouldFollow = "10006", a.ScopeNull = "10010", a.RedirectUriNull = "10011", a.AppidNull = "10012", a.StateNull = "10013", a))(jr || {});
2115
2113
  function E(a) {
2116
- return V(a, "open_id", "union_id", "weixin_token");
2114
+ return C(a, "open_id", "union_id", "weixin_token");
2117
2115
  }
2118
2116
  const Z = "wx_login_cache";
2119
2117
  class Or {
@@ -2182,7 +2180,7 @@ class Or {
2182
2180
  E,
2183
2181
  { ...t, message: !1 }
2184
2182
  );
2185
- return i && (this.token.weixinToken = i.weixin_token, this.token.storage.set(Z, JSON.stringify(i)), await this.token.autoLogin()), i ?? {
2183
+ return i && (this.token.weixinToken = i.weixin_token, this.token.storage.set(Z, JSON.stringify(i))), i ?? {
2186
2184
  message: g,
2187
2185
  error: o
2188
2186
  };
@@ -2206,7 +2204,7 @@ class Or {
2206
2204
  async webLogin(t = "snsapi_userinfo", r) {
2207
2205
  const n = P("code"), i = Date.now(), o = +P("state");
2208
2206
  if (!n || !o || o < i - 1e3 * 60 * 5 || o > i) {
2209
- const le = M(["code", "state"]);
2207
+ const le = Q(["code", "state"]);
2210
2208
  location.replace(
2211
2209
  `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${this.appid}&redirect_uri=${encodeURIComponent(le)}&response_type=code&scope=${t}&state=${i}#wechat_redirect`
2212
2210
  );
@@ -2217,7 +2215,7 @@ class Or {
2217
2215
  message: "Error: " + n,
2218
2216
  error: n
2219
2217
  };
2220
- const g = M(["code", "state"]);
2218
+ const g = Q(["code", "state"]);
2221
2219
  "replaceState" in history && history.replaceState({}, "", g);
2222
2220
  const {
2223
2221
  data: m,
@@ -2298,7 +2296,7 @@ export {
2298
2296
  Ie as ClubUserCreditValidator,
2299
2297
  De as ClubUserProfileValidator,
2300
2298
  jn as CommentEngagementValidator,
2301
- C as CommentValidator,
2299
+ v as CommentValidator,
2302
2300
  Nr as CommunityApi,
2303
2301
  We as EngageAccountType,
2304
2302
  et as EngageAccountTypeValidator,
@@ -2319,7 +2317,7 @@ export {
2319
2317
  Dt as EventFeatureConfigOfLotteryValidator,
2320
2318
  Nt as EventFeatureConfigOfPreregisterValidator,
2321
2319
  Bt as EventFeatureConfigOfQuestValidator,
2322
- Qt as EventFeatureConfigOfRegisterValidator,
2320
+ Mt as EventFeatureConfigOfRegisterValidator,
2323
2321
  Ht as EventFeatureConfigOfShareValidator,
2324
2322
  Jt as EventFeatureConfigOfSubscribeValidator,
2325
2323
  Xt as EventFeatureConfigOfSurveyValidator,
@@ -2337,7 +2335,7 @@ export {
2337
2335
  Jn as ForumMode,
2338
2336
  Zn as ForumModeValidator,
2339
2337
  se as ForumValidator,
2340
- j as GamerItemType,
2338
+ R as GamerItemType,
2341
2339
  ne as GamerItemTypeValidator,
2342
2340
  Ce as Gender,
2343
2341
  Ve as GenderValidator,
@@ -2347,14 +2345,14 @@ export {
2347
2345
  Dr as LotteryDrawActionValidator,
2348
2346
  _n as LotteryDrawEngagementDataValidator,
2349
2347
  dn as LotteryEngagementDataValidator,
2350
- v as LotteryTicketStatus,
2348
+ k as LotteryTicketStatus,
2351
2349
  Ur as LotteryTicketStatusValidator,
2352
2350
  f as NotificationBaseValidator,
2353
2351
  Yn as NotificationCategory,
2354
2352
  Ar as NotificationCategoryValidator,
2355
2353
  ar as NotificationCommentReplyValidator,
2356
2354
  sr as NotificationCommentValidator,
2357
- q as NotificationPayloadCommentValidator,
2355
+ T as NotificationPayloadCommentValidator,
2358
2356
  O as NotificationPayloadPostValidator,
2359
2357
  B as NotificationPayloadReplyValidator,
2360
2358
  nr as NotificationPayloadSystemValidator,
@@ -2380,7 +2378,7 @@ export {
2380
2378
  Be as RedemptionValidator,
2381
2379
  gt as RegularRewardValidator,
2382
2380
  er as ReplyToValidator,
2383
- T as ReplyValidator,
2381
+ j as ReplyValidator,
2384
2382
  Pr as RewardItemType,
2385
2383
  re as RewardItemTypeValidator,
2386
2384
  st as RewardSource,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@seayoo-web/gamer-api",
3
3
  "description": "agent for gamer api",
4
- "version": "2.5.3",
4
+ "version": "2.5.5",
5
5
  "type": "module",
6
6
  "source": "index.ts",
7
7
  "main": "./dist/index.js",
@@ -31,10 +31,10 @@
31
31
  "devDependencies": {
32
32
  "@types/node": "^22.13.1",
33
33
  "@seayoo-web/combo-webview": "^2.5.4",
34
- "@seayoo-web/scripts": "^2.6.0",
35
- "@seayoo-web/tsconfig": "^1.0.4",
36
34
  "@seayoo-web/request": "^3.2.0",
37
- "@seayoo-web/utils": "^3.6.1"
35
+ "@seayoo-web/scripts": "^2.6.1",
36
+ "@seayoo-web/utils": "^3.6.1",
37
+ "@seayoo-web/tsconfig": "^1.0.5"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "@seayoo-web/combo-webview": "^2.5.4",