UNPKG

@braze/web-sdk

Version:

Braze SDK for web sites and other JS platforms.

54 lines (53 loc) 1.51 kB
import { Guid as L, logger as E } from "../../shared-lib/index.js"; import { isArray as z } 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 = L.oe()), !i || isNaN(i) ? (this.Ol = new Date().valueOf()) : (this.Ol = i), (this.eu = t), (this.Zl = new Date().valueOf()), (this.Yl = e); } dt() { return `g:${encodeURIComponent(this.eu)}|e:${this.Yl}|c:${this.Ol}|l:${ this.Zl }`; } 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 Vo(t) { let e; if ("string" == typeof t) try { const i = t.split("|"); if (!z(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.Zl = 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.Zl = t.l); } return e; } }