@edusight/notification-widget 1.0.32 → 1.0.35

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/index.esm.js CHANGED
@@ -1,10 +1,10 @@
1
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";
2
+ import M, { Component as V, useState as C, useCallback as g, useEffect as y, createContext as z, useReducer as q, useRef as $, useContext as H } from "react";
3
3
  import { io as J } from "socket.io-client";
4
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-D8XxiFEB.js";
6
- import { N as Te, P as _e } from "./components-D8XxiFEB.js";
7
- import { u as ee, c as x } from "./hooks-BTG0z6yd.js";
5
+ import { M as G, a as Q, C as O, B as x, S as X, I as Y, L as Z } from "./components-Dq8aSwWR.js";
6
+ import { N as Te, P as _e } from "./components-Dq8aSwWR.js";
7
+ import { u as ee, c as D } from "./hooks-BTG0z6yd.js";
8
8
  const te = ({ error: t, onRetry: r }) => /* @__PURE__ */ k(
9
9
  "div",
10
10
  {
@@ -113,24 +113,24 @@ class ne extends V {
113
113
  ) : this.props.children;
114
114
  }
115
115
  }
116
- const re = () => window.__notificationSDK?.client, ie = ({
116
+ const re = () => window.__notificationSDK?.client, oe = ({
117
117
  onPreferencesLoaded: t,
118
118
  onError: r
119
119
  }) => {
120
- const l = re(), [p, a] = C(!0), [i, n] = C(null), [s, f] = C(null), m = y(async () => {
120
+ const l = re(), [p, a] = C(!0), [o, n] = C(null), [s, f] = C(null), w = g(async () => {
121
121
  try {
122
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: g, tenantId: T, environmentId: w } = u;
128
- if (!g || !T || !w)
127
+ const { subscriberId: b, tenantId: T, environmentId: m } = u;
128
+ if (!b || !T || !m)
129
129
  throw new Error("SubscriberId, TenantId or EnvironmentId not available in config");
130
130
  const E = await l.preferences.get(
131
131
  T,
132
- g,
133
- w
132
+ b,
133
+ m
134
134
  ), N = {
135
135
  channels: {
136
136
  email: E.emailEnabled ?? !0,
@@ -162,9 +162,9 @@ const re = () => window.__notificationSDK?.client, ie = ({
162
162
  });
163
163
  }), f(N), t(N);
164
164
  } catch (u) {
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 = {
165
+ const b = u instanceof Error ? u : new Error("Failed to load preferences");
166
+ u?.response?.status === 404 || u?.status === 404 || (n(b), r?.(b));
167
+ const m = {
168
168
  channels: {
169
169
  email: !0,
170
170
  push: !0,
@@ -181,57 +181,56 @@ const re = () => window.__notificationSDK?.client, ie = ({
181
181
  weekdays: [!0, !0, !0, !0, !0, !1, !1]
182
182
  }
183
183
  };
184
- f(w), t(w);
184
+ f(m), t(m);
185
185
  } finally {
186
186
  a(!1);
187
187
  }
188
188
  }, [l, t, r]);
189
- return b(() => {
190
- l && m();
191
- }, [l, m]), {
189
+ return y(() => {
190
+ l && w();
191
+ }, [l, w]), {
192
192
  isLoading: p,
193
- error: i,
193
+ error: o,
194
194
  preferences: s
195
195
  };
196
- }, oe = () => window.__notificationSDK?.client, ae = () => {
197
- const t = oe(), [r, l] = C([]), [p, a] = C(!0), [i, n] = C(null), s = y(async () => {
196
+ }, ie = () => window.__notificationSDK?.client, ae = () => {
197
+ const t = ie(), [r, l] = C([]), [p, a] = C(!0), [o, n] = C(null), s = g(async () => {
198
198
  try {
199
199
  if (a(!0), n(null), !t)
200
- throw new Error("Notification client not available");
200
+ throw new Error("[useWorkflows] Notification client not available");
201
201
  const f = window.__notificationSDK?.config;
202
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");
203
+ throw new Error("[useWorkflows] SDK configuration not available");
204
+ const { tenantId: w, environmentId: u } = f;
205
+ if (!w || !u)
206
+ throw new Error("[useWorkflows] TenantId or EnvironmentId not available in config");
207
207
  const T = ((await t.workflows.list(
208
208
  { status: "active" },
209
- // Only load active workflows
210
- m,
209
+ w,
211
210
  u
212
- ))?.workflows || []).map((w) => ({
213
- workflowId: w.workflowId,
214
- name: w.name || w.workflowId,
215
- description: w.description
211
+ ))?.workflows || []).map((m) => ({
212
+ workflowId: m.workflowId,
213
+ name: m.name || m.workflowId,
214
+ description: m.description
216
215
  }));
217
216
  l(T);
218
217
  } catch (f) {
219
- const m = f instanceof Error ? f : new Error("Failed to load workflows");
220
- n(m), l([]);
218
+ const w = f instanceof Error ? f : new Error("Failed to load workflows");
219
+ n(w), l([]);
221
220
  } finally {
222
221
  a(!1);
223
222
  }
224
223
  }, [t]);
225
- return b(() => {
224
+ return y(() => {
226
225
  t && s();
227
226
  }, [t, s]), {
228
227
  workflows: r,
229
228
  isLoading: p,
230
- error: i,
229
+ error: o,
231
230
  refetch: s
232
231
  };
233
- }, R = z(null), se = () => {
234
- const t = H(R);
232
+ }, W = z(null), se = () => {
233
+ const t = H(W);
235
234
  if (!t)
236
235
  throw new Error("useSDK must be used within a NotificationWidget");
237
236
  return t;
@@ -275,7 +274,7 @@ const re = () => window.__notificationSDK?.client, ie = ({
275
274
  isInitialized: !1,
276
275
  error: null
277
276
  });
278
- return b(() => {
277
+ return y(() => {
279
278
  let a = !0;
280
279
  return (async () => {
281
280
  try {
@@ -309,37 +308,37 @@ const re = () => window.__notificationSDK?.client, ie = ({
309
308
  })(), () => {
310
309
  a = !1;
311
310
  };
312
- }, [t]), /* @__PURE__ */ d(R.Provider, { value: l, children: r });
311
+ }, [t]), /* @__PURE__ */ d(W.Provider, { value: l, children: r });
313
312
  }, le = (t, r) => {
314
313
  switch (r.type) {
315
314
  case "SET_NOTIFICATIONS":
316
315
  return {
317
316
  ...t,
318
317
  notifications: r.payload,
319
- unreadCount: r.payload.filter((i) => !i.isRead).length
318
+ unreadCount: r.payload.filter((o) => !o.isRead).length
320
319
  };
321
320
  case "ADD_NOTIFICATION":
322
321
  const l = [r.payload, ...t.notifications];
323
322
  return {
324
323
  ...t,
325
324
  notifications: l,
326
- unreadCount: l.filter((i) => !i.isRead).length
325
+ unreadCount: l.filter((o) => !o.isRead).length
327
326
  };
328
327
  case "UPDATE_NOTIFICATION":
329
328
  const p = t.notifications.map(
330
- (i) => i.id === r.payload.id ? { ...i, ...r.payload.updates } : i
329
+ (o) => o.id === r.payload.id ? { ...o, ...r.payload.updates } : o
331
330
  );
332
331
  return {
333
332
  ...t,
334
333
  notifications: p,
335
- unreadCount: p.filter((i) => !i.isRead).length
334
+ unreadCount: p.filter((o) => !o.isRead).length
336
335
  };
337
336
  case "DELETE_NOTIFICATION":
338
- const a = t.notifications.filter((i) => i.id !== r.payload);
337
+ const a = t.notifications.filter((o) => o.id !== r.payload);
339
338
  return {
340
339
  ...t,
341
340
  notifications: a,
342
- unreadCount: a.filter((i) => !i.isRead).length
341
+ unreadCount: a.filter((o) => !o.isRead).length
343
342
  };
344
343
  case "SET_PREFERENCES":
345
344
  return {
@@ -366,26 +365,26 @@ const re = () => window.__notificationSDK?.client, ie = ({
366
365
  className: p = "",
367
366
  onError: a
368
367
  }) => {
369
- const [i, n] = q(le, ce), { client: s, isInitialized: f, error: m } = se(), u = $(null), g = y((e) => {
368
+ const [o, n] = q(le, ce), { client: s, isInitialized: f, error: w } = se(), u = $(null), b = g((e) => {
370
369
  n({
371
370
  type: "SET_PREFERENCES",
372
371
  payload: e
373
372
  });
374
- }, []), T = y((e) => {
373
+ }, []), T = g((e) => {
375
374
  a && a(e);
376
- }, [a]), { error: w } = ie({
377
- onPreferencesLoaded: g,
375
+ }, [a]), { error: m } = oe({
376
+ onPreferencesLoaded: b,
378
377
  onError: T
379
378
  }), { workflows: E, isLoading: N } = ae(), { updatePreference: v, isSaving: _, error: K } = ee({
380
- preferences: i.preferences,
381
- onPreferencesChange: g,
379
+ preferences: o.preferences,
380
+ onPreferencesChange: b,
382
381
  onError: T
383
382
  });
384
- b(() => {
383
+ y(() => {
385
384
  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,
385
+ const e = E.map((i) => o.preferences.subscriptions.find((I) => I.workflowId === i.workflowId) || {
386
+ workflowId: i.workflowId,
387
+ name: i.name,
389
388
  enabled: !0,
390
389
  // Default to enabled
391
390
  channels: {
@@ -395,24 +394,24 @@ const re = () => window.__notificationSDK?.client, ie = ({
395
394
  inApp: !0
396
395
  }
397
396
  });
398
- JSON.stringify(e) !== JSON.stringify(i.preferences.subscriptions) && n({
397
+ JSON.stringify(e) !== JSON.stringify(o.preferences.subscriptions) && n({
399
398
  type: "SET_PREFERENCES",
400
399
  payload: {
401
- ...i.preferences,
400
+ ...o.preferences,
402
401
  subscriptions: e
403
402
  }
404
403
  });
405
404
  }
406
- }, [E, N, i.preferences]);
407
- const A = y((e) => {
405
+ }, [E, N, o.preferences]);
406
+ const A = g((e) => {
408
407
  try {
409
- const o = x();
408
+ const i = D();
410
409
  switch (e.type) {
411
410
  case "notification_received": {
412
411
  const c = e.data;
413
- if (!o.validateWebSocketPayload(c))
412
+ if (!i.validateWebSocketPayload(c))
414
413
  break;
415
- const I = o.toWidgetNotificationFromWebSocket(c);
414
+ const I = i.toWidgetNotificationFromWebSocket(c);
416
415
  n({
417
416
  type: "ADD_NOTIFICATION",
418
417
  payload: I
@@ -444,7 +443,7 @@ const re = () => window.__notificationSDK?.client, ie = ({
444
443
  }
445
444
  } catch {
446
445
  }
447
- }, []), W = y(async () => {
446
+ }, []), R = g(async () => {
448
447
  if (!(!s || !f || u.current))
449
448
  try {
450
449
  n({
@@ -499,7 +498,7 @@ const re = () => window.__notificationSDK?.client, ie = ({
499
498
  payload: { connected: !1, reconnecting: !1 }
500
499
  }), a && a(e);
501
500
  }
502
- }, [s, f, A, a]), F = y(() => {
501
+ }, [s, f, A, a]), F = g(() => {
503
502
  if (u.current)
504
503
  try {
505
504
  u.current.disconnect && u.current.disconnect(), u.current = null, n({
@@ -508,22 +507,22 @@ const re = () => window.__notificationSDK?.client, ie = ({
508
507
  });
509
508
  } catch {
510
509
  }
511
- }, []), P = y(() => {
510
+ }, []), P = g(() => {
512
511
  n({
513
512
  type: "SET_UI_STATE",
514
- payload: { isOpen: !i.ui.isOpen }
513
+ payload: { isOpen: !o.ui.isOpen }
515
514
  });
516
- }, [i.ui.isOpen]), U = y(() => {
515
+ }, [o.ui.isOpen]), U = g(() => {
517
516
  n({
518
517
  type: "SET_UI_STATE",
519
518
  payload: { isOpen: !1 }
520
519
  });
521
- }, []), L = y((e) => {
520
+ }, []), L = g((e) => {
522
521
  n({
523
522
  type: "SET_UI_STATE",
524
523
  payload: { currentView: e }
525
524
  });
526
- }, []), B = y(async (e, o) => {
525
+ }, []), B = g(async (e, i) => {
527
526
  if (!s || !f)
528
527
  return;
529
528
  const c = window.__notificationSDK?.config;
@@ -531,7 +530,7 @@ const re = () => window.__notificationSDK?.client, ie = ({
531
530
  if (!e)
532
531
  throw new Error("notificationId is required");
533
532
  try {
534
- switch (o.type) {
533
+ switch (i.type) {
535
534
  case "mark_read":
536
535
  await s.inbox.markAsRead(e, c.tenantId, c.environmentId, c.subscriberId);
537
536
  break;
@@ -545,10 +544,10 @@ const re = () => window.__notificationSDK?.client, ie = ({
545
544
  await s.inbox.delete(e, c.tenantId, c.environmentId, c.subscriberId);
546
545
  break;
547
546
  default:
548
- o.handler && await o.handler(e);
547
+ i.handler && await i.handler(e);
549
548
  break;
550
549
  }
551
- switch (o.type) {
550
+ switch (i.type) {
552
551
  case "mark_read":
553
552
  n({
554
553
  type: "UPDATE_NOTIFICATION",
@@ -579,7 +578,7 @@ const re = () => window.__notificationSDK?.client, ie = ({
579
578
  }
580
579
  }
581
580
  }, [s]);
582
- return b(() => {
581
+ return y(() => {
583
582
  if (!s || !f) return;
584
583
  (async () => {
585
584
  try {
@@ -587,18 +586,18 @@ const re = () => window.__notificationSDK?.client, ie = ({
587
586
  type: "SET_UI_STATE",
588
587
  payload: { isLoading: !0 }
589
588
  });
590
- const o = window.__notificationSDK?.config;
591
- if (!o)
589
+ const i = window.__notificationSDK?.config;
590
+ if (!i)
592
591
  throw new Error("SDK configuration not available");
593
- const c = x(), h = ((await s.inbox.getRenderedNotifications(
592
+ const c = D(), h = ((await s.inbox.getRenderedNotifications(
594
593
  {
595
594
  channel: "in_app",
596
595
  limit: 50,
597
596
  offset: 0
598
597
  },
599
- o.tenantId,
600
- o.environmentId,
601
- o.subscriberId
598
+ i.tenantId,
599
+ i.environmentId,
600
+ i.subscriberId
602
601
  ))?.items || []).map(
603
602
  (S) => c.toWidgetNotification(S)
604
603
  );
@@ -609,34 +608,34 @@ const re = () => window.__notificationSDK?.client, ie = ({
609
608
  type: "SET_UI_STATE",
610
609
  payload: { isLoading: !1, error: null }
611
610
  });
612
- } catch (o) {
611
+ } catch (i) {
613
612
  n({
614
613
  type: "SET_UI_STATE",
615
614
  payload: {
616
615
  isLoading: !1,
617
- error: o
616
+ error: i
618
617
  }
619
- }), a && a(o);
618
+ }), a && a(i);
620
619
  }
621
620
  })();
622
- }, [s, f, a]), b(() => (s && f && W(), () => {
621
+ }, [s, f, a]), y(() => (s && f && R(), () => {
623
622
  F();
624
- }), [s]), b(() => {
625
- if (!s || !f || i.websocket.connected) return;
623
+ }), [s]), y(() => {
624
+ if (!s || !f || o.websocket.connected) return;
626
625
  const e = setInterval(async () => {
627
626
  try {
628
- const o = window.__notificationSDK?.config;
629
- if (!o)
627
+ const i = window.__notificationSDK?.config;
628
+ if (!i)
630
629
  return;
631
- const c = x(), h = ((await s.inbox.getRenderedNotifications(
630
+ const c = D(), h = ((await s.inbox.getRenderedNotifications(
632
631
  {
633
632
  channel: "in_app",
634
633
  limit: 50,
635
634
  offset: 0
636
635
  },
637
- o.tenantId,
638
- o.environmentId,
639
- o.subscriberId
636
+ i.tenantId,
637
+ i.environmentId,
638
+ i.subscriberId
640
639
  ))?.items || []).map(
641
640
  (S) => c.toWidgetNotification(S)
642
641
  );
@@ -648,36 +647,37 @@ const re = () => window.__notificationSDK?.client, ie = ({
648
647
  }
649
648
  }, 3e4);
650
649
  return () => clearInterval(e);
651
- }, [s, i.websocket.connected]), b(() => {
652
- const e = (o) => {
653
- if (o.key === "notification_widget_sync" && o.newValue)
650
+ }, [s, o.websocket.connected]), y(() => {
651
+ const e = (i) => {
652
+ if (i.key === "notification_widget_sync" && i.newValue)
654
653
  try {
655
- const c = JSON.parse(o.newValue);
654
+ const c = JSON.parse(i.newValue);
656
655
  A(c);
657
656
  } catch {
658
657
  }
659
658
  };
660
659
  return window.addEventListener("storage", e), () => window.removeEventListener("storage", e);
661
- }, [A]), b(() => {
660
+ }, [A]), y(() => {
662
661
  n({
663
662
  type: "SET_UI_STATE",
664
663
  payload: { isLoading: _ }
665
664
  });
666
- }, [_]), b(() => {
667
- const e = m || K || w;
665
+ }, [_]), y(() => {
666
+ const e = w || K || m;
668
667
  e && n({
669
668
  type: "SET_UI_STATE",
670
669
  payload: { error: e }
671
670
  });
672
- }, [m, K, w]), !f && !m ? /* @__PURE__ */ d(
671
+ }, [w, K, m]), !f && !w ? /* @__PURE__ */ d(
673
672
  "div",
674
673
  {
675
- className: `relative inline-block ${p}`,
674
+ className: `mx-widget-root relative inline-block ${p}`,
675
+ "data-mx-widget": "root",
676
676
  "data-widget-size": r || "small",
677
677
  "data-theme": l,
678
678
  "data-testid": "notification-widget",
679
679
  children: /* @__PURE__ */ d(O, { componentName: "BellComponent", children: /* @__PURE__ */ d(
680
- D,
680
+ x,
681
681
  {
682
682
  unreadCount: 0,
683
683
  onClick: () => {
@@ -687,10 +687,11 @@ const re = () => window.__notificationSDK?.client, ie = ({
687
687
  }
688
688
  ) })
689
689
  }
690
- ) : m ? /* @__PURE__ */ d(
690
+ ) : w ? /* @__PURE__ */ d(
691
691
  "div",
692
692
  {
693
- className: `relative inline-block ${p}`,
693
+ className: `mx-widget-root relative inline-block ${p}`,
694
+ "data-mx-widget": "root",
694
695
  "data-widget-size": r || "small",
695
696
  "data-theme": l,
696
697
  "data-testid": "notification-widget",
@@ -701,12 +702,12 @@ const re = () => window.__notificationSDK?.client, ie = ({
701
702
  fallback: /* @__PURE__ */ d(
702
703
  X,
703
704
  {
704
- error: m.message,
705
+ error: w.message,
705
706
  onRetry: () => window.location.reload()
706
707
  }
707
708
  ),
708
709
  children: /* @__PURE__ */ d(
709
- D,
710
+ x,
710
711
  {
711
712
  unreadCount: 0,
712
713
  onClick: () => {
@@ -721,18 +722,19 @@ const re = () => window.__notificationSDK?.client, ie = ({
721
722
  ) : /* @__PURE__ */ k(
722
723
  "div",
723
724
  {
724
- className: `relative inline-block ${p}`,
725
+ className: `mx-widget-root relative inline-block ${p}`,
726
+ "data-mx-widget": "root",
725
727
  "data-widget-size": r || "small",
726
728
  "data-theme": l,
727
729
  "data-testid": "notification-widget",
728
730
  children: [
729
731
  /* @__PURE__ */ d(O, { componentName: "BellComponent", children: /* @__PURE__ */ d(
730
- D,
732
+ x,
731
733
  {
732
- unreadCount: i.unreadCount,
734
+ unreadCount: o.unreadCount,
733
735
  onClick: P,
734
736
  size: r,
735
- disabled: i.ui.isLoading
737
+ disabled: o.ui.isLoading
736
738
  }
737
739
  ) }),
738
740
  /* @__PURE__ */ d(
@@ -743,14 +745,14 @@ const re = () => window.__notificationSDK?.client, ie = ({
743
745
  children: /* @__PURE__ */ d(
744
746
  Y,
745
747
  {
746
- isOpen: i.ui.isOpen,
748
+ isOpen: o.ui.isOpen,
747
749
  onClose: U,
748
750
  position: t,
749
- currentView: i.ui.currentView,
751
+ currentView: o.ui.currentView,
750
752
  onViewChange: L,
751
- notifications: i.notifications,
753
+ notifications: o.notifications,
752
754
  onNotificationAction: B,
753
- preferences: i.preferences,
755
+ preferences: o.preferences,
754
756
  onPreferenceChange: v,
755
757
  isPreferencesLoading: _
756
758
  }
@@ -760,18 +762,18 @@ const re = () => window.__notificationSDK?.client, ie = ({
760
762
  ]
761
763
  }
762
764
  );
763
- }, ye = ({
765
+ }, ge = ({
764
766
  sdkConfig: t,
765
767
  ...r
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";
768
+ }) => /* @__PURE__ */ d(ne, { onError: r.onError, children: /* @__PURE__ */ d(de, { config: t, children: /* @__PURE__ */ d(fe, { ...r }) }) }), ye = "3.0.0", be = "@edusight/notification-widget";
767
769
  export {
768
- D as BellComponent,
770
+ x as BellComponent,
769
771
  Y as InboxPopover,
770
772
  Te as NotificationItem,
771
- ye as NotificationWidget,
773
+ ge as NotificationWidget,
772
774
  ne as NotificationWidgetErrorBoundary,
773
775
  _e as PreferencesView,
774
- be as VERSION,
775
- ge as WIDGET_NAME
776
+ ye as VERSION,
777
+ be as WIDGET_NAME
776
778
  };
777
779
  //# sourceMappingURL=index.esm.js.map