@klevu/core
Version:
Typescript SDK that simplifies development on Klevu backend. Klevu provides advanced AI-powered search and discovery solutions for online retailers.
65 lines (64 loc) • 1.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Klaviyo = void 0;
const index_js_1 = require("../index.js");
const usersession_js_1 = require("../resolvers/usersession.js");
class Klaviyo {
constructor() {
this.timer = null;
}
setExchangeId() {
var _a;
if (!globalThis._learnq) {
if (!this.timer) {
this.timer = setInterval(() => {
this.setExchangeId();
}, 300);
}
return;
}
const _getIdentifiersResponse = (_a = globalThis._learnq) === null || _a === void 0 ? void 0 : _a.push([
"_getIdentifiers",
"",
{},
]);
this.exchangeId = _getIdentifiersResponse.$exchange_id;
if (!this.exchangeId) {
if (!this.timer) {
this.timer = setInterval(() => {
this.setExchangeId();
}, 300);
}
return;
}
if (this.timer) {
clearInterval(this.timer);
}
usersession_js_1.KlevuUserSession.getDefault().generateSession();
}
static init() {
Klaviyo.default = new Klaviyo();
this.getDefault().setExchangeId();
}
static getDefault() {
if (!Klaviyo.default) {
throw new Error("Klaviyo not initialized.");
}
return Klaviyo.default;
}
getExchangeId() {
return this.exchangeId;
}
static generatePayload() {
if (!index_js_1.KlevuConfig.getDefault().enableKlaviyoConnector ||
!this.default ||
!this.getDefault().exchangeId) {
return undefined;
}
return {
connectorType: "klaviyo",
exchangeId: this.getDefault().exchangeId || "",
};
}
}
exports.Klaviyo = Klaviyo;