@edusight/notification-widget 1.0.28 → 1.0.29
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-B9Z6HsnI.cjs +70 -0
- package/dist/{components-ytSNU0U3.cjs.map → components-B9Z6HsnI.cjs.map} +1 -1
- package/dist/{components-BJ465mfK.js → components-DgV3nlCC.js} +214 -199
- package/dist/{components-BJ465mfK.js.map → components-DgV3nlCC.js.map} +1 -1
- package/dist/hooks-CggRWw6Q.cjs +2 -0
- package/dist/hooks-CggRWw6Q.cjs.map +1 -0
- package/dist/hooks-Cv5k48VE.js +159 -0
- package/dist/hooks-Cv5k48VE.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 +1 -1
- package/dist/index.esm.js +241 -177
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/dist/components-ytSNU0U3.cjs +0 -72
- package/dist/hooks-CACL0Qzv.cjs +0 -2
- package/dist/hooks-CACL0Qzv.cjs.map +0 -1
- package/dist/hooks-DQflK_dw.js +0 -160
- package/dist/hooks-DQflK_dw.js.map +0 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { jsx as d, jsxs as
|
|
2
|
-
import
|
|
3
|
-
import { io as
|
|
4
|
-
import { NotificationClient as
|
|
5
|
-
import { M as
|
|
6
|
-
import { N as Te, P as
|
|
7
|
-
import { u as
|
|
8
|
-
const
|
|
1
|
+
import { jsx as d, jsxs as k } from "react/jsx-runtime";
|
|
2
|
+
import M, { Component as V, useState as C, useCallback as y, useEffect as b, createContext as z, useReducer as q, useRef as $, useContext as H } from "react";
|
|
3
|
+
import { io as J } from "socket.io-client";
|
|
4
|
+
import { NotificationClient as j } from "@edusight/notification-sdk";
|
|
5
|
+
import { M as G, a as Q, C as O, B as D, S as X, I as Y, L as Z } from "./components-DgV3nlCC.js";
|
|
6
|
+
import { N as Te, P as _e } from "./components-DgV3nlCC.js";
|
|
7
|
+
import { u as ee, c as x } from "./hooks-Cv5k48VE.js";
|
|
8
|
+
const te = ({ error: t, onRetry: r }) => /* @__PURE__ */ k(
|
|
9
9
|
"div",
|
|
10
10
|
{
|
|
11
11
|
className: "p-4 bg-[var(--widget-error)]/10 border border-[var(--widget-error)]/20 rounded-lg",
|
|
12
12
|
role: "alert",
|
|
13
13
|
"data-testid": "error-boundary-fallback",
|
|
14
14
|
children: [
|
|
15
|
-
/* @__PURE__ */
|
|
15
|
+
/* @__PURE__ */ k("div", { className: "flex items-center mb-2", children: [
|
|
16
16
|
/* @__PURE__ */ d(
|
|
17
|
-
|
|
17
|
+
G,
|
|
18
18
|
{
|
|
19
19
|
className: "w-6 h-6 text-[var(--widget-error)] mr-2",
|
|
20
20
|
"aria-hidden": "true"
|
|
@@ -35,7 +35,7 @@ const Z = ({ error: t, onRetry: r }) => /* @__PURE__ */ C(
|
|
|
35
35
|
children: "The notification widget encountered an error and couldn't load properly."
|
|
36
36
|
}
|
|
37
37
|
),
|
|
38
|
-
process.env.NODE_ENV === "development" && t && /* @__PURE__ */
|
|
38
|
+
process.env.NODE_ENV === "development" && t && /* @__PURE__ */ k("details", { className: "mb-3", children: [
|
|
39
39
|
/* @__PURE__ */ d(
|
|
40
40
|
"summary",
|
|
41
41
|
{
|
|
@@ -43,7 +43,7 @@ const Z = ({ error: t, onRetry: r }) => /* @__PURE__ */ C(
|
|
|
43
43
|
children: "Error details (development only)"
|
|
44
44
|
}
|
|
45
45
|
),
|
|
46
|
-
/* @__PURE__ */
|
|
46
|
+
/* @__PURE__ */ k(
|
|
47
47
|
"pre",
|
|
48
48
|
{
|
|
49
49
|
className: "mt-2 text-xs bg-[var(--widget-error)]/5 p-2 rounded overflow-auto max-h-32 text-[var(--widget-error)]",
|
|
@@ -56,7 +56,7 @@ ${t.stack}`
|
|
|
56
56
|
}
|
|
57
57
|
)
|
|
58
58
|
] }),
|
|
59
|
-
/* @__PURE__ */
|
|
59
|
+
/* @__PURE__ */ k(
|
|
60
60
|
"button",
|
|
61
61
|
{
|
|
62
62
|
type: "button",
|
|
@@ -65,7 +65,7 @@ ${t.stack}`
|
|
|
65
65
|
"data-testid": "error-retry-button",
|
|
66
66
|
children: [
|
|
67
67
|
/* @__PURE__ */ d(
|
|
68
|
-
|
|
68
|
+
Q,
|
|
69
69
|
{
|
|
70
70
|
className: "mr-1 w-4 h-4",
|
|
71
71
|
"aria-hidden": "true"
|
|
@@ -78,7 +78,7 @@ ${t.stack}`
|
|
|
78
78
|
]
|
|
79
79
|
}
|
|
80
80
|
);
|
|
81
|
-
class
|
|
81
|
+
class ne extends V {
|
|
82
82
|
constructor(r) {
|
|
83
83
|
super(r), this.handleRetry = () => {
|
|
84
84
|
this.setState({
|
|
@@ -105,7 +105,7 @@ class ee extends B {
|
|
|
105
105
|
}
|
|
106
106
|
render() {
|
|
107
107
|
return this.state.hasError ? /* @__PURE__ */ d(
|
|
108
|
-
|
|
108
|
+
te,
|
|
109
109
|
{
|
|
110
110
|
error: this.state.error,
|
|
111
111
|
onRetry: this.handleRetry
|
|
@@ -113,25 +113,25 @@ class ee extends B {
|
|
|
113
113
|
) : this.props.children;
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
-
const
|
|
116
|
+
const re = () => window.__notificationSDK?.client, ie = ({
|
|
117
117
|
onPreferencesLoaded: t,
|
|
118
118
|
onError: r
|
|
119
119
|
}) => {
|
|
120
|
-
const l =
|
|
120
|
+
const l = re(), [p, a] = C(!0), [i, n] = C(null), [s, f] = C(null), m = y(async () => {
|
|
121
121
|
try {
|
|
122
|
-
if (
|
|
122
|
+
if (a(!0), n(null), !l)
|
|
123
123
|
throw new Error("Notification client not available");
|
|
124
124
|
const u = window.__notificationSDK?.config;
|
|
125
125
|
if (!u)
|
|
126
126
|
throw new Error("SDK configuration not available");
|
|
127
|
-
const { subscriberId:
|
|
128
|
-
if (!
|
|
127
|
+
const { subscriberId: g, tenantId: T, environmentId: w } = u;
|
|
128
|
+
if (!g || !T || !w)
|
|
129
129
|
throw new Error("SubscriberId, TenantId or EnvironmentId not available in config");
|
|
130
130
|
const E = await l.preferences.get(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
),
|
|
131
|
+
T,
|
|
132
|
+
g,
|
|
133
|
+
w
|
|
134
|
+
), N = {
|
|
135
135
|
channels: {
|
|
136
136
|
email: E.emailEnabled ?? !0,
|
|
137
137
|
push: E.pushEnabled ?? !0,
|
|
@@ -148,23 +148,23 @@ const te = () => window.__notificationSDK?.client, ne = ({
|
|
|
148
148
|
weekdays: [!0, !0, !0, !0, !0, !1, !1]
|
|
149
149
|
}
|
|
150
150
|
};
|
|
151
|
-
E.categories && Object.entries(E.categories).forEach(([v,
|
|
152
|
-
|
|
151
|
+
E.categories && Object.entries(E.categories).forEach(([v, _]) => {
|
|
152
|
+
N.subscriptions.push({
|
|
153
153
|
workflowId: v,
|
|
154
154
|
name: v,
|
|
155
155
|
enabled: !0,
|
|
156
156
|
channels: {
|
|
157
|
-
email:
|
|
158
|
-
push:
|
|
159
|
-
sms:
|
|
160
|
-
inApp:
|
|
157
|
+
email: _.emailEnabled ?? !0,
|
|
158
|
+
push: _.pushEnabled ?? !0,
|
|
159
|
+
sms: _.smsEnabled ?? !1,
|
|
160
|
+
inApp: _.inAppEnabled ?? !0
|
|
161
161
|
}
|
|
162
162
|
});
|
|
163
|
-
}),
|
|
163
|
+
}), f(N), t(N);
|
|
164
164
|
} catch (u) {
|
|
165
|
-
const
|
|
166
|
-
u?.response?.status === 404 || u?.status === 404 || (n(
|
|
167
|
-
const
|
|
165
|
+
const g = u instanceof Error ? u : new Error("Failed to load preferences");
|
|
166
|
+
u?.response?.status === 404 || u?.status === 404 || (n(g), r?.(g));
|
|
167
|
+
const w = {
|
|
168
168
|
channels: {
|
|
169
169
|
email: !0,
|
|
170
170
|
push: !0,
|
|
@@ -181,24 +181,61 @@ const te = () => window.__notificationSDK?.client, ne = ({
|
|
|
181
181
|
weekdays: [!0, !0, !0, !0, !0, !1, !1]
|
|
182
182
|
}
|
|
183
183
|
};
|
|
184
|
-
|
|
184
|
+
f(w), t(w);
|
|
185
185
|
} finally {
|
|
186
|
-
|
|
186
|
+
a(!1);
|
|
187
187
|
}
|
|
188
188
|
}, [l, t, r]);
|
|
189
|
-
return
|
|
190
|
-
l &&
|
|
191
|
-
}, [l,
|
|
192
|
-
isLoading:
|
|
189
|
+
return b(() => {
|
|
190
|
+
l && m();
|
|
191
|
+
}, [l, m]), {
|
|
192
|
+
isLoading: p,
|
|
193
193
|
error: i,
|
|
194
|
-
preferences:
|
|
194
|
+
preferences: s
|
|
195
195
|
};
|
|
196
|
-
},
|
|
197
|
-
const t =
|
|
196
|
+
}, oe = () => window.__notificationSDK?.client, ae = () => {
|
|
197
|
+
const t = oe(), [r, l] = C([]), [p, a] = C(!0), [i, n] = C(null), s = y(async () => {
|
|
198
|
+
try {
|
|
199
|
+
if (a(!0), n(null), !t)
|
|
200
|
+
throw new Error("Notification client not available");
|
|
201
|
+
const f = window.__notificationSDK?.config;
|
|
202
|
+
if (!f)
|
|
203
|
+
throw new Error("SDK configuration not available");
|
|
204
|
+
const { tenantId: m, environmentId: u } = f;
|
|
205
|
+
if (!m || !u)
|
|
206
|
+
throw new Error("TenantId or EnvironmentId not available in config");
|
|
207
|
+
const T = ((await t.workflows.list(
|
|
208
|
+
{ status: "active" },
|
|
209
|
+
// Only load active workflows
|
|
210
|
+
m,
|
|
211
|
+
u
|
|
212
|
+
))?.workflows || []).map((w) => ({
|
|
213
|
+
workflowId: w.workflowId,
|
|
214
|
+
name: w.name || w.workflowId,
|
|
215
|
+
description: w.description
|
|
216
|
+
}));
|
|
217
|
+
l(T);
|
|
218
|
+
} catch (f) {
|
|
219
|
+
const m = f instanceof Error ? f : new Error("Failed to load workflows");
|
|
220
|
+
n(m), l([]);
|
|
221
|
+
} finally {
|
|
222
|
+
a(!1);
|
|
223
|
+
}
|
|
224
|
+
}, [t]);
|
|
225
|
+
return b(() => {
|
|
226
|
+
t && s();
|
|
227
|
+
}, [t, s]), {
|
|
228
|
+
workflows: r,
|
|
229
|
+
isLoading: p,
|
|
230
|
+
error: i,
|
|
231
|
+
refetch: s
|
|
232
|
+
};
|
|
233
|
+
}, R = z(null), se = () => {
|
|
234
|
+
const t = H(R);
|
|
198
235
|
if (!t)
|
|
199
236
|
throw new Error("useSDK must be used within a NotificationWidget");
|
|
200
237
|
return t;
|
|
201
|
-
},
|
|
238
|
+
}, ce = {
|
|
202
239
|
notifications: [],
|
|
203
240
|
unreadCount: 0,
|
|
204
241
|
preferences: {
|
|
@@ -229,51 +266,51 @@ const te = () => window.__notificationSDK?.client, ne = ({
|
|
|
229
266
|
connected: !1,
|
|
230
267
|
reconnecting: !1
|
|
231
268
|
}
|
|
232
|
-
},
|
|
269
|
+
}, de = ({
|
|
233
270
|
config: t,
|
|
234
271
|
children: r
|
|
235
272
|
}) => {
|
|
236
|
-
const [l,
|
|
273
|
+
const [l, p] = M.useState({
|
|
237
274
|
client: null,
|
|
238
275
|
isInitialized: !1,
|
|
239
276
|
error: null
|
|
240
277
|
});
|
|
241
|
-
return
|
|
242
|
-
let
|
|
278
|
+
return b(() => {
|
|
279
|
+
let a = !0;
|
|
243
280
|
return (async () => {
|
|
244
281
|
try {
|
|
245
282
|
const n = window.__notificationSDK;
|
|
246
283
|
if (n?.client && JSON.stringify(n.config) === JSON.stringify(t)) {
|
|
247
|
-
|
|
284
|
+
a && p({
|
|
248
285
|
client: n.client,
|
|
249
286
|
isInitialized: !0,
|
|
250
287
|
error: null
|
|
251
288
|
});
|
|
252
289
|
return;
|
|
253
290
|
}
|
|
254
|
-
const
|
|
291
|
+
const s = new j({
|
|
255
292
|
apiUrl: t.baseUrl,
|
|
256
293
|
apiKey: t.apiKey,
|
|
257
294
|
tenantId: t.tenantId,
|
|
258
295
|
environmentId: t.environmentId
|
|
259
296
|
});
|
|
260
|
-
window.__notificationSDK = { client:
|
|
261
|
-
client:
|
|
297
|
+
window.__notificationSDK = { client: s, config: t }, a && p({
|
|
298
|
+
client: s,
|
|
262
299
|
isInitialized: !0,
|
|
263
300
|
error: null
|
|
264
301
|
});
|
|
265
302
|
} catch (n) {
|
|
266
|
-
|
|
303
|
+
a && p({
|
|
267
304
|
client: null,
|
|
268
305
|
isInitialized: !1,
|
|
269
306
|
error: n
|
|
270
307
|
});
|
|
271
308
|
}
|
|
272
309
|
})(), () => {
|
|
273
|
-
|
|
310
|
+
a = !1;
|
|
274
311
|
};
|
|
275
|
-
}, [t]), /* @__PURE__ */ d(
|
|
276
|
-
},
|
|
312
|
+
}, [t]), /* @__PURE__ */ d(R.Provider, { value: l, children: r });
|
|
313
|
+
}, le = (t, r) => {
|
|
277
314
|
switch (r.type) {
|
|
278
315
|
case "SET_NOTIFICATIONS":
|
|
279
316
|
return {
|
|
@@ -289,20 +326,20 @@ const te = () => window.__notificationSDK?.client, ne = ({
|
|
|
289
326
|
unreadCount: l.filter((i) => !i.isRead).length
|
|
290
327
|
};
|
|
291
328
|
case "UPDATE_NOTIFICATION":
|
|
292
|
-
const
|
|
329
|
+
const p = t.notifications.map(
|
|
293
330
|
(i) => i.id === r.payload.id ? { ...i, ...r.payload.updates } : i
|
|
294
331
|
);
|
|
295
332
|
return {
|
|
296
333
|
...t,
|
|
297
|
-
notifications:
|
|
298
|
-
unreadCount:
|
|
334
|
+
notifications: p,
|
|
335
|
+
unreadCount: p.filter((i) => !i.isRead).length
|
|
299
336
|
};
|
|
300
337
|
case "DELETE_NOTIFICATION":
|
|
301
|
-
const
|
|
338
|
+
const a = t.notifications.filter((i) => i.id !== r.payload);
|
|
302
339
|
return {
|
|
303
340
|
...t,
|
|
304
|
-
notifications:
|
|
305
|
-
unreadCount:
|
|
341
|
+
notifications: a,
|
|
342
|
+
unreadCount: a.filter((i) => !i.isRead).length
|
|
306
343
|
};
|
|
307
344
|
case "SET_PREFERENCES":
|
|
308
345
|
return {
|
|
@@ -322,39 +359,63 @@ const te = () => window.__notificationSDK?.client, ne = ({
|
|
|
322
359
|
default:
|
|
323
360
|
return t;
|
|
324
361
|
}
|
|
325
|
-
},
|
|
362
|
+
}, fe = ({
|
|
326
363
|
position: t = "right",
|
|
327
364
|
size: r = "medium",
|
|
328
365
|
theme: l = "light",
|
|
329
|
-
className:
|
|
330
|
-
onError:
|
|
366
|
+
className: p = "",
|
|
367
|
+
onError: a
|
|
331
368
|
}) => {
|
|
332
|
-
const [i, n] =
|
|
369
|
+
const [i, n] = q(le, ce), { client: s, isInitialized: f, error: m } = se(), u = $(null), g = y((e) => {
|
|
333
370
|
n({
|
|
334
371
|
type: "SET_PREFERENCES",
|
|
335
372
|
payload: e
|
|
336
373
|
});
|
|
337
|
-
}, []),
|
|
338
|
-
|
|
339
|
-
}, [
|
|
340
|
-
onPreferencesLoaded:
|
|
341
|
-
onError:
|
|
342
|
-
}), {
|
|
374
|
+
}, []), T = y((e) => {
|
|
375
|
+
a && a(e);
|
|
376
|
+
}, [a]), { error: w } = ie({
|
|
377
|
+
onPreferencesLoaded: g,
|
|
378
|
+
onError: T
|
|
379
|
+
}), { workflows: E, isLoading: N } = ae(), { updatePreference: v, isSaving: _, error: K } = ee({
|
|
343
380
|
preferences: i.preferences,
|
|
344
|
-
onPreferencesChange:
|
|
345
|
-
onError:
|
|
346
|
-
})
|
|
381
|
+
onPreferencesChange: g,
|
|
382
|
+
onError: T
|
|
383
|
+
});
|
|
384
|
+
b(() => {
|
|
385
|
+
if (!N && E.length > 0) {
|
|
386
|
+
const e = E.map((o) => i.preferences.subscriptions.find((I) => I.workflowId === o.workflowId) || {
|
|
387
|
+
workflowId: o.workflowId,
|
|
388
|
+
name: o.name,
|
|
389
|
+
enabled: !0,
|
|
390
|
+
// Default to enabled
|
|
391
|
+
channels: {
|
|
392
|
+
email: !0,
|
|
393
|
+
push: !0,
|
|
394
|
+
sms: !1,
|
|
395
|
+
inApp: !0
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
JSON.stringify(e) !== JSON.stringify(i.preferences.subscriptions) && n({
|
|
399
|
+
type: "SET_PREFERENCES",
|
|
400
|
+
payload: {
|
|
401
|
+
...i.preferences,
|
|
402
|
+
subscriptions: e
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
}, [E, N, i.preferences]);
|
|
407
|
+
const A = y((e) => {
|
|
347
408
|
try {
|
|
348
|
-
const
|
|
409
|
+
const o = x();
|
|
349
410
|
switch (e.type) {
|
|
350
411
|
case "notification_received": {
|
|
351
|
-
const
|
|
352
|
-
if (!
|
|
412
|
+
const c = e.data;
|
|
413
|
+
if (!o.validateWebSocketPayload(c))
|
|
353
414
|
break;
|
|
354
|
-
const
|
|
415
|
+
const I = o.toWidgetNotificationFromWebSocket(c);
|
|
355
416
|
n({
|
|
356
417
|
type: "ADD_NOTIFICATION",
|
|
357
|
-
payload:
|
|
418
|
+
payload: I
|
|
358
419
|
});
|
|
359
420
|
break;
|
|
360
421
|
}
|
|
@@ -383,8 +444,8 @@ const te = () => window.__notificationSDK?.client, ne = ({
|
|
|
383
444
|
}
|
|
384
445
|
} catch {
|
|
385
446
|
}
|
|
386
|
-
}, []),
|
|
387
|
-
if (!(!
|
|
447
|
+
}, []), W = y(async () => {
|
|
448
|
+
if (!(!s || !f || u.current))
|
|
388
449
|
try {
|
|
389
450
|
n({
|
|
390
451
|
type: "SET_WEBSOCKET_STATE",
|
|
@@ -393,7 +454,7 @@ const te = () => window.__notificationSDK?.client, ne = ({
|
|
|
393
454
|
const e = window.__notificationSDK?.config;
|
|
394
455
|
if (!e)
|
|
395
456
|
throw new Error("SDK configuration not available for WebSocket connection");
|
|
396
|
-
const
|
|
457
|
+
const I = `${s.getApiHost()}/v1/notifications`, h = J(I, {
|
|
397
458
|
query: {
|
|
398
459
|
tenantId: e.tenantId,
|
|
399
460
|
subscriberId: e.subscriberId,
|
|
@@ -406,39 +467,39 @@ const te = () => window.__notificationSDK?.client, ne = ({
|
|
|
406
467
|
reconnectionDelay: 1e3,
|
|
407
468
|
reconnectionDelayMax: 5e3
|
|
408
469
|
});
|
|
409
|
-
u.current =
|
|
410
|
-
|
|
470
|
+
u.current = h, h.on("notification", (S) => {
|
|
471
|
+
A({
|
|
411
472
|
type: "notification_received",
|
|
412
|
-
data:
|
|
473
|
+
data: S
|
|
413
474
|
});
|
|
414
|
-
}),
|
|
475
|
+
}), h.on("connect", () => {
|
|
415
476
|
n({
|
|
416
477
|
type: "SET_WEBSOCKET_STATE",
|
|
417
478
|
payload: { connected: !0, reconnecting: !1 }
|
|
418
479
|
});
|
|
419
|
-
}),
|
|
480
|
+
}), h.on("disconnect", (S) => {
|
|
420
481
|
n({
|
|
421
482
|
type: "SET_WEBSOCKET_STATE",
|
|
422
483
|
payload: { connected: !1, reconnecting: !1 }
|
|
423
484
|
});
|
|
424
|
-
}),
|
|
485
|
+
}), h.on("reconnect_attempt", (S) => {
|
|
425
486
|
n({
|
|
426
487
|
type: "SET_WEBSOCKET_STATE",
|
|
427
488
|
payload: { connected: !1, reconnecting: !0 }
|
|
428
489
|
});
|
|
429
|
-
}),
|
|
490
|
+
}), h.on("connect_error", (S) => {
|
|
430
491
|
n({
|
|
431
492
|
type: "SET_WEBSOCKET_STATE",
|
|
432
493
|
payload: { connected: !1, reconnecting: !1 }
|
|
433
|
-
}),
|
|
434
|
-
}),
|
|
494
|
+
}), a && a(S);
|
|
495
|
+
}), h.connect();
|
|
435
496
|
} catch (e) {
|
|
436
497
|
n({
|
|
437
498
|
type: "SET_WEBSOCKET_STATE",
|
|
438
499
|
payload: { connected: !1, reconnecting: !1 }
|
|
439
|
-
}),
|
|
500
|
+
}), a && a(e);
|
|
440
501
|
}
|
|
441
|
-
}, [
|
|
502
|
+
}, [s, f, A, a]), F = y(() => {
|
|
442
503
|
if (u.current)
|
|
443
504
|
try {
|
|
444
505
|
u.current.disconnect && u.current.disconnect(), u.current = null, n({
|
|
@@ -447,45 +508,47 @@ const te = () => window.__notificationSDK?.client, ne = ({
|
|
|
447
508
|
});
|
|
448
509
|
} catch {
|
|
449
510
|
}
|
|
450
|
-
}, []), P =
|
|
511
|
+
}, []), P = y(() => {
|
|
451
512
|
n({
|
|
452
513
|
type: "SET_UI_STATE",
|
|
453
514
|
payload: { isOpen: !i.ui.isOpen }
|
|
454
515
|
});
|
|
455
|
-
}, [i.ui.isOpen]),
|
|
516
|
+
}, [i.ui.isOpen]), U = y(() => {
|
|
456
517
|
n({
|
|
457
518
|
type: "SET_UI_STATE",
|
|
458
519
|
payload: { isOpen: !1 }
|
|
459
520
|
});
|
|
460
|
-
}, []),
|
|
521
|
+
}, []), L = y((e) => {
|
|
461
522
|
n({
|
|
462
523
|
type: "SET_UI_STATE",
|
|
463
524
|
payload: { currentView: e }
|
|
464
525
|
});
|
|
465
|
-
}, []),
|
|
466
|
-
if (!
|
|
526
|
+
}, []), B = y(async (e, o) => {
|
|
527
|
+
if (!s || !f)
|
|
467
528
|
return;
|
|
468
|
-
const
|
|
469
|
-
if (
|
|
529
|
+
const c = window.__notificationSDK?.config;
|
|
530
|
+
if (c) {
|
|
531
|
+
if (!e)
|
|
532
|
+
throw new Error("notificationId is required");
|
|
470
533
|
try {
|
|
471
|
-
switch (
|
|
534
|
+
switch (o.type) {
|
|
472
535
|
case "mark_read":
|
|
473
|
-
await
|
|
536
|
+
await s.inbox.markAsRead(e, c.tenantId, c.environmentId, c.subscriberId);
|
|
474
537
|
break;
|
|
475
538
|
case "mark_unread":
|
|
476
|
-
await
|
|
539
|
+
await s.inbox.markAsUnread(e, c.tenantId, c.environmentId, c.subscriberId);
|
|
477
540
|
break;
|
|
478
541
|
case "archive":
|
|
479
|
-
await
|
|
542
|
+
await s.inbox.archive(e, c.tenantId, c.environmentId, c.subscriberId);
|
|
480
543
|
break;
|
|
481
544
|
case "delete":
|
|
482
|
-
await
|
|
545
|
+
await s.inbox.delete(e, c.tenantId, c.environmentId, c.subscriberId);
|
|
483
546
|
break;
|
|
484
547
|
default:
|
|
485
|
-
|
|
548
|
+
o.handler && await o.handler(e);
|
|
486
549
|
break;
|
|
487
550
|
}
|
|
488
|
-
switch (
|
|
551
|
+
switch (o.type) {
|
|
489
552
|
case "mark_read":
|
|
490
553
|
n({
|
|
491
554
|
type: "UPDATE_NOTIFICATION",
|
|
@@ -511,109 +574,110 @@ const te = () => window.__notificationSDK?.client, ne = ({
|
|
|
511
574
|
});
|
|
512
575
|
break;
|
|
513
576
|
}
|
|
514
|
-
} catch (
|
|
515
|
-
|
|
577
|
+
} catch (I) {
|
|
578
|
+
a && a(I);
|
|
516
579
|
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
580
|
+
}
|
|
581
|
+
}, [s]);
|
|
582
|
+
return b(() => {
|
|
583
|
+
if (!s || !f) return;
|
|
520
584
|
(async () => {
|
|
521
585
|
try {
|
|
522
586
|
n({
|
|
523
587
|
type: "SET_UI_STATE",
|
|
524
588
|
payload: { isLoading: !0 }
|
|
525
589
|
});
|
|
526
|
-
const
|
|
527
|
-
if (!
|
|
590
|
+
const o = window.__notificationSDK?.config;
|
|
591
|
+
if (!o)
|
|
528
592
|
throw new Error("SDK configuration not available");
|
|
529
|
-
const
|
|
593
|
+
const c = x(), h = ((await s.inbox.getRenderedNotifications(
|
|
530
594
|
{
|
|
531
595
|
channel: "in_app",
|
|
532
596
|
limit: 50,
|
|
533
597
|
offset: 0
|
|
534
598
|
},
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
599
|
+
o.tenantId,
|
|
600
|
+
o.environmentId,
|
|
601
|
+
o.subscriberId
|
|
538
602
|
))?.items || []).map(
|
|
539
|
-
(
|
|
603
|
+
(S) => c.toWidgetNotification(S)
|
|
540
604
|
);
|
|
541
605
|
n({
|
|
542
606
|
type: "SET_NOTIFICATIONS",
|
|
543
|
-
payload:
|
|
607
|
+
payload: h
|
|
544
608
|
}), n({
|
|
545
609
|
type: "SET_UI_STATE",
|
|
546
610
|
payload: { isLoading: !1, error: null }
|
|
547
611
|
});
|
|
548
|
-
} catch (
|
|
612
|
+
} catch (o) {
|
|
549
613
|
n({
|
|
550
614
|
type: "SET_UI_STATE",
|
|
551
615
|
payload: {
|
|
552
616
|
isLoading: !1,
|
|
553
|
-
error:
|
|
617
|
+
error: o
|
|
554
618
|
}
|
|
555
|
-
}),
|
|
619
|
+
}), a && a(o);
|
|
556
620
|
}
|
|
557
621
|
})();
|
|
558
|
-
}, [
|
|
559
|
-
|
|
560
|
-
}), [
|
|
561
|
-
if (!
|
|
622
|
+
}, [s, f, a]), b(() => (s && f && W(), () => {
|
|
623
|
+
F();
|
|
624
|
+
}), [s]), b(() => {
|
|
625
|
+
if (!s || !f || i.websocket.connected) return;
|
|
562
626
|
const e = setInterval(async () => {
|
|
563
627
|
try {
|
|
564
|
-
const
|
|
565
|
-
if (!
|
|
628
|
+
const o = window.__notificationSDK?.config;
|
|
629
|
+
if (!o)
|
|
566
630
|
return;
|
|
567
|
-
const
|
|
631
|
+
const c = x(), h = ((await s.inbox.getRenderedNotifications(
|
|
568
632
|
{
|
|
569
633
|
channel: "in_app",
|
|
570
634
|
limit: 50,
|
|
571
635
|
offset: 0
|
|
572
636
|
},
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
637
|
+
o.tenantId,
|
|
638
|
+
o.environmentId,
|
|
639
|
+
o.subscriberId
|
|
576
640
|
))?.items || []).map(
|
|
577
|
-
(
|
|
641
|
+
(S) => c.toWidgetNotification(S)
|
|
578
642
|
);
|
|
579
643
|
n({
|
|
580
644
|
type: "SET_NOTIFICATIONS",
|
|
581
|
-
payload:
|
|
645
|
+
payload: h
|
|
582
646
|
});
|
|
583
647
|
} catch {
|
|
584
648
|
}
|
|
585
649
|
}, 3e4);
|
|
586
650
|
return () => clearInterval(e);
|
|
587
|
-
}, [
|
|
588
|
-
const e = (
|
|
589
|
-
if (
|
|
651
|
+
}, [s, i.websocket.connected]), b(() => {
|
|
652
|
+
const e = (o) => {
|
|
653
|
+
if (o.key === "notification_widget_sync" && o.newValue)
|
|
590
654
|
try {
|
|
591
|
-
const
|
|
592
|
-
|
|
655
|
+
const c = JSON.parse(o.newValue);
|
|
656
|
+
A(c);
|
|
593
657
|
} catch {
|
|
594
658
|
}
|
|
595
659
|
};
|
|
596
660
|
return window.addEventListener("storage", e), () => window.removeEventListener("storage", e);
|
|
597
|
-
}, [
|
|
661
|
+
}, [A]), b(() => {
|
|
598
662
|
n({
|
|
599
663
|
type: "SET_UI_STATE",
|
|
600
|
-
payload: { isLoading:
|
|
664
|
+
payload: { isLoading: _ }
|
|
601
665
|
});
|
|
602
|
-
}, [
|
|
603
|
-
const e =
|
|
666
|
+
}, [_]), b(() => {
|
|
667
|
+
const e = m || K || w;
|
|
604
668
|
e && n({
|
|
605
669
|
type: "SET_UI_STATE",
|
|
606
670
|
payload: { error: e }
|
|
607
671
|
});
|
|
608
|
-
}, [
|
|
672
|
+
}, [m, K, w]), !f && !m ? /* @__PURE__ */ d(
|
|
609
673
|
"div",
|
|
610
674
|
{
|
|
611
|
-
className: `relative inline-block ${
|
|
675
|
+
className: `relative inline-block ${p}`,
|
|
612
676
|
"data-widget-size": r || "small",
|
|
613
677
|
"data-theme": l,
|
|
614
678
|
"data-testid": "notification-widget",
|
|
615
|
-
children: /* @__PURE__ */ d(
|
|
616
|
-
|
|
679
|
+
children: /* @__PURE__ */ d(O, { componentName: "BellComponent", children: /* @__PURE__ */ d(
|
|
680
|
+
D,
|
|
617
681
|
{
|
|
618
682
|
unreadCount: 0,
|
|
619
683
|
onClick: () => {
|
|
@@ -623,26 +687,26 @@ const te = () => window.__notificationSDK?.client, ne = ({
|
|
|
623
687
|
}
|
|
624
688
|
) })
|
|
625
689
|
}
|
|
626
|
-
) :
|
|
690
|
+
) : m ? /* @__PURE__ */ d(
|
|
627
691
|
"div",
|
|
628
692
|
{
|
|
629
|
-
className: `relative inline-block ${
|
|
693
|
+
className: `relative inline-block ${p}`,
|
|
630
694
|
"data-widget-size": r || "small",
|
|
631
695
|
"data-theme": l,
|
|
632
696
|
"data-testid": "notification-widget",
|
|
633
697
|
children: /* @__PURE__ */ d(
|
|
634
|
-
|
|
698
|
+
O,
|
|
635
699
|
{
|
|
636
700
|
componentName: "BellComponent",
|
|
637
701
|
fallback: /* @__PURE__ */ d(
|
|
638
|
-
|
|
702
|
+
X,
|
|
639
703
|
{
|
|
640
|
-
error:
|
|
704
|
+
error: m.message,
|
|
641
705
|
onRetry: () => window.location.reload()
|
|
642
706
|
}
|
|
643
707
|
),
|
|
644
708
|
children: /* @__PURE__ */ d(
|
|
645
|
-
|
|
709
|
+
D,
|
|
646
710
|
{
|
|
647
711
|
unreadCount: 0,
|
|
648
712
|
onClick: () => {
|
|
@@ -654,16 +718,16 @@ const te = () => window.__notificationSDK?.client, ne = ({
|
|
|
654
718
|
}
|
|
655
719
|
)
|
|
656
720
|
}
|
|
657
|
-
) : /* @__PURE__ */
|
|
721
|
+
) : /* @__PURE__ */ k(
|
|
658
722
|
"div",
|
|
659
723
|
{
|
|
660
|
-
className: `relative inline-block ${
|
|
724
|
+
className: `relative inline-block ${p}`,
|
|
661
725
|
"data-widget-size": r || "small",
|
|
662
726
|
"data-theme": l,
|
|
663
727
|
"data-testid": "notification-widget",
|
|
664
728
|
children: [
|
|
665
|
-
/* @__PURE__ */ d(
|
|
666
|
-
|
|
729
|
+
/* @__PURE__ */ d(O, { componentName: "BellComponent", children: /* @__PURE__ */ d(
|
|
730
|
+
D,
|
|
667
731
|
{
|
|
668
732
|
unreadCount: i.unreadCount,
|
|
669
733
|
onClick: P,
|
|
@@ -672,23 +736,23 @@ const te = () => window.__notificationSDK?.client, ne = ({
|
|
|
672
736
|
}
|
|
673
737
|
) }),
|
|
674
738
|
/* @__PURE__ */ d(
|
|
675
|
-
|
|
739
|
+
O,
|
|
676
740
|
{
|
|
677
741
|
componentName: "InboxPopover",
|
|
678
|
-
fallback: /* @__PURE__ */ d(
|
|
742
|
+
fallback: /* @__PURE__ */ d(Z, { message: "Unable to load notifications" }),
|
|
679
743
|
children: /* @__PURE__ */ d(
|
|
680
|
-
|
|
744
|
+
Y,
|
|
681
745
|
{
|
|
682
746
|
isOpen: i.ui.isOpen,
|
|
683
|
-
onClose:
|
|
747
|
+
onClose: U,
|
|
684
748
|
position: t,
|
|
685
749
|
currentView: i.ui.currentView,
|
|
686
|
-
onViewChange:
|
|
750
|
+
onViewChange: L,
|
|
687
751
|
notifications: i.notifications,
|
|
688
|
-
onNotificationAction:
|
|
752
|
+
onNotificationAction: B,
|
|
689
753
|
preferences: i.preferences,
|
|
690
|
-
onPreferenceChange:
|
|
691
|
-
isPreferencesLoading:
|
|
754
|
+
onPreferenceChange: v,
|
|
755
|
+
isPreferencesLoading: _
|
|
692
756
|
}
|
|
693
757
|
)
|
|
694
758
|
}
|
|
@@ -696,18 +760,18 @@ const te = () => window.__notificationSDK?.client, ne = ({
|
|
|
696
760
|
]
|
|
697
761
|
}
|
|
698
762
|
);
|
|
699
|
-
},
|
|
763
|
+
}, ye = ({
|
|
700
764
|
sdkConfig: t,
|
|
701
765
|
...r
|
|
702
|
-
}) => /* @__PURE__ */ d(
|
|
766
|
+
}) => /* @__PURE__ */ d(ne, { onError: r.onError, children: /* @__PURE__ */ d(de, { config: t, children: /* @__PURE__ */ d(fe, { ...r }) }) }), be = "3.0.0", ge = "@edusight/notification-widget";
|
|
703
767
|
export {
|
|
704
|
-
|
|
705
|
-
|
|
768
|
+
D as BellComponent,
|
|
769
|
+
Y as InboxPopover,
|
|
706
770
|
Te as NotificationItem,
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
771
|
+
ye as NotificationWidget,
|
|
772
|
+
ne as NotificationWidgetErrorBoundary,
|
|
773
|
+
_e as PreferencesView,
|
|
774
|
+
be as VERSION,
|
|
775
|
+
ge as WIDGET_NAME
|
|
712
776
|
};
|
|
713
777
|
//# sourceMappingURL=index.esm.js.map
|