@putkoff/abstract-utilities 0.1.179 → 0.1.181
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 +38 -47
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +38 -47
- package/dist/esm/index.js.map +1 -1
- package/dist/functions/fetch_utils/src/fetchIt_utils.d.ts +3 -0
- package/dist/functions/fetch_utils/src/fetch_utils.d.ts +5 -2
- package/dist/functions/fetch_utils/src/index.d.ts +0 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -1197,6 +1197,10 @@ function getConfig(key) {
|
|
|
1197
1197
|
});
|
|
1198
1198
|
}
|
|
1199
1199
|
|
|
1200
|
+
// Constructs API URL from endpoint
|
|
1201
|
+
function api(endpoint) {
|
|
1202
|
+
return ensureAbstractUrl(endpoint);
|
|
1203
|
+
}
|
|
1200
1204
|
/**
|
|
1201
1205
|
* Strip a leading host (http://host) from any URL-like string.
|
|
1202
1206
|
*/
|
|
@@ -1205,34 +1209,43 @@ function stripHost(str) {
|
|
|
1205
1209
|
const hostPattern = `(?:https?:\\/\\/)?${getWindowHost()}`;
|
|
1206
1210
|
return str.replace(new RegExp(`^${hostPattern}`), '');
|
|
1207
1211
|
}
|
|
1212
|
+
function ensureAbstractUrl(endpoint, slices = []) {
|
|
1213
|
+
slices = slices || ['https//abstractendeavors.com', 'api'];
|
|
1214
|
+
// 1) build a prefix string like "api/v1/"
|
|
1215
|
+
const prefix = slices.map((s) => `${s}/`).join("");
|
|
1216
|
+
const windowHost = getWindowHost();
|
|
1217
|
+
const normalized = [
|
|
1218
|
+
'/',
|
|
1219
|
+
...slices,
|
|
1220
|
+
windowHost, // so "abstractendeavors.com" will be stripped
|
|
1221
|
+
`${windowHost}/api` // etc, if you need it
|
|
1222
|
+
];
|
|
1223
|
+
const stripped = stripPrefixes(endpoint, normalized);
|
|
1224
|
+
console.log('BUILD PREFIX:', prefix);
|
|
1225
|
+
console.log('RAW ENDPOINT:', endpoint);
|
|
1226
|
+
console.log('STRIPPED ENDPT:', stripped);
|
|
1227
|
+
return make_path(prefix, stripped);
|
|
1228
|
+
}
|
|
1208
1229
|
/**
|
|
1209
1230
|
* Given an “endpoint” slug like "api/list", build the full URL
|
|
1210
1231
|
* from the BASE_API_URL entry in your JSON config.
|
|
1211
1232
|
*/
|
|
1212
1233
|
function get_app_config_url(endpoint) {
|
|
1213
1234
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1214
|
-
// 1) normalize
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
}
|
|
1229
|
-
if (endpoint) {
|
|
1230
|
-
return endpoint;
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
catch (_a) {
|
|
1234
|
-
return endpoint;
|
|
1235
|
-
}
|
|
1235
|
+
// 1) normalize + strip prefixes
|
|
1236
|
+
const clean = stripHost(endpoint);
|
|
1237
|
+
// 2) fetch your BASE_API_URL
|
|
1238
|
+
const vars = getFetchVars(null, 'POST', {
|
|
1239
|
+
key: 'BASE_API_URL',
|
|
1240
|
+
path: '/var/www/abstractendeavors/secure-files/public/config.json'
|
|
1241
|
+
});
|
|
1242
|
+
const resp = yield fetch(ensureAbstractUrl('/secure_env'), vars);
|
|
1243
|
+
checkResponse(resp);
|
|
1244
|
+
// 3) parse, then unwrap { result }
|
|
1245
|
+
const json = yield resp.json();
|
|
1246
|
+
const baseUrl = getResult(json);
|
|
1247
|
+
// 4) now build your final URL
|
|
1248
|
+
return make_path(baseUrl, clean);
|
|
1236
1249
|
});
|
|
1237
1250
|
}
|
|
1238
1251
|
/**
|
|
@@ -1333,10 +1346,10 @@ function checkResponse(res) {
|
|
|
1333
1346
|
}
|
|
1334
1347
|
return res;
|
|
1335
1348
|
}
|
|
1336
|
-
function fetchIt(
|
|
1337
|
-
return __awaiter(this,
|
|
1349
|
+
function fetchIt(url_1) {
|
|
1350
|
+
return __awaiter(this, arguments, void 0, function* (url, body = null, method = null, headers = null, blob = false, configUrl = false, withCredentials = true, returnJson = true, returnReult = true) {
|
|
1338
1351
|
method = method || "GET";
|
|
1339
|
-
if (!
|
|
1352
|
+
if (!configUrl) {
|
|
1340
1353
|
url = yield get_app_config_url(url);
|
|
1341
1354
|
}
|
|
1342
1355
|
// headers: JSON by default, plus any auth + overrides
|
|
@@ -1406,28 +1419,6 @@ function fetchSharePatch(file_1) {
|
|
|
1406
1419
|
}
|
|
1407
1420
|
});
|
|
1408
1421
|
}
|
|
1409
|
-
|
|
1410
|
-
function ensureAbstractUrl(endpoint, slices = []) {
|
|
1411
|
-
slices = slices || ['https//abstractendeavors.com', 'api'];
|
|
1412
|
-
// 1) build a prefix string like "api/v1/"
|
|
1413
|
-
const prefix = slices.map((s) => `${s}/`).join("");
|
|
1414
|
-
const windowHost = getWindowHost();
|
|
1415
|
-
const normalized = [
|
|
1416
|
-
'/',
|
|
1417
|
-
...slices,
|
|
1418
|
-
windowHost, // so "abstractendeavors.com" will be stripped
|
|
1419
|
-
`${windowHost}/api` // etc, if you need it
|
|
1420
|
-
];
|
|
1421
|
-
const stripped = stripPrefixes(endpoint, normalized);
|
|
1422
|
-
console.log('BUILD PREFIX:', prefix);
|
|
1423
|
-
console.log('RAW ENDPOINT:', endpoint);
|
|
1424
|
-
console.log('STRIPPED ENDPT:', stripped);
|
|
1425
|
-
return make_path(prefix, stripped);
|
|
1426
|
-
}
|
|
1427
|
-
// Constructs API URL from endpoint
|
|
1428
|
-
function api(endpoint) {
|
|
1429
|
-
return ensureAbstractUrl(endpoint);
|
|
1430
|
-
}
|
|
1431
1422
|
// Constructs HTML directory path
|
|
1432
1423
|
function getHtmlDirectory(directory, filename) {
|
|
1433
1424
|
return `${directory}/${filename}.html`;
|