@variamosple/variamos-components 0.0.19 → 0.0.22

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.
@@ -1,52 +1,55 @@
1
- import { j as o } from "../../jsx-runtime-Drh4NO5G.js";
2
- import * as d from "react";
1
+ import { j as a } from "../../jsx-runtime-Drh4NO5G.js";
2
+ import * as p from "react";
3
3
  import f, { useEffect as u } from "react";
4
4
  import "../../Context/AnalyticsContext.js";
5
5
  import "../../Context/MenuContext.js";
6
- import { useRouter as l } from "../../Context/RouterContext.js";
7
- import { useSession as h } from "../../Context/SessionsContext.js";
8
- import { u as g, c as x } from "../../ThemeProvider-Q3gZ4GF2.js";
9
- const p = /* @__PURE__ */ d.forwardRef(({
10
- bsPrefix: e,
11
- variant: i,
12
- animation: n = "border",
13
- size: a,
6
+ import { useRouter as h } from "../../Context/RouterContext.js";
7
+ import { useSession as l } from "../../Context/SessionContext.js";
8
+ import { u as g, c as w } from "../../ThemeProvider-Q3gZ4GF2.js";
9
+ const d = /* @__PURE__ */ p.forwardRef(({
10
+ bsPrefix: t,
11
+ variant: n,
12
+ animation: i = "border",
13
+ size: c,
14
14
  // Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
15
- as: t = "div",
16
- className: r,
15
+ as: r = "div",
16
+ className: s,
17
17
  ...m
18
- }, c) => {
19
- e = g(e, "spinner");
20
- const s = `${e}-${n}`;
21
- return /* @__PURE__ */ o.jsx(t, {
22
- ref: c,
18
+ }, e) => {
19
+ t = g(t, "spinner");
20
+ const o = `${t}-${i}`;
21
+ return /* @__PURE__ */ a.jsx(r, {
22
+ ref: e,
23
23
  ...m,
24
- className: x(r, s, a && `${s}-${a}`, i && `text-${i}`)
24
+ className: w(s, o, c && `${o}-${c}`, n && `text-${n}`)
25
25
  });
26
26
  });
27
- p.displayName = "Spinner";
28
- const v = ({
29
- redirectPath: e,
30
- children: i
27
+ d.displayName = "Spinner";
28
+ const k = ({
29
+ redirectPath: t,
30
+ children: n
31
31
  }) => {
32
- const [n, a] = f.useState(!1), { isAuthenticated: t, isLoading: r } = h(), { navigate: m } = l();
32
+ const [i, c] = f.useState(!1), { isAuthenticated: r, isLoading: s } = l(), { navigate: m } = h();
33
33
  return u(() => {
34
- if (!r && !t && !n) {
35
- const c = window.location.href, s = new URLSearchParams();
36
- s.set("redirectTo", encodeURIComponent(c)), a(!0), setTimeout(
37
- () => m(`${e}?${s.toString()}`),
34
+ if (!s && !r && !i) {
35
+ const e = window.location.href, o = new URLSearchParams();
36
+ o.set("redirectTo", encodeURIComponent(e)), c(!0), setTimeout(
37
+ () => m(`${t}?${o.toString()}`),
38
38
  300
39
39
  );
40
40
  }
41
- }, [t, r, e, m, n]), r || !t ? /* @__PURE__ */ o.jsx("div", { className: "d-flex justify-content-center align-items-center w-100 h-100", children: /* @__PURE__ */ o.jsx(
42
- p,
41
+ }, [r, s, t, m, i]), u(() => {
42
+ const e = new URL(window.location.href);
43
+ e.searchParams.has("authToken") && (localStorage.setItem("authToken", e.searchParams.get("authToken")), e.searchParams.delete("authToken"), window.history.replaceState({}, "", e));
44
+ }, []), s || !r ? /* @__PURE__ */ a.jsx("div", { className: "d-flex justify-content-center align-items-center w-100 h-100", children: /* @__PURE__ */ a.jsx(
45
+ d,
43
46
  {
44
47
  animation: "border",
45
48
  variant: "primary",
46
49
  style: { width: "3rem", height: "3rem", borderWidth: "0.5rem" }
47
50
  }
48
- ) }) : /* @__PURE__ */ o.jsx(o.Fragment, { children: i });
51
+ ) }) : /* @__PURE__ */ a.jsx(a.Fragment, { children: n });
49
52
  };
50
53
  export {
51
- v as AuthWrapper
54
+ k as AuthWrapper
52
55
  };
@@ -3,7 +3,7 @@ import { useMemo as p } from "react";
3
3
  import "../../Context/AnalyticsContext.js";
4
4
  import { useMenu as w } from "../../Context/MenuContext.js";
5
5
  import { useRouter as x } from "../../Context/RouterContext.js";
6
- import { useSession as j } from "../../Context/SessionsContext.js";
6
+ import { useSession as j } from "../../Context/SessionContext.js";
7
7
  import { mapToWebTarget as R } from "../../Model/Router.js";
8
8
  import { N as a } from "../../NavDropdown-AuV3RgfC.js";
9
9
  const E = () => {
@@ -3,7 +3,7 @@ import { useMemo as N } from "react";
3
3
  import "../../Context/AnalyticsContext.js";
4
4
  import "../../Context/MenuContext.js";
5
5
  import { useRouter as R } from "../../Context/RouterContext.js";
6
- import { useSession as k } from "../../Context/SessionsContext.js";
6
+ import { useSession as k } from "../../Context/SessionContext.js";
7
7
  import { mapToWebTarget as m } from "../../Model/Router.js";
8
8
  import { N as h } from "../../Nav-CdxSljzW.js";
9
9
  import { N as d } from "../../NavDropdown-AuV3RgfC.js";
@@ -3,8 +3,8 @@ import "react";
3
3
  import "../../Context/AnalyticsContext.js";
4
4
  import "../../Context/MenuContext.js";
5
5
  import "../../Context/RouterContext.js";
6
- import "../../Context/SessionsContext.js";
7
- import { S as d } from "../../SubHeader-DNc4qWBV.js";
6
+ import "../../Context/SessionContext.js";
7
+ import { S as d } from "../../SubHeader-gTVD9DIX.js";
8
8
  import "../../Container-BLjzOisH.js";
9
9
  import "../../Nav-CdxSljzW.js";
10
10
  export {
@@ -2,10 +2,10 @@ import { j as s } from "../../jsx-runtime-Drh4NO5G.js";
2
2
  import "../../Context/AnalyticsContext.js";
3
3
  import { useMenu as d } from "../../Context/MenuContext.js";
4
4
  import { useRouter as x } from "../../Context/RouterContext.js";
5
- import { useSession as j } from "../../Context/SessionsContext.js";
5
+ import { useSession as j } from "../../Context/SessionContext.js";
6
6
  import { HeaderOptions as u } from "./HeaderOptions.js";
7
7
  import { MenuItemComponent as o } from "./MenuItem.js";
8
- import { N as r, S as f } from "../../SubHeader-DNc4qWBV.js";
8
+ import { N as r, S as f } from "../../SubHeader-gTVD9DIX.js";
9
9
  import { C as h } from "../../Container-BLjzOisH.js";
10
10
  import { N as t } from "../../Nav-CdxSljzW.js";
11
11
  const I = ({
@@ -2,7 +2,7 @@ import { j as t } from "../../jsx-runtime-Drh4NO5G.js";
2
2
  import "../../Context/AnalyticsContext.js";
3
3
  import "../../Context/MenuContext.js";
4
4
  import { useRouter as o } from "../../Context/RouterContext.js";
5
- import "../../Context/SessionsContext.js";
5
+ import "../../Context/SessionContext.js";
6
6
  import { C as s } from "../../Container-BLjzOisH.js";
7
7
  import { B as i } from "../../Button-GQJKgb76.js";
8
8
  const d = ({ homePath: e }) => {
@@ -3,7 +3,7 @@ import { useEffect as f } from "react";
3
3
  import "../../Context/AnalyticsContext.js";
4
4
  import "../../Context/MenuContext.js";
5
5
  import { useRouter as g } from "../../Context/RouterContext.js";
6
- import { useSession as x } from "../../Context/SessionsContext.js";
6
+ import { useSession as x } from "../../Context/SessionContext.js";
7
7
  const v = ({
8
8
  notAuthorizedPath: e,
9
9
  allowedPermissions: i = [],
@@ -2,7 +2,7 @@ import { j as F } from "../jsx-runtime-Drh4NO5G.js";
2
2
  import { createContext as j, useMemo as d, useEffect as E, useContext as L } from "react";
3
3
  import { useQuery as S } from "../Hooks/useQuery.js";
4
4
  import { useRouter as y } from "./RouterContext.js";
5
- import { useSession as m } from "./SessionsContext.js";
5
+ import { useSession as m } from "./SessionContext.js";
6
6
  const P = j({
7
7
  items: [],
8
8
  isLoading: !0
@@ -1,5 +1,5 @@
1
1
  import { FC, ReactNode } from 'react';
2
- import { Credentials, ResponseModel, SessionUser, singInResponse, UserRegistration } from '../Model';
2
+ import { Credentials, ResponseModel, SessionInfoResponse, SessionUser, singInResponse, UserRegistration } from '../Model';
3
3
  interface SessionContextType {
4
4
  user: SessionUser | null;
5
5
  isLoading: boolean;
@@ -10,7 +10,8 @@ interface SessionContextType {
10
10
  logout: () => void;
11
11
  }
12
12
  export interface SessionProviderProps {
13
- getSessionInfo: () => Promise<ResponseModel<SessionUser>>;
13
+ loginUrl: string;
14
+ getSessionInfo: () => Promise<ResponseModel<SessionInfoResponse>>;
14
15
  requestLogout: () => Promise<ResponseModel<void>>;
15
16
  requestSignIn?: (request: Credentials) => Promise<ResponseModel<singInResponse>>;
16
17
  requestSignInAsGuest?: (guestId?: string | null) => Promise<ResponseModel<singInResponse>>;
@@ -0,0 +1,97 @@
1
+ import { j as G } from "../jsx-runtime-Drh4NO5G.js";
2
+ import { createContext as K, useState as S, useEffect as T, useContext as N } from "react";
3
+ import { Events as R } from "../Common/Events.js";
4
+ import { usePageVisibility as V } from "../Hooks/usePageVisibility.js";
5
+ const y = K(void 0), k = "guestId", f = (d) => {
6
+ d && R.publish("variamosNavigate", d);
7
+ }, m = (d) => {
8
+ d && sessionStorage.setItem("authToken", d);
9
+ }, H = ({
10
+ loginUrl: d,
11
+ getSessionInfo: h,
12
+ requestSignUp: v,
13
+ requestSignIn: w,
14
+ requestSignInAsGuest: C,
15
+ requestLogout: P,
16
+ children: b
17
+ }) => {
18
+ const [E, t] = S(null), [j, c] = S(!0), g = !!E, x = V();
19
+ T(() => {
20
+ c(!0), h().then((o) => {
21
+ var i, n, a;
22
+ o != null && o.errorCode ? t(null) : (m((i = o == null ? void 0 : o.data) == null ? void 0 : i.authToken), t(((n = o == null ? void 0 : o.data) == null ? void 0 : n.user) ?? null), f((a = o == null ? void 0 : o.data) == null ? void 0 : a.redirect));
23
+ }).catch(() => {
24
+ t(null);
25
+ }).finally(() => c(!1));
26
+ }, [h]), T(() => {
27
+ if (g && x) {
28
+ const o = () => {
29
+ h().then((n) => {
30
+ var a, r, e;
31
+ n != null && n.errorCode ? t(null) : (m((a = n == null ? void 0 : n.data) == null ? void 0 : a.authToken), t(((r = n == null ? void 0 : n.data) == null ? void 0 : r.user) ?? null), f((e = n == null ? void 0 : n.data) == null ? void 0 : e.redirect));
32
+ }).catch(() => {
33
+ t(null);
34
+ });
35
+ };
36
+ o();
37
+ const i = setInterval(() => {
38
+ o();
39
+ }, 6e4);
40
+ return () => clearInterval(i);
41
+ }
42
+ }, [g, x, h]);
43
+ const A = (o) => {
44
+ if (!v)
45
+ throw new Error("requestSignUp is not defined.");
46
+ return c(!0), v(o).finally(() => c(!1));
47
+ }, L = (o) => {
48
+ if (!w)
49
+ throw new Error("requestSignIn is not defined.");
50
+ return c(!0), w(o).then((i) => i != null && i.errorCode ? i : h().then((n) => {
51
+ var a, r, e;
52
+ return n != null && n.errorCode ? (t(null), i.withError(n.errorCode, n.message)) : (m((a = n == null ? void 0 : n.data) == null ? void 0 : a.authToken), t(((r = n == null ? void 0 : n.data) == null ? void 0 : r.user) ?? null), f((e = n == null ? void 0 : n.data) == null ? void 0 : e.redirect)), i;
53
+ }).catch(() => (t(null), i.withError(500, "Sign in error.")))).finally(() => c(!1));
54
+ }, U = () => {
55
+ if (!C)
56
+ throw new Error("requestSignInAsGuest is not defined.");
57
+ c(!0);
58
+ const o = localStorage.getItem(k);
59
+ return C(o).then((i) => {
60
+ var n;
61
+ return i != null && i.errorCode ? i : (localStorage.setItem(k, ((n = i == null ? void 0 : i.data) == null ? void 0 : n.id) || ""), h().then((a) => {
62
+ var r, e, I;
63
+ return a != null && a.errorCode ? (t(null), i.withError(a.errorCode, a.message)) : (m((r = a == null ? void 0 : a.data) == null ? void 0 : r.authToken), t(((e = a == null ? void 0 : a.data) == null ? void 0 : e.user) ?? null), f((I = a == null ? void 0 : a.data) == null ? void 0 : I.redirect)), i;
64
+ }).catch(() => (t(null), i.withError(500, "Sign in error."))));
65
+ }).finally(() => c(!1));
66
+ }, q = () => {
67
+ P().then(() => {
68
+ sessionStorage.removeItem("authToken"), f(d), setTimeout(() => {
69
+ t(null);
70
+ }, 200);
71
+ });
72
+ };
73
+ return /* @__PURE__ */ G.jsx(
74
+ y.Provider,
75
+ {
76
+ value: {
77
+ user: E,
78
+ isAuthenticated: g,
79
+ logout: q,
80
+ signUp: A,
81
+ signIn: L,
82
+ signInAsGuest: U,
83
+ isLoading: j
84
+ },
85
+ children: b
86
+ }
87
+ );
88
+ }, J = () => {
89
+ const d = N(y);
90
+ if (d === void 0)
91
+ throw new Error("useSession must be used within a SessionProvider");
92
+ return d;
93
+ };
94
+ export {
95
+ H as SessionProvider,
96
+ J as useSession
97
+ };
@@ -1,4 +1,4 @@
1
1
  export * from './AnalyticsContext';
2
2
  export * from './MenuContext';
3
3
  export * from './RouterContext';
4
- export * from './SessionsContext';
4
+ export * from './SessionContext';
@@ -1,7 +1,7 @@
1
1
  import { AnalyticsContext as t, AnalyticsProvider as r, PAGE_VISIT_EVENT as s } from "./AnalyticsContext.js";
2
2
  import { MenuContext as u, MenuContextProvider as i, useMenu as x } from "./MenuContext.js";
3
3
  import { RouterContext as a, getBasePath as f, isAbsoluteUrl as l, useRouter as m } from "./RouterContext.js";
4
- import { SessionProvider as A, useSession as C } from "./SessionsContext.js";
4
+ import { SessionProvider as A, useSession as C } from "./SessionContext.js";
5
5
  export {
6
6
  t as AnalyticsContext,
7
7
  r as AnalyticsProvider,
@@ -0,0 +1,6 @@
1
+ import { SessionUser } from './SessionUser';
2
+ export interface SessionInfoResponse {
3
+ user: SessionUser;
4
+ authToken?: string;
5
+ redirect?: string;
6
+ }
@@ -0,0 +1 @@
1
+
@@ -3,6 +3,7 @@ export * from './Menu';
3
3
  export * from './PagedModel';
4
4
  export * from './ResponseModel';
5
5
  export * from './Router';
6
+ export * from './SessionInfoResponse';
6
7
  export * from './SessionUser';
7
8
  export * from './SingInResponse';
8
9
  export * from './UserRegistration';
@@ -4,7 +4,7 @@ import z, { useMemo as j, useContext as M, useState as Z, useRef as we, useEffec
4
4
  import "./Context/AnalyticsContext.js";
5
5
  import { useMenu as je } from "./Context/MenuContext.js";
6
6
  import { useRouter as $e } from "./Context/RouterContext.js";
7
- import { useSession as Te } from "./Context/SessionsContext.js";
7
+ import { useSession as Te } from "./Context/SessionContext.js";
8
8
  import { c as N, u as w } from "./ThemeProvider-Q3gZ4GF2.js";
9
9
  import { d as B, e as Ce, c as Re, S as Oe } from "./NavLink-ebvp1HCw.js";
10
10
  import { T as V, a as I, b as q, s as J, c as be, E as P, e as L, f as ee, h as Be, A as Se, d as ke, M as He, B as De, F as Fe, i as Me, g as Le } from "./AbstractModalHeader-UzCRSxIO.js";
package/dist/main.js CHANGED
@@ -9,7 +9,7 @@ import { ProtectedRoute as g } from "./Components/ProtectedRoute/index.js";
9
9
  import { AnalyticsContext as M, AnalyticsProvider as c, PAGE_VISIT_EVENT as y } from "./Context/AnalyticsContext.js";
10
10
  import { MenuContext as R, MenuContextProvider as V, useMenu as b } from "./Context/MenuContext.js";
11
11
  import { RouterContext as v, getBasePath as E, isAbsoluteUrl as T, useRouter as S } from "./Context/RouterContext.js";
12
- import { SessionProvider as I, useSession as N } from "./Context/SessionsContext.js";
12
+ import { SessionProvider as I, useSession as N } from "./Context/SessionContext.js";
13
13
  import { withPageVisit as U } from "./HOC/WithPageVisit.js";
14
14
  import { useDebouncedValue as _ } from "./Hooks/useDebouncedValue.js";
15
15
  import { usePageVisibility as z } from "./Hooks/usePageVisibility.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@variamosple/variamos-components",
3
3
  "private": false,
4
- "version": "0.0.19",
4
+ "version": "0.0.22",
5
5
  "type": "module",
6
6
  "main": "dist/main.js",
7
7
  "types": "dist/main.d.ts",
@@ -1,81 +0,0 @@
1
- import { j } from "../jsx-runtime-Drh4NO5G.js";
2
- import { createContext as A, useState as w, useEffect as m, useContext as b } from "react";
3
- import { usePageVisibility as L } from "../Hooks/usePageVisibility.js";
4
- const C = A(void 0), u = "guestId", K = ({
5
- getSessionInfo: o,
6
- requestSignUp: d,
7
- requestSignIn: f,
8
- requestSignInAsGuest: h,
9
- requestLogout: v,
10
- children: E
11
- }) => {
12
- const [l, r] = w(null), [x, a] = w(!0), c = !!l, g = L();
13
- m(() => {
14
- a(!0), o().then((i) => {
15
- i != null && i.errorCode ? r(null) : r((i == null ? void 0 : i.data) ?? null);
16
- }).catch(() => {
17
- r(null);
18
- }).finally(() => a(!1));
19
- }, [o]), m(() => {
20
- if (c && g) {
21
- const i = () => {
22
- o().then((t) => {
23
- t != null && t.errorCode ? r(null) : r((t == null ? void 0 : t.data) ?? null);
24
- }).catch(() => {
25
- r(null);
26
- });
27
- };
28
- i();
29
- const n = setInterval(() => {
30
- i();
31
- }, 6e4);
32
- return () => clearInterval(n);
33
- }
34
- }, [c, g, o]);
35
- const y = (i) => {
36
- if (!d)
37
- throw new Error("requestSignUp is not defined.");
38
- return a(!0), d(i).finally(() => a(!1));
39
- }, I = (i) => {
40
- if (!f)
41
- throw new Error("requestSignIn is not defined.");
42
- return a(!0), f(i).then((n) => n != null && n.errorCode ? n : o().then((t) => (t != null && t.errorCode ? (r(null), n.withError(t.errorCode, t.message)) : r((t == null ? void 0 : t.data) ?? null), n)).catch(() => (r(null), n.withError(500, "Sign in error.")))).finally(() => a(!1));
43
- }, S = () => {
44
- if (!h)
45
- throw new Error("requestSignInAsGuest is not defined.");
46
- a(!0);
47
- const i = localStorage.getItem(u);
48
- return h(i).then((n) => {
49
- var t;
50
- return n != null && n.errorCode ? n : (localStorage.setItem(u, ((t = n == null ? void 0 : n.data) == null ? void 0 : t.id) || ""), o().then((e) => (e != null && e.errorCode ? (r(null), n.withError(e.errorCode, e.message)) : r((e == null ? void 0 : e.data) ?? null), n)).catch(() => (r(null), n.withError(500, "Sign in error."))));
51
- }).finally(() => a(!1));
52
- }, P = () => {
53
- v().then(() => {
54
- r(null);
55
- });
56
- };
57
- return /* @__PURE__ */ j.jsx(
58
- C.Provider,
59
- {
60
- value: {
61
- user: l,
62
- isAuthenticated: c,
63
- logout: P,
64
- signUp: y,
65
- signIn: I,
66
- signInAsGuest: S,
67
- isLoading: x
68
- },
69
- children: E
70
- }
71
- );
72
- }, R = () => {
73
- const o = b(C);
74
- if (o === void 0)
75
- throw new Error("useSession must be used within a SessionProvider");
76
- return o;
77
- };
78
- export {
79
- K as SessionProvider,
80
- R as useSession
81
- };