@chimera-pe/react-saas 3.0.10 → 3.0.11

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,9 +1,9 @@
1
1
  import { jsxs as g, jsx as a } from "react/jsx-runtime";
2
2
  import o from "prop-types";
3
3
  import { useContext as j, useEffect as f } from "react";
4
- import { AuthContext as w, AuthProvider as A } from "react-oauth2-code-pkce";
4
+ import { AuthContext as w, AuthProvider as C } from "react-oauth2-code-pkce";
5
5
  import { create as h } from "zustand";
6
- import { useTranslate as b, I18n as C } from "react-polyglot";
6
+ import { useTranslate as b, I18n as A } from "react-polyglot";
7
7
  import { union as I } from "lodash";
8
8
  import q from "navigator-languages";
9
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 = {
@@ -102,7 +102,7 @@ const O = "https://saas.chimera.com.pe/backend", E = "https://saas.chimera.com.p
102
102
  ]
103
103
  }
104
104
  );
105
- }, p = ({ titulo: e, texto: r }) => {
105
+ }, m = ({ titulo: e, texto: r }) => {
106
106
  const i = b();
107
107
  return /* @__PURE__ */ g(
108
108
  "div",
@@ -131,7 +131,7 @@ const O = "https://saas.chimera.com.pe/backend", E = "https://saas.chimera.com.p
131
131
  }
132
132
  );
133
133
  };
134
- p.propTypes = {
134
+ m.propTypes = {
135
135
  titulo: o.string.isRequired,
136
136
  texto: o.string
137
137
  };
@@ -156,13 +156,13 @@ const _ = () => {
156
156
  };
157
157
  }, B = ({ children: e }) => {
158
158
  const { error: r } = _();
159
- return r ? /* @__PURE__ */ a(p, { titulo: "saas.login.error", texto: r }) : e;
159
+ return r ? /* @__PURE__ */ a(m, { titulo: "saas.error.login", texto: r }) : e;
160
160
  }, v = ({ devAuthUrl: e, children: r }) => {
161
161
  const i = d((n) => n.instancia);
162
162
  if (i.requiereLogin) {
163
163
  const n = e || E;
164
164
  return /* @__PURE__ */ a(
165
- A,
165
+ C,
166
166
  {
167
167
  authConfig: {
168
168
  clientId: i.identificador,
@@ -199,7 +199,7 @@ const y = ({ aplicacion: e, devBackendUrl: r }) => {
199
199
  backgroundColor: "#141316",
200
200
  color: "#e6e1e6"
201
201
  },
202
- children: i.inicializando ? /* @__PURE__ */ a(S, {}) : i.error && /* @__PURE__ */ a(p, { titulo: "saas.error.titulo", texto: i.error })
202
+ children: i.inicializando ? /* @__PURE__ */ a(S, {}) : i.error && /* @__PURE__ */ a(m, { titulo: "saas.error.titulo", texto: i.error })
203
203
  }
204
204
  );
205
205
  };
@@ -235,15 +235,17 @@ const D = {
235
235
  nombre: "English",
236
236
  cargando: "Loading...",
237
237
  error: {
238
- titulo: "Could not initialize application"
238
+ titulo: "Could not initialize application",
239
+ login: "Could not login"
239
240
  }
240
241
  }, V = {
241
242
  nombre: "Castellano",
242
243
  cargando: "Cargando...",
243
244
  error: {
244
- titulo: "Error iniciando aplicación"
245
+ titulo: "Error iniciando aplicación",
246
+ login: "No se pudo iniciar sesión"
245
247
  }
246
- }, m = {
248
+ }, p = {
247
249
  en: D,
248
250
  es: V
249
251
  }, z = h((e) => ({
@@ -256,20 +258,20 @@ const D = {
256
258
  }
257
259
  })), x = ({ mensajes: e, children: r }) => {
258
260
  const i = z((n) => n.idiomaActual);
259
- return /* @__PURE__ */ a(C, { locale: i, messages: e[i], children: r });
261
+ return /* @__PURE__ */ a(A, { locale: i, messages: e[i], children: r });
260
262
  };
261
263
  x.propTypes = {
262
264
  mensajes: o.object,
263
265
  children: o.element.isRequired
264
266
  };
265
- const P = () => {
267
+ const N = () => {
266
268
  const e = q();
267
269
  if (!e?.length)
268
270
  return;
269
271
  const r = e[0];
270
272
  return r.indexOf("-") ? r.substring(0, r.indexOf("-")) : r;
271
273
  }, U = ({ mensajes: e, idiomaDefecto: r, children: i }) => {
272
- const n = z((s) => s.cambiarIdioma), t = P(), c = I(Object.keys(e), Object.keys(m));
274
+ const n = z((s) => s.cambiarIdioma), t = N(), c = I(Object.keys(e), Object.keys(p));
273
275
  f(() => {
274
276
  let s = c[0];
275
277
  t && Object.hasOwn(e, t) ? s = t : r && Object.hasOwn(e, r) && (s = r), n(s);
@@ -278,7 +280,7 @@ const P = () => {
278
280
  return c.forEach((s) => {
279
281
  l[s] = {
280
282
  ...Object.hasOwn(e, s) ? e[s] : {},
281
- saas: Object.hasOwn(m, s) ? m[s] : {}
283
+ saas: Object.hasOwn(p, s) ? p[s] : {}
282
284
  };
283
285
  }), /* @__PURE__ */ a(x, { mensajes: l, children: i });
284
286
  };
@@ -287,7 +289,7 @@ U.propTypes = {
287
289
  idiomaDefecto: o.string,
288
290
  children: o.element.isRequired
289
291
  };
290
- const Z = ({
292
+ const P = ({
291
293
  aplicacion: e,
292
294
  dev: r = !1,
293
295
  devBackendUrl: i = R,
@@ -308,7 +310,7 @@ const Z = ({
308
310
  children: l
309
311
  }
310
312
  ) });
311
- Z.propTypes = {
313
+ P.propTypes = {
312
314
  aplicacion: o.string.isRequired,
313
315
  dev: o.bool,
314
316
  devBackendUrl: o.string,
@@ -318,7 +320,7 @@ Z.propTypes = {
318
320
  children: o.element.isRequired
319
321
  };
320
322
  export {
321
- Z as SaasApp,
323
+ P as SaasApp,
322
324
  _ as useAuth,
323
325
  z as useLangStore,
324
326
  d as useSaasStore
@@ -1 +1 @@
1
- (function(s,t){typeof exports=="object"&&typeof module<"u"?t(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"],t):(s=typeof globalThis<"u"?globalThis:s||self,t(s["react-saas"]={},s.ReactJSX,s.PropTypes,s.React,s.ReactOauth2CodePkce,s.Zustand,s.ReactPolyglot,s.Lodash,s.NavigatorLanguages))})(this,(function(s,t,a,g,v,k,f,C,I){"use strict";const y="https://saas.chimera.com.pe/backend",O="https://saas.chimera.com.pe/v3",S="http://localhost:7000",E="http://localhost:7777",h={primary:"#1C6CCC",secondary:"#17A7FF",info:"#2196f3",success:"#4caf50",error:"#f44336",warning:"#ff9800"},d=k.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(r,i)=>{e({estado:{inicializando:!0,error:null}});try{const n=await fetch(`${r||y}/identidad/?codigoAplicacion=${i}`);if(!n.ok)throw new Error(`inicializar.error.${n.status}`);const o=await n.json();e({inicializado:!0,estado:{inicializando:!1,error:null},instancia:{identificador:o.identificador,nombre:o.nombre,abreviatura:o.nombre.match(/\b([A-Z])/g).join(""),requiereLogin:o.requiereLogin,redirectUri:o.redirectUri,logo:o.logo,color:{...h,...o.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}})}}})),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",_=()=>{const e=f.useTranslate();return t.jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[t.jsx("img",{src:L,alt:e("saas.cargando"),style:{filter:"invert(99%) sepia(2%) saturate(740%) hue-rotate(250deg) brightness(93%) contrast(93%)"}}),t.jsx("span",{children:e("saas.cargando")})]})},m=({titulo:e,texto:r})=>{const i=f.useTranslate();return t.jsxs("div",{style:{borderWidth:"2px",borderStyle:"solid",borderRadius:"7px",backgroundColor:"#f44336",padding:"0.5rem",borderColor:"#8d1108"},children:[t.jsx("h4",{style:{marginTop:0,marginBottom:"0.3rem"},children:i(e)}),r&&t.jsx("p",{children:i(r)})]})};m.propTypes={titulo:a.string.isRequired,texto:a.string};const z=()=>{const{loginInProgress:e,token:r,tokenData:i,logIn:n,logOut:o,error:l}=g.useContext(v.AuthContext);return{loginInProgress:e,token:r,logIn:n,logOut:o,error:l,correo:i?.sub,nombre:i?.name,perfiles:i?.profiles}},B=({children:e})=>{const{error:r}=z();return r?t.jsx(m,{titulo:"saas.login.error",texto:r}):e},q=({devAuthUrl:e,children:r})=>{const i=d(n=>n.instancia);if(i.requiereLogin){const n=e||O;return t.jsx(v.AuthProvider,{authConfig:{clientId:i.identificador,authorizationEndpoint:`${n}/oauth2/authorize`,tokenEndpoint:`${n}/oauth2/token`,logoutEndpoint:`${n}/connect/logout`,redirectUri:i.redirectUri,scope:"openid profile",storage:"session"},children:t.jsx(B,{children:r})})}return r};q.propTypes={devAuthUrl:a.string,children:a.element.isRequired};const j=({aplicacion:e,devBackendUrl:r})=>{const i=d(o=>o.estado),n=d(o=>o.inicializar);return g.useEffect(()=>{n(r,e)},[n,r,e]),t.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"100vh",backgroundColor:"#141316",color:"#e6e1e6"},children:i.inicializando?t.jsx(_,{}):i.error&&t.jsx(m,{titulo:"saas.error.titulo",texto:i.error})})};j.propTypes={aplicacion:a.string.isRequired,devBackendUrl:a.string};const U=({aplicacion:e,devBackendUrl:r,devAuthUrl:i,children:n})=>d(l=>l.inicializado)?t.jsx(q,{devAuthUrl:i,children:n}):t.jsx(j,{aplicacion:e,devBackendUrl:r});U.propTypes={aplicacion:a.string.isRequired,devBackendUrl:a.string,devAuthUrl:a.string,children:a.element.isRequired};const p={en:{nombre:"English",cargando:"Loading...",error:{titulo:"Could not initialize application"}},es:{nombre:"Castellano",cargando:"Cargando...",error:{titulo:"Error iniciando aplicación"}}},b=k.create(e=>({idiomasDisponibles:["en","es"],idiomaActual:"en",cambiarIdioma:r=>{e({idiomaActual:r})}})),x=({mensajes:e,children:r})=>{const i=b(n=>n.idiomaActual);return t.jsx(f.I18n,{locale:i,messages:e[i],children:r})};x.propTypes={mensajes:a.object,children:a.element.isRequired};const D=()=>{const e=I();if(!e?.length)return;const r=e[0];return r.indexOf("-")?r.substring(0,r.indexOf("-")):r},A=({mensajes:e,idiomaDefecto:r,children:i})=>{const n=b(c=>c.cambiarIdioma),o=D(),l=C.union(Object.keys(e),Object.keys(p));g.useEffect(()=>{let c=l[0];o&&Object.hasOwn(e,o)?c=o:r&&Object.hasOwn(e,r)&&(c=r),n(c)},[l,e,r,o,n]);const u={};return l.forEach(c=>{u[c]={...Object.hasOwn(e,c)?e[c]:{},saas:Object.hasOwn(p,c)?p[c]:{}}}),t.jsx(x,{mensajes:u,children:i})};A.propTypes={mensajes:a.object,idiomaDefecto:a.string,children:a.element.isRequired};const w=({aplicacion:e,dev:r=!1,devBackendUrl:i=S,devAuthUrl:n=E,idiomaDefecto:o="en",mensajes:l={en:{},es:{}},children:u})=>t.jsx(A,{mensajes:l,children:t.jsx(U,{aplicacion:e,devBackendUrl:r?i:null,devAuthUrl:r?n:null,idiomaDefecto:o,children:u})});w.propTypes={aplicacion:a.string.isRequired,dev:a.bool,devBackendUrl:a.string,devAuthUrl:a.string,idiomaDefecto:a.string,mensajes:a.object,children:a.element.isRequired},s.SaasApp=w,s.useAuth=z,s.useLangStore=b,s.useSaasStore=d,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(s,t){typeof exports=="object"&&typeof module<"u"?t(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"],t):(s=typeof globalThis<"u"?globalThis:s||self,t(s["react-saas"]={},s.ReactJSX,s.PropTypes,s.React,s.ReactOauth2CodePkce,s.Zustand,s.ReactPolyglot,s.Lodash,s.NavigatorLanguages))})(this,(function(s,t,a,g,v,k,f,C,I){"use strict";const y="https://saas.chimera.com.pe/backend",O="https://saas.chimera.com.pe/v3",S="http://localhost:7000",E="http://localhost:7777",h={primary:"#1C6CCC",secondary:"#17A7FF",info:"#2196f3",success:"#4caf50",error:"#f44336",warning:"#ff9800"},d=k.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||y}/identidad/?codigoAplicacion=${r}`);if(!n.ok)throw new Error(`inicializar.error.${n.status}`);const o=await n.json();e({inicializado:!0,estado:{inicializando:!1,error:null},instancia:{identificador:o.identificador,nombre:o.nombre,abreviatura:o.nombre.match(/\b([A-Z])/g).join(""),requiereLogin:o.requiereLogin,redirectUri:o.redirectUri,logo:o.logo,color:{...h,...o.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}})}}})),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",_=()=>{const e=f.useTranslate();return t.jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[t.jsx("img",{src:L,alt:e("saas.cargando"),style:{filter:"invert(99%) sepia(2%) saturate(740%) hue-rotate(250deg) brightness(93%) contrast(93%)"}}),t.jsx("span",{children:e("saas.cargando")})]})},m=({titulo:e,texto:i})=>{const r=f.useTranslate();return t.jsxs("div",{style:{borderWidth:"2px",borderStyle:"solid",borderRadius:"7px",backgroundColor:"#f44336",padding:"0.5rem",borderColor:"#8d1108"},children:[t.jsx("h4",{style:{marginTop:0,marginBottom:"0.3rem"},children:r(e)}),i&&t.jsx("p",{children:r(i)})]})};m.propTypes={titulo:a.string.isRequired,texto:a.string};const z=()=>{const{loginInProgress:e,token:i,tokenData:r,logIn:n,logOut:o,error:l}=g.useContext(v.AuthContext);return{loginInProgress:e,token:i,logIn:n,logOut:o,error:l,correo:r?.sub,nombre:r?.name,perfiles:r?.profiles}},B=({children:e})=>{const{error:i}=z();return i?t.jsx(m,{titulo:"saas.error.login",texto:i}):e},q=({devAuthUrl:e,children:i})=>{const r=d(n=>n.instancia);if(r.requiereLogin){const n=e||O;return t.jsx(v.AuthProvider,{authConfig:{clientId:r.identificador,authorizationEndpoint:`${n}/oauth2/authorize`,tokenEndpoint:`${n}/oauth2/token`,logoutEndpoint:`${n}/connect/logout`,redirectUri:r.redirectUri,scope:"openid profile",storage:"session"},children:t.jsx(B,{children:i})})}return i};q.propTypes={devAuthUrl:a.string,children:a.element.isRequired};const j=({aplicacion:e,devBackendUrl:i})=>{const r=d(o=>o.estado),n=d(o=>o.inicializar);return g.useEffect(()=>{n(i,e)},[n,i,e]),t.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:"100vh",backgroundColor:"#141316",color:"#e6e1e6"},children:r.inicializando?t.jsx(_,{}):r.error&&t.jsx(m,{titulo:"saas.error.titulo",texto:r.error})})};j.propTypes={aplicacion:a.string.isRequired,devBackendUrl:a.string};const U=({aplicacion:e,devBackendUrl:i,devAuthUrl:r,children:n})=>d(l=>l.inicializado)?t.jsx(q,{devAuthUrl:r,children:n}):t.jsx(j,{aplicacion:e,devBackendUrl:i});U.propTypes={aplicacion:a.string.isRequired,devBackendUrl:a.string,devAuthUrl:a.string,children:a.element.isRequired};const p={en:{nombre:"English",cargando:"Loading...",error:{titulo:"Could not initialize application",login:"Could not login"}},es:{nombre:"Castellano",cargando:"Cargando...",error:{titulo:"Error iniciando aplicación",login:"No se pudo iniciar sesión"}}},b=k.create(e=>({idiomasDisponibles:["en","es"],idiomaActual:"en",cambiarIdioma:i=>{e({idiomaActual:i})}})),x=({mensajes:e,children:i})=>{const r=b(n=>n.idiomaActual);return t.jsx(f.I18n,{locale:r,messages:e[r],children:i})};x.propTypes={mensajes:a.object,children:a.element.isRequired};const D=()=>{const e=I();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=b(c=>c.cambiarIdioma),o=D(),l=C.union(Object.keys(e),Object.keys(p));g.useEffect(()=>{let c=l[0];o&&Object.hasOwn(e,o)?c=o:i&&Object.hasOwn(e,i)&&(c=i),n(c)},[l,e,i,o,n]);const u={};return l.forEach(c=>{u[c]={...Object.hasOwn(e,c)?e[c]:{},saas:Object.hasOwn(p,c)?p[c]:{}}}),t.jsx(x,{mensajes:u,children:r})};A.propTypes={mensajes:a.object,idiomaDefecto:a.string,children:a.element.isRequired};const w=({aplicacion:e,dev:i=!1,devBackendUrl:r=S,devAuthUrl:n=E,idiomaDefecto:o="en",mensajes:l={en:{},es:{}},children:u})=>t.jsx(A,{mensajes:l,children:t.jsx(U,{aplicacion:e,devBackendUrl:i?r:null,devAuthUrl:i?n:null,idiomaDefecto:o,children:u})});w.propTypes={aplicacion:a.string.isRequired,dev:a.bool,devBackendUrl:a.string,devAuthUrl:a.string,idiomaDefecto:a.string,mensajes:a.object,children:a.element.isRequired},s.SaasApp=w,s.useAuth=z,s.useLangStore=b,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.10",
5
+ "version": "3.0.11",
6
6
  "type": "module",
7
7
  "repository": {
8
8
  "type": "git",