@putkoff/abstract-utilities 0.1.102 → 0.1.104

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.
@@ -0,0 +1,8 @@
1
+ /** Runtime-loaded JSON (config.json) shape */
2
+ export interface RuntimeConfig {
3
+ API_BASE_URL: string;
4
+ }
5
+ /** Call once, early in app startup (e.g. in index.tsx) */
6
+ export declare function load(): Promise<void>;
7
+ /** Get the base (after `load()`), or '' if not loaded yet */
8
+ export declare function apiBase(): string;
@@ -0,0 +1,8 @@
1
+ /** Runtime-loaded JSON (config.json) shape */
2
+ export interface RuntimeConfig {
3
+ API_BASE_URL: string;
4
+ }
5
+ /** Call once, early in app startup (e.g. in index.tsx) */
6
+ export declare function load(): Promise<void>;
7
+ /** Get the base (after `load()`), or '' if not loaded yet */
8
+ export declare function apiBase(): string;
@@ -4,5 +4,4 @@ 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';
8
7
  export type { LogoutButtonProps, FetchVariables } from './../../types';
@@ -10,6 +10,6 @@
10
10
  export declare function get_app_config_url(endpoint: any): string;
11
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>;
12
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>;
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>;
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>;
14
14
  export declare function requestPatch(url: string, body?: unknown): Promise<Response>;
15
15
  export declare function fetchSharePatch(file: unknown): Promise<void>;
@@ -4,8 +4,6 @@ export declare function ensureAbstractUrl(endpoint: string, slices?: string[]):
4
4
  * Unwraps nested { result } fields until you hit a non-object or no more "result" keys.
5
5
  */
6
6
  export declare function getResult<T>(obj: unknown): T;
7
- /** Pulls base-URL from AppConfig.API_BASE_URL, strips trailing slashes */
8
- export declare function getRawConfigUrl(): any;
9
7
  export declare function api(endpoint: string): string;
10
8
  export declare function checkResponse(res: Response): any;
11
9
  export declare function parseResult(res: Response): Promise<unknown>;
package/dist/esm/index.js CHANGED
@@ -1108,15 +1108,8 @@ function getFetchVars(headers = null, method = null, body = null) {
1108
1108
  }
1109
1109
 
1110
1110
  function getAppConfig(endpoint) {
1111
- var _a;
1112
- const rawBase = (_a = void 0 ) !== null && _a !== void 0 ? _a : "";
1113
- const base = rawBase.replace(/\/+$/, "");
1114
- // strip any leading slashes on endpoint, then prefix “/api/”
1115
- const cleanEndpoint = endpoint.replace(/^\/+/, "");
1116
- const url = base
1117
- ? `${base}/${cleanEndpoint}`
1118
- : `/api/${cleanEndpoint}`;
1119
- return url;
1111
+ const clean = endpoint.replace(/^\/+/, '');
1112
+ return `/api/${clean}`;
1120
1113
  }
1121
1114
 
1122
1115
  /**
@@ -1146,10 +1139,10 @@ function fetchIt(endpoint_1) {
1146
1139
  });
1147
1140
  }
1148
1141
  function secureFetchIt(endpoint_1) {
1149
- return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, customHeaders = null, blob = false, noApi = false, withCredentials = true, returnJson = true) {
1142
+ return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, customHeaders = null, blob = false, noApi = false, withCredentials = true, returnJson = true, returnReult = true) {
1150
1143
  // strip leading slashes off the endpoint
1151
1144
  method = method || "GET";
1152
- let url = endpoint.replace(/^\/+/, "");
1145
+ let url = endpoint;
1153
1146
  if (!noApi) {
1154
1147
  url = get_app_config_url(url);
1155
1148
  }
@@ -1173,8 +1166,10 @@ function secureFetchIt(endpoint_1) {
1173
1166
  }
1174
1167
  if (blob)
1175
1168
  return res.blob();
1176
- if (returnJson)
1169
+ if (returnReult)
1177
1170
  return getResult(res.json());
1171
+ if (returnJson)
1172
+ return res.json();
1178
1173
  return res;
1179
1174
  });
1180
1175
  }
@@ -1385,7 +1380,7 @@ function uploadFiles(file_1) {
1385
1380
  formData.append('file', file);
1386
1381
  formData.append('subdir', subdir.trim());
1387
1382
  try {
1388
- const json = yield secureFetchIt('upload', formData, 'POST', null, false, true);
1383
+ const json = yield secureFetchIt('upload', formData, 'POST', null, false, false);
1389
1384
  if (!json || typeof json !== 'object') {
1390
1385
  throw new Error('Invalid response from server.');
1391
1386
  }