Skip to content

Commit 4e2d585

Browse files
Merge pull request #118 from contentstack/feat/DX-3858
update implementation of oauth support
2 parents 3ae44d8 + e6fb4a4 commit 4e2d585

File tree

7 files changed

+245
-198
lines changed

7 files changed

+245
-198
lines changed

.talismanrc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ fileignoreconfig:
1111
- filename: src/commands/content-type/audit.ts
1212
checksum: df9f0768c90f8e3a15cd70cbb1765a6c6f0dc5a8e4e7e74e42bfa8ca2ebf3bc9
1313
- filename: src/commands/content-type/details.ts
14-
checksum: 097682096da7632b396aa07074bd65b8c9a955f3bf841267fdf386c7b21e23d2
14+
checksum: db30263b288e1686d1fc8ff593a2e33c727a8d130ca7a943c28277c0985f00ff
1515
- filename: src/commands/content-type/diagram.ts
16-
checksum: bfac9877807cad48faabea9d9e49634eb6a2fe62e97e36114ac70ba469b14ad9
16+
checksum: 276a57c16a4aa434ede1058134517feaf190c9c5db2c12116904daed82996303
1717
- filename: src/commands/content-type/compare.ts
1818
checksum: 2d650febfa3f4671f716e79bb1f6446273046d7041f980733e5ac306a13f447d
1919
- filename: src/commands/content-type/list.ts
20-
checksum: 5b4cff3a06fd66a615facfd3ad6844019bd8d0d819e147370ca8e09420249c85
20+
checksum: e7623d46577a9f5c209fd8d0d5abd0da0a2140f6cce30f68cfe81b29e292585c
2121
- filename: src/commands/content-type/compare-remote.ts
2222
checksum: 151b32699500c465378c4088240c5a25266141150261313434068740862949a1
2323
version: "1.0"

src/commands/content-type/audit.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
managementSDKClient,
55
cliux,
66
printFlagDeprecation,
7-
authenticationHandler,
87
} from "@contentstack/cli-utilities";
98
import buildOutput from "../../core/content-type/audit";
109
import { getStack, getUsers, getContentType } from "../../utils";
@@ -53,20 +52,7 @@ export default class AuditCommand extends Command {
5352
async run() {
5453
try {
5554
const { flags } = await this.parse(AuditCommand);
56-
await authenticationHandler.getAuthDetails();
57-
const authToken = authenticationHandler.accessToken;
58-
if (!authToken) {
59-
this.error(
60-
"You're not logged in. Run auth:login to sign in. Use auth:login --help for more details.",
61-
{
62-
exit: 2,
63-
suggestions: [
64-
"https://www.contentstack.com/docs/developers/cli/authentication/",
65-
],
66-
}
67-
);
68-
}
69-
this.setup(flags, authToken);
55+
await this.setup(flags);
7056

7157
this.contentTypeManagementClient = await managementSDKClient({
7258
host: this.cmaHost,
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
}
Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,101 @@
1-
import Command from '../../core/command'
2-
import { flags, FlagInput, managementSDKClient, cliux, printFlagDeprecation } from '@contentstack/cli-utilities'
3-
import buildOutput from '../../core/content-type/details'
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/details";
10+
import { getStack, getContentType } from "../../utils";
511

612
export default class DetailsCommand extends Command {
7-
static description = 'Display Content Type details'
13+
static description = "Display Content Type details";
814

915
static examples = [
1016
'$ csdx content-type:details --stack-api-key "xxxxxxxxxxxxxxxxxxx" --content-type "home_page"',
1117
'$ csdx content-type:details --alias "management token" --content-type "home_page"',
12-
'$ csdx content-type:details --alias "management token" --content-type "home_page" --no-path'
13-
]
18+
'$ csdx content-type:details --alias "management token" --content-type "home_page" --no-path',
19+
];
1420

1521
static flags: any = {
1622
stack: flags.string({
17-
char: 's',
18-
description: 'Stack UID',
19-
exclusive: ['token-alias'],
20-
parse: printFlagDeprecation(['-s', '--stack'], ['-k', '--stack-api-key'])
23+
char: "s",
24+
description: "Stack UID",
25+
exclusive: ["token-alias"],
26+
parse: printFlagDeprecation(["-s", "--stack"], ["-k", "--stack-api-key"]),
2127
}),
2228

23-
'stack-api-key': flags.string({
24-
char: 'k',
25-
description: 'Stack API Key',
26-
exclusive: ['token-alias']
29+
"stack-api-key": flags.string({
30+
char: "k",
31+
description: "Stack API Key",
32+
exclusive: ["token-alias"],
2733
}),
2834

29-
'token-alias': flags.string({
30-
char: 'a',
31-
description: 'Management token alias',
32-
parse: printFlagDeprecation(['--token-alias'], ['-a', '--alias'])
35+
"token-alias": flags.string({
36+
char: "a",
37+
description: "Management token alias",
38+
parse: printFlagDeprecation(["--token-alias"], ["-a", "--alias"]),
3339
}),
3440

3541
alias: flags.string({
36-
char: 'a',
37-
description: 'Alias of the management token'
42+
char: "a",
43+
description: "Alias of the management token",
3844
}),
3945

40-
'content-type': flags.string({
41-
char: 'c',
42-
description: 'Content Type UID',
46+
"content-type": flags.string({
47+
char: "c",
48+
description: "Content Type UID",
4349
required: true,
44-
parse: printFlagDeprecation(['-c'], ['--content-type'])
50+
parse: printFlagDeprecation(["-c"], ["--content-type"]),
4551
}),
4652

4753
path: flags.boolean({
48-
char: 'p',
49-
description: 'show path column',
54+
char: "p",
55+
description: "show path column",
5056
default: true,
5157
allowNo: true,
52-
parse: printFlagDeprecation(['-p'], ['--path'])
53-
})
54-
}
58+
parse: printFlagDeprecation(["-p"], ["--path"]),
59+
}),
60+
};
5561

5662
async run() {
5763
try {
58-
const { flags } = await this.parse(DetailsCommand)
59-
this.setup(flags)
64+
const { flags } = await this.parse(DetailsCommand);
65+
await this.setup(flags);
6066
this.contentTypeManagementClient = await managementSDKClient({
6167
host: this.cmaHost,
62-
'X-CS-CLI': this.context?.analyticsInfo
63-
})
68+
"X-CS-CLI": this.context?.analyticsInfo,
69+
});
6470

65-
const spinner = cliux.loaderV2(Command.RequestDataMessage)
71+
const spinner = cliux.loaderV2(Command.RequestDataMessage);
6672

6773
const [stack, contentType, references] = await Promise.all([
6874
getStack(this.contentTypeManagementClient, this.apiKey, spinner),
6975
getContentType({
7076
managementSdk: this.contentTypeManagementClient,
7177
apiKey: this.apiKey,
72-
uid: flags['content-type'],
73-
spinner
78+
uid: flags["content-type"],
79+
spinner,
7480
}),
75-
this.client.getContentTypeReferences(this.apiKey, flags['content-type'], spinner)
76-
])
81+
this.client.getContentTypeReferences(
82+
this.apiKey,
83+
flags["content-type"],
84+
spinner
85+
),
86+
]);
7787

78-
cliux.loaderV2('', spinner)
88+
cliux.loaderV2("", spinner);
7989

8090
const output = buildOutput(contentType, references, {
81-
showPath: flags.path
82-
})
83-
this.printOutput(output, 'details', flags['content-type'], stack.name)
91+
showPath: flags.path,
92+
});
93+
this.printOutput(output, "details", flags["content-type"], stack.name);
8494
} catch (error: any) {
85-
this.error(error?.message || 'An error occurred.', { exit: 1, suggestions: error.suggestions })
95+
this.error(error?.message || "An error occurred.", {
96+
exit: 1,
97+
suggestions: error.suggestions,
98+
});
8699
}
87100
}
88101
}

0 commit comments

Comments
 (0)