@jetthai/cuora 2.0.0-beta.1 → 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 -113
  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 -112
  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 +18 -28
  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 +2 -13
  70. package/src/machine/game_v2_1.js +42 -166
  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 -463
  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 -91
  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 -144
  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 -195
  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 -148
  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 -629
  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,541 +0,0 @@
1
- import { assign, createMachine } from 'xstate'
2
- import findLastIndex from 'lodash/findLastIndex.js'
3
- import payment from '../../api/payment.js'
4
- import user from '../../api/user.js'
5
-
6
- export default function (request) {
7
- const { appSecret } = request.config
8
- return createMachine(
9
- {
10
- id: 'withdraw_manual',
11
- predictableActionArguments: true,
12
- initial: 'loading',
13
- context: {
14
- mode: null,
15
- siteConfig: null,
16
- userInfo: null,
17
- paymentDetail: [],
18
- bindingPaymentInfo: {},
19
- bindingPaymentList: {},
20
- boundBanks: [],
21
- balance: null,
22
- charge: null,
23
- realAmount: null,
24
- applyId: null,
25
- currentBank: null,
26
- currentWithdrawLimit: null,
27
- targetWithdrawLimit: null,
28
- attachmentType: null, // null | 'withdraw' | 'pool'
29
- enableWithdrawAmount: 0,
30
- enableWithdraw: false,
31
- withdrawRules: [],
32
- withdrawRule: {},
33
- withdrawCheck: {},
34
- freeGameDetail: [],
35
- amount: null,
36
- calculation: null,
37
-
38
- // otp
39
- requestId: null,
40
- status: null,
41
- target: null,
42
- ttl: null,
43
- },
44
- states: {
45
- loading: {
46
- invoke: {
47
- src: 'fetchInitData',
48
- onDone: {
49
- target: 'pending',
50
- actions: ['setInitData', 'preset'],
51
- },
52
- onError: {
53
- target: 'fail',
54
- },
55
- },
56
- },
57
- pending: {
58
- on: {
59
- SET_MODE: {
60
- target: 'fetching',
61
- actions: 'setMode',
62
- },
63
- },
64
- },
65
- fetching: {
66
- invoke: {
67
- src: 'fetchWithdrawRules',
68
- onDone: {
69
- target: 'cash',
70
- actions: 'updateWithdrawCondition',
71
- },
72
- onError: {
73
- target: '#withdraw_manual.fail',
74
- },
75
- },
76
- },
77
- cash: {
78
- initial: 'checking',
79
- states: {
80
- checking: {
81
- always: [
82
- { target: 'inProcessing', cond: 'haveProcessing' },
83
- { target: 'unbound', cond: 'isBankNotBound' },
84
- { target: 'withdrawCheck' },
85
- ],
86
- },
87
- withdrawCheck: {
88
- invoke: {
89
- src: 'withdrawCheck',
90
- onDone: [
91
- {
92
- target: 'checkingWithdrawStatus',
93
- actions: assign((context, event) => {
94
- return {
95
- withdrawCheck: event.data,
96
- }
97
- }),
98
- },
99
- ],
100
- onError: {
101
- target: '#withdraw_manual.fail',
102
- },
103
- },
104
- },
105
- checkingWithdrawStatus: {
106
- always: [
107
- // 提款最低存款金額
108
- { target: 'notWithdrawMinDepositAmount', cond: 'isNotWithdrawMinDepositAmount' },
109
- // 提款冷卻時間
110
- { target: 'passWithdrawCooldownTime', cond: 'isPassWithdrawCooldownTime' },
111
- // 提款服務時間
112
- { target: 'withdrawServiceTime', cond: 'isNotWIthdrawServiceTime' },
113
- { target: 'notWithdrawable', cond: 'isNotWithdrawable' },
114
- { target: 'withdrawable' },
115
- ],
116
- },
117
- notWithdrawMinDepositAmount: {},
118
- passWithdrawCooldownTime: {},
119
- withdrawServiceTime: {},
120
- notWithdrawable: {},
121
- unbound: {
122
- // to bank_binding.js
123
- },
124
- inProcessing: {},
125
- withdrawable: {
126
- on: {
127
- SET_CURRENT_BANK: {
128
- actions: assign((context, event) => {
129
- return {
130
- currentBank: event.data,
131
- }
132
- }),
133
- },
134
- SET_ATTACHMENT_TYPE: {
135
- actions: 'setAttachmentType',
136
- },
137
- SUBMIT: [
138
- {
139
- target: 'pooling',
140
- cond: (context, event) => {
141
- const { amount, attachmentType } = context
142
- return attachmentType === 'pool' && amount > 0
143
- },
144
- },
145
- {
146
- target: 'submitting',
147
- cond: 'isAvailableAmount',
148
- },
149
- ],
150
- },
151
- },
152
- debouncing: {
153
- after: {
154
- 1000: [
155
- {
156
- target: 'calculating',
157
- cond: 'isAvailableAmount',
158
- },
159
- {
160
- target: 'withdrawable',
161
- },
162
- ],
163
- },
164
- },
165
- calculating: {
166
- invoke: {
167
- src: 'fetchCalculation',
168
- onDone: {
169
- target: 'withdrawable',
170
- actions: 'setCalculation',
171
- },
172
- onError: {
173
- target: 'withdrawable',
174
- },
175
- },
176
- },
177
- submitting: {
178
- invoke: {
179
- src: 'submitWithdraw',
180
- onDone: [
181
- {
182
- target: '#withdraw_manual.otp',
183
- actions: 'setOtp',
184
- cond: 'isOtpRequired',
185
- },
186
- {
187
- target: 'submitted',
188
- },
189
- ],
190
- onError: {
191
- target: 'withdrawable',
192
- },
193
- },
194
- },
195
- submitted: {
196
- entry: assign((context, event) => {
197
- const { applyId, balance, realAmount, charge } = event.data
198
- return { applyId, balance, realAmount, charge }
199
- }),
200
- invoke: {
201
- src: 'fetchPaymentData',
202
- onDone: {
203
- target: 'inProcessing',
204
- actions: 'setPaymentData',
205
- },
206
- onError: {
207
- target: '#withdraw_manual.fail',
208
- },
209
- },
210
- },
211
- pooling: {
212
- invoke: {
213
- src: 'pool',
214
- onDone: { target: 'pooled' },
215
- onError: {
216
- target: 'withdrawable',
217
- },
218
- },
219
- },
220
- pooled: {},
221
- },
222
- on: {
223
- SET_AMOUNT: {
224
- actions: ['setAmount', 'clearCalculation'],
225
- },
226
- CALCULATE: {
227
- target: '.debouncing',
228
- },
229
- },
230
- },
231
- otp: {
232
- type: 'parallel',
233
- states: {
234
- countdown: {
235
- after: {
236
- 1000: {
237
- target: 'countdown',
238
- actions: 'decreaseTtl',
239
- cond: (context) => context.ttl > 0,
240
- },
241
- },
242
- },
243
- verification: {
244
- initial: 'idle',
245
- states: {
246
- idle: {
247
- on: {
248
- ACKNOWLEDGE: {
249
- target: 'acknowledging',
250
- },
251
- RESET_OTP: {
252
- target: 'reset',
253
- },
254
- BACK: [
255
- {
256
- target: '#withdraw_manual.cash.withdrawable',
257
- },
258
- ],
259
- },
260
- },
261
- acknowledging: {
262
- invoke: {
263
- src: 'acknowledge',
264
- onDone: [
265
- {
266
- target: '#withdraw_manual.cash.submitted',
267
- },
268
- ],
269
- onError: {
270
- target: 'idle',
271
- },
272
- },
273
- },
274
- reset: {
275
- invoke: {
276
- src: 'resetOtp',
277
- onDone: {
278
- target: 'idle',
279
- actions: 'setVerificationData',
280
- },
281
- onError: { target: 'idle' },
282
- },
283
- },
284
- },
285
- },
286
- },
287
- },
288
- fail: {},
289
- },
290
- on: {
291
- REFRESH: {
292
- target: 'loading',
293
- },
294
- },
295
- },
296
- {
297
- actions: {
298
- setInitData: assign((context, event) => {
299
- const { bindingPaymentList = {}, bindingPaymentInfo = {} } = event.data
300
- const toBeUsed = new Set(['bankList', 'cryptoList', 'ewalletList'])
301
- const combinedData = []
302
- const types = Object.keys(bindingPaymentInfo)
303
- for (let i = 0; i < types.length; i++) {
304
- const type = types[i]
305
- if (!toBeUsed.has(type)) {
306
- continue
307
- }
308
- const list = bindingPaymentInfo[type]
309
- if (Array.isArray(list)) {
310
- combinedData.push(...list)
311
- } else if (list !== undefined) {
312
- combinedData.push(list)
313
- }
314
- }
315
- return { bindingPaymentList, bindingPaymentInfo, boundBanks: combinedData, currentBank: combinedData[0] }
316
- }),
317
- preset: assign((context, event) => {
318
- return {
319
- attachmentType: 'withdraw',
320
- }
321
- }),
322
- setMode: assign((context, event) => {
323
- return {
324
- mode: event.data,
325
- }
326
- }),
327
- updateWithdrawCondition: assign((context, event) => {
328
- const { enableWithdraw, enableWithdrawAmount, currentWithdrawLimit, targetWithdrawLimit, balance, freeGameDetail, freeGameExpired } =
329
- event.data
330
- const withdrawRules = event.data?.rules || []
331
- const rules = withdrawRules.filter((rule) => rule.maxWithdrawAmount > 0)
332
- const lastMatchedIndex = findLastIndex(rules, (rule) => balance >= rule.greaterEqualThen)
333
-
334
- let maxWithdrawAmount = 0
335
-
336
- if (lastMatchedIndex > -1) {
337
- rules[lastMatchedIndex].match = true
338
- maxWithdrawAmount = rules[lastMatchedIndex].maxWithdrawAmount
339
- } else if (rules.length > 0) {
340
- maxWithdrawAmount = rules[0].maxWithdrawAmount
341
- } else {
342
- maxWithdrawAmount = balance
343
- }
344
-
345
- return {
346
- balance,
347
- currentWithdrawLimit,
348
- targetWithdrawLimit,
349
- maxWithdrawAmount,
350
- enableWithdrawAmount: +enableWithdrawAmount,
351
- enableWithdraw,
352
- withdrawRules,
353
- freeGameDetail,
354
- freeGameExpired,
355
- }
356
- }),
357
- setWithdrawRulePreview: assign((context, event) => {
358
- return {
359
- withdrawRule: event.data,
360
- }
361
- }),
362
- setPaymentData: assign((context, event) => {
363
- const { paymentDetail } = event.data
364
- return { paymentDetail }
365
- }),
366
- setOtp: assign((context, event) => {
367
- const { requestId, status, target, ttl } = event.data
368
- return {
369
- requestId,
370
- status,
371
- target,
372
- ttl,
373
- }
374
- }),
375
- decreaseTtl: assign((context, evnet) => {
376
- const second = context.ttl
377
- return {
378
- ttl: Math.max(second - 1, 0),
379
- }
380
- }),
381
- setVerificationData: assign((context, event) => {
382
- const { requestId, ttl, target } = event.data
383
- return {
384
- requestId,
385
- ttl,
386
- target,
387
- }
388
- }),
389
- setAttachmentType: assign((context, event) => {
390
- return {
391
- attachmentType: event.data,
392
- }
393
- }),
394
- setCalculation: assign((context, event) => {
395
- // V2接口轉換中回傳的資料結構不同
396
- const { data } = event.data
397
- if (data) {
398
- return {
399
- calculation: data,
400
- }
401
- } else {
402
- return {
403
- calculation: event.data,
404
- }
405
- }
406
- }),
407
- clearCalculation: assign((context, event) => {
408
- return {
409
- calculation: null,
410
- }
411
- }),
412
- setAmount: assign((context, event) => {
413
- return {
414
- amount: event.data,
415
- }
416
- }),
417
- },
418
- guards: {
419
- isAvailableAmount: (context, event) => {
420
- const { paymentDetail, currentBank, amount, userInfo } = context
421
- const { minimum = 0, maximum = 0 } = paymentDetail?.[0] || {}
422
- const { balance = 0 } = userInfo || {}
423
- const lastMax = Math.min(parseFloat(balance), maximum)
424
- return !!currentBank && amount > 0 && minimum <= amount && amount <= lastMax
425
- },
426
- hasAttachmentType: (context, event) => {
427
- return ['withdraw', 'pool'].includes(context.attachmentType)
428
- },
429
- haveProcessing: (context, event) => {
430
- return (context.paymentDetail?.[0]?.processing || []).length > 0
431
- },
432
- isBankNotBound: (context, event) => {
433
- return !context.boundBanks?.length
434
- },
435
- isConvertible: (context, event) => {
436
- const { enableWithdraw, freeGameDetail } = context
437
- const isFreeGame = freeGameDetail?.length > 0
438
- if (isFreeGame) {
439
- return freeGameDetail[0]?.freeGameCount === freeGameDetail[0]?.freeGameUsedCount
440
- } else {
441
- return enableWithdraw
442
- }
443
- },
444
- isNotWithdrawable: (context, event) => {
445
- const { balance, enableWithdraw, paymentDetail } = context
446
- const minWithdrawAmount = paymentDetail[0]?.minimum || 0
447
- return !enableWithdraw || balance < minWithdrawAmount
448
- },
449
- isOtpRequired: (context, event) => {
450
- return event.data?.status === 'otp-verifying'
451
- },
452
- isNotWithdrawMinDepositAmount: (context, event) => {
453
- const { withdrawCheck } = context
454
- return !withdrawCheck?.passDepositeLimit
455
- },
456
- isPassWithdrawCooldownTime: (context, event) => {
457
- const { withdrawCheck } = context
458
- return !withdrawCheck?.passWithdrawCooldownTime
459
- },
460
- isNotWIthdrawServiceTime: (context, event) => {
461
- const { withdrawCheck } = context
462
- return !withdrawCheck?.withdrawInServiceTime
463
- },
464
- },
465
- services: {
466
- fetchInitData: async (context, event) => {
467
- const [bindingPaymentList = {}, bindingPaymentInfo = {}] = await Promise.all([
468
- request.send(payment.getBindingPaymentList({ appSecret })),
469
- request.send(payment.getBindingPaymentInfo({ appSecret })),
470
- ])
471
- return { bindingPaymentList, bindingPaymentInfo }
472
- },
473
- fetchPaymentData: async (context, event) => {
474
- const paymentDetail = await request.send(payment.getPaymentDetail({ transferType: 'WITHDRAW' }))
475
- return { paymentDetail }
476
- },
477
- fetchWithdrawRules: async (context, event) => {
478
- const { mode } = context
479
- return await request.send(payment.getDoubleWalletWithdrawRule({ walletType: mode }))
480
- },
481
- fetchWithdrawRulePreview: async (context, event) => {
482
- const data = await request.send(payment.getWithdrawRulePreview({ applyType: 'giveup' }))
483
- return data
484
- },
485
- fetchCalculation: async (context, event) => {
486
- const { paymentDetail, currentBank, amount } = context
487
- const { method } = paymentDetail?.[0] || {}
488
- const { cryptoCurrency } = currentBank || {}
489
- return await request.send(payment.getCryptoWithdrawExpectedResult({ method, amount, cryptoCurrency }))
490
- },
491
- submitWithdraw: async (context, event) => {
492
- const { currentBank, amount } = context
493
- const { method } = context.paymentDetail[0]
494
- const { bindingType } = currentBank || {}
495
-
496
- let branchTemp = ''
497
- if (bindingType === 'BANK' && !['GCASH', 'PAYM', 'PIX'].includes(currentBank.bankCode)) {
498
- branchTemp = currentBank.branch
499
- }
500
-
501
- return await request.send(
502
- payment.submitWithdrawTransactionManual({
503
- method,
504
- amount,
505
- applyerBankCode: currentBank.bankCode || currentBank.walletCode,
506
- applyerAccountNumber: currentBank.accountNumber,
507
- applyerIfscCode: currentBank.ifscCode,
508
- branch: branchTemp,
509
- holderName: currentBank.holderName,
510
- cryptoCurrency: currentBank.cryptoCurrency,
511
- cryptoNetwork: currentBank.cryptoNetwork,
512
- targetAddress: currentBank.cryptoAddress,
513
- })
514
- )
515
- },
516
- convertFreeCredit: async (context, event) => {
517
- return await request.send(payment.convertFreeCredit({ exchangeType: 1 }))
518
- },
519
- resetOtp: async (context, event) => {
520
- const { requestId, target } = context
521
- return await request.send(user.otpReset({ requestId, target }))
522
- },
523
- acknowledge: async (context, event) => {
524
- const { requestId, target } = context
525
- const code = event.data
526
- return await request.send(user.otpAcknowledge({ requestId, target, code }))
527
- },
528
- pool: async (context, event) => {
529
- const { amount } = context
530
- return await request.send(payment.restore({ amount }))
531
- },
532
- giveUp: async (context, event) => {
533
- return await request.send(payment.giveUp())
534
- },
535
- withdrawCheck: async (context, event) => {
536
- return await request.send(payment.withdrawCheck())
537
- },
538
- },
539
- }
540
- )
541
- }
@@ -1,60 +0,0 @@
1
- import uniqBy from 'lodash/uniqBy.js'
2
- import { load, defaultEndpoint } from '../lib/fingerprint_v3_11_12.js'
3
-
4
- const reg = /fnapi\d*/
5
-
6
- const getDeviceToken = async ({ fpToken, sentry, hosts, enable = true, loader = load }) => {
7
- if (!enable) {
8
- return
9
- }
10
-
11
- let dt, endpoints
12
- try {
13
- const hostList = Array.isArray(hosts) ? hosts : []
14
- endpoints = uniqBy(
15
- hostList.map((host) => host.replace(reg, 'fp')),
16
- (url) => url
17
- )
18
-
19
- const fp = await loader({ endpoint: [...endpoints, defaultEndpoint] })
20
- const result = await fp.get({ timeout: 30000 })
21
- dt = result.visitorId
22
-
23
- if (!dt) {
24
- throw new Error('[Device Token] No token from FingerprintJS.')
25
- }
26
-
27
- sentry?.setTag('dt', dt)
28
- } catch (error) {
29
- console.error('[Device Token]', `${dt} from ${endpoints}`, error)
30
- sentry?.captureException(error)
31
- } finally {
32
- return dt
33
- }
34
- }
35
-
36
- // 重試機制,最多嘗試 maxRetries 次,每次間隔 intervalMs 毫秒
37
- const getDeviceTokenWithRetry = async ({ fpToken, sentry, hosts, enable = true, maxRetries = 3, intervalMs = 1000, loader = load }) => {
38
- if (!enable) {
39
- return
40
- }
41
- // 設置幾秒後重試
42
- const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
43
- // 設定重試次數
44
- for (let attempt = 1; attempt <= maxRetries; attempt++) {
45
- try {
46
- const deviceToken = await getDeviceToken({ fpToken, sentry, hosts, enable, loader })
47
- if (deviceToken) return deviceToken
48
- throw new Error('No device token received')
49
- } catch (error) {
50
- // 若失敗則等待intervalMs後重試,最多重試maxRetries次
51
- if (attempt < maxRetries) {
52
- await delay(intervalMs)
53
- } else {
54
- throw error
55
- }
56
- }
57
- }
58
- }
59
-
60
- export { getDeviceToken, getDeviceTokenWithRetry }
package/src/util/math.js DELETED
@@ -1,4 +0,0 @@
1
- export function max(...args) {
2
- const casted = args.map((arg) => arg || 0)
3
- return Math.max(...casted)
4
- }
@@ -1,69 +0,0 @@
1
- import test from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import api from '../src/api/index.js'
5
-
6
- test('auth.register builds querystring and payload correctly', () => {
7
- const req = api.auth.register({
8
- channel: 'web',
9
- subchannel: 'sub',
10
- ac: 'ac1',
11
- fc: null,
12
- dt: 'dt1',
13
- username: 'u1',
14
- password: 'p1',
15
- })
16
-
17
- assert.equal(req.method, 'post')
18
- assert.equal(req.url, 'register?channel=web&subchannel=sub&ac=ac1')
19
- assert.equal(req.params.dt, 'dt1')
20
- assert.equal(req.params.username, 'u1')
21
- assert.equal(req.isPublic, true)
22
- })
23
-
24
- test('common API endpoints keep expected paths', () => {
25
- assert.equal(api.common.getConfig({ appSecret: 's' }).url, 'getConfig')
26
- assert.equal(api.common.broadcast({ appSecret: 's' }).url, 'broadcast')
27
- assert.equal(api.common.sendPixel({ appSecret: 's' }).method, 'post')
28
- })
29
-
30
- test('game search trace and replay endpoints map params', () => {
31
- const trace = api.game.setGameSearchTrace({
32
- traceId: 't1',
33
- tagId: 'tag',
34
- gameCode: 'g1',
35
- query: 'q',
36
- })
37
- assert.equal(trace.url, 'game/search/trace')
38
- assert.equal(trace.method, 'post')
39
- assert.equal(trace.params.traceId, 't1')
40
-
41
- const replay = api.game.getGameReplayInfo({ providerId: 'P', seqNo: 'S', lang: 'en', appSecret: 'sec' })
42
- assert.equal(replay.url, 'game/gameReplay')
43
- assert.equal(replay.isPublic, true)
44
- })
45
-
46
- test('payment APIs build dynamic method paths', () => {
47
- assert.equal(api.payment.getBankList('crypto').url, 'payment/v2/crypto/getBankList')
48
- assert.equal(api.payment.checkTransaction('manual').url, 'payment/v2/manual/checkTransaction')
49
- assert.equal(api.payment.getDepositExpectedResult({ method: 'manual', amount: 10 }).url, 'payment/v2/manual/expected/result')
50
- })
51
-
52
- test('user and otp APIs keep security-sensitive paths', () => {
53
- assert.equal(api.user.passwordV2RecoveryInit({ provider: 'account', username: 'u', appSecret: 's' }).url, 'recovery/v2/initiate')
54
- assert.equal(api.user.verifyV2Initiate({ strategy: 'phone' }).url, '/verify/v2/initiate')
55
-
56
- const verify = api.otp.verification({ requestId: 'r1', code: '1234' })
57
- assert.equal(verify.url, 'otp-verification-point/verify')
58
- assert.equal(verify.method, 'POST')
59
- })
60
-
61
- test('activity APIs retain public/private intent', () => {
62
- const list = api.activity.getActivityList({ appSecret: 's' })
63
- assert.equal(list.url, 'activities/list')
64
- assert.equal(list.isPublic, true)
65
-
66
- const detail = api.activity.getActivityDetail({ activityNo: 1, appSecret: 's' })
67
- assert.equal(detail.url, 'activities')
68
- assert.equal(detail.isPublic, undefined)
69
- })
@@ -1,18 +0,0 @@
1
- import test from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import api from '../src/api/index.js'
5
- import { callWithFallback } from './helpers.js'
6
-
7
- for (const [moduleName, moduleApi] of Object.entries(api)) {
8
- test(`api contract: ${moduleName} endpoints return request descriptor`, () => {
9
- assert.equal(typeof moduleApi, 'object')
10
-
11
- for (const [fnName, endpointFactory] of Object.entries(moduleApi)) {
12
- assert.equal(typeof endpointFactory, 'function', `${moduleName}.${fnName} should be a function`)
13
- const requestDescriptor = callWithFallback(endpointFactory)
14
- assert.equal(typeof requestDescriptor.url, 'string', `${moduleName}.${fnName} should return url`)
15
- assert.equal(typeof requestDescriptor.method, 'string', `${moduleName}.${fnName} should return method`)
16
- }
17
- })
18
- }