@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/esm/index.js
CHANGED
|
@@ -80,6 +80,19 @@ function getWindowHost() {
|
|
|
80
80
|
return getWindowProp('location', 'host');
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
function getSafeDocument() {
|
|
84
|
+
return typeof document !== 'undefined' ? document : undefined;
|
|
85
|
+
}
|
|
86
|
+
function getDocumentProp(...keys) {
|
|
87
|
+
let obj = getSafeDocument();
|
|
88
|
+
for (const k of keys) {
|
|
89
|
+
if (obj == null || typeof obj !== 'object')
|
|
90
|
+
return undefined;
|
|
91
|
+
obj = obj[k];
|
|
92
|
+
}
|
|
93
|
+
return obj;
|
|
94
|
+
}
|
|
95
|
+
|
|
83
96
|
/**
|
|
84
97
|
***Changes**:
|
|
85
98
|
*- Updated import path for `InputProps` to `../../types/interfaces`.
|
|
@@ -1088,25 +1101,45 @@ function alertit(obj = null) {
|
|
|
1088
1101
|
let _cachedConfig = null;
|
|
1089
1102
|
function loadConfig() {
|
|
1090
1103
|
return __awaiter(this, arguments, void 0, function* (filePath = null) {
|
|
1091
|
-
|
|
1104
|
+
var _a;
|
|
1105
|
+
// 1) decide which path
|
|
1092
1106
|
const relativePath = filePath || 'config.json';
|
|
1093
|
-
// 2
|
|
1094
|
-
const
|
|
1095
|
-
// 3
|
|
1096
|
-
|
|
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) {
|
|
1097
1120
|
return _cachedConfig;
|
|
1098
|
-
const res = yield fetch(configUrl);
|
|
1099
|
-
if (!res.ok) {
|
|
1100
|
-
throw new Error(`Could not fetch ${configUrl}: ${res.status}`);
|
|
1101
1121
|
}
|
|
1102
|
-
|
|
1103
|
-
|
|
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
|
+
}
|
|
1104
1137
|
});
|
|
1105
1138
|
}
|
|
1106
1139
|
function getConfig(key) {
|
|
1107
1140
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1108
1141
|
const cfg = yield loadConfig();
|
|
1109
|
-
return key ? cfg[key] : cfg;
|
|
1142
|
+
return key != null ? cfg[key] : cfg;
|
|
1110
1143
|
});
|
|
1111
1144
|
}
|
|
1112
1145
|
|
|
@@ -1438,5 +1471,5 @@ function readJsonFile(relativeOrAbsolutePath) {
|
|
|
1438
1471
|
});
|
|
1439
1472
|
}
|
|
1440
1473
|
|
|
1441
|
-
export { API_PREFIX, BASE_URL, Button, Checkbox, DEV_PREFIX, DOMAIN_NAME, Input, PROD_PREFIX, PROTOCOL, SUB_DIR, Spinner, alertit, api, callStorage, callWindowMethod, checkResponse, currentUsername, currentUsernames, decodeJwt, eatAll, eatEnd, eatInner, eatOuter, ensureAbstractUrl, ensure_list, fetchIndexHtml, fetchIndexHtmlContainer, fetchIt, fetchSharePatch, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, getAbsDir, getAbsPath, getAuthorizationHeader, getBaseDir, getBody, getComponentsUtilsDirectory, getConfig, getDbConfigsPath, getDistDir, getEnvDir, getEnvPath, getFetchVars, getFunctionsDir, getFunctionsUtilsDirectory, getHeaders, getHooksUtilsDirectory, getHtmlDirectory, getLibUtilsDirectory, getMethod, getPublicDir, getResult, getSafeLocalStorage, getSafeWindow, getSchemasDirPath, getSchemasPath, getSrcDir, getSubstring, getToken, getWindowHost, getWindowProp, get_app_config_url, get_basename, get_dirname, get_extname, get_filename, get_splitext, get_window, get_window_location, get_window_parts, get_window_pathname, isLoggedIn, isTokenExpired, loadConfig, make_path, make_sanitized_path, normalizeUrl, parseResult, readFileContents, readJsonFile, requestPatch, requireToken, sanitizeFilename, secureFetchIt, stripPrefixes, truncateString };
|
|
1474
|
+
export { API_PREFIX, BASE_URL, Button, Checkbox, DEV_PREFIX, DOMAIN_NAME, Input, PROD_PREFIX, PROTOCOL, SUB_DIR, Spinner, alertit, api, callStorage, callWindowMethod, checkResponse, currentUsername, currentUsernames, decodeJwt, eatAll, eatEnd, eatInner, eatOuter, ensureAbstractUrl, ensure_list, fetchIndexHtml, fetchIndexHtmlContainer, fetchIt, fetchSharePatch, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, getAbsDir, getAbsPath, getAuthorizationHeader, getBaseDir, getBody, getComponentsUtilsDirectory, getConfig, getDbConfigsPath, getDistDir, getDocumentProp, getEnvDir, getEnvPath, getFetchVars, getFunctionsDir, getFunctionsUtilsDirectory, getHeaders, getHooksUtilsDirectory, getHtmlDirectory, getLibUtilsDirectory, getMethod, getPublicDir, getResult, getSafeDocument, getSafeLocalStorage, getSafeWindow, getSchemasDirPath, getSchemasPath, getSrcDir, getSubstring, getToken, getWindowHost, getWindowProp, get_app_config_url, get_basename, get_dirname, get_extname, get_filename, get_splitext, get_window, get_window_location, get_window_parts, get_window_pathname, isLoggedIn, isTokenExpired, loadConfig, make_path, make_sanitized_path, normalizeUrl, parseResult, readFileContents, readJsonFile, requestPatch, requireToken, sanitizeFilename, secureFetchIt, stripPrefixes, truncateString };
|
|
1442
1475
|
//# sourceMappingURL=index.js.map
|