@edusight/notification-widget 1.0.40 → 1.0.41
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-DqQ0ehzG.js → components-CWbjrQKA.js} +129 -137
- package/dist/{components-DqQ0ehzG.js.map → components-CWbjrQKA.js.map} +1 -1
- package/dist/{components-D9Q1H53S.cjs → components-Cr9Sf7Cz.cjs} +9 -9
- package/dist/{components-D9Q1H53S.cjs.map → components-Cr9Sf7Cz.cjs.map} +1 -1
- package/dist/hooks-C6Z38jT_.cjs +2 -0
- package/dist/hooks-C6Z38jT_.cjs.map +1 -0
- package/dist/{hooks-C7dzVxIU.js → hooks-S0z2_-4B.js} +63 -50
- package/dist/hooks-S0z2_-4B.js.map +1 -0
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.esm.js +177 -156
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/dist/hooks-C7dzVxIU.js.map +0 -1
- package/dist/hooks-kLhwdW29.cjs +0 -2
- package/dist/hooks-kLhwdW29.cjs.map +0 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,29 +1,39 @@
|
|
|
1
|
-
import { jsx as
|
|
1
|
+
import { jsx as u, jsxs as A } from "react/jsx-runtime";
|
|
2
2
|
import { NotificationClient as $ } from "@edusight/notification-sdk";
|
|
3
|
-
import F, { useState as
|
|
3
|
+
import F, { useState as v, useCallback as T, useEffect as k, Component as j, createContext as J, useReducer as G, useRef as Q, useContext as X } from "react";
|
|
4
4
|
import { io as Y } from "socket.io-client";
|
|
5
|
-
import { u as Z, c as K } from "./hooks-
|
|
6
|
-
import { M as ee, a as te, C as x, B as P, S as ne, I as re, L as ie } from "./components-
|
|
7
|
-
import { N as
|
|
5
|
+
import { u as Z, c as K } from "./hooks-S0z2_-4B.js";
|
|
6
|
+
import { M as ee, a as te, C as x, B as P, S as ne, I as re, L as ie } from "./components-CWbjrQKA.js";
|
|
7
|
+
import { N as Ce, P as ve } from "./components-CWbjrQKA.js";
|
|
8
8
|
const oe = () => window.__notificationSDK?.client, ae = ({
|
|
9
9
|
onPreferencesLoaded: t,
|
|
10
10
|
onError: n
|
|
11
11
|
}) => {
|
|
12
|
-
const f = oe(), [
|
|
12
|
+
const f = oe(), [h, a] = v(!0), [l, s] = v(null), [r, d] = v(null), m = T(async () => {
|
|
13
13
|
try {
|
|
14
14
|
if (a(!0), s(null), !f)
|
|
15
15
|
throw new Error("Notification client not available");
|
|
16
16
|
const p = window.__notificationSDK?.config;
|
|
17
17
|
if (!p)
|
|
18
18
|
throw new Error("SDK configuration not available");
|
|
19
|
-
const { subscriberId:
|
|
20
|
-
if (!
|
|
19
|
+
const { subscriberId: E, tenantId: I, environmentId: b } = p;
|
|
20
|
+
if (!E || !I || !b)
|
|
21
21
|
throw new Error("SubscriberId, TenantId or EnvironmentId not available in config");
|
|
22
22
|
const w = await f.preferences.get(
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
I,
|
|
24
|
+
E,
|
|
25
25
|
b
|
|
26
|
-
)
|
|
26
|
+
);
|
|
27
|
+
let c = null;
|
|
28
|
+
try {
|
|
29
|
+
c = await f.preferences.getSchedule(
|
|
30
|
+
I,
|
|
31
|
+
E,
|
|
32
|
+
b
|
|
33
|
+
);
|
|
34
|
+
} catch {
|
|
35
|
+
}
|
|
36
|
+
const N = {
|
|
27
37
|
channels: {
|
|
28
38
|
email: w.emailEnabled ?? !0,
|
|
29
39
|
push: w.pushEnabled ?? !0,
|
|
@@ -32,30 +42,40 @@ const oe = () => window.__notificationSDK?.client, ae = ({
|
|
|
32
42
|
},
|
|
33
43
|
subscriptions: [],
|
|
34
44
|
deliverySchedule: {
|
|
45
|
+
enabled: c?.isEnabled || !1,
|
|
35
46
|
timezone: "UTC",
|
|
36
47
|
quietHours: {
|
|
37
48
|
start: w.quietHoursStart ?? "22:00",
|
|
38
49
|
end: w.quietHoursEnd ?? "08:00"
|
|
39
50
|
},
|
|
40
|
-
weekdays:
|
|
51
|
+
weekdays: c?.weeklySchedule ? [
|
|
52
|
+
!!c.weeklySchedule.monday,
|
|
53
|
+
!!c.weeklySchedule.tuesday,
|
|
54
|
+
!!c.weeklySchedule.wednesday,
|
|
55
|
+
!!c.weeklySchedule.thursday,
|
|
56
|
+
!!c.weeklySchedule.friday,
|
|
57
|
+
!!c.weeklySchedule.saturday,
|
|
58
|
+
!!c.weeklySchedule.sunday
|
|
59
|
+
] : [!0, !0, !0, !0, !0, !1, !1],
|
|
60
|
+
weeklySchedule: c?.weeklySchedule || void 0
|
|
41
61
|
}
|
|
42
62
|
};
|
|
43
|
-
w.categories && Object.entries(w.categories).forEach(([
|
|
44
|
-
|
|
45
|
-
workflowId:
|
|
46
|
-
name:
|
|
63
|
+
w.categories && Object.entries(w.categories).forEach(([C, _]) => {
|
|
64
|
+
N.subscriptions.push({
|
|
65
|
+
workflowId: C,
|
|
66
|
+
name: C,
|
|
47
67
|
enabled: !0,
|
|
48
68
|
channels: {
|
|
49
|
-
email:
|
|
50
|
-
push:
|
|
51
|
-
sms:
|
|
52
|
-
inApp:
|
|
69
|
+
email: _.emailEnabled ?? !0,
|
|
70
|
+
push: _.pushEnabled ?? !0,
|
|
71
|
+
sms: _.smsEnabled ?? !1,
|
|
72
|
+
inApp: _.inAppEnabled ?? !0
|
|
53
73
|
}
|
|
54
74
|
});
|
|
55
|
-
}),
|
|
75
|
+
}), d(N), t(N);
|
|
56
76
|
} catch (p) {
|
|
57
|
-
const
|
|
58
|
-
p?.response?.status === 404 || p?.status === 404 || (s(
|
|
77
|
+
const E = p instanceof Error ? p : new Error("Failed to load preferences");
|
|
78
|
+
p?.response?.status === 404 || p?.status === 404 || (s(E), n?.(E));
|
|
59
79
|
const b = {
|
|
60
80
|
channels: {
|
|
61
81
|
email: !0,
|
|
@@ -65,6 +85,7 @@ const oe = () => window.__notificationSDK?.client, ae = ({
|
|
|
65
85
|
},
|
|
66
86
|
subscriptions: [],
|
|
67
87
|
deliverySchedule: {
|
|
88
|
+
enabled: !1,
|
|
68
89
|
timezone: "UTC",
|
|
69
90
|
quietHours: {
|
|
70
91
|
start: "22:00",
|
|
@@ -73,83 +94,83 @@ const oe = () => window.__notificationSDK?.client, ae = ({
|
|
|
73
94
|
weekdays: [!0, !0, !0, !0, !0, !1, !1]
|
|
74
95
|
}
|
|
75
96
|
};
|
|
76
|
-
|
|
97
|
+
d(b), t(b);
|
|
77
98
|
} finally {
|
|
78
99
|
a(!1);
|
|
79
100
|
}
|
|
80
101
|
}, [f, t, n]);
|
|
81
|
-
return
|
|
82
|
-
f &&
|
|
83
|
-
}, [f,
|
|
84
|
-
isLoading:
|
|
85
|
-
error:
|
|
102
|
+
return k(() => {
|
|
103
|
+
f && m();
|
|
104
|
+
}, [f, m]), {
|
|
105
|
+
isLoading: h,
|
|
106
|
+
error: l,
|
|
86
107
|
preferences: r
|
|
87
108
|
};
|
|
88
109
|
}, se = () => window.__notificationSDK?.client, ce = () => {
|
|
89
|
-
const t = se(), [n, f] =
|
|
90
|
-
if (!(!t ||
|
|
110
|
+
const t = se(), [n, f] = v([]), [h, a] = v(!1), [l, s] = v(!0), [r, d] = v(0), m = 5, p = T(async () => {
|
|
111
|
+
if (!(!t || h || !l))
|
|
91
112
|
try {
|
|
92
113
|
a(!0);
|
|
93
|
-
const
|
|
94
|
-
if (!
|
|
114
|
+
const I = window.__notificationSDK?.config;
|
|
115
|
+
if (!I) return;
|
|
95
116
|
const b = await t.preferences.listSpecific(
|
|
96
|
-
|
|
97
|
-
|
|
117
|
+
I.tenantId,
|
|
118
|
+
I.subscriberId,
|
|
98
119
|
{
|
|
99
120
|
includeWorkflows: !0,
|
|
100
121
|
includeTemplates: !1,
|
|
101
122
|
activeOnly: !0,
|
|
102
|
-
limit:
|
|
123
|
+
limit: m,
|
|
103
124
|
offset: r
|
|
104
125
|
}
|
|
105
|
-
), w = (b.items || []).map((
|
|
106
|
-
workflowId:
|
|
107
|
-
name:
|
|
108
|
-
enabled:
|
|
109
|
-
channels:
|
|
126
|
+
), w = (b.items || []).map((c) => ({
|
|
127
|
+
workflowId: c.identifier,
|
|
128
|
+
name: c.name,
|
|
129
|
+
enabled: c.preference.enabled,
|
|
130
|
+
channels: c.preference.channels
|
|
110
131
|
}));
|
|
111
|
-
f((
|
|
112
|
-
const
|
|
113
|
-
return [...
|
|
114
|
-
}),
|
|
132
|
+
f((c) => {
|
|
133
|
+
const N = new Set(c.map((_) => _.workflowId)), C = w.filter((_) => !N.has(_.workflowId));
|
|
134
|
+
return [...c, ...C];
|
|
135
|
+
}), d((c) => c + m), (w.length < m || b.total !== void 0 && n.length + w.length >= b.total) && s(!1);
|
|
115
136
|
} catch {
|
|
116
137
|
} finally {
|
|
117
138
|
a(!1);
|
|
118
139
|
}
|
|
119
|
-
}, [t, r,
|
|
120
|
-
return
|
|
140
|
+
}, [t, r, l, h, n.length]);
|
|
141
|
+
return k(() => {
|
|
121
142
|
t && r === 0 && n.length === 0 && p();
|
|
122
143
|
}, [t, p, r, n.length]), {
|
|
123
144
|
specificPreferences: n,
|
|
124
|
-
isLoading:
|
|
125
|
-
hasMore:
|
|
145
|
+
isLoading: h,
|
|
146
|
+
hasMore: l,
|
|
126
147
|
loadMore: p,
|
|
127
148
|
refetch: async () => {
|
|
128
|
-
f([]),
|
|
149
|
+
f([]), d(0), s(!0);
|
|
129
150
|
}
|
|
130
151
|
};
|
|
131
|
-
}, de = ({ error: t, onRetry: n }) => /* @__PURE__ */
|
|
152
|
+
}, de = ({ error: t, onRetry: n }) => /* @__PURE__ */ A(
|
|
132
153
|
"div",
|
|
133
154
|
{
|
|
134
155
|
className: "p-4 bg-[var(--widget-error)]/10 border border-[var(--widget-error)]/20 rounded-lg",
|
|
135
156
|
role: "alert",
|
|
136
157
|
"data-testid": "error-boundary-fallback",
|
|
137
158
|
children: [
|
|
138
|
-
/* @__PURE__ */
|
|
139
|
-
/* @__PURE__ */
|
|
140
|
-
/* @__PURE__ */
|
|
159
|
+
/* @__PURE__ */ A("div", { className: "flex items-center mb-2", children: [
|
|
160
|
+
/* @__PURE__ */ u(ee, { className: "w-6 h-6 text-[var(--widget-error)] mr-2", "aria-hidden": "true" }),
|
|
161
|
+
/* @__PURE__ */ u("h3", { className: "text-sm font-medium text-[var(--widget-error)]", children: "Something went wrong" })
|
|
141
162
|
] }),
|
|
142
|
-
/* @__PURE__ */
|
|
143
|
-
process.env.NODE_ENV === "development" && t && /* @__PURE__ */
|
|
144
|
-
/* @__PURE__ */
|
|
145
|
-
/* @__PURE__ */
|
|
163
|
+
/* @__PURE__ */ u("p", { className: "text-sm mb-3 text-[var(--widget-error)]/80", children: "The notification widget encountered an error and couldn't load properly." }),
|
|
164
|
+
process.env.NODE_ENV === "development" && t && /* @__PURE__ */ A("details", { className: "mb-3", children: [
|
|
165
|
+
/* @__PURE__ */ u("summary", { className: "text-xs cursor-pointer text-[var(--widget-error)] hover:text-[var(--widget-error)]/80 transition-colors", children: "Error details (development only)" }),
|
|
166
|
+
/* @__PURE__ */ A("pre", { className: "mt-2 text-xs bg-[var(--widget-error)]/5 p-2 rounded overflow-auto max-h-32 text-[var(--widget-error)]", children: [
|
|
146
167
|
t.message,
|
|
147
168
|
t.stack && `
|
|
148
169
|
|
|
149
170
|
${t.stack}`
|
|
150
171
|
] })
|
|
151
172
|
] }),
|
|
152
|
-
/* @__PURE__ */
|
|
173
|
+
/* @__PURE__ */ A(
|
|
153
174
|
"button",
|
|
154
175
|
{
|
|
155
176
|
type: "button",
|
|
@@ -157,7 +178,7 @@ ${t.stack}`
|
|
|
157
178
|
onClick: n,
|
|
158
179
|
"data-testid": "error-retry-button",
|
|
159
180
|
children: [
|
|
160
|
-
/* @__PURE__ */
|
|
181
|
+
/* @__PURE__ */ u(te, { className: "mr-1 w-4 h-4", "aria-hidden": "true" }),
|
|
161
182
|
"Try again"
|
|
162
183
|
]
|
|
163
184
|
}
|
|
@@ -191,15 +212,15 @@ class le extends j {
|
|
|
191
212
|
}), this.props.onError && this.props.onError(n, f);
|
|
192
213
|
}
|
|
193
214
|
render() {
|
|
194
|
-
return this.state.hasError ? /* @__PURE__ */
|
|
215
|
+
return this.state.hasError ? /* @__PURE__ */ u(de, { error: this.state.error, onRetry: this.handleRetry }) : this.props.children;
|
|
195
216
|
}
|
|
196
217
|
}
|
|
197
|
-
const L = J(null),
|
|
218
|
+
const L = J(null), ue = () => {
|
|
198
219
|
const t = X(L);
|
|
199
220
|
if (!t)
|
|
200
221
|
throw new Error("useSDK must be used within a NotificationWidget");
|
|
201
222
|
return t;
|
|
202
|
-
},
|
|
223
|
+
}, fe = {
|
|
203
224
|
notifications: [],
|
|
204
225
|
unreadCount: 0,
|
|
205
226
|
preferences: {
|
|
@@ -234,18 +255,18 @@ const L = J(null), fe = () => {
|
|
|
234
255
|
config: t,
|
|
235
256
|
children: n
|
|
236
257
|
}) => {
|
|
237
|
-
const [f,
|
|
258
|
+
const [f, h] = F.useState({
|
|
238
259
|
client: null,
|
|
239
260
|
isInitialized: !1,
|
|
240
261
|
error: null
|
|
241
262
|
});
|
|
242
|
-
return
|
|
263
|
+
return k(() => {
|
|
243
264
|
let a = !0;
|
|
244
265
|
return (async () => {
|
|
245
266
|
try {
|
|
246
267
|
const s = window.__notificationSDK;
|
|
247
268
|
if (s?.client && JSON.stringify(s.config) === JSON.stringify(t)) {
|
|
248
|
-
a &&
|
|
269
|
+
a && h({
|
|
249
270
|
client: s.client,
|
|
250
271
|
isInitialized: !0,
|
|
251
272
|
error: null
|
|
@@ -258,13 +279,13 @@ const L = J(null), fe = () => {
|
|
|
258
279
|
tenantId: t.tenantId,
|
|
259
280
|
environmentId: t.environmentId
|
|
260
281
|
});
|
|
261
|
-
window.__notificationSDK = { client: r, config: t }, a &&
|
|
282
|
+
window.__notificationSDK = { client: r, config: t }, a && h({
|
|
262
283
|
client: r,
|
|
263
284
|
isInitialized: !0,
|
|
264
285
|
error: null
|
|
265
286
|
});
|
|
266
287
|
} catch (s) {
|
|
267
|
-
a &&
|
|
288
|
+
a && h({
|
|
268
289
|
client: null,
|
|
269
290
|
isInitialized: !1,
|
|
270
291
|
error: s
|
|
@@ -273,37 +294,37 @@ const L = J(null), fe = () => {
|
|
|
273
294
|
})(), () => {
|
|
274
295
|
a = !1;
|
|
275
296
|
};
|
|
276
|
-
}, [t]), /* @__PURE__ */
|
|
277
|
-
},
|
|
297
|
+
}, [t]), /* @__PURE__ */ u(L.Provider, { value: f, children: n });
|
|
298
|
+
}, he = (t, n) => {
|
|
278
299
|
switch (n.type) {
|
|
279
300
|
case "SET_NOTIFICATIONS":
|
|
280
301
|
return {
|
|
281
302
|
...t,
|
|
282
303
|
notifications: n.payload,
|
|
283
|
-
unreadCount: n.payload.filter((
|
|
304
|
+
unreadCount: n.payload.filter((l) => !l.isRead).length
|
|
284
305
|
};
|
|
285
306
|
case "ADD_NOTIFICATION":
|
|
286
307
|
const f = [n.payload, ...t.notifications];
|
|
287
308
|
return {
|
|
288
309
|
...t,
|
|
289
310
|
notifications: f,
|
|
290
|
-
unreadCount: f.filter((
|
|
311
|
+
unreadCount: f.filter((l) => !l.isRead).length
|
|
291
312
|
};
|
|
292
313
|
case "UPDATE_NOTIFICATION":
|
|
293
|
-
const
|
|
294
|
-
(
|
|
314
|
+
const h = t.notifications.map(
|
|
315
|
+
(l) => l.id === n.payload.id ? { ...l, ...n.payload.updates } : l
|
|
295
316
|
);
|
|
296
317
|
return {
|
|
297
318
|
...t,
|
|
298
|
-
notifications:
|
|
299
|
-
unreadCount:
|
|
319
|
+
notifications: h,
|
|
320
|
+
unreadCount: h.filter((l) => !l.isRead).length
|
|
300
321
|
};
|
|
301
322
|
case "DELETE_NOTIFICATION":
|
|
302
|
-
const a = t.notifications.filter((
|
|
323
|
+
const a = t.notifications.filter((l) => l.id !== n.payload);
|
|
303
324
|
return {
|
|
304
325
|
...t,
|
|
305
326
|
notifications: a,
|
|
306
|
-
unreadCount: a.filter((
|
|
327
|
+
unreadCount: a.filter((l) => !l.isRead).length
|
|
307
328
|
};
|
|
308
329
|
case "SET_PREFERENCES":
|
|
309
330
|
return {
|
|
@@ -323,15 +344,15 @@ const L = J(null), fe = () => {
|
|
|
323
344
|
default:
|
|
324
345
|
return t;
|
|
325
346
|
}
|
|
326
|
-
},
|
|
347
|
+
}, me = ({
|
|
327
348
|
position: t = "right",
|
|
328
349
|
size: n = "medium",
|
|
329
350
|
theme: f = "light",
|
|
330
|
-
className:
|
|
351
|
+
className: h = "",
|
|
331
352
|
onError: a,
|
|
332
|
-
onMorePreferencesClick:
|
|
353
|
+
onMorePreferencesClick: l
|
|
333
354
|
}) => {
|
|
334
|
-
const [s, r] = G(
|
|
355
|
+
const [s, r] = G(he, fe), { client: d, isInitialized: m, error: p } = ue(), E = Q(null), I = T((e) => {
|
|
335
356
|
r({
|
|
336
357
|
type: "SET_PREFERENCES",
|
|
337
358
|
payload: e
|
|
@@ -342,33 +363,33 @@ const L = J(null), fe = () => {
|
|
|
342
363
|
},
|
|
343
364
|
[a]
|
|
344
365
|
), { error: w } = ae({
|
|
345
|
-
onPreferencesLoaded:
|
|
366
|
+
onPreferencesLoaded: I,
|
|
346
367
|
onError: b
|
|
347
368
|
}), {
|
|
348
|
-
specificPreferences:
|
|
349
|
-
isLoading:
|
|
350
|
-
hasMore:
|
|
351
|
-
loadMore:
|
|
369
|
+
specificPreferences: c,
|
|
370
|
+
isLoading: N,
|
|
371
|
+
hasMore: C,
|
|
372
|
+
loadMore: _
|
|
352
373
|
} = ce(), {
|
|
353
374
|
updatePreference: U,
|
|
354
375
|
isSaving: D,
|
|
355
376
|
error: R
|
|
356
377
|
} = Z({
|
|
357
378
|
preferences: s.preferences,
|
|
358
|
-
onPreferencesChange:
|
|
379
|
+
onPreferencesChange: I,
|
|
359
380
|
onError: b
|
|
360
381
|
});
|
|
361
|
-
|
|
362
|
-
if (
|
|
382
|
+
k(() => {
|
|
383
|
+
if (c.length > 0) {
|
|
363
384
|
const i = [...s.preferences.subscriptions];
|
|
364
385
|
let o = !1;
|
|
365
|
-
|
|
366
|
-
const
|
|
367
|
-
if (
|
|
368
|
-
i.push(
|
|
386
|
+
c.forEach((g) => {
|
|
387
|
+
const y = i.findIndex((S) => S.workflowId === g.workflowId);
|
|
388
|
+
if (y === -1)
|
|
389
|
+
i.push(g), o = !0;
|
|
369
390
|
else {
|
|
370
|
-
const
|
|
371
|
-
|
|
391
|
+
const S = i[y];
|
|
392
|
+
S.name === S.workflowId && g.name && g.name !== g.workflowId && (i[y] = { ...S, name: g.name }, o = !0);
|
|
372
393
|
}
|
|
373
394
|
}), o && r({
|
|
374
395
|
type: "SET_PREFERENCES",
|
|
@@ -378,8 +399,8 @@ const L = J(null), fe = () => {
|
|
|
378
399
|
}
|
|
379
400
|
});
|
|
380
401
|
}
|
|
381
|
-
}, [
|
|
382
|
-
const W = F.useMemo(() =>
|
|
402
|
+
}, [c]);
|
|
403
|
+
const W = F.useMemo(() => c.map((e) => s.preferences.subscriptions.find((o) => o.workflowId === e.workflowId) || e), [c, s.preferences.subscriptions]), O = T((e) => {
|
|
383
404
|
try {
|
|
384
405
|
const i = K();
|
|
385
406
|
switch (e.type) {
|
|
@@ -387,10 +408,10 @@ const L = J(null), fe = () => {
|
|
|
387
408
|
const o = e.data;
|
|
388
409
|
if (!i.validateWebSocketPayload(o))
|
|
389
410
|
break;
|
|
390
|
-
const
|
|
411
|
+
const g = i.toWidgetNotificationFromWebSocket(o);
|
|
391
412
|
r({
|
|
392
413
|
type: "ADD_NOTIFICATION",
|
|
393
|
-
payload:
|
|
414
|
+
payload: g
|
|
394
415
|
});
|
|
395
416
|
break;
|
|
396
417
|
}
|
|
@@ -420,7 +441,7 @@ const L = J(null), fe = () => {
|
|
|
420
441
|
} catch {
|
|
421
442
|
}
|
|
422
443
|
}, []), M = T(async () => {
|
|
423
|
-
if (!(!
|
|
444
|
+
if (!(!d || !m || E.current))
|
|
424
445
|
try {
|
|
425
446
|
r({
|
|
426
447
|
type: "SET_WEBSOCKET_STATE",
|
|
@@ -429,7 +450,7 @@ const L = J(null), fe = () => {
|
|
|
429
450
|
const e = window.__notificationSDK?.config;
|
|
430
451
|
if (!e)
|
|
431
452
|
throw new Error("SDK configuration not available for WebSocket connection");
|
|
432
|
-
const
|
|
453
|
+
const g = `${d.getApiHost()}/v1/notifications`, y = Y(g, {
|
|
433
454
|
query: {
|
|
434
455
|
tenantId: e.tenantId,
|
|
435
456
|
subscriberId: e.subscriberId,
|
|
@@ -442,42 +463,42 @@ const L = J(null), fe = () => {
|
|
|
442
463
|
reconnectionDelay: 1e3,
|
|
443
464
|
reconnectionDelayMax: 5e3
|
|
444
465
|
});
|
|
445
|
-
|
|
466
|
+
E.current = y, y.on("notification", (S) => {
|
|
446
467
|
O({
|
|
447
468
|
type: "notification_received",
|
|
448
|
-
data:
|
|
469
|
+
data: S
|
|
449
470
|
});
|
|
450
|
-
}),
|
|
471
|
+
}), y.on("connect", () => {
|
|
451
472
|
r({
|
|
452
473
|
type: "SET_WEBSOCKET_STATE",
|
|
453
474
|
payload: { connected: !0, reconnecting: !1 }
|
|
454
475
|
});
|
|
455
|
-
}),
|
|
476
|
+
}), y.on("disconnect", (S) => {
|
|
456
477
|
r({
|
|
457
478
|
type: "SET_WEBSOCKET_STATE",
|
|
458
479
|
payload: { connected: !1, reconnecting: !1 }
|
|
459
480
|
});
|
|
460
|
-
}),
|
|
481
|
+
}), y.on("reconnect_attempt", (S) => {
|
|
461
482
|
r({
|
|
462
483
|
type: "SET_WEBSOCKET_STATE",
|
|
463
484
|
payload: { connected: !1, reconnecting: !0 }
|
|
464
485
|
});
|
|
465
|
-
}),
|
|
486
|
+
}), y.on("connect_error", (S) => {
|
|
466
487
|
r({
|
|
467
488
|
type: "SET_WEBSOCKET_STATE",
|
|
468
489
|
payload: { connected: !1, reconnecting: !1 }
|
|
469
|
-
}), a && a(
|
|
470
|
-
}),
|
|
490
|
+
}), a && a(S);
|
|
491
|
+
}), y.connect();
|
|
471
492
|
} catch (e) {
|
|
472
493
|
r({
|
|
473
494
|
type: "SET_WEBSOCKET_STATE",
|
|
474
495
|
payload: { connected: !1, reconnecting: !1 }
|
|
475
496
|
}), a && a(e);
|
|
476
497
|
}
|
|
477
|
-
}, [
|
|
478
|
-
if (
|
|
498
|
+
}, [d, m, O, a]), B = T(() => {
|
|
499
|
+
if (E.current)
|
|
479
500
|
try {
|
|
480
|
-
|
|
501
|
+
E.current.disconnect && E.current.disconnect(), E.current = null, r({
|
|
481
502
|
type: "SET_WEBSOCKET_STATE",
|
|
482
503
|
payload: { connected: !1, reconnecting: !1 }
|
|
483
504
|
});
|
|
@@ -500,7 +521,7 @@ const L = J(null), fe = () => {
|
|
|
500
521
|
});
|
|
501
522
|
}, []), H = T(
|
|
502
523
|
async (e, i) => {
|
|
503
|
-
if (!
|
|
524
|
+
if (!d || !m)
|
|
504
525
|
return;
|
|
505
526
|
const o = window.__notificationSDK?.config;
|
|
506
527
|
if (o) {
|
|
@@ -509,7 +530,7 @@ const L = J(null), fe = () => {
|
|
|
509
530
|
try {
|
|
510
531
|
switch (i.type) {
|
|
511
532
|
case "mark_read":
|
|
512
|
-
await
|
|
533
|
+
await d.inbox.markAsRead(
|
|
513
534
|
e,
|
|
514
535
|
o.tenantId,
|
|
515
536
|
o.environmentId,
|
|
@@ -517,7 +538,7 @@ const L = J(null), fe = () => {
|
|
|
517
538
|
);
|
|
518
539
|
break;
|
|
519
540
|
case "mark_unread":
|
|
520
|
-
await
|
|
541
|
+
await d.inbox.markAsUnread(
|
|
521
542
|
e,
|
|
522
543
|
o.tenantId,
|
|
523
544
|
o.environmentId,
|
|
@@ -525,7 +546,7 @@ const L = J(null), fe = () => {
|
|
|
525
546
|
);
|
|
526
547
|
break;
|
|
527
548
|
case "archive":
|
|
528
|
-
await
|
|
549
|
+
await d.inbox.archive(
|
|
529
550
|
e,
|
|
530
551
|
o.tenantId,
|
|
531
552
|
o.environmentId,
|
|
@@ -533,7 +554,7 @@ const L = J(null), fe = () => {
|
|
|
533
554
|
);
|
|
534
555
|
break;
|
|
535
556
|
case "delete":
|
|
536
|
-
await
|
|
557
|
+
await d.inbox.delete(
|
|
537
558
|
e,
|
|
538
559
|
o.tenantId,
|
|
539
560
|
o.environmentId,
|
|
@@ -570,15 +591,15 @@ const L = J(null), fe = () => {
|
|
|
570
591
|
});
|
|
571
592
|
break;
|
|
572
593
|
}
|
|
573
|
-
} catch (
|
|
574
|
-
a && a(
|
|
594
|
+
} catch (g) {
|
|
595
|
+
a && a(g);
|
|
575
596
|
}
|
|
576
597
|
}
|
|
577
598
|
},
|
|
578
|
-
[
|
|
599
|
+
[d]
|
|
579
600
|
);
|
|
580
|
-
return
|
|
581
|
-
if (!
|
|
601
|
+
return k(() => {
|
|
602
|
+
if (!d || !m) return;
|
|
582
603
|
(async () => {
|
|
583
604
|
try {
|
|
584
605
|
r({
|
|
@@ -588,7 +609,7 @@ const L = J(null), fe = () => {
|
|
|
588
609
|
const i = window.__notificationSDK?.config;
|
|
589
610
|
if (!i)
|
|
590
611
|
throw new Error("SDK configuration not available");
|
|
591
|
-
const o = K(),
|
|
612
|
+
const o = K(), y = ((await d.inbox.getRenderedNotifications(
|
|
592
613
|
{
|
|
593
614
|
channel: "in_app",
|
|
594
615
|
limit: 50,
|
|
@@ -598,11 +619,11 @@ const L = J(null), fe = () => {
|
|
|
598
619
|
i.environmentId,
|
|
599
620
|
i.subscriberId
|
|
600
621
|
))?.items || []).map(
|
|
601
|
-
(
|
|
622
|
+
(S) => o.toWidgetNotification(S)
|
|
602
623
|
);
|
|
603
624
|
r({
|
|
604
625
|
type: "SET_NOTIFICATIONS",
|
|
605
|
-
payload:
|
|
626
|
+
payload: y
|
|
606
627
|
}), r({
|
|
607
628
|
type: "SET_UI_STATE",
|
|
608
629
|
payload: { isLoading: !1, error: null }
|
|
@@ -617,16 +638,16 @@ const L = J(null), fe = () => {
|
|
|
617
638
|
}), a && a(i);
|
|
618
639
|
}
|
|
619
640
|
})();
|
|
620
|
-
}, [
|
|
641
|
+
}, [d, m, a]), k(() => (d && m && M(), () => {
|
|
621
642
|
B();
|
|
622
|
-
}), [
|
|
623
|
-
if (!
|
|
643
|
+
}), [d]), k(() => {
|
|
644
|
+
if (!d || !m || s.websocket.connected) return;
|
|
624
645
|
const e = setInterval(async () => {
|
|
625
646
|
try {
|
|
626
647
|
const i = window.__notificationSDK?.config;
|
|
627
648
|
if (!i)
|
|
628
649
|
return;
|
|
629
|
-
const o = K(),
|
|
650
|
+
const o = K(), y = ((await d.inbox.getRenderedNotifications(
|
|
630
651
|
{
|
|
631
652
|
channel: "in_app",
|
|
632
653
|
limit: 50,
|
|
@@ -636,17 +657,17 @@ const L = J(null), fe = () => {
|
|
|
636
657
|
i.environmentId,
|
|
637
658
|
i.subscriberId
|
|
638
659
|
))?.items || []).map(
|
|
639
|
-
(
|
|
660
|
+
(S) => o.toWidgetNotification(S)
|
|
640
661
|
);
|
|
641
662
|
r({
|
|
642
663
|
type: "SET_NOTIFICATIONS",
|
|
643
|
-
payload:
|
|
664
|
+
payload: y
|
|
644
665
|
});
|
|
645
666
|
} catch {
|
|
646
667
|
}
|
|
647
668
|
}, 3e4);
|
|
648
669
|
return () => clearInterval(e);
|
|
649
|
-
}, [
|
|
670
|
+
}, [d, s.websocket.connected]), k(() => {
|
|
650
671
|
const e = (i) => {
|
|
651
672
|
if (i.key === "notification_widget_sync" && i.newValue)
|
|
652
673
|
try {
|
|
@@ -656,62 +677,62 @@ const L = J(null), fe = () => {
|
|
|
656
677
|
}
|
|
657
678
|
};
|
|
658
679
|
return window.addEventListener("storage", e), () => window.removeEventListener("storage", e);
|
|
659
|
-
}, [O]),
|
|
680
|
+
}, [O]), k(() => {
|
|
660
681
|
r({
|
|
661
682
|
type: "SET_UI_STATE",
|
|
662
683
|
payload: { isLoading: D }
|
|
663
684
|
});
|
|
664
|
-
}, [D]),
|
|
685
|
+
}, [D]), k(() => {
|
|
665
686
|
const e = p || R || w;
|
|
666
687
|
e && r({
|
|
667
688
|
type: "SET_UI_STATE",
|
|
668
689
|
payload: { error: e }
|
|
669
690
|
});
|
|
670
|
-
}, [p, R, w]), !
|
|
691
|
+
}, [p, R, w]), !m && !p ? /* @__PURE__ */ u(
|
|
671
692
|
"div",
|
|
672
693
|
{
|
|
673
|
-
className: `mx-widget-root relative inline-block ${
|
|
694
|
+
className: `mx-widget-root relative inline-block ${h}`,
|
|
674
695
|
"data-mx-widget": "root",
|
|
675
696
|
"data-widget-size": n || "small",
|
|
676
697
|
"data-theme": f,
|
|
677
698
|
"data-testid": "notification-widget",
|
|
678
|
-
children: /* @__PURE__ */
|
|
699
|
+
children: /* @__PURE__ */ u(x, { componentName: "BellComponent", children: /* @__PURE__ */ u(P, { unreadCount: 0, onClick: () => {
|
|
679
700
|
}, size: n, disabled: !0 }) })
|
|
680
701
|
}
|
|
681
|
-
) : p ? /* @__PURE__ */
|
|
702
|
+
) : p ? /* @__PURE__ */ u(
|
|
682
703
|
"div",
|
|
683
704
|
{
|
|
684
|
-
className: `mx-widget-root relative inline-block ${
|
|
705
|
+
className: `mx-widget-root relative inline-block ${h}`,
|
|
685
706
|
"data-mx-widget": "root",
|
|
686
707
|
"data-widget-size": n || "small",
|
|
687
708
|
"data-theme": f,
|
|
688
709
|
"data-testid": "notification-widget",
|
|
689
|
-
children: /* @__PURE__ */
|
|
710
|
+
children: /* @__PURE__ */ u(
|
|
690
711
|
x,
|
|
691
712
|
{
|
|
692
713
|
componentName: "BellComponent",
|
|
693
|
-
fallback: /* @__PURE__ */
|
|
714
|
+
fallback: /* @__PURE__ */ u(
|
|
694
715
|
ne,
|
|
695
716
|
{
|
|
696
717
|
error: p.message,
|
|
697
718
|
onRetry: () => window.location.reload()
|
|
698
719
|
}
|
|
699
720
|
),
|
|
700
|
-
children: /* @__PURE__ */
|
|
721
|
+
children: /* @__PURE__ */ u(P, { unreadCount: 0, onClick: () => {
|
|
701
722
|
}, size: n, disabled: !0 })
|
|
702
723
|
}
|
|
703
724
|
)
|
|
704
725
|
}
|
|
705
|
-
) : /* @__PURE__ */
|
|
726
|
+
) : /* @__PURE__ */ A(
|
|
706
727
|
"div",
|
|
707
728
|
{
|
|
708
|
-
className: `mx-widget-root relative inline-block ${
|
|
729
|
+
className: `mx-widget-root relative inline-block ${h}`,
|
|
709
730
|
"data-mx-widget": "root",
|
|
710
731
|
"data-widget-size": n || "small",
|
|
711
732
|
"data-theme": f,
|
|
712
733
|
"data-testid": "notification-widget",
|
|
713
734
|
children: [
|
|
714
|
-
/* @__PURE__ */
|
|
735
|
+
/* @__PURE__ */ u(x, { componentName: "BellComponent", children: /* @__PURE__ */ u(
|
|
715
736
|
P,
|
|
716
737
|
{
|
|
717
738
|
unreadCount: s.unreadCount,
|
|
@@ -720,12 +741,12 @@ const L = J(null), fe = () => {
|
|
|
720
741
|
disabled: s.ui.isLoading
|
|
721
742
|
}
|
|
722
743
|
) }),
|
|
723
|
-
/* @__PURE__ */
|
|
744
|
+
/* @__PURE__ */ u(
|
|
724
745
|
x,
|
|
725
746
|
{
|
|
726
747
|
componentName: "InboxPopover",
|
|
727
|
-
fallback: /* @__PURE__ */
|
|
728
|
-
children: /* @__PURE__ */
|
|
748
|
+
fallback: /* @__PURE__ */ u(ie, { message: "Unable to load notifications" }),
|
|
749
|
+
children: /* @__PURE__ */ u(
|
|
729
750
|
re,
|
|
730
751
|
{
|
|
731
752
|
isOpen: s.ui.isOpen,
|
|
@@ -739,10 +760,10 @@ const L = J(null), fe = () => {
|
|
|
739
760
|
onPreferenceChange: U,
|
|
740
761
|
isPreferencesLoading: D,
|
|
741
762
|
specificPreferences: W,
|
|
742
|
-
onLoadMoreSpecific:
|
|
743
|
-
hasMoreSpecific:
|
|
744
|
-
isListLoading:
|
|
745
|
-
onMorePreferencesClick:
|
|
763
|
+
onLoadMoreSpecific: _,
|
|
764
|
+
hasMoreSpecific: C,
|
|
765
|
+
isListLoading: N,
|
|
766
|
+
onMorePreferencesClick: l
|
|
746
767
|
}
|
|
747
768
|
)
|
|
748
769
|
}
|
|
@@ -750,12 +771,12 @@ const L = J(null), fe = () => {
|
|
|
750
771
|
]
|
|
751
772
|
}
|
|
752
773
|
);
|
|
753
|
-
},
|
|
774
|
+
}, Ie = ({ sdkConfig: t, ...n }) => /* @__PURE__ */ u(le, { onError: n.onError, children: /* @__PURE__ */ u(pe, { config: t, children: /* @__PURE__ */ u(me, { ...n }) }) }), Te = "3.0.0", _e = "@edusight/notification-widget";
|
|
754
775
|
export {
|
|
755
776
|
P as BellComponent,
|
|
756
777
|
re as InboxPopover,
|
|
757
|
-
|
|
758
|
-
|
|
778
|
+
Ce as NotificationItem,
|
|
779
|
+
Ie as NotificationWidget,
|
|
759
780
|
le as NotificationWidgetErrorBoundary,
|
|
760
781
|
ve as PreferencesView,
|
|
761
782
|
Te as VERSION,
|