"use strict"; // adpanel:stepup-credential-types - only string credentials may reach a // verifier; limiter admission and verification share this classification. function parseDestructiveActionCredentials(body) { const input = body && typeof body === "object" && !Array.isArray(body) ? body : {}; const invalidType = ["currentPassword", "twoFactorCode"].some((key) => input[key] !== undefined && typeof input[key] !== "string" ); const currentPassword = typeof input.currentPassword === "string" ? input.currentPassword : ""; const rawCode = typeof input.twoFactorCode === "string" ? input.twoFactorCode.replace(/\s+/g, "") : ""; const twoFactorCode = /^\d{6}$/.test(rawCode) ? rawCode : ""; return { currentPassword, twoFactorCode, invalidType }; } function hasDestructiveActionCredentialPayload(req) { const credentials = parseDestructiveActionCredentials(req?.body); return !credentials.invalidType && !!(credentials.currentPassword || credentials.twoFactorCode); } module.exports = { parseDestructiveActionCredentials, hasDestructiveActionCredentialPayload };