@braze/web-sdk 4.6.3 → 4.7.1

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 (98) hide show
  1. package/index.d.ts +19 -14
  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 +17 -17
  9. package/src/Card/models/card.js +1 -1
  10. package/src/Core/handle-braze-action.js +40 -34
  11. package/src/Core/log-custom-event.js +2 -7
  12. package/src/Core/log-purchase.js +3 -3
  13. package/src/Core/wipe-data.js +2 -2
  14. package/src/FeatureFlags/feature-flag.js +33 -16
  15. package/src/FeatureFlags/feature-flags-provider.js +86 -75
  16. package/src/FeatureFlags/get-all-feature-flags.js +5 -5
  17. package/src/FeatureFlags/get-feature-flag.js +6 -6
  18. package/src/FeatureFlags/refresh-feature-flags.js +1 -1
  19. package/src/FeatureFlags/types.js +1 -0
  20. package/src/Feed/feed-provider.js +17 -17
  21. package/src/Feed/get-cached-feed.js +1 -1
  22. package/src/Feed/ui/show-feed.js +1 -1
  23. package/src/InAppMessage/display/html-message-to-html.js +135 -120
  24. package/src/InAppMessage/display/in-app-message-to-html.js +21 -21
  25. package/src/InAppMessage/display/modal-utils.js +6 -6
  26. package/src/InAppMessage/in-app-message-factory.js +3 -3
  27. package/src/InAppMessage/in-app-message-manager-factory.js +3 -3
  28. package/src/InAppMessage/in-app-message-manager.js +65 -65
  29. package/src/InAppMessage/log-in-app-message-button-click.js +4 -4
  30. package/src/InAppMessage/log-in-app-message-click.js +4 -4
  31. package/src/InAppMessage/log-in-app-message-html-click.js +3 -3
  32. package/src/InAppMessage/log-in-app-message-impression.js +3 -3
  33. package/src/InAppMessage/models/full-screen-message.js +1 -1
  34. package/src/InAppMessage/models/html-message.js +1 -1
  35. package/src/InAppMessage/models/in-app-message-button.js +4 -4
  36. package/src/InAppMessage/models/in-app-message.js +80 -80
  37. package/src/InAppMessage/models/modal-message.js +2 -2
  38. package/src/InAppMessage/models/slide-up-message.js +8 -8
  39. package/src/InAppMessage/models/templated-in-app-message.js +4 -4
  40. package/src/InAppMessage/subscribe-to-in-app-message.js +1 -1
  41. package/src/InAppMessage/ui/automatically-show-in-app-messages.js +3 -3
  42. package/src/InAppMessage/ui/show-in-app-message.js +20 -20
  43. package/src/Push/push-manager.js +216 -209
  44. package/src/Push/utils/push-utils.js +4 -4
  45. package/src/User/user-manager.js +11 -8
  46. package/src/User/user.js +52 -41
  47. package/src/common/base-feed.js +1 -1
  48. package/src/common/base-provider.js +1 -1
  49. package/src/common/constants.js +2 -0
  50. package/src/common/feed-display.js +6 -6
  51. package/src/l10n/l10n-manager-factory.js +1 -1
  52. package/src/managers/auth-manager.js +24 -24
  53. package/src/managers/braze-instance.js +122 -122
  54. package/src/managers/device-manager.js +11 -11
  55. package/src/managers/network-manager.js +63 -54
  56. package/src/managers/server-config-manager.js +20 -20
  57. package/src/managers/session-manager.js +29 -29
  58. package/src/managers/storage-manager-factory.js +4 -4
  59. package/src/managers/storage-manager.js +104 -104
  60. package/src/managers/subscription-manager.js +6 -6
  61. package/src/models/backend-errors.js +5 -5
  62. package/src/models/braze-event.js +7 -7
  63. package/src/models/device.js +1 -1
  64. package/src/models/identifier.js +6 -6
  65. package/src/models/push-token.js +3 -3
  66. package/src/models/server-config.js +15 -15
  67. package/src/request-controller.js +92 -88
  68. package/src/triggers/models/custom-event-data.js +4 -4
  69. package/src/triggers/models/custom-event-property-data.js +9 -9
  70. package/src/triggers/models/filter-set.js +9 -9
  71. package/src/triggers/models/filter.js +63 -63
  72. package/src/triggers/models/in-app-message-click-data.js +5 -5
  73. package/src/triggers/models/purchase-data.js +3 -3
  74. package/src/triggers/models/purchase-property-data.js +9 -9
  75. package/src/triggers/models/push-click-data.js +5 -5
  76. package/src/triggers/models/trigger-condition.js +48 -48
  77. package/src/triggers/models/trigger-events.js +1 -1
  78. package/src/triggers/models/trigger.js +29 -29
  79. package/src/triggers/triggers-provider-factory.js +2 -2
  80. package/src/triggers/triggers-provider.js +87 -89
  81. package/src/ui/js/attach-css.js +1 -1
  82. package/src/ui/js/feed-css.js +4 -4
  83. package/src/ui/js/iam-css.js +4 -4
  84. package/src/ui/js/load-font-awesome.js +1 -1
  85. package/src/util/base-device-parser.js +2 -2
  86. package/src/util/braze-actions.js +8 -8
  87. package/src/util/browser-detector.js +8 -8
  88. package/src/util/client-hints-parser.js +3 -3
  89. package/src/util/code-utils.js +10 -3
  90. package/src/util/component-utils.js +1 -1
  91. package/src/util/date-utils.js +2 -2
  92. package/src/util/device-constants.js +1 -1
  93. package/src/util/dom-utils.js +9 -9
  94. package/src/util/key-codes.js +1 -1
  95. package/src/util/net.js +3 -3
  96. package/src/util/user-agent-parser.js +4 -4
  97. package/src/util/validation-utils.js +155 -74
  98. package/src/util/window-utils.js +1 -1
package/src/User/user.js CHANGED
@@ -1,18 +1,24 @@
1
1
  import {
2
2
  isArray as p,
3
- isDate as yt,
3
+ isDate as Nt,
4
+ isObject as yt,
4
5
  validateValueIsFromEnum as F
5
6
  } from "../util/code-utils.js";
6
7
  import r from "../../shared-lib/braze-shared-lib.js";
7
- import { toValidBackendTimeString as Nt } from "../util/date-utils.js";
8
8
  import {
9
9
  isValidEmail as Ct,
10
+ validateCustomAttributeArrayType as It,
11
+ validateCustomAttributeKey as St,
12
+ validateCustomProperties as X,
10
13
  validateCustomString as Y,
14
+ validatePropertyType as At,
11
15
  validateStandardString as R
12
16
  } from "../util/validation-utils.js";
17
+ import { SET_CUSTOM_USER_ATTRIBUTE_STRING as Ut } from "../common/constants.js";
18
+ import { toValidBackendTimeString as Ft } from "../util/date-utils.js";
13
19
  export default class User {
14
20
  constructor(t, e) {
15
- (this.v = t), (this.si = e);
21
+ (this.v = t), (this.Ci = e);
16
22
  }
17
23
  getUserId(t) {
18
24
  null == t &&
@@ -26,7 +32,7 @@ export default class User {
26
32
  ? (r.D.error("addAlias requires a non-empty alias"), !1)
27
33
  : !R(e, "add alias", "the label", !1) || e.length <= 0
28
34
  ? (r.D.error("addAlias requires a non-empty label"), !1)
29
- : this.si.Nn(t, e).S;
35
+ : this.Ci.Nn(t, e).S;
30
36
  }
31
37
  setFirstName(t) {
32
38
  return (
@@ -148,35 +154,40 @@ export default class User {
148
154
  "Cannot set last-known location - accuracy and altitudeAccuracy may not be negative."
149
155
  ),
150
156
  !1)
151
- : this.si.setLastKnownLocation(this.v.getUserId(), t, e, i, s, n).S);
157
+ : this.Ci.setLastKnownLocation(this.v.getUserId(), t, e, i, s, n).S);
152
158
  }
153
- setCustomUserAttribute(t, e) {
154
- if (!Y(t, "set custom user attribute", "the given key")) return !1;
155
- const s = typeof e,
156
- i = yt(e),
157
- n = p(e);
158
- if (
159
- "number" !== s &&
160
- "boolean" !== s &&
161
- !i &&
162
- !n &&
163
- null !== e &&
164
- !Y(e, `set custom user attribute "${t}"`, "the given value")
165
- )
166
- return !1;
167
- if ((i && (e = Nt(e)), n)) {
168
- for (let s = 0; s < e.length; s++) {
169
- const r = e[s];
170
- if (
159
+ setCustomUserAttribute(t, e, s) {
160
+ if (!St(t)) return !1;
161
+ const i = e => {
162
+ const [r] = X(
163
+ e,
164
+ Ut,
165
+ "attribute value",
166
+ `set custom user attribute "${t}"`,
167
+ "custom user attribute"
168
+ );
169
+ return r;
170
+ };
171
+ if (p(e)) {
172
+ const [s, n] = It(t, e);
173
+ if (!s && !n && 0 !== e.length) return !1;
174
+ if (s || 0 === e.length) return this.Ci.In(r.A.Sn, t, e).S;
175
+ for (const t of e) if (!i(t)) return !1;
176
+ } else if (yt(e)) {
177
+ if (!i(e)) return !1;
178
+ if (s) return this.Ci.In(r.A.An, t, e).S;
179
+ } else {
180
+ if (!(void 0 !== e && At(e))) return !1;
181
+ if (
182
+ (Nt(e) && (e = Ft(e)),
183
+ "string" == typeof e &&
171
184
  !Y(
172
- r,
185
+ e,
173
186
  `set custom user attribute "${t}"`,
174
187
  "the element in the given array"
175
- )
176
- )
177
- return !1;
178
- }
179
- return this.si.In(r.A.Un, t, e).S;
188
+ ))
189
+ )
190
+ return !1;
180
191
  }
181
192
  return this.v.setCustomUserAttribute(t, e);
182
193
  }
@@ -187,7 +198,7 @@ export default class User {
187
198
  null != e &&
188
199
  !Y(e, "add to custom user attribute array", "the given value")
189
200
  ) &&
190
- this.si.In(r.A.En, t, e).S
201
+ this.Ci.In(r.A.Un, t, e).S
191
202
  );
192
203
  }
193
204
  removeFromCustomAttributeArray(t, e) {
@@ -197,7 +208,7 @@ export default class User {
197
208
  null != e &&
198
209
  !Y(e, "remove from custom user attribute array", "the given value")
199
210
  ) &&
200
- this.si.In(r.A.Fn, t, e).S
211
+ this.Ci.In(r.A.En, t, e).S
201
212
  );
202
213
  }
203
214
  incrementCustomUserAttribute(t, e) {
@@ -209,7 +220,7 @@ export default class User {
209
220
  `Cannot increment custom user attribute because the given incrementValue "${e}" is not an integer.`
210
221
  ),
211
222
  !1)
212
- : this.si.In(r.A.Tn, t, s).S;
223
+ : this.Ci.In(r.A.Fn, t, s).S;
213
224
  }
214
225
  setCustomLocationAttribute(t, e, s) {
215
226
  return (
@@ -222,7 +233,7 @@ export default class User {
222
233
  "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."
223
234
  ),
224
235
  !1)
225
- : this.si.$n(t, e, s).S)
236
+ : this.Ci.Tn(t, e, s).S)
226
237
  );
227
238
  }
228
239
  addToSubscriptionGroup(t) {
@@ -236,7 +247,7 @@ export default class User {
236
247
  "addToSubscriptionGroup requires a non-empty subscription group ID"
237
248
  ),
238
249
  !1)
239
- : this.si.Bn(t, User.Ln.SUBSCRIBED).S;
250
+ : this.Ci.$n(t, User._n.SUBSCRIBED).S;
240
251
  }
241
252
  removeFromSubscriptionGroup(t) {
242
253
  return !R(
@@ -249,13 +260,13 @@ export default class User {
249
260
  "removeFromSubscriptionGroup requires a non-empty subscription group ID"
250
261
  ),
251
262
  !1)
252
- : this.si.Bn(t, User.Ln.UNSUBSCRIBED).S;
263
+ : this.Ci.$n(t, User._n.UNSUBSCRIBED).S;
253
264
  }
254
- Zr(t, e, s, r, i) {
255
- this.v.Zr(t, e, s, r, i), this.si.Rn();
265
+ on(t, e, r, s, i) {
266
+ this.v.on(t, e, r, s, i), this.Ci.Bn();
256
267
  }
257
- fn(t) {
258
- this.v.fn(t);
268
+ an(t) {
269
+ this.v.an(t);
259
270
  }
260
271
  }
261
272
  (User.Cn = /^[0-9 .\\(\\)\\+\\-]+$/),
@@ -272,7 +283,7 @@ export default class User {
272
283
  SUBSCRIBED: "subscribed",
273
284
  UNSUBSCRIBED: "unsubscribed"
274
285
  }),
275
- (User.Ln = { SUBSCRIBED: "subscribed", UNSUBSCRIBED: "unsubscribed" }),
276
- (User.On = "user_id"),
286
+ (User._n = { SUBSCRIBED: "subscribed", UNSUBSCRIBED: "unsubscribed" }),
287
+ (User.Dn = "user_id"),
277
288
  (User.lu = "custom"),
278
289
  (User.ee = 997);
@@ -22,4 +22,4 @@ export default class x {
22
22
  throw new Error("Must be implemented in subclass");
23
23
  }
24
24
  }
25
- (x.ur = 6e4), (x.Zi = 500), (x.uo = 1e4);
25
+ (x.ur = 6e4), (x.uh = 500), (x.uo = 1e4);
@@ -1,6 +1,6 @@
1
1
  export default class y {
2
2
  constructor() {}
3
- Rs() {}
3
+ Rs(a) {}
4
4
  changeUser(a) {}
5
5
  clearData() {}
6
6
  }
@@ -3,3 +3,5 @@ export const MUST_BE_IN_APP_MESSAGE_WARNING =
3
3
  "inAppMessage must be an InAppMessage object";
4
4
  export const MUST_BE_CARD_WARNING_SUFFIX = "must be a Card object";
5
5
  export const FEED_ANIMATION_DURATION = 500;
6
+ export const LOG_CUSTOM_EVENT_STRING = "logCustomEvent";
7
+ export const SET_CUSTOM_USER_ATTRIBUTE_STRING = "setCustomUserAttribute";
@@ -15,11 +15,11 @@ import { KeyCodes as at } from "../util/key-codes.js";
15
15
  import Ee from "../l10n/l10n-manager-factory.js";
16
16
  import { removeSubscription } from "../Core/remove-subscription.js";
17
17
  import r from "../../shared-lib/braze-shared-lib.js";
18
- import { BRAZE_ACTION_URI_REGEX as O } from "../util/validation-utils.js";
18
+ import { BRAZE_ACTION_URI_REGEX as J } from "../util/validation-utils.js";
19
19
  import {
20
20
  INELIGIBLE_BRAZE_ACTION_URL_ERROR_TYPES as ft,
21
21
  ineligibleBrazeActionURLErrorMessage as ht,
22
- getDecodedBrazeAction as J,
22
+ getDecodedBrazeAction as _,
23
23
  containsUnknownBrazeAction as gt
24
24
  } from "../util/braze-actions.js";
25
25
  export const LAST_REQUESTED_REFRESH_DATA_ATTRIBUTE =
@@ -30,7 +30,7 @@ export function destroyFeedHtml(e) {
30
30
  ((e.className = e.className.replace("ab-show", "ab-hide")),
31
31
  setTimeout(() => {
32
32
  e && e.parentNode && e.parentNode.removeChild(e);
33
- }, x.Zi));
33
+ }, x.uh));
34
34
  const t = e.getAttribute("data-update-subscription-id");
35
35
  null != t && removeSubscription(t);
36
36
  }
@@ -175,10 +175,10 @@ export function updateFeedCards(e, t, o, s, n) {
175
175
  const a = [];
176
176
  for (const e of t)
177
177
  if (e instanceof Card) {
178
- if (e.url && O.test(e.url)) {
179
- let t = J(e.url);
178
+ if (e.url && J.test(e.url)) {
179
+ let t = _(e.url);
180
180
  if (gt(t)) {
181
- r.D.error(ht(ft.Di, "Content Card"));
181
+ r.D.error(ht(ft.Ei, "Content Card"));
182
182
  continue;
183
183
  }
184
184
  }
@@ -8,7 +8,7 @@ const Ee = {
8
8
  if ((Ee.o(), !Ee.i)) {
9
9
  let r = ot.language,
10
10
  t = !1;
11
- e.nn(T.zn) && ((r = e.nn(T.zn)), (t = !0)), (Ee.i = new nr(r, t));
11
+ e.nn(T.jn) && ((r = e.nn(T.jn)), (t = !0)), (Ee.i = new nr(r, t));
12
12
  }
13
13
  return Ee.i;
14
14
  },
@@ -1,48 +1,48 @@
1
1
  import { STORAGE_KEYS as o } from "./storage-manager.js";
2
2
  import u from "./subscription-manager.js";
3
3
  import r from "../../shared-lib/braze-shared-lib.js";
4
- export default class St {
4
+ export default class kt {
5
5
  constructor(t, i, s) {
6
6
  (this.h = t),
7
7
  (this.xn = i || !1),
8
- (this.qn = s),
9
- (this.Gn = new u()),
10
- (this.Hn = 0),
11
- (this.Jn = 1);
8
+ (this.zn = s),
9
+ (this.qn = new u()),
10
+ (this.Gn = 0),
11
+ (this.Hn = 1);
12
12
  }
13
- Kn() {
13
+ Jn() {
14
14
  return this.xn;
15
15
  }
16
- Mn() {
17
- return this.h.I(o.q.Qn);
16
+ Kn() {
17
+ return this.h.I(o.q.Ln);
18
18
  }
19
19
  setSdkAuthenticationSignature(t) {
20
- const i = this.Mn();
21
- this.h.B(o.q.Qn, t);
20
+ const i = this.Kn();
21
+ this.h.B(o.q.Ln, t);
22
22
  const s = r.xt.Ft;
23
- new r.qt(s, r.D).setItem(s.$t.Vn, this.Jn, t), i !== t && this.Qs();
23
+ new r.qt(s, r.D).setItem(s.$t.Mn, this.Hn, t), i !== t && this.Qs();
24
24
  }
25
- Wn() {
26
- this.h.Xs(o.q.Qn);
25
+ On() {
26
+ this.h.Xs(o.q.Ln);
27
27
  const t = r.xt.Ft;
28
- new r.qt(t, r.D).br(t.$t.Vn, this.Jn);
28
+ new r.qt(t, r.D).br(t.$t.Mn, this.Hn);
29
29
  }
30
30
  subscribeToSdkAuthenticationFailures(t) {
31
- return this.qn.ut(t);
31
+ return this.zn.ut(t);
32
32
  }
33
- Xn(t) {
34
- this.qn.St(t);
33
+ Qn(t) {
34
+ this.zn.St(t);
35
35
  }
36
- Yn() {
37
- this.Gn.removeAllSubscriptions();
36
+ Rn() {
37
+ this.qn.removeAllSubscriptions();
38
38
  }
39
- Zn() {
40
- this.Hn += 1;
39
+ Vn() {
40
+ this.Gn += 1;
41
41
  }
42
- au() {
43
- return this.Hn;
42
+ Wn() {
43
+ return this.Gn;
44
44
  }
45
45
  Qs() {
46
- this.Hn = 0;
46
+ this.Gn = 0;
47
47
  }
48
48
  }