@jetthai/cuora 1.1.488 → 2.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/.husky/pre-commit +3 -1
  2. package/BREAKING_CHANGES.md +9 -0
  3. package/CHANGELOG.md +3 -316
  4. package/README.md +15 -299
  5. package/package.json +5 -5
  6. package/resetGitBranch.sh +101 -0
  7. package/src/api/account.js +1 -0
  8. package/src/api/activity.js +39 -24
  9. package/src/api/auth.js +36 -5
  10. package/src/api/common.js +3 -5
  11. package/src/api/game.js +10 -0
  12. package/src/api/payment.js +55 -17
  13. package/src/api/user.js +16 -10
  14. package/src/index.js +2 -2
  15. package/src/lib/fingerprint_v3_11_12.js +11433 -0
  16. package/src/machine/activity/activity.js +213 -0
  17. package/src/machine/activity/activity_cash.js +36 -84
  18. package/src/machine/activity/cash_rain_activity.js +1 -0
  19. package/src/machine/activity/continue_deposit_activity.js +1 -0
  20. package/src/machine/activity/deposit_activity.js +1 -0
  21. package/src/machine/activity/diamond_shop_activity_cash.js +8 -0
  22. package/src/machine/activity/diamond_shop_activity_fc.js +197 -0
  23. package/src/machine/activity/diamond_shop_activity_vn.js +179 -0
  24. package/src/machine/activity/fafafa_activity.js +11 -0
  25. package/src/machine/activity/friend_invite_friends_activity.js +7 -8
  26. package/src/machine/activity/index.js +12 -0
  27. package/src/machine/activity/instant_rebate_activity.js +1 -0
  28. package/src/machine/activity/invite_friends_activity.js +115 -0
  29. package/src/machine/activity/jackpot.js +1 -0
  30. package/src/machine/activity/mini_game_activity.js +69 -0
  31. package/src/machine/activity/otp_verified_activity.js +1 -0
  32. package/src/machine/activity/ranking_activity.js +1 -0
  33. package/src/machine/activity/return_bonus_activity.js +155 -0
  34. package/src/machine/activity/roulette_activity_v2.js +1 -0
  35. package/src/machine/activity/sign_in_activity.js +1 -0
  36. package/src/machine/activity/sign_in_monthly_activity.js +2 -1
  37. package/src/machine/activity/specify_bets_activity.js +1 -0
  38. package/src/machine/activity/specify_turnover_activity.js +1 -0
  39. package/src/machine/activity/time_bomb_activity.js +1 -0
  40. package/src/machine/activity/vip_card_activity.js +1 -0
  41. package/src/machine/auth.js +112 -149
  42. package/src/machine/auth_otp_v2.js +178 -0
  43. package/src/machine/auth_otp_v3.js +22 -64
  44. package/src/machine/bank_binding.js +3 -2
  45. package/src/machine/bank_binding_amb.js +146 -0
  46. package/src/machine/bonus.js +76 -0
  47. package/src/machine/common.js +98 -14
  48. package/src/machine/deposit/amb.js +93 -0
  49. package/src/machine/deposit/crypto_bank.js +340 -0
  50. package/src/machine/deposit/crypto_bank_cash.js +35 -20
  51. package/src/machine/deposit/crypto_qrcode.js +158 -0
  52. package/src/machine/deposit/crypto_qrcode_cash.js +64 -26
  53. package/src/machine/deposit/crypto_way.js +253 -0
  54. package/src/machine/deposit/crypto_way_cash.js +37 -48
  55. package/src/machine/deposit/deposit_fc.js +272 -0
  56. package/src/machine/deposit/direct.js +311 -0
  57. package/src/machine/deposit/direct_cash.js +10 -8
  58. package/src/machine/deposit/float.js +375 -0
  59. package/src/machine/deposit/index.js +28 -0
  60. package/src/machine/deposit/krway.js +152 -0
  61. package/src/machine/deposit/loadcard_cash.js +32 -14
  62. package/src/machine/deposit/loadcard_vn.js +352 -0
  63. package/src/machine/deposit/manual_cash.js +11 -8
  64. package/src/machine/deposit/manual_vn.js +459 -0
  65. package/src/machine/deposit/qrcode_cash.js +32 -15
  66. package/src/machine/deposit/qrcode_v2.js +339 -0
  67. package/src/machine/deposit/usdt.js +163 -0
  68. package/src/machine/deposit/usdt_cash.js +15 -1
  69. package/src/machine/deposit/virtual_bank_cash.js +12 -13
  70. package/src/machine/deposit/virtual_bank_vn.js +270 -0
  71. package/src/machine/deposit/vpay.js +374 -0
  72. package/src/machine/error.js +1 -7
  73. package/src/machine/game_betslip.js +1 -0
  74. package/src/machine/game_favorite_v2.js +1 -0
  75. package/src/machine/game_hot_new.js +80 -0
  76. package/src/machine/game_info.js +13 -1
  77. package/src/machine/game_replay.js +47 -0
  78. package/src/machine/game_search_cash.js +1 -0
  79. package/src/machine/game_search_v2.js +402 -0
  80. package/src/machine/game_v2_1.js +126 -39
  81. package/src/machine/honor_board.js +133 -0
  82. package/src/machine/honor_board_cash.js +28 -22
  83. package/src/machine/inbox.js +105 -43
  84. package/src/machine/index.js +32 -0
  85. package/src/machine/leaderboard.js +12 -8
  86. package/src/machine/merge.js +58 -0
  87. package/src/machine/navbar.js +3 -1
  88. package/src/machine/payment_data.js +87 -0
  89. package/src/machine/promotions.js +163 -0
  90. package/src/machine/ranking.js +30 -45
  91. package/src/machine/reward.js +256 -0
  92. package/src/machine/reward_cash.js +42 -2
  93. package/src/machine/reward_fc.js +99 -0
  94. package/src/machine/roulette_v2.js +11 -14
  95. package/src/machine/setting.js +1 -0
  96. package/src/machine/side.js +160 -0
  97. package/src/machine/side_cash.js +3 -3
  98. package/src/machine/side_v2.js +223 -0
  99. package/src/machine/user_info.js +1 -0
  100. package/src/machine/user_photo.js +1 -0
  101. package/src/machine/user_reset_password.js +14 -0
  102. package/src/machine/user_sign_up.js +61 -46
  103. package/src/machine/vip_table.js +58 -0
  104. package/src/machine/websocket.js +349 -374
  105. package/src/machine/welcome.js +111 -0
  106. package/src/machine/withdraw/index.js +6 -0
  107. package/src/machine/withdraw/withdraw_crypto_cash.js +328 -0
  108. package/src/machine/withdraw/withdraw_krway.js +223 -0
  109. package/src/machine/withdraw/withdraw_manual.js +541 -0
  110. package/src/machine/withdraw/withdraw_manual_cash.js +39 -59
  111. package/src/request/config.js +0 -2
  112. package/src/request/request.js +60 -124
  113. package/src/util/constant.js +2 -6
  114. package/src/util/deviceToken.js +60 -0
  115. package/src/util/index.js +4 -2
  116. package/src/util/math.js +4 -0
  117. package/src/util/storage.js +4 -3
  118. package/test/api.behavior.test.js +69 -0
  119. package/test/api.contract.test.js +18 -0
  120. package/test/config.test.js +27 -0
  121. package/test/deviceToken.test.js +139 -0
  122. package/test/helpers.coverage.test.js +11 -0
  123. package/test/helpers.js +91 -0
  124. package/test/index.exports.test.js +14 -0
  125. package/test/machine.activity.core.coverage.test.js +337 -0
  126. package/test/machine.activity.gap.coverage.test.js +252 -0
  127. package/test/machine.activity.more.coverage.test.js +180 -0
  128. package/test/machine.activity_plus_and_binding_amb.coverage.test.js +201 -0
  129. package/test/machine.activity_timer_bonus.coverage.test.js +136 -0
  130. package/test/machine.activity_welcome.low.coverage.test.js +211 -0
  131. package/test/machine.amb_rewardfc_websocket.more.coverage.test.js +201 -0
  132. package/test/machine.auth.coverage.test.js +215 -0
  133. package/test/machine.bank_binding.test.js +143 -0
  134. package/test/machine.binding_otp_krway.coverage.test.js +223 -0
  135. package/test/machine.contract.test.js +50 -0
  136. package/test/machine.crypto_bank.coverage.test.js +270 -0
  137. package/test/machine.crypto_way.coverage.test.js +108 -0
  138. package/test/machine.crypto_way_cash.coverage.test.js +114 -0
  139. package/test/machine.definition.test.js +137 -0
  140. package/test/machine.deposit.manual.coverage.test.js +365 -0
  141. package/test/machine.deposit_fc.coverage.test.js +126 -0
  142. package/test/machine.direct.coverage.test.js +96 -0
  143. package/test/machine.direct_cash.coverage.test.js +108 -0
  144. package/test/machine.error.coverage.test.js +37 -0
  145. package/test/machine.events.test.js +126 -0
  146. package/test/machine.favorite_jackpot.coverage.test.js +82 -0
  147. package/test/machine.float.coverage.test.js +136 -0
  148. package/test/machine.flow.test.js +226 -0
  149. package/test/machine.game_hot_new_vip_table.coverage.test.js +105 -0
  150. package/test/machine.game_search_cash.coverage.test.js +155 -0
  151. package/test/machine.game_search_v2.test.js +199 -0
  152. package/test/machine.game_user_profile.coverage.test.js +100 -0
  153. package/test/machine.honor_board.test.js +133 -0
  154. package/test/machine.inbox.common.coverage.test.js +304 -0
  155. package/test/machine.loadcard_cash.coverage.test.js +101 -0
  156. package/test/machine.loadcard_vn.coverage.test.js +122 -0
  157. package/test/machine.misc.coverage.test.js +361 -0
  158. package/test/machine.more2.coverage.test.js +261 -0
  159. package/test/machine.options.execution.test.js +272 -0
  160. package/test/machine.priority.coverage.test.js +603 -0
  161. package/test/machine.qrcode_cash.coverage.test.js +107 -0
  162. package/test/machine.qrcode_v2.coverage.test.js +121 -0
  163. package/test/machine.regression.test.js +82 -0
  164. package/test/machine.roulette_v2.test.js +142 -0
  165. package/test/machine.side_reward_reset.coverage.test.js +220 -0
  166. package/test/machine.targeted.coverage.test.js +313 -0
  167. package/test/machine.usdt.coverage.test.js +95 -0
  168. package/test/machine.usdt_cash.coverage.test.js +73 -0
  169. package/test/machine.vip_card_activity.test.js +114 -0
  170. package/test/machine.virtual_bank_cash.coverage.test.js +105 -0
  171. package/test/machine.virtual_bank_vn.coverage.test.js +105 -0
  172. package/test/machine.vpay.coverage.test.js +142 -0
  173. package/test/machine.withdraw_crypto_cash.coverage.test.js +166 -0
  174. package/test/machine.withdraw_krway.coverage.test.js +123 -0
  175. package/test/machine.withdraw_manual.coverage.test.js +185 -0
  176. package/test/machine.withdraw_manual_cash.coverage.test.js +123 -0
  177. package/test/request.test.js +325 -0
  178. package/test/util.storage.errors.test.js +47 -0
  179. package/test/util.test.js +41 -0
  180. package/.claude/commands/sync-ai-prompts.md +0 -93
  181. package/.claude/settings.local.json +0 -23
  182. package/.github/copilot-instructions.md +0 -448
  183. package/.husky/post-checkout +0 -32
  184. package/.husky/pre-push +0 -36
  185. package/AGENTS.md +0 -448
  186. package/AI_PROMPT_SOURCE.md +0 -446
  187. package/CLAUDE.md +0 -448
  188. package/GEMINI.md +0 -448
  189. package/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +0 -1003
  190. package/docs/kibana/play-providerId-error.md +0 -202
  191. package/docs/kibana/play-selectedWalletType.md +0 -1
  192. package/docs/kibana/play-selectedWalletType_2.md +0 -1
  193. package/docs/kibana/play-selectedWalletType_analysis.md +0 -565
  194. package/docs/my-claude/feat-sharon-JT-1790247240-socket/branch-transfer.md +0 -14
  195. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-preparation.json +0 -40
  196. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-verification.md +0 -41
  197. package/docs/my-claude/feat-sharon-JT-1790247240-socket/implementation-ledger.md +0 -87
  198. package/docs/my-claude/feat-sharon-JT-1790247240-socket/module-report.md +0 -73
  199. package/docs/my-claude/feat-sharon-JT-1790247240-socket/plan.md +0 -309
  200. package/docs/my-claude/feat-sharon-JT-1790247240-socket/test-cases.md +0 -245
  201. package/docs/my-claude/feat-sharon-JT-1791180540-onesignal/transfer.md +0 -9
  202. package/scripts/auto-version.js +0 -68
  203. package/scripts/auto-version.sh +0 -33
  204. package/scripts/branch-auto-npm-publish.js +0 -29
  205. package/scripts/check-version.sh +0 -36
  206. package/scripts/clean-tags.sh +0 -84
  207. package/src/util/amount.js +0 -8
  208. package/src/util/err998SentryExtra.js +0 -26
  209. package/src/util/paramStore.js +0 -139
  210. package/src/util/socketPolicy.js +0 -57
  211. package/test/auth_otp_v3.test.js +0 -323
  212. package/tests/websocket.test.mjs +0 -779
@@ -0,0 +1,160 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import api from '../api/game.js'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'side',
8
+ predictableActionArguments: true,
9
+ initial: 'preparing',
10
+ context: {
11
+ menu: {},
12
+ room: null,
13
+ roomHistory: [],
14
+ },
15
+ states: {
16
+ preparing: {
17
+ invoke: {
18
+ src: 'getRoomItems',
19
+ onDone: {
20
+ target: 'room',
21
+ actions: 'makeMenu',
22
+ },
23
+ onError: {
24
+ target: 'room',
25
+ },
26
+ },
27
+ },
28
+ room: {
29
+ initial: 'home',
30
+ states: {
31
+ home: {
32
+ entry: createSideAction('home'),
33
+ },
34
+ favorite: {
35
+ entry: createSideAction('favorite'),
36
+ },
37
+ hot: {
38
+ entry: createSideAction('hot'),
39
+ },
40
+ new: {
41
+ entry: createSideAction('new'),
42
+ },
43
+ slot: {
44
+ entry: createSideAction('slot'),
45
+ },
46
+ fish: {
47
+ entry: createSideAction('fish'),
48
+ },
49
+ arcade: {
50
+ entry: createSideAction('arcade'),
51
+ },
52
+ table: {
53
+ entry: createSideAction('table'),
54
+ },
55
+ search: {},
56
+ history: {
57
+ type: 'history',
58
+ },
59
+ },
60
+ },
61
+ feature: {
62
+ on: {
63
+ RETURN: { target: 'room.history' },
64
+ CLICK_HOT: { target: 'room.hot', actions: 'resetRoomHistory' },
65
+ CLICK_NEW: { target: 'room.new', actions: 'resetRoomHistory' },
66
+ },
67
+ },
68
+ category: {
69
+ on: {
70
+ RETURN: { target: 'room.history' },
71
+ CLICK_SLOT: { target: 'room.slot', actions: 'resetRoomHistory' },
72
+ CLICK_FISH: { target: 'room.fish', actions: 'resetRoomHistory' },
73
+ CLICK_ARCADE: { target: 'room.arcade', actions: 'resetRoomHistory' },
74
+ CLICK_TABLE: { target: 'room.table', actions: 'resetRoomHistory' },
75
+ },
76
+ },
77
+ },
78
+ on: {
79
+ CLICK_HOME: { target: 'room.home', actions: 'resetRoomHistory' },
80
+ CLICK_FAVORITE: { target: 'room.favorite', actions: 'resetRoomHistory' },
81
+ CLICK_FEATURE: { target: 'feature' },
82
+ CLICK_CATEGORY: { target: 'category' },
83
+ CLICK_SEARCH: { target: 'room.search' },
84
+ FORWARD_ROOM: { actions: 'forwardRoom' },
85
+ BACKWARD_ROOM: { actions: 'backwardRoom' },
86
+ },
87
+ },
88
+ {
89
+ actions: {
90
+ makeMenu: assign((context, event) => {
91
+ const { list = [] } = event.data
92
+ const map = {
93
+ home: ['SYSTEM_PERSONAL', 'SYSTEM_INDEX_LIST'],
94
+ favorite: 'SYSTEM_MY_FAVORITE',
95
+ hot: 'SYSTEM_TOP_GAME',
96
+ new: 'SYSTEM_NEW_GAME',
97
+ slot: 'SYSTEM_BIG_CATEGORY_SLOT',
98
+ fish: 'SYSTEM_BIG_CATEGORY_FISHING',
99
+ arcade: 'SYSTEM_BIG_CATEGORY_ARCADE',
100
+ table: 'SYSTEM_BIG_CATEGORY_TABLECARD',
101
+ }
102
+ const menu = {}
103
+ const categoryMap = new Map(list.map((item) => [item.category, item]))
104
+ Object.keys(map).forEach((key) => {
105
+ if (Array.isArray(map[key])) {
106
+ // 若是陣列則依順序決定館別內容
107
+ map[key].some((val) => {
108
+ const category = categoryMap.get(val)
109
+ if (category) {
110
+ menu[key] = category
111
+ return true
112
+ } else {
113
+ return false
114
+ }
115
+ })
116
+ } else {
117
+ menu[key] = categoryMap.get(map[key])
118
+ }
119
+ })
120
+ return { menu }
121
+ }),
122
+ forwardRoom: assign((context, event) => {
123
+ return {
124
+ room: event.data,
125
+ roomHistory: [...context.roomHistory, context.room],
126
+ }
127
+ }),
128
+ backwardRoom: assign((context, event) => {
129
+ const { roomHistory } = context
130
+ return {
131
+ room: roomHistory.slice(-1)[0],
132
+ roomHistory: roomHistory.slice(0, -1),
133
+ }
134
+ }),
135
+ resetRoomHistory: assign((context, event) => {
136
+ return {
137
+ roomHistory: [],
138
+ }
139
+ }),
140
+ },
141
+ services: {
142
+ getRoomItems: async (context, event) => {
143
+ return await request.send(api.getGameCategory({ id: context.room?.id }))
144
+ },
145
+ },
146
+ }
147
+ )
148
+ }
149
+
150
+ function createSideAction(name) {
151
+ return assign((context, event) => {
152
+ const menuItem = context.menu?.[name]
153
+ if (!menuItem) {
154
+ return
155
+ }
156
+ if (!context.roomHistory.some((item) => item.id === menuItem.id)) {
157
+ return { room: menuItem }
158
+ }
159
+ })
160
+ }
@@ -6,6 +6,7 @@ export default function (request) {
6
6
  return createMachine(
7
7
  {
8
8
  id: 'side',
9
+ predictableActionArguments: true,
9
10
  initial: 'inactive',
10
11
  context: {
11
12
  menu: null,
@@ -66,13 +67,12 @@ export default function (request) {
66
67
  actions: {
67
68
  setMenu: assign((context, event) => {
68
69
  const menu = event.data
69
- if (!Array.isArray(menu?.data)) return
70
70
  addLevelProperty(menu.data, 0)
71
71
  return { menu }
72
72
  }),
73
73
  updateMenu: assign((context, event) => {
74
74
  const menu = event.data
75
- if (menu?.data?.length) {
75
+ if (menu.data.length) {
76
76
  addLevelProperty(menu.data, 0)
77
77
  return { menu, defaultMenuItemStack: getDefaultItem(menu.data[0]) }
78
78
  }
@@ -83,7 +83,7 @@ export default function (request) {
83
83
  return await request.send(game.getListRoot({ appSecret }))
84
84
  },
85
85
  fetchUpdateMenu: async (context, event) => {
86
- return await request.send(game.getListRoot({ timestamp: context.menu?.timestamp, appSecret }))
86
+ return await request.send(game.getListRoot({ timestamp: context.menu.timestamp, appSecret }))
87
87
  },
88
88
  },
89
89
  }
@@ -0,0 +1,223 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import game from '../api/game.js'
3
+
4
+ export default function (request) {
5
+ const { appSecret } = request.config
6
+ return createMachine(
7
+ {
8
+ id: 'side',
9
+ predictableActionArguments: true,
10
+ initial: 'init',
11
+ context: {
12
+ menu: null,
13
+ menuItemStack: [],
14
+ previousMenuItemStack: [],
15
+ historyStack: [],
16
+ defaultMenuItemStack: [],
17
+ },
18
+ states: {
19
+ init: {
20
+ on: {
21
+ START_MENU: {
22
+ target: 'loading',
23
+ },
24
+ },
25
+ },
26
+ loading: {
27
+ invoke: {
28
+ src: 'getMenu',
29
+ onDone: {
30
+ target: 'idle',
31
+ actions: ['setMenu', 'setDefaultMenuItemStack'],
32
+ },
33
+ },
34
+ },
35
+ idle: {
36
+ initial: 'pending',
37
+ states: {
38
+ pending: {
39
+ after: {
40
+ 20000: [
41
+ {
42
+ target: 'updating',
43
+ cond: 'isInMenu',
44
+ },
45
+ {
46
+ target: 'pending',
47
+ },
48
+ ],
49
+ },
50
+ },
51
+ updating: {
52
+ invoke: {
53
+ src: 'fetchUpdateMenu',
54
+ onDone: {
55
+ target: 'pending',
56
+ actions: 'updateMenu',
57
+ },
58
+ },
59
+ },
60
+ },
61
+ on: {
62
+ SELECT: {
63
+ actions: 'setMenuItemStack',
64
+ },
65
+ CANCEL: {
66
+ actions: 'restoreMenuItemStack',
67
+ },
68
+ PUSH: {
69
+ actions: 'pushHistoryStack',
70
+ },
71
+ POP: {
72
+ actions: 'popHistoryStack',
73
+ },
74
+ RESET: {
75
+ actions: ['resetMenuItemStack', 'resetHistoryStack'],
76
+ },
77
+ },
78
+ },
79
+ },
80
+ },
81
+ {
82
+ actions: {
83
+ setMenu: assign((context, event) => {
84
+ const menu = event.data
85
+ addLevelProperty(menu.data, 0)
86
+ return { menu }
87
+ }),
88
+ setDefaultMenuItemStack: assign((context, event) => {
89
+ const menu = event.data
90
+ if (menu.data.length > 0) {
91
+ const menuItemStack = getDefaultItem(menu.data[0])
92
+ return { menuItemStack, defaultMenuItemStack: menuItemStack }
93
+ }
94
+ }),
95
+ setMenuItemStack: assign((context, event) => {
96
+ const { menuItemStack } = context
97
+ const inputItem = event.data
98
+ const isTopItem = inputItem.level === 0
99
+ const hasSubMenu = inputItem.sub?.length
100
+
101
+ if (isTopItem) {
102
+ if (hasSubMenu) {
103
+ return {
104
+ previousMenuItemStack: menuItemStack,
105
+ menuItemStack: [event.data],
106
+ }
107
+ } else {
108
+ return {
109
+ previousMenuItemStack: [],
110
+ menuItemStack: [event.data],
111
+ historyStack: [],
112
+ }
113
+ }
114
+ } else {
115
+ const slicedStack = menuItemStack.slice(0, inputItem.level)
116
+ return {
117
+ menuItemStack: [...slicedStack, event.data],
118
+ historyStack: [],
119
+ }
120
+ }
121
+ }),
122
+ restoreMenuItemStack: assign((context, event) => {
123
+ const { previousMenuItemStack } = context
124
+ return {
125
+ previousMenuItemStack: [],
126
+ menuItemStack: previousMenuItemStack,
127
+ }
128
+ }),
129
+ updateMenu: assign((context, event) => {
130
+ const menu = event.data
131
+ if (menu.data.length) {
132
+ addLevelProperty(menu.data, 0)
133
+ return { menu, defaultMenuItemStack: getDefaultItem(menu.data[0]) }
134
+ }
135
+ }),
136
+ pushHistoryStack: assign((context, event) => {
137
+ const { historyStack } = context
138
+ return {
139
+ historyStack: [...historyStack, event.data],
140
+ }
141
+ }),
142
+ popHistoryStack: assign((context, event) => {
143
+ const { historyStack } = context
144
+ return {
145
+ historyStack: historyStack.slice(0, -1),
146
+ }
147
+ }),
148
+ resetMenuItemStack: assign((context, event) => {
149
+ const { defaultMenuItemStack } = context
150
+ return { menuItemStack: defaultMenuItemStack }
151
+ }),
152
+ resetHistoryStack: assign((context, event) => {
153
+ return { historyStack: [] }
154
+ }),
155
+ },
156
+ guards: {
157
+ isInMenu: (context, event) => {
158
+ const { menuItemStack, menu } = context
159
+ const menuItem = menuItemStack.slice(-1)[0]
160
+ return isItemInMenu(menuItem, menu.data)
161
+ },
162
+ },
163
+ services: {
164
+ getMenu: async (context, event) => {
165
+ return await request.send(game.getListRoot({ appSecret }))
166
+ },
167
+ fetchUpdateMenu: async (context, event) => {
168
+ return await request.send(game.getListRoot({ timestamp: context.menu.timestamp, appSecret }))
169
+ },
170
+ },
171
+ }
172
+ )
173
+ }
174
+
175
+ function isItemInMenu(targetItem, menuList) {
176
+ if (!targetItem || !Array.isArray(menuList)) {
177
+ return false
178
+ }
179
+ const stack = [...menuList]
180
+ while (stack.length > 0) {
181
+ const currentItem = stack.pop()
182
+ if (currentItem?.categoryId === targetItem?.categoryId) {
183
+ return true
184
+ }
185
+ if (Array.isArray(currentItem?.sub) && currentItem.sub.length > 0) {
186
+ stack.push(...currentItem.sub)
187
+ }
188
+ }
189
+ return false
190
+ }
191
+
192
+ function getDefaultItem(node) {
193
+ const stack = []
194
+ let current = node
195
+ while (current) {
196
+ stack.push(current)
197
+ if (!Array.isArray(current.sub) || current.sub.length === 0) {
198
+ break
199
+ }
200
+ current = current.sub[0]
201
+ }
202
+ return stack
203
+ }
204
+
205
+ function addLevelProperty(list, level) {
206
+ if (!Array.isArray(list)) {
207
+ return
208
+ }
209
+ const stack = [{ nodes: list, level }]
210
+ while (stack.length > 0) {
211
+ const current = stack.pop()
212
+ const nodes = current.nodes
213
+ const currentLevel = current.level
214
+ const nextLevel = currentLevel + 1
215
+ for (let i = 0; i < nodes.length; i++) {
216
+ nodes[i].level = currentLevel
217
+ // avoid games in list
218
+ if (!nodes[i].isGame && Array.isArray(nodes[i].sub)) {
219
+ stack.push({ nodes: nodes[i].sub, level: nextLevel })
220
+ }
221
+ }
222
+ }
223
+ }
@@ -5,6 +5,7 @@ export default function (request) {
5
5
  return createMachine(
6
6
  {
7
7
  id: 'user_info',
8
+ predictableActionArguments: true,
8
9
  initial: 'fetching',
9
10
  context: {
10
11
  userInfo: {},
@@ -5,6 +5,7 @@ export default function (request) {
5
5
  return createMachine(
6
6
  {
7
7
  id: 'user_photo',
8
+ predictableActionArguments: true,
8
9
  initial: 'fetching',
9
10
  context: {
10
11
  userPhotoList: {},
@@ -6,6 +6,7 @@ export default function (request) {
6
6
  return createMachine(
7
7
  {
8
8
  id: 'user_reset_password',
9
+ predictableActionArguments: true,
9
10
  initial: 'idle',
10
11
  context: {
11
12
  otpParams: {
@@ -28,6 +29,10 @@ export default function (request) {
28
29
  target: 'otpFetching',
29
30
  actions: 'setOtpParamsEmail',
30
31
  },
32
+ SEND_OTP_LOCAL: {
33
+ target: 'otpFetching',
34
+ actions: 'setOtpParamsLocal',
35
+ },
31
36
  SEND_OTP_PHONE: {
32
37
  target: 'otpFetching',
33
38
  actions: 'setOtpParamsPhone',
@@ -153,6 +158,15 @@ export default function (request) {
153
158
  },
154
159
  }
155
160
  }),
161
+ setOtpParamsLocal: assign((context, event) => {
162
+ const { username } = event.data
163
+ return {
164
+ otpParams: {
165
+ provider: 'local',
166
+ username,
167
+ },
168
+ }
169
+ }),
156
170
  setOtpParamsEmail: assign((context, event) => {
157
171
  const { email } = event.data
158
172
  return {
@@ -1,30 +1,19 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import auth from '../api/auth.js'
3
+ import { getDeviceTokenWithRetry } from '../util/deviceToken.js'
3
4
  import storage from '../util/storage.js'
4
- import { readParamFromLocation, normalize, AC_KEYS, FC_KEYS } from '../util/paramStore.js'
5
-
6
- // 註冊強制綁定多型出款:轉發各綁定型別欄位(BANK / CRYPTO / EWALLET),只帶有值的欄位
7
- const BIND_FIELDS = [
8
- 'bindingType',
9
- 'cryptoCurrency',
10
- 'cryptoNetwork',
11
- 'cryptoAddress',
12
- 'walletCode',
13
- 'ifscCode',
14
- 'pixType',
15
- 'firstNameLocale',
16
- 'lastNameLocale',
17
- ]
18
- const pickBindData = (data = {}) => BIND_FIELDS.reduce((acc, key) => (data[key] !== undefined ? { ...acc, [key]: data[key] } : acc), {})
19
5
 
20
6
  export default function (request) {
21
- const { sentry } = request.config
7
+ const { fpToken, sentry, defaultChannel, defaultSubchannel } = request.config
22
8
  return createMachine(
23
9
  {
24
10
  id: 'user_sign_up',
11
+ predictableActionArguments: true,
25
12
  initial: 'idle',
26
13
  context: {
27
14
  provider: null,
15
+ channel: null,
16
+ subchannel: null,
28
17
  signUpData: {},
29
18
  fc: null,
30
19
  reCaptchaToken: null,
@@ -34,7 +23,6 @@ export default function (request) {
34
23
  site: null,
35
24
  strategy: null,
36
25
  uid: null,
37
- agentId: null,
38
26
  },
39
27
  deviceTokenEnable: true,
40
28
  },
@@ -85,8 +73,7 @@ export default function (request) {
85
73
  }),
86
74
  setFriendCode: assign((context, event) => {
87
75
  const { fc } = event.data
88
- // api/auth.js 的 register 只濾 undefined/null,字面 'undefined' 會直送 query string
89
- return { fc: normalize(fc) }
76
+ return { fc }
90
77
  }),
91
78
  setSignUpId: assign((context, event) => {
92
79
  const {
@@ -96,19 +83,18 @@ export default function (request) {
96
83
  password,
97
84
  countryCode,
98
85
  phone,
86
+ channel,
87
+ subchannel,
99
88
  bankCode,
100
89
  bankAccount,
101
90
  holderName,
102
91
  branch,
103
92
  branchCode,
104
93
  affiliateCode,
105
- birthday,
106
94
  } = event.data
107
95
  return {
108
96
  signUpData: {
109
97
  provider: 'local',
110
- ...pickBindData(event.data),
111
- birthday,
112
98
  email,
113
99
  username,
114
100
  nick_name,
@@ -122,16 +108,29 @@ export default function (request) {
122
108
  branchCode,
123
109
  affiliateCode,
124
110
  },
111
+ channel,
112
+ subchannel,
125
113
  }
126
114
  }),
127
115
  setSignUpPhone: assign((context, event) => {
128
- const { email, countryCode, phone, nick_name, password, bankCode, bankAccount, holderName, branch, branchCode, affiliateCode, birthday } =
129
- event.data
116
+ const {
117
+ email,
118
+ countryCode,
119
+ phone,
120
+ nick_name,
121
+ password,
122
+ channel,
123
+ subchannel,
124
+ bankCode,
125
+ bankAccount,
126
+ holderName,
127
+ branch,
128
+ branchCode,
129
+ affiliateCode,
130
+ } = event.data
130
131
  return {
131
132
  signUpData: {
132
133
  provider: 'phone',
133
- ...pickBindData(event.data),
134
- birthday,
135
134
  email,
136
135
  countryCode,
137
136
  phone,
@@ -144,16 +143,29 @@ export default function (request) {
144
143
  branchCode,
145
144
  affiliateCode,
146
145
  },
146
+ channel,
147
+ subchannel,
147
148
  }
148
149
  }),
149
150
  setSignUpEmail: assign((context, event) => {
150
- const { email, nick_name, password, bankCode, bankAccount, holderName, branch, branchCode, affiliateCode, countryCode, phone, birthday } =
151
- event.data
151
+ const {
152
+ email,
153
+ nick_name,
154
+ password,
155
+ channel,
156
+ subchannel,
157
+ bankCode,
158
+ bankAccount,
159
+ holderName,
160
+ branch,
161
+ branchCode,
162
+ affiliateCode,
163
+ countryCode,
164
+ phone,
165
+ } = event.data
152
166
  return {
153
167
  signUpData: {
154
168
  provider: 'email',
155
- ...pickBindData(event.data),
156
- birthday,
157
169
  email,
158
170
  nick_name,
159
171
  password,
@@ -166,10 +178,12 @@ export default function (request) {
166
178
  countryCode,
167
179
  phone,
168
180
  },
181
+ channel,
182
+ subchannel,
169
183
  }
170
184
  }),
171
185
  setRegistrationData: assign((context, event) => {
172
- const { account, currency, site, strategy, uid, agentId } = event.data
186
+ const { account, currency, site, strategy, uid, channel, sub_channel } = event.data
173
187
  return {
174
188
  registrationData: {
175
189
  account,
@@ -177,7 +191,8 @@ export default function (request) {
177
191
  site,
178
192
  strategy,
179
193
  uid,
180
- agentId,
194
+ channel,
195
+ sub_channel,
181
196
  },
182
197
  }
183
198
  }),
@@ -189,36 +204,36 @@ export default function (request) {
189
204
  },
190
205
  services: {
191
206
  authenticate: async (context, event) => {
192
- const { signUpData, deviceTokenEnable } = context
193
- const dt = deviceTokenEnable ? await request.config.getDt?.() : undefined
207
+ const { channel, subchannel, signUpData, deviceTokenEnable } = context
208
+ const dt = await getDeviceTokenWithRetry({ fpToken, sentry, hosts: request.hosts, enable: deviceTokenEnable })
194
209
 
195
- // 宿主明確帶入的 affiliateCode(註冊表單的代理碼欄位)優先於網址/儲存這類環境值。
196
- // 判定用 `!== undefined` 而非 hasOwnProperty:上面的 setSignUpId/Phone/Email 是以解構寫入
197
- // signUpData,宿主沒帶時 key 仍然存在(值為 undefined),hasOwnProperty 會恆為 true、
198
- // 讓三層解析變成死碼。也不能用 `||`,否則使用者刻意清空送出的空字串會被吃掉、
199
- // 退回三層解析把剛清掉的舊代理碼從網址撿回來。
200
- const { affiliateCode: explicitAffiliateCode, ...signUpRest } = signUpData || {}
201
- const hasExplicitAc = explicitAffiliateCode !== undefined
202
- const acRead = readParamFromLocation(AC_KEYS)
203
- const affiliateCode = hasExplicitAc ? normalize(explicitAffiliateCode) : acRead.value
210
+ const affiliateCode = storage.get('ac') || signUpData?.affiliateCode
204
211
  const messages = {
205
212
  url: window.location.href,
213
+ channelOrders: [
214
+ { channel: storage.get('channel'), subchannel: storage.get('subchannel') },
215
+ { channel: defaultChannel, subchannel: defaultSubchannel },
216
+ { channel: channel, subchannel: subchannel },
217
+ ],
206
218
  affiliateCode,
207
- acSource: hasExplicitAc ? 'signUpData' : acRead.from,
208
219
  }
220
+ sentry.captureMessage(JSON.stringify(messages))
209
221
 
210
222
  const referralObj = {}
211
223
  if (![undefined, 'undefined', null, 'null'].includes(affiliateCode)) {
212
224
  referralObj.ac = affiliateCode
213
225
  }
214
226
 
227
+ referralObj.channel = storage.get('channel') || defaultChannel || channel
228
+ referralObj.subchannel = storage.get('subchannel') || defaultSubchannel || subchannel
229
+
215
230
  return await request.send(
216
231
  auth.register({
217
- ...signUpRest,
232
+ ...signUpData,
218
233
  ...referralObj,
219
234
  dt,
220
235
  reCaptchaToken: context.reCaptchaToken,
221
- fc: context.fc || readParamFromLocation(FC_KEYS).value,
236
+ fc: context.fc,
222
237
  })
223
238
  )
224
239
  },