From 3bcdbdcf90eabbb59dd6b6f94944bfd6b5260a3b Mon Sep 17 00:00:00 2001 From: "Luiz H. R. Silva" Date: Tue, 4 Jun 2024 14:46:58 -0300 Subject: [PATCH] . --- dist-import/autenticacao.d.ts | 2 +- dist-import/autenticacao.js | 2 +- dist-import/index.d.ts | 1 - dist-import/index.js | 1 - dist-import/respostas.d.ts | 34 ----------- dist-import/respostas.js | 76 ----------------------- dist-require/autenticacao.d.ts | 2 +- dist-require/autenticacao.js | 6 +- dist-require/index.d.ts | 1 - dist-require/index.js | 1 - dist-require/respostas.d.ts | 34 ----------- dist-require/respostas.js | 80 ------------------------ package.json | 3 +- pnpm-lock.yaml | 11 ++++ src/autenticacao.ts | 3 +- src/index.ts | 1 - src/respostas.ts | 108 --------------------------------- 17 files changed, 20 insertions(+), 346 deletions(-) delete mode 100644 dist-import/respostas.d.ts delete mode 100644 dist-import/respostas.js delete mode 100644 dist-require/respostas.d.ts delete mode 100644 dist-require/respostas.js delete mode 100644 src/respostas.ts diff --git a/dist-import/autenticacao.d.ts b/dist-import/autenticacao.d.ts index 8b761a1..cb35680 100644 --- a/dist-import/autenticacao.d.ts +++ b/dist-import/autenticacao.d.ts @@ -1,4 +1,4 @@ -import { type tipoResposta } from "./respostas"; +import { type tipoResposta } from "~respostas"; type tipoPostValidarTokem = { token: string; }; diff --git a/dist-import/autenticacao.js b/dist-import/autenticacao.js index 6e7186d..82360b5 100644 --- a/dist-import/autenticacao.js +++ b/dist-import/autenticacao.js @@ -1,4 +1,4 @@ -import { respostaComuns } from "./respostas"; +import { respostaComuns } from "~respostas"; const urlAutenticacao = (ambiente) => `${ambiente == "producao" ? "https://carro-de-boi.idz.one" : "http://localhost:5030"}/autenticacao`; diff --git a/dist-import/index.d.ts b/dist-import/index.d.ts index 2a403c3..6475344 100644 --- a/dist-import/index.d.ts +++ b/dist-import/index.d.ts @@ -1,3 +1,2 @@ export * from "./tokenQuipo"; export * from "./autenticacao"; -export * from "./respostas"; diff --git a/dist-import/index.js b/dist-import/index.js index 2a403c3..6475344 100644 --- a/dist-import/index.js +++ b/dist-import/index.js @@ -1,3 +1,2 @@ export * from "./tokenQuipo"; export * from "./autenticacao"; -export * from "./respostas"; diff --git a/dist-import/respostas.d.ts b/dist-import/respostas.d.ts deleted file mode 100644 index 8159105..0000000 --- a/dist-import/respostas.d.ts +++ /dev/null @@ -1,34 +0,0 @@ -export type tipoRespostaSucesso = { - cod: 200; - valor: T; - mensagem: undefined; - eErro: false; - eCerto: true; - detalhe?: undefined; -}; -export type tipoRespostaErro = { - cod: 400 | 401 | 500; - valor: undefined; - mensagem: string; - eErro: true; - eCerto: false; - detalhe?: string[]; -}; -export type tipoResposta = tipoRespostaSucesso | tipoRespostaErro; -export declare const gerarRespostas: (registrarErroInterno: (erro: T) => Partial) => { - valor: (valor: T_1) => tipoRespostaSucesso; - valorTrue: () => tipoRespostaSucesso; - erro: (mensagem: string) => tipoRespostaErro; - erroPermissao: (mensagem?: string) => tipoRespostaErro; - erroInterno: (parametros: T, mensagem?: string) => tipoRespostaErro; -}; -/** - * Uso de respostas em comuns - */ -export declare const respostaComuns: { - valor: (valor: T) => tipoRespostaSucesso; - valorTrue: () => tipoRespostaSucesso; - erro: (mensagem: string) => tipoRespostaErro; - erroPermissao: (mensagem?: string) => tipoRespostaErro; - erroInterno: (parametros: unknown, mensagem?: string) => tipoRespostaErro; -}; diff --git a/dist-import/respostas.js b/dist-import/respostas.js deleted file mode 100644 index f2d5bfc..0000000 --- a/dist-import/respostas.js +++ /dev/null @@ -1,76 +0,0 @@ -export const gerarRespostas = (registrarErroInterno) => { - /** - * Gera uma resposta de sucesso - */ - const valor = (valor) => { - return { - cod: 200, - valor, - mensagem: undefined, - eErro: false, - eCerto: true, - }; - }; - /** - * Gera uma resposta de sucesso com valor true - */ - const valorTrue = () => { - return { - cod: 200, - valor: true, - mensagem: undefined, - eErro: false, - eCerto: true, - }; - }; - /** - * Gera uma resposta de erro conhecido - */ - const erro = (mensagem) => { - return { - cod: 400, - valor: undefined, - mensagem, - eErro: true, - eCerto: false, - }; - }; - /** - * Gera uma resposta de erro de permissão,será necessário fazer o login novamente - */ - const erroPermissao = (mensagem) => { - return { - cod: 401, - valor: undefined, - mensagem: mensagem || "Sem permissão para esse recurso.", - eErro: true, - eCerto: false, - }; - }; - /** - * Gera uma resposta de erro desconhecido, geralmente tem origem de um exception - */ - const erroInterno = (parametros, mensagem) => { - const resRegistro = registrarErroInterno(parametros); - const mensagemFim = `${mensagem || "Erro interno"}`; - return { - cod: 500, - valor: undefined, - mensagem: mensagemFim, - eErro: true, - eCerto: false, - ...resRegistro, - }; - }; - return { - valor, - valorTrue, - erro, - erroPermissao, - erroInterno, - }; -}; -/** - * Uso de respostas em comuns - */ -export const respostaComuns = gerarRespostas(() => ({})); diff --git a/dist-require/autenticacao.d.ts b/dist-require/autenticacao.d.ts index 8b761a1..cb35680 100644 --- a/dist-require/autenticacao.d.ts +++ b/dist-require/autenticacao.d.ts @@ -1,4 +1,4 @@ -import { type tipoResposta } from "./respostas"; +import { type tipoResposta } from "~respostas"; type tipoPostValidarTokem = { token: string; }; diff --git a/dist-require/autenticacao.js b/dist-require/autenticacao.js index bdb60e0..bb09cc3 100644 --- a/dist-require/autenticacao.js +++ b/dist-require/autenticacao.js @@ -1,7 +1,7 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.pAutenticacao = void 0; -const respostas_1 = require("./respostas"); +const _respostas_1 = require("~respostas"); const urlAutenticacao = (ambiente) => `${ambiente == "producao" ? "https://carro-de-boi.idz.one" : "http://localhost:5030"}/autenticacao`; @@ -21,11 +21,11 @@ const validarToken = async ({ ambiente, post, buscar, }) => { const codigoContaSite = async ({ ambiente, post, buscar, }) => { const url = `${urlAutenticacao(ambiente)}/autenticacao/api/codigo_prefeitura_site`; try { - const resp = await buscar(url, post).catch((e) => respostas_1.respostaComuns.erro(`erro ao buscar código do site: ${e}`)); + const resp = await buscar(url, post).catch((e) => _respostas_1.respostaComuns.erro(`erro ao buscar código do site: ${e}`)); return resp; } catch (e) { - return respostas_1.respostaComuns.erro(`erro ao buscar código do site: ${e}`); + return _respostas_1.respostaComuns.erro(`erro ao buscar código do site: ${e}`); } }; /** todas as rotas de comunicação com autenticador partem dessa variável */ diff --git a/dist-require/index.d.ts b/dist-require/index.d.ts index 2a403c3..6475344 100644 --- a/dist-require/index.d.ts +++ b/dist-require/index.d.ts @@ -1,3 +1,2 @@ export * from "./tokenQuipo"; export * from "./autenticacao"; -export * from "./respostas"; diff --git a/dist-require/index.js b/dist-require/index.js index 30eb08f..a287750 100644 --- a/dist-require/index.js +++ b/dist-require/index.js @@ -16,4 +16,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) { Object.defineProperty(exports, "__esModule", { value: true }); __exportStar(require("./tokenQuipo"), exports); __exportStar(require("./autenticacao"), exports); -__exportStar(require("./respostas"), exports); diff --git a/dist-require/respostas.d.ts b/dist-require/respostas.d.ts deleted file mode 100644 index 8159105..0000000 --- a/dist-require/respostas.d.ts +++ /dev/null @@ -1,34 +0,0 @@ -export type tipoRespostaSucesso = { - cod: 200; - valor: T; - mensagem: undefined; - eErro: false; - eCerto: true; - detalhe?: undefined; -}; -export type tipoRespostaErro = { - cod: 400 | 401 | 500; - valor: undefined; - mensagem: string; - eErro: true; - eCerto: false; - detalhe?: string[]; -}; -export type tipoResposta = tipoRespostaSucesso | tipoRespostaErro; -export declare const gerarRespostas: (registrarErroInterno: (erro: T) => Partial) => { - valor: (valor: T_1) => tipoRespostaSucesso; - valorTrue: () => tipoRespostaSucesso; - erro: (mensagem: string) => tipoRespostaErro; - erroPermissao: (mensagem?: string) => tipoRespostaErro; - erroInterno: (parametros: T, mensagem?: string) => tipoRespostaErro; -}; -/** - * Uso de respostas em comuns - */ -export declare const respostaComuns: { - valor: (valor: T) => tipoRespostaSucesso; - valorTrue: () => tipoRespostaSucesso; - erro: (mensagem: string) => tipoRespostaErro; - erroPermissao: (mensagem?: string) => tipoRespostaErro; - erroInterno: (parametros: unknown, mensagem?: string) => tipoRespostaErro; -}; diff --git a/dist-require/respostas.js b/dist-require/respostas.js deleted file mode 100644 index 2944f7a..0000000 --- a/dist-require/respostas.js +++ /dev/null @@ -1,80 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.respostaComuns = exports.gerarRespostas = void 0; -const gerarRespostas = (registrarErroInterno) => { - /** - * Gera uma resposta de sucesso - */ - const valor = (valor) => { - return { - cod: 200, - valor, - mensagem: undefined, - eErro: false, - eCerto: true, - }; - }; - /** - * Gera uma resposta de sucesso com valor true - */ - const valorTrue = () => { - return { - cod: 200, - valor: true, - mensagem: undefined, - eErro: false, - eCerto: true, - }; - }; - /** - * Gera uma resposta de erro conhecido - */ - const erro = (mensagem) => { - return { - cod: 400, - valor: undefined, - mensagem, - eErro: true, - eCerto: false, - }; - }; - /** - * Gera uma resposta de erro de permissão,será necessário fazer o login novamente - */ - const erroPermissao = (mensagem) => { - return { - cod: 401, - valor: undefined, - mensagem: mensagem || "Sem permissão para esse recurso.", - eErro: true, - eCerto: false, - }; - }; - /** - * Gera uma resposta de erro desconhecido, geralmente tem origem de um exception - */ - const erroInterno = (parametros, mensagem) => { - const resRegistro = registrarErroInterno(parametros); - const mensagemFim = `${mensagem || "Erro interno"}`; - return { - cod: 500, - valor: undefined, - mensagem: mensagemFim, - eErro: true, - eCerto: false, - ...resRegistro, - }; - }; - return { - valor, - valorTrue, - erro, - erroPermissao, - erroInterno, - }; -}; -exports.gerarRespostas = gerarRespostas; -/** - * Uso de respostas em comuns - */ -exports.respostaComuns = (0, exports.gerarRespostas)(() => ({})); diff --git a/package.json b/package.json index f342dcb..70e6b39 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "~drives", - "version": "0.18.0", + "version": "0.21.0", "description": "", "main": "src/index.ts", "exports": { @@ -20,6 +20,7 @@ "@biomejs/biome": "1.7.3", "@types/node": "^20.12.7", "check-node-version": "^4.2.1", + "~respostas": "git+http://leitura:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTQ3NTA1NzYsImlzcyI6IkdpdG5lc3MiLCJwaWQiOjgsInRrbiI6eyJ0eXAiOiJwYXQiLCJpZCI6MzJ9fQ.OYdExOVQm5UI3wfeTaWjmD0o65Y1hrjFz5EvMB1a__U@git.idz.one:3000/git/multi-modulos-ambientais/_respostas.git#producao", "~comuns": "git+http://leitura:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTQ3NTA1NzYsImlzcyI6IkdpdG5lc3MiLCJwaWQiOjgsInRrbiI6eyJ0eXAiOiJwYXQiLCJpZCI6MzJ9fQ.OYdExOVQm5UI3wfeTaWjmD0o65Y1hrjFz5EvMB1a__U@git.idz.one:3000/git/multi-modulos-ambientais/_comuns.git#producao", "typescript": "^4.8.4" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 420669e..4110b29 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -27,6 +27,9 @@ importers: ~comuns: specifier: git+http://leitura:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTQ3NTA1NzYsImlzcyI6IkdpdG5lc3MiLCJwaWQiOjgsInRrbiI6eyJ0eXAiOiJwYXQiLCJpZCI6MzJ9fQ.OYdExOVQm5UI3wfeTaWjmD0o65Y1hrjFz5EvMB1a__U@git.idz.one:3000/git/multi-modulos-ambientais/_comuns.git#producao version: git+http://leitura:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTQ3NTA1NzYsImlzcyI6IkdpdG5lc3MiLCJwaWQiOjgsInRrbiI6eyJ0eXAiOiJwYXQiLCJpZCI6MzJ9fQ.OYdExOVQm5UI3wfeTaWjmD0o65Y1hrjFz5EvMB1a__U@git.idz.one:3000/git/multi-modulos-ambientais/_comuns.git#0482d3c102440334a120afd0327234a888892534(typescript@4.9.5) + ~respostas: + specifier: git+http://leitura:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTQ3NTA1NzYsImlzcyI6IkdpdG5lc3MiLCJwaWQiOjgsInRrbiI6eyJ0eXAiOiJwYXQiLCJpZCI6MzJ9fQ.OYdExOVQm5UI3wfeTaWjmD0o65Y1hrjFz5EvMB1a__U@git.idz.one:3000/git/multi-modulos-ambientais/_respostas.git#producao + version: git+http://leitura:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTQ3NTA1NzYsImlzcyI6IkdpdG5lc3MiLCJwaWQiOjgsInRrbiI6eyJ0eXAiOiJwYXQiLCJpZCI6MzJ9fQ.OYdExOVQm5UI3wfeTaWjmD0o65Y1hrjFz5EvMB1a__U@git.idz.one:3000/git/multi-modulos-ambientais/_respostas.git#2cedd41095ad7e964b5ec43bf1ae0480290d493e packages: @@ -150,6 +153,10 @@ packages: peerDependencies: typescript: ^5.0.0 + ~respostas@git+http://leitura:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTQ3NTA1NzYsImlzcyI6IkdpdG5lc3MiLCJwaWQiOjgsInRrbiI6eyJ0eXAiOiJwYXQiLCJpZCI6MzJ9fQ.OYdExOVQm5UI3wfeTaWjmD0o65Y1hrjFz5EvMB1a__U@git.idz.one:3000/git/multi-modulos-ambientais/_respostas.git#2cedd41095ad7e964b5ec43bf1ae0480290d493e: + resolution: {commit: 2cedd41095ad7e964b5ec43bf1ae0480290d493e, repo: http://leitura:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTQ3NTA1NzYsImlzcyI6IkdpdG5lc3MiLCJwaWQiOjgsInRrbiI6eyJ0eXAiOiJwYXQiLCJpZCI6MzJ9fQ.OYdExOVQm5UI3wfeTaWjmD0o65Y1hrjFz5EvMB1a__U@git.idz.one:3000/git/multi-modulos-ambientais/_respostas.git, type: git} + version: 0.2.0 + snapshots: '@biomejs/biome@1.7.3': @@ -245,3 +252,7 @@ snapshots: dependencies: typescript: 4.9.5 zod: 3.23.8 + + ~respostas@git+http://leitura:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MTQ3NTA1NzYsImlzcyI6IkdpdG5lc3MiLCJwaWQiOjgsInRrbiI6eyJ0eXAiOiJwYXQiLCJpZCI6MzJ9fQ.OYdExOVQm5UI3wfeTaWjmD0o65Y1hrjFz5EvMB1a__U@git.idz.one:3000/git/multi-modulos-ambientais/_respostas.git#2cedd41095ad7e964b5ec43bf1ae0480290d493e: + dependencies: + zod: 3.23.8 diff --git a/src/autenticacao.ts b/src/autenticacao.ts index 283a2e9..d91b8af 100644 --- a/src/autenticacao.ts +++ b/src/autenticacao.ts @@ -1,5 +1,4 @@ -import { respostaComuns, type tipoResposta } from "./respostas" - +import { respostaComuns, type tipoResposta } from "~respostas" type tipoPostValidarTokem = { token: string } type tipoPostCodigoContaSite = { site: string } diff --git a/src/index.ts b/src/index.ts index 0f6cf16..e159102 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,2 @@ export * from "./tokenQuipo" export * from "./autenticacao" -export * from "./respostas" diff --git a/src/respostas.ts b/src/respostas.ts deleted file mode 100644 index a14395c..0000000 --- a/src/respostas.ts +++ /dev/null @@ -1,108 +0,0 @@ -export type tipoRespostaSucesso = { - cod: 200 - valor: T - mensagem: undefined - eErro: false - eCerto: true - detalhe?: undefined -} - -export type tipoRespostaErro = { - //400 é um erro conhecido, - //500 é um erro desconhecido, geralmente tem origem de um exception - cod: 400 | 401 | 500 - valor: undefined - mensagem: string - eErro: true - eCerto: false - detalhe?: string[] -} - -export type tipoResposta = tipoRespostaSucesso | tipoRespostaErro - -export const gerarRespostas = ( - registrarErroInterno: (erro: T) => Partial, -) => { - /** - * Gera uma resposta de sucesso - */ - const valor = (valor: T): tipoRespostaSucesso => { - return { - cod: 200, - valor, - mensagem: undefined, - eErro: false, - eCerto: true, - } - } - - /** - * Gera uma resposta de sucesso com valor true - */ - const valorTrue = (): tipoRespostaSucesso => { - return { - cod: 200, - valor: true, - mensagem: undefined, - eErro: false, - eCerto: true, - } - } - - /** - * Gera uma resposta de erro conhecido - */ - const erro = (mensagem: string): tipoRespostaErro => { - return { - cod: 400, - valor: undefined, - mensagem, - eErro: true, - eCerto: false, - } - } - - /** - * Gera uma resposta de erro de permissão,será necessário fazer o login novamente - */ - const erroPermissao = (mensagem?: string): tipoRespostaErro => { - return { - cod: 401, - valor: undefined, - mensagem: mensagem || "Sem permissão para esse recurso.", - eErro: true, - eCerto: false, - } - } - - /** - * Gera uma resposta de erro desconhecido, geralmente tem origem de um exception - */ - const erroInterno = (parametros: T, mensagem?: string): tipoRespostaErro => { - const resRegistro = registrarErroInterno(parametros) - - const mensagemFim = `${mensagem || "Erro interno"}` - - return { - cod: 500, - valor: undefined, - mensagem: mensagemFim, - eErro: true, - eCerto: false, - ...resRegistro, - } - } - - return { - valor, - valorTrue, - erro, - erroPermissao, - erroInterno, - } -} - -/** - * Uso de respostas em comuns - */ -export const respostaComuns = gerarRespostas(() => ({}))