mstate-cli 0.0.2 → 0.0.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/Readme.md +11 -5
- package/dist/common/constant.js +4 -3
- package/dist/common/enum.js +4 -1
- package/dist/common/utils.js +25 -0
- package/dist/handlers/action.handler.js +148 -0
- package/dist/handlers/environment.handler.js +139 -0
- package/dist/handlers/mobioffice.handler.js +77 -0
- package/dist/{actions/workflow.action.js → handlers/workflow.handler.js} +60 -52
- package/dist/index.js +30 -7
- package/package.json +1 -1
- package/src/common/constant.ts +3 -2
- package/src/common/enum.ts +4 -1
- package/src/common/utils.ts +27 -0
- package/src/handlers/action.handler.ts +126 -0
- package/src/handlers/environment.handler.ts +108 -0
- package/src/handlers/mobioffice.handler.ts +72 -0
- package/src/handlers/workflow.handler.ts +160 -0
- package/src/index.ts +41 -7
- package/src/interface.d.ts +1 -1
- package/dist/actions/publishWorkflow.js +0 -78
- package/src/actions/workflow.action.ts +0 -163
package/Readme.md
CHANGED
@@ -2,20 +2,26 @@
|
|
2
2
|
|
3
3
|
## Commands
|
4
4
|
|
5
|
-
|
5
|
+
### add
|
6
|
+
|
7
|
+
```cmd
|
8
|
+
mstate add secret="secret-key" file="json-file-path" path="path-to-workflow"
|
9
|
+
```
|
10
|
+
|
11
|
+
### clone
|
6
12
|
|
7
13
|
```cmd
|
8
14
|
mstate clone secret="secret-key" workflow="workflow-path__workflow-name"
|
9
15
|
```
|
10
16
|
|
11
|
-
|
17
|
+
### push
|
12
18
|
|
13
19
|
```cmd
|
14
|
-
mstate
|
20
|
+
mstate push secret="secret-key" workflow="workflow-path__workflow-name"
|
15
21
|
```
|
16
22
|
|
17
|
-
|
23
|
+
### link and unlink
|
18
24
|
|
19
25
|
```cmd
|
20
|
-
mstate
|
26
|
+
mstate [link | unlink] secret="secret-key" workflow="workflow-path__workflow-name" user="user-id" company="company-id"
|
21
27
|
```
|
package/dist/common/constant.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.MSTATE_URL = void 0;
|
4
|
-
|
5
|
-
|
3
|
+
exports.MOBIOFFICE_URL = exports.MSTATE_URL = void 0;
|
4
|
+
// export const MSTATE_URL = 'https://dev.mstate.mobioffice.io/api';
|
5
|
+
exports.MSTATE_URL = 'https://api.mstate.mobioffice.io/api';
|
6
|
+
exports.MOBIOFFICE_URL = 'https://server.mobioffice.io/api';
|
package/dist/common/enum.js
CHANGED
@@ -4,7 +4,10 @@ exports.CmdAction = void 0;
|
|
4
4
|
var CmdAction;
|
5
5
|
(function (CmdAction) {
|
6
6
|
CmdAction["LINK"] = "link";
|
7
|
+
CmdAction["UNLINK"] = "unlink";
|
7
8
|
CmdAction["ADD"] = "add";
|
8
9
|
CmdAction["CLONE"] = "clone";
|
9
|
-
CmdAction["
|
10
|
+
CmdAction["PUSH"] = "push";
|
11
|
+
CmdAction["HELP"] = "help";
|
12
|
+
CmdAction["HELP_FLAG"] = "-h";
|
10
13
|
})(CmdAction || (exports.CmdAction = CmdAction = {}));
|
@@ -0,0 +1,25 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.customLog = void 0;
|
4
|
+
exports.getValueFromArgs = getValueFromArgs;
|
5
|
+
function getValueFromArgs(args, key) {
|
6
|
+
var _a, _b;
|
7
|
+
return (_b = (_a = args.find((str) => str.includes(key))) === null || _a === void 0 ? void 0 : _a.replace(key, '')) !== null && _b !== void 0 ? _b : '';
|
8
|
+
}
|
9
|
+
exports.customLog = {
|
10
|
+
error(...message) {
|
11
|
+
const RED_COLOR = '\x1b[31m'; // ANSI code for red
|
12
|
+
const RESET_COLOR = '\x1b[0m'; // ANSI code to reset to default color
|
13
|
+
console.error(`${RED_COLOR}[MSTATE][ERROR] ${RESET_COLOR}`, ...message);
|
14
|
+
},
|
15
|
+
success(...message) {
|
16
|
+
const GREEN_COLOR = '\x1b[32m'; // ANSI code for green
|
17
|
+
const RESET_COLOR = '\x1b[0m'; // ANSI code to reset to default color
|
18
|
+
console.log(`${GREEN_COLOR}[MSTATE] ${RESET_COLOR}`, ...message);
|
19
|
+
},
|
20
|
+
info(key, desc) {
|
21
|
+
const optionPadding = 30; // Define spacing width for the option column
|
22
|
+
const descriptionPadding = 60; // Define spacing width for the description column
|
23
|
+
console.log(' ', key.padEnd(optionPadding) + desc.padEnd(descriptionPadding));
|
24
|
+
},
|
25
|
+
};
|
@@ -0,0 +1,148 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
32
|
+
});
|
33
|
+
};
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
36
|
+
};
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
38
|
+
exports.actionHandler = void 0;
|
39
|
+
const fs = __importStar(require("fs"));
|
40
|
+
const path_1 = __importDefault(require("path"));
|
41
|
+
const constant_1 = require("../common/constant");
|
42
|
+
const utils_1 = require("../common/utils");
|
43
|
+
var Key;
|
44
|
+
(function (Key) {
|
45
|
+
Key["WORKFLOW"] = "workflow=";
|
46
|
+
Key["SECRET_KEY"] = "secret=";
|
47
|
+
})(Key || (Key = {}));
|
48
|
+
class ActionHandler {
|
49
|
+
constructor() { }
|
50
|
+
cloneActions() {
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
52
|
+
try {
|
53
|
+
const args = process.argv;
|
54
|
+
const workflowName = (0, utils_1.getValueFromArgs)(args, Key.WORKFLOW);
|
55
|
+
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
56
|
+
if (!secretKey) {
|
57
|
+
utils_1.customLog.error(`Parameter secret is required`);
|
58
|
+
return;
|
59
|
+
}
|
60
|
+
if (!workflowName) {
|
61
|
+
utils_1.customLog.error(`Parameter workflow is required`);
|
62
|
+
return;
|
63
|
+
}
|
64
|
+
try {
|
65
|
+
const url = `${constant_1.MSTATE_URL}/action/config/all/?workflow=${workflowName}`;
|
66
|
+
const responseJSON = yield fetch(url, {
|
67
|
+
headers: {
|
68
|
+
'Content-Type': 'application/json',
|
69
|
+
'secret-key': secretKey,
|
70
|
+
},
|
71
|
+
});
|
72
|
+
const response = yield responseJSON.json();
|
73
|
+
if (response === null || response === void 0 ? void 0 : response.errors) {
|
74
|
+
utils_1.customLog.error('Invalid Parameters: ', response === null || response === void 0 ? void 0 : response.errors);
|
75
|
+
}
|
76
|
+
else {
|
77
|
+
const actionConfigs = response === null || response === void 0 ? void 0 : response.data;
|
78
|
+
const folderPath = path_1.default.resolve(workflowName, 'actions');
|
79
|
+
fs.mkdirSync(folderPath, { recursive: true });
|
80
|
+
actionConfigs.forEach((config) => {
|
81
|
+
const file = path_1.default.join(folderPath, `${config === null || config === void 0 ? void 0 : config.name}.json`);
|
82
|
+
fs.writeFileSync(file, JSON.stringify(config, null, 2));
|
83
|
+
utils_1.customLog.success('file created at', folderPath, `${config === null || config === void 0 ? void 0 : config.name}.json`);
|
84
|
+
});
|
85
|
+
}
|
86
|
+
}
|
87
|
+
catch (error) {
|
88
|
+
utils_1.customLog.error('Error in cloning action', error.message);
|
89
|
+
}
|
90
|
+
}
|
91
|
+
catch (error) {
|
92
|
+
utils_1.customLog.error('Error in cloning action', error.message);
|
93
|
+
}
|
94
|
+
});
|
95
|
+
}
|
96
|
+
saveToDB() {
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
98
|
+
try {
|
99
|
+
const args = process.argv;
|
100
|
+
const workflowName = (0, utils_1.getValueFromArgs)(args, Key.WORKFLOW);
|
101
|
+
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
102
|
+
if (!secretKey) {
|
103
|
+
utils_1.customLog.error(`Parameter secret is required`);
|
104
|
+
return;
|
105
|
+
}
|
106
|
+
if (!workflowName) {
|
107
|
+
utils_1.customLog.error(`Parameter workflow is required`);
|
108
|
+
return;
|
109
|
+
}
|
110
|
+
const folderPath = path_1.default.resolve(workflowName, 'actions');
|
111
|
+
// loop to every folder to publish workflow
|
112
|
+
fs.readdir(folderPath, (err, files) => {
|
113
|
+
if (!files)
|
114
|
+
return;
|
115
|
+
files.forEach((fileName) => __awaiter(this, void 0, void 0, function* () {
|
116
|
+
try {
|
117
|
+
const filePath = path_1.default.join(folderPath, fileName);
|
118
|
+
const data = fs.readFileSync(filePath, 'utf8');
|
119
|
+
const url = `${constant_1.MSTATE_URL}/action/config/?workflow=${workflowName}`;
|
120
|
+
const responseJSON = yield fetch(url, {
|
121
|
+
method: 'PUT',
|
122
|
+
headers: {
|
123
|
+
'secret-key': secretKey,
|
124
|
+
'Content-Type': 'application/json',
|
125
|
+
},
|
126
|
+
body: data,
|
127
|
+
});
|
128
|
+
const response = yield responseJSON.json();
|
129
|
+
if (response === null || response === void 0 ? void 0 : response.errors) {
|
130
|
+
utils_1.customLog.error(`Invalid Parameters for Action ${fileName}: `, response === null || response === void 0 ? void 0 : response.errors);
|
131
|
+
}
|
132
|
+
else {
|
133
|
+
utils_1.customLog.success(`Action ${fileName} Updated successfully`);
|
134
|
+
}
|
135
|
+
}
|
136
|
+
catch (error) {
|
137
|
+
utils_1.customLog.error(error.message);
|
138
|
+
}
|
139
|
+
}));
|
140
|
+
});
|
141
|
+
}
|
142
|
+
catch (error) {
|
143
|
+
utils_1.customLog.error(error.message);
|
144
|
+
}
|
145
|
+
});
|
146
|
+
}
|
147
|
+
}
|
148
|
+
exports.actionHandler = new ActionHandler();
|
@@ -0,0 +1,139 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
32
|
+
});
|
33
|
+
};
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
36
|
+
};
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
38
|
+
exports.environmentHandler = void 0;
|
39
|
+
const fs = __importStar(require("fs"));
|
40
|
+
const path_1 = __importDefault(require("path"));
|
41
|
+
const constant_1 = require("../common/constant");
|
42
|
+
const utils_1 = require("../common/utils");
|
43
|
+
var Key;
|
44
|
+
(function (Key) {
|
45
|
+
Key["WORKFLOW"] = "workflow=";
|
46
|
+
Key["SECRET_KEY"] = "secret=";
|
47
|
+
})(Key || (Key = {}));
|
48
|
+
class EnvironmentHandler {
|
49
|
+
constructor() { }
|
50
|
+
cloneEnvironments() {
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
52
|
+
try {
|
53
|
+
const args = process.argv;
|
54
|
+
const workflowName = (0, utils_1.getValueFromArgs)(args, Key.WORKFLOW);
|
55
|
+
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
56
|
+
if (!secretKey) {
|
57
|
+
utils_1.customLog.error(`Parameter secret is required`);
|
58
|
+
return;
|
59
|
+
}
|
60
|
+
if (!workflowName) {
|
61
|
+
utils_1.customLog.error(`Parameter workflow is required`);
|
62
|
+
return;
|
63
|
+
}
|
64
|
+
try {
|
65
|
+
const url = `${constant_1.MSTATE_URL}/env/?workflow=${workflowName}`;
|
66
|
+
const responseJSON = yield fetch(url, {
|
67
|
+
headers: {
|
68
|
+
'Content-Type': 'application/json',
|
69
|
+
'secret-key': secretKey,
|
70
|
+
},
|
71
|
+
});
|
72
|
+
const response = yield responseJSON.json();
|
73
|
+
if (response === null || response === void 0 ? void 0 : response.errors) {
|
74
|
+
utils_1.customLog.error('Invalid Parameters: ', response === null || response === void 0 ? void 0 : response.errors);
|
75
|
+
}
|
76
|
+
else {
|
77
|
+
const config = response === null || response === void 0 ? void 0 : response.data;
|
78
|
+
const filePath = path_1.default.resolve(workflowName, 'environment.json');
|
79
|
+
fs.writeFileSync(filePath, JSON.stringify(config, null, 2));
|
80
|
+
}
|
81
|
+
}
|
82
|
+
catch (error) {
|
83
|
+
utils_1.customLog.error('Error in cloning action', error.message);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
catch (error) {
|
87
|
+
utils_1.customLog.error('Error in cloning action', error.message);
|
88
|
+
}
|
89
|
+
});
|
90
|
+
}
|
91
|
+
saveToDB() {
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
93
|
+
try {
|
94
|
+
const args = process.argv;
|
95
|
+
const workflowName = (0, utils_1.getValueFromArgs)(args, Key.WORKFLOW);
|
96
|
+
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
97
|
+
if (!secretKey) {
|
98
|
+
utils_1.customLog.error(`Parameter secret is required`);
|
99
|
+
return;
|
100
|
+
}
|
101
|
+
if (!workflowName) {
|
102
|
+
utils_1.customLog.error(`Parameter workflow is required`);
|
103
|
+
return;
|
104
|
+
}
|
105
|
+
const filePath = path_1.default.resolve(workflowName, 'environment.json');
|
106
|
+
const data = fs.readFileSync(filePath, 'utf8');
|
107
|
+
const environments = JSON.parse(data);
|
108
|
+
try {
|
109
|
+
const url = `${constant_1.MSTATE_URL}/env`;
|
110
|
+
const responseJSON = yield fetch(url, {
|
111
|
+
method: 'POST',
|
112
|
+
headers: {
|
113
|
+
'secret-key': secretKey,
|
114
|
+
'Content-Type': 'application/json',
|
115
|
+
},
|
116
|
+
body: JSON.stringify({
|
117
|
+
workflow: workflowName,
|
118
|
+
env: environments,
|
119
|
+
}),
|
120
|
+
});
|
121
|
+
const response = yield responseJSON.json();
|
122
|
+
if (response === null || response === void 0 ? void 0 : response.errors) {
|
123
|
+
utils_1.customLog.error(`Updating environment:`, response === null || response === void 0 ? void 0 : response.errors);
|
124
|
+
}
|
125
|
+
else {
|
126
|
+
utils_1.customLog.success(`Environments Updated successfully`);
|
127
|
+
}
|
128
|
+
}
|
129
|
+
catch (error) {
|
130
|
+
utils_1.customLog.error(error.message);
|
131
|
+
}
|
132
|
+
}
|
133
|
+
catch (error) {
|
134
|
+
utils_1.customLog.error('Something went wrong');
|
135
|
+
}
|
136
|
+
});
|
137
|
+
}
|
138
|
+
}
|
139
|
+
exports.environmentHandler = new EnvironmentHandler();
|
@@ -0,0 +1,77 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
exports.mobiofficeHandler = void 0;
|
13
|
+
const constant_1 = require("../common/constant");
|
14
|
+
const utils_1 = require("../common/utils");
|
15
|
+
var Key;
|
16
|
+
(function (Key) {
|
17
|
+
Key["WORKFLOW"] = "workflow=";
|
18
|
+
Key["SECRET_KEY"] = "secret=";
|
19
|
+
Key["COMPANY_ID"] = "company=";
|
20
|
+
Key["USER_ID"] = "user=";
|
21
|
+
})(Key || (Key = {}));
|
22
|
+
class MobiofficeHandler {
|
23
|
+
constructor() { }
|
24
|
+
linkToMobioffice(action) {
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
26
|
+
try {
|
27
|
+
const args = process.argv;
|
28
|
+
const workflowPath = (0, utils_1.getValueFromArgs)(args, Key.WORKFLOW);
|
29
|
+
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
30
|
+
const companyID = (0, utils_1.getValueFromArgs)(args, Key.COMPANY_ID);
|
31
|
+
const user = (0, utils_1.getValueFromArgs)(args, Key.USER_ID);
|
32
|
+
if (!workflowPath) {
|
33
|
+
utils_1.customLog.error(`Parameter workflow is required`);
|
34
|
+
return;
|
35
|
+
}
|
36
|
+
if (!secretKey) {
|
37
|
+
utils_1.customLog.error(`Parameter secret is required`);
|
38
|
+
return;
|
39
|
+
}
|
40
|
+
if (!companyID) {
|
41
|
+
utils_1.customLog.error(`Parameter company is required`);
|
42
|
+
return;
|
43
|
+
}
|
44
|
+
if (!user) {
|
45
|
+
utils_1.customLog.error(`Parameter user is required`);
|
46
|
+
return;
|
47
|
+
}
|
48
|
+
const url = `${constant_1.MOBIOFFICE_URL}/Mstate/workFlow/user`;
|
49
|
+
const responseJSON = yield fetch(url, {
|
50
|
+
method: 'POST',
|
51
|
+
headers: {
|
52
|
+
'secret-key': secretKey,
|
53
|
+
'Content-Type': 'application/json',
|
54
|
+
},
|
55
|
+
body: JSON.stringify({
|
56
|
+
action: action.toUpperCase(),
|
57
|
+
workflow: workflowPath,
|
58
|
+
secret: secretKey,
|
59
|
+
companyID,
|
60
|
+
user,
|
61
|
+
}),
|
62
|
+
});
|
63
|
+
const response = yield responseJSON.json();
|
64
|
+
if (responseJSON.status >= 400) {
|
65
|
+
utils_1.customLog.error('Invalid Parameters: ', responseJSON.statusText);
|
66
|
+
}
|
67
|
+
else {
|
68
|
+
utils_1.customLog.success('Workflow Added successfully', response === null || response === void 0 ? void 0 : response.message);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
catch (error) {
|
72
|
+
utils_1.customLog.error(error.message);
|
73
|
+
}
|
74
|
+
});
|
75
|
+
}
|
76
|
+
}
|
77
|
+
exports.mobiofficeHandler = new MobiofficeHandler();
|
@@ -35,138 +35,146 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
36
36
|
};
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
38
|
-
exports.
|
38
|
+
exports.workflowHandler = void 0;
|
39
39
|
const fs = __importStar(require("fs"));
|
40
40
|
const path_1 = __importDefault(require("path"));
|
41
41
|
const constant_1 = require("../common/constant");
|
42
|
+
const utils_1 = require("../common/utils");
|
42
43
|
var Key;
|
43
44
|
(function (Key) {
|
44
|
-
Key["PATH"] = "path";
|
45
|
-
Key["
|
46
|
-
Key["
|
45
|
+
Key["PATH"] = "path=";
|
46
|
+
Key["FILE"] = "file=";
|
47
|
+
Key["SECRET_KEY"] = "secret=";
|
48
|
+
Key["WORKFLOW"] = "workflow=";
|
47
49
|
})(Key || (Key = {}));
|
48
|
-
class
|
50
|
+
class WorkflowHandler {
|
49
51
|
constructor() { }
|
50
|
-
saveToDB(
|
52
|
+
saveToDB() {
|
51
53
|
return __awaiter(this, void 0, void 0, function* () {
|
52
|
-
var _a, _b, _c;
|
53
54
|
try {
|
54
|
-
const
|
55
|
-
|
56
|
-
const
|
55
|
+
const args = process.argv;
|
56
|
+
const workflowPath = (0, utils_1.getValueFromArgs)(args, Key.PATH);
|
57
|
+
const file = (0, utils_1.getValueFromArgs)(args, Key.FILE);
|
58
|
+
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
|
+
if (!file) {
|
62
|
+
utils_1.customLog.error(`Parameter file is required`);
|
63
|
+
return;
|
64
|
+
}
|
65
|
+
if (!secretKey) {
|
66
|
+
utils_1.customLog.error(`Parameter secret is required`);
|
67
|
+
return;
|
68
|
+
}
|
57
69
|
let query = '';
|
58
|
-
if (
|
59
|
-
query += `path=${
|
70
|
+
if (workflowPath) {
|
71
|
+
query += `path=${workflowPath}`;
|
60
72
|
}
|
61
73
|
if (query.length) {
|
62
74
|
query = '?' + query;
|
63
75
|
}
|
64
76
|
const url = `${constant_1.MSTATE_URL}/workflow/config/new${query}`;
|
65
|
-
const filePath = path_1.default.resolve(args[0]);
|
66
|
-
const workflowJSON = fs.readFileSync(filePath, 'utf8');
|
67
77
|
const responseJSON = yield fetch(url, {
|
68
78
|
method: 'POST',
|
69
79
|
headers: {
|
70
80
|
'secret-key': secretKey,
|
71
81
|
'Content-Type': 'application/json',
|
72
82
|
},
|
73
|
-
body:
|
83
|
+
body: workflowJSON,
|
74
84
|
});
|
75
85
|
const response = yield responseJSON.json();
|
76
86
|
if (response === null || response === void 0 ? void 0 : response.errors) {
|
77
|
-
|
87
|
+
utils_1.customLog.error('Invalid Parameters: ', response === null || response === void 0 ? void 0 : response.errors);
|
78
88
|
}
|
79
89
|
else {
|
80
|
-
|
90
|
+
utils_1.customLog.success('Workflow Added successfully', response === null || response === void 0 ? void 0 : response.data);
|
81
91
|
}
|
82
92
|
}
|
83
93
|
catch (error) {
|
84
|
-
|
94
|
+
utils_1.customLog.error(error.message);
|
85
95
|
}
|
86
96
|
});
|
87
97
|
}
|
88
|
-
updateWorkflowToDB(
|
98
|
+
updateWorkflowToDB() {
|
89
99
|
return __awaiter(this, void 0, void 0, function* () {
|
90
|
-
var _a, _b, _c;
|
91
100
|
try {
|
92
|
-
const
|
93
|
-
|
94
|
-
const secretKey = (
|
101
|
+
const args = process.argv;
|
102
|
+
const workflow = (0, utils_1.getValueFromArgs)(args, Key.WORKFLOW);
|
103
|
+
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
95
104
|
if (!secretKey) {
|
96
|
-
|
105
|
+
utils_1.customLog.error(`Parameter secret is required`);
|
97
106
|
return;
|
98
107
|
}
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
}
|
103
|
-
if (query.length) {
|
104
|
-
query = '?' + query;
|
108
|
+
if (!workflow) {
|
109
|
+
utils_1.customLog.error(`Parameter workflow is required`);
|
110
|
+
return;
|
105
111
|
}
|
106
|
-
const
|
107
|
-
const filePath = path_1.default.
|
112
|
+
const folderPath = path_1.default.resolve(workflow);
|
113
|
+
const filePath = path_1.default.join(folderPath, 'workflow.json');
|
108
114
|
const workflowJSON = fs.readFileSync(filePath, 'utf8');
|
115
|
+
let query = `?workflow=${workflow}`;
|
116
|
+
const url = `${constant_1.MSTATE_URL}/workflow/config${query}`;
|
109
117
|
const responseJSON = yield fetch(url, {
|
110
118
|
method: 'PUT',
|
111
119
|
headers: {
|
112
120
|
'secret-key': secretKey,
|
113
121
|
'Content-Type': 'application/json',
|
114
122
|
},
|
115
|
-
body:
|
123
|
+
body: workflowJSON,
|
116
124
|
});
|
117
125
|
const response = yield responseJSON.json();
|
118
126
|
if (response === null || response === void 0 ? void 0 : response.errors) {
|
119
|
-
|
127
|
+
utils_1.customLog.error('Invalid Parameters: ', response === null || response === void 0 ? void 0 : response.errors);
|
120
128
|
}
|
121
129
|
else {
|
122
|
-
|
130
|
+
utils_1.customLog.success('Workflow Uploaded successfully \n', response === null || response === void 0 ? void 0 : response.data);
|
123
131
|
}
|
132
|
+
return response;
|
124
133
|
}
|
125
134
|
catch (error) {
|
126
|
-
|
135
|
+
utils_1.customLog.error(error.message);
|
127
136
|
}
|
128
137
|
});
|
129
138
|
}
|
130
|
-
|
131
|
-
return __awaiter(this, void 0, void 0, function* () { });
|
132
|
-
}
|
133
|
-
cloneWorkflow(args) {
|
139
|
+
cloneWorkflow() {
|
134
140
|
return __awaiter(this, void 0, void 0, function* () {
|
135
|
-
var _a, _b, _c;
|
136
141
|
try {
|
137
|
-
const
|
138
|
-
|
139
|
-
const secretKey = (
|
142
|
+
const args = process.argv;
|
143
|
+
const workflowName = (0, utils_1.getValueFromArgs)(args, Key.WORKFLOW);
|
144
|
+
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
140
145
|
if (!secretKey) {
|
141
|
-
|
146
|
+
utils_1.customLog.error(`Parameter secret is required`);
|
142
147
|
return;
|
143
148
|
}
|
144
149
|
if (!workflowName) {
|
145
|
-
|
150
|
+
utils_1.customLog.error(`Parameter workflow is required`);
|
146
151
|
return;
|
147
152
|
}
|
148
153
|
const url = `${constant_1.MSTATE_URL}/workflow/config/${workflowName}`;
|
149
|
-
console.log({ url });
|
150
154
|
const responseJSON = yield fetch(url, {
|
155
|
+
method: 'GET',
|
151
156
|
headers: {
|
157
|
+
'Content-Type': 'application/json',
|
152
158
|
'secret-key': secretKey,
|
153
159
|
},
|
154
160
|
});
|
155
161
|
const response = yield responseJSON.json();
|
156
162
|
if (response === null || response === void 0 ? void 0 : response.errors) {
|
157
|
-
|
163
|
+
utils_1.customLog.error('Invalid Parameters: ', response === null || response === void 0 ? void 0 : response.errors);
|
158
164
|
}
|
159
165
|
else {
|
160
166
|
const workflowConfig = response === null || response === void 0 ? void 0 : response.data;
|
161
|
-
const
|
167
|
+
const folderPath = path_1.default.resolve(workflowName);
|
168
|
+
fs.mkdirSync(folderPath, { recursive: true });
|
169
|
+
const filePath = path_1.default.join(folderPath, 'workflow.json');
|
162
170
|
fs.writeFileSync(filePath, JSON.stringify(workflowConfig, null, 2));
|
163
|
-
|
171
|
+
utils_1.customLog.success(`Workflow "${workflowName}" is cloned successfully`);
|
164
172
|
}
|
165
173
|
}
|
166
174
|
catch (error) {
|
167
|
-
|
175
|
+
utils_1.customLog.error('Error in cloning workflow', error.message);
|
168
176
|
}
|
169
177
|
});
|
170
178
|
}
|
171
179
|
}
|
172
|
-
exports.
|
180
|
+
exports.workflowHandler = new WorkflowHandler();
|