@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
|
@@ -5,4 +5,4 @@ export { alertit } from './../rndm_utils';
|
|
|
5
5
|
export { ensure_list } from './../type_utils';
|
|
6
6
|
export { eatInner } from './../string_utils';
|
|
7
7
|
export type { LogoutButtonProps, FetchVariables } from './../../types';
|
|
8
|
-
export {
|
|
8
|
+
export { getConfig } from './../config_utils';
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
/** Pulls base-URL from AppConfig.API_BASE_URL, strips trailing slashes */
|
|
10
|
-
export declare function get_app_config_url(endpoint: any): string
|
|
10
|
+
export declare function get_app_config_url(endpoint: any, appKey?: any): Promise<string>;
|
|
11
11
|
export declare function fetchIt(endpoint: string, body?: unknown, method?: string | null, headers?: Record<string, string> | null, blob?: boolean | null, no_api?: boolean, requireAuth?: boolean): Promise<unknown>;
|
|
12
12
|
export declare function secureFetchIt<T>(endpoint: any, body?: any, method?: any, headers?: Record<string, string> | null, blob?: boolean, noApi?: boolean, withCredentials?: boolean, returnJson?: boolean, returnReult?: boolean): Promise<T>;
|
|
13
13
|
export declare function secureFetchIt(endpoint: any, body?: any, method?: any, headers?: Record<string, string> | null, blob?: boolean, noApi?: boolean, withCredentials?: boolean, returnJson?: boolean, returnReult?: boolean): Promise<Blob>;
|
|
14
14
|
export declare function requestPatch(url: string, body?: unknown): Promise<Response>;
|
|
15
|
-
export declare function fetchSharePatch(file: unknown): Promise<void>;
|
|
15
|
+
export declare function fetchSharePatch(file: unknown, appKey?: any): Promise<void>;
|
package/dist/cjs/index.d.ts
CHANGED
package/dist/cjs/index.js
CHANGED
|
@@ -1016,21 +1016,29 @@ function alertit(obj = null) {
|
|
|
1016
1016
|
alert(msg);
|
|
1017
1017
|
}
|
|
1018
1018
|
|
|
1019
|
-
|
|
1020
|
-
function
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1019
|
+
let _cachedConfig = null;
|
|
1020
|
+
function loadConfig$1() {
|
|
1021
|
+
return __awaiter(this, arguments, void 0, function* (filePath = null) {
|
|
1022
|
+
// 1. If nobody passed a custom path, we default to "config.json" (relative)
|
|
1023
|
+
const relativePath = filePath || 'config.json';
|
|
1024
|
+
// 2. Resolve it against the running page’s URL (document.baseURI)
|
|
1025
|
+
const configUrl = new URL(relativePath, document.baseURI).href;
|
|
1026
|
+
// 3. Fetch + cache
|
|
1027
|
+
if (_cachedConfig)
|
|
1028
|
+
return _cachedConfig;
|
|
1029
|
+
const res = yield fetch(configUrl);
|
|
1030
|
+
if (!res.ok) {
|
|
1031
|
+
throw new Error(`Could not fetch ${configUrl}: ${res.status}`);
|
|
1032
|
+
}
|
|
1033
|
+
_cachedConfig = (yield res.json());
|
|
1034
|
+
return _cachedConfig;
|
|
1035
|
+
});
|
|
1030
1036
|
}
|
|
1031
|
-
|
|
1032
|
-
function
|
|
1033
|
-
|
|
1037
|
+
function getConfig(key) {
|
|
1038
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1039
|
+
const cfg = yield loadConfig$1();
|
|
1040
|
+
return key ? cfg[key] : cfg;
|
|
1041
|
+
});
|
|
1034
1042
|
}
|
|
1035
1043
|
|
|
1036
1044
|
function ensureAbstractUrl(endpoint, slices = []) {
|
|
@@ -1158,12 +1166,17 @@ function getFetchVars(headers = null, method = null, body = null) {
|
|
|
1158
1166
|
/** Pulls base-URL from AppConfig.API_BASE_URL, strips trailing slashes */
|
|
1159
1167
|
// src/functions/fetch/secureFetchIt.ts
|
|
1160
1168
|
// --- fetch_utils/src/fetch_utils.ts ----------------------------
|
|
1161
|
-
function get_app_config_url(
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1169
|
+
function get_app_config_url(endpoint_1) {
|
|
1170
|
+
return __awaiter(this, arguments, void 0, function* (endpoint, appKey = null) {
|
|
1171
|
+
const cleanEndpoint = endpoint.replace(/^\/+/, "");
|
|
1172
|
+
const config = yield getConfig();
|
|
1173
|
+
const baseUrl = JSON.stringify(config);
|
|
1174
|
+
appKey = appKey || 'BASE_API_URL';
|
|
1175
|
+
const base = baseUrl[appKey];
|
|
1176
|
+
const baseSlices = base.split("/").filter(Boolean);
|
|
1177
|
+
const url = ensureAbstractUrl(cleanEndpoint, baseSlices);
|
|
1178
|
+
return url;
|
|
1179
|
+
});
|
|
1167
1180
|
}
|
|
1168
1181
|
function fetchIt(endpoint_1) {
|
|
1169
1182
|
return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, headers = null, blob = null, no_api = false, requireAuth = true) {
|
|
@@ -1179,7 +1192,7 @@ function secureFetchIt(endpoint_1) {
|
|
|
1179
1192
|
method = method || "GET";
|
|
1180
1193
|
let url = endpoint;
|
|
1181
1194
|
if (!noApi) {
|
|
1182
|
-
url = get_app_config_url(
|
|
1195
|
+
url = yield get_app_config_url(endpoint);
|
|
1183
1196
|
}
|
|
1184
1197
|
// headers: JSON by default, plus any auth + overrides
|
|
1185
1198
|
const headers = Object.assign(Object.assign(Object.assign({}, (body instanceof FormData ? {} : { "Content-Type": "application/json" })), getAuthorizationHeader()), customHeaders);
|
|
@@ -1216,13 +1229,11 @@ function requestPatch(url_1) {
|
|
|
1216
1229
|
});
|
|
1217
1230
|
}
|
|
1218
1231
|
// Performs PATCH request for file sharing
|
|
1219
|
-
function fetchSharePatch(
|
|
1220
|
-
return __awaiter(this,
|
|
1232
|
+
function fetchSharePatch(file_1) {
|
|
1233
|
+
return __awaiter(this, arguments, void 0, function* (file, appKey = null) {
|
|
1221
1234
|
const cleanEndpoint = '/files/share';
|
|
1222
|
-
const baseUrl = getAppConfig(cleanEndpoint);
|
|
1223
|
-
const baseSlices = baseUrl.split("/").filter(Boolean);
|
|
1224
|
-
const url = ensureAbstractUrl(cleanEndpoint, baseSlices);
|
|
1225
1235
|
// build final URL
|
|
1236
|
+
const url = yield get_app_config_url(cleanEndpoint);
|
|
1226
1237
|
const token = localStorage.getItem('token');
|
|
1227
1238
|
const body = JSON.stringify(file);
|
|
1228
1239
|
const method = 'PATCH';
|
|
@@ -1280,31 +1291,6 @@ function Spinner() {
|
|
|
1280
1291
|
return (jsxRuntime.jsx("p", { className: 'animate-pulse', children: "Loading\u2026" }));
|
|
1281
1292
|
}
|
|
1282
1293
|
|
|
1283
|
-
let _cachedConfig = null;
|
|
1284
|
-
function loadConfig() {
|
|
1285
|
-
return __awaiter(this, arguments, void 0, function* (filePath = null) {
|
|
1286
|
-
// 1. If nobody passed a custom path, we default to "config.json" (relative)
|
|
1287
|
-
const relativePath = filePath || 'config.json';
|
|
1288
|
-
// 2. Resolve it against the running page’s URL (document.baseURI)
|
|
1289
|
-
const configUrl = new URL(relativePath, document.baseURI).href;
|
|
1290
|
-
// 3. Fetch + cache
|
|
1291
|
-
if (_cachedConfig)
|
|
1292
|
-
return _cachedConfig;
|
|
1293
|
-
const res = yield fetch(configUrl);
|
|
1294
|
-
if (!res.ok) {
|
|
1295
|
-
throw new Error(`Could not fetch ${configUrl}: ${res.status}`);
|
|
1296
|
-
}
|
|
1297
|
-
_cachedConfig = (yield res.json());
|
|
1298
|
-
return _cachedConfig;
|
|
1299
|
-
});
|
|
1300
|
-
}
|
|
1301
|
-
function getConfig(key) {
|
|
1302
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1303
|
-
const cfg = yield loadConfig();
|
|
1304
|
-
return key ? cfg[key] : cfg;
|
|
1305
|
-
});
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1308
1294
|
// src/read_utils.ts
|
|
1309
1295
|
/**
|
|
1310
1296
|
* Attempt to load the Node-only modules.
|
|
@@ -1352,6 +1338,17 @@ function readJsonFile(relativeOrAbsolutePath) {
|
|
|
1352
1338
|
});
|
|
1353
1339
|
}
|
|
1354
1340
|
|
|
1341
|
+
function loadConfig() {
|
|
1342
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1343
|
+
const base = (process.env.BASE_API_URL || "").replace(/\/+$/, "");
|
|
1344
|
+
const url = `${base}/config.json`;
|
|
1345
|
+
const res = yield fetch(url);
|
|
1346
|
+
if (!res.ok)
|
|
1347
|
+
throw new Error(`Failed to load ${url}: ${res.status}`);
|
|
1348
|
+
yield res.json();
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1355
1352
|
Object.defineProperty(exports, "useCallback", {
|
|
1356
1353
|
enumerable: true,
|
|
1357
1354
|
get: function () { return react.useCallback; }
|
|
@@ -1432,6 +1429,7 @@ exports.get_window_parts = get_window_parts;
|
|
|
1432
1429
|
exports.get_window_pathname = get_window_pathname;
|
|
1433
1430
|
exports.isLoggedIn = isLoggedIn;
|
|
1434
1431
|
exports.isTokenExpired = isTokenExpired;
|
|
1432
|
+
exports.loadConfig = loadConfig;
|
|
1435
1433
|
exports.make_path = make_path;
|
|
1436
1434
|
exports.make_sanitized_path = make_sanitized_path;
|
|
1437
1435
|
exports.normalizeUrl = normalizeUrl;
|