@adaptivestone/framework 5.0.0-alpha.8 → 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,10 @@
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
+
1
8
  ### 5.0.0-alpha.8
2
9
 
3
10
  [UPDATE] replace dotenv with loadEnvFile
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaptivestone/framework",
3
- "version": "5.0.0-alpha.8",
3
+ "version": "5.0.0-alpha.9",
4
4
  "description": "Adaptive stone node js framework",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -51,7 +51,7 @@
51
51
  "yup": "^1.0.0"
52
52
  },
53
53
  "devDependencies": {
54
- "@vitest/coverage-v8": "^1.0.0",
54
+ "@vitest/coverage-v8": "^2.0.0",
55
55
  "eslint": "^8.0.0",
56
56
  "eslint-config-airbnb-base": "^15.0.0",
57
57
  "eslint-config-prettier": "^9.0.0",
@@ -61,7 +61,7 @@
61
61
  "lint-staged": "^15.0.0",
62
62
  "mongodb-memory-server": "^9.0.0",
63
63
  "prettier": "^3.0.0",
64
- "vitest": "^1.0.0"
64
+ "vitest": "^2.0.0"
65
65
  },
66
66
  "lint-staged": {
67
67
  "**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
package/server.js CHANGED
@@ -34,7 +34,6 @@ class Server {
34
34
  * @param {String} config.folders.models path to folder with moidels files
35
35
  * @param {String} config.folders.controllers path to folder with controllers files
36
36
  * @param {String} config.folders.views path to folder with view files
37
- * @param {String} config.folders.public path to folder with public files
38
37
  * @param {String} config.folders.locales path to folder with locales files
39
38
  * @param {String} config.folders.emails path to folder with emails files
40
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;