@putkoff/abstract-utilities 0.1.116 → 0.1.117

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/esm/index.js CHANGED
@@ -1013,21 +1013,29 @@ function alertit(obj = null) {
1013
1013
  alert(msg);
1014
1014
  }
1015
1015
 
1016
- /** Will be filled in by loadConfig() */
1017
- function getAppConfig(endpoint) {
1018
- const base = apiBase(); // '' until load() finishes
1019
- const clean = endpoint.replace(/^\/+/, '');
1020
- return base ? `${base}/${clean}` : `/api/${clean}`;
1021
- }
1022
- /** Accessor for the loaded config. Throws if you forgot to loadConfig(). */
1023
- function getConfig$1() {
1024
- {
1025
- throw new Error('Config not loaded! Call loadConfig() first.');
1026
- }
1016
+ let _cachedConfig = null;
1017
+ function loadConfig$1() {
1018
+ return __awaiter(this, arguments, void 0, function* (filePath = null) {
1019
+ // 1. If nobody passed a custom path, we default to "config.json" (relative)
1020
+ const relativePath = filePath || 'config.json';
1021
+ // 2. Resolve it against the running page’s URL (document.baseURI)
1022
+ const configUrl = new URL(relativePath, document.baseURI).href;
1023
+ // 3. Fetch + cache
1024
+ if (_cachedConfig)
1025
+ return _cachedConfig;
1026
+ const res = yield fetch(configUrl);
1027
+ if (!res.ok) {
1028
+ throw new Error(`Could not fetch ${configUrl}: ${res.status}`);
1029
+ }
1030
+ _cachedConfig = (yield res.json());
1031
+ return _cachedConfig;
1032
+ });
1027
1033
  }
1028
- /** Convenience to grab the base URL once loaded. */
1029
- function apiBase() {
1030
- return getConfig$1().API_BASE_URL.replace(/\/+$/, '');
1034
+ function getConfig(key) {
1035
+ return __awaiter(this, void 0, void 0, function* () {
1036
+ const cfg = yield loadConfig$1();
1037
+ return key ? cfg[key] : cfg;
1038
+ });
1031
1039
  }
1032
1040
 
1033
1041
  function ensureAbstractUrl(endpoint, slices = []) {
@@ -1155,9 +1163,11 @@ function getFetchVars(headers = null, method = null, body = null) {
1155
1163
  /** Pulls base-URL from AppConfig.API_BASE_URL, strips trailing slashes */
1156
1164
  // src/functions/fetch/secureFetchIt.ts
1157
1165
  // --- fetch_utils/src/fetch_utils.ts ----------------------------
1158
- function get_app_config_url(endpoint) {
1166
+ function get_app_config_url(endpoint, appKey = null) {
1159
1167
  const cleanEndpoint = endpoint.replace(/^\/+/, "");
1160
- const baseUrl = getAppConfig(cleanEndpoint);
1168
+ const baseUrl = getConfig();
1169
+ appKey = appKey || 'BASE_API_URL';
1170
+ baseUrl[appKey];
1161
1171
  const baseSlices = baseUrl.split("/").filter(Boolean);
1162
1172
  const url = ensureAbstractUrl(cleanEndpoint, baseSlices);
1163
1173
  return url;
@@ -1176,7 +1186,7 @@ function secureFetchIt(endpoint_1) {
1176
1186
  method = method || "GET";
1177
1187
  let url = endpoint;
1178
1188
  if (!noApi) {
1179
- url = get_app_config_url(url);
1189
+ url = get_app_config_url(endpoint);
1180
1190
  }
1181
1191
  // headers: JSON by default, plus any auth + overrides
1182
1192
  const headers = Object.assign(Object.assign(Object.assign({}, (body instanceof FormData ? {} : { "Content-Type": "application/json" })), getAuthorizationHeader()), customHeaders);
@@ -1213,13 +1223,11 @@ function requestPatch(url_1) {
1213
1223
  });
1214
1224
  }
1215
1225
  // Performs PATCH request for file sharing
1216
- function fetchSharePatch(file) {
1217
- return __awaiter(this, void 0, void 0, function* () {
1226
+ function fetchSharePatch(file_1) {
1227
+ return __awaiter(this, arguments, void 0, function* (file, appKey = null) {
1218
1228
  const cleanEndpoint = '/files/share';
1219
- const baseUrl = getAppConfig(cleanEndpoint);
1220
- const baseSlices = baseUrl.split("/").filter(Boolean);
1221
- const url = ensureAbstractUrl(cleanEndpoint, baseSlices);
1222
1229
  // build final URL
1230
+ const url = get_app_config_url(cleanEndpoint);
1223
1231
  const token = localStorage.getItem('token');
1224
1232
  const body = JSON.stringify(file);
1225
1233
  const method = 'PATCH';
@@ -1277,31 +1285,6 @@ function Spinner() {
1277
1285
  return (jsx("p", { className: 'animate-pulse', children: "Loading\u2026" }));
1278
1286
  }
1279
1287
 
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
1288
  // src/read_utils.ts
1306
1289
  /**
1307
1290
  * Attempt to load the Node-only modules.
@@ -1349,5 +1332,16 @@ function readJsonFile(relativeOrAbsolutePath) {
1349
1332
  });
1350
1333
  }
1351
1334
 
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 };
1335
+ function loadConfig() {
1336
+ return __awaiter(this, void 0, void 0, function* () {
1337
+ const base = (process.env.BASE_API_URL || "").replace(/\/+$/, "");
1338
+ const url = `${base}/config.json`;
1339
+ const res = yield fetch(url);
1340
+ if (!res.ok)
1341
+ throw new Error(`Failed to load ${url}: ${res.status}`);
1342
+ yield res.json();
1343
+ });
1344
+ }
1345
+
1346
+ 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, loadConfig, make_path, make_sanitized_path, normalizeUrl, readFileContents, readJsonFile, requestPatch, requireToken, sanitizeFilename, secureFetchIt, stripPrefixes, truncateString };
1353
1347
  //# sourceMappingURL=index.js.map