@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 ir } from "../util/string-utils.js";
import oi from "../models/push-token.js";
import { logger as E, IndexedDBAdapter as et } from "../../shared-lib/index.js";
import { STORAGE_KEYS as s } from "../managers/storage-manager.js";
import { User } from "../User/index.js";
export default class Ut {
constructor(t, s) {
(this.h = t), (this.C = s), (this.h = t), (this.C = s);
}
getUserId() {
const t = this.C.$u(s.Ou.Cu);
if (null == t) return null;
let i = t.Tu,
e = ir(i);
if (e > User.br) {
for (; e > User.br; ) (i = i.slice(0, i.length - 1)), (e = ir(i));
(t.Tu = i), this.C.Iu(s.Ou.Cu, t);
}
return i;
}
Ju(t) {
const i = null == this.getUserId();
this.C.Iu(s.Ou.Cu, new _t(t)), i && this.C.Lu(t);
}
setCustomUserAttribute(t, s) {
if (this.h.qu(t))
return (
E.info('Custom Attribute "' + t + '" is blocklisted, ignoring.'), !1
);
const i = {};
return (i[t] = s), this.zu(User.Bu, i, !0);
}
zu(t, s, i = !1, e = !1) {
const u = this.C.Eu(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 && E.info(`Logged${o} attribute ${r} with value ${h}`),
u
);
}
gu(t, i, e, u, o) {
this.zu("push_token", t, !1, !0),
this.zu("custom_push_public_key", e, !1, !0),
this.zu("custom_push_user_auth", u, !1, !0),
this.zu("custom_push_vapid_public_key", o, !1, !0);
const r = et.Ps.$s,
h = new et(r, E),
n = new oi(t, i, e, u, o);
this.C.It(s.Tt.Uu, n.qt()), h.setItem(r.Os.Fu, r.be, !0);
}
wu(t) {
if (
(this.zu("push_token", null, !1, !0),
this.zu("custom_push_public_key", null, !1, !0),
this.zu("custom_push_user_auth", null, !1, !0),
this.zu("custom_push_vapid_public_key", null, !1, !0),
t)
) {
const t = et.Ps.$s,
i = new et(t, E);
this.C.It(s.Tt.Uu, !1), i.setItem(t.Os.Fu, t.be, !1);
}
}
}