From 152929b0caadd67ee680a0588740fd64706e7856 Mon Sep 17 00:00:00 2001 From: Bruno Date: Fri, 6 Dec 2024 10:38:21 +0100 Subject: [PATCH 1/3] feat(mainDemo): seed default DB --- examples/README.md | 24 +----------------------- examples/main-demo/.gitignore | 1 - examples/main-demo/manifest/backend.db | Bin 53248 -> 53248 bytes 3 files changed, 1 insertion(+), 24 deletions(-) diff --git a/examples/README.md b/examples/README.md index 38de70e7..6b6613a7 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,25 +1,3 @@ # Examples -This folders hosts examples of Manifest implementations for **contributors**. - -## How to work with npm link - -[NPM Link](https://docs.npmjs.com/cli/v10/commands/npm-link) is a great tool to develop packages on real-world situations without having to publish them. - -### Example with NPM manifest package - -First go to `packages/core/manifest` and run this command to link the "manifest" package. - -``` -sudo npm link -``` - -the go to a folder that as `manifest` as a dependency in its `package.json` and run - -``` -npm link manifest -``` - -The local "manifest" package will now replace the dependency. - -Attention: for some reason the `nodemon` binary gets removed this way. Try to add it if the `npm run manifest` command is not working: `npm i nodemon` +This folder hosts examples of Manifest implementations. diff --git a/examples/main-demo/.gitignore b/examples/main-demo/.gitignore index 02400b23..b512c09d 100644 --- a/examples/main-demo/.gitignore +++ b/examples/main-demo/.gitignore @@ -1,2 +1 @@ - node_modules \ No newline at end of file diff --git a/examples/main-demo/manifest/backend.db b/examples/main-demo/manifest/backend.db index fd0b4e4db1a9baad0d1466518c6d38d4e7896d6b..fdd50bc0a0c0cbfc5f19727d0a8de752b841659f 100644 GIT binary patch literal 53248 zcmeHQYit`=b|xiq_?RInTcRmimPFH%CEB7mGki0oEypV0&OP^iXZhZRYFiCe8qIa39g17}ELN*!CKR$* zth~iy@t|+`ZAITc^ld}m#s&92w%!b09yW!AexLOW}s`a*dS#5?cES))bYU%z^arXYusf#P; z&nzO?x!J{)(BgUYeQ{x7Dikg?Ri&+#Pqo9LGWy5XN1;#5&Yilruo9Yt+wJPQIyq5q zT$_kQ5NLA)Zc>8k%DNg3T~(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(2g_| zAIME%vx)V_btG2$_-OVx7EFwV4iARzAGzxowwD;HH-50Id*yTl%k{e`q6Dbw&rQ-9 zi5QA2ptJKpE{vhXLNOGJjmU+=wDzL+LL2su`ST%wqq0C48qlsZ&;pkm1$2;Zt2*He&kb!P`N zehej!F^Ch0u>G-_0YDBD>ugjphT2E{C;H(D Date: Fri, 6 Dec 2024 10:38:53 +0100 Subject: [PATCH 2/3] feat(JWT): use default token secret key if not in env --- packages/core/manifest/.env.contribution | 1 - packages/core/manifest/src/auth/auth.service.ts | 4 ++-- .../core/manifest/src/auth/tests/auth.service.spec.ts | 2 +- packages/core/manifest/src/config/general.ts | 11 ++++++++--- packages/core/manifest/src/constants.ts | 1 + 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/core/manifest/.env.contribution b/packages/core/manifest/.env.contribution index dfe7ebd5..d3a2e799 100644 --- a/packages/core/manifest/.env.contribution +++ b/packages/core/manifest/.env.contribution @@ -1,2 +1 @@ -TOKEN_SECRET_KEY=ReplaceThisToWhatever NODE_ENV=contribution \ No newline at end of file diff --git a/packages/core/manifest/src/auth/auth.service.ts b/packages/core/manifest/src/auth/auth.service.ts index a3808065..122932d1 100644 --- a/packages/core/manifest/src/auth/auth.service.ts +++ b/packages/core/manifest/src/auth/auth.service.ts @@ -66,7 +66,7 @@ export class AuthService { return { token: jwt.sign( { email: signupUserDto.email, entitySlug }, - this.configService.get('TOKEN_SECRET_KEY') + this.configService.get('tokenSecretKey') ) } } @@ -142,7 +142,7 @@ export class AuthService { try { decoded = jwt.verify( token?.replace('Bearer ', ''), - this.configService.get('TOKEN_SECRET_KEY') + this.configService.get('tokenSecretKey') ) as jwt.JwtPayload } catch { return Promise.resolve({ user: null, entitySlug: null }) diff --git a/packages/core/manifest/src/auth/tests/auth.service.spec.ts b/packages/core/manifest/src/auth/tests/auth.service.spec.ts index 1ed25bc7..0d5fca5f 100644 --- a/packages/core/manifest/src/auth/tests/auth.service.spec.ts +++ b/packages/core/manifest/src/auth/tests/auth.service.spec.ts @@ -102,7 +102,7 @@ describe('AuthService', () => { const { jwtToken, entitySlug } = jwt.sign( 'nonexistent@email.com', - configService.get('TOKEN_SECRET_KEY') + configService.get('tokenSecretKey') ) expect(await authService.getUserFromToken(jwtToken)).toMatchObject({ diff --git a/packages/core/manifest/src/config/general.ts b/packages/core/manifest/src/config/general.ts index 257d9cdb..77ed19c7 100644 --- a/packages/core/manifest/src/config/general.ts +++ b/packages/core/manifest/src/config/general.ts @@ -1,8 +1,13 @@ -import { DEFAULT_PORT } from '../constants' +import { DEFAULT_PORT, DEFAULT_TOKEN_SECRET_KEY } from '../constants' -export default (): { port: number | string; nodeEnv: string } => { +export default (): { + port: number | string + nodeEnv: string + tokenSecretKey: string +} => { return { port: process.env.PORT || DEFAULT_PORT, - nodeEnv: process.env.NODE_ENV || 'development' + nodeEnv: process.env.NODE_ENV || 'development', + tokenSecretKey: process.env.TOKEN_SECRET_KEY || DEFAULT_TOKEN_SECRET_KEY } } diff --git a/packages/core/manifest/src/constants.ts b/packages/core/manifest/src/constants.ts index 0b3b0468..8ef10863 100644 --- a/packages/core/manifest/src/constants.ts +++ b/packages/core/manifest/src/constants.ts @@ -14,6 +14,7 @@ export const DEFAULT_SEED_COUNT: number = 50 export const DEFAULT_MAX_MANY_TO_MANY_RELATIONS: number = 5 export const DUMMY_FILE_NAME: string = 'dummy-invoice.pdf' export const DUMMY_IMAGE_NAME: string = 'dummy-image.jpg' +export const DEFAULT_TOKEN_SECRET_KEY: string = 'REPLACE_ME' // Uploads. export const STORAGE_PATH: string = 'public/storage' From 560087e5b482f828cb0b006725ef2792e42b2d54 Mon Sep 17 00:00:00 2001 From: Bruno Date: Fri, 6 Dec 2024 10:45:29 +0100 Subject: [PATCH 3/3] feat(production): throw error if env prod and no token secret key --- packages/core/manifest/src/main.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/core/manifest/src/main.ts b/packages/core/manifest/src/main.ts index 5d89fe1d..07da4630 100644 --- a/packages/core/manifest/src/main.ts +++ b/packages/core/manifest/src/main.ts @@ -7,7 +7,7 @@ import * as express from 'express' import * as livereload from 'livereload' import { join } from 'path' import { AppModule } from './app.module' -import { DEFAULT_PORT } from './constants' +import { DEFAULT_PORT, DEFAULT_TOKEN_SECRET_KEY } from './constants' import { OpenApiService } from './open-api/services/open-api.service' async function bootstrap() { @@ -26,6 +26,15 @@ async function bootstrap() { const isProduction: boolean = configService.get('NODE_ENV') === 'production' const isTest: boolean = configService.get('NODE_ENV') === 'test' + if ( + isProduction && + configService.get('tokenSecretKey') === DEFAULT_TOKEN_SECRET_KEY + ) { + throw new Error( + 'Token secret key not defined. Please set a custom token secret key to run in production environment adding TOKEN_SECRET_KEY in your env file.' + ) + } + // Reload the browser when server files change. if (!isProduction && !isTest) { const liveReloadServer = livereload.createServer()