@m4l/core 2.0.24 → 2.0.26
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/contexts/AuthContext/AuthContext.js +60 -88
- package/contexts/AuthContext/constants.d.ts +2 -0
- package/contexts/AuthContext/constants.js +8 -2
- package/contexts/AuthContext/helpers.d.ts +5 -0
- package/contexts/AuthContext/helpers.js +27 -0
- package/contexts/AuthContext/index.d.ts +1 -1
- package/contexts/AuthContext/types.d.ts +12 -0
- package/contexts/BaseContext/index.d.ts +1 -0
- package/contexts/BaseContext/store.js +26 -18
- package/contexts/BaseContext/types.d.ts +4 -0
- package/contexts/index.d.ts +1 -1
- package/index.js +30 -30
- package/package.json +1 -1
|
@@ -1,122 +1,94 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
import { E as
|
|
4
|
-
import { E as
|
|
5
|
-
import {
|
|
6
|
-
import { u as
|
|
7
|
-
import { u as
|
|
1
|
+
import { jsx as C } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as U, useReducer as _, useEffect as f, useCallback as l } from "react";
|
|
3
|
+
import { i as p, E as n } from "./constants.js";
|
|
4
|
+
import { E as w } from "../../types/index.js";
|
|
5
|
+
import { J as I } from "./helpers.js";
|
|
6
|
+
import { u as L } from "../../hooks/useHostTools/index.js";
|
|
7
|
+
import { u as P } from "../../hooks/useNetwork/index.js";
|
|
8
|
+
import { u as x } from "../../hooks/useEnvironment/index.js";
|
|
8
9
|
import { u as N } from "../../hooks/useLocalStorageWithListener/index.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
user: null
|
|
15
|
-
}, C = (e, t) => {
|
|
16
|
-
switch (t.type) {
|
|
17
|
-
case "INITIALIZE":
|
|
18
|
-
return {
|
|
19
|
-
isAuthenticated: t.payload.isAuthenticated,
|
|
20
|
-
isInitialized: !0,
|
|
21
|
-
user: t.payload.user
|
|
22
|
-
};
|
|
23
|
-
case "LOGIN":
|
|
24
|
-
return {
|
|
25
|
-
...e,
|
|
26
|
-
isAuthenticated: !0,
|
|
27
|
-
user: t.payload.user
|
|
28
|
-
};
|
|
29
|
-
case "LOGOUT":
|
|
30
|
-
return {
|
|
31
|
-
...e,
|
|
32
|
-
isAuthenticated: !1,
|
|
33
|
-
user: null
|
|
34
|
-
};
|
|
35
|
-
default:
|
|
36
|
-
return e;
|
|
37
|
-
}
|
|
38
|
-
}, O = A(null);
|
|
39
|
-
function P(e) {
|
|
40
|
-
e({
|
|
41
|
-
type: r.Initial,
|
|
42
|
-
payload: {
|
|
43
|
-
isAuthenticated: !1,
|
|
44
|
-
user: null
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
function j(e) {
|
|
49
|
-
const { children: t } = e, [m, i] = D(C, _), { events_add_listener: f } = S(), { networkOperation: o } = v(), { domain_token: p } = w(), [h, l] = N(
|
|
10
|
+
import { s as m } from "../../utils/setLocalStorage/index.js";
|
|
11
|
+
import { g as k } from "../../utils/getLocalStorage/index.js";
|
|
12
|
+
const z = U(null);
|
|
13
|
+
function b(g) {
|
|
14
|
+
const { children: h, isMicroFrontEnd: o = !1, loggedUser: c } = g, [E, s] = _(I, o ? { ...p, user: c, isAuthenticated: !0, isInitialized: !0 } : p), { events_add_listener: T } = L(), { networkOperation: t } = P(), { domain_token: d } = x(), [y, r] = N(
|
|
50
15
|
// Variable para saber si ha cambiado la session en otro navegador
|
|
51
16
|
"vSession",
|
|
52
17
|
(/* @__PURE__ */ new Date()).getTime() + ""
|
|
53
18
|
);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
19
|
+
f(() => {
|
|
20
|
+
const e = async () => {
|
|
21
|
+
t({
|
|
57
22
|
method: "GET",
|
|
58
23
|
endPoint: "auth/login",
|
|
59
24
|
parms: { user_data: !0 },
|
|
60
25
|
checkUnAuthorized: !1,
|
|
61
26
|
responseToCamelCase: !0
|
|
62
|
-
}).then((
|
|
63
|
-
|
|
64
|
-
type:
|
|
27
|
+
}).then((a) => {
|
|
28
|
+
s({
|
|
29
|
+
type: n.Initial,
|
|
65
30
|
payload: {
|
|
66
31
|
isAuthenticated: !0,
|
|
67
|
-
user:
|
|
32
|
+
user: a.user
|
|
68
33
|
}
|
|
69
|
-
}),
|
|
70
|
-
email:
|
|
34
|
+
}), k("userData", {
|
|
35
|
+
email: a.user.email,
|
|
71
36
|
remember: !0
|
|
72
|
-
})?.email !==
|
|
37
|
+
})?.email !== a.user.email && m("userData", { email: a.user.email }, !0);
|
|
73
38
|
}).catch(() => {
|
|
74
|
-
|
|
39
|
+
s({
|
|
40
|
+
type: n.Initial,
|
|
41
|
+
payload: {
|
|
42
|
+
isAuthenticated: !1,
|
|
43
|
+
user: null
|
|
44
|
+
}
|
|
45
|
+
});
|
|
75
46
|
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
47
|
+
};
|
|
48
|
+
o || e();
|
|
49
|
+
}, [t, y, o, c]);
|
|
50
|
+
const D = l(async (e, a, i) => {
|
|
51
|
+
await t({
|
|
80
52
|
endPoint: "auth/login",
|
|
81
53
|
method: "POST",
|
|
82
54
|
data: {
|
|
83
|
-
email:
|
|
84
|
-
password:
|
|
85
|
-
domain_token:
|
|
55
|
+
email: e,
|
|
56
|
+
password: a,
|
|
57
|
+
domain_token: d
|
|
86
58
|
},
|
|
87
59
|
responseToCamelCase: !0
|
|
88
|
-
}).then((
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
type:
|
|
60
|
+
}).then((v) => {
|
|
61
|
+
const A = v.data;
|
|
62
|
+
i ? m("userData", { email: e, remember: i }) : m("userData", { email: "", remember: i }), s({
|
|
63
|
+
type: n.Login,
|
|
92
64
|
payload: {
|
|
93
|
-
user:
|
|
65
|
+
user: A
|
|
94
66
|
}
|
|
95
|
-
}),
|
|
67
|
+
}), r((/* @__PURE__ */ new Date()).getTime() + "");
|
|
96
68
|
});
|
|
97
|
-
},
|
|
98
|
-
|
|
69
|
+
}, [t, r, d]), u = l(async (e) => {
|
|
70
|
+
e && await t({
|
|
99
71
|
endPoint: "auth/logout",
|
|
100
72
|
method: "POST"
|
|
101
|
-
}),
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
};
|
|
105
|
-
return
|
|
106
|
-
|
|
107
|
-
}, []), /* @__PURE__ */
|
|
108
|
-
|
|
73
|
+
}), s({ type: n.Logout }), r((/* @__PURE__ */ new Date()).getTime() + "");
|
|
74
|
+
}, [t, r]), S = l(() => {
|
|
75
|
+
u(!1);
|
|
76
|
+
}, [u]);
|
|
77
|
+
return f(function() {
|
|
78
|
+
o || T(w.EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED, S);
|
|
79
|
+
}, [o]), /* @__PURE__ */ C(
|
|
80
|
+
z.Provider,
|
|
109
81
|
{
|
|
110
82
|
value: {
|
|
111
|
-
...
|
|
112
|
-
login:
|
|
113
|
-
logout:
|
|
83
|
+
...E,
|
|
84
|
+
login: D,
|
|
85
|
+
logout: u
|
|
114
86
|
},
|
|
115
|
-
children:
|
|
87
|
+
children: h
|
|
116
88
|
}
|
|
117
89
|
);
|
|
118
90
|
}
|
|
119
91
|
export {
|
|
120
|
-
|
|
121
|
-
|
|
92
|
+
z as A,
|
|
93
|
+
b as a
|
|
122
94
|
};
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
var
|
|
1
|
+
var t = /* @__PURE__ */ ((i) => (i.Initial = "INITIALIZE", i.Login = "LOGIN", i.Logout = "LOGOUT", i))(t || {});
|
|
2
|
+
const a = {
|
|
3
|
+
isAuthenticated: !1,
|
|
4
|
+
isInitialized: !1,
|
|
5
|
+
user: null
|
|
6
|
+
};
|
|
2
7
|
export {
|
|
3
|
-
|
|
8
|
+
t as E,
|
|
9
|
+
a as i
|
|
4
10
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const r = (u, e) => {
|
|
2
|
+
switch (e.type) {
|
|
3
|
+
case "INITIALIZE":
|
|
4
|
+
return {
|
|
5
|
+
isAuthenticated: e.payload.isAuthenticated,
|
|
6
|
+
isInitialized: !0,
|
|
7
|
+
user: e.payload.user
|
|
8
|
+
};
|
|
9
|
+
case "LOGIN":
|
|
10
|
+
return {
|
|
11
|
+
...u,
|
|
12
|
+
isAuthenticated: !0,
|
|
13
|
+
user: e.payload.user
|
|
14
|
+
};
|
|
15
|
+
case "LOGOUT":
|
|
16
|
+
return {
|
|
17
|
+
...u,
|
|
18
|
+
isAuthenticated: !1,
|
|
19
|
+
user: null
|
|
20
|
+
};
|
|
21
|
+
default:
|
|
22
|
+
return u;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
r as J
|
|
27
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './AuthContext';
|
|
2
|
-
export type { UserAuth, AuthState } from './types';
|
|
2
|
+
export type { UserAuth, AuthState, AuthUserType } from './types';
|
|
@@ -21,6 +21,18 @@ export interface UserAuth {
|
|
|
21
21
|
}
|
|
22
22
|
export type AuthUserType = Maybe<UserAuth>;
|
|
23
23
|
export type AuthProviderProps = {
|
|
24
|
+
/**
|
|
25
|
+
* isMicroFrontEnd: indica si la aplicación es un microfrontend
|
|
26
|
+
* default: false
|
|
27
|
+
*/
|
|
28
|
+
isMicroFrontEnd?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* loggedUser: usuario de la aplicación, solo aplica para Microfrontends, porque se pasa la información del usuario directamente desde el host
|
|
31
|
+
*/
|
|
32
|
+
loggedUser?: AuthUserType;
|
|
33
|
+
/**
|
|
34
|
+
* children: hijos del componente
|
|
35
|
+
*/
|
|
24
36
|
children: ReactNode;
|
|
25
37
|
};
|
|
26
38
|
export type ActionMap<M extends {
|
|
@@ -1,42 +1,50 @@
|
|
|
1
1
|
import { createStore as l } from "zustand";
|
|
2
2
|
import { devtools as m } from "zustand/middleware";
|
|
3
|
-
import { immer as
|
|
4
|
-
import
|
|
5
|
-
function
|
|
6
|
-
const { enabled:
|
|
7
|
-
return
|
|
3
|
+
import { immer as u } from "zustand/middleware/immer";
|
|
4
|
+
import c from "lodash-es/merge";
|
|
5
|
+
function v(e, o) {
|
|
6
|
+
const { enabled: a = !1 } = o;
|
|
7
|
+
return a && process.env.NODE_ENV === "development" ? m(e, o) : e;
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
const
|
|
9
|
+
function V(e, o = !1) {
|
|
10
|
+
const a = {
|
|
11
11
|
...e
|
|
12
12
|
};
|
|
13
13
|
return l(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
...
|
|
14
|
+
v(
|
|
15
|
+
u((s) => ({
|
|
16
|
+
...a,
|
|
17
17
|
actions: {
|
|
18
18
|
/**
|
|
19
|
-
* Setea un valor parcial en el estado y lo combina con el estado actual
|
|
19
|
+
* Setea un valor parcial en el estado y lo combina con el estado actual,
|
|
20
20
|
*/
|
|
21
|
-
setPartialValue: (
|
|
22
|
-
s((
|
|
23
|
-
|
|
21
|
+
setPartialValue: (r) => {
|
|
22
|
+
s((t) => {
|
|
23
|
+
Object.assign(t.value, r);
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
/**
|
|
27
|
+
* Mergea un valor parcial en el estado y lo combina con el estado actual, sin perderse la anidación
|
|
28
|
+
*/
|
|
29
|
+
mergeValue: (r) => {
|
|
30
|
+
s((t) => {
|
|
31
|
+
c(t.value, r);
|
|
24
32
|
});
|
|
25
33
|
},
|
|
26
34
|
/**
|
|
27
35
|
* Setea un valor en el estado
|
|
28
36
|
*/
|
|
29
|
-
setKeyValue: (
|
|
37
|
+
setKeyValue: (r, t) => {
|
|
30
38
|
s((n) => {
|
|
31
|
-
n.value[
|
|
39
|
+
n.value[r] = t;
|
|
32
40
|
});
|
|
33
41
|
}
|
|
34
42
|
}
|
|
35
43
|
})),
|
|
36
|
-
{ name: `BaseProviderStore: ${e.storeId}`, enabled:
|
|
44
|
+
{ name: `BaseProviderStore: ${e.storeId}`, enabled: o }
|
|
37
45
|
)
|
|
38
46
|
);
|
|
39
47
|
}
|
|
40
48
|
export {
|
|
41
|
-
|
|
49
|
+
V as c
|
|
42
50
|
};
|
|
@@ -19,6 +19,10 @@ export interface BaseProviderStoreStateWithActions<T extends Record<KeyOFHash, a
|
|
|
19
19
|
* Modifica parcialmente el custom data.
|
|
20
20
|
*/
|
|
21
21
|
setPartialValue: (customData: Partial<T>) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Modifica parcialmente el custom data.
|
|
24
|
+
*/
|
|
25
|
+
mergeValue: (customData: Partial<T>) => void;
|
|
22
26
|
/**
|
|
23
27
|
* Modifica una propidadparcialmente el custom data.
|
|
24
28
|
*/
|
package/contexts/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './BaseContext';
|
|
2
2
|
export { EnvironmentContext, EnvironmentProvider } from './EnvironmentContext';
|
|
3
3
|
export { HostToolsContext, HostToolsProvider } from './HostToolsContext';
|
|
4
4
|
export { NetworkContext, NetworkProvider } from './NetworkContext';
|
package/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { C as r, E as t } from "./types/index.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { D, a as S } from "./contexts/
|
|
8
|
-
import { M as y, a as F } from "./contexts/
|
|
9
|
-
import { M as k, a as B } from "./contexts/
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
2
|
+
import { E as s, a as u } from "./contexts/EnvironmentContext/index.js";
|
|
3
|
+
import { H as i, a as m } from "./contexts/HostToolsContext/index.js";
|
|
4
|
+
import { N as p, a as f } from "./contexts/NetworkContext/index.js";
|
|
5
|
+
import { F as d, a as v } from "./contexts/FlagsContext/index.js";
|
|
6
|
+
import { D as P, a as C } from "./contexts/DomainContext/index.js";
|
|
7
|
+
import { M as D, a as S } from "./contexts/ModuleDictionaryContext/index.js";
|
|
8
|
+
import { M as y, a as F } from "./contexts/ModulePrivilegesContext/index.js";
|
|
9
|
+
import { M as k, a as B } from "./contexts/ModuleSkeletonContext/index.js";
|
|
10
|
+
import { D as L, a as A } from "./contexts/DomainCountryContext/index.js";
|
|
11
|
+
import { B as N, a as w } from "./contexts/BaseContext/BaseContext.js";
|
|
12
12
|
import { A as W, a as O } from "./contexts/AuthContext/AuthContext.js";
|
|
13
13
|
import { u as j } from "./hooks/useEnvironment/index.js";
|
|
14
14
|
import { a as z, u as G } from "./hooks/useFlagsStore/index.js";
|
|
@@ -35,28 +35,28 @@ import { a as Lo } from "./utils/axiosOperation/index.js";
|
|
|
35
35
|
export {
|
|
36
36
|
W as AuthContext,
|
|
37
37
|
O as AuthProvider,
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
N as BaseContext,
|
|
39
|
+
w as BaseProvider,
|
|
40
40
|
r as CommonFlags,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
P as DomainContext,
|
|
42
|
+
L as DomainCountryContext,
|
|
43
|
+
A as DomainCountryProvider,
|
|
44
|
+
C as DomainProvider,
|
|
45
45
|
t as EmitEvents,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
46
|
+
s as EnvironmentContext,
|
|
47
|
+
u as EnvironmentProvider,
|
|
48
|
+
d as FlagsContext,
|
|
49
|
+
v as FlagsProvider,
|
|
50
|
+
i as HostToolsContext,
|
|
51
|
+
m as HostToolsProvider,
|
|
52
|
+
D as ModuleDictionaryContext,
|
|
53
|
+
S as ModuleDictionaryProvider,
|
|
54
|
+
y as ModulePrivilegesContext,
|
|
55
|
+
F as ModulePrivilegesProvider,
|
|
56
|
+
k as ModuleSkeletonContext,
|
|
57
|
+
B as ModuleSkeletonProvider,
|
|
58
|
+
p as NetworkContext,
|
|
59
|
+
f as NetworkProvider,
|
|
60
60
|
Lo as axiosOperation,
|
|
61
61
|
yo as evaluateWithContext,
|
|
62
62
|
Eo as getLocalStorage,
|