@logora/debate 0.4.91 → 0.4.93

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.
@@ -9,7 +9,7 @@ import { useAuthRequired as D } from "../../hooks/use_auth_required/useAuthRequi
9
9
  import { AuthProviderFactory as F } from "../providers/AuthProviderFactory.js";
10
10
  import { OnboardingModal as J } from "../../user/onboarding_modal/OnboardingModal.js";
11
11
  import { saveOnboardingBeforeLogin as M } from "../../user/onboarding_modal/useOnboarding.js";
12
- import { httpClient as d } from "../../data/axios_client/httpClient.js";
12
+ import { httpClient as d } from "../../data/http_client/httpClient.js";
13
13
  const j = (e) => {
14
14
  const t = e.replace(/-/g, "+").replace(/_/g, "/"), a = t.padEnd(t.length + (4 - t.length % 4) % 4, "=");
15
15
  return new TextDecoder().decode(Uint8Array.from(atob(a), (r) => r.charCodeAt(0)));
@@ -5,7 +5,7 @@ import { useConfig as I } from "../../data/config_provider/useConfig.js";
5
5
  import { useModal as y } from "../../dialog/modal/useModal.js";
6
6
  import { useAuth as C } from "../use_auth/useAuth.js";
7
7
  import { useAuthActions as E } from "../use_auth/useAuthActions.js";
8
- import { httpClient as P } from "../../data/axios_client/httpClient.js";
8
+ import { httpClient as P } from "../../data/http_client/httpClient.js";
9
9
  import { Modal as T } from "../../dialog/modal/Modal.js";
10
10
  import { Loader as R } from "../../progress/loader/Loader.js";
11
11
  import { SocialAuthForm as B } from "../social_auth_form/SocialAuthForm.js";
@@ -1,54 +1,67 @@
1
- import { makeStorage as g } from "./AuthStorage.js";
2
- const y = (i, k, _) => {
3
- const a = g(_), l = () => a.getToken(), d = () => {
4
- a.removeToken();
5
- }, f = (e, r) => {
1
+ import { makeStorage as y } from "./AuthStorage.js";
2
+ const p = (k, c, _) => {
3
+ const i = y(_), u = () => i.getToken(), f = () => {
4
+ i.removeToken();
5
+ }, l = (e, n) => {
6
6
  const t = {
7
7
  ...e,
8
8
  expires_at: e.created_at + e.expires_in,
9
- session_id: r
9
+ session_id: n
10
10
  };
11
- a.setToken(t);
11
+ i.setToken(t);
12
12
  };
13
13
  let s = null;
14
- const h = (e) => {
14
+ const T = (e) => {
15
15
  if (s) return s;
16
- const r = e.session_id, t = new Promise((c, u) => i.post(k, e).then((n) => {
17
- if (n.data.access_token) {
18
- const T = n.data;
19
- f(T, r), c(n);
16
+ const n = e.session_id, t = new Promise((a, h) => k.post(c, e).then((r) => {
17
+ if (r.data.access_token) {
18
+ const x = r.data;
19
+ l(x, n), a(r);
20
20
  } else
21
- u(n);
22
- }).catch((n) => {
23
- u(n);
21
+ h(r);
22
+ }).catch((r) => {
23
+ h(r);
24
24
  })).finally(() => {
25
25
  s = null;
26
26
  });
27
27
  return s = t, t;
28
28
  };
29
29
  let o = null;
30
+ const d = () => {
31
+ if (o) return o;
32
+ const e = u(), n = {
33
+ grant_type: "refresh_token",
34
+ refresh_token: e.refresh_token
35
+ };
36
+ return o = k.post(c, n).then((t) => {
37
+ if (t.data.access_token) {
38
+ const a = t.data;
39
+ return l(a, e.session_id), a.access_token;
40
+ }
41
+ return Promise.reject(t);
42
+ }).finally(() => {
43
+ o = null;
44
+ }), o;
45
+ }, m = (e) => {
46
+ try {
47
+ return e.expires_at < Date.now() / 1e3;
48
+ } catch {
49
+ return !1;
50
+ }
51
+ };
30
52
  return {
31
- getToken: l,
32
- removeToken: d,
33
- fetchToken: h,
34
- refreshToken: () => {
35
- if (o) return o;
36
- const e = l(), r = {
37
- grant_type: "refresh_token",
38
- refresh_token: e.refresh_token
39
- };
40
- return o = i.post(k, r).then((t) => {
41
- if (t.data.access_token) {
42
- const c = t.data;
43
- return f(c, e.session_id), c.access_token;
44
- }
45
- return Promise.reject(t);
46
- }).finally(() => {
47
- o = null;
48
- }), o;
53
+ getToken: u,
54
+ removeToken: f,
55
+ fetchToken: T,
56
+ refreshToken: d,
57
+ ensureValidToken: (e) => {
58
+ if (!e?.headers?.authorization)
59
+ return e;
60
+ const n = u();
61
+ return !n || !m(n) || e.url === c ? e : d().then((t) => (e.headers.authorization = `Bearer ${t}`, e));
49
62
  }
50
63
  };
51
64
  };
52
65
  export {
53
- y as authTokenHandler
66
+ p as authTokenHandler
54
67
  };
@@ -1,35 +1,15 @@
1
- import { useEffect as f } from "react";
2
- import { authTokenHandler as m } from "./authTokenHandler.js";
3
- const k = (t, o, s) => {
4
- const { getToken: u, refreshToken: a } = m(
5
- t,
6
- o,
7
- s
8
- ), i = (e) => {
9
- try {
10
- return e.expires_at < Date.now() / 1e3;
11
- } catch {
12
- return !1;
13
- }
1
+ import { useEffect as s } from "react";
2
+ import { authTokenHandler as u } from "./authTokenHandler.js";
3
+ const f = (e, r, t) => (s(() => {
4
+ const { ensureValidToken: o } = u(
5
+ e,
6
+ r,
7
+ t
8
+ ), n = e.interceptors.request.use(o);
9
+ return () => {
10
+ e.interceptors.request.eject?.(n);
14
11
  };
15
- return f(() => {
16
- t.interceptors.request.use(
17
- (e) => {
18
- const r = e;
19
- if (r.headers.authorization) {
20
- const n = u();
21
- if (n && i(n) && e.url !== o)
22
- return a().then((c) => {
23
- const h = `Bearer ${c}`;
24
- return r.headers.authorization = h, Promise.resolve(r);
25
- });
26
- }
27
- return e;
28
- },
29
- (e) => Promise.reject(e)
30
- );
31
- }, []), null;
32
- };
12
+ }, []), null);
33
13
  export {
34
- k as useAuthInterceptor
14
+ f as useAuthInterceptor
35
15
  };
@@ -0,0 +1,103 @@
1
+ const C = "application/json", g = "application/json, text/plain, */*", f = [], E = (t) => t instanceof Date ? t.toISOString() : String(t), A = (t, e) => {
2
+ if (!e)
3
+ return t;
4
+ const n = new URLSearchParams();
5
+ for (const [c, i] of Object.entries(e))
6
+ if (i != null)
7
+ if (Array.isArray(i))
8
+ for (const o of i)
9
+ o != null && n.append(`${c}[]`, E(o));
10
+ else
11
+ n.append(c, E(i));
12
+ const r = n.toString();
13
+ return r ? t.includes("?") ? `${t}&${r}` : `${t}?${r}` : t;
14
+ }, O = (t) => t ? Array.isArray(t) ? Object.fromEntries(t) : typeof t.entries == "function" ? Object.fromEntries(t.entries()) : { ...t } : {}, w = (t, e) => {
15
+ const n = e.toLowerCase();
16
+ return Object.keys(t).some((r) => r.toLowerCase() === n);
17
+ }, P = (t) => {
18
+ const e = {};
19
+ if (!t)
20
+ return e;
21
+ for (const [n, r] of t.entries())
22
+ e[n.toLowerCase()] = r;
23
+ return e;
24
+ }, H = (t, e) => {
25
+ if (t != null)
26
+ return typeof FormData < "u" && t instanceof FormData || typeof t == "string" ? t : (w(e, "content-type") || (e["Content-Type"] = C), JSON.stringify(t));
27
+ }, S = (t) => {
28
+ if (!t)
29
+ return "";
30
+ try {
31
+ return JSON.parse(t);
32
+ } catch {
33
+ return t;
34
+ }
35
+ }, h = (t, e, n) => {
36
+ const r = new Error(t);
37
+ return e && (r.response = e), n && (r.code = n), r;
38
+ }, b = async (t) => {
39
+ let e = t;
40
+ for (const n of [...f])
41
+ e = await n(e);
42
+ return e;
43
+ }, u = async (t, e, n, r) => {
44
+ const { params: c, headers: i = {}, timeout: o = 1e4 } = r ?? {}, d = O(i);
45
+ w(d, "accept") || (d.Accept = g);
46
+ const a = await b({
47
+ url: A(e, c),
48
+ method: t,
49
+ headers: d,
50
+ data: n,
51
+ timeout: o
52
+ }), p = O(a.headers), l = new AbortController();
53
+ let y = !1;
54
+ const T = o ? setTimeout(() => {
55
+ y = !0, l.abort();
56
+ }, o) : null;
57
+ try {
58
+ const s = await fetch(a.url, {
59
+ method: a.method,
60
+ headers: p,
61
+ body: H(a.data, p),
62
+ signal: l.signal
63
+ }), m = {
64
+ data: S(await s.text()),
65
+ status: s.status,
66
+ statusText: s.statusText,
67
+ headers: P(s.headers)
68
+ };
69
+ if (!s.ok)
70
+ throw h(
71
+ `Request failed with status code ${s.status}`,
72
+ m
73
+ );
74
+ return m;
75
+ } catch (s) {
76
+ throw y ? h(
77
+ `timeout of ${o}ms exceeded`,
78
+ void 0,
79
+ "ECONNABORTED"
80
+ ) : s;
81
+ } finally {
82
+ T && clearTimeout(T);
83
+ }
84
+ }, q = {
85
+ interceptors: {
86
+ request: {
87
+ use: (t) => (f.push(t), () => {
88
+ const e = f.indexOf(t);
89
+ e !== -1 && f.splice(e, 1);
90
+ }),
91
+ eject: (t) => {
92
+ typeof t == "function" && t();
93
+ }
94
+ }
95
+ },
96
+ get: (t, e) => u("GET", t, void 0, e),
97
+ delete: (t, e) => u("DELETE", t, void 0, e),
98
+ post: (t, e, n) => u("POST", t, e, n),
99
+ patch: (t, e, n) => u("PATCH", t, e, n)
100
+ };
101
+ export {
102
+ q as httpClient
103
+ };
@@ -6,9 +6,9 @@ import t from "./ContentHeader.module.scss.js";
6
6
  import { useRelativeTime as b } from "../../hooks/use_relative_time/useRelativeTime.js";
7
7
  import { useConfig as x } from "../../data/config_provider/useConfig.js";
8
8
  import { Icon as g } from "../../icons/icon/Icon.js";
9
- import { UserBoxSmall as H } from "../../user/user_box_small/UserBoxSmall.js";
10
- import { AuthorBox as w } from "../../user/author_box/AuthorBox.js";
11
- const $ = ({
9
+ import { UserBoxSmall as w } from "../../user/user_box_small/UserBoxSmall.js";
10
+ import { AuthorBox as H } from "../../user/author_box/AuthorBox.js";
11
+ const U = ({
12
12
  author: e,
13
13
  tag: r,
14
14
  tagClassName: _,
@@ -22,7 +22,9 @@ const $ = ({
22
22
  moderationPolicyUrl: m,
23
23
  showModerationFeedback: v = !1
24
24
  }) => {
25
- const M = b(new Date(l).getTime()), n = N(), f = x();
25
+ const M = b(
26
+ Math.min(new Date(l).getTime(), Date.now())
27
+ ), n = N(), f = x();
26
28
  return /* @__PURE__ */ o("div", { className: t.contentHeaderContainer, children: [
27
29
  v && /* @__PURE__ */ o("div", { className: t.moderationInfo, children: [
28
30
  /* @__PURE__ */ o("div", { className: t.moderationReason, children: [
@@ -82,14 +84,14 @@ const $ = ({
82
84
  ] }),
83
85
  /* @__PURE__ */ o("div", { className: t.contentHeader, children: [
84
86
  /* @__PURE__ */ a("div", { className: t.contentHeaderAuthorBox, children: i === !0 ? /* @__PURE__ */ a(
85
- H,
87
+ w,
86
88
  {
87
89
  userName: e.full_name,
88
90
  avatarUrl: e.image_url,
89
91
  userSlug: e.hash_id
90
92
  }
91
93
  ) : /* @__PURE__ */ a(
92
- w,
94
+ H,
93
95
  {
94
96
  fullName: e.full_name,
95
97
  avatarUrl: e.image_url,
@@ -124,5 +126,5 @@ const $ = ({
124
126
  ] });
125
127
  };
126
128
  export {
127
- $ as ContentHeader
129
+ U as ContentHeader
128
130
  };
package/dist/index.js CHANGED
@@ -133,7 +133,7 @@ import { classes as rx, getAccent as ex } from "./components/input/text_input/co
133
133
  import { dataProvider as xx } from "./components/data/data_provider/DataProvider.js";
134
134
  import { extractFormData as px } from "./components/forms/form/extract-form-data.js";
135
135
  import { getTranslatedContent as nx, useTranslatedContent as ax } from "./components/translation/translated_content/useTranslatedContent.js";
136
- import { httpClient as sx } from "./components/data/axios_client/httpClient.js";
136
+ import { httpClient as sx } from "./components/data/http_client/httpClient.js";
137
137
  import { lexicalToHtml as dx } from "./components/input/text_editor/lexicalToHtml.js";
138
138
  import { makeStorage as gx } from "./components/auth/use_auth/AuthStorage.js";
139
139
  import { uniqueBy as Bx } from "./components/util/unique_by/uniqueBy.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logora/debate",
3
- "version": "0.4.91",
3
+ "version": "0.4.93",
4
4
  "type": "module",
5
5
  "license": "AGPL-3.0",
6
6
  "description": "Design system of @Logora made with React",
@@ -52,7 +52,6 @@
52
52
  "@lexical/selection": "^0.45.0",
53
53
  "@lexical/utils": "^0.45.0",
54
54
  "@rooks/use-previous": "^4.11.2",
55
- "axios": "^1.15.2",
56
55
  "chart.js": "^4.5.1",
57
56
  "chartjs-plugin-datalabels": "^2.2.0",
58
57
  "classnames": "^2.5.1",
@@ -1,8 +0,0 @@
1
- import t from "axios";
2
- const e = 1e4, r = t.create({
3
- timeout: e,
4
- adapter: "fetch"
5
- });
6
- export {
7
- r as httpClient
8
- };