@braze/web-sdk
Version:
Braze SDK for web sites and other JS platforms.
166 lines (165 loc) • 4.18 kB
JavaScript
import { STORAGE_KEYS as s } from "./storage-manager.js";
import u from "./subscription-manager.js";
import ni from "../models/server-config.js";
import c from "../common/event-logger.js";
import { EventTypes as m } from "../../shared-lib/index.js";
export default class Vt {
constructor(t) {
(this.j = t),
(this.j = t),
(this.El = new u()),
(this.wl = new u()),
(this.Cl = new u()),
(this.yl = new u()),
(this.Ll = new u()),
(this.Tl = null),
(this.Bl = null);
}
Fl() {
if (null == this.Bl) {
const t = this.j.lt(s.ct.jl);
this.Bl = null != t ? ni.Vo(t) : new ni();
}
return this.Bl;
}
Ft() {
return this.Fl().Dl;
}
Nl(t) {
var i, e, n, r;
if (null != t && null != t.config) {
const l = t.config;
if (l.time > this.Fl().Dl) {
const t = (t) => (null == t ? this.Fl().kl : t),
u = new ni(
l.time,
l.events_blacklist,
l.attributes_blacklist,
l.purchases_blacklist,
l.messaging_session_timeout,
l.vapid_public_key,
l.content_cards,
l.feature_flags,
t(l.global_request_rate_limit),
l.banners,
l.dust,
);
let a = !1;
null != u.xl && this.Zn() !== u.xl && (a = !0);
let h = !1;
null != u.Gl.enabled && this.wi() !== u.Gl.enabled && (h = !0);
let o = !1;
null != u.je.enabled && this.Te() !== u.je.enabled && (o = !0);
let d = !1;
null !=
(null === (i = u.banners) || void 0 === i ? void 0 : i.enabled) &&
this.Dt() !==
(null === (e = u.banners) || void 0 === e ? void 0 : e.enabled) &&
(d = !0);
let c = !1;
null != (null === (n = u.dust) || void 0 === n ? void 0 : n.enabled) &&
this.Xi() !==
(null === (r = u.dust) || void 0 === r ? void 0 : r.enabled) &&
(c = !0),
(this.Bl = u),
this.j.ft(s.ct.jl, u.dt()),
a && this.El.L(),
h && this.wl.L(),
o && this.Cl.L(),
d && this.yl.L(),
c && this.Ll.L();
}
}
}
$n(t) {
const i = this.El.wt(t);
return this.Tl && this.El.removeSubscription(this.Tl), (this.Tl = i), i;
}
bi(t) {
return this.wl.wt(t);
}
$e(t) {
return this.Cl.wt(t);
}
P(t) {
return this.yl.wt(t);
}
Tr(t) {
return this.Ll.wt(t);
}
ge(t) {
return -1 !== this.Fl().Il.indexOf(t);
}
hu(t) {
return -1 !== this.Fl().Ml.indexOf(t);
}
Dr(t) {
return -1 !== this.Fl().Sl.indexOf(t);
}
Kl() {
return this.Fl().Pl;
}
Zn() {
return this.Fl().xl;
}
wi() {
return this.Fl().Gl.enabled || !1;
}
_l() {
const t = this.Fl().kl;
return !(!t || null == t.enabled) && t.enabled;
}
Rl() {
if (!this._l()) return -1;
const t = this.Fl().kl;
return null == t.capacity || t.capacity < 10 ? -1 : t.capacity;
}
gl() {
if (!this._l()) return -1;
const t = this.Fl().kl;
return null == t.refill_rate || t.refill_rate <= 0 ? -1 : t.refill_rate;
}
Al(t) {
const i = this.Fl().kl.endpoint_overrides;
return null == i ? null : i[t];
}
bl(t) {
const i = this.Al(t);
return null == i || isNaN(i.capacity) || i.capacity <= 0 ? -1 : i.capacity;
}
ql(t) {
const i = this.Al(t);
return null == i || isNaN(i.refill_rate) || i.refill_rate <= 0
? -1
: i.refill_rate;
}
Te() {
return this.Fl().je.enabled && null == this.Be()
? (c.rt(m.ju, { e: "Missing feature flag refresh_rate_limit." }), !1)
: this.Fl().je.enabled || !1;
}
Be() {
return this.Fl().je.refresh_rate_limit;
}
Dt() {
var t;
return (
(null === (t = this.Fl().banners) || void 0 === t ? void 0 : t.enabled) ||
null
);
}
te() {
var t;
return (
(null === (t = this.Fl().banners) || void 0 === t
? void 0
: t.max_placements) || 0
);
}
Xi() {
var t;
return (
(null === (t = this.Fl().dust) || void 0 === t ? void 0 : t.enabled) || !1
);
}
}