@jetthai/cuora 1.1.365 → 1.1.366-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 +6 -0
- package/package.json +1 -1
- package/resetGitBranch.sh +0 -10
- package/src/api/game.js +12 -0
- package/src/lib/{fingerprint_v3_11_5.js → fingerprint_v3_11_12.js} +3749 -4212
- package/src/machine/auth.js +7 -4
- package/src/machine/common.js +3 -2
- package/src/machine/game_betslip.js +46 -0
- package/src/machine/index.js +2 -0
- package/src/machine/user_sign_up.js +2 -2
- package/src/util/deviceToken.js +26 -2
- package/src/util/index.js +2 -2
- package/src/util/sessionStorage.js +28 -0
package/src/machine/auth.js
CHANGED
|
@@ -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 {
|
|
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
|
|
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
|
|
521
|
-
|
|
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
|
},
|
package/src/machine/common.js
CHANGED
|
@@ -3,6 +3,7 @@ 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'
|
|
6
7
|
|
|
7
8
|
export default function (request) {
|
|
8
9
|
const { appSecret, defaultChannel, defaultSubchannel } = request.config
|
|
@@ -258,7 +259,7 @@ export default function (request) {
|
|
|
258
259
|
const channel = urlParams.get('channel') || storage.get('channel') || defaultChannel || 'official'
|
|
259
260
|
const subchannel = urlParams.get('subchannel') || storage.get('subchannel') || defaultSubchannel || 'pwa'
|
|
260
261
|
const affiliateCode = urlParams.get('ac') || urlParams.get('referralCode') || storage.get('ac') || storage.get('referralCode')
|
|
261
|
-
const friendCode = urlParams.get('fc') || urlParams.get('affiliate') ||
|
|
262
|
+
const friendCode = urlParams.get('fc') || urlParams.get('affiliate') || sessionStorage.get('fc') || sessionStorage.get('affiliate')
|
|
262
263
|
|
|
263
264
|
storage.set('channel', channel, {
|
|
264
265
|
path: '/',
|
|
@@ -272,7 +273,7 @@ export default function (request) {
|
|
|
272
273
|
path: '/',
|
|
273
274
|
maxAge: 60 * 60 * 24 * 7,
|
|
274
275
|
})
|
|
275
|
-
|
|
276
|
+
sessionStorage.set('fc', friendCode, {
|
|
276
277
|
path: '/',
|
|
277
278
|
maxAge: 60 * 60 * 24 * 7,
|
|
278
279
|
})
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
}
|
package/src/machine/index.js
CHANGED
|
@@ -10,6 +10,7 @@ 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'
|
|
13
14
|
import inbox from './inbox.js'
|
|
14
15
|
import merge from './merge.js'
|
|
15
16
|
import payment_data from './payment_data.js'
|
|
@@ -53,6 +54,7 @@ export default {
|
|
|
53
54
|
game_hot_new,
|
|
54
55
|
game_info,
|
|
55
56
|
game_replay,
|
|
57
|
+
game_betslip,
|
|
56
58
|
inbox,
|
|
57
59
|
merge,
|
|
58
60
|
payment_data,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assign, createMachine } from 'xstate'
|
|
2
2
|
import auth from '../api/auth.js'
|
|
3
|
-
import {
|
|
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
|
|
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 = {
|
package/src/util/deviceToken.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import uniqBy from 'lodash/uniqBy'
|
|
2
|
-
import { load, defaultEndpoint } from '../lib/
|
|
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
|
-
|
|
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 }
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
}
|