UNPKG

@zencemarketing/web-sdk

Version:

ZenceMarketing Web SDK for push notifications, popups, and custom event tracking.

48 lines (47 loc) 1.25 kB
import apiRequest from "../api.js"; import { logger } from "../index.js"; let authToken = null; let sdkData = { programcode: '', website_url: '', instance_type: '', redpanda_broker_ip: '', redpanda_incoming: '', redpanda_outgoing: '', redpanda_clicks_queue: '', show_web_pop: "0", show_web_push: "0", show_custom_event: "0", isactive: false, configuration: {}, opt_in_prompt: {}, public_vapid_key: '', pushSubscribed: false, popSubscribed: false, userID: '', sub: {}, token: null, }; async function init(data) { const response = await apiRequest("auth/init", "POST", { clientID: data.clientID, clientSecret: data.clientSecret, programCode: data.programCode, websiteUrl: data.websiteUrl, }); if (response.success) { sdkData = response.results; authToken = response.token; sdkData.token = authToken; logger.info("SDK initialized successfully.", sdkData); } else { logger.error("SDK initialization failed:", response.error); } return response; } const getAuthToken = () => authToken; const getSdkData = () => { return sdkData; }; export { init, getSdkData, getAuthToken };