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