JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q45792F
  • License MIT

This package handles validation and verification of user roles and permissions

Package Exports

  • zeesix
  • zeesix/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (zeesix) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Node Package: zeesix

Overview

The zeesix package provides utilities for managing user data, handling token-based authentication, and managing role-based permissions. It integrates with Redis for data storage and offers functions for validating admin data, generating and verifying tokens, and managing role permissions.

Installation

To use this package in your Node.js project, follow these steps:

  1. Install the package via npm:
npm install zeesix

Function Documentation

Initialization

Before using the functions for token management or role/permission management, you must initialize the package with your signing key and Redis URL.

const { initializeConnection } = require('zeesix');

const signingKey = 'your-signing-key';
const redisUrl = 'redis-url';

await initializeConnection(redisUrl, signingKey);

Validation Functions

validateAdmin(adminData: AdminData)

Validates the admin user data against the defined schema.

Parameters:

  • adminData (AdminData): An object containing the admin user data.

Returns:

  • ValidationResult: The result of the validation, including any errors or success.

Example

const adminData = { id: '1', fullname: 'Alpha James', email: 'alphajames@yopmail.com', phone: '0708633536', role: '999', status: true };

const result = validateAdmin(adminData);
if (result.error) {
  console.error('Validation failed:', result.error.details);
} else {
  console.log('Validation successful');
}

Token Management

signToken(authData: AdminData)

Generates a token for the given admin data.

Parameters:

  • authData (AdminData): An object containing the admin data to include in the token.

Returns:

  • TokenResult: The generated token or any error encountered during the process.

Example:

const tokenResult = signToken(adminData);
console.log('Generated Token:', tokenResult.value);

verifyToken(token: string)

Verifies the provided token and returns the result.

Parameters:

  • token (string): The token to verify.

Returns:

  • VerifiedTokenResult: The result of the token verification, including any errors or decoded data. Example:
const result = await verifyToken(token);
console.log('Token verification result:', result);

Role and Permission Management

createRolePermissions({ role, permissions }: RolePermissionsData)

Creates or updates role permissions in the system.

Parameters:

  • rolePermissions (RolePermissionsData): An object containing the role and its associated permissions.

Returns:

  • Promise: Resolves when the role permissions are successfully created or updated. Example:
await createRolePermissions({ role: '99', permissions: ['admin.plan.delete', 'admin.plan.create', 'admin.plan.read'] });

console.log('Role permissions created.');

readRolePermissions(role: string)

Retrieves permissions associated with a specific role.

Parameters:

  • role (string): The role whose permissions are to be retrieved.

Returns:

  • RolePermissionsData: The retrieved permissions for the specified role. Example:
const permissions = await readRolePermissions('99');
console.log('Role permissions:', permissions);

Authorization

isAuthorized(token: string, permission: string)

Checks if the provided token grants the specified permission.

Parameters:

  • token (string): The token to check. permission (string): The permission to validate against the token.

Returns:

  • VerifiedTokenResult: The result of the authorization check, including any errors or authorized status. Example:
const result = await isAuthorized(token, 'admin.plan.read');
console.log('Authorization result:', result);

License

This package is licensed under the MIT License.

Contributing

Contributions are welcome! Please fork the repository and submit a pull request.