@contentstack/cli-utilities 1.0.2 → 1.0.3

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.
@@ -4,10 +4,10 @@ const tslib_1 = require("tslib");
4
4
  const conf_1 = tslib_1.__importDefault(require("conf"));
5
5
  const uuid_1 = require("uuid");
6
6
  const fs_1 = require("fs");
7
- const ENC_KEY = 'encryptionKey';
8
- const ENCRYPT_CONF = true;
9
- const CONFIG_NAME = 'contentstack_cli';
10
- const ENC_CONFIG_NAME = 'contentstack_cli_obfuscate';
7
+ const ENC_KEY = process.env.ENC_KEY || 'encryptionKey';
8
+ const ENCRYPT_CONF = process.env.ENCRYPT_CONF === 'true' || false;
9
+ const CONFIG_NAME = process.env.CONFIG_NAME || 'contentstack_cli';
10
+ const ENC_CONFIG_NAME = process.env.ENC_CONFIG_NAME || 'contentstack_cli_obfuscate';
11
11
  const OLD_CONFIG_BACKUP_FLAG = 'isOldConfigBackup';
12
12
  const xdgBasedir = require('xdg-basedir');
13
13
  const path = require('path');
@@ -108,7 +108,7 @@ class Config {
108
108
  const oldConfigData = this.getConfigDataAndUnlinkConfigFile(config);
109
109
  this.getEncryptedConfig(oldConfigData, true);
110
110
  }
111
- catch (error) {
111
+ catch (_error) {
112
112
  // console.trace(error.message)
113
113
  }
114
114
  }
@@ -146,14 +146,14 @@ class Config {
146
146
  const oldConfigData = this.getConfigDataAndUnlinkConfigFile(config);
147
147
  this.getDecryptedConfig(oldConfigData); // NOTE NOTE reinitialize the config with old data and new decrypted file
148
148
  }
149
- catch (error) {
149
+ catch (_error) {
150
150
  // console.trace(error.message)
151
151
  try {
152
152
  const config = this.fallbackInit();
153
- const configData = this.getConfigDataAndUnlinkConfigFile(config);
154
- this.getDecryptedConfig(configData); // NOTE reinitialize the config with old data and new decrypted file
153
+ const _configData = this.getConfigDataAndUnlinkConfigFile(config);
154
+ this.getDecryptedConfig(_configData); // NOTE reinitialize the config with old data and new decrypted file
155
155
  }
156
- catch (error) {
156
+ catch (__error) {
157
157
  // console.trace(error.message)
158
158
  }
159
159
  }
package/lib/encrypter.js CHANGED
@@ -3,46 +3,44 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const crypto_1 = tslib_1.__importDefault(require("crypto"));
5
5
  const defaultValues = {
6
- typeIdentifier: "",
7
- algorithm: "aes-192-cbc",
8
- encryptionKey: "nF2ejRQcTv",
6
+ typeIdentifier: '',
7
+ algorithm: 'aes-192-cbc',
8
+ // file deepcode ignore HardcodedNonCryptoSecret: <This is a ToDo>
9
+ encryptionKey: 'nF2ejRQcTv',
9
10
  };
10
11
  class NodeCrypto {
11
12
  constructor(config = defaultValues) {
12
13
  const { algorithm, encryptionKey, typeIdentifier } = config;
13
14
  this.algorithm = algorithm;
14
15
  this.typeIdentifier = typeIdentifier;
15
- this.key = crypto_1.default.scryptSync(encryptionKey, "salt", 24);
16
+ this.key = crypto_1.default.scryptSync(encryptionKey, 'salt', 24);
16
17
  }
17
18
  encrypt(plainData) {
18
19
  const iv = crypto_1.default.randomBytes(16);
19
20
  const cipher = crypto_1.default.createCipheriv(this.algorithm, this.key, iv);
20
21
  let data = plainData;
21
22
  switch (typeof plainData) {
22
- case "number":
23
+ case 'number':
23
24
  data = `${String(plainData)}${this.typeIdentifier}number`;
24
25
  break;
25
- case "object":
26
+ case 'object':
26
27
  data = `${JSON.stringify(plainData)}${this.typeIdentifier}object`;
27
28
  break;
28
29
  }
29
- const encrypted = cipher.update(data, "utf8", "hex");
30
- return [
31
- encrypted + cipher.final("hex"),
32
- Buffer.from(iv).toString("hex"),
33
- ].join("|");
30
+ const encrypted = cipher.update(data, 'utf8', 'hex');
31
+ return [encrypted + cipher.final('hex'), Buffer.from(iv).toString('hex')].join('|');
34
32
  }
35
33
  decrypt(encryptedData) {
36
- const [encrypted, iv] = encryptedData.split("|");
34
+ const [encrypted, iv] = encryptedData.split('|');
37
35
  if (!iv)
38
- throw new Error("IV not found");
39
- const decipher = crypto_1.default.createDecipheriv(this.algorithm, this.key, Buffer.from(iv, "hex"));
40
- const result = decipher.update(encrypted, "hex", "utf8") + decipher.final("utf8");
36
+ throw new Error('IV not found');
37
+ const decipher = crypto_1.default.createDecipheriv(this.algorithm, this.key, Buffer.from(iv, 'hex'));
38
+ const result = decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8');
41
39
  const [data, type] = result.split(this.typeIdentifier);
42
40
  switch (type) {
43
- case "number":
41
+ case 'number':
44
42
  return Number(data);
45
- case "object":
43
+ case 'object':
46
44
  return JSON.parse(data);
47
45
  }
48
46
  return data;
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.chooseLocalePrompt = exports.NodeCrypto = exports.printFlagDeprecation = exports.configHandler = exports.messageHandler = exports.CLIError = exports.cliux = exports.logger = void 0;
3
+ exports.NodeCrypto = exports.printFlagDeprecation = exports.configHandler = exports.messageHandler = exports.CLIError = exports.cliux = exports.logger = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  var logger_1 = require("./logger");
6
6
  Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return tslib_1.__importDefault(logger_1).default; } });
@@ -17,5 +17,3 @@ Object.defineProperty(exports, "printFlagDeprecation", { enumerable: true, get:
17
17
  tslib_1.__exportStar(require("./http-client"), exports);
18
18
  var encrypter_1 = require("./encrypter");
19
19
  Object.defineProperty(exports, "NodeCrypto", { enumerable: true, get: function () { return tslib_1.__importDefault(encrypter_1).default; } });
20
- var selectors_1 = require("./selectors");
21
- Object.defineProperty(exports, "chooseLocalePrompt", { enumerable: true, get: function () { return selectors_1.chooseLocale; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/cli-utilities",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Utilities for contentstack projects",
5
5
  "main": "lib/index.js",
6
6
  "types": "./types/index.d.ts",
@@ -38,35 +38,32 @@
38
38
  "ora": "^5.4.0",
39
39
  "unique-string": "^2.0.0",
40
40
  "winston": "^3.7.2",
41
- "xdg-basedir": "^4.0.0"
41
+ "xdg-basedir": "^4.0.0",
42
+ "uuid": "^8.3.2"
42
43
  },
43
44
  "devDependencies": {
44
45
  "@oclif/plugin-help": "^5.1.12",
45
46
  "@oclif/test": "^1.2.8",
46
- "@types/axios": "^0.14.0",
47
47
  "@types/chai": "^4.2.18",
48
- "@types/conf": "^3.0.0",
49
- "@types/dot-prop": "^5.0.1",
50
48
  "@types/inquirer": "^7.3.1",
51
49
  "@types/mkdirp": "^1.0.1",
52
50
  "@types/mocha": "^8.2.2",
53
- "@types/nock": "^11.1.0",
54
51
  "@types/node": "^14.14.32",
55
52
  "@types/sinon": "^10.0.2",
56
53
  "@types/tar": "^4.0.3",
57
- "@types/winston": "^2.4.4",
58
54
  "chai": "^4.3.4",
59
55
  "eslint": "^8.18.0",
60
56
  "eslint-config-oclif": "^3.1.0",
61
- "eslint-config-oclif-typescript": "^0.1.0",
57
+ "eslint-config-oclif-typescript": "^0.2.0",
58
+ "fancy-test": "^2.0.0",
62
59
  "globby": "^10.0.2",
63
- "mocha": "^9.2.2",
60
+ "mocha": "^10.0.0",
64
61
  "nock": "^13.1.0",
65
62
  "nyc": "^15.1.0",
66
63
  "rimraf": "^2.7.1",
67
64
  "sinon": "^11.1.1",
68
65
  "tmp": "^0.2.1",
69
- "ts-node": "^8.10.2",
66
+ "ts-node": "^10.9.1",
70
67
  "typescript": "^4.7.4"
71
68
  }
72
- }
69
+ }
@@ -2,10 +2,10 @@ import Conf from 'conf';
2
2
  import { v4 as uuid } from 'uuid';
3
3
  import { existsSync, unlinkSync, readFileSync } from 'fs';
4
4
 
5
- const ENC_KEY = 'encryptionKey';
6
- const ENCRYPT_CONF: boolean = true
7
- const CONFIG_NAME = 'contentstack_cli';
8
- const ENC_CONFIG_NAME = 'contentstack_cli_obfuscate';
5
+ const ENC_KEY = process.env.ENC_KEY || 'encryptionKey';
6
+ const ENCRYPT_CONF: boolean = process.env.ENCRYPT_CONF === 'true' || false;
7
+ const CONFIG_NAME = process.env.CONFIG_NAME || 'contentstack_cli';
8
+ const ENC_CONFIG_NAME = process.env.ENC_CONFIG_NAME || 'contentstack_cli_obfuscate';
9
9
  const OLD_CONFIG_BACKUP_FLAG = 'isOldConfigBackup'
10
10
 
11
11
  const xdgBasedir = require('xdg-basedir');
@@ -41,8 +41,8 @@ class Config {
41
41
  }
42
42
  } catch (error) {
43
43
  console.log("No data to be imported from Old config file");
44
-
45
44
  }
45
+
46
46
  this.set(OLD_CONFIG_BACKUP_FLAG, true)
47
47
  }
48
48
  }
@@ -52,10 +52,10 @@ class Config {
52
52
  for (const key in data) {
53
53
  const value = data[key];
54
54
  const setPath = _path ? _path + '.' + key : key
55
+
55
56
  if (typeof (value) == "object") {
56
57
  this.setOldConfigStoreData(value, setPath)
57
- }
58
- else {
58
+ } else {
59
59
  this.set(setPath, value)
60
60
  }
61
61
  }
@@ -121,7 +121,7 @@ class Config {
121
121
  const config = this.fallbackInit()
122
122
  const oldConfigData = this.getConfigDataAndUnlinkConfigFile(config)
123
123
  this.getEncryptedConfig(oldConfigData, true)
124
- } catch (error) {
124
+ } catch (_error) {
125
125
  // console.trace(error.message)
126
126
  }
127
127
  }
@@ -159,14 +159,14 @@ class Config {
159
159
  let config = new Conf({ configName: CONFIG_NAME, encryptionKey })
160
160
  const oldConfigData = this.getConfigDataAndUnlinkConfigFile(config)
161
161
  this.getDecryptedConfig(oldConfigData) // NOTE NOTE reinitialize the config with old data and new decrypted file
162
- } catch (error) {
162
+ } catch (_error) {
163
163
  // console.trace(error.message)
164
164
 
165
165
  try {
166
166
  const config = this.fallbackInit()
167
- const configData = this.getConfigDataAndUnlinkConfigFile(config)
168
- this.getDecryptedConfig(configData) // NOTE reinitialize the config with old data and new decrypted file
169
- } catch (error) {
167
+ const _configData = this.getConfigDataAndUnlinkConfigFile(config)
168
+ this.getDecryptedConfig(_configData) // NOTE reinitialize the config with old data and new decrypted file
169
+ } catch (__error) {
170
170
  // console.trace(error.message)
171
171
  }
172
172
  }
package/src/encrypter.ts CHANGED
@@ -1,4 +1,4 @@
1
- import crypto from "crypto";
1
+ import crypto from 'crypto';
2
2
 
3
3
  type CryptoConfig = {
4
4
  algorithm?: string;
@@ -7,9 +7,10 @@ type CryptoConfig = {
7
7
  };
8
8
 
9
9
  const defaultValues: CryptoConfig = {
10
- typeIdentifier: "",
11
- algorithm: "aes-192-cbc",
12
- encryptionKey: "nF2ejRQcTv",
10
+ typeIdentifier: '',
11
+ algorithm: 'aes-192-cbc',
12
+ // file deepcode ignore HardcodedNonCryptoSecret: <This is a ToDo>
13
+ encryptionKey: 'nF2ejRQcTv',
13
14
  };
14
15
 
15
16
  export default class NodeCrypto {
@@ -21,7 +22,7 @@ export default class NodeCrypto {
21
22
  const { algorithm, encryptionKey, typeIdentifier } = config;
22
23
  this.algorithm = algorithm;
23
24
  this.typeIdentifier = typeIdentifier;
24
- this.key = crypto.scryptSync(encryptionKey, "salt", 24);
25
+ this.key = crypto.scryptSync(encryptionKey, 'salt', 24);
25
26
  }
26
27
 
27
28
  encrypt(plainData) {
@@ -30,38 +31,30 @@ export default class NodeCrypto {
30
31
  let data = plainData;
31
32
 
32
33
  switch (typeof plainData) {
33
- case "number":
34
+ case 'number':
34
35
  data = `${String(plainData)}${this.typeIdentifier}number`;
35
36
  break;
36
- case "object":
37
+ case 'object':
37
38
  data = `${JSON.stringify(plainData)}${this.typeIdentifier}object`;
38
39
  break;
39
40
  }
40
41
 
41
- const encrypted = cipher.update(data, "utf8", "hex");
42
+ const encrypted = cipher.update(data, 'utf8', 'hex');
42
43
 
43
- return [
44
- encrypted + cipher.final("hex"),
45
- Buffer.from(iv).toString("hex"),
46
- ].join("|");
44
+ return [encrypted + cipher.final('hex'), Buffer.from(iv).toString('hex')].join('|');
47
45
  }
48
46
 
49
47
  decrypt(encryptedData) {
50
- const [encrypted, iv] = encryptedData.split("|");
51
- if (!iv) throw new Error("IV not found");
52
- const decipher = crypto.createDecipheriv(
53
- this.algorithm,
54
- this.key,
55
- Buffer.from(iv, "hex")
56
- );
57
- const result =
58
- decipher.update(encrypted, "hex", "utf8") + decipher.final("utf8");
48
+ const [encrypted, iv] = encryptedData.split('|');
49
+ if (!iv) throw new Error('IV not found');
50
+ const decipher = crypto.createDecipheriv(this.algorithm, this.key, Buffer.from(iv, 'hex'));
51
+ const result = decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8');
59
52
  const [data, type] = result.split(this.typeIdentifier);
60
53
 
61
54
  switch (type) {
62
- case "number":
55
+ case 'number':
63
56
  return Number(data);
64
- case "object":
57
+ case 'object':
65
58
  return JSON.parse(data);
66
59
  }
67
60
 
package/src/index.ts CHANGED
@@ -6,4 +6,3 @@ export { default as configHandler } from './config-handler';
6
6
  export { default as printFlagDeprecation } from './flag-deprecation-check';
7
7
  export * from './http-client';
8
8
  export { default as NodeCrypto } from './encrypter'
9
- export { chooseLocale as chooseLocalePrompt } from './selectors';
package/types/index.d.ts CHANGED
@@ -6,4 +6,3 @@ export { default as configHandler } from './config-handler';
6
6
  export { default as printFlagDeprecation } from './flag-deprecation-check';
7
7
  export * from './http-client';
8
8
  export { default as NodeCrypto } from './encrypter';
9
- export { chooseLocale as chooseLocalePrompt } from './selectors';