@braze/web-sdk 5.0.0 → 5.1.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 (158) hide show
  1. package/README.md +1 -1
  2. package/index.d.ts +12 -5
  3. package/package.json +1 -1
  4. package/shared-lib/encoding-utils.js +3 -3
  5. package/shared-lib/event-types.js +29 -29
  6. package/shared-lib/guid.js +3 -3
  7. package/shared-lib/index.js +6 -0
  8. package/shared-lib/indexed-db-adapter.js +70 -70
  9. package/shared-lib/logger.js +18 -18
  10. package/shared-lib/supported-options.js +21 -21
  11. package/src/Card/card-manager.js +43 -45
  12. package/src/Card/display/card-display.js +60 -60
  13. package/src/Card/log-card-click.js +4 -4
  14. package/src/Card/log-card-dismissal.js +2 -3
  15. package/src/Card/log-card-impressions.js +7 -7
  16. package/src/Card/models/captioned-image.js +21 -21
  17. package/src/Card/models/card.js +73 -73
  18. package/src/Card/models/classic-card.js +21 -21
  19. package/src/Card/models/control-card.js +11 -11
  20. package/src/Card/models/image-only.js +19 -19
  21. package/src/Card/util/card-factory.js +68 -68
  22. package/src/ContentCards/content-cards-provider-factory.js +3 -3
  23. package/src/ContentCards/content-cards-provider.js +255 -245
  24. package/src/ContentCards/content-cards.js +2 -2
  25. package/src/ContentCards/get-cached-content-cards.js +1 -1
  26. package/src/ContentCards/request-content-cards-refresh.js +1 -1
  27. package/src/ContentCards/subscribe-to-content-cards-updates.js +6 -6
  28. package/src/ContentCards/ui/hide-content-cards.js +1 -1
  29. package/src/ContentCards/ui/show-content-cards.js +24 -24
  30. package/src/ContentCards/ui/toggle-content-cards.js +1 -1
  31. package/src/Core/add-sdk-metadata.js +21 -19
  32. package/src/Core/change-user.js +10 -10
  33. package/src/Core/destroy.js +2 -2
  34. package/src/Core/disable-sdk.js +11 -11
  35. package/src/Core/enable-sdk.js +7 -7
  36. package/src/Core/get-device-id.js +6 -6
  37. package/src/Core/get-user.js +1 -1
  38. package/src/Core/handle-braze-action.js +41 -41
  39. package/src/Core/is-disabled.js +2 -2
  40. package/src/Core/log-custom-event.js +15 -15
  41. package/src/Core/log-purchase.js +31 -37
  42. package/src/Core/open-session.js +12 -12
  43. package/src/Core/remove-all-subscriptions.js +1 -1
  44. package/src/Core/remove-subscription.js +1 -1
  45. package/src/Core/request-immediate-data-flush.js +1 -1
  46. package/src/Core/set-logger.js +2 -2
  47. package/src/Core/set-sdk-authentication-signature.js +3 -3
  48. package/src/Core/subscribe-to-sdk-authentication-failures.js +6 -4
  49. package/src/Core/toggle-logging.js +2 -2
  50. package/src/Core/wipe-data.js +9 -9
  51. package/src/FeatureFlags/feature-flag-factory.js +12 -12
  52. package/src/FeatureFlags/feature-flag.js +10 -10
  53. package/src/FeatureFlags/feature-flags-provider-factory.js +3 -2
  54. package/src/FeatureFlags/feature-flags-provider.js +108 -80
  55. package/src/FeatureFlags/get-all-feature-flags.js +5 -5
  56. package/src/FeatureFlags/get-feature-flag.js +6 -6
  57. package/src/FeatureFlags/log-feature-flag-impression.js +15 -13
  58. package/src/FeatureFlags/refresh-feature-flags.js +1 -1
  59. package/src/FeatureFlags/subscribe-to-feature-flags-updates.js +7 -4
  60. package/src/Feed/feed-provider-factory.js +2 -2
  61. package/src/Feed/feed-provider.js +44 -44
  62. package/src/Feed/feed.js +1 -1
  63. package/src/Feed/get-cached-feed.js +1 -1
  64. package/src/Feed/log-feed-displayed.js +4 -4
  65. package/src/Feed/request-feed-refresh.js +1 -1
  66. package/src/Feed/subscribe-to-feed-updates.js +1 -1
  67. package/src/Feed/ui/hide-feed.js +1 -1
  68. package/src/Feed/ui/show-feed.js +28 -28
  69. package/src/Feed/ui/toggle-feed.js +1 -1
  70. package/src/InAppMessage/defer-in-app-message.js +5 -5
  71. package/src/InAppMessage/display/html-message-to-html.js +54 -54
  72. package/src/InAppMessage/display/in-app-message-to-html.js +79 -79
  73. package/src/InAppMessage/display/modal-utils.js +8 -8
  74. package/src/InAppMessage/get-deferred-in-app-message.js +1 -1
  75. package/src/InAppMessage/in-app-message-factory.js +49 -49
  76. package/src/InAppMessage/in-app-message-manager-factory.js +1 -1
  77. package/src/InAppMessage/in-app-message-manager.js +143 -138
  78. package/src/InAppMessage/log-in-app-message-button-click.js +12 -12
  79. package/src/InAppMessage/log-in-app-message-click.js +9 -9
  80. package/src/InAppMessage/log-in-app-message-html-click.js +12 -12
  81. package/src/InAppMessage/log-in-app-message-impression.js +6 -6
  82. package/src/InAppMessage/models/full-screen-message.js +33 -33
  83. package/src/InAppMessage/models/html-message.js +20 -20
  84. package/src/InAppMessage/models/in-app-message-button.js +6 -6
  85. package/src/InAppMessage/models/in-app-message.js +99 -99
  86. package/src/InAppMessage/models/modal-message.js +32 -32
  87. package/src/InAppMessage/models/slide-up-message.js +28 -28
  88. package/src/InAppMessage/models/templated-in-app-message.js +8 -8
  89. package/src/InAppMessage/subscribe-to-in-app-message.js +2 -2
  90. package/src/InAppMessage/ui/automatically-show-in-app-messages.js +4 -4
  91. package/src/InAppMessage/ui/show-in-app-message.js +81 -81
  92. package/src/Push/is-push-blocked.js +1 -1
  93. package/src/Push/is-push-permission-granted.js +1 -1
  94. package/src/Push/is-push-supported.js +1 -1
  95. package/src/Push/push-manager-factory.js +5 -5
  96. package/src/Push/push-manager.js +176 -173
  97. package/src/Push/request-push-permission.js +1 -1
  98. package/src/Push/unregister-push.js +1 -1
  99. package/src/Push/utils/push-utils.js +4 -4
  100. package/src/User/user-manager.js +29 -29
  101. package/src/User/user.js +72 -74
  102. package/src/common/base-feed.js +7 -7
  103. package/src/common/base-provider.js +1 -1
  104. package/src/common/constants.js +2 -0
  105. package/src/common/event-logger.js +21 -18
  106. package/src/common/feed-display.js +44 -44
  107. package/src/l10n/l10n-manager-factory.js +3 -3
  108. package/src/l10n/l10n-manager.js +7 -7
  109. package/src/managers/auth-manager.js +32 -32
  110. package/src/managers/braze-instance.js +188 -189
  111. package/src/managers/device-manager.js +28 -28
  112. package/src/managers/network-manager.js +189 -138
  113. package/src/managers/server-config-manager.js +69 -53
  114. package/src/managers/session-manager.js +34 -30
  115. package/src/managers/storage-manager-factory.js +16 -16
  116. package/src/managers/storage-manager.js +210 -188
  117. package/src/managers/subscription-manager.js +12 -12
  118. package/src/models/backend-errors.js +5 -5
  119. package/src/models/braze-event.js +3 -3
  120. package/src/models/device.js +2 -2
  121. package/src/models/identifier.js +34 -14
  122. package/src/models/push-token.js +8 -8
  123. package/src/models/request-result.js +3 -3
  124. package/src/models/server-config.js +32 -23
  125. package/src/request-controller.js +187 -180
  126. package/src/triggers/models/custom-event-data.js +7 -7
  127. package/src/triggers/models/custom-event-property-data.js +10 -10
  128. package/src/triggers/models/filter-set.js +13 -13
  129. package/src/triggers/models/filter.js +45 -45
  130. package/src/triggers/models/in-app-message-click-data.js +12 -12
  131. package/src/triggers/models/purchase-data.js +2 -2
  132. package/src/triggers/models/purchase-property-data.js +10 -10
  133. package/src/triggers/models/push-click-data.js +7 -7
  134. package/src/triggers/models/trigger-condition.js +57 -59
  135. package/src/triggers/models/trigger-events.js +4 -4
  136. package/src/triggers/models/trigger.js +38 -38
  137. package/src/triggers/triggers-provider-factory.js +4 -4
  138. package/src/triggers/triggers-provider.js +127 -130
  139. package/src/ui/js/attach-css.js +2 -2
  140. package/src/ui/js/iam-css.js +1 -1
  141. package/src/ui/js/load-font-awesome.js +1 -1
  142. package/src/util/base-device-parser.js +3 -3
  143. package/src/util/braze-actions.js +35 -35
  144. package/src/util/browser-detector.js +21 -21
  145. package/src/util/client-hints-parser.js +8 -8
  146. package/src/util/code-utils.js +2 -2
  147. package/src/util/component-utils.js +1 -1
  148. package/src/util/deprecation-utils.js +4 -4
  149. package/src/util/device-constants.js +1 -1
  150. package/src/util/dom-utils.js +18 -18
  151. package/src/util/key-codes.js +1 -1
  152. package/src/util/net.js +18 -18
  153. package/src/util/request-header-utils.js +39 -37
  154. package/src/util/string-utils.js +10 -10
  155. package/src/util/user-agent-parser.js +18 -18
  156. package/src/util/validation-utils.js +37 -39
  157. package/src/util/window-utils.js +3 -3
  158. package/shared-lib/braze-shared-lib.js +0 -8
@@ -3,23 +3,23 @@ import {
3
3
  bottomHadImpression as be,
4
4
  getCardId as ye,
5
5
  impressOnBottom as Fe,
6
- impressOnTop as Te,
7
- markCardAsRead as xe,
6
+ impressOnTop as xe,
7
+ markCardAsRead as Te,
8
8
  topHadImpression as Ee,
9
9
  } from "../Card/display/card-display.js";
10
10
  import { bottomIsInView as he, topIsInView as Se } from "../util/dom-utils.js";
11
11
  import { Card, ControlCard } from "../Card/index.js";
12
12
  import { cardToHtml as _e } from "../Card/display/card-display.js";
13
- import { isArray as p } from "../util/code-utils.js";
13
+ import { isArray as j } from "../util/code-utils.js";
14
14
  import { KeyCodes as at } from "../util/key-codes.js";
15
15
  import je from "../l10n/l10n-manager-factory.js";
16
16
  import { removeSubscription } from "../Core/remove-subscription.js";
17
- import r from "../../shared-lib/braze-shared-lib.js";
18
- import { BRAZE_ACTION_URI_REGEX as W } from "../util/validation-utils.js";
17
+ import { logger as r, Guid as p } from "../../shared-lib/index.js";
18
+ import { BRAZE_ACTION_URI_REGEX as Z } from "../util/validation-utils.js";
19
19
  import {
20
20
  INELIGIBLE_BRAZE_ACTION_URL_ERROR_TYPES as dt,
21
21
  ineligibleBrazeActionURLErrorMessage as ft,
22
- getDecodedBrazeAction as O,
22
+ getDecodedBrazeAction as W,
23
23
  containsUnknownBrazeAction as gt,
24
24
  } from "../util/braze-actions.js";
25
25
  export const LAST_REQUESTED_REFRESH_DATA_ATTRIBUTE =
@@ -59,9 +59,9 @@ export function generateFeedBody(e, t) {
59
59
  const logCardClick = (t) => e.logCardClick(t);
60
60
  for (const n of e.cards) {
61
61
  const i = n instanceof ControlCard;
62
- !i || e.ur()
62
+ !i || e.dr()
63
63
  ? (o.appendChild(_e(n, logCardClick, t)), (s = s || !i))
64
- : r.j.error(
64
+ : r.error(
65
65
  "Received a control card for a legacy news feed. Control cards are only supported with content cards.",
66
66
  );
67
67
  }
@@ -79,13 +79,13 @@ export function detectFeedImpressions(e, t) {
79
79
  if (null != e && null != t) {
80
80
  const o = [],
81
81
  s = t.querySelectorAll(".ab-card");
82
- e.yo || (e.yo = {});
82
+ e.Fo || (e.Fo = {});
83
83
  for (let t = 0; t < s.length; t++) {
84
84
  const n = ye(s[t]),
85
85
  r = Se(s[t]),
86
86
  i = he(s[t]);
87
- if (e.yo[n]) {
88
- r || i || xe(s[t]);
87
+ if (e.Fo[n]) {
88
+ r || i || Te(s[t]);
89
89
  continue;
90
90
  }
91
91
  let a = Ee(s[t]),
@@ -93,14 +93,14 @@ export function detectFeedImpressions(e, t) {
93
93
  const l = a,
94
94
  c = d;
95
95
  if (
96
- (!a && r && ((a = !0), Te(s[t])),
96
+ (!a && r && ((a = !0), xe(s[t])),
97
97
  !d && i && ((d = !0), Fe(s[t])),
98
98
  a && d)
99
99
  ) {
100
100
  if (l && c) continue;
101
101
  for (const t of e.cards)
102
102
  if (t.id === n) {
103
- (e.yo[t.id] = !0), o.push(t);
103
+ (e.Fo[t.id] = !0), o.push(t);
104
104
  break;
105
105
  }
106
106
  }
@@ -130,7 +130,7 @@ export function refreshFeed(e, t) {
130
130
  "true" === t.getAttribute("aria-busy") &&
131
131
  t.setAttribute("aria-busy", "false");
132
132
  }
133
- }, x.uo),
133
+ }, x.Co),
134
134
  e.sr();
135
135
  }
136
136
  export function feedToHtml(e, t, o) {
@@ -143,51 +143,51 @@ export function feedToHtml(e, t, o) {
143
143
  (n.className = "ab-feed-buttons-wrapper"),
144
144
  n.setAttribute("role", "group"),
145
145
  s.appendChild(n);
146
- const i = document.createElement("i");
147
- (i.className = "fa fa-times ab-close-button"),
148
- i.setAttribute("aria-label", "Close Feed"),
149
- i.setAttribute("tabindex", "0"),
150
- i.setAttribute("role", "button");
151
- const a = (e) => {
146
+ const r = document.createElement("i");
147
+ (r.className = "fa fa-times ab-close-button"),
148
+ r.setAttribute("aria-label", "Close Feed"),
149
+ r.setAttribute("tabindex", "0"),
150
+ r.setAttribute("role", "button");
151
+ const i = (e) => {
152
152
  destroyFeedHtml(s), e.stopPropagation();
153
153
  };
154
- i.addEventListener("keydown", (e) => {
155
- (e.keyCode !== at.Fo && e.keyCode !== at.To) || a(e);
154
+ r.addEventListener("keydown", (e) => {
155
+ (e.keyCode !== at.To && e.keyCode !== at.Eo) || i(e);
156
156
  }),
157
- (i.onclick = a);
158
- const d = document.createElement("i");
159
- (d.className = "fa fa-refresh ab-refresh-button"),
160
- e && null == e.lastUpdated && (d.className += " fa-spin"),
161
- d.setAttribute("aria-label", "Refresh Feed"),
162
- d.setAttribute("tabindex", "0"),
163
- d.setAttribute("role", "button");
164
- const l = (t) => {
157
+ (r.onclick = i);
158
+ const a = document.createElement("i");
159
+ (a.className = "fa fa-refresh ab-refresh-button"),
160
+ e && null == e.lastUpdated && (a.className += " fa-spin"),
161
+ a.setAttribute("aria-label", "Refresh Feed"),
162
+ a.setAttribute("tabindex", "0"),
163
+ a.setAttribute("role", "button");
164
+ const d = (t) => {
165
165
  refreshFeed(e, s), t.stopPropagation();
166
166
  };
167
- d.addEventListener("keydown", (e) => {
168
- (e.keyCode !== at.Fo && e.keyCode !== at.To) || l(e);
167
+ a.addEventListener("keydown", (e) => {
168
+ (e.keyCode !== at.To && e.keyCode !== at.Eo) || d(e);
169
169
  }),
170
- (d.onclick = l),
171
- n.appendChild(d),
172
- n.appendChild(i),
170
+ (a.onclick = d),
171
+ n.appendChild(a),
172
+ n.appendChild(r),
173
173
  s.appendChild(generateFeedBody(e, t));
174
- const c = () => detectFeedImpressions(e, s);
175
- if ((s.addEventListener("scroll", c), !o)) {
176
- window.addEventListener("scroll", c);
177
- const e = r.Z.Y();
178
- (scrollListeners[e] = c), s.setAttribute("data-listener-id", e);
174
+ const l = () => detectFeedImpressions(e, s);
175
+ if ((s.addEventListener("scroll", l), !o)) {
176
+ window.addEventListener("scroll", l);
177
+ const e = p.W();
178
+ (scrollListeners[e] = l), s.setAttribute("data-listener-id", e);
179
179
  }
180
180
  return s;
181
181
  }
182
182
  export function updateFeedCards(e, t, o, s, n) {
183
- if (!p(t)) return;
183
+ if (!j(t)) return;
184
184
  const i = [];
185
185
  for (const e of t)
186
186
  if (e instanceof Card) {
187
- if (e.url && W.test(e.url)) {
188
- const t = O(e.url);
187
+ if (e.url && Z.test(e.url)) {
188
+ const t = W(e.url);
189
189
  if (gt(t)) {
190
- r.j.error(ft(dt._r, "Content Card"));
190
+ r.error(ft(dt.Xi, "Content Card"));
191
191
  continue;
192
192
  }
193
193
  }
@@ -1,14 +1,14 @@
1
1
  import e, { OPTIONS as L } from "../managers/braze-instance.js";
2
- import Q from "../util/browser-detector.js";
2
+ import X from "../util/browser-detector.js";
3
3
  import nr from "./l10n-manager.js";
4
4
  const je = {
5
5
  t: !1,
6
6
  i: null,
7
7
  m: () => {
8
8
  if ((je.o(), !je.i)) {
9
- let r = Q.language,
9
+ let r = X.language,
10
10
  t = !1;
11
- e.nn(L.Ba) && ((r = e.nn(L.Ba)), (t = !0)), (je.i = new nr(r, t));
11
+ e.nn(L.Xn) && ((r = e.nn(L.Xn)), (t = !0)), (je.i = new nr(r, t));
12
12
  }
13
13
  return je.i;
14
14
  },
@@ -1,25 +1,25 @@
1
- import r from "../../shared-lib/braze-shared-lib.js";
2
- import zt from "../common/translations.js";
1
+ import { logger as r } from "../../shared-lib/index.js";
2
+ import jt from "../common/translations.js";
3
3
  export default class nr {
4
4
  constructor(t, l = !1) {
5
5
  if (
6
6
  ((this.language = t),
7
7
  null != t && (t = t.toLowerCase()),
8
- null != t && null == zt[t])
8
+ null != t && null == jt[t])
9
9
  ) {
10
10
  const l = t.indexOf("-");
11
11
  l > 0 && (t = t.substring(0, l));
12
12
  }
13
- if (null == zt[t]) {
14
- const a =
13
+ if (null == jt[t]) {
14
+ const n =
15
15
  "Braze does not yet have a localization for language " +
16
16
  t +
17
17
  ", defaulting to English. Please contact us if you are willing and able to help us translate our SDK into this language.";
18
- l ? r.j.error(a) : r.j.info(a), (t = "en");
18
+ l ? r.error(n) : r.info(n), (t = "en");
19
19
  }
20
20
  this.language = t;
21
21
  }
22
22
  get(t) {
23
- return zt[this.language][t];
23
+ return jt[this.language][t];
24
24
  }
25
25
  }
@@ -1,51 +1,51 @@
1
- import { STORAGE_KEYS as i } from "./storage-manager.js";
2
- import E from "./subscription-manager.js";
3
- import r from "../../shared-lib/braze-shared-lib.js";
1
+ import { STORAGE_KEYS as o } from "./storage-manager.js";
2
+ import T from "./subscription-manager.js";
3
+ import { logger as r, IndexedDBAdapter as A } from "../../shared-lib/index.js";
4
4
  export default class kt {
5
5
  constructor(t, i, s) {
6
6
  (this.u = t),
7
- (this.gh = i),
8
- (this.ph = s),
7
+ (this.Zn = i),
8
+ (this.gh = s),
9
9
  (this.u = t),
10
- (this.gh = i || !1),
11
- (this.ph = s),
12
- (this.Fh = new E()),
13
- (this.kh = 0),
14
- (this.fh = 1);
10
+ (this.Zn = i || !1),
11
+ (this.gh = s),
12
+ (this.ph = new T()),
13
+ (this.Fh = 0),
14
+ (this.kh = 1);
15
15
  }
16
- wh() {
17
- return this.gh;
16
+ fh() {
17
+ return this.Zn;
18
18
  }
19
- jh() {
20
- return this.u.v(i.k.xh);
19
+ wh() {
20
+ return this.u.j(o.C.jh);
21
21
  }
22
22
  setSdkAuthenticationSignature(t) {
23
- const s = this.jh();
24
- this.u.D(i.k.xh, t);
25
- const e = r.ts.Zt;
26
- new r.es(e, r.j).setItem(e.rs.qh, this.fh, t), s !== t && this.ti();
23
+ const i = this.wh();
24
+ this.u.k(o.C.jh, t);
25
+ const s = A.Yt.Qt;
26
+ new A(s, r).setItem(s.ss.xh, this.kh, t), i !== t && this.Xs();
27
27
  }
28
- yh() {
29
- this.u.ni(i.k.xh);
30
- const t = r.ts.Zt;
31
- new r.es(t, r.j).oe(t.rs.qh, this.fh);
28
+ qh() {
29
+ this.u.hi(o.C.jh);
30
+ const t = A.Yt.Qt;
31
+ new A(t, r).re(t.ss.xh, this.kh);
32
32
  }
33
33
  subscribeToSdkAuthenticationFailures(t) {
34
- return this.ph.It(t);
34
+ return this.gh.It(t);
35
35
  }
36
- Bh(t) {
37
- this.ph.Dt(t);
36
+ yh(t) {
37
+ this.gh.Dt(t);
38
+ }
39
+ Bh() {
40
+ this.ph.removeAllSubscriptions();
38
41
  }
39
42
  Gh() {
40
- this.Fh.removeAllSubscriptions();
43
+ this.Fh += 1;
41
44
  }
42
45
  Hh() {
43
- this.kh += 1;
44
- }
45
- Jh() {
46
- return this.kh;
46
+ return this.Fh;
47
47
  }
48
- ti() {
49
- this.kh = 0;
48
+ Xs() {
49
+ this.Fh = 0;
50
50
  }
51
51
  }