mstate-cli 0.2.3 → 0.2.5

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.2.3",
3
+ "version": "0.2.5",
4
4
  "main": "index.js",
5
5
  "bin": {
6
6
  "mstate": "./dist/index.js"
@@ -7,10 +7,15 @@ export const CRED_FILE_PATH = path.join(
7
7
  '.mstate_credentials',
8
8
  );
9
9
 
10
- // export const MSTATE_DOMAIN: string = `https://mstate.ai/`;
10
+ export const ENCRYPT_KEY: string = 'THIS_IS_MOBIOFFICE';
11
+
12
+ export const MSTATE_DOMAIN: string = `https://mstate.ai/`;
11
13
  // export const MSTATE_DOMAIN: string = `http://localhost:5173/`;
12
- export const MSTATE_DOMAIN: string = `https://dev.mstate.ai/`;
14
+ // export const MSTATE_DOMAIN: string = `https://dev.mstate.ai/`;
13
15
 
14
- export const MSTATE_URL: string = 'https://dev.mstate.mobioffice.io/api';
16
+ // export const MSTATE_URL: string = 'https://dev.mstate.mobioffice.io/api';
15
17
  // export const MSTATE_URL = 'http://localhost:3000/api';
16
- // export const MSTATE_URL = 'https://api.mstate.mobioffice.io/api';
18
+ export const MSTATE_URL = 'https://api.mstate.mobioffice.io/api';
19
+
20
+ export const MOBIOFFICE_URL: string = 'https://server.mobioffice.io/api';
21
+ // export const MOBIOFFICE_URL: string = 'https://dev-server.mobioffice.io/api';
@@ -1,7 +1,7 @@
1
1
  export enum CmdAction {
2
2
  LOGIN = 'login',
3
3
  LINK = 'link',
4
- UPDATE = 'update',
4
+ SET = 'set',
5
5
  DEV = 'dev',
6
6
  UNLINK = 'unlink',
7
7
  PERMISSION = 'permission',
@@ -1,4 +1,6 @@
1
1
  import CryptoJS from 'crypto-js';
2
+ import os from 'os';
3
+ import { ENCRYPT_KEY } from './constant';
2
4
 
3
5
  export function getValueFromArgs(args: string[], key: string) {
4
6
  return args.find((str) => str.includes(key))?.replace(key, '') ?? '';
@@ -8,18 +10,33 @@ export function hasFlag(args: string[], flag: string) {
8
10
  return args.includes(flag.toUpperCase()) || args.includes(flag.toLowerCase());
9
11
  }
10
12
 
11
- const ENCRYPT_KEY: string = 'THIS_IS_MOBIOFFICE';
12
-
13
13
  // Encrypting data
14
14
  export function encryptData(data: any) {
15
15
  const jsonData = JSON.stringify(data);
16
- const encryptedData = CryptoJS.AES.encrypt(jsonData, ENCRYPT_KEY).toString();
16
+ const encryptedData = CryptoJS.AES.encrypt(
17
+ jsonData,
18
+ getEncryptionKey(),
19
+ ).toString();
17
20
  return encryptedData;
18
21
  }
19
22
 
20
23
  // Decrypting data
21
24
  export function decryptData<T = any>(encryptedData: string) {
22
- const bytes = CryptoJS.AES.decrypt(encryptedData, ENCRYPT_KEY);
25
+ const bytes = CryptoJS.AES.decrypt(encryptedData, getEncryptionKey());
23
26
  const decryptedData = bytes.toString(CryptoJS.enc.Utf8);
24
27
  return JSON.parse(decryptedData) as T;
25
28
  }
29
+
30
+ export function getEncryptionKey() {
31
+ return ENCRYPT_KEY + getMacID();
32
+ }
33
+
34
+ export function getMacID() {
35
+ const networkInterfaces = os.networkInterfaces();
36
+ const macAddresses = Object.values(networkInterfaces)
37
+ .flat()
38
+ .filter((details) => !details?.internal)
39
+ .map((details) => details?.mac);
40
+
41
+ return macAddresses[0];
42
+ }
@@ -38,7 +38,7 @@ export function handleUpdateSecretKey(secret: string) {
38
38
  flag: 'w',
39
39
  mode: 0o600,
40
40
  });
41
- } catch (error) { }
41
+ } catch (error) {}
42
42
  }
43
43
 
44
44
  export function getSecretKey() {
@@ -62,4 +62,6 @@ export function getSecretKey() {
62
62
  }
63
63
  }
64
64
 
65
+ export function getEnv() {}
66
+
65
67
  //#endregion
@@ -1,3 +1,4 @@
1
+ import { MOBIOFFICE_URL } from '../common/constant';
1
2
  import { CmdAction } from '../common/enum';
2
3
  import { getValueFromArgs } from '../common/helpers';
3
4
  import { customLog, getSecretKey } from '../common/utils';
@@ -6,12 +7,12 @@ enum Key {
6
7
  WORKFLOW = 'workflow=',
7
8
  PERMISSIONS = 'permissions=',
8
9
  SECRET_KEY = 'secret=',
9
- COMPANY_ID = 'company=',
10
+ COMPANY_NAME = 'company=',
10
11
  USER_ID = 'user=',
11
12
  }
12
13
 
13
14
  class MobiofficeHandler {
14
- private MOBIOFFICE_URL: string = 'https://server.mobioffice.io/api';
15
+ private MOBIOFFICE_URL: string = MOBIOFFICE_URL;
15
16
 
16
17
  constructor() {}
17
18
 
@@ -20,7 +21,7 @@ class MobiofficeHandler {
20
21
 
21
22
  const workflowName = getValueFromArgs(args, Key.WORKFLOW);
22
23
  const secretKey = getSecretKey();
23
- const companyID = getValueFromArgs(args, Key.COMPANY_ID);
24
+ const companyName = getValueFromArgs(args, Key.COMPANY_NAME);
24
25
  const user = getValueFromArgs(args, Key.USER_ID);
25
26
 
26
27
  if (!workflowName) {
@@ -33,7 +34,7 @@ class MobiofficeHandler {
33
34
  return;
34
35
  }
35
36
 
36
- if (!companyID) {
37
+ if (!companyName) {
37
38
  customLog.changeAndThrow(`Parameter company is required`);
38
39
  return;
39
40
  }
@@ -54,7 +55,7 @@ class MobiofficeHandler {
54
55
  action: action.toUpperCase(),
55
56
  workflow: workflowName,
56
57
  secret: secretKey,
57
- companyID,
58
+ nickname: companyName,
58
59
  user,
59
60
  }),
60
61
  });
package/src/index.ts CHANGED
@@ -33,7 +33,7 @@ const [action] = argv.slice(2);
33
33
  else await companyHandler.addToken();
34
34
  break;
35
35
 
36
- case CmdAction.UPDATE:
36
+ case CmdAction.SET:
37
37
  companyHandler.handleUpdateSavedSecretKey();
38
38
  break;
39
39