@braze/web-sdk 4.9.0 → 4.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/index.d.ts +2289 -2228
  2. package/package.json +1 -1
  3. package/shared-lib/braze-shared-lib.js +1 -1
  4. package/shared-lib/event-types.js +9 -9
  5. package/shared-lib/indexed-db-adapter.js +1 -1
  6. package/shared-lib/logger.js +2 -2
  7. package/shared-lib/supported-options.js +5 -4
  8. package/src/Core/get-device-id.js +9 -7
  9. package/src/User/user.js +10 -9
  10. package/src/managers/braze-instance.js +68 -66
  11. package/src/managers/device-manager.js +15 -15
  12. package/src/managers/network-manager.js +64 -61
  13. package/src/managers/session-manager.js +1 -1
  14. package/src/managers/storage-manager-factory.js +8 -8
  15. package/src/managers/storage-manager.js +15 -15
  16. package/src/managers/subscription-manager.js +1 -1
  17. package/src/models/backend-errors.js +5 -5
  18. package/src/models/braze-event.js +2 -2
  19. package/src/models/device.js +1 -1
  20. package/src/models/server-config.js +2 -2
  21. package/src/request-controller.js +112 -108
  22. package/src/triggers/models/filter.js +7 -7
  23. package/src/triggers/models/trigger-condition.js +17 -17
  24. package/src/triggers/models/trigger.js +25 -25
  25. package/src/triggers/triggers-provider.js +21 -21
  26. package/src/ui/js/attach-css.js +1 -1
  27. package/src/ui/js/load-font-awesome.js +1 -1
  28. package/src/util/base-device-parser.js +1 -1
  29. package/src/util/browser-detector.js +5 -5
  30. package/src/util/client-hints-parser.js +6 -6
  31. package/src/util/date-utils.js +2 -2
  32. package/src/util/device-constants.js +1 -1
  33. package/src/util/dom-utils.js +5 -5
  34. package/src/util/net.js +1 -1
  35. package/src/util/request-header-utils.js +14 -14
  36. package/src/util/user-agent-parser.js +5 -5
  37. package/src/util/validation-utils.js +9 -9
@@ -10,48 +10,51 @@ import r from "../../shared-lib/braze-shared-lib.js";
10
10
  import { STORAGE_KEYS as i } from "./storage-manager.js";
11
11
  import T from "../util/request-header-utils.js";
12
12
  import { LAST_REQUEST_TO_ENDPOINT_MS_AGO_DEFAULT as Ht } from "../common/constants.js";
13
- export default class Pt {
14
- constructor(t, e, s, i, r, o, n, a, h, u, c) {
13
+ export default class Rt {
14
+ constructor(t, e, s, i, r, o, n, h, a, u, c, l) {
15
15
  (this.fn = t),
16
16
  (this.u = e),
17
- (this.Do = s),
17
+ (this.Uo = s),
18
18
  (this.ft = i),
19
19
  (this._e = r),
20
20
  (this.wt = o),
21
21
  (this.cn = n),
22
- (this.Uo = a),
23
- (this.Mo = h),
24
- (this.jo = u),
22
+ (this.Bo = h),
23
+ (this.jo = a),
24
+ (this.Do = u),
25
25
  (this.appVersion = c),
26
+ (this.Xh = l),
26
27
  (this.fn = t),
27
28
  (this.u = e),
28
- (this.Do = s),
29
+ (this.Uo = s),
29
30
  (this.ft = i),
30
31
  (this._e = r),
31
32
  (this.wt = o),
32
33
  (this.cn = n),
33
- (this.Uo = a),
34
- (this.Mo = h),
35
- (this.jo = u),
34
+ (this.Bo = h),
35
+ (this.jo = a),
36
+ (this.Do = u),
36
37
  (this.appVersion = c),
37
- (this.Ra = ["npm"]);
38
+ (this.Xh = l),
39
+ (this.$h = ["npm"]);
38
40
  }
39
41
  Bs(t, e = !1, s = !1) {
40
42
  const r = this.fn.ce(!s),
41
43
  o = r.Kr(),
42
- n = this.u.v(i.k.Ca);
44
+ n = this.u.v(i.k.Fa);
43
45
  ii(n, o) || (t.device = o),
44
46
  (t.api_key = this.cn),
45
47
  (t.time = h(new Date().valueOf(), !0));
46
- const a = this.u.v(i.k.Xa) || [],
47
- u = this.u.v(i.k.Ea) || "";
48
+ const a = this.u.v(i.k.Kh) || [],
49
+ u = this.u.v(i.k.Wh) || "";
48
50
  if (
49
- (this.Ra.length > 0 &&
50
- (!ii(a, this.Ra) || u !== this._e.Pa()) &&
51
- (t.sdk_metadata = this.Ra),
52
- (t.sdk_version = this.Mo),
53
- this.jo && (t.sdk_flavor = this.jo),
51
+ (this.$h.length > 0 &&
52
+ (!ii(a, this.$h) || u !== this._e.Yh()) &&
53
+ (t.sdk_metadata = this.$h),
54
+ (t.sdk_version = this.jo),
55
+ this.Do && (t.sdk_flavor = this.Do),
54
56
  (t.app_version = this.appVersion),
57
+ (t.app_version_code = this.Xh),
55
58
  (t.device_id = r.id),
56
59
  e)
57
60
  ) {
@@ -66,7 +69,7 @@ export default class Pt {
66
69
  if (!o && !n) return !0;
67
70
  if (o) {
68
71
  let e;
69
- this.Do.Hh();
72
+ this.Uo.Hh();
70
73
  const s = { errorCode: o.error_code };
71
74
  for (const t of i)
72
75
  p(t) && "X-Braze-Auth-Signature" === t[0] && (s.signature = t[1]);
@@ -78,12 +81,12 @@ export default class Pt {
78
81
  n
79
82
  ? ((s.reason = n), (e = `due to ${n}`))
80
83
  : (e = `with error code ${o.error_code}.`),
81
- this.Do.wh() ||
84
+ this.Uo.wh() ||
82
85
  (e +=
83
86
  ' Please use the "enableSdkAuthentication" initialization option to enable authentication.'),
84
87
  r.j.error(`SDK Authentication failed ${e}`),
85
- this.$a(t.events || [], t.attributes || []),
86
- this.Do.Bh(s),
88
+ this.Qh(t.events || [], t.attributes || []),
89
+ this.Uo.Bh(s),
87
90
  !1
88
91
  );
89
92
  }
@@ -91,42 +94,42 @@ export default class Pt {
91
94
  let i,
92
95
  o = n;
93
96
  switch (o) {
94
- case qt.Na:
97
+ case qt.Vh:
95
98
  return (
96
99
  (i = "Received successful response with empty body."),
97
100
  s.N(r.q.qs, { e: i }),
98
101
  r.j.info(i),
99
102
  !1
100
103
  );
101
- case qt.Ha:
104
+ case qt.Zh:
102
105
  return (
103
106
  (i = "Received successful response with invalid JSON"),
104
107
  s.N(r.q.qs, { e: i + ": " + e.response }),
105
108
  r.j.info(i),
106
109
  !1
107
110
  );
108
- case qt.Ka:
109
- o = `The API key "${t.api_key}" is invalid for the baseUrl ${this.Uo}`;
111
+ case qt.Ra:
112
+ o = `The API key "${t.api_key}" is invalid for the baseUrl ${this.Bo}`;
110
113
  break;
111
- case qt.Ua:
114
+ case qt.Xa:
112
115
  o =
113
116
  "Sorry, we are not currently accepting your requests. If you think this is in error, please contact us.";
114
117
  break;
115
- case qt.La:
118
+ case qt.Ea:
116
119
  o = "No device identifier. Please contact support@braze.com";
117
120
  }
118
121
  r.j.error("Backend error: " + o);
119
122
  }
120
123
  return !1;
121
124
  }
122
- Wa(t, e, s, i) {
125
+ Pa(t, e, s, i) {
123
126
  return !!((t && 0 !== t.length) || (e && 0 !== e.length) || s || i);
124
127
  }
125
- Ya(t, e, s, i, r = !1) {
128
+ $a(t, e, s, i, r = !1) {
126
129
  const o = [],
127
130
  n = (t) => t || "",
128
- a = n(this.ft.getUserId());
129
- let h = this.Jr(t, e);
131
+ h = n(this.ft.getUserId());
132
+ let a = this.Jr(t, e);
130
133
  const u = [],
131
134
  c = [];
132
135
  let l,
@@ -134,36 +137,36 @@ export default class Pt {
134
137
  if (s.length > 0) {
135
138
  const t = [];
136
139
  for (const e of s) {
137
- if (((l = e.Kr()), this.Do.wh())) {
138
- if (a && !l.user_id) {
140
+ if (((l = e.Kr()), this.Uo.wh())) {
141
+ if (h && !l.user_id) {
139
142
  f || (f = {}), f.events || (f.events = []), f.events.push(l);
140
143
  continue;
141
144
  }
142
- if (n(l.user_id) !== a) {
145
+ if (n(l.user_id) !== h) {
143
146
  c.push(l);
144
147
  continue;
145
148
  }
146
149
  }
147
150
  t.push(l);
148
151
  }
149
- t.length > 0 && (h.events = t);
152
+ t.length > 0 && (a.events = t);
150
153
  }
151
154
  if (i.length > 0) {
152
155
  const t = [];
153
156
  for (const e of i)
154
- e && (this.Do.wh() && n(e.user_id) !== a ? u.push(e) : t.push(e));
155
- t.length > 0 && (h.attributes = t);
157
+ e && (this.Uo.wh() && n(e.user_id) !== h ? u.push(e) : t.push(e));
158
+ t.length > 0 && (a.attributes = t);
156
159
  }
157
- if ((this.$a(c, u), (h = this.Bs(h, !0, r)), f)) {
160
+ if ((this.Qh(c, u), (a = this.Bs(a, !0, r)), f)) {
158
161
  f = this.Bs(f, !1, r);
159
- const t = { requestData: f, headers: this.Hs(f, T.Os.Ja) };
162
+ const t = { requestData: f, headers: this.Hs(f, T.Os.Na) };
160
163
  o.push(t);
161
164
  }
162
- if (h && !this.Wa(h.events, h.attributes, t, e)) return f ? o : null;
163
- const d = { requestData: h, headers: this.Hs(h, T.Os.Ja) };
165
+ if (a && !this.Pa(a.events, a.attributes, t, e)) return f ? o : null;
166
+ const d = { requestData: a, headers: this.Hs(a, T.Os.Na) };
164
167
  return o.push(d), o;
165
168
  }
166
- $a(t, e) {
169
+ Qh(t, e) {
167
170
  if (t) {
168
171
  const e = [];
169
172
  for (const s of t) {
@@ -172,14 +175,14 @@ export default class Pt {
172
175
  }
173
176
  this.u.bo(e);
174
177
  }
175
- if (e) for (const t of e) this.u.Qa(t);
178
+ if (e) for (const t of e) this.u.Ha(t);
176
179
  }
177
180
  ii(t, e) {
178
181
  let s = "HTTP error ";
179
182
  null != t && (s += t + " "), (s += e), r.j.error(s);
180
183
  }
181
184
  qr(t) {
182
- return s.N(r.q.Va, { n: t });
185
+ return s.N(r.q.Ka, { n: t });
183
186
  }
184
187
  Jr(t, e, s) {
185
188
  const i = {};
@@ -191,10 +194,10 @@ export default class Pt {
191
194
  { respond_with: i }
192
195
  );
193
196
  }
194
- Za(t) {
197
+ Ua(t) {
195
198
  const e = new Date().valueOf();
196
199
  let s = Ht.toString();
197
- const i = T.Ga(this.u, t);
200
+ const i = T.La(this.u, t);
198
201
  if (-1 !== i) {
199
202
  s = (e - i).toString();
200
203
  }
@@ -202,33 +205,33 @@ export default class Pt {
202
205
  }
203
206
  Hs(t, e, s = !1) {
204
207
  const r = [["X-Braze-Api-Key", this.cn]],
205
- o = this.Za(e);
208
+ o = this.Ua(e);
206
209
  r.push(["X-Braze-Last-Req-Ms-Ago", o]);
207
- const n = T.Xh(this.u, e).toString();
210
+ const n = T.Wa(this.u, e).toString();
208
211
  r.push(["X-Braze-Req-Attempt", n]);
209
- let a = !1;
212
+ let h = !1;
210
213
  if (
211
214
  (null != t.respond_with &&
212
215
  t.respond_with.triggers &&
213
- (r.push(["X-Braze-TriggersRequest", "true"]), (a = !0)),
216
+ (r.push(["X-Braze-TriggersRequest", "true"]), (h = !0)),
214
217
  null != t.respond_with &&
215
218
  t.respond_with.feed &&
216
- (r.push(["X-Braze-FeedRequest", "true"]), (a = !0)),
219
+ (r.push(["X-Braze-FeedRequest", "true"]), (h = !0)),
217
220
  e === T.Os.Ks)
218
221
  ) {
219
222
  r.push(["X-Braze-ContentCardsRequest", "true"]);
220
223
  let t = this.u.v(i.k.Ls);
221
224
  (t && s) || ((t = 0), this.u.D(i.k.Ls, t)),
222
225
  r.push(["BRAZE-SYNC-RETRY-COUNT", t.toString()]),
223
- (a = !0);
226
+ (h = !0);
224
227
  }
225
228
  if (
226
229
  (e === T.Os.Si &&
227
- (r.push(["X-Braze-FeatureFlagsRequest", "true"]), (a = !0)),
228
- a && r.push(["X-Braze-DataRequest", "true"]),
229
- this.Do.wh())
230
+ (r.push(["X-Braze-FeatureFlagsRequest", "true"]), (h = !0)),
231
+ h && r.push(["X-Braze-DataRequest", "true"]),
232
+ this.Uo.wh())
230
233
  ) {
231
- const t = this.Do.jh();
234
+ const t = this.Uo.jh();
232
235
  null != t && r.push(["X-Braze-Auth-Signature", t]);
233
236
  }
234
237
  return r;
@@ -242,12 +245,12 @@ export default class Pt {
242
245
  : e();
243
246
  }
244
247
  ti() {
245
- this.Do.ti();
248
+ this.Uo.ti();
246
249
  }
247
250
  Ys() {
248
- return this.Uo;
251
+ return this.Bo;
249
252
  }
250
253
  addSdkMetadata(t) {
251
- for (const e of t) -1 === this.Ra.indexOf(e) && this.Ra.push(e);
254
+ for (const e of t) -1 === this.$h.indexOf(e) && this.$h.push(e);
252
255
  }
253
256
  }
@@ -28,7 +28,7 @@ export default class Dt {
28
28
  jl(s, t) {
29
29
  return new be(this.ft.getUserId(), r.q.xl, s, t.iu, { d: h(s - t.vl) });
30
30
  }
31
- Pa() {
31
+ Yh() {
32
32
  const s = this.u.tu(i.eu.Dl);
33
33
  return null == s ? null : s.iu;
34
34
  }
@@ -1,14 +1,14 @@
1
1
  import O, { STORAGE_KEYS as i } from "./storage-manager.js";
2
2
  import r from "../../shared-lib/braze-shared-lib.js";
3
3
  const Bt = {
4
- qo: function (e, o = !1) {
4
+ xo: function (e, o = !1) {
5
5
  let t = !1;
6
6
  try {
7
7
  if (localStorage && localStorage.getItem)
8
8
  try {
9
- localStorage.setItem(i.k.ec, "true"),
10
- localStorage.getItem(i.k.ec) &&
11
- (localStorage.removeItem(i.k.ec), (t = !0));
9
+ localStorage.setItem(i.k.Qa, "true"),
10
+ localStorage.getItem(i.k.Qa) &&
11
+ (localStorage.removeItem(i.k.Qa), (t = !0));
12
12
  } catch (e) {
13
13
  if (
14
14
  !(
@@ -24,12 +24,12 @@ const Bt = {
24
24
  } catch (e) {
25
25
  r.j.info("Local Storage not supported!");
26
26
  }
27
- const a = Bt.oc(),
28
- n = new O.tc(e, a && !o, t);
27
+ const a = Bt.Ja(),
28
+ n = new O.Va(e, a && !o, t);
29
29
  let c;
30
- return (c = t ? new O.rc(e) : new O.ac()), new O(n, c);
30
+ return (c = t ? new O.Ya(e) : new O.Za()), new O(n, c);
31
31
  },
32
- oc: function () {
32
+ Ja: function () {
33
33
  return (
34
34
  navigator.cookieEnabled ||
35
35
  ("cookie" in document &&
@@ -4,7 +4,7 @@ import {
4
4
  isArray as p,
5
5
  keys as oo,
6
6
  validateValueIsFromEnum as H,
7
- values as Lt,
7
+ values as Pt,
8
8
  } from "../util/code-utils.js";
9
9
  import r from "../../shared-lib/braze-shared-lib.js";
10
10
  import { User } from "../User/index.js";
@@ -13,17 +13,17 @@ import { getErrorMessage as ei } from "../util/error-utils.js";
13
13
  export const STORAGE_KEYS = {
14
14
  eu: {
15
15
  su: "ab.storage.userId",
16
- Xo: "ab.storage.deviceId",
16
+ Zo: "ab.storage.deviceId",
17
17
  Dl: "ab.storage.sessionId",
18
18
  },
19
19
  k: {
20
- ec: "ab.test",
20
+ Qa: "ab.test",
21
21
  tE: "ab.storage.events",
22
22
  eE: "ab.storage.attributes",
23
23
  sE: "ab.storage.attributes.anonymous_user",
24
- Ca: "ab.storage.device",
25
- Xa: "ab.storage.sdk_metadata",
26
- Ea: "ab.storage.session_id_for_cached_metadata",
24
+ Fa: "ab.storage.device",
25
+ Kh: "ab.storage.sdk_metadata",
26
+ Wh: "ab.storage.session_id_for_cached_metadata",
27
27
  Bn: "ab.storage.pushToken",
28
28
  Bi: "ab.storage.newsFeed",
29
29
  Ei: "ab.storage.lastNewsFeedRefresh",
@@ -59,7 +59,7 @@ export default class O {
59
59
  constructor(t, e) {
60
60
  (this.SE = t), (this._E = e), (this.SE = t), (this._E = e);
61
61
  }
62
- xo(t) {
62
+ Jo(t) {
63
63
  const e = oo(STORAGE_KEYS.eu),
64
64
  s = new O.ee(t);
65
65
  for (const t of e) s.remove(STORAGE_KEYS.eu[t]);
@@ -160,7 +160,7 @@ export default class O {
160
160
  hE(t) {
161
161
  return t || STORAGE_KEYS.k.sE;
162
162
  }
163
- Qa(t) {
163
+ Ha(t) {
164
164
  let e = this._E.jr(STORAGE_KEYS.k.eE);
165
165
  null == e && (e = {});
166
166
  const s = this.hE(t[User.bu]),
@@ -199,7 +199,7 @@ export default class O {
199
199
  ((e[s] = void 0),
200
200
  this._E.store(STORAGE_KEYS.k.eE, e),
201
201
  (r[User.bu] = t),
202
- this.Qa(r));
202
+ this.Ha(r));
203
203
  }
204
204
  const s = this.tu(STORAGE_KEYS.eu.Dl);
205
205
  let r = null;
@@ -215,7 +215,7 @@ export default class O {
215
215
  return this._E.gE;
216
216
  }
217
217
  }
218
- (O.rc = class {
218
+ (O.Ya = class {
219
219
  constructor(t) {
220
220
  (this.cn = t), (this.cn = t), (this.gE = V.OE() ? 3 : 10);
221
221
  }
@@ -247,7 +247,7 @@ export default class O {
247
247
  }
248
248
  }
249
249
  }),
250
- (O.ac = class {
250
+ (O.Za = class {
251
251
  constructor() {
252
252
  (this.fE = {}), (this.bE = 5242880), (this.gE = 3);
253
253
  }
@@ -321,7 +321,7 @@ export default class O {
321
321
  return t.setTime(t.getTime() + 60 * this.NE * 1e3), t.getFullYear();
322
322
  }
323
323
  DE() {
324
- const t = Lt(STORAGE_KEYS.eu),
324
+ const t = Pt(STORAGE_KEYS.eu),
325
325
  e = document.cookie.split(";");
326
326
  for (let s = 0; s < e.length; s++) {
327
327
  let r = e[s];
@@ -392,13 +392,13 @@ export default class O {
392
392
  (document.cookie = s), (document.cookie = s + ";path=/");
393
393
  }
394
394
  }),
395
- (O.tc = class {
395
+ (O.Va = class {
396
396
  constructor(t, e, s) {
397
397
  (this.cn = t),
398
398
  (this.GE = []),
399
399
  e && this.GE.push(new O.ee(t)),
400
- s && this.GE.push(new O.rc(t)),
401
- this.GE.push(new O.ac());
400
+ s && this.GE.push(new O.Ya(t)),
401
+ this.GE.push(new O.Za());
402
402
  }
403
403
  store(t, e) {
404
404
  let s = !0;
@@ -14,7 +14,7 @@ export default class E {
14
14
  removeAllSubscriptions() {
15
15
  this.Ve = {};
16
16
  }
17
- ic() {
17
+ tc() {
18
18
  return Object.keys(this.Ve).length;
19
19
  }
20
20
  Et(t) {
@@ -1,8 +1,8 @@
1
1
  export default {
2
- Ka: "invalid_api_key",
3
- Ua: "blacklisted",
4
- La: "no_device_identifier",
5
- Ha: "invalid_json_response",
6
- Na: "empty_response",
2
+ Ra: "invalid_api_key",
3
+ Xa: "blacklisted",
4
+ Ea: "no_device_identifier",
5
+ Zh: "invalid_json_response",
6
+ Vh: "empty_response",
7
7
  __: "sdk_auth_error",
8
8
  };
@@ -1,4 +1,4 @@
1
- import { isObject as yt } from "../util/code-utils.js";
1
+ import { isObject as Nt } from "../util/code-utils.js";
2
2
  import {
3
3
  convertMsToSeconds as h,
4
4
  timestampOrNow as Jt,
@@ -39,7 +39,7 @@ export default class be {
39
39
  return new be(t.user_id, t.name, t.time, t.session_id, t.data);
40
40
  }
41
41
  static TE(t) {
42
- return null != t && yt(t) && null != t.t && "" !== t.t;
42
+ return null != t && Nt(t) && null != t.t && "" !== t.t;
43
43
  }
44
44
  static Yn(t) {
45
45
  return new be(t.u, t.t, t.ts, t.s, t.d);
@@ -6,7 +6,7 @@ export default class xt {
6
6
  const s = {};
7
7
  return (
8
8
  null != this.browser && (s.browser = this.browser),
9
- null != this.Zo && (s.browser_version = this.Zo),
9
+ null != this.Ia && (s.browser_version = this.Ia),
10
10
  null != this.os && (s.os_version = this.os),
11
11
  null != this.resolution && (s.resolution = this.resolution),
12
12
  null != this.language && (s.locale = this.language),
@@ -28,7 +28,7 @@ export default class Kt {
28
28
  }
29
29
  ss() {
30
30
  return {
31
- s: "4.9.0",
31
+ s: "4.10.0",
32
32
  l: this.ol,
33
33
  e: this.cl,
34
34
  a: this.gl,
@@ -42,7 +42,7 @@ export default class Kt {
42
42
  static Yn(t) {
43
43
  let i = t.l;
44
44
  return (
45
- "4.9.0" !== t.s && (i = 0), new Kt(i, t.e, t.a, t.p, t.m, t.v, t.c, t.f)
45
+ "4.10.0" !== t.s && (i = 0), new Kt(i, t.e, t.a, t.p, t.m, t.v, t.c, t.f)
46
46
  );
47
47
  }
48
48
  }