@gandalan/weblibs 0.0.38 → 0.0.39

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.
Files changed (2) hide show
  1. package/api/RESTClient.js +16 -24
  2. package/package.json +1 -1
package/api/RESTClient.js CHANGED
@@ -31,12 +31,16 @@ export class RESTClient {
31
31
  this.token = token;
32
32
  }
33
33
 
34
+ getUrlOptions(noJWT = false) {
35
+ let options = { withCredentials: false }
36
+ if (this.isJWT && !noJWT)
37
+ options.headers = { Authorization: `Bearer ${this.token}` }
38
+ return options
39
+ }
40
+
34
41
  async get(uri, noJWT = false) {
35
42
  try {
36
- let options = { withCredentials: false }
37
- if (this.isJWT && !noJWT)
38
- options.headers = { Authorization: `Bearer ${this.token}` }
39
- const response = await axios.get(this.baseurl + uri, options);
43
+ const response = await axios.get(this.baseurl + uri, this.getUrlOptions(noJWT));
40
44
  this.lastError = '';
41
45
  return response.data;
42
46
  } catch (error) {
@@ -60,13 +64,10 @@ export class RESTClient {
60
64
  }
61
65
  }
62
66
 
63
- async getRaw(uri) {
67
+ async getRaw(uri, noJWT = false) {
64
68
  let response = {};
65
69
  try {
66
- let options = { withCredentials: false }
67
- if (this.isJWT)
68
- options.headers = { Authorization: `Bearer ${this.token}` }
69
- response = await axios.get(this.baseurl + uri, options)
70
+ response = await axios.get(this.baseurl + uri, this.getUrlOptions(noJWT))
70
71
  this.lastError = '';
71
72
  } catch (error) {
72
73
  this.handleError(error);
@@ -74,12 +75,9 @@ export class RESTClient {
74
75
  return response;
75
76
  }
76
77
 
77
- async post(uri, formData) {
78
+ async post(uri, formData, noJWT = false) {
78
79
  try {
79
- let options = { withCredentials: false }
80
- if (this.isJWT)
81
- options.headers = { Authorization: `Bearer ${this.token}` }
82
- const response = await axios.post(this.baseurl + uri, formData, options);
80
+ const response = await axios.post(this.baseurl + uri, formData, this.getUrlOptions(noJWT));
83
81
  this.lastError = '';
84
82
  return response;
85
83
  } catch (error) {
@@ -87,12 +85,9 @@ export class RESTClient {
87
85
  }
88
86
  }
89
87
 
90
- async put(uri, formData) {
88
+ async put(uri, formData, noJWT = false) {
91
89
  try {
92
- let options = { withCredentials: false }
93
- if (this.isJWT)
94
- options.headers = { Authorization: `Bearer ${this.token}` }
95
- const response = await axios.put(this.baseurl + uri, formData, options);
90
+ const response = await axios.put(this.baseurl + uri, formData, this.getUrlOptions(noJWT));
96
91
  this.lastError = '';
97
92
  return response;
98
93
  } catch (error) {
@@ -100,12 +95,9 @@ export class RESTClient {
100
95
  }
101
96
  }
102
97
 
103
- async delete(uri) {
98
+ async delete(uri, noJWT = false) {
104
99
  try {
105
- let options = { withCredentials: false }
106
- if (this.isJWT)
107
- options.headers = { Authorization: `Bearer ${this.token}` }
108
- const response = await axios.delete(this.baseurl + uri, options);
100
+ const response = await axios.delete(this.baseurl + uri, this.getUrlOptions(noJWT));
109
101
  this.lastError = '';
110
102
  return response;
111
103
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gandalan/weblibs",
3
- "version": "0.0.38",
3
+ "version": "0.0.39",
4
4
  "description": "WebLibs for Gandalan JS/TS/Svelte projects",
5
5
  "author": "Philipp Reif",
6
6
  "license": "ISC",