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