@m4l/core 0.0.33 → 0.0.36
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.
- package/dist/contexts/EnvironmentContext/index.js +8 -3
- package/dist/contexts/ModuleDictionaryContext/index.js +2 -1
- package/dist/contexts/ModuleDictionaryContext/types.d.ts +1 -1
- package/dist/contexts/ModulePrivilegesContext/index.d.ts +5 -0
- package/dist/contexts/ModulePrivilegesContext/index.js +63 -0
- package/dist/contexts/ModulePrivilegesContext/types.d.ts +9 -0
- package/dist/contexts/index.d.ts +1 -0
- package/dist/hooks/index.d.ts +2 -1
- package/dist/hooks/useModulePrivileges/index.d.ts +1 -0
- package/dist/hooks/useModulePrivileges/index.js +9 -0
- package/dist/index.js +4 -2
- package/dist/types/index.d.ts +9 -3
- package/package.json +1 -1
|
@@ -8,9 +8,14 @@ const initialValue = {
|
|
|
8
8
|
host_api_remote: "",
|
|
9
9
|
host_static_assets: "",
|
|
10
10
|
environment_assets: "",
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
dfnsFormat: {
|
|
12
|
+
date_format: "yyyy-MM-dd",
|
|
13
|
+
date_mask: "____-__-__",
|
|
14
|
+
time_format: "HH:mm:ss",
|
|
15
|
+
time_mask: "__:__:__",
|
|
16
|
+
datetime_format: "yyyy-MM-dd HH:mm:ss",
|
|
17
|
+
datetime_mask: "____-__-__ __:__:__"
|
|
18
|
+
}
|
|
14
19
|
};
|
|
15
20
|
const EnvironmentContext = createContext(initialValue);
|
|
16
21
|
function EnvironmentProvider(props) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createContext, useState, useLayoutEffect, useCallback } from "react";
|
|
2
|
+
import { u as useEnvironment } from "../../hooks/useEnvironment/index.js";
|
|
2
3
|
import { u as useFlags } from "../../hooks/useFlags/index.js";
|
|
3
4
|
import { u as useHostTools } from "../../hooks/useHostTools/index.js";
|
|
5
|
+
import "../ModulePrivilegesContext/index.js";
|
|
4
6
|
import { u as useNetwork } from "../../hooks/useNetwork/index.js";
|
|
5
|
-
import { u as useEnvironment } from "../../hooks/useEnvironment/index.js";
|
|
6
7
|
import { jsx } from "react/jsx-runtime";
|
|
7
8
|
const initialState = {
|
|
8
9
|
getLabel: () => "..",
|
|
@@ -3,7 +3,7 @@ import type { GetLabelType, ModuleDictionary } from '../../types/dictionary';
|
|
|
3
3
|
export interface ModuleDictionaryProviderProps {
|
|
4
4
|
currentLang?: string;
|
|
5
5
|
isAuth?: boolean;
|
|
6
|
-
moduleId:
|
|
6
|
+
moduleId: string;
|
|
7
7
|
moduleName?: string;
|
|
8
8
|
componentsDictionary: string[];
|
|
9
9
|
children: ReactNode;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ModulePrivilegesContextProps, ModulePrivilegesProviderProps } from './types';
|
|
3
|
+
declare const ModulePrivilegesContext: import("react").Context<ModulePrivilegesContextProps>;
|
|
4
|
+
declare function ModulePrivilegesProvider(props: ModulePrivilegesProviderProps): JSX.Element;
|
|
5
|
+
export { ModulePrivilegesProvider, ModulePrivilegesContext };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { createContext, useState, useLayoutEffect, useCallback } from "react";
|
|
2
|
+
import "../EnvironmentContext/index.js";
|
|
3
|
+
import { u as useFlags } from "../../hooks/useFlags/index.js";
|
|
4
|
+
import { u as useHostTools } from "../../hooks/useHostTools/index.js";
|
|
5
|
+
import "../ModuleDictionaryContext/index.js";
|
|
6
|
+
import { u as useNetwork } from "../../hooks/useNetwork/index.js";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
const initialState = {
|
|
9
|
+
privileges: {},
|
|
10
|
+
hasPrivilege: () => false
|
|
11
|
+
};
|
|
12
|
+
const ModulePrivilegesContext = createContext(initialState);
|
|
13
|
+
function ModulePrivilegesProvider(props) {
|
|
14
|
+
const {
|
|
15
|
+
children,
|
|
16
|
+
queryPrivileges
|
|
17
|
+
} = props;
|
|
18
|
+
const {
|
|
19
|
+
addFlag
|
|
20
|
+
} = useFlags();
|
|
21
|
+
const [privileges, setPrivileges] = useState({});
|
|
22
|
+
const {
|
|
23
|
+
startProgress,
|
|
24
|
+
stopProgress
|
|
25
|
+
} = useHostTools();
|
|
26
|
+
const {
|
|
27
|
+
networkOperation
|
|
28
|
+
} = useNetwork();
|
|
29
|
+
useLayoutEffect(() => {
|
|
30
|
+
let mounted = true;
|
|
31
|
+
startProgress();
|
|
32
|
+
networkOperation({
|
|
33
|
+
method: "GET",
|
|
34
|
+
endPoint: `auth/validate`,
|
|
35
|
+
parms: {
|
|
36
|
+
privileges: queryPrivileges
|
|
37
|
+
}
|
|
38
|
+
}).then((response) => {
|
|
39
|
+
if (mounted) {
|
|
40
|
+
setPrivileges({
|
|
41
|
+
...response.data
|
|
42
|
+
});
|
|
43
|
+
addFlag("privileges_loaded");
|
|
44
|
+
}
|
|
45
|
+
}).finally(() => {
|
|
46
|
+
stopProgress();
|
|
47
|
+
});
|
|
48
|
+
return function cleanUp() {
|
|
49
|
+
mounted = false;
|
|
50
|
+
};
|
|
51
|
+
}, []);
|
|
52
|
+
const hasPrivilege = useCallback((key) => {
|
|
53
|
+
return key in privileges;
|
|
54
|
+
}, [privileges]);
|
|
55
|
+
return /* @__PURE__ */ jsx(ModulePrivilegesContext.Provider, {
|
|
56
|
+
value: {
|
|
57
|
+
hasPrivilege,
|
|
58
|
+
privileges
|
|
59
|
+
},
|
|
60
|
+
children
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
export { ModulePrivilegesContext as M, ModulePrivilegesProvider as a };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export interface ModulePrivilegesProviderProps {
|
|
3
|
+
queryPrivileges: string[];
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
}
|
|
6
|
+
export interface ModulePrivilegesContextProps {
|
|
7
|
+
privileges: Record<string, boolean>;
|
|
8
|
+
hasPrivilege: (id: string) => boolean;
|
|
9
|
+
}
|
package/dist/contexts/index.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ export { HostToolsContext, HostToolsProvider } from './HostToolsContext';
|
|
|
3
3
|
export { NetworkContext, NetworkProvider } from './NetworkContext';
|
|
4
4
|
export { FlagsContext, FlagsProvider } from './FlagsContext';
|
|
5
5
|
export { ModuleDictionaryContext, ModuleDictionaryProvider } from './ModuleDictionaryContext';
|
|
6
|
+
export { ModulePrivilegesContext, ModulePrivilegesProvider } from './ModulePrivilegesContext';
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
export { useEnvironment } from './useEnvironment';
|
|
1
2
|
export { useFlags, useFlagsPresent } from './useFlags';
|
|
2
3
|
export { useHostTools } from './useHostTools';
|
|
3
4
|
export { useLocalStorage } from './useLocalStorage';
|
|
4
5
|
export { useModuleDictionary } from './useModuleDictionary';
|
|
6
|
+
export { useModulePrivileges } from './useModulePrivileges';
|
|
5
7
|
export { useNetwork } from './useNetwork';
|
|
6
|
-
export { useEnvironment } from './useEnvironment';
|
|
7
8
|
export { usePaginate } from './usePaginate';
|
|
8
9
|
export type { PagerState } from './usePaginate/types';
|
|
9
10
|
export { initialPagerState } from './usePaginate/types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useModulePrivileges: () => import("../../contexts/ModulePrivilegesContext/types").ModulePrivilegesContextProps;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { M as ModulePrivilegesContext } from "../../contexts/ModulePrivilegesContext/index.js";
|
|
3
|
+
const useModulePrivileges = () => {
|
|
4
|
+
const context = useContext(ModulePrivilegesContext);
|
|
5
|
+
if (!context)
|
|
6
|
+
throw new Error("useModulePrivileges context must be use inside ModulePrivilegesContext");
|
|
7
|
+
return context;
|
|
8
|
+
};
|
|
9
|
+
export { useModulePrivileges as u };
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import "react";
|
|
2
|
+
export { E as EnvironmentContext, a as EnvironmentProvider } from "./contexts/EnvironmentContext/index.js";
|
|
2
3
|
export { F as FlagsContext, a as FlagsProvider } from "./contexts/FlagsContext/index.js";
|
|
3
4
|
export { H as HostToolsContext, a as HostToolsProvider } from "./contexts/HostToolsContext/index.js";
|
|
4
5
|
export { M as ModuleDictionaryContext, a as ModuleDictionaryProvider } from "./contexts/ModuleDictionaryContext/index.js";
|
|
6
|
+
export { M as ModulePrivilegesContext, a as ModulePrivilegesProvider } from "./contexts/ModulePrivilegesContext/index.js";
|
|
5
7
|
export { N as NetworkContext, a as NetworkProvider } from "./contexts/NetworkContext/index.js";
|
|
6
|
-
export {
|
|
8
|
+
export { u as useEnvironment } from "./hooks/useEnvironment/index.js";
|
|
7
9
|
export { u as useFlags, a as useFlagsPresent } from "./hooks/useFlags/index.js";
|
|
8
10
|
export { u as useHostTools } from "./hooks/useHostTools/index.js";
|
|
9
11
|
export { u as useLocalStorage } from "./hooks/useLocalStorage/index.js";
|
|
10
12
|
export { u as useModuleDictionary } from "./hooks/useModuleDictionary/index.js";
|
|
13
|
+
export { u as useModulePrivileges } from "./hooks/useModulePrivileges/index.js";
|
|
11
14
|
export { u as useNetwork } from "./hooks/useNetwork/index.js";
|
|
12
|
-
export { u as useEnvironment } from "./hooks/useEnvironment/index.js";
|
|
13
15
|
export { i as initialPagerState, u as usePaginate } from "./hooks/usePaginate/index.js";
|
|
14
16
|
export { E as EmitEvents } from "./types/index.js";
|
|
15
17
|
export { a as getLocalStorage, g as getPropertyByString, s as setLocalStorage, v as voidFunction } from "./utils/index.js";
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import type { Id, ToastContent, ToastOptions } from 'react-toastify';
|
|
2
2
|
import type { BrowserHistory } from 'history';
|
|
3
3
|
export declare type Maybe<T> = T | undefined | null;
|
|
4
|
+
export declare interface DfnFormat {
|
|
5
|
+
date_format: string;
|
|
6
|
+
date_mask: string;
|
|
7
|
+
time_format: string;
|
|
8
|
+
time_mask: string;
|
|
9
|
+
datetime_format: string;
|
|
10
|
+
datetime_mask: string;
|
|
11
|
+
}
|
|
4
12
|
export declare interface EnvironmentType {
|
|
5
13
|
isLocalhost: boolean;
|
|
6
14
|
host: string;
|
|
@@ -9,9 +17,7 @@ export declare interface EnvironmentType {
|
|
|
9
17
|
host_api_local: string;
|
|
10
18
|
host_static_assets: string;
|
|
11
19
|
environment_assets: string;
|
|
12
|
-
|
|
13
|
-
date_format: string;
|
|
14
|
-
time_format: string;
|
|
20
|
+
dfnsFormat: DfnFormat;
|
|
15
21
|
}
|
|
16
22
|
export declare type NetworkProps = {
|
|
17
23
|
method: any;
|