mstate-cli 0.0.9 → 0.1.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/dist/common/constant.js +2 -2
- package/dist/handlers/action.handler.js +6 -4
- package/dist/handlers/environment.handler.js +6 -4
- package/dist/handlers/mobioffice.handler.js +4 -3
- package/dist/handlers/workflow.handler.js +13 -10
- package/dist/index.js +2 -1
- package/package.json +1 -1
- package/src/common/constant.ts +2 -2
- package/src/handlers/action.handler.ts +6 -5
- package/src/handlers/environment.handler.ts +6 -4
- package/src/handlers/mobioffice.handler.ts +4 -3
- package/src/handlers/workflow.handler.ts +14 -11
- package/src/index.ts +5 -1
package/dist/common/constant.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.MOBIOFFICE_URL = exports.MSTATE_URL = void 0;
|
4
|
-
|
5
|
-
|
4
|
+
exports.MSTATE_URL = 'https://dev.mstate.mobioffice.io/api';
|
5
|
+
// export const MSTATE_URL = 'https://api.mstate.mobioffice.io/api';
|
6
6
|
exports.MOBIOFFICE_URL = 'https://server.mobioffice.io/api';
|
@@ -51,7 +51,8 @@ class ActionHandler {
|
|
51
51
|
return __awaiter(this, void 0, void 0, function* () {
|
52
52
|
try {
|
53
53
|
const args = process.argv;
|
54
|
-
const
|
54
|
+
const dirPath = (0, utils_1.getValueFromArgs)(args, Key.WORKFLOW);
|
55
|
+
const workflowName = dirPath.replace(/\//g, '__');
|
55
56
|
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
56
57
|
if (!secretKey) {
|
57
58
|
utils_1.customLog.error(`Parameter secret is required`);
|
@@ -75,7 +76,7 @@ class ActionHandler {
|
|
75
76
|
}
|
76
77
|
else {
|
77
78
|
const actionConfigs = response === null || response === void 0 ? void 0 : response.data;
|
78
|
-
const folderPath = path_1.default.resolve(
|
79
|
+
const folderPath = path_1.default.resolve(dirPath, 'actions');
|
79
80
|
fs.mkdirSync(folderPath, { recursive: true });
|
80
81
|
actionConfigs.forEach((config) => {
|
81
82
|
const file = path_1.default.join(folderPath, `${config === null || config === void 0 ? void 0 : config.name}.json`);
|
@@ -97,7 +98,8 @@ class ActionHandler {
|
|
97
98
|
return __awaiter(this, void 0, void 0, function* () {
|
98
99
|
try {
|
99
100
|
const args = process.argv;
|
100
|
-
const
|
101
|
+
const dirPath = (0, utils_1.getValueFromArgs)(args, Key.WORKFLOW);
|
102
|
+
const workflowName = dirPath.replace(/\//g, '__');
|
101
103
|
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
102
104
|
if (!secretKey) {
|
103
105
|
utils_1.customLog.error(`Parameter secret is required`);
|
@@ -107,7 +109,7 @@ class ActionHandler {
|
|
107
109
|
utils_1.customLog.error(`Parameter workflow is required`);
|
108
110
|
return;
|
109
111
|
}
|
110
|
-
const folderPath = path_1.default.resolve(
|
112
|
+
const folderPath = path_1.default.resolve(dirPath, 'actions');
|
111
113
|
// loop to every folder to publish workflow
|
112
114
|
fs.readdir(folderPath, (err, files) => {
|
113
115
|
if (!files)
|
@@ -51,7 +51,8 @@ class EnvironmentHandler {
|
|
51
51
|
return __awaiter(this, void 0, void 0, function* () {
|
52
52
|
try {
|
53
53
|
const args = process.argv;
|
54
|
-
const
|
54
|
+
const dirPath = (0, utils_1.getValueFromArgs)(args, Key.WORKFLOW);
|
55
|
+
const workflowName = dirPath.replace(/\//g, '__');
|
55
56
|
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
56
57
|
if (!secretKey) {
|
57
58
|
utils_1.customLog.error(`Parameter secret is required`);
|
@@ -75,7 +76,7 @@ class EnvironmentHandler {
|
|
75
76
|
}
|
76
77
|
else {
|
77
78
|
const config = response === null || response === void 0 ? void 0 : response.data;
|
78
|
-
const filePath = path_1.default.resolve(
|
79
|
+
const filePath = path_1.default.resolve(dirPath, 'environment.json');
|
79
80
|
fs.writeFileSync(filePath, JSON.stringify(config, null, 2));
|
80
81
|
}
|
81
82
|
}
|
@@ -92,7 +93,8 @@ class EnvironmentHandler {
|
|
92
93
|
return __awaiter(this, void 0, void 0, function* () {
|
93
94
|
try {
|
94
95
|
const args = process.argv;
|
95
|
-
const
|
96
|
+
const dirPath = (0, utils_1.getValueFromArgs)(args, Key.WORKFLOW);
|
97
|
+
const workflowName = dirPath.replace(/\//g, '__');
|
96
98
|
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
97
99
|
if (!secretKey) {
|
98
100
|
utils_1.customLog.error(`Parameter secret is required`);
|
@@ -102,7 +104,7 @@ class EnvironmentHandler {
|
|
102
104
|
utils_1.customLog.error(`Parameter workflow is required`);
|
103
105
|
return;
|
104
106
|
}
|
105
|
-
const filePath = path_1.default.resolve(
|
107
|
+
const filePath = path_1.default.resolve(dirPath, 'environment.json');
|
106
108
|
const data = fs.readFileSync(filePath, 'utf8');
|
107
109
|
const environments = JSON.parse(data);
|
108
110
|
try {
|
@@ -25,11 +25,12 @@ class MobiofficeHandler {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
26
26
|
try {
|
27
27
|
const args = process.argv;
|
28
|
-
const
|
28
|
+
const dirPath = (0, utils_1.getValueFromArgs)(args, Key.WORKFLOW);
|
29
|
+
const workflowName = dirPath.replace(/\//g, '__');
|
29
30
|
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
30
31
|
const companyID = (0, utils_1.getValueFromArgs)(args, Key.COMPANY_ID);
|
31
32
|
const user = (0, utils_1.getValueFromArgs)(args, Key.USER_ID);
|
32
|
-
if (!
|
33
|
+
if (!workflowName) {
|
33
34
|
utils_1.customLog.error(`Parameter workflow is required`);
|
34
35
|
return;
|
35
36
|
}
|
@@ -54,7 +55,7 @@ class MobiofficeHandler {
|
|
54
55
|
},
|
55
56
|
body: JSON.stringify({
|
56
57
|
action: action.toUpperCase(),
|
57
|
-
workflow:
|
58
|
+
workflow: workflowName,
|
58
59
|
secret: secretKey,
|
59
60
|
companyID,
|
60
61
|
user,
|
@@ -53,11 +53,10 @@ class WorkflowHandler {
|
|
53
53
|
return __awaiter(this, void 0, void 0, function* () {
|
54
54
|
try {
|
55
55
|
const args = process.argv;
|
56
|
-
const
|
56
|
+
const dirPath = (0, utils_1.getValueFromArgs)(args, Key.PATH);
|
57
|
+
const workflowPath = dirPath.replace(/\//g, '__');
|
57
58
|
const file = (0, utils_1.getValueFromArgs)(args, Key.FILE);
|
58
59
|
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
59
|
-
const filePath = path_1.default.resolve(file);
|
60
|
-
const workflowJSON = fs.readFileSync(filePath, 'utf8');
|
61
60
|
if (!file) {
|
62
61
|
utils_1.customLog.error(`Parameter file is required`);
|
63
62
|
return;
|
@@ -66,6 +65,8 @@ class WorkflowHandler {
|
|
66
65
|
utils_1.customLog.error(`Parameter secret is required`);
|
67
66
|
return;
|
68
67
|
}
|
68
|
+
const filePath = path_1.default.resolve(file);
|
69
|
+
const workflowJSON = fs.readFileSync(filePath, 'utf8');
|
69
70
|
let query = '';
|
70
71
|
if (workflowPath) {
|
71
72
|
query += `path=${workflowPath}`;
|
@@ -99,20 +100,21 @@ class WorkflowHandler {
|
|
99
100
|
return __awaiter(this, void 0, void 0, function* () {
|
100
101
|
try {
|
101
102
|
const args = process.argv;
|
102
|
-
const
|
103
|
+
const dirPath = (0, utils_1.getValueFromArgs)(args, Key.WORKFLOW);
|
104
|
+
const workflowName = dirPath.replace(/\//g, '__');
|
103
105
|
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
104
106
|
if (!secretKey) {
|
105
107
|
utils_1.customLog.error(`Parameter secret is required`);
|
106
108
|
return;
|
107
109
|
}
|
108
|
-
if (!
|
110
|
+
if (!workflowName) {
|
109
111
|
utils_1.customLog.error(`Parameter workflow is required`);
|
110
112
|
return;
|
111
113
|
}
|
112
|
-
const folderPath = path_1.default.resolve(
|
114
|
+
const folderPath = path_1.default.resolve(dirPath);
|
113
115
|
const filePath = path_1.default.join(folderPath, 'workflow.json');
|
114
116
|
const workflowJSON = fs.readFileSync(filePath, 'utf8');
|
115
|
-
let query = `?workflow=${
|
117
|
+
let query = `?workflow=${workflowName}`;
|
116
118
|
const url = `${constant_1.MSTATE_URL}/workflow/config${query}`;
|
117
119
|
const responseJSON = yield fetch(url, {
|
118
120
|
method: 'PUT',
|
@@ -140,7 +142,8 @@ class WorkflowHandler {
|
|
140
142
|
return __awaiter(this, void 0, void 0, function* () {
|
141
143
|
try {
|
142
144
|
const args = process.argv;
|
143
|
-
const
|
145
|
+
const dirPath = (0, utils_1.getValueFromArgs)(args, Key.WORKFLOW);
|
146
|
+
const workflowName = dirPath.replace(/\//g, '__');
|
144
147
|
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
145
148
|
if (!secretKey) {
|
146
149
|
utils_1.customLog.error(`Parameter secret is required`);
|
@@ -164,11 +167,11 @@ class WorkflowHandler {
|
|
164
167
|
}
|
165
168
|
else {
|
166
169
|
const workflowConfig = response === null || response === void 0 ? void 0 : response.data;
|
167
|
-
const folderPath = path_1.default.resolve(
|
170
|
+
const folderPath = path_1.default.resolve(dirPath);
|
168
171
|
fs.mkdirSync(folderPath, { recursive: true });
|
169
172
|
const filePath = path_1.default.join(folderPath, 'workflow.json');
|
170
173
|
fs.writeFileSync(filePath, JSON.stringify(workflowConfig, null, 2));
|
171
|
-
utils_1.customLog.success(`Workflow
|
174
|
+
utils_1.customLog.success(`Workflow cloned successfully`);
|
172
175
|
}
|
173
176
|
}
|
174
177
|
catch (error) {
|
package/dist/index.js
CHANGED
@@ -39,6 +39,7 @@ switch (action) {
|
|
39
39
|
utils_1.customLog.info(enum_1.CmdAction.UNLINK, 'add workflow and remove user to view workflow to mobioffice application');
|
40
40
|
break;
|
41
41
|
default:
|
42
|
-
utils_1.customLog.error(
|
42
|
+
utils_1.customLog.error(`${action ? 'Invalid' : 'Missing'} script: "${action !== null && action !== void 0 ? action : ''}"`);
|
43
43
|
console.log('use `mstate help, -h` for getting allowed action');
|
44
44
|
}
|
45
|
+
console.log('\n');
|
package/package.json
CHANGED
package/src/common/constant.ts
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
export const MSTATE_URL = 'https://api.mstate.mobioffice.io/api';
|
1
|
+
export const MSTATE_URL = 'https://dev.mstate.mobioffice.io/api';
|
2
|
+
// export const MSTATE_URL = 'https://api.mstate.mobioffice.io/api';
|
3
3
|
export const MOBIOFFICE_URL = 'https://server.mobioffice.io/api';
|
@@ -14,7 +14,8 @@ class ActionHandler {
|
|
14
14
|
async cloneActions() {
|
15
15
|
try {
|
16
16
|
const args = process.argv;
|
17
|
-
const
|
17
|
+
const dirPath = getValueFromArgs(args, Key.WORKFLOW);
|
18
|
+
const workflowName = dirPath.replace(/\//g, '__');
|
18
19
|
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
19
20
|
|
20
21
|
if (!secretKey) {
|
@@ -43,7 +44,7 @@ class ActionHandler {
|
|
43
44
|
} else {
|
44
45
|
const actionConfigs = response?.data;
|
45
46
|
|
46
|
-
const folderPath = path.resolve(
|
47
|
+
const folderPath = path.resolve(dirPath, 'actions');
|
47
48
|
fs.mkdirSync(folderPath, { recursive: true });
|
48
49
|
|
49
50
|
actionConfigs.forEach((config: ActionConfig) => {
|
@@ -68,8 +69,8 @@ class ActionHandler {
|
|
68
69
|
async saveToDB() {
|
69
70
|
try {
|
70
71
|
const args = process.argv;
|
71
|
-
|
72
|
-
const workflowName =
|
72
|
+
const dirPath = getValueFromArgs(args, Key.WORKFLOW);
|
73
|
+
const workflowName = dirPath.replace(/\//g, '__');
|
73
74
|
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
74
75
|
|
75
76
|
if (!secretKey) {
|
@@ -82,7 +83,7 @@ class ActionHandler {
|
|
82
83
|
return;
|
83
84
|
}
|
84
85
|
|
85
|
-
const folderPath = path.resolve(
|
86
|
+
const folderPath = path.resolve(dirPath, 'actions');
|
86
87
|
|
87
88
|
// loop to every folder to publish workflow
|
88
89
|
fs.readdir(folderPath, (err, files) => {
|
@@ -14,7 +14,8 @@ class EnvironmentHandler {
|
|
14
14
|
async cloneEnvironments() {
|
15
15
|
try {
|
16
16
|
const args = process.argv;
|
17
|
-
const
|
17
|
+
const dirPath = getValueFromArgs(args, Key.WORKFLOW);
|
18
|
+
const workflowName = dirPath.replace(/\//g, '__');
|
18
19
|
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
19
20
|
|
20
21
|
if (!secretKey) {
|
@@ -43,7 +44,7 @@ class EnvironmentHandler {
|
|
43
44
|
} else {
|
44
45
|
const config = response?.data;
|
45
46
|
|
46
|
-
const filePath = path.resolve(
|
47
|
+
const filePath = path.resolve(dirPath, 'environment.json');
|
47
48
|
fs.writeFileSync(filePath, JSON.stringify(config, null, 2));
|
48
49
|
}
|
49
50
|
} catch (error: any) {
|
@@ -58,7 +59,8 @@ class EnvironmentHandler {
|
|
58
59
|
try {
|
59
60
|
const args = process.argv;
|
60
61
|
|
61
|
-
const
|
62
|
+
const dirPath = getValueFromArgs(args, Key.WORKFLOW);
|
63
|
+
const workflowName = dirPath.replace(/\//g, '__');
|
62
64
|
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
63
65
|
|
64
66
|
if (!secretKey) {
|
@@ -71,7 +73,7 @@ class EnvironmentHandler {
|
|
71
73
|
return;
|
72
74
|
}
|
73
75
|
|
74
|
-
const filePath = path.resolve(
|
76
|
+
const filePath = path.resolve(dirPath, 'environment.json');
|
75
77
|
|
76
78
|
const data = fs.readFileSync(filePath, 'utf8');
|
77
79
|
const environments = JSON.parse(data);
|
@@ -16,12 +16,13 @@ class MobiofficeHandler {
|
|
16
16
|
try {
|
17
17
|
const args = process.argv;
|
18
18
|
|
19
|
-
const
|
19
|
+
const dirPath = getValueFromArgs(args, Key.WORKFLOW);
|
20
|
+
const workflowName = dirPath.replace(/\//g, '__');
|
20
21
|
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
21
22
|
const companyID = getValueFromArgs(args, Key.COMPANY_ID);
|
22
23
|
const user = getValueFromArgs(args, Key.USER_ID);
|
23
24
|
|
24
|
-
if (!
|
25
|
+
if (!workflowName) {
|
25
26
|
customLog.error(`Parameter workflow is required`);
|
26
27
|
return;
|
27
28
|
}
|
@@ -50,7 +51,7 @@ class MobiofficeHandler {
|
|
50
51
|
},
|
51
52
|
body: JSON.stringify({
|
52
53
|
action: action.toUpperCase(),
|
53
|
-
workflow:
|
54
|
+
workflow: workflowName,
|
54
55
|
secret: secretKey,
|
55
56
|
companyID,
|
56
57
|
user,
|
@@ -17,13 +17,11 @@ class WorkflowHandler {
|
|
17
17
|
try {
|
18
18
|
const args = process.argv;
|
19
19
|
|
20
|
-
const
|
20
|
+
const dirPath = getValueFromArgs(args, Key.PATH);
|
21
|
+
const workflowPath = dirPath.replace(/\//g, '__');
|
21
22
|
const file = getValueFromArgs(args, Key.FILE);
|
22
23
|
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
23
24
|
|
24
|
-
const filePath = path.resolve(file);
|
25
|
-
const workflowJSON = fs.readFileSync(filePath, 'utf8');
|
26
|
-
|
27
25
|
if (!file) {
|
28
26
|
customLog.error(`Parameter file is required`);
|
29
27
|
return;
|
@@ -34,6 +32,9 @@ class WorkflowHandler {
|
|
34
32
|
return;
|
35
33
|
}
|
36
34
|
|
35
|
+
const filePath = path.resolve(file);
|
36
|
+
const workflowJSON = fs.readFileSync(filePath, 'utf8');
|
37
|
+
|
37
38
|
let query = '';
|
38
39
|
if (workflowPath) {
|
39
40
|
query += `path=${workflowPath}`;
|
@@ -68,7 +69,8 @@ class WorkflowHandler {
|
|
68
69
|
try {
|
69
70
|
const args = process.argv;
|
70
71
|
|
71
|
-
const
|
72
|
+
const dirPath = getValueFromArgs(args, Key.WORKFLOW);
|
73
|
+
const workflowName = dirPath.replace(/\//g, '__');
|
72
74
|
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
73
75
|
|
74
76
|
if (!secretKey) {
|
@@ -76,17 +78,17 @@ class WorkflowHandler {
|
|
76
78
|
return;
|
77
79
|
}
|
78
80
|
|
79
|
-
if (!
|
81
|
+
if (!workflowName) {
|
80
82
|
customLog.error(`Parameter workflow is required`);
|
81
83
|
return;
|
82
84
|
}
|
83
85
|
|
84
|
-
const folderPath = path.resolve(
|
86
|
+
const folderPath = path.resolve(dirPath);
|
85
87
|
const filePath = path.join(folderPath, 'workflow.json');
|
86
88
|
|
87
89
|
const workflowJSON = fs.readFileSync(filePath, 'utf8');
|
88
90
|
|
89
|
-
let query = `?workflow=${
|
91
|
+
let query = `?workflow=${workflowName}`;
|
90
92
|
|
91
93
|
const url = `${MSTATE_URL}/workflow/config${query}`;
|
92
94
|
const responseJSON = await fetch(url, {
|
@@ -115,7 +117,8 @@ class WorkflowHandler {
|
|
115
117
|
try {
|
116
118
|
const args = process.argv;
|
117
119
|
|
118
|
-
const
|
120
|
+
const dirPath = getValueFromArgs(args, Key.WORKFLOW);
|
121
|
+
const workflowName = dirPath.replace(/\//g, '__');
|
119
122
|
const secretKey = getValueFromArgs(args, Key.SECRET_KEY);
|
120
123
|
|
121
124
|
if (!secretKey) {
|
@@ -143,13 +146,13 @@ class WorkflowHandler {
|
|
143
146
|
} else {
|
144
147
|
const workflowConfig = response?.data;
|
145
148
|
|
146
|
-
const folderPath = path.resolve(
|
149
|
+
const folderPath = path.resolve(dirPath);
|
147
150
|
fs.mkdirSync(folderPath, { recursive: true });
|
148
151
|
|
149
152
|
const filePath = path.join(folderPath, 'workflow.json');
|
150
153
|
fs.writeFileSync(filePath, JSON.stringify(workflowConfig, null, 2));
|
151
154
|
|
152
|
-
customLog.success(`Workflow
|
155
|
+
customLog.success(`Workflow cloned successfully`);
|
153
156
|
}
|
154
157
|
} catch (error: any) {
|
155
158
|
customLog.error('Error in cloning workflow', error.message);
|
package/src/index.ts
CHANGED
@@ -52,6 +52,10 @@ switch (action as CmdAction) {
|
|
52
52
|
);
|
53
53
|
break;
|
54
54
|
default:
|
55
|
-
customLog.error(
|
55
|
+
customLog.error(
|
56
|
+
`${action ? 'Invalid' : 'Missing'} script: "${action ?? ''}"`,
|
57
|
+
);
|
56
58
|
console.log('use `mstate help, -h` for getting allowed action');
|
57
59
|
}
|
60
|
+
|
61
|
+
console.log('\n');
|