@putkoff/abstract-utilities 0.1.126 → 0.1.128

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.
@@ -1,4 +1,5 @@
1
1
  import type { AppConfig } from './../imports';
2
+ export declare function loadConfig(filePath?: string | null): Promise<AppConfig>;
2
3
  /**
3
4
  * getConfig(): load the full AppConfig
4
5
  * getConfig(key): load just that key
@@ -4,5 +4,5 @@ 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 type { LogoutButtonProps, FetchVariables, AppConfig } from './../../types';
8
- export { getConfig } from './../config_utils';
7
+ export type { LogoutButtonProps, FetchVariables, UrlKey } from './../../types';
8
+ export { getConfig, loadConfig } from './../config_utils';
@@ -1,14 +1,8 @@
1
- import type { AppConfig } from './../imports';
2
1
  /**
3
-
4
- ***Changes**: None, as it’s self-contained and doesn’t rely on external imports.
5
- *
6
- *4. **secureFetchIt** (`src/functions/fetch/secureFetchIt.ts`):
7
- * Since `secureFetchIt` isn’t provided, we’ll create a minimal implementation based on its usage in `Login` and `uploadFiles`. It’s assumed to be a wrapper around `fetch` that handles authentication and JSON parsing.
8
- *
9
- */
10
- /** Pulls base-URL from AppConfig.API_BASE_URL, strips trailing slashes */
11
- export declare function get_app_config_url(endpoint: string, appKey?: keyof AppConfig): Promise<string>;
2
+ * Given an “endpoint” slug like "api/list", build the full URL
3
+ * from the BASE_API_URL entry in your JSON config.
4
+ */
5
+ export declare function get_app_config_url(endpoint: string): Promise<string>;
12
6
  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>;
13
7
  export declare function secureFetchIt<T>(endpoint: any, body?: any, method?: any, headers?: Record<string, string> | null, blob?: boolean, noApi?: boolean, withCredentials?: boolean, returnJson?: boolean, returnReult?: boolean): Promise<T>;
14
8
  export declare function secureFetchIt(endpoint: any, body?: any, method?: any, headers?: Record<string, string> | null, blob?: boolean, noApi?: boolean, withCredentials?: boolean, returnJson?: boolean, returnReult?: boolean): Promise<Blob>;
package/dist/cjs/index.js CHANGED
@@ -1045,14 +1045,17 @@ function ensureAbstractUrl(endpoint, slices = []) {
1045
1045
  slices = slices || ['https//abstractendeavors.com', 'api'];
1046
1046
  // 1) build a prefix string like "api/v1/"
1047
1047
  const prefix = slices.map((s) => `${s}/`).join("");
1048
- // 2) normalize the list you’ll use for stripping
1049
- const normalized = ["/", ...ensure_list(slices)];
1050
- // 3) remove any inner “/” duplicates from prefix
1051
- const target = eatInner(prefix, ["/"]);
1052
- // 4) drop any of those prefixes off the endpoint
1053
- const strippedEndpoint = stripPrefixes(endpoint, normalized);
1054
- // 5) hand it back to make_path to join “target” + “strippedEndpoint”
1055
- return make_path(target, strippedEndpoint);
1048
+ const normalized = [
1049
+ '/',
1050
+ ...slices,
1051
+ window.location.host, // so "abstractendeavors.com" will be stripped
1052
+ `${window.location.host}/api` // etc, if you need it
1053
+ ];
1054
+ const stripped = stripPrefixes(endpoint, normalized);
1055
+ console.log('BUILD PREFIX:', prefix);
1056
+ console.log('RAW ENDPOINT:', endpoint);
1057
+ console.log('STRIPPED ENDPT:', stripped);
1058
+ return make_path(prefix, stripped);
1056
1059
  }
1057
1060
  /**
1058
1061
  * Unwraps nested { result } fields until you hit a non-object or no more "result" keys.
@@ -1156,24 +1159,32 @@ function getFetchVars(headers = null, method = null, body = null) {
1156
1159
  }
1157
1160
 
1158
1161
  /**
1159
-
1160
- ***Changes**: None, as it’s self-contained and doesn’t rely on external imports.
1161
- *
1162
- *4. **secureFetchIt** (`src/functions/fetch/secureFetchIt.ts`):
1163
- * Since `secureFetchIt` isn’t provided, we’ll create a minimal implementation based on its usage in `Login` and `uploadFiles`. It’s assumed to be a wrapper around `fetch` that handles authentication and JSON parsing.
1164
- *
1165
- */
1166
- /** Pulls base-URL from AppConfig.API_BASE_URL, strips trailing slashes */
1167
- // src/functions/fetch/secureFetchIt.ts
1168
- // --- fetch_utils/src/fetch_utils.ts ----------------------------
1169
- function get_app_config_url(endpoint_1) {
1170
- return __awaiter(this, arguments, void 0, function* (endpoint, appKey = 'BASE_API_URL') {
1171
- const cleanEndpoint = endpoint.replace(/^\/+/, '');
1172
- const config = yield getConfig(appKey);
1173
- appKey = appKey || 'BASE_API_URL';
1174
- const base = config[appKey]; // full AppConfig object
1175
- const slices = base.split('/').filter(Boolean);
1176
- return ensureAbstractUrl(cleanEndpoint, slices);
1162
+ * Strip a leading host (http://host) from any URL-like string.
1163
+ */
1164
+ function stripHost(str) {
1165
+ return str.replace(/^https?:\/\/[^/]+/, '');
1166
+ }
1167
+ /**
1168
+ * Given an “endpoint” slug like "api/list", build the full URL
1169
+ * from the BASE_API_URL entry in your JSON config.
1170
+ */
1171
+ function get_app_config_url(endpoint) {
1172
+ return __awaiter(this, void 0, void 0, function* () {
1173
+ // 1) normalize your input
1174
+ const clean = stripHost(endpoint.trim().toLowerCase());
1175
+ const cfg = yield loadConfig();
1176
+ // 2) pick the key you expect in your JSON
1177
+ const appKey = (`BASE_API_URL`);
1178
+ const base = cfg[appKey]; // TS now infers `base: AppConfig[UrlKey]`
1179
+ // 3) load your JSON (this returns an AppConfig)
1180
+ // 4) pull out the base for that key
1181
+ if (!base) {
1182
+ throw new Error(`Missing configuration key "${appKey}". ` +
1183
+ `Available: ${Object.keys(cfg).join(', ')}`);
1184
+ }
1185
+ // 5) build the final URL (this handles trailing/slashes)
1186
+ const normalizedBase = base.replace(/\/+$/, '') + '/';
1187
+ return new URL(clean, normalizedBase).toString();
1177
1188
  });
1178
1189
  }
1179
1190
  function fetchIt(endpoint_1) {
@@ -1416,6 +1427,7 @@ exports.get_window_parts = get_window_parts;
1416
1427
  exports.get_window_pathname = get_window_pathname;
1417
1428
  exports.isLoggedIn = isLoggedIn;
1418
1429
  exports.isTokenExpired = isTokenExpired;
1430
+ exports.loadConfig = loadConfig;
1419
1431
  exports.make_path = make_path;
1420
1432
  exports.make_sanitized_path = make_sanitized_path;
1421
1433
  exports.normalizeUrl = normalizeUrl;