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