.
This commit is contained in:
parent
e30a1a6f40
commit
3bcdbdcf90
17 changed files with 20 additions and 346 deletions
2
dist-import/autenticacao.d.ts
vendored
2
dist-import/autenticacao.d.ts
vendored
|
|
@ -1,4 +1,4 @@
|
|||
import { type tipoResposta } from "./respostas";
|
||||
import { type tipoResposta } from "~respostas";
|
||||
type tipoPostValidarTokem = {
|
||||
token: string;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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`;
|
||||
|
|
|
|||
1
dist-import/index.d.ts
vendored
1
dist-import/index.d.ts
vendored
|
|
@ -1,3 +1,2 @@
|
|||
export * from "./tokenQuipo";
|
||||
export * from "./autenticacao";
|
||||
export * from "./respostas";
|
||||
|
|
|
|||
|
|
@ -1,3 +1,2 @@
|
|||
export * from "./tokenQuipo";
|
||||
export * from "./autenticacao";
|
||||
export * from "./respostas";
|
||||
|
|
|
|||
34
dist-import/respostas.d.ts
vendored
34
dist-import/respostas.d.ts
vendored
|
|
@ -1,34 +0,0 @@
|
|||
export type tipoRespostaSucesso<T> = {
|
||||
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<T> = tipoRespostaSucesso<T> | tipoRespostaErro;
|
||||
export declare const gerarRespostas: <T>(registrarErroInterno: (erro: T) => Partial<tipoRespostaErro>) => {
|
||||
valor: <T_1>(valor: T_1) => tipoRespostaSucesso<T_1>;
|
||||
valorTrue: () => tipoRespostaSucesso<true>;
|
||||
erro: (mensagem: string) => tipoRespostaErro;
|
||||
erroPermissao: (mensagem?: string) => tipoRespostaErro;
|
||||
erroInterno: (parametros: T, mensagem?: string) => tipoRespostaErro;
|
||||
};
|
||||
/**
|
||||
* Uso de respostas em comuns
|
||||
*/
|
||||
export declare const respostaComuns: {
|
||||
valor: <T>(valor: T) => tipoRespostaSucesso<T>;
|
||||
valorTrue: () => tipoRespostaSucesso<true>;
|
||||
erro: (mensagem: string) => tipoRespostaErro;
|
||||
erroPermissao: (mensagem?: string) => tipoRespostaErro;
|
||||
erroInterno: (parametros: unknown, mensagem?: string) => tipoRespostaErro;
|
||||
};
|
||||
|
|
@ -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(() => ({}));
|
||||
2
dist-require/autenticacao.d.ts
vendored
2
dist-require/autenticacao.d.ts
vendored
|
|
@ -1,4 +1,4 @@
|
|||
import { type tipoResposta } from "./respostas";
|
||||
import { type tipoResposta } from "~respostas";
|
||||
type tipoPostValidarTokem = {
|
||||
token: string;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
1
dist-require/index.d.ts
vendored
1
dist-require/index.d.ts
vendored
|
|
@ -1,3 +1,2 @@
|
|||
export * from "./tokenQuipo";
|
||||
export * from "./autenticacao";
|
||||
export * from "./respostas";
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
34
dist-require/respostas.d.ts
vendored
34
dist-require/respostas.d.ts
vendored
|
|
@ -1,34 +0,0 @@
|
|||
export type tipoRespostaSucesso<T> = {
|
||||
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<T> = tipoRespostaSucesso<T> | tipoRespostaErro;
|
||||
export declare const gerarRespostas: <T>(registrarErroInterno: (erro: T) => Partial<tipoRespostaErro>) => {
|
||||
valor: <T_1>(valor: T_1) => tipoRespostaSucesso<T_1>;
|
||||
valorTrue: () => tipoRespostaSucesso<true>;
|
||||
erro: (mensagem: string) => tipoRespostaErro;
|
||||
erroPermissao: (mensagem?: string) => tipoRespostaErro;
|
||||
erroInterno: (parametros: T, mensagem?: string) => tipoRespostaErro;
|
||||
};
|
||||
/**
|
||||
* Uso de respostas em comuns
|
||||
*/
|
||||
export declare const respostaComuns: {
|
||||
valor: <T>(valor: T) => tipoRespostaSucesso<T>;
|
||||
valorTrue: () => tipoRespostaSucesso<true>;
|
||||
erro: (mensagem: string) => tipoRespostaErro;
|
||||
erroPermissao: (mensagem?: string) => tipoRespostaErro;
|
||||
erroInterno: (parametros: unknown, mensagem?: string) => tipoRespostaErro;
|
||||
};
|
||||
|
|
@ -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)(() => ({}));
|
||||
|
|
@ -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"
|
||||
},
|
||||
|
|
|
|||
11
pnpm-lock.yaml
generated
11
pnpm-lock.yaml
generated
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { respostaComuns, type tipoResposta } from "./respostas"
|
||||
|
||||
import { respostaComuns, type tipoResposta } from "~respostas"
|
||||
type tipoPostValidarTokem = { token: string }
|
||||
type tipoPostCodigoContaSite = { site: string }
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,2 @@
|
|||
export * from "./tokenQuipo"
|
||||
export * from "./autenticacao"
|
||||
export * from "./respostas"
|
||||
|
|
|
|||
108
src/respostas.ts
108
src/respostas.ts
|
|
@ -1,108 +0,0 @@
|
|||
export type tipoRespostaSucesso<T> = {
|
||||
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<T> = tipoRespostaSucesso<T> | tipoRespostaErro
|
||||
|
||||
export const gerarRespostas = <T>(
|
||||
registrarErroInterno: (erro: T) => Partial<tipoRespostaErro>,
|
||||
) => {
|
||||
/**
|
||||
* Gera uma resposta de sucesso
|
||||
*/
|
||||
const valor = <T>(valor: T): tipoRespostaSucesso<T> => {
|
||||
return {
|
||||
cod: 200,
|
||||
valor,
|
||||
mensagem: undefined,
|
||||
eErro: false,
|
||||
eCerto: true,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gera uma resposta de sucesso com valor true
|
||||
*/
|
||||
const valorTrue = (): tipoRespostaSucesso<true> => {
|
||||
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(() => ({}))
|
||||
Loading…
Add table
Add a link
Reference in a new issue