mstate-cli 0.3.0 → 0.4.1
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/Readme.md +1 -12
- package/dist/index.js +50 -50
- package/package.json +3 -2
- package/src/common/constant.ts +0 -7
- package/src/common/enum.ts +11 -1
- package/src/common/helpers.ts +19 -3
- package/src/common/utils.ts +3 -3
- package/src/handlers/action.handler.ts +3 -40
- package/src/handlers/company.handler.ts +11 -76
- package/src/handlers/environment.handler.ts +3 -37
- package/src/handlers/help.handler.ts +41 -4
- package/src/handlers/mobioffice.handler.ts +5 -40
- package/src/handlers/workflow.handler.ts +13 -80
- package/src/index.ts +5 -5
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "mstate-cli",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.4.1",
|
4
4
|
"main": "index.js",
|
5
5
|
"bin": {
|
6
6
|
"mstate": "./dist/index.js"
|
@@ -15,7 +15,8 @@
|
|
15
15
|
"mstate",
|
16
16
|
"workflow",
|
17
17
|
"cli",
|
18
|
-
"automation"
|
18
|
+
"automation",
|
19
|
+
"mobioffice"
|
19
20
|
],
|
20
21
|
"author": "",
|
21
22
|
"license": "ISC",
|
package/src/common/constant.ts
CHANGED
@@ -14,13 +14,6 @@ export const CRED_FILE_PATH = path.join(
|
|
14
14
|
|
15
15
|
export const ENCRYPT_KEY: string = 'THIS_IS_MOBIOFFICE';
|
16
16
|
|
17
|
-
// export const MSTATE_DOMAIN: string = `https://mstate.ai/`;
|
18
17
|
export const MSTATE_DOMAIN: string = MSTATE_FRONTEND_URL;
|
19
|
-
// export const MSTATE_DOMAIN: string = `https://dev.mstate.ai/`;
|
20
|
-
|
21
|
-
// export const MSTATE_URL: string = 'https://dev.mstate.mobioffice.io/api';
|
22
18
|
export const MSTATE_URL = MSTATE_API_URL;
|
23
|
-
// export const MSTATE_URL = 'https://api.mstate.mobioffice.io/api';
|
24
|
-
|
25
19
|
export const MOBIOFFICE_URL: string = MOBIOFFICE_API_URL;
|
26
|
-
// export const MOBIOFFICE_URL: string = 'https://dev-server.mobioffice.io/api';
|
package/src/common/enum.ts
CHANGED
@@ -5,7 +5,7 @@ export enum CmdAction {
|
|
5
5
|
DEV = 'dev',
|
6
6
|
UNLINK = 'unlink',
|
7
7
|
PERMISSION = 'permission',
|
8
|
-
|
8
|
+
ADD_USER = 'add-user',
|
9
9
|
ADD = 'add',
|
10
10
|
CLONE = 'clone',
|
11
11
|
PUSH = 'push',
|
@@ -14,3 +14,13 @@ export enum CmdAction {
|
|
14
14
|
VERSION = '--version',
|
15
15
|
VERSION_FLAG = '-v',
|
16
16
|
}
|
17
|
+
|
18
|
+
export enum Variables {
|
19
|
+
WORKFLOW = '-w',
|
20
|
+
SECRET = '-s',
|
21
|
+
USER_ID = '-u',
|
22
|
+
PERMISSIONS = '-p',
|
23
|
+
COMPANY_ID = '-c',
|
24
|
+
EMAIL = '-e',
|
25
|
+
PHONE = '-m',
|
26
|
+
}
|
package/src/common/helpers.ts
CHANGED
@@ -1,12 +1,28 @@
|
|
1
1
|
import CryptoJS from 'crypto-js';
|
2
2
|
import os from 'os';
|
3
3
|
import { ENCRYPT_KEY } from './constant';
|
4
|
+
import { customLog } from './utils';
|
5
|
+
import { Variables } from './enum';
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
+
const variables = Object.entries(Variables);
|
8
|
+
|
9
|
+
export function getValueFromArgs(key: string, allowed = false) {
|
10
|
+
const args = process.argv;
|
11
|
+
const variableIndex = args.indexOf(key);
|
12
|
+
const value = variableIndex !== -1 ? (args[variableIndex + 1] ?? '') : '';
|
13
|
+
|
14
|
+
if (allowed && !value) {
|
15
|
+
const [desc] = variables.find(([, flag]) => key === flag) ?? [];
|
16
|
+
customLog.changeAndThrow(
|
17
|
+
`Value for ${desc} is required. \n\t\t Use '${key}' flag for assigning value`,
|
18
|
+
);
|
19
|
+
}
|
20
|
+
|
21
|
+
return value;
|
7
22
|
}
|
8
23
|
|
9
|
-
export function hasFlag(
|
24
|
+
export function hasFlag(flag: string) {
|
25
|
+
const args = process.argv;
|
10
26
|
return args.includes(flag.toUpperCase()) || args.includes(flag.toLowerCase());
|
11
27
|
}
|
12
28
|
|
package/src/common/utils.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import fs from 'fs';
|
2
2
|
import { CRED_FILE_PATH, CRED_FOLDER_PATH } from './constant';
|
3
3
|
import { decryptData, encryptData, getValueFromArgs } from './helpers';
|
4
|
+
import { Variables } from './enum';
|
4
5
|
|
5
6
|
export const customLog = {
|
6
7
|
changeAndThrow(...message: string[]) {
|
@@ -45,15 +46,14 @@ export function getSecretKey() {
|
|
45
46
|
try {
|
46
47
|
const fileData = fs.readFileSync(CRED_FILE_PATH, 'utf8');
|
47
48
|
const secret =
|
48
|
-
getValueFromArgs(
|
49
|
-
decryptData(fileData)?.secret;
|
49
|
+
getValueFromArgs(Variables.SECRET) || decryptData(fileData)?.secret;
|
50
50
|
if (!secret) {
|
51
51
|
customLog.changeAndThrow(`Please login or Parameter secret is required`);
|
52
52
|
}
|
53
53
|
|
54
54
|
return secret;
|
55
55
|
} catch (error) {
|
56
|
-
const secretKey = getValueFromArgs(
|
56
|
+
const secretKey = getValueFromArgs(Variables.SECRET);
|
57
57
|
if (secretKey) {
|
58
58
|
return secretKey;
|
59
59
|
}
|
@@ -3,37 +3,16 @@ import path from 'path';
|
|
3
3
|
import { MSTATE_URL } from '../common/constant';
|
4
4
|
import { getValueFromArgs } from '../common/helpers';
|
5
5
|
import { customLog, getSecretKey } from '../common/utils';
|
6
|
-
|
7
|
-
enum Key {
|
8
|
-
WORKFLOW = 'workflow=',
|
9
|
-
SECRET_KEY = 'secret=',
|
10
|
-
TYPE = 'type=',
|
11
|
-
}
|
6
|
+
import { Variables } from 'src/common/enum';
|
12
7
|
|
13
8
|
class ActionHandler {
|
14
9
|
constructor() {}
|
15
10
|
|
16
11
|
async cloneActions() {
|
17
|
-
const
|
18
|
-
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
12
|
+
const workflowName = getValueFromArgs(Variables.WORKFLOW, true);
|
19
13
|
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
14
|
|
32
15
|
let query = `?workflow=${workflowName}`;
|
33
|
-
if (type) {
|
34
|
-
query += `&type=${type}`;
|
35
|
-
}
|
36
|
-
|
37
16
|
const url = `${MSTATE_URL}/action/config/all/${query}`;
|
38
17
|
|
39
18
|
const responseJSON = await fetch(url, {
|
@@ -73,28 +52,12 @@ class ActionHandler {
|
|
73
52
|
}
|
74
53
|
|
75
54
|
async saveToDB() {
|
76
|
-
const
|
77
|
-
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
78
|
-
const type = getValueFromArgs(args, Key.TYPE);
|
55
|
+
const workflowName = getValueFromArgs(Variables.WORKFLOW, true);
|
79
56
|
const secretKey = getSecretKey();
|
80
57
|
|
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
58
|
const folderPath = path.resolve(workflowName, 'actions');
|
92
59
|
|
93
60
|
let query = `?workflow=${workflowName}`;
|
94
|
-
if (type) {
|
95
|
-
query += `&type=${type}`;
|
96
|
-
}
|
97
|
-
|
98
61
|
// loop to every folder to publish workflow
|
99
62
|
fs.readdir(folderPath, (err, files) => {
|
100
63
|
if (!files) return;
|
@@ -9,49 +9,23 @@ import { getValueFromArgs } from '../common/helpers';
|
|
9
9
|
import open from 'open';
|
10
10
|
import express from 'express';
|
11
11
|
import cors from 'cors';
|
12
|
-
|
13
|
-
enum Key {
|
14
|
-
PERMISSIONS = 'permissions=',
|
15
|
-
SECRET_KEY = 'secret=',
|
16
|
-
USER_ID = 'user=',
|
17
|
-
NAME = 'name=',
|
18
|
-
EMAIL = 'email=',
|
19
|
-
PHONE = 'phone=',
|
20
|
-
COMPANY_ID = 'company=',
|
21
|
-
}
|
12
|
+
import { Variables } from 'src/common/enum';
|
22
13
|
|
23
14
|
class CompanyHandler {
|
24
15
|
constructor() {}
|
25
16
|
|
26
17
|
async addToken() {
|
27
|
-
const
|
28
|
-
|
29
|
-
const pString = getValueFromArgs(args, Key.PERMISSIONS).trim();
|
18
|
+
const pString = getValueFromArgs(Variables.PERMISSIONS).trim();
|
30
19
|
const permissions = pString.split(',').map((s) => s.trim());
|
31
20
|
const secretKey = getSecretKey();
|
32
|
-
const user = getValueFromArgs(
|
33
|
-
const companyID = getValueFromArgs(
|
21
|
+
const user = getValueFromArgs(Variables.USER_ID, true);
|
22
|
+
const companyID = getValueFromArgs(Variables.COMPANY_ID, true);
|
34
23
|
|
35
24
|
if (!permissions.length && permissions[0]?.length) {
|
36
25
|
customLog.changeAndThrow(`Parameter permissions is required`);
|
37
26
|
return;
|
38
27
|
}
|
39
28
|
|
40
|
-
if (!secretKey) {
|
41
|
-
customLog.changeAndThrow(`Parameter secret is required`);
|
42
|
-
return;
|
43
|
-
}
|
44
|
-
|
45
|
-
if (!user) {
|
46
|
-
customLog.changeAndThrow(`Parameter user is required`);
|
47
|
-
return;
|
48
|
-
}
|
49
|
-
|
50
|
-
if (!companyID) {
|
51
|
-
customLog.changeAndThrow(`Parameter company is required`);
|
52
|
-
return;
|
53
|
-
}
|
54
|
-
|
55
29
|
const url = `${MSTATE_URL}/company/permission`;
|
56
30
|
const responseJSON = await fetch(url, {
|
57
31
|
method: 'POST',
|
@@ -78,32 +52,10 @@ class CompanyHandler {
|
|
78
52
|
}
|
79
53
|
|
80
54
|
async addUser() {
|
81
|
-
const args = process.argv;
|
82
|
-
|
83
55
|
const secretKey = getSecretKey();
|
84
|
-
const name = getValueFromArgs(
|
85
|
-
const email = getValueFromArgs(
|
86
|
-
const phone = getValueFromArgs(
|
87
|
-
|
88
|
-
if (!secretKey) {
|
89
|
-
customLog.changeAndThrow(`Parameter secret is required`);
|
90
|
-
return;
|
91
|
-
}
|
92
|
-
|
93
|
-
if (!name) {
|
94
|
-
customLog.changeAndThrow(`Parameter name is required`);
|
95
|
-
return;
|
96
|
-
}
|
97
|
-
|
98
|
-
if (!email) {
|
99
|
-
customLog.changeAndThrow(`Parameter email is required`);
|
100
|
-
return;
|
101
|
-
}
|
102
|
-
|
103
|
-
if (!phone) {
|
104
|
-
customLog.changeAndThrow(`Parameter phone is required`);
|
105
|
-
return;
|
106
|
-
}
|
56
|
+
const name = getValueFromArgs(Variables.USER_ID, true);
|
57
|
+
const email = getValueFromArgs(Variables.EMAIL, true);
|
58
|
+
const phone = getValueFromArgs(Variables.PHONE, true);
|
107
59
|
|
108
60
|
const url = `${MSTATE_URL}/um/user`;
|
109
61
|
const responseJSON = await fetch(url, {
|
@@ -133,34 +85,17 @@ class CompanyHandler {
|
|
133
85
|
}
|
134
86
|
|
135
87
|
async revokePermission() {
|
136
|
-
const
|
137
|
-
|
138
|
-
const pString = getValueFromArgs(args, Key.PERMISSIONS);
|
88
|
+
const pString = getValueFromArgs(Variables.PERMISSIONS);
|
139
89
|
const permissions = pString.split(',').map((s) => s.trim());
|
140
90
|
const secretKey = getSecretKey();
|
141
|
-
const user = getValueFromArgs(
|
142
|
-
const companyID = getValueFromArgs(
|
91
|
+
const user = getValueFromArgs(Variables.USER_ID, true);
|
92
|
+
const companyID = getValueFromArgs(Variables.COMPANY_ID, true);
|
143
93
|
|
144
94
|
if (!permissions.length && permissions[0]?.length) {
|
145
95
|
customLog.changeAndThrow(`Parameter permissions is required`);
|
146
96
|
return;
|
147
97
|
}
|
148
98
|
|
149
|
-
if (!secretKey) {
|
150
|
-
customLog.changeAndThrow(`Parameter secret is required`);
|
151
|
-
return;
|
152
|
-
}
|
153
|
-
|
154
|
-
if (!user) {
|
155
|
-
customLog.changeAndThrow(`Parameter user is required`);
|
156
|
-
return;
|
157
|
-
}
|
158
|
-
|
159
|
-
if (!companyID) {
|
160
|
-
customLog.changeAndThrow(`Parameter company is required`);
|
161
|
-
return;
|
162
|
-
}
|
163
|
-
|
164
99
|
const url = `${MSTATE_URL}/company/permission`;
|
165
100
|
const responseJSON = await fetch(url, {
|
166
101
|
method: 'DELETE',
|
@@ -259,8 +194,8 @@ class CompanyHandler {
|
|
259
194
|
}
|
260
195
|
|
261
196
|
logToken() {
|
262
|
-
customLog.info('Token', getSecretKey());
|
263
197
|
customLog.info('MSTATE_URL', MSTATE_URL);
|
198
|
+
customLog.info('Token', getSecretKey());
|
264
199
|
}
|
265
200
|
}
|
266
201
|
|
@@ -3,36 +3,16 @@ import path from 'path';
|
|
3
3
|
import { MSTATE_URL } from '../common/constant';
|
4
4
|
import { customLog, getSecretKey } from '../common/utils';
|
5
5
|
import { getValueFromArgs } from '../common/helpers';
|
6
|
-
|
7
|
-
enum Key {
|
8
|
-
WORKFLOW = 'workflow=',
|
9
|
-
SECRET_KEY = 'secret=',
|
10
|
-
TYPE = 'type=',
|
11
|
-
}
|
6
|
+
import { Variables } from 'src/common/enum';
|
12
7
|
|
13
8
|
class EnvironmentHandler {
|
14
9
|
constructor() {}
|
15
10
|
|
16
11
|
async cloneEnvironments() {
|
17
|
-
const
|
18
|
-
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
12
|
+
const workflowName = getValueFromArgs(Variables.WORKFLOW, true);
|
19
13
|
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
14
|
|
32
15
|
let query = `?workflow=${workflowName}`;
|
33
|
-
if (type) {
|
34
|
-
query += `&type=${type}`;
|
35
|
-
}
|
36
16
|
const url = `${MSTATE_URL}/env/${query}`;
|
37
17
|
|
38
18
|
const responseJSON = await fetch(url, {
|
@@ -57,21 +37,8 @@ class EnvironmentHandler {
|
|
57
37
|
}
|
58
38
|
|
59
39
|
async saveToDB() {
|
60
|
-
const
|
61
|
-
|
62
|
-
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
40
|
+
const workflowName = getValueFromArgs(Variables.WORKFLOW, true);
|
63
41
|
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
42
|
|
76
43
|
const filePath = path.resolve(workflowName, 'environment.json');
|
77
44
|
|
@@ -89,7 +56,6 @@ class EnvironmentHandler {
|
|
89
56
|
body: JSON.stringify({
|
90
57
|
workflow: workflowName,
|
91
58
|
env: environments,
|
92
|
-
type,
|
93
59
|
}),
|
94
60
|
});
|
95
61
|
|
@@ -1,17 +1,19 @@
|
|
1
|
-
import { CmdAction } from '../common/enum';
|
1
|
+
import { CmdAction, Variables } from '../common/enum';
|
2
2
|
import { customLog } from '../common/utils';
|
3
3
|
|
4
4
|
class HelpHandler {
|
5
5
|
logCommandInfo() {
|
6
|
-
console.log('\n\nUsage: mstate [
|
6
|
+
console.log('\n\nUsage: mstate <command> [arguments] \n');
|
7
7
|
|
8
8
|
console.log('Commands:');
|
9
|
+
customLog.info(CmdAction.LOGIN, 'Login in your terminal using browser');
|
9
10
|
customLog.info(CmdAction.ADD, 'Create a new workflow');
|
10
11
|
customLog.info(
|
11
12
|
CmdAction.CLONE,
|
12
13
|
'Clone workflow with actions and environments',
|
13
14
|
);
|
14
15
|
customLog.info(CmdAction.PUSH, 'Update the changes one in cloned workflow');
|
16
|
+
customLog.info(CmdAction.ADD_USER, 'Add new user to your company');
|
15
17
|
customLog.info(
|
16
18
|
CmdAction.LINK,
|
17
19
|
'Add workflow and allow user to view workflow in the mobioffice application',
|
@@ -27,17 +29,52 @@ class HelpHandler {
|
|
27
29
|
}
|
28
30
|
|
29
31
|
logActionInfo(action: CmdAction) {
|
32
|
+
console.log('Used Arguments: ');
|
33
|
+
|
30
34
|
switch (action) {
|
35
|
+
case CmdAction.LOGIN:
|
36
|
+
break;
|
37
|
+
|
31
38
|
case CmdAction.ADD:
|
39
|
+
case CmdAction.PUSH:
|
40
|
+
case CmdAction.CLONE:
|
41
|
+
customLog.info(
|
42
|
+
Variables.WORKFLOW,
|
43
|
+
'Specifying workflow name with path',
|
44
|
+
);
|
45
|
+
break;
|
46
|
+
|
47
|
+
case CmdAction.LINK:
|
48
|
+
case CmdAction.UNLINK:
|
49
|
+
customLog.info(
|
50
|
+
Variables.WORKFLOW,
|
51
|
+
'Specifying workflow name with path',
|
52
|
+
);
|
53
|
+
customLog.info(Variables.COMPANY_ID, 'Specifying company nickname');
|
54
|
+
customLog.info(Variables.USER_ID, 'Specifying user phone number');
|
55
|
+
break;
|
56
|
+
|
57
|
+
case CmdAction.ADD_USER:
|
58
|
+
customLog.info(
|
59
|
+
Variables.USER_ID,
|
60
|
+
'Specifying user unique name for the company',
|
61
|
+
);
|
62
|
+
customLog.info(Variables.EMAIL, 'Specifying user email');
|
63
|
+
customLog.info(Variables.PHONE, 'Specifying user phone number');
|
32
64
|
break;
|
33
65
|
default:
|
34
66
|
customLog.error(
|
35
|
-
`${action ? 'Invalid' : 'Missing'}
|
67
|
+
`${action ? 'Invalid' : 'Missing'} command: ${action ?? ''}`,
|
36
68
|
);
|
37
69
|
console.log(
|
38
|
-
|
70
|
+
`\t\t use 'mstate ${CmdAction.HELP_FLAG}, ${CmdAction.HELP}' for getting allowed action`,
|
39
71
|
);
|
40
72
|
}
|
73
|
+
|
74
|
+
customLog.info(
|
75
|
+
Variables.SECRET,
|
76
|
+
'Specifying token, If you want to use other token for this command instead of saved one',
|
77
|
+
);
|
41
78
|
}
|
42
79
|
}
|
43
80
|
|
@@ -1,52 +1,18 @@
|
|
1
1
|
import { MOBIOFFICE_URL } from '../common/constant';
|
2
|
-
import { CmdAction } from '../common/enum';
|
2
|
+
import { CmdAction, Variables } from '../common/enum';
|
3
3
|
import { getValueFromArgs } from '../common/helpers';
|
4
4
|
import { customLog, getSecretKey } from '../common/utils';
|
5
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
6
|
class MobiofficeHandler {
|
16
|
-
private MOBIOFFICE_URL: string = MOBIOFFICE_URL;
|
17
|
-
|
18
7
|
constructor() {}
|
19
8
|
|
20
9
|
async linkToMobioffice(action: CmdAction.LINK | CmdAction.UNLINK) {
|
21
|
-
const
|
22
|
-
|
23
|
-
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
10
|
+
const workflowName = getValueFromArgs(Variables.WORKFLOW, true);
|
24
11
|
const secretKey = getSecretKey();
|
25
|
-
const companyName = getValueFromArgs(
|
26
|
-
const user = getValueFromArgs(
|
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
|
-
}
|
12
|
+
const companyName = getValueFromArgs(Variables.COMPANY_ID, true);
|
13
|
+
const user = getValueFromArgs(Variables.USER_ID, true);
|
48
14
|
|
49
|
-
const url = `${
|
15
|
+
const url = `${MOBIOFFICE_URL}/Mstate/workFlow/user`;
|
50
16
|
const responseJSON = await fetch(url, {
|
51
17
|
method: 'POST',
|
52
18
|
headers: {
|
@@ -58,7 +24,6 @@ class MobiofficeHandler {
|
|
58
24
|
workflow: workflowName,
|
59
25
|
secret: secretKey,
|
60
26
|
nickname: companyName,
|
61
|
-
type,
|
62
27
|
user,
|
63
28
|
}),
|
64
29
|
});
|
@@ -3,25 +3,13 @@ import path from 'path';
|
|
3
3
|
import { MSTATE_URL } from '../common/constant';
|
4
4
|
import { customLog, getSecretKey } from '../common/utils';
|
5
5
|
import { getValueFromArgs } from '../common/helpers';
|
6
|
-
|
7
|
-
enum Key {
|
8
|
-
PATH = 'path=',
|
9
|
-
FILE = 'file=',
|
10
|
-
SECRET_KEY = 'secret=',
|
11
|
-
WORKFLOW = 'workflow=',
|
12
|
-
TYPE = 'type=',
|
13
|
-
}
|
6
|
+
import { Variables } from 'src/common/enum';
|
14
7
|
|
15
8
|
class WorkflowHandler {
|
16
9
|
constructor() {}
|
17
10
|
|
18
|
-
async addNewWorkflow() {
|
11
|
+
private async addNewWorkflow(workflowPath: string, file: string) {
|
19
12
|
try {
|
20
|
-
const args = process.argv;
|
21
|
-
|
22
|
-
const workflowPath = getValueFromArgs(args, Key.PATH);
|
23
|
-
const file = getValueFromArgs(args, Key.FILE);
|
24
|
-
const type = getValueFromArgs(args, Key.TYPE);
|
25
13
|
const secretKey = getSecretKey();
|
26
14
|
|
27
15
|
if (!file) {
|
@@ -46,10 +34,6 @@ class WorkflowHandler {
|
|
46
34
|
query = '?' + query;
|
47
35
|
}
|
48
36
|
|
49
|
-
if (type) {
|
50
|
-
query += query ? `&type=${type}` : `?type=${type}`;
|
51
|
-
}
|
52
|
-
|
53
37
|
const url = `${MSTATE_URL}/workflow/config/new${query}`;
|
54
38
|
const responseJSON = await fetch(url, {
|
55
39
|
method: 'POST',
|
@@ -75,22 +59,9 @@ class WorkflowHandler {
|
|
75
59
|
}
|
76
60
|
|
77
61
|
async updateWorkflowToDB() {
|
78
|
-
const
|
79
|
-
|
80
|
-
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
81
|
-
const type = getValueFromArgs(args, Key.TYPE);
|
62
|
+
const workflowName = getValueFromArgs(Variables.WORKFLOW, true);
|
82
63
|
const secretKey = getSecretKey();
|
83
64
|
|
84
|
-
if (!secretKey) {
|
85
|
-
customLog.changeAndThrow(`Parameter secret is required`);
|
86
|
-
return;
|
87
|
-
}
|
88
|
-
|
89
|
-
if (!workflowName) {
|
90
|
-
customLog.changeAndThrow(`Parameter workflow is required`);
|
91
|
-
return;
|
92
|
-
}
|
93
|
-
|
94
65
|
const folderPath = path.resolve(workflowName);
|
95
66
|
const filePath = path.join(folderPath, 'workflow.json');
|
96
67
|
|
@@ -98,10 +69,6 @@ class WorkflowHandler {
|
|
98
69
|
|
99
70
|
let query = `?workflow=${workflowName}`;
|
100
71
|
|
101
|
-
if (type) {
|
102
|
-
query += `&type=${type}`;
|
103
|
-
}
|
104
|
-
|
105
72
|
const url = `${MSTATE_URL}/workflow/config${query}`;
|
106
73
|
const responseJSON = await fetch(url, {
|
107
74
|
method: 'PUT',
|
@@ -126,25 +93,10 @@ class WorkflowHandler {
|
|
126
93
|
}
|
127
94
|
|
128
95
|
async cloneWorkflow() {
|
129
|
-
const
|
130
|
-
|
131
|
-
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
132
|
-
const type = getValueFromArgs(args, Key.TYPE);
|
133
|
-
|
96
|
+
const workflowName = getValueFromArgs(Variables.WORKFLOW, true);
|
134
97
|
const secretKey = getSecretKey();
|
135
98
|
|
136
|
-
|
137
|
-
customLog.changeAndThrow(`Parameter secret is required`);
|
138
|
-
return;
|
139
|
-
}
|
140
|
-
|
141
|
-
if (!workflowName) {
|
142
|
-
customLog.changeAndThrow(`Parameter workflow is required`);
|
143
|
-
return;
|
144
|
-
}
|
145
|
-
const typeQuery = type ? `&type=${type}` : '';
|
146
|
-
|
147
|
-
const url = `${MSTATE_URL}/workflow/config/?workflow=${workflowName}${typeQuery}`;
|
99
|
+
const url = `${MSTATE_URL}/workflow/config/?workflow=${workflowName}`;
|
148
100
|
const responseJSON = await fetch(url, {
|
149
101
|
method: 'GET',
|
150
102
|
headers: {
|
@@ -174,47 +126,28 @@ class WorkflowHandler {
|
|
174
126
|
|
175
127
|
async copyWorkflow() {
|
176
128
|
try {
|
177
|
-
const
|
129
|
+
const workflowName = getValueFromArgs(Variables.WORKFLOW, true);
|
178
130
|
|
179
|
-
|
180
|
-
|
181
|
-
if (!workflowName) {
|
182
|
-
customLog.changeAndThrow(`Parameter workflow is required`);
|
183
|
-
return;
|
184
|
-
}
|
131
|
+
let path = '';
|
132
|
+
let file = '';
|
185
133
|
|
186
134
|
const workflowPath = ('/' + workflowName).replace(/\/([^\/]*)$/, '');
|
187
135
|
if (workflowPath) {
|
188
|
-
|
136
|
+
path = workflowPath.slice(1, workflowPath.length);
|
189
137
|
}
|
190
|
-
|
138
|
+
file = workflowName + '/workflow.json';
|
191
139
|
|
192
|
-
await this.addNewWorkflow();
|
140
|
+
await this.addNewWorkflow(path, file);
|
193
141
|
} catch (error: any) {
|
194
142
|
customLog.changeAndThrow(error.message);
|
195
143
|
}
|
196
144
|
}
|
197
145
|
|
198
146
|
async resetCache() {
|
199
|
-
const
|
200
|
-
const type = getValueFromArgs(args, Key.TYPE);
|
201
|
-
|
202
|
-
const workflowName = getValueFromArgs(args, Key.WORKFLOW);
|
147
|
+
const workflowName = getValueFromArgs(Variables.WORKFLOW, true);
|
203
148
|
const secretKey = getSecretKey();
|
204
149
|
|
205
|
-
|
206
|
-
customLog.changeAndThrow(`Parameter secret is required`);
|
207
|
-
return;
|
208
|
-
}
|
209
|
-
|
210
|
-
if (!workflowName) {
|
211
|
-
customLog.changeAndThrow(`Parameter workflow is required`);
|
212
|
-
return;
|
213
|
-
}
|
214
|
-
|
215
|
-
const typeQuery = type ? `&type=${type}` : '';
|
216
|
-
|
217
|
-
const url = `${MSTATE_URL}/cache/reset/?workflow=${workflowName}${typeQuery}`;
|
150
|
+
const url = `${MSTATE_URL}/cache/reset/?workflow=${workflowName}`;
|
218
151
|
const responseJSON = await fetch(url, {
|
219
152
|
method: 'DELETE',
|
220
153
|
headers: {
|