@braze/web-sdk
Version:
Braze SDK for web sites and other JS platforms.
123 lines (122 loc) • 2.93 kB
JavaScript
import {
dateFromUnixTimestamp as Y,
rehydrateDateAfterJsonization as ee,
} from "../../util/date-utils.js";
import { logger as b } from "../../../shared-lib/index.js";
import pi from "./trigger-condition.js";
import { validateValueIsFromEnum as ta } from "../../util/code-utils.js";
export default class gt {
constructor(t, i = [], s, e, r = 0, h, l, o = 0, n = gt.Dd, a, u, d) {
(this.id = t),
(this.Pd = i),
(this.startTime = s),
(this.endTime = e),
(this.priority = r),
(this.type = h),
(this.data = l),
(this.yd = o),
(this.jd = n),
(this.ca = a),
(this.Nd = u),
(this._d = d),
(this.id = t),
(this.Pd = i || []),
void 0 === s && (s = null),
(this.startTime = s),
void 0 === e && (e = null),
(this.endTime = e),
(this.priority = r || 0),
(this.type = h),
(this.yd = o || 0),
null == a && (a = 1e3 * (this.yd + 30)),
(this.ca = a),
(this.data = l),
null != n && (this.jd = n),
(this.Nd = u),
(this._d = d || null);
}
Ad(t) {
return (
null == this._d || (this.jd !== gt.Dd && t - this._d >= 1e3 * this.jd)
);
}
Id(t) {
this._d = t;
}
$d(t) {
const i = t + 1e3 * this.yd;
return Math.max(i - new Date().valueOf(), 0);
}
xd(t) {
const i = new Date().valueOf() - t,
s = null == t || isNaN(i) || null == this.ca || i < this.ca;
return (
s ||
b.info(
`Trigger action ${this.type} is no longer eligible for display - fired ${i}ms ago and has a timeout of ${this.ca}ms.`,
),
!s
);
}
static fromJson(t) {
const i = t.id,
s = [];
for (let i = 0; i < t.trigger_condition.length; i++)
s.push(pi.fromJson(t.trigger_condition[i]));
const e = Y(t.start_time),
r = Y(t.end_time),
h = t.priority,
l = t.type,
o = t.delay,
n = t.re_eligibility,
a = t.timeout,
u = t.data,
d = t.min_seconds_since_last_trigger;
return ta(
gt.la,
l,
"Could not construct Trigger from server data",
"Trigger.Types",
)
? new gt(i, s, e, r, h, l, u, o, n, a, d)
: null;
}
qt() {
const t = [];
for (let i = 0; i < this.Pd.length; i++) t.push(this.Pd[i].qt());
return {
i: this.id,
c: t,
s: this.startTime,
e: this.endTime,
p: this.priority,
t: this.type,
da: this.data,
d: this.yd,
r: this.jd,
tm: this.ca,
ss: this.Nd,
ld: this._d,
};
}
static _u(t) {
const i = [],
s = t.c || [];
for (let t = 0; t < s.length; t++) i.push(pi._u(s[t]));
return new gt(
t.i,
i,
ee(t.s),
ee(t.e),
t.p,
t.t,
t.da,
t.d,
t.r,
t.tm,
t.ss,
t.ld,
);
}
}
(gt.la = { oa: "inapp", zd: "templated_iam" }), (gt.Dd = -1);