@notificationapi/react 0.0.20 → 0.0.22

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,7 +1,7 @@
1
1
  import { InboxHeaderProps } from './InboxHeader';
2
2
  import { ImageShape } from './Notification';
3
3
  import { NotificationPopupProps } from './NotificationPopup';
4
- import { InAppNotification } from '../../interface';
4
+ import { InAppNotification } from '@notificationapi/core/dist/interfaces';
5
5
 
6
6
  export declare enum Pagination {
7
7
  INFINITE_SCROLL = "infinite_scroll",
@@ -14,7 +14,7 @@ export type InboxProps = {
14
14
  imageShape: keyof typeof ImageShape;
15
15
  pageSize: number;
16
16
  pagePosition: NotificationPopupProps["pagePosition"];
17
- notificationRenderer: ((notification: InAppNotification) => JSX.Element) | undefined;
17
+ notificationRenderer: ((notification: InAppNotification[]) => JSX.Element) | undefined;
18
18
  header?: InboxHeaderProps;
19
19
  };
20
20
  export declare const Inbox: React.FC<InboxProps>;
@@ -1,14 +1,14 @@
1
- import { InAppNotification } from '../../interface';
1
+ import { InAppNotification } from '@notificationapi/core/dist/interfaces';
2
2
 
3
3
  export declare enum ImageShape {
4
4
  square = "square",
5
5
  circle = "circle"
6
6
  }
7
7
  export type NotificationProps = {
8
- notification: InAppNotification;
8
+ notifications: InAppNotification[];
9
9
  markAsArchived: (ids: string[] | "ALL") => void;
10
- markAsClicked: (id: string) => void;
10
+ markAsClicked: (ids: string[]) => void;
11
11
  imageShape: keyof typeof ImageShape;
12
- renderer?: (notification: InAppNotification) => JSX.Element;
12
+ renderer?: (notification: InAppNotification[]) => JSX.Element;
13
13
  };
14
14
  export declare const Notification: (props: NotificationProps) => JSX.Element;
@@ -1,8 +1,8 @@
1
1
  import { Pagination } from './Inbox';
2
2
  import { ImageShape, NotificationProps } from './Notification';
3
3
  import { Filter } from './NotificationPopup';
4
- import { InAppNotification } from '../../interface';
5
4
  import { InboxHeaderProps } from './InboxHeader';
5
+ import { InAppNotification } from '@notificationapi/core/dist/interfaces';
6
6
 
7
7
  export type NotificationFeedProps = {
8
8
  imageShape?: keyof typeof ImageShape;
@@ -1,7 +1,7 @@
1
1
  import { Pagination } from './Inbox';
2
2
  import { UnreadBadgeProps } from './UnreadBadge';
3
3
  import { ImageShape, NotificationProps } from './Notification';
4
- import { InAppNotification } from '../../interface';
4
+ import { InAppNotification } from '@notificationapi/core/dist/interfaces';
5
5
  import { InboxHeaderProps } from './InboxHeader';
6
6
 
7
7
  export declare enum Filter {
@@ -1,6 +1,6 @@
1
1
  import { PropsWithChildren } from 'react';
2
2
  import { NotificationPopupProps } from './NotificationPopup';
3
- import { InAppNotification } from '../../interface';
3
+ import { InAppNotification } from '@notificationapi/core/dist/interfaces';
4
4
 
5
5
  export type UnreadBadgeProps = {
6
6
  color?: "blue" | "purple" | "cyan" | "green" | "magenta" | "pink" | "red" | "orange" | "yellow" | "volcano" | "geekblue" | "lime" | "gold" | undefined;
@@ -1,9 +1,9 @@
1
- import { Channels, DeliveryOptions, Preferences } from '../Provider';
1
+ import { BaseDeliveryOptions, Channels, DeliveryOptionsForEmail, DeliveryOptionsForInappWeb, GetPreferencesResponse } from '@notificationapi/core/dist/interfaces';
2
2
 
3
3
  type Props = {
4
- preferences: Preferences["preferences"];
5
- notification: Preferences["notifications"][0];
6
- updateDelivery: (notificationId: string, channel: Channels, delivery: DeliveryOptions, subNotificationId?: string) => void;
4
+ preferences: GetPreferencesResponse["preferences"];
5
+ notification: GetPreferencesResponse["notifications"][0];
6
+ updateDelivery: (notificationId: string, channel: Channels, delivery: DeliveryOptionsForEmail | DeliveryOptionsForInappWeb | BaseDeliveryOptions, subNotificationId?: string) => void;
7
7
  subNotificationId?: string;
8
8
  };
9
9
  export declare const PreferenceInput: ({ notification, preferences, updateDelivery, subNotificationId, }: Props) => JSX.Element;
@@ -1,7 +1,6 @@
1
1
  import "react/jsx-runtime";
2
- import "../Provider/index.js";
3
- import { b as m } from "../../assets/Preferences.js";
2
+ import { b as t } from "../../assets/Preferences.js";
4
3
  import "../../assets/index3.js";
5
4
  export {
6
- m as PreferenceInput
5
+ t as PreferenceInput
7
6
  };
@@ -1,4 +1,4 @@
1
- import { Channels } from '../Provider';
1
+ import { Channels } from '@notificationapi/core/dist/interfaces';
2
2
 
3
3
  export declare const getChannelLabel: (c: Channels) => string;
4
4
  export declare const getChannelIcon: (channel: Channels) => React.ReactElement;
@@ -1,104 +1,15 @@
1
1
  import { PropsWithChildren } from 'react';
2
- import { InAppNotification } from '../../interface';
2
+ import { GetPreferencesResponse, InAppNotification, BaseDeliveryOptions, Channels, DeliveryOptionsForEmail, DeliveryOptionsForInappWeb } from '@notificationapi/core/dist/interfaces';
3
3
 
4
- export declare const NOTIFICATION_ACTIONS: {
5
- opened: string;
6
- clicked: string;
7
- archived: string;
8
- replied: string;
9
- actioned1: string;
10
- actioned2: string;
11
- };
12
- export declare enum Channels {
13
- EMAIL = "EMAIL",
14
- INAPP_WEB = "INAPP_WEB",
15
- SMS = "SMS",
16
- CALL = "CALL",
17
- PUSH = "PUSH",
18
- WEB_PUSH = "WEB_PUSH"
19
- }
20
- export declare enum DeliveryOptions {
21
- OFF = "off",
22
- INSTANT = "instant",
23
- HOURLY = "hourly",
24
- DAILY = "daily",
25
- WEEKLY = "weekly",
26
- MONTHLY = "monthly"
27
- }
28
- export interface NotificationConfig {
29
- envId: string;
30
- notificationId: string;
31
- title: string;
32
- channels: Channels[];
33
- enabled: boolean;
34
- deduplication?: {
35
- duration: number;
36
- };
37
- throttling?: {
38
- max: number;
39
- period: number;
40
- unit: "seconds" | "minutes" | "hours" | "days" | "months" | "years";
41
- forever: boolean;
42
- scope: ["userId", "notificationId"];
43
- };
44
- retention?: number;
45
- options?: {
46
- [key in Channels]?: {
47
- defaultDeliveryOption: DeliveryOptions;
48
- [DeliveryOptions.OFF]: {
49
- enabled: boolean;
50
- };
51
- [DeliveryOptions.INSTANT]: {
52
- enabled: boolean;
53
- };
54
- [DeliveryOptions.HOURLY]: {
55
- enabled: boolean;
56
- };
57
- [DeliveryOptions.DAILY]: {
58
- enabled: boolean;
59
- hour: string;
60
- };
61
- [DeliveryOptions.WEEKLY]: {
62
- enabled: boolean;
63
- hour: string;
64
- day: string;
65
- };
66
- [DeliveryOptions.MONTHLY]: {
67
- enabled: boolean;
68
- hour: string;
69
- date: "first" | "last";
70
- };
71
- };
72
- };
73
- }
74
- export interface Preferences {
75
- preferences: {
76
- notificationId: string;
77
- channel: Channels;
78
- delivery: DeliveryOptions;
79
- subNotificationId?: string;
80
- }[];
81
- notifications: {
82
- notificationId: string;
83
- title: string;
84
- channels: Channels[];
85
- options: NotificationConfig["options"];
86
- }[];
87
- subNotifications: {
88
- notificationId: string;
89
- subNotificationId: string;
90
- title: string;
91
- }[];
92
- }
93
4
  export type Context = {
94
5
  notifications?: InAppNotification[];
95
- preferences?: Preferences;
6
+ preferences?: GetPreferencesResponse;
96
7
  loadNotifications: (initial?: boolean) => void;
97
8
  markAsOpened: () => void;
98
9
  markAsArchived: (ids: string[] | "ALL") => void;
99
10
  markAsUnarchived: (ids: string[] | "ALL") => void;
100
- markAsClicked: (id: string) => void;
101
- updateDelivery: (notificationId: string, channel: Channels, delivery: DeliveryOptions, subNotificationId?: string) => void;
11
+ markAsClicked: (ids: string[]) => void;
12
+ updateDelivery: (notificationId: string, channel: Channels, delivery: DeliveryOptionsForEmail | DeliveryOptionsForInappWeb | BaseDeliveryOptions, subNotificationId?: string) => void;
102
13
  };
103
14
  export declare const NotificationAPIContext: import('react').Context<Context | undefined>;
104
15
  type Props = {
@@ -1,19 +1,140 @@
1
- import { jsx as W } from "react/jsx-runtime";
2
- import { createContext as _, useState as u, useEffect as y, useContext as B } from "react";
3
- import { api as d } from "../../api.js";
4
- const z = {
5
- opened: "opened",
6
- clicked: "clicked",
7
- archived: "archived",
8
- replied: "replied",
9
- actioned1: "actioned1",
10
- actioned2: "actioned2"
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))($ || {}), b = /* @__PURE__ */ ((e) => (e.OFF = "off", e.INSTANT = "instant", e.HOURLY = "hourly", e.DAILY = "daily", e.WEEKLY = "weekly", e.MONTHLY = "monthly", e))(b || {});
13
- const N = _(
1
+ import { jsx as M } from "react/jsx-runtime";
2
+ import { createContext as $, useState as N, useEffect as E, useContext as U } from "react";
3
+ const j = async (e, o, d, r, f, g, l) => {
4
+ const h = T(r, f, g), u = await fetch(
5
+ `https://${o}/${r}/users/${encodeURIComponent(
6
+ f
7
+ )}/${d}`,
8
+ {
9
+ method: e,
10
+ body: JSON.stringify(l),
11
+ headers: {
12
+ Authorization: `Basic ${h}`
13
+ }
14
+ }
15
+ );
16
+ try {
17
+ return await u.json();
18
+ } catch {
19
+ return;
20
+ }
21
+ }, T = (e, o, d) => btoa(d ? e + ":" + o + ":" + d : e + ":" + o), D = {
22
+ host: "api.notificationapi.com",
23
+ websocketHost: "ws.notificationapi.com",
24
+ userId: "",
25
+ clientId: "",
26
+ hashedUserId: "",
27
+ getInAppDefaultCount: 100,
28
+ getInAppDefaultOldest: new Date(
29
+ Date.now() - 2592e6
30
+ ).toISOString(),
31
+ onNewInAppNotifications: void 0,
32
+ keepWebSocketAliveForSeconds: 86400
33
+ // 24 hours
34
+ }, n = {
35
+ config: D,
36
+ init: function(e) {
37
+ return this.config = { ...D, ...e }, {
38
+ ...this
39
+ };
40
+ },
41
+ rest: {
42
+ generic: function(e, o, d) {
43
+ return j(
44
+ e,
45
+ n.config.host,
46
+ o,
47
+ n.config.clientId,
48
+ n.config.userId,
49
+ n.config.hashedUserId,
50
+ d
51
+ );
52
+ },
53
+ getNotifications: function(e, o) {
54
+ return n.rest.generic(
55
+ "GET",
56
+ `notifications/INAPP_WEB?count=${o}&before=${e}`
57
+ );
58
+ },
59
+ patchNotifications: function(e) {
60
+ return n.rest.generic(
61
+ "PATCH",
62
+ "notifications/INAPP_WEB",
63
+ e
64
+ );
65
+ },
66
+ getPreferences: function() {
67
+ return n.rest.generic("GET", "preferences");
68
+ },
69
+ postPreferences: function(e) {
70
+ return n.rest.generic(
71
+ "POST",
72
+ "preferences",
73
+ e
74
+ );
75
+ }
76
+ },
77
+ websocket: {
78
+ object: void 0,
79
+ connect: function() {
80
+ let e = `wss://${n.config.websocketHost}?userId=${n.config.userId}&envId=${n.config.clientId}`;
81
+ return n.config.hashedUserId && (e += `&userIdHash=${n.config.hashedUserId}`), n.websocket.object = new WebSocket(e), n.websocket.object.onmessage = (o) => {
82
+ const d = JSON.parse(o.data);
83
+ if (!(!d || !d.route) && d.route === "inapp_web/new_notifications") {
84
+ const r = d;
85
+ n.config.onNewInAppNotifications && n.config.onNewInAppNotifications(
86
+ r.payload.notifications
87
+ );
88
+ }
89
+ }, n.websocket.object;
90
+ },
91
+ disconnect: function(e) {
92
+ var o;
93
+ n.websocket.object && ((o = n.websocket.object) == null || o.close(), e && e(n.websocket.object));
94
+ }
95
+ },
96
+ openWebSocket: function() {
97
+ return n.websocket.connect(() => {
98
+ setTimeout(() => {
99
+ this.websocket.disconnect(() => {
100
+ this.websocket.connect();
101
+ });
102
+ }, 54e4);
103
+ });
104
+ },
105
+ getInAppNotifications: async (e) => {
106
+ const o = e.maxCountNeeded || n.config.getInAppDefaultCount, d = e.oldestNeeded || n.config.getInAppDefaultOldest;
107
+ let r = [], f = e.before, g = !0, l = !0;
108
+ for (; l; ) {
109
+ const h = (await n.rest.getNotifications(
110
+ f,
111
+ o
112
+ )).notifications.filter(
113
+ (u) => !r.find((w) => w.id === u.id)
114
+ );
115
+ f = h.reduce(
116
+ (u, w) => u < w.date ? u : w.date,
117
+ e.before
118
+ ), r = [...r, ...h], g = h.length > 0, l = !0, (!g || r.length >= o || f < d) && (l = !1);
119
+ }
120
+ return {
121
+ items: r,
122
+ hasMore: g,
123
+ oldestReceived: f
124
+ };
125
+ },
126
+ updateInAppNotifications: async (e) => {
127
+ const o = {
128
+ trackingIds: e.ids
129
+ };
130
+ return e.archived === !0 ? o.archived = (/* @__PURE__ */ new Date()).toISOString() : e.archived === !1 && (o.archived = null), e.clicked === !0 ? o.clicked = (/* @__PURE__ */ new Date()).toISOString() : e.clicked === !1 && (o.clicked = null), e.opened === !0 ? o.opened = (/* @__PURE__ */ new Date()).toISOString() : e.opened === !1 && (o.opened = null), n.rest.patchNotifications(o);
131
+ },
132
+ getPreferences: async () => n.rest.getPreferences(),
133
+ updateDeliveryOption: async (e) => n.rest.postPreferences([e])
134
+ }, m = $(
14
135
  void 0
15
- ), Y = (e) => {
16
- const r = {
136
+ ), W = (e) => {
137
+ const d = {
17
138
  ...{
18
139
  apiURL: "https://api.notificationapi.com",
19
140
  wsURL: "wss://ws.notificationapi.com",
@@ -21,206 +142,118 @@ const N = _(
21
142
  initialLoadMaxAge: new Date((/* @__PURE__ */ new Date()).setMonth((/* @__PURE__ */ new Date()).getMonth() - 3))
22
143
  },
23
144
  ...e
24
- }, [s, f] = u(), [E, h] = u(), [m, L] = u(!1), [M, A] = u((/* @__PURE__ */ new Date()).toISOString()), [k, g] = u(!0), P = (i) => {
25
- const n = (/* @__PURE__ */ new Date()).toISOString();
26
- f((t) => (i = i.filter((o) => !(o.expDate && new Date(o.expDate * 1e3).toISOString() > n || o.date > n)), t ? [
27
- ...i.filter((o) => !t.find((a) => a.id === o.id)),
28
- ...t
29
- ] : i));
30
- }, T = async (i, n) => (await d(
31
- r.apiURL,
32
- "GET",
33
- `notifications/INAPP_WEB?count=${i}&before=${n}`,
34
- e.clientId,
35
- e.userId,
36
- e.hashedUserId
37
- )).notifications, R = async (i, n, t) => {
38
- let o = [], a = i, c = !0, w = !0;
39
- for (; w; ) {
40
- const S = (await T(
41
- n,
42
- new Date(a).getTime()
43
- )).filter(
44
- (I) => !o.find((l) => l.id === I.id)
45
- );
46
- a = S.reduce(
47
- (I, l) => I < l.date ? I : l.date,
48
- i
49
- ), o = [...o, ...S], c = S.length > 0, w = !0, (!c || o.length >= n || t && a < t) && (w = !1);
145
+ }, [r, f] = N(), [g, l] = N(), [h, u] = N(!1), [w, S] = N((/* @__PURE__ */ new Date()).toISOString()), [v, b] = N(!0), A = (c) => {
146
+ const s = (/* @__PURE__ */ new Date()).toISOString();
147
+ f((i) => (c = c.filter((t) => !(t.expDate && new Date(t.expDate * 1e3).toISOString() > s || t.date > s)), i ? [
148
+ ...c.filter((t) => !i.find((a) => a.id === t.id)),
149
+ ...i
150
+ ] : c));
151
+ }, p = n.init({
152
+ clientId: e.clientId,
153
+ userId: e.userId,
154
+ hashedUserId: e.hashedUserId,
155
+ onNewInAppNotifications: (c) => {
156
+ A(c);
50
157
  }
51
- return {
52
- notifications: o,
53
- couldLoadMore: c,
54
- oldestReceived: a
55
- };
56
- }, U = async (i) => {
57
- if (!i && !k || !i && m)
158
+ }), k = async (c) => {
159
+ if (!c && !v || !c && h)
58
160
  return;
59
- L(!0);
60
- const n = await R(
61
- i ? (/* @__PURE__ */ new Date()).toISOString() : M,
62
- i ? r.initialLoadMaxCount : 1e3,
63
- i ? r.initialLoadMaxAge.toISOString() : void 0
161
+ u(!0);
162
+ const s = await p.rest.getNotifications(
163
+ c ? (/* @__PURE__ */ new Date()).toISOString() : w,
164
+ c ? d.initialLoadMaxCount : 1e3
64
165
  );
65
- A(n.oldestReceived), g(n.couldLoadMore), P(n.notifications), L(!1);
66
- }, v = async (i) => {
67
- const n = (/* @__PURE__ */ new Date()).toISOString();
68
- d(
69
- r.apiURL,
70
- "PATCH",
71
- "notifications/INAPP_WEB",
72
- e.clientId,
73
- e.userId,
74
- e.hashedUserId,
75
- {
76
- trackingIds: [i],
77
- clicked: n
78
- }
79
- ), f((t) => {
166
+ S(s.oldestReceived), b(s.couldLoadMore), A(s.notifications), u(!1);
167
+ }, O = async (c) => {
168
+ if (!r)
169
+ return;
170
+ const s = (/* @__PURE__ */ new Date()).toISOString(), i = r.filter((t) => c.includes(t.id) && !t.clicked).map((t) => t.id);
171
+ p.updateInAppNotifications({ ids: i, clicked: !0 }), f((t) => {
80
172
  if (!t)
81
173
  return [];
82
- const o = [...t], a = o.find((c) => c.id === i);
83
- return a && (a.clicked = n), o;
174
+ const a = [...t];
175
+ return a.filter((I) => i.includes(I.id)).forEach((I) => {
176
+ I.clicked = s;
177
+ }), a;
84
178
  });
85
- }, x = async () => {
86
- if (!s)
179
+ }, P = async () => {
180
+ if (!r)
87
181
  return;
88
- const i = (/* @__PURE__ */ new Date()).toISOString(), n = s.filter((t) => !t.opened || !t.seen).map((t) => t.id);
89
- n.length !== 0 && (d(
90
- r.apiURL,
91
- "PATCH",
92
- "notifications/INAPP_WEB",
93
- e.clientId,
94
- e.userId,
95
- e.hashedUserId,
96
- {
97
- trackingIds: n,
98
- opened: i
99
- }
100
- ), f((t) => {
101
- if (!t)
182
+ const c = (/* @__PURE__ */ new Date()).toISOString(), s = r.filter((i) => !i.opened || !i.seen).map((i) => i.id);
183
+ s.length !== 0 && (p.updateInAppNotifications({
184
+ ids: s,
185
+ opened: !0
186
+ }), f((i) => {
187
+ if (!i)
102
188
  return [];
103
- const o = [...t];
104
- return o.filter((a) => n.includes(a.id)).forEach((a) => {
105
- a.opened = i, a.seen = !0;
106
- }), o;
189
+ const t = [...i];
190
+ return t.filter((a) => s.includes(a.id)).forEach((a) => {
191
+ a.opened = c, a.seen = !0;
192
+ }), t;
107
193
  }));
108
- }, O = async (i) => {
109
- if (!s)
194
+ }, y = async (c) => {
195
+ if (!r)
110
196
  return;
111
- const n = s.filter((t) => t.archived && (i === "ALL" || i.includes(t.id))).map((t) => t.id);
112
- n.length !== 0 && (d(
113
- r.apiURL,
114
- "PATCH",
115
- "notifications/INAPP_WEB",
116
- e.clientId,
117
- e.userId,
118
- e.hashedUserId,
119
- {
120
- trackingIds: n,
121
- archived: null
122
- }
123
- ), f((t) => {
124
- if (!t)
197
+ const s = r.filter((i) => i.archived && (c === "ALL" || c.includes(i.id))).map((i) => i.id);
198
+ s.length !== 0 && (p.updateInAppNotifications({
199
+ ids: s,
200
+ archived: !1
201
+ }), f((i) => {
202
+ if (!i)
125
203
  return [];
126
- const o = [...t];
127
- return o.filter((a) => n.includes(a.id)).forEach((a) => {
204
+ const t = [...i];
205
+ return t.filter((a) => s.includes(a.id)).forEach((a) => {
128
206
  a.archived = void 0;
129
- }), o;
207
+ }), t;
130
208
  }));
131
- }, C = async (i) => {
132
- if (!s)
209
+ }, C = async (c) => {
210
+ if (!r)
133
211
  return;
134
- const n = (/* @__PURE__ */ new Date()).toISOString(), t = s.filter((o) => !o.archived && (i === "ALL" || i.includes(o.id))).map((o) => o.id);
135
- t.length !== 0 && (d(
136
- r.apiURL,
137
- "PATCH",
138
- "notifications/INAPP_WEB",
139
- e.clientId,
140
- e.userId,
141
- e.hashedUserId,
142
- {
143
- trackingIds: t,
144
- archived: n
145
- }
146
- ), f((o) => {
147
- if (!o)
212
+ const s = (/* @__PURE__ */ new Date()).toISOString(), i = r.filter((t) => !t.archived && (c === "ALL" || c.includes(t.id))).map((t) => t.id);
213
+ i.length !== 0 && (p.updateInAppNotifications({ ids: i, archived: !0 }), f((t) => {
214
+ if (!t)
148
215
  return [];
149
- const a = [...o];
150
- return a.filter((c) => t.includes(c.id)).forEach((c) => {
151
- c.archived = n;
216
+ const a = [...t];
217
+ return a.filter((I) => i.includes(I.id)).forEach((I) => {
218
+ I.archived = s;
152
219
  }), a;
153
220
  }));
154
- }, D = (i, n, t, o) => {
155
- d(
156
- r.apiURL,
157
- "POST",
158
- "preferences",
159
- e.clientId,
160
- e.userId,
161
- e.hashedUserId,
162
- [
163
- {
164
- notificationId: i,
165
- subNotificationId: o,
166
- channel: n,
167
- delivery: t
168
- }
169
- ]
170
- ).then(() => {
171
- d(
172
- r.apiURL,
173
- "GET",
174
- "preferences",
175
- e.clientId,
176
- e.userId,
177
- e.hashedUserId
178
- ).then((a) => {
179
- h(a);
221
+ }, x = (c, s, i, t) => {
222
+ p.updateDeliveryOption({
223
+ notificationId: c,
224
+ channel: s,
225
+ delivery: i,
226
+ subNotificationId: t
227
+ }).then(() => {
228
+ p.getPreferences().then((a) => {
229
+ l(a);
180
230
  });
181
231
  });
182
232
  };
183
- y(() => {
184
- f([]), L(!1), h(void 0), A((/* @__PURE__ */ new Date()).toISOString()), g(!0), U(!0);
185
- const i = new WebSocket(
186
- r.hashedUserId ? `${r.wsURL}?userId=${r.userId}&envId=${r.clientId}&userIdHash=${r.hashedUserId}` : `${r.wsURL}?userId=${r.userId}&envId=${r.clientId}`
187
- );
188
- i.onmessage = (n) => {
189
- const t = JSON.parse(n.data);
190
- !t || !t.route || t.route === "inapp_web/new_notifications" && P(t.payload.notifications);
191
- }, d(
192
- r.apiURL,
193
- "GET",
194
- "preferences",
195
- e.clientId,
196
- e.userId,
197
- e.hashedUserId
198
- ).then((n) => {
199
- h(n);
233
+ E(() => {
234
+ f([]), u(!1), l(void 0), S((/* @__PURE__ */ new Date()).toISOString()), b(!0), k(!0), p.openWebSocket(), p.getPreferences().then((c) => {
235
+ l(c);
200
236
  });
201
237
  }, [e]);
202
- const H = {
203
- notifications: s,
204
- preferences: E,
205
- loadNotifications: U,
206
- markAsOpened: x,
238
+ const L = {
239
+ notifications: r,
240
+ preferences: g,
241
+ loadNotifications: k,
242
+ markAsOpened: P,
207
243
  markAsArchived: C,
208
- markAsUnarchived: O,
209
- markAsClicked: v,
210
- updateDelivery: D
244
+ markAsUnarchived: y,
245
+ markAsClicked: O,
246
+ updateDelivery: x
211
247
  };
212
- return /* @__PURE__ */ W(N.Provider, { value: H, children: e.children });
213
- }, F = () => {
214
- const e = B(N);
248
+ return /* @__PURE__ */ M(m.Provider, { value: L, children: e.children });
249
+ }, H = () => {
250
+ const e = U(m);
215
251
  if (!e)
216
252
  throw new Error("useMyContext must be used within a MyProvider");
217
253
  return e;
218
254
  };
219
- Y.useNotificationAPIContext = F;
255
+ W.useNotificationAPIContext = H;
220
256
  export {
221
- $ as Channels,
222
- b as DeliveryOptions,
223
- z as NOTIFICATION_ACTIONS,
224
- N as NotificationAPIContext,
225
- Y as NotificationAPIProvider
257
+ m as NotificationAPIContext,
258
+ W as NotificationAPIProvider
226
259
  };