@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/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 +42 -47
- 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 +42 -48
- 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): 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,9 +1166,11 @@ 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(endpoint) {
|
|
1169
|
+
function get_app_config_url(endpoint, appKey = null) {
|
|
1162
1170
|
const cleanEndpoint = endpoint.replace(/^\/+/, "");
|
|
1163
|
-
const baseUrl =
|
|
1171
|
+
const baseUrl = getConfig();
|
|
1172
|
+
appKey = appKey || 'BASE_API_URL';
|
|
1173
|
+
baseUrl[appKey];
|
|
1164
1174
|
const baseSlices = baseUrl.split("/").filter(Boolean);
|
|
1165
1175
|
const url = ensureAbstractUrl(cleanEndpoint, baseSlices);
|
|
1166
1176
|
return url;
|
|
@@ -1179,7 +1189,7 @@ function secureFetchIt(endpoint_1) {
|
|
|
1179
1189
|
method = method || "GET";
|
|
1180
1190
|
let url = endpoint;
|
|
1181
1191
|
if (!noApi) {
|
|
1182
|
-
url = get_app_config_url(
|
|
1192
|
+
url = get_app_config_url(endpoint);
|
|
1183
1193
|
}
|
|
1184
1194
|
// headers: JSON by default, plus any auth + overrides
|
|
1185
1195
|
const headers = Object.assign(Object.assign(Object.assign({}, (body instanceof FormData ? {} : { "Content-Type": "application/json" })), getAuthorizationHeader()), customHeaders);
|
|
@@ -1216,13 +1226,11 @@ function requestPatch(url_1) {
|
|
|
1216
1226
|
});
|
|
1217
1227
|
}
|
|
1218
1228
|
// Performs PATCH request for file sharing
|
|
1219
|
-
function fetchSharePatch(
|
|
1220
|
-
return __awaiter(this,
|
|
1229
|
+
function fetchSharePatch(file_1) {
|
|
1230
|
+
return __awaiter(this, arguments, void 0, function* (file, appKey = null) {
|
|
1221
1231
|
const cleanEndpoint = '/files/share';
|
|
1222
|
-
const baseUrl = getAppConfig(cleanEndpoint);
|
|
1223
|
-
const baseSlices = baseUrl.split("/").filter(Boolean);
|
|
1224
|
-
const url = ensureAbstractUrl(cleanEndpoint, baseSlices);
|
|
1225
1232
|
// build final URL
|
|
1233
|
+
const url = get_app_config_url(cleanEndpoint);
|
|
1226
1234
|
const token = localStorage.getItem('token');
|
|
1227
1235
|
const body = JSON.stringify(file);
|
|
1228
1236
|
const method = 'PATCH';
|
|
@@ -1280,31 +1288,6 @@ function Spinner() {
|
|
|
1280
1288
|
return (jsxRuntime.jsx("p", { className: 'animate-pulse', children: "Loading\u2026" }));
|
|
1281
1289
|
}
|
|
1282
1290
|
|
|
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
1291
|
// src/read_utils.ts
|
|
1309
1292
|
/**
|
|
1310
1293
|
* Attempt to load the Node-only modules.
|
|
@@ -1352,6 +1335,17 @@ function readJsonFile(relativeOrAbsolutePath) {
|
|
|
1352
1335
|
});
|
|
1353
1336
|
}
|
|
1354
1337
|
|
|
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
|
+
|
|
1355
1349
|
Object.defineProperty(exports, "useCallback", {
|
|
1356
1350
|
enumerable: true,
|
|
1357
1351
|
get: function () { return react.useCallback; }
|
|
@@ -1432,6 +1426,7 @@ exports.get_window_parts = get_window_parts;
|
|
|
1432
1426
|
exports.get_window_pathname = get_window_pathname;
|
|
1433
1427
|
exports.isLoggedIn = isLoggedIn;
|
|
1434
1428
|
exports.isTokenExpired = isTokenExpired;
|
|
1429
|
+
exports.loadConfig = loadConfig;
|
|
1435
1430
|
exports.make_path = make_path;
|
|
1436
1431
|
exports.make_sanitized_path = make_sanitized_path;
|
|
1437
1432
|
exports.normalizeUrl = normalizeUrl;
|