@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/cjs/index.js
CHANGED
|
@@ -1278,6 +1278,29 @@ function getConfig(key) {
|
|
|
1278
1278
|
return key != null ? cfg[key] : cfg;
|
|
1279
1279
|
});
|
|
1280
1280
|
}
|
|
1281
|
+
function getConfigContent() {
|
|
1282
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1283
|
+
try {
|
|
1284
|
+
// `readJsonFile` should throw if the file isn’t there or isn’t valid JSON
|
|
1285
|
+
const cfg = yield readJsonFile('./config.json');
|
|
1286
|
+
return cfg;
|
|
1287
|
+
}
|
|
1288
|
+
catch (_a) {
|
|
1289
|
+
// swallow errors & return null so callers can detect “no config”
|
|
1290
|
+
return null;
|
|
1291
|
+
}
|
|
1292
|
+
});
|
|
1293
|
+
}
|
|
1294
|
+
// 2) Pull a single key out of that object
|
|
1295
|
+
function getConfigVar() {
|
|
1296
|
+
return __awaiter(this, arguments, void 0, function* (key = null) {
|
|
1297
|
+
const cfg = yield getConfigContent();
|
|
1298
|
+
if (cfg && typeof cfg === 'object' && key in cfg) {
|
|
1299
|
+
return cfg[key];
|
|
1300
|
+
}
|
|
1301
|
+
return undefined;
|
|
1302
|
+
});
|
|
1303
|
+
}
|
|
1281
1304
|
|
|
1282
1305
|
// Constructs API URL from endpoint
|
|
1283
1306
|
function api(endpoint) {
|
|
@@ -1548,6 +1571,51 @@ function fetchIndexHtmlContainer(filename_1) {
|
|
|
1548
1571
|
}
|
|
1549
1572
|
});
|
|
1550
1573
|
}
|
|
1574
|
+
// 2) Pull a single key out of that object
|
|
1575
|
+
function getBaseUrl() {
|
|
1576
|
+
return __awaiter(this, arguments, void 0, function* (key = null) {
|
|
1577
|
+
key = key || 'BASE_API_URL';
|
|
1578
|
+
const value = yield getConfigVar(key);
|
|
1579
|
+
return value;
|
|
1580
|
+
});
|
|
1581
|
+
}
|
|
1582
|
+
function getEndpoints() {
|
|
1583
|
+
return __awaiter(this, arguments, void 0, function* (base_url = null) {
|
|
1584
|
+
base_url = yield getUrl(base_url);
|
|
1585
|
+
const endpoints_url = `${base_url}/api/endpoints`;
|
|
1586
|
+
return yield fetchIt(endpoints_url, {}, "GET");
|
|
1587
|
+
});
|
|
1588
|
+
}
|
|
1589
|
+
function getUrl() {
|
|
1590
|
+
return __awaiter(this, arguments, void 0, function* (base_url = null) {
|
|
1591
|
+
return base_url || (yield getBaseUrl()) || 'https://abstractendeavors.com';
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
/**
|
|
1595
|
+
* Find the most specific endpoint matching the given keyword.
|
|
1596
|
+
* @param keyword A fragment to search for, e.g. 'list'
|
|
1597
|
+
* @returns The full path string, or null if nothing matches
|
|
1598
|
+
*/
|
|
1599
|
+
function getEndpoint(keyword_1) {
|
|
1600
|
+
return __awaiter(this, arguments, void 0, function* (keyword, base_url = null) {
|
|
1601
|
+
base_url = yield getUrl(base_url);
|
|
1602
|
+
const endpoints = yield getEndpoints(base_url);
|
|
1603
|
+
const lower = keyword.toLowerCase();
|
|
1604
|
+
let bestMatch = null;
|
|
1605
|
+
let bestLen = -1;
|
|
1606
|
+
for (const [path] of endpoints) {
|
|
1607
|
+
const lastSegment = path.split("/").pop().toLowerCase();
|
|
1608
|
+
// does either string contain the other?
|
|
1609
|
+
if (lastSegment.includes(lower)) {
|
|
1610
|
+
if (lastSegment.length > bestLen) {
|
|
1611
|
+
bestLen = lastSegment.length;
|
|
1612
|
+
bestMatch = path;
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
return `${base_url}${bestMatch}`;
|
|
1617
|
+
});
|
|
1618
|
+
}
|
|
1551
1619
|
|
|
1552
1620
|
function Button(_a) {
|
|
1553
1621
|
var { children, color = 'gray', variant = 'default', className = '' } = _a, rest = __rest(_a, ["children", "color", "variant", "className"]);
|
|
@@ -1644,12 +1712,17 @@ exports.getAbsDir = getAbsDir;
|
|
|
1644
1712
|
exports.getAbsPath = getAbsPath;
|
|
1645
1713
|
exports.getAuthorizationHeader = getAuthorizationHeader;
|
|
1646
1714
|
exports.getBaseDir = getBaseDir;
|
|
1715
|
+
exports.getBaseUrl = getBaseUrl;
|
|
1647
1716
|
exports.getBody = getBody;
|
|
1648
1717
|
exports.getComponentsUtilsDirectory = getComponentsUtilsDirectory;
|
|
1649
1718
|
exports.getConfig = getConfig;
|
|
1719
|
+
exports.getConfigContent = getConfigContent;
|
|
1720
|
+
exports.getConfigVar = getConfigVar;
|
|
1650
1721
|
exports.getDbConfigsPath = getDbConfigsPath;
|
|
1651
1722
|
exports.getDistDir = getDistDir;
|
|
1652
1723
|
exports.getDocumentProp = getDocumentProp;
|
|
1724
|
+
exports.getEndpoint = getEndpoint;
|
|
1725
|
+
exports.getEndpoints = getEndpoints;
|
|
1653
1726
|
exports.getEnvDir = getEnvDir;
|
|
1654
1727
|
exports.getEnvPath = getEnvPath;
|
|
1655
1728
|
exports.getFetchVars = getFetchVars;
|
|
@@ -1670,6 +1743,7 @@ exports.getSchemasPath = getSchemasPath;
|
|
|
1670
1743
|
exports.getSrcDir = getSrcDir;
|
|
1671
1744
|
exports.getSubstring = getSubstring;
|
|
1672
1745
|
exports.getToken = getToken;
|
|
1746
|
+
exports.getUrl = getUrl;
|
|
1673
1747
|
exports.getWindowHost = getWindowHost;
|
|
1674
1748
|
exports.getWindowProp = getWindowProp;
|
|
1675
1749
|
exports.get_app_config_url = get_app_config_url;
|