@notificationapi/react 0.0.19 → 0.0.21
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/Inbox.js +948 -932
- package/dist/assets/Notification.js +4857 -2072
- package/dist/components/Notifications/Inbox.d.ts +1 -1
- package/dist/components/Notifications/Notification.d.ts +3 -3
- package/dist/components/Provider/index.d.ts +1 -1
- package/dist/components/Provider/index.js +117 -108
- package/dist/interface.d.ts +29 -0
- package/dist/interface.js +4 -1
- package/package.json +2 -1
|
@@ -14,7 +14,7 @@ export type InboxProps = {
|
|
|
14
14
|
imageShape: keyof typeof ImageShape;
|
|
15
15
|
pageSize: number;
|
|
16
16
|
pagePosition: NotificationPopupProps["pagePosition"];
|
|
17
|
-
notificationRenderer: ((notification: InAppNotification) => JSX.Element) | undefined;
|
|
17
|
+
notificationRenderer: ((notification: InAppNotification[]) => JSX.Element) | undefined;
|
|
18
18
|
header?: InboxHeaderProps;
|
|
19
19
|
};
|
|
20
20
|
export declare const Inbox: React.FC<InboxProps>;
|
|
@@ -5,10 +5,10 @@ export declare enum ImageShape {
|
|
|
5
5
|
circle = "circle"
|
|
6
6
|
}
|
|
7
7
|
export type NotificationProps = {
|
|
8
|
-
|
|
8
|
+
notifications: InAppNotification[];
|
|
9
9
|
markAsArchived: (ids: string[] | "ALL") => void;
|
|
10
|
-
markAsClicked: (
|
|
10
|
+
markAsClicked: (ids: string[]) => void;
|
|
11
11
|
imageShape: keyof typeof ImageShape;
|
|
12
|
-
renderer?: (notification: InAppNotification) => JSX.Element;
|
|
12
|
+
renderer?: (notification: InAppNotification[]) => JSX.Element;
|
|
13
13
|
};
|
|
14
14
|
export declare const Notification: (props: NotificationProps) => JSX.Element;
|
|
@@ -97,7 +97,7 @@ export type Context = {
|
|
|
97
97
|
markAsOpened: () => void;
|
|
98
98
|
markAsArchived: (ids: string[] | "ALL") => void;
|
|
99
99
|
markAsUnarchived: (ids: string[] | "ALL") => void;
|
|
100
|
-
markAsClicked: (
|
|
100
|
+
markAsClicked: (ids: string[]) => void;
|
|
101
101
|
updateDelivery: (notificationId: string, channel: Channels, delivery: DeliveryOptions, subNotificationId?: string) => void;
|
|
102
102
|
};
|
|
103
103
|
export declare const NotificationAPIContext: import('react').Context<Context | undefined>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
1
|
+
import { jsx as B } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as $, useState as u, useEffect as b, useContext as Y } from "react";
|
|
3
3
|
import { api as d } from "../../api.js";
|
|
4
|
-
const
|
|
4
|
+
const X = {
|
|
5
5
|
opened: "opened",
|
|
6
6
|
clicked: "clicked",
|
|
7
7
|
archived: "archived",
|
|
@@ -9,10 +9,10 @@ const z = {
|
|
|
9
9
|
actioned1: "actioned1",
|
|
10
10
|
actioned2: "actioned2"
|
|
11
11
|
};
|
|
12
|
-
var
|
|
13
|
-
const
|
|
12
|
+
var F = /* @__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))(F || {}), G = /* @__PURE__ */ ((e) => (e.OFF = "off", e.INSTANT = "instant", e.HOURLY = "hourly", e.DAILY = "daily", e.WEEKLY = "weekly", e.MONTHLY = "monthly", e))(G || {});
|
|
13
|
+
const E = $(
|
|
14
14
|
void 0
|
|
15
|
-
),
|
|
15
|
+
), j = (e) => {
|
|
16
16
|
const c = {
|
|
17
17
|
...{
|
|
18
18
|
apiURL: "https://api.notificationapi.com",
|
|
@@ -21,50 +21,52 @@ const S = y(
|
|
|
21
21
|
initialLoadMaxAge: new Date((/* @__PURE__ */ new Date()).setMonth((/* @__PURE__ */ new Date()).getMonth() - 3))
|
|
22
22
|
},
|
|
23
23
|
...e
|
|
24
|
-
}, [s, f] = u(), [
|
|
25
|
-
const
|
|
26
|
-
f((
|
|
27
|
-
...
|
|
28
|
-
...
|
|
29
|
-
] :
|
|
30
|
-
},
|
|
24
|
+
}, [s, f] = u(), [m, h] = u(), [k, L] = u(!1), [M, g] = u((/* @__PURE__ */ new Date()).toISOString()), [T, A] = u(!0), P = (t) => {
|
|
25
|
+
const o = (/* @__PURE__ */ new Date()).toISOString();
|
|
26
|
+
f((n) => (t = t.filter((i) => !(i.expDate && new Date(i.expDate * 1e3).toISOString() > o || i.date > o)), n ? [
|
|
27
|
+
...t.filter((i) => !n.find((a) => a.id === i.id)),
|
|
28
|
+
...n
|
|
29
|
+
] : t));
|
|
30
|
+
}, O = async (t, o) => (await d(
|
|
31
31
|
c.apiURL,
|
|
32
32
|
"GET",
|
|
33
|
-
`notifications/INAPP_WEB?count=${
|
|
33
|
+
`notifications/INAPP_WEB?count=${t}&before=${o}`,
|
|
34
34
|
e.clientId,
|
|
35
35
|
e.userId,
|
|
36
36
|
e.hashedUserId
|
|
37
|
-
)).notifications, R = async (
|
|
38
|
-
let
|
|
39
|
-
for (;
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
new Date(
|
|
37
|
+
)).notifications, R = async (t, o, n) => {
|
|
38
|
+
let i = [], a = t, r = !0, w = !0;
|
|
39
|
+
for (; w; ) {
|
|
40
|
+
const S = (await O(
|
|
41
|
+
o,
|
|
42
|
+
new Date(a).getTime()
|
|
43
43
|
)).filter(
|
|
44
|
-
(
|
|
44
|
+
(l) => !i.find((I) => I.id === l.id)
|
|
45
45
|
);
|
|
46
|
-
|
|
47
|
-
(
|
|
48
|
-
|
|
49
|
-
),
|
|
46
|
+
a = S.reduce(
|
|
47
|
+
(l, I) => l < I.date ? l : I.date,
|
|
48
|
+
t
|
|
49
|
+
), i = [...i, ...S], r = S.length > 0, w = !0, (!r || i.length >= o || n && a < n) && (w = !1);
|
|
50
50
|
}
|
|
51
51
|
return {
|
|
52
|
-
notifications:
|
|
52
|
+
notifications: i,
|
|
53
53
|
couldLoadMore: r,
|
|
54
|
-
oldestReceived:
|
|
54
|
+
oldestReceived: a
|
|
55
55
|
};
|
|
56
|
-
},
|
|
57
|
-
if (!
|
|
56
|
+
}, U = async (t) => {
|
|
57
|
+
if (!t && !T || !t && k)
|
|
58
58
|
return;
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
L(!0);
|
|
60
|
+
const o = await R(
|
|
61
|
+
t ? (/* @__PURE__ */ new Date()).toISOString() : M,
|
|
62
|
+
t ? c.initialLoadMaxCount : 1e3,
|
|
63
|
+
t ? c.initialLoadMaxAge.toISOString() : void 0
|
|
64
64
|
);
|
|
65
|
-
|
|
66
|
-
},
|
|
67
|
-
|
|
65
|
+
g(o.oldestReceived), A(o.couldLoadMore), P(o.notifications), L(!1);
|
|
66
|
+
}, v = async (t) => {
|
|
67
|
+
if (!s)
|
|
68
|
+
return;
|
|
69
|
+
const o = (/* @__PURE__ */ new Date()).toISOString(), n = s.filter((i) => t.includes(i.id) && !i.clicked).map((i) => i.id);
|
|
68
70
|
d(
|
|
69
71
|
c.apiURL,
|
|
70
72
|
"PATCH",
|
|
@@ -73,20 +75,22 @@ const S = y(
|
|
|
73
75
|
e.userId,
|
|
74
76
|
e.hashedUserId,
|
|
75
77
|
{
|
|
76
|
-
trackingIds:
|
|
77
|
-
clicked:
|
|
78
|
+
trackingIds: n,
|
|
79
|
+
clicked: o
|
|
78
80
|
}
|
|
79
|
-
), f((
|
|
80
|
-
if (!
|
|
81
|
+
), f((i) => {
|
|
82
|
+
if (!i)
|
|
81
83
|
return [];
|
|
82
|
-
const
|
|
83
|
-
return
|
|
84
|
+
const a = [...i];
|
|
85
|
+
return a.filter((r) => n.includes(r.id)).forEach((r) => {
|
|
86
|
+
r.clicked = o;
|
|
87
|
+
}), a;
|
|
84
88
|
});
|
|
85
|
-
},
|
|
89
|
+
}, x = async () => {
|
|
86
90
|
if (!s)
|
|
87
91
|
return;
|
|
88
|
-
const
|
|
89
|
-
|
|
92
|
+
const t = (/* @__PURE__ */ new Date()).toISOString(), o = s.filter((n) => !n.opened || !n.seen).map((n) => n.id);
|
|
93
|
+
o.length !== 0 && (d(
|
|
90
94
|
c.apiURL,
|
|
91
95
|
"PATCH",
|
|
92
96
|
"notifications/INAPP_WEB",
|
|
@@ -94,22 +98,22 @@ const S = y(
|
|
|
94
98
|
e.userId,
|
|
95
99
|
e.hashedUserId,
|
|
96
100
|
{
|
|
97
|
-
trackingIds:
|
|
98
|
-
opened:
|
|
101
|
+
trackingIds: o,
|
|
102
|
+
opened: t
|
|
99
103
|
}
|
|
100
|
-
), f((
|
|
101
|
-
if (!
|
|
104
|
+
), f((n) => {
|
|
105
|
+
if (!n)
|
|
102
106
|
return [];
|
|
103
|
-
const
|
|
104
|
-
return
|
|
105
|
-
|
|
106
|
-
}),
|
|
107
|
+
const i = [...n];
|
|
108
|
+
return i.filter((a) => o.includes(a.id)).forEach((a) => {
|
|
109
|
+
a.opened = t, a.seen = !0;
|
|
110
|
+
}), i;
|
|
107
111
|
}));
|
|
108
|
-
}, C = async (
|
|
112
|
+
}, C = async (t) => {
|
|
109
113
|
if (!s)
|
|
110
114
|
return;
|
|
111
|
-
const
|
|
112
|
-
|
|
115
|
+
const o = s.filter((n) => n.archived && (t === "ALL" || t.includes(n.id))).map((n) => n.id);
|
|
116
|
+
o.length !== 0 && (d(
|
|
113
117
|
c.apiURL,
|
|
114
118
|
"PATCH",
|
|
115
119
|
"notifications/INAPP_WEB",
|
|
@@ -117,22 +121,22 @@ const S = y(
|
|
|
117
121
|
e.userId,
|
|
118
122
|
e.hashedUserId,
|
|
119
123
|
{
|
|
120
|
-
trackingIds:
|
|
124
|
+
trackingIds: o,
|
|
121
125
|
archived: null
|
|
122
126
|
}
|
|
123
|
-
), f((
|
|
124
|
-
if (!
|
|
127
|
+
), f((n) => {
|
|
128
|
+
if (!n)
|
|
125
129
|
return [];
|
|
126
|
-
const
|
|
127
|
-
return
|
|
128
|
-
|
|
129
|
-
}),
|
|
130
|
+
const i = [...n];
|
|
131
|
+
return i.filter((a) => o.includes(a.id)).forEach((a) => {
|
|
132
|
+
a.archived = void 0;
|
|
133
|
+
}), i;
|
|
130
134
|
}));
|
|
131
|
-
}, H = async (
|
|
135
|
+
}, H = async (t) => {
|
|
132
136
|
if (!s)
|
|
133
137
|
return;
|
|
134
|
-
const
|
|
135
|
-
|
|
138
|
+
const o = (/* @__PURE__ */ new Date()).toISOString(), n = s.filter((i) => !i.archived && (t === "ALL" || t.includes(i.id))).map((i) => i.id);
|
|
139
|
+
n.length !== 0 && (d(
|
|
136
140
|
c.apiURL,
|
|
137
141
|
"PATCH",
|
|
138
142
|
"notifications/INAPP_WEB",
|
|
@@ -140,18 +144,18 @@ const S = y(
|
|
|
140
144
|
e.userId,
|
|
141
145
|
e.hashedUserId,
|
|
142
146
|
{
|
|
143
|
-
trackingIds:
|
|
144
|
-
archived:
|
|
147
|
+
trackingIds: n,
|
|
148
|
+
archived: o
|
|
145
149
|
}
|
|
146
|
-
), f((
|
|
147
|
-
if (!
|
|
150
|
+
), f((i) => {
|
|
151
|
+
if (!i)
|
|
148
152
|
return [];
|
|
149
|
-
const
|
|
150
|
-
return
|
|
151
|
-
r.archived =
|
|
152
|
-
}),
|
|
153
|
+
const a = [...i];
|
|
154
|
+
return a.filter((r) => n.includes(r.id)).forEach((r) => {
|
|
155
|
+
r.archived = o;
|
|
156
|
+
}), a;
|
|
153
157
|
}));
|
|
154
|
-
},
|
|
158
|
+
}, D = (t, o, n, i) => {
|
|
155
159
|
d(
|
|
156
160
|
c.apiURL,
|
|
157
161
|
"POST",
|
|
@@ -161,10 +165,10 @@ const S = y(
|
|
|
161
165
|
e.hashedUserId,
|
|
162
166
|
[
|
|
163
167
|
{
|
|
164
|
-
notificationId:
|
|
165
|
-
subNotificationId:
|
|
166
|
-
channel:
|
|
167
|
-
delivery:
|
|
168
|
+
notificationId: t,
|
|
169
|
+
subNotificationId: i,
|
|
170
|
+
channel: o,
|
|
171
|
+
delivery: n
|
|
168
172
|
}
|
|
169
173
|
]
|
|
170
174
|
).then(() => {
|
|
@@ -175,52 +179,57 @@ const S = y(
|
|
|
175
179
|
e.clientId,
|
|
176
180
|
e.userId,
|
|
177
181
|
e.hashedUserId
|
|
178
|
-
).then((
|
|
179
|
-
|
|
182
|
+
).then((a) => {
|
|
183
|
+
h(a);
|
|
180
184
|
});
|
|
181
185
|
});
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
+
}, W = (t) => {
|
|
187
|
+
const o = JSON.parse(t.data);
|
|
188
|
+
!o || !o.route || o.route === "inapp_web/new_notifications" && P(o.payload.notifications);
|
|
189
|
+
}, _ = (t) => {
|
|
190
|
+
setTimeout(() => {
|
|
191
|
+
t.onclose = () => N(), t.close();
|
|
192
|
+
}, 9 * 60 * 1e3);
|
|
193
|
+
}, N = () => {
|
|
194
|
+
const t = new WebSocket(
|
|
186
195
|
c.hashedUserId ? `${c.wsURL}?userId=${c.userId}&envId=${c.clientId}&userIdHash=${c.hashedUserId}` : `${c.wsURL}?userId=${c.userId}&envId=${c.clientId}`
|
|
187
196
|
);
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
197
|
+
t.onopen = () => _(t), t.onmessage = W;
|
|
198
|
+
};
|
|
199
|
+
b(() => {
|
|
200
|
+
f([]), L(!1), h(void 0), g((/* @__PURE__ */ new Date()).toISOString()), A(!0), U(!0), N(), d(
|
|
192
201
|
c.apiURL,
|
|
193
202
|
"GET",
|
|
194
203
|
"preferences",
|
|
195
204
|
e.clientId,
|
|
196
205
|
e.userId,
|
|
197
206
|
e.hashedUserId
|
|
198
|
-
).then((
|
|
199
|
-
|
|
207
|
+
).then((t) => {
|
|
208
|
+
h(t);
|
|
200
209
|
});
|
|
201
|
-
}, []);
|
|
202
|
-
const
|
|
210
|
+
}, [e]);
|
|
211
|
+
const y = {
|
|
203
212
|
notifications: s,
|
|
204
|
-
preferences:
|
|
205
|
-
loadNotifications:
|
|
206
|
-
markAsOpened:
|
|
213
|
+
preferences: m,
|
|
214
|
+
loadNotifications: U,
|
|
215
|
+
markAsOpened: x,
|
|
207
216
|
markAsArchived: H,
|
|
208
217
|
markAsUnarchived: C,
|
|
209
|
-
markAsClicked:
|
|
210
|
-
updateDelivery:
|
|
218
|
+
markAsClicked: v,
|
|
219
|
+
updateDelivery: D
|
|
211
220
|
};
|
|
212
|
-
return /* @__PURE__ */
|
|
213
|
-
},
|
|
214
|
-
const e =
|
|
221
|
+
return /* @__PURE__ */ B(E.Provider, { value: y, children: e.children });
|
|
222
|
+
}, J = () => {
|
|
223
|
+
const e = Y(E);
|
|
215
224
|
if (!e)
|
|
216
225
|
throw new Error("useMyContext must be used within a MyProvider");
|
|
217
226
|
return e;
|
|
218
227
|
};
|
|
219
|
-
|
|
228
|
+
j.useNotificationAPIContext = J;
|
|
220
229
|
export {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
230
|
+
F as Channels,
|
|
231
|
+
G as DeliveryOptions,
|
|
232
|
+
X as NOTIFICATION_ACTIONS,
|
|
233
|
+
E as NotificationAPIContext,
|
|
234
|
+
j as NotificationAPIProvider
|
|
226
235
|
};
|
package/dist/interface.d.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
export declare enum DeliveryOptionsForInappWeb {
|
|
2
|
+
OFF = "off",
|
|
3
|
+
INSTANT = "instant"
|
|
4
|
+
}
|
|
5
|
+
export interface Template {
|
|
6
|
+
instant: {
|
|
7
|
+
title: string;
|
|
8
|
+
redirectURL: string;
|
|
9
|
+
imageURL: string;
|
|
10
|
+
};
|
|
11
|
+
batch: {
|
|
12
|
+
title: string;
|
|
13
|
+
redirectURL: string;
|
|
14
|
+
imageURL: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
1
17
|
export interface InAppNotification {
|
|
2
18
|
id: string;
|
|
3
19
|
notificationId: string;
|
|
@@ -6,6 +22,19 @@ export interface InAppNotification {
|
|
|
6
22
|
redirectURL?: string;
|
|
7
23
|
imageURL?: string;
|
|
8
24
|
date: string;
|
|
25
|
+
deliveryOptions?: {
|
|
26
|
+
defaultDeliveryOption: DeliveryOptionsForInappWeb;
|
|
27
|
+
[DeliveryOptionsForInappWeb.OFF]?: {
|
|
28
|
+
enabled: boolean;
|
|
29
|
+
};
|
|
30
|
+
[DeliveryOptionsForInappWeb.INSTANT]?: {
|
|
31
|
+
enabled: boolean;
|
|
32
|
+
batching?: boolean;
|
|
33
|
+
batchingKey?: string;
|
|
34
|
+
batchingWindow?: number;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
template?: Template;
|
|
9
38
|
parameters?: Record<string, unknown>;
|
|
10
39
|
expDate?: number;
|
|
11
40
|
opened?: string;
|
package/dist/interface.js
CHANGED
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.21",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "vite",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"antd": "^5.17.4",
|
|
44
44
|
"javascript-time-ago": "^2.5.10",
|
|
45
|
+
"liquidjs": "^10.14.0",
|
|
45
46
|
"rc-virtual-list": "^3.11.5",
|
|
46
47
|
"react-time-ago": "^7.3.3",
|
|
47
48
|
"styled-components": "^6.1.9"
|