mstate-cli 0.1.4 → 0.1.7
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/.vscode/settings.json +3 -0
- package/Readme.md +32 -9
- package/dist/common/constant.js +2 -1
- package/dist/common/enum.js +1 -0
- package/dist/common/utils.js +7 -0
- package/dist/handlers/action.handler.js +70 -84
- package/dist/handlers/company.handler.js +104 -0
- package/dist/handlers/environment.handler.js +59 -74
- package/dist/handlers/help.handler.js +21 -0
- package/dist/handlers/mobioffice.handler.js +43 -47
- package/dist/handlers/workflow.handler.js +68 -78
- package/dist/index.js +60 -41
- package/package.json +4 -2
- package/src/common/constant.ts +2 -1
- package/src/common/enum.ts +1 -0
- package/src/common/utils.ts +7 -1
- package/src/handlers/action.handler.ts +87 -95
- package/src/handlers/company.handler.ts +108 -0
- package/src/handlers/environment.handler.ts +73 -79
- package/src/handlers/help.handler.ts +34 -0
- package/src/handlers/mobioffice.handler.ts +47 -47
- package/src/handlers/workflow.handler.ts +81 -77
- package/src/index.ts +52 -60
package/Readme.md
CHANGED
@@ -1,27 +1,50 @@
|
|
1
1
|
# Mstate CLI
|
2
2
|
|
3
|
-
|
3
|
+
<div style="display: flex; justify-content: center;">
|
4
|
+
<img src="https://docs.mstate.ai/img/mymobioffice_logo.png" alt="mstate" />
|
5
|
+
</div>
|
4
6
|
|
5
|
-
|
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:
|
6
16
|
|
7
17
|
```cmd
|
8
|
-
mstate
|
18
|
+
mstate clone secret="zW5Knss75pBgRIvJgsh6" workflow="demo/signup_form"
|
9
19
|
```
|
10
20
|
|
11
|
-
|
21
|
+
All Node.js versions are supported starting Node.js 12.X.
|
22
|
+
|
23
|
+
### Installing MSTATE CLI
|
24
|
+
|
25
|
+
With NPM:
|
12
26
|
|
13
27
|
```cmd
|
14
|
-
mstate
|
28
|
+
npm i mstate-cli -g
|
15
29
|
```
|
16
30
|
|
17
|
-
|
31
|
+
You can install Node.js easily from [Link](https://nodejs.org/en/download/package-manager).
|
32
|
+
|
33
|
+
### To list all Command:
|
18
34
|
|
19
35
|
```cmd
|
20
|
-
mstate
|
36
|
+
mstate -h
|
21
37
|
```
|
22
38
|
|
23
|
-
###
|
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.
|
24
44
|
|
25
45
|
```cmd
|
26
|
-
mstate
|
46
|
+
mstate add file="demo/signup_form/workflow.json" secret="secret-key" path="myFolder/mySubfolder"
|
27
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/dist/common/constant.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.MOBIOFFICE_URL = exports.MSTATE_URL = void 0;
|
4
|
+
exports.MSTATE_URL = 'http://localhost:3000/api';
|
4
5
|
// export const MSTATE_URL = 'https://dev.mstate.mobioffice.io/api';
|
5
|
-
|
6
|
+
// export const MSTATE_URL = 'https://api.mstate.mobioffice.io/api';
|
6
7
|
exports.MOBIOFFICE_URL = 'https://server.mobioffice.io/api';
|
package/dist/common/enum.js
CHANGED
package/dist/common/utils.js
CHANGED
@@ -2,11 +2,15 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.customLog = void 0;
|
4
4
|
exports.getValueFromArgs = getValueFromArgs;
|
5
|
+
exports.hasFlag = hasFlag;
|
5
6
|
function getValueFromArgs(args, key) {
|
6
7
|
var _a, _b;
|
7
8
|
return (_b = (_a = args.find((str) => str.includes(key))) === null || _a === void 0 ? void 0 : _a.replace(key, '')) !== null && _b !== void 0 ? _b : '';
|
8
9
|
}
|
9
10
|
exports.customLog = {
|
11
|
+
changeAndThrow(...message) {
|
12
|
+
throw new Error(message.join('\n'));
|
13
|
+
},
|
10
14
|
error(...message) {
|
11
15
|
const RED_COLOR = '\x1b[31m'; // ANSI code for red
|
12
16
|
const RESET_COLOR = '\x1b[0m'; // ANSI code to reset to default color
|
@@ -23,3 +27,6 @@ exports.customLog = {
|
|
23
27
|
console.log(' ', key.padEnd(optionPadding) + desc.padEnd(descriptionPadding));
|
24
28
|
},
|
25
29
|
};
|
30
|
+
function hasFlag(args, flag) {
|
31
|
+
return args.includes(flag.toUpperCase()) || args.includes(flag.toLowerCase());
|
32
|
+
}
|
@@ -49,101 +49,87 @@ class ActionHandler {
|
|
49
49
|
constructor() { }
|
50
50
|
cloneActions() {
|
51
51
|
return __awaiter(this, void 0, void 0, function* () {
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
52
|
+
const args = process.argv;
|
53
|
+
const dirPath = (0, utils_1.getValueFromArgs)(args, Key.WORKFLOW);
|
54
|
+
const workflowName = dirPath.replace(/\//g, '__');
|
55
|
+
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
56
|
+
if (!secretKey) {
|
57
|
+
utils_1.customLog.changeAndThrow(`Parameter secret is required`);
|
58
|
+
return;
|
59
|
+
}
|
60
|
+
if (!workflowName) {
|
61
|
+
utils_1.customLog.changeAndThrow(`Parameter workflow is required`);
|
62
|
+
return;
|
63
|
+
}
|
64
|
+
const url = `${constant_1.MSTATE_URL}/action/config/all/?workflow=${workflowName}`;
|
65
|
+
const responseJSON = yield fetch(url, {
|
66
|
+
headers: {
|
67
|
+
'Content-Type': 'application/json',
|
68
|
+
'secret-key': secretKey,
|
69
|
+
},
|
70
|
+
});
|
71
|
+
const response = yield responseJSON.json();
|
72
|
+
if (response === null || response === void 0 ? void 0 : response.errors) {
|
73
|
+
utils_1.customLog.changeAndThrow('Invalid Parameters for Action: ', ...response === null || response === void 0 ? void 0 : response.errors);
|
74
|
+
}
|
75
|
+
else {
|
76
|
+
const actionConfigs = response === null || response === void 0 ? void 0 : response.data;
|
77
|
+
const folderPath = path_1.default.resolve(dirPath, 'actions');
|
78
|
+
fs.mkdirSync(folderPath, { recursive: true });
|
79
|
+
actionConfigs.forEach((config) => {
|
80
|
+
try {
|
81
|
+
const file = path_1.default.join(folderPath, `${config === null || config === void 0 ? void 0 : config.name}.json`);
|
82
|
+
fs.writeFileSync(file, JSON.stringify(config, null, 2));
|
83
|
+
utils_1.customLog.success('file created at', folderPath, `${config === null || config === void 0 ? void 0 : config.name}.json`);
|
84
|
+
}
|
85
|
+
catch (error) {
|
86
|
+
utils_1.customLog.error(error.message);
|
87
|
+
}
|
88
|
+
});
|
89
|
+
}
|
90
|
+
});
|
91
|
+
}
|
92
|
+
saveToDB() {
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
94
|
+
const args = process.argv;
|
95
|
+
const dirPath = (0, utils_1.getValueFromArgs)(args, Key.WORKFLOW);
|
96
|
+
const workflowName = dirPath.replace(/\//g, '__');
|
97
|
+
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
98
|
+
if (!secretKey) {
|
99
|
+
utils_1.customLog.changeAndThrow(`Parameter secret is required`);
|
100
|
+
return;
|
101
|
+
}
|
102
|
+
if (!workflowName) {
|
103
|
+
utils_1.customLog.changeAndThrow(`Parameter workflow is required`);
|
104
|
+
return;
|
105
|
+
}
|
106
|
+
const folderPath = path_1.default.resolve(dirPath, 'actions');
|
107
|
+
// loop to every folder to publish workflow
|
108
|
+
fs.readdir(folderPath, (err, files) => {
|
109
|
+
if (!files)
|
63
110
|
return;
|
64
|
-
|
65
|
-
|
66
|
-
const
|
111
|
+
files.forEach((fileName) => __awaiter(this, void 0, void 0, function* () {
|
112
|
+
const filePath = path_1.default.join(folderPath, fileName);
|
113
|
+
const data = fs.readFileSync(filePath, 'utf8');
|
114
|
+
const url = `${constant_1.MSTATE_URL}/action/config/?workflow=${workflowName}`;
|
67
115
|
const responseJSON = yield fetch(url, {
|
116
|
+
method: 'PUT',
|
68
117
|
headers: {
|
69
|
-
'Content-Type': 'application/json',
|
70
118
|
'secret-key': secretKey,
|
119
|
+
'Content-Type': 'application/json',
|
71
120
|
},
|
121
|
+
body: data,
|
72
122
|
});
|
73
123
|
const response = yield responseJSON.json();
|
124
|
+
const actionConfig = JSON.parse(data);
|
74
125
|
if (response === null || response === void 0 ? void 0 : response.errors) {
|
75
|
-
utils_1.customLog.error(
|
126
|
+
utils_1.customLog.error(`Invalid Parameters for Action ${actionConfig.name}: `, ...response === null || response === void 0 ? void 0 : response.errors);
|
76
127
|
}
|
77
128
|
else {
|
78
|
-
|
79
|
-
const folderPath = path_1.default.resolve(dirPath, 'actions');
|
80
|
-
fs.mkdirSync(folderPath, { recursive: true });
|
81
|
-
actionConfigs.forEach((config) => {
|
82
|
-
const file = path_1.default.join(folderPath, `${config === null || config === void 0 ? void 0 : config.name}.json`);
|
83
|
-
fs.writeFileSync(file, JSON.stringify(config, null, 2));
|
84
|
-
utils_1.customLog.success('file created at', folderPath, `${config === null || config === void 0 ? void 0 : config.name}.json`);
|
85
|
-
});
|
129
|
+
utils_1.customLog.success(`Action ${actionConfig.name} Updated successfully`);
|
86
130
|
}
|
87
|
-
}
|
88
|
-
|
89
|
-
utils_1.customLog.error('Error in cloning action', error.message);
|
90
|
-
}
|
91
|
-
}
|
92
|
-
catch (error) {
|
93
|
-
utils_1.customLog.error('Error in cloning action', error.message);
|
94
|
-
}
|
95
|
-
});
|
96
|
-
}
|
97
|
-
saveToDB() {
|
98
|
-
return __awaiter(this, void 0, void 0, function* () {
|
99
|
-
try {
|
100
|
-
const args = process.argv;
|
101
|
-
const dirPath = (0, utils_1.getValueFromArgs)(args, Key.WORKFLOW);
|
102
|
-
const workflowName = dirPath.replace(/\//g, '__');
|
103
|
-
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
104
|
-
if (!secretKey) {
|
105
|
-
utils_1.customLog.error(`Parameter secret is required`);
|
106
|
-
return;
|
107
|
-
}
|
108
|
-
if (!workflowName) {
|
109
|
-
utils_1.customLog.error(`Parameter workflow is required`);
|
110
|
-
return;
|
111
|
-
}
|
112
|
-
const folderPath = path_1.default.resolve(dirPath, 'actions');
|
113
|
-
// loop to every folder to publish workflow
|
114
|
-
fs.readdir(folderPath, (err, files) => {
|
115
|
-
if (!files)
|
116
|
-
return;
|
117
|
-
files.forEach((fileName) => __awaiter(this, void 0, void 0, function* () {
|
118
|
-
try {
|
119
|
-
const filePath = path_1.default.join(folderPath, fileName);
|
120
|
-
const data = fs.readFileSync(filePath, 'utf8');
|
121
|
-
const url = `${constant_1.MSTATE_URL}/action/config/?workflow=${workflowName}`;
|
122
|
-
const responseJSON = yield fetch(url, {
|
123
|
-
method: 'PUT',
|
124
|
-
headers: {
|
125
|
-
'secret-key': secretKey,
|
126
|
-
'Content-Type': 'application/json',
|
127
|
-
},
|
128
|
-
body: data,
|
129
|
-
});
|
130
|
-
const response = yield responseJSON.json();
|
131
|
-
if (response === null || response === void 0 ? void 0 : response.errors) {
|
132
|
-
utils_1.customLog.error(`Invalid Parameters for Action ${fileName}: `, response === null || response === void 0 ? void 0 : response.errors);
|
133
|
-
}
|
134
|
-
else {
|
135
|
-
utils_1.customLog.success(`Action ${fileName} Updated successfully`);
|
136
|
-
}
|
137
|
-
}
|
138
|
-
catch (error) {
|
139
|
-
utils_1.customLog.error(error.message);
|
140
|
-
}
|
141
|
-
}));
|
142
|
-
});
|
143
|
-
}
|
144
|
-
catch (error) {
|
145
|
-
utils_1.customLog.error(error.message);
|
146
|
-
}
|
131
|
+
}));
|
132
|
+
});
|
147
133
|
});
|
148
134
|
}
|
149
135
|
}
|
@@ -0,0 +1,104 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
exports.companyHandler = void 0;
|
13
|
+
const constant_1 = require("../common/constant");
|
14
|
+
const utils_1 = require("../common/utils");
|
15
|
+
var Key;
|
16
|
+
(function (Key) {
|
17
|
+
Key["PERMISSIONS"] = "permissions=";
|
18
|
+
Key["SECRET_KEY"] = "secret=";
|
19
|
+
Key["USER_ID"] = "user=";
|
20
|
+
})(Key || (Key = {}));
|
21
|
+
class CompanyHandler {
|
22
|
+
constructor() { }
|
23
|
+
addToken() {
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
25
|
+
const args = process.argv;
|
26
|
+
const pString = (0, utils_1.getValueFromArgs)(args, Key.PERMISSIONS).trim();
|
27
|
+
const permissions = pString.split(',');
|
28
|
+
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
29
|
+
const user = (0, utils_1.getValueFromArgs)(args, Key.USER_ID);
|
30
|
+
if (!pString.length) {
|
31
|
+
utils_1.customLog.changeAndThrow(`Parameter permissions is required`);
|
32
|
+
return;
|
33
|
+
}
|
34
|
+
if (!secretKey) {
|
35
|
+
utils_1.customLog.changeAndThrow(`Parameter secret is required`);
|
36
|
+
return;
|
37
|
+
}
|
38
|
+
if (!user) {
|
39
|
+
utils_1.customLog.changeAndThrow(`Parameter user is required`);
|
40
|
+
return;
|
41
|
+
}
|
42
|
+
const url = `${constant_1.MSTATE_URL}/company/permission`;
|
43
|
+
const responseJSON = yield fetch(url, {
|
44
|
+
method: 'POST',
|
45
|
+
headers: {
|
46
|
+
'secret-key': secretKey,
|
47
|
+
'Content-Type': 'application/json',
|
48
|
+
},
|
49
|
+
body: JSON.stringify({
|
50
|
+
user,
|
51
|
+
permissions,
|
52
|
+
}),
|
53
|
+
});
|
54
|
+
const response = yield responseJSON.json();
|
55
|
+
if (response === null || response === void 0 ? void 0 : response.errors) {
|
56
|
+
utils_1.customLog.changeAndThrow('Invalid Parameters for Company: ', ...response === null || response === void 0 ? void 0 : response.errors);
|
57
|
+
}
|
58
|
+
else {
|
59
|
+
utils_1.customLog.success('Company updated successfully \n', response === null || response === void 0 ? void 0 : response.data);
|
60
|
+
}
|
61
|
+
});
|
62
|
+
}
|
63
|
+
revokePermission() {
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
65
|
+
const args = process.argv;
|
66
|
+
const pString = (0, utils_1.getValueFromArgs)(args, Key.PERMISSIONS);
|
67
|
+
const permissions = pString.split(',');
|
68
|
+
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
69
|
+
const user = (0, utils_1.getValueFromArgs)(args, Key.USER_ID);
|
70
|
+
if (!permissions.length) {
|
71
|
+
utils_1.customLog.changeAndThrow(`Parameter permissions is required`);
|
72
|
+
return;
|
73
|
+
}
|
74
|
+
if (!secretKey) {
|
75
|
+
utils_1.customLog.changeAndThrow(`Parameter secret is required`);
|
76
|
+
return;
|
77
|
+
}
|
78
|
+
if (!user) {
|
79
|
+
utils_1.customLog.changeAndThrow(`Parameter user is required`);
|
80
|
+
return;
|
81
|
+
}
|
82
|
+
const url = `${constant_1.MSTATE_URL}/company/permission`;
|
83
|
+
const responseJSON = yield fetch(url, {
|
84
|
+
method: 'DELETE',
|
85
|
+
headers: {
|
86
|
+
'secret-key': secretKey,
|
87
|
+
'Content-Type': 'application/json',
|
88
|
+
},
|
89
|
+
body: JSON.stringify({
|
90
|
+
user,
|
91
|
+
permissions,
|
92
|
+
}),
|
93
|
+
});
|
94
|
+
const response = yield responseJSON.json();
|
95
|
+
if (response === null || response === void 0 ? void 0 : response.errors) {
|
96
|
+
utils_1.customLog.changeAndThrow('Invalid Parameters for Company: ', ...response === null || response === void 0 ? void 0 : response.errors);
|
97
|
+
}
|
98
|
+
else {
|
99
|
+
utils_1.customLog.success('Company updated successfully \n', response === null || response === void 0 ? void 0 : response.data);
|
100
|
+
}
|
101
|
+
});
|
102
|
+
}
|
103
|
+
}
|
104
|
+
exports.companyHandler = new CompanyHandler();
|
@@ -49,91 +49,76 @@ class EnvironmentHandler {
|
|
49
49
|
constructor() { }
|
50
50
|
cloneEnvironments() {
|
51
51
|
return __awaiter(this, void 0, void 0, function* () {
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
return;
|
60
|
-
}
|
61
|
-
if (!workflowName) {
|
62
|
-
utils_1.customLog.error(`Parameter workflow is required`);
|
63
|
-
return;
|
64
|
-
}
|
65
|
-
try {
|
66
|
-
const url = `${constant_1.MSTATE_URL}/env/?workflow=${workflowName}`;
|
67
|
-
const responseJSON = yield fetch(url, {
|
68
|
-
headers: {
|
69
|
-
'Content-Type': 'application/json',
|
70
|
-
'secret-key': secretKey,
|
71
|
-
},
|
72
|
-
});
|
73
|
-
const response = yield responseJSON.json();
|
74
|
-
if (response === null || response === void 0 ? void 0 : response.errors) {
|
75
|
-
utils_1.customLog.error('Invalid Parameters: ', response === null || response === void 0 ? void 0 : response.errors);
|
76
|
-
}
|
77
|
-
else {
|
78
|
-
const config = response === null || response === void 0 ? void 0 : response.data;
|
79
|
-
const filePath = path_1.default.resolve(dirPath, 'environment.json');
|
80
|
-
fs.writeFileSync(filePath, JSON.stringify(config, null, 2));
|
81
|
-
}
|
82
|
-
}
|
83
|
-
catch (error) {
|
84
|
-
utils_1.customLog.error('Error in cloning action', error.message);
|
85
|
-
}
|
52
|
+
const args = process.argv;
|
53
|
+
const dirPath = (0, utils_1.getValueFromArgs)(args, Key.WORKFLOW);
|
54
|
+
const workflowName = dirPath.replace(/\//g, '__');
|
55
|
+
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
56
|
+
if (!secretKey) {
|
57
|
+
utils_1.customLog.changeAndThrow(`Parameter secret is required`);
|
58
|
+
return;
|
86
59
|
}
|
87
|
-
|
88
|
-
utils_1.customLog.
|
60
|
+
if (!workflowName) {
|
61
|
+
utils_1.customLog.changeAndThrow(`Parameter workflow is required`);
|
62
|
+
return;
|
63
|
+
}
|
64
|
+
const url = `${constant_1.MSTATE_URL}/env/?workflow=${workflowName}`;
|
65
|
+
const responseJSON = yield fetch(url, {
|
66
|
+
headers: {
|
67
|
+
'Content-Type': 'application/json',
|
68
|
+
'secret-key': secretKey,
|
69
|
+
},
|
70
|
+
});
|
71
|
+
const response = yield responseJSON.json();
|
72
|
+
if (response === null || response === void 0 ? void 0 : response.errors) {
|
73
|
+
utils_1.customLog.changeAndThrow('Invalid Parameters for Environment: ', ...response === null || response === void 0 ? void 0 : response.errors);
|
74
|
+
}
|
75
|
+
else {
|
76
|
+
const config = response === null || response === void 0 ? void 0 : response.data;
|
77
|
+
const filePath = path_1.default.resolve(dirPath, 'environment.json');
|
78
|
+
fs.writeFileSync(filePath, JSON.stringify(config, null, 2));
|
89
79
|
}
|
90
80
|
});
|
91
81
|
}
|
92
82
|
saveToDB() {
|
93
83
|
return __awaiter(this, void 0, void 0, function* () {
|
84
|
+
const args = process.argv;
|
85
|
+
const dirPath = (0, utils_1.getValueFromArgs)(args, Key.WORKFLOW);
|
86
|
+
const workflowName = dirPath.replace(/\//g, '__');
|
87
|
+
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
88
|
+
if (!secretKey) {
|
89
|
+
utils_1.customLog.changeAndThrow(`Parameter secret is required`);
|
90
|
+
return;
|
91
|
+
}
|
92
|
+
if (!workflowName) {
|
93
|
+
utils_1.customLog.changeAndThrow(`Parameter workflow is required`);
|
94
|
+
return;
|
95
|
+
}
|
96
|
+
const filePath = path_1.default.resolve(dirPath, 'environment.json');
|
97
|
+
const data = fs.readFileSync(filePath, 'utf8');
|
98
|
+
const environments = JSON.parse(data);
|
94
99
|
try {
|
95
|
-
const
|
96
|
-
const
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
}
|
107
|
-
const
|
108
|
-
|
109
|
-
|
110
|
-
try {
|
111
|
-
const url = `${constant_1.MSTATE_URL}/env`;
|
112
|
-
const responseJSON = yield fetch(url, {
|
113
|
-
method: 'POST',
|
114
|
-
headers: {
|
115
|
-
'secret-key': secretKey,
|
116
|
-
'Content-Type': 'application/json',
|
117
|
-
},
|
118
|
-
body: JSON.stringify({
|
119
|
-
workflow: workflowName,
|
120
|
-
env: environments,
|
121
|
-
}),
|
122
|
-
});
|
123
|
-
const response = yield responseJSON.json();
|
124
|
-
if (response === null || response === void 0 ? void 0 : response.errors) {
|
125
|
-
utils_1.customLog.error(`Updating environment:`, response === null || response === void 0 ? void 0 : response.errors);
|
126
|
-
}
|
127
|
-
else {
|
128
|
-
utils_1.customLog.success(`Environments Updated successfully`);
|
129
|
-
}
|
100
|
+
const url = `${constant_1.MSTATE_URL}/env`;
|
101
|
+
const responseJSON = yield fetch(url, {
|
102
|
+
method: 'POST',
|
103
|
+
headers: {
|
104
|
+
'secret-key': secretKey,
|
105
|
+
'Content-Type': 'application/json',
|
106
|
+
},
|
107
|
+
body: JSON.stringify({
|
108
|
+
workflow: workflowName,
|
109
|
+
env: environments,
|
110
|
+
}),
|
111
|
+
});
|
112
|
+
const response = yield responseJSON.json();
|
113
|
+
if (response === null || response === void 0 ? void 0 : response.errors) {
|
114
|
+
utils_1.customLog.changeAndThrow(`Invalid Parameters for Environment: `, ...response === null || response === void 0 ? void 0 : response.errors);
|
130
115
|
}
|
131
|
-
|
132
|
-
utils_1.customLog.
|
116
|
+
else {
|
117
|
+
utils_1.customLog.success(`Environments Updated successfully`);
|
133
118
|
}
|
134
119
|
}
|
135
120
|
catch (error) {
|
136
|
-
utils_1.customLog.error
|
121
|
+
utils_1.customLog.changeAndThrow(error.message);
|
137
122
|
}
|
138
123
|
});
|
139
124
|
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.helpHandler = void 0;
|
4
|
+
const enum_1 = require("../common/enum");
|
5
|
+
const utils_1 = require("../common/utils");
|
6
|
+
class HelpHandler {
|
7
|
+
logCommandInfo() {
|
8
|
+
console.log('\n\nUsage: mstate [cmd] [parameter]="[value]"\n');
|
9
|
+
console.log('Commands:');
|
10
|
+
utils_1.customLog.info(enum_1.CmdAction.ADD, 'Add new workflow');
|
11
|
+
utils_1.customLog.info(enum_1.CmdAction.CLONE, 'Clone workflow with actions and environments');
|
12
|
+
utils_1.customLog.info(enum_1.CmdAction.PUSH, 'Update the changes one in cloned workflow');
|
13
|
+
utils_1.customLog.info(enum_1.CmdAction.LINK, 'add workflow and allow user to view workflow to mobioffice application');
|
14
|
+
utils_1.customLog.info(enum_1.CmdAction.UNLINK, 'add workflow and remove user to view workflow to mobioffice application');
|
15
|
+
utils_1.customLog.info([enum_1.CmdAction.VERSION_FLAG, enum_1.CmdAction.VERSION].toString(), 'add workflow and remove user to view workflow to mobioffice application');
|
16
|
+
}
|
17
|
+
logActionInfo(action) {
|
18
|
+
console.log({ action });
|
19
|
+
}
|
20
|
+
}
|
21
|
+
exports.helpHandler = new HelpHandler();
|