@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.
@@ -1,122 +1,94 @@
1
- import { jsx as I } from "react/jsx-runtime";
2
- import { createContext as A, useReducer as D, useEffect as d } from "react";
3
- import { E as r } from "./constants.js";
4
- import { E as L } from "../../types/index.js";
5
- import { u as S } from "../../hooks/useHostTools/index.js";
6
- import { u as v } from "../../hooks/useNetwork/index.js";
7
- import { u as w } from "../../hooks/useEnvironment/index.js";
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 { g as U } from "../../utils/getLocalStorage/index.js";
10
- import { s as u } from "../../utils/setLocalStorage/index.js";
11
- const _ = {
12
- isAuthenticated: !1,
13
- isInitialized: !1,
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
- d(() => {
55
- (async () => {
56
- o({
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((s) => {
63
- i({
64
- type: r.Initial,
27
+ }).then((a) => {
28
+ s({
29
+ type: n.Initial,
65
30
  payload: {
66
31
  isAuthenticated: !0,
67
- user: s.user
32
+ user: a.user
68
33
  }
69
- }), U("userData", {
70
- email: s.user.email,
34
+ }), k("userData", {
35
+ email: a.user.email,
71
36
  remember: !0
72
- })?.email !== s.user.email && u("userData", { email: s.user.email }, !0);
37
+ })?.email !== a.user.email && m("userData", { email: a.user.email }, !0);
73
38
  }).catch(() => {
74
- P(i);
39
+ s({
40
+ type: n.Initial,
41
+ payload: {
42
+ isAuthenticated: !1,
43
+ user: null
44
+ }
45
+ });
75
46
  });
76
- })();
77
- }, [o, h]);
78
- const g = async (a, s, n) => {
79
- await o({
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: a,
84
- password: s,
85
- domain_token: p
55
+ email: e,
56
+ password: a,
57
+ domain_token: d
86
58
  },
87
59
  responseToCamelCase: !0
88
- }).then((y) => {
89
- const E = y.data;
90
- n ? u("userData", { email: a, remember: n }) : u("userData", { email: "", remember: n }), i({
91
- type: r.Login,
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: E
65
+ user: A
94
66
  }
95
- }), l((/* @__PURE__ */ new Date()).getTime() + "");
67
+ }), r((/* @__PURE__ */ new Date()).getTime() + "");
96
68
  });
97
- }, c = async (a) => {
98
- a && await o({
69
+ }, [t, r, d]), u = l(async (e) => {
70
+ e && await t({
99
71
  endPoint: "auth/logout",
100
72
  method: "POST"
101
- }), i({ type: r.Logout }), l((/* @__PURE__ */ new Date()).getTime() + "");
102
- }, T = () => {
103
- c(!1);
104
- };
105
- return d(function() {
106
- f(L.EMMIT_EVENT_NET_SERVICE_UNAUTHORIZED, T);
107
- }, []), /* @__PURE__ */ I(
108
- O.Provider,
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
- ...m,
112
- login: g,
113
- logout: c
83
+ ...E,
84
+ login: D,
85
+ logout: u
114
86
  },
115
- children: t
87
+ children: h
116
88
  }
117
89
  );
118
90
  }
119
91
  export {
120
- O as A,
121
- j as a
92
+ z as A,
93
+ b as a
122
94
  };
@@ -1,5 +1,7 @@
1
+ import { AuthState } from './types';
1
2
  export declare enum EnumTypes {
2
3
  Initial = "INITIALIZE",
3
4
  Login = "LOGIN",
4
5
  Logout = "LOGOUT"
5
6
  }
7
+ export declare const initialState: AuthState;
@@ -1,4 +1,10 @@
1
- var L = /* @__PURE__ */ ((I) => (I.Initial = "INITIALIZE", I.Login = "LOGIN", I.Logout = "LOGOUT", I))(L || {});
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
- L as E
8
+ t as E,
9
+ a as i
4
10
  };
@@ -0,0 +1,5 @@
1
+ import { AuthState, SessionActions } from './types';
2
+ /**
3
+ * Reducer para el contexto de autenticación
4
+ */
5
+ export declare const JWTReducer: (state: AuthState, action: SessionActions) => AuthState;
@@ -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 +1,2 @@
1
1
  export * from './BaseContext';
2
+ export type { BaseProviderStoreStateWithActions } from './types';
@@ -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 c } from "zustand/middleware/immer";
4
- import u from "lodash-es/merge";
5
- function f(e, r) {
6
- const { enabled: t = !1 } = r;
7
- return t && process.env.NODE_ENV === "development" ? m(e, r) : e;
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 P(e, r = !1) {
10
- const t = {
9
+ function V(e, o = !1) {
10
+ const a = {
11
11
  ...e
12
12
  };
13
13
  return l(
14
- f(
15
- c((s) => ({
16
- ...t,
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: (o) => {
22
- s((a) => {
23
- u(a.value, o);
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: (o, a) => {
37
+ setKeyValue: (r, t) => {
30
38
  s((n) => {
31
- n.value[o] = a;
39
+ n.value[r] = t;
32
40
  });
33
41
  }
34
42
  }
35
43
  })),
36
- { name: `BaseProviderStore: ${e.storeId}`, enabled: r }
44
+ { name: `BaseProviderStore: ${e.storeId}`, enabled: o }
37
45
  )
38
46
  );
39
47
  }
40
48
  export {
41
- P as c
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
  */
@@ -1,4 +1,4 @@
1
- export { BaseContext, BaseProvider } from './BaseContext';
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 { B as s, a as u } from "./contexts/BaseContext/BaseContext.js";
3
- import { E as i, a as m } from "./contexts/EnvironmentContext/index.js";
4
- import { H as p, a as f } from "./contexts/HostToolsContext/index.js";
5
- import { N as d, a as v } from "./contexts/NetworkContext/index.js";
6
- import { F as P, a as C } from "./contexts/FlagsContext/index.js";
7
- import { D, a as S } from "./contexts/DomainContext/index.js";
8
- import { M as y, a as F } from "./contexts/ModuleDictionaryContext/index.js";
9
- import { M as k, a as B } from "./contexts/ModulePrivilegesContext/index.js";
10
- import { M as L, a as A } from "./contexts/ModuleSkeletonContext/index.js";
11
- import { D as N, a as w } from "./contexts/DomainCountryContext/index.js";
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
- s as BaseContext,
39
- u as BaseProvider,
38
+ N as BaseContext,
39
+ w as BaseProvider,
40
40
  r as CommonFlags,
41
- D as DomainContext,
42
- N as DomainCountryContext,
43
- w as DomainCountryProvider,
44
- S as DomainProvider,
41
+ P as DomainContext,
42
+ L as DomainCountryContext,
43
+ A as DomainCountryProvider,
44
+ C as DomainProvider,
45
45
  t as EmitEvents,
46
- i as EnvironmentContext,
47
- m as EnvironmentProvider,
48
- P as FlagsContext,
49
- C as FlagsProvider,
50
- p as HostToolsContext,
51
- f as HostToolsProvider,
52
- y as ModuleDictionaryContext,
53
- F as ModuleDictionaryProvider,
54
- k as ModulePrivilegesContext,
55
- B as ModulePrivilegesProvider,
56
- L as ModuleSkeletonContext,
57
- A as ModuleSkeletonProvider,
58
- d as NetworkContext,
59
- v as NetworkProvider,
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m4l/core",
3
- "version": "2.0.24",
3
+ "version": "2.0.26",
4
4
  "license": "UNLICENSED",
5
5
  "author": "M4L Team",
6
6
  "publishConfig": {