@jetthai/cuora 1.1.488 → 2.0.0-beta.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/BREAKING_CHANGES.md +9 -0
- package/CHANGELOG.md +3 -316
- package/README.md +15 -299
- package/package.json +5 -5
- package/resetGitBranch.sh +101 -0
- package/src/api/account.js +1 -0
- package/src/api/activity.js +39 -24
- package/src/api/auth.js +36 -5
- package/src/api/common.js +3 -5
- package/src/api/game.js +10 -0
- package/src/api/payment.js +55 -17
- package/src/api/user.js +16 -10
- package/src/index.js +2 -2
- package/src/lib/fingerprint_v3_11_12.js +11433 -0
- package/src/machine/activity/activity.js +213 -0
- package/src/machine/activity/activity_cash.js +36 -84
- package/src/machine/activity/cash_rain_activity.js +1 -0
- package/src/machine/activity/continue_deposit_activity.js +1 -0
- package/src/machine/activity/deposit_activity.js +1 -0
- package/src/machine/activity/diamond_shop_activity_cash.js +8 -0
- package/src/machine/activity/diamond_shop_activity_fc.js +197 -0
- package/src/machine/activity/diamond_shop_activity_vn.js +179 -0
- package/src/machine/activity/fafafa_activity.js +11 -0
- package/src/machine/activity/friend_invite_friends_activity.js +7 -8
- package/src/machine/activity/index.js +12 -0
- package/src/machine/activity/instant_rebate_activity.js +1 -0
- package/src/machine/activity/invite_friends_activity.js +115 -0
- package/src/machine/activity/jackpot.js +1 -0
- package/src/machine/activity/mini_game_activity.js +69 -0
- package/src/machine/activity/otp_verified_activity.js +1 -0
- package/src/machine/activity/ranking_activity.js +1 -0
- package/src/machine/activity/return_bonus_activity.js +155 -0
- package/src/machine/activity/roulette_activity_v2.js +1 -0
- package/src/machine/activity/sign_in_activity.js +1 -0
- package/src/machine/activity/sign_in_monthly_activity.js +2 -1
- package/src/machine/activity/specify_bets_activity.js +1 -0
- package/src/machine/activity/specify_turnover_activity.js +1 -0
- package/src/machine/activity/time_bomb_activity.js +1 -0
- package/src/machine/activity/vip_card_activity.js +1 -0
- package/src/machine/auth.js +112 -149
- package/src/machine/auth_otp_v2.js +178 -0
- package/src/machine/auth_otp_v3.js +22 -64
- package/src/machine/bank_binding.js +3 -2
- package/src/machine/bank_binding_amb.js +146 -0
- package/src/machine/bonus.js +76 -0
- package/src/machine/common.js +98 -14
- package/src/machine/deposit/amb.js +93 -0
- package/src/machine/deposit/crypto_bank.js +340 -0
- package/src/machine/deposit/crypto_bank_cash.js +35 -20
- package/src/machine/deposit/crypto_qrcode.js +158 -0
- package/src/machine/deposit/crypto_qrcode_cash.js +64 -26
- package/src/machine/deposit/crypto_way.js +253 -0
- package/src/machine/deposit/crypto_way_cash.js +37 -48
- package/src/machine/deposit/deposit_fc.js +272 -0
- package/src/machine/deposit/direct.js +311 -0
- package/src/machine/deposit/direct_cash.js +10 -8
- package/src/machine/deposit/float.js +375 -0
- package/src/machine/deposit/index.js +28 -0
- package/src/machine/deposit/krway.js +152 -0
- package/src/machine/deposit/loadcard_cash.js +32 -14
- package/src/machine/deposit/loadcard_vn.js +352 -0
- package/src/machine/deposit/manual_cash.js +11 -8
- package/src/machine/deposit/manual_vn.js +459 -0
- package/src/machine/deposit/qrcode_cash.js +32 -15
- package/src/machine/deposit/qrcode_v2.js +339 -0
- package/src/machine/deposit/usdt.js +163 -0
- package/src/machine/deposit/usdt_cash.js +15 -1
- package/src/machine/deposit/virtual_bank_cash.js +12 -13
- package/src/machine/deposit/virtual_bank_vn.js +270 -0
- package/src/machine/deposit/vpay.js +374 -0
- package/src/machine/error.js +1 -7
- package/src/machine/game_betslip.js +1 -0
- package/src/machine/game_favorite_v2.js +1 -0
- package/src/machine/game_hot_new.js +80 -0
- package/src/machine/game_info.js +13 -1
- package/src/machine/game_replay.js +47 -0
- package/src/machine/game_search_cash.js +1 -0
- package/src/machine/game_search_v2.js +402 -0
- package/src/machine/game_v2_1.js +126 -39
- package/src/machine/honor_board.js +133 -0
- package/src/machine/honor_board_cash.js +28 -22
- package/src/machine/inbox.js +105 -43
- package/src/machine/index.js +32 -0
- package/src/machine/leaderboard.js +12 -8
- package/src/machine/merge.js +58 -0
- package/src/machine/navbar.js +3 -1
- package/src/machine/payment_data.js +87 -0
- package/src/machine/promotions.js +163 -0
- package/src/machine/ranking.js +30 -45
- package/src/machine/reward.js +256 -0
- package/src/machine/reward_cash.js +42 -2
- package/src/machine/reward_fc.js +99 -0
- package/src/machine/roulette_v2.js +11 -14
- package/src/machine/setting.js +1 -0
- package/src/machine/side.js +160 -0
- package/src/machine/side_cash.js +3 -3
- package/src/machine/side_v2.js +223 -0
- package/src/machine/user_info.js +1 -0
- package/src/machine/user_photo.js +1 -0
- package/src/machine/user_reset_password.js +14 -0
- package/src/machine/user_sign_up.js +61 -46
- package/src/machine/vip_table.js +58 -0
- package/src/machine/websocket.js +349 -374
- package/src/machine/welcome.js +111 -0
- package/src/machine/withdraw/index.js +6 -0
- package/src/machine/withdraw/withdraw_crypto_cash.js +328 -0
- package/src/machine/withdraw/withdraw_krway.js +223 -0
- package/src/machine/withdraw/withdraw_manual.js +541 -0
- package/src/machine/withdraw/withdraw_manual_cash.js +39 -59
- package/src/request/config.js +0 -2
- package/src/request/request.js +60 -124
- package/src/util/constant.js +2 -6
- package/src/util/deviceToken.js +60 -0
- package/src/util/index.js +4 -2
- package/src/util/math.js +4 -0
- package/src/util/storage.js +4 -3
- package/test/api.behavior.test.js +69 -0
- package/test/api.contract.test.js +18 -0
- package/test/config.test.js +27 -0
- package/test/deviceToken.test.js +139 -0
- package/test/helpers.coverage.test.js +11 -0
- package/test/helpers.js +91 -0
- package/test/index.exports.test.js +14 -0
- package/test/machine.activity.core.coverage.test.js +337 -0
- package/test/machine.activity.gap.coverage.test.js +252 -0
- package/test/machine.activity.more.coverage.test.js +180 -0
- package/test/machine.activity_plus_and_binding_amb.coverage.test.js +201 -0
- package/test/machine.activity_timer_bonus.coverage.test.js +136 -0
- package/test/machine.activity_welcome.low.coverage.test.js +211 -0
- package/test/machine.amb_rewardfc_websocket.more.coverage.test.js +201 -0
- package/test/machine.auth.coverage.test.js +215 -0
- package/test/machine.bank_binding.test.js +143 -0
- package/test/machine.binding_otp_krway.coverage.test.js +223 -0
- package/test/machine.contract.test.js +50 -0
- package/test/machine.crypto_bank.coverage.test.js +270 -0
- package/test/machine.crypto_way.coverage.test.js +108 -0
- package/test/machine.crypto_way_cash.coverage.test.js +114 -0
- package/test/machine.definition.test.js +137 -0
- package/test/machine.deposit.manual.coverage.test.js +365 -0
- package/test/machine.deposit_fc.coverage.test.js +126 -0
- package/test/machine.direct.coverage.test.js +96 -0
- package/test/machine.direct_cash.coverage.test.js +108 -0
- package/test/machine.error.coverage.test.js +37 -0
- package/test/machine.events.test.js +126 -0
- package/test/machine.favorite_jackpot.coverage.test.js +82 -0
- package/test/machine.float.coverage.test.js +136 -0
- package/test/machine.flow.test.js +226 -0
- package/test/machine.game_hot_new_vip_table.coverage.test.js +105 -0
- package/test/machine.game_search_cash.coverage.test.js +155 -0
- package/test/machine.game_search_v2.test.js +199 -0
- package/test/machine.game_user_profile.coverage.test.js +100 -0
- package/test/machine.honor_board.test.js +133 -0
- package/test/machine.inbox.common.coverage.test.js +304 -0
- package/test/machine.loadcard_cash.coverage.test.js +101 -0
- package/test/machine.loadcard_vn.coverage.test.js +122 -0
- package/test/machine.misc.coverage.test.js +361 -0
- package/test/machine.more2.coverage.test.js +261 -0
- package/test/machine.options.execution.test.js +272 -0
- package/test/machine.priority.coverage.test.js +603 -0
- package/test/machine.qrcode_cash.coverage.test.js +107 -0
- package/test/machine.qrcode_v2.coverage.test.js +121 -0
- package/test/machine.regression.test.js +82 -0
- package/test/machine.roulette_v2.test.js +142 -0
- package/test/machine.side_reward_reset.coverage.test.js +220 -0
- package/test/machine.targeted.coverage.test.js +313 -0
- package/test/machine.usdt.coverage.test.js +95 -0
- package/test/machine.usdt_cash.coverage.test.js +73 -0
- package/test/machine.vip_card_activity.test.js +114 -0
- package/test/machine.virtual_bank_cash.coverage.test.js +105 -0
- package/test/machine.virtual_bank_vn.coverage.test.js +105 -0
- package/test/machine.vpay.coverage.test.js +142 -0
- package/test/machine.withdraw_crypto_cash.coverage.test.js +166 -0
- package/test/machine.withdraw_krway.coverage.test.js +123 -0
- package/test/machine.withdraw_manual.coverage.test.js +185 -0
- package/test/machine.withdraw_manual_cash.coverage.test.js +123 -0
- package/test/request.test.js +325 -0
- package/test/util.storage.errors.test.js +47 -0
- package/test/util.test.js +41 -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/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
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { assign, createMachine } from 'xstate'
|
|
2
|
-
import api from '
|
|
2
|
+
import api from '../../api/activity.js'
|
|
3
3
|
|
|
4
4
|
export default function (request) {
|
|
5
5
|
const { appSecret } = request.config
|
|
6
6
|
return createMachine(
|
|
7
7
|
{
|
|
8
8
|
id: 'sign_in_monthly',
|
|
9
|
+
predictableActionArguments: true,
|
|
9
10
|
context: {
|
|
10
11
|
activityNo: null,
|
|
11
12
|
activityDetail: null,
|
package/src/machine/auth.js
CHANGED
|
@@ -3,28 +3,24 @@ 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
|
+
const getDtWithRetry = request.config.getDeviceTokenWithRetry || getDeviceTokenWithRetry
|
|
12
13
|
const tokenKey = `cuora_${clientId}`
|
|
14
|
+
const userKey = `cuora_tempuser`
|
|
13
15
|
const phoneCountryCode = 'phone_countrycode'
|
|
14
16
|
const accountPhoneKey = 'account_phone'
|
|
15
17
|
const accountEmailKey = 'account_email'
|
|
16
18
|
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
19
|
|
|
25
20
|
return createMachine(
|
|
26
21
|
{
|
|
27
22
|
id: 'auth',
|
|
23
|
+
predictableActionArguments: true,
|
|
28
24
|
initial: 'fetchingConfig',
|
|
29
25
|
context: {
|
|
30
26
|
base: '',
|
|
@@ -46,7 +42,6 @@ export default function (request) {
|
|
|
46
42
|
redirectURL: null,
|
|
47
43
|
reCaptchaToken: null,
|
|
48
44
|
fc: null,
|
|
49
|
-
dt: null,
|
|
50
45
|
},
|
|
51
46
|
states: {
|
|
52
47
|
fetchingConfig: {
|
|
@@ -54,7 +49,7 @@ export default function (request) {
|
|
|
54
49
|
src: 'fetchSiteConfig',
|
|
55
50
|
onDone: {
|
|
56
51
|
target: 'idle',
|
|
57
|
-
actions:
|
|
52
|
+
actions: 'setSiteConfig',
|
|
58
53
|
},
|
|
59
54
|
onError: {
|
|
60
55
|
target: 'idle',
|
|
@@ -78,83 +73,50 @@ export default function (request) {
|
|
|
78
73
|
},
|
|
79
74
|
},
|
|
80
75
|
},
|
|
81
|
-
|
|
76
|
+
authenticationGuest: {
|
|
82
77
|
invoke: {
|
|
83
|
-
src: '
|
|
78
|
+
src: 'authenticateGuest',
|
|
84
79
|
onDone: {
|
|
85
|
-
target: '
|
|
86
|
-
actions:
|
|
80
|
+
target: 'authenticated',
|
|
81
|
+
actions: 'setToken',
|
|
87
82
|
},
|
|
88
83
|
onError: {
|
|
89
|
-
target: '
|
|
84
|
+
target: 'idle',
|
|
85
|
+
actions: 'removeToken',
|
|
90
86
|
},
|
|
91
87
|
},
|
|
92
88
|
},
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
target: 'fetching',
|
|
100
|
-
},
|
|
101
|
-
},
|
|
89
|
+
authenticationApp: {
|
|
90
|
+
invoke: {
|
|
91
|
+
src: 'authenticateApp',
|
|
92
|
+
onDone: {
|
|
93
|
+
target: 'authenticated',
|
|
94
|
+
actions: ['setToken'],
|
|
102
95
|
},
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
onDone: {
|
|
107
|
-
target: 'pending',
|
|
108
|
-
actions: ['setUserInfo', 'extendToken'],
|
|
109
|
-
},
|
|
110
|
-
onError: {
|
|
111
|
-
target: 'pending',
|
|
112
|
-
},
|
|
113
|
-
},
|
|
96
|
+
onError: {
|
|
97
|
+
target: 'idle',
|
|
98
|
+
actions: 'removeToken',
|
|
114
99
|
},
|
|
115
100
|
},
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
target: '
|
|
101
|
+
},
|
|
102
|
+
authenticated: {
|
|
103
|
+
invoke: {
|
|
104
|
+
src: 'fetchUserInfo',
|
|
105
|
+
onDone: {
|
|
106
|
+
target: 'otpChecking',
|
|
107
|
+
actions: ['setUserInfo', 'extendToken'],
|
|
122
108
|
},
|
|
123
|
-
|
|
109
|
+
onError: {
|
|
124
110
|
target: 'leaving',
|
|
125
111
|
},
|
|
126
112
|
},
|
|
127
113
|
},
|
|
128
|
-
|
|
129
|
-
// 才不會在綁定窗開著時觸發。是否需要綁定由前端依 siteConfig 判斷,machine 只負責等待結果。
|
|
130
|
-
bindBankChecking: {
|
|
131
|
-
initial: 'pending',
|
|
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
|
-
},
|
|
114
|
+
otpChecking: {
|
|
153
115
|
on: {
|
|
154
|
-
|
|
116
|
+
OTP_VERIFIED: {
|
|
155
117
|
target: 'loginSuccess',
|
|
156
118
|
},
|
|
157
|
-
|
|
119
|
+
OTP_SKIP: {
|
|
158
120
|
target: 'loginSuccess',
|
|
159
121
|
},
|
|
160
122
|
LOGOUT: {
|
|
@@ -217,12 +179,10 @@ export default function (request) {
|
|
|
217
179
|
initial: 'deviceTokenChecking',
|
|
218
180
|
states: {
|
|
219
181
|
deviceTokenChecking: {
|
|
220
|
-
entry: 'clearDeviceToken',
|
|
221
182
|
invoke: {
|
|
222
183
|
src: 'checkDeviceToken',
|
|
223
184
|
onDone: {
|
|
224
185
|
target: 'checkDeviceTokenDone',
|
|
225
|
-
actions: 'setDeviceToken',
|
|
226
186
|
},
|
|
227
187
|
onError: {
|
|
228
188
|
target: 'fetching',
|
|
@@ -302,6 +262,9 @@ export default function (request) {
|
|
|
302
262
|
CLEAR: {
|
|
303
263
|
target: '.logout',
|
|
304
264
|
},
|
|
265
|
+
LOGIN_GUEST: {
|
|
266
|
+
target: '.authenticationGuest',
|
|
267
|
+
},
|
|
305
268
|
LOGIN_ID: {
|
|
306
269
|
target: '.authentication',
|
|
307
270
|
actions: ['setReCaptchaToken', 'setLoginId'],
|
|
@@ -314,9 +277,16 @@ export default function (request) {
|
|
|
314
277
|
target: '.authentication',
|
|
315
278
|
actions: ['setReCaptchaToken', 'setLoginEmail'],
|
|
316
279
|
},
|
|
280
|
+
LOGIN_LOCAL: {
|
|
281
|
+
target: '.authentication',
|
|
282
|
+
actions: 'setLoginLocal',
|
|
283
|
+
},
|
|
317
284
|
LOGIN_3PARTY: {
|
|
318
285
|
actions: 'redirectTo3Party',
|
|
319
286
|
},
|
|
287
|
+
LOGIN_APP: {
|
|
288
|
+
target: '.authenticationApp',
|
|
289
|
+
},
|
|
320
290
|
LOGIN_TELEGRAM: {
|
|
321
291
|
target: '.authentication',
|
|
322
292
|
actions: 'setLoginTelegram',
|
|
@@ -351,19 +321,6 @@ export default function (request) {
|
|
|
351
321
|
siteConfig: { ...event.data, loginMethods: pickBy(loginMethods), registerMethods: pickBy(registerMethods) },
|
|
352
322
|
}
|
|
353
323
|
}),
|
|
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
324
|
setReCaptchaToken: assign((context, event) => {
|
|
368
325
|
const { reCaptchaToken } = event.data
|
|
369
326
|
return {
|
|
@@ -402,15 +359,28 @@ export default function (request) {
|
|
|
402
359
|
},
|
|
403
360
|
}
|
|
404
361
|
}),
|
|
362
|
+
setLoginLocal: assign((context, event) => {
|
|
363
|
+
const { username, password } = event.data
|
|
364
|
+
storage.set(userKey, username, {
|
|
365
|
+
path: '/',
|
|
366
|
+
maxAge: 60 * 60 * 24,
|
|
367
|
+
})
|
|
368
|
+
return {
|
|
369
|
+
loginData: {
|
|
370
|
+
provider: 'local',
|
|
371
|
+
username,
|
|
372
|
+
password,
|
|
373
|
+
},
|
|
374
|
+
}
|
|
375
|
+
}),
|
|
405
376
|
setLoginTelegram: assign((context, event) => {
|
|
406
|
-
const { loginType, additionalUserInfo, isSignature
|
|
377
|
+
const { loginType, additionalUserInfo, isSignature } = event.data
|
|
407
378
|
return {
|
|
408
379
|
loginData: {
|
|
409
380
|
provider: 'telegram',
|
|
410
381
|
loginType,
|
|
411
382
|
additionalUserInfo,
|
|
412
383
|
isSignature,
|
|
413
|
-
idToken,
|
|
414
384
|
},
|
|
415
385
|
}
|
|
416
386
|
}),
|
|
@@ -429,13 +399,6 @@ export default function (request) {
|
|
|
429
399
|
token: event.data,
|
|
430
400
|
}
|
|
431
401
|
}),
|
|
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
402
|
setAccount: assign((context, event) => {
|
|
440
403
|
if (context.loginData.username) {
|
|
441
404
|
storage.remove(accountEmailKey)
|
|
@@ -470,7 +433,7 @@ export default function (request) {
|
|
|
470
433
|
path: '/',
|
|
471
434
|
maxAge: 300,
|
|
472
435
|
})
|
|
473
|
-
return { token: null
|
|
436
|
+
return { token: null }
|
|
474
437
|
}),
|
|
475
438
|
extendToken: assign((context, event) => {
|
|
476
439
|
const token = storage.get(tokenKey)
|
|
@@ -481,69 +444,61 @@ export default function (request) {
|
|
|
481
444
|
return { token }
|
|
482
445
|
}),
|
|
483
446
|
redirectTo3Party: async (context, event) => {
|
|
484
|
-
const { provider, fc } = event.data
|
|
447
|
+
const { provider, channel, subchannel, fc } = event.data
|
|
485
448
|
const deviceTokenEnable = context.siteConfig?.dtVerify
|
|
486
449
|
|
|
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 })
|
|
450
|
+
const dt = await getDeviceTokenWithRetry({
|
|
451
|
+
fpToken,
|
|
452
|
+
sentry,
|
|
453
|
+
hosts: request.hosts,
|
|
454
|
+
enable: deviceTokenEnable,
|
|
455
|
+
})
|
|
500
456
|
|
|
457
|
+
const affiliateCode = storage.get('ac')
|
|
501
458
|
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
459
|
const messages = {
|
|
507
460
|
url: window.location.href,
|
|
461
|
+
channelOrders: [
|
|
462
|
+
{ channel: storage.get('channel'), subchannel: storage.get('subchannel') },
|
|
463
|
+
{ channel: defaultChannel, subchannel: defaultSubchannel },
|
|
464
|
+
{ channel: channel, subchannel: subchannel },
|
|
465
|
+
],
|
|
508
466
|
affiliateCode,
|
|
509
|
-
acSource: hasExplicitAc ? 'event' : acRead.from,
|
|
510
467
|
nickname,
|
|
511
468
|
}
|
|
469
|
+
sentry?.captureMessage(JSON.stringify(messages))
|
|
512
470
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
phone,
|
|
522
|
-
countryCode,
|
|
523
|
-
email,
|
|
524
|
-
birthday,
|
|
525
|
-
dt,
|
|
526
|
-
platform: 'pwa',
|
|
527
|
-
fc: friendCode,
|
|
528
|
-
},
|
|
529
|
-
(value) => normalize(value) !== null
|
|
530
|
-
)
|
|
471
|
+
const referralObj = {}
|
|
472
|
+
if (![undefined, 'undefined', null, 'null'].includes(affiliateCode)) {
|
|
473
|
+
referralObj.ac = affiliateCode
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
if (![undefined, 'undefined', null, 'null'].includes(nickname)) {
|
|
477
|
+
referralObj.nick_name = nickname
|
|
478
|
+
}
|
|
531
479
|
|
|
532
|
-
storage.
|
|
533
|
-
storage.
|
|
534
|
-
storage.remove('tp_email')
|
|
535
|
-
// tp_birthday 不在此移除:client 於回站登入完成後以 /self 補交作為備援,由 client 消費後移除
|
|
480
|
+
referralObj.channel = storage.get('channel') || defaultChannel || channel
|
|
481
|
+
referralObj.subchannel = storage.get('subchannel') || defaultSubchannel || subchannel
|
|
536
482
|
|
|
537
483
|
const fullURL = request.config.fullURL
|
|
538
484
|
|
|
539
|
-
const redirectURL = urljoin(
|
|
485
|
+
const redirectURL = urljoin(
|
|
486
|
+
fullURL,
|
|
487
|
+
'login?' +
|
|
488
|
+
new URLSearchParams({
|
|
489
|
+
provider,
|
|
490
|
+
redirectURI: `${window.location.protocol}//${window.location.host}${context.base}`,
|
|
491
|
+
...referralObj,
|
|
492
|
+
dt,
|
|
493
|
+
platform: 'pwa',
|
|
494
|
+
fc,
|
|
495
|
+
}).toString()
|
|
496
|
+
)
|
|
540
497
|
|
|
541
498
|
window.location.href = redirectURL
|
|
542
499
|
},
|
|
543
500
|
setUserInfo: assign((context, event) => {
|
|
544
|
-
|
|
545
|
-
sentry?.setUser({ id: event.data.uid_site })
|
|
546
|
-
}
|
|
501
|
+
sentry?.setUser({ id: event.data.uid_site })
|
|
547
502
|
return {
|
|
548
503
|
userInfo: event.data,
|
|
549
504
|
}
|
|
@@ -555,11 +510,19 @@ export default function (request) {
|
|
|
555
510
|
}),
|
|
556
511
|
},
|
|
557
512
|
services: {
|
|
513
|
+
authenticateApp: async (context, event) => {
|
|
514
|
+
const { token } = await request.send(auth.loginApp(event.data))
|
|
515
|
+
return token
|
|
516
|
+
},
|
|
558
517
|
authenticate: async (context, event) => {
|
|
559
518
|
const data = { ...context.loginData, reCaptchaToken: context.reCaptchaToken }
|
|
560
519
|
const { token } = await request.send(auth.login(data))
|
|
561
520
|
return token
|
|
562
521
|
},
|
|
522
|
+
authenticateGuest: async (context, event) => {
|
|
523
|
+
const { token } = await request.send(auth.guestLogin())
|
|
524
|
+
return token
|
|
525
|
+
},
|
|
563
526
|
logout: async (context, event) => {
|
|
564
527
|
return await request.send(auth.logout())
|
|
565
528
|
},
|
|
@@ -568,16 +531,16 @@ export default function (request) {
|
|
|
568
531
|
},
|
|
569
532
|
checkDeviceToken: async (context, event) => {
|
|
570
533
|
const deviceTokenEnable = context.siteConfig?.dtVerify
|
|
571
|
-
if (
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
534
|
+
if (deviceTokenEnable) {
|
|
535
|
+
const { exist } = await request.send(user.checkDt())
|
|
536
|
+
if (!exist) {
|
|
537
|
+
const dt = await getDtWithRetry({ fpToken, sentry, hosts: request.hosts, enable: deviceTokenEnable })
|
|
538
|
+
// 確定有dt再取得updateDt
|
|
539
|
+
if (dt) {
|
|
540
|
+
await request.send(user.updateDt({ dt }))
|
|
541
|
+
}
|
|
542
|
+
}
|
|
579
543
|
}
|
|
580
|
-
return { dt: null }
|
|
581
544
|
},
|
|
582
545
|
fetchSiteConfig: async (context, event) => {
|
|
583
546
|
const { config } = await request.send(common.getConfig({ appSecret }))
|
|
@@ -0,0 +1,178 @@
|
|
|
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
|
+
predictableActionArguments: true,
|
|
9
|
+
initial: 'idle',
|
|
10
|
+
context: {
|
|
11
|
+
strategy: null,
|
|
12
|
+
requestId: null,
|
|
13
|
+
ttl: null,
|
|
14
|
+
target: {},
|
|
15
|
+
acknowledgeTtl: null,
|
|
16
|
+
newPassword: null,
|
|
17
|
+
},
|
|
18
|
+
states: {
|
|
19
|
+
idle: {
|
|
20
|
+
on: {
|
|
21
|
+
SET_OTP_INITIALIZATION: {
|
|
22
|
+
target: 'otp',
|
|
23
|
+
actions: 'setOtpResult',
|
|
24
|
+
},
|
|
25
|
+
SEND_OTP_EMAIL: {
|
|
26
|
+
target: 'otpFetching',
|
|
27
|
+
actions: 'setStrategyEmail',
|
|
28
|
+
},
|
|
29
|
+
SEND_OTP_PHONE: {
|
|
30
|
+
target: 'otpFetching',
|
|
31
|
+
actions: 'setStrategyPhone',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
otpFetching: {
|
|
36
|
+
invoke: {
|
|
37
|
+
src: 'sendOtp',
|
|
38
|
+
onDone: [
|
|
39
|
+
{
|
|
40
|
+
target: 'acknowledged',
|
|
41
|
+
cond: (context, event) => event.data.status === 'success-verified',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
target: 'otp',
|
|
45
|
+
actions: 'setOtpResult',
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
onError: {
|
|
49
|
+
target: 'idle',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
otp: {
|
|
54
|
+
after: {
|
|
55
|
+
1000: [
|
|
56
|
+
{
|
|
57
|
+
target: 'otp',
|
|
58
|
+
actions: 'decreaseTtl',
|
|
59
|
+
cond: (context) => context.ttl > 0,
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
target: 'idle',
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
on: {
|
|
67
|
+
ACKNOWLEDGE: {
|
|
68
|
+
target: 'acknowledging',
|
|
69
|
+
},
|
|
70
|
+
BACK: {
|
|
71
|
+
target: 'idle',
|
|
72
|
+
},
|
|
73
|
+
RESET_OTP: {
|
|
74
|
+
target: 'otpResetting',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
otpResetting: {
|
|
79
|
+
invoke: {
|
|
80
|
+
src: 'resetOtp',
|
|
81
|
+
onDone: {
|
|
82
|
+
target: 'otp',
|
|
83
|
+
actions: 'setOtpResult',
|
|
84
|
+
},
|
|
85
|
+
onError: {
|
|
86
|
+
target: 'otp',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
acknowledging: {
|
|
91
|
+
invoke: {
|
|
92
|
+
src: 'acknowledge',
|
|
93
|
+
onDone: {
|
|
94
|
+
target: 'acknowledged',
|
|
95
|
+
actions: 'setAcknowledgeResult',
|
|
96
|
+
},
|
|
97
|
+
onError: [
|
|
98
|
+
{
|
|
99
|
+
target: 'idle',
|
|
100
|
+
cond: (context, event) => event.data.code === 'ERR_A108',
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
target: 'otp',
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
acknowledged: {
|
|
109
|
+
// after: {
|
|
110
|
+
// 1000: [
|
|
111
|
+
// {
|
|
112
|
+
// target: 'acknowledged',
|
|
113
|
+
// actions: 'decreaseAcknowledgeTtl',
|
|
114
|
+
// cond: (context) => context.acknowledgeTtl > 0,
|
|
115
|
+
// },
|
|
116
|
+
// {
|
|
117
|
+
// target: 'idle',
|
|
118
|
+
// },
|
|
119
|
+
// ],
|
|
120
|
+
// },
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
actions: {
|
|
126
|
+
setStrategyPhone: assign((context, event) => {
|
|
127
|
+
return {
|
|
128
|
+
strategy: 'phone',
|
|
129
|
+
}
|
|
130
|
+
}),
|
|
131
|
+
setStrategyEmail: assign((context, event) => {
|
|
132
|
+
return {
|
|
133
|
+
strategy: 'email',
|
|
134
|
+
}
|
|
135
|
+
}),
|
|
136
|
+
setOtpResult: assign((context, event) => {
|
|
137
|
+
const { requestId, ttl, target } = event.data
|
|
138
|
+
return {
|
|
139
|
+
requestId,
|
|
140
|
+
ttl,
|
|
141
|
+
target,
|
|
142
|
+
}
|
|
143
|
+
}),
|
|
144
|
+
decreaseTtl: assign((context, event) => {
|
|
145
|
+
return {
|
|
146
|
+
ttl: Math.max(context.ttl - 1, 0),
|
|
147
|
+
}
|
|
148
|
+
}),
|
|
149
|
+
setAcknowledgeResult: assign((context, event) => {
|
|
150
|
+
const { requestId, ttl, target } = event.data
|
|
151
|
+
return {
|
|
152
|
+
acknowledgeTtl: ttl,
|
|
153
|
+
}
|
|
154
|
+
}),
|
|
155
|
+
decreaseAcknowledgeTtl: assign((context, event) => {
|
|
156
|
+
return {
|
|
157
|
+
acknowledgeTtl: Math.max(context.acknowledgeTtl - 1, 0),
|
|
158
|
+
}
|
|
159
|
+
}),
|
|
160
|
+
},
|
|
161
|
+
services: {
|
|
162
|
+
sendOtp: async (context, event) => {
|
|
163
|
+
const { strategy } = context
|
|
164
|
+
return await request.send(user.verifyV2Initiate({ strategy }))
|
|
165
|
+
},
|
|
166
|
+
resetOtp: async (context, event) => {
|
|
167
|
+
const { requestId, target } = context
|
|
168
|
+
return await request.send(user.otpReset({ requestId, target }))
|
|
169
|
+
},
|
|
170
|
+
acknowledge: async (context, event) => {
|
|
171
|
+
const { requestId, target } = context
|
|
172
|
+
const code = event.data
|
|
173
|
+
return await request.send(user.otpAcknowledge({ requestId, target, code }))
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
}
|
|
177
|
+
)
|
|
178
|
+
}
|