@braze/web-sdk 5.5.0 → 5.6.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.
- package/index.d.ts +109 -7
- package/package.json +1 -1
- package/shared-lib/encoding-utils.js +1 -1
- package/shared-lib/event-types.js +33 -31
- package/shared-lib/guid.js +3 -3
- package/shared-lib/indexed-db-adapter.js +20 -20
- package/shared-lib/logger.js +18 -18
- package/shared-lib/supported-options.js +24 -24
- package/src/Banner/banner-factory.js +14 -0
- package/src/Banner/banner-provider-factory.js +19 -0
- package/src/Banner/banner-provider.js +198 -0
- package/src/Banner/banner.js +30 -0
- package/src/Banner/display/banner-to-html.js +57 -0
- package/src/Banner/display/destroy-banner-html.js +7 -0
- package/src/Banner/display/detect-banner-impressions.js +28 -0
- package/src/Banner/get-all-banners.js +13 -0
- package/src/Banner/get-banner.js +19 -0
- package/src/Banner/index.js +7 -0
- package/src/Banner/log-banner-click.js +22 -0
- package/src/Banner/log-banner-impressions.js +31 -0
- package/src/Banner/request-banners-refresh.js +35 -0
- package/src/Banner/subscribe-to-banners-updates.js +23 -0
- package/src/Banner/types.js +1 -0
- package/src/Banner/ui/insert-banner.js +24 -0
- package/src/Card/card-manager-factory.js +10 -10
- package/src/Card/card-manager.js +54 -52
- package/src/Card/display/card-display.js +77 -91
- package/src/Card/log-card-click.js +6 -6
- package/src/Card/log-card-dismissal.js +6 -5
- package/src/Card/log-card-impressions.js +11 -11
- package/src/Card/models/captioned-image.js +21 -21
- package/src/Card/models/card.js +99 -99
- package/src/Card/models/classic-card.js +21 -21
- package/src/Card/models/control-card.js +11 -11
- package/src/Card/models/image-only.js +19 -19
- package/src/Card/util/card-factory.js +58 -58
- package/src/ContentCards/content-cards-provider-factory.js +14 -14
- package/src/ContentCards/content-cards-provider.js +261 -263
- package/src/ContentCards/content-cards.js +5 -5
- package/src/ContentCards/get-cached-content-cards.js +3 -3
- package/src/ContentCards/request-content-cards-refresh.js +4 -4
- package/src/ContentCards/subscribe-to-content-cards-updates.js +13 -13
- package/src/ContentCards/ui/hide-content-cards.js +7 -7
- package/src/ContentCards/ui/show-content-cards.js +52 -52
- package/src/ContentCards/ui/toggle-content-cards.js +4 -4
- package/src/Core/add-sdk-metadata.js +9 -9
- package/src/Core/change-user.js +14 -14
- package/src/Core/destroy.js +3 -3
- package/src/Core/disable-sdk.js +13 -13
- package/src/Core/enable-sdk.js +9 -9
- package/src/Core/get-device-id.js +10 -10
- package/src/Core/get-user.js +2 -2
- package/src/Core/handle-braze-action.js +53 -53
- package/src/Core/initialize.js +2 -2
- package/src/Core/is-disabled.js +2 -2
- package/src/Core/is-initialized.js +2 -2
- package/src/Core/log-custom-event.js +27 -27
- package/src/Core/log-purchase.js +38 -38
- package/src/Core/open-session.js +18 -18
- package/src/Core/remove-all-subscriptions.js +2 -2
- package/src/Core/remove-subscription.js +3 -3
- package/src/Core/request-immediate-data-flush.js +5 -5
- package/src/Core/set-logger.js +2 -2
- package/src/Core/set-sdk-authentication-signature.js +6 -6
- package/src/Core/subscribe-to-sdk-authentication-failures.js +5 -5
- package/src/Core/toggle-logging.js +2 -2
- package/src/Core/wipe-data.js +10 -10
- package/src/FeatureFlags/feature-flag-factory.js +13 -13
- package/src/FeatureFlags/feature-flag.js +10 -10
- package/src/FeatureFlags/feature-flags-provider-factory.js +13 -14
- package/src/FeatureFlags/feature-flags-provider.js +118 -116
- package/src/FeatureFlags/get-all-feature-flags.js +10 -10
- package/src/FeatureFlags/get-feature-flag.js +9 -9
- package/src/FeatureFlags/log-feature-flag-impression.js +18 -18
- package/src/FeatureFlags/refresh-feature-flags.js +6 -6
- package/src/FeatureFlags/subscribe-to-feature-flags-updates.js +9 -9
- package/src/Feed/feed-provider-factory.js +12 -12
- package/src/Feed/feed-provider.js +59 -59
- package/src/Feed/feed.js +4 -4
- package/src/Feed/get-cached-feed.js +3 -3
- package/src/Feed/log-feed-displayed.js +5 -5
- package/src/Feed/request-feed-refresh.js +3 -3
- package/src/Feed/subscribe-to-feed-updates.js +4 -4
- package/src/Feed/ui/hide-feed.js +5 -5
- package/src/Feed/ui/show-feed.js +53 -53
- package/src/Feed/ui/toggle-feed.js +4 -4
- package/src/InAppMessage/defer-in-app-message.js +9 -9
- package/src/InAppMessage/display/html-message-display-utils.js +18 -164
- package/src/InAppMessage/display/html-message-to-html.js +55 -62
- package/src/InAppMessage/display/in-app-message-to-html.js +74 -74
- package/src/InAppMessage/display/modal-utils.js +17 -17
- package/src/InAppMessage/get-deferred-in-app-message.js +2 -2
- package/src/InAppMessage/in-app-message-factory.js +61 -61
- package/src/InAppMessage/in-app-message-manager-factory.js +9 -9
- package/src/InAppMessage/in-app-message-manager.js +158 -156
- package/src/InAppMessage/log-in-app-message-button-click.js +16 -16
- package/src/InAppMessage/log-in-app-message-click.js +11 -11
- package/src/InAppMessage/log-in-app-message-html-click.js +15 -15
- package/src/InAppMessage/log-in-app-message-impression.js +6 -6
- package/src/InAppMessage/models/control-message.js +15 -8
- package/src/InAppMessage/models/full-screen-message.js +34 -34
- package/src/InAppMessage/models/html-message.js +23 -23
- package/src/InAppMessage/models/in-app-message-button.js +10 -10
- package/src/InAppMessage/models/in-app-message.js +155 -155
- package/src/InAppMessage/models/modal-message.js +33 -33
- package/src/InAppMessage/models/slide-up-message.js +35 -35
- package/src/InAppMessage/models/templated-in-app-message.js +8 -8
- package/src/InAppMessage/subscribe-to-in-app-message.js +3 -3
- package/src/InAppMessage/ui/automatically-show-in-app-messages.js +6 -6
- package/src/InAppMessage/ui/show-in-app-message.js +103 -103
- 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 +25 -25
- package/src/Push/push-manager.js +176 -176
- package/src/Push/request-push-permission.js +8 -8
- package/src/Push/unregister-push.js +4 -4
- package/src/Push/utils/push-utils.js +4 -4
- package/src/User/user-manager.js +38 -38
- package/src/User/user.js +95 -92
- package/src/common/base-feed.js +9 -9
- package/src/common/base-provider.js +2 -2
- package/src/common/constants.js +1 -0
- package/src/common/detect-impression.js +18 -0
- package/src/common/event-logger.js +22 -22
- package/src/common/feed-display.js +53 -53
- package/src/index.js +1 -0
- package/src/l10n/l10n-manager-factory.js +15 -15
- package/src/l10n/l10n-manager.js +4 -4
- package/src/managers/auth-manager.js +38 -38
- package/src/managers/braze-instance.js +212 -212
- package/src/managers/device-manager.js +30 -30
- package/src/managers/network-manager.js +234 -235
- package/src/managers/server-config-manager.js +99 -83
- package/src/managers/session-manager.js +46 -50
- package/src/managers/storage-manager-factory.js +13 -13
- package/src/managers/storage-manager.js +182 -180
- package/src/managers/subscription-manager.js +12 -12
- package/src/managers/utils.js +4 -4
- package/src/models/backend-errors.js +5 -5
- package/src/models/braze-event.js +9 -9
- package/src/models/device.js +2 -2
- package/src/models/identifier.js +15 -15
- package/src/models/push-token.js +10 -10
- package/src/models/request-result.js +4 -4
- package/src/models/server-config.js +38 -34
- package/src/request-controller.js +228 -228
- package/src/triggers/models/custom-event-data.js +5 -5
- package/src/triggers/models/custom-event-property-data.js +6 -6
- package/src/triggers/models/filter-set.js +10 -10
- package/src/triggers/models/filter.js +66 -66
- package/src/triggers/models/in-app-message-click-data.js +10 -10
- package/src/triggers/models/purchase-data.js +2 -2
- package/src/triggers/models/purchase-property-data.js +6 -6
- package/src/triggers/models/push-click-data.js +5 -5
- package/src/triggers/models/trigger-condition.js +46 -46
- package/src/triggers/models/trigger-events.js +4 -4
- package/src/triggers/models/trigger.js +33 -33
- package/src/triggers/triggers-provider-factory.js +16 -16
- package/src/triggers/triggers-provider.js +156 -154
- package/src/ui/js/attach-css.js +7 -7
- package/src/ui/js/banner-css.js +11 -0
- package/src/ui/js/feed-css.js +4 -4
- package/src/ui/js/iam-css.js +4 -4
- package/src/ui/js/index.js +1 -0
- package/src/ui/js/load-font-awesome.js +8 -8
- package/src/util/base-device-parser.js +9 -9
- package/src/util/braze-actions.js +32 -32
- package/src/util/browser-detector.js +31 -30
- package/src/util/client-hints-parser.js +10 -10
- package/src/util/code-utils.js +5 -5
- package/src/util/component-utils.js +5 -5
- package/src/util/deprecation-utils.js +3 -3
- package/src/util/device-constants.js +1 -1
- package/src/util/dom-utils.js +13 -13
- package/src/util/html-display-utils.js +158 -0
- package/src/util/key-codes.js +1 -1
- package/src/util/net.js +21 -21
- package/src/util/request-header-utils.js +31 -30
- package/src/util/string-utils.js +2 -2
- package/src/util/user-agent-parser.js +18 -18
- package/src/util/validation-utils.js +89 -85
- package/src/util/window-utils.js +3 -3
package/src/Push/push-manager.js
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
import { isArray as
|
|
1
|
+
import { isArray as w, isEqual as ii } from "../util/code-utils.js";
|
|
2
2
|
import ti from "../models/push-token.js";
|
|
3
|
-
import { logger as
|
|
4
|
-
import { STORAGE_KEYS as
|
|
3
|
+
import { logger as N, EncodingUtils as ei } from "../../shared-lib/index.js";
|
|
4
|
+
import { STORAGE_KEYS as t } from "../managers/storage-manager.js";
|
|
5
5
|
import { User } from "../User/index.js";
|
|
6
6
|
import yt from "./utils/push-utils.js";
|
|
7
7
|
import { getErrorMessage as si } from "../util/error-utils.js";
|
|
8
|
-
export default class
|
|
8
|
+
export default class na {
|
|
9
9
|
constructor(i, t, e, s, r, n, o, u, a, h, c) {
|
|
10
|
-
(this.
|
|
11
|
-
(this.
|
|
12
|
-
(this.
|
|
13
|
-
(this.
|
|
14
|
-
(this.
|
|
15
|
-
(this.
|
|
16
|
-
(this.
|
|
17
|
-
(this.
|
|
18
|
-
(this.
|
|
19
|
-
(this.
|
|
20
|
-
(this.
|
|
21
|
-
(this.
|
|
22
|
-
(this.
|
|
23
|
-
(this.
|
|
24
|
-
(this.
|
|
25
|
-
(this.
|
|
26
|
-
(this.
|
|
27
|
-
(this.
|
|
28
|
-
(this.
|
|
29
|
-
(this.
|
|
30
|
-
(this.
|
|
31
|
-
(this.
|
|
10
|
+
(this.bn = i),
|
|
11
|
+
(this.yn = t),
|
|
12
|
+
(this.wn = e),
|
|
13
|
+
(this.kn = r),
|
|
14
|
+
(this.Pn = n),
|
|
15
|
+
(this.Dn = o),
|
|
16
|
+
(this.B = u),
|
|
17
|
+
(this.Sn = a),
|
|
18
|
+
(this.An = h),
|
|
19
|
+
(this.C = c),
|
|
20
|
+
(this.bn = i),
|
|
21
|
+
(this.yn = t),
|
|
22
|
+
(this.wn = e),
|
|
23
|
+
(this.xn = s + "/safari/" + t),
|
|
24
|
+
(this.kn = r || "/service-worker.js"),
|
|
25
|
+
(this.Dn = o),
|
|
26
|
+
(this.B = u),
|
|
27
|
+
(this.Sn = a || !1),
|
|
28
|
+
(this.An = h || !1),
|
|
29
|
+
(this.C = c),
|
|
30
|
+
(this.Nn = yt.Un()),
|
|
31
|
+
(this.Wn = yt._n());
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
return this.
|
|
33
|
+
Tn() {
|
|
34
|
+
return this.An;
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
In(i, t, e, s, r) {
|
|
37
37
|
i.unsubscribe()
|
|
38
38
|
.then((i) => {
|
|
39
39
|
i
|
|
40
|
-
? this.
|
|
41
|
-
: (
|
|
42
|
-
"function" == typeof
|
|
40
|
+
? this.Vn(t, e, s, r)
|
|
41
|
+
: (N.error("Failed to unsubscribe device from push."),
|
|
42
|
+
"function" == typeof r && r(!1));
|
|
43
43
|
})
|
|
44
44
|
.catch((i) => {
|
|
45
|
-
|
|
46
|
-
"function" == typeof
|
|
45
|
+
N.error("Push unsubscription error: " + i),
|
|
46
|
+
"function" == typeof r && r(!1);
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
qn(i, t, e) {
|
|
50
50
|
var s;
|
|
51
|
-
const
|
|
51
|
+
const r = ((i) => {
|
|
52
52
|
if ("string" == typeof i) return i;
|
|
53
53
|
if (0 !== i.endpoint.indexOf("https://android.googleapis.com/gcm/send"))
|
|
54
54
|
return i.endpoint;
|
|
55
55
|
let t = i.endpoint;
|
|
56
56
|
const e = i;
|
|
57
57
|
return (
|
|
58
|
-
e.
|
|
59
|
-
-1 === i.endpoint.indexOf(e.
|
|
60
|
-
(t = i.endpoint + "/" + e.
|
|
58
|
+
e.zn &&
|
|
59
|
+
-1 === i.endpoint.indexOf(e.zn) &&
|
|
60
|
+
(t = i.endpoint + "/" + e.zn),
|
|
61
61
|
t
|
|
62
62
|
);
|
|
63
63
|
})(i);
|
|
64
|
-
let
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
if (null !=
|
|
64
|
+
let n = null,
|
|
65
|
+
o = null;
|
|
66
|
+
const u = i;
|
|
67
|
+
if (null != u.getKey)
|
|
68
68
|
try {
|
|
69
|
-
const i = Array.from(new Uint8Array(
|
|
70
|
-
t = Array.from(new Uint8Array(
|
|
71
|
-
(
|
|
72
|
-
(
|
|
69
|
+
const i = Array.from(new Uint8Array(u.getKey("p256dh"))),
|
|
70
|
+
t = Array.from(new Uint8Array(u.getKey("auth")));
|
|
71
|
+
(n = btoa(String.fromCharCode.apply(null, i))),
|
|
72
|
+
(o = btoa(String.fromCharCode.apply(null, t)));
|
|
73
73
|
} catch (i) {
|
|
74
|
-
|
|
74
|
+
N.error(si(i));
|
|
75
75
|
}
|
|
76
|
-
const
|
|
76
|
+
const a = ((i) => {
|
|
77
77
|
let t;
|
|
78
78
|
return i.options &&
|
|
79
79
|
(t = i.options.applicationServerKey) &&
|
|
@@ -83,54 +83,54 @@ export default class ea {
|
|
|
83
83
|
.replace(/\+/g, "-")
|
|
84
84
|
.replace(/\//g, "_")
|
|
85
85
|
: null;
|
|
86
|
-
})(
|
|
87
|
-
null === (s = this.
|
|
88
|
-
|
|
86
|
+
})(u);
|
|
87
|
+
null === (s = this.bn) || void 0 === s || s.En(r, t, n, o, a),
|
|
88
|
+
r && "function" == typeof e && e(r, n, o);
|
|
89
89
|
}
|
|
90
|
-
|
|
90
|
+
Rn() {
|
|
91
91
|
var i;
|
|
92
|
-
null === (i = this.
|
|
92
|
+
null === (i = this.bn) || void 0 === i || i.Cn(!0);
|
|
93
93
|
}
|
|
94
|
-
|
|
94
|
+
Fn(i, t) {
|
|
95
95
|
var e;
|
|
96
|
-
null === (e = this.
|
|
97
|
-
|
|
96
|
+
null === (e = this.bn) || void 0 === e || e.Cn(!1),
|
|
97
|
+
N.info(i),
|
|
98
98
|
"function" == typeof t && t(!1);
|
|
99
99
|
}
|
|
100
|
-
|
|
101
|
-
var
|
|
100
|
+
On(i, t, e, s) {
|
|
101
|
+
var r;
|
|
102
102
|
if ("default" === t.permission)
|
|
103
103
|
try {
|
|
104
104
|
window.safari.pushNotification.requestPermission(
|
|
105
|
-
this.
|
|
105
|
+
this.xn,
|
|
106
106
|
i,
|
|
107
107
|
{
|
|
108
|
-
api_key: this.
|
|
108
|
+
api_key: this.yn,
|
|
109
109
|
device_id:
|
|
110
|
-
(null === (
|
|
110
|
+
(null === (r = this.wn) || void 0 === r ? void 0 : r.ce().id) ||
|
|
111
111
|
"",
|
|
112
112
|
},
|
|
113
113
|
(t) => {
|
|
114
114
|
"granted" === t.permission &&
|
|
115
|
-
this.
|
|
116
|
-
this.
|
|
115
|
+
this.bn &&
|
|
116
|
+
this.bn.setPushNotificationSubscriptionType(
|
|
117
117
|
User.NotificationSubscriptionTypes.OPTED_IN,
|
|
118
118
|
),
|
|
119
|
-
this.
|
|
119
|
+
this.On(i, t, e, s);
|
|
120
120
|
},
|
|
121
121
|
);
|
|
122
122
|
} catch (i) {
|
|
123
|
-
this.
|
|
123
|
+
this.Fn("Could not request permission for push: " + i, s);
|
|
124
124
|
}
|
|
125
125
|
else
|
|
126
126
|
"denied" === t.permission
|
|
127
|
-
? this.
|
|
127
|
+
? this.Fn(
|
|
128
128
|
"The user has blocked notifications from this site, or Safari push is not configured in the Braze dashboard.",
|
|
129
129
|
s,
|
|
130
130
|
)
|
|
131
131
|
: "granted" === t.permission &&
|
|
132
|
-
(
|
|
133
|
-
this.
|
|
132
|
+
(N.info("Device successfully subscribed to push."),
|
|
133
|
+
this.qn(t.deviceToken, new Date(), e));
|
|
134
134
|
}
|
|
135
135
|
requestPermission(i, t, e) {
|
|
136
136
|
const s = (s) => {
|
|
@@ -142,245 +142,245 @@ export default class ea {
|
|
|
142
142
|
case "denied":
|
|
143
143
|
return void ("function" == typeof e && e());
|
|
144
144
|
default:
|
|
145
|
-
|
|
145
|
+
N.error("Received unexpected permission result " + s);
|
|
146
146
|
}
|
|
147
147
|
};
|
|
148
|
-
let
|
|
148
|
+
let r = !1;
|
|
149
149
|
if ("default" !== window.Notification.permission)
|
|
150
150
|
s(Notification.permission);
|
|
151
151
|
else {
|
|
152
152
|
const i = window.Notification.requestPermission((i) => {
|
|
153
|
-
|
|
153
|
+
r && s(i);
|
|
154
154
|
});
|
|
155
155
|
i
|
|
156
156
|
? i.then((i) => {
|
|
157
157
|
s(i);
|
|
158
158
|
})
|
|
159
|
-
: (
|
|
159
|
+
: (r = !0);
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
|
-
|
|
163
|
-
const
|
|
164
|
-
null != t && (
|
|
162
|
+
Vn(i, t, e, s) {
|
|
163
|
+
const r = { userVisibleOnly: !0 };
|
|
164
|
+
null != t && (r.applicationServerKey = t),
|
|
165
165
|
i.pushManager
|
|
166
|
-
.subscribe(
|
|
166
|
+
.subscribe(r)
|
|
167
167
|
.then((i) => {
|
|
168
|
-
|
|
169
|
-
this.
|
|
168
|
+
N.info("Device successfully subscribed to push."),
|
|
169
|
+
this.qn(i, new Date(), e);
|
|
170
170
|
})
|
|
171
171
|
.catch((i) => {
|
|
172
172
|
yt.isPushBlocked()
|
|
173
|
-
? (
|
|
173
|
+
? (N.info("Permission for push notifications was denied."),
|
|
174
174
|
"function" == typeof s && s(!1))
|
|
175
|
-
: (
|
|
175
|
+
: (N.error("Push subscription failed: " + i),
|
|
176
176
|
"function" == typeof s && s(!0));
|
|
177
177
|
});
|
|
178
178
|
}
|
|
179
|
-
|
|
180
|
-
if (this.
|
|
181
|
-
const i = this.
|
|
182
|
-
return navigator.serviceWorker.register(this.
|
|
179
|
+
Bn() {
|
|
180
|
+
if (this.Sn) return navigator.serviceWorker.getRegistration(this.kn);
|
|
181
|
+
const i = this.Pn ? { scope: this.Pn } : void 0;
|
|
182
|
+
return navigator.serviceWorker.register(this.kn, i).then(() =>
|
|
183
183
|
navigator.serviceWorker.ready.then(
|
|
184
184
|
(i) => (
|
|
185
185
|
i &&
|
|
186
186
|
"function" == typeof i.update &&
|
|
187
187
|
i.update().catch((i) => {
|
|
188
|
-
|
|
188
|
+
N.info("ServiceWorker update failed: " + i);
|
|
189
189
|
}),
|
|
190
190
|
i
|
|
191
191
|
),
|
|
192
192
|
),
|
|
193
193
|
);
|
|
194
194
|
}
|
|
195
|
-
|
|
196
|
-
this.
|
|
197
|
-
(i.unregister(),
|
|
195
|
+
Mn(i) {
|
|
196
|
+
this.Sn ||
|
|
197
|
+
(i.unregister(), N.info("Service worker successfully unregistered."));
|
|
198
198
|
}
|
|
199
|
-
subscribe(i,
|
|
199
|
+
subscribe(i, e) {
|
|
200
200
|
if (!yt.isPushSupported())
|
|
201
|
-
return
|
|
202
|
-
if (this.
|
|
203
|
-
if (!this.
|
|
204
|
-
let i = this.
|
|
201
|
+
return N.info(na.Yn), void ("function" == typeof e && e(!1));
|
|
202
|
+
if (this.Nn) {
|
|
203
|
+
if (!this.Sn && null != window.location) {
|
|
204
|
+
let i = this.kn;
|
|
205
205
|
-1 === i.indexOf(window.location.host) &&
|
|
206
206
|
(i = window.location.host + i),
|
|
207
207
|
-1 === i.indexOf(window.location.protocol) &&
|
|
208
208
|
(i = window.location.protocol + "//" + i);
|
|
209
209
|
}
|
|
210
210
|
if (yt.isPushBlocked())
|
|
211
|
-
return void this.
|
|
211
|
+
return void this.Fn(
|
|
212
212
|
"Notifications from this site are blocked. This may be a temporary embargo or a permanent denial.",
|
|
213
|
-
|
|
213
|
+
e,
|
|
214
214
|
);
|
|
215
|
-
if (this.
|
|
215
|
+
if (this.B && !this.B.Gn() && 0 === this.B.Es())
|
|
216
216
|
return (
|
|
217
|
-
|
|
217
|
+
N.info(
|
|
218
218
|
"Waiting for VAPID key from server config before subscribing to push.",
|
|
219
219
|
),
|
|
220
|
-
void this.
|
|
221
|
-
this.subscribe(i,
|
|
220
|
+
void this.B.Hn(() => {
|
|
221
|
+
this.subscribe(i, e);
|
|
222
222
|
})
|
|
223
223
|
);
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
"function" == typeof
|
|
224
|
+
const s = () => {
|
|
225
|
+
N.info("Permission for push notifications was denied."),
|
|
226
|
+
"function" == typeof e && e(!1);
|
|
227
227
|
},
|
|
228
|
-
|
|
228
|
+
r = () => {
|
|
229
229
|
let i = "Permission for push notifications was ignored.";
|
|
230
230
|
yt.isPushBlocked() &&
|
|
231
231
|
(i +=
|
|
232
232
|
" The browser has automatically blocked further permission requests for a period (probably 1 week)."),
|
|
233
|
-
|
|
234
|
-
"function" == typeof
|
|
233
|
+
N.info(i),
|
|
234
|
+
"function" == typeof e && e(!0);
|
|
235
235
|
},
|
|
236
236
|
n = yt.isPushPermissionGranted(),
|
|
237
|
-
|
|
237
|
+
o = () => {
|
|
238
238
|
!n &&
|
|
239
|
-
this.
|
|
240
|
-
this.
|
|
239
|
+
this.bn &&
|
|
240
|
+
this.bn.setPushNotificationSubscriptionType(
|
|
241
241
|
User.NotificationSubscriptionTypes.OPTED_IN,
|
|
242
242
|
),
|
|
243
|
-
this.
|
|
244
|
-
.then((
|
|
245
|
-
if (null ==
|
|
243
|
+
this.Bn()
|
|
244
|
+
.then((s) => {
|
|
245
|
+
if (null == s)
|
|
246
246
|
return (
|
|
247
|
-
|
|
247
|
+
N.error(
|
|
248
248
|
"No service worker registration. Set the `manageServiceWorkerExternally` initialization option to false or ensure that your service worker is registered before calling registerPush.",
|
|
249
249
|
),
|
|
250
|
-
void ("function" == typeof
|
|
250
|
+
void ("function" == typeof e && e(!0))
|
|
251
251
|
);
|
|
252
|
-
|
|
252
|
+
s.pushManager
|
|
253
253
|
.getSubscription()
|
|
254
|
-
.then((
|
|
254
|
+
.then((r) => {
|
|
255
255
|
var n;
|
|
256
|
-
let
|
|
256
|
+
let o = null;
|
|
257
257
|
if (
|
|
258
258
|
(null !=
|
|
259
|
-
(null === (n = this.
|
|
259
|
+
(null === (n = this.B) || void 0 === n
|
|
260
260
|
? void 0
|
|
261
|
-
: n.
|
|
262
|
-
|
|
261
|
+
: n.Gn()) && (o = ei.Jn(this.B.Gn())),
|
|
262
|
+
r)
|
|
263
263
|
) {
|
|
264
264
|
let n,
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if ((this.
|
|
265
|
+
u = null,
|
|
266
|
+
a = null;
|
|
267
|
+
if ((this.C && (n = this.C.ps(t.bs.Kn)), n && !w(n))) {
|
|
268
268
|
let i;
|
|
269
269
|
try {
|
|
270
|
-
i = ti.
|
|
270
|
+
i = ti.Qn(n).Ln;
|
|
271
271
|
} catch (t) {
|
|
272
272
|
i = null;
|
|
273
273
|
}
|
|
274
274
|
null == i ||
|
|
275
275
|
isNaN(i.getTime()) ||
|
|
276
276
|
0 === i.getTime() ||
|
|
277
|
-
((
|
|
278
|
-
(
|
|
279
|
-
|
|
277
|
+
((u = i),
|
|
278
|
+
(a = new Date(u)),
|
|
279
|
+
a.setMonth(u.getMonth() + 6));
|
|
280
280
|
}
|
|
281
|
-
null !=
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
!ii(
|
|
287
|
-
? (
|
|
288
|
-
?
|
|
281
|
+
null != o &&
|
|
282
|
+
r.options &&
|
|
283
|
+
r.options.applicationServerKey &&
|
|
284
|
+
r.options.applicationServerKey.byteLength &&
|
|
285
|
+
r.options.applicationServerKey.byteLength > 0 &&
|
|
286
|
+
!ii(o, new Uint8Array(r.options.applicationServerKey))
|
|
287
|
+
? (r.options.applicationServerKey.byteLength > 12
|
|
288
|
+
? N.info(
|
|
289
289
|
"Device was already subscribed to push using a different VAPID provider, creating new subscription.",
|
|
290
290
|
)
|
|
291
|
-
:
|
|
291
|
+
: N.info(
|
|
292
292
|
"Attempting to upgrade a gcm_sender_id-based push registration to VAPID - depending on the browser this may or may not result in the same gcm_sender_id-based subscription.",
|
|
293
293
|
),
|
|
294
|
-
this.
|
|
295
|
-
:
|
|
296
|
-
new Date(
|
|
294
|
+
this.In(r, s, o, i, e))
|
|
295
|
+
: r.expirationTime &&
|
|
296
|
+
new Date(r.expirationTime).valueOf() <=
|
|
297
297
|
new Date().valueOf()
|
|
298
|
-
? (
|
|
298
|
+
? (N.info(
|
|
299
299
|
"Push subscription is expired, creating new subscription.",
|
|
300
300
|
),
|
|
301
|
-
this.
|
|
302
|
-
: n &&
|
|
303
|
-
? this.
|
|
304
|
-
: null ==
|
|
305
|
-
? (
|
|
301
|
+
this.In(r, s, o, i, e))
|
|
302
|
+
: n && w(n)
|
|
303
|
+
? this.In(r, s, o, i, e)
|
|
304
|
+
: null == a
|
|
305
|
+
? (N.info(
|
|
306
306
|
"No push subscription creation date found, creating new subscription.",
|
|
307
307
|
),
|
|
308
|
-
this.
|
|
309
|
-
:
|
|
310
|
-
? (
|
|
308
|
+
this.In(r, s, o, i, e))
|
|
309
|
+
: a.valueOf() <= new Date().valueOf()
|
|
310
|
+
? (N.info(
|
|
311
311
|
"Push subscription older than 6 months, creating new subscription.",
|
|
312
312
|
),
|
|
313
|
-
this.
|
|
314
|
-
: (
|
|
313
|
+
this.In(r, s, o, i, e))
|
|
314
|
+
: (N.info(
|
|
315
315
|
"Device already subscribed to push, sending existing subscription to backend.",
|
|
316
316
|
),
|
|
317
|
-
this.
|
|
318
|
-
} else this.
|
|
317
|
+
this.qn(r, u, i));
|
|
318
|
+
} else this.Vn(s, o, i, e);
|
|
319
319
|
})
|
|
320
320
|
.catch((i) => {
|
|
321
|
-
|
|
321
|
+
N.error("Error checking current push subscriptions: " + i);
|
|
322
322
|
});
|
|
323
323
|
})
|
|
324
324
|
.catch((i) => {
|
|
325
|
-
|
|
325
|
+
N.error("ServiceWorker registration failed: " + i);
|
|
326
326
|
});
|
|
327
327
|
};
|
|
328
|
-
this.requestPermission(
|
|
329
|
-
} else if (this.
|
|
330
|
-
if (null == this.
|
|
328
|
+
this.requestPermission(o, r, s);
|
|
329
|
+
} else if (this.Wn) {
|
|
330
|
+
if (null == this.Dn || "" === this.Dn)
|
|
331
331
|
return (
|
|
332
|
-
|
|
332
|
+
N.error(
|
|
333
333
|
"You must supply the safariWebsitePushId initialization option in order to use registerPush on Safari",
|
|
334
334
|
),
|
|
335
|
-
void ("function" == typeof
|
|
335
|
+
void ("function" == typeof e && e(!0))
|
|
336
336
|
);
|
|
337
|
-
const
|
|
338
|
-
this.
|
|
337
|
+
const t = window.safari.pushNotification.permission(this.Dn);
|
|
338
|
+
this.On(this.Dn, t, i, e);
|
|
339
339
|
}
|
|
340
340
|
}
|
|
341
341
|
unsubscribe(i, t) {
|
|
342
342
|
if (!yt.isPushSupported())
|
|
343
|
-
return
|
|
344
|
-
this.
|
|
345
|
-
? navigator.serviceWorker.getRegistration(this.
|
|
343
|
+
return N.info(na.Yn), void ("function" == typeof t && t());
|
|
344
|
+
this.Nn
|
|
345
|
+
? navigator.serviceWorker.getRegistration(this.kn).then((e) => {
|
|
346
346
|
e
|
|
347
347
|
? e.pushManager
|
|
348
348
|
.getSubscription()
|
|
349
349
|
.then((s) => {
|
|
350
350
|
s
|
|
351
|
-
? (this.
|
|
351
|
+
? (this.Rn(),
|
|
352
352
|
s
|
|
353
353
|
.unsubscribe()
|
|
354
354
|
.then((s) => {
|
|
355
355
|
s
|
|
356
|
-
? (
|
|
356
|
+
? (N.info(
|
|
357
357
|
"Device successfully unsubscribed from push.",
|
|
358
358
|
),
|
|
359
359
|
"function" == typeof i && i())
|
|
360
|
-
: (
|
|
360
|
+
: (N.error(
|
|
361
361
|
"Failed to unsubscribe device from push.",
|
|
362
362
|
),
|
|
363
363
|
"function" == typeof t && t()),
|
|
364
|
-
this.
|
|
364
|
+
this.Mn(e);
|
|
365
365
|
})
|
|
366
366
|
.catch((i) => {
|
|
367
|
-
|
|
367
|
+
N.error("Push unsubscription error: " + i),
|
|
368
368
|
"function" == typeof t && t();
|
|
369
369
|
}))
|
|
370
|
-
: (
|
|
370
|
+
: (N.info("Device already unsubscribed from push."),
|
|
371
371
|
"function" == typeof i && i());
|
|
372
372
|
})
|
|
373
373
|
.catch((i) => {
|
|
374
|
-
|
|
374
|
+
N.error("Error unsubscribing from push: " + i),
|
|
375
375
|
"function" == typeof t && t();
|
|
376
376
|
})
|
|
377
|
-
: (
|
|
377
|
+
: (N.info("Device already unsubscribed from push."),
|
|
378
378
|
"function" == typeof i && i());
|
|
379
379
|
})
|
|
380
|
-
: this.
|
|
381
|
-
(this.
|
|
382
|
-
|
|
380
|
+
: this.Wn &&
|
|
381
|
+
(this.Rn(),
|
|
382
|
+
N.info("Device unsubscribed from push."),
|
|
383
383
|
"function" == typeof i && i());
|
|
384
384
|
}
|
|
385
385
|
}
|
|
386
|
-
|
|
386
|
+
na.Yn = "Push notifications are not supported in this browser.";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
export function requestPushPermission(
|
|
4
|
-
if (
|
|
5
|
-
return
|
|
6
|
-
const s =
|
|
7
|
-
s && s.requestImmediateDataFlush(), "function" == typeof
|
|
8
|
-
},
|
|
1
|
+
import r from "../managers/braze-instance.js";
|
|
2
|
+
import ra from "./push-manager-factory.js";
|
|
3
|
+
export function requestPushPermission(n, o) {
|
|
4
|
+
if (r.rr())
|
|
5
|
+
return ra.ea().subscribe((o, t, e) => {
|
|
6
|
+
const s = r.nn();
|
|
7
|
+
s && s.requestImmediateDataFlush(), "function" == typeof n && n(o, t, e);
|
|
8
|
+
}, o);
|
|
9
9
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
export function unregisterPush(
|
|
4
|
-
if (
|
|
1
|
+
import r from "../managers/braze-instance.js";
|
|
2
|
+
import ra from "./push-manager-factory.js";
|
|
3
|
+
export function unregisterPush(e, n) {
|
|
4
|
+
if (r.rr()) return ra.ea().unsubscribe(e, n);
|
|
5
5
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
const yt = {
|
|
2
|
-
|
|
2
|
+
Un: () =>
|
|
3
3
|
"serviceWorker" in navigator &&
|
|
4
4
|
"undefined" != typeof ServiceWorkerRegistration &&
|
|
5
5
|
"showNotification" in ServiceWorkerRegistration.prototype &&
|
|
6
6
|
"PushManager" in window,
|
|
7
|
-
|
|
7
|
+
_n: () =>
|
|
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: () => yt.
|
|
12
|
+
isPushSupported: () => yt.Un() || yt._n(),
|
|
13
13
|
isPushBlocked: () => {
|
|
14
14
|
const i =
|
|
15
15
|
yt.isPushSupported() &&
|
|
@@ -28,7 +28,7 @@ const yt = {
|
|
|
28
28
|
null != window.Notification &&
|
|
29
29
|
null != window.Notification.permission &&
|
|
30
30
|
"granted" === window.Notification.permission,
|
|
31
|
-
|
|
31
|
+
Ur: () =>
|
|
32
32
|
!yt.isPushBlocked() &&
|
|
33
33
|
yt.isPushSupported() &&
|
|
34
34
|
!yt.isPushPermissionGranted(),
|