UNPKG

airalo-sdk-type

Version:

UNOFFICIAL AIRALO API INTEGRATION FOR JAVASCRIPT/TYPESCRIPT

143 lines (142 loc) 5.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SimulateWebhook = exports.GetNotification = exports.NotificationOptOut = exports.NotificationOptIn = void 0; const config_1 = require("../config"); const axios_master_1 = require("axios-master"); const auth_1 = require("./auth"); // Мэдэгдлийн тохиргоог идэвхжүүлэх (opt-in) const NotificationOptIn = async (params) => { try { const result = await (0, axios_master_1.axiosMasterLogger)({ method: "POST", url: `${config_1.config.host}/v2/notifications/opt-in`, headers: { Accept: "application/json", "Content-Type": "application/json", Authorization: `Bearer ${config_1.config.token}` }, data: params }, { name: "NotificationOptIn", timeout: 20000, retryFunction: auth_1.getToken, shouldRetry: true, shouldRetryStatus: [401], logger: (data) => config_1.config.logger && console.log("NotificationOptIn:", data.json) }); return { success: true, data: result.data ?? null, message: "Амжилттай." }; } catch (error) { const axiosError = error; console.error("NotificationOptIn амжилтгүй:", axiosError.message); return { success: false, data: null, message: axiosError?.response?.data?.meta?.message ?? "Алдаа гарлаа." }; } }; exports.NotificationOptIn = NotificationOptIn; // Мэдэгдлийн тохиргоог идэвхгүй болгох (opt-out) const NotificationOptOut = async (params) => { try { const result = await (0, axios_master_1.axiosMasterLogger)({ method: "POST", url: `${config_1.config.host}/v2/notifications/opt-out`, headers: { Accept: "application/json", "Content-Type": "application/json", Authorization: `Bearer ${config_1.config.token}` }, data: params }, { name: "NotificationOptOut", timeout: 20000, retryFunction: auth_1.getToken, shouldRetry: true, shouldRetryStatus: [401], logger: (data) => config_1.config.logger && console.log("NotificationOptOut:", data.json) }); return { success: true, data: result.data ?? null, message: "Амжилттай." }; } catch (error) { const axiosError = error; console.error("NotificationOptOut амжилтгүй:", axiosError.message); return { success: false, data: null, message: axiosError?.response?.data?.meta?.message ?? "Алдаа гарлаа." }; } }; exports.NotificationOptOut = NotificationOptOut; // Идэвхтэй мэдэгдлийн тохиргоог авах const GetNotification = async () => { try { const result = await (0, axios_master_1.axiosMasterLogger)({ method: "GET", url: `${config_1.config.host}/v2/notifications/opt-in`, headers: { Accept: "application/json", Authorization: `Bearer ${config_1.config.token}` } }, { name: "GetNotification", timeout: 20000, retryFunction: auth_1.getToken, shouldRetry: true, shouldRetryStatus: [401], logger: (data) => config_1.config.logger && console.log("GetNotification:", data.json) }); return { success: true, data: result.data ?? [], message: "Амжилттай." }; } catch (error) { const axiosError = error; console.error("GetNotification амжилтгүй:", axiosError.message); return { success: false, data: null, message: axiosError?.response?.data?.meta?.message ?? "Алдаа гарлаа." }; } }; exports.GetNotification = GetNotification; // Webhook-г туршилтаар дуудах (sandbox орчинд) const SimulateWebhook = async (params) => { try { const result = await (0, axios_master_1.axiosMasterLogger)({ method: "POST", url: `${config_1.config.host}/v2/simulator/webhook`, headers: { Accept: "application/json", "Content-Type": "application/json", Authorization: `Bearer ${config_1.config.token}` }, data: params }, { name: "SimulateWebhook", timeout: 20000, retryFunction: auth_1.getToken, shouldRetry: true, shouldRetryStatus: [401], logger: (data) => config_1.config.logger && console.log("SimulateWebhook:", data.json) }); return { success: true, data: result.data ?? null, message: "Амжилттай." }; } catch (error) { const axiosError = error; console.error("SimulateWebhook амжилтгүй:", axiosError.message); return { success: false, data: null, message: axiosError?.response?.data?.meta?.message ?? "Алдаа гарлаа." }; } }; exports.SimulateWebhook = SimulateWebhook; exports.default = { NotificationOptIn: exports.NotificationOptIn, NotificationOptOut: exports.NotificationOptOut, GetNotification: exports.GetNotification, SimulateWebhook: exports.SimulateWebhook };