@service_laboratory/auth 2.0.9 → 2.0.10

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/index.js CHANGED
@@ -4659,7 +4659,7 @@ function ln(e) {
4659
4659
  }
4660
4660
  )
4661
4661
  ] }),
4662
- /* @__PURE__ */ C.jsx(wo, { type: "submit", className: "w-full", children: e.submitButtonLabel })
4662
+ /* @__PURE__ */ C.jsx(wo, { type: "submit", className: "w-full cursor-pointer", children: e.submitButtonLabel })
4663
4663
  ] }) }) }) })
4664
4664
  ] }) });
4665
4665
  }
@@ -106,4 +106,4 @@ See https://react.dev/link/invalid-hook-call for tips about how to debug and fix
106
106
  *
107
107
  * This source code is licensed under the ISC license.
108
108
  * See the LICENSE file in the root directory of this source tree.
109
- */const Xo=rr("eye",[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);function Jo(e){const[r,t]=O.useState(!1);return T.jsx("div",{className:"flex flex-col gap-6",children:T.jsxs(_o,{children:[T.jsxs(wo,{children:[T.jsx(ko,{className:"text-2xl",children:e.loginFormTitle}),T.jsx(Oo,{children:e.loginFormDescription})]}),T.jsx(So,{children:T.jsx(Go,{...e.form,children:T.jsx("form",{onSubmit:e.form.handleSubmit(e.submit),children:T.jsxs("div",{className:"flex flex-col gap-6",children:[T.jsxs("div",{className:"grid gap-2",children:[T.jsx(Wt,{htmlFor:"email",children:e.emailLabel}),T.jsx(qt,{control:e.form.control,name:"email",render:({field:o})=>T.jsx(Jt,{children:T.jsx(Zt,{children:T.jsx(Qt,{id:"email",type:"email",placeholder:"m@example.com",required:!0,...o})})})})]}),T.jsxs("div",{className:"grid gap-2",children:[T.jsxs("div",{className:"flex items-center",children:[T.jsx(Wt,{htmlFor:"password",children:e.passwordLabel}),e.resetPasswordLinkComponent?e.resetPasswordLinkComponent():null]}),T.jsx(qt,{control:e.form.control,name:"password",render:({field:o})=>T.jsx(Jt,{children:T.jsx(Zt,{className:"relative",children:T.jsxs("div",{className:"relative",children:[r?T.jsx(qo,{className:"absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-500 z-10 cursor-pointer",onClick:()=>{t(!1)}}):T.jsx(Xo,{className:"absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-500 z-10 cursor-pointer",onClick:()=>{t(!0)}}),T.jsx(Qt,{type:r?"text":"password",placeholder:"********",...o,className:"pr-10"})]})})})})]}),T.jsx(xo,{type:"submit",className:"w-full",children:e.submitButtonLabel})]})})})})]})})}const me=new WeakMap,je=new WeakMap,Te={current:[]};let Ke=!1;const Ae=new Set,or=new Map;function nr(e){const r=Array.from(e).sort((t,o)=>t instanceof le&&t.options.deps.includes(o)?1:o instanceof le&&o.options.deps.includes(t)?-1:0);for(const t of r){if(Te.current.includes(t))continue;Te.current.push(t),t.recompute();const o=je.get(t);if(o)for(const n of o){const s=me.get(n);s&&nr(s)}}}function Zo(e){e.listeners.forEach(r=>r({prevVal:e.prevState,currentVal:e.state}))}function Qo(e){e.listeners.forEach(r=>r({prevVal:e.prevState,currentVal:e.state}))}function en(e){if(Ae.add(e),!Ke)try{for(Ke=!0;Ae.size>0;){const r=Array.from(Ae);Ae.clear();for(const t of r){const o=or.get(t)??t.prevState;t.prevState=o,Zo(t)}for(const t of r){const o=me.get(t);o&&(Te.current.push(t),nr(o))}for(const t of r){const o=me.get(t);if(o)for(const n of o)Qo(n)}}}finally{Ke=!1,Te.current=[],or.clear()}}function tn(e){return typeof e=="function"}class qe{constructor(r,t){this.listeners=new Set,this.subscribe=o=>{var n,s;this.listeners.add(o);const d=(s=(n=this.options)==null?void 0:n.onSubscribe)==null?void 0:s.call(n,o,this);return()=>{this.listeners.delete(o),d?.()}},this.prevState=r,this.state=r,this.options=t}setState(r){var t,o,n;this.prevState=this.state,(t=this.options)!=null&&t.updateFn?this.state=this.options.updateFn(this.prevState)(r):tn(r)?this.state=r(this.prevState):this.state=r,(n=(o=this.options)==null?void 0:o.onUpdate)==null||n.call(o),en(this)}}class le{constructor(r){this.listeners=new Set,this._subscriptions=[],this.lastSeenDepValues=[],this.getDepVals=()=>{const t=[],o=[];for(const n of this.options.deps)t.push(n.prevState),o.push(n.state);return this.lastSeenDepValues=o,{prevDepVals:t,currDepVals:o,prevVal:this.prevState??void 0}},this.recompute=()=>{var t,o;this.prevState=this.state;const{prevDepVals:n,currDepVals:s,prevVal:d}=this.getDepVals();this.state=this.options.fn({prevDepVals:n,currDepVals:s,prevVal:d}),(o=(t=this.options).onUpdate)==null||o.call(t)},this.checkIfRecalculationNeededDeeply=()=>{for(const s of this.options.deps)s instanceof le&&s.checkIfRecalculationNeededDeeply();let t=!1;const o=this.lastSeenDepValues,{currDepVals:n}=this.getDepVals();for(let s=0;s<n.length;s++)if(n[s]!==o[s]){t=!0;break}t&&this.recompute()},this.mount=()=>(this.registerOnGraph(),this.checkIfRecalculationNeededDeeply(),()=>{this.unregisterFromGraph();for(const t of this._subscriptions)t()}),this.subscribe=t=>{var o,n;this.listeners.add(t);const s=(n=(o=this.options).onSubscribe)==null?void 0:n.call(o,t,this);return()=>{this.listeners.delete(t),s?.()}},this.options=r,this.state=r.fn({prevDepVals:void 0,prevVal:void 0,currDepVals:this.getDepVals().currDepVals})}registerOnGraph(r=this.options.deps){for(const t of r)if(t instanceof le)t.registerOnGraph(),this.registerOnGraph(t.options.deps);else if(t instanceof qe){let o=me.get(t);o||(o=new Set,me.set(t,o)),o.add(this);let n=je.get(this);n||(n=new Set,je.set(this,n)),n.add(t)}}unregisterFromGraph(r=this.options.deps){for(const t of r)if(t instanceof le)this.unregisterFromGraph(t.options.deps);else if(t instanceof qe){const o=me.get(t);o&&o.delete(this);const n=je.get(this);n&&n.delete(t)}}}const Xe="Authorization",sr=()=>({user:{id:null,email:null,roles:[],is_enabled:!1,is_email_verified:!1},sessionID:null,isAuthenticated:!1,isLoaded:!1}),ce=new qe(sr()),rn=new le({fn:()=>!!ce.state.user?.roles.find(e=>e.name==="admin"),deps:[ce]});class on{accountStore;httpClient;constructor(r){this.httpClient=r,this.accountStore=ce}initAuthData(){const r=localStorage.getItem("token");r&&(this.httpClient.defaults.headers.common[Xe]=r)}async load(){try{const{data:r}=await this.httpClient.get("/api/auth/account/me");ce.setState(()=>({user:r.user,sessionID:r.session_id,isAuthenticated:!0,isLoaded:!0}))}catch{ce.setState(r=>({...r,isLoaded:!0}))}}async login(r){const t=await this.httpClient.post("/api/auth/account/login",r),{user:o,token:n,session_id:s}=t.data;return this._initUserData({user:o,token:n,sessionID:s}),o}register(r){return this.httpClient.post("/api/auth/account/register",r)}async activate(r){const t=await this.httpClient.post("/api/auth/account/activate",r);this._initUserData(t.data)}logout(){ce.setState(()=>({...sr(),isLoaded:!0})),this._clearAuthData()}startResetPassword(r){return this.httpClient.post("/api/auth/account/start-reset-password",r)}async resetPassword(r){const t=await this.httpClient.post("/api/auth/account/reset-password",r);this._initUserData(t.data)}_initUserData({user:r,token:t,sessionID:o}){this._setAuthData(t),ce.setState(()=>({user:r,isAuthenticated:!0,isLoaded:!0,sessionID:o}))}_setAuthData(r){localStorage.setItem("token",r),this.httpClient.defaults.headers.common[Xe]=r}_clearAuthData(){localStorage.removeItem("token"),delete this.httpClient.defaults.headers.common[Xe]}}te.Auth=on,te.LoginForm=Jo,te.isAdmin=rn,Object.defineProperty(te,Symbol.toStringTag,{value:"Module"})}));
109
+ */const Xo=rr("eye",[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);function Jo(e){const[r,t]=O.useState(!1);return T.jsx("div",{className:"flex flex-col gap-6",children:T.jsxs(_o,{children:[T.jsxs(wo,{children:[T.jsx(ko,{className:"text-2xl",children:e.loginFormTitle}),T.jsx(Oo,{children:e.loginFormDescription})]}),T.jsx(So,{children:T.jsx(Go,{...e.form,children:T.jsx("form",{onSubmit:e.form.handleSubmit(e.submit),children:T.jsxs("div",{className:"flex flex-col gap-6",children:[T.jsxs("div",{className:"grid gap-2",children:[T.jsx(Wt,{htmlFor:"email",children:e.emailLabel}),T.jsx(qt,{control:e.form.control,name:"email",render:({field:o})=>T.jsx(Jt,{children:T.jsx(Zt,{children:T.jsx(Qt,{id:"email",type:"email",placeholder:"m@example.com",required:!0,...o})})})})]}),T.jsxs("div",{className:"grid gap-2",children:[T.jsxs("div",{className:"flex items-center",children:[T.jsx(Wt,{htmlFor:"password",children:e.passwordLabel}),e.resetPasswordLinkComponent?e.resetPasswordLinkComponent():null]}),T.jsx(qt,{control:e.form.control,name:"password",render:({field:o})=>T.jsx(Jt,{children:T.jsx(Zt,{className:"relative",children:T.jsxs("div",{className:"relative",children:[r?T.jsx(qo,{className:"absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-500 z-10 cursor-pointer",onClick:()=>{t(!1)}}):T.jsx(Xo,{className:"absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-500 z-10 cursor-pointer",onClick:()=>{t(!0)}}),T.jsx(Qt,{type:r?"text":"password",placeholder:"********",...o,className:"pr-10"})]})})})})]}),T.jsx(xo,{type:"submit",className:"w-full cursor-pointer",children:e.submitButtonLabel})]})})})})]})})}const me=new WeakMap,je=new WeakMap,Te={current:[]};let Ke=!1;const Ae=new Set,or=new Map;function nr(e){const r=Array.from(e).sort((t,o)=>t instanceof le&&t.options.deps.includes(o)?1:o instanceof le&&o.options.deps.includes(t)?-1:0);for(const t of r){if(Te.current.includes(t))continue;Te.current.push(t),t.recompute();const o=je.get(t);if(o)for(const n of o){const s=me.get(n);s&&nr(s)}}}function Zo(e){e.listeners.forEach(r=>r({prevVal:e.prevState,currentVal:e.state}))}function Qo(e){e.listeners.forEach(r=>r({prevVal:e.prevState,currentVal:e.state}))}function en(e){if(Ae.add(e),!Ke)try{for(Ke=!0;Ae.size>0;){const r=Array.from(Ae);Ae.clear();for(const t of r){const o=or.get(t)??t.prevState;t.prevState=o,Zo(t)}for(const t of r){const o=me.get(t);o&&(Te.current.push(t),nr(o))}for(const t of r){const o=me.get(t);if(o)for(const n of o)Qo(n)}}}finally{Ke=!1,Te.current=[],or.clear()}}function tn(e){return typeof e=="function"}class qe{constructor(r,t){this.listeners=new Set,this.subscribe=o=>{var n,s;this.listeners.add(o);const d=(s=(n=this.options)==null?void 0:n.onSubscribe)==null?void 0:s.call(n,o,this);return()=>{this.listeners.delete(o),d?.()}},this.prevState=r,this.state=r,this.options=t}setState(r){var t,o,n;this.prevState=this.state,(t=this.options)!=null&&t.updateFn?this.state=this.options.updateFn(this.prevState)(r):tn(r)?this.state=r(this.prevState):this.state=r,(n=(o=this.options)==null?void 0:o.onUpdate)==null||n.call(o),en(this)}}class le{constructor(r){this.listeners=new Set,this._subscriptions=[],this.lastSeenDepValues=[],this.getDepVals=()=>{const t=[],o=[];for(const n of this.options.deps)t.push(n.prevState),o.push(n.state);return this.lastSeenDepValues=o,{prevDepVals:t,currDepVals:o,prevVal:this.prevState??void 0}},this.recompute=()=>{var t,o;this.prevState=this.state;const{prevDepVals:n,currDepVals:s,prevVal:d}=this.getDepVals();this.state=this.options.fn({prevDepVals:n,currDepVals:s,prevVal:d}),(o=(t=this.options).onUpdate)==null||o.call(t)},this.checkIfRecalculationNeededDeeply=()=>{for(const s of this.options.deps)s instanceof le&&s.checkIfRecalculationNeededDeeply();let t=!1;const o=this.lastSeenDepValues,{currDepVals:n}=this.getDepVals();for(let s=0;s<n.length;s++)if(n[s]!==o[s]){t=!0;break}t&&this.recompute()},this.mount=()=>(this.registerOnGraph(),this.checkIfRecalculationNeededDeeply(),()=>{this.unregisterFromGraph();for(const t of this._subscriptions)t()}),this.subscribe=t=>{var o,n;this.listeners.add(t);const s=(n=(o=this.options).onSubscribe)==null?void 0:n.call(o,t,this);return()=>{this.listeners.delete(t),s?.()}},this.options=r,this.state=r.fn({prevDepVals:void 0,prevVal:void 0,currDepVals:this.getDepVals().currDepVals})}registerOnGraph(r=this.options.deps){for(const t of r)if(t instanceof le)t.registerOnGraph(),this.registerOnGraph(t.options.deps);else if(t instanceof qe){let o=me.get(t);o||(o=new Set,me.set(t,o)),o.add(this);let n=je.get(this);n||(n=new Set,je.set(this,n)),n.add(t)}}unregisterFromGraph(r=this.options.deps){for(const t of r)if(t instanceof le)this.unregisterFromGraph(t.options.deps);else if(t instanceof qe){const o=me.get(t);o&&o.delete(this);const n=je.get(this);n&&n.delete(t)}}}const Xe="Authorization",sr=()=>({user:{id:null,email:null,roles:[],is_enabled:!1,is_email_verified:!1},sessionID:null,isAuthenticated:!1,isLoaded:!1}),ce=new qe(sr()),rn=new le({fn:()=>!!ce.state.user?.roles.find(e=>e.name==="admin"),deps:[ce]});class on{accountStore;httpClient;constructor(r){this.httpClient=r,this.accountStore=ce}initAuthData(){const r=localStorage.getItem("token");r&&(this.httpClient.defaults.headers.common[Xe]=r)}async load(){try{const{data:r}=await this.httpClient.get("/api/auth/account/me");ce.setState(()=>({user:r.user,sessionID:r.session_id,isAuthenticated:!0,isLoaded:!0}))}catch{ce.setState(r=>({...r,isLoaded:!0}))}}async login(r){const t=await this.httpClient.post("/api/auth/account/login",r),{user:o,token:n,session_id:s}=t.data;return this._initUserData({user:o,token:n,sessionID:s}),o}register(r){return this.httpClient.post("/api/auth/account/register",r)}async activate(r){const t=await this.httpClient.post("/api/auth/account/activate",r);this._initUserData(t.data)}logout(){ce.setState(()=>({...sr(),isLoaded:!0})),this._clearAuthData()}startResetPassword(r){return this.httpClient.post("/api/auth/account/start-reset-password",r)}async resetPassword(r){const t=await this.httpClient.post("/api/auth/account/reset-password",r);this._initUserData(t.data)}_initUserData({user:r,token:t,sessionID:o}){this._setAuthData(t),ce.setState(()=>({user:r,isAuthenticated:!0,isLoaded:!0,sessionID:o}))}_setAuthData(r){localStorage.setItem("token",r),this.httpClient.defaults.headers.common[Xe]=r}_clearAuthData(){localStorage.removeItem("token"),delete this.httpClient.defaults.headers.common[Xe]}}te.Auth=on,te.LoginForm=Jo,te.isAdmin=rn,Object.defineProperty(te,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@service_laboratory/auth",
3
- "version": "2.0.9",
3
+ "version": "2.0.10",
4
4
  "type": "module",
5
5
  "main": "./dist/index.umd.cjs",
6
6
  "module": "./dist/index.js",