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