underpost 2.8.841 → 2.8.844
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/.env.development +1 -0
- package/.env.production +1 -0
- package/.env.test +1 -0
- package/.github/workflows/{ghpkg.yml → ghpkg.ci.yml} +1 -1
- package/.github/workflows/{npmpkg.yml → npmpkg.ci.yml} +1 -1
- package/.github/workflows/{publish.yml → publish.ci.yml} +1 -1
- package/.github/workflows/{pwa-microservices-template.page.yml → pwa-microservices-template-page.cd.yml} +1 -1
- package/.github/workflows/{pwa-microservices-template.test.yml → pwa-microservices-template-test.ci.yml} +1 -1
- package/.vscode/settings.json +0 -1
- package/README.md +16 -2
- package/bin/build.js +8 -4
- package/bin/deploy.js +10 -81
- package/bin/file.js +15 -8
- package/cli.md +48 -43
- package/docker-compose.yml +1 -1
- package/manifests/deployment/dd-template-development/deployment.yaml +2 -2
- package/manifests/maas/gpu-diag.sh +1 -1
- package/package.json +4 -5
- package/src/api/user/user.router.js +24 -1
- package/src/cli/cluster.js +19 -10
- package/src/cli/deploy.js +19 -0
- package/src/cli/index.js +9 -1
- package/src/cli/monitor.js +8 -12
- package/src/cli/run.js +80 -0
- package/src/client/components/core/CssCore.js +0 -4
- package/src/client/components/core/Docs.js +1 -47
- package/src/client/components/core/EventsUI.js +92 -5
- package/src/client/components/core/Modal.js +431 -87
- package/src/client/components/core/NotificationManager.js +2 -2
- package/src/client/components/core/Panel.js +2 -2
- package/src/client/components/core/PanelForm.js +2 -0
- package/src/client/components/core/Recover.js +1 -1
- package/src/index.js +1 -1
- package/src/monitor.js +24 -0
- package/src/server/client-build.js +0 -20
- package/src/server/valkey.js +102 -41
|
@@ -119,10 +119,11 @@ const Panel = {
|
|
|
119
119
|
});
|
|
120
120
|
s(`.a-${payload._id}`).onclick = async (e) => {
|
|
121
121
|
e.preventDefault();
|
|
122
|
+
if (options.onClick) await options.onClick({ payload });
|
|
122
123
|
};
|
|
123
124
|
s(`.container-${idPanel}-${id}`).onclick = async (e) => {
|
|
124
125
|
e.preventDefault();
|
|
125
|
-
if (options.onClick) await options.onClick({ payload });
|
|
126
|
+
// if (options.onClick) await options.onClick({ payload });
|
|
126
127
|
};
|
|
127
128
|
});
|
|
128
129
|
if (s(`.${idPanel}-${id}`)) s(`.${idPanel}-${id}`).remove();
|
|
@@ -540,7 +541,6 @@ const Panel = {
|
|
|
540
541
|
background: #f6f6f6;
|
|
541
542
|
color: black;
|
|
542
543
|
padding: 10px;
|
|
543
|
-
cursor: pointer;
|
|
544
544
|
min-height: 400px;
|
|
545
545
|
}
|
|
546
546
|
.${idPanel}:hover {
|
|
@@ -425,7 +425,9 @@ const PanelForm = {
|
|
|
425
425
|
});
|
|
426
426
|
let firsUpdateEvent = false;
|
|
427
427
|
let lastCid;
|
|
428
|
+
console.warn('-------------> updatePanel 1');
|
|
428
429
|
this.Data[idPanel].updatePanel = async () => {
|
|
430
|
+
console.warn('-------------> updatePanel 2');
|
|
429
431
|
const cid = getQueryParams().cid ? getQueryParams().cid : '';
|
|
430
432
|
if (lastCid === cid) return;
|
|
431
433
|
lastCid = cid;
|
|
@@ -62,7 +62,7 @@ const Recover = {
|
|
|
62
62
|
|
|
63
63
|
setTimeout(async () => {
|
|
64
64
|
if (user && user.email) {
|
|
65
|
-
s(`.recover-email`).value = user.email;
|
|
65
|
+
s(`.recover-email`).value = user.role === 'guest' ? '' : user.email;
|
|
66
66
|
if (user.emailConfirmed) s(`.recover-email`).setAttribute('disabled', '');
|
|
67
67
|
}
|
|
68
68
|
|
package/src/index.js
CHANGED
package/src/monitor.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// https://nodejs.org/api
|
|
4
|
+
// https://expressjs.com/en/4x/api.html
|
|
5
|
+
|
|
6
|
+
import dotenv from 'dotenv';
|
|
7
|
+
import { loggerFactory } from './server/logger.js';
|
|
8
|
+
import { ProcessController } from './server/process.js';
|
|
9
|
+
import { getUnderpostRootPath } from './server/conf.js';
|
|
10
|
+
import fs from 'fs-extra';
|
|
11
|
+
import UnderpostMonitor from './cli/monitor.js';
|
|
12
|
+
|
|
13
|
+
const underpostRootPath = getUnderpostRootPath();
|
|
14
|
+
fs.existsSync(`${underpostRootPath}/.env`)
|
|
15
|
+
? dotenv.config({ path: `${underpostRootPath}/.env`, override: true })
|
|
16
|
+
: dotenv.config();
|
|
17
|
+
|
|
18
|
+
const logger = loggerFactory(import.meta);
|
|
19
|
+
|
|
20
|
+
await logger.setUpInfo();
|
|
21
|
+
|
|
22
|
+
UnderpostMonitor.API.callback(process.argv[2], process.argv[3], { type: 'blue-green', sync: true });
|
|
23
|
+
|
|
24
|
+
ProcessController.init(logger);
|
|
@@ -577,9 +577,6 @@ Sitemap: https://${host}${path === '/' ? '' : path}/sitemap.xml`,
|
|
|
577
577
|
fs.mkdirSync(coverageBuildPath, { recursive: true });
|
|
578
578
|
fs.copySync(`./coverage`, coverageBuildPath);
|
|
579
579
|
|
|
580
|
-
// uml
|
|
581
|
-
// shellExec(`node bin/deploy uml ${host} ${path}`);
|
|
582
|
-
|
|
583
580
|
// https://swagger-autogen.github.io/docs/
|
|
584
581
|
|
|
585
582
|
const basePath = path === '/' ? `${process.env.BASE_API}` : `/${process.env.BASE_API}`;
|
|
@@ -667,10 +664,6 @@ Sitemap: https://${host}${path === '/' ? '' : path}/sitemap.xml`,
|
|
|
667
664
|
},
|
|
668
665
|
};
|
|
669
666
|
|
|
670
|
-
// plantuml
|
|
671
|
-
logger.info('copy plantuml', `${rootClientPath}/docs/plantuml`);
|
|
672
|
-
fs.copySync(`./src/client/public/default/plantuml`, `${rootClientPath}/docs/plantuml`);
|
|
673
|
-
|
|
674
667
|
logger.warn('build swagger api docs', doc.info);
|
|
675
668
|
|
|
676
669
|
const outputFile = `./public/${host}${path === '/' ? path : `${path}/`}swagger-output.json`;
|
|
@@ -683,19 +676,6 @@ Sitemap: https://${host}${path === '/' ? '' : path}/sitemap.xml`,
|
|
|
683
676
|
root file where the route starts, such as index.js, app.js, routes.js, etc ... */
|
|
684
677
|
|
|
685
678
|
await swaggerAutoGen({ openapi: '3.0.0' })(outputFile, routes, doc);
|
|
686
|
-
|
|
687
|
-
const htmlFiles = await fs.readdir(`./public/${host}/docs/engine/${Underpost.version.replace('v', '')}`);
|
|
688
|
-
for (const htmlFile of htmlFiles) {
|
|
689
|
-
if (htmlFile.match('.html')) {
|
|
690
|
-
fs.writeFileSync(
|
|
691
|
-
`./public/${host}/docs/engine/${Underpost.version.replace('v', '')}/${htmlFile}`,
|
|
692
|
-
fs
|
|
693
|
-
.readFileSync(`./public/${host}/docs/engine/${Underpost.version.replace('v', '')}/${htmlFile}`, 'utf8')
|
|
694
|
-
.replaceAll('Tutorials', 'References'),
|
|
695
|
-
'utf8',
|
|
696
|
-
);
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
679
|
}
|
|
700
680
|
|
|
701
681
|
if (client) {
|
package/src/server/valkey.js
CHANGED
|
@@ -5,22 +5,71 @@ import { loggerFactory } from './logger.js';
|
|
|
5
5
|
|
|
6
6
|
const logger = loggerFactory(import.meta);
|
|
7
7
|
|
|
8
|
+
// Per-instance registries keyed by `${host}${path}`
|
|
8
9
|
const ValkeyInstances = {};
|
|
10
|
+
const DummyStores = {}; // in-memory Maps per instance
|
|
11
|
+
const ValkeyStatus = {}; // 'connected' | 'dummy' | 'error' | undefined
|
|
9
12
|
|
|
10
|
-
|
|
13
|
+
// Backward-compatible overall flag: true if any instance is connected
|
|
14
|
+
const isValkeyEnable = () => Object.values(ValkeyStatus).some((s) => s === 'connected');
|
|
11
15
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const isValkeyEnable = () => valkeyEnabled;
|
|
16
|
+
const _instanceKey = (opts = { host: '', path: '' }) => `${opts.host || ''}${opts.path || ''}`;
|
|
15
17
|
|
|
16
18
|
const createValkeyConnection = async (
|
|
17
|
-
instance = { host: '',
|
|
18
|
-
valkeyServerConnectionOptions = { host: '',
|
|
19
|
+
instance = { host: '', path: '' },
|
|
20
|
+
valkeyServerConnectionOptions = { host: '', path: '' },
|
|
19
21
|
) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
);
|
|
23
|
-
|
|
22
|
+
const key = _instanceKey(instance);
|
|
23
|
+
// Initialize dummy store for the instance
|
|
24
|
+
if (!DummyStores[key]) DummyStores[key] = new Map();
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const client = await ValkeyAPI.valkeyClientFactory(valkeyServerConnectionOptions);
|
|
28
|
+
|
|
29
|
+
// Attach listeners for visibility
|
|
30
|
+
client.on?.('ready', () => {
|
|
31
|
+
ValkeyStatus[key] = 'connected';
|
|
32
|
+
logger.info('Valkey connected', { instance, status: ValkeyStatus[key] });
|
|
33
|
+
});
|
|
34
|
+
client.on?.('error', (err) => {
|
|
35
|
+
// Switch to dummy if not yet connected
|
|
36
|
+
if (ValkeyStatus[key] !== 'connected') {
|
|
37
|
+
ValkeyStatus[key] = 'dummy';
|
|
38
|
+
} else {
|
|
39
|
+
ValkeyStatus[key] = 'error';
|
|
40
|
+
}
|
|
41
|
+
logger.warn('Valkey error', { err: err?.message, instance, status: ValkeyStatus[key] });
|
|
42
|
+
});
|
|
43
|
+
client.on?.('end', () => {
|
|
44
|
+
if (ValkeyStatus[key] !== 'dummy') ValkeyStatus[key] = 'error';
|
|
45
|
+
logger.warn('Valkey connection ended', { instance, status: ValkeyStatus[key] });
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Probe connectivity with a short timeout
|
|
49
|
+
const probe = async () => {
|
|
50
|
+
try {
|
|
51
|
+
// basic ping via SET/GET roundtrip
|
|
52
|
+
const probeKey = `__vk_probe_${Date.now()}`;
|
|
53
|
+
await client.set(probeKey, '1');
|
|
54
|
+
await client.get(probeKey);
|
|
55
|
+
ValkeyStatus[key] = 'connected';
|
|
56
|
+
} catch (e) {
|
|
57
|
+
ValkeyStatus[key] = 'dummy';
|
|
58
|
+
logger.warn('Valkey probe failed, falling back to dummy', { instance, error: e?.message });
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// Race with timeout to avoid hanging
|
|
63
|
+
await Promise.race([probe(), new Promise((resolve) => setTimeout(resolve, 1000))]);
|
|
64
|
+
|
|
65
|
+
ValkeyInstances[key] = client;
|
|
66
|
+
if (!ValkeyStatus[key]) ValkeyStatus[key] = 'dummy';
|
|
67
|
+
} catch (err) {
|
|
68
|
+
ValkeyStatus[key] = 'dummy';
|
|
69
|
+
logger.warn('Valkey client creation failed, using dummy', { instance, error: err?.message });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return ValkeyInstances[key];
|
|
24
73
|
};
|
|
25
74
|
|
|
26
75
|
const selectDtoFactory = (payload, select) => {
|
|
@@ -33,18 +82,12 @@ const selectDtoFactory = (payload, select) => {
|
|
|
33
82
|
|
|
34
83
|
const valkeyClientFactory = async (options) => {
|
|
35
84
|
const valkey = new Valkey({
|
|
36
|
-
// port: 6379,
|
|
37
|
-
// host: 'valkey-service.default.svc.cluster.local',
|
|
38
85
|
port: options?.port ? options.port : undefined,
|
|
39
86
|
host: options?.host ? options.host : undefined,
|
|
87
|
+
// Keep retry strategy minimal; state handled in createValkeyConnection
|
|
40
88
|
retryStrategy: (attempt) => {
|
|
41
|
-
if (attempt === 1)
|
|
42
|
-
|
|
43
|
-
valkeyEnabled = false;
|
|
44
|
-
logger.warn('Valkey service not enabled', { ...options, valkeyEnabled });
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
return 1000; // 1 second interval attempt
|
|
89
|
+
if (attempt === 1) return undefined; // stop aggressive retries early
|
|
90
|
+
return 1000; // retry interval if library continues
|
|
48
91
|
},
|
|
49
92
|
}); // Connect to 127.0.0.1:6379
|
|
50
93
|
// new Valkey(6380); // 127.0.0.1:6380
|
|
@@ -60,34 +103,52 @@ const valkeyClientFactory = async (options) => {
|
|
|
60
103
|
return valkey;
|
|
61
104
|
};
|
|
62
105
|
|
|
63
|
-
const getValkeyObject = async (options = { host: '',
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
const object = await ValkeyInstances[`${options.host}${options.path}`].get(key);
|
|
106
|
+
const getValkeyObject = async (options = { host: '', path: '' }, key = '') => {
|
|
107
|
+
const k = _instanceKey(options);
|
|
108
|
+
const status = ValkeyStatus[k];
|
|
69
109
|
try {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
110
|
+
if (status === 'connected' && ValkeyInstances[k]) {
|
|
111
|
+
const value = await ValkeyInstances[k].get(key);
|
|
112
|
+
if (value == null) return null;
|
|
113
|
+
try {
|
|
114
|
+
return JSON.parse(value);
|
|
115
|
+
} catch {
|
|
116
|
+
// not JSON, return raw string
|
|
117
|
+
return value;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
} catch (err) {
|
|
121
|
+
logger.warn('Valkey get failed, using dummy', { key, err: err?.message });
|
|
74
122
|
}
|
|
123
|
+
// Dummy fallback returns stored value as-is (string or object)
|
|
124
|
+
return DummyStores[k]?.get(key) ?? null;
|
|
75
125
|
};
|
|
76
126
|
|
|
77
|
-
const setValkeyObject = async (options = { host: '',
|
|
78
|
-
|
|
79
|
-
|
|
127
|
+
const setValkeyObject = async (options = { host: '', path: '' }, key = '', payload = {}) => {
|
|
128
|
+
const k = _instanceKey(options);
|
|
129
|
+
const isString = typeof payload === 'string';
|
|
130
|
+
const value = isString ? payload : JSON.stringify(payload);
|
|
131
|
+
try {
|
|
132
|
+
if (ValkeyStatus[k] === 'connected' && ValkeyInstances[k]) {
|
|
133
|
+
return await ValkeyInstances[k].set(key, value);
|
|
134
|
+
}
|
|
135
|
+
} catch (err) {
|
|
136
|
+
logger.warn('Valkey set failed, writing to dummy', { key, err: err?.message });
|
|
137
|
+
}
|
|
138
|
+
if (!DummyStores[k]) DummyStores[k] = new Map();
|
|
139
|
+
// Store raw string or object accordingly
|
|
140
|
+
DummyStores[k].set(key, isString ? payload : payload);
|
|
141
|
+
return 'OK';
|
|
80
142
|
};
|
|
81
143
|
|
|
82
|
-
const updateValkeyObject = async (options = { host: '',
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return await
|
|
144
|
+
const updateValkeyObject = async (options = { host: '', path: '' }, key = '', payload = {}) => {
|
|
145
|
+
let base = await getValkeyObject(options, key);
|
|
146
|
+
if (typeof base !== 'object' || base === null) base = {};
|
|
147
|
+
base.updatedAt = new Date().toISOString();
|
|
148
|
+
return await setValkeyObject(options, key, { ...base, ...payload });
|
|
87
149
|
};
|
|
88
150
|
|
|
89
|
-
const valkeyObjectFactory = async (options = { host: 'localhost', object: {} },
|
|
90
|
-
if (!valkeyEnabled) throw new Error(disableValkeyErrorMessage);
|
|
151
|
+
const valkeyObjectFactory = async (options = { host: 'localhost', object: {} }, model = '') => {
|
|
91
152
|
const idoDate = new Date().toISOString();
|
|
92
153
|
options.object = options.object || {};
|
|
93
154
|
const { object } = options;
|
|
@@ -95,7 +156,7 @@ const valkeyObjectFactory = async (options = { host: 'localhost', object: {} },
|
|
|
95
156
|
object._id = _id;
|
|
96
157
|
object.createdAt = idoDate;
|
|
97
158
|
object.updatedAt = idoDate;
|
|
98
|
-
switch (
|
|
159
|
+
switch (model) {
|
|
99
160
|
case 'user': {
|
|
100
161
|
const role = 'guest';
|
|
101
162
|
object._id = `${role}${_id}`;
|
|
@@ -115,7 +176,7 @@ const valkeyObjectFactory = async (options = { host: 'localhost', object: {} },
|
|
|
115
176
|
};
|
|
116
177
|
}
|
|
117
178
|
default:
|
|
118
|
-
throw new Error(`
|
|
179
|
+
throw new Error(`model schema not found: ${model}`);
|
|
119
180
|
}
|
|
120
181
|
};
|
|
121
182
|
|