UNPKG

@braze/web-sdk

Version:

Braze SDK for web sites and other JS platforms.

137 lines (136 loc) 3.42 kB
import { STORAGE_KEYS as s } from "./storage-manager.js"; import u from "./subscription-manager.js"; import Jt 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.il = new u()), (this.sl = new u()), (this.rl = new u()), (this.al = new u()), (this.hl = null), (this.ul = null); } ol() { if (null == this.ul) { const t = this.C.ft(s.gt.cl); this.ul = null != t ? Jt.En(t) : new Jt(); } return this.ul; } Et() { return this.ol().ml; } gl(t) { if (null != t && null != t.config) { const e = t.config; if (e.time > this.ol().ml) { const t = (t) => (null == t ? this.ol().bl : t), i = new Jt( e.time, e.events_blacklist, e.attributes_blacklist, e.purchases_blacklist, e.messaging_session_timeout, e.vapid_public_key, e.content_cards, e.feature_flags, t(e.global_request_rate_limit), e.banners, ); let n = !1; null != i.fl && this.Tn() !== i.fl && (n = !0); let r = !1; null != i.dl.enabled && this.Ri() !== i.dl.enabled && (r = !0); let l = !1; null != i.De.enabled && this.Be() !== i.De.enabled && (l = !0); let a = !1; null != i.banners.enabled && this.Dt() !== i.banners.enabled && (a = !0), (this.ul = i), this.C.Bt(s.gt.cl, i.bt()), n && this.il.X(), r && this.sl.X(), l && this.rl.X(), a && this.al.X(); } } } In(t) { const e = this.il.Ft(t); return this.hl && this.il.removeSubscription(this.hl), (this.hl = e), e; } ji(t) { return this.sl.Ft(t); } Ke(t) { return this.rl.Ft(t); } A(t) { return this.al.Ft(t); } je(t) { return -1 !== this.ol().Rl.indexOf(t); } hu(t) { return -1 !== this.ol().Cl.indexOf(t); } Dr(t) { return -1 !== this.ol().El.indexOf(t); } vl() { return this.ol().wl; } Tn() { return this.ol().fl; } Ri() { return this.ol().dl.enabled || !1; } yl() { const t = this.ol().bl; return !(!t || null == t.enabled) && t.enabled; } Vu() { if (!this.yl()) return -1; const t = this.ol().bl; return null == t.capacity || t.capacity < 10 ? -1 : t.capacity; } Zu() { if (!this.yl()) return -1; const t = this.ol().bl; return null == t.refill_rate || t.refill_rate <= 0 ? -1 : t.refill_rate; } Ll(t) { const e = this.ol().bl.endpoint_overrides; return null == e ? null : e[t]; } tl(t) { const e = this.Ll(t); return null == e || isNaN(e.capacity) || e.capacity <= 0 ? -1 : e.capacity; } el(t) { const e = this.Ll(t); return null == e || isNaN(e.refill_rate) || e.refill_rate <= 0 ? -1 : e.refill_rate; } Be() { return this.ol().De.enabled && null == this.Oe() ? (c.ut(d.bu, { e: "Missing feature flag refresh_rate_limit." }), !1) : this.ol().De.enabled || !1; } Oe() { return this.ol().De.refresh_rate_limit; } Dt() { return this.ol().banners.enabled || !1; } ne() { return this.ol().banners.max_placements || 0; } }