@notificationapi/react 0.0.8 → 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 +3 -2
- package/dist/components/Provider/index.js +102 -96
- 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,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
2
|
|
|
3
3
|
type Props = {
|
|
4
4
|
clientId: string;
|
|
5
5
|
userId: string;
|
|
6
|
+
hashedUserId?: string;
|
|
6
7
|
apiURL?: string;
|
|
7
8
|
wsURL?: string;
|
|
8
9
|
initialLoadMaxCount?: number;
|
|
@@ -125,6 +126,6 @@ export type Context = {
|
|
|
125
126
|
markAsClicked: (id: string) => void;
|
|
126
127
|
updateDelivery: (notificationId: string, channel: Channels, delivery: DeliveryOptions, subNotificationId?: string) => void;
|
|
127
128
|
};
|
|
128
|
-
export declare const NotificationAPIContext:
|
|
129
|
+
export declare const NotificationAPIContext: import('react').Context<Context | undefined>;
|
|
129
130
|
export declare const NotificationAPIProvider: React.FunctionComponent<PropsWithChildren<Props>>;
|
|
130
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,160 +9,166 @@ 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
|
-
),
|
|
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
|
-
},
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
+
const g = (await k(
|
|
40
|
+
t,
|
|
41
|
+
new Date(a).getTime()
|
|
41
42
|
)).filter(
|
|
42
|
-
(I) => !n.find((
|
|
43
|
+
(I) => !n.find((h) => h.id === I.id)
|
|
43
44
|
);
|
|
44
|
-
|
|
45
|
-
(I,
|
|
45
|
+
a = g.reduce(
|
|
46
|
+
(I, h) => I < h.date ? I : h.date,
|
|
46
47
|
o
|
|
47
|
-
), n = [...n, ...
|
|
48
|
+
), n = [...n, ...g], s = g.length > 0, d = !0, (!s || n.length >= t || i && a < i) && (d = !1);
|
|
48
49
|
}
|
|
49
|
-
return console.log(n.length,
|
|
50
|
+
return console.log(n.length, s, a), {
|
|
50
51
|
notifications: n,
|
|
51
|
-
couldLoadMore:
|
|
52
|
-
oldestReceived:
|
|
52
|
+
couldLoadMore: s,
|
|
53
|
+
oldestReceived: a
|
|
53
54
|
};
|
|
54
|
-
},
|
|
55
|
-
if (!
|
|
55
|
+
}, N = async (o) => {
|
|
56
|
+
if (!m || S)
|
|
56
57
|
return;
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
o ?
|
|
61
|
-
o ?
|
|
58
|
+
A(!0);
|
|
59
|
+
const t = await T(
|
|
60
|
+
U,
|
|
61
|
+
o ? c.initialLoadMaxCount : 1e3,
|
|
62
|
+
o ? c.initialLoadMaxAge.toISOString() : void 0
|
|
62
63
|
);
|
|
63
|
-
|
|
64
|
+
E(t.oldestReceived), M(t.couldLoadMore), P(t.notifications), A(!1);
|
|
64
65
|
}, R = async (o) => {
|
|
65
|
-
const
|
|
66
|
+
const t = (/* @__PURE__ */ new Date()).toISOString();
|
|
66
67
|
u(
|
|
67
|
-
|
|
68
|
+
c.apiURL,
|
|
68
69
|
"PATCH",
|
|
69
70
|
"notifications/INAPP_WEB",
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
e.clientId,
|
|
72
|
+
e.userId,
|
|
73
|
+
e.hashedUserId,
|
|
73
74
|
{
|
|
74
75
|
trackingIds: [o],
|
|
75
|
-
clicked:
|
|
76
|
+
clicked: t
|
|
76
77
|
}
|
|
77
78
|
), l((i) => {
|
|
78
79
|
if (!i)
|
|
79
80
|
return [];
|
|
80
|
-
const n = [...i],
|
|
81
|
-
return
|
|
81
|
+
const n = [...i], a = n.find((s) => s.id === o);
|
|
82
|
+
return a && (a.clicked = t), n;
|
|
82
83
|
});
|
|
83
|
-
},
|
|
84
|
-
if (!
|
|
84
|
+
}, H = async () => {
|
|
85
|
+
if (!r)
|
|
85
86
|
return;
|
|
86
|
-
const o = (/* @__PURE__ */ new Date()).toISOString(),
|
|
87
|
-
|
|
88
|
-
|
|
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,
|
|
89
90
|
"PATCH",
|
|
90
91
|
"notifications/INAPP_WEB",
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
e.clientId,
|
|
93
|
+
e.userId,
|
|
94
|
+
e.hashedUserId,
|
|
94
95
|
{
|
|
95
|
-
trackingIds:
|
|
96
|
+
trackingIds: t,
|
|
96
97
|
opened: o
|
|
97
98
|
}
|
|
98
99
|
), l((i) => {
|
|
99
100
|
if (!i)
|
|
100
101
|
return [];
|
|
101
102
|
const n = [...i];
|
|
102
|
-
return n.filter((
|
|
103
|
-
|
|
103
|
+
return n.filter((a) => t.includes(a.id)).forEach((a) => {
|
|
104
|
+
a.opened = o, a.seen = !0;
|
|
104
105
|
}), n;
|
|
105
106
|
}));
|
|
106
|
-
},
|
|
107
|
-
if (!
|
|
107
|
+
}, W = async (o) => {
|
|
108
|
+
if (!r)
|
|
108
109
|
return;
|
|
109
|
-
const
|
|
110
|
+
const t = (/* @__PURE__ */ new Date()).toISOString(), i = r.filter((n) => !n.archived && (o === "ALL" || o.includes(n.id))).map((n) => n.id);
|
|
110
111
|
i.length !== 0 && (u(
|
|
111
|
-
|
|
112
|
+
c.apiURL,
|
|
112
113
|
"PATCH",
|
|
113
114
|
"notifications/INAPP_WEB",
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
e.clientId,
|
|
116
|
+
e.userId,
|
|
117
|
+
e.hashedUserId,
|
|
117
118
|
{
|
|
118
119
|
trackingIds: i,
|
|
119
|
-
archived:
|
|
120
|
+
archived: t
|
|
120
121
|
}
|
|
121
122
|
), l((n) => {
|
|
122
123
|
if (!n)
|
|
123
124
|
return [];
|
|
124
|
-
const
|
|
125
|
-
return
|
|
126
|
-
|
|
127
|
-
}),
|
|
125
|
+
const a = [...n];
|
|
126
|
+
return a.filter((s) => i.includes(s.id)).forEach((s) => {
|
|
127
|
+
s.archived = t;
|
|
128
|
+
}), a;
|
|
128
129
|
}));
|
|
129
|
-
},
|
|
130
|
-
if (!
|
|
130
|
+
}, _ = (o, t, i, n) => {
|
|
131
|
+
if (!L)
|
|
131
132
|
return;
|
|
132
|
-
const
|
|
133
|
-
(
|
|
133
|
+
const a = { ...L }, s = a.preferences.find(
|
|
134
|
+
(d) => d.notificationId === o && d.subNotificationId === n && d.channel === t
|
|
134
135
|
);
|
|
135
|
-
|
|
136
|
+
s && (s.delivery = i), w(a);
|
|
136
137
|
};
|
|
137
|
-
|
|
138
|
-
|
|
138
|
+
O(() => {
|
|
139
|
+
N(!0);
|
|
139
140
|
const o = new WebSocket(
|
|
140
|
-
`${
|
|
141
|
-
);
|
|
142
|
-
o.onmessage = (e) => {
|
|
143
|
-
const i = JSON.parse(e.data);
|
|
144
|
-
!i || !i.route || i.route === "inapp_web/new_notifications" && N(i.payload.notifications);
|
|
145
|
-
}, u(r.apiURL, "GET", "preferences", t.clientId, t.userId).then(
|
|
146
|
-
(e) => {
|
|
147
|
-
w(e);
|
|
148
|
-
}
|
|
141
|
+
c.hashedUserId ? `${c.wsURL}?userId=${c.userId}&envId=${c.clientId}&userIdHash=${c.hashedUserId}` : `${c.wsURL}?userId=${c.userId}&envId=${c.clientId}`
|
|
149
142
|
);
|
|
143
|
+
o.onmessage = (t) => {
|
|
144
|
+
const i = JSON.parse(t.data);
|
|
145
|
+
!i || !i.route || i.route === "inapp_web/new_notifications" && P(i.payload.notifications);
|
|
146
|
+
}, u(
|
|
147
|
+
c.apiURL,
|
|
148
|
+
"GET",
|
|
149
|
+
"preferences",
|
|
150
|
+
e.clientId,
|
|
151
|
+
e.userId,
|
|
152
|
+
e.hashedUserId
|
|
153
|
+
).then((t) => {
|
|
154
|
+
w(t);
|
|
155
|
+
});
|
|
150
156
|
}, []);
|
|
151
|
-
const
|
|
152
|
-
notifications:
|
|
153
|
-
preferences:
|
|
154
|
-
loadNotifications:
|
|
155
|
-
markAsOpened:
|
|
156
|
-
markAsArchived:
|
|
157
|
+
const v = {
|
|
158
|
+
notifications: r,
|
|
159
|
+
preferences: L,
|
|
160
|
+
loadNotifications: N,
|
|
161
|
+
markAsOpened: H,
|
|
162
|
+
markAsArchived: W,
|
|
157
163
|
markAsClicked: R,
|
|
158
|
-
updateDelivery:
|
|
164
|
+
updateDelivery: _
|
|
159
165
|
};
|
|
160
|
-
return /* @__PURE__ */
|
|
166
|
+
return /* @__PURE__ */ y(x.Provider, { value: v, children: e.children });
|
|
161
167
|
};
|
|
162
168
|
export {
|
|
163
|
-
|
|
164
|
-
|
|
169
|
+
$ as Channels,
|
|
170
|
+
C as DeliveryOptions,
|
|
165
171
|
j as NOTIFICATION_ACTIONS,
|
|
166
|
-
|
|
167
|
-
|
|
172
|
+
x as NotificationAPIContext,
|
|
173
|
+
J as NotificationAPIProvider
|
|
168
174
|
};
|