@contentstack/cli-utilities 1.0.3 → 1.0.4
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/lib/encrypter.js +2 -1
- package/lib/logger.js +3 -3
- package/package.json +15 -10
- package/types/config-handler.d.ts +4 -0
- package/types/http-client/http-response.d.ts +3 -1
- package/.eslintignore +0 -2
- package/.eslintrc +0 -40
- package/.mocharc.json +0 -12
- package/.nycrc.json +0 -5
- package/messages/auth.json +0 -46
- package/messages/config.json +0 -9
- package/messages/core.json +0 -6
- package/src/cli-error.ts +0 -15
- package/src/cli-ux.ts +0 -78
- package/src/config-handler.ts +0 -197
- package/src/encrypter.ts +0 -63
- package/src/flag-deprecation-check.ts +0 -41
- package/src/http-client/client.ts +0 -369
- package/src/http-client/http-response.ts +0 -55
- package/src/http-client/index.ts +0 -7
- package/src/index.ts +0 -8
- package/src/interfaces/index.ts +0 -61
- package/src/logger.ts +0 -101
- package/src/message-handler.ts +0 -45
- package/src/selectors/index.ts +0 -429
- package/src/selectors/interfaces.ts +0 -39
- package/src/selectors/validations.ts +0 -5
- package/test/helpers/init.js +0 -4
- package/test/tsconfig.json +0 -6
- package/tsconfig.json +0 -20
package/lib/encrypter.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const crypto_1 = tslib_1.__importDefault(require("crypto"));
|
|
5
|
+
const merge_1 = tslib_1.__importDefault(require("lodash/merge"));
|
|
5
6
|
const defaultValues = {
|
|
6
7
|
typeIdentifier: '◈',
|
|
7
8
|
algorithm: 'aes-192-cbc',
|
|
@@ -10,7 +11,7 @@ const defaultValues = {
|
|
|
10
11
|
};
|
|
11
12
|
class NodeCrypto {
|
|
12
13
|
constructor(config = defaultValues) {
|
|
13
|
-
const { algorithm, encryptionKey, typeIdentifier } = config;
|
|
14
|
+
const { algorithm, encryptionKey, typeIdentifier } = (0, merge_1.default)(defaultValues, config);
|
|
14
15
|
this.algorithm = algorithm;
|
|
15
16
|
this.typeIdentifier = typeIdentifier;
|
|
16
17
|
this.key = crypto_1.default.scryptSync(encryptionKey, 'salt', 24);
|
package/lib/logger.js
CHANGED
|
@@ -4,6 +4,9 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
const winston_1 = tslib_1.__importDefault(require("winston"));
|
|
5
5
|
const message_handler_1 = tslib_1.__importDefault(require("./message-handler"));
|
|
6
6
|
class LoggerService {
|
|
7
|
+
static dateFormat() {
|
|
8
|
+
return new Date(Date.now()).toUTCString();
|
|
9
|
+
}
|
|
7
10
|
constructor(name) {
|
|
8
11
|
this.data = null;
|
|
9
12
|
this.name = null;
|
|
@@ -36,9 +39,6 @@ class LoggerService {
|
|
|
36
39
|
});
|
|
37
40
|
this.logger = logger;
|
|
38
41
|
}
|
|
39
|
-
static dateFormat() {
|
|
40
|
-
return new Date(Date.now()).toUTCString();
|
|
41
|
-
}
|
|
42
42
|
init(context) {
|
|
43
43
|
this.name = (context && context.plugin && context.plugin.name) || 'cli';
|
|
44
44
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-utilities",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Utilities for contentstack projects",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -23,29 +23,34 @@
|
|
|
23
23
|
"contentstack",
|
|
24
24
|
"utilities"
|
|
25
25
|
],
|
|
26
|
+
"files": [
|
|
27
|
+
"/npm-shrinkwrap.json",
|
|
28
|
+
"/lib",
|
|
29
|
+
"/types"
|
|
30
|
+
],
|
|
26
31
|
"author": "contentstack",
|
|
27
32
|
"license": "MIT",
|
|
28
33
|
"dependencies": {
|
|
29
|
-
"@contentstack/management": "^1.
|
|
34
|
+
"@contentstack/management": "^1.6.0",
|
|
30
35
|
"@oclif/core": "^1.8.2",
|
|
31
|
-
"axios": "
|
|
36
|
+
"axios": "1.1.3",
|
|
32
37
|
"chalk": "^4.0.0",
|
|
33
38
|
"conf": "^10.1.2",
|
|
34
39
|
"debug": "^4.1.1",
|
|
35
|
-
"inquirer": "
|
|
40
|
+
"inquirer": "8.2.4",
|
|
36
41
|
"inquirer-search-checkbox": "^1.0.0",
|
|
37
42
|
"inquirer-search-list": "^1.2.6",
|
|
38
43
|
"ora": "^5.4.0",
|
|
39
44
|
"unique-string": "^2.0.0",
|
|
45
|
+
"uuid": "^9.0.0",
|
|
40
46
|
"winston": "^3.7.2",
|
|
41
|
-
"xdg-basedir": "^4.0.0"
|
|
42
|
-
"uuid": "^8.3.2"
|
|
47
|
+
"xdg-basedir": "^4.0.0"
|
|
43
48
|
},
|
|
44
49
|
"devDependencies": {
|
|
45
50
|
"@oclif/plugin-help": "^5.1.12",
|
|
46
51
|
"@oclif/test": "^1.2.8",
|
|
47
52
|
"@types/chai": "^4.2.18",
|
|
48
|
-
"@types/inquirer": "^
|
|
53
|
+
"@types/inquirer": "^9.0.3",
|
|
49
54
|
"@types/mkdirp": "^1.0.1",
|
|
50
55
|
"@types/mocha": "^8.2.2",
|
|
51
56
|
"@types/node": "^14.14.32",
|
|
@@ -57,13 +62,13 @@
|
|
|
57
62
|
"eslint-config-oclif-typescript": "^0.2.0",
|
|
58
63
|
"fancy-test": "^2.0.0",
|
|
59
64
|
"globby": "^10.0.2",
|
|
60
|
-
"mocha": "
|
|
65
|
+
"mocha": "10.1.0",
|
|
61
66
|
"nock": "^13.1.0",
|
|
62
67
|
"nyc": "^15.1.0",
|
|
63
68
|
"rimraf": "^2.7.1",
|
|
64
69
|
"sinon": "^11.1.1",
|
|
65
70
|
"tmp": "^0.2.1",
|
|
66
71
|
"ts-node": "^10.9.1",
|
|
67
|
-
"typescript": "^4.
|
|
72
|
+
"typescript": "^4.9.3"
|
|
68
73
|
}
|
|
69
|
-
}
|
|
74
|
+
}
|
|
@@ -3,6 +3,10 @@ declare class Config {
|
|
|
3
3
|
private config;
|
|
4
4
|
constructor();
|
|
5
5
|
init(): Conf<Record<string, unknown>>;
|
|
6
|
+
importOldConfig(): void;
|
|
7
|
+
setOldConfigStoreData(data: any, _path?: string): void;
|
|
8
|
+
removeOldConfigStoreFile(): void;
|
|
9
|
+
private getOldConfig;
|
|
6
10
|
private fallbackInit;
|
|
7
11
|
private getObfuscationKey;
|
|
8
12
|
private getConfigDataAndUnlinkConfigFile;
|
|
@@ -33,5 +33,7 @@ export declare class HttpResponse<ResponseType = any> {
|
|
|
33
33
|
*
|
|
34
34
|
* @returns {Object}
|
|
35
35
|
*/
|
|
36
|
-
get headers(): import("axios").AxiosResponseHeaders
|
|
36
|
+
get headers(): import("axios").AxiosResponseHeaders | Partial<Record<string, string> & {
|
|
37
|
+
"set-cookie"?: string[];
|
|
38
|
+
}>;
|
|
37
39
|
}
|
package/.eslintignore
DELETED
package/.eslintrc
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": {
|
|
3
|
-
"node": true
|
|
4
|
-
},
|
|
5
|
-
"parser": "@typescript-eslint/parser",
|
|
6
|
-
"parserOptions": {
|
|
7
|
-
"project": "tsconfig.json",
|
|
8
|
-
"sourceType": "module"
|
|
9
|
-
},
|
|
10
|
-
"extends": [
|
|
11
|
-
"plugin:@typescript-eslint/recommended"
|
|
12
|
-
],
|
|
13
|
-
"rules": {
|
|
14
|
-
"@typescript-eslint/no-unused-vars": [
|
|
15
|
-
"error",
|
|
16
|
-
{
|
|
17
|
-
"args": "none"
|
|
18
|
-
}
|
|
19
|
-
],
|
|
20
|
-
"@typescript-eslint/prefer-namespace-keyword": "error",
|
|
21
|
-
"@typescript-eslint/quotes": [
|
|
22
|
-
"error",
|
|
23
|
-
"single",
|
|
24
|
-
{
|
|
25
|
-
"avoidEscape": true,
|
|
26
|
-
"allowTemplateLiterals": true
|
|
27
|
-
}
|
|
28
|
-
],
|
|
29
|
-
"semi": "off",
|
|
30
|
-
"@typescript-eslint/type-annotation-spacing": "error",
|
|
31
|
-
"@typescript-eslint/no-redeclare": "off",
|
|
32
|
-
"eqeqeq": [
|
|
33
|
-
"error",
|
|
34
|
-
"smart"
|
|
35
|
-
],
|
|
36
|
-
"id-match": "error",
|
|
37
|
-
"no-eval": "error",
|
|
38
|
-
"no-var": "error"
|
|
39
|
-
}
|
|
40
|
-
}
|
package/.mocharc.json
DELETED
package/messages/auth.json
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"CLI_AUTH_LOGIN_ENTER_EMAIL_ADDRESS": "Enter your email address",
|
|
3
|
-
"CLI_AUTH_LOGIN_ENTER_PASSWORD": "Enter your password",
|
|
4
|
-
"CLI_AUTH_LOGIN_SUCCESS": "Successfully logged in!!",
|
|
5
|
-
"CLI_AUTH_LOGIN_FAILED": "Login Error",
|
|
6
|
-
"CLI_AUTH_LOGIN_DESCRIPTION": "User session login",
|
|
7
|
-
"CLI_AUTH_LOGIN_FLAG_USERNAME": "User name",
|
|
8
|
-
"CLI_AUTH_LOGIN_FLAG_PASSWORD": "Password",
|
|
9
|
-
"CLI_AUTH_LOGIN_SECURITY_CODE_SEND_SUCCESS": "Security code sent to your mobile",
|
|
10
|
-
"CLI_AUTH_LOGIN_ASK_CHANNEL_FOR_SECURITY_CODE": "Two factor authentication enabled, please select a way to get the security code",
|
|
11
|
-
"CLI_AUTH_LOGIN_ENTER_SECURITY_CODE": "Please provide the security code",
|
|
12
|
-
"CLI_AUTH_LOGOUT_CONFIRM": "Are you sure you want to log out?",
|
|
13
|
-
"CLI_AUTH_LOGOUT_LOADER_START": "Logging out....",
|
|
14
|
-
"CLI_AUTH_LOGOUT_SUCCESS": "Successfully logged out",
|
|
15
|
-
"CLI_AUTH_LOGOUT_FAILED": "Error in logout, please login again",
|
|
16
|
-
"CLI_AUTH_LOGOUT_DESCRIPTION": "User session logout",
|
|
17
|
-
"CLI_AUTH_LOGOUT_FLAG_FORCE": "Force logging out for skipping the confirmation",
|
|
18
|
-
"CLI_AUTH_WHOAMI_LOGGED_IN_AS": "You are currently logged in with email",
|
|
19
|
-
"CLI_AUTH_WHOAMI_FAILED": "Failed to get the current user details",
|
|
20
|
-
"CLI_AUTH_WHOAMI_DESCRIPTION": "Display current users email address",
|
|
21
|
-
"CLI_AUTH_TOKENS_ADD_ASK_TOKEN_ALIAS": "Provide alias to store token",
|
|
22
|
-
"CLI_AUTH_TOKENS_ADD_CONFIRM_ALIAS_REPLACE": "Alias is already exists, do you want to replace?",
|
|
23
|
-
"CLI_AUTH_TOKENS_ADD_ENTER_API_KEY": "Enter the api key",
|
|
24
|
-
"CLI_AUTH_TOKENS_ADD_ENTER_TOKEN": "Enter the token",
|
|
25
|
-
"CLI_AUTH_TOKENS_ADD_ENTER_ENVIRONMENT": "Enter the environment name",
|
|
26
|
-
"CLI_AUTH_TOKENS_ADD_REPLACE_SUCCESS": "Successfully replaced the token",
|
|
27
|
-
"CLI_AUTH_TOKENS_ADD_SUCCESS": "Successfully added the token",
|
|
28
|
-
"CLI_AUTH_TOKENS_ADD_FAILED": "Failed to add the token",
|
|
29
|
-
"CLI_AUTH_TOKENS_ADD_DESCRIPTION": "Adds management/delivery tokens to your session to use it with further CLI command by default it adds management token if either of management or delivery flags are not set",
|
|
30
|
-
"CLI_AUTH_TOKENS_ADD_FLAG_DELIVERY_TOKEN": "Set this while saving delivery token",
|
|
31
|
-
"CLI_AUTH_TOKENS_ADD_FLAG_MANAGEMENT_TOKEN": "Set this while saving management token",
|
|
32
|
-
"CLI_AUTH_TOKENS_ADD_FLAG_ENVIRONMENT_NAME": "Environment name for delivery token",
|
|
33
|
-
"CLI_AUTH_TOKENS_REMOVE_SUCCESS": "Token removed successfully !!",
|
|
34
|
-
"CLI_AUTH_TOKENS_REMOVE_FAILED": "Failed to remove the selected token",
|
|
35
|
-
"CLI_AUTH_TOKENS_NOT_FOUND": "No tokens are added yet!",
|
|
36
|
-
"CLI_AUTH_TOKENS_REMOVE_SELECT_TOKEN": "Select tokens to remove",
|
|
37
|
-
"CLI_AUTH_TOKENS_REMOVE_DESCRIPTION": "Removes selected tokens",
|
|
38
|
-
"CLI_AUTH_TOKENS_LIST_NO_TOKENS": "No tokens are added. Use auth:tokens:add command to add tokens.",
|
|
39
|
-
"CLI_AUTH_TOKENS_LIST_FAILED": "Failed to list the tokens",
|
|
40
|
-
"CLI_AUTH_TOKENS_LIST_DESCRIPTION": "Lists all existing tokens added to the session",
|
|
41
|
-
"CLI_AUTH_TOKENS_VALIDATION_INVALID_DELIVERY_TOKEN": "Invalid delivery token",
|
|
42
|
-
"CLI_AUTH_TOKENS_VALIDATION_INVALID_ENVIRONMENT_NAME": "Invalid environment name",
|
|
43
|
-
"CLI_AUTH_TOKENS_VALIDATION_INVALID_MANAGEMENT_TOKEN": "Invalid management token",
|
|
44
|
-
"CLI_AUTH_TOKENS_VALIDATION_INVALID_API_KEY": "Invalid api key",
|
|
45
|
-
"CLI_AUTH_EXIT_PROCESS": "Exiting the process..."
|
|
46
|
-
}
|
package/messages/config.json
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"CLI_CONFIG_SET_REGION_DESCRIPTION": "Set region for CLI",
|
|
3
|
-
"CLI_CONFIG_SET_REGION_FLAG_D_DESCRIPTION": "Custom host to set for content delivery API, if this flag is added then cma and name flags are required",
|
|
4
|
-
"CLI_CONFIG_SET_REGION_FLAG_M_DESCRIPTION": "Custom host to set for content management API, , if this flag is added then cda and name flags are required",
|
|
5
|
-
"CLI_CONFIG_SET_REGION_FLAG_N_DESCRIPTION": "Name for the region, if this flag is added then cda and cma flags are required",
|
|
6
|
-
"CLI_CONFIG_SET_REGION_DEFAULT": "No argument or custom flag provided. Setting region to default NA",
|
|
7
|
-
"CLI_CONFIG_GET_REGION_DESCRIPTION": "Get current region set for CLI",
|
|
8
|
-
"CLI_CONFIG_GET_REGION_NOT_FOUND": "No region found, please set by running command $ csdx config:set:region"
|
|
9
|
-
}
|
package/messages/core.json
DELETED
package/src/cli-error.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export default class CLIError extends Error {
|
|
2
|
-
suggestions?: string[];
|
|
3
|
-
|
|
4
|
-
constructor(message, suggestions?: string[]) {
|
|
5
|
-
super(message);
|
|
6
|
-
this.suggestions = suggestions;
|
|
7
|
-
this.message = message;
|
|
8
|
-
|
|
9
|
-
if (typeof Error.captureStackTrace === 'function') {
|
|
10
|
-
Error.captureStackTrace(this, this.constructor);
|
|
11
|
-
} else {
|
|
12
|
-
this.stack = new Error(message).stack;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
package/src/cli-ux.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import inquirer from 'inquirer';
|
|
3
|
-
import { ux as cliux, Table } from '@oclif/core/lib/cli-ux'
|
|
4
|
-
|
|
5
|
-
import messageHandler from './message-handler';
|
|
6
|
-
import { PrintOptions, InquirePayload, CliUXPromptOptions } from './interfaces';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* CLI Interface
|
|
10
|
-
*/
|
|
11
|
-
class CLIInterface {
|
|
12
|
-
private loading: boolean;
|
|
13
|
-
|
|
14
|
-
constructor() {
|
|
15
|
-
this.loading = false;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
get uxTable(): typeof Table.table {
|
|
19
|
-
return cliux.table
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
init(context) {}
|
|
23
|
-
|
|
24
|
-
print(message: string, opts?: PrintOptions): void {
|
|
25
|
-
if (opts && opts.color) {
|
|
26
|
-
cliux.log(chalk[opts.color](messageHandler.parse(message)));
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
cliux.log(messageHandler.parse(message));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
success(message: string): void {
|
|
34
|
-
cliux.log(chalk.green(messageHandler.parse(message)));
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
error(message: string, ...params: any): void {
|
|
38
|
-
cliux.log(chalk.red(messageHandler.parse(message) + (params && params.length > 0 ? ': ' : '')), ...params);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
loader(message: string = ''): void {
|
|
42
|
-
if (!this.loading) {
|
|
43
|
-
cliux.action.start(messageHandler.parse(message));
|
|
44
|
-
} else {
|
|
45
|
-
cliux.action.stop(messageHandler.parse(message));
|
|
46
|
-
}
|
|
47
|
-
this.loading = !this.loading;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
table(
|
|
51
|
-
data: Record<string, unknown>[],
|
|
52
|
-
columns: Table.table.Columns<Record<string, unknown>>,
|
|
53
|
-
options?: Table.table.Options
|
|
54
|
-
): void {
|
|
55
|
-
cliux.table(data, columns, options);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async inquire<T>(inquirePayload: InquirePayload): Promise<T> {
|
|
59
|
-
inquirePayload.message = messageHandler.parse(inquirePayload.message);
|
|
60
|
-
const result = await inquirer.prompt(inquirePayload as inquirer.QuestionCollection<T>);
|
|
61
|
-
|
|
62
|
-
return result[inquirePayload.name] as T;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
prompt(name: string, options?: CliUXPromptOptions): Promise<any> {
|
|
66
|
-
return cliux.prompt(name, options)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
confirm(message?: string): Promise<boolean> {
|
|
70
|
-
return cliux.confirm(message)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
progress(options?: any): any {
|
|
74
|
-
return cliux.progress(options)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export default new CLIInterface();
|
package/src/config-handler.ts
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import Conf from 'conf';
|
|
2
|
-
import { v4 as uuid } from 'uuid';
|
|
3
|
-
import { existsSync, unlinkSync, readFileSync } from 'fs';
|
|
4
|
-
|
|
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
|
-
const OLD_CONFIG_BACKUP_FLAG = 'isOldConfigBackup'
|
|
10
|
-
|
|
11
|
-
const xdgBasedir = require('xdg-basedir');
|
|
12
|
-
const path = require('path');
|
|
13
|
-
const os = require('os');
|
|
14
|
-
const uniqueString = require('unique-string');
|
|
15
|
-
const oldConfigDirectory = xdgBasedir.config || path.join(os.tmpdir(), uniqueString());
|
|
16
|
-
const pathPrefix = path.join('configstore', `${CONFIG_NAME}.json`);
|
|
17
|
-
const oldConfigPath = path.join(oldConfigDirectory, pathPrefix);
|
|
18
|
-
|
|
19
|
-
class Config {
|
|
20
|
-
private config: Conf;
|
|
21
|
-
|
|
22
|
-
constructor() {
|
|
23
|
-
this.init()
|
|
24
|
-
this.importOldConfig()
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
init() {
|
|
28
|
-
return ENCRYPT_CONF === true
|
|
29
|
-
? this.getEncryptedConfig()
|
|
30
|
-
: this.getDecryptedConfig()
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
importOldConfig() {
|
|
35
|
-
if (!this.get(OLD_CONFIG_BACKUP_FLAG)) {
|
|
36
|
-
try {
|
|
37
|
-
const oldConfigStoreData = this.getOldConfig()
|
|
38
|
-
if (oldConfigStoreData) {
|
|
39
|
-
this.setOldConfigStoreData(oldConfigStoreData, '')
|
|
40
|
-
this.removeOldConfigStoreFile()
|
|
41
|
-
}
|
|
42
|
-
} catch (error) {
|
|
43
|
-
console.log("No data to be imported from Old config file");
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
this.set(OLD_CONFIG_BACKUP_FLAG, true)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Recursive function to migrate from the old config
|
|
51
|
-
setOldConfigStoreData(data, _path = '') {
|
|
52
|
-
for (const key in data) {
|
|
53
|
-
const value = data[key];
|
|
54
|
-
const setPath = _path ? _path + '.' + key : key
|
|
55
|
-
|
|
56
|
-
if (typeof (value) == "object") {
|
|
57
|
-
this.setOldConfigStoreData(value, setPath)
|
|
58
|
-
} else {
|
|
59
|
-
this.set(setPath, value)
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
removeOldConfigStoreFile() {
|
|
65
|
-
if (existsSync(oldConfigPath)) {
|
|
66
|
-
unlinkSync(oldConfigPath) // NOTE remove old configstore file
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
private getOldConfig() {
|
|
71
|
-
try {
|
|
72
|
-
return JSON.parse(readFileSync(oldConfigPath, 'utf8'));
|
|
73
|
-
} catch (error) {
|
|
74
|
-
return undefined;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
private fallbackInit(): Conf {
|
|
79
|
-
return new Conf({ configName: CONFIG_NAME, encryptionKey: ENC_KEY })
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
private getObfuscationKey() {
|
|
83
|
-
const obfuscationKeyName = 'obfuscation_key'
|
|
84
|
-
const encConfig = new Conf({ configName: ENC_CONFIG_NAME })
|
|
85
|
-
let obfuscationKey: any = encConfig.get(obfuscationKeyName)
|
|
86
|
-
|
|
87
|
-
if (!obfuscationKey) {
|
|
88
|
-
encConfig.set(obfuscationKeyName, uuid())
|
|
89
|
-
obfuscationKey = encConfig.get(obfuscationKeyName)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return obfuscationKey
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
private getConfigDataAndUnlinkConfigFile(config: Conf) {
|
|
96
|
-
let configData
|
|
97
|
-
|
|
98
|
-
if (config?.path) {
|
|
99
|
-
if (existsSync(config.path)) {
|
|
100
|
-
configData = JSON.parse(JSON.stringify(config?.store || {})) // NOTE convert prototype object to plain object
|
|
101
|
-
unlinkSync(config.path) // NOTE remove old config file
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return configData
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
private getEncryptedConfig(configData?: Record<string, unknown>, skip = false) {
|
|
109
|
-
const getEncryptedDataElseFallBack = () => {
|
|
110
|
-
try {
|
|
111
|
-
// NOTE reading current code base encrypted file if exist
|
|
112
|
-
const encryptionKey: any = this.getObfuscationKey()
|
|
113
|
-
this.config = new Conf({ configName: CONFIG_NAME, encryptionKey })
|
|
114
|
-
|
|
115
|
-
if (Object.keys(configData || {})?.length) {
|
|
116
|
-
this.config.set(configData) // NOTE set config data if passed any
|
|
117
|
-
}
|
|
118
|
-
} catch (error) {
|
|
119
|
-
// NOTE reading old code base encrypted file if exist
|
|
120
|
-
try {
|
|
121
|
-
const config = this.fallbackInit()
|
|
122
|
-
const oldConfigData = this.getConfigDataAndUnlinkConfigFile(config)
|
|
123
|
-
this.getEncryptedConfig(oldConfigData, true)
|
|
124
|
-
} catch (_error) {
|
|
125
|
-
// console.trace(error.message)
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
try {
|
|
131
|
-
if (skip === false) {
|
|
132
|
-
const config = new Conf({ configName: CONFIG_NAME })
|
|
133
|
-
const oldConfigData = this.getConfigDataAndUnlinkConfigFile(config)
|
|
134
|
-
this.getEncryptedConfig(oldConfigData, true)
|
|
135
|
-
} else {
|
|
136
|
-
getEncryptedDataElseFallBack()
|
|
137
|
-
}
|
|
138
|
-
} catch (error) {
|
|
139
|
-
// console.trace(error.message)
|
|
140
|
-
// NOTE reading current code base encrypted file if exist
|
|
141
|
-
getEncryptedDataElseFallBack()
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return this.config
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
private getDecryptedConfig(configData?: Record<string, unknown>) {
|
|
148
|
-
try {
|
|
149
|
-
this.config = new Conf({ configName: CONFIG_NAME })
|
|
150
|
-
|
|
151
|
-
if (Object.keys(configData || {})?.length) {
|
|
152
|
-
this.config.set(configData) // NOTE set config data if passed any
|
|
153
|
-
}
|
|
154
|
-
} catch (error) {
|
|
155
|
-
// console.trace(error.message)
|
|
156
|
-
|
|
157
|
-
try {
|
|
158
|
-
const encryptionKey: any = this.getObfuscationKey()
|
|
159
|
-
let config = new Conf({ configName: CONFIG_NAME, encryptionKey })
|
|
160
|
-
const oldConfigData = this.getConfigDataAndUnlinkConfigFile(config)
|
|
161
|
-
this.getDecryptedConfig(oldConfigData) // NOTE NOTE reinitialize the config with old data and new decrypted file
|
|
162
|
-
} catch (_error) {
|
|
163
|
-
// console.trace(error.message)
|
|
164
|
-
|
|
165
|
-
try {
|
|
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) {
|
|
170
|
-
// console.trace(error.message)
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return this.config
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
get(key): string | any {
|
|
179
|
-
return this.config.get(key);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
async set(key, value) {
|
|
183
|
-
this.config.set(key, value);
|
|
184
|
-
return this.config;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
delete(key) {
|
|
188
|
-
this.config.delete(key);
|
|
189
|
-
return this.config;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
clear() {
|
|
193
|
-
this.config.clear()
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export default new Config();
|
package/src/encrypter.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import crypto from 'crypto';
|
|
2
|
-
|
|
3
|
-
type CryptoConfig = {
|
|
4
|
-
algorithm?: string;
|
|
5
|
-
encryptionKey?: string;
|
|
6
|
-
typeIdentifier?: string;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const defaultValues: CryptoConfig = {
|
|
10
|
-
typeIdentifier: '◈',
|
|
11
|
-
algorithm: 'aes-192-cbc',
|
|
12
|
-
// file deepcode ignore HardcodedNonCryptoSecret: <This is a ToDo>
|
|
13
|
-
encryptionKey: 'nF2ejRQcTv',
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export default class NodeCrypto {
|
|
17
|
-
private readonly key: Buffer;
|
|
18
|
-
private readonly algorithm: string;
|
|
19
|
-
private readonly typeIdentifier: string;
|
|
20
|
-
|
|
21
|
-
constructor(config: CryptoConfig = defaultValues) {
|
|
22
|
-
const { algorithm, encryptionKey, typeIdentifier } = config;
|
|
23
|
-
this.algorithm = algorithm;
|
|
24
|
-
this.typeIdentifier = typeIdentifier;
|
|
25
|
-
this.key = crypto.scryptSync(encryptionKey, 'salt', 24);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
encrypt(plainData) {
|
|
29
|
-
const iv = crypto.randomBytes(16);
|
|
30
|
-
const cipher = crypto.createCipheriv(this.algorithm, this.key, iv);
|
|
31
|
-
let data = plainData;
|
|
32
|
-
|
|
33
|
-
switch (typeof plainData) {
|
|
34
|
-
case 'number':
|
|
35
|
-
data = `${String(plainData)}${this.typeIdentifier}number`;
|
|
36
|
-
break;
|
|
37
|
-
case 'object':
|
|
38
|
-
data = `${JSON.stringify(plainData)}${this.typeIdentifier}object`;
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const encrypted = cipher.update(data, 'utf8', 'hex');
|
|
43
|
-
|
|
44
|
-
return [encrypted + cipher.final('hex'), Buffer.from(iv).toString('hex')].join('|');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
decrypt(encryptedData) {
|
|
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');
|
|
52
|
-
const [data, type] = result.split(this.typeIdentifier);
|
|
53
|
-
|
|
54
|
-
switch (type) {
|
|
55
|
-
case 'number':
|
|
56
|
-
return Number(data);
|
|
57
|
-
case 'object':
|
|
58
|
-
return JSON.parse(data);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return data;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import cliux from './cli-ux';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* checks the deprecation and prints it
|
|
5
|
-
* @param {Array} deprecatedFlags flags to be deprecated
|
|
6
|
-
* @param {String} customMessage [optional] a custom message
|
|
7
|
-
* @returns flag parser
|
|
8
|
-
*/
|
|
9
|
-
export default function (deprecatedFlags = [], suggestions = [], customMessage?: string) {
|
|
10
|
-
return (input, command) => {
|
|
11
|
-
const { context: { flagWarningPrintState = {} } = {} } = command
|
|
12
|
-
let isCommandHasDeprecationFlag = false;
|
|
13
|
-
deprecatedFlags.forEach((item) => {
|
|
14
|
-
if (command.argv.indexOf(item) !== -1) {
|
|
15
|
-
if (flagWarningPrintState[command.id + item]) {
|
|
16
|
-
return input
|
|
17
|
-
}
|
|
18
|
-
flagWarningPrintState[command.id + item] = true
|
|
19
|
-
isCommandHasDeprecationFlag = true;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
if (isCommandHasDeprecationFlag) {
|
|
24
|
-
let depreactionMessage = '';
|
|
25
|
-
if (customMessage) {
|
|
26
|
-
depreactionMessage = customMessage;
|
|
27
|
-
} else {
|
|
28
|
-
depreactionMessage = `WARNING!!! You're using the old (soon to be deprecated) Contentstack CLI flags (${deprecatedFlags.join(
|
|
29
|
-
', ',
|
|
30
|
-
)}).`;
|
|
31
|
-
|
|
32
|
-
if (suggestions.length > 0) {
|
|
33
|
-
depreactionMessage += ` We recommend you to use the updated flags (${suggestions.join(', ')}).`;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
cliux.print(depreactionMessage, { color: 'yellow' });
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return input;
|
|
40
|
-
};
|
|
41
|
-
}
|