@notificationapi/react 1.4.1 → 1.5.0

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 (44) hide show
  1. package/dist/assets/Badge.js +1 -1
  2. package/dist/assets/Box.js +13 -13
  3. package/dist/assets/Button.js +781 -0
  4. package/dist/assets/ButtonBase.js +409 -622
  5. package/dist/assets/DefaultPropsProvider.js +220 -215
  6. package/dist/assets/Divider.js +105 -154
  7. package/dist/assets/Grow.js +201 -0
  8. package/dist/assets/IconButton.js +1 -1
  9. package/dist/assets/List.js +142 -0
  10. package/dist/assets/Modal.js +1094 -0
  11. package/dist/assets/Notification.js +71 -71
  12. package/dist/assets/Paper.js +1 -1
  13. package/dist/assets/Popover.js +8 -6
  14. package/dist/assets/Portal.js +2 -2
  15. package/dist/assets/Stack.js +216 -0
  16. package/dist/assets/Typography.js +193 -117
  17. package/dist/assets/WebPushOptInMessage.js +40 -814
  18. package/dist/assets/createSvgIcon.js +5 -5
  19. package/dist/assets/dividerClasses.js +56 -0
  20. package/dist/assets/index.js +151 -0
  21. package/dist/assets/useTheme2.js +253 -11
  22. package/dist/assets/utils.js +4 -4
  23. package/dist/components/Notifications/Inbox.js +2927 -9
  24. package/dist/components/Notifications/InboxHeader.js +2146 -7
  25. package/dist/components/Notifications/NotificationFeed.js +13 -13
  26. package/dist/components/Notifications/NotificationLauncher.js +2 -2
  27. package/dist/components/Notifications/NotificationPopup.js +7 -7
  28. package/dist/components/Preferences/NotificationPreferencesPopup.js +608 -7
  29. package/dist/components/Preferences/PreferenceInput.js +1451 -6
  30. package/dist/components/Preferences/Preferences.js +368 -515
  31. package/dist/components/Preferences/index.js +1 -1
  32. package/dist/components/Provider/index.js +226 -202
  33. package/dist/components/Slack/SlackConnect.d.ts +12 -0
  34. package/dist/components/Slack/SlackConnect.js +4826 -0
  35. package/dist/components/Slack/index.d.ts +1 -0
  36. package/dist/components/Slack/index.js +4 -0
  37. package/dist/components/WebPush/WebPushOptInMessage.js +3 -2
  38. package/dist/main.d.ts +1 -0
  39. package/dist/main.js +5 -3
  40. package/package.json +4 -4
  41. package/dist/assets/Inbox.js +0 -3061
  42. package/dist/assets/InboxHeader.js +0 -2338
  43. package/dist/assets/NotificationPreferencesPopup.js +0 -1694
  44. package/dist/assets/PreferenceInput.js +0 -1657
@@ -1,12 +1,12 @@
1
1
  import { jsx as oe } from "react/jsx-runtime";
2
- import { useMemo as z, useState as N, useCallback as A, useRef as F, useEffect as E, useContext as ie } from "react";
3
- import { NotificationAPIContext as V } from "./context.js";
2
+ import { useMemo as K, useState as k, useCallback as A, useRef as F, useEffect as E, useContext as ie } from "react";
3
+ import { NotificationAPIContext as B } from "./context.js";
4
4
  import { createDebugLogger as ne, formatApiCall as C } from "../../utils/debug.js";
5
- const re = async (o, e, u, a, c, h, I, l) => {
6
- const p = se(a, c, h), b = `https://${e}/${a}/users/${encodeURIComponent(
5
+ const re = async (o, e, d, a, c, p, I, l) => {
6
+ const h = se(a, c, p), b = `https://${e}/${a}/users/${encodeURIComponent(
7
7
  c
8
- )}/${u}`, w = {
9
- Authorization: `Basic ${p}`
8
+ )}/${d}`, w = {
9
+ Authorization: `Basic ${h}`
10
10
  };
11
11
  l && l.log("HTTP Request:", {
12
12
  method: o,
@@ -14,7 +14,7 @@ const re = async (o, e, u, a, c, h, I, l) => {
14
14
  url: b,
15
15
  body: I
16
16
  });
17
- const v = Date.now();
17
+ const N = Date.now();
18
18
  try {
19
19
  const m = await fetch(b, {
20
20
  method: o,
@@ -30,7 +30,7 @@ const re = async (o, e, u, a, c, h, I, l) => {
30
30
  return;
31
31
  }
32
32
  } catch (m) {
33
- const P = Date.now() - v;
33
+ const P = Date.now() - N;
34
34
  throw l && l.error("HTTP Request Failed:", {
35
35
  error: m,
36
36
  url: b,
@@ -38,8 +38,8 @@ const re = async (o, e, u, a, c, h, I, l) => {
38
38
  duration: `${P}ms`
39
39
  }), m;
40
40
  }
41
- }, se = (o, e, u) => btoa(u ? o + ":" + e + ":" + u : o + ":" + e);
42
- class B {
41
+ }, se = (o, e, d) => btoa(d ? o + ":" + e + ":" + d : o + ":" + e);
42
+ class G {
43
43
  constructor(e = !1) {
44
44
  this.debug = e;
45
45
  }
@@ -66,12 +66,13 @@ const J = {
66
66
  onNewInAppNotifications: void 0,
67
67
  keepWebSocketAliveForSeconds: 24 * 60 * 60,
68
68
  // 24 hours
69
- debug: !1
70
- }, s = {
69
+ debug: !1,
70
+ sdkDevMode: !1
71
+ }, n = {
71
72
  config: J,
72
- logger: new B(!1),
73
+ logger: new G(!1),
73
74
  init: function(o) {
74
- return this.config = { ...J, ...o }, this.logger = new B(this.config.debug), this.logger.log("Initialized with config:", {
75
+ return this.config = { ...J, ...o }, this.logger = new G(this.config.debug), this.logger.log("Initialized with config:", {
75
76
  userId: this.config.userId,
76
77
  clientId: this.config.clientId,
77
78
  host: this.config.host,
@@ -83,92 +84,92 @@ const J = {
83
84
  };
84
85
  },
85
86
  rest: {
86
- generic: function(o, e, u) {
87
- return s.logger.log(
87
+ generic: function(o, e, d) {
88
+ return n.logger.log(
88
89
  `API Call: ${o} ${e}`,
89
- u ? { body: u } : ""
90
+ d ? { body: d } : ""
90
91
  ), re(
91
92
  o,
92
- s.config.host,
93
+ n.config.host,
93
94
  e,
94
- s.config.clientId,
95
- s.config.userId,
96
- s.config.hashedUserId,
97
- u,
98
- s.logger
95
+ n.config.clientId,
96
+ n.config.userId,
97
+ n.config.hashedUserId,
98
+ d,
99
+ n.logger
99
100
  );
100
101
  },
101
102
  // The functions below are nice wrappers over the generic
102
103
  // rest api function above. They must follow REST API naming:
103
104
  // Method + Resource, representing the end-point.
104
105
  getNotifications: function(o, e) {
105
- return s.rest.generic(
106
+ return n.rest.generic(
106
107
  "GET",
107
108
  `notifications/INAPP_WEB?count=${e}&before=${o}`
108
109
  );
109
110
  },
110
111
  patchNotifications: function(o) {
111
- return s.rest.generic(
112
+ return n.rest.generic(
112
113
  "PATCH",
113
114
  "notifications/INAPP_WEB",
114
115
  o
115
116
  );
116
117
  },
117
118
  getPreferences: function() {
118
- return s.rest.generic("GET", "preferences");
119
+ return n.rest.generic("GET", "preferences");
119
120
  },
120
121
  postPreferences: function(o) {
121
- return s.rest.generic(
122
+ return n.rest.generic(
122
123
  "POST",
123
124
  "preferences",
124
125
  o
125
126
  );
126
127
  },
127
128
  postUser: function(o) {
128
- return s.rest.generic("POST", "", o);
129
+ return n.rest.generic("POST", "", o);
129
130
  },
130
131
  getUserAccountMetadata: function() {
131
- return s.rest.generic("GET", "account_metadata");
132
+ return n.rest.generic("GET", "account_metadata");
132
133
  }
133
134
  },
134
135
  websocket: {
135
136
  object: void 0,
136
137
  connect: function() {
137
- let o = `wss://${s.config.websocketHost}?userId=${encodeURIComponent(s.config.userId)}&envId=${s.config.clientId}`;
138
- return s.config.hashedUserId && (o += `&userIdHash=${encodeURIComponent(s.config.hashedUserId)}`), s.logger.log("WebSocket connecting to:", o), s.websocket.object = new WebSocket(o), s.websocket.object.onopen = () => {
139
- s.logger.log("WebSocket connection opened");
140
- }, s.websocket.object.onclose = (e) => {
141
- s.logger.log("WebSocket connection closed:", {
138
+ let o = `wss://${n.config.websocketHost}?userId=${encodeURIComponent(n.config.userId)}&envId=${n.config.clientId}`;
139
+ return n.config.hashedUserId && (o += `&userIdHash=${encodeURIComponent(n.config.hashedUserId)}`), n.logger.log("WebSocket connecting to:", o), n.websocket.object = new WebSocket(o), n.websocket.object.onopen = () => {
140
+ n.logger.log("WebSocket connection opened");
141
+ }, n.websocket.object.onclose = (e) => {
142
+ n.logger.log("WebSocket connection closed:", {
142
143
  code: e.code,
143
144
  reason: e.reason,
144
145
  wasClean: e.wasClean
145
146
  });
146
- }, s.websocket.object.onerror = (e) => {
147
- s.logger.error("WebSocket error:", e);
148
- }, s.websocket.object.onmessage = (e) => {
149
- s.logger.log(
147
+ }, n.websocket.object.onerror = (e) => {
148
+ n.logger.error("WebSocket error:", e);
149
+ }, n.websocket.object.onmessage = (e) => {
150
+ n.logger.log(
150
151
  "WebSocket message received:",
151
152
  e.data
152
153
  );
153
- const u = JSON.parse(e.data);
154
- if (!(!u || !u.route) && u.route === "inapp_web/new_notifications") {
155
- const a = u;
156
- s.logger.log(
154
+ const d = JSON.parse(e.data);
155
+ if (!(!d || !d.route) && d.route === "inapp_web/new_notifications") {
156
+ const a = d;
157
+ n.logger.log(
157
158
  "New notifications received:",
158
159
  a.payload.notifications
159
- ), s.config.onNewInAppNotifications && s.config.onNewInAppNotifications(
160
+ ), n.config.onNewInAppNotifications && n.config.onNewInAppNotifications(
160
161
  a.payload.notifications
161
162
  );
162
163
  }
163
- }, s.websocket.object;
164
+ }, n.websocket.object;
164
165
  },
165
166
  disconnect: function(o) {
166
167
  var e;
167
- s.websocket.object && (s.logger.log("WebSocket disconnecting"), (e = s.websocket.object) == null || e.close(), o && o(s.websocket.object));
168
+ n.websocket.object && (n.logger.log("WebSocket disconnecting"), (e = n.websocket.object) == null || e.close(), o && o(n.websocket.object));
168
169
  }
169
170
  },
170
171
  openWebSocket: function() {
171
- return s.websocket.connect(() => {
172
+ return n.websocket.connect(() => {
172
173
  setTimeout(
173
174
  () => {
174
175
  this.websocket.disconnect(() => {
@@ -183,72 +184,95 @@ const J = {
183
184
  // They may or may not do additional tasks.
184
185
  // e.g. identify simply maps to postUsers
185
186
  getInAppNotifications: async (o) => {
186
- s.logger.log(
187
+ n.logger.log(
187
188
  "getInAppNotifications called with params:",
188
189
  o
189
190
  );
190
- const e = o.maxCountNeeded || s.config.getInAppDefaultCount, u = o.oldestNeeded || s.config.getInAppDefaultOldest;
191
- s.logger.log("Fetching notifications with:", {
191
+ const e = o.maxCountNeeded || n.config.getInAppDefaultCount, d = o.oldestNeeded || n.config.getInAppDefaultOldest;
192
+ n.logger.log("Fetching notifications with:", {
192
193
  maxCountNeeded: e,
193
- oldestNeeded: u,
194
+ oldestNeeded: d,
194
195
  before: o.before
195
196
  });
196
- let a = [], c = o.before, h = !0, I = !0;
197
+ let a = [], c = o.before, p = !0, I = !0;
197
198
  for (; I; ) {
198
- const l = (await s.rest.getNotifications(
199
+ const l = (await n.rest.getNotifications(
199
200
  c,
200
201
  e
201
- )).notifications, p = l.filter(
202
+ )).notifications, h = l.filter(
202
203
  (b) => !a.find((w) => w.id === b.id)
203
204
  );
204
- s.logger.log(
205
- `Received ${l.length} notifications, ${p.length} unique`
206
- ), c = p.reduce(
205
+ n.logger.log(
206
+ `Received ${l.length} notifications, ${h.length} unique`
207
+ ), c = h.reduce(
207
208
  (b, w) => b < w.date ? b : w.date,
208
209
  o.before
209
- ), a = [...a, ...p], h = p.length > 0, I = !0, (!h || a.length >= e || c < u) && (I = !1, s.logger.log("Stopping fetch loop:", {
210
- hasMore: h,
210
+ ), a = [...a, ...h], p = h.length > 0, I = !0, (!p || a.length >= e || c < d) && (I = !1, n.logger.log("Stopping fetch loop:", {
211
+ hasMore: p,
211
212
  totalResults: a.length,
212
213
  maxCountNeeded: e,
213
214
  oldestReceived: c,
214
- oldestNeeded: u
215
+ oldestNeeded: d
215
216
  }));
216
217
  }
217
- return s.logger.log("getInAppNotifications completed:", {
218
+ return n.logger.log("getInAppNotifications completed:", {
218
219
  totalItems: a.length,
219
- hasMore: h,
220
+ hasMore: p,
220
221
  oldestReceived: c
221
222
  }), {
222
223
  items: a,
223
- hasMore: h,
224
+ hasMore: p,
224
225
  oldestReceived: c
225
226
  };
226
227
  },
227
228
  updateInAppNotifications: async (o) => {
228
- s.logger.log(
229
+ n.logger.log(
229
230
  "updateInAppNotifications called with params:",
230
231
  o
231
232
  );
232
233
  const e = {
233
234
  trackingIds: o.ids
234
235
  };
235
- return o.archived === !0 ? e.archived = (/* @__PURE__ */ new Date()).toISOString() : o.archived === !1 && (e.archived = null), o.clicked === !0 ? e.clicked = (/* @__PURE__ */ new Date()).toISOString() : o.clicked === !1 && (e.clicked = null), o.opened === !0 ? e.opened = (/* @__PURE__ */ new Date()).toISOString() : o.opened === !1 && (e.opened = null), s.logger.log(
236
+ return o.archived === !0 ? e.archived = (/* @__PURE__ */ new Date()).toISOString() : o.archived === !1 && (e.archived = null), o.clicked === !0 ? e.clicked = (/* @__PURE__ */ new Date()).toISOString() : o.clicked === !1 && (e.clicked = null), o.opened === !0 ? e.opened = (/* @__PURE__ */ new Date()).toISOString() : o.opened === !1 && (e.opened = null), n.logger.log(
236
237
  "Updating notifications with body:",
237
238
  e
238
- ), s.rest.patchNotifications(e);
239
+ ), n.rest.patchNotifications(e);
239
240
  },
240
- getPreferences: async () => s.rest.getPreferences(),
241
- updateDeliveryOption: async (o) => s.rest.postPreferences([o]),
241
+ getPreferences: async () => n.rest.getPreferences(),
242
+ updateDeliveryOption: async (o) => n.rest.postPreferences([o]),
242
243
  identify: async (o) => {
243
- if (o.id && o.id !== s.config.userId)
244
+ if (o.id && o.id !== n.config.userId)
244
245
  throw new Error(
245
246
  "The id in the parameters does not match the initialized userId."
246
247
  );
247
- return s.rest.postUser(o);
248
+ return n.rest.postUser(o);
248
249
  },
249
- getUserAccountMetadata: async () => s.rest.getUserAccountMetadata()
250
- }, G = typeof window < "u", ae = (o) => {
251
- const e = z(
250
+ getUserAccountMetadata: async () => n.rest.getUserAccountMetadata(),
251
+ user: {
252
+ get: async () => n.rest.generic("GET", "")
253
+ },
254
+ slack: {
255
+ getOAuthUrl: (o) => {
256
+ const e = n.config.sdkDevMode ? "localhost:3001" : n.config.host.replace("api.", "app."), d = (o == null ? void 0 : o.destinationUrl) || window.location.href, a = encodeURIComponent(
257
+ JSON.stringify({
258
+ destination: d,
259
+ userId: n.config.userId,
260
+ clientId: n.config.clientId,
261
+ hashedUserId: n.config.hashedUserId
262
+ })
263
+ );
264
+ return `https://slack.com/oauth/v2/authorize?client_id=1146598856352.8825220259395&scope=chat:write,channels:read,channels:join,chat:write.customize,chat:write.public,groups:read,im:read,users:read&redirect_uri=https://${e}/slack/oauth/callback&state=${a}`;
265
+ },
266
+ getChannels: async () => await n.rest.generic(
267
+ "GET",
268
+ "slack/channels"
269
+ ),
270
+ setChannel: async (o) => n.identify({
271
+ slackChannel: o
272
+ })
273
+ }
274
+ }, V = typeof window < "u", ae = (o) => {
275
+ const e = K(
252
276
  () => ne(o.debug || !1),
253
277
  [o.debug]
254
278
  );
@@ -273,11 +297,11 @@ const J = {
273
297
  user: "userId" in o ? { id: o.userId } : o.user
274
298
  };
275
299
  e.log("Configuration loaded", a);
276
- const [c, h] = N(), [I, l] = N(), [p, b] = N(), [w, v] = N(!1), [m, P] = N((/* @__PURE__ */ new Date()).toISOString()), [D, x] = N(!0), [k, y] = N(a.webPushOptInMessage), [M, Q] = N(!1), $ = A(() => {
300
+ const [c, p] = k(), [I, l] = k(), [h, b] = k(), [w, N] = k(!1), [m, P] = k((/* @__PURE__ */ new Date()).toISOString()), [U, x] = k(!0), [v, y] = k(a.webPushOptInMessage), [M, _] = k(!1), $ = A(() => {
277
301
  a.playSoundOnNewNotification && (e.log("Playing notification sound", {
278
302
  soundPath: a.newNotificationSoundPath
279
- }), new Audio(a.newNotificationSoundPath).play().catch((n) => {
280
- e.error("Failed to play new notification sound", n), console.log("Failed to play new notification sound:", n);
303
+ }), new Audio(a.newNotificationSoundPath).play().catch((r) => {
304
+ e.error("Failed to play new notification sound", r), console.log("Failed to play new notification sound:", r);
281
305
  }));
282
306
  }, [
283
307
  a.newNotificationSoundPath,
@@ -289,19 +313,19 @@ const J = {
289
313
  count: (t == null ? void 0 : t.length) || 0,
290
314
  notifications: t
291
315
  });
292
- const n = (/* @__PURE__ */ new Date()).toISOString();
293
- h((i) => {
294
- const r = (i == null ? void 0 : i.length) || 0;
295
- e.log("Current notifications count", r), t = Array.isArray(t) ? t : [], t = t.filter((g) => {
296
- const S = g.expDate && new Date(g.expDate).toISOString() > n, L = new Date(g.date).getTime() > new Date(n).getTime() + 1e3, K = !S && !L;
297
- return K || e.log("Filtering out notification", {
316
+ const r = (/* @__PURE__ */ new Date()).toISOString();
317
+ p((i) => {
318
+ const s = (i == null ? void 0 : i.length) || 0;
319
+ e.log("Current notifications count", s), t = Array.isArray(t) ? t : [], t = t.filter((g) => {
320
+ const S = g.expDate && new Date(g.expDate).toISOString() > r, L = new Date(g.date).getTime() > new Date(r).getTime() + 1e3, z = !S && !L;
321
+ return z || e.log("Filtering out notification", {
298
322
  id: g.id,
299
323
  reason: S ? "expired" : "future",
300
324
  expDate: g.expDate,
301
325
  date: g.date
302
- }), K;
326
+ }), z;
303
327
  }), i = Array.isArray(i) ? i : [];
304
- const d = [
328
+ const u = [
305
329
  ...t.filter((g) => {
306
330
  const S = i.find((L) => L.id === g.id);
307
331
  return S && e.log("Filtering out duplicate notification", { id: g.id }), !S;
@@ -309,14 +333,14 @@ const J = {
309
333
  ...i
310
334
  ];
311
335
  return e.log("State updated", {
312
- previousCount: r,
313
- newCount: d.length,
336
+ previousCount: s,
337
+ newCount: u.length,
314
338
  addedCount: t.length
315
- }), e.groupEnd(), d;
339
+ }), e.groupEnd(), u;
316
340
  });
317
341
  },
318
342
  [e]
319
- ), f = z(() => {
343
+ ), f = K(() => {
320
344
  e.group("Initializing NotificationAPI client");
321
345
  const t = {
322
346
  clientId: a.clientId,
@@ -327,19 +351,19 @@ const J = {
327
351
  debug: a.debug
328
352
  };
329
353
  e.log("Client configuration", t);
330
- const n = o.client ? o.client : s.init({
354
+ const r = o.client ? o.client : n.init({
331
355
  ...t,
332
- onNewInAppNotifications: (r) => {
356
+ onNewInAppNotifications: (s) => {
333
357
  e.log("Received new in-app notifications via WebSocket", {
334
- count: (r == null ? void 0 : r.length) || 0,
335
- notifications: r
336
- }), $(), O(r);
358
+ count: (s == null ? void 0 : s.length) || 0,
359
+ notifications: s
360
+ }), $(), O(s);
337
361
  }
338
362
  }), i = {
339
363
  email: a.user.email,
340
364
  number: a.user.number
341
365
  };
342
- return e.log("Identifying user", i), n.identify(i), e.groupEnd(), n;
366
+ return e.log("Identifying user", i), r.identify(i), e.groupEnd(), r;
343
367
  }, [
344
368
  a.clientId,
345
369
  a.user.id,
@@ -354,57 +378,57 @@ const J = {
354
378
  a.wsURL,
355
379
  e
356
380
  ]), j = A(
357
- async (t, n) => {
381
+ async (t, r) => {
358
382
  var i;
359
383
  e.group("Fetching notifications"), e.log(
360
384
  "Fetch parameters",
361
- C("GET", "/notifications", { date: t, count: n })
385
+ C("GET", "/notifications", { date: t, count: r })
362
386
  );
363
387
  try {
364
- const r = await f.rest.getNotifications(t, n);
388
+ const s = await f.rest.getNotifications(t, r);
365
389
  e.log("Fetch successful", {
366
- notificationsCount: ((i = r.notifications) == null ? void 0 : i.length) || 0,
367
- oldestReceived: r.oldestReceived,
368
- couldLoadMore: r.couldLoadMore
369
- }), P(r.oldestReceived), x(r.couldLoadMore), O(r.notifications), e.groupEnd();
370
- } catch (r) {
371
- throw e.error("Failed to fetch notifications", r, { date: t, count: n }), e.groupEnd(), r;
390
+ notificationsCount: ((i = s.notifications) == null ? void 0 : i.length) || 0,
391
+ oldestReceived: s.oldestReceived,
392
+ couldLoadMore: s.couldLoadMore
393
+ }), P(s.oldestReceived), x(s.couldLoadMore), O(s.notifications), e.groupEnd();
394
+ } catch (s) {
395
+ throw e.error("Failed to fetch notifications", s, { date: t, count: r }), e.groupEnd(), s;
372
396
  }
373
397
  },
374
398
  [O, f.rest, e]
375
- ), U = F(D), W = F(w), q = F(m);
399
+ ), D = F(U), T = F(w), q = F(m);
376
400
  E(() => {
377
- U.current = D, W.current = w, q.current = m;
378
- }, [D, w, m]);
379
- const T = A(
401
+ D.current = U, T.current = w, q.current = m;
402
+ }, [U, w, m]);
403
+ const W = A(
380
404
  async (t) => {
381
405
  if (e.group(`Loading notifications (${t ? "initial" : "more"})`), e.log("Load conditions", {
382
406
  initial: t,
383
- hasMore: U.current,
384
- loading: W.current
385
- }), !t && (!U.current || W.current)) {
407
+ hasMore: D.current,
408
+ loading: T.current
409
+ }), !t && (!D.current || T.current)) {
386
410
  e.log("Skipping load - conditions not met"), e.groupEnd();
387
411
  return;
388
412
  }
389
- v(!0), e.log("Loading started");
413
+ N(!0), e.log("Loading started");
390
414
  try {
391
415
  await j(
392
416
  t ? (/* @__PURE__ */ new Date()).toISOString() : q.current,
393
417
  t ? a.initialLoadMaxCount : 1e3
394
418
  ), e.log("Loading completed successfully");
395
- } catch (n) {
396
- throw e.error("Loading failed", n), n;
419
+ } catch (r) {
420
+ throw e.error("Loading failed", r), r;
397
421
  } finally {
398
- v(!1), e.groupEnd();
422
+ N(!1), e.groupEnd();
399
423
  }
400
424
  },
401
425
  [a.initialLoadMaxCount, j, e]
402
- ), X = async (t) => {
426
+ ), Q = async (t) => {
403
427
  if (e.group("Marking notifications as clicked"), e.log("Requested IDs", t), !c) {
404
428
  e.warn("No notifications available"), e.groupEnd();
405
429
  return;
406
430
  }
407
- const n = (/* @__PURE__ */ new Date()).toISOString(), i = c.filter((r) => t.includes(r.id) && !r.clicked).map((r) => r.id);
431
+ const r = (/* @__PURE__ */ new Date()).toISOString(), i = c.filter((s) => t.includes(s.id) && !s.clicked).map((s) => s.id);
408
432
  if (e.log("Filtered IDs for update", {
409
433
  requestedCount: t.length,
410
434
  actualCount: i.length,
@@ -417,79 +441,79 @@ const J = {
417
441
  e.log(
418
442
  "Updating notifications via API",
419
443
  C("PUT", "/notifications/clicked", { ids: i })
420
- ), f.updateInAppNotifications({ ids: i, clicked: !0 }), h((r) => {
421
- if (!r) return [];
422
- const d = [...r];
423
- return d.filter((g) => i.includes(g.id)).forEach((g) => {
424
- g.clicked = n;
425
- }), e.log("Local state updated", { updatedCount: i.length }), d;
444
+ ), f.updateInAppNotifications({ ids: i, clicked: !0 }), p((s) => {
445
+ if (!s) return [];
446
+ const u = [...s];
447
+ return u.filter((g) => i.includes(g.id)).forEach((g) => {
448
+ g.clicked = r;
449
+ }), e.log("Local state updated", { updatedCount: i.length }), u;
426
450
  }), e.groupEnd();
427
- } catch (r) {
428
- throw e.error("Failed to mark notifications as clicked", r, { ids: i }), e.groupEnd(), r;
451
+ } catch (s) {
452
+ throw e.error("Failed to mark notifications as clicked", s, { ids: i }), e.groupEnd(), s;
429
453
  }
430
- }, Y = async () => {
454
+ }, X = async () => {
431
455
  if (e.group("Marking notifications as opened"), !c) {
432
456
  e.warn("No notifications available"), e.groupEnd();
433
457
  return;
434
458
  }
435
- const t = (/* @__PURE__ */ new Date()).toISOString(), n = c.filter((i) => !i.opened || !i.seen).map((i) => i.id);
436
- if (e.log("Notifications to mark as opened", { count: n.length, ids: n }), n.length === 0) {
459
+ const t = (/* @__PURE__ */ new Date()).toISOString(), r = c.filter((i) => !i.opened || !i.seen).map((i) => i.id);
460
+ if (e.log("Notifications to mark as opened", { count: r.length, ids: r }), r.length === 0) {
437
461
  e.log("All notifications already opened"), e.groupEnd();
438
462
  return;
439
463
  }
440
464
  try {
441
465
  e.log(
442
466
  "Updating notifications via API",
443
- C("PUT", "/notifications/opened", { ids: n })
467
+ C("PUT", "/notifications/opened", { ids: r })
444
468
  ), f.updateInAppNotifications({
445
- ids: n,
469
+ ids: r,
446
470
  opened: !0
447
- }), h((i) => {
471
+ }), p((i) => {
448
472
  if (!i) return [];
449
- const r = [...i];
450
- return r.filter((d) => n.includes(d.id)).forEach((d) => {
451
- d.opened = t, d.seen = !0;
452
- }), e.log("Local state updated", { updatedCount: n.length }), r;
473
+ const s = [...i];
474
+ return s.filter((u) => r.includes(u.id)).forEach((u) => {
475
+ u.opened = t, u.seen = !0;
476
+ }), e.log("Local state updated", { updatedCount: r.length }), s;
453
477
  }), e.groupEnd();
454
478
  } catch (i) {
455
- throw e.error("Failed to mark notifications as opened", i, { ids: n }), e.groupEnd(), i;
479
+ throw e.error("Failed to mark notifications as opened", i, { ids: r }), e.groupEnd(), i;
456
480
  }
457
- }, Z = async (t) => {
481
+ }, Y = async (t) => {
458
482
  if (e.group("Marking notifications as unarchived"), e.log("Requested operation", { ids: t }), !c) {
459
483
  e.warn("No notifications available"), e.groupEnd();
460
484
  return;
461
485
  }
462
- const n = c.filter((i) => i.archived && (t === "ALL" || t.includes(i.id))).map((i) => i.id);
486
+ const r = c.filter((i) => i.archived && (t === "ALL" || t.includes(i.id))).map((i) => i.id);
463
487
  if (e.log("Filtered notifications for unarchiving", {
464
- count: n.length,
465
- ids: n
466
- }), n.length === 0) {
488
+ count: r.length,
489
+ ids: r
490
+ }), r.length === 0) {
467
491
  e.log("No archived notifications to unarchive"), e.groupEnd();
468
492
  return;
469
493
  }
470
494
  try {
471
495
  e.log(
472
496
  "Updating notifications via API",
473
- C("PUT", "/notifications/unarchived", { ids: n })
497
+ C("PUT", "/notifications/unarchived", { ids: r })
474
498
  ), f.updateInAppNotifications({
475
- ids: n,
499
+ ids: r,
476
500
  archived: !1
477
- }), h((i) => {
501
+ }), p((i) => {
478
502
  if (!i) return [];
479
- const r = [...i];
480
- return r.filter((d) => n.includes(d.id)).forEach((d) => {
481
- d.archived = void 0;
482
- }), e.log("Local state updated", { unarchivedCount: n.length }), r;
503
+ const s = [...i];
504
+ return s.filter((u) => r.includes(u.id)).forEach((u) => {
505
+ u.archived = void 0;
506
+ }), e.log("Local state updated", { unarchivedCount: r.length }), s;
483
507
  }), e.groupEnd();
484
508
  } catch (i) {
485
- throw e.error("Failed to unarchive notifications", i, { ids: n }), e.groupEnd(), i;
509
+ throw e.error("Failed to unarchive notifications", i, { ids: r }), e.groupEnd(), i;
486
510
  }
487
- }, _ = async (t) => {
511
+ }, Z = async (t) => {
488
512
  if (e.group("Marking notifications as archived"), e.log("Requested operation", { ids: t }), !c) {
489
513
  e.warn("No notifications available"), e.groupEnd();
490
514
  return;
491
515
  }
492
- const n = (/* @__PURE__ */ new Date()).toISOString(), i = c.filter((r) => !r.archived && (t === "ALL" || t.includes(r.id))).map((r) => r.id);
516
+ const r = (/* @__PURE__ */ new Date()).toISOString(), i = c.filter((s) => !s.archived && (t === "ALL" || t.includes(s.id))).map((s) => s.id);
493
517
  if (e.log("Filtered notifications for archiving", {
494
518
  count: i.length,
495
519
  ids: i
@@ -501,27 +525,27 @@ const J = {
501
525
  e.log(
502
526
  "Updating notifications via API",
503
527
  C("PUT", "/notifications/archived", { ids: i })
504
- ), f.updateInAppNotifications({ ids: i, archived: !0 }), h((r) => {
505
- if (!r) return [];
506
- const d = [...r];
507
- return d.filter((g) => i.includes(g.id)).forEach((g) => {
508
- g.archived = n;
509
- }), e.log("Local state updated", { archivedCount: i.length }), d;
528
+ ), f.updateInAppNotifications({ ids: i, archived: !0 }), p((s) => {
529
+ if (!s) return [];
530
+ const u = [...s];
531
+ return u.filter((g) => i.includes(g.id)).forEach((g) => {
532
+ g.archived = r;
533
+ }), e.log("Local state updated", { archivedCount: i.length }), u;
510
534
  }), e.groupEnd();
511
- } catch (r) {
512
- throw e.error("Failed to archive notifications", r, { ids: i }), e.groupEnd(), r;
535
+ } catch (s) {
536
+ throw e.error("Failed to archive notifications", s, { ids: i }), e.groupEnd(), s;
513
537
  }
514
- }, ee = (t, n, i, r) => (e.log("Updating single delivery preference", {
538
+ }, ee = (t, r, i, s) => (e.log("Updating single delivery preference", {
515
539
  notificationId: t,
516
- channel: n,
540
+ channel: r,
517
541
  delivery: i,
518
- subNotificationId: r
542
+ subNotificationId: s
519
543
  }), H([
520
544
  {
521
545
  notificationId: t,
522
- channel: n,
546
+ channel: r,
523
547
  delivery: i,
524
- subNotificationId: r
548
+ subNotificationId: s
525
549
  }
526
550
  ])), H = (t) => {
527
551
  e.group("Updating delivery preferences"), e.log("Preference updates", { count: t.length, params: t });
@@ -529,34 +553,34 @@ const J = {
529
553
  f.rest.postPreferences(t).then(() => {
530
554
  e.log(
531
555
  "Preferences updated successfully, fetching latest preferences"
532
- ), f.getPreferences().then((n) => {
533
- var i, r, d;
556
+ ), f.getPreferences().then((r) => {
557
+ var i, s, u;
534
558
  e.log("Latest preferences fetched", {
535
- preferencesCount: ((i = n.preferences) == null ? void 0 : i.length) || 0,
536
- notificationsCount: ((r = n.notifications) == null ? void 0 : r.length) || 0,
537
- subNotificationsCount: ((d = n.subNotifications) == null ? void 0 : d.length) || 0
538
- }), l(n), e.groupEnd();
539
- }).catch((n) => {
540
- e.error("Failed to fetch updated preferences", n), e.groupEnd();
559
+ preferencesCount: ((i = r.preferences) == null ? void 0 : i.length) || 0,
560
+ notificationsCount: ((s = r.notifications) == null ? void 0 : s.length) || 0,
561
+ subNotificationsCount: ((u = r.subNotifications) == null ? void 0 : u.length) || 0
562
+ }), l(r), e.groupEnd();
563
+ }).catch((r) => {
564
+ e.error("Failed to fetch updated preferences", r), e.groupEnd();
541
565
  });
542
- }).catch((n) => {
543
- e.error("Failed to update preferences", n, { params: t }), e.groupEnd();
566
+ }).catch((r) => {
567
+ e.error("Failed to update preferences", r, { params: t }), e.groupEnd();
544
568
  });
545
- } catch (n) {
546
- throw e.error("Error in updateDeliveries", n, { params: t }), e.groupEnd(), n;
569
+ } catch (r) {
570
+ throw e.error("Error in updateDeliveries", r, { params: t }), e.groupEnd(), r;
547
571
  }
548
572
  }, R = A(() => {
549
573
  e.group("Requesting web push permission"), e.log("Service worker support check", {
550
574
  supported: "serviceWorker" in navigator,
551
575
  customServiceWorkerPath: a.customServiceWorkerPath
552
576
  }), "serviceWorker" in navigator ? (e.log("Registering service worker"), navigator.serviceWorker.register(a.customServiceWorkerPath).then(async (t) => {
553
- e.log("Service worker registered successfully"), y(!1), de().then(async (n) => {
554
- e.log("Notification permission result", { permission: n }), n === "granted" ? (e.log("Permission granted, subscribing to push manager"), await t.pushManager.subscribe({
577
+ e.log("Service worker registered successfully"), y(!1), de().then(async (r) => {
578
+ e.log("Notification permission result", { permission: r }), r === "granted" ? (e.log("Permission granted, subscribing to push manager"), await t.pushManager.subscribe({
555
579
  userVisibleOnly: !0,
556
- applicationServerKey: p == null ? void 0 : p.userAccountMetadata.environmentVapidPublicKey
580
+ applicationServerKey: h == null ? void 0 : h.userAccountMetadata.environmentVapidPublicKey
557
581
  }).then(async (i) => {
558
582
  e.log("Push subscription successful");
559
- const r = {
583
+ const s = {
560
584
  webPushTokens: [
561
585
  {
562
586
  sub: {
@@ -566,8 +590,8 @@ const J = {
566
590
  }
567
591
  ]
568
592
  };
569
- e.log("Identifying user with web push tokens"), await f.identify(r), localStorage.setItem("hideWebPushOptInMessage", "true"), e.log("Web push setup completed successfully"), e.groupEnd();
570
- })) : n === "denied" && (e.warn("Permission for notifications was denied"), console.log("Permission for notifications was denied"), e.groupEnd());
593
+ e.log("Identifying user with web push tokens"), await f.identify(s), localStorage.setItem("hideWebPushOptInMessage", "true"), e.log("Web push setup completed successfully"), e.groupEnd();
594
+ })) : r === "denied" && (e.warn("Permission for notifications was denied"), console.log("Permission for notifications was denied"), e.groupEnd());
571
595
  });
572
596
  }).catch((t) => {
573
597
  e.error(
@@ -592,26 +616,26 @@ const J = {
592
616
  }, [
593
617
  f,
594
618
  a.customServiceWorkerPath,
595
- p == null ? void 0 : p.userAccountMetadata.environmentVapidPublicKey,
619
+ h == null ? void 0 : h.userAccountMetadata.environmentVapidPublicKey,
596
620
  e
597
621
  ]);
598
622
  E(() => {
599
- e.group("Provider initialization effect"), e.log("Resetting state and loading initial data"), h([]), v(!1), l(void 0), P((/* @__PURE__ */ new Date()).toISOString()), x(!0), T(!0), e.log("Opening WebSocket connection"), f.openWebSocket(), e.log("Fetching user preferences"), f.getPreferences().then((t) => {
600
- var n, i, r;
623
+ e.group("Provider initialization effect"), e.log("Resetting state and loading initial data"), p([]), N(!1), l(void 0), P((/* @__PURE__ */ new Date()).toISOString()), x(!0), W(!0), e.log("Opening WebSocket connection"), f.openWebSocket(), e.log("Fetching user preferences"), f.getPreferences().then((t) => {
624
+ var r, i, s;
601
625
  e.log("Initial preferences loaded", {
602
- preferencesCount: ((n = t.preferences) == null ? void 0 : n.length) || 0,
626
+ preferencesCount: ((r = t.preferences) == null ? void 0 : r.length) || 0,
603
627
  notificationsCount: ((i = t.notifications) == null ? void 0 : i.length) || 0,
604
- subNotificationsCount: ((r = t.subNotifications) == null ? void 0 : r.length) || 0
628
+ subNotificationsCount: ((s = t.subNotifications) == null ? void 0 : s.length) || 0
605
629
  }), l(t), e.groupEnd();
606
630
  }).catch((t) => {
607
631
  e.error("Failed to fetch initial preferences", t), e.groupEnd();
608
632
  });
609
- }, [f, T, R, e]), E(() => {
633
+ }, [f, W, R, e]), E(() => {
610
634
  e.group("Fetching user account metadata"), f.getUserAccountMetadata().then((t) => {
611
635
  e.log("User account metadata loaded", {
612
636
  hasWebPushEnabled: t.userAccountMetadata.hasWebPushEnabled,
613
637
  environmentVapidPublicKey: t.userAccountMetadata.environmentVapidPublicKey ? "present" : "missing"
614
- }), b(t), G && "Notification" in window && typeof Notification.requestPermission == "function" ? (e.log("Browser notification support detected", {
638
+ }), b(t), V && "Notification" in window && typeof Notification.requestPermission == "function" ? (e.log("Browser notification support detected", {
615
639
  permission: Notification.permission
616
640
  }), Notification.permission !== "default" && (e.log(
617
641
  "Setting webPushOptInMessage to false (permission already set)"
@@ -625,7 +649,7 @@ const J = {
625
649
  e.error("Failed to fetch user account metadata", t), e.groupEnd();
626
650
  });
627
651
  }, [f, e]), E(() => {
628
- if (e.group("Handling webPushOptInMessage state"), e.log("webPushOptInMessage value", k), k === "AUTOMATIC") {
652
+ if (e.group("Handling webPushOptInMessage state"), e.log("webPushOptInMessage value", v), v === "AUTOMATIC") {
629
653
  const t = localStorage.getItem("hideWebPushOptInMessage") === "true";
630
654
  e.log("Automatic mode - checking localStorage", {
631
655
  hideMessage: t,
@@ -633,41 +657,41 @@ const J = {
633
657
  }), y(!t);
634
658
  }
635
659
  e.groupEnd();
636
- }, [k, e]), E(() => {
660
+ }, [v, e]), E(() => {
637
661
  e.group("Handling webPushOptIn state"), e.log("webPushOptIn state", M), M && (e.log("User opted in for web push, requesting permission"), R()), e.groupEnd();
638
662
  }, [M, R, e]);
639
663
  const te = {
640
664
  notifications: c,
641
665
  preferences: I,
642
- userAccountMetaData: p,
643
- webPushOptInMessage: k,
644
- loadNotifications: T,
645
- markAsOpened: Y,
646
- markAsArchived: _,
647
- markAsUnarchived: Z,
648
- markAsClicked: X,
666
+ userAccountMetaData: h,
667
+ webPushOptInMessage: v,
668
+ loadNotifications: W,
669
+ markAsOpened: X,
670
+ markAsArchived: Z,
671
+ markAsUnarchived: Y,
672
+ markAsClicked: Q,
649
673
  updateDelivery: ee,
650
674
  updateDeliveries: H,
651
675
  getClient: () => f,
652
676
  setWebPushOptInMessage: y,
653
- setWebPushOptIn: Q
677
+ setWebPushOptIn: _
654
678
  };
655
679
  return e.log("NotificationAPI Provider rendering", {
656
680
  notificationsCount: (c == null ? void 0 : c.length) || 0,
657
681
  hasPreferences: !!I,
658
- hasUserAccountMetaData: !!p,
659
- webPushOptInMessage: k,
682
+ hasUserAccountMetaData: !!h,
683
+ webPushOptInMessage: v,
660
684
  webPushOptIn: M
661
- }), /* @__PURE__ */ oe(V.Provider, { value: te, children: o.children });
685
+ }), /* @__PURE__ */ oe(B.Provider, { value: te, children: o.children });
662
686
  }, ce = () => {
663
- const o = ie(V);
687
+ const o = ie(B);
664
688
  if (!o)
665
689
  throw new Error("useMyContext must be used within a MyProvider");
666
690
  return o;
667
691
  };
668
692
  ae.useNotificationAPIContext = ce;
669
693
  const de = async () => {
670
- if (G && "Notification" in window && typeof Notification.requestPermission == "function")
694
+ if (V && "Notification" in window && typeof Notification.requestPermission == "function")
671
695
  try {
672
696
  return await Notification.requestPermission();
673
697
  } catch (o) {