@notificationapi/react 0.0.21 → 0.0.22
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/Preferences.js +432 -448
- package/dist/components/Notifications/Inbox.d.ts +1 -1
- package/dist/components/Notifications/Notification.d.ts +1 -1
- package/dist/components/Notifications/NotificationFeed.d.ts +1 -1
- package/dist/components/Notifications/NotificationPopup.d.ts +1 -1
- package/dist/components/Notifications/UnreadBadge.d.ts +1 -1
- package/dist/components/Preferences/PreferenceInput.d.ts +4 -4
- package/dist/components/Preferences/PreferenceInput.js +2 -3
- package/dist/components/Preferences/Preferences.d.ts +1 -1
- package/dist/components/Provider/index.d.ts +3 -92
- package/dist/components/Provider/index.js +221 -197
- package/package.json +2 -1
- package/dist/api.d.ts +0 -1
- package/dist/api.js +0 -20
- package/dist/interface.d.ts +0 -49
- package/dist/interface.js +0 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { InboxHeaderProps } from './InboxHeader';
|
|
2
2
|
import { ImageShape } from './Notification';
|
|
3
3
|
import { NotificationPopupProps } from './NotificationPopup';
|
|
4
|
-
import { InAppNotification } from '
|
|
4
|
+
import { InAppNotification } from '@notificationapi/core/dist/interfaces';
|
|
5
5
|
|
|
6
6
|
export declare enum Pagination {
|
|
7
7
|
INFINITE_SCROLL = "infinite_scroll",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Pagination } from './Inbox';
|
|
2
2
|
import { ImageShape, NotificationProps } from './Notification';
|
|
3
3
|
import { Filter } from './NotificationPopup';
|
|
4
|
-
import { InAppNotification } from '../../interface';
|
|
5
4
|
import { InboxHeaderProps } from './InboxHeader';
|
|
5
|
+
import { InAppNotification } from '@notificationapi/core/dist/interfaces';
|
|
6
6
|
|
|
7
7
|
export type NotificationFeedProps = {
|
|
8
8
|
imageShape?: keyof typeof ImageShape;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Pagination } from './Inbox';
|
|
2
2
|
import { UnreadBadgeProps } from './UnreadBadge';
|
|
3
3
|
import { ImageShape, NotificationProps } from './Notification';
|
|
4
|
-
import { InAppNotification } from '
|
|
4
|
+
import { InAppNotification } from '@notificationapi/core/dist/interfaces';
|
|
5
5
|
import { InboxHeaderProps } from './InboxHeader';
|
|
6
6
|
|
|
7
7
|
export declare enum Filter {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
2
|
import { NotificationPopupProps } from './NotificationPopup';
|
|
3
|
-
import { InAppNotification } from '
|
|
3
|
+
import { InAppNotification } from '@notificationapi/core/dist/interfaces';
|
|
4
4
|
|
|
5
5
|
export type UnreadBadgeProps = {
|
|
6
6
|
color?: "blue" | "purple" | "cyan" | "green" | "magenta" | "pink" | "red" | "orange" | "yellow" | "volcano" | "geekblue" | "lime" | "gold" | undefined;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Channels,
|
|
1
|
+
import { BaseDeliveryOptions, Channels, DeliveryOptionsForEmail, DeliveryOptionsForInappWeb, GetPreferencesResponse } from '@notificationapi/core/dist/interfaces';
|
|
2
2
|
|
|
3
3
|
type Props = {
|
|
4
|
-
preferences:
|
|
5
|
-
notification:
|
|
6
|
-
updateDelivery: (notificationId: string, channel: Channels, delivery:
|
|
4
|
+
preferences: GetPreferencesResponse["preferences"];
|
|
5
|
+
notification: GetPreferencesResponse["notifications"][0];
|
|
6
|
+
updateDelivery: (notificationId: string, channel: Channels, delivery: DeliveryOptionsForEmail | DeliveryOptionsForInappWeb | BaseDeliveryOptions, subNotificationId?: string) => void;
|
|
7
7
|
subNotificationId?: string;
|
|
8
8
|
};
|
|
9
9
|
export declare const PreferenceInput: ({ notification, preferences, updateDelivery, subNotificationId, }: Props) => JSX.Element;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import "react/jsx-runtime";
|
|
2
|
-
import "
|
|
3
|
-
import { b as m } from "../../assets/Preferences.js";
|
|
2
|
+
import { b as t } from "../../assets/Preferences.js";
|
|
4
3
|
import "../../assets/index3.js";
|
|
5
4
|
export {
|
|
6
|
-
|
|
5
|
+
t as PreferenceInput
|
|
7
6
|
};
|
|
@@ -1,104 +1,15 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
|
-
import { InAppNotification } from '
|
|
2
|
+
import { GetPreferencesResponse, InAppNotification, BaseDeliveryOptions, Channels, DeliveryOptionsForEmail, DeliveryOptionsForInappWeb } from '@notificationapi/core/dist/interfaces';
|
|
3
3
|
|
|
4
|
-
export declare const NOTIFICATION_ACTIONS: {
|
|
5
|
-
opened: string;
|
|
6
|
-
clicked: string;
|
|
7
|
-
archived: string;
|
|
8
|
-
replied: string;
|
|
9
|
-
actioned1: string;
|
|
10
|
-
actioned2: string;
|
|
11
|
-
};
|
|
12
|
-
export declare enum Channels {
|
|
13
|
-
EMAIL = "EMAIL",
|
|
14
|
-
INAPP_WEB = "INAPP_WEB",
|
|
15
|
-
SMS = "SMS",
|
|
16
|
-
CALL = "CALL",
|
|
17
|
-
PUSH = "PUSH",
|
|
18
|
-
WEB_PUSH = "WEB_PUSH"
|
|
19
|
-
}
|
|
20
|
-
export declare enum DeliveryOptions {
|
|
21
|
-
OFF = "off",
|
|
22
|
-
INSTANT = "instant",
|
|
23
|
-
HOURLY = "hourly",
|
|
24
|
-
DAILY = "daily",
|
|
25
|
-
WEEKLY = "weekly",
|
|
26
|
-
MONTHLY = "monthly"
|
|
27
|
-
}
|
|
28
|
-
export interface NotificationConfig {
|
|
29
|
-
envId: string;
|
|
30
|
-
notificationId: string;
|
|
31
|
-
title: string;
|
|
32
|
-
channels: Channels[];
|
|
33
|
-
enabled: boolean;
|
|
34
|
-
deduplication?: {
|
|
35
|
-
duration: number;
|
|
36
|
-
};
|
|
37
|
-
throttling?: {
|
|
38
|
-
max: number;
|
|
39
|
-
period: number;
|
|
40
|
-
unit: "seconds" | "minutes" | "hours" | "days" | "months" | "years";
|
|
41
|
-
forever: boolean;
|
|
42
|
-
scope: ["userId", "notificationId"];
|
|
43
|
-
};
|
|
44
|
-
retention?: number;
|
|
45
|
-
options?: {
|
|
46
|
-
[key in Channels]?: {
|
|
47
|
-
defaultDeliveryOption: DeliveryOptions;
|
|
48
|
-
[DeliveryOptions.OFF]: {
|
|
49
|
-
enabled: boolean;
|
|
50
|
-
};
|
|
51
|
-
[DeliveryOptions.INSTANT]: {
|
|
52
|
-
enabled: boolean;
|
|
53
|
-
};
|
|
54
|
-
[DeliveryOptions.HOURLY]: {
|
|
55
|
-
enabled: boolean;
|
|
56
|
-
};
|
|
57
|
-
[DeliveryOptions.DAILY]: {
|
|
58
|
-
enabled: boolean;
|
|
59
|
-
hour: string;
|
|
60
|
-
};
|
|
61
|
-
[DeliveryOptions.WEEKLY]: {
|
|
62
|
-
enabled: boolean;
|
|
63
|
-
hour: string;
|
|
64
|
-
day: string;
|
|
65
|
-
};
|
|
66
|
-
[DeliveryOptions.MONTHLY]: {
|
|
67
|
-
enabled: boolean;
|
|
68
|
-
hour: string;
|
|
69
|
-
date: "first" | "last";
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
export interface Preferences {
|
|
75
|
-
preferences: {
|
|
76
|
-
notificationId: string;
|
|
77
|
-
channel: Channels;
|
|
78
|
-
delivery: DeliveryOptions;
|
|
79
|
-
subNotificationId?: string;
|
|
80
|
-
}[];
|
|
81
|
-
notifications: {
|
|
82
|
-
notificationId: string;
|
|
83
|
-
title: string;
|
|
84
|
-
channels: Channels[];
|
|
85
|
-
options: NotificationConfig["options"];
|
|
86
|
-
}[];
|
|
87
|
-
subNotifications: {
|
|
88
|
-
notificationId: string;
|
|
89
|
-
subNotificationId: string;
|
|
90
|
-
title: string;
|
|
91
|
-
}[];
|
|
92
|
-
}
|
|
93
4
|
export type Context = {
|
|
94
5
|
notifications?: InAppNotification[];
|
|
95
|
-
preferences?:
|
|
6
|
+
preferences?: GetPreferencesResponse;
|
|
96
7
|
loadNotifications: (initial?: boolean) => void;
|
|
97
8
|
markAsOpened: () => void;
|
|
98
9
|
markAsArchived: (ids: string[] | "ALL") => void;
|
|
99
10
|
markAsUnarchived: (ids: string[] | "ALL") => void;
|
|
100
11
|
markAsClicked: (ids: string[]) => void;
|
|
101
|
-
updateDelivery: (notificationId: string, channel: Channels, delivery:
|
|
12
|
+
updateDelivery: (notificationId: string, channel: Channels, delivery: DeliveryOptionsForEmail | DeliveryOptionsForInappWeb | BaseDeliveryOptions, subNotificationId?: string) => void;
|
|
102
13
|
};
|
|
103
14
|
export declare const NotificationAPIContext: import('react').Context<Context | undefined>;
|
|
104
15
|
type Props = {
|
|
@@ -1,19 +1,140 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as $, useState as
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { jsx as M } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as $, useState as N, useEffect as E, useContext as U } from "react";
|
|
3
|
+
const j = async (e, o, d, r, f, g, l) => {
|
|
4
|
+
const h = T(r, f, g), u = await fetch(
|
|
5
|
+
`https://${o}/${r}/users/${encodeURIComponent(
|
|
6
|
+
f
|
|
7
|
+
)}/${d}`,
|
|
8
|
+
{
|
|
9
|
+
method: e,
|
|
10
|
+
body: JSON.stringify(l),
|
|
11
|
+
headers: {
|
|
12
|
+
Authorization: `Basic ${h}`
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
);
|
|
16
|
+
try {
|
|
17
|
+
return await u.json();
|
|
18
|
+
} catch {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
}, T = (e, o, d) => btoa(d ? e + ":" + o + ":" + d : e + ":" + o), D = {
|
|
22
|
+
host: "api.notificationapi.com",
|
|
23
|
+
websocketHost: "ws.notificationapi.com",
|
|
24
|
+
userId: "",
|
|
25
|
+
clientId: "",
|
|
26
|
+
hashedUserId: "",
|
|
27
|
+
getInAppDefaultCount: 100,
|
|
28
|
+
getInAppDefaultOldest: new Date(
|
|
29
|
+
Date.now() - 2592e6
|
|
30
|
+
).toISOString(),
|
|
31
|
+
onNewInAppNotifications: void 0,
|
|
32
|
+
keepWebSocketAliveForSeconds: 86400
|
|
33
|
+
// 24 hours
|
|
34
|
+
}, n = {
|
|
35
|
+
config: D,
|
|
36
|
+
init: function(e) {
|
|
37
|
+
return this.config = { ...D, ...e }, {
|
|
38
|
+
...this
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
rest: {
|
|
42
|
+
generic: function(e, o, d) {
|
|
43
|
+
return j(
|
|
44
|
+
e,
|
|
45
|
+
n.config.host,
|
|
46
|
+
o,
|
|
47
|
+
n.config.clientId,
|
|
48
|
+
n.config.userId,
|
|
49
|
+
n.config.hashedUserId,
|
|
50
|
+
d
|
|
51
|
+
);
|
|
52
|
+
},
|
|
53
|
+
getNotifications: function(e, o) {
|
|
54
|
+
return n.rest.generic(
|
|
55
|
+
"GET",
|
|
56
|
+
`notifications/INAPP_WEB?count=${o}&before=${e}`
|
|
57
|
+
);
|
|
58
|
+
},
|
|
59
|
+
patchNotifications: function(e) {
|
|
60
|
+
return n.rest.generic(
|
|
61
|
+
"PATCH",
|
|
62
|
+
"notifications/INAPP_WEB",
|
|
63
|
+
e
|
|
64
|
+
);
|
|
65
|
+
},
|
|
66
|
+
getPreferences: function() {
|
|
67
|
+
return n.rest.generic("GET", "preferences");
|
|
68
|
+
},
|
|
69
|
+
postPreferences: function(e) {
|
|
70
|
+
return n.rest.generic(
|
|
71
|
+
"POST",
|
|
72
|
+
"preferences",
|
|
73
|
+
e
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
websocket: {
|
|
78
|
+
object: void 0,
|
|
79
|
+
connect: function() {
|
|
80
|
+
let e = `wss://${n.config.websocketHost}?userId=${n.config.userId}&envId=${n.config.clientId}`;
|
|
81
|
+
return n.config.hashedUserId && (e += `&userIdHash=${n.config.hashedUserId}`), n.websocket.object = new WebSocket(e), n.websocket.object.onmessage = (o) => {
|
|
82
|
+
const d = JSON.parse(o.data);
|
|
83
|
+
if (!(!d || !d.route) && d.route === "inapp_web/new_notifications") {
|
|
84
|
+
const r = d;
|
|
85
|
+
n.config.onNewInAppNotifications && n.config.onNewInAppNotifications(
|
|
86
|
+
r.payload.notifications
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
}, n.websocket.object;
|
|
90
|
+
},
|
|
91
|
+
disconnect: function(e) {
|
|
92
|
+
var o;
|
|
93
|
+
n.websocket.object && ((o = n.websocket.object) == null || o.close(), e && e(n.websocket.object));
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
openWebSocket: function() {
|
|
97
|
+
return n.websocket.connect(() => {
|
|
98
|
+
setTimeout(() => {
|
|
99
|
+
this.websocket.disconnect(() => {
|
|
100
|
+
this.websocket.connect();
|
|
101
|
+
});
|
|
102
|
+
}, 54e4);
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
getInAppNotifications: async (e) => {
|
|
106
|
+
const o = e.maxCountNeeded || n.config.getInAppDefaultCount, d = e.oldestNeeded || n.config.getInAppDefaultOldest;
|
|
107
|
+
let r = [], f = e.before, g = !0, l = !0;
|
|
108
|
+
for (; l; ) {
|
|
109
|
+
const h = (await n.rest.getNotifications(
|
|
110
|
+
f,
|
|
111
|
+
o
|
|
112
|
+
)).notifications.filter(
|
|
113
|
+
(u) => !r.find((w) => w.id === u.id)
|
|
114
|
+
);
|
|
115
|
+
f = h.reduce(
|
|
116
|
+
(u, w) => u < w.date ? u : w.date,
|
|
117
|
+
e.before
|
|
118
|
+
), r = [...r, ...h], g = h.length > 0, l = !0, (!g || r.length >= o || f < d) && (l = !1);
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
items: r,
|
|
122
|
+
hasMore: g,
|
|
123
|
+
oldestReceived: f
|
|
124
|
+
};
|
|
125
|
+
},
|
|
126
|
+
updateInAppNotifications: async (e) => {
|
|
127
|
+
const o = {
|
|
128
|
+
trackingIds: e.ids
|
|
129
|
+
};
|
|
130
|
+
return e.archived === !0 ? o.archived = (/* @__PURE__ */ new Date()).toISOString() : e.archived === !1 && (o.archived = null), e.clicked === !0 ? o.clicked = (/* @__PURE__ */ new Date()).toISOString() : e.clicked === !1 && (o.clicked = null), e.opened === !0 ? o.opened = (/* @__PURE__ */ new Date()).toISOString() : e.opened === !1 && (o.opened = null), n.rest.patchNotifications(o);
|
|
131
|
+
},
|
|
132
|
+
getPreferences: async () => n.rest.getPreferences(),
|
|
133
|
+
updateDeliveryOption: async (e) => n.rest.postPreferences([e])
|
|
134
|
+
}, m = $(
|
|
14
135
|
void 0
|
|
15
|
-
),
|
|
16
|
-
const
|
|
136
|
+
), W = (e) => {
|
|
137
|
+
const d = {
|
|
17
138
|
...{
|
|
18
139
|
apiURL: "https://api.notificationapi.com",
|
|
19
140
|
wsURL: "wss://ws.notificationapi.com",
|
|
@@ -21,215 +142,118 @@ const E = $(
|
|
|
21
142
|
initialLoadMaxAge: new Date((/* @__PURE__ */ new Date()).setMonth((/* @__PURE__ */ new Date()).getMonth() - 3))
|
|
22
143
|
},
|
|
23
144
|
...e
|
|
24
|
-
}, [
|
|
25
|
-
const
|
|
26
|
-
f((
|
|
27
|
-
...
|
|
28
|
-
...
|
|
29
|
-
] :
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
e.hashedUserId
|
|
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
|
-
)).filter(
|
|
44
|
-
(l) => !i.find((I) => I.id === l.id)
|
|
45
|
-
);
|
|
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);
|
|
145
|
+
}, [r, f] = N(), [g, l] = N(), [h, u] = N(!1), [w, S] = N((/* @__PURE__ */ new Date()).toISOString()), [v, b] = N(!0), A = (c) => {
|
|
146
|
+
const s = (/* @__PURE__ */ new Date()).toISOString();
|
|
147
|
+
f((i) => (c = c.filter((t) => !(t.expDate && new Date(t.expDate * 1e3).toISOString() > s || t.date > s)), i ? [
|
|
148
|
+
...c.filter((t) => !i.find((a) => a.id === t.id)),
|
|
149
|
+
...i
|
|
150
|
+
] : c));
|
|
151
|
+
}, p = n.init({
|
|
152
|
+
clientId: e.clientId,
|
|
153
|
+
userId: e.userId,
|
|
154
|
+
hashedUserId: e.hashedUserId,
|
|
155
|
+
onNewInAppNotifications: (c) => {
|
|
156
|
+
A(c);
|
|
50
157
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
couldLoadMore: r,
|
|
54
|
-
oldestReceived: a
|
|
55
|
-
};
|
|
56
|
-
}, U = async (t) => {
|
|
57
|
-
if (!t && !T || !t && k)
|
|
158
|
+
}), k = async (c) => {
|
|
159
|
+
if (!c && !v || !c && h)
|
|
58
160
|
return;
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
t ? c.initialLoadMaxAge.toISOString() : void 0
|
|
161
|
+
u(!0);
|
|
162
|
+
const s = await p.rest.getNotifications(
|
|
163
|
+
c ? (/* @__PURE__ */ new Date()).toISOString() : w,
|
|
164
|
+
c ? d.initialLoadMaxCount : 1e3
|
|
64
165
|
);
|
|
65
|
-
|
|
66
|
-
},
|
|
67
|
-
if (!
|
|
166
|
+
S(s.oldestReceived), b(s.couldLoadMore), A(s.notifications), u(!1);
|
|
167
|
+
}, O = async (c) => {
|
|
168
|
+
if (!r)
|
|
68
169
|
return;
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
"PATCH",
|
|
73
|
-
"notifications/INAPP_WEB",
|
|
74
|
-
e.clientId,
|
|
75
|
-
e.userId,
|
|
76
|
-
e.hashedUserId,
|
|
77
|
-
{
|
|
78
|
-
trackingIds: n,
|
|
79
|
-
clicked: o
|
|
80
|
-
}
|
|
81
|
-
), f((i) => {
|
|
82
|
-
if (!i)
|
|
170
|
+
const s = (/* @__PURE__ */ new Date()).toISOString(), i = r.filter((t) => c.includes(t.id) && !t.clicked).map((t) => t.id);
|
|
171
|
+
p.updateInAppNotifications({ ids: i, clicked: !0 }), f((t) => {
|
|
172
|
+
if (!t)
|
|
83
173
|
return [];
|
|
84
|
-
const a = [...
|
|
85
|
-
return a.filter((
|
|
86
|
-
|
|
174
|
+
const a = [...t];
|
|
175
|
+
return a.filter((I) => i.includes(I.id)).forEach((I) => {
|
|
176
|
+
I.clicked = s;
|
|
87
177
|
}), a;
|
|
88
178
|
});
|
|
89
|
-
},
|
|
90
|
-
if (!
|
|
179
|
+
}, P = async () => {
|
|
180
|
+
if (!r)
|
|
91
181
|
return;
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
e.userId,
|
|
99
|
-
e.hashedUserId,
|
|
100
|
-
{
|
|
101
|
-
trackingIds: o,
|
|
102
|
-
opened: t
|
|
103
|
-
}
|
|
104
|
-
), f((n) => {
|
|
105
|
-
if (!n)
|
|
182
|
+
const c = (/* @__PURE__ */ new Date()).toISOString(), s = r.filter((i) => !i.opened || !i.seen).map((i) => i.id);
|
|
183
|
+
s.length !== 0 && (p.updateInAppNotifications({
|
|
184
|
+
ids: s,
|
|
185
|
+
opened: !0
|
|
186
|
+
}), f((i) => {
|
|
187
|
+
if (!i)
|
|
106
188
|
return [];
|
|
107
|
-
const
|
|
108
|
-
return
|
|
109
|
-
a.opened =
|
|
110
|
-
}),
|
|
189
|
+
const t = [...i];
|
|
190
|
+
return t.filter((a) => s.includes(a.id)).forEach((a) => {
|
|
191
|
+
a.opened = c, a.seen = !0;
|
|
192
|
+
}), t;
|
|
111
193
|
}));
|
|
112
|
-
},
|
|
113
|
-
if (!
|
|
194
|
+
}, y = async (c) => {
|
|
195
|
+
if (!r)
|
|
114
196
|
return;
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
e.userId,
|
|
122
|
-
e.hashedUserId,
|
|
123
|
-
{
|
|
124
|
-
trackingIds: o,
|
|
125
|
-
archived: null
|
|
126
|
-
}
|
|
127
|
-
), f((n) => {
|
|
128
|
-
if (!n)
|
|
197
|
+
const s = r.filter((i) => i.archived && (c === "ALL" || c.includes(i.id))).map((i) => i.id);
|
|
198
|
+
s.length !== 0 && (p.updateInAppNotifications({
|
|
199
|
+
ids: s,
|
|
200
|
+
archived: !1
|
|
201
|
+
}), f((i) => {
|
|
202
|
+
if (!i)
|
|
129
203
|
return [];
|
|
130
|
-
const
|
|
131
|
-
return
|
|
204
|
+
const t = [...i];
|
|
205
|
+
return t.filter((a) => s.includes(a.id)).forEach((a) => {
|
|
132
206
|
a.archived = void 0;
|
|
133
|
-
}),
|
|
207
|
+
}), t;
|
|
134
208
|
}));
|
|
135
|
-
},
|
|
136
|
-
if (!
|
|
209
|
+
}, C = async (c) => {
|
|
210
|
+
if (!r)
|
|
137
211
|
return;
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
"PATCH",
|
|
142
|
-
"notifications/INAPP_WEB",
|
|
143
|
-
e.clientId,
|
|
144
|
-
e.userId,
|
|
145
|
-
e.hashedUserId,
|
|
146
|
-
{
|
|
147
|
-
trackingIds: n,
|
|
148
|
-
archived: o
|
|
149
|
-
}
|
|
150
|
-
), f((i) => {
|
|
151
|
-
if (!i)
|
|
212
|
+
const s = (/* @__PURE__ */ new Date()).toISOString(), i = r.filter((t) => !t.archived && (c === "ALL" || c.includes(t.id))).map((t) => t.id);
|
|
213
|
+
i.length !== 0 && (p.updateInAppNotifications({ ids: i, archived: !0 }), f((t) => {
|
|
214
|
+
if (!t)
|
|
152
215
|
return [];
|
|
153
|
-
const a = [...
|
|
154
|
-
return a.filter((
|
|
155
|
-
|
|
216
|
+
const a = [...t];
|
|
217
|
+
return a.filter((I) => i.includes(I.id)).forEach((I) => {
|
|
218
|
+
I.archived = s;
|
|
156
219
|
}), a;
|
|
157
220
|
}));
|
|
158
|
-
},
|
|
159
|
-
|
|
160
|
-
c
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
{
|
|
168
|
-
notificationId: t,
|
|
169
|
-
subNotificationId: i,
|
|
170
|
-
channel: o,
|
|
171
|
-
delivery: n
|
|
172
|
-
}
|
|
173
|
-
]
|
|
174
|
-
).then(() => {
|
|
175
|
-
d(
|
|
176
|
-
c.apiURL,
|
|
177
|
-
"GET",
|
|
178
|
-
"preferences",
|
|
179
|
-
e.clientId,
|
|
180
|
-
e.userId,
|
|
181
|
-
e.hashedUserId
|
|
182
|
-
).then((a) => {
|
|
183
|
-
h(a);
|
|
221
|
+
}, x = (c, s, i, t) => {
|
|
222
|
+
p.updateDeliveryOption({
|
|
223
|
+
notificationId: c,
|
|
224
|
+
channel: s,
|
|
225
|
+
delivery: i,
|
|
226
|
+
subNotificationId: t
|
|
227
|
+
}).then(() => {
|
|
228
|
+
p.getPreferences().then((a) => {
|
|
229
|
+
l(a);
|
|
184
230
|
});
|
|
185
231
|
});
|
|
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(
|
|
195
|
-
c.hashedUserId ? `${c.wsURL}?userId=${c.userId}&envId=${c.clientId}&userIdHash=${c.hashedUserId}` : `${c.wsURL}?userId=${c.userId}&envId=${c.clientId}`
|
|
196
|
-
);
|
|
197
|
-
t.onopen = () => _(t), t.onmessage = W;
|
|
198
232
|
};
|
|
199
|
-
|
|
200
|
-
f([]),
|
|
201
|
-
c
|
|
202
|
-
"GET",
|
|
203
|
-
"preferences",
|
|
204
|
-
e.clientId,
|
|
205
|
-
e.userId,
|
|
206
|
-
e.hashedUserId
|
|
207
|
-
).then((t) => {
|
|
208
|
-
h(t);
|
|
233
|
+
E(() => {
|
|
234
|
+
f([]), u(!1), l(void 0), S((/* @__PURE__ */ new Date()).toISOString()), b(!0), k(!0), p.openWebSocket(), p.getPreferences().then((c) => {
|
|
235
|
+
l(c);
|
|
209
236
|
});
|
|
210
237
|
}, [e]);
|
|
211
|
-
const
|
|
212
|
-
notifications:
|
|
213
|
-
preferences:
|
|
214
|
-
loadNotifications:
|
|
215
|
-
markAsOpened:
|
|
216
|
-
markAsArchived:
|
|
217
|
-
markAsUnarchived:
|
|
218
|
-
markAsClicked:
|
|
219
|
-
updateDelivery:
|
|
238
|
+
const L = {
|
|
239
|
+
notifications: r,
|
|
240
|
+
preferences: g,
|
|
241
|
+
loadNotifications: k,
|
|
242
|
+
markAsOpened: P,
|
|
243
|
+
markAsArchived: C,
|
|
244
|
+
markAsUnarchived: y,
|
|
245
|
+
markAsClicked: O,
|
|
246
|
+
updateDelivery: x
|
|
220
247
|
};
|
|
221
|
-
return /* @__PURE__ */
|
|
222
|
-
},
|
|
223
|
-
const e =
|
|
248
|
+
return /* @__PURE__ */ M(m.Provider, { value: L, children: e.children });
|
|
249
|
+
}, H = () => {
|
|
250
|
+
const e = U(m);
|
|
224
251
|
if (!e)
|
|
225
252
|
throw new Error("useMyContext must be used within a MyProvider");
|
|
226
253
|
return e;
|
|
227
254
|
};
|
|
228
|
-
|
|
255
|
+
W.useNotificationAPIContext = H;
|
|
229
256
|
export {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
X as NOTIFICATION_ACTIONS,
|
|
233
|
-
E as NotificationAPIContext,
|
|
234
|
-
j as NotificationAPIProvider
|
|
257
|
+
m as NotificationAPIContext,
|
|
258
|
+
W as NotificationAPIProvider
|
|
235
259
|
};
|
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.22",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "vite",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"**/*.css"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
+
"@notificationapi/core": "^0.0.7",
|
|
43
44
|
"antd": "^5.17.4",
|
|
44
45
|
"javascript-time-ago": "^2.5.10",
|
|
45
46
|
"liquidjs": "^10.14.0",
|
package/dist/api.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const api: (endpoint: string, method: "GET" | "POST" | "PATCH", resource: string, clientId: string, userId: string, hashedUserId?: string, data?: any) => Promise<any>;
|