@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.
Files changed (38) hide show
  1. package/dist/components/Confetti/Confetti2.js +33 -33
  2. package/dist/components/ContextToast/ContextToast2.js +53 -57
  3. package/dist/components/ContextToast/useToast.js +12 -0
  4. package/dist/components/ControlPanel/ControlPanel2.js +41 -43
  5. package/dist/components/ControlPanel/ControlPanelContext.js +16 -21
  6. package/dist/components/ControlPanel/useControlPanel.js +11 -0
  7. package/dist/components/DataView/DataView.CardView.js +83 -109
  8. package/dist/components/DataView/DataView.MiniSort.js +1 -1
  9. package/dist/components/DataView/DataView.helpers.js +34 -0
  10. package/dist/components/DataView/DataView2.js +111 -108
  11. package/dist/components/Dropdown/Dropdown2.js +108 -106
  12. package/dist/components/InputEmail/InputEmail2.js +43 -43
  13. package/dist/components/InputEmail/validateEmail.js +7 -0
  14. package/dist/components/InputMask/InputMask2.js +40 -54
  15. package/dist/components/InputMask/InputMaskPresets.js +18 -0
  16. package/dist/components/Pagination/Pagination2.js +4 -4
  17. package/dist/components/QuickOptionUpdate/QuickOptionUpdate2.js +29 -28
  18. package/dist/components/Sidebar/Sidebar2.js +1 -1
  19. package/dist/components/Sidebar/SidebarContext.js +18 -23
  20. package/dist/components/Sidebar/useSidebar.js +11 -0
  21. package/dist/components/SuggestionsList/SuggestionsList2.js +27 -27
  22. package/dist/components/TimelineMarkers/TimelineMarkers2.js +31 -49
  23. package/dist/components/TimelineMarkers/calculateTimelineMarkers.js +28 -0
  24. package/dist/components/Toolbar/Toolbar2.js +6 -6
  25. package/dist/components/Tooltip/Tooltip2.js +35 -35
  26. package/dist/contexts/AuthContext/AuthContext.context.js +5 -0
  27. package/dist/contexts/AuthContext/AuthContext.js +59 -63
  28. package/dist/helpers/AppPersistenceStorage.js +25 -15
  29. package/dist/helpers/Http.js +76 -48
  30. package/dist/helpers/VersionInfo.js +1 -1
  31. package/dist/hooks/useAppPersistence.js +20 -20
  32. package/dist/hooks/useAuth/useAuth.js +1 -1
  33. package/dist/http.d.ts +4 -0
  34. package/dist/index.d.ts +13 -1
  35. package/dist/index.js +270 -262
  36. package/dist/version.js +2 -2
  37. package/dist/version.json +4 -4
  38. 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 { useControlPanelContext as I } from "../ControlPanel/ControlPanelContext.js";
6
- import { Dropdown as y } from "../Dropdown/Dropdown2.js";
7
- import { InputSearch as B } from "../InputSearch/InputSearch2.js";
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 = I(), v = !!(n && u?.isMobile), d = typeof n == "object" ? n.count ?? 0 : 0, h = [
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(B, {
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(y, {
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 S, jsx as N, jsxs as D } from "react/jsx-runtime";
5
- import { createPortal as V } from "react-dom";
6
- var K = ({ title: L, position: T = "top", delay: _ = 200, children: k, disabled: $ = !1, className: F = "", maxWidth: p, maxHeight: a }) => {
7
- const [f, u] = B(!1), [M, I] = B({
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), g = h(!1), w = a !== void 0, v = w ? 150 : 0, R = () => {
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(), m = 8;
20
+ const n = d.current.getBoundingClientRect(), v = 8;
21
21
  let o = 0, i = 0;
22
- switch (T) {
22
+ switch (p) {
23
23
  case "top":
24
- o = e.top - n.height - m, i = e.left + e.width / 2 - n.width / 2;
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 + m, i = e.left + e.width / 2 - n.width / 2;
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 - m;
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 + m;
33
+ o = e.top + e.height / 2 - n.height / 2, i = e.right + v;
34
34
  }
35
- const s = 8;
36
- i < s && (i = s), i + n.width > window.innerWidth - s && (i = window.innerWidth - n.width - s), o < s && (o = s), o + n.height > window.innerHeight - s && (o = window.innerHeight - n.height - s), 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
- $ || g.current || (r.current && (clearTimeout(r.current), r.current = null), c.current = setTimeout(() => {
42
- u(!0);
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
- g.current || (c.current && clearTimeout(c.current), v > 0 ? r.current = setTimeout(() => u(!1), v) : u(!1));
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" || $ || (g.current = !0, c.current && (clearTimeout(c.current), c.current = null), t.stopPropagation(), u((e) => !e));
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) || u(!1);
52
+ e.target instanceof Node && d.current?.contains(e.target) || s(!1);
53
53
  };
54
- return R(), window.addEventListener("scroll", t, !0), window.addEventListener("resize", R), () => {
55
- window.removeEventListener("scroll", t, !0), window.removeEventListener("resize", R);
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) || u(!1);
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), g.current = !1;
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
- w && r.current && (clearTimeout(r.current), r.current = null);
69
+ m && r.current && (clearTimeout(r.current), r.current = null);
70
70
  }, z = () => {
71
- w && (r.current = setTimeout(() => u(!1), v));
71
+ m && (r.current = setTimeout(() => s(!1), R));
72
72
  };
73
- return /* @__PURE__ */ D(S, { children: [/* @__PURE__ */ N("span", {
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: k
82
- }), f && L && V(/* @__PURE__ */ D("div", {
81
+ children: _
82
+ }), f && L && O(/* @__PURE__ */ k("div", {
83
83
  ref: d,
84
- className: `tooltip tooltip--${T} ${w ? "tooltip--scrollable" : ""} ${F}`,
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
- ...p !== void 0 && { maxWidth: typeof p == "number" ? `${p}px` : p },
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--${T}` })]
93
+ children: [L, /* @__PURE__ */ N("div", { className: `tooltip__arrow tooltip__arrow--${p}` })]
94
94
  }), document.body)] });
95
95
  };
96
96
  export {
97
- K as Tooltip
97
+ Q as Tooltip
98
98
  };
@@ -0,0 +1,5 @@
1
+ import { createContext as t } from "react";
2
+ var e = t(void 0);
3
+ export {
4
+ e as AuthContext
5
+ };
@@ -1,114 +1,110 @@
1
- import { HttpMethod as s, buildRequestHeaders as w } from "../../helpers/Http.js";
2
- import { createContext as A, useCallback as i, useEffect as U, useState as d } from "react";
3
- import { jsx as j } from "react/jsx-runtime";
4
- var v = A(void 0);
5
- function P({ children: h, config: a }) {
6
- const [c, l] = d(null), [f, o] = d(!0);
7
- U(() => {
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: s.Get,
12
+ method: o.Get,
12
13
  credentials: "include",
13
14
  headers: { "Content-Type": "application/json" }
14
15
  });
15
16
  if (t.ok) {
16
- const e = await t.json();
17
- l({
18
- id: e.user.id,
19
- username: e.user.username,
20
- createdAt: new Date(e.user.createdAt)
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
- console.error("Failed to restore auth state:", t);
25
+ h.warn("Auth check could not reach the server", { error: String(t) });
25
26
  } finally {
26
- o(!1);
27
+ s(!1);
27
28
  }
28
29
  })();
29
30
  }, [a.apiBaseUrl]);
30
- const n = i((r) => {
31
- r.user && l({
32
- id: r.user.id,
33
- username: r.user.username,
34
- createdAt: new Date(r.user.createdAt)
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
- }, []), p = i(async (r) => {
37
- o(!0);
37
+ }, []), m = i(async (e) => {
38
+ s(!0);
38
39
  try {
39
40
  const t = await fetch(`${a.apiBaseUrl}/auth/login`, {
40
- method: s.Post,
41
+ method: o.Post,
41
42
  credentials: "include",
42
43
  headers: { "Content-Type": "application/json" },
43
44
  body: JSON.stringify({
44
- username: r.username,
45
- password: r.password,
46
- rememberMe: r.rememberMe
45
+ username: e.username,
46
+ password: e.password,
47
+ rememberMe: e.rememberMe
47
48
  })
48
49
  });
49
50
  if (!t.ok) {
50
- const u = await t.json();
51
- throw new Error(u.error || "Login failed");
51
+ const l = await t.json();
52
+ throw new Error(l.error || "Login failed");
52
53
  }
53
- const e = await t.json();
54
- return e.mfaRequired ? {
54
+ const r = await t.json();
55
+ return r.mfaRequired ? {
55
56
  mfaRequired: !0,
56
- method: e.method
57
- } : (n(e), { mfaRequired: !1 });
58
- } catch (t) {
59
- throw console.error("Login failed:", t), t;
57
+ method: r.method
58
+ } : (n(r), { mfaRequired: !1 });
60
59
  } finally {
61
- o(!1);
60
+ s(!1);
62
61
  }
63
- }, [a.apiBaseUrl, n]), m = i(async (r, t) => {
64
- o(!0);
62
+ }, [a.apiBaseUrl, n]), y = i(async (e, t) => {
63
+ s(!0);
65
64
  try {
66
- const e = await fetch(`${a.apiBaseUrl}/auth/verifyMfa`, {
67
- method: s.Post,
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: r,
70
+ code: e,
72
71
  trustDevice: t
73
72
  })
74
73
  });
75
- if (!e.ok) {
76
- const u = await e.json();
77
- throw new Error(u.error || "Verification failed");
74
+ if (!r.ok) {
75
+ const l = await r.json();
76
+ throw new Error(l.error || "Verification failed");
78
77
  }
79
- n(await e.json());
80
- } catch (e) {
81
- throw console.error("MFA verification failed:", e), e;
78
+ n(await r.json());
82
79
  } finally {
83
- o(!1);
80
+ s(!1);
84
81
  }
85
- }, [a.apiBaseUrl, n]), y = i(async () => {
82
+ }, [a.apiBaseUrl, n]), w = i(async () => {
86
83
  try {
87
84
  await fetch(`${a.apiBaseUrl}/auth/logout`, {
88
- method: s.Post,
85
+ method: o.Post,
89
86
  credentials: "include",
90
- headers: w(s.Post)
87
+ headers: A(o.Post)
91
88
  });
92
- } catch (r) {
93
- console.error("Logout error:", r);
89
+ } catch (e) {
90
+ h.warn("Logout request failed", { error: String(e) });
94
91
  } finally {
95
- l(null);
92
+ u(null);
96
93
  }
97
94
  }, [a.apiBaseUrl]);
98
- return /* @__PURE__ */ j(v.Provider, {
95
+ return /* @__PURE__ */ B(U.Provider, {
99
96
  value: {
100
- user: c,
101
- isAuthenticated: !!c,
102
- isLoading: f,
97
+ user: d,
98
+ isAuthenticated: !!d,
99
+ isLoading: p,
103
100
  config: a,
104
- login: p,
105
- verifyMfa: m,
106
- logout: y
101
+ login: m,
102
+ verifyMfa: y,
103
+ logout: w
107
104
  },
108
- children: h
105
+ children: f
109
106
  });
110
107
  }
111
108
  export {
112
- v as AuthContext,
113
- P as AuthProvider
109
+ C as AuthProvider
114
110
  };
@@ -1,34 +1,41 @@
1
- var g = class {
1
+ import { logger as g } from "@memobit/core";
2
+ var n = class {
2
3
  static getData(e, t) {
3
4
  try {
4
- const a = localStorage.getItem(e);
5
- if (a) {
6
- const r = JSON.parse(a), o = { ...t.pages };
7
- if (r.pages && typeof r.pages == "object") for (const s of Object.keys(r.pages)) {
8
- const c = t.pages[s], n = r.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
- ...n
12
- } : o[s] = n;
12
+ ...i
13
+ } : o[s] = i;
13
14
  }
14
15
  return {
15
16
  pages: o,
16
17
  theme: {
17
18
  ...t.theme,
18
- ...r.theme
19
+ ...a.theme
19
20
  }
20
21
  };
21
22
  }
22
- } catch (a) {
23
- console.warn(`Failed to load app persistence data for ${e}:`, a);
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 (a) {
31
- console.warn(`Failed to save app persistence data for ${e}:`, a);
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
- console.warn(`Failed to clear app persistence data for ${e}:`, t);
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
- g as AppPersistenceStorage
59
+ n as AppPersistenceStorage
50
60
  };
@@ -1,4 +1,5 @@
1
- var l = {
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
- }, n = {
36
+ }, s = {
36
37
  Get: "GET",
37
38
  Post: "POST",
38
39
  Put: "PUT",
39
40
  Patch: "PATCH",
40
41
  Delete: "DELETE"
41
- }, w = (e) => e >= 200 && e < 300, C = (e) => e >= 400 && e < 500, E = (e) => e >= 500 && e < 600, f = "csrf_token", h = "X-CSRF-Token", v = () => {
42
- const e = document.cookie.match(new RegExp(`(?:^|;\\s*)${f}=([^;]+)`));
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, r = !0) => {
45
- const s = r ? { "Content-Type": "application/json" } : {};
46
- if (e !== n.Get) {
47
- const i = v();
48
- i && (s[h] = i);
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 s;
51
- }, y = class extends Error {
52
- constructor(e, r) {
53
- super(e), this.name = "ApiError", this.status = r;
51
+ return n;
52
+ }, v = class extends Error {
53
+ constructor(e, t) {
54
+ super(e), this.name = "ApiError", this.status = t;
54
55
  }
55
- }, T = async (e) => {
56
+ }, P = async (e) => {
56
57
  try {
57
- const r = await e.json();
58
- if (r && typeof r == "object") {
59
- if ("error" in r && typeof r.error == "string") return r.error;
60
- if ("message" in r && typeof r.message == "string") return r.message;
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
- }, P = ({ baseUrl: e, loginPath: r = "/login" }) => {
66
- let s = !1;
67
- const i = (t) => `${e.replace(/\/$/, "")}/${t.replace(/^\//, "")}`, c = async (t, o, u, p = !0) => {
68
- const a = await fetch(i(t), {
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
- headers: m(o, p),
71
- credentials: "include",
72
- body: u
73
- });
74
- if (a.status === l.Unauthorized && !window.location.pathname.startsWith(r))
75
- return s || (s = !0, window.location.href = `${r}?session_expired=true`), new Promise(() => {
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
- if (!a.ok) throw new y(await T(a), a.status);
78
- if (a.status !== l.NoContent)
79
- return await a.json();
80
- }, d = (t, o, u) => c(t, o, u === void 0 ? void 0 : JSON.stringify(u));
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: (t) => c(t, n.Get),
83
- post: (t, o) => d(t, n.Post, o),
84
- put: (t, o) => d(t, n.Put, o),
85
- patch: (t, o) => d(t, n.Patch, o),
86
- delete: (t) => c(t, n.Delete),
87
- upload: (t, o) => c(t, n.Post, o, !1)
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
- y as ApiError,
92
- h as CSRF_HEADER,
93
- n as HttpMethod,
94
- l as HttpStatus,
118
+ v as ApiError,
119
+ S as CSRF_HEADER,
120
+ s as HttpMethod,
121
+ c as HttpStatus,
95
122
  m as buildRequestHeaders,
96
- P as createApiClient,
97
- v as getCsrfToken,
98
- C as isClientErrorStatus,
99
- E as isServerErrorStatus,
100
- w as isSuccessStatus,
101
- T as readErrorMessage
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
  };
@@ -23,7 +23,7 @@ var r = (i) => {
23
23
  const o = {
24
24
  ...i,
25
25
  lib: d,
26
- libBuildNumber: 509,
26
+ libBuildNumber: 515,
27
27
  libCommit: n,
28
28
  libBuildDate: t
29
29
  };