@putkoff/abstract-utilities 0.1.169 → 0.1.171
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 +32 -11
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +32 -11
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1104,25 +1104,45 @@ function alertit(obj = null) {
|
|
|
1104
1104
|
let _cachedConfig = null;
|
|
1105
1105
|
function loadConfig() {
|
|
1106
1106
|
return __awaiter(this, arguments, void 0, function* (filePath = null) {
|
|
1107
|
-
|
|
1107
|
+
var _a;
|
|
1108
|
+
// 1) decide which path
|
|
1108
1109
|
const relativePath = filePath || 'config.json';
|
|
1109
|
-
// 2
|
|
1110
|
-
const
|
|
1111
|
-
// 3
|
|
1112
|
-
|
|
1110
|
+
// 2) pick a base URL: document.baseURI → window.location.href → '/'
|
|
1111
|
+
const base = (_a = getDocumentProp('baseURI')) !== null && _a !== void 0 ? _a : (typeof window !== 'undefined' ? window.location.href : '/');
|
|
1112
|
+
// 3) build the URL, safely
|
|
1113
|
+
let configUrl;
|
|
1114
|
+
try {
|
|
1115
|
+
configUrl = new URL(relativePath, base).href;
|
|
1116
|
+
}
|
|
1117
|
+
catch (err) {
|
|
1118
|
+
console.warn(`[loadConfig] failed to resolve URL for "${relativePath}" against "${base}":`, err);
|
|
1119
|
+
configUrl = relativePath; // try a bare-relative fetch
|
|
1120
|
+
}
|
|
1121
|
+
// 4) return cached if we have it
|
|
1122
|
+
if (_cachedConfig) {
|
|
1113
1123
|
return _cachedConfig;
|
|
1114
|
-
const res = yield fetch(configUrl);
|
|
1115
|
-
if (!res.ok) {
|
|
1116
|
-
throw new Error(`Could not fetch ${configUrl}: ${res.status}`);
|
|
1117
1124
|
}
|
|
1118
|
-
|
|
1119
|
-
|
|
1125
|
+
// 5) actually fetch + parse, but never throw
|
|
1126
|
+
try {
|
|
1127
|
+
const res = yield fetch(configUrl);
|
|
1128
|
+
if (!res.ok) {
|
|
1129
|
+
console.warn(`[loadConfig] server returned ${res.status} when fetching ${configUrl}`);
|
|
1130
|
+
return {};
|
|
1131
|
+
}
|
|
1132
|
+
const json = (yield res.json());
|
|
1133
|
+
_cachedConfig = json;
|
|
1134
|
+
return json;
|
|
1135
|
+
}
|
|
1136
|
+
catch (err) {
|
|
1137
|
+
console.warn(`[loadConfig] error fetching/parsing ${configUrl}:`, err);
|
|
1138
|
+
return {};
|
|
1139
|
+
}
|
|
1120
1140
|
});
|
|
1121
1141
|
}
|
|
1122
1142
|
function getConfig(key) {
|
|
1123
1143
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1124
1144
|
const cfg = yield loadConfig();
|
|
1125
|
-
return key ? cfg[key] : cfg;
|
|
1145
|
+
return key != null ? cfg[key] : cfg;
|
|
1126
1146
|
});
|
|
1127
1147
|
}
|
|
1128
1148
|
|
|
@@ -1287,6 +1307,7 @@ function stripHost(str) {
|
|
|
1287
1307
|
function get_app_config_url(endpoint) {
|
|
1288
1308
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1289
1309
|
// 1) normalize your input
|
|
1310
|
+
endpoint = endpoint || '';
|
|
1290
1311
|
stripHost(endpoint.trim().toLowerCase());
|
|
1291
1312
|
yield loadConfig();
|
|
1292
1313
|
const base = yield fetchIt('https://abstractendeavors.com/api/secure_env', { "key": 'BASE_API_URL', 'path': '/var/www/abstractendeavors/secure-files/public/config.json' }, 'POST', null, false, true);
|