@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,80 @@
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: 'game_hot_new',
8
+ predictableActionArguments: true,
9
+ initial: 'preparing',
10
+ context: {
11
+ hot: {
12
+ id: null,
13
+ name: 'SYSTEM_TOP_GAME',
14
+ list: [],
15
+ },
16
+ new: {
17
+ id: null,
18
+ name: 'SYSTEM_NEW_GAME',
19
+ list: [],
20
+ },
21
+ },
22
+ states: {
23
+ preparing: {
24
+ invoke: {
25
+ src: 'getRoomItems',
26
+ onDone: {
27
+ target: 'fetchingGames',
28
+ actions: 'setId',
29
+ },
30
+ onError: {
31
+ target: 'fetchingGames',
32
+ },
33
+ },
34
+ },
35
+ fetchingGames: {
36
+ invoke: {
37
+ src: 'getGames',
38
+ onDone: {
39
+ actions: 'setGames',
40
+ },
41
+ },
42
+ },
43
+ },
44
+ },
45
+ {
46
+ actions: {
47
+ setId: assign((context, event) => {
48
+ const { list = [] } = event.data
49
+ const hotId = list.find((item) => item.category === context.hot.name)?.id
50
+ const newId = list.find((item) => item.category === context.new.name)?.id
51
+ return {
52
+ hot: { ...context.hot, id: hotId },
53
+ new: { ...context.new, id: newId },
54
+ }
55
+ }),
56
+ setGames: assign((context, event) => {
57
+ const { games } = event.data
58
+ return {
59
+ hot: { ...context.hot, list: games.hot },
60
+ new: { ...context.new, list: games.new },
61
+ }
62
+ }),
63
+ },
64
+ services: {
65
+ getRoomItems: async (context, event) => {
66
+ return await request.send(api.getGameCategory({ id: context.roomId }))
67
+ },
68
+ getGames: async (context, event) => {
69
+ const [resHot, resNew] = await Promise.all([
70
+ request.send(api.getGameCategory({ id: context.hot.id })),
71
+ request.send(api.getGameCategory({ id: context.new.id })),
72
+ ])
73
+ const hotGames = resHot?.list?.map?.((item) => item.g)
74
+ const newGames = resNew?.list?.map?.((item) => item.g)
75
+ return { games: { hot: hotGames, new: newGames } }
76
+ },
77
+ },
78
+ }
79
+ )
80
+ }
@@ -7,6 +7,7 @@ export default function (request, context) {
7
7
  return createMachine(
8
8
  {
9
9
  id: 'game_info',
10
+ predictableActionArguments: true,
10
11
  initial: 'fetching',
11
12
  context: {
12
13
  gameInfo: {},
@@ -24,7 +25,13 @@ export default function (request, context) {
24
25
  },
25
26
  },
26
27
  },
27
- idle: {},
28
+ idle: {
29
+ // on: {
30
+ // SET_GAME_CODE: {
31
+ // actions: 'setGameCode',
32
+ // },
33
+ // },
34
+ },
28
35
  },
29
36
  },
30
37
  {
@@ -34,6 +41,11 @@ export default function (request, context) {
34
41
  gameInfo: event.data.data,
35
42
  }
36
43
  }),
44
+ // setGameCode: assign((context, event) => {
45
+ // return {
46
+ // gameCode: event.data.data,
47
+ // }
48
+ // }),
37
49
  },
38
50
  services: {
39
51
  // 取得遊戲資訊
@@ -0,0 +1,47 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import game from '../api/game.js'
3
+
4
+ export default function (request, context) {
5
+ const { appSecret } = request.config
6
+ const { providerId, seqNo, lang } = context
7
+ return createMachine(
8
+ {
9
+ id: 'game_replay',
10
+ predictableActionArguments: true,
11
+ initial: 'fetching',
12
+ context: {
13
+ gameReplayInfo: {},
14
+ },
15
+ states: {
16
+ fetching: {
17
+ invoke: {
18
+ src: 'fetchGameReplayInfo',
19
+ onDone: {
20
+ target: 'idle',
21
+ actions: 'setGameReplayInfo',
22
+ },
23
+ onError: {
24
+ target: 'idle',
25
+ },
26
+ },
27
+ },
28
+ idle: {},
29
+ },
30
+ },
31
+ {
32
+ actions: {
33
+ setGameReplayInfo: assign((context, event) => {
34
+ return {
35
+ gameReplayInfo: event.data.data,
36
+ }
37
+ }),
38
+ },
39
+ services: {
40
+ // 取得遊戲重播資訊
41
+ fetchGameReplayInfo: async (context, event) => {
42
+ return await request.send(game.getGameReplayInfo({ providerId, seqNo, lang, appSecret }))
43
+ },
44
+ },
45
+ }
46
+ )
47
+ }
@@ -5,6 +5,7 @@ export default function (request) {
5
5
  return createMachine(
6
6
  {
7
7
  id: 'game_search_cash',
8
+ predictableActionArguments: true,
8
9
  initial: 'init',
9
10
  context: {
10
11
  initialized: false,
@@ -0,0 +1,402 @@
1
+ import { createMachine, assign, send } from 'xstate'
2
+ import game from '../api/game.js'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'game_search_v2',
8
+ predictableActionArguments: true,
9
+ initial: 'init',
10
+ context: {
11
+ keyword: '',
12
+ tagId: null,
13
+ mainTagList: [],
14
+ tagList: [],
15
+ gameList: [],
16
+ recentlySearch: [],
17
+ recentlyGame: [],
18
+ youMayLike: [],
19
+ // 以下變數為數據分析用
20
+ selectedType: null,
21
+ tagIndex: null,
22
+ click: null,
23
+ clickDefault: null,
24
+ traceId: null,
25
+ isYouMayLike: false,
26
+ isRecentlyGame: false,
27
+ isRecentlySearch: false,
28
+ gameCode: null,
29
+ lang: 'en-US',
30
+ },
31
+ states: {
32
+ init: {
33
+ on: {
34
+ INIT: {
35
+ target: 'preset',
36
+ actions: ['setLang'],
37
+ },
38
+ },
39
+ },
40
+ preset: {
41
+ invoke: {
42
+ src: 'fetchTags',
43
+ onDone: {
44
+ target: 'loading',
45
+ actions: 'setMainTagList',
46
+ },
47
+ onError: {
48
+ target: 'fail',
49
+ },
50
+ },
51
+ },
52
+ loading: {
53
+ invoke: {
54
+ src: 'fetchInitialData',
55
+ onDone: {
56
+ target: 'idle',
57
+ actions: 'setInitialData',
58
+ },
59
+ onError: {
60
+ target: '#game_search_v2.fail',
61
+ },
62
+ },
63
+ },
64
+ idle: {
65
+ on: {
66
+ SET_MAIN_TAG_ID: {
67
+ target: 'setGameList',
68
+ actions: ['setMainTagId', 'setTraceData'],
69
+ },
70
+ PLAY_GAME: {
71
+ target: 'sendingTrace',
72
+ actions: 'setGameCode',
73
+ },
74
+ START_SEARCH: {
75
+ target: 'searching',
76
+ actions: 'clearKeywords',
77
+ },
78
+ CLEAR_MAIN_TAG: {
79
+ actions: 'clearMainTag',
80
+ },
81
+ },
82
+ },
83
+ setGameList: {
84
+ always: [
85
+ {
86
+ target: 'idle',
87
+ actions: 'setGames',
88
+ cond: 'isRecentlyYouMayLike',
89
+ },
90
+ {
91
+ target: 'fetchGameList',
92
+ },
93
+ ],
94
+ },
95
+ fetchGameList: {
96
+ invoke: {
97
+ src: 'fetchGames',
98
+ onDone: {
99
+ target: 'idle',
100
+ actions: 'setGames',
101
+ },
102
+ onError: {
103
+ target: '#game_search_v2.fail',
104
+ },
105
+ },
106
+ },
107
+ searching: {
108
+ initial: 'searchIdle',
109
+ states: {
110
+ searchIdle: {
111
+ on: {
112
+ SET_TAG_ID: {
113
+ target: '#game_search_v2.fetchGameList',
114
+ actions: ['setTagId', 'setTraceData'],
115
+ },
116
+ PRESS_ENTER: [
117
+ {
118
+ actions: send((context, event) => ({
119
+ type: 'SET_TAG_ID',
120
+ data: {
121
+ tagId: context.tagList[0]?.id,
122
+ traceData: {
123
+ isYouMayLike: false,
124
+ isRecentlyGame: false,
125
+ isRecentlySearch: false,
126
+ },
127
+ },
128
+ })),
129
+ cond: 'hasTagList',
130
+ },
131
+ {
132
+ target: '#game_search_v2.sendingTrace',
133
+ actions: 'clearExceptKeyword',
134
+ },
135
+ ],
136
+ SET_KEYWORD: {
137
+ target: 'debouncing',
138
+ actions: ['setKeyword', 'setLang'],
139
+ },
140
+ STOP_SEARCH: {
141
+ target: '#game_search_v2.idle',
142
+ actions: 'clearKeywords',
143
+ },
144
+ },
145
+ },
146
+ debouncing: {
147
+ on: {
148
+ SET_KEYWORD: {
149
+ target: 'debouncing',
150
+ actions: ['setKeyword', 'setLang'],
151
+ },
152
+ },
153
+ after: {
154
+ 500: {
155
+ target: 'fetching',
156
+ },
157
+ },
158
+ },
159
+ fetching: {
160
+ invoke: {
161
+ src: 'fetchTags',
162
+ onDone: {
163
+ target: 'searchIdle',
164
+ actions: 'setTagList',
165
+ },
166
+ onError: {
167
+ target: '#game_search_v2.fail',
168
+ },
169
+ },
170
+ },
171
+ },
172
+ },
173
+ sendingTrace: {
174
+ invoke: {
175
+ src: 'sendTrace',
176
+ onDone: {
177
+ target: 'idle',
178
+ },
179
+ onError: {
180
+ target: 'fail',
181
+ },
182
+ },
183
+ },
184
+ fail: {},
185
+ },
186
+ },
187
+ {
188
+ actions: {
189
+ setMainTagList: assign((context, event) => {
190
+ return {
191
+ mainTagList: event.data,
192
+ }
193
+ }),
194
+ setInitialData: assign((context, event) => {
195
+ const { recentlySearch = [], recentlyGame = [], youMayLike = [] } = event.data
196
+ let tagId = null
197
+ let gameList = []
198
+ if (recentlyGame?.length > 0) {
199
+ gameList = recentlyGame
200
+ } else if (youMayLike?.length > 0) {
201
+ gameList = youMayLike
202
+ }
203
+ return {
204
+ recentlySearch: recentlySearch.filter((item) => item.id && item.i18n),
205
+ recentlyGame,
206
+ youMayLike,
207
+ gameList,
208
+ tagId,
209
+ }
210
+ }),
211
+ setMainTagId: assign((context, event) => {
212
+ const { tagId } = event.data
213
+ const { mainTagList } = context
214
+ const tagIndex = mainTagList.findIndex((tag) => tag.id === tagId)
215
+ return {
216
+ keyword: '',
217
+ tagId,
218
+ tagIndex,
219
+ click: 1,
220
+ clickDefault: null,
221
+ }
222
+ }),
223
+ clearMainTag: assign((context, event) => {
224
+ return {
225
+ tagId: null,
226
+ }
227
+ }),
228
+ setTagId: assign((context, event) => {
229
+ const { tagId, clickTagType } = event.data
230
+ const { mainTagList, tagList, recentlySearch } = context
231
+ if (clickTagType === 'RECENTLY SEARCH') {
232
+ const tagIndex = recentlySearch.findIndex((tag) => tag.id === tagId)
233
+ return {
234
+ tagId,
235
+ tagIndex,
236
+ click: 1,
237
+ clickDefault: null,
238
+ }
239
+ } else if (clickTagType === 'POPULAR KEYWORDS' || tagList.length <= 0) {
240
+ const tagIndex = mainTagList.findIndex((tag) => tag.id === tagId)
241
+ return {
242
+ tagId,
243
+ tagIndex,
244
+ click: null,
245
+ clickDefault: 1,
246
+ }
247
+ } else {
248
+ const tagIndex = tagList.findIndex((tag) => tag.id === tagId)
249
+ return {
250
+ tagId,
251
+ tagIndex,
252
+ click: 1,
253
+ clickDefault: null,
254
+ }
255
+ }
256
+ }),
257
+ setGames: assign((context, event) => {
258
+ if (event?.data) {
259
+ const { traceId, result } = event.data
260
+ return {
261
+ traceId,
262
+ gameList: result,
263
+ }
264
+ } else {
265
+ const { tagId, recentlyGame, youMayLike } = context
266
+ let gameList = []
267
+ if (tagId === 'Recently') {
268
+ gameList = recentlyGame
269
+ } else if (tagId === 'You may like') {
270
+ gameList = youMayLike
271
+ }
272
+ return {
273
+ traceId: null,
274
+ gameList,
275
+ }
276
+ }
277
+ }),
278
+ setTraceData: assign((context, event) => {
279
+ const { isYouMayLike, isRecentlyGame, isRecentlySearch } = event.data?.traceData
280
+ return {
281
+ isYouMayLike,
282
+ isRecentlyGame,
283
+ isRecentlySearch,
284
+ }
285
+ }),
286
+ setKeyword: assign((context, event) => {
287
+ return {
288
+ keyword: event.data.keyword,
289
+ }
290
+ }),
291
+ setLang: assign((context, event) => {
292
+ return {
293
+ lang: event.data.lang,
294
+ }
295
+ }),
296
+ clearKeywords: assign((context, event) => {
297
+ return {
298
+ keyword: '',
299
+ }
300
+ }),
301
+ setTagList: assign((context, event) => {
302
+ return {
303
+ tagList: event.data,
304
+ }
305
+ }),
306
+ setGameCode: assign((context, event) => {
307
+ const { gameList } = context
308
+ const gameCode = event.data
309
+ const gameCodeIndex = gameList.findIndex((game) => game?.gameCode === gameCode)
310
+ return {
311
+ gameCode,
312
+ gameCodeIndex,
313
+ }
314
+ }),
315
+ clearExceptKeyword: assign((context, event) => {
316
+ return {
317
+ gameList: [],
318
+ traceId: null,
319
+ tagId: null,
320
+ tagIndex: null,
321
+ gameCode: null,
322
+ gameCodeIndex: null,
323
+ isYouMayLike: false,
324
+ isRecentlyGame: false,
325
+ isRecentlySearch: false,
326
+ query: context.keyword,
327
+ click: null,
328
+ clickDefault: null,
329
+ }
330
+ }),
331
+ },
332
+ guards: {
333
+ isRecentlyYouMayLike: (context, event) => {
334
+ const { tagId } = context
335
+ return tagId === 'Recently' || tagId === 'You may like'
336
+ },
337
+ hasTagList: (context, event) => {
338
+ const { tagList } = context
339
+ return tagList?.length > 0
340
+ },
341
+ },
342
+ services: {
343
+ fetchTags: async (context, event) => {
344
+ const { keyword, lang } = context
345
+ const { result } = await request.send(game.getGameTags({ q: keyword, lang }))
346
+ return result
347
+ },
348
+ fetchInitialData: async (context, event) => {
349
+ const data = await request.send(game.getGameSearchHome())
350
+ return data
351
+ },
352
+ fetchGames: async (context, event) => {
353
+ const { tagId, tagIndex, keyword, click, clickDefault } = context
354
+ const { traceId, result } = await request.send(
355
+ game.getGameSearchList({
356
+ id: tagId,
357
+ index: tagIndex,
358
+ q: keyword,
359
+ click,
360
+ clickDefault,
361
+ })
362
+ )
363
+ return { traceId, result }
364
+ },
365
+ sendTrace: async (context, event) => {
366
+ const {
367
+ traceId,
368
+ tagId,
369
+ tagIndex,
370
+ gameCode,
371
+ gameCodeIndex,
372
+ keyword: query,
373
+ click,
374
+ clickDefault,
375
+ isYouMayLike,
376
+ isRecentlyGame,
377
+ isRecentlySearch,
378
+ } = context
379
+ let id = tagId
380
+ if (tagId === 'Recently' || tagId === 'You may like') {
381
+ id = null
382
+ }
383
+ return await request.send(
384
+ game.setGameSearchTrace({
385
+ traceId,
386
+ tagId: id,
387
+ tagIndex,
388
+ gameCode,
389
+ gameCodeIndex,
390
+ query,
391
+ click,
392
+ clickDefault,
393
+ isYouMayLike,
394
+ isRecentlyGame,
395
+ isRecentlySearch,
396
+ })
397
+ )
398
+ },
399
+ },
400
+ }
401
+ )
402
+ }