|
1 | | -import Command from '../../core/command' |
2 | | -import { flags, FlagInput, managementSDKClient, cliux, printFlagDeprecation } from '@contentstack/cli-utilities' |
3 | | -import buildOutput from '../../core/content-type/audit' |
4 | | -import { getStack, getUsers, getContentType } from '../../utils' |
| 1 | +import Command from "../../core/command"; |
| 2 | +import { |
| 3 | + flags, |
| 4 | + FlagInput, |
| 5 | + managementSDKClient, |
| 6 | + cliux, |
| 7 | + printFlagDeprecation, |
| 8 | +} from "@contentstack/cli-utilities"; |
| 9 | +import buildOutput from "../../core/content-type/audit"; |
| 10 | +import { getStack, getUsers, getContentType } from "../../utils"; |
5 | 11 |
|
6 | 12 | export default class AuditCommand extends Command { |
7 | | - static description = 'Display recent changes to a Content Type' |
| 13 | + static description = "Display recent changes to a Content Type"; |
8 | 14 |
|
9 | 15 | static examples = [ |
10 | 16 | '$ csdx content-type:audit --stack-api-key "xxxxxxxxxxxxxxxxxxx" --content-type "home_page"', |
11 | | - '$ csdx content-type:audit --alias "management token" --content-type "home_page"' |
12 | | - ] |
| 17 | + '$ csdx content-type:audit --alias "management token" --content-type "home_page"', |
| 18 | + ]; |
13 | 19 |
|
14 | 20 | static flags: any = { |
15 | 21 | stack: flags.string({ |
16 | | - char: 's', |
17 | | - description: 'Stack UID', |
18 | | - exclusive: ['token-alias', 'alias'], |
19 | | - parse: printFlagDeprecation(['-s', '--stack'], ['-k', '--stack-api-key']) |
| 22 | + char: "s", |
| 23 | + description: "Stack UID", |
| 24 | + exclusive: ["token-alias", "alias"], |
| 25 | + parse: printFlagDeprecation(["-s", "--stack"], ["-k", "--stack-api-key"]), |
20 | 26 | }), |
21 | 27 |
|
22 | | - 'stack-api-key': flags.string({ |
23 | | - char: 'k', |
24 | | - description: 'Stack API Key', |
25 | | - exclusive: ['token-alias', 'alias'] |
| 28 | + "stack-api-key": flags.string({ |
| 29 | + char: "k", |
| 30 | + description: "Stack API Key", |
| 31 | + exclusive: ["token-alias", "alias"], |
26 | 32 | }), |
27 | 33 |
|
28 | | - 'token-alias': flags.string({ |
29 | | - char: 'a', |
30 | | - description: 'Management token alias', |
31 | | - parse: printFlagDeprecation(['--token-alias'], ['-a', '--alias']) |
| 34 | + "token-alias": flags.string({ |
| 35 | + char: "a", |
| 36 | + description: "Management token alias", |
| 37 | + parse: printFlagDeprecation(["--token-alias"], ["-a", "--alias"]), |
32 | 38 | }), |
33 | 39 |
|
34 | 40 | alias: flags.string({ |
35 | | - char: 'a', |
36 | | - description: 'Alias of the management token' |
| 41 | + char: "a", |
| 42 | + description: "Alias of the management token", |
37 | 43 | }), |
38 | 44 |
|
39 | | - 'content-type': flags.string({ |
40 | | - char: 'c', |
41 | | - description: 'Content Type UID', |
| 45 | + "content-type": flags.string({ |
| 46 | + char: "c", |
| 47 | + description: "Content Type UID", |
42 | 48 | required: true, |
43 | | - parse: printFlagDeprecation(['-c'], ['--content-type']) |
44 | | - }) |
45 | | - } |
| 49 | + parse: printFlagDeprecation(["-c"], ["--content-type"]), |
| 50 | + }), |
| 51 | + }; |
46 | 52 |
|
47 | 53 | async run() { |
48 | 54 | try { |
49 | | - const { flags } = await this.parse(AuditCommand) |
50 | | - this.setup(flags) |
51 | | - |
| 55 | + const { flags } = await this.parse(AuditCommand); |
| 56 | + await this.setup(flags); |
| 57 | + |
52 | 58 | this.contentTypeManagementClient = await managementSDKClient({ |
53 | 59 | host: this.cmaHost, |
54 | | - 'X-CS-CLI': this.context?.analyticsInfo |
55 | | - }) |
| 60 | + "X-CS-CLI": this.context?.analyticsInfo, |
| 61 | + }); |
56 | 62 |
|
57 | | - const spinner = cliux.loaderV2(Command.RequestDataMessage) |
| 63 | + const spinner = cliux.loaderV2(Command.RequestDataMessage); |
58 | 64 | await getContentType({ |
59 | 65 | managementSdk: this.contentTypeManagementClient, |
60 | 66 | apiKey: this.apiKey, |
61 | | - uid: flags['content-type'], |
62 | | - spinner |
| 67 | + uid: flags["content-type"], |
| 68 | + spinner, |
63 | 69 | }); |
64 | 70 | const [stack, audit, users] = await Promise.all([ |
65 | 71 | getStack(this.contentTypeManagementClient, this.apiKey, spinner), |
66 | | - this.client.getContentTypeAuditLogs(this.apiKey, flags['content-type'], spinner), |
67 | | - getUsers(this.contentTypeManagementClient, this.apiKey, spinner) |
68 | | - ]) |
69 | | - cliux.loaderV2('', spinner) |
| 72 | + this.client.getContentTypeAuditLogs( |
| 73 | + this.apiKey, |
| 74 | + flags["content-type"], |
| 75 | + spinner |
| 76 | + ), |
| 77 | + getUsers(this.contentTypeManagementClient, this.apiKey, spinner), |
| 78 | + ]); |
| 79 | + cliux.loaderV2("", spinner); |
70 | 80 |
|
71 | | - const output = buildOutput(audit.logs, users) |
72 | | - this.printOutput(output, 'Audit Logs', flags['content-type'], stack.name) |
| 81 | + const output = buildOutput(audit.logs, users); |
| 82 | + this.printOutput(output, "Audit Logs", flags["content-type"], stack.name); |
73 | 83 | } catch (error: any) { |
74 | | - this.error(error?.message || 'An error occurred.', { exit: 1, suggestions: error.suggestions }) |
| 84 | + this.error(error?.message || "An error occurred.", { |
| 85 | + exit: 1, |
| 86 | + suggestions: error.suggestions, |
| 87 | + }); |
75 | 88 | } |
76 | 89 | } |
77 | 90 | } |
0 commit comments