@putkoff/abstract-utilities 0.1.156 → 0.1.157
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 -1
- package/dist/cjs/functions/fetch_utils/src/index.d.ts +1 -0
- package/dist/cjs/index.js +61 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/functions/fetch_utils/src/fetchIt_utils.d.ts +1 -1
- package/dist/esm/functions/fetch_utils/src/index.d.ts +1 -0
- package/dist/esm/index.js +50 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/functions/fetch_utils/src/fetchIt_utils.d.ts +1 -1
- package/dist/functions/fetch_utils/src/index.d.ts +1 -0
- package/dist/index.d.ts +35 -11
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -1031,6 +1031,22 @@ function getConfig(key) {
|
|
|
1031
1031
|
});
|
|
1032
1032
|
}
|
|
1033
1033
|
|
|
1034
|
+
function ensureAbstractUrl(endpoint, slices = []) {
|
|
1035
|
+
slices = slices || ['https//abstractendeavors.com', 'api'];
|
|
1036
|
+
// 1) build a prefix string like "api/v1/"
|
|
1037
|
+
const prefix = slices.map((s) => `${s}/`).join("");
|
|
1038
|
+
const normalized = [
|
|
1039
|
+
'/',
|
|
1040
|
+
...slices,
|
|
1041
|
+
window.location.host, // so "abstractendeavors.com" will be stripped
|
|
1042
|
+
`${window.location.host}/api` // etc, if you need it
|
|
1043
|
+
];
|
|
1044
|
+
const stripped = stripPrefixes(endpoint, normalized);
|
|
1045
|
+
console.log('BUILD PREFIX:', prefix);
|
|
1046
|
+
console.log('RAW ENDPOINT:', endpoint);
|
|
1047
|
+
console.log('STRIPPED ENDPT:', stripped);
|
|
1048
|
+
return make_path(prefix, stripped);
|
|
1049
|
+
}
|
|
1034
1050
|
/**
|
|
1035
1051
|
* Unwraps nested { result } fields until you hit a non-object or no more "result" keys.
|
|
1036
1052
|
*/
|
|
@@ -1043,6 +1059,10 @@ function getResult(obj) {
|
|
|
1043
1059
|
}
|
|
1044
1060
|
return current;
|
|
1045
1061
|
}
|
|
1062
|
+
// Constructs API URL from endpoint
|
|
1063
|
+
function api(endpoint) {
|
|
1064
|
+
return ensureAbstractUrl(endpoint);
|
|
1065
|
+
}
|
|
1046
1066
|
/**
|
|
1047
1067
|
* Intercept 401/403 and force a clean redirect to login
|
|
1048
1068
|
* without ever showing an alert.
|
|
@@ -1129,6 +1149,32 @@ function getFetchVars(headers = null, method = null, body = null) {
|
|
|
1129
1149
|
}
|
|
1130
1150
|
return { method, headers, body };
|
|
1131
1151
|
}
|
|
1152
|
+
// Constructs HTML directory path
|
|
1153
|
+
function getHtmlDirectory(directory, filename) {
|
|
1154
|
+
return `${directory}/${filename}.html`;
|
|
1155
|
+
}
|
|
1156
|
+
// Fetches HTML content
|
|
1157
|
+
function fetchIndexHtml(filename_1) {
|
|
1158
|
+
return __awaiter(this, arguments, void 0, function* (filename, directory = 'sf_index', base = 'html') {
|
|
1159
|
+
const url = `/${base}/${directory}/${filename}.html`;
|
|
1160
|
+
const response = yield fetch(api(url));
|
|
1161
|
+
return yield response.text();
|
|
1162
|
+
});
|
|
1163
|
+
}
|
|
1164
|
+
// Fetches and injects HTML content into container
|
|
1165
|
+
function fetchIndexHtmlContainer(filename_1) {
|
|
1166
|
+
return __awaiter(this, arguments, void 0, function* (filename, doc = document, directory = 'html') {
|
|
1167
|
+
const container = `${filename}-container`;
|
|
1168
|
+
const html = yield fetchIndexHtml(filename, directory);
|
|
1169
|
+
const el = doc.getElementById(container);
|
|
1170
|
+
if (el) {
|
|
1171
|
+
el.innerHTML = html;
|
|
1172
|
+
}
|
|
1173
|
+
else {
|
|
1174
|
+
console.warn(`⚠️ No container found for: #${container}`);
|
|
1175
|
+
}
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
1132
1178
|
|
|
1133
1179
|
/**
|
|
1134
1180
|
* Strip a leading host (http://host) from any URL-like string.
|
|
@@ -1152,10 +1198,10 @@ function get_app_config_url(endpoint) {
|
|
|
1152
1198
|
return make_path(base, endpoint);
|
|
1153
1199
|
});
|
|
1154
1200
|
}
|
|
1155
|
-
function fetchIt(
|
|
1156
|
-
return __awaiter(this,
|
|
1201
|
+
function fetchIt(endpoint, body, method, headers, blob, noApi, withCredentials, returnJson, returnReult) {
|
|
1202
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1157
1203
|
const vars = getFetchVars(headers, method, body);
|
|
1158
|
-
const url =
|
|
1204
|
+
const url = noApi ? endpoint : yield get_app_config_url(endpoint);
|
|
1159
1205
|
const res = yield fetch(url, vars);
|
|
1160
1206
|
return blob ? (checkResponse(res), res.blob()) : yield parseResult(res);
|
|
1161
1207
|
});
|
|
@@ -1312,5 +1358,5 @@ function readJsonFile(relativeOrAbsolutePath) {
|
|
|
1312
1358
|
});
|
|
1313
1359
|
}
|
|
1314
1360
|
|
|
1315
|
-
export { API_PREFIX, BASE_URL, Button, Checkbox, DEV_PREFIX, DOMAIN_NAME, Input, PROD_PREFIX, PROTOCOL, SUB_DIR, Spinner, alertit, currentUsername, currentUsernames, decodeJwt, eatAll, eatEnd, eatInner, eatOuter, ensure_list, fetchIt, fetchSharePatch, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, getAbsDir, getAbsPath, getAuthorizationHeader, getBaseDir, getComponentsUtilsDirectory, getConfig, getDbConfigsPath, getDistDir, getEnvDir, getEnvPath, getFunctionsDir, getFunctionsUtilsDirectory, getHooksUtilsDirectory, getLibUtilsDirectory, getPublicDir, getSchemasDirPath, getSchemasPath, getSrcDir, getSubstring, 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, isLoggedIn, isTokenExpired, loadConfig, make_path, make_sanitized_path, normalizeUrl, readFileContents, readJsonFile, requestPatch, requireToken, sanitizeFilename, secureFetchIt, stripPrefixes, truncateString };
|
|
1361
|
+
export { API_PREFIX, BASE_URL, Button, Checkbox, DEV_PREFIX, DOMAIN_NAME, Input, PROD_PREFIX, PROTOCOL, SUB_DIR, Spinner, alertit, api, checkResponse, currentUsername, currentUsernames, decodeJwt, eatAll, eatEnd, eatInner, eatOuter, ensureAbstractUrl, ensure_list, fetchIndexHtml, fetchIndexHtmlContainer, fetchIt, fetchSharePatch, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, getAbsDir, getAbsPath, getAuthorizationHeader, getBaseDir, getBody, getComponentsUtilsDirectory, getConfig, getDbConfigsPath, getDistDir, getEnvDir, getEnvPath, getFetchVars, getFunctionsDir, getFunctionsUtilsDirectory, getHeaders, getHooksUtilsDirectory, getHtmlDirectory, getLibUtilsDirectory, getMethod, getPublicDir, getResult, getSchemasDirPath, getSchemasPath, getSrcDir, getSubstring, 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, isLoggedIn, isTokenExpired, loadConfig, make_path, make_sanitized_path, normalizeUrl, parseResult, readFileContents, readJsonFile, requestPatch, requireToken, sanitizeFilename, secureFetchIt, stripPrefixes, truncateString };
|
|
1316
1362
|
//# sourceMappingURL=index.js.map
|