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 ni from "../models/server-config.js"; import c from "../common/event-logger.js"; import { EventTypes as d } from "../../shared-lib/index.js"; export default class Vt { constructor(t) { (this.C = t), (this.C = t), (this.Vl = new u()), (this.Jl = new u()), (this.Ql = new u()), (this.Yl = new u()), (this.Zl = null), (this.au = null); } du() { if (null == this.au) { const t = this.C.ft(s.gt.gu); this.au = null != t ? ni.zn(t) : new ni(); } return this.au; } Et() { return this.du().bu; } fu(t) { var i, e; if (null != t && null != t.config) { const n = t.config; if (n.time > this.du().bu) { const t = (t) => (null == t ? this.du().vu : 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.pu && this._n() !== r.pu && (l = !0); let u = !1; null != r.Ru.enabled && this.ji() !== r.Ru.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.au = r), this.C.Bt(s.gt.gu, r.bt()), l && this.Vl.X(), u && this.Jl.X(), a && this.Ql.X(), h && this.Yl.X(); } } } Tn(t) { const i = this.Vl.Dt(t); return this.Zl && this.Vl.removeSubscription(this.Zl), (this.Zl = i), i; } wi(t) { return this.Jl.Dt(t); } Ke(t) { return this.Ql.Dt(t); } A(t) { return this.Yl.Dt(t); } je(t) { return -1 !== this.du().Cu.indexOf(t); } hu(t) { return -1 !== this.du().Eu.indexOf(t); } Dr(t) { return -1 !== this.du().wu.indexOf(t); } yu() { return this.du().Lu; } _n() { return this.du().pu; } ji() { return this.du().Ru.enabled || !1; } Bu() { const t = this.du().vu; return !(!t || null == t.enabled) && t.enabled; } Ol() { if (!this.Bu()) return -1; const t = this.du().vu; return null == t.capacity || t.capacity < 10 ? -1 : t.capacity; } Gl() { if (!this.Bu()) return -1; const t = this.du().vu; return null == t.refill_rate || t.refill_rate <= 0 ? -1 : t.refill_rate; } Fu(t) { const i = this.du().vu.endpoint_overrides; return null == i ? null : i[t]; } _l(t) { const i = this.Fu(t); return null == i || isNaN(i.capacity) || i.capacity <= 0 ? -1 : i.capacity; } Wl(t) { const i = this.Fu(t); return null == i || isNaN(i.refill_rate) || i.refill_rate <= 0 ? -1 : i.refill_rate; } ke() { return this.du().De.enabled && null == this.Oe() ? (c.ut(d.ul, { e: "Missing feature flag refresh_rate_limit." }), !1) : this.du().De.enabled || !1; } Oe() { return this.du().De.refresh_rate_limit; } zt() { var t; return ( (null === (t = this.du().banners) || void 0 === t ? void 0 : t.enabled) || null ); } ne() { var t; return ( (null === (t = this.du().banners) || void 0 === t ? void 0 : t.max_placements) || 0 ); } }