@braze/web-sdk
Version:
Braze SDK for web sites and other JS platforms.
74 lines (73 loc) • 2.22 kB
JavaScript
import _t from "../models/identifier.js";
import { getByteLength as er } from "../util/string-utils.js";
import ti from "../models/push-token.js";
import { logger as N, IndexedDBAdapter as tt } from "../../shared-lib/index.js";
import { STORAGE_KEYS as s } from "../managers/storage-manager.js";
import { User } from "../User/index.js";
export default class bt {
constructor(t, s) {
(this.B = t), (this.C = s), (this.B = t), (this.C = s);
}
getUserId() {
const t = this.C.tu(s.iu.su);
if (null == t) return null;
let i = t.eu,
e = er(i);
if (e > User.ur) {
for (; e > User.ur; ) (i = i.slice(0, i.length - 1)), (e = er(i));
(t.eu = i), this.C.uu(s.iu.su, t);
}
return i;
}
ou(t) {
const i = null == this.getUserId();
this.C.uu(s.iu.su, new _t(t)), i && this.C.ru(t);
}
setCustomUserAttribute(t, s) {
if (this.B.hu(t))
return (
N.info('Custom Attribute "' + t + '" is blocklisted, ignoring.'), !1
);
const i = {};
return (i[t] = s), this.nu(User.lu, i, !0);
}
nu(t, s, i = !1, e = !1) {
const u = this.C.mu(this.getUserId(), t, s);
let o = "",
r = t,
h = s;
return (
i &&
((o = " custom"),
"object" == typeof s &&
((r = Object.keys(s)[0]),
(h = s[r]),
"object" == typeof h && (h = JSON.stringify(h, null, 2)))),
!e && u && N.info(`Logged${o} attribute ${r} with value ${h}`),
u
);
}
Sn(t, i, e, u, o) {
this.nu("push_token", t, !1, !0),
this.nu("custom_push_public_key", e, !1, !0),
this.nu("custom_push_user_auth", u, !1, !0),
this.nu("custom_push_vapid_public_key", o, !1, !0);
const r = tt.Ls.Fs,
h = new tt(r, N),
n = new ti(t, i, e, u, o);
this.C.Bt(s.gt.qn, n.bt()), h.setItem(r.Ms.cu, r.be, !0);
}
jn(t) {
if (
(this.nu("push_token", null, !1, !0),
this.nu("custom_push_public_key", null, !1, !0),
this.nu("custom_push_user_auth", null, !1, !0),
this.nu("custom_push_vapid_public_key", null, !1, !0),
t)
) {
const t = tt.Ls.Fs,
i = new tt(t, N);
this.C.Bt(s.gt.qn, !1), i.setItem(t.Ms.cu, t.be, !1);
}
}
}