@underpostnet/underpost 2.98.3 → 2.99.0

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.
@@ -7,7 +7,7 @@
7
7
  import dotenv from 'dotenv';
8
8
  import { shellExec } from '../server/process.js';
9
9
  import fs from 'fs-extra';
10
- import UnderpostRootEnv from './env.js';
10
+ import Underpost from '../index.js';
11
11
 
12
12
  dotenv.config();
13
13
 
@@ -41,7 +41,7 @@ class UnderpostSecret {
41
41
  createFromEnvFile(envPath) {
42
42
  const envObj = dotenv.parse(fs.readFileSync(envPath, 'utf8'));
43
43
  for (const key of Object.keys(envObj)) {
44
- UnderpostSecret.API.docker.set(key, envObj[key]);
44
+ Underpost.secret.docker.set(key, envObj[key]);
45
45
  }
46
46
  },
47
47
  set(key, value) {
@@ -61,7 +61,7 @@ class UnderpostSecret {
61
61
  createFromEnvFile(envPath) {
62
62
  const envObj = dotenv.parse(fs.readFileSync(envPath, 'utf8'));
63
63
  for (const key of Object.keys(envObj)) {
64
- UnderpostRootEnv.API.set(key, envObj[key]);
64
+ Underpost.env.set(key, envObj[key]);
65
65
  }
66
66
  },
67
67
  },
package/src/cli/ssh.js CHANGED
@@ -5,11 +5,10 @@
5
5
  */
6
6
 
7
7
  import { generateRandomPasswordSelection } from '../client/components/core/CommonJs.js';
8
- import Dns from '../server/dns.js';
9
8
  import { pbcopy, shellExec } from '../server/process.js';
10
9
  import { loggerFactory } from '../server/logger.js';
11
10
  import fs from 'fs-extra';
12
- import UnderpostRootEnv from './env.js';
11
+ import Underpost from '../index.js';
13
12
 
14
13
  const logger = loggerFactory(import.meta);
15
14
 
@@ -252,17 +251,17 @@ EOF`);
252
251
 
253
252
  // Set defaults
254
253
  if (!options.user) options.user = 'root';
255
- if (!options.host) options.host = await Dns.getPublicIp();
254
+ if (!options.host) options.host = await Underpost.dns.getPublicIp();
256
255
  if (!options.password) options.password = options.disablePassword ? '' : generateRandomPasswordSelection(16);
257
256
  if (!options.groups) options.groups = 'wheel';
258
257
  if (!options.port) options.port = 22; // Handle connect uri
259
258
 
260
- const userHome = UnderpostSSH.API.getUserHome(options.user);
259
+ const userHome = Underpost.ssh.getUserHome(options.user);
261
260
  options.userHome = userHome;
262
261
 
263
262
  // Load config and override password and host if user exists in config
264
263
  if (options.deployId) {
265
- const config = UnderpostSSH.API.loadConfigNode(options.deployId);
264
+ const config = Underpost.ssh.loadConfigNode(options.deployId);
266
265
  confNode = config.confNode;
267
266
  confNodePath = config.confNodePath;
268
267
 
@@ -335,7 +334,7 @@ EOF`);
335
334
  // Remove the private key copy folder and update config only if deployId is provided
336
335
  if (options.deployId) {
337
336
  if (!confNode) {
338
- const config = UnderpostSSH.API.loadConfigNode(options.deployId);
337
+ const config = Underpost.ssh.loadConfigNode(options.deployId);
339
338
  confNode = config.confNode;
340
339
  confNodePath = config.confNodePath;
341
340
  }
@@ -347,7 +346,7 @@ EOF`);
347
346
  }
348
347
 
349
348
  delete confNode.users[options.user];
350
- UnderpostSSH.API.saveConfigNode(confNodePath, confNode);
349
+ Underpost.ssh.saveConfigNode(confNodePath, confNode);
351
350
  }
352
351
 
353
352
  logger.info(`User removed`);
@@ -362,7 +361,7 @@ EOF`);
362
361
  // If deployId is provided, check for existing config and backup keys
363
362
  if (options.deployId) {
364
363
  if (!confNode) {
365
- const config = UnderpostSSH.API.loadConfigNode(options.deployId);
364
+ const config = Underpost.ssh.loadConfigNode(options.deployId);
366
365
  confNode = config.confNode;
367
366
  confNodePath = config.confNodePath;
368
367
  }
@@ -378,14 +377,14 @@ EOF`);
378
377
  logger.info(`User ${options.user} already exists in config. Importing existing keys...`);
379
378
 
380
379
  // Create system user if it doesn't exist
381
- const userExists = UnderpostSSH.API.checkUserExists(options.user);
380
+ const userExists = Underpost.ssh.checkUserExists(options.user);
382
381
  if (!userExists) {
383
- UnderpostSSH.API.createSystemUser(options.user, options.password, options.groups);
382
+ Underpost.ssh.createSystemUser(options.user, options.password, options.groups);
384
383
  }
385
384
 
386
- const userHome = UnderpostSSH.API.getUserHome(options.user);
385
+ const userHome = Underpost.ssh.getUserHome(options.user);
387
386
  const sshDir = `${userHome}/.ssh`;
388
- UnderpostSSH.API.ensureSSHDirectory(sshDir);
387
+ Underpost.ssh.ensureSSHDirectory(sshDir);
389
388
 
390
389
  const userKeyPath = `${sshDir}/id_rsa`;
391
390
  const userPubKeyPath = `${sshDir}/id_rsa.pub`;
@@ -394,10 +393,10 @@ EOF`);
394
393
  fs.copyFileSync(privateKeyPath, userKeyPath);
395
394
  fs.copyFileSync(publicKeyPath, userPubKeyPath);
396
395
 
397
- UnderpostSSH.API.configureAuthorizedKeys(sshDir, userPubKeyPath, options.disablePassword);
398
- UnderpostSSH.API.configureSudoAccess(options.user, options.password, options.disablePassword);
399
- UnderpostSSH.API.configureKnownHosts(sshDir, options.port, options.host);
400
- UnderpostSSH.API.setSSHFilePermissions(sshDir, options.user, userKeyPath, userPubKeyPath);
396
+ Underpost.ssh.configureAuthorizedKeys(sshDir, userPubKeyPath, options.disablePassword);
397
+ Underpost.ssh.configureSudoAccess(options.user, options.password, options.disablePassword);
398
+ Underpost.ssh.configureKnownHosts(sshDir, options.port, options.host);
399
+ Underpost.ssh.setSSHFilePermissions(sshDir, options.user, userKeyPath, userPubKeyPath);
401
400
 
402
401
  logger.info(`Keys imported from ${privateCopyDir} to ${sshDir}`);
403
402
  logger.info(`User added with existing keys`);
@@ -406,11 +405,11 @@ EOF`);
406
405
  }
407
406
 
408
407
  // New user or no existing keys - create new user and generate keys
409
- UnderpostSSH.API.createSystemUser(options.user, options.password, options.groups);
408
+ Underpost.ssh.createSystemUser(options.user, options.password, options.groups);
410
409
 
411
- const userHome = UnderpostSSH.API.getUserHome(options.user);
410
+ const userHome = Underpost.ssh.getUserHome(options.user);
412
411
  const sshDir = `${userHome}/.ssh`;
413
- UnderpostSSH.API.ensureSSHDirectory(sshDir);
412
+ Underpost.ssh.ensureSSHDirectory(sshDir);
414
413
 
415
414
  const keyPath = `${sshDir}/id_rsa`;
416
415
  const pubKeyPath = `${sshDir}/id_rsa.pub`;
@@ -421,10 +420,10 @@ EOF`);
421
420
  );
422
421
  }
423
422
 
424
- UnderpostSSH.API.configureAuthorizedKeys(sshDir, pubKeyPath, options.disablePassword);
425
- UnderpostSSH.API.configureSudoAccess(options.user, options.password, options.disablePassword);
426
- UnderpostSSH.API.configureKnownHosts(sshDir, options.port, options.host);
427
- UnderpostSSH.API.setSSHFilePermissions(sshDir, options.user, keyPath, pubKeyPath);
423
+ Underpost.ssh.configureAuthorizedKeys(sshDir, pubKeyPath, options.disablePassword);
424
+ Underpost.ssh.configureSudoAccess(options.user, options.password, options.disablePassword);
425
+ Underpost.ssh.configureKnownHosts(sshDir, options.port, options.host);
426
+ Underpost.ssh.setSSHFilePermissions(sshDir, options.user, keyPath, pubKeyPath);
428
427
 
429
428
  // Save a copy of the keys to the private folder only if deployId is provided
430
429
  if (options.deployId) {
@@ -447,7 +446,7 @@ EOF`);
447
446
  privateKeyCopyPath,
448
447
  publicKeyCopyPath,
449
448
  };
450
- UnderpostSSH.API.saveConfigNode(confNodePath, confNode);
449
+ Underpost.ssh.saveConfigNode(confNodePath, confNode);
451
450
  }
452
451
 
453
452
  logger.info(`User added`);
@@ -457,7 +456,7 @@ EOF`);
457
456
  // Handle config user listing (only with deployId)
458
457
  if (options.deployId) {
459
458
  if (!confNode) {
460
- const config = UnderpostSSH.API.loadConfigNode(options.deployId);
459
+ const config = Underpost.ssh.loadConfigNode(options.deployId);
461
460
  confNode = config.confNode;
462
461
  confNodePath = config.confNodePath;
463
462
  }
@@ -472,7 +471,7 @@ EOF`);
472
471
 
473
472
  // Handle generate root keys
474
473
  if (options.generate)
475
- UnderpostSSH.API.generateKeys({ user: options.user, password: options.password, host: options.host });
474
+ Underpost.ssh.generateKeys({ user: options.user, password: options.password, host: options.host });
476
475
 
477
476
  // Handle list operations
478
477
  if (options.keysList) shellExec(`cat ${userHome}/.ssh/authorized_keys`);
@@ -489,8 +488,8 @@ EOF`);
489
488
 
490
489
  // Handle start server
491
490
  if (options.start) {
492
- UnderpostSSH.API.chmod({ user: options.user });
493
- UnderpostSSH.API.initService({ port: options.port });
491
+ Underpost.ssh.chmod({ user: options.user });
492
+ Underpost.ssh.initService({ port: options.port });
494
493
  }
495
494
 
496
495
  // Handle status server
@@ -512,10 +511,10 @@ EOF`);
512
511
  if (fs.existsSync(confNodePath)) {
513
512
  const { users } = JSON.parse(fs.readFileSync(confNodePath, 'utf8'));
514
513
  const { user, host, keyPath, port } = users[options.user];
515
- UnderpostRootEnv.API.set('DEFAULT_SSH_USER', user);
516
- UnderpostRootEnv.API.set('DEFAULT_SSH_HOST', host);
517
- UnderpostRootEnv.API.set('DEFAULT_SSH_KEY_PATH', keyPath);
518
- UnderpostRootEnv.API.set('DEFAULT_SSH_PORT', port);
514
+ Underpost.env.set('DEFAULT_SSH_USER', user);
515
+ Underpost.env.set('DEFAULT_SSH_HOST', host);
516
+ Underpost.env.set('DEFAULT_SSH_KEY_PATH', keyPath);
517
+ Underpost.env.set('DEFAULT_SSH_PORT', port);
519
518
  } else logger.warn(`No SSH config found at ${confNodePath}`);
520
519
  },
521
520
 
package/src/cli/static.js CHANGED
@@ -412,7 +412,7 @@ class UnderpostStatic {
412
412
  // Handle config template generation
413
413
  if (options.generateConfig) {
414
414
  const configPath = typeof options.generateConfig === 'string' ? options.generateConfig : './static-config.json';
415
- return UnderpostStatic.API.generateConfigTemplate(configPath);
415
+ return Underpost.static.generateConfigTemplate(configPath);
416
416
  }
417
417
 
418
418
  // Parse comma-separated options
package/src/cli/test.js CHANGED
@@ -9,8 +9,7 @@ import { MariaDB } from '../db/mariadb/MariaDB.js';
9
9
  import { getNpmRootPath } from '../server/conf.js';
10
10
  import { actionInitLog, loggerFactory, setUpInfo } from '../server/logger.js';
11
11
  import { pbcopy, shellExec } from '../server/process.js';
12
- import UnderpostDeploy from './deploy.js';
13
-
12
+ import Underpost from '../index.js';
14
13
  const logger = loggerFactory(import.meta);
15
14
 
16
15
  /**
@@ -67,10 +66,10 @@ class UnderpostTest {
67
66
  options.podStatus &&
68
67
  typeof options.podStatus === 'string'
69
68
  )
70
- return await UnderpostTest.API.statusMonitor(options.podName, options.podStatus, options.kindType);
69
+ return await Underpost.test.statusMonitor(options.podName, options.podStatus, options.kindType);
71
70
 
72
71
  if (options.sh === true || options.logs === true) {
73
- const [pod] = UnderpostDeploy.API.get(deployList);
72
+ const [pod] = Underpost.deploy.get(deployList);
74
73
  if (pod) {
75
74
  if (options.sh) return pbcopy(`sudo kubectl exec -it ${pod.NAME} -- sh`);
76
75
  if (options.logs) return shellExec(`sudo kubectl logs -f ${pod.NAME}`);
@@ -104,7 +103,7 @@ class UnderpostTest {
104
103
  break;
105
104
  }
106
105
  else {
107
- const pods = UnderpostDeploy.API.get(deployId);
106
+ const pods = Underpost.deploy.get(deployId);
108
107
  if (pods.length > 0)
109
108
  for (const deployData of pods) {
110
109
  const { NAME } = deployData;
@@ -115,7 +114,7 @@ class UnderpostTest {
115
114
  else logger.warn(`Couldn't find pods in deployment`, { deployId });
116
115
  }
117
116
  }
118
- } else return UnderpostTest.API.run();
117
+ } else return Underpost.test.run();
119
118
  },
120
119
  /**
121
120
  * @method statusMonitor
@@ -134,7 +133,7 @@ class UnderpostTest {
134
133
  logger.info(`Loading instance`, { podName, status, kindType, deltaMs, maxAttempts });
135
134
  const _monitor = async () => {
136
135
  await timer(deltaMs);
137
- const pods = UnderpostDeploy.API.get(podName, kindType);
136
+ const pods = Underpost.deploy.get(podName, kindType);
138
137
  let result = pods.find((p) => p.STATUS === status || (status === 'Running' && p.STATUS === 'Completed'));
139
138
  logger.info(
140
139
  `Testing pod ${podName}... ${result ? 1 : 0}/1 - elapsed time ${deltaMs * (index + 1)}s - attempt ${
package/src/index.js CHANGED
@@ -7,7 +7,6 @@
7
7
  import UnderpostBaremetal from './cli/baremetal.js';
8
8
  import UnderpostCloudInit from './cli/cloud-init.js';
9
9
  import UnderpostCluster from './cli/cluster.js';
10
- import UnderpostCron from './cli/cron.js';
11
10
  import UnderpostDB from './cli/db.js';
12
11
  import UnderpostDeploy from './cli/deploy.js';
13
12
  import UnderpostRootEnv from './cli/env.js';
@@ -17,11 +16,14 @@ import UnderpostLxd from './cli/lxd.js';
17
16
  import UnderpostMonitor from './cli/monitor.js';
18
17
  import UnderpostRepository from './cli/repository.js';
19
18
  import UnderpostRun from './cli/run.js';
20
- import UnderpostScript from './cli/script.js';
21
19
  import UnderpostSecret from './cli/secrets.js';
22
20
  import UnderpostSSH from './cli/ssh.js';
23
21
  import UnderpostStatic from './cli/static.js';
24
22
  import UnderpostTest from './cli/test.js';
23
+
24
+ import UnderpostDns from './server/dns.js';
25
+ import UnderpostBackup from './server/backup.js';
26
+ import UnderpostCron from './server/cron.js';
25
27
  import UnderpostStartUp from './server/start.js';
26
28
 
27
29
  /**
@@ -36,7 +38,7 @@ class Underpost {
36
38
  * @type {String}
37
39
  * @memberof Underpost
38
40
  */
39
- static version = 'v2.98.3';
41
+ static version = 'v2.99.0';
40
42
  /**
41
43
  * Repository cli API
42
44
  * @static
@@ -64,15 +66,7 @@ class Underpost {
64
66
  static get test() {
65
67
  return UnderpostTest.API;
66
68
  }
67
- /**
68
- * Underpost Start Up cli API
69
- * @static
70
- * @type {UnderpostStartUp.API}
71
- * @memberof Underpost
72
- */
73
- static get start() {
74
- return UnderpostStartUp.API;
75
- }
69
+
76
70
  /**
77
71
  * Static cli API
78
72
  * @static
@@ -110,15 +104,6 @@ class Underpost {
110
104
  static get secret() {
111
105
  return UnderpostSecret.API;
112
106
  }
113
- /**
114
- * Scripts cli API
115
- * @static
116
- * @type {UnderpostScript.API}
117
- * @memberof Underpost
118
- */
119
- static get script() {
120
- return UnderpostScript.API;
121
- }
122
107
  /**
123
108
  * Database cli API
124
109
  * @static
@@ -137,15 +122,6 @@ class Underpost {
137
122
  static get deploy() {
138
123
  return UnderpostDeploy.API;
139
124
  }
140
- /**
141
- * Cron cli API
142
- * @static
143
- * @type {UnderpostCron.API}
144
- * @memberof Underpost
145
- */
146
- static get cron() {
147
- return UnderpostCron.API;
148
- }
149
125
  /**
150
126
  * File Storage cli API
151
127
  * @static
@@ -212,6 +188,46 @@ class Underpost {
212
188
  static get baremetal() {
213
189
  return UnderpostBaremetal.API;
214
190
  }
191
+
192
+ /**
193
+ * Dns cli API
194
+ * @static
195
+ * @type {UnderpostDns.API}
196
+ * @memberof Underpost
197
+ */
198
+ static get dns() {
199
+ return UnderpostDns.API;
200
+ }
201
+
202
+ /**
203
+ * BackUp cli API
204
+ * @static
205
+ * @type {UnderpostBackup.API}
206
+ * @memberof Underpost
207
+ */
208
+ static get backup() {
209
+ return UnderpostBackup.API;
210
+ }
211
+
212
+ /**
213
+ * Cron cli API
214
+ * @static
215
+ * @type {UnderpostCron.API}
216
+ * @memberof Underpost
217
+ */
218
+ static get cron() {
219
+ return UnderpostCron.API;
220
+ }
221
+
222
+ /**
223
+ * Start Up cli API
224
+ * @static
225
+ * @type {UnderpostStartUp.API}
226
+ * @memberof Underpost
227
+ */
228
+ static get start() {
229
+ return UnderpostStartUp.API;
230
+ }
215
231
  }
216
232
 
217
233
  const up = Underpost;
@@ -225,7 +241,6 @@ export {
225
241
  UnderpostBaremetal,
226
242
  UnderpostCloudInit,
227
243
  UnderpostCluster,
228
- UnderpostCron,
229
244
  UnderpostDB,
230
245
  UnderpostDeploy,
231
246
  UnderpostRootEnv,
@@ -236,10 +251,12 @@ export {
236
251
  UnderpostMonitor,
237
252
  UnderpostRepository,
238
253
  UnderpostRun,
239
- UnderpostScript,
240
254
  UnderpostSecret,
241
255
  UnderpostSSH,
242
256
  UnderpostTest,
257
+ UnderpostDns,
258
+ UnderpostBackup,
259
+ UnderpostCron,
243
260
  UnderpostStartUp,
244
261
  };
245
262
 
@@ -12,7 +12,6 @@ import swaggerUi from 'swagger-ui-express';
12
12
  import compression from 'compression';
13
13
  import { createServer } from 'http';
14
14
 
15
- import UnderpostStartUp from '../../server/start.js';
16
15
  import { loggerFactory, loggerMiddleware } from '../../server/logger.js';
17
16
  import { getCapVariableName, newInstance } from '../../client/components/core/CommonJs.js';
18
17
  import { MailerProvider } from '../../mailer/MailerProvider.js';
@@ -25,6 +24,8 @@ import { TLS } from '../../server/tls.js';
25
24
  import { shellExec } from '../../server/process.js';
26
25
  import { devProxyHostFactory, isDevProxyContext, isTlsDevProxy } from '../../server/conf.js';
27
26
 
27
+ import Underpost from '../../index.js';
28
+
28
29
  const logger = loggerFactory(import.meta);
29
30
 
30
31
  /**
@@ -143,7 +144,7 @@ class ExpressService {
143
144
  }
144
145
  return next();
145
146
  });
146
- await UnderpostStartUp.API.listenPortController(app, port, runningData);
147
+ await Underpost.start.listenPortController(app, port, runningData);
147
148
  return { portsUsed };
148
149
  }
149
150
 
@@ -214,7 +215,7 @@ class ExpressService {
214
215
  const { options, meta, ioServer } = await createIoServer(server, { host, path, db, port, origins });
215
216
 
216
217
  // Listen on the main port for the WS server
217
- await UnderpostStartUp.API.listenPortController(ioServer, port, {
218
+ await Underpost.start.listenPortController(ioServer, port, {
218
219
  runtime: 'nodejs',
219
220
  client: null,
220
221
  host,
@@ -232,7 +233,7 @@ class ExpressService {
232
233
  origins,
233
234
  path,
234
235
  });
235
- await UnderpostStartUp.API.listenPortController(peerServer, peerPort, {
236
+ await Underpost.start.listenPortController(peerServer, peerPort, {
236
237
  runtime: 'nodejs',
237
238
  client: null,
238
239
  host,
@@ -250,8 +251,8 @@ class ExpressService {
250
251
  if (useLocalSsl && process.env.NODE_ENV === 'development') {
251
252
  if (!TLS.validateSecureContext()) shellExec(`node bin/deploy tls`);
252
253
  const { ServerSSL } = await TLS.createSslServer(app);
253
- await UnderpostStartUp.API.listenPortController(ServerSSL, port, runningData);
254
- } else await UnderpostStartUp.API.listenPortController(server, port, runningData);
254
+ await Underpost.start.listenPortController(ServerSSL, port, runningData);
255
+ } else await Underpost.start.listenPortController(server, port, runningData);
255
256
 
256
257
  return { portsUsed };
257
258
  }
@@ -349,7 +349,12 @@ const cookieOptionsFactory = (req, host) => {
349
349
  secure,
350
350
  sameSite,
351
351
  path: '/',
352
- domain: process.env.NODE_ENV === 'production' || isDevProxyContext() ? host : 'localhost',
352
+ domain:
353
+ process.env.NODE_ENV === 'production' ||
354
+ isDevProxyContext() ||
355
+ (req.headers.host && req.headers.host.toLocaleLowerCase().match(host))
356
+ ? host
357
+ : 'localhost',
353
358
  maxAge,
354
359
  };
355
360
 
@@ -43,5 +43,15 @@ class BackUp {
43
43
  }
44
44
  };
45
45
  }
46
+ /**
47
+ * Main UnderpostBakcup class for backup operations.
48
+ * @class UnderpostBakcup
49
+ * @memberof UnderpostBakcup
50
+ */
51
+ class UnderpostBakcUp {
52
+ static API = BackUp;
53
+ }
54
+
55
+ export default UnderpostBakcUp;
46
56
 
47
- export default BackUp;
57
+ export { BackUp, UnderpostBakcUp };
@@ -22,7 +22,7 @@ import { loggerFactory } from './logger.js';
22
22
  import { shellExec } from './process.js';
23
23
  import { DefaultConf } from '../../conf.js';
24
24
  import splitFile from 'split-file';
25
- import UnderpostRootEnv from '../cli/env.js';
25
+ import Underpost from '../index.js';
26
26
 
27
27
  colors.enable();
28
28
 
@@ -59,7 +59,7 @@ const Config = {
59
59
  if (!subConf && process.argv[3] && typeof process.argv[3] === 'string') subConf = process.argv[3];
60
60
  if (!fs.existsSync(`./tmp`)) fs.mkdirSync(`./tmp`);
61
61
  if (!fs.existsSync(`./conf`)) fs.mkdirSync(`./conf`);
62
- UnderpostRootEnv.API.set('await-deploy', new Date().toISOString());
62
+ Underpost.env.set('await-deploy', new Date().toISOString());
63
63
  if (deployContext.startsWith('dd-')) loadConf(deployContext, subConf);
64
64
  if (deployContext === 'proxy') await Config.buildProxy(deployList, subConf);
65
65
  },
@@ -1050,9 +1050,9 @@ const validateTemplatePath = (absolutePath = '') => {
1050
1050
  * @memberof ServerConfBuilder
1051
1051
  */
1052
1052
  const awaitDeployMonitor = async (init = false, deltaMs = 1000) => {
1053
- if (init) UnderpostRootEnv.API.set('await-deploy', new Date().toISOString());
1053
+ if (init) Underpost.env.set('await-deploy', new Date().toISOString());
1054
1054
  await timer(deltaMs);
1055
- if (UnderpostRootEnv.API.get('await-deploy')) return await awaitDeployMonitor();
1055
+ if (Underpost.env.get('await-deploy')) return await awaitDeployMonitor();
1056
1056
  };
1057
1057
 
1058
1058
  /**
@@ -1,15 +1,14 @@
1
1
  /**
2
- * UnderpostCron CLI index module
3
- * @module src/cli/cron.js
2
+ * UnderpostCron server module
3
+ * @module src/server/cron.js
4
4
  * @namespace UnderpostCron
5
5
  */
6
6
 
7
- import BackUp from '../server/backup.js';
8
- import { Cmd } from '../server/conf.js';
9
- import Dns from '../server/dns.js';
10
- import { loggerFactory } from '../server/logger.js';
11
- import { shellExec } from '../server/process.js';
7
+ import { Cmd } from './conf.js';
8
+ import { loggerFactory } from './logger.js';
9
+ import { shellExec } from './process.js';
12
10
  import fs from 'fs-extra';
11
+ import Underpost from '../index.js';
13
12
 
14
13
  const logger = loggerFactory(import.meta);
15
14
 
@@ -19,22 +18,30 @@ const logger = loggerFactory(import.meta);
19
18
  * @memberof UnderpostCron
20
19
  */
21
20
  class UnderpostCron {
22
- static JOB = {
23
- /**
24
- * DNS cli API
25
- * @static
26
- * @type {Dns}
27
- * @memberof UnderpostCron
28
- */
29
- dns: Dns,
30
- /**
31
- * BackUp cli API
32
- * @static
33
- * @type {BackUp}
34
- * @memberof UnderpostCron
35
- */
36
- backup: BackUp,
37
- };
21
+ /**
22
+ * Get the JOB static member
23
+ * @static
24
+ * @type {Object}
25
+ * @memberof UnderpostCron
26
+ */
27
+ static get JOB() {
28
+ return {
29
+ /**
30
+ * DNS cli API
31
+ * @static
32
+ * @type {Dns}
33
+ * @memberof UnderpostCron
34
+ */
35
+ dns: Underpost.dns,
36
+ /**
37
+ * BackUp cli API
38
+ * @static
39
+ * @type {BackUp}
40
+ * @memberof UnderpostCron
41
+ */
42
+ backup: Underpost.backup,
43
+ };
44
+ }
38
45
 
39
46
  static API = {
40
47
  /**
@@ -48,25 +55,25 @@ class UnderpostCron {
48
55
  */
49
56
  callback: async function (
50
57
  deployList = 'default',
51
- jobList = Object.keys(UnderpostCron.JOB).join(','),
58
+ jobList = Object.keys(Underpost.cron.JOB).join(','),
52
59
  options = { initPm2Cronjobs: false, git: false, updatePackageScripts: false },
53
60
  ) {
54
61
  if (options.updatePackageScripts === true) {
55
- await UnderpostCron.API.updatePackageScripts(deployList);
62
+ await Underpost.cron.updatePackageScripts(deployList);
56
63
  return;
57
64
  }
58
65
 
59
66
  if (options.initPm2Cronjobs === true) {
60
- await UnderpostCron.API.initCronJobs(options);
67
+ await Underpost.cron.initCronJobs(options);
61
68
  return;
62
69
  }
63
70
 
64
71
  // Execute the requested jobs
65
72
  for (const _jobId of jobList.split(',')) {
66
73
  const jobId = _jobId.trim();
67
- if (UnderpostCron.JOB[jobId]) {
74
+ if (Underpost.cron.JOB[jobId]) {
68
75
  logger.info(`Executing cron job: ${jobId}`);
69
- await UnderpostCron.JOB[jobId].callback(deployList, options);
76
+ await Underpost.cron.JOB[jobId].callback(deployList, options);
70
77
  } else {
71
78
  logger.warn(`Unknown cron job: ${jobId}`);
72
79
  }
@@ -115,7 +122,7 @@ class UnderpostCron {
115
122
  }
116
123
 
117
124
  const name = `${jobDeployId}-${job}`;
118
- const deployIdList = UnderpostCron.API.getRelatedDeployIdList(job);
125
+ const deployIdList = Underpost.cron.getRelatedDeployIdList(job);
119
126
  const expression = jobConfig.expression || '0 0 * * *'; // Default: daily at midnight
120
127
  const instances = jobConfig.instances || 1; // Default: 1 instance
121
128
 
@@ -221,6 +228,26 @@ class UnderpostCron {
221
228
  // Return the deploy-id list from the file (may be single or comma-separated)
222
229
  return fs.readFileSync(deployFilePath, 'utf8').trim();
223
230
  },
231
+
232
+ /**
233
+ * Get the JOB static object
234
+ * @static
235
+ * @type {Object}
236
+ * @memberof UnderpostCron
237
+ */
238
+ get JOB() {
239
+ return UnderpostCron.JOB;
240
+ },
241
+
242
+ /**
243
+ * Get the list of available job IDs
244
+ * @static
245
+ * @return {Array<String>} List of job IDs
246
+ * @memberof UnderpostCron
247
+ */
248
+ getJobsIDs: function () {
249
+ return Object.keys(UnderpostCron.JOB);
250
+ },
224
251
  };
225
252
  }
226
253