@m4l/layouts 1.0.4 → 1.0.5

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 (82) hide show
  1. package/components/BaseModule/index.8ff0193e.js +39 -0
  2. package/components/BaseModule/index.d.ts +4 -0
  3. package/components/BaseModule/types.d.ts +10 -0
  4. package/components/MFHostApp/index.401a303e.js +79 -0
  5. package/components/MFHostApp/index.d.ts +4 -0
  6. package/components/MFHostApp/types.d.ts +17 -0
  7. package/components/MFIsolationApp/index.d.ts +4 -0
  8. package/components/MFIsolationApp/index.e733d368.js +181 -0
  9. package/components/MFIsolationApp/subcomponents/MFAuthApp/index.d.ts +4 -0
  10. package/components/MFIsolationApp/subcomponents/MFAuthApp/types.d.ts +6 -0
  11. package/components/MFIsolationApp/types.d.ts +14 -0
  12. package/components/MFNoAuthApp/index.d.ts +4 -0
  13. package/components/MFNoAuthApp/types.d.ts +10 -0
  14. package/components/index.7006a30d.js +47 -0
  15. package/components/index.d.ts +6 -0
  16. package/contexts/AuthContext/index.6f966215.js +160 -0
  17. package/contexts/AuthContext/index.d.ts +5 -0
  18. package/contexts/AuthContext/types.d.ts +51 -0
  19. package/contexts/index.d.ts +1 -0
  20. package/contexts/index.ee173661.js +1 -0
  21. package/hooks/index.77acdde7.js +1 -0
  22. package/{dist/hooks → hooks}/index.d.ts +1 -0
  23. package/hooks/useAuth/index.cb6a3420.js +11 -0
  24. package/hooks/useAuth/index.d.ts +2 -0
  25. package/{dist/hooks/useMasterDetail/index.js → hooks/useMasterDetail/index.d45f2a86.js} +4 -2
  26. package/{dist/hooks/useModule/index.js → hooks/useModule/index.b5f598b1.js} +4 -2
  27. package/index.d.ts +4 -0
  28. package/index.js +46 -0
  29. package/{dist/layouts/MasterDetailLayout/index.d.ts → layouts/MasterDetailLayout/MasterDetailLayout.d.ts} +1 -1
  30. package/layouts/MasterDetailLayout/classes/constants.d.ts +1 -0
  31. package/layouts/MasterDetailLayout/classes/index.d.ts +6 -0
  32. package/layouts/MasterDetailLayout/classes/types.d.ts +6 -0
  33. package/{dist/layouts → layouts}/MasterDetailLayout/contexts/MasterDetailContext/index.d.ts +1 -1
  34. package/{dist/layouts → layouts}/MasterDetailLayout/contexts/MasterDetailContext/types.d.ts +2 -3
  35. package/layouts/MasterDetailLayout/index.748f7ada.js +155 -0
  36. package/layouts/MasterDetailLayout/styles.d.ts +2 -0
  37. package/{dist/layouts → layouts}/MasterDetailLayout/types.d.ts +0 -1
  38. package/layouts/ModuleLayout/classes/constants.d.ts +1 -0
  39. package/layouts/ModuleLayout/classes/index.d.ts +7 -0
  40. package/layouts/ModuleLayout/classes/types.d.ts +7 -0
  41. package/{dist/layouts → layouts}/ModuleLayout/contexts/ModuleContext/index.d.ts +2 -2
  42. package/{dist/layouts → layouts}/ModuleLayout/contexts/ModuleContext/types.d.ts +4 -9
  43. package/layouts/ModuleLayout/index.e7218171.js +122 -0
  44. package/layouts/ModuleLayout/subcomponents/InnerModule/index.d.ts +3 -0
  45. package/layouts/ModuleLayout/subcomponents/InnerModule/styles.d.ts +2 -0
  46. package/layouts/ModuleLayout/types.d.ts +16 -0
  47. package/layouts/NoAuthModuleLayout/dicctionary.d.ts +3 -0
  48. package/layouts/NoAuthModuleLayout/index.83cd3ea3.js +425 -0
  49. package/layouts/NoAuthModuleLayout/index.d.ts +3 -0
  50. package/layouts/NoAuthModuleLayout/subcomponents/InnerModule/index.d.ts +2 -0
  51. package/layouts/NoAuthModuleLayout/subcomponents/InnerModule/styles.d.ts +2 -0
  52. package/layouts/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/DesktopContent/index.d.ts +2 -0
  53. package/layouts/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/DesktopContent/styles.d.ts +10 -0
  54. package/layouts/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/MobileContent/index.d.ts +2 -0
  55. package/layouts/NoAuthModuleLayout/subcomponents/InnerModule/subcomponents/MobileContent/styles.d.ts +9 -0
  56. package/layouts/NoAuthModuleLayout/types.d.ts +20 -0
  57. package/layouts/index.417b6868.js +1 -0
  58. package/layouts/index.d.ts +6 -0
  59. package/m4l_layouts/types.d.ts +0 -0
  60. package/package.json +22 -55
  61. package/dist/hooks/useResponsive.d.ts +0 -8
  62. package/dist/index.d.ts +0 -2
  63. package/dist/index.js +0 -12
  64. package/dist/layouts/MasterDetailLayout/components/ButtonDetail/index.d.ts +0 -3
  65. package/dist/layouts/MasterDetailLayout/index.js +0 -170
  66. package/dist/layouts/ModuleLayout/components/Header/index.d.ts +0 -2
  67. package/dist/layouts/ModuleLayout/components/Header/skeleton.d.ts +0 -2
  68. package/dist/layouts/ModuleLayout/components/Header/styles.d.ts +0 -8
  69. package/dist/layouts/ModuleLayout/components/Header/types.d.ts +0 -2
  70. package/dist/layouts/ModuleLayout/components/ModuleContent/index.d.ts +0 -3
  71. package/dist/layouts/ModuleLayout/components/ModuleContent/styles.d.ts +0 -3
  72. package/dist/layouts/ModuleLayout/index.js +0 -380
  73. package/dist/layouts/ModuleLayout/types.d.ts +0 -28
  74. package/dist/layouts/index.d.ts +0 -2
  75. package/dist/vendor.js +0 -35
  76. /package/{dist/hooks → hooks}/useMasterDetail/index.d.ts +0 -0
  77. /package/{dist/hooks → hooks}/useModule/index.d.ts +0 -0
  78. /package/{dist/layouts → layouts}/MasterDetailLayout/dicctionary.d.ts +0 -0
  79. /package/{dist/layouts/ModuleLayout/index.d.ts → layouts/ModuleLayout/ModuleLayout.d.ts} +0 -0
  80. /package/{dist/layouts → layouts}/ModuleLayout/dicctionary.d.ts +0 -0
  81. /package/{dist/layouts/ModuleLayout/components/ModuleContent → layouts/ModuleLayout/subcomponents/InnerModule}/types.d.ts +0 -0
  82. /package/{dist/vite-env.d.ts → vite-env.d.ts} +0 -0
@@ -0,0 +1,39 @@
1
+ import { ModalProvider } from "@m4l/components";
2
+ import { FlagsProvider, ModuleDictionaryProvider, ModuleSkeletonProvider, ModulePrivilegesProvider } from "@m4l/core";
3
+ import { useLocales } from "@m4l/graphics";
4
+ import { jsx } from "react/jsx-runtime";
5
+ function BaseModule(props) {
6
+ const {
7
+ children,
8
+ isAuth = true,
9
+ moduleId,
10
+ moduleNameField,
11
+ skeletonFlags,
12
+ privileges,
13
+ componentsDictionary
14
+ } = props;
15
+ const localeString = useLocales().currentLocale?.localeString;
16
+ return /* @__PURE__ */ jsx(FlagsProvider, {
17
+ children: /* @__PURE__ */ jsx(ModuleDictionaryProvider, {
18
+ isAuth,
19
+ moduleId,
20
+ moduleNameField,
21
+ componentsDictionary,
22
+ currentLang: localeString,
23
+ children: /* @__PURE__ */ jsx(ModuleSkeletonProvider, {
24
+ flags: skeletonFlags,
25
+ children: isAuth ? /* @__PURE__ */ jsx(ModulePrivilegesProvider, {
26
+ queryPrivileges: privileges,
27
+ children: /* @__PURE__ */ jsx(ModalProvider, {
28
+ children
29
+ })
30
+ }) : /* @__PURE__ */ jsx(ModalProvider, {
31
+ children
32
+ })
33
+ })
34
+ })
35
+ });
36
+ }
37
+ export {
38
+ BaseModule as B
39
+ };
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { BaseModuleProps } from './types';
3
+ export declare function BaseModule(props: BaseModuleProps): import("react").JSX.Element;
4
+ export default BaseModule;
@@ -0,0 +1,10 @@
1
+ import { ReactNode } from 'react';
2
+ export declare type BaseModuleProps = {
3
+ moduleId: string;
4
+ skeletonFlags: string[];
5
+ moduleNameField?: string;
6
+ privileges: string[];
7
+ componentsDictionary: string[];
8
+ isAuth?: boolean;
9
+ children: ReactNode;
10
+ };
@@ -0,0 +1,79 @@
1
+ import { unstable_HistoryRouter } from "react-router-dom";
2
+ import { EnvironmentProvider, HostToolsProvider, NetworkProvider, DomainCountryProvider } from "@m4l/core";
3
+ import { LocalesProvider, HostThemeProvider, ResponsiveContainerProvider, FormatterProvider } from "@m4l/graphics";
4
+ import { WindowToolsMFProvider, DynamicMFParmsProvider } from "@m4l/components";
5
+ import { B as BaseModule } from "../BaseModule/index.8ff0193e.js";
6
+ import { jsx } from "react/jsx-runtime";
7
+ function MFHostApp(props) {
8
+ const {
9
+ children,
10
+ currentLocale,
11
+ hostTheme,
12
+ environment,
13
+ hostTools,
14
+ axiosOperation,
15
+ formatters,
16
+ isAuth = true,
17
+ moduleId,
18
+ moduleNameField,
19
+ skeletonFlags,
20
+ privileges,
21
+ componentsDictionary,
22
+ dynamicMFStore,
23
+ windowTools,
24
+ observedDivRef
25
+ } = props;
26
+ return /* @__PURE__ */ jsx(EnvironmentProvider, {
27
+ ...environment,
28
+ children: /* @__PURE__ */ jsx(HostToolsProvider, {
29
+ ...hostTools,
30
+ children: /* @__PURE__ */ jsx(NetworkProvider, {
31
+ axiosOperation,
32
+ children: /* @__PURE__ */ jsx(LocalesProvider, {
33
+ isMicroFrontEnd: true,
34
+ localeHost: currentLocale,
35
+ children: /* @__PURE__ */ jsx(HostThemeProvider, {
36
+ isMicroFrontEnd: true,
37
+ ...hostTheme,
38
+ children: /* @__PURE__ */ jsx(ResponsiveContainerProvider, {
39
+ observedDivRef,
40
+ children: /* @__PURE__ */ jsx(unstable_HistoryRouter, {
41
+ history: hostTools.history,
42
+ children: /* @__PURE__ */ jsx(DomainCountryProvider, {
43
+ isMicroFrontEnd: true,
44
+ id: dynamicMFStore?.getState().dynamicMFParameters?.id || 1,
45
+ currency: formatters.currencyFormatter.code,
46
+ currency_decimal_digits: formatters.currencyFormatter.decimalDigits,
47
+ decimal_symbol: formatters.numberFormatter.decimalSymbol,
48
+ thousands_symbol: formatters.numberFormatter.thousandsSymbol,
49
+ children: /* @__PURE__ */ jsx(BaseModule, {
50
+ isAuth,
51
+ moduleId,
52
+ moduleNameField,
53
+ componentsDictionary,
54
+ skeletonFlags,
55
+ privileges,
56
+ children: /* @__PURE__ */ jsx(FormatterProvider, {
57
+ isMicroFrontEnd: true,
58
+ ...formatters,
59
+ children: /* @__PURE__ */ jsx(WindowToolsMFProvider, {
60
+ ...windowTools,
61
+ children: /* @__PURE__ */ jsx(DynamicMFParmsProvider, {
62
+ store: dynamicMFStore,
63
+ children
64
+ })
65
+ })
66
+ })
67
+ })
68
+ })
69
+ })
70
+ })
71
+ })
72
+ })
73
+ })
74
+ })
75
+ });
76
+ }
77
+ export {
78
+ MFHostApp as M
79
+ };
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { MFHostAppProps } from './types';
3
+ export declare function MFHostApp(props: MFHostAppProps): import("react").JSX.Element;
4
+ export default MFHostApp;
@@ -0,0 +1,17 @@
1
+ import type { AxiosOperation, EnvironmentType, HostToolsType } from '@m4l/core';
2
+ import { Formatters, LocaleType } from '@m4l/graphics';
3
+ import { DynamicMFStore, WindowToolsMF } from '@m4l/components';
4
+ import { BaseModuleProps } from '../BaseModule/types';
5
+ import { HostThemeType } from '@m4l/graphics';
6
+ export interface ByHostProps {
7
+ environment: EnvironmentType;
8
+ hostTools: HostToolsType;
9
+ hostTheme: HostThemeType;
10
+ currentLocale: LocaleType;
11
+ axiosOperation: AxiosOperation;
12
+ formatters: Formatters;
13
+ dynamicMFStore: DynamicMFStore;
14
+ windowTools: WindowToolsMF;
15
+ observedDivRef: Element | Text | null;
16
+ }
17
+ export declare type MFHostAppProps = ByHostProps & BaseModuleProps;
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { MFIsolationAppProps } from './types';
3
+ export declare function MFIsolationApp(props: MFIsolationAppProps): import("react").JSX.Element;
4
+ export default MFIsolationApp;
@@ -0,0 +1,181 @@
1
+ import { useEffect, useMemo, useCallback } from "react";
2
+ import { unstable_HistoryRouter } from "react-router-dom";
3
+ import { ToastContainer, toast } from "react-toastify";
4
+ import { HostThemeProvider, FormatterProvider, LocalesProvider, getLocaleFromNetwork, ResponsiveContainerProvider } from "@m4l/graphics";
5
+ import { A as AuthProvider } from "../../contexts/AuthContext/index.6f966215.js";
6
+ import { DomainCountryProvider, EnvironmentProvider, HostToolsProvider, NetworkProvider, axiosOperation } from "@m4l/core";
7
+ import { createBrowserHistory } from "history";
8
+ import EventEmitter from "eventemitter3";
9
+ import { format } from "date-fns";
10
+ import { defaultThemeOptions, fnComponentsOverrides } from "@m4l/styles";
11
+ import { u as useAuth } from "../../hooks/useAuth/index.cb6a3420.js";
12
+ import { jsx, jsxs } from "react/jsx-runtime";
13
+ import NProgress from "nprogress";
14
+ import { B as BaseModule } from "../BaseModule/index.8ff0193e.js";
15
+ import { AreasProvider } from "@m4l/components";
16
+ function MFAuthApp(props) {
17
+ const {
18
+ children,
19
+ user,
20
+ pwd
21
+ } = props;
22
+ const {
23
+ isAuthenticated,
24
+ isInitialized,
25
+ login,
26
+ user: authUser
27
+ } = useAuth();
28
+ useEffect(() => {
29
+ if (isInitialized && isAuthenticated === false) {
30
+ login(user, pwd, false);
31
+ }
32
+ }, [isInitialized, isAuthenticated]);
33
+ if (!isAuthenticated)
34
+ return /* @__PURE__ */ jsx("div", {
35
+ children: "Pendiente x atenticar"
36
+ });
37
+ const domianCountry = {
38
+ id: 1,
39
+ currency: "USD",
40
+ currency_decimal_digits: 2,
41
+ decimal_symbol: ".",
42
+ thousands_symbol: ","
43
+ };
44
+ if (authUser?.domain_country) {
45
+ domianCountry.id = authUser?.domain_country.id ?? domianCountry.id;
46
+ domianCountry.currency = authUser?.domain_country.currency ?? domianCountry.currency;
47
+ domianCountry.currency_decimal_digits = authUser?.domain_country.currency_decimal_digits ?? domianCountry.currency_decimal_digits;
48
+ domianCountry.decimal_symbol = authUser?.domain_country.decimal_symbol ?? domianCountry.decimal_symbol;
49
+ domianCountry.thousands_symbol = authUser?.domain_country?.thousands_symbol ?? domianCountry.thousands_symbol;
50
+ }
51
+ return /* @__PURE__ */ jsxs(HostThemeProvider, {
52
+ hostThemeOptions: defaultThemeOptions,
53
+ fnComponentsOverrides,
54
+ isMicroFrontEnd: true,
55
+ children: [/* @__PURE__ */ jsx(ToastContainer, {}), /* @__PURE__ */ jsx(DomainCountryProvider, {
56
+ ...domianCountry,
57
+ isMicroFrontEnd: false,
58
+ children: /* @__PURE__ */ jsx(FormatterProvider, {
59
+ isMicroFrontEnd: false,
60
+ dateFormatter: {
61
+ formatDate: format
62
+ },
63
+ currencyFormatter: {
64
+ code: domianCountry.currency,
65
+ decimalDigits: domianCountry.currency_decimal_digits
66
+ },
67
+ children
68
+ })
69
+ })]
70
+ });
71
+ }
72
+ const history = createBrowserHistory({
73
+ window
74
+ });
75
+ function MFIsolationApp(props) {
76
+ const {
77
+ children,
78
+ user,
79
+ pwd,
80
+ database = "domain",
81
+ host_api_local,
82
+ host_api_remote,
83
+ host_static_assets,
84
+ environment_assets,
85
+ moduleId,
86
+ skeletonFlags,
87
+ moduleNameField,
88
+ privileges,
89
+ componentsDictionary,
90
+ onLoad,
91
+ activeAreasNetwork = false,
92
+ activeCookiesFromNetwork = false,
93
+ observedDivRef
94
+ } = props;
95
+ const eventEmitter = useMemo(() => new EventEmitter(), []);
96
+ const events_add_listener = useCallback((eventName, handler) => {
97
+ eventEmitter.on(eventName, handler);
98
+ }, [eventEmitter]);
99
+ const events_remove_listener = useCallback((eventName, handler) => {
100
+ if (handler === null) {
101
+ eventEmitter.removeListener(eventName);
102
+ return;
103
+ }
104
+ eventEmitter.removeListener(eventName, handler);
105
+ }, [eventEmitter]);
106
+ const events_emit = useCallback((eventName, arg) => {
107
+ eventEmitter.emit(eventName, arg);
108
+ }, [eventEmitter]);
109
+ const startProgress = () => {
110
+ NProgress.configure({
111
+ showSpinner: true
112
+ });
113
+ NProgress.start();
114
+ };
115
+ const stopProgress = () => {
116
+ NProgress.done();
117
+ };
118
+ const environment = useMemo(() => ({
119
+ host: "",
120
+ isLocalhost: true,
121
+ domain_token: "lab1",
122
+ database,
123
+ host_api_local,
124
+ host_api_remote,
125
+ host_static_assets,
126
+ environment_assets
127
+ }), []);
128
+ const hostTools = useMemo(() => ({
129
+ history,
130
+ toast,
131
+ startProgress,
132
+ stopProgress,
133
+ events_add_listener,
134
+ events_remove_listener,
135
+ events_emit
136
+ }), []);
137
+ return /* @__PURE__ */ jsx(EnvironmentProvider, {
138
+ ...environment,
139
+ children: /* @__PURE__ */ jsx(HostToolsProvider, {
140
+ ...hostTools,
141
+ children: /* @__PURE__ */ jsx(NetworkProvider, {
142
+ axiosOperation,
143
+ children: /* @__PURE__ */ jsx(unstable_HistoryRouter, {
144
+ history,
145
+ children: /* @__PURE__ */ jsx(LocalesProvider, {
146
+ isMicroFrontEnd: false,
147
+ getLocaleFromNetwork,
148
+ children: /* @__PURE__ */ jsx(AuthProvider, {
149
+ children: /* @__PURE__ */ jsx(MFAuthApp, {
150
+ user,
151
+ pwd,
152
+ children: /* @__PURE__ */ jsx(BaseModule, {
153
+ moduleId,
154
+ privileges,
155
+ skeletonFlags,
156
+ componentsDictionary,
157
+ moduleNameField,
158
+ children: /* @__PURE__ */ jsx(AreasProvider, {
159
+ onLoad,
160
+ loadAreasFromNetwork: activeAreasNetwork,
161
+ loadCookiesFromNetwork: activeCookiesFromNetwork,
162
+ onSelectLayout: (modId) => {
163
+ console.log("onSelectLayout", modId);
164
+ },
165
+ children: /* @__PURE__ */ jsx(ResponsiveContainerProvider, {
166
+ observedDivRef,
167
+ children
168
+ })
169
+ })
170
+ })
171
+ })
172
+ })
173
+ })
174
+ })
175
+ })
176
+ })
177
+ });
178
+ }
179
+ export {
180
+ MFIsolationApp as M
181
+ };
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { MFAuthAppProps } from './types';
3
+ export declare function MFAuthApp(props: MFAuthAppProps): import("react").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,14 @@
1
+ import { BaseModuleProps } from '../BaseModule/types';
2
+ export declare type MFIsolationAppProps = BaseModuleProps & {
3
+ user: string;
4
+ pwd: string;
5
+ host_api_local: string;
6
+ database?: string;
7
+ host_api_remote: string;
8
+ host_static_assets: string;
9
+ environment_assets: string;
10
+ onLoad: () => void;
11
+ activeAreasNetwork?: boolean;
12
+ activeCookiesFromNetwork?: boolean;
13
+ observedDivRef: Element | Text | null;
14
+ };
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { MFNoAuthAppProps } from './types';
3
+ export declare function MFNoAuthApp(props: MFNoAuthAppProps): import("react").JSX.Element;
4
+ export default MFNoAuthApp;
@@ -0,0 +1,10 @@
1
+ import { Formatters } from '@m4l/graphics';
2
+ import { WindowToolsMF } from '@m4l/components';
3
+ import { BaseModuleProps } from '../BaseModule/types';
4
+ export interface ByHostProps {
5
+ formatters: Formatters;
6
+ windowTools: WindowToolsMF;
7
+ }
8
+ export interface MFNoAuthAppProps extends ByHostProps, BaseModuleProps {
9
+ observedDivRef: Element | Text | null;
10
+ }
@@ -0,0 +1,47 @@
1
+ import { DomainCountryProvider } from "@m4l/core";
2
+ import { FormatterProvider, ResponsiveContainerProvider } from "@m4l/graphics";
3
+ import { B as BaseModule } from "./BaseModule/index.8ff0193e.js";
4
+ import { jsx } from "react/jsx-runtime";
5
+ function MFNoAuthApp(props) {
6
+ const {
7
+ children,
8
+ formatters,
9
+ moduleId,
10
+ moduleNameField,
11
+ skeletonFlags,
12
+ privileges,
13
+ componentsDictionary,
14
+ isAuth,
15
+ observedDivRef
16
+ } = props;
17
+ const domianCountry = {
18
+ id: 1,
19
+ currency: "USD",
20
+ currency_decimal_digits: 2,
21
+ decimal_symbol: ".",
22
+ thousands_symbol: ","
23
+ };
24
+ return /* @__PURE__ */ jsx(DomainCountryProvider, {
25
+ isMicroFrontEnd: true,
26
+ ...domianCountry,
27
+ children: /* @__PURE__ */ jsx(BaseModule, {
28
+ isAuth,
29
+ moduleId,
30
+ moduleNameField,
31
+ componentsDictionary,
32
+ skeletonFlags,
33
+ privileges,
34
+ children: /* @__PURE__ */ jsx(FormatterProvider, {
35
+ isMicroFrontEnd: true,
36
+ ...formatters,
37
+ children: /* @__PURE__ */ jsx(ResponsiveContainerProvider, {
38
+ observedDivRef,
39
+ children
40
+ })
41
+ })
42
+ })
43
+ });
44
+ }
45
+ export {
46
+ MFNoAuthApp as M
47
+ };
@@ -0,0 +1,6 @@
1
+ export { MFIsolationApp } from './MFIsolationApp';
2
+ export { MFNoAuthApp } from './MFNoAuthApp';
3
+ export { MFHostApp } from './MFHostApp';
4
+ export { BaseModule } from './BaseModule';
5
+ export type { ByHostProps } from './MFHostApp/types';
6
+ export type { BaseModuleProps } from './BaseModule/types';
@@ -0,0 +1,160 @@
1
+ import { createContext, useReducer, useEffect } from "react";
2
+ import { useHostTools, useNetwork, useEnvironment, useLocalStorageWithListener, EmitEvents, getLocalStorage, setLocalStorage } from "@m4l/core";
3
+ import { jsx } from "react/jsx-runtime";
4
+ var EnumTypes = /* @__PURE__ */ ((EnumTypes2) => {
5
+ EnumTypes2["Initial"] = "INITIALIZE";
6
+ EnumTypes2["Login"] = "LOGIN";
7
+ EnumTypes2["Logout"] = "LOGOUT";
8
+ return EnumTypes2;
9
+ })(EnumTypes || {});
10
+ const initialState = {
11
+ isAuthenticated: false,
12
+ isInitialized: false,
13
+ user: null
14
+ };
15
+ const JWTReducer = (state, action) => {
16
+ switch (action.type) {
17
+ case "INITIALIZE":
18
+ return {
19
+ isAuthenticated: action.payload.isAuthenticated,
20
+ isInitialized: true,
21
+ user: action.payload.user
22
+ };
23
+ case "LOGIN":
24
+ return {
25
+ ...state,
26
+ isAuthenticated: true,
27
+ user: action.payload.user
28
+ };
29
+ case "LOGOUT":
30
+ return {
31
+ ...state,
32
+ isAuthenticated: false,
33
+ user: null
34
+ };
35
+ default:
36
+ return state;
37
+ }
38
+ };
39
+ const AuthContext = createContext(null);
40
+ function dispatchInitial(dispatch) {
41
+ dispatch({
42
+ type: EnumTypes.Initial,
43
+ payload: {
44
+ isAuthenticated: false,
45
+ user: null
46
+ }
47
+ });
48
+ }
49
+ function AuthProvider(props) {
50
+ const {
51
+ children
52
+ } = props;
53
+ const [state, dispatch] = useReducer(JWTReducer, initialState);
54
+ const {
55
+ events_add_listener
56
+ } = useHostTools();
57
+ const {
58
+ networkOperation
59
+ } = useNetwork();
60
+ const {
61
+ domain_token
62
+ } = useEnvironment();
63
+ const [nextValSession, setNextValSession] = useLocalStorageWithListener(
64
+ "vSession",
65
+ new Date().getTime() + ""
66
+ );
67
+ useEffect(() => {
68
+ const initialize = async () => {
69
+ networkOperation({
70
+ method: "GET",
71
+ endPoint: `auth/login`,
72
+ parms: {
73
+ user_data: true
74
+ },
75
+ checkUnAuthorized: false
76
+ }).then((response) => {
77
+ dispatch({
78
+ type: EnumTypes.Initial,
79
+ payload: {
80
+ isAuthenticated: true,
81
+ user: response.user
82
+ }
83
+ });
84
+ const useSaved = getLocalStorage("userData", {
85
+ email: response.user.email,
86
+ remember: true
87
+ });
88
+ if (useSaved?.email !== response.user.email) {
89
+ setLocalStorage("userData", {
90
+ email: response.user.email
91
+ }, true);
92
+ }
93
+ }).catch(() => {
94
+ dispatchInitial(dispatch);
95
+ });
96
+ };
97
+ initialize();
98
+ }, [nextValSession]);
99
+ const login = async (email, password, remember) => {
100
+ await networkOperation({
101
+ endPoint: `auth/login`,
102
+ method: "POST",
103
+ data: {
104
+ email,
105
+ password,
106
+ domain_token
107
+ }
108
+ }).then((response) => {
109
+ const user = response.data;
110
+ if (remember) {
111
+ setLocalStorage("userData", {
112
+ email,
113
+ remember
114
+ });
115
+ } else {
116
+ setLocalStorage("userData", {
117
+ email: "",
118
+ remember
119
+ });
120
+ }
121
+ dispatch({
122
+ type: EnumTypes.Login,
123
+ payload: {
124
+ user
125
+ }
126
+ });
127
+ setNextValSession(new Date().getTime() + "");
128
+ });
129
+ };
130
+ const logout = async (isAuthenticated) => {
131
+ if (isAuthenticated) {
132
+ await networkOperation({
133
+ endPoint: `auth/logout`,
134
+ method: "POST"
135
+ });
136
+ }
137
+ dispatch({
138
+ type: EnumTypes.Logout
139
+ });
140
+ setNextValSession(new Date().getTime() + "");
141
+ };
142
+ const onNetserviceUnautorized = () => {
143
+ logout(false);
144
+ };
145
+ useEffect(() => {
146
+ events_add_listener(EmitEvents.EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED, onNetserviceUnautorized);
147
+ }, []);
148
+ return /* @__PURE__ */ jsx(AuthContext.Provider, {
149
+ value: {
150
+ ...state,
151
+ login,
152
+ logout
153
+ },
154
+ children
155
+ });
156
+ }
157
+ export {
158
+ AuthProvider as A,
159
+ AuthContext as a
160
+ };
@@ -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): import("react").JSX.Element;
5
+ export { AuthContext, AuthProvider };
@@ -0,0 +1,51 @@
1
+ import { DomainCountry, 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 interface User {
33
+ email: string;
34
+ id: number;
35
+ first_name: string;
36
+ last_name: string;
37
+ account_id: number;
38
+ domain_country: DomainCountry;
39
+ avatar_url?: Maybe<string>;
40
+ user_type_id?: number;
41
+ }
42
+ export declare type AuthUser = Maybe<User>;
43
+ export declare type AuthState = {
44
+ isAuthenticated: boolean;
45
+ isInitialized: boolean;
46
+ user: AuthUser;
47
+ };
48
+ export interface SessionContextType extends AuthState {
49
+ login: (email: string, password: string, remember: boolean) => object | undefined;
50
+ logout: (isAuthenticated: boolean) => Promise<void>;
51
+ }
@@ -0,0 +1 @@
1
+ export * from './AuthContext';
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+
@@ -1,2 +1,3 @@
1
1
  export * from './useMasterDetail';
2
+ export * from './useAuth';
2
3
  export * from './useModule';