2025-10-08 13:03:31 +09:00
|
|
|
/**
|
|
|
|
|
* Freebit Provider Utilities
|
2025-12-25 17:30:02 +09:00
|
|
|
*
|
2025-10-08 13:03:31 +09:00
|
|
|
* 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 {
|
2025-12-25 17:30:02 +09:00
|
|
|
return account.replace(/[^0-9]/g, "");
|
2025-10-08 13:03:31 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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();
|
2025-12-25 17:30:02 +09:00
|
|
|
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
|
|
|
const day = String(date.getDate()).padStart(2, "0");
|
2025-10-08 13:03:31 +09:00
|
|
|
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;
|
2025-12-25 17:30:02 +09:00
|
|
|
|
2026-01-15 11:28:25 +09:00
|
|
|
const year = Number.parseInt(dateString.slice(0, 4), 10);
|
|
|
|
|
const month = Number.parseInt(dateString.slice(4, 6), 10) - 1; // Month is 0-indexed
|
|
|
|
|
const day = Number.parseInt(dateString.slice(6, 8), 10);
|
2025-12-25 17:30:02 +09:00
|
|
|
|
2025-10-08 13:03:31 +09:00
|
|
|
return new Date(year, month, day);
|
|
|
|
|
}
|