@putkoff/abstract-utilities 0.1.200 → 0.1.202

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 CHANGED
@@ -1487,74 +1487,52 @@ function Spinner() {
1487
1487
  }
1488
1488
 
1489
1489
  // src/functions/config_utils/src/config_utils.ts
1490
- let _cachedConfig = null;
1491
- function loadConfig() {
1492
- return __awaiter(this, arguments, void 0, function* (filePath = null) {
1493
- var _a;
1494
- if (_cachedConfig) {
1495
- return _cachedConfig;
1496
- }
1497
- // 1) figure out where config.json lives
1498
- let configUrl;
1499
- if (filePath) {
1500
- configUrl = filePath;
1501
- }
1502
- else if (typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)) }) !== 'undefined' && typeof (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)) === 'string') {
1503
- // ES module: resolve relative to this file
1504
- try {
1505
- configUrl = new URL('./config.json', (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href))).href;
1506
- }
1507
- catch (_b) {
1508
- configUrl = 'config.json';
1509
- }
1510
- }
1511
- else {
1512
- // browser fallback
1513
- const baseURI = safeGlobalProp('document', 'baseURI');
1490
+ /**
1491
+ * Attempt to load config.json if present, otherwise return empty object.
1492
+ */
1493
+ function getConfigJson() {
1494
+ return __awaiter(this, void 0, void 0, function* () {
1495
+ // Node environment: check if file exists
1496
+ if (typeof process !== 'undefined' &&
1497
+ process.versions != null &&
1498
+ process.versions.node) {
1514
1499
  try {
1515
- configUrl =
1516
- typeof baseURI === 'string'
1517
- ? new URL('config.json', baseURI).href
1518
- : 'config.json';
1500
+ // dynamically require fs to check existence
1501
+ const fs = yield import('fs');
1502
+ const path = yield import('path');
1503
+ const configPath = path.resolve(__dirname, 'config.json');
1504
+ if (fs.existsSync(configPath)) {
1505
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
1506
+ return require(configPath);
1507
+ }
1519
1508
  }
1520
- catch (_c) {
1521
- configUrl = 'config.json';
1509
+ catch (_a) {
1510
+ // fall through
1522
1511
  }
1523
1512
  }
1524
- // 2) if we have a fetch, try HTTP(S)
1513
+ // Browser or fallback: try fetching via HTTP
1525
1514
  const fetchFn = safeGlobalProp('fetch');
1526
1515
  if (typeof fetchFn === 'function') {
1527
1516
  try {
1528
- const res = yield fetchFn(configUrl);
1517
+ const res = yield fetchFn('config.json');
1529
1518
  if (res.ok) {
1530
- const json = yield res.json();
1531
- // cache & return
1532
- _cachedConfig = (_a = json) !== null && _a !== void 0 ? _a : {};
1533
- return _cachedConfig;
1519
+ return (yield res.json());
1534
1520
  }
1535
1521
  }
1536
- catch (_d) {
1537
- /* swallow */
1522
+ catch (_b) {
1523
+ // ignore
1538
1524
  }
1539
1525
  }
1540
- // 3) Node fallback: try reading from disk (requires your readJsonFile util)
1526
+ // Node fallback: read from disk via readJsonFile
1541
1527
  try {
1542
- const disk = yield readJsonFile(configUrl);
1543
- _cachedConfig = disk !== null && disk !== void 0 ? disk : {};
1544
- return _cachedConfig;
1528
+ const disk = yield readJsonFile('config.json');
1529
+ return disk !== null && disk !== void 0 ? disk : {};
1545
1530
  }
1546
- catch (_e) {
1547
- /* swallow */
1531
+ catch (_c) {
1532
+ // ignore
1548
1533
  }
1549
- // 4) if all else fails, return an empty config
1550
- _cachedConfig = {};
1551
- return _cachedConfig;
1552
- });
1553
- }
1554
- function getConfig(key) {
1555
- return __awaiter(this, void 0, void 0, function* () {
1556
- const cfg = yield loadConfig();
1557
- return key != null ? cfg[key] : cfg;
1534
+ // final fallback
1535
+ return {};
1558
1536
  });
1559
1537
  }
1560
1538
 
@@ -1657,8 +1635,8 @@ exports.getBaseDir = getBaseDir;
1657
1635
  exports.getBody = getBody;
1658
1636
  exports.getCleanArray = getCleanArray;
1659
1637
  exports.getComponentsUtilsDirectory = getComponentsUtilsDirectory;
1660
- exports.getConfig = getConfig;
1661
1638
  exports.getConfigContent = getConfigContent;
1639
+ exports.getConfigJson = getConfigJson;
1662
1640
  exports.getConfigVar = getConfigVar;
1663
1641
  exports.getDbConfigsPath = getDbConfigsPath;
1664
1642
  exports.getDistDir = getDistDir;
@@ -1698,7 +1676,6 @@ exports.get_window_parts = get_window_parts;
1698
1676
  exports.get_window_pathname = get_window_pathname;
1699
1677
  exports.isLoggedIn = isLoggedIn;
1700
1678
  exports.isTokenExpired = isTokenExpired;
1701
- exports.loadConfig = loadConfig;
1702
1679
  exports.make_path = make_path;
1703
1680
  exports.make_sanitized_path = make_sanitized_path;
1704
1681
  exports.normalizeUrl = normalizeUrl;