@jetthai/cuora 1.0.193-2 → 1.0.194

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,9 +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.0.193-2](https://github.com/jetthai/cuora-module/compare/v1.0.193-1...v1.0.193-2) (2022-11-02)
6
-
7
- ### [1.0.193-1](https://github.com/jetthai/cuora-module/compare/v1.0.193...v1.0.193-1) (2022-11-01)
5
+ ### [1.0.194](https://github.com/jetthai/cuora-module/compare/v1.0.193...v1.0.194) (2022-10-28)
8
6
 
9
7
  ### [1.0.193](https://github.com/jetthai/cuora-module/compare/v1.0.192...v1.0.193) (2022-10-26)
10
8
 
package/dist/bundle.mjs CHANGED
@@ -7366,7 +7366,6 @@ function sign_in_activity (request) {
7366
7366
  {
7367
7367
  actions: {
7368
7368
  setActivityNo: assign((context, event) => {
7369
- console.log('Event:', event.data);
7370
7369
  return {
7371
7370
  activityNo: event.data,
7372
7371
  }
@@ -7744,42 +7743,33 @@ var urlJoin = {exports: {}};
7744
7743
 
7745
7744
  var urljoin = urlJoin.exports;
7746
7745
 
7747
- // import Cookies from 'universal-cookie'
7746
+ var storage = {
7747
+ get(name, options) {
7748
+ const itemStr = localStorage.getItem(name);
7748
7749
 
7749
- // const cookies = new Cookies()
7750
+ if (!itemStr) {
7751
+ return null
7752
+ }
7750
7753
 
7751
- var storage = {
7752
- get(name, options) {
7753
- //return cookies.get(name, options)
7754
-
7755
- const itemStr = localStorage.getItem(name);
7756
-
7757
- if (!itemStr) {
7758
- return null
7759
- }
7760
-
7761
- const item = JSON.parse(itemStr);
7762
- if (new Date().getTime() > item.expiry) {
7763
- localStorage.removeItem(name);
7764
- return null
7765
- }
7766
-
7767
- return item.value
7768
- },
7769
- set(name, value, options) {
7770
- // cookies.set(name, value, options)
7754
+ const item = JSON.parse(itemStr);
7755
+ if (item.expiry && new Date().getTime() > item.expiry) {
7756
+ localStorage.removeItem(name);
7757
+ return null
7758
+ }
7771
7759
 
7772
- const item = {
7773
- value,
7774
- expiry: new Date().getTime() + (options.maxAge || 0)*1000
7775
- };
7776
- localStorage.setItem(name, JSON.stringify(item));
7777
- },
7778
- remove(name, options) {
7779
- // cookies.remove(name, options)
7780
-
7781
- localStorage.removeItem(name);
7782
- }
7760
+ return item.value
7761
+ },
7762
+ set(name, value, options) {
7763
+ const item = {value};
7764
+
7765
+ if (options.maxAge) {
7766
+ item.expiry = new Date().getTime() + options.maxAge * 1000;
7767
+ }
7768
+ localStorage.setItem(name, JSON.stringify(item));
7769
+ },
7770
+ remove(name, options) {
7771
+ localStorage.removeItem(name);
7772
+ }
7783
7773
  };
7784
7774
 
7785
7775
  /*! *****************************************************************************
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.0.193-2",
3
+ "version": "1.0.194",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
package/src/api/game.js CHANGED
@@ -10,13 +10,12 @@ export default {
10
10
  logoutGame: ({ uid_site, provider_id }) => ({ url: 'game/logout', method: 'get', params: { uid_site, provider_id } }),
11
11
 
12
12
  getGameTags: ({ q }) => ({ url: 'game/search', method: 'get', params: { q } }),
13
- getGameSearchHome: () => ({ url: 'game/search/home', method: 'get' }),
14
13
  getGameSearchList: ({ id, index, q, click, clickDefault }) => ({
15
14
  url: 'game/search/list',
16
15
  method: 'get',
17
16
  params: { id, index, q, click, clickDefault },
18
17
  }),
19
- setGameSearchTrace: ({ traceId, tagId, tagIndex, gameCode, gameCodeIndex, query, click, clickDefault, isYouMayLike, isRecentlyGame, isRecentlySearch }) => ({
18
+ setGameSearchTrace: ({ traceId, tagId, tagIndex, gameCode, gameCodeIndex, query, click, clickDefault }) => ({
20
19
  url: 'game/search/trace',
21
20
  method: 'post',
22
21
  params: {
@@ -28,9 +27,6 @@ export default {
28
27
  query,
29
28
  click,
30
29
  clickDefault,
31
- isYouMayLike,
32
- isRecentlyGame,
33
- isRecentlySearch
34
30
  },
35
31
  }),
36
32
  gameHistory: ({ requestTimestamp, lang, provider, type }) => ({
@@ -20,7 +20,7 @@ export default function (request) {
20
20
  src: 'fetchActivityList',
21
21
  onDone: {
22
22
  target: 'pending',
23
- actions: ['setActivityList', 'setActivityUnread', 'setTournamentList'],
23
+ actions: ['setActivityList', 'setTournamentList'],
24
24
  },
25
25
  onError: {
26
26
  target: 'pending',
@@ -45,31 +45,10 @@ export default function (request) {
45
45
  }
46
46
  }),
47
47
  setActivityList: assign((context, event) => {
48
- const noRedActivity = [2, 4, 13, 20, 91, 92]
49
- let list = event.data
50
- list.forEach(activity => {
51
- if (noRedActivity.includes(activity.activityType)) {
52
- activity.unread = false
53
- } else {
54
- activity.unread = true
55
- }
56
- })
57
48
  return {
58
- activityList: list,
49
+ activityList: event.data,
59
50
  }
60
51
  }),
61
- setActivityUnread: assign((context, event) => {
62
- const { activityList = [] } = context
63
- activityList.forEach(item => {
64
- const storageUnread = localStorage.getItem(`activity_${item.activityNo}`)
65
- if (storageUnread) {
66
- item.unread = JSON.parse(storageUnread)
67
- }
68
- })
69
- return {
70
- activityList
71
- }
72
- })
73
52
  },
74
53
  delays: {
75
54
  TIMEOUT: (context, event) => {
@@ -9,7 +9,6 @@ import game_v2 from './game_v2.js'
9
9
  import game_favorite from './game_favorite.js'
10
10
  import game_favorite_v2 from './game_favorite_v2.js'
11
11
  import game_search from './game_search.js'
12
- import game_search_v2 from './game_search_v2.js'
13
12
  import game_hot_new from './game_hot_new.js'
14
13
  import inbox from './inbox.js'
15
14
  import merge from './merge.js'
@@ -46,7 +45,6 @@ export default {
46
45
  game_favorite,
47
46
  game_favorite_v2,
48
47
  game_search,
49
- game_search_v2,
50
48
  game_hot_new,
51
49
  inbox,
52
50
  merge,
@@ -1,37 +1,28 @@
1
- // import Cookies from 'universal-cookie'
1
+ export default {
2
+ get(name, options) {
3
+ const itemStr = localStorage.getItem(name)
2
4
 
3
- // const cookies = new Cookies()
5
+ if (!itemStr) {
6
+ return null
7
+ }
4
8
 
5
- export default {
6
- get(name, options) {
7
- //return cookies.get(name, options)
8
-
9
- const itemStr = localStorage.getItem(name)
10
-
11
- if (!itemStr) {
12
- return null
13
- }
14
-
15
- const item = JSON.parse(itemStr)
16
- if (new Date().getTime() > item.expiry) {
17
- localStorage.removeItem(name)
18
- return null
19
- }
20
-
21
- return item.value
22
- },
23
- set(name, value, options) {
24
- // cookies.set(name, value, options)
9
+ const item = JSON.parse(itemStr)
10
+ if (item.expiry && new Date().getTime() > item.expiry) {
11
+ localStorage.removeItem(name)
12
+ return null
13
+ }
14
+
15
+ return item.value
16
+ },
17
+ set(name, value, options) {
18
+ const item = {value}
25
19
 
26
- const item = {
27
- value,
28
- expiry: new Date().getTime() + (options.maxAge || 0)*1000
20
+ if (options.maxAge) {
21
+ item.expiry = new Date().getTime() + options.maxAge * 1000
22
+ }
23
+ localStorage.setItem(name, JSON.stringify(item))
24
+ },
25
+ remove(name, options) {
26
+ localStorage.removeItem(name)
29
27
  }
30
- localStorage.setItem(name, JSON.stringify(item))
31
- },
32
- remove(name, options) {
33
- // cookies.remove(name, options)
34
-
35
- localStorage.removeItem(name)
36
- }
37
28
  }
@@ -1,353 +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
- initial: 'preset',
9
- context: {
10
- keyword: '',
11
- tagId: null,
12
- mainTagList: [],
13
- tagList: [],
14
- gameList: [],
15
- recentlySearch: [],
16
- recentlyGame: [],
17
- youMayLike: [],
18
- // 以下變數為數據分析用
19
- selectedType: null,
20
- tagIndex: null,
21
- click: null,
22
- clickDefault: null,
23
- traceId: null,
24
- isYouMayLike: null,
25
- isRecentlyGame: null,
26
- isRecentlySearch: null,
27
- gameCode: null,
28
- },
29
- states: {
30
- preset: {
31
- invoke: {
32
- src: 'fetchTags',
33
- onDone: {
34
- target: 'loading',
35
- actions: 'setMainTagList',
36
- },
37
- onError: {
38
- target: 'fail',
39
- },
40
- },
41
- },
42
- loading: {
43
- invoke: {
44
- src: 'fetchInitialData',
45
- onDone: {
46
- target: 'idle',
47
- actions: 'setInitialData',
48
- },
49
- onError: {
50
- target: '#game_search_v2.fail',
51
- },
52
- },
53
- },
54
- idle: {
55
- on: {
56
- SET_MAIN_TAG_ID: {
57
- target: 'setGameList',
58
- actions: ['setMainTagId', 'setTraceData']
59
- },
60
- PLAY_GAME: {
61
- target: 'sendingTrace',
62
- actions: 'setGameCode',
63
- },
64
- START_SEARCH: {
65
- target: 'searching',
66
- actions: 'clearKeyword',
67
- },
68
- CLEAR_MAIN_TAG: {
69
- actions: 'clearMainTag',
70
- }
71
- },
72
- },
73
- setGameList: {
74
- always: [
75
- {
76
- target: 'idle',
77
- actions: 'setGames',
78
- cond: 'isRecentlyYouMayLike'
79
- },
80
- {
81
- target: 'fetchGameList',
82
- }
83
- ]
84
- },
85
- fetchGameList: {
86
- invoke: {
87
- src: 'fetchGames',
88
- onDone: {
89
- target: 'idle',
90
- actions: 'setGames',
91
- },
92
- onError: {
93
- target: '#game_search_v2.fail',
94
- },
95
- },
96
- },
97
- searching: {
98
- initial: 'searchIdle',
99
- states: {
100
- searchIdle: {
101
- on: {
102
- SET_TAG_ID: {
103
- target: '#game_search_v2.fetchGameList',
104
- actions: ['setTagId', 'setTraceData']
105
- },
106
- PRESS_ENTER: [
107
- {
108
- actions: send((context, event) => ({
109
- type: 'SET_TAG_ID',
110
- data: {
111
- tagId: context.tagList[0]?.id,
112
- traceData: {
113
- isYouMayLike: null,
114
- isRecentlyGame: null,
115
- isRecentlySearch: null
116
- }
117
- }
118
- })),
119
- cond: 'hasTagList',
120
- },
121
- {
122
- target: '#game_search_v2.sendingTrace',
123
- actions: 'clearExceptKeyword',
124
- },
125
- ],
126
- SET_KEYWORD: {
127
- target: 'debouncing',
128
- actions: 'setKeyword',
129
- },
130
- STOP_SEARCH: {
131
- target: '#game_search_v2.idle',
132
- actions: 'clearKeywords'
133
- },
134
- },
135
- },
136
- debouncing: {
137
- on: {
138
- SET_KEYWORD: {
139
- target: 'debouncing',
140
- actions: 'setKeyword',
141
- },
142
- },
143
- after: {
144
- 500: {
145
- target: 'fetching',
146
- },
147
- },
148
- },
149
- fetching: {
150
- invoke: {
151
- src: 'fetchTags',
152
- onDone: {
153
- target: 'searchIdle',
154
- actions: 'setTagList',
155
- },
156
- onError: {
157
- target: '#game_search_v2.fail',
158
- },
159
- },
160
- },
161
- },
162
- },
163
- sendingTrace: {
164
- invoke: {
165
- src: 'sendTrace',
166
- onDone: {
167
- target: 'idle',
168
- },
169
- onError: {
170
- target: 'fail',
171
- },
172
- },
173
- },
174
- fail: {},
175
- },
176
- },
177
- {
178
- actions: {
179
- setMainTagList: assign((context, event) => {
180
- return {
181
- mainTagList: event.data,
182
- }
183
- }),
184
- setInitialData: assign((context, event) => {
185
- const { recentlySearch = [], recentlyGame = [], youMayLike = [] } = event.data
186
- let tagId = null
187
- let gameList = []
188
- if (recentlyGame?.length > 0) {
189
- gameList = recentlyGame
190
- } else if (youMayLike?.length > 0) {
191
- gameList = youMayLike
192
- }
193
- return {
194
- recentlySearch: recentlySearch.filter(item => item.id && item.i18n),
195
- recentlyGame,
196
- youMayLike,
197
- gameList,
198
- tagId
199
- }
200
- }),
201
- setMainTagId: assign((context, event) => {
202
- const { tagId } = event.data
203
- const { mainTagList } = context
204
- const tagIndex = mainTagList.findIndex((tag) => tag.id === tagId)
205
- return {
206
- keyword: '',
207
- tagId,
208
- tagIndex,
209
- click: 1,
210
- clickDefault: null,
211
- }
212
- }),
213
- clearMainTag: assign((context, event) => {
214
- return {
215
- tagId: null,
216
- }
217
- }),
218
- setTagId: assign((context, event) => {
219
- const { tagId, clickTagType } = event.data
220
- const { mainTagList, tagList, recentlySearch } = context
221
- if (clickTagType === 'RECENTLY SEARCH') {
222
- const tagIndex = recentlySearch.findIndex((tag) => tag.id === tagId)
223
- return {
224
- tagId,
225
- tagIndex,
226
- click: 1,
227
- clickDefault: null,
228
- }
229
- } else if (clickTagType === 'POPULAR KEYWORDS' || tagList.length <= 0) {
230
- const tagIndex = mainTagList.findIndex((tag) => tag.id === tagId)
231
- return {
232
- tagId,
233
- tagIndex,
234
- click: null,
235
- clickDefault: 1,
236
- }
237
- } else {
238
- const tagIndex = tagList.findIndex((tag) => tag.id === tagId)
239
- return {
240
- tagId,
241
- tagIndex,
242
- click: 1,
243
- clickDefault: null,
244
- }
245
- }
246
- }),
247
- setGames: assign((context, event) => {
248
- if (event?.data) {
249
- const { traceId, result } = event.data
250
- return {
251
- traceId,
252
- gameList: result,
253
- }
254
- } else {
255
- const { tagId, recentlyGame, youMayLike } = context
256
- let gameList = []
257
- if (tagId === 'RECENTLY') {
258
- gameList = recentlyGame
259
- } else if (tagId === 'YOU MAY LIKE') {
260
- gameList = youMayLike
261
- }
262
- return {
263
- traceId: null,
264
- gameList,
265
- }
266
- }
267
- }),
268
- setTraceData: assign((context, event) => {
269
- const { isYouMayLike, isRecentlyGame, isRecentlySearch } = event.data?.traceData
270
- return {
271
- isYouMayLike,
272
- isRecentlyGame,
273
- isRecentlySearch,
274
- }
275
- }),
276
- setKeyword: assign((context, event) => {
277
- return {
278
- keyword: event.data,
279
- }
280
- }),
281
- clearKeywords: assign((context, event) => {
282
- return {
283
- keyword: '',
284
- }
285
- }),
286
- setTagList: assign((context, event) => {
287
- return {
288
- tagList: event.data,
289
- }
290
- }),
291
- setGameCode: assign((context, event) => {
292
- const { gameList } = context
293
- const gameCode = event.data
294
- const gameCodeIndex = gameList.findIndex((game) => game === gameCode)
295
- return {
296
- gameCode,
297
- gameCodeIndex,
298
- }
299
- }),
300
- clearExceptKeyword: assign((context, event) => {
301
- return {
302
- gameList: [],
303
- traceId: null,
304
- tagId: null,
305
- tagIndex: null,
306
- gameCode: null,
307
- gameCodeIndex: null,
308
- isYouMayLike: null,
309
- isRecentlyGame: null,
310
- isRecentlySearch: null,
311
- query: context.keyword,
312
- click: null,
313
- clickDefault: null,
314
- }
315
- }),
316
- },
317
- guards: {
318
- isRecentlyYouMayLike: (context, event) => {
319
- const { tagId } = context
320
- return tagId === 'RECENTLY' || tagId === 'YOU MAY LIKE'
321
- },
322
- hasTagList: (context, event) => {
323
- const { tagList } = context
324
- return tagList?.length > 0
325
- },
326
- },
327
- services: {
328
- fetchTags: async (context, event) => {
329
- const { keyword } = context
330
- const { result } = await request.send(game.getGameTags({ q: keyword }))
331
- return result
332
- },
333
- fetchInitialData: async (context, event) => {
334
- const data = await request.send(game.getGameSearchHome())
335
- return data
336
- },
337
- fetchGames: async (context, event) => {
338
- const { tagId, tagIndex, keyword, click, clickDefault } = context
339
- const { traceId, result } = await request.send(game.getGameSearchList({ id: tagId, index: tagIndex, q: keyword, click, clickDefault }))
340
- return { traceId, result }
341
- },
342
- sendTrace: async (context, event) => {
343
- const { traceId, tagId, tagIndex, gameCode, gameCodeIndex, keyword: query, click, clickDefault, isYouMayLike, isRecentlyGame, isRecentlySearch } = context
344
- let id = tagId
345
- if (tagId === 'RECENTLY' || tagId === 'YOU MAY LIKE') {
346
- id = null
347
- }
348
- return await request.send(game.setGameSearchTrace({ traceId, tagId: id, tagIndex, gameCode, gameCodeIndex, query, click, clickDefault, isYouMayLike, isRecentlyGame, isRecentlySearch }))
349
- },
350
- },
351
- }
352
- )
353
- }