@notificationapi/react 0.0.11 → 0.0.13
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/components/Notifications/NotificationCounter.d.ts +1 -1
- package/dist/components/Notifications/NotificationCounter.js +3 -3
- package/dist/components/Notifications/UnreadBadge.d.ts +2 -1
- package/dist/components/Preferences/NotificationPreferencesInline.d.ts +3 -1
- package/dist/components/Preferences/NotificationPreferencesInline.js +5 -4
- package/dist/components/Provider/index.d.ts +13 -10
- package/dist/components/Provider/index.js +81 -75
- package/dist/interface.d.ts +1 -0
- package/package.json +1 -1
|
@@ -2,6 +2,6 @@ import { PropsWithChildren } from 'react';
|
|
|
2
2
|
import { UnreadBadgeProps } from './UnreadBadge';
|
|
3
3
|
|
|
4
4
|
export type NotificationCounterProps = Omit<UnreadBadgeProps, "count"> & {
|
|
5
|
-
|
|
5
|
+
count?: UnreadBadgeProps["count"];
|
|
6
6
|
};
|
|
7
7
|
export declare const NotificationCounter: React.FC<PropsWithChildren<NotificationCounterProps>>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as n } from "react/jsx-runtime";
|
|
2
2
|
import { UnreadBadge as r } from "./UnreadBadge.js";
|
|
3
|
-
const
|
|
4
|
-
const t = o.
|
|
3
|
+
const e = (o) => {
|
|
4
|
+
const t = o.count || "COUNT_UNOPENED_NOTIFICATIONS";
|
|
5
5
|
return /* @__PURE__ */ n(r, { ...o, count: t });
|
|
6
6
|
};
|
|
7
7
|
export {
|
|
8
|
-
|
|
8
|
+
e as NotificationCounter
|
|
9
9
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
2
|
import { NotificationPopupProps } from './NotificationPopup';
|
|
3
|
+
import { InAppNotification } from '../../interface';
|
|
3
4
|
|
|
4
5
|
export type UnreadBadgeProps = {
|
|
5
6
|
color?: "blue" | "purple" | "cyan" | "green" | "magenta" | "pink" | "red" | "orange" | "yellow" | "volcano" | "geekblue" | "lime" | "gold" | undefined;
|
|
@@ -8,7 +9,7 @@ export type UnreadBadgeProps = {
|
|
|
8
9
|
showZero?: boolean;
|
|
9
10
|
size?: "default" | "small";
|
|
10
11
|
style?: React.CSSProperties;
|
|
11
|
-
count?: keyof typeof COUNT_TYPE | ((notification:
|
|
12
|
+
count?: keyof typeof COUNT_TYPE | ((notification: InAppNotification) => boolean);
|
|
12
13
|
filter?: NotificationPopupProps["filter"];
|
|
13
14
|
};
|
|
14
15
|
export declare enum COUNT_TYPE {
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
|
|
2
|
+
type NotificationPreferencesInlineProps = {};
|
|
3
|
+
export declare function NotificationPreferencesInline(props: NotificationPreferencesInlineProps): JSX.Element;
|
|
4
|
+
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { jsx as r } from "react/jsx-runtime";
|
|
2
|
+
import { P as e } from "../../assets/Preferences.js";
|
|
3
|
+
function t(o) {
|
|
4
|
+
return /* @__PURE__ */ r(e, {});
|
|
4
5
|
}
|
|
5
6
|
export {
|
|
6
|
-
|
|
7
|
+
t as NotificationPreferencesInline
|
|
7
8
|
};
|
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
2
|
import { InAppNotification } from '../../interface';
|
|
3
3
|
|
|
4
|
-
type Props = {
|
|
5
|
-
clientId: string;
|
|
6
|
-
userId: string;
|
|
7
|
-
hashedUserId?: string;
|
|
8
|
-
apiURL?: string;
|
|
9
|
-
wsURL?: string;
|
|
10
|
-
initialLoadMaxCount?: number;
|
|
11
|
-
initialLoadMaxAge?: Date;
|
|
12
|
-
};
|
|
13
4
|
export declare const NOTIFICATION_ACTIONS: {
|
|
14
5
|
opened: string;
|
|
15
6
|
clicked: string;
|
|
@@ -109,5 +100,17 @@ export type Context = {
|
|
|
109
100
|
updateDelivery: (notificationId: string, channel: Channels, delivery: DeliveryOptions, subNotificationId?: string) => void;
|
|
110
101
|
};
|
|
111
102
|
export declare const NotificationAPIContext: import('react').Context<Context | undefined>;
|
|
112
|
-
|
|
103
|
+
type Props = {
|
|
104
|
+
clientId: string;
|
|
105
|
+
userId: string;
|
|
106
|
+
hashedUserId?: string;
|
|
107
|
+
apiURL?: string;
|
|
108
|
+
wsURL?: string;
|
|
109
|
+
initialLoadMaxCount?: number;
|
|
110
|
+
initialLoadMaxAge?: Date;
|
|
111
|
+
};
|
|
112
|
+
export declare const NotificationAPIProvider: React.FunctionComponent<PropsWithChildren<Props>> & {
|
|
113
|
+
useNotificationAPIContext: typeof useNotificationAPIContext;
|
|
114
|
+
};
|
|
115
|
+
declare const useNotificationAPIContext: () => Context;
|
|
113
116
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
import { api as
|
|
4
|
-
const
|
|
1
|
+
import { jsx as W } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as _, useState as f, useEffect as y, useContext as v } from "react";
|
|
3
|
+
import { api as s } from "../../api.js";
|
|
4
|
+
const q = {
|
|
5
5
|
opened: "opened",
|
|
6
6
|
clicked: "clicked",
|
|
7
7
|
archived: "archived",
|
|
@@ -9,10 +9,10 @@ const j = {
|
|
|
9
9
|
actioned1: "actioned1",
|
|
10
10
|
actioned2: "actioned2"
|
|
11
11
|
};
|
|
12
|
-
var
|
|
13
|
-
const
|
|
12
|
+
var B = /* @__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))(B || {}), $ = /* @__PURE__ */ ((e) => (e.OFF = "off", e.INSTANT = "instant", e.HOURLY = "hourly", e.DAILY = "daily", e.WEEKLY = "weekly", e.MONTHLY = "monthly", e))($ || {});
|
|
13
|
+
const g = _(
|
|
14
14
|
void 0
|
|
15
|
-
),
|
|
15
|
+
), b = (e) => {
|
|
16
16
|
const c = {
|
|
17
17
|
...{
|
|
18
18
|
apiURL: "https://api.notificationapi.com",
|
|
@@ -21,51 +21,51 @@ const y = x(
|
|
|
21
21
|
initialLoadMaxAge: new Date((/* @__PURE__ */ new Date()).setMonth((/* @__PURE__ */ new Date()).getMonth() - 3))
|
|
22
22
|
},
|
|
23
23
|
...e
|
|
24
|
-
}, [
|
|
24
|
+
}, [d, u] = f(), [N, w] = f(), [U, S] = f(!1), [E, M] = f((/* @__PURE__ */ new Date()).toISOString()), [m, T] = f(!0), A = (o) => {
|
|
25
25
|
const n = (/* @__PURE__ */ new Date()).toISOString();
|
|
26
|
-
u((t) => (
|
|
27
|
-
...
|
|
26
|
+
u((t) => (o = o.filter((i) => !(i.expDate && new Date(i.expDate * 1e3).toISOString() > n || i.date > n)), t ? [
|
|
27
|
+
...o.filter((i) => !t.find((a) => a.id === i.id)),
|
|
28
28
|
...t
|
|
29
|
-
] :
|
|
30
|
-
},
|
|
29
|
+
] : o));
|
|
30
|
+
}, k = async (o, n) => (await s(
|
|
31
31
|
c.apiURL,
|
|
32
32
|
"GET",
|
|
33
|
-
`notifications/INAPP_WEB?count=${
|
|
33
|
+
`notifications/INAPP_WEB?count=${o}&before=${n}`,
|
|
34
34
|
e.clientId,
|
|
35
35
|
e.userId,
|
|
36
36
|
e.hashedUserId
|
|
37
|
-
)).notifications,
|
|
38
|
-
let i = [],
|
|
37
|
+
)).notifications, x = async (o, n, t) => {
|
|
38
|
+
let i = [], a = o, r = !0, h = !0;
|
|
39
39
|
for (; h; ) {
|
|
40
|
-
const L = (await
|
|
40
|
+
const L = (await k(
|
|
41
41
|
n,
|
|
42
|
-
new Date(
|
|
42
|
+
new Date(a).getTime()
|
|
43
43
|
)).filter(
|
|
44
44
|
(I) => !i.find((l) => l.id === I.id)
|
|
45
45
|
);
|
|
46
|
-
|
|
46
|
+
a = L.reduce(
|
|
47
47
|
(I, l) => I < l.date ? I : l.date,
|
|
48
|
-
|
|
49
|
-
), i = [...i, ...L],
|
|
48
|
+
o
|
|
49
|
+
), i = [...i, ...L], r = L.length > 0, h = !0, (!r || i.length >= n || t && a < t) && (h = !1);
|
|
50
50
|
}
|
|
51
51
|
return {
|
|
52
52
|
notifications: i,
|
|
53
|
-
couldLoadMore:
|
|
54
|
-
oldestReceived:
|
|
53
|
+
couldLoadMore: r,
|
|
54
|
+
oldestReceived: a
|
|
55
55
|
};
|
|
56
|
-
},
|
|
56
|
+
}, P = async (o) => {
|
|
57
57
|
if (!m || U)
|
|
58
58
|
return;
|
|
59
|
-
|
|
60
|
-
const n = await
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
S(!0);
|
|
60
|
+
const n = await x(
|
|
61
|
+
E,
|
|
62
|
+
o ? c.initialLoadMaxCount : 1e3,
|
|
63
|
+
o ? c.initialLoadMaxAge.toISOString() : void 0
|
|
64
64
|
);
|
|
65
|
-
|
|
66
|
-
}, R = async (
|
|
65
|
+
M(n.oldestReceived), T(n.couldLoadMore), A(n.notifications), S(!1);
|
|
66
|
+
}, R = async (o) => {
|
|
67
67
|
const n = (/* @__PURE__ */ new Date()).toISOString();
|
|
68
|
-
|
|
68
|
+
s(
|
|
69
69
|
c.apiURL,
|
|
70
70
|
"PATCH",
|
|
71
71
|
"notifications/INAPP_WEB",
|
|
@@ -73,20 +73,20 @@ const y = x(
|
|
|
73
73
|
e.userId,
|
|
74
74
|
e.hashedUserId,
|
|
75
75
|
{
|
|
76
|
-
trackingIds: [
|
|
76
|
+
trackingIds: [o],
|
|
77
77
|
clicked: n
|
|
78
78
|
}
|
|
79
79
|
), u((t) => {
|
|
80
80
|
if (!t)
|
|
81
81
|
return [];
|
|
82
|
-
const i = [...t],
|
|
83
|
-
return
|
|
82
|
+
const i = [...t], a = i.find((r) => r.id === o);
|
|
83
|
+
return a && (a.clicked = n), i;
|
|
84
84
|
});
|
|
85
|
-
},
|
|
86
|
-
if (!
|
|
85
|
+
}, C = async () => {
|
|
86
|
+
if (!d)
|
|
87
87
|
return;
|
|
88
|
-
const
|
|
89
|
-
n.length !== 0 && (
|
|
88
|
+
const o = (/* @__PURE__ */ new Date()).toISOString(), n = d.filter((t) => !t.opened || !t.seen).map((t) => t.id);
|
|
89
|
+
n.length !== 0 && (s(
|
|
90
90
|
c.apiURL,
|
|
91
91
|
"PATCH",
|
|
92
92
|
"notifications/INAPP_WEB",
|
|
@@ -95,21 +95,21 @@ const y = x(
|
|
|
95
95
|
e.hashedUserId,
|
|
96
96
|
{
|
|
97
97
|
trackingIds: n,
|
|
98
|
-
opened:
|
|
98
|
+
opened: o
|
|
99
99
|
}
|
|
100
100
|
), u((t) => {
|
|
101
101
|
if (!t)
|
|
102
102
|
return [];
|
|
103
103
|
const i = [...t];
|
|
104
|
-
return i.filter((
|
|
105
|
-
|
|
104
|
+
return i.filter((a) => n.includes(a.id)).forEach((a) => {
|
|
105
|
+
a.opened = o, a.seen = !0;
|
|
106
106
|
}), i;
|
|
107
107
|
}));
|
|
108
|
-
},
|
|
109
|
-
if (!
|
|
108
|
+
}, O = async (o) => {
|
|
109
|
+
if (!d)
|
|
110
110
|
return;
|
|
111
|
-
const n = (/* @__PURE__ */ new Date()).toISOString(), t =
|
|
112
|
-
t.length !== 0 && (
|
|
111
|
+
const n = (/* @__PURE__ */ new Date()).toISOString(), t = d.filter((i) => !i.archived && (o === "ALL" || o.includes(i.id))).map((i) => i.id);
|
|
112
|
+
t.length !== 0 && (s(
|
|
113
113
|
c.apiURL,
|
|
114
114
|
"PATCH",
|
|
115
115
|
"notifications/INAPP_WEB",
|
|
@@ -123,13 +123,13 @@ const y = x(
|
|
|
123
123
|
), u((i) => {
|
|
124
124
|
if (!i)
|
|
125
125
|
return [];
|
|
126
|
-
const
|
|
127
|
-
return
|
|
128
|
-
|
|
129
|
-
}),
|
|
126
|
+
const a = [...i];
|
|
127
|
+
return a.filter((r) => t.includes(r.id)).forEach((r) => {
|
|
128
|
+
r.archived = n;
|
|
129
|
+
}), a;
|
|
130
130
|
}));
|
|
131
|
-
},
|
|
132
|
-
|
|
131
|
+
}, D = (o, n, t, i) => {
|
|
132
|
+
s(
|
|
133
133
|
c.apiURL,
|
|
134
134
|
"POST",
|
|
135
135
|
"preferences",
|
|
@@ -138,34 +138,34 @@ const y = x(
|
|
|
138
138
|
e.hashedUserId,
|
|
139
139
|
[
|
|
140
140
|
{
|
|
141
|
-
notificationId:
|
|
141
|
+
notificationId: o,
|
|
142
142
|
subNotificationId: i,
|
|
143
143
|
channel: n,
|
|
144
144
|
delivery: t
|
|
145
145
|
}
|
|
146
146
|
]
|
|
147
147
|
).then(() => {
|
|
148
|
-
|
|
148
|
+
s(
|
|
149
149
|
c.apiURL,
|
|
150
150
|
"GET",
|
|
151
151
|
"preferences",
|
|
152
152
|
e.clientId,
|
|
153
153
|
e.userId,
|
|
154
154
|
e.hashedUserId
|
|
155
|
-
).then((
|
|
156
|
-
|
|
155
|
+
).then((a) => {
|
|
156
|
+
w(a);
|
|
157
157
|
});
|
|
158
158
|
});
|
|
159
159
|
};
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const
|
|
160
|
+
y(() => {
|
|
161
|
+
P(!0);
|
|
162
|
+
const o = new WebSocket(
|
|
163
163
|
c.hashedUserId ? `${c.wsURL}?userId=${c.userId}&envId=${c.clientId}&userIdHash=${c.hashedUserId}` : `${c.wsURL}?userId=${c.userId}&envId=${c.clientId}`
|
|
164
164
|
);
|
|
165
|
-
|
|
165
|
+
o.onmessage = (n) => {
|
|
166
166
|
const t = JSON.parse(n.data);
|
|
167
|
-
!t || !t.route || t.route === "inapp_web/new_notifications" &&
|
|
168
|
-
},
|
|
167
|
+
!t || !t.route || t.route === "inapp_web/new_notifications" && A(t.payload.notifications);
|
|
168
|
+
}, s(
|
|
169
169
|
c.apiURL,
|
|
170
170
|
"GET",
|
|
171
171
|
"preferences",
|
|
@@ -173,24 +173,30 @@ const y = x(
|
|
|
173
173
|
e.userId,
|
|
174
174
|
e.hashedUserId
|
|
175
175
|
).then((n) => {
|
|
176
|
-
|
|
176
|
+
w(n);
|
|
177
177
|
});
|
|
178
178
|
}, []);
|
|
179
|
-
const
|
|
180
|
-
notifications:
|
|
181
|
-
preferences:
|
|
182
|
-
loadNotifications:
|
|
183
|
-
markAsOpened:
|
|
184
|
-
markAsArchived:
|
|
179
|
+
const H = {
|
|
180
|
+
notifications: d,
|
|
181
|
+
preferences: N,
|
|
182
|
+
loadNotifications: P,
|
|
183
|
+
markAsOpened: C,
|
|
184
|
+
markAsArchived: O,
|
|
185
185
|
markAsClicked: R,
|
|
186
|
-
updateDelivery:
|
|
186
|
+
updateDelivery: D
|
|
187
187
|
};
|
|
188
|
-
return /* @__PURE__ */
|
|
188
|
+
return /* @__PURE__ */ W(g.Provider, { value: H, children: e.children });
|
|
189
|
+
}, Y = () => {
|
|
190
|
+
const e = v(g);
|
|
191
|
+
if (!e)
|
|
192
|
+
throw new Error("useMyContext must be used within a MyProvider");
|
|
193
|
+
return e;
|
|
189
194
|
};
|
|
195
|
+
b.useNotificationAPIContext = Y;
|
|
190
196
|
export {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
197
|
+
B as Channels,
|
|
198
|
+
$ as DeliveryOptions,
|
|
199
|
+
q as NOTIFICATION_ACTIONS,
|
|
200
|
+
g as NotificationAPIContext,
|
|
201
|
+
b as NotificationAPIProvider
|
|
196
202
|
};
|
package/dist/interface.d.ts
CHANGED