@putkoff/abstract-utilities 0.1.1 → 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 +39 -16
- 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 +39 -17
- 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
|
}
|
|
@@ -1173,15 +1188,22 @@ function requestPatch(url_1) {
|
|
|
1173
1188
|
// Performs PATCH request for file sharing
|
|
1174
1189
|
function fetchSharePatch(file) {
|
|
1175
1190
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1176
|
-
const
|
|
1191
|
+
const cleanEndpoint = '/files/share';
|
|
1192
|
+
const baseUrl = getAppConfig(cleanEndpoint);
|
|
1193
|
+
const baseSlices = baseUrl.split("/").filter(Boolean);
|
|
1194
|
+
const url = ensureAbstractUrl(cleanEndpoint, baseSlices);
|
|
1195
|
+
// build final URL
|
|
1177
1196
|
const token = localStorage.getItem('token');
|
|
1197
|
+
const body = JSON.stringify(file);
|
|
1198
|
+
const method = 'PATCH';
|
|
1199
|
+
const headers = {
|
|
1200
|
+
'Content-Type': 'application/json',
|
|
1201
|
+
'Authorization': `Bearer ${token}`,
|
|
1202
|
+
};
|
|
1178
1203
|
const resp = yield fetch(url, {
|
|
1179
|
-
method
|
|
1180
|
-
headers
|
|
1181
|
-
|
|
1182
|
-
'Authorization': `Bearer ${token}`,
|
|
1183
|
-
},
|
|
1184
|
-
body: JSON.stringify(file),
|
|
1204
|
+
method,
|
|
1205
|
+
headers,
|
|
1206
|
+
body
|
|
1185
1207
|
});
|
|
1186
1208
|
if (!resp.ok) {
|
|
1187
1209
|
console.error('Error from server', yield resp.text());
|
|
@@ -1680,5 +1702,5 @@ function useFiles() {
|
|
|
1680
1702
|
};
|
|
1681
1703
|
}
|
|
1682
1704
|
|
|
1683
|
-
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 };
|
|
1684
1706
|
//# sourceMappingURL=index.js.map
|