@putkoff/abstract-utilities 0.1.116 → 0.1.118
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/fetch_utils/imports.d.ts +1 -1
- package/dist/cjs/functions/fetch_utils/src/fetchIt_utils.d.ts +2 -2
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +49 -51
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/src/utils.d.ts +6 -0
- package/dist/cjs/utils/src/index.d.ts +1 -0
- package/dist/esm/functions/fetch_utils/imports.d.ts +1 -1
- package/dist/esm/functions/fetch_utils/src/fetchIt_utils.d.ts +2 -2
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +49 -52
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/src/utils.d.ts +6 -0
- package/dist/esm/utils/src/index.d.ts +1 -0
- package/dist/functions/fetch_utils/imports.d.ts +1 -1
- package/dist/functions/fetch_utils/src/fetchIt_utils.d.ts +2 -2
- package/dist/index.d.ts +11 -3
- package/dist/types/src/utils.d.ts +6 -0
- package/dist/utils/src/index.d.ts +1 -0
- package/package.json +1 -1
- package/dist/cjs/functions/read_utils/imports.d.ts +0 -3
- package/dist/esm/functions/read_utils/imports.d.ts +0 -3
package/dist/esm/index.js
CHANGED
|
@@ -1013,21 +1013,29 @@ function alertit(obj = null) {
|
|
|
1013
1013
|
alert(msg);
|
|
1014
1014
|
}
|
|
1015
1015
|
|
|
1016
|
-
|
|
1017
|
-
function
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
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
|
-
|
|
1029
|
-
function
|
|
1030
|
-
|
|
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,12 +1163,17 @@ 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(
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1166
|
+
function get_app_config_url(endpoint_1) {
|
|
1167
|
+
return __awaiter(this, arguments, void 0, function* (endpoint, appKey = null) {
|
|
1168
|
+
const cleanEndpoint = endpoint.replace(/^\/+/, "");
|
|
1169
|
+
const config = yield getConfig();
|
|
1170
|
+
const baseUrl = JSON.stringify(config);
|
|
1171
|
+
appKey = appKey || 'BASE_API_URL';
|
|
1172
|
+
const base = baseUrl[appKey];
|
|
1173
|
+
const baseSlices = base.split("/").filter(Boolean);
|
|
1174
|
+
const url = ensureAbstractUrl(cleanEndpoint, baseSlices);
|
|
1175
|
+
return url;
|
|
1176
|
+
});
|
|
1164
1177
|
}
|
|
1165
1178
|
function fetchIt(endpoint_1) {
|
|
1166
1179
|
return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, headers = null, blob = null, no_api = false, requireAuth = true) {
|
|
@@ -1176,7 +1189,7 @@ function secureFetchIt(endpoint_1) {
|
|
|
1176
1189
|
method = method || "GET";
|
|
1177
1190
|
let url = endpoint;
|
|
1178
1191
|
if (!noApi) {
|
|
1179
|
-
url = get_app_config_url(
|
|
1192
|
+
url = yield get_app_config_url(endpoint);
|
|
1180
1193
|
}
|
|
1181
1194
|
// headers: JSON by default, plus any auth + overrides
|
|
1182
1195
|
const headers = Object.assign(Object.assign(Object.assign({}, (body instanceof FormData ? {} : { "Content-Type": "application/json" })), getAuthorizationHeader()), customHeaders);
|
|
@@ -1213,13 +1226,11 @@ function requestPatch(url_1) {
|
|
|
1213
1226
|
});
|
|
1214
1227
|
}
|
|
1215
1228
|
// Performs PATCH request for file sharing
|
|
1216
|
-
function fetchSharePatch(
|
|
1217
|
-
return __awaiter(this,
|
|
1229
|
+
function fetchSharePatch(file_1) {
|
|
1230
|
+
return __awaiter(this, arguments, void 0, function* (file, appKey = null) {
|
|
1218
1231
|
const cleanEndpoint = '/files/share';
|
|
1219
|
-
const baseUrl = getAppConfig(cleanEndpoint);
|
|
1220
|
-
const baseSlices = baseUrl.split("/").filter(Boolean);
|
|
1221
|
-
const url = ensureAbstractUrl(cleanEndpoint, baseSlices);
|
|
1222
1232
|
// build final URL
|
|
1233
|
+
const url = yield get_app_config_url(cleanEndpoint);
|
|
1223
1234
|
const token = localStorage.getItem('token');
|
|
1224
1235
|
const body = JSON.stringify(file);
|
|
1225
1236
|
const method = 'PATCH';
|
|
@@ -1277,31 +1288,6 @@ function Spinner() {
|
|
|
1277
1288
|
return (jsx("p", { className: 'animate-pulse', children: "Loading\u2026" }));
|
|
1278
1289
|
}
|
|
1279
1290
|
|
|
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
1291
|
// src/read_utils.ts
|
|
1306
1292
|
/**
|
|
1307
1293
|
* Attempt to load the Node-only modules.
|
|
@@ -1349,5 +1335,16 @@ function readJsonFile(relativeOrAbsolutePath) {
|
|
|
1349
1335
|
});
|
|
1350
1336
|
}
|
|
1351
1337
|
|
|
1352
|
-
|
|
1338
|
+
function loadConfig() {
|
|
1339
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1340
|
+
const base = (process.env.BASE_API_URL || "").replace(/\/+$/, "");
|
|
1341
|
+
const url = `${base}/config.json`;
|
|
1342
|
+
const res = yield fetch(url);
|
|
1343
|
+
if (!res.ok)
|
|
1344
|
+
throw new Error(`Failed to load ${url}: ${res.status}`);
|
|
1345
|
+
yield res.json();
|
|
1346
|
+
});
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
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
1350
|
//# sourceMappingURL=index.js.map
|