@gandalan/weblibs 1.1.4 → 1.1.9

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/api/IDAS.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { isInvalid, currentToken} from "./authUtils";
2
2
  import { RESTClient } from "./RESTClient";
3
- import jwt_decode from "jwt-decode";
3
+ import { jwtDecode } from "jwt-decode";
4
4
 
5
5
  export function IDASFactory(settings)
6
6
  {
@@ -37,7 +37,7 @@ class IDAS
37
37
  return [];
38
38
  }
39
39
 
40
- const decoded = jwt_decode(currentToken);
40
+ const decoded = jwtDecode(currentToken);
41
41
  return decoded.rights;
42
42
  },
43
43
  getRoles()
@@ -47,7 +47,7 @@ class IDAS
47
47
  return [];
48
48
  }
49
49
 
50
- const decoded = jwt_decode(currentToken);
50
+ const decoded = jwtDecode(currentToken);
51
51
  return decoded.role;
52
52
  },
53
53
  hasRight(code)
@@ -65,7 +65,7 @@ class IDAS
65
65
  return undefined;
66
66
  }
67
67
 
68
- const decoded = jwt_decode(currentToken);
68
+ const decoded = jwtDecode(currentToken);
69
69
  return decoded.id;
70
70
  },
71
71
  };
package/api/RESTClient.js CHANGED
@@ -8,7 +8,7 @@ export class RESTClient
8
8
  axiosInstance = null;
9
9
 
10
10
  constructor(settings)
11
- {
11
+ {
12
12
  this.settings = settings;
13
13
 
14
14
  this.axiosInstance = axios.create({
@@ -39,32 +39,34 @@ export class RESTClient
39
39
  }*/
40
40
 
41
41
  getUrlOptions()
42
- {
42
+ {
43
43
  return { withCredentials: false };
44
44
  }
45
45
 
46
46
  async get(uri)
47
- {
47
+ {
48
48
  try
49
- {
49
+ {
50
+ this.axiosInstance = this.getNewAxiosInstance();
50
51
  const response = await this.axiosInstance.get(uri, this.getUrlOptions());
51
52
  this.lastError = "";
52
53
  return response.data;
53
54
  }
54
55
  catch (error)
55
- {
56
+ {
56
57
  this.handleError(error);
57
58
  }
58
59
  }
59
60
 
60
61
  async getFile(uri)
61
- {
62
+ {
62
63
  try
63
- {
64
+ {
65
+ this.axiosInstance = this.getNewAxiosInstance();
64
66
  const response = await this.axiosInstance.get(uri, { responseType: "blob" });
65
67
  let fileName = "1000.pdf";
66
68
  if (response.headers["content-disposition"])
67
- {
69
+ {
68
70
  fileName = response.headers["content-disposition"].split(";")[1];
69
71
  fileName = fileName.replace("filename=", "").trim();
70
72
  }
@@ -72,79 +74,105 @@ export class RESTClient
72
74
  return { data: response.data, filename: fileName, contentType: "application/pdf" };
73
75
  }
74
76
  catch (error)
75
- {
77
+ {
76
78
  this.handleError(error);
77
79
  }
78
80
  }
79
81
 
80
82
  async getRaw(uri)
81
- {
83
+ {
82
84
  let response = {};
83
85
  try
84
- {
86
+ {
87
+ this.axiosInstance = this.getNewAxiosInstance();
85
88
  response = await this.axiosInstance.get(uri, this.getUrlOptions())
86
89
  this.lastError = "";
87
90
  }
88
91
  catch (error)
89
- {
92
+ {
90
93
  this.handleError(error);
91
94
  }
92
95
  return response;
93
96
  }
94
97
 
95
98
  async post(uri, formData)
96
- {
99
+ {
97
100
  try
98
- {
101
+ {
102
+ this.axiosInstance = this.getNewAxiosInstance();
99
103
  const response = await this.axiosInstance.post(uri, formData, this.getUrlOptions());
100
104
  this.lastError = "";
101
105
  return response;
102
106
  }
103
107
  catch (error)
104
- {
108
+ {
105
109
  this.handleError(error);
106
110
  }
107
111
  }
108
112
 
109
113
  async put(uri, formData)
110
- {
114
+ {
111
115
  try
112
- {
116
+ {
117
+ this.axiosInstance = this.getNewAxiosInstance();
113
118
  const response = await this.axiosInstance.put(uri, formData, this.getUrlOptions());
114
119
  this.lastError = "";
115
120
  return response;
116
121
  }
117
122
  catch (error)
118
- {
123
+ {
119
124
  this.handleError(error);
120
125
  }
121
126
  }
122
127
 
123
128
  async delete(uri)
124
- {
129
+ {
125
130
  try
126
- {
131
+ {
132
+ this.axiosInstance = this.getNewAxiosInstance();
127
133
  const response = await this.axiosInstance.delete(uri, this.getUrlOptions());
128
134
  this.lastError = "";
129
135
  return response;
130
136
  }
131
137
  catch (error)
132
- {
138
+ {
133
139
  this.handleError(error);
134
140
  }
135
141
  }
136
142
 
137
- // eslint-disable-next-line no-unused-vars
138
- onError = (error, message) =>
139
- { };
143
+ getNewAxiosInstance()
144
+ {
145
+ return axios.create({
146
+ baseURL: this.settings.apiBaseurl,
147
+ headers: {
148
+ "Authorization": `Bearer ${currentToken}`,
149
+ },
150
+ });
151
+ }
140
152
 
141
153
  handleError(error)
142
- {
143
- let message = error ? error.message : "?";
144
- // eslint-disable-next-line no-console
145
- console.error(`API Error: ${message}`);
146
- this.lastError = message;
147
- this.onError(error, message);
148
- throw error;
154
+ {
155
+ if (error.response)
156
+ {
157
+ // The request was made and the server responded with a status code
158
+ // that falls out of the range of 2xx
159
+ console.log(error.response.data);
160
+ console.log(error.response.status);
161
+ console.log(error.response.headers);
162
+ }
163
+ else if (error.request)
164
+ {
165
+ // The request was made but no response was received
166
+ // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
167
+ // http.ClientRequest in node.js
168
+ console.log(error.request);
169
+ }
170
+ else
171
+ {
172
+ // Something happened in setting up the request that triggered an Error
173
+ console.log("Error", error.message);
174
+ }
175
+ console.log(error.config);
176
+ this.lastError = error;
149
177
  }
150
178
  }
package/api/authUtils.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-console */
2
- import jwt_decode from "jwt-decode";
2
+ import { jwtDecode } from "jwt-decode";
3
3
 
4
4
  export let currentToken = undefined;
5
5
  export let currentRefreshToken = undefined;
@@ -70,7 +70,7 @@ export async function setup(settings)
70
70
  else
71
71
  {
72
72
  console.log("Settings already have a valid JWT token, nothing to do");
73
- let decoded = jwt_decode(currentToken);
73
+ let decoded = jwtDecode(currentToken);
74
74
  let refreshToken = decoded["refreshToken"] || "";
75
75
  if (refreshToken)
76
76
  {
@@ -99,7 +99,7 @@ function startRefreshTimer(settings)
99
99
  {
100
100
  if (currentToken)
101
101
  {
102
- let decoded = jwt_decode(currentToken);
102
+ let decoded = jwtDecode(currentToken);
103
103
  const utcNow = Date.parse(new Date().toUTCString()) / 1000;
104
104
  if (decoded && utcNow > decoded.exp - 120)
105
105
  {
@@ -115,7 +115,7 @@ export function isInvalid(settings)
115
115
  {
116
116
  return true;
117
117
  }
118
- let decoded = jwt_decode(currentToken);
118
+ let decoded = jwtDecode(currentToken);
119
119
  const utcNow = Date.parse(new Date().toUTCString()) / 1000;
120
120
  if (decoded && decoded.exp > utcNow)
121
121
  {
@@ -139,7 +139,7 @@ export async function tryRenew(settings)
139
139
  currentToken = token;
140
140
  //console.log("Got JWT token:", currentToken);
141
141
 
142
- let decoded = jwt_decode(currentToken);
142
+ let decoded = jwtDecode(currentToken);
143
143
  let refreshToken = decoded["refreshToken"] || "";
144
144
  if (refreshToken)
145
145
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gandalan/weblibs",
3
- "version": "1.1.4",
3
+ "version": "1.1.9",
4
4
  "description": "WebLibs for Gandalan JS/TS/Svelte projects",
5
5
  "keywords": [
6
6
  "gandalan"
@@ -21,17 +21,17 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@mdi/js": "^7.3.67",
24
- "axios": "^0.27.2",
25
- "jwt-decode": "^3.1.2",
24
+ "axios": "^1.6.1",
25
+ "jwt-decode": "^4.0.0",
26
26
  "svelte-table": "^0.6.1"
27
27
  },
28
28
  "devDependencies": {
29
- "@babel/eslint-parser": "^7.22.15",
29
+ "@babel/eslint-parser": "^7.23.3",
30
30
  "chota": "^0.9.2",
31
- "eslint": "^8.52.0",
32
- "eslint-plugin-svelte": "^2.34.0",
33
- "svelte": "^4.2.2",
34
- "svelte-check": "^3.5.2",
31
+ "eslint": "^8.53.0",
32
+ "eslint-plugin-svelte": "^2.35.0",
33
+ "svelte": "^4.2.3",
34
+ "svelte-check": "^3.6.0",
35
35
  "svelte-chota": "^1.8.6"
36
36
  },
37
37
  "peerDependencies": {