@adaptivestone/framework 5.0.0-alpha.7 → 5.0.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ### 5.0.0-alpha.9
2
+
3
+ [UPDATE] update deps
4
+ [BREAKING] removing staticFiles middleware as it not used in projects anymore. Docs with nginx config will be provided
5
+ [BREAKING] remove default AUTH_SALT. It should be provided on a app level now
6
+ [BREAKING] Vitest 2.0.0 https://vitest.dev/guide/migration.html#migrating-to-vitest-2-0
7
+
8
+ ### 5.0.0-alpha.8
9
+
10
+ [UPDATE] replace dotenv with loadEnvFile
11
+ [UPDATE] replace nodemon with node --watch (dev only)
12
+ [BREAKING] Minimum node version is 20.12 as for now (process.loadEnvFile)
13
+
1
14
  ### 5.0.0-alpha.7
2
15
 
3
16
  [UPDATE] deps update
package/config/auth.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export default {
2
2
  hashRounds: 64,
3
- saltSecret: process.env.AUTH_SALT || 'gdfg45667_%%^trterte',
3
+ saltSecret:
4
+ process.env.AUTH_SALT || console.error('AUTH_SALT is not defined'),
4
5
  isAuthWithVefificationFlow: true,
5
6
  };
package/folderConfig.js CHANGED
@@ -6,7 +6,6 @@ export default {
6
6
  models: path.resolve('./models'),
7
7
  controllers: path.resolve('./controllers'),
8
8
  views: path.resolve('./views'),
9
- public: path.resolve('./public'),
10
9
  locales: path.resolve('./locales'),
11
10
  emails: path.resolve('./services/messaging/email/templates'),
12
11
  commands: path.resolve('./commands'),
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@adaptivestone/framework",
3
- "version": "5.0.0-alpha.7",
3
+ "version": "5.0.0-alpha.9",
4
4
  "description": "Adaptive stone node js framework",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "engines": {
8
- "node": ">=18.17.0"
8
+ "node": ">=20.12.0"
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
@@ -13,8 +13,8 @@
13
13
  },
14
14
  "homepage": "https://framework.adaptivestone.com/",
15
15
  "scripts": {
16
- "dev": "nodemon ./index.js",
17
- "prod": "nodemon ./cluster.js",
16
+ "dev": "node --watch ./index.js",
17
+ "prod": "node --watch ./cluster.js",
18
18
  "test": "vitest run",
19
19
  "prettier": "prettier --check '**/*.(js|jsx|ts|tsx|json|css|scss|md)'",
20
20
  "lint": "eslint '**/*.js'",
@@ -30,7 +30,6 @@
30
30
  "license": "MIT",
31
31
  "dependencies": {
32
32
  "deepmerge": "^4.2.2",
33
- "dotenv": "^16.0.0",
34
33
  "express": "^4.17.1",
35
34
  "formidable": "^3.5.1",
36
35
  "html-to-text": "^9.0.3",
@@ -52,18 +51,17 @@
52
51
  "yup": "^1.0.0"
53
52
  },
54
53
  "devDependencies": {
55
- "@vitest/coverage-v8": "^1.0.0",
54
+ "@vitest/coverage-v8": "^2.0.0",
56
55
  "eslint": "^8.0.0",
57
56
  "eslint-config-airbnb-base": "^15.0.0",
58
57
  "eslint-config-prettier": "^9.0.0",
59
58
  "eslint-plugin-prettier": "^5.0.0",
60
- "eslint-plugin-vitest": "^0.3.1",
59
+ "eslint-plugin-vitest": "^0.4.0",
61
60
  "husky": "^9.0.0",
62
61
  "lint-staged": "^15.0.0",
63
62
  "mongodb-memory-server": "^9.0.0",
64
- "nodemon": "^3.0.1",
65
63
  "prettier": "^3.0.0",
66
- "vitest": "^1.0.0"
64
+ "vitest": "^2.0.0"
67
65
  },
68
66
  "lint-staged": {
69
67
  "**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
package/server.js CHANGED
@@ -1,16 +1,21 @@
1
1
  /* eslint-disable no-console */
2
2
  import EventEmitter from 'node:events';
3
- import { hrtime } from 'node:process';
3
+ import { hrtime, loadEnvFile } from 'node:process';
4
4
  import * as url from 'node:url';
5
5
  import path from 'node:path';
6
6
 
7
- import 'dotenv/config';
8
7
  import merge from 'deepmerge';
9
8
  import winston from 'winston';
10
9
  import { getFilesPathWithInheritance } from './helpers/files.js';
11
10
  import { consoleLogger } from './helpers/logger.js';
12
11
  import Cache from './services/cache/Cache.js';
13
12
 
13
+ try {
14
+ loadEnvFile();
15
+ } catch (e) {
16
+ console.warn('No env file found. This is ok. But please check youself.');
17
+ }
18
+
14
19
  /**
15
20
  * Main framework class.
16
21
  */
@@ -29,7 +34,6 @@ class Server {
29
34
  * @param {String} config.folders.models path to folder with moidels files
30
35
  * @param {String} config.folders.controllers path to folder with controllers files
31
36
  * @param {String} config.folders.views path to folder with view files
32
- * @param {String} config.folders.public path to folder with public files
33
37
  * @param {String} config.folders.locales path to folder with locales files
34
38
  * @param {String} config.folders.emails path to folder with emails files
35
39
  */
@@ -6,7 +6,6 @@ import RequestLoggerMiddleware from './middleware/RequestLogger.js';
6
6
  import I18nMiddleware from './middleware/I18n.js';
7
7
  import PrepareAppInfoMiddleware from './middleware/PrepareAppInfo.js';
8
8
  import RequestParserMiddleware from './middleware/RequestParser.js';
9
- import StaticFilesMiddleware from './middleware/StaticFiles.js';
10
9
  import Cors from './middleware/Cors.js';
11
10
  import Base from '../../modules/Base.js';
12
11
 
@@ -35,15 +34,6 @@ class HttpServer extends Base {
35
34
  origins: httpConfig.corsDomains,
36
35
  }).getMiddleware(),
37
36
  );
38
- // todo whitelist
39
- this.express.use(
40
- new StaticFilesMiddleware(this.app, {
41
- folders: [
42
- this.app.foldersConfig.public,
43
- path.join(dirname, '../../public/files'),
44
- ],
45
- }).getMiddleware(),
46
- );
47
37
 
48
38
  this.express.use(new RequestParserMiddleware(this.app).getMiddleware());
49
39
 
package/tests/setup.js CHANGED
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable no-undef */
2
2
  import path from 'node:path';
3
+ import { randomBytes } from 'node:crypto';
3
4
  import { MongoMemoryReplSet } from 'mongodb-memory-server';
4
5
  import mongoose from 'mongoose';
5
6
  import redis from 'redis';
@@ -19,6 +20,8 @@ beforeAll(async () => {
19
20
  });
20
21
  await mongoMemoryServerInstance.waitUntilRunning();
21
22
  process.env.LOGGER_CONSOLE_LEVEL = 'error';
23
+ process.env.AUTH_SALT = randomBytes(16).toString('hex');
24
+
22
25
  const connectionStringMongo = await mongoMemoryServerInstance.getUri();
23
26
  // console.info('MONGO_URI: ', connectionStringMongo);
24
27
  global.server = new Server({
@@ -27,7 +30,6 @@ beforeAll(async () => {
27
30
  controllers:
28
31
  process.env.TEST_FOLDER_CONTROLLERS || path.resolve('./controllers'),
29
32
  views: process.env.TEST_FOLDER_VIEWS || path.resolve('./views'),
30
- public: process.env.TEST_FOLDER_PUBLIC || path.resolve('./public'),
31
33
  models: process.env.TEST_FOLDER_MODELS || path.resolve('./models'),
32
34
  emails:
33
35
  process.env.TEST_FOLDER_EMAIL ||
@@ -12,13 +12,13 @@ mongoose.set('autoIndex', false);
12
12
 
13
13
  beforeAll(async () => {
14
14
  process.env.LOGGER_CONSOLE_LEVEL = 'error';
15
+ process.env.AUTH_SALT = crypto.randomBytes(16).toString('hex');
15
16
  global.server = new Server({
16
17
  folders: {
17
18
  config: process.env.TEST_FOLDER_CONFIG || path.resolve('./config'),
18
19
  controllers:
19
20
  process.env.TEST_FOLDER_CONTROLLERS || path.resolve('./controllers'),
20
21
  views: process.env.TEST_FOLDER_VIEWS || path.resolve('./views'),
21
- public: process.env.TEST_FOLDER_PUBLIC || path.resolve('./public'),
22
22
  models: process.env.TEST_FOLDER_MODELS || path.resolve('./models'),
23
23
  emails:
24
24
  process.env.TEST_FOLDER_EMAIL ||
@@ -3,7 +3,6 @@
3
3
  * @param models path to folder with moidels files
4
4
  * @param controllers path to folder with controllers files
5
5
  * @param views path to folder with view files
6
- * @param public path to folder with public files
7
6
  * @param locales path to folder with locales files
8
7
  * @param emails path to folder with emails files
9
8
  */
@@ -12,7 +11,6 @@ type FolderConfig = {
12
11
  models: string;
13
12
  controllers: string;
14
13
  views: string;
15
- public: string;
16
14
  emails: string;
17
15
  };
18
16
 
@@ -1,59 +0,0 @@
1
- import fsPromises from 'node:fs/promises';
2
- import fs from 'node:fs';
3
- import path from 'node:path';
4
- import mime from 'mime';
5
- import AbstractMiddleware from './AbstractMiddleware.js';
6
- /**
7
- * Middleware for static files
8
- */
9
- class StaticFiles extends AbstractMiddleware {
10
- constructor(app, params) {
11
- super(app);
12
- this.params = params;
13
- if (!params || !params.folders || !params.folders.length) {
14
- throw new Error('StaticFiles inited without folders config');
15
- }
16
- }
17
-
18
- static get description() {
19
- return 'Static file server middleware. Host you static files from public foolder. Mostly for dev.';
20
- }
21
-
22
- async middleware(req, res, next) {
23
- if (req.method !== 'GET') {
24
- // only get supported
25
- return next();
26
- }
27
- const { folders } = this.params;
28
-
29
- const promises = [];
30
-
31
- for (const f of folders) {
32
- const filePath = path.join(f, req.url);
33
- promises.push(
34
- fsPromises
35
- .stat(filePath)
36
- .catch(() => {
37
- // nothing there, file just not exists
38
- })
39
- .then((stats) => ({ stats, file: filePath })),
40
- );
41
- }
42
-
43
- const fileStats = await Promise.all(promises);
44
-
45
- for (const fileStat of fileStats) {
46
- if (fileStat.stats && fileStat.stats.isFile()) {
47
- const contentType = mime.getType(fileStat.file);
48
- const fileStream = fs.createReadStream(fileStat.file);
49
- res.set('Content-Type', contentType);
50
- fileStream.pipe(res);
51
- return null;
52
- }
53
- }
54
-
55
- return next();
56
- }
57
- }
58
-
59
- export default StaticFiles;