优化领取页角色绑定校验
This commit is contained in:
@@ -25,6 +25,16 @@ export function normalizeKuaishouCloudFlow(value: unknown) {
|
||||
|
||||
const roleName = String(role.name || binding.roleName || '').trim()
|
||||
const roleId = String(role.rid || binding.roleId || '').trim()
|
||||
const defaultRoleName = String(role.defaultName || role.defaultRoleName || '').trim()
|
||||
const defaultRoleId = String(role.defaultRid || role.defaultRoleId || '').trim()
|
||||
const hasDefaultRole = Boolean(defaultRoleName || defaultRoleId)
|
||||
const isDefaultRole =
|
||||
Boolean(roleName || roleId) &&
|
||||
hasDefaultRole &&
|
||||
isSameKuaishouCloudRoleIdentity(
|
||||
{ name: roleName, rid: roleId },
|
||||
{ name: defaultRoleName, rid: defaultRoleId },
|
||||
)
|
||||
const bindPreparedAt = binding.bindPreparedAt || null
|
||||
const bindExpiresAt =
|
||||
binding.bindExpiresAt || resolveKuaishouCloudBindUrlExpiresAt(bindPreparedAt)
|
||||
@@ -72,6 +82,12 @@ export function normalizeKuaishouCloudFlow(value: unknown) {
|
||||
refreshedAt: role.refreshedAt || null,
|
||||
errorMessage: String(role.errorMessage || '').trim(),
|
||||
rawInfo: role.rawInfo && typeof role.rawInfo === 'object' ? role.rawInfo : null,
|
||||
defaultName: defaultRoleName,
|
||||
defaultRid: defaultRoleId,
|
||||
defaultCapturedAt: role.defaultCapturedAt || null,
|
||||
defaultCaptureStatus: String(role.defaultCaptureStatus || '').trim(),
|
||||
defaultErrorMessage: String(role.defaultErrorMessage || '').trim(),
|
||||
isDefaultRole,
|
||||
},
|
||||
purchase: {
|
||||
autoBuyEnabled: purchase.autoBuyEnabled !== false,
|
||||
@@ -113,6 +129,49 @@ export function normalizeKuaishouCloudFlow(value: unknown) {
|
||||
}
|
||||
}
|
||||
|
||||
export function hasKuaishouCloudDefaultRoleSnapshot(flowLike: unknown) {
|
||||
const flow = normalizeKuaishouCloudFlow(flowLike)
|
||||
return Boolean(flow.role.defaultName || flow.role.defaultRid)
|
||||
}
|
||||
|
||||
export function hasKuaishouCloudCustomerRole(flowLike: unknown) {
|
||||
const flow = normalizeKuaishouCloudFlow(flowLike)
|
||||
if (!flow.binding.vnPhone || !flow.binding.roleName || !flow.binding.roleId) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (!hasKuaishouCloudDefaultRoleSnapshot(flow)) {
|
||||
return false
|
||||
}
|
||||
|
||||
return !isSameKuaishouCloudRoleIdentity(
|
||||
{ name: flow.binding.roleName, rid: flow.binding.roleId },
|
||||
{ name: flow.role.defaultName, rid: flow.role.defaultRid },
|
||||
)
|
||||
}
|
||||
|
||||
export function isSameKuaishouCloudRoleIdentity(
|
||||
left: { name?: unknown; rid?: unknown },
|
||||
right: { name?: unknown; rid?: unknown },
|
||||
) {
|
||||
const leftRid = String(left.rid || '').trim()
|
||||
const rightRid = String(right.rid || '').trim()
|
||||
if (leftRid && rightRid) {
|
||||
return leftRid === rightRid
|
||||
}
|
||||
|
||||
const leftName = normalizeRoleNameForCompare(left.name)
|
||||
const rightName = normalizeRoleNameForCompare(right.name)
|
||||
return Boolean(leftName && rightName && leftName === rightName)
|
||||
}
|
||||
|
||||
function normalizeRoleNameForCompare(value: unknown) {
|
||||
return String(value || '')
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace(/\s+/g, '')
|
||||
}
|
||||
|
||||
export function normalizeKuaishouCloudDeliveryItems(value: unknown) {
|
||||
const source: JsonObject = value && typeof value === 'object' ? (value as JsonObject) : {}
|
||||
const binding = source.binding && typeof source.binding === 'object' ? source.binding : {}
|
||||
|
||||
Reference in New Issue
Block a user