@braze/web-sdk 4.7.0 → 4.7.2

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 (34) hide show
  1. package/index.d.ts +7 -7
  2. package/package.json +1 -1
  3. package/shared-lib/braze-shared-lib.js +1 -1
  4. package/shared-lib/event-types.js +7 -7
  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 +2 -2
  8. package/src/Card/models/card.js +1 -1
  9. package/src/managers/braze-instance.js +21 -19
  10. package/src/managers/device-manager.js +5 -5
  11. package/src/managers/network-manager.js +32 -32
  12. package/src/managers/session-manager.js +1 -1
  13. package/src/managers/storage-manager.js +73 -66
  14. package/src/models/backend-errors.js +5 -5
  15. package/src/models/braze-event.js +1 -1
  16. package/src/models/server-config.js +2 -2
  17. package/src/request-controller.js +70 -70
  18. package/src/triggers/models/custom-event-data.js +1 -1
  19. package/src/triggers/models/custom-event-property-data.js +5 -5
  20. package/src/triggers/models/filter-set.js +2 -2
  21. package/src/triggers/models/filter.js +56 -56
  22. package/src/triggers/models/in-app-message-click-data.js +9 -9
  23. package/src/triggers/models/purchase-data.js +1 -1
  24. package/src/triggers/models/purchase-property-data.js +5 -5
  25. package/src/triggers/models/push-click-data.js +4 -4
  26. package/src/triggers/models/trigger-condition.js +2 -2
  27. package/src/triggers/models/trigger.js +20 -20
  28. package/src/triggers/triggers-provider.js +37 -37
  29. package/src/ui/js/attach-css.js +1 -1
  30. package/src/util/base-device-parser.js +1 -1
  31. package/src/util/browser-detector.js +4 -4
  32. package/src/util/client-hints-parser.js +1 -1
  33. package/src/util/net.js +1 -1
  34. package/src/util/user-agent-parser.js +1 -1
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Type definitions for @braze/web-sdk v4.7.0
2
+ * Type definitions for @braze/web-sdk v4.7.2
3
3
  * Project: https://github.com/braze-inc/braze-web-sdk
4
4
  * (c) Braze, Inc. 2023 - http://braze.com
5
5
  * License available at https://github.com/braze-inc/braze-web-sdk/blob/master/LICENSE
@@ -116,8 +116,8 @@
116
116
  /** When this card expires and should stop being shown to the user. */
117
117
  expiresAt: Date | null;
118
118
 
119
- /** Object of string/string key/value pairs. */
120
- extras?: Record<string, any>;
119
+ /** Object of string/string key/value pairs. Defaults to empty object {}. */
120
+ extras: Record<string, string>;
121
121
 
122
122
  /** Whether to pin this card to the top of the view. */
123
123
  pinned: boolean;
@@ -161,7 +161,7 @@
161
161
  url?: string,
162
162
  linkText?: string,
163
163
  aspectRatio?: number,
164
- extras?: Record<string, any>,
164
+ extras?: Record<string, string>,
165
165
  pinned?: boolean,
166
166
  dismissible?: boolean,
167
167
  clicked?: boolean
@@ -238,7 +238,7 @@
238
238
  url?: string,
239
239
  linkText?: string,
240
240
  aspectRatio?: number,
241
- extras?: Record<string, any>,
241
+ extras?: Record<string, string>,
242
242
  pinned?: boolean,
243
243
  dismissible?: boolean,
244
244
  clicked?: boolean
@@ -322,7 +322,7 @@
322
322
  url?: string,
323
323
  linkText?: string,
324
324
  aspectRatio?: number,
325
- extras?: Record<string, any>,
325
+ extras?: Record<string, string>,
326
326
  pinned?: boolean,
327
327
  dismissible?: boolean,
328
328
  clicked?: boolean
@@ -387,7 +387,7 @@
387
387
  viewed?: boolean,
388
388
  updated?: Date,
389
389
  expiresAt?: Date,
390
- extras?: Record<string, any>,
390
+ extras?: Record<string, string>,
391
391
  pinned?: boolean
392
392
  );
393
393
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@braze/web-sdk",
3
- "version": "4.7.0",
3
+ "version": "4.7.2",
4
4
  "description": "Braze SDK for web sites and other JS platforms.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -4,5 +4,5 @@ import Be from "./guid.js";
4
4
  import Ae from "./indexed-db-adapter.js";
5
5
  import Ge from "./logger.js";
6
6
  import Ue from "./supported-options.js";
7
- const r = { yn: je, A: ve, Ar: De, it: Be, qt: Ae, xt: Ae.ep, D: Ge, Wo: Ue };
7
+ const r = { yn: je, A: ve, Ar: De, it: Be, qt: Ae, xt: Ae.ep, D: Ge, Fo: Ue };
8
8
  export default r;
@@ -1,9 +1,9 @@
1
1
  const ve = {
2
2
  CustomEvent: "ce",
3
3
  Pr: "p",
4
- Nl: "pc",
4
+ Ol: "pc",
5
5
  cc: "ca",
6
- qa: "i",
6
+ Aa: "i",
7
7
  qs: "ie",
8
8
  T: "cci",
9
9
  W: "ccic",
@@ -16,18 +16,18 @@ const ve = {
16
16
  Ai: "sbc",
17
17
  Ze: "sfe",
18
18
  ro: "iec",
19
- Ml: "lr",
20
- Rl: "uae",
19
+ Nl: "lr",
20
+ Ml: "uae",
21
21
  U: "ci",
22
22
  F: "cc",
23
- Ul: "lcaa",
24
- Il: "lcar",
23
+ xl: "lcaa",
24
+ Ul: "lcar",
25
25
  Fn: "inc",
26
26
  Un: "add",
27
27
  En: "rem",
28
28
  Sn: "set",
29
29
  An: "ncam",
30
- xl: "sgu"
30
+ Jl: "sgu"
31
31
  },
32
32
  De = { qr: "feed_displayed", dc: "content_cards_displayed" };
33
33
  export { ve as EventTypes, De as InternalEventTypes };
@@ -301,7 +301,7 @@ Ae.ep = {
301
301
  dd: "AppboyServiceWorkerAsyncStorage",
302
302
  VERSION: 6,
303
303
  $t: {
304
- Ol: "data",
304
+ Il: "data",
305
305
  jr: "pushClicks",
306
306
  cu: "pushSubscribed",
307
307
  ud: "fallbackDevice",
@@ -24,13 +24,13 @@ const Ge = {
24
24
  },
25
25
  warn: function(n) {
26
26
  if (Ge.zg) {
27
- const o = "Braze SDK Warning: " + n + " (v4.7.0)";
27
+ const o = "Braze SDK Warning: " + n + " (v4.7.2)";
28
28
  null != Ge.nd ? Ge.nd(o) : console.warn(o);
29
29
  }
30
30
  },
31
31
  error: function(n) {
32
32
  if (Ge.zg) {
33
- const o = "Braze SDK Error: " + n + " (v4.7.0)";
33
+ const o = "Braze SDK Error: " + n + " (v4.7.2)";
34
34
  null != Ge.nd ? Ge.nd(o) : console.error(o);
35
35
  }
36
36
  }
@@ -3,10 +3,10 @@ export default {
3
3
  Xn: "baseUrl",
4
4
  Zn: "noCookies",
5
5
  ho: "devicePropertyAllowlist",
6
- ta: "disablePushTokenMaintenance",
6
+ ia: "disablePushTokenMaintenance",
7
7
  po: "enableLogging",
8
8
  Eo: "enableSdkAuthentication",
9
- ia: "manageServiceWorkerExternally",
9
+ ta: "manageServiceWorkerExternally",
10
10
  _o: "minimumIntervalBetweenTriggerActionsInSeconds",
11
11
  Io: "sessionTimeoutInSeconds",
12
12
  Ao: "appVersion",
@@ -19,7 +19,7 @@ export default class Card {
19
19
  (this.linkText = T),
20
20
  (o = parseFloat(o)),
21
21
  (this.aspectRatio = isNaN(o) ? null : o),
22
- (this.extras = I),
22
+ (this.extras = I || {}),
23
23
  (this.pinned = a || !1),
24
24
  (this.dismissible = N || !1),
25
25
  (this.dismissed = !1),
@@ -28,10 +28,10 @@ const T = {
28
28
  Xn: "baseUrl",
29
29
  Zn: "noCookies",
30
30
  ho: "devicePropertyAllowlist",
31
- ta: "disablePushTokenMaintenance",
31
+ ia: "disablePushTokenMaintenance",
32
32
  po: "enableLogging",
33
33
  Eo: "enableSdkAuthentication",
34
- ia: "manageServiceWorkerExternally",
34
+ ta: "manageServiceWorkerExternally",
35
35
  _o: "minimumIntervalBetweenTriggerActionsInSeconds",
36
36
  Io: "sessionTimeoutInSeconds",
37
37
  Ao: "appVersion",
@@ -59,7 +59,7 @@ class Bt {
59
59
  (this.Ro = []),
60
60
  (this.Mo = []),
61
61
  (this.Se = []),
62
- (this.jo = "4.7.0");
62
+ (this.jo = "4.7.2");
63
63
  }
64
64
  yo(t) {
65
65
  this.Co.ut(t);
@@ -87,10 +87,10 @@ class Bt {
87
87
  if (null == n || "" === n || "string" != typeof n)
88
88
  return r.D.error("Braze requires a valid baseUrl to be initialized."), !1;
89
89
  !1 === /^https?:/.test(n) && (n = `https://${n}`);
90
- let a = n;
90
+ let h = n;
91
91
  if (
92
92
  ((n = document.createElement("a")),
93
- (n.href = a),
93
+ (n.href = h),
94
94
  "/" === n.pathname && (n = `${n}api/v3`),
95
95
  (this.Uo = n.toString()),
96
96
  ot.zo && !this.nn(T.Yn))
@@ -100,24 +100,26 @@ class Bt {
100
100
  (this.vo = !0),
101
101
  !1
102
102
  );
103
- const h = this.nn(Bt.Zn) || !1;
104
- if (((this.h = Dt.Bo(t, h)), new G.ne(null, !0).lr(o.ae)))
103
+ const a = this.nn(T.Zn) || !1;
104
+ if (
105
+ ((this.h = Dt.Bo(t, a)), a && this.h.Wo(t), new G.ne(null, !0).lr(o.ae))
106
+ )
105
107
  return (
106
108
  r.D.info("Ignoring all activity due to previous opt out"),
107
109
  (this.vo = !0),
108
110
  !1
109
111
  );
110
112
  for (const t of or(this.Po))
111
- -1 === Lt(r.Wo).indexOf(t) &&
113
+ -1 === Lt(r.Fo).indexOf(t) &&
112
114
  r.D.warn(`Ignoring unknown initialization option '${t}'.`);
113
115
  const l = ["mparticle", "wordpress", "tealium"];
114
116
  if (null != this.nn(T.To)) {
115
117
  const t = this.nn(T.To);
116
118
  -1 !== l.indexOf(t)
117
- ? (this.Fo = t)
119
+ ? (this.Vo = t)
118
120
  : r.D.error("Invalid sdk flavor passed: " + t);
119
121
  }
120
- let f = this.nn(r.Wo.ho);
122
+ let f = this.nn(r.Fo.ho);
121
123
  if (null != f)
122
124
  if (p(f)) {
123
125
  const t = [];
@@ -140,19 +142,19 @@ class Bt {
140
142
  (this.j = new jt(this.h, this.v, this.gt, this.nn(T.Io)));
141
143
  const m = new u();
142
144
  return (
143
- (this.Vo = new kt(this.h, this.nn(T.Eo), m)),
145
+ (this.Go = new kt(this.h, this.nn(T.Eo), m)),
144
146
  this.jt(m),
145
147
  (this.vt = new Pt(
146
148
  this.Ur,
147
149
  this.h,
148
- this.Vo,
150
+ this.Go,
149
151
  this.v,
150
152
  this.j,
151
153
  this.gt,
152
154
  this._r,
153
155
  this.Uo,
154
156
  this.jo,
155
- this.Fo,
157
+ this.Vo,
156
158
  this.nn(T.Ao)
157
159
  )),
158
160
  (this.Ci = new Rt(
@@ -166,7 +168,7 @@ class Bt {
166
168
  t => {
167
169
  if (this.Do()) for (const i of this.re()) i.Rs(t);
168
170
  },
169
- this.Vo,
171
+ this.Go,
170
172
  this.vt
171
173
  )),
172
174
  this.Ci.initialize(),
@@ -214,21 +216,21 @@ class Bt {
214
216
  (this.Se = []),
215
217
  this.Ci.destroy(),
216
218
  (this.Ci = null),
217
- (this.Vo = null),
219
+ (this.Go = null),
218
220
  (this.Ur = null),
219
221
  (this.vt = null),
220
222
  (this.gt = null),
221
223
  (this.j = null),
222
224
  (this.v = null),
223
225
  (this.Po = {}),
224
- (this.Fo = void 0),
226
+ (this.Vo = void 0),
225
227
  (this.Oo = !1),
226
228
  (this.vo = !1),
227
229
  t && (this.h = null);
228
230
  }
229
231
  }
230
232
  rr() {
231
- if (this.Go()) return !1;
233
+ if (this.Ko()) return !1;
232
234
  if (!this.Do())
233
235
  throw new Error("Braze must be initialized before calling methods.");
234
236
  return !0;
@@ -237,7 +239,7 @@ class Bt {
237
239
  return this._r;
238
240
  }
239
241
  ii() {
240
- return this.Vo;
242
+ return this.Go;
241
243
  }
242
244
  Ks() {
243
245
  return this.Uo;
@@ -300,7 +302,7 @@ class Bt {
300
302
  Do() {
301
303
  return this.Oo;
302
304
  }
303
- Go() {
305
+ Ko() {
304
306
  return this.vo;
305
307
  }
306
308
  Ds() {
@@ -41,9 +41,9 @@ export default class Ot {
41
41
  return t;
42
42
  }
43
43
  qo() {
44
- if (ot.Ko()) return ot.Ko();
45
- const e = this.h.I(o.q.Qo);
46
- return e && e.os_version ? e.os_version : ot.Xo();
44
+ if (ot.Qo()) return ot.Qo();
45
+ const e = this.h.I(o.q.Xo);
46
+ return e && e.os_version ? e.os_version : ot.Yo();
47
47
  }
48
48
  Ho(e) {
49
49
  if ("undefined" != typeof Intl && "function" == typeof Intl.DateTimeFormat)
@@ -61,9 +61,9 @@ export default class Ot {
61
61
  }
62
62
  if (!e) return e;
63
63
  const t = e.getTimezoneOffset();
64
- return this.Yo(t);
64
+ return this.Zo(t);
65
65
  }
66
- Yo(e) {
66
+ Zo(e) {
67
67
  const t = parseInt(e / 60),
68
68
  r = parseInt(e % 60);
69
69
  let s = "GMT";
@@ -12,32 +12,32 @@ export default class Pt {
12
12
  constructor(t, e, s, i, r, o, n, a, u, h, c) {
13
13
  (this.Ur = t),
14
14
  (this.h = e),
15
- (this.Vo = s),
15
+ (this.Go = s),
16
16
  (this.v = i),
17
17
  (this.j = r),
18
18
  (this.gt = o),
19
19
  (this._r = n),
20
20
  (this.Uo = a),
21
21
  (this.jo = u),
22
- (this.Fo = h),
22
+ (this.Vo = h),
23
23
  (this.$o = c),
24
- (this.Zo = ["npm"]);
24
+ (this.sa = ["npm"]);
25
25
  }
26
26
  Ps(t, e) {
27
27
  const s = this.Ur.te(),
28
28
  i = s.Pi(),
29
- r = this.h.I(o.q.Qo);
29
+ r = this.h.I(o.q.Xo);
30
30
  ii(r, i) || (t.device = i),
31
31
  (t.api_key = this._r),
32
32
  (t.time = l(new Date().valueOf(), !0));
33
- const n = this.h.I(o.q.sa) || [],
34
- a = this.h.I(o.q.oa) || "";
33
+ const n = this.h.I(o.q.oa) || [],
34
+ a = this.h.I(o.q.ua) || "";
35
35
  if (
36
- (this.Zo.length > 0 &&
37
- (!ii(n, this.Zo) || a !== this.j.ua()) &&
38
- (t.sdk_metadata = this.Zo),
36
+ (this.sa.length > 0 &&
37
+ (!ii(n, this.sa) || a !== this.j.ha()) &&
38
+ (t.sdk_metadata = this.sa),
39
39
  (t.sdk_version = this.jo),
40
- this.Fo && (t.sdk_flavor = this.Fo),
40
+ this.Vo && (t.sdk_flavor = this.Vo),
41
41
  (t.app_version = this.$o),
42
42
  (t.device_id = s.id),
43
43
  e)
@@ -53,7 +53,7 @@ export default class Pt {
53
53
  if (!o && !n) return !0;
54
54
  if (o) {
55
55
  let e;
56
- this.Vo.Vn();
56
+ this.Go.Vn();
57
57
  const s = { errorCode: o.error_code };
58
58
  for (const t of i)
59
59
  p(t) && "X-Braze-Auth-Signature" === t[0] && (s.signature = t[1]);
@@ -65,12 +65,12 @@ export default class Pt {
65
65
  n
66
66
  ? ((s.reason = n), (e = `due to ${n}`))
67
67
  : (e = `with error code ${o.error_code}.`),
68
- this.Vo.Jn() ||
68
+ this.Go.Jn() ||
69
69
  (e +=
70
70
  ' Please use the "enableSdkAuthentication" initialization option to enable authentication.'),
71
71
  r.D.error(`SDK Authentication failed ${e}`),
72
- this.ha(t.events, t.attributes),
73
- this.Vo.Qn(s),
72
+ this.ca(t.events, t.attributes),
73
+ this.Go.Qn(s),
74
74
  !1
75
75
  );
76
76
  }
@@ -78,38 +78,38 @@ export default class Pt {
78
78
  let i,
79
79
  o = n;
80
80
  switch (o) {
81
- case qt.ca:
81
+ case qt.la:
82
82
  return (
83
83
  (i = "Received successful response with empty body."),
84
84
  s.G(r.A.qs, { e: i }),
85
85
  r.D.info(i),
86
86
  !1
87
87
  );
88
- case qt.la:
88
+ case qt.fa:
89
89
  return (
90
90
  (i = "Received successful response with invalid JSON"),
91
91
  s.G(r.A.qs, { e: i + ": " + e.response }),
92
92
  r.D.info(i),
93
93
  !1
94
94
  );
95
- case qt.fa:
95
+ case qt.ma:
96
96
  o = `The API key "${t.api_key}" is invalid for the baseUrl ${this.Uo}`;
97
97
  break;
98
- case qt.ma:
98
+ case qt.pa:
99
99
  o =
100
100
  "Sorry, we are not currently accepting your requests. If you think this is in error, please contact us.";
101
101
  break;
102
- case qt.pa:
102
+ case qt.Ra:
103
103
  o = "No device identifier. Please contact support@braze.com";
104
104
  }
105
105
  r.D.error("Backend error: " + o);
106
106
  }
107
107
  return !1;
108
108
  }
109
- Ra(t, e, s, i) {
109
+ ba(t, e, s, i) {
110
110
  return !!((t && 0 !== t.length) || (e && 0 !== e.length) || s || i);
111
111
  }
112
- ba(t, e, s, i) {
112
+ ga(t, e, s, i) {
113
113
  const r = [],
114
114
  o = t => t || "",
115
115
  n = o(this.v.getUserId());
@@ -121,7 +121,7 @@ export default class Pt {
121
121
  if (s.length > 0) {
122
122
  const t = [];
123
123
  for (const e of s) {
124
- if (((a = e.Pi()), this.Vo.Jn())) {
124
+ if (((a = e.Pi()), this.Go.Jn())) {
125
125
  if (n && !a.user_id) {
126
126
  c || ((c = {}), (c.events = [])), c.events.push(a);
127
127
  continue;
@@ -138,21 +138,21 @@ export default class Pt {
138
138
  if (i.length > 0) {
139
139
  const t = [];
140
140
  for (const e of i)
141
- this.Vo.Jn() && o(e.user_id) !== n
141
+ this.Go.Jn() && o(e.user_id) !== n
142
142
  ? (h || (h = []), h.push(e))
143
143
  : t.push(e);
144
144
  t.length > 0 && (l.attributes = t);
145
145
  }
146
- if ((this.ha(u, h), (l = this.Ps(l, !0)), c)) {
146
+ if ((this.ca(u, h), (l = this.Ps(l, !0)), c)) {
147
147
  c = this.Ps(c, !1);
148
148
  const t = { requestData: c, headers: this.Bs(c) };
149
149
  r.push(t);
150
150
  }
151
- if (l && !this.Ra(l.events, l.attributes, t, e)) return c ? r : null;
151
+ if (l && !this.ba(l.events, l.attributes, t, e)) return c ? r : null;
152
152
  const f = { requestData: l, headers: this.Bs(l) };
153
153
  return r.push(f), r;
154
154
  }
155
- ha(t, e) {
155
+ ca(t, e) {
156
156
  if (t) {
157
157
  const e = [];
158
158
  for (const s of t) {
@@ -161,14 +161,14 @@ export default class Pt {
161
161
  }
162
162
  this.h.bo(e);
163
163
  }
164
- if (e) for (const t of e) this.h.ga(t);
164
+ if (e) for (const t of e) this.h.qa(t);
165
165
  }
166
166
  Vs(t, e) {
167
167
  let s = "HTTP error ";
168
168
  null != t && (s += t + " "), (s += e), r.D.error(s);
169
169
  }
170
170
  Fr(t) {
171
- return s.G(r.A.qa, { n: t });
171
+ return s.G(r.A.Aa, { n: t });
172
172
  }
173
173
  Oi(t, e, s) {
174
174
  const i = {};
@@ -201,9 +201,9 @@ export default class Pt {
201
201
  if (
202
202
  (s && (r.push(["X-Braze-FeatureFlagsRequest", "true"]), (n = !0)),
203
203
  n && r.push(["X-Braze-DataRequest", "true"]),
204
- this.Vo.Jn())
204
+ this.Go.Jn())
205
205
  ) {
206
- const t = this.Vo.Kn();
206
+ const t = this.Go.Kn();
207
207
  null != t && r.push(["X-Braze-Auth-Signature", t]);
208
208
  }
209
209
  return r;
@@ -217,12 +217,12 @@ export default class Pt {
217
217
  : e();
218
218
  }
219
219
  Qs() {
220
- this.Vo.Qs();
220
+ this.Go.Qs();
221
221
  }
222
222
  Ks() {
223
223
  return this.Uo;
224
224
  }
225
225
  addSdkMetadata(t) {
226
- for (const e of t) -1 === this.Zo.indexOf(e) && this.Zo.push(e);
226
+ for (const e of t) -1 === this.sa.indexOf(e) && this.sa.push(e);
227
227
  }
228
228
  }
@@ -25,7 +25,7 @@ export default class jt {
25
25
  gh(s, t) {
26
26
  return new ue(this.v.getUserId(), r.A.wh, s, t.iu, { d: l(s - t.jh) });
27
27
  }
28
- ua() {
28
+ ha() {
29
29
  const s = this.h.tu(o.eu.xh);
30
30
  return null == s ? null : s.iu;
31
31
  }