mstate-cli 0.4.3 → 0.4.4
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/.prettierrc +5 -5
- package/Readme.md +39 -39
- package/dist/index.js +30 -30
- package/package.json +46 -46
- package/rollup.config.mjs +34 -34
- package/src/common/constant.ts +19 -19
- package/src/common/enum.ts +30 -26
- package/src/common/helpers.ts +85 -83
- package/src/common/utils.ts +67 -67
- package/src/handlers/action.handler.ts +94 -94
- package/src/handlers/company.handler.ts +226 -202
- package/src/handlers/environment.handler.ts +77 -77
- package/src/handlers/help.handler.ts +122 -81
- package/src/handlers/mobioffice.handler.ts +43 -43
- package/src/handlers/workflow.handler.ts +207 -174
- package/src/index.ts +94 -85
- package/src/interface.d.ts +43 -43
- package/tsconfig.json +18 -18
package/package.json
CHANGED
@@ -1,46 +1,46 @@
|
|
1
|
-
{
|
2
|
-
"name": "mstate-cli",
|
3
|
-
"version": "0.4.
|
4
|
-
"main": "index.js",
|
5
|
-
"bin": {
|
6
|
-
"mstate": "./dist/index.js"
|
7
|
-
},
|
8
|
-
"scripts": {
|
9
|
-
"build": "rollup -c",
|
10
|
-
"dev": "rollup -c --watch",
|
11
|
-
"prod": "npm run build",
|
12
|
-
"start": "npm run build && node dist/index.js"
|
13
|
-
},
|
14
|
-
"keywords": [
|
15
|
-
"mstate",
|
16
|
-
"workflow",
|
17
|
-
"cli",
|
18
|
-
"automation",
|
19
|
-
"mobioffice"
|
20
|
-
],
|
21
|
-
"author": "",
|
22
|
-
"license": "ISC",
|
23
|
-
"description": "A CLI tool for maintaining mstate workflows config",
|
24
|
-
"devDependencies": {
|
25
|
-
"@rollup/plugin-alias": "^5.1.1",
|
26
|
-
"@rollup/plugin-commonjs": "^28.0.1",
|
27
|
-
"@rollup/plugin-json": "^6.1.0",
|
28
|
-
"@rollup/plugin-node-resolve": "^15.3.0",
|
29
|
-
"@rollup/plugin-terser": "^0.4.4",
|
30
|
-
"@rollup/plugin-typescript": "^12.1.1",
|
31
|
-
"@types/cors": "^2.8.17",
|
32
|
-
"@types/crypto-js": "^4.2.2",
|
33
|
-
"@types/express": "^5.0.0",
|
34
|
-
"@types/node": "^22.9.0",
|
35
|
-
"rollup": "^4.18.0",
|
36
|
-
"tslib": "^2.8.1",
|
37
|
-
"typescript": "^5.6.3"
|
38
|
-
},
|
39
|
-
"dependencies": {
|
40
|
-
"cors": "^2.8.5",
|
41
|
-
"crypto-js": "^4.2.0",
|
42
|
-
"express": "^4.21.1",
|
43
|
-
"mstate-cli": "^0.0.9",
|
44
|
-
"open": "^10.1.0"
|
45
|
-
}
|
46
|
-
}
|
1
|
+
{
|
2
|
+
"name": "mstate-cli",
|
3
|
+
"version": "0.4.4",
|
4
|
+
"main": "index.js",
|
5
|
+
"bin": {
|
6
|
+
"mstate": "./dist/index.js"
|
7
|
+
},
|
8
|
+
"scripts": {
|
9
|
+
"build": "rollup -c",
|
10
|
+
"dev": "rollup -c --watch",
|
11
|
+
"prod": "npm run build",
|
12
|
+
"start": "npm run build && node dist/index.js"
|
13
|
+
},
|
14
|
+
"keywords": [
|
15
|
+
"mstate",
|
16
|
+
"workflow",
|
17
|
+
"cli",
|
18
|
+
"automation",
|
19
|
+
"mobioffice"
|
20
|
+
],
|
21
|
+
"author": "",
|
22
|
+
"license": "ISC",
|
23
|
+
"description": "A CLI tool for maintaining mstate workflows config",
|
24
|
+
"devDependencies": {
|
25
|
+
"@rollup/plugin-alias": "^5.1.1",
|
26
|
+
"@rollup/plugin-commonjs": "^28.0.1",
|
27
|
+
"@rollup/plugin-json": "^6.1.0",
|
28
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
29
|
+
"@rollup/plugin-terser": "^0.4.4",
|
30
|
+
"@rollup/plugin-typescript": "^12.1.1",
|
31
|
+
"@types/cors": "^2.8.17",
|
32
|
+
"@types/crypto-js": "^4.2.2",
|
33
|
+
"@types/express": "^5.0.0",
|
34
|
+
"@types/node": "^22.9.0",
|
35
|
+
"rollup": "^4.18.0",
|
36
|
+
"tslib": "^2.8.1",
|
37
|
+
"typescript": "^5.6.3"
|
38
|
+
},
|
39
|
+
"dependencies": {
|
40
|
+
"cors": "^2.8.5",
|
41
|
+
"crypto-js": "^4.2.0",
|
42
|
+
"express": "^4.21.1",
|
43
|
+
"mstate-cli": "^0.0.9",
|
44
|
+
"open": "^10.1.0"
|
45
|
+
}
|
46
|
+
}
|
package/rollup.config.mjs
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
import resolve from '@rollup/plugin-node-resolve';
|
2
|
-
import commonjs from '@rollup/plugin-commonjs';
|
3
|
-
import typescript from '@rollup/plugin-typescript';
|
4
|
-
import json from '@rollup/plugin-json';
|
5
|
-
import terser from '@rollup/plugin-terser';
|
6
|
-
import alias from '@rollup/plugin-alias';
|
7
|
-
import { fileURLToPath } from 'url';
|
8
|
-
import path from 'path';
|
9
|
-
|
10
|
-
const __filename = fileURLToPath(import.meta.url);
|
11
|
-
const __dirname = path.dirname(__filename);
|
12
|
-
|
13
|
-
export default {
|
14
|
-
input: 'src/index.ts', // Your entry file
|
15
|
-
output: {
|
16
|
-
dir: 'dist', // Output directory
|
17
|
-
format: 'cjs', // CommonJS format
|
18
|
-
},
|
19
|
-
plugins: [
|
20
|
-
alias({
|
21
|
-
entries: [
|
22
|
-
{ find: '@shared', replacement: path.resolve(__dirname, '../shared') },
|
23
|
-
],
|
24
|
-
}),
|
25
|
-
resolve(), // Resolves node_modules
|
26
|
-
commonjs(), // Converts CommonJS to ES Modules
|
27
|
-
terser(), // remove spaces and compress build
|
28
|
-
typescript({
|
29
|
-
tsconfig: './tsconfig.json', // Ensure Rollup uses your TypeScript config
|
30
|
-
declaration: false, // Make sure to disable declaration file generation in Rollup
|
31
|
-
}), // Transpile TypeScript
|
32
|
-
json(), // Add JSON plugin
|
33
|
-
],
|
34
|
-
};
|
1
|
+
import resolve from '@rollup/plugin-node-resolve';
|
2
|
+
import commonjs from '@rollup/plugin-commonjs';
|
3
|
+
import typescript from '@rollup/plugin-typescript';
|
4
|
+
import json from '@rollup/plugin-json';
|
5
|
+
import terser from '@rollup/plugin-terser';
|
6
|
+
import alias from '@rollup/plugin-alias';
|
7
|
+
import { fileURLToPath } from 'url';
|
8
|
+
import path from 'path';
|
9
|
+
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
11
|
+
const __dirname = path.dirname(__filename);
|
12
|
+
|
13
|
+
export default {
|
14
|
+
input: 'src/index.ts', // Your entry file
|
15
|
+
output: {
|
16
|
+
dir: 'dist', // Output directory
|
17
|
+
format: 'cjs', // CommonJS format
|
18
|
+
},
|
19
|
+
plugins: [
|
20
|
+
alias({
|
21
|
+
entries: [
|
22
|
+
{ find: '@shared', replacement: path.resolve(__dirname, '../shared') },
|
23
|
+
],
|
24
|
+
}),
|
25
|
+
resolve(), // Resolves node_modules
|
26
|
+
commonjs(), // Converts CommonJS to ES Modules
|
27
|
+
terser(), // remove spaces and compress build
|
28
|
+
typescript({
|
29
|
+
tsconfig: './tsconfig.json', // Ensure Rollup uses your TypeScript config
|
30
|
+
declaration: false, // Make sure to disable declaration file generation in Rollup
|
31
|
+
}), // Transpile TypeScript
|
32
|
+
json(), // Add JSON plugin
|
33
|
+
],
|
34
|
+
};
|
package/src/common/constant.ts
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
import path from 'path';
|
2
|
-
import os from 'os';
|
3
|
-
import {
|
4
|
-
MOBIOFFICE_API_URL,
|
5
|
-
MSTATE_API_URL,
|
6
|
-
MSTATE_FRONTEND_URL,
|
7
|
-
} from '@shared/constants';
|
8
|
-
|
9
|
-
export const CRED_FOLDER_PATH = path.join(os.homedir(), '.mstate');
|
10
|
-
export const CRED_FILE_PATH = path.join(
|
11
|
-
CRED_FOLDER_PATH,
|
12
|
-
'.mstate_credentials',
|
13
|
-
);
|
14
|
-
|
15
|
-
export const ENCRYPT_KEY: string = 'THIS_IS_MOBIOFFICE';
|
16
|
-
|
17
|
-
export const MSTATE_DOMAIN: string = MSTATE_FRONTEND_URL;
|
18
|
-
export const MSTATE_URL = MSTATE_API_URL;
|
19
|
-
export const MOBIOFFICE_URL: string = MOBIOFFICE_API_URL;
|
1
|
+
import path from 'path';
|
2
|
+
import os from 'os';
|
3
|
+
import {
|
4
|
+
MOBIOFFICE_API_URL,
|
5
|
+
MSTATE_API_URL,
|
6
|
+
MSTATE_FRONTEND_URL,
|
7
|
+
} from '@shared/constants';
|
8
|
+
|
9
|
+
export const CRED_FOLDER_PATH = path.join(os.homedir(), '.mstate');
|
10
|
+
export const CRED_FILE_PATH = path.join(
|
11
|
+
CRED_FOLDER_PATH,
|
12
|
+
'.mstate_credentials',
|
13
|
+
);
|
14
|
+
|
15
|
+
export const ENCRYPT_KEY: string = 'THIS_IS_MOBIOFFICE';
|
16
|
+
|
17
|
+
export const MSTATE_DOMAIN: string = MSTATE_FRONTEND_URL;
|
18
|
+
export const MSTATE_URL = MSTATE_API_URL;
|
19
|
+
export const MOBIOFFICE_URL: string = MOBIOFFICE_API_URL;
|
package/src/common/enum.ts
CHANGED
@@ -1,26 +1,30 @@
|
|
1
|
-
export enum CmdAction {
|
2
|
-
LOGIN = 'login',
|
3
|
-
LINK = 'link',
|
4
|
-
SET = 'set',
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
1
|
+
export enum CmdAction {
|
2
|
+
LOGIN = 'login',
|
3
|
+
LINK = 'link',
|
4
|
+
SET = 'set',
|
5
|
+
CHANGE = 'change',
|
6
|
+
INFO = 'info',
|
7
|
+
DEV = 'dev',
|
8
|
+
UNLINK = 'unlink',
|
9
|
+
PERMISSION = 'permission',
|
10
|
+
ADD_USER = 'add-user',
|
11
|
+
ADD = 'add',
|
12
|
+
CLONE = 'clone',
|
13
|
+
PUSH = 'push',
|
14
|
+
HELP = '--help',
|
15
|
+
HELP_FLAG = '-h',
|
16
|
+
VERSION = '--version',
|
17
|
+
VERSION_FLAG = '-v',
|
18
|
+
}
|
19
|
+
|
20
|
+
export enum Variables {
|
21
|
+
WORKFLOW = '-w',
|
22
|
+
SECRET = '-s',
|
23
|
+
USER_ID = '-u',
|
24
|
+
PERMISSIONS = '-p',
|
25
|
+
COMPANY_ID = '-c',
|
26
|
+
EMAIL = '-e',
|
27
|
+
PHONE = '-m',
|
28
|
+
SAVED_VALUE = '-ws',
|
29
|
+
VISIBILITY = '-v',
|
30
|
+
}
|
package/src/common/helpers.ts
CHANGED
@@ -1,83 +1,85 @@
|
|
1
|
-
import CryptoJS from 'crypto-js';
|
2
|
-
import os from 'os';
|
3
|
-
import { ENCRYPT_KEY } from './constant';
|
4
|
-
import { customLog } from './utils';
|
5
|
-
import { Variables } from './enum';
|
6
|
-
|
7
|
-
const variables = Object.entries(Variables);
|
8
|
-
|
9
|
-
export function getValueFromArgs(key: string, allowed = false) {
|
10
|
-
const args = process.argv;
|
11
|
-
const variableIndex = args.indexOf(key);
|
12
|
-
const value = variableIndex !== -1 ? (args[variableIndex + 1] ?? '') : '';
|
13
|
-
|
14
|
-
if (allowed && !value) {
|
15
|
-
const [desc] = variables.find(([, flag]) => key === flag) ?? [];
|
16
|
-
customLog.changeAndThrow(
|
17
|
-
`Value for ${desc} is required. \n\t\t Use '${key}' flag for assigning value`,
|
18
|
-
);
|
19
|
-
}
|
20
|
-
|
21
|
-
return value;
|
22
|
-
}
|
23
|
-
|
24
|
-
export function hasFlag(flag: string) {
|
25
|
-
const args = process.argv;
|
26
|
-
return args.includes(flag.toUpperCase()) || args.includes(flag.toLowerCase());
|
27
|
-
}
|
28
|
-
|
29
|
-
// Encrypting data
|
30
|
-
export function encryptData(data: any) {
|
31
|
-
const jsonData = JSON.stringify(data);
|
32
|
-
const encryptedData = CryptoJS.AES.encrypt(
|
33
|
-
jsonData,
|
34
|
-
getEncryptionKey(),
|
35
|
-
).toString();
|
36
|
-
return encryptedData;
|
37
|
-
}
|
38
|
-
|
39
|
-
// Decrypting data
|
40
|
-
export function decryptData<T = any>(encryptedData: string) {
|
41
|
-
const bytes = CryptoJS.AES.decrypt(encryptedData, getEncryptionKey());
|
42
|
-
const decryptedData = bytes.toString(CryptoJS.enc.Utf8);
|
43
|
-
return JSON.parse(decryptedData) as T;
|
44
|
-
}
|
45
|
-
|
46
|
-
export function getEncryptionKey() {
|
47
|
-
return ENCRYPT_KEY + getMacID();
|
48
|
-
}
|
49
|
-
|
50
|
-
export function getMacID() {
|
51
|
-
const networkInterfaces = os.networkInterfaces();
|
52
|
-
const macAddresses = Object.values(networkInterfaces)
|
53
|
-
.flat()
|
54
|
-
.filter((details) => !details?.internal)
|
55
|
-
.map((details) => details?.mac);
|
56
|
-
|
57
|
-
return macAddresses[0];
|
58
|
-
}
|
59
|
-
|
60
|
-
export function sortJSON(data: any): any {
|
61
|
-
if (
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
)
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
1
|
+
import CryptoJS from 'crypto-js';
|
2
|
+
import os from 'os';
|
3
|
+
import { ENCRYPT_KEY } from './constant';
|
4
|
+
import { customLog } from './utils';
|
5
|
+
import { Variables } from './enum';
|
6
|
+
|
7
|
+
const variables = Object.entries(Variables);
|
8
|
+
|
9
|
+
export function getValueFromArgs(key: string, allowed = false) {
|
10
|
+
const args = process.argv;
|
11
|
+
const variableIndex = args.indexOf(key);
|
12
|
+
const value = variableIndex !== -1 ? (args[variableIndex + 1] ?? '') : '';
|
13
|
+
|
14
|
+
if (allowed && !value) {
|
15
|
+
const [desc] = variables.find(([, flag]) => key === flag) ?? [];
|
16
|
+
customLog.changeAndThrow(
|
17
|
+
`Value for ${desc} is required. \n\t\t Use '${key}' flag for assigning value`,
|
18
|
+
);
|
19
|
+
}
|
20
|
+
|
21
|
+
return value;
|
22
|
+
}
|
23
|
+
|
24
|
+
export function hasFlag(flag: string) {
|
25
|
+
const args = process.argv;
|
26
|
+
return args.includes(flag.toUpperCase()) || args.includes(flag.toLowerCase());
|
27
|
+
}
|
28
|
+
|
29
|
+
// Encrypting data
|
30
|
+
export function encryptData(data: any) {
|
31
|
+
const jsonData = JSON.stringify(data);
|
32
|
+
const encryptedData = CryptoJS.AES.encrypt(
|
33
|
+
jsonData,
|
34
|
+
getEncryptionKey(),
|
35
|
+
).toString();
|
36
|
+
return encryptedData;
|
37
|
+
}
|
38
|
+
|
39
|
+
// Decrypting data
|
40
|
+
export function decryptData<T = any>(encryptedData: string) {
|
41
|
+
const bytes = CryptoJS.AES.decrypt(encryptedData, getEncryptionKey());
|
42
|
+
const decryptedData = bytes.toString(CryptoJS.enc.Utf8);
|
43
|
+
return JSON.parse(decryptedData) as T;
|
44
|
+
}
|
45
|
+
|
46
|
+
export function getEncryptionKey() {
|
47
|
+
return ENCRYPT_KEY + getMacID();
|
48
|
+
}
|
49
|
+
|
50
|
+
export function getMacID() {
|
51
|
+
const networkInterfaces = os.networkInterfaces();
|
52
|
+
const macAddresses = Object.values(networkInterfaces)
|
53
|
+
.flat()
|
54
|
+
.filter((details) => !details?.internal)
|
55
|
+
.map((details) => details?.mac);
|
56
|
+
|
57
|
+
return macAddresses[0];
|
58
|
+
}
|
59
|
+
|
60
|
+
export function sortJSON(data: any): any {
|
61
|
+
if (data === null) return data;
|
62
|
+
|
63
|
+
if (Array.isArray(data)) {
|
64
|
+
const newArr = [];
|
65
|
+
for (const val of data) {
|
66
|
+
newArr.push(sortJSON(val));
|
67
|
+
}
|
68
|
+
|
69
|
+
return newArr;
|
70
|
+
} else if (typeof data === 'object') {
|
71
|
+
const entries = Object.entries(data);
|
72
|
+
const sortedObject = entries.sort(([, d1]) =>
|
73
|
+
typeof d1 === 'string' || typeof d1 === 'number' ? -1 : 1,
|
74
|
+
);
|
75
|
+
|
76
|
+
let newObj: any = {};
|
77
|
+
for (const [k, d] of sortedObject) {
|
78
|
+
newObj[k] = sortJSON(d);
|
79
|
+
}
|
80
|
+
|
81
|
+
return newObj;
|
82
|
+
}
|
83
|
+
|
84
|
+
return data;
|
85
|
+
}
|
package/src/common/utils.ts
CHANGED
@@ -1,67 +1,67 @@
|
|
1
|
-
import fs from 'fs';
|
2
|
-
import { CRED_FILE_PATH, CRED_FOLDER_PATH } from './constant';
|
3
|
-
import { decryptData, encryptData, getValueFromArgs } from './helpers';
|
4
|
-
import { Variables } from './enum';
|
5
|
-
|
6
|
-
export const customLog = {
|
7
|
-
changeAndThrow(...message: string[]) {
|
8
|
-
throw new Error(message.join('\n'));
|
9
|
-
},
|
10
|
-
error(...message: string[]) {
|
11
|
-
const RED_COLOR = '\x1b[31m'; // ANSI code for red
|
12
|
-
const RESET_COLOR = '\x1b[0m'; // ANSI code to reset to default color
|
13
|
-
|
14
|
-
console.error(`${RED_COLOR}[MSTATE][ERROR] ${RESET_COLOR}`, ...message);
|
15
|
-
},
|
16
|
-
success(...message: string[]) {
|
17
|
-
const GREEN_COLOR = '\x1b[32m'; // ANSI code for green
|
18
|
-
const RESET_COLOR = '\x1b[0m'; // ANSI code to reset to default color
|
19
|
-
|
20
|
-
console.log(`${GREEN_COLOR}[MSTATE] ${RESET_COLOR}`, ...message);
|
21
|
-
},
|
22
|
-
info(key: string, desc: string) {
|
23
|
-
const optionPadding = 30; // Define spacing width for the option column
|
24
|
-
const descriptionPadding = 60; // Define spacing width for the description column
|
25
|
-
console.log(
|
26
|
-
' ',
|
27
|
-
key.padEnd(optionPadding) + desc.padEnd(descriptionPadding),
|
28
|
-
);
|
29
|
-
},
|
30
|
-
};
|
31
|
-
|
32
|
-
//#region Credentials
|
33
|
-
export function handleUpdateSecretKey(secret: string) {
|
34
|
-
try {
|
35
|
-
fs.mkdirSync(CRED_FOLDER_PATH, { recursive: true });
|
36
|
-
|
37
|
-
const data = encryptData({ secret });
|
38
|
-
fs.writeFileSync(CRED_FILE_PATH, data, {
|
39
|
-
flag: 'w',
|
40
|
-
mode: 0o600,
|
41
|
-
});
|
42
|
-
} catch (error) {}
|
43
|
-
}
|
44
|
-
|
45
|
-
export function getSecretKey() {
|
46
|
-
try {
|
47
|
-
const fileData = fs.readFileSync(CRED_FILE_PATH, 'utf8');
|
48
|
-
const secret =
|
49
|
-
getValueFromArgs(Variables.SECRET) || decryptData(fileData)?.secret;
|
50
|
-
if (!secret) {
|
51
|
-
customLog.changeAndThrow(`Please login or Parameter secret is required`);
|
52
|
-
}
|
53
|
-
|
54
|
-
return secret;
|
55
|
-
} catch (error) {
|
56
|
-
const secretKey = getValueFromArgs(Variables.SECRET);
|
57
|
-
if (secretKey) {
|
58
|
-
return secretKey;
|
59
|
-
}
|
60
|
-
|
61
|
-
customLog.changeAndThrow(`Please login or Parameter secret is required`);
|
62
|
-
}
|
63
|
-
}
|
64
|
-
|
65
|
-
export function getEnv() {}
|
66
|
-
|
67
|
-
//#endregion
|
1
|
+
import fs from 'fs';
|
2
|
+
import { CRED_FILE_PATH, CRED_FOLDER_PATH } from './constant';
|
3
|
+
import { decryptData, encryptData, getValueFromArgs } from './helpers';
|
4
|
+
import { Variables } from './enum';
|
5
|
+
|
6
|
+
export const customLog = {
|
7
|
+
changeAndThrow(...message: string[]) {
|
8
|
+
throw new Error(message.join('\n'));
|
9
|
+
},
|
10
|
+
error(...message: string[]) {
|
11
|
+
const RED_COLOR = '\x1b[31m'; // ANSI code for red
|
12
|
+
const RESET_COLOR = '\x1b[0m'; // ANSI code to reset to default color
|
13
|
+
|
14
|
+
console.error(`${RED_COLOR}[MSTATE][ERROR] ${RESET_COLOR}`, ...message);
|
15
|
+
},
|
16
|
+
success(...message: string[]) {
|
17
|
+
const GREEN_COLOR = '\x1b[32m'; // ANSI code for green
|
18
|
+
const RESET_COLOR = '\x1b[0m'; // ANSI code to reset to default color
|
19
|
+
|
20
|
+
console.log(`${GREEN_COLOR}[MSTATE] ${RESET_COLOR}`, ...message);
|
21
|
+
},
|
22
|
+
info(key: string, desc: string) {
|
23
|
+
const optionPadding = 30; // Define spacing width for the option column
|
24
|
+
const descriptionPadding = 60; // Define spacing width for the description column
|
25
|
+
console.log(
|
26
|
+
' ',
|
27
|
+
key.padEnd(optionPadding) + desc.padEnd(descriptionPadding),
|
28
|
+
);
|
29
|
+
},
|
30
|
+
};
|
31
|
+
|
32
|
+
//#region Credentials
|
33
|
+
export function handleUpdateSecretKey(secret: string) {
|
34
|
+
try {
|
35
|
+
fs.mkdirSync(CRED_FOLDER_PATH, { recursive: true });
|
36
|
+
|
37
|
+
const data = encryptData({ secret });
|
38
|
+
fs.writeFileSync(CRED_FILE_PATH, data, {
|
39
|
+
flag: 'w',
|
40
|
+
mode: 0o600,
|
41
|
+
});
|
42
|
+
} catch (error) {}
|
43
|
+
}
|
44
|
+
|
45
|
+
export function getSecretKey() {
|
46
|
+
try {
|
47
|
+
const fileData = fs.readFileSync(CRED_FILE_PATH, 'utf8');
|
48
|
+
const secret =
|
49
|
+
getValueFromArgs(Variables.SECRET) || decryptData(fileData)?.secret;
|
50
|
+
if (!secret) {
|
51
|
+
customLog.changeAndThrow(`Please login or Parameter secret is required`);
|
52
|
+
}
|
53
|
+
|
54
|
+
return secret;
|
55
|
+
} catch (error) {
|
56
|
+
const secretKey = getValueFromArgs(Variables.SECRET);
|
57
|
+
if (secretKey) {
|
58
|
+
return secretKey;
|
59
|
+
}
|
60
|
+
|
61
|
+
customLog.changeAndThrow(`Please login or Parameter secret is required`);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
export function getEnv() {}
|
66
|
+
|
67
|
+
//#endregion
|