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.
- package/.github/workflows/ghpkg.yml +6 -50
- package/.github/workflows/npmpkg.yml +67 -0
- package/.github/workflows/pwa-microservices-template.page.yml +2 -1
- package/.github/workflows/pwa-microservices-template.test.yml +2 -2
- package/Dockerfile +3 -3
- package/bin/build.js +32 -191
- package/bin/deploy.js +3 -19
- package/bin/file.js +13 -2
- package/bin/index.js +30 -3
- package/docker-compose.yml +1 -1
- package/package.json +12 -3
- package/src/cli/cluster.js +3 -3
- package/src/cli/db.js +148 -0
- package/src/cli/deploy.js +277 -0
- package/src/cli/image.js +21 -14
- package/src/cli/repository.js +11 -17
- package/src/cli/test.js +52 -1
- package/src/client/components/core/Auth.js +22 -4
- package/src/client/components/core/CommonJs.js +9 -0
- package/src/client/components/core/Modal.js +0 -1
- package/src/client/components/core/Translate.js +4 -0
- package/src/client/components/core/VanillaJs.js +0 -9
- package/src/client/components/core/Worker.js +34 -31
- package/src/index.js +17 -1
- package/src/server/conf.js +25 -15
- package/src/server/logger.js +1 -0
- package/src/server/network.js +16 -6
|
@@ -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')
|
|
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
|
-
|
|
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
|
};
|
|
@@ -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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
switch (status) {
|
|
37
|
+
case 'loader':
|
|
38
|
+
{
|
|
39
|
+
LoadingAnimation.RenderCurrentSrcLoad(event);
|
|
40
|
+
}
|
|
41
|
+
break;
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
default:
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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.
|
|
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;
|
package/src/server/conf.js
CHANGED
|
@@ -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/${
|
|
47
|
-
|
|
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 (
|
|
52
|
+
if (deployContext === 'deploy') return;
|
|
50
53
|
|
|
51
|
-
if (
|
|
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
|
|
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.${
|
|
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
|
-
|
|
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
|
-
(
|
|
152
|
+
(deployContext === 'proxy' ||
|
|
145
153
|
!singleReplica ||
|
|
146
|
-
(singleReplica && process.env.NODE_ENV === 'development' && !
|
|
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 (
|
|
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;
|
package/src/server/logger.js
CHANGED
|
@@ -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', {
|
package/src/server/network.js
CHANGED
|
@@ -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) => (
|
|
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 (
|
|
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 = [];
|