build
This commit is contained in:
parent
20fb47126d
commit
ccc6e94e8c
12 changed files with 21 additions and 291 deletions
|
|
@ -1,33 +0,0 @@
|
|||
import { respostaComuns, type tipoResposta } from "p-respostas"
|
||||
import type { z } from "zod"
|
||||
import type { zAmbiente } from "../ts/ambiente"
|
||||
import { urlAutenticacao } from "./_urlAutenticacao"
|
||||
type tipoPostCodigoContaSite = { site: string }
|
||||
import node_fetch from "cross-fetch"
|
||||
|
||||
export const codigoContaSite = async ({
|
||||
ambiente,
|
||||
post,
|
||||
}: {
|
||||
ambiente: z.infer<typeof zAmbiente>
|
||||
post: tipoPostCodigoContaSite
|
||||
}): Promise<tipoResposta<string>> => {
|
||||
const url = `${urlAutenticacao(ambiente)}/api/codigo_prefeitura_site`
|
||||
|
||||
try {
|
||||
const resp = await node_fetch(url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(post),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.catch((e) =>
|
||||
respostaComuns.erro("Erro ao enviar registros", [e.message]),
|
||||
)
|
||||
.then((r) => r as tipoResposta<string>)
|
||||
|
||||
return resp
|
||||
} catch (e) {
|
||||
return respostaComuns.erro(`erro ao buscar código do site: ${e}`)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
import type { z } from "zod"
|
||||
import type { zAmbiente } from "../ts/ambiente"
|
||||
|
||||
export const urlAutenticacao = (ambiente: z.infer<typeof zAmbiente>) =>
|
||||
`${
|
||||
ambiente == "producao"
|
||||
? "https://carro-de-boi.idz.one"
|
||||
: "http://localhost:5030"
|
||||
}/autenticacao`
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
import node_fetch from "cross-fetch"
|
||||
import { respostaComuns, type tipoResposta } from "p-respostas"
|
||||
import type { z } from "zod"
|
||||
import type { tipos_de_acesso_quipo } from "../tokenQuipo"
|
||||
import type { zAmbiente } from "../ts/ambiente"
|
||||
import { urlAutenticacao } from "./_urlAutenticacao"
|
||||
|
||||
export type tipoUsuarioExterno = {
|
||||
_nome: string
|
||||
_email: string
|
||||
_telefone: string
|
||||
vinculo: string
|
||||
$cliente: string
|
||||
chave_produto: string
|
||||
codigo: string
|
||||
_cpf: string
|
||||
}
|
||||
|
||||
export const usuarios_quipo = async ({
|
||||
token_produto,
|
||||
ambiente,
|
||||
tipo,
|
||||
}: {
|
||||
ambiente: z.infer<typeof zAmbiente>
|
||||
token_produto: string
|
||||
tipo: tipos_de_acesso_quipo
|
||||
}): Promise<tipoResposta<tipoUsuarioExterno[]>> => {
|
||||
const url = `${urlAutenticacao(ambiente)}/api/usuarios_quipo`
|
||||
|
||||
if (!token_produto) return respostaComuns.erro("token_produto não informado")
|
||||
|
||||
const headers = {
|
||||
token: token_produto,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
return node_fetch(url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ tipo }),
|
||||
headers,
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.catch((e) =>
|
||||
respostaComuns.erro(`Erro ao buscar usuários quipo governo ${e.message}`),
|
||||
)
|
||||
.then((r) => r as tipoResposta<tipoUsuarioExterno[]>)
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
import node_fetch from "cross-fetch"
|
||||
import { respostaComuns, type tipoResposta } from "p-respostas"
|
||||
import type { z } from "zod"
|
||||
import type { zAmbiente } from "../ts/ambiente"
|
||||
import { urlAutenticacao } from "./_urlAutenticacao"
|
||||
|
||||
export const usuarios_quipo_vincular = async ({
|
||||
token_produto,
|
||||
ambiente,
|
||||
$cliente,
|
||||
vinculo,
|
||||
codigo_usuario,
|
||||
email,
|
||||
}: {
|
||||
ambiente: z.infer<typeof zAmbiente>
|
||||
token_produto: string
|
||||
$cliente: string
|
||||
vinculo: string
|
||||
codigo_usuario?: string
|
||||
email: string
|
||||
}): Promise<tipoResposta<string>> => {
|
||||
const url = `${urlAutenticacao(ambiente)}/api/vinculos__criar`
|
||||
|
||||
if (!token_produto) return respostaComuns.erro("token_produto não informado")
|
||||
const headers = {
|
||||
token: token_produto,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
const parametros = {
|
||||
vinculos: { $cliente, codigo_usuario, vinculo },
|
||||
email: email,
|
||||
}
|
||||
return await node_fetch(url, {
|
||||
headers,
|
||||
body: JSON.stringify(parametros),
|
||||
method: "POST",
|
||||
})
|
||||
.then(async (r) => await r.json())
|
||||
.catch((e) =>
|
||||
respostaComuns.erro(`Erro ao criar vinculo de usuario ${e.message}`),
|
||||
)
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
import type { tipoResposta } from "p-respostas"
|
||||
import { urlAutenticacao } from "./_urlAutenticacao"
|
||||
type tipoPostValidarTokem = { token: string }
|
||||
import node_fetch from "cross-fetch"
|
||||
import type { z } from "zod"
|
||||
import type { zAmbiente } from "../ts/ambiente"
|
||||
|
||||
/** faz a validação do token */
|
||||
export const validarToken = async ({
|
||||
ambiente,
|
||||
post,
|
||||
}: {
|
||||
ambiente: z.infer<typeof zAmbiente>
|
||||
post: tipoPostValidarTokem
|
||||
}): Promise<"valido" | "erro"> => {
|
||||
const url = `${urlAutenticacao(ambiente)}/api/validar_token`
|
||||
|
||||
try {
|
||||
const resposta = await node_fetch(url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(post),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.then((r) => r as tipoResposta<any>)
|
||||
.then((resposta) =>
|
||||
resposta.eCerto ? ("valido" as const) : ("erro" as const),
|
||||
)
|
||||
.catch(() => "erro" as const)
|
||||
|
||||
return resposta
|
||||
} catch (_e) {
|
||||
return "erro"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
import { codigoContaSite } from "./_codigoContaSite"
|
||||
import { urlAutenticacao } from "./_urlAutenticacao"
|
||||
import { type tipoUsuarioExterno, usuarios_quipo } from "./_usuarios_quipo"
|
||||
import { usuarios_quipo_vincular } from "./_usuarios_quipo_vincular"
|
||||
import { validarToken } from "./_validarToken"
|
||||
|
||||
export type { tipoUsuarioExterno }
|
||||
|
||||
/** todas as rotas de comunicação com autenticador partem dessa variável */
|
||||
export const pAutenticacao = {
|
||||
validarToken,
|
||||
urlAutenticacao,
|
||||
codigoContaSite,
|
||||
usuarios_quipo,
|
||||
usuarios_quipo_vincular,
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
export * from "./tokenQuipo"
|
||||
export * from "./autenticacao"
|
||||
export * from "./pilao-de-dados"
|
||||
export * from "./residuos"
|
||||
export * from "./NPS"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue