ci-validation
Version:
🇺🇾 Complete TypeScript/JavaScript library for validating Uruguayan CI (Cédula de Identidad) with official algorithm and government service integration
68 lines • 3.06 kB
JavaScript
/**
* Utility function to extract proInstId and proEleInstId from XML response
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractProcessInstanceIds = extractProcessInstanceIds;
/**
* Extrae proInstId y proEleInstId de una respuesta XML
* @param xmlResponse - La respuesta XML que contiene la URL con los parámetros
* @returns Objeto con proInstId y proEleInstId extraĂdos
*/
function extractProcessInstanceIds(xmlResponse) {
try {
console.log(`🔍 Extracting process instance IDs from XML response...`);
// Buscar el atributo url en el XML
const urlMatch = xmlResponse.match(/url="([^"]+)"/);
if (!urlMatch) {
console.error("❌ No URL attribute found in XML response");
return null;
}
let url = urlMatch[1];
// Decodificar entidades HTML (& -> &)
url = url.replace(/&/g, "&");
console.log(`📡 Extracted URL: ${url}`);
// Extraer proInstId y proEleInstId usando regex
const proInstIdMatch = url.match(/proInstId=([^&]+)/);
const proEleInstIdMatch = url.match(/proEleInstId=([^&]+)/);
if (!proInstIdMatch || !proEleInstIdMatch) {
console.error("❌ proInstId or proEleInstId not found in URL");
return null;
}
const result = {
proInstId: proInstIdMatch[1],
proEleInstId: proEleInstIdMatch[1],
};
console.log(`âś… Extracted process IDs:`, result);
return result;
}
catch (error) {
console.error("❌ Error extracting process instance IDs:", error);
return null;
}
}
// Test the function
console.log("đź§Ş Testing extractProcessInstanceIds function\n");
// Test case 1: XML response válido
const xmlResponse1 = '<?xml version="1.0" encoding="iso-8859-1"?><result url="apia.execution.TaskAction.run?action=getTask&proInstId=83432&proEleInstId=4358057&fromWizzard=true&tabId=1754188254534&tokenId=1754188254448" />';
console.log("Test 1 - XML response válido:");
const result1 = extractProcessInstanceIds(xmlResponse1);
console.log("Result:", result1);
console.log("\n" + "=".repeat(50) + "\n");
// Test case 2: XML con diferentes valores
const xmlResponse2 = '<?xml version="1.0" encoding="iso-8859-1"?><result url="apia.execution.TaskAction.run?action=getTask&proInstId=12345&proEleInstId=67890&fromWizzard=true&tabId=9999&tokenId=8888" />';
console.log("Test 2 - XML con diferentes valores:");
const result2 = extractProcessInstanceIds(xmlResponse2);
console.log("Result:", result2);
console.log("\n" + "=".repeat(50) + "\n");
// Test case 3: Formato JSON para uso fácil
console.log("Example JSON format for integration:");
if (result1) {
const jsonFormat = {
processInstanceIds: result1,
extractedAt: new Date().toISOString(),
source: "XML response extraction",
};
console.log(JSON.stringify(jsonFormat, null, 2));
}
//# sourceMappingURL=extractProcessInstanceIds.js.map
;