@braze/web-sdk
Version:
Braze SDK for web sites and other JS platforms.
149 lines (148 loc) • 3.71 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.tl = new u()),
(this.il = new u()),
(this.el = new u()),
(this.sl = new u()),
(this.rl = null),
(this.ul = null);
}
al() {
if (null == this.ul) {
const t = this.j.lt(s.ct.hl);
this.ul = null != t ? ni.qn(t) : new ni();
}
return this.ul;
}
Ft() {
return this.al().ol;
}
cl(t) {
var i, e;
if (null != t && null != t.config) {
const n = t.config;
if (n.time > this.al().ol) {
const t = (t) => (null == t ? this.al().ml : t),
r = new ni(
n.time,
n.events_blacklist,
n.attributes_blacklist,
n.purchases_blacklist,
n.messaging_session_timeout,
n.vapid_public_key,
n.content_cards,
n.feature_flags,
t(n.global_request_rate_limit),
n.banners,
);
let l = !1;
null != r.dl && this.Wn() !== r.dl && (l = !0);
let u = !1;
null != r.gl.enabled && this.gi() !== r.gl.enabled && (u = !0);
let a = !1;
null != r.he.enabled && this.Re() !== r.he.enabled && (a = !0);
let h = !1;
null !=
(null === (i = r.banners) || void 0 === i ? void 0 : i.enabled) &&
this.Dt() !==
(null === (e = r.banners) || void 0 === e ? void 0 : e.enabled) &&
(h = !0),
(this.ul = r),
this.j.ft(s.ct.hl, r.dt()),
l && this.tl.L(),
u && this.il.L(),
a && this.el.L(),
h && this.sl.L();
}
}
}
_n(t) {
const i = this.tl.wt(t);
return this.rl && this.tl.removeSubscription(this.rl), (this.rl = i), i;
}
vi(t) {
return this.il.wt(t);
}
Ue(t) {
return this.el.wt(t);
}
P(t) {
return this.sl.wt(t);
}
ge(t) {
return -1 !== this.al().bl.indexOf(t);
}
hu(t) {
return -1 !== this.al().fl.indexOf(t);
}
Dr(t) {
return -1 !== this.al().vl.indexOf(t);
}
Rl() {
return this.al().Cl;
}
Wn() {
return this.al().dl;
}
gi() {
return this.al().gl.enabled || !1;
}
El() {
const t = this.al().ml;
return !(!t || null == t.enabled) && t.enabled;
}
Ju() {
if (!this.El()) return -1;
const t = this.al().ml;
return null == t.capacity || t.capacity < 10 ? -1 : t.capacity;
}
Qu() {
if (!this.El()) return -1;
const t = this.al().ml;
return null == t.refill_rate || t.refill_rate <= 0 ? -1 : t.refill_rate;
}
wl(t) {
const i = this.al().ml.endpoint_overrides;
return null == i ? null : i[t];
}
Vu(t) {
const i = this.wl(t);
return null == i || isNaN(i.capacity) || i.capacity <= 0 ? -1 : i.capacity;
}
Zu(t) {
const i = this.wl(t);
return null == i || isNaN(i.refill_rate) || i.refill_rate <= 0
? -1
: i.refill_rate;
}
Re() {
return this.al().he.enabled && null == this.ke()
? (c.rt(m.pu, { e: "Missing feature flag refresh_rate_limit." }), !1)
: this.al().he.enabled || !1;
}
ke() {
return this.al().he.refresh_rate_limit;
}
Dt() {
var t;
return (
(null === (t = this.al().banners) || void 0 === t ? void 0 : t.enabled) ||
null
);
}
te() {
var t;
return (
(null === (t = this.al().banners) || void 0 === t
? void 0
: t.max_placements) || 0
);
}
}