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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@course-plateform/common

v1.1.2

Published

Common utilities, guards, decorators and constants for Udemy Clone

Downloads

827

Readme

@udemy/common

A shared package containing common utilities, guards, decorators, constants, and interfaces for the Course Platform microservices architecture.

Installation

npm install @udemy/common

Features

Guards

  • RoleGuard: Authentication and authorization guard that validates JWT tokens and checks user roles and permissions
  • Supports both REST and GraphQL contexts

Decorators

  • @Auth(): Protects routes with required permissions
  • @Roles(): Specifies required roles for route access
  • @CurrentUser(): Injects the current user from the request context

Constants

  • Enums: User roles, permissions, course levels, and request statuses
  • Role-Permissions Mapping: Defines which permissions each role has
  • Pagination: Default limit and page values
  • Messages: Common error and validation messages

Interfaces

  • Common TypeScript interfaces for user, JWT, and context objects

Usage

Basic Authentication

import { Auth, CurrentUser } from '@udemy/common';

@Resolver()
export class UserResolver {
  @Query(() => User)
  @Auth()
  getProfile(@CurrentUser() user: any) {
    return user;
  }
}

Role-Based Access

import { Roles, Role } from '@udemy/common';

@Resolver()
export class AdminResolver {
  @Mutation(() => User)
  @Roles(Role.ADMIN)
  createUser(@Args('input') input: CreateUserInput) {
    // Only ADMIN role can access this
  }
}

Permission-Based Access

import { Auth, Permission } from '@udemy/common';

@Resolver()
export class CourseResolver {
  @Mutation(() => Course)
  @Auth([Permission.CREATE_COURSE])
  createCourse(@Args('input') input: CreateCourseInput) {
    // Requires CREATE_COURSE permission
  }
}

Available Roles

  • ADMIN: Full system access with all permissions
  • INSTRUCTOR: Can create and manage courses
  • USER: Basic user permissions for learning and purchases

Available Permissions

User Management

  • UPDATE_USER, DELETE_USER, EDIT_USER_ROLE, VIEW_USER, CREATE_INSTRUCTOR

Authentication

  • RESET_PASSWORD, CHANGE_PASSWORD, FORGOT_PASSWORD, LOGOUT

Category Management

  • CREATE_CATEGORY, UPDATE_CATEGORY, DELETE_CATEGORY

Course Management

  • CREATE_COURSE, UPDATE_COURSE, DELETE_COURSE

Request Management

  • CREATE_REQUEST, UPDATE_REQUEST, DELETE_REQUEST, VIEW_REQUEST

Certificate Management

  • CREATE_CERTIFICATE, VIEW_CERTIFICATE, DELETE_CERTIFICATE

Shopping Features

  • CART operations: CREATE_CART, UPDATE_CART, DELETE_CART, VIEW_CART
  • WISHLIST operations: CREATE_WISHLIST, DELETE_WISHLIST, VIEW_WISHLIST
  • REVIEW operations: CREATE_REVIEW, UPDATE_REVIEW, DELETE_REVIEW

Configuration

The RoleGuard requires these environment variables:

JWT_SECRET=your-jwt-secret-key

Dependencies

  • @nestjs/common
  • @nestjs/core
  • @nestjs/graphql
  • @nestjs/jwt
  • @nestjs/passport
  • nestjs-i18n
  • passport
  • passport-jwt
  • typeorm
  • reflect-metadata

Development

Building the Package

npm run build

Watch Mode

npm run dev

Integration with Services

In your service module:

import { RoleGuard } from '@udemy/common';

@Module({
  providers: [
    {
      provide: APP_GUARD,
      useClass: RoleGuard,
    },
  ],
})
export class AppModule {}

Required Dependencies in Service:

Make sure your service has these dependencies installed:

npm install @nestjs/jwt @nestjs/passport passport-jwt nestjs-i18n

Error Messages

Common error messages included in the package:

  • "User not found in request"
  • "Password should be from 6 to 16 digits"
  • "An error occurred"

Pagination

Default pagination constants:

import { LIMIT, PAGE } from '@udemy/common';

// LIMIT = 12
// PAGE = 1

License

This package is part of the Course Platform microservices architecture.