UNPKG

@braze/web-sdk

Version:

Braze SDK for web sites and other JS platforms.

207 lines (206 loc) 5.19 kB
import { STORAGE_KEYS as s } from "./storage-manager.js"; import f from "./subscription-manager.js"; import ci from "../models/server-config.js"; import v from "../common/event-logger.js"; import { EventTypes as p } from "../../shared-lib/index.js"; import { DISMISSALS_CACHE_SIZE_DEFAULT as u, REQUEST_BACKOFF_MAX_SLEEP_MS_DEFAULT as c, REQUEST_BACKOFF_MIN_SLEEP_MS_DEFAULT as d, REQUEST_BACKOFF_SCALE_FACTOR_DEFAULT as m, } from "../common/constants.js"; export default class Yt { constructor(t) { (this.C = t), (this.C = t), (this.Gl = new f()), (this._l = new f()), (this.Vl = new f()), (this.Jl = new f()), (this.Ql = new f()), (this.Wl = null), (this.Yl = null); } Zl() { if (null == this.Yl) { const t = this.C.Rt(s.Tt.tc); this.Yl = null != t ? ci._u(t) : new ci(); } return this.Yl; } Ot() { return this.Zl().ec; } sc(t) { var i, e, n, r; if (null != t && null != t.config) { const l = t.config; if (l.time > this.Zl().ec) { const t = (t) => (null == t ? this.Zl().nc : t), u = new ci( 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, l.request_backoff, l.minimum_session_timeout, ); let o = !1; null != u.rc && this.ju() !== u.rc && (o = !0); let a = !1; null != u.lc.enabled && this.Bi() !== u.lc.enabled && (a = !0); let h = !1; null != u.Xr.enabled && this.lo() !== u.Xr.enabled && (h = !0); let c = !1; null != (null === (i = u.banners) || void 0 === i ? void 0 : i.enabled) && this.Jt() !== (null === (e = u.banners) || void 0 === e ? void 0 : e.enabled) && (c = !0); let d = !1; null != (null === (n = u.dust) || void 0 === n ? void 0 : n.enabled) && this.fn() !== (null === (r = u.dust) || void 0 === r ? void 0 : r.enabled) && (d = !0), (this.Yl = u), this.C.It(s.Tt.tc, u.qt()), o && this.Gl.A(), a && this._l.A(), h && this.Vl.A(), c && this.Jl.A(), d && this.Ql.A(); } } } xu(t) { const i = this.Gl.Kt(t); return this.Wl && this.Gl.removeSubscription(this.Wl), (this.Wl = i), i; } Mi(t) { return this._l.Kt(t); } bo(t) { return this.Vl.Kt(t); } V(t) { return this.Jl.Kt(t); } Tr(t) { return this.Ql.Kt(t); } $e(t) { return -1 !== this.Zl().uc.indexOf(t); } qu(t) { return -1 !== this.Zl().oc.indexOf(t); } Dr(t) { return -1 !== this.Zl().ac.indexOf(t); } hc() { return this.Zl().cc; } ju() { return this.Zl().rc; } Bi() { return this.Zl().lc.enabled || !1; } dc() { const t = this.Zl().nc; return !(!t || null == t.enabled) && t.enabled; } Ul() { if (!this.dc()) return -1; const t = this.Zl().nc; return null == t.capacity || t.capacity < 10 ? -1 : t.capacity; } xl() { if (!this.dc()) return -1; const t = this.Zl().nc; return null == t.refill_rate || t.refill_rate <= 0 ? -1 : t.refill_rate; } mc(t) { const i = this.Zl().nc.endpoint_overrides; return null == i ? null : i[t]; } Hl(t) { const i = this.mc(t); return null == i || isNaN(i.capacity) || i.capacity <= 0 ? -1 : i.capacity; } Ol(t) { const i = this.mc(t); return null == i || isNaN(i.refill_rate) || i.refill_rate <= 0 ? -1 : i.refill_rate; } lo() { return this.Zl().Xr.enabled && null == this.Ro() ? (v.wt(p.Ya, { e: "Missing feature flag refresh_rate_limit." }), !1) : this.Zl().Xr.enabled || !1; } Ro() { return this.Zl().Xr.refresh_rate_limit; } Jt() { var t; return ( (null === (t = this.Zl().banners) || void 0 === t ? void 0 : t.enabled) || null ); } re() { var t; return ( (null === (t = this.Zl().banners) || void 0 === t ? void 0 : t.max_placements) || 0 ); } Xt() { var t; const i = null === (t = this.Zl().banners) || void 0 === t ? void 0 : t.dismissals_cache_size; return null != i && "number" == typeof i && i > 0 ? i : u; } fn() { var t; return ( (null === (t = this.Zl().dust) || void 0 === t ? void 0 : t.enabled) || !1 ); } vt() { var t; const i = null === (t = this.Zl().vc) || void 0 === t ? void 0 : t.min_sleep_duration_ms; return null != i ? i : d; } gt() { var t; const i = null === (t = this.Zl().vc) || void 0 === t ? void 0 : t.scale_factor; return null != i ? i : m; } bt() { var t; const i = null === (t = this.Zl().vc) || void 0 === t ? void 0 : t.max_sleep_duration_ms; return null != i ? i : c; } gc() { return this.Zl().fc; } }