barsa 0c63bc5c33 refactor: domain package cleanup
- Remove validation wrapper functions from common/validation.ts (use Zod schemas directly)
- Delete duplicate CheckoutItem/CheckoutTotals/CheckoutCart/OrderCreateResponse from orders/contract.ts
- Delete empty orders/checkout.ts
- Remove unused MIGRATION_STEPS/MIGRATION_TRANSFER_ITEMS UI constants from auth/forms.ts
- Standardize checkout/contract.ts to not re-export schema types
- Fix customer/providers/index.ts to not re-export contract types through providers barrel
2026-02-24 11:57:43 +09:00

59 lines
2.0 KiB
TypeScript

/**
* Auth Domain - Form Utilities
*
* Business logic for password validation and strength checking.
* UI configurations (labels, placeholders) belong in the frontend.
*/
// ============================================================================
// Password Requirements (Business Logic)
// ============================================================================
/**
* Password requirements - single source of truth for validation rules.
* Used by passwordSchema in common/schema.ts and for UI display.
*/
export const PASSWORD_REQUIREMENTS = [
{ key: "minLength", label: "At least 8 characters", regex: /.{8,}/ },
{ key: "uppercase", label: "One uppercase letter", regex: /[A-Z]/ },
{ key: "lowercase", label: "One lowercase letter", regex: /[a-z]/ },
{ key: "number", label: "One number", regex: /[0-9]/ },
{ key: "special", label: "One special character", regex: /[^A-Za-z0-9]/ },
] as const;
export type PasswordRequirementKey = (typeof PASSWORD_REQUIREMENTS)[number]["key"];
/**
* Check password strength against requirements
*/
export function checkPasswordStrength(password: string): {
requirements: Array<{ key: string; label: string; met: boolean }>;
strength: number;
isValid: boolean;
} {
const requirements = PASSWORD_REQUIREMENTS.map(req => ({
key: req.key,
label: req.label,
met: req.regex.test(password),
}));
const metCount = requirements.filter(r => r.met).length;
const strength = (metCount / requirements.length) * 100;
const isValid = metCount === requirements.length;
return { requirements, strength, isValid };
}
/**
* Get password strength display label and color class
*/
export function getPasswordStrengthDisplay(strength: number): {
label: string;
colorClass: string;
} {
if (strength >= 100) return { label: "Strong", colorClass: "bg-green-500" };
if (strength >= 80) return { label: "Good", colorClass: "bg-blue-500" };
if (strength >= 60) return { label: "Fair", colorClass: "bg-yellow-500" };
return { label: "Weak", colorClass: "bg-red-500" };
}