@braze/web-sdk
Version:
Braze SDK for web sites and other JS platforms.
54 lines (53 loc) • 1.51 kB
JavaScript
import { Guid as P, logger as E } from "../../shared-lib/index.js";
import { isArray as D } from "../util/code-utils.js";
import { getErrorMessage as si } from "../util/error-utils.js";
export default class _t {
constructor(t, e, i) {
(this.eu = t),
null == t && (t = P.oe()),
!i || isNaN(i) ? (this.Gl = new Date().valueOf()) : (this.Gl = i),
(this.eu = t),
(this.ql = new Date().valueOf()),
(this.kl = e);
}
dt() {
return `g:${encodeURIComponent(this.eu)}|e:${this.kl}|c:${this.Gl}|l:${
this.ql
}`;
}
static AE(t) {
if ("string" != typeof t) return null;
const e = t.lastIndexOf("|e:"),
i = t.substring(0, e),
r = i.split("g:")[1];
let n;
return (
(n = /[|:]/.test(r) ? encodeURIComponent(r) : r),
(t = t.replace(i, `g:${n}`))
);
}
static qn(t) {
let e;
if ("string" == typeof t)
try {
const i = t.split("|");
if (!D(i) || 4 !== i.length) return null;
const r = (t) => t.split(":")[1],
n = (t) => {
const e = parseInt(r(t));
if (!isNaN(e)) return e;
};
(e = new _t(decodeURIComponent(r(i[0])), n(i[1]), n(i[2]))),
(e.ql = n(i[3]));
} catch (e) {
E.info(
`Unable to parse cookie string ${t}, failed with error: ${si(e)}`,
);
}
else {
if (null == t || null == t.g) return null;
(e = new _t(t.g, t.e, t.c)), (e.ql = t.l);
}
return e;
}
}