mstate-cli 0.2.7 → 0.2.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/.prettierrc +5 -5
- package/Readme.md +50 -50
- package/package.json +45 -45
- package/rollup.config.mjs +34 -34
- package/src/common/constant.ts +26 -26
- package/src/common/enum.ts +16 -17
- 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 +274 -274
- package/src/handlers/environment.handler.ts +111 -111
- package/src/handlers/help.handler.ts +48 -48
- package/src/handlers/mobioffice.handler.ts +78 -78
- package/src/handlers/workflow.handler.ts +238 -238
- package/src/index.ts +85 -88
- package/src/interface.d.ts +43 -43
- package/tsconfig.json +18 -18
- package/dist/index.js +0 -298
@@ -1,111 +1,111 @@
|
|
1
|
-
import * as fs from 'fs';
|
2
|
-
import path from 'path';
|
3
|
-
import { MSTATE_URL } from '../common/constant';
|
4
|
-
import { customLog, getSecretKey } from '../common/utils';
|
5
|
-
import { getValueFromArgs } from '../common/helpers';
|
6
|
-
|
7
|
-
enum Key {
|
8
|
-
WORKFLOW = 'workflow=',
|
9
|
-
SECRET_KEY = 'secret=',
|
10
|
-
TYPE = 'type=',
|
11
|
-
}
|
12
|
-
|
13
|
-
class EnvironmentHandler {
|
14
|
-
constructor() {}
|
15
|
-
|
16
|
-
async cloneEnvironments() {
|
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
|
-
const url = `${MSTATE_URL}/env/${query}`;
|
37
|
-
|
38
|
-
const responseJSON = await fetch(url, {
|
39
|
-
headers: {
|
40
|
-
'Content-Type': 'application/json',
|
41
|
-
'secret-key': secretKey,
|
42
|
-
},
|
43
|
-
});
|
44
|
-
|
45
|
-
const response = await responseJSON.json();
|
46
|
-
if (response?.errors) {
|
47
|
-
customLog.changeAndThrow(
|
48
|
-
'Invalid Parameters for Environment: ',
|
49
|
-
...response?.errors,
|
50
|
-
);
|
51
|
-
} else {
|
52
|
-
const config = response?.data;
|
53
|
-
|
54
|
-
const filePath = path.resolve(workflowName, 'environment.json');
|
55
|
-
fs.writeFileSync(filePath, JSON.stringify(config, null, 2));
|
56
|
-
}
|
57
|
-
}
|
58
|
-
|
59
|
-
async saveToDB() {
|
60
|
-
const args = process.argv;
|
61
|
-
|
62
|
-
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
63
|
-
const secretKey = getSecretKey();
|
64
|
-
const type = getValueFromArgs(args, Key.TYPE) || undefined;
|
65
|
-
|
66
|
-
if (!secretKey) {
|
67
|
-
customLog.changeAndThrow(`Parameter secret is required`);
|
68
|
-
return;
|
69
|
-
}
|
70
|
-
|
71
|
-
if (!workflowName) {
|
72
|
-
customLog.changeAndThrow(`Parameter workflow is required`);
|
73
|
-
return;
|
74
|
-
}
|
75
|
-
|
76
|
-
const filePath = path.resolve(workflowName, 'environment.json');
|
77
|
-
|
78
|
-
const data = fs.readFileSync(filePath, 'utf8');
|
79
|
-
const environments = JSON.parse(data);
|
80
|
-
|
81
|
-
try {
|
82
|
-
const url = `${MSTATE_URL}/env`;
|
83
|
-
const responseJSON = await fetch(url, {
|
84
|
-
method: 'POST',
|
85
|
-
headers: {
|
86
|
-
'secret-key': secretKey,
|
87
|
-
'Content-Type': 'application/json',
|
88
|
-
},
|
89
|
-
body: JSON.stringify({
|
90
|
-
workflow: workflowName,
|
91
|
-
env: environments,
|
92
|
-
type,
|
93
|
-
}),
|
94
|
-
});
|
95
|
-
|
96
|
-
const response = await responseJSON.json();
|
97
|
-
if (response?.errors) {
|
98
|
-
customLog.changeAndThrow(
|
99
|
-
`Invalid Parameters for Environment: `,
|
100
|
-
...response?.errors,
|
101
|
-
);
|
102
|
-
} else {
|
103
|
-
customLog.success(`Environments Updated successfully`);
|
104
|
-
}
|
105
|
-
} catch (error: any) {
|
106
|
-
customLog.changeAndThrow(error.message);
|
107
|
-
}
|
108
|
-
}
|
109
|
-
}
|
110
|
-
|
111
|
-
export const environmentHandler = new EnvironmentHandler();
|
1
|
+
import * as fs from 'fs';
|
2
|
+
import path from 'path';
|
3
|
+
import { MSTATE_URL } from '../common/constant';
|
4
|
+
import { customLog, getSecretKey } from '../common/utils';
|
5
|
+
import { getValueFromArgs } from '../common/helpers';
|
6
|
+
|
7
|
+
enum Key {
|
8
|
+
WORKFLOW = 'workflow=',
|
9
|
+
SECRET_KEY = 'secret=',
|
10
|
+
TYPE = 'type=',
|
11
|
+
}
|
12
|
+
|
13
|
+
class EnvironmentHandler {
|
14
|
+
constructor() {}
|
15
|
+
|
16
|
+
async cloneEnvironments() {
|
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
|
+
const url = `${MSTATE_URL}/env/${query}`;
|
37
|
+
|
38
|
+
const responseJSON = await fetch(url, {
|
39
|
+
headers: {
|
40
|
+
'Content-Type': 'application/json',
|
41
|
+
'secret-key': secretKey,
|
42
|
+
},
|
43
|
+
});
|
44
|
+
|
45
|
+
const response = await responseJSON.json();
|
46
|
+
if (response?.errors) {
|
47
|
+
customLog.changeAndThrow(
|
48
|
+
'Invalid Parameters for Environment: ',
|
49
|
+
...response?.errors,
|
50
|
+
);
|
51
|
+
} else {
|
52
|
+
const config = response?.data;
|
53
|
+
|
54
|
+
const filePath = path.resolve(workflowName, 'environment.json');
|
55
|
+
fs.writeFileSync(filePath, JSON.stringify(config, null, 2));
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
async saveToDB() {
|
60
|
+
const args = process.argv;
|
61
|
+
|
62
|
+
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
63
|
+
const secretKey = getSecretKey();
|
64
|
+
const type = getValueFromArgs(args, Key.TYPE) || undefined;
|
65
|
+
|
66
|
+
if (!secretKey) {
|
67
|
+
customLog.changeAndThrow(`Parameter secret is required`);
|
68
|
+
return;
|
69
|
+
}
|
70
|
+
|
71
|
+
if (!workflowName) {
|
72
|
+
customLog.changeAndThrow(`Parameter workflow is required`);
|
73
|
+
return;
|
74
|
+
}
|
75
|
+
|
76
|
+
const filePath = path.resolve(workflowName, 'environment.json');
|
77
|
+
|
78
|
+
const data = fs.readFileSync(filePath, 'utf8');
|
79
|
+
const environments = JSON.parse(data);
|
80
|
+
|
81
|
+
try {
|
82
|
+
const url = `${MSTATE_URL}/env`;
|
83
|
+
const responseJSON = await fetch(url, {
|
84
|
+
method: 'POST',
|
85
|
+
headers: {
|
86
|
+
'secret-key': secretKey,
|
87
|
+
'Content-Type': 'application/json',
|
88
|
+
},
|
89
|
+
body: JSON.stringify({
|
90
|
+
workflow: workflowName,
|
91
|
+
env: environments,
|
92
|
+
type,
|
93
|
+
}),
|
94
|
+
});
|
95
|
+
|
96
|
+
const response = await responseJSON.json();
|
97
|
+
if (response?.errors) {
|
98
|
+
customLog.changeAndThrow(
|
99
|
+
`Invalid Parameters for Environment: `,
|
100
|
+
...response?.errors,
|
101
|
+
);
|
102
|
+
} else {
|
103
|
+
customLog.success(`Environments Updated successfully`);
|
104
|
+
}
|
105
|
+
} catch (error: any) {
|
106
|
+
customLog.changeAndThrow(error.message);
|
107
|
+
}
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
export const environmentHandler = new EnvironmentHandler();
|
@@ -1,48 +1,48 @@
|
|
1
|
-
import { CmdAction } from '../common/enum';
|
2
|
-
import { customLog } from '../common/utils';
|
3
|
-
|
4
|
-
class HelpHandler {
|
5
|
-
logCommandInfo() {
|
6
|
-
console.log('\n\nUsage: mstate [cmd] [parameter]="[value]"\n');
|
7
|
-
|
8
|
-
console.log('Commands:');
|
9
|
-
customLog.info(CmdAction.ADD, 'Add new workflow');
|
10
|
-
customLog.info(
|
11
|
-
CmdAction.CLONE,
|
12
|
-
'Clone workflow with actions and environments',
|
13
|
-
);
|
14
|
-
customLog.info(
|
15
|
-
CmdAction.COPY,
|
16
|
-
'crete a new workflow by copying the current',
|
17
|
-
);
|
18
|
-
customLog.info(CmdAction.PUSH, 'Update the changes one in cloned workflow');
|
19
|
-
customLog.info(
|
20
|
-
CmdAction.LINK,
|
21
|
-
'Add workflow and allow user to view workflow in the mobioffice application',
|
22
|
-
);
|
23
|
-
customLog.info(
|
24
|
-
CmdAction.UNLINK,
|
25
|
-
'Disallow user to view workflow in the mobioffice application',
|
26
|
-
);
|
27
|
-
customLog.info(
|
28
|
-
[CmdAction.VERSION_FLAG, CmdAction.VERSION].toString(),
|
29
|
-
'print mstate-cli version',
|
30
|
-
);
|
31
|
-
}
|
32
|
-
|
33
|
-
logActionInfo(action: CmdAction) {
|
34
|
-
switch (action) {
|
35
|
-
case CmdAction.ADD:
|
36
|
-
break;
|
37
|
-
default:
|
38
|
-
customLog.error(
|
39
|
-
`${action ? 'Invalid' : 'Missing'} script: ${action ?? ''}`,
|
40
|
-
);
|
41
|
-
console.log(
|
42
|
-
`use 'mstate ${CmdAction.HELP_FLAG}, ${CmdAction.HELP}' for getting allowed action`,
|
43
|
-
);
|
44
|
-
}
|
45
|
-
}
|
46
|
-
}
|
47
|
-
|
48
|
-
export const helpHandler = new HelpHandler();
|
1
|
+
import { CmdAction } from '../common/enum';
|
2
|
+
import { customLog } from '../common/utils';
|
3
|
+
|
4
|
+
class HelpHandler {
|
5
|
+
logCommandInfo() {
|
6
|
+
console.log('\n\nUsage: mstate [cmd] [parameter]="[value]"\n');
|
7
|
+
|
8
|
+
console.log('Commands:');
|
9
|
+
customLog.info(CmdAction.ADD, 'Add new workflow');
|
10
|
+
customLog.info(
|
11
|
+
CmdAction.CLONE,
|
12
|
+
'Clone workflow with actions and environments',
|
13
|
+
);
|
14
|
+
customLog.info(
|
15
|
+
CmdAction.COPY,
|
16
|
+
'crete a new workflow by copying the current',
|
17
|
+
);
|
18
|
+
customLog.info(CmdAction.PUSH, 'Update the changes one in cloned workflow');
|
19
|
+
customLog.info(
|
20
|
+
CmdAction.LINK,
|
21
|
+
'Add workflow and allow user to view workflow in the mobioffice application',
|
22
|
+
);
|
23
|
+
customLog.info(
|
24
|
+
CmdAction.UNLINK,
|
25
|
+
'Disallow user to view workflow in the mobioffice application',
|
26
|
+
);
|
27
|
+
customLog.info(
|
28
|
+
[CmdAction.VERSION_FLAG, CmdAction.VERSION].toString(),
|
29
|
+
'print mstate-cli version',
|
30
|
+
);
|
31
|
+
}
|
32
|
+
|
33
|
+
logActionInfo(action: CmdAction) {
|
34
|
+
switch (action) {
|
35
|
+
case CmdAction.ADD:
|
36
|
+
break;
|
37
|
+
default:
|
38
|
+
customLog.error(
|
39
|
+
`${action ? 'Invalid' : 'Missing'} script: ${action ?? ''}`,
|
40
|
+
);
|
41
|
+
console.log(
|
42
|
+
`use 'mstate ${CmdAction.HELP_FLAG}, ${CmdAction.HELP}' for getting allowed action`,
|
43
|
+
);
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
export const helpHandler = new HelpHandler();
|
@@ -1,78 +1,78 @@
|
|
1
|
-
import { MOBIOFFICE_URL } from '../common/constant';
|
2
|
-
import { CmdAction } from '../common/enum';
|
3
|
-
import { getValueFromArgs } from '../common/helpers';
|
4
|
-
import { customLog, getSecretKey } from '../common/utils';
|
5
|
-
|
6
|
-
enum Key {
|
7
|
-
WORKFLOW = 'workflow=',
|
8
|
-
PERMISSIONS = 'permissions=',
|
9
|
-
SECRET_KEY = 'secret=',
|
10
|
-
COMPANY_NAME = 'company=',
|
11
|
-
USER_ID = 'user=',
|
12
|
-
TYPE = 'type=',
|
13
|
-
}
|
14
|
-
|
15
|
-
class MobiofficeHandler {
|
16
|
-
private MOBIOFFICE_URL: string = MOBIOFFICE_URL;
|
17
|
-
|
18
|
-
constructor() {}
|
19
|
-
|
20
|
-
async linkToMobioffice(action: CmdAction.LINK | CmdAction.UNLINK) {
|
21
|
-
const args = process.argv;
|
22
|
-
|
23
|
-
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
24
|
-
const secretKey = getSecretKey();
|
25
|
-
const companyName = getValueFromArgs(args, Key.COMPANY_NAME);
|
26
|
-
const user = getValueFromArgs(args, Key.USER_ID);
|
27
|
-
const type = getValueFromArgs(args, Key.TYPE) || 'private';
|
28
|
-
|
29
|
-
if (!workflowName) {
|
30
|
-
customLog.changeAndThrow(`Parameter workflow is required`);
|
31
|
-
return;
|
32
|
-
}
|
33
|
-
|
34
|
-
if (!secretKey) {
|
35
|
-
customLog.changeAndThrow(`Parameter secret is required`);
|
36
|
-
return;
|
37
|
-
}
|
38
|
-
|
39
|
-
if (!companyName) {
|
40
|
-
customLog.changeAndThrow(`Parameter company is required`);
|
41
|
-
return;
|
42
|
-
}
|
43
|
-
|
44
|
-
if (!user) {
|
45
|
-
customLog.changeAndThrow(`Parameter user is required`);
|
46
|
-
return;
|
47
|
-
}
|
48
|
-
|
49
|
-
const url = `${this.MOBIOFFICE_URL}/Mstate/workFlow/user`;
|
50
|
-
const responseJSON = await fetch(url, {
|
51
|
-
method: 'POST',
|
52
|
-
headers: {
|
53
|
-
'secret-key': secretKey,
|
54
|
-
'Content-Type': 'application/json',
|
55
|
-
},
|
56
|
-
body: JSON.stringify({
|
57
|
-
action: action.toUpperCase(),
|
58
|
-
workflow: workflowName,
|
59
|
-
secret: secretKey,
|
60
|
-
nickname: companyName,
|
61
|
-
type,
|
62
|
-
user,
|
63
|
-
}),
|
64
|
-
});
|
65
|
-
|
66
|
-
const response = await responseJSON.json();
|
67
|
-
if (responseJSON.status >= 400) {
|
68
|
-
customLog.changeAndThrow(
|
69
|
-
'Invalid Parameters for Linking: ',
|
70
|
-
responseJSON.statusText,
|
71
|
-
);
|
72
|
-
} else {
|
73
|
-
customLog.success('Workflow Added successfully', response?.message);
|
74
|
-
}
|
75
|
-
}
|
76
|
-
}
|
77
|
-
|
78
|
-
export const mobiofficeHandler = new MobiofficeHandler();
|
1
|
+
import { MOBIOFFICE_URL } from '../common/constant';
|
2
|
+
import { CmdAction } from '../common/enum';
|
3
|
+
import { getValueFromArgs } from '../common/helpers';
|
4
|
+
import { customLog, getSecretKey } from '../common/utils';
|
5
|
+
|
6
|
+
enum Key {
|
7
|
+
WORKFLOW = 'workflow=',
|
8
|
+
PERMISSIONS = 'permissions=',
|
9
|
+
SECRET_KEY = 'secret=',
|
10
|
+
COMPANY_NAME = 'company=',
|
11
|
+
USER_ID = 'user=',
|
12
|
+
TYPE = 'type=',
|
13
|
+
}
|
14
|
+
|
15
|
+
class MobiofficeHandler {
|
16
|
+
private MOBIOFFICE_URL: string = MOBIOFFICE_URL;
|
17
|
+
|
18
|
+
constructor() {}
|
19
|
+
|
20
|
+
async linkToMobioffice(action: CmdAction.LINK | CmdAction.UNLINK) {
|
21
|
+
const args = process.argv;
|
22
|
+
|
23
|
+
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
24
|
+
const secretKey = getSecretKey();
|
25
|
+
const companyName = getValueFromArgs(args, Key.COMPANY_NAME);
|
26
|
+
const user = getValueFromArgs(args, Key.USER_ID);
|
27
|
+
const type = getValueFromArgs(args, Key.TYPE) || 'private';
|
28
|
+
|
29
|
+
if (!workflowName) {
|
30
|
+
customLog.changeAndThrow(`Parameter workflow is required`);
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
|
34
|
+
if (!secretKey) {
|
35
|
+
customLog.changeAndThrow(`Parameter secret is required`);
|
36
|
+
return;
|
37
|
+
}
|
38
|
+
|
39
|
+
if (!companyName) {
|
40
|
+
customLog.changeAndThrow(`Parameter company is required`);
|
41
|
+
return;
|
42
|
+
}
|
43
|
+
|
44
|
+
if (!user) {
|
45
|
+
customLog.changeAndThrow(`Parameter user is required`);
|
46
|
+
return;
|
47
|
+
}
|
48
|
+
|
49
|
+
const url = `${this.MOBIOFFICE_URL}/Mstate/workFlow/user`;
|
50
|
+
const responseJSON = await fetch(url, {
|
51
|
+
method: 'POST',
|
52
|
+
headers: {
|
53
|
+
'secret-key': secretKey,
|
54
|
+
'Content-Type': 'application/json',
|
55
|
+
},
|
56
|
+
body: JSON.stringify({
|
57
|
+
action: action.toUpperCase(),
|
58
|
+
workflow: workflowName,
|
59
|
+
secret: secretKey,
|
60
|
+
nickname: companyName,
|
61
|
+
type,
|
62
|
+
user,
|
63
|
+
}),
|
64
|
+
});
|
65
|
+
|
66
|
+
const response = await responseJSON.json();
|
67
|
+
if (responseJSON.status >= 400) {
|
68
|
+
customLog.changeAndThrow(
|
69
|
+
'Invalid Parameters for Linking: ',
|
70
|
+
responseJSON.statusText,
|
71
|
+
);
|
72
|
+
} else {
|
73
|
+
customLog.success('Workflow Added successfully', response?.message);
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
export const mobiofficeHandler = new MobiofficeHandler();
|