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

@notadd/module-user

v1.6.4

Published

The user module for Notadd application.

Downloads

38

Readme

Notadd User Module(GraphQL Api Version)

中文文档

Document

Features

  • [x] registration
  • [x] login
  • [x] Authorization and Authentication
  • [x] Organization Management
  • [x] User Management
  • [x] role management
  • [x] Information Group Management
  • [x] Information Item Management
  • [x] Global i18n support
  • [ ] ......

Instructions for use

Most of the interfaces of the user module define permissions. When initializing, a super administrator user will be generated. The account number is: sadmin, and the password is: sadmin. After logging in, use accessToken to call updateCurrentUserInfo. (Update the current login user information) and change the password.

Import User Module

Import UserModule in the application root module, and configure the i18n option

Resource Definition

@Resource is a general term for users to perform business operations on an entity resource.

Set annotations for defining resources on the Resolver or Controller class to define the current resource, such as:

@Resource({ name: 'article management', identify: 'artical:manage' })

name: The name of the resource, which is used to define the parent name of the permission. The naming method is: resource+behavior, such as: `related article management related api => 'article management'

identity: The unique identifier of the resource, such as: 'article management' => 'artical:manage'

Permission Definition

@Permission is a definition of a specific operation performed by the user on the current entity resource.

Set annotations for defining operations on the Resolver and Controller methods. The user defines the operation permissions on the current resource, such as:

@Permission({ name: 'Add article', identify: 'artical:create', action: 'create' })

name: The name of the permission, used to define the specific permission name, named: operation + resource, such as: `Add article in the article resource => 'Add article'

identify: The unique identifier of the permission, named: resource: method, such as: 'Add article' => 'artical:createArtical'

action: permission operation type, can only be one of create, delete, update, find

The definition of permissions is inseparable from the definition of resources. The two are coexisting states. When using the permission function, the resources are defined on the class first, and then the permissions are defined on the methods that require permission control.

Once the resources and permissions are defined, the launcher, resources, and permissions are automatically loaded and stored in the database.

Configure authorization, authentication function

The following is an example of the authorization and authentication function logic for the apollo-server-express 2.x version.

Authorization function can be automatically configured by simply importing UserModule

app.module.ts

import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { TypeOrmModule } from '@nestjs/typeorm';

import { UserModule } from '@notadd/module-user';

@Module({
    imports: [
        GraphQLModule.forRootAsync({
           useClass: GraphQLConfigService
        }),
        TypeOrmModule.forRoot(),
        UserModule.forRoot({ i18n: 'en-US' })
    ],
    controllers: [],
    providers: [],
    exports: []
})
export class AppModule { }

Authentication function, using the validateUser method of the AuthService class in the graphql context, and passing the authenticated user to the context

GraphQLJSON is used to handle the JSON scalar type in graphql, you need to install graphql-type-json additionally, and then configure it into the resolvers option.

graphql-config.service.ts

import { Inject, Injectable } from '@nestjs/common';
import { GqlModuleOptions, GqlOptionsFactory } from '@nestjs/graphql';
import * as GraphQLJSON from 'graphql-type-json';
import { AuthService } from '@notadd/module-user';

@Injectable()
export class GraphQLConfigService implements GqlOptionsFactory {
    constructor(
        @Inject(AuthService) private readonly authService: AuthService
    ) {}

    createGqlOptions(): GqlModuleOptions {
        return {
            typePaths: ['./**/*.types.graphql'],
            resolvers: { JSON: GraphQLJSON },
            context: async ({ req }) => {
                const user = await this.authService.validateUser(req);
                return { user };
            }
        };
    }
}