@braze/web-sdk 6.10.2 → 6.12.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 +61 -6
- package/package.json +1 -1
- package/shared-lib/encoding-utils.js +3 -3
- package/shared-lib/event-types.js +12 -12
- package/shared-lib/indexed-db-adapter.js +52 -52
- package/shared-lib/logger.js +7 -7
- package/shared-lib/supported-options.js +10 -10
- package/src/Core/logout.js +2 -2
- package/src/DUST/dust-config-store.js +89 -0
- package/src/DUST/dust-connection-core.js +7 -21
- package/src/DUST/dust-message-dedup.js +33 -0
- package/src/DUST/dust-provider.js +367 -397
- package/src/DUST/dust-tab-identity.js +30 -0
- package/src/DUST/index.js +7 -9
- package/src/DUST/subscribe-to-dust.js +5 -5
- package/src/FeatureFlags/feature-flag-factory.js +4 -4
- package/src/FeatureFlags/feature-flag.js +5 -5
- package/src/FeatureFlags/feature-flags-provider-factory.js +8 -1
- package/src/FeatureFlags/feature-flags-provider.js +74 -74
- package/src/FeatureFlags/get-all-feature-flags.js +2 -2
- package/src/FeatureFlags/get-feature-flag.js +2 -2
- package/src/FeatureFlags/log-feature-flag-impression.js +3 -3
- package/src/FeatureFlags/subscribe-to-feature-flags-updates.js +1 -1
- package/src/InAppMessage/constants.js +39 -47
- package/src/InAppMessage/defer-in-app-message.js +2 -2
- package/src/InAppMessage/display/get-animation-effect.js +1 -1
- package/src/InAppMessage/display/html-message-display-utils.js +4 -4
- package/src/InAppMessage/display/html-message-to-html.js +10 -10
- package/src/InAppMessage/display/in-app-message-to-html.js +68 -66
- package/src/InAppMessage/display/modal-utils.js +14 -14
- package/src/InAppMessage/get-deferred-in-app-message.js +2 -2
- package/src/InAppMessage/in-app-message-factory.js +6 -6
- package/src/InAppMessage/in-app-message-manager-factory.js +5 -5
- package/src/InAppMessage/in-app-message-manager.js +101 -80
- package/src/InAppMessage/log-in-app-message-button-click.js +2 -2
- package/src/InAppMessage/log-in-app-message-click.js +2 -2
- package/src/InAppMessage/log-in-app-message-html-click.js +4 -4
- package/src/InAppMessage/log-in-app-message-impression.js +3 -3
- package/src/InAppMessage/models/full-screen-message.js +25 -25
- package/src/InAppMessage/models/html-message.js +14 -14
- package/src/InAppMessage/models/in-app-message-button.js +4 -4
- package/src/InAppMessage/models/in-app-message.js +100 -98
- package/src/InAppMessage/models/modal-message.js +23 -23
- package/src/InAppMessage/models/slide-up-message.js +29 -29
- 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 +2 -2
- package/src/InAppMessage/ui/show-in-app-message.js +42 -40
- package/src/Push/index.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 +6 -6
- package/src/Push/push-manager.js +228 -185
- package/src/Push/register-push.js +9 -0
- package/src/Push/unregister-push-token-on-server.js +4 -4
- package/src/Push/utils/push-utils.js +16 -16
- package/src/User/user-manager.js +19 -19
- package/src/User/user.js +36 -36
- package/src/common/constants.js +1 -1
- package/src/common/content-cards-display.js +21 -21
- package/src/common/event-logger.js +2 -2
- package/src/l10n/l10n-manager-factory.js +7 -7
- package/src/l10n/l10n-manager.js +5 -5
- package/src/managers/auth-manager.js +1 -1
- package/src/managers/braze-instance.js +70 -66
- package/src/managers/device-manager.js +12 -12
- package/src/managers/network-manager.js +118 -118
- package/src/managers/server-config-manager.js +84 -84
- package/src/managers/session-manager.js +10 -10
- package/src/managers/storage-manager-factory.js +4 -4
- package/src/managers/storage-manager.js +138 -136
- package/src/managers/subscription-manager.js +1 -1
- package/src/managers/utils.js +1 -1
- 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 +6 -6
- package/src/models/push-token.js +6 -6
- package/src/models/server-config.js +31 -31
- package/src/request-controller.js +91 -91
- package/src/triggers/models/filter.js +58 -58
- package/src/triggers/models/in-app-message-click-data.js +4 -4
- package/src/triggers/models/push-click-data.js +2 -2
- package/src/triggers/models/trigger-condition.js +35 -35
- package/src/triggers/models/trigger.js +37 -37
- package/src/triggers/triggers-provider-factory.js +3 -3
- package/src/triggers/triggers-provider.js +61 -53
- package/src/types.js +1 -1
- package/src/ui/js/attach-css.js +1 -1
- package/src/ui/js/feed-css.js +2 -2
- package/src/ui/js/iam-css.js +2 -2
- package/src/util/base-device-parser.js +1 -1
- package/src/util/braze-actions.js +4 -4
- package/src/util/browser-detector.js +13 -13
- package/src/util/client-hints-parser.js +4 -4
- package/src/util/component-utils.js +4 -4
- package/src/util/dom-utils.js +5 -5
- package/src/util/ecommerce-event-validation.js +77 -48
- package/src/util/key-codes.js +1 -1
- package/src/util/net.js +4 -4
- package/src/util/request-header-utils.js +20 -20
- package/src/util/string-utils.js +5 -0
- package/src/util/user-agent-parser.js +15 -15
- package/src/util/validation-utils.js +9 -9
- package/src/util/window-utils.js +2 -2
- package/src/DUST/dust-shared-worker-code.js +0 -2
- package/src/DUST/dust-shared-worker-impl.js +0 -234
- package/src/DUST/dust-worker-bridge.js +0 -151
package/src/Push/push-manager.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import ui from "../models/push-token.js";
|
|
3
|
-
import { logger as b, EncodingUtils as ai } from "../../shared-lib/index.js";
|
|
1
|
+
import { EncodingUtils as oi, logger as b } from "../../shared-lib/index.js";
|
|
4
2
|
import { STORAGE_KEYS as s } from "../managers/storage-manager.js";
|
|
3
|
+
import ui from "../models/push-token.js";
|
|
5
4
|
import { User } from "../User/index.js";
|
|
6
|
-
import
|
|
7
|
-
import { getErrorMessage as
|
|
5
|
+
import { isArray as g, isEqual as hi } from "../util/code-utils.js";
|
|
6
|
+
import { getErrorMessage as ci } from "../util/error-utils.js";
|
|
7
|
+
import Dt from "./utils/push-utils.js";
|
|
8
8
|
export default class na {
|
|
9
|
-
constructor(i,
|
|
9
|
+
constructor(i, e, t, s, r, o, n, u, h, a, c) {
|
|
10
10
|
(this.iu = i),
|
|
11
|
-
(this.tu = t),
|
|
12
11
|
(this.eu = e),
|
|
12
|
+
(this.tu = t),
|
|
13
13
|
(this.su = r),
|
|
14
|
-
(this.ru =
|
|
15
|
-
(this.
|
|
14
|
+
(this.ru = o),
|
|
15
|
+
(this.ou = n),
|
|
16
16
|
(this.h = u),
|
|
17
|
-
(this.
|
|
18
|
-
(this.uu =
|
|
17
|
+
(this.nu = h),
|
|
18
|
+
(this.uu = a),
|
|
19
19
|
(this.j = c),
|
|
20
20
|
(this.iu = i),
|
|
21
|
-
(this.tu = t),
|
|
22
21
|
(this.eu = e),
|
|
23
|
-
(this.
|
|
22
|
+
(this.tu = t),
|
|
23
|
+
(this.hu = s + "/safari/" + e),
|
|
24
24
|
(this.su = r || "/service-worker.js"),
|
|
25
|
-
(this.
|
|
25
|
+
(this.ou = n),
|
|
26
26
|
(this.h = u),
|
|
27
|
-
(this.
|
|
28
|
-
(this.uu =
|
|
27
|
+
(this.nu = h || !1),
|
|
28
|
+
(this.uu = a || !1),
|
|
29
29
|
(this.j = c),
|
|
30
|
-
(this.
|
|
31
|
-
(this.fu =
|
|
30
|
+
(this.au = Dt.cu()),
|
|
31
|
+
(this.fu = Dt.du());
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
lu() {
|
|
34
34
|
return this.uu;
|
|
35
35
|
}
|
|
36
|
-
pu(i,
|
|
36
|
+
pu(i, e, t, s, r) {
|
|
37
37
|
i.unsubscribe()
|
|
38
38
|
.then((i) => {
|
|
39
39
|
i
|
|
40
|
-
? this.bu(
|
|
40
|
+
? this.bu(e, t, s, r)
|
|
41
41
|
: (b.error("Failed to unsubscribe device from push."),
|
|
42
42
|
"function" == typeof r && r(!1));
|
|
43
43
|
})
|
|
@@ -46,101 +46,101 @@ export default class na {
|
|
|
46
46
|
"function" == typeof r && r(!1);
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
mu(i, e, t) {
|
|
50
50
|
var s;
|
|
51
51
|
const r = ((i) => {
|
|
52
52
|
if ("string" == typeof i) return i;
|
|
53
53
|
if (0 !== i.endpoint.indexOf("https://android.googleapis.com/gcm/send"))
|
|
54
54
|
return i.endpoint;
|
|
55
|
-
let
|
|
56
|
-
const
|
|
55
|
+
let e = i.endpoint;
|
|
56
|
+
const t = i;
|
|
57
57
|
return (
|
|
58
|
-
|
|
59
|
-
-1 === i.endpoint.indexOf(
|
|
60
|
-
(
|
|
61
|
-
|
|
58
|
+
t.gu &&
|
|
59
|
+
-1 === i.endpoint.indexOf(t.gu) &&
|
|
60
|
+
(e = i.endpoint + "/" + t.gu),
|
|
61
|
+
e
|
|
62
62
|
);
|
|
63
63
|
})(i);
|
|
64
|
-
let
|
|
65
|
-
|
|
64
|
+
let o = null,
|
|
65
|
+
n = null;
|
|
66
66
|
const u = i;
|
|
67
67
|
if (null != u.getKey)
|
|
68
68
|
try {
|
|
69
69
|
const i = Array.from(new Uint8Array(u.getKey("p256dh"))),
|
|
70
|
-
|
|
71
|
-
(
|
|
72
|
-
(
|
|
70
|
+
e = Array.from(new Uint8Array(u.getKey("auth")));
|
|
71
|
+
(o = btoa(String.fromCharCode.apply(null, i))),
|
|
72
|
+
(n = btoa(String.fromCharCode.apply(null, e)));
|
|
73
73
|
} catch (i) {
|
|
74
|
-
b.error(
|
|
74
|
+
b.error(ci(i));
|
|
75
75
|
}
|
|
76
|
-
const
|
|
77
|
-
let
|
|
76
|
+
const h = ((i) => {
|
|
77
|
+
let e;
|
|
78
78
|
return i.options &&
|
|
79
|
-
(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
? btoa(String.fromCharCode.apply(null, Array.from(new Uint8Array(
|
|
79
|
+
(e = i.options.applicationServerKey) &&
|
|
80
|
+
e.byteLength &&
|
|
81
|
+
e.byteLength > 0
|
|
82
|
+
? btoa(String.fromCharCode.apply(null, Array.from(new Uint8Array(e))))
|
|
83
83
|
.replace(/\+/g, "-")
|
|
84
84
|
.replace(/\//g, "_")
|
|
85
85
|
: null;
|
|
86
86
|
})(u);
|
|
87
|
-
null === (s = this.iu) || void 0 === s || s.
|
|
88
|
-
r && "function" == typeof
|
|
87
|
+
null === (s = this.iu) || void 0 === s || s.yu(r, e, o, n, h),
|
|
88
|
+
r && "function" == typeof t && t(r, o, n);
|
|
89
89
|
}
|
|
90
90
|
vu() {
|
|
91
91
|
var i;
|
|
92
92
|
null === (i = this.iu) || void 0 === i || i.wu(!0);
|
|
93
93
|
}
|
|
94
|
-
|
|
95
|
-
var
|
|
96
|
-
null === (
|
|
94
|
+
Pu(i, e) {
|
|
95
|
+
var t;
|
|
96
|
+
null === (t = this.iu) || void 0 === t || t.wu(!1),
|
|
97
97
|
b.info(i),
|
|
98
|
-
"function" == typeof
|
|
98
|
+
"function" == typeof e && e(!1);
|
|
99
99
|
}
|
|
100
|
-
|
|
100
|
+
ku(i, e, t, s) {
|
|
101
101
|
var r;
|
|
102
|
-
if ("default" ===
|
|
102
|
+
if ("default" === e.permission)
|
|
103
103
|
try {
|
|
104
104
|
window.safari.pushNotification.requestPermission(
|
|
105
|
-
this.
|
|
105
|
+
this.hu,
|
|
106
106
|
i,
|
|
107
107
|
{
|
|
108
|
-
api_key: this.
|
|
108
|
+
api_key: this.eu,
|
|
109
109
|
device_id:
|
|
110
|
-
(null === (r = this.
|
|
110
|
+
(null === (r = this.tu) || void 0 === r ? void 0 : r.ve().id) ||
|
|
111
111
|
"",
|
|
112
112
|
},
|
|
113
|
-
(
|
|
114
|
-
"granted" ===
|
|
113
|
+
(e) => {
|
|
114
|
+
"granted" === e.permission &&
|
|
115
115
|
this.iu &&
|
|
116
116
|
this.iu.setPushNotificationSubscriptionType(
|
|
117
117
|
User.NotificationSubscriptionTypes.OPTED_IN,
|
|
118
118
|
),
|
|
119
|
-
this.
|
|
119
|
+
this.ku(i, e, t, s);
|
|
120
120
|
},
|
|
121
121
|
);
|
|
122
122
|
} catch (i) {
|
|
123
|
-
this.
|
|
123
|
+
this.Pu("Could not request permission for push: " + i, s);
|
|
124
124
|
}
|
|
125
125
|
else
|
|
126
|
-
"denied" ===
|
|
127
|
-
? this.
|
|
126
|
+
"denied" === e.permission
|
|
127
|
+
? this.Pu(
|
|
128
128
|
"The user has blocked notifications from this site, or Safari push is not configured in the Braze dashboard.",
|
|
129
129
|
s,
|
|
130
130
|
)
|
|
131
|
-
: "granted" ===
|
|
131
|
+
: "granted" === e.permission &&
|
|
132
132
|
(b.info("Device successfully subscribed to push."),
|
|
133
|
-
this.
|
|
133
|
+
this.mu(e.deviceToken, new Date(), t));
|
|
134
134
|
}
|
|
135
|
-
requestPermission(i,
|
|
135
|
+
requestPermission(i, e, t) {
|
|
136
136
|
const s = (s) => {
|
|
137
137
|
switch (s) {
|
|
138
138
|
case "granted":
|
|
139
139
|
return void ("function" == typeof i && i());
|
|
140
140
|
case "default":
|
|
141
|
-
return void ("function" == typeof t && t());
|
|
142
|
-
case "denied":
|
|
143
141
|
return void ("function" == typeof e && e());
|
|
142
|
+
case "denied":
|
|
143
|
+
return void ("function" == typeof t && t());
|
|
144
144
|
default:
|
|
145
145
|
b.error("Received unexpected permission result " + s);
|
|
146
146
|
}
|
|
@@ -159,17 +159,17 @@ export default class na {
|
|
|
159
159
|
: (r = !0);
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
|
-
bu(i,
|
|
162
|
+
bu(i, e, t, s) {
|
|
163
163
|
const r = { userVisibleOnly: !0 };
|
|
164
|
-
null !=
|
|
164
|
+
null != e && (r.applicationServerKey = e),
|
|
165
165
|
i.pushManager
|
|
166
166
|
.subscribe(r)
|
|
167
167
|
.then((i) => {
|
|
168
168
|
b.info("Device successfully subscribed to push."),
|
|
169
|
-
this.
|
|
169
|
+
this.mu(i, new Date(), t);
|
|
170
170
|
})
|
|
171
171
|
.catch((i) => {
|
|
172
|
-
|
|
172
|
+
Dt.isPushBlocked()
|
|
173
173
|
? (b.info("Permission for push notifications was denied."),
|
|
174
174
|
"function" == typeof s && s(!1))
|
|
175
175
|
: (b.error("Push subscription failed: " + i),
|
|
@@ -177,7 +177,7 @@ export default class na {
|
|
|
177
177
|
});
|
|
178
178
|
}
|
|
179
179
|
Du() {
|
|
180
|
-
if (this.
|
|
180
|
+
if (this.nu) return navigator.serviceWorker.getRegistration(this.su);
|
|
181
181
|
const i = this.ru ? { scope: this.ru } : void 0;
|
|
182
182
|
return navigator.serviceWorker.register(this.su, i).then(() =>
|
|
183
183
|
navigator.serviceWorker.ready.then(
|
|
@@ -193,158 +193,201 @@ export default class na {
|
|
|
193
193
|
);
|
|
194
194
|
}
|
|
195
195
|
Su(i) {
|
|
196
|
-
this.
|
|
196
|
+
this.nu ||
|
|
197
197
|
(i.unregister(), b.info("Service worker successfully unregistered."));
|
|
198
198
|
}
|
|
199
|
-
subscribe(i,
|
|
200
|
-
if (!
|
|
201
|
-
return b.info(na.Au), void ("function" == typeof
|
|
202
|
-
if (this.
|
|
203
|
-
if (!this.
|
|
199
|
+
subscribe(i, e) {
|
|
200
|
+
if (!Dt.isPushSupported())
|
|
201
|
+
return b.info(na.Au), void ("function" == typeof e && e(!1));
|
|
202
|
+
if (this.au) {
|
|
203
|
+
if (!this.nu && null != window.location) {
|
|
204
204
|
let i = this.su;
|
|
205
205
|
-1 === i.indexOf(window.location.host) &&
|
|
206
206
|
(i = window.location.host + i),
|
|
207
207
|
-1 === i.indexOf(window.location.protocol) &&
|
|
208
208
|
(i = window.location.protocol + "//" + i);
|
|
209
209
|
}
|
|
210
|
-
if (
|
|
211
|
-
return void this.
|
|
210
|
+
if (Dt.isPushBlocked())
|
|
211
|
+
return void this.Pu(
|
|
212
212
|
"Notifications from this site are blocked. This may be a temporary embargo or a permanent denial.",
|
|
213
|
-
|
|
213
|
+
e,
|
|
214
214
|
);
|
|
215
|
-
if (this.h && !this.h.
|
|
215
|
+
if (this.h && !this.h.Wu() && 0 === this.h.Qt())
|
|
216
216
|
return (
|
|
217
217
|
b.info(
|
|
218
218
|
"Waiting for VAPID key from server config before subscribing to push.",
|
|
219
219
|
),
|
|
220
|
-
void this.h.
|
|
221
|
-
this.subscribe(i,
|
|
220
|
+
void this.h.ju(() => {
|
|
221
|
+
this.subscribe(i, e);
|
|
222
222
|
})
|
|
223
223
|
);
|
|
224
|
-
const
|
|
224
|
+
const t = () => {
|
|
225
225
|
b.info("Permission for push notifications was denied."),
|
|
226
|
-
"function" == typeof
|
|
226
|
+
"function" == typeof e && e(!1);
|
|
227
227
|
},
|
|
228
|
-
|
|
228
|
+
s = () => {
|
|
229
229
|
let i = "Permission for push notifications was ignored.";
|
|
230
|
-
|
|
230
|
+
Dt.isPushBlocked() &&
|
|
231
231
|
(i +=
|
|
232
232
|
" The browser has automatically blocked further permission requests for a period (probably 1 week)."),
|
|
233
233
|
b.info(i),
|
|
234
|
-
"function" == typeof
|
|
234
|
+
"function" == typeof e && e(!0);
|
|
235
235
|
},
|
|
236
|
-
|
|
236
|
+
r = Dt.isPushPermissionGranted(),
|
|
237
237
|
o = () => {
|
|
238
|
-
!
|
|
238
|
+
!r &&
|
|
239
239
|
this.iu &&
|
|
240
240
|
this.iu.setPushNotificationSubscriptionType(
|
|
241
241
|
User.NotificationSubscriptionTypes.OPTED_IN,
|
|
242
242
|
),
|
|
243
|
-
this.
|
|
244
|
-
.then((e) => {
|
|
245
|
-
if (null == e)
|
|
246
|
-
return (
|
|
247
|
-
b.error(
|
|
248
|
-
"No service worker registration. Set the `manageServiceWorkerExternally` initialization option to false or ensure that your service worker is registered before calling registerPush.",
|
|
249
|
-
),
|
|
250
|
-
void ("function" == typeof t && t(!0))
|
|
251
|
-
);
|
|
252
|
-
e.pushManager
|
|
253
|
-
.getSubscription()
|
|
254
|
-
.then((r) => {
|
|
255
|
-
var n;
|
|
256
|
-
let o = null;
|
|
257
|
-
if (
|
|
258
|
-
(null !=
|
|
259
|
-
(null === (n = this.h) || void 0 === n
|
|
260
|
-
? void 0
|
|
261
|
-
: n.ju()) && (o = ai.Nu(this.h.ju())),
|
|
262
|
-
r)
|
|
263
|
-
) {
|
|
264
|
-
let n,
|
|
265
|
-
u = null,
|
|
266
|
-
a = null;
|
|
267
|
-
if ((this.j && (n = this.j.St(s.It.Uu)), n && !g(n))) {
|
|
268
|
-
let i;
|
|
269
|
-
try {
|
|
270
|
-
i = ui._u(n).Wu;
|
|
271
|
-
} catch (t) {
|
|
272
|
-
i = null;
|
|
273
|
-
}
|
|
274
|
-
null == i ||
|
|
275
|
-
isNaN(i.getTime()) ||
|
|
276
|
-
0 === i.getTime() ||
|
|
277
|
-
((u = i),
|
|
278
|
-
(a = new Date(u)),
|
|
279
|
-
a.setMonth(u.getMonth() + 6));
|
|
280
|
-
}
|
|
281
|
-
null != o &&
|
|
282
|
-
r.options &&
|
|
283
|
-
r.options.applicationServerKey &&
|
|
284
|
-
r.options.applicationServerKey.byteLength &&
|
|
285
|
-
r.options.applicationServerKey.byteLength > 0 &&
|
|
286
|
-
!oi(o, new Uint8Array(r.options.applicationServerKey))
|
|
287
|
-
? (r.options.applicationServerKey.byteLength > 12
|
|
288
|
-
? b.info(
|
|
289
|
-
"Device was already subscribed to push using a different VAPID provider, creating new subscription.",
|
|
290
|
-
)
|
|
291
|
-
: b.info(
|
|
292
|
-
"Attempting to upgrade a gcm_sender_id-based push registration to VAPID - depending on the browser this may or may not result in the same gcm_sender_id-based subscription.",
|
|
293
|
-
),
|
|
294
|
-
this.pu(r, e, o, i, t))
|
|
295
|
-
: r.expirationTime &&
|
|
296
|
-
new Date(r.expirationTime).valueOf() <=
|
|
297
|
-
new Date().valueOf()
|
|
298
|
-
? (b.info(
|
|
299
|
-
"Push subscription is expired, creating new subscription.",
|
|
300
|
-
),
|
|
301
|
-
this.pu(r, e, o, i, t))
|
|
302
|
-
: n && g(n)
|
|
303
|
-
? this.pu(r, e, o, i, t)
|
|
304
|
-
: null == a
|
|
305
|
-
? (b.info(
|
|
306
|
-
"No push subscription creation date found, creating new subscription.",
|
|
307
|
-
),
|
|
308
|
-
this.pu(r, e, o, i, t))
|
|
309
|
-
: a.valueOf() <= new Date().valueOf()
|
|
310
|
-
? (b.info(
|
|
311
|
-
"Push subscription older than 6 months, creating new subscription.",
|
|
312
|
-
),
|
|
313
|
-
this.pu(r, e, o, i, t))
|
|
314
|
-
: (b.info(
|
|
315
|
-
"Device already subscribed to push, sending existing subscription to backend.",
|
|
316
|
-
),
|
|
317
|
-
this.yu(r, u, i));
|
|
318
|
-
} else this.bu(e, o, i, t);
|
|
319
|
-
})
|
|
320
|
-
.catch((i) => {
|
|
321
|
-
b.error("Error checking current push subscriptions: " + i);
|
|
322
|
-
});
|
|
323
|
-
})
|
|
324
|
-
.catch((i) => {
|
|
325
|
-
b.error("ServiceWorker registration failed: " + i);
|
|
326
|
-
});
|
|
243
|
+
this.Nu(i, e);
|
|
327
244
|
};
|
|
328
|
-
this.requestPermission(o,
|
|
245
|
+
this.requestPermission(o, s, t);
|
|
329
246
|
} else if (this.fu) {
|
|
330
|
-
if (null == this.
|
|
247
|
+
if (null == this.ou || "" === this.ou)
|
|
331
248
|
return (
|
|
332
249
|
b.error(
|
|
333
250
|
"You must supply the safariWebsitePushId initialization option in order to use registerPush on Safari",
|
|
334
251
|
),
|
|
335
|
-
void ("function" == typeof
|
|
252
|
+
void ("function" == typeof e && e(!0))
|
|
336
253
|
);
|
|
337
|
-
const
|
|
338
|
-
this.
|
|
254
|
+
const t = window.safari.pushNotification.permission(this.ou);
|
|
255
|
+
this.ku(this.ou, t, i, e);
|
|
339
256
|
}
|
|
340
257
|
}
|
|
341
|
-
|
|
342
|
-
if (!
|
|
258
|
+
registerPush(i, e) {
|
|
259
|
+
if (!Dt.isPushSupported())
|
|
260
|
+
return b.info(na.Au), void ("function" == typeof e && e(!1));
|
|
261
|
+
if (this.au) {
|
|
262
|
+
if (Dt.isPushBlocked())
|
|
263
|
+
return void this.Pu(
|
|
264
|
+
"Notifications from this site are blocked. This may be a temporary embargo or a permanent denial.",
|
|
265
|
+
e,
|
|
266
|
+
);
|
|
267
|
+
if (this.h && !this.h.Wu() && 0 === this.h.Qt())
|
|
268
|
+
return (
|
|
269
|
+
b.info(
|
|
270
|
+
"Waiting for VAPID key from server config before registering push.",
|
|
271
|
+
),
|
|
272
|
+
void this.h.ju(() => {
|
|
273
|
+
this.registerPush(i, e);
|
|
274
|
+
})
|
|
275
|
+
);
|
|
276
|
+
if (!Dt.isPushPermissionGranted())
|
|
277
|
+
return void b.info(
|
|
278
|
+
"Push permission has not been granted, so registerPush is a no-op. Call requestPushPermission to prompt the user for permission.",
|
|
279
|
+
);
|
|
280
|
+
this.Nu(i, e);
|
|
281
|
+
} else if (this.fu) {
|
|
282
|
+
if (null == this.ou || "" === this.ou)
|
|
283
|
+
return (
|
|
284
|
+
b.error(
|
|
285
|
+
"You must supply the safariWebsitePushId initialization option in order to use registerPush on Safari",
|
|
286
|
+
),
|
|
287
|
+
void ("function" == typeof e && e(!0))
|
|
288
|
+
);
|
|
289
|
+
const t = window.safari.pushNotification.permission(this.ou);
|
|
290
|
+
"granted" === t.permission
|
|
291
|
+
? this.ku(this.ou, t, i, e)
|
|
292
|
+
: "denied" === t.permission
|
|
293
|
+
? this.Pu(
|
|
294
|
+
"The user has blocked notifications from this site, or Safari push is not configured in the Braze dashboard.",
|
|
295
|
+
e,
|
|
296
|
+
)
|
|
297
|
+
: b.info(
|
|
298
|
+
"Push permission has not been granted, so registerPush is a no-op. Call requestPushPermission to prompt the user for permission.",
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
Nu(i, e) {
|
|
303
|
+
this.Du()
|
|
304
|
+
.then((t) => {
|
|
305
|
+
if (null == t)
|
|
306
|
+
return (
|
|
307
|
+
b.error(
|
|
308
|
+
"No service worker registration. Set the `manageServiceWorkerExternally` initialization option to false or ensure that your service worker is registered before calling registerPush.",
|
|
309
|
+
),
|
|
310
|
+
void ("function" == typeof e && e(!0))
|
|
311
|
+
);
|
|
312
|
+
t.pushManager
|
|
313
|
+
.getSubscription()
|
|
314
|
+
.then((r) => {
|
|
315
|
+
var o;
|
|
316
|
+
let n = null;
|
|
317
|
+
if (
|
|
318
|
+
(null !=
|
|
319
|
+
(null === (o = this.h) || void 0 === o ? void 0 : o.Wu()) &&
|
|
320
|
+
(n = oi.Tu(this.h.Wu())),
|
|
321
|
+
r)
|
|
322
|
+
) {
|
|
323
|
+
let o,
|
|
324
|
+
u = null,
|
|
325
|
+
h = null;
|
|
326
|
+
if ((this.j && (o = this.j.St(s.It.xu)), o && !g(o))) {
|
|
327
|
+
let i;
|
|
328
|
+
try {
|
|
329
|
+
i = ui._u(o).Uu;
|
|
330
|
+
} catch (e) {
|
|
331
|
+
i = null;
|
|
332
|
+
}
|
|
333
|
+
null == i ||
|
|
334
|
+
isNaN(i.getTime()) ||
|
|
335
|
+
0 === i.getTime() ||
|
|
336
|
+
((u = i), (h = new Date(u)), h.setMonth(u.getMonth() + 6));
|
|
337
|
+
}
|
|
338
|
+
null != n &&
|
|
339
|
+
r.options &&
|
|
340
|
+
r.options.applicationServerKey &&
|
|
341
|
+
r.options.applicationServerKey.byteLength &&
|
|
342
|
+
r.options.applicationServerKey.byteLength > 0 &&
|
|
343
|
+
!hi(n, new Uint8Array(r.options.applicationServerKey))
|
|
344
|
+
? (r.options.applicationServerKey.byteLength > 12
|
|
345
|
+
? b.info(
|
|
346
|
+
"Device was already subscribed to push using a different VAPID provider, creating new subscription.",
|
|
347
|
+
)
|
|
348
|
+
: b.info(
|
|
349
|
+
"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.",
|
|
350
|
+
),
|
|
351
|
+
this.pu(r, t, n, i, e))
|
|
352
|
+
: r.expirationTime &&
|
|
353
|
+
new Date(r.expirationTime).valueOf() <= new Date().valueOf()
|
|
354
|
+
? (b.info(
|
|
355
|
+
"Push subscription is expired, creating new subscription.",
|
|
356
|
+
),
|
|
357
|
+
this.pu(r, t, n, i, e))
|
|
358
|
+
: o && g(o)
|
|
359
|
+
? this.pu(r, t, n, i, e)
|
|
360
|
+
: null == h
|
|
361
|
+
? (b.info(
|
|
362
|
+
"No push subscription creation date found, creating new subscription.",
|
|
363
|
+
),
|
|
364
|
+
this.pu(r, t, n, i, e))
|
|
365
|
+
: h.valueOf() <= new Date().valueOf()
|
|
366
|
+
? (b.info(
|
|
367
|
+
"Push subscription older than 6 months, creating new subscription.",
|
|
368
|
+
),
|
|
369
|
+
this.pu(r, t, n, i, e))
|
|
370
|
+
: (b.info(
|
|
371
|
+
"Device already subscribed to push, sending existing subscription to backend.",
|
|
372
|
+
),
|
|
373
|
+
this.mu(r, u, i));
|
|
374
|
+
} else this.bu(t, n, i, e);
|
|
375
|
+
})
|
|
376
|
+
.catch((i) => {
|
|
377
|
+
b.error("Error checking current push subscriptions: " + i);
|
|
378
|
+
});
|
|
379
|
+
})
|
|
380
|
+
.catch((i) => {
|
|
381
|
+
b.error("ServiceWorker registration failed: " + i);
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
unsubscribe(i, e) {
|
|
385
|
+
if (!Dt.isPushSupported())
|
|
343
386
|
return b.info(na.Au), void ("function" == typeof i && i());
|
|
344
|
-
this.
|
|
345
|
-
? navigator.serviceWorker.getRegistration(this.su).then((
|
|
346
|
-
|
|
347
|
-
?
|
|
387
|
+
this.au
|
|
388
|
+
? navigator.serviceWorker.getRegistration(this.su).then((t) => {
|
|
389
|
+
t
|
|
390
|
+
? t.pushManager
|
|
348
391
|
.getSubscription()
|
|
349
392
|
.then((s) => {
|
|
350
393
|
s
|
|
@@ -360,19 +403,19 @@ export default class na {
|
|
|
360
403
|
: (b.error(
|
|
361
404
|
"Failed to unsubscribe device from push.",
|
|
362
405
|
),
|
|
363
|
-
"function" == typeof
|
|
364
|
-
this.Su(
|
|
406
|
+
"function" == typeof e && e()),
|
|
407
|
+
this.Su(t);
|
|
365
408
|
})
|
|
366
409
|
.catch((i) => {
|
|
367
410
|
b.error("Push unsubscription error: " + i),
|
|
368
|
-
"function" == typeof
|
|
411
|
+
"function" == typeof e && e();
|
|
369
412
|
}))
|
|
370
413
|
: (b.info("Device already unsubscribed from push."),
|
|
371
414
|
"function" == typeof i && i());
|
|
372
415
|
})
|
|
373
416
|
.catch((i) => {
|
|
374
417
|
b.error("Error unsubscribing from push: " + i),
|
|
375
|
-
"function" == typeof
|
|
418
|
+
"function" == typeof e && e();
|
|
376
419
|
})
|
|
377
420
|
: (b.info("Device already unsubscribed from push."),
|
|
378
421
|
"function" == typeof i && i());
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import r from "../managers/braze-instance.js";
|
|
2
|
+
import ra from "./push-manager-factory.js";
|
|
3
|
+
export function registerPush(t, n) {
|
|
4
|
+
if (r.rr())
|
|
5
|
+
return ra.ra().registerPush((n, o, e) => {
|
|
6
|
+
const s = r.nn();
|
|
7
|
+
s && s.requestImmediateDataFlush(), "function" == typeof t && t(n, o, e);
|
|
8
|
+
}, n);
|
|
9
|
+
}
|
|
@@ -8,18 +8,18 @@ export function unregisterPushTokenOnServer() {
|
|
|
8
8
|
const e = r.m();
|
|
9
9
|
if (!e) return;
|
|
10
10
|
const t = r.p(),
|
|
11
|
-
n = null == t ? void 0 : t.St(s.It.
|
|
11
|
+
n = null == t ? void 0 : t.St(s.It.xu);
|
|
12
12
|
if (!n || "object" != typeof n || Array.isArray(n)) return;
|
|
13
13
|
const o = ui._u(n);
|
|
14
14
|
if (!o.endpoint) return;
|
|
15
15
|
const i = e.Z({}, !0);
|
|
16
16
|
i.push_token = o.endpoint;
|
|
17
|
-
const a = e.tt(i, h.it.
|
|
17
|
+
const a = e.tt(i, h.it.ka);
|
|
18
18
|
e.et(
|
|
19
19
|
i,
|
|
20
20
|
(n = -1) => {
|
|
21
21
|
r.rr() &&
|
|
22
|
-
(h.nt(t, h.it.
|
|
22
|
+
(h.nt(t, h.it.ka, new Date().valueOf()),
|
|
23
23
|
-1 !== n && a.push(["X-Braze-Req-Tokens-Remaining", n.toString()]),
|
|
24
24
|
l.ot({
|
|
25
25
|
url: `${e.ht()}/push/unregister`,
|
|
@@ -30,6 +30,6 @@ export function unregisterPushTokenOnServer() {
|
|
|
30
30
|
},
|
|
31
31
|
}));
|
|
32
32
|
},
|
|
33
|
-
h.it.
|
|
33
|
+
h.it.ka,
|
|
34
34
|
);
|
|
35
35
|
}
|