@vulkano/core 1.17.1 → 1.17.3

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.
@@ -9,6 +9,7 @@
9
9
 
10
10
  const fs = require('fs');
11
11
  const path = require('path');
12
+ const readline = require('readline');
12
13
 
13
14
  // npm sets INIT_CWD to the directory where `npm install` was invoked.
14
15
  // npm_config_local_prefix is the project root (directory containing node_modules).
@@ -23,7 +24,7 @@ if (projectRoot === coreRoot) {
23
24
  process.exit(0);
24
25
  }
25
26
 
26
- const appDir = path.join(projectRoot, 'app');
27
+ const appDir = path.join(projectRoot, 'app');
27
28
  const vulkanoDir = path.join(projectRoot, 'vulkano');
28
29
 
29
30
  if (fs.existsSync(appDir) || fs.existsSync(vulkanoDir)) {
@@ -31,52 +32,31 @@ if (fs.existsSync(appDir) || fs.existsSync(vulkanoDir)) {
31
32
  process.exit(0);
32
33
  }
33
34
 
34
- // ─────────────────────────────────────────────
35
- // Prompt
36
- // ─────────────────────────────────────────────
37
-
38
- const readline = require('readline');
39
-
40
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
41
-
42
- rl.question('\n 🌋 Vulkano: Would you like to scaffold a new project? (Y/n) ', (answer) => {
43
-
44
- rl.close();
45
-
46
- if (answer.trim().toLowerCase() === 'n') {
47
- console.log('\n Skipped. You can scaffold manually at any time.\n');
48
- process.exit(0);
49
- }
50
-
51
- scaffold();
52
-
53
- });
54
-
55
35
  // ─────────────────────────────────────────────
56
36
  // Scaffold
57
37
  // ─────────────────────────────────────────────
58
38
 
59
39
  function scaffold() {
60
40
 
61
- function write(relPath, content) {
62
- const abs = path.join(appDir, relPath);
63
- fs.mkdirSync(path.dirname(abs), { recursive: true });
64
- if (!fs.existsSync(abs)) {
65
- fs.writeFileSync(abs, content, 'utf8');
41
+ function write(relPath, content) {
42
+ const abs = path.join(appDir, relPath);
43
+ fs.mkdirSync(path.dirname(abs), { recursive: true });
44
+ if (!fs.existsSync(abs)) {
45
+ fs.writeFileSync(abs, content, 'utf8');
46
+ }
66
47
  }
67
- }
68
48
 
69
- function dir(relPath) {
70
- const abs = path.join(appDir, relPath);
71
- fs.mkdirSync(abs, { recursive: true });
72
- const keep = path.join(abs, '.gitkeep');
73
- if (!fs.existsSync(keep)) fs.writeFileSync(keep, '', 'utf8');
74
- }
49
+ function dir(relPath) {
50
+ const abs = path.join(appDir, relPath);
51
+ fs.mkdirSync(abs, { recursive: true });
52
+ const keep = path.join(abs, '.gitkeep');
53
+ if (!fs.existsSync(keep)) fs.writeFileSync(keep, '', 'utf8');
54
+ }
75
55
 
76
- // ─────────────────────────────────────────────
77
- // app/config/bootstrap.js (required by Vulkano)
78
- // ─────────────────────────────────────────────
79
- write('config/bootstrap.js', `/**
56
+ // ─────────────────────────────────────────────
57
+ // app/config/bootstrap.js (required by Vulkano)
58
+ // ─────────────────────────────────────────────
59
+ write('config/bootstrap.js', `/**
80
60
  * Bootstrap — called once the server is ready to start.
81
61
  * @param {Function} cb Call cb() to finish startup
82
62
  */
@@ -89,10 +69,10 @@ module.exports = (cb) => {
89
69
  };
90
70
  `);
91
71
 
92
- // ─────────────────────────────────────────────
93
- // app/config/settings.js
94
- // ─────────────────────────────────────────────
95
- write('config/settings.js', `/**
72
+ // ─────────────────────────────────────────────
73
+ // app/config/settings.js
74
+ // ─────────────────────────────────────────────
75
+ write('config/settings.js', `/**
96
76
  * Application settings
97
77
  */
98
78
  module.exports = {
@@ -112,10 +92,10 @@ module.exports = {
112
92
  };
113
93
  `);
114
94
 
115
- // ─────────────────────────────────────────────
116
- // app/config/connections.js
117
- // ─────────────────────────────────────────────
118
- write('config/connections.js', `/**
95
+ // ─────────────────────────────────────────────
96
+ // app/config/connections.js
97
+ // ─────────────────────────────────────────────
98
+ write('config/connections.js', `/**
119
99
  * Database connections
120
100
  * The key here is referenced from settings.js → database.connection
121
101
  */
@@ -126,10 +106,10 @@ module.exports = {
126
106
  };
127
107
  `);
128
108
 
129
- // ─────────────────────────────────────────────
130
- // app/config/routes.js
131
- // ─────────────────────────────────────────────
132
- write('config/routes.js', `/**
109
+ // ─────────────────────────────────────────────
110
+ // app/config/routes.js
111
+ // ─────────────────────────────────────────────
112
+ write('config/routes.js', `/**
133
113
  * Explicit routes (optional)
134
114
  * Format: 'METHOD /path': 'ControllerName.action'
135
115
  *
@@ -153,10 +133,10 @@ module.exports = {
153
133
  };
154
134
  `);
155
135
 
156
- // ─────────────────────────────────────────────
157
- // app/config/express/settings.js
158
- // ─────────────────────────────────────────────
159
- write('config/express/settings.js', `/**
136
+ // ─────────────────────────────────────────────
137
+ // app/config/express/settings.js
138
+ // ─────────────────────────────────────────────
139
+ write('config/express/settings.js', `/**
160
140
  * Express server settings
161
141
  */
162
142
  module.exports = {
@@ -177,10 +157,10 @@ module.exports = {
177
157
  };
178
158
  `);
179
159
 
180
- // ─────────────────────────────────────────────
181
- // app/config/express/cors.js
182
- // ─────────────────────────────────────────────
183
- write('config/express/cors.js', `/**
160
+ // ─────────────────────────────────────────────
161
+ // app/config/express/cors.js
162
+ // ─────────────────────────────────────────────
163
+ write('config/express/cors.js', `/**
184
164
  * CORS configuration
185
165
  */
186
166
  module.exports = {
@@ -200,10 +180,10 @@ module.exports = {
200
180
  };
201
181
  `);
202
182
 
203
- // ─────────────────────────────────────────────
204
- // app/config/express/jwt.js
205
- // ─────────────────────────────────────────────
206
- write('config/express/jwt.js', `/**
183
+ // ─────────────────────────────────────────────
184
+ // app/config/express/jwt.js
185
+ // ─────────────────────────────────────────────
186
+ write('config/express/jwt.js', `/**
207
187
  * JWT authentication middleware
208
188
  */
209
189
  module.exports = {
@@ -265,10 +245,10 @@ module.exports = {
265
245
  };
266
246
  `);
267
247
 
268
- // ─────────────────────────────────────────────
269
- // app/config/express/cookies.js
270
- // ─────────────────────────────────────────────
271
- write('config/express/cookies.js', `/**
248
+ // ─────────────────────────────────────────────
249
+ // app/config/express/cookies.js
250
+ // ─────────────────────────────────────────────
251
+ write('config/express/cookies.js', `/**
272
252
  * Cookie parser
273
253
  */
274
254
  module.exports = {
@@ -287,10 +267,10 @@ module.exports = {
287
267
  };
288
268
  `);
289
269
 
290
- // ─────────────────────────────────────────────
291
- // app/config/encryption.js
292
- // ─────────────────────────────────────────────
293
- write('config/encryption.js', `/**
270
+ // ─────────────────────────────────────────────
271
+ // app/config/encryption.js
272
+ // ─────────────────────────────────────────────
273
+ write('config/encryption.js', `/**
294
274
  * Encryption settings (used by Encrypter)
295
275
  */
296
276
  module.exports = {
@@ -307,10 +287,10 @@ module.exports = {
307
287
  };
308
288
  `);
309
289
 
310
- // ─────────────────────────────────────────────
311
- // app/controllers/HomeController.js
312
- // ─────────────────────────────────────────────
313
- write('controllers/HomeController.js', `/**
290
+ // ─────────────────────────────────────────────
291
+ // app/controllers/HomeController.js
292
+ // ─────────────────────────────────────────────
293
+ write('controllers/HomeController.js', `/**
314
294
  * HomeController
315
295
  * Convention-based routes → GET /home/, GET /home/:id, POST /home/save, etc.
316
296
  *
@@ -327,21 +307,21 @@ module.exports = {
327
307
  };
328
308
  `);
329
309
 
330
- // ─────────────────────────────────────────────
331
- // Empty placeholder directories
332
- // ─────────────────────────────────────────────
333
- dir('models');
334
- dir('services');
335
- dir('responses');
336
-
337
- // ─────────────────────────────────────────────
338
- // app/views structure
339
- // ─────────────────────────────────────────────
340
- dir('views/home');
341
- dir('views/_shared/errors');
342
- dir('views/_shared/templates');
343
-
344
- write('views/_shared/templates/default.html', `<!DOCTYPE html>
310
+ // ─────────────────────────────────────────────
311
+ // Empty placeholder directories
312
+ // ─────────────────────────────────────────────
313
+ dir('models');
314
+ dir('services');
315
+ dir('responses');
316
+
317
+ // ─────────────────────────────────────────────
318
+ // app/views structure
319
+ // ─────────────────────────────────────────────
320
+ dir('views/home');
321
+ dir('views/_shared/errors');
322
+ dir('views/_shared/templates');
323
+
324
+ write('views/_shared/templates/default.html', `<!DOCTYPE html>
345
325
  <html lang="en">
346
326
  <head>
347
327
  <meta charset="UTF-8">
@@ -358,7 +338,7 @@ write('views/_shared/templates/default.html', `<!DOCTYPE html>
358
338
  </html>
359
339
  `);
360
340
 
361
- write('views/home/index.html', `{% extends "_shared/templates/default.html" %}
341
+ write('views/home/index.html', `{% extends "_shared/templates/default.html" %}
362
342
 
363
343
  {% block title %}Home — Vulkano{% endblock %}
364
344
 
@@ -367,7 +347,7 @@ write('views/home/index.html', `{% extends "_shared/templates/default.html" %}
367
347
  {% endblock %}
368
348
  `);
369
349
 
370
- write('views/_shared/errors/404.html', `<!DOCTYPE html>
350
+ write('views/_shared/errors/404.html', `<!DOCTYPE html>
371
351
  <html lang="en">
372
352
  <head>
373
353
  <meta charset="UTF-8">
@@ -379,7 +359,7 @@ write('views/_shared/errors/404.html', `<!DOCTYPE html>
379
359
  </html>
380
360
  `);
381
361
 
382
- write('views/_shared/errors/500.html', `<!DOCTYPE html>
362
+ write('views/_shared/errors/500.html', `<!DOCTYPE html>
383
363
  <html lang="en">
384
364
  <head>
385
365
  <meta charset="UTF-8">
@@ -391,59 +371,78 @@ write('views/_shared/errors/500.html', `<!DOCTYPE html>
391
371
  </html>
392
372
  `);
393
373
 
394
- // public/files for multer uploads
395
- const publicFiles = path.join(projectRoot, 'public', 'files');
396
- fs.mkdirSync(publicFiles, { recursive: true });
397
-
398
- // public/css for css files
399
- const publicCss = path.join(projectRoot, 'public', 'css');
400
- fs.mkdirSync(publicCss, { recursive: true });
401
-
402
- // public/js for js files
403
- const publicJs = path.join(projectRoot, 'public', 'js');
404
- fs.mkdirSync(publicJs, { recursive: true });
405
-
406
- // public/img for image files
407
- const publicImg = path.join(projectRoot, 'public', 'img');
408
- fs.mkdirSync(publicImg, { recursive: true });
409
-
410
- // public/fonts for font files
411
- const publicFonts = path.join(projectRoot, 'public', 'fonts');
412
- fs.mkdirSync(publicFonts, { recursive: true });
413
-
414
- // .env example
415
- const envExample = path.join(projectRoot, '.env');
416
- if (!fs.existsSync(envExample)) {
417
- fs.writeFileSync(envExample, [
418
- '# Copy to .env and fill in your values',
419
- 'PORT=8000',
420
- 'MONGO_URI=',
421
- 'JWT_SECRET=',
422
- 'COOKIE_SECRET=',
423
- 'ENCRYPTION_KEY=',
424
- 'ENCRYPTION_SALT=salt',
425
- 'ENCRYPTION_ALGORITHM=aes-256-cbc',
426
- ''
427
- ].join('\n'), 'utf8');
428
- }
374
+ // public/files for multer uploads
375
+ const publicFiles = path.join(projectRoot, 'public', 'files');
376
+ fs.mkdirSync(publicFiles, { recursive: true });
377
+
378
+ // public/css for css files
379
+ const publicCss = path.join(projectRoot, 'public', 'css');
380
+ fs.mkdirSync(publicCss, { recursive: true });
381
+
382
+ // public/js for js files
383
+ const publicJs = path.join(projectRoot, 'public', 'js');
384
+ fs.mkdirSync(publicJs, { recursive: true });
385
+
386
+ // public/img for image files
387
+ const publicImg = path.join(projectRoot, 'public', 'img');
388
+ fs.mkdirSync(publicImg, { recursive: true });
389
+
390
+ // public/fonts for font files
391
+ const publicFonts = path.join(projectRoot, 'public', 'fonts');
392
+ fs.mkdirSync(publicFonts, { recursive: true });
393
+
394
+ // .env example
395
+ const envExample = path.join(projectRoot, '.env');
396
+ if (!fs.existsSync(envExample)) {
397
+ fs.writeFileSync(envExample, [
398
+ '# Copy to .env and fill in your values',
399
+ 'PORT=8000',
400
+ 'MONGO_URI=',
401
+ 'JWT_SECRET=',
402
+ 'COOKIE_SECRET=',
403
+ 'ENCRYPTION_KEY=',
404
+ 'ENCRYPTION_SALT=salt',
405
+ 'ENCRYPTION_ALGORITHM=aes-256-cbc',
406
+ ''
407
+ ].join('\n'), 'utf8');
408
+ }
409
+
410
+ console.log([
411
+ '',
412
+ ' ✔ Vulkano scaffold created:',
413
+ ' app/config/ ← settings, connections, routes, express, jwt…',
414
+ ' app/controllers/ ← HomeController.js',
415
+ ' app/models/ ← (empty — add your models here)',
416
+ ' app/services/ ← (empty — add your services here)',
417
+ ' app/views/ ← home/index.html, _shared/templates/default.html, errors/404, 500',
418
+ ' public/css/ ← css files',
419
+ ' public/js/ ← js files',
420
+ ' public/img/ ← image files',
421
+ ' public/fonts/ ← font files',
422
+ ' .env ← fill in values',
423
+ '',
424
+ ' Next steps:',
425
+ ' 1. Set MONGO_URI, JWT_SECRET, etc.',
426
+ '',
427
+ ].join('\n'));
428
+
429
+ } // end scaffold()
429
430
 
430
- console.log([
431
- '',
432
- ' ✔ Vulkano scaffold created:',
433
- ' app/config/ ← settings, connections, routes, express, jwt…',
434
- ' app/controllers/ ← HomeController.js',
435
- ' app/models/ ← (empty — add your models here)',
436
- ' app/services/ ← (empty add your services here)',
437
- ' app/views/ ← home/index.html, _shared/templates/default.html, errors/404, 500',
438
- ' public/css/ ← css files',
439
- ' public/js/ ← js files',
440
- ' public/img/ ← image files',
441
- ' public/fonts/ ← font files',
442
- ' .env ← fill in values',
443
- '',
444
- ' Next steps:',
445
- ' 1. Set MONGO_URI, JWT_SECRET, etc.',
446
- '',
447
- ].join('\n'));
448
-
449
- } // end scaffold()
431
+ // ─────────────────────────────────────────────
432
+ // Prompt
433
+ // ─────────────────────────────────────────────
434
+
435
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
436
+
437
+ rl.question('\n 🌋 Vulkano: Would you like to scaffold a new project? (Y/n) ', (answer) => {
438
+
439
+ rl.close();
440
+
441
+ if (answer.trim().toLowerCase() === 'n') {
442
+ console.log('\n Skipped. You can scaffold manually at any time.\n');
443
+ process.exit(0);
444
+ }
445
+
446
+ scaffold();
447
+
448
+ });
@@ -190,9 +190,10 @@ module.exports = function loadServer() {
190
190
  vulkano.use(timeout( expressConfig.timeout || 120000 ));
191
191
 
192
192
  vulkano.use( (req, res, next) => {
193
- if (!req.timedout) {
194
- next();
193
+ if (req.timedout) {
194
+ return res.status(503).json({ success: false, statusCode: 503, error: { detail: 'Request timeout' } });
195
195
  }
196
+ next();
196
197
  });
197
198
 
198
199
  // ---------------
@@ -660,6 +661,11 @@ module.exports = function loadServer() {
660
661
  return;
661
662
  }
662
663
 
664
+ // Timeout — always respond with JSON regardless of request type
665
+ if (req.timedout || (err && err.timeout)) {
666
+ return res.status(503).json({ success: false, statusCode: 503, error: { detail: 'Request timeout' } });
667
+ }
668
+
663
669
  const status = err ? (err.status || 500) : (res.statusCode || 500);
664
670
 
665
671
  res.status(status);
@@ -871,6 +877,9 @@ module.exports = function loadServer() {
871
877
  (pubClient ? pubClient.connect() : null),
872
878
  (subClient ? subClient.connect() : null)
873
879
  ])
880
+ .catch((err) => {
881
+ throw new Error(`Socket Redis adapter failed to connect: ${err.message}`);
882
+ })
874
883
  .then(() => {
875
884
 
876
885
  io.on('connection', (socket) => {
@@ -97,10 +97,12 @@ module.exports = {
97
97
  });
98
98
  }
99
99
 
100
+ // Two queries by design: fetch the full document first so subdocument arrays
101
+ // and nested fields are preserved in the write — a bare $set would drop
102
+ // any subdoc entries not included in the incoming payload.
100
103
  return this.getByField(_id)
101
104
  .then( (record) => {
102
105
 
103
- // Merge current info with incoming values
104
106
  const merged = {
105
107
  ...record,
106
108
  ...filtered,
package/libs/Jwt.js CHANGED
@@ -122,12 +122,16 @@ module.exports = {
122
122
  */
123
123
  decode(token, customKey) {
124
124
 
125
+ if (!token) {
126
+ return null;
127
+ }
128
+
125
129
  const {
126
130
  key,
127
131
  expiration: allowExpiration
128
132
  } = this.getConfig();
129
133
 
130
- let data = {};
134
+ let data = null;
131
135
 
132
136
  try {
133
137
 
@@ -135,12 +139,16 @@ module.exports = {
135
139
  data = this.decrypt(payload);
136
140
 
137
141
  } catch (e) {
138
- console.log('Invalid Token');
142
+ // invalid token
143
+ }
144
+
145
+ if (!data) {
146
+ return null;
139
147
  }
140
148
 
141
149
  const {
142
150
  expiration
143
- } = data || {};
151
+ } = data;
144
152
 
145
153
  const now = String(Date.now());
146
154
 
@@ -149,14 +157,13 @@ module.exports = {
149
157
  return null;
150
158
  }
151
159
 
152
- // Ignore expiration field
160
+ // Ignore expiration requirement
153
161
  if (allowExpiration === false) {
154
162
  return data;
155
163
  }
156
164
 
157
- // Expiration must be required
165
+ // Expiration field is required
158
166
  if (!expiration) {
159
- console.log('JWT Without expiration date');
160
167
  return null;
161
168
  }
162
169
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulkano/core",
3
- "version": "1.17.1",
3
+ "version": "1.17.3",
4
4
  "description": "A MVC framework using Express 4",
5
5
  "license": "MIT",
6
6
  "author": "Vulkano Team",
@@ -54,6 +54,7 @@
54
54
  "nunjucks": "^3.2.4",
55
55
  "redis": "^5.12.1",
56
56
  "socket.io": "^4.8.1",
57
+ "socket.io-adapter": "^2.5.6",
57
58
  "undici": "^6.25.0"
58
59
  },
59
60
  "devDependencies": {