T. Narantuya 94e1625b78 order fix
2025-08-27 10:54:05 +09:00

128 lines
3.5 KiB
TypeScript

// Central SKU registry for Product2 <-> portal mappings.
// Replace the placeholder codes with your actual Product2.SKU__c values.
export type InternetTier = "Platinum" | "Gold" | "Silver";
export type AccessMode = "IPoE-HGW" | "IPoE-BYOR" | "PPPoE";
export type InstallPlan = "One-time" | "12-Month" | "24-Month";
const INTERNET_SKU: Record<InternetTier, Record<AccessMode, string>> = {
Platinum: {
"IPoE-HGW": "INT-1G-PLAT-HGW",
"IPoE-BYOR": "INT-1G-PLAT-BYOR",
PPPoE: "INT-1G-PLAT-PPPOE",
},
Gold: {
"IPoE-HGW": "INT-1G-GOLD-HGW",
"IPoE-BYOR": "INT-1G-GOLD-BYOR",
PPPoE: "INT-1G-GOLD-PPPOE",
},
Silver: {
"IPoE-HGW": "INT-1G-SILV-HGW",
"IPoE-BYOR": "INT-1G-SILV-BYOR",
PPPoE: "INT-1G-SILV-PPPOE",
},
};
const INSTALL_SKU: Record<InstallPlan, string> = {
"One-time": "INT-INSTALL-ONETIME",
"12-Month": "INT-INSTALL-12M",
"24-Month": "INT-INSTALL-24M",
};
const VPN_SKU: Record<string, string> = {
"USA-SF": "VPN-USA-SF",
"UK-London": "VPN-UK-LON",
};
export function getInternetServiceSku(tier: InternetTier, mode: AccessMode): string {
return INTERNET_SKU[tier][mode];
}
export function getInternetInstallSku(plan: InstallPlan): string {
return INSTALL_SKU[plan];
}
export function getVpnServiceSku(region: string): string {
return VPN_SKU[region] || "";
}
export function getVpnActivationSku(): string {
return "VPN-ACTIVATION";
}
// ===== SIM / eSIM =====
export type SimFormat = "eSIM" | "Physical";
export type SimPlanType = "DataOnly" | "DataSmsVoice" | "VoiceOnly";
export type SimDataSize = "5GB" | "10GB" | "25GB" | "50GB" | "None";
type SimSkuMap = Record<SimFormat, Record<SimPlanType, Partial<Record<SimDataSize, string>>>>;
// Default mapping. Replace with your actual Product2.SKU__c codes in Salesforce.
// Can be overridden at runtime via NEXT_PUBLIC_SIM_SKU_MAP (JSON with the same shape as SimSkuMap).
const DEFAULT_SIM_SKU_MAP: SimSkuMap = {
eSIM: {
DataOnly: {
"5GB": "SIM-ESIM-DATA-5GB",
"10GB": "SIM-ESIM-DATA-10GB",
"25GB": "SIM-ESIM-DATA-25GB",
"50GB": "SIM-ESIM-DATA-50GB",
},
DataSmsVoice: {
"5GB": "SIM-ESIM-VOICE-5GB",
"10GB": "SIM-ESIM-VOICE-10GB",
"25GB": "SIM-ESIM-VOICE-25GB",
"50GB": "SIM-ESIM-VOICE-50GB",
},
VoiceOnly: {
None: "SIM-ESIM-VOICEONLY",
},
},
Physical: {
DataOnly: {
"5GB": "SIM-PHYS-DATA-5GB",
"10GB": "SIM-PHYS-DATA-10GB",
"25GB": "SIM-PHYS-DATA-25GB",
"50GB": "SIM-PHYS-DATA-50GB",
},
DataSmsVoice: {
"5GB": "SIM-PHYS-VOICE-5GB",
"10GB": "SIM-PHYS-VOICE-10GB",
"25GB": "SIM-PHYS-VOICE-25GB",
"50GB": "SIM-PHYS-VOICE-50GB",
},
VoiceOnly: {
None: "SIM-PHYS-VOICEONLY",
},
},
};
function getEnvSimSkuMap(): SimSkuMap | null {
try {
const raw = process.env.NEXT_PUBLIC_SIM_SKU_MAP;
if (!raw) return null;
const parsed: unknown = JSON.parse(raw);
// Best-effort structural check
if (parsed && typeof parsed === "object") {
return parsed as SimSkuMap;
}
return null;
} catch {
return null;
}
}
/**
* Returns the Product2 SKU for the given SIM configuration.
* If an environment override is present, it takes precedence.
*/
export function getSimServiceSku(
format: SimFormat,
planType: SimPlanType,
dataSize: SimDataSize
): string {
const map = getEnvSimSkuMap() || DEFAULT_SIM_SKU_MAP;
const byFormat = map[format] || {};
const byType = (byFormat[planType] || {}) as Record<string, string>;
return typeof byType[dataSize] === "string" ? byType[dataSize] : "";
}