feat: update PDF stamp picker and server CORS settings for enhanced UI rendering

This commit is contained in:
Claudecio Martins
2026-10-11 19:45:30 -03:00
parent b46d8b665f
commit 994a27886e
9 changed files with 440 additions and 123 deletions
+64 -1
View File
@@ -691,8 +691,71 @@ export class CyberCoreSigner {
// Métodos Utilitários Internos
// =========================================================================
/**
* Executa requisições HTTP REST ao servidor local CCSP/1.
*
* @param {string} endpoint Caminho do endpoint (ex: '/ccsp/v1/status').
* @param {Object} [options={}] Opções do fetch (method, body, timeoutMs, etc).
* @returns {Promise<Object>} Resposta JSON decodificada.
*/
async _fetch(endpoint, options = {}) {
const url = `${this.baseUrl}${endpoint}`;
const timeout = options.timeoutMs || 15000;
const controller = typeof AbortController !== 'undefined' ? new AbortController() : null;
const timeoutId = controller ? setTimeout(() => controller.abort(), timeout) : null;
try {
const headers = {
'Accept': 'application/json',
'X-CyberCore-AppId': this.applicationId,
...(options.headers || {})
};
if (options.body && !headers['Content-Type']) {
headers['Content-Type'] = 'application/json';
}
const fetchOptions = {
...options,
headers
};
if (controller) {
fetchOptions.signal = controller.signal;
}
const res = await fetch(url, fetchOptions);
const data = await res.json().catch(() => ({}));
if (!res.ok) {
const errorCode = data.error_code || `HTTP_${res.status}`;
const message = data.message || `Erro retornado pelo agente (${res.status})`;
this._throwMappedError(errorCode, message);
}
return data;
} catch (err) {
if (err.name === 'AbortError') {
throw new CyberCoreError(`Tempo limite esgotado (${timeout}ms) na comunicação com o agente.`, 'TIMEOUT_ERROR');
}
if (err instanceof CyberCoreError) {
throw err;
}
throw new AgentNotRunningError(`Falha ao conectar com o CyberCore Signer em ${this.baseUrl}: ${err.message}`);
} finally {
if (timeoutId) {
clearTimeout(timeoutId);
}
}
}
async _fileToBuffer(file) {
if (file instanceof ArrayBuffer) return file;
if (file instanceof ArrayBuffer) {
if (file.byteLength === 0) {
throw new Error('O buffer binário está vazio ou foi desacoplado (detached). Forneça o objeto File ou Blob original.');
}
return file;
}
if (ArrayBuffer.isView(file)) {
return file.buffer.slice(file.byteOffset, file.byteOffset + file.byteLength);
}