@braze/web-sdk 4.3.0 → 4.5.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.
- package/index.d.ts +68 -6
- package/package.json +1 -1
- package/shared-lib/braze-shared-lib.js +8 -1
- package/shared-lib/encoding-utils.js +12 -1
- package/shared-lib/event-types.js +32 -1
- package/shared-lib/guid.js +10 -1
- package/shared-lib/indexed-db-adapter.js +315 -1
- package/shared-lib/logger.js +38 -1
- package/shared-lib/supported-options.js +26 -1
- package/src/Card/card-manager-factory.js +14 -1
- package/src/Card/card-manager.js +72 -1
- package/src/Card/display/card-display.js +134 -1
- package/src/Card/index.js +5 -1
- package/src/Card/log-card-click.js +11 -1
- package/src/Card/log-card-dismissal.js +11 -1
- package/src/Card/log-card-impressions.js +13 -1
- package/src/Card/log-content-card-impressions.js +4 -1
- package/src/Card/models/banner.js +30 -1
- package/src/Card/models/captioned-image.js +32 -1
- package/src/Card/models/card.js +175 -1
- package/src/Card/models/classic-card.js +32 -1
- package/src/Card/models/control-card.js +39 -1
- package/src/Card/models/index.js +5 -1
- package/src/Card/util/card-factory.js +104 -1
- package/src/ContentCards/content-cards-provider-factory.js +20 -1
- package/src/ContentCards/content-cards-provider.js +283 -1
- package/src/ContentCards/content-cards.js +24 -1
- package/src/ContentCards/get-cached-content-cards.js +5 -1
- package/src/ContentCards/index.js +8 -1
- package/src/ContentCards/log-content-cards-displayed.js +5 -1
- package/src/ContentCards/request-content-cards-refresh.js +5 -1
- package/src/ContentCards/subscribe-to-content-cards-updates.js +14 -1
- package/src/ContentCards/ui/hide-content-cards.js +8 -1
- package/src/ContentCards/ui/show-content-cards.js +72 -1
- package/src/ContentCards/ui/toggle-content-cards.js +8 -1
- package/src/Core/add-sdk-metadata.js +27 -1
- package/src/Core/braze-sdk-metadata.js +10 -1
- package/src/Core/change-user.js +19 -1
- package/src/Core/destroy.js +5 -1
- package/src/Core/device-properties.js +9 -1
- package/src/Core/disable-sdk.js +10 -1
- package/src/Core/enable-sdk.js +8 -1
- package/src/Core/get-device-id.js +10 -1
- package/src/Core/get-user.js +4 -1
- package/src/Core/handle-braze-action.js +64 -1
- package/src/Core/index.js +23 -1
- package/src/Core/initialize.js +4 -1
- package/src/Core/is-disabled.js +4 -1
- package/src/Core/log-custom-event.js +36 -1
- package/src/Core/log-purchase.js +245 -1
- package/src/Core/open-session.js +23 -1
- package/src/Core/remove-all-subscriptions.js +4 -1
- package/src/Core/remove-subscription.js +4 -1
- package/src/Core/request-immediate-data-flush.js +4 -1
- package/src/Core/set-logger.js +4 -1
- package/src/Core/set-sdk-authentication-signature.js +9 -1
- package/src/Core/subscribe-to-sdk-authentication-failures.js +4 -1
- package/src/Core/toggle-logging.js +4 -1
- package/src/Core/wipe-data.js +15 -1
- package/src/FeatureFlags/feature-flag-factory.js +14 -0
- package/src/FeatureFlags/feature-flag.js +16 -0
- package/src/FeatureFlags/feature-flags-provider-factory.js +19 -0
- package/src/FeatureFlags/feature-flags-provider.js +94 -0
- package/src/FeatureFlags/get-all-feature-flags.js +12 -0
- package/src/FeatureFlags/get-feature-flag.js +12 -0
- package/src/FeatureFlags/index.js +4 -0
- package/src/FeatureFlags/refresh-feature-flags.js +9 -0
- package/src/FeatureFlags/subscribe-to-feature-flags-updates.js +6 -0
- package/src/Feed/feed-provider-factory.js +18 -1
- package/src/Feed/feed-provider.js +79 -1
- package/src/Feed/feed.js +20 -1
- package/src/Feed/get-cached-feed.js +5 -1
- package/src/Feed/index.js +8 -1
- package/src/Feed/log-feed-displayed.js +5 -1
- package/src/Feed/request-feed-refresh.js +5 -1
- package/src/Feed/subscribe-to-feed-updates.js +5 -1
- package/src/Feed/ui/hide-feed.js +7 -1
- package/src/Feed/ui/show-feed.js +89 -1
- package/src/Feed/ui/toggle-feed.js +8 -1
- package/src/InAppMessage/display/get-animation-effect.js +19 -1
- package/src/InAppMessage/display/html-message-to-html.js +223 -1
- package/src/InAppMessage/display/in-app-message-to-html.js +152 -1
- package/src/InAppMessage/display/modal-utils.js +68 -1
- package/src/InAppMessage/in-app-message-factory.js +145 -1
- package/src/InAppMessage/in-app-message-manager-factory.js +16 -1
- package/src/InAppMessage/in-app-message-manager.js +189 -1
- package/src/InAppMessage/index.js +14 -1
- package/src/InAppMessage/log-in-app-message-button-click.js +19 -1
- package/src/InAppMessage/log-in-app-message-click.js +19 -1
- package/src/InAppMessage/log-in-app-message-html-click.js +23 -1
- package/src/InAppMessage/log-in-app-message-impression.js +13 -1
- package/src/InAppMessage/models/control-message.js +8 -1
- package/src/InAppMessage/models/full-screen-message.js +71 -1
- package/src/InAppMessage/models/html-message.js +54 -1
- package/src/InAppMessage/models/in-app-message-button.js +40 -1
- package/src/InAppMessage/models/in-app-message.js +271 -1
- package/src/InAppMessage/models/modal-message.js +68 -1
- package/src/InAppMessage/models/slide-up-message.js +58 -1
- package/src/InAppMessage/models/templated-in-app-message.js +14 -1
- package/src/InAppMessage/subscribe-to-in-app-message.js +10 -1
- package/src/InAppMessage/ui/automatically-show-in-app-messages.js +15 -1
- package/src/InAppMessage/ui/show-in-app-message.js +170 -1
- package/src/Push/index.js +5 -1
- package/src/Push/is-push-blocked.js +5 -1
- package/src/Push/is-push-permission-granted.js +5 -1
- package/src/Push/is-push-supported.js +5 -1
- package/src/Push/push-manager-factory.js +30 -1
- package/src/Push/push-manager.js +360 -1
- package/src/Push/request-push-permission.js +8 -1
- package/src/Push/unregister-push.js +5 -1
- package/src/Push/utils/push-utils.js +34 -1
- package/src/User/index.js +1 -1
- package/src/User/user-manager.js +70 -1
- package/src/User/user.js +278 -1
- package/src/common/base-feed.js +25 -1
- package/src/common/base-provider.js +6 -1
- package/src/common/constants.js +5 -1
- package/src/common/event-logger.js +24 -1
- package/src/common/feed-display.js +200 -1
- package/src/common/translations.js +148 -1
- package/src/index.js +9 -1
- package/src/l10n/l10n-manager-factory.js +22 -1
- package/src/l10n/l10n-manager.js +21 -1
- package/src/managers/auth-manager.js +48 -1
- package/src/managers/braze-instance.js +307 -1
- package/src/managers/device-manager.js +80 -1
- package/src/managers/network-manager.js +219 -1
- package/src/managers/server-config-manager.js +88 -1
- package/src/managers/session-manager.js +68 -1
- package/src/managers/storage-manager-factory.js +35 -1
- package/src/managers/storage-manager.js +394 -1
- package/src/managers/subscription-manager.js +25 -1
- package/src/models/backend-errors.js +8 -1
- package/src/models/braze-event.js +41 -1
- package/src/models/braze-sdk-metadata.js +10 -1
- package/src/models/device.js +26 -1
- package/src/models/identifier.js +20 -1
- package/src/models/push-token.js +22 -1
- package/src/models/request-result.js +8 -1
- package/src/models/server-config.js +32 -1
- package/src/request-controller.js +288 -1
- package/src/triggers/models/custom-event-data.js +14 -1
- package/src/triggers/models/custom-event-property-data.js +21 -1
- package/src/triggers/models/filter-set.js +55 -1
- package/src/triggers/models/filter.js +98 -1
- package/src/triggers/models/in-app-message-click-data.js +25 -1
- package/src/triggers/models/purchase-data.js +14 -1
- package/src/triggers/models/purchase-property-data.js +21 -1
- package/src/triggers/models/push-click-data.js +15 -1
- package/src/triggers/models/trigger-condition.js +109 -1
- package/src/triggers/models/trigger-events.js +8 -1
- package/src/triggers/models/trigger.js +110 -1
- package/src/triggers/triggers-provider-factory.js +30 -1
- package/src/triggers/triggers-provider.js +307 -1
- package/src/ui/js/attach-css.js +12 -1
- package/src/ui/js/feed-css.js +12 -1
- package/src/ui/js/iam-css.js +12 -1
- package/src/ui/js/index.js +3 -1
- package/src/ui/js/load-font-awesome.js +13 -1
- package/src/util/base-device-parser.js +14 -1
- package/src/util/braze-actions.js +79 -1
- package/src/util/browser-detector.js +85 -1
- package/src/util/client-hints-parser.js +60 -1
- package/src/util/code-utils.js +92 -1
- package/src/util/color-utils.js +23 -1
- package/src/util/component-utils.js +26 -1
- package/src/util/date-utils.js +27 -1
- package/src/util/deprecation-utils.js +5 -1
- package/src/util/device-constants.js +14 -1
- package/src/util/dom-utils.js +87 -1
- package/src/util/key-codes.js +1 -1
- package/src/util/math.js +5 -1
- package/src/util/net.js +75 -1
- package/src/util/string-utils.js +22 -1
- package/src/util/url-utils.js +23 -1
- package/src/util/user-agent-parser.js +85 -1
- package/src/util/validation-utils.js +136 -1
- package/src/util/window-utils.js +35 -1
package/src/User/user.js
CHANGED
|
@@ -1 +1,278 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
isArray as p,
|
|
3
|
+
isDate as yt,
|
|
4
|
+
validateValueIsFromEnum as F
|
|
5
|
+
} from "../util/code-utils.js";
|
|
6
|
+
import r from "../../shared-lib/braze-shared-lib.js";
|
|
7
|
+
import { toValidBackendTimeString as Nt } from "../util/date-utils.js";
|
|
8
|
+
import {
|
|
9
|
+
isValidEmail as Ct,
|
|
10
|
+
validateCustomString as Y,
|
|
11
|
+
validateStandardString as R
|
|
12
|
+
} from "../util/validation-utils.js";
|
|
13
|
+
export default class User {
|
|
14
|
+
constructor(t, e) {
|
|
15
|
+
(this.v = t), (this.si = e);
|
|
16
|
+
}
|
|
17
|
+
getUserId(t) {
|
|
18
|
+
null == t &&
|
|
19
|
+
r.D.error(
|
|
20
|
+
"getUserId must be supplied with a callback. e.g., braze.getUser().getUserId(function(userId) {console.log('the user id is ' + userId)})"
|
|
21
|
+
),
|
|
22
|
+
"function" == typeof t && t(this.v.getUserId());
|
|
23
|
+
}
|
|
24
|
+
addAlias(t, e) {
|
|
25
|
+
return !R(t, "add alias", "the alias", !1) || t.length <= 0
|
|
26
|
+
? (r.D.error("addAlias requires a non-empty alias"), !1)
|
|
27
|
+
: !R(e, "add alias", "the label", !1) || e.length <= 0
|
|
28
|
+
? (r.D.error("addAlias requires a non-empty label"), !1)
|
|
29
|
+
: this.si.Nn(t, e).S;
|
|
30
|
+
}
|
|
31
|
+
setFirstName(t) {
|
|
32
|
+
return (
|
|
33
|
+
!!R(t, "set first name", "the firstName", !0) &&
|
|
34
|
+
this.v.nu("first_name", t)
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
setLastName(t) {
|
|
38
|
+
return (
|
|
39
|
+
!!R(t, "set last name", "the lastName", !0) && this.v.nu("last_name", t)
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
setEmail(t) {
|
|
43
|
+
return null === t || Ct(t)
|
|
44
|
+
? this.v.nu("email", t)
|
|
45
|
+
: (r.D.error(
|
|
46
|
+
`Cannot set email address - "${t}" did not pass RFC-5322 validation.`
|
|
47
|
+
),
|
|
48
|
+
!1);
|
|
49
|
+
}
|
|
50
|
+
setGender(t) {
|
|
51
|
+
return (
|
|
52
|
+
"string" == typeof t && (t = t.toLowerCase()),
|
|
53
|
+
!(
|
|
54
|
+
null !== t &&
|
|
55
|
+
!F(
|
|
56
|
+
User.Genders,
|
|
57
|
+
t,
|
|
58
|
+
`Gender "${t}" is not a valid gender.`,
|
|
59
|
+
"User.Genders"
|
|
60
|
+
)
|
|
61
|
+
) && this.v.nu("gender", t)
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
setDateOfBirth(t, e, s) {
|
|
65
|
+
return null === t && null === e && null === s
|
|
66
|
+
? this.v.nu("dob", null)
|
|
67
|
+
: ((t = parseInt(t)),
|
|
68
|
+
(e = parseInt(e)),
|
|
69
|
+
(s = parseInt(s)),
|
|
70
|
+
isNaN(t) || isNaN(e) || isNaN(s) || e > 12 || e < 1 || s > 31 || s < 1
|
|
71
|
+
? (r.D.error(
|
|
72
|
+
"Cannot set date of birth - parameters should comprise a valid date e.g. setDateOfBirth(1776, 7, 4);"
|
|
73
|
+
),
|
|
74
|
+
!1)
|
|
75
|
+
: this.v.nu("dob", `${t}-${e}-${s}`));
|
|
76
|
+
}
|
|
77
|
+
setCountry(t) {
|
|
78
|
+
return !!R(t, "set country", "the country", !0) && this.v.nu("country", t);
|
|
79
|
+
}
|
|
80
|
+
setHomeCity(t) {
|
|
81
|
+
return (
|
|
82
|
+
!!R(t, "set home city", "the homeCity", !0) && this.v.nu("home_city", t)
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
setLanguage(t) {
|
|
86
|
+
return (
|
|
87
|
+
!!R(t, "set language", "the language", !0) && this.v.nu("language", t)
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
setEmailNotificationSubscriptionType(t) {
|
|
91
|
+
return (
|
|
92
|
+
!!F(
|
|
93
|
+
User.NotificationSubscriptionTypes,
|
|
94
|
+
t,
|
|
95
|
+
`Email notification setting "${t}" is not a valid subscription type.`,
|
|
96
|
+
"User.NotificationSubscriptionTypes"
|
|
97
|
+
) && this.v.nu("email_subscribe", t)
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
setPushNotificationSubscriptionType(t) {
|
|
101
|
+
return (
|
|
102
|
+
!!F(
|
|
103
|
+
User.NotificationSubscriptionTypes,
|
|
104
|
+
t,
|
|
105
|
+
`Push notification setting "${t}" is not a valid subscription type.`,
|
|
106
|
+
"User.NotificationSubscriptionTypes"
|
|
107
|
+
) && this.v.nu("push_subscribe", t)
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
setPhoneNumber(t) {
|
|
111
|
+
return (
|
|
112
|
+
!!R(t, "set phone number", "the phoneNumber", !0) &&
|
|
113
|
+
(null === t || t.match(User.Cn)
|
|
114
|
+
? this.v.nu("phone", t)
|
|
115
|
+
: (r.D.error(
|
|
116
|
+
`Cannot set phone number - "${t}" did not pass validation.`
|
|
117
|
+
),
|
|
118
|
+
!1))
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
setLastKnownLocation(t, e, s, i, n) {
|
|
122
|
+
return null == t || null == e
|
|
123
|
+
? (r.D.error(
|
|
124
|
+
"Cannot set last-known location - latitude and longitude are required."
|
|
125
|
+
),
|
|
126
|
+
!1)
|
|
127
|
+
: ((t = parseFloat(t)),
|
|
128
|
+
(e = parseFloat(e)),
|
|
129
|
+
null != s && (s = parseFloat(s)),
|
|
130
|
+
null != i && (i = parseFloat(i)),
|
|
131
|
+
null != n && (n = parseFloat(n)),
|
|
132
|
+
isNaN(t) ||
|
|
133
|
+
isNaN(e) ||
|
|
134
|
+
(null != s && isNaN(s)) ||
|
|
135
|
+
(null != i && isNaN(i)) ||
|
|
136
|
+
(null != n && isNaN(n))
|
|
137
|
+
? (r.D.error(
|
|
138
|
+
"Cannot set last-known location - all supplied parameters must be numeric."
|
|
139
|
+
),
|
|
140
|
+
!1)
|
|
141
|
+
: t > 90 || t < -90 || e > 180 || e < -180
|
|
142
|
+
? (r.D.error(
|
|
143
|
+
"Cannot set last-known location - latitude and longitude are bounded by ±90 and ±180 respectively."
|
|
144
|
+
),
|
|
145
|
+
!1)
|
|
146
|
+
: (null != s && s < 0) || (null != n && n < 0)
|
|
147
|
+
? (r.D.error(
|
|
148
|
+
"Cannot set last-known location - accuracy and altitudeAccuracy may not be negative."
|
|
149
|
+
),
|
|
150
|
+
!1)
|
|
151
|
+
: this.si.setLastKnownLocation(this.v.getUserId(), t, e, i, s, n).S);
|
|
152
|
+
}
|
|
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 (
|
|
171
|
+
!Y(
|
|
172
|
+
r,
|
|
173
|
+
`set custom user attribute "${t}"`,
|
|
174
|
+
"the element in the given array"
|
|
175
|
+
)
|
|
176
|
+
)
|
|
177
|
+
return !1;
|
|
178
|
+
}
|
|
179
|
+
return this.si.In(r.A.An, t, e).S;
|
|
180
|
+
}
|
|
181
|
+
return this.v.setCustomUserAttribute(t, e);
|
|
182
|
+
}
|
|
183
|
+
addToCustomAttributeArray(t, e) {
|
|
184
|
+
return (
|
|
185
|
+
!!Y(t, "add to custom user attribute array", "the given key") &&
|
|
186
|
+
!(
|
|
187
|
+
null != e &&
|
|
188
|
+
!Y(e, "add to custom user attribute array", "the given value")
|
|
189
|
+
) &&
|
|
190
|
+
this.si.In(r.A.Un, t, e).S
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
removeFromCustomAttributeArray(t, e) {
|
|
194
|
+
return (
|
|
195
|
+
!!Y(t, "remove from custom user attribute array", "the given key") &&
|
|
196
|
+
!(
|
|
197
|
+
null != e &&
|
|
198
|
+
!Y(e, "remove from custom user attribute array", "the given value")
|
|
199
|
+
) &&
|
|
200
|
+
this.si.In(r.A.En, t, e).S
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
incrementCustomUserAttribute(t, e) {
|
|
204
|
+
if (!Y(t, "increment custom user attribute", "the given key")) return !1;
|
|
205
|
+
null == e && (e = 1);
|
|
206
|
+
const s = parseInt(e);
|
|
207
|
+
return isNaN(s) || s !== parseFloat(e)
|
|
208
|
+
? (r.D.error(
|
|
209
|
+
`Cannot increment custom user attribute because the given incrementValue "${e}" is not an integer.`
|
|
210
|
+
),
|
|
211
|
+
!1)
|
|
212
|
+
: this.si.In(r.A.Fn, t, s).S;
|
|
213
|
+
}
|
|
214
|
+
setCustomLocationAttribute(t, e, s) {
|
|
215
|
+
return (
|
|
216
|
+
!!Y(t, "set custom location attribute", "the given key") &&
|
|
217
|
+
((null !== e || null !== s) &&
|
|
218
|
+
((e = parseFloat(e)),
|
|
219
|
+
(s = parseFloat(s)),
|
|
220
|
+
isNaN(e) || e > 90 || e < -90 || isNaN(s) || s > 180 || s < -180)
|
|
221
|
+
? (r.D.error(
|
|
222
|
+
"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
|
+
),
|
|
224
|
+
!1)
|
|
225
|
+
: this.si.Tn(t, e, s).S)
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
addToSubscriptionGroup(t) {
|
|
229
|
+
return !R(
|
|
230
|
+
t,
|
|
231
|
+
"add user to subscription group",
|
|
232
|
+
"subscription group ID",
|
|
233
|
+
!1
|
|
234
|
+
) || t.length <= 0
|
|
235
|
+
? (r.D.error(
|
|
236
|
+
"addToSubscriptionGroup requires a non-empty subscription group ID"
|
|
237
|
+
),
|
|
238
|
+
!1)
|
|
239
|
+
: this.si.$n(t, User.Bn.SUBSCRIBED).S;
|
|
240
|
+
}
|
|
241
|
+
removeFromSubscriptionGroup(t) {
|
|
242
|
+
return !R(
|
|
243
|
+
t,
|
|
244
|
+
"remove user from subscription group",
|
|
245
|
+
"subscription group ID",
|
|
246
|
+
!1
|
|
247
|
+
) || t.length <= 0
|
|
248
|
+
? (r.D.error(
|
|
249
|
+
"removeFromSubscriptionGroup requires a non-empty subscription group ID"
|
|
250
|
+
),
|
|
251
|
+
!1)
|
|
252
|
+
: this.si.$n(t, User.Bn.UNSUBSCRIBED).S;
|
|
253
|
+
}
|
|
254
|
+
Qr(t, e, s, r, i) {
|
|
255
|
+
this.v.Qr(t, e, s, r, i), this.si.Ln();
|
|
256
|
+
}
|
|
257
|
+
Zr(t) {
|
|
258
|
+
this.v.Zr(t);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
(User.Cn = /^[0-9 .\\(\\)\\+\\-]+$/),
|
|
262
|
+
(User.Genders = {
|
|
263
|
+
MALE: "m",
|
|
264
|
+
FEMALE: "f",
|
|
265
|
+
OTHER: "o",
|
|
266
|
+
UNKNOWN: "u",
|
|
267
|
+
NOT_APPLICABLE: "n",
|
|
268
|
+
PREFER_NOT_TO_SAY: "p"
|
|
269
|
+
}),
|
|
270
|
+
(User.NotificationSubscriptionTypes = {
|
|
271
|
+
OPTED_IN: "opted_in",
|
|
272
|
+
SUBSCRIBED: "subscribed",
|
|
273
|
+
UNSUBSCRIBED: "unsubscribed"
|
|
274
|
+
}),
|
|
275
|
+
(User.Bn = { SUBSCRIBED: "subscribed", UNSUBSCRIBED: "unsubscribed" }),
|
|
276
|
+
(User.Rn = "user_id"),
|
|
277
|
+
(User.lu = "custom"),
|
|
278
|
+
(User.ee = 997);
|
package/src/common/base-feed.js
CHANGED
|
@@ -1 +1,25 @@
|
|
|
1
|
-
import{ControlCard}from"../Card/index.js";
|
|
1
|
+
import { ControlCard } from "../Card/index.js";
|
|
2
|
+
export const FEED_ANIMATION_DURATION = 500;
|
|
3
|
+
export default class x {
|
|
4
|
+
constructor(e, r) {
|
|
5
|
+
(this.cards = e), (this.lastUpdated = r);
|
|
6
|
+
}
|
|
7
|
+
getUnreadCardCount() {
|
|
8
|
+
let e = 0;
|
|
9
|
+
for (const r of this.cards) r.viewed || r instanceof ControlCard || e++;
|
|
10
|
+
return e;
|
|
11
|
+
}
|
|
12
|
+
dr() {
|
|
13
|
+
throw new Error("Must be implemented in a subclass");
|
|
14
|
+
}
|
|
15
|
+
logCardImpressions() {
|
|
16
|
+
throw new Error("Must be implemented in subclass");
|
|
17
|
+
}
|
|
18
|
+
logCardClick() {
|
|
19
|
+
throw new Error("Must be implemented in subclass");
|
|
20
|
+
}
|
|
21
|
+
sr() {
|
|
22
|
+
throw new Error("Must be implemented in subclass");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
(x.ur = 6e4), (x.Ki = 500), (x.uo = 1e4);
|
package/src/common/constants.js
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
export const MAX_PURCHASE_QUANTITY
|
|
1
|
+
export const MAX_PURCHASE_QUANTITY = 100;
|
|
2
|
+
export const MUST_BE_IN_APP_MESSAGE_WARNING =
|
|
3
|
+
"inAppMessage must be an InAppMessage object";
|
|
4
|
+
export const MUST_BE_CARD_WARNING_SUFFIX = "must be a Card object";
|
|
5
|
+
export const FEED_ANIMATION_DURATION = 500;
|
|
@@ -1 +1,24 @@
|
|
|
1
|
-
import r from"../../shared-lib/braze-shared-lib.js";
|
|
1
|
+
import r from "../../shared-lib/braze-shared-lib.js";
|
|
2
|
+
import e from "../managers/braze-instance.js";
|
|
3
|
+
import ue from "../models/braze-event.js";
|
|
4
|
+
import t from "../models/request-result.js";
|
|
5
|
+
const s = {
|
|
6
|
+
G: (o, n, s) => {
|
|
7
|
+
const a = new t(),
|
|
8
|
+
i = e.g();
|
|
9
|
+
if (!i)
|
|
10
|
+
return (
|
|
11
|
+
r.D.info(
|
|
12
|
+
`Not logging event with type "${o}" because the current session ID could not be found.`
|
|
13
|
+
),
|
|
14
|
+
a
|
|
15
|
+
);
|
|
16
|
+
const m = i.mo();
|
|
17
|
+
return (
|
|
18
|
+
a.ve.push(new ue(s || e.p().getUserId(), o, new Date().valueOf(), m, n)),
|
|
19
|
+
(a.S = e.l().bo(a.ve)),
|
|
20
|
+
a
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
export default s;
|
|
@@ -1 +1,200 @@
|
|
|
1
|
-
import x from"./base-feed.js";
|
|
1
|
+
import x from "./base-feed.js";
|
|
2
|
+
import {
|
|
3
|
+
bottomHadImpression as de,
|
|
4
|
+
getCardId as be,
|
|
5
|
+
impressOnBottom as ye,
|
|
6
|
+
impressOnTop as Fe,
|
|
7
|
+
markCardAsRead as Te,
|
|
8
|
+
topHadImpression as he
|
|
9
|
+
} from "../Card/display/card-display.js";
|
|
10
|
+
import { bottomIsInView as _e, topIsInView as xe } from "../util/dom-utils.js";
|
|
11
|
+
import { Card, ControlCard } from "../Card/index.js";
|
|
12
|
+
import { cardToHtml as Ee } from "../Card/display/card-display.js";
|
|
13
|
+
import { isArray as p } from "../util/code-utils.js";
|
|
14
|
+
import { KeyCodes as at } from "../util/key-codes.js";
|
|
15
|
+
import je from "../l10n/l10n-manager-factory.js";
|
|
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 O } from "../util/validation-utils.js";
|
|
19
|
+
import {
|
|
20
|
+
INELIGIBLE_BRAZE_ACTION_URL_ERROR_TYPES as ft,
|
|
21
|
+
ineligibleBrazeActionURLErrorMessage as ht,
|
|
22
|
+
getDecodedBrazeAction as J,
|
|
23
|
+
containsUnknownBrazeAction as ct
|
|
24
|
+
} from "../util/braze-actions.js";
|
|
25
|
+
export const LAST_REQUESTED_REFRESH_DATA_ATTRIBUTE =
|
|
26
|
+
"data-last-requested-refresh";
|
|
27
|
+
export const _SUBSCRIPTION_ID_DATA_ATTRIBUTE = "data-update-subscription-id";
|
|
28
|
+
export function destroyFeedHtml(e) {
|
|
29
|
+
e &&
|
|
30
|
+
((e.className = e.className.replace("ab-show", "ab-hide")),
|
|
31
|
+
setTimeout(() => {
|
|
32
|
+
e && e.parentNode && e.parentNode.removeChild(e);
|
|
33
|
+
}, x.Ki));
|
|
34
|
+
const t = e.getAttribute("data-update-subscription-id");
|
|
35
|
+
null != t && removeSubscription(t);
|
|
36
|
+
}
|
|
37
|
+
export function _generateFeedBody(e, t) {
|
|
38
|
+
const o = document.createElement("div");
|
|
39
|
+
if (
|
|
40
|
+
((o.className = "ab-feed-body"),
|
|
41
|
+
o.setAttribute("aria-label", "Feed"),
|
|
42
|
+
o.setAttribute("role", "feed"),
|
|
43
|
+
null == e.lastUpdated)
|
|
44
|
+
) {
|
|
45
|
+
const e = document.createElement("div");
|
|
46
|
+
e.className = "ab-no-cards-message";
|
|
47
|
+
const t = document.createElement("i");
|
|
48
|
+
(t.className = "fa fa-spinner fa-spin fa-4x ab-initial-spinner"),
|
|
49
|
+
e.appendChild(t),
|
|
50
|
+
o.appendChild(e);
|
|
51
|
+
} else {
|
|
52
|
+
let s = !1;
|
|
53
|
+
const logCardClick = t => {
|
|
54
|
+
e.logCardClick(t);
|
|
55
|
+
};
|
|
56
|
+
for (const n of e.cards) {
|
|
57
|
+
const a = n instanceof ControlCard;
|
|
58
|
+
!a || e.dr()
|
|
59
|
+
? (o.appendChild(Ee(n, logCardClick, t)), (s = s || !a))
|
|
60
|
+
: r.D.error(
|
|
61
|
+
"Received a control card for a legacy news feed. Control cards are only supported with content cards."
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
if (!s) {
|
|
65
|
+
const e = document.createElement("div");
|
|
66
|
+
(e.className = "ab-no-cards-message"),
|
|
67
|
+
(e.innerHTML = je.m().get("NO_CARDS_MESSAGE")),
|
|
68
|
+
e.setAttribute("role", "article"),
|
|
69
|
+
o.appendChild(e);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return o;
|
|
73
|
+
}
|
|
74
|
+
export function detectFeedImpressions(e, t) {
|
|
75
|
+
if (null != t) {
|
|
76
|
+
const o = [],
|
|
77
|
+
r = t.querySelectorAll(".ab-card");
|
|
78
|
+
e.do || (e.do = {});
|
|
79
|
+
for (let t = 0; t < r.length; t++) {
|
|
80
|
+
const s = be(r[t]);
|
|
81
|
+
if (e.do[s]) continue;
|
|
82
|
+
let n = he(r[t]),
|
|
83
|
+
a = de(r[t]);
|
|
84
|
+
const i = n,
|
|
85
|
+
d = a,
|
|
86
|
+
f = xe(r[t]),
|
|
87
|
+
c = _e(r[t]);
|
|
88
|
+
if (
|
|
89
|
+
(!n && f && ((n = !0), Fe(r[t])),
|
|
90
|
+
!a && c && ((a = !0), ye(r[t])),
|
|
91
|
+
n && a)
|
|
92
|
+
) {
|
|
93
|
+
if ((f || c || Te(r[t]), i && d)) continue;
|
|
94
|
+
for (const t of e.cards)
|
|
95
|
+
if (t.id === s) {
|
|
96
|
+
(e.do[t.id] = !0), o.push(t);
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
o.length > 0 && e.logCardImpressions(o);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export function refreshFeed(e, t) {
|
|
105
|
+
t.setAttribute("aria-busy", "true");
|
|
106
|
+
const o = t.querySelectorAll(".ab-refresh-button")[0];
|
|
107
|
+
null != o && (o.className += " fa-spin");
|
|
108
|
+
const r = new Date().valueOf().toString();
|
|
109
|
+
t.setAttribute("data-last-requested-refresh", r),
|
|
110
|
+
setTimeout(() => {
|
|
111
|
+
if (t.getAttribute("data-last-requested-refresh") === r) {
|
|
112
|
+
const e = t.querySelectorAll(".fa-spin");
|
|
113
|
+
for (let t = 0; t < e.length; t++)
|
|
114
|
+
e[t].className = e[t].className.replace(/fa-spin/g, "");
|
|
115
|
+
const o = t.querySelectorAll(".ab-initial-spinner")[0];
|
|
116
|
+
if (null != o) {
|
|
117
|
+
const e = document.createElement("span");
|
|
118
|
+
(e.innerHTML = je.m().get("FEED_TIMEOUT_MESSAGE")),
|
|
119
|
+
o.parentNode.appendChild(e),
|
|
120
|
+
o.parentNode.removeChild(o);
|
|
121
|
+
}
|
|
122
|
+
"true" === t.getAttribute("aria-busy") &&
|
|
123
|
+
t.setAttribute("aria-busy", "false");
|
|
124
|
+
}
|
|
125
|
+
}, x.uo),
|
|
126
|
+
e.sr();
|
|
127
|
+
}
|
|
128
|
+
export function feedToHtml(e, t) {
|
|
129
|
+
const o = document.createElement("div");
|
|
130
|
+
(o.className = "ab-feed ab-hide ab-effect-slide"),
|
|
131
|
+
o.setAttribute("role", "dialog"),
|
|
132
|
+
o.setAttribute("aria-label", "Feed"),
|
|
133
|
+
o.setAttribute("tabindex", "-1");
|
|
134
|
+
const r = document.createElement("div");
|
|
135
|
+
(r.className = "ab-feed-buttons-wrapper"),
|
|
136
|
+
r.setAttribute("role", "group"),
|
|
137
|
+
o.appendChild(r);
|
|
138
|
+
const s = document.createElement("i");
|
|
139
|
+
(s.className = "fa fa-times ab-close-button"),
|
|
140
|
+
s.setAttribute("aria-label", "Close Feed"),
|
|
141
|
+
s.setAttribute("tabindex", "0"),
|
|
142
|
+
s.setAttribute("role", "button");
|
|
143
|
+
const n = e => {
|
|
144
|
+
destroyFeedHtml(o), e.stopPropagation();
|
|
145
|
+
};
|
|
146
|
+
s.addEventListener("keydown", e => {
|
|
147
|
+
(e.keyCode !== at.fo && e.keyCode !== at.co) || n(e);
|
|
148
|
+
}),
|
|
149
|
+
(s.onclick = n);
|
|
150
|
+
const a = document.createElement("i");
|
|
151
|
+
(a.className = "fa fa-refresh ab-refresh-button"),
|
|
152
|
+
null == e.lastUpdated && (a.className += " fa-spin"),
|
|
153
|
+
a.setAttribute("aria-label", "Refresh Feed"),
|
|
154
|
+
a.setAttribute("tabindex", "0"),
|
|
155
|
+
a.setAttribute("role", "button");
|
|
156
|
+
const i = t => {
|
|
157
|
+
refreshFeed(e, o), t.stopPropagation();
|
|
158
|
+
};
|
|
159
|
+
return (
|
|
160
|
+
a.addEventListener("keydown", e => {
|
|
161
|
+
(e.keyCode !== at.fo && e.keyCode !== at.co) || i(e);
|
|
162
|
+
}),
|
|
163
|
+
(a.onclick = i),
|
|
164
|
+
r.appendChild(a),
|
|
165
|
+
r.appendChild(s),
|
|
166
|
+
o.appendChild(_generateFeedBody(e, t)),
|
|
167
|
+
(o.onscroll = () => {
|
|
168
|
+
detectFeedImpressions(e, o);
|
|
169
|
+
}),
|
|
170
|
+
o
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
export function updateFeedCards(e, t, o, s, n) {
|
|
174
|
+
if (!p(t)) return;
|
|
175
|
+
const a = [];
|
|
176
|
+
for (const e of t)
|
|
177
|
+
if (e instanceof Card) {
|
|
178
|
+
if (e.url && O.test(e.url)) {
|
|
179
|
+
let t = J(e.url);
|
|
180
|
+
if (ct(t)) {
|
|
181
|
+
r.D.error(ht(ft.yi, "Content Card"));
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
a.push(e);
|
|
186
|
+
}
|
|
187
|
+
if (((e.cards = a), (e.lastUpdated = o), null != s))
|
|
188
|
+
if ((s.setAttribute("aria-busy", "false"), null == e.lastUpdated))
|
|
189
|
+
destroyFeedHtml(s);
|
|
190
|
+
else {
|
|
191
|
+
const t = s.querySelectorAll(".ab-feed-body")[0];
|
|
192
|
+
if (null != t) {
|
|
193
|
+
const o = _generateFeedBody(e, n);
|
|
194
|
+
t.parentNode.replaceChild(o, t), detectFeedImpressions(e, o.parentNode);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
export function registerFeedSubscriptionId(e, t) {
|
|
199
|
+
t.setAttribute("data-update-subscription-id", e);
|
|
200
|
+
}
|