@dashadmin/dash-auth 1.3.25 → 1.3.28
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/README.md +35 -1
- package/dist/index.cjs +473 -0
- package/dist/index.d.cts +41 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +340 -197
- package/package.json +50 -51
- package/dist/AuthPersistanceService.js +0 -1
package/package.json
CHANGED
|
@@ -1,52 +1,51 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
2
|
+
"name": "@dashadmin/dash-auth",
|
|
3
|
+
"version": "1.3.28",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
|
+
"devDependencies": {
|
|
7
|
+
"@commitlint/cli": "latest",
|
|
8
|
+
"@commitlint/config-conventional": "latest",
|
|
9
|
+
"@types/jest": "latest",
|
|
10
|
+
"@types/node": "latest",
|
|
11
|
+
"@types/react": "latest",
|
|
12
|
+
"@types/react-dom": "latest",
|
|
13
|
+
"@typescript-eslint/eslint-plugin": "latest",
|
|
14
|
+
"@typescript-eslint/parser": "latest",
|
|
15
|
+
"eslint-config-airbnb-typescript": "latest",
|
|
16
|
+
"eslint-config-prettier": "latest",
|
|
17
|
+
"eslint-plugin-html": "latest",
|
|
18
|
+
"eslint-plugin-import": "latest",
|
|
19
|
+
"eslint-plugin-jsdoc": "latest",
|
|
20
|
+
"eslint-plugin-json": "latest",
|
|
21
|
+
"eslint-plugin-prettier": "latest",
|
|
22
|
+
"ts-jest": "latest",
|
|
23
|
+
"ts-loader": "latest",
|
|
24
|
+
"tsconfig-paths": "latest",
|
|
25
|
+
"typescript": "latest"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@mui/material": "^7.3.10",
|
|
29
|
+
"@dashadmin/dash-utils": "workspace:*"
|
|
30
|
+
},
|
|
31
|
+
"module": "dist/index.js",
|
|
32
|
+
"types": "dist/index.d.ts",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"import": "./dist/index.js",
|
|
37
|
+
"require": "./dist/index.cjs"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public",
|
|
42
|
+
"registry": "https://registry.npmjs.org"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup"
|
|
46
|
+
},
|
|
47
|
+
"files": [
|
|
48
|
+
"dist"
|
|
49
|
+
],
|
|
50
|
+
"type": "module"
|
|
51
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var d=Object.defineProperty;var h=(a,e,t)=>e in a?d(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var l=(a,e,t)=>h(a,typeof e!="symbol"?e+"":e,t);import{dashStorage as r}from"@dashadmin/dash-utils";class c{static saveAuth(e){try{const t={auth:e.auth};e.auth?.tenantImages?r.setItem(this.TENANT_IMAGES_KEY,JSON.stringify(e.auth.tenantImages)):r.removeItem(this.TENANT_IMAGES_KEY),e.auth?.tenantSettings?r.setItem(this.TENANT_SETTINGS_KEY,JSON.stringify(e.auth.tenantSettings)):r.removeItem(this.TENANT_SETTINGS_KEY),e.systemValues&&r.setItem(this.SYSTEM_VALUES_KEY,JSON.stringify(e.systemValues));const s={...t};delete s._loggedOut,delete s._loggedOutAt,r.setItem(this.AUTH_KEY,JSON.stringify(s)),r.setItem(this.TIMESTAMP_KEY,Date.now().toString())}catch(t){console.error("Failed to save auth data:",t)}}static setAuth(e){try{e.token&&r.setItem("token",e.token),e.user&&r.setItem("user",JSON.stringify(e.user)),e.systemValues&&r.setItem(this.SYSTEM_VALUES_KEY,JSON.stringify(e.systemValues)),r.setItem("authenticated","true"),this.saveAuth({auth:{user:e.user,token:e.token,refreshToken:e.refreshToken},systemValues:e.systemValues}),console.log("Auth data set successfully")}catch(t){console.error("Failed to set auth data:",t)}}static getToken(){try{return r.getItem("token")}catch(e){return console.error("Failed to get token:",e),null}}static getUser(){try{const e=r.getItem("user");return e?JSON.parse(e):null}catch(e){return console.error("Failed to get user data:",e),null}}static getAuth(){try{const e=r.getItem(this.AUTH_KEY),t=r.getItem(this.TIMESTAMP_KEY);if(!e||!t)return null;const s=parseInt(t);if((Date.now()-s)/(1e3*60*60)>this.EXPIRY_HOURS)return this.clearAuth(),null;const i=JSON.parse(e);return i._loggedOut?(console.log("Auth data exists but user is marked as logged out"),null):i}catch(e){return console.error("Failed to retrieve auth data:",e),this.clearAuth(),null}}static markAsLoggedOut(){try{const e=r.getItem(this.AUTH_KEY);if(e){const s={...JSON.parse(e),_loggedOut:!0,_loggedOutAt:Date.now()};r.setItem(this.AUTH_KEY,JSON.stringify(s)),console.log("Auth data marked as logged out but preserved in localStorage")}r.removeItem("token"),r.setItem("authenticated","false"),r.removeItem("user")}catch(e){console.error("Failed to mark auth as logged out:",e)}}static getTenantImages(){try{const e=r.getItem(this.TENANT_IMAGES_KEY);return e?JSON.parse(e):null}catch(e){return console.error("Failed to get tenant images:",e),null}}static setTenantImages(e){try{r.setItem(this.TENANT_IMAGES_KEY,JSON.stringify(e))}catch(t){console.error("Failed to set tenant images:",t)}}static getTenantSettings(){try{const e=r.getItem(this.TENANT_SETTINGS_KEY);return e?JSON.parse(e):null}catch(e){return console.error("Failed to get tenant settings:",e),null}}static setTenantSettings(e){try{r.setItem(this.TENANT_SETTINGS_KEY,JSON.stringify(e))}catch(t){console.error("Failed to set tenant settings:",t)}}static clearTenantSettings(){try{r.removeItem(this.TENANT_SETTINGS_KEY)}catch(e){console.error("Failed to clear tenant settings:",e)}}static clearTenantImages(){try{r.removeItem(this.TENANT_IMAGES_KEY)}catch(e){console.error("Failed to clear tenant images:",e)}}static getSystemValues(){try{const e=r.getItem(this.SYSTEM_VALUES_KEY);return e?JSON.parse(e):null}catch(e){return console.error("Failed to get system values:",e),null}}static setSystemValues(e){try{r.setItem(this.SYSTEM_VALUES_KEY,JSON.stringify(e))}catch(t){console.error("Failed to set system values:",t)}}static getSystemValue(e){try{const t=this.getSystemValues();return t?t[e]:null}catch(t){return console.error(`Failed to get system value for key '${e}':`,t),null}}static getPointOfSales(){return this.getSystemValue("point_of_sales")}static clearAuth(){r.removeItem(this.AUTH_KEY),r.removeItem(this.TIMESTAMP_KEY),r.removeItem("token"),r.removeItem("user"),r.setItem("authenticated","false")}static clearAllAuthData(){r.removeItem(this.AUTH_KEY),r.removeItem(this.TIMESTAMP_KEY),r.removeItem(this.TENANT_IMAGES_KEY),r.removeItem(this.TENANT_SETTINGS_KEY),r.removeItem(this.SYSTEM_VALUES_KEY),r.removeItem("token"),r.removeItem("user"),r.setItem("authenticated","false")}static getStoredAuthData(){try{const e=r.getItem("token"),t=r.getItem("user"),s=r.getItem(this.SYSTEM_VALUES_KEY),o=r.getItem(this.AUTH_KEY),n=r.getItem(this.TENANT_IMAGES_KEY),i=r.getItem(this.TENANT_SETTINGS_KEY),u=t?JSON.parse(t):null,g=s?JSON.parse(s):null,S=o?JSON.parse(o):null,y=n?JSON.parse(n):null,m=i?JSON.parse(i):null;return{token:e,user:u,systemValues:g,auth:S?.auth||null,tenantImages:y,tenantSettings:m}}catch(e){return console.error("Failed to get stored auth data:",e),null}}static isAuthValid(){return this.getAuth()!==null}static getPermissions(){try{const e=r.getItem("roles");if(e==="guest")return Promise.resolve("guest");const t=this.getAuth();if(t?.auth?.user?.roles){const s={roles:t.auth.user.roles.map(o=>typeof o=="string"?o:o.name)};return Promise.resolve(s)}if(e)try{const s=JSON.parse(e),o={roles:Array.isArray(s)?s.map(n=>typeof n=="string"?n:n.name):[s]};return Promise.resolve(o)}catch(s){return console.error("Failed to parse roles from localStorage:",s),Promise.resolve("null")}return Promise.resolve("null")}catch(e){return console.error("Failed to get permissions:",e),Promise.resolve("null")}}}l(c,"AUTH_KEY","dashAuth"),l(c,"TIMESTAMP_KEY","dashAuthTimestamp"),l(c,"TENANT_IMAGES_KEY","dashTenantImages"),l(c,"TENANT_SETTINGS_KEY","dashTenantSettings"),l(c,"SYSTEM_VALUES_KEY","dashSystemValues"),l(c,"EXPIRY_HOURS",24);async function I(){const a=window.electronStore;if(a&&a.getAll)try{const t=await a.getAll();if(t&&typeof t=="object"){for(const[s,o]of Object.entries(t))window.localStorage.setItem(s,JSON.stringify(o));console.log("[ElectronStorageSync] Synced electron-store to localStorage")}return}catch(t){console.error("[ElectronStorageSync] Failed to sync:",t)}const e=window?.Capacitor?.Plugins?.Preferences||window?.Capacitor?.Preferences;if(e&&e.keys&&e.get)try{const{keys:t}=await e.keys();for(const s of t){const{value:o}=await e.get({key:s});o!==null&&window.localStorage.setItem(s,o)}console.log("[CapacitorStorageSync] Synced Preferences to localStorage")}catch(t){console.error("[CapacitorStorageSync] Failed to sync:",t)}}async function f(){const a=window.electronStore;if(a&&a.set)try{for(let t=0;t<window.localStorage.length;t++){const s=window.localStorage.key(t);if(!s)continue;const o=window.localStorage.getItem(s);try{await a.set(s,JSON.parse(o))}catch{await a.set(s,o)}}console.log("[ElectronStorageSync] Synced localStorage to electron-store");return}catch(t){console.error("[ElectronStorageSync] Failed to sync:",t)}const e=window?.Capacitor?.Plugins?.Preferences||window?.Capacitor?.Preferences;if(e&&e.set)try{for(let t=0;t<window.localStorage.length;t++){const s=window.localStorage.key(t);if(!s)continue;const o=window.localStorage.getItem(s);o!==null&&await e.set({key:s,value:o})}console.log("[CapacitorStorageSync] Synced localStorage to Preferences")}catch(t){console.error("[CapacitorStorageSync] Failed to sync:",t)}}async function A(){const a=["token","user","authenticated","roles","dashAuth","dashAuthTimestamp","dashSystemValues","socketConnectionState","SerializedAuthContext","tenant_id","user_id"],e=window.electronStore;if(e&&e.delete&&e.getAll)try{for(const s of a)await e.delete(s);await e.set("authenticated",!1),console.log("[ElectronStorageSync] Cleared auth data from electron-store");return}catch(s){console.error("[ElectronStorageSync] Failed to clear auth:",s)}const t=window?.Capacitor?.Plugins?.Preferences||window?.Capacitor?.Preferences;if(t&&t.remove)try{for(const s of a)await t.remove({key:s});await t.set({key:"authenticated",value:"false"}),console.log("[CapacitorStorageSync] Cleared auth data from Preferences")}catch(s){console.error("[CapacitorStorageSync] Failed to clear auth:",s)}}export{c as AuthPersistenceService,A as clearDeviceStoreAuth,I as syncDeviceStoreToLocalStorage,f as syncLocalStorageToDeviceStore};
|