@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,91 +0,0 @@
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
- let hotId
50
- let newId
51
- for (let i = 0; i < list.length; i++) {
52
- const item = list[i]
53
- if (hotId === undefined && item.category === context.hot.name) {
54
- hotId = item.id
55
- } else if (newId === undefined && item.category === context.new.name) {
56
- newId = item.id
57
- }
58
- if (hotId !== undefined && newId !== undefined) {
59
- break
60
- }
61
- }
62
- return {
63
- hot: { ...context.hot, id: hotId },
64
- new: { ...context.new, id: newId },
65
- }
66
- }),
67
- setGames: assign((context, event) => {
68
- const { games } = event.data
69
- return {
70
- hot: { ...context.hot, list: games.hot },
71
- new: { ...context.new, list: games.new },
72
- }
73
- }),
74
- },
75
- services: {
76
- getRoomItems: async (context, event) => {
77
- return await request.send(api.getGameCategory({ id: context.roomId }))
78
- },
79
- getGames: async (context, event) => {
80
- const [resHot, resNew] = await Promise.all([
81
- request.send(api.getGameCategory({ id: context.hot.id })),
82
- request.send(api.getGameCategory({ id: context.new.id })),
83
- ])
84
- const hotGames = resHot?.list?.map?.((item) => item.g)
85
- const newGames = resNew?.list?.map?.((item) => item.g)
86
- return { games: { hot: hotGames, new: newGames } }
87
- },
88
- },
89
- }
90
- )
91
- }
@@ -1,47 +0,0 @@
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
- }
@@ -1,402 +0,0 @@
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
- }
@@ -1,144 +0,0 @@
1
- import { assign, createMachine } from 'xstate'
2
- import activity from '../api/activity.js'
3
-
4
- export default function (request) {
5
- const { appSecret } = request.config
6
- return createMachine(
7
- {
8
- id: 'honor_board',
9
- predictableActionArguments: true,
10
- type: 'parallel',
11
- context: {
12
- tick: 6000,
13
- isPlaying: false,
14
- },
15
- states: {
16
- feed: {
17
- initial: 'updating',
18
- states: {
19
- updating: {
20
- invoke: {
21
- src: 'fetchHonorBoardList',
22
- onDone: {
23
- target: 'waiting',
24
- actions: 'setBroadcastList',
25
- },
26
- onError: {
27
- target: 'waiting',
28
- },
29
- },
30
- },
31
- waiting: {
32
- after: {
33
- TIMEOUT: {
34
- target: 'updating',
35
- cond: 'isNotInGame',
36
- },
37
- },
38
- },
39
- },
40
- },
41
- broadcast: {
42
- initial: 'idle',
43
- states: {
44
- idle: {
45
- on: {
46
- START_BROADCAST: {
47
- target: 'picking',
48
- actions: 'leaveGame',
49
- },
50
- },
51
- },
52
- picking: {
53
- after: {
54
- 5000: {
55
- target: 'display',
56
- actions: 'setBroadcast',
57
- },
58
- },
59
- },
60
- display: {
61
- after: {
62
- 5000: {
63
- target: 'picking',
64
- },
65
- },
66
- },
67
- },
68
- on: {
69
- RESET_BROADCAST: {
70
- target: '.idle',
71
- actions: 'resetBroadcast',
72
- },
73
- },
74
- },
75
- },
76
- },
77
- {
78
- delays: {
79
- TIMEOUT: (context, event) => {
80
- return context.tick * 10
81
- },
82
- },
83
- actions: {
84
- setBroadcastList: assign((context, event) => {
85
- const broadcastList = (event.data || []).map((item) => item.data).flat()
86
- const sortBroadcastList = broadcastList.sort((a, b) => {
87
- if (!a.time) return -1
88
- if (!b.time) return 1
89
- return a.time - b.time
90
- })
91
- return { broadcastList: sortBroadcastList }
92
- }),
93
- setBroadcast: assign((context, event) => {
94
- const { broadcastList = [], sentNormalBroadcastList = [], normalBroadcast = null } = context
95
- const broadcastIdSet = new Set(broadcastList.map((item) => item.broadcastId))
96
- const sentNormalList = []
97
- const seenSentIds = new Set()
98
- for (let i = 0; i < sentNormalBroadcastList.length; i++) {
99
- const item = sentNormalBroadcastList[i]
100
- const broadcastId = item?.broadcastId
101
- if (!broadcastIdSet.has(broadcastId) || seenSentIds.has(broadcastId)) {
102
- continue
103
- }
104
- seenSentIds.add(broadcastId)
105
- sentNormalList.push(item)
106
- }
107
- const currentBroadcastId = normalBroadcast?.broadcastId
108
- if (currentBroadcastId != null && broadcastIdSet.has(currentBroadcastId) && !seenSentIds.has(currentBroadcastId)) {
109
- seenSentIds.add(currentBroadcastId)
110
- sentNormalList.push(normalBroadcast)
111
- }
112
- const nextNormalBroadcast = broadcastList.find((broadcast) => !seenSentIds.has(broadcast.broadcastId))
113
- return {
114
- normalBroadcast: nextNormalBroadcast,
115
- sentNormalBroadcastList: sentNormalList,
116
- }
117
- }),
118
- resetBroadcast: assign((context, event) => {
119
- return {
120
- isPlaying: true,
121
- normalBroadcast: null,
122
- sentNormalBroadcastList: [],
123
- }
124
- }),
125
- leaveGame: assign((context, event) => {
126
- return {
127
- isPlaying: false,
128
- }
129
- }),
130
- },
131
- guards: {
132
- isNotInGame: (context, event) => {
133
- return !context.isPlaying
134
- },
135
- },
136
- services: {
137
- fetchHonorBoardList: async (context, event) => {
138
- const { data } = await request.send(activity.getHonorBroadcast({ isPwa: true, appSecret }))
139
- return data
140
- },
141
- },
142
- }
143
- )
144
- }