mstate-cli 0.2.9 → 0.3.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.
- package/.prettierrc +5 -5
- package/Readme.md +50 -50
- package/dist/index.js +298 -0
- package/package.json +45 -45
- package/rollup.config.mjs +34 -34
- package/src/common/constant.ts +26 -26
- package/src/common/enum.ts +16 -16
- 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 +267 -274
- package/src/handlers/environment.handler.ts +111 -111
- package/src/handlers/help.handler.ts +44 -48
- package/src/handlers/mobioffice.handler.ts +78 -78
- package/src/handlers/workflow.handler.ts +238 -238
- package/src/index.ts +85 -85
- package/src/interface.d.ts +43 -43
- package/tsconfig.json +18 -18
@@ -1,131 +1,131 @@
|
|
1
|
-
import * as fs from 'fs';
|
2
|
-
import path from 'path';
|
3
|
-
import { MSTATE_URL } from '../common/constant';
|
4
|
-
import { getValueFromArgs } from '../common/helpers';
|
5
|
-
import { customLog, getSecretKey } from '../common/utils';
|
6
|
-
|
7
|
-
enum Key {
|
8
|
-
WORKFLOW = 'workflow=',
|
9
|
-
SECRET_KEY = 'secret=',
|
10
|
-
TYPE = 'type=',
|
11
|
-
}
|
12
|
-
|
13
|
-
class ActionHandler {
|
14
|
-
constructor() {}
|
15
|
-
|
16
|
-
async cloneActions() {
|
17
|
-
const args = process.argv;
|
18
|
-
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
19
|
-
const secretKey = getSecretKey();
|
20
|
-
const type = getValueFromArgs(args, Key.TYPE);
|
21
|
-
|
22
|
-
if (!secretKey) {
|
23
|
-
customLog.changeAndThrow(`Parameter secret is required`);
|
24
|
-
return;
|
25
|
-
}
|
26
|
-
|
27
|
-
if (!workflowName) {
|
28
|
-
customLog.changeAndThrow(`Parameter workflow is required`);
|
29
|
-
return;
|
30
|
-
}
|
31
|
-
|
32
|
-
let query = `?workflow=${workflowName}`;
|
33
|
-
if (type) {
|
34
|
-
query += `&type=${type}`;
|
35
|
-
}
|
36
|
-
|
37
|
-
const url = `${MSTATE_URL}/action/config/all/${query}`;
|
38
|
-
|
39
|
-
const responseJSON = await fetch(url, {
|
40
|
-
headers: {
|
41
|
-
'Content-Type': 'application/json',
|
42
|
-
'secret-key': secretKey,
|
43
|
-
},
|
44
|
-
});
|
45
|
-
|
46
|
-
const response = await responseJSON.json();
|
47
|
-
if (response?.errors) {
|
48
|
-
customLog.changeAndThrow(
|
49
|
-
'Invalid Parameters for Action: ',
|
50
|
-
...response?.errors,
|
51
|
-
);
|
52
|
-
} else {
|
53
|
-
const actionConfigs = response?.data;
|
54
|
-
|
55
|
-
const folderPath = path.resolve(workflowName, 'actions');
|
56
|
-
fs.mkdirSync(folderPath, { recursive: true });
|
57
|
-
|
58
|
-
actionConfigs.forEach((config: ActionConfig) => {
|
59
|
-
try {
|
60
|
-
const file = path.join(folderPath, `${config?.name}.json`);
|
61
|
-
fs.writeFileSync(file, JSON.stringify(config, null, 2));
|
62
|
-
|
63
|
-
customLog.success(
|
64
|
-
'file created at',
|
65
|
-
folderPath,
|
66
|
-
`${config?.name}.json`,
|
67
|
-
);
|
68
|
-
} catch (error: any) {
|
69
|
-
customLog.error(error.message);
|
70
|
-
}
|
71
|
-
});
|
72
|
-
}
|
73
|
-
}
|
74
|
-
|
75
|
-
async saveToDB() {
|
76
|
-
const args = process.argv;
|
77
|
-
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
78
|
-
const type = getValueFromArgs(args, Key.TYPE);
|
79
|
-
const secretKey = getSecretKey();
|
80
|
-
|
81
|
-
if (!secretKey) {
|
82
|
-
customLog.changeAndThrow(`Parameter secret is required`);
|
83
|
-
return;
|
84
|
-
}
|
85
|
-
|
86
|
-
if (!workflowName) {
|
87
|
-
customLog.changeAndThrow(`Parameter workflow is required`);
|
88
|
-
return;
|
89
|
-
}
|
90
|
-
|
91
|
-
const folderPath = path.resolve(workflowName, 'actions');
|
92
|
-
|
93
|
-
let query = `?workflow=${workflowName}`;
|
94
|
-
if (type) {
|
95
|
-
query += `&type=${type}`;
|
96
|
-
}
|
97
|
-
|
98
|
-
// loop to every folder to publish workflow
|
99
|
-
fs.readdir(folderPath, (err, files) => {
|
100
|
-
if (!files) return;
|
101
|
-
|
102
|
-
files.forEach(async (fileName) => {
|
103
|
-
const filePath = path.join(folderPath, fileName);
|
104
|
-
const data = fs.readFileSync(filePath, 'utf8');
|
105
|
-
|
106
|
-
const url = `${MSTATE_URL}/action/config/${query}`;
|
107
|
-
const responseJSON = await fetch(url, {
|
108
|
-
method: 'PUT',
|
109
|
-
headers: {
|
110
|
-
'secret-key': secretKey,
|
111
|
-
'Content-Type': 'application/json',
|
112
|
-
},
|
113
|
-
body: data,
|
114
|
-
});
|
115
|
-
const response = await responseJSON.json();
|
116
|
-
|
117
|
-
const actionConfig = JSON.parse(data) as ActionConfig;
|
118
|
-
if (response?.errors) {
|
119
|
-
customLog.error(
|
120
|
-
`Invalid Parameters for Action ${actionConfig.name}: `,
|
121
|
-
...response?.errors,
|
122
|
-
);
|
123
|
-
} else {
|
124
|
-
customLog.success(`Action ${actionConfig.name} Updated successfully`);
|
125
|
-
}
|
126
|
-
});
|
127
|
-
});
|
128
|
-
}
|
129
|
-
}
|
130
|
-
|
131
|
-
export const actionHandler = new ActionHandler();
|
1
|
+
import * as fs from 'fs';
|
2
|
+
import path from 'path';
|
3
|
+
import { MSTATE_URL } from '../common/constant';
|
4
|
+
import { getValueFromArgs } from '../common/helpers';
|
5
|
+
import { customLog, getSecretKey } from '../common/utils';
|
6
|
+
|
7
|
+
enum Key {
|
8
|
+
WORKFLOW = 'workflow=',
|
9
|
+
SECRET_KEY = 'secret=',
|
10
|
+
TYPE = 'type=',
|
11
|
+
}
|
12
|
+
|
13
|
+
class ActionHandler {
|
14
|
+
constructor() {}
|
15
|
+
|
16
|
+
async cloneActions() {
|
17
|
+
const args = process.argv;
|
18
|
+
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
19
|
+
const secretKey = getSecretKey();
|
20
|
+
const type = getValueFromArgs(args, Key.TYPE);
|
21
|
+
|
22
|
+
if (!secretKey) {
|
23
|
+
customLog.changeAndThrow(`Parameter secret is required`);
|
24
|
+
return;
|
25
|
+
}
|
26
|
+
|
27
|
+
if (!workflowName) {
|
28
|
+
customLog.changeAndThrow(`Parameter workflow is required`);
|
29
|
+
return;
|
30
|
+
}
|
31
|
+
|
32
|
+
let query = `?workflow=${workflowName}`;
|
33
|
+
if (type) {
|
34
|
+
query += `&type=${type}`;
|
35
|
+
}
|
36
|
+
|
37
|
+
const url = `${MSTATE_URL}/action/config/all/${query}`;
|
38
|
+
|
39
|
+
const responseJSON = await fetch(url, {
|
40
|
+
headers: {
|
41
|
+
'Content-Type': 'application/json',
|
42
|
+
'secret-key': secretKey,
|
43
|
+
},
|
44
|
+
});
|
45
|
+
|
46
|
+
const response = await responseJSON.json();
|
47
|
+
if (response?.errors) {
|
48
|
+
customLog.changeAndThrow(
|
49
|
+
'Invalid Parameters for Action: ',
|
50
|
+
...response?.errors,
|
51
|
+
);
|
52
|
+
} else {
|
53
|
+
const actionConfigs = response?.data;
|
54
|
+
|
55
|
+
const folderPath = path.resolve(workflowName, 'actions');
|
56
|
+
fs.mkdirSync(folderPath, { recursive: true });
|
57
|
+
|
58
|
+
actionConfigs.forEach((config: ActionConfig) => {
|
59
|
+
try {
|
60
|
+
const file = path.join(folderPath, `${config?.name}.json`);
|
61
|
+
fs.writeFileSync(file, JSON.stringify(config, null, 2));
|
62
|
+
|
63
|
+
customLog.success(
|
64
|
+
'file created at',
|
65
|
+
folderPath,
|
66
|
+
`${config?.name}.json`,
|
67
|
+
);
|
68
|
+
} catch (error: any) {
|
69
|
+
customLog.error(error.message);
|
70
|
+
}
|
71
|
+
});
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
async saveToDB() {
|
76
|
+
const args = process.argv;
|
77
|
+
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
78
|
+
const type = getValueFromArgs(args, Key.TYPE);
|
79
|
+
const secretKey = getSecretKey();
|
80
|
+
|
81
|
+
if (!secretKey) {
|
82
|
+
customLog.changeAndThrow(`Parameter secret is required`);
|
83
|
+
return;
|
84
|
+
}
|
85
|
+
|
86
|
+
if (!workflowName) {
|
87
|
+
customLog.changeAndThrow(`Parameter workflow is required`);
|
88
|
+
return;
|
89
|
+
}
|
90
|
+
|
91
|
+
const folderPath = path.resolve(workflowName, 'actions');
|
92
|
+
|
93
|
+
let query = `?workflow=${workflowName}`;
|
94
|
+
if (type) {
|
95
|
+
query += `&type=${type}`;
|
96
|
+
}
|
97
|
+
|
98
|
+
// loop to every folder to publish workflow
|
99
|
+
fs.readdir(folderPath, (err, files) => {
|
100
|
+
if (!files) return;
|
101
|
+
|
102
|
+
files.forEach(async (fileName) => {
|
103
|
+
const filePath = path.join(folderPath, fileName);
|
104
|
+
const data = fs.readFileSync(filePath, 'utf8');
|
105
|
+
|
106
|
+
const url = `${MSTATE_URL}/action/config/${query}`;
|
107
|
+
const responseJSON = await fetch(url, {
|
108
|
+
method: 'PUT',
|
109
|
+
headers: {
|
110
|
+
'secret-key': secretKey,
|
111
|
+
'Content-Type': 'application/json',
|
112
|
+
},
|
113
|
+
body: data,
|
114
|
+
});
|
115
|
+
const response = await responseJSON.json();
|
116
|
+
|
117
|
+
const actionConfig = JSON.parse(data) as ActionConfig;
|
118
|
+
if (response?.errors) {
|
119
|
+
customLog.error(
|
120
|
+
`Invalid Parameters for Action ${actionConfig.name}: `,
|
121
|
+
...response?.errors,
|
122
|
+
);
|
123
|
+
} else {
|
124
|
+
customLog.success(`Action ${actionConfig.name} Updated successfully`);
|
125
|
+
}
|
126
|
+
});
|
127
|
+
});
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
export const actionHandler = new ActionHandler();
|