@braze/web-sdk 4.6.3 → 4.7.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 (97) hide show
  1. package/index.d.ts +13 -8
  2. package/package.json +1 -1
  3. package/shared-lib/braze-shared-lib.js +2 -2
  4. package/shared-lib/encoding-utils.js +1 -1
  5. package/shared-lib/event-types.js +18 -17
  6. package/shared-lib/indexed-db-adapter.js +2 -2
  7. package/shared-lib/logger.js +2 -2
  8. package/shared-lib/supported-options.js +15 -15
  9. package/src/Core/handle-braze-action.js +40 -34
  10. package/src/Core/log-custom-event.js +2 -7
  11. package/src/Core/log-purchase.js +3 -3
  12. package/src/Core/wipe-data.js +2 -2
  13. package/src/FeatureFlags/feature-flag.js +33 -16
  14. package/src/FeatureFlags/feature-flags-provider.js +86 -75
  15. package/src/FeatureFlags/get-all-feature-flags.js +5 -5
  16. package/src/FeatureFlags/get-feature-flag.js +6 -6
  17. package/src/FeatureFlags/refresh-feature-flags.js +1 -1
  18. package/src/FeatureFlags/types.js +1 -0
  19. package/src/Feed/feed-provider.js +17 -17
  20. package/src/Feed/get-cached-feed.js +1 -1
  21. package/src/Feed/ui/show-feed.js +1 -1
  22. package/src/InAppMessage/display/html-message-to-html.js +135 -120
  23. package/src/InAppMessage/display/in-app-message-to-html.js +21 -21
  24. package/src/InAppMessage/display/modal-utils.js +6 -6
  25. package/src/InAppMessage/in-app-message-factory.js +3 -3
  26. package/src/InAppMessage/in-app-message-manager-factory.js +3 -3
  27. package/src/InAppMessage/in-app-message-manager.js +65 -65
  28. package/src/InAppMessage/log-in-app-message-button-click.js +4 -4
  29. package/src/InAppMessage/log-in-app-message-click.js +4 -4
  30. package/src/InAppMessage/log-in-app-message-html-click.js +3 -3
  31. package/src/InAppMessage/log-in-app-message-impression.js +3 -3
  32. package/src/InAppMessage/models/full-screen-message.js +1 -1
  33. package/src/InAppMessage/models/html-message.js +1 -1
  34. package/src/InAppMessage/models/in-app-message-button.js +4 -4
  35. package/src/InAppMessage/models/in-app-message.js +80 -80
  36. package/src/InAppMessage/models/modal-message.js +2 -2
  37. package/src/InAppMessage/models/slide-up-message.js +8 -8
  38. package/src/InAppMessage/models/templated-in-app-message.js +4 -4
  39. package/src/InAppMessage/subscribe-to-in-app-message.js +1 -1
  40. package/src/InAppMessage/ui/automatically-show-in-app-messages.js +3 -3
  41. package/src/InAppMessage/ui/show-in-app-message.js +20 -20
  42. package/src/Push/push-manager.js +216 -209
  43. package/src/Push/utils/push-utils.js +4 -4
  44. package/src/User/user-manager.js +11 -8
  45. package/src/User/user.js +52 -41
  46. package/src/common/base-feed.js +1 -1
  47. package/src/common/base-provider.js +1 -1
  48. package/src/common/constants.js +2 -0
  49. package/src/common/feed-display.js +6 -6
  50. package/src/l10n/l10n-manager-factory.js +1 -1
  51. package/src/managers/auth-manager.js +24 -24
  52. package/src/managers/braze-instance.js +120 -120
  53. package/src/managers/device-manager.js +11 -11
  54. package/src/managers/network-manager.js +63 -54
  55. package/src/managers/server-config-manager.js +20 -20
  56. package/src/managers/session-manager.js +29 -29
  57. package/src/managers/storage-manager-factory.js +4 -4
  58. package/src/managers/storage-manager.js +104 -104
  59. package/src/managers/subscription-manager.js +6 -6
  60. package/src/models/backend-errors.js +5 -5
  61. package/src/models/braze-event.js +7 -7
  62. package/src/models/device.js +1 -1
  63. package/src/models/identifier.js +6 -6
  64. package/src/models/push-token.js +3 -3
  65. package/src/models/server-config.js +15 -15
  66. package/src/request-controller.js +92 -88
  67. package/src/triggers/models/custom-event-data.js +4 -4
  68. package/src/triggers/models/custom-event-property-data.js +9 -9
  69. package/src/triggers/models/filter-set.js +9 -9
  70. package/src/triggers/models/filter.js +63 -63
  71. package/src/triggers/models/in-app-message-click-data.js +5 -5
  72. package/src/triggers/models/purchase-data.js +3 -3
  73. package/src/triggers/models/purchase-property-data.js +9 -9
  74. package/src/triggers/models/push-click-data.js +5 -5
  75. package/src/triggers/models/trigger-condition.js +48 -48
  76. package/src/triggers/models/trigger-events.js +1 -1
  77. package/src/triggers/models/trigger.js +29 -29
  78. package/src/triggers/triggers-provider-factory.js +2 -2
  79. package/src/triggers/triggers-provider.js +87 -89
  80. package/src/ui/js/attach-css.js +1 -1
  81. package/src/ui/js/feed-css.js +4 -4
  82. package/src/ui/js/iam-css.js +4 -4
  83. package/src/ui/js/load-font-awesome.js +1 -1
  84. package/src/util/base-device-parser.js +2 -2
  85. package/src/util/braze-actions.js +8 -8
  86. package/src/util/browser-detector.js +8 -8
  87. package/src/util/client-hints-parser.js +3 -3
  88. package/src/util/code-utils.js +10 -3
  89. package/src/util/component-utils.js +1 -1
  90. package/src/util/date-utils.js +2 -2
  91. package/src/util/device-constants.js +1 -1
  92. package/src/util/dom-utils.js +9 -9
  93. package/src/util/key-codes.js +1 -1
  94. package/src/util/net.js +3 -3
  95. package/src/util/user-agent-parser.js +4 -4
  96. package/src/util/validation-utils.js +155 -74
  97. package/src/util/window-utils.js +1 -1
@@ -6,114 +6,125 @@ import u from "../managers/subscription-manager.js";
6
6
  import { randomInclusive as tt } from "../util/math.js";
7
7
  import b from "../util/net.js";
8
8
  import {
9
- newFeatureFlagFromJson as et,
10
- newFeatureFlagFromSerializedValue as st
9
+ newFeatureFlagFromJson as st,
10
+ newFeatureFlagFromSerializedValue as it
11
11
  } from "./feature-flag-factory.js";
12
12
  export default class er extends y {
13
13
  constructor(t, s, i) {
14
14
  super(),
15
- (this.gt = t),
16
- (this.vt = s),
17
- (this.h = i),
18
- (this.he = new u()),
19
- (this.ye = 10),
20
- (this.Te = null),
21
- e.jt(this.he);
15
+ (this.si = t),
16
+ (this.ei = s),
17
+ (this.ri = i),
18
+ (this.hi = []),
19
+ (this.oi = 0),
20
+ (this.si = t),
21
+ (this.ei = s),
22
+ (this.ri = i),
23
+ (this.ni = null),
24
+ (this.ai = new u()),
25
+ (this.fi = 10),
26
+ (this.ui = null),
27
+ (this.li = null),
28
+ e.jt(this.ai);
22
29
  }
23
30
  Rs(t) {
24
- if (this.gt._e() && null != t && t.feature_flags) {
25
- this.Re = [];
26
- for (const e of t.feature_flags) {
27
- let t = et(e);
28
- t && this.Re.push(t);
31
+ if ((!this.si || this.si.ci()) && null != t && t.feature_flags) {
32
+ this.hi = [];
33
+ for (const s of t.feature_flags) {
34
+ const t = st(s);
35
+ t && this.hi.push(t);
29
36
  }
30
- (this.De = new Date().getTime()), this.Ne(), this.he.St(this.Re);
37
+ (this.oi = new Date().getTime()), this.mi(), this.ai.St(this.hi);
31
38
  }
32
39
  }
33
- xe() {
34
- const t = this.h.I(o.q.ze) || {};
35
- let e = {};
36
- for (let s in t) {
37
- let i = st(t[s]);
38
- i && (e[i.id] = i);
40
+ pi() {
41
+ let t = {};
42
+ this.ri && (t = this.ri.I(o.q.di));
43
+ const s = {};
44
+ for (const i in t) {
45
+ const e = it(t[i]);
46
+ e && (s[e.id] = e);
39
47
  }
40
- return e;
48
+ return s;
41
49
  }
42
50
  Ws(t) {
43
- return this.he.ut(t);
51
+ return this.ai.ut(t);
44
52
  }
45
- refreshFeatureFlags(t, e, s, i) {
46
- if (!this.Se(s))
53
+ refreshFeatureFlags(t, s, i = !1, e = !0) {
54
+ if (!this.gi(i))
47
55
  return (
48
- this.$e ||
49
- (this.$e = this.gt.qe(() => {
50
- this.refreshFeatureFlags(t, e);
56
+ !this.ni &&
57
+ this.si &&
58
+ (this.ni = this.si.Fi(() => {
59
+ this.refreshFeatureFlags(t, s);
51
60
  })),
52
- void ("function" == typeof e && e())
61
+ void ("function" == typeof s && s())
53
62
  );
54
- null == i && (i = !0), i && this.Me();
55
- const r = this.vt.Ps({}, !0),
56
- a = this.vt.Bs(r, !1, !0);
57
- let h = !1;
58
- this.vt.Gs(r, () => {
59
- b.Hs({
60
- url: `${this.vt.Ks()}/feature_flags/sync`,
61
- headers: a,
62
- data: r,
63
- S: s => {
64
- if (!this.vt.Os(r, s, a))
65
- return (h = !0), void ("function" == typeof e && e());
66
- this.vt.Qs(), this.Rs(s), "function" == typeof t && t();
67
- },
68
- error: t => {
69
- this.vt.Vs(t, "retrieving feature flags"),
70
- (h = !0),
71
- "function" == typeof e && e();
72
- },
73
- Ue: () => {
74
- if (i && h && !this.ke) {
75
- let i = this.Te;
76
- (null == i || i < 1e3 * this.ye) && (i = 1e3 * this.ye),
77
- this.Ae(Math.min(3e5, tt(1e3 * this.ye, 3 * i)), t, e, s);
78
- }
79
- }
80
- });
63
+ if ((e && this.yi(), !this.ei)) return void ("function" == typeof s && s());
64
+ const r = this.ei.Ps({}, !0),
65
+ h = this.ei.Bs(r, !1, !0);
66
+ let o = !1;
67
+ this.ei.Gs(r, () => {
68
+ this.ei
69
+ ? b.Hs({
70
+ url: `${this.ei.Ks()}/feature_flags/sync`,
71
+ headers: h,
72
+ data: r,
73
+ S: i => {
74
+ if (!this.ei.Os(r, i, h))
75
+ return (o = !0), void ("function" == typeof s && s());
76
+ this.ei.Qs(), this.Rs(i), "function" == typeof t && t();
77
+ },
78
+ error: t => {
79
+ this.ei.Vs(t, "retrieving feature flags"),
80
+ (o = !0),
81
+ "function" == typeof s && s();
82
+ },
83
+ wi: () => {
84
+ if (e && o && !this.li) {
85
+ let e = this.ui;
86
+ (null == e || e < 1e3 * this.fi) && (e = 1e3 * this.fi),
87
+ this.bi(Math.min(3e5, tt(1e3 * this.fi, 3 * e)), t, s, i);
88
+ }
89
+ }
90
+ })
91
+ : "function" == typeof s && s();
81
92
  });
82
93
  }
83
- Me() {
84
- null != this.ke && (clearTimeout(this.ke), (this.ke = null));
94
+ yi() {
95
+ null != this.li && (clearTimeout(this.li), (this.li = null));
85
96
  }
86
- Ae(t, e, s, i) {
87
- null == t && (t = 1e3 * this.ye),
88
- this.Me(),
89
- (this.ke = setTimeout(() => {
90
- this.refreshFeatureFlags(e, s, i);
97
+ bi(t = 1e3 * this.fi, s, i, e) {
98
+ this.yi(),
99
+ (this.li = window.setTimeout(() => {
100
+ this.refreshFeatureFlags(s, i, e);
91
101
  }, t)),
92
- (this.Te = t);
102
+ (this.ui = t);
93
103
  }
94
- Se(t) {
104
+ gi(t) {
105
+ if (!this.si) return !1;
95
106
  if (!t) {
96
- const t = parseFloat(this.gt.Be());
97
- let e = !1;
107
+ const t = parseFloat(this.si.ji());
108
+ let s = !1;
98
109
  if (!isNaN(t)) {
99
110
  if (-1 === t) return r.D.info("Feature flag refreshes not allowed"), !1;
100
- e = new Date().getTime() >= (this.De || 0) + 1e3 * t;
111
+ s = new Date().getTime() >= (this.oi || 0) + 1e3 * t;
101
112
  }
102
- if (!e)
113
+ if (!s)
103
114
  return (
104
115
  r.D.info(`Feature flag refreshes were rate limited to ${t} seconds`),
105
116
  !1
106
117
  );
107
118
  }
108
- return this.gt._e();
119
+ return this.si.ci();
109
120
  }
110
- Ne() {
121
+ mi() {
122
+ if (!this.ri) return;
111
123
  const t = {};
112
- for (let e = 0; e < this.Re.length; e++) {
113
- let s = this.Re[e],
114
- i = s.ss();
124
+ for (const s of this.hi) {
125
+ const i = s.ss();
115
126
  t[s.id] = i;
116
127
  }
117
- this.h.B(o.q.ze, t), this.h.B(o.q.Ce, this.De);
128
+ this.ri.B(o.q.di, t), this.ri.B(o.q.vi, this.oi);
118
129
  }
119
130
  }
@@ -1,12 +1,12 @@
1
1
  import r from "../../shared-lib/braze-shared-lib.js";
2
2
  import e from "../managers/braze-instance.js";
3
- import { newFeatureFlagFromJson as et } from "./feature-flag-factory.js";
4
3
  import ir from "./feature-flags-provider-factory.js";
5
4
  export function getAllFeatureFlags() {
6
5
  if (!e.rr()) return;
7
- let t = [];
8
- if (!e.ir()._e()) return r.D.info("Feature flags are not enabled."), t;
9
- const a = ir.er().xe();
10
- for (let r in a) t.push(et(a[r]));
6
+ const t = [],
7
+ a = e.ir();
8
+ if (a && !a.ci()) return r.D.info("Feature flags are not enabled."), t;
9
+ const o = ir.er().pi();
10
+ for (const r in o) t.push(o[r]);
11
11
  return t;
12
12
  }
@@ -1,12 +1,12 @@
1
1
  import r from "../../shared-lib/braze-shared-lib.js";
2
2
  import e from "../managers/braze-instance.js";
3
- import { newFeatureFlagFromJson as et } from "./feature-flag-factory.js";
4
3
  import FeatureFlag from "./feature-flag.js";
5
4
  import ir from "./feature-flags-provider-factory.js";
6
- export function getFeatureFlag(a) {
5
+ export function getFeatureFlag(t) {
7
6
  if (!e.rr()) return;
8
- if (!e.ir()._e())
9
- return r.D.info("Feature flags are not enabled."), new FeatureFlag(a);
10
- const t = ir.er().xe();
11
- return t[a] ? et(t[a]) : new FeatureFlag(a);
7
+ const a = e.ir();
8
+ if (a && !a.ci())
9
+ return r.D.info("Feature flags are not enabled."), new FeatureFlag(t);
10
+ const o = ir.er().pi();
11
+ return o[t] ? o[t] : new FeatureFlag(t);
12
12
  }
@@ -1,6 +1,6 @@
1
1
  import e from "../managers/braze-instance.js";
2
2
  import ir from "./feature-flags-provider-factory.js";
3
- function tr(r, t, a) {
3
+ function tr(r, t, a = !1) {
4
4
  if (e.rr()) return ir.er().refreshFeatureFlags(r, t, a);
5
5
  }
6
6
  export function refreshFeatureFlags(r, e) {
@@ -0,0 +1 @@
1
+ export {};
@@ -2,7 +2,7 @@ import y from "../common/base-provider.js";
2
2
  import e from "../managers/braze-instance.js";
3
3
  import Feed from "./feed.js";
4
4
  import {
5
- newCardFromFeedJson as it,
5
+ newCardFromFeedJson as et,
6
6
  newCardFromSerializedValue as S
7
7
  } from "../Card/util/card-factory.js";
8
8
  import { rehydrateDateAfterJsonization as w } from "../util/date-utils.js";
@@ -12,59 +12,59 @@ export default class ee extends y {
12
12
  constructor(t, s) {
13
13
  super(),
14
14
  (this.h = t),
15
- (this.si = s),
15
+ (this.Ci = s),
16
16
  (this.yt = new u()),
17
17
  e.jt(this.yt),
18
18
  this.zt();
19
19
  }
20
20
  zt() {
21
- const t = this.h.I(o.q.ei) || [],
21
+ const t = this.h.I(o.q.Di) || [],
22
22
  s = [];
23
23
  for (let i = 0; i < t.length; i++) {
24
24
  const e = S(t[i]);
25
25
  null != e && s.push(e);
26
26
  }
27
- (this.Zt = s), (this.ri = w(this.h.I(o.q.hi)));
27
+ (this.Zt = s), (this._i = w(this.h.I(o.q.xi)));
28
28
  }
29
- oi(t) {
29
+ Si(t) {
30
30
  const s = [];
31
31
  let i = null;
32
32
  const e = this.h.I(o.q.P) || {},
33
33
  r = {};
34
34
  for (let h = 0; h < t.length; h++) {
35
35
  i = t[h];
36
- const o = it(i);
36
+ const o = et(i);
37
37
  null != o && (e[o.id] && ((o.viewed = !0), (r[o.id] = !0)), s.push(o));
38
38
  }
39
39
  this.h.B(o.q.P, r),
40
40
  (this.Zt = s),
41
41
  this.Ss(),
42
- (this.ri = new Date()),
43
- this.h.B(o.q.hi, this.ri);
42
+ (this._i = new Date()),
43
+ this.h.B(o.q.xi, this._i);
44
44
  }
45
45
  Ss() {
46
46
  const t = [];
47
47
  for (let s = 0; s < this.Zt.length; s++) t.push(this.Zt[s].ss());
48
- this.h.B(o.q.ei, t);
48
+ this.h.B(o.q.Di, t);
49
49
  }
50
50
  Rs(t) {
51
51
  null != t &&
52
52
  t.feed &&
53
53
  (this.zt(),
54
- this.oi(t.feed),
55
- this.yt.St(new Feed(this.Zt.slice(), this.ri)));
54
+ this.Si(t.feed),
55
+ this.yt.St(new Feed(this.Zt.slice(), this._i)));
56
56
  }
57
- ai() {
57
+ Ti() {
58
58
  this.zt();
59
59
  const t = [],
60
60
  s = new Date();
61
61
  for (let i = 0; i < this.Zt.length; i++)
62
62
  (null == this.Zt[i].expiresAt || this.Zt[i].expiresAt >= s) &&
63
63
  t.push(this.Zt[i]);
64
- return new Feed(t, this.ri);
64
+ return new Feed(t, this._i);
65
65
  }
66
66
  Is() {
67
- this.si.requestFeedRefresh();
67
+ this.Ci.requestFeedRefresh();
68
68
  }
69
69
  Ws(t) {
70
70
  return this.yt.ut(t);
@@ -72,8 +72,8 @@ export default class ee extends y {
72
72
  clearData(t) {
73
73
  null == t && (t = !1),
74
74
  (this.Zt = []),
75
- (this.ri = null),
76
- t && (this.h.Xs(o.q.ei), this.h.Xs(o.q.hi)),
77
- this.yt.St(new Feed(this.Zt.slice(), this.ri));
75
+ (this._i = null),
76
+ t && (this.h.Xs(o.q.Di), this.h.Xs(o.q.xi)),
77
+ this.yt.St(new Feed(this.Zt.slice(), this._i));
78
78
  }
79
79
  }
@@ -1,5 +1,5 @@
1
1
  import e from "../managers/braze-instance.js";
2
2
  import re from "./feed-provider-factory.js";
3
3
  export function getCachedFeed() {
4
- if (e.rr()) return re.er().ai();
4
+ if (e.rr()) return re.er().Ti();
5
5
  }
@@ -36,7 +36,7 @@ export function showFeed(t, n, o) {
36
36
  let a = !1,
37
37
  f = null;
38
38
  null == n
39
- ? ((f = re.er().ai()),
39
+ ? ((f = re.er().Ti()),
40
40
  k(f, s(f.cards, o), f.lastUpdated, null, i),
41
41
  (a = !0))
42
42
  : (f = new Feed(s(n, o), new Date()));