mstate-cli 0.0.2 → 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.
@@ -1,78 +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.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();
@@ -1,163 +0,0 @@
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
- WORKFLOW = 'workflow',
14
- }
15
-
16
- class WorkflowAction {
17
- constructor() {}
18
-
19
- async saveToDB(args: string[]) {
20
- try {
21
- const docPath =
22
- args
23
- .find((str) => str.includes(Key.PATH))
24
- ?.replace(Key.PATH + '=', '') ?? '';
25
-
26
- const secretKey = (
27
- args.find((str) => str.includes(Key.SECRET_KEY)) ?? ''
28
- ).replace(Key.SECRET_KEY + '=', '');
29
-
30
- let query = '';
31
- if (docPath) {
32
- query += `path=${docPath}`;
33
- }
34
-
35
- if (query.length) {
36
- query = '?' + query;
37
- }
38
- const url = `${MSTATE_URL}/workflow/config/new${query}`;
39
-
40
- const filePath = path.resolve(args[0]);
41
-
42
- const workflowJSON = fs.readFileSync(filePath, 'utf8');
43
-
44
- const responseJSON = await fetch(url, {
45
- method: 'POST',
46
- headers: {
47
- 'secret-key': secretKey,
48
- 'Content-Type': 'application/json',
49
- },
50
- body: JSON.stringify(JSON.parse(workflowJSON)),
51
- });
52
-
53
- const response = await responseJSON.json();
54
- if (response?.errors) {
55
- console.error('Mstate error', 'Invalid Parameters: ', response?.errors);
56
- } else {
57
- console.log('Workflow Added successfully', response?.data);
58
- }
59
- } catch (error: any) {
60
- console.error(error.message);
61
- }
62
- }
63
-
64
- async updateWorkflowToDB(args: string[]) {
65
- try {
66
- const docPath =
67
- args
68
- .find((str) => str.includes(Key.PATH))
69
- ?.replace(Key.PATH + '=', '') ?? '';
70
-
71
- const secretKey = (
72
- args.find((str) => str.includes(Key.SECRET_KEY)) ?? ''
73
- ).replace(Key.SECRET_KEY + '=', '');
74
-
75
- if (!secretKey) {
76
- console.error(`Parameter secret is required`);
77
- return;
78
- }
79
-
80
- let query = '';
81
- if (docPath) {
82
- query += `path=${docPath}`;
83
- }
84
-
85
- if (query.length) {
86
- query = '?' + query;
87
- }
88
- const url = `${MSTATE_URL}/workflow/config${query}`;
89
-
90
- const filePath = path.resolve(args[0]);
91
-
92
- const workflowJSON = fs.readFileSync(filePath, 'utf8');
93
-
94
- const responseJSON = await fetch(url, {
95
- method: 'PUT',
96
- headers: {
97
- 'secret-key': secretKey,
98
- 'Content-Type': 'application/json',
99
- },
100
- body: JSON.stringify(JSON.parse(workflowJSON)),
101
- });
102
-
103
- const response = await responseJSON.json();
104
- if (response?.errors) {
105
- console.error('Mstate error', 'Invalid Parameters: ', response?.errors);
106
- } else {
107
- console.log('Workflow Uploaded successfully', response?.data);
108
- }
109
- } catch (error: any) {
110
- console.error(error.message);
111
- }
112
- }
113
-
114
- async linkToMobioffice() {}
115
-
116
- async cloneWorkflow(args: string[]) {
117
- try {
118
- const workflowName =
119
- args
120
- .find((str) => str.includes(Key.WORKFLOW))
121
- ?.replace(Key.WORKFLOW + '=', '') ?? '';
122
-
123
- const secretKey = (
124
- args.find((str) => str.includes(Key.SECRET_KEY)) ?? ''
125
- ).replace(Key.SECRET_KEY + '=', '');
126
-
127
- if (!secretKey) {
128
- console.error(`Parameter secret is required`);
129
- return;
130
- }
131
-
132
- if (!workflowName) {
133
- console.error(`Parameter workflow is required`);
134
- return;
135
- }
136
-
137
- const url = `${MSTATE_URL}/workflow/config/${workflowName}`;
138
-
139
- console.log({ url });
140
- const responseJSON = await fetch(url, {
141
- headers: {
142
- 'secret-key': secretKey,
143
- },
144
- });
145
-
146
- const response = await responseJSON.json();
147
- if (response?.errors) {
148
- console.error('Mstate error', 'Invalid Parameters: ', response?.errors);
149
- } else {
150
- const workflowConfig = response?.data;
151
-
152
- const filePath = path.resolve(workflowName);
153
- fs.writeFileSync(filePath, JSON.stringify(workflowConfig, null, 2));
154
-
155
- console.log(`Workflow "${workflowName}" is cloned successfully`);
156
- }
157
- } catch (error: any) {
158
- console.error(error.message);
159
- }
160
- }
161
- }
162
-
163
- export const workflowAction = new WorkflowAction();