@notificationapi/react 0.0.9 → 0.0.10
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/BellOutlined.js +18 -15
- package/dist/assets/Inbox.js +2376 -2270
- package/dist/assets/Notification.js +1960 -1340
- package/dist/assets/Preferences.js +564 -533
- package/dist/assets/PurePanel.js +24 -23
- package/dist/assets/button.js +275 -265
- package/dist/assets/colors.js +19298 -7652
- package/dist/assets/index.js +48 -47
- package/dist/assets/index2.js +94 -92
- package/dist/assets/index3.js +2990 -2647
- package/dist/components/Notifications/Inbox.d.ts +0 -1
- package/dist/components/Notifications/InboxHeader.d.ts +2 -3
- package/dist/components/Notifications/InboxHeader.js +14 -13
- package/dist/components/Notifications/Notification.d.ts +2 -3
- package/dist/components/Notifications/NotificationCounter.d.ts +1 -1
- package/dist/components/Notifications/NotificationFeed.d.ts +0 -1
- package/dist/components/Notifications/NotificationLauncher.d.ts +0 -1
- package/dist/components/Notifications/NotificationPopup.d.ts +0 -1
- package/dist/components/Notifications/UnreadBadge.d.ts +1 -1
- package/dist/components/Preferences/NotificationPreferencesInline.d.ts +2 -3
- package/dist/components/Preferences/NotificationPreferencesPopup.d.ts +2 -3
- package/dist/components/Preferences/NotificationPreferencesPopup.js +682 -646
- package/dist/components/Preferences/PreferenceGroup.d.ts +1 -2
- package/dist/components/Preferences/Preferences.d.ts +1 -2
- package/dist/components/Provider/index.d.ts +2 -2
- package/dist/components/Provider/index.js +80 -80
- package/package.json +1 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { default as React } from 'react';
|
|
2
1
|
import { Channels } from '../Provider';
|
|
3
2
|
|
|
4
3
|
export declare const getChannelLabel: (c: Channels) => string;
|
|
5
4
|
export declare const getChannelIcon: (channel: Channels) => React.ReactElement;
|
|
6
|
-
export declare function Preferences():
|
|
5
|
+
export declare function Preferences(): JSX.Element | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
2
|
|
|
3
3
|
type Props = {
|
|
4
4
|
clientId: string;
|
|
@@ -126,6 +126,6 @@ export type Context = {
|
|
|
126
126
|
markAsClicked: (id: string) => void;
|
|
127
127
|
updateDelivery: (notificationId: string, channel: Channels, delivery: DeliveryOptions, subNotificationId?: string) => void;
|
|
128
128
|
};
|
|
129
|
-
export declare const NotificationAPIContext:
|
|
129
|
+
export declare const NotificationAPIContext: import('react').Context<Context | undefined>;
|
|
130
130
|
export declare const NotificationAPIProvider: React.FunctionComponent<PropsWithChildren<Props>>;
|
|
131
131
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
1
|
+
import { jsx as y } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as B, useState as f, useEffect as O } from "react";
|
|
3
3
|
import { api as u } from "../../api.js";
|
|
4
4
|
const j = {
|
|
5
5
|
opened: "opened",
|
|
@@ -9,35 +9,35 @@ const j = {
|
|
|
9
9
|
actioned1: "actioned1",
|
|
10
10
|
actioned2: "actioned2"
|
|
11
11
|
};
|
|
12
|
-
var
|
|
13
|
-
const
|
|
12
|
+
var $ = /* @__PURE__ */ ((e) => (e.EMAIL = "EMAIL", e.INAPP_WEB = "INAPP_WEB", e.SMS = "SMS", e.CALL = "CALL", e.PUSH = "PUSH", e.WEB_PUSH = "WEB_PUSH", e))($ || {}), C = /* @__PURE__ */ ((e) => (e.OFF = "off", e.INSTANT = "instant", e.HOURLY = "hourly", e.DAILY = "daily", e.WEEKLY = "weekly", e.MONTHLY = "monthly", e))(C || {});
|
|
13
|
+
const x = B(
|
|
14
14
|
void 0
|
|
15
|
-
), J = (
|
|
16
|
-
const
|
|
15
|
+
), J = (e) => {
|
|
16
|
+
const c = {
|
|
17
17
|
...{
|
|
18
18
|
apiURL: "https://api.notificationapi.com",
|
|
19
19
|
wsURL: "wss://ws.notificationapi.com",
|
|
20
20
|
initialLoadMaxCount: 1e3,
|
|
21
21
|
initialLoadMaxAge: new Date((/* @__PURE__ */ new Date()).setMonth((/* @__PURE__ */ new Date()).getMonth() - 3))
|
|
22
22
|
},
|
|
23
|
-
...
|
|
24
|
-
}, [
|
|
25
|
-
l((
|
|
26
|
-
...o.filter((i) => !
|
|
27
|
-
...
|
|
23
|
+
...e
|
|
24
|
+
}, [r, l] = f(), [L, w] = f(), [S, A] = f(!1), [U, E] = f((/* @__PURE__ */ new Date()).toISOString()), [m, M] = f(!0), P = (o) => {
|
|
25
|
+
l((t) => t ? [
|
|
26
|
+
...o.filter((i) => !t.find((n) => n.id === i.id)),
|
|
27
|
+
...t
|
|
28
28
|
] : o);
|
|
29
|
-
}, k = async (o,
|
|
30
|
-
|
|
29
|
+
}, k = async (o, t) => (await u(
|
|
30
|
+
c.apiURL,
|
|
31
31
|
"GET",
|
|
32
|
-
`notifications/INAPP_WEB?count=${o}&before=${
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
)).notifications, T = async (o,
|
|
37
|
-
let n = [], a = o,
|
|
38
|
-
for (;
|
|
32
|
+
`notifications/INAPP_WEB?count=${o}&before=${t}`,
|
|
33
|
+
e.clientId,
|
|
34
|
+
e.userId,
|
|
35
|
+
e.hashedUserId
|
|
36
|
+
)).notifications, T = async (o, t, i) => {
|
|
37
|
+
let n = [], a = o, s = !0, d = !0;
|
|
38
|
+
for (; d; ) {
|
|
39
39
|
const g = (await k(
|
|
40
|
-
|
|
40
|
+
t,
|
|
41
41
|
new Date(a).getTime()
|
|
42
42
|
)).filter(
|
|
43
43
|
(I) => !n.find((h) => h.id === I.id)
|
|
@@ -45,130 +45,130 @@ const D = O(
|
|
|
45
45
|
a = g.reduce(
|
|
46
46
|
(I, h) => I < h.date ? I : h.date,
|
|
47
47
|
o
|
|
48
|
-
), n = [...n, ...g],
|
|
48
|
+
), n = [...n, ...g], s = g.length > 0, d = !0, (!s || n.length >= t || i && a < i) && (d = !1);
|
|
49
49
|
}
|
|
50
|
-
return console.log(n.length,
|
|
50
|
+
return console.log(n.length, s, a), {
|
|
51
51
|
notifications: n,
|
|
52
|
-
couldLoadMore:
|
|
52
|
+
couldLoadMore: s,
|
|
53
53
|
oldestReceived: a
|
|
54
54
|
};
|
|
55
55
|
}, N = async (o) => {
|
|
56
56
|
if (!m || S)
|
|
57
57
|
return;
|
|
58
|
-
|
|
59
|
-
const
|
|
58
|
+
A(!0);
|
|
59
|
+
const t = await T(
|
|
60
60
|
U,
|
|
61
|
-
o ?
|
|
62
|
-
o ?
|
|
61
|
+
o ? c.initialLoadMaxCount : 1e3,
|
|
62
|
+
o ? c.initialLoadMaxAge.toISOString() : void 0
|
|
63
63
|
);
|
|
64
|
-
E(
|
|
64
|
+
E(t.oldestReceived), M(t.couldLoadMore), P(t.notifications), A(!1);
|
|
65
65
|
}, R = async (o) => {
|
|
66
|
-
const
|
|
66
|
+
const t = (/* @__PURE__ */ new Date()).toISOString();
|
|
67
67
|
u(
|
|
68
|
-
|
|
68
|
+
c.apiURL,
|
|
69
69
|
"PATCH",
|
|
70
70
|
"notifications/INAPP_WEB",
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
e.clientId,
|
|
72
|
+
e.userId,
|
|
73
|
+
e.hashedUserId,
|
|
74
74
|
{
|
|
75
75
|
trackingIds: [o],
|
|
76
|
-
clicked:
|
|
76
|
+
clicked: t
|
|
77
77
|
}
|
|
78
78
|
), l((i) => {
|
|
79
79
|
if (!i)
|
|
80
80
|
return [];
|
|
81
|
-
const n = [...i], a = n.find((
|
|
82
|
-
return a && (a.clicked =
|
|
81
|
+
const n = [...i], a = n.find((s) => s.id === o);
|
|
82
|
+
return a && (a.clicked = t), n;
|
|
83
83
|
});
|
|
84
|
-
},
|
|
85
|
-
if (!
|
|
84
|
+
}, H = async () => {
|
|
85
|
+
if (!r)
|
|
86
86
|
return;
|
|
87
|
-
const o = (/* @__PURE__ */ new Date()).toISOString(),
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
const o = (/* @__PURE__ */ new Date()).toISOString(), t = r.filter((i) => !i.opened || !i.seen).map((i) => i.id);
|
|
88
|
+
t.length !== 0 && (u(
|
|
89
|
+
c.apiURL,
|
|
90
90
|
"PATCH",
|
|
91
91
|
"notifications/INAPP_WEB",
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
e.clientId,
|
|
93
|
+
e.userId,
|
|
94
|
+
e.hashedUserId,
|
|
95
95
|
{
|
|
96
|
-
trackingIds:
|
|
96
|
+
trackingIds: t,
|
|
97
97
|
opened: o
|
|
98
98
|
}
|
|
99
99
|
), l((i) => {
|
|
100
100
|
if (!i)
|
|
101
101
|
return [];
|
|
102
102
|
const n = [...i];
|
|
103
|
-
return n.filter((a) =>
|
|
103
|
+
return n.filter((a) => t.includes(a.id)).forEach((a) => {
|
|
104
104
|
a.opened = o, a.seen = !0;
|
|
105
105
|
}), n;
|
|
106
106
|
}));
|
|
107
|
-
},
|
|
108
|
-
if (!
|
|
107
|
+
}, W = async (o) => {
|
|
108
|
+
if (!r)
|
|
109
109
|
return;
|
|
110
|
-
const
|
|
110
|
+
const t = (/* @__PURE__ */ new Date()).toISOString(), i = r.filter((n) => !n.archived && (o === "ALL" || o.includes(n.id))).map((n) => n.id);
|
|
111
111
|
i.length !== 0 && (u(
|
|
112
|
-
|
|
112
|
+
c.apiURL,
|
|
113
113
|
"PATCH",
|
|
114
114
|
"notifications/INAPP_WEB",
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
e.clientId,
|
|
116
|
+
e.userId,
|
|
117
|
+
e.hashedUserId,
|
|
118
118
|
{
|
|
119
119
|
trackingIds: i,
|
|
120
|
-
archived:
|
|
120
|
+
archived: t
|
|
121
121
|
}
|
|
122
122
|
), l((n) => {
|
|
123
123
|
if (!n)
|
|
124
124
|
return [];
|
|
125
125
|
const a = [...n];
|
|
126
|
-
return a.filter((
|
|
127
|
-
|
|
126
|
+
return a.filter((s) => i.includes(s.id)).forEach((s) => {
|
|
127
|
+
s.archived = t;
|
|
128
128
|
}), a;
|
|
129
129
|
}));
|
|
130
|
-
},
|
|
130
|
+
}, _ = (o, t, i, n) => {
|
|
131
131
|
if (!L)
|
|
132
132
|
return;
|
|
133
|
-
const a = { ...L },
|
|
134
|
-
(
|
|
133
|
+
const a = { ...L }, s = a.preferences.find(
|
|
134
|
+
(d) => d.notificationId === o && d.subNotificationId === n && d.channel === t
|
|
135
135
|
);
|
|
136
|
-
|
|
136
|
+
s && (s.delivery = i), w(a);
|
|
137
137
|
};
|
|
138
|
-
|
|
138
|
+
O(() => {
|
|
139
139
|
N(!0);
|
|
140
140
|
const o = new WebSocket(
|
|
141
|
-
`${
|
|
141
|
+
c.hashedUserId ? `${c.wsURL}?userId=${c.userId}&envId=${c.clientId}&userIdHash=${c.hashedUserId}` : `${c.wsURL}?userId=${c.userId}&envId=${c.clientId}`
|
|
142
142
|
);
|
|
143
|
-
o.onmessage = (
|
|
144
|
-
const i = JSON.parse(
|
|
143
|
+
o.onmessage = (t) => {
|
|
144
|
+
const i = JSON.parse(t.data);
|
|
145
145
|
!i || !i.route || i.route === "inapp_web/new_notifications" && P(i.payload.notifications);
|
|
146
146
|
}, u(
|
|
147
|
-
|
|
147
|
+
c.apiURL,
|
|
148
148
|
"GET",
|
|
149
149
|
"preferences",
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
).then((
|
|
154
|
-
|
|
150
|
+
e.clientId,
|
|
151
|
+
e.userId,
|
|
152
|
+
e.hashedUserId
|
|
153
|
+
).then((t) => {
|
|
154
|
+
w(t);
|
|
155
155
|
});
|
|
156
156
|
}, []);
|
|
157
|
-
const
|
|
158
|
-
notifications:
|
|
157
|
+
const v = {
|
|
158
|
+
notifications: r,
|
|
159
159
|
preferences: L,
|
|
160
160
|
loadNotifications: N,
|
|
161
|
-
markAsOpened:
|
|
162
|
-
markAsArchived:
|
|
161
|
+
markAsOpened: H,
|
|
162
|
+
markAsArchived: W,
|
|
163
163
|
markAsClicked: R,
|
|
164
|
-
updateDelivery:
|
|
164
|
+
updateDelivery: _
|
|
165
165
|
};
|
|
166
|
-
return /* @__PURE__ */
|
|
166
|
+
return /* @__PURE__ */ y(x.Provider, { value: v, children: e.children });
|
|
167
167
|
};
|
|
168
168
|
export {
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
$ as Channels,
|
|
170
|
+
C as DeliveryOptions,
|
|
171
171
|
j as NOTIFICATION_ACTIONS,
|
|
172
|
-
|
|
172
|
+
x as NotificationAPIContext,
|
|
173
173
|
J as NotificationAPIProvider
|
|
174
174
|
};
|