This commit is contained in:
Luiz H. R. Silva 2024-06-04 16:16:53 -03:00
parent aa2892c9fb
commit fed8453f61
13 changed files with 157 additions and 211 deletions

View file

@ -1,24 +0,0 @@
import { type tipoResposta } from "~respostas";
type tipoPostValidarTokem = {
token: string;
};
type tipoPostCodigoContaSite = {
site: string;
};
/** todas as rotas de comunicação com autenticador partem dessa variável */
export declare const pAutenticacao: {
validarToken: ({ ambiente, post, buscar, }: {
ambiente: "desenvolvimento" | "producao";
post: tipoPostValidarTokem;
/** função que conecta com a API */
buscar: (url: string, post: tipoPostValidarTokem) => Promise<tipoResposta<any>>;
}) => Promise<"valido" | "erro">;
urlAutenticacao: (ambiente: "desenvolvimento" | "producao") => string;
codigoContaSite: ({ ambiente, post, buscar, }: {
ambiente: "desenvolvimento" | "producao";
post: tipoPostCodigoContaSite;
/** função que conecta com a API */
buscar: (url: string, post: tipoPostCodigoContaSite) => Promise<tipoResposta<string>>;
}) => Promise<tipoResposta<string>>;
};
export {};

View file

@ -1,30 +1,39 @@
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 "~respostas"; import { respostaComuns } from "~respostas";
const urlAutenticacao = (ambiente) => `${ambiente == "producao" const urlAutenticacao = (ambiente) => `${ambiente == "producao"
? "https://carro-de-boi.idz.one" ? "https://carro-de-boi.idz.one"
: "http://localhost:5030"}/autenticacao`; : "http://localhost:5030"}/autenticacao`;
/** faz a validação do token */ /** faz a validação do token */
const validarToken = async ({ ambiente, post, buscar, }) => { const validarToken = ({ ambiente, post, buscar, }) => __awaiter(void 0, void 0, void 0, function* () {
const url = `${urlAutenticacao(ambiente)}/autenticacao/api/validar_token`; const url = `${urlAutenticacao(ambiente)}/autenticacao/api/validar_token`;
try { try {
const resposta = await buscar(url, post) const resposta = yield buscar(url, post)
.then((resposta) => resposta.eCerto ? "valido" : "erro") .then((resposta) => resposta.eCerto ? "valido" : "erro")
.catch((e) => "erro"); .catch(() => "erro");
return resposta; return resposta;
} }
catch (e) { catch (e) {
return "erro"; return "erro";
} }
}; });
const codigoContaSite = async ({ ambiente, post, buscar, }) => { const codigoContaSite = ({ ambiente, post, buscar, }) => __awaiter(void 0, void 0, void 0, function* () {
const url = `${urlAutenticacao(ambiente)}/autenticacao/api/codigo_prefeitura_site`; const url = `${urlAutenticacao(ambiente)}/autenticacao/api/codigo_prefeitura_site`;
try { try {
const resp = await buscar(url, post).catch((e) => respostaComuns.erro(`erro ao buscar código do site: ${e}`)); const resp = yield buscar(url, post).catch((e) => respostaComuns.erro(`erro ao buscar código do site: ${e}`));
return resp; return resp;
} }
catch (e) { catch (e) {
return respostaComuns.erro(`erro ao buscar código do site: ${e}`); return respostaComuns.erro(`erro ao buscar código do site: ${e}`);
} }
}; });
/** todas as rotas de comunicação com autenticador partem dessa variável */ /** todas as rotas de comunicação com autenticador partem dessa variável */
export const pAutenticacao = { export const pAutenticacao = {
validarToken, validarToken,

View file

@ -1,2 +0,0 @@
export * from "./tokenQuipo";
export * from "./autenticacao";

View file

@ -1,34 +0,0 @@
import { z } from "zod";
export declare const ztokenQuipo: z.ZodObject<{
provedor: z.ZodString;
codigo_usuario: z.ZodString;
nome_usuario: z.ZodString;
codigo_conta: z.ZodString;
nome_conta: z.ZodString;
codigo_autenticacao: z.ZodString;
codigo_acesso_produto: z.ZodString;
tipo_de_acesso: z.ZodEnum<["publico", "governo", "sociedade"]>;
exp: z.ZodOptional<z.ZodNumber>;
}, "strip", z.ZodTypeAny, {
provedor: string;
codigo_usuario: string;
nome_usuario: string;
codigo_conta: string;
nome_conta: string;
codigo_autenticacao: string;
codigo_acesso_produto: string;
tipo_de_acesso: "publico" | "governo" | "sociedade";
exp?: number | undefined;
}, {
provedor: string;
codigo_usuario: string;
nome_usuario: string;
codigo_conta: string;
nome_conta: string;
codigo_autenticacao: string;
codigo_acesso_produto: string;
tipo_de_acesso: "publico" | "governo" | "sociedade";
exp?: number | undefined;
}>;
export type tipos_de_acesso_quipo = z.infer<typeof ztokenQuipo>["tipo_de_acesso"];
export type tipoTokenQuipo = z.infer<typeof ztokenQuipo>;

View file

@ -1,36 +1,104 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
exports.pAutenticacao = void 0; function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
const _respostas_1 = require("~respostas"); return new (P || (P = Promise))(function (resolve, reject) {
const urlAutenticacao = (ambiente) => `${ambiente == "producao" function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
? "https://carro-de-boi.idz.one" function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
: "http://localhost:5030"}/autenticacao`; function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
/** faz a validação do token */ step((generator = generator.apply(thisArg, _arguments || [])).next());
const validarToken = async ({ ambiente, post, buscar, }) => { });
const url = `${urlAutenticacao(ambiente)}/autenticacao/api/validar_token`; };
try { var __generator = (this && this.__generator) || function (thisArg, body) {
const resposta = await buscar(url, post) var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
.then((resposta) => resposta.eCerto ? "valido" : "erro") return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
.catch((e) => "erro"); function verb(n) { return function (v) { return step([n, v]); }; }
return resposta; function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
} }
catch (e) { op = body.call(thisArg, _);
return "erro"; } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
} }
}; };
const codigoContaSite = async ({ ambiente, post, buscar, }) => { Object.defineProperty(exports, "__esModule", { value: true });
const url = `${urlAutenticacao(ambiente)}/autenticacao/api/codigo_prefeitura_site`; exports.pAutenticacao = void 0;
try { var _respostas_1 = require("~respostas");
const resp = await buscar(url, post).catch((e) => _respostas_1.respostaComuns.erro(`erro ao buscar código do site: ${e}`)); var urlAutenticacao = function (ambiente) {
return resp; return "".concat(ambiente == "producao"
? "https://carro-de-boi.idz.one"
: "http://localhost:5030", "/autenticacao");
};
/** faz a validação do token */
var validarToken = function (_a) {
var ambiente = _a.ambiente, post = _a.post, buscar = _a.buscar;
return __awaiter(void 0, void 0, void 0, function () {
var url, resposta, e_1;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
url = "".concat(urlAutenticacao(ambiente), "/autenticacao/api/validar_token");
_b.label = 1;
case 1:
_b.trys.push([1, 3, , 4]);
return [4 /*yield*/, buscar(url, post)
.then(function (resposta) {
return resposta.eCerto ? "valido" : "erro";
})
.catch(function () { return "erro"; })];
case 2:
resposta = _b.sent();
return [2 /*return*/, resposta];
case 3:
e_1 = _b.sent();
return [2 /*return*/, "erro"];
case 4: return [2 /*return*/];
} }
catch (e) { });
return _respostas_1.respostaComuns.erro(`erro ao buscar código do site: ${e}`); });
};
var codigoContaSite = function (_a) {
var ambiente = _a.ambiente, post = _a.post, buscar = _a.buscar;
return __awaiter(void 0, void 0, void 0, function () {
var url, resp, e_2;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
url = "".concat(urlAutenticacao(ambiente), "/autenticacao/api/codigo_prefeitura_site");
_b.label = 1;
case 1:
_b.trys.push([1, 3, , 4]);
return [4 /*yield*/, buscar(url, post).catch(function (e) {
return _respostas_1.respostaComuns.erro("erro ao buscar c\u00F3digo do site: ".concat(e));
})];
case 2:
resp = _b.sent();
return [2 /*return*/, resp];
case 3:
e_2 = _b.sent();
return [2 /*return*/, _respostas_1.respostaComuns.erro("erro ao buscar c\u00F3digo do site: ".concat(e_2))];
case 4: return [2 /*return*/];
} }
});
});
}; };
/** todas as rotas de comunicação com autenticador partem dessa variável */ /** todas as rotas de comunicação com autenticador partem dessa variável */
exports.pAutenticacao = { exports.pAutenticacao = {
validarToken, validarToken: validarToken,
urlAutenticacao, urlAutenticacao: urlAutenticacao,
codigoContaSite, codigoContaSite: codigoContaSite,
}; };

View file

@ -1,7 +1,7 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.ztokenQuipo = void 0; exports.ztokenQuipo = void 0;
const zod_1 = require("zod"); var zod_1 = require("zod");
exports.ztokenQuipo = zod_1.z.object({ exports.ztokenQuipo = zod_1.z.object({
provedor: zod_1.z.string(), provedor: zod_1.z.string(),
codigo_usuario: zod_1.z.string(), codigo_usuario: zod_1.z.string(),

View file

@ -1,17 +1,18 @@
{ {
"name": "~drives", "name": "~drives",
"version": "0.23.0", "version": "0.28.0",
"description": "", "description": "",
"main": "src/index.ts", "main": "src/index.ts",
"exports": { "exports": {
".": { ".": {
"import": "./dist-import/index.js", "import": "./dist-import/index.js",
"require": "./dist-require/index.js" "require": "./dist-require/index.js",
"default": "./dist-require/index.js"
} }
}, },
"scripts": { "scripts": {
"build-back": "rm -fr dist-require && tsc --project ./tsconfig-back.json", "build-back": "rm -fr dist-require && tsc -p ./tsconfig-require.json",
"build-front": "rm -fr dist-import && tsc --project ./tsconfig-front.json", "build-front": "rm -fr dist-import && tsc -p ./tsconfig-import.json",
"build": "pnpm run biome && npm --no-git-tag-version version minor && pnpm run build-back && pnpm run build-front", "build": "pnpm run biome && npm --no-git-tag-version version minor && pnpm run build-back && pnpm run build-front",
"biome": "npx @biomejs/biome check --apply ./src", "biome": "npx @biomejs/biome check --apply ./src",
"nodev": "check-node-version --node '>= 20'" "nodev": "check-node-version --node '>= 20'"

View file

@ -30,7 +30,7 @@ const validarToken = async ({
.then((resposta) => .then((resposta) =>
resposta.eCerto ? ("valido" as const) : ("erro" as const), resposta.eCerto ? ("valido" as const) : ("erro" as const),
) )
.catch((e) => "erro" as const) .catch(() => "erro" as const)
return resposta return resposta
} catch (e) { } catch (e) {

View file

@ -1,7 +0,0 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"outDir": "./dist-require",
"module": "commonjs"
}
}

View file

@ -1,7 +0,0 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"outDir": "./dist-import",
"module": "ES6"
}
}

11
tsconfig-import.json Normal file
View file

@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./dist-import",
"target": "ES2015",
"module": "ES2015",
"declaration": false,
"declarationMap": false,
"sourceMap": false
}
}

11
tsconfig-require.json Normal file
View file

@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"target": "ES5",
"outDir": "./dist-require",
"declaration": true,
"declarationMap": false,
"sourceMap": false
},
}

View file

@ -1,100 +1,20 @@
{ {
"compilerOptions": { "compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */ "lib": ["es5", "es6", "es7", "esnext", "dom"],
"target": "es2018",
/* Projects */ "removeComments": false,
// "incremental": true, /* Enable incremental compilation */ "esModuleInterop": true,
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ "moduleResolution": "node",
// "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */ "resolveJsonModule": true,
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */ "strict": true,
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ "skipLibCheck": true,
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ "strictPropertyInitialization": false,
"noUnusedLocals": true,
/* Language and Environment */ "noUnusedParameters": true,
"target": "ES2020" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, "noImplicitReturns": true,
"lib": ["dom.iterable"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ "noFallthroughCasesInSwitch": true,
// "jsx": "preserve", /* Specify what JSX code is generated. */ "downlevelIteration": true,
"experimentalDecorators": true /* Enable experimental support for TC39 stage 2 draft decorators. */, "isolatedModules": true
"emitDecoratorMetadata": true /* Emit design-type metadata for decorated declarations in source files. */,
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */
// "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
/* Modules */
"rootDir": "./src" /* Specify the root folder within your source files. */,
"moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "resolveJsonModule": true, /* Enable importing .json files */
// "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
/* JavaScript Support */
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */
/* Emit */
"declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
// "newLine": "crlf", /* Set the newline character for emitting files. */
// "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
// "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
/* Type Checking */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
// "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
// "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
// "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */
// "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
// "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}, },
"include": ["src/**/*"] "include": ["src/**/*"]
} }