Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(auth)!: Migrate auth-related functionalities from @spuxx/nest-utils to new package @spuxx/nest-auth #129

Merged
merged 5 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .release-please/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"packages": {
"packages/js-utils": {},
"packages/browser-utils": {},
"packages/nest-auth": {},
"packages/nest-utils": {},
"packages/nest-testing": {},
"packages/solid": {}
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@

## <a name='Description'></a>Description

A monorepo containing various libraries for JavaScript, TypeScript, Nest.js and Solid.js applications. Find out more about each package here:
A monorepo containing various libraries for JavaScript, TypeScript, NestJS and SolidJS applications. Find out more about each package here:

- [@spuxx/js-utils](https://github.com/spuxx-dev/jslibs/tree/main/packages/js-utils)
- [@spuxx/browser-utils](https://github.com/spuxx-dev/jslibs/tree/main/packages/browser-utils)
- [@spuxx/nest-utils](https://github.com/spuxx-dev/jslibs/tree/main/packages/nest-utils)
- [@spuxx/nest-auth](https://github.com/spuxx-dev/jslibs/tree/main/packages/nest-auth)
- [@spuxx/nest-testing](https://github.com/spuxx-dev/jslibs/tree/main/packages/nest-testing)
- [@spuxx/solid](https://github.com/spuxx-dev/jslibs/tree/main/packages/solid)

## <a name='Documentation'></a>Documentation

Expand Down
3 changes: 2 additions & 1 deletion apps/nest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
"test:vitest": "vitest run --coverage"
},
"dependencies": {
"@nanogiants/nestjs-swagger-api-exception-decorator": "1.7.0",
"@nanogiants/nestjs-swagger-api-exception-decorator": "1.7.2",
"@nestjs/common": "11.0.11",
"@nestjs/core": "11.0.11",
"@nestjs/platform-express": "11.0.11",
"@nestjs/swagger": "11.0.6",
"@spuxx/js-utils": "workspace:@spuxx/js-utils@*",
"@spuxx/nest-auth": "workspace:@spuxx/nest-auth@*",
"@spuxx/nest-utils": "workspace:@spuxx/nest-utils@*",
"class-transformer": "0.5.1",
"class-validator": "0.14.1",
Expand Down
2 changes: 1 addition & 1 deletion apps/nest/src/app.controller.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { beforeEach, describe, expect, it } from 'vitest';
import { AppController } from './app.controller';
import { TestContainer, Supertest } from '@spuxx/nest-testing';
import { AuthModule } from '@spuxx/nest-utils';
import { AuthModule } from '@spuxx/nest-auth';
import { authConfig, AuthRole } from './auth/auth.config';

describe('AppController', () => {
Expand Down
9 changes: 2 additions & 7 deletions apps/nest/src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@ import {
} from '@nestjs/common';
import { EnvModule } from './env/env.module';
import type { Request } from 'express';
import {
AuthGuard,
getSession,
HttpLoggingInterceptor,
isAuthenticated,
Roles,
} from '@spuxx/nest-utils';
import { HttpLoggingInterceptor } from '@spuxx/nest-utils';
import { AuthRole } from './auth/auth.config';
import { ApiException } from '@nanogiants/nestjs-swagger-api-exception-decorator';
import { AuthGuard, getSession, isAuthenticated, Roles } from '@spuxx/nest-auth';

@Controller()
@UseInterceptors(HttpLoggingInterceptor)
Expand Down
3 changes: 2 additions & 1 deletion apps/nest/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AuthModule, MappingModule } from '@spuxx/nest-utils';
import { MappingModule } from '@spuxx/nest-utils';
import { EnvModule } from './env/env.module';
import { authConfig } from './auth/auth.config';
import { CatsModule } from './cats/cats.module';
import { AuthModule } from '@spuxx/nest-auth';

@Module({
imports: [EnvModule.register(), AuthModule.forRoot(authConfig), MappingModule, CatsModule],
Expand Down
2 changes: 1 addition & 1 deletion apps/nest/src/auth/auth.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AuthOptions } from '@spuxx/nest-utils';
import { AuthOptions } from '@spuxx/nest-auth';
import { EnvModule } from '../env/env.module';

export const AuthRole = {
Expand Down
3 changes: 2 additions & 1 deletion apps/nest/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { CustomLogger, AuthModule } from '@spuxx/nest-utils';
import { CustomLogger } from '@spuxx/nest-utils';
import { auth } from 'express-openid-connect';
import { AppModule } from './app.module';
import { authConfig } from './auth/auth.config';
import { EnvModule } from './env/env.module';
import { AuthModule } from '@spuxx/nest-auth';

async function bootstrap() {
const logger = new CustomLogger({
Expand Down
5 changes: 5 additions & 0 deletions packages/nest-auth/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*
!/dist
!package.json
!LICENSE.md
!README.md
1 change: 1 addition & 0 deletions packages/nest-auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
21 changes: 21 additions & 0 deletions packages/nest-auth/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) [2024] [spuxx]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
26 changes: 26 additions & 0 deletions packages/nest-auth/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# @spuxx/nest-auth

![Main pipeline](https://github.com/spuxx-dev/jslibs/actions/workflows/main.yml/badge.svg)
![Release pipeline](https://github.com/spuxx-dev/jslibs/actions/workflows/release_nest_auth.yml/badge.svg)
![npm version](https://img.shields.io/npm/v/%40spuxx%2Fnest-auth)
![npm bundle size](https://img.shields.io/bundlephobia/min/%40spuxx%2Fnest-auth)
![License](https://img.shields.io/github/license/spuxx-dev/jslibs)

<!-- vscode-markdown-toc -->

- [Description](#Description)
- [Links](#Links)

<!-- vscode-markdown-toc-config
numbering=false
autoSave=true
/vscode-markdown-toc-config -->
<!-- /vscode-markdown-toc -->

## <a name='Description'></a>Description

`@spuxx/nest-auth` contains a selection of auth-related utilities that I keep reusing in my NestJS applications.

## <a name='Links'></a>Links

- [Source](https://github.com/spuxx-dev/jslibs)
71 changes: 71 additions & 0 deletions packages/nest-auth/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"name": "@spuxx/nest-auth",
"version": "0.0.0",
"description": "A package containing auth-related functionalities for my NestJS applications.",
"license": "MIT",
"author": {
"name": "spuxx",
"email": "hi@spuxx.dev",
"url": "https://spuxx.dev"
},
"keywords": [
"spuxx"
],
"repository": {
"type": "git",
"url": "https://github.com/spuxx-dev/jslibs"
},
"homepage": "https://github.com/spuxx-dev/jslibs/blob/main/packages/nest-auth/README.md",
"bugs": {
"url": "https://github.com/spuxx-dev/jslibs/issues"
},
"type": "module",
"main": "dist/main.js",
"module": "dist/main.js",
"types": "dist/main.d.ts",
"exports": {
".": {
"types": "./dist/main.d.ts",
"import": "./dist/main.js",
"default": "./dist/main.js"
}
},
"files": [
"dist",
"README.md",
"LICENSE",
"package.json"
],
"scripts": {
"dev": "vite build --watch",
"build": "vite build",
"types": "tsc --noEmit",
"test": "pnpm run test:vitest",
"test:vitest": "vitest run --coverage"
},
"peerDependencies": {
"@nanogiants/nestjs-swagger-api-exception-decorator": "^1.7.2",
"@nestjs/common": "^11.0.0",
"@nestjs/core": "^11.0.0",
"@nestjs/swagger": "^11.0.0",
"@spuxx/js-utils": "^1.3.0",
"class-transformer": "^0.5.0",
"class-validator": "^0.14.0",
"express-openid-connect": "^2.17.0",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.0"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "16.0.0",
"@spuxx/js-utils": "1.3.0",
"@spuxx/nest-testing": "workspace:@spuxx/nest-testing@*",
"@types/express": "5.0.0",
"@vitest/coverage-v8": "3.0.5",
"typescript": "5.7.3",
"unplugin-swc": "1.5.1",
"vite": "6.1.0",
"vite-plugin-dts": "4.5.0",
"vite-tsconfig-paths": "5.1.4",
"vitest": "3.0.7"
}
}
6 changes: 6 additions & 0 deletions packages/nest-auth/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// +++ IMPORTANT ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Make sure to re-export all components, functions and services from this file.
// Otherwise, they will not be included into the bundle.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
export * from './auth';
export * from './constants';
6 changes: 6 additions & 0 deletions packages/nest-auth/tests/vitest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { vi, afterEach } from 'vitest';

afterEach(() => {
vi.unstubAllEnvs();
vi.unstubAllGlobals();
});
13 changes: 13 additions & 0 deletions packages/nest-auth/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"include": ["./src"],
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "node",
"skipLibCheck": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"declaration": true,
"allowSyntheticDefaultImports": true,
"baseUrl": "."
}
}
69 changes: 69 additions & 0 deletions packages/nest-auth/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/// <reference types="vitest" />
import { defineConfig } from 'vite';
import { resolve } from 'path';
import { peerDependencies } from './package.json';
import dts from 'vite-plugin-dts';
import tsconfigPaths from 'vite-tsconfig-paths';

import swc from 'unplugin-swc';

export default defineConfig({
plugins: [
dts({
include: ['src/**/*'],
exclude: ['*.{test,spec}.*'],
tsconfigPath: './tsconfig.json',
rollupTypes: true,
}),
tsconfigPaths(),
// esbuild doesn't support a couple of features that nestjs requires, so instead
// we use swc. For example, see: https://github.com/nestjs/nest/issues/9228
swc.vite({
module: { type: 'es6' },
jsc: {
target: 'esnext',
parser: {
syntax: 'typescript',
decorators: true,
},
transform: {
legacyDecorator: true,
decoratorMetadata: true,
},
keepClassNames: true,
preserveAllComments: true,
},
}),
],
ssr: {
target: 'node',
},
build: {
ssr: true,
minify: false,
lib: {
entry: {
main: resolve(__dirname, 'src/main.ts'),
},
name: '@spuxx/nest-testing',
formats: ['es'],
},
rollupOptions: {
external: [...Object.keys(peerDependencies)],
},
},
test: {
environment: 'node',
silent: true,
setupFiles: './tests/vitest.setup.ts',
reporters: ['default', 'junit'],
outputFile: 'reports/junit/junit.xml',
coverage: {
provider: 'v8',
all: true,
include: ['**/*.ts'],
reportsDirectory: 'reports/vitest/coverage',
reporter: ['text', 'json'],
},
},
});
8 changes: 0 additions & 8 deletions packages/nest-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,16 @@
"test:vitest": "vitest run --coverage"
},
"peerDependencies": {
"@nanogiants/nestjs-swagger-api-exception-decorator": "^1.6.0",
"@nestjs/common": "^11.0.0",
"@nestjs/config": "^3.0.0",
"@nestjs/core": "^11.0.0",
"@nestjs/swagger": "^11.0.0",
"@spuxx/js-utils": "^1.3.0",
"class-transformer": "^0.5.0",
"class-validator": "^0.14.0",
"dotenv": "^16.0.0",
"express-openid-connect": "^2.17.0",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.0"
},
"peerDependenciesMeta": {
"express-openid-connect": {
"optional": true
}
},
"devDependencies": {
"@rollup/plugin-node-resolve": "16.0.0",
"@spuxx/js-utils": "1.3.0",
Expand Down
2 changes: 0 additions & 2 deletions packages/nest-utils/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
// Otherwise, they will not be included into the bundle.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
export * from './env';
export * from './auth';
export * from './logging';
export * from './transformers';
export * from './http';
export * from './mapping';
export * from './constants';
Loading
Loading