@chimera-pe/react-saas 3.0.5 → 3.0.7

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,12 +1,12 @@
1
- import { jsxs as m, jsx as a } from "react/jsx-runtime";
1
+ import { jsxs as p, jsx as a } from "react/jsx-runtime";
2
2
  import o from "prop-types";
3
3
  import { useEffect as g, useContext as x } from "react";
4
4
  import { AuthProvider as w, AuthContext as A } from "react-oauth2-code-pkce";
5
5
  import { create as f } from "zustand";
6
6
  import { useTranslate as h, I18n as C } from "react-polyglot";
7
7
  import { union as I } from "lodash";
8
- import U from "navigator-languages";
9
- const O = "https://saas.chimera.com.pe/backend", R = "https://saas.chimera.com.pe/v3", E = "http://localhost:7000", T = "http://localhost:7777", u = {
8
+ import q from "navigator-languages";
9
+ const O = "https://saas.chimera.com.pe/backend", E = "https://saas.chimera.com.pe/v3", R = "http://localhost:7000", T = "http://localhost:7777", u = {
10
10
  primary: "#1C6CCC",
11
11
  secondary: "#17A7FF",
12
12
  info: "#2196f3",
@@ -24,10 +24,11 @@ const O = "https://saas.chimera.com.pe/backend", R = "https://saas.chimera.com.p
24
24
  nombre: null,
25
25
  abreviatura: null,
26
26
  requiereLogin: !1,
27
+ redirectUri: null,
27
28
  logo: null,
28
29
  color: u
29
30
  },
30
- inicializar: async (i, r) => {
31
+ inicializar: async (r, i) => {
31
32
  e({
32
33
  estado: {
33
34
  inicializando: !0,
@@ -35,10 +36,10 @@ const O = "https://saas.chimera.com.pe/backend", R = "https://saas.chimera.com.p
35
36
  }
36
37
  });
37
38
  try {
38
- const t = await fetch(`${i || O}/identidad/?codigoAplicacion=${r}`);
39
- if (!t.ok)
40
- throw new Error(`inicializar.error.${t.status}`);
41
- const n = await t.json();
39
+ const n = await fetch(`${r || O}/identidad/?codigoAplicacion=${i}`);
40
+ if (!n.ok)
41
+ throw new Error(`inicializar.error.${n.status}`);
42
+ const t = await n.json();
42
43
  e({
43
44
  inicializado: !0,
44
45
  estado: {
@@ -46,29 +47,31 @@ const O = "https://saas.chimera.com.pe/backend", R = "https://saas.chimera.com.p
46
47
  error: null
47
48
  },
48
49
  instancia: {
49
- identificador: n.identificador,
50
- nombre: n.nombre,
51
- abreviatura: n.nombre.match(/\b([A-Z])/g).join(""),
52
- requiereLogin: n.requiereLogin,
53
- logo: n.logo,
50
+ identificador: t.identificador,
51
+ nombre: t.nombre,
52
+ abreviatura: t.nombre.match(/\b([A-Z])/g).join(""),
53
+ requiereLogin: t.requiereLogin,
54
+ redirectUri: t.redirectUri,
55
+ logo: t.logo,
54
56
  color: {
55
57
  ...u,
56
- ...n.color
58
+ ...t.color
57
59
  }
58
60
  }
59
61
  });
60
- } catch (t) {
62
+ } catch (n) {
61
63
  e({
62
64
  inicializado: !1,
63
65
  estado: {
64
66
  inicializando: !1,
65
- error: t.message
67
+ error: n.message
66
68
  },
67
69
  instancia: {
68
70
  identificador: null,
69
71
  nombre: null,
70
72
  abreviatura: null,
71
73
  requiereLogin: !1,
74
+ redirectUri: null,
72
75
  logo: null,
73
76
  color: u
74
77
  }
@@ -77,7 +80,7 @@ const O = "https://saas.chimera.com.pe/backend", R = "https://saas.chimera.com.p
77
80
  }
78
81
  })), 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
82
  const e = h();
80
- return /* @__PURE__ */ m(
83
+ return /* @__PURE__ */ p(
81
84
  "div",
82
85
  {
83
86
  style: {
@@ -99,9 +102,9 @@ const O = "https://saas.chimera.com.pe/backend", R = "https://saas.chimera.com.p
99
102
  ]
100
103
  }
101
104
  );
102
- }, b = ({ titulo: e, texto: i }) => {
103
- const r = h();
104
- return /* @__PURE__ */ m(
105
+ }, b = ({ titulo: e, texto: r }) => {
106
+ const i = h();
107
+ return /* @__PURE__ */ p(
105
108
  "div",
106
109
  {
107
110
  style: {
@@ -120,10 +123,10 @@ const O = "https://saas.chimera.com.pe/backend", R = "https://saas.chimera.com.p
120
123
  marginTop: 0,
121
124
  marginBottom: "0.3rem"
122
125
  },
123
- children: r(e)
126
+ children: i(e)
124
127
  }
125
128
  ),
126
- i && /* @__PURE__ */ a("p", { children: r(i) })
129
+ r && /* @__PURE__ */ a("p", { children: i(r) })
127
130
  ]
128
131
  }
129
132
  );
@@ -132,19 +135,19 @@ b.propTypes = {
132
135
  titulo: o.string.isRequired,
133
136
  texto: o.string
134
137
  };
135
- const v = ({ devAuthUrl: e, redirectUri: i, children: r }) => {
136
- const t = d((n) => n.instancia);
137
- if (t.requiereLogin) {
138
- const n = e || R;
138
+ const v = ({ devAuthUrl: e, children: r }) => {
139
+ const i = d((n) => n.instancia);
140
+ if (i.requiereLogin) {
141
+ const n = e || E;
139
142
  return /* @__PURE__ */ a(
140
143
  w,
141
144
  {
142
145
  authConfig: {
143
- clientId: t.identificador,
146
+ clientId: i.identificador,
144
147
  authorizationEndpoint: `${n}/oauth2/authorize`,
145
148
  tokenEndpoint: `${n}/oauth2/token`,
146
149
  logoutEndpoint: `${n}/connect/logout`,
147
- redirectUri: i,
150
+ redirectUri: i.redirectUri,
148
151
  scope: "openid profile"
149
152
  },
150
153
  children: r
@@ -155,14 +158,13 @@ const v = ({ devAuthUrl: e, redirectUri: i, children: r }) => {
155
158
  };
156
159
  v.propTypes = {
157
160
  devAuthUrl: o.string,
158
- redirectUri: o.string.isRequired,
159
161
  children: o.element.isRequired
160
162
  };
161
- const y = ({ aplicacion: e, devBackendUrl: i }) => {
162
- const r = d((n) => n.estado), t = d((n) => n.inicializar);
163
+ const y = ({ aplicacion: e, devBackendUrl: r }) => {
164
+ const i = d((t) => t.estado), n = d((t) => t.inicializar);
163
165
  return g(() => {
164
- t(i, e);
165
- }, [t, i, e]), /* @__PURE__ */ a(
166
+ n(r, e);
167
+ }, [n, r, e]), /* @__PURE__ */ a(
166
168
  "div",
167
169
  {
168
170
  style: {
@@ -174,7 +176,7 @@ const y = ({ aplicacion: e, devBackendUrl: i }) => {
174
176
  backgroundColor: "#141316",
175
177
  color: "#e6e1e6"
176
178
  },
177
- children: r.inicializando ? /* @__PURE__ */ a(S, {}) : r.error && /* @__PURE__ */ a(b, { titulo: "saas.error.titulo", texto: r.error })
179
+ children: i.inicializando ? /* @__PURE__ */ a(S, {}) : i.error && /* @__PURE__ */ a(b, { titulo: "saas.error.titulo", texto: i.error })
178
180
  }
179
181
  );
180
182
  };
@@ -182,31 +184,28 @@ y.propTypes = {
182
184
  aplicacion: o.string.isRequired,
183
185
  devBackendUrl: o.string
184
186
  };
185
- const z = ({
187
+ const k = ({
186
188
  aplicacion: e,
187
- devBackendUrl: i,
188
- devAuthUrl: r,
189
- redirectUri: t,
189
+ devBackendUrl: r,
190
+ devAuthUrl: i,
190
191
  children: n
191
- }) => d((l) => l.inicializado) ? /* @__PURE__ */ a(
192
+ }) => d((c) => c.inicializado) ? /* @__PURE__ */ a(
192
193
  v,
193
194
  {
194
- devAuthUrl: r,
195
- redirectUri: t,
195
+ devAuthUrl: i,
196
196
  children: n
197
197
  }
198
198
  ) : /* @__PURE__ */ a(
199
199
  y,
200
200
  {
201
201
  aplicacion: e,
202
- devBackendUrl: i
202
+ devBackendUrl: r
203
203
  }
204
204
  );
205
- z.propTypes = {
205
+ k.propTypes = {
206
206
  aplicacion: o.string.isRequired,
207
207
  devBackendUrl: o.string,
208
208
  devAuthUrl: o.string,
209
- redirectUri: o.string.isRequired,
210
209
  children: o.element.isRequired
211
210
  };
212
211
  const _ = {
@@ -221,106 +220,103 @@ const _ = {
221
220
  error: {
222
221
  titulo: "Error iniciando aplicación"
223
222
  }
224
- }, p = {
223
+ }, m = {
225
224
  en: _,
226
225
  es: B
227
- }, j = f((e) => ({
226
+ }, z = f((e) => ({
228
227
  idiomasDisponibles: ["en", "es"],
229
228
  idiomaActual: "en",
230
- cambiarIdioma: (i) => {
229
+ cambiarIdioma: (r) => {
231
230
  e({
232
- idiomaActual: i
231
+ idiomaActual: r
233
232
  });
234
233
  }
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
+ })), U = ({ mensajes: e, children: r }) => {
235
+ const i = z((n) => n.idiomaActual);
236
+ return /* @__PURE__ */ a(C, { locale: i, messages: e[i], children: r });
238
237
  };
239
- k.propTypes = {
238
+ U.propTypes = {
240
239
  mensajes: o.object,
241
240
  children: o.element.isRequired
242
241
  };
243
- const P = () => {
244
- const e = U();
245
- if (!(e != null && e.length))
242
+ const D = () => {
243
+ const e = q();
244
+ if (!e?.length)
246
245
  return;
247
- const i = e[0];
248
- return i.indexOf("-") ? i.substring(0, i.indexOf("-")) : i;
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));
246
+ const r = e[0];
247
+ return r.indexOf("-") ? r.substring(0, r.indexOf("-")) : r;
248
+ }, j = ({ mensajes: e, idiomaDefecto: r, children: i }) => {
249
+ const n = z((s) => s.cambiarIdioma), t = D(), c = I(Object.keys(e), Object.keys(m));
251
250
  g(() => {
252
251
  let s = c[0];
253
- n && Object.hasOwn(e, n) ? s = n : i && Object.hasOwn(e, i) && (s = i), t(s);
254
- }, [c, e, i, n, t]);
252
+ t && Object.hasOwn(e, t) ? s = t : r && Object.hasOwn(e, r) && (s = r), n(s);
253
+ }, [c, e, r, t, n]);
255
254
  const l = {};
256
255
  return c.forEach((s) => {
257
256
  l[s] = {
258
257
  ...Object.hasOwn(e, s) ? e[s] : {},
259
- saas: Object.hasOwn(p, s) ? p[s] : {}
258
+ saas: Object.hasOwn(m, s) ? m[s] : {}
260
259
  };
261
- }), /* @__PURE__ */ a(k, { mensajes: l, children: r });
260
+ }), /* @__PURE__ */ a(U, { mensajes: l, children: i });
262
261
  };
263
- q.propTypes = {
262
+ j.propTypes = {
264
263
  mensajes: o.object,
265
264
  idiomaDefecto: o.string,
266
265
  children: o.element.isRequired
267
266
  };
268
- const V = ({
267
+ const P = ({
269
268
  aplicacion: e,
270
- devBackendUrl: i = E,
271
- devAuthUrl: r = T,
272
- dev: t = !1,
273
- redirectUri: n,
274
- idiomaDefecto: c = "en",
275
- mensajes: l = {
269
+ dev: r = !1,
270
+ devBackendUrl: i = R,
271
+ devAuthUrl: n = T,
272
+ idiomaDefecto: t = "en",
273
+ mensajes: c = {
276
274
  en: {},
277
275
  es: {}
278
276
  },
279
- children: s
280
- }) => /* @__PURE__ */ a(q, { mensajes: l, children: /* @__PURE__ */ a(
281
- z,
277
+ children: l
278
+ }) => /* @__PURE__ */ a(j, { mensajes: c, children: /* @__PURE__ */ a(
279
+ k,
282
280
  {
283
281
  aplicacion: e,
284
- devBackendUrl: t ? i : null,
285
- devAuthUrl: t ? r : null,
286
- redirectUri: n,
287
- idiomaDefecto: c,
288
- children: s
282
+ devBackendUrl: r ? i : null,
283
+ devAuthUrl: r ? n : null,
284
+ idiomaDefecto: t,
285
+ children: l
289
286
  }
290
287
  ) });
291
- V.propTypes = {
288
+ P.propTypes = {
292
289
  aplicacion: o.string.isRequired,
290
+ dev: o.bool,
293
291
  devBackendUrl: o.string,
294
292
  devAuthUrl: o.string,
295
- dev: o.bool,
296
- redirectUri: o.string.isRequired,
297
293
  idiomaDefecto: o.string,
298
294
  mensajes: o.object,
299
295
  children: o.element.isRequired
300
296
  };
301
- const $ = () => {
297
+ const W = () => {
302
298
  const {
303
299
  loginInProgress: e,
304
- token: i,
305
- tokenData: r,
306
- logIn: t,
307
- logOut: n,
300
+ token: r,
301
+ tokenData: i,
302
+ logIn: n,
303
+ logOut: t,
308
304
  error: c
309
305
  } = x(A);
310
306
  return {
311
307
  loginInProgress: e,
312
- token: i,
313
- logIn: t,
314
- logOut: n,
308
+ token: r,
309
+ logIn: n,
310
+ logOut: t,
315
311
  error: c,
316
- correo: r == null ? void 0 : r.sub,
317
- nombre: r == null ? void 0 : r.name,
318
- perfiles: r == null ? void 0 : r.profiles
312
+ correo: i?.sub,
313
+ nombre: i?.name,
314
+ perfiles: i?.profiles
319
315
  };
320
316
  };
321
317
  export {
322
- V as SaasApp,
323
- $ as useAuth,
324
- j as useLangStore,
318
+ P as SaasApp,
319
+ W as useAuth,
320
+ z as useLangStore,
325
321
  d as useSaasStore
326
322
  };
@@ -1 +1 @@
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,f,C,I){"use strict";const U="https://saas.chimera.com.pe/backend",O="https://saas.chimera.com.pe/v3",S="http://localhost:7000",y="http://localhost:7777",h={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:h},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:{...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}})}}})),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=f.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=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)})]})};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(f.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:null,devAuthUrl:a?i:null,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"})});
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,f,x,C){"use strict";const I="https://saas.chimera.com.pe/backend",y="https://saas.chimera.com.pe/v3",O="http://localhost:7000",S="http://localhost:7777",h={primary:"#1C6CCC",secondary:"#17A7FF",info:"#2196f3",success:"#4caf50",error:"#f44336",warning:"#ff9800"},d=v.create(e=>({inicializado:!1,estado:{inicializando:!0,error:null},instancia:{identificador:null,nombre:null,abreviatura:null,requiereLogin:!1,redirectUri:null,logo:null,color:h},inicializar:async(i,r)=>{e({estado:{inicializando:!0,error:null}});try{const n=await fetch(`${i||I}/identidad/?codigoAplicacion=${r}`);if(!n.ok)throw new Error(`inicializar.error.${n.status}`);const a=await n.json();e({inicializado:!0,estado:{inicializando:!1,error:null},instancia:{identificador:a.identificador,nombre:a.nombre,abreviatura:a.nombre.match(/\b([A-Z])/g).join(""),requiereLogin:a.requiereLogin,redirectUri:a.redirectUri,logo:a.logo,color:{...h,...a.color}}})}catch(n){e({inicializado:!1,estado:{inicializando:!1,error:n.message},instancia:{identificador:null,nombre:null,abreviatura:null,requiereLogin:!1,redirectUri:null,logo:null,color:h}})}}})),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=f.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")})]})},k=({titulo:e,texto:i})=>{const r=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:r(e)}),i&&o.jsx("p",{children:r(i)})]})};k.propTypes={titulo:t.string.isRequired,texto:t.string};const z=({devAuthUrl:e,children:i})=>{const r=d(n=>n.instancia);if(r.requiereLogin){const n=e||y;return o.jsx(b.AuthProvider,{authConfig:{clientId:r.identificador,authorizationEndpoint:`${n}/oauth2/authorize`,tokenEndpoint:`${n}/oauth2/token`,logoutEndpoint:`${n}/connect/logout`,redirectUri:r.redirectUri,scope:"openid profile"},children:i})}return i};z.propTypes={devAuthUrl:t.string,children:t.element.isRequired};const q=({aplicacion:e,devBackendUrl:i})=>{const r=d(a=>a.estado),n=d(a=>a.inicializar);return g.useEffect(()=>{n(i,e)},[n,i,e]),o.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"100vh",backgroundColor:"#141316",color:"#e6e1e6"},children:r.inicializando?o.jsx(L,{}):r.error&&o.jsx(k,{titulo:"saas.error.titulo",texto:r.error})})};q.propTypes={aplicacion:t.string.isRequired,devBackendUrl:t.string};const j=({aplicacion:e,devBackendUrl:i,devAuthUrl:r,children:n})=>d(l=>l.inicializado)?o.jsx(z,{devAuthUrl:r,children:n}):o.jsx(q,{aplicacion:e,devBackendUrl:i});j.propTypes={aplicacion:t.string.isRequired,devBackendUrl:t.string,devAuthUrl:t.string,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:i=>{e({idiomaActual:i})}})),U=({mensajes:e,children:i})=>{const r=p(n=>n.idiomaActual);return o.jsx(f.I18n,{locale:r,messages:e[r],children:i})};U.propTypes={mensajes:t.object,children:t.element.isRequired};const _=()=>{const e=C();if(!e?.length)return;const i=e[0];return i.indexOf("-")?i.substring(0,i.indexOf("-")):i},A=({mensajes:e,idiomaDefecto:i,children:r})=>{const n=p(c=>c.cambiarIdioma),a=_(),l=x.union(Object.keys(e),Object.keys(m));g.useEffect(()=>{let c=l[0];a&&Object.hasOwn(e,a)?c=a:i&&Object.hasOwn(e,i)&&(c=i),n(c)},[l,e,i,a,n]);const u={};return l.forEach(c=>{u[c]={...Object.hasOwn(e,c)?e[c]:{},saas:Object.hasOwn(m,c)?m[c]:{}}}),o.jsx(U,{mensajes:u,children:r})};A.propTypes={mensajes:t.object,idiomaDefecto:t.string,children:t.element.isRequired};const w=({aplicacion:e,dev:i=!1,devBackendUrl:r=O,devAuthUrl:n=S,idiomaDefecto:a="en",mensajes:l={en:{},es:{}},children:u})=>o.jsx(A,{mensajes:l,children:o.jsx(j,{aplicacion:e,devBackendUrl:i?r:null,devAuthUrl:i?n:null,idiomaDefecto:a,children:u})});w.propTypes={aplicacion:t.string.isRequired,dev:t.bool,devBackendUrl:t.string,devAuthUrl:t.string,idiomaDefecto:t.string,mensajes:t.object,children:t.element.isRequired};const B=()=>{const{loginInProgress:e,token:i,tokenData:r,logIn:n,logOut:a,error:l}=g.useContext(b.AuthContext);return{loginInProgress:e,token:i,logIn:n,logOut:a,error:l,correo:r?.sub,nombre:r?.name,perfiles:r?.profiles}};s.SaasApp=w,s.useAuth=B,s.useLangStore=p,s.useSaasStore=d,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -2,7 +2,7 @@
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.5",
5
+ "version": "3.0.7",
6
6
  "type": "module",
7
7
  "repository": {
8
8
  "type": "git",
@@ -34,21 +34,21 @@
34
34
  "peerDependencies": {
35
35
  "lodash": "^4.17.21",
36
36
  "navigator-languages": "^2.0.2",
37
- "react": "^19.1.0",
38
- "react-dom": "^19.1.0",
39
- "react-oauth2-code-pkce": "^1.23.0",
37
+ "react": "^19.1.1",
38
+ "react-dom": "^19.1.1",
39
+ "react-oauth2-code-pkce": "^1.23.2",
40
40
  "react-polyglot": "^0.7.2",
41
- "zustand": "^5.0.5"
41
+ "zustand": "^5.0.8"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@eslint/js": "^9.25.0",
45
- "@types/react": "^19.1.6",
46
- "@types/react-dom": "^19.1.6",
47
- "@vitejs/plugin-react": "^4.5.1",
48
- "eslint": "^9.28.0",
45
+ "@types/react": "^19.1.12",
46
+ "@types/react-dom": "^19.1.9",
47
+ "@vitejs/plugin-react": "^4.7.0",
48
+ "eslint": "^9.34.0",
49
49
  "eslint-plugin-react-hooks": "^5.2.0",
50
50
  "eslint-plugin-react-refresh": "^0.4.20",
51
- "globals": "^16.2.0",
52
- "vite": "^6.3.5"
51
+ "globals": "^16.3.0",
52
+ "vite": "^7.1.4"
53
53
  }
54
54
  }