@braze/web-sdk 5.9.1 → 6.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 (176) hide show
  1. package/index.d.ts +209 -283
  2. package/package.json +1 -1
  3. package/shared-lib/encoding-utils.js +1 -1
  4. package/shared-lib/event-types.js +27 -29
  5. package/shared-lib/guid.js +3 -3
  6. package/shared-lib/indexed-db-adapter.js +22 -22
  7. package/shared-lib/logger.js +18 -18
  8. package/shared-lib/supported-options.js +22 -23
  9. package/src/Banner/banner-factory.js +2 -1
  10. package/src/Banner/banner-provider-factory.js +7 -7
  11. package/src/Banner/banner-provider.js +92 -98
  12. package/src/Banner/banner.js +21 -18
  13. package/src/Banner/display/banner-to-html.js +18 -30
  14. package/src/Banner/display/detect-banner-impressions.js +11 -11
  15. package/src/Banner/get-all-banners.js +5 -5
  16. package/src/Banner/get-banner.js +7 -7
  17. package/src/Banner/index.js +0 -1
  18. package/src/Banner/log-banner-click.js +7 -7
  19. package/src/Banner/log-banner-impressions.js +9 -9
  20. package/src/Banner/request-banners-refresh.js +23 -27
  21. package/src/Banner/subscribe-to-banners-updates.js +9 -9
  22. package/src/Banner/ui/insert-banner.js +10 -10
  23. package/src/Card/card-manager-factory.js +7 -7
  24. package/src/Card/card-manager.js +45 -47
  25. package/src/Card/display/card-display.js +76 -74
  26. package/src/Card/index.js +0 -2
  27. package/src/Card/log-card-dismissal.js +4 -4
  28. package/src/Card/log-content-card-click.js +9 -2
  29. package/src/Card/log-content-card-impressions.js +11 -2
  30. package/src/Card/models/captioned-image.js +21 -21
  31. package/src/Card/models/card.js +116 -110
  32. package/src/Card/models/classic-card.js +21 -21
  33. package/src/Card/models/control-card.js +15 -15
  34. package/src/Card/models/image-only.js +20 -21
  35. package/src/Card/util/card-factory.js +58 -79
  36. package/src/ContentCards/content-cards-provider-factory.js +13 -13
  37. package/src/ContentCards/content-cards-provider.js +148 -148
  38. package/src/ContentCards/content-cards.js +21 -13
  39. package/src/ContentCards/get-cached-content-cards.js +2 -2
  40. package/src/ContentCards/request-content-cards-refresh.js +2 -2
  41. package/src/ContentCards/subscribe-to-content-cards-updates.js +8 -8
  42. package/src/ContentCards/ui/hide-content-cards.js +5 -5
  43. package/src/ContentCards/ui/show-content-cards.js +35 -35
  44. package/src/Core/add-sdk-metadata.js +5 -5
  45. package/src/Core/change-user.js +7 -7
  46. package/src/Core/destroy.js +2 -2
  47. package/src/Core/disable-sdk.js +10 -10
  48. package/src/Core/enable-sdk.js +7 -7
  49. package/src/Core/get-device-id.js +4 -4
  50. package/src/Core/get-user.js +1 -1
  51. package/src/Core/handle-braze-action.js +10 -10
  52. package/src/Core/is-disabled.js +2 -2
  53. package/src/Core/is-initialized.js +1 -1
  54. package/src/Core/log-custom-event.js +18 -18
  55. package/src/Core/log-purchase.js +19 -19
  56. package/src/Core/open-session.js +13 -13
  57. package/src/Core/request-immediate-data-flush.js +1 -1
  58. package/src/Core/set-logger.js +2 -2
  59. package/src/Core/toggle-logging.js +2 -2
  60. package/src/Core/wipe-data.js +9 -9
  61. package/src/FeatureFlags/feature-flag-factory.js +10 -10
  62. package/src/FeatureFlags/feature-flag.js +20 -71
  63. package/src/FeatureFlags/feature-flags-provider-factory.js +7 -7
  64. package/src/FeatureFlags/feature-flags-provider.js +86 -86
  65. package/src/FeatureFlags/get-all-feature-flags.js +3 -3
  66. package/src/FeatureFlags/get-feature-flag.js +3 -3
  67. package/src/FeatureFlags/log-feature-flag-impression.js +8 -8
  68. package/src/FeatureFlags/refresh-feature-flags.js +1 -1
  69. package/src/FeatureFlags/subscribe-to-feature-flags-updates.js +3 -3
  70. package/src/InAppMessage/defer-in-app-message.js +4 -4
  71. package/src/InAppMessage/display/html-message-to-html.js +41 -41
  72. package/src/InAppMessage/display/in-app-message-to-html.js +145 -139
  73. package/src/InAppMessage/display/modal-utils.js +40 -42
  74. package/src/InAppMessage/get-deferred-in-app-message.js +1 -1
  75. package/src/InAppMessage/in-app-message-factory.js +24 -16
  76. package/src/InAppMessage/in-app-message-manager-factory.js +5 -5
  77. package/src/InAppMessage/in-app-message-manager.js +124 -122
  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 +11 -11
  81. package/src/InAppMessage/log-in-app-message-impression.js +4 -4
  82. package/src/InAppMessage/models/control-message.js +5 -5
  83. package/src/InAppMessage/models/full-screen-message.js +41 -35
  84. package/src/InAppMessage/models/html-message.js +28 -26
  85. package/src/InAppMessage/models/in-app-message-button.js +5 -5
  86. package/src/InAppMessage/models/in-app-message.js +156 -152
  87. package/src/InAppMessage/models/modal-message.js +40 -34
  88. package/src/InAppMessage/models/slide-up-message.js +38 -32
  89. package/src/InAppMessage/models/templated-in-app-message.js +8 -8
  90. package/src/InAppMessage/subscribe-to-in-app-message.js +1 -1
  91. package/src/InAppMessage/ui/automatically-show-in-app-messages.js +3 -3
  92. package/src/InAppMessage/ui/show-in-app-message.js +68 -74
  93. package/src/Push/is-push-blocked.js +2 -2
  94. package/src/Push/is-push-permission-granted.js +2 -2
  95. package/src/Push/is-push-supported.js +2 -2
  96. package/src/Push/push-manager-factory.js +17 -17
  97. package/src/Push/push-manager.js +127 -127
  98. package/src/Push/request-push-permission.js +1 -1
  99. package/src/Push/utils/push-utils.js +25 -15
  100. package/src/User/user-manager.js +20 -20
  101. package/src/User/user.js +60 -61
  102. package/src/common/base-provider.js +1 -1
  103. package/src/common/content-cards-display.js +211 -0
  104. package/src/common/event-logger.js +12 -12
  105. package/src/common/properties-base.js +56 -0
  106. package/src/index.js +0 -1
  107. package/src/l10n/l10n-manager-factory.js +10 -10
  108. package/src/l10n/l10n-manager.js +7 -7
  109. package/src/managers/auth-manager.js +36 -36
  110. package/src/managers/braze-instance.js +184 -185
  111. package/src/managers/device-manager.js +26 -26
  112. package/src/managers/network-manager.js +194 -193
  113. package/src/managers/server-config-manager.js +75 -75
  114. package/src/managers/session-manager.js +29 -29
  115. package/src/managers/storage-manager-factory.js +13 -13
  116. package/src/managers/storage-manager.js +162 -164
  117. package/src/managers/subscription-manager.js +12 -12
  118. package/src/managers/utils.js +1 -1
  119. package/src/models/backend-errors.js +5 -5
  120. package/src/models/braze-event.js +16 -16
  121. package/src/models/device.js +3 -3
  122. package/src/models/identifier.js +8 -8
  123. package/src/models/push-token.js +10 -10
  124. package/src/models/request-result.js +4 -4
  125. package/src/models/server-config.js +33 -33
  126. package/src/request-controller.js +193 -192
  127. package/src/triggers/models/custom-event-data.js +7 -7
  128. package/src/triggers/models/custom-event-property-data.js +8 -8
  129. package/src/triggers/models/filter-set.js +8 -8
  130. package/src/triggers/models/filter.js +43 -43
  131. package/src/triggers/models/in-app-message-click-data.js +4 -4
  132. package/src/triggers/models/purchase-data.js +2 -2
  133. package/src/triggers/models/purchase-property-data.js +6 -6
  134. package/src/triggers/models/push-click-data.js +2 -2
  135. package/src/triggers/models/trigger-condition.js +52 -52
  136. package/src/triggers/models/trigger-events.js +4 -4
  137. package/src/triggers/models/trigger.js +19 -19
  138. package/src/triggers/triggers-provider-factory.js +14 -14
  139. package/src/triggers/triggers-provider.js +70 -70
  140. package/src/ui/js/attach-css.js +3 -3
  141. package/src/ui/js/banner-css.js +1 -1
  142. package/src/ui/js/iam-css.js +1 -1
  143. package/src/ui/js/load-font-awesome.js +2 -2
  144. package/src/util/base-device-parser.js +4 -4
  145. package/src/util/braze-actions.js +12 -18
  146. package/src/util/browser-detector.js +27 -20
  147. package/src/util/client-hints-parser.js +8 -8
  148. package/src/util/code-utils.js +2 -2
  149. package/src/util/component-utils.js +14 -14
  150. package/src/util/deprecation-utils.js +2 -2
  151. package/src/util/device-constants.js +5 -5
  152. package/src/util/dom-utils.js +9 -9
  153. package/src/util/html-display-utils.js +38 -38
  154. package/src/util/key-codes.js +1 -1
  155. package/src/util/net.js +12 -12
  156. package/src/util/request-header-utils.js +22 -22
  157. package/src/util/string-utils.js +2 -2
  158. package/src/util/user-agent-parser.js +17 -17
  159. package/src/util/validation-utils.js +28 -28
  160. package/src/util/window-utils.js +2 -2
  161. package/src/Card/log-card-click.js +0 -11
  162. package/src/Card/log-card-impressions.js +0 -13
  163. package/src/Feed/feed-provider-factory.js +0 -18
  164. package/src/Feed/feed-provider.js +0 -90
  165. package/src/Feed/feed.js +0 -20
  166. package/src/Feed/get-cached-feed.js +0 -5
  167. package/src/Feed/index.js +0 -8
  168. package/src/Feed/log-feed-displayed.js +0 -7
  169. package/src/Feed/request-feed-refresh.js +0 -5
  170. package/src/Feed/subscribe-to-feed-updates.js +0 -5
  171. package/src/Feed/types.js +0 -1
  172. package/src/Feed/ui/hide-feed.js +0 -7
  173. package/src/Feed/ui/show-feed.js +0 -96
  174. package/src/Feed/ui/toggle-feed.js +0 -8
  175. package/src/common/base-feed.js +0 -29
  176. package/src/common/feed-display.js +0 -211
package/src/User/user.js CHANGED
@@ -1,39 +1,39 @@
1
1
  import {
2
- isArray as z,
2
+ isArray as D,
3
3
  isDate as Nt,
4
- isObject as yt,
4
+ isObject as It,
5
5
  validateValueIsFromEnum as ta,
6
6
  } from "../util/code-utils.js";
7
- import { logger as N, EventTypes as d } from "../../shared-lib/index.js";
7
+ import { logger as E, EventTypes as m } from "../../shared-lib/index.js";
8
8
  import {
9
9
  isValidEmail as Ct,
10
10
  validateCustomAttributeArrayType as St,
11
- validateCustomAttributeKey as At,
12
- validateCustomProperties as rt,
13
- validateCustomString as nt,
14
- validatePropertyType as Ut,
11
+ validateCustomAttributeKey as Ut,
12
+ validateCustomProperties as nt,
13
+ validateCustomString as mt,
14
+ validatePropertyType as Dt,
15
15
  validateStandardString as ir,
16
16
  } from "../util/validation-utils.js";
17
- import { SET_CUSTOM_USER_ATTRIBUTE_STRING as Dt } from "../common/constants.js";
18
- import { toValidBackendTimeString as Ft } from "../util/date-utils.js";
17
+ import { SET_CUSTOM_USER_ATTRIBUTE_STRING as Ft } from "../common/constants.js";
18
+ import { toValidBackendTimeString as Lt } from "../util/date-utils.js";
19
19
  export default class User {
20
20
  constructor(t, e) {
21
- (this.Cs = t), (this.Fi = e), (this.Cs = t), (this.Fi = e);
21
+ (this.Cs = t), (this.Cn = e), (this.Cs = t), (this.Cn = e);
22
22
  }
23
23
  getUserId(t) {
24
24
  const e = this.Cs.getUserId();
25
25
  if ("function" != typeof t) return e;
26
- N.warn(
26
+ E.warn(
27
27
  "The callback for getUserId is deprecated. You can access its return value directly instead (e.g. `const id = braze.getUser().getUserId()`)",
28
28
  ),
29
29
  t(e);
30
30
  }
31
31
  addAlias(t, e) {
32
32
  return !ir(t, "add alias", "the alias", !1) || t.length <= 0
33
- ? (N.error("addAlias requires a non-empty alias"), !1)
33
+ ? (E.error("addAlias requires a non-empty alias"), !1)
34
34
  : !ir(e, "add alias", "the label", !1) || e.length <= 0
35
- ? (N.error("addAlias requires a non-empty label"), !1)
36
- : this.Fi.Cn(t, e).tt;
35
+ ? (E.error("addAlias requires a non-empty label"), !1)
36
+ : this.Cn.En(t, e).W;
37
37
  }
38
38
  setFirstName(t) {
39
39
  return (
@@ -49,7 +49,7 @@ export default class User {
49
49
  setEmail(t) {
50
50
  return null === t || Ct(t)
51
51
  ? this.Cs.nu("email", t)
52
- : (N.error(
52
+ : (E.error(
53
53
  `Cannot set email address - "${t}" did not pass RFC-5322 validation.`,
54
54
  ),
55
55
  !1);
@@ -84,7 +84,7 @@ export default class User {
84
84
  e < 1 ||
85
85
  r > 31 ||
86
86
  r < 1
87
- ? (N.error(
87
+ ? (E.error(
88
88
  "Cannot set date of birth - parameters should comprise a valid date e.g. setDateOfBirth(1776, 7, 4);",
89
89
  ),
90
90
  !1)
@@ -130,13 +130,13 @@ export default class User {
130
130
  !!ir(t, "set phone number", "the phoneNumber", !0) &&
131
131
  (null === t || t.match(User.Fn)
132
132
  ? this.Cs.nu("phone", t)
133
- : (N.error(`Cannot set phone number - "${t}" did not pass validation.`),
133
+ : (E.error(`Cannot set phone number - "${t}" did not pass validation.`),
134
134
  !1))
135
135
  );
136
136
  }
137
137
  setLastKnownLocation(t, e, r, s, n) {
138
138
  return null == t || null == e
139
- ? (N.error(
139
+ ? (E.error(
140
140
  "Cannot set last-known location - latitude and longitude are required.",
141
141
  ),
142
142
  !1)
@@ -150,49 +150,48 @@ export default class User {
150
150
  (null != r && isNaN(r)) ||
151
151
  (null != s && isNaN(s)) ||
152
152
  (null != n && isNaN(n))
153
- ? (N.error(
153
+ ? (E.error(
154
154
  "Cannot set last-known location - all supplied parameters must be numeric.",
155
155
  ),
156
156
  !1)
157
157
  : t > 90 || t < -90 || e > 180 || e < -180
158
- ? (N.error(
158
+ ? (E.error(
159
159
  "Cannot set last-known location - latitude and longitude are bounded by ±90 and ±180 respectively.",
160
160
  ),
161
161
  !1)
162
162
  : (null != r && r < 0) || (null != n && n < 0)
163
- ? (N.error(
163
+ ? (E.error(
164
164
  "Cannot set last-known location - accuracy and altitudeAccuracy may not be negative.",
165
165
  ),
166
166
  !1)
167
- : this.Fi.setLastKnownLocation(this.Cs.getUserId(), t, e, s, r, n)
168
- .tt);
167
+ : this.Cn.setLastKnownLocation(this.Cs.getUserId(), t, e, s, r, n).W);
169
168
  }
170
169
  setCustomUserAttribute(t, e, r) {
171
- if (!At(t)) return !1;
170
+ if (!Ut(t)) return !1;
172
171
  const s = (e) => {
173
- const [r] = rt(
172
+ const [r] = nt(
174
173
  e,
175
- Dt,
174
+ Ft,
176
175
  "attribute value",
177
176
  `set custom user attribute "${t}"`,
178
177
  "custom user attribute",
179
178
  );
180
179
  return r;
181
180
  };
182
- if (z(e)) {
181
+ if (D(e)) {
183
182
  const [r, n] = St(t, e);
184
183
  if (!r && !n && 0 !== e.length) return !1;
185
- if (r || 0 === e.length) return this.Fi.Ln(d.$n, t, e).tt;
184
+ if (r || 0 === e.length) return this.Cn.Ln(m.$n, t, e).W;
186
185
  for (const t of e) if (!s(t)) return !1;
187
- } else if (yt(e)) {
186
+ } else if (It(e)) {
188
187
  if (!s(e)) return !1;
189
- if (r) return this.Fi.Ln(d.Bn, t, e).tt;
188
+ if (r) return this.Cn.Ln(m.Bn, t, e).W;
190
189
  } else {
191
- if (!(void 0 !== e && Ut(e))) return !1;
190
+ if (!(void 0 !== e && Dt(e))) return !1;
192
191
  if (
193
- (Nt(e) && (e = Ft(e)),
192
+ (Nt(e) && (e = Lt(e)),
194
193
  "string" == typeof e &&
195
- !nt(
194
+ !mt(
196
195
  e,
197
196
  `set custom user attribute "${t}"`,
198
197
  "the element in the given array",
@@ -204,38 +203,38 @@ export default class User {
204
203
  }
205
204
  addToCustomAttributeArray(t, e) {
206
205
  return (
207
- !!nt(t, "add to custom user attribute array", "the given key") &&
206
+ !!mt(t, "add to custom user attribute array", "the given key") &&
208
207
  !(
209
208
  null != e &&
210
- !nt(e, "add to custom user attribute array", "the given value")
209
+ !mt(e, "add to custom user attribute array", "the given value")
211
210
  ) &&
212
- this.Fi.Ln(d.On, t, e).tt
211
+ this.Cn.Ln(m.Rn, t, e).W
213
212
  );
214
213
  }
215
214
  removeFromCustomAttributeArray(t, e) {
216
215
  return (
217
- !!nt(t, "remove from custom user attribute array", "the given key") &&
216
+ !!mt(t, "remove from custom user attribute array", "the given key") &&
218
217
  !(
219
218
  null != e &&
220
- !nt(e, "remove from custom user attribute array", "the given value")
219
+ !mt(e, "remove from custom user attribute array", "the given value")
221
220
  ) &&
222
- this.Fi.Ln(d.Gn, t, e).tt
221
+ this.Cn.Ln(m.On, t, e).W
223
222
  );
224
223
  }
225
224
  incrementCustomUserAttribute(t, e) {
226
- if (!nt(t, "increment custom user attribute", "the given key")) return !1;
225
+ if (!mt(t, "increment custom user attribute", "the given key")) return !1;
227
226
  null == e && (e = 1);
228
227
  const r = parseInt(e.toString());
229
228
  return isNaN(r) || r !== parseFloat(e.toString())
230
- ? (N.error(
229
+ ? (E.error(
231
230
  `Cannot increment custom user attribute because the given incrementValue "${e}" is not an integer.`,
232
231
  ),
233
232
  !1)
234
- : this.Fi.Ln(d.Hn, t, r).tt;
233
+ : this.Cn.Ln(m.Gn, t, r).W;
235
234
  }
236
235
  setCustomLocationAttribute(t, e, r) {
237
236
  return (
238
- !!nt(t, "set custom location attribute", "the given key") &&
237
+ !!mt(t, "set custom location attribute", "the given key") &&
239
238
  ((null !== e || null !== r) &&
240
239
  ((e = null != e ? parseFloat(e.toString()) : null),
241
240
  (r = null != r ? parseFloat(r.toString()) : null),
@@ -243,11 +242,11 @@ export default class User {
243
242
  (null != e && null == r) ||
244
243
  (null != e && (isNaN(e) || e > 90 || e < -90)) ||
245
244
  (null != r && (isNaN(r) || r > 180 || r < -180)))
246
- ? (N.error(
245
+ ? (E.error(
247
246
  "Received invalid values for latitude and/or longitude. Latitude and longitude are bounded by ±90 and ±180 respectively, or must both be null for removal.",
248
247
  ),
249
248
  !1)
250
- : this.Fi.Kn(t, e, r).tt)
249
+ : this.Cn.Hn(t, e, r).W)
251
250
  );
252
251
  }
253
252
  addToSubscriptionGroup(t) {
@@ -257,11 +256,11 @@ export default class User {
257
256
  "subscription group ID",
258
257
  !1,
259
258
  ) || t.length <= 0
260
- ? (N.error(
259
+ ? (E.error(
261
260
  "addToSubscriptionGroup requires a non-empty subscription group ID",
262
261
  ),
263
262
  !1)
264
- : this.Fi.Mn(t, User.Yn.SUBSCRIBED).tt;
263
+ : this.Cn.Kn(t, User.Mn.SUBSCRIBED).W;
265
264
  }
266
265
  removeFromSubscriptionGroup(t) {
267
266
  return !ir(
@@ -270,28 +269,28 @@ export default class User {
270
269
  "subscription group ID",
271
270
  !1,
272
271
  ) || t.length <= 0
273
- ? (N.error(
272
+ ? (E.error(
274
273
  "removeFromSubscriptionGroup requires a non-empty subscription group ID",
275
274
  ),
276
275
  !1)
277
- : this.Fi.Mn(t, User.Yn.UNSUBSCRIBED).tt;
276
+ : this.Cn.Kn(t, User.Mn.UNSUBSCRIBED).W;
278
277
  }
279
278
  setLineId(t) {
280
279
  return ir(t, "set LINE user ID", "the ID", !0) &&
281
280
  0 !== (null == t ? void 0 : t.length)
282
- ? t && t.length > User.Jn
283
- ? (N.error(
284
- `Rejected LINE user ID ${t} because it is longer than ${User.Jn} characters.`,
281
+ ? t && t.length > User.Yn
282
+ ? (E.error(
283
+ `Rejected LINE user ID ${t} because it is longer than ${User.Yn} characters.`,
285
284
  ),
286
285
  !1)
287
286
  : this.Cs.nu("native_line_id", t)
288
- : (N.error("setLineId requires a non-empty ID"), !1);
287
+ : (E.error("setLineId requires a non-empty ID"), !1);
289
288
  }
290
- An(t, e, r, s, n) {
291
- this.Cs.An(t, e, r, s, n), this.Fi.Qn();
289
+ Pn(t, e, r, s, n) {
290
+ this.Cs.Pn(t, e, r, s, n), this.Cn.zn();
292
291
  }
293
- xn(t) {
294
- this.Cs.xn(t);
292
+ Sn(t) {
293
+ this.Cs.Sn(t);
295
294
  }
296
295
  }
297
296
  (User.Genders = {
@@ -308,8 +307,8 @@ export default class User {
308
307
  UNSUBSCRIBED: "unsubscribed",
309
308
  }),
310
309
  (User.Fn = /^[0-9 .\\(\\)\\+\\-]+$/),
311
- (User.Yn = { SUBSCRIBED: "subscribed", UNSUBSCRIBED: "unsubscribed" }),
312
- (User.Xn = "user_id"),
310
+ (User.Mn = { SUBSCRIBED: "subscribed", UNSUBSCRIBED: "unsubscribed" }),
311
+ (User.Jn = "user_id"),
313
312
  (User.lu = "custom"),
314
- (User.ur = 997),
315
- (User.Jn = 33);
313
+ (User.mr = 997),
314
+ (User.Yn = 33);
@@ -1,6 +1,6 @@
1
1
  export default class t {
2
2
  constructor() {}
3
- U(a) {}
3
+ N(a) {}
4
4
  changeUser(a = !1) {}
5
5
  clearData(a = !1) {}
6
6
  }
@@ -0,0 +1,211 @@
1
+ import {
2
+ getCardId as xt,
3
+ markCardAsRead as Rt,
4
+ } from "../Card/display/card-display.js";
5
+ import { bottomIsInView as x, topIsInView as g } from "../util/dom-utils.js";
6
+ import { Card, ControlCard } from "../Card/index.js";
7
+ import { cardToHtml as Ht } from "../Card/display/card-display.js";
8
+ import { isArray as D } from "../util/code-utils.js";
9
+ import { KeyCodes as ie } from "../util/key-codes.js";
10
+ import fe from "../l10n/l10n-manager-factory.js";
11
+ import { removeSubscription } from "../Core/remove-subscription.js";
12
+ import { logger as E, Guid as P } from "../../shared-lib/index.js";
13
+ import { BRAZE_ACTION_URI_REGEX as to } from "../util/validation-utils.js";
14
+ import {
15
+ INELIGIBLE_BRAZE_ACTION_URL_ERROR_TYPES as vt,
16
+ ineligibleBrazeActionURLErrorMessage as jt,
17
+ getDecodedBrazeAction as eo,
18
+ containsUnknownBrazeAction as dt,
19
+ } from "../util/braze-actions.js";
20
+ import {
21
+ bottomHadImpression as kt,
22
+ impressOnBottom as d,
23
+ impressOnTop as j,
24
+ topHadImpression as qt,
25
+ } from "./detect-impression.js";
26
+ import { SUBSCRIPTION_ID_DATA_ATTRIBUTE as f } from "./constants.js";
27
+ import ContentCards from "../ContentCards/content-cards.js";
28
+ export const LAST_REQUESTED_REFRESH_DATA_ATTRIBUTE =
29
+ "data-last-requested-refresh";
30
+ export const SCROLL_LISTENER_ID = "data-listener-id";
31
+ export const scrollListeners = {};
32
+ export function destroyContentCardsHtml(t) {
33
+ t &&
34
+ ((t.className = t.className.replace("ab-show", "ab-hide")),
35
+ setTimeout(() => {
36
+ t && t.parentNode && t.parentNode.removeChild(t);
37
+ }, ContentCards.cr));
38
+ const e = t.getAttribute(f);
39
+ null != e && removeSubscription(e);
40
+ const n = t.getAttribute("data-listener-id");
41
+ null != n &&
42
+ (window.removeEventListener("scroll", scrollListeners[n]),
43
+ delete scrollListeners[n]);
44
+ }
45
+ export function generateContentCardsUI(t, e) {
46
+ const n = fe.ea(),
47
+ o = document.createElement("div");
48
+ if (
49
+ ((o.className = "ab-feed-body"),
50
+ o.setAttribute("aria-label", "Feed"),
51
+ o.setAttribute("role", "feed"),
52
+ null == t.lastUpdated)
53
+ ) {
54
+ const t = document.createElement("div");
55
+ t.className = "ab-no-cards-message";
56
+ const e = document.createElement("i");
57
+ (e.className = "fa fa-spinner fa-spin fa-4x ab-initial-spinner"),
58
+ t.appendChild(e),
59
+ o.appendChild(t);
60
+ } else {
61
+ let s = !1;
62
+ const r = (e) => t.nr(e);
63
+ for (const a of t.cards) {
64
+ const i = a instanceof ControlCard;
65
+ !i || t.ar()
66
+ ? (o.appendChild(Ht(a, r, e, n.So())), (s = s || !i))
67
+ : E.error(
68
+ "Received a control card for a legacy news feed. Control cards are only supported with content cards.",
69
+ );
70
+ }
71
+ if (!s) {
72
+ const t = document.createElement("div");
73
+ (t.className = "ab-no-cards-message"),
74
+ (t.innerHTML = n.get("NO_CARDS_MESSAGE") || ""),
75
+ t.setAttribute("role", "article"),
76
+ o.appendChild(t);
77
+ }
78
+ }
79
+ return o;
80
+ }
81
+ export function detectContentCardsImpressions(t, e) {
82
+ if (null != t && null != e) {
83
+ const n = [],
84
+ o = e.querySelectorAll(".ab-card");
85
+ t.Qn || (t.Qn = {});
86
+ for (let e = 0; e < o.length; e++) {
87
+ const s = xt(o[e]),
88
+ r = g(o[e]),
89
+ a = x(o[e]);
90
+ if (t.Qn[s]) {
91
+ r || a || Rt(o[e]);
92
+ continue;
93
+ }
94
+ let i = qt(o[e]),
95
+ l = kt(o[e]);
96
+ const c = i,
97
+ f = l;
98
+ if (
99
+ (!i && r && ((i = !0), j(o[e])), !l && a && ((l = !0), d(o[e])), i && l)
100
+ ) {
101
+ if (c && f) continue;
102
+ for (const e of t.cards)
103
+ if (e.id === s) {
104
+ (t.Qn[e.id] = !0), n.push(e);
105
+ break;
106
+ }
107
+ }
108
+ }
109
+ n.length > 0 && t.sr(n);
110
+ }
111
+ }
112
+ export function refreshContentCardsUI(t, e) {
113
+ if (null == t || null == e) return;
114
+ e.setAttribute("aria-busy", "true");
115
+ const n = e.querySelectorAll(".ab-refresh-button")[0];
116
+ null != n && (n.className += " fa-spin");
117
+ const o = new Date().valueOf().toString();
118
+ e.setAttribute("data-last-requested-refresh", o),
119
+ setTimeout(() => {
120
+ if (e.getAttribute("data-last-requested-refresh") === o) {
121
+ const t = e.querySelectorAll(".fa-spin");
122
+ for (let e = 0; e < t.length; e++)
123
+ t[e].className = t[e].className.replace(/fa-spin/g, "");
124
+ const n = e.querySelectorAll(".ab-initial-spinner")[0];
125
+ if (null != n) {
126
+ const t = document.createElement("span");
127
+ (t.innerHTML = fe.ea().get("FEED_TIMEOUT_MESSAGE") || ""),
128
+ null != n.parentNode &&
129
+ (n.parentNode.appendChild(t), n.parentNode.removeChild(n));
130
+ }
131
+ "true" === e.getAttribute("aria-busy") &&
132
+ e.setAttribute("aria-busy", "false");
133
+ }
134
+ }, ContentCards.Cr),
135
+ t.dr();
136
+ }
137
+ export function contentCardsToHtml(t, e, n) {
138
+ const o = document.createElement("div");
139
+ (o.className = "ab-feed ab-hide ab-effect-slide"),
140
+ o.setAttribute("role", "dialog"),
141
+ o.setAttribute("aria-label", "Feed"),
142
+ o.setAttribute("tabindex", "-1");
143
+ const s = document.createElement("div");
144
+ (s.className = "ab-feed-buttons-wrapper"),
145
+ s.setAttribute("role", "group"),
146
+ o.appendChild(s);
147
+ const r = document.createElement("i");
148
+ (r.className = "fa fa-times ab-close-button"),
149
+ r.setAttribute("aria-label", "Close Feed"),
150
+ r.setAttribute("tabindex", "0"),
151
+ r.setAttribute("role", "button");
152
+ const a = (t) => {
153
+ destroyContentCardsHtml(o), t.stopPropagation();
154
+ };
155
+ r.addEventListener("keydown", (t) => {
156
+ (t.keyCode !== ie.lo && t.keyCode !== ie.Ze) || a(t);
157
+ }),
158
+ (r.onclick = a);
159
+ const i = document.createElement("i");
160
+ (i.className = "fa fa-refresh ab-refresh-button"),
161
+ t && null == t.lastUpdated && (i.className += " fa-spin"),
162
+ i.setAttribute("aria-label", "Refresh Feed"),
163
+ i.setAttribute("tabindex", "0"),
164
+ i.setAttribute("role", "button");
165
+ const l = (e) => {
166
+ refreshContentCardsUI(t, o), e.stopPropagation();
167
+ };
168
+ i.addEventListener("keydown", (t) => {
169
+ (t.keyCode !== ie.lo && t.keyCode !== ie.Ze) || l(t);
170
+ }),
171
+ (i.onclick = l),
172
+ s.appendChild(i),
173
+ s.appendChild(r),
174
+ o.appendChild(generateContentCardsUI(t, e));
175
+ const d = () => detectContentCardsImpressions(t, o);
176
+ if ((o.addEventListener("scroll", d), !n)) {
177
+ window.addEventListener("scroll", d);
178
+ const t = P.oe();
179
+ (scrollListeners[t] = d), o.setAttribute("data-listener-id", t);
180
+ }
181
+ return o;
182
+ }
183
+ export function updateContentCards(t, e, n, o, s) {
184
+ if (!D(e)) return;
185
+ const r = [];
186
+ for (const t of e)
187
+ if (t instanceof Card) {
188
+ if (t.url && to.test(t.url)) {
189
+ const e = eo(t.url);
190
+ if (dt(e)) {
191
+ E.error(jt(vt.Li, "Content Card"));
192
+ continue;
193
+ }
194
+ }
195
+ r.push(t);
196
+ }
197
+ if (((t.cards = r), (t.lastUpdated = n), null != o))
198
+ if ((o.setAttribute("aria-busy", "false"), null == t.lastUpdated))
199
+ destroyContentCardsHtml(o);
200
+ else {
201
+ const e = o.querySelectorAll(".ab-feed-body")[0];
202
+ if (null != e) {
203
+ const n = generateContentCardsUI(t, s);
204
+ e.parentNode && e.parentNode.replaceChild(n, e),
205
+ detectContentCardsImpressions(t, n.parentNode);
206
+ }
207
+ }
208
+ }
209
+ export function registerContentCardsSubscriptionId(t, e) {
210
+ t && e.setAttribute(f, t);
211
+ }
@@ -1,23 +1,23 @@
1
- import { logger as N } from "../../shared-lib/index.js";
1
+ import { logger as E } from "../../shared-lib/index.js";
2
2
  import r from "../managers/braze-instance.js";
3
- import ve from "../models/braze-event.js";
4
- import F from "../models/request-result.js";
3
+ import ue from "../models/braze-event.js";
4
+ import H from "../models/request-result.js";
5
5
  const c = {
6
- ut: (e, o, t) => {
6
+ rt: (e, o, t) => {
7
7
  var n, s;
8
- const i = new F(),
9
- l = r.P();
8
+ const i = new H(),
9
+ l = r.u();
10
10
  if (!l)
11
11
  return (
12
- N.info(
12
+ E.info(
13
13
  `Not logging event with type "${e}" because the current session ID could not be found.`,
14
14
  ),
15
15
  i
16
16
  );
17
- const d = l.Qo();
17
+ const d = l.qo();
18
18
  return (
19
- i.$e.push(
20
- new ve(
19
+ i.ue.push(
20
+ new ue(
21
21
  t || (null === (n = r.ir()) || void 0 === n ? void 0 : n.getUserId()),
22
22
  e,
23
23
  new Date().valueOf(),
@@ -25,8 +25,8 @@ const c = {
25
25
  o,
26
26
  ),
27
27
  ),
28
- (i.tt =
29
- (null === (s = r.j()) || void 0 === s ? void 0 : s.Vo(i.$e)) || !1),
28
+ (i.W =
29
+ (null === (s = r.p()) || void 0 === s ? void 0 : s.Eo(i.ue)) || !1),
30
30
  i
31
31
  );
32
32
  },
@@ -0,0 +1,56 @@
1
+ import { logger as E } from "../../shared-lib/index.js";
2
+ export class PropertiesBase {
3
+ constructor(t) {
4
+ (this.properties = t), (this.properties = t || {});
5
+ }
6
+ To(t, r, e) {
7
+ const o = this.properties[t];
8
+ return null == o ? (this.No(t), null) : r(o) ? o.value : (this.Oo(e), null);
9
+ }
10
+ getStringProperty(t) {
11
+ return this.To(t, this.Fo, "string");
12
+ }
13
+ getNumberProperty(t) {
14
+ return this.To(t, this.Go, "number");
15
+ }
16
+ getBooleanProperty(t) {
17
+ return this.To(t, this.Ho, "boolean");
18
+ }
19
+ getImageProperty(t) {
20
+ return this.To(t, this.Ko, "image");
21
+ }
22
+ getJsonProperty(t) {
23
+ return this.To(t, this.Lo, "jsonobject");
24
+ }
25
+ getTimestampProperty(t) {
26
+ return this.To(t, this.Qo, "datetime");
27
+ }
28
+ Oo(t) {
29
+ E.info(`Property is not of type ${t}.`);
30
+ }
31
+ No(t) {
32
+ E.info(`${t} not found in properties.`);
33
+ }
34
+ Fo(t) {
35
+ return "string" === t.type && "string" == typeof t.value;
36
+ }
37
+ Go(t) {
38
+ return "number" === t.type && "number" == typeof t.value;
39
+ }
40
+ Ho(t) {
41
+ return "boolean" === t.type && "boolean" == typeof t.value;
42
+ }
43
+ Ko(t) {
44
+ return "image" === t.type && "string" == typeof t.value;
45
+ }
46
+ Lo(t) {
47
+ return (
48
+ "jsonobject" === t.type &&
49
+ "object" == typeof t.value &&
50
+ t.value.constructor == Object
51
+ );
52
+ }
53
+ Qo(t) {
54
+ return "datetime" === t.type && "number" == typeof t.value;
55
+ }
56
+ }
package/src/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  export * from "./Card/index.js";
2
2
  export * from "./ContentCards/index.js";
3
3
  export * from "./Core/index.js";
4
- export * from "./Feed/index.js";
5
4
  export * from "./InAppMessage/index.js";
6
5
  export * from "./Push/index.js";
7
6
  export * from "./User/index.js";
@@ -1,22 +1,22 @@
1
- import r, { OPTIONS as w } from "../managers/braze-instance.js";
1
+ import r, { OPTIONS as z } from "../managers/braze-instance.js";
2
2
  import ro from "../util/browser-detector.js";
3
3
  import lr from "./l10n-manager.js";
4
- const ge = {
5
- l: !1,
4
+ const fe = {
5
+ i: !1,
6
6
  aa: null,
7
7
  ea: () => {
8
- if ((ge.p(), !ge.aa)) {
8
+ if ((fe.t(), !fe.aa)) {
9
9
  let e = ro.language,
10
10
  t = !1;
11
- r.ee(w.Zn) && ((e = r.ee(w.Zn)), (t = !0)), (ge.aa = new lr(e, t));
11
+ r.ee(z.Xn) && ((e = r.ee(z.Xn)), (t = !0)), (fe.aa = new lr(e, t));
12
12
  }
13
- return ge.aa;
13
+ return fe.aa;
14
14
  },
15
- p: () => {
16
- ge.l || (r.h(ge), (ge.l = !0));
15
+ t: () => {
16
+ fe.i || (r.g(fe), (fe.i = !0));
17
17
  },
18
18
  destroy: () => {
19
- (ge.aa = null), (ge.l = !1);
19
+ (fe.aa = null), (fe.i = !1);
20
20
  },
21
21
  };
22
- export default ge;
22
+ export default fe;
@@ -1,28 +1,28 @@
1
- import { logger as N } from "../../shared-lib/index.js";
2
- import xt from "../common/translations.js";
1
+ import { logger as E } from "../../shared-lib/index.js";
2
+ import zt from "../common/translations.js";
3
3
  export default class lr {
4
4
  constructor(t, e = !1) {
5
5
  if (
6
6
  ((this.language = t),
7
7
  null != t && (t = t.toLowerCase()),
8
- null != t && null == xt[t])
8
+ null != t && null == zt[t])
9
9
  ) {
10
10
  const e = t.indexOf("-");
11
11
  e > 0 && (t = t.substring(0, e));
12
12
  }
13
- if (null == xt[t]) {
13
+ if (null == zt[t]) {
14
14
  const a =
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
- e ? N.error(a) : N.info(a), (t = "en");
18
+ e ? E.error(a) : E.info(a), (t = "en");
19
19
  }
20
20
  this.language = t;
21
21
  }
22
22
  get(t) {
23
- return xt[this.language][t];
23
+ return zt[this.language][t];
24
24
  }
25
- Oo() {
25
+ So() {
26
26
  switch (this.language) {
27
27
  case "ar":
28
28
  case "he":