@zencemarketing/web-sdk
Version:
ZenceMarketing Web SDK for push notifications, popups, and custom event tracking.
55 lines (47 loc) • 1.33 kB
text/typescript
import apiRequest from "../api.js";
import { logger } from "../index.js";
import { InitData, SDKData, SDKResponse } from "../types/types.js";
let authToken: string | null = null;
let sdkData: 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: InitData): Promise<SDKResponse> {
const response = await apiRequest<SDKResponse>("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 = (): string | null => authToken;
const getSdkData = (): SDKData => {
return sdkData;
};
export { init, getSdkData, getAuthToken };