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

jnext-library-ts

v1.0.7

Published

An authentication library for Node.js simplifies the implementation of authentication-related functionalities in your Express applications. It provides tools for managing Sequelize models, creating Express routes, initializing email configurations, and Sw

Downloads

8

Readme

jnext-library-ts

An authentication library for Node.js simplifies the implementation of authentication-related functionalities in your Express applications. It provides tools for managing Sequelize models, creating Express routes, initializing email configurations, and Swagger documentation setup.

Installation

npm install jnext-library-ts

Usage

1. Setup server connection in your project

import dotenv from 'dotenv';
dotenv.config();
import express, { Express } from 'express';
import { Sequelize } from 'sequelize';
import * as myLib from 'jnext-library-ts';

// Create an Express application
const app: Express = express();

const sequelize = new Sequelize('dbName', 'root', '', {
    dialect: 'mysql',
    host: '127.0.0.1',
    logging: false
});

// Start the server on port 7000
app.listen(7000, () => {
    console.log(`Server is started on port:`, 7000);
});

2. Create Sequelize Models

Use the getModels function to retrieve predefined Sequelize models for users, user_meta, and user_roles. The user_roles model is automatically populated with data for the 'user' and 'admin' roles. Additionally, you can dynamically add fields to the user model using createModel().

import { Sequelize } from 'sequelize';
import * as myLib from 'jnext-library-ts';

const sequelize = new Sequelize('dbName', 'root', '', {
    dialect: 'mysql',
    host: '127.0.0.1',
    logging: false
});

myLib.getModels();
myLib.createModel('customUserModel', sequelize, {
    // Define additional fields here
    filedName: dataType // Datatype should be string. Ex. 'STRING' , 'INTEGER'
});

3. Create Express Routes

Use the createRoutes function to fetch API routes from the library for use in your Express application.

import express, { Express } from 'express';
import * as myLib from 'jnext-library-ts';

const router = myLib.createRoutes({ validator: false });

const app: Express = express();
app.use('/', router);

4. Set Environment variables in .env files

   PORT: 8000

   #JWT comfiguration details
   JWT_SECRET: jwtSecretkey
   JWT_EXPIRATION_TIME: Expiration time of jwt. Example - 1h

   #APIs prefix route to access swagger
   API_BASE_PREFIX: /

   #To manage delete APIs functionality. Hard delete or soft delete
   HARD_DELETE: false

   #To add/ manage custome templete for email Templetes in request data
   CUSTOM_TEMPLATE: true

   #To manage send mail using SMTP or sendmail()   
   SMTP=true

Example

import express, { Express } from 'express';
import Sequelize from 'sequelize';
import * as myLib from 'jnext-library-ts';

const router = myLib.createRoutes({ validator: false });
const sequelize = new Sequelize.Sequelize('authapis', 'root', '', {
    dialect: 'mysql',
    host: '127.0.0.1',
    logging: false
});

myLib.getModels();
myLib.createModel('customUserModel', sequelize, {
    // Define additional fields here
});

const app: Express = express();
app.use('/', router);

app.listen(8000, () => {
    console.log(`Server is started on`, 8000);
});

Additional Details

Types of validations

| Type | Description | | :------- | :-------------------------------- | | string.base | Specifies that the value must be a string. | | number.base | Specifies that the value must be a number. | | boolean.base | Specifies that the value must be a boolean. | | object.base | Specifies that the value must be an object. | | array.base | Specifies that the value must be an array. | | date.base | Specifies that the value must be a date. | | alternatives | Specifies multiple valid alternatives for the value. | | any.required | Specifies that the property is required. | | any.optional | Specifies that the property is optional. | | any.forbidden | Specifies that the property is forbidden. | | any.allow | Specifies the allowed values for the property. | | any.valid | Specifies the valid values for the property. | | any.invalid | Specifies the invalid values for the property. | | any.default | Specifies the default value for the property. | | string.email | Specifies that the string must be a valid email. | | string.min | Specifies the minimum length of the string. | | string.max | Specifies the maximum length of the string. | | number.min | Specifies the minimum value for the number. | | number.max | Specifies the maximum value for the number. | | date.min | Specifies the minimum date for the date. | | date.max | Specifies the maximum date for the date. | | string.pattern | Specifies a regular expression pattern for the string.| | any.when | Specifies conditional validation based on another property.| | any.error | Specifies custom error messages for the property. | | any.label | Specifies a custom label for the property in error messages.| | any.messages | Specifies custom validation error messages. |

Acknowledgements