@notificationapi/react 0.0.9 → 0.0.11

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.
Files changed (33) hide show
  1. package/dist/assets/BellOutlined.js +18 -15
  2. package/dist/assets/Inbox.js +2376 -2270
  3. package/dist/assets/Notification.js +1967 -1342
  4. package/dist/assets/Preferences.js +828 -782
  5. package/dist/assets/PurePanel.js +24 -23
  6. package/dist/assets/button.js +275 -265
  7. package/dist/assets/colors.js +19298 -7652
  8. package/dist/assets/index.js +48 -47
  9. package/dist/assets/index2.js +94 -92
  10. package/dist/assets/index3.js +2990 -2647
  11. package/dist/components/Notifications/Inbox.d.ts +0 -1
  12. package/dist/components/Notifications/InboxHeader.d.ts +2 -3
  13. package/dist/components/Notifications/InboxHeader.js +14 -13
  14. package/dist/components/Notifications/Notification.d.ts +3 -3
  15. package/dist/components/Notifications/NotificationCounter.d.ts +1 -1
  16. package/dist/components/Notifications/NotificationFeed.d.ts +2 -2
  17. package/dist/components/Notifications/NotificationLauncher.d.ts +0 -1
  18. package/dist/components/Notifications/NotificationPopup.d.ts +2 -2
  19. package/dist/components/Notifications/UnreadBadge.d.ts +1 -1
  20. package/dist/components/Notifications/UnreadBadge.js +1 -1
  21. package/dist/components/Preferences/NotificationPreferencesInline.d.ts +2 -3
  22. package/dist/components/Preferences/NotificationPreferencesPopup.d.ts +3 -3
  23. package/dist/components/Preferences/NotificationPreferencesPopup.js +684 -647
  24. package/dist/components/Preferences/PreferenceInput.d.ts +10 -0
  25. package/dist/components/Preferences/{PreferenceGroup.js → PreferenceInput.js} +2 -3
  26. package/dist/components/Preferences/Preferences.d.ts +1 -2
  27. package/dist/components/Preferences/Preferences.js +4 -5
  28. package/dist/components/Provider/index.d.ts +4 -22
  29. package/dist/components/Provider/index.js +139 -117
  30. package/dist/interface.d.ts +19 -0
  31. package/dist/interface.js +1 -0
  32. package/package.json +1 -1
  33. package/dist/components/Preferences/PreferenceGroup.d.ts +0 -8
@@ -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
  };
@@ -1,6 +1,5 @@
1
- import { default as React } from 'react';
2
1
  import { Channels } from '../Provider';
3
2
 
4
3
  export declare const getChannelLabel: (c: Channels) => string;
5
4
  export declare const getChannelIcon: (channel: Channels) => React.ReactElement;
6
- export declare function Preferences(): React.JSX.Element | null;
5
+ export declare function Preferences(): JSX.Element | null;
@@ -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
- import { default as React, PropsWithChildren } from 'react';
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;
@@ -126,6 +108,6 @@ export type Context = {
126
108
  markAsClicked: (id: string) => void;
127
109
  updateDelivery: (notificationId: string, channel: Channels, delivery: DeliveryOptions, subNotificationId?: string) => void;
128
110
  };
129
- export declare const NotificationAPIContext: React.Context<Context | undefined>;
111
+ export declare const NotificationAPIContext: import('react').Context<Context | undefined>;
130
112
  export declare const NotificationAPIProvider: React.FunctionComponent<PropsWithChildren<Props>>;
131
113
  export {};
@@ -1,6 +1,6 @@
1
- import { jsx as B } from "react/jsx-runtime";
2
- import { createContext as O, useState as f, useEffect as v } 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,166 +9,188 @@ const j = {
9
9
  actioned1: "actioned1",
10
10
  actioned2: "actioned2"
11
11
  };
12
- var C = /* @__PURE__ */ ((t) => (t.EMAIL = "EMAIL", t.INAPP_WEB = "INAPP_WEB", t.SMS = "SMS", t.CALL = "CALL", t.PUSH = "PUSH", t.WEB_PUSH = "WEB_PUSH", t))(C || {}), x = /* @__PURE__ */ ((t) => (t.OFF = "off", t.INSTANT = "instant", t.HOURLY = "hourly", t.DAILY = "daily", t.WEEKLY = "weekly", t.MONTHLY = "monthly", t))(x || {});
13
- const D = O(
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
- ), J = (t) => {
16
- const s = {
15
+ ), J = (e) => {
16
+ const c = {
17
17
  ...{
18
18
  apiURL: "https://api.notificationapi.com",
19
19
  wsURL: "wss://ws.notificationapi.com",
20
20
  initialLoadMaxCount: 1e3,
21
21
  initialLoadMaxAge: new Date((/* @__PURE__ */ new Date()).setMonth((/* @__PURE__ */ new Date()).getMonth() - 3))
22
22
  },
23
- ...t
24
- }, [d, l] = f(), [L, A] = f(), [S, w] = f(!1), [U, E] = f((/* @__PURE__ */ new Date()).toISOString()), [m, M] = f(!0), P = (o) => {
25
- l((e) => e ? [
26
- ...o.filter((i) => !e.find((n) => n.id === i.id)),
27
- ...e
28
- ] : o);
29
- }, k = async (o, e) => (await u(
30
- s.apiURL,
23
+ ...e
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)),
28
+ ...t
29
+ ] : a));
30
+ }, T = async (a, n) => (await r(
31
+ c.apiURL,
31
32
  "GET",
32
- `notifications/INAPP_WEB?count=${o}&before=${e}`,
33
- t.clientId,
34
- t.userId,
35
- t.hashedUserId
36
- )).notifications, T = async (o, e, i) => {
37
- let n = [], a = o, c = !0, r = !0;
38
- for (; r; ) {
39
- const g = (await k(
40
- e,
41
- new Date(a).getTime()
33
+ `notifications/INAPP_WEB?count=${a}&before=${n}`,
34
+ e.clientId,
35
+ e.userId,
36
+ e.hashedUserId
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], c = g.length > 0, r = !0, (!c || n.length >= e || i && a < i) && (r = !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, c, a), {
51
- notifications: n,
52
- couldLoadMore: c,
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
59
  w(!0);
59
- const e = await T(
60
- U,
61
- o ? s.initialLoadMaxCount : 1e3,
62
- o ? s.initialLoadMaxAge.toISOString() : void 0
60
+ const n = await k(
61
+ N,
62
+ a ? c.initialLoadMaxCount : 1e3,
63
+ a ? c.initialLoadMaxAge.toISOString() : void 0
63
64
  );
64
- E(e.oldestReceived), M(e.couldLoadMore), P(e.notifications), w(!1);
65
- }, R = async (o) => {
66
- const e = (/* @__PURE__ */ new Date()).toISOString();
67
- u(
68
- s.apiURL,
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(
69
+ c.apiURL,
69
70
  "PATCH",
70
71
  "notifications/INAPP_WEB",
71
- t.clientId,
72
- t.userId,
73
- t.hashedUserId,
72
+ e.clientId,
73
+ e.userId,
74
+ e.hashedUserId,
74
75
  {
75
- trackingIds: [o],
76
- clicked: e
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((c) => c.id === o);
82
- return a && (a.clicked = e), n;
82
+ const i = [...t], o = i.find((d) => d.id === a);
83
+ return o && (o.clicked = n), i;
83
84
  });
84
- }, W = async () => {
85
- if (!d)
85
+ }, O = async () => {
86
+ if (!s)
86
87
  return;
87
- const o = (/* @__PURE__ */ new Date()).toISOString(), e = d.filter((i) => !i.opened || !i.seen).map((i) => i.id);
88
- e.length !== 0 && (u(
89
- s.apiURL,
88
+ const a = (/* @__PURE__ */ new Date()).toISOString(), n = s.filter((t) => !t.opened || !t.seen).map((t) => t.id);
89
+ n.length !== 0 && (r(
90
+ c.apiURL,
90
91
  "PATCH",
91
92
  "notifications/INAPP_WEB",
92
- t.clientId,
93
- t.userId,
94
- t.hashedUserId,
93
+ e.clientId,
94
+ e.userId,
95
+ e.hashedUserId,
95
96
  {
96
- trackingIds: e,
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) => e.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
- }, _ = async (o) => {
108
- if (!d)
108
+ }, D = async (a) => {
109
+ if (!s)
109
110
  return;
110
- const e = (/* @__PURE__ */ new Date()).toISOString(), i = d.filter((n) => !n.archived && (o === "ALL" || o.includes(n.id))).map((n) => n.id);
111
- i.length !== 0 && (u(
112
- s.apiURL,
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(
113
+ c.apiURL,
113
114
  "PATCH",
114
115
  "notifications/INAPP_WEB",
115
- t.clientId,
116
- t.userId,
117
- t.hashedUserId,
116
+ e.clientId,
117
+ e.userId,
118
+ e.hashedUserId,
118
119
  {
119
- trackingIds: i,
120
- archived: e
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((c) => i.includes(c.id)).forEach((c) => {
127
- c.archived = e;
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
- }, H = (o, e, i, n) => {
131
- if (!L)
132
- return;
133
- const a = { ...L }, c = a.preferences.find(
134
- (r) => r.notificationId === o && r.subNotificationId === n && r.channel === e
135
- );
136
- c && (c.delivery = i), A(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
- v(() => {
139
- N(!0);
140
- const o = new WebSocket(
141
- `${s.wsURL}?userId=${s.userId}&envId=${s.clientId}`
160
+ B(() => {
161
+ A(!0);
162
+ const a = new WebSocket(
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 = (e) => {
144
- const i = JSON.parse(e.data);
145
- !i || !i.route || i.route === "inapp_web/new_notifications" && P(i.payload.notifications);
146
- }, u(
147
- s.apiURL,
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(
169
+ c.apiURL,
148
170
  "GET",
149
171
  "preferences",
150
- t.clientId,
151
- t.userId,
152
- t.hashedUserId
153
- ).then((e) => {
154
- A(e);
172
+ e.clientId,
173
+ e.userId,
174
+ e.hashedUserId
175
+ ).then((n) => {
176
+ S(n);
155
177
  });
156
178
  }, []);
157
- const y = {
158
- notifications: d,
159
- preferences: L,
160
- loadNotifications: N,
161
- markAsOpened: W,
162
- markAsArchived: _,
179
+ const W = {
180
+ notifications: s,
181
+ preferences: P,
182
+ loadNotifications: A,
183
+ markAsOpened: O,
184
+ markAsArchived: D,
163
185
  markAsClicked: R,
164
186
  updateDelivery: H
165
187
  };
166
- return /* @__PURE__ */ B(D.Provider, { value: y, children: t.children });
188
+ return /* @__PURE__ */ _(y.Provider, { value: W, children: e.children });
167
189
  };
168
190
  export {
169
- C as Channels,
170
- x as DeliveryOptions,
191
+ $ as Channels,
192
+ v as DeliveryOptions,
171
193
  j as NOTIFICATION_ACTIONS,
172
- D 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.9",
4
+ "version": "0.0.11",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -1,8 +0,0 @@
1
- import { default as React } from 'react';
2
-
3
- type PreferenceGroupProps = {
4
- subNotificationId?: string;
5
- title: string;
6
- };
7
- export declare const PreferenceGroup: React.FC<PreferenceGroupProps>;
8
- export {};