barsa 1b944f57aa Update Configuration Files and Refactor Code Structure
- Adjusted .prettierrc to ensure consistent formatting with a newline at the end of the file.
- Reformatted eslint.config.mjs for improved readability by aligning array elements.
- Updated pnpm-lock.yaml to use single quotes for consistency across dependencies.
- Simplified worktree setup in .cursor/worktrees.json for cleaner configuration.
- Enhanced documentation in .cursor/plans to clarify architecture refactoring.
- Refactored various service files for improved readability and maintainability, including rate-limiting and auth services.
- Updated imports and exports across multiple files for consistency and clarity.
- Improved error handling and logging in service methods to enhance debugging capabilities.
- Streamlined utility functions for better performance and maintainability across the domain packages.
2025-12-25 17:30:02 +09:00

46 lines
1.3 KiB
TypeScript

/**
* Freebit Provider Utilities
*
* Provider-specific utilities for Freebit SIM API integration
*/
/**
* Normalize account identifier (remove formatting)
* Removes all non-digit characters from account string
*/
export function normalizeAccount(account: string): string {
return account.replace(/[^0-9]/g, "");
}
/**
* Validate account format (10-11 digits for Japanese phone numbers)
*/
export function validateAccount(account: string): boolean {
const normalized = normalizeAccount(account);
return /^\d{10,11}$/.test(normalized);
}
/**
* Format date for Freebit API (YYYYMMDD)
*/
export function formatDateForApi(date: Date): string {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0");
const day = String(date.getDate()).padStart(2, "0");
return `${year}${month}${day}`;
}
/**
* Parse date from Freebit API format (YYYYMMDD)
* @returns Date object or null if invalid format
*/
export function parseDateFromApi(dateString: string): Date | null {
if (!/^\d{8}$/.test(dateString)) return null;
const year = parseInt(dateString.substring(0, 4), 10);
const month = parseInt(dateString.substring(4, 6), 10) - 1; // Month is 0-indexed
const day = parseInt(dateString.substring(6, 8), 10);
return new Date(year, month, day);
}