mstate-cli 0.3.0 → 0.4.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mstate-cli",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
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",
@@ -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';
@@ -5,7 +5,7 @@ export enum CmdAction {
5
5
  DEV = 'dev',
6
6
  UNLINK = 'unlink',
7
7
  PERMISSION = 'permission',
8
- USER = 'user',
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
+ }
@@ -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
- export function getValueFromArgs(args: string[], key: string) {
6
- return args.find((str) => str.includes(key))?.replace(key, '') ?? '';
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(args: string[], flag: string) {
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
 
@@ -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(process.argv, 'secret=') ||
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(process.argv, 'secret=');
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 args = process.argv;
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 args = process.argv;
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 args = process.argv;
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(args, Key.USER_ID);
33
- const companyID = getValueFromArgs(args, Key.COMPANY_ID);
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(args, Key.NAME);
85
- const email = getValueFromArgs(args, Key.EMAIL);
86
- const phone = getValueFromArgs(args, Key.PHONE);
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 args = process.argv;
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(args, Key.USER_ID);
142
- const companyID = getValueFromArgs(args, Key.COMPANY_ID);
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 args = process.argv;
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 args = process.argv;
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,9 +1,9 @@
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 [cmd] [parameter]="[value]"\n');
6
+ console.log('\n\nUsage: mstate <command> [arguments] \n');
7
7
 
8
8
  console.log('Commands:');
9
9
  customLog.info(CmdAction.ADD, 'Create a new workflow');
@@ -12,6 +12,7 @@ class HelpHandler {
12
12
  'Clone workflow with actions and environments',
13
13
  );
14
14
  customLog.info(CmdAction.PUSH, 'Update the changes one in cloned workflow');
15
+ customLog.info(CmdAction.ADD_USER, 'Add new user to your company');
15
16
  customLog.info(
16
17
  CmdAction.LINK,
17
18
  'Add workflow and allow user to view workflow in the mobioffice application',
@@ -27,15 +28,50 @@ class HelpHandler {
27
28
  }
28
29
 
29
30
  logActionInfo(action: CmdAction) {
31
+ console.log('Used Arguments: ');
32
+
30
33
  switch (action) {
31
34
  case CmdAction.ADD:
35
+ customLog.info(
36
+ Variables.WORKFLOW,
37
+ 'Specifying workflow name with path',
38
+ );
39
+ break;
40
+ case CmdAction.CLONE:
41
+ customLog.info(
42
+ Variables.WORKFLOW,
43
+ 'Specifying workflow name with path',
44
+ );
45
+ break;
46
+ case CmdAction.LINK:
47
+ case CmdAction.UNLINK:
48
+ customLog.info(
49
+ Variables.WORKFLOW,
50
+ 'Specifying workflow name with path',
51
+ );
52
+ customLog.info(Variables.COMPANY_ID, 'Specifying company nickname');
53
+ customLog.info(Variables.USER_ID, 'Specifying user phone number');
54
+ break;
55
+ case CmdAction.PUSH:
56
+ customLog.info(
57
+ Variables.WORKFLOW,
58
+ 'Specifying workflow name with path',
59
+ );
60
+ break;
61
+ case CmdAction.ADD_USER:
62
+ customLog.info(
63
+ Variables.USER_ID,
64
+ 'Specifying user unique name for the company',
65
+ );
66
+ customLog.info(Variables.EMAIL, 'Specifying user email');
67
+ customLog.info(Variables.PHONE, 'Specifying user phone number');
32
68
  break;
33
69
  default:
34
70
  customLog.error(
35
- `${action ? 'Invalid' : 'Missing'} script: ${action ?? ''}`,
71
+ `${action ? 'Invalid' : 'Missing'} command: ${action ?? ''}`,
36
72
  );
37
73
  console.log(
38
- `use 'mstate ${CmdAction.HELP_FLAG}, ${CmdAction.HELP}' for getting allowed action`,
74
+ `\t\t use 'mstate ${CmdAction.HELP_FLAG}, ${CmdAction.HELP}' for getting allowed action`,
39
75
  );
40
76
  }
41
77
  }
@@ -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 args = process.argv;
22
-
23
- const workflowName = getValueFromArgs(args, Key.WORKFLOW);
10
+ const workflowName = getValueFromArgs(Variables.WORKFLOW, true);
24
11
  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
- }
12
+ const companyName = getValueFromArgs(Variables.COMPANY_ID, true);
13
+ const user = getValueFromArgs(Variables.USER_ID, true);
48
14
 
49
- const url = `${this.MOBIOFFICE_URL}/Mstate/workFlow/user`;
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 args = process.argv;
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 args = process.argv;
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
- if (!secretKey) {
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 args = process.argv;
129
+ const workflowName = getValueFromArgs(Variables.WORKFLOW, true);
178
130
 
179
- const workflowName = getValueFromArgs(args, Key.WORKFLOW);
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
- process.argv.push(`path=${workflowPath.slice(1, workflowPath.length)}`);
136
+ path = workflowPath.slice(1, workflowPath.length);
189
137
  }
190
- process.argv.push(`file=${workflowName + '/workflow.json'}`);
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 args = process.argv;
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
- if (!secretKey) {
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: {