underpost 2.8.86 → 2.8.87

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.
Files changed (42) hide show
  1. package/.env.development +6 -1
  2. package/.env.production +6 -1
  3. package/.env.test +6 -1
  4. package/README.md +22 -2
  5. package/bin/build.js +1 -0
  6. package/bin/deploy.js +32 -20
  7. package/bin/file.js +5 -2
  8. package/bin/util.js +1 -56
  9. package/cli.md +10 -5
  10. package/conf.js +3 -3
  11. package/manifests/deployment/dd-default-development/deployment.yaml +2 -2
  12. package/manifests/deployment/mongo-express/deployment.yaml +12 -12
  13. package/manifests/maas/nvim.sh +91 -0
  14. package/package.json +3 -11
  15. package/src/api/file/file.service.js +28 -8
  16. package/src/api/user/user.router.js +31 -5
  17. package/src/api/user/user.service.js +3 -4
  18. package/src/cli/cluster.js +4 -23
  19. package/src/cli/db.js +0 -19
  20. package/src/cli/deploy.js +21 -29
  21. package/src/cli/fs.js +1 -0
  22. package/src/cli/index.js +4 -1
  23. package/src/cli/repository.js +4 -2
  24. package/src/cli/run.js +17 -2
  25. package/src/client/components/core/CssCore.js +12 -0
  26. package/src/client/components/core/FullScreen.js +19 -28
  27. package/src/client/components/core/Input.js +1 -0
  28. package/src/client/components/core/Modal.js +25 -39
  29. package/src/client/components/core/ObjectLayerEngine.js +229 -4
  30. package/src/client/components/core/ObjectLayerEngineModal.js +441 -0
  31. package/src/client/components/core/ToggleSwitch.js +15 -1
  32. package/src/client/public/default/assets/mailer/api-user-default-avatar.png +0 -0
  33. package/src/index.js +1 -1
  34. package/src/server/client-build-docs.js +1 -1
  35. package/src/server/client-build.js +4 -12
  36. package/src/server/client-icons.js +6 -78
  37. package/src/server/conf.js +83 -138
  38. package/src/server/proxy.js +1 -1
  39. package/src/server/runtime.js +1 -2
  40. package/src/server/start.js +2 -2
  41. package/test/api.test.js +3 -2
  42. package/bin/cyberia0.js +0 -78
@@ -9,17 +9,11 @@ import {
9
9
  timer,
10
10
  } from '../client/components/core/CommonJs.js';
11
11
  import * as dir from 'path';
12
- import cliProgress from 'cli-progress';
13
- import cliSpinners from 'cli-spinners';
14
- import logUpdate from 'log-update';
15
12
  import colors from 'colors';
16
13
  import { loggerFactory } from './logger.js';
17
14
  import { shellExec } from './process.js';
18
15
  import { DefaultConf } from '../../conf.js';
19
- import read from 'read';
20
16
  import splitFile from 'split-file';
21
- import axios from 'axios';
22
- import { ssrFactory } from './client-formatted.js';
23
17
 
24
18
  colors.enable();
25
19
 
@@ -27,68 +21,84 @@ dotenv.config();
27
21
 
28
22
  const logger = loggerFactory(import.meta);
29
23
 
30
- // monitoring: https://app.pm2.io/
31
-
32
24
  const Config = {
33
25
  default: DefaultConf,
34
- build: async function (options = { folder: '' }, deployContext, deployList, subConf) {
35
- if (!deployContext) deployContext = process.argv[2];
26
+ build: async function (deployContext = 'dd-default', deployList, subConf) {
27
+ if (typeof process.argv[2] === 'string' && process.argv[2].startsWith('dd-')) deployContext = process.argv[2];
36
28
  if (!fs.existsSync(`./tmp`)) fs.mkdirSync(`./tmp`, { recursive: true });
37
29
  fs.writeFileSync(`./tmp/await-deploy`, '', 'utf8');
38
- if (fs.existsSync(`./engine-private/conf/${deployContext}`))
39
- return loadConf(deployContext, process.env.NODE_ENV, subConf);
40
30
  if (fs.existsSync(`./engine-private/replica/${deployContext}`))
41
31
  return loadConf(deployContext, process.env.NODE_ENV, subConf);
32
+ else if (deployContext.startsWith('dd-')) return loadConf(deployContext, process.env.NODE_ENV, subConf);
33
+ if (deployContext === 'proxy') Config.buildProxy(deployContext, deployList, subConf);
34
+ },
35
+ deployIdFactory: function (deployId = 'dd-default') {
36
+ if (!deployId.startsWith('dd-')) deployId = `dd-${deployId}`;
42
37
 
43
- if (deployContext === 'deploy') return;
44
-
45
- if (deployContext === 'proxy') {
46
- if (!deployList) deployList = process.argv[3];
47
- if (!subConf) subConf = process.argv[4];
48
- this.default.server = {};
49
- for (const deployId of deployList.split(',')) {
50
- let confPath = `./engine-private/conf/${deployId}/conf.server.json`;
51
- const privateConfDevPath = fs.existsSync(`./engine-private/replica/${deployId}/conf.server.json`)
52
- ? `./engine-private/replica/${deployId}/conf.server.json`
53
- : `./engine-private/conf/${deployId}/conf.server.dev.${subConf}.json`;
54
- const confDevPath = fs.existsSync(privateConfDevPath)
55
- ? privateConfDevPath
56
- : `./engine-private/conf/${deployId}/conf.server.dev.json`;
57
-
58
- if (process.env.NODE_ENV === 'development' && fs.existsSync(confDevPath)) confPath = confDevPath;
59
- const serverConf = JSON.parse(fs.readFileSync(confPath, 'utf8'));
60
-
61
- for (const host of Object.keys(loadReplicas(serverConf, deployContext, subConf))) {
62
- if (serverConf[host]['/'])
63
- this.default.server[host] = {
64
- ...this.default.server[host],
65
- ...serverConf[host],
66
- };
67
- else
68
- this.default.server[host] = {
69
- ...serverConf[host],
70
- ...this.default.server[host],
71
- };
72
- }
38
+ logger.info('Build deployId', deployId);
39
+
40
+ const folder = `./engine-private/conf/${deployId}`;
41
+
42
+ if (!fs.existsSync(folder)) fs.mkdirSync(folder, { recursive: true });
43
+ fs.writeFileSync(
44
+ `${folder}/.env.production`,
45
+ fs.readFileSync('./.env.production', 'utf8').replaceAll('dd-default', deployId),
46
+ 'utf8',
47
+ );
48
+ fs.writeFileSync(
49
+ `${folder}/.env.development`,
50
+ fs.readFileSync('./.env.development', 'utf8').replaceAll('dd-default', deployId),
51
+ 'utf8',
52
+ );
53
+ fs.writeFileSync(
54
+ `${folder}/.env.test`,
55
+ fs.readFileSync('./.env.test', 'utf8').replaceAll('dd-default', deployId),
56
+ 'utf8',
57
+ );
58
+ fs.writeFileSync(`${folder}/package.json`, fs.readFileSync('./package.json', 'utf8'), 'utf8');
59
+
60
+ this.buildTmpConf(folder);
61
+
62
+ return { deployIdFolder: folder, deployId };
63
+ },
64
+ buildTmpConf: function (folder = './conf') {
65
+ for (const confType of Object.keys(this.default))
66
+ fs.writeFileSync(`${folder}/conf.${confType}.json`, JSON.stringify(this.default[confType], null, 4), 'utf8');
67
+ },
68
+ buildProxy: function (deployContext = 'dd-default', deployList, subConf) {
69
+ if (!deployList) deployList = process.argv[3];
70
+ if (!subConf) subConf = process.argv[4];
71
+ this.default.server = {};
72
+ for (const deployId of deployList.split(',')) {
73
+ let confPath = `./engine-private/conf/${deployId}/conf.server.json`;
74
+ const privateConfDevPath = fs.existsSync(`./engine-private/replica/${deployId}/conf.server.json`)
75
+ ? `./engine-private/replica/${deployId}/conf.server.json`
76
+ : `./engine-private/conf/${deployId}/conf.server.dev.${subConf}.json`;
77
+ const confDevPath = fs.existsSync(privateConfDevPath)
78
+ ? privateConfDevPath
79
+ : `./engine-private/conf/${deployId}/conf.server.dev.json`;
80
+
81
+ if (process.env.NODE_ENV === 'development' && fs.existsSync(confDevPath)) confPath = confDevPath;
82
+ const serverConf = JSON.parse(fs.readFileSync(confPath, 'utf8'));
83
+
84
+ for (const host of Object.keys(loadReplicas(serverConf, deployContext, subConf))) {
85
+ if (serverConf[host]['/'])
86
+ this.default.server[host] = {
87
+ ...this.default.server[host],
88
+ ...serverConf[host],
89
+ };
90
+ else
91
+ this.default.server[host] = {
92
+ ...serverConf[host],
93
+ ...this.default.server[host],
94
+ };
73
95
  }
74
96
  }
75
- if (!options || !options.folder)
76
- options = {
77
- ...options,
78
- folder: `./conf`,
79
- };
80
- if (!fs.existsSync(options.folder)) fs.mkdirSync(options.folder, { recursive: true });
81
- for (const confType of Object.keys(this.default)) {
82
- fs.writeFileSync(
83
- `${options.folder}/conf.${confType}.json`,
84
- JSON.stringify(this.default[confType], null, 4),
85
- 'utf8',
86
- );
87
- }
97
+ this.buildTmpConf();
88
98
  },
89
99
  };
90
100
 
91
- const loadConf = (deployId, envInput, subConf) => {
101
+ const loadConf = (deployId = 'dd-default', envInput, subConf) => {
92
102
  if (deployId === 'current') {
93
103
  console.log(process.env.DEPLOY_ID);
94
104
  return;
@@ -104,22 +114,15 @@ const loadConf = (deployId, envInput, subConf) => {
104
114
  shellExec(`git checkout ${path}/package-lock.json`);
105
115
  return;
106
116
  }
107
- if (!deployId.startsWith('dd-')) deployId = 'dd-default';
108
117
  const folder = fs.existsSync(`./engine-private/replica/${deployId}`)
109
118
  ? `./engine-private/replica/${deployId}`
110
119
  : `./engine-private/conf/${deployId}`;
120
+ if (!fs.existsSync(folder)) Config.deployIdFactory(deployId);
111
121
  if (!fs.existsSync(`./conf`)) fs.mkdirSync(`./conf`);
112
- if (!fs.existsSync(`./tmp`)) fs.mkdirSync(`./tmp`, { recursive: true });
113
- const isValidDeployId = fs.existsSync(`${folder}`);
114
- if (!isValidDeployId) {
115
- logger.info(`Save new deploy conf: '${deployId}'`);
116
- shellExec(`node bin/deploy save ${deployId}`);
117
- return loadConf(deployId);
118
- }
122
+ if (!fs.existsSync(`./tmp`)) fs.mkdirSync(`./tmp`);
123
+
119
124
  for (const typeConf of Object.keys(Config.default)) {
120
- let srcConf = isValidDeployId
121
- ? fs.readFileSync(`${folder}/conf.${typeConf}.json`, 'utf8')
122
- : JSON.stringify(Config.default[typeConf]);
125
+ let srcConf = fs.readFileSync(`${folder}/conf.${typeConf}.json`, 'utf8');
123
126
  if (process.env.NODE_ENV === 'development' && typeConf === 'server') {
124
127
  if (!subConf) subConf = process.argv[3];
125
128
  const devConfPath = `${folder}/conf.${typeConf}.dev${subConf ? `.${subConf}` : ''}.json`;
@@ -494,15 +497,6 @@ const buildProxyRouter = () => {
494
497
  }
495
498
  }
496
499
  }
497
- if (process.argv.includes('maintenance'))
498
- (async () => {
499
- globalThis.defaultHtmlSrcMaintenance = (await ssrFactory())({
500
- title: 'Site in maintenance',
501
- ssrPath: '/',
502
- ssrHeadComponents: '',
503
- ssrBodyComponents: (await ssrFactory(`./src/client/ssr/offline/Maintenance.js`))(),
504
- });
505
- })();
506
500
 
507
501
  return proxyRouter;
508
502
  };
@@ -562,16 +556,24 @@ const buildPortProxyRouter = (port, proxyRouter) => {
562
556
  // build router
563
557
  Object.keys(hosts).map((hostKey) => {
564
558
  let { host, path, target, proxy, peer } = hosts[hostKey];
565
- if (process.argv.includes('localhost') && process.env.NODE_ENV === 'development') host = `localhost`;
559
+ if (process.env.NODE_ENV === 'development') host = `localhost`;
560
+
561
+ if (!proxy.includes(port)) {
562
+ logger.warn('Proxy port not set on conf', { port, host, path, proxy, target });
563
+ if (process.env.NODE_ENV === 'production') {
564
+ logger.warn('Omitting host', { host, path, target });
565
+ return;
566
+ }
567
+ }
566
568
 
567
- if (!proxy.includes(port)) return;
568
569
  const absoluteHost = [80, 443].includes(port)
569
570
  ? `${host}${path === '/' ? '' : path}`
570
571
  : `${host}:${port}${path === '/' ? '' : path}`;
571
572
 
572
- if (process.argv.includes('localhost')) {
573
- if (!(absoluteHost in router)) router[absoluteHost] = target;
574
- } else router[absoluteHost] = target;
573
+ if (absoluteHost in router)
574
+ logger.warn('Overwrite: Absolute host already exists on router', { absoluteHost, target });
575
+
576
+ router[absoluteHost] = target;
575
577
  }); // order router
576
578
 
577
579
  if (Object.keys(router).length === 0) return router;
@@ -583,51 +585,6 @@ const buildPortProxyRouter = (port, proxyRouter) => {
583
585
  return reOrderRouter;
584
586
  };
585
587
 
586
- const cliBar = async (time = 5000) => {
587
- // create new progress bar
588
- const b = new cliProgress.SingleBar({
589
- format: 'Delay | {bar} | {percentage}% || {value}/{total} Chunks || Speed: {speed}',
590
- barCompleteChar: '\u2588',
591
- barIncompleteChar: '\u2591',
592
- hideCursor: true,
593
- });
594
-
595
- const maxValueDisplay = 200;
596
- const minValueDisplay = 0;
597
- const steps = 10;
598
- const incrementValue = 200 / steps;
599
- const delayTime = time / steps;
600
- // initialize the bar - defining payload token "speed" with the default value "N/A"
601
- b.start(maxValueDisplay, minValueDisplay, {
602
- speed: 'N/A',
603
- });
604
-
605
- // update values
606
- // b1.increment();
607
- // b1.update(20);
608
-
609
- for (const step of range(1, steps)) {
610
- b.increment(incrementValue);
611
- await timer(delayTime);
612
- }
613
-
614
- // stop the bar
615
- b.stop();
616
- };
617
-
618
- const cliSpinner = async (time = 5000, message0, message1, color, type = 'dots') => {
619
- const { frames, interval } = cliSpinners[type];
620
- const steps = parseInt(time / interval);
621
- let index = 0;
622
- for (const step of range(1, steps)) {
623
- const msg = `${message0 ? message0 : ''}${frames[index]}${message1 ? message1 : ''}`;
624
- logUpdate(color ? msg[color] : msg);
625
- await timer(interval);
626
- index++;
627
- if (index === frames.length) index = 0;
628
- }
629
- };
630
-
631
588
  const buildReplicaId = ({ deployId, replica }) => `${deployId}-${replica.slice(1)}`;
632
589
 
633
590
  const getDataDeploy = (
@@ -636,7 +593,6 @@ const getDataDeploy = (
636
593
  deployGroupId: '',
637
594
  deployId: '',
638
595
  disableSyncEnvPort: false,
639
- deployIdConcat: [],
640
596
  },
641
597
  ) => {
642
598
  let dataDeploy =
@@ -649,8 +605,6 @@ const getDataDeploy = (
649
605
  .map((deployId) => deployId.trim())
650
606
  .filter((deployId) => deployId);
651
607
 
652
- if (options.deployIdConcat) dataDeploy = dataDeploy.concat(options.deployIdConcat);
653
-
654
608
  if (options.deployId) dataDeploy = dataDeploy.filter((d) => d === options.deployId);
655
609
 
656
610
  dataDeploy = dataDeploy.map((deployId) => {
@@ -777,12 +731,6 @@ const awaitDeployMonitor = async (init = false, deltaMs = 1000) => {
777
731
  if (fs.existsSync(`./tmp/await-deploy`)) return await awaitDeployMonitor();
778
732
  };
779
733
 
780
- const getDeployId = () => {
781
- const deployIndexArg = process.argv.findIndex((a) => a.match(`deploy-id:`));
782
- if (deployIndexArg > -1) return process.argv[deployIndexArg].split(':')[1].trim();
783
- return 'dd-default';
784
- };
785
-
786
734
  const getCronBackUpFolder = (host = '', path = '') => {
787
735
  return `${host}${path.replace(/\\/g, '/').replace(`/`, '-')}`;
788
736
  };
@@ -992,14 +940,11 @@ export {
992
940
  buildWsSrc,
993
941
  cloneSrcComponents,
994
942
  buildProxyRouter,
995
- cliBar,
996
- cliSpinner,
997
943
  getDataDeploy,
998
944
  validateTemplatePath,
999
945
  buildReplicaId,
1000
946
  getCronBackUpFolder,
1001
947
  mergeFile,
1002
- getDeployId,
1003
948
  getPathsSSR,
1004
949
  buildKindPorts,
1005
950
  buildPortProxyRouter,
@@ -55,7 +55,7 @@ const buildProxy = async () => {
55
55
  // '^/target-path': '/',
56
56
  },
57
57
  };
58
- if (!process.argv.includes('maintenance')) options.router = buildPortProxyRouter(port, proxyRouter);
58
+ options.router = buildPortProxyRouter(port, proxyRouter);
59
59
 
60
60
  const filter = false
61
61
  ? (pathname, req) => {
@@ -18,7 +18,6 @@ import { DataBaseProvider } from '../db/DataBaseProvider.js';
18
18
  // import { createProxyMiddleware } from 'http-proxy-middleware';
19
19
  import { createPeerServer } from './peer.js';
20
20
  import { Lampp } from '../runtime/lampp/Lampp.js';
21
- import { getDeployId } from './conf.js';
22
21
  import { JSONweb, ssrFactory } from './client-formatted.js';
23
22
  import Underpost from '../index.js';
24
23
  import { createValkeyConnection } from './valkey.js';
@@ -28,7 +27,7 @@ dotenv.config();
28
27
  const logger = loggerFactory(import.meta);
29
28
 
30
29
  const buildRuntime = async () => {
31
- const deployId = getDeployId();
30
+ const deployId = process.env.DEPLOY_ID;
32
31
 
33
32
  const collectDefaultMetrics = promClient.collectDefaultMetrics;
34
33
  collectDefaultMetrics();
@@ -107,12 +107,12 @@ class UnderpostStartUp {
107
107
  for (const replica of replicas) {
108
108
  if (!replica.match(deployId)) continue;
109
109
  shellExec(`node bin/deploy conf ${replica} ${env}`);
110
- shellExec(`npm ${runCmd} deploy deploy-id:${replica}`, { async: true });
110
+ shellExec(`npm ${runCmd} ${replica}`, { async: true });
111
111
  await awaitDeployMonitor(true);
112
112
  }
113
113
  }
114
114
  shellExec(`node bin/deploy conf ${deployId} ${env}`);
115
- shellExec(`npm ${runCmd} deploy deploy-id:${deployId}`, { async: true });
115
+ shellExec(`npm ${runCmd} ${deployId}`, { async: true });
116
116
  await awaitDeployMonitor(true);
117
117
  UnderpostRootEnv.API.set('container-status', `${deployId}-${env}-running-deployment`);
118
118
  },
package/test/api.test.js CHANGED
@@ -21,12 +21,13 @@ const BASE_URL =
21
21
 
22
22
  describe(`GET 'Test' API Request `, async () => {
23
23
  {
24
- const url = `${BASE_URL}/test/youtube-id/?url=https://www.youtube.com/watch?v=o4f42SbyDMk`;
24
+ const youtubeId = '2aib-pmgUdQ';
25
+ const url = `${BASE_URL}/test/youtube-id/?url=https://www.youtube.com/watch?v=${youtubeId}`;
25
26
  it(`youtube id from raw youtube url`, async () => {
26
27
  logger.info('request info', { url });
27
28
  const res = await axios.get(url);
28
29
  logger.info('response', res.data);
29
- return expect(res.data.data).equal('o4f42SbyDMk');
30
+ return expect(res.data.data).equal(youtubeId);
30
31
  });
31
32
  }
32
33
  {
package/bin/cyberia0.js DELETED
@@ -1,78 +0,0 @@
1
- #! /usr/bin/env node
2
-
3
- import dotenv from 'dotenv';
4
- import { Command } from 'commander';
5
- import fs from 'fs-extra';
6
- import { pbcopy, shellExec } from '../src/server/process.js';
7
- import Jimp from 'jimp';
8
- import Underpost from '../src/index.js';
9
- import { loggerFactory } from '../src/server/logger.js';
10
- import { DataBaseProvider } from '../src/db/DataBaseProvider.js';
11
-
12
- dotenv.config();
13
-
14
- const logger = loggerFactory(import.meta);
15
-
16
- const deployId = process.env.DEFAULT_DEPLOY_ID;
17
- const host = process.env.DEFAULT_DEPLOY_HOST;
18
- const path = process.env.DEFAULT_DEPLOY_PATH;
19
-
20
- const confServerPath = `./engine-private/conf/${deployId}/conf.server.json`;
21
- const confServer = JSON.parse(fs.readFileSync(confServerPath, 'utf8'));
22
- const { db } = confServer[host][path];
23
-
24
- logger.info('env', {
25
- deployId,
26
- host,
27
- path,
28
- db,
29
- });
30
-
31
- await DataBaseProvider.load({
32
- apis: ['object-layer'],
33
- host,
34
- path,
35
- db,
36
- });
37
-
38
- const ObjectLayer = DataBaseProvider.instance[`${host}${path}`].mongoose.models.ObjectLayer;
39
-
40
- const program = new Command();
41
-
42
- program.name('cyberia').description(`content generator cli ${Underpost.version}`).version(Underpost.version);
43
-
44
- const pngDirectoryIteratorByObjectLayerType = async (
45
- objectLayerType = 'skin',
46
- callback = ({ path, objectLayerType, objectLayerId, direction, frame }) => {},
47
- ) => {
48
- for (const objectLayerId of await fs.readdir(`./src/client/public/cyberia/assets/${objectLayerType}`)) {
49
- for (const direction of await fs.readdir(
50
- `./src/client/public/cyberia/assets/${objectLayerType}/${objectLayerId}`,
51
- )) {
52
- const dirFolder = `./src/client/public/cyberia/assets/${objectLayerType}/${objectLayerId}/${direction}`;
53
- if (!fs.statSync(dirFolder).isDirectory()) continue;
54
- for (const frame of await fs.readdir(dirFolder)) {
55
- const imageFilePath = `./src/client/public/cyberia/assets/${objectLayerType}/${objectLayerId}/${direction}/${frame}`;
56
- await callback({ path: imageFilePath, objectLayerType, objectLayerId, direction, frame });
57
- }
58
- }
59
- }
60
- };
61
-
62
- program
63
- .command('ol')
64
- .option('--import [object-layer-type]', 'Import object layer from type storage png image')
65
- .action(async (options = { import: false }) => {
66
- if (options.import) {
67
- await pngDirectoryIteratorByObjectLayerType(
68
- options.import,
69
- async ({ path, objectLayerType, objectLayerId, direction, frame }) => {
70
- console.log(path, { objectLayerType, objectLayerId, direction, frame });
71
- },
72
- );
73
- }
74
- await DataBaseProvider.instance[`${host}${path}`].mongoose.close();
75
- })
76
- .description('Object layer management');
77
-
78
- program.parse();