@notificationapi/react 0.0.26 → 0.0.28

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/README.md CHANGED
@@ -1,3 +1,25 @@
1
+ [![NotificationAPI](./ReadmeLogo.svg)](https://notificationapi.com)
2
+
3
+ The React SDK is mainly used for displaying In-App Notifications and allowing users to see and change their Notification Preferences.
4
+
5
+ # Docs
6
+
7
+ Please refer to our [documentations](https://docs.notificationapi.com).
8
+
9
+ # Development
10
+
11
+ 1. Install dependencies:
12
+
13
+ ```
14
+ npm install
15
+ ```
16
+
17
+ 2. Run the example application:
18
+
19
+ ```
20
+ npm run dev
21
+ ```
22
+
1
23
  # React + TypeScript + Vite
2
24
 
3
25
  This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
@@ -20,11 +42,85 @@ export default {
20
42
  ecmaVersion: 'latest',
21
43
  sourceType: 'module',
22
44
  project: ['./tsconfig.json', './tsconfig.node.json'],
23
- tsconfigRootDir: __dirname,
24
- },
25
- }
45
+ tsconfigRootDir: __dirname
46
+ }
47
+ };
26
48
  ```
27
49
 
28
50
  - Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
29
51
  - Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
30
52
  - Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
53
+
54
+ ## Contributing
55
+
56
+ We welcome contributions! To ensure smooth collaboration, please follow these steps:
57
+
58
+ 1. **Clone the Repository**
59
+
60
+ - Fork the repository to your GitHub account.
61
+ - Clone it to your local machine:
62
+
63
+ ```bash
64
+ git clone https://github.com/your-username/repo-name.git
65
+ cd repo-name
66
+ ```
67
+
68
+ 2. **Create a Branch**
69
+
70
+ - Create a new branch for your changes:
71
+
72
+ ```bash
73
+ git checkout -b your-branch-name
74
+ ```
75
+
76
+ 3. **Make Your Changes**
77
+
78
+ - Make your changes in the relevant files.
79
+ - Thoroughly test your changes to ensure they work as expected.
80
+
81
+ 4. **Versioning**
82
+
83
+ - Before committing your changes, update the package version by running:
84
+
85
+ ```bash
86
+ npm version <type>
87
+ ```
88
+
89
+ - **Versioning Types:**
90
+
91
+ - **major**: For breaking changes or large-scale features.
92
+ - **minor**: For adding functionality in a backwards-compatible manner.
93
+ - **patch**: For backwards-compatible bug fixes or small improvements.
94
+
95
+ - For example, to update a patch version:
96
+
97
+ ```bash
98
+ npm version patch
99
+ ```
100
+
101
+ 5. **Commit and Push**
102
+
103
+ - Once you’ve made and tested your changes, commit them with a meaningful message:
104
+
105
+ ```bash
106
+ git add .
107
+ git commit -m "Describe your changes"
108
+ ```
109
+
110
+ - Push your branch to GitHub:
111
+
112
+ ```bash
113
+ git push origin your-branch-name
114
+ ```
115
+
116
+ 6. **Submit a Pull Request**
117
+
118
+ - Create a pull request (PR) on GitHub.
119
+ - Provide a clear description of what your changes do.
120
+ - Link any relevant issues.
121
+
122
+ 7. **Update Documentation**
123
+ - If your changes affect the documentation, please update it accordingly.
124
+ - You can find the documentation repository here: [NotificationAPI Docs](https://github.com/notificationapi-com/docs).
125
+
126
+ Thank you for contributing!
@@ -6185,7 +6185,7 @@ const us = (e) => {
6185
6185
  data: s,
6186
6186
  height: e.maxHeight,
6187
6187
  itemHeight: 47,
6188
- itemKey: "id",
6188
+ itemKey: (u) => u[0].id,
6189
6189
  onScroll: (u) => {
6190
6190
  Math.abs(
6191
6191
  u.currentTarget.scrollHeight - u.currentTarget.scrollTop - e.maxHeight
@@ -1,24 +1,25 @@
1
- import { jsx as i, jsxs as h } from "react/jsx-runtime";
2
- import { Inbox as l } from "./Inbox.js";
1
+ import { jsx as i, jsxs as l } from "react/jsx-runtime";
2
+ import { Inbox as h } from "./Inbox.js";
3
3
  import { UnreadBadge as g } from "./UnreadBadge.js";
4
4
  import { useState as m, useContext as b } from "react";
5
5
  import { NotificationAPIContext as s } from "../Provider/index.js";
6
6
  import { NotificationPreferencesPopup as I } from "../Preferences/NotificationPreferencesPopup.js";
7
7
  import "../Preferences/PreferenceInput.js";
8
- import { R as p } from "../../assets/channelUtils.js";
9
- import { P as S } from "../../assets/index.js";
10
- import { B as P } from "../../assets/button.js";
8
+ import { R as S } from "../../assets/channelUtils.js";
9
+ import { P } from "../../assets/index.js";
10
+ import { B as C } from "../../assets/button.js";
11
11
  const B = (t) => {
12
- var a, r, d, u;
13
- const [c, o] = m(!1), n = b(s);
12
+ var a, r, d, c;
13
+ const [u, o] = m(!1), n = b(s);
14
14
  if (!n)
15
15
  return null;
16
16
  const e = {
17
17
  buttonIcon: t.buttonIcon || /* @__PURE__ */ i(
18
- p,
18
+ S,
19
19
  {
20
20
  style: {
21
- fontSize: t.buttonIconSize || (t.buttonWidth ? t.buttonWidth / 2 : 20)
21
+ fontSize: t.buttonIconSize || (t.buttonWidth ? t.buttonWidth / 2 : 20),
22
+ color: t.iconColor || "#000000"
22
23
  }
23
24
  }
24
25
  ),
@@ -28,6 +29,7 @@ const B = (t) => {
28
29
  popupHeight: t.popupHeight || 600,
29
30
  buttonIconSize: t.buttonIconSize || (t.buttonWidth ? t.buttonWidth / 2 : 20),
30
31
  imageShape: t.imageShape || "circle",
32
+ iconColor: t.iconColor || "#000000",
31
33
  pagination: t.pagination || "INFINITE_SCROLL",
32
34
  pageSize: t.pageSize || 10,
33
35
  pagePosition: t.pagePosition || "top",
@@ -44,10 +46,10 @@ const B = (t) => {
44
46
  button2ClickHandler: ((d = t.header) == null ? void 0 : d.button2ClickHandler) ?? (() => o(!0))
45
47
  },
46
48
  renderers: {
47
- notification: (u = t.renderers) == null ? void 0 : u.notification
49
+ notification: (c = t.renderers) == null ? void 0 : c.notification
48
50
  }
49
51
  };
50
- return /* @__PURE__ */ h(
52
+ return /* @__PURE__ */ l(
51
53
  "div",
52
54
  {
53
55
  style: {
@@ -58,12 +60,12 @@ const B = (t) => {
58
60
  },
59
61
  children: [
60
62
  /* @__PURE__ */ i(
61
- S,
63
+ P,
62
64
  {
63
65
  autoAdjustOverflow: !0,
64
66
  trigger: "click",
65
67
  content: /* @__PURE__ */ i(
66
- l,
68
+ h,
67
69
  {
68
70
  maxHeight: 500,
69
71
  pagination: e.pagination,
@@ -99,7 +101,7 @@ const B = (t) => {
99
101
  },
100
102
  count: e.count,
101
103
  children: /* @__PURE__ */ i(
102
- P,
104
+ C,
103
105
  {
104
106
  icon: e.buttonIcon,
105
107
  style: {
@@ -119,7 +121,7 @@ const B = (t) => {
119
121
  /* @__PURE__ */ i(
120
122
  I,
121
123
  {
122
- open: c,
124
+ open: u,
123
125
  onClose: () => o(!1)
124
126
  }
125
127
  )
@@ -12,6 +12,7 @@ export type NotificationPopupProps = {
12
12
  popupWidth?: number | string;
13
13
  popupHeight?: number;
14
14
  imageShape?: keyof typeof ImageShape;
15
+ iconColor?: string;
15
16
  pagination?: keyof typeof Pagination;
16
17
  pageSize?: number;
17
18
  pagePosition?: 'top' | 'bottom';
@@ -6,20 +6,21 @@ import { useState as b, useContext as I } from "react";
6
6
  import { NotificationPreferencesPopup as P } from "../Preferences/NotificationPreferencesPopup.js";
7
7
  import "../Preferences/PreferenceInput.js";
8
8
  import { Filter as S } from "./interface.js";
9
- import { R as s } from "../../assets/channelUtils.js";
10
- import { P as x } from "../../assets/index.js";
11
- import { B as C } from "../../assets/button.js";
9
+ import { R as x } from "../../assets/channelUtils.js";
10
+ import { P as C } from "../../assets/index.js";
11
+ import { B as s } from "../../assets/button.js";
12
12
  const F = (t) => {
13
- var a, r, d, u;
14
- const [c, o] = b(!1), n = I(p);
13
+ var a, r, c, d;
14
+ const [u, o] = b(!1), n = I(p);
15
15
  if (!n)
16
16
  return null;
17
17
  const e = {
18
18
  buttonIcon: t.buttonIcon || /* @__PURE__ */ i(
19
- s,
19
+ x,
20
20
  {
21
21
  style: {
22
- fontSize: t.buttonIconSize || (t.buttonWidth ? t.buttonWidth / 2 : 20)
22
+ fontSize: t.buttonIconSize || (t.buttonWidth ? t.buttonWidth / 2 : 20),
23
+ color: t.iconColor || "#000000"
23
24
  }
24
25
  }
25
26
  ),
@@ -29,6 +30,7 @@ const F = (t) => {
29
30
  popupHeight: t.popupHeight || 600,
30
31
  buttonIconSize: t.buttonIconSize || (t.buttonWidth ? t.buttonWidth / 2 : 20),
31
32
  imageShape: t.imageShape || "circle",
33
+ iconColor: t.iconColor || "#000000",
32
34
  pagination: t.pagination || "INFINITE_SCROLL",
33
35
  pageSize: t.pageSize || 10,
34
36
  pagePosition: t.pagePosition || "top",
@@ -39,15 +41,15 @@ const F = (t) => {
39
41
  header: {
40
42
  title: (a = t.header) == null ? void 0 : a.title,
41
43
  button1ClickHandler: ((r = t.header) == null ? void 0 : r.button1ClickHandler) ?? n.markAsArchived,
42
- button2ClickHandler: ((d = t.header) == null ? void 0 : d.button2ClickHandler) ?? (() => o(!0))
44
+ button2ClickHandler: ((c = t.header) == null ? void 0 : c.button2ClickHandler) ?? (() => o(!0))
43
45
  },
44
46
  renderers: {
45
- notification: (u = t.renderers) == null ? void 0 : u.notification
47
+ notification: (d = t.renderers) == null ? void 0 : d.notification
46
48
  }
47
49
  };
48
50
  return /* @__PURE__ */ h(f, { children: [
49
51
  /* @__PURE__ */ i(
50
- x,
52
+ C,
51
53
  {
52
54
  autoAdjustOverflow: !0,
53
55
  trigger: "click",
@@ -90,7 +92,7 @@ const F = (t) => {
90
92
  count: e.count,
91
93
  filter: e.filter,
92
94
  children: /* @__PURE__ */ i(
93
- C,
95
+ s,
94
96
  {
95
97
  icon: e.buttonIcon,
96
98
  style: {
@@ -110,7 +112,7 @@ const F = (t) => {
110
112
  /* @__PURE__ */ i(
111
113
  P,
112
114
  {
113
- open: c,
115
+ open: u,
114
116
  onClose: () => o(!1)
115
117
  }
116
118
  )
@@ -26,6 +26,8 @@ type Props = {
26
26
  wsURL?: string;
27
27
  initialLoadMaxCount?: number;
28
28
  initialLoadMaxAge?: Date;
29
+ playSoundOnNewNotification?: boolean;
30
+ newNotificationSoundPath?: string;
29
31
  };
30
32
  export declare const NotificationAPIProvider: React.FunctionComponent<PropsWithChildren<Props>> & {
31
33
  useNotificationAPIContext: typeof useNotificationAPIContext;
@@ -1,15 +1,15 @@
1
- import { jsx as H } from "react/jsx-runtime";
2
- import { createContext as B, useState as N, useCallback as A, useMemo as G, useRef as m, useEffect as L, useContext as J } from "react";
3
- const _ = async (e, c, a, r, f, I, h) => {
4
- const g = z(r, f, I), l = await fetch(
5
- `https://${c}/${r}/users/${encodeURIComponent(
1
+ import { jsx as B } from "react/jsx-runtime";
2
+ import { createContext as F, useState as N, useCallback as b, useMemo as G, useRef as m, useEffect as M, useContext as J } from "react";
3
+ const _ = async (e, c, r, a, f, w, p) => {
4
+ const h = z(a, f, w), l = await fetch(
5
+ `https://${c}/${a}/users/${encodeURIComponent(
6
6
  f
7
- )}/${a}`,
7
+ )}/${r}`,
8
8
  {
9
9
  method: e,
10
- body: JSON.stringify(h),
10
+ body: JSON.stringify(p),
11
11
  headers: {
12
- Authorization: `Basic ${g}`
12
+ Authorization: `Basic ${h}`
13
13
  }
14
14
  }
15
15
  );
@@ -18,7 +18,7 @@ const _ = async (e, c, a, r, f, I, h) => {
18
18
  } catch {
19
19
  return;
20
20
  }
21
- }, z = (e, c, a) => btoa(a ? e + ":" + c + ":" + a : e + ":" + c), M = {
21
+ }, z = (e, c, r) => btoa(r ? e + ":" + c + ":" + r : e + ":" + c), U = {
22
22
  host: "api.notificationapi.com",
23
23
  websocketHost: "ws.notificationapi.com",
24
24
  userId: "",
@@ -31,43 +31,43 @@ const _ = async (e, c, a, r, f, I, h) => {
31
31
  onNewInAppNotifications: void 0,
32
32
  keepWebSocketAliveForSeconds: 86400
33
33
  // 24 hours
34
- }, i = {
35
- config: M,
34
+ }, o = {
35
+ config: U,
36
36
  init: function(e) {
37
- return this.config = { ...M, ...e }, {
37
+ return this.config = { ...U, ...e }, {
38
38
  ...this
39
39
  };
40
40
  },
41
41
  rest: {
42
- generic: function(e, c, a) {
42
+ generic: function(e, c, r) {
43
43
  return _(
44
44
  e,
45
- i.config.host,
45
+ o.config.host,
46
46
  c,
47
- i.config.clientId,
48
- i.config.userId,
49
- i.config.hashedUserId,
50
- a
47
+ o.config.clientId,
48
+ o.config.userId,
49
+ o.config.hashedUserId,
50
+ r
51
51
  );
52
52
  },
53
53
  getNotifications: function(e, c) {
54
- return i.rest.generic(
54
+ return o.rest.generic(
55
55
  "GET",
56
56
  `notifications/INAPP_WEB?count=${c}&before=${e}`
57
57
  );
58
58
  },
59
59
  patchNotifications: function(e) {
60
- return i.rest.generic(
60
+ return o.rest.generic(
61
61
  "PATCH",
62
62
  "notifications/INAPP_WEB",
63
63
  e
64
64
  );
65
65
  },
66
66
  getPreferences: function() {
67
- return i.rest.generic("GET", "preferences");
67
+ return o.rest.generic("GET", "preferences");
68
68
  },
69
69
  postPreferences: function(e) {
70
- return i.rest.generic(
70
+ return o.rest.generic(
71
71
  "POST",
72
72
  "preferences",
73
73
  e
@@ -77,24 +77,24 @@ const _ = async (e, c, a, r, f, I, h) => {
77
77
  websocket: {
78
78
  object: void 0,
79
79
  connect: function() {
80
- let e = `wss://${i.config.websocketHost}?userId=${encodeURIComponent(i.config.userId)}&envId=${i.config.clientId}`;
81
- return i.config.hashedUserId && (e += `&userIdHash=${encodeURIComponent(i.config.hashedUserId)}`), i.websocket.object = new WebSocket(e), i.websocket.object.onmessage = (c) => {
82
- const a = JSON.parse(c.data);
83
- if (!(!a || !a.route) && a.route === "inapp_web/new_notifications") {
84
- const r = a;
85
- i.config.onNewInAppNotifications && i.config.onNewInAppNotifications(
86
- r.payload.notifications
80
+ let e = `wss://${o.config.websocketHost}?userId=${encodeURIComponent(o.config.userId)}&envId=${o.config.clientId}`;
81
+ return o.config.hashedUserId && (e += `&userIdHash=${encodeURIComponent(o.config.hashedUserId)}`), o.websocket.object = new WebSocket(e), o.websocket.object.onmessage = (c) => {
82
+ const r = JSON.parse(c.data);
83
+ if (!(!r || !r.route) && r.route === "inapp_web/new_notifications") {
84
+ const a = r;
85
+ o.config.onNewInAppNotifications && o.config.onNewInAppNotifications(
86
+ a.payload.notifications
87
87
  );
88
88
  }
89
- }, i.websocket.object;
89
+ }, o.websocket.object;
90
90
  },
91
91
  disconnect: function(e) {
92
92
  var c;
93
- i.websocket.object && ((c = i.websocket.object) == null || c.close(), e && e(i.websocket.object));
93
+ o.websocket.object && ((c = o.websocket.object) == null || c.close(), e && e(o.websocket.object));
94
94
  }
95
95
  },
96
96
  openWebSocket: function() {
97
- return i.websocket.connect(() => {
97
+ return o.websocket.connect(() => {
98
98
  setTimeout(
99
99
  () => {
100
100
  this.websocket.disconnect(() => {
@@ -106,23 +106,23 @@ const _ = async (e, c, a, r, f, I, h) => {
106
106
  });
107
107
  },
108
108
  getInAppNotifications: async (e) => {
109
- const c = e.maxCountNeeded || i.config.getInAppDefaultCount, a = e.oldestNeeded || i.config.getInAppDefaultOldest;
110
- let r = [], f = e.before, I = !0, h = !0;
111
- for (; h; ) {
112
- const g = (await i.rest.getNotifications(
109
+ const c = e.maxCountNeeded || o.config.getInAppDefaultCount, r = e.oldestNeeded || o.config.getInAppDefaultOldest;
110
+ let a = [], f = e.before, w = !0, p = !0;
111
+ for (; p; ) {
112
+ const h = (await o.rest.getNotifications(
113
113
  f,
114
114
  c
115
115
  )).notifications.filter(
116
- (l) => !r.find((p) => p.id === l.id)
116
+ (l) => !a.find((g) => g.id === l.id)
117
117
  );
118
- f = g.reduce(
119
- (l, p) => l < p.date ? l : p.date,
118
+ f = h.reduce(
119
+ (l, g) => l < g.date ? l : g.date,
120
120
  e.before
121
- ), r = [...r, ...g], I = g.length > 0, h = !0, (!I || r.length >= c || f < a) && (h = !1);
121
+ ), a = [...a, ...h], w = h.length > 0, p = !0, (!w || a.length >= c || f < r) && (p = !1);
122
122
  }
123
123
  return {
124
- items: r,
125
- hasMore: I,
124
+ items: a,
125
+ hasMore: w,
126
126
  oldestReceived: f
127
127
  };
128
128
  },
@@ -130,157 +130,164 @@ const _ = async (e, c, a, r, f, I, h) => {
130
130
  const c = {
131
131
  trackingIds: e.ids
132
132
  };
133
- return e.archived === !0 ? c.archived = (/* @__PURE__ */ new Date()).toISOString() : e.archived === !1 && (c.archived = null), e.clicked === !0 ? c.clicked = (/* @__PURE__ */ new Date()).toISOString() : e.clicked === !1 && (c.clicked = null), e.opened === !0 ? c.opened = (/* @__PURE__ */ new Date()).toISOString() : e.opened === !1 && (c.opened = null), i.rest.patchNotifications(c);
133
+ return e.archived === !0 ? c.archived = (/* @__PURE__ */ new Date()).toISOString() : e.archived === !1 && (c.archived = null), e.clicked === !0 ? c.clicked = (/* @__PURE__ */ new Date()).toISOString() : e.clicked === !1 && (c.clicked = null), e.opened === !0 ? c.opened = (/* @__PURE__ */ new Date()).toISOString() : e.opened === !1 && (c.opened = null), o.rest.patchNotifications(c);
134
134
  },
135
- getPreferences: async () => i.rest.getPreferences(),
136
- updateDeliveryOption: async (e) => i.rest.postPreferences([e])
137
- }, U = B(
135
+ getPreferences: async () => o.rest.getPreferences(),
136
+ updateDeliveryOption: async (e) => o.rest.postPreferences([e])
137
+ }, R = F(
138
138
  void 0
139
- ), F = (e) => {
140
- const a = {
139
+ ), q = (e) => {
140
+ const r = {
141
141
  ...{
142
142
  apiURL: "https://api.notificationapi.com",
143
143
  wsURL: "wss://ws.notificationapi.com",
144
144
  initialLoadMaxCount: 1e3,
145
- initialLoadMaxAge: new Date((/* @__PURE__ */ new Date()).setMonth((/* @__PURE__ */ new Date()).getMonth() - 3))
145
+ initialLoadMaxAge: new Date((/* @__PURE__ */ new Date()).setMonth((/* @__PURE__ */ new Date()).getMonth() - 3)),
146
+ playSoundOnNewNotification: !1,
147
+ newNotificationSoundPath: "https://proxy.notificationsounds.com/notification-sounds/elegant-notification-sound/download/file-sounds-1233-elegant.mp3"
146
148
  },
147
149
  ...e
148
- }, [r, f] = N(), [I, h] = N(), [g, l] = N(!1), [p, D] = N((/* @__PURE__ */ new Date()).toISOString()), [b, v] = N(!0), S = A((o) => {
150
+ }, [a, f] = N(), [w, p] = N(), [h, l] = N(!1), [g, y] = N((/* @__PURE__ */ new Date()).toISOString()), [A, D] = N(!0), P = b(() => {
151
+ r.playSoundOnNewNotification && new Audio(r.newNotificationSoundPath).play().catch((s) => {
152
+ console.log("Failed to play new notification sound:", s);
153
+ });
154
+ }, [r.newNotificationSoundPath, r.playSoundOnNewNotification]), S = b((n) => {
149
155
  const s = (/* @__PURE__ */ new Date()).toISOString();
150
- f((t) => (o = o.filter((n) => !(n.expDate && new Date(n.expDate * 1e3).toISOString() > s || n.date > s)), t ? [
151
- ...o.filter((n) => !t.find((d) => d.id === n.id)),
156
+ f((t) => (n = n.filter((i) => !(i.expDate && new Date(i.expDate * 1e3).toISOString() > s || i.date > s)), t ? [
157
+ ...n.filter((i) => !t.find((d) => d.id === i.id)),
152
158
  ...t
153
- ] : o));
154
- }, []), u = G(() => i.init({
159
+ ] : n));
160
+ }, []), u = G(() => o.init({
155
161
  clientId: e.clientId,
156
162
  userId: e.userId,
157
163
  hashedUserId: e.hashedUserId,
158
- onNewInAppNotifications: (o) => {
159
- S(o);
164
+ onNewInAppNotifications: (n) => {
165
+ P(), S(n);
160
166
  }
161
167
  }), [
162
168
  e.clientId,
163
169
  e.userId,
164
170
  e.hashedUserId,
165
- S
166
- ]), P = A(
167
- async (o, s) => {
168
- const t = await u.rest.getNotifications(o, s);
169
- D(t.oldestReceived), v(t.couldLoadMore), S(t.notifications);
171
+ S,
172
+ P
173
+ ]), v = b(
174
+ async (n, s) => {
175
+ const t = await u.rest.getNotifications(n, s);
176
+ y(t.oldestReceived), D(t.couldLoadMore), S(t.notifications);
170
177
  },
171
178
  [S, u.rest]
172
- ), y = m(b), C = m(g), O = m(p);
173
- L(() => {
174
- y.current = b, C.current = g, O.current = p;
175
- }, [b, g, p]);
176
- const k = A(
177
- async (o) => {
178
- if (!(!o && (!y.current || C.current))) {
179
+ ), O = m(A), C = m(h), x = m(g);
180
+ M(() => {
181
+ O.current = A, C.current = h, x.current = g;
182
+ }, [A, h, g]);
183
+ const k = b(
184
+ async (n) => {
185
+ if (!(!n && (!O.current || C.current))) {
179
186
  l(!0);
180
187
  try {
181
- await P(
182
- o ? (/* @__PURE__ */ new Date()).toISOString() : O.current,
183
- o ? a.initialLoadMaxCount : 1e3
188
+ await v(
189
+ n ? (/* @__PURE__ */ new Date()).toISOString() : x.current,
190
+ n ? r.initialLoadMaxCount : 1e3
184
191
  );
185
192
  } finally {
186
193
  l(!1);
187
194
  }
188
195
  }
189
196
  },
190
- [a.initialLoadMaxCount, P]
191
- ), R = async (o) => {
192
- if (!r)
197
+ [r.initialLoadMaxCount, v]
198
+ ), $ = async (n) => {
199
+ if (!a)
193
200
  return;
194
- const s = (/* @__PURE__ */ new Date()).toISOString(), t = r.filter((n) => o.includes(n.id) && !n.clicked).map((n) => n.id);
195
- u.updateInAppNotifications({ ids: t, clicked: !0 }), f((n) => {
196
- if (!n)
201
+ const s = (/* @__PURE__ */ new Date()).toISOString(), t = a.filter((i) => n.includes(i.id) && !i.clicked).map((i) => i.id);
202
+ u.updateInAppNotifications({ ids: t, clicked: !0 }), f((i) => {
203
+ if (!i)
197
204
  return [];
198
- const d = [...n];
199
- return d.filter((w) => t.includes(w.id)).forEach((w) => {
200
- w.clicked = s;
205
+ const d = [...i];
206
+ return d.filter((I) => t.includes(I.id)).forEach((I) => {
207
+ I.clicked = s;
201
208
  }), d;
202
209
  });
203
- }, $ = async () => {
204
- if (!r)
210
+ }, E = async () => {
211
+ if (!a)
205
212
  return;
206
- const o = (/* @__PURE__ */ new Date()).toISOString(), s = r.filter((t) => !t.opened || !t.seen).map((t) => t.id);
213
+ const n = (/* @__PURE__ */ new Date()).toISOString(), s = a.filter((t) => !t.opened || !t.seen).map((t) => t.id);
207
214
  s.length !== 0 && (u.updateInAppNotifications({
208
215
  ids: s,
209
216
  opened: !0
210
217
  }), f((t) => {
211
218
  if (!t)
212
219
  return [];
213
- const n = [...t];
214
- return n.filter((d) => s.includes(d.id)).forEach((d) => {
215
- d.opened = o, d.seen = !0;
216
- }), n;
220
+ const i = [...t];
221
+ return i.filter((d) => s.includes(d.id)).forEach((d) => {
222
+ d.opened = n, d.seen = !0;
223
+ }), i;
217
224
  }));
218
- }, E = async (o) => {
219
- if (!r)
225
+ }, j = async (n) => {
226
+ if (!a)
220
227
  return;
221
- const s = r.filter((t) => t.archived && (o === "ALL" || o.includes(t.id))).map((t) => t.id);
228
+ const s = a.filter((t) => t.archived && (n === "ALL" || n.includes(t.id))).map((t) => t.id);
222
229
  s.length !== 0 && (u.updateInAppNotifications({
223
230
  ids: s,
224
231
  archived: !1
225
232
  }), f((t) => {
226
233
  if (!t)
227
234
  return [];
228
- const n = [...t];
229
- return n.filter((d) => s.includes(d.id)).forEach((d) => {
235
+ const i = [...t];
236
+ return i.filter((d) => s.includes(d.id)).forEach((d) => {
230
237
  d.archived = void 0;
231
- }), n;
238
+ }), i;
232
239
  }));
233
- }, j = async (o) => {
234
- if (!r)
240
+ }, T = async (n) => {
241
+ if (!a)
235
242
  return;
236
- const s = (/* @__PURE__ */ new Date()).toISOString(), t = r.filter((n) => !n.archived && (o === "ALL" || o.includes(n.id))).map((n) => n.id);
237
- t.length !== 0 && (u.updateInAppNotifications({ ids: t, archived: !0 }), f((n) => {
238
- if (!n)
243
+ const s = (/* @__PURE__ */ new Date()).toISOString(), t = a.filter((i) => !i.archived && (n === "ALL" || n.includes(i.id))).map((i) => i.id);
244
+ t.length !== 0 && (u.updateInAppNotifications({ ids: t, archived: !0 }), f((i) => {
245
+ if (!i)
239
246
  return [];
240
- const d = [...n];
241
- return d.filter((w) => t.includes(w.id)).forEach((w) => {
242
- w.archived = s;
247
+ const d = [...i];
248
+ return d.filter((I) => t.includes(I.id)).forEach((I) => {
249
+ I.archived = s;
243
250
  }), d;
244
251
  }));
245
- }, T = (o, s, t, n) => x([
252
+ }, W = (n, s, t, i) => L([
246
253
  {
247
- notificationId: o,
254
+ notificationId: n,
248
255
  channel: s,
249
256
  delivery: t,
250
- subNotificationId: n
257
+ subNotificationId: i
251
258
  }
252
- ]), x = (o) => {
253
- u.rest.postPreferences(o).then(() => {
259
+ ]), L = (n) => {
260
+ u.rest.postPreferences(n).then(() => {
254
261
  u.getPreferences().then((s) => {
255
- h(s);
262
+ p(s);
256
263
  });
257
264
  });
258
265
  };
259
- L(() => {
260
- f([]), l(!1), h(void 0), D((/* @__PURE__ */ new Date()).toISOString()), v(!0), k(!0), u.openWebSocket(), u.getPreferences().then((o) => {
261
- h(o);
266
+ M(() => {
267
+ f([]), l(!1), p(void 0), y((/* @__PURE__ */ new Date()).toISOString()), D(!0), k(!0), u.openWebSocket(), u.getPreferences().then((n) => {
268
+ p(n);
262
269
  });
263
270
  }, [u, k]);
264
- const W = {
265
- notifications: r,
266
- preferences: I,
271
+ const H = {
272
+ notifications: a,
273
+ preferences: w,
267
274
  loadNotifications: k,
268
- markAsOpened: $,
269
- markAsArchived: j,
270
- markAsUnarchived: E,
271
- markAsClicked: R,
272
- updateDelivery: T,
273
- updateDeliveries: x
275
+ markAsOpened: E,
276
+ markAsArchived: T,
277
+ markAsUnarchived: j,
278
+ markAsClicked: $,
279
+ updateDelivery: W,
280
+ updateDeliveries: L
274
281
  };
275
- return /* @__PURE__ */ H(U.Provider, { value: W, children: e.children });
276
- }, q = () => {
277
- const e = J(U);
282
+ return /* @__PURE__ */ B(R.Provider, { value: H, children: e.children });
283
+ }, K = () => {
284
+ const e = J(R);
278
285
  if (!e)
279
286
  throw new Error("useMyContext must be used within a MyProvider");
280
287
  return e;
281
288
  };
282
- F.useNotificationAPIContext = q;
289
+ q.useNotificationAPIContext = K;
283
290
  export {
284
- U as NotificationAPIContext,
285
- F as NotificationAPIProvider
291
+ R as NotificationAPIContext,
292
+ q as NotificationAPIProvider
286
293
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@notificationapi/react",
3
3
  "private": false,
4
- "version": "0.0.26",
4
+ "version": "0.0.28",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",