@notificationapi/react 0.0.10 → 0.0.12

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.
@@ -1,10 +1,11 @@
1
- /// <reference types="react" />
1
+ import { InAppNotification } from '../../interface';
2
+
2
3
  export declare enum ImageShape {
3
4
  square = "square",
4
5
  circle = "circle"
5
6
  }
6
7
  export declare const Notification: (props: {
7
- notification: any;
8
+ notification: InAppNotification;
8
9
  markAsArchived: (ids: string[] | "ALL") => void;
9
10
  markAsClicked: (id: string) => void;
10
11
  imageShape: keyof typeof ImageShape;
@@ -1,6 +1,7 @@
1
1
  import { Pagination } from './Inbox';
2
2
  import { ImageShape } from './Notification';
3
3
  import { Filter } from './NotificationPopup';
4
+ import { InAppNotification } from '../../interface';
4
5
 
5
6
  export type NotificationFeedProps = {
6
7
  imageShape?: keyof typeof ImageShape;
@@ -9,6 +10,6 @@ export type NotificationFeedProps = {
9
10
  pagePosition?: "top" | "bottom";
10
11
  infiniteScrollHeight?: number;
11
12
  style?: React.CSSProperties;
12
- filter?: keyof typeof Filter | ((n: any) => boolean);
13
+ filter?: keyof typeof Filter | ((n: InAppNotification) => boolean);
13
14
  };
14
15
  export declare const NotificationFeed: React.FC<NotificationFeedProps>;
@@ -1,6 +1,7 @@
1
1
  import { Pagination } from './Inbox';
2
2
  import { UnreadBadgeProps } from './UnreadBadge';
3
3
  import { ImageShape } from './Notification';
4
+ import { InAppNotification } from '../../interface';
4
5
 
5
6
  export declare enum Filter {
6
7
  ALL = "ALL",
@@ -19,6 +20,6 @@ export type NotificationPopupProps = {
19
20
  style?: React.CSSProperties;
20
21
  unreadBadgeProps?: UnreadBadgeProps;
21
22
  count?: UnreadBadgeProps["count"];
22
- filter?: keyof typeof Filter | ((n: any) => boolean);
23
+ filter?: keyof typeof Filter | ((n: InAppNotification) => boolean);
23
24
  };
24
25
  export declare const NotificationPopup: React.FC<NotificationPopupProps>;
@@ -9,7 +9,7 @@ const d = (e) => {
9
9
  I,
10
10
  {
11
11
  count: ((n) => e.count === "COUNT_UNOPENED_NOTIFICATIONS" || e.count === void 0 ? n.filter((t) => !t.opened && !t.seen).length : e.count === "COUNT_UNARCHIVED_NOTIFICATIONS" ? n.filter(
12
- (t) => !t.archived && !t.clicked && !t.replied && !t.actioned1 && !t.actioned2
12
+ (t) => !t.archived && !t.clicked && !t.replies && !t.actioned1 && !t.actioned2
13
13
  ).length : n.filter(e.count).length)((o == null ? void 0 : o.notifications) || []),
14
14
  color: e.color,
15
15
  overflowCount: e.overflowCount,
@@ -1,2 +1,4 @@
1
1
  /// <reference types="react" />
2
- export declare function NotificationPreferencesInline(props: React.HTMLAttributes<HTMLElement>): JSX.Element;
2
+ type NotificationPreferencesInlineProps = {};
3
+ export declare function NotificationPreferencesInline(props: NotificationPreferencesInlineProps): JSX.Element;
4
+ export {};
@@ -1,7 +1,8 @@
1
- import { jsx as e } from "react/jsx-runtime";
2
- function r(i) {
3
- return /* @__PURE__ */ e("div", { ...i, children: "hi" });
1
+ import { jsx as r } from "react/jsx-runtime";
2
+ import { P as e } from "../../assets/Preferences.js";
3
+ function t(o) {
4
+ return /* @__PURE__ */ r(e, {});
4
5
  }
5
6
  export {
6
- r as NotificationPreferencesInline
7
+ t as NotificationPreferencesInline
7
8
  };
@@ -2,6 +2,7 @@
2
2
  type NotificationPreferencesPopupProps = {
3
3
  open?: boolean;
4
4
  onClose?: () => void;
5
+ collapse?: boolean;
5
6
  };
6
7
  export declare function NotificationPreferencesPopup(props: NotificationPreferencesPopupProps): JSX.Element;
7
8
  export {};
@@ -1481,7 +1481,8 @@ function Vt(e) {
1481
1481
  const n = {
1482
1482
  open: e.open === void 0 ? !0 : e.open,
1483
1483
  onClose: e.onClose || (() => {
1484
- })
1484
+ }),
1485
+ collapse: e.collapse === void 0 ? !1 : e.collapse
1485
1486
  };
1486
1487
  return /* @__PURE__ */ ye(
1487
1488
  B,
@@ -0,0 +1,10 @@
1
+ import { Channels, DeliveryOptions, Preferences } from '../Provider';
2
+
3
+ type Props = {
4
+ preferences: Preferences["preferences"];
5
+ notification: Preferences["notifications"][0];
6
+ updateDelivery: (notificationId: string, channel: Channels, delivery: DeliveryOptions, subNotificationId?: string) => void;
7
+ subNotificationId?: string;
8
+ };
9
+ export declare const PreferenceInput: ({ notification, preferences, updateDelivery, subNotificationId, }: Props) => JSX.Element;
10
+ export {};
@@ -1,8 +1,7 @@
1
1
  import "react/jsx-runtime";
2
2
  import "../Provider/index.js";
3
- import { a as i } from "../../assets/Preferences.js";
4
- import "react";
3
+ import { a as m } from "../../assets/Preferences.js";
5
4
  import "../../assets/index3.js";
6
5
  export {
7
- i as PreferenceGroup
6
+ m as PreferenceInput
8
7
  };
@@ -2,11 +2,10 @@ import "react/jsx-runtime";
2
2
  import "../Provider/index.js";
3
3
  import "react";
4
4
  import "../../assets/colors.js";
5
- import { P as n, b as s, g } from "../../assets/Preferences.js";
6
- import "../../assets/index3.js";
5
+ import { P as p, b as i, g as s } from "../../assets/Preferences.js";
7
6
  import "../../assets/BellOutlined.js";
8
7
  export {
9
- n as Preferences,
10
- s as getChannelIcon,
11
- g as getChannelLabel
8
+ p as Preferences,
9
+ i as getChannelIcon,
10
+ s as getChannelLabel
12
11
  };
@@ -1,4 +1,5 @@
1
1
  import { PropsWithChildren } from 'react';
2
+ import { InAppNotification } from '../../interface';
2
3
 
3
4
  type Props = {
4
5
  clientId: string;
@@ -79,25 +80,6 @@ export interface Notification {
79
80
  };
80
81
  };
81
82
  }
82
- export interface InappNotification {
83
- id: string;
84
- seen: boolean;
85
- title: string;
86
- redirectURL?: string;
87
- imageURL?: string;
88
- date: Date;
89
- parameters?: Record<string, unknown>;
90
- expDate?: Date;
91
- opened?: string;
92
- clicked?: string;
93
- archived?: string;
94
- actioned1?: string;
95
- actioned2?: string;
96
- replies?: {
97
- date: string;
98
- message: string;
99
- }[];
100
- }
101
83
  export interface Preferences {
102
84
  preferences: {
103
85
  notificationId: string;
@@ -118,7 +100,7 @@ export interface Preferences {
118
100
  }[];
119
101
  }
120
102
  export type Context = {
121
- notifications?: InappNotification[];
103
+ notifications?: InAppNotification[];
122
104
  preferences?: Preferences;
123
105
  loadNotifications: (initial?: boolean) => void;
124
106
  markAsOpened: () => void;
@@ -1,6 +1,6 @@
1
- import { jsx as y } from "react/jsx-runtime";
2
- import { createContext as B, useState as f, useEffect as O } from "react";
3
- import { api as u } from "../../api.js";
1
+ import { jsx as _ } from "react/jsx-runtime";
2
+ import { createContext as x, useState as f, useEffect as B } from "react";
3
+ import { api as r } from "../../api.js";
4
4
  const j = {
5
5
  opened: "opened",
6
6
  clicked: "clicked",
@@ -9,8 +9,8 @@ const j = {
9
9
  actioned1: "actioned1",
10
10
  actioned2: "actioned2"
11
11
  };
12
- var $ = /* @__PURE__ */ ((e) => (e.EMAIL = "EMAIL", e.INAPP_WEB = "INAPP_WEB", e.SMS = "SMS", e.CALL = "CALL", e.PUSH = "PUSH", e.WEB_PUSH = "WEB_PUSH", e))($ || {}), C = /* @__PURE__ */ ((e) => (e.OFF = "off", e.INSTANT = "instant", e.HOURLY = "hourly", e.DAILY = "daily", e.WEEKLY = "weekly", e.MONTHLY = "monthly", e))(C || {});
13
- const x = B(
12
+ var $ = /* @__PURE__ */ ((e) => (e.EMAIL = "EMAIL", e.INAPP_WEB = "INAPP_WEB", e.SMS = "SMS", e.CALL = "CALL", e.PUSH = "PUSH", e.WEB_PUSH = "WEB_PUSH", e))($ || {}), v = /* @__PURE__ */ ((e) => (e.OFF = "off", e.INSTANT = "instant", e.HOURLY = "hourly", e.DAILY = "daily", e.WEEKLY = "weekly", e.MONTHLY = "monthly", e))(v || {});
13
+ const y = x(
14
14
  void 0
15
15
  ), J = (e) => {
16
16
  const c = {
@@ -21,50 +21,51 @@ const x = B(
21
21
  initialLoadMaxAge: new Date((/* @__PURE__ */ new Date()).setMonth((/* @__PURE__ */ new Date()).getMonth() - 3))
22
22
  },
23
23
  ...e
24
- }, [r, l] = f(), [L, w] = f(), [S, A] = f(!1), [U, E] = f((/* @__PURE__ */ new Date()).toISOString()), [m, M] = f(!0), P = (o) => {
25
- l((t) => t ? [
26
- ...o.filter((i) => !t.find((n) => n.id === i.id)),
24
+ }, [s, u] = f(), [P, S] = f(), [U, w] = f(!1), [N, E] = f((/* @__PURE__ */ new Date()).toISOString()), [m, M] = f(!0), g = (a) => {
25
+ const n = (/* @__PURE__ */ new Date()).toISOString();
26
+ u((t) => (a = a.filter((i) => !(i.expDate && new Date(i.expDate * 1e3).toISOString() > n || i.date > n)), t ? [
27
+ ...a.filter((i) => !t.find((o) => o.id === i.id)),
27
28
  ...t
28
- ] : o);
29
- }, k = async (o, t) => (await u(
29
+ ] : a));
30
+ }, T = async (a, n) => (await r(
30
31
  c.apiURL,
31
32
  "GET",
32
- `notifications/INAPP_WEB?count=${o}&before=${t}`,
33
+ `notifications/INAPP_WEB?count=${a}&before=${n}`,
33
34
  e.clientId,
34
35
  e.userId,
35
36
  e.hashedUserId
36
- )).notifications, T = async (o, t, i) => {
37
- let n = [], a = o, s = !0, d = !0;
38
- for (; d; ) {
39
- const g = (await k(
40
- t,
41
- new Date(a).getTime()
37
+ )).notifications, k = async (a, n, t) => {
38
+ let i = [], o = a, d = !0, h = !0;
39
+ for (; h; ) {
40
+ const L = (await T(
41
+ n,
42
+ new Date(o).getTime()
42
43
  )).filter(
43
- (I) => !n.find((h) => h.id === I.id)
44
+ (I) => !i.find((l) => l.id === I.id)
44
45
  );
45
- a = g.reduce(
46
- (I, h) => I < h.date ? I : h.date,
47
- o
48
- ), n = [...n, ...g], s = g.length > 0, d = !0, (!s || n.length >= t || i && a < i) && (d = !1);
46
+ o = L.reduce(
47
+ (I, l) => I < l.date ? I : l.date,
48
+ a
49
+ ), i = [...i, ...L], d = L.length > 0, h = !0, (!d || i.length >= n || t && o < t) && (h = !1);
49
50
  }
50
- return console.log(n.length, s, a), {
51
- notifications: n,
52
- couldLoadMore: s,
53
- oldestReceived: a
51
+ return {
52
+ notifications: i,
53
+ couldLoadMore: d,
54
+ oldestReceived: o
54
55
  };
55
- }, N = async (o) => {
56
- if (!m || S)
56
+ }, A = async (a) => {
57
+ if (!m || U)
57
58
  return;
58
- A(!0);
59
- const t = await T(
60
- U,
61
- o ? c.initialLoadMaxCount : 1e3,
62
- o ? c.initialLoadMaxAge.toISOString() : void 0
59
+ w(!0);
60
+ const n = await k(
61
+ N,
62
+ a ? c.initialLoadMaxCount : 1e3,
63
+ a ? c.initialLoadMaxAge.toISOString() : void 0
63
64
  );
64
- E(t.oldestReceived), M(t.couldLoadMore), P(t.notifications), A(!1);
65
- }, R = async (o) => {
66
- const t = (/* @__PURE__ */ new Date()).toISOString();
67
- u(
65
+ E(n.oldestReceived), M(n.couldLoadMore), g(n.notifications), w(!1);
66
+ }, R = async (a) => {
67
+ const n = (/* @__PURE__ */ new Date()).toISOString();
68
+ r(
68
69
  c.apiURL,
69
70
  "PATCH",
70
71
  "notifications/INAPP_WEB",
@@ -72,20 +73,20 @@ const x = B(
72
73
  e.userId,
73
74
  e.hashedUserId,
74
75
  {
75
- trackingIds: [o],
76
- clicked: t
76
+ trackingIds: [a],
77
+ clicked: n
77
78
  }
78
- ), l((i) => {
79
- if (!i)
79
+ ), u((t) => {
80
+ if (!t)
80
81
  return [];
81
- const n = [...i], a = n.find((s) => s.id === o);
82
- return a && (a.clicked = t), n;
82
+ const i = [...t], o = i.find((d) => d.id === a);
83
+ return o && (o.clicked = n), i;
83
84
  });
84
- }, H = async () => {
85
- if (!r)
85
+ }, O = async () => {
86
+ if (!s)
86
87
  return;
87
- const o = (/* @__PURE__ */ new Date()).toISOString(), t = r.filter((i) => !i.opened || !i.seen).map((i) => i.id);
88
- t.length !== 0 && (u(
88
+ const a = (/* @__PURE__ */ new Date()).toISOString(), n = s.filter((t) => !t.opened || !t.seen).map((t) => t.id);
89
+ n.length !== 0 && (r(
89
90
  c.apiURL,
90
91
  "PATCH",
91
92
  "notifications/INAPP_WEB",
@@ -93,22 +94,22 @@ const x = B(
93
94
  e.userId,
94
95
  e.hashedUserId,
95
96
  {
96
- trackingIds: t,
97
- opened: o
97
+ trackingIds: n,
98
+ opened: a
98
99
  }
99
- ), l((i) => {
100
- if (!i)
100
+ ), u((t) => {
101
+ if (!t)
101
102
  return [];
102
- const n = [...i];
103
- return n.filter((a) => t.includes(a.id)).forEach((a) => {
104
- a.opened = o, a.seen = !0;
105
- }), n;
103
+ const i = [...t];
104
+ return i.filter((o) => n.includes(o.id)).forEach((o) => {
105
+ o.opened = a, o.seen = !0;
106
+ }), i;
106
107
  }));
107
- }, W = async (o) => {
108
- if (!r)
108
+ }, D = async (a) => {
109
+ if (!s)
109
110
  return;
110
- const t = (/* @__PURE__ */ new Date()).toISOString(), i = r.filter((n) => !n.archived && (o === "ALL" || o.includes(n.id))).map((n) => n.id);
111
- i.length !== 0 && (u(
111
+ const n = (/* @__PURE__ */ new Date()).toISOString(), t = s.filter((i) => !i.archived && (a === "ALL" || a.includes(i.id))).map((i) => i.id);
112
+ t.length !== 0 && (r(
112
113
  c.apiURL,
113
114
  "PATCH",
114
115
  "notifications/INAPP_WEB",
@@ -116,59 +117,80 @@ const x = B(
116
117
  e.userId,
117
118
  e.hashedUserId,
118
119
  {
119
- trackingIds: i,
120
- archived: t
120
+ trackingIds: t,
121
+ archived: n
121
122
  }
122
- ), l((n) => {
123
- if (!n)
123
+ ), u((i) => {
124
+ if (!i)
124
125
  return [];
125
- const a = [...n];
126
- return a.filter((s) => i.includes(s.id)).forEach((s) => {
127
- s.archived = t;
128
- }), a;
126
+ const o = [...i];
127
+ return o.filter((d) => t.includes(d.id)).forEach((d) => {
128
+ d.archived = n;
129
+ }), o;
129
130
  }));
130
- }, _ = (o, t, i, n) => {
131
- if (!L)
132
- return;
133
- const a = { ...L }, s = a.preferences.find(
134
- (d) => d.notificationId === o && d.subNotificationId === n && d.channel === t
135
- );
136
- s && (s.delivery = i), w(a);
131
+ }, H = (a, n, t, i) => {
132
+ r(
133
+ c.apiURL,
134
+ "POST",
135
+ "preferences",
136
+ e.clientId,
137
+ e.userId,
138
+ e.hashedUserId,
139
+ [
140
+ {
141
+ notificationId: a,
142
+ subNotificationId: i,
143
+ channel: n,
144
+ delivery: t
145
+ }
146
+ ]
147
+ ).then(() => {
148
+ r(
149
+ c.apiURL,
150
+ "GET",
151
+ "preferences",
152
+ e.clientId,
153
+ e.userId,
154
+ e.hashedUserId
155
+ ).then((o) => {
156
+ S(o);
157
+ });
158
+ });
137
159
  };
138
- O(() => {
139
- N(!0);
140
- const o = new WebSocket(
160
+ B(() => {
161
+ A(!0);
162
+ const a = new WebSocket(
141
163
  c.hashedUserId ? `${c.wsURL}?userId=${c.userId}&envId=${c.clientId}&userIdHash=${c.hashedUserId}` : `${c.wsURL}?userId=${c.userId}&envId=${c.clientId}`
142
164
  );
143
- o.onmessage = (t) => {
144
- const i = JSON.parse(t.data);
145
- !i || !i.route || i.route === "inapp_web/new_notifications" && P(i.payload.notifications);
146
- }, u(
165
+ a.onmessage = (n) => {
166
+ const t = JSON.parse(n.data);
167
+ !t || !t.route || t.route === "inapp_web/new_notifications" && g(t.payload.notifications);
168
+ }, r(
147
169
  c.apiURL,
148
170
  "GET",
149
171
  "preferences",
150
172
  e.clientId,
151
173
  e.userId,
152
174
  e.hashedUserId
153
- ).then((t) => {
154
- w(t);
175
+ ).then((n) => {
176
+ S(n);
155
177
  });
156
178
  }, []);
157
- const v = {
158
- notifications: r,
159
- preferences: L,
160
- loadNotifications: N,
161
- markAsOpened: H,
162
- markAsArchived: W,
179
+ const W = {
180
+ notifications: s,
181
+ preferences: P,
182
+ loadNotifications: A,
183
+ markAsOpened: O,
184
+ markAsArchived: D,
163
185
  markAsClicked: R,
164
- updateDelivery: _
186
+ updateDelivery: H
165
187
  };
166
- return /* @__PURE__ */ y(x.Provider, { value: v, children: e.children });
188
+ return /* @__PURE__ */ _(y.Provider, { value: W, children: e.children });
167
189
  };
168
190
  export {
169
191
  $ as Channels,
170
- C as DeliveryOptions,
192
+ v as DeliveryOptions,
171
193
  j as NOTIFICATION_ACTIONS,
172
- x as NotificationAPIContext,
194
+ y as NotificationAPIContext,
173
195
  J as NotificationAPIProvider
174
196
  };
@@ -0,0 +1,19 @@
1
+ export interface InAppNotification {
2
+ id: string;
3
+ seen: boolean;
4
+ title: string;
5
+ redirectURL?: string;
6
+ imageURL?: string;
7
+ date: string;
8
+ parameters?: Record<string, unknown>;
9
+ expDate?: number;
10
+ opened?: string;
11
+ clicked?: string;
12
+ archived?: string;
13
+ actioned1?: string;
14
+ actioned2?: string;
15
+ replies?: {
16
+ date: string;
17
+ message: string;
18
+ }[];
19
+ }
@@ -0,0 +1 @@
1
+
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@notificationapi/react",
3
3
  "private": false,
4
- "version": "0.0.10",
4
+ "version": "0.0.12",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -1,7 +0,0 @@
1
- /// <reference types="react" />
2
- type PreferenceGroupProps = {
3
- subNotificationId?: string;
4
- title: string;
5
- };
6
- export declare const PreferenceGroup: React.FC<PreferenceGroupProps>;
7
- export {};