@jetthai/cuora 1.1.346-qa-2 → 1.1.346-ranking-1

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.
package/CHANGELOG.md CHANGED
@@ -2,11 +2,7 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
- ### [1.1.346-qa-2](https://github.com/jetthai/cuora-module/compare/v1.1.346-qa-1...v1.1.346-qa-2) (2025-03-31)
6
-
7
- ### [1.1.346-qa-1](https://github.com/jetthai/cuora-module/compare/v1.1.346-qa...v1.1.346-qa-1) (2025-03-31)
8
-
9
- ### [1.1.346-qa](https://github.com/jetthai/cuora-module/compare/v1.1.346...v1.1.346-qa) (2025-03-30)
5
+ ### [1.1.346-ranking-1](https://github.com/jetthai/cuora-module/compare/v1.1.346...v1.1.346-ranking-1) (2025-04-02)
10
6
 
11
7
  ### [1.1.346](https://github.com/jetthai/cuora-module/compare/v1.1.345...v1.1.346) (2025-03-27)
12
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.1.346-qa-2",
3
+ "version": "1.1.346-ranking-1",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
package/src/api/game.js CHANGED
@@ -1,4 +1,7 @@
1
1
  export default {
2
+ getGameSHA: () => ({ method: 'get', url: 'game/list/v2/sha' }),
3
+ getOptionMap: (code) => ({ method: 'get', url: 'game/list/v2/options', params: { code } }),
4
+ getGameStatus: () => ({ method: 'get', url: 'game/list/v2/status' }),
2
5
  getGameCategory: ({ id, first } = {}) => ({ method: 'get', url: 'game/list/v2/category', params: { id, first } }),
3
6
  addFavoriteGame: (code) => ({ method: 'post', url: 'game/myfavorite/add', params: { games: [code] } }),
4
7
  removeFavoriteGame: (code) => ({ method: 'post', url: 'game/myfavorite/remove', params: { games: [code] } }),
@@ -97,5 +100,4 @@ export default {
97
100
  }),
98
101
  getFreeGameList: () => ({ method: 'get', url: 'activities/getFreeGameRewardList' }),
99
102
  getFreeGameReward: ({ activityNo, receiveNo }) => ({ method: 'post', url: 'activities/getFreeGameReward', params: { activityNo, receiveNo } }),
100
- getV3GameInfo: ({ appSecret, gameCodes }) => ({ method: 'post', url: 'game/list/v3/gameInfo', params: { appSecret, gameCodes } }),
101
103
  }
package/src/api/index.js CHANGED
@@ -6,5 +6,6 @@ import mailbox from './mailbox.js'
6
6
  import payment from './payment.js'
7
7
  import user from './user.js'
8
8
  import form from './form.js'
9
+ import ranking from './ranking.js'
9
10
 
10
- export default { activity, auth, common, game, mailbox, payment, user, form }
11
+ export default { activity, auth, common, game, mailbox, payment, user, form, ranking }
@@ -0,0 +1,26 @@
1
+ export default {
2
+ // 未登入排名資料
3
+ getTournament: ({ activityNo }) => ({
4
+ url: 'tournament/detail',
5
+ method: 'get',
6
+ params: { activityNo },
7
+ isPublic: true,
8
+ }),
9
+ // 登入後排名預設期數資料
10
+ getRankingOptions: ({ activityNo }) => ({
11
+ url: 'ranking/detail/option',
12
+ method: 'get',
13
+ params: { activityNo },
14
+ }),
15
+ // 登入後排名資料
16
+ getRankingDetail: ({ activityNo, cycle, round }) => ({
17
+ url: 'ranking/detail',
18
+ method: 'post',
19
+ params: { activityNo, cycle, round },
20
+ }),
21
+ getRankingGames: ({ activityNo }) => ({
22
+ url: 'hot-game/ranking',
23
+ method: 'get',
24
+ params: { activityNo },
25
+ }),
26
+ }
@@ -292,8 +292,12 @@ export default function (request) {
292
292
  return { announcementList: { data } }
293
293
  }),
294
294
  setFeeds: assign((context, event) => {
295
- const { announcementList, broadcastList, mailBoxInfo } = event.data
295
+ const { announcementList, broadcastList, mailBoxInfo, siteConfig } = event.data
296
296
  const promotions = announcementList?.announcements?.filter?.((item) => item.category === 3) || []
297
+ const customerMessageEnable = siteConfig?.csChat?.some((item) => item.enable && item.name === 'customermessage')
298
+ if (!customerMessageEnable) {
299
+ mailBoxInfo.rows -= mailBoxInfo.detailRows.CUSTOMER || 0
300
+ }
297
301
  return { broadcastList, mailBoxInfo, promotions }
298
302
  }),
299
303
  setBroadcast: assign((context, event) => {
@@ -1,9 +1,6 @@
1
1
  import { assign, createMachine } from 'xstate'
2
- import api from '../api/game.js'
3
-
4
- export default function (request) {
5
- const { appSecret } = request.config
6
2
 
3
+ export default function () {
7
4
  return createMachine(
8
5
  {
9
6
  id: 'error',
@@ -11,7 +8,6 @@ export default function (request) {
11
8
  context: {
12
9
  error: null,
13
10
  gameCode: null,
14
- game: null,
15
11
  },
16
12
  states: {
17
13
  normal: {
@@ -32,23 +28,15 @@ export default function (request) {
32
28
  { target: 'unfinishedGame', cond: 'isUnfinishedGame', actions: 'setUnfinishedGame' },
33
29
  { target: 'freeGameSettle', cond: 'isFreeGameSettle' },
34
30
  { target: 'freeGameGiveUp', cond: 'isFreeGameGiveUp' },
31
+ // { target: 'hall' },
35
32
  ],
36
33
  },
37
34
  logout: {},
38
35
  deposit: {},
39
- unfinishedGame: {
40
- invoke: {
41
- src: 'getGameInfo',
42
- onDone: {
43
- actions: 'setGame',
44
- },
45
- onError: {
46
- target: 'unfinishedGame',
47
- },
48
- },
49
- },
36
+ unfinishedGame: {},
50
37
  freeGameSettle: {},
51
38
  freeGameGiveUp: {},
39
+ // hall: {},
52
40
  },
53
41
  },
54
42
  },
@@ -70,12 +58,6 @@ export default function (request) {
70
58
  gameCode: context.error.extend.split(/_(.+)/)[1],
71
59
  }
72
60
  }),
73
- setGame: assign((context, event) => {
74
- const { data = [] } = event.data
75
- return {
76
- game: data?.[0],
77
- }
78
- }),
79
61
  },
80
62
  guards: {
81
63
  isLogout: (context, event) => {
@@ -94,12 +76,7 @@ export default function (request) {
94
76
  return context.error.code === 'ERR_G125'
95
77
  },
96
78
  },
97
- services: {
98
- getGameInfo: async (context, event) => {
99
- const { gameCode } = context
100
- return await request.send(api.getV3GameInfo({ appSecret, gameCodes: [gameCode] }))
101
- },
102
- },
79
+ services: {},
103
80
  }
104
81
  )
105
82
  }
@@ -49,6 +49,7 @@ export default function (request) {
49
49
  gameWalletType: null,
50
50
  switchGame: null,
51
51
  isPlaying: false,
52
+ ...oldContext,
52
53
  },
53
54
  states: {
54
55
  flow: {
@@ -206,6 +207,7 @@ export default function (request) {
206
207
  actions: ['setIsPlaying', 'resetContent', 'resetSHA'],
207
208
  },
208
209
  LEAVE_GAME_REFRESH: {
210
+ target: '#game.oldTimer',
209
211
  actions: 'setIsPlaying',
210
212
  },
211
213
  },
@@ -280,6 +282,63 @@ export default function (request) {
280
282
  },
281
283
  },
282
284
  },
285
+ oldTimer: {
286
+ initial: 'fetchingGameSHA',
287
+ states: {
288
+ fetchingGameSHA: {
289
+ invoke: {
290
+ src: 'fetchGameSHA',
291
+ onDone: {
292
+ target: 'checking',
293
+ actions: 'setGameSHA',
294
+ },
295
+ onError: {
296
+ target: 'pending',
297
+ },
298
+ },
299
+ },
300
+ checking: {
301
+ always: [{ target: 'updatingStatus', cond: 'isStatusChanged' }, { target: 'pending' }],
302
+ },
303
+ updatingStatus: {
304
+ invoke: {
305
+ src: 'fetchStatus',
306
+ onDone: {
307
+ target: 'updatingOption',
308
+ actions: ['setStatus'],
309
+ },
310
+ onError: {
311
+ target: 'pending',
312
+ },
313
+ },
314
+ },
315
+ updatingOption: {
316
+ invoke: {
317
+ src: 'fetchOption',
318
+ onDone: {
319
+ target: 'pending',
320
+ actions: 'mergeOption',
321
+ },
322
+ onError: {
323
+ target: 'pending',
324
+ },
325
+ },
326
+ },
327
+ pending: {
328
+ after: {
329
+ 20000: [
330
+ {
331
+ target: 'fetchingGameSHA',
332
+ cond: 'isNotInGame',
333
+ },
334
+ {
335
+ target: 'pending',
336
+ },
337
+ ],
338
+ },
339
+ },
340
+ },
341
+ },
283
342
  },
284
343
  },
285
344
  {
@@ -396,6 +455,9 @@ export default function (request) {
396
455
  return event.data.gameWalletType
397
456
  },
398
457
  }),
458
+ clearGameInfo: assign((context, event) => {
459
+ return { game: { providerId: null, gameId: null, gameTypeId: null, mappingId: null } }
460
+ }),
399
461
  setGameInfo: assign((context, event) => {
400
462
  const { providerId, gameId, gameTypeId, mappingId, portrait, gameCode, name } = event.data.game
401
463
  return { game: { providerId, gameId, gameTypeId, mappingId, portrait: portrait ? 1 : 0, gameCode, name } }
@@ -429,6 +491,7 @@ export default function (request) {
429
491
  isPlaying: event.data,
430
492
  }
431
493
  }),
494
+ ...oldActions,
432
495
  },
433
496
  guards: {
434
497
  isDifferentRoom: (context, event) => context.room?.categoryId !== event.data?.categoryId,
@@ -437,9 +500,13 @@ export default function (request) {
437
500
  // 是否有下一頁
438
501
  return loadable && !isLastPage
439
502
  },
503
+ isNotInGame: (context, event) => {
504
+ return !context.isPlaying
505
+ },
440
506
  hasRoomAndIsNotInGame: (context, event) => {
441
507
  return context.room?.categoryId && !context.isPlaying
442
508
  },
509
+ ...oldGuards,
443
510
  },
444
511
  services: {
445
512
  batchFetch: async (context, event) => {
@@ -567,7 +634,75 @@ export default function (request) {
567
634
  const provider_id = context.game.providerId
568
635
  return await request.send(api.logoutGame({ uid_site, provider_id }))
569
636
  },
637
+ ...oldServices(request),
570
638
  },
571
639
  }
572
640
  )
573
641
  }
642
+
643
+ const oldContext = {
644
+ sha: {
645
+ status: null,
646
+ },
647
+ isStatusChanged: false,
648
+ statusMap: {},
649
+ optionMap: {},
650
+ }
651
+
652
+ const oldActions = {
653
+ setGameSHA: assign((context, event) => {
654
+ const { sha } = context
655
+ const newSha = event.data
656
+ return {
657
+ sha: newSha,
658
+ isStatusChanged: !sha.status || sha.status !== newSha.status,
659
+ }
660
+ }),
661
+ setStatus: assign((context, event) => {
662
+ return {
663
+ statusMap: event.data,
664
+ }
665
+ }),
666
+ mergeOption: assign((context, event) => {
667
+ const { optionMap } = context
668
+ return {
669
+ optionMap: { ...optionMap, ...event.data },
670
+ }
671
+ }),
672
+ resetSHA: assign((context, event) => {
673
+ return {
674
+ sha: {
675
+ status: null,
676
+ },
677
+ isStatusChanged: false,
678
+ statusMap: {},
679
+ optionMap: {},
680
+ }
681
+ }),
682
+ }
683
+
684
+ const oldGuards = {
685
+ isStatusChanged: (context, event) => context.isStatusChanged,
686
+ }
687
+
688
+ const oldServices = (request) => ({
689
+ fetchOption: async (context, event) => {
690
+ if (request.getToken()) {
691
+ return await request.send(api.getOptionMap())
692
+ }
693
+ },
694
+ fetchGameSHA: async (context, event) => {
695
+ if (request.getToken()) {
696
+ return await request.send(api.getGameSHA())
697
+ } else {
698
+ return {
699
+ status: null,
700
+ }
701
+ }
702
+ },
703
+ fetchStatus: async (context, event) => {
704
+ if (request.getToken()) {
705
+ return await request.send(api.getGameStatus())
706
+ }
707
+ },
708
+ })
@@ -39,6 +39,7 @@ import honor_board from './honor_board.js'
39
39
  import user_photo from './user_photo.js'
40
40
  import navbar from './navbar.js'
41
41
  import websocket from './websocket.js'
42
+ import ranking from './ranking.js'
42
43
 
43
44
  export default {
44
45
  ...activity,
@@ -82,4 +83,5 @@ export default {
82
83
  navbar,
83
84
  ...withdraw,
84
85
  websocket,
86
+ ranking,
85
87
  }
@@ -1,6 +1,5 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import common from '../api/common.js'
3
- import game from '../api/game.js'
4
3
 
5
4
  export default function (request) {
6
5
  const { appSecret } = request.config
@@ -9,38 +8,15 @@ export default function (request) {
9
8
  id: 'navbar',
10
9
  initial: 'fetching',
11
10
  context: {
12
- navbar: [],
13
- gameCodes: [],
11
+ navbar: null,
14
12
  },
15
13
  states: {
16
14
  fetching: {
17
15
  invoke: {
18
16
  src: 'fetchNavbar',
19
- onDone: [
20
- {
21
- target: 'checking',
22
- actions: ['setNavbar', 'filterGameCodes'],
23
- cond: 'haveGames',
24
- },
25
- {
26
- target: 'idle',
27
- actions: 'setNavbar',
28
- },
29
- ],
30
- onError: {
31
- target: 'idle',
32
- },
33
- },
34
- },
35
- checking: {
36
- always: [{ target: 'combinning', cond: (context, event) => context.gameCodes?.length > 0 }, { target: 'idle' }],
37
- },
38
- combinning: {
39
- invoke: {
40
- src: 'getGameInfo',
41
17
  onDone: {
42
18
  target: 'idle',
43
- actions: 'combindGames',
19
+ actions: 'setNavbar',
44
20
  },
45
21
  onError: {
46
22
  target: 'idle',
@@ -58,47 +34,6 @@ export default function (request) {
58
34
  navbar: navbarConfig.settings,
59
35
  }
60
36
  }),
61
- filterGameCodes: assign((context, event) => {
62
- const { navbar = [] } = context
63
- const gameCodes = navbar.reduce((acc, item) => {
64
- if (item.type.toLowerCase() === 'game' && item.gameCode) {
65
- acc.push(item.gameCode)
66
- }
67
- return acc
68
- }, [])
69
-
70
- return { gameCodes }
71
- }),
72
- combindGames: assign((context, event) => {
73
- const gameInfo = event.data?.data || []
74
- const { navbar = [] } = context
75
- const combindNavBar = navbar.map((item) => {
76
- if (item.type.toLowerCase() === 'game') {
77
- const currentGame = gameInfo.find((game) => game.gameCode === item.gameCode)
78
- return {
79
- ...item,
80
- ...currentGame,
81
- }
82
- } else {
83
- return item
84
- }
85
- })
86
-
87
- return {
88
- navbar: combindNavBar,
89
- }
90
- }),
91
- },
92
- guards: {
93
- haveGames: (context, event) => {
94
- const { navbarConfig = {} } = event.data
95
- const { settings = [] } = navbarConfig
96
- if (settings?.length) {
97
- return settings.some((item) => item.type.toLowerCase() === 'game')
98
- } else {
99
- return false
100
- }
101
- },
102
37
  },
103
38
  services: {
104
39
  fetchNavbar: async (context, event) => {
@@ -116,10 +51,6 @@ export default function (request) {
116
51
  )
117
52
  return { navbarConfig: JSON.parse(decodeResult) }
118
53
  },
119
- getGameInfo: async (context, event) => {
120
- const { gameCodes } = context
121
- return await request.send(game.getV3GameInfo({ appSecret, gameCodes }))
122
- },
123
54
  },
124
55
  }
125
56
  )
@@ -0,0 +1,202 @@
1
+ import { createMachine, assign } from 'xstate'
2
+ import ranking from '../api/ranking.js'
3
+
4
+ export default function (request) {
5
+ const cycleMapping = ['DAILY', 'WEEKLY', 'MONTHLY']
6
+
7
+ function roundProcess(rounds) {
8
+ const roundArrays = rounds.map((round) => Array.from({ length: round }, (_, i) => i + 1))
9
+ return roundArrays.reduce((acc, roundArray, index) => {
10
+ acc[cycleMapping[index]] = roundArray.reverse()
11
+ return acc
12
+ }, {})
13
+ }
14
+
15
+ function transGameData(item) {
16
+ if (!item) return {}
17
+ item.providerId = item.provider
18
+ return item
19
+ }
20
+
21
+ return createMachine(
22
+ {
23
+ id: 'ranking',
24
+ initial: 'idle',
25
+ context: {
26
+ auth: false,
27
+ activityNo: '',
28
+ // api options 回傳的資料
29
+ currentRound: [],
30
+ cycle: '',
31
+ round: 0,
32
+ rule: '',
33
+ // api detail 資料
34
+ description: '',
35
+ descriptionUrl: [],
36
+ // api detail 排名資料
37
+ playerRanking: {},
38
+ gameRanking: [],
39
+ topRanking: [],
40
+ settleStatus: false,
41
+ // 前端這邊用的選單資料 { cycle, round }
42
+ options: {},
43
+ },
44
+ states: {
45
+ idle: {
46
+ on: {
47
+ SET_ACTIVITY: {
48
+ target: 'loading',
49
+ },
50
+ SET_OPTIONS: {
51
+ target: 'setting',
52
+ },
53
+ },
54
+ },
55
+ loading: {
56
+ entry: 'setActivity',
57
+ always: [{ target: 'getRankingOptions', cond: 'hasAuth' }, { target: 'getTournament' }],
58
+ },
59
+ setting: {
60
+ entry: 'setOptions',
61
+ always: [{ target: 'getRankingDetail' }],
62
+ },
63
+ // 未登入時取得排名資料
64
+ getTournament: {
65
+ invoke: {
66
+ src: 'fetchTournament',
67
+ onDone: {
68
+ target: 'idle',
69
+ actions: 'setRanking',
70
+ },
71
+ onError: {
72
+ target: 'idle',
73
+ },
74
+ },
75
+ },
76
+ // 登入後取得排名選單資料
77
+ getRankingOptions: {
78
+ invoke: {
79
+ src: 'fetchRankingOptions',
80
+ onDone: {
81
+ target: 'getRankingGames',
82
+ actions: 'setRankingOptions',
83
+ },
84
+ onError: {
85
+ target: 'idle',
86
+ },
87
+ },
88
+ },
89
+ // 登入後取得排名資料
90
+ getRankingDetail: {
91
+ invoke: {
92
+ src: 'fetchRankingDetail',
93
+ onDone: {
94
+ target: 'idle',
95
+ actions: 'setRanking',
96
+ },
97
+ onError: {
98
+ target: 'idle',
99
+ },
100
+ },
101
+ },
102
+ getRankingGames: {
103
+ invoke: {
104
+ src: 'fetchRankingGames',
105
+ onDone: {
106
+ target: 'getRankingDetail',
107
+ actions: 'setRankingGames',
108
+ },
109
+ onError: {
110
+ target: 'idle',
111
+ },
112
+ },
113
+ },
114
+ },
115
+ },
116
+ {
117
+ actions: {
118
+ setActivity: assign((context, event) => {
119
+ return {
120
+ auth: !!request.getToken(),
121
+ activityNo: event.data?.activityNo,
122
+ }
123
+ }),
124
+ setRanking: assign((context, event) => {
125
+ const topRanking = event.data?.topRanking?.map((rank) => transGameData(rank)) || []
126
+ return {
127
+ description: event.data?.description,
128
+ descriptionUrl: event.data?.descriptionUrl,
129
+ topRanking: topRanking,
130
+ playerRanking: transGameData(event.data?.playerRanking) || {},
131
+ settleStatus: !!topRanking[0]?.settleStatus,
132
+ }
133
+ }),
134
+ setRankingGames: assign((context, event) => {
135
+ const gameRanking = event.data?.map((rank) => transGameData(rank))
136
+ return {
137
+ gameRanking: gameRanking || [],
138
+ }
139
+ }),
140
+ setRankingOptions: assign((context, event) => {
141
+ const cycle = event.data?.cycle
142
+ const currentRound = event.data?.currentRound || []
143
+ // 取得結算週期選單列表
144
+ const cycleOptions = cycleMapping.slice(0, currentRound.length)
145
+ // 取得每週期的歷史期數選單列表
146
+ const roundOptions = roundProcess(currentRound)
147
+ // 如果是月結算,則加入全部選項
148
+ if (cycle === 'MONTHLY') {
149
+ cycleOptions.push('ALL')
150
+ roundOptions.ALL = roundOptions.MONTHLY
151
+ }
152
+ return {
153
+ ...event.data,
154
+ options: { cycle: cycleOptions, round: roundOptions },
155
+ // 初始固定顯示 DAILY
156
+ cycle: event.data?.rule !== 'NORMAL' ? 'DAILY' : cycle,
157
+ round: currentRound[0],
158
+ }
159
+ }),
160
+ setOptions: assign((context, event) => {
161
+ const { cycle, round } = context
162
+ // 處理變更 cycle,如果沒有輸入或沒有變更就不更新
163
+ if (event.data?.cycle && cycle !== event.data?.cycle) {
164
+ const { currentRound } = context
165
+ const cycleForRound = event.data?.cycle === 'ALL' ? 'MONTHLY' : event.data?.cycle
166
+ const cycleIndex = cycleMapping.indexOf(cycleForRound)
167
+ return { cycle: event.data?.cycle, round: currentRound[cycleIndex] }
168
+ }
169
+ if (event.data?.round && round !== event.data?.round) {
170
+ return { round: event.data?.round }
171
+ }
172
+ return {}
173
+ }),
174
+ },
175
+ guards: {
176
+ hasAuth: (context) => context.auth,
177
+ },
178
+ services: {
179
+ fetchTournament: async (context) => {
180
+ const { activityNo } = context
181
+ const { data } = await request.send(ranking.getTournament({ activityNo }))
182
+ return data
183
+ },
184
+ fetchRankingOptions: async (context) => {
185
+ const { activityNo } = context
186
+ const { data } = await request.send(ranking.getRankingOptions({ activityNo }))
187
+ return data
188
+ },
189
+ fetchRankingDetail: async (context, event) => {
190
+ const { activityNo, cycle, round } = context
191
+ const { data } = await request.send(ranking.getRankingDetail({ activityNo, cycle, round }))
192
+ return data
193
+ },
194
+ fetchRankingGames: async (context) => {
195
+ const { activityNo } = context
196
+ const { data } = await request.send(ranking.getRankingGames({ activityNo }))
197
+ return data
198
+ },
199
+ },
200
+ }
201
+ )
202
+ }