@jetthai/cuora 1.1.488 → 1.2.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 (128) hide show
  1. package/.husky/pre-commit +3 -1
  2. package/CHANGELOG.md +0 -349
  3. package/README.md +15 -299
  4. package/package.json +3 -6
  5. package/resetGitBranch.sh +101 -0
  6. package/src/api/activity.js +39 -24
  7. package/src/api/auth.js +35 -4
  8. package/src/api/common.js +1 -8
  9. package/src/api/game.js +10 -0
  10. package/src/api/index.js +1 -3
  11. package/src/api/payment.js +55 -17
  12. package/src/api/user.js +16 -11
  13. package/src/index.js +2 -2
  14. package/src/lib/fingerprint_v3_11_12.js +11433 -0
  15. package/src/machine/activity/activity.js +209 -0
  16. package/src/machine/activity/activity_cash.js +18 -71
  17. package/src/machine/activity/diamond_shop_activity_cash.js +1 -0
  18. package/src/machine/activity/diamond_shop_activity_fc.js +196 -0
  19. package/src/machine/activity/diamond_shop_activity_vn.js +178 -0
  20. package/src/machine/activity/fafafa_activity.js +10 -0
  21. package/src/machine/activity/index.js +12 -0
  22. package/src/machine/activity/invite_friends_activity.js +114 -0
  23. package/src/machine/activity/mini_game_activity.js +68 -0
  24. package/src/machine/activity/return_bonus_activity.js +153 -0
  25. package/src/machine/activity/roulette_activity_v2.js +0 -5
  26. package/src/machine/auth.js +109 -158
  27. package/src/machine/auth_otp_v2.js +177 -0
  28. package/src/machine/auth_otp_v3.js +32 -111
  29. package/src/machine/bank_binding.js +2 -2
  30. package/src/machine/bank_binding_amb.js +145 -0
  31. package/src/machine/bonus.js +75 -0
  32. package/src/machine/common.js +91 -27
  33. package/src/machine/deposit/amb.js +92 -0
  34. package/src/machine/deposit/crypto_bank.js +325 -0
  35. package/src/machine/deposit/crypto_bank_cash.js +8 -19
  36. package/src/machine/deposit/crypto_qrcode.js +148 -0
  37. package/src/machine/deposit/crypto_qrcode_cash.js +41 -26
  38. package/src/machine/deposit/crypto_way.js +247 -0
  39. package/src/machine/deposit/crypto_way_cash.js +32 -52
  40. package/src/machine/deposit/deposit_fc.js +271 -0
  41. package/src/machine/deposit/direct.js +310 -0
  42. package/src/machine/deposit/direct_cash.js +9 -8
  43. package/src/machine/deposit/float.js +374 -0
  44. package/src/machine/deposit/index.js +28 -0
  45. package/src/machine/deposit/krway.js +151 -0
  46. package/src/machine/deposit/loadcard_cash.js +31 -14
  47. package/src/machine/deposit/loadcard_vn.js +351 -0
  48. package/src/machine/deposit/manual_cash.js +10 -8
  49. package/src/machine/deposit/manual_vn.js +458 -0
  50. package/src/machine/deposit/qrcode_cash.js +30 -14
  51. package/src/machine/deposit/qrcode_v2.js +338 -0
  52. package/src/machine/deposit/usdt.js +144 -0
  53. package/src/machine/deposit/virtual_bank_cash.js +2 -5
  54. package/src/machine/deposit/virtual_bank_vn.js +269 -0
  55. package/src/machine/deposit/vpay.js +367 -0
  56. package/src/machine/error.js +0 -7
  57. package/src/machine/game_hot_new.js +79 -0
  58. package/src/machine/game_info.js +12 -5
  59. package/src/machine/game_replay.js +46 -0
  60. package/src/machine/game_search_v2.js +401 -0
  61. package/src/machine/game_v2_1.js +88 -43
  62. package/src/machine/honor_board.js +132 -0
  63. package/src/machine/honor_board_cash.js +18 -15
  64. package/src/machine/inbox.js +12 -0
  65. package/src/machine/index.js +32 -0
  66. package/src/machine/leaderboard.js +11 -8
  67. package/src/machine/merge.js +57 -0
  68. package/src/machine/payment_data.js +86 -0
  69. package/src/machine/promotions.js +170 -0
  70. package/src/machine/ranking.js +25 -43
  71. package/src/machine/reward.js +255 -0
  72. package/src/machine/reward_cash.js +41 -2
  73. package/src/machine/reward_fc.js +98 -0
  74. package/src/machine/roulette_v2.js +25 -20
  75. package/src/machine/side.js +154 -0
  76. package/src/machine/side_cash.js +2 -3
  77. package/src/machine/side_v2.js +209 -0
  78. package/src/machine/user_reset_password.js +15 -4
  79. package/src/machine/user_sign_up.js +60 -46
  80. package/src/machine/vip_table.js +57 -0
  81. package/src/machine/websocket.js +325 -378
  82. package/src/machine/welcome.js +110 -0
  83. package/src/machine/withdraw/index.js +6 -0
  84. package/src/machine/withdraw/withdraw_crypto_cash.js +327 -0
  85. package/src/machine/withdraw/withdraw_krway.js +222 -0
  86. package/src/machine/withdraw/withdraw_manual.js +533 -0
  87. package/src/machine/withdraw/withdraw_manual_cash.js +38 -59
  88. package/src/request/config.js +0 -2
  89. package/src/request/request.js +62 -130
  90. package/src/util/constant.js +2 -6
  91. package/src/util/deviceToken.js +59 -0
  92. package/src/util/index.js +4 -2
  93. package/src/util/math.js +4 -0
  94. package/.claude/commands/sync-ai-prompts.md +0 -93
  95. package/.claude/settings.local.json +0 -23
  96. package/.github/copilot-instructions.md +0 -448
  97. package/.husky/post-checkout +0 -32
  98. package/.husky/pre-push +0 -36
  99. package/AGENTS.md +0 -448
  100. package/AI_PROMPT_SOURCE.md +0 -446
  101. package/CLAUDE.md +0 -448
  102. package/GEMINI.md +0 -448
  103. package/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +0 -1003
  104. package/docs/kibana/play-providerId-error.md +0 -202
  105. package/docs/kibana/play-selectedWalletType.md +0 -1
  106. package/docs/kibana/play-selectedWalletType_2.md +0 -1
  107. package/docs/kibana/play-selectedWalletType_analysis.md +0 -565
  108. package/docs/my-claude/feat-sharon-JT-1790247240-socket/branch-transfer.md +0 -14
  109. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-preparation.json +0 -40
  110. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-verification.md +0 -41
  111. package/docs/my-claude/feat-sharon-JT-1790247240-socket/implementation-ledger.md +0 -87
  112. package/docs/my-claude/feat-sharon-JT-1790247240-socket/module-report.md +0 -73
  113. package/docs/my-claude/feat-sharon-JT-1790247240-socket/plan.md +0 -309
  114. package/docs/my-claude/feat-sharon-JT-1790247240-socket/test-cases.md +0 -245
  115. package/docs/my-claude/feat-sharon-JT-1791180540-onesignal/transfer.md +0 -9
  116. package/scripts/auto-version.js +0 -68
  117. package/scripts/auto-version.sh +0 -33
  118. package/scripts/branch-auto-npm-publish.js +0 -29
  119. package/scripts/check-version.sh +0 -36
  120. package/scripts/clean-tags.sh +0 -84
  121. package/src/api/account.js +0 -7
  122. package/src/api/otp.js +0 -5
  123. package/src/util/amount.js +0 -8
  124. package/src/util/err998SentryExtra.js +0 -26
  125. package/src/util/paramStore.js +0 -139
  126. package/src/util/socketPolicy.js +0 -57
  127. package/test/auth_otp_v3.test.js +0 -323
  128. package/tests/websocket.test.mjs +0 -779
@@ -3,14 +3,13 @@ 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
10
  initial: 'loading',
11
11
  context: {
12
12
  paymentDetail,
13
- doubleWalletWithdrawLimitCheck,
14
13
  currentPayment: null,
15
14
  banks: [],
16
15
  paymentInfo: null,
@@ -24,8 +23,6 @@ export default function (request, context) {
24
23
  requestId: null,
25
24
  status: null,
26
25
  target: null,
27
- email: null,
28
- number: null,
29
26
  ttl: null,
30
27
  },
31
28
  states: {
@@ -120,20 +117,31 @@ export default function (request, context) {
120
117
  RESET_OTP: {
121
118
  target: 'reset',
122
119
  },
123
- BACK: {
124
- target: '#withdraw_manual_cash.calculated',
125
- },
120
+ BACK: [
121
+ // {
122
+ // target: '#withdraw_vn2.activity.convertible',
123
+ // cond: 'isActivity',
124
+ // },
125
+ // {
126
+ // target: '#withdraw_vn2.cash.withdrawable',
127
+ // },
128
+ ],
126
129
  },
127
130
  },
128
131
  acknowledging: {
129
132
  invoke: {
130
133
  src: 'acknowledge',
131
- onDone: {
132
- target: '#withdraw_manual_cash.submitted',
133
- actions: 'setProcessing',
134
- },
134
+ onDone: [
135
+ // {
136
+ // target: '#withdraw_vn2.activity.converted',
137
+ // cond: 'isActivity',
138
+ // },
139
+ // {
140
+ // target: '#withdraw_vn2.cash.submitted',
141
+ // },
142
+ ],
135
143
  onError: {
136
- target: '#withdraw_manual_cash.calculated',
144
+ target: 'idle',
137
145
  },
138
146
  },
139
147
  },
@@ -168,7 +176,7 @@ export default function (request, context) {
168
176
  actions: {
169
177
  setInitData: assign((context, event) => {
170
178
  const { currentPayment, paymentInfo, withdrawRule, processing } = event.data
171
- const userBanks = [...paymentInfo.bankList, ...paymentInfo.ewalletList, ...paymentInfo.cryptoList]
179
+ const userBanks = [...paymentInfo.bankList, ...paymentInfo.cryptoList, ...paymentInfo.ewalletList]
172
180
 
173
181
  return {
174
182
  currentPayment,
@@ -195,27 +203,26 @@ export default function (request, context) {
195
203
  }
196
204
  }),
197
205
  setOtp: assign((context, event) => {
198
- const { request_id, email, number, ttl } = event.data
206
+ const { requestId, status, target, ttl } = event.data
199
207
  return {
200
- requestId: request_id,
201
- email,
202
- number,
208
+ requestId,
209
+ status,
210
+ target,
203
211
  ttl,
204
212
  }
205
213
  }),
206
214
  decreaseTtl: assign((context, evnet) => {
207
215
  const second = context.ttl
208
216
  return {
209
- ttl: Math.max(second - 1000, 0),
217
+ ttl: Math.max(second - 1, 0),
210
218
  }
211
219
  }),
212
220
  setVerificationData: assign((context, event) => {
213
- const { request_id, ttl, number, email } = event.data
221
+ const { requestId, ttl, target } = event.data
214
222
  return {
215
- requestId: request_id,
223
+ requestId,
216
224
  ttl,
217
- number,
218
- email,
225
+ target,
219
226
  }
220
227
  }),
221
228
  },
@@ -231,43 +238,15 @@ export default function (request, context) {
231
238
  return selectedUserBank && selectedAmount > 0 && currentPayment.minimum <= selectedAmount && selectedAmount <= currentPayment.maximum
232
239
  },
233
240
  isOtpRequired: (context, event) => {
234
- return event.data?.request_id !== undefined
241
+ return event.data?.status === 'otp-verifying'
235
242
  },
236
243
  },
237
244
  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
245
  fetchInitData: async (context, event) => {
244
- const { paymentDetail = [], doubleWalletWithdrawLimitCheck = '0' } = context
246
+ const { paymentDetail = [] } = context
245
247
  const currentPayment = paymentDetail.find((element) => element.category === 'manual' && element.transferType === 'withdraw')
246
248
 
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([
249
+ const [paymentInfo, withdrawRule, orders] = await Promise.all([
271
250
  request.send(payment.getBindingPaymentInfo()),
272
251
  request.send(payment.getDoubleWalletWithdrawRule({ walletType: 'CASH' })),
273
252
  request.send(payment.getPendingOrder({ transferType: 'WITHDRAW' })),
@@ -276,7 +255,7 @@ export default function (request, context) {
276
255
  return {
277
256
  currentPayment,
278
257
  paymentInfo,
279
- withdrawRule: cashRule,
258
+ withdrawRule,
280
259
  processing: orders[0],
281
260
  }
282
261
  },
@@ -303,20 +282,20 @@ export default function (request, context) {
303
282
  method: currentPayment.method,
304
283
  amount: selectedAmount,
305
284
  cryptoCurrency: selectedUserBank.cryptoCurrency,
306
- cryptoNetwork: selectedUserBank.networkCode,
285
+ cryptoNetwork: selectedUserBank.cryptoNetwork,
307
286
  targetAddress: selectedUserBank.cryptoAddress,
308
287
  applyerHolderName: selectedUserBank.holderName,
309
288
  })
310
289
  )
311
290
  },
312
291
  resetOtp: async (context, event) => {
313
- const { currentPayment, requestId } = context
314
- return await request.send(payment.otpReset({ method: currentPayment.method, requestId }))
292
+ const { requestId, target } = context
293
+ return await request.send(user.otpReset({ requestId, target }))
315
294
  },
316
295
  acknowledge: async (context, event) => {
317
- const { currentPayment, requestId } = context
296
+ const { requestId, target } = context
318
297
  const code = event.data
319
- return await request.send(payment.otpAcknowledge({ method: currentPayment.method, requestId, code }))
298
+ return await request.send(user.otpAcknowledge({ requestId, target, code }))
320
299
  },
321
300
  },
322
301
  }
@@ -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
@@ -133,20 +140,6 @@ const supportVersion2List = [
133
140
  'game/list/v3/gameInfo',
134
141
  'payment/v2/uploadCommonSlip',
135
142
  'game/history/options',
136
- // 09/30
137
- 'pixel',
138
- // 10/09
139
- 'account-binding/status',
140
- 'account-binding/bind',
141
- 'account-binding/acknowledge',
142
- 'account-binding/bind-password',
143
- 'account-binding/reset-otp',
144
- // 11/10
145
- 'otp-verification-point/verify',
146
- 'otp-verification-point/acknowledge',
147
- 'otp-verification-point/reset-otp',
148
- // 12/02
149
- 'user-info/get-profile',
150
143
  ]
151
144
 
152
145
  function isValid(value) {
@@ -156,17 +149,13 @@ function isValid(value) {
156
149
  export default class Request {
157
150
  constructor(axios, config) {
158
151
  this.axios = axios
152
+ this.source = axios.CancelToken.source()
159
153
  this.config = config
160
154
  this.sentry = config.sentry
161
155
  this.key = `cuora_${config.clientId}`
162
156
  this.errorHandler = null
163
157
  this.hosts = []
164
158
  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
159
  this.initialize()
171
160
  }
172
161
 
@@ -214,24 +203,15 @@ export default class Request {
214
203
  },
215
204
  (error) => {
216
205
  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
- })
206
+ const errData = (error || {}).response || {}
207
+ const errorDetails = {
208
+ data: errData.config?.data,
209
+ params: errData.config?.params,
210
+ url: errData.config?.url,
211
+ status: errData.status,
233
212
  }
234
- return Promise.reject({ code: 'ERR_998', endpoint })
213
+ this.sentry?.captureException(`ERR_998:${error.message}`)
214
+ return Promise.reject({ code: 'ERR_998' })
235
215
  }
236
216
  return Promise.reject(error.response?.data?.error || error)
237
217
  }
@@ -242,119 +222,54 @@ export default class Request {
242
222
  this.errorHandler = handler
243
223
  }
244
224
 
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
225
  async send(req, customToken) {
285
- let tracked = null
286
- let requestToken = null
287
226
  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
- }
227
+ const cancelToken = customToken || this.source.token
228
+ this._checkToken(req)
314
229
 
315
230
  const requestConfig = this._createConfig(req, cancelToken)
231
+ // console.log('*請求資料Check', requestConfig)
316
232
  const configUrls = ['getConfig', 'get-config']
317
233
  if (this.isBlocked && !configUrls.includes(requestConfig.url)) {
318
234
  // 狀態是維護中&請求非siteConfig,終止所有的請求,除了維護頁需要的資料(siteConfig)
235
+ // console.log('%c*禁止的請求目標', requestConfig)
319
236
  } else {
237
+ // console.log('%c*允許的請求目標', requestConfig)
320
238
  const { data } = await this.axios.request(requestConfig)
321
239
  return data
322
240
  }
323
241
  } 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
242
  if (error.code === 'ERR_F108') {
243
+ console.log('%c*維護中', 'color: #00ff33ff; font-weight: bold;')
330
244
  this.isBlocked = true
331
245
  this.errorHandler && this.errorHandler(error)
332
246
  throw error
333
247
  }
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
248
  if (error.code !== 'ERR_800') {
341
- if (error.code && !req.silent) {
249
+ if (error.code) {
342
250
  this.errorHandler && this.errorHandler(error)
343
251
  }
344
252
  throw error
345
253
  }
346
- } finally {
347
- if (tracked) this.activeRequests.delete(tracked)
348
254
  }
349
255
  }
350
256
 
257
+ sourceUpdate() {
258
+ this.source.cancel('Requests Cancelled')
259
+ this.source = this.axios.CancelToken.source()
260
+ }
261
+
262
+ sourceGenerate() {
263
+ return this.axios.CancelToken.source()
264
+ }
265
+
351
266
  _createConfig(req, cancelToken) {
352
267
  const { method, url, params, isPublic, isFormData, headers } = req
353
268
  let fullURL = this.config.fullURL
354
269
  let urlName = url
355
-
356
270
  // 有些API會將參數(/?)直接帶在URL上,所以要將參數排除
357
271
  const cleanUrl = url.split('?')[0]
272
+
358
273
  const isV2Supported = supportVersion2List.some((supportedUrl) => {
359
274
  // 如果包含動態參數(:parameter),則使用模式匹配
360
275
  if (supportedUrl.includes(':')) {
@@ -364,9 +279,16 @@ export default class Request {
364
279
  }
365
280
  return supportedUrl === cleanUrl
366
281
  })
367
- // 符合轉換規則的API進行路徑調整
368
- if (isV2Supported) {
282
+
283
+ // 目前全站都支援V2,若有需要限制為V1的站點可以填入,此段等轉換全部完成之後就可以移除了
284
+ const supportV2Toggle = [''].includes(this.config?.clientId)
285
+
286
+ if (isV2Supported && !supportV2Toggle) {
287
+ fullURL = fullURL.replace('/v1/', '/v2/')
369
288
  urlName = this._convertUrlToKebabCase(url)
289
+ // console.log(`*[DEV_ONLY]V2`, 'url:', urlName)
290
+ } else {
291
+ // console.log(`*[DEV_ONLY]V2-不支援:`, 'url:', urlName)
370
292
  }
371
293
 
372
294
  if (isFormData) {
@@ -394,7 +316,6 @@ export default class Request {
394
316
 
395
317
  // 調整API路徑與名稱
396
318
  _convertUrlToKebabCase(url) {
397
- const [path, queryString] = url.split('?')
398
319
  const specifyingPath = {
399
320
  'all-activities/list': 'activities/all-activities-list',
400
321
  friends: 'activities/friends',
@@ -406,6 +327,7 @@ export default class Request {
406
327
  'activities/getFreeGameRewardList': 'activities/free-game/get-free-game-reward-list',
407
328
  'activities/lose-rebate/history': 'activities/rebate/lose-rebate/history',
408
329
  'activities/ranking': 'activities/ranking/promotion-ranking',
330
+ 'activities/activity/ranking': 'activities/ranking/basic-ranking',
409
331
  'activities/cashRain': 'activities/cash-rain/exchange',
410
332
  'tournament/detail': 'activities/tournament/detail',
411
333
  'ranking/detail': 'activities/tournament/ranking/detail',
@@ -415,9 +337,19 @@ export default class Request {
415
337
  'activities/exchange/diamond/max-amount': 'activities/diamond/exchange/max-amount',
416
338
  'activities/exchange/diamond/settle': 'activities/diamond/exchange/settle',
417
339
  }
418
- // 和原有路徑不同有另外改路徑
419
- const convertedPath = specifyingPath[path] ? specifyingPath[path] : path.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()
420
- return queryString ? `${convertedPath}?${queryString}` : convertedPath
340
+ if (specifyingPath[url]) {
341
+ // 和原有路徑不同有另外改路徑
342
+ return specifyingPath[url]
343
+ } else {
344
+ // 將API_URL的命名規則由駝峰調整為短橫線(-)
345
+ return url.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()
346
+ }
347
+ }
348
+
349
+ _checkToken(req) {
350
+ if (!req.isPublic && !this.getToken()) {
351
+ throw { code: 'ERR_A103', url: req.url }
352
+ }
421
353
  }
422
354
 
423
355
  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,59 @@
1
+ import uniqBy from 'lodash/uniqBy'
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 }) => {
7
+ if (!enable) {
8
+ return
9
+ }
10
+
11
+ let dt, endpoints
12
+ try {
13
+ endpoints = uniqBy(
14
+ hosts.map((host) => host.replace(reg, 'fp')),
15
+ (url) => url
16
+ )
17
+
18
+ const fp = await load({ endpoint: [...endpoints, defaultEndpoint] })
19
+ const result = await fp.get({ timeout: 30000 })
20
+ dt = result.visitorId
21
+
22
+ if (!dt) {
23
+ throw new Error('[Device Token] No token from FingerprintJS.')
24
+ }
25
+
26
+ sentry?.setTag('dt', dt)
27
+ } catch (error) {
28
+ console.error('[Device Token]', `${dt} from ${endpoints}`, error)
29
+ sentry?.captureException(error)
30
+ } finally {
31
+ return dt
32
+ }
33
+ }
34
+
35
+ // 重試機制,最多嘗試 maxRetries 次,每次間隔 intervalMs 毫秒
36
+ const getDeviceTokenWithRetry = async ({ fpToken, sentry, hosts, enable = true, maxRetries = 3, intervalMs = 1000 }) => {
37
+ if (!enable) {
38
+ return
39
+ }
40
+ // 設置幾秒後重試
41
+ const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
42
+ // 設定重試次數
43
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
44
+ try {
45
+ const deviceToken = await getDeviceToken({ fpToken, sentry, hosts, enable })
46
+ if (deviceToken) return deviceToken
47
+ throw new Error('No device token received')
48
+ } catch (error) {
49
+ // 若失敗則等待intervalMs後重試,最多重試maxRetries次
50
+ if (attempt < maxRetries) {
51
+ await delay(intervalMs)
52
+ } else {
53
+ throw error
54
+ }
55
+ }
56
+ }
57
+ }
58
+
59
+ 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
+ }