@gandalan/weblibs 1.1.20 → 1.1.22

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,5 +1,5 @@
1
1
  {
2
2
  "editor.codeActionsOnSave": {
3
- "source.fixAll.eslint": true
3
+ "source.fixAll.eslint": "explicit"
4
4
  }
5
- }
5
+ }
package/api/authUtils.js CHANGED
@@ -1,11 +1,18 @@
1
1
  /* eslint-disable no-console */
2
2
  import { jwtDecode } from "jwt-decode";
3
+ import validator from "validator";
3
4
 
4
5
  export let currentToken = undefined;
5
6
  export let currentRefreshToken = undefined;
6
7
 
7
8
  export async function initIDAS(appToken)
8
9
  {
10
+ if (!validator.isUUID(appToken))
11
+ {
12
+ console.error("AppToken is not valid GUID");
13
+ return null;
14
+ }
15
+
9
16
  let jwtToken = "";
10
17
  let mandantGuid = "";
11
18
  let apiBaseurl = window.document.body.dataset.apiBaseUrl || "https://api.dev.idas-cloudservices.net/api/";
@@ -48,6 +55,7 @@ export async function initIDAS(appToken)
48
55
  {
49
56
  redirectToLogin(settings, "/");
50
57
  }
58
+
51
59
  return settings;
52
60
  }
53
61
 
@@ -64,7 +72,7 @@ export async function setup(settings)
64
72
  await tryRenew(settings);
65
73
  if (isInvalid(settings))
66
74
  {
67
- console.log("Refresh failed, invalid JWT token!");
75
+ console.error("Refresh failed, invalid JWT token!");
68
76
  }
69
77
  }
70
78
  else
@@ -85,6 +93,7 @@ export async function setup(settings)
85
93
  settings.mandantGuid = mandantGuid;
86
94
  }
87
95
  }
96
+
88
97
  console.log("Setup finished", settings);
89
98
  }
90
99
 
@@ -95,6 +104,7 @@ function startRefreshTimer(settings)
95
104
  {
96
105
  clearInterval(timerRef);
97
106
  }
107
+
98
108
  timerRef = setInterval(() =>
99
109
  {
100
110
  if (currentToken)
@@ -115,18 +125,20 @@ export function isInvalid(settings)
115
125
  {
116
126
  return true;
117
127
  }
128
+
118
129
  let decoded = jwtDecode(currentToken);
119
130
  const utcNow = Date.parse(new Date().toUTCString()) / 1000;
120
131
  if (decoded && decoded.exp > utcNow)
121
132
  {
122
133
  return false;
123
134
  }
135
+
124
136
  return true;
125
137
  }
126
138
 
127
139
  export async function tryRenew(settings)
128
140
  {
129
- console.log("try to refresh");
141
+ console.log("Try to refresh");
130
142
 
131
143
  const url = settings.authUrl || settings.apiBaseurl;
132
144
  const payload = { "Token": currentRefreshToken };
@@ -157,7 +169,7 @@ export async function tryRenew(settings)
157
169
 
158
170
  if (isInvalid(settings))
159
171
  {
160
- console.log("Token is already expired!");
172
+ console.warn("Token is already expired!");
161
173
  }
162
174
  }
163
175
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gandalan/weblibs",
3
- "version": "1.1.20",
3
+ "version": "1.1.22",
4
4
  "description": "WebLibs for Gandalan JS/TS/Svelte projects",
5
5
  "keywords": [
6
6
  "gandalan"
@@ -24,7 +24,8 @@
24
24
  "@mdi/js": "^7.4.47",
25
25
  "axios": "^1.6.5",
26
26
  "jwt-decode": "^4.0.0",
27
- "svelte-table": "^0.6.1"
27
+ "svelte-table": "^0.6.1",
28
+ "validator": "^13.11.0"
28
29
  },
29
30
  "devDependencies": {
30
31
  "@babel/eslint-parser": "^7.23.3",
@@ -32,7 +33,7 @@
32
33
  "eslint": "^8.56.0",
33
34
  "eslint-plugin-svelte": "^2.35.1",
34
35
  "svelte": "^4.2.8",
35
- "svelte-check": "^3.6.2",
36
+ "svelte-check": "^3.6.3",
36
37
  "svelte-chota": "^1.8.6"
37
38
  },
38
39
  "peerDependencies": {