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