mstate-cli 0.1.7 → 0.1.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/dist/index.js +297 -73
- package/package.json +16 -3
- package/rollup.config.js +23 -0
- package/src/common/constant.ts +15 -4
- package/src/common/enum.ts +1 -0
- package/src/common/helpers.ts +25 -0
- package/src/common/utils.ts +38 -5
- package/src/handlers/action.handler.ts +8 -9
- package/src/handlers/company.handler.ts +85 -4
- package/src/handlers/environment.handler.ts +8 -9
- package/src/handlers/help.handler.ts +14 -4
- package/src/handlers/mobioffice.handler.ts +7 -6
- package/src/handlers/workflow.handler.ts +14 -17
- package/src/index.ts +17 -10
- package/tsconfig.json +10 -8
- package/dist/common/constant.js +0 -7
- package/dist/common/enum.js +0 -16
- package/dist/common/utils.js +0 -32
- package/dist/handlers/action.handler.js +0 -136
- package/dist/handlers/company.handler.js +0 -104
- package/dist/handlers/environment.handler.js +0 -126
- package/dist/handlers/help.handler.js +0 -21
- package/dist/handlers/mobioffice.handler.js +0 -74
- package/dist/handlers/workflow.handler.js +0 -204
@@ -1,204 +0,0 @@
|
|
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 dirPath = (0, utils_1.getValueFromArgs)(args, Key.PATH);
|
57
|
-
const workflowPath = dirPath.replace(/\//g, '__');
|
58
|
-
const file = (0, utils_1.getValueFromArgs)(args, Key.FILE);
|
59
|
-
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
60
|
-
if (!file) {
|
61
|
-
utils_1.customLog.changeAndThrow(`Parameter file is required`);
|
62
|
-
return;
|
63
|
-
}
|
64
|
-
if (!secretKey) {
|
65
|
-
utils_1.customLog.changeAndThrow(`Parameter secret is required`);
|
66
|
-
return;
|
67
|
-
}
|
68
|
-
const filePath = path_1.default.resolve(file);
|
69
|
-
const workflowJSON = fs.readFileSync(filePath, 'utf8');
|
70
|
-
let query = '';
|
71
|
-
if (workflowPath) {
|
72
|
-
query += `path=${workflowPath}`;
|
73
|
-
}
|
74
|
-
if (query.length) {
|
75
|
-
query = '?' + query;
|
76
|
-
}
|
77
|
-
const url = `${constant_1.MSTATE_URL}/workflow/config/new${query}`;
|
78
|
-
const responseJSON = yield fetch(url, {
|
79
|
-
method: 'POST',
|
80
|
-
headers: {
|
81
|
-
'secret-key': secretKey,
|
82
|
-
'Content-Type': 'application/json',
|
83
|
-
},
|
84
|
-
body: workflowJSON,
|
85
|
-
});
|
86
|
-
const response = yield responseJSON.json();
|
87
|
-
if (response === null || response === void 0 ? void 0 : response.errors) {
|
88
|
-
utils_1.customLog.changeAndThrow('Invalid Parameters for Workflow: ', ...response === null || response === void 0 ? void 0 : response.errors);
|
89
|
-
}
|
90
|
-
else {
|
91
|
-
utils_1.customLog.success('Workflow Added successfully', response === null || response === void 0 ? void 0 : response.data);
|
92
|
-
}
|
93
|
-
}
|
94
|
-
catch (error) {
|
95
|
-
utils_1.customLog.changeAndThrow(error.message);
|
96
|
-
}
|
97
|
-
});
|
98
|
-
}
|
99
|
-
updateWorkflowToDB() {
|
100
|
-
return __awaiter(this, void 0, void 0, function* () {
|
101
|
-
const args = process.argv;
|
102
|
-
const dirPath = (0, utils_1.getValueFromArgs)(args, Key.WORKFLOW);
|
103
|
-
const workflowName = dirPath.replace(/\//g, '__');
|
104
|
-
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
105
|
-
if (!secretKey) {
|
106
|
-
utils_1.customLog.changeAndThrow(`Parameter secret is required`);
|
107
|
-
return;
|
108
|
-
}
|
109
|
-
if (!workflowName) {
|
110
|
-
utils_1.customLog.changeAndThrow(`Parameter workflow is required`);
|
111
|
-
return;
|
112
|
-
}
|
113
|
-
const folderPath = path_1.default.resolve(dirPath);
|
114
|
-
const filePath = path_1.default.join(folderPath, 'workflow.json');
|
115
|
-
const workflowJSON = fs.readFileSync(filePath, 'utf8');
|
116
|
-
let query = `?workflow=${workflowName}`;
|
117
|
-
const url = `${constant_1.MSTATE_URL}/workflow/config${query}`;
|
118
|
-
const responseJSON = yield fetch(url, {
|
119
|
-
method: 'PUT',
|
120
|
-
headers: {
|
121
|
-
'secret-key': secretKey,
|
122
|
-
'Content-Type': 'application/json',
|
123
|
-
},
|
124
|
-
body: workflowJSON,
|
125
|
-
});
|
126
|
-
const response = yield responseJSON.json();
|
127
|
-
if (response === null || response === void 0 ? void 0 : response.errors) {
|
128
|
-
utils_1.customLog.changeAndThrow('Invalid Parameters for Server: ', ...response === null || response === void 0 ? void 0 : response.errors);
|
129
|
-
}
|
130
|
-
else {
|
131
|
-
utils_1.customLog.success('Workflow Uploaded successfully \n', response === null || response === void 0 ? void 0 : response.data);
|
132
|
-
}
|
133
|
-
return response;
|
134
|
-
});
|
135
|
-
}
|
136
|
-
cloneWorkflow() {
|
137
|
-
return __awaiter(this, void 0, void 0, function* () {
|
138
|
-
const args = process.argv;
|
139
|
-
const dirPath = (0, utils_1.getValueFromArgs)(args, Key.WORKFLOW);
|
140
|
-
const workflowName = dirPath.replace(/\//g, '__');
|
141
|
-
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
142
|
-
if (!secretKey) {
|
143
|
-
utils_1.customLog.changeAndThrow(`Parameter secret is required`);
|
144
|
-
return;
|
145
|
-
}
|
146
|
-
if (!workflowName) {
|
147
|
-
utils_1.customLog.changeAndThrow(`Parameter workflow is required`);
|
148
|
-
return;
|
149
|
-
}
|
150
|
-
const url = `${constant_1.MSTATE_URL}/workflow/config/${workflowName}`;
|
151
|
-
const responseJSON = yield fetch(url, {
|
152
|
-
method: 'GET',
|
153
|
-
headers: {
|
154
|
-
'Content-Type': 'application/json',
|
155
|
-
'secret-key': secretKey,
|
156
|
-
},
|
157
|
-
});
|
158
|
-
const response = yield responseJSON.json();
|
159
|
-
if (response === null || response === void 0 ? void 0 : response.errors) {
|
160
|
-
utils_1.customLog.changeAndThrow('Invalid Parameters for Workflow: ', ...response === null || response === void 0 ? void 0 : response.errors);
|
161
|
-
}
|
162
|
-
else {
|
163
|
-
const workflowConfig = response === null || response === void 0 ? void 0 : response.data;
|
164
|
-
const folderPath = path_1.default.resolve(dirPath);
|
165
|
-
fs.mkdirSync(folderPath, { recursive: true });
|
166
|
-
const filePath = path_1.default.join(folderPath, 'workflow.json');
|
167
|
-
fs.writeFileSync(filePath, JSON.stringify(workflowConfig, null, 2));
|
168
|
-
utils_1.customLog.success(`Workflow cloned successfully`);
|
169
|
-
}
|
170
|
-
});
|
171
|
-
}
|
172
|
-
resetCache() {
|
173
|
-
return __awaiter(this, void 0, void 0, function* () {
|
174
|
-
const args = process.argv;
|
175
|
-
const dirPath = (0, utils_1.getValueFromArgs)(args, Key.WORKFLOW);
|
176
|
-
const workflowName = dirPath.replace(/\//g, '__');
|
177
|
-
const secretKey = (0, utils_1.getValueFromArgs)(args, Key.SECRET_KEY);
|
178
|
-
if (!secretKey) {
|
179
|
-
utils_1.customLog.changeAndThrow(`Parameter secret is required`);
|
180
|
-
return;
|
181
|
-
}
|
182
|
-
if (!workflowName) {
|
183
|
-
utils_1.customLog.changeAndThrow(`Parameter workflow is required`);
|
184
|
-
return;
|
185
|
-
}
|
186
|
-
const url = `${constant_1.MSTATE_URL}/cache/reset/${workflowName}`;
|
187
|
-
const responseJSON = yield fetch(url, {
|
188
|
-
method: 'DELETE',
|
189
|
-
headers: {
|
190
|
-
'Content-Type': 'application/json',
|
191
|
-
'secret-key': secretKey,
|
192
|
-
},
|
193
|
-
});
|
194
|
-
const response = yield responseJSON.json();
|
195
|
-
if (response === null || response === void 0 ? void 0 : response.errors) {
|
196
|
-
utils_1.customLog.changeAndThrow('Invalid Parameters for Workflow: ', ...response === null || response === void 0 ? void 0 : response.errors);
|
197
|
-
}
|
198
|
-
else {
|
199
|
-
utils_1.customLog.success(`Workflow updated successfully`);
|
200
|
-
}
|
201
|
-
});
|
202
|
-
}
|
203
|
-
}
|
204
|
-
exports.workflowHandler = new WorkflowHandler();
|