@osimatic/helpers-js 1.0.111 → 1.1.0

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/http_client.js +19 -11
  2. package/package.json +1 -1
package/http_client.js CHANGED
@@ -179,25 +179,33 @@ class HTTPClient {
179
179
  static async request(method, url, data, successCallback, errorCallback, formErrorCallback) {
180
180
  method = method.toUpperCase();
181
181
 
182
- if ('GET' === method) {
182
+ if (!window.fetch) {
183
+ return;
184
+ }
185
+
186
+ let body = null;
187
+ method = method.toUpperCase();
188
+
189
+ if ('POST' !== method && 'PATCH' !== method) {
183
190
  url += (!url.includes('?') ? '?' : '') + HTTPClient.formatQueryString(data);
184
191
  data = null;
185
192
  }
186
193
 
187
- if (!window.fetch) {
188
- return;
194
+ if (method === 'PATCH') {
195
+ HTTPClient.setHeader('Content-Type', 'application/x-www-form-urlencoded');
196
+ body = new URLSearchParams(HTTPClient.formatFormData(data)).toString();
189
197
  }
190
198
 
191
- //console.log(HTTPClient.getHeaders());
192
- let requestOptions = {
193
- method: method,
194
- headers: HTTPClient.getHeaders(),
195
- mode: 'cors',
196
- cache: 'no-cache'
199
+ if ('POST' === method) {
200
+ body = HTTPClient.formatFormData(data);
197
201
  }
198
202
 
199
- if ('GET' !== method) {
200
- requestOptions['body'] = HTTPClient.formatFormData(data);
203
+ const requestOptions = {
204
+ headers: HTTPClient.getHeaders(),
205
+ mode: 'cors',
206
+ cache: 'no-cache',
207
+ method,
208
+ body
201
209
  }
202
210
 
203
211
  const response = await fetch(url, requestOptions);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.0.111",
3
+ "version": "1.1.0",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"