airalo-sdk-type
Version:
UNOFFICIAL AIRALO API INTEGRATION FOR JAVASCRIPT/TYPESCRIPT
72 lines (71 loc) • 2.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CreateEsimVoucher = exports.GetCompatibleDevices = void 0;
const config_1 = require("../config");
const axios_master_1 = require("axios-master");
const auth_1 = require("./auth");
// eSIM-тэй тохирох төхөөрөмжүүдийн жагсаалтыг авах
const GetCompatibleDevices = async () => {
try {
const result = await (0, axios_master_1.axiosMasterLogger)({
method: "GET",
url: `${config_1.config.host}/v2/compatible-devices`,
headers: {
Accept: "application/json",
Authorization: `Bearer ${config_1.config.token}`
}
}, {
name: "GetCompatibleDevices",
timeout: 20000,
retryFunction: auth_1.getToken,
shouldRetry: true,
shouldRetryStatus: [401],
logger: (data) => config_1.config.logger && console.log("GetCompatibleDevices:", data.json)
});
return { success: true, data: result.data ?? [], message: "Амжилттай." };
}
catch (error) {
const axiosError = error;
console.error("GetCompatibleDevices амжилтгүй:", axiosError.message);
return {
success: false,
data: null,
message: axiosError?.response?.data?.meta?.message ?? "Алдаа гарлаа."
};
}
};
exports.GetCompatibleDevices = GetCompatibleDevices;
// eSIM ваучер үүсгэх
const CreateEsimVoucher = async (params) => {
try {
const result = await (0, axios_master_1.axiosMasterLogger)({
method: "POST",
url: `${config_1.config.host}/v2/voucher/esim`,
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: `Bearer ${config_1.config.token}`
},
data: params
}, {
name: "CreateEsimVoucher",
timeout: 20000,
retryFunction: auth_1.getToken,
shouldRetry: true,
shouldRetryStatus: [401],
logger: (data) => config_1.config.logger && console.log("CreateEsimVoucher:", data.json)
});
return { success: true, data: result.data ?? [], message: "Амжилттай." };
}
catch (error) {
const axiosError = error;
console.error("CreateEsimVoucher амжилтгүй:", axiosError.message);
return {
success: false,
data: null,
message: axiosError?.response?.data?.meta?.message ?? "Алдаа гарлаа."
};
}
};
exports.CreateEsimVoucher = CreateEsimVoucher;
exports.default = { GetCompatibleDevices: exports.GetCompatibleDevices, CreateEsimVoucher: exports.CreateEsimVoucher };