@notificationapi/react 1.6.2 → 1.8.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 +4 -3
- package/dist/assets/Box.js +26 -24
- package/dist/assets/Button.js +20 -18
- package/dist/assets/ButtonBase.js +193 -185
- package/dist/assets/DefaultPropsProvider.js +416 -4199
- package/dist/assets/DefaultPropsProvider2.js +992 -0
- package/dist/assets/Divider.js +2 -1
- package/dist/assets/GlobalStyles.js +23 -0
- package/dist/assets/Grow.js +87 -92
- package/dist/assets/IconButton.js +8 -7
- package/dist/assets/List.js +12 -11
- package/dist/assets/Modal.js +18 -17
- package/dist/assets/Notification.js +787 -770
- package/dist/assets/Paper.js +6 -6
- package/dist/assets/Popover.js +38 -37
- package/dist/assets/Portal.js +38 -48
- package/dist/assets/Stack.js +32 -30
- package/dist/assets/Typography.js +84 -97
- package/dist/assets/createSvgIcon.js +25 -24
- package/dist/assets/createTheme.js +2828 -0
- package/dist/assets/dividerClasses.js +16 -15
- package/dist/assets/exactProp.js +13 -0
- package/dist/assets/index.js +19 -148
- package/dist/assets/index2.js +151 -0
- package/dist/assets/useTheme.js +6 -7
- package/dist/assets/{useTheme2.js → useThemeWithoutDefault.js} +63 -67
- package/dist/assets/utils.js +2 -2
- package/dist/components/Notifications/DefaultEmpty.d.ts +0 -1
- package/dist/components/Notifications/Inbox.d.ts +0 -1
- package/dist/components/Notifications/Inbox.js +592 -582
- package/dist/components/Notifications/InboxHeader.js +31 -30
- package/dist/components/Notifications/Notification.d.ts +0 -1
- package/dist/components/Notifications/Notification.js +4 -2
- package/dist/components/Notifications/NotificationCounter.d.ts +0 -1
- package/dist/components/Notifications/NotificationFeed.d.ts +0 -1
- package/dist/components/Notifications/NotificationFeed.js +40 -32
- package/dist/components/Notifications/NotificationLauncher.d.ts +0 -1
- package/dist/components/Notifications/NotificationLauncher.js +90 -64
- package/dist/components/Notifications/NotificationPopup.d.ts +0 -1
- package/dist/components/Notifications/NotificationPopup.js +76 -65
- package/dist/components/Notifications/UnreadBadge.d.ts +0 -1
- package/dist/components/Preferences/NotificationPreferencesInline.js +57 -39
- package/dist/components/Preferences/NotificationPreferencesPopup.js +111 -99
- package/dist/components/Preferences/PreferenceInput.d.ts +0 -1
- package/dist/components/Preferences/PreferenceInput.js +427 -414
- package/dist/components/Preferences/Preferences.js +329 -278
- package/dist/components/Preferences/channelUtils.d.ts +0 -1
- package/dist/components/Provider/context.d.ts +0 -1
- package/dist/components/Provider/index.d.ts +4 -2
- package/dist/components/Provider/index.js +986 -375
- package/dist/components/Slack/SlackConnect.js +8 -7
- package/dist/components/WebPush/WebPushOptInMessage.d.ts +0 -1
- package/dist/main.d.ts +2 -1
- package/dist/main.js +6 -3
- package/dist/utils/theme.d.ts +17 -0
- package/dist/utils/theme.js +104 -0
- package/package.json +7 -3
|
@@ -1,45 +1,650 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { jsx as M, jsxs as He } from "react/jsx-runtime";
|
|
2
|
+
import * as w from "react";
|
|
3
|
+
import { useMemo as pe, useState as F, useCallback as B, useRef as Se, useEffect as ce, useContext as Ge } from "react";
|
|
4
|
+
import { NotificationAPIContext as je } from "./context.js";
|
|
5
|
+
import { createDebugLogger as ze, formatApiCall as ae } from "../../utils/debug.js";
|
|
6
|
+
import { createNotificationAPITheme as Oe } from "../../utils/theme.js";
|
|
7
|
+
import { a as Be, D as Je, T as J } from "../../assets/DefaultPropsProvider2.js";
|
|
8
|
+
import { P as I, c as Ye, t as Qe, s as Xe } from "../../assets/createTheme.js";
|
|
9
|
+
import { R as Ze } from "../../assets/index.js";
|
|
10
|
+
import { u as et } from "../../assets/useThemeWithoutDefault.js";
|
|
11
|
+
import { e as Ve } from "../../assets/exactProp.js";
|
|
12
|
+
import { G as tt } from "../../assets/GlobalStyles.js";
|
|
13
|
+
const we = /* @__PURE__ */ w.createContext(null);
|
|
14
|
+
process.env.NODE_ENV !== "production" && (we.displayName = "ThemeContext");
|
|
15
|
+
function be() {
|
|
16
|
+
const t = w.useContext(we);
|
|
17
|
+
return process.env.NODE_ENV !== "production" && w.useDebugValue(t), t;
|
|
18
|
+
}
|
|
19
|
+
const ot = typeof Symbol == "function" && Symbol.for, nt = ot ? Symbol.for("mui.nested") : "__THEME_NESTED__";
|
|
20
|
+
function it(t, e) {
|
|
21
|
+
if (typeof e == "function") {
|
|
22
|
+
const c = e(t);
|
|
23
|
+
return process.env.NODE_ENV !== "production" && (c || console.error(["MUI: You should return an object from your theme function, i.e.", "<ThemeProvider theme={() => ({})} />"].join(`
|
|
24
|
+
`))), c;
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
...t,
|
|
28
|
+
...e
|
|
10
29
|
};
|
|
11
|
-
|
|
12
|
-
|
|
30
|
+
}
|
|
31
|
+
function ge(t) {
|
|
32
|
+
const {
|
|
33
|
+
children: e,
|
|
34
|
+
theme: c
|
|
35
|
+
} = t, n = be();
|
|
36
|
+
process.env.NODE_ENV !== "production" && n === null && typeof c == "function" && console.error(["MUI: You are providing a theme function prop to the ThemeProvider component:", "<ThemeProvider theme={outerTheme => outerTheme} />", "", "However, no outer theme is present.", "Make sure a theme is already injected higher in the React tree or provide a theme object."].join(`
|
|
37
|
+
`));
|
|
38
|
+
const l = w.useMemo(() => {
|
|
39
|
+
const u = n === null ? {
|
|
40
|
+
...c
|
|
41
|
+
} : it(n, c);
|
|
42
|
+
return u != null && (u[nt] = n !== null), u;
|
|
43
|
+
}, [c, n]);
|
|
44
|
+
return /* @__PURE__ */ M(we.Provider, {
|
|
45
|
+
value: l,
|
|
46
|
+
children: e
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
process.env.NODE_ENV !== "production" && (ge.propTypes = {
|
|
50
|
+
/**
|
|
51
|
+
* Your component tree.
|
|
52
|
+
*/
|
|
53
|
+
children: I.node,
|
|
54
|
+
/**
|
|
55
|
+
* A theme object. You can provide a function to extend the outer theme.
|
|
56
|
+
*/
|
|
57
|
+
theme: I.oneOfType([I.object, I.func]).isRequired
|
|
58
|
+
});
|
|
59
|
+
process.env.NODE_ENV !== "production" && process.env.NODE_ENV !== "production" && (ge.propTypes = Ve(ge.propTypes));
|
|
60
|
+
const $e = {};
|
|
61
|
+
function Le(t, e, c, n = !1) {
|
|
62
|
+
return w.useMemo(() => {
|
|
63
|
+
const l = t && e[t] || e;
|
|
64
|
+
if (typeof c == "function") {
|
|
65
|
+
const u = c(l), d = t ? {
|
|
66
|
+
...e,
|
|
67
|
+
[t]: u
|
|
68
|
+
} : u;
|
|
69
|
+
return n ? () => d : d;
|
|
70
|
+
}
|
|
71
|
+
return t ? {
|
|
72
|
+
...e,
|
|
73
|
+
[t]: c
|
|
74
|
+
} : {
|
|
75
|
+
...e,
|
|
76
|
+
...c
|
|
77
|
+
};
|
|
78
|
+
}, [t, e, c, n]);
|
|
79
|
+
}
|
|
80
|
+
function de(t) {
|
|
81
|
+
const {
|
|
82
|
+
children: e,
|
|
83
|
+
theme: c,
|
|
84
|
+
themeId: n
|
|
85
|
+
} = t, l = et($e), u = be() || $e;
|
|
86
|
+
process.env.NODE_ENV !== "production" && (l === null && typeof c == "function" || n && l && !l[n] && typeof c == "function") && console.error(["MUI: You are providing a theme function prop to the ThemeProvider component:", "<ThemeProvider theme={outerTheme => outerTheme} />", "", "However, no outer theme is present.", "Make sure a theme is already injected higher in the React tree or provide a theme object."].join(`
|
|
87
|
+
`));
|
|
88
|
+
const d = Le(n, l, c), f = Le(n, u, c, !0), k = (n ? d[n] : d).direction === "rtl";
|
|
89
|
+
return /* @__PURE__ */ M(ge, {
|
|
90
|
+
theme: f,
|
|
91
|
+
children: /* @__PURE__ */ M(Be.Provider, {
|
|
92
|
+
value: d,
|
|
93
|
+
children: /* @__PURE__ */ M(Ze, {
|
|
94
|
+
value: k,
|
|
95
|
+
children: /* @__PURE__ */ M(Je, {
|
|
96
|
+
value: n ? d[n].components : d.components,
|
|
97
|
+
children: e
|
|
98
|
+
})
|
|
99
|
+
})
|
|
100
|
+
})
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
process.env.NODE_ENV !== "production" && (de.propTypes = {
|
|
104
|
+
// ┌────────────────────────────── Warning ──────────────────────────────┐
|
|
105
|
+
// │ These PropTypes are generated from the TypeScript type definitions. │
|
|
106
|
+
// │ To update them, edit the d.ts file and run `pnpm proptypes`. │
|
|
107
|
+
// └─────────────────────────────────────────────────────────────────────┘
|
|
108
|
+
/**
|
|
109
|
+
* Your component tree.
|
|
110
|
+
*/
|
|
111
|
+
children: I.node,
|
|
112
|
+
/**
|
|
113
|
+
* A theme object. You can provide a function to extend the outer theme.
|
|
114
|
+
*/
|
|
115
|
+
theme: I.oneOfType([I.func, I.object]).isRequired,
|
|
116
|
+
/**
|
|
117
|
+
* The design system's unique id for getting the corresponded theme when there are multiple design systems.
|
|
118
|
+
*/
|
|
119
|
+
themeId: I.string
|
|
120
|
+
});
|
|
121
|
+
process.env.NODE_ENV !== "production" && process.env.NODE_ENV !== "production" && (de.propTypes = Ve(de.propTypes));
|
|
122
|
+
const ke = "mode", Ce = "color-scheme", rt = "data-color-scheme";
|
|
123
|
+
function st(t) {
|
|
124
|
+
const {
|
|
125
|
+
defaultMode: e = "system",
|
|
126
|
+
defaultLightColorScheme: c = "light",
|
|
127
|
+
defaultDarkColorScheme: n = "dark",
|
|
128
|
+
modeStorageKey: l = ke,
|
|
129
|
+
colorSchemeStorageKey: u = Ce,
|
|
130
|
+
attribute: d = rt,
|
|
131
|
+
colorSchemeNode: f = "document.documentElement",
|
|
132
|
+
nonce: k
|
|
133
|
+
} = t || {};
|
|
134
|
+
let S = "", y = d;
|
|
135
|
+
if (d === "class" && (y = ".%s"), d === "data" && (y = "[data-%s]"), y.startsWith(".")) {
|
|
136
|
+
const b = y.substring(1);
|
|
137
|
+
S += `${f}.classList.remove('${b}'.replace('%s', light), '${b}'.replace('%s', dark));
|
|
138
|
+
${f}.classList.add('${b}'.replace('%s', colorScheme));`;
|
|
139
|
+
}
|
|
140
|
+
const P = y.match(/\[([^\]]+)\]/);
|
|
141
|
+
if (P) {
|
|
142
|
+
const [b, N] = P[1].split("=");
|
|
143
|
+
N || (S += `${f}.removeAttribute('${b}'.replace('%s', light));
|
|
144
|
+
${f}.removeAttribute('${b}'.replace('%s', dark));`), S += `
|
|
145
|
+
${f}.setAttribute('${b}'.replace('%s', colorScheme), ${N ? `${N}.replace('%s', colorScheme)` : '""'});`;
|
|
146
|
+
} else
|
|
147
|
+
S += `${f}.setAttribute('${y}', colorScheme);`;
|
|
148
|
+
return /* @__PURE__ */ M("script", {
|
|
149
|
+
suppressHydrationWarning: !0,
|
|
150
|
+
nonce: typeof window > "u" ? k : "",
|
|
151
|
+
dangerouslySetInnerHTML: {
|
|
152
|
+
__html: `(function() {
|
|
153
|
+
try {
|
|
154
|
+
let colorScheme = '';
|
|
155
|
+
const mode = localStorage.getItem('${l}') || '${e}';
|
|
156
|
+
const dark = localStorage.getItem('${u}-dark') || '${n}';
|
|
157
|
+
const light = localStorage.getItem('${u}-light') || '${c}';
|
|
158
|
+
if (mode === 'system') {
|
|
159
|
+
// handle system mode
|
|
160
|
+
const mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
161
|
+
if (mql.matches) {
|
|
162
|
+
colorScheme = dark
|
|
163
|
+
} else {
|
|
164
|
+
colorScheme = light
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (mode === 'light') {
|
|
168
|
+
colorScheme = light;
|
|
169
|
+
}
|
|
170
|
+
if (mode === 'dark') {
|
|
171
|
+
colorScheme = dark;
|
|
172
|
+
}
|
|
173
|
+
if (colorScheme) {
|
|
174
|
+
${S}
|
|
175
|
+
}
|
|
176
|
+
} catch(e){}})();`
|
|
177
|
+
}
|
|
178
|
+
}, "mui-color-scheme-init");
|
|
179
|
+
}
|
|
180
|
+
function Ue(t) {
|
|
181
|
+
if (typeof window < "u" && typeof window.matchMedia == "function" && t === "system")
|
|
182
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
183
|
+
}
|
|
184
|
+
function _e(t, e) {
|
|
185
|
+
if (t.mode === "light" || t.mode === "system" && t.systemMode === "light")
|
|
186
|
+
return e("light");
|
|
187
|
+
if (t.mode === "dark" || t.mode === "system" && t.systemMode === "dark")
|
|
188
|
+
return e("dark");
|
|
189
|
+
}
|
|
190
|
+
function ct(t) {
|
|
191
|
+
return _e(t, (e) => {
|
|
192
|
+
if (e === "light")
|
|
193
|
+
return t.lightColorScheme;
|
|
194
|
+
if (e === "dark")
|
|
195
|
+
return t.darkColorScheme;
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
function ye(t, e) {
|
|
199
|
+
if (typeof window > "u")
|
|
200
|
+
return;
|
|
201
|
+
let c;
|
|
202
|
+
try {
|
|
203
|
+
c = localStorage.getItem(t) || void 0, c || localStorage.setItem(t, e);
|
|
204
|
+
} catch {
|
|
205
|
+
}
|
|
206
|
+
return c || e;
|
|
207
|
+
}
|
|
208
|
+
function at(t) {
|
|
209
|
+
const {
|
|
210
|
+
defaultMode: e = "light",
|
|
211
|
+
defaultLightColorScheme: c,
|
|
212
|
+
defaultDarkColorScheme: n,
|
|
213
|
+
supportedColorSchemes: l = [],
|
|
214
|
+
modeStorageKey: u = ke,
|
|
215
|
+
colorSchemeStorageKey: d = Ce,
|
|
216
|
+
storageWindow: f = typeof window > "u" ? void 0 : window,
|
|
217
|
+
noSsr: k = !1
|
|
218
|
+
} = t, S = l.join(","), y = l.length > 1, [P, b] = w.useState(() => {
|
|
219
|
+
const h = ye(u, e), g = ye(`${d}-light`, c), m = ye(`${d}-dark`, n);
|
|
220
|
+
return {
|
|
221
|
+
mode: h,
|
|
222
|
+
systemMode: Ue(h),
|
|
223
|
+
lightColorScheme: g,
|
|
224
|
+
darkColorScheme: m
|
|
225
|
+
};
|
|
226
|
+
}), [N, K] = w.useState(k || !y);
|
|
227
|
+
w.useEffect(() => {
|
|
228
|
+
K(!0);
|
|
229
|
+
}, []);
|
|
230
|
+
const G = ct(P), R = w.useCallback((h) => {
|
|
231
|
+
b((g) => {
|
|
232
|
+
if (h === g.mode)
|
|
233
|
+
return g;
|
|
234
|
+
const m = h ?? e;
|
|
235
|
+
try {
|
|
236
|
+
localStorage.setItem(u, m);
|
|
237
|
+
} catch {
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
...g,
|
|
241
|
+
mode: m,
|
|
242
|
+
systemMode: Ue(m)
|
|
243
|
+
};
|
|
244
|
+
});
|
|
245
|
+
}, [u, e]), A = w.useCallback((h) => {
|
|
246
|
+
h ? typeof h == "string" ? h && !S.includes(h) ? console.error(`\`${h}\` does not exist in \`theme.colorSchemes\`.`) : b((g) => {
|
|
247
|
+
const m = {
|
|
248
|
+
...g
|
|
249
|
+
};
|
|
250
|
+
return _e(g, (D) => {
|
|
251
|
+
try {
|
|
252
|
+
localStorage.setItem(`${d}-${D}`, h);
|
|
253
|
+
} catch {
|
|
254
|
+
}
|
|
255
|
+
D === "light" && (m.lightColorScheme = h), D === "dark" && (m.darkColorScheme = h);
|
|
256
|
+
}), m;
|
|
257
|
+
}) : b((g) => {
|
|
258
|
+
const m = {
|
|
259
|
+
...g
|
|
260
|
+
}, D = h.light === null ? c : h.light, p = h.dark === null ? n : h.dark;
|
|
261
|
+
if (D)
|
|
262
|
+
if (!S.includes(D))
|
|
263
|
+
console.error(`\`${D}\` does not exist in \`theme.colorSchemes\`.`);
|
|
264
|
+
else {
|
|
265
|
+
m.lightColorScheme = D;
|
|
266
|
+
try {
|
|
267
|
+
localStorage.setItem(`${d}-light`, D);
|
|
268
|
+
} catch {
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (p)
|
|
272
|
+
if (!S.includes(p))
|
|
273
|
+
console.error(`\`${p}\` does not exist in \`theme.colorSchemes\`.`);
|
|
274
|
+
else {
|
|
275
|
+
m.darkColorScheme = p;
|
|
276
|
+
try {
|
|
277
|
+
localStorage.setItem(`${d}-dark`, p);
|
|
278
|
+
} catch {
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return m;
|
|
282
|
+
}) : b((g) => {
|
|
283
|
+
try {
|
|
284
|
+
localStorage.setItem(`${d}-light`, c), localStorage.setItem(`${d}-dark`, n);
|
|
285
|
+
} catch {
|
|
286
|
+
}
|
|
287
|
+
return {
|
|
288
|
+
...g,
|
|
289
|
+
lightColorScheme: c,
|
|
290
|
+
darkColorScheme: n
|
|
291
|
+
};
|
|
292
|
+
});
|
|
293
|
+
}, [S, d, c, n]), j = w.useCallback((h) => {
|
|
294
|
+
P.mode === "system" && b((g) => {
|
|
295
|
+
const m = h != null && h.matches ? "dark" : "light";
|
|
296
|
+
return g.systemMode === m ? g : {
|
|
297
|
+
...g,
|
|
298
|
+
systemMode: m
|
|
299
|
+
};
|
|
300
|
+
});
|
|
301
|
+
}, [P.mode]), _ = w.useRef(j);
|
|
302
|
+
return _.current = j, w.useEffect(() => {
|
|
303
|
+
if (typeof window.matchMedia != "function" || !y)
|
|
304
|
+
return;
|
|
305
|
+
const h = (...m) => _.current(...m), g = window.matchMedia("(prefers-color-scheme: dark)");
|
|
306
|
+
return g.addListener(h), h(g), () => {
|
|
307
|
+
g.removeListener(h);
|
|
308
|
+
};
|
|
309
|
+
}, [y]), w.useEffect(() => {
|
|
310
|
+
if (f && y) {
|
|
311
|
+
const h = (g) => {
|
|
312
|
+
const m = g.newValue;
|
|
313
|
+
typeof g.key == "string" && g.key.startsWith(d) && (!m || S.match(m)) && (g.key.endsWith("light") && A({
|
|
314
|
+
light: m
|
|
315
|
+
}), g.key.endsWith("dark") && A({
|
|
316
|
+
dark: m
|
|
317
|
+
})), g.key === u && (!m || ["light", "dark", "system"].includes(m)) && R(m || e);
|
|
318
|
+
};
|
|
319
|
+
return f.addEventListener("storage", h), () => {
|
|
320
|
+
f.removeEventListener("storage", h);
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
}, [A, R, u, d, S, e, f, y]), {
|
|
324
|
+
...P,
|
|
325
|
+
mode: N ? P.mode : void 0,
|
|
326
|
+
systemMode: N ? P.systemMode : void 0,
|
|
327
|
+
colorScheme: N ? G : void 0,
|
|
328
|
+
setMode: R,
|
|
329
|
+
setColorScheme: A
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
const dt = "*{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}";
|
|
333
|
+
function lt(t) {
|
|
334
|
+
const {
|
|
335
|
+
themeId: e,
|
|
336
|
+
/**
|
|
337
|
+
* This `theme` object needs to follow a certain structure to
|
|
338
|
+
* be used correctly by the finel `CssVarsProvider`. It should have a
|
|
339
|
+
* `colorSchemes` key with the light and dark (and any other) palette.
|
|
340
|
+
* It should also ideally have a vars object created using `prepareCssVars`.
|
|
341
|
+
*/
|
|
342
|
+
theme: c = {},
|
|
343
|
+
modeStorageKey: n = ke,
|
|
344
|
+
colorSchemeStorageKey: l = Ce,
|
|
345
|
+
disableTransitionOnChange: u = !1,
|
|
346
|
+
defaultColorScheme: d,
|
|
347
|
+
resolveTheme: f
|
|
348
|
+
} = t, k = {
|
|
349
|
+
allColorSchemes: [],
|
|
350
|
+
colorScheme: void 0,
|
|
351
|
+
darkColorScheme: void 0,
|
|
352
|
+
lightColorScheme: void 0,
|
|
353
|
+
mode: void 0,
|
|
354
|
+
setColorScheme: () => {
|
|
355
|
+
},
|
|
356
|
+
setMode: () => {
|
|
357
|
+
},
|
|
358
|
+
systemMode: void 0
|
|
359
|
+
}, S = /* @__PURE__ */ w.createContext(void 0);
|
|
360
|
+
process.env.NODE_ENV !== "production" && (S.displayName = "ColorSchemeContext");
|
|
361
|
+
const y = () => w.useContext(S) || k, P = {}, b = {};
|
|
362
|
+
function N(A) {
|
|
363
|
+
var Te, Me, Ae, De;
|
|
364
|
+
const {
|
|
365
|
+
children: j,
|
|
366
|
+
theme: _,
|
|
367
|
+
modeStorageKey: h = n,
|
|
368
|
+
colorSchemeStorageKey: g = l,
|
|
369
|
+
disableTransitionOnChange: m = u,
|
|
370
|
+
storageWindow: D = typeof window > "u" ? void 0 : window,
|
|
371
|
+
documentNode: p = typeof document > "u" ? void 0 : document,
|
|
372
|
+
colorSchemeNode: L = typeof document > "u" ? void 0 : document.documentElement,
|
|
373
|
+
disableNestedContext: Y = !1,
|
|
374
|
+
disableStyleSheetGeneration: Q = !1,
|
|
375
|
+
defaultMode: le = "system",
|
|
376
|
+
noSsr: X
|
|
377
|
+
} = A, Z = w.useRef(!1), ee = be(), te = w.useContext(S), oe = !!te && !Y, ue = w.useMemo(() => _ || (typeof c == "function" ? c() : c), [_]), ne = ue[e], T = ne || ue, {
|
|
378
|
+
colorSchemes: W = P,
|
|
379
|
+
components: fe = b,
|
|
380
|
+
cssVarPrefix: o
|
|
381
|
+
} = T, r = Object.keys(W).filter((E) => !!W[E]).join(","), i = w.useMemo(() => r.split(","), [r]), a = typeof d == "string" ? d : d.light, C = typeof d == "string" ? d : d.dark, v = W[a] && W[C] ? le : ((Me = (Te = W[T.defaultColorScheme]) == null ? void 0 : Te.palette) == null ? void 0 : Me.mode) || ((Ae = T.palette) == null ? void 0 : Ae.mode), {
|
|
382
|
+
mode: q,
|
|
383
|
+
setMode: H,
|
|
384
|
+
systemMode: ie,
|
|
385
|
+
lightColorScheme: Ie,
|
|
386
|
+
darkColorScheme: Ne,
|
|
387
|
+
colorScheme: Ke,
|
|
388
|
+
setColorScheme: ve
|
|
389
|
+
} = at({
|
|
390
|
+
supportedColorSchemes: i,
|
|
391
|
+
defaultLightColorScheme: a,
|
|
392
|
+
defaultDarkColorScheme: C,
|
|
393
|
+
modeStorageKey: h,
|
|
394
|
+
colorSchemeStorageKey: g,
|
|
395
|
+
defaultMode: v,
|
|
396
|
+
storageWindow: D,
|
|
397
|
+
noSsr: X
|
|
398
|
+
});
|
|
399
|
+
let me = q, U = Ke;
|
|
400
|
+
oe && (me = te.mode, U = te.colorScheme);
|
|
401
|
+
const z = w.useMemo(() => {
|
|
402
|
+
var se;
|
|
403
|
+
const E = U || T.defaultColorScheme, O = ((se = T.generateThemeVars) == null ? void 0 : se.call(T)) || T.vars, $ = {
|
|
404
|
+
...T,
|
|
405
|
+
components: fe,
|
|
406
|
+
colorSchemes: W,
|
|
407
|
+
cssVarPrefix: o,
|
|
408
|
+
vars: O
|
|
409
|
+
};
|
|
410
|
+
if (typeof $.generateSpacing == "function" && ($.spacing = $.generateSpacing()), E) {
|
|
411
|
+
const x = W[E];
|
|
412
|
+
x && typeof x == "object" && Object.keys(x).forEach((V) => {
|
|
413
|
+
x[V] && typeof x[V] == "object" ? $[V] = {
|
|
414
|
+
...$[V],
|
|
415
|
+
...x[V]
|
|
416
|
+
} : $[V] = x[V];
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
return f ? f($) : $;
|
|
420
|
+
}, [T, U, fe, W, o]), re = T.colorSchemeSelector;
|
|
421
|
+
w.useEffect(() => {
|
|
422
|
+
if (U && L && re && re !== "media") {
|
|
423
|
+
const E = re;
|
|
424
|
+
let O = re;
|
|
425
|
+
if (E === "class" && (O = ".%s"), E === "data" && (O = "[data-%s]"), E != null && E.startsWith("data-") && !E.includes("%s") && (O = `[${E}="%s"]`), O.startsWith("."))
|
|
426
|
+
L.classList.remove(...i.map(($) => O.substring(1).replace("%s", $))), L.classList.add(O.substring(1).replace("%s", U));
|
|
427
|
+
else {
|
|
428
|
+
const $ = O.replace("%s", U).match(/\[([^\]]+)\]/);
|
|
429
|
+
if ($) {
|
|
430
|
+
const [se, x] = $[1].split("=");
|
|
431
|
+
x || i.forEach((V) => {
|
|
432
|
+
L.removeAttribute(se.replace(U, V));
|
|
433
|
+
}), L.setAttribute(se, x ? x.replace(/"|'/g, "") : "");
|
|
434
|
+
} else
|
|
435
|
+
L.setAttribute(O, U);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}, [U, re, L, i]), w.useEffect(() => {
|
|
439
|
+
let E;
|
|
440
|
+
if (m && Z.current && p) {
|
|
441
|
+
const O = p.createElement("style");
|
|
442
|
+
O.appendChild(p.createTextNode(dt)), p.head.appendChild(O), window.getComputedStyle(p.body), E = setTimeout(() => {
|
|
443
|
+
p.head.removeChild(O);
|
|
444
|
+
}, 1);
|
|
445
|
+
}
|
|
446
|
+
return () => {
|
|
447
|
+
clearTimeout(E);
|
|
448
|
+
};
|
|
449
|
+
}, [U, m, p]), w.useEffect(() => (Z.current = !0, () => {
|
|
450
|
+
Z.current = !1;
|
|
451
|
+
}), []);
|
|
452
|
+
const qe = w.useMemo(() => ({
|
|
453
|
+
allColorSchemes: i,
|
|
454
|
+
colorScheme: U,
|
|
455
|
+
darkColorScheme: Ne,
|
|
456
|
+
lightColorScheme: Ie,
|
|
457
|
+
mode: me,
|
|
458
|
+
setColorScheme: ve,
|
|
459
|
+
setMode: process.env.NODE_ENV === "production" ? H : (E) => {
|
|
460
|
+
z.colorSchemeSelector === "media" && console.error(["MUI: The `setMode` function has no effect if `colorSchemeSelector` is `media` (`media` is the default value).", "To toggle the mode manually, please configure `colorSchemeSelector` to use a class or data attribute.", "To learn more, visit https://mui.com/material-ui/customization/css-theme-variables/configuration/#toggling-dark-mode-manually"].join(`
|
|
461
|
+
`)), H(E);
|
|
462
|
+
},
|
|
463
|
+
systemMode: ie
|
|
464
|
+
}), [i, U, Ne, Ie, me, ve, H, ie, z.colorSchemeSelector]);
|
|
465
|
+
let Pe = !0;
|
|
466
|
+
(Q || T.cssVariables === !1 || oe && (ee == null ? void 0 : ee.cssVarPrefix) === o) && (Pe = !1);
|
|
467
|
+
const Ee = /* @__PURE__ */ He(w.Fragment, {
|
|
468
|
+
children: [/* @__PURE__ */ M(de, {
|
|
469
|
+
themeId: ne ? e : void 0,
|
|
470
|
+
theme: z,
|
|
471
|
+
children: j
|
|
472
|
+
}), Pe && /* @__PURE__ */ M(tt, {
|
|
473
|
+
styles: ((De = z.generateStyleSheets) == null ? void 0 : De.call(z)) || []
|
|
474
|
+
})]
|
|
475
|
+
});
|
|
476
|
+
return oe ? Ee : /* @__PURE__ */ M(S.Provider, {
|
|
477
|
+
value: qe,
|
|
478
|
+
children: Ee
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
process.env.NODE_ENV !== "production" && (N.propTypes = {
|
|
482
|
+
/**
|
|
483
|
+
* The component tree.
|
|
484
|
+
*/
|
|
485
|
+
children: I.node,
|
|
486
|
+
/**
|
|
487
|
+
* The node used to attach the color-scheme attribute
|
|
488
|
+
*/
|
|
489
|
+
colorSchemeNode: I.any,
|
|
490
|
+
/**
|
|
491
|
+
* localStorage key used to store `colorScheme`
|
|
492
|
+
*/
|
|
493
|
+
colorSchemeStorageKey: I.string,
|
|
494
|
+
/**
|
|
495
|
+
* The default mode when the storage is empty,
|
|
496
|
+
* require the theme to have `colorSchemes` with light and dark.
|
|
497
|
+
*/
|
|
498
|
+
defaultMode: I.string,
|
|
499
|
+
/**
|
|
500
|
+
* If `true`, the provider creates its own context and generate stylesheet as if it is a root `CssVarsProvider`.
|
|
501
|
+
*/
|
|
502
|
+
disableNestedContext: I.bool,
|
|
503
|
+
/**
|
|
504
|
+
* If `true`, the style sheet won't be generated.
|
|
505
|
+
*
|
|
506
|
+
* This is useful for controlling nested CssVarsProvider behavior.
|
|
507
|
+
*/
|
|
508
|
+
disableStyleSheetGeneration: I.bool,
|
|
509
|
+
/**
|
|
510
|
+
* Disable CSS transitions when switching between modes or color schemes.
|
|
511
|
+
*/
|
|
512
|
+
disableTransitionOnChange: I.bool,
|
|
513
|
+
/**
|
|
514
|
+
* The document to attach the attribute to.
|
|
515
|
+
*/
|
|
516
|
+
documentNode: I.any,
|
|
517
|
+
/**
|
|
518
|
+
* The key in the local storage used to store current color scheme.
|
|
519
|
+
*/
|
|
520
|
+
modeStorageKey: I.string,
|
|
521
|
+
/**
|
|
522
|
+
* If `true`, the mode will be the same value as the storage without an extra rerendering after the hydration.
|
|
523
|
+
* You should use this option in conjuction with `InitColorSchemeScript` component.
|
|
524
|
+
*/
|
|
525
|
+
noSsr: I.bool,
|
|
526
|
+
/**
|
|
527
|
+
* The window that attaches the 'storage' event listener.
|
|
528
|
+
* @default window
|
|
529
|
+
*/
|
|
530
|
+
storageWindow: I.any,
|
|
531
|
+
/**
|
|
532
|
+
* The calculated theme object that will be passed through context.
|
|
533
|
+
*/
|
|
534
|
+
theme: I.object
|
|
535
|
+
});
|
|
536
|
+
const K = typeof d == "string" ? d : d.light, G = typeof d == "string" ? d : d.dark;
|
|
537
|
+
return {
|
|
538
|
+
CssVarsProvider: N,
|
|
539
|
+
useColorScheme: y,
|
|
540
|
+
getInitColorSchemeScript: (A) => st({
|
|
541
|
+
colorSchemeStorageKey: l,
|
|
542
|
+
defaultLightColorScheme: K,
|
|
543
|
+
defaultDarkColorScheme: G,
|
|
544
|
+
modeStorageKey: n,
|
|
545
|
+
...A
|
|
546
|
+
})
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
function xe({
|
|
550
|
+
theme: t,
|
|
551
|
+
...e
|
|
552
|
+
}) {
|
|
553
|
+
const c = J in t ? t[J] : void 0;
|
|
554
|
+
return /* @__PURE__ */ M(de, {
|
|
555
|
+
...e,
|
|
556
|
+
themeId: c ? J : void 0,
|
|
557
|
+
theme: c || t
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
const he = {
|
|
561
|
+
attribute: "data-mui-color-scheme",
|
|
562
|
+
colorSchemeStorageKey: "mui-color-scheme",
|
|
563
|
+
defaultLightColorScheme: "light",
|
|
564
|
+
defaultDarkColorScheme: "dark",
|
|
565
|
+
modeStorageKey: "mui-mode"
|
|
566
|
+
}, {
|
|
567
|
+
CssVarsProvider: ut,
|
|
568
|
+
useColorScheme: At,
|
|
569
|
+
getInitColorSchemeScript: Dt
|
|
570
|
+
} = lt({
|
|
571
|
+
themeId: J,
|
|
572
|
+
// @ts-ignore ignore module augmentation tests
|
|
573
|
+
theme: () => Ye({
|
|
574
|
+
cssVariables: !0
|
|
575
|
+
}),
|
|
576
|
+
colorSchemeStorageKey: he.colorSchemeStorageKey,
|
|
577
|
+
modeStorageKey: he.modeStorageKey,
|
|
578
|
+
defaultColorScheme: {
|
|
579
|
+
light: he.defaultLightColorScheme,
|
|
580
|
+
dark: he.defaultDarkColorScheme
|
|
581
|
+
},
|
|
582
|
+
resolveTheme: (t) => {
|
|
583
|
+
const e = {
|
|
584
|
+
...t,
|
|
585
|
+
typography: Qe(t.palette, t.typography)
|
|
586
|
+
};
|
|
587
|
+
return e.unstable_sx = function(n) {
|
|
588
|
+
return Xe({
|
|
589
|
+
sx: n,
|
|
590
|
+
theme: this
|
|
591
|
+
});
|
|
592
|
+
}, e;
|
|
593
|
+
}
|
|
594
|
+
}), ft = ut;
|
|
595
|
+
function ht({
|
|
596
|
+
theme: t,
|
|
597
|
+
...e
|
|
598
|
+
}) {
|
|
599
|
+
return typeof t == "function" ? /* @__PURE__ */ M(xe, {
|
|
600
|
+
theme: t,
|
|
601
|
+
...e
|
|
602
|
+
}) : "colorSchemes" in (J in t ? t[J] : t) ? /* @__PURE__ */ M(ft, {
|
|
603
|
+
theme: t,
|
|
604
|
+
...e
|
|
605
|
+
}) : /* @__PURE__ */ M(xe, {
|
|
606
|
+
theme: t,
|
|
607
|
+
...e
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
const gt = async (t, e, c, n, l, u, d, f) => {
|
|
611
|
+
const k = mt(n, l, u), S = `https://${e}/${n}/users/${encodeURIComponent(
|
|
612
|
+
l
|
|
613
|
+
)}/${c}`, y = {
|
|
614
|
+
Authorization: `Basic ${k}`
|
|
615
|
+
};
|
|
616
|
+
f && f.log("HTTP Request:", {
|
|
617
|
+
method: t,
|
|
13
618
|
host: e,
|
|
14
|
-
url:
|
|
15
|
-
body:
|
|
619
|
+
url: S,
|
|
620
|
+
body: d
|
|
16
621
|
});
|
|
17
|
-
const
|
|
622
|
+
const P = Date.now();
|
|
18
623
|
try {
|
|
19
|
-
const
|
|
20
|
-
method:
|
|
21
|
-
body: JSON.stringify(
|
|
22
|
-
headers:
|
|
624
|
+
const b = await fetch(S, {
|
|
625
|
+
method: t,
|
|
626
|
+
body: JSON.stringify(d),
|
|
627
|
+
headers: y
|
|
23
628
|
});
|
|
24
|
-
|
|
629
|
+
f && f.log("HTTP Response:", b);
|
|
25
630
|
try {
|
|
26
|
-
const
|
|
27
|
-
return
|
|
28
|
-
} catch (
|
|
29
|
-
|
|
631
|
+
const N = await b.json();
|
|
632
|
+
return f && f.log("Response Data:", N), N;
|
|
633
|
+
} catch (N) {
|
|
634
|
+
f && f.warn("Failed to parse response as JSON:", N);
|
|
30
635
|
return;
|
|
31
636
|
}
|
|
32
|
-
} catch (
|
|
33
|
-
const
|
|
34
|
-
throw
|
|
35
|
-
error:
|
|
36
|
-
url:
|
|
37
|
-
headers:
|
|
38
|
-
duration: `${
|
|
39
|
-
}),
|
|
637
|
+
} catch (b) {
|
|
638
|
+
const N = Date.now() - P;
|
|
639
|
+
throw f && f.error("HTTP Request Failed:", {
|
|
640
|
+
error: b,
|
|
641
|
+
url: S,
|
|
642
|
+
headers: y,
|
|
643
|
+
duration: `${N}ms`
|
|
644
|
+
}), b;
|
|
40
645
|
}
|
|
41
|
-
},
|
|
42
|
-
class
|
|
646
|
+
}, mt = (t, e, c) => btoa(c ? t + ":" + e + ":" + c : t + ":" + e);
|
|
647
|
+
class Re {
|
|
43
648
|
constructor(e = !1) {
|
|
44
649
|
this.debug = e;
|
|
45
650
|
}
|
|
@@ -53,7 +658,7 @@ class G {
|
|
|
53
658
|
this.debug && console.error("[NotificationAPI js core SDK Debug]", ...e);
|
|
54
659
|
}
|
|
55
660
|
}
|
|
56
|
-
const
|
|
661
|
+
const We = {
|
|
57
662
|
host: "api.notificationapi.com",
|
|
58
663
|
websocketHost: "ws.notificationapi.com",
|
|
59
664
|
userId: "",
|
|
@@ -68,11 +673,11 @@ const J = {
|
|
|
68
673
|
// 24 hours
|
|
69
674
|
debug: !1,
|
|
70
675
|
sdkDevMode: !1
|
|
71
|
-
},
|
|
72
|
-
config:
|
|
73
|
-
logger: new
|
|
74
|
-
init: function(
|
|
75
|
-
return this.config = { ...
|
|
676
|
+
}, s = {
|
|
677
|
+
config: We,
|
|
678
|
+
logger: new Re(!1),
|
|
679
|
+
init: function(t) {
|
|
680
|
+
return this.config = { ...We, ...t }, this.logger = new Re(this.config.debug), this.logger.log("Initialized with config:", {
|
|
76
681
|
userId: this.config.userId,
|
|
77
682
|
clientId: this.config.clientId,
|
|
78
683
|
host: this.config.host,
|
|
@@ -84,92 +689,92 @@ const J = {
|
|
|
84
689
|
};
|
|
85
690
|
},
|
|
86
691
|
rest: {
|
|
87
|
-
generic: function(
|
|
88
|
-
return
|
|
89
|
-
`API Call: ${
|
|
90
|
-
|
|
91
|
-
),
|
|
92
|
-
|
|
93
|
-
|
|
692
|
+
generic: function(t, e, c) {
|
|
693
|
+
return s.logger.log(
|
|
694
|
+
`API Call: ${t} ${e}`,
|
|
695
|
+
c ? { body: c } : ""
|
|
696
|
+
), gt(
|
|
697
|
+
t,
|
|
698
|
+
s.config.host,
|
|
94
699
|
e,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
700
|
+
s.config.clientId,
|
|
701
|
+
s.config.userId,
|
|
702
|
+
s.config.hashedUserId,
|
|
703
|
+
c,
|
|
704
|
+
s.logger
|
|
100
705
|
);
|
|
101
706
|
},
|
|
102
707
|
// The functions below are nice wrappers over the generic
|
|
103
708
|
// rest api function above. They must follow REST API naming:
|
|
104
709
|
// Method + Resource, representing the end-point.
|
|
105
|
-
getNotifications: function(
|
|
106
|
-
return
|
|
710
|
+
getNotifications: function(t, e) {
|
|
711
|
+
return s.rest.generic(
|
|
107
712
|
"GET",
|
|
108
|
-
`notifications/INAPP_WEB?count=${e}&before=${
|
|
713
|
+
`notifications/INAPP_WEB?count=${e}&before=${t}`
|
|
109
714
|
);
|
|
110
715
|
},
|
|
111
|
-
patchNotifications: function(
|
|
112
|
-
return
|
|
716
|
+
patchNotifications: function(t) {
|
|
717
|
+
return s.rest.generic(
|
|
113
718
|
"PATCH",
|
|
114
719
|
"notifications/INAPP_WEB",
|
|
115
|
-
|
|
720
|
+
t
|
|
116
721
|
);
|
|
117
722
|
},
|
|
118
723
|
getPreferences: function() {
|
|
119
|
-
return
|
|
724
|
+
return s.rest.generic("GET", "preferences");
|
|
120
725
|
},
|
|
121
|
-
postPreferences: function(
|
|
122
|
-
return
|
|
726
|
+
postPreferences: function(t) {
|
|
727
|
+
return s.rest.generic(
|
|
123
728
|
"POST",
|
|
124
729
|
"preferences",
|
|
125
|
-
|
|
730
|
+
t
|
|
126
731
|
);
|
|
127
732
|
},
|
|
128
|
-
postUser: function(
|
|
129
|
-
return
|
|
733
|
+
postUser: function(t) {
|
|
734
|
+
return s.rest.generic("POST", "", t);
|
|
130
735
|
},
|
|
131
736
|
getUserAccountMetadata: function() {
|
|
132
|
-
return
|
|
737
|
+
return s.rest.generic("GET", "account_metadata");
|
|
133
738
|
}
|
|
134
739
|
},
|
|
135
740
|
websocket: {
|
|
136
741
|
object: void 0,
|
|
137
742
|
connect: function() {
|
|
138
|
-
let
|
|
139
|
-
return
|
|
140
|
-
|
|
141
|
-
},
|
|
142
|
-
|
|
743
|
+
let t = `wss://${s.config.websocketHost}?userId=${encodeURIComponent(s.config.userId)}&envId=${s.config.clientId}`;
|
|
744
|
+
return s.config.hashedUserId && (t += `&userIdHash=${encodeURIComponent(s.config.hashedUserId)}`), s.logger.log("WebSocket connecting to:", t), s.websocket.object = new WebSocket(t), s.websocket.object.onopen = () => {
|
|
745
|
+
s.logger.log("WebSocket connection opened");
|
|
746
|
+
}, s.websocket.object.onclose = (e) => {
|
|
747
|
+
s.logger.log("WebSocket connection closed:", {
|
|
143
748
|
code: e.code,
|
|
144
749
|
reason: e.reason,
|
|
145
750
|
wasClean: e.wasClean
|
|
146
751
|
});
|
|
147
|
-
},
|
|
148
|
-
|
|
149
|
-
},
|
|
150
|
-
|
|
752
|
+
}, s.websocket.object.onerror = (e) => {
|
|
753
|
+
s.logger.error("WebSocket error:", e);
|
|
754
|
+
}, s.websocket.object.onmessage = (e) => {
|
|
755
|
+
s.logger.log(
|
|
151
756
|
"WebSocket message received:",
|
|
152
757
|
e.data
|
|
153
758
|
);
|
|
154
|
-
const
|
|
155
|
-
if (!(!
|
|
156
|
-
const
|
|
157
|
-
|
|
759
|
+
const c = JSON.parse(e.data);
|
|
760
|
+
if (!(!c || !c.route) && c.route === "inapp_web/new_notifications") {
|
|
761
|
+
const n = c;
|
|
762
|
+
s.logger.log(
|
|
158
763
|
"New notifications received:",
|
|
159
|
-
|
|
160
|
-
),
|
|
161
|
-
|
|
764
|
+
n.payload.notifications
|
|
765
|
+
), s.config.onNewInAppNotifications && s.config.onNewInAppNotifications(
|
|
766
|
+
n.payload.notifications
|
|
162
767
|
);
|
|
163
768
|
}
|
|
164
|
-
},
|
|
769
|
+
}, s.websocket.object;
|
|
165
770
|
},
|
|
166
|
-
disconnect: function(
|
|
771
|
+
disconnect: function(t) {
|
|
167
772
|
var e;
|
|
168
|
-
|
|
773
|
+
s.websocket.object && (s.logger.log("WebSocket disconnecting"), (e = s.websocket.object) == null || e.close(), t && t(s.websocket.object));
|
|
169
774
|
}
|
|
170
775
|
},
|
|
171
776
|
openWebSocket: function() {
|
|
172
|
-
return
|
|
777
|
+
return s.websocket.connect(() => {
|
|
173
778
|
setTimeout(
|
|
174
779
|
() => {
|
|
175
780
|
this.websocket.disconnect(() => {
|
|
@@ -183,106 +788,106 @@ const J = {
|
|
|
183
788
|
// These functions are developer friendly wrappers over the rest APIs
|
|
184
789
|
// They may or may not do additional tasks.
|
|
185
790
|
// e.g. identify simply maps to postUsers
|
|
186
|
-
getInAppNotifications: async (
|
|
187
|
-
|
|
791
|
+
getInAppNotifications: async (t) => {
|
|
792
|
+
s.logger.log(
|
|
188
793
|
"getInAppNotifications called with params:",
|
|
189
|
-
|
|
794
|
+
t
|
|
190
795
|
);
|
|
191
|
-
const e =
|
|
192
|
-
|
|
796
|
+
const e = t.maxCountNeeded || s.config.getInAppDefaultCount, c = t.oldestNeeded || s.config.getInAppDefaultOldest;
|
|
797
|
+
s.logger.log("Fetching notifications with:", {
|
|
193
798
|
maxCountNeeded: e,
|
|
194
|
-
oldestNeeded:
|
|
195
|
-
before:
|
|
799
|
+
oldestNeeded: c,
|
|
800
|
+
before: t.before
|
|
196
801
|
});
|
|
197
|
-
let
|
|
198
|
-
for (;
|
|
199
|
-
const
|
|
200
|
-
|
|
802
|
+
let n = [], l = t.before, u = !0, d = !0;
|
|
803
|
+
for (; d; ) {
|
|
804
|
+
const f = (await s.rest.getNotifications(
|
|
805
|
+
l,
|
|
201
806
|
e
|
|
202
|
-
)).notifications,
|
|
203
|
-
(
|
|
807
|
+
)).notifications, k = f.filter(
|
|
808
|
+
(S) => !n.find((y) => y.id === S.id)
|
|
204
809
|
);
|
|
205
|
-
|
|
206
|
-
`Received ${
|
|
207
|
-
),
|
|
208
|
-
(
|
|
209
|
-
|
|
210
|
-
),
|
|
211
|
-
hasMore:
|
|
212
|
-
totalResults:
|
|
810
|
+
s.logger.log(
|
|
811
|
+
`Received ${f.length} notifications, ${k.length} unique`
|
|
812
|
+
), l = k.reduce(
|
|
813
|
+
(S, y) => S < y.date ? S : y.date,
|
|
814
|
+
t.before
|
|
815
|
+
), n = [...n, ...k], u = k.length > 0, d = !0, (!u || n.length >= e || l < c) && (d = !1, s.logger.log("Stopping fetch loop:", {
|
|
816
|
+
hasMore: u,
|
|
817
|
+
totalResults: n.length,
|
|
213
818
|
maxCountNeeded: e,
|
|
214
|
-
oldestReceived:
|
|
215
|
-
oldestNeeded:
|
|
819
|
+
oldestReceived: l,
|
|
820
|
+
oldestNeeded: c
|
|
216
821
|
}));
|
|
217
822
|
}
|
|
218
|
-
return
|
|
219
|
-
totalItems:
|
|
220
|
-
hasMore:
|
|
221
|
-
oldestReceived:
|
|
823
|
+
return s.logger.log("getInAppNotifications completed:", {
|
|
824
|
+
totalItems: n.length,
|
|
825
|
+
hasMore: u,
|
|
826
|
+
oldestReceived: l
|
|
222
827
|
}), {
|
|
223
|
-
items:
|
|
224
|
-
hasMore:
|
|
225
|
-
oldestReceived:
|
|
828
|
+
items: n,
|
|
829
|
+
hasMore: u,
|
|
830
|
+
oldestReceived: l
|
|
226
831
|
};
|
|
227
832
|
},
|
|
228
|
-
updateInAppNotifications: async (
|
|
229
|
-
|
|
833
|
+
updateInAppNotifications: async (t) => {
|
|
834
|
+
s.logger.log(
|
|
230
835
|
"updateInAppNotifications called with params:",
|
|
231
|
-
|
|
836
|
+
t
|
|
232
837
|
);
|
|
233
838
|
const e = {
|
|
234
|
-
trackingIds:
|
|
839
|
+
trackingIds: t.ids
|
|
235
840
|
};
|
|
236
|
-
return
|
|
841
|
+
return t.archived === !0 ? e.archived = (/* @__PURE__ */ new Date()).toISOString() : t.archived === !1 && (e.archived = null), t.clicked === !0 ? e.clicked = (/* @__PURE__ */ new Date()).toISOString() : t.clicked === !1 && (e.clicked = null), t.opened === !0 ? e.opened = (/* @__PURE__ */ new Date()).toISOString() : t.opened === !1 && (e.opened = null), s.logger.log(
|
|
237
842
|
"Updating notifications with body:",
|
|
238
843
|
e
|
|
239
|
-
),
|
|
844
|
+
), s.rest.patchNotifications(e);
|
|
240
845
|
},
|
|
241
|
-
getPreferences: async () =>
|
|
242
|
-
updateDeliveryOption: async (
|
|
243
|
-
identify: async (
|
|
244
|
-
if (
|
|
846
|
+
getPreferences: async () => s.rest.getPreferences(),
|
|
847
|
+
updateDeliveryOption: async (t) => s.rest.postPreferences([t]),
|
|
848
|
+
identify: async (t) => {
|
|
849
|
+
if (t.id && t.id !== s.config.userId)
|
|
245
850
|
throw new Error(
|
|
246
851
|
"The id in the parameters does not match the initialized userId."
|
|
247
852
|
);
|
|
248
|
-
return
|
|
853
|
+
return s.rest.postUser(t);
|
|
249
854
|
},
|
|
250
|
-
getUserAccountMetadata: async () =>
|
|
855
|
+
getUserAccountMetadata: async () => s.rest.getUserAccountMetadata(),
|
|
251
856
|
user: {
|
|
252
|
-
get: async () =>
|
|
857
|
+
get: async () => s.rest.generic("GET", "")
|
|
253
858
|
},
|
|
254
859
|
slack: {
|
|
255
|
-
getOAuthUrl: (
|
|
256
|
-
const e =
|
|
860
|
+
getOAuthUrl: (t) => {
|
|
861
|
+
const e = s.config.sdkDevMode ? "localhost:3001" : s.config.host.replace("api.", "app."), c = (t == null ? void 0 : t.destinationUrl) || window.location.href, n = encodeURIComponent(
|
|
257
862
|
JSON.stringify({
|
|
258
|
-
destination:
|
|
259
|
-
userId:
|
|
260
|
-
clientId:
|
|
261
|
-
hashedUserId:
|
|
863
|
+
destination: c,
|
|
864
|
+
userId: s.config.userId,
|
|
865
|
+
clientId: s.config.clientId,
|
|
866
|
+
hashedUserId: s.config.hashedUserId
|
|
262
867
|
})
|
|
263
868
|
);
|
|
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=${
|
|
869
|
+
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=${n}`;
|
|
265
870
|
},
|
|
266
|
-
getChannels: async () => await
|
|
871
|
+
getChannels: async () => await s.rest.generic(
|
|
267
872
|
"GET",
|
|
268
873
|
"slack/channels"
|
|
269
874
|
),
|
|
270
|
-
setChannel: async (
|
|
271
|
-
slackChannel:
|
|
875
|
+
setChannel: async (t) => s.identify({
|
|
876
|
+
slackChannel: t
|
|
272
877
|
})
|
|
273
878
|
}
|
|
274
|
-
},
|
|
275
|
-
const e =
|
|
276
|
-
() =>
|
|
277
|
-
[
|
|
879
|
+
}, Fe = typeof window < "u", pt = (t) => {
|
|
880
|
+
const e = pe(
|
|
881
|
+
() => ze(t.debug || !1),
|
|
882
|
+
[t.debug]
|
|
278
883
|
);
|
|
279
884
|
e.log("NotificationAPI Provider initializing", {
|
|
280
|
-
clientId:
|
|
281
|
-
userId: "userId" in
|
|
282
|
-
debug:
|
|
885
|
+
clientId: t.clientId,
|
|
886
|
+
userId: "userId" in t ? t.userId : t.user.id,
|
|
887
|
+
debug: t.debug || !1,
|
|
283
888
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
284
889
|
});
|
|
285
|
-
const
|
|
890
|
+
const n = {
|
|
286
891
|
...{
|
|
287
892
|
apiURL: "api.notificationapi.com",
|
|
288
893
|
wsURL: "ws.notificationapi.com",
|
|
@@ -293,144 +898,148 @@ const J = {
|
|
|
293
898
|
webPushOptInMessage: "AUTOMATIC",
|
|
294
899
|
customServiceWorkerPath: "/notificationapi-service-worker.js"
|
|
295
900
|
},
|
|
296
|
-
...
|
|
297
|
-
user: "userId" in
|
|
901
|
+
...t,
|
|
902
|
+
user: "userId" in t ? { id: t.userId } : t.user
|
|
298
903
|
};
|
|
299
|
-
e.log("Configuration loaded",
|
|
300
|
-
const [
|
|
301
|
-
|
|
302
|
-
soundPath:
|
|
303
|
-
}), new Audio(
|
|
904
|
+
e.log("Configuration loaded", n);
|
|
905
|
+
const [l, u] = F(), [d, f] = F(), [k, S] = F(), [y, P] = F(!1), [b, N] = F((/* @__PURE__ */ new Date()).toISOString()), [K, G] = F(!0), [R, A] = F(n.webPushOptInMessage), [j, _] = F(!1), h = B(() => {
|
|
906
|
+
n.playSoundOnNewNotification && (e.log("Playing notification sound", {
|
|
907
|
+
soundPath: n.newNotificationSoundPath
|
|
908
|
+
}), new Audio(n.newNotificationSoundPath).play().catch((r) => {
|
|
304
909
|
e.error("Failed to play new notification sound", r), console.log("Failed to play new notification sound:", r);
|
|
305
910
|
}));
|
|
306
911
|
}, [
|
|
307
|
-
|
|
308
|
-
|
|
912
|
+
n.newNotificationSoundPath,
|
|
913
|
+
n.playSoundOnNewNotification,
|
|
309
914
|
e
|
|
310
|
-
]),
|
|
311
|
-
(
|
|
915
|
+
]), g = B(
|
|
916
|
+
(o) => {
|
|
312
917
|
e.group("Adding notifications to state"), e.log("Received notifications", {
|
|
313
|
-
count: (
|
|
314
|
-
notifications:
|
|
918
|
+
count: (o == null ? void 0 : o.length) || 0,
|
|
919
|
+
notifications: o
|
|
315
920
|
});
|
|
316
921
|
const r = (/* @__PURE__ */ new Date()).toISOString();
|
|
317
|
-
|
|
318
|
-
const
|
|
319
|
-
e.log("Current notifications count",
|
|
320
|
-
const
|
|
321
|
-
return
|
|
322
|
-
id:
|
|
323
|
-
reason:
|
|
324
|
-
expDate:
|
|
325
|
-
date:
|
|
326
|
-
}),
|
|
922
|
+
u((i) => {
|
|
923
|
+
const a = (i == null ? void 0 : i.length) || 0;
|
|
924
|
+
e.log("Current notifications count", a), o = Array.isArray(o) ? o : [], o = o.filter((v) => {
|
|
925
|
+
const q = v.expDate && new Date(v.expDate).toISOString() > r, H = new Date(v.date).getTime() > new Date(r).getTime() + 1e3, ie = !q && !H;
|
|
926
|
+
return ie || e.log("Filtering out notification", {
|
|
927
|
+
id: v.id,
|
|
928
|
+
reason: q ? "expired" : "future",
|
|
929
|
+
expDate: v.expDate,
|
|
930
|
+
date: v.date
|
|
931
|
+
}), ie;
|
|
327
932
|
}), i = Array.isArray(i) ? i : [];
|
|
328
|
-
const
|
|
329
|
-
...
|
|
330
|
-
const
|
|
331
|
-
return
|
|
933
|
+
const C = [
|
|
934
|
+
...o.filter((v) => {
|
|
935
|
+
const q = i.find((H) => H.id === v.id);
|
|
936
|
+
return q && e.log("Filtering out duplicate notification", { id: v.id }), !q;
|
|
332
937
|
}),
|
|
333
938
|
...i
|
|
334
939
|
];
|
|
335
940
|
return e.log("State updated", {
|
|
336
|
-
previousCount:
|
|
337
|
-
newCount:
|
|
338
|
-
addedCount:
|
|
339
|
-
}), e.groupEnd(),
|
|
941
|
+
previousCount: a,
|
|
942
|
+
newCount: C.length,
|
|
943
|
+
addedCount: o.length
|
|
944
|
+
}), e.groupEnd(), C;
|
|
340
945
|
});
|
|
341
946
|
},
|
|
342
947
|
[e]
|
|
343
|
-
),
|
|
948
|
+
), { onNewNotifications: m } = t, D = B(
|
|
949
|
+
(o) => {
|
|
950
|
+
e.log("Received new in-app notifications via WebSocket", {
|
|
951
|
+
count: (o == null ? void 0 : o.length) || 0,
|
|
952
|
+
notifications: o
|
|
953
|
+
}), h(), g(o), m && (e.log("Calling onNewNotifications callback", {
|
|
954
|
+
count: (o == null ? void 0 : o.length) || 0
|
|
955
|
+
}), m(o));
|
|
956
|
+
},
|
|
957
|
+
[h, g, m, e]
|
|
958
|
+
), p = pe(() => {
|
|
344
959
|
e.group("Initializing NotificationAPI client");
|
|
345
|
-
const
|
|
346
|
-
clientId:
|
|
347
|
-
userId:
|
|
348
|
-
hashedUserId:
|
|
349
|
-
host:
|
|
350
|
-
websocketHost:
|
|
351
|
-
debug:
|
|
960
|
+
const o = {
|
|
961
|
+
clientId: n.clientId,
|
|
962
|
+
userId: n.user.id,
|
|
963
|
+
hashedUserId: n.hashedUserId,
|
|
964
|
+
host: n.apiURL,
|
|
965
|
+
websocketHost: n.wsURL,
|
|
966
|
+
debug: n.debug
|
|
352
967
|
};
|
|
353
|
-
e.log("Client configuration",
|
|
354
|
-
const r =
|
|
355
|
-
...
|
|
356
|
-
onNewInAppNotifications:
|
|
357
|
-
e.log("Received new in-app notifications via WebSocket", {
|
|
358
|
-
count: (s == null ? void 0 : s.length) || 0,
|
|
359
|
-
notifications: s
|
|
360
|
-
}), $(), O(s);
|
|
361
|
-
}
|
|
968
|
+
e.log("Client configuration", o);
|
|
969
|
+
const r = t.client ? t.client : s.init({
|
|
970
|
+
...o,
|
|
971
|
+
onNewInAppNotifications: D
|
|
362
972
|
}), i = {
|
|
363
|
-
email:
|
|
364
|
-
number:
|
|
973
|
+
email: n.user.email,
|
|
974
|
+
number: n.user.number
|
|
365
975
|
};
|
|
366
976
|
return e.log("Identifying user", i), r.identify(i), e.groupEnd(), r;
|
|
367
977
|
}, [
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
a.wsURL,
|
|
978
|
+
n.clientId,
|
|
979
|
+
n.user.id,
|
|
980
|
+
n.user.email,
|
|
981
|
+
n.user.number,
|
|
982
|
+
n.hashedUserId,
|
|
983
|
+
n.debug,
|
|
984
|
+
D,
|
|
985
|
+
t.client,
|
|
986
|
+
n.apiURL,
|
|
987
|
+
n.wsURL,
|
|
379
988
|
e
|
|
380
|
-
]),
|
|
381
|
-
async (
|
|
989
|
+
]), L = B(
|
|
990
|
+
async (o, r) => {
|
|
382
991
|
var i;
|
|
383
992
|
e.group("Fetching notifications"), e.log(
|
|
384
993
|
"Fetch parameters",
|
|
385
|
-
|
|
994
|
+
ae("GET", "/notifications", { date: o, count: r })
|
|
386
995
|
);
|
|
387
996
|
try {
|
|
388
|
-
const
|
|
997
|
+
const a = await p.rest.getNotifications(o, r);
|
|
389
998
|
e.log("Fetch successful", {
|
|
390
|
-
notificationsCount: ((i =
|
|
391
|
-
oldestReceived:
|
|
392
|
-
couldLoadMore:
|
|
393
|
-
}),
|
|
394
|
-
} catch (
|
|
395
|
-
throw e.error("Failed to fetch notifications",
|
|
999
|
+
notificationsCount: ((i = a.notifications) == null ? void 0 : i.length) || 0,
|
|
1000
|
+
oldestReceived: a.oldestReceived,
|
|
1001
|
+
couldLoadMore: a.couldLoadMore
|
|
1002
|
+
}), N(a.oldestReceived), G(a.couldLoadMore), g(a.notifications), e.groupEnd();
|
|
1003
|
+
} catch (a) {
|
|
1004
|
+
throw e.error("Failed to fetch notifications", a, { date: o, count: r }), e.groupEnd(), a;
|
|
396
1005
|
}
|
|
397
1006
|
},
|
|
398
|
-
[
|
|
399
|
-
),
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
}, [
|
|
403
|
-
const
|
|
404
|
-
async (
|
|
405
|
-
if (e.group(`Loading notifications (${
|
|
406
|
-
initial:
|
|
407
|
-
hasMore:
|
|
408
|
-
loading:
|
|
409
|
-
}), !
|
|
1007
|
+
[g, p.rest, e]
|
|
1008
|
+
), Y = Se(K), Q = Se(y), le = Se(b);
|
|
1009
|
+
ce(() => {
|
|
1010
|
+
Y.current = K, Q.current = y, le.current = b;
|
|
1011
|
+
}, [K, y, b]);
|
|
1012
|
+
const X = B(
|
|
1013
|
+
async (o) => {
|
|
1014
|
+
if (e.group(`Loading notifications (${o ? "initial" : "more"})`), e.log("Load conditions", {
|
|
1015
|
+
initial: o,
|
|
1016
|
+
hasMore: Y.current,
|
|
1017
|
+
loading: Q.current
|
|
1018
|
+
}), !o && (!Y.current || Q.current)) {
|
|
410
1019
|
e.log("Skipping load - conditions not met"), e.groupEnd();
|
|
411
1020
|
return;
|
|
412
1021
|
}
|
|
413
|
-
|
|
1022
|
+
P(!0), e.log("Loading started");
|
|
414
1023
|
try {
|
|
415
|
-
await
|
|
416
|
-
|
|
417
|
-
|
|
1024
|
+
await L(
|
|
1025
|
+
o ? (/* @__PURE__ */ new Date()).toISOString() : le.current,
|
|
1026
|
+
o ? n.initialLoadMaxCount : 1e3
|
|
418
1027
|
), e.log("Loading completed successfully");
|
|
419
1028
|
} catch (r) {
|
|
420
1029
|
throw e.error("Loading failed", r), r;
|
|
421
1030
|
} finally {
|
|
422
|
-
|
|
1031
|
+
P(!1), e.groupEnd();
|
|
423
1032
|
}
|
|
424
1033
|
},
|
|
425
|
-
[
|
|
426
|
-
),
|
|
427
|
-
if (e.group("Marking notifications as clicked"), e.log("Requested IDs",
|
|
1034
|
+
[n.initialLoadMaxCount, L, e]
|
|
1035
|
+
), Z = async (o) => {
|
|
1036
|
+
if (e.group("Marking notifications as clicked"), e.log("Requested IDs", o), !l) {
|
|
428
1037
|
e.warn("No notifications available"), e.groupEnd();
|
|
429
1038
|
return;
|
|
430
1039
|
}
|
|
431
|
-
const r = (/* @__PURE__ */ new Date()).toISOString(), i =
|
|
1040
|
+
const r = (/* @__PURE__ */ new Date()).toISOString(), i = l.filter((a) => o.includes(a.id) && !a.clicked).map((a) => a.id);
|
|
432
1041
|
if (e.log("Filtered IDs for update", {
|
|
433
|
-
requestedCount:
|
|
1042
|
+
requestedCount: o.length,
|
|
434
1043
|
actualCount: i.length,
|
|
435
1044
|
ids: i
|
|
436
1045
|
}), i.length === 0) {
|
|
@@ -440,23 +1049,23 @@ const J = {
|
|
|
440
1049
|
try {
|
|
441
1050
|
e.log(
|
|
442
1051
|
"Updating notifications via API",
|
|
443
|
-
|
|
444
|
-
),
|
|
445
|
-
if (!
|
|
446
|
-
const
|
|
447
|
-
return
|
|
448
|
-
|
|
449
|
-
}), e.log("Local state updated", { updatedCount: i.length }),
|
|
1052
|
+
ae("PUT", "/notifications/clicked", { ids: i })
|
|
1053
|
+
), p.updateInAppNotifications({ ids: i, clicked: !0 }), u((a) => {
|
|
1054
|
+
if (!a) return [];
|
|
1055
|
+
const C = [...a];
|
|
1056
|
+
return C.filter((v) => i.includes(v.id)).forEach((v) => {
|
|
1057
|
+
v.clicked = r;
|
|
1058
|
+
}), e.log("Local state updated", { updatedCount: i.length }), C;
|
|
450
1059
|
}), e.groupEnd();
|
|
451
|
-
} catch (
|
|
452
|
-
throw e.error("Failed to mark notifications as clicked",
|
|
1060
|
+
} catch (a) {
|
|
1061
|
+
throw e.error("Failed to mark notifications as clicked", a, { ids: i }), e.groupEnd(), a;
|
|
453
1062
|
}
|
|
454
|
-
},
|
|
455
|
-
if (e.group("Marking notifications as opened"), !
|
|
1063
|
+
}, ee = async () => {
|
|
1064
|
+
if (e.group("Marking notifications as opened"), !l) {
|
|
456
1065
|
e.warn("No notifications available"), e.groupEnd();
|
|
457
1066
|
return;
|
|
458
1067
|
}
|
|
459
|
-
const
|
|
1068
|
+
const o = (/* @__PURE__ */ new Date()).toISOString(), r = l.filter((i) => !i.opened || !i.seen).map((i) => i.id);
|
|
460
1069
|
if (e.log("Notifications to mark as opened", { count: r.length, ids: r }), r.length === 0) {
|
|
461
1070
|
e.log("All notifications already opened"), e.groupEnd();
|
|
462
1071
|
return;
|
|
@@ -464,26 +1073,26 @@ const J = {
|
|
|
464
1073
|
try {
|
|
465
1074
|
e.log(
|
|
466
1075
|
"Updating notifications via API",
|
|
467
|
-
|
|
468
|
-
),
|
|
1076
|
+
ae("PUT", "/notifications/opened", { ids: r })
|
|
1077
|
+
), p.updateInAppNotifications({
|
|
469
1078
|
ids: r,
|
|
470
1079
|
opened: !0
|
|
471
|
-
}),
|
|
1080
|
+
}), u((i) => {
|
|
472
1081
|
if (!i) return [];
|
|
473
|
-
const
|
|
474
|
-
return
|
|
475
|
-
|
|
476
|
-
}), e.log("Local state updated", { updatedCount: r.length }),
|
|
1082
|
+
const a = [...i];
|
|
1083
|
+
return a.filter((C) => r.includes(C.id)).forEach((C) => {
|
|
1084
|
+
C.opened = o, C.seen = !0;
|
|
1085
|
+
}), e.log("Local state updated", { updatedCount: r.length }), a;
|
|
477
1086
|
}), e.groupEnd();
|
|
478
1087
|
} catch (i) {
|
|
479
1088
|
throw e.error("Failed to mark notifications as opened", i, { ids: r }), e.groupEnd(), i;
|
|
480
1089
|
}
|
|
481
|
-
},
|
|
482
|
-
if (e.group("Marking notifications as unarchived"), e.log("Requested operation", { ids:
|
|
1090
|
+
}, te = async (o) => {
|
|
1091
|
+
if (e.group("Marking notifications as unarchived"), e.log("Requested operation", { ids: o }), !l) {
|
|
483
1092
|
e.warn("No notifications available"), e.groupEnd();
|
|
484
1093
|
return;
|
|
485
1094
|
}
|
|
486
|
-
const r =
|
|
1095
|
+
const r = l.filter((i) => i.archived && (o === "ALL" || o.includes(i.id))).map((i) => i.id);
|
|
487
1096
|
if (e.log("Filtered notifications for unarchiving", {
|
|
488
1097
|
count: r.length,
|
|
489
1098
|
ids: r
|
|
@@ -494,26 +1103,26 @@ const J = {
|
|
|
494
1103
|
try {
|
|
495
1104
|
e.log(
|
|
496
1105
|
"Updating notifications via API",
|
|
497
|
-
|
|
498
|
-
),
|
|
1106
|
+
ae("PUT", "/notifications/unarchived", { ids: r })
|
|
1107
|
+
), p.updateInAppNotifications({
|
|
499
1108
|
ids: r,
|
|
500
1109
|
archived: !1
|
|
501
|
-
}),
|
|
1110
|
+
}), u((i) => {
|
|
502
1111
|
if (!i) return [];
|
|
503
|
-
const
|
|
504
|
-
return
|
|
505
|
-
|
|
506
|
-
}), e.log("Local state updated", { unarchivedCount: r.length }),
|
|
1112
|
+
const a = [...i];
|
|
1113
|
+
return a.filter((C) => r.includes(C.id)).forEach((C) => {
|
|
1114
|
+
C.archived = void 0;
|
|
1115
|
+
}), e.log("Local state updated", { unarchivedCount: r.length }), a;
|
|
507
1116
|
}), e.groupEnd();
|
|
508
1117
|
} catch (i) {
|
|
509
1118
|
throw e.error("Failed to unarchive notifications", i, { ids: r }), e.groupEnd(), i;
|
|
510
1119
|
}
|
|
511
|
-
},
|
|
512
|
-
if (e.group("Marking notifications as archived"), e.log("Requested operation", { ids:
|
|
1120
|
+
}, oe = async (o) => {
|
|
1121
|
+
if (e.group("Marking notifications as archived"), e.log("Requested operation", { ids: o }), !l) {
|
|
513
1122
|
e.warn("No notifications available"), e.groupEnd();
|
|
514
1123
|
return;
|
|
515
1124
|
}
|
|
516
|
-
const r = (/* @__PURE__ */ new Date()).toISOString(), i =
|
|
1125
|
+
const r = (/* @__PURE__ */ new Date()).toISOString(), i = l.filter((a) => !a.archived && (o === "ALL" || o.includes(a.id))).map((a) => a.id);
|
|
517
1126
|
if (e.log("Filtered notifications for archiving", {
|
|
518
1127
|
count: i.length,
|
|
519
1128
|
ids: i
|
|
@@ -524,63 +1133,63 @@ const J = {
|
|
|
524
1133
|
try {
|
|
525
1134
|
e.log(
|
|
526
1135
|
"Updating notifications via API",
|
|
527
|
-
|
|
528
|
-
),
|
|
529
|
-
if (!
|
|
530
|
-
const
|
|
531
|
-
return
|
|
532
|
-
|
|
533
|
-
}), e.log("Local state updated", { archivedCount: i.length }),
|
|
1136
|
+
ae("PUT", "/notifications/archived", { ids: i })
|
|
1137
|
+
), p.updateInAppNotifications({ ids: i, archived: !0 }), u((a) => {
|
|
1138
|
+
if (!a) return [];
|
|
1139
|
+
const C = [...a];
|
|
1140
|
+
return C.filter((v) => i.includes(v.id)).forEach((v) => {
|
|
1141
|
+
v.archived = r;
|
|
1142
|
+
}), e.log("Local state updated", { archivedCount: i.length }), C;
|
|
534
1143
|
}), e.groupEnd();
|
|
535
|
-
} catch (
|
|
536
|
-
throw e.error("Failed to archive notifications",
|
|
1144
|
+
} catch (a) {
|
|
1145
|
+
throw e.error("Failed to archive notifications", a, { ids: i }), e.groupEnd(), a;
|
|
537
1146
|
}
|
|
538
|
-
},
|
|
539
|
-
notificationId:
|
|
1147
|
+
}, ue = (o, r, i, a) => (e.log("Updating single delivery preference", {
|
|
1148
|
+
notificationId: o,
|
|
540
1149
|
channel: r,
|
|
541
1150
|
delivery: i,
|
|
542
|
-
subNotificationId:
|
|
543
|
-
}),
|
|
1151
|
+
subNotificationId: a
|
|
1152
|
+
}), ne([
|
|
544
1153
|
{
|
|
545
|
-
notificationId:
|
|
1154
|
+
notificationId: o,
|
|
546
1155
|
channel: r,
|
|
547
1156
|
delivery: i,
|
|
548
|
-
subNotificationId:
|
|
1157
|
+
subNotificationId: a
|
|
549
1158
|
}
|
|
550
|
-
])),
|
|
551
|
-
e.group("Updating delivery preferences"), e.log("Preference updates", { count:
|
|
1159
|
+
])), ne = (o) => {
|
|
1160
|
+
e.group("Updating delivery preferences"), e.log("Preference updates", { count: o.length, params: o });
|
|
552
1161
|
try {
|
|
553
|
-
|
|
1162
|
+
p.rest.postPreferences(o).then(() => {
|
|
554
1163
|
e.log(
|
|
555
1164
|
"Preferences updated successfully, fetching latest preferences"
|
|
556
|
-
),
|
|
557
|
-
var i,
|
|
1165
|
+
), p.getPreferences().then((r) => {
|
|
1166
|
+
var i, a, C;
|
|
558
1167
|
e.log("Latest preferences fetched", {
|
|
559
1168
|
preferencesCount: ((i = r.preferences) == null ? void 0 : i.length) || 0,
|
|
560
|
-
notificationsCount: ((
|
|
561
|
-
subNotificationsCount: ((
|
|
562
|
-
}),
|
|
1169
|
+
notificationsCount: ((a = r.notifications) == null ? void 0 : a.length) || 0,
|
|
1170
|
+
subNotificationsCount: ((C = r.subNotifications) == null ? void 0 : C.length) || 0
|
|
1171
|
+
}), f(r), e.groupEnd();
|
|
563
1172
|
}).catch((r) => {
|
|
564
1173
|
e.error("Failed to fetch updated preferences", r), e.groupEnd();
|
|
565
1174
|
});
|
|
566
1175
|
}).catch((r) => {
|
|
567
|
-
e.error("Failed to update preferences", r, { params:
|
|
1176
|
+
e.error("Failed to update preferences", r, { params: o }), e.groupEnd();
|
|
568
1177
|
});
|
|
569
1178
|
} catch (r) {
|
|
570
|
-
throw e.error("Error in updateDeliveries", r, { params:
|
|
1179
|
+
throw e.error("Error in updateDeliveries", r, { params: o }), e.groupEnd(), r;
|
|
571
1180
|
}
|
|
572
|
-
},
|
|
1181
|
+
}, T = B(() => {
|
|
573
1182
|
e.group("Requesting web push permission"), e.log("Service worker support check", {
|
|
574
1183
|
supported: "serviceWorker" in navigator,
|
|
575
|
-
customServiceWorkerPath:
|
|
576
|
-
}), "serviceWorker" in navigator ? (e.log("Registering service worker"), navigator.serviceWorker.register(
|
|
577
|
-
e.log("Service worker registered successfully"),
|
|
578
|
-
e.log("Notification permission result", { permission: r }), r === "granted" ? (e.log("Permission granted, subscribing to push manager"), await
|
|
1184
|
+
customServiceWorkerPath: n.customServiceWorkerPath
|
|
1185
|
+
}), "serviceWorker" in navigator ? (e.log("Registering service worker"), navigator.serviceWorker.register(n.customServiceWorkerPath).then(async (o) => {
|
|
1186
|
+
e.log("Service worker registered successfully"), A(!1), yt().then(async (r) => {
|
|
1187
|
+
e.log("Notification permission result", { permission: r }), r === "granted" ? (e.log("Permission granted, subscribing to push manager"), await o.pushManager.subscribe({
|
|
579
1188
|
userVisibleOnly: !0,
|
|
580
|
-
applicationServerKey:
|
|
1189
|
+
applicationServerKey: k == null ? void 0 : k.userAccountMetadata.environmentVapidPublicKey
|
|
581
1190
|
}).then(async (i) => {
|
|
582
1191
|
e.log("Push subscription successful");
|
|
583
|
-
const
|
|
1192
|
+
const a = {
|
|
584
1193
|
webPushTokens: [
|
|
585
1194
|
{
|
|
586
1195
|
sub: {
|
|
@@ -590,116 +1199,118 @@ const J = {
|
|
|
590
1199
|
}
|
|
591
1200
|
]
|
|
592
1201
|
};
|
|
593
|
-
e.log("Identifying user with web push tokens"), await
|
|
1202
|
+
e.log("Identifying user with web push tokens"), await p.identify(a), localStorage.setItem("hideWebPushOptInMessage", "true"), e.log("Web push setup completed successfully"), e.groupEnd();
|
|
594
1203
|
})) : r === "denied" && (e.warn("Permission for notifications was denied"), console.log("Permission for notifications was denied"), e.groupEnd());
|
|
595
1204
|
});
|
|
596
|
-
}).catch((
|
|
1205
|
+
}).catch((o) => {
|
|
597
1206
|
e.error(
|
|
598
1207
|
"Service worker registration or push subscription failed",
|
|
599
|
-
|
|
1208
|
+
o,
|
|
600
1209
|
{
|
|
601
|
-
errorCode:
|
|
602
|
-
customServiceWorkerPath:
|
|
1210
|
+
errorCode: o.code,
|
|
1211
|
+
customServiceWorkerPath: n.customServiceWorkerPath
|
|
603
1212
|
}
|
|
604
|
-
),
|
|
1213
|
+
), o.code === 18 ? console.error(
|
|
605
1214
|
"NotificationAPI guide: Probably you are not setup the service worker correctly. Please check the documentation at https://docs.notificationapi.com/guides/web-push#step-by-step-implementation Step 3: Service Worker Setup."
|
|
606
|
-
) :
|
|
1215
|
+
) : o.code === 19 ? console.error(
|
|
607
1216
|
"The operation is aborted. This can happen if the user denies the permission request."
|
|
608
|
-
) :
|
|
1217
|
+
) : o.code === 20 ? console.error(
|
|
609
1218
|
"The operation is invalid. This can occur if the provided application server key is invalid. Please contact NotificationAPI support."
|
|
610
|
-
) :
|
|
1219
|
+
) : o.code === 21 ? console.error(
|
|
611
1220
|
"The operation is not allowed. This can happen if the user has blocked notifications for the site. Please check your browser site settings Notifications part."
|
|
612
|
-
) :
|
|
1221
|
+
) : o.code === 22 ? console.error(
|
|
613
1222
|
"The operation is not supported. This can occur if the browser does not support the required features."
|
|
614
|
-
) : console.error(
|
|
1223
|
+
) : console.error(o), e.groupEnd();
|
|
615
1224
|
})) : (e.warn("Service worker not supported in this browser"), e.groupEnd());
|
|
616
1225
|
}, [
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
1226
|
+
p,
|
|
1227
|
+
n.customServiceWorkerPath,
|
|
1228
|
+
k == null ? void 0 : k.userAccountMetadata.environmentVapidPublicKey,
|
|
620
1229
|
e
|
|
621
1230
|
]);
|
|
622
|
-
|
|
623
|
-
e.group("Provider initialization effect"), e.log("Resetting state and loading initial data"),
|
|
624
|
-
var r, i,
|
|
1231
|
+
ce(() => {
|
|
1232
|
+
e.group("Provider initialization effect"), e.log("Resetting state and loading initial data"), u([]), P(!1), f(void 0), N((/* @__PURE__ */ new Date()).toISOString()), G(!0), X(!0), e.log("Opening WebSocket connection"), p.openWebSocket(), e.log("Fetching user preferences"), p.getPreferences().then((o) => {
|
|
1233
|
+
var r, i, a;
|
|
625
1234
|
e.log("Initial preferences loaded", {
|
|
626
|
-
preferencesCount: ((r =
|
|
627
|
-
notificationsCount: ((i =
|
|
628
|
-
subNotificationsCount: ((
|
|
629
|
-
}),
|
|
630
|
-
}).catch((
|
|
631
|
-
e.error("Failed to fetch initial preferences",
|
|
1235
|
+
preferencesCount: ((r = o.preferences) == null ? void 0 : r.length) || 0,
|
|
1236
|
+
notificationsCount: ((i = o.notifications) == null ? void 0 : i.length) || 0,
|
|
1237
|
+
subNotificationsCount: ((a = o.subNotifications) == null ? void 0 : a.length) || 0
|
|
1238
|
+
}), f(o), e.groupEnd();
|
|
1239
|
+
}).catch((o) => {
|
|
1240
|
+
e.error("Failed to fetch initial preferences", o), e.groupEnd();
|
|
632
1241
|
});
|
|
633
|
-
}, [
|
|
634
|
-
e.group("Fetching user account metadata"),
|
|
1242
|
+
}, [p, X, T, e]), ce(() => {
|
|
1243
|
+
e.group("Fetching user account metadata"), p.getUserAccountMetadata().then((o) => {
|
|
635
1244
|
e.log("User account metadata loaded", {
|
|
636
|
-
hasWebPushEnabled:
|
|
637
|
-
environmentVapidPublicKey:
|
|
638
|
-
}),
|
|
1245
|
+
hasWebPushEnabled: o.userAccountMetadata.hasWebPushEnabled,
|
|
1246
|
+
environmentVapidPublicKey: o.userAccountMetadata.environmentVapidPublicKey ? "present" : "missing"
|
|
1247
|
+
}), S(o), Fe && "Notification" in window && typeof Notification.requestPermission == "function" ? (e.log("Browser notification support detected", {
|
|
639
1248
|
permission: Notification.permission
|
|
640
1249
|
}), Notification.permission !== "default" && (e.log(
|
|
641
1250
|
"Setting webPushOptInMessage to false (permission already set)"
|
|
642
|
-
),
|
|
1251
|
+
), A(!1))) : (e.log(
|
|
643
1252
|
"Browser notification not supported, using server setting",
|
|
644
1253
|
{
|
|
645
|
-
hasWebPushEnabled:
|
|
1254
|
+
hasWebPushEnabled: o.userAccountMetadata.hasWebPushEnabled
|
|
646
1255
|
}
|
|
647
|
-
),
|
|
648
|
-
}).catch((
|
|
649
|
-
e.error("Failed to fetch user account metadata",
|
|
1256
|
+
), A(o.userAccountMetadata.hasWebPushEnabled)), e.groupEnd();
|
|
1257
|
+
}).catch((o) => {
|
|
1258
|
+
e.error("Failed to fetch user account metadata", o), e.groupEnd();
|
|
650
1259
|
});
|
|
651
|
-
}, [
|
|
652
|
-
if (e.group("Handling webPushOptInMessage state"), e.log("webPushOptInMessage value",
|
|
653
|
-
const
|
|
1260
|
+
}, [p, e]), ce(() => {
|
|
1261
|
+
if (e.group("Handling webPushOptInMessage state"), e.log("webPushOptInMessage value", R), R === "AUTOMATIC") {
|
|
1262
|
+
const o = localStorage.getItem("hideWebPushOptInMessage") === "true";
|
|
654
1263
|
e.log("Automatic mode - checking localStorage", {
|
|
655
|
-
hideMessage:
|
|
656
|
-
shouldShow: !
|
|
657
|
-
}),
|
|
1264
|
+
hideMessage: o,
|
|
1265
|
+
shouldShow: !o
|
|
1266
|
+
}), A(!o);
|
|
658
1267
|
}
|
|
659
1268
|
e.groupEnd();
|
|
660
|
-
}, [
|
|
661
|
-
e.group("Handling webPushOptIn state"), e.log("webPushOptIn state",
|
|
662
|
-
}, [
|
|
663
|
-
const
|
|
664
|
-
notifications:
|
|
665
|
-
preferences:
|
|
666
|
-
userAccountMetaData:
|
|
667
|
-
webPushOptInMessage:
|
|
668
|
-
loadNotifications:
|
|
669
|
-
markAsOpened:
|
|
670
|
-
markAsArchived:
|
|
671
|
-
markAsUnarchived:
|
|
672
|
-
markAsClicked:
|
|
673
|
-
updateDelivery:
|
|
674
|
-
updateDeliveries:
|
|
675
|
-
getClient: () =>
|
|
676
|
-
setWebPushOptInMessage:
|
|
1269
|
+
}, [R, e]), ce(() => {
|
|
1270
|
+
e.group("Handling webPushOptIn state"), e.log("webPushOptIn state", j), j && (e.log("User opted in for web push, requesting permission"), T()), e.groupEnd();
|
|
1271
|
+
}, [j, T, e]);
|
|
1272
|
+
const W = {
|
|
1273
|
+
notifications: l,
|
|
1274
|
+
preferences: d,
|
|
1275
|
+
userAccountMetaData: k,
|
|
1276
|
+
webPushOptInMessage: R,
|
|
1277
|
+
loadNotifications: X,
|
|
1278
|
+
markAsOpened: ee,
|
|
1279
|
+
markAsArchived: oe,
|
|
1280
|
+
markAsUnarchived: te,
|
|
1281
|
+
markAsClicked: Z,
|
|
1282
|
+
updateDelivery: ue,
|
|
1283
|
+
updateDeliveries: ne,
|
|
1284
|
+
getClient: () => p,
|
|
1285
|
+
setWebPushOptInMessage: A,
|
|
677
1286
|
setWebPushOptIn: _
|
|
678
1287
|
};
|
|
679
|
-
|
|
680
|
-
notificationsCount: (
|
|
681
|
-
hasPreferences: !!
|
|
682
|
-
hasUserAccountMetaData: !!
|
|
683
|
-
webPushOptInMessage:
|
|
684
|
-
webPushOptIn:
|
|
685
|
-
})
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
1288
|
+
e.log("NotificationAPI Provider rendering", {
|
|
1289
|
+
notificationsCount: (l == null ? void 0 : l.length) || 0,
|
|
1290
|
+
hasPreferences: !!d,
|
|
1291
|
+
hasUserAccountMetaData: !!k,
|
|
1292
|
+
webPushOptInMessage: R,
|
|
1293
|
+
webPushOptIn: j
|
|
1294
|
+
});
|
|
1295
|
+
const fe = pe(() => t.theme ? Oe(t.theme) : Oe("light"), [t.theme]);
|
|
1296
|
+
return /* @__PURE__ */ M(ht, { theme: fe, children: /* @__PURE__ */ M(je.Provider, { value: W, children: t.children }) });
|
|
1297
|
+
}, St = () => {
|
|
1298
|
+
const t = Ge(je);
|
|
1299
|
+
if (!t)
|
|
689
1300
|
throw new Error("useMyContext must be used within a MyProvider");
|
|
690
|
-
return
|
|
1301
|
+
return t;
|
|
691
1302
|
};
|
|
692
|
-
|
|
693
|
-
const
|
|
694
|
-
if (
|
|
1303
|
+
pt.useNotificationAPIContext = St;
|
|
1304
|
+
const yt = async () => {
|
|
1305
|
+
if (Fe && "Notification" in window && typeof Notification.requestPermission == "function")
|
|
695
1306
|
try {
|
|
696
1307
|
return await Notification.requestPermission();
|
|
697
|
-
} catch (
|
|
698
|
-
return console.error("Error requesting notification permission:",
|
|
1308
|
+
} catch (t) {
|
|
1309
|
+
return console.error("Error requesting notification permission:", t), "default";
|
|
699
1310
|
}
|
|
700
1311
|
else
|
|
701
1312
|
return console.warn("Web Push Notifications are not supported in this browser."), "default";
|
|
702
1313
|
};
|
|
703
1314
|
export {
|
|
704
|
-
|
|
1315
|
+
pt as NotificationAPIProvider
|
|
705
1316
|
};
|