@putkoff/abstract-utilities 0.1.206 → 0.1.208
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/dist/cjs/index.js +12 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +12 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/types/functions/fetch_utils/src/fetch_utils.d.ts +2 -2
- package/dist/types/functions/fetch_utils/src/utils.d.ts +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -405,6 +405,9 @@ function getResult(obj) {
|
|
|
405
405
|
Object.prototype.hasOwnProperty.call(current, "result")) {
|
|
406
406
|
current = current.result;
|
|
407
407
|
}
|
|
408
|
+
if (current === null || current === void 0 ? void 0 : current.result) {
|
|
409
|
+
current = current.result;
|
|
410
|
+
}
|
|
408
411
|
return current;
|
|
409
412
|
}
|
|
410
413
|
// Determines HTTP method, defaults to GET or POST based on body
|
|
@@ -495,7 +498,7 @@ function checkResponse(res) {
|
|
|
495
498
|
}
|
|
496
499
|
|
|
497
500
|
function fetchIt(endpoint_1) {
|
|
498
|
-
return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, headers = null, blob = false, configUrl = false, withCredentials = true, returnJson = true,
|
|
501
|
+
return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, headers = null, blob = false, configUrl = false, withCredentials = true, returnJson = true, returnResult = true) {
|
|
499
502
|
method = (method || "GET").toUpperCase();
|
|
500
503
|
// 2) choose the URL
|
|
501
504
|
let url = endpoint;
|
|
@@ -512,17 +515,20 @@ function fetchIt(endpoint_1) {
|
|
|
512
515
|
: undefined,
|
|
513
516
|
};
|
|
514
517
|
console.debug("➡️ secureFetchIt →", url, opts);
|
|
515
|
-
|
|
518
|
+
let res = yield fetch(url, opts);
|
|
516
519
|
if (!res.ok) {
|
|
517
520
|
const err = yield res.text();
|
|
518
521
|
throw new Error(`HTTP ${res.status}: ${err}`);
|
|
519
522
|
}
|
|
520
523
|
if (blob)
|
|
521
524
|
return res.blob();
|
|
522
|
-
if (
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
525
|
+
if (returnResult || returnJson) {
|
|
526
|
+
let JsonRes = res.json();
|
|
527
|
+
if (returnResult) {
|
|
528
|
+
JsonRes = getResult(JsonRes);
|
|
529
|
+
}
|
|
530
|
+
return JsonRes;
|
|
531
|
+
}
|
|
526
532
|
return res;
|
|
527
533
|
});
|
|
528
534
|
}
|