import cFetch from "cross-fetch"; import { cacheM } from "p-comuns"; import { respostaComuns } from "p-respostas"; import { uuidV3 } from "./plugins/uuid"; const tx_vinculos__listar = "vinculos__listar"; const listarVinculos = async ({ token, url_api_autenticacao, desativarCache }) => { const chaveCache = uuidV3({ token, url_api_autenticacao }); if (!desativarCache) { const valorCache = cacheM(chaveCache); if (valorCache) return valorCache; } const res = (async () => { const url = `${url_api_autenticacao}/api/${tx_vinculos__listar}`; return cFetch(url, { headers: { token, "Content-Type": "application/json" }, body: "{}", method: "post" }).then(async (a) => { const texto = await a.text(); try { const res2 = JSON.parse(texto); return res2; } catch (error) { return respostaComuns.erro( `Erro ao listar cidades: ${error.message}`, [texto, error] ); } }).catch( (error) => respostaComuns.erro(`Erro ao listar cidades: ${error.message}`, [ error ]) ); })(); cacheM( chaveCache, res.then((a) => { try { } catch { } return a; }), 10 ); return res; }; export { listarVinculos, tx_vinculos__listar };