Skip to content

Commit 8ba13c2

Browse files
author
naman-contentstack
committed
add authenticationHandler from utilities
1 parent 32a9903 commit 8ba13c2

File tree

8 files changed

+385
-286
lines changed

8 files changed

+385
-286
lines changed

.talismanrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,16 @@ fileignoreconfig:
88
checksum: 8a91f44817d08d0289f754ff02bd53b106bf89b3a8082bdfe1500a3297f25805
99
- filename: src/core/command.ts
1010
checksum: 9deaa9b6edc6698caf2f469263252b83d4f84b2dde7154d78f6340282d136754
11+
- filename: src/commands/content-type/audit.ts
12+
checksum: df9f0768c90f8e3a15cd70cbb1765a6c6f0dc5a8e4e7e74e42bfa8ca2ebf3bc9
13+
- filename: src/commands/content-type/details.ts
14+
checksum: db30263b288e1686d1fc8ff593a2e33c727a8d130ca7a943c28277c0985f00ff
15+
- filename: src/commands/content-type/diagram.ts
16+
checksum: 276a57c16a4aa434ede1058134517feaf190c9c5db2c12116904daed82996303
17+
- filename: src/commands/content-type/compare.ts
18+
checksum: d618e040ed9f318051094e03f5535051bcea4b8d1b90e3b00339d49f2111f920
19+
- filename: src/commands/content-type/list.ts
20+
checksum: 57c712c12a8d9a911e732593615651ff63ae53298c4f48cdbabdb6de15104331
21+
- filename: src/commands/content-type/compare-remote.ts
22+
checksum: 151b32699500c465378c4088240c5a25266141150261313434068740862949a1
1123
version: "1.0"

src/commands/content-type/audit.ts

Lines changed: 55 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,90 @@
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";
511

612
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";
814

915
static examples = [
1016
'$ 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+
];
1319

1420
static flags: any = {
1521
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"]),
2026
}),
2127

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"],
2632
}),
2733

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"]),
3238
}),
3339

3440
alias: flags.string({
35-
char: 'a',
36-
description: 'Alias of the management token'
41+
char: "a",
42+
description: "Alias of the management token",
3743
}),
3844

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",
4248
required: true,
43-
parse: printFlagDeprecation(['-c'], ['--content-type'])
44-
})
45-
}
49+
parse: printFlagDeprecation(["-c"], ["--content-type"]),
50+
}),
51+
};
4652

4753
async run() {
4854
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+
5258
this.contentTypeManagementClient = await managementSDKClient({
5359
host: this.cmaHost,
54-
'X-CS-CLI': this.context?.analyticsInfo
55-
})
60+
"X-CS-CLI": this.context?.analyticsInfo,
61+
});
5662

57-
const spinner = cliux.loaderV2(Command.RequestDataMessage)
63+
const spinner = cliux.loaderV2(Command.RequestDataMessage);
5864
await getContentType({
5965
managementSdk: this.contentTypeManagementClient,
6066
apiKey: this.apiKey,
61-
uid: flags['content-type'],
62-
spinner
67+
uid: flags["content-type"],
68+
spinner,
6369
});
6470
const [stack, audit, users] = await Promise.all([
6571
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);
7080

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);
7383
} 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+
});
7588
}
7689
}
7790
}
Lines changed: 67 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,106 @@
1-
import Command from '../../core/command'
2-
import { flags, FlagInput, managementSDKClient, cliux, printFlagDeprecation } from '@contentstack/cli-utilities'
3-
import buildOutput from '../../core/content-type/compare'
4-
import { getStack, 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/compare";
10+
import { getStack, getContentType } from "../../utils";
511

612
export default class CompareRemoteCommand extends Command {
7-
static description = 'compare two Content Types on different Stacks'
13+
static description = "compare two Content Types on different Stacks";
814

915
static examples = [
10-
'$ csdx content-type:compare-remote --origin-stack "xxxxxxxxxxxxxxxxxxx" --remote-stack "xxxxxxxxxxxxxxxxxxx" -content-type "home_page"'
11-
]
16+
'$ csdx content-type:compare-remote --origin-stack "xxxxxxxxxxxxxxxxxxx" --remote-stack "xxxxxxxxxxxxxxxxxxx" -content-type "home_page"',
17+
];
1218

1319
static flags: any = {
14-
'origin-stack': flags.string({
15-
char: 'o',
16-
description: 'Origin Stack API Key',
20+
"origin-stack": flags.string({
21+
char: "o",
22+
description: "Origin Stack API Key",
1723
required: true,
18-
dependsOn: ['remote-stack'],
19-
parse: printFlagDeprecation(['-o'], ['--remote-stack'])
24+
dependsOn: ["remote-stack"],
25+
parse: printFlagDeprecation(["-o"], ["--remote-stack"]),
2026
}),
2127

22-
'remote-stack': flags.string({
23-
char: 'r',
24-
description: 'Remote Stack API Key',
28+
"remote-stack": flags.string({
29+
char: "r",
30+
description: "Remote Stack API Key",
2531
required: true,
26-
dependsOn: ['origin-stack'],
27-
parse: printFlagDeprecation(['-r'], ['--remote-stack'])
32+
dependsOn: ["origin-stack"],
33+
parse: printFlagDeprecation(["-r"], ["--remote-stack"]),
2834
}),
2935

30-
'content-type': flags.string({
31-
char: 'c',
32-
description: 'Content Type UID',
36+
"content-type": flags.string({
37+
char: "c",
38+
description: "Content Type UID",
3339
required: true,
34-
parse: printFlagDeprecation(['-c'], ['--content-type'])
35-
})
36-
}
40+
parse: printFlagDeprecation(["-c"], ["--content-type"]),
41+
}),
42+
};
3743

3844
async run() {
3945
try {
40-
const { flags } = await this.parse(CompareRemoteCommand)
41-
this.setup({ alias: undefined, stack: flags['origin-stack'] })
46+
const { flags } = await this.parse(CompareRemoteCommand);
47+
await this.setup({ alias: undefined, stack: flags["origin-stack"] });
4248
this.contentTypeManagementClient = await managementSDKClient({
4349
host: this.cmaHost,
44-
'X-CS-CLI': this.context?.analyticsInfo
45-
})
50+
"X-CS-CLI": this.context?.analyticsInfo,
51+
});
4652

47-
const originStackApi = flags['origin-stack'] as string
48-
const remoteStackApi = flags['remote-stack'] as string
53+
const originStackApi = flags["origin-stack"] as string;
54+
const remoteStackApi = flags["remote-stack"] as string;
4955

5056
if (originStackApi === remoteStackApi) {
51-
this.warn('You cannot compare the same stack. Please choose different stacks to compare.')
57+
this.warn(
58+
"You cannot compare the same stack. Please choose different stacks to compare."
59+
);
5260
}
5361

54-
const spinner = cliux.loaderV2(Command.RequestDataMessage)
62+
const spinner = cliux.loaderV2(Command.RequestDataMessage);
5563

56-
const [originStackResp, remoteStackResp, originContentTypeResp, remoteContentTypeResp] = await Promise.all([
64+
const [
65+
originStackResp,
66+
remoteStackResp,
67+
originContentTypeResp,
68+
remoteContentTypeResp,
69+
] = await Promise.all([
5770
getStack(this.contentTypeManagementClient, originStackApi, spinner),
5871
getStack(this.contentTypeManagementClient, remoteStackApi, spinner),
5972
getContentType({
6073
managementSdk: this.contentTypeManagementClient,
6174
apiKey: originStackApi,
62-
uid: flags['content-type'],
63-
spinner
75+
uid: flags["content-type"],
76+
spinner,
6477
}),
6578
getContentType({
6679
managementSdk: this.contentTypeManagementClient,
6780
apiKey: remoteStackApi,
68-
uid: flags['content-type'],
69-
spinner
70-
})
71-
])
81+
uid: flags["content-type"],
82+
spinner,
83+
}),
84+
]);
7285

73-
cliux.loaderV2('', spinner)
86+
cliux.loaderV2("", spinner);
7487

75-
const output = await buildOutput(flags['content-type'], originContentTypeResp, remoteContentTypeResp)
76-
this.printOutput(output, 'changes', flags['content-type'], `${originStackResp.name} <-> ${remoteStackResp.name}`)
88+
const output = await buildOutput(
89+
flags["content-type"],
90+
originContentTypeResp,
91+
remoteContentTypeResp
92+
);
93+
this.printOutput(
94+
output,
95+
"changes",
96+
flags["content-type"],
97+
`${originStackResp.name} <-> ${remoteStackResp.name}`
98+
);
7799
} catch (error: any) {
78-
this.error(error?.message || 'An error occurred.', { exit: 1, suggestions: error.suggestions })
100+
this.error(error?.message || "An error occurred.", {
101+
exit: 1,
102+
suggestions: error.suggestions,
103+
});
79104
}
80105
}
81106
}

0 commit comments

Comments
 (0)