@m4l/layouts 0.1.14 → 0.1.16

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.
@@ -0,0 +1,33 @@
1
+ import { unstable_HistoryRouter as c } from "react-router-dom";
2
+ import { LocalesProvider as m, HostThemeProvider as d } from "@m4l/graphics";
3
+ import "../../node_modules.6a6cd7c4.js";
4
+ import { DomainCountryProvider as u } from "@m4l/core";
5
+ import { jsx as r } from "react/jsx-runtime";
6
+ function M(o) {
7
+ const {
8
+ children: t,
9
+ currentLocale: i,
10
+ hostTheme: e,
11
+ history: n,
12
+ domainCountryId: s
13
+ } = o;
14
+ return /* @__PURE__ */ r(m, {
15
+ isMicroFrontEnd: !0,
16
+ localeHost: i,
17
+ children: /* @__PURE__ */ r(d, {
18
+ isMicroFrontEnd: !0,
19
+ ...e,
20
+ children: /* @__PURE__ */ r(u, {
21
+ domainCountryId: s,
22
+ isMicroFrontEnd: !0,
23
+ children: /* @__PURE__ */ r(c, {
24
+ history: n,
25
+ children: t
26
+ })
27
+ })
28
+ })
29
+ });
30
+ }
31
+ export {
32
+ M
33
+ };
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { MFHostAppProps } from './types';
3
+ export declare function MFHostApp(props: MFHostAppProps): JSX.Element;
4
+ export default MFHostApp;
@@ -0,0 +1,19 @@
1
+ import { ReactNode } from 'react';
2
+ import type { AxiosOperation, EnvironmentType, HostToolsType } from '@m4l/core';
3
+ import { HostThemeType, LocaleType } from '@m4l/graphics';
4
+ import type { BrowserHistory } from 'history';
5
+ export declare type ByHostProps = {
6
+ environment: EnvironmentType;
7
+ hostTools: HostToolsType;
8
+ axiosOperation: AxiosOperation;
9
+ hostTheme: HostThemeType;
10
+ currentLocale: LocaleType;
11
+ domainCountryId: number;
12
+ };
13
+ export declare type MFHostAppProps = {
14
+ domainCountryId: number;
15
+ history: BrowserHistory;
16
+ hostTheme: HostThemeType;
17
+ currentLocale: LocaleType;
18
+ children: ReactNode;
19
+ };
@@ -0,0 +1,105 @@
1
+ import { useEffect as v, useMemo as d } from "react";
2
+ import { unstable_HistoryRouter as y } from "react-router-dom";
3
+ import { ToastContainer as P, toast as M } from "react-toastify";
4
+ import { HostThemeProvider as w, defaultThemeOptions as F, fnComponentsOverrides as H, ProgressBarStyle as g, LocalesProvider as A, getLocaleFromNetwork as k } from "@m4l/graphics";
5
+ import { A as T } from "../../contexts/AuthContext/index.6f966215.js";
6
+ import { voidFunction as m, EnvironmentProvider as x, HostToolsProvider as E, NetworkProvider as C, axiosOperation as N, DomainCountryProvider as O } from "@m4l/core";
7
+ import { c as I, f as L, N as _ } from "../../node_modules.6a6cd7c4.js";
8
+ import { u as b } from "../../hooks/useAuth/index.cb6a3420.js";
9
+ import { jsx as o, jsxs as j } from "react/jsx-runtime";
10
+ function B(r) {
11
+ const {
12
+ children: s,
13
+ user: i,
14
+ pwd: n
15
+ } = r, {
16
+ isAuthenticated: t,
17
+ isInitialized: e,
18
+ login: a
19
+ } = b();
20
+ return v(() => {
21
+ e && t === !1 && a(i, n, !1);
22
+ }, [e, t]), t ? /* @__PURE__ */ j(w, {
23
+ hostThemeOptions: F,
24
+ fnComponentsOverrides: H,
25
+ isMicroFrontEnd: !0,
26
+ children: [/* @__PURE__ */ o(g, {}), /* @__PURE__ */ o(P, {}), s]
27
+ }) : /* @__PURE__ */ o("div", {
28
+ children: "Pendiente x atenticar"
29
+ });
30
+ }
31
+ const c = I({
32
+ window
33
+ });
34
+ function U(r) {
35
+ const {
36
+ children: s,
37
+ user: i,
38
+ pwd: n,
39
+ host_api_local: t,
40
+ host_api_remote: e,
41
+ host_static_assets: a,
42
+ environment_assets: l
43
+ } = r, f = () => {
44
+ _.configure({
45
+ showSpinner: !0
46
+ }), _.start();
47
+ }, h = () => {
48
+ _.done();
49
+ }, u = d(() => ({
50
+ host: "",
51
+ isLocalhost: !0,
52
+ domain_token: "lab1",
53
+ host_api_local: t,
54
+ host_api_remote: e,
55
+ host_static_assets: a,
56
+ environment_assets: l,
57
+ dfnsFormat: {
58
+ date_format: "yyyy-MM-dd",
59
+ date_mask: "____-__-__",
60
+ time_format: "HH:mm:ss",
61
+ time_mask: "__:__:__",
62
+ datetime_format: "yyyy-MM-dd HH:mm:ss",
63
+ datetime_mask: "____-__-__ __:__:__"
64
+ }
65
+ }), []), p = d(() => ({
66
+ history: c,
67
+ toast: M,
68
+ startProgress: f,
69
+ stopProgress: h,
70
+ events_add_listener: m,
71
+ events_remove_listener: m,
72
+ events_emit: m,
73
+ formatDate: L
74
+ }), []);
75
+ return /* @__PURE__ */ o(x, {
76
+ ...u,
77
+ children: /* @__PURE__ */ o(E, {
78
+ ...p,
79
+ children: /* @__PURE__ */ o(C, {
80
+ axiosOperation: N,
81
+ children: /* @__PURE__ */ o(y, {
82
+ history: c,
83
+ children: /* @__PURE__ */ o(A, {
84
+ isMicroFrontEnd: !1,
85
+ getLocaleFromNetwork: k,
86
+ children: /* @__PURE__ */ o(O, {
87
+ domainCountryId: 1,
88
+ isMicroFrontEnd: !1,
89
+ children: /* @__PURE__ */ o(T, {
90
+ children: /* @__PURE__ */ o(B, {
91
+ user: i,
92
+ pwd: n,
93
+ children: s
94
+ })
95
+ })
96
+ })
97
+ })
98
+ })
99
+ })
100
+ })
101
+ });
102
+ }
103
+ export {
104
+ U as M
105
+ };
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { MFIsolationAppProps } from './types';
3
+ export declare function MFIsolationApp(props: MFIsolationAppProps): JSX.Element;
4
+ export default MFIsolationApp;
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { MFAuthAppProps } from './types';
3
+ export declare function MFAuthApp(props: MFAuthAppProps): JSX.Element;
4
+ export default MFAuthApp;
@@ -0,0 +1,6 @@
1
+ import { ReactNode } from 'react';
2
+ export declare type MFAuthAppProps = {
3
+ user: string;
4
+ pwd: string;
5
+ children: ReactNode;
6
+ };
@@ -0,0 +1,10 @@
1
+ import { ReactNode } from 'react';
2
+ export declare type MFIsolationAppProps = {
3
+ host_api_local: string;
4
+ host_api_remote: string;
5
+ host_static_assets: string;
6
+ environment_assets: string;
7
+ user: string;
8
+ pwd: string;
9
+ children: ReactNode;
10
+ };
@@ -0,0 +1,3 @@
1
+ export * from './MFIsolationApp';
2
+ export * from './MFHostApp';
3
+ export type { ByHostProps } from './MFHostApp/types';
@@ -0,0 +1,130 @@
1
+ import { createContext as T, useReducer as y, useEffect as d } from "react";
2
+ import { useHostTools as E, useNetwork as S, useEnvironment as v, useLocalStorageWithListener as N, EmitEvents as O, getLocalStorage as w, setLocalStorage as r } from "@m4l/core";
3
+ import { jsx as D } from "react/jsx-runtime";
4
+ var n = /* @__PURE__ */ ((e) => (e.Initial = "INITIALIZE", e.Login = "LOGIN", e.Logout = "LOGOUT", e))(n || {});
5
+ const _ = {
6
+ isAuthenticated: !1,
7
+ isInitialized: !1,
8
+ user: null
9
+ }, P = (e, t) => {
10
+ switch (t.type) {
11
+ case "INITIALIZE":
12
+ return {
13
+ isAuthenticated: t.payload.isAuthenticated,
14
+ isInitialized: !0,
15
+ user: t.payload.user
16
+ };
17
+ case "LOGIN":
18
+ return {
19
+ ...e,
20
+ isAuthenticated: !0,
21
+ user: t.payload.user
22
+ };
23
+ case "LOGOUT":
24
+ return {
25
+ ...e,
26
+ isAuthenticated: !1,
27
+ user: null
28
+ };
29
+ default:
30
+ return e;
31
+ }
32
+ }, x = T(null);
33
+ function z(e) {
34
+ e({
35
+ type: n.Initial,
36
+ payload: {
37
+ isAuthenticated: !1,
38
+ user: null
39
+ }
40
+ });
41
+ }
42
+ function R(e) {
43
+ const {
44
+ children: t
45
+ } = e, [h, s] = y(P, _), {
46
+ events_add_listener: I
47
+ } = E(), {
48
+ networkOperation: u
49
+ } = S(), {
50
+ domain_token: m
51
+ } = v(), [f, l] = N(
52
+ "vSession",
53
+ new Date().getTime() + ""
54
+ );
55
+ d(() => {
56
+ (async () => {
57
+ u({
58
+ method: "GET",
59
+ endPoint: "auth/login",
60
+ parms: {
61
+ user_data: !0
62
+ },
63
+ checkUnAuthorized: !1
64
+ }).then((a) => {
65
+ s({
66
+ type: n.Initial,
67
+ payload: {
68
+ isAuthenticated: !0,
69
+ user: a.user
70
+ }
71
+ }), w("userData", {
72
+ email: a.user.email,
73
+ remember: !0
74
+ })?.email !== a.user.email && r("userData", {
75
+ email: a.user.email
76
+ }, !0);
77
+ }).catch(() => {
78
+ z(s);
79
+ });
80
+ })();
81
+ }, [f]);
82
+ const g = async (i, a, o) => {
83
+ await u({
84
+ endPoint: "auth/login",
85
+ method: "POST",
86
+ data: {
87
+ email: i,
88
+ password: a,
89
+ domain_token: m
90
+ }
91
+ }).then((A) => {
92
+ const L = A.data;
93
+ o ? r("userData", {
94
+ email: i,
95
+ remember: o
96
+ }) : r("userData", {
97
+ email: "",
98
+ remember: o
99
+ }), s({
100
+ type: n.Login,
101
+ payload: {
102
+ user: L
103
+ }
104
+ }), l(new Date().getTime() + "");
105
+ });
106
+ }, c = async (i) => {
107
+ i && await u({
108
+ endPoint: "auth/logout",
109
+ method: "POST"
110
+ }), s({
111
+ type: n.Logout
112
+ }), l(new Date().getTime() + "");
113
+ }, p = () => {
114
+ c(!1);
115
+ };
116
+ return d(() => {
117
+ I(O.EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED, p);
118
+ }, []), /* @__PURE__ */ D(x.Provider, {
119
+ value: {
120
+ ...h,
121
+ login: g,
122
+ logout: c
123
+ },
124
+ children: t
125
+ });
126
+ }
127
+ export {
128
+ R as A,
129
+ x as a
130
+ };
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import type { AuthProviderProps, SessionContextType } from './types';
3
+ declare const AuthContext: import("react").Context<SessionContextType | null>;
4
+ declare function AuthProvider(props: AuthProviderProps): JSX.Element;
5
+ export { AuthContext, AuthProvider };
@@ -0,0 +1,54 @@
1
+ import { Maybe } from '@m4l/core';
2
+ import { ReactNode } from 'react';
3
+ export declare enum EnumTypes {
4
+ Initial = "INITIALIZE",
5
+ Login = "LOGIN",
6
+ Logout = "LOGOUT"
7
+ }
8
+ export declare type AuthProviderProps = {
9
+ children: ReactNode;
10
+ };
11
+ export declare type ActionMap<M extends {
12
+ [index: string]: any;
13
+ }> = {
14
+ [Key in keyof M]: M[Key] extends undefined ? {
15
+ type: Key;
16
+ } : {
17
+ type: Key;
18
+ payload: M[Key];
19
+ };
20
+ };
21
+ export declare type SessionAuthPayload = {
22
+ [EnumTypes.Initial]: {
23
+ isAuthenticated: boolean;
24
+ user: AuthUser;
25
+ };
26
+ [EnumTypes.Login]: {
27
+ user: AuthUser;
28
+ };
29
+ [EnumTypes.Logout]: undefined;
30
+ };
31
+ export declare type SessionActions = ActionMap<SessionAuthPayload>[keyof ActionMap<SessionAuthPayload>];
32
+ export declare type AuthStoreState = {
33
+ user: User;
34
+ remember?: boolean;
35
+ };
36
+ export interface User {
37
+ email: string;
38
+ id: number;
39
+ first_name: string;
40
+ last_name: string;
41
+ account_id: number;
42
+ domain_country_id: number;
43
+ avatar_url?: Maybe<string>;
44
+ }
45
+ export declare type AuthUser = Maybe<User>;
46
+ export declare type AuthState = {
47
+ isAuthenticated: boolean;
48
+ isInitialized: boolean;
49
+ user: AuthUser;
50
+ };
51
+ export interface SessionContextType extends AuthState {
52
+ login: (email: string, password: string, remember: boolean) => object | undefined;
53
+ logout: (isAuthenticated: boolean) => Promise<void>;
54
+ }
@@ -0,0 +1 @@
1
+ export * from './AuthContext';
package/hooks/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './useMasterDetail';
2
+ export * from './useAuth';
2
3
  export * from './useModule';
@@ -0,0 +1,11 @@
1
+ import { useContext as o } from "react";
2
+ import { a as e } from "../../contexts/AuthContext/index.6f966215.js";
3
+ const n = () => {
4
+ const t = o(e);
5
+ if (!t)
6
+ throw new Error("Auth context must be use inside AuthProvider");
7
+ return t;
8
+ };
9
+ export {
10
+ n as u
11
+ };
@@ -0,0 +1,2 @@
1
+ export declare const useAuth: () => import("../../contexts/AuthContext/types").SessionContextType;
2
+ export default useAuth;
package/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
+ export * from './components';
2
+ export * from './contexts';
1
3
  export * from './layouts';
2
4
  export * from './hooks';
package/index.js CHANGED
@@ -1,25 +1,38 @@
1
- import { a as p, d as l, g as y } from "./layouts/ModuleLayout/index.842072c5.js";
2
- import "@m4l/components";
1
+ import { M as n } from "./components/MFIsolationApp/index.967f891d.js";
2
+ import { M as f } from "./components/MFHostApp/index.60578754.js";
3
+ import { a as D, A } from "./contexts/AuthContext/index.6f966215.js";
4
+ import { a as c, d as g, g as h } from "./layouts/ModuleLayout/index.842072c5.js";
5
+ import { a as N, d as F, g as v } from "./layouts/MasterDetailLayout/index.71de0dc7.js";
6
+ import { N as I, d as P, g as b } from "./layouts/NoAuthModuleLayout/index.5d1098ef.js";
7
+ import { u as k } from "./hooks/useMasterDetail/index.8e9e900b.js";
8
+ import { u as w } from "./hooks/useAuth/index.cb6a3420.js";
9
+ import { u as B } from "./hooks/useModule/index.096d7d13.js";
3
10
  import "react";
4
- import "@m4l/core";
5
- import { a as n, d as M, g as D } from "./layouts/MasterDetailLayout/index.71de0dc7.js";
11
+ import "react-router-dom";
12
+ import "react-toastify";
6
13
  import "@m4l/graphics";
7
- import "@mui/material";
14
+ import "@m4l/core";
15
+ import "./node_modules.6a6cd7c4.js";
16
+ import "./vendor.9dd106b8.js";
8
17
  import "react/jsx-runtime";
9
- import { N as L, d as c, g } from "./layouts/NoAuthModuleLayout/index.5d1098ef.js";
10
- import { u as N } from "./hooks/useMasterDetail/index.8e9e900b.js";
11
- import { u as A } from "./hooks/useModule/index.096d7d13.js";
18
+ import "@m4l/components";
19
+ import "@mui/material";
12
20
  import "@mui/material/styles";
13
21
  export {
14
- n as MasterDetailLayout,
15
- p as ModuleLayout,
16
- L as NoAuthModuleLayout,
17
- M as defaultMasterDetailDictionary,
18
- l as defaultModuleLayoutDictionary,
19
- c as defaultNoAuthModuleLayoutDictionary,
20
- D as getMasterDetailLayoutComponentsDictionary,
21
- y as getModuleLayoutComponentsDictionary,
22
- g as getNoAuthModuleLayoutComponentsDictionary,
23
- N as useMasterDetail,
24
- A as useModule
22
+ D as AuthContext,
23
+ A as AuthProvider,
24
+ f as MFHostApp,
25
+ n as MFIsolationApp,
26
+ N as MasterDetailLayout,
27
+ c as ModuleLayout,
28
+ I as NoAuthModuleLayout,
29
+ F as defaultMasterDetailDictionary,
30
+ g as defaultModuleLayoutDictionary,
31
+ P as defaultNoAuthModuleLayoutDictionary,
32
+ v as getMasterDetailLayoutComponentsDictionary,
33
+ h as getModuleLayoutComponentsDictionary,
34
+ b as getNoAuthModuleLayoutComponentsDictionary,
35
+ w as useAuth,
36
+ k as useMasterDetail,
37
+ B as useModule
25
38
  };