task-94(店铺中心): 实现店铺凭证明文短时展示
新增 shop-credential-reveal.ts:复用 secret-mask 会话,店铺密码读取后默认 5 秒短时展示,读取失败/离开即清空,明文不写持久化/日志。 TDD: task-94.test.ts 8 用例先 RED 后 GREEN。
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
/** 店铺密码短时揭示会话(任务 94):读取明文后只在内存按短窗口(默认 5 秒)展示,
|
||||
* 读取失败或离开页面即清空;纯逻辑,明文不写持久化/日志。 */
|
||||
import {
|
||||
DEFAULT_REVEAL_MS,
|
||||
createSecretRevealState,
|
||||
expireReveal,
|
||||
revealSecret,
|
||||
type SecretRevealState,
|
||||
} from './secret-mask.ts'
|
||||
|
||||
export const DEFAULT_SHOP_PASSWORD_REVEAL_MS = DEFAULT_REVEAL_MS
|
||||
|
||||
/** 空揭示会话(默认/读取失败/离开页面后)。 */
|
||||
export function clearShopPasswordReveal(): SecretRevealState {
|
||||
return createSecretRevealState()
|
||||
}
|
||||
|
||||
/** 开始揭示某店铺密码明文(记录 id + 明文 + 揭示时刻),返回新会话。 */
|
||||
export function beginShopPasswordReveal(
|
||||
session: SecretRevealState,
|
||||
shopId: number,
|
||||
plain: string,
|
||||
now: number,
|
||||
expiresAt?: number,
|
||||
): SecretRevealState {
|
||||
return revealSecret(session, shopId, plain, now, expiresAt)
|
||||
}
|
||||
|
||||
/** 到达过期点即清空明文。 */
|
||||
export function expireShopPasswordReveal(session: SecretRevealState, now: number): SecretRevealState {
|
||||
return expireReveal(session, now)
|
||||
}
|
||||
|
||||
/** 当前时刻是否存在有效的短时揭示明文。 */
|
||||
export function isShopPasswordRevealActive(session: SecretRevealState, now: number): boolean {
|
||||
const current = expireReveal(session, now)
|
||||
return current.keyId !== null && current.token !== undefined && current.token !== ''
|
||||
}
|
||||
Reference in New Issue
Block a user