@jetthai/cuora 2.0.0-beta.0 → 2.0.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 (201) hide show
  1. package/.claude/commands/sync-ai-prompts.md +93 -0
  2. package/.claude/settings.local.json +23 -0
  3. package/.github/copilot-instructions.md +405 -0
  4. package/.husky/post-checkout +32 -0
  5. package/.husky/pre-commit +1 -3
  6. package/.husky/pre-push +36 -0
  7. package/AGENTS.md +405 -0
  8. package/AI_PROMPT_SOURCE.md +403 -0
  9. package/CHANGELOG.md +274 -3
  10. package/CLAUDE.md +405 -0
  11. package/GEMINI.md +405 -0
  12. package/README.md +299 -15
  13. package/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +1003 -0
  14. package/docs/kibana/play-providerId-error.md +202 -0
  15. package/docs/kibana/play-selectedWalletType.md +1 -0
  16. package/docs/kibana/play-selectedWalletType_2.md +1 -0
  17. package/docs/kibana/play-selectedWalletType_analysis.md +565 -0
  18. package/package.json +3 -3
  19. package/scripts/auto-version.js +68 -0
  20. package/scripts/auto-version.sh +33 -0
  21. package/scripts/branch-auto-npm-publish.js +29 -0
  22. package/scripts/check-version.sh +36 -0
  23. package/scripts/clean-tags.sh +84 -0
  24. package/src/api/account.js +0 -1
  25. package/src/api/activity.js +22 -37
  26. package/src/api/auth.js +5 -36
  27. package/src/api/common.js +5 -3
  28. package/src/api/game.js +0 -10
  29. package/src/api/payment.js +17 -55
  30. package/src/api/user.js +10 -16
  31. package/src/index.js +2 -2
  32. package/src/machine/activity/activity_cash.js +84 -36
  33. package/src/machine/activity/cash_rain_activity.js +0 -1
  34. package/src/machine/activity/continue_deposit_activity.js +0 -1
  35. package/src/machine/activity/deposit_activity.js +0 -1
  36. package/src/machine/activity/diamond_shop_activity_cash.js +0 -8
  37. package/src/machine/activity/fafafa_activity.js +0 -11
  38. package/src/machine/activity/friend_invite_friends_activity.js +8 -7
  39. package/src/machine/activity/index.js +0 -12
  40. package/src/machine/activity/instant_rebate_activity.js +0 -1
  41. package/src/machine/activity/jackpot.js +0 -1
  42. package/src/machine/activity/otp_verified_activity.js +0 -1
  43. package/src/machine/activity/ranking_activity.js +0 -1
  44. package/src/machine/activity/roulette_activity_v2.js +0 -1
  45. package/src/machine/activity/sign_in_activity.js +0 -1
  46. package/src/machine/activity/sign_in_monthly_activity.js +1 -2
  47. package/src/machine/activity/specify_bets_activity.js +0 -1
  48. package/src/machine/activity/specify_turnover_activity.js +0 -1
  49. package/src/machine/activity/time_bomb_activity.js +0 -1
  50. package/src/machine/activity/vip_card_activity.js +0 -1
  51. package/src/machine/auth.js +112 -112
  52. package/src/machine/auth_otp_v3.js +11 -8
  53. package/src/machine/bank_binding.js +2 -3
  54. package/src/machine/common.js +14 -98
  55. package/src/machine/deposit/crypto_bank_cash.js +20 -35
  56. package/src/machine/deposit/crypto_qrcode_cash.js +26 -64
  57. package/src/machine/deposit/crypto_way_cash.js +48 -37
  58. package/src/machine/deposit/direct_cash.js +8 -10
  59. package/src/machine/deposit/index.js +0 -28
  60. package/src/machine/deposit/loadcard_cash.js +14 -32
  61. package/src/machine/deposit/manual_cash.js +8 -11
  62. package/src/machine/deposit/qrcode_cash.js +15 -32
  63. package/src/machine/deposit/usdt_cash.js +1 -15
  64. package/src/machine/deposit/virtual_bank_cash.js +13 -12
  65. package/src/machine/error.js +7 -1
  66. package/src/machine/game_betslip.js +0 -1
  67. package/src/machine/game_favorite_v2.js +0 -1
  68. package/src/machine/game_info.js +1 -13
  69. package/src/machine/game_search_cash.js +0 -1
  70. package/src/machine/game_v2_1.js +39 -126
  71. package/src/machine/honor_board_cash.js +8 -11
  72. package/src/machine/inbox.js +43 -105
  73. package/src/machine/index.js +0 -32
  74. package/src/machine/leaderboard.js +8 -12
  75. package/src/machine/navbar.js +1 -3
  76. package/src/machine/ranking.js +45 -30
  77. package/src/machine/reward_cash.js +0 -40
  78. package/src/machine/roulette_v2.js +14 -11
  79. package/src/machine/setting.js +0 -1
  80. package/src/machine/side_cash.js +3 -3
  81. package/src/machine/user_info.js +0 -1
  82. package/src/machine/user_photo.js +0 -1
  83. package/src/machine/user_reset_password.js +0 -14
  84. package/src/machine/user_sign_up.js +46 -61
  85. package/src/machine/websocket.js +18 -62
  86. package/src/machine/withdraw/index.js +0 -6
  87. package/src/machine/withdraw/withdraw_manual_cash.js +59 -39
  88. package/src/request/config.js +2 -0
  89. package/src/request/request.js +49 -60
  90. package/src/util/amount.js +8 -0
  91. package/src/util/constant.js +0 -1
  92. package/src/util/err998SentryExtra.js +26 -0
  93. package/src/util/index.js +2 -4
  94. package/src/util/paramStore.js +139 -0
  95. package/src/util/storage.js +3 -4
  96. package/BREAKING_CHANGES.md +0 -9
  97. package/resetGitBranch.sh +0 -101
  98. package/src/lib/fingerprint_v3_11_12.js +0 -11433
  99. package/src/machine/activity/activity.js +0 -213
  100. package/src/machine/activity/diamond_shop_activity_fc.js +0 -197
  101. package/src/machine/activity/diamond_shop_activity_vn.js +0 -179
  102. package/src/machine/activity/invite_friends_activity.js +0 -115
  103. package/src/machine/activity/mini_game_activity.js +0 -69
  104. package/src/machine/activity/return_bonus_activity.js +0 -155
  105. package/src/machine/auth_otp_v2.js +0 -178
  106. package/src/machine/bank_binding_amb.js +0 -146
  107. package/src/machine/bonus.js +0 -76
  108. package/src/machine/deposit/amb.js +0 -93
  109. package/src/machine/deposit/crypto_bank.js +0 -340
  110. package/src/machine/deposit/crypto_qrcode.js +0 -158
  111. package/src/machine/deposit/crypto_way.js +0 -253
  112. package/src/machine/deposit/deposit_fc.js +0 -272
  113. package/src/machine/deposit/direct.js +0 -311
  114. package/src/machine/deposit/float.js +0 -375
  115. package/src/machine/deposit/krway.js +0 -152
  116. package/src/machine/deposit/loadcard_vn.js +0 -352
  117. package/src/machine/deposit/manual_vn.js +0 -459
  118. package/src/machine/deposit/qrcode_v2.js +0 -339
  119. package/src/machine/deposit/usdt.js +0 -163
  120. package/src/machine/deposit/virtual_bank_vn.js +0 -270
  121. package/src/machine/deposit/vpay.js +0 -374
  122. package/src/machine/game_hot_new.js +0 -80
  123. package/src/machine/game_replay.js +0 -47
  124. package/src/machine/game_search_v2.js +0 -402
  125. package/src/machine/honor_board.js +0 -133
  126. package/src/machine/merge.js +0 -58
  127. package/src/machine/payment_data.js +0 -87
  128. package/src/machine/promotions.js +0 -163
  129. package/src/machine/reward.js +0 -256
  130. package/src/machine/reward_fc.js +0 -99
  131. package/src/machine/side.js +0 -160
  132. package/src/machine/side_v2.js +0 -223
  133. package/src/machine/vip_table.js +0 -58
  134. package/src/machine/welcome.js +0 -111
  135. package/src/machine/withdraw/withdraw_crypto_cash.js +0 -328
  136. package/src/machine/withdraw/withdraw_krway.js +0 -223
  137. package/src/machine/withdraw/withdraw_manual.js +0 -541
  138. package/src/util/deviceToken.js +0 -60
  139. package/src/util/math.js +0 -4
  140. package/test/api.behavior.test.js +0 -69
  141. package/test/api.contract.test.js +0 -18
  142. package/test/config.test.js +0 -27
  143. package/test/deviceToken.test.js +0 -139
  144. package/test/helpers.coverage.test.js +0 -11
  145. package/test/helpers.js +0 -91
  146. package/test/index.exports.test.js +0 -14
  147. package/test/machine.activity.core.coverage.test.js +0 -337
  148. package/test/machine.activity.gap.coverage.test.js +0 -252
  149. package/test/machine.activity.more.coverage.test.js +0 -180
  150. package/test/machine.activity_plus_and_binding_amb.coverage.test.js +0 -201
  151. package/test/machine.activity_timer_bonus.coverage.test.js +0 -136
  152. package/test/machine.activity_welcome.low.coverage.test.js +0 -211
  153. package/test/machine.amb_rewardfc_websocket.more.coverage.test.js +0 -201
  154. package/test/machine.auth.coverage.test.js +0 -215
  155. package/test/machine.bank_binding.test.js +0 -143
  156. package/test/machine.binding_otp_krway.coverage.test.js +0 -223
  157. package/test/machine.contract.test.js +0 -50
  158. package/test/machine.crypto_bank.coverage.test.js +0 -270
  159. package/test/machine.crypto_way.coverage.test.js +0 -108
  160. package/test/machine.crypto_way_cash.coverage.test.js +0 -114
  161. package/test/machine.definition.test.js +0 -137
  162. package/test/machine.deposit.manual.coverage.test.js +0 -365
  163. package/test/machine.deposit_fc.coverage.test.js +0 -126
  164. package/test/machine.direct.coverage.test.js +0 -96
  165. package/test/machine.direct_cash.coverage.test.js +0 -108
  166. package/test/machine.error.coverage.test.js +0 -37
  167. package/test/machine.events.test.js +0 -126
  168. package/test/machine.favorite_jackpot.coverage.test.js +0 -82
  169. package/test/machine.float.coverage.test.js +0 -136
  170. package/test/machine.flow.test.js +0 -226
  171. package/test/machine.game_hot_new_vip_table.coverage.test.js +0 -105
  172. package/test/machine.game_search_cash.coverage.test.js +0 -155
  173. package/test/machine.game_search_v2.test.js +0 -199
  174. package/test/machine.game_user_profile.coverage.test.js +0 -100
  175. package/test/machine.honor_board.test.js +0 -133
  176. package/test/machine.inbox.common.coverage.test.js +0 -304
  177. package/test/machine.loadcard_cash.coverage.test.js +0 -101
  178. package/test/machine.loadcard_vn.coverage.test.js +0 -122
  179. package/test/machine.misc.coverage.test.js +0 -361
  180. package/test/machine.more2.coverage.test.js +0 -261
  181. package/test/machine.options.execution.test.js +0 -272
  182. package/test/machine.priority.coverage.test.js +0 -603
  183. package/test/machine.qrcode_cash.coverage.test.js +0 -107
  184. package/test/machine.qrcode_v2.coverage.test.js +0 -121
  185. package/test/machine.regression.test.js +0 -82
  186. package/test/machine.roulette_v2.test.js +0 -142
  187. package/test/machine.side_reward_reset.coverage.test.js +0 -220
  188. package/test/machine.targeted.coverage.test.js +0 -313
  189. package/test/machine.usdt.coverage.test.js +0 -95
  190. package/test/machine.usdt_cash.coverage.test.js +0 -73
  191. package/test/machine.vip_card_activity.test.js +0 -114
  192. package/test/machine.virtual_bank_cash.coverage.test.js +0 -105
  193. package/test/machine.virtual_bank_vn.coverage.test.js +0 -105
  194. package/test/machine.vpay.coverage.test.js +0 -142
  195. package/test/machine.withdraw_crypto_cash.coverage.test.js +0 -166
  196. package/test/machine.withdraw_krway.coverage.test.js +0 -123
  197. package/test/machine.withdraw_manual.coverage.test.js +0 -185
  198. package/test/machine.withdraw_manual_cash.coverage.test.js +0 -123
  199. package/test/request.test.js +0 -325
  200. package/test/util.storage.errors.test.js +0 -47
  201. package/test/util.test.js +0 -41
@@ -1,11 +1,14 @@
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
3
7
 
4
8
  // const pickBy = require('lodash/pickBy')
5
9
  const supportVersion2List = [
6
10
  // 04-09 Update
7
11
  'game/play',
8
- 'game/gameReplay',
9
12
  'game/logout',
10
13
  'game/list/v3/root',
11
14
  'game/list/v3/category',
@@ -17,8 +20,6 @@ const supportVersion2List = [
17
20
  'game/list/v3/removeMyFavorite',
18
21
  'login',
19
22
  'callback/:strategy',
20
- 'guestLogin',
21
- 'appLogin',
22
23
  'logout',
23
24
  'self',
24
25
  'register',
@@ -26,7 +27,6 @@ const supportVersion2List = [
26
27
  'verify',
27
28
  'reset',
28
29
  'acknowledge',
29
- 'recovery',
30
30
  'recovery/abandon',
31
31
  'recovery/acknowledge',
32
32
  'checkDt',
@@ -55,7 +55,6 @@ const supportVersion2List = [
55
55
  'account-binding/status',
56
56
  'account-binding/bind',
57
57
  'account-binding/acknowledge',
58
- 'account-binding/bind-third-party',
59
58
  'feeds',
60
59
  'broadcast',
61
60
  'upload',
@@ -74,18 +73,13 @@ const supportVersion2List = [
74
73
  'payment/v2/convertFreeCredit',
75
74
  'payment/v2/getBindingBankList',
76
75
  'payment/v2/getBindingPaymentList',
77
- 'payment/v2/getWithdrawBankList',
78
- 'payment/v2/getCurrentWithdrawRule',
79
76
  'payment/v2/withdrawCheck',
80
- 'payment/v2/history',
81
- 'payment/v2/mergeWallet',
82
77
  'payment/v2/paymentDetail',
83
78
  'payment/v2/category/options',
84
79
  'payment/v2/paymentInfo',
85
80
  'payment/v2/getBindingPaymentInfo',
86
81
  'payment/v2/pendingOrder',
87
82
  'payment/v2/promotions',
88
- 'payment/v2/spotmarket',
89
83
  'payment/v2/transactionHistory',
90
84
  'payment/v2/updateUtr',
91
85
  'payment/v2/setting',
@@ -95,7 +89,6 @@ const supportVersion2List = [
95
89
  'payment/v2/withdrawRule',
96
90
  'payment/v2/:paymentType/getBankList',
97
91
  'payment/v2/:paymentType/transaction',
98
- 'payment/v2/:paymentType/checkTransaction',
99
92
  'payment/v2/:paymentType/bonus/preview',
100
93
  'payment/v2/:paymentType/expected/result',
101
94
  'payment/v2/:paymentType/crypto/expected/result',
@@ -110,7 +103,6 @@ const supportVersion2List = [
110
103
  'activities',
111
104
  'activities/types',
112
105
  'activities/promo',
113
- 'activities/viptable',
114
106
  'activities/level-bonus/info',
115
107
  'activities/numbers',
116
108
  'activities/honorBroadcast',
@@ -132,7 +124,6 @@ const supportVersion2List = [
132
124
  'friends/dashboard',
133
125
  'friends/dashboard/list',
134
126
  'activities/ranking',
135
- 'activities/activity/ranking',
136
127
  'activities/cashRain',
137
128
  'activities/jackpot/list',
138
129
  // 09/09
@@ -146,7 +137,6 @@ const supportVersion2List = [
146
137
  'account-binding/status',
147
138
  'account-binding/bind',
148
139
  'account-binding/acknowledge',
149
- 'account-binding/bind-third-party',
150
140
  'account-binding/bind-password',
151
141
  'account-binding/reset-otp',
152
142
  // 11/10
@@ -156,13 +146,6 @@ const supportVersion2List = [
156
146
  // 12/02
157
147
  'user-info/get-profile',
158
148
  ]
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
- })
166
149
 
167
150
  function isValid(value) {
168
151
  return value !== undefined && value !== null
@@ -171,13 +154,14 @@ function isValid(value) {
171
154
  export default class Request {
172
155
  constructor(axios, config) {
173
156
  this.axios = axios
174
- this.source = axios.CancelToken.source()
175
157
  this.config = config
176
158
  this.sentry = config.sentry
177
159
  this.key = `cuora_${config.clientId}`
178
160
  this.errorHandler = null
179
161
  this.hosts = []
180
162
  this.isBlocked = false
163
+ this.clientIp = '' // 由外部 plugin(如 clientIp.client.js)非同步寫入,用於 ERR_998 Sentry 回報
164
+ this.hostTester = null // 由外部 plugin(如 host.client.js)寫入,需提供 lastResults 陣列供 ERR_998 Sentry 回報使用
181
165
  this.initialize()
182
166
  }
183
167
 
@@ -209,10 +193,9 @@ export default class Request {
209
193
  this.axios.interceptors.request.use((axiosConfig) => {
210
194
  axiosConfig.headers['X-TH1GAMES-VERSION'] = this.config.version
211
195
  axiosConfig.headers['X-TH1GAMES-PLATFORM'] = this.config.platform
212
- const token = this.getToken()
213
- if (token) {
196
+ if (this.getToken()) {
214
197
  // 為了支援V2版本的API接口新增Bearer來進行身份驗證
215
- axiosConfig.headers.Authorization = `Bearer ${token}`
198
+ axiosConfig.headers.Authorization = `Bearer ${this.getToken()}`
216
199
  }
217
200
  return axiosConfig
218
201
  })
@@ -226,8 +209,24 @@ export default class Request {
226
209
  },
227
210
  (error) => {
228
211
  if (error.message === 'Network Error' || error.message === 'Request failed with status code 404') {
229
- this.sentry?.captureException(`ERR_998:${error.message}`)
230
- return Promise.reject({ code: 'ERR_998' })
212
+ const endpoint = error.config?.url || ''
213
+ // 確實在線才以 warning 等級回報(連線不穩定多為使用者端網路問題,非應用程式錯誤)
214
+ const isOnline = typeof navigator !== 'undefined' ? navigator.onLine : true
215
+ if (!IS_ERR_998_REPORT_PAUSED && isOnline) {
216
+ const errData998 = getErr998SentryExtra(this, error.config)
217
+ const sentryError = new Error(`ERR_998:${error.message}`)
218
+ sentryError.name = 'ERR_998'
219
+ this.sentry?.captureException(sentryError, {
220
+ level: 'warning',
221
+ tags: errData998,
222
+ extra: {
223
+ ...errData998,
224
+ version: this.config.version,
225
+ hostTestResults: this.hostTester?.lastResults || [],
226
+ },
227
+ })
228
+ }
229
+ return Promise.reject({ code: 'ERR_998', endpoint })
231
230
  }
232
231
  return Promise.reject(error.response?.data?.error || error)
233
232
  }
@@ -240,27 +239,33 @@ export default class Request {
240
239
 
241
240
  async send(req, customToken) {
242
241
  try {
243
- const cancelToken = customToken || this.source.token
244
- this._checkToken(req)
242
+ // 非 public 請求缺 token 直接 reject:reject → onError → leaving → 乾淨登出,且不送網路 → 洪水照止
243
+ if (!req.isPublic && !this.getToken()) return Promise.reject({ code: 'ERR_A103' })
244
+
245
+ // axios <0.22 對 cancelToken.promise 註冊的取消 handler 永不退訂(xhr.js 無 unsubscribe),
246
+ // 預設掛長壽命共用 token 會使 handler 隨請求數線性累積(掛機過夜 OOM,TI-15555)。
247
+ // 故預設不掛 cancelToken,僅呼叫端明確傳入 customToken(自行管理其生命週期)時才附加。
248
+ const cancelToken = customToken
245
249
 
246
250
  const requestConfig = this._createConfig(req, cancelToken)
247
251
  const configUrls = ['getConfig', 'get-config']
248
252
  if (this.isBlocked && !configUrls.includes(requestConfig.url)) {
249
- // 狀態是維護中且請求非 site config,回傳明確錯誤避免呼叫端拿到 undefined
250
- throw { code: 'ERR_MAINTENANCE_BLOCKED', url: requestConfig.url }
253
+ // 狀態是維護中&請求非siteConfig,終止所有的請求,除了維護頁需要的資料(siteConfig)
251
254
  } else {
252
255
  const { data } = await this.axios.request(requestConfig)
253
256
  return data
254
257
  }
255
258
  } catch (error) {
256
259
  if (error.code === 'ERR_F108') {
257
- console.log('%c*維護中', 'color: #00ff33ff; font-weight: bold;')
258
260
  this.isBlocked = true
259
261
  this.errorHandler && this.errorHandler(error)
260
262
  throw error
261
263
  }
264
+ if (error.code === 'ERR_998') {
265
+ throw error
266
+ }
262
267
  if (error.code !== 'ERR_800') {
263
- if (error.code) {
268
+ if (error.code && !req.silent) {
264
269
  this.errorHandler && this.errorHandler(error)
265
270
  }
266
271
  throw error
@@ -268,15 +273,6 @@ export default class Request {
268
273
  }
269
274
  }
270
275
 
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
-
280
276
  _createConfig(req, cancelToken) {
281
277
  const { method, url, params, isPublic, isFormData, headers } = req
282
278
  let fullURL = this.config.fullURL
@@ -284,11 +280,14 @@ export default class Request {
284
280
 
285
281
  // 有些API會將參數(/?)直接帶在URL上,所以要將參數排除
286
282
  const cleanUrl = url.split('?')[0]
287
- const isV2Supported = supportVersion2Matchers.some((matcher) => {
288
- if (matcher instanceof RegExp) {
289
- return matcher.test(cleanUrl)
283
+ const isV2Supported = supportVersion2List.some((supportedUrl) => {
284
+ // 如果包含動態參數(:parameter),則使用模式匹配
285
+ if (supportedUrl.includes(':')) {
286
+ const pattern = supportedUrl.replace(/:[^/]+/g, '[^/]+')
287
+ const regex = new RegExp(`^${pattern}$`)
288
+ return regex.test(cleanUrl)
290
289
  }
291
- return matcher === cleanUrl
290
+ return supportedUrl === cleanUrl
292
291
  })
293
292
  // 符合轉換規則的API進行路徑調整
294
293
  if (isV2Supported) {
@@ -320,6 +319,7 @@ export default class Request {
320
319
 
321
320
  // 調整API路徑與名稱
322
321
  _convertUrlToKebabCase(url) {
322
+ const [path, queryString] = url.split('?')
323
323
  const specifyingPath = {
324
324
  'all-activities/list': 'activities/all-activities-list',
325
325
  friends: 'activities/friends',
@@ -331,7 +331,6 @@ export default class Request {
331
331
  'activities/getFreeGameRewardList': 'activities/free-game/get-free-game-reward-list',
332
332
  'activities/lose-rebate/history': 'activities/rebate/lose-rebate/history',
333
333
  'activities/ranking': 'activities/ranking/promotion-ranking',
334
- 'activities/activity/ranking': 'activities/ranking/basic-ranking',
335
334
  'activities/cashRain': 'activities/cash-rain/exchange',
336
335
  'tournament/detail': 'activities/tournament/detail',
337
336
  'ranking/detail': 'activities/tournament/ranking/detail',
@@ -341,19 +340,9 @@ export default class Request {
341
340
  'activities/exchange/diamond/max-amount': 'activities/diamond/exchange/max-amount',
342
341
  'activities/exchange/diamond/settle': 'activities/diamond/exchange/settle',
343
342
  }
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
- }
343
+ // 和原有路徑不同有另外改路徑
344
+ const convertedPath = specifyingPath[path] ? specifyingPath[path] : path.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()
345
+ return queryString ? `${convertedPath}?${queryString}` : convertedPath
357
346
  }
358
347
 
359
348
  getToken() {
@@ -0,0 +1,8 @@
1
+ export function isAmountInRange(raw, payment) {
2
+ if (!payment) return false
3
+ const amount = Number(raw)
4
+ if (!Number.isFinite(amount) || amount <= 0) return false
5
+ const minimum = payment.minimum ?? 0
6
+ const maximum = payment.maximum ?? Infinity
7
+ return amount >= minimum && amount <= maximum
8
+ }
@@ -1,4 +1,3 @@
1
- export const MY_FAVORITE = 'MyFavorite'
2
1
  export const GAME_SEARCH = 'GameSearch'
3
2
  export const GAME_TYPE_LIST = [
4
3
  { typeId: 'SLOT', name: 'Slots', gameTypeMappingId: 1 },
@@ -0,0 +1,26 @@
1
+ // ERR_998(Network Error / 404)Sentry 回報資料組裝工具
2
+ // 集中組裝 tags/extra,避免在 request.js 內重複拼裝邏輯
3
+ export function getErr998SentryExtra(request, config) {
4
+ const method = config?.method || ''
5
+ const endpoint = config?.url || ''
6
+ const apiHost = request?.config?.apiURL || ''
7
+ const uidSite = getUidSite()
8
+
9
+ return {
10
+ code: 'ERR_998',
11
+ endpoint,
12
+ method,
13
+ site: request?.config?.clientId || '',
14
+ ip: request?.clientIp || '',
15
+ apiHost,
16
+ uidSite,
17
+ }
18
+ }
19
+
20
+ function getUidSite() {
21
+ try {
22
+ return (typeof window !== 'undefined' && window.$nuxt?.$store?.state?.userInfo?.uid_site) || ''
23
+ } catch (error) {
24
+ return ''
25
+ }
26
+ }
package/src/util/index.js CHANGED
@@ -1,7 +1,5 @@
1
- import { getDeviceToken, getDeviceTokenWithRetry } from './deviceToken.js'
2
1
  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'
5
4
 
6
- export default { getDeviceToken, getDeviceTokenWithRetry }
7
- export { constant, storage, max }
5
+ export { constant, storage, paramStore }
@@ -0,0 +1,139 @@
1
+ import Cookies from 'universal-cookie'
2
+ import storage from './storage.js'
3
+
4
+ export const PARAM_MAX_AGE = 60 * 60 * 24 * 7
5
+ export const AC_KEYS = ['ac', 'referralCode']
6
+ export const FC_KEYS = ['fc', 'affiliate']
7
+
8
+ const DIRTY_VALUES = ['undefined', 'null', 'NaN']
9
+
10
+ const reportedOnce = new Set()
11
+
12
+ function cookieJar() {
13
+ return typeof document === 'undefined' ? null : new Cookies()
14
+ }
15
+
16
+ export function normalize(value) {
17
+ if (value === undefined || value === null) return null
18
+ const trimmed = String(value).trim()
19
+ if (trimmed === '' || DIRTY_VALUES.includes(trimmed)) return null
20
+ return trimmed
21
+ }
22
+
23
+ // storage.js 的 JSON.parse 未包在 try/catch 內,localStorage 若存有同名裸字串會 throw,
24
+ // 未攔截會沿 xstate entry chain 往上炸掉整條 setUA→setAgent→setPixel→setKPixel→setFbclid
25
+ function readLocal(name) {
26
+ try {
27
+ return normalize(storage.get(name))
28
+ } catch (error) {
29
+ return null
30
+ }
31
+ }
32
+
33
+ function readCookie(name) {
34
+ const jar = cookieJar()
35
+ if (!jar) return null
36
+ try {
37
+ return normalize(jar.get(name, { doNotParse: true }))
38
+ } catch (error) {
39
+ return null
40
+ }
41
+ }
42
+
43
+ export function readParam(urlParams, keys) {
44
+ for (const key of keys) {
45
+ const value = normalize(urlParams?.get?.(key))
46
+ if (value) return { value, from: `url:${key}` }
47
+ }
48
+ for (const key of keys) {
49
+ const value = readLocal(key)
50
+ if (value) return { value, from: `local:${key}` }
51
+ }
52
+ for (const key of keys) {
53
+ const value = readCookie(key)
54
+ if (value) return { value, from: `cookie:${key}` }
55
+ }
56
+ return { value: null, from: 'none' }
57
+ }
58
+
59
+ export function readParamFromLocation(keys) {
60
+ const search = typeof window === 'undefined' ? '' : window.location.search
61
+ return readParam(new URLSearchParams(search), keys)
62
+ }
63
+
64
+ function report(sentry, name, medium, reason) {
65
+ // 去重必須在確定送得出去之後才登錄,否則早於 sentry 注入的那次失敗會把 fingerprint 佔走,
66
+ // 導致之後真正有 sentry 時被自己的去重擋掉、永遠不上報
67
+ if (!sentry?.captureMessage) return
68
+ const fingerprint = `${name}:${medium}:${reason}`
69
+ if (reportedOnce.has(fingerprint)) return
70
+ reportedOnce.add(fingerprint)
71
+ sentry?.captureMessage?.(`[ParamStore] ${medium} persist ${reason}: ${name}`, {
72
+ level: 'warning',
73
+ tags: { feature: 'url-param-fallback', param_key: name, storage_medium: medium, failure_reason: reason },
74
+ })
75
+ }
76
+
77
+ function clearParam(name) {
78
+ const result = { local: 'ok', cookie: 'ok', cleared: true }
79
+ try {
80
+ storage.remove(name)
81
+ } catch (error) {
82
+ result.local = 'throw'
83
+ }
84
+ const jar = cookieJar()
85
+ if (jar) {
86
+ try {
87
+ jar.remove(name, { path: '/' })
88
+ } catch (error) {
89
+ result.cookie = 'throw'
90
+ }
91
+ }
92
+ return result
93
+ }
94
+
95
+ export function writeParam(name, value, options = {}) {
96
+ const { sentry, allowClear = false } = options
97
+ const normalized = normalize(value)
98
+
99
+ if (normalized === null) {
100
+ return allowClear ? clearParam(name) : { local: 'skipped', cookie: 'skipped', skipped: true }
101
+ }
102
+
103
+ const result = { local: 'ok', cookie: 'ok' }
104
+
105
+ try {
106
+ storage.set(name, normalized, { path: '/', maxAge: PARAM_MAX_AGE })
107
+ } catch (error) {
108
+ result.local = 'throw'
109
+ }
110
+ if (result.local === 'ok' && readLocal(name) !== normalized) {
111
+ result.local = 'mismatch'
112
+ }
113
+
114
+ const jar = cookieJar()
115
+ if (!jar) {
116
+ result.cookie = 'unavailable'
117
+ } else {
118
+ try {
119
+ jar.set(name, normalized, {
120
+ path: '/',
121
+ maxAge: PARAM_MAX_AGE,
122
+ sameSite: 'lax',
123
+ secure: typeof window !== 'undefined' && window.location.protocol === 'https:',
124
+ })
125
+ } catch (error) {
126
+ result.cookie = 'throw'
127
+ }
128
+ if (result.cookie === 'ok' && readCookie(name) !== normalized) {
129
+ result.cookie = 'mismatch'
130
+ }
131
+ }
132
+
133
+ if (result.local !== 'ok') report(sentry, name, 'localStorage', result.local)
134
+ if (result.cookie !== 'ok') report(sentry, name, 'cookie', result.cookie)
135
+
136
+ return result
137
+ }
138
+
139
+ export default { PARAM_MAX_AGE, AC_KEYS, FC_KEYS, normalize, readParam, readParamFromLocation, writeParam }
@@ -13,7 +13,7 @@ export default {
13
13
  }
14
14
 
15
15
  const item = JSON.parse(itemStr)
16
- if (Object.prototype.hasOwnProperty.call(item, 'expiry') && Date.now() >= item.expiry) {
16
+ if (item.expiry && new Date().getTime() > item.expiry) {
17
17
  localStorage.removeItem(name)
18
18
  return null
19
19
  }
@@ -23,9 +23,8 @@ export default {
23
23
  set(name, value, options) {
24
24
  const item = { value }
25
25
 
26
- const maxAge = Number(options?.maxAge)
27
- if (Number.isFinite(maxAge)) {
28
- item.expiry = Date.now() + maxAge * 1000
26
+ if (options?.maxAge) {
27
+ item.expiry = new Date().getTime() + options.maxAge * 1000
29
28
  }
30
29
  try {
31
30
  localStorage.setItem(name, JSON.stringify(item))
@@ -1,9 +0,0 @@
1
- # Breaking Changes
2
-
3
- ## 2026-02-17
4
-
5
- - `Request.send` maintenance-mode behavior changed.
6
- - Before: when `isBlocked === true` and request URL was not `getConfig/get-config`, it returned `undefined` silently.
7
- - After: it throws `{ code: 'ERR_MAINTENANCE_BLOCKED', url }`.
8
- - Impact: callers that relied on `undefined` fallback must now handle `ERR_MAINTENANCE_BLOCKED` explicitly.
9
- - File: `src/request/request.js`
package/resetGitBranch.sh DELETED
@@ -1,101 +0,0 @@
1
- #!/bin/bash
2
-
3
- set -e
4
-
5
- # 切換到 master 分支
6
- git checkout master
7
- if [ $? -ne 0 ]; then
8
- echo "切換到 master 分支失敗"
9
- exit 1
10
- fi
11
-
12
- # 從遠端獲取最新的 master 分支更新
13
- git pull origin master
14
- if [ $? -ne 0 ]; then
15
- echo "從 origin 拉取 master 分支失敗"
16
- exit 1
17
- fi
18
-
19
- # 刪除本地的 dev 分支
20
- git branch -D dev
21
- if [ $? -ne 0 ]; then
22
- echo "刪除本地 dev 分支失敗"
23
- exit 1
24
- fi
25
-
26
- # 刪除遠端的 dev 分支
27
- git push origin --delete dev
28
- if [ $? -ne 0 ]; then
29
- echo "刪除遠端 dev 分支失敗"
30
- exit 1
31
- fi
32
-
33
- # 建立並切換到新的 dev 分支
34
- git checkout -b dev
35
- if [ $? -ne 0 ]; then
36
- echo "建立並切換到新的 dev 分支失敗"
37
- exit 1
38
- fi
39
-
40
- # 強制推送新的 dev 分支到遠端
41
- git push -f origin dev
42
- if [ $? -ne 0 ]; then
43
- echo "強制推送新的 dev 分支到遠端失敗"
44
- exit 1
45
- fi
46
-
47
- # 設定 dev 分支的上游分支為 origin/dev
48
- git branch --set-upstream-to=origin/dev dev
49
- if [ $? -ne 0 ]; then
50
- echo "設定 dev 分支的上游分支為 origin/dev 失敗"
51
- exit 1
52
- fi
53
-
54
- # 切換到 master
55
- git checkout master
56
- if [ $? -ne 0 ]; then
57
- echo "切換到 master 分支失敗"
58
- exit 1
59
- fi
60
-
61
- # 建立並切換到新的 qa 分支
62
- git checkout -b qa
63
- if [ $? -ne 0 ]; then
64
- echo "建立並切換到新的 qa 分支失敗"
65
- exit 1
66
- fi
67
-
68
- # 強制推送新的 qa 分支到遠端
69
- git push -f origin qa
70
- if [ $? -ne 0 ]; then
71
- echo "強制推送新的 qa 分支到遠端失敗"
72
- exit 1
73
- fi
74
-
75
- # 設定 qa 分支的上游分支為 origin/qa
76
- git branch --set-upstream-to=origin/qa qa
77
- if [ $? -ne 0 ]; then
78
- echo "設定 qa 分支的上游分支為 origin/qa 失敗"
79
- exit 1
80
- fi
81
-
82
- # 切換到 master
83
- git checkout master
84
- if [ $? -ne 0 ]; then
85
- echo "切換到 master 分支失敗"
86
- exit 1
87
- fi
88
-
89
- # 刪除所有已經合併到 master 分支的本地分支,除了 master 分支本身
90
- git branch --merged master | grep -v "^\* master$" | grep -vE "^[* ]*(dev|qa)$" | xargs -r git branch -d
91
- if [ $? -ne 0 ]; then
92
- echo "刪除已合併到 master 分支的本地分支失敗"
93
- exit 1
94
- fi
95
-
96
- # 刪除所有已經合併到 master 分支的遠端分支,除了 master 分支本身
97
- git branch -r --merged master | grep -v "master" | grep -vE "(dev|qa)$" | sed 's/origin\///' | xargs -r -I {} git push origin --delete {}
98
- if [ $? -ne 0 ]; then
99
- echo "刪除已合併到 master 分支的遠端分支失敗"
100
- exit 1
101
- fi