@putkoff/abstract-utilities 0.1.184 → 0.1.185
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 +74 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +69 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/functions/config_utils/src/config_utils.d.ts +2 -0
- package/dist/functions/fetch_utils/imports.d.ts +1 -0
- package/dist/functions/fetch_utils/src/fetchIt_utils.d.ts +9 -0
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -1275,6 +1275,29 @@ function getConfig(key) {
|
|
|
1275
1275
|
return key != null ? cfg[key] : cfg;
|
|
1276
1276
|
});
|
|
1277
1277
|
}
|
|
1278
|
+
function getConfigContent() {
|
|
1279
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1280
|
+
try {
|
|
1281
|
+
// `readJsonFile` should throw if the file isn’t there or isn’t valid JSON
|
|
1282
|
+
const cfg = yield readJsonFile('./config.json');
|
|
1283
|
+
return cfg;
|
|
1284
|
+
}
|
|
1285
|
+
catch (_a) {
|
|
1286
|
+
// swallow errors & return null so callers can detect “no config”
|
|
1287
|
+
return null;
|
|
1288
|
+
}
|
|
1289
|
+
});
|
|
1290
|
+
}
|
|
1291
|
+
// 2) Pull a single key out of that object
|
|
1292
|
+
function getConfigVar() {
|
|
1293
|
+
return __awaiter(this, arguments, void 0, function* (key = null) {
|
|
1294
|
+
const cfg = yield getConfigContent();
|
|
1295
|
+
if (cfg && typeof cfg === 'object' && key in cfg) {
|
|
1296
|
+
return cfg[key];
|
|
1297
|
+
}
|
|
1298
|
+
return undefined;
|
|
1299
|
+
});
|
|
1300
|
+
}
|
|
1278
1301
|
|
|
1279
1302
|
// Constructs API URL from endpoint
|
|
1280
1303
|
function api(endpoint) {
|
|
@@ -1545,6 +1568,51 @@ function fetchIndexHtmlContainer(filename_1) {
|
|
|
1545
1568
|
}
|
|
1546
1569
|
});
|
|
1547
1570
|
}
|
|
1571
|
+
// 2) Pull a single key out of that object
|
|
1572
|
+
function getBaseUrl() {
|
|
1573
|
+
return __awaiter(this, arguments, void 0, function* (key = null) {
|
|
1574
|
+
key = key || 'BASE_API_URL';
|
|
1575
|
+
const value = yield getConfigVar(key);
|
|
1576
|
+
return value;
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1579
|
+
function getEndpoints() {
|
|
1580
|
+
return __awaiter(this, arguments, void 0, function* (base_url = null) {
|
|
1581
|
+
base_url = yield getUrl(base_url);
|
|
1582
|
+
const endpoints_url = `${base_url}/api/endpoints`;
|
|
1583
|
+
return yield fetchIt(endpoints_url, {}, "GET");
|
|
1584
|
+
});
|
|
1585
|
+
}
|
|
1586
|
+
function getUrl() {
|
|
1587
|
+
return __awaiter(this, arguments, void 0, function* (base_url = null) {
|
|
1588
|
+
return base_url || (yield getBaseUrl()) || 'https://abstractendeavors.com';
|
|
1589
|
+
});
|
|
1590
|
+
}
|
|
1591
|
+
/**
|
|
1592
|
+
* Find the most specific endpoint matching the given keyword.
|
|
1593
|
+
* @param keyword A fragment to search for, e.g. 'list'
|
|
1594
|
+
* @returns The full path string, or null if nothing matches
|
|
1595
|
+
*/
|
|
1596
|
+
function getEndpoint(keyword_1) {
|
|
1597
|
+
return __awaiter(this, arguments, void 0, function* (keyword, base_url = null) {
|
|
1598
|
+
base_url = yield getUrl(base_url);
|
|
1599
|
+
const endpoints = yield getEndpoints(base_url);
|
|
1600
|
+
const lower = keyword.toLowerCase();
|
|
1601
|
+
let bestMatch = null;
|
|
1602
|
+
let bestLen = -1;
|
|
1603
|
+
for (const [path] of endpoints) {
|
|
1604
|
+
const lastSegment = path.split("/").pop().toLowerCase();
|
|
1605
|
+
// does either string contain the other?
|
|
1606
|
+
if (lastSegment.includes(lower)) {
|
|
1607
|
+
if (lastSegment.length > bestLen) {
|
|
1608
|
+
bestLen = lastSegment.length;
|
|
1609
|
+
bestMatch = path;
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
return `${base_url}${bestMatch}`;
|
|
1614
|
+
});
|
|
1615
|
+
}
|
|
1548
1616
|
|
|
1549
1617
|
function Button(_a) {
|
|
1550
1618
|
var { children, color = 'gray', variant = 'default', className = '' } = _a, rest = __rest(_a, ["children", "color", "variant", "className"]);
|
|
@@ -1581,5 +1649,5 @@ function Spinner() {
|
|
|
1581
1649
|
return (jsx("p", { className: 'animate-pulse', children: "Loading\u2026" }));
|
|
1582
1650
|
}
|
|
1583
1651
|
|
|
1584
|
-
export { API_PREFIX, BASE_URL, Button, Checkbox, DEV_PREFIX, DOMAIN_NAME, Input, PROD_PREFIX, PROTOCOL, SUB_DIR, Spinner, alertit, api, callStorage, callWindowMethod, checkResponse, create_list_string, 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, readJsonFile, requestPatch, requireToken, safeGlobalProp, safeStorage, sanitizeFilename, secureFetchIt, stripHost, stripPrefixes, truncateString, tryParse };
|
|
1652
|
+
export { API_PREFIX, BASE_URL, Button, Checkbox, DEV_PREFIX, DOMAIN_NAME, Input, PROD_PREFIX, PROTOCOL, SUB_DIR, Spinner, alertit, api, callStorage, callWindowMethod, checkResponse, create_list_string, 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, getBaseUrl, getBody, getComponentsUtilsDirectory, getConfig, getConfigContent, getConfigVar, getDbConfigsPath, getDistDir, getDocumentProp, getEndpoint, getEndpoints, getEnvDir, getEnvPath, getFetchVars, getFunctionsDir, getFunctionsUtilsDirectory, getHeaders, getHooksUtilsDirectory, getHtmlDirectory, getLibUtilsDirectory, getMethod, getPublicDir, getResult, getSafeDocument, getSafeLocalStorage, getSafeWindow, getSchemasDirPath, getSchemasPath, getSrcDir, getSubstring, getToken, getUrl, 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, readJsonFile, requestPatch, requireToken, safeGlobalProp, safeStorage, sanitizeFilename, secureFetchIt, stripHost, stripPrefixes, truncateString, tryParse };
|
|
1585
1653
|
//# sourceMappingURL=index.js.map
|