@gandalan/weblibs 2.0.1 → 2.0.2
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/fluentApi.js +36 -31
- package/api/fluentRestClient.js +13 -8
- package/package.json +1 -1
package/api/fluentApi.js
CHANGED
|
@@ -73,44 +73,47 @@ export function createApi() {
|
|
|
73
73
|
},
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
76
|
+
* Sends a GET request, ensuring authentication if needed.
|
|
77
|
+
*
|
|
78
|
+
* @async
|
|
79
|
+
* @param {string} [url=""]
|
|
80
|
+
* @param {boolean} [auth=true]
|
|
81
|
+
* @param {boolean} [skipResponseParsing=false]
|
|
82
|
+
* @returns {Promise<Object>}
|
|
83
|
+
*/
|
|
84
|
+
async get(url = "", auth = true, skipResponseParsing = false) {
|
|
84
85
|
await this.preCheck(auth);
|
|
85
|
-
return await this.createRestClient().get(url);
|
|
86
|
+
return await this.createRestClient().get(url, auth, skipResponseParsing);
|
|
86
87
|
},
|
|
87
88
|
|
|
88
89
|
/**
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
90
|
+
* Sends a PUT request with a payload, ensuring authentication if needed.
|
|
91
|
+
*
|
|
92
|
+
* @async
|
|
93
|
+
* @param {string} [url=""]
|
|
94
|
+
* @param {Object} [payload={}]
|
|
95
|
+
* @param {boolean} [auth=true]
|
|
96
|
+
* @param {boolean} [skipResponseParsing=false]
|
|
97
|
+
* @returns {Promise<Object>}
|
|
98
|
+
*/
|
|
99
|
+
async put(url = "", payload = {}, auth = true, skipResponseParsing = false) {
|
|
98
100
|
await this.preCheck(auth);
|
|
99
|
-
return await this.createRestClient().put(url, payload);
|
|
101
|
+
return await this.createRestClient().put(url, payload, skipResponseParsing);
|
|
100
102
|
},
|
|
101
103
|
|
|
102
104
|
/**
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
105
|
+
* Sends a POST request with a payload, ensuring authentication if needed.
|
|
106
|
+
*
|
|
107
|
+
* @async
|
|
108
|
+
* @param {string} [url=""]
|
|
109
|
+
* @param {Object} [payload={}]
|
|
110
|
+
* @param {boolean} [auth=true]
|
|
111
|
+
* @param {boolean} [skipResponseParsing=false]
|
|
112
|
+
* @returns {Promise<Object>}
|
|
113
|
+
*/
|
|
114
|
+
async post(url = "", payload = {}, auth = true, skipResponseParsing = false) {
|
|
112
115
|
await this.preCheck(auth);
|
|
113
|
-
return await this.createRestClient().post(url, payload);
|
|
116
|
+
return await this.createRestClient().post(url, payload, skipResponseParsing);
|
|
114
117
|
},
|
|
115
118
|
|
|
116
119
|
/**
|
|
@@ -118,12 +121,14 @@ export function createApi() {
|
|
|
118
121
|
*
|
|
119
122
|
* @async
|
|
120
123
|
* @param {string} [url=""]
|
|
124
|
+
* @param {Object|FormData} [payload=null]
|
|
121
125
|
* @param {boolean} [auth=true]
|
|
126
|
+
* @param {boolean} [skipResponseParsing=false]
|
|
122
127
|
* @returns {Promise<Object>}
|
|
123
128
|
*/
|
|
124
|
-
async delete(url = "", payload = null, auth = true) {
|
|
129
|
+
async delete(url = "", payload = null, auth = true, skipResponseParsing = false) {
|
|
125
130
|
await this.preCheck(auth);
|
|
126
|
-
return await this.createRestClient().delete(url, payload);
|
|
131
|
+
return await this.createRestClient().delete(url, payload, skipResponseParsing);
|
|
127
132
|
},
|
|
128
133
|
|
|
129
134
|
/**
|
package/api/fluentRestClient.js
CHANGED
|
@@ -60,14 +60,15 @@ export function restClient() {
|
|
|
60
60
|
* @async
|
|
61
61
|
* @param {string} [url=""]
|
|
62
62
|
* @param {boolean} [auth=true]
|
|
63
|
+
* @param {boolean} [skipResponseParsing=false]
|
|
63
64
|
* @returns {Promise<any>}
|
|
64
65
|
*/
|
|
65
|
-
async get(url = "", auth = true) {
|
|
66
|
+
async get(url = "", auth = true, skipResponseParsing = false) {
|
|
66
67
|
const finalUrl = `${this.baseUrl}${url}`;
|
|
67
68
|
const headers = this._createHeaders();
|
|
68
69
|
const res = await fetch(finalUrl, { method: "GET", headers });
|
|
69
70
|
if (res.ok) {
|
|
70
|
-
return await this._parseReponse(res);
|
|
71
|
+
return skipResponseParsing ? res : await this._parseReponse(res);
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
throw new Error(`GET ${finalUrl} failed: ${res.status} ${res.statusText}`);
|
|
@@ -79,14 +80,15 @@ export function restClient() {
|
|
|
79
80
|
* @async
|
|
80
81
|
* @param {string} [url=""]
|
|
81
82
|
* @param {Object} [payload={}]
|
|
83
|
+
* @param {boolean} [skipResponseParsing=false]
|
|
82
84
|
* @returns {Promise<any>}
|
|
83
85
|
*/
|
|
84
|
-
async put(url = "", payload = {}) {
|
|
86
|
+
async put(url = "", payload = {}, skipResponseParsing = false) {
|
|
85
87
|
const finalUrl = `${this.baseUrl}${url}`;
|
|
86
88
|
const headers = this._createHeaders("application/json");
|
|
87
89
|
const res = await fetch(finalUrl, { method: "PUT", body: JSON.stringify(payload), headers });
|
|
88
90
|
if (res.ok) {
|
|
89
|
-
return await this._parseReponse(res);
|
|
91
|
+
return skipResponseParsing ? res : await this._parseReponse(res);
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
throw new Error(`PUT ${finalUrl} failed: ${res.status} ${res.statusText}`);
|
|
@@ -98,9 +100,10 @@ export function restClient() {
|
|
|
98
100
|
* @async
|
|
99
101
|
* @param {string} [url=""]
|
|
100
102
|
* @param {Object|FormData} [payload={}]
|
|
103
|
+
* @param {boolean} [skipResponseParsing=false]
|
|
101
104
|
* @returns {Promise<any>}
|
|
102
105
|
*/
|
|
103
|
-
async post(url = "", payload = {}) {
|
|
106
|
+
async post(url = "", payload = {}, skipResponseParsing = false) {
|
|
104
107
|
const finalUrl = `${this.baseUrl}${url}`;
|
|
105
108
|
let headers;
|
|
106
109
|
|
|
@@ -116,7 +119,7 @@ export function restClient() {
|
|
|
116
119
|
|
|
117
120
|
const res = await fetch(finalUrl, { method: "POST", body, headers });
|
|
118
121
|
if (res.ok) {
|
|
119
|
-
return await this._parseReponse(res);
|
|
122
|
+
return skipResponseParsing ? res : await this._parseReponse(res);
|
|
120
123
|
}
|
|
121
124
|
|
|
122
125
|
throw new Error(`POST ${finalUrl} failed: ${res.status} ${res.statusText}`);
|
|
@@ -127,9 +130,11 @@ export function restClient() {
|
|
|
127
130
|
*
|
|
128
131
|
* @async
|
|
129
132
|
* @param {string} [url=""]
|
|
133
|
+
* @param {Object|FormData} [payload=null]
|
|
134
|
+
* @param {boolean} [skipResponseParsing=false]
|
|
130
135
|
* @returns {Promise<any>}
|
|
131
136
|
*/
|
|
132
|
-
async delete(url = "", payload = null) {
|
|
137
|
+
async delete(url = "", payload = null, skipResponseParsing = false) {
|
|
133
138
|
const finalUrl = `${this.baseUrl}${url}`;
|
|
134
139
|
const hasBody = payload !== null && payload !== undefined;
|
|
135
140
|
const isFormData = payload instanceof FormData;
|
|
@@ -137,7 +142,7 @@ export function restClient() {
|
|
|
137
142
|
const body = !hasBody ? undefined : isFormData ? payload : JSON.stringify(payload);
|
|
138
143
|
const res = await fetch(finalUrl, { method: "DELETE", headers, body });
|
|
139
144
|
if (res.ok) {
|
|
140
|
-
return await this._parseReponse(res);
|
|
145
|
+
return skipResponseParsing ? res : await this._parseReponse(res);
|
|
141
146
|
}
|
|
142
147
|
|
|
143
148
|
throw new Error(`DELETE ${finalUrl} failed: ${res.status} ${res.statusText}`);
|