This commit is contained in:
Luiz H. R. Silva 2024-07-01 12:55:34 -03:00
parent f2562a37d1
commit 7032eb1329
39 changed files with 442 additions and 790 deletions

View file

@ -1,16 +1,7 @@
// npm run build produz um arquivo abrirNps.js que é copiado para a pasta public
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { respostaComuns } from "p-respostas";
// exibe o iframe em tela cheia
export const abrirNps = (emDesenvolvimento) => (parametros) => __awaiter(void 0, void 0, void 0, function* () {
export const abrirNps = (emDesenvolvimento) => async (parametros) => {
const base_site = emDesenvolvimento
? "http://localhost:5040/nps"
: "https://carro-de-boi.idz.one/nps";
@ -23,7 +14,7 @@ export const abrirNps = (emDesenvolvimento) => (parametros) => __awaiter(void 0,
for (const [chave, valor] of Object.entries(parametros)) {
url_proxima_avaliacao.searchParams.append(chave, valor);
}
const response = yield fetch(url_proxima_avaliacao.href)
const response = await fetch(url_proxima_avaliacao.href)
.then((resposta) => resposta.json())
.catch((error) => respostaComuns.erro(error.message));
const proxima_avaliacao = response.valor;
@ -56,4 +47,4 @@ export const abrirNps = (emDesenvolvimento) => (parametros) => __awaiter(void 0,
document.body.removeChild(iframe);
}
});
});
};

View file

@ -1,19 +1,10 @@
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { respostaComuns } from "p-respostas";
import { urlAutenticacao } from "./_urlAutenticacao";
import node_fetch from "cross-fetch";
export const codigoContaSite = (_a) => __awaiter(void 0, [_a], void 0, function* ({ ambiente, post, }) {
export const codigoContaSite = async ({ ambiente, post, }) => {
const url = `${urlAutenticacao(ambiente)}/api/codigo_prefeitura_site`;
try {
const resp = yield node_fetch(url, {
const resp = await node_fetch(url, {
method: "POST",
body: JSON.stringify(post),
headers: { "Content-Type": "application/json" },
@ -26,4 +17,4 @@ export const codigoContaSite = (_a) => __awaiter(void 0, [_a], void 0, function*
catch (e) {
return respostaComuns.erro(`erro ao buscar código do site: ${e}`);
}
});
};

View file

@ -1,16 +1,7 @@
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import node_fetch from "cross-fetch";
import { respostaComuns } from "p-respostas";
import { urlAutenticacao } from "./_urlAutenticacao";
export const usuarios_quipo_governo = (_a) => __awaiter(void 0, [_a], void 0, function* ({ token_produto, ambiente, }) {
export const usuarios_quipo_governo = async ({ token_produto, ambiente, }) => {
const url = `${urlAutenticacao(ambiente)}/api/usuarios_quipo_governo`;
if (!token_produto)
return respostaComuns.erro("token_produto não informado");
@ -23,4 +14,4 @@ export const usuarios_quipo_governo = (_a) => __awaiter(void 0, [_a], void 0, fu
.then((r) => r.json())
.catch((e) => respostaComuns.erro(`Erro ao buscar usuários quipo governo ${e.message}`))
.then((r) => r);
});
};

View file

@ -1,16 +1,7 @@
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import node_fetch from "cross-fetch";
import { respostaComuns } from "p-respostas";
import { urlAutenticacao } from "./_urlAutenticacao";
export const usuarios_quipo_vincular = (_a) => __awaiter(void 0, [_a], void 0, function* ({ token_produto, ambiente, conta, vinculo, codigo_usuario, email, }) {
export const usuarios_quipo_vincular = async ({ token_produto, ambiente, conta, vinculo, codigo_usuario, email, }) => {
const url = `${urlAutenticacao(ambiente)}/api/vinculos__criar`;
if (!token_produto)
return respostaComuns.erro("token_produto não informado");
@ -22,11 +13,11 @@ export const usuarios_quipo_vincular = (_a) => __awaiter(void 0, [_a], void 0, f
vinculos: { codigo_conta: conta, codigo_usuario, vinculo },
email: email,
};
return yield node_fetch(url, {
return await node_fetch(url, {
headers,
body: JSON.stringify(parametros),
method: "POST",
})
.then((r) => __awaiter(void 0, void 0, void 0, function* () { return yield r.json(); }))
.then(async (r) => await r.json())
.catch((e) => respostaComuns.erro(`Erro ao criar vinculo de usuario ${e.message}`));
});
};

View file

@ -1,19 +1,10 @@
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { urlAutenticacao } from "./_urlAutenticacao";
import node_fetch from "cross-fetch";
/** faz a validação do token */
export const validarToken = (_a) => __awaiter(void 0, [_a], void 0, function* ({ ambiente, post, }) {
export const validarToken = async ({ ambiente, post, }) => {
const url = `${urlAutenticacao(ambiente)}/api/validar_token`;
try {
const resposta = yield node_fetch(url, {
const resposta = await node_fetch(url, {
method: "POST",
body: JSON.stringify(post),
headers: { "Content-Type": "application/json" },
@ -27,4 +18,4 @@ export const validarToken = (_a) => __awaiter(void 0, [_a], void 0, function* ({
catch (e) {
return "erro";
}
});
};

View file

@ -1,12 +1,3 @@
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import node_fetch from "cross-fetch";
import { respostaComuns } from "p-respostas";
import { z } from "zod";
@ -16,12 +7,12 @@ export const zp_deletar_registros = z.object({
tabela: z.string(),
codigos: z.array(z.string()),
});
export const deletar_registros = ({ conta, produto, emDesenvolvimento }) => (_a) => __awaiter(void 0, [_a], void 0, function* ({ codigos, tabela, }) {
export const deletar_registros = ({ conta, produto, emDesenvolvimento }) => async ({ codigos, tabela, }) => {
const url = new URL(`${urlPilao(emDesenvolvimento).api}/${Object.keys({ deletar_registros })[0]}/${produto}/${conta}`);
const tamanhoBlocos = 1000;
while (codigos.length > 0) {
const bloco = codigos.splice(0, tamanhoBlocos);
const resp = yield node_fetch(url.toString(), {
const resp = await node_fetch(url.toString(), {
method: "POST",
body: JSON.stringify({ tabela, codigos: bloco }),
headers: { "Content-Type": "application/json" },
@ -34,4 +25,4 @@ export const deletar_registros = ({ conta, produto, emDesenvolvimento }) => (_a)
}
}
return respostaComuns.valor(true);
});
};

View file

@ -1,12 +1,3 @@
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import node_fetch from "cross-fetch";
import { respostaComuns } from "p-respostas";
import { z } from "zod";
@ -26,14 +17,14 @@ export const zp_enviar_registros = z.object({
tipo: z_tipo_coluna_base_dados.optional().nullable(),
}))),
});
export const enviar_registros = ({ conta, produto, emDesenvolvimento }) => (_a) => __awaiter(void 0, [_a], void 0, function* ({ registros, tabela, }) {
export const enviar_registros = ({ conta, produto, emDesenvolvimento }) => async ({ registros, tabela, }) => {
const url = new URL(`${urlPilao(emDesenvolvimento).api}/${Object.keys({ enviar_registros })[0]}/${produto}/${conta}`);
const tamanhoBlocos = 1000;
while (registros.length > 0) {
const bloco = registros
.splice(0, tamanhoBlocos)
.map((r) => Object.fromEntries(Object.entries(r).map(([k, v]) => [k, v === undefined ? null : v])));
const resp = yield node_fetch(url.toString(), {
const resp = await node_fetch(url.toString(), {
method: "POST",
body: JSON.stringify({ tabela, registros: bloco }),
headers: { "Content-Type": "application/json" },
@ -46,4 +37,4 @@ export const enviar_registros = ({ conta, produto, emDesenvolvimento }) => (_a)
}
}
return respostaComuns.valor(true);
});
};

View file

@ -6,16 +6,39 @@ export declare const zp_serie_registrar: z.ZodObject<{
colanuEixoX: z.ZodString;
colunaAgrupamento: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
agregacao: z.ZodEnum<["contagem", "somatoria"]>;
filtro: z.ZodOptional<z.ZodArray<z.ZodObject<{
coluna: z.ZodString;
valor: z.ZodString;
operador: z.ZodEnum<["=", "!=", ">", "<", ">=", "<=", "∩"]>;
}, "strip", z.ZodTypeAny, {
valor: string;
coluna: string;
operador: "=" | "!=" | ">" | "<" | ">=" | "<=" | "∩";
}, {
valor: string;
coluna: string;
operador: "=" | "!=" | ">" | "<" | ">=" | "<=" | "∩";
}>, "many">>;
}, "strip", z.ZodTypeAny, {
tabela: string;
colanuEixoX: string;
agregacao: "contagem" | "somatoria";
colunaAgrupamento?: string[] | undefined;
filtro?: {
valor: string;
coluna: string;
operador: "=" | "!=" | ">" | "<" | ">=" | "<=" | "∩";
}[] | undefined;
}, {
tabela: string;
colanuEixoX: string;
agregacao: "contagem" | "somatoria";
colunaAgrupamento?: string[] | undefined;
filtro?: {
valor: string;
coluna: string;
operador: "=" | "!=" | ">" | "<" | ">=" | "<=" | "∩";
}[] | undefined;
}>;
export declare const serie_consultar: (cliente: z.infer<typeof zp_produto_conta>) => (parametros: z.infer<typeof zp_serie_registrar>) => {
dados: () => Promise<tipoResposta<{

View file

@ -1,26 +1,23 @@
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import node_fetch from "cross-fetch";
import { respostaComuns } from "p-respostas";
import { z } from "zod";
import { tiposSeriesAgregacoes, urlPilao, } from "./variaveis";
import { operadores_pilao, tiposSeriesAgregacoes, urlPilao, } from "./variaveis";
const filtro = z.object({
coluna: z.string(),
valor: z.string(),
operador: operadores_pilao,
});
export const zp_serie_registrar = z.object({
tabela: z.string(),
colanuEixoX: z.string(),
colunaAgrupamento: z.string().array().optional(),
agregacao: tiposSeriesAgregacoes,
filtro: filtro.array().optional(),
});
export const serie_consultar = (cliente) => (parametros) => {
const dados = () => __awaiter(void 0, void 0, void 0, function* () {
const dados = async () => {
const url = new URL(`${urlPilao(cliente.emDesenvolvimento).api}/${tiposSeriesAgregacoes.enum.contagem}/${cliente.produto}/${cliente.conta}`);
const resp = yield node_fetch(url.toString(), {
const resp = await node_fetch(url.toString(), {
method: "POST",
body: JSON.stringify(parametros),
headers: { "Content-Type": "application/json" },
@ -29,7 +26,7 @@ export const serie_consultar = (cliente) => (parametros) => {
.catch((e) => respostaComuns.erro("Erro ao enviar registros", [e.message]))
.then((r) => r);
return resp;
});
};
const url = () => {
const vUrl = new URL(`${urlPilao(cliente.emDesenvolvimento).site}/${tiposSeriesAgregacoes.enum.contagem}/${cliente.produto}/${cliente.conta}`);
const serie = encodeURIComponent(JSON.stringify(parametros, null, 2));

View file

@ -61,16 +61,39 @@ export declare const pPilao: {
colanuEixoX: import("zod").ZodString;
colunaAgrupamento: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString, "many">>;
agregacao: import("zod").ZodEnum<["contagem", "somatoria"]>;
filtro: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
coluna: import("zod").ZodString;
valor: import("zod").ZodString;
operador: import("zod").ZodEnum<["=", "!=", ">", "<", ">=", "<=", "∩"]>;
}, "strip", import("zod").ZodTypeAny, {
valor: string;
coluna: string;
operador: "=" | "!=" | ">" | "<" | ">=" | "<=" | "∩";
}, {
valor: string;
coluna: string;
operador: "=" | "!=" | ">" | "<" | ">=" | "<=" | "∩";
}>, "many">>;
}, "strip", import("zod").ZodTypeAny, {
tabela: string;
colanuEixoX: string;
agregacao: "contagem" | "somatoria";
colunaAgrupamento?: string[] | undefined;
filtro?: {
valor: string;
coluna: string;
operador: "=" | "!=" | ">" | "<" | ">=" | "<=" | "∩";
}[] | undefined;
}, {
tabela: string;
colanuEixoX: string;
agregacao: "contagem" | "somatoria";
colunaAgrupamento?: string[] | undefined;
filtro?: {
valor: string;
coluna: string;
operador: "=" | "!=" | ">" | "<" | ">=" | "<=" | "∩";
}[] | undefined;
}>;
serie_consultar: (cliente: import("zod").TypeOf<typeof zp_produto_conta>) => (parametros: import("zod").TypeOf<typeof zp_serie_registrar>) => {
dados: () => Promise<import("p-respostas").tipoResposta<{
@ -105,4 +128,14 @@ export declare const pPilao: {
tabela: string;
codigos: string[];
}>;
operadores_pilao: import("zod").ZodEnum<["=", "!=", ">", "<", ">=", "<=", "∩"]>;
operadores_permitidos_por_tipo: {
texto: ("=" | "!=" | ">" | "<" | ">=" | "<=" | "∩")[];
numero: ("=" | "!=" | ">" | "<" | ">=" | "<=" | "∩")[];
confirmacao: ("=" | "!=" | ">" | "<" | ">=" | "<=" | "∩")[];
lista_texto: ("=" | "!=" | ">" | "<" | ">=" | "<=" | "∩")[];
lista_numero: ("=" | "!=" | ">" | "<" | ">=" | "<=" | "∩")[];
data: ("=" | "!=" | ">" | "<" | ">=" | "<=" | "∩")[];
mes: ("=" | "!=" | ">" | "<" | ">=" | "<=" | "∩")[];
};
};

View file

@ -1,7 +1,7 @@
import { deletar_registros, zp_deletar_registros } from "./_deletar_registros";
export { PREFIXO_PILAO, urlPilao } from "./variaveis";
import { enviar_registros, zp_enviar_registros, zp_registrar_base_dados, } from "./_enviar_registros";
import { tiposSeriesAgregacoes, validarZ, zp_produto_conta } from "./variaveis";
import { operadores_permitidos_por_tipo, operadores_pilao, tiposSeriesAgregacoes, validarZ, zp_produto_conta, } from "./variaveis";
import { serie_consultar, zp_serie_registrar } from "./_serie_consultar";
export { tiposSeriesAgregacoes };
export const pPilao = {
@ -14,4 +14,6 @@ export const pPilao = {
validarZ,
deletar_registros,
zp_deletar_registros,
operadores_pilao,
operadores_permitidos_por_tipo,
};

View file

@ -16,6 +16,10 @@ export declare const zp_produto_conta: z.ZodObject<{
emDesenvolvimento?: boolean | undefined;
}>;
export declare const z_tipo_coluna_base_dados: z.ZodEnum<["texto", "numero", "confirmacao", "lista_texto", "lista_numero", "data", "mes"]>;
export declare const operadores_pilao: z.ZodEnum<["=", "!=", ">", "<", ">=", "<=", "∩"]>;
export declare const operadores_permitidos_por_tipo: {
[key in z.infer<typeof z_tipo_coluna_base_dados>]: z.infer<typeof operadores_pilao>[];
};
export declare const tiposSeriesAgregacoes: z.ZodEnum<["contagem", "somatoria"]>;
export declare const z_validar_colunna_base_dados: {
texto: z.ZodNullable<z.ZodString>;

View file

@ -23,6 +23,16 @@ export const z_tipo_coluna_base_dados = z.enum([
"data",
"mes",
]);
export const operadores_pilao = z.enum(["=", "!=", ">", "<", ">=", "<=", "∩"]);
export const operadores_permitidos_por_tipo = {
confirmacao: ["=", "!="],
data: ["=", "!=", ">", "<", ">=", "<="],
lista_numero: ["∩"],
lista_texto: ["∩"],
mes: ["=", "!=", ">", "<", ">=", "<="],
numero: ["=", "!=", ">", "<", ">=", "<="],
texto: ["=", "!="],
};
export const tiposSeriesAgregacoes = z.enum(["contagem", "somatoria"]);
export const z_validar_colunna_base_dados = {
texto: z.string().nullable(),