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