mstate-cli 0.2.5 → 0.2.6

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/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "mstate-cli",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "main": "index.js",
5
5
  "bin": {
6
6
  "mstate": "./dist/index.js"
7
7
  },
8
8
  "scripts": {
9
- "build": "npx rollup -c",
9
+ "build": "rollup -c",
10
+ "dev": "rollup -c --watch",
11
+ "prod": "npm run build",
10
12
  "start": "npm run build && node dist/index.js"
11
13
  },
12
14
  "keywords": [
@@ -19,6 +21,7 @@
19
21
  "license": "ISC",
20
22
  "description": "A CLI tool for maintaining mstate workflows config",
21
23
  "devDependencies": {
24
+ "@rollup/plugin-alias": "^5.1.1",
22
25
  "@rollup/plugin-commonjs": "^28.0.1",
23
26
  "@rollup/plugin-json": "^6.1.0",
24
27
  "@rollup/plugin-node-resolve": "^15.3.0",
@@ -28,6 +31,7 @@
28
31
  "@types/crypto-js": "^4.2.2",
29
32
  "@types/express": "^5.0.0",
30
33
  "@types/node": "^22.9.0",
34
+ "rollup": "^4.18.0",
31
35
  "tslib": "^2.8.1",
32
36
  "typescript": "^5.6.3"
33
37
  },
@@ -0,0 +1,34 @@
1
+ import resolve from '@rollup/plugin-node-resolve';
2
+ import commonjs from '@rollup/plugin-commonjs';
3
+ import typescript from '@rollup/plugin-typescript';
4
+ import json from '@rollup/plugin-json';
5
+ import terser from '@rollup/plugin-terser';
6
+ import alias from '@rollup/plugin-alias';
7
+ import { fileURLToPath } from 'url';
8
+ import path from 'path';
9
+
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = path.dirname(__filename);
12
+
13
+ export default {
14
+ input: 'src/index.ts', // Your entry file
15
+ output: {
16
+ dir: 'dist', // Output directory
17
+ format: 'cjs', // CommonJS format
18
+ },
19
+ plugins: [
20
+ alias({
21
+ entries: [
22
+ { find: '@shared', replacement: path.resolve(__dirname, '../shared') },
23
+ ],
24
+ }),
25
+ resolve(), // Resolves node_modules
26
+ commonjs(), // Converts CommonJS to ES Modules
27
+ terser(), // remove spaces and compress build
28
+ typescript({
29
+ tsconfig: './tsconfig.json', // Ensure Rollup uses your TypeScript config
30
+ declaration: false, // Make sure to disable declaration file generation in Rollup
31
+ }), // Transpile TypeScript
32
+ json(), // Add JSON plugin
33
+ ],
34
+ };
@@ -1,5 +1,10 @@
1
1
  import path from 'path';
2
2
  import os from 'os';
3
+ import {
4
+ MOBIOFFICE_API_URL,
5
+ MSTATE_API_URL,
6
+ MSTATE_FRONTEND_URL,
7
+ } from '@shared/constants';
3
8
 
4
9
  export const CRED_FOLDER_PATH = path.join(os.homedir(), '.mstate');
5
10
  export const CRED_FILE_PATH = path.join(
@@ -9,13 +14,13 @@ export const CRED_FILE_PATH = path.join(
9
14
 
10
15
  export const ENCRYPT_KEY: string = 'THIS_IS_MOBIOFFICE';
11
16
 
12
- export const MSTATE_DOMAIN: string = `https://mstate.ai/`;
13
- // export const MSTATE_DOMAIN: string = `http://localhost:5173/`;
17
+ // export const MSTATE_DOMAIN: string = `https://mstate.ai/`;
18
+ export const MSTATE_DOMAIN: string = MSTATE_FRONTEND_URL;
14
19
  // export const MSTATE_DOMAIN: string = `https://dev.mstate.ai/`;
15
20
 
16
21
  // export const MSTATE_URL: string = 'https://dev.mstate.mobioffice.io/api';
17
- // export const MSTATE_URL = 'http://localhost:3000/api';
18
- export const MSTATE_URL = 'https://api.mstate.mobioffice.io/api';
22
+ export const MSTATE_URL = MSTATE_API_URL;
23
+ // export const MSTATE_URL = 'https://api.mstate.mobioffice.io/api';
19
24
 
20
- export const MOBIOFFICE_URL: string = 'https://server.mobioffice.io/api';
25
+ export const MOBIOFFICE_URL: string = MOBIOFFICE_API_URL;
21
26
  // export const MOBIOFFICE_URL: string = 'https://dev-server.mobioffice.io/api';
@@ -7,6 +7,7 @@ export enum CmdAction {
7
7
  PERMISSION = 'permission',
8
8
  USER = 'user',
9
9
  ADD = 'add',
10
+ COPY = 'copy',
10
11
  CLONE = 'clone',
11
12
  PUSH = 'push',
12
13
  HELP = '--help',
@@ -7,6 +7,7 @@ import { customLog, getSecretKey } from '../common/utils';
7
7
  enum Key {
8
8
  WORKFLOW = 'workflow=',
9
9
  SECRET_KEY = 'secret=',
10
+ TYPE = 'type=',
10
11
  }
11
12
 
12
13
  class ActionHandler {
@@ -16,6 +17,7 @@ class ActionHandler {
16
17
  const args = process.argv;
17
18
  const workflowName = getValueFromArgs(args, Key.WORKFLOW);
18
19
  const secretKey = getSecretKey();
20
+ const type = getValueFromArgs(args, Key.TYPE);
19
21
 
20
22
  if (!secretKey) {
21
23
  customLog.changeAndThrow(`Parameter secret is required`);
@@ -27,7 +29,12 @@ class ActionHandler {
27
29
  return;
28
30
  }
29
31
 
30
- const url = `${MSTATE_URL}/action/config/all/?workflow=${workflowName}`;
32
+ let query = `?workflow=${workflowName}`;
33
+ if (type) {
34
+ query += `&type=${type}`;
35
+ }
36
+
37
+ const url = `${MSTATE_URL}/action/config/all/${query}`;
31
38
 
32
39
  const responseJSON = await fetch(url, {
33
40
  headers: {
@@ -68,6 +75,7 @@ class ActionHandler {
68
75
  async saveToDB() {
69
76
  const args = process.argv;
70
77
  const workflowName = getValueFromArgs(args, Key.WORKFLOW);
78
+ const type = getValueFromArgs(args, Key.TYPE);
71
79
  const secretKey = getSecretKey();
72
80
 
73
81
  if (!secretKey) {
@@ -82,6 +90,11 @@ class ActionHandler {
82
90
 
83
91
  const folderPath = path.resolve(workflowName, 'actions');
84
92
 
93
+ let query = `?workflow=${workflowName}`;
94
+ if (type) {
95
+ query += `&type=${type}`;
96
+ }
97
+
85
98
  // loop to every folder to publish workflow
86
99
  fs.readdir(folderPath, (err, files) => {
87
100
  if (!files) return;
@@ -90,7 +103,7 @@ class ActionHandler {
90
103
  const filePath = path.join(folderPath, fileName);
91
104
  const data = fs.readFileSync(filePath, 'utf8');
92
105
 
93
- const url = `${MSTATE_URL}/action/config/?workflow=${workflowName}`;
106
+ const url = `${MSTATE_URL}/action/config/${query}`;
94
107
  const responseJSON = await fetch(url, {
95
108
  method: 'PUT',
96
109
  headers: {
@@ -7,6 +7,7 @@ import { getValueFromArgs } from '../common/helpers';
7
7
  enum Key {
8
8
  WORKFLOW = 'workflow=',
9
9
  SECRET_KEY = 'secret=',
10
+ TYPE = 'type=',
10
11
  }
11
12
 
12
13
  class EnvironmentHandler {
@@ -16,6 +17,7 @@ class EnvironmentHandler {
16
17
  const args = process.argv;
17
18
  const workflowName = getValueFromArgs(args, Key.WORKFLOW);
18
19
  const secretKey = getSecretKey();
20
+ const type = getValueFromArgs(args, Key.TYPE);
19
21
 
20
22
  if (!secretKey) {
21
23
  customLog.changeAndThrow(`Parameter secret is required`);
@@ -27,7 +29,11 @@ class EnvironmentHandler {
27
29
  return;
28
30
  }
29
31
 
30
- const url = `${MSTATE_URL}/env/?workflow=${workflowName}`;
32
+ let query = `?workflow=${workflowName}`;
33
+ if (type) {
34
+ query += `&type=${type}`;
35
+ }
36
+ const url = `${MSTATE_URL}/env/${query}`;
31
37
 
32
38
  const responseJSON = await fetch(url, {
33
39
  headers: {
@@ -55,6 +61,7 @@ class EnvironmentHandler {
55
61
 
56
62
  const workflowName = getValueFromArgs(args, Key.WORKFLOW);
57
63
  const secretKey = getSecretKey();
64
+ const type = getValueFromArgs(args, Key.TYPE);
58
65
 
59
66
  if (!secretKey) {
60
67
  customLog.changeAndThrow(`Parameter secret is required`);
@@ -82,6 +89,7 @@ class EnvironmentHandler {
82
89
  body: JSON.stringify({
83
90
  workflow: workflowName,
84
91
  env: environments,
92
+ type,
85
93
  }),
86
94
  });
87
95
 
@@ -11,6 +11,10 @@ class HelpHandler {
11
11
  CmdAction.CLONE,
12
12
  'Clone workflow with actions and environments',
13
13
  );
14
+ customLog.info(
15
+ CmdAction.COPY,
16
+ 'crete a new workflow by copying the current',
17
+ );
14
18
  customLog.info(CmdAction.PUSH, 'Update the changes one in cloned workflow');
15
19
  customLog.info(
16
20
  CmdAction.LINK,
@@ -9,6 +9,7 @@ enum Key {
9
9
  SECRET_KEY = 'secret=',
10
10
  COMPANY_NAME = 'company=',
11
11
  USER_ID = 'user=',
12
+ TYPE = 'type=',
12
13
  }
13
14
 
14
15
  class MobiofficeHandler {
@@ -23,6 +24,7 @@ class MobiofficeHandler {
23
24
  const secretKey = getSecretKey();
24
25
  const companyName = getValueFromArgs(args, Key.COMPANY_NAME);
25
26
  const user = getValueFromArgs(args, Key.USER_ID);
27
+ const type = getValueFromArgs(args, Key.TYPE) || 'private';
26
28
 
27
29
  if (!workflowName) {
28
30
  customLog.changeAndThrow(`Parameter workflow is required`);
@@ -56,6 +58,7 @@ class MobiofficeHandler {
56
58
  workflow: workflowName,
57
59
  secret: secretKey,
58
60
  nickname: companyName,
61
+ type,
59
62
  user,
60
63
  }),
61
64
  });
@@ -9,17 +9,19 @@ enum Key {
9
9
  FILE = 'file=',
10
10
  SECRET_KEY = 'secret=',
11
11
  WORKFLOW = 'workflow=',
12
+ TYPE = 'type=',
12
13
  }
13
14
 
14
15
  class WorkflowHandler {
15
16
  constructor() {}
16
17
 
17
- async saveToDB() {
18
+ async addNewWorkflow() {
18
19
  try {
19
20
  const args = process.argv;
20
21
 
21
22
  const workflowPath = getValueFromArgs(args, Key.PATH);
22
23
  const file = getValueFromArgs(args, Key.FILE);
24
+ const type = getValueFromArgs(args, Key.TYPE);
23
25
  const secretKey = getSecretKey();
24
26
 
25
27
  if (!file) {
@@ -44,6 +46,10 @@ class WorkflowHandler {
44
46
  query = '?' + query;
45
47
  }
46
48
 
49
+ if (type) {
50
+ query += query ? `&type=${type}` : `?type=${type}`;
51
+ }
52
+
47
53
  const url = `${MSTATE_URL}/workflow/config/new${query}`;
48
54
  const responseJSON = await fetch(url, {
49
55
  method: 'POST',
@@ -72,6 +78,7 @@ class WorkflowHandler {
72
78
  const args = process.argv;
73
79
 
74
80
  const workflowName = getValueFromArgs(args, Key.WORKFLOW);
81
+ const type = getValueFromArgs(args, Key.TYPE);
75
82
  const secretKey = getSecretKey();
76
83
 
77
84
  if (!secretKey) {
@@ -91,6 +98,10 @@ class WorkflowHandler {
91
98
 
92
99
  let query = `?workflow=${workflowName}`;
93
100
 
101
+ if (type) {
102
+ query += `&type=${type}`;
103
+ }
104
+
94
105
  const url = `${MSTATE_URL}/workflow/config${query}`;
95
106
  const responseJSON = await fetch(url, {
96
107
  method: 'PUT',
@@ -118,6 +129,8 @@ class WorkflowHandler {
118
129
  const args = process.argv;
119
130
 
120
131
  const workflowName = getValueFromArgs(args, Key.WORKFLOW);
132
+ const type = getValueFromArgs(args, Key.TYPE);
133
+
121
134
  const secretKey = getSecretKey();
122
135
 
123
136
  if (!secretKey) {
@@ -129,8 +142,9 @@ class WorkflowHandler {
129
142
  customLog.changeAndThrow(`Parameter workflow is required`);
130
143
  return;
131
144
  }
145
+ const typeQuery = type ? `&type=${type}` : '';
132
146
 
133
- const url = `${MSTATE_URL}/workflow/config/?workflow=${workflowName}`;
147
+ const url = `${MSTATE_URL}/workflow/config/?workflow=${workflowName}${typeQuery}`;
134
148
  const responseJSON = await fetch(url, {
135
149
  method: 'GET',
136
150
  headers: {
@@ -158,6 +172,29 @@ class WorkflowHandler {
158
172
  }
159
173
  }
160
174
 
175
+ async copyWorkflow() {
176
+ try {
177
+ const args = process.argv;
178
+
179
+ const workflowName = getValueFromArgs(args, Key.WORKFLOW);
180
+
181
+ if (!workflowName) {
182
+ customLog.changeAndThrow(`Parameter workflow is required`);
183
+ return;
184
+ }
185
+
186
+ const workflowPath = ('/' + workflowName).replace(/\/([^\/]*)$/, '');
187
+ if (workflowPath) {
188
+ process.argv.push(`path=${workflowPath.slice(1, workflowPath.length)}`);
189
+ }
190
+ process.argv.push(`file=${workflowName + '/workflow.json'}`);
191
+
192
+ await this.addNewWorkflow();
193
+ } catch (error: any) {
194
+ customLog.changeAndThrow(error.message);
195
+ }
196
+ }
197
+
161
198
  async resetCache() {
162
199
  const args = process.argv;
163
200
 
package/src/index.ts CHANGED
@@ -55,8 +55,10 @@ const [action] = argv.slice(2);
55
55
  await environmentHandler.cloneEnvironments();
56
56
  break;
57
57
  case CmdAction.ADD:
58
- await workflowHandler.saveToDB();
58
+ await workflowHandler.addNewWorkflow();
59
59
  break;
60
+ case CmdAction.COPY:
61
+ await workflowHandler.copyWorkflow();
60
62
  case CmdAction.PUSH:
61
63
  await workflowHandler.updateWorkflowToDB();
62
64
  await actionHandler.saveToDB();
package/tsconfig.json CHANGED
@@ -1,16 +1,18 @@
1
1
  {
2
+ "extends": "../tsconfig.base.json",
2
3
  "compilerOptions": {
3
4
  "target": "ESNext",
4
5
  "module": "ESNext",
5
6
  "moduleResolution": "Node",
6
7
  "strict": true,
7
- "rootDir": "src",
8
+ "rootDir": "../",
9
+ "baseUrl": ".",
8
10
  "esModuleInterop": true,
9
11
  "resolveJsonModule": true,
10
12
  "skipLibCheck": true,
11
13
  "outDir": "./dist",
12
14
  "declaration": true
13
15
  },
14
- "include": ["src/**/*.ts"],
16
+ "include": ["src/**/*.ts", "../shared/**/*"],
15
17
  "exclude": ["node_modules", "dist", ".vscode"]
16
18
  }
@@ -1,3 +0,0 @@
1
- {
2
- "cSpell.words": ["MOBIOFFICE", "Mstate"]
3
- }
package/rollup.config.js DELETED
@@ -1,23 +0,0 @@
1
- const resolve = require('@rollup/plugin-node-resolve');
2
- const commonjs = require('@rollup/plugin-commonjs');
3
- const typescript = require('@rollup/plugin-typescript');
4
- const json = require('@rollup/plugin-json');
5
- const terser = require('@rollup/plugin-terser');
6
-
7
- module.exports = {
8
- input: 'src/index.ts', // Your entry file
9
- output: {
10
- dir: 'dist', // Output directory
11
- format: 'cjs', // CommonJS format
12
- },
13
- plugins: [
14
- resolve(), // Resolves node_modules
15
- commonjs(), // Converts CommonJS to ES Modules
16
- terser(), // remove spaces and compress build
17
- typescript({
18
- tsconfig: './tsconfig.json', // Ensure Rollup uses your TypeScript config
19
- declaration: false, // Make sure to disable declaration file generation in Rollup
20
- }), // Transpile TypeScript
21
- json(), // Add JSON plugin
22
- ],
23
- };