This commit is contained in:
Luiz H. R. Silva 2024-06-19 17:47:48 -03:00
parent a6205f1ab6
commit e580643abc
40 changed files with 329 additions and 507 deletions

View file

@ -4,10 +4,8 @@ import type { zAmbiente } from "../ts/ambiente";
type tipoPostCodigoContaSite = {
site: string;
};
export declare const codigoContaSite: ({ ambiente, post, buscar, }: {
export declare const codigoContaSite: ({ ambiente, post, }: {
ambiente: z.infer<typeof zAmbiente>;
post: tipoPostCodigoContaSite;
/** função que conecta com a API */
buscar: (url: string, post: tipoPostCodigoContaSite) => Promise<tipoResposta<string>>;
}) => Promise<tipoResposta<string>>;
export {};

View file

@ -35,12 +35,16 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.codigoContaSite = void 0;
var p_respostas_1 = require("p-respostas");
var _urlAutenticacao_1 = require("./_urlAutenticacao");
var cross_fetch_1 = __importDefault(require("cross-fetch"));
var codigoContaSite = function (_a) {
var ambiente = _a.ambiente, post = _a.post, buscar = _a.buscar;
var ambiente = _a.ambiente, post = _a.post;
return __awaiter(void 0, void 0, void 0, function () {
var url, resp, e_1;
return __generator(this, function (_b) {
@ -50,9 +54,16 @@ var codigoContaSite = function (_a) {
_b.label = 1;
case 1:
_b.trys.push([1, 3, , 4]);
return [4 /*yield*/, buscar(url, post).catch(function (e) {
return p_respostas_1.respostaComuns.erro("erro ao buscar c\u00F3digo do site: ".concat(e));
})];
return [4 /*yield*/, (0, cross_fetch_1.default)(url, {
method: "POST",
body: JSON.stringify(post),
headers: { "Content-Type": "application/json" },
})
.then(function (r) { return r.json(); })
.catch(function (e) {
return p_respostas_1.respostaComuns.erro("Erro ao enviar registros", [e.message]);
})
.then(function (r) { return r; })];
case 2:
resp = _b.sent();
return [2 /*return*/, resp];

View file

@ -9,10 +9,7 @@ export type tipoUsuarioExterno = {
codigo_conta: string;
chave_produto: string;
};
export declare const usuarios_quipo_governo: ({ token_produto, ambiente, buscar, }: {
export declare const usuarios_quipo_governo: ({ token_produto, ambiente, }: {
ambiente: z.infer<typeof zAmbiente>;
token_produto: string;
buscar: (url: string, headers: {
[k: string]: string;
}) => Promise<tipoResposta<tipoUsuarioExterno[]>>;
}) => Promise<tipoResposta<tipoUsuarioExterno[]>>;

View file

@ -35,12 +35,16 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.usuarios_quipo_governo = void 0;
var cross_fetch_1 = __importDefault(require("cross-fetch"));
var p_respostas_1 = require("p-respostas");
var _urlAutenticacao_1 = require("./_urlAutenticacao");
var usuarios_quipo_governo = function (_a) {
var token_produto = _a.token_produto, ambiente = _a.ambiente, buscar = _a.buscar;
var token_produto = _a.token_produto, ambiente = _a.ambiente;
return __awaiter(void 0, void 0, void 0, function () {
var url, headers;
return __generator(this, function (_b) {
@ -50,9 +54,14 @@ var usuarios_quipo_governo = function (_a) {
headers = {
token: token_produto,
};
return [2 /*return*/, buscar(url, headers).catch(function (e) {
return p_respostas_1.respostaComuns.erro("erro ao buscar usu\u00E1rios quipo governo: ".concat(e));
})];
return [2 /*return*/, (0, cross_fetch_1.default)(url, {
headers: headers,
})
.then(function (r) { return r.json(); })
.catch(function (e) {
return p_respostas_1.respostaComuns.erro("Erro ao buscar usuários quipo governo", [e.message]);
})
.then(function (r) { return r; })];
});
});
};

View file

@ -1,14 +1,11 @@
import type { tipoResposta } from "p-respostas";
type tipoPostValidarTokem = {
token: string;
};
import type { z } from "zod";
import type { zAmbiente } from "../ts/ambiente";
/** faz a validação do token */
export declare const validarToken: ({ ambiente, post, buscar, }: {
export declare const validarToken: ({ ambiente, post, }: {
ambiente: z.infer<typeof zAmbiente>;
post: tipoPostValidarTokem;
/** função que conecta com a API */
buscar: (url: string, post: tipoPostValidarTokem) => Promise<tipoResposta<any>>;
}) => Promise<"valido" | "erro">;
export {};

View file

@ -35,12 +35,16 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.validarToken = void 0;
var _urlAutenticacao_1 = require("./_urlAutenticacao");
var cross_fetch_1 = __importDefault(require("cross-fetch"));
/** faz a validação do token */
var validarToken = function (_a) {
var ambiente = _a.ambiente, post = _a.post, buscar = _a.buscar;
var ambiente = _a.ambiente, post = _a.post;
return __awaiter(void 0, void 0, void 0, function () {
var url, resposta, e_1;
return __generator(this, function (_b) {
@ -50,7 +54,13 @@ var validarToken = function (_a) {
_b.label = 1;
case 1:
_b.trys.push([1, 3, , 4]);
return [4 /*yield*/, buscar(url, post)
return [4 /*yield*/, (0, cross_fetch_1.default)(url, {
method: "POST",
body: JSON.stringify(post),
headers: { "Content-Type": "application/json" },
})
.then(function (r) { return r.json(); })
.then(function (r) { return r; })
.then(function (resposta) {
return resposta.eCerto ? "valido" : "erro";
})

View file

@ -2,30 +2,21 @@ import { type tipoUsuarioExterno } from "./_usuarios_quipo_governo";
export type { tipoUsuarioExterno };
/** todas as rotas de comunicação com autenticador partem dessa variável */
export declare const pAutenticacao: {
validarToken: ({ ambiente, post, buscar, }: {
validarToken: ({ ambiente, post, }: {
ambiente: "desenvolvimento" | "producao";
post: {
token: string;
};
buscar: (url: string, post: {
token: string;
}) => Promise<import("p-respostas").tipoResposta<any>>;
}) => Promise<"valido" | "erro">;
urlAutenticacao: (ambiente: "desenvolvimento" | "producao") => string;
codigoContaSite: ({ ambiente, post, buscar, }: {
codigoContaSite: ({ ambiente, post, }: {
ambiente: "desenvolvimento" | "producao";
post: {
site: string;
};
buscar: (url: string, post: {
site: string;
}) => Promise<import("p-respostas").tipoResposta<string>>;
}) => Promise<import("p-respostas").tipoResposta<string>>;
usuarios_quipo_governo: ({ token_produto, ambiente, buscar, }: {
usuarios_quipo_governo: ({ token_produto, ambiente, }: {
ambiente: "desenvolvimento" | "producao";
token_produto: string;
buscar: (url: string, headers: {
[k: string]: string;
}) => Promise<import("p-respostas").tipoResposta<tipoUsuarioExterno[]>>;
}) => Promise<import("p-respostas").tipoResposta<tipoUsuarioExterno[]>>;
};