@jetthai/cuora 1.1.366-dev-11 → 1.1.366-v2api-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.
@@ -3,7 +3,7 @@ import { assign, createMachine } from 'xstate'
3
3
  import auth from '../api/auth.js'
4
4
  import user from '../api/user.js'
5
5
  import storage from '../util/storage.js'
6
- import { getDeviceTokenWithRetry } from '../util/deviceToken.js'
6
+ import { getDeviceToken } from '../util/deviceToken.js'
7
7
  import common from '../api/common.js'
8
8
  import pickBy from 'lodash/pickBy.js'
9
9
 
@@ -432,7 +432,7 @@ export default function (request) {
432
432
  const { provider, channel, subchannel, fc } = event.data
433
433
  const deviceTokenEnable = context.siteConfig?.dtVerify
434
434
 
435
- const dt = await getDeviceTokenWithRetry({
435
+ const dt = await getDeviceToken({
436
436
  fpToken,
437
437
  sentry,
438
438
  hosts: request.hosts,
@@ -517,11 +517,8 @@ export default function (request) {
517
517
  if (deviceTokenEnable) {
518
518
  const { exist } = await request.send(user.checkDt())
519
519
  if (!exist) {
520
- const dt = await getDeviceTokenWithRetry({ fpToken, sentry, hosts: request.hosts, enable: deviceTokenEnable })
521
- // 確定有dt再取得updateDt
522
- if (dt) {
523
- await request.send(user.updateDt({ dt }))
524
- }
520
+ const dt = await getDeviceToken({ fpToken, sentry, hosts: request.hosts, enable: deviceTokenEnable })
521
+ await request.send(user.updateDt({ dt }))
525
522
  }
526
523
  }
527
524
  },
@@ -3,7 +3,6 @@ import { assign, createMachine } from 'xstate'
3
3
  import pickBy from 'lodash/pickBy.js'
4
4
  import api from '../api/common.js'
5
5
  import storage from '../util/storage.js'
6
- import sessionStorage from '../util/sessionStorage.js'
7
6
 
8
7
  export default function (request) {
9
8
  const { appSecret, defaultChannel, defaultSubchannel } = request.config
@@ -259,7 +258,7 @@ export default function (request) {
259
258
  const channel = urlParams.get('channel') || storage.get('channel') || defaultChannel || 'official'
260
259
  const subchannel = urlParams.get('subchannel') || storage.get('subchannel') || defaultSubchannel || 'pwa'
261
260
  const affiliateCode = urlParams.get('ac') || urlParams.get('referralCode') || storage.get('ac') || storage.get('referralCode')
262
- const friendCode = urlParams.get('fc') || urlParams.get('affiliate') || sessionStorage.get('fc') || sessionStorage.get('affiliate')
261
+ const friendCode = urlParams.get('fc') || urlParams.get('affiliate') || storage.get('fc') || storage.get('affiliate')
263
262
 
264
263
  storage.set('channel', channel, {
265
264
  path: '/',
@@ -273,7 +272,7 @@ export default function (request) {
273
272
  path: '/',
274
273
  maxAge: 60 * 60 * 24 * 7,
275
274
  })
276
- sessionStorage.set('fc', friendCode, {
275
+ storage.set('fc', friendCode, {
277
276
  path: '/',
278
277
  maxAge: 60 * 60 * 24 * 7,
279
278
  })
@@ -247,9 +247,6 @@ export default function (request) {
247
247
  CLEAR: {
248
248
  actions: 'hideMessage',
249
249
  },
250
- SET_LANG: {
251
- actions: 'setLang',
252
- },
253
250
  },
254
251
  },
255
252
  {
@@ -279,10 +276,6 @@ export default function (request) {
279
276
  },
280
277
  },
281
278
  actions: {
282
- setLang: assign((context, event) => {
283
- const lang = event.data.locale || context.lang || 'en-US'
284
- return { lang }
285
- }),
286
279
  reset: assign((context, event) => {
287
280
  return {
288
281
  currentTab: null,
@@ -422,10 +415,9 @@ export default function (request) {
422
415
  return tabs
423
416
  },
424
417
  fetchMessages: async (context, event) => {
425
- const lang = context.lang
426
418
  const { isRewardListEnable, currentTab, inbox } = JSON.parse(JSON.stringify(context))
427
- if (isRewardListEnable && (currentTab === 'REWARD' || currentTab === 'DIAMOND' || currentTab === 'FREE_GAME')) {
428
- const { data } = await request.send(activity.getRewardList({ count: 30, appSecret, lang }))
419
+ if (isRewardListEnable && (currentTab === 'REWARD' || currentTab === 'DIAMOND')) {
420
+ const { data } = await request.send(activity.getRewardList({ count: 30, appSecret }))
429
421
  inbox[currentTab] = { data, page: 0, totalPage: 1 }
430
422
  } else {
431
423
  const { page = -1 } = inbox[currentTab] || {}
@@ -438,9 +430,6 @@ export default function (request) {
438
430
  },
439
431
  reFetchMessages: async (context, event) => {
440
432
  const { currentTab, inbox } = JSON.parse(JSON.stringify(context))
441
-
442
- if (currentTab === 'FREE_GAME') return inbox
443
-
444
433
  const { data, ...rest } = await request.send(mailbox.getMessageList({ type: currentTab, page: 0 }))
445
434
  let formattedData = []
446
435
  formattedData = data?.map((item) => ({ ...item, isSelected: false }))
@@ -10,7 +10,6 @@ import game_search_v2 from './game_search_v2.js'
10
10
  import game_hot_new from './game_hot_new.js'
11
11
  import game_info from './game_info.js'
12
12
  import game_replay from './game_replay.js'
13
- import game_betslip from './game_betslip.js'
14
13
  import inbox from './inbox.js'
15
14
  import merge from './merge.js'
16
15
  import payment_data from './payment_data.js'
@@ -54,7 +53,6 @@ export default {
54
53
  game_hot_new,
55
54
  game_info,
56
55
  game_replay,
57
- game_betslip,
58
56
  inbox,
59
57
  merge,
60
58
  payment_data,
@@ -2,7 +2,7 @@ import { createMachine, assign, send } from 'xstate'
2
2
  import activity from '../api/activity.js'
3
3
  import payment from '../api/payment.js'
4
4
 
5
- export default function (request, context) {
5
+ export default function (request) {
6
6
  const { appSecret } = request.config
7
7
  return createMachine(
8
8
  {
@@ -19,7 +19,6 @@ export default function (request, context) {
19
19
  isPlaying: false,
20
20
  callback: () => {},
21
21
  orderColumn: 'createTime',
22
- lang: context?.locale,
23
22
  },
24
23
  states: {
25
24
  timer: {
@@ -73,9 +72,6 @@ export default function (request, context) {
73
72
  SET_IS_PLAYING: {
74
73
  actions: 'setIsPlaying',
75
74
  },
76
- SET_LANG: {
77
- actions: 'setLang',
78
- },
79
75
  },
80
76
  },
81
77
  fetching: {
@@ -197,10 +193,6 @@ export default function (request, context) {
197
193
  isPlaying: event.data,
198
194
  }
199
195
  }),
200
- setLang: assign((context, event) => {
201
- const lang = event.data.locale || context.lang || 'en-US'
202
- return { lang }
203
- }),
204
196
  },
205
197
  guards: {
206
198
  isPrize: (context, event) => {
@@ -213,24 +205,22 @@ export default function (request, context) {
213
205
  },
214
206
  services: {
215
207
  fetchRewardList: async (context, event) => {
216
- const lang = context.lang
217
208
  const orderColumn = context.orderColumn
218
- const getRewardAPI = request.send(activity.getRewardList({ count: 30, appSecret, lang }))
219
- const getPointsRewardAPI = request.send(activity.getRewardList({ rewardType: 'POINTS', count: 30, appSecret, lang }))
220
- const getOtherRewardAPI = request.send(activity.getRewardList({ rewardType: 'CASH,FREE,PRIZE', count: 30, appSecret, orderColumn, lang }))
209
+ const getRewardAPI = request.send(activity.getRewardList({ count: 30, appSecret }))
210
+ const getPointsRewardAPI = request.send(activity.getRewardList({ rewardType: 'POINTS', count: 30, appSecret }))
211
+ const getOtherRewardAPI = request.send(activity.getRewardList({ rewardType: 'CASH,FREE,PRIZE', count: 30, appSecret, orderColumn }))
221
212
  const [otherRewardList, pointsRewardList, rewardList] = await Promise.all([getOtherRewardAPI, getPointsRewardAPI, getRewardAPI])
222
213
  return [otherRewardList, pointsRewardList, rewardList]
223
214
  },
224
215
  fetchOtherRewardList: async (context, event) => {
225
216
  const orderColumn = context.orderColumn
226
- const lang = context.lang
217
+
227
218
  const getOtherRewardAPI = request.send(
228
219
  activity.getRewardList({
229
220
  rewardType: 'CASH,FREE,PRIZE',
230
221
  count: 30,
231
222
  appSecret,
232
223
  orderColumn,
233
- lang,
234
224
  })
235
225
  )
236
226
  const [otherRewardList] = await Promise.all([getOtherRewardAPI])
@@ -2,7 +2,7 @@ import { createMachine, assign, send } from 'xstate'
2
2
  import activity from '../api/activity.js'
3
3
  import payment from '../api/payment.js'
4
4
 
5
- export default function (request, context) {
5
+ export default function (request) {
6
6
  const { appSecret } = request.config
7
7
  return createMachine(
8
8
  {
@@ -18,7 +18,6 @@ export default function (request, context) {
18
18
  withdrawRule: {},
19
19
  callback: () => {},
20
20
  orderColumn: 'createTime',
21
- lang: context?.locale,
22
21
  },
23
22
  states: {
24
23
  timer: {
@@ -79,9 +78,6 @@ export default function (request, context) {
79
78
  target: 'allPointsReceiving',
80
79
  actions: 'setCallback',
81
80
  },
82
- SET_LANG: {
83
- actions: 'setLang',
84
- },
85
81
  },
86
82
  },
87
83
  fetching: {
@@ -205,22 +201,16 @@ export default function (request, context) {
205
201
  withdrawRule: event.data,
206
202
  }
207
203
  }),
208
- setLang: assign((context, event) => {
209
- const lang = event.data.locale || context.lang || 'en-US'
210
- return { lang }
211
- }),
212
204
  },
213
205
  services: {
214
206
  fetchRewardList: async (context, event) => {
215
- const lang = context.lang
216
- const getRewardAPI = request.send(activity.getRewardList({ count: 30, appSecret, lang }))
207
+ const getRewardAPI = request.send(activity.getRewardList({ count: 30, appSecret }))
217
208
  const orderColumn = context.orderColumn
218
209
  const getPointsRewardAPI = request.send(
219
210
  activity.getRewardList({
220
211
  rewardType: 'POINTS',
221
212
  count: 30,
222
213
  appSecret,
223
- lang,
224
214
  })
225
215
  )
226
216
  const getOtherRewardAPI = request.send(
@@ -229,7 +219,6 @@ export default function (request, context) {
229
219
  count: 30,
230
220
  appSecret,
231
221
  orderColumn,
232
- lang,
233
222
  })
234
223
  )
235
224
  const [otherRewardList, pointsRewardList, rewardList] = await Promise.all([getOtherRewardAPI, getPointsRewardAPI, getRewardAPI])
@@ -237,14 +226,13 @@ export default function (request, context) {
237
226
  },
238
227
  fetchOtherRewardList: async (context, event) => {
239
228
  const orderColumn = context.orderColumn
240
- const lang = context.lang
229
+
241
230
  const getOtherRewardAPI = request.send(
242
231
  activity.getRewardList({
243
232
  rewardType: 'CASH,FREE,PRIZE',
244
233
  count: 30,
245
234
  appSecret,
246
235
  orderColumn,
247
- lang,
248
236
  })
249
237
  )
250
238
  const [otherRewardList] = await Promise.all([getOtherRewardAPI])
@@ -1,6 +1,6 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import auth from '../api/auth.js'
3
- import { getDeviceTokenWithRetry } from '../util/deviceToken.js'
3
+ import { getDeviceToken } from '../util/deviceToken.js'
4
4
  import storage from '../util/storage.js'
5
5
 
6
6
  export default function (request) {
@@ -200,7 +200,7 @@ export default function (request) {
200
200
  services: {
201
201
  authenticate: async (context, event) => {
202
202
  const { channel, subchannel, signUpData, deviceTokenEnable } = context
203
- const dt = await getDeviceTokenWithRetry({ fpToken, sentry, hosts: request.hosts, enable: deviceTokenEnable })
203
+ const dt = await getDeviceToken({ fpToken, sentry, hosts: request.hosts, enable: deviceTokenEnable })
204
204
 
205
205
  const affiliateCode = storage.get('ac') || signUpData?.affiliateCode
206
206
  const messages = {
@@ -149,7 +149,6 @@ export default class Request {
149
149
  this.key = `cuora_${config.clientId}`
150
150
  this.errorHandler = null
151
151
  this.hosts = []
152
- this.isBlocked = false
153
152
  this.initialize()
154
153
  }
155
154
 
@@ -193,16 +192,6 @@ export default class Request {
193
192
  }
194
193
 
195
194
  async send(req, customToken) {
196
- // console.log('*查看請求的API', this.isBlocked, req)
197
- // 終止所有的請求,除了維護頁需要的資料(siteConfig)
198
- if (this.isBlocked && req.url !== 'getConfig') {
199
- console.log('%c*禁止API請求', 'color: #00ff33ff; font-weight: bold;')
200
- throw {
201
- code: 'ERR_BLOCKED',
202
- message: 'All API calls are blocked due to previous critical error',
203
- url: req.url,
204
- }
205
- }
206
195
  try {
207
196
  const cancelToken = customToken || this.source.token
208
197
  this._checkToken(req)
@@ -210,12 +199,6 @@ export default class Request {
210
199
  const { data } = await this.axios.request(requestConfig)
211
200
  return data
212
201
  } catch (error) {
213
- if (error.code === 'ERR_F108') {
214
- console.log('%c*維護中', 'color: #00ff33ff; font-weight: bold;')
215
- this.isBlocked = true
216
- this.errorHandler && this.errorHandler(error)
217
- throw error
218
- }
219
202
  if (error.code !== 'ERR_800') {
220
203
  if (error.code) {
221
204
  this.errorHandler && this.errorHandler(error)
@@ -251,15 +234,12 @@ export default class Request {
251
234
  return supportedUrl === cleanUrl
252
235
  })
253
236
 
254
- // 如果站點是ZAZA或ZAZAAPP,則不支援V2版本的API
255
- const supportV2Toggle = ['ZAZA', 'ZAZAAPP'].includes(this.config?.clientId)
256
-
257
- if (isV2Supported && !supportV2Toggle) {
237
+ if (isV2Supported) {
258
238
  fullURL = fullURL.replace('/v1/', '/v2/')
259
239
  urlName = this._convertUrlToKebabCase(url)
260
- // console.log(`*[DEV_ONLY]V2`, 'url:', urlName)
240
+ console.log(`*[DEV_ONLY]V2`, 'url:', urlName)
261
241
  } else {
262
- // console.log(`*[DEV_ONLY]V2-不支援:`, 'url:', urlName)
242
+ console.log(`*[DEV_ONLY]V2-不支援:`, 'url:', urlName)
263
243
  }
264
244
 
265
245
  if (isFormData) {
@@ -1,5 +1,5 @@
1
1
  import uniqBy from 'lodash/uniqBy'
2
- import { load, defaultEndpoint } from '../lib/fingerprint_v3_11_12.js'
2
+ import { load, defaultEndpoint } from '../lib/fingerprint_v3_11_5.js'
3
3
 
4
4
  const reg = /fnapi\d*/
5
5
 
@@ -32,28 +32,4 @@ const getDeviceToken = async ({ fpToken, sentry, hosts, enable = true }) => {
32
32
  }
33
33
  }
34
34
 
35
- // 重試機制,最多嘗試 maxRetries 次,每次間隔 intervalMs 毫秒
36
- const getDeviceTokenWithRetry = async ({ fpToken, sentry, hosts, enable = true, maxRetries = 3, intervalMs = 1000 }) => {
37
- if (!enable) {
38
- return
39
- }
40
- // 設置幾秒後重試
41
- const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
42
- // 設定重試次數
43
- for (let attempt = 1; attempt <= maxRetries; attempt++) {
44
- try {
45
- const deviceToken = await getDeviceToken({ fpToken, sentry, hosts, enable })
46
- if (deviceToken) return deviceToken
47
- throw new Error('No device token received')
48
- } catch (error) {
49
- // 若失敗則等待intervalMs後重試,最多重試maxRetries次
50
- if (attempt < maxRetries) {
51
- await delay(intervalMs)
52
- } else {
53
- throw error
54
- }
55
- }
56
- }
57
- }
58
-
59
- export { getDeviceToken, getDeviceTokenWithRetry }
35
+ export { getDeviceToken }
package/src/util/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { getDeviceToken, getDeviceTokenWithRetry } from './deviceToken.js'
1
+ import { getDeviceToken } from './deviceToken.js'
2
2
  import storage from './storage.js'
3
3
  import * as constant from './constant.js'
4
4
  import { max } from './math.js'
5
5
 
6
- export default { getDeviceToken, getDeviceTokenWithRetry }
6
+ export default { getDeviceToken }
7
7
  export { constant, storage, max }
@@ -1,12 +1,6 @@
1
1
  export default {
2
2
  get(name, options) {
3
- let itemStr = null
4
- try {
5
- itemStr = localStorage.getItem(name)
6
- } catch (error) {
7
- console.error(`Error getting item from localStorage: ${error}`)
8
- return null
9
- }
3
+ const itemStr = localStorage.getItem(name)
10
4
 
11
5
  if (!itemStr) {
12
6
  return null
@@ -18,7 +12,7 @@ export default {
18
12
  return null
19
13
  }
20
14
 
21
- return 'value' in item ? item.value : item
15
+ return item.value
22
16
  },
23
17
  set(name, value, options) {
24
18
  const item = { value }
@@ -26,17 +20,9 @@ export default {
26
20
  if (options?.maxAge) {
27
21
  item.expiry = new Date().getTime() + options.maxAge * 1000
28
22
  }
29
- try {
30
- localStorage.setItem(name, JSON.stringify(item))
31
- } catch (error) {
32
- console.error(`Error setting item in localStorage: ${error}`)
33
- }
23
+ localStorage.setItem(name, JSON.stringify(item))
34
24
  },
35
25
  remove(name, options) {
36
- try {
37
- localStorage.removeItem(name)
38
- } catch (error) {
39
- console.error(`Error removing item from localStorage: ${error}`)
40
- }
26
+ localStorage.removeItem(name)
41
27
  },
42
28
  }
@@ -1,46 +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_betslip',
10
- initial: 'fetching',
11
- context: {
12
- gameBetSlip: {},
13
- },
14
- states: {
15
- fetching: {
16
- invoke: {
17
- src: 'fetchBetslip',
18
- onDone: {
19
- target: 'idle',
20
- actions: 'setBetslip',
21
- },
22
- onError: {
23
- target: 'idle',
24
- },
25
- },
26
- },
27
- idle: {},
28
- },
29
- },
30
- {
31
- actions: {
32
- setBetslip: assign((context, event) => {
33
- return {
34
- gameBetSlip: event.data,
35
- }
36
- }),
37
- },
38
- services: {
39
- // 取得遊戲注單
40
- fetchBetslip: async (context, event) => {
41
- return await request.send(game.getBetslip({ providerId, seqNo, lang, appSecret }))
42
- },
43
- },
44
- }
45
- )
46
- }
@@ -1,28 +0,0 @@
1
- export default {
2
- get(name, options) {
3
- const itemStr = sessionStorage.getItem(name)
4
-
5
- if (!itemStr) {
6
- return null
7
- }
8
-
9
- const item = JSON.parse(itemStr)
10
- if (item.expiry && new Date().getTime() > item.expiry) {
11
- sessionStorage.removeItem(name)
12
- return null
13
- }
14
-
15
- return item.value
16
- },
17
- set(name, value, options) {
18
- const item = { value }
19
-
20
- if (options?.maxAge) {
21
- item.expiry = new Date().getTime() + options.maxAge * 1000
22
- }
23
- sessionStorage.setItem(name, JSON.stringify(item))
24
- },
25
- remove(name, options) {
26
- sessionStorage.removeItem(name)
27
- },
28
- }