@osimatic/helpers-js 1.0.108 → 1.0.110
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/http_client.js +4 -4
- package/network.js +26 -42
- package/package.json +1 -1
package/http_client.js
CHANGED
|
@@ -176,7 +176,7 @@ class HTTPClient {
|
|
|
176
176
|
static async request(method, url, data, successCallback, errorCallback, formErrorCallback) {
|
|
177
177
|
method = method.toUpperCase();
|
|
178
178
|
|
|
179
|
-
if ('
|
|
179
|
+
if ('GET' === method) {
|
|
180
180
|
url += (!url.includes('?') ? '?' : '') + HTTPClient.formatQueryString(data);
|
|
181
181
|
data = null;
|
|
182
182
|
}
|
|
@@ -193,7 +193,7 @@ class HTTPClient {
|
|
|
193
193
|
cache: 'no-cache'
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
if ('
|
|
196
|
+
if ('GET' !== method) {
|
|
197
197
|
requestOptions['body'] = HTTPClient.formatFormData(data);
|
|
198
198
|
}
|
|
199
199
|
|
|
@@ -244,7 +244,7 @@ class HTTPClient {
|
|
|
244
244
|
static async download(method, url, data, errorCallback, completeCallback) {
|
|
245
245
|
method = typeof method == 'undefined' || null == method ? 'GET' : method;
|
|
246
246
|
|
|
247
|
-
if ('
|
|
247
|
+
if ('GET' === method) {
|
|
248
248
|
url += (!url.includes('?') ? '?' : '') + HTTPClient.formatQueryString(data);
|
|
249
249
|
data = null;
|
|
250
250
|
}
|
|
@@ -260,7 +260,7 @@ class HTTPClient {
|
|
|
260
260
|
cache: 'no-cache'
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
-
if ('
|
|
263
|
+
if ('GET' !== method) {
|
|
264
264
|
requestOptions['body'] = HTTPClient.formatFormData(data);
|
|
265
265
|
}
|
|
266
266
|
|
package/network.js
CHANGED
|
@@ -30,11 +30,17 @@ class Cookie {
|
|
|
30
30
|
class UrlAndQueryString {
|
|
31
31
|
static displayUrl(url, withLink) {
|
|
32
32
|
withLink = typeof withLink == 'undefined' ? true : withLink;
|
|
33
|
-
return (withLink?'<a href="'+url+'">':'')+UrlAndQueryString.getHost(url, false)+(withLink?'</a>':'');
|
|
33
|
+
return (withLink ? '<a href="' + url + '">' : '') + UrlAndQueryString.getHost(url, false) + (withLink ? '</a>' : '');
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
|
|
36
|
+
static displayUrlAndPath(url, withLink, displayPathIfEmpty) {
|
|
36
37
|
withLink = typeof withLink == 'undefined' ? true : withLink;
|
|
37
|
-
|
|
38
|
+
displayPathIfEmpty = typeof displayPathIfEmpty == 'undefined' ? false : displayPathIfEmpty;
|
|
39
|
+
let formattedUrl = UrlAndQueryString.getHostAndPath(url, false);
|
|
40
|
+
if (!displayPathIfEmpty && UrlAndQueryString.getPath(url) === '/') {
|
|
41
|
+
formattedUrl = formattedUrl.slice(-1) === '/' ? formattedUrl.slice(0, -1) : formattedUrl;
|
|
42
|
+
}
|
|
43
|
+
return (withLink ? '<a href="' + url + '">' : '') + formattedUrl + (withLink ? '</a>' : '');
|
|
38
44
|
}
|
|
39
45
|
|
|
40
46
|
static getHost(url, withProtocol) {
|
|
@@ -43,7 +49,7 @@ class UrlAndQueryString {
|
|
|
43
49
|
return withProtocol ? window.location.origin : window.location.host;
|
|
44
50
|
}
|
|
45
51
|
url = new URL(url);
|
|
46
|
-
return (withProtocol?url.protocol+'//':'') + url.host;
|
|
52
|
+
return (withProtocol ? url.protocol + '//' : '') + url.host;
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
static getPath(url) {
|
|
@@ -88,6 +94,7 @@ class UrlAndQueryString {
|
|
|
88
94
|
params[name] = value;
|
|
89
95
|
return decodeURI($.param(params));
|
|
90
96
|
}
|
|
97
|
+
|
|
91
98
|
static setParamOfUrl(name, value, url) {
|
|
92
99
|
let queryString = UrlAndQueryString.setParam(UrlAndQueryString.getQueryString(url), name, value);
|
|
93
100
|
return UrlAndQueryString.getHostAndPath(url) + '?' + queryString;
|
|
@@ -102,10 +109,12 @@ class UrlAndQueryString {
|
|
|
102
109
|
//params[name] = null;
|
|
103
110
|
//return $.param(params);
|
|
104
111
|
}
|
|
112
|
+
|
|
105
113
|
static deleteParamOfUrl(name, url) {
|
|
106
114
|
let queryString = UrlAndQueryString.deleteParam(UrlAndQueryString.getQueryString(url), name);
|
|
107
115
|
return UrlAndQueryString.getHostAndPath(url) + '?' + queryString;
|
|
108
116
|
}
|
|
117
|
+
|
|
109
118
|
static deleteParamsOfUrl(names, url) {
|
|
110
119
|
let queryString = UrlAndQueryString.getQueryString(url);
|
|
111
120
|
names.forEach((name => queryString = UrlAndQueryString.deleteParam(queryString, name)));
|
|
@@ -237,23 +246,6 @@ class UrlAndQueryString {
|
|
|
237
246
|
}
|
|
238
247
|
|
|
239
248
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
249
|
// deprecated
|
|
258
250
|
|
|
259
251
|
/** @deprecated **/
|
|
@@ -314,6 +306,7 @@ class UrlAndQueryString {
|
|
|
314
306
|
}
|
|
315
307
|
|
|
316
308
|
}
|
|
309
|
+
|
|
317
310
|
/** @deprecated */
|
|
318
311
|
class HTTPRequest {
|
|
319
312
|
static init() {
|
|
@@ -382,13 +375,11 @@ class HTTPRequest {
|
|
|
382
375
|
root = root || '';
|
|
383
376
|
if (data instanceof File) {
|
|
384
377
|
formData.append(root, data);
|
|
385
|
-
}
|
|
386
|
-
else if (Array.isArray(data)) {
|
|
378
|
+
} else if (Array.isArray(data)) {
|
|
387
379
|
for (var i = 0; i < data.length; i++) {
|
|
388
380
|
appendFormData(data[i], root + '[' + i + ']');
|
|
389
381
|
}
|
|
390
|
-
}
|
|
391
|
-
else if (typeof data === 'object' && data) {
|
|
382
|
+
} else if (typeof data === 'object' && data) {
|
|
392
383
|
for (var key in data) {
|
|
393
384
|
if (data.hasOwnProperty(key)) {
|
|
394
385
|
if (root === '') {
|
|
@@ -398,8 +389,7 @@ class HTTPRequest {
|
|
|
398
389
|
}
|
|
399
390
|
}
|
|
400
391
|
}
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
392
|
+
} else {
|
|
403
393
|
if (data !== null && typeof data !== 'undefined') {
|
|
404
394
|
formData.append(root, data);
|
|
405
395
|
}
|
|
@@ -432,11 +422,11 @@ class HTTPRequest {
|
|
|
432
422
|
}
|
|
433
423
|
|
|
434
424
|
static logRequestFailure(response, json) {
|
|
435
|
-
console.error('Request failure. Status: '+response.statusText+' ; HTTP Code : '+response.status, json);
|
|
425
|
+
console.error('Request failure. Status: ' + response.statusText + ' ; HTTP Code : ' + response.status, json);
|
|
436
426
|
}
|
|
437
427
|
|
|
438
428
|
static logJqueryRequestFailure(jqxhr, status, errorThrown) {
|
|
439
|
-
console.error('Request failure. Status: '+status+' ; HTTP Code: '+jqxhr.status+(null!=errorThrown && ''!==errorThrown ? ' ; Error message: '+errorThrown : ''), jqxhr.responseJSON);
|
|
429
|
+
console.error('Request failure. Status: ' + status + ' ; HTTP Code: ' + jqxhr.status + (null != errorThrown && '' !== errorThrown ? ' ; Error message: ' + errorThrown : ''), jqxhr.responseJSON);
|
|
440
430
|
}
|
|
441
431
|
|
|
442
432
|
static isExpiredToken(response, json) {
|
|
@@ -479,8 +469,7 @@ class HTTPRequest {
|
|
|
479
469
|
successCallback(jsonData, response);
|
|
480
470
|
return;
|
|
481
471
|
}
|
|
482
|
-
}
|
|
483
|
-
catch (e) {
|
|
472
|
+
} catch (e) {
|
|
484
473
|
console.error(e);
|
|
485
474
|
if (typeof errorCallback != 'undefined' && errorCallback != null) {
|
|
486
475
|
errorCallback(response);
|
|
@@ -552,15 +541,13 @@ class HTTPRequest {
|
|
|
552
541
|
if (response.ok) {
|
|
553
542
|
const blobData = await response.blob();
|
|
554
543
|
File.download(blobData, response.headers.get('content-type'), response.headers.get('content-disposition'));
|
|
555
|
-
}
|
|
556
|
-
else {
|
|
544
|
+
} else {
|
|
557
545
|
HTTPRequest.logRequestFailure(response, null);
|
|
558
546
|
if (typeof errorCallback != 'undefined' && errorCallback != null) {
|
|
559
547
|
errorCallback(response);
|
|
560
548
|
}
|
|
561
549
|
}
|
|
562
|
-
}
|
|
563
|
-
catch (e) {
|
|
550
|
+
} catch (e) {
|
|
564
551
|
console.error(e);
|
|
565
552
|
if (typeof errorCallback != 'undefined' && errorCallback != null) {
|
|
566
553
|
errorCallback(response);
|
|
@@ -645,8 +632,7 @@ class HTTPRequest {
|
|
|
645
632
|
formErrorCallback(jsonData, response);
|
|
646
633
|
return;
|
|
647
634
|
}
|
|
648
|
-
}
|
|
649
|
-
catch (e) {
|
|
635
|
+
} catch (e) {
|
|
650
636
|
console.error(e);
|
|
651
637
|
if (typeof errorCallback != 'undefined' && errorCallback != null) {
|
|
652
638
|
errorCallback(response);
|
|
@@ -747,8 +733,7 @@ class HTTPRequest {
|
|
|
747
733
|
let data;
|
|
748
734
|
if (formatRetour == 'xml') {
|
|
749
735
|
data = xhr.responseXML;
|
|
750
|
-
}
|
|
751
|
-
else {
|
|
736
|
+
} else {
|
|
752
737
|
data = eval('(' + xhr.responseText + ')');
|
|
753
738
|
}
|
|
754
739
|
callback(data);
|
|
@@ -758,8 +743,7 @@ class HTTPRequest {
|
|
|
758
743
|
if (methode === 'POST') {
|
|
759
744
|
xhr.open('POST', url, true);
|
|
760
745
|
xhr.send();
|
|
761
|
-
}
|
|
762
|
-
else {
|
|
746
|
+
} else {
|
|
763
747
|
xhr.open('GET', url + '?' + strParam, true);
|
|
764
748
|
xhr.send(null);
|
|
765
749
|
}
|
|
@@ -767,4 +751,4 @@ class HTTPRequest {
|
|
|
767
751
|
}
|
|
768
752
|
}
|
|
769
753
|
|
|
770
|
-
module.exports = {
|
|
754
|
+
module.exports = {HTTPRequest, Cookie, UrlAndQueryString};
|