@putkoff/abstract-utilities 0.1.183 → 0.1.184
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/index.js
CHANGED
|
@@ -1303,31 +1303,31 @@ function ensureAbstractUrl(endpoint, slices = []) {
|
|
|
1303
1303
|
`${windowHost}/api` // etc, if you need it
|
|
1304
1304
|
];
|
|
1305
1305
|
const stripped = stripPrefixes(endpoint, normalized);
|
|
1306
|
-
console.log('BUILD PREFIX:', prefix);
|
|
1307
|
-
console.log('RAW ENDPOINT:', endpoint);
|
|
1308
|
-
console.log('STRIPPED ENDPT:', stripped);
|
|
1309
1306
|
return make_path(prefix, stripped);
|
|
1310
1307
|
}
|
|
1311
1308
|
/**
|
|
1312
1309
|
* Given an “endpoint” slug like "api/list", build the full URL
|
|
1313
1310
|
* from the BASE_API_URL entry in your JSON config.
|
|
1311
|
+
* If anything goes wrong, just returns the raw endpoint.
|
|
1314
1312
|
*/
|
|
1315
1313
|
function get_app_config_url(endpoint) {
|
|
1316
1314
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1317
|
-
// 1) normalize + strip prefixes
|
|
1318
1315
|
const clean = stripHost(endpoint);
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1316
|
+
try {
|
|
1317
|
+
const vars = getFetchVars(null, 'POST', {
|
|
1318
|
+
key: 'BASE_API_URL',
|
|
1319
|
+
path: '/var/www/abstractendeavors/secure-files/public/config.json'
|
|
1320
|
+
});
|
|
1321
|
+
const resp = yield fetch(ensureAbstractUrl('/secure_env'), vars);
|
|
1322
|
+
checkResponse(resp);
|
|
1323
|
+
const json = yield resp.json();
|
|
1324
|
+
const baseUrl = getResult(json);
|
|
1325
|
+
return make_path(baseUrl, clean);
|
|
1326
|
+
}
|
|
1327
|
+
catch (err) {
|
|
1328
|
+
console.warn(`[get_app_config_url] failed, falling back to raw endpoint:`, endpoint, err);
|
|
1329
|
+
return endpoint;
|
|
1330
|
+
}
|
|
1331
1331
|
});
|
|
1332
1332
|
}
|
|
1333
1333
|
/**
|
|
@@ -1430,38 +1430,49 @@ function checkResponse(res) {
|
|
|
1430
1430
|
}
|
|
1431
1431
|
function fetchIt(endpoint_1) {
|
|
1432
1432
|
return __awaiter(this, arguments, void 0, function* (endpoint, body = null, method = null, headers = null, blob = false, noApi = false, withCredentials = true, returnJson = true, returnReult = true) {
|
|
1433
|
-
|
|
1434
|
-
// 1) auto-detect absolute URLs
|
|
1435
|
-
const isAbsolute = typeof endpoint === "string" && /^https?:\/\//i.test(endpoint);
|
|
1436
|
-
// 2) choose the URL
|
|
1433
|
+
const verb = (method || 'GET').toUpperCase();
|
|
1434
|
+
// 1) auto-detect absolute URLs, or use API lookup, but never throw
|
|
1437
1435
|
let url;
|
|
1438
|
-
|
|
1439
|
-
|
|
1436
|
+
try {
|
|
1437
|
+
const isAbsolute = typeof endpoint === 'string' && /^https?:\/\//i.test(endpoint);
|
|
1438
|
+
if (isAbsolute || noApi) {
|
|
1439
|
+
url = endpoint;
|
|
1440
|
+
}
|
|
1441
|
+
else {
|
|
1442
|
+
url = yield get_app_config_url(endpoint);
|
|
1443
|
+
}
|
|
1440
1444
|
}
|
|
1441
|
-
|
|
1445
|
+
catch (_a) {
|
|
1442
1446
|
url = endpoint;
|
|
1443
1447
|
}
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
}
|
|
1447
|
-
// 3) prepare headers & body
|
|
1448
|
-
headers = Object.assign(Object.assign(Object.assign({}, (body instanceof FormData ? {} : { "Content-Type": "application/json" })), getAuthorizationHeader()), headers);
|
|
1448
|
+
// 2) prepare headers & body
|
|
1449
|
+
const authHeaders = Object.assign({}, (body instanceof FormData ? {} : { 'Content-Type': 'application/json' }));
|
|
1450
|
+
headers = Object.assign(Object.assign(Object.assign({}, authHeaders), getFetchVars(null, verb, body).headers), headers);
|
|
1449
1451
|
const opts = {
|
|
1450
|
-
method,
|
|
1451
|
-
credentials: withCredentials ?
|
|
1452
|
+
method: verb,
|
|
1453
|
+
credentials: withCredentials ? 'include' : 'same-origin',
|
|
1452
1454
|
headers,
|
|
1453
1455
|
body: body instanceof FormData
|
|
1454
1456
|
? body
|
|
1455
|
-
: body != null &&
|
|
1457
|
+
: body != null && verb !== 'GET'
|
|
1456
1458
|
? JSON.stringify(body)
|
|
1457
1459
|
: undefined,
|
|
1458
1460
|
};
|
|
1459
|
-
console.debug(
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1461
|
+
console.debug('➡️ fetchIt →', url, opts);
|
|
1462
|
+
// 3) perform fetch, swallow any errors and return raw URL on failure
|
|
1463
|
+
let res;
|
|
1464
|
+
try {
|
|
1465
|
+
res = yield fetch(url, opts);
|
|
1466
|
+
if (!res.ok) {
|
|
1467
|
+
const err = yield res.text();
|
|
1468
|
+
throw new Error(`HTTP ${res.status}: ${err}`);
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
catch (err) {
|
|
1472
|
+
console.warn(`[fetchIt] failed for ${url}, returning raw endpoint:`, err);
|
|
1473
|
+
return url;
|
|
1464
1474
|
}
|
|
1475
|
+
// 4) produce the expected result
|
|
1465
1476
|
if (blob)
|
|
1466
1477
|
return res.blob();
|
|
1467
1478
|
if (returnReult)
|