@putkoff/abstract-utilities 0.1.101 → 0.1.102
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/src/fetchIt_utils.d.ts +1 -0
- package/dist/cjs/index.js +26 -10
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/functions/fetch_utils/src/fetchIt_utils.d.ts +1 -0
- package/dist/esm/index.js +26 -11
- package/dist/esm/index.js.map +1 -1
- package/dist/functions/fetch_utils/src/fetchIt_utils.d.ts +1 -0
- package/dist/index.d.ts +2 -1
- package/package.json +1 -1
|
@@ -7,6 +7,7 @@
|
|
|
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
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>;
|
|
11
12
|
export declare function secureFetchIt<T>(endpoint: string, body?: unknown, method?: string, headers?: Record<string, string> | null, blob?: false, noApi?: boolean, requireAuth?: boolean): Promise<T>;
|
|
12
13
|
export declare function secureFetchIt(endpoint: string, body?: unknown, method?: string, headers?: Record<string, string> | null, blob?: boolean, noApi?: boolean, withCredentials?: boolean, returnJson?: boolean): Promise<Blob>;
|
package/dist/esm/index.js
CHANGED
|
@@ -1006,6 +1006,18 @@ function ensureAbstractUrl(endpoint, slices = []) {
|
|
|
1006
1006
|
// 5) hand it back to make_path to join “target” + “strippedEndpoint”
|
|
1007
1007
|
return make_path(target, strippedEndpoint);
|
|
1008
1008
|
}
|
|
1009
|
+
/**
|
|
1010
|
+
* Unwraps nested { result } fields until you hit a non-object or no more "result" keys.
|
|
1011
|
+
*/
|
|
1012
|
+
function getResult(obj) {
|
|
1013
|
+
let current = obj;
|
|
1014
|
+
while (current &&
|
|
1015
|
+
typeof current === "object" &&
|
|
1016
|
+
Object.prototype.hasOwnProperty.call(current, "result")) {
|
|
1017
|
+
current = current.result;
|
|
1018
|
+
}
|
|
1019
|
+
return current;
|
|
1020
|
+
}
|
|
1009
1021
|
// Constructs API URL from endpoint
|
|
1010
1022
|
function api(endpoint) {
|
|
1011
1023
|
return ensureAbstractUrl(endpoint);
|
|
@@ -1118,6 +1130,13 @@ function getAppConfig(endpoint) {
|
|
|
1118
1130
|
/** Pulls base-URL from AppConfig.API_BASE_URL, strips trailing slashes */
|
|
1119
1131
|
// src/functions/fetch/secureFetchIt.ts
|
|
1120
1132
|
// --- fetch_utils/src/fetch_utils.ts ----------------------------
|
|
1133
|
+
function get_app_config_url(endpoint) {
|
|
1134
|
+
const cleanEndpoint = endpoint.replace(/^\/+/, "");
|
|
1135
|
+
const baseUrl = getAppConfig(cleanEndpoint);
|
|
1136
|
+
const baseSlices = baseUrl.split("/").filter(Boolean);
|
|
1137
|
+
const url = ensureAbstractUrl(cleanEndpoint, baseSlices);
|
|
1138
|
+
return url;
|
|
1139
|
+
}
|
|
1121
1140
|
function fetchIt(endpoint_1) {
|
|
1122
1141
|
return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, headers = null, blob = null, no_api = false, requireAuth = true) {
|
|
1123
1142
|
const vars = getFetchVars(headers, method, body);
|
|
@@ -1130,14 +1149,10 @@ function secureFetchIt(endpoint_1) {
|
|
|
1130
1149
|
return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, customHeaders = null, blob = false, noApi = false, withCredentials = true, returnJson = true) {
|
|
1131
1150
|
// strip leading slashes off the endpoint
|
|
1132
1151
|
method = method || "GET";
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
? []
|
|
1138
|
-
: rawBase.split("/").filter(Boolean);
|
|
1139
|
-
// build final URL
|
|
1140
|
-
const url = ensureAbstractUrl(cleanEndpoint, baseSlices);
|
|
1152
|
+
let url = endpoint.replace(/^\/+/, "");
|
|
1153
|
+
if (!noApi) {
|
|
1154
|
+
url = get_app_config_url(url);
|
|
1155
|
+
}
|
|
1141
1156
|
// headers: JSON by default, plus any auth + overrides
|
|
1142
1157
|
const headers = Object.assign(Object.assign(Object.assign({}, (body instanceof FormData ? {} : { "Content-Type": "application/json" })), getAuthorizationHeader()), customHeaders);
|
|
1143
1158
|
const opts = {
|
|
@@ -1159,7 +1174,7 @@ function secureFetchIt(endpoint_1) {
|
|
|
1159
1174
|
if (blob)
|
|
1160
1175
|
return res.blob();
|
|
1161
1176
|
if (returnJson)
|
|
1162
|
-
return res.json();
|
|
1177
|
+
return getResult(res.json());
|
|
1163
1178
|
return res;
|
|
1164
1179
|
});
|
|
1165
1180
|
}
|
|
@@ -1176,8 +1191,8 @@ function fetchSharePatch(file) {
|
|
|
1176
1191
|
const cleanEndpoint = '/files/share';
|
|
1177
1192
|
const baseUrl = getAppConfig(cleanEndpoint);
|
|
1178
1193
|
const baseSlices = baseUrl.split("/").filter(Boolean);
|
|
1179
|
-
// build final URL
|
|
1180
1194
|
const url = ensureAbstractUrl(cleanEndpoint, baseSlices);
|
|
1195
|
+
// build final URL
|
|
1181
1196
|
const token = localStorage.getItem('token');
|
|
1182
1197
|
const body = JSON.stringify(file);
|
|
1183
1198
|
const method = 'PATCH';
|
|
@@ -1687,5 +1702,5 @@ function useFiles() {
|
|
|
1687
1702
|
};
|
|
1688
1703
|
}
|
|
1689
1704
|
|
|
1690
|
-
export { API_PREFIX, BASE_URL, Button, Checkbox, DEV_PREFIX, DOMAIN_NAME, Input, PROD_PREFIX, PROTOCOL, SUB_DIR, Spinner, alertit, currentUsername, currentUsernames, decodeJwt, directDownload, downloadFile, downloadRow, downloadSelect, downloadSelected, eatAll, eatEnd, eatInner, eatOuter, ensure_list, fetchIt, fetchSharePatch, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, getAbsDir, getAbsPath, getAuthorizationHeader, getBaseDir, getComponentsUtilsDirectory, getDbConfigsPath, getDistDir, getEnvDir, getEnvPath, getFunctionsDir, getFunctionsUtilsDirectory, getHooksUtilsDirectory, getLibUtilsDirectory, getPublicDir, getSchemasDirPath, getSchemasPath, getSrcDir, getSubstring, getToggleShare, getToken, get_basename, get_dirname, get_extname, get_filename, get_splitext, get_window, get_window_location, get_window_parts, get_window_pathname, initSelectAll, isLoggedIn, isTokenExpired, listFiles, make_path, make_sanitized_path, normalizeUrl, patchFileSetting, removeFile, removeRow, removeSelected, requestPatch, requireToken, sanitizeFilename, secureFetchIt, stripPrefixes, syncHeaderCheckbox, toggleCheckboxes, toggleShare, triggerDownload, truncateString, updateFileShare, uploadFile, uploadFiles, useDeleteFile, useFiles, useLoadFiles, usePatchShareSettings, useToggleShare };
|
|
1705
|
+
export { API_PREFIX, BASE_URL, Button, Checkbox, DEV_PREFIX, DOMAIN_NAME, Input, PROD_PREFIX, PROTOCOL, SUB_DIR, Spinner, alertit, currentUsername, currentUsernames, decodeJwt, directDownload, downloadFile, downloadRow, downloadSelect, downloadSelected, eatAll, eatEnd, eatInner, eatOuter, ensure_list, fetchIt, fetchSharePatch, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, getAbsDir, getAbsPath, getAuthorizationHeader, getBaseDir, getComponentsUtilsDirectory, getDbConfigsPath, getDistDir, getEnvDir, getEnvPath, getFunctionsDir, getFunctionsUtilsDirectory, getHooksUtilsDirectory, getLibUtilsDirectory, getPublicDir, getSchemasDirPath, getSchemasPath, getSrcDir, getSubstring, getToggleShare, 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, initSelectAll, isLoggedIn, isTokenExpired, listFiles, make_path, make_sanitized_path, normalizeUrl, patchFileSetting, removeFile, removeRow, removeSelected, requestPatch, requireToken, sanitizeFilename, secureFetchIt, stripPrefixes, syncHeaderCheckbox, toggleCheckboxes, toggleShare, triggerDownload, truncateString, updateFileShare, uploadFile, uploadFiles, useDeleteFile, useFiles, useLoadFiles, usePatchShareSettings, useToggleShare };
|
|
1691
1706
|
//# sourceMappingURL=index.js.map
|