@putkoff/abstract-utilities 0.1.114 → 0.1.116
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/functions/config_utils/imports.d.ts +1 -0
- package/dist/cjs/functions/config_utils/index.d.ts +1 -0
- package/dist/cjs/functions/config_utils/src/config_utils.d.ts +7 -0
- package/dist/cjs/functions/config_utils/src/index.d.ts +1 -0
- package/dist/cjs/functions/index.d.ts +2 -0
- package/dist/cjs/functions/read_utils/imports.d.ts +3 -0
- package/dist/cjs/functions/read_utils/index.d.ts +1 -0
- package/dist/cjs/functions/read_utils/src/index.d.ts +1 -0
- package/dist/cjs/functions/read_utils/src/read_utils.d.ts +9 -0
- package/dist/cjs/index.js +77 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/src/utils.d.ts +6 -0
- package/dist/esm/functions/config_utils/imports.d.ts +1 -0
- package/dist/esm/functions/config_utils/index.d.ts +1 -0
- package/dist/esm/functions/config_utils/src/config_utils.d.ts +7 -0
- package/dist/esm/functions/config_utils/src/index.d.ts +1 -0
- package/dist/esm/functions/index.d.ts +2 -0
- package/dist/esm/functions/read_utils/imports.d.ts +3 -0
- package/dist/esm/functions/read_utils/index.d.ts +1 -0
- package/dist/esm/functions/read_utils/src/index.d.ts +1 -0
- package/dist/esm/functions/read_utils/src/read_utils.d.ts +9 -0
- package/dist/esm/index.js +75 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/src/utils.d.ts +6 -0
- package/dist/functions/config_utils/imports.d.ts +1 -0
- package/dist/functions/config_utils/index.d.ts +1 -0
- package/dist/functions/config_utils/src/config_utils.d.ts +7 -0
- package/dist/functions/config_utils/src/index.d.ts +1 -0
- package/dist/functions/index.d.ts +2 -0
- package/dist/functions/read_utils/imports.d.ts +0 -0
- package/dist/functions/read_utils/index.d.ts +1 -0
- package/dist/functions/read_utils/src/index.d.ts +1 -0
- package/dist/functions/read_utils/src/read_utils.d.ts +9 -0
- package/dist/index.d.ts +24 -1
- package/dist/types/src/utils.d.ts +6 -0
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -1020,14 +1020,14 @@ function getAppConfig(endpoint) {
|
|
|
1020
1020
|
return base ? `${base}/${clean}` : `/api/${clean}`;
|
|
1021
1021
|
}
|
|
1022
1022
|
/** Accessor for the loaded config. Throws if you forgot to loadConfig(). */
|
|
1023
|
-
function getConfig() {
|
|
1023
|
+
function getConfig$1() {
|
|
1024
1024
|
{
|
|
1025
1025
|
throw new Error('Config not loaded! Call loadConfig() first.');
|
|
1026
1026
|
}
|
|
1027
1027
|
}
|
|
1028
1028
|
/** Convenience to grab the base URL once loaded. */
|
|
1029
1029
|
function apiBase() {
|
|
1030
|
-
return getConfig().API_BASE_URL.replace(/\/+$/, '');
|
|
1030
|
+
return getConfig$1().API_BASE_URL.replace(/\/+$/, '');
|
|
1031
1031
|
}
|
|
1032
1032
|
|
|
1033
1033
|
function ensureAbstractUrl(endpoint, slices = []) {
|
|
@@ -1277,5 +1277,77 @@ function Spinner() {
|
|
|
1277
1277
|
return (jsx("p", { className: 'animate-pulse', children: "Loading\u2026" }));
|
|
1278
1278
|
}
|
|
1279
1279
|
|
|
1280
|
-
|
|
1280
|
+
let _cachedConfig = null;
|
|
1281
|
+
function loadConfig() {
|
|
1282
|
+
return __awaiter(this, arguments, void 0, function* (filePath = null) {
|
|
1283
|
+
// 1. If nobody passed a custom path, we default to "config.json" (relative)
|
|
1284
|
+
const relativePath = filePath || 'config.json';
|
|
1285
|
+
// 2. Resolve it against the running page’s URL (document.baseURI)
|
|
1286
|
+
const configUrl = new URL(relativePath, document.baseURI).href;
|
|
1287
|
+
// 3. Fetch + cache
|
|
1288
|
+
if (_cachedConfig)
|
|
1289
|
+
return _cachedConfig;
|
|
1290
|
+
const res = yield fetch(configUrl);
|
|
1291
|
+
if (!res.ok) {
|
|
1292
|
+
throw new Error(`Could not fetch ${configUrl}: ${res.status}`);
|
|
1293
|
+
}
|
|
1294
|
+
_cachedConfig = (yield res.json());
|
|
1295
|
+
return _cachedConfig;
|
|
1296
|
+
});
|
|
1297
|
+
}
|
|
1298
|
+
function getConfig(key) {
|
|
1299
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1300
|
+
const cfg = yield loadConfig();
|
|
1301
|
+
return key ? cfg[key] : cfg;
|
|
1302
|
+
});
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
// src/read_utils.ts
|
|
1306
|
+
/**
|
|
1307
|
+
* Attempt to load the Node-only modules.
|
|
1308
|
+
* Returns { fs: null, path: null } in the browser.
|
|
1309
|
+
*/
|
|
1310
|
+
function tryNodeModules() {
|
|
1311
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1312
|
+
try {
|
|
1313
|
+
const fsMod = yield import('fs');
|
|
1314
|
+
const pathMod = yield import('path');
|
|
1315
|
+
return {
|
|
1316
|
+
fs: fsMod.promises, // keep the `promises` API
|
|
1317
|
+
path: pathMod
|
|
1318
|
+
};
|
|
1319
|
+
}
|
|
1320
|
+
catch (_a) {
|
|
1321
|
+
return { fs: null, path: null };
|
|
1322
|
+
}
|
|
1323
|
+
});
|
|
1324
|
+
}
|
|
1325
|
+
/**
|
|
1326
|
+
* Reads a file at `relativeOrAbsolutePath` and returns its contents as a string.
|
|
1327
|
+
* In a browser this will reject immediately.
|
|
1328
|
+
*/
|
|
1329
|
+
function readFileContents(relativeOrAbsolutePath) {
|
|
1330
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1331
|
+
const { fs, path } = yield tryNodeModules();
|
|
1332
|
+
if (!fs || !path) {
|
|
1333
|
+
throw new Error('readFileContents can only be used in Node.js');
|
|
1334
|
+
}
|
|
1335
|
+
// resolve absolute
|
|
1336
|
+
const filePath = path.isAbsolute(relativeOrAbsolutePath)
|
|
1337
|
+
? relativeOrAbsolutePath
|
|
1338
|
+
: path.resolve(__dirname, relativeOrAbsolutePath);
|
|
1339
|
+
return fs.readFile(filePath, 'utf8');
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1342
|
+
/**
|
|
1343
|
+
* Reads a JSON file and returns the parsed object.
|
|
1344
|
+
*/
|
|
1345
|
+
function readJsonFile(relativeOrAbsolutePath) {
|
|
1346
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1347
|
+
const text = yield readFileContents(relativeOrAbsolutePath);
|
|
1348
|
+
return JSON.parse(text);
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
export { API_PREFIX, BASE_URL, Button, Checkbox, DEV_PREFIX, DOMAIN_NAME, Input, PROD_PREFIX, PROTOCOL, SUB_DIR, Spinner, alertit, currentUsername, currentUsernames, decodeJwt, eatAll, eatEnd, eatInner, eatOuter, ensure_list, fetchIt, fetchSharePatch, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, getAbsDir, getAbsPath, getAuthorizationHeader, getBaseDir, getComponentsUtilsDirectory, getConfig, getDbConfigsPath, getDistDir, getEnvDir, getEnvPath, getFunctionsDir, getFunctionsUtilsDirectory, getHooksUtilsDirectory, getLibUtilsDirectory, getPublicDir, getSchemasDirPath, getSchemasPath, getSrcDir, getSubstring, getToken, 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, make_path, make_sanitized_path, normalizeUrl, readFileContents, readJsonFile, requestPatch, requireToken, sanitizeFilename, secureFetchIt, stripPrefixes, truncateString };
|
|
1281
1353
|
//# sourceMappingURL=index.js.map
|