@braze/web-sdk 4.8.3 → 4.10.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 (153) hide show
  1. package/index.d.ts +2247 -2071
  2. package/package.json +1 -1
  3. package/shared-lib/braze-shared-lib.js +7 -7
  4. package/shared-lib/encoding-utils.js +4 -4
  5. package/shared-lib/event-types.js +23 -22
  6. package/shared-lib/guid.js +7 -7
  7. package/shared-lib/indexed-db-adapter.js +172 -135
  8. package/shared-lib/logger.js +26 -26
  9. package/shared-lib/supported-options.js +14 -13
  10. package/shared-lib/types.js +1 -0
  11. package/src/Card/card-manager-factory.js +1 -1
  12. package/src/Card/card-manager.js +2 -2
  13. package/src/Card/display/card-display.js +5 -4
  14. package/src/Card/models/banner.js +10 -10
  15. package/src/Card/models/captioned-image.js +7 -7
  16. package/src/Card/models/card.js +37 -36
  17. package/src/Card/models/classic-card.js +7 -7
  18. package/src/Card/models/control-card.js +3 -3
  19. package/src/Card/models/image-only.js +32 -0
  20. package/src/Card/models/index.js +1 -0
  21. package/src/Card/util/card-factory.js +16 -16
  22. package/src/ContentCards/content-cards-provider-factory.js +1 -1
  23. package/src/ContentCards/content-cards-provider.js +102 -102
  24. package/src/ContentCards/get-cached-content-cards.js +1 -1
  25. package/src/ContentCards/request-content-cards-refresh.js +1 -1
  26. package/src/ContentCards/subscribe-to-content-cards-updates.js +4 -4
  27. package/src/ContentCards/ui/show-content-cards.js +15 -12
  28. package/src/Core/add-sdk-metadata.js +2 -2
  29. package/src/Core/braze-sdk-metadata.js +1 -1
  30. package/src/Core/change-user.js +1 -1
  31. package/src/Core/device-properties.js +1 -1
  32. package/src/Core/disable-sdk.js +10 -7
  33. package/src/Core/enable-sdk.js +5 -2
  34. package/src/Core/get-device-id.js +9 -7
  35. package/src/Core/get-user.js +1 -1
  36. package/src/Core/handle-braze-action.js +14 -14
  37. package/src/Core/is-disabled.js +1 -1
  38. package/src/Core/log-custom-event.js +4 -4
  39. package/src/Core/log-purchase.js +9 -9
  40. package/src/Core/open-session.js +10 -10
  41. package/src/FeatureFlags/feature-flag-factory.js +5 -3
  42. package/src/FeatureFlags/feature-flag.js +17 -14
  43. package/src/FeatureFlags/feature-flags-provider-factory.js +1 -1
  44. package/src/FeatureFlags/feature-flags-provider.js +56 -43
  45. package/src/FeatureFlags/get-all-feature-flags.js +2 -2
  46. package/src/FeatureFlags/get-feature-flag.js +2 -2
  47. package/src/FeatureFlags/index.js +1 -0
  48. package/src/FeatureFlags/log-feature-flag-impression.js +23 -0
  49. package/src/FeatureFlags/subscribe-to-feature-flags-updates.js +1 -1
  50. package/src/Feed/feed-provider-factory.js +1 -1
  51. package/src/Feed/feed-provider.js +20 -20
  52. package/src/Feed/get-cached-feed.js +1 -1
  53. package/src/Feed/log-feed-displayed.js +1 -1
  54. package/src/Feed/request-feed-refresh.js +1 -1
  55. package/src/Feed/subscribe-to-feed-updates.js +1 -1
  56. package/src/Feed/ui/show-feed.js +13 -10
  57. package/src/InAppMessage/defer-in-app-message.js +13 -0
  58. package/src/InAppMessage/display/get-animation-effect.js +1 -1
  59. package/src/InAppMessage/display/html-message-to-html.js +47 -47
  60. package/src/InAppMessage/display/in-app-message-to-html.js +92 -91
  61. package/src/InAppMessage/display/modal-utils.js +16 -16
  62. package/src/InAppMessage/get-deferred-in-app-message.js +5 -0
  63. package/src/InAppMessage/in-app-message-factory.js +77 -57
  64. package/src/InAppMessage/in-app-message-manager-factory.js +6 -6
  65. package/src/InAppMessage/in-app-message-manager.js +121 -82
  66. package/src/InAppMessage/index.js +2 -0
  67. package/src/InAppMessage/log-in-app-message-button-click.js +17 -9
  68. package/src/InAppMessage/log-in-app-message-click.js +4 -4
  69. package/src/InAppMessage/log-in-app-message-html-click.js +6 -6
  70. package/src/InAppMessage/log-in-app-message-impression.js +3 -3
  71. package/src/InAppMessage/models/full-screen-message.js +65 -29
  72. package/src/InAppMessage/models/html-message.js +32 -13
  73. package/src/InAppMessage/models/in-app-message-button.js +7 -7
  74. package/src/InAppMessage/models/in-app-message.js +203 -134
  75. package/src/InAppMessage/models/modal-message.js +64 -29
  76. package/src/InAppMessage/models/slide-up-message.js +52 -24
  77. package/src/InAppMessage/models/templated-in-app-message.js +8 -8
  78. package/src/InAppMessage/subscribe-to-in-app-message.js +2 -2
  79. package/src/InAppMessage/ui/automatically-show-in-app-messages.js +6 -6
  80. package/src/InAppMessage/ui/show-in-app-message.js +49 -47
  81. package/src/InAppMessage/utils/in-app-message-utils.js +1 -1
  82. package/src/Push/is-push-blocked.js +2 -2
  83. package/src/Push/is-push-permission-granted.js +2 -2
  84. package/src/Push/is-push-supported.js +2 -2
  85. package/src/Push/push-manager-factory.js +19 -19
  86. package/src/Push/push-manager.js +131 -131
  87. package/src/Push/request-push-permission.js +2 -2
  88. package/src/Push/unregister-push.js +2 -2
  89. package/src/Push/utils/push-utils.js +12 -10
  90. package/src/User/user-manager.js +4 -4
  91. package/src/User/user.js +63 -62
  92. package/src/common/base-feed.js +1 -1
  93. package/src/common/constants.js +1 -0
  94. package/src/common/event-logger.js +6 -6
  95. package/src/common/feed-display.js +34 -34
  96. package/src/common/translations.js +33 -33
  97. package/src/l10n/l10n-manager-factory.js +8 -8
  98. package/src/l10n/l10n-manager.js +6 -2
  99. package/src/l10n/types.js +1 -0
  100. package/src/managers/auth-manager.js +29 -29
  101. package/src/managers/braze-instance.js +132 -130
  102. package/src/managers/device-manager.js +22 -22
  103. package/src/managers/network-manager.js +103 -98
  104. package/src/managers/server-config-manager.js +23 -23
  105. package/src/managers/session-manager.js +5 -5
  106. package/src/managers/storage-manager-factory.js +9 -9
  107. package/src/managers/storage-manager.js +134 -131
  108. package/src/managers/subscription-manager.js +7 -7
  109. package/src/models/backend-errors.js +6 -6
  110. package/src/models/braze-event.js +11 -11
  111. package/src/models/braze-sdk-metadata.js +1 -1
  112. package/src/models/device.js +2 -2
  113. package/src/models/identifier.js +1 -1
  114. package/src/models/push-token.js +5 -5
  115. package/src/models/server-config.js +7 -7
  116. package/src/request-controller.js +197 -180
  117. package/src/triggers/models/custom-event-data.js +4 -4
  118. package/src/triggers/models/custom-event-property-data.js +7 -7
  119. package/src/triggers/models/filter-set.js +5 -5
  120. package/src/triggers/models/filter.js +65 -61
  121. package/src/triggers/models/in-app-message-click-data.js +9 -9
  122. package/src/triggers/models/purchase-data.js +4 -4
  123. package/src/triggers/models/purchase-property-data.js +6 -6
  124. package/src/triggers/models/push-click-data.js +6 -6
  125. package/src/triggers/models/trigger-condition.js +52 -56
  126. package/src/triggers/models/trigger-events.js +3 -3
  127. package/src/triggers/models/trigger.js +50 -38
  128. package/src/triggers/triggers-provider-factory.js +10 -6
  129. package/src/triggers/triggers-provider.js +204 -186
  130. package/src/triggers/types.js +1 -0
  131. package/src/ui/js/attach-css.js +5 -4
  132. package/src/ui/js/feed-css.js +5 -5
  133. package/src/ui/js/iam-css.js +5 -5
  134. package/src/util/base-device-parser.js +1 -1
  135. package/src/util/braze-actions.js +35 -30
  136. package/src/util/browser-detector.js +30 -31
  137. package/src/util/client-hints-parser.js +28 -22
  138. package/src/util/code-utils.js +22 -21
  139. package/src/util/color-utils.js +19 -13
  140. package/src/util/component-utils.js +4 -4
  141. package/src/util/date-utils.js +6 -5
  142. package/src/util/device-constants.js +10 -10
  143. package/src/util/dom-utils.js +28 -24
  144. package/src/util/error-utils.js +1 -1
  145. package/src/util/key-codes.js +1 -1
  146. package/src/util/net.js +53 -57
  147. package/src/util/request-header-utils.js +34 -11
  148. package/src/util/string-utils.js +14 -14
  149. package/src/util/types.js +1 -0
  150. package/src/util/url-utils.js +1 -4
  151. package/src/util/user-agent-parser.js +39 -39
  152. package/src/util/validation-utils.js +34 -34
  153. package/src/util/window-utils.js +11 -12
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  isArray as p,
3
- isDate as Nt,
4
- isObject as Ct,
5
- keys as oo
3
+ isDate as yt,
4
+ isObject as Nt,
5
+ keys as oo,
6
6
  } from "./code-utils.js";
7
7
  import { getByteLength as U } from "./string-utils.js";
8
8
  import r from "../../shared-lib/braze-shared-lib.js";
9
- import { toValidBackendTimeString as kt } from "./date-utils.js";
9
+ import { toValidBackendTimeString as $t } from "./date-utils.js";
10
10
  import { BRAZE_ACTIONS as _ } from "./braze-actions.js";
11
- import { SET_CUSTOM_USER_ATTRIBUTE_STRING as $t } from "../common/constants.js";
11
+ import { SET_CUSTOM_USER_ATTRIBUTE_STRING as Ft } from "../common/constants.js";
12
12
  export const CUSTOM_DATA_REGEX = /^[^\x00-\x1F\x22]+$/;
13
13
  export const CUSTOM_ATTRIBUTE_SPECIAL_CHARS_REGEX = /[$.]/;
14
14
  export const CUSTOM_ATTRIBUTE_RESERVED_OPERATORS = [
@@ -18,7 +18,7 @@ export const CUSTOM_ATTRIBUTE_RESERVED_OPERATORS = [
18
18
  "$identifier_key",
19
19
  "$identifier_value",
20
20
  "$new_object",
21
- "$time"
21
+ "$time",
22
22
  ];
23
23
  export const EMAIL_ADDRESS_REGEX = new RegExp(/^.+@.+\..+$/);
24
24
  export const CUSTOM_PROPERTIES_MAX_SIZE_BYTES = 51200;
@@ -31,7 +31,7 @@ export function validateCustomString(t, e, n) {
31
31
  const o =
32
32
  null != t &&
33
33
  "string" == typeof t &&
34
- ("" === t || t.match(CUSTOM_DATA_REGEX));
34
+ ("" === t || null != t.match(CUSTOM_DATA_REGEX));
35
35
  return o || r.j.error(`Cannot ${e} because ${n} "${t}" is invalid.`), o;
36
36
  }
37
37
  export function validateCustomAttributeKey(t) {
@@ -46,7 +46,7 @@ export function validateCustomAttributeKey(t) {
46
46
  export function validatePropertyType(t) {
47
47
  const e = typeof t;
48
48
  return (
49
- null == t || "number" === e || "boolean" === e || Nt(t) || "string" === e
49
+ null == t || "number" === e || "boolean" === e || yt(t) || "string" === e
50
50
  );
51
51
  }
52
52
  export function _validateNestedProperties(t, e, n) {
@@ -59,19 +59,19 @@ export function _validateNestedProperties(t, e, n) {
59
59
  if (p(t) && p(e)) {
60
60
  for (let r = 0; r < t.length && r < e.length; r++)
61
61
  if (
62
- (Nt(t[r]) && (e[r] = kt(t[r])),
62
+ (yt(t[r]) && (e[r] = $t(t[r])),
63
63
  !_validateNestedProperties(t[r], e[r], i))
64
64
  )
65
65
  return !1;
66
66
  } else {
67
- if (!Ct(t)) return validatePropertyType(t);
67
+ if (!Nt(t)) return validatePropertyType(t);
68
68
  for (const r of oo(t)) {
69
+ const n = t[r];
69
70
  if (o && !validateCustomAttributeKey(r)) return !1;
70
- if (
71
- (Nt(t[r]) && (e[r] = kt(t[r])),
72
- !_validateNestedProperties(t[r], e[r], i))
73
- )
74
- return !1;
71
+ if (yt(n)) {
72
+ e[r] = $t(n);
73
+ }
74
+ if (!_validateNestedProperties(n, e[r], i)) return !1;
75
75
  }
76
76
  }
77
77
  return !0;
@@ -80,14 +80,14 @@ export function _validateEventPropertyValue(t, e, n, o, i) {
80
80
  let a;
81
81
  return (
82
82
  (a =
83
- Ct(t) || p(t)
83
+ Nt(t) || p(t)
84
84
  ? _validateNestedProperties(t, e, i ? 1 : -1)
85
85
  : validatePropertyType(t)),
86
86
  a || r.j.error(`Cannot ${n} because ${o} "${t}" is invalid.`),
87
87
  a
88
88
  );
89
89
  }
90
- export function validateStandardString(t, e, n, o) {
90
+ export function validateStandardString(t, e, n, o = !1) {
91
91
  const i = "string" == typeof t || (null === t && o);
92
92
  return i || r.j.error(`Cannot ${e} because ${n} "${t}" is invalid.`), i;
93
93
  }
@@ -98,12 +98,12 @@ export function validateCustomProperties(t, e, n, o, i) {
98
98
  [!1, null]
99
99
  );
100
100
  let a, s;
101
- e === $t ? ((a = 76800), (s = "75KB")) : ((a = 51200), (s = "50KB"));
101
+ e === Ft ? ((a = 76800), (s = "75KB")) : ((a = 51200), (s = "50KB"));
102
102
  const u = JSON.stringify(t);
103
103
  if (U(u) > a)
104
104
  return (
105
105
  r.j.error(
106
- `Could not ${o} because ${n} was greater than the max size of ${s}.`
106
+ `Could not ${o} because ${n} was greater than the max size of ${s}.`,
107
107
  ),
108
108
  [!1, null]
109
109
  );
@@ -116,23 +116,23 @@ export function validateCustomProperties(t, e, n, o, i) {
116
116
  [!1, null]
117
117
  );
118
118
  }
119
- for (let r in t) {
120
- if (e === $t && !validateCustomAttributeKey(r)) return [!1, null];
119
+ for (const r in t) {
120
+ if (e === Ft && !validateCustomAttributeKey(r)) return [!1, null];
121
121
  if (!validateCustomString(r, o, `the ${i} property name`))
122
122
  return [!1, null];
123
123
  const n = t[r];
124
- if (e !== $t && null == n) {
124
+ if (e !== Ft && null == n) {
125
125
  delete t[r], delete l[r];
126
126
  continue;
127
127
  }
128
- Nt(n) && (l[r] = kt(n));
128
+ yt(n) && (l[r] = $t(n));
129
129
  if (
130
130
  !_validateEventPropertyValue(
131
131
  n,
132
132
  l[r],
133
133
  o,
134
134
  `the ${i} property "${r}"`,
135
- e === $t
135
+ e === Ft,
136
136
  )
137
137
  )
138
138
  return [!1, null];
@@ -144,7 +144,7 @@ export function validateCustomAttributeArrayType(t, e) {
144
144
  o = !1;
145
145
  const i = () => {
146
146
  r.j.error(
147
- "Custom attribute arrays must be either string arrays or object arrays."
147
+ "Custom attribute arrays must be either string arrays or object arrays.",
148
148
  );
149
149
  };
150
150
  for (const r of e)
@@ -154,21 +154,21 @@ export function validateCustomAttributeArrayType(t, e) {
154
154
  !validateCustomString(
155
155
  r,
156
156
  `set custom user attribute "${t}"`,
157
- "the element in the given array"
157
+ "the element in the given array",
158
158
  )
159
159
  )
160
160
  return [!1, !1];
161
161
  n = !0;
162
162
  } else {
163
- if (!Ct(r)) return i(), [!1, !1];
163
+ if (!Nt(r)) return i(), [!1, !1];
164
164
  if (n) return i(), [!1, !1];
165
165
  if (
166
166
  !validateCustomProperties(
167
167
  r,
168
- $t,
168
+ Ft,
169
169
  "attribute value",
170
170
  `set custom user attribute "${t}"`,
171
- "custom user attribute"
171
+ "custom user attribute",
172
172
  )
173
173
  )
174
174
  return [!1, !1];
@@ -184,8 +184,8 @@ export function isValidEmail(t) {
184
184
  export function isValidBrazeActionJson(t) {
185
185
  if (!(_.properties.type in t)) return !1;
186
186
  switch (t[_.properties.type]) {
187
- case _.types.le:
188
- if (_.properties.ce in t) return !0;
187
+ case _.types.ue:
188
+ if (_.properties.me in t) return !0;
189
189
  break;
190
190
  case _.types.logCustomEvent:
191
191
  case _.types.setEmailNotificationSubscriptionType:
@@ -195,9 +195,9 @@ export function isValidBrazeActionJson(t) {
195
195
  case _.types.removeFromSubscriptionGroup:
196
196
  case _.types.addToCustomAttributeArray:
197
197
  case _.types.removeFromCustomAttributeArray:
198
- case _.types.de:
199
198
  case _.types.pe:
200
- if (_.properties.me in t) return !0;
199
+ case _.types.je:
200
+ if (_.properties.le in t) return !0;
201
201
  break;
202
202
  case _.types.requestPushPermission:
203
203
  return !0;
@@ -209,7 +209,7 @@ export function isValidBrazeActionJson(t) {
209
209
  export function isValidBrazeActionType(t) {
210
210
  let e = !1;
211
211
  return (
212
- Object.keys(_.types).forEach(r => {
212
+ Object.keys(_.types).forEach((r) => {
213
213
  _.types[r] !== t.toString() || (e = !0);
214
214
  }),
215
215
  e
@@ -7,29 +7,28 @@ export function _getOrientation() {
7
7
  return 90 === Math.abs(window.orientation) || 270 === window.orientation
8
8
  ? ORIENTATION.LANDSCAPE
9
9
  : ORIENTATION.PORTRAIT;
10
- if ("screen" in window) {
11
- let n =
12
- window.screen.orientation ||
13
- screen.mozOrientation ||
14
- screen.msOrientation;
10
+ const n = window;
11
+ if ("screen" in n) {
12
+ let e =
13
+ n.screen.orientation || screen.mozOrientation || screen.msOrientation;
15
14
  return (
16
- null != n && "object" == typeof n && (n = n.type),
17
- "landscape-primary" === n || "landscape-secondary" === n
15
+ null != e && "object" == typeof e && (e = e.type),
16
+ "landscape-primary" === e || "landscape-secondary" === e
18
17
  ? ORIENTATION.LANDSCAPE
19
18
  : ORIENTATION.PORTRAIT
20
19
  );
21
20
  }
22
21
  return ORIENTATION.PORTRAIT;
23
22
  }
24
- export function _openUri(n, e, r) {
25
- e || (null != r && r.metaKey) ? window.open(n) : (window.location = n);
23
+ export function _openUri(n, e, t) {
24
+ n && (e || (null != t && t.metaKey) ? window.open(n) : (window.location = n));
26
25
  }
27
26
  export function _getCurrentUrl() {
28
27
  return window.location.href;
29
28
  }
30
29
  export const WindowUtils = {
31
30
  openUri: _openUri,
32
- no: _isPhone,
33
- ao: _getOrientation,
34
- jn: _getCurrentUrl
31
+ ao: _isPhone,
32
+ mo: _getOrientation,
33
+ Cn: _getCurrentUrl,
35
34
  };