mstate-cli 0.1.8 → 0.1.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/dist/index.js +297 -75
- package/package.json +16 -3
- package/rollup.config.js +23 -0
- package/src/common/constant.ts +14 -1
- package/src/common/enum.ts +1 -0
- package/src/common/helpers.ts +25 -0
- package/src/common/utils.ts +38 -5
- package/src/handlers/action.handler.ts +8 -9
- package/src/handlers/company.handler.ts +85 -4
- package/src/handlers/environment.handler.ts +8 -9
- package/src/handlers/mobioffice.handler.ts +7 -6
- package/src/handlers/workflow.handler.ts +14 -17
- package/src/index.ts +8 -3
- package/tsconfig.json +10 -8
- package/dist/common/constant.js +0 -5
- package/dist/common/enum.js +0 -16
- package/dist/common/utils.js +0 -32
- package/dist/handlers/action.handler.js +0 -136
- package/dist/handlers/company.handler.js +0 -104
- package/dist/handlers/environment.handler.js +0 -126
- package/dist/handlers/help.handler.js +0 -27
- package/dist/handlers/mobioffice.handler.js +0 -74
- package/dist/handlers/workflow.handler.js +0 -204
package/package.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "mstate-cli",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.9",
|
4
4
|
"main": "index.js",
|
5
5
|
"bin": {
|
6
6
|
"mstate": "./dist/index.js"
|
7
7
|
},
|
8
8
|
"scripts": {
|
9
|
-
"build": "
|
9
|
+
"build": "npx rollup -c",
|
10
10
|
"start": "npm run build && node dist/index.js"
|
11
11
|
},
|
12
12
|
"keywords": [
|
@@ -19,10 +19,23 @@
|
|
19
19
|
"license": "ISC",
|
20
20
|
"description": "A CLI tool for maintaining mstate workflows config",
|
21
21
|
"devDependencies": {
|
22
|
+
"@rollup/plugin-commonjs": "^28.0.1",
|
23
|
+
"@rollup/plugin-json": "^6.1.0",
|
24
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
25
|
+
"@rollup/plugin-terser": "^0.4.4",
|
26
|
+
"@rollup/plugin-typescript": "^12.1.1",
|
27
|
+
"@types/cors": "^2.8.17",
|
28
|
+
"@types/crypto-js": "^4.2.2",
|
29
|
+
"@types/express": "^5.0.0",
|
22
30
|
"@types/node": "^22.9.0",
|
31
|
+
"tslib": "^2.8.1",
|
23
32
|
"typescript": "^5.6.3"
|
24
33
|
},
|
25
34
|
"dependencies": {
|
26
|
-
"
|
35
|
+
"cors": "^2.8.5",
|
36
|
+
"crypto-js": "^4.2.0",
|
37
|
+
"express": "^4.21.1",
|
38
|
+
"mstate-cli": "^0.0.9",
|
39
|
+
"open": "^10.1.0"
|
27
40
|
}
|
28
41
|
}
|
package/rollup.config.js
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
const resolve = require('@rollup/plugin-node-resolve');
|
2
|
+
const commonjs = require('@rollup/plugin-commonjs');
|
3
|
+
const typescript = require('@rollup/plugin-typescript');
|
4
|
+
const json = require('@rollup/plugin-json');
|
5
|
+
const terser = require('@rollup/plugin-terser');
|
6
|
+
|
7
|
+
module.exports = {
|
8
|
+
input: 'src/index.ts', // Your entry file
|
9
|
+
output: {
|
10
|
+
dir: 'dist', // Output directory
|
11
|
+
format: 'cjs', // CommonJS format
|
12
|
+
},
|
13
|
+
plugins: [
|
14
|
+
resolve(), // Resolves node_modules
|
15
|
+
commonjs(), // Converts CommonJS to ES Modules
|
16
|
+
terser(), // remove spaces and compress build
|
17
|
+
typescript({
|
18
|
+
tsconfig: './tsconfig.json', // Ensure Rollup uses your TypeScript config
|
19
|
+
declaration: false, // Make sure to disable declaration file generation in Rollup
|
20
|
+
}), // Transpile TypeScript
|
21
|
+
json(), // Add JSON plugin
|
22
|
+
],
|
23
|
+
};
|
package/src/common/constant.ts
CHANGED
@@ -1,2 +1,15 @@
|
|
1
|
+
import path from 'path';
|
2
|
+
import os from 'os';
|
3
|
+
|
4
|
+
export const CRED_FOLDER_PATH = path.join(os.homedir(), '.mstate');
|
5
|
+
export const CRED_FILE_PATH = path.join(
|
6
|
+
CRED_FOLDER_PATH,
|
7
|
+
'.mstate_credentials',
|
8
|
+
);
|
9
|
+
|
10
|
+
export const MSTATE_DOMAIN: string = `https"//mstate.ai/`;
|
11
|
+
// export const MSTATE_DOMAIN: string = `http://localhost:5173/`;
|
12
|
+
|
13
|
+
// export const MSTATE_URL: string = 'https://dev.mstate.mobioffice.io/api';
|
14
|
+
// export const MSTATE_URL = 'http://localhost:3000/api';
|
1
15
|
export const MSTATE_URL = 'https://api.mstate.mobioffice.io/api';
|
2
|
-
export const MOBIOFFICE_URL = 'https://server.mobioffice.io/api';
|
package/src/common/enum.ts
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
import CryptoJS from 'crypto-js';
|
2
|
+
|
3
|
+
export function getValueFromArgs(args: string[], key: string) {
|
4
|
+
return args.find((str) => str.includes(key))?.replace(key, '') ?? '';
|
5
|
+
}
|
6
|
+
|
7
|
+
export function hasFlag(args: string[], flag: string) {
|
8
|
+
return args.includes(flag.toUpperCase()) || args.includes(flag.toLowerCase());
|
9
|
+
}
|
10
|
+
|
11
|
+
const ENCRYPT_KEY: string = 'THIS_IS_MOBIOFFICE';
|
12
|
+
|
13
|
+
// Encrypting data
|
14
|
+
export function encryptData(data: any) {
|
15
|
+
const jsonData = JSON.stringify(data);
|
16
|
+
const encryptedData = CryptoJS.AES.encrypt(jsonData, ENCRYPT_KEY).toString();
|
17
|
+
return encryptedData;
|
18
|
+
}
|
19
|
+
|
20
|
+
// Decrypting data
|
21
|
+
export function decryptData<T = any>(encryptedData: string) {
|
22
|
+
const bytes = CryptoJS.AES.decrypt(encryptedData, ENCRYPT_KEY);
|
23
|
+
const decryptedData = bytes.toString(CryptoJS.enc.Utf8);
|
24
|
+
return JSON.parse(decryptedData) as T;
|
25
|
+
}
|
package/src/common/utils.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
}
|
1
|
+
import fs from 'fs';
|
2
|
+
import { CRED_FILE_PATH, CRED_FOLDER_PATH } from './constant';
|
3
|
+
import { decryptData, encryptData, getValueFromArgs } from './helpers';
|
4
4
|
|
5
5
|
export const customLog = {
|
6
6
|
changeAndThrow(...message: string[]) {
|
@@ -28,6 +28,39 @@ export const customLog = {
|
|
28
28
|
},
|
29
29
|
};
|
30
30
|
|
31
|
-
|
32
|
-
|
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
|
+
decryptData(fileData)?.secret ||
|
49
|
+
getValueFromArgs(process.argv, 'secret=');
|
50
|
+
|
51
|
+
if (!secret) {
|
52
|
+
customLog.changeAndThrow(`Please login or Parameter secret is required`);
|
53
|
+
}
|
54
|
+
|
55
|
+
return secret;
|
56
|
+
} catch (error) {
|
57
|
+
const secretKey = getValueFromArgs(process.argv, 'secret=');
|
58
|
+
if (secretKey) {
|
59
|
+
return secretKey;
|
60
|
+
}
|
61
|
+
|
62
|
+
customLog.changeAndThrow(`Please login or Parameter secret is required`);
|
63
|
+
}
|
33
64
|
}
|
65
|
+
|
66
|
+
//#endregion
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import * as fs from 'fs';
|
2
2
|
import path from 'path';
|
3
3
|
import { MSTATE_URL } from '../common/constant';
|
4
|
-
import {
|
4
|
+
import { getValueFromArgs } from '../common/helpers';
|
5
|
+
import { customLog, getSecretKey } from '../common/utils';
|
5
6
|
|
6
7
|
enum Key {
|
7
8
|
WORKFLOW = 'workflow=',
|
@@ -13,9 +14,8 @@ class ActionHandler {
|
|
13
14
|
|
14
15
|
async cloneActions() {
|
15
16
|
const args = process.argv;
|
16
|
-
const
|
17
|
-
const
|
18
|
-
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
17
|
+
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
18
|
+
const secretKey = getSecretKey();
|
19
19
|
|
20
20
|
if (!secretKey) {
|
21
21
|
customLog.changeAndThrow(`Parameter secret is required`);
|
@@ -45,7 +45,7 @@ class ActionHandler {
|
|
45
45
|
} else {
|
46
46
|
const actionConfigs = response?.data;
|
47
47
|
|
48
|
-
const folderPath = path.resolve(
|
48
|
+
const folderPath = path.resolve(workflowName, 'actions');
|
49
49
|
fs.mkdirSync(folderPath, { recursive: true });
|
50
50
|
|
51
51
|
actionConfigs.forEach((config: ActionConfig) => {
|
@@ -67,9 +67,8 @@ class ActionHandler {
|
|
67
67
|
|
68
68
|
async saveToDB() {
|
69
69
|
const args = process.argv;
|
70
|
-
const
|
71
|
-
const
|
72
|
-
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
70
|
+
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
71
|
+
const secretKey = getSecretKey();
|
73
72
|
|
74
73
|
if (!secretKey) {
|
75
74
|
customLog.changeAndThrow(`Parameter secret is required`);
|
@@ -81,7 +80,7 @@ class ActionHandler {
|
|
81
80
|
return;
|
82
81
|
}
|
83
82
|
|
84
|
-
const folderPath = path.resolve(
|
83
|
+
const folderPath = path.resolve(workflowName, 'actions');
|
85
84
|
|
86
85
|
// loop to every folder to publish workflow
|
87
86
|
fs.readdir(folderPath, (err, files) => {
|
@@ -1,5 +1,14 @@
|
|
1
|
-
import { MSTATE_URL } from '../common/constant';
|
2
|
-
import {
|
1
|
+
import { MSTATE_DOMAIN, MSTATE_URL } from '../common/constant';
|
2
|
+
import {
|
3
|
+
customLog,
|
4
|
+
getSecretKey,
|
5
|
+
handleUpdateSecretKey,
|
6
|
+
} from '../common/utils';
|
7
|
+
import { getValueFromArgs } from '../common/helpers';
|
8
|
+
|
9
|
+
import open from 'open';
|
10
|
+
import express from 'express';
|
11
|
+
import cors from 'cors';
|
3
12
|
|
4
13
|
enum Key {
|
5
14
|
PERMISSIONS = 'permissions=',
|
@@ -15,7 +24,7 @@ class CompanyHandler {
|
|
15
24
|
|
16
25
|
const pString = getValueFromArgs(args, Key.PERMISSIONS).trim();
|
17
26
|
const permissions = pString.split(',');
|
18
|
-
const secretKey =
|
27
|
+
const secretKey = getSecretKey();
|
19
28
|
const user = getValueFromArgs(args, Key.USER_ID);
|
20
29
|
|
21
30
|
if (!pString.length) {
|
@@ -62,7 +71,7 @@ class CompanyHandler {
|
|
62
71
|
|
63
72
|
const pString = getValueFromArgs(args, Key.PERMISSIONS);
|
64
73
|
const permissions = pString.split(',');
|
65
|
-
const secretKey =
|
74
|
+
const secretKey = getSecretKey();
|
66
75
|
const user = getValueFromArgs(args, Key.USER_ID);
|
67
76
|
|
68
77
|
if (!permissions.length) {
|
@@ -103,6 +112,78 @@ class CompanyHandler {
|
|
103
112
|
customLog.success('Company updated successfully \n', response?.data);
|
104
113
|
}
|
105
114
|
}
|
115
|
+
|
116
|
+
async handleLogin() {
|
117
|
+
// Start the login process
|
118
|
+
let port = 49152;
|
119
|
+
const app = express();
|
120
|
+
app.use(cors({ origin: '*' }));
|
121
|
+
|
122
|
+
async function login() {
|
123
|
+
console.log('Opening browser for authentication...');
|
124
|
+
|
125
|
+
// Start a local server to capture the token
|
126
|
+
|
127
|
+
const startServer = (port: number) => {
|
128
|
+
return app.listen(port, () => {
|
129
|
+
console.log(`Server is running on port ${port}`);
|
130
|
+
});
|
131
|
+
};
|
132
|
+
|
133
|
+
const server = startServer(port);
|
134
|
+
|
135
|
+
server.on('error', (err: any) => {
|
136
|
+
if (err.code === 'EADDRINUSE') {
|
137
|
+
console.log(`Port ${port} is in use. Trying another port...`);
|
138
|
+
|
139
|
+
startServer(++port);
|
140
|
+
} else {
|
141
|
+
console.error('Server error:', err);
|
142
|
+
}
|
143
|
+
});
|
144
|
+
|
145
|
+
// Capture the OAuth callback
|
146
|
+
app.get('/cli/mstate/login', (req, res) => {
|
147
|
+
try {
|
148
|
+
const { token } = req.query;
|
149
|
+
|
150
|
+
if (token) {
|
151
|
+
console.log('Authentication successful! Token received.');
|
152
|
+
|
153
|
+
// Save the token locally
|
154
|
+
handleUpdateSecretKey(token as string);
|
155
|
+
|
156
|
+
res.send('<h1>Login successful! You can close this window.</h1>');
|
157
|
+
} else {
|
158
|
+
console.error('Authentication failed. No token received.');
|
159
|
+
res.send('<h1>Authentication failed. Please try again.</h1>');
|
160
|
+
}
|
161
|
+
} catch (error) {
|
162
|
+
} finally {
|
163
|
+
server.close(); // Stop the server after handling the response
|
164
|
+
}
|
165
|
+
});
|
166
|
+
}
|
167
|
+
|
168
|
+
// Command handling
|
169
|
+
login()
|
170
|
+
.then(async () => {
|
171
|
+
await open(
|
172
|
+
MSTATE_DOMAIN +
|
173
|
+
`oauth?redirect=${encodeURIComponent(
|
174
|
+
'cli/mstate/login',
|
175
|
+
)}&open=${port}&scope=profile`,
|
176
|
+
);
|
177
|
+
})
|
178
|
+
.catch((err) => {
|
179
|
+
console.error('Error during login:', err.message);
|
180
|
+
process.exit(1);
|
181
|
+
});
|
182
|
+
}
|
183
|
+
|
184
|
+
logToken() {
|
185
|
+
customLog.info('Token', getSecretKey());
|
186
|
+
}
|
106
187
|
}
|
107
188
|
|
108
189
|
export const companyHandler = new CompanyHandler();
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import * as fs from 'fs';
|
2
2
|
import path from 'path';
|
3
3
|
import { MSTATE_URL } from '../common/constant';
|
4
|
-
import { customLog,
|
4
|
+
import { customLog, getSecretKey } from '../common/utils';
|
5
|
+
import { getValueFromArgs } from '../common/helpers';
|
5
6
|
|
6
7
|
enum Key {
|
7
8
|
WORKFLOW = 'workflow=',
|
@@ -13,9 +14,8 @@ class EnvironmentHandler {
|
|
13
14
|
|
14
15
|
async cloneEnvironments() {
|
15
16
|
const args = process.argv;
|
16
|
-
const
|
17
|
-
const
|
18
|
-
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
17
|
+
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
18
|
+
const secretKey = getSecretKey();
|
19
19
|
|
20
20
|
if (!secretKey) {
|
21
21
|
customLog.changeAndThrow(`Parameter secret is required`);
|
@@ -45,7 +45,7 @@ class EnvironmentHandler {
|
|
45
45
|
} else {
|
46
46
|
const config = response?.data;
|
47
47
|
|
48
|
-
const filePath = path.resolve(
|
48
|
+
const filePath = path.resolve(workflowName, 'environment.json');
|
49
49
|
fs.writeFileSync(filePath, JSON.stringify(config, null, 2));
|
50
50
|
}
|
51
51
|
}
|
@@ -53,9 +53,8 @@ class EnvironmentHandler {
|
|
53
53
|
async saveToDB() {
|
54
54
|
const args = process.argv;
|
55
55
|
|
56
|
-
const
|
57
|
-
const
|
58
|
-
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
56
|
+
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
57
|
+
const secretKey = getSecretKey();
|
59
58
|
|
60
59
|
if (!secretKey) {
|
61
60
|
customLog.changeAndThrow(`Parameter secret is required`);
|
@@ -67,7 +66,7 @@ class EnvironmentHandler {
|
|
67
66
|
return;
|
68
67
|
}
|
69
68
|
|
70
|
-
const filePath = path.resolve(
|
69
|
+
const filePath = path.resolve(workflowName, 'environment.json');
|
71
70
|
|
72
71
|
const data = fs.readFileSync(filePath, 'utf8');
|
73
72
|
const environments = JSON.parse(data);
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { MOBIOFFICE_URL, MSTATE_URL } from '../common/constant';
|
2
1
|
import { CmdAction } from '../common/enum';
|
3
|
-
import {
|
2
|
+
import { getValueFromArgs } from '../common/helpers';
|
3
|
+
import { customLog, getSecretKey } from '../common/utils';
|
4
4
|
|
5
5
|
enum Key {
|
6
6
|
WORKFLOW = 'workflow=',
|
@@ -11,14 +11,15 @@ enum Key {
|
|
11
11
|
}
|
12
12
|
|
13
13
|
class MobiofficeHandler {
|
14
|
+
private MOBIOFFICE_URL: string = 'https://server.mobioffice.io/api';
|
15
|
+
|
14
16
|
constructor() {}
|
15
17
|
|
16
18
|
async linkToMobioffice(action: CmdAction.LINK | CmdAction.UNLINK) {
|
17
19
|
const args = process.argv;
|
18
20
|
|
19
|
-
const
|
20
|
-
const
|
21
|
-
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
21
|
+
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
22
|
+
const secretKey = getSecretKey();
|
22
23
|
const companyID = getValueFromArgs(args, Key.COMPANY_ID);
|
23
24
|
const user = getValueFromArgs(args, Key.USER_ID);
|
24
25
|
|
@@ -42,7 +43,7 @@ class MobiofficeHandler {
|
|
42
43
|
return;
|
43
44
|
}
|
44
45
|
|
45
|
-
const url = `${MOBIOFFICE_URL}/Mstate/workFlow/user`;
|
46
|
+
const url = `${this.MOBIOFFICE_URL}/Mstate/workFlow/user`;
|
46
47
|
const responseJSON = await fetch(url, {
|
47
48
|
method: 'POST',
|
48
49
|
headers: {
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import * as fs from 'fs';
|
2
2
|
import path from 'path';
|
3
3
|
import { MSTATE_URL } from '../common/constant';
|
4
|
-
import { customLog,
|
4
|
+
import { customLog, getSecretKey } from '../common/utils';
|
5
|
+
import { getValueFromArgs } from '../common/helpers';
|
5
6
|
|
6
7
|
enum Key {
|
7
8
|
PATH = 'path=',
|
@@ -17,10 +18,9 @@ class WorkflowHandler {
|
|
17
18
|
try {
|
18
19
|
const args = process.argv;
|
19
20
|
|
20
|
-
const
|
21
|
-
const workflowPath = dirPath.replace(/\//g, '__');
|
21
|
+
const workflowPath = getValueFromArgs(args, Key.PATH);
|
22
22
|
const file = getValueFromArgs(args, Key.FILE);
|
23
|
-
const secretKey =
|
23
|
+
const secretKey = getSecretKey();
|
24
24
|
|
25
25
|
if (!file) {
|
26
26
|
customLog.changeAndThrow(`Parameter file is required`);
|
@@ -71,9 +71,8 @@ class WorkflowHandler {
|
|
71
71
|
async updateWorkflowToDB() {
|
72
72
|
const args = process.argv;
|
73
73
|
|
74
|
-
const
|
75
|
-
const
|
76
|
-
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
74
|
+
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
75
|
+
const secretKey = getSecretKey();
|
77
76
|
|
78
77
|
if (!secretKey) {
|
79
78
|
customLog.changeAndThrow(`Parameter secret is required`);
|
@@ -85,7 +84,7 @@ class WorkflowHandler {
|
|
85
84
|
return;
|
86
85
|
}
|
87
86
|
|
88
|
-
const folderPath = path.resolve(
|
87
|
+
const folderPath = path.resolve(workflowName);
|
89
88
|
const filePath = path.join(folderPath, 'workflow.json');
|
90
89
|
|
91
90
|
const workflowJSON = fs.readFileSync(filePath, 'utf8');
|
@@ -118,9 +117,8 @@ class WorkflowHandler {
|
|
118
117
|
async cloneWorkflow() {
|
119
118
|
const args = process.argv;
|
120
119
|
|
121
|
-
const
|
122
|
-
const
|
123
|
-
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
120
|
+
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
121
|
+
const secretKey = getSecretKey();
|
124
122
|
|
125
123
|
if (!secretKey) {
|
126
124
|
customLog.changeAndThrow(`Parameter secret is required`);
|
@@ -132,7 +130,7 @@ class WorkflowHandler {
|
|
132
130
|
return;
|
133
131
|
}
|
134
132
|
|
135
|
-
const url = `${MSTATE_URL}/workflow/config
|
133
|
+
const url = `${MSTATE_URL}/workflow/config/?workflow=${workflowName}`;
|
136
134
|
const responseJSON = await fetch(url, {
|
137
135
|
method: 'GET',
|
138
136
|
headers: {
|
@@ -150,7 +148,7 @@ class WorkflowHandler {
|
|
150
148
|
} else {
|
151
149
|
const workflowConfig = response?.data;
|
152
150
|
|
153
|
-
const folderPath = path.resolve(
|
151
|
+
const folderPath = path.resolve(workflowName);
|
154
152
|
fs.mkdirSync(folderPath, { recursive: true });
|
155
153
|
|
156
154
|
const filePath = path.join(folderPath, 'workflow.json');
|
@@ -163,9 +161,8 @@ class WorkflowHandler {
|
|
163
161
|
async resetCache() {
|
164
162
|
const args = process.argv;
|
165
163
|
|
166
|
-
const
|
167
|
-
const
|
168
|
-
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
164
|
+
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
165
|
+
const secretKey = getSecretKey();
|
169
166
|
|
170
167
|
if (!secretKey) {
|
171
168
|
customLog.changeAndThrow(`Parameter secret is required`);
|
@@ -177,7 +174,7 @@ class WorkflowHandler {
|
|
177
174
|
return;
|
178
175
|
}
|
179
176
|
|
180
|
-
const url = `${MSTATE_URL}/cache/reset
|
177
|
+
const url = `${MSTATE_URL}/cache/reset/?workflow=${workflowName}`;
|
181
178
|
const responseJSON = await fetch(url, {
|
182
179
|
method: 'DELETE',
|
183
180
|
headers: {
|
package/src/index.ts
CHANGED
@@ -6,7 +6,8 @@ import { actionHandler } from './handlers/action.handler';
|
|
6
6
|
import { workflowHandler } from './handlers/workflow.handler';
|
7
7
|
import { CmdAction } from './common/enum';
|
8
8
|
import { mobiofficeHandler } from './handlers/mobioffice.handler';
|
9
|
-
import { customLog
|
9
|
+
import { customLog } from './common/utils';
|
10
|
+
import { hasFlag } from './common/helpers';
|
10
11
|
import { environmentHandler } from './handlers/environment.handler';
|
11
12
|
import { companyHandler } from './handlers/company.handler';
|
12
13
|
import { argv } from 'process';
|
@@ -28,8 +29,12 @@ const [action] = argv.slice(2);
|
|
28
29
|
break;
|
29
30
|
|
30
31
|
case CmdAction.USER:
|
31
|
-
|
32
|
-
|
32
|
+
companyHandler.logToken();
|
33
|
+
// if (hasFlag(argv, '-d')) companyHandler.revokePermission();
|
34
|
+
// else companyHandler.addToken();
|
35
|
+
break;
|
36
|
+
case CmdAction.LOGIN:
|
37
|
+
await companyHandler.handleLogin();
|
33
38
|
break;
|
34
39
|
|
35
40
|
case CmdAction.CLONE:
|
package/tsconfig.json
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
{
|
2
2
|
"compilerOptions": {
|
3
|
-
"
|
3
|
+
"target": "ESNext",
|
4
|
+
"module": "ESNext",
|
5
|
+
"moduleResolution": "Node",
|
6
|
+
"strict": true,
|
4
7
|
"rootDir": "src",
|
5
|
-
"target": "es2016",
|
6
|
-
"module": "commonjs",
|
7
8
|
"esModuleInterop": true,
|
8
|
-
"
|
9
|
-
"strict": true,
|
9
|
+
"resolveJsonModule": true,
|
10
10
|
"skipLibCheck": true,
|
11
|
-
"
|
12
|
-
"
|
13
|
-
}
|
11
|
+
"outDir": "./dist",
|
12
|
+
"declaration": true
|
13
|
+
},
|
14
|
+
"include": ["src/**/*.ts"],
|
15
|
+
"exclude": ["node_modules", "dist", ".vscode"]
|
14
16
|
}
|
package/dist/common/constant.js
DELETED
package/dist/common/enum.js
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.CmdAction = void 0;
|
4
|
-
var CmdAction;
|
5
|
-
(function (CmdAction) {
|
6
|
-
CmdAction["LINK"] = "link";
|
7
|
-
CmdAction["UNLINK"] = "unlink";
|
8
|
-
CmdAction["USER"] = "user";
|
9
|
-
CmdAction["ADD"] = "add";
|
10
|
-
CmdAction["CLONE"] = "clone";
|
11
|
-
CmdAction["PUSH"] = "push";
|
12
|
-
CmdAction["HELP"] = "--help";
|
13
|
-
CmdAction["HELP_FLAG"] = "-h";
|
14
|
-
CmdAction["VERSION"] = "--version";
|
15
|
-
CmdAction["VERSION_FLAG"] = "-v";
|
16
|
-
})(CmdAction || (exports.CmdAction = CmdAction = {}));
|
package/dist/common/utils.js
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.customLog = void 0;
|
4
|
-
exports.getValueFromArgs = getValueFromArgs;
|
5
|
-
exports.hasFlag = hasFlag;
|
6
|
-
function getValueFromArgs(args, key) {
|
7
|
-
var _a, _b;
|
8
|
-
return (_b = (_a = args.find((str) => str.includes(key))) === null || _a === void 0 ? void 0 : _a.replace(key, '')) !== null && _b !== void 0 ? _b : '';
|
9
|
-
}
|
10
|
-
exports.customLog = {
|
11
|
-
changeAndThrow(...message) {
|
12
|
-
throw new Error(message.join('\n'));
|
13
|
-
},
|
14
|
-
error(...message) {
|
15
|
-
const RED_COLOR = '\x1b[31m'; // ANSI code for red
|
16
|
-
const RESET_COLOR = '\x1b[0m'; // ANSI code to reset to default color
|
17
|
-
console.error(`${RED_COLOR}[MSTATE][ERROR] ${RESET_COLOR}`, ...message);
|
18
|
-
},
|
19
|
-
success(...message) {
|
20
|
-
const GREEN_COLOR = '\x1b[32m'; // ANSI code for green
|
21
|
-
const RESET_COLOR = '\x1b[0m'; // ANSI code to reset to default color
|
22
|
-
console.log(`${GREEN_COLOR}[MSTATE] ${RESET_COLOR}`, ...message);
|
23
|
-
},
|
24
|
-
info(key, desc) {
|
25
|
-
const optionPadding = 30; // Define spacing width for the option column
|
26
|
-
const descriptionPadding = 60; // Define spacing width for the description column
|
27
|
-
console.log(' ', key.padEnd(optionPadding) + desc.padEnd(descriptionPadding));
|
28
|
-
},
|
29
|
-
};
|
30
|
-
function hasFlag(args, flag) {
|
31
|
-
return args.includes(flag.toUpperCase()) || args.includes(flag.toLowerCase());
|
32
|
-
}
|