@putkoff/abstract-utilities 0.1.135 → 0.1.137
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/env_utils/src/window_utils.d.ts +2 -2
- package/dist/cjs/index.js +3 -24
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/functions/env_utils/src/window_utils.d.ts +2 -2
- package/dist/esm/index.js +3 -24
- package/dist/esm/index.js.map +1 -1
- package/dist/functions/env_utils/src/window_utils.d.ts +2 -2
- package/dist/index.d.ts +2 -2
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare function get_window(): (Window & typeof globalThis) | null;
|
|
2
|
-
export declare function get_window_location():
|
|
2
|
+
export declare function get_window_location(): "https://abstractendeavors.com" | Location | null;
|
|
3
3
|
export declare function get_window_pathname(): string | null;
|
|
4
|
-
export declare function get_window_parts():
|
|
4
|
+
export declare function get_window_parts(): "https://abstractendeavors.com" | Location | null;
|
package/dist/cjs/index.js
CHANGED
|
@@ -37,7 +37,6 @@ function requireToken() {
|
|
|
37
37
|
if (!tok || isTokenExpired(tok)) {
|
|
38
38
|
console.warn("→ No token or expired token, redirecting to login…");
|
|
39
39
|
localStorage.removeItem("token");
|
|
40
|
-
window.location.href = '/login';
|
|
41
40
|
throw new Error("Redirecting to login…");
|
|
42
41
|
}
|
|
43
42
|
return tok;
|
|
@@ -1041,22 +1040,6 @@ function getConfig(key) {
|
|
|
1041
1040
|
});
|
|
1042
1041
|
}
|
|
1043
1042
|
|
|
1044
|
-
function ensureAbstractUrl(endpoint, slices = []) {
|
|
1045
|
-
slices = slices || ['https//abstractendeavors.com', 'api'];
|
|
1046
|
-
// 1) build a prefix string like "api/v1/"
|
|
1047
|
-
const prefix = slices.map((s) => `${s}/`).join("");
|
|
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);
|
|
1059
|
-
}
|
|
1060
1043
|
/**
|
|
1061
1044
|
* Unwraps nested { result } fields until you hit a non-object or no more "result" keys.
|
|
1062
1045
|
*/
|
|
@@ -1069,10 +1052,6 @@ function getResult(obj) {
|
|
|
1069
1052
|
}
|
|
1070
1053
|
return current;
|
|
1071
1054
|
}
|
|
1072
|
-
// Constructs API URL from endpoint
|
|
1073
|
-
function api(endpoint) {
|
|
1074
|
-
return ensureAbstractUrl(endpoint);
|
|
1075
|
-
}
|
|
1076
1055
|
// Checks if response is OK, handles 401/403 by redirecting to login
|
|
1077
1056
|
function checkResponse(res) {
|
|
1078
1057
|
if (!res.ok) {
|
|
@@ -1093,7 +1072,7 @@ function parseResult(res) {
|
|
|
1093
1072
|
if ((data === null || data === void 0 ? void 0 : data.success) === true && Array.isArray(data.result)) {
|
|
1094
1073
|
return data.result;
|
|
1095
1074
|
}
|
|
1096
|
-
if ((data === null || data === void 0 ? void 0 : data.message) && typeof data.message === 'string') {
|
|
1075
|
+
if ((data === null || data === void 0 ? void 0 : data.error) && (data === null || data === void 0 ? void 0 : data.message) && typeof data.message === 'string') {
|
|
1097
1076
|
alert(`Error: ${data.message}`);
|
|
1098
1077
|
}
|
|
1099
1078
|
return data;
|
|
@@ -1183,7 +1162,7 @@ function get_app_config_url(endpoint) {
|
|
|
1183
1162
|
function fetchIt(endpoint_1) {
|
|
1184
1163
|
return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, headers = null, blob = null, no_api = false, requireAuth = true) {
|
|
1185
1164
|
const vars = getFetchVars(headers, method, body);
|
|
1186
|
-
const url = no_api ? endpoint : get_app_config_url(endpoint);
|
|
1165
|
+
const url = no_api ? endpoint : yield get_app_config_url(endpoint);
|
|
1187
1166
|
const res = yield fetch(url, vars);
|
|
1188
1167
|
return blob ? (checkResponse(res), res.blob()) : yield parseResult(res);
|
|
1189
1168
|
});
|
|
@@ -1227,7 +1206,7 @@ function secureFetchIt(endpoint_1) {
|
|
|
1227
1206
|
function requestPatch(url_1) {
|
|
1228
1207
|
return __awaiter(this, arguments, void 0, function* (url, body = null) {
|
|
1229
1208
|
const variables = getFetchVars(null, 'PATCH', body);
|
|
1230
|
-
return yield fetch(
|
|
1209
|
+
return yield fetch(yield get_app_config_url(url), variables);
|
|
1231
1210
|
});
|
|
1232
1211
|
}
|
|
1233
1212
|
// Performs PATCH request for file sharing
|