@codice-progressio/easy-permissions
Advanced tools
+18
| # Changelog | ||
| All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. | ||
| ### [0.2.3](https://github.com/RafaelAngelRamirez/easy-permissions/compare/v0.2.2...v0.2.3) (2024-07-30) | ||
| ### [0.2.2](https://github.com/RafaelAngelRamirez/easy-permissions/compare/v0.2.1...v0.2.2) (2024-07-30) | ||
| ### Features | ||
| * Optimization ([b8544d9](https://github.com/RafaelAngelRamirez/easy-permissions/commit/b8544d920982280d6867ae3319872b03d5fa5c96)) | ||
| * Timer for wait creation of files permission ([0c6afb4](https://github.com/RafaelAngelRamirez/easy-permissions/commit/0c6afb4dca5e520aa773854e5b1d5b6cc108757b)) | ||
| ### Bug Fixes | ||
| * Error on permissions fixed ([c1ad338](https://github.com/RafaelAngelRamirez/easy-permissions/commit/c1ad338a2bdf48bd15c7333288d5db6f514c23ca)) |
+58
-21
| const fs = require("fs") | ||
| const guard = require("express-jwt-permissions")() | ||
| /** | ||
| * Object that stores the descriptions of permissions. | ||
| * @type {Object} | ||
| */ | ||
| let permissions_description = {} | ||
| let new_permission_added = false | ||
| /** | ||
| * Object representing permissions. | ||
| * @type {Object} | ||
| */ | ||
| const permissions_permission = {} | ||
| /** | ||
| * Saves timer for saving permissions. | ||
| * @type {undefined} | ||
| */ | ||
| let timer = undefined | ||
| /** | ||
| * Un objeto con clave fichero1, fichero2 | ||
@@ -109,12 +127,7 @@ */ | ||
| try { | ||
| // Modificamos este mismo archivo para agregar los permisos | ||
| // directamente. | ||
| // Leemos este mesmo archivo. | ||
| const data = fs.readFileSync(rutaCompletaFichero.fichero1, "utf-8") | ||
| const data2 = fs.readFileSync(rutaCompletaFichero.fichero2, "utf-8") | ||
| const data = require(rutaCompletaFichero.fichero1) | ||
| // En modo produccion, o en caso de que el permiso exista, regresa el permiso | ||
| // la funcion segun este definido. | ||
| if (configuraciones.modoProduccion || data.includes(permiso)) | ||
| if (configuraciones.modoProduccion ) | ||
| return opciones.esMiddleware ? funcion : permiso | ||
@@ -127,17 +140,41 @@ | ||
| // Si no existe el permiso lo agregamos. | ||
| let texto = data.toString().split("\n") | ||
| let texto2 = data2.toString().split("\n") | ||
| // Estructuramos | ||
| let nuevaLinea = ` "${permiso}":"${descripcion}",` | ||
| let nuevaLinea2 = ` "${permiso}":"${permiso}",` | ||
| permissions_description = {...data} | ||
| permissions_description[permiso] = descripcion | ||
| permissions_permission[permiso] = permiso | ||
| // Separamos el archivo en lineas. | ||
| // Agregamos una nueva linea siempre en la segunda posicion | ||
| texto.splice(1, 0, nuevaLinea) | ||
| texto2.splice(1, 0, nuevaLinea2) | ||
| // Escribimos el archivo | ||
| function timer_execution() { | ||
| fs.writeFileSync(rutaCompletaFichero.fichero1, texto.join("\n")) | ||
| fs.writeFileSync(rutaCompletaFichero.fichero2, texto2.join("\n")) | ||
| console.log(msj("[ easyPermissions ], ", "Saving permissions...")) | ||
| const header = "const permisos = {\n" | ||
| const footer = "\n}\n\nmodule.exports = permisos" | ||
| const permissions_description_sort = {} | ||
| const permissions_permission_sort = {} | ||
| Object.keys(permissions_description).sort((a, b) => a > b ? 1 : -1).forEach(x => { | ||
| permissions_description_sort[x] = permissions_description[x] | ||
| permissions_permission_sort[x] = permissions_permission[x] | ||
| }) | ||
| const permissions_description_string = JSON.stringify(permissions_description_sort, null, 2) | ||
| .replace(/{/g, header) | ||
| .replace(/}/g, footer); | ||
| const permissions_permission_string = JSON.stringify(permissions_permission_sort, null, 2) | ||
| .replace(/{/g, header) | ||
| .replace(/}/g, footer); | ||
| fs.writeFileSync(rutaCompletaFichero.fichero1, permissions_description_string) | ||
| fs.writeFileSync(rutaCompletaFichero.fichero2, permissions_permission_string) | ||
| clearTimeout(timer) | ||
| } | ||
| if (!timer) timer = setInterval(() => { | ||
| clearTimeout(timer) | ||
| timer_execution() | ||
| return | ||
| } | ||
| , 5000 | ||
| ) | ||
| } catch (error) { | ||
@@ -144,0 +181,0 @@ throw new Error(msj("[ easyPermissions ] ", error)) |
+3
-2
| { | ||
| "name": "@codice-progressio/easy-permissions", | ||
| "version": "0.2.1", | ||
| "version": "0.2.3", | ||
| "description": "Permisos fáciles de crear y administrar.", | ||
@@ -8,3 +8,4 @@ "main": "index.js", | ||
| "test": "nyc --reporter=html --reporter=text mocha", | ||
| "coverage": "nyc report --reporter=text-lcov | coveralls" | ||
| "coverage": "nyc report --reporter=text-lcov | coveralls", | ||
| "release": "npx standard-version && git push --follow-tags && npm publish" | ||
| }, | ||
@@ -11,0 +12,0 @@ "author": "Rafael Ramirez", |
| const permisos = { | ||
| } | ||
| module.exports = permisos |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
13120
16.23%191
16.46%2
100%