@notificationapi/react 0.0.8 → 0.0.9
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.
|
@@ -12,8 +12,8 @@ const j = {
|
|
|
12
12
|
var C = /* @__PURE__ */ ((t) => (t.EMAIL = "EMAIL", t.INAPP_WEB = "INAPP_WEB", t.SMS = "SMS", t.CALL = "CALL", t.PUSH = "PUSH", t.WEB_PUSH = "WEB_PUSH", t))(C || {}), x = /* @__PURE__ */ ((t) => (t.OFF = "off", t.INSTANT = "instant", t.HOURLY = "hourly", t.DAILY = "daily", t.WEEKLY = "weekly", t.MONTHLY = "monthly", t))(x || {});
|
|
13
13
|
const D = O(
|
|
14
14
|
void 0
|
|
15
|
-
),
|
|
16
|
-
const
|
|
15
|
+
), J = (t) => {
|
|
16
|
+
const s = {
|
|
17
17
|
...{
|
|
18
18
|
apiURL: "https://api.notificationapi.com",
|
|
19
19
|
wsURL: "wss://ws.notificationapi.com",
|
|
@@ -21,55 +21,56 @@ const D = O(
|
|
|
21
21
|
initialLoadMaxAge: new Date((/* @__PURE__ */ new Date()).setMonth((/* @__PURE__ */ new Date()).getMonth() - 3))
|
|
22
22
|
},
|
|
23
23
|
...t
|
|
24
|
-
}, [d, l] = f(), [
|
|
24
|
+
}, [d, l] = f(), [L, A] = f(), [S, w] = f(!1), [U, E] = f((/* @__PURE__ */ new Date()).toISOString()), [m, M] = f(!0), P = (o) => {
|
|
25
25
|
l((e) => e ? [
|
|
26
26
|
...o.filter((i) => !e.find((n) => n.id === i.id)),
|
|
27
27
|
...e
|
|
28
28
|
] : o);
|
|
29
|
-
},
|
|
30
|
-
|
|
29
|
+
}, k = async (o, e) => (await u(
|
|
30
|
+
s.apiURL,
|
|
31
31
|
"GET",
|
|
32
32
|
`notifications/INAPP_WEB?count=${o}&before=${e}`,
|
|
33
33
|
t.clientId,
|
|
34
|
-
t.userId
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
t.userId,
|
|
35
|
+
t.hashedUserId
|
|
36
|
+
)).notifications, T = async (o, e, i) => {
|
|
37
|
+
let n = [], a = o, c = !0, r = !0;
|
|
38
|
+
for (; r; ) {
|
|
39
|
+
const g = (await k(
|
|
39
40
|
e,
|
|
40
|
-
new Date(
|
|
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], c = g.length > 0, r = !0, (!c || n.length >= e || i && a < i) && (r = !1);
|
|
48
49
|
}
|
|
49
|
-
return console.log(n.length,
|
|
50
|
+
return console.log(n.length, c, a), {
|
|
50
51
|
notifications: n,
|
|
51
|
-
couldLoadMore:
|
|
52
|
-
oldestReceived:
|
|
52
|
+
couldLoadMore: c,
|
|
53
|
+
oldestReceived: a
|
|
53
54
|
};
|
|
54
|
-
},
|
|
55
|
-
if (!
|
|
55
|
+
}, N = async (o) => {
|
|
56
|
+
if (!m || S)
|
|
56
57
|
return;
|
|
57
|
-
|
|
58
|
-
const e = await
|
|
59
|
-
|
|
60
|
-
o ?
|
|
61
|
-
o ?
|
|
58
|
+
w(!0);
|
|
59
|
+
const e = await T(
|
|
60
|
+
U,
|
|
61
|
+
o ? s.initialLoadMaxCount : 1e3,
|
|
62
|
+
o ? s.initialLoadMaxAge.toISOString() : void 0
|
|
62
63
|
);
|
|
63
|
-
|
|
64
|
+
E(e.oldestReceived), M(e.couldLoadMore), P(e.notifications), w(!1);
|
|
64
65
|
}, R = async (o) => {
|
|
65
66
|
const e = (/* @__PURE__ */ new Date()).toISOString();
|
|
66
67
|
u(
|
|
67
|
-
|
|
68
|
+
s.apiURL,
|
|
68
69
|
"PATCH",
|
|
69
70
|
"notifications/INAPP_WEB",
|
|
70
71
|
t.clientId,
|
|
71
72
|
t.userId,
|
|
72
|
-
|
|
73
|
+
t.hashedUserId,
|
|
73
74
|
{
|
|
74
75
|
trackingIds: [o],
|
|
75
76
|
clicked: e
|
|
@@ -77,20 +78,20 @@ const D = O(
|
|
|
77
78
|
), l((i) => {
|
|
78
79
|
if (!i)
|
|
79
80
|
return [];
|
|
80
|
-
const n = [...i],
|
|
81
|
-
return
|
|
81
|
+
const n = [...i], a = n.find((c) => c.id === o);
|
|
82
|
+
return a && (a.clicked = e), n;
|
|
82
83
|
});
|
|
83
84
|
}, W = async () => {
|
|
84
85
|
if (!d)
|
|
85
86
|
return;
|
|
86
87
|
const o = (/* @__PURE__ */ new Date()).toISOString(), e = d.filter((i) => !i.opened || !i.seen).map((i) => i.id);
|
|
87
88
|
e.length !== 0 && (u(
|
|
88
|
-
|
|
89
|
+
s.apiURL,
|
|
89
90
|
"PATCH",
|
|
90
91
|
"notifications/INAPP_WEB",
|
|
91
92
|
t.clientId,
|
|
92
93
|
t.userId,
|
|
93
|
-
|
|
94
|
+
t.hashedUserId,
|
|
94
95
|
{
|
|
95
96
|
trackingIds: e,
|
|
96
97
|
opened: o
|
|
@@ -99,8 +100,8 @@ const D = O(
|
|
|
99
100
|
if (!i)
|
|
100
101
|
return [];
|
|
101
102
|
const n = [...i];
|
|
102
|
-
return n.filter((
|
|
103
|
-
|
|
103
|
+
return n.filter((a) => e.includes(a.id)).forEach((a) => {
|
|
104
|
+
a.opened = o, a.seen = !0;
|
|
104
105
|
}), n;
|
|
105
106
|
}));
|
|
106
107
|
}, _ = async (o) => {
|
|
@@ -108,12 +109,12 @@ const D = O(
|
|
|
108
109
|
return;
|
|
109
110
|
const e = (/* @__PURE__ */ new Date()).toISOString(), i = d.filter((n) => !n.archived && (o === "ALL" || o.includes(n.id))).map((n) => n.id);
|
|
110
111
|
i.length !== 0 && (u(
|
|
111
|
-
|
|
112
|
+
s.apiURL,
|
|
112
113
|
"PATCH",
|
|
113
114
|
"notifications/INAPP_WEB",
|
|
114
115
|
t.clientId,
|
|
115
116
|
t.userId,
|
|
116
|
-
|
|
117
|
+
t.hashedUserId,
|
|
117
118
|
{
|
|
118
119
|
trackingIds: i,
|
|
119
120
|
archived: e
|
|
@@ -121,37 +122,42 @@ const D = O(
|
|
|
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((c) => i.includes(c.id)).forEach((c) => {
|
|
127
|
+
c.archived = e;
|
|
128
|
+
}), a;
|
|
128
129
|
}));
|
|
129
130
|
}, H = (o, e, i, n) => {
|
|
130
|
-
if (!
|
|
131
|
+
if (!L)
|
|
131
132
|
return;
|
|
132
|
-
const
|
|
133
|
-
(
|
|
133
|
+
const a = { ...L }, c = a.preferences.find(
|
|
134
|
+
(r) => r.notificationId === o && r.subNotificationId === n && r.channel === e
|
|
134
135
|
);
|
|
135
|
-
|
|
136
|
+
c && (c.delivery = i), A(a);
|
|
136
137
|
};
|
|
137
138
|
v(() => {
|
|
138
|
-
|
|
139
|
+
N(!0);
|
|
139
140
|
const o = new WebSocket(
|
|
140
|
-
`${
|
|
141
|
+
`${s.wsURL}?userId=${s.userId}&envId=${s.clientId}`
|
|
141
142
|
);
|
|
142
143
|
o.onmessage = (e) => {
|
|
143
144
|
const i = JSON.parse(e.data);
|
|
144
|
-
!i || !i.route || i.route === "inapp_web/new_notifications" &&
|
|
145
|
-
}, u(
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
145
|
+
!i || !i.route || i.route === "inapp_web/new_notifications" && P(i.payload.notifications);
|
|
146
|
+
}, u(
|
|
147
|
+
s.apiURL,
|
|
148
|
+
"GET",
|
|
149
|
+
"preferences",
|
|
150
|
+
t.clientId,
|
|
151
|
+
t.userId,
|
|
152
|
+
t.hashedUserId
|
|
153
|
+
).then((e) => {
|
|
154
|
+
A(e);
|
|
155
|
+
});
|
|
150
156
|
}, []);
|
|
151
157
|
const y = {
|
|
152
158
|
notifications: d,
|
|
153
|
-
preferences:
|
|
154
|
-
loadNotifications:
|
|
159
|
+
preferences: L,
|
|
160
|
+
loadNotifications: N,
|
|
155
161
|
markAsOpened: W,
|
|
156
162
|
markAsArchived: _,
|
|
157
163
|
markAsClicked: R,
|
|
@@ -164,5 +170,5 @@ export {
|
|
|
164
170
|
x as DeliveryOptions,
|
|
165
171
|
j as NOTIFICATION_ACTIONS,
|
|
166
172
|
D as NotificationAPIContext,
|
|
167
|
-
|
|
173
|
+
J as NotificationAPIProvider
|
|
168
174
|
};
|