@notificationapi/react 0.0.30 → 0.0.32
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/dist/assets/AntdIcon.js +4 -4
- package/dist/assets/Notification.js +3094 -2713
- package/dist/assets/PurePanel.js +2 -2
- package/dist/assets/RightOutlined.js +1 -1
- package/dist/assets/button.js +1394 -577
- package/dist/assets/channelUtils.js +1 -1
- package/dist/assets/colors.js +14798 -14301
- package/dist/assets/index.js +156 -158
- package/dist/assets/index2.js +212 -221
- package/dist/assets/index3.js +8307 -724
- package/dist/assets/pickAttrs.js +1 -1
- package/dist/assets/presets.js +810 -0
- package/dist/components/Notifications/Inbox.js +3520 -3323
- package/dist/components/Notifications/InboxHeader.d.ts +1 -2
- package/dist/components/Notifications/InboxHeader.js +2 -2
- package/dist/components/Notifications/Notification.js +1 -1
- package/dist/components/Notifications/NotificationFeed.js +1 -2
- package/dist/components/Preferences/NotificationPreferencesInline.d.ts +1 -2
- package/dist/components/Preferences/NotificationPreferencesPopup.d.ts +1 -2
- package/dist/components/Preferences/NotificationPreferencesPopup.js +1423 -857
- package/dist/components/Preferences/PreferenceInput.d.ts +1 -1
- package/dist/components/Preferences/PreferenceInput.js +843 -812
- package/dist/components/Preferences/Preferences.d.ts +1 -2
- package/dist/components/Preferences/Preferences.js +331 -328
- package/dist/components/Preferences/channelUtils.js +1 -1
- package/dist/components/Provider/index.js +77 -80
- package/package.json +5 -5
- package/dist/assets/index4.js +0 -8408
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as B } from "react/jsx-runtime";
|
|
2
|
-
import { createContext as z, useState as N, useCallback as
|
|
3
|
-
const J = async (e, s,
|
|
2
|
+
import { createContext as z, useState as N, useCallback as m, useMemo as F, useRef as k, useEffect as U, useContext as G } from "react";
|
|
3
|
+
const J = async (e, s, i, a, f, w, p) => {
|
|
4
4
|
const h = _(a, f, w), l = await fetch(
|
|
5
5
|
`https://${s}/${a}/users/${encodeURIComponent(
|
|
6
6
|
f
|
|
7
|
-
)}/${
|
|
7
|
+
)}/${i}`,
|
|
8
8
|
{
|
|
9
9
|
method: e,
|
|
10
10
|
body: JSON.stringify(p),
|
|
@@ -18,7 +18,7 @@ const J = async (e, s, c, a, f, w, p) => {
|
|
|
18
18
|
} catch {
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
|
-
}, _ = (e, s,
|
|
21
|
+
}, _ = (e, s, i) => btoa(i ? e + ":" + s + ":" + i : e + ":" + s), M = {
|
|
22
22
|
host: "api.notificationapi.com",
|
|
23
23
|
websocketHost: "ws.notificationapi.com",
|
|
24
24
|
userId: "",
|
|
@@ -39,7 +39,7 @@ const J = async (e, s, c, a, f, w, p) => {
|
|
|
39
39
|
};
|
|
40
40
|
},
|
|
41
41
|
rest: {
|
|
42
|
-
generic: function(e, s,
|
|
42
|
+
generic: function(e, s, i) {
|
|
43
43
|
return J(
|
|
44
44
|
e,
|
|
45
45
|
n.config.host,
|
|
@@ -47,7 +47,7 @@ const J = async (e, s, c, a, f, w, p) => {
|
|
|
47
47
|
n.config.clientId,
|
|
48
48
|
n.config.userId,
|
|
49
49
|
n.config.hashedUserId,
|
|
50
|
-
|
|
50
|
+
i
|
|
51
51
|
);
|
|
52
52
|
},
|
|
53
53
|
// The functions below are nice wrappers over the generic
|
|
@@ -85,9 +85,9 @@ const J = async (e, s, c, a, f, w, p) => {
|
|
|
85
85
|
connect: function() {
|
|
86
86
|
let e = `wss://${n.config.websocketHost}?userId=${encodeURIComponent(n.config.userId)}&envId=${n.config.clientId}`;
|
|
87
87
|
return n.config.hashedUserId && (e += `&userIdHash=${encodeURIComponent(n.config.hashedUserId)}`), n.websocket.object = new WebSocket(e), n.websocket.object.onmessage = (s) => {
|
|
88
|
-
const
|
|
89
|
-
if (!(!
|
|
90
|
-
const a =
|
|
88
|
+
const i = JSON.parse(s.data);
|
|
89
|
+
if (!(!i || !i.route) && i.route === "inapp_web/new_notifications") {
|
|
90
|
+
const a = i;
|
|
91
91
|
n.config.onNewInAppNotifications && n.config.onNewInAppNotifications(
|
|
92
92
|
a.payload.notifications
|
|
93
93
|
);
|
|
@@ -115,7 +115,7 @@ const J = async (e, s, c, a, f, w, p) => {
|
|
|
115
115
|
// They may or may not do additional tasks.
|
|
116
116
|
// e.g. identify simply maps to postUsers
|
|
117
117
|
getInAppNotifications: async (e) => {
|
|
118
|
-
const s = e.maxCountNeeded || n.config.getInAppDefaultCount,
|
|
118
|
+
const s = e.maxCountNeeded || n.config.getInAppDefaultCount, i = e.oldestNeeded || n.config.getInAppDefaultOldest;
|
|
119
119
|
let a = [], f = e.before, w = !0, p = !0;
|
|
120
120
|
for (; p; ) {
|
|
121
121
|
const h = (await n.rest.getNotifications(
|
|
@@ -127,7 +127,7 @@ const J = async (e, s, c, a, f, w, p) => {
|
|
|
127
127
|
f = h.reduce(
|
|
128
128
|
(l, g) => l < g.date ? l : g.date,
|
|
129
129
|
e.before
|
|
130
|
-
), a = [...a, ...h], w = h.length > 0, p = !0, (!w || a.length >= s || f <
|
|
130
|
+
), a = [...a, ...h], w = h.length > 0, p = !0, (!w || a.length >= s || f < i) && (p = !1);
|
|
131
131
|
}
|
|
132
132
|
return {
|
|
133
133
|
items: a,
|
|
@@ -153,7 +153,7 @@ const J = async (e, s, c, a, f, w, p) => {
|
|
|
153
153
|
}, E = z(
|
|
154
154
|
void 0
|
|
155
155
|
), q = (e) => {
|
|
156
|
-
const
|
|
156
|
+
const i = {
|
|
157
157
|
...{
|
|
158
158
|
apiURL: "https://api.notificationapi.com",
|
|
159
159
|
wsURL: "wss://ws.notificationapi.com",
|
|
@@ -164,134 +164,131 @@ const J = async (e, s, c, a, f, w, p) => {
|
|
|
164
164
|
},
|
|
165
165
|
...e,
|
|
166
166
|
user: "userId" in e ? { id: e.userId } : e.user
|
|
167
|
-
}, [a, f] = N(), [w, p] = N(), [h, l] = N(!1), [g,
|
|
168
|
-
|
|
167
|
+
}, [a, f] = N(), [w, p] = N(), [h, l] = N(!1), [g, y] = N((/* @__PURE__ */ new Date()).toISOString()), [b, P] = N(!0), D = m(() => {
|
|
168
|
+
i.playSoundOnNewNotification && new Audio(i.newNotificationSoundPath).play().catch((r) => {
|
|
169
169
|
console.log("Failed to play new notification sound:", r);
|
|
170
170
|
});
|
|
171
|
-
}, [
|
|
171
|
+
}, [i.newNotificationSoundPath, i.playSoundOnNewNotification]), S = m((o) => {
|
|
172
172
|
const r = (/* @__PURE__ */ new Date()).toISOString();
|
|
173
|
-
f((t) => (
|
|
174
|
-
...
|
|
173
|
+
f((t) => (o = o.filter((c) => !(c.expDate && new Date(c.expDate * 1e3).toISOString() > r || c.date > r)), t ? [
|
|
174
|
+
...o.filter((c) => !t.find((d) => d.id === c.id)),
|
|
175
175
|
...t
|
|
176
|
-
] :
|
|
176
|
+
] : o));
|
|
177
177
|
}, []), u = F(() => {
|
|
178
|
-
const
|
|
179
|
-
clientId:
|
|
180
|
-
userId:
|
|
181
|
-
hashedUserId:
|
|
178
|
+
const o = n.init({
|
|
179
|
+
clientId: i.clientId,
|
|
180
|
+
userId: i.user.id,
|
|
181
|
+
hashedUserId: i.hashedUserId,
|
|
182
182
|
onNewInAppNotifications: (r) => {
|
|
183
183
|
D(), S(r);
|
|
184
184
|
}
|
|
185
185
|
});
|
|
186
|
-
return
|
|
186
|
+
return o.identify({
|
|
187
|
+
email: i.user.email,
|
|
188
|
+
number: i.user.number
|
|
189
|
+
}), o;
|
|
187
190
|
}, [
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
+
i.clientId,
|
|
192
|
+
i.user.id,
|
|
193
|
+
i.user.email,
|
|
194
|
+
i.user.number,
|
|
195
|
+
i.hashedUserId,
|
|
191
196
|
S,
|
|
192
197
|
D
|
|
193
|
-
]), O =
|
|
194
|
-
async (
|
|
195
|
-
const t = await u.rest.getNotifications(
|
|
196
|
-
|
|
198
|
+
]), O = m(
|
|
199
|
+
async (o, r) => {
|
|
200
|
+
const t = await u.rest.getNotifications(o, r);
|
|
201
|
+
y(t.oldestReceived), P(t.couldLoadMore), S(t.notifications);
|
|
197
202
|
},
|
|
198
203
|
[S, u.rest]
|
|
199
|
-
), v =
|
|
204
|
+
), v = k(b), C = k(h), x = k(g);
|
|
200
205
|
U(() => {
|
|
201
206
|
v.current = b, C.current = h, x.current = g;
|
|
202
207
|
}, [b, h, g]);
|
|
203
|
-
const
|
|
204
|
-
async (
|
|
205
|
-
if (!(!
|
|
208
|
+
const A = m(
|
|
209
|
+
async (o) => {
|
|
210
|
+
if (!(!o && (!v.current || C.current))) {
|
|
206
211
|
l(!0);
|
|
207
212
|
try {
|
|
208
213
|
await O(
|
|
209
|
-
|
|
210
|
-
|
|
214
|
+
o ? (/* @__PURE__ */ new Date()).toISOString() : x.current,
|
|
215
|
+
o ? i.initialLoadMaxCount : 1e3
|
|
211
216
|
);
|
|
212
217
|
} finally {
|
|
213
218
|
l(!1);
|
|
214
219
|
}
|
|
215
220
|
}
|
|
216
221
|
},
|
|
217
|
-
[
|
|
218
|
-
), R = async (
|
|
219
|
-
if (!a)
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
return [];
|
|
225
|
-
const d = [...o];
|
|
222
|
+
[i.initialLoadMaxCount, O]
|
|
223
|
+
), R = async (o) => {
|
|
224
|
+
if (!a) return;
|
|
225
|
+
const r = (/* @__PURE__ */ new Date()).toISOString(), t = a.filter((c) => o.includes(c.id) && !c.clicked).map((c) => c.id);
|
|
226
|
+
u.updateInAppNotifications({ ids: t, clicked: !0 }), f((c) => {
|
|
227
|
+
if (!c) return [];
|
|
228
|
+
const d = [...c];
|
|
226
229
|
return d.filter((I) => t.includes(I.id)).forEach((I) => {
|
|
227
230
|
I.clicked = r;
|
|
228
231
|
}), d;
|
|
229
232
|
});
|
|
230
233
|
}, $ = async () => {
|
|
231
|
-
if (!a)
|
|
232
|
-
|
|
233
|
-
const i = (/* @__PURE__ */ new Date()).toISOString(), r = a.filter((t) => !t.opened || !t.seen).map((t) => t.id);
|
|
234
|
+
if (!a) return;
|
|
235
|
+
const o = (/* @__PURE__ */ new Date()).toISOString(), r = a.filter((t) => !t.opened || !t.seen).map((t) => t.id);
|
|
234
236
|
r.length !== 0 && (u.updateInAppNotifications({
|
|
235
237
|
ids: r,
|
|
236
238
|
opened: !0
|
|
237
239
|
}), f((t) => {
|
|
238
|
-
if (!t)
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}), o;
|
|
240
|
+
if (!t) return [];
|
|
241
|
+
const c = [...t];
|
|
242
|
+
return c.filter((d) => r.includes(d.id)).forEach((d) => {
|
|
243
|
+
d.opened = o, d.seen = !0;
|
|
244
|
+
}), c;
|
|
244
245
|
}));
|
|
245
|
-
}, j = async (
|
|
246
|
-
if (!a)
|
|
247
|
-
|
|
248
|
-
const r = a.filter((t) => t.archived && (i === "ALL" || i.includes(t.id))).map((t) => t.id);
|
|
246
|
+
}, j = async (o) => {
|
|
247
|
+
if (!a) return;
|
|
248
|
+
const r = a.filter((t) => t.archived && (o === "ALL" || o.includes(t.id))).map((t) => t.id);
|
|
249
249
|
r.length !== 0 && (u.updateInAppNotifications({
|
|
250
250
|
ids: r,
|
|
251
251
|
archived: !1
|
|
252
252
|
}), f((t) => {
|
|
253
|
-
if (!t)
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
return o.filter((d) => r.includes(d.id)).forEach((d) => {
|
|
253
|
+
if (!t) return [];
|
|
254
|
+
const c = [...t];
|
|
255
|
+
return c.filter((d) => r.includes(d.id)).forEach((d) => {
|
|
257
256
|
d.archived = void 0;
|
|
258
|
-
}),
|
|
257
|
+
}), c;
|
|
259
258
|
}));
|
|
260
|
-
}, T = async (
|
|
261
|
-
if (!a)
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
return [];
|
|
267
|
-
const d = [...o];
|
|
259
|
+
}, T = async (o) => {
|
|
260
|
+
if (!a) return;
|
|
261
|
+
const r = (/* @__PURE__ */ new Date()).toISOString(), t = a.filter((c) => !c.archived && (o === "ALL" || o.includes(c.id))).map((c) => c.id);
|
|
262
|
+
t.length !== 0 && (u.updateInAppNotifications({ ids: t, archived: !0 }), f((c) => {
|
|
263
|
+
if (!c) return [];
|
|
264
|
+
const d = [...c];
|
|
268
265
|
return d.filter((I) => t.includes(I.id)).forEach((I) => {
|
|
269
266
|
I.archived = r;
|
|
270
267
|
}), d;
|
|
271
268
|
}));
|
|
272
|
-
}, W = (
|
|
269
|
+
}, W = (o, r, t, c) => L([
|
|
273
270
|
{
|
|
274
|
-
notificationId:
|
|
271
|
+
notificationId: o,
|
|
275
272
|
channel: r,
|
|
276
273
|
delivery: t,
|
|
277
|
-
subNotificationId:
|
|
274
|
+
subNotificationId: c
|
|
278
275
|
}
|
|
279
|
-
]), L = (
|
|
280
|
-
u.rest.postPreferences(
|
|
276
|
+
]), L = (o) => {
|
|
277
|
+
u.rest.postPreferences(o).then(() => {
|
|
281
278
|
u.getPreferences().then((r) => {
|
|
282
279
|
p(r);
|
|
283
280
|
});
|
|
284
281
|
});
|
|
285
282
|
};
|
|
286
283
|
U(() => {
|
|
287
|
-
f([]), l(!1), p(void 0),
|
|
288
|
-
p(
|
|
284
|
+
f([]), l(!1), p(void 0), y((/* @__PURE__ */ new Date()).toISOString()), P(!0), A(!0), u.openWebSocket(), u.getPreferences().then((o) => {
|
|
285
|
+
p(o);
|
|
289
286
|
});
|
|
290
|
-
}, [u,
|
|
287
|
+
}, [u, A]);
|
|
291
288
|
const H = {
|
|
292
289
|
notifications: a,
|
|
293
290
|
preferences: w,
|
|
294
|
-
loadNotifications:
|
|
291
|
+
loadNotifications: A,
|
|
295
292
|
markAsOpened: $,
|
|
296
293
|
markAsArchived: T,
|
|
297
294
|
markAsUnarchived: j,
|
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.32",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "vite",
|
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
"prepublishOnly": "npm run build"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
|
-
"react": "^
|
|
17
|
-
"react-dom": "^
|
|
16
|
+
"react": "^17.0.2",
|
|
17
|
+
"react-dom": "^17.0.2"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@ant-design/icons": "^5.3.6",
|
|
21
21
|
"@types/node": "^20.12.7",
|
|
22
|
-
"@types/react": "^
|
|
23
|
-
"@types/react-dom": "^
|
|
22
|
+
"@types/react": "^17.0.38",
|
|
23
|
+
"@types/react-dom": "^17.0.11",
|
|
24
24
|
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
|
25
25
|
"@typescript-eslint/parser": "^7.2.0",
|
|
26
26
|
"@vitejs/plugin-react": "^4.2.1",
|