Gathering detailed insights and metrics for maxi-validate-permissions-test
Gathering detailed insights and metrics for maxi-validate-permissions-test
Gathering detailed insights and metrics for maxi-validate-permissions-test
Gathering detailed insights and metrics for maxi-validate-permissions-test
npm install maxi-validate-permissions-test
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
4
6
This library provides utilities to manage and validate user permissions using JSON Web Tokens (JWT). The library includes functionalities to decode JWT, check token validity, and fetch user permissions.
To use this library, you need to have maxi-validate-permissions-test
installed. You can install this dependency:
Using npm:
1$ npm install maxi-validate-permissions-test
Using bower:
1$ bower install maxi-validate-permissions-test
Using yarn:
1$ yarn add maxi-validate-permissions-test
Using pnpm:
1$ pnpm add maxi-validate-permissions-test
This code is a TypeScript module that includes functions for handling user permissions and validating them based on a token received from an API. Here is a step-by-step explanation of the code:
The code imports necessary modules such as axios for making HTTP requests, jwt-decode for decoding JWT tokens, and luxon for date and time manipulation.
It defines various interfaces and enums for handling token decoding, response data, user roles, systems, modules, permissions, and permission information.
It sets a URL for an API endpoint that checks user permissions.
The callApi function is defined to make a GET request to the API endpoint with a provided token. It returns a response containing the status, message, and user role data.
The decodeToken function decodes a JWT token and returns the decoded token along with a status and message.
The isTokenActive function checks if a token is valid and active by decoding the token and checking its expiration time against the current time.
The getPermissionsUnique function retrieves unique permissions for a specific system and permission name from a user role.
The getPermissionsInGroup function retrieves permissions for a group of systems and permission names from a user role.
The validatePermission function validates a single permission based on the provided token, permission system, and permission name by calling isTokenActive , callApi , and getPermissionsUnique functions.
The validateGroupPermissions function validates a group of permissions for a system based on the provided token, system name, and array of permissions by calling isTokenActive , callApi , and getPermissionsInGroup functions.
In summary, this code module provides functions to handle user permissions, decode tokens, check token validity, and validate permissions based on the user's role and provided token.
1import { validatePermission } from 'maxi-validate-permissions-test'; 2//const { validatePermission } = require('maxi-validate-permissions-test'); // legacy way 3 4const token = "*****"; 5const permissionSystem = "test"; 6const permissionName = "TEST_USER_MANGEMENT_PERM_1000"; 7 8validatePermission( 9 token, 10 permissionSystem, 11 permissionName, 12 ).then((data) => console.log(data));
1import { validateGroupPermissions } from 'maxi-validate-permissions-test'; 2//const { validateGroupPermissions } = require('maxi-validate-permissions-test'); // legacy way 3 4const token = "*****"; 5const systemName = "test"; 6 7const permissions = [ 8 "TEST_USER_MANAGMENT_PERM_2", 9 "TEST_USER_MANAGMENT_PERM_1", 10 "TEST_USER_MANAGMENT_PERM_10", 11 "TEST_USER_MANAGMENT_PERM_3", 12]; 13 14validateGroupPermissions(token, systemName, permissions).then((data) => 15 console.log(data) 16);
When request failed.
1{ status: 'error', message: 'Request failed.' }
When token is invalid.
1{ status: 'error', message: 'The token is invalid.' }
When token is expired.
1{ status: 'error', message: 'The token has expired.' }
When permission system doesn´t exist.
1{ status: 'success', message: 'Request successful.', permission: null }
When permission doesn´t exist.
1{ 2 status: 'success', 3 message: 'Request successful.', 4 permission: { TEST_USER_MANGEMENT_PERM_1000: null } 5}
When the user has access to the permission.
1{ 2 status: 'success', 3 message: 'Request successful.', 4 permission: { TEST_USER_MANAGMENT_PERM_2: { view: true, edit: false } } 5}
List of permissions that the user has access to use.
1{ 2 status: 'success', 3 message: 'Request successful.', 4 permission: [ 5 { TEST_USER_MANAGMENT_PERM_2: {"view":true,"edit":false} }, 6 { TEST_USER_MANAGMENT_PERM_1: null }, 7 { TEST_USER_MANAGMENT_PERM_10: null }, 8 { TEST_USER_MANAGMENT_PERM_3: {"view":true,"edit":false} } 9 ] 10}
No vulnerabilities found.
No security vulnerabilities found.