@braze/web-sdk 5.9.1 → 6.0.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 +109 -253
- package/package.json +1 -1
- package/shared-lib/encoding-utils.js +1 -1
- package/shared-lib/event-types.js +24 -26
- package/shared-lib/guid.js +2 -2
- package/shared-lib/indexed-db-adapter.js +19 -19
- package/shared-lib/logger.js +2 -2
- package/shared-lib/supported-options.js +21 -22
- package/src/Banner/display/banner-to-html.js +13 -25
- package/src/Banner/display/destroy-banner-html.js +2 -2
- package/src/Banner/display/detect-banner-impressions.js +11 -11
- package/src/Banner/index.js +0 -1
- package/src/Banner/request-banners-refresh.js +8 -8
- package/src/Banner/subscribe-to-banners-updates.js +2 -2
- package/src/Banner/ui/insert-banner.js +7 -7
- package/src/Card/card-manager.js +35 -37
- package/src/Card/display/card-display.js +76 -74
- package/src/Card/index.js +0 -2
- package/src/Card/log-card-dismissal.js +2 -2
- package/src/Card/log-content-card-click.js +9 -2
- package/src/Card/log-content-card-impressions.js +11 -2
- package/src/Card/models/captioned-image.js +20 -20
- package/src/Card/models/card.js +110 -104
- package/src/Card/models/classic-card.js +20 -20
- package/src/Card/models/control-card.js +14 -14
- package/src/Card/models/image-only.js +19 -20
- package/src/Card/util/card-factory.js +57 -78
- package/src/ContentCards/content-cards-provider-factory.js +10 -10
- package/src/ContentCards/content-cards-provider.js +109 -109
- package/src/ContentCards/content-cards.js +21 -13
- package/src/ContentCards/get-cached-content-cards.js +2 -2
- package/src/ContentCards/request-content-cards-refresh.js +2 -2
- package/src/ContentCards/subscribe-to-content-cards-updates.js +5 -5
- package/src/ContentCards/ui/hide-content-cards.js +5 -5
- package/src/ContentCards/ui/show-content-cards.js +34 -34
- package/src/Core/add-sdk-metadata.js +2 -2
- package/src/Core/change-user.js +7 -7
- package/src/Core/disable-sdk.js +6 -6
- package/src/Core/enable-sdk.js +5 -5
- package/src/Core/get-user.js +1 -1
- package/src/Core/handle-braze-action.js +7 -7
- package/src/Core/is-disabled.js +2 -2
- package/src/Core/is-initialized.js +1 -1
- package/src/Core/log-custom-event.js +9 -9
- package/src/Core/log-purchase.js +7 -7
- package/src/Core/open-session.js +12 -12
- package/src/Core/request-immediate-data-flush.js +1 -1
- package/src/Core/set-sdk-authentication-signature.js +2 -2
- package/src/Core/wipe-data.js +7 -7
- package/src/FeatureFlags/feature-flag-factory.js +7 -7
- package/src/FeatureFlags/feature-flag.js +6 -6
- package/src/FeatureFlags/feature-flags-provider-factory.js +9 -9
- package/src/FeatureFlags/feature-flags-provider.js +1 -1
- package/src/FeatureFlags/get-all-feature-flags.js +2 -2
- package/src/FeatureFlags/get-feature-flag.js +2 -2
- package/src/FeatureFlags/log-feature-flag-impression.js +4 -4
- package/src/FeatureFlags/refresh-feature-flags.js +2 -2
- package/src/FeatureFlags/subscribe-to-feature-flags-updates.js +2 -2
- package/src/InAppMessage/defer-in-app-message.js +1 -1
- package/src/InAppMessage/display/html-message-to-html.js +37 -37
- package/src/InAppMessage/display/in-app-message-to-html.js +139 -133
- package/src/InAppMessage/display/modal-utils.js +39 -41
- package/src/InAppMessage/get-deferred-in-app-message.js +1 -1
- package/src/InAppMessage/in-app-message-factory.js +22 -14
- package/src/InAppMessage/in-app-message-manager.js +90 -88
- package/src/InAppMessage/log-in-app-message-button-click.js +5 -5
- package/src/InAppMessage/log-in-app-message-click.js +5 -5
- package/src/InAppMessage/log-in-app-message-html-click.js +5 -5
- package/src/InAppMessage/log-in-app-message-impression.js +1 -1
- package/src/InAppMessage/models/control-message.js +2 -2
- package/src/InAppMessage/models/full-screen-message.js +40 -34
- package/src/InAppMessage/models/html-message.js +23 -21
- package/src/InAppMessage/models/in-app-message-button.js +2 -2
- package/src/InAppMessage/models/in-app-message.js +137 -133
- package/src/InAppMessage/models/modal-message.js +39 -33
- package/src/InAppMessage/models/slide-up-message.js +36 -30
- package/src/InAppMessage/models/templated-in-app-message.js +8 -8
- package/src/InAppMessage/subscribe-to-in-app-message.js +1 -1
- package/src/InAppMessage/ui/automatically-show-in-app-messages.js +3 -3
- package/src/InAppMessage/ui/show-in-app-message.js +56 -62
- package/src/Push/is-push-blocked.js +2 -2
- package/src/Push/is-push-permission-granted.js +2 -2
- package/src/Push/is-push-supported.js +2 -2
- package/src/Push/push-manager-factory.js +8 -8
- package/src/Push/push-manager.js +90 -90
- package/src/Push/request-push-permission.js +1 -1
- package/src/Push/utils/push-utils.js +25 -15
- package/src/User/user-manager.js +14 -14
- package/src/User/user.js +55 -55
- package/src/common/content-cards-display.js +211 -0
- package/src/common/event-logger.js +6 -6
- package/src/index.js +0 -1
- package/src/l10n/l10n-manager-factory.js +9 -9
- package/src/l10n/l10n-manager.js +6 -6
- package/src/managers/auth-manager.js +27 -27
- package/src/managers/braze-instance.js +136 -137
- package/src/managers/device-manager.js +22 -22
- package/src/managers/network-manager.js +180 -183
- package/src/managers/server-config-manager.js +63 -63
- package/src/managers/session-manager.js +34 -34
- package/src/managers/storage-manager-factory.js +11 -11
- package/src/managers/storage-manager.js +139 -141
- package/src/managers/subscription-manager.js +3 -3
- package/src/managers/utils.js +1 -1
- package/src/models/backend-errors.js +5 -5
- package/src/models/braze-event.js +15 -15
- package/src/models/device.js +3 -3
- package/src/models/identifier.js +13 -13
- package/src/models/push-token.js +12 -12
- package/src/models/request-result.js +2 -2
- package/src/models/server-config.js +29 -29
- package/src/request-controller.js +175 -174
- package/src/triggers/models/custom-event-data.js +6 -6
- package/src/triggers/models/custom-event-property-data.js +7 -7
- package/src/triggers/models/filter-set.js +8 -8
- package/src/triggers/models/filter.js +45 -45
- package/src/triggers/models/in-app-message-click-data.js +3 -3
- package/src/triggers/models/purchase-data.js +1 -1
- package/src/triggers/models/purchase-property-data.js +4 -4
- package/src/triggers/models/push-click-data.js +1 -1
- package/src/triggers/models/trigger-condition.js +47 -47
- package/src/triggers/models/trigger-events.js +3 -3
- package/src/triggers/models/trigger.js +15 -15
- package/src/triggers/triggers-provider-factory.js +4 -4
- package/src/triggers/triggers-provider.js +44 -44
- package/src/ui/js/attach-css.js +3 -3
- package/src/ui/js/banner-css.js +1 -1
- package/src/ui/js/iam-css.js +1 -1
- package/src/ui/js/load-font-awesome.js +2 -2
- package/src/util/base-device-parser.js +4 -4
- package/src/util/braze-actions.js +8 -14
- package/src/util/browser-detector.js +12 -12
- package/src/util/client-hints-parser.js +3 -3
- package/src/util/component-utils.js +14 -14
- package/src/util/device-constants.js +1 -1
- package/src/util/dom-utils.js +6 -6
- package/src/util/html-display-utils.js +37 -37
- package/src/util/key-codes.js +1 -1
- package/src/util/net.js +1 -1
- package/src/util/request-header-utils.js +17 -17
- package/src/util/user-agent-parser.js +4 -4
- package/src/util/validation-utils.js +20 -20
- package/src/util/window-utils.js +1 -1
- package/src/Card/log-card-click.js +0 -11
- package/src/Card/log-card-impressions.js +0 -13
- package/src/Feed/feed-provider-factory.js +0 -18
- package/src/Feed/feed-provider.js +0 -90
- package/src/Feed/feed.js +0 -20
- package/src/Feed/get-cached-feed.js +0 -5
- package/src/Feed/index.js +0 -8
- package/src/Feed/log-feed-displayed.js +0 -7
- package/src/Feed/request-feed-refresh.js +0 -5
- package/src/Feed/subscribe-to-feed-updates.js +0 -5
- package/src/Feed/types.js +0 -1
- package/src/Feed/ui/hide-feed.js +0 -7
- package/src/Feed/ui/show-feed.js +0 -96
- package/src/Feed/ui/toggle-feed.js +0 -8
- package/src/common/base-feed.js +0 -29
- package/src/common/feed-display.js +0 -211
|
@@ -3,7 +3,7 @@ import ra from "./push-manager-factory.js";
|
|
|
3
3
|
export function requestPushPermission(n, o) {
|
|
4
4
|
if (r.rr())
|
|
5
5
|
return ra.ea().subscribe((o, t, e) => {
|
|
6
|
-
const s = r.
|
|
6
|
+
const s = r.nn();
|
|
7
7
|
s && s.requestImmediateDataFlush(), "function" == typeof n && n(o, t, e);
|
|
8
8
|
}, o);
|
|
9
9
|
}
|
|
@@ -1,36 +1,46 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
1
|
+
const yt = {
|
|
2
|
+
bn: () =>
|
|
3
3
|
"serviceWorker" in navigator &&
|
|
4
4
|
"undefined" != typeof ServiceWorkerRegistration &&
|
|
5
5
|
"showNotification" in ServiceWorkerRegistration.prototype &&
|
|
6
6
|
"PushManager" in window,
|
|
7
|
-
|
|
7
|
+
mn: () =>
|
|
8
8
|
"safari" in window &&
|
|
9
9
|
"pushNotification" in window.safari &&
|
|
10
10
|
"function" == typeof window.safari.pushNotification.permission &&
|
|
11
11
|
"function" == typeof window.safari.pushNotification.requestPermission,
|
|
12
|
-
isPushSupported: () =>
|
|
12
|
+
isPushSupported: () => yt.bn() || yt.mn(),
|
|
13
13
|
isPushBlocked: () => {
|
|
14
|
-
const
|
|
15
|
-
|
|
14
|
+
const o =
|
|
15
|
+
yt.isPushSupported() &&
|
|
16
16
|
"Notification" in window &&
|
|
17
17
|
null != window.Notification &&
|
|
18
18
|
null != window.Notification.permission &&
|
|
19
19
|
"denied" === window.Notification.permission,
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
i =
|
|
21
|
+
yt.isPushSupported() &&
|
|
22
22
|
(!("Notification" in window) || null == window.Notification);
|
|
23
|
-
return
|
|
23
|
+
return o || i;
|
|
24
24
|
},
|
|
25
25
|
isPushPermissionGranted: () =>
|
|
26
|
-
|
|
26
|
+
yt.isPushSupported() &&
|
|
27
27
|
"Notification" in window &&
|
|
28
28
|
null != window.Notification &&
|
|
29
29
|
null != window.Notification.permission &&
|
|
30
30
|
"granted" === window.Notification.permission,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
Ui: () =>
|
|
32
|
+
yt.isPushBlocked()
|
|
33
|
+
? { Vi: !1, reason: "blocked" }
|
|
34
|
+
: yt.isPushSupported()
|
|
35
|
+
? yt.isPushPermissionGranted()
|
|
36
|
+
? { Vi: !1, reason: "permissionGranted" }
|
|
37
|
+
: { Vi: !0 }
|
|
38
|
+
: { Vi: !1, reason: "unsupported" },
|
|
39
|
+
Wi: (o, i) =>
|
|
40
|
+
"blocked" === o
|
|
41
|
+
? `${i} containing a push prompt is not being shown because the user has already declined push permission prompt.`
|
|
42
|
+
: "unsupported" === o
|
|
43
|
+
? `${i} containing a push prompt is not being shown because the browser doesn't support push notifications.`
|
|
44
|
+
: `${i} containing a push prompt is not being shown because the user has already accepted the permission prompt.`,
|
|
35
45
|
};
|
|
36
|
-
export default
|
|
46
|
+
export default yt;
|
package/src/User/user-manager.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import _t from "../models/identifier.js";
|
|
2
|
-
import { getByteLength as
|
|
2
|
+
import { getByteLength as rr } from "../util/string-utils.js";
|
|
3
3
|
import ti from "../models/push-token.js";
|
|
4
|
-
import { logger as N, IndexedDBAdapter as
|
|
4
|
+
import { logger as N, IndexedDBAdapter as et } from "../../shared-lib/index.js";
|
|
5
5
|
import { STORAGE_KEYS as s } from "../managers/storage-manager.js";
|
|
6
6
|
import { User } from "../User/index.js";
|
|
7
|
-
export default class
|
|
7
|
+
export default class bt {
|
|
8
8
|
constructor(t, s) {
|
|
9
9
|
(this.B = t), (this.C = s), (this.B = t), (this.C = s);
|
|
10
10
|
}
|
|
@@ -12,9 +12,9 @@ export default class kt {
|
|
|
12
12
|
const t = this.C.tu(s.iu.su);
|
|
13
13
|
if (null == t) return null;
|
|
14
14
|
let i = t.eu,
|
|
15
|
-
e =
|
|
16
|
-
if (e > User.
|
|
17
|
-
for (; e > User.
|
|
15
|
+
e = rr(i);
|
|
16
|
+
if (e > User.mr) {
|
|
17
|
+
for (; e > User.mr; ) (i = i.slice(0, i.length - 1)), (e = rr(i));
|
|
18
18
|
(t.eu = i), this.C.uu(s.iu.su, t);
|
|
19
19
|
}
|
|
20
20
|
return i;
|
|
@@ -47,17 +47,17 @@ export default class kt {
|
|
|
47
47
|
u
|
|
48
48
|
);
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
Dn(t, i, e, u, o) {
|
|
51
51
|
this.nu("push_token", t, !1, !0),
|
|
52
52
|
this.nu("custom_push_public_key", e, !1, !0),
|
|
53
53
|
this.nu("custom_push_user_auth", u, !1, !0),
|
|
54
54
|
this.nu("custom_push_vapid_public_key", o, !1, !0);
|
|
55
|
-
const r =
|
|
56
|
-
h = new
|
|
55
|
+
const r = et.Ds.Us,
|
|
56
|
+
h = new et(r, N),
|
|
57
57
|
n = new ti(t, i, e, u, o);
|
|
58
|
-
this.C.Bt(s.gt.
|
|
58
|
+
this.C.Bt(s.gt.Vn, n.bt()), h.setItem(r.Ls.cu, r.be, !0);
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
An(t) {
|
|
61
61
|
if (
|
|
62
62
|
(this.nu("push_token", null, !1, !0),
|
|
63
63
|
this.nu("custom_push_public_key", null, !1, !0),
|
|
@@ -65,9 +65,9 @@ export default class kt {
|
|
|
65
65
|
this.nu("custom_push_vapid_public_key", null, !1, !0),
|
|
66
66
|
t)
|
|
67
67
|
) {
|
|
68
|
-
const t =
|
|
69
|
-
i = new
|
|
70
|
-
this.C.Bt(s.gt.
|
|
68
|
+
const t = et.Ds.Us,
|
|
69
|
+
i = new et(t, N);
|
|
70
|
+
this.C.Bt(s.gt.Vn, !1), i.setItem(t.Ls.cu, t.be, !1);
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
}
|
package/src/User/user.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
|
-
isArray as
|
|
2
|
+
isArray as D,
|
|
3
3
|
isDate as Nt,
|
|
4
|
-
isObject as
|
|
4
|
+
isObject as It,
|
|
5
5
|
validateValueIsFromEnum as ta,
|
|
6
6
|
} from "../util/code-utils.js";
|
|
7
7
|
import { logger as N, EventTypes as d } from "../../shared-lib/index.js";
|
|
8
8
|
import {
|
|
9
9
|
isValidEmail as Ct,
|
|
10
10
|
validateCustomAttributeArrayType as St,
|
|
11
|
-
validateCustomAttributeKey as
|
|
12
|
-
validateCustomProperties as
|
|
13
|
-
validateCustomString as
|
|
14
|
-
validatePropertyType as
|
|
15
|
-
validateStandardString as
|
|
11
|
+
validateCustomAttributeKey as Ut,
|
|
12
|
+
validateCustomProperties as nt,
|
|
13
|
+
validateCustomString as mt,
|
|
14
|
+
validatePropertyType as Dt,
|
|
15
|
+
validateStandardString as er,
|
|
16
16
|
} from "../util/validation-utils.js";
|
|
17
|
-
import { SET_CUSTOM_USER_ATTRIBUTE_STRING as
|
|
18
|
-
import { toValidBackendTimeString as
|
|
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.
|
|
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();
|
|
@@ -29,21 +29,21 @@ export default class User {
|
|
|
29
29
|
t(e);
|
|
30
30
|
}
|
|
31
31
|
addAlias(t, e) {
|
|
32
|
-
return !
|
|
32
|
+
return !er(t, "add alias", "the alias", !1) || t.length <= 0
|
|
33
33
|
? (N.error("addAlias requires a non-empty alias"), !1)
|
|
34
|
-
: !
|
|
34
|
+
: !er(e, "add alias", "the label", !1) || e.length <= 0
|
|
35
35
|
? (N.error("addAlias requires a non-empty label"), !1)
|
|
36
|
-
: this.
|
|
36
|
+
: this.Cn.En(t, e).tt;
|
|
37
37
|
}
|
|
38
38
|
setFirstName(t) {
|
|
39
39
|
return (
|
|
40
|
-
!!
|
|
40
|
+
!!er(t, "set first name", "the firstName", !0) &&
|
|
41
41
|
this.Cs.nu("first_name", t)
|
|
42
42
|
);
|
|
43
43
|
}
|
|
44
44
|
setLastName(t) {
|
|
45
45
|
return (
|
|
46
|
-
!!
|
|
46
|
+
!!er(t, "set last name", "the lastName", !0) && this.Cs.nu("last_name", t)
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
49
|
setEmail(t) {
|
|
@@ -92,17 +92,17 @@ export default class User {
|
|
|
92
92
|
}
|
|
93
93
|
setCountry(t) {
|
|
94
94
|
return (
|
|
95
|
-
!!
|
|
95
|
+
!!er(t, "set country", "the country", !0) && this.Cs.nu("country", t)
|
|
96
96
|
);
|
|
97
97
|
}
|
|
98
98
|
setHomeCity(t) {
|
|
99
99
|
return (
|
|
100
|
-
!!
|
|
100
|
+
!!er(t, "set home city", "the homeCity", !0) && this.Cs.nu("home_city", t)
|
|
101
101
|
);
|
|
102
102
|
}
|
|
103
103
|
setLanguage(t) {
|
|
104
104
|
return (
|
|
105
|
-
!!
|
|
105
|
+
!!er(t, "set language", "the language", !0) && this.Cs.nu("language", t)
|
|
106
106
|
);
|
|
107
107
|
}
|
|
108
108
|
setEmailNotificationSubscriptionType(t) {
|
|
@@ -127,7 +127,7 @@ export default class User {
|
|
|
127
127
|
}
|
|
128
128
|
setPhoneNumber(t) {
|
|
129
129
|
return (
|
|
130
|
-
!!
|
|
130
|
+
!!er(t, "set phone number", "the phoneNumber", !0) &&
|
|
131
131
|
(null === t || t.match(User.Fn)
|
|
132
132
|
? this.Cs.nu("phone", t)
|
|
133
133
|
: (N.error(`Cannot set phone number - "${t}" did not pass validation.`),
|
|
@@ -164,35 +164,35 @@ export default class User {
|
|
|
164
164
|
"Cannot set last-known location - accuracy and altitudeAccuracy may not be negative.",
|
|
165
165
|
),
|
|
166
166
|
!1)
|
|
167
|
-
: this.
|
|
167
|
+
: this.Cn.setLastKnownLocation(this.Cs.getUserId(), t, e, s, r, n)
|
|
168
168
|
.tt);
|
|
169
169
|
}
|
|
170
170
|
setCustomUserAttribute(t, e, r) {
|
|
171
|
-
if (!
|
|
171
|
+
if (!Ut(t)) return !1;
|
|
172
172
|
const s = (e) => {
|
|
173
|
-
const [r] =
|
|
173
|
+
const [r] = nt(
|
|
174
174
|
e,
|
|
175
|
-
|
|
175
|
+
Ft,
|
|
176
176
|
"attribute value",
|
|
177
177
|
`set custom user attribute "${t}"`,
|
|
178
178
|
"custom user attribute",
|
|
179
179
|
);
|
|
180
180
|
return r;
|
|
181
181
|
};
|
|
182
|
-
if (
|
|
182
|
+
if (D(e)) {
|
|
183
183
|
const [r, n] = St(t, e);
|
|
184
184
|
if (!r && !n && 0 !== e.length) return !1;
|
|
185
|
-
if (r || 0 === e.length) return this.
|
|
185
|
+
if (r || 0 === e.length) return this.Cn.Ln(d.$n, t, e).tt;
|
|
186
186
|
for (const t of e) if (!s(t)) return !1;
|
|
187
|
-
} else if (
|
|
187
|
+
} else if (It(e)) {
|
|
188
188
|
if (!s(e)) return !1;
|
|
189
|
-
if (r) return this.
|
|
189
|
+
if (r) return this.Cn.Ln(d.Bn, t, e).tt;
|
|
190
190
|
} else {
|
|
191
|
-
if (!(void 0 !== e &&
|
|
191
|
+
if (!(void 0 !== e && Dt(e))) return !1;
|
|
192
192
|
if (
|
|
193
|
-
(Nt(e) && (e =
|
|
193
|
+
(Nt(e) && (e = Lt(e)),
|
|
194
194
|
"string" == typeof e &&
|
|
195
|
-
!
|
|
195
|
+
!mt(
|
|
196
196
|
e,
|
|
197
197
|
`set custom user attribute "${t}"`,
|
|
198
198
|
"the element in the given array",
|
|
@@ -204,26 +204,26 @@ export default class User {
|
|
|
204
204
|
}
|
|
205
205
|
addToCustomAttributeArray(t, e) {
|
|
206
206
|
return (
|
|
207
|
-
!!
|
|
207
|
+
!!mt(t, "add to custom user attribute array", "the given key") &&
|
|
208
208
|
!(
|
|
209
209
|
null != e &&
|
|
210
|
-
!
|
|
210
|
+
!mt(e, "add to custom user attribute array", "the given value")
|
|
211
211
|
) &&
|
|
212
|
-
this.
|
|
212
|
+
this.Cn.Ln(d.Rn, t, e).tt
|
|
213
213
|
);
|
|
214
214
|
}
|
|
215
215
|
removeFromCustomAttributeArray(t, e) {
|
|
216
216
|
return (
|
|
217
|
-
!!
|
|
217
|
+
!!mt(t, "remove from custom user attribute array", "the given key") &&
|
|
218
218
|
!(
|
|
219
219
|
null != e &&
|
|
220
|
-
!
|
|
220
|
+
!mt(e, "remove from custom user attribute array", "the given value")
|
|
221
221
|
) &&
|
|
222
|
-
this.
|
|
222
|
+
this.Cn.Ln(d.On, t, e).tt
|
|
223
223
|
);
|
|
224
224
|
}
|
|
225
225
|
incrementCustomUserAttribute(t, e) {
|
|
226
|
-
if (!
|
|
226
|
+
if (!mt(t, "increment custom user attribute", "the given key")) return !1;
|
|
227
227
|
null == e && (e = 1);
|
|
228
228
|
const r = parseInt(e.toString());
|
|
229
229
|
return isNaN(r) || r !== parseFloat(e.toString())
|
|
@@ -231,11 +231,11 @@ export default class User {
|
|
|
231
231
|
`Cannot increment custom user attribute because the given incrementValue "${e}" is not an integer.`,
|
|
232
232
|
),
|
|
233
233
|
!1)
|
|
234
|
-
: this.
|
|
234
|
+
: this.Cn.Ln(d.Gn, t, r).tt;
|
|
235
235
|
}
|
|
236
236
|
setCustomLocationAttribute(t, e, r) {
|
|
237
237
|
return (
|
|
238
|
-
!!
|
|
238
|
+
!!mt(t, "set custom location attribute", "the given key") &&
|
|
239
239
|
((null !== e || null !== r) &&
|
|
240
240
|
((e = null != e ? parseFloat(e.toString()) : null),
|
|
241
241
|
(r = null != r ? parseFloat(r.toString()) : null),
|
|
@@ -247,11 +247,11 @@ export default class User {
|
|
|
247
247
|
"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
248
|
),
|
|
249
249
|
!1)
|
|
250
|
-
: this.
|
|
250
|
+
: this.Cn.Hn(t, e, r).tt)
|
|
251
251
|
);
|
|
252
252
|
}
|
|
253
253
|
addToSubscriptionGroup(t) {
|
|
254
|
-
return !
|
|
254
|
+
return !er(
|
|
255
255
|
t,
|
|
256
256
|
"add user to subscription group",
|
|
257
257
|
"subscription group ID",
|
|
@@ -261,10 +261,10 @@ export default class User {
|
|
|
261
261
|
"addToSubscriptionGroup requires a non-empty subscription group ID",
|
|
262
262
|
),
|
|
263
263
|
!1)
|
|
264
|
-
: this.
|
|
264
|
+
: this.Cn.Kn(t, User.Mn.SUBSCRIBED).tt;
|
|
265
265
|
}
|
|
266
266
|
removeFromSubscriptionGroup(t) {
|
|
267
|
-
return !
|
|
267
|
+
return !er(
|
|
268
268
|
t,
|
|
269
269
|
"remove user from subscription group",
|
|
270
270
|
"subscription group ID",
|
|
@@ -274,24 +274,24 @@ export default class User {
|
|
|
274
274
|
"removeFromSubscriptionGroup requires a non-empty subscription group ID",
|
|
275
275
|
),
|
|
276
276
|
!1)
|
|
277
|
-
: this.
|
|
277
|
+
: this.Cn.Kn(t, User.Mn.UNSUBSCRIBED).tt;
|
|
278
278
|
}
|
|
279
279
|
setLineId(t) {
|
|
280
|
-
return
|
|
280
|
+
return er(t, "set LINE user ID", "the ID", !0) &&
|
|
281
281
|
0 !== (null == t ? void 0 : t.length)
|
|
282
|
-
? t && t.length > User.
|
|
282
|
+
? t && t.length > User.Yn
|
|
283
283
|
? (N.error(
|
|
284
|
-
`Rejected LINE user ID ${t} because it is longer than ${User.
|
|
284
|
+
`Rejected LINE user ID ${t} because it is longer than ${User.Yn} characters.`,
|
|
285
285
|
),
|
|
286
286
|
!1)
|
|
287
287
|
: this.Cs.nu("native_line_id", t)
|
|
288
288
|
: (N.error("setLineId requires a non-empty ID"), !1);
|
|
289
289
|
}
|
|
290
|
-
|
|
291
|
-
this.Cs.
|
|
290
|
+
Dn(t, e, r, s, n) {
|
|
291
|
+
this.Cs.Dn(t, e, r, s, n), this.Cn.Jn();
|
|
292
292
|
}
|
|
293
|
-
|
|
294
|
-
this.Cs.
|
|
293
|
+
An(t) {
|
|
294
|
+
this.Cs.An(t);
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
297
|
(User.Genders = {
|
|
@@ -308,8 +308,8 @@ export default class User {
|
|
|
308
308
|
UNSUBSCRIBED: "unsubscribed",
|
|
309
309
|
}),
|
|
310
310
|
(User.Fn = /^[0-9 .\\(\\)\\+\\-]+$/),
|
|
311
|
-
(User.
|
|
312
|
-
(User.
|
|
311
|
+
(User.Mn = { SUBSCRIBED: "subscribed", UNSUBSCRIBED: "unsubscribed" }),
|
|
312
|
+
(User.Qn = "user_id"),
|
|
313
313
|
(User.lu = "custom"),
|
|
314
|
-
(User.
|
|
315
|
-
(User.
|
|
314
|
+
(User.mr = 997),
|
|
315
|
+
(User.Yn = 33);
|
|
@@ -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 N, Guid as O } 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 f,
|
|
23
|
+
impressOnTop as j,
|
|
24
|
+
topHadImpression as qt,
|
|
25
|
+
} from "./detect-impression.js";
|
|
26
|
+
import { SUBSCRIPTION_ID_DATA_ATTRIBUTE as p } 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(p);
|
|
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.Ro())), (s = s || !i))
|
|
67
|
+
: N.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.Xn || (t.Xn = {});
|
|
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.Xn[s]) {
|
|
91
|
+
r || a || Rt(o[e]);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
let i = qt(o[e]),
|
|
95
|
+
l = kt(o[e]);
|
|
96
|
+
const d = i,
|
|
97
|
+
c = l;
|
|
98
|
+
if (
|
|
99
|
+
(!i && r && ((i = !0), j(o[e])), !l && a && ((l = !0), f(o[e])), i && l)
|
|
100
|
+
) {
|
|
101
|
+
if (d && c) continue;
|
|
102
|
+
for (const e of t.cards)
|
|
103
|
+
if (e.id === s) {
|
|
104
|
+
(t.Xn[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.$o && t.keyCode !== ie.Co) || 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.$o && t.keyCode !== ie.Co) || 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 = O.ce();
|
|
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
|
+
N.error(jt(vt.Qi, "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(p, t);
|
|
211
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { logger as N } from "../../shared-lib/index.js";
|
|
2
2
|
import r from "../managers/braze-instance.js";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import ue from "../models/braze-event.js";
|
|
4
|
+
import G from "../models/request-result.js";
|
|
5
5
|
const c = {
|
|
6
6
|
ut: (e, o, t) => {
|
|
7
7
|
var n, s;
|
|
8
|
-
const i = new
|
|
8
|
+
const i = new G(),
|
|
9
9
|
l = r.P();
|
|
10
10
|
if (!l)
|
|
11
11
|
return (
|
|
@@ -14,10 +14,10 @@ const c = {
|
|
|
14
14
|
),
|
|
15
15
|
i
|
|
16
16
|
);
|
|
17
|
-
const d = l.
|
|
17
|
+
const d = l.Vo();
|
|
18
18
|
return (
|
|
19
19
|
i.$e.push(
|
|
20
|
-
new
|
|
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(),
|
|
@@ -26,7 +26,7 @@ const c = {
|
|
|
26
26
|
),
|
|
27
27
|
),
|
|
28
28
|
(i.tt =
|
|
29
|
-
(null === (s = r.j()) || void 0 === s ? void 0 : s.
|
|
29
|
+
(null === (s = r.j()) || void 0 === s ? void 0 : s.Wo(i.$e)) || !1),
|
|
30
30
|
i
|
|
31
31
|
);
|
|
32
32
|
},
|
package/src/index.js
CHANGED