@jetthai/cuora 1.1.488 → 2.0.0-beta.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.
Files changed (212) hide show
  1. package/.husky/pre-commit +3 -1
  2. package/BREAKING_CHANGES.md +9 -0
  3. package/CHANGELOG.md +3 -316
  4. package/README.md +15 -299
  5. package/package.json +5 -5
  6. package/resetGitBranch.sh +101 -0
  7. package/src/api/account.js +1 -0
  8. package/src/api/activity.js +39 -24
  9. package/src/api/auth.js +36 -5
  10. package/src/api/common.js +3 -5
  11. package/src/api/game.js +10 -0
  12. package/src/api/payment.js +55 -17
  13. package/src/api/user.js +16 -10
  14. package/src/index.js +2 -2
  15. package/src/lib/fingerprint_v3_11_12.js +11433 -0
  16. package/src/machine/activity/activity.js +213 -0
  17. package/src/machine/activity/activity_cash.js +36 -84
  18. package/src/machine/activity/cash_rain_activity.js +1 -0
  19. package/src/machine/activity/continue_deposit_activity.js +1 -0
  20. package/src/machine/activity/deposit_activity.js +1 -0
  21. package/src/machine/activity/diamond_shop_activity_cash.js +8 -0
  22. package/src/machine/activity/diamond_shop_activity_fc.js +197 -0
  23. package/src/machine/activity/diamond_shop_activity_vn.js +179 -0
  24. package/src/machine/activity/fafafa_activity.js +11 -0
  25. package/src/machine/activity/friend_invite_friends_activity.js +7 -8
  26. package/src/machine/activity/index.js +12 -0
  27. package/src/machine/activity/instant_rebate_activity.js +1 -0
  28. package/src/machine/activity/invite_friends_activity.js +115 -0
  29. package/src/machine/activity/jackpot.js +1 -0
  30. package/src/machine/activity/mini_game_activity.js +69 -0
  31. package/src/machine/activity/otp_verified_activity.js +1 -0
  32. package/src/machine/activity/ranking_activity.js +1 -0
  33. package/src/machine/activity/return_bonus_activity.js +155 -0
  34. package/src/machine/activity/roulette_activity_v2.js +1 -0
  35. package/src/machine/activity/sign_in_activity.js +1 -0
  36. package/src/machine/activity/sign_in_monthly_activity.js +2 -1
  37. package/src/machine/activity/specify_bets_activity.js +1 -0
  38. package/src/machine/activity/specify_turnover_activity.js +1 -0
  39. package/src/machine/activity/time_bomb_activity.js +1 -0
  40. package/src/machine/activity/vip_card_activity.js +1 -0
  41. package/src/machine/auth.js +112 -149
  42. package/src/machine/auth_otp_v2.js +178 -0
  43. package/src/machine/auth_otp_v3.js +22 -64
  44. package/src/machine/bank_binding.js +3 -2
  45. package/src/machine/bank_binding_amb.js +146 -0
  46. package/src/machine/bonus.js +76 -0
  47. package/src/machine/common.js +98 -14
  48. package/src/machine/deposit/amb.js +93 -0
  49. package/src/machine/deposit/crypto_bank.js +340 -0
  50. package/src/machine/deposit/crypto_bank_cash.js +35 -20
  51. package/src/machine/deposit/crypto_qrcode.js +158 -0
  52. package/src/machine/deposit/crypto_qrcode_cash.js +64 -26
  53. package/src/machine/deposit/crypto_way.js +253 -0
  54. package/src/machine/deposit/crypto_way_cash.js +37 -48
  55. package/src/machine/deposit/deposit_fc.js +272 -0
  56. package/src/machine/deposit/direct.js +311 -0
  57. package/src/machine/deposit/direct_cash.js +10 -8
  58. package/src/machine/deposit/float.js +375 -0
  59. package/src/machine/deposit/index.js +28 -0
  60. package/src/machine/deposit/krway.js +152 -0
  61. package/src/machine/deposit/loadcard_cash.js +32 -14
  62. package/src/machine/deposit/loadcard_vn.js +352 -0
  63. package/src/machine/deposit/manual_cash.js +11 -8
  64. package/src/machine/deposit/manual_vn.js +459 -0
  65. package/src/machine/deposit/qrcode_cash.js +32 -15
  66. package/src/machine/deposit/qrcode_v2.js +339 -0
  67. package/src/machine/deposit/usdt.js +163 -0
  68. package/src/machine/deposit/usdt_cash.js +15 -1
  69. package/src/machine/deposit/virtual_bank_cash.js +12 -13
  70. package/src/machine/deposit/virtual_bank_vn.js +270 -0
  71. package/src/machine/deposit/vpay.js +374 -0
  72. package/src/machine/error.js +1 -7
  73. package/src/machine/game_betslip.js +1 -0
  74. package/src/machine/game_favorite_v2.js +1 -0
  75. package/src/machine/game_hot_new.js +80 -0
  76. package/src/machine/game_info.js +13 -1
  77. package/src/machine/game_replay.js +47 -0
  78. package/src/machine/game_search_cash.js +1 -0
  79. package/src/machine/game_search_v2.js +402 -0
  80. package/src/machine/game_v2_1.js +126 -39
  81. package/src/machine/honor_board.js +133 -0
  82. package/src/machine/honor_board_cash.js +28 -22
  83. package/src/machine/inbox.js +105 -43
  84. package/src/machine/index.js +32 -0
  85. package/src/machine/leaderboard.js +12 -8
  86. package/src/machine/merge.js +58 -0
  87. package/src/machine/navbar.js +3 -1
  88. package/src/machine/payment_data.js +87 -0
  89. package/src/machine/promotions.js +163 -0
  90. package/src/machine/ranking.js +30 -45
  91. package/src/machine/reward.js +256 -0
  92. package/src/machine/reward_cash.js +42 -2
  93. package/src/machine/reward_fc.js +99 -0
  94. package/src/machine/roulette_v2.js +11 -14
  95. package/src/machine/setting.js +1 -0
  96. package/src/machine/side.js +160 -0
  97. package/src/machine/side_cash.js +3 -3
  98. package/src/machine/side_v2.js +223 -0
  99. package/src/machine/user_info.js +1 -0
  100. package/src/machine/user_photo.js +1 -0
  101. package/src/machine/user_reset_password.js +14 -0
  102. package/src/machine/user_sign_up.js +61 -46
  103. package/src/machine/vip_table.js +58 -0
  104. package/src/machine/websocket.js +349 -374
  105. package/src/machine/welcome.js +111 -0
  106. package/src/machine/withdraw/index.js +6 -0
  107. package/src/machine/withdraw/withdraw_crypto_cash.js +328 -0
  108. package/src/machine/withdraw/withdraw_krway.js +223 -0
  109. package/src/machine/withdraw/withdraw_manual.js +541 -0
  110. package/src/machine/withdraw/withdraw_manual_cash.js +39 -59
  111. package/src/request/config.js +0 -2
  112. package/src/request/request.js +60 -124
  113. package/src/util/constant.js +2 -6
  114. package/src/util/deviceToken.js +60 -0
  115. package/src/util/index.js +4 -2
  116. package/src/util/math.js +4 -0
  117. package/src/util/storage.js +4 -3
  118. package/test/api.behavior.test.js +69 -0
  119. package/test/api.contract.test.js +18 -0
  120. package/test/config.test.js +27 -0
  121. package/test/deviceToken.test.js +139 -0
  122. package/test/helpers.coverage.test.js +11 -0
  123. package/test/helpers.js +91 -0
  124. package/test/index.exports.test.js +14 -0
  125. package/test/machine.activity.core.coverage.test.js +337 -0
  126. package/test/machine.activity.gap.coverage.test.js +252 -0
  127. package/test/machine.activity.more.coverage.test.js +180 -0
  128. package/test/machine.activity_plus_and_binding_amb.coverage.test.js +201 -0
  129. package/test/machine.activity_timer_bonus.coverage.test.js +136 -0
  130. package/test/machine.activity_welcome.low.coverage.test.js +211 -0
  131. package/test/machine.amb_rewardfc_websocket.more.coverage.test.js +201 -0
  132. package/test/machine.auth.coverage.test.js +215 -0
  133. package/test/machine.bank_binding.test.js +143 -0
  134. package/test/machine.binding_otp_krway.coverage.test.js +223 -0
  135. package/test/machine.contract.test.js +50 -0
  136. package/test/machine.crypto_bank.coverage.test.js +270 -0
  137. package/test/machine.crypto_way.coverage.test.js +108 -0
  138. package/test/machine.crypto_way_cash.coverage.test.js +114 -0
  139. package/test/machine.definition.test.js +137 -0
  140. package/test/machine.deposit.manual.coverage.test.js +365 -0
  141. package/test/machine.deposit_fc.coverage.test.js +126 -0
  142. package/test/machine.direct.coverage.test.js +96 -0
  143. package/test/machine.direct_cash.coverage.test.js +108 -0
  144. package/test/machine.error.coverage.test.js +37 -0
  145. package/test/machine.events.test.js +126 -0
  146. package/test/machine.favorite_jackpot.coverage.test.js +82 -0
  147. package/test/machine.float.coverage.test.js +136 -0
  148. package/test/machine.flow.test.js +226 -0
  149. package/test/machine.game_hot_new_vip_table.coverage.test.js +105 -0
  150. package/test/machine.game_search_cash.coverage.test.js +155 -0
  151. package/test/machine.game_search_v2.test.js +199 -0
  152. package/test/machine.game_user_profile.coverage.test.js +100 -0
  153. package/test/machine.honor_board.test.js +133 -0
  154. package/test/machine.inbox.common.coverage.test.js +304 -0
  155. package/test/machine.loadcard_cash.coverage.test.js +101 -0
  156. package/test/machine.loadcard_vn.coverage.test.js +122 -0
  157. package/test/machine.misc.coverage.test.js +361 -0
  158. package/test/machine.more2.coverage.test.js +261 -0
  159. package/test/machine.options.execution.test.js +272 -0
  160. package/test/machine.priority.coverage.test.js +603 -0
  161. package/test/machine.qrcode_cash.coverage.test.js +107 -0
  162. package/test/machine.qrcode_v2.coverage.test.js +121 -0
  163. package/test/machine.regression.test.js +82 -0
  164. package/test/machine.roulette_v2.test.js +142 -0
  165. package/test/machine.side_reward_reset.coverage.test.js +220 -0
  166. package/test/machine.targeted.coverage.test.js +313 -0
  167. package/test/machine.usdt.coverage.test.js +95 -0
  168. package/test/machine.usdt_cash.coverage.test.js +73 -0
  169. package/test/machine.vip_card_activity.test.js +114 -0
  170. package/test/machine.virtual_bank_cash.coverage.test.js +105 -0
  171. package/test/machine.virtual_bank_vn.coverage.test.js +105 -0
  172. package/test/machine.vpay.coverage.test.js +142 -0
  173. package/test/machine.withdraw_crypto_cash.coverage.test.js +166 -0
  174. package/test/machine.withdraw_krway.coverage.test.js +123 -0
  175. package/test/machine.withdraw_manual.coverage.test.js +185 -0
  176. package/test/machine.withdraw_manual_cash.coverage.test.js +123 -0
  177. package/test/request.test.js +325 -0
  178. package/test/util.storage.errors.test.js +47 -0
  179. package/test/util.test.js +41 -0
  180. package/.claude/commands/sync-ai-prompts.md +0 -93
  181. package/.claude/settings.local.json +0 -23
  182. package/.github/copilot-instructions.md +0 -448
  183. package/.husky/post-checkout +0 -32
  184. package/.husky/pre-push +0 -36
  185. package/AGENTS.md +0 -448
  186. package/AI_PROMPT_SOURCE.md +0 -446
  187. package/CLAUDE.md +0 -448
  188. package/GEMINI.md +0 -448
  189. package/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +0 -1003
  190. package/docs/kibana/play-providerId-error.md +0 -202
  191. package/docs/kibana/play-selectedWalletType.md +0 -1
  192. package/docs/kibana/play-selectedWalletType_2.md +0 -1
  193. package/docs/kibana/play-selectedWalletType_analysis.md +0 -565
  194. package/docs/my-claude/feat-sharon-JT-1790247240-socket/branch-transfer.md +0 -14
  195. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-preparation.json +0 -40
  196. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-verification.md +0 -41
  197. package/docs/my-claude/feat-sharon-JT-1790247240-socket/implementation-ledger.md +0 -87
  198. package/docs/my-claude/feat-sharon-JT-1790247240-socket/module-report.md +0 -73
  199. package/docs/my-claude/feat-sharon-JT-1790247240-socket/plan.md +0 -309
  200. package/docs/my-claude/feat-sharon-JT-1790247240-socket/test-cases.md +0 -245
  201. package/docs/my-claude/feat-sharon-JT-1791180540-onesignal/transfer.md +0 -9
  202. package/scripts/auto-version.js +0 -68
  203. package/scripts/auto-version.sh +0 -33
  204. package/scripts/branch-auto-npm-publish.js +0 -29
  205. package/scripts/check-version.sh +0 -36
  206. package/scripts/clean-tags.sh +0 -84
  207. package/src/util/amount.js +0 -8
  208. package/src/util/err998SentryExtra.js +0 -26
  209. package/src/util/paramStore.js +0 -139
  210. package/src/util/socketPolicy.js +0 -57
  211. package/test/auth_otp_v3.test.js +0 -323
  212. package/tests/websocket.test.mjs +0 -779
@@ -3,14 +3,14 @@ import payment from '../../api/payment.js'
3
3
  import user from '../../api/user.js'
4
4
 
5
5
  export default function (request, context) {
6
- const { paymentDetail = [], doubleWalletWithdrawLimitCheck = '0' } = context || {}
6
+ const { paymentDetail = [] } = context || {}
7
7
  return createMachine(
8
8
  {
9
9
  id: 'withdraw_manual_cash',
10
+ predictableActionArguments: true,
10
11
  initial: 'loading',
11
12
  context: {
12
13
  paymentDetail,
13
- doubleWalletWithdrawLimitCheck,
14
14
  currentPayment: null,
15
15
  banks: [],
16
16
  paymentInfo: null,
@@ -24,8 +24,6 @@ export default function (request, context) {
24
24
  requestId: null,
25
25
  status: null,
26
26
  target: null,
27
- email: null,
28
- number: null,
29
27
  ttl: null,
30
28
  },
31
29
  states: {
@@ -120,20 +118,31 @@ export default function (request, context) {
120
118
  RESET_OTP: {
121
119
  target: 'reset',
122
120
  },
123
- BACK: {
124
- target: '#withdraw_manual_cash.calculated',
125
- },
121
+ BACK: [
122
+ // {
123
+ // target: '#withdraw_vn2.activity.convertible',
124
+ // cond: 'isActivity',
125
+ // },
126
+ // {
127
+ // target: '#withdraw_vn2.cash.withdrawable',
128
+ // },
129
+ ],
126
130
  },
127
131
  },
128
132
  acknowledging: {
129
133
  invoke: {
130
134
  src: 'acknowledge',
131
- onDone: {
132
- target: '#withdraw_manual_cash.submitted',
133
- actions: 'setProcessing',
134
- },
135
+ onDone: [
136
+ // {
137
+ // target: '#withdraw_vn2.activity.converted',
138
+ // cond: 'isActivity',
139
+ // },
140
+ // {
141
+ // target: '#withdraw_vn2.cash.submitted',
142
+ // },
143
+ ],
135
144
  onError: {
136
- target: '#withdraw_manual_cash.calculated',
145
+ target: 'idle',
137
146
  },
138
147
  },
139
148
  },
@@ -168,7 +177,7 @@ export default function (request, context) {
168
177
  actions: {
169
178
  setInitData: assign((context, event) => {
170
179
  const { currentPayment, paymentInfo, withdrawRule, processing } = event.data
171
- const userBanks = [...paymentInfo.bankList, ...paymentInfo.ewalletList, ...paymentInfo.cryptoList]
180
+ const userBanks = [...paymentInfo.bankList, ...paymentInfo.cryptoList, ...paymentInfo.ewalletList]
172
181
 
173
182
  return {
174
183
  currentPayment,
@@ -195,27 +204,26 @@ export default function (request, context) {
195
204
  }
196
205
  }),
197
206
  setOtp: assign((context, event) => {
198
- const { request_id, email, number, ttl } = event.data
207
+ const { requestId, status, target, ttl } = event.data
199
208
  return {
200
- requestId: request_id,
201
- email,
202
- number,
209
+ requestId,
210
+ status,
211
+ target,
203
212
  ttl,
204
213
  }
205
214
  }),
206
215
  decreaseTtl: assign((context, evnet) => {
207
216
  const second = context.ttl
208
217
  return {
209
- ttl: Math.max(second - 1000, 0),
218
+ ttl: Math.max(second - 1, 0),
210
219
  }
211
220
  }),
212
221
  setVerificationData: assign((context, event) => {
213
- const { request_id, ttl, number, email } = event.data
222
+ const { requestId, ttl, target } = event.data
214
223
  return {
215
- requestId: request_id,
224
+ requestId,
216
225
  ttl,
217
- number,
218
- email,
226
+ target,
219
227
  }
220
228
  }),
221
229
  },
@@ -231,43 +239,15 @@ export default function (request, context) {
231
239
  return selectedUserBank && selectedAmount > 0 && currentPayment.minimum <= selectedAmount && selectedAmount <= currentPayment.maximum
232
240
  },
233
241
  isOtpRequired: (context, event) => {
234
- return event.data?.request_id !== undefined
242
+ return event.data?.status === 'otp-verifying'
235
243
  },
236
244
  },
237
245
  services: {
238
- // 雙錢包出款規則閘門(對齊 client-pwa-ssr useWithdrawManual.initialize 流程):
239
- // - '0':只抓 CASH withdrawRule
240
- // - '1':只抓 ACTIVITY withdrawRule(不論達標與否,CASH 規則不參與閘門,省一次 API)
241
- // - '2' + ACTIVITY 不可提:略過 CASH withdrawRule(少一次 API)
242
- // - '2' + ACTIVITY 達標:續抓 CASH withdrawRule 作為最終出款依據
243
246
  fetchInitData: async (context, event) => {
244
- const { paymentDetail = [], doubleWalletWithdrawLimitCheck = '0' } = context
247
+ const { paymentDetail = [] } = context
245
248
  const currentPayment = paymentDetail.find((element) => element.category === 'manual' && element.transferType === 'withdraw')
246
249
 
247
- let prefetchedRule = null
248
- if (doubleWalletWithdrawLimitCheck === '2' || doubleWalletWithdrawLimitCheck === '1') {
249
- const activityRule = await request.send(payment.getDoubleWalletWithdrawRule({ walletType: 'ACTIVITY' }))
250
- // '1' 模式僅看 ACTIVITY,'2' 模式 ACTIVITY 不可提則 CASH 不參與閘門 — 兩種情況都用 activityRule 為依據。
251
- // enableWithdraw 用 truthy 比較對齊 client-pwa-ssr useWithdrawManual(!enableWithdraw.value),避免 backend 回傳非 boolean truthy 值(如 1)時誤判。
252
- if (doubleWalletWithdrawLimitCheck === '1' || !activityRule?.enableWithdraw) {
253
- prefetchedRule = activityRule
254
- }
255
- }
256
-
257
- if (prefetchedRule) {
258
- const [paymentInfo, orders] = await Promise.all([
259
- request.send(payment.getBindingPaymentInfo()),
260
- request.send(payment.getPendingOrder({ transferType: 'WITHDRAW' })),
261
- ])
262
- return {
263
- currentPayment,
264
- paymentInfo,
265
- withdrawRule: prefetchedRule,
266
- processing: orders[0],
267
- }
268
- }
269
-
270
- const [paymentInfo, cashRule, orders] = await Promise.all([
250
+ const [paymentInfo, withdrawRule, orders] = await Promise.all([
271
251
  request.send(payment.getBindingPaymentInfo()),
272
252
  request.send(payment.getDoubleWalletWithdrawRule({ walletType: 'CASH' })),
273
253
  request.send(payment.getPendingOrder({ transferType: 'WITHDRAW' })),
@@ -276,7 +256,7 @@ export default function (request, context) {
276
256
  return {
277
257
  currentPayment,
278
258
  paymentInfo,
279
- withdrawRule: cashRule,
259
+ withdrawRule,
280
260
  processing: orders[0],
281
261
  }
282
262
  },
@@ -303,20 +283,20 @@ export default function (request, context) {
303
283
  method: currentPayment.method,
304
284
  amount: selectedAmount,
305
285
  cryptoCurrency: selectedUserBank.cryptoCurrency,
306
- cryptoNetwork: selectedUserBank.networkCode,
286
+ cryptoNetwork: selectedUserBank.cryptoNetwork,
307
287
  targetAddress: selectedUserBank.cryptoAddress,
308
288
  applyerHolderName: selectedUserBank.holderName,
309
289
  })
310
290
  )
311
291
  },
312
292
  resetOtp: async (context, event) => {
313
- const { currentPayment, requestId } = context
314
- return await request.send(payment.otpReset({ method: currentPayment.method, requestId }))
293
+ const { requestId, target } = context
294
+ return await request.send(user.otpReset({ requestId, target }))
315
295
  },
316
296
  acknowledge: async (context, event) => {
317
- const { currentPayment, requestId } = context
297
+ const { requestId, target } = context
318
298
  const code = event.data
319
- return await request.send(payment.otpAcknowledge({ method: currentPayment.method, requestId, code }))
299
+ return await request.send(user.otpAcknowledge({ requestId, target, code }))
320
300
  },
321
301
  },
322
302
  }
@@ -16,7 +16,6 @@ export default class Config {
16
16
  defaultSubchannel,
17
17
  socketURL,
18
18
  bucketName,
19
- getDt,
20
19
  }) {
21
20
  this.apiURL = apiURL
22
21
  this.apiVersion = apiVersion
@@ -31,7 +30,6 @@ export default class Config {
31
30
  this.defaultSubchannel = defaultSubchannel
32
31
  this.socketURL = socketURL
33
32
  this.bucketName = bucketName
34
- this.getDt = getDt
35
33
  }
36
34
 
37
35
  setApiURL(url) {
@@ -1,16 +1,11 @@
1
1
  import pickBy from 'lodash/pickBy.js'
2
2
  import storage from '../util/storage.js'
3
- import { getErr998SentryExtra } from '../util/err998SentryExtra.js'
4
-
5
- // 暫停 ERR_998 上報:在組裝 Sentry 資料之前就中止,不建立事件;仍照常 reject ERR_998 給呼叫端。恢復時改回 false 即可
6
- const IS_ERR_998_REPORT_PAUSED = true
7
-
8
- const CANCELLED_MESSAGE = 'Requests Cancelled'
9
3
 
10
4
  // const pickBy = require('lodash/pickBy')
11
5
  const supportVersion2List = [
12
6
  // 04-09 Update
13
7
  'game/play',
8
+ 'game/gameReplay',
14
9
  'game/logout',
15
10
  'game/list/v3/root',
16
11
  'game/list/v3/category',
@@ -22,6 +17,8 @@ const supportVersion2List = [
22
17
  'game/list/v3/removeMyFavorite',
23
18
  'login',
24
19
  'callback/:strategy',
20
+ 'guestLogin',
21
+ 'appLogin',
25
22
  'logout',
26
23
  'self',
27
24
  'register',
@@ -29,6 +26,7 @@ const supportVersion2List = [
29
26
  'verify',
30
27
  'reset',
31
28
  'acknowledge',
29
+ 'recovery',
32
30
  'recovery/abandon',
33
31
  'recovery/acknowledge',
34
32
  'checkDt',
@@ -57,6 +55,7 @@ const supportVersion2List = [
57
55
  'account-binding/status',
58
56
  'account-binding/bind',
59
57
  'account-binding/acknowledge',
58
+ 'account-binding/bind-third-party',
60
59
  'feeds',
61
60
  'broadcast',
62
61
  'upload',
@@ -75,13 +74,18 @@ const supportVersion2List = [
75
74
  'payment/v2/convertFreeCredit',
76
75
  'payment/v2/getBindingBankList',
77
76
  'payment/v2/getBindingPaymentList',
77
+ 'payment/v2/getWithdrawBankList',
78
+ 'payment/v2/getCurrentWithdrawRule',
78
79
  'payment/v2/withdrawCheck',
80
+ 'payment/v2/history',
81
+ 'payment/v2/mergeWallet',
79
82
  'payment/v2/paymentDetail',
80
83
  'payment/v2/category/options',
81
84
  'payment/v2/paymentInfo',
82
85
  'payment/v2/getBindingPaymentInfo',
83
86
  'payment/v2/pendingOrder',
84
87
  'payment/v2/promotions',
88
+ 'payment/v2/spotmarket',
85
89
  'payment/v2/transactionHistory',
86
90
  'payment/v2/updateUtr',
87
91
  'payment/v2/setting',
@@ -91,6 +95,7 @@ const supportVersion2List = [
91
95
  'payment/v2/withdrawRule',
92
96
  'payment/v2/:paymentType/getBankList',
93
97
  'payment/v2/:paymentType/transaction',
98
+ 'payment/v2/:paymentType/checkTransaction',
94
99
  'payment/v2/:paymentType/bonus/preview',
95
100
  'payment/v2/:paymentType/expected/result',
96
101
  'payment/v2/:paymentType/crypto/expected/result',
@@ -105,6 +110,7 @@ const supportVersion2List = [
105
110
  'activities',
106
111
  'activities/types',
107
112
  'activities/promo',
113
+ 'activities/viptable',
108
114
  'activities/level-bonus/info',
109
115
  'activities/numbers',
110
116
  'activities/honorBroadcast',
@@ -126,6 +132,7 @@ const supportVersion2List = [
126
132
  'friends/dashboard',
127
133
  'friends/dashboard/list',
128
134
  'activities/ranking',
135
+ 'activities/activity/ranking',
129
136
  'activities/cashRain',
130
137
  'activities/jackpot/list',
131
138
  // 09/09
@@ -139,6 +146,7 @@ const supportVersion2List = [
139
146
  'account-binding/status',
140
147
  'account-binding/bind',
141
148
  'account-binding/acknowledge',
149
+ 'account-binding/bind-third-party',
142
150
  'account-binding/bind-password',
143
151
  'account-binding/reset-otp',
144
152
  // 11/10
@@ -148,6 +156,13 @@ const supportVersion2List = [
148
156
  // 12/02
149
157
  'user-info/get-profile',
150
158
  ]
159
+ const supportVersion2Matchers = supportVersion2List.map((supportedUrl) => {
160
+ if (supportedUrl.includes(':')) {
161
+ const pattern = supportedUrl.replace(/:[^/]+/g, '[^/]+')
162
+ return new RegExp(`^${pattern}$`)
163
+ }
164
+ return supportedUrl
165
+ })
151
166
 
152
167
  function isValid(value) {
153
168
  return value !== undefined && value !== null
@@ -156,17 +171,13 @@ function isValid(value) {
156
171
  export default class Request {
157
172
  constructor(axios, config) {
158
173
  this.axios = axios
174
+ this.source = axios.CancelToken.source()
159
175
  this.config = config
160
176
  this.sentry = config.sentry
161
177
  this.key = `cuora_${config.clientId}`
162
178
  this.errorHandler = null
163
179
  this.hosts = []
164
180
  this.isBlocked = false
165
- this.activeRequests = new Set() // { source, token }:僅追蹤非 public 且帶 token 的在途請求,供 revokeToken 取消
166
- this.revokedToken = null
167
- this.tokenGate = null
168
- this.clientIp = '' // 由外部 plugin(如 clientIp.client.js)非同步寫入,用於 ERR_998 Sentry 回報
169
- this.hostTester = null // 由外部 plugin(如 host.client.js)寫入,需提供 lastResults 陣列供 ERR_998 Sentry 回報使用
170
181
  this.initialize()
171
182
  }
172
183
 
@@ -198,9 +209,10 @@ export default class Request {
198
209
  this.axios.interceptors.request.use((axiosConfig) => {
199
210
  axiosConfig.headers['X-TH1GAMES-VERSION'] = this.config.version
200
211
  axiosConfig.headers['X-TH1GAMES-PLATFORM'] = this.config.platform
201
- if (this.getToken()) {
212
+ const token = this.getToken()
213
+ if (token) {
202
214
  // 為了支援V2版本的API接口新增Bearer來進行身份驗證
203
- axiosConfig.headers.Authorization = `Bearer ${this.getToken()}`
215
+ axiosConfig.headers.Authorization = `Bearer ${token}`
204
216
  }
205
217
  return axiosConfig
206
218
  })
@@ -214,24 +226,8 @@ export default class Request {
214
226
  },
215
227
  (error) => {
216
228
  if (error.message === 'Network Error' || error.message === 'Request failed with status code 404') {
217
- const endpoint = error.config?.url || ''
218
- // 確實在線才以 warning 等級回報(連線不穩定多為使用者端網路問題,非應用程式錯誤)
219
- const isOnline = typeof navigator !== 'undefined' ? navigator.onLine : true
220
- if (!IS_ERR_998_REPORT_PAUSED && isOnline) {
221
- const errData998 = getErr998SentryExtra(this, error.config)
222
- const sentryError = new Error(`ERR_998:${error.message}`)
223
- sentryError.name = 'ERR_998'
224
- this.sentry?.captureException(sentryError, {
225
- level: 'warning',
226
- tags: errData998,
227
- extra: {
228
- ...errData998,
229
- version: this.config.version,
230
- hostTestResults: this.hostTester?.lastResults || [],
231
- },
232
- })
233
- }
234
- return Promise.reject({ code: 'ERR_998', endpoint })
229
+ this.sentry?.captureException(`ERR_998:${error.message}`)
230
+ return Promise.reject({ code: 'ERR_998' })
235
231
  }
236
232
  return Promise.reject(error.response?.data?.error || error)
237
233
  }
@@ -242,112 +238,45 @@ export default class Request {
242
238
  this.errorHandler = handler
243
239
  }
244
240
 
245
- // 作廢指定 token:取消同 token 的在途請求,並讓之後仍帶此 token 的 send() 直接 reject。
246
- // 只在 token 仍是目前身分時作用,舊身分遲到的錯誤不得影響新身分;重新登入後 token 改變即自然恢復
247
- revokeToken(token) {
248
- if (!token || token !== this.getToken()) return
249
- this.revokedToken = token
250
- this.activeRequests.forEach((item) => {
251
- if (item.token === token) item.source.cancel(CANCELLED_MESSAGE)
252
- })
253
- }
254
-
255
- // 回前景時先確認 token 仍有效:promise 結算(成功或失敗)或逾時即放行,之後的 send() 才會送出
256
- beginTokenGate(promise, timeoutMs = 3000) {
257
- let timer
258
- const timeout = new Promise((resolve) => {
259
- timer = setTimeout(resolve, timeoutMs)
260
- })
261
- const gate = Promise.race([Promise.resolve(promise).catch(() => {}), timeout]).then(() => {
262
- clearTimeout(timer)
263
- if (this.tokenGate === gate) this.tokenGate = null
264
- })
265
- this.tokenGate = gate
266
- return gate
267
- }
268
-
269
- // 帶 ERR_800 讓下游既有的 `if (!error.code)` 判斷(如 Sentry 上報)把取消視為預期錯誤
270
- _cancelledError() {
271
- return Object.assign(new Error(CANCELLED_MESSAGE), { code: 'ERR_800' })
272
- }
273
-
274
- _throwIfRevoked() {
275
- if (this.revokedToken && this.getToken() === this.revokedToken) {
276
- throw this._cancelledError()
277
- }
278
- }
279
-
280
- _isCancelled(error) {
281
- return !!this.axios.isCancel?.(error) || error?.message === CANCELLED_MESSAGE
282
- }
283
-
284
241
  async send(req, customToken) {
285
- let tracked = null
286
- let requestToken = null
287
242
  try {
288
- // 非 public 請求缺 token 直接 reject:reject → onError → leaving → 乾淨登出,且不送網路 → 洪水照止
289
- if (!req.isPublic && !this.getToken()) return Promise.reject({ code: 'ERR_A103' })
290
-
291
- // 公開請求不帶 token,作廢期間 token 仍留在 storage 也不可誤拒(如 autoLogin 前後的 getConfig)
292
- if (!req.isPublic) this._throwIfRevoked()
293
-
294
- // /self 是 gate 自己的探測請求,不可等待 gate,否則死鎖
295
- if (this.tokenGate && !req.isPublic && req.url.split('?')[0] !== 'self') {
296
- await this.tokenGate
297
- this._throwIfRevoked()
298
- if (!this.getToken()) return Promise.reject({ code: 'ERR_A103' })
299
- }
300
-
301
- requestToken = req.isPublic ? null : this.getToken()
302
-
303
- // axios <0.22 對 cancelToken.promise 註冊的取消 handler 永不退訂(xhr.js 無 unsubscribe),
304
- // 預設掛長壽命共用 token 會使 handler 隨請求數線性累積(掛機過夜 OOM,TI-15555)。
305
- // 故不掛共用 token:呼叫端傳入 customToken 時自行管理其生命週期;否則帶 token 的請求用一次性 source,
306
- // 結束即移出 activeRequests 隨請求回收
307
- let cancelToken = customToken
308
- if (!customToken && requestToken && this.axios.CancelToken) {
309
- const source = this.axios.CancelToken.source()
310
- tracked = { source, token: requestToken }
311
- this.activeRequests.add(tracked)
312
- cancelToken = source.token
313
- }
243
+ const cancelToken = customToken || this.source.token
244
+ this._checkToken(req)
314
245
 
315
246
  const requestConfig = this._createConfig(req, cancelToken)
316
247
  const configUrls = ['getConfig', 'get-config']
317
248
  if (this.isBlocked && !configUrls.includes(requestConfig.url)) {
318
- // 狀態是維護中&請求非siteConfig,終止所有的請求,除了維護頁需要的資料(siteConfig)
249
+ // 狀態是維護中且請求非 site config,回傳明確錯誤避免呼叫端拿到 undefined
250
+ throw { code: 'ERR_MAINTENANCE_BLOCKED', url: requestConfig.url }
319
251
  } else {
320
252
  const { data } = await this.axios.request(requestConfig)
321
253
  return data
322
254
  }
323
255
  } catch (error) {
324
- if (this._isCancelled(error)) throw this._cancelledError()
325
- // 不可列舉:避免 Bearer token 隨 JSON.stringify/Sentry 序列化外洩,但 error.requestToken 仍可讀取
326
- if (requestToken && error && typeof error === 'object' && Object.isExtensible(error)) {
327
- Object.defineProperty(error, 'requestToken', { value: requestToken, enumerable: false, configurable: true })
328
- }
329
256
  if (error.code === 'ERR_F108') {
257
+ console.log('%c*維護中', 'color: #00ff33ff; font-weight: bold;')
330
258
  this.isBlocked = true
331
259
  this.errorHandler && this.errorHandler(error)
332
260
  throw error
333
261
  }
334
- // 舊身分遲到的錯誤不進 errorHandler;目前沒 token(TTL 過期或已 CLEAR)時維持原路由,A204 等彈窗才不會被吞
335
- const currentToken = this.getToken()
336
- if (requestToken && currentToken && currentToken !== requestToken) throw error
337
- if (error.code === 'ERR_998') {
338
- throw error
339
- }
340
262
  if (error.code !== 'ERR_800') {
341
- if (error.code && !req.silent) {
263
+ if (error.code) {
342
264
  this.errorHandler && this.errorHandler(error)
343
265
  }
344
266
  throw error
345
267
  }
346
- } finally {
347
- if (tracked) this.activeRequests.delete(tracked)
348
268
  }
349
269
  }
350
270
 
271
+ sourceUpdate() {
272
+ this.source.cancel('Requests Cancelled')
273
+ this.source = this.axios.CancelToken.source()
274
+ }
275
+
276
+ sourceGenerate() {
277
+ return this.axios.CancelToken.source()
278
+ }
279
+
351
280
  _createConfig(req, cancelToken) {
352
281
  const { method, url, params, isPublic, isFormData, headers } = req
353
282
  let fullURL = this.config.fullURL
@@ -355,14 +284,11 @@ export default class Request {
355
284
 
356
285
  // 有些API會將參數(/?)直接帶在URL上,所以要將參數排除
357
286
  const cleanUrl = url.split('?')[0]
358
- const isV2Supported = supportVersion2List.some((supportedUrl) => {
359
- // 如果包含動態參數(:parameter),則使用模式匹配
360
- if (supportedUrl.includes(':')) {
361
- const pattern = supportedUrl.replace(/:[^/]+/g, '[^/]+')
362
- const regex = new RegExp(`^${pattern}$`)
363
- return regex.test(cleanUrl)
287
+ const isV2Supported = supportVersion2Matchers.some((matcher) => {
288
+ if (matcher instanceof RegExp) {
289
+ return matcher.test(cleanUrl)
364
290
  }
365
- return supportedUrl === cleanUrl
291
+ return matcher === cleanUrl
366
292
  })
367
293
  // 符合轉換規則的API進行路徑調整
368
294
  if (isV2Supported) {
@@ -394,7 +320,6 @@ export default class Request {
394
320
 
395
321
  // 調整API路徑與名稱
396
322
  _convertUrlToKebabCase(url) {
397
- const [path, queryString] = url.split('?')
398
323
  const specifyingPath = {
399
324
  'all-activities/list': 'activities/all-activities-list',
400
325
  friends: 'activities/friends',
@@ -406,6 +331,7 @@ export default class Request {
406
331
  'activities/getFreeGameRewardList': 'activities/free-game/get-free-game-reward-list',
407
332
  'activities/lose-rebate/history': 'activities/rebate/lose-rebate/history',
408
333
  'activities/ranking': 'activities/ranking/promotion-ranking',
334
+ 'activities/activity/ranking': 'activities/ranking/basic-ranking',
409
335
  'activities/cashRain': 'activities/cash-rain/exchange',
410
336
  'tournament/detail': 'activities/tournament/detail',
411
337
  'ranking/detail': 'activities/tournament/ranking/detail',
@@ -415,9 +341,19 @@ export default class Request {
415
341
  'activities/exchange/diamond/max-amount': 'activities/diamond/exchange/max-amount',
416
342
  'activities/exchange/diamond/settle': 'activities/diamond/exchange/settle',
417
343
  }
418
- // 和原有路徑不同有另外改路徑
419
- const convertedPath = specifyingPath[path] ? specifyingPath[path] : path.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()
420
- return queryString ? `${convertedPath}?${queryString}` : convertedPath
344
+ if (specifyingPath[url]) {
345
+ // 和原有路徑不同有另外改路徑
346
+ return specifyingPath[url]
347
+ } else {
348
+ // 將API_URL的命名規則由駝峰調整為短橫線(-)
349
+ return url.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()
350
+ }
351
+ }
352
+
353
+ _checkToken(req) {
354
+ if (!req.isPublic && !this.getToken()) {
355
+ throw { code: 'ERR_A103', url: req.url }
356
+ }
421
357
  }
422
358
 
423
359
  getToken() {
@@ -1,3 +1,4 @@
1
+ export const MY_FAVORITE = 'MyFavorite'
1
2
  export const GAME_SEARCH = 'GameSearch'
2
3
  export const GAME_TYPE_LIST = [
3
4
  { typeId: 'SLOT', name: 'Slots', gameTypeMappingId: 1 },
@@ -11,14 +12,9 @@ export const GAME_TYPE_LIST = [
11
12
  { typeId: 'SCRATCHCARDS', name: 'Scratch Cards', gameTypeMappingId: 9 },
12
13
  { typeId: 'EGAME', name: 'E-Game', gameTypeMappingId: 10 },
13
14
  { typeId: 'BONUS', name: 'Bonus', gameTypeMappingId: 11 },
14
- // { typeId: 'BALL', name: 'Ball', gameTypeMappingId: 12 }, 已經沒有此類別,由 Prediction 取代。但暫不移除
15
+ { typeId: 'BALL', name: 'Ball', gameTypeMappingId: 12 },
15
16
  { typeId: 'PACHINKO', name: 'Pachinko', gameTypeMappingId: 13 },
16
17
  { typeId: 'GRAPH', name: 'Graph', gameTypeMappingId: 14 },
17
18
  { typeId: 'TURBO', name: 'Turbo', gameTypeMappingId: 15 },
18
19
  { typeId: 'SPORT', name: 'Sports', gameTypeMappingId: 16 },
19
- { typeId: 'PREDICTION', name: 'Prediction', gameTypeMappingId: 12 },
20
20
  ]
21
-
22
- // OTP 自動驗證:主動打的 /self 未通過後,最多再等幾次 auth 例行輪詢的 /self、等待上限多久
23
- export const AUTO_VERIFY_MAX_USER_INFO_UPDATES = 2
24
- export const AUTO_VERIFY_WAIT_MS = 5000
@@ -0,0 +1,60 @@
1
+ import uniqBy from 'lodash/uniqBy.js'
2
+ import { load, defaultEndpoint } from '../lib/fingerprint_v3_11_12.js'
3
+
4
+ const reg = /fnapi\d*/
5
+
6
+ const getDeviceToken = async ({ fpToken, sentry, hosts, enable = true, loader = load }) => {
7
+ if (!enable) {
8
+ return
9
+ }
10
+
11
+ let dt, endpoints
12
+ try {
13
+ const hostList = Array.isArray(hosts) ? hosts : []
14
+ endpoints = uniqBy(
15
+ hostList.map((host) => host.replace(reg, 'fp')),
16
+ (url) => url
17
+ )
18
+
19
+ const fp = await loader({ endpoint: [...endpoints, defaultEndpoint] })
20
+ const result = await fp.get({ timeout: 30000 })
21
+ dt = result.visitorId
22
+
23
+ if (!dt) {
24
+ throw new Error('[Device Token] No token from FingerprintJS.')
25
+ }
26
+
27
+ sentry?.setTag('dt', dt)
28
+ } catch (error) {
29
+ console.error('[Device Token]', `${dt} from ${endpoints}`, error)
30
+ sentry?.captureException(error)
31
+ } finally {
32
+ return dt
33
+ }
34
+ }
35
+
36
+ // 重試機制,最多嘗試 maxRetries 次,每次間隔 intervalMs 毫秒
37
+ const getDeviceTokenWithRetry = async ({ fpToken, sentry, hosts, enable = true, maxRetries = 3, intervalMs = 1000, loader = load }) => {
38
+ if (!enable) {
39
+ return
40
+ }
41
+ // 設置幾秒後重試
42
+ const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
43
+ // 設定重試次數
44
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
45
+ try {
46
+ const deviceToken = await getDeviceToken({ fpToken, sentry, hosts, enable, loader })
47
+ if (deviceToken) return deviceToken
48
+ throw new Error('No device token received')
49
+ } catch (error) {
50
+ // 若失敗則等待intervalMs後重試,最多重試maxRetries次
51
+ if (attempt < maxRetries) {
52
+ await delay(intervalMs)
53
+ } else {
54
+ throw error
55
+ }
56
+ }
57
+ }
58
+ }
59
+
60
+ export { getDeviceToken, getDeviceTokenWithRetry }
package/src/util/index.js CHANGED
@@ -1,5 +1,7 @@
1
+ import { getDeviceToken, getDeviceTokenWithRetry } from './deviceToken.js'
1
2
  import storage from './storage.js'
2
- import paramStore from './paramStore.js'
3
3
  import * as constant from './constant.js'
4
+ import { max } from './math.js'
4
5
 
5
- export { constant, storage, paramStore }
6
+ export default { getDeviceToken, getDeviceTokenWithRetry }
7
+ export { constant, storage, max }
@@ -0,0 +1,4 @@
1
+ export function max(...args) {
2
+ const casted = args.map((arg) => arg || 0)
3
+ return Math.max(...casted)
4
+ }
@@ -13,7 +13,7 @@ export default {
13
13
  }
14
14
 
15
15
  const item = JSON.parse(itemStr)
16
- if (item.expiry && new Date().getTime() > item.expiry) {
16
+ if (Object.prototype.hasOwnProperty.call(item, 'expiry') && Date.now() >= item.expiry) {
17
17
  localStorage.removeItem(name)
18
18
  return null
19
19
  }
@@ -23,8 +23,9 @@ export default {
23
23
  set(name, value, options) {
24
24
  const item = { value }
25
25
 
26
- if (options?.maxAge) {
27
- item.expiry = new Date().getTime() + options.maxAge * 1000
26
+ const maxAge = Number(options?.maxAge)
27
+ if (Number.isFinite(maxAge)) {
28
+ item.expiry = Date.now() + maxAge * 1000
28
29
  }
29
30
  try {
30
31
  localStorage.setItem(name, JSON.stringify(item))