underpost 2.8.452 → 2.8.481

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.
@@ -3,7 +3,10 @@ import { Account } from './Account.js';
3
3
  import { loggerFactory } from './Logger.js';
4
4
  import { LogIn } from './LogIn.js';
5
5
  import { LogOut } from './LogOut.js';
6
+ import { NotificationManager } from './NotificationManager.js';
6
7
  import { SignUp } from './SignUp.js';
8
+ import { Translate } from './Translate.js';
9
+ import { s } from './VanillaJs.js';
7
10
 
8
11
  const logger = loggerFactory(import.meta);
9
12
 
@@ -65,6 +68,7 @@ const Auth = {
65
68
  const _result = await UserService.get({ id: 'auth' });
66
69
  return {
67
70
  status: _result.status,
71
+ message: _result.message,
68
72
  data: {
69
73
  user: _result.data,
70
74
  },
@@ -77,6 +81,15 @@ const Auth = {
77
81
  await Account.updateForm(data.user);
78
82
  return { user: data.user };
79
83
  }
84
+ if (message && message.match('expired'))
85
+ setTimeout(() => {
86
+ s(`.main-btn-log-in`).click();
87
+ NotificationManager.Push({
88
+ html: Translate.Render(`expired-session`),
89
+ status: 'warning',
90
+ });
91
+ });
92
+ return await Auth.sessionOut();
80
93
  }
81
94
 
82
95
  // anon guest session
@@ -92,20 +105,25 @@ const Auth = {
92
105
 
93
106
  this.setGuestToken(guestToken);
94
107
  let { data, status, message } = await UserService.get({ id: 'auth' });
95
- if (status === 'error') throw new Error(message);
108
+ if (status === 'error') {
109
+ if (message && message.match('expired')) {
110
+ localStorage.removeItem('jwt.g');
111
+ return await Auth.sessionOut();
112
+ } else throw new Error(message);
113
+ }
96
114
  await Account.updateForm(data);
97
115
  return { user: data };
98
116
  } catch (error) {
99
117
  logger.error(error);
100
- localStorage.removeItem('jwt');
101
- localStorage.removeItem('jwt.g');
102
118
  return { user: UserMock.default };
103
119
  }
104
120
  },
105
121
  sessionOut: async function () {
106
122
  this.deleteToken();
107
123
  localStorage.removeItem('jwt');
108
- await LogOut.Trigger(await this.sessionIn());
124
+ const result = await this.sessionIn();
125
+ await LogOut.Trigger(result);
126
+ return result;
109
127
  },
110
128
  };
111
129
 
@@ -573,6 +573,14 @@ const isValidFormat = (value, format) => {
573
573
  }
574
574
  };
575
575
 
576
+ const getCurrentTrace = () => {
577
+ try {
578
+ _stack;
579
+ } catch (error) {
580
+ return error.stack.split('is not defined')[1];
581
+ }
582
+ };
583
+
576
584
  /**
577
585
  * Returns the time difference between UTC time and local time, in minutes.
578
586
  * @memberof CommonJS
@@ -943,6 +951,7 @@ export {
943
951
  commonAdminGuard,
944
952
  commonModeratorGuard,
945
953
  isChileanIdentityDocument,
954
+ getCurrentTrace,
946
955
  userRoleEnum,
947
956
  commitData,
948
957
  };
@@ -9,7 +9,6 @@ import {
9
9
  htmls,
10
10
  sa,
11
11
  getAllChildNodes,
12
- getCurrentTrace,
13
12
  isActiveElement,
14
13
  } from './VanillaJs.js';
15
14
  import { BtnIcon } from './BtnIcon.js';
@@ -508,6 +508,10 @@ const TranslateCore = {
508
508
  en: 'Invalid identity document',
509
509
  es: 'Documento de identidad inválido',
510
510
  };
511
+ Translate.Data['expired-session'] = {
512
+ en: 'Your session has expired. Please log in again.',
513
+ es: 'Su sesión ha expirado. Por favor, inicie sesión de nuevo.',
514
+ };
511
515
  },
512
516
  };
513
517
 
@@ -419,14 +419,6 @@ const isActiveTab = () => document.hasFocus();
419
419
  const isActiveElement = (classSearch = '') =>
420
420
  document.activeElement?.classList?.value?.match(classSearch) ? true : false;
421
421
 
422
- const getCurrentTrace = () => {
423
- try {
424
- _stack;
425
- } catch (error) {
426
- return error.stack.split('is not defined')[1];
427
- }
428
- };
429
-
430
422
  const isDevInstance = () => location.origin.match('localhost') && location.port;
431
423
 
432
424
  const getDataFromInputFile = async (file) => Array.from(new Uint8Array(await file.arrayBuffer()));
@@ -460,7 +452,6 @@ export {
460
452
  isNavigator,
461
453
  getTimeZone,
462
454
  getAllChildNodes,
463
- getCurrentTrace,
464
455
  isActiveTab,
465
456
  isActiveElement,
466
457
  isDevInstance,
@@ -22,41 +22,44 @@ const Worker = {
22
22
  setTimeout(() => {
23
23
  if ('onLine' in navigator && navigator.onLine) window.ononline();
24
24
  });
25
- navigator.serviceWorker.addEventListener('controllerchange', () => {
26
- logger.info('The controller of current browsing context has changed.');
27
- });
28
- navigator.serviceWorker.ready.then((worker) => {
29
- logger.info('Ready', worker);
30
- // event message
31
- navigator.serviceWorker.addEventListener('message', (event) => {
32
- logger.info('Received event message', event.data);
33
- const { status } = event.data;
25
+ if ('serviceWorker' in navigator) {
26
+ navigator.serviceWorker.addEventListener('controllerchange', () => {
27
+ logger.info('The controller of current browsing context has changed.');
28
+ });
29
+ navigator.serviceWorker.ready.then((worker) => {
30
+ logger.info('Ready', worker);
31
+ // event message
32
+ navigator.serviceWorker.addEventListener('message', (event) => {
33
+ logger.info('Received event message', event.data);
34
+ const { status } = event.data;
34
35
 
35
- switch (status) {
36
- case 'loader':
37
- {
38
- LoadingAnimation.RenderCurrentSrcLoad(event);
39
- }
40
- break;
36
+ switch (status) {
37
+ case 'loader':
38
+ {
39
+ LoadingAnimation.RenderCurrentSrcLoad(event);
40
+ }
41
+ break;
41
42
 
42
- default:
43
- break;
44
- }
45
- });
43
+ default:
44
+ break;
45
+ }
46
+ });
46
47
 
47
- // if (navigator.serviceWorker.controller)
48
- // navigator.serviceWorker.controller.postMessage({
49
- // title: 'Hello from Client event message',
50
- // });
48
+ // if (navigator.serviceWorker.controller)
49
+ // navigator.serviceWorker.controller.postMessage({
50
+ // title: 'Hello from Client event message',
51
+ // });
52
+
53
+ // broadcast message
54
+ // const channel = new BroadcastChannel('sw-messages');
55
+ // channel.addEventListener('message', (event) => {
56
+ // logger.info('Received broadcast message', event.data);
57
+ // });
58
+ // channel.postMessage({ title: 'Hello from Client broadcast message' });
59
+ // channel.close();
60
+ });
61
+ }
51
62
 
52
- // broadcast message
53
- // const channel = new BroadcastChannel('sw-messages');
54
- // channel.addEventListener('message', (event) => {
55
- // logger.info('Received broadcast message', event.data);
56
- // });
57
- // channel.postMessage({ title: 'Hello from Client broadcast message' });
58
- // channel.close();
59
- });
60
63
  this.RouterInstance = router();
61
64
  const isInstall = await this.status();
62
65
  if (!isInstall) await this.install();
package/src/index.js CHANGED
@@ -5,6 +5,8 @@
5
5
  */
6
6
 
7
7
  import UnderpostCluster from './cli/cluster.js';
8
+ import UnderpostDB from './cli/db.js';
9
+ import UnderpostDeploy from './cli/deploy.js';
8
10
  import UnderpostRootEnv from './cli/env.js';
9
11
  import UnderpostImage from './cli/image.js';
10
12
  import UnderpostRepository from './cli/repository.js';
@@ -24,7 +26,7 @@ class Underpost {
24
26
  * @type {String}
25
27
  * @memberof Underpost
26
28
  */
27
- static version = 'v2.8.452';
29
+ static version = 'v2.8.481';
28
30
  /**
29
31
  * Repository cli API
30
32
  * @static
@@ -74,6 +76,20 @@ class Underpost {
74
76
  * @memberof Underpost
75
77
  */
76
78
  static script = UnderpostScript.API;
79
+ /**
80
+ * Database cli API
81
+ * @static
82
+ * @type {UnderpostDB.API}
83
+ * @memberof Underpost
84
+ */
85
+ static db = UnderpostDB.API;
86
+ /**
87
+ * Deployment cli API
88
+ * @static
89
+ * @type {UnderpostDeploy.API}
90
+ * @memberof Underpost
91
+ */
92
+ static deploy = UnderpostDeploy.API;
77
93
  }
78
94
 
79
95
  const up = Underpost;
@@ -40,21 +40,26 @@ const logger = loggerFactory(import.meta);
40
40
 
41
41
  const Config = {
42
42
  default: DefaultConf,
43
- build: async function (options = { folder: '' }) {
43
+ build: async function (options = { folder: '' }, deployContext, deployList, subConf) {
44
+ if (!deployContext) deployContext = process.argv[2];
44
45
  if (!fs.existsSync(`./tmp`)) fs.mkdirSync(`./tmp`, { recursive: true });
45
46
  fs.writeFileSync(`./tmp/await-deploy`, '', 'utf8');
46
- if (fs.existsSync(`./engine-private/conf/${process.argv[2]}`)) return loadConf(process.argv[2]);
47
- if (fs.existsSync(`./engine-private/replica/${process.argv[2]}`)) return loadConf(process.argv[2]);
47
+ if (fs.existsSync(`./engine-private/conf/${deployContext}`))
48
+ return loadConf(deployContext, process.env.NODE_ENV, subConf);
49
+ if (fs.existsSync(`./engine-private/replica/${deployContext}`))
50
+ return loadConf(deployContext, process.env.NODE_ENV, subConf);
48
51
 
49
- if (process.argv[2] === 'deploy') return;
52
+ if (deployContext === 'deploy') return;
50
53
 
51
- if (process.argv[2] === 'proxy') {
54
+ if (deployContext === 'proxy') {
55
+ if (!deployList) deployList = process.argv[3];
56
+ if (!subConf) subConf = process.argv[4];
52
57
  this.default.server = {};
53
- for (const deployId of process.argv[3].split(',')) {
58
+ for (const deployId of deployList.split(',')) {
54
59
  let confPath = `./engine-private/conf/${deployId}/conf.server.json`;
55
60
  const privateConfDevPath = fs.existsSync(`./engine-private/replica/${deployId}/conf.server.json`)
56
61
  ? `./engine-private/replica/${deployId}/conf.server.json`
57
- : `./engine-private/conf/${deployId}/conf.server.dev.${process.argv[4]}.json`;
62
+ : `./engine-private/conf/${deployId}/conf.server.dev.${subConf}.json`;
58
63
  const confDevPath = fs.existsSync(privateConfDevPath)
59
64
  ? privateConfDevPath
60
65
  : `./engine-private/conf/${deployId}/conf.server.dev.json`;
@@ -62,7 +67,7 @@ const Config = {
62
67
  if (process.env.NODE_ENV === 'development' && fs.existsSync(confDevPath)) confPath = confDevPath;
63
68
  const serverConf = JSON.parse(fs.readFileSync(confPath, 'utf8'));
64
69
 
65
- for (const host of Object.keys(loadReplicas(serverConf))) {
70
+ for (const host of Object.keys(loadReplicas(serverConf, deployContext, subConf))) {
66
71
  if (serverConf[host]['/'])
67
72
  this.default.server[host] = {
68
73
  ...this.default.server[host],
@@ -92,7 +97,7 @@ const Config = {
92
97
  },
93
98
  };
94
99
 
95
- const loadConf = (deployId, envInput) => {
100
+ const loadConf = (deployId, envInput, subConf) => {
96
101
  const folder = fs.existsSync(`./engine-private/replica/${deployId}`)
97
102
  ? `./engine-private/replica/${deployId}`
98
103
  : `./engine-private/conf/${deployId}`;
@@ -109,7 +114,8 @@ const loadConf = (deployId, envInput) => {
109
114
  ? fs.readFileSync(`${folder}/conf.${typeConf}.json`, 'utf8')
110
115
  : JSON.stringify(Config.default[typeConf]);
111
116
  if (process.env.NODE_ENV === 'development' && typeConf === 'server') {
112
- const devConfPath = `${folder}/conf.${typeConf}.dev${process.argv[3] ? `.${process.argv[3]}` : ''}.json`;
117
+ if (!subConf) subConf = process.argv[3];
118
+ const devConfPath = `${folder}/conf.${typeConf}.dev${subConf ? `.${subConf}` : ''}.json`;
113
119
  if (fs.existsSync(devConfPath)) srcConf = fs.readFileSync(devConfPath, 'utf8');
114
120
  }
115
121
  if (typeConf === 'server') srcConf = JSON.stringify(loadReplicas(JSON.parse(srcConf)), null, 4);
@@ -135,15 +141,17 @@ const loadConf = (deployId, envInput) => {
135
141
  return { folder, deployId };
136
142
  };
137
143
 
138
- const loadReplicas = (confServer) => {
144
+ const loadReplicas = (confServer, deployContext, subConf) => {
145
+ if (!deployContext) deployContext = process.argv[2];
146
+ if (!subConf) subConf = process.argv[3];
139
147
  for (const host of Object.keys(confServer)) {
140
148
  for (const path of Object.keys(confServer[host])) {
141
149
  const { replicas, singleReplica } = confServer[host][path];
142
150
  if (
143
151
  replicas &&
144
- (process.argv[2] === 'proxy' ||
152
+ (deployContext === 'proxy' ||
145
153
  !singleReplica ||
146
- (singleReplica && process.env.NODE_ENV === 'development' && !process.argv[3]))
154
+ (singleReplica && process.env.NODE_ENV === 'development' && !subConf))
147
155
  )
148
156
  for (const replicaPath of replicas) {
149
157
  confServer[host][replicaPath] = newInstance(confServer[host][path]);
@@ -513,14 +521,16 @@ const buildPortProxyRouter = (port, proxyRouter) => {
513
521
  // build router
514
522
  Object.keys(hosts).map((hostKey) => {
515
523
  let { host, path, target, proxy, peer } = hosts[hostKey];
516
- if (process.env.NODE_ENV === 'development') host = `localhost`;
524
+ if (process.argv.includes('localhost') && process.env.NODE_ENV === 'development') host = `localhost`;
517
525
 
518
526
  if (!proxy.includes(port)) return;
519
527
  const absoluteHost = [80, 443].includes(port)
520
528
  ? `${host}${path === '/' ? '' : path}`
521
529
  : `${host}:${port}${path === '/' ? '' : path}`;
522
530
 
523
- if (!(absoluteHost in router)) router[absoluteHost] = target;
531
+ if (process.argv.includes('localhost')) {
532
+ if (!(absoluteHost in router)) router[absoluteHost] = target;
533
+ } else router[absoluteHost] = target;
524
534
  }); // order router
525
535
 
526
536
  if (Object.keys(router).length === 0) return router;
@@ -85,6 +85,7 @@ const format = (meta) =>
85
85
  */
86
86
  const setUpInfo = async (logger = new winston.Logger()) => {
87
87
  logger.info('argv', process.argv);
88
+ logger.info('cwd', process.cwd());
88
89
  logger.info('platform', process.platform);
89
90
  logger.info('env', process.env.NODE_ENV);
90
91
  logger.info('--max-old-space-size', {
@@ -1,7 +1,7 @@
1
1
  import fs from 'fs-extra';
2
2
 
3
3
  import { publicIp, publicIpv4, publicIpv6 } from 'public-ip';
4
- import { loggerFactory } from './logger.js';
4
+ import { actionInitLog, loggerFactory } from './logger.js';
5
5
  import { DataBaseProvider } from '../db/DataBaseProvider.js';
6
6
  import { getDeployId } from './conf.js';
7
7
 
@@ -39,7 +39,7 @@ const saveRuntimeRouter = async () => {
39
39
  const host = process.env.DEFAULT_DEPLOY_HOST;
40
40
  const path = process.env.DEFAULT_DEPLOY_PATH;
41
41
  const confServerPath = `./engine-private/conf/${deployId}/conf.server.json`;
42
- if (!deployId || !host || !path) {
42
+ if (!deployId || !host || !path || !fs.existsSync(confServerPath)) {
43
43
  // logger.warn('default deploy instance not found');
44
44
  return;
45
45
  }
@@ -77,7 +77,7 @@ const saveRuntimeRouter = async () => {
77
77
 
78
78
  if (closeConn) await DataBaseProvider.instance[`${host}${path}`].mongoose.close();
79
79
  } catch (error) {
80
- logger.error(error);
80
+ logger.error(error, error.stack);
81
81
  }
82
82
  };
83
83
 
@@ -114,20 +114,30 @@ const saveRuntimeCron = async () => {
114
114
 
115
115
  if (closeConn) await DataBaseProvider.instance[`${host}${path}`].mongoose.close();
116
116
  } catch (error) {
117
- logger.error(error);
117
+ logger.error(error, error.stack);
118
118
  }
119
119
  };
120
120
 
121
121
  const listenServerFactory = (logic = async () => {}) => {
122
122
  return {
123
- listen: async (...args) => (logic ? await logic(...args) : undefined, args[1]()),
123
+ listen: async (...args) => (
124
+ setTimeout(() => {
125
+ const message = 'Listen server factory timeout';
126
+ logger.error(message);
127
+ throw new Error(message);
128
+ }, 80000000), // ~ 55 days
129
+ (logic ? await logic(...args) : undefined, args[1]())
130
+ ),
124
131
  };
125
132
  };
126
133
 
127
134
  const listenPortController = async (server, port, metadata) =>
128
135
  new Promise((resolve) => {
129
136
  try {
130
- if (!server) server = listenServerFactory();
137
+ if (port === ':') {
138
+ server.listen(port, actionInitLog);
139
+ return resolve(true);
140
+ }
131
141
 
132
142
  const { host, path, client, runtime, meta } = metadata;
133
143
  const error = [];