@jetthai/cuora 1.1.366-dev-1 → 1.1.366-dev-3

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 { getDeviceToken } from '../util/deviceToken.js'
6
+ import { getDeviceTokenWithRetry } 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 getDeviceToken({
435
+ const dt = await getDeviceTokenWithRetry({
436
436
  fpToken,
437
437
  sentry,
438
438
  hosts: request.hosts,
@@ -517,8 +517,11 @@ 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 getDeviceToken({ fpToken, sentry, hosts: request.hosts, enable: deviceTokenEnable })
521
- await request.send(user.updateDt({ dt }))
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
+ }
522
525
  }
523
526
  }
524
527
  },
@@ -247,6 +247,9 @@ export default function (request) {
247
247
  CLEAR: {
248
248
  actions: 'hideMessage',
249
249
  },
250
+ SET_LANG: {
251
+ actions: 'setLang',
252
+ },
250
253
  },
251
254
  },
252
255
  {
@@ -276,6 +279,10 @@ export default function (request) {
276
279
  },
277
280
  },
278
281
  actions: {
282
+ setLang: assign((context, event) => {
283
+ const lang = event.data.locale || context.lang || 'en-US'
284
+ return { lang }
285
+ }),
279
286
  reset: assign((context, event) => {
280
287
  return {
281
288
  currentTab: null,
@@ -415,9 +422,10 @@ export default function (request) {
415
422
  return tabs
416
423
  },
417
424
  fetchMessages: async (context, event) => {
425
+ const lang = context.lang
418
426
  const { isRewardListEnable, currentTab, inbox } = JSON.parse(JSON.stringify(context))
419
427
  if (isRewardListEnable && (currentTab === 'REWARD' || currentTab === 'DIAMOND')) {
420
- const { data } = await request.send(activity.getRewardList({ count: 30, appSecret }))
428
+ const { data } = await request.send(activity.getRewardList({ count: 30, appSecret, lang }))
421
429
  inbox[currentTab] = { data, page: 0, totalPage: 1 }
422
430
  } else {
423
431
  const { page = -1 } = inbox[currentTab] || {}
@@ -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) {
5
+ export default function (request, context) {
6
6
  const { appSecret } = request.config
7
7
  return createMachine(
8
8
  {
@@ -19,6 +19,7 @@ export default function (request) {
19
19
  isPlaying: false,
20
20
  callback: () => {},
21
21
  orderColumn: 'createTime',
22
+ lang: context?.locale,
22
23
  },
23
24
  states: {
24
25
  timer: {
@@ -72,6 +73,9 @@ export default function (request) {
72
73
  SET_IS_PLAYING: {
73
74
  actions: 'setIsPlaying',
74
75
  },
76
+ SET_LANG: {
77
+ actions: 'setLang',
78
+ },
75
79
  },
76
80
  },
77
81
  fetching: {
@@ -193,6 +197,10 @@ export default function (request) {
193
197
  isPlaying: event.data,
194
198
  }
195
199
  }),
200
+ setLang: assign((context, event) => {
201
+ const lang = event.data.locale || context.lang || 'en-US'
202
+ return { lang }
203
+ }),
196
204
  },
197
205
  guards: {
198
206
  isPrize: (context, event) => {
@@ -205,22 +213,24 @@ export default function (request) {
205
213
  },
206
214
  services: {
207
215
  fetchRewardList: async (context, event) => {
216
+ const lang = context.lang
208
217
  const orderColumn = context.orderColumn
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 }))
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 }))
212
221
  const [otherRewardList, pointsRewardList, rewardList] = await Promise.all([getOtherRewardAPI, getPointsRewardAPI, getRewardAPI])
213
222
  return [otherRewardList, pointsRewardList, rewardList]
214
223
  },
215
224
  fetchOtherRewardList: async (context, event) => {
216
225
  const orderColumn = context.orderColumn
217
-
226
+ const lang = context.lang
218
227
  const getOtherRewardAPI = request.send(
219
228
  activity.getRewardList({
220
229
  rewardType: 'CASH,FREE,PRIZE',
221
230
  count: 30,
222
231
  appSecret,
223
232
  orderColumn,
233
+ lang,
224
234
  })
225
235
  )
226
236
  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) {
5
+ export default function (request, context) {
6
6
  const { appSecret } = request.config
7
7
  return createMachine(
8
8
  {
@@ -18,6 +18,7 @@ export default function (request) {
18
18
  withdrawRule: {},
19
19
  callback: () => {},
20
20
  orderColumn: 'createTime',
21
+ lang: context?.locale,
21
22
  },
22
23
  states: {
23
24
  timer: {
@@ -78,6 +79,9 @@ export default function (request) {
78
79
  target: 'allPointsReceiving',
79
80
  actions: 'setCallback',
80
81
  },
82
+ SET_LANG: {
83
+ actions: 'setLang',
84
+ },
81
85
  },
82
86
  },
83
87
  fetching: {
@@ -201,16 +205,22 @@ export default function (request) {
201
205
  withdrawRule: event.data,
202
206
  }
203
207
  }),
208
+ setLang: assign((context, event) => {
209
+ const lang = event.data.locale || context.lang || 'en-US'
210
+ return { lang }
211
+ }),
204
212
  },
205
213
  services: {
206
214
  fetchRewardList: async (context, event) => {
207
- const getRewardAPI = request.send(activity.getRewardList({ count: 30, appSecret }))
215
+ const lang = context.lang
216
+ const getRewardAPI = request.send(activity.getRewardList({ count: 30, appSecret, lang }))
208
217
  const orderColumn = context.orderColumn
209
218
  const getPointsRewardAPI = request.send(
210
219
  activity.getRewardList({
211
220
  rewardType: 'POINTS',
212
221
  count: 30,
213
222
  appSecret,
223
+ lang,
214
224
  })
215
225
  )
216
226
  const getOtherRewardAPI = request.send(
@@ -219,6 +229,7 @@ export default function (request) {
219
229
  count: 30,
220
230
  appSecret,
221
231
  orderColumn,
232
+ lang,
222
233
  })
223
234
  )
224
235
  const [otherRewardList, pointsRewardList, rewardList] = await Promise.all([getOtherRewardAPI, getPointsRewardAPI, getRewardAPI])
@@ -226,13 +237,14 @@ export default function (request) {
226
237
  },
227
238
  fetchOtherRewardList: async (context, event) => {
228
239
  const orderColumn = context.orderColumn
229
-
240
+ const lang = context.lang
230
241
  const getOtherRewardAPI = request.send(
231
242
  activity.getRewardList({
232
243
  rewardType: 'CASH,FREE,PRIZE',
233
244
  count: 30,
234
245
  appSecret,
235
246
  orderColumn,
247
+ lang,
236
248
  })
237
249
  )
238
250
  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 { getDeviceToken } from '../util/deviceToken.js'
3
+ import { getDeviceTokenWithRetry } 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 getDeviceToken({ fpToken, sentry, hosts: request.hosts, enable: deviceTokenEnable })
203
+ const dt = await getDeviceTokenWithRetry({ fpToken, sentry, hosts: request.hosts, enable: deviceTokenEnable })
204
204
 
205
205
  const affiliateCode = storage.get('ac') || signUpData?.affiliateCode
206
206
  const messages = {
@@ -1,5 +1,5 @@
1
1
  import uniqBy from 'lodash/uniqBy'
2
- import { load, defaultEndpoint } from '../lib/fingerprint_v3_11_5.js'
2
+ import { load, defaultEndpoint } from '../lib/fingerprint_v3_11_12.js'
3
3
 
4
4
  const reg = /fnapi\d*/
5
5
 
@@ -32,4 +32,28 @@ const getDeviceToken = async ({ fpToken, sentry, hosts, enable = true }) => {
32
32
  }
33
33
  }
34
34
 
35
- export { getDeviceToken }
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 }
package/src/util/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { getDeviceToken } from './deviceToken.js'
1
+ import { getDeviceToken, getDeviceTokenWithRetry } 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 }
6
+ export default { getDeviceToken, getDeviceTokenWithRetry }
7
7
  export { constant, storage, max }