Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
// Phone-number normalization for the mobile-api.
|
|
// solvway-mobile-api massages usernames server-side, but we normalize on the
|
|
// client too so the value we send is predictable and testable.
|
|
|
|
/** All non-digit characters removed. */
|
|
export function digitsOnly(s: string): string {
|
|
return (s ?? "").replace(/\D/g, "");
|
|
}
|
|
|
|
/** A dial code ("+60") → its digits ("60"). */
|
|
export function dialToPrefix(dialCode: string): string {
|
|
return digitsOnly(dialCode);
|
|
}
|
|
|
|
/** A local number → digits with a single leading zero removed (Malaysian format). */
|
|
export function normalizeLocal(local: string): string {
|
|
return digitsOnly(local).replace(/^0+/, "");
|
|
}
|
|
|
|
/**
|
|
* Combined username for login / forgot-password, e.g. ("+60","016-678 9304") → "60166789304".
|
|
* The mobile-api applies further massaging, but this is already in its canonical form.
|
|
*/
|
|
export function toLoginUsername(dialCode: string, local: string): string {
|
|
return dialToPrefix(dialCode) + normalizeLocal(local);
|
|
}
|
|
|
|
/** Split form for registration / profile: { phoneNoPrefix, phoneNo }. */
|
|
export function toRegisterPhone(
|
|
dialCode: string,
|
|
local: string,
|
|
): { phoneNoPrefix: string; phoneNo: string } {
|
|
return {
|
|
phoneNoPrefix: dialToPrefix(dialCode),
|
|
phoneNo: normalizeLocal(local),
|
|
};
|
|
}
|