@contentstack/cli-audit 1.0.0
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/LICENSE +21 -0
- package/README.md +402 -0
- package/bin/dev +5 -0
- package/bin/dev.cmd +3 -0
- package/bin/run +5 -0
- package/bin/run.cmd +3 -0
- package/lib/base-command.d.ts +45 -0
- package/lib/base-command.js +88 -0
- package/lib/commands/cm/stacks/audit/fix.d.ts +8 -0
- package/lib/commands/cm/stacks/audit/fix.js +11 -0
- package/lib/commands/cm/stacks/audit/index.d.ts +62 -0
- package/lib/commands/cm/stacks/audit/index.js +242 -0
- package/lib/config/index.d.ts +28 -0
- package/lib/config/index.js +30 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -0
- package/lib/messages/index.d.ts +33 -0
- package/lib/messages/index.js +46 -0
- package/lib/modules/content-types.d.ts +96 -0
- package/lib/modules/content-types.js +209 -0
- package/lib/modules/entries.d.ts +121 -0
- package/lib/modules/entries.js +288 -0
- package/lib/modules/global-fields.d.ts +27 -0
- package/lib/modules/global-fields.js +43 -0
- package/lib/modules/index.d.ts +4 -0
- package/lib/modules/index.js +10 -0
- package/lib/types/content-types.d.ts +69 -0
- package/lib/types/content-types.js +12 -0
- package/lib/types/entries.d.ts +46 -0
- package/lib/types/entries.js +2 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/index.js +6 -0
- package/lib/types/utils.d.ts +18 -0
- package/lib/types/utils.js +2 -0
- package/lib/util/index.d.ts +1 -0
- package/lib/util/index.js +8 -0
- package/lib/util/log.d.ts +42 -0
- package/lib/util/log.js +153 -0
- package/oclif.manifest.json +134 -0
- package/package.json +85 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const content_types_1 = tslib_1.__importDefault(require("./content-types"));
|
|
5
|
+
class GlobalField extends content_types_1.default {
|
|
6
|
+
/**
|
|
7
|
+
* The above function is an asynchronous function that runs a validation and returns any missing
|
|
8
|
+
* references.
|
|
9
|
+
* @returns the value of the variable `missingRefs`.
|
|
10
|
+
*/
|
|
11
|
+
async run() {
|
|
12
|
+
// NOTE add any validation if required
|
|
13
|
+
const missingRefs = await super.run();
|
|
14
|
+
return missingRefs;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The function validates a field containing modular blocks by traversing each block and checking for
|
|
18
|
+
* references in a given tree.
|
|
19
|
+
* @param {Record<string, unknown>[]} tree - The `tree` parameter is an array of objects that
|
|
20
|
+
* represents a tree structure. Each object in the array represents a node in the tree.
|
|
21
|
+
* @param {ModularBlocksDataType} field - The `field` parameter is of type `ModularBlocksDataType`.
|
|
22
|
+
*/
|
|
23
|
+
async validateModularBlocksField(tree, field) {
|
|
24
|
+
const { blocks } = field;
|
|
25
|
+
// NOTE Traverse each and every module and look for reference
|
|
26
|
+
for (const block of blocks) {
|
|
27
|
+
await this.lookForReference(tree, block);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The function "validateGroupField" performs group field validation by looking for a reference in a
|
|
32
|
+
* tree structure.
|
|
33
|
+
* @param {Record<string, unknown>[]} tree - The `tree` parameter is an array of objects representing
|
|
34
|
+
* a tree structure. Each object in the array represents a node in the tree and has properties like
|
|
35
|
+
* `uid` and `name`.
|
|
36
|
+
* @param {GroupFieldDataType} field - The `field` parameter is of type `GroupFieldDataType`.
|
|
37
|
+
*/
|
|
38
|
+
async validateGroupField(tree, field) {
|
|
39
|
+
// NOTE Any Group Field related logic can be added here (Ex data serialization or picking any metadata for report etc.,)
|
|
40
|
+
await this.lookForReference([...tree, { uid: field.uid, name: field.display_name }], field);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.default = GlobalField;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContentType = exports.GlobalField = exports.Entries = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const entries_1 = tslib_1.__importDefault(require("./entries"));
|
|
6
|
+
exports.Entries = entries_1.default;
|
|
7
|
+
const global_fields_1 = tslib_1.__importDefault(require("./global-fields"));
|
|
8
|
+
exports.GlobalField = global_fields_1.default;
|
|
9
|
+
const content_types_1 = tslib_1.__importDefault(require("./content-types"));
|
|
10
|
+
exports.ContentType = content_types_1.default;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import config from '../config';
|
|
2
|
+
import { ConfigType, LogFn } from './utils';
|
|
3
|
+
type ContentTypeStruct = {
|
|
4
|
+
uid: string;
|
|
5
|
+
title: string;
|
|
6
|
+
description: string;
|
|
7
|
+
schema?: (ReferenceFieldDataType | GlobalFieldDataType | CustomFieldDataType | JsonRTEFieldDataType | GroupFieldDataType | ModularBlocksDataType)[];
|
|
8
|
+
};
|
|
9
|
+
type ModuleConstructorParam = {
|
|
10
|
+
log: LogFn;
|
|
11
|
+
config: ConfigType;
|
|
12
|
+
moduleName?: keyof typeof config.moduleConfig;
|
|
13
|
+
};
|
|
14
|
+
type CtConstructorParam = {
|
|
15
|
+
gfSchema: ContentTypeStruct[] | [];
|
|
16
|
+
ctSchema: ContentTypeStruct[] | [];
|
|
17
|
+
};
|
|
18
|
+
type CommonDataTypeStruct = {
|
|
19
|
+
uid: string;
|
|
20
|
+
data_type: string;
|
|
21
|
+
display_name: string;
|
|
22
|
+
field_metadata: {
|
|
23
|
+
extension: boolean;
|
|
24
|
+
ref_multiple: boolean;
|
|
25
|
+
allow_json_rte: boolean;
|
|
26
|
+
} & Record<string, unknown>;
|
|
27
|
+
};
|
|
28
|
+
type RefErrorReturnType = {
|
|
29
|
+
name: string;
|
|
30
|
+
ct_uid: string;
|
|
31
|
+
treeStr: string;
|
|
32
|
+
data_type: string;
|
|
33
|
+
missingRefs: string[];
|
|
34
|
+
display_name: string;
|
|
35
|
+
tree: Record<string, unknown>[];
|
|
36
|
+
};
|
|
37
|
+
type ReferenceFieldDataType = CommonDataTypeStruct & {
|
|
38
|
+
reference_to: string[];
|
|
39
|
+
};
|
|
40
|
+
type GlobalFieldDataType = CommonDataTypeStruct & {
|
|
41
|
+
reference_to: string;
|
|
42
|
+
schema: GlobalFieldSchemaTypes[];
|
|
43
|
+
};
|
|
44
|
+
type CustomFieldDataType = CommonDataTypeStruct & {};
|
|
45
|
+
type JsonRTEFieldDataType = CommonDataTypeStruct & {
|
|
46
|
+
reference_to: string[];
|
|
47
|
+
};
|
|
48
|
+
type GroupFieldDataType = CommonDataTypeStruct & {
|
|
49
|
+
schema: GroupFieldSchemaTypes[];
|
|
50
|
+
};
|
|
51
|
+
type ModularBlockType = {
|
|
52
|
+
uid: string;
|
|
53
|
+
title: string;
|
|
54
|
+
schema: (JsonRTEFieldDataType | ModularBlocksDataType | ReferenceFieldDataType | CustomFieldDataType | GroupFieldDataType)[];
|
|
55
|
+
};
|
|
56
|
+
type ModularBlocksDataType = CommonDataTypeStruct & {
|
|
57
|
+
blocks: ModularBlockType[];
|
|
58
|
+
};
|
|
59
|
+
type GroupFieldSchemaTypes = GroupFieldDataType | CommonDataTypeStruct | GlobalFieldDataType | ReferenceFieldDataType;
|
|
60
|
+
type GlobalFieldSchemaTypes = ReferenceFieldDataType | GroupFieldDataType | CustomFieldDataType;
|
|
61
|
+
type ModularBlocksSchemaTypes = ReferenceFieldDataType | JsonRTEFieldDataType;
|
|
62
|
+
declare enum OutputColumn {
|
|
63
|
+
Title = "name",
|
|
64
|
+
'Field name' = "display_name",
|
|
65
|
+
'Field type' = "data_type",
|
|
66
|
+
'Missing references' = "missingRefs",
|
|
67
|
+
Path = "treeStr"
|
|
68
|
+
}
|
|
69
|
+
export { CtConstructorParam, ContentTypeStruct, ModuleConstructorParam, ReferenceFieldDataType, GlobalFieldDataType, CustomFieldDataType, JsonRTEFieldDataType, GroupFieldDataType, ModularBlocksDataType, RefErrorReturnType, ModularBlocksSchemaTypes, ModularBlockType, OutputColumn, };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OutputColumn = void 0;
|
|
4
|
+
var OutputColumn;
|
|
5
|
+
(function (OutputColumn) {
|
|
6
|
+
OutputColumn["Title"] = "name";
|
|
7
|
+
OutputColumn["Field name"] = "display_name";
|
|
8
|
+
OutputColumn["Field type"] = "data_type";
|
|
9
|
+
OutputColumn["Missing references"] = "missingRefs";
|
|
10
|
+
OutputColumn["Path"] = "treeStr";
|
|
11
|
+
})(OutputColumn || (OutputColumn = {}));
|
|
12
|
+
exports.OutputColumn = OutputColumn;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
type Locale = {
|
|
2
|
+
uid: string;
|
|
3
|
+
code: string;
|
|
4
|
+
name: string;
|
|
5
|
+
fallback_locale: string | null;
|
|
6
|
+
};
|
|
7
|
+
type EntryStruct = {
|
|
8
|
+
uid: string;
|
|
9
|
+
title: string;
|
|
10
|
+
} & {
|
|
11
|
+
[key: string]: EntryReferenceFieldDataType[] | EntryGlobalFieldDataType | EntryJsonRTEFieldDataType | EntryGroupFieldDataType | EntryModularBlocksDataType[];
|
|
12
|
+
};
|
|
13
|
+
type EntryReferenceFieldDataType = {
|
|
14
|
+
uid: string;
|
|
15
|
+
_content_type_uid: string;
|
|
16
|
+
};
|
|
17
|
+
type EntryGlobalFieldDataType = {
|
|
18
|
+
[key: string]: EntryStruct;
|
|
19
|
+
};
|
|
20
|
+
type EntryCustomFieldDataType = {
|
|
21
|
+
[key: string]: EntryStruct;
|
|
22
|
+
};
|
|
23
|
+
type EntryJsonRTEFieldDataType = {
|
|
24
|
+
uid: string;
|
|
25
|
+
attrs: Record<string, any>;
|
|
26
|
+
children: EntryJsonRTEFieldDataType[];
|
|
27
|
+
};
|
|
28
|
+
type EntryGroupFieldDataType = {
|
|
29
|
+
[key: string]: EntryReferenceFieldDataType[] | EntryGlobalFieldDataType | EntryJsonRTEFieldDataType;
|
|
30
|
+
};
|
|
31
|
+
type EntryModularBlockType = {
|
|
32
|
+
[key: string]: EntryJsonRTEFieldDataType | EntryModularBlocksDataType | EntryReferenceFieldDataType[] | EntryGroupFieldDataType;
|
|
33
|
+
};
|
|
34
|
+
type EntryModularBlocksDataType = {
|
|
35
|
+
[key: string]: EntryModularBlockType;
|
|
36
|
+
};
|
|
37
|
+
type EntryRefErrorReturnType = {
|
|
38
|
+
name: string;
|
|
39
|
+
uid: string;
|
|
40
|
+
treeStr: string;
|
|
41
|
+
data_type: string;
|
|
42
|
+
missingRefs: string[] | Record<string, unknown>[];
|
|
43
|
+
display_name: string;
|
|
44
|
+
tree: Record<string, unknown>[];
|
|
45
|
+
};
|
|
46
|
+
export { Locale, EntryStruct, EntryGlobalFieldDataType, EntryCustomFieldDataType, EntryJsonRTEFieldDataType, EntryGroupFieldDataType, EntryModularBlocksDataType, EntryReferenceFieldDataType, EntryRefErrorReturnType, };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./utils"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./entries"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./content-types"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Color } from "chalk";
|
|
2
|
+
import { PrintOptions } from "@contentstack/cli-utilities";
|
|
3
|
+
import config from "../config";
|
|
4
|
+
type LogFn = (message: string | any, logType?: LoggerType | PrintOptions | undefined) => void;
|
|
5
|
+
type ExitFn = (code?: number | undefined) => void;
|
|
6
|
+
type Partial<T> = {
|
|
7
|
+
[P in keyof T]?: T[P];
|
|
8
|
+
};
|
|
9
|
+
type ConfigType = {
|
|
10
|
+
config?: string;
|
|
11
|
+
} & typeof config & Record<string, any>;
|
|
12
|
+
export { LogFn, ExitFn, Partial, ConfigType };
|
|
13
|
+
export type LoggerType = "info" | "warn" | "error" | "debug";
|
|
14
|
+
export type PrintType = {
|
|
15
|
+
message: string;
|
|
16
|
+
bold?: boolean;
|
|
17
|
+
color?: typeof Color;
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Logger } from "./log";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Logger = void 0;
|
|
7
|
+
var log_1 = require("./log");
|
|
8
|
+
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return __importDefault(log_1).default; } });
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import winston from 'winston';
|
|
2
|
+
import { PrintOptions } from '@contentstack/cli-utilities';
|
|
3
|
+
import { LoggerType, PrintType } from '../types';
|
|
4
|
+
export default class Logger {
|
|
5
|
+
private infoLogger;
|
|
6
|
+
private errorLogger;
|
|
7
|
+
private config;
|
|
8
|
+
get loggerOptions(): winston.transports.FileTransportOptions;
|
|
9
|
+
constructor(config: Record<string, any>);
|
|
10
|
+
/**
|
|
11
|
+
* The function getLoggerInstance creates and returns a winston logger instance based on the provided
|
|
12
|
+
* log type.
|
|
13
|
+
* @param {LoggerType} logType - The `logType` parameter is a string that represents the type of log.
|
|
14
|
+
* It can have one of the following values: "error", "info", "debug", "warn", or any other custom log
|
|
15
|
+
* type.
|
|
16
|
+
* @returns an instance of the winston.Logger class.
|
|
17
|
+
*/
|
|
18
|
+
getLoggerInstance(logType: LoggerType): winston.Logger;
|
|
19
|
+
/**
|
|
20
|
+
* The function `log` takes a message and an optional log type, and logs the message using different
|
|
21
|
+
* loggers based on the log type.
|
|
22
|
+
* @param {string | any} message - The `message` parameter is a string or any type of value that you
|
|
23
|
+
* want to log. It represents the content of the log message that you want to display.
|
|
24
|
+
* @param {LoggerType | PrintOptions | undefined} [logType] - The `logType` parameter is an optional
|
|
25
|
+
* parameter that specifies the type of log. It can be one of the following values:
|
|
26
|
+
*/
|
|
27
|
+
log(message: string | any, logType?: LoggerType | PrintOptions | undefined): void;
|
|
28
|
+
/**
|
|
29
|
+
* The function `returnString` takes a message as input and returns a modified version of the message
|
|
30
|
+
* with sensitive credentials replaced and any ANSI escape codes removed.
|
|
31
|
+
* @param {any} message - The `message` parameter can be of any type. It can be a string, an object, or
|
|
32
|
+
* an array.
|
|
33
|
+
* @returns a string.
|
|
34
|
+
*/
|
|
35
|
+
returnString(message: any): string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The `print` function takes an array of `PrintType` objects, formats the messages using the `chalk`
|
|
39
|
+
* library for styling, and prints the formatted messages using the `ux.print` function.
|
|
40
|
+
* @param printInput - An array of objects with the following properties:
|
|
41
|
+
*/
|
|
42
|
+
export declare function print(printInput: Array<PrintType>): void;
|
package/lib/util/log.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.print = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const map_1 = tslib_1.__importDefault(require("lodash/map"));
|
|
6
|
+
const winston_1 = tslib_1.__importDefault(require("winston"));
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
9
|
+
const replace_1 = tslib_1.__importDefault(require("lodash/replace"));
|
|
10
|
+
const isObject_1 = tslib_1.__importDefault(require("lodash/isObject"));
|
|
11
|
+
const path_1 = require("path");
|
|
12
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
13
|
+
const ansiRegexPattern = [
|
|
14
|
+
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
|
|
15
|
+
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))',
|
|
16
|
+
].join('|');
|
|
17
|
+
const customLevels = {
|
|
18
|
+
levels: {
|
|
19
|
+
warn: 1,
|
|
20
|
+
info: 2,
|
|
21
|
+
debug: 3,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
/* The Logger class is a TypeScript class that provides logging functionality with different log levels
|
|
25
|
+
and options. */
|
|
26
|
+
class Logger {
|
|
27
|
+
get loggerOptions() {
|
|
28
|
+
return {
|
|
29
|
+
filename: '',
|
|
30
|
+
maxFiles: 20,
|
|
31
|
+
tailable: true,
|
|
32
|
+
maxsize: 1000000,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
constructor(config) {
|
|
36
|
+
this.config = config;
|
|
37
|
+
this.infoLogger = this.getLoggerInstance('info');
|
|
38
|
+
this.errorLogger = this.getLoggerInstance('error');
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The function getLoggerInstance creates and returns a winston logger instance based on the provided
|
|
42
|
+
* log type.
|
|
43
|
+
* @param {LoggerType} logType - The `logType` parameter is a string that represents the type of log.
|
|
44
|
+
* It can have one of the following values: "error", "info", "debug", "warn", or any other custom log
|
|
45
|
+
* type.
|
|
46
|
+
* @returns an instance of the winston.Logger class.
|
|
47
|
+
*/
|
|
48
|
+
getLoggerInstance(logType) {
|
|
49
|
+
const consoleOptions = {
|
|
50
|
+
format: winston_1.default.format.combine(winston_1.default.format.simple(), winston_1.default.format.colorize({ all: true })),
|
|
51
|
+
};
|
|
52
|
+
if (logType === 'error') {
|
|
53
|
+
consoleOptions.level = logType;
|
|
54
|
+
}
|
|
55
|
+
if ((0, fs_1.existsSync)(this.config.basePath)) {
|
|
56
|
+
const filename = (0, path_1.normalize)((0, path_1.resolve)(this.config.basePath, 'logs', `${logType}.log`)).replace(/^(\.\.(\/|\\|$))+/, '');
|
|
57
|
+
const loggerOptions = {
|
|
58
|
+
transports: [
|
|
59
|
+
new winston_1.default.transports.File(Object.assign(Object.assign({}, this.loggerOptions), { level: logType, filename })),
|
|
60
|
+
new winston_1.default.transports.Console(consoleOptions),
|
|
61
|
+
],
|
|
62
|
+
levels: customLevels.levels,
|
|
63
|
+
};
|
|
64
|
+
if (logType === 'error') {
|
|
65
|
+
loggerOptions.levels = { error: 0 };
|
|
66
|
+
}
|
|
67
|
+
return winston_1.default.createLogger(loggerOptions);
|
|
68
|
+
}
|
|
69
|
+
winston_1.default
|
|
70
|
+
.createLogger({
|
|
71
|
+
transports: [new winston_1.default.transports.Console(consoleOptions)],
|
|
72
|
+
})
|
|
73
|
+
.error('Provided base path is not valid');
|
|
74
|
+
throw new Error('Provided base path is not valid');
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The function `log` takes a message and an optional log type, and logs the message using different
|
|
78
|
+
* loggers based on the log type.
|
|
79
|
+
* @param {string | any} message - The `message` parameter is a string or any type of value that you
|
|
80
|
+
* want to log. It represents the content of the log message that you want to display.
|
|
81
|
+
* @param {LoggerType | PrintOptions | undefined} [logType] - The `logType` parameter is an optional
|
|
82
|
+
* parameter that specifies the type of log. It can be one of the following values:
|
|
83
|
+
*/
|
|
84
|
+
log(message, logType) {
|
|
85
|
+
const logString = this.returnString(message);
|
|
86
|
+
switch (logType) {
|
|
87
|
+
case 'info':
|
|
88
|
+
case 'debug':
|
|
89
|
+
case 'warn':
|
|
90
|
+
this.infoLogger.log(logType, logString);
|
|
91
|
+
break;
|
|
92
|
+
case 'error':
|
|
93
|
+
this.errorLogger.error(logString);
|
|
94
|
+
break;
|
|
95
|
+
default:
|
|
96
|
+
cli_utilities_1.cliux.print(logString, logType || {});
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The function `returnString` takes a message as input and returns a modified version of the message
|
|
102
|
+
* with sensitive credentials replaced and any ANSI escape codes removed.
|
|
103
|
+
* @param {any} message - The `message` parameter can be of any type. It can be a string, an object, or
|
|
104
|
+
* an array.
|
|
105
|
+
* @returns a string.
|
|
106
|
+
*/
|
|
107
|
+
returnString(message) {
|
|
108
|
+
let returnStr = '';
|
|
109
|
+
const replaceCredentials = (item) => {
|
|
110
|
+
try {
|
|
111
|
+
return JSON.stringify(item).replace(/authtoken":"abc................/g, 'authtoken":"abc....');
|
|
112
|
+
}
|
|
113
|
+
catch (error) { }
|
|
114
|
+
return item;
|
|
115
|
+
};
|
|
116
|
+
if (Array.isArray(message) && message.length) {
|
|
117
|
+
returnStr = (0, map_1.default)(message, (item) => {
|
|
118
|
+
if (item && typeof item === 'object') {
|
|
119
|
+
return replaceCredentials(item);
|
|
120
|
+
}
|
|
121
|
+
return item;
|
|
122
|
+
})
|
|
123
|
+
.join(' ')
|
|
124
|
+
.trim();
|
|
125
|
+
}
|
|
126
|
+
else if ((0, isObject_1.default)(message)) {
|
|
127
|
+
return replaceCredentials(message);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
returnStr = message;
|
|
131
|
+
}
|
|
132
|
+
returnStr = (0, replace_1.default)(returnStr, new RegExp(ansiRegexPattern, 'g'), '').trim();
|
|
133
|
+
return returnStr;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.default = Logger;
|
|
137
|
+
/**
|
|
138
|
+
* The `print` function takes an array of `PrintType` objects, formats the messages using the `chalk`
|
|
139
|
+
* library for styling, and prints the formatted messages using the `ux.print` function.
|
|
140
|
+
* @param printInput - An array of objects with the following properties:
|
|
141
|
+
*/
|
|
142
|
+
function print(printInput) {
|
|
143
|
+
const str = (0, map_1.default)(printInput, ({ message, bold, color }) => {
|
|
144
|
+
let chalkFn = chalk_1.default;
|
|
145
|
+
if (color)
|
|
146
|
+
chalkFn = chalkFn[color];
|
|
147
|
+
if (bold)
|
|
148
|
+
chalkFn = chalkFn.bold;
|
|
149
|
+
return chalkFn(message);
|
|
150
|
+
}).join(' ');
|
|
151
|
+
cli_utilities_1.cliux.print(str);
|
|
152
|
+
}
|
|
153
|
+
exports.print = print;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "1.0.0",
|
|
3
|
+
"commands": {
|
|
4
|
+
"cm:stacks:audit:fix": {
|
|
5
|
+
"id": "cm:stacks:audit:fix",
|
|
6
|
+
"description": "Audit fix command",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"pluginName": "@contentstack/cli-audit",
|
|
9
|
+
"pluginAlias": "@contentstack/cli-audit",
|
|
10
|
+
"pluginType": "core",
|
|
11
|
+
"aliases": [
|
|
12
|
+
"cm::stacks:audit:fix"
|
|
13
|
+
],
|
|
14
|
+
"examples": [
|
|
15
|
+
"$ <%= config.bin %> <%= command.id %>"
|
|
16
|
+
],
|
|
17
|
+
"flags": {
|
|
18
|
+
"config": {
|
|
19
|
+
"name": "config",
|
|
20
|
+
"type": "option",
|
|
21
|
+
"char": "c",
|
|
22
|
+
"description": "Path of the external config.",
|
|
23
|
+
"multiple": false
|
|
24
|
+
},
|
|
25
|
+
"data-dir": {
|
|
26
|
+
"name": "data-dir",
|
|
27
|
+
"type": "option",
|
|
28
|
+
"char": "d",
|
|
29
|
+
"description": "Path where the data is stored.",
|
|
30
|
+
"multiple": false
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"args": {}
|
|
34
|
+
},
|
|
35
|
+
"cm:stacks:audit": {
|
|
36
|
+
"id": "cm:stacks:audit",
|
|
37
|
+
"description": "Perform audits and find possible errors in the exported Contentstack data",
|
|
38
|
+
"strict": true,
|
|
39
|
+
"pluginName": "@contentstack/cli-audit",
|
|
40
|
+
"pluginAlias": "@contentstack/cli-audit",
|
|
41
|
+
"pluginType": "core",
|
|
42
|
+
"aliases": [
|
|
43
|
+
"cm:stacks:audit"
|
|
44
|
+
],
|
|
45
|
+
"examples": [
|
|
46
|
+
"$ <%= config.bin %> <%= command.id %>",
|
|
47
|
+
"$ <%= config.bin %> <%= command.id %> --report-path=<path>",
|
|
48
|
+
"$ <%= config.bin %> <%= command.id %> --report-path=<path> --csv",
|
|
49
|
+
"$ <%= config.bin %> <%= command.id %> --report-path=<path> --filter=\"name=<filter-value>\"",
|
|
50
|
+
"$ <%= config.bin %> <%= command.id %> --report-path=<path> --modules=content-types --filter=\"name=\"<filter-value>\""
|
|
51
|
+
],
|
|
52
|
+
"flags": {
|
|
53
|
+
"config": {
|
|
54
|
+
"name": "config",
|
|
55
|
+
"type": "option",
|
|
56
|
+
"char": "c",
|
|
57
|
+
"description": "Path of the external config.",
|
|
58
|
+
"multiple": false
|
|
59
|
+
},
|
|
60
|
+
"data-dir": {
|
|
61
|
+
"name": "data-dir",
|
|
62
|
+
"type": "option",
|
|
63
|
+
"char": "d",
|
|
64
|
+
"description": "Path where the data is stored.",
|
|
65
|
+
"multiple": false
|
|
66
|
+
},
|
|
67
|
+
"report-path": {
|
|
68
|
+
"name": "report-path",
|
|
69
|
+
"type": "option",
|
|
70
|
+
"description": "Path to store the audit reports.",
|
|
71
|
+
"multiple": false
|
|
72
|
+
},
|
|
73
|
+
"reference-only": {
|
|
74
|
+
"name": "reference-only",
|
|
75
|
+
"type": "boolean",
|
|
76
|
+
"description": "Checks only for missing references.",
|
|
77
|
+
"hidden": true,
|
|
78
|
+
"allowNo": false
|
|
79
|
+
},
|
|
80
|
+
"modules": {
|
|
81
|
+
"name": "modules",
|
|
82
|
+
"type": "option",
|
|
83
|
+
"description": "Provide the list of modules to be audited.",
|
|
84
|
+
"multiple": true,
|
|
85
|
+
"options": [
|
|
86
|
+
"content-types",
|
|
87
|
+
"global-fields",
|
|
88
|
+
"entries"
|
|
89
|
+
]
|
|
90
|
+
},
|
|
91
|
+
"columns": {
|
|
92
|
+
"name": "columns",
|
|
93
|
+
"type": "option",
|
|
94
|
+
"description": "only show provided columns (comma-separated)",
|
|
95
|
+
"multiple": false,
|
|
96
|
+
"exclusive": [
|
|
97
|
+
"extended"
|
|
98
|
+
]
|
|
99
|
+
},
|
|
100
|
+
"sort": {
|
|
101
|
+
"name": "sort",
|
|
102
|
+
"type": "option",
|
|
103
|
+
"description": "property to sort by (prepend '-' for descending)",
|
|
104
|
+
"multiple": false
|
|
105
|
+
},
|
|
106
|
+
"filter": {
|
|
107
|
+
"name": "filter",
|
|
108
|
+
"type": "option",
|
|
109
|
+
"description": "filter property by partial string matching, ex: name=foo",
|
|
110
|
+
"multiple": false
|
|
111
|
+
},
|
|
112
|
+
"csv": {
|
|
113
|
+
"name": "csv",
|
|
114
|
+
"type": "boolean",
|
|
115
|
+
"description": "output is csv format [alias: --output=csv]",
|
|
116
|
+
"allowNo": false,
|
|
117
|
+
"exclusive": [
|
|
118
|
+
"no-truncate"
|
|
119
|
+
]
|
|
120
|
+
},
|
|
121
|
+
"no-truncate": {
|
|
122
|
+
"name": "no-truncate",
|
|
123
|
+
"type": "boolean",
|
|
124
|
+
"description": "do not truncate output to fit screen",
|
|
125
|
+
"allowNo": false,
|
|
126
|
+
"exclusive": [
|
|
127
|
+
"csv"
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
"args": {}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@contentstack/cli-audit",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Contentstack audit plugin",
|
|
5
|
+
"author": "Contentstack CLI",
|
|
6
|
+
"homepage": "https://github.com/contentstack/cli",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"main": "./lib/index.js",
|
|
9
|
+
"types": "./lib/index.d.ts",
|
|
10
|
+
"bin": {
|
|
11
|
+
"audit": "./bin/run"
|
|
12
|
+
},
|
|
13
|
+
"repository": "contentstack/audit",
|
|
14
|
+
"files": [
|
|
15
|
+
"/bin",
|
|
16
|
+
"/lib",
|
|
17
|
+
"/npm-shrinkwrap.json",
|
|
18
|
+
"/oclif.manifest.json"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@contentstack/cli-command": "~1.2.11",
|
|
22
|
+
"@contentstack/cli-utilities": "~1.5.1",
|
|
23
|
+
"@oclif/plugin-help": "^5.2.20",
|
|
24
|
+
"@oclif/plugin-plugins": "^3.8.4",
|
|
25
|
+
"chalk": "^4.1.2",
|
|
26
|
+
"fast-csv": "^4.3.6",
|
|
27
|
+
"lodash": "^4.17.21",
|
|
28
|
+
"winston": "^3.9.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@oclif/test": "^2.0.3",
|
|
32
|
+
"@types/chai": "^4.3.5",
|
|
33
|
+
"@types/node": "^20.3.1",
|
|
34
|
+
"chai": "^4.3.7",
|
|
35
|
+
"eslint": "^8.43.0",
|
|
36
|
+
"eslint-config-oclif": "^4.0.0",
|
|
37
|
+
"eslint-config-oclif-typescript": "^1.0.3",
|
|
38
|
+
"mocha": "^10.2.0",
|
|
39
|
+
"nyc": "^15.1.0",
|
|
40
|
+
"oclif": "^3.10.0",
|
|
41
|
+
"shx": "^0.3.4",
|
|
42
|
+
"ts-node": "^10.9.1",
|
|
43
|
+
"tslib": "^2.5.3",
|
|
44
|
+
"typescript": "^5.1.3"
|
|
45
|
+
},
|
|
46
|
+
"oclif": {
|
|
47
|
+
"bin": "csdx",
|
|
48
|
+
"commands": "./lib/commands",
|
|
49
|
+
"plugins": [
|
|
50
|
+
"@oclif/plugin-help",
|
|
51
|
+
"@oclif/plugin-plugins"
|
|
52
|
+
],
|
|
53
|
+
"topicSeparator": ":",
|
|
54
|
+
"additionalHelpFlags": [
|
|
55
|
+
"-h"
|
|
56
|
+
],
|
|
57
|
+
"additionalVersionFlags": [
|
|
58
|
+
"-v"
|
|
59
|
+
],
|
|
60
|
+
"topics": {
|
|
61
|
+
"cm:stacks:audit": {
|
|
62
|
+
"description": "Audit and find possible refrence errors in the exported data"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"repositoryPrefix": "<%- repo %>/blob/main/packages/contentstack-audit/<%- commandPath %>"
|
|
66
|
+
},
|
|
67
|
+
"scripts": {
|
|
68
|
+
"build": "npm run clean && shx rm -rf lib && tsc -b",
|
|
69
|
+
"lint": "eslint . --ext .ts --config .eslintrc",
|
|
70
|
+
"postpack": "shx rm -f oclif.manifest.json",
|
|
71
|
+
"posttest": "npm run lint",
|
|
72
|
+
"prepack": "npm run build && oclif manifest && oclif readme",
|
|
73
|
+
"test": "mocha --forbid-only \"test/**/*.test.ts\"",
|
|
74
|
+
"version": "oclif readme && git add README.md",
|
|
75
|
+
"clean": "rm -rf ./lib ./node_modules tsconfig.tsbuildinfo oclif.manifest.json",
|
|
76
|
+
"test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\""
|
|
77
|
+
},
|
|
78
|
+
"engines": {
|
|
79
|
+
"node": ">=16"
|
|
80
|
+
},
|
|
81
|
+
"bugs": "https://github.com/contentstack/cli/issues",
|
|
82
|
+
"keywords": [
|
|
83
|
+
"oclif"
|
|
84
|
+
]
|
|
85
|
+
}
|