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

@synap/nest

v3.2.4

Published

Contents:

Downloads

40

Readme

Synap Nest Modules

Contents:

  • Users/Auth
  • Mongoose
  • Nodemailer
  • Changelogs

Authentication, authorization and user/account management built with @nestjs. This module takes care of session storage/management using mongo-store and connect-session (Express/MongoDb), account login/logout, password resets and registration.

Users/Auth:

You'll need to apply some configuration options when bootstrapping your server:

import { NestFactory } from '@nestjs/core';
import { CoreModule } from './core/core.module';
import { expressConfig } from '@synap-libs/nest';

async function bootstrap()
{
	const app = await NestFactory.create(CoreModule);

	// This allows the SynapNestUsersModule to set up passport middleware and session persistence
	expressConfig(app, {
		// Without passing corsOpts, you won't be able to make use of this module's API
		corsOpts: { origin: [/localhost/], credentials: true },
		dbConnectionUrl: 'mongodb://localhost:27017/my-db'
	});

	app.listen(9000);
}

bootstrap().catch(e => Logger.log(
	`Error bootstrapping app: ${e.stack || e.message || e}`,
	'Bootstrap')
);

See auth.interfaces for further available options the expressConfig method accepts.

Now you can use the module in your application:

import { Module } from '@nestjs/common';
import { SynapNestUsersModule } from '@synap-libs/nest';

@Module({
	imports: [SynapNestUsersModule.forRoot()]
})
export class CoreModule
{
}

This module provides a base user schema that looks like this:

import * as moment from 'moment';

export const BaseSchema = {
	createdAt: { type: Date, required: true, default: moment(new Date(Date.now())).toDate() },
	deleted: { type: Boolean, required: true, default: false },
	email: { type: String, required: true, index: { unique: true } },
	enabled: { type: Boolean, required: true, default: true },
	firstName: { type: String, required: true },
	lastLoggedIn: { type: Date, required: false },
	lastName: { type: String, required: true },
	password: { type: String, required: true },
	registrationToken: { type: String, required: false },
	resetPasswordToken: { type: String, required: false },
	roles: { type: [String], required: true, default: ['user'] },
	tokenExpires: { type: Date, required: false },
	updatedAt: { type: Date, required: true, default: moment(new Date(Date.now())).toDate() }
};

If you don't need any other properties on your users, then you can skip ahead. If you do require additional properties, you can pass them in the forRoot method when importing the module:

SynapNestUsersModule.forRoot({
	extraSchemaFields: { 
		img: { type: String, required: true, default: 'assets/images/stock-user.png' },
		displayName: { type: String, required: true, default: function()
		{
			if (!(this.firstName && this.lastName))
				return 'awesome.user';

			return `${this.firstName.toLowerCase()}.${this.lastName.toLowerCase()}`;
		}}
	}
})

Mongoose

This is an extension of Nest's MongooseModule. The only differences are

  1. The mongoose package is 5.3.1 as opposed to 5.0.1 which is the version included in @nestjs/mongoose
  2. The createMongooseProviders method has been updated to allow schema hooks and dependency injection

Usage

import { Module } from '@nestjs/common';
import { MongooseModule, InjectModel } from './';
import { Schema, Model, Document } from 'mongoose';

// CoreModule
@Module({
	imports: [
		MongooseModule.forRoot('mongodb://localhost:27017/my-db', { useNewUrlParser: true }),
		MyModule
	]
})
export class CoreModule {}

// Document Interface
export interface MyDocument extends Document
{
	someProp:string;
}

// MyService
export class MyService 
{
	constructor(@InjectModel('MyModel') private readonly myModel:Model<MyDocument>)
	{
	}
}

// MyModule
@Module({
	imports: [
		MongooseModule.forFeature([{
			name: 'MyModel',
			schema: new Schema({ someProp: { type: String } }),
			hooks: [
				{
					type: 'post',
					method: 'remove',
					fn: async (doc:MyDocument, svc:MyService) => console.log('MyModel.postRemove'),
					inject: ['MyService']
				}
			]
		}])
	]
})
export class MyModule {}

Nodemailer

A Nodemailer module built with @nestjs.

#Usage:

TODO

Changelogs

Usage:

TODO