123 lines
4.2 KiB
JavaScript
123 lines
4.2 KiB
JavaScript
"use strict";
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
var converter_resposta_e_licencie_para_p_resposta_exports = {};
|
|
__export(converter_resposta_e_licencie_para_p_resposta_exports, {
|
|
codigosErros: () => codigosErros,
|
|
converterRespostaELicencieParaPResposta: () => converterRespostaELicencieParaPResposta
|
|
});
|
|
module.exports = __toCommonJS(converter_resposta_e_licencie_para_p_resposta_exports);
|
|
var import_respostas = require("./respostas");
|
|
const codigosErros = {
|
|
400: "Erro de requisi\xE7\xE3o",
|
|
403: "N\xE3o autenticado",
|
|
500: "Erro interno",
|
|
504: "Tempo de resposta excedido"
|
|
};
|
|
const mapaCodigoELicencieParaPResposta = {
|
|
400: import_respostas.codigosResposta.erroConhecido,
|
|
403: import_respostas.codigosResposta.erroPermissao,
|
|
500: import_respostas.codigosResposta.erroDesconhecido,
|
|
504: import_respostas.codigosResposta.tempoEsgotado
|
|
};
|
|
const mapaCodigoPRespostaParaELicencie = {
|
|
[import_respostas.codigosResposta.erroConhecido]: 400,
|
|
[import_respostas.codigosResposta.erroPermissao]: 403,
|
|
[import_respostas.codigosResposta.erroDesconhecido]: 500,
|
|
[import_respostas.codigosResposta.erroNaoEncontrado]: 400,
|
|
[import_respostas.codigosResposta.tempoEsgotado]: 504
|
|
};
|
|
function eRespostaPadrao(entrada) {
|
|
return "cod" in entrada;
|
|
}
|
|
function detalhesParaArray(detalhes) {
|
|
if (!detalhes) return void 0;
|
|
if (Array.isArray(detalhes)) return detalhes;
|
|
const entries = Object.entries(detalhes);
|
|
if (entries.length === 0) return void 0;
|
|
return entries.map(([chave, valor]) => {
|
|
const valorStr = typeof valor === "string" ? valor : JSON.stringify(valor);
|
|
return `${chave}: ${valorStr}`;
|
|
});
|
|
}
|
|
function montarRespostaDual(op) {
|
|
const detalhesArray = detalhesParaArray(op.detalhesOriginal);
|
|
const detalhesRecord = op.detalhesOriginal && !Array.isArray(op.detalhesOriginal) ? op.detalhesOriginal : void 0;
|
|
return {
|
|
// P-Resposta
|
|
cod: op.cod,
|
|
valor: op.valor,
|
|
mensagem: op.mensagem,
|
|
eErro: op.eErro,
|
|
eCerto: !op.eErro,
|
|
detalhes: detalhesArray,
|
|
// ELicencie (runtime)
|
|
codigo: op.codigoELicencie,
|
|
erro: op.erroELicencie,
|
|
...detalhesRecord ? { detalhes: detalhesRecord } : {}
|
|
};
|
|
}
|
|
const converterRespostaELicencieParaPResposta = (entrada) => {
|
|
if (eRespostaPadrao(entrada)) {
|
|
if (!entrada.eErro) {
|
|
return montarRespostaDual({
|
|
cod: import_respostas.codigosResposta.sucesso,
|
|
valor: entrada.valor,
|
|
mensagem: void 0,
|
|
eErro: false,
|
|
codigoELicencie: 200,
|
|
erroELicencie: void 0,
|
|
detalhesOriginal: entrada.detalhes
|
|
});
|
|
}
|
|
return montarRespostaDual({
|
|
cod: entrada.cod,
|
|
valor: void 0,
|
|
mensagem: entrada.mensagem,
|
|
eErro: true,
|
|
codigoELicencie: mapaCodigoPRespostaParaELicencie[entrada.cod],
|
|
erroELicencie: entrada.mensagem,
|
|
detalhesOriginal: entrada.detalhes
|
|
});
|
|
}
|
|
if (!entrada.eErro) {
|
|
return montarRespostaDual({
|
|
cod: import_respostas.codigosResposta.sucesso,
|
|
valor: entrada.valor,
|
|
mensagem: void 0,
|
|
eErro: false,
|
|
codigoELicencie: entrada.codigo,
|
|
erroELicencie: void 0,
|
|
detalhesOriginal: entrada.detalhes
|
|
});
|
|
}
|
|
return montarRespostaDual({
|
|
cod: mapaCodigoELicencieParaPResposta[entrada.codigo],
|
|
valor: void 0,
|
|
mensagem: entrada.erro,
|
|
eErro: true,
|
|
codigoELicencie: entrada.codigo,
|
|
erroELicencie: entrada.erro,
|
|
detalhesOriginal: entrada.detalhes
|
|
});
|
|
};
|
|
// Annotate the CommonJS export names for ESM import in node:
|
|
0 && (module.exports = {
|
|
codigosErros,
|
|
converterRespostaELicencieParaPResposta
|
|
});
|