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 rr } from "../util/string-utils.js"; import ti from "../models/push-token.js"; import { logger as N, 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.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 = rr(i); if (e > User.mr) { for (; e > User.mr; ) (i = i.slice(0, i.length - 1)), (e = rr(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 ); } Dn(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.Ds.Us, h = new et(r, N), n = new ti(t, i, e, u, o); this.C.Bt(s.gt.Vn, n.bt()), h.setItem(r.Ls.cu, r.be, !0); } An(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.Ds.Us, i = new et(t, N); this.C.Bt(s.gt.Vn, !1), i.setItem(t.Ls.cu, t.be, !1); } } }