@chimera-pe/react-saas 3.0.9 → 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.
- package/dist/react-saas.js +63 -58
- package/dist/react-saas.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/react-saas.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { jsxs as
|
|
1
|
+
import { jsxs as g, jsx as a } from "react/jsx-runtime";
|
|
2
2
|
import o from "prop-types";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { create as
|
|
6
|
-
import { useTranslate as
|
|
3
|
+
import { useContext as j, useEffect as f } from "react";
|
|
4
|
+
import { AuthContext as w, AuthProvider as C } from "react-oauth2-code-pkce";
|
|
5
|
+
import { create as h } from "zustand";
|
|
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 = {
|
|
@@ -13,7 +13,7 @@ const O = "https://saas.chimera.com.pe/backend", E = "https://saas.chimera.com.p
|
|
|
13
13
|
success: "#4caf50",
|
|
14
14
|
error: "#f44336",
|
|
15
15
|
warning: "#ff9800"
|
|
16
|
-
}, d =
|
|
16
|
+
}, d = h((e) => ({
|
|
17
17
|
inicializado: !1,
|
|
18
18
|
estado: {
|
|
19
19
|
inicializando: !0,
|
|
@@ -79,8 +79,8 @@ const O = "https://saas.chimera.com.pe/backend", E = "https://saas.chimera.com.p
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
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 = () => {
|
|
82
|
-
const e =
|
|
83
|
-
return /* @__PURE__ */
|
|
82
|
+
const e = b();
|
|
83
|
+
return /* @__PURE__ */ g(
|
|
84
84
|
"div",
|
|
85
85
|
{
|
|
86
86
|
style: {
|
|
@@ -102,9 +102,9 @@ const O = "https://saas.chimera.com.pe/backend", E = "https://saas.chimera.com.p
|
|
|
102
102
|
]
|
|
103
103
|
}
|
|
104
104
|
);
|
|
105
|
-
},
|
|
106
|
-
const i =
|
|
107
|
-
return /* @__PURE__ */
|
|
105
|
+
}, m = ({ titulo: e, texto: r }) => {
|
|
106
|
+
const i = b();
|
|
107
|
+
return /* @__PURE__ */ g(
|
|
108
108
|
"div",
|
|
109
109
|
{
|
|
110
110
|
style: {
|
|
@@ -131,16 +131,38 @@ const O = "https://saas.chimera.com.pe/backend", E = "https://saas.chimera.com.p
|
|
|
131
131
|
}
|
|
132
132
|
);
|
|
133
133
|
};
|
|
134
|
-
|
|
134
|
+
m.propTypes = {
|
|
135
135
|
titulo: o.string.isRequired,
|
|
136
136
|
texto: o.string
|
|
137
137
|
};
|
|
138
|
-
const
|
|
138
|
+
const _ = () => {
|
|
139
|
+
const {
|
|
140
|
+
loginInProgress: e,
|
|
141
|
+
token: r,
|
|
142
|
+
tokenData: i,
|
|
143
|
+
logIn: n,
|
|
144
|
+
logOut: t,
|
|
145
|
+
error: c
|
|
146
|
+
} = j(w);
|
|
147
|
+
return {
|
|
148
|
+
loginInProgress: e,
|
|
149
|
+
token: r,
|
|
150
|
+
logIn: n,
|
|
151
|
+
logOut: t,
|
|
152
|
+
error: c,
|
|
153
|
+
correo: i?.sub,
|
|
154
|
+
nombre: i?.name,
|
|
155
|
+
perfiles: i?.profiles
|
|
156
|
+
};
|
|
157
|
+
}, B = ({ children: e }) => {
|
|
158
|
+
const { error: r } = _();
|
|
159
|
+
return r ? /* @__PURE__ */ a(m, { titulo: "saas.error.login", texto: r }) : e;
|
|
160
|
+
}, v = ({ devAuthUrl: e, children: r }) => {
|
|
139
161
|
const i = d((n) => n.instancia);
|
|
140
162
|
if (i.requiereLogin) {
|
|
141
163
|
const n = e || E;
|
|
142
164
|
return /* @__PURE__ */ a(
|
|
143
|
-
|
|
165
|
+
C,
|
|
144
166
|
{
|
|
145
167
|
authConfig: {
|
|
146
168
|
clientId: i.identificador,
|
|
@@ -148,9 +170,10 @@ const v = ({ devAuthUrl: e, children: r }) => {
|
|
|
148
170
|
tokenEndpoint: `${n}/oauth2/token`,
|
|
149
171
|
logoutEndpoint: `${n}/connect/logout`,
|
|
150
172
|
redirectUri: i.redirectUri,
|
|
151
|
-
scope: "openid profile"
|
|
173
|
+
scope: "openid profile",
|
|
174
|
+
storage: "session"
|
|
152
175
|
},
|
|
153
|
-
children: r
|
|
176
|
+
children: /* @__PURE__ */ a(B, { children: r })
|
|
154
177
|
}
|
|
155
178
|
);
|
|
156
179
|
}
|
|
@@ -162,7 +185,7 @@ v.propTypes = {
|
|
|
162
185
|
};
|
|
163
186
|
const y = ({ aplicacion: e, devBackendUrl: r }) => {
|
|
164
187
|
const i = d((t) => t.estado), n = d((t) => t.inicializar);
|
|
165
|
-
return
|
|
188
|
+
return f(() => {
|
|
166
189
|
n(r, e);
|
|
167
190
|
}, [n, r, e]), /* @__PURE__ */ a(
|
|
168
191
|
"div",
|
|
@@ -176,7 +199,7 @@ const y = ({ aplicacion: e, devBackendUrl: r }) => {
|
|
|
176
199
|
backgroundColor: "#141316",
|
|
177
200
|
color: "#e6e1e6"
|
|
178
201
|
},
|
|
179
|
-
children: i.inicializando ? /* @__PURE__ */ a(S, {}) : i.error && /* @__PURE__ */ a(
|
|
202
|
+
children: i.inicializando ? /* @__PURE__ */ a(S, {}) : i.error && /* @__PURE__ */ a(m, { titulo: "saas.error.titulo", texto: i.error })
|
|
180
203
|
}
|
|
181
204
|
);
|
|
182
205
|
};
|
|
@@ -208,22 +231,24 @@ k.propTypes = {
|
|
|
208
231
|
devAuthUrl: o.string,
|
|
209
232
|
children: o.element.isRequired
|
|
210
233
|
};
|
|
211
|
-
const
|
|
234
|
+
const D = {
|
|
212
235
|
nombre: "English",
|
|
213
236
|
cargando: "Loading...",
|
|
214
237
|
error: {
|
|
215
|
-
titulo: "Could not initialize application"
|
|
238
|
+
titulo: "Could not initialize application",
|
|
239
|
+
login: "Could not login"
|
|
216
240
|
}
|
|
217
|
-
},
|
|
241
|
+
}, V = {
|
|
218
242
|
nombre: "Castellano",
|
|
219
243
|
cargando: "Cargando...",
|
|
220
244
|
error: {
|
|
221
|
-
titulo: "Error iniciando aplicación"
|
|
245
|
+
titulo: "Error iniciando aplicación",
|
|
246
|
+
login: "No se pudo iniciar sesión"
|
|
222
247
|
}
|
|
223
|
-
},
|
|
224
|
-
en:
|
|
225
|
-
es:
|
|
226
|
-
}, z =
|
|
248
|
+
}, p = {
|
|
249
|
+
en: D,
|
|
250
|
+
es: V
|
|
251
|
+
}, z = h((e) => ({
|
|
227
252
|
idiomasDisponibles: ["en", "es"],
|
|
228
253
|
idiomaActual: "en",
|
|
229
254
|
cambiarIdioma: (r) => {
|
|
@@ -231,23 +256,23 @@ const _ = {
|
|
|
231
256
|
idiomaActual: r
|
|
232
257
|
});
|
|
233
258
|
}
|
|
234
|
-
})),
|
|
259
|
+
})), x = ({ mensajes: e, children: r }) => {
|
|
235
260
|
const i = z((n) => n.idiomaActual);
|
|
236
|
-
return /* @__PURE__ */ a(
|
|
261
|
+
return /* @__PURE__ */ a(A, { locale: i, messages: e[i], children: r });
|
|
237
262
|
};
|
|
238
|
-
|
|
263
|
+
x.propTypes = {
|
|
239
264
|
mensajes: o.object,
|
|
240
265
|
children: o.element.isRequired
|
|
241
266
|
};
|
|
242
|
-
const
|
|
267
|
+
const N = () => {
|
|
243
268
|
const e = q();
|
|
244
269
|
if (!e?.length)
|
|
245
270
|
return;
|
|
246
271
|
const r = e[0];
|
|
247
272
|
return r.indexOf("-") ? r.substring(0, r.indexOf("-")) : r;
|
|
248
|
-
},
|
|
249
|
-
const n = z((s) => s.cambiarIdioma), t =
|
|
250
|
-
|
|
273
|
+
}, U = ({ mensajes: e, idiomaDefecto: r, children: i }) => {
|
|
274
|
+
const n = z((s) => s.cambiarIdioma), t = N(), c = I(Object.keys(e), Object.keys(p));
|
|
275
|
+
f(() => {
|
|
251
276
|
let s = c[0];
|
|
252
277
|
t && Object.hasOwn(e, t) ? s = t : r && Object.hasOwn(e, r) && (s = r), n(s);
|
|
253
278
|
}, [c, e, r, t, n]);
|
|
@@ -255,11 +280,11 @@ const D = () => {
|
|
|
255
280
|
return c.forEach((s) => {
|
|
256
281
|
l[s] = {
|
|
257
282
|
...Object.hasOwn(e, s) ? e[s] : {},
|
|
258
|
-
saas: Object.hasOwn(
|
|
283
|
+
saas: Object.hasOwn(p, s) ? p[s] : {}
|
|
259
284
|
};
|
|
260
|
-
}), /* @__PURE__ */ a(
|
|
285
|
+
}), /* @__PURE__ */ a(x, { mensajes: l, children: i });
|
|
261
286
|
};
|
|
262
|
-
|
|
287
|
+
U.propTypes = {
|
|
263
288
|
mensajes: o.object,
|
|
264
289
|
idiomaDefecto: o.string,
|
|
265
290
|
children: o.element.isRequired
|
|
@@ -275,7 +300,7 @@ const P = ({
|
|
|
275
300
|
es: {}
|
|
276
301
|
},
|
|
277
302
|
children: l
|
|
278
|
-
}) => /* @__PURE__ */ a(
|
|
303
|
+
}) => /* @__PURE__ */ a(U, { mensajes: c, children: /* @__PURE__ */ a(
|
|
279
304
|
k,
|
|
280
305
|
{
|
|
281
306
|
aplicacion: e,
|
|
@@ -294,29 +319,9 @@ P.propTypes = {
|
|
|
294
319
|
mensajes: o.object,
|
|
295
320
|
children: o.element.isRequired
|
|
296
321
|
};
|
|
297
|
-
const W = () => {
|
|
298
|
-
const {
|
|
299
|
-
loginInProgress: e,
|
|
300
|
-
token: r,
|
|
301
|
-
tokenData: i,
|
|
302
|
-
logIn: n,
|
|
303
|
-
logOut: t,
|
|
304
|
-
error: c
|
|
305
|
-
} = x(A);
|
|
306
|
-
return {
|
|
307
|
-
loginInProgress: e,
|
|
308
|
-
token: r,
|
|
309
|
-
logIn: n,
|
|
310
|
-
logOut: t,
|
|
311
|
-
error: c,
|
|
312
|
-
correo: i?.sub,
|
|
313
|
-
nombre: i?.name,
|
|
314
|
-
perfiles: i?.profiles
|
|
315
|
-
};
|
|
316
|
-
};
|
|
317
322
|
export {
|
|
318
323
|
P as SaasApp,
|
|
319
|
-
|
|
324
|
+
_ as useAuth,
|
|
320
325
|
z as useLangStore,
|
|
321
326
|
d as useSaasStore
|
|
322
327
|
};
|
package/dist/react-saas.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(s,
|
|
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"})}));
|