@chimera-pe/react-saas 3.0.1 → 3.0.3

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,19 +1,19 @@
1
- import { jsxs as g, jsx as a } from "react/jsx-runtime";
2
- import { useEffect as m, useContext as k } from "react";
1
+ import { jsxs as m, jsx as a } from "react/jsx-runtime";
3
2
  import o from "prop-types";
4
- import { AuthProvider as q, AuthContext as x } from "react-oauth2-code-pkce";
5
- import { create as w } from "zustand";
6
- import { useTranslate as f, I18n as I } from "react-polyglot";
7
- import { union as U } from "lodash";
8
- import C from "navigator-languages";
9
- const O = "https://saas.chimera.com.pe/backend/v3", R = "https://saas.chimera.com.pe/oauth/v3", A = "http://localhost:7000", T = "http://localhost:7777", u = {
3
+ import { useEffect as g, useContext as x } from "react";
4
+ import { AuthProvider as w, AuthContext as A } from "react-oauth2-code-pkce";
5
+ import { create as f } from "zustand";
6
+ import { useTranslate as h, I18n as C } from "react-polyglot";
7
+ import { union as I } from "lodash";
8
+ import U from "navigator-languages";
9
+ const O = "https://saas.chimera.com.pe/backend/v3", R = "https://saas.chimera.com.pe/oauth/v3", E = "http://localhost:7000", T = "http://localhost:7777", u = {
10
10
  primary: "#1C6CCC",
11
11
  secondary: "#17A7FF",
12
12
  info: "#2196f3",
13
13
  success: "#4caf50",
14
14
  error: "#f44336",
15
15
  warning: "#ff9800"
16
- }, d = w((e) => ({
16
+ }, d = f((e) => ({
17
17
  inicializado: !1,
18
18
  estado: {
19
19
  inicializando: !0,
@@ -27,7 +27,6 @@ const O = "https://saas.chimera.com.pe/backend/v3", R = "https://saas.chimera.co
27
27
  logo: null,
28
28
  color: u
29
29
  },
30
- idioma: "en",
31
30
  inicializar: async (i, r) => {
32
31
  e({
33
32
  estado: {
@@ -75,15 +74,10 @@ const O = "https://saas.chimera.com.pe/backend/v3", R = "https://saas.chimera.co
75
74
  }
76
75
  });
77
76
  }
78
- },
79
- cambiarIdioma: (i) => {
80
- e({
81
- idioma: i
82
- });
83
77
  }
84
- })), E = "data:image/svg+xml,%3csvg%20width='24'%20height='24'%20stroke='%23000'%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%3e%3cstyle%3e.spinner_V8m1{transform-origin:center;animation:spinner_zKoa%202s%20linear%20infinite}.spinner_V8m1%20circle{stroke-linecap:round;animation:spinner_YpZS%201.5s%20ease-in-out%20infinite}@keyframes%20spinner_zKoa{100%25{transform:rotate(360deg)}}@keyframes%20spinner_YpZS{0%25{stroke-dasharray:0%20150;stroke-dashoffset:0}47.5%25{stroke-dasharray:42%20150;stroke-dashoffset:-16}95%25,100%25{stroke-dasharray:42%20150;stroke-dashoffset:-59}}%3c/style%3e%3cg%20class='spinner_V8m1'%3e%3ccircle%20cx='12'%20cy='12'%20r='9.5'%20fill='none'%20stroke-width='3'%3e%3c/circle%3e%3c/g%3e%3c/svg%3e", L = () => {
85
- const e = f();
86
- return /* @__PURE__ */ g(
78
+ })), L = "data:image/svg+xml,%3csvg%20width='24'%20height='24'%20stroke='%23000'%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%3e%3cstyle%3e.spinner_V8m1{transform-origin:center;animation:spinner_zKoa%202s%20linear%20infinite}.spinner_V8m1%20circle{stroke-linecap:round;animation:spinner_YpZS%201.5s%20ease-in-out%20infinite}@keyframes%20spinner_zKoa{100%25{transform:rotate(360deg)}}@keyframes%20spinner_YpZS{0%25{stroke-dasharray:0%20150;stroke-dashoffset:0}47.5%25{stroke-dasharray:42%20150;stroke-dashoffset:-16}95%25,100%25{stroke-dasharray:42%20150;stroke-dashoffset:-59}}%3c/style%3e%3cg%20class='spinner_V8m1'%3e%3ccircle%20cx='12'%20cy='12'%20r='9.5'%20fill='none'%20stroke-width='3'%3e%3c/circle%3e%3c/g%3e%3c/svg%3e", S = () => {
79
+ const e = h();
80
+ return /* @__PURE__ */ m(
87
81
  "div",
88
82
  {
89
83
  style: {
@@ -94,7 +88,7 @@ const O = "https://saas.chimera.com.pe/backend/v3", R = "https://saas.chimera.co
94
88
  /* @__PURE__ */ a(
95
89
  "img",
96
90
  {
97
- src: E,
91
+ src: L,
98
92
  alt: e("saas.cargando"),
99
93
  style: {
100
94
  filter: "invert(99%) sepia(2%) saturate(740%) hue-rotate(250deg) brightness(93%) contrast(93%)"
@@ -105,9 +99,9 @@ const O = "https://saas.chimera.com.pe/backend/v3", R = "https://saas.chimera.co
105
99
  ]
106
100
  }
107
101
  );
108
- }, h = ({ titulo: e, texto: i }) => {
109
- const r = f();
110
- return /* @__PURE__ */ g(
102
+ }, b = ({ titulo: e, texto: i }) => {
103
+ const r = h();
104
+ return /* @__PURE__ */ m(
111
105
  "div",
112
106
  {
113
107
  style: {
@@ -134,16 +128,16 @@ const O = "https://saas.chimera.com.pe/backend/v3", R = "https://saas.chimera.co
134
128
  }
135
129
  );
136
130
  };
137
- h.propTypes = {
131
+ b.propTypes = {
138
132
  titulo: o.string.isRequired,
139
133
  texto: o.string
140
134
  };
141
- const b = ({ devAuthUrl: e, redirectUri: i, children: r }) => {
135
+ const v = ({ devAuthUrl: e, redirectUri: i, children: r }) => {
142
136
  const t = d((n) => n.instancia);
143
137
  if (t.requiereLogin) {
144
138
  const n = e || R;
145
139
  return /* @__PURE__ */ a(
146
- q,
140
+ w,
147
141
  {
148
142
  authConfig: {
149
143
  clientId: t.identificador,
@@ -159,14 +153,14 @@ const b = ({ devAuthUrl: e, redirectUri: i, children: r }) => {
159
153
  }
160
154
  return r;
161
155
  };
162
- b.propTypes = {
156
+ v.propTypes = {
163
157
  devAuthUrl: o.string,
164
158
  redirectUri: o.string.isRequired,
165
159
  children: o.element.isRequired
166
160
  };
167
- const v = ({ aplicacion: e, devBackendUrl: i }) => {
161
+ const y = ({ aplicacion: e, devBackendUrl: i }) => {
168
162
  const r = d((n) => n.estado), t = d((n) => n.inicializar);
169
- return m(() => {
163
+ return g(() => {
170
164
  t(i, e);
171
165
  }, [t, i, e]), /* @__PURE__ */ a(
172
166
  "div",
@@ -180,35 +174,35 @@ const v = ({ aplicacion: e, devBackendUrl: i }) => {
180
174
  backgroundColor: "#141316",
181
175
  color: "#e6e1e6"
182
176
  },
183
- children: r.inicializando ? /* @__PURE__ */ a(L, {}) : r.error && /* @__PURE__ */ a(h, { titulo: "saas.error.titulo", texto: r.error })
177
+ children: r.inicializando ? /* @__PURE__ */ a(S, {}) : r.error && /* @__PURE__ */ a(b, { titulo: "saas.error.titulo", texto: r.error })
184
178
  }
185
179
  );
186
180
  };
187
- v.propTypes = {
181
+ y.propTypes = {
188
182
  aplicacion: o.string.isRequired,
189
183
  devBackendUrl: o.string
190
184
  };
191
- const y = ({
185
+ const z = ({
192
186
  aplicacion: e,
193
187
  devBackendUrl: i,
194
188
  devAuthUrl: r,
195
189
  redirectUri: t,
196
190
  children: n
197
191
  }) => d((l) => l.inicializado) ? /* @__PURE__ */ a(
198
- b,
192
+ v,
199
193
  {
200
194
  devAuthUrl: r,
201
195
  redirectUri: t,
202
196
  children: n
203
197
  }
204
198
  ) : /* @__PURE__ */ a(
205
- v,
199
+ y,
206
200
  {
207
201
  aplicacion: e,
208
202
  devBackendUrl: i
209
203
  }
210
204
  );
211
- y.propTypes = {
205
+ z.propTypes = {
212
206
  aplicacion: o.string.isRequired,
213
207
  devBackendUrl: o.string,
214
208
  devAuthUrl: o.string,
@@ -216,11 +210,13 @@ y.propTypes = {
216
210
  children: o.element.isRequired
217
211
  };
218
212
  const _ = {
213
+ nombre: "English",
219
214
  cargando: "Loading...",
220
215
  error: {
221
216
  titulo: "Could not initialize application"
222
217
  }
223
218
  }, B = {
219
+ nombre: "Castellano",
224
220
  cargando: "Cargando...",
225
221
  error: {
226
222
  titulo: "Error iniciando aplicación"
@@ -228,23 +224,31 @@ const _ = {
228
224
  }, p = {
229
225
  en: _,
230
226
  es: B
231
- }, z = ({ mensajes: e, children: i }) => {
232
- const r = d((t) => t.idioma);
233
- return /* @__PURE__ */ a(I, { locale: r, messages: e[r], children: i });
227
+ }, j = f((e) => ({
228
+ idiomasDisponibles: ["en", "es"],
229
+ idiomaActual: "en",
230
+ cambiarIdioma: (i) => {
231
+ e({
232
+ idiomaActual: i
233
+ });
234
+ }
235
+ })), k = ({ mensajes: e, children: i }) => {
236
+ const r = j((t) => t.idiomaActual);
237
+ return /* @__PURE__ */ a(C, { locale: r, messages: e[r], children: i });
234
238
  };
235
- z.propTypes = {
239
+ k.propTypes = {
236
240
  mensajes: o.object,
237
241
  children: o.element.isRequired
238
242
  };
239
- const S = () => {
240
- const e = C();
243
+ const P = () => {
244
+ const e = U();
241
245
  if (!(e != null && e.length))
242
246
  return;
243
247
  const i = e[0];
244
248
  return i.indexOf("-") ? i.substring(0, i.indexOf("-")) : i;
245
- }, j = ({ mensajes: e, idiomaDefecto: i, children: r }) => {
246
- const t = d((s) => s.cambiarIdioma), n = S(), c = U(Object.keys(e), Object.keys(p));
247
- m(() => {
249
+ }, q = ({ mensajes: e, idiomaDefecto: i, children: r }) => {
250
+ const t = j((s) => s.cambiarIdioma), n = P(), c = I(Object.keys(e), Object.keys(p));
251
+ g(() => {
248
252
  let s = c[0];
249
253
  n && Object.hasOwn(e, n) ? s = n : i && Object.hasOwn(e, i) && (s = i), t(s);
250
254
  }, [c, e, i, n, t]);
@@ -254,16 +258,16 @@ const S = () => {
254
258
  ...Object.hasOwn(e, s) ? e[s] : {},
255
259
  saas: Object.hasOwn(p, s) ? p[s] : {}
256
260
  };
257
- }), /* @__PURE__ */ a(z, { mensajes: l, children: r });
261
+ }), /* @__PURE__ */ a(k, { mensajes: l, children: r });
258
262
  };
259
- j.propTypes = {
263
+ q.propTypes = {
260
264
  mensajes: o.object,
261
265
  idiomaDefecto: o.string,
262
266
  children: o.element.isRequired
263
267
  };
264
- const P = ({
268
+ const V = ({
265
269
  aplicacion: e,
266
- devBackendUrl: i = A,
270
+ devBackendUrl: i = E,
267
271
  devAuthUrl: r = T,
268
272
  dev: t = !1,
269
273
  redirectUri: n,
@@ -273,8 +277,8 @@ const P = ({
273
277
  es: {}
274
278
  },
275
279
  children: s
276
- }) => /* @__PURE__ */ a(j, { mensajes: l, children: /* @__PURE__ */ a(
277
- y,
280
+ }) => /* @__PURE__ */ a(q, { mensajes: l, children: /* @__PURE__ */ a(
281
+ z,
278
282
  {
279
283
  aplicacion: e,
280
284
  devBackendUrl: t && i,
@@ -284,7 +288,7 @@ const P = ({
284
288
  children: s
285
289
  }
286
290
  ) });
287
- P.propTypes = {
291
+ V.propTypes = {
288
292
  aplicacion: o.string.isRequired,
289
293
  devBackendUrl: o.string,
290
294
  devAuthUrl: o.string,
@@ -294,7 +298,7 @@ P.propTypes = {
294
298
  mensajes: o.object,
295
299
  children: o.element.isRequired
296
300
  };
297
- const W = () => {
301
+ const $ = () => {
298
302
  const {
299
303
  loginInProgress: e,
300
304
  token: i,
@@ -302,7 +306,7 @@ const W = () => {
302
306
  logIn: t,
303
307
  logOut: n,
304
308
  error: c
305
- } = k(x);
309
+ } = x(A);
306
310
  return {
307
311
  loginInProgress: e,
308
312
  token: i,
@@ -315,8 +319,8 @@ const W = () => {
315
319
  };
316
320
  };
317
321
  export {
318
- y as Inicializar,
319
- P as SaasApp,
320
- W as useAuth,
322
+ V as SaasApp,
323
+ $ as useAuth,
324
+ j as useLangStore,
321
325
  d as useSaasStore
322
326
  };
@@ -1 +1 @@
1
- (function(s,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("react/jsx-runtime"),require("react"),require("prop-types"),require("react-oauth2-code-pkce"),require("zustand"),require("react-polyglot"),require("lodash"),require("navigator-languages")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","prop-types","react-oauth2-code-pkce","zustand","react-polyglot","lodash","navigator-languages"],o):(s=typeof globalThis<"u"?globalThis:s||self,o(s["react-saas"]={},s.ReactJSX,s.React,s.PropTypes,s.ReactOauth2CodePkce,s.Zustand,s.ReactPolyglot,s.Lodash,s.NavigatorLanguages))})(this,function(s,o,g,t,v,x,f,I,U){"use strict";const A="https://saas.chimera.com.pe/backend/v3",C="https://saas.chimera.com.pe/oauth/v3",O="http://localhost:7000",S="http://localhost:7777",h={primary:"#1C6CCC",secondary:"#17A7FF",info:"#2196f3",success:"#4caf50",error:"#f44336",warning:"#ff9800"},l=x.create(e=>({inicializado:!1,estado:{inicializando:!0,error:null},instancia:{identificador:null,nombre:null,abreviatura:null,requiereLogin:!1,logo:null,color:h},idioma:"en",inicializar:async(r,i)=>{e({estado:{inicializando:!0,error:null}});try{const a=await fetch(`${r||A}/identidad/?codigoAplicacion=${i}`);if(!a.ok)throw new Error(`inicializar.error.${a.status}`);const n=await a.json();e({inicializado:!0,estado:{inicializando:!1,error:null},instancia:{identificador:n.identificador,nombre:n.nombre,abreviatura:n.nombre.match(/\b([A-Z])/g).join(""),requiereLogin:n.requiereLogin,logo:n.logo,color:{...h,...n.color}}})}catch(a){e({inicializado:!1,estado:{inicializando:!1,error:a.message},instancia:{identificador:null,nombre:null,abreviatura:null,requiereLogin:!1,logo:null,color:h}})}},cambiarIdioma:r=>{e({idioma:r})}})),y="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20stroke='%23000'%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%3e%3cstyle%3e.spinner_V8m1{transform-origin:center;animation:spinner_zKoa%202s%20linear%20infinite}.spinner_V8m1%20circle{stroke-linecap:round;animation:spinner_YpZS%201.5s%20ease-in-out%20infinite}@keyframes%20spinner_zKoa{100%25{transform:rotate(360deg)}}@keyframes%20spinner_YpZS{0%25{stroke-dasharray:0%20150;stroke-dashoffset:0}47.5%25{stroke-dasharray:42%20150;stroke-dashoffset:-16}95%25,100%25{stroke-dasharray:42%20150;stroke-dashoffset:-59}}%3c/style%3e%3cg%20class='spinner_V8m1'%3e%3ccircle%20cx='12'%20cy='12'%20r='9.5'%20fill='none'%20stroke-width='3'%3e%3c/circle%3e%3c/g%3e%3c/svg%3e",E=()=>{const e=f.useTranslate();return o.jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[o.jsx("img",{src:y,alt:e("saas.cargando"),style:{filter:"invert(99%) sepia(2%) saturate(740%) hue-rotate(250deg) brightness(93%) contrast(93%)"}}),o.jsx("span",{children:e("saas.cargando")})]})},b=({titulo:e,texto:r})=>{const i=f.useTranslate();return o.jsxs("div",{style:{borderWidth:"2px",borderStyle:"solid",borderRadius:"7px",backgroundColor:"#f44336",padding:"0.5rem",borderColor:"#8d1108"},children:[o.jsx("h4",{style:{marginTop:0,marginBottom:"0.3rem"},children:i(e)}),r&&o.jsx("p",{children:i(r)})]})};b.propTypes={titulo:t.string.isRequired,texto:t.string};const q=({devAuthUrl:e,redirectUri:r,children:i})=>{const a=l(n=>n.instancia);if(a.requiereLogin){const n=e||C;return o.jsx(v.AuthProvider,{authConfig:{clientId:a.identificador,authorizationEndpoint:`${n}/oauth2/authorize`,tokenEndpoint:`${n}/oauth2/token`,logoutEndpoint:`${n}/connect/logout`,redirectUri:r,scope:"openid profile"},children:i})}return i};q.propTypes={devAuthUrl:t.string,redirectUri:t.string.isRequired,children:t.element.isRequired};const z=({aplicacion:e,devBackendUrl:r})=>{const i=l(n=>n.estado),a=l(n=>n.inicializar);return g.useEffect(()=>{a(r,e)},[a,r,e]),o.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"100vh",backgroundColor:"#141316",color:"#e6e1e6"},children:i.inicializando?o.jsx(E,{}):i.error&&o.jsx(b,{titulo:"saas.error.titulo",texto:i.error})})};z.propTypes={aplicacion:t.string.isRequired,devBackendUrl:t.string};const m=({aplicacion:e,devBackendUrl:r,devAuthUrl:i,redirectUri:a,children:n})=>l(u=>u.inicializado)?o.jsx(q,{devAuthUrl:i,redirectUri:a,children:n}):o.jsx(z,{aplicacion:e,devBackendUrl:r});m.propTypes={aplicacion:t.string.isRequired,devBackendUrl:t.string,devAuthUrl:t.string,redirectUri:t.string.isRequired,children:t.element.isRequired};const p={en:{cargando:"Loading...",error:{titulo:"Could not initialize application"}},es:{cargando:"Cargando...",error:{titulo:"Error iniciando aplicación"}}},j=({mensajes:e,children:r})=>{const i=l(a=>a.idioma);return o.jsx(f.I18n,{locale:i,messages:e[i],children:r})};j.propTypes={mensajes:t.object,children:t.element.isRequired};const L=()=>{const e=U();if(!(e!=null&&e.length))return;const r=e[0];return r.indexOf("-")?r.substring(0,r.indexOf("-")):r},k=({mensajes:e,idiomaDefecto:r,children:i})=>{const a=l(c=>c.cambiarIdioma),n=L(),d=I.union(Object.keys(e),Object.keys(p));g.useEffect(()=>{let c=d[0];n&&Object.hasOwn(e,n)?c=n:r&&Object.hasOwn(e,r)&&(c=r),a(c)},[d,e,r,n,a]);const u={};return d.forEach(c=>{u[c]={...Object.hasOwn(e,c)?e[c]:{},saas:Object.hasOwn(p,c)?p[c]:{}}}),o.jsx(j,{mensajes:u,children:i})};k.propTypes={mensajes:t.object,idiomaDefecto:t.string,children:t.element.isRequired};const w=({aplicacion:e,devBackendUrl:r=O,devAuthUrl:i=S,dev:a=!1,redirectUri:n,idiomaDefecto:d="en",mensajes:u={en:{},es:{}},children:c})=>o.jsx(k,{mensajes:u,children:o.jsx(m,{aplicacion:e,devBackendUrl:a&&r,devAuthUrl:a&&i,redirectUri:n,idiomaDefecto:d,children:c})});w.propTypes={aplicacion:t.string.isRequired,devBackendUrl:t.string,devAuthUrl:t.string,dev:t.bool,redirectUri:t.string.isRequired,idiomaDefecto:t.string,mensajes:t.object,children:t.element.isRequired};const _=()=>{const{loginInProgress:e,token:r,tokenData:i,logIn:a,logOut:n,error:d}=g.useContext(v.AuthContext);return{loginInProgress:e,token:r,logIn:a,logOut:n,error:d,correo:i==null?void 0:i.sub,nombre:i==null?void 0:i.name,perfiles:i==null?void 0:i.profiles}};s.Inicializar=m,s.SaasApp=w,s.useAuth=_,s.useSaasStore=l,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
1
+ (function(s,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("react/jsx-runtime"),require("prop-types"),require("react"),require("react-oauth2-code-pkce"),require("zustand"),require("react-polyglot"),require("lodash"),require("navigator-languages")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","prop-types","react","react-oauth2-code-pkce","zustand","react-polyglot","lodash","navigator-languages"],o):(s=typeof globalThis<"u"?globalThis:s||self,o(s["react-saas"]={},s.ReactJSX,s.PropTypes,s.React,s.ReactOauth2CodePkce,s.Zustand,s.ReactPolyglot,s.Lodash,s.NavigatorLanguages))})(this,function(s,o,t,g,b,v,h,C,I){"use strict";const U="https://saas.chimera.com.pe/backend/v3",O="https://saas.chimera.com.pe/oauth/v3",S="http://localhost:7000",y="http://localhost:7777",f={primary:"#1C6CCC",secondary:"#17A7FF",info:"#2196f3",success:"#4caf50",error:"#f44336",warning:"#ff9800"},u=v.create(e=>({inicializado:!1,estado:{inicializando:!0,error:null},instancia:{identificador:null,nombre:null,abreviatura:null,requiereLogin:!1,logo:null,color:f},inicializar:async(r,i)=>{e({estado:{inicializando:!0,error:null}});try{const a=await fetch(`${r||U}/identidad/?codigoAplicacion=${i}`);if(!a.ok)throw new Error(`inicializar.error.${a.status}`);const n=await a.json();e({inicializado:!0,estado:{inicializando:!1,error:null},instancia:{identificador:n.identificador,nombre:n.nombre,abreviatura:n.nombre.match(/\b([A-Z])/g).join(""),requiereLogin:n.requiereLogin,logo:n.logo,color:{...f,...n.color}}})}catch(a){e({inicializado:!1,estado:{inicializando:!1,error:a.message},instancia:{identificador:null,nombre:null,abreviatura:null,requiereLogin:!1,logo:null,color:f}})}}})),E="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20stroke='%23000'%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%3e%3cstyle%3e.spinner_V8m1{transform-origin:center;animation:spinner_zKoa%202s%20linear%20infinite}.spinner_V8m1%20circle{stroke-linecap:round;animation:spinner_YpZS%201.5s%20ease-in-out%20infinite}@keyframes%20spinner_zKoa{100%25{transform:rotate(360deg)}}@keyframes%20spinner_YpZS{0%25{stroke-dasharray:0%20150;stroke-dashoffset:0}47.5%25{stroke-dasharray:42%20150;stroke-dashoffset:-16}95%25,100%25{stroke-dasharray:42%20150;stroke-dashoffset:-59}}%3c/style%3e%3cg%20class='spinner_V8m1'%3e%3ccircle%20cx='12'%20cy='12'%20r='9.5'%20fill='none'%20stroke-width='3'%3e%3c/circle%3e%3c/g%3e%3c/svg%3e",L=()=>{const e=h.useTranslate();return o.jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[o.jsx("img",{src:E,alt:e("saas.cargando"),style:{filter:"invert(99%) sepia(2%) saturate(740%) hue-rotate(250deg) brightness(93%) contrast(93%)"}}),o.jsx("span",{children:e("saas.cargando")})]})},q=({titulo:e,texto:r})=>{const i=h.useTranslate();return o.jsxs("div",{style:{borderWidth:"2px",borderStyle:"solid",borderRadius:"7px",backgroundColor:"#f44336",padding:"0.5rem",borderColor:"#8d1108"},children:[o.jsx("h4",{style:{marginTop:0,marginBottom:"0.3rem"},children:i(e)}),r&&o.jsx("p",{children:i(r)})]})};q.propTypes={titulo:t.string.isRequired,texto:t.string};const z=({devAuthUrl:e,redirectUri:r,children:i})=>{const a=u(n=>n.instancia);if(a.requiereLogin){const n=e||O;return o.jsx(b.AuthProvider,{authConfig:{clientId:a.identificador,authorizationEndpoint:`${n}/oauth2/authorize`,tokenEndpoint:`${n}/oauth2/token`,logoutEndpoint:`${n}/connect/logout`,redirectUri:r,scope:"openid profile"},children:i})}return i};z.propTypes={devAuthUrl:t.string,redirectUri:t.string.isRequired,children:t.element.isRequired};const j=({aplicacion:e,devBackendUrl:r})=>{const i=u(n=>n.estado),a=u(n=>n.inicializar);return g.useEffect(()=>{a(r,e)},[a,r,e]),o.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"100vh",backgroundColor:"#141316",color:"#e6e1e6"},children:i.inicializando?o.jsx(L,{}):i.error&&o.jsx(q,{titulo:"saas.error.titulo",texto:i.error})})};j.propTypes={aplicacion:t.string.isRequired,devBackendUrl:t.string};const k=({aplicacion:e,devBackendUrl:r,devAuthUrl:i,redirectUri:a,children:n})=>u(d=>d.inicializado)?o.jsx(z,{devAuthUrl:i,redirectUri:a,children:n}):o.jsx(j,{aplicacion:e,devBackendUrl:r});k.propTypes={aplicacion:t.string.isRequired,devBackendUrl:t.string,devAuthUrl:t.string,redirectUri:t.string.isRequired,children:t.element.isRequired};const m={en:{nombre:"English",cargando:"Loading...",error:{titulo:"Could not initialize application"}},es:{nombre:"Castellano",cargando:"Cargando...",error:{titulo:"Error iniciando aplicación"}}},p=v.create(e=>({idiomasDisponibles:["en","es"],idiomaActual:"en",cambiarIdioma:r=>{e({idiomaActual:r})}})),A=({mensajes:e,children:r})=>{const i=p(a=>a.idiomaActual);return o.jsx(h.I18n,{locale:i,messages:e[i],children:r})};A.propTypes={mensajes:t.object,children:t.element.isRequired};const _=()=>{const e=I();if(!(e!=null&&e.length))return;const r=e[0];return r.indexOf("-")?r.substring(0,r.indexOf("-")):r},w=({mensajes:e,idiomaDefecto:r,children:i})=>{const a=p(c=>c.cambiarIdioma),n=_(),l=C.union(Object.keys(e),Object.keys(m));g.useEffect(()=>{let c=l[0];n&&Object.hasOwn(e,n)?c=n:r&&Object.hasOwn(e,r)&&(c=r),a(c)},[l,e,r,n,a]);const d={};return l.forEach(c=>{d[c]={...Object.hasOwn(e,c)?e[c]:{},saas:Object.hasOwn(m,c)?m[c]:{}}}),o.jsx(A,{mensajes:d,children:i})};w.propTypes={mensajes:t.object,idiomaDefecto:t.string,children:t.element.isRequired};const x=({aplicacion:e,devBackendUrl:r=S,devAuthUrl:i=y,dev:a=!1,redirectUri:n,idiomaDefecto:l="en",mensajes:d={en:{},es:{}},children:c})=>o.jsx(w,{mensajes:d,children:o.jsx(k,{aplicacion:e,devBackendUrl:a&&r,devAuthUrl:a&&i,redirectUri:n,idiomaDefecto:l,children:c})});x.propTypes={aplicacion:t.string.isRequired,devBackendUrl:t.string,devAuthUrl:t.string,dev:t.bool,redirectUri:t.string.isRequired,idiomaDefecto:t.string,mensajes:t.object,children:t.element.isRequired};const B=()=>{const{loginInProgress:e,token:r,tokenData:i,logIn:a,logOut:n,error:l}=g.useContext(b.AuthContext);return{loginInProgress:e,token:r,logIn:a,logOut:n,error:l,correo:i==null?void 0:i.sub,nombre:i==null?void 0:i.name,perfiles:i==null?void 0:i.profiles}};s.SaasApp=x,s.useAuth=B,s.useLangStore=p,s.useSaasStore=u,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -2,14 +2,16 @@
2
2
  "name": "@chimera-pe/react-saas",
3
3
  "description": "Componente integrador con SaaS",
4
4
  "author": "Germán Enríquez",
5
- "version": "3.0.1",
5
+ "version": "3.0.3",
6
6
  "type": "module",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "https://git.chimera.com.pe/nodejs/react-saas.git"
10
10
  },
11
11
  "keywords": [
12
- "saas"
12
+ "Chimera Software",
13
+ "saas",
14
+ "oAuth2"
13
15
  ],
14
16
  "main": "./dist/react-saas.umd.cjs",
15
17
  "module": "./dist/react-saas.js",
@@ -40,13 +42,13 @@
40
42
  },
41
43
  "devDependencies": {
42
44
  "@eslint/js": "^9.22.0",
43
- "@types/react": "^19.1.3",
44
- "@types/react-dom": "^19.1.3",
45
+ "@types/react": "^19.1.4",
46
+ "@types/react-dom": "^19.1.5",
45
47
  "@vitejs/plugin-react": "^4.4.1",
46
- "eslint": "^9.26.0",
48
+ "eslint": "^9.27.0",
47
49
  "eslint-plugin-react-hooks": "^5.2.0",
48
50
  "eslint-plugin-react-refresh": "^0.4.20",
49
- "globals": "^16.0.0",
51
+ "globals": "^16.1.0",
50
52
  "vite": "^6.3.5"
51
53
  }
52
54
  }