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