@braze/web-sdk
Version:
Braze SDK for web sites and other JS platforms.
76 lines (75 loc) • 2.22 kB
JavaScript
import { STORAGE_KEYS as s } from "../managers/storage-manager.js";
import ue from "../models/braze-event.js";
import _t from "../models/identifier.js";
import { convertMsToSeconds as P } from "../util/date-utils.js";
import {
logger as E,
Guid as L,
EventTypes as m,
} from "../../shared-lib/index.js";
export default class Kt {
constructor(s, t, i, e) {
(this.j = s),
(this.Cs = t),
(this.h = i),
(this.zl = e),
(this.j = s),
(this.Cs = t),
(this.h = i),
(this.Hl = 1e3),
(null == e || isNaN(e)) && (e = 1800),
e < this.Hl / 1e3 &&
(E.info(
"Specified session timeout of " +
e +
"s is too small, using the minimum session timeout of " +
this.Hl / 1e3 +
"s instead.",
),
(e = this.Hl / 1e3)),
(this.zl = e);
}
Wl(s, t) {
return new ue(this.Cs.getUserId(), m.Jl, s, t.eu, { d: P(s - t.Ol) });
}
bt() {
const t = this.j.tu(s.iu.Ql);
return null == t ? null : t.eu;
}
Ul() {
const t = new Date().valueOf(),
i = this.h.Kl();
if (null == i) return !1;
const e = this.j.lt(s.ct.Vl),
n = null == e || t - e > 1e3 * i;
return n && this.j.ft(s.ct.Vl, t), n;
}
Xl(s, t) {
return null == t || null == t.Yl || (!(s - t.Ol < this.Hl) && t.Yl < s);
}
Fo() {
const t = new Date().valueOf(),
i = t + 1e3 * this.zl,
e = this.j.tu(s.iu.Ql);
if (this.Xl(t, e)) {
let n = "Generating session start event with time " + t;
if (null != e) {
let s = e.Zl;
s - e.Ol < this.Hl && (s = e.Ol + this.Hl),
this.j.$l(this.Wl(s, e)),
(n += " (old session ended " + s + ")");
}
(n += ". Will expire " + i.valueOf()), E.info(n);
const o = new _t(L.oe(), i);
this.j.$l(new ue(this.Cs.getUserId(), m.sm, t, o.eu)),
this.j.uu(s.iu.Ql, o);
return null == this.j.lt(s.ct.Vl) && this.j.ft(s.ct.Vl, t), o.eu;
}
if (null != e) return (e.Zl = t), (e.Yl = i), this.j.uu(s.iu.Ql, e), e.eu;
}
tm() {
const t = this.j.tu(s.iu.Ql);
null != t &&
(this.j.im(s.iu.Ql), this.j.$l(this.Wl(new Date().valueOf(), t)));
}
}