From 5a235c91005f17773f3533ddbd995edf2a4069df Mon Sep 17 00:00:00 2001 From: Douglas Gabriel Cardoso <32394842+douglasgc@users.noreply.github.com> Date: Thu, 25 Apr 2024 21:44:08 -0300 Subject: [PATCH] Refactor/v0.1.0 (#21) * feat(): security group generic structure + security * fix(): package-lock * fix(): removing comment * fix(): lint * ifx(): webpack link * ifx(): webpack package * fix(): missing sdk dependencies * fix(): testing cli output fix * refactor: refactor code and update dependencies and nodejs version * cicd: change pipeline nodejs version * cicd: change pipeline nodejs version * feature: add oidc and update tsconfigs and reestructure auth service * fix: pretier fix all codebase * refact: infraestructure refactoring to bundle swagger * fix: hotfix in cdk vpc warning * fix: fix in environment * refactor: infra multiples security groups * fix: source .env in pipeline * lint: fix eslint files * lint: fix eslint files * lint: fix eslint files * lint: fix eslint files * fix: fix in unit test * fix: fix in migration command load env * fix: fix in migration command load env * fix: fix in migration command load env * fix: fix in migration command load env * fix: fix in migration command load env * fix: fix in migration command load env * fix: fix in migration command load env * fix: fix in migration command load env * fix: fix in migration command load env * fix: fix in migration command load env * cicd: add wait on pipeline script * cicd: add wait on pipeline script * cicd: add wait on pipeline script * cicd: add wait on pipeline script * cicd: add wait on pipeline script * cicd: add wait on pipeline script * cicd: add wait on pipeline script * fix: docker environment overide * fix: swagger dependencies * fix: swagger dependencies * fix: lint project * fix pipeline: fix pipeline deploy * fix pipeline: fix pipeline deploy * doc: update project title and description --------- Co-authored-by: Luiz Grigio --- .DS_Store | Bin 6148 -> 0 bytes .circleci/config.yml | 131 +- .dockerignore | 4 + .eslintrc.js | 4 +- .gitignore | 35 +- .vscode/settings.json | 3 + CONTRIBUTING.md | 107 + Dockerfile | 14 + README.md | 24 +- cdk.context.json | 65 +- docker-compose.yaml | 19 +- docker.env | 1 + docs/auth.md | 55 +- docs/installing-and-running.md | 6 +- infra/constants.ts | 1 + .../api-gateway/api-gateway.construct.ts | 21 +- .../api-gateway/props/api-gateway.props.ts | 3 + .../aurora-database-proxy.construct.ts | 10 +- .../aurora-database.construct.ts | 12 +- .../generic-security-group.construct.ts} | 33 +- .../props/generic-security-group.props.ts} | 3 +- .../lambda-database-migration.construct.ts | 15 +- .../props/lambda-database-migration.prop.ts | 3 +- .../lambda-nestjs-function/constants.ts | 75 +- .../lambda-nestjs-function.constructs.ts | 32 +- .../props/lambda-nestjs-function.props.ts | 7 +- .../lambda-role/lambda-role.construct.ts | 16 +- infra/factories/infraestructure.ts | 53 +- infra/index.ts | 67 +- infra/layers/application.layer.ts | 134 +- infra/layers/core.layer.ts | 6 +- infra/props/application.props.ts | 22 +- infra/props/lambda.props.ts | 11 + infra/resources/aurora-database.resource.ts | 35 +- .../resources/database-migration.resource.ts | 38 +- infra/resources/lambda.resources.ts | 66 +- infra/tables/sessions.ts | 40 + infra/utils/create-name.ts | 7 +- infra/utils/create-output.ts | 14 +- nest-cli.json | 2 +- package-lock.json | 31868 ++++------------ package.json | 124 +- src/app.module.ts | 7 + src/auth/auth.service.ts | 14 +- src/auth/dto/auth-confirm-email.dto.ts | 8 + src/auth/dto/auth-email-login.dto.ts | 21 +- src/auth/dto/auth-forgot-password.dto.ts | 12 + src/auth/dto/auth-register-login.dto.ts | 11 +- src/auth/dto/auth-reset-password.dto.ts | 13 + src/auth/dto/auth-update.dto.ts | 24 + src/auth/forgot/entities/forgot.entity.ts | 32 + src/auth/guards/login.guard.ts | 5 + src/auth/oidc/adapters/dynamodb.adapter.ts | 200 + .../oidc/clients/clients.controller.spec.ts | 24 + src/auth/oidc/clients/clients.controller.ts | 17 + src/auth/oidc/clients/clients.data-source.ts | 32 + src/auth/oidc/clients/clients.module.ts | 10 + src/auth/oidc/clients/clients.service.spec.ts | 22 + src/auth/oidc/clients/clients.service.ts | 18 + src/auth/oidc/oidc.controller.ts | 131 + src/auth/oidc/oidc.module.ts | 23 + .../oidc/providers/access-token.provider.ts | 15 + src/auth/oidc/providers/account.provider.ts | 21 + src/auth/oidc/sources/logout.source.ts | 107 + src/auth/server.module.ts | 10 + src/auth/server.ts | 4 + src/common/bootstrap.ts | 19 +- src/common/config/certs/jwks.ts | 15 + src/common/config/certs/rds-ca-2019-root.pem | 24 - .../config/certs/rds-combined-ca-bundle.pem | 3028 ++ src/common/config/database.config.ts | 44 +- src/common/database/README.md | 7 + ...ta-source.ts => lambda-cli.data-source.ts} | 0 ...ata-source.ts => local-cli.data-source.ts} | 0 .../database/seeds/user/user-seed.service.ts | 2 +- src/common/database/typeorm-config.service.ts | 3 +- .../utils/generatePasswordWithRdsSigner.ts | 11 + src/common/factories/lambda-server.factory.ts | 75 + src/common/factories/oidc-provider.factory.ts | 54 + src/common/mail/mail.service.ts | 15 +- src/common/strategies/jwt.strategy.ts | 6 +- src/common/utils/types/deep-partial.type.ts | 4 +- src/main.ts | 15 +- src/swagger/index.ts | 18 +- src/swagger/server.ts | 4 + src/users/server.module.ts | 2 +- src/users/server.ts | 4 +- test/wait-on.js | 52 + tsconfig.json | 2 +- 89 files changed, 13432 insertions(+), 23939 deletions(-) delete mode 100644 .DS_Store create mode 100644 .dockerignore create mode 100644 .vscode/settings.json create mode 100644 CONTRIBUTING.md create mode 100644 Dockerfile create mode 100644 docker.env rename infra/constructs/{aurora-database-security-group/aurora-database-security-group.construct.ts => generic-security-group/generic-security-group.construct.ts} (64%) rename infra/constructs/{aurora-database-security-group/props/aurora-database-security-group.props.ts => generic-security-group/props/generic-security-group.props.ts} (60%) create mode 100644 infra/props/lambda.props.ts create mode 100644 infra/tables/sessions.ts create mode 100644 src/auth/guards/login.guard.ts create mode 100644 src/auth/oidc/adapters/dynamodb.adapter.ts create mode 100644 src/auth/oidc/clients/clients.controller.spec.ts create mode 100644 src/auth/oidc/clients/clients.controller.ts create mode 100644 src/auth/oidc/clients/clients.data-source.ts create mode 100644 src/auth/oidc/clients/clients.module.ts create mode 100644 src/auth/oidc/clients/clients.service.spec.ts create mode 100644 src/auth/oidc/clients/clients.service.ts create mode 100644 src/auth/oidc/oidc.controller.ts create mode 100644 src/auth/oidc/oidc.module.ts create mode 100644 src/auth/oidc/providers/access-token.provider.ts create mode 100644 src/auth/oidc/providers/account.provider.ts create mode 100644 src/auth/oidc/sources/logout.source.ts create mode 100644 src/auth/server.module.ts create mode 100644 src/auth/server.ts create mode 100644 src/common/config/certs/jwks.ts delete mode 100755 src/common/config/certs/rds-ca-2019-root.pem create mode 100644 src/common/config/certs/rds-combined-ca-bundle.pem create mode 100644 src/common/database/README.md rename src/common/database/{lambda.data-source.ts => lambda-cli.data-source.ts} (100%) rename src/common/database/{local.data-source.ts => local-cli.data-source.ts} (100%) create mode 100644 src/common/database/utils/generatePasswordWithRdsSigner.ts create mode 100644 src/common/factories/lambda-server.factory.ts create mode 100644 src/common/factories/oidc-provider.factory.ts create mode 100644 src/swagger/server.ts create mode 100644 test/wait-on.js diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 2cfa3149cbf2e9fa12ece83f12c9d93f355896e1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKPfNov6i?jLmLc?@ptpe6fgMwscqwy!0V{e?ne95XSewyy_Amy$>lgBi_<4LU zNx|U`oRL0w4M2`_WXoU;Z=jg%MENKQVR;y8OfP#{0Kg`gm4J@51m*~X zp212ZctE&L1=OkBlo(v6gI$<7&tRodr!#Jf4{p9(7cX3W9p)D*oN-Sh^~3-%u*d+` zz90_X|L5?_EG_a?2zA5&G4Nj*;LU+Q=)>;J-TG~xc-IPO_s~! diff.txt && cat diff.txt deployment: working_directory: ~/nest-boilerplate executor: aws-cli/default docker: - - image: cimg/node:16.18.1-browsers + - image: cimg/node:20.12.2-browsers steps: - restore_cache: - key: v0-src-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }} + key: v1-src-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }} - restore_cache: key: v0-node-modules-{{ .Branch }}-{{ checksum "package.json" }} - restore_cache: @@ -171,48 +174,48 @@ workflows: - build: requires: - dependencies - - diff: - name: diff_to_development - context: development - requires: - - build - - integration_test - - unit_test - - diff: - name: diff_to_production - context: production - filters: - tags: - only: /^v.*/ - branches: - ignore: /.*/ - requires: - - build - - integration_test - - unit_test - - approve_deploy_to_development: - type: approval - context: development - filters: - branches: - only: - - master - - main - - develop - requires: - - diff_to_development - - approve_deploy_to_production: - type: approval - context: production - requires: - - diff_to_production - - deployment: - name: deployment_to_development - context: development - requires: - - approve_deploy_to_development - - deployment: - name: deployment_to_production - context: production - requires: - - approve_deploy_to_production \ No newline at end of file + # - diff: + # name: diff_to_development + # context: development + # requires: + # - build + # - integration_test + # - unit_test + # - diff: + # name: diff_to_production + # context: production + # filters: + # tags: + # only: /^v.*/ + # branches: + # ignore: /.*/ + # requires: + # - build + # - integration_test + # - unit_test + # - approve_deploy_to_development: + # type: approval + # context: development + # filters: + # branches: + # only: + # - master + # - main + # - develop + # requires: + # - diff_to_development + # - approve_deploy_to_production: + # type: approval + # context: production + # requires: + # - diff_to_production + # - deployment: + # name: deployment_to_development + # context: development + # requires: + # - approve_deploy_to_development + # - deployment: + # name: deployment_to_production + # context: production + # requires: + # - approve_deploy_to_production \ No newline at end of file diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..19dbfd591 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +/.data +/dist +/documentation +.env \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js index ead57c7db..259de13c7 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -2,7 +2,7 @@ module.exports = { parser: '@typescript-eslint/parser', parserOptions: { project: 'tsconfig.json', - tsconfigRootDir : __dirname, + tsconfigRootDir: __dirname, sourceType: 'module', }, plugins: ['@typescript-eslint/eslint-plugin'], @@ -22,4 +22,4 @@ module.exports = { '@typescript-eslint/explicit-module-boundary-types': 'off', '@typescript-eslint/no-explicit-any': 'off', }, -}; \ No newline at end of file +}; diff --git a/.gitignore b/.gitignore index 65aec6ae9..c2dde4bcc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # compiled output /dist /node_modules +/build # Logs logs @@ -27,6 +28,13 @@ lerna-debug.log* .settings/ *.sublime-workspace +# infra outputs +cdk.out/* +cdk.context.json + +# compodoc +documentation/* + # IDE - VSCode .vscode/* !.vscode/settings.json @@ -34,13 +42,22 @@ lerna-debug.log* !.vscode/launch.json !.vscode/extensions.json -# infra outputs -cdk.out/* - -# documentatin dist -documentation - -.data -/files +# dotenv environment variable files .env -/ormconfig.json \ No newline at end of file +.env.development.local +.env.test.local +.env.production.local +.env.local + +# temp directory +.temp +.tmp + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..3be886795 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "CodeGPT.apiKey": "OpenAI" +} \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..a212dd24c --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,107 @@ +### Commit Message Format + +Each commit message consists of a **header**, a **body** and a **footer**. The header has a special +format that includes a **type**, a **scope** and a **subject**: + +``` +(): + + + +