@jetthai/cuora 1.1.346-dev-3 → 1.1.346-dev-2

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,8 +2,6 @@
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-dev-3](https://github.com/jetthai/cuora-module/compare/v1.1.346-dev-2...v1.1.346-dev-3) (2025-03-30)
6
-
7
5
  ### [1.1.346-dev-2](https://github.com/jetthai/cuora-module/compare/v1.1.346-dev-1...v1.1.346-dev-2) (2025-03-28)
8
6
 
9
7
  ### [1.1.346-dev-1](https://github.com/jetthai/cuora-module/compare/v1.1.346...v1.1.346-dev-1) (2025-03-28)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.1.346-dev-3",
3
+ "version": "1.1.346-dev-2",
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
  }
@@ -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
  },
@@ -284,6 +286,63 @@ export default function (request) {
284
286
  },
285
287
  },
286
288
  },
289
+ oldTimer: {
290
+ initial: 'fetchingGameSHA',
291
+ states: {
292
+ fetchingGameSHA: {
293
+ invoke: {
294
+ src: 'fetchGameSHA',
295
+ onDone: {
296
+ target: 'checking',
297
+ actions: 'setGameSHA',
298
+ },
299
+ onError: {
300
+ target: 'pending',
301
+ },
302
+ },
303
+ },
304
+ checking: {
305
+ always: [{ target: 'updatingStatus', cond: 'isStatusChanged' }, { target: 'pending' }],
306
+ },
307
+ updatingStatus: {
308
+ invoke: {
309
+ src: 'fetchStatus',
310
+ onDone: {
311
+ target: 'updatingOption',
312
+ actions: ['setStatus'],
313
+ },
314
+ onError: {
315
+ target: 'pending',
316
+ },
317
+ },
318
+ },
319
+ updatingOption: {
320
+ invoke: {
321
+ src: 'fetchOption',
322
+ onDone: {
323
+ target: 'pending',
324
+ actions: 'mergeOption',
325
+ },
326
+ onError: {
327
+ target: 'pending',
328
+ },
329
+ },
330
+ },
331
+ pending: {
332
+ after: {
333
+ 20000: [
334
+ {
335
+ target: 'fetchingGameSHA',
336
+ cond: 'isNotInGame',
337
+ },
338
+ {
339
+ target: 'pending',
340
+ },
341
+ ],
342
+ },
343
+ },
344
+ },
345
+ },
287
346
  },
288
347
  },
289
348
  {
@@ -400,6 +459,9 @@ export default function (request) {
400
459
  return event.data.gameWalletType
401
460
  },
402
461
  }),
462
+ clearGameInfo: assign((context, event) => {
463
+ return { game: { providerId: null, gameId: null, gameTypeId: null, mappingId: null } }
464
+ }),
403
465
  setGameInfo: assign((context, event) => {
404
466
  const { providerId, gameId, gameTypeId, mappingId, portrait, gameCode, name } = event.data.game
405
467
  return { game: { providerId, gameId, gameTypeId, mappingId, portrait: portrait ? 1 : 0, gameCode, name } }
@@ -433,6 +495,7 @@ export default function (request) {
433
495
  isPlaying: event.data,
434
496
  }
435
497
  }),
498
+ ...oldActions,
436
499
  },
437
500
  guards: {
438
501
  isDifferentRoom: (context, event) => context.room?.categoryId !== event.data?.categoryId,
@@ -441,9 +504,13 @@ export default function (request) {
441
504
  // 是否有下一頁
442
505
  return loadable && !isLastPage
443
506
  },
507
+ isNotInGame: (context, event) => {
508
+ return !context.isPlaying
509
+ },
444
510
  hasRoomAndIsNotInGame: (context, event) => {
445
511
  return context.room?.categoryId && !context.isPlaying
446
512
  },
513
+ ...oldGuards,
447
514
  },
448
515
  services: {
449
516
  batchFetch: async (context, event) => {
@@ -571,7 +638,75 @@ export default function (request) {
571
638
  const provider_id = context.game.providerId
572
639
  return await request.send(api.logoutGame({ uid_site, provider_id }))
573
640
  },
641
+ ...oldServices(request),
574
642
  },
575
643
  }
576
644
  )
577
645
  }
646
+
647
+ const oldContext = {
648
+ sha: {
649
+ status: null,
650
+ },
651
+ isStatusChanged: false,
652
+ statusMap: {},
653
+ optionMap: {},
654
+ }
655
+
656
+ const oldActions = {
657
+ setGameSHA: assign((context, event) => {
658
+ const { sha } = context
659
+ const newSha = event.data
660
+ return {
661
+ sha: newSha,
662
+ isStatusChanged: !sha.status || sha.status !== newSha.status,
663
+ }
664
+ }),
665
+ setStatus: assign((context, event) => {
666
+ return {
667
+ statusMap: event.data,
668
+ }
669
+ }),
670
+ mergeOption: assign((context, event) => {
671
+ const { optionMap } = context
672
+ return {
673
+ optionMap: { ...optionMap, ...event.data },
674
+ }
675
+ }),
676
+ resetSHA: assign((context, event) => {
677
+ return {
678
+ sha: {
679
+ status: null,
680
+ },
681
+ isStatusChanged: false,
682
+ statusMap: {},
683
+ optionMap: {},
684
+ }
685
+ }),
686
+ }
687
+
688
+ const oldGuards = {
689
+ isStatusChanged: (context, event) => context.isStatusChanged,
690
+ }
691
+
692
+ const oldServices = (request) => ({
693
+ fetchOption: async (context, event) => {
694
+ if (request.getToken()) {
695
+ return await request.send(api.getOptionMap())
696
+ }
697
+ },
698
+ fetchGameSHA: async (context, event) => {
699
+ if (request.getToken()) {
700
+ return await request.send(api.getGameSHA())
701
+ } else {
702
+ return {
703
+ status: null,
704
+ }
705
+ }
706
+ },
707
+ fetchStatus: async (context, event) => {
708
+ if (request.getToken()) {
709
+ return await request.send(api.getGameStatus())
710
+ }
711
+ },
712
+ })
@@ -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
  )