@putkoff/abstract-utilities 0.1.168 → 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 +46 -11
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +45 -12
- package/dist/esm/index.js.map +1 -1
- package/dist/functions/config_utils/imports.d.ts +1 -0
- package/dist/functions/safe_utils/src/index.d.ts +1 -0
- package/dist/functions/safe_utils/src/safe_document.d.ts +3 -0
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -83,6 +83,19 @@ function getWindowHost() {
|
|
|
83
83
|
return getWindowProp('location', 'host');
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
function getSafeDocument() {
|
|
87
|
+
return typeof document !== 'undefined' ? document : undefined;
|
|
88
|
+
}
|
|
89
|
+
function getDocumentProp(...keys) {
|
|
90
|
+
let obj = getSafeDocument();
|
|
91
|
+
for (const k of keys) {
|
|
92
|
+
if (obj == null || typeof obj !== 'object')
|
|
93
|
+
return undefined;
|
|
94
|
+
obj = obj[k];
|
|
95
|
+
}
|
|
96
|
+
return obj;
|
|
97
|
+
}
|
|
98
|
+
|
|
86
99
|
/**
|
|
87
100
|
***Changes**:
|
|
88
101
|
*- Updated import path for `InputProps` to `../../types/interfaces`.
|
|
@@ -1091,25 +1104,45 @@ function alertit(obj = null) {
|
|
|
1091
1104
|
let _cachedConfig = null;
|
|
1092
1105
|
function loadConfig() {
|
|
1093
1106
|
return __awaiter(this, arguments, void 0, function* (filePath = null) {
|
|
1094
|
-
|
|
1107
|
+
var _a;
|
|
1108
|
+
// 1) decide which path
|
|
1095
1109
|
const relativePath = filePath || 'config.json';
|
|
1096
|
-
// 2
|
|
1097
|
-
const
|
|
1098
|
-
// 3
|
|
1099
|
-
|
|
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) {
|
|
1100
1123
|
return _cachedConfig;
|
|
1101
|
-
const res = yield fetch(configUrl);
|
|
1102
|
-
if (!res.ok) {
|
|
1103
|
-
throw new Error(`Could not fetch ${configUrl}: ${res.status}`);
|
|
1104
1124
|
}
|
|
1105
|
-
|
|
1106
|
-
|
|
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
|
+
}
|
|
1107
1140
|
});
|
|
1108
1141
|
}
|
|
1109
1142
|
function getConfig(key) {
|
|
1110
1143
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1111
1144
|
const cfg = yield loadConfig();
|
|
1112
|
-
return key ? cfg[key] : cfg;
|
|
1145
|
+
return key != null ? cfg[key] : cfg;
|
|
1113
1146
|
});
|
|
1114
1147
|
}
|
|
1115
1148
|
|
|
@@ -1505,6 +1538,7 @@ exports.getComponentsUtilsDirectory = getComponentsUtilsDirectory;
|
|
|
1505
1538
|
exports.getConfig = getConfig;
|
|
1506
1539
|
exports.getDbConfigsPath = getDbConfigsPath;
|
|
1507
1540
|
exports.getDistDir = getDistDir;
|
|
1541
|
+
exports.getDocumentProp = getDocumentProp;
|
|
1508
1542
|
exports.getEnvDir = getEnvDir;
|
|
1509
1543
|
exports.getEnvPath = getEnvPath;
|
|
1510
1544
|
exports.getFetchVars = getFetchVars;
|
|
@@ -1517,6 +1551,7 @@ exports.getLibUtilsDirectory = getLibUtilsDirectory;
|
|
|
1517
1551
|
exports.getMethod = getMethod;
|
|
1518
1552
|
exports.getPublicDir = getPublicDir;
|
|
1519
1553
|
exports.getResult = getResult;
|
|
1554
|
+
exports.getSafeDocument = getSafeDocument;
|
|
1520
1555
|
exports.getSafeLocalStorage = getSafeLocalStorage;
|
|
1521
1556
|
exports.getSafeWindow = getSafeWindow;
|
|
1522
1557
|
exports.getSchemasDirPath = getSchemasDirPath;
|