@service_laboratory/auth 0.0.3 → 0.0.4
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/forms.cjs.js +50 -0
- package/dist/forms.d.ts +5 -0
- package/dist/forms.es.js +1507 -0
- package/dist/index.cjs.js +1 -0
- package/package.json +13 -8
- package/dist/laboratory.umd.cjs +0 -1
- /package/dist/{laboratory.d.ts → index.d.ts} +0 -0
- /package/dist/{laboratory.js → index.es.js} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=new WeakMap,h=new WeakMap,p={current:[]};let d=!1;const u=new Set,_=new Map;function S(a){const e=Array.from(a).sort((t,s)=>t instanceof r&&t.options.deps.includes(s)?1:s instanceof r&&s.options.deps.includes(t)?-1:0);for(const t of e){if(p.current.includes(t))continue;p.current.push(t),t.recompute();const s=h.get(t);if(s)for(const i of s){const n=c.get(i);n&&S(n)}}}function D(a){a.listeners.forEach(e=>e({prevVal:a.prevState,currentVal:a.state}))}function V(a){a.listeners.forEach(e=>e({prevVal:a.prevState,currentVal:a.state}))}function m(a){if(u.add(a),!d)try{for(d=!0;u.size>0;){const e=Array.from(u);u.clear();for(const t of e){const s=_.get(t)??t.prevState;t.prevState=s,D(t)}for(const t of e){const s=c.get(t);s&&(p.current.push(t),S(s))}for(const t of e){const s=c.get(t);if(s)for(const i of s)V(i)}}}finally{d=!1,p.current=[],_.clear()}}function w(a){return typeof a=="function"}class v{constructor(e,t){this.listeners=new Set,this.subscribe=s=>{var i,n;this.listeners.add(s);const l=(n=(i=this.options)==null?void 0:i.onSubscribe)==null?void 0:n.call(i,s,this);return()=>{this.listeners.delete(s),l?.()}},this.prevState=e,this.state=e,this.options=t}setState(e){var t,s,i;this.prevState=this.state,(t=this.options)!=null&&t.updateFn?this.state=this.options.updateFn(this.prevState)(e):w(e)?this.state=e(this.prevState):this.state=e,(i=(s=this.options)==null?void 0:s.onUpdate)==null||i.call(s),m(this)}}class r{constructor(e){this.listeners=new Set,this._subscriptions=[],this.lastSeenDepValues=[],this.getDepVals=()=>{const t=[],s=[];for(const i of this.options.deps)t.push(i.prevState),s.push(i.state);return this.lastSeenDepValues=s,{prevDepVals:t,currDepVals:s,prevVal:this.prevState??void 0}},this.recompute=()=>{var t,s;this.prevState=this.state;const{prevDepVals:i,currDepVals:n,prevVal:l}=this.getDepVals();this.state=this.options.fn({prevDepVals:i,currDepVals:n,prevVal:l}),(s=(t=this.options).onUpdate)==null||s.call(t)},this.checkIfRecalculationNeededDeeply=()=>{for(const n of this.options.deps)n instanceof r&&n.checkIfRecalculationNeededDeeply();let t=!1;const s=this.lastSeenDepValues,{currDepVals:i}=this.getDepVals();for(let n=0;n<i.length;n++)if(i[n]!==s[n]){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 s,i;this.listeners.add(t);const n=(i=(s=this.options).onSubscribe)==null?void 0:i.call(s,t,this);return()=>{this.listeners.delete(t),n?.()}},this.options=e,this.state=e.fn({prevDepVals:void 0,prevVal:void 0,currDepVals:this.getDepVals().currDepVals})}registerOnGraph(e=this.options.deps){for(const t of e)if(t instanceof r)t.registerOnGraph(),this.registerOnGraph(t.options.deps);else if(t instanceof v){let s=c.get(t);s||(s=new Set,c.set(t,s)),s.add(this);let i=h.get(this);i||(i=new Set,h.set(this,i)),i.add(t)}}unregisterFromGraph(e=this.options.deps){for(const t of e)if(t instanceof r)this.unregisterFromGraph(t.options.deps);else if(t instanceof v){const s=c.get(t);s&&s.delete(this);const i=h.get(this);i&&i.delete(t)}}}const f="Authorization",g=()=>({user:{id:null,email:null,roles:[],is_enabled:!1,is_active:!1},isAuthenticated:!1,isLoaded:!1}),o=new v(g()),b=new r({fn:()=>!!o.state.user?.roles.find(a=>a.name==="admin"),deps:[o]});class A{accountStore;httpClient;constructor(e){this.httpClient=e,this.accountStore=o}initAuthData(){const e=localStorage.getItem("token");e&&(this.httpClient.defaults.headers.common[f]=e)}async load(){try{const{data:e}=await this.httpClient.get("/api/auth/account/me");o.setState(()=>({user:e,isAuthenticated:!0,isLoaded:!0}))}catch{o.setState(e=>({...e,isLoaded:!0}))}}async login(e){const t=await this.httpClient.post("/api/auth/account/login",e),{user:s,access_token:i}=t.data;return s.is_active&&this._initUserData({user:s,access_token:i}),s}register(e){return this.httpClient.post("/api/auth/account/register",e)}async activate(e){const t=await this.httpClient.post("/api/auth/account/activate",e);this._initUserData(t.data)}logout(){o.setState(()=>({...g(),isLoaded:!0})),this._clearAuthData()}startResetPassword(e){return this.httpClient.post("/api/auth/account/start-reset-password",e)}async resetPassword(e){const t=await this.httpClient.post("/api/auth/account/reset-password",e);this._initUserData(t.data)}_initUserData({user:e,access_token:t}){this._setAuthData(t),o.setState(()=>({user:e,isAuthenticated:!0,isLoaded:!0}))}_setAuthData(e){localStorage.setItem("token",e),this.httpClient.defaults.headers.common[f]=e}_clearAuthData(){localStorage.removeItem("token"),delete this.httpClient.defaults.headers.common[f]}}exports.Auth=A;exports.isAdmin=b;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@service_laboratory/auth",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"main": "./dist/
|
|
6
|
-
"module": "./dist/
|
|
5
|
+
"main": "./dist/index.umd.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
@@ -14,18 +14,23 @@
|
|
|
14
14
|
},
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
17
|
-
"types": "./dist/
|
|
18
|
-
"import": "./dist/
|
|
19
|
-
"require": "./dist/
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"require": "./dist/index.umd.cjs"
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@tanstack/store": "^0.7.4",
|
|
24
|
-
"axios": "^1.11.0"
|
|
24
|
+
"axios": "^1.11.0",
|
|
25
|
+
"react": "^19.1.1",
|
|
26
|
+
"react-dom": "^19.1.1"
|
|
25
27
|
},
|
|
26
28
|
"devDependencies": {
|
|
27
29
|
"typescript": "~5.8.3",
|
|
28
30
|
"vite": "^7.1.4",
|
|
29
|
-
"vite-plugin-dts": "^4.5.4"
|
|
31
|
+
"vite-plugin-dts": "^4.5.4",
|
|
32
|
+
"@types/node": "^24.5.2",
|
|
33
|
+
"@types/react": "^19.1.13",
|
|
34
|
+
"@vitejs/plugin-react": "^5.0.3"
|
|
30
35
|
}
|
|
31
36
|
}
|
package/dist/laboratory.umd.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(r,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(r=typeof globalThis<"u"?globalThis:r||self,a(r.laboratory={}))})(this,(function(r){"use strict";const a=new WeakMap,u=new WeakMap,h={current:[]};let f=!1;const p=new Set,S=new Map;function g(o){const e=Array.from(o).sort((t,s)=>t instanceof c&&t.options.deps.includes(s)?1:s instanceof c&&s.options.deps.includes(t)?-1:0);for(const t of e){if(h.current.includes(t))continue;h.current.push(t),t.recompute();const s=u.get(t);if(s)for(const i of s){const n=a.get(i);n&&g(n)}}}function m(o){o.listeners.forEach(e=>e({prevVal:o.prevState,currentVal:o.state}))}function V(o){o.listeners.forEach(e=>e({prevVal:o.prevState,currentVal:o.state}))}function b(o){if(p.add(o),!f)try{for(f=!0;p.size>0;){const e=Array.from(p);p.clear();for(const t of e){const s=S.get(t)??t.prevState;t.prevState=s,m(t)}for(const t of e){const s=a.get(t);s&&(h.current.push(t),g(s))}for(const t of e){const s=a.get(t);if(s)for(const i of s)V(i)}}}finally{f=!1,h.current=[],S.clear()}}function y(o){return typeof o=="function"}class v{constructor(e,t){this.listeners=new Set,this.subscribe=s=>{var i,n;this.listeners.add(s);const d=(n=(i=this.options)==null?void 0:i.onSubscribe)==null?void 0:n.call(i,s,this);return()=>{this.listeners.delete(s),d?.()}},this.prevState=e,this.state=e,this.options=t}setState(e){var t,s,i;this.prevState=this.state,(t=this.options)!=null&&t.updateFn?this.state=this.options.updateFn(this.prevState)(e):y(e)?this.state=e(this.prevState):this.state=e,(i=(s=this.options)==null?void 0:s.onUpdate)==null||i.call(s),b(this)}}class c{constructor(e){this.listeners=new Set,this._subscriptions=[],this.lastSeenDepValues=[],this.getDepVals=()=>{const t=[],s=[];for(const i of this.options.deps)t.push(i.prevState),s.push(i.state);return this.lastSeenDepValues=s,{prevDepVals:t,currDepVals:s,prevVal:this.prevState??void 0}},this.recompute=()=>{var t,s;this.prevState=this.state;const{prevDepVals:i,currDepVals:n,prevVal:d}=this.getDepVals();this.state=this.options.fn({prevDepVals:i,currDepVals:n,prevVal:d}),(s=(t=this.options).onUpdate)==null||s.call(t)},this.checkIfRecalculationNeededDeeply=()=>{for(const n of this.options.deps)n instanceof c&&n.checkIfRecalculationNeededDeeply();let t=!1;const s=this.lastSeenDepValues,{currDepVals:i}=this.getDepVals();for(let n=0;n<i.length;n++)if(i[n]!==s[n]){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 s,i;this.listeners.add(t);const n=(i=(s=this.options).onSubscribe)==null?void 0:i.call(s,t,this);return()=>{this.listeners.delete(t),n?.()}},this.options=e,this.state=e.fn({prevDepVals:void 0,prevVal:void 0,currDepVals:this.getDepVals().currDepVals})}registerOnGraph(e=this.options.deps){for(const t of e)if(t instanceof c)t.registerOnGraph(),this.registerOnGraph(t.options.deps);else if(t instanceof v){let s=a.get(t);s||(s=new Set,a.set(t,s)),s.add(this);let i=u.get(this);i||(i=new Set,u.set(this,i)),i.add(t)}}unregisterFromGraph(e=this.options.deps){for(const t of e)if(t instanceof c)this.unregisterFromGraph(t.options.deps);else if(t instanceof v){const s=a.get(t);s&&s.delete(this);const i=u.get(this);i&&i.delete(t)}}}const _="Authorization",D=()=>({user:{id:null,email:null,roles:[],is_enabled:!1,is_active:!1},isAuthenticated:!1,isLoaded:!1}),l=new v(D()),w=new c({fn:()=>!!l.state.user?.roles.find(o=>o.name==="admin"),deps:[l]});class A{accountStore;httpClient;constructor(e){this.httpClient=e,this.accountStore=l}initAuthData(){const e=localStorage.getItem("token");e&&(this.httpClient.defaults.headers.common[_]=e)}async load(){try{const{data:e}=await this.httpClient.get("/api/auth/account/me");l.setState(()=>({user:e,isAuthenticated:!0,isLoaded:!0}))}catch{l.setState(e=>({...e,isLoaded:!0}))}}async login(e){const t=await this.httpClient.post("/api/auth/account/login",e),{user:s,access_token:i}=t.data;return s.is_active&&this._initUserData({user:s,access_token:i}),s}register(e){return this.httpClient.post("/api/auth/account/register",e)}async activate(e){const t=await this.httpClient.post("/api/auth/account/activate",e);this._initUserData(t.data)}logout(){l.setState(()=>({...D(),isLoaded:!0})),this._clearAuthData()}startResetPassword(e){return this.httpClient.post("/api/auth/account/start-reset-password",e)}async resetPassword(e){const t=await this.httpClient.post("/api/auth/account/reset-password",e);this._initUserData(t.data)}_initUserData({user:e,access_token:t}){this._setAuthData(t),l.setState(()=>({user:e,isAuthenticated:!0,isLoaded:!0}))}_setAuthData(e){localStorage.setItem("token",e),this.httpClient.defaults.headers.common[_]=e}_clearAuthData(){localStorage.removeItem("token"),delete this.httpClient.defaults.headers.common[_]}}r.Auth=A,r.isAdmin=w,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})}));
|
|
File without changes
|
|
File without changes
|