@putkoff/abstract-utilities 0.1.186 → 0.1.188
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/esm/index.js
CHANGED
|
@@ -1300,56 +1300,6 @@ function getConfigVar() {
|
|
|
1300
1300
|
}
|
|
1301
1301
|
|
|
1302
1302
|
// Constructs API URL from endpoint
|
|
1303
|
-
function api(endpoint) {
|
|
1304
|
-
return ensureAbstractUrl(endpoint);
|
|
1305
|
-
}
|
|
1306
|
-
/**
|
|
1307
|
-
* Strip a leading host (http://host) from any URL-like string.
|
|
1308
|
-
*/
|
|
1309
|
-
function stripHost(str) {
|
|
1310
|
-
// now also removes "abstractendeavors.com" even without protocol
|
|
1311
|
-
const hostPattern = `(?:https?:\\/\\/)?${getWindowHost()}`;
|
|
1312
|
-
return str.replace(new RegExp(`^${hostPattern}`), '');
|
|
1313
|
-
}
|
|
1314
|
-
function ensureAbstractUrl(endpoint, slices = []) {
|
|
1315
|
-
slices = slices || ['https//abstractendeavors.com', 'api'];
|
|
1316
|
-
// 1) build a prefix string like "api/v1/"
|
|
1317
|
-
const prefix = slices.map((s) => `${s}/`).join("");
|
|
1318
|
-
const windowHost = getWindowHost();
|
|
1319
|
-
const normalized = [
|
|
1320
|
-
'/',
|
|
1321
|
-
...slices,
|
|
1322
|
-
windowHost, // so "abstractendeavors.com" will be stripped
|
|
1323
|
-
`${windowHost}/api` // etc, if you need it
|
|
1324
|
-
];
|
|
1325
|
-
const stripped = stripPrefixes(endpoint, normalized);
|
|
1326
|
-
return make_path(prefix, stripped);
|
|
1327
|
-
}
|
|
1328
|
-
/**
|
|
1329
|
-
* Given an “endpoint” slug like "api/list", build the full URL
|
|
1330
|
-
* from the BASE_API_URL entry in your JSON config.
|
|
1331
|
-
* If anything goes wrong, just returns the raw endpoint.
|
|
1332
|
-
*/
|
|
1333
|
-
function get_app_config_url(endpoint) {
|
|
1334
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1335
|
-
const clean = stripHost(endpoint);
|
|
1336
|
-
try {
|
|
1337
|
-
const vars = getFetchVars(null, 'POST', {
|
|
1338
|
-
key: 'BASE_API_URL',
|
|
1339
|
-
path: '/var/www/abstractendeavors/secure-files/public/config.json'
|
|
1340
|
-
});
|
|
1341
|
-
const resp = yield fetch(ensureAbstractUrl('/secure_env'), vars);
|
|
1342
|
-
checkResponse(resp);
|
|
1343
|
-
const json = yield resp.json();
|
|
1344
|
-
const baseUrl = getResult(json);
|
|
1345
|
-
return make_path(baseUrl, clean);
|
|
1346
|
-
}
|
|
1347
|
-
catch (err) {
|
|
1348
|
-
console.warn(`[get_app_config_url] failed, falling back to raw endpoint:`, endpoint, err);
|
|
1349
|
-
return endpoint;
|
|
1350
|
-
}
|
|
1351
|
-
});
|
|
1352
|
-
}
|
|
1353
1303
|
/**
|
|
1354
1304
|
* Unwraps nested { result } fields until you hit a non-object or no more "result" keys.
|
|
1355
1305
|
*/
|
|
@@ -1449,50 +1399,28 @@ function checkResponse(res) {
|
|
|
1449
1399
|
return res;
|
|
1450
1400
|
}
|
|
1451
1401
|
function fetchIt(endpoint_1) {
|
|
1452
|
-
return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, headers = null, blob = false,
|
|
1453
|
-
|
|
1454
|
-
//
|
|
1455
|
-
let url;
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
if (isAbsolute || noApi) {
|
|
1459
|
-
url = endpoint;
|
|
1460
|
-
}
|
|
1461
|
-
else {
|
|
1462
|
-
url = yield get_app_config_url(endpoint);
|
|
1463
|
-
}
|
|
1464
|
-
}
|
|
1465
|
-
catch (_a) {
|
|
1466
|
-
url = endpoint;
|
|
1467
|
-
}
|
|
1468
|
-
// 2) prepare headers & body
|
|
1469
|
-
const authHeaders = Object.assign({}, (body instanceof FormData ? {} : { 'Content-Type': 'application/json' }));
|
|
1470
|
-
headers = Object.assign(Object.assign(Object.assign({}, authHeaders), getFetchVars(null, verb, body).headers), headers);
|
|
1402
|
+
return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, headers = null, blob = false, configUrl = false, withCredentials = true, returnJson = true, returnReult = true) {
|
|
1403
|
+
method = (method || "GET").toUpperCase();
|
|
1404
|
+
// 2) choose the URL
|
|
1405
|
+
let url = endpoint;
|
|
1406
|
+
// 3) prepare headers & body
|
|
1407
|
+
headers = Object.assign(Object.assign(Object.assign({}, (body instanceof FormData ? {} : { "Content-Type": "application/json" })), getAuthorizationHeader()), headers);
|
|
1471
1408
|
const opts = {
|
|
1472
|
-
method
|
|
1473
|
-
credentials: withCredentials ?
|
|
1409
|
+
method,
|
|
1410
|
+
credentials: withCredentials ? "include" : "same-origin",
|
|
1474
1411
|
headers,
|
|
1475
1412
|
body: body instanceof FormData
|
|
1476
1413
|
? body
|
|
1477
|
-
: body != null &&
|
|
1414
|
+
: body != null && method !== "GET"
|
|
1478
1415
|
? JSON.stringify(body)
|
|
1479
1416
|
: undefined,
|
|
1480
1417
|
};
|
|
1481
|
-
console.debug(
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
if (!res.ok) {
|
|
1487
|
-
const err = yield res.text();
|
|
1488
|
-
throw new Error(`HTTP ${res.status}: ${err}`);
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
catch (err) {
|
|
1492
|
-
console.warn(`[fetchIt] failed for ${url}, returning raw endpoint:`, err);
|
|
1493
|
-
return url;
|
|
1418
|
+
console.debug("➡️ secureFetchIt →", url, opts);
|
|
1419
|
+
const res = yield fetch(url, opts);
|
|
1420
|
+
if (!res.ok) {
|
|
1421
|
+
const err = yield res.text();
|
|
1422
|
+
throw new Error(`HTTP ${res.status}: ${err}`);
|
|
1494
1423
|
}
|
|
1495
|
-
// 4) produce the expected result
|
|
1496
1424
|
if (blob)
|
|
1497
1425
|
return res.blob();
|
|
1498
1426
|
if (returnReult)
|
|
@@ -1502,46 +1430,6 @@ function fetchIt(endpoint_1) {
|
|
|
1502
1430
|
return res;
|
|
1503
1431
|
});
|
|
1504
1432
|
}
|
|
1505
|
-
|
|
1506
|
-
function secureFetchIt(endpoint_1) {
|
|
1507
|
-
return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, customHeaders = null, blob = false, configUrl = false, withCredentials = true, returnJson = true, returnReult = true) {
|
|
1508
|
-
return yield fetchIt(yield getEndpoint(endpoint), body, method, customHeaders, blob, configUrl, withCredentials, returnJson, returnReult);
|
|
1509
|
-
});
|
|
1510
|
-
}
|
|
1511
|
-
// Performs PATCH request
|
|
1512
|
-
function requestPatch(url_1) {
|
|
1513
|
-
return __awaiter(this, arguments, void 0, function* (url, body = null) {
|
|
1514
|
-
const variables = getFetchVars(null, 'PATCH', body);
|
|
1515
|
-
return yield fetch(yield get_app_config_url(url), variables);
|
|
1516
|
-
});
|
|
1517
|
-
}
|
|
1518
|
-
// Performs PATCH request for file sharing
|
|
1519
|
-
function fetchSharePatch(file_1) {
|
|
1520
|
-
return __awaiter(this, arguments, void 0, function* (file, appKey = null) {
|
|
1521
|
-
const cleanEndpoint = '/files/share';
|
|
1522
|
-
// build final URL
|
|
1523
|
-
const url = yield get_app_config_url(cleanEndpoint);
|
|
1524
|
-
const token = callStorage('getItem', 'token');
|
|
1525
|
-
const body = JSON.stringify(file);
|
|
1526
|
-
const method = 'PATCH';
|
|
1527
|
-
const headers = {
|
|
1528
|
-
'Content-Type': 'application/json',
|
|
1529
|
-
'Authorization': `Bearer ${token}`,
|
|
1530
|
-
};
|
|
1531
|
-
const resp = yield fetch(url, {
|
|
1532
|
-
method,
|
|
1533
|
-
headers,
|
|
1534
|
-
body
|
|
1535
|
-
});
|
|
1536
|
-
if (!resp.ok) {
|
|
1537
|
-
console.error('Error from server', yield resp.text());
|
|
1538
|
-
}
|
|
1539
|
-
else {
|
|
1540
|
-
const data = yield resp.json();
|
|
1541
|
-
console.log('Success!', data);
|
|
1542
|
-
}
|
|
1543
|
-
});
|
|
1544
|
-
}
|
|
1545
1433
|
// Constructs HTML directory path
|
|
1546
1434
|
function getHtmlDirectory(directory, filename) {
|
|
1547
1435
|
return `${directory}/${filename}.html`;
|
|
@@ -1550,7 +1438,7 @@ function getHtmlDirectory(directory, filename) {
|
|
|
1550
1438
|
function fetchIndexHtml(filename_1) {
|
|
1551
1439
|
return __awaiter(this, arguments, void 0, function* (filename, directory = 'sf_index', base = 'html') {
|
|
1552
1440
|
const url = `/${base}/${directory}/${filename}.html`;
|
|
1553
|
-
const response = yield fetch(
|
|
1441
|
+
const response = yield fetch(url);
|
|
1554
1442
|
return yield response.text();
|
|
1555
1443
|
});
|
|
1556
1444
|
}
|
|
@@ -1568,51 +1456,6 @@ function fetchIndexHtmlContainer(filename_1) {
|
|
|
1568
1456
|
}
|
|
1569
1457
|
});
|
|
1570
1458
|
}
|
|
1571
|
-
// 2) Pull a single key out of that object
|
|
1572
|
-
function getBaseUrl() {
|
|
1573
|
-
return __awaiter(this, arguments, void 0, function* (key = null) {
|
|
1574
|
-
key = key || 'BASE_API_URL';
|
|
1575
|
-
const value = yield getConfigVar(key);
|
|
1576
|
-
return value;
|
|
1577
|
-
});
|
|
1578
|
-
}
|
|
1579
|
-
function getEndpoints() {
|
|
1580
|
-
return __awaiter(this, arguments, void 0, function* (base_url = null) {
|
|
1581
|
-
base_url = yield getUrl(base_url);
|
|
1582
|
-
const endpoints_url = `${base_url}/api/endpoints`;
|
|
1583
|
-
return yield fetchIt(endpoints_url, {}, "GET");
|
|
1584
|
-
});
|
|
1585
|
-
}
|
|
1586
|
-
function getUrl() {
|
|
1587
|
-
return __awaiter(this, arguments, void 0, function* (base_url = null) {
|
|
1588
|
-
return base_url || (yield getBaseUrl()) || 'https://abstractendeavors.com';
|
|
1589
|
-
});
|
|
1590
|
-
}
|
|
1591
|
-
/**
|
|
1592
|
-
* Find the most specific endpoint matching the given keyword.
|
|
1593
|
-
* @param keyword A fragment to search for, e.g. 'list'
|
|
1594
|
-
* @returns The full path string, or null if nothing matches
|
|
1595
|
-
*/
|
|
1596
|
-
function getEndpoint(keyword_1) {
|
|
1597
|
-
return __awaiter(this, arguments, void 0, function* (keyword, base_url = null) {
|
|
1598
|
-
base_url = yield getUrl(base_url);
|
|
1599
|
-
const endpoints = yield getEndpoints(base_url);
|
|
1600
|
-
const lower = keyword.toLowerCase();
|
|
1601
|
-
let bestMatch = null;
|
|
1602
|
-
let bestLen = -1;
|
|
1603
|
-
for (const [path] of endpoints) {
|
|
1604
|
-
const lastSegment = path.split("/").pop().toLowerCase();
|
|
1605
|
-
// does either string contain the other?
|
|
1606
|
-
if (lastSegment.includes(lower)) {
|
|
1607
|
-
if (lastSegment.length > bestLen) {
|
|
1608
|
-
bestLen = lastSegment.length;
|
|
1609
|
-
bestMatch = path;
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
}
|
|
1613
|
-
return `${base_url}${bestMatch}`;
|
|
1614
|
-
});
|
|
1615
|
-
}
|
|
1616
1459
|
|
|
1617
1460
|
function Button(_a) {
|
|
1618
1461
|
var { children, color = 'gray', variant = 'default', className = '' } = _a, rest = __rest(_a, ["children", "color", "variant", "className"]);
|
|
@@ -1649,5 +1492,5 @@ function Spinner() {
|
|
|
1649
1492
|
return (jsx("p", { className: 'animate-pulse', children: "Loading\u2026" }));
|
|
1650
1493
|
}
|
|
1651
1494
|
|
|
1652
|
-
export { API_PREFIX, BASE_URL, Button, Checkbox, DEV_PREFIX, DOMAIN_NAME, Input, PROD_PREFIX, PROTOCOL, SUB_DIR, Spinner, alertit,
|
|
1495
|
+
export { API_PREFIX, BASE_URL, Button, Checkbox, DEV_PREFIX, DOMAIN_NAME, Input, PROD_PREFIX, PROTOCOL, SUB_DIR, Spinner, alertit, callStorage, callWindowMethod, checkResponse, create_list_string, currentUsername, currentUsernames, decodeJwt, eatAll, eatEnd, eatInner, eatOuter, ensure_list, fetchIndexHtml, fetchIndexHtmlContainer, fetchIt, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, getAbsDir, getAbsPath, getAuthorizationHeader, getBaseDir, getBody, getComponentsUtilsDirectory, getConfig, getConfigContent, getConfigVar, getDbConfigsPath, getDistDir, getDocumentProp, getEnvDir, getEnvPath, getFetchVars, getFunctionsDir, getFunctionsUtilsDirectory, getHeaders, getHooksUtilsDirectory, getHtmlDirectory, getLibUtilsDirectory, getMethod, getPublicDir, getResult, getSafeDocument, getSafeLocalStorage, getSafeWindow, getSchemasDirPath, getSchemasPath, getSrcDir, getSubstring, getToken, getWindowHost, getWindowProp, 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, readJsonFile, requireToken, safeGlobalProp, safeStorage, sanitizeFilename, stripPrefixes, truncateString, tryParse };
|
|
1653
1496
|
//# sourceMappingURL=index.js.map
|