@putkoff/abstract-utilities 0.0.7 → 0.1.1
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 -0
- package/dist/cjs/functions/fetch_utils/index.d.ts +1 -1
- package/dist/cjs/functions/fetch_utils/src/getAppConfig.d.ts +1 -0
- package/dist/cjs/functions/fetch_utils/src/index.d.ts +1 -1
- package/dist/cjs/index.d.ts +0 -1
- package/dist/cjs/index.js +14 -23
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utils/imports.d.ts +1 -0
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/cjs/utils/src/Input.d.ts +13 -0
- package/dist/cjs/utils/src/config.d.ts +5 -0
- package/dist/cjs/utils/src/index.d.ts +2 -0
- package/dist/esm/functions/fetch_utils/imports.d.ts +1 -0
- package/dist/esm/functions/fetch_utils/index.d.ts +1 -1
- package/dist/esm/functions/fetch_utils/src/getAppConfig.d.ts +1 -0
- package/dist/esm/functions/fetch_utils/src/index.d.ts +1 -1
- package/dist/esm/index.d.ts +0 -1
- package/dist/esm/index.js +15 -23
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/imports.d.ts +1 -0
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/src/Input.d.ts +13 -0
- package/dist/esm/utils/src/config.d.ts +5 -0
- package/dist/esm/utils/src/index.d.ts +2 -0
- package/dist/functions/fetch_utils/imports.d.ts +1 -0
- package/dist/functions/fetch_utils/index.d.ts +1 -1
- package/dist/functions/fetch_utils/src/getAppConfig.d.ts +1 -0
- package/dist/functions/fetch_utils/src/index.d.ts +1 -1
- package/dist/index.d.ts +1 -7
- package/dist/utils/imports.d.ts +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/src/Input.d.ts +13 -0
- package/dist/utils/src/config.d.ts +5 -0
- package/dist/utils/src/index.d.ts +2 -0
- package/package.json +1 -1
|
@@ -4,4 +4,5 @@ export { stripPrefixes } from './../string_utils';
|
|
|
4
4
|
export { alertit } from './../rndm_utils';
|
|
5
5
|
export { ensure_list } from './../type_utils';
|
|
6
6
|
export { eatInner } from './../string_utils';
|
|
7
|
+
export { AppConfig } from './../../utils/src/config';
|
|
7
8
|
export type { LogoutButtonProps, FetchVariables } from './../../types';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './src';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getAppConfig(endpoint: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './fetchIt_utils';
|
package/dist/cjs/index.d.ts
CHANGED
package/dist/cjs/index.js
CHANGED
|
@@ -48,18 +48,6 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
48
48
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
exports.AppConfig = void 0;
|
|
52
|
-
function loadConfig() {
|
|
53
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
const base = (process.env.PUBLIC_URL || "").replace(/\/+$/, "");
|
|
55
|
-
const url = `${base}/config.json`;
|
|
56
|
-
const res = yield fetch(url);
|
|
57
|
-
if (!res.ok)
|
|
58
|
-
throw new Error(`Failed to load ${url}: ${res.status}`);
|
|
59
|
-
exports.AppConfig = yield res.json();
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
51
|
/** Helper function to trigger file download */
|
|
64
52
|
function triggerDownload(blob, filename) {
|
|
65
53
|
const url = URL.createObjectURL(blob);
|
|
@@ -1021,13 +1009,6 @@ function ensureAbstractUrl(endpoint, slices = []) {
|
|
|
1021
1009
|
// 5) hand it back to make_path to join “target” + “strippedEndpoint”
|
|
1022
1010
|
return make_path(target, strippedEndpoint);
|
|
1023
1011
|
}
|
|
1024
|
-
/** Pulls base-URL from AppConfig.API_BASE_URL, strips trailing slashes */
|
|
1025
|
-
function getRawConfigUrl() {
|
|
1026
|
-
var _a;
|
|
1027
|
-
// Now AppConfig[key] is allowed because of the index signature
|
|
1028
|
-
const rawBase = (_a = exports.AppConfig.API_BASE_URL) !== null && _a !== void 0 ? _a : "";
|
|
1029
|
-
return rawBase.replace(/\/+$/, "");
|
|
1030
|
-
}
|
|
1031
1012
|
// Constructs API URL from endpoint
|
|
1032
1013
|
function api(endpoint) {
|
|
1033
1014
|
return ensureAbstractUrl(endpoint);
|
|
@@ -1117,6 +1098,18 @@ function getFetchVars(headers = null, method = null, body = null) {
|
|
|
1117
1098
|
return { method, headers, body };
|
|
1118
1099
|
}
|
|
1119
1100
|
|
|
1101
|
+
function getAppConfig(endpoint) {
|
|
1102
|
+
var _a;
|
|
1103
|
+
const rawBase = (_a = void 0 ) !== null && _a !== void 0 ? _a : "";
|
|
1104
|
+
const base = rawBase.replace(/\/+$/, "");
|
|
1105
|
+
// strip any leading slashes on endpoint, then prefix “/api/”
|
|
1106
|
+
const cleanEndpoint = endpoint.replace(/^\/+/, "");
|
|
1107
|
+
const url = base
|
|
1108
|
+
? `${base}/${cleanEndpoint}`
|
|
1109
|
+
: `/api/${cleanEndpoint}`;
|
|
1110
|
+
return url;
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1120
1113
|
/**
|
|
1121
1114
|
|
|
1122
1115
|
***Changes**: None, as it’s self-contained and doesn’t rely on external imports.
|
|
@@ -1142,7 +1135,7 @@ function secureFetchIt(endpoint_1) {
|
|
|
1142
1135
|
method = method || "GET";
|
|
1143
1136
|
const cleanEndpoint = endpoint.replace(/^\/+/, "");
|
|
1144
1137
|
// decide whether to build off your API_BASE_URL or not
|
|
1145
|
-
const rawBase =
|
|
1138
|
+
const rawBase = getAppConfig(cleanEndpoint);
|
|
1146
1139
|
const baseSlices = noApi
|
|
1147
1140
|
? []
|
|
1148
1141
|
: rawBase.split("/").filter(Boolean);
|
|
@@ -1183,8 +1176,7 @@ function requestPatch(url_1) {
|
|
|
1183
1176
|
// Performs PATCH request for file sharing
|
|
1184
1177
|
function fetchSharePatch(file) {
|
|
1185
1178
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1186
|
-
const
|
|
1187
|
-
const url = `${base}/files/share`;
|
|
1179
|
+
const url = getAppConfig('/files/share');
|
|
1188
1180
|
const token = localStorage.getItem('token');
|
|
1189
1181
|
const resp = yield fetch(url, {
|
|
1190
1182
|
method: 'PATCH',
|
|
@@ -1761,7 +1753,6 @@ exports.initSelectAll = initSelectAll;
|
|
|
1761
1753
|
exports.isLoggedIn = isLoggedIn;
|
|
1762
1754
|
exports.isTokenExpired = isTokenExpired;
|
|
1763
1755
|
exports.listFiles = listFiles;
|
|
1764
|
-
exports.loadConfig = loadConfig;
|
|
1765
1756
|
exports.make_path = make_path;
|
|
1766
1757
|
exports.make_sanitized_path = make_sanitized_path;
|
|
1767
1758
|
exports.normalizeUrl = normalizeUrl;
|