UNPKG

@braze/web-sdk

Version:

Braze SDK for web sites and other JS platforms.

74 lines (73 loc) 2.22 kB
import _t from "../models/identifier.js"; import { getByteLength as er } from "../util/string-utils.js"; import ui from "../models/push-token.js"; import { logger as b, 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.j = s), (this.h = t), (this.j = s); } getUserId() { const t = this.j.$u(s.Ou.Cu); if (null == t) return null; let i = t.Tu, e = er(i); if (e > User.br) { for (; e > User.br; ) (i = i.slice(0, i.length - 1)), (e = er(i)); (t.Tu = i), this.j.Iu(s.Ou.Cu, t); } return i; } Ju(t) { const i = null == this.getUserId(); this.j.Iu(s.Ou.Cu, new _t(t)), i && this.j.Lu(t); } setCustomUserAttribute(t, s) { if (this.h.qu(t)) return ( b.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.j.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 && b.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._s.Xs, h = new et(r, b), n = new ui(t, i, e, u, o); this.j.Pt(s.It.Uu, n.qt()), h.setItem(r.Ws.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._s.Xs, i = new et(t, b); this.j.Pt(s.It.Uu, !1), i.setItem(t.Ws.Fu, t.be, !1); } } }