-
Notifications
You must be signed in to change notification settings - Fork 6
/
new.ts
74 lines (66 loc) · 2.06 KB
/
new.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import {SourceType, SourceVisibility} from '@coveord/platform-client';
import {Command, flags} from '@oclif/command';
import {green} from 'chalk';
import dedent from 'ts-dedent';
import {
buildAnalyticsFailureHook,
buildAnalyticsSuccessHook,
} from '../../../hooks/analytics/analytics';
import {
IsAuthenticated,
Preconditions,
} from '../../../lib/decorators/preconditions';
import {AuthenticatedClient} from '../../../lib/platform/authenticatedClient';
export default class SourcePushNew extends Command {
public static description =
'Create a new push source in a Coveo organization';
public static flags = {
sourceVisibility: flags.enum({
options: [
SourceVisibility.PRIVATE,
SourceVisibility.SECURED,
SourceVisibility.SHARED,
],
description:
'Controls the content security option that should be applied to the items in a source. See https://docs.coveo.com/en/1779/index-content/content-security',
default: SourceVisibility.SECURED,
char: 'v',
}),
};
public static args = [
{
name: 'name',
description: 'The name of the source to create.',
required: true,
},
];
@Preconditions(IsAuthenticated())
public async run() {
const {flags, args} = this.parse(SourcePushNew);
const authenticatedClient = new AuthenticatedClient();
const platformClient = await authenticatedClient.getClient();
const res = await platformClient.source.create({
sourceType: SourceType.PUSH,
pushEnabled: true,
name: args.name,
sourceVisibility: flags.sourceVisibility,
});
this.log(
green(
dedent(
`Source ${args.name} with visibility ${flags.sourceVisibility} has been successfully created.
Id: ${res.id}`
)
)
);
this.config.runHook('analytics', buildAnalyticsSuccessHook(this, flags));
}
public async catch(err?: Error) {
const {flags} = this.parse(SourcePushNew);
await this.config.runHook(
'analytics',
buildAnalyticsFailureHook(this, flags, err)
);
throw err;
}
}