@putkoff/abstract-utilities 0.1.101 → 0.1.103
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 +2 -1
- package/dist/cjs/index.js +29 -11
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/functions/fetch_utils/src/fetchIt_utils.d.ts +2 -1
- package/dist/esm/index.js +29 -12
- package/dist/esm/index.js.map +1 -1
- package/dist/functions/fetch_utils/src/fetchIt_utils.d.ts +2 -1
- package/dist/index.d.ts +3 -2
- package/package.json +1 -1
|
@@ -7,8 +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
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
|
-
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>;
|
|
13
|
+
export declare function secureFetchIt(endpoint: string, body?: unknown, method?: string, headers?: Record<string, string> | null, blob?: boolean, noApi?: boolean, withCredentials?: boolean, returnJson?: boolean, returnReult?: boolean): Promise<Blob>;
|
|
13
14
|
export declare function requestPatch(url: string, body?: unknown): Promise<Response>;
|
|
14
15
|
export declare function fetchSharePatch(file: unknown): Promise<void>;
|
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);
|
|
@@ -1127,17 +1146,13 @@ function fetchIt(endpoint_1) {
|
|
|
1127
1146
|
});
|
|
1128
1147
|
}
|
|
1129
1148
|
function secureFetchIt(endpoint_1) {
|
|
1130
|
-
return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, customHeaders = null, blob = false, noApi = false, withCredentials = true, returnJson = true) {
|
|
1149
|
+
return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, customHeaders = null, blob = false, noApi = false, withCredentials = true, returnJson = true, returnReult = 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;
|
|
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 = {
|
|
@@ -1158,6 +1173,8 @@ function secureFetchIt(endpoint_1) {
|
|
|
1158
1173
|
}
|
|
1159
1174
|
if (blob)
|
|
1160
1175
|
return res.blob();
|
|
1176
|
+
if (returnReult)
|
|
1177
|
+
return getResult(res.json());
|
|
1161
1178
|
if (returnJson)
|
|
1162
1179
|
return res.json();
|
|
1163
1180
|
return res;
|
|
@@ -1176,8 +1193,8 @@ function fetchSharePatch(file) {
|
|
|
1176
1193
|
const cleanEndpoint = '/files/share';
|
|
1177
1194
|
const baseUrl = getAppConfig(cleanEndpoint);
|
|
1178
1195
|
const baseSlices = baseUrl.split("/").filter(Boolean);
|
|
1179
|
-
// build final URL
|
|
1180
1196
|
const url = ensureAbstractUrl(cleanEndpoint, baseSlices);
|
|
1197
|
+
// build final URL
|
|
1181
1198
|
const token = localStorage.getItem('token');
|
|
1182
1199
|
const body = JSON.stringify(file);
|
|
1183
1200
|
const method = 'PATCH';
|
|
@@ -1370,7 +1387,7 @@ function uploadFiles(file_1) {
|
|
|
1370
1387
|
formData.append('file', file);
|
|
1371
1388
|
formData.append('subdir', subdir.trim());
|
|
1372
1389
|
try {
|
|
1373
|
-
const json = yield secureFetchIt('upload', formData, 'POST', null, false,
|
|
1390
|
+
const json = yield secureFetchIt('upload', formData, 'POST', null, false, false);
|
|
1374
1391
|
if (!json || typeof json !== 'object') {
|
|
1375
1392
|
throw new Error('Invalid response from server.');
|
|
1376
1393
|
}
|
|
@@ -1687,5 +1704,5 @@ function useFiles() {
|
|
|
1687
1704
|
};
|
|
1688
1705
|
}
|
|
1689
1706
|
|
|
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 };
|
|
1707
|
+
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
1708
|
//# sourceMappingURL=index.js.map
|