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