mstate-cli 0.0.1 → 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 +16 -4
- package/dist/common/constant.js +4 -3
- package/dist/common/enum.js +5 -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/handlers/workflow.handler.js +180 -0
- package/dist/index.js +32 -6
- package/package.json +1 -1
- package/src/common/constant.ts +3 -2
- package/src/common/enum.ts +5 -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 +43 -6
- package/src/interface.d.ts +1 -1
- package/dist/actions/publishWorkflow.js +0 -78
- package/dist/actions/workflow.action.js +0 -133
- package/src/actions/workflow.action.ts +0 -116
package/Readme.md
CHANGED
@@ -2,14 +2,26 @@
|
|
2
2
|
|
3
3
|
## Commands
|
4
4
|
|
5
|
-
|
5
|
+
### add
|
6
6
|
|
7
7
|
```cmd
|
8
|
-
mstate add
|
8
|
+
mstate add secret="secret-key" file="json-file-path" path="path-to-workflow"
|
9
9
|
```
|
10
10
|
|
11
|
-
|
11
|
+
### clone
|
12
12
|
|
13
13
|
```cmd
|
14
|
-
mstate
|
14
|
+
mstate clone secret="secret-key" workflow="workflow-path__workflow-name"
|
15
|
+
```
|
16
|
+
|
17
|
+
### push
|
18
|
+
|
19
|
+
```cmd
|
20
|
+
mstate push secret="secret-key" workflow="workflow-path__workflow-name"
|
21
|
+
```
|
22
|
+
|
23
|
+
### link and unlink
|
24
|
+
|
25
|
+
```cmd
|
26
|
+
mstate [link | unlink] secret="secret-key" workflow="workflow-path__workflow-name" user="user-id" company="company-id"
|
15
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,6 +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
|
-
CmdAction["
|
9
|
+
CmdAction["CLONE"] = "clone";
|
10
|
+
CmdAction["PUSH"] = "push";
|
11
|
+
CmdAction["HELP"] = "help";
|
12
|
+
CmdAction["HELP_FLAG"] = "-h";
|
9
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();
|
@@ -0,0 +1,180 @@
|
|
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.workflowHandler = 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["PATH"] = "path=";
|
46
|
+
Key["FILE"] = "file=";
|
47
|
+
Key["SECRET_KEY"] = "secret=";
|
48
|
+
Key["WORKFLOW"] = "workflow=";
|
49
|
+
})(Key || (Key = {}));
|
50
|
+
class WorkflowHandler {
|
51
|
+
constructor() { }
|
52
|
+
saveToDB() {
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
54
|
+
try {
|
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
|
+
}
|
69
|
+
let query = '';
|
70
|
+
if (workflowPath) {
|
71
|
+
query += `path=${workflowPath}`;
|
72
|
+
}
|
73
|
+
if (query.length) {
|
74
|
+
query = '?' + query;
|
75
|
+
}
|
76
|
+
const url = `${constant_1.MSTATE_URL}/workflow/config/new${query}`;
|
77
|
+
const responseJSON = yield fetch(url, {
|
78
|
+
method: 'POST',
|
79
|
+
headers: {
|
80
|
+
'secret-key': secretKey,
|
81
|
+
'Content-Type': 'application/json',
|
82
|
+
},
|
83
|
+
body: workflowJSON,
|
84
|
+
});
|
85
|
+
const response = yield responseJSON.json();
|
86
|
+
if (response === null || response === void 0 ? void 0 : response.errors) {
|
87
|
+
utils_1.customLog.error('Invalid Parameters: ', response === null || response === void 0 ? void 0 : response.errors);
|
88
|
+
}
|
89
|
+
else {
|
90
|
+
utils_1.customLog.success('Workflow Added successfully', response === null || response === void 0 ? void 0 : response.data);
|
91
|
+
}
|
92
|
+
}
|
93
|
+
catch (error) {
|
94
|
+
utils_1.customLog.error(error.message);
|
95
|
+
}
|
96
|
+
});
|
97
|
+
}
|
98
|
+
updateWorkflowToDB() {
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
100
|
+
try {
|
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);
|
104
|
+
if (!secretKey) {
|
105
|
+
utils_1.customLog.error(`Parameter secret is required`);
|
106
|
+
return;
|
107
|
+
}
|
108
|
+
if (!workflow) {
|
109
|
+
utils_1.customLog.error(`Parameter workflow is required`);
|
110
|
+
return;
|
111
|
+
}
|
112
|
+
const folderPath = path_1.default.resolve(workflow);
|
113
|
+
const filePath = path_1.default.join(folderPath, 'workflow.json');
|
114
|
+
const workflowJSON = fs.readFileSync(filePath, 'utf8');
|
115
|
+
let query = `?workflow=${workflow}`;
|
116
|
+
const url = `${constant_1.MSTATE_URL}/workflow/config${query}`;
|
117
|
+
const responseJSON = yield fetch(url, {
|
118
|
+
method: 'PUT',
|
119
|
+
headers: {
|
120
|
+
'secret-key': secretKey,
|
121
|
+
'Content-Type': 'application/json',
|
122
|
+
},
|
123
|
+
body: workflowJSON,
|
124
|
+
});
|
125
|
+
const response = yield responseJSON.json();
|
126
|
+
if (response === null || response === void 0 ? void 0 : response.errors) {
|
127
|
+
utils_1.customLog.error('Invalid Parameters: ', response === null || response === void 0 ? void 0 : response.errors);
|
128
|
+
}
|
129
|
+
else {
|
130
|
+
utils_1.customLog.success('Workflow Uploaded successfully \n', response === null || response === void 0 ? void 0 : response.data);
|
131
|
+
}
|
132
|
+
return response;
|
133
|
+
}
|
134
|
+
catch (error) {
|
135
|
+
utils_1.customLog.error(error.message);
|
136
|
+
}
|
137
|
+
});
|
138
|
+
}
|
139
|
+
cloneWorkflow() {
|
140
|
+
return __awaiter(this, void 0, void 0, function* () {
|
141
|
+
try {
|
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);
|
145
|
+
if (!secretKey) {
|
146
|
+
utils_1.customLog.error(`Parameter secret is required`);
|
147
|
+
return;
|
148
|
+
}
|
149
|
+
if (!workflowName) {
|
150
|
+
utils_1.customLog.error(`Parameter workflow is required`);
|
151
|
+
return;
|
152
|
+
}
|
153
|
+
const url = `${constant_1.MSTATE_URL}/workflow/config/${workflowName}`;
|
154
|
+
const responseJSON = yield fetch(url, {
|
155
|
+
method: 'GET',
|
156
|
+
headers: {
|
157
|
+
'Content-Type': 'application/json',
|
158
|
+
'secret-key': secretKey,
|
159
|
+
},
|
160
|
+
});
|
161
|
+
const response = yield responseJSON.json();
|
162
|
+
if (response === null || response === void 0 ? void 0 : response.errors) {
|
163
|
+
utils_1.customLog.error('Invalid Parameters: ', response === null || response === void 0 ? void 0 : response.errors);
|
164
|
+
}
|
165
|
+
else {
|
166
|
+
const workflowConfig = response === null || response === void 0 ? void 0 : response.data;
|
167
|
+
const folderPath = path_1.default.resolve(workflowName);
|
168
|
+
fs.mkdirSync(folderPath, { recursive: true });
|
169
|
+
const filePath = path_1.default.join(folderPath, 'workflow.json');
|
170
|
+
fs.writeFileSync(filePath, JSON.stringify(workflowConfig, null, 2));
|
171
|
+
utils_1.customLog.success(`Workflow "${workflowName}" is cloned successfully`);
|
172
|
+
}
|
173
|
+
}
|
174
|
+
catch (error) {
|
175
|
+
utils_1.customLog.error('Error in cloning workflow', error.message);
|
176
|
+
}
|
177
|
+
});
|
178
|
+
}
|
179
|
+
}
|
180
|
+
exports.workflowHandler = new WorkflowHandler();
|