UNPKG

@braze/web-sdk

Version:

Braze SDK for web sites and other JS platforms.

54 lines (53 loc) 1.51 kB
import { Guid as V, logger as E } from "../../shared-lib/index.js"; import { isArray as g } from "../util/code-utils.js"; import { getErrorMessage as ai } from "../util/error-utils.js"; export default class _t { constructor(t, e, i) { (this.Tu = t), null == t && (t = V.de()), !i || isNaN(i) ? (this.lm = new Date().valueOf()) : (this.lm = i), (this.Tu = t), (this.pm = new Date().valueOf()), (this.fm = e); } qt() { return `g:${encodeURIComponent(this.Tu)}|e:${this.fm}|c:${this.lm}|l:${ this.pm }`; } static cS(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 _u(t) { let e; if ("string" == typeof t) try { const i = t.split("|"); if (!g(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.pm = n(i[3])); } catch (e) { E.info( `Unable to parse cookie string ${t}, failed with error: ${ai(e)}`, ); } else { if (null == t || null == t.g) return null; (e = new _t(t.g, t.e, t.c)), (e.pm = t.l); } return e; } }