163 lines
6.7 KiB
JavaScript
163 lines
6.7 KiB
JavaScript
|
|
"use strict";
|
||
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
|
exports.transformFreebitAccountDetails = transformFreebitAccountDetails;
|
||
|
|
exports.transformFreebitTrafficInfo = transformFreebitTrafficInfo;
|
||
|
|
exports.transformFreebitQuotaHistory = transformFreebitQuotaHistory;
|
||
|
|
exports.transformFreebitTopUpResponse = transformFreebitTopUpResponse;
|
||
|
|
exports.transformFreebitAddSpecResponse = transformFreebitAddSpecResponse;
|
||
|
|
exports.transformFreebitPlanChangeResponse = transformFreebitPlanChangeResponse;
|
||
|
|
exports.transformFreebitCancelPlanResponse = transformFreebitCancelPlanResponse;
|
||
|
|
exports.transformFreebitCancelAccountResponse = transformFreebitCancelAccountResponse;
|
||
|
|
exports.transformFreebitEsimReissueResponse = transformFreebitEsimReissueResponse;
|
||
|
|
exports.transformFreebitEsimAddAccountResponse = transformFreebitEsimAddAccountResponse;
|
||
|
|
exports.transformFreebitEsimActivationResponse = transformFreebitEsimActivationResponse;
|
||
|
|
exports.transformFreebitAuthResponse = transformFreebitAuthResponse;
|
||
|
|
const schema_1 = require("../../schema");
|
||
|
|
const raw_types_1 = require("./raw.types");
|
||
|
|
function asString(value) {
|
||
|
|
if (typeof value === "string")
|
||
|
|
return value;
|
||
|
|
if (typeof value === "number")
|
||
|
|
return String(value);
|
||
|
|
return "";
|
||
|
|
}
|
||
|
|
function asNumber(value) {
|
||
|
|
if (typeof value === "number")
|
||
|
|
return value;
|
||
|
|
if (typeof value === "string") {
|
||
|
|
const parsed = parseFloat(value);
|
||
|
|
return isNaN(parsed) ? 0 : parsed;
|
||
|
|
}
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
function parseBooleanFlag(value) {
|
||
|
|
if (typeof value === "boolean")
|
||
|
|
return value;
|
||
|
|
if (typeof value === "number")
|
||
|
|
return value === 10;
|
||
|
|
if (typeof value === "string")
|
||
|
|
return value === "10" || value.toLowerCase() === "true";
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
function mapSimStatus(status) {
|
||
|
|
if (!status)
|
||
|
|
return "pending";
|
||
|
|
const normalized = status.toLowerCase();
|
||
|
|
if (normalized.includes("active") || normalized === "10")
|
||
|
|
return "active";
|
||
|
|
if (normalized.includes("suspend"))
|
||
|
|
return "suspended";
|
||
|
|
if (normalized.includes("cancel") || normalized.includes("terminate"))
|
||
|
|
return "cancelled";
|
||
|
|
return "pending";
|
||
|
|
}
|
||
|
|
function deriveSimType(sizeValue, eid) {
|
||
|
|
const simSizeStr = typeof sizeValue === "number" ? String(sizeValue) : sizeValue;
|
||
|
|
const raw = typeof simSizeStr === "string" ? simSizeStr.toLowerCase() : undefined;
|
||
|
|
const eidStr = typeof eid === "number" ? String(eid) : eid;
|
||
|
|
if (eidStr && eidStr.length > 0) {
|
||
|
|
return "esim";
|
||
|
|
}
|
||
|
|
switch (raw) {
|
||
|
|
case "nano":
|
||
|
|
return "nano";
|
||
|
|
case "micro":
|
||
|
|
return "micro";
|
||
|
|
case "esim":
|
||
|
|
return "esim";
|
||
|
|
default:
|
||
|
|
return "standard";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
function transformFreebitAccountDetails(raw) {
|
||
|
|
const response = raw_types_1.freebitAccountDetailsRawSchema.parse(raw);
|
||
|
|
const account = response.responseDatas.at(0);
|
||
|
|
if (!account) {
|
||
|
|
throw new Error("Freebit account details missing response data");
|
||
|
|
}
|
||
|
|
const sanitizedAccount = asString(account.account);
|
||
|
|
const simSizeValue = account.simSize ?? account.size;
|
||
|
|
const eidValue = account.eid;
|
||
|
|
const simType = deriveSimType(typeof simSizeValue === 'number' ? String(simSizeValue) : simSizeValue, typeof eidValue === 'number' ? String(eidValue) : eidValue);
|
||
|
|
const voiceMailEnabled = parseBooleanFlag(account.voicemail ?? account.voiceMail);
|
||
|
|
const callWaitingEnabled = parseBooleanFlag(account.callwaiting ?? account.callWaiting);
|
||
|
|
const internationalRoamingEnabled = parseBooleanFlag(account.worldwing ?? account.worldWing);
|
||
|
|
const simDetails = {
|
||
|
|
account: sanitizedAccount,
|
||
|
|
status: mapSimStatus(account.status),
|
||
|
|
planCode: asString(account.planCode),
|
||
|
|
planName: asString(account.planName),
|
||
|
|
simType,
|
||
|
|
iccid: asString(account.iccid),
|
||
|
|
eid: asString(eidValue),
|
||
|
|
msisdn: asString(account.msisdn),
|
||
|
|
imsi: asString(account.imsi),
|
||
|
|
remainingQuotaMb: asNumber(account.quota),
|
||
|
|
remainingQuotaKb: asNumber(account.quotaKb),
|
||
|
|
voiceMailEnabled,
|
||
|
|
callWaitingEnabled,
|
||
|
|
internationalRoamingEnabled,
|
||
|
|
networkType: asString(account.contractLine),
|
||
|
|
activatedAt: asString(account.startDate) || undefined,
|
||
|
|
expiresAt: asString(account.expireDate) || undefined,
|
||
|
|
};
|
||
|
|
return schema_1.simDetailsSchema.parse(simDetails);
|
||
|
|
}
|
||
|
|
function transformFreebitTrafficInfo(raw) {
|
||
|
|
const response = raw_types_1.freebitTrafficInfoRawSchema.parse(raw);
|
||
|
|
const simUsage = {
|
||
|
|
account: asString(response.account),
|
||
|
|
todayUsageMb: response.traffic?.today ? asNumber(response.traffic.today) / 1024 : 0,
|
||
|
|
todayUsageKb: response.traffic?.today ? asNumber(response.traffic.today) : 0,
|
||
|
|
monthlyUsageMb: undefined,
|
||
|
|
monthlyUsageKb: undefined,
|
||
|
|
recentDaysUsage: [],
|
||
|
|
isBlacklisted: parseBooleanFlag(response.traffic?.blackList),
|
||
|
|
lastUpdated: new Date().toISOString(),
|
||
|
|
};
|
||
|
|
return schema_1.simUsageSchema.parse(simUsage);
|
||
|
|
}
|
||
|
|
function transformFreebitQuotaHistory(raw, accountOverride) {
|
||
|
|
const response = raw_types_1.freebitQuotaHistoryRawSchema.parse(raw);
|
||
|
|
const history = {
|
||
|
|
account: accountOverride ?? asString(response.account),
|
||
|
|
totalAdditions: asNumber(response.total),
|
||
|
|
additionCount: asNumber(response.count),
|
||
|
|
history: (response.quotaHistory || []).map(detail => ({
|
||
|
|
quotaKb: asNumber(detail.addQuotaKb),
|
||
|
|
quotaMb: asNumber(detail.addQuotaKb) / 1024,
|
||
|
|
addedDate: detail.addDate || "",
|
||
|
|
expiryDate: detail.expireDate || "",
|
||
|
|
campaignCode: detail.campaignCode || "",
|
||
|
|
})),
|
||
|
|
};
|
||
|
|
return schema_1.simTopUpHistorySchema.parse(history);
|
||
|
|
}
|
||
|
|
function transformFreebitTopUpResponse(raw) {
|
||
|
|
return raw_types_1.freebitTopUpRawSchema.parse(raw);
|
||
|
|
}
|
||
|
|
function transformFreebitAddSpecResponse(raw) {
|
||
|
|
return raw_types_1.freebitAddSpecRawSchema.parse(raw);
|
||
|
|
}
|
||
|
|
function transformFreebitPlanChangeResponse(raw) {
|
||
|
|
return raw_types_1.freebitPlanChangeRawSchema.parse(raw);
|
||
|
|
}
|
||
|
|
function transformFreebitCancelPlanResponse(raw) {
|
||
|
|
return raw_types_1.freebitCancelPlanRawSchema.parse(raw);
|
||
|
|
}
|
||
|
|
function transformFreebitCancelAccountResponse(raw) {
|
||
|
|
return raw_types_1.freebitCancelAccountRawSchema.parse(raw);
|
||
|
|
}
|
||
|
|
function transformFreebitEsimReissueResponse(raw) {
|
||
|
|
return raw_types_1.freebitEsimReissueRawSchema.parse(raw);
|
||
|
|
}
|
||
|
|
function transformFreebitEsimAddAccountResponse(raw) {
|
||
|
|
return raw_types_1.freebitEsimAddAccountRawSchema.parse(raw);
|
||
|
|
}
|
||
|
|
function transformFreebitEsimActivationResponse(raw) {
|
||
|
|
return raw_types_1.freebitEsimAddAccountRawSchema.parse(raw);
|
||
|
|
}
|
||
|
|
function transformFreebitAuthResponse(raw) {
|
||
|
|
return raw_types_1.freebitAuthResponseRawSchema.parse(raw);
|
||
|
|
}
|
||
|
|
//# sourceMappingURL=mapper.js.map
|