@notificationapi/react 0.0.8 → 0.0.10

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 (27) hide show
  1. package/dist/assets/BellOutlined.js +18 -15
  2. package/dist/assets/Inbox.js +2376 -2270
  3. package/dist/assets/Notification.js +1960 -1340
  4. package/dist/assets/Preferences.js +564 -533
  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 +2 -3
  15. package/dist/components/Notifications/NotificationCounter.d.ts +1 -1
  16. package/dist/components/Notifications/NotificationFeed.d.ts +0 -1
  17. package/dist/components/Notifications/NotificationLauncher.d.ts +0 -1
  18. package/dist/components/Notifications/NotificationPopup.d.ts +0 -1
  19. package/dist/components/Notifications/UnreadBadge.d.ts +1 -1
  20. package/dist/components/Preferences/NotificationPreferencesInline.d.ts +2 -3
  21. package/dist/components/Preferences/NotificationPreferencesPopup.d.ts +2 -3
  22. package/dist/components/Preferences/NotificationPreferencesPopup.js +682 -646
  23. package/dist/components/Preferences/PreferenceGroup.d.ts +1 -2
  24. package/dist/components/Preferences/Preferences.d.ts +1 -2
  25. package/dist/components/Provider/index.d.ts +3 -2
  26. package/dist/components/Provider/index.js +102 -96
  27. package/package.json +1 -1
@@ -1,5 +1,4 @@
1
- import { default as React } from 'react';
2
-
1
+ /// <reference types="react" />
3
2
  type PreferenceGroupProps = {
4
3
  subNotificationId?: string;
5
4
  title: string;
@@ -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;
@@ -1,8 +1,9 @@
1
- import { default as React, PropsWithChildren } from 'react';
1
+ import { PropsWithChildren } from 'react';
2
2
 
3
3
  type Props = {
4
4
  clientId: string;
5
5
  userId: string;
6
+ hashedUserId?: string;
6
7
  apiURL?: string;
7
8
  wsURL?: string;
8
9
  initialLoadMaxCount?: number;
@@ -125,6 +126,6 @@ export type Context = {
125
126
  markAsClicked: (id: string) => void;
126
127
  updateDelivery: (notificationId: string, channel: Channels, delivery: DeliveryOptions, subNotificationId?: string) => void;
127
128
  };
128
- export declare const NotificationAPIContext: React.Context<Context | undefined>;
129
+ export declare const NotificationAPIContext: import('react').Context<Context | undefined>;
129
130
  export declare const NotificationAPIProvider: React.FunctionComponent<PropsWithChildren<Props>>;
130
131
  export {};
@@ -1,5 +1,5 @@
1
- import { jsx as B } from "react/jsx-runtime";
2
- import { createContext as O, useState as f, useEffect as v } from "react";
1
+ import { jsx as y } from "react/jsx-runtime";
2
+ import { createContext as B, useState as f, useEffect as O } from "react";
3
3
  import { api as u } from "../../api.js";
4
4
  const j = {
5
5
  opened: "opened",
@@ -9,160 +9,166 @@ 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))($ || {}), 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(
14
14
  void 0
15
- ), p = (t) => {
16
- const r = {
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(), [g, w] = f(), [h, P] = f(!1), [E, m] = f((/* @__PURE__ */ new Date()).toISOString()), [M, k] = f(!0), N = (o) => {
25
- l((e) => e ? [
26
- ...o.filter((i) => !e.find((n) => n.id === i.id)),
27
- ...e
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)),
27
+ ...t
28
28
  ] : o);
29
- }, T = async (o, e) => (await u(
30
- r.apiURL,
29
+ }, k = async (o, t) => (await u(
30
+ c.apiURL,
31
31
  "GET",
32
- `notifications/INAPP_WEB?count=${o}&before=${e}`,
33
- t.clientId,
34
- t.userId
35
- )).notifications, U = async (o, e, i) => {
36
- let n = [], c = o, a = !0, s = !0;
37
- for (; s; ) {
38
- const A = (await T(
39
- e,
40
- new Date(c).getTime()
32
+ `notifications/INAPP_WEB?count=${o}&before=${t}`,
33
+ e.clientId,
34
+ e.userId,
35
+ 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()
41
42
  )).filter(
42
- (I) => !n.find((L) => L.id === I.id)
43
+ (I) => !n.find((h) => h.id === I.id)
43
44
  );
44
- c = A.reduce(
45
- (I, L) => I < L.date ? I : L.date,
45
+ a = g.reduce(
46
+ (I, h) => I < h.date ? I : h.date,
46
47
  o
47
- ), n = [...n, ...A], a = A.length > 0, s = !0, (!a || n.length >= e || i && c < i) && (s = !1);
48
+ ), n = [...n, ...g], s = g.length > 0, d = !0, (!s || n.length >= t || i && a < i) && (d = !1);
48
49
  }
49
- return console.log(n.length, a, c), {
50
+ return console.log(n.length, s, a), {
50
51
  notifications: n,
51
- couldLoadMore: a,
52
- oldestReceived: c
52
+ couldLoadMore: s,
53
+ oldestReceived: a
53
54
  };
54
- }, S = async (o) => {
55
- if (!M || h)
55
+ }, N = async (o) => {
56
+ if (!m || S)
56
57
  return;
57
- P(!0);
58
- const e = await U(
59
- E,
60
- o ? r.initialLoadMaxCount : 1e3,
61
- o ? r.initialLoadMaxAge.toISOString() : void 0
58
+ A(!0);
59
+ const t = await T(
60
+ U,
61
+ o ? c.initialLoadMaxCount : 1e3,
62
+ o ? c.initialLoadMaxAge.toISOString() : void 0
62
63
  );
63
- m(e.oldestReceived), k(e.couldLoadMore), N(e.notifications), P(!1);
64
+ E(t.oldestReceived), M(t.couldLoadMore), P(t.notifications), A(!1);
64
65
  }, R = async (o) => {
65
- const e = (/* @__PURE__ */ new Date()).toISOString();
66
+ const t = (/* @__PURE__ */ new Date()).toISOString();
66
67
  u(
67
- r.apiURL,
68
+ c.apiURL,
68
69
  "PATCH",
69
70
  "notifications/INAPP_WEB",
70
- t.clientId,
71
- t.userId,
72
- "",
71
+ e.clientId,
72
+ e.userId,
73
+ e.hashedUserId,
73
74
  {
74
75
  trackingIds: [o],
75
- clicked: e
76
+ clicked: t
76
77
  }
77
78
  ), l((i) => {
78
79
  if (!i)
79
80
  return [];
80
- const n = [...i], c = n.find((a) => a.id === o);
81
- return c && (c.clicked = e), n;
81
+ const n = [...i], a = n.find((s) => s.id === o);
82
+ return a && (a.clicked = t), n;
82
83
  });
83
- }, W = async () => {
84
- if (!d)
84
+ }, H = async () => {
85
+ if (!r)
85
86
  return;
86
- const o = (/* @__PURE__ */ new Date()).toISOString(), e = d.filter((i) => !i.opened || !i.seen).map((i) => i.id);
87
- e.length !== 0 && (u(
88
- r.apiURL,
87
+ const o = (/* @__PURE__ */ new Date()).toISOString(), t = r.filter((i) => !i.opened || !i.seen).map((i) => i.id);
88
+ t.length !== 0 && (u(
89
+ c.apiURL,
89
90
  "PATCH",
90
91
  "notifications/INAPP_WEB",
91
- t.clientId,
92
- t.userId,
93
- "",
92
+ e.clientId,
93
+ e.userId,
94
+ e.hashedUserId,
94
95
  {
95
- trackingIds: e,
96
+ trackingIds: t,
96
97
  opened: o
97
98
  }
98
99
  ), l((i) => {
99
100
  if (!i)
100
101
  return [];
101
102
  const n = [...i];
102
- return n.filter((c) => e.includes(c.id)).forEach((c) => {
103
- c.opened = o, c.seen = !0;
103
+ return n.filter((a) => t.includes(a.id)).forEach((a) => {
104
+ a.opened = o, a.seen = !0;
104
105
  }), n;
105
106
  }));
106
- }, _ = async (o) => {
107
- if (!d)
107
+ }, W = async (o) => {
108
+ if (!r)
108
109
  return;
109
- const e = (/* @__PURE__ */ new Date()).toISOString(), i = d.filter((n) => !n.archived && (o === "ALL" || o.includes(n.id))).map((n) => n.id);
110
+ const t = (/* @__PURE__ */ new Date()).toISOString(), i = r.filter((n) => !n.archived && (o === "ALL" || o.includes(n.id))).map((n) => n.id);
110
111
  i.length !== 0 && (u(
111
- r.apiURL,
112
+ c.apiURL,
112
113
  "PATCH",
113
114
  "notifications/INAPP_WEB",
114
- t.clientId,
115
- t.userId,
116
- "",
115
+ e.clientId,
116
+ e.userId,
117
+ e.hashedUserId,
117
118
  {
118
119
  trackingIds: i,
119
- archived: e
120
+ archived: t
120
121
  }
121
122
  ), l((n) => {
122
123
  if (!n)
123
124
  return [];
124
- const c = [...n];
125
- return c.filter((a) => i.includes(a.id)).forEach((a) => {
126
- a.archived = e;
127
- }), c;
125
+ const a = [...n];
126
+ return a.filter((s) => i.includes(s.id)).forEach((s) => {
127
+ s.archived = t;
128
+ }), a;
128
129
  }));
129
- }, H = (o, e, i, n) => {
130
- if (!g)
130
+ }, _ = (o, t, i, n) => {
131
+ if (!L)
131
132
  return;
132
- const c = { ...g }, a = c.preferences.find(
133
- (s) => s.notificationId === o && s.subNotificationId === n && s.channel === e
133
+ const a = { ...L }, s = a.preferences.find(
134
+ (d) => d.notificationId === o && d.subNotificationId === n && d.channel === t
134
135
  );
135
- a && (a.delivery = i), w(c);
136
+ s && (s.delivery = i), w(a);
136
137
  };
137
- v(() => {
138
- S(!0);
138
+ O(() => {
139
+ N(!0);
139
140
  const o = new WebSocket(
140
- `${r.wsURL}?userId=${r.userId}&envId=${r.clientId}`
141
- );
142
- o.onmessage = (e) => {
143
- const i = JSON.parse(e.data);
144
- !i || !i.route || i.route === "inapp_web/new_notifications" && N(i.payload.notifications);
145
- }, u(r.apiURL, "GET", "preferences", t.clientId, t.userId).then(
146
- (e) => {
147
- w(e);
148
- }
141
+ c.hashedUserId ? `${c.wsURL}?userId=${c.userId}&envId=${c.clientId}&userIdHash=${c.hashedUserId}` : `${c.wsURL}?userId=${c.userId}&envId=${c.clientId}`
149
142
  );
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(
147
+ c.apiURL,
148
+ "GET",
149
+ "preferences",
150
+ e.clientId,
151
+ e.userId,
152
+ e.hashedUserId
153
+ ).then((t) => {
154
+ w(t);
155
+ });
150
156
  }, []);
151
- const y = {
152
- notifications: d,
153
- preferences: g,
154
- loadNotifications: S,
155
- markAsOpened: W,
156
- markAsArchived: _,
157
+ const v = {
158
+ notifications: r,
159
+ preferences: L,
160
+ loadNotifications: N,
161
+ markAsOpened: H,
162
+ markAsArchived: W,
157
163
  markAsClicked: R,
158
- updateDelivery: H
164
+ updateDelivery: _
159
165
  };
160
- return /* @__PURE__ */ B(D.Provider, { value: y, children: t.children });
166
+ return /* @__PURE__ */ y(x.Provider, { value: v, children: e.children });
161
167
  };
162
168
  export {
163
- C as Channels,
164
- x as DeliveryOptions,
169
+ $ as Channels,
170
+ C as DeliveryOptions,
165
171
  j as NOTIFICATION_ACTIONS,
166
- D as NotificationAPIContext,
167
- p as NotificationAPIProvider
172
+ x as NotificationAPIContext,
173
+ J as NotificationAPIProvider
168
174
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@notificationapi/react",
3
3
  "private": false,
4
- "version": "0.0.8",
4
+ "version": "0.0.10",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",