@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
package/src/util/paramStore.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import Cookies from 'universal-cookie'
|
|
2
|
-
import storage from './storage.js'
|
|
3
|
-
|
|
4
|
-
export const PARAM_MAX_AGE = 60 * 60 * 24 * 7
|
|
5
|
-
export const AC_KEYS = ['ac', 'referralCode']
|
|
6
|
-
export const FC_KEYS = ['fc', 'affiliate']
|
|
7
|
-
|
|
8
|
-
const DIRTY_VALUES = ['undefined', 'null', 'NaN']
|
|
9
|
-
|
|
10
|
-
const reportedOnce = new Set()
|
|
11
|
-
|
|
12
|
-
function cookieJar() {
|
|
13
|
-
return typeof document === 'undefined' ? null : new Cookies()
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function normalize(value) {
|
|
17
|
-
if (value === undefined || value === null) return null
|
|
18
|
-
const trimmed = String(value).trim()
|
|
19
|
-
if (trimmed === '' || DIRTY_VALUES.includes(trimmed)) return null
|
|
20
|
-
return trimmed
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// storage.js 的 JSON.parse 未包在 try/catch 內,localStorage 若存有同名裸字串會 throw,
|
|
24
|
-
// 未攔截會沿 xstate entry chain 往上炸掉整條 setUA→setAgent→setPixel→setKPixel→setFbclid
|
|
25
|
-
function readLocal(name) {
|
|
26
|
-
try {
|
|
27
|
-
return normalize(storage.get(name))
|
|
28
|
-
} catch (error) {
|
|
29
|
-
return null
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function readCookie(name) {
|
|
34
|
-
const jar = cookieJar()
|
|
35
|
-
if (!jar) return null
|
|
36
|
-
try {
|
|
37
|
-
return normalize(jar.get(name, { doNotParse: true }))
|
|
38
|
-
} catch (error) {
|
|
39
|
-
return null
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function readParam(urlParams, keys) {
|
|
44
|
-
for (const key of keys) {
|
|
45
|
-
const value = normalize(urlParams?.get?.(key))
|
|
46
|
-
if (value) return { value, from: `url:${key}` }
|
|
47
|
-
}
|
|
48
|
-
for (const key of keys) {
|
|
49
|
-
const value = readLocal(key)
|
|
50
|
-
if (value) return { value, from: `local:${key}` }
|
|
51
|
-
}
|
|
52
|
-
for (const key of keys) {
|
|
53
|
-
const value = readCookie(key)
|
|
54
|
-
if (value) return { value, from: `cookie:${key}` }
|
|
55
|
-
}
|
|
56
|
-
return { value: null, from: 'none' }
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function readParamFromLocation(keys) {
|
|
60
|
-
const search = typeof window === 'undefined' ? '' : window.location.search
|
|
61
|
-
return readParam(new URLSearchParams(search), keys)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function report(sentry, name, medium, reason) {
|
|
65
|
-
// 去重必須在確定送得出去之後才登錄,否則早於 sentry 注入的那次失敗會把 fingerprint 佔走,
|
|
66
|
-
// 導致之後真正有 sentry 時被自己的去重擋掉、永遠不上報
|
|
67
|
-
if (!sentry?.captureMessage) return
|
|
68
|
-
const fingerprint = `${name}:${medium}:${reason}`
|
|
69
|
-
if (reportedOnce.has(fingerprint)) return
|
|
70
|
-
reportedOnce.add(fingerprint)
|
|
71
|
-
sentry?.captureMessage?.(`[ParamStore] ${medium} persist ${reason}: ${name}`, {
|
|
72
|
-
level: 'warning',
|
|
73
|
-
tags: { feature: 'url-param-fallback', param_key: name, storage_medium: medium, failure_reason: reason },
|
|
74
|
-
})
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function clearParam(name) {
|
|
78
|
-
const result = { local: 'ok', cookie: 'ok', cleared: true }
|
|
79
|
-
try {
|
|
80
|
-
storage.remove(name)
|
|
81
|
-
} catch (error) {
|
|
82
|
-
result.local = 'throw'
|
|
83
|
-
}
|
|
84
|
-
const jar = cookieJar()
|
|
85
|
-
if (jar) {
|
|
86
|
-
try {
|
|
87
|
-
jar.remove(name, { path: '/' })
|
|
88
|
-
} catch (error) {
|
|
89
|
-
result.cookie = 'throw'
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return result
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function writeParam(name, value, options = {}) {
|
|
96
|
-
const { sentry, allowClear = false } = options
|
|
97
|
-
const normalized = normalize(value)
|
|
98
|
-
|
|
99
|
-
if (normalized === null) {
|
|
100
|
-
return allowClear ? clearParam(name) : { local: 'skipped', cookie: 'skipped', skipped: true }
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const result = { local: 'ok', cookie: 'ok' }
|
|
104
|
-
|
|
105
|
-
try {
|
|
106
|
-
storage.set(name, normalized, { path: '/', maxAge: PARAM_MAX_AGE })
|
|
107
|
-
} catch (error) {
|
|
108
|
-
result.local = 'throw'
|
|
109
|
-
}
|
|
110
|
-
if (result.local === 'ok' && readLocal(name) !== normalized) {
|
|
111
|
-
result.local = 'mismatch'
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const jar = cookieJar()
|
|
115
|
-
if (!jar) {
|
|
116
|
-
result.cookie = 'unavailable'
|
|
117
|
-
} else {
|
|
118
|
-
try {
|
|
119
|
-
jar.set(name, normalized, {
|
|
120
|
-
path: '/',
|
|
121
|
-
maxAge: PARAM_MAX_AGE,
|
|
122
|
-
sameSite: 'lax',
|
|
123
|
-
secure: typeof window !== 'undefined' && window.location.protocol === 'https:',
|
|
124
|
-
})
|
|
125
|
-
} catch (error) {
|
|
126
|
-
result.cookie = 'throw'
|
|
127
|
-
}
|
|
128
|
-
if (result.cookie === 'ok' && readCookie(name) !== normalized) {
|
|
129
|
-
result.cookie = 'mismatch'
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (result.local !== 'ok') report(sentry, name, 'localStorage', result.local)
|
|
134
|
-
if (result.cookie !== 'ok') report(sentry, name, 'cookie', result.cookie)
|
|
135
|
-
|
|
136
|
-
return result
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export default { PARAM_MAX_AGE, AC_KEYS, FC_KEYS, normalize, readParam, readParamFromLocation, writeParam }
|
package/src/util/socketPolicy.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
export function decideNextStep({ event, reason, err, active, ready, rejection } = {}) {
|
|
2
|
-
if (event === 'kicked') return 'kicked'
|
|
3
|
-
if (event === 'disconnect' && reason === 'io client disconnect') return 'none'
|
|
4
|
-
if ((event === 'disconnect' && reason !== 'io server disconnect') || (event === 'connect_error' && active)) return 'socketio'
|
|
5
|
-
const info = rejection || err?.data
|
|
6
|
-
if (info) {
|
|
7
|
-
if (info.code === 'MAX_CONNECTIONS') return 'kicked'
|
|
8
|
-
if (info.code === 'SESSION_TOKEN_INVALID') return 'renew'
|
|
9
|
-
if (info.retryable === false) return 'stop'
|
|
10
|
-
if (info.retryable === true) return 'retry'
|
|
11
|
-
}
|
|
12
|
-
if (event === 'disconnect') return ready ? 'kicked' : 'retry'
|
|
13
|
-
if (err?.message === 'session rejected') return 'renew'
|
|
14
|
-
return 'retry'
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function canResume(state, currentToken, source = 'user', now = Date.now()) {
|
|
18
|
-
if (!currentToken) return false
|
|
19
|
-
if (currentToken !== state.lastToken) return true
|
|
20
|
-
if (!state.blocked) return true
|
|
21
|
-
if (state.blocked === 'stop') return false
|
|
22
|
-
if (state.blocked === 'kicked') return source === 'user'
|
|
23
|
-
if (state.blocked === 'exhausted') return source === 'user' || (source === 'auto' && now - state.lastAttemptAt >= 15000)
|
|
24
|
-
return false
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function nextRetryDelay(attempt, retryAfterMs) {
|
|
28
|
-
const count = Number.isFinite(attempt) ? Math.max(1, Math.floor(attempt)) : 1
|
|
29
|
-
const base = Math.min(30000, 1000 * 2 ** Math.min(count - 1, 30))
|
|
30
|
-
const floor = Number.isFinite(retryAfterMs) ? Math.max(0, retryAfterMs) : 0
|
|
31
|
-
return Math.max(floor, Math.round(base * (0.5 + Math.random())))
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function createPushDedupe({ max = 500, ttlMs = 600000 } = {}) {
|
|
35
|
-
const capacity = Number.isFinite(max) ? Math.max(1, Math.floor(max)) : 500
|
|
36
|
-
const ttl = Number.isFinite(ttlMs) ? Math.max(0, ttlMs) : 600000
|
|
37
|
-
const seen = new Map()
|
|
38
|
-
return (eventName, data, now = Date.now()) => {
|
|
39
|
-
for (const [key, timestamp] of seen) {
|
|
40
|
-
if (now - timestamp >= ttl) seen.delete(key)
|
|
41
|
-
}
|
|
42
|
-
const messageId = data?._meta?.messageId
|
|
43
|
-
const orderId = [data?.data?.applyId, data?.applyId, data?.data?.transactionId, data?.transactionId].find(
|
|
44
|
-
(id) => id !== undefined && id !== null && id !== ''
|
|
45
|
-
)
|
|
46
|
-
const businessEvent = [data?.event, data?.data?.event].find((event) => event !== undefined && event !== null && event !== '')
|
|
47
|
-
let key
|
|
48
|
-
if (messageId !== undefined && messageId !== null && messageId !== '') key = JSON.stringify(['message', messageId])
|
|
49
|
-
else if (eventName === 'payment-info' && businessEvent && orderId !== undefined && orderId !== null && orderId !== '')
|
|
50
|
-
key = JSON.stringify(['payment', eventName, businessEvent, String(orderId)])
|
|
51
|
-
if (!key) return false
|
|
52
|
-
if (seen.has(key)) return true
|
|
53
|
-
seen.set(key, now)
|
|
54
|
-
while (seen.size > capacity) seen.delete(seen.keys().next().value)
|
|
55
|
-
return false
|
|
56
|
-
}
|
|
57
|
-
}
|
package/test/auth_otp_v3.test.js
DELETED
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
import test from 'node:test'
|
|
2
|
-
import assert from 'node:assert/strict'
|
|
3
|
-
import { interpret } from 'xstate'
|
|
4
|
-
import authOtpV3 from '../src/machine/auth_otp_v3.js'
|
|
5
|
-
|
|
6
|
-
function waitForState(service, matches) {
|
|
7
|
-
if (service.state.matches(matches)) return Promise.resolve(service.state)
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
const timeout = setTimeout(() => reject(new Error(`Timed out waiting for ${matches}`)), 1000)
|
|
10
|
-
service.onTransition((state) => {
|
|
11
|
-
if (!state.matches(matches)) return
|
|
12
|
-
clearTimeout(timeout)
|
|
13
|
-
resolve(state)
|
|
14
|
-
})
|
|
15
|
-
})
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
test('phone entry skips OTP only after /self confirms phone verification', async () => {
|
|
19
|
-
let selfReads = 0
|
|
20
|
-
const requests = []
|
|
21
|
-
const request = {
|
|
22
|
-
async send(descriptor) {
|
|
23
|
-
requests.push(descriptor.url)
|
|
24
|
-
if (descriptor.url === 'self') {
|
|
25
|
-
selfReads++
|
|
26
|
-
return {
|
|
27
|
-
phone: selfReads === 1 ? null : '123456789',
|
|
28
|
-
phone_verification_status: selfReads > 1,
|
|
29
|
-
email: null,
|
|
30
|
-
email_verification_status: false,
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (descriptor.url === 'otp-verification-point/verify') return { needAcknowledge: false }
|
|
34
|
-
throw new Error(`Unexpected request: ${descriptor.url}`)
|
|
35
|
-
},
|
|
36
|
-
}
|
|
37
|
-
const service = interpret(authOtpV3(request)).start()
|
|
38
|
-
try {
|
|
39
|
-
service.send({ type: 'SET_STRATEGY', data: 'phone' })
|
|
40
|
-
await waitForState(service, 'notVerified.phone')
|
|
41
|
-
service.send({ type: 'SEND_PHONE', data: { countryCode: '886', phone: '123456789' } })
|
|
42
|
-
await waitForState(service, 'verified')
|
|
43
|
-
assert.equal(selfReads, 2)
|
|
44
|
-
assert.deepEqual(requests, ['self', 'otp-verification-point/verify', 'self'])
|
|
45
|
-
} finally {
|
|
46
|
-
service.stop()
|
|
47
|
-
}
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
test('email entry skips OTP only after /self confirms email verification', async () => {
|
|
51
|
-
let selfReads = 0
|
|
52
|
-
const request = {
|
|
53
|
-
async send(descriptor) {
|
|
54
|
-
if (descriptor.url === 'self') {
|
|
55
|
-
selfReads++
|
|
56
|
-
return {
|
|
57
|
-
phone: null,
|
|
58
|
-
phone_verification_status: false,
|
|
59
|
-
email: selfReads === 1 ? null : 'test@example.com',
|
|
60
|
-
email_verification_status: selfReads > 1,
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (descriptor.url === 'otp-verification-point/verify') return { needAcknowledge: false }
|
|
64
|
-
throw new Error(`Unexpected request: ${descriptor.url}`)
|
|
65
|
-
},
|
|
66
|
-
}
|
|
67
|
-
const service = interpret(authOtpV3(request)).start()
|
|
68
|
-
try {
|
|
69
|
-
service.send({ type: 'SET_STRATEGY', data: 'email' })
|
|
70
|
-
await waitForState(service, 'notVerified.email')
|
|
71
|
-
service.send({ type: 'SEND_EMAIL', data: { email: 'test@example.com' } })
|
|
72
|
-
await waitForState(service, 'verified')
|
|
73
|
-
assert.equal(selfReads, 2)
|
|
74
|
-
} finally {
|
|
75
|
-
service.stop()
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
test('existing phone auto verification checks /self before finishing', async () => {
|
|
80
|
-
let selfReads = 0
|
|
81
|
-
const request = {
|
|
82
|
-
async send(descriptor) {
|
|
83
|
-
if (descriptor.url === 'self') {
|
|
84
|
-
selfReads++
|
|
85
|
-
return {
|
|
86
|
-
phone: '123456789',
|
|
87
|
-
phone_verification_status: selfReads > 1,
|
|
88
|
-
email: null,
|
|
89
|
-
email_verification_status: false,
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (descriptor.url === 'otp-verification-point/verify') return { needAcknowledge: false }
|
|
93
|
-
throw new Error(`Unexpected request: ${descriptor.url}`)
|
|
94
|
-
},
|
|
95
|
-
}
|
|
96
|
-
const service = interpret(authOtpV3(request)).start()
|
|
97
|
-
try {
|
|
98
|
-
service.send({ type: 'SET_STRATEGY', data: 'phone' })
|
|
99
|
-
await waitForState(service, 'verified')
|
|
100
|
-
assert.equal(selfReads, 2)
|
|
101
|
-
} finally {
|
|
102
|
-
service.stop()
|
|
103
|
-
}
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
test('needAcknowledge false never grants verification when /self is still unverified', async () => {
|
|
107
|
-
let verifyCalls = 0
|
|
108
|
-
const request = {
|
|
109
|
-
async send(descriptor) {
|
|
110
|
-
if (descriptor.url === 'self') {
|
|
111
|
-
return { phone: null, phone_verification_status: false, email: null, email_verification_status: false }
|
|
112
|
-
}
|
|
113
|
-
if (descriptor.url === 'otp-verification-point/verify') {
|
|
114
|
-
verifyCalls++
|
|
115
|
-
return { needAcknowledge: false }
|
|
116
|
-
}
|
|
117
|
-
throw new Error(`Unexpected request: ${descriptor.url}`)
|
|
118
|
-
},
|
|
119
|
-
}
|
|
120
|
-
const service = interpret(authOtpV3(request)).start()
|
|
121
|
-
try {
|
|
122
|
-
service.send({ type: 'SET_STRATEGY', data: 'phone' })
|
|
123
|
-
await waitForState(service, 'notVerified.phone')
|
|
124
|
-
service.send({ type: 'SEND_PHONE', data: { countryCode: '886', phone: '123456789' } })
|
|
125
|
-
await waitForState(service, 'autoVerifyWaiting')
|
|
126
|
-
const stale = { phone: '123456789', phone_verification_status: false, email: null, email_verification_status: false }
|
|
127
|
-
service.send({ type: 'USER_INFO_UPDATED', data: stale })
|
|
128
|
-
assert.equal(service.state.matches('autoVerifyWaiting'), true)
|
|
129
|
-
service.send({ type: 'USER_INFO_UPDATED', data: stale })
|
|
130
|
-
assert.equal(service.state.matches('fail'), true)
|
|
131
|
-
assert.equal(verifyCalls, 1)
|
|
132
|
-
} finally {
|
|
133
|
-
service.stop()
|
|
134
|
-
}
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
const autoVerifyEntries = [
|
|
138
|
-
{
|
|
139
|
-
name: 'existing phone',
|
|
140
|
-
strategy: 'phone',
|
|
141
|
-
initialUser: { phone: '123456789', phone_verification_status: false },
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
name: 'filled phone',
|
|
145
|
-
strategy: 'phone',
|
|
146
|
-
initialUser: { phone: null, phone_verification_status: false },
|
|
147
|
-
fill: { type: 'SEND_PHONE', data: { countryCode: '886', phone: '123456789' } },
|
|
148
|
-
waitFor: 'notVerified.phone',
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
name: 'filled email',
|
|
152
|
-
strategy: 'email',
|
|
153
|
-
initialUser: { email: null, email_verification_status: false },
|
|
154
|
-
fill: { type: 'SEND_EMAIL', data: { email: 'test@example.com' } },
|
|
155
|
-
waitFor: 'notVerified.email',
|
|
156
|
-
},
|
|
157
|
-
]
|
|
158
|
-
|
|
159
|
-
// 第 1 次 /self 為進入流程時抓的,第 2 次為 verify 後主動打的;兩次都尚未反映驗證結果
|
|
160
|
-
function staleSelfRequest(strategy, initialUser) {
|
|
161
|
-
const requests = []
|
|
162
|
-
const contact = strategy === 'phone' ? { phone: '123456789' } : { email: 'test@example.com' }
|
|
163
|
-
return {
|
|
164
|
-
requests,
|
|
165
|
-
contact,
|
|
166
|
-
async send(descriptor) {
|
|
167
|
-
requests.push(descriptor.url)
|
|
168
|
-
if (descriptor.url === 'self') {
|
|
169
|
-
return requests.filter((url) => url === 'self').length === 1 ? { ...initialUser } : { ...initialUser, ...contact }
|
|
170
|
-
}
|
|
171
|
-
if (descriptor.url === 'otp-verification-point/verify') return { needAcknowledge: false }
|
|
172
|
-
throw new Error(`Unexpected request: ${descriptor.url}`)
|
|
173
|
-
},
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
async function startAutoVerify(entry) {
|
|
178
|
-
const request = staleSelfRequest(entry.strategy, entry.initialUser)
|
|
179
|
-
const service = interpret(authOtpV3(request)).start()
|
|
180
|
-
service.send({ type: 'SET_STRATEGY', data: entry.strategy })
|
|
181
|
-
if (entry.fill) {
|
|
182
|
-
await waitForState(service, entry.waitFor)
|
|
183
|
-
service.send(entry.fill)
|
|
184
|
-
}
|
|
185
|
-
await waitForState(service, 'autoVerifyWaiting')
|
|
186
|
-
return { service, request }
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
for (const entry of autoVerifyEntries) {
|
|
190
|
-
test(`${entry.name}: stale /self waits and passes on a later polled /self`, async () => {
|
|
191
|
-
const { service, request } = await startAutoVerify(entry)
|
|
192
|
-
try {
|
|
193
|
-
const statusKey = `${entry.strategy}_verification_status`
|
|
194
|
-
service.send({ type: 'USER_INFO_UPDATED', data: { ...request.contact, [statusKey]: false } })
|
|
195
|
-
assert.equal(service.state.matches('autoVerifyWaiting'), true)
|
|
196
|
-
service.send({ type: 'USER_INFO_UPDATED', data: { ...request.contact, [statusKey]: true } })
|
|
197
|
-
assert.equal(service.state.matches('verified'), true)
|
|
198
|
-
assert.equal(service.state.context.userInfo[statusKey], true)
|
|
199
|
-
assert.deepEqual(request.requests, ['self', 'otp-verification-point/verify', 'self'])
|
|
200
|
-
} finally {
|
|
201
|
-
service.stop()
|
|
202
|
-
}
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
test(`${entry.name}: two stale polled /self responses fail`, async () => {
|
|
206
|
-
const { service, request } = await startAutoVerify(entry)
|
|
207
|
-
try {
|
|
208
|
-
const stale = { ...request.contact, [`${entry.strategy}_verification_status`]: false }
|
|
209
|
-
service.send({ type: 'USER_INFO_UPDATED', data: stale })
|
|
210
|
-
service.send({ type: 'USER_INFO_UPDATED', data: stale })
|
|
211
|
-
assert.equal(service.state.matches('fail'), true)
|
|
212
|
-
assert.deepEqual(request.requests, ['self', 'otp-verification-point/verify', 'self'])
|
|
213
|
-
} finally {
|
|
214
|
-
service.stop()
|
|
215
|
-
}
|
|
216
|
-
})
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
test('auto verify waiting fails after the 5 second limit without polled /self', async (t) => {
|
|
220
|
-
t.mock.timers.enable({ apis: ['setTimeout'] })
|
|
221
|
-
const { service } = await startAutoVerify(autoVerifyEntries[0])
|
|
222
|
-
try {
|
|
223
|
-
t.mock.timers.tick(4999)
|
|
224
|
-
assert.equal(service.state.matches('autoVerifyWaiting'), true)
|
|
225
|
-
t.mock.timers.tick(1)
|
|
226
|
-
assert.equal(service.state.matches('fail'), true)
|
|
227
|
-
} finally {
|
|
228
|
-
service.stop()
|
|
229
|
-
}
|
|
230
|
-
})
|
|
231
|
-
|
|
232
|
-
test('the 5 second limit is not reset by a stale polled /self', async (t) => {
|
|
233
|
-
t.mock.timers.enable({ apis: ['setTimeout'] })
|
|
234
|
-
const { service, request } = await startAutoVerify(autoVerifyEntries[0])
|
|
235
|
-
try {
|
|
236
|
-
t.mock.timers.tick(4000)
|
|
237
|
-
service.send({ type: 'USER_INFO_UPDATED', data: { ...request.contact, phone_verification_status: false } })
|
|
238
|
-
t.mock.timers.tick(1000)
|
|
239
|
-
assert.equal(service.state.matches('fail'), true)
|
|
240
|
-
} finally {
|
|
241
|
-
service.stop()
|
|
242
|
-
}
|
|
243
|
-
})
|
|
244
|
-
|
|
245
|
-
test('USER_INFO_UPDATED outside auto verify waiting does not change state', async () => {
|
|
246
|
-
const request = {
|
|
247
|
-
async send(descriptor) {
|
|
248
|
-
if (descriptor.url === 'self') return { phone: null, phone_verification_status: false }
|
|
249
|
-
throw new Error(`Unexpected request: ${descriptor.url}`)
|
|
250
|
-
},
|
|
251
|
-
}
|
|
252
|
-
const service = interpret(authOtpV3(request)).start()
|
|
253
|
-
try {
|
|
254
|
-
service.send({ type: 'SET_STRATEGY', data: 'phone' })
|
|
255
|
-
await waitForState(service, 'notVerified.phone')
|
|
256
|
-
service.send({ type: 'USER_INFO_UPDATED', data: { phone: '123456789', phone_verification_status: true } })
|
|
257
|
-
assert.equal(service.state.matches('notVerified.phone'), true)
|
|
258
|
-
} finally {
|
|
259
|
-
service.stop()
|
|
260
|
-
}
|
|
261
|
-
})
|
|
262
|
-
|
|
263
|
-
test('needAcknowledge true keeps the existing OTP input route', async () => {
|
|
264
|
-
const request = {
|
|
265
|
-
async send(descriptor) {
|
|
266
|
-
if (descriptor.url === 'self') {
|
|
267
|
-
return { phone: null, phone_verification_status: false, email: null, email_verification_status: false }
|
|
268
|
-
}
|
|
269
|
-
if (descriptor.url === 'otp-verification-point/verify') {
|
|
270
|
-
return { needAcknowledge: true, request_id: 'test-request', ttl: 60000, countryCode: '886', phone: '123456789' }
|
|
271
|
-
}
|
|
272
|
-
throw new Error(`Unexpected request: ${descriptor.url}`)
|
|
273
|
-
},
|
|
274
|
-
}
|
|
275
|
-
const service = interpret(authOtpV3(request)).start()
|
|
276
|
-
try {
|
|
277
|
-
service.send({ type: 'SET_STRATEGY', data: 'phone' })
|
|
278
|
-
await waitForState(service, 'notVerified.phone')
|
|
279
|
-
service.send({ type: 'SEND_PHONE', data: { countryCode: '886', phone: '123456789' } })
|
|
280
|
-
await waitForState(service, 'notVerified.otp')
|
|
281
|
-
assert.equal(service.state.context.requestId, 'test-request')
|
|
282
|
-
} finally {
|
|
283
|
-
service.stop()
|
|
284
|
-
}
|
|
285
|
-
})
|
|
286
|
-
|
|
287
|
-
test('email without an address still requires input even if its verification flag is true', async () => {
|
|
288
|
-
const request = {
|
|
289
|
-
async send(descriptor) {
|
|
290
|
-
if (descriptor.url === 'self') {
|
|
291
|
-
return { phone: '123456789', phone_verification_status: true, email: null, email_verification_status: true }
|
|
292
|
-
}
|
|
293
|
-
throw new Error(`Unexpected request: ${descriptor.url}`)
|
|
294
|
-
},
|
|
295
|
-
}
|
|
296
|
-
const service = interpret(authOtpV3(request)).start()
|
|
297
|
-
try {
|
|
298
|
-
service.send({ type: 'SET_STRATEGY', data: 'email' })
|
|
299
|
-
await waitForState(service, 'notVerified.email')
|
|
300
|
-
assert.equal(service.state.matches('verified'), false)
|
|
301
|
-
} finally {
|
|
302
|
-
service.stop()
|
|
303
|
-
}
|
|
304
|
-
})
|
|
305
|
-
|
|
306
|
-
test('phone without a number still requires input even if its verification flag is true', async () => {
|
|
307
|
-
const request = {
|
|
308
|
-
async send(descriptor) {
|
|
309
|
-
if (descriptor.url === 'self') {
|
|
310
|
-
return { phone: null, phone_verification_status: true, email: 'test@example.com', email_verification_status: true }
|
|
311
|
-
}
|
|
312
|
-
throw new Error(`Unexpected request: ${descriptor.url}`)
|
|
313
|
-
},
|
|
314
|
-
}
|
|
315
|
-
const service = interpret(authOtpV3(request)).start()
|
|
316
|
-
try {
|
|
317
|
-
service.send({ type: 'SET_STRATEGY', data: 'phone' })
|
|
318
|
-
await waitForState(service, 'notVerified.phone')
|
|
319
|
-
assert.equal(service.state.matches('verified'), false)
|
|
320
|
-
} finally {
|
|
321
|
-
service.stop()
|
|
322
|
-
}
|
|
323
|
-
})
|