UNPKG

@braze/web-sdk

Version:

Braze SDK for web sites and other JS platforms.

149 lines (148 loc) 3.71 kB
import { STORAGE_KEYS as s } from "./storage-manager.js"; import u from "./subscription-manager.js"; import Qt from "../models/server-config.js"; import c from "../common/event-logger.js"; import { EventTypes as d } from "../../shared-lib/index.js"; export default class Mt { constructor(t) { (this.C = t), (this.C = t), (this.sl = new u()), (this.rl = new u()), (this.ul = new u()), (this.al = new u()), (this.hl = null), (this.ol = null); } cl() { if (null == this.ol) { const t = this.C.ft(s.gt.ml); this.ol = null != t ? Qt.Rn(t) : new Qt(); } return this.ol; } Et() { return this.cl().dl; } gl(t) { var i, e; if (null != t && null != t.config) { const n = t.config; if (n.time > this.cl().dl) { const t = (t) => (null == t ? this.cl().bl : t), r = new Qt( 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.fl && this.In() !== r.fl && (l = !0); let u = !1; null != r.vl.enabled && this.yi() !== r.vl.enabled && (u = !0); let a = !1; null != r.De.enabled && this.ke() !== r.De.enabled && (a = !0); let h = !1; null != (null === (i = r.banners) || void 0 === i ? void 0 : i.enabled) && this.zt() !== (null === (e = r.banners) || void 0 === e ? void 0 : e.enabled) && (h = !0), (this.ol = r), this.C.Bt(s.gt.ml, r.bt()), l && this.sl.X(), u && this.rl.X(), a && this.ul.X(), h && this.al.X(); } } } Vn(t) { const i = this.sl.Dt(t); return this.hl && this.sl.removeSubscription(this.hl), (this.hl = i), i; } gi(t) { return this.rl.Dt(t); } Ke(t) { return this.ul.Dt(t); } A(t) { return this.al.Dt(t); } je(t) { return -1 !== this.cl().Rl.indexOf(t); } hu(t) { return -1 !== this.cl().Cl.indexOf(t); } Dr(t) { return -1 !== this.cl().El.indexOf(t); } wl() { return this.cl().yl; } In() { return this.cl().fl; } yi() { return this.cl().vl.enabled || !1; } Ll() { const t = this.cl().bl; return !(!t || null == t.enabled) && t.enabled; } Zu() { if (!this.Ll()) return -1; const t = this.cl().bl; return null == t.capacity || t.capacity < 10 ? -1 : t.capacity; } tl() { if (!this.Ll()) return -1; const t = this.cl().bl; return null == t.refill_rate || t.refill_rate <= 0 ? -1 : t.refill_rate; } Bl(t) { const i = this.cl().bl.endpoint_overrides; return null == i ? null : i[t]; } el(t) { const i = this.Bl(t); return null == i || isNaN(i.capacity) || i.capacity <= 0 ? -1 : i.capacity; } il(t) { const i = this.Bl(t); return null == i || isNaN(i.refill_rate) || i.refill_rate <= 0 ? -1 : i.refill_rate; } ke() { return this.cl().De.enabled && null == this.Oe() ? (c.ut(d.qu, { e: "Missing feature flag refresh_rate_limit." }), !1) : this.cl().De.enabled || !1; } Oe() { return this.cl().De.refresh_rate_limit; } zt() { var t; return ( (null === (t = this.cl().banners) || void 0 === t ? void 0 : t.enabled) || null ); } ne() { var t; return ( (null === (t = this.cl().banners) || void 0 === t ? void 0 : t.max_placements) || 0 ); } }