@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.
@@ -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/cjs/index.js CHANGED
@@ -1009,6 +1009,18 @@ function ensureAbstractUrl(endpoint, slices = []) {
1009
1009
  // 5) hand it back to make_path to join “target” + “strippedEndpoint”
1010
1010
  return make_path(target, strippedEndpoint);
1011
1011
  }
1012
+ /**
1013
+ * Unwraps nested { result } fields until you hit a non-object or no more "result" keys.
1014
+ */
1015
+ function getResult(obj) {
1016
+ let current = obj;
1017
+ while (current &&
1018
+ typeof current === "object" &&
1019
+ Object.prototype.hasOwnProperty.call(current, "result")) {
1020
+ current = current.result;
1021
+ }
1022
+ return current;
1023
+ }
1012
1024
  // Constructs API URL from endpoint
1013
1025
  function api(endpoint) {
1014
1026
  return ensureAbstractUrl(endpoint);
@@ -1121,6 +1133,13 @@ function getAppConfig(endpoint) {
1121
1133
  /** Pulls base-URL from AppConfig.API_BASE_URL, strips trailing slashes */
1122
1134
  // src/functions/fetch/secureFetchIt.ts
1123
1135
  // --- fetch_utils/src/fetch_utils.ts ----------------------------
1136
+ function get_app_config_url(endpoint) {
1137
+ const cleanEndpoint = endpoint.replace(/^\/+/, "");
1138
+ const baseUrl = getAppConfig(cleanEndpoint);
1139
+ const baseSlices = baseUrl.split("/").filter(Boolean);
1140
+ const url = ensureAbstractUrl(cleanEndpoint, baseSlices);
1141
+ return url;
1142
+ }
1124
1143
  function fetchIt(endpoint_1) {
1125
1144
  return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, headers = null, blob = null, no_api = false, requireAuth = true) {
1126
1145
  const vars = getFetchVars(headers, method, body);
@@ -1133,14 +1152,10 @@ function secureFetchIt(endpoint_1) {
1133
1152
  return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, customHeaders = null, blob = false, noApi = false, withCredentials = true, returnJson = true) {
1134
1153
  // strip leading slashes off the endpoint
1135
1154
  method = method || "GET";
1136
- const cleanEndpoint = endpoint.replace(/^\/+/, "");
1137
- // decide whether to build off your API_BASE_URL or not
1138
- const rawBase = getAppConfig(cleanEndpoint);
1139
- const baseSlices = noApi
1140
- ? []
1141
- : rawBase.split("/").filter(Boolean);
1142
- // build final URL
1143
- const url = ensureAbstractUrl(cleanEndpoint, baseSlices);
1155
+ let url = endpoint.replace(/^\/+/, "");
1156
+ if (!noApi) {
1157
+ url = get_app_config_url(url);
1158
+ }
1144
1159
  // headers: JSON by default, plus any auth + overrides
1145
1160
  const headers = Object.assign(Object.assign(Object.assign({}, (body instanceof FormData ? {} : { "Content-Type": "application/json" })), getAuthorizationHeader()), customHeaders);
1146
1161
  const opts = {
@@ -1162,7 +1177,7 @@ function secureFetchIt(endpoint_1) {
1162
1177
  if (blob)
1163
1178
  return res.blob();
1164
1179
  if (returnJson)
1165
- return res.json();
1180
+ return getResult(res.json());
1166
1181
  return res;
1167
1182
  });
1168
1183
  }
@@ -1179,8 +1194,8 @@ function fetchSharePatch(file) {
1179
1194
  const cleanEndpoint = '/files/share';
1180
1195
  const baseUrl = getAppConfig(cleanEndpoint);
1181
1196
  const baseSlices = baseUrl.split("/").filter(Boolean);
1182
- // build final URL
1183
1197
  const url = ensureAbstractUrl(cleanEndpoint, baseSlices);
1198
+ // build final URL
1184
1199
  const token = localStorage.getItem('token');
1185
1200
  const body = JSON.stringify(file);
1186
1201
  const method = 'PATCH';
@@ -1747,6 +1762,7 @@ exports.getSrcDir = getSrcDir;
1747
1762
  exports.getSubstring = getSubstring;
1748
1763
  exports.getToggleShare = getToggleShare;
1749
1764
  exports.getToken = getToken;
1765
+ exports.get_app_config_url = get_app_config_url;
1750
1766
  exports.get_basename = get_basename;
1751
1767
  exports.get_dirname = get_dirname;
1752
1768
  exports.get_extname = get_extname;