@jetthai/cuora 1.1.482 → 1.1.483-dev.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/.claude/commands/sync-ai-prompts.md +88 -1
- package/.claude/settings.local.json +3 -1
- package/.husky/post-checkout +3 -3
- package/.husky/pre-push +1 -1
- package/.prettierignore +2 -1
- package/CHANGELOG.md +333 -23
- package/package.json +1 -1
- package/scripts/auto-version.js +1 -0
- package/scripts/branch-auto-npm-publish.js +9 -2
- package/src/api/activity.js +2 -2
- package/src/api/payment.js +1 -0
- package/src/machine/auth_otp_v3.js +59 -20
- package/src/machine/honor_board_cash.js +15 -18
- package/src/machine/user_sign_up.js +3 -0
- package/src/request/request.js +77 -2
- package/src/util/constant.js +4 -0
- package/test/auth_otp_v3.test.js +323 -0
package/src/api/payment.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { assign, createMachine } from 'xstate'
|
|
2
2
|
import user from '../api/user.js'
|
|
3
3
|
import otp from '../api/otp.js'
|
|
4
|
+
import { AUTO_VERIFY_MAX_USER_INFO_UPDATES, AUTO_VERIFY_WAIT_MS } from '../util/constant.js'
|
|
5
|
+
|
|
6
|
+
function isStrategyVerified(strategy, userInfo) {
|
|
7
|
+
if (strategy === 'phone') return !!(userInfo?.phone || userInfo?.tel) && !!userInfo?.phone_verification_status
|
|
8
|
+
if (strategy === 'email') return !!userInfo?.email && !!userInfo?.email_verification_status
|
|
9
|
+
return false
|
|
10
|
+
}
|
|
4
11
|
|
|
5
12
|
export default function (request) {
|
|
6
13
|
return createMachine(
|
|
@@ -18,6 +25,7 @@ export default function (request) {
|
|
|
18
25
|
requestId: null,
|
|
19
26
|
status: null,
|
|
20
27
|
ttl: 0,
|
|
28
|
+
autoVerifyUpdates: 0,
|
|
21
29
|
},
|
|
22
30
|
states: {
|
|
23
31
|
idle: {
|
|
@@ -48,16 +56,44 @@ export default function (request) {
|
|
|
48
56
|
{ target: 'notVerified', cond: 'isNotVerified' },
|
|
49
57
|
],
|
|
50
58
|
},
|
|
59
|
+
autoVerifying: {
|
|
60
|
+
invoke: {
|
|
61
|
+
src: 'fetchUserInfo',
|
|
62
|
+
onDone: {
|
|
63
|
+
target: 'checkingAutoVerification',
|
|
64
|
+
actions: 'setUserInfo',
|
|
65
|
+
},
|
|
66
|
+
onError: { target: 'fail' },
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
checkingAutoVerification: {
|
|
70
|
+
always: [{ target: 'verified', cond: 'isVerified' }, { target: 'autoVerifyWaiting' }],
|
|
71
|
+
},
|
|
72
|
+
// 後端寫入驗證狀態到 /self 反映之間有延遲(主動打的那次可能還是舊值),
|
|
73
|
+
// 改等下游轉送 auth 例行輪詢的 /self 結果,不另開輪詢以免重複打 /self
|
|
74
|
+
autoVerifyWaiting: {
|
|
75
|
+
entry: 'resetAutoVerifyUpdates',
|
|
76
|
+
after: {
|
|
77
|
+
AUTO_VERIFY_TIMEOUT: { target: 'fail' },
|
|
78
|
+
},
|
|
79
|
+
on: {
|
|
80
|
+
USER_INFO_UPDATED: [
|
|
81
|
+
{ target: 'verified', cond: 'isUpdatedUserInfoVerified', actions: 'setUserInfo' },
|
|
82
|
+
{ target: 'fail', cond: 'isLastAutoVerifyUpdate', actions: 'setUserInfo' },
|
|
83
|
+
{ actions: ['setUserInfo', 'countAutoVerifyUpdate'] },
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
51
87
|
notVerified: {
|
|
52
88
|
initial: 'checkingStatus',
|
|
53
89
|
states: {
|
|
54
90
|
checkingStatus: {
|
|
55
91
|
invoke: {
|
|
56
92
|
src: 'verify',
|
|
57
|
-
onDone:
|
|
58
|
-
target: '
|
|
59
|
-
actions: 'setVerificationData',
|
|
60
|
-
|
|
93
|
+
onDone: [
|
|
94
|
+
{ target: '#auth_otp.autoVerifying', cond: 'doesNotNeedAcknowledge' },
|
|
95
|
+
{ target: 'otp', actions: 'setVerificationData' },
|
|
96
|
+
],
|
|
61
97
|
onError: {
|
|
62
98
|
target: 'errorChecking',
|
|
63
99
|
actions: 'setError',
|
|
@@ -86,20 +122,20 @@ export default function (request) {
|
|
|
86
122
|
sendingPhone: {
|
|
87
123
|
invoke: {
|
|
88
124
|
src: 'sendPhone',
|
|
89
|
-
onDone:
|
|
90
|
-
target: '
|
|
91
|
-
actions: 'setVerificationData',
|
|
92
|
-
|
|
125
|
+
onDone: [
|
|
126
|
+
{ target: '#auth_otp.autoVerifying', cond: 'doesNotNeedAcknowledge' },
|
|
127
|
+
{ target: 'otp', actions: 'setVerificationData' },
|
|
128
|
+
],
|
|
93
129
|
onError: { target: 'phone' },
|
|
94
130
|
},
|
|
95
131
|
},
|
|
96
132
|
sendingEmail: {
|
|
97
133
|
invoke: {
|
|
98
134
|
src: 'sendEmail',
|
|
99
|
-
onDone:
|
|
100
|
-
target: '
|
|
101
|
-
actions: 'setVerificationData',
|
|
102
|
-
|
|
135
|
+
onDone: [
|
|
136
|
+
{ target: '#auth_otp.autoVerifying', cond: 'doesNotNeedAcknowledge' },
|
|
137
|
+
{ target: 'otp', actions: 'setVerificationData' },
|
|
138
|
+
],
|
|
103
139
|
onError: { target: 'email' },
|
|
104
140
|
},
|
|
105
141
|
},
|
|
@@ -163,6 +199,9 @@ export default function (request) {
|
|
|
163
199
|
},
|
|
164
200
|
},
|
|
165
201
|
{
|
|
202
|
+
delays: {
|
|
203
|
+
AUTO_VERIFY_TIMEOUT: AUTO_VERIFY_WAIT_MS,
|
|
204
|
+
},
|
|
166
205
|
actions: {
|
|
167
206
|
setStrategy: assign((context, event) => {
|
|
168
207
|
return {
|
|
@@ -193,6 +232,8 @@ export default function (request) {
|
|
|
193
232
|
ttl: Math.max(ms - 1000, 0),
|
|
194
233
|
}
|
|
195
234
|
}),
|
|
235
|
+
resetAutoVerifyUpdates: assign(() => ({ autoVerifyUpdates: 0 })),
|
|
236
|
+
countAutoVerifyUpdate: assign((context) => ({ autoVerifyUpdates: context.autoVerifyUpdates + 1 })),
|
|
196
237
|
setError: assign((context, event) => {
|
|
197
238
|
return {
|
|
198
239
|
error: event.data,
|
|
@@ -213,12 +254,10 @@ export default function (request) {
|
|
|
213
254
|
}),
|
|
214
255
|
},
|
|
215
256
|
guards: {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
return false
|
|
221
|
-
},
|
|
257
|
+
doesNotNeedAcknowledge: (context, event) => event.data?.needAcknowledge === false,
|
|
258
|
+
isVerified: (context, event) => isStrategyVerified(context.strategy, context.userInfo),
|
|
259
|
+
isUpdatedUserInfoVerified: (context, event) => isStrategyVerified(context.strategy, event.data),
|
|
260
|
+
isLastAutoVerifyUpdate: (context, event) => context.autoVerifyUpdates + 1 >= AUTO_VERIFY_MAX_USER_INFO_UPDATES,
|
|
222
261
|
isNotVerified: (context, event) => {
|
|
223
262
|
const { strategy, userInfo } = context
|
|
224
263
|
if (!userInfo) return false
|
|
@@ -228,11 +267,11 @@ export default function (request) {
|
|
|
228
267
|
},
|
|
229
268
|
isPhoneNotVerified: (context, event) => {
|
|
230
269
|
const { strategy, userInfo } = context
|
|
231
|
-
return strategy === 'phone' && !!userInfo && !userInfo.
|
|
270
|
+
return strategy === 'phone' && !!userInfo && !(userInfo.phone || userInfo.tel)
|
|
232
271
|
},
|
|
233
272
|
isEmailNotVerified: (context, event) => {
|
|
234
273
|
const { strategy, userInfo } = context
|
|
235
|
-
return strategy === 'email' && !!userInfo && !userInfo.
|
|
274
|
+
return strategy === 'email' && !!userInfo && !userInfo.email
|
|
236
275
|
},
|
|
237
276
|
hasNoPhone: (context, event) => {
|
|
238
277
|
const { error } = context
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { createMachine, assign } from 'xstate'
|
|
2
2
|
import activity from '../api/activity.js'
|
|
3
3
|
|
|
4
|
+
const TAB_KEY_BY_TYPE = {
|
|
5
|
+
CASH_RAIN: 'cashRain',
|
|
6
|
+
DEPOSIT: 'deposit',
|
|
7
|
+
FREE_ROULETTE_SPIN: 'roulette',
|
|
8
|
+
JACKPOT: 'jackpot',
|
|
9
|
+
WIN_SCORE: 'bigWin',
|
|
10
|
+
WIN_MULTIPLIER: 'maxBet',
|
|
11
|
+
WITHDRAW: 'withdraw',
|
|
12
|
+
LATEST_BET: 'latestBet',
|
|
13
|
+
}
|
|
14
|
+
|
|
4
15
|
export default function (request) {
|
|
5
16
|
const { appSecret } = request.config
|
|
6
17
|
return createMachine(
|
|
@@ -17,6 +28,7 @@ export default function (request) {
|
|
|
17
28
|
bigWin: {},
|
|
18
29
|
maxBet: {},
|
|
19
30
|
withdraw: {},
|
|
31
|
+
latestBet: {},
|
|
20
32
|
},
|
|
21
33
|
states: {
|
|
22
34
|
fetching: {
|
|
@@ -44,24 +56,8 @@ export default function (request) {
|
|
|
44
56
|
actions: {
|
|
45
57
|
setHonorBoardList: assign((context, event) => {
|
|
46
58
|
return {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
case 'CASH_RAIN':
|
|
50
|
-
return 'cashRain'
|
|
51
|
-
case 'DEPOSIT':
|
|
52
|
-
return 'deposit'
|
|
53
|
-
case 'FREE_ROULETTE_SPIN':
|
|
54
|
-
return 'roulette'
|
|
55
|
-
case 'JACKPOT':
|
|
56
|
-
return 'jackpot'
|
|
57
|
-
case 'WIN_SCORE':
|
|
58
|
-
return 'bigWin'
|
|
59
|
-
case 'WIN_MULTIPLIER':
|
|
60
|
-
return 'maxBet'
|
|
61
|
-
case 'WITHDRAW':
|
|
62
|
-
return 'withdraw'
|
|
63
|
-
}
|
|
64
|
-
}),
|
|
59
|
+
// 後端新增的類型若尚未對應 tab key,略過以免產生 undefined tab
|
|
60
|
+
tabs: (event.data || []).map((list) => TAB_KEY_BY_TYPE[list.type]).filter(Boolean),
|
|
65
61
|
cashRain: (event.data || []).find((item) => item.type === 'CASH_RAIN') || {},
|
|
66
62
|
deposit: (event.data || []).find((item) => item.type === 'DEPOSIT') || {},
|
|
67
63
|
roulette: (event.data || []).find((item) => item.type === 'FREE_ROULETTE_SPIN') || {},
|
|
@@ -69,6 +65,7 @@ export default function (request) {
|
|
|
69
65
|
bigWin: (event.data || []).find((item) => item.type === 'WIN_SCORE') || {},
|
|
70
66
|
maxBet: (event.data || []).find((item) => item.type === 'WIN_MULTIPLIER') || {},
|
|
71
67
|
withdraw: (event.data || []).find((item) => item.type === 'WITHDRAW') || {},
|
|
68
|
+
latestBet: (event.data || []).find((item) => item.type === 'LATEST_BET') || {},
|
|
72
69
|
}
|
|
73
70
|
}),
|
|
74
71
|
},
|
|
@@ -107,6 +107,7 @@ export default function (request) {
|
|
|
107
107
|
return {
|
|
108
108
|
signUpData: {
|
|
109
109
|
provider: 'local',
|
|
110
|
+
birthday,
|
|
110
111
|
...pickBindData(event.data),
|
|
111
112
|
birthday,
|
|
112
113
|
email,
|
|
@@ -130,6 +131,7 @@ export default function (request) {
|
|
|
130
131
|
return {
|
|
131
132
|
signUpData: {
|
|
132
133
|
provider: 'phone',
|
|
134
|
+
birthday,
|
|
133
135
|
...pickBindData(event.data),
|
|
134
136
|
birthday,
|
|
135
137
|
email,
|
|
@@ -152,6 +154,7 @@ export default function (request) {
|
|
|
152
154
|
return {
|
|
153
155
|
signUpData: {
|
|
154
156
|
provider: 'email',
|
|
157
|
+
birthday,
|
|
155
158
|
...pickBindData(event.data),
|
|
156
159
|
birthday,
|
|
157
160
|
email,
|
package/src/request/request.js
CHANGED
|
@@ -5,6 +5,8 @@ import { getErr998SentryExtra } from '../util/err998SentryExtra.js'
|
|
|
5
5
|
// 暫停 ERR_998 上報:在組裝 Sentry 資料之前就中止,不建立事件;仍照常 reject ERR_998 給呼叫端。恢復時改回 false 即可
|
|
6
6
|
const IS_ERR_998_REPORT_PAUSED = true
|
|
7
7
|
|
|
8
|
+
const CANCELLED_MESSAGE = 'Requests Cancelled'
|
|
9
|
+
|
|
8
10
|
// const pickBy = require('lodash/pickBy')
|
|
9
11
|
const supportVersion2List = [
|
|
10
12
|
// 04-09 Update
|
|
@@ -160,6 +162,9 @@ export default class Request {
|
|
|
160
162
|
this.errorHandler = null
|
|
161
163
|
this.hosts = []
|
|
162
164
|
this.isBlocked = false
|
|
165
|
+
this.activeRequests = new Set() // { source, token }:僅追蹤非 public 且帶 token 的在途請求,供 revokeToken 取消
|
|
166
|
+
this.revokedToken = null
|
|
167
|
+
this.tokenGate = null
|
|
163
168
|
this.clientIp = '' // 由外部 plugin(如 clientIp.client.js)非同步寫入,用於 ERR_998 Sentry 回報
|
|
164
169
|
this.hostTester = null // 由外部 plugin(如 host.client.js)寫入,需提供 lastResults 陣列供 ERR_998 Sentry 回報使用
|
|
165
170
|
this.initialize()
|
|
@@ -237,15 +242,75 @@ export default class Request {
|
|
|
237
242
|
this.errorHandler = handler
|
|
238
243
|
}
|
|
239
244
|
|
|
245
|
+
// 作廢指定 token:取消同 token 的在途請求,並讓之後仍帶此 token 的 send() 直接 reject。
|
|
246
|
+
// 只在 token 仍是目前身分時作用,舊身分遲到的錯誤不得影響新身分;重新登入後 token 改變即自然恢復
|
|
247
|
+
revokeToken(token) {
|
|
248
|
+
if (!token || token !== this.getToken()) return
|
|
249
|
+
this.revokedToken = token
|
|
250
|
+
this.activeRequests.forEach((item) => {
|
|
251
|
+
if (item.token === token) item.source.cancel(CANCELLED_MESSAGE)
|
|
252
|
+
})
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// 回前景時先確認 token 仍有效:promise 結算(成功或失敗)或逾時即放行,之後的 send() 才會送出
|
|
256
|
+
beginTokenGate(promise, timeoutMs = 3000) {
|
|
257
|
+
let timer
|
|
258
|
+
const timeout = new Promise((resolve) => {
|
|
259
|
+
timer = setTimeout(resolve, timeoutMs)
|
|
260
|
+
})
|
|
261
|
+
const gate = Promise.race([Promise.resolve(promise).catch(() => {}), timeout]).then(() => {
|
|
262
|
+
clearTimeout(timer)
|
|
263
|
+
if (this.tokenGate === gate) this.tokenGate = null
|
|
264
|
+
})
|
|
265
|
+
this.tokenGate = gate
|
|
266
|
+
return gate
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// 帶 ERR_800 讓下游既有的 `if (!error.code)` 判斷(如 Sentry 上報)把取消視為預期錯誤
|
|
270
|
+
_cancelledError() {
|
|
271
|
+
return Object.assign(new Error(CANCELLED_MESSAGE), { code: 'ERR_800' })
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
_throwIfRevoked() {
|
|
275
|
+
if (this.revokedToken && this.getToken() === this.revokedToken) {
|
|
276
|
+
throw this._cancelledError()
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
_isCancelled(error) {
|
|
281
|
+
return !!this.axios.isCancel?.(error) || error?.message === CANCELLED_MESSAGE
|
|
282
|
+
}
|
|
283
|
+
|
|
240
284
|
async send(req, customToken) {
|
|
285
|
+
let tracked = null
|
|
286
|
+
let requestToken = null
|
|
241
287
|
try {
|
|
242
288
|
// 非 public 請求缺 token 直接 reject:reject → onError → leaving → 乾淨登出,且不送網路 → 洪水照止
|
|
243
289
|
if (!req.isPublic && !this.getToken()) return Promise.reject({ code: 'ERR_A103' })
|
|
244
290
|
|
|
291
|
+
// 公開請求不帶 token,作廢期間 token 仍留在 storage 也不可誤拒(如 autoLogin 前後的 getConfig)
|
|
292
|
+
if (!req.isPublic) this._throwIfRevoked()
|
|
293
|
+
|
|
294
|
+
// /self 是 gate 自己的探測請求,不可等待 gate,否則死鎖
|
|
295
|
+
if (this.tokenGate && !req.isPublic && req.url.split('?')[0] !== 'self') {
|
|
296
|
+
await this.tokenGate
|
|
297
|
+
this._throwIfRevoked()
|
|
298
|
+
if (!this.getToken()) return Promise.reject({ code: 'ERR_A103' })
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
requestToken = req.isPublic ? null : this.getToken()
|
|
302
|
+
|
|
245
303
|
// axios <0.22 對 cancelToken.promise 註冊的取消 handler 永不退訂(xhr.js 無 unsubscribe),
|
|
246
304
|
// 預設掛長壽命共用 token 會使 handler 隨請求數線性累積(掛機過夜 OOM,TI-15555)。
|
|
247
|
-
//
|
|
248
|
-
|
|
305
|
+
// 故不掛共用 token:呼叫端傳入 customToken 時自行管理其生命週期;否則帶 token 的請求用一次性 source,
|
|
306
|
+
// 結束即移出 activeRequests 隨請求回收
|
|
307
|
+
let cancelToken = customToken
|
|
308
|
+
if (!customToken && requestToken && this.axios.CancelToken) {
|
|
309
|
+
const source = this.axios.CancelToken.source()
|
|
310
|
+
tracked = { source, token: requestToken }
|
|
311
|
+
this.activeRequests.add(tracked)
|
|
312
|
+
cancelToken = source.token
|
|
313
|
+
}
|
|
249
314
|
|
|
250
315
|
const requestConfig = this._createConfig(req, cancelToken)
|
|
251
316
|
const configUrls = ['getConfig', 'get-config']
|
|
@@ -256,11 +321,19 @@ export default class Request {
|
|
|
256
321
|
return data
|
|
257
322
|
}
|
|
258
323
|
} catch (error) {
|
|
324
|
+
if (this._isCancelled(error)) throw this._cancelledError()
|
|
325
|
+
// 不可列舉:避免 Bearer token 隨 JSON.stringify/Sentry 序列化外洩,但 error.requestToken 仍可讀取
|
|
326
|
+
if (requestToken && error && typeof error === 'object' && Object.isExtensible(error)) {
|
|
327
|
+
Object.defineProperty(error, 'requestToken', { value: requestToken, enumerable: false, configurable: true })
|
|
328
|
+
}
|
|
259
329
|
if (error.code === 'ERR_F108') {
|
|
260
330
|
this.isBlocked = true
|
|
261
331
|
this.errorHandler && this.errorHandler(error)
|
|
262
332
|
throw error
|
|
263
333
|
}
|
|
334
|
+
// 舊身分遲到的錯誤不進 errorHandler;目前沒 token(TTL 過期或已 CLEAR)時維持原路由,A204 等彈窗才不會被吞
|
|
335
|
+
const currentToken = this.getToken()
|
|
336
|
+
if (requestToken && currentToken && currentToken !== requestToken) throw error
|
|
264
337
|
if (error.code === 'ERR_998') {
|
|
265
338
|
throw error
|
|
266
339
|
}
|
|
@@ -270,6 +343,8 @@ export default class Request {
|
|
|
270
343
|
}
|
|
271
344
|
throw error
|
|
272
345
|
}
|
|
346
|
+
} finally {
|
|
347
|
+
if (tracked) this.activeRequests.delete(tracked)
|
|
273
348
|
}
|
|
274
349
|
}
|
|
275
350
|
|
package/src/util/constant.js
CHANGED
|
@@ -17,3 +17,7 @@ export const GAME_TYPE_LIST = [
|
|
|
17
17
|
{ typeId: 'TURBO', name: 'Turbo', gameTypeMappingId: 15 },
|
|
18
18
|
{ typeId: 'SPORT', name: 'Sports', gameTypeMappingId: 16 },
|
|
19
19
|
]
|
|
20
|
+
|
|
21
|
+
// OTP 自動驗證:主動打的 /self 未通過後,最多再等幾次 auth 例行輪詢的 /self、等待上限多久
|
|
22
|
+
export const AUTO_VERIFY_MAX_USER_INFO_UPDATES = 2
|
|
23
|
+
export const AUTO_VERIFY_WAIT_MS = 4000
|