@memobit/libs 3.11.2 → 3.12.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/components/Confetti/Confetti2.js +33 -33
- package/dist/components/ContextToast/ContextToast2.js +53 -57
- package/dist/components/ContextToast/useToast.js +12 -0
- package/dist/components/ControlPanel/ControlPanel2.js +41 -43
- package/dist/components/ControlPanel/ControlPanelContext.js +16 -21
- package/dist/components/ControlPanel/useControlPanel.js +11 -0
- package/dist/components/DataView/DataView.CardView.js +83 -109
- package/dist/components/DataView/DataView.MiniSort.js +1 -1
- package/dist/components/DataView/DataView.helpers.js +34 -0
- package/dist/components/DataView/DataView2.js +111 -108
- package/dist/components/Dropdown/Dropdown2.js +108 -106
- package/dist/components/InputEmail/InputEmail2.js +43 -43
- package/dist/components/InputEmail/validateEmail.js +7 -0
- package/dist/components/InputMask/InputMask2.js +40 -54
- package/dist/components/InputMask/InputMaskPresets.js +18 -0
- package/dist/components/Pagination/Pagination2.js +4 -4
- package/dist/components/QuickOptionUpdate/QuickOptionUpdate2.js +29 -28
- package/dist/components/Sidebar/Sidebar2.js +1 -1
- package/dist/components/Sidebar/SidebarContext.js +18 -23
- package/dist/components/Sidebar/useSidebar.js +11 -0
- package/dist/components/SuggestionsList/SuggestionsList2.js +27 -27
- package/dist/components/TimelineMarkers/TimelineMarkers2.js +31 -49
- package/dist/components/TimelineMarkers/calculateTimelineMarkers.js +28 -0
- package/dist/components/Toolbar/Toolbar2.js +6 -6
- package/dist/components/Tooltip/Tooltip2.js +35 -35
- package/dist/contexts/AuthContext/AuthContext.context.js +5 -0
- package/dist/contexts/AuthContext/AuthContext.js +59 -63
- package/dist/helpers/AppPersistenceStorage.js +25 -15
- package/dist/helpers/Http.js +76 -48
- package/dist/helpers/VersionInfo.js +1 -1
- package/dist/hooks/useAppPersistence.js +20 -20
- package/dist/hooks/useAuth/useAuth.js +1 -1
- package/dist/http.d.ts +4 -0
- package/dist/index.d.ts +13 -1
- package/dist/index.js +270 -262
- package/dist/version.js +2 -2
- package/dist/version.json +4 -4
- package/package.json +1 -1
|
@@ -2,9 +2,9 @@ import './Toolbar.css';
|
|
|
2
2
|
import { Icon as S } from "../Icon/Icon2.js";
|
|
3
3
|
import { Button as w } from "../Button/Button2.js";
|
|
4
4
|
import { Tooltip as x } from "../Tooltip/Tooltip2.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import { Dropdown as I } from "../Dropdown/Dropdown2.js";
|
|
6
|
+
import { InputSearch as y } from "../InputSearch/InputSearch2.js";
|
|
7
|
+
import { useControlPanelContext as B } from "../ControlPanel/useControlPanel.js";
|
|
8
8
|
import { MenuHamburger as $ } from "../MenuHamburger/MenuHamburger2.js";
|
|
9
9
|
import { NotificationPanel as R } from "../NotificationPanel/NotificationPanel2.js";
|
|
10
10
|
/* empty css */
|
|
@@ -19,7 +19,7 @@ var c = "::", k = (e) => typeof e == "object" ? e.label : void 0, M = (e) => "fi
|
|
|
19
19
|
label: i.label,
|
|
20
20
|
suffixIcon: "arrow-down"
|
|
21
21
|
}]) : e.options, O = (e) => "fields" in e ? e.value ? `${e.value.field}${c}${e.value.direction}` : null : e.value, J = ({ children: e, className: i = "", controlPanelToggle: n, heading: l, noCard: f = !1, menuItems: _, notifications: r, search: s, sort: o }) => {
|
|
22
|
-
const u =
|
|
22
|
+
const u = B(), v = !!(n && u?.isMobile), d = typeof n == "object" ? n.count ?? 0 : 0, h = [
|
|
23
23
|
"memobit-toolbar",
|
|
24
24
|
f ? "memobit-toolbar--no-card" : "",
|
|
25
25
|
i
|
|
@@ -83,7 +83,7 @@ var c = "::", k = (e) => typeof e == "object" ? e.label : void 0, M = (e) => "fi
|
|
|
83
83
|
children: [
|
|
84
84
|
s && /* @__PURE__ */ a("div", {
|
|
85
85
|
className: "memobit-toolbar__search",
|
|
86
|
-
children: /* @__PURE__ */ a(
|
|
86
|
+
children: /* @__PURE__ */ a(y, {
|
|
87
87
|
...s,
|
|
88
88
|
className: ["memobit-toolbar__search-input", s.className].filter(Boolean).join(" ")
|
|
89
89
|
})
|
|
@@ -94,7 +94,7 @@ var c = "::", k = (e) => typeof e == "object" ? e.label : void 0, M = (e) => "fi
|
|
|
94
94
|
}),
|
|
95
95
|
o && /* @__PURE__ */ a("div", {
|
|
96
96
|
className: ["memobit-toolbar__sort", o.className].filter(Boolean).join(" "),
|
|
97
|
-
children: /* @__PURE__ */ a(
|
|
97
|
+
children: /* @__PURE__ */ a(I, {
|
|
98
98
|
highlighted: o.highlighted,
|
|
99
99
|
label: o.label,
|
|
100
100
|
name: o.name ?? "toolbar-sort",
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import './Tooltip.css';
|
|
2
2
|
/* empty css */
|
|
3
|
-
import { useEffect as b, useRef as h, useState as B } from "react";
|
|
4
|
-
import { Fragment as
|
|
5
|
-
import { createPortal as
|
|
6
|
-
var
|
|
7
|
-
const [f,
|
|
3
|
+
import { useCallback as S, useEffect as b, useRef as h, useState as B } from "react";
|
|
4
|
+
import { Fragment as V, jsx as N, jsxs as k } from "react/jsx-runtime";
|
|
5
|
+
import { createPortal as O } from "react-dom";
|
|
6
|
+
var Q = ({ title: L, position: p = "top", delay: D = 200, children: _, disabled: $ = !1, className: F = "", maxWidth: g, maxHeight: a }) => {
|
|
7
|
+
const [f, s] = B(!1), [M, I] = B({
|
|
8
8
|
top: 0,
|
|
9
9
|
left: 0
|
|
10
|
-
}), c = h(null), r = h(null), l = h(null), d = h(null),
|
|
10
|
+
}), c = h(null), r = h(null), l = h(null), d = h(null), w = h(!1), m = a !== void 0, R = m ? 150 : 0, T = S(() => {
|
|
11
11
|
if (!l.current || !d.current) return;
|
|
12
12
|
const t = l.current.firstElementChild?.getBoundingClientRect();
|
|
13
13
|
let e = t && t.width > 0 ? t : l.current.getBoundingClientRect();
|
|
@@ -17,60 +17,60 @@ var K = ({ title: L, position: T = "top", delay: _ = 200, children: k, disabled:
|
|
|
17
17
|
const E = C.getBoundingClientRect();
|
|
18
18
|
(E.width > 0 || E.height > 0) && (e = E);
|
|
19
19
|
}
|
|
20
|
-
const n = d.current.getBoundingClientRect(),
|
|
20
|
+
const n = d.current.getBoundingClientRect(), v = 8;
|
|
21
21
|
let o = 0, i = 0;
|
|
22
|
-
switch (
|
|
22
|
+
switch (p) {
|
|
23
23
|
case "top":
|
|
24
|
-
o = e.top - n.height -
|
|
24
|
+
o = e.top - n.height - v, i = e.left + e.width / 2 - n.width / 2;
|
|
25
25
|
break;
|
|
26
26
|
case "bottom":
|
|
27
|
-
o = e.bottom +
|
|
27
|
+
o = e.bottom + v, i = e.left + e.width / 2 - n.width / 2;
|
|
28
28
|
break;
|
|
29
29
|
case "left":
|
|
30
|
-
o = e.top + e.height / 2 - n.height / 2, i = e.left - n.width -
|
|
30
|
+
o = e.top + e.height / 2 - n.height / 2, i = e.left - n.width - v;
|
|
31
31
|
break;
|
|
32
32
|
case "right":
|
|
33
|
-
o = e.top + e.height / 2 - n.height / 2, i = e.right +
|
|
33
|
+
o = e.top + e.height / 2 - n.height / 2, i = e.right + v;
|
|
34
34
|
}
|
|
35
|
-
const
|
|
36
|
-
i <
|
|
35
|
+
const u = 8;
|
|
36
|
+
i < u && (i = u), i + n.width > window.innerWidth - u && (i = window.innerWidth - n.width - u), o < u && (o = u), o + n.height > window.innerHeight - u && (o = window.innerHeight - n.height - u), I({
|
|
37
37
|
top: o,
|
|
38
38
|
left: i
|
|
39
39
|
});
|
|
40
|
-
}, P = () => {
|
|
41
|
-
$ ||
|
|
42
|
-
|
|
43
|
-
},
|
|
40
|
+
}, [p]), P = () => {
|
|
41
|
+
$ || w.current || (r.current && (clearTimeout(r.current), r.current = null), c.current = setTimeout(() => {
|
|
42
|
+
s(!0);
|
|
43
|
+
}, D));
|
|
44
44
|
}, y = () => {
|
|
45
|
-
|
|
45
|
+
w.current || (c.current && clearTimeout(c.current), R > 0 ? r.current = setTimeout(() => s(!1), R) : s(!1));
|
|
46
46
|
}, j = (t) => {
|
|
47
|
-
t.pointerType !== "touch" && t.pointerType !== "pen" || $ || (
|
|
47
|
+
t.pointerType !== "touch" && t.pointerType !== "pen" || $ || (w.current = !0, c.current && (clearTimeout(c.current), c.current = null), t.stopPropagation(), s((e) => !e));
|
|
48
48
|
};
|
|
49
49
|
b(() => {
|
|
50
50
|
if (!f) return;
|
|
51
51
|
const t = (e) => {
|
|
52
|
-
e.target instanceof Node && d.current?.contains(e.target) ||
|
|
52
|
+
e.target instanceof Node && d.current?.contains(e.target) || s(!1);
|
|
53
53
|
};
|
|
54
|
-
return
|
|
55
|
-
window.removeEventListener("scroll", t, !0), window.removeEventListener("resize",
|
|
54
|
+
return T(), window.addEventListener("scroll", t, !0), window.addEventListener("resize", T), () => {
|
|
55
|
+
window.removeEventListener("scroll", t, !0), window.removeEventListener("resize", T);
|
|
56
56
|
};
|
|
57
|
-
}, [f]), b(() => {
|
|
57
|
+
}, [f, T]), b(() => {
|
|
58
58
|
if (!f) return;
|
|
59
59
|
const t = (e) => {
|
|
60
|
-
l.current?.contains(e.target) || d.current?.contains(e.target) ||
|
|
60
|
+
l.current?.contains(e.target) || d.current?.contains(e.target) || s(!1);
|
|
61
61
|
};
|
|
62
62
|
return document.addEventListener("pointerdown", t), () => {
|
|
63
|
-
document.removeEventListener("pointerdown", t),
|
|
63
|
+
document.removeEventListener("pointerdown", t), w.current = !1;
|
|
64
64
|
};
|
|
65
65
|
}, [f]), b(() => () => {
|
|
66
66
|
c.current && clearTimeout(c.current), r.current && clearTimeout(r.current);
|
|
67
67
|
}, []);
|
|
68
68
|
const x = () => {
|
|
69
|
-
|
|
69
|
+
m && r.current && (clearTimeout(r.current), r.current = null);
|
|
70
70
|
}, z = () => {
|
|
71
|
-
|
|
71
|
+
m && (r.current = setTimeout(() => s(!1), R));
|
|
72
72
|
};
|
|
73
|
-
return /* @__PURE__ */
|
|
73
|
+
return /* @__PURE__ */ k(V, { children: [/* @__PURE__ */ N("span", {
|
|
74
74
|
ref: l,
|
|
75
75
|
className: "tooltip-trigger",
|
|
76
76
|
onMouseEnter: P,
|
|
@@ -78,21 +78,21 @@ var K = ({ title: L, position: T = "top", delay: _ = 200, children: k, disabled:
|
|
|
78
78
|
onFocus: P,
|
|
79
79
|
onBlur: y,
|
|
80
80
|
onPointerDown: j,
|
|
81
|
-
children:
|
|
82
|
-
}), f && L &&
|
|
81
|
+
children: _
|
|
82
|
+
}), f && L && O(/* @__PURE__ */ k("div", {
|
|
83
83
|
ref: d,
|
|
84
|
-
className: `tooltip tooltip--${
|
|
84
|
+
className: `tooltip tooltip--${p} ${m ? "tooltip--scrollable" : ""} ${F}`,
|
|
85
85
|
style: {
|
|
86
86
|
top: `${M.top}px`,
|
|
87
87
|
left: `${M.left}px`,
|
|
88
|
-
...
|
|
88
|
+
...g !== void 0 && { maxWidth: typeof g == "number" ? `${g}px` : g },
|
|
89
89
|
...a !== void 0 && { maxHeight: typeof a == "number" ? `${a}px` : a }
|
|
90
90
|
},
|
|
91
91
|
onMouseEnter: x,
|
|
92
92
|
onMouseLeave: z,
|
|
93
|
-
children: [L, /* @__PURE__ */ N("div", { className: `tooltip__arrow tooltip__arrow--${
|
|
93
|
+
children: [L, /* @__PURE__ */ N("div", { className: `tooltip__arrow tooltip__arrow--${p}` })]
|
|
94
94
|
}), document.body)] });
|
|
95
95
|
};
|
|
96
96
|
export {
|
|
97
|
-
|
|
97
|
+
Q as Tooltip
|
|
98
98
|
};
|
|
@@ -1,114 +1,110 @@
|
|
|
1
|
-
import { HttpMethod as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { HttpMethod as o, buildRequestHeaders as A } from "../../helpers/Http.js";
|
|
2
|
+
import { AuthContext as U } from "./AuthContext.context.js";
|
|
3
|
+
import { useCallback as i, useEffect as j, useState as c } from "react";
|
|
4
|
+
import { jsx as B } from "react/jsx-runtime";
|
|
5
|
+
import { logger as h } from "@memobit/core";
|
|
6
|
+
function C({ children: f, config: a }) {
|
|
7
|
+
const [d, u] = c(null), [p, s] = c(!0);
|
|
8
|
+
j(() => {
|
|
8
9
|
(async () => {
|
|
9
10
|
try {
|
|
10
11
|
const t = await fetch(`${a.apiBaseUrl}/auth/verify`, {
|
|
11
|
-
method:
|
|
12
|
+
method: o.Get,
|
|
12
13
|
credentials: "include",
|
|
13
14
|
headers: { "Content-Type": "application/json" }
|
|
14
15
|
});
|
|
15
16
|
if (t.ok) {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
id:
|
|
19
|
-
username:
|
|
20
|
-
createdAt: new Date(
|
|
17
|
+
const r = await t.json();
|
|
18
|
+
u({
|
|
19
|
+
id: r.user.id,
|
|
20
|
+
username: r.user.username,
|
|
21
|
+
createdAt: new Date(r.user.createdAt)
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
24
|
} catch (t) {
|
|
24
|
-
|
|
25
|
+
h.warn("Auth check could not reach the server", { error: String(t) });
|
|
25
26
|
} finally {
|
|
26
|
-
|
|
27
|
+
s(!1);
|
|
27
28
|
}
|
|
28
29
|
})();
|
|
29
30
|
}, [a.apiBaseUrl]);
|
|
30
|
-
const n = i((
|
|
31
|
-
|
|
32
|
-
id:
|
|
33
|
-
username:
|
|
34
|
-
createdAt: new Date(
|
|
31
|
+
const n = i((e) => {
|
|
32
|
+
e.user && u({
|
|
33
|
+
id: e.user.id,
|
|
34
|
+
username: e.user.username,
|
|
35
|
+
createdAt: new Date(e.user.createdAt)
|
|
35
36
|
});
|
|
36
|
-
}, []),
|
|
37
|
-
|
|
37
|
+
}, []), m = i(async (e) => {
|
|
38
|
+
s(!0);
|
|
38
39
|
try {
|
|
39
40
|
const t = await fetch(`${a.apiBaseUrl}/auth/login`, {
|
|
40
|
-
method:
|
|
41
|
+
method: o.Post,
|
|
41
42
|
credentials: "include",
|
|
42
43
|
headers: { "Content-Type": "application/json" },
|
|
43
44
|
body: JSON.stringify({
|
|
44
|
-
username:
|
|
45
|
-
password:
|
|
46
|
-
rememberMe:
|
|
45
|
+
username: e.username,
|
|
46
|
+
password: e.password,
|
|
47
|
+
rememberMe: e.rememberMe
|
|
47
48
|
})
|
|
48
49
|
});
|
|
49
50
|
if (!t.ok) {
|
|
50
|
-
const
|
|
51
|
-
throw new Error(
|
|
51
|
+
const l = await t.json();
|
|
52
|
+
throw new Error(l.error || "Login failed");
|
|
52
53
|
}
|
|
53
|
-
const
|
|
54
|
-
return
|
|
54
|
+
const r = await t.json();
|
|
55
|
+
return r.mfaRequired ? {
|
|
55
56
|
mfaRequired: !0,
|
|
56
|
-
method:
|
|
57
|
-
} : (n(
|
|
58
|
-
} catch (t) {
|
|
59
|
-
throw console.error("Login failed:", t), t;
|
|
57
|
+
method: r.method
|
|
58
|
+
} : (n(r), { mfaRequired: !1 });
|
|
60
59
|
} finally {
|
|
61
|
-
|
|
60
|
+
s(!1);
|
|
62
61
|
}
|
|
63
|
-
}, [a.apiBaseUrl, n]),
|
|
64
|
-
|
|
62
|
+
}, [a.apiBaseUrl, n]), y = i(async (e, t) => {
|
|
63
|
+
s(!0);
|
|
65
64
|
try {
|
|
66
|
-
const
|
|
67
|
-
method:
|
|
65
|
+
const r = await fetch(`${a.apiBaseUrl}/auth/verifyMfa`, {
|
|
66
|
+
method: o.Post,
|
|
68
67
|
credentials: "include",
|
|
69
68
|
headers: { "Content-Type": "application/json" },
|
|
70
69
|
body: JSON.stringify({
|
|
71
|
-
code:
|
|
70
|
+
code: e,
|
|
72
71
|
trustDevice: t
|
|
73
72
|
})
|
|
74
73
|
});
|
|
75
|
-
if (!
|
|
76
|
-
const
|
|
77
|
-
throw new Error(
|
|
74
|
+
if (!r.ok) {
|
|
75
|
+
const l = await r.json();
|
|
76
|
+
throw new Error(l.error || "Verification failed");
|
|
78
77
|
}
|
|
79
|
-
n(await
|
|
80
|
-
} catch (e) {
|
|
81
|
-
throw console.error("MFA verification failed:", e), e;
|
|
78
|
+
n(await r.json());
|
|
82
79
|
} finally {
|
|
83
|
-
|
|
80
|
+
s(!1);
|
|
84
81
|
}
|
|
85
|
-
}, [a.apiBaseUrl, n]),
|
|
82
|
+
}, [a.apiBaseUrl, n]), w = i(async () => {
|
|
86
83
|
try {
|
|
87
84
|
await fetch(`${a.apiBaseUrl}/auth/logout`, {
|
|
88
|
-
method:
|
|
85
|
+
method: o.Post,
|
|
89
86
|
credentials: "include",
|
|
90
|
-
headers:
|
|
87
|
+
headers: A(o.Post)
|
|
91
88
|
});
|
|
92
|
-
} catch (
|
|
93
|
-
|
|
89
|
+
} catch (e) {
|
|
90
|
+
h.warn("Logout request failed", { error: String(e) });
|
|
94
91
|
} finally {
|
|
95
|
-
|
|
92
|
+
u(null);
|
|
96
93
|
}
|
|
97
94
|
}, [a.apiBaseUrl]);
|
|
98
|
-
return /* @__PURE__ */
|
|
95
|
+
return /* @__PURE__ */ B(U.Provider, {
|
|
99
96
|
value: {
|
|
100
|
-
user:
|
|
101
|
-
isAuthenticated: !!
|
|
102
|
-
isLoading:
|
|
97
|
+
user: d,
|
|
98
|
+
isAuthenticated: !!d,
|
|
99
|
+
isLoading: p,
|
|
103
100
|
config: a,
|
|
104
|
-
login:
|
|
105
|
-
verifyMfa:
|
|
106
|
-
logout:
|
|
101
|
+
login: m,
|
|
102
|
+
verifyMfa: y,
|
|
103
|
+
logout: w
|
|
107
104
|
},
|
|
108
|
-
children:
|
|
105
|
+
children: f
|
|
109
106
|
});
|
|
110
107
|
}
|
|
111
108
|
export {
|
|
112
|
-
|
|
113
|
-
P as AuthProvider
|
|
109
|
+
C as AuthProvider
|
|
114
110
|
};
|
|
@@ -1,34 +1,41 @@
|
|
|
1
|
-
|
|
1
|
+
import { logger as g } from "@memobit/core";
|
|
2
|
+
var n = class {
|
|
2
3
|
static getData(e, t) {
|
|
3
4
|
try {
|
|
4
|
-
const
|
|
5
|
-
if (
|
|
6
|
-
const
|
|
7
|
-
if (
|
|
8
|
-
const c = t.pages[s],
|
|
5
|
+
const r = localStorage.getItem(e);
|
|
6
|
+
if (r) {
|
|
7
|
+
const a = JSON.parse(r), o = { ...t.pages };
|
|
8
|
+
if (a.pages && typeof a.pages == "object") for (const s of Object.keys(a.pages)) {
|
|
9
|
+
const c = t.pages[s], i = a.pages[s];
|
|
9
10
|
c && typeof c == "object" ? o[s] = {
|
|
10
11
|
...c,
|
|
11
|
-
...
|
|
12
|
-
} : o[s] =
|
|
12
|
+
...i
|
|
13
|
+
} : o[s] = i;
|
|
13
14
|
}
|
|
14
15
|
return {
|
|
15
16
|
pages: o,
|
|
16
17
|
theme: {
|
|
17
18
|
...t.theme,
|
|
18
|
-
...
|
|
19
|
+
...a.theme
|
|
19
20
|
}
|
|
20
21
|
};
|
|
21
22
|
}
|
|
22
|
-
} catch (
|
|
23
|
-
|
|
23
|
+
} catch (r) {
|
|
24
|
+
g.debug("Failed to load app persistence data", {
|
|
25
|
+
appId: e,
|
|
26
|
+
error: String(r)
|
|
27
|
+
});
|
|
24
28
|
}
|
|
25
29
|
return t;
|
|
26
30
|
}
|
|
27
31
|
static saveData(e, t) {
|
|
28
32
|
try {
|
|
29
33
|
localStorage.setItem(e, JSON.stringify(t));
|
|
30
|
-
} catch (
|
|
31
|
-
|
|
34
|
+
} catch (r) {
|
|
35
|
+
g.debug("Failed to save app persistence data", {
|
|
36
|
+
appId: e,
|
|
37
|
+
error: String(r)
|
|
38
|
+
});
|
|
32
39
|
}
|
|
33
40
|
}
|
|
34
41
|
static load(e, t) {
|
|
@@ -41,10 +48,13 @@ var g = class {
|
|
|
41
48
|
try {
|
|
42
49
|
localStorage.removeItem(e);
|
|
43
50
|
} catch (t) {
|
|
44
|
-
|
|
51
|
+
g.debug("Failed to clear app persistence data", {
|
|
52
|
+
appId: e,
|
|
53
|
+
error: String(t)
|
|
54
|
+
});
|
|
45
55
|
}
|
|
46
56
|
}
|
|
47
57
|
};
|
|
48
58
|
export {
|
|
49
|
-
|
|
59
|
+
n as AppPersistenceStorage
|
|
50
60
|
};
|
package/dist/helpers/Http.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { logger as p } from "@memobit/core";
|
|
2
|
+
var c = {
|
|
2
3
|
Continue: 100,
|
|
3
4
|
SwitchingProtocols: 101,
|
|
4
5
|
Ok: 200,
|
|
@@ -32,71 +33,98 @@ var l = {
|
|
|
32
33
|
BadGateway: 502,
|
|
33
34
|
ServiceUnavailable: 503,
|
|
34
35
|
GatewayTimeout: 504
|
|
35
|
-
},
|
|
36
|
+
}, s = {
|
|
36
37
|
Get: "GET",
|
|
37
38
|
Post: "POST",
|
|
38
39
|
Put: "PUT",
|
|
39
40
|
Patch: "PATCH",
|
|
40
41
|
Delete: "DELETE"
|
|
41
|
-
},
|
|
42
|
-
const e = document.cookie.match(new RegExp(`(?:^|;\\s*)${
|
|
42
|
+
}, A = (e) => e >= 200 && e < 300, R = (e) => e >= 400 && e < 500, U = (e) => e >= 500 && e < 600, y = "csrf_token", S = "X-CSRF-Token", T = () => {
|
|
43
|
+
const e = document.cookie.match(new RegExp(`(?:^|;\\s*)${y}=([^;]+)`));
|
|
43
44
|
return e ? decodeURIComponent(e[1]) : null;
|
|
44
|
-
}, m = (e,
|
|
45
|
-
const
|
|
46
|
-
if (e !==
|
|
47
|
-
const
|
|
48
|
-
|
|
45
|
+
}, m = (e, t = !0) => {
|
|
46
|
+
const n = t ? { "Content-Type": "application/json" } : {};
|
|
47
|
+
if (e !== s.Get) {
|
|
48
|
+
const u = T();
|
|
49
|
+
u && (n[S] = u);
|
|
49
50
|
}
|
|
50
|
-
return
|
|
51
|
-
},
|
|
52
|
-
constructor(e,
|
|
53
|
-
super(e), this.name = "ApiError", this.status =
|
|
51
|
+
return n;
|
|
52
|
+
}, v = class extends Error {
|
|
53
|
+
constructor(e, t) {
|
|
54
|
+
super(e), this.name = "ApiError", this.status = t;
|
|
54
55
|
}
|
|
55
|
-
},
|
|
56
|
+
}, P = async (e) => {
|
|
56
57
|
try {
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
59
|
-
if ("error" in
|
|
60
|
-
if ("message" in
|
|
58
|
+
const t = await e.json();
|
|
59
|
+
if (t && typeof t == "object") {
|
|
60
|
+
if ("error" in t && typeof t.error == "string") return t.error;
|
|
61
|
+
if ("message" in t && typeof t.message == "string") return t.message;
|
|
61
62
|
}
|
|
62
63
|
} catch {
|
|
63
64
|
}
|
|
64
65
|
return `Request failed (${e.status}${e.statusText ? ` ${e.statusText}` : ""})`;
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
}, w = (e) => e instanceof DOMException && e.name === "AbortError", b = (e, t, n) => {
|
|
67
|
+
t instanceof v || w(t) || p.error(e, t, n);
|
|
68
|
+
}, g = /* @__PURE__ */ new Set([
|
|
69
|
+
c.BadGateway,
|
|
70
|
+
c.ServiceUnavailable,
|
|
71
|
+
c.GatewayTimeout
|
|
72
|
+
]), G = ({ baseUrl: e, loginPath: t = "/login" }) => {
|
|
73
|
+
let n = !1;
|
|
74
|
+
const u = (r) => `${e.replace(/\/$/, "")}/${r.replace(/^\//, "")}`, d = async (r, o, l, E = !0) => {
|
|
75
|
+
const h = {
|
|
69
76
|
method: o,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
path: r.split("?")[0]
|
|
78
|
+
};
|
|
79
|
+
let a;
|
|
80
|
+
try {
|
|
81
|
+
a = await fetch(u(r), {
|
|
82
|
+
method: o,
|
|
83
|
+
headers: m(o, E),
|
|
84
|
+
credentials: "include",
|
|
85
|
+
body: l
|
|
76
86
|
});
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
87
|
+
} catch (i) {
|
|
88
|
+
throw w(i) ? i : (p.warn("API request could not reach the server", h), new v("Could not reach the server", 0));
|
|
89
|
+
}
|
|
90
|
+
if (a.status === c.Unauthorized && !window.location.pathname.startsWith(t))
|
|
91
|
+
return n || (n = !0, window.location.href = `${t}?session_expired=true`), new Promise(() => {
|
|
92
|
+
});
|
|
93
|
+
if (!a.ok)
|
|
94
|
+
throw g.has(a.status) && p.warn("API gateway failure", {
|
|
95
|
+
...h,
|
|
96
|
+
status: a.status
|
|
97
|
+
}), new v(await P(a), a.status);
|
|
98
|
+
if (a.status !== c.NoContent)
|
|
99
|
+
try {
|
|
100
|
+
return await a.json();
|
|
101
|
+
} catch (i) {
|
|
102
|
+
throw p.error("API response was not valid JSON", i, {
|
|
103
|
+
...h,
|
|
104
|
+
status: a.status
|
|
105
|
+
}), i;
|
|
106
|
+
}
|
|
107
|
+
}, f = (r, o, l) => d(r, o, l === void 0 ? void 0 : JSON.stringify(l));
|
|
81
108
|
return {
|
|
82
|
-
get: (
|
|
83
|
-
post: (
|
|
84
|
-
put: (
|
|
85
|
-
patch: (
|
|
86
|
-
delete: (
|
|
87
|
-
upload: (
|
|
109
|
+
get: (r) => d(r, s.Get),
|
|
110
|
+
post: (r, o) => f(r, s.Post, o),
|
|
111
|
+
put: (r, o) => f(r, s.Put, o),
|
|
112
|
+
patch: (r, o) => f(r, s.Patch, o),
|
|
113
|
+
delete: (r) => d(r, s.Delete),
|
|
114
|
+
upload: (r, o) => d(r, s.Post, o, !1)
|
|
88
115
|
};
|
|
89
116
|
};
|
|
90
117
|
export {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
118
|
+
v as ApiError,
|
|
119
|
+
S as CSRF_HEADER,
|
|
120
|
+
s as HttpMethod,
|
|
121
|
+
c as HttpStatus,
|
|
95
122
|
m as buildRequestHeaders,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
123
|
+
G as createApiClient,
|
|
124
|
+
T as getCsrfToken,
|
|
125
|
+
R as isClientErrorStatus,
|
|
126
|
+
U as isServerErrorStatus,
|
|
127
|
+
A as isSuccessStatus,
|
|
128
|
+
b as logUnexpectedError,
|
|
129
|
+
P as readErrorMessage
|
|
102
130
|
};
|