mstate-cli 0.1.3 → 0.1.6
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 +0 -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 +96 -75
- package/dist/index.js +60 -40
- package/package.json +7 -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 +113 -75
- package/src/index.ts +52 -59
@@ -23,12 +23,12 @@ class WorkflowHandler {
|
|
23
23
|
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
24
24
|
|
25
25
|
if (!file) {
|
26
|
-
customLog.
|
26
|
+
customLog.changeAndThrow(`Parameter file is required`);
|
27
27
|
return;
|
28
28
|
}
|
29
29
|
|
30
30
|
if (!secretKey) {
|
31
|
-
customLog.
|
31
|
+
customLog.changeAndThrow(`Parameter secret is required`);
|
32
32
|
return;
|
33
33
|
}
|
34
34
|
|
@@ -56,106 +56,144 @@ class WorkflowHandler {
|
|
56
56
|
|
57
57
|
const response = await responseJSON.json();
|
58
58
|
if (response?.errors) {
|
59
|
-
customLog.
|
59
|
+
customLog.changeAndThrow(
|
60
|
+
'Invalid Parameters for Workflow: ',
|
61
|
+
...response?.errors,
|
62
|
+
);
|
60
63
|
} else {
|
61
64
|
customLog.success('Workflow Added successfully', response?.data);
|
62
65
|
}
|
63
66
|
} catch (error: any) {
|
64
|
-
customLog.
|
67
|
+
customLog.changeAndThrow(error.message);
|
65
68
|
}
|
66
69
|
}
|
67
70
|
|
68
71
|
async updateWorkflowToDB() {
|
69
|
-
|
70
|
-
const args = process.argv;
|
72
|
+
const args = process.argv;
|
71
73
|
|
72
|
-
|
73
|
-
|
74
|
-
|
74
|
+
const dirPath = getValueFromArgs(args, Key.WORKFLOW);
|
75
|
+
const workflowName = dirPath.replace(/\//g, '__');
|
76
|
+
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
75
77
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
78
|
+
if (!secretKey) {
|
79
|
+
customLog.changeAndThrow(`Parameter secret is required`);
|
80
|
+
return;
|
81
|
+
}
|
80
82
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
83
|
+
if (!workflowName) {
|
84
|
+
customLog.changeAndThrow(`Parameter workflow is required`);
|
85
|
+
return;
|
86
|
+
}
|
85
87
|
|
86
|
-
|
87
|
-
|
88
|
+
const folderPath = path.resolve(dirPath);
|
89
|
+
const filePath = path.join(folderPath, 'workflow.json');
|
90
|
+
|
91
|
+
const workflowJSON = fs.readFileSync(filePath, 'utf8');
|
92
|
+
|
93
|
+
let query = `?workflow=${workflowName}`;
|
94
|
+
|
95
|
+
const url = `${MSTATE_URL}/workflow/config${query}`;
|
96
|
+
const responseJSON = await fetch(url, {
|
97
|
+
method: 'PUT',
|
98
|
+
headers: {
|
99
|
+
'secret-key': secretKey,
|
100
|
+
'Content-Type': 'application/json',
|
101
|
+
},
|
102
|
+
body: workflowJSON,
|
103
|
+
});
|
104
|
+
|
105
|
+
const response = await responseJSON.json();
|
106
|
+
if (response?.errors) {
|
107
|
+
customLog.changeAndThrow(
|
108
|
+
'Invalid Parameters for Server: ',
|
109
|
+
...response?.errors,
|
110
|
+
);
|
111
|
+
} else {
|
112
|
+
customLog.success('Workflow Uploaded successfully \n', response?.data);
|
113
|
+
}
|
88
114
|
|
89
|
-
|
115
|
+
return response;
|
116
|
+
}
|
90
117
|
|
91
|
-
|
118
|
+
async cloneWorkflow() {
|
119
|
+
const args = process.argv;
|
92
120
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
headers: {
|
97
|
-
'secret-key': secretKey,
|
98
|
-
'Content-Type': 'application/json',
|
99
|
-
},
|
100
|
-
body: workflowJSON,
|
101
|
-
});
|
121
|
+
const dirPath = getValueFromArgs(args, Key.WORKFLOW);
|
122
|
+
const workflowName = dirPath.replace(/\//g, '__');
|
123
|
+
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
102
124
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
customLog.success('Workflow Uploaded successfully \n', response?.data);
|
108
|
-
}
|
125
|
+
if (!secretKey) {
|
126
|
+
customLog.changeAndThrow(`Parameter secret is required`);
|
127
|
+
return;
|
128
|
+
}
|
109
129
|
|
110
|
-
|
111
|
-
|
112
|
-
|
130
|
+
if (!workflowName) {
|
131
|
+
customLog.changeAndThrow(`Parameter workflow is required`);
|
132
|
+
return;
|
113
133
|
}
|
114
|
-
}
|
115
134
|
|
116
|
-
|
117
|
-
|
118
|
-
|
135
|
+
const url = `${MSTATE_URL}/workflow/config/${workflowName}`;
|
136
|
+
const responseJSON = await fetch(url, {
|
137
|
+
method: 'GET',
|
138
|
+
headers: {
|
139
|
+
'Content-Type': 'application/json',
|
140
|
+
'secret-key': secretKey,
|
141
|
+
},
|
142
|
+
});
|
143
|
+
|
144
|
+
const response = await responseJSON.json();
|
145
|
+
if (response?.errors) {
|
146
|
+
customLog.changeAndThrow(
|
147
|
+
'Invalid Parameters for Workflow: ',
|
148
|
+
...response?.errors,
|
149
|
+
);
|
150
|
+
} else {
|
151
|
+
const workflowConfig = response?.data;
|
119
152
|
|
120
|
-
const
|
121
|
-
|
122
|
-
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
153
|
+
const folderPath = path.resolve(dirPath);
|
154
|
+
fs.mkdirSync(folderPath, { recursive: true });
|
123
155
|
|
124
|
-
|
125
|
-
|
126
|
-
return;
|
127
|
-
}
|
156
|
+
const filePath = path.join(folderPath, 'workflow.json');
|
157
|
+
fs.writeFileSync(filePath, JSON.stringify(workflowConfig, null, 2));
|
128
158
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
}
|
159
|
+
customLog.success(`Workflow cloned successfully`);
|
160
|
+
}
|
161
|
+
}
|
133
162
|
|
134
|
-
|
135
|
-
|
136
|
-
method: 'GET',
|
137
|
-
headers: {
|
138
|
-
'Content-Type': 'application/json',
|
139
|
-
'secret-key': secretKey,
|
140
|
-
},
|
141
|
-
});
|
163
|
+
async resetCache() {
|
164
|
+
const args = process.argv;
|
142
165
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
} else {
|
147
|
-
const workflowConfig = response?.data;
|
166
|
+
const dirPath = getValueFromArgs(args, Key.WORKFLOW);
|
167
|
+
const workflowName = dirPath.replace(/\//g, '__');
|
168
|
+
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
148
169
|
|
149
|
-
|
150
|
-
|
170
|
+
if (!secretKey) {
|
171
|
+
customLog.changeAndThrow(`Parameter secret is required`);
|
172
|
+
return;
|
173
|
+
}
|
151
174
|
|
152
|
-
|
153
|
-
|
175
|
+
if (!workflowName) {
|
176
|
+
customLog.changeAndThrow(`Parameter workflow is required`);
|
177
|
+
return;
|
178
|
+
}
|
154
179
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
180
|
+
const url = `${MSTATE_URL}/cache/reset/${workflowName}`;
|
181
|
+
const responseJSON = await fetch(url, {
|
182
|
+
method: 'DELETE',
|
183
|
+
headers: {
|
184
|
+
'Content-Type': 'application/json',
|
185
|
+
'secret-key': secretKey,
|
186
|
+
},
|
187
|
+
});
|
188
|
+
|
189
|
+
const response = await responseJSON.json();
|
190
|
+
if (response?.errors) {
|
191
|
+
customLog.changeAndThrow(
|
192
|
+
'Invalid Parameters for Workflow: ',
|
193
|
+
...response?.errors,
|
194
|
+
);
|
195
|
+
} else {
|
196
|
+
customLog.success(`Workflow updated successfully`);
|
159
197
|
}
|
160
198
|
}
|
161
199
|
}
|
package/src/index.ts
CHANGED
@@ -6,69 +6,62 @@ 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 } from './common/utils';
|
9
|
+
import { customLog, hasFlag } from './common/utils';
|
10
10
|
import { environmentHandler } from './handlers/environment.handler';
|
11
|
+
import { companyHandler } from './handlers/company.handler';
|
12
|
+
import { argv } from 'process';
|
13
|
+
import { helpHandler } from './handlers/help.handler';
|
11
14
|
|
12
|
-
const [action] =
|
15
|
+
const [action] = argv.slice(2);
|
16
|
+
(async function () {
|
17
|
+
switch (action as CmdAction) {
|
18
|
+
case CmdAction.VERSION:
|
19
|
+
case CmdAction.VERSION_FLAG:
|
20
|
+
console.log(`v${packageJSON.version}`);
|
21
|
+
break;
|
13
22
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
23
|
+
case CmdAction.LINK:
|
24
|
+
case CmdAction.UNLINK:
|
25
|
+
await mobiofficeHandler.linkToMobioffice(
|
26
|
+
action as CmdAction.LINK | CmdAction.UNLINK,
|
27
|
+
);
|
28
|
+
break;
|
19
29
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
);
|
25
|
-
break;
|
26
|
-
case CmdAction.CLONE:
|
27
|
-
workflowHandler.cloneWorkflow().then(() => {
|
28
|
-
actionHandler.cloneActions();
|
29
|
-
environmentHandler.cloneEnvironments();
|
30
|
-
});
|
31
|
-
break;
|
32
|
-
case CmdAction.ADD:
|
33
|
-
workflowHandler.saveToDB();
|
34
|
-
break;
|
35
|
-
case CmdAction.PUSH:
|
36
|
-
workflowHandler.updateWorkflowToDB().then(() => {
|
37
|
-
actionHandler.saveToDB();
|
38
|
-
environmentHandler.saveToDB();
|
39
|
-
});
|
40
|
-
break;
|
41
|
-
case CmdAction.HELP:
|
42
|
-
case CmdAction.HELP_FLAG:
|
43
|
-
console.log('\n\nUsage: mstate [cmd] [parameter]="[value]"\n');
|
30
|
+
case CmdAction.USER:
|
31
|
+
if (hasFlag(argv, '-d')) companyHandler.revokePermission();
|
32
|
+
else companyHandler.addToken();
|
33
|
+
break;
|
44
34
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
);
|
64
|
-
break;
|
65
|
-
default:
|
66
|
-
customLog.error(
|
67
|
-
`${action ? 'Invalid' : 'Missing'} script: ${action ?? ''}`,
|
68
|
-
);
|
69
|
-
console.log(
|
70
|
-
`use 'mstate ${CmdAction.HELP_FLAG}, ${CmdAction.HELP}' for getting allowed action`,
|
71
|
-
);
|
72
|
-
}
|
35
|
+
case CmdAction.CLONE:
|
36
|
+
await workflowHandler.cloneWorkflow();
|
37
|
+
await actionHandler.cloneActions();
|
38
|
+
await environmentHandler.cloneEnvironments();
|
39
|
+
break;
|
40
|
+
case CmdAction.ADD:
|
41
|
+
await workflowHandler.saveToDB();
|
42
|
+
break;
|
43
|
+
case CmdAction.PUSH:
|
44
|
+
await workflowHandler.updateWorkflowToDB();
|
45
|
+
await actionHandler.saveToDB();
|
46
|
+
await environmentHandler.saveToDB();
|
47
|
+
await workflowHandler.resetCache();
|
48
|
+
break;
|
49
|
+
case CmdAction.HELP:
|
50
|
+
case CmdAction.HELP_FLAG:
|
51
|
+
helpHandler.logCommandInfo();
|
52
|
+
break;
|
73
53
|
|
54
|
+
default:
|
55
|
+
customLog.changeAndThrow(
|
56
|
+
`${action ? 'Invalid' : 'Missing'} script: ${action ?? ''}`,
|
57
|
+
);
|
58
|
+
console.log(
|
59
|
+
`use 'mstate ${CmdAction.HELP_FLAG}, ${CmdAction.HELP}' for getting allowed action`,
|
60
|
+
);
|
61
|
+
}
|
62
|
+
})().catch((error: any) => {
|
63
|
+
if (hasFlag(argv, CmdAction.HELP) || hasFlag(argv, CmdAction.HELP_FLAG)) {
|
64
|
+
helpHandler.logActionInfo(action as CmdAction);
|
65
|
+
} else customLog.error(error.message);
|
66
|
+
});
|
74
67
|
console.log('');
|