underpost 2.8.1 → 2.8.6

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 (108) hide show
  1. package/.dockerignore +1 -0
  2. package/.github/workflows/ghpkg.yml +19 -49
  3. package/.github/workflows/npmpkg.yml +67 -0
  4. package/.github/workflows/publish.yml +5 -5
  5. package/.github/workflows/pwa-microservices-template.page.yml +12 -4
  6. package/.github/workflows/pwa-microservices-template.test.yml +2 -2
  7. package/.vscode/extensions.json +17 -71
  8. package/.vscode/settings.json +18 -3
  9. package/AUTHORS.md +16 -5
  10. package/CHANGELOG.md +103 -3
  11. package/Dockerfile +24 -66
  12. package/README.md +1 -28
  13. package/bin/build.js +186 -0
  14. package/bin/db.js +2 -24
  15. package/bin/deploy.js +169 -144
  16. package/bin/file.js +59 -16
  17. package/bin/hwt.js +0 -10
  18. package/bin/index.js +201 -60
  19. package/bin/ssl.js +19 -11
  20. package/bin/util.js +9 -104
  21. package/bin/vs.js +26 -2
  22. package/conf.js +29 -138
  23. package/docker-compose.yml +1 -1
  24. package/manifests/deployment/mongo-express/deployment.yaml +60 -0
  25. package/manifests/deployment/phpmyadmin/deployment.yaml +54 -0
  26. package/manifests/kind-config-dev.yaml +12 -0
  27. package/manifests/kind-config.yaml +12 -0
  28. package/manifests/letsencrypt-prod.yaml +15 -0
  29. package/manifests/mariadb/config.yaml +10 -0
  30. package/manifests/mariadb/kustomization.yaml +9 -0
  31. package/manifests/mariadb/pv.yaml +12 -0
  32. package/manifests/mariadb/pvc.yaml +10 -0
  33. package/manifests/mariadb/secret.yaml +8 -0
  34. package/manifests/mariadb/service.yaml +10 -0
  35. package/manifests/mariadb/statefulset.yaml +55 -0
  36. package/manifests/mongodb/backup-access.yaml +16 -0
  37. package/manifests/mongodb/backup-cronjob.yaml +42 -0
  38. package/manifests/mongodb/backup-pv-pvc.yaml +22 -0
  39. package/manifests/mongodb/configmap.yaml +26 -0
  40. package/manifests/mongodb/headless-service.yaml +10 -0
  41. package/manifests/mongodb/kustomization.yaml +11 -0
  42. package/manifests/mongodb/pv-pvc.yaml +23 -0
  43. package/manifests/mongodb/statefulset.yaml +125 -0
  44. package/manifests/mongodb-4.4/kustomization.yaml +7 -0
  45. package/manifests/mongodb-4.4/pv-pvc.yaml +23 -0
  46. package/manifests/mongodb-4.4/service-deployment.yaml +63 -0
  47. package/manifests/valkey/kustomization.yaml +7 -0
  48. package/manifests/valkey/service.yaml +17 -0
  49. package/manifests/valkey/statefulset.yaml +39 -0
  50. package/package.json +133 -136
  51. package/src/api/core/core.service.js +1 -1
  52. package/src/api/user/user.model.js +16 -3
  53. package/src/api/user/user.service.js +1 -1
  54. package/src/cli/cluster.js +202 -0
  55. package/src/cli/cron.js +90 -0
  56. package/src/cli/db.js +212 -0
  57. package/src/cli/deploy.js +318 -0
  58. package/src/cli/env.js +52 -0
  59. package/src/cli/fs.js +149 -0
  60. package/src/cli/image.js +148 -0
  61. package/src/cli/repository.js +125 -0
  62. package/src/cli/script.js +53 -0
  63. package/src/cli/secrets.js +37 -0
  64. package/src/cli/test.js +118 -0
  65. package/src/client/components/core/Auth.js +22 -4
  66. package/src/client/components/core/CalendarCore.js +127 -50
  67. package/src/client/components/core/CommonJs.js +282 -19
  68. package/src/client/components/core/Css.js +1 -0
  69. package/src/client/components/core/CssCore.js +8 -4
  70. package/src/client/components/core/Docs.js +1 -2
  71. package/src/client/components/core/DropDown.js +5 -1
  72. package/src/client/components/core/Input.js +22 -6
  73. package/src/client/components/core/LoadingAnimation.js +8 -1
  74. package/src/client/components/core/Modal.js +40 -12
  75. package/src/client/components/core/Panel.js +92 -31
  76. package/src/client/components/core/PanelForm.js +25 -23
  77. package/src/client/components/core/Scroll.js +1 -0
  78. package/src/client/components/core/Translate.js +47 -9
  79. package/src/client/components/core/Validator.js +9 -1
  80. package/src/client/components/core/VanillaJs.js +0 -9
  81. package/src/client/components/core/Worker.js +34 -31
  82. package/src/client/services/core/core.service.js +15 -10
  83. package/src/client/services/default/default.management.js +4 -2
  84. package/src/client/ssr/Render.js +4 -1
  85. package/src/client/ssr/body/CacheControl.js +2 -3
  86. package/src/client/sw/default.sw.js +3 -3
  87. package/src/db/mongo/MongooseDB.js +29 -1
  88. package/src/index.js +85 -19
  89. package/src/runtime/lampp/Lampp.js +1 -13
  90. package/src/runtime/xampp/Xampp.js +0 -13
  91. package/src/server/auth.js +3 -3
  92. package/src/server/backup.js +49 -93
  93. package/src/server/client-build.js +36 -46
  94. package/src/server/client-formatted.js +6 -3
  95. package/src/server/conf.js +204 -54
  96. package/src/server/dns.js +30 -55
  97. package/src/server/downloader.js +0 -8
  98. package/src/server/logger.js +15 -10
  99. package/src/server/network.js +17 -43
  100. package/src/server/process.js +25 -2
  101. package/src/server/proxy.js +4 -26
  102. package/src/server/runtime.js +30 -30
  103. package/src/server/ssl.js +1 -1
  104. package/src/server/valkey.js +2 -0
  105. package/test/api.test.js +0 -8
  106. package/src/dns.js +0 -22
  107. package/src/server/prompt-optimizer.js +0 -28
  108. package/startup.js +0 -11
@@ -1,120 +1,76 @@
1
1
  import fs from 'fs-extra';
2
2
  import { loggerFactory } from './logger.js';
3
- import { shellCd, shellExec } from './process.js';
4
- import { getCronBackUpFolder, getDataDeploy } from './conf.js';
3
+ import { shellExec } from './process.js';
4
+ import { getCronBackUpFolder } from './conf.js';
5
5
  import dotenv from 'dotenv';
6
6
 
7
7
  dotenv.config();
8
8
 
9
9
  const logger = loggerFactory(import.meta);
10
10
 
11
- const BackUpManagement = {
12
- repoUrl: `https://${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_USERNAME}/${process.env.GITHUB_BACKUP_REPO}.git`,
13
- Init: async function ({ deployId }) {
14
- const Callback = async function () {
15
- const privateCronConfPath = `./engine-private/conf/${deployId}/conf.cron.json`;
11
+ class BackUp {
12
+ static callback = async function (deployList, options = { itc: false, git: false }) {
13
+ if ((!deployList || deployList === 'dd') && fs.existsSync(`./engine-private/deploy/dd.router`))
14
+ deployList = fs.readFileSync(`./engine-private/deploy/dd.router`, 'utf8');
16
15
 
17
- const confCronPath = fs.existsSync(privateCronConfPath) ? privateCronConfPath : './conf/conf.cron.json';
16
+ logger.info('init backups callback', deployList);
17
+ await logger.setUpInfo();
18
+ const currentDate = new Date().getTime();
19
+ const maxBackupRetention = 5;
18
20
 
19
- const { backups } = JSON.parse(fs.readFileSync(confCronPath, 'utf8'));
21
+ if (!fs.existsSync('./engine-private/cron-backups'))
22
+ fs.mkdirSync('./engine-private/cron-backups', { recursive: true });
20
23
 
21
- if (!backups) return;
24
+ for (const _deployId of deployList.split(',')) {
25
+ const deployId = _deployId.trim();
26
+ if (!deployId) continue;
22
27
 
23
- logger.info('init backups callback');
24
- await logger.setUpInfo();
25
-
26
- const currentDate = new Date().getTime();
27
-
28
- if (!fs.existsSync('./engine-private/cron-backups'))
29
- fs.mkdirSync('./engine-private/cron-backups', { recursive: true });
30
-
31
- for (const deployGroupData of backups) {
32
- const { deployGroupId } = deployGroupData;
33
- const dataDeploy = getDataDeploy({ deployGroupId });
34
-
35
- for (const deployObj of dataDeploy) {
36
- const { deployId, replicaHost } = deployObj;
37
-
38
- if (replicaHost) continue;
39
-
40
- const confServer = JSON.parse(
41
- fs.existsSync(`./engine-private/replica/${deployId}/conf.server.json`)
42
- ? fs.readFileSync(`./engine-private/replica/${deployId}/conf.server.json`, 'utf8')
43
- : fs.readFileSync(`./engine-private/conf/${deployId}/conf.server.json`, 'utf8'),
44
- );
45
-
46
- for (const host of Object.keys(confServer))
47
- for (const path of Object.keys(confServer[host])) {
48
- // retention policy
49
- let { db, backupFrequency, maxBackupRetention, singleReplica, wp, git, directory } =
50
- confServer[host][path];
51
-
52
- if (!db || singleReplica) continue;
53
-
54
- if (!backupFrequency) backupFrequency = 'daily';
55
- if (!maxBackupRetention) maxBackupRetention = 5;
56
-
57
- const backUpPath = `${process.cwd()}/engine-private/cron-backups/${getCronBackUpFolder(host, path)}`;
58
- if (!fs.existsSync(backUpPath)) fs.mkdirSync(`${backUpPath}`, { recursive: true });
59
- // .isDirectory()
60
- const files = await fs.readdir(backUpPath, { withFileTypes: true });
61
-
62
- const currentBackupsDirs = files
63
- .map((fileObj) => parseInt(fileObj.name))
64
- .sort((a, b) => a - b)
65
- .reverse();
28
+ if (!(options.itc === true)) {
29
+ shellExec(`node bin db ${options.git ? '--git ' : ''}--export ${deployId}`);
30
+ continue;
31
+ }
66
32
 
67
- switch (backupFrequency) {
68
- case 'daily':
33
+ const confServer = JSON.parse(fs.readFileSync(`./engine-private/conf/${deployId}/conf.server.json`, 'utf8'));
69
34
 
70
- default:
71
- // if (currentBackupsDirs[0] && currentDate - currentBackupsDirs[0] < 1000 * 60 * 60 * 24) continue;
72
- break;
73
- }
35
+ for (const host of Object.keys(confServer))
36
+ for (const path of Object.keys(confServer[host])) {
37
+ // retention policy
38
+ const { db } = confServer[host][path];
39
+ if (!db) continue;
40
+ logger.info('Init backup', { host, path, db });
74
41
 
75
- for (const retentionPath of currentBackupsDirs.filter((t, i) => i >= maxBackupRetention - 1)) {
76
- const removePathRetention = `${backUpPath}/${retentionPath}`;
77
- logger.info('Remove backup folder', removePathRetention);
78
- fs.removeSync(removePathRetention);
79
- }
42
+ const backUpPath = `${process.cwd()}/engine-private/cron-backups/${getCronBackUpFolder(host, path)}`;
43
+ if (!fs.existsSync(backUpPath)) fs.mkdirSync(`${backUpPath}`, { recursive: true });
44
+ // .isDirectory()
45
+ const files = await fs.readdir(backUpPath, { withFileTypes: true });
80
46
 
81
- fs.mkdirSync(`${backUpPath}/${currentDate}`, { recursive: true });
47
+ const currentBackupsDirs = files
48
+ .map((fileObj) => parseInt(fileObj.name))
49
+ .sort((a, b) => a - b)
50
+ .reverse();
82
51
 
83
- shellExec(`node bin/db ${host}${path} export ${deployId} ${backUpPath}/${currentDate}`);
52
+ for (const retentionPath of currentBackupsDirs.filter((t, i) => i >= maxBackupRetention - 1)) {
53
+ const removePathRetention = `${backUpPath}/${retentionPath}`;
54
+ logger.info('Remove backup folder', removePathRetention);
55
+ fs.removeSync(removePathRetention);
56
+ }
84
57
 
85
- if (wp) {
86
- const repoUrl = `https://${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_USERNAME}/${git
87
- .split('/')
88
- .pop()}.git`;
58
+ fs.mkdirSync(`${backUpPath}/${currentDate}`, { recursive: true });
89
59
 
90
- shellExec(
91
- `cd ${directory}` +
92
- ` && git pull ${repoUrl}` +
93
- ` && git add . && git commit -m "backup ${new Date().toLocaleDateString()}"` +
94
- ` && git push ${repoUrl}`,
95
- {
96
- disableLog: true,
97
- },
98
- );
99
- }
100
- }
60
+ shellExec(`node bin/db ${host}${path} export ${deployId} ${backUpPath}/${currentDate}`);
101
61
  }
102
- }
103
62
  shellExec(
104
63
  `cd ./engine-private/cron-backups` +
105
- ` && git pull ${BackUpManagement.repoUrl}` +
106
- ` && git add . && git commit -m "backup ${new Date().toLocaleDateString()}"` +
107
- ` && git push ${BackUpManagement.repoUrl}`,
64
+ ` && underpost pull . underpostnet/cron-backups` +
65
+ ` && git add .` +
66
+ ` && underpost cmt . backup cron-job '${new Date().toLocaleDateString()}'` +
67
+ ` && underpost push . underpostnet/cron-backups`,
108
68
  {
109
69
  disableLog: true,
110
70
  },
111
71
  );
112
- };
113
- await Callback();
114
- BackUpManagement.Callback = Callback;
115
- return Callback;
116
- },
117
- Callback: async function (params) {},
118
- };
72
+ }
73
+ };
74
+ }
119
75
 
120
- export { BackUpManagement };
76
+ export default BackUp;
@@ -21,6 +21,7 @@ import swaggerAutoGen from 'swagger-autogen';
21
21
  import { SitemapStream, streamToPromise } from 'sitemap';
22
22
  import { Readable } from 'stream';
23
23
  import { buildIcons, buildTextImg, getBufferPngText } from './client-icons.js';
24
+ import Underpost from '../index.js';
24
25
 
25
26
  dotenv.config();
26
27
 
@@ -50,10 +51,10 @@ const fullBuild = async ({
50
51
  buildAcmeChallengePath(acmeChallengeFullPath);
51
52
 
52
53
  if (publicClientId && publicClientId.startsWith('html-website-templates')) {
53
- if (!fs.existsSync(`/dd/html-website-templates/`))
54
- shellExec(`cd /dd && git clone https://github.com/designmodo/html-website-templates.git`);
54
+ if (!fs.existsSync(`/home/dd/html-website-templates/`))
55
+ shellExec(`cd /home/dd && git clone https://github.com/designmodo/html-website-templates.git`);
55
56
  if (!fs.existsSync(`${rootClientPath}/index.php`)) {
56
- fs.copySync(`/dd/html-website-templates/${publicClientId.split('-publicClientId-')[1]}`, rootClientPath);
57
+ fs.copySync(`/home/dd/html-website-templates/${publicClientId.split('-publicClientId-')[1]}`, rootClientPath);
57
58
  shellExec(`cd ${rootClientPath} && git init && git add . && git commit -m "Base template implementation"`);
58
59
  // git remote add origin git@github.com:<username>/<repo>.git
59
60
  fs.writeFileSync(`${rootClientPath}/.git/.htaccess`, `Deny from all`, 'utf8');
@@ -191,8 +192,7 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [] }
191
192
 
192
193
  if (redirect || disabledRebuild) continue;
193
194
 
194
- if (fullBuildEnabled) {
195
- // !(confServer[host]['/'] && confServer[host]['/'].liteBuild)
195
+ if (fullBuildEnabled)
196
196
  await fullBuild({
197
197
  path,
198
198
  logger,
@@ -205,14 +205,6 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [] }
205
205
  iconsBuild,
206
206
  metadata,
207
207
  });
208
- if (apis && false)
209
- for (const apiBuildScript of apis) {
210
- const scriptPath = `src/api/${apiBuildScript}/${apiBuildScript}.build.js`;
211
- if (fs.existsSync(`./${scriptPath}`)) {
212
- shellExec(`node ${scriptPath}`);
213
- }
214
- }
215
- }
216
208
 
217
209
  if (components)
218
210
  for (const module of Object.keys(components)) {
@@ -259,20 +251,6 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [] }
259
251
  'services',
260
252
  baseHost,
261
253
  );
262
- if (module === 'core' && (process.env.NODE_ENV === 'production' || process.argv.includes('static'))) {
263
- if (apiBaseHost)
264
- jsSrc = jsSrc.replace(
265
- 'const getBaseHost = () => location.host;',
266
- `const getBaseHost = () => '${apiBaseHost}';`,
267
- );
268
- if (apiBaseProxyPath) {
269
- jsSrc = jsSrc.replace('${getProxyPath()}api/', `${apiBaseProxyPath}${process.env.BASE_API}/`);
270
- jsSrc = jsSrc.replace(
271
- "const getWsBasePath = () => (getProxyPath() !== '/' ? `${getProxyPath()}socket.io/` : undefined);",
272
- `const getWsBasePath = () => '${apiBaseProxyPath}socket.io/';`,
273
- );
274
- }
275
- }
276
254
  fs.writeFileSync(
277
255
  jsPublicPath,
278
256
  minifyBuild || process.env.NODE_ENV === 'production' ? UglifyJS.minify(jsSrc).code : jsSrc,
@@ -496,7 +474,13 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [] }
496
474
  }
497
475
 
498
476
  default:
499
- ssrBodyComponents += SrrComponent({ ssrPath, host, path, ttiLoadTimeLimit });
477
+ ssrBodyComponents += SrrComponent({
478
+ ssrPath,
479
+ host,
480
+ path,
481
+ ttiLoadTimeLimit,
482
+ version: Underpost.version,
483
+ });
500
484
  break;
501
485
  }
502
486
  }
@@ -516,6 +500,15 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [] }
516
500
  ssrPath,
517
501
  ssrHeadComponents,
518
502
  ssrBodyComponents,
503
+ renderPayload: {
504
+ apiBaseProxyPath,
505
+ apiBaseHost,
506
+ apiBasePath: process.env.BASE_API,
507
+ version: Underpost.version,
508
+ },
509
+ renderApi: {
510
+ JSONweb,
511
+ },
519
512
  });
520
513
 
521
514
  fs.writeFileSync(
@@ -545,17 +538,7 @@ const buildClient = async (options = { liveClientBuildPaths: [], instances: [] }
545
538
  let siteMapSrc = await new Promise((resolve) =>
546
539
  streamToPromise(Readable.from(siteMapLinks).pipe(siteMapStream)).then((data) => resolve(data.toString())),
547
540
  );
548
- switch (publicClientId) {
549
- case 'underpost':
550
- siteMapSrc = siteMapSrc.replaceAll(
551
- `</urlset>`,
552
- `${fs.readFileSync(`./src/client/public/underpost/sitemap-template.txt`, 'utf8')} </urlset>`,
553
- );
554
- break;
555
541
 
556
- default:
557
- break;
558
- }
559
542
  // Return a promise that resolves with your XML string
560
543
  fs.writeFileSync(`${rootClientPath}/sitemap.xml`, siteMapSrc, 'utf8');
561
544
  if (xslUrl)
@@ -726,6 +709,15 @@ root file where the route starts, such as index.js, app.js, routes.js, etc ... *
726
709
  ssrPath,
727
710
  ssrHeadComponents: '',
728
711
  ssrBodyComponents: SsrComponent(),
712
+ renderPayload: {
713
+ apiBaseProxyPath,
714
+ apiBaseHost,
715
+ apiBasePath: process.env.BASE_API,
716
+ version: Underpost.version,
717
+ },
718
+ renderApi: {
719
+ JSONweb,
720
+ },
729
721
  });
730
722
 
731
723
  const buildPath = `${
@@ -758,16 +750,14 @@ root file where the route starts, such as index.js, app.js, routes.js, etc ... *
758
750
  }
759
751
 
760
752
  {
761
- const PRE_CACHED_JSON = `PRE_CACHED_RESOURCES = ${JSONweb(uniqueArray(PRE_CACHED_RESOURCES))}`;
762
- const PROXY_PATH = `PROXY_PATH = '${path}'`;
753
+ const renderPayload = {
754
+ PRE_CACHED_RESOURCES: uniqueArray(PRE_CACHED_RESOURCES),
755
+ PROXY_PATH: path,
756
+ };
763
757
  fs.writeFileSync(
764
758
  `${rootClientPath}/sw.js`,
765
- fs
766
- .readFileSync(`${rootClientPath}/sw.js`, 'utf8')
767
- .replaceAll(`PRE_CACHED_RESOURCES = []`, PRE_CACHED_JSON)
768
- .replaceAll(`PRE_CACHED_RESOURCES=[]`, PRE_CACHED_JSON)
769
- .replaceAll(`PROXY_PATH = '/'`, PROXY_PATH)
770
- .replaceAll(`PROXY_PATH='/'`, PROXY_PATH),
759
+ `self.renderPayload = ${JSONweb(renderPayload)};
760
+ ${fs.readFileSync(`${rootClientPath}/sw.js`, 'utf8')}`,
771
761
  'utf8',
772
762
  );
773
763
  }
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  import fs from 'fs-extra';
4
+ import vm from 'node:vm';
5
+ import Underpost from '../index.js';
4
6
 
5
7
  const srcFormatted = (src) =>
6
8
  src
@@ -48,9 +50,10 @@ const viewFormatted = (src, dists, proxyPath, baseHost = '') => {
48
50
  };
49
51
 
50
52
  const ssrFactory = async (componentPath = `./src/client/ssr/Render.js`) => {
51
- let SrrComponent = () => {};
52
- eval(await srcFormatted(fs.readFileSync(componentPath, 'utf8')));
53
- return SrrComponent;
53
+ const context = { SrrComponent: () => {}, npm_package_version: Underpost.version };
54
+ vm.createContext(context);
55
+ vm.runInContext(await srcFormatted(fs.readFileSync(componentPath, 'utf8')), context);
56
+ return context.SrrComponent;
54
57
  };
55
58
 
56
59
  export { srcFormatted, JSONweb, componentFormatted, viewFormatted, ssrFactory };