This commit is contained in:
Marcelo Dares
2026-04-29 01:15:50 +02:00
parent 65aaf9275e
commit ea23136288
172 changed files with 30358 additions and 353 deletions

View File

@@ -2,6 +2,25 @@ import { readFileSync, existsSync } from "node:fs";
import { resolve } from "node:path";
const DEFAULT_TIMEOUT_MS = 20000;
const DEFAULT_ENDPOINT = "/tender/SCRZJ";
function parseBoolean(value, fallback = false) {
if (!value) {
return fallback;
}
const normalized = value.trim().toLowerCase();
if (["1", "true", "yes", "si"].includes(normalized)) {
return true;
}
if (["0", "false", "no"].includes(normalized)) {
return false;
}
return fallback;
}
function loadDotenv(filePath) {
if (!existsSync(filePath)) {
@@ -40,10 +59,11 @@ function loadDotenv(filePath) {
function parseArgs(argv) {
const args = {
baseUrl: process.env.LICITAYA_BASE_URL,
endpoint: process.env.LICITAYA_TEST_ENDPOINT,
endpoint: process.env.LICITAYA_TEST_ENDPOINT || DEFAULT_ENDPOINT,
accept: process.env.LICITAYA_ACCEPT || "application/json",
method: "GET",
timeoutMs: Number.parseInt(process.env.LICITAYA_TIMEOUT_MS || "", 10) || DEFAULT_TIMEOUT_MS,
allowEmptySearch: parseBoolean(process.env.LICITAYA_ALLOW_EMPTY_SEARCH, true),
};
for (let i = 0; i < argv.length; i += 1) {
@@ -82,6 +102,11 @@ function parseArgs(argv) {
i += 1;
continue;
}
if (current === "--allow-empty-search") {
args.allowEmptySearch = true;
continue;
}
}
return args;
@@ -176,10 +201,17 @@ try {
console.log("--- Response Preview ---");
console.log(bodyPreview);
if (response.status === 404 && url.pathname.endsWith("/tender/search")) {
const isEmptySearch404 = response.status === 404 && url.pathname.endsWith("/tender/search");
if (isEmptySearch404) {
console.error("No tenders matched the current filters. Try a broader keyword or fewer filters.");
}
if (isEmptySearch404 && args.allowEmptySearch) {
console.log("Connectivity check passed (search endpoint returned 404 with no matches).");
process.exit(0);
}
if (!response.ok) {
process.exit(1);
}