@jetthai/cuora 1.1.488 → 1.2.0
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/.husky/pre-commit +3 -1
- package/CHANGELOG.md +0 -349
- package/README.md +15 -299
- package/package.json +3 -6
- package/resetGitBranch.sh +101 -0
- package/src/api/activity.js +39 -24
- package/src/api/auth.js +35 -4
- package/src/api/common.js +1 -8
- package/src/api/game.js +10 -0
- package/src/api/index.js +1 -3
- package/src/api/payment.js +55 -17
- package/src/api/user.js +16 -11
- package/src/index.js +2 -2
- package/src/lib/fingerprint_v3_11_12.js +11433 -0
- package/src/machine/activity/activity.js +209 -0
- package/src/machine/activity/activity_cash.js +18 -71
- package/src/machine/activity/diamond_shop_activity_cash.js +1 -0
- package/src/machine/activity/diamond_shop_activity_fc.js +196 -0
- package/src/machine/activity/diamond_shop_activity_vn.js +178 -0
- package/src/machine/activity/fafafa_activity.js +10 -0
- package/src/machine/activity/index.js +12 -0
- package/src/machine/activity/invite_friends_activity.js +114 -0
- package/src/machine/activity/mini_game_activity.js +68 -0
- package/src/machine/activity/return_bonus_activity.js +153 -0
- package/src/machine/activity/roulette_activity_v2.js +0 -5
- package/src/machine/auth.js +109 -158
- package/src/machine/auth_otp_v2.js +177 -0
- package/src/machine/auth_otp_v3.js +32 -111
- package/src/machine/bank_binding.js +2 -2
- package/src/machine/bank_binding_amb.js +145 -0
- package/src/machine/bonus.js +75 -0
- package/src/machine/common.js +91 -27
- package/src/machine/deposit/amb.js +92 -0
- package/src/machine/deposit/crypto_bank.js +325 -0
- package/src/machine/deposit/crypto_bank_cash.js +8 -19
- package/src/machine/deposit/crypto_qrcode.js +148 -0
- package/src/machine/deposit/crypto_qrcode_cash.js +41 -26
- package/src/machine/deposit/crypto_way.js +247 -0
- package/src/machine/deposit/crypto_way_cash.js +32 -52
- package/src/machine/deposit/deposit_fc.js +271 -0
- package/src/machine/deposit/direct.js +310 -0
- package/src/machine/deposit/direct_cash.js +9 -8
- package/src/machine/deposit/float.js +374 -0
- package/src/machine/deposit/index.js +28 -0
- package/src/machine/deposit/krway.js +151 -0
- package/src/machine/deposit/loadcard_cash.js +31 -14
- package/src/machine/deposit/loadcard_vn.js +351 -0
- package/src/machine/deposit/manual_cash.js +10 -8
- package/src/machine/deposit/manual_vn.js +458 -0
- package/src/machine/deposit/qrcode_cash.js +30 -14
- package/src/machine/deposit/qrcode_v2.js +338 -0
- package/src/machine/deposit/usdt.js +144 -0
- package/src/machine/deposit/virtual_bank_cash.js +2 -5
- package/src/machine/deposit/virtual_bank_vn.js +269 -0
- package/src/machine/deposit/vpay.js +367 -0
- package/src/machine/error.js +0 -7
- package/src/machine/game_hot_new.js +79 -0
- package/src/machine/game_info.js +12 -5
- package/src/machine/game_replay.js +46 -0
- package/src/machine/game_search_v2.js +401 -0
- package/src/machine/game_v2_1.js +88 -43
- package/src/machine/honor_board.js +132 -0
- package/src/machine/honor_board_cash.js +18 -15
- package/src/machine/inbox.js +12 -0
- package/src/machine/index.js +32 -0
- package/src/machine/leaderboard.js +11 -8
- package/src/machine/merge.js +57 -0
- package/src/machine/payment_data.js +86 -0
- package/src/machine/promotions.js +170 -0
- package/src/machine/ranking.js +25 -43
- package/src/machine/reward.js +255 -0
- package/src/machine/reward_cash.js +41 -2
- package/src/machine/reward_fc.js +98 -0
- package/src/machine/roulette_v2.js +25 -20
- package/src/machine/side.js +154 -0
- package/src/machine/side_cash.js +2 -3
- package/src/machine/side_v2.js +209 -0
- package/src/machine/user_reset_password.js +15 -4
- package/src/machine/user_sign_up.js +60 -46
- package/src/machine/vip_table.js +57 -0
- package/src/machine/websocket.js +325 -378
- package/src/machine/welcome.js +110 -0
- package/src/machine/withdraw/index.js +6 -0
- package/src/machine/withdraw/withdraw_crypto_cash.js +327 -0
- package/src/machine/withdraw/withdraw_krway.js +222 -0
- package/src/machine/withdraw/withdraw_manual.js +533 -0
- package/src/machine/withdraw/withdraw_manual_cash.js +38 -59
- package/src/request/config.js +0 -2
- package/src/request/request.js +62 -130
- package/src/util/constant.js +2 -6
- package/src/util/deviceToken.js +59 -0
- package/src/util/index.js +4 -2
- package/src/util/math.js +4 -0
- package/.claude/commands/sync-ai-prompts.md +0 -93
- package/.claude/settings.local.json +0 -23
- package/.github/copilot-instructions.md +0 -448
- package/.husky/post-checkout +0 -32
- package/.husky/pre-push +0 -36
- package/AGENTS.md +0 -448
- package/AI_PROMPT_SOURCE.md +0 -446
- package/CLAUDE.md +0 -448
- package/GEMINI.md +0 -448
- package/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +0 -1003
- package/docs/kibana/play-providerId-error.md +0 -202
- package/docs/kibana/play-selectedWalletType.md +0 -1
- package/docs/kibana/play-selectedWalletType_2.md +0 -1
- package/docs/kibana/play-selectedWalletType_analysis.md +0 -565
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/branch-transfer.md +0 -14
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-preparation.json +0 -40
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-verification.md +0 -41
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/implementation-ledger.md +0 -87
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/module-report.md +0 -73
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/plan.md +0 -309
- package/docs/my-claude/feat-sharon-JT-1790247240-socket/test-cases.md +0 -245
- package/docs/my-claude/feat-sharon-JT-1791180540-onesignal/transfer.md +0 -9
- package/scripts/auto-version.js +0 -68
- package/scripts/auto-version.sh +0 -33
- package/scripts/branch-auto-npm-publish.js +0 -29
- package/scripts/check-version.sh +0 -36
- package/scripts/clean-tags.sh +0 -84
- package/src/api/account.js +0 -7
- package/src/api/otp.js +0 -5
- package/src/util/amount.js +0 -8
- package/src/util/err998SentryExtra.js +0 -26
- package/src/util/paramStore.js +0 -139
- package/src/util/socketPolicy.js +0 -57
- package/test/auth_otp_v3.test.js +0 -323
- package/tests/websocket.test.mjs +0 -779
package/src/machine/auth.js
CHANGED
|
@@ -3,24 +3,18 @@ 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
7
|
import common from '../api/common.js'
|
|
7
8
|
import pickBy from 'lodash/pickBy.js'
|
|
8
|
-
import { readParamFromLocation, writeParam, normalize, AC_KEYS, FC_KEYS } from '../util/paramStore.js'
|
|
9
9
|
|
|
10
10
|
export default function (request) {
|
|
11
|
-
const { appSecret, clientId, sentry } = request.config
|
|
11
|
+
const { appSecret, clientId, fpToken, sentry, defaultChannel, defaultSubchannel } = request.config
|
|
12
12
|
const tokenKey = `cuora_${clientId}`
|
|
13
|
+
const userKey = `cuora_tempuser`
|
|
13
14
|
const phoneCountryCode = 'phone_countrycode'
|
|
14
15
|
const accountPhoneKey = 'account_phone'
|
|
15
16
|
const accountEmailKey = 'account_email'
|
|
16
17
|
const accountUsernameKey = 'account_username'
|
|
17
|
-
// loginMethods 的鍵 → setAccount 寫入的 storage key。
|
|
18
|
-
// LOGIN_ID 寫的是 accountUsernameKey,在 loginMethods 卻算 'local',此對照無法由 key 名反推。
|
|
19
|
-
const rememberedAccountKeys = [
|
|
20
|
-
['local', accountUsernameKey],
|
|
21
|
-
['phone', accountPhoneKey],
|
|
22
|
-
['email', accountEmailKey],
|
|
23
|
-
]
|
|
24
18
|
|
|
25
19
|
return createMachine(
|
|
26
20
|
{
|
|
@@ -46,7 +40,6 @@ export default function (request) {
|
|
|
46
40
|
redirectURL: null,
|
|
47
41
|
reCaptchaToken: null,
|
|
48
42
|
fc: null,
|
|
49
|
-
dt: null,
|
|
50
43
|
},
|
|
51
44
|
states: {
|
|
52
45
|
fetchingConfig: {
|
|
@@ -54,7 +47,7 @@ export default function (request) {
|
|
|
54
47
|
src: 'fetchSiteConfig',
|
|
55
48
|
onDone: {
|
|
56
49
|
target: 'idle',
|
|
57
|
-
actions:
|
|
50
|
+
actions: 'setSiteConfig',
|
|
58
51
|
},
|
|
59
52
|
onError: {
|
|
60
53
|
target: 'idle',
|
|
@@ -78,86 +71,40 @@ export default function (request) {
|
|
|
78
71
|
},
|
|
79
72
|
},
|
|
80
73
|
},
|
|
81
|
-
|
|
74
|
+
authenticationGuest: {
|
|
82
75
|
invoke: {
|
|
83
|
-
src: '
|
|
76
|
+
src: 'authenticateGuest',
|
|
84
77
|
onDone: {
|
|
85
|
-
target: '
|
|
86
|
-
actions:
|
|
78
|
+
target: 'authenticated',
|
|
79
|
+
actions: 'setToken',
|
|
87
80
|
},
|
|
88
81
|
onError: {
|
|
89
|
-
target: '
|
|
82
|
+
target: 'idle',
|
|
83
|
+
actions: 'removeToken',
|
|
90
84
|
},
|
|
91
85
|
},
|
|
92
86
|
},
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
target: 'fetching',
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
fetching: {
|
|
104
|
-
invoke: {
|
|
105
|
-
src: 'fetchUserInfo',
|
|
106
|
-
onDone: {
|
|
107
|
-
target: 'pending',
|
|
108
|
-
actions: ['setUserInfo', 'extendToken'],
|
|
109
|
-
},
|
|
110
|
-
onError: {
|
|
111
|
-
target: 'pending',
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
on: {
|
|
117
|
-
OTP_VERIFIED: {
|
|
118
|
-
target: 'bindBankChecking',
|
|
119
|
-
},
|
|
120
|
-
OTP_SKIP: {
|
|
121
|
-
target: 'bindBankChecking',
|
|
87
|
+
authenticationApp: {
|
|
88
|
+
invoke: {
|
|
89
|
+
src: 'authenticateApp',
|
|
90
|
+
onDone: {
|
|
91
|
+
target: 'authenticated',
|
|
92
|
+
actions: ['setToken'],
|
|
122
93
|
},
|
|
123
|
-
|
|
124
|
-
target: '
|
|
94
|
+
onError: {
|
|
95
|
+
target: 'idle',
|
|
96
|
+
actions: 'removeToken',
|
|
125
97
|
},
|
|
126
98
|
},
|
|
127
99
|
},
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
states: {
|
|
133
|
-
pending: {
|
|
134
|
-
after: {
|
|
135
|
-
TIMEOUT: {
|
|
136
|
-
target: 'fetching',
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
fetching: {
|
|
141
|
-
invoke: {
|
|
142
|
-
src: 'fetchUserInfo',
|
|
143
|
-
onDone: {
|
|
144
|
-
target: 'pending',
|
|
145
|
-
actions: ['setUserInfo', 'extendToken'],
|
|
146
|
-
},
|
|
147
|
-
onError: {
|
|
148
|
-
target: 'pending',
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
on: {
|
|
154
|
-
BIND_BANK_DONE: {
|
|
155
|
-
target: 'loginSuccess',
|
|
156
|
-
},
|
|
157
|
-
BIND_BANK_SKIP: {
|
|
100
|
+
authenticated: {
|
|
101
|
+
invoke: {
|
|
102
|
+
src: 'fetchUserInfo',
|
|
103
|
+
onDone: {
|
|
158
104
|
target: 'loginSuccess',
|
|
105
|
+
actions: ['setUserInfo', 'extendToken'],
|
|
159
106
|
},
|
|
160
|
-
|
|
107
|
+
onError: {
|
|
161
108
|
target: 'leaving',
|
|
162
109
|
},
|
|
163
110
|
},
|
|
@@ -217,12 +164,10 @@ export default function (request) {
|
|
|
217
164
|
initial: 'deviceTokenChecking',
|
|
218
165
|
states: {
|
|
219
166
|
deviceTokenChecking: {
|
|
220
|
-
entry: 'clearDeviceToken',
|
|
221
167
|
invoke: {
|
|
222
168
|
src: 'checkDeviceToken',
|
|
223
169
|
onDone: {
|
|
224
170
|
target: 'checkDeviceTokenDone',
|
|
225
|
-
actions: 'setDeviceToken',
|
|
226
171
|
},
|
|
227
172
|
onError: {
|
|
228
173
|
target: 'fetching',
|
|
@@ -302,6 +247,9 @@ export default function (request) {
|
|
|
302
247
|
CLEAR: {
|
|
303
248
|
target: '.logout',
|
|
304
249
|
},
|
|
250
|
+
LOGIN_GUEST: {
|
|
251
|
+
target: '.authenticationGuest',
|
|
252
|
+
},
|
|
305
253
|
LOGIN_ID: {
|
|
306
254
|
target: '.authentication',
|
|
307
255
|
actions: ['setReCaptchaToken', 'setLoginId'],
|
|
@@ -314,9 +262,16 @@ export default function (request) {
|
|
|
314
262
|
target: '.authentication',
|
|
315
263
|
actions: ['setReCaptchaToken', 'setLoginEmail'],
|
|
316
264
|
},
|
|
265
|
+
LOGIN_LOCAL: {
|
|
266
|
+
target: '.authentication',
|
|
267
|
+
actions: 'setLoginLocal',
|
|
268
|
+
},
|
|
317
269
|
LOGIN_3PARTY: {
|
|
318
270
|
actions: 'redirectTo3Party',
|
|
319
271
|
},
|
|
272
|
+
LOGIN_APP: {
|
|
273
|
+
target: '.authenticationApp',
|
|
274
|
+
},
|
|
320
275
|
LOGIN_TELEGRAM: {
|
|
321
276
|
target: '.authentication',
|
|
322
277
|
actions: 'setLoginTelegram',
|
|
@@ -351,19 +306,6 @@ export default function (request) {
|
|
|
351
306
|
siteConfig: { ...event.data, loginMethods: pickBy(loginMethods), registerMethods: pickBy(registerMethods) },
|
|
352
307
|
}
|
|
353
308
|
}),
|
|
354
|
-
// setAccount 寫入的帳號 TTL 是 31 天,且只互斥清除另外兩支 key,
|
|
355
|
-
// 後台關掉某種登入方式後殘值仍在,下游會把它回填進已改型別的輸入框(例如把 email 填進 phone-only 站台)。
|
|
356
|
-
// 非 assign action,故取得的是 setSiteConfig 套用後的 context。
|
|
357
|
-
pruneRememberedAccounts: (context) => {
|
|
358
|
-
// fetchSiteConfig 失敗會走 onError 不進到這裡;此處防的是回傳成功但 loginMethods 整包缺失,避免誤清全部記住的帳號。
|
|
359
|
-
const enabledMethods = context.siteConfig?.loginMethods
|
|
360
|
-
if (!enabledMethods || !Object.keys(enabledMethods).length) return
|
|
361
|
-
rememberedAccountKeys.forEach(([method, key]) => {
|
|
362
|
-
if (enabledMethods[method]) return
|
|
363
|
-
storage.remove(key)
|
|
364
|
-
if (method === 'phone') storage.remove(phoneCountryCode)
|
|
365
|
-
})
|
|
366
|
-
},
|
|
367
309
|
setReCaptchaToken: assign((context, event) => {
|
|
368
310
|
const { reCaptchaToken } = event.data
|
|
369
311
|
return {
|
|
@@ -402,15 +344,28 @@ export default function (request) {
|
|
|
402
344
|
},
|
|
403
345
|
}
|
|
404
346
|
}),
|
|
347
|
+
setLoginLocal: assign((context, event) => {
|
|
348
|
+
const { username, password } = event.data
|
|
349
|
+
storage.set(userKey, username, {
|
|
350
|
+
path: '/',
|
|
351
|
+
maxAge: 60 * 60 * 24,
|
|
352
|
+
})
|
|
353
|
+
return {
|
|
354
|
+
loginData: {
|
|
355
|
+
provider: 'local',
|
|
356
|
+
username,
|
|
357
|
+
password,
|
|
358
|
+
},
|
|
359
|
+
}
|
|
360
|
+
}),
|
|
405
361
|
setLoginTelegram: assign((context, event) => {
|
|
406
|
-
const { loginType, additionalUserInfo, isSignature
|
|
362
|
+
const { loginType, additionalUserInfo, isSignature } = event.data
|
|
407
363
|
return {
|
|
408
364
|
loginData: {
|
|
409
365
|
provider: 'telegram',
|
|
410
366
|
loginType,
|
|
411
367
|
additionalUserInfo,
|
|
412
368
|
isSignature,
|
|
413
|
-
idToken,
|
|
414
369
|
},
|
|
415
370
|
}
|
|
416
371
|
}),
|
|
@@ -429,13 +384,6 @@ export default function (request) {
|
|
|
429
384
|
token: event.data,
|
|
430
385
|
}
|
|
431
386
|
}),
|
|
432
|
-
setDeviceToken: assign((context, event) => {
|
|
433
|
-
return {
|
|
434
|
-
dt: event.data?.dt ?? null,
|
|
435
|
-
}
|
|
436
|
-
}),
|
|
437
|
-
// checkDeviceToken 失敗走 onError 不會執行 setDeviceToken,先清空避免下游讀到前一個帳號的 dt
|
|
438
|
-
clearDeviceToken: assign({ dt: null }),
|
|
439
387
|
setAccount: assign((context, event) => {
|
|
440
388
|
if (context.loginData.username) {
|
|
441
389
|
storage.remove(accountEmailKey)
|
|
@@ -470,7 +418,7 @@ export default function (request) {
|
|
|
470
418
|
path: '/',
|
|
471
419
|
maxAge: 300,
|
|
472
420
|
})
|
|
473
|
-
return { token: null
|
|
421
|
+
return { token: null }
|
|
474
422
|
}),
|
|
475
423
|
extendToken: assign((context, event) => {
|
|
476
424
|
const token = storage.get(tokenKey)
|
|
@@ -481,69 +429,64 @@ export default function (request) {
|
|
|
481
429
|
return { token }
|
|
482
430
|
}),
|
|
483
431
|
redirectTo3Party: async (context, event) => {
|
|
484
|
-
const { provider, fc } = event.data
|
|
432
|
+
const { provider, channel, subchannel, fc } = event.data
|
|
485
433
|
const deviceTokenEnable = context.siteConfig?.dtVerify
|
|
486
434
|
|
|
487
|
-
const dt =
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
const affiliateCode = hasExplicitAc ? normalize(event.data.ac) : acRead.value
|
|
494
|
-
// 宿主可能傳進字面 'undefined',先 normalize 才不會蓋掉網址/儲存層的真值
|
|
495
|
-
const friendCode = normalize(fc) || readParamFromLocation(FC_KEYS).value
|
|
496
|
-
|
|
497
|
-
// 本段結尾以 window.location.href 離站,離站後 SPA 記憶體全丟;導頁前先落地雙寫
|
|
498
|
-
writeParam('ac', affiliateCode, { sentry })
|
|
499
|
-
writeParam('fc', friendCode, { sentry })
|
|
435
|
+
const dt = await getDeviceTokenWithRetry({
|
|
436
|
+
fpToken,
|
|
437
|
+
sentry,
|
|
438
|
+
hosts: request.hosts,
|
|
439
|
+
enable: deviceTokenEnable,
|
|
440
|
+
})
|
|
500
441
|
|
|
442
|
+
const affiliateCode = storage.get('ac')
|
|
501
443
|
const nickname = storage.get('nk')
|
|
502
|
-
const phone = storage.get('tp_phone')
|
|
503
|
-
const countryCode = storage.get('tp_countryCode')
|
|
504
|
-
const email = storage.get('tp_email')
|
|
505
|
-
const birthday = storage.get('tp_birthday')
|
|
506
444
|
const messages = {
|
|
507
445
|
url: window.location.href,
|
|
446
|
+
channelOrders: [
|
|
447
|
+
{ channel: storage.get('channel'), subchannel: storage.get('subchannel') },
|
|
448
|
+
{ channel: defaultChannel, subchannel: defaultSubchannel },
|
|
449
|
+
{ channel: channel, subchannel: subchannel },
|
|
450
|
+
],
|
|
508
451
|
affiliateCode,
|
|
509
|
-
acSource: hasExplicitAc ? 'event' : acRead.from,
|
|
510
452
|
nickname,
|
|
511
453
|
}
|
|
454
|
+
sentry?.captureMessage(JSON.stringify(messages))
|
|
512
455
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
provider,
|
|
518
|
-
redirectURI: `${window.location.protocol}//${window.location.host}${context.base}`,
|
|
519
|
-
ac: affiliateCode,
|
|
520
|
-
nick_name: nickname,
|
|
521
|
-
phone,
|
|
522
|
-
countryCode,
|
|
523
|
-
email,
|
|
524
|
-
birthday,
|
|
525
|
-
dt,
|
|
526
|
-
platform: 'pwa',
|
|
527
|
-
fc: friendCode,
|
|
528
|
-
},
|
|
529
|
-
(value) => normalize(value) !== null
|
|
530
|
-
)
|
|
456
|
+
const referralObj = {}
|
|
457
|
+
if (![undefined, 'undefined', null, 'null'].includes(affiliateCode)) {
|
|
458
|
+
referralObj.ac = affiliateCode
|
|
459
|
+
}
|
|
531
460
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
// tp_birthday 不在此移除:client 於回站登入完成後以 /self 補交作為備援,由 client 消費後移除
|
|
461
|
+
if (![undefined, 'undefined', null, 'null'].includes(nickname)) {
|
|
462
|
+
referralObj.nick_name = nickname
|
|
463
|
+
}
|
|
536
464
|
|
|
537
|
-
|
|
465
|
+
referralObj.channel = storage.get('channel') || defaultChannel || channel
|
|
466
|
+
referralObj.subchannel = storage.get('subchannel') || defaultSubchannel || subchannel
|
|
538
467
|
|
|
539
|
-
|
|
468
|
+
// OZE、ZAZA 先使用 v2 測試 ,等待確認沒問題後再統一用 v2
|
|
469
|
+
// 但 ZALO 仍維持 v1
|
|
470
|
+
const fullURL =
|
|
471
|
+
['OZE', 'ZAZA'].includes(clientId) && provider !== 'zalo' ? request.config.fullURL.replace('/v1/', '/v2/') : request.config.fullURL
|
|
472
|
+
|
|
473
|
+
const redirectURL = urljoin(
|
|
474
|
+
fullURL,
|
|
475
|
+
'login?' +
|
|
476
|
+
new URLSearchParams({
|
|
477
|
+
provider,
|
|
478
|
+
redirectURI: `${window.location.protocol}//${window.location.host}${context.base}`,
|
|
479
|
+
...referralObj,
|
|
480
|
+
dt,
|
|
481
|
+
platform: 'pwa',
|
|
482
|
+
fc,
|
|
483
|
+
}).toString()
|
|
484
|
+
)
|
|
540
485
|
|
|
541
486
|
window.location.href = redirectURL
|
|
542
487
|
},
|
|
543
488
|
setUserInfo: assign((context, event) => {
|
|
544
|
-
|
|
545
|
-
sentry?.setUser({ id: event.data.uid_site })
|
|
546
|
-
}
|
|
489
|
+
sentry?.setUser({ id: event.data.uid_site })
|
|
547
490
|
return {
|
|
548
491
|
userInfo: event.data,
|
|
549
492
|
}
|
|
@@ -555,11 +498,19 @@ export default function (request) {
|
|
|
555
498
|
}),
|
|
556
499
|
},
|
|
557
500
|
services: {
|
|
501
|
+
authenticateApp: async (context, event) => {
|
|
502
|
+
const { token } = await request.send(auth.loginApp(event.data))
|
|
503
|
+
return token
|
|
504
|
+
},
|
|
558
505
|
authenticate: async (context, event) => {
|
|
559
506
|
const data = { ...context.loginData, reCaptchaToken: context.reCaptchaToken }
|
|
560
507
|
const { token } = await request.send(auth.login(data))
|
|
561
508
|
return token
|
|
562
509
|
},
|
|
510
|
+
authenticateGuest: async (context, event) => {
|
|
511
|
+
const { token } = await request.send(auth.guestLogin())
|
|
512
|
+
return token
|
|
513
|
+
},
|
|
563
514
|
logout: async (context, event) => {
|
|
564
515
|
return await request.send(auth.logout())
|
|
565
516
|
},
|
|
@@ -568,16 +519,16 @@ export default function (request) {
|
|
|
568
519
|
},
|
|
569
520
|
checkDeviceToken: async (context, event) => {
|
|
570
521
|
const deviceTokenEnable = context.siteConfig?.dtVerify
|
|
571
|
-
if (
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
522
|
+
if (deviceTokenEnable) {
|
|
523
|
+
const { exist } = await request.send(user.checkDt())
|
|
524
|
+
if (!exist) {
|
|
525
|
+
const dt = await getDeviceTokenWithRetry({ fpToken, sentry, hosts: request.hosts, enable: deviceTokenEnable })
|
|
526
|
+
// 確定有dt再取得updateDt
|
|
527
|
+
if (dt) {
|
|
528
|
+
await request.send(user.updateDt({ dt }))
|
|
529
|
+
}
|
|
530
|
+
}
|
|
579
531
|
}
|
|
580
|
-
return { dt: null }
|
|
581
532
|
},
|
|
582
533
|
fetchSiteConfig: async (context, event) => {
|
|
583
534
|
const { config } = await request.send(common.getConfig({ appSecret }))
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { assign, createMachine } from 'xstate'
|
|
2
|
+
import user from '../api/user.js'
|
|
3
|
+
|
|
4
|
+
export default function (request) {
|
|
5
|
+
return createMachine(
|
|
6
|
+
{
|
|
7
|
+
id: 'auth_otp_v2',
|
|
8
|
+
initial: 'idle',
|
|
9
|
+
context: {
|
|
10
|
+
strategy: null,
|
|
11
|
+
requestId: null,
|
|
12
|
+
ttl: null,
|
|
13
|
+
target: {},
|
|
14
|
+
acknowledgeTtl: null,
|
|
15
|
+
newPassword: null,
|
|
16
|
+
},
|
|
17
|
+
states: {
|
|
18
|
+
idle: {
|
|
19
|
+
on: {
|
|
20
|
+
SET_OTP_INITIALIZATION: {
|
|
21
|
+
target: 'otp',
|
|
22
|
+
actions: 'setOtpResult',
|
|
23
|
+
},
|
|
24
|
+
SEND_OTP_EMAIL: {
|
|
25
|
+
target: 'otpFetching',
|
|
26
|
+
actions: 'setStrategyEmail',
|
|
27
|
+
},
|
|
28
|
+
SEND_OTP_PHONE: {
|
|
29
|
+
target: 'otpFetching',
|
|
30
|
+
actions: 'setStrategyPhone',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
otpFetching: {
|
|
35
|
+
invoke: {
|
|
36
|
+
src: 'sendOtp',
|
|
37
|
+
onDone: [
|
|
38
|
+
{
|
|
39
|
+
target: 'acknowledged',
|
|
40
|
+
cond: (context, event) => event.data.status === 'success-verified',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
target: 'otp',
|
|
44
|
+
actions: 'setOtpResult',
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
onError: {
|
|
48
|
+
target: 'idle',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
otp: {
|
|
53
|
+
after: {
|
|
54
|
+
1000: [
|
|
55
|
+
{
|
|
56
|
+
target: 'otp',
|
|
57
|
+
actions: 'decreaseTtl',
|
|
58
|
+
cond: (context) => context.ttl > 0,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
target: 'idle',
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
on: {
|
|
66
|
+
ACKNOWLEDGE: {
|
|
67
|
+
target: 'acknowledging',
|
|
68
|
+
},
|
|
69
|
+
BACK: {
|
|
70
|
+
target: 'idle',
|
|
71
|
+
},
|
|
72
|
+
RESET_OTP: {
|
|
73
|
+
target: 'otpResetting',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
otpResetting: {
|
|
78
|
+
invoke: {
|
|
79
|
+
src: 'resetOtp',
|
|
80
|
+
onDone: {
|
|
81
|
+
target: 'otp',
|
|
82
|
+
actions: 'setOtpResult',
|
|
83
|
+
},
|
|
84
|
+
onError: {
|
|
85
|
+
target: 'otp',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
acknowledging: {
|
|
90
|
+
invoke: {
|
|
91
|
+
src: 'acknowledge',
|
|
92
|
+
onDone: {
|
|
93
|
+
target: 'acknowledged',
|
|
94
|
+
actions: 'setAcknowledgeResult',
|
|
95
|
+
},
|
|
96
|
+
onError: [
|
|
97
|
+
{
|
|
98
|
+
target: 'idle',
|
|
99
|
+
cond: (context, event) => event.data.code === 'ERR_A108',
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
target: 'otp',
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
acknowledged: {
|
|
108
|
+
// after: {
|
|
109
|
+
// 1000: [
|
|
110
|
+
// {
|
|
111
|
+
// target: 'acknowledged',
|
|
112
|
+
// actions: 'decreaseAcknowledgeTtl',
|
|
113
|
+
// cond: (context) => context.acknowledgeTtl > 0,
|
|
114
|
+
// },
|
|
115
|
+
// {
|
|
116
|
+
// target: 'idle',
|
|
117
|
+
// },
|
|
118
|
+
// ],
|
|
119
|
+
// },
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
actions: {
|
|
125
|
+
setStrategyPhone: assign((context, event) => {
|
|
126
|
+
return {
|
|
127
|
+
strategy: 'phone',
|
|
128
|
+
}
|
|
129
|
+
}),
|
|
130
|
+
setStrategyEmail: assign((context, event) => {
|
|
131
|
+
return {
|
|
132
|
+
strategy: 'email',
|
|
133
|
+
}
|
|
134
|
+
}),
|
|
135
|
+
setOtpResult: assign((context, event) => {
|
|
136
|
+
const { requestId, ttl, target } = event.data
|
|
137
|
+
return {
|
|
138
|
+
requestId,
|
|
139
|
+
ttl,
|
|
140
|
+
target,
|
|
141
|
+
}
|
|
142
|
+
}),
|
|
143
|
+
decreaseTtl: assign((context, event) => {
|
|
144
|
+
return {
|
|
145
|
+
ttl: Math.max(context.ttl - 1, 0),
|
|
146
|
+
}
|
|
147
|
+
}),
|
|
148
|
+
setAcknowledgeResult: assign((context, event) => {
|
|
149
|
+
const { requestId, ttl, target } = event.data
|
|
150
|
+
return {
|
|
151
|
+
acknowledgeTtl: ttl,
|
|
152
|
+
}
|
|
153
|
+
}),
|
|
154
|
+
decreaseAcknowledgeTtl: assign((context, event) => {
|
|
155
|
+
return {
|
|
156
|
+
acknowledgeTtl: Math.max(context.acknowledgeTtl - 1, 0),
|
|
157
|
+
}
|
|
158
|
+
}),
|
|
159
|
+
},
|
|
160
|
+
services: {
|
|
161
|
+
sendOtp: async (context, event) => {
|
|
162
|
+
const { strategy } = context
|
|
163
|
+
return await request.send(user.verifyV2Initiate({ strategy }))
|
|
164
|
+
},
|
|
165
|
+
resetOtp: async (context, event) => {
|
|
166
|
+
const { requestId, target } = context
|
|
167
|
+
return await request.send(user.otpReset({ requestId, target }))
|
|
168
|
+
},
|
|
169
|
+
acknowledge: async (context, event) => {
|
|
170
|
+
const { requestId, target } = context
|
|
171
|
+
const code = event.data
|
|
172
|
+
return await request.send(user.otpAcknowledge({ requestId, target, code }))
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
}
|
|
176
|
+
)
|
|
177
|
+
}
|