mstate-cli 0.0.1
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/.prettierrc +5 -0
- package/Readme.md +15 -0
- package/dist/actions/publishWorkflow.js +78 -0
- package/dist/actions/workflow.action.js +133 -0
- package/dist/common/constant.js +5 -0
- package/dist/common/enum.js +9 -0
- package/dist/index.js +18 -0
- package/package.json +23 -0
- package/src/actions/workflow.action.ts +116 -0
- package/src/common/constant.ts +2 -0
- package/src/common/enum.ts +5 -0
- package/src/index.ts +20 -0
- package/src/interface.d.ts +43 -0
- package/tsconfig.json +12 -0
package/.prettierrc
ADDED
package/Readme.md
ADDED
@@ -0,0 +1,78 @@
|
|
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.workflowAction = void 0;
|
39
|
+
const fs = __importStar(require("fs"));
|
40
|
+
const path_1 = __importDefault(require("path"));
|
41
|
+
const constant_1 = require("../common/constant");
|
42
|
+
var Key;
|
43
|
+
(function (Key) {
|
44
|
+
Key["PATH"] = "path";
|
45
|
+
Key["SECRET_KEY"] = "secret";
|
46
|
+
})(Key || (Key = {}));
|
47
|
+
class CreateWorkflowSeed {
|
48
|
+
constructor() { }
|
49
|
+
saveToDB(args) {
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
51
|
+
var _a, _b, _c;
|
52
|
+
try {
|
53
|
+
const docPath = (_b = (_a = args
|
54
|
+
.find((str) => str.includes(Key.PATH))) === null || _a === void 0 ? void 0 : _a.replace(Key.PATH + '=', '')) !== null && _b !== void 0 ? _b : '';
|
55
|
+
const secretKey = ((_c = args.find((str) => str.includes(Key.SECRET_KEY))) !== null && _c !== void 0 ? _c : '').replace(Key.SECRET_KEY + '=', '');
|
56
|
+
const url = `${constant_1.MSTATE_URL}/workflow/config/new?path=${docPath}`;
|
57
|
+
const filePath = path_1.default.resolve(args[0]);
|
58
|
+
const workflowJSON = fs.readFileSync(filePath, 'utf8');
|
59
|
+
const responseJSON = yield fetch(url, {
|
60
|
+
method: 'POST',
|
61
|
+
headers: {
|
62
|
+
'secret-key': secretKey,
|
63
|
+
'Content-Type': 'application/json',
|
64
|
+
},
|
65
|
+
body: JSON.stringify(JSON.parse(workflowJSON)),
|
66
|
+
});
|
67
|
+
const response = yield responseJSON.json();
|
68
|
+
if (response === null || response === void 0 ? void 0 : response.errors) {
|
69
|
+
console.error('Mstate error', 'Invalid Parameters: ', response === null || response === void 0 ? void 0 : response.errors);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
catch (error) {
|
73
|
+
console.error(error.message);
|
74
|
+
}
|
75
|
+
});
|
76
|
+
}
|
77
|
+
}
|
78
|
+
exports.workflowAction = new CreateWorkflowSeed();
|
@@ -0,0 +1,133 @@
|
|
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.workflowAction = void 0;
|
39
|
+
const fs = __importStar(require("fs"));
|
40
|
+
const path_1 = __importDefault(require("path"));
|
41
|
+
const constant_1 = require("../common/constant");
|
42
|
+
var Key;
|
43
|
+
(function (Key) {
|
44
|
+
Key["PATH"] = "path";
|
45
|
+
Key["SECRET_KEY"] = "secret";
|
46
|
+
})(Key || (Key = {}));
|
47
|
+
class WorkflowAction {
|
48
|
+
constructor() { }
|
49
|
+
saveToDB(args) {
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
51
|
+
var _a, _b, _c;
|
52
|
+
try {
|
53
|
+
const docPath = (_b = (_a = args
|
54
|
+
.find((str) => str.includes(Key.PATH))) === null || _a === void 0 ? void 0 : _a.replace(Key.PATH + '=', '')) !== null && _b !== void 0 ? _b : '';
|
55
|
+
const secretKey = ((_c = args.find((str) => str.includes(Key.SECRET_KEY))) !== null && _c !== void 0 ? _c : '').replace(Key.SECRET_KEY + '=', '');
|
56
|
+
let query = '';
|
57
|
+
if (docPath) {
|
58
|
+
query += `path=${docPath}`;
|
59
|
+
}
|
60
|
+
if (query.length) {
|
61
|
+
query = '?' + query;
|
62
|
+
}
|
63
|
+
const url = `${constant_1.MSTATE_URL}/workflow/config/new${query}`;
|
64
|
+
const filePath = path_1.default.resolve(args[0]);
|
65
|
+
const workflowJSON = fs.readFileSync(filePath, 'utf8');
|
66
|
+
const responseJSON = yield fetch(url, {
|
67
|
+
method: 'POST',
|
68
|
+
headers: {
|
69
|
+
'secret-key': secretKey,
|
70
|
+
'Content-Type': 'application/json',
|
71
|
+
},
|
72
|
+
body: JSON.stringify(JSON.parse(workflowJSON)),
|
73
|
+
});
|
74
|
+
const response = yield responseJSON.json();
|
75
|
+
if (response === null || response === void 0 ? void 0 : response.errors) {
|
76
|
+
console.error('Mstate error', 'Invalid Parameters: ', response === null || response === void 0 ? void 0 : response.errors);
|
77
|
+
}
|
78
|
+
else {
|
79
|
+
console.log('Workflow Added successfully', response === null || response === void 0 ? void 0 : response.data);
|
80
|
+
}
|
81
|
+
}
|
82
|
+
catch (error) {
|
83
|
+
console.error(error.message);
|
84
|
+
}
|
85
|
+
});
|
86
|
+
}
|
87
|
+
updateWorkflowToDB(args) {
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
89
|
+
var _a, _b, _c;
|
90
|
+
try {
|
91
|
+
const docPath = (_b = (_a = args
|
92
|
+
.find((str) => str.includes(Key.PATH))) === null || _a === void 0 ? void 0 : _a.replace(Key.PATH + '=', '')) !== null && _b !== void 0 ? _b : '';
|
93
|
+
const secretKey = ((_c = args.find((str) => str.includes(Key.SECRET_KEY))) !== null && _c !== void 0 ? _c : '').replace(Key.SECRET_KEY + '=', '');
|
94
|
+
if (!secretKey) {
|
95
|
+
console.error(`Parameter secret is required`);
|
96
|
+
return;
|
97
|
+
}
|
98
|
+
let query = '';
|
99
|
+
if (docPath) {
|
100
|
+
query += `path=${docPath}`;
|
101
|
+
}
|
102
|
+
if (query.length) {
|
103
|
+
query = '?' + query;
|
104
|
+
}
|
105
|
+
const url = `${constant_1.MSTATE_URL}/workflow/config${query}`;
|
106
|
+
const filePath = path_1.default.resolve(args[0]);
|
107
|
+
const workflowJSON = fs.readFileSync(filePath, 'utf8');
|
108
|
+
const responseJSON = yield fetch(url, {
|
109
|
+
method: 'PUT',
|
110
|
+
headers: {
|
111
|
+
'secret-key': secretKey,
|
112
|
+
'Content-Type': 'application/json',
|
113
|
+
},
|
114
|
+
body: JSON.stringify(JSON.parse(workflowJSON)),
|
115
|
+
});
|
116
|
+
const response = yield responseJSON.json();
|
117
|
+
if (response === null || response === void 0 ? void 0 : response.errors) {
|
118
|
+
console.error('Mstate error', 'Invalid Parameters: ', response === null || response === void 0 ? void 0 : response.errors);
|
119
|
+
}
|
120
|
+
else {
|
121
|
+
console.log('Workflow Uploaded successfully', response === null || response === void 0 ? void 0 : response.data);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
catch (error) {
|
125
|
+
console.error(error.message);
|
126
|
+
}
|
127
|
+
});
|
128
|
+
}
|
129
|
+
linkToMobioffice() {
|
130
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
131
|
+
}
|
132
|
+
}
|
133
|
+
exports.workflowAction = new WorkflowAction();
|
@@ -0,0 +1,9 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.CmdAction = void 0;
|
4
|
+
var CmdAction;
|
5
|
+
(function (CmdAction) {
|
6
|
+
CmdAction["LINK"] = "link";
|
7
|
+
CmdAction["ADD"] = "add";
|
8
|
+
CmdAction["UPDATE"] = "update";
|
9
|
+
})(CmdAction || (exports.CmdAction = CmdAction = {}));
|
package/dist/index.js
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
const workflow_action_1 = require("./actions/workflow.action");
|
5
|
+
const enum_1 = require("./common/enum");
|
6
|
+
const [action, ...params] = process.argv.slice(2);
|
7
|
+
switch (action) {
|
8
|
+
case enum_1.CmdAction.LINK:
|
9
|
+
break;
|
10
|
+
case enum_1.CmdAction.ADD:
|
11
|
+
workflow_action_1.workflowAction.saveToDB(params);
|
12
|
+
break;
|
13
|
+
case enum_1.CmdAction.UPDATE:
|
14
|
+
workflow_action_1.workflowAction.updateWorkflowToDB(params);
|
15
|
+
break;
|
16
|
+
default:
|
17
|
+
console.error(`Mstate`, 'error', `Missing script: "${action}"`);
|
18
|
+
}
|
package/package.json
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
{
|
2
|
+
"name": "mstate-cli",
|
3
|
+
"version": "0.0.1",
|
4
|
+
"main": "index.js",
|
5
|
+
"bin": {
|
6
|
+
"mstate": "./dist/index.js"
|
7
|
+
},
|
8
|
+
"scripts": {
|
9
|
+
"build": "tsc",
|
10
|
+
"start": "npm run build && node dist/index.js"
|
11
|
+
},
|
12
|
+
"keywords": [
|
13
|
+
"mstate",
|
14
|
+
"workflow"
|
15
|
+
],
|
16
|
+
"author": "",
|
17
|
+
"license": "ISC",
|
18
|
+
"description": "A CLI tool for maintaining mstate workflows config",
|
19
|
+
"devDependencies": {
|
20
|
+
"@types/node": "^22.9.0",
|
21
|
+
"typescript": "^5.6.3"
|
22
|
+
}
|
23
|
+
}
|
@@ -0,0 +1,116 @@
|
|
1
|
+
import * as fs from 'fs';
|
2
|
+
import path from 'path';
|
3
|
+
import readline from 'readline';
|
4
|
+
import { MSTATE_URL } from '../common/constant';
|
5
|
+
|
6
|
+
interface AddWorkflow extends WorkflowConfig {
|
7
|
+
version: string;
|
8
|
+
}
|
9
|
+
|
10
|
+
enum Key {
|
11
|
+
PATH = 'path',
|
12
|
+
SECRET_KEY = 'secret',
|
13
|
+
}
|
14
|
+
|
15
|
+
class WorkflowAction {
|
16
|
+
constructor() {}
|
17
|
+
|
18
|
+
async saveToDB(args: string[]) {
|
19
|
+
try {
|
20
|
+
const docPath =
|
21
|
+
args
|
22
|
+
.find((str) => str.includes(Key.PATH))
|
23
|
+
?.replace(Key.PATH + '=', '') ?? '';
|
24
|
+
|
25
|
+
const secretKey = (
|
26
|
+
args.find((str) => str.includes(Key.SECRET_KEY)) ?? ''
|
27
|
+
).replace(Key.SECRET_KEY + '=', '');
|
28
|
+
|
29
|
+
let query = '';
|
30
|
+
if (docPath) {
|
31
|
+
query += `path=${docPath}`;
|
32
|
+
}
|
33
|
+
|
34
|
+
if (query.length) {
|
35
|
+
query = '?' + query;
|
36
|
+
}
|
37
|
+
const url = `${MSTATE_URL}/workflow/config/new${query}`;
|
38
|
+
|
39
|
+
const filePath = path.resolve(args[0]);
|
40
|
+
|
41
|
+
const workflowJSON = fs.readFileSync(filePath, 'utf8');
|
42
|
+
|
43
|
+
const responseJSON = await fetch(url, {
|
44
|
+
method: 'POST',
|
45
|
+
headers: {
|
46
|
+
'secret-key': secretKey,
|
47
|
+
'Content-Type': 'application/json',
|
48
|
+
},
|
49
|
+
body: JSON.stringify(JSON.parse(workflowJSON)),
|
50
|
+
});
|
51
|
+
|
52
|
+
const response = await responseJSON.json();
|
53
|
+
if (response?.errors) {
|
54
|
+
console.error('Mstate error', 'Invalid Parameters: ', response?.errors);
|
55
|
+
} else {
|
56
|
+
console.log('Workflow Added successfully', response?.data);
|
57
|
+
}
|
58
|
+
} catch (error: any) {
|
59
|
+
console.error(error.message);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
async updateWorkflowToDB(args: string[]) {
|
64
|
+
try {
|
65
|
+
const docPath =
|
66
|
+
args
|
67
|
+
.find((str) => str.includes(Key.PATH))
|
68
|
+
?.replace(Key.PATH + '=', '') ?? '';
|
69
|
+
|
70
|
+
const secretKey = (
|
71
|
+
args.find((str) => str.includes(Key.SECRET_KEY)) ?? ''
|
72
|
+
).replace(Key.SECRET_KEY + '=', '');
|
73
|
+
|
74
|
+
if (!secretKey) {
|
75
|
+
console.error(`Parameter secret is required`);
|
76
|
+
return;
|
77
|
+
}
|
78
|
+
|
79
|
+
let query = '';
|
80
|
+
if (docPath) {
|
81
|
+
query += `path=${docPath}`;
|
82
|
+
}
|
83
|
+
|
84
|
+
if (query.length) {
|
85
|
+
query = '?' + query;
|
86
|
+
}
|
87
|
+
const url = `${MSTATE_URL}/workflow/config${query}`;
|
88
|
+
|
89
|
+
const filePath = path.resolve(args[0]);
|
90
|
+
|
91
|
+
const workflowJSON = fs.readFileSync(filePath, 'utf8');
|
92
|
+
|
93
|
+
const responseJSON = await fetch(url, {
|
94
|
+
method: 'PUT',
|
95
|
+
headers: {
|
96
|
+
'secret-key': secretKey,
|
97
|
+
'Content-Type': 'application/json',
|
98
|
+
},
|
99
|
+
body: JSON.stringify(JSON.parse(workflowJSON)),
|
100
|
+
});
|
101
|
+
|
102
|
+
const response = await responseJSON.json();
|
103
|
+
if (response?.errors) {
|
104
|
+
console.error('Mstate error', 'Invalid Parameters: ', response?.errors);
|
105
|
+
} else {
|
106
|
+
console.log('Workflow Uploaded successfully', response?.data);
|
107
|
+
}
|
108
|
+
} catch (error: any) {
|
109
|
+
console.error(error.message);
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
async linkToMobioffice() {}
|
114
|
+
}
|
115
|
+
|
116
|
+
export const workflowAction = new WorkflowAction();
|
package/src/index.ts
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
3
|
+
import { workflowAction } from './actions/workflow.action';
|
4
|
+
import { CmdAction } from './common/enum';
|
5
|
+
|
6
|
+
const [action, ...params] = process.argv.slice(2);
|
7
|
+
|
8
|
+
switch (action as CmdAction) {
|
9
|
+
case CmdAction.LINK:
|
10
|
+
break;
|
11
|
+
case CmdAction.ADD:
|
12
|
+
workflowAction.saveToDB(params);
|
13
|
+
break;
|
14
|
+
case CmdAction.UPDATE:
|
15
|
+
workflowAction.updateWorkflowToDB(params);
|
16
|
+
break;
|
17
|
+
|
18
|
+
default:
|
19
|
+
console.error(`Mstate`, 'error', `Missing script: "${action}"`);
|
20
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
interface WorkflowConfig {
|
2
|
+
name: string;
|
3
|
+
states: State[];
|
4
|
+
}
|
5
|
+
|
6
|
+
interface State {
|
7
|
+
name: string;
|
8
|
+
actions: Action[];
|
9
|
+
}
|
10
|
+
|
11
|
+
interface Action {
|
12
|
+
name: string;
|
13
|
+
when?: string;
|
14
|
+
on: {
|
15
|
+
[key: string]: {
|
16
|
+
name: string;
|
17
|
+
type: 'ACTION' | 'STATE';
|
18
|
+
};
|
19
|
+
done: {
|
20
|
+
name: string;
|
21
|
+
type: 'ACTION' | 'STATE';
|
22
|
+
};
|
23
|
+
error: {
|
24
|
+
name: string;
|
25
|
+
type: 'ACTION' | 'STATE';
|
26
|
+
};
|
27
|
+
};
|
28
|
+
}
|
29
|
+
|
30
|
+
interface ActionConfig {
|
31
|
+
version: string;
|
32
|
+
name: string;
|
33
|
+
meta?: unknown;
|
34
|
+
type: 'MANUAL' | 'AUTO' | 'CHAINED';
|
35
|
+
steps: Step[];
|
36
|
+
completionWebhook?: string;
|
37
|
+
}
|
38
|
+
|
39
|
+
interface Step {
|
40
|
+
id: string;
|
41
|
+
module: string;
|
42
|
+
config: unknown;
|
43
|
+
}
|
package/tsconfig.json
ADDED