@putkoff/abstract-utilities 0.1.156 → 0.1.158

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.
@@ -3,7 +3,7 @@
3
3
  * from the BASE_API_URL entry in your JSON config.
4
4
  */
5
5
  export declare function get_app_config_url(endpoint: string): Promise<any>;
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<any>;
6
+ export declare function fetchIt(endpoint: any, body?: any, method?: any, headers?: Record<string, string> | null, blob?: boolean, noApi?: boolean, withCredentials?: boolean, returnJson?: boolean, returnReult?: boolean): Promise<any>;
7
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>;
8
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>;
9
9
  export declare function requestPatch(url: string, body?: unknown): Promise<Response>;
@@ -1 +1,2 @@
1
1
  export * from './fetchIt_utils';
2
+ export * from './utils';
package/dist/cjs/index.js CHANGED
@@ -1034,6 +1034,22 @@ function getConfig(key) {
1034
1034
  });
1035
1035
  }
1036
1036
 
1037
+ function ensureAbstractUrl(endpoint, slices = []) {
1038
+ slices = slices || ['https//abstractendeavors.com', 'api'];
1039
+ // 1) build a prefix string like "api/v1/"
1040
+ const prefix = slices.map((s) => `${s}/`).join("");
1041
+ const normalized = [
1042
+ '/',
1043
+ ...slices,
1044
+ window.location.host, // so "abstractendeavors.com" will be stripped
1045
+ `${window.location.host}/api` // etc, if you need it
1046
+ ];
1047
+ const stripped = stripPrefixes(endpoint, normalized);
1048
+ console.log('BUILD PREFIX:', prefix);
1049
+ console.log('RAW ENDPOINT:', endpoint);
1050
+ console.log('STRIPPED ENDPT:', stripped);
1051
+ return make_path(prefix, stripped);
1052
+ }
1037
1053
  /**
1038
1054
  * Unwraps nested { result } fields until you hit a non-object or no more "result" keys.
1039
1055
  */
@@ -1046,6 +1062,10 @@ function getResult(obj) {
1046
1062
  }
1047
1063
  return current;
1048
1064
  }
1065
+ // Constructs API URL from endpoint
1066
+ function api(endpoint) {
1067
+ return ensureAbstractUrl(endpoint);
1068
+ }
1049
1069
  /**
1050
1070
  * Intercept 401/403 and force a clean redirect to login
1051
1071
  * without ever showing an alert.
@@ -1132,6 +1152,32 @@ function getFetchVars(headers = null, method = null, body = null) {
1132
1152
  }
1133
1153
  return { method, headers, body };
1134
1154
  }
1155
+ // Constructs HTML directory path
1156
+ function getHtmlDirectory(directory, filename) {
1157
+ return `${directory}/${filename}.html`;
1158
+ }
1159
+ // Fetches HTML content
1160
+ function fetchIndexHtml(filename_1) {
1161
+ return __awaiter(this, arguments, void 0, function* (filename, directory = 'sf_index', base = 'html') {
1162
+ const url = `/${base}/${directory}/${filename}.html`;
1163
+ const response = yield fetch(api(url));
1164
+ return yield response.text();
1165
+ });
1166
+ }
1167
+ // Fetches and injects HTML content into container
1168
+ function fetchIndexHtmlContainer(filename_1) {
1169
+ return __awaiter(this, arguments, void 0, function* (filename, doc = document, directory = 'html') {
1170
+ const container = `${filename}-container`;
1171
+ const html = yield fetchIndexHtml(filename, directory);
1172
+ const el = doc.getElementById(container);
1173
+ if (el) {
1174
+ el.innerHTML = html;
1175
+ }
1176
+ else {
1177
+ console.warn(`⚠️ No container found for: #${container}`);
1178
+ }
1179
+ });
1180
+ }
1135
1181
 
1136
1182
  /**
1137
1183
  * Strip a leading host (http://host) from any URL-like string.
@@ -1155,10 +1201,10 @@ function get_app_config_url(endpoint) {
1155
1201
  return make_path(base, endpoint);
1156
1202
  });
1157
1203
  }
1158
- function fetchIt(endpoint_1) {
1159
- return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, headers = null, blob = null, no_api = false, requireAuth = true) {
1204
+ function fetchIt(endpoint, body, method, headers, blob, noApi, withCredentials, returnJson, returnReult) {
1205
+ return __awaiter(this, void 0, void 0, function* () {
1160
1206
  const vars = getFetchVars(headers, method, body);
1161
- const url = no_api ? endpoint : yield get_app_config_url(endpoint);
1207
+ const url = noApi ? endpoint : yield get_app_config_url(endpoint);
1162
1208
  const res = yield fetch(url, vars);
1163
1209
  return blob ? (checkResponse(res), res.blob()) : yield parseResult(res);
1164
1210
  });
@@ -1343,6 +1389,8 @@ exports.PROTOCOL = PROTOCOL;
1343
1389
  exports.SUB_DIR = SUB_DIR;
1344
1390
  exports.Spinner = Spinner;
1345
1391
  exports.alertit = alertit;
1392
+ exports.api = api;
1393
+ exports.checkResponse = checkResponse;
1346
1394
  exports.currentUsername = currentUsername;
1347
1395
  exports.currentUsernames = currentUsernames;
1348
1396
  exports.decodeJwt = decodeJwt;
@@ -1350,7 +1398,10 @@ exports.eatAll = eatAll;
1350
1398
  exports.eatEnd = eatEnd;
1351
1399
  exports.eatInner = eatInner;
1352
1400
  exports.eatOuter = eatOuter;
1401
+ exports.ensureAbstractUrl = ensureAbstractUrl;
1353
1402
  exports.ensure_list = ensure_list;
1403
+ exports.fetchIndexHtml = fetchIndexHtml;
1404
+ exports.fetchIndexHtmlContainer = fetchIndexHtmlContainer;
1354
1405
  exports.fetchIt = fetchIt;
1355
1406
  exports.fetchSharePatch = fetchSharePatch;
1356
1407
  exports.geAuthsUtilsDirectory = geAuthsUtilsDirectory;
@@ -1367,17 +1418,23 @@ exports.getAbsDir = getAbsDir;
1367
1418
  exports.getAbsPath = getAbsPath;
1368
1419
  exports.getAuthorizationHeader = getAuthorizationHeader;
1369
1420
  exports.getBaseDir = getBaseDir;
1421
+ exports.getBody = getBody;
1370
1422
  exports.getComponentsUtilsDirectory = getComponentsUtilsDirectory;
1371
1423
  exports.getConfig = getConfig;
1372
1424
  exports.getDbConfigsPath = getDbConfigsPath;
1373
1425
  exports.getDistDir = getDistDir;
1374
1426
  exports.getEnvDir = getEnvDir;
1375
1427
  exports.getEnvPath = getEnvPath;
1428
+ exports.getFetchVars = getFetchVars;
1376
1429
  exports.getFunctionsDir = getFunctionsDir;
1377
1430
  exports.getFunctionsUtilsDirectory = getFunctionsUtilsDirectory;
1431
+ exports.getHeaders = getHeaders;
1378
1432
  exports.getHooksUtilsDirectory = getHooksUtilsDirectory;
1433
+ exports.getHtmlDirectory = getHtmlDirectory;
1379
1434
  exports.getLibUtilsDirectory = getLibUtilsDirectory;
1435
+ exports.getMethod = getMethod;
1380
1436
  exports.getPublicDir = getPublicDir;
1437
+ exports.getResult = getResult;
1381
1438
  exports.getSchemasDirPath = getSchemasDirPath;
1382
1439
  exports.getSchemasPath = getSchemasPath;
1383
1440
  exports.getSrcDir = getSrcDir;
@@ -1399,6 +1456,7 @@ exports.loadConfig = loadConfig;
1399
1456
  exports.make_path = make_path;
1400
1457
  exports.make_sanitized_path = make_sanitized_path;
1401
1458
  exports.normalizeUrl = normalizeUrl;
1459
+ exports.parseResult = parseResult;
1402
1460
  exports.readFileContents = readFileContents;
1403
1461
  exports.readJsonFile = readJsonFile;
1404
1462
  exports.requestPatch = requestPatch;