npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

zeesix

v1.0.5

Published

This package handles validation and verification of user roles and permissions

Downloads

104

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: '[email protected]', 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.