@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.
- package/dist/assets/Badge.js +1 -1
- package/dist/assets/Box.js +13 -13
- package/dist/assets/Button.js +781 -0
- package/dist/assets/ButtonBase.js +409 -622
- package/dist/assets/DefaultPropsProvider.js +220 -215
- package/dist/assets/Divider.js +105 -154
- package/dist/assets/Grow.js +201 -0
- package/dist/assets/IconButton.js +1 -1
- package/dist/assets/List.js +142 -0
- package/dist/assets/Modal.js +1094 -0
- package/dist/assets/Notification.js +71 -71
- package/dist/assets/Paper.js +1 -1
- package/dist/assets/Popover.js +8 -6
- package/dist/assets/Portal.js +2 -2
- package/dist/assets/Stack.js +216 -0
- package/dist/assets/Typography.js +193 -117
- package/dist/assets/WebPushOptInMessage.js +40 -814
- package/dist/assets/createSvgIcon.js +5 -5
- package/dist/assets/dividerClasses.js +56 -0
- package/dist/assets/index.js +151 -0
- package/dist/assets/useTheme2.js +253 -11
- package/dist/assets/utils.js +4 -4
- package/dist/components/Notifications/Inbox.js +2927 -9
- package/dist/components/Notifications/InboxHeader.js +2146 -7
- package/dist/components/Notifications/NotificationFeed.js +13 -13
- package/dist/components/Notifications/NotificationLauncher.js +2 -2
- package/dist/components/Notifications/NotificationPopup.js +7 -7
- package/dist/components/Preferences/NotificationPreferencesPopup.js +608 -7
- package/dist/components/Preferences/PreferenceInput.js +1451 -6
- package/dist/components/Preferences/Preferences.js +368 -515
- package/dist/components/Preferences/index.js +1 -1
- package/dist/components/Provider/index.js +226 -202
- package/dist/components/Slack/SlackConnect.d.ts +12 -0
- package/dist/components/Slack/SlackConnect.js +4826 -0
- package/dist/components/Slack/index.d.ts +1 -0
- package/dist/components/Slack/index.js +4 -0
- package/dist/components/WebPush/WebPushOptInMessage.js +3 -2
- package/dist/main.d.ts +1 -0
- package/dist/main.js +5 -3
- package/package.json +4 -4
- package/dist/assets/Inbox.js +0 -3061
- package/dist/assets/InboxHeader.js +0 -2338
- package/dist/assets/NotificationPreferencesPopup.js +0 -1694
- 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
|
|
3
|
-
import { NotificationAPIContext as
|
|
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,
|
|
6
|
-
const
|
|
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
|
-
)}/${
|
|
9
|
-
Authorization: `Basic ${
|
|
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
|
|
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() -
|
|
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,
|
|
42
|
-
class
|
|
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
|
-
|
|
69
|
+
debug: !1,
|
|
70
|
+
sdkDevMode: !1
|
|
71
|
+
}, n = {
|
|
71
72
|
config: J,
|
|
72
|
-
logger: new
|
|
73
|
+
logger: new G(!1),
|
|
73
74
|
init: function(o) {
|
|
74
|
-
return this.config = { ...J, ...o }, this.logger = new
|
|
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,
|
|
87
|
-
return
|
|
87
|
+
generic: function(o, e, d) {
|
|
88
|
+
return n.logger.log(
|
|
88
89
|
`API Call: ${o} ${e}`,
|
|
89
|
-
|
|
90
|
+
d ? { body: d } : ""
|
|
90
91
|
), re(
|
|
91
92
|
o,
|
|
92
|
-
|
|
93
|
+
n.config.host,
|
|
93
94
|
e,
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
|
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
|
|
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
|
|
119
|
+
return n.rest.generic("GET", "preferences");
|
|
119
120
|
},
|
|
120
121
|
postPreferences: function(o) {
|
|
121
|
-
return
|
|
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
|
|
129
|
+
return n.rest.generic("POST", "", o);
|
|
129
130
|
},
|
|
130
131
|
getUserAccountMetadata: function() {
|
|
131
|
-
return
|
|
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://${
|
|
138
|
-
return
|
|
139
|
-
|
|
140
|
-
},
|
|
141
|
-
|
|
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
|
-
},
|
|
147
|
-
|
|
148
|
-
},
|
|
149
|
-
|
|
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
|
|
154
|
-
if (!(!
|
|
155
|
-
const a =
|
|
156
|
-
|
|
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
|
-
),
|
|
160
|
+
), n.config.onNewInAppNotifications && n.config.onNewInAppNotifications(
|
|
160
161
|
a.payload.notifications
|
|
161
162
|
);
|
|
162
163
|
}
|
|
163
|
-
},
|
|
164
|
+
}, n.websocket.object;
|
|
164
165
|
},
|
|
165
166
|
disconnect: function(o) {
|
|
166
167
|
var e;
|
|
167
|
-
|
|
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
|
|
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
|
-
|
|
187
|
+
n.logger.log(
|
|
187
188
|
"getInAppNotifications called with params:",
|
|
188
189
|
o
|
|
189
190
|
);
|
|
190
|
-
const e = o.maxCountNeeded ||
|
|
191
|
-
|
|
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:
|
|
194
|
+
oldestNeeded: d,
|
|
194
195
|
before: o.before
|
|
195
196
|
});
|
|
196
|
-
let a = [], c = o.before,
|
|
197
|
+
let a = [], c = o.before, p = !0, I = !0;
|
|
197
198
|
for (; I; ) {
|
|
198
|
-
const l = (await
|
|
199
|
+
const l = (await n.rest.getNotifications(
|
|
199
200
|
c,
|
|
200
201
|
e
|
|
201
|
-
)).notifications,
|
|
202
|
+
)).notifications, h = l.filter(
|
|
202
203
|
(b) => !a.find((w) => w.id === b.id)
|
|
203
204
|
);
|
|
204
|
-
|
|
205
|
-
`Received ${l.length} notifications, ${
|
|
206
|
-
), c =
|
|
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, ...
|
|
210
|
-
hasMore:
|
|
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:
|
|
215
|
+
oldestNeeded: d
|
|
215
216
|
}));
|
|
216
217
|
}
|
|
217
|
-
return
|
|
218
|
+
return n.logger.log("getInAppNotifications completed:", {
|
|
218
219
|
totalItems: a.length,
|
|
219
|
-
hasMore:
|
|
220
|
+
hasMore: p,
|
|
220
221
|
oldestReceived: c
|
|
221
222
|
}), {
|
|
222
223
|
items: a,
|
|
223
|
-
hasMore:
|
|
224
|
+
hasMore: p,
|
|
224
225
|
oldestReceived: c
|
|
225
226
|
};
|
|
226
227
|
},
|
|
227
228
|
updateInAppNotifications: async (o) => {
|
|
228
|
-
|
|
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),
|
|
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
|
-
),
|
|
239
|
+
), n.rest.patchNotifications(e);
|
|
239
240
|
},
|
|
240
|
-
getPreferences: async () =>
|
|
241
|
-
updateDeliveryOption: async (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 !==
|
|
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
|
|
248
|
+
return n.rest.postUser(o);
|
|
248
249
|
},
|
|
249
|
-
getUserAccountMetadata: async () =>
|
|
250
|
-
|
|
251
|
-
|
|
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,
|
|
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((
|
|
280
|
-
e.error("Failed to play new notification sound",
|
|
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
|
|
293
|
-
|
|
294
|
-
const
|
|
295
|
-
e.log("Current notifications count",
|
|
296
|
-
const S = g.expDate && new Date(g.expDate).toISOString() >
|
|
297
|
-
return
|
|
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
|
-
}),
|
|
326
|
+
}), z;
|
|
303
327
|
}), i = Array.isArray(i) ? i : [];
|
|
304
|
-
const
|
|
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:
|
|
313
|
-
newCount:
|
|
336
|
+
previousCount: s,
|
|
337
|
+
newCount: u.length,
|
|
314
338
|
addedCount: t.length
|
|
315
|
-
}), e.groupEnd(),
|
|
339
|
+
}), e.groupEnd(), u;
|
|
316
340
|
});
|
|
317
341
|
},
|
|
318
342
|
[e]
|
|
319
|
-
), f =
|
|
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
|
|
354
|
+
const r = o.client ? o.client : n.init({
|
|
331
355
|
...t,
|
|
332
|
-
onNewInAppNotifications: (
|
|
356
|
+
onNewInAppNotifications: (s) => {
|
|
333
357
|
e.log("Received new in-app notifications via WebSocket", {
|
|
334
|
-
count: (
|
|
335
|
-
notifications:
|
|
336
|
-
}), $(), O(
|
|
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),
|
|
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,
|
|
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:
|
|
385
|
+
C("GET", "/notifications", { date: t, count: r })
|
|
362
386
|
);
|
|
363
387
|
try {
|
|
364
|
-
const
|
|
388
|
+
const s = await f.rest.getNotifications(t, r);
|
|
365
389
|
e.log("Fetch successful", {
|
|
366
|
-
notificationsCount: ((i =
|
|
367
|
-
oldestReceived:
|
|
368
|
-
couldLoadMore:
|
|
369
|
-
}), P(
|
|
370
|
-
} catch (
|
|
371
|
-
throw e.error("Failed to fetch notifications",
|
|
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
|
-
),
|
|
399
|
+
), D = F(U), T = F(w), q = F(m);
|
|
376
400
|
E(() => {
|
|
377
|
-
|
|
378
|
-
}, [
|
|
379
|
-
const
|
|
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:
|
|
384
|
-
loading:
|
|
385
|
-
}), !t && (!
|
|
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
|
-
|
|
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 (
|
|
396
|
-
throw e.error("Loading failed",
|
|
419
|
+
} catch (r) {
|
|
420
|
+
throw e.error("Loading failed", r), r;
|
|
397
421
|
} finally {
|
|
398
|
-
|
|
422
|
+
N(!1), e.groupEnd();
|
|
399
423
|
}
|
|
400
424
|
},
|
|
401
425
|
[a.initialLoadMaxCount, j, e]
|
|
402
|
-
),
|
|
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
|
|
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 }),
|
|
421
|
-
if (!
|
|
422
|
-
const
|
|
423
|
-
return
|
|
424
|
-
g.clicked =
|
|
425
|
-
}), e.log("Local state updated", { updatedCount: i.length }),
|
|
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 (
|
|
428
|
-
throw e.error("Failed to mark notifications as clicked",
|
|
451
|
+
} catch (s) {
|
|
452
|
+
throw e.error("Failed to mark notifications as clicked", s, { ids: i }), e.groupEnd(), s;
|
|
429
453
|
}
|
|
430
|
-
},
|
|
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(),
|
|
436
|
-
if (e.log("Notifications to mark as opened", { count:
|
|
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:
|
|
467
|
+
C("PUT", "/notifications/opened", { ids: r })
|
|
444
468
|
), f.updateInAppNotifications({
|
|
445
|
-
ids:
|
|
469
|
+
ids: r,
|
|
446
470
|
opened: !0
|
|
447
|
-
}),
|
|
471
|
+
}), p((i) => {
|
|
448
472
|
if (!i) return [];
|
|
449
|
-
const
|
|
450
|
-
return
|
|
451
|
-
|
|
452
|
-
}), e.log("Local state updated", { updatedCount:
|
|
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:
|
|
479
|
+
throw e.error("Failed to mark notifications as opened", i, { ids: r }), e.groupEnd(), i;
|
|
456
480
|
}
|
|
457
|
-
},
|
|
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
|
|
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:
|
|
465
|
-
ids:
|
|
466
|
-
}),
|
|
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:
|
|
497
|
+
C("PUT", "/notifications/unarchived", { ids: r })
|
|
474
498
|
), f.updateInAppNotifications({
|
|
475
|
-
ids:
|
|
499
|
+
ids: r,
|
|
476
500
|
archived: !1
|
|
477
|
-
}),
|
|
501
|
+
}), p((i) => {
|
|
478
502
|
if (!i) return [];
|
|
479
|
-
const
|
|
480
|
-
return
|
|
481
|
-
|
|
482
|
-
}), e.log("Local state updated", { unarchivedCount:
|
|
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:
|
|
509
|
+
throw e.error("Failed to unarchive notifications", i, { ids: r }), e.groupEnd(), i;
|
|
486
510
|
}
|
|
487
|
-
},
|
|
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
|
|
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 }),
|
|
505
|
-
if (!
|
|
506
|
-
const
|
|
507
|
-
return
|
|
508
|
-
g.archived =
|
|
509
|
-
}), e.log("Local state updated", { archivedCount: i.length }),
|
|
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 (
|
|
512
|
-
throw e.error("Failed to archive notifications",
|
|
535
|
+
} catch (s) {
|
|
536
|
+
throw e.error("Failed to archive notifications", s, { ids: i }), e.groupEnd(), s;
|
|
513
537
|
}
|
|
514
|
-
}, ee = (t,
|
|
538
|
+
}, ee = (t, r, i, s) => (e.log("Updating single delivery preference", {
|
|
515
539
|
notificationId: t,
|
|
516
|
-
channel:
|
|
540
|
+
channel: r,
|
|
517
541
|
delivery: i,
|
|
518
|
-
subNotificationId:
|
|
542
|
+
subNotificationId: s
|
|
519
543
|
}), H([
|
|
520
544
|
{
|
|
521
545
|
notificationId: t,
|
|
522
|
-
channel:
|
|
546
|
+
channel: r,
|
|
523
547
|
delivery: i,
|
|
524
|
-
subNotificationId:
|
|
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((
|
|
533
|
-
var i,
|
|
556
|
+
), f.getPreferences().then((r) => {
|
|
557
|
+
var i, s, u;
|
|
534
558
|
e.log("Latest preferences fetched", {
|
|
535
|
-
preferencesCount: ((i =
|
|
536
|
-
notificationsCount: ((
|
|
537
|
-
subNotificationsCount: ((
|
|
538
|
-
}), l(
|
|
539
|
-
}).catch((
|
|
540
|
-
e.error("Failed to fetch updated preferences",
|
|
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((
|
|
543
|
-
e.error("Failed to update preferences",
|
|
566
|
+
}).catch((r) => {
|
|
567
|
+
e.error("Failed to update preferences", r, { params: t }), e.groupEnd();
|
|
544
568
|
});
|
|
545
|
-
} catch (
|
|
546
|
-
throw e.error("Error in updateDeliveries",
|
|
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 (
|
|
554
|
-
e.log("Notification permission result", { permission:
|
|
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:
|
|
580
|
+
applicationServerKey: h == null ? void 0 : h.userAccountMetadata.environmentVapidPublicKey
|
|
557
581
|
}).then(async (i) => {
|
|
558
582
|
e.log("Push subscription successful");
|
|
559
|
-
const
|
|
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(
|
|
570
|
-
})) :
|
|
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
|
-
|
|
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"),
|
|
600
|
-
var
|
|
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: ((
|
|
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: ((
|
|
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,
|
|
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),
|
|
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",
|
|
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
|
-
}, [
|
|
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:
|
|
643
|
-
webPushOptInMessage:
|
|
644
|
-
loadNotifications:
|
|
645
|
-
markAsOpened:
|
|
646
|
-
markAsArchived:
|
|
647
|
-
markAsUnarchived:
|
|
648
|
-
markAsClicked:
|
|
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:
|
|
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: !!
|
|
659
|
-
webPushOptInMessage:
|
|
682
|
+
hasUserAccountMetaData: !!h,
|
|
683
|
+
webPushOptInMessage: v,
|
|
660
684
|
webPushOptIn: M
|
|
661
|
-
}), /* @__PURE__ */ oe(
|
|
685
|
+
}), /* @__PURE__ */ oe(B.Provider, { value: te, children: o.children });
|
|
662
686
|
}, ce = () => {
|
|
663
|
-
const o = ie(
|
|
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 (
|
|
694
|
+
if (V && "Notification" in window && typeof Notification.requestPermission == "function")
|
|
671
695
|
try {
|
|
672
696
|
return await Notification.requestPermission();
|
|
673
697
|
} catch (o) {
|