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 ti 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 bt { constructor(t, s) { (this.h = t), (this.j = s), (this.h = t), (this.j = s); } getUserId() { const t = this.j.tu(s.iu.su); if (null == t) return null; let i = t.eu, e = er(i); if (e > User.mr) { for (; e > User.mr; ) (i = i.slice(0, i.length - 1)), (e = er(i)); (t.eu = i), this.j.uu(s.iu.su, t); } return i; } ou(t) { const i = null == this.getUserId(); this.j.uu(s.iu.su, new _t(t)), i && this.j.ru(t); } setCustomUserAttribute(t, s) { if (this.h.hu(t)) return ( E.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.j.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 && E.info(`Logged${o} attribute ${r} with value ${h}`), u ); } Pn(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 = et.Us.Rs, h = new et(r, E), n = new ti(t, i, e, u, o); this.j.ft(s.ct.In, n.dt()), h.setItem(r.Fs.cu, r.me, !0); } Sn(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 = et.Us.Rs, i = new et(t, E); this.j.ft(s.ct.In, !1), i.setItem(t.Fs.cu, t.me, !1); } } }