@braze/web-sdk 6.3.1 → 6.5.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/README.md +1 -1
- package/index.d.ts +38 -5
- package/package.json +1 -1
- package/shared-lib/encoding-utils.js +3 -3
- package/shared-lib/event-types.js +30 -30
- package/shared-lib/guid.js +1 -1
- package/shared-lib/indexed-db-adapter.js +60 -60
- package/shared-lib/logger.js +7 -7
- package/shared-lib/supported-options.js +24 -23
- package/src/Banner/banner-provider.js +95 -81
- package/src/Banner/banner.js +9 -9
- package/src/Banner/constants.js +4 -0
- package/src/Banner/display/banner-to-html.js +3 -3
- package/src/Banner/display/destroy-banner-html.js +3 -3
- package/src/Banner/display/detect-banner-impressions.js +16 -16
- package/src/Banner/get-all-banners.js +4 -4
- package/src/Banner/get-banner.js +5 -4
- package/src/Banner/index.js +2 -0
- package/src/Banner/log-banner-click.js +2 -2
- package/src/Banner/log-banner-impressions.js +6 -6
- package/src/Banner/request-banners-refresh.js +18 -20
- package/src/Banner/subscribe-to-banners-updates.js +5 -5
- package/src/Banner/ui/insert-banner.js +17 -14
- package/src/Card/card-manager-factory.js +6 -6
- package/src/Card/card-manager.js +28 -28
- package/src/Card/constants.js +1 -0
- package/src/Card/display/card-display.js +7 -7
- package/src/Card/log-card-dismissal.js +3 -3
- package/src/Card/log-content-card-click.js +3 -3
- package/src/Card/log-content-card-impressions.js +6 -6
- package/src/Card/models/captioned-image.js +3 -3
- package/src/Card/models/card.js +9 -9
- package/src/Card/models/classic-card.js +3 -3
- package/src/Card/models/control-card.js +3 -3
- package/src/Card/models/image-only.js +3 -3
- package/src/ContentCards/content-cards-provider-factory.js +6 -2
- package/src/ContentCards/content-cards-provider.js +101 -87
- package/src/ContentCards/content-cards.js +4 -4
- 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 +5 -5
- package/src/Core/add-sdk-metadata.js +2 -2
- package/src/Core/change-user.js +1 -1
- package/src/Core/disable-sdk.js +5 -5
- package/src/Core/enable-sdk.js +3 -3
- package/src/Core/get-device-id.js +2 -2
- package/src/Core/get-user.js +1 -1
- package/src/Core/handle-braze-action.js +3 -3
- package/src/Core/is-disabled.js +1 -1
- package/src/Core/log-custom-event.js +7 -7
- package/src/Core/log-purchase.js +4 -4
- package/src/Core/open-session.js +6 -6
- package/src/Core/wipe-data.js +3 -3
- package/src/DUST/dust-connection-core.js +23 -0
- package/src/DUST/dust-provider-factory.js +22 -0
- package/src/DUST/dust-provider.js +520 -0
- package/src/DUST/dust-shared-worker-code.js +2 -0
- package/src/DUST/dust-shared-worker-impl.js +240 -0
- package/src/DUST/dust-worker-bridge.js +136 -0
- package/src/DUST/index.js +13 -0
- package/src/DUST/subscribe-to-dust.js +24 -0
- package/src/DUST/types.js +1 -0
- package/src/FeatureFlags/feature-flag-factory.js +8 -8
- package/src/FeatureFlags/feature-flag.js +6 -6
- package/src/FeatureFlags/feature-flags-provider-factory.js +9 -9
- package/src/FeatureFlags/feature-flags-provider.js +98 -84
- package/src/FeatureFlags/get-all-feature-flags.js +3 -3
- package/src/FeatureFlags/get-feature-flag.js +3 -3
- package/src/FeatureFlags/log-feature-flag-impression.js +7 -7
- package/src/FeatureFlags/refresh-feature-flags.js +5 -5
- package/src/FeatureFlags/subscribe-to-feature-flags-updates.js +4 -4
- package/src/InAppMessage/constants.js +4 -0
- 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-to-html.js +6 -6
- package/src/InAppMessage/display/in-app-message-to-html.js +34 -34
- 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 +4 -4
- package/src/InAppMessage/in-app-message-manager-factory.js +7 -7
- package/src/InAppMessage/in-app-message-manager.js +98 -98
- package/src/InAppMessage/log-in-app-message-button-click.js +12 -12
- package/src/InAppMessage/log-in-app-message-click.js +11 -11
- package/src/InAppMessage/log-in-app-message-html-click.js +9 -9
- package/src/InAppMessage/log-in-app-message-impression.js +8 -8
- package/src/InAppMessage/models/control-message.js +5 -5
- package/src/InAppMessage/models/full-screen-message.js +21 -21
- package/src/InAppMessage/models/html-message.js +18 -18
- package/src/InAppMessage/models/in-app-message-button.js +7 -7
- package/src/InAppMessage/models/in-app-message.js +145 -145
- package/src/InAppMessage/models/modal-message.js +21 -21
- package/src/InAppMessage/models/slide-up-message.js +27 -27
- 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 +5 -5
- package/src/InAppMessage/ui/remove-all-visible-in-app-messages.js +18 -0
- package/src/InAppMessage/ui/show-in-app-message.js +36 -36
- 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 +15 -15
- package/src/Push/push-manager.js +97 -97
- package/src/Push/request-push-permission.js +1 -1
- package/src/Push/unregister-push.js +1 -1
- package/src/Push/utils/push-utils.js +17 -17
- package/src/User/user-manager.js +24 -24
- package/src/User/user.js +55 -55
- package/src/common/constants.js +8 -10
- package/src/common/content-cards-display.js +40 -40
- package/src/common/event-logger.js +8 -8
- package/src/common/properties-base.js +16 -16
- package/src/l10n/l10n-manager-factory.js +11 -11
- package/src/l10n/l10n-manager.js +2 -2
- package/src/managers/auth-manager.js +30 -30
- package/src/managers/braze-instance.js +170 -162
- package/src/managers/device-manager.js +24 -24
- package/src/managers/network-manager.js +149 -149
- package/src/managers/server-config-manager.js +140 -95
- package/src/managers/session-manager.js +39 -39
- package/src/managers/storage-manager-factory.js +10 -10
- package/src/managers/storage-manager.js +145 -141
- package/src/managers/subscription-manager.js +11 -11
- package/src/managers/utils.js +1 -1
- package/src/models/backend-errors.js +5 -5
- package/src/models/braze-event.js +11 -11
- package/src/models/device.js +3 -3
- package/src/models/identifier.js +16 -16
- package/src/models/push-token.js +13 -13
- package/src/models/request-result.js +3 -3
- package/src/models/server-config.js +45 -37
- package/src/request-controller.js +163 -158
- package/src/triggers/models/custom-event-data.js +5 -5
- package/src/triggers/models/custom-event-property-data.js +6 -6
- package/src/triggers/models/filter-set.js +10 -10
- package/src/triggers/models/filter.js +27 -27
- package/src/triggers/models/in-app-message-click-data.js +13 -13
- package/src/triggers/models/purchase-data.js +2 -2
- 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 +47 -47
- package/src/triggers/models/trigger-events.js +3 -3
- package/src/triggers/models/trigger.js +36 -36
- package/src/triggers/triggers-provider-factory.js +5 -5
- package/src/triggers/triggers-provider.js +63 -63
- 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 +9 -9
- package/src/util/braze-actions.js +5 -5
- package/src/util/browser-detector.js +37 -37
- package/src/util/client-hints-parser.js +11 -11
- package/src/util/component-utils.js +5 -5
- package/src/util/dom-utils.js +13 -13
- package/src/util/html-display-utils.js +7 -7
- package/src/util/key-codes.js +1 -1
- package/src/util/net.js +5 -5
- package/src/util/request-header-utils.js +27 -27
- package/src/util/user-agent-parser.js +21 -21
- package/src/util/validation-utils.js +17 -17
- package/src/util/window-utils.js +3 -3
package/src/Push/push-manager.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import { isArray as
|
|
2
|
-
import
|
|
3
|
-
import { logger as E, EncodingUtils as
|
|
1
|
+
import { isArray as R, isEqual as ni } from "../util/code-utils.js";
|
|
2
|
+
import oi from "../models/push-token.js";
|
|
3
|
+
import { logger as E, EncodingUtils as ui } from "../../shared-lib/index.js";
|
|
4
4
|
import { STORAGE_KEYS as s } from "../managers/storage-manager.js";
|
|
5
5
|
import { User } from "../User/index.js";
|
|
6
|
-
import
|
|
7
|
-
import { getErrorMessage as
|
|
6
|
+
import vt from "./utils/push-utils.js";
|
|
7
|
+
import { getErrorMessage as ai } from "../util/error-utils.js";
|
|
8
8
|
export default class na {
|
|
9
9
|
constructor(i, t, e, s, r, n, o, u, a, h, c) {
|
|
10
|
-
(this.
|
|
11
|
-
(this.
|
|
12
|
-
(this.
|
|
13
|
-
(this.
|
|
14
|
-
(this.
|
|
15
|
-
(this.
|
|
10
|
+
(this.iu = i),
|
|
11
|
+
(this.tu = t),
|
|
12
|
+
(this.eu = e),
|
|
13
|
+
(this.su = r),
|
|
14
|
+
(this.ru = n),
|
|
15
|
+
(this.nu = o),
|
|
16
16
|
(this.h = u),
|
|
17
|
-
(this.
|
|
18
|
-
(this.
|
|
19
|
-
(this.
|
|
20
|
-
(this.
|
|
21
|
-
(this.
|
|
22
|
-
(this.
|
|
23
|
-
(this.
|
|
24
|
-
(this.
|
|
25
|
-
(this.
|
|
17
|
+
(this.ou = a),
|
|
18
|
+
(this.uu = h),
|
|
19
|
+
(this.B = c),
|
|
20
|
+
(this.iu = i),
|
|
21
|
+
(this.tu = t),
|
|
22
|
+
(this.eu = e),
|
|
23
|
+
(this.au = s + "/safari/" + t),
|
|
24
|
+
(this.su = r || "/service-worker.js"),
|
|
25
|
+
(this.nu = o),
|
|
26
26
|
(this.h = u),
|
|
27
|
-
(this.
|
|
28
|
-
(this.
|
|
29
|
-
(this.
|
|
30
|
-
(this.
|
|
31
|
-
(this.
|
|
27
|
+
(this.ou = a || !1),
|
|
28
|
+
(this.uu = h || !1),
|
|
29
|
+
(this.B = c),
|
|
30
|
+
(this.hu = vt.cu()),
|
|
31
|
+
(this.fu = vt.lu());
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
return this.
|
|
33
|
+
du() {
|
|
34
|
+
return this.uu;
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
pu(i, t, e, s, r) {
|
|
37
37
|
i.unsubscribe()
|
|
38
38
|
.then((i) => {
|
|
39
39
|
i
|
|
40
|
-
? this.
|
|
40
|
+
? this.bu(t, e, s, r)
|
|
41
41
|
: (E.error("Failed to unsubscribe device from push."),
|
|
42
42
|
"function" == typeof r && r(!1));
|
|
43
43
|
})
|
|
@@ -46,7 +46,7 @@ export default class na {
|
|
|
46
46
|
"function" == typeof r && r(!1);
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
yu(i, t, e) {
|
|
50
50
|
var s;
|
|
51
51
|
const r = ((i) => {
|
|
52
52
|
if ("string" == typeof i) return i;
|
|
@@ -55,9 +55,9 @@ export default class na {
|
|
|
55
55
|
let t = i.endpoint;
|
|
56
56
|
const e = i;
|
|
57
57
|
return (
|
|
58
|
-
e.
|
|
59
|
-
-1 === i.endpoint.indexOf(e.
|
|
60
|
-
(t = i.endpoint + "/" + e.
|
|
58
|
+
e.mu &&
|
|
59
|
+
-1 === i.endpoint.indexOf(e.mu) &&
|
|
60
|
+
(t = i.endpoint + "/" + e.mu),
|
|
61
61
|
t
|
|
62
62
|
);
|
|
63
63
|
})(i);
|
|
@@ -71,7 +71,7 @@ export default class na {
|
|
|
71
71
|
(n = btoa(String.fromCharCode.apply(null, i))),
|
|
72
72
|
(o = btoa(String.fromCharCode.apply(null, t)));
|
|
73
73
|
} catch (i) {
|
|
74
|
-
E.error(
|
|
74
|
+
E.error(ai(i));
|
|
75
75
|
}
|
|
76
76
|
const a = ((i) => {
|
|
77
77
|
let t;
|
|
@@ -84,53 +84,53 @@ export default class na {
|
|
|
84
84
|
.replace(/\//g, "_")
|
|
85
85
|
: null;
|
|
86
86
|
})(u);
|
|
87
|
-
null === (s = this.
|
|
87
|
+
null === (s = this.iu) || void 0 === s || s.gu(r, t, n, o, a),
|
|
88
88
|
r && "function" == typeof e && e(r, n, o);
|
|
89
89
|
}
|
|
90
|
-
|
|
90
|
+
vu() {
|
|
91
91
|
var i;
|
|
92
|
-
null === (i = this.
|
|
92
|
+
null === (i = this.iu) || void 0 === i || i.wu(!0);
|
|
93
93
|
}
|
|
94
|
-
|
|
94
|
+
ku(i, t) {
|
|
95
95
|
var e;
|
|
96
|
-
null === (e = this.
|
|
96
|
+
null === (e = this.iu) || void 0 === e || e.wu(!1),
|
|
97
97
|
E.info(i),
|
|
98
98
|
"function" == typeof t && t(!1);
|
|
99
99
|
}
|
|
100
|
-
|
|
100
|
+
Pu(i, t, e, s) {
|
|
101
101
|
var r;
|
|
102
102
|
if ("default" === t.permission)
|
|
103
103
|
try {
|
|
104
104
|
window.safari.pushNotification.requestPermission(
|
|
105
|
-
this.
|
|
105
|
+
this.au,
|
|
106
106
|
i,
|
|
107
107
|
{
|
|
108
|
-
api_key: this.
|
|
108
|
+
api_key: this.tu,
|
|
109
109
|
device_id:
|
|
110
|
-
(null === (r = this.
|
|
110
|
+
(null === (r = this.eu) || void 0 === r ? void 0 : r.ve().id) ||
|
|
111
111
|
"",
|
|
112
112
|
},
|
|
113
113
|
(t) => {
|
|
114
114
|
"granted" === t.permission &&
|
|
115
|
-
this.
|
|
116
|
-
this.
|
|
115
|
+
this.iu &&
|
|
116
|
+
this.iu.setPushNotificationSubscriptionType(
|
|
117
117
|
User.NotificationSubscriptionTypes.OPTED_IN,
|
|
118
118
|
),
|
|
119
|
-
this.
|
|
119
|
+
this.Pu(i, t, e, s);
|
|
120
120
|
},
|
|
121
121
|
);
|
|
122
122
|
} catch (i) {
|
|
123
|
-
this.
|
|
123
|
+
this.ku("Could not request permission for push: " + i, s);
|
|
124
124
|
}
|
|
125
125
|
else
|
|
126
126
|
"denied" === t.permission
|
|
127
|
-
? this.
|
|
127
|
+
? this.ku(
|
|
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
131
|
: "granted" === t.permission &&
|
|
132
132
|
(E.info("Device successfully subscribed to push."),
|
|
133
|
-
this.
|
|
133
|
+
this.yu(t.deviceToken, new Date(), e));
|
|
134
134
|
}
|
|
135
135
|
requestPermission(i, t, e) {
|
|
136
136
|
const s = (s) => {
|
|
@@ -159,27 +159,27 @@ export default class na {
|
|
|
159
159
|
: (r = !0);
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
|
-
|
|
162
|
+
bu(i, t, e, s) {
|
|
163
163
|
const r = { userVisibleOnly: !0 };
|
|
164
164
|
null != t && (r.applicationServerKey = t),
|
|
165
165
|
i.pushManager
|
|
166
166
|
.subscribe(r)
|
|
167
167
|
.then((i) => {
|
|
168
168
|
E.info("Device successfully subscribed to push."),
|
|
169
|
-
this.
|
|
169
|
+
this.yu(i, new Date(), e);
|
|
170
170
|
})
|
|
171
171
|
.catch((i) => {
|
|
172
|
-
|
|
172
|
+
vt.isPushBlocked()
|
|
173
173
|
? (E.info("Permission for push notifications was denied."),
|
|
174
174
|
"function" == typeof s && s(!1))
|
|
175
175
|
: (E.error("Push subscription failed: " + i),
|
|
176
176
|
"function" == typeof s && s(!0));
|
|
177
177
|
});
|
|
178
178
|
}
|
|
179
|
-
|
|
180
|
-
if (this.
|
|
181
|
-
const i = this.
|
|
182
|
-
return navigator.serviceWorker.register(this.
|
|
179
|
+
Du() {
|
|
180
|
+
if (this.ou) return navigator.serviceWorker.getRegistration(this.su);
|
|
181
|
+
const i = this.ru ? { scope: this.ru } : void 0;
|
|
182
|
+
return navigator.serviceWorker.register(this.su, i).then(() =>
|
|
183
183
|
navigator.serviceWorker.ready.then(
|
|
184
184
|
(i) => (
|
|
185
185
|
i &&
|
|
@@ -192,32 +192,32 @@ export default class na {
|
|
|
192
192
|
),
|
|
193
193
|
);
|
|
194
194
|
}
|
|
195
|
-
|
|
196
|
-
this.
|
|
195
|
+
Su(i) {
|
|
196
|
+
this.ou ||
|
|
197
197
|
(i.unregister(), E.info("Service worker successfully unregistered."));
|
|
198
198
|
}
|
|
199
199
|
subscribe(i, t) {
|
|
200
|
-
if (!
|
|
201
|
-
return E.info(na.
|
|
202
|
-
if (this.
|
|
203
|
-
if (!this.
|
|
204
|
-
let i = this.
|
|
200
|
+
if (!vt.isPushSupported())
|
|
201
|
+
return E.info(na.Au), void ("function" == typeof t && t(!1));
|
|
202
|
+
if (this.hu) {
|
|
203
|
+
if (!this.ou && null != window.location) {
|
|
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 (vt.isPushBlocked())
|
|
211
|
+
return void this.ku(
|
|
212
212
|
"Notifications from this site are blocked. This may be a temporary embargo or a permanent denial.",
|
|
213
213
|
t,
|
|
214
214
|
);
|
|
215
|
-
if (this.h && !this.h.
|
|
215
|
+
if (this.h && !this.h.ju() && 0 === this.h.xt())
|
|
216
216
|
return (
|
|
217
217
|
E.info(
|
|
218
218
|
"Waiting for VAPID key from server config before subscribing to push.",
|
|
219
219
|
),
|
|
220
|
-
void this.h.
|
|
220
|
+
void this.h.xu(() => {
|
|
221
221
|
this.subscribe(i, t);
|
|
222
222
|
})
|
|
223
223
|
);
|
|
@@ -227,20 +227,20 @@ export default class na {
|
|
|
227
227
|
},
|
|
228
228
|
r = () => {
|
|
229
229
|
let i = "Permission for push notifications was ignored.";
|
|
230
|
-
|
|
230
|
+
vt.isPushBlocked() &&
|
|
231
231
|
(i +=
|
|
232
232
|
" The browser has automatically blocked further permission requests for a period (probably 1 week)."),
|
|
233
233
|
E.info(i),
|
|
234
234
|
"function" == typeof t && t(!0);
|
|
235
235
|
},
|
|
236
|
-
n =
|
|
236
|
+
n = vt.isPushPermissionGranted(),
|
|
237
237
|
o = () => {
|
|
238
238
|
!n &&
|
|
239
|
-
this.
|
|
240
|
-
this.
|
|
239
|
+
this.iu &&
|
|
240
|
+
this.iu.setPushNotificationSubscriptionType(
|
|
241
241
|
User.NotificationSubscriptionTypes.OPTED_IN,
|
|
242
242
|
),
|
|
243
|
-
this.
|
|
243
|
+
this.Du()
|
|
244
244
|
.then((e) => {
|
|
245
245
|
if (null == e)
|
|
246
246
|
return (
|
|
@@ -258,16 +258,16 @@ export default class na {
|
|
|
258
258
|
(null !=
|
|
259
259
|
(null === (n = this.h) || void 0 === n
|
|
260
260
|
? void 0
|
|
261
|
-
: n.
|
|
261
|
+
: n.ju()) && (o = ui.Nu(this.h.ju())),
|
|
262
262
|
r)
|
|
263
263
|
) {
|
|
264
264
|
let n,
|
|
265
265
|
u = null,
|
|
266
266
|
a = null;
|
|
267
|
-
if ((this.
|
|
267
|
+
if ((this.B && (n = this.B.dt(s.ft.Uu)), n && !R(n))) {
|
|
268
268
|
let i;
|
|
269
269
|
try {
|
|
270
|
-
i =
|
|
270
|
+
i = oi._u(n).Wu;
|
|
271
271
|
} catch (t) {
|
|
272
272
|
i = null;
|
|
273
273
|
}
|
|
@@ -283,7 +283,7 @@ export default class na {
|
|
|
283
283
|
r.options.applicationServerKey &&
|
|
284
284
|
r.options.applicationServerKey.byteLength &&
|
|
285
285
|
r.options.applicationServerKey.byteLength > 0 &&
|
|
286
|
-
!
|
|
286
|
+
!ni(o, new Uint8Array(r.options.applicationServerKey))
|
|
287
287
|
? (r.options.applicationServerKey.byteLength > 12
|
|
288
288
|
? E.info(
|
|
289
289
|
"Device was already subscribed to push using a different VAPID provider, creating new subscription.",
|
|
@@ -291,31 +291,31 @@ export default class na {
|
|
|
291
291
|
: E.info(
|
|
292
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
293
|
),
|
|
294
|
-
this.
|
|
294
|
+
this.pu(r, e, o, i, t))
|
|
295
295
|
: r.expirationTime &&
|
|
296
296
|
new Date(r.expirationTime).valueOf() <=
|
|
297
297
|
new Date().valueOf()
|
|
298
298
|
? (E.info(
|
|
299
299
|
"Push subscription is expired, creating new subscription.",
|
|
300
300
|
),
|
|
301
|
-
this.
|
|
302
|
-
: n &&
|
|
303
|
-
? this.
|
|
301
|
+
this.pu(r, e, o, i, t))
|
|
302
|
+
: n && R(n)
|
|
303
|
+
? this.pu(r, e, o, i, t)
|
|
304
304
|
: null == a
|
|
305
305
|
? (E.info(
|
|
306
306
|
"No push subscription creation date found, creating new subscription.",
|
|
307
307
|
),
|
|
308
|
-
this.
|
|
308
|
+
this.pu(r, e, o, i, t))
|
|
309
309
|
: a.valueOf() <= new Date().valueOf()
|
|
310
310
|
? (E.info(
|
|
311
311
|
"Push subscription older than 6 months, creating new subscription.",
|
|
312
312
|
),
|
|
313
|
-
this.
|
|
313
|
+
this.pu(r, e, o, i, t))
|
|
314
314
|
: (E.info(
|
|
315
315
|
"Device already subscribed to push, sending existing subscription to backend.",
|
|
316
316
|
),
|
|
317
|
-
this.
|
|
318
|
-
} else this.
|
|
317
|
+
this.yu(r, u, i));
|
|
318
|
+
} else this.bu(e, o, i, t);
|
|
319
319
|
})
|
|
320
320
|
.catch((i) => {
|
|
321
321
|
E.error("Error checking current push subscriptions: " + i);
|
|
@@ -326,29 +326,29 @@ export default class na {
|
|
|
326
326
|
});
|
|
327
327
|
};
|
|
328
328
|
this.requestPermission(o, r, e);
|
|
329
|
-
} else if (this.
|
|
330
|
-
if (null == this.
|
|
329
|
+
} else if (this.fu) {
|
|
330
|
+
if (null == this.nu || "" === this.nu)
|
|
331
331
|
return (
|
|
332
332
|
E.error(
|
|
333
333
|
"You must supply the safariWebsitePushId initialization option in order to use registerPush on Safari",
|
|
334
334
|
),
|
|
335
335
|
void ("function" == typeof t && t(!0))
|
|
336
336
|
);
|
|
337
|
-
const e = window.safari.pushNotification.permission(this.
|
|
338
|
-
this.
|
|
337
|
+
const e = window.safari.pushNotification.permission(this.nu);
|
|
338
|
+
this.Pu(this.nu, e, i, t);
|
|
339
339
|
}
|
|
340
340
|
}
|
|
341
341
|
unsubscribe(i, t) {
|
|
342
|
-
if (!
|
|
343
|
-
return E.info(na.
|
|
344
|
-
this.
|
|
345
|
-
? navigator.serviceWorker.getRegistration(this.
|
|
342
|
+
if (!vt.isPushSupported())
|
|
343
|
+
return E.info(na.Au), void ("function" == typeof t && t());
|
|
344
|
+
this.hu
|
|
345
|
+
? navigator.serviceWorker.getRegistration(this.su).then((e) => {
|
|
346
346
|
e
|
|
347
347
|
? e.pushManager
|
|
348
348
|
.getSubscription()
|
|
349
349
|
.then((s) => {
|
|
350
350
|
s
|
|
351
|
-
? (this.
|
|
351
|
+
? (this.vu(),
|
|
352
352
|
s
|
|
353
353
|
.unsubscribe()
|
|
354
354
|
.then((s) => {
|
|
@@ -361,7 +361,7 @@ export default class na {
|
|
|
361
361
|
"Failed to unsubscribe device from push.",
|
|
362
362
|
),
|
|
363
363
|
"function" == typeof t && t()),
|
|
364
|
-
this.
|
|
364
|
+
this.Su(e);
|
|
365
365
|
})
|
|
366
366
|
.catch((i) => {
|
|
367
367
|
E.error("Push unsubscription error: " + i),
|
|
@@ -377,10 +377,10 @@ export default class na {
|
|
|
377
377
|
: (E.info("Device already unsubscribed from push."),
|
|
378
378
|
"function" == typeof i && i());
|
|
379
379
|
})
|
|
380
|
-
: this.
|
|
381
|
-
(this.
|
|
380
|
+
: this.fu &&
|
|
381
|
+
(this.vu(),
|
|
382
382
|
E.info("Device unsubscribed from push."),
|
|
383
383
|
"function" == typeof i && i());
|
|
384
384
|
}
|
|
385
385
|
}
|
|
386
|
-
na.
|
|
386
|
+
na.Au = "Push notifications are not supported in this browser.";
|
|
@@ -2,7 +2,7 @@ import r from "../managers/braze-instance.js";
|
|
|
2
2
|
import ra from "./push-manager-factory.js";
|
|
3
3
|
export function requestPushPermission(n, o) {
|
|
4
4
|
if (r.rr())
|
|
5
|
-
return ra.
|
|
5
|
+
return ra.ra().subscribe((o, t, e) => {
|
|
6
6
|
const s = r.nn();
|
|
7
7
|
s && s.requestImmediateDataFlush(), "function" == typeof n && n(o, t, e);
|
|
8
8
|
}, o);
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
1
|
+
const vt = {
|
|
2
|
+
cu: () =>
|
|
3
3
|
"serviceWorker" in navigator &&
|
|
4
4
|
"undefined" != typeof ServiceWorkerRegistration &&
|
|
5
5
|
"showNotification" in ServiceWorkerRegistration.prototype &&
|
|
6
6
|
"PushManager" in window,
|
|
7
|
-
|
|
7
|
+
lu: () =>
|
|
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: () => vt.cu() || vt.lu(),
|
|
13
13
|
isPushBlocked: () => {
|
|
14
14
|
const o =
|
|
15
|
-
|
|
15
|
+
vt.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
|
i =
|
|
21
|
-
|
|
21
|
+
vt.isPushSupported() &&
|
|
22
22
|
(!("Notification" in window) || null == window.Notification);
|
|
23
23
|
return o || i;
|
|
24
24
|
},
|
|
25
25
|
isPushPermissionGranted: () =>
|
|
26
|
-
|
|
26
|
+
vt.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
|
-
|
|
33
|
-
? {
|
|
34
|
-
:
|
|
35
|
-
?
|
|
36
|
-
? {
|
|
37
|
-
: {
|
|
38
|
-
: {
|
|
39
|
-
|
|
31
|
+
En: () =>
|
|
32
|
+
vt.isPushBlocked()
|
|
33
|
+
? { Gn: !1, reason: "blocked" }
|
|
34
|
+
: vt.isPushSupported()
|
|
35
|
+
? vt.isPushPermissionGranted()
|
|
36
|
+
? { Gn: !1, reason: "permissionGranted" }
|
|
37
|
+
: { Gn: !0 }
|
|
38
|
+
: { Gn: !1, reason: "unsupported" },
|
|
39
|
+
Nn: (o, i) =>
|
|
40
40
|
"blocked" === o
|
|
41
41
|
? `${i} containing a push prompt is not being shown because the user has already declined push permission prompt.`
|
|
42
42
|
: "unsupported" === o
|
|
43
43
|
? `${i} containing a push prompt is not being shown because the browser doesn't support push notifications.`
|
|
44
44
|
: `${i} containing a push prompt is not being shown because the user has already accepted the permission prompt.`,
|
|
45
45
|
};
|
|
46
|
-
export default
|
|
46
|
+
export default vt;
|
package/src/User/user-manager.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
import _t from "../models/identifier.js";
|
|
2
2
|
import { getByteLength as er } from "../util/string-utils.js";
|
|
3
|
-
import
|
|
3
|
+
import oi from "../models/push-token.js";
|
|
4
4
|
import { logger as E, IndexedDBAdapter as et } from "../../shared-lib/index.js";
|
|
5
5
|
import { STORAGE_KEYS as s } from "../managers/storage-manager.js";
|
|
6
6
|
import { User } from "../User/index.js";
|
|
7
7
|
export default class bt {
|
|
8
8
|
constructor(t, s) {
|
|
9
|
-
(this.h = t), (this.
|
|
9
|
+
(this.h = t), (this.B = s), (this.h = t), (this.B = s);
|
|
10
10
|
}
|
|
11
11
|
getUserId() {
|
|
12
|
-
const t = this.
|
|
12
|
+
const t = this.B.$u(s.Ou.Cu);
|
|
13
13
|
if (null == t) return null;
|
|
14
|
-
let i = t.
|
|
14
|
+
let i = t.Tu,
|
|
15
15
|
e = er(i);
|
|
16
16
|
if (e > User.mr) {
|
|
17
17
|
for (; e > User.mr; ) (i = i.slice(0, i.length - 1)), (e = er(i));
|
|
18
|
-
(t.
|
|
18
|
+
(t.Tu = i), this.B.Iu(s.Ou.Cu, t);
|
|
19
19
|
}
|
|
20
20
|
return i;
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
Ju(t) {
|
|
23
23
|
const i = null == this.getUserId();
|
|
24
|
-
this.
|
|
24
|
+
this.B.Iu(s.Ou.Cu, new _t(t)), i && this.B.Lu(t);
|
|
25
25
|
}
|
|
26
26
|
setCustomUserAttribute(t, s) {
|
|
27
|
-
if (this.h.
|
|
27
|
+
if (this.h.qu(t))
|
|
28
28
|
return (
|
|
29
29
|
E.info('Custom Attribute "' + t + '" is blocklisted, ignoring.'), !1
|
|
30
30
|
);
|
|
31
31
|
const i = {};
|
|
32
|
-
return (i[t] = s), this.
|
|
32
|
+
return (i[t] = s), this.zu(User.Bu, i, !0);
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
const u = this.
|
|
34
|
+
zu(t, s, i = !1, e = !1) {
|
|
35
|
+
const u = this.B.Eu(this.getUserId(), t, s);
|
|
36
36
|
let o = "",
|
|
37
37
|
r = t,
|
|
38
38
|
h = s;
|
|
@@ -47,27 +47,27 @@ export default class bt {
|
|
|
47
47
|
u
|
|
48
48
|
);
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
54
|
-
this.
|
|
50
|
+
gu(t, i, e, u, o) {
|
|
51
|
+
this.zu("push_token", t, !1, !0),
|
|
52
|
+
this.zu("custom_push_public_key", e, !1, !0),
|
|
53
|
+
this.zu("custom_push_user_auth", u, !1, !0),
|
|
54
|
+
this.zu("custom_push_vapid_public_key", o, !1, !0);
|
|
55
55
|
const r = et.Us.Rs,
|
|
56
56
|
h = new et(r, E),
|
|
57
|
-
n = new
|
|
58
|
-
this.
|
|
57
|
+
n = new oi(t, i, e, u, o);
|
|
58
|
+
this.B.bt(s.ft.Uu, n.gt()), h.setItem(r.Fs.Fu, r.fe, !0);
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
wu(t) {
|
|
61
61
|
if (
|
|
62
|
-
(this.
|
|
63
|
-
this.
|
|
64
|
-
this.
|
|
65
|
-
this.
|
|
62
|
+
(this.zu("push_token", null, !1, !0),
|
|
63
|
+
this.zu("custom_push_public_key", null, !1, !0),
|
|
64
|
+
this.zu("custom_push_user_auth", null, !1, !0),
|
|
65
|
+
this.zu("custom_push_vapid_public_key", null, !1, !0),
|
|
66
66
|
t)
|
|
67
67
|
) {
|
|
68
68
|
const t = et.Us.Rs,
|
|
69
69
|
i = new et(t, E);
|
|
70
|
-
this.
|
|
70
|
+
this.B.bt(s.ft.Uu, !1), i.setItem(t.Fs.Fu, t.fe, !1);
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
}
|