mstate-cli 0.4.5 → 0.4.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,6 +1,6 @@
1
1
  {
2
2
  "name": "mstate-cli",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "main": "dist/index.js",
5
5
  "bin": {
6
6
  "mstate": "./dist/index.js"
@@ -15,5 +15,16 @@ export const CRED_FILE_PATH = path.join(
15
15
  export const ENCRYPT_KEY: string = 'THIS_IS_MOBIOFFICE';
16
16
 
17
17
  export const MSTATE_DOMAIN: string = MSTATE_FRONTEND_URL;
18
- export const MSTATE_URL = MSTATE_API_URL;
19
- export const MOBIOFFICE_URL: string = MOBIOFFICE_API_URL;
18
+ export const getMstateURL = (env?: string) => {
19
+ return env === 'local'
20
+ ? 'http://localhost:3000/api'
21
+ : env
22
+ ? 'https://dev.mstate.mobioffice.io/api'
23
+ : 'https://api.mstate.mobioffice.io/api';
24
+ };
25
+
26
+ export const getMobiofficeURL = (env?: string) => {
27
+ return env
28
+ ? 'https://dev-server.mobioffice.io/api'
29
+ : 'https://server.mobioffice.io/api';
30
+ };
@@ -27,4 +27,5 @@ export enum Variables {
27
27
  PHONE = '-m',
28
28
  SAVED_VALUE = '-ws',
29
29
  VISIBILITY = '-v',
30
+ ENV = '--env',
30
31
  }
@@ -1,9 +1,9 @@
1
1
  import * as fs from 'fs';
2
2
  import path from 'path';
3
- import { MSTATE_URL } from '../common/constant';
4
3
  import { getValueFromArgs, sortJSON } from '../common/helpers';
5
4
  import { customLog, getSecretKey } from '../common/utils';
6
5
  import { Variables } from 'src/common/enum';
6
+ import { getMstateURL } from 'src/common/constant';
7
7
 
8
8
  class ActionHandler {
9
9
  constructor() {}
@@ -11,6 +11,8 @@ class ActionHandler {
11
11
  async cloneActions() {
12
12
  const workflowName = getValueFromArgs(Variables.WORKFLOW, true);
13
13
  const secretKey = getSecretKey();
14
+ const env = getValueFromArgs(Variables.ENV);
15
+ const MSTATE_URL = getMstateURL(env);
14
16
 
15
17
  let query = `?workflow=${workflowName}&hasNickName=${true}`;
16
18
  const url = `${MSTATE_URL}/action/config/all/${query}`;
@@ -58,6 +60,8 @@ class ActionHandler {
58
60
  async saveToDB() {
59
61
  const workflowName = getValueFromArgs(Variables.WORKFLOW, true);
60
62
  const secretKey = getSecretKey();
63
+ const env = getValueFromArgs(Variables.ENV);
64
+ const MSTATE_URL = getMstateURL(env);
61
65
 
62
66
  const folderPath = path.resolve(workflowName, 'actions');
63
67
 
@@ -1,4 +1,8 @@
1
- import { MSTATE_DOMAIN, MSTATE_URL } from '../common/constant';
1
+ import {
2
+ getMobiofficeURL,
3
+ getMstateURL,
4
+ MSTATE_DOMAIN,
5
+ } from '../common/constant';
2
6
  import {
3
7
  customLog,
4
8
  getSecretKey,
@@ -20,6 +24,8 @@ class CompanyHandler {
20
24
  const secretKey = getSecretKey();
21
25
  const user = getValueFromArgs(Variables.USER_ID, true);
22
26
  const companyID = getValueFromArgs(Variables.COMPANY_ID, true);
27
+ const env = getValueFromArgs(Variables.ENV);
28
+ const MSTATE_URL = getMstateURL(env);
23
29
 
24
30
  if (!permissions.length && permissions[0]?.length) {
25
31
  customLog.changeAndThrow(`Parameter permissions is required`);
@@ -56,6 +62,8 @@ class CompanyHandler {
56
62
  const name = getValueFromArgs(Variables.USER_ID, true);
57
63
  const email = getValueFromArgs(Variables.EMAIL, true);
58
64
  const phone = getValueFromArgs(Variables.PHONE, true);
65
+ const env = getValueFromArgs(Variables.ENV);
66
+ const MSTATE_URL = getMstateURL(env);
59
67
 
60
68
  const url = `${MSTATE_URL}/um/user`;
61
69
  const responseJSON = await fetch(url, {
@@ -90,6 +98,8 @@ class CompanyHandler {
90
98
  const secretKey = getSecretKey();
91
99
  const user = getValueFromArgs(Variables.USER_ID, true);
92
100
  const companyID = getValueFromArgs(Variables.COMPANY_ID, true);
101
+ const env = getValueFromArgs(Variables.ENV);
102
+ const MSTATE_URL = getMstateURL(env);
93
103
 
94
104
  if (!permissions.length && permissions[0]?.length) {
95
105
  customLog.changeAndThrow(`Parameter permissions is required`);
@@ -195,6 +205,8 @@ class CompanyHandler {
195
205
 
196
206
  async logInfo() {
197
207
  const secretKey = getSecretKey();
208
+ const env = getValueFromArgs(Variables.ENV);
209
+ const MSTATE_URL = getMstateURL(env);
198
210
 
199
211
  try {
200
212
  const url = `${MSTATE_URL}/company/info`;
@@ -218,6 +230,7 @@ class CompanyHandler {
218
230
  customLog.error(error.message);
219
231
  }
220
232
 
233
+ customLog.info('MSTATE_URL', getMobiofficeURL(env));
221
234
  customLog.info('MSTATE_URL', MSTATE_URL);
222
235
  customLog.info('Token', getSecretKey());
223
236
  }
@@ -1,9 +1,9 @@
1
1
  import * as fs from 'fs';
2
2
  import path from 'path';
3
- import { MSTATE_URL } from '../common/constant';
4
3
  import { customLog, getSecretKey } from '../common/utils';
5
4
  import { getValueFromArgs } from '../common/helpers';
6
5
  import { Variables } from 'src/common/enum';
6
+ import { getMstateURL } from 'src/common/constant';
7
7
 
8
8
  class EnvironmentHandler {
9
9
  constructor() {}
@@ -11,6 +11,8 @@ class EnvironmentHandler {
11
11
  async cloneEnvironments() {
12
12
  const workflowName = getValueFromArgs(Variables.WORKFLOW, true);
13
13
  const secretKey = getSecretKey();
14
+ const env = getValueFromArgs(Variables.ENV);
15
+ const MSTATE_URL = getMstateURL(env);
14
16
 
15
17
  let query = `?workflow=${workflowName}&hasNickName=${true}`;
16
18
  const url = `${MSTATE_URL}/env/${query}`;
@@ -39,6 +41,8 @@ class EnvironmentHandler {
39
41
  async saveToDB() {
40
42
  const workflowName = getValueFromArgs(Variables.WORKFLOW, true);
41
43
  const secretKey = getSecretKey();
44
+ const env = getValueFromArgs(Variables.ENV);
45
+ const MSTATE_URL = getMstateURL(env);
42
46
 
43
47
  const filePath = path.resolve(workflowName, 'environment.json');
44
48
 
@@ -1,4 +1,4 @@
1
- import { MOBIOFFICE_URL } from '../common/constant';
1
+ import { getMobiofficeURL } from 'src/common/constant';
2
2
  import { CmdAction, Variables } from '../common/enum';
3
3
  import { getValueFromArgs } from '../common/helpers';
4
4
  import { customLog, getSecretKey } from '../common/utils';
@@ -11,6 +11,8 @@ class MobiofficeHandler {
11
11
  const secretKey = getSecretKey();
12
12
  const companyName = getValueFromArgs(Variables.COMPANY_ID, true);
13
13
  const user = getValueFromArgs(Variables.USER_ID, true);
14
+ const env = getValueFromArgs(Variables.ENV);
15
+ const MOBIOFFICE_URL = getMobiofficeURL(env);
14
16
 
15
17
  const url = `${MOBIOFFICE_URL}/Mstate/workFlow/user`;
16
18
  const responseJSON = await fetch(url, {
@@ -1,9 +1,9 @@
1
1
  import * as fs from 'fs';
2
2
  import path from 'path';
3
- import { MSTATE_URL } from '../common/constant';
4
3
  import { customLog, getSecretKey } from '../common/utils';
5
4
  import { getValueFromArgs, sortJSON } from '../common/helpers';
6
5
  import { Variables } from 'src/common/enum';
6
+ import { getMstateURL } from 'src/common/constant';
7
7
 
8
8
  class WorkflowHandler {
9
9
  constructor() {}
@@ -11,6 +11,8 @@ class WorkflowHandler {
11
11
  private async addNewWorkflow(workflowPath: string, file: string) {
12
12
  try {
13
13
  const secretKey = getSecretKey();
14
+ const env = getValueFromArgs(Variables.ENV);
15
+ const MSTATE_URL = getMstateURL(env);
14
16
 
15
17
  if (!file) {
16
18
  customLog.changeAndThrow(`Parameter file is required`);
@@ -61,6 +63,8 @@ class WorkflowHandler {
61
63
  async updateWorkflowToDB() {
62
64
  const workflowName = getValueFromArgs(Variables.WORKFLOW, true);
63
65
  const secretKey = getSecretKey();
66
+ const env = getValueFromArgs(Variables.ENV);
67
+ const MSTATE_URL = getMstateURL(env);
64
68
 
65
69
  const folderPath = path.resolve(workflowName);
66
70
  const filePath = path.join(folderPath, 'workflow.json');
@@ -98,6 +102,8 @@ class WorkflowHandler {
98
102
  getValueFromArgs(Variables.VISIBILITY, false) || 'private';
99
103
 
100
104
  const secretKey = getSecretKey();
105
+ const env = getValueFromArgs(Variables.ENV);
106
+ const MSTATE_URL = getMstateURL(env);
101
107
 
102
108
  let query = `?workflow=${workflowName}`;
103
109
  const url = `${MSTATE_URL}/workflow/property${query}`;
@@ -128,6 +134,8 @@ class WorkflowHandler {
128
134
  async cloneWorkflow() {
129
135
  const workflowName = getValueFromArgs(Variables.WORKFLOW, true);
130
136
  const secretKey = getSecretKey();
137
+ const env = getValueFromArgs(Variables.ENV);
138
+ const MSTATE_URL = getMstateURL(env);
131
139
 
132
140
  const url = `${MSTATE_URL}/workflow/config/?workflow=${workflowName}&hasNickName=${true}`;
133
141
  const responseJSON = await fetch(url, {
@@ -182,6 +190,8 @@ class WorkflowHandler {
182
190
  async resetCache() {
183
191
  const workflowName = getValueFromArgs(Variables.WORKFLOW, true);
184
192
  const secretKey = getSecretKey();
193
+ const env = getValueFromArgs(Variables.ENV);
194
+ const MSTATE_URL = getMstateURL(env);
185
195
 
186
196
  const url = `${MSTATE_URL}/cache/reset/?workflow=${workflowName}`;
187
197
  const responseJSON = await fetch(url, {