@notificationapi/react 0.0.33 → 0.0.35
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/dist/assets/AntdIcon.js +1 -1
- package/dist/assets/CloseOutlined.js +13 -0
- package/dist/assets/Notification.js +17 -16
- package/dist/assets/PreferenceInput.js +1470 -0
- package/dist/assets/PurePanel.js +32 -42
- package/dist/assets/WebPushOptInMessage.js +478 -0
- package/dist/assets/button.js +50 -50
- package/dist/assets/colors.js +25 -20840
- package/dist/assets/compact-item.js +860 -0
- package/dist/assets/index.js +11 -9
- package/dist/assets/index2.js +10 -9
- package/dist/assets/index3.js +2303 -3150
- package/dist/assets/presets.js +22 -22
- package/dist/assets/reactNode.js +20821 -0
- package/dist/components/Notifications/Inbox.js +81 -78
- package/dist/components/Notifications/NotificationFeed.js +59 -31
- package/dist/components/Notifications/NotificationLauncher.js +61 -41
- package/dist/components/Notifications/NotificationPopup.js +72 -65
- package/dist/components/Preferences/NotificationPreferencesInline.d.ts +1 -1
- package/dist/components/Preferences/NotificationPreferencesInline.js +39 -5
- package/dist/components/Preferences/NotificationPreferencesPopup.d.ts +1 -1
- package/dist/components/Preferences/NotificationPreferencesPopup.js +463 -464
- package/dist/components/Preferences/PreferenceInput.js +5 -1466
- package/dist/components/Preferences/Preferences.js +24 -23
- package/dist/components/Provider/index.d.ts +9 -1
- package/dist/components/Provider/index.js +214 -156
- package/dist/components/WebPush/WebPushOptInMessage.d.ts +14 -0
- package/dist/components/WebPush/WebPushOptInMessage.js +8 -0
- package/package.json +2 -2
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
`https://${
|
|
1
|
+
import { jsx as z } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as Q, useState as I, useCallback as m, useMemo as X, useRef as T, useEffect as P, useContext as Y } from "react";
|
|
3
|
+
const Z = async (e, r, o, a, f, b, h) => {
|
|
4
|
+
const l = ee(a, f, b), g = await fetch(
|
|
5
|
+
`https://${r}/${a}/users/${encodeURIComponent(
|
|
6
6
|
f
|
|
7
|
-
)}/${
|
|
7
|
+
)}/${o}`,
|
|
8
8
|
{
|
|
9
9
|
method: e,
|
|
10
10
|
body: JSON.stringify(h),
|
|
11
11
|
headers: {
|
|
12
|
-
Authorization: `Basic ${
|
|
12
|
+
Authorization: `Basic ${l}`
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
);
|
|
16
16
|
try {
|
|
17
|
-
return await
|
|
17
|
+
return await g.json();
|
|
18
18
|
} catch {
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
|
-
},
|
|
21
|
+
}, ee = (e, r, o) => btoa(o ? e + ":" + r + ":" + o : e + ":" + r), H = {
|
|
22
22
|
host: "api.notificationapi.com",
|
|
23
23
|
websocketHost: "ws.notificationapi.com",
|
|
24
24
|
userId: "",
|
|
@@ -31,76 +31,79 @@ const J = async (e, s, i, a, f, w, h) => {
|
|
|
31
31
|
onNewInAppNotifications: void 0,
|
|
32
32
|
keepWebSocketAliveForSeconds: 86400
|
|
33
33
|
// 24 hours
|
|
34
|
-
},
|
|
35
|
-
config:
|
|
34
|
+
}, i = {
|
|
35
|
+
config: H,
|
|
36
36
|
init: function(e) {
|
|
37
|
-
return this.config = { ...
|
|
37
|
+
return this.config = { ...H, ...e }, {
|
|
38
38
|
...this
|
|
39
39
|
};
|
|
40
40
|
},
|
|
41
41
|
rest: {
|
|
42
|
-
generic: function(e,
|
|
43
|
-
return
|
|
42
|
+
generic: function(e, r, o) {
|
|
43
|
+
return Z(
|
|
44
44
|
e,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
i.config.host,
|
|
46
|
+
r,
|
|
47
|
+
i.config.clientId,
|
|
48
|
+
i.config.userId,
|
|
49
|
+
i.config.hashedUserId,
|
|
50
|
+
o
|
|
51
51
|
);
|
|
52
52
|
},
|
|
53
53
|
// The functions below are nice wrappers over the generic
|
|
54
54
|
// rest api function above. They must follow REST API naming:
|
|
55
55
|
// Method + Resource, representing the end-point.
|
|
56
|
-
getNotifications: function(e,
|
|
57
|
-
return
|
|
56
|
+
getNotifications: function(e, r) {
|
|
57
|
+
return i.rest.generic(
|
|
58
58
|
"GET",
|
|
59
|
-
`notifications/INAPP_WEB?count=${
|
|
59
|
+
`notifications/INAPP_WEB?count=${r}&before=${e}`
|
|
60
60
|
);
|
|
61
61
|
},
|
|
62
62
|
patchNotifications: function(e) {
|
|
63
|
-
return
|
|
63
|
+
return i.rest.generic(
|
|
64
64
|
"PATCH",
|
|
65
65
|
"notifications/INAPP_WEB",
|
|
66
66
|
e
|
|
67
67
|
);
|
|
68
68
|
},
|
|
69
69
|
getPreferences: function() {
|
|
70
|
-
return
|
|
70
|
+
return i.rest.generic("GET", "preferences");
|
|
71
71
|
},
|
|
72
72
|
postPreferences: function(e) {
|
|
73
|
-
return
|
|
73
|
+
return i.rest.generic(
|
|
74
74
|
"POST",
|
|
75
75
|
"preferences",
|
|
76
76
|
e
|
|
77
77
|
);
|
|
78
78
|
},
|
|
79
79
|
postUser: function(e) {
|
|
80
|
-
return
|
|
80
|
+
return i.rest.generic("POST", "", e);
|
|
81
|
+
},
|
|
82
|
+
getUserAccountMetadata: function() {
|
|
83
|
+
return i.rest.generic("GET", "account_metadata");
|
|
81
84
|
}
|
|
82
85
|
},
|
|
83
86
|
websocket: {
|
|
84
87
|
object: void 0,
|
|
85
88
|
connect: function() {
|
|
86
|
-
let e = `wss://${
|
|
87
|
-
return
|
|
88
|
-
const
|
|
89
|
-
if (!(!
|
|
90
|
-
const a =
|
|
91
|
-
|
|
89
|
+
let e = `wss://${i.config.websocketHost}?userId=${encodeURIComponent(i.config.userId)}&envId=${i.config.clientId}`;
|
|
90
|
+
return i.config.hashedUserId && (e += `&userIdHash=${encodeURIComponent(i.config.hashedUserId)}`), i.websocket.object = new WebSocket(e), i.websocket.object.onmessage = (r) => {
|
|
91
|
+
const o = JSON.parse(r.data);
|
|
92
|
+
if (!(!o || !o.route) && o.route === "inapp_web/new_notifications") {
|
|
93
|
+
const a = o;
|
|
94
|
+
i.config.onNewInAppNotifications && i.config.onNewInAppNotifications(
|
|
92
95
|
a.payload.notifications
|
|
93
96
|
);
|
|
94
97
|
}
|
|
95
|
-
},
|
|
98
|
+
}, i.websocket.object;
|
|
96
99
|
},
|
|
97
100
|
disconnect: function(e) {
|
|
98
|
-
var
|
|
99
|
-
|
|
101
|
+
var r;
|
|
102
|
+
i.websocket.object && ((r = i.websocket.object) == null || r.close(), e && e(i.websocket.object));
|
|
100
103
|
}
|
|
101
104
|
},
|
|
102
105
|
openWebSocket: function() {
|
|
103
|
-
return
|
|
106
|
+
return i.websocket.connect(() => {
|
|
104
107
|
setTimeout(
|
|
105
108
|
() => {
|
|
106
109
|
this.websocket.disconnect(() => {
|
|
@@ -115,198 +118,253 @@ const J = async (e, s, i, a, f, w, h) => {
|
|
|
115
118
|
// They may or may not do additional tasks.
|
|
116
119
|
// e.g. identify simply maps to postUsers
|
|
117
120
|
getInAppNotifications: async (e) => {
|
|
118
|
-
const
|
|
119
|
-
let a = [], f = e.before,
|
|
121
|
+
const r = e.maxCountNeeded || i.config.getInAppDefaultCount, o = e.oldestNeeded || i.config.getInAppDefaultOldest;
|
|
122
|
+
let a = [], f = e.before, b = !0, h = !0;
|
|
120
123
|
for (; h; ) {
|
|
121
|
-
const
|
|
124
|
+
const l = (await i.rest.getNotifications(
|
|
122
125
|
f,
|
|
123
|
-
|
|
126
|
+
r
|
|
124
127
|
)).notifications.filter(
|
|
125
|
-
(
|
|
128
|
+
(g) => !a.find((w) => w.id === g.id)
|
|
126
129
|
);
|
|
127
|
-
f =
|
|
128
|
-
(
|
|
130
|
+
f = l.reduce(
|
|
131
|
+
(g, w) => g < w.date ? g : w.date,
|
|
129
132
|
e.before
|
|
130
|
-
), a = [...a, ...
|
|
133
|
+
), a = [...a, ...l], b = l.length > 0, h = !0, (!b || a.length >= r || f < o) && (h = !1);
|
|
131
134
|
}
|
|
132
135
|
return {
|
|
133
136
|
items: a,
|
|
134
|
-
hasMore:
|
|
137
|
+
hasMore: b,
|
|
135
138
|
oldestReceived: f
|
|
136
139
|
};
|
|
137
140
|
},
|
|
138
141
|
updateInAppNotifications: async (e) => {
|
|
139
|
-
const
|
|
142
|
+
const r = {
|
|
140
143
|
trackingIds: e.ids
|
|
141
144
|
};
|
|
142
|
-
return e.archived === !0 ?
|
|
145
|
+
return e.archived === !0 ? r.archived = (/* @__PURE__ */ new Date()).toISOString() : e.archived === !1 && (r.archived = null), e.clicked === !0 ? r.clicked = (/* @__PURE__ */ new Date()).toISOString() : e.clicked === !1 && (r.clicked = null), e.opened === !0 ? r.opened = (/* @__PURE__ */ new Date()).toISOString() : e.opened === !1 && (r.opened = null), i.rest.patchNotifications(r);
|
|
143
146
|
},
|
|
144
|
-
getPreferences: async () =>
|
|
145
|
-
updateDeliveryOption: async (e) =>
|
|
147
|
+
getPreferences: async () => i.rest.getPreferences(),
|
|
148
|
+
updateDeliveryOption: async (e) => i.rest.postPreferences([e]),
|
|
146
149
|
identify: async (e) => {
|
|
147
|
-
if (e.id && e.id !==
|
|
150
|
+
if (e.id && e.id !== i.config.userId)
|
|
148
151
|
throw new Error(
|
|
149
152
|
"The id in the parameters does not match the initialized userId."
|
|
150
153
|
);
|
|
151
|
-
return
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
+
return i.rest.postUser(e);
|
|
155
|
+
},
|
|
156
|
+
getUserAccountMetadata: async () => i.rest.getUserAccountMetadata()
|
|
157
|
+
}, F = Q(
|
|
154
158
|
void 0
|
|
155
|
-
),
|
|
156
|
-
const
|
|
159
|
+
), te = (e) => {
|
|
160
|
+
const o = {
|
|
157
161
|
...{
|
|
158
162
|
apiURL: "https://api.notificationapi.com",
|
|
159
163
|
wsURL: "wss://ws.notificationapi.com",
|
|
160
164
|
initialLoadMaxCount: 1e3,
|
|
161
165
|
initialLoadMaxAge: new Date((/* @__PURE__ */ new Date()).setMonth((/* @__PURE__ */ new Date()).getMonth() - 3)),
|
|
162
166
|
playSoundOnNewNotification: !1,
|
|
163
|
-
newNotificationSoundPath: "https://proxy.notificationsounds.com/notification-sounds/elegant-notification-sound/download/file-sounds-1233-elegant.mp3"
|
|
167
|
+
newNotificationSoundPath: "https://proxy.notificationsounds.com/notification-sounds/elegant-notification-sound/download/file-sounds-1233-elegant.mp3",
|
|
168
|
+
webPushOptInMessage: "AUTOMATIC",
|
|
169
|
+
customServiceWorkerPath: "/notificationapi-service-worker.js"
|
|
164
170
|
},
|
|
165
171
|
...e,
|
|
166
172
|
user: "userId" in e ? { id: e.userId } : e.user
|
|
167
|
-
}, [a, f] =
|
|
168
|
-
|
|
169
|
-
console.log("Failed to play new notification sound:",
|
|
173
|
+
}, [a, f] = I(), [b, h] = I(), [l, g] = I(), [w, y] = I(!1), [k, C] = I((/* @__PURE__ */ new Date()).toISOString()), [A, U] = I(!0), [v, N] = I(o.webPushOptInMessage), [x, J] = I(!1), W = m(() => {
|
|
174
|
+
o.playSoundOnNewNotification && new Audio(o.newNotificationSoundPath).play().catch((s) => {
|
|
175
|
+
console.log("Failed to play new notification sound:", s);
|
|
170
176
|
});
|
|
171
|
-
}, [
|
|
172
|
-
const
|
|
173
|
-
f((
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
177
|
+
}, [o.newNotificationSoundPath, o.playSoundOnNewNotification]), S = m((t) => {
|
|
178
|
+
const s = (/* @__PURE__ */ new Date()).toISOString();
|
|
179
|
+
f((n) => (t = t.filter((d) => {
|
|
180
|
+
const p = d.expDate && new Date(d.expDate * 1e3).toISOString() < s, D = new Date(d.date).getTime() > new Date(s).getTime() + 1e3;
|
|
181
|
+
return !p && !D;
|
|
182
|
+
}), n ? [
|
|
183
|
+
...t.filter((d) => !n.find((D) => D.id === d.id)),
|
|
184
|
+
...n
|
|
185
|
+
] : t));
|
|
186
|
+
}, []), u = X(() => {
|
|
187
|
+
const t = e.client ? e.client : i.init({
|
|
188
|
+
clientId: o.clientId,
|
|
189
|
+
userId: o.user.id,
|
|
190
|
+
hashedUserId: o.hashedUserId,
|
|
191
|
+
onNewInAppNotifications: (s) => {
|
|
192
|
+
W(), S(s);
|
|
184
193
|
}
|
|
185
194
|
});
|
|
186
|
-
return
|
|
187
|
-
email:
|
|
188
|
-
number:
|
|
189
|
-
}),
|
|
195
|
+
return t.identify({
|
|
196
|
+
email: o.user.email,
|
|
197
|
+
number: o.user.number
|
|
198
|
+
}), t;
|
|
190
199
|
}, [
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
200
|
+
o.clientId,
|
|
201
|
+
o.user.id,
|
|
202
|
+
o.user.email,
|
|
203
|
+
o.user.number,
|
|
204
|
+
o.hashedUserId,
|
|
196
205
|
S,
|
|
197
|
-
|
|
206
|
+
W,
|
|
198
207
|
e.client
|
|
199
|
-
]),
|
|
200
|
-
async (
|
|
201
|
-
const
|
|
202
|
-
|
|
208
|
+
]), L = m(
|
|
209
|
+
async (t, s) => {
|
|
210
|
+
const n = await u.rest.getNotifications(t, s);
|
|
211
|
+
C(n.oldestReceived), U(n.couldLoadMore), S(n.notifications);
|
|
203
212
|
},
|
|
204
213
|
[S, u.rest]
|
|
205
|
-
),
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}, [
|
|
209
|
-
const
|
|
210
|
-
async (
|
|
211
|
-
if (!(!
|
|
212
|
-
|
|
214
|
+
), E = T(A), R = T(w), $ = T(k);
|
|
215
|
+
P(() => {
|
|
216
|
+
E.current = A, R.current = w, $.current = k;
|
|
217
|
+
}, [A, w, k]);
|
|
218
|
+
const O = m(
|
|
219
|
+
async (t) => {
|
|
220
|
+
if (!(!t && (!E.current || R.current))) {
|
|
221
|
+
y(!0);
|
|
213
222
|
try {
|
|
214
|
-
await
|
|
215
|
-
|
|
216
|
-
|
|
223
|
+
await L(
|
|
224
|
+
t ? (/* @__PURE__ */ new Date()).toISOString() : $.current,
|
|
225
|
+
t ? o.initialLoadMaxCount : 1e3
|
|
217
226
|
);
|
|
218
227
|
} finally {
|
|
219
|
-
|
|
228
|
+
y(!1);
|
|
220
229
|
}
|
|
221
230
|
}
|
|
222
231
|
},
|
|
223
|
-
[
|
|
224
|
-
),
|
|
232
|
+
[o.initialLoadMaxCount, L]
|
|
233
|
+
), q = async (t) => {
|
|
225
234
|
if (!a) return;
|
|
226
|
-
const
|
|
227
|
-
u.updateInAppNotifications({ ids:
|
|
235
|
+
const s = (/* @__PURE__ */ new Date()).toISOString(), n = a.filter((c) => t.includes(c.id) && !c.clicked).map((c) => c.id);
|
|
236
|
+
u.updateInAppNotifications({ ids: n, clicked: !0 }), f((c) => {
|
|
228
237
|
if (!c) return [];
|
|
229
238
|
const d = [...c];
|
|
230
|
-
return d.filter((
|
|
231
|
-
|
|
239
|
+
return d.filter((p) => n.includes(p.id)).forEach((p) => {
|
|
240
|
+
p.clicked = s;
|
|
232
241
|
}), d;
|
|
233
242
|
});
|
|
234
|
-
},
|
|
243
|
+
}, B = async () => {
|
|
235
244
|
if (!a) return;
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
ids:
|
|
245
|
+
const t = (/* @__PURE__ */ new Date()).toISOString(), s = a.filter((n) => !n.opened || !n.seen).map((n) => n.id);
|
|
246
|
+
s.length !== 0 && (u.updateInAppNotifications({
|
|
247
|
+
ids: s,
|
|
239
248
|
opened: !0
|
|
240
|
-
}), f((
|
|
241
|
-
if (!
|
|
242
|
-
const c = [...
|
|
243
|
-
return c.filter((d) =>
|
|
244
|
-
d.opened =
|
|
249
|
+
}), f((n) => {
|
|
250
|
+
if (!n) return [];
|
|
251
|
+
const c = [...n];
|
|
252
|
+
return c.filter((d) => s.includes(d.id)).forEach((d) => {
|
|
253
|
+
d.opened = t, d.seen = !0;
|
|
245
254
|
}), c;
|
|
246
255
|
}));
|
|
247
|
-
},
|
|
256
|
+
}, G = async (t) => {
|
|
248
257
|
if (!a) return;
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
ids:
|
|
258
|
+
const s = a.filter((n) => n.archived && (t === "ALL" || t.includes(n.id))).map((n) => n.id);
|
|
259
|
+
s.length !== 0 && (u.updateInAppNotifications({
|
|
260
|
+
ids: s,
|
|
252
261
|
archived: !1
|
|
253
|
-
}), f((
|
|
254
|
-
if (!
|
|
255
|
-
const c = [...
|
|
256
|
-
return c.filter((d) =>
|
|
262
|
+
}), f((n) => {
|
|
263
|
+
if (!n) return [];
|
|
264
|
+
const c = [...n];
|
|
265
|
+
return c.filter((d) => s.includes(d.id)).forEach((d) => {
|
|
257
266
|
d.archived = void 0;
|
|
258
267
|
}), c;
|
|
259
268
|
}));
|
|
260
|
-
},
|
|
269
|
+
}, K = async (t) => {
|
|
261
270
|
if (!a) return;
|
|
262
|
-
const
|
|
263
|
-
|
|
271
|
+
const s = (/* @__PURE__ */ new Date()).toISOString(), n = a.filter((c) => !c.archived && (t === "ALL" || t.includes(c.id))).map((c) => c.id);
|
|
272
|
+
n.length !== 0 && (u.updateInAppNotifications({ ids: n, archived: !0 }), f((c) => {
|
|
264
273
|
if (!c) return [];
|
|
265
274
|
const d = [...c];
|
|
266
|
-
return d.filter((
|
|
267
|
-
|
|
275
|
+
return d.filter((p) => n.includes(p.id)).forEach((p) => {
|
|
276
|
+
p.archived = s;
|
|
268
277
|
}), d;
|
|
269
278
|
}));
|
|
270
|
-
},
|
|
279
|
+
}, V = (t, s, n, c) => j([
|
|
271
280
|
{
|
|
272
|
-
notificationId:
|
|
273
|
-
channel:
|
|
274
|
-
delivery:
|
|
281
|
+
notificationId: t,
|
|
282
|
+
channel: s,
|
|
283
|
+
delivery: n,
|
|
275
284
|
subNotificationId: c
|
|
276
285
|
}
|
|
277
|
-
]),
|
|
278
|
-
u.rest.postPreferences(
|
|
279
|
-
u.getPreferences().then((
|
|
280
|
-
h(
|
|
286
|
+
]), j = (t) => {
|
|
287
|
+
u.rest.postPreferences(t).then(() => {
|
|
288
|
+
u.getPreferences().then((s) => {
|
|
289
|
+
h(s);
|
|
281
290
|
});
|
|
282
291
|
});
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
292
|
+
}, M = m(() => {
|
|
293
|
+
"serviceWorker" in navigator && navigator.serviceWorker.register(o.customServiceWorkerPath).then(async (t) => {
|
|
294
|
+
N(!1), Notification.requestPermission().then(async (s) => {
|
|
295
|
+
s === "granted" ? await t.pushManager.subscribe({
|
|
296
|
+
userVisibleOnly: !0,
|
|
297
|
+
applicationServerKey: l == null ? void 0 : l.userAccountMetadata.environmentVapidPublicKey
|
|
298
|
+
}).then(async (n) => {
|
|
299
|
+
const c = {
|
|
300
|
+
webPushTokens: [
|
|
301
|
+
{
|
|
302
|
+
sub: {
|
|
303
|
+
endpoint: n.toJSON().endpoint,
|
|
304
|
+
keys: n.toJSON().keys
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
]
|
|
308
|
+
};
|
|
309
|
+
await u.identify(c), console.log("index"), localStorage.setItem("hideWebPushOptInMessage", "true");
|
|
310
|
+
}) : s === "denied" && console.log("Permission for notifications was denied");
|
|
311
|
+
});
|
|
312
|
+
}).catch((t) => {
|
|
313
|
+
t.code === 18 ? console.error(
|
|
314
|
+
"NotificationAPI guide: Probably you are not setup the service worker correctly. Please check the documentation at https://docs.notificationapi.com/guides/web-push#step-by-step-implementation Step 3: Service Worker Setup."
|
|
315
|
+
) : t.code === 19 ? console.error(
|
|
316
|
+
"The operation is aborted. This can happen if the user denies the permission request."
|
|
317
|
+
) : t.code === 20 ? console.error(
|
|
318
|
+
"The operation is invalid. This can occur if the provided application server key is invalid. Please contact NotificationAPI support."
|
|
319
|
+
) : t.code === 21 ? console.error(
|
|
320
|
+
"The operation is not allowed. This can happen if the user has blocked notifications for the site. Please check your browser site settings Notifications part."
|
|
321
|
+
) : t.code === 22 ? console.error(
|
|
322
|
+
"The operation is not supported. This can occur if the browser does not support the required features."
|
|
323
|
+
) : console.error(t);
|
|
324
|
+
});
|
|
325
|
+
}, [
|
|
326
|
+
u,
|
|
327
|
+
o.customServiceWorkerPath,
|
|
328
|
+
l == null ? void 0 : l.userAccountMetadata.environmentVapidPublicKey
|
|
329
|
+
]);
|
|
330
|
+
P(() => {
|
|
331
|
+
f([]), y(!1), h(void 0), C((/* @__PURE__ */ new Date()).toISOString()), U(!0), O(!0), u.openWebSocket(), u.getPreferences().then((t) => {
|
|
332
|
+
h(t);
|
|
287
333
|
});
|
|
288
|
-
}, [u,
|
|
289
|
-
|
|
334
|
+
}, [u, O, M]), P(() => {
|
|
335
|
+
Notification.permission !== "default" && N(!1), v === "AUTOMATIC" && (N(
|
|
336
|
+
localStorage.getItem("hideWebPushOptInMessage") !== "true"
|
|
337
|
+
), u.getUserAccountMetadata().then((t) => {
|
|
338
|
+
g(t), N(t.userAccountMetadata.hasWebPushEnabled);
|
|
339
|
+
}));
|
|
340
|
+
}, [u, v]), P(() => {
|
|
341
|
+
x && M();
|
|
342
|
+
}, [x, M]);
|
|
343
|
+
const _ = {
|
|
290
344
|
notifications: a,
|
|
291
|
-
preferences:
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
345
|
+
preferences: b,
|
|
346
|
+
userAccountMetaData: l,
|
|
347
|
+
webPushOptInMessage: v,
|
|
348
|
+
loadNotifications: O,
|
|
349
|
+
markAsOpened: B,
|
|
350
|
+
markAsArchived: K,
|
|
351
|
+
markAsUnarchived: G,
|
|
352
|
+
markAsClicked: q,
|
|
353
|
+
updateDelivery: V,
|
|
354
|
+
updateDeliveries: j,
|
|
355
|
+
getClient: () => u,
|
|
356
|
+
setWebPushOptInMessage: N,
|
|
357
|
+
setWebPushOptIn: J
|
|
300
358
|
};
|
|
301
|
-
return /* @__PURE__ */
|
|
302
|
-
},
|
|
303
|
-
const e =
|
|
359
|
+
return /* @__PURE__ */ z(F.Provider, { value: _, children: e.children });
|
|
360
|
+
}, ne = () => {
|
|
361
|
+
const e = Y(F);
|
|
304
362
|
if (!e)
|
|
305
363
|
throw new Error("useMyContext must be used within a MyProvider");
|
|
306
364
|
return e;
|
|
307
365
|
};
|
|
308
|
-
|
|
366
|
+
te.useNotificationAPIContext = ne;
|
|
309
367
|
export {
|
|
310
|
-
|
|
311
|
-
|
|
368
|
+
F as NotificationAPIContext,
|
|
369
|
+
te as NotificationAPIProvider
|
|
312
370
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
|
|
3
|
+
interface WebPushOptInMessageProps {
|
|
4
|
+
hideAfterInteraction?: boolean;
|
|
5
|
+
alertContainerStyle?: React.CSSProperties;
|
|
6
|
+
descriptionStyle?: React.CSSProperties;
|
|
7
|
+
buttonContainerStyle?: React.CSSProperties;
|
|
8
|
+
yesButtonStyle?: React.CSSProperties;
|
|
9
|
+
cancelButtonStyle?: React.CSSProperties;
|
|
10
|
+
description?: string;
|
|
11
|
+
icon?: React.ReactNode;
|
|
12
|
+
}
|
|
13
|
+
declare const WebPushOptInMessage: React.FC<WebPushOptInMessageProps>;
|
|
14
|
+
export default WebPushOptInMessage;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@notificationapi/react",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.35",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "vite",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"**/*.css"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@notificationapi/core": "^0.0.
|
|
46
|
+
"@notificationapi/core": "^0.0.12",
|
|
47
47
|
"antd": "^5.17.4",
|
|
48
48
|
"javascript-time-ago": "^2.5.10",
|
|
49
49
|
"liquidjs": "^10.14.0",
|