@jetthai/cuora 1.1.488-dev.1 → 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 (221) hide show
  1. package/.husky/pre-commit +3 -1
  2. package/.prettierignore +1 -2
  3. package/CHANGELOG.md +0 -746
  4. package/README.md +15 -299
  5. package/package.json +3 -6
  6. package/resetGitBranch.sh +101 -0
  7. package/src/api/activity.js +39 -24
  8. package/src/api/auth.js +35 -4
  9. package/src/api/common.js +1 -8
  10. package/src/api/game.js +10 -0
  11. package/src/api/index.js +1 -3
  12. package/src/api/payment.js +55 -18
  13. package/src/api/user.js +16 -11
  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 +209 -0
  17. package/src/machine/activity/activity_cash.js +18 -71
  18. package/src/machine/activity/diamond_shop_activity_cash.js +1 -0
  19. package/src/machine/activity/diamond_shop_activity_fc.js +196 -0
  20. package/src/machine/activity/diamond_shop_activity_vn.js +178 -0
  21. package/src/machine/activity/fafafa_activity.js +10 -0
  22. package/src/machine/activity/index.js +12 -0
  23. package/src/machine/activity/invite_friends_activity.js +114 -0
  24. package/src/machine/activity/mini_game_activity.js +68 -0
  25. package/src/machine/activity/return_bonus_activity.js +153 -0
  26. package/src/machine/activity/roulette_activity_v2.js +0 -5
  27. package/src/machine/auth.js +140 -192
  28. package/src/machine/auth_otp_v2.js +177 -0
  29. package/src/machine/auth_otp_v3.js +32 -111
  30. package/src/machine/bank_binding.js +2 -2
  31. package/src/machine/bank_binding_amb.js +145 -0
  32. package/src/machine/bonus.js +75 -0
  33. package/src/machine/common.js +91 -27
  34. package/src/machine/deposit/amb.js +92 -0
  35. package/src/machine/deposit/crypto_bank.js +325 -0
  36. package/src/machine/deposit/crypto_bank_cash.js +8 -19
  37. package/src/machine/deposit/crypto_qrcode.js +148 -0
  38. package/src/machine/deposit/crypto_qrcode_cash.js +41 -26
  39. package/src/machine/deposit/crypto_way.js +247 -0
  40. package/src/machine/deposit/crypto_way_cash.js +32 -52
  41. package/src/machine/deposit/deposit_fc.js +271 -0
  42. package/src/machine/deposit/direct.js +310 -0
  43. package/src/machine/deposit/direct_cash.js +9 -8
  44. package/src/machine/deposit/float.js +374 -0
  45. package/src/machine/deposit/index.js +28 -0
  46. package/src/machine/deposit/krway.js +151 -0
  47. package/src/machine/deposit/loadcard_cash.js +31 -14
  48. package/src/machine/deposit/loadcard_vn.js +351 -0
  49. package/src/machine/deposit/manual_cash.js +10 -8
  50. package/src/machine/deposit/manual_vn.js +458 -0
  51. package/src/machine/deposit/qrcode_cash.js +30 -14
  52. package/src/machine/deposit/qrcode_v2.js +338 -0
  53. package/src/machine/deposit/usdt.js +144 -0
  54. package/src/machine/deposit/virtual_bank_cash.js +2 -5
  55. package/src/machine/deposit/virtual_bank_vn.js +269 -0
  56. package/src/machine/deposit/vpay.js +367 -0
  57. package/src/machine/error.js +0 -7
  58. package/src/machine/game_hot_new.js +79 -0
  59. package/src/machine/game_info.js +12 -5
  60. package/src/machine/game_replay.js +46 -0
  61. package/src/machine/game_search_v2.js +401 -0
  62. package/src/machine/game_v2_1.js +88 -58
  63. package/src/machine/honor_board.js +132 -0
  64. package/src/machine/honor_board_cash.js +18 -15
  65. package/src/machine/inbox.js +12 -0
  66. package/src/machine/index.js +32 -0
  67. package/src/machine/leaderboard.js +11 -8
  68. package/src/machine/merge.js +57 -0
  69. package/src/machine/payment_data.js +86 -0
  70. package/src/machine/promotions.js +170 -0
  71. package/src/machine/ranking.js +25 -43
  72. package/src/machine/reward.js +255 -0
  73. package/src/machine/reward_cash.js +41 -2
  74. package/src/machine/reward_fc.js +98 -0
  75. package/src/machine/roulette_v2.js +25 -20
  76. package/src/machine/side.js +154 -0
  77. package/src/machine/side_cash.js +2 -3
  78. package/src/machine/side_v2.js +209 -0
  79. package/src/machine/user_reset_password.js +15 -4
  80. package/src/machine/user_sign_up.js +60 -49
  81. package/src/machine/vip_table.js +57 -0
  82. package/src/machine/websocket.js +325 -378
  83. package/src/machine/welcome.js +110 -0
  84. package/src/machine/withdraw/index.js +6 -0
  85. package/src/machine/withdraw/withdraw_crypto_cash.js +327 -0
  86. package/src/machine/withdraw/withdraw_krway.js +222 -0
  87. package/src/machine/withdraw/withdraw_manual.js +533 -0
  88. package/src/machine/withdraw/withdraw_manual_cash.js +43 -74
  89. package/src/request/config.js +0 -2
  90. package/src/request/request.js +64 -231
  91. package/src/util/constant.js +2 -12
  92. package/src/util/deviceToken.js +59 -0
  93. package/src/util/index.js +4 -2
  94. package/src/util/math.js +4 -0
  95. package/.claude/commands/sync-ai-prompts.md +0 -180
  96. package/.claude/settings.local.json +0 -25
  97. package/.github/copilot-instructions.md +0 -459
  98. package/.husky/post-checkout +0 -32
  99. package/.husky/pre-push +0 -36
  100. package/AGENTS.md +0 -459
  101. package/AI_PROMPT_SOURCE.md +0 -457
  102. package/CLAUDE.md +0 -459
  103. package/GEMINI.md +0 -459
  104. package/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +0 -1003
  105. package/docs/kibana/play-providerId-error.md +0 -202
  106. package/docs/kibana/play-selectedWalletType.md +0 -1
  107. package/docs/kibana/play-selectedWalletType_2.md +0 -1
  108. package/docs/kibana/play-selectedWalletType_analysis.md +0 -565
  109. package/docs/my-claude/feat-sharon-JT-1790247240-socket/branch-transfer.md +0 -14
  110. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-preparation.json +0 -40
  111. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-verification.md +0 -41
  112. package/docs/my-claude/feat-sharon-JT-1790247240-socket/implementation-ledger.md +0 -87
  113. package/docs/my-claude/feat-sharon-JT-1790247240-socket/module-report.md +0 -73
  114. package/docs/my-claude/feat-sharon-JT-1790247240-socket/plan.md +0 -309
  115. package/docs/my-claude/feat-sharon-JT-1790247240-socket/test-cases.md +0 -245
  116. package/docs/my-claude/feat-sharon-JT-1791180540-onesignal/transfer.md +0 -9
  117. package/e2e/feature-map.md +0 -19
  118. package/prepare-for-pr/JT-1776243420.md +0 -85
  119. package/prepare-for-pr/TI-16026/STATE.md +0 -18
  120. package/prepare-for-pr/TI-16026/after-prepare-authorization.md +0 -3
  121. package/prepare-for-pr/TI-16026/analysis.md +0 -38
  122. package/prepare-for-pr/TI-16026/answer-analyze-01.md +0 -1
  123. package/prepare-for-pr/TI-16026/answer-commit-01.md +0 -2
  124. package/prepare-for-pr/TI-16026/answer-commit-02.md +0 -1
  125. package/prepare-for-pr/TI-16026/bundle.json +0 -18
  126. package/prepare-for-pr/TI-16026/checklist.md +0 -196
  127. package/prepare-for-pr/TI-16026/checklist.unit-test-original.md +0 -39
  128. package/prepare-for-pr/TI-16026/claude-after-model +0 -1
  129. package/prepare-for-pr/TI-16026/claude-commit-session +0 -1
  130. package/prepare-for-pr/TI-16026/claude-harvest-session +0 -1
  131. package/prepare-for-pr/TI-16026/claude-hops/01-analyze.err +0 -1
  132. package/prepare-for-pr/TI-16026/claude-hops/01-analyze.out +0 -2
  133. package/prepare-for-pr/TI-16026/claude-hops/02-analyze.err +0 -1
  134. package/prepare-for-pr/TI-16026/claude-hops/02-analyze.out +0 -4
  135. package/prepare-for-pr/TI-16026/claude-hops/03-dev.err +0 -1
  136. package/prepare-for-pr/TI-16026/claude-hops/03-dev.out +0 -4
  137. package/prepare-for-pr/TI-16026/claude-hops/04-dev.err +0 -1
  138. package/prepare-for-pr/TI-16026/claude-hops/04-dev.out +0 -4
  139. package/prepare-for-pr/TI-16026/claude-hops/05-dev.err +0 -1
  140. package/prepare-for-pr/TI-16026/claude-hops/05-dev.out +0 -3
  141. package/prepare-for-pr/TI-16026/claude-hops/06-after.err +0 -1
  142. package/prepare-for-pr/TI-16026/claude-hops/06-after.out +0 -2
  143. package/prepare-for-pr/TI-16026/claude-hops/07-commit.err +0 -1
  144. package/prepare-for-pr/TI-16026/claude-hops/07-commit.out +0 -2
  145. package/prepare-for-pr/TI-16026/claude-hops/08-commit.err +0 -1
  146. package/prepare-for-pr/TI-16026/claude-hops/08-commit.out +0 -2
  147. package/prepare-for-pr/TI-16026/claude-hops/09-commit.err +0 -1
  148. package/prepare-for-pr/TI-16026/claude-hops/09-commit.out +0 -8
  149. package/prepare-for-pr/TI-16026/claude-hops/10-harvest.err +0 -1
  150. package/prepare-for-pr/TI-16026/claude-hops/10-harvest.out +0 -3
  151. package/prepare-for-pr/TI-16026/claude-hops/11-harvest.err +0 -1
  152. package/prepare-for-pr/TI-16026/claude-hops/11-harvest.out +0 -3
  153. package/prepare-for-pr/TI-16026/commit-note.md +0 -5
  154. package/prepare-for-pr/TI-16026/evidence-index.json +0 -215
  155. package/prepare-for-pr/TI-16026/feature-map.before.md +0 -61
  156. package/prepare-for-pr/TI-16026/harvest-redaction.json +0 -34
  157. package/prepare-for-pr/TI-16026/harvest-redaction.out +0 -37
  158. package/prepare-for-pr/TI-16026/harvest.md +0 -46
  159. package/prepare-for-pr/TI-16026/lessons.md +0 -5
  160. package/prepare-for-pr/TI-16026/note-harvest-redaction.md +0 -1
  161. package/prepare-for-pr/TI-16026/open-questions.md +0 -6
  162. package/prepare-for-pr/TI-16026/publish.md +0 -32
  163. package/prepare-for-pr/TI-16026/review-convergence-response.md +0 -3
  164. package/prepare-for-pr/TI-16026/review-input/scope.md +0 -18
  165. package/prepare-for-pr/TI-16026/review-log.md +0 -57
  166. package/prepare-for-pr/TI-16026/review-notes.md +0 -97
  167. package/prepare-for-pr/TI-16026/review-response-r1.md +0 -7
  168. package/prepare-for-pr/TI-16026/self-test-report.md +0 -67
  169. package/prepare-for-pr/TI-16026/spec-proposal.md +0 -34
  170. package/prepare-for-pr/TI-16026/spec-snapshot.md +0 -291
  171. package/prepare-for-pr/TI-16026/state-log.md +0 -57
  172. package/prepare-for-pr/TI-16026/user-messages/01.md +0 -12
  173. package/prepare-for-pr/TI-16026/user-messages/02.md +0 -20
  174. package/prepare-for-pr/TI-16026/user-messages/03.md +0 -1
  175. package/prepare-for-pr/TI-16026/user-messages/04.md +0 -1
  176. package/prepare-for-pr/TI-16026/user-messages/05.md +0 -1
  177. package/prepare-for-pr/TI-16026/user-messages/06.md +0 -1
  178. package/prepare-for-pr/TI-16026/user-messages/07.md +0 -1
  179. package/prepare-for-pr/TI-16026/user-messages/08.md +0 -1
  180. package/prepare-for-pr/TI-16026/user-messages/09.md +0 -1
  181. package/prepare-for-pr/TI-16026/user-messages/10.md +0 -1
  182. package/prepare-for-pr/TI-16026/user-messages/11.md +0 -1
  183. package/prepare-for-pr/TI-16026/user-messages/12.md +0 -1
  184. package/prepare-for-pr/TI-16026/user-messages/13.md +0 -1
  185. package/prepare-for-pr/TI-16026/user-messages/14.md +0 -1
  186. package/prepare-for-pr/TI-16026/user-messages/15.md +0 -1
  187. package/prepare-for-pr/TI-16026/user-messages/16.md +0 -1
  188. package/prepare-for-pr/TI-16026/user-messages/17.md +0 -1
  189. package/prepare-for-pr/TI-16026/user-messages/18.md +0 -10
  190. package/prepare-for-pr/TI-16026/user-messages/19.md +0 -1
  191. package/prepare-for-pr/TI-16026/user-messages/20.md +0 -1
  192. package/prepare-for-pr/TI-16026/user-messages/21.md +0 -1
  193. package/prepare-for-pr/TI-16026/user-messages/22.md +0 -1
  194. package/prepare-for-pr/TI-16026/user-messages/23.md +0 -8
  195. package/prepare-for-pr/TI-16026/user-messages/24.md +0 -24
  196. package/prepare-for-pr/TI-16026/user-question.md +0 -24
  197. package/prepare-for-pr/TI-16026/verify/metrics-check.json +0 -13
  198. package/prepare-for-pr/TI-16026/verify/redaction.json +0 -38
  199. package/prepare-for-pr/TI-16026/verify/row-closure.json +0 -45
  200. package/prepare-for-pr/TI-16026/verify/s04-ws-capture.md +0 -23
  201. package/prepare-for-pr/TI-16026/verify-after.md +0 -23
  202. package/prepare-for-pr/TI-16026/verify.json +0 -80
  203. package/prepare-for-pr/TI-16026.md +0 -408
  204. package/scripts/auto-version.js +0 -69
  205. package/scripts/auto-version.sh +0 -33
  206. package/scripts/branch-auto-npm-publish.js +0 -36
  207. package/scripts/check-version.sh +0 -36
  208. package/scripts/clean-tags.sh +0 -84
  209. package/src/api/account.js +0 -7
  210. package/src/api/otp.js +0 -5
  211. package/src/util/amount.js +0 -8
  212. package/src/util/err998SentryExtra.js +0 -26
  213. package/src/util/paramStore.js +0 -139
  214. package/src/util/socketPolicy.js +0 -57
  215. package/src/util/tokenStore.js +0 -44
  216. package/test/auth_otp_v3.test.js +0 -323
  217. package/test/auth_self_timeout.test.js +0 -171
  218. package/test/request_self.test.js +0 -288
  219. package/test/withdraw_manual_cash.test.js +0 -149
  220. package/tests/session.test.mjs +0 -177
  221. package/tests/websocket.test.mjs +0 -779
@@ -1,20 +1,11 @@
1
1
  import pickBy from 'lodash/pickBy.js'
2
- import createTokenStore from '../util/tokenStore.js'
3
- import { getErr998SentryExtra } from '../util/err998SentryExtra.js'
4
- import { SELF_REQUEST_TIMEOUT_MS } from '../util/constant.js'
5
-
6
- // 暫停 ERR_998 上報:在組裝 Sentry 資料之前就中止,不建立事件;仍照常 reject ERR_998 給呼叫端。恢復時改回 false 即可
7
- const IS_ERR_998_REPORT_PAUSED = true
8
-
9
- const CANCELLED_MESSAGE = 'Requests Cancelled'
10
-
11
- const SELF_URL = 'self'
12
- const TOKEN_EXPIRED_CODE = 'ERR_A108'
2
+ import storage from '../util/storage.js'
13
3
 
14
4
  // const pickBy = require('lodash/pickBy')
15
5
  const supportVersion2List = [
16
6
  // 04-09 Update
17
7
  'game/play',
8
+ 'game/gameReplay',
18
9
  'game/logout',
19
10
  'game/list/v3/root',
20
11
  'game/list/v3/category',
@@ -26,6 +17,8 @@ const supportVersion2List = [
26
17
  'game/list/v3/removeMyFavorite',
27
18
  'login',
28
19
  'callback/:strategy',
20
+ 'guestLogin',
21
+ 'appLogin',
29
22
  'logout',
30
23
  'self',
31
24
  'register',
@@ -33,6 +26,7 @@ const supportVersion2List = [
33
26
  'verify',
34
27
  'reset',
35
28
  'acknowledge',
29
+ 'recovery',
36
30
  'recovery/abandon',
37
31
  'recovery/acknowledge',
38
32
  'checkDt',
@@ -61,6 +55,7 @@ const supportVersion2List = [
61
55
  'account-binding/status',
62
56
  'account-binding/bind',
63
57
  'account-binding/acknowledge',
58
+ 'account-binding/bind-third-party',
64
59
  'feeds',
65
60
  'broadcast',
66
61
  'upload',
@@ -79,13 +74,18 @@ const supportVersion2List = [
79
74
  'payment/v2/convertFreeCredit',
80
75
  'payment/v2/getBindingBankList',
81
76
  'payment/v2/getBindingPaymentList',
77
+ 'payment/v2/getWithdrawBankList',
78
+ 'payment/v2/getCurrentWithdrawRule',
82
79
  'payment/v2/withdrawCheck',
80
+ 'payment/v2/history',
81
+ 'payment/v2/mergeWallet',
83
82
  'payment/v2/paymentDetail',
84
83
  'payment/v2/category/options',
85
84
  'payment/v2/paymentInfo',
86
85
  'payment/v2/getBindingPaymentInfo',
87
86
  'payment/v2/pendingOrder',
88
87
  'payment/v2/promotions',
88
+ 'payment/v2/spotmarket',
89
89
  'payment/v2/transactionHistory',
90
90
  'payment/v2/updateUtr',
91
91
  'payment/v2/setting',
@@ -95,6 +95,7 @@ const supportVersion2List = [
95
95
  'payment/v2/withdrawRule',
96
96
  'payment/v2/:paymentType/getBankList',
97
97
  'payment/v2/:paymentType/transaction',
98
+ 'payment/v2/:paymentType/checkTransaction',
98
99
  'payment/v2/:paymentType/bonus/preview',
99
100
  'payment/v2/:paymentType/expected/result',
100
101
  'payment/v2/:paymentType/crypto/expected/result',
@@ -109,6 +110,7 @@ const supportVersion2List = [
109
110
  'activities',
110
111
  'activities/types',
111
112
  'activities/promo',
113
+ 'activities/viptable',
112
114
  'activities/level-bonus/info',
113
115
  'activities/numbers',
114
116
  'activities/honorBroadcast',
@@ -130,6 +132,7 @@ const supportVersion2List = [
130
132
  'friends/dashboard',
131
133
  'friends/dashboard/list',
132
134
  'activities/ranking',
135
+ 'activities/activity/ranking',
133
136
  'activities/cashRain',
134
137
  'activities/jackpot/list',
135
138
  // 09/09
@@ -137,20 +140,6 @@ const supportVersion2List = [
137
140
  'game/list/v3/gameInfo',
138
141
  'payment/v2/uploadCommonSlip',
139
142
  'game/history/options',
140
- // 09/30
141
- 'pixel',
142
- // 10/09
143
- 'account-binding/status',
144
- 'account-binding/bind',
145
- 'account-binding/acknowledge',
146
- 'account-binding/bind-password',
147
- 'account-binding/reset-otp',
148
- // 11/10
149
- 'otp-verification-point/verify',
150
- 'otp-verification-point/acknowledge',
151
- 'otp-verification-point/reset-otp',
152
- // 12/02
153
- 'user-info/get-profile',
154
143
  ]
155
144
 
156
145
  function isValid(value) {
@@ -160,19 +149,13 @@ function isValid(value) {
160
149
  export default class Request {
161
150
  constructor(axios, config) {
162
151
  this.axios = axios
152
+ this.source = axios.CancelToken.source()
163
153
  this.config = config
164
154
  this.sentry = config.sentry
165
155
  this.key = `cuora_${config.clientId}`
166
- this.tokenStore = createTokenStore(this.key)
167
156
  this.errorHandler = null
168
157
  this.hosts = []
169
158
  this.isBlocked = false
170
- this.activeRequests = new Set() // { source, token }:僅追蹤非 public 且帶 token 的在途請求,供 revokeToken 取消
171
- this.selfFlights = new Map() // 在途的 /self 讀取:同類別(channel)、同 token、同 descriptor 共用同一筆,結束即移除
172
- this.revokedToken = null
173
- this.tokenGate = null
174
- this.clientIp = '' // 由外部 plugin(如 clientIp.client.js)非同步寫入,用於 ERR_998 Sentry 回報
175
- this.hostTester = null // 由外部 plugin(如 host.client.js)寫入,需提供 lastResults 陣列供 ERR_998 Sentry 回報使用
176
159
  this.initialize()
177
160
  }
178
161
 
@@ -220,24 +203,15 @@ export default class Request {
220
203
  },
221
204
  (error) => {
222
205
  if (error.message === 'Network Error' || error.message === 'Request failed with status code 404') {
223
- const endpoint = error.config?.url || ''
224
- // 確實在線才以 warning 等級回報(連線不穩定多為使用者端網路問題,非應用程式錯誤)
225
- const isOnline = typeof navigator !== 'undefined' ? navigator.onLine : true
226
- if (!IS_ERR_998_REPORT_PAUSED && isOnline) {
227
- const errData998 = getErr998SentryExtra(this, error.config)
228
- const sentryError = new Error(`ERR_998:${error.message}`)
229
- sentryError.name = 'ERR_998'
230
- this.sentry?.captureException(sentryError, {
231
- level: 'warning',
232
- tags: errData998,
233
- extra: {
234
- ...errData998,
235
- version: this.config.version,
236
- hostTestResults: this.hostTester?.lastResults || [],
237
- },
238
- })
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,
239
212
  }
240
- return Promise.reject({ code: 'ERR_998', endpoint })
213
+ this.sentry?.captureException(`ERR_998:${error.message}`)
214
+ return Promise.reject({ code: 'ERR_998' })
241
215
  }
242
216
  return Promise.reject(error.response?.data?.error || error)
243
217
  }
@@ -248,199 +222,54 @@ export default class Request {
248
222
  this.errorHandler = handler
249
223
  }
250
224
 
251
- // 作廢指定 token:取消同 token 的在途請求,並讓之後仍帶此 token 的 send() 直接 reject。
252
- // 只在 token 仍是目前身分時作用,舊身分遲到的錯誤不得影響新身分;重新登入後 token 改變即自然恢復
253
- revokeToken(token) {
254
- if (!token || token !== this.getToken()) return
255
- this.revokedToken = token
256
- this.activeRequests.forEach((item) => {
257
- if (item.token === token) item.source.cancel(CANCELLED_MESSAGE)
258
- })
259
- }
260
-
261
- // 回前景時先確認 token 仍有效:promise 結算(成功或失敗)或逾時即放行,之後的 send() 才會送出
262
- beginTokenGate(promise, timeoutMs = 3000) {
263
- let timer
264
- const timeout = new Promise((resolve) => {
265
- timer = setTimeout(resolve, timeoutMs)
266
- })
267
- const gate = Promise.race([Promise.resolve(promise).catch(() => {}), timeout]).then(() => {
268
- clearTimeout(timer)
269
- if (this.tokenGate === gate) this.tokenGate = null
270
- })
271
- this.tokenGate = gate
272
- return gate
273
- }
274
-
275
- // 帶 ERR_800 讓下游既有的 `if (!error.code)` 判斷(如 Sentry 上報)把取消視為預期錯誤
276
- _cancelledError() {
277
- return Object.assign(new Error(CANCELLED_MESSAGE), { code: 'ERR_800' })
278
- }
279
-
280
- _throwIfRevoked() {
281
- if (this.revokedToken && this.getToken() === this.revokedToken) {
282
- throw this._cancelledError()
283
- }
284
- }
285
-
286
- _isCancelled(error) {
287
- return !!this.axios.isCancel?.(error) || error?.message === CANCELLED_MESSAGE
288
- }
289
-
290
- _isSelf(req) {
291
- return req.url.split('?')[0] === SELF_URL
292
- }
293
-
294
- _isSelfRead(req) {
295
- return !req.isPublic && this._isSelf(req) && req.method.toUpperCase() === 'GET'
296
- }
297
-
298
- _isSelfWrite(req) {
299
- return !req.isPublic && this._isSelf(req) && req.method.toUpperCase() === 'POST'
300
- }
301
-
302
- // GET /self 成功(任何類別)即證明 token 仍有效:比照 auth machine 的 extendToken 續 5 分鐘。
303
- // 主輪詢連續逾時期間,只要其他類別的 GET /self 有一筆成功就不該被 TTL 登出。
304
- // POST /self 不續:後端只在 GET /self 續期 token
305
- _extendToken(requestToken) {
306
- if (requestToken && requestToken === this.getToken()) this.extendToken()
307
- }
308
-
309
- // /self 讀取分三類(descriptor 的 channel):主輪詢 polling/免費遊戲輪詢 freeGame/單獨呼叫 standalone(預設)。
310
- // 類別之間各發各的,不共用在途;同一類別內單一在途:在途期間相同的呼叫共用同一筆結果不另發。
311
- // key 含 channel、token 與 descriptor:換身分或參數不同(錯誤處理不同)各自獨立;自帶 customToken 者由呼叫端管理,不共用
312
225
  async send(req, customToken) {
313
- const token = !customToken && this._isSelfRead(req) ? this.getToken() : null
314
- if (!token) return this._send(req, customToken)
315
-
316
- const key = JSON.stringify([req.channel || 'standalone', token, req.url, req.params ?? null, req.headers ?? null, !!req.silent])
317
- const inFlight = this.selfFlights.get(key)
318
- if (inFlight) return inFlight
319
-
320
- const flight = this._send(req).finally(() => {
321
- if (this.selfFlights.get(key) === flight) this.selfFlights.delete(key)
322
- })
323
- this.selfFlights.set(key, flight)
324
- return flight
325
- }
326
-
327
- // 逾時視同網路失敗(ERR_998:不進 errorHandler、不彈窗),並取消請求。
328
- // 不用 axios 的 timeout:ECONNABORTED 會被下游 axios-retry 重試;取消的錯誤不帶 config,不會被重試
329
- _requestWithTimeout(requestConfig, tracked, timeoutMs) {
330
- let timer
331
- const timeout = new Promise((resolve, reject) => {
332
- timer = setTimeout(() => {
333
- reject({ code: 'ERR_998', endpoint: requestConfig.url, isTimeout: true })
334
- tracked?.source.cancel(CANCELLED_MESSAGE)
335
- }, timeoutMs)
336
- })
337
- return Promise.race([this.axios.request(requestConfig), timeout]).finally(() => clearTimeout(timer))
338
- }
339
-
340
- // ERR_A108 多半是續期的短暫落差:先以 /self 確認 session 仍在,成功才把原請求重送一次。
341
- // /self 自己、已重送過的請求、送出後身分已變的請求都不重送
342
- async _renewSession(req, requestToken) {
343
- if (!requestToken || this._isSelf(req) || this.getToken() !== requestToken) return false
344
226
  try {
345
- await this._send({ url: SELF_URL, method: 'get', silent: true }, undefined, true)
346
- } catch (error) {
347
- return false
348
- }
349
- return this.getToken() === requestToken
350
- }
351
-
352
- async _send(req, customToken, isRetry) {
353
- let tracked = null
354
- let requestToken = null
355
- try {
356
- // 非 public 請求缺 token 直接 reject:reject → onError → leaving → 乾淨登出,且不送網路 → 洪水照止
357
- if (!req.isPublic && !this.getToken()) return Promise.reject({ code: 'ERR_A103' })
358
-
359
- // 公開請求不帶 token,作廢期間 token 仍留在 storage 也不可誤拒(如 autoLogin 前後的 getConfig)
360
- if (!req.isPublic) this._throwIfRevoked()
361
-
362
- // /self 是 gate 自己的探測請求,不可等待 gate,否則死鎖
363
- if (this.tokenGate && !req.isPublic && !this._isSelf(req)) {
364
- await this.tokenGate
365
- this._throwIfRevoked()
366
- if (!this.getToken()) return Promise.reject({ code: 'ERR_A103' })
367
- }
368
-
369
- requestToken = req.isPublic ? null : this.getToken()
370
-
371
- // axios <0.22 對 cancelToken.promise 註冊的取消 handler 永不退訂(xhr.js 無 unsubscribe),
372
- // 預設掛長壽命共用 token 會使 handler 隨請求數線性累積(掛機過夜 OOM,TI-15555)。
373
- // 故不掛共用 token:呼叫端傳入 customToken 時自行管理其生命週期;否則帶 token 的請求用一次性 source,
374
- // 結束即移出 activeRequests 隨請求回收
375
- let cancelToken = customToken
376
- if (!customToken && requestToken && this.axios.CancelToken) {
377
- const source = this.axios.CancelToken.source()
378
- tracked = { source, token: requestToken }
379
- this.activeRequests.add(tracked)
380
- cancelToken = source.token
381
- }
227
+ const cancelToken = customToken || this.source.token
228
+ this._checkToken(req)
382
229
 
383
230
  const requestConfig = this._createConfig(req, cancelToken)
231
+ // console.log('*請求資料Check', requestConfig)
384
232
  const configUrls = ['getConfig', 'get-config']
385
233
  if (this.isBlocked && !configUrls.includes(requestConfig.url)) {
386
234
  // 狀態是維護中&請求非siteConfig,終止所有的請求,除了維護頁需要的資料(siteConfig)
235
+ // console.log('%c*禁止的請求目標', requestConfig)
387
236
  } else {
388
- // 單一在途必須配逾時釋放:請求卡住不回時,共用它的輪詢會跟著永久停止
389
- const isSelfWrite = this._isSelfWrite(req)
390
- if (isSelfWrite) {
391
- // 寫入與讀取相反:每次嘗試各 15 秒,逾時(ECONNABORTED)交給下游 axios-retry 照現行設定重試;
392
- // shouldResetTimeout 讓每次重試各有完整期限,否則期限由所有嘗試共用
393
- requestConfig.timeout = SELF_REQUEST_TIMEOUT_MS
394
- requestConfig['axios-retry'] = { shouldResetTimeout: true }
395
- }
396
- const { data } = await (this._isSelfRead(req)
397
- ? this._requestWithTimeout(requestConfig, tracked, SELF_REQUEST_TIMEOUT_MS)
398
- : this.axios.request(requestConfig))
399
- if (this._isSelfRead(req)) this._extendToken(requestToken)
237
+ // console.log('%c*允許的請求目標', requestConfig)
238
+ const { data } = await this.axios.request(requestConfig)
400
239
  return data
401
240
  }
402
241
  } catch (error) {
403
- if (this._isCancelled(error)) throw this._cancelledError()
404
- if (error?.code === TOKEN_EXPIRED_CODE && !isRetry && (await this._renewSession(req, requestToken))) {
405
- return await this._send(req, customToken, true)
406
- }
407
- // 不可列舉:避免 Bearer token 隨 JSON.stringify/Sentry 序列化外洩,但 error.requestToken 仍可讀取
408
- if (requestToken && error && typeof error === 'object' && Object.isExtensible(error)) {
409
- Object.defineProperty(error, 'requestToken', { value: requestToken, enumerable: false, configurable: true })
410
- }
411
- // POST /self 重試用完仍逾時:比照讀取的逾時(ERR_998:不進 errorHandler、不彈窗)
412
- if (error?.code === 'ECONNABORTED' && this._isSelfWrite(req)) {
413
- throw { code: 'ERR_998', endpoint: req.url, isTimeout: true }
414
- }
415
242
  if (error.code === 'ERR_F108') {
243
+ console.log('%c*維護中', 'color: #00ff33ff; font-weight: bold;')
416
244
  this.isBlocked = true
417
245
  this.errorHandler && this.errorHandler(error)
418
246
  throw error
419
247
  }
420
- // 舊身分遲到的錯誤不進 errorHandler;目前沒 token(TTL 過期或已 CLEAR)時維持原路由,A204 等彈窗才不會被吞
421
- const currentToken = this.getToken()
422
- if (requestToken && currentToken && currentToken !== requestToken) throw error
423
- if (error.code === 'ERR_998') {
424
- throw error
425
- }
426
248
  if (error.code !== 'ERR_800') {
427
- if (error.code && !req.silent) {
249
+ if (error.code) {
428
250
  this.errorHandler && this.errorHandler(error)
429
251
  }
430
252
  throw error
431
253
  }
432
- } finally {
433
- if (tracked) this.activeRequests.delete(tracked)
434
254
  }
435
255
  }
436
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
+
437
266
  _createConfig(req, cancelToken) {
438
267
  const { method, url, params, isPublic, isFormData, headers } = req
439
268
  let fullURL = this.config.fullURL
440
269
  let urlName = url
441
-
442
270
  // 有些API會將參數(/?)直接帶在URL上,所以要將參數排除
443
271
  const cleanUrl = url.split('?')[0]
272
+
444
273
  const isV2Supported = supportVersion2List.some((supportedUrl) => {
445
274
  // 如果包含動態參數(:parameter),則使用模式匹配
446
275
  if (supportedUrl.includes(':')) {
@@ -450,9 +279,16 @@ export default class Request {
450
279
  }
451
280
  return supportedUrl === cleanUrl
452
281
  })
453
- // 符合轉換規則的API進行路徑調整
454
- if (isV2Supported) {
282
+
283
+ // 目前全站都支援V2,若有需要限制為V1的站點可以填入,此段等轉換全部完成之後就可以移除了
284
+ const supportV2Toggle = [''].includes(this.config?.clientId)
285
+
286
+ if (isV2Supported && !supportV2Toggle) {
287
+ fullURL = fullURL.replace('/v1/', '/v2/')
455
288
  urlName = this._convertUrlToKebabCase(url)
289
+ // console.log(`*[DEV_ONLY]V2`, 'url:', urlName)
290
+ } else {
291
+ // console.log(`*[DEV_ONLY]V2-不支援:`, 'url:', urlName)
456
292
  }
457
293
 
458
294
  if (isFormData) {
@@ -480,7 +316,6 @@ export default class Request {
480
316
 
481
317
  // 調整API路徑與名稱
482
318
  _convertUrlToKebabCase(url) {
483
- const [path, queryString] = url.split('?')
484
319
  const specifyingPath = {
485
320
  'all-activities/list': 'activities/all-activities-list',
486
321
  friends: 'activities/friends',
@@ -492,6 +327,7 @@ export default class Request {
492
327
  'activities/getFreeGameRewardList': 'activities/free-game/get-free-game-reward-list',
493
328
  'activities/lose-rebate/history': 'activities/rebate/lose-rebate/history',
494
329
  'activities/ranking': 'activities/ranking/promotion-ranking',
330
+ 'activities/activity/ranking': 'activities/ranking/basic-ranking',
495
331
  'activities/cashRain': 'activities/cash-rain/exchange',
496
332
  'tournament/detail': 'activities/tournament/detail',
497
333
  'ranking/detail': 'activities/tournament/ranking/detail',
@@ -501,25 +337,22 @@ export default class Request {
501
337
  'activities/exchange/diamond/max-amount': 'activities/diamond/exchange/max-amount',
502
338
  'activities/exchange/diamond/settle': 'activities/diamond/exchange/settle',
503
339
  }
504
- // 和原有路徑不同有另外改路徑
505
- const convertedPath = specifyingPath[path] ? specifyingPath[path] : path.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()
506
- return queryString ? `${convertedPath}?${queryString}` : convertedPath
507
- }
508
-
509
- getToken() {
510
- return this.tokenStore.get()
511
- }
512
-
513
- setToken(token) {
514
- this.tokenStore.set(token)
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
+ }
515
347
  }
516
348
 
517
- // 回傳續期當下的 token;已不存在時回傳 null
518
- extendToken() {
519
- return this.tokenStore.extend()
349
+ _checkToken(req) {
350
+ if (!req.isPublic && !this.getToken()) {
351
+ throw { code: 'ERR_A103', url: req.url }
352
+ }
520
353
  }
521
354
 
522
- removeToken() {
523
- this.tokenStore.clear()
355
+ getToken() {
356
+ return storage.get(this.key)
524
357
  }
525
358
  }
@@ -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,20 +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
25
-
26
- // 登入 token 的存活秒數:每次 /self 成功續期一次,逾時由瀏覽器自行移除 cookie
27
- export const TOKEN_MAX_AGE = 300
28
-
29
- // /self 讀取的逾時上限:後端 5 分鐘沒收到 /self 會移除 token,逾時釋放在途後由下一輪輪詢重發
30
- export const SELF_REQUEST_TIMEOUT_MS = 15000
@@ -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
+ }