mstate-cli 0.2.7 → 0.2.9
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 +50 -50
- package/package.json +45 -45
- package/rollup.config.mjs +34 -34
- package/src/common/constant.ts +26 -26
- package/src/common/enum.ts +16 -17
- package/src/common/helpers.ts +42 -42
- package/src/common/utils.ts +67 -67
- package/src/handlers/action.handler.ts +131 -131
- package/src/handlers/company.handler.ts +274 -274
- package/src/handlers/environment.handler.ts +111 -111
- package/src/handlers/help.handler.ts +48 -48
- package/src/handlers/mobioffice.handler.ts +78 -78
- package/src/handlers/workflow.handler.ts +238 -238
- package/src/index.ts +85 -88
- package/src/interface.d.ts +43 -43
- package/tsconfig.json +18 -18
- package/dist/index.js +0 -298
package/.prettierrc
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
{
|
2
|
-
"endOfLine": "auto",
|
3
|
-
"singleQuote": true,
|
4
|
-
"trailingComma": "all"
|
5
|
-
}
|
1
|
+
{
|
2
|
+
"endOfLine": "auto",
|
3
|
+
"singleQuote": true,
|
4
|
+
"trailingComma": "all"
|
5
|
+
}
|
package/Readme.md
CHANGED
@@ -1,50 +1,50 @@
|
|
1
|
-
# Mstate CLI
|
2
|
-
|
3
|
-
<div style="display: flex; justify-content: center;">
|
4
|
-
<img src="https://docs.mstate.ai/img/mymobioffice_logo.png" alt="mstate" />
|
5
|
-
</div>
|
6
|
-
|
7
|
-
##
|
8
|
-
|
9
|
-
MSTATE is a powerful library that automates workflows managing state transactions and actions, ensuring seamless execution and enhanced process control.
|
10
|
-
|
11
|
-
MSTATE CLI is a manager for workflow configs and user management using your command shell.
|
12
|
-
|
13
|
-
To know more about it, Please check [https://docs.mstate.ai](https://docs.mstate.ai).
|
14
|
-
|
15
|
-
Cloning your first workflow is as easy as:
|
16
|
-
|
17
|
-
```cmd
|
18
|
-
mstate clone secret="zW5Knss75pBgRIvJgsh6" workflow="demo/signup_form"
|
19
|
-
```
|
20
|
-
|
21
|
-
All Node.js versions are supported starting Node.js 12.X.
|
22
|
-
|
23
|
-
### Installing MSTATE CLI
|
24
|
-
|
25
|
-
With NPM:
|
26
|
-
|
27
|
-
```cmd
|
28
|
-
npm i mstate-cli -g
|
29
|
-
```
|
30
|
-
|
31
|
-
You can install Node.js easily from [Link](https://nodejs.org/en/download/package-manager).
|
32
|
-
|
33
|
-
### To list all Command:
|
34
|
-
|
35
|
-
```cmd
|
36
|
-
mstate -h
|
37
|
-
```
|
38
|
-
|
39
|
-
### Managing workflow config is straightforward:
|
40
|
-
|
41
|
-
### Add new workflow
|
42
|
-
|
43
|
-
Just create a json file and add the path to `file` parameter.
|
44
|
-
|
45
|
-
```cmd
|
46
|
-
mstate add file="demo/signup_form/workflow.json" secret="secret-key" path="myFolder/mySubfolder"
|
47
|
-
```
|
48
|
-
|
49
|
-
For checking your workflow execution.
|
50
|
-
Just input your workflow name with path and secret key at [https://mstate.ai](https://mstate.ai).
|
1
|
+
# Mstate CLI
|
2
|
+
|
3
|
+
<div style="display: flex; justify-content: center;">
|
4
|
+
<img src="https://docs.mstate.ai/img/mymobioffice_logo.png" alt="mstate" />
|
5
|
+
</div>
|
6
|
+
|
7
|
+
##
|
8
|
+
|
9
|
+
MSTATE is a powerful library that automates workflows managing state transactions and actions, ensuring seamless execution and enhanced process control.
|
10
|
+
|
11
|
+
MSTATE CLI is a manager for workflow configs and user management using your command shell.
|
12
|
+
|
13
|
+
To know more about it, Please check [https://docs.mstate.ai](https://docs.mstate.ai).
|
14
|
+
|
15
|
+
Cloning your first workflow is as easy as:
|
16
|
+
|
17
|
+
```cmd
|
18
|
+
mstate clone secret="zW5Knss75pBgRIvJgsh6" workflow="demo/signup_form"
|
19
|
+
```
|
20
|
+
|
21
|
+
All Node.js versions are supported starting Node.js 12.X.
|
22
|
+
|
23
|
+
### Installing MSTATE CLI
|
24
|
+
|
25
|
+
With NPM:
|
26
|
+
|
27
|
+
```cmd
|
28
|
+
npm i mstate-cli -g
|
29
|
+
```
|
30
|
+
|
31
|
+
You can install Node.js easily from [Link](https://nodejs.org/en/download/package-manager).
|
32
|
+
|
33
|
+
### To list all Command:
|
34
|
+
|
35
|
+
```cmd
|
36
|
+
mstate -h
|
37
|
+
```
|
38
|
+
|
39
|
+
### Managing workflow config is straightforward:
|
40
|
+
|
41
|
+
### Add new workflow
|
42
|
+
|
43
|
+
Just create a json file and add the path to `file` parameter.
|
44
|
+
|
45
|
+
```cmd
|
46
|
+
mstate add file="demo/signup_form/workflow.json" secret="secret-key" path="myFolder/mySubfolder"
|
47
|
+
```
|
48
|
+
|
49
|
+
For checking your workflow execution.
|
50
|
+
Just input your workflow name with path and secret key at [https://mstate.ai](https://mstate.ai).
|
package/package.json
CHANGED
@@ -1,45 +1,45 @@
|
|
1
|
-
{
|
2
|
-
"name": "mstate-cli",
|
3
|
-
"version": "0.2.
|
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
|
-
],
|
20
|
-
"author": "",
|
21
|
-
"license": "ISC",
|
22
|
-
"description": "A CLI tool for maintaining mstate workflows config",
|
23
|
-
"devDependencies": {
|
24
|
-
"@rollup/plugin-alias": "^5.1.1",
|
25
|
-
"@rollup/plugin-commonjs": "^28.0.1",
|
26
|
-
"@rollup/plugin-json": "^6.1.0",
|
27
|
-
"@rollup/plugin-node-resolve": "^15.3.0",
|
28
|
-
"@rollup/plugin-terser": "^0.4.4",
|
29
|
-
"@rollup/plugin-typescript": "^12.1.1",
|
30
|
-
"@types/cors": "^2.8.17",
|
31
|
-
"@types/crypto-js": "^4.2.2",
|
32
|
-
"@types/express": "^5.0.0",
|
33
|
-
"@types/node": "^22.9.0",
|
34
|
-
"rollup": "^4.18.0",
|
35
|
-
"tslib": "^2.8.1",
|
36
|
-
"typescript": "^5.6.3"
|
37
|
-
},
|
38
|
-
"dependencies": {
|
39
|
-
"cors": "^2.8.5",
|
40
|
-
"crypto-js": "^4.2.0",
|
41
|
-
"express": "^4.21.1",
|
42
|
-
"mstate-cli": "^0.0.9",
|
43
|
-
"open": "^10.1.0"
|
44
|
-
}
|
45
|
-
}
|
1
|
+
{
|
2
|
+
"name": "mstate-cli",
|
3
|
+
"version": "0.2.9",
|
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
|
+
],
|
20
|
+
"author": "",
|
21
|
+
"license": "ISC",
|
22
|
+
"description": "A CLI tool for maintaining mstate workflows config",
|
23
|
+
"devDependencies": {
|
24
|
+
"@rollup/plugin-alias": "^5.1.1",
|
25
|
+
"@rollup/plugin-commonjs": "^28.0.1",
|
26
|
+
"@rollup/plugin-json": "^6.1.0",
|
27
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
28
|
+
"@rollup/plugin-terser": "^0.4.4",
|
29
|
+
"@rollup/plugin-typescript": "^12.1.1",
|
30
|
+
"@types/cors": "^2.8.17",
|
31
|
+
"@types/crypto-js": "^4.2.2",
|
32
|
+
"@types/express": "^5.0.0",
|
33
|
+
"@types/node": "^22.9.0",
|
34
|
+
"rollup": "^4.18.0",
|
35
|
+
"tslib": "^2.8.1",
|
36
|
+
"typescript": "^5.6.3"
|
37
|
+
},
|
38
|
+
"dependencies": {
|
39
|
+
"cors": "^2.8.5",
|
40
|
+
"crypto-js": "^4.2.0",
|
41
|
+
"express": "^4.21.1",
|
42
|
+
"mstate-cli": "^0.0.9",
|
43
|
+
"open": "^10.1.0"
|
44
|
+
}
|
45
|
+
}
|
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,26 +1,26 @@
|
|
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 = `https://mstate.ai/`;
|
18
|
-
export const MSTATE_DOMAIN: string = MSTATE_FRONTEND_URL;
|
19
|
-
// export const MSTATE_DOMAIN: string = `https://dev.mstate.ai/`;
|
20
|
-
|
21
|
-
// export const MSTATE_URL: string = 'https://dev.mstate.mobioffice.io/api';
|
22
|
-
export const MSTATE_URL = MSTATE_API_URL;
|
23
|
-
// export const MSTATE_URL = 'https://api.mstate.mobioffice.io/api';
|
24
|
-
|
25
|
-
export const MOBIOFFICE_URL: string = MOBIOFFICE_API_URL;
|
26
|
-
// export const MOBIOFFICE_URL: string = 'https://dev-server.mobioffice.io/api';
|
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 = `https://mstate.ai/`;
|
18
|
+
export const MSTATE_DOMAIN: string = MSTATE_FRONTEND_URL;
|
19
|
+
// export const MSTATE_DOMAIN: string = `https://dev.mstate.ai/`;
|
20
|
+
|
21
|
+
// export const MSTATE_URL: string = 'https://dev.mstate.mobioffice.io/api';
|
22
|
+
export const MSTATE_URL = MSTATE_API_URL;
|
23
|
+
// export const MSTATE_URL = 'https://api.mstate.mobioffice.io/api';
|
24
|
+
|
25
|
+
export const MOBIOFFICE_URL: string = MOBIOFFICE_API_URL;
|
26
|
+
// export const MOBIOFFICE_URL: string = 'https://dev-server.mobioffice.io/api';
|
package/src/common/enum.ts
CHANGED
@@ -1,17 +1,16 @@
|
|
1
|
-
export enum CmdAction {
|
2
|
-
LOGIN = 'login',
|
3
|
-
LINK = 'link',
|
4
|
-
SET = 'set',
|
5
|
-
DEV = 'dev',
|
6
|
-
UNLINK = 'unlink',
|
7
|
-
PERMISSION = 'permission',
|
8
|
-
USER = 'user',
|
9
|
-
ADD = 'add',
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
}
|
1
|
+
export enum CmdAction {
|
2
|
+
LOGIN = 'login',
|
3
|
+
LINK = 'link',
|
4
|
+
SET = 'set',
|
5
|
+
DEV = 'dev',
|
6
|
+
UNLINK = 'unlink',
|
7
|
+
PERMISSION = 'permission',
|
8
|
+
USER = 'user',
|
9
|
+
ADD = 'add',
|
10
|
+
CLONE = 'clone',
|
11
|
+
PUSH = 'push',
|
12
|
+
HELP = '--help',
|
13
|
+
HELP_FLAG = '-h',
|
14
|
+
VERSION = '--version',
|
15
|
+
VERSION_FLAG = '-v',
|
16
|
+
}
|
package/src/common/helpers.ts
CHANGED
@@ -1,42 +1,42 @@
|
|
1
|
-
import CryptoJS from 'crypto-js';
|
2
|
-
import os from 'os';
|
3
|
-
import { ENCRYPT_KEY } from './constant';
|
4
|
-
|
5
|
-
export function getValueFromArgs(args: string[], key: string) {
|
6
|
-
return args.find((str) => str.includes(key))?.replace(key, '') ?? '';
|
7
|
-
}
|
8
|
-
|
9
|
-
export function hasFlag(args: string[], flag: string) {
|
10
|
-
return args.includes(flag.toUpperCase()) || args.includes(flag.toLowerCase());
|
11
|
-
}
|
12
|
-
|
13
|
-
// Encrypting data
|
14
|
-
export function encryptData(data: any) {
|
15
|
-
const jsonData = JSON.stringify(data);
|
16
|
-
const encryptedData = CryptoJS.AES.encrypt(
|
17
|
-
jsonData,
|
18
|
-
getEncryptionKey(),
|
19
|
-
).toString();
|
20
|
-
return encryptedData;
|
21
|
-
}
|
22
|
-
|
23
|
-
// Decrypting data
|
24
|
-
export function decryptData<T = any>(encryptedData: string) {
|
25
|
-
const bytes = CryptoJS.AES.decrypt(encryptedData, getEncryptionKey());
|
26
|
-
const decryptedData = bytes.toString(CryptoJS.enc.Utf8);
|
27
|
-
return JSON.parse(decryptedData) as T;
|
28
|
-
}
|
29
|
-
|
30
|
-
export function getEncryptionKey() {
|
31
|
-
return ENCRYPT_KEY + getMacID();
|
32
|
-
}
|
33
|
-
|
34
|
-
export function getMacID() {
|
35
|
-
const networkInterfaces = os.networkInterfaces();
|
36
|
-
const macAddresses = Object.values(networkInterfaces)
|
37
|
-
.flat()
|
38
|
-
.filter((details) => !details?.internal)
|
39
|
-
.map((details) => details?.mac);
|
40
|
-
|
41
|
-
return macAddresses[0];
|
42
|
-
}
|
1
|
+
import CryptoJS from 'crypto-js';
|
2
|
+
import os from 'os';
|
3
|
+
import { ENCRYPT_KEY } from './constant';
|
4
|
+
|
5
|
+
export function getValueFromArgs(args: string[], key: string) {
|
6
|
+
return args.find((str) => str.includes(key))?.replace(key, '') ?? '';
|
7
|
+
}
|
8
|
+
|
9
|
+
export function hasFlag(args: string[], flag: string) {
|
10
|
+
return args.includes(flag.toUpperCase()) || args.includes(flag.toLowerCase());
|
11
|
+
}
|
12
|
+
|
13
|
+
// Encrypting data
|
14
|
+
export function encryptData(data: any) {
|
15
|
+
const jsonData = JSON.stringify(data);
|
16
|
+
const encryptedData = CryptoJS.AES.encrypt(
|
17
|
+
jsonData,
|
18
|
+
getEncryptionKey(),
|
19
|
+
).toString();
|
20
|
+
return encryptedData;
|
21
|
+
}
|
22
|
+
|
23
|
+
// Decrypting data
|
24
|
+
export function decryptData<T = any>(encryptedData: string) {
|
25
|
+
const bytes = CryptoJS.AES.decrypt(encryptedData, getEncryptionKey());
|
26
|
+
const decryptedData = bytes.toString(CryptoJS.enc.Utf8);
|
27
|
+
return JSON.parse(decryptedData) as T;
|
28
|
+
}
|
29
|
+
|
30
|
+
export function getEncryptionKey() {
|
31
|
+
return ENCRYPT_KEY + getMacID();
|
32
|
+
}
|
33
|
+
|
34
|
+
export function getMacID() {
|
35
|
+
const networkInterfaces = os.networkInterfaces();
|
36
|
+
const macAddresses = Object.values(networkInterfaces)
|
37
|
+
.flat()
|
38
|
+
.filter((details) => !details?.internal)
|
39
|
+
.map((details) => details?.mac);
|
40
|
+
|
41
|
+
return macAddresses[0];
|
42
|
+
}
|
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
|
-
|
5
|
-
export const customLog = {
|
6
|
-
changeAndThrow(...message: string[]) {
|
7
|
-
throw new Error(message.join('\n'));
|
8
|
-
},
|
9
|
-
error(...message: string[]) {
|
10
|
-
const RED_COLOR = '\x1b[31m'; // ANSI code for red
|
11
|
-
const RESET_COLOR = '\x1b[0m'; // ANSI code to reset to default color
|
12
|
-
|
13
|
-
console.error(`${RED_COLOR}[MSTATE][ERROR] ${RESET_COLOR}`, ...message);
|
14
|
-
},
|
15
|
-
success(...message: string[]) {
|
16
|
-
const GREEN_COLOR = '\x1b[32m'; // ANSI code for green
|
17
|
-
const RESET_COLOR = '\x1b[0m'; // ANSI code to reset to default color
|
18
|
-
|
19
|
-
console.log(`${GREEN_COLOR}[MSTATE] ${RESET_COLOR}`, ...message);
|
20
|
-
},
|
21
|
-
info(key: string, desc: string) {
|
22
|
-
const optionPadding = 30; // Define spacing width for the option column
|
23
|
-
const descriptionPadding = 60; // Define spacing width for the description column
|
24
|
-
console.log(
|
25
|
-
' ',
|
26
|
-
key.padEnd(optionPadding) + desc.padEnd(descriptionPadding),
|
27
|
-
);
|
28
|
-
},
|
29
|
-
};
|
30
|
-
|
31
|
-
//#region Credentials
|
32
|
-
export function handleUpdateSecretKey(secret: string) {
|
33
|
-
try {
|
34
|
-
fs.mkdirSync(CRED_FOLDER_PATH, { recursive: true });
|
35
|
-
|
36
|
-
const data = encryptData({ secret });
|
37
|
-
fs.writeFileSync(CRED_FILE_PATH, data, {
|
38
|
-
flag: 'w',
|
39
|
-
mode: 0o600,
|
40
|
-
});
|
41
|
-
} catch (error) {}
|
42
|
-
}
|
43
|
-
|
44
|
-
export function getSecretKey() {
|
45
|
-
try {
|
46
|
-
const fileData = fs.readFileSync(CRED_FILE_PATH, 'utf8');
|
47
|
-
const secret =
|
48
|
-
getValueFromArgs(process.argv, 'secret=') ||
|
49
|
-
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(process.argv, '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
|
+
|
5
|
+
export const customLog = {
|
6
|
+
changeAndThrow(...message: string[]) {
|
7
|
+
throw new Error(message.join('\n'));
|
8
|
+
},
|
9
|
+
error(...message: string[]) {
|
10
|
+
const RED_COLOR = '\x1b[31m'; // ANSI code for red
|
11
|
+
const RESET_COLOR = '\x1b[0m'; // ANSI code to reset to default color
|
12
|
+
|
13
|
+
console.error(`${RED_COLOR}[MSTATE][ERROR] ${RESET_COLOR}`, ...message);
|
14
|
+
},
|
15
|
+
success(...message: string[]) {
|
16
|
+
const GREEN_COLOR = '\x1b[32m'; // ANSI code for green
|
17
|
+
const RESET_COLOR = '\x1b[0m'; // ANSI code to reset to default color
|
18
|
+
|
19
|
+
console.log(`${GREEN_COLOR}[MSTATE] ${RESET_COLOR}`, ...message);
|
20
|
+
},
|
21
|
+
info(key: string, desc: string) {
|
22
|
+
const optionPadding = 30; // Define spacing width for the option column
|
23
|
+
const descriptionPadding = 60; // Define spacing width for the description column
|
24
|
+
console.log(
|
25
|
+
' ',
|
26
|
+
key.padEnd(optionPadding) + desc.padEnd(descriptionPadding),
|
27
|
+
);
|
28
|
+
},
|
29
|
+
};
|
30
|
+
|
31
|
+
//#region Credentials
|
32
|
+
export function handleUpdateSecretKey(secret: string) {
|
33
|
+
try {
|
34
|
+
fs.mkdirSync(CRED_FOLDER_PATH, { recursive: true });
|
35
|
+
|
36
|
+
const data = encryptData({ secret });
|
37
|
+
fs.writeFileSync(CRED_FILE_PATH, data, {
|
38
|
+
flag: 'w',
|
39
|
+
mode: 0o600,
|
40
|
+
});
|
41
|
+
} catch (error) {}
|
42
|
+
}
|
43
|
+
|
44
|
+
export function getSecretKey() {
|
45
|
+
try {
|
46
|
+
const fileData = fs.readFileSync(CRED_FILE_PATH, 'utf8');
|
47
|
+
const secret =
|
48
|
+
getValueFromArgs(process.argv, 'secret=') ||
|
49
|
+
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(process.argv, '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
|