mstate-cli 0.1.4 → 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 +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
@@ -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,107 @@ 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;
|
71
|
-
|
72
|
-
const dirPath = getValueFromArgs(args, Key.WORKFLOW);
|
73
|
-
const workflowName = dirPath.replace(/\//g, '__');
|
74
|
-
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
72
|
+
const args = process.argv;
|
75
73
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
}
|
74
|
+
const dirPath = getValueFromArgs(args, Key.WORKFLOW);
|
75
|
+
const workflowName = dirPath.replace(/\//g, '__');
|
76
|
+
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
80
77
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
78
|
+
if (!secretKey) {
|
79
|
+
customLog.changeAndThrow(`Parameter secret is required`);
|
80
|
+
return;
|
81
|
+
}
|
85
82
|
|
86
|
-
|
87
|
-
|
83
|
+
if (!workflowName) {
|
84
|
+
customLog.changeAndThrow(`Parameter workflow is required`);
|
85
|
+
return;
|
86
|
+
}
|
88
87
|
|
89
|
-
|
88
|
+
const folderPath = path.resolve(dirPath);
|
89
|
+
const filePath = path.join(folderPath, 'workflow.json');
|
90
90
|
|
91
|
-
|
91
|
+
const workflowJSON = fs.readFileSync(filePath, 'utf8');
|
92
92
|
|
93
|
-
|
94
|
-
const responseJSON = await fetch(url, {
|
95
|
-
method: 'PUT',
|
96
|
-
headers: {
|
97
|
-
'secret-key': secretKey,
|
98
|
-
'Content-Type': 'application/json',
|
99
|
-
},
|
100
|
-
body: workflowJSON,
|
101
|
-
});
|
93
|
+
let query = `?workflow=${workflowName}`;
|
102
94
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
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
|
+
});
|
109
104
|
|
110
|
-
|
111
|
-
|
112
|
-
customLog.
|
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
113
|
}
|
114
|
+
|
115
|
+
return response;
|
114
116
|
}
|
115
117
|
|
116
118
|
async cloneWorkflow() {
|
117
|
-
|
118
|
-
const args = process.argv;
|
119
|
+
const args = process.argv;
|
119
120
|
|
120
|
-
|
121
|
-
|
122
|
-
|
121
|
+
const dirPath = getValueFromArgs(args, Key.WORKFLOW);
|
122
|
+
const workflowName = dirPath.replace(/\//g, '__');
|
123
|
+
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
123
124
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
125
|
+
if (!secretKey) {
|
126
|
+
customLog.changeAndThrow(`Parameter secret is required`);
|
127
|
+
return;
|
128
|
+
}
|
128
129
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
130
|
+
if (!workflowName) {
|
131
|
+
customLog.changeAndThrow(`Parameter workflow is required`);
|
132
|
+
return;
|
133
|
+
}
|
133
134
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
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
|
+
});
|
142
143
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
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;
|
148
152
|
|
149
|
-
|
150
|
-
|
153
|
+
const folderPath = path.resolve(dirPath);
|
154
|
+
fs.mkdirSync(folderPath, { recursive: true });
|
151
155
|
|
152
|
-
|
153
|
-
|
156
|
+
const filePath = path.join(folderPath, 'workflow.json');
|
157
|
+
fs.writeFileSync(filePath, JSON.stringify(workflowConfig, null, 2));
|
154
158
|
|
155
|
-
|
156
|
-
}
|
157
|
-
} catch (error: any) {
|
158
|
-
customLog.error('Error in cloning workflow', error.message);
|
159
|
+
customLog.success(`Workflow cloned successfully`);
|
159
160
|
}
|
160
161
|
}
|
161
162
|
|
@@ -167,12 +168,12 @@ class WorkflowHandler {
|
|
167
168
|
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
168
169
|
|
169
170
|
if (!secretKey) {
|
170
|
-
customLog.
|
171
|
+
customLog.changeAndThrow(`Parameter secret is required`);
|
171
172
|
return;
|
172
173
|
}
|
173
174
|
|
174
175
|
if (!workflowName) {
|
175
|
-
customLog.
|
176
|
+
customLog.changeAndThrow(`Parameter workflow is required`);
|
176
177
|
return;
|
177
178
|
}
|
178
179
|
|
@@ -187,7 +188,10 @@ class WorkflowHandler {
|
|
187
188
|
|
188
189
|
const response = await responseJSON.json();
|
189
190
|
if (response?.errors) {
|
190
|
-
customLog.
|
191
|
+
customLog.changeAndThrow(
|
192
|
+
'Invalid Parameters for Workflow: ',
|
193
|
+
...response?.errors,
|
194
|
+
);
|
191
195
|
} else {
|
192
196
|
customLog.success(`Workflow updated successfully`);
|
193
197
|
}
|
package/src/index.ts
CHANGED
@@ -6,70 +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
|
-
workflowHandler.resetCache();
|
40
|
-
});
|
41
|
-
break;
|
42
|
-
case CmdAction.HELP:
|
43
|
-
case CmdAction.HELP_FLAG:
|
44
|
-
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;
|
45
34
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
);
|
65
|
-
break;
|
66
|
-
default:
|
67
|
-
customLog.error(
|
68
|
-
`${action ? 'Invalid' : 'Missing'} script: ${action ?? ''}`,
|
69
|
-
);
|
70
|
-
console.log(
|
71
|
-
`use 'mstate ${CmdAction.HELP_FLAG}, ${CmdAction.HELP}' for getting allowed action`,
|
72
|
-
);
|
73
|
-
}
|
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;
|
74
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
|
+
});
|
75
67
|
console.log('');
|