UNPKG

@braze/web-sdk

Version:

Braze SDK for web sites and other JS platforms.

76 lines (75 loc) 2.22 kB
import { STORAGE_KEYS as s } from "../managers/storage-manager.js"; import ve from "../models/braze-event.js"; import _t from "../models/identifier.js"; import { convertMsToSeconds as L } from "../util/date-utils.js"; import { logger as N, Guid as G, EventTypes as d, } from "../../shared-lib/index.js"; export default class Wt { constructor(s, t, i, e) { (this.C = s), (this.Cs = t), (this.B = i), (this.Sl = e), (this.C = s), (this.Cs = t), (this.B = i), (this.jl = 1e3), (null == e || isNaN(e)) && (e = 1800), e < this.jl / 1e3 && (N.info( "Specified session timeout of " + e + "s is too small, using the minimum session timeout of " + this.jl / 1e3 + "s instead.", ), (e = this.jl / 1e3)), (this.Sl = e); } xl(s, t) { return new ve(this.Cs.getUserId(), d.Dl, s, t.eu, { d: L(s - t.Gl) }); } St() { const t = this.C.tu(s.iu.Nl); return null == t ? null : t.eu; } zl() { const t = new Date().valueOf(), i = this.B.vl(); if (null == i) return !1; const e = this.C.ft(s.gt.Hl), n = null == e || t - e > 1e3 * i; return n && this.C.Bt(s.gt.Hl, t), n; } Wl(s, t) { return null == t || null == t.kl || (!(s - t.Gl < this.jl) && t.kl < s); } Qo() { const t = new Date().valueOf(), i = t + 1e3 * this.Sl, e = this.C.tu(s.iu.Nl); if (this.Wl(t, e)) { let n = "Generating session start event with time " + t; if (null != e) { let s = e.ql; s - e.Gl < this.jl && (s = e.Gl + this.jl), this.C.Al(this.xl(s, e)), (n += " (old session ended " + s + ")"); } (n += ". Will expire " + i.valueOf()), N.info(n); const o = new _t(G.ce(), i); this.C.Al(new ve(this.Cs.getUserId(), d.Bl, t, o.eu)), this.C.uu(s.iu.Nl, o); return null == this.C.ft(s.gt.Hl) && this.C.Bt(s.gt.Hl, t), o.eu; } if (null != e) return (e.ql = t), (e.kl = i), this.C.uu(s.iu.Nl, e), e.eu; } Fl() { const t = this.C.tu(s.iu.Nl); null != t && (this.C.Il(s.iu.Nl), this.C.Al(this.xl(new Date().valueOf(), t))); } }