@putkoff/abstract-utilities 0.1.169 → 0.1.170
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 +31 -11
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +31 -11
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -1101,25 +1101,45 @@ function alertit(obj = null) {
|
|
|
1101
1101
|
let _cachedConfig = null;
|
|
1102
1102
|
function loadConfig() {
|
|
1103
1103
|
return __awaiter(this, arguments, void 0, function* (filePath = null) {
|
|
1104
|
-
|
|
1104
|
+
var _a;
|
|
1105
|
+
// 1) decide which path
|
|
1105
1106
|
const relativePath = filePath || 'config.json';
|
|
1106
|
-
// 2
|
|
1107
|
-
const
|
|
1108
|
-
// 3
|
|
1109
|
-
|
|
1107
|
+
// 2) pick a base URL: document.baseURI → window.location.href → '/'
|
|
1108
|
+
const base = (_a = getDocumentProp('baseURI')) !== null && _a !== void 0 ? _a : (typeof window !== 'undefined' ? window.location.href : '/');
|
|
1109
|
+
// 3) build the URL, safely
|
|
1110
|
+
let configUrl;
|
|
1111
|
+
try {
|
|
1112
|
+
configUrl = new URL(relativePath, base).href;
|
|
1113
|
+
}
|
|
1114
|
+
catch (err) {
|
|
1115
|
+
console.warn(`[loadConfig] failed to resolve URL for "${relativePath}" against "${base}":`, err);
|
|
1116
|
+
configUrl = relativePath; // try a bare-relative fetch
|
|
1117
|
+
}
|
|
1118
|
+
// 4) return cached if we have it
|
|
1119
|
+
if (_cachedConfig) {
|
|
1110
1120
|
return _cachedConfig;
|
|
1111
|
-
const res = yield fetch(configUrl);
|
|
1112
|
-
if (!res.ok) {
|
|
1113
|
-
throw new Error(`Could not fetch ${configUrl}: ${res.status}`);
|
|
1114
1121
|
}
|
|
1115
|
-
|
|
1116
|
-
|
|
1122
|
+
// 5) actually fetch + parse, but never throw
|
|
1123
|
+
try {
|
|
1124
|
+
const res = yield fetch(configUrl);
|
|
1125
|
+
if (!res.ok) {
|
|
1126
|
+
console.warn(`[loadConfig] server returned ${res.status} when fetching ${configUrl}`);
|
|
1127
|
+
return {};
|
|
1128
|
+
}
|
|
1129
|
+
const json = (yield res.json());
|
|
1130
|
+
_cachedConfig = json;
|
|
1131
|
+
return json;
|
|
1132
|
+
}
|
|
1133
|
+
catch (err) {
|
|
1134
|
+
console.warn(`[loadConfig] error fetching/parsing ${configUrl}:`, err);
|
|
1135
|
+
return {};
|
|
1136
|
+
}
|
|
1117
1137
|
});
|
|
1118
1138
|
}
|
|
1119
1139
|
function getConfig(key) {
|
|
1120
1140
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1121
1141
|
const cfg = yield loadConfig();
|
|
1122
|
-
return key ? cfg[key] : cfg;
|
|
1142
|
+
return key != null ? cfg[key] : cfg;
|
|
1123
1143
|
});
|
|
1124
1144
|
}
|
|
1125
1145
|
|