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