@braze/web-sdk
Version:
Braze SDK for web sites and other JS platforms.
224 lines (223 loc) • 5.67 kB
JavaScript
import { STORAGE_KEYS as s } from "./storage-manager.js";
import f from "./subscription-manager.js";
import di 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.j = t),
(this.j = t),
(this.Gl = new f()),
(this._l = new f()),
(this.Vl = new f()),
(this.Jl = new f()),
(this.Ql = new f()),
(this.Wl = new f()),
(this.Yl = null),
(this.Zl = null);
}
ed() {
if (null == this.Zl) {
const t = this.j.St(s.It.sd);
this.Zl = null != t ? di._u(t) : new di();
}
return this.Zl;
}
Qt() {
return this.ed().nd;
}
ld(t) {
var i, e, n, l, r, o;
if (null != t && null != t.config) {
const u = t.config;
if (u.time > this.ed().nd) {
const t = (t) => (null == t ? this.ed().ud : t),
a = new di(
u.time,
u.events_blacklist,
u.attributes_blacklist,
u.purchases_blacklist,
u.messaging_session_timeout,
u.vapid_public_key,
u.content_cards,
u.feature_flags,
t(u.global_request_rate_limit),
u.banners,
u.dust,
u.request_backoff,
u.minimum_session_timeout,
u.conversational_chat,
);
let h = !1;
null != a.ad && this.ju() !== a.ad && (h = !0);
let d = !1;
null != a.hd.enabled && this.Pi() !== a.hd.enabled && (d = !0);
let c = !1;
null != a.Xr.enabled && this.lo() !== a.Xr.enabled && (c = !0);
let v = !1;
null !=
(null === (i = a.banners) || void 0 === i ? void 0 : i.enabled) &&
this.Ot() !==
(null === (e = a.banners) || void 0 === e ? void 0 : e.enabled) &&
(v = !0);
let m = !1;
null != (null === (n = a.dust) || void 0 === n ? void 0 : n.enabled) &&
this.fn() !==
(null === (l = a.dust) || void 0 === l ? void 0 : l.enabled) &&
(m = !0);
let g = !1;
null != (null === (r = a.dd) || void 0 === r ? void 0 : r.enabled) &&
this.vd() !==
(null === (o = a.dd) || void 0 === o ? void 0 : o.enabled) &&
(g = !0),
(this.Zl = a),
this.j.Pt(s.It.sd, a.qt()),
h && this.Gl.A(),
d && this._l.A(),
c && this.Vl.A(),
v && this.Jl.A(),
m && this.Ql.A(),
g && this.Wl.A();
}
}
}
xu(t) {
const i = this.Gl.Ut(t);
return this.Yl && this.Gl.removeSubscription(this.Yl), (this.Yl = i), i;
}
$i(t) {
return this._l.Ut(t);
}
bo(t) {
return this.Vl.Ut(t);
}
V(t) {
return this.Jl.Ut(t);
}
Tr(t) {
return this.Ql.Ut(t);
}
md(t) {
return this.Wl.Ut(t);
}
$e(t) {
return -1 !== this.ed().gd.indexOf(t);
}
qu(t) {
return -1 !== this.ed().bd.indexOf(t);
}
$r(t) {
return -1 !== this.ed().fd.indexOf(t);
}
pd() {
return this.ed().Rd;
}
ju() {
return this.ed().ad;
}
Pi() {
return this.ed().hd.enabled || !1;
}
Cd() {
const t = this.ed().ud;
return !(!t || null == t.enabled) && t.enabled;
}
Ul() {
if (!this.Cd()) return -1;
const t = this.ed().ud;
return null == t.capacity || t.capacity < 10 ? -1 : t.capacity;
}
xl() {
if (!this.Cd()) return -1;
const t = this.ed().ud;
return null == t.refill_rate || t.refill_rate <= 0 ? -1 : t.refill_rate;
}
Ed(t) {
const i = this.ed().ud.endpoint_overrides;
return null == i ? null : i[t];
}
Hl(t) {
const i = this.Ed(t);
return null == i || isNaN(i.capacity) || i.capacity <= 0 ? -1 : i.capacity;
}
Ol(t) {
const i = this.Ed(t);
return null == i || isNaN(i.refill_rate) || i.refill_rate <= 0
? -1
: i.refill_rate;
}
lo() {
return this.ed().Xr.enabled && null == this.Ro()
? (v.Dt(p.Ya, { e: "Missing feature flag refresh_rate_limit." }), !1)
: this.ed().Xr.enabled || !1;
}
Ro() {
return this.ed().Xr.refresh_rate_limit;
}
Ot() {
var t;
return (
(null === (t = this.ed().banners) || void 0 === t ? void 0 : t.enabled) ||
null
);
}
re() {
var t;
return (
(null === (t = this.ed().banners) || void 0 === t
? void 0
: t.max_placements) || 0
);
}
Gt() {
var t;
const i =
null === (t = this.ed().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.ed().dust) || void 0 === t ? void 0 : t.enabled) || !1
);
}
vd() {
var t;
return (
(null === (t = this.ed().dd) || void 0 === t ? void 0 : t.enabled) || !1
);
}
vt() {
var t;
const i =
null === (t = this.ed().wd) || void 0 === t
? void 0
: t.min_sleep_duration_ms;
return null != i ? i : d;
}
gt() {
var t;
const i =
null === (t = this.ed().wd) || void 0 === t ? void 0 : t.scale_factor;
return null != i ? i : m;
}
bt() {
var t;
const i =
null === (t = this.ed().wd) || void 0 === t
? void 0
: t.max_sleep_duration_ms;
return null != i ? i : c;
}
Bd() {
return this.ed().Td;
}
}