1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const command_1 = require("@oclif/command");
|
5 |
|
6 | const suggest = require("inquirer-prompt-suggest");
|
7 | const base_command_1 = require("../../base-command");
|
8 | const commands_1 = require("../../utils/commands");
|
9 | const decorators_1 = require("../../utils/decorators");
|
10 | const prompts_1 = require("../../utils/prompts");
|
11 | const inquirer = require("inquirer");
|
12 | class IntegrationsCreate extends base_command_1.default {
|
13 | async run() {
|
14 | const { flags } = this.parse(IntegrationsCreate);
|
15 | const name = flags.name || (await this.askForName());
|
16 | const description = flags.description || (await prompts_1.askForString('Description (optional)'));
|
17 | try {
|
18 | const { data } = await this.devPortalClient.request({
|
19 | query: MUTATION,
|
20 | variables: { name, description }
|
21 | });
|
22 | if (data.data) {
|
23 | const { integration } = data.data.createIntegration;
|
24 | this.success('Integration successfully created');
|
25 | this.log(' name: %s\n uuid: %s\n Url:', integration.name, integration.uuid, `${this.constants.DeveloperPortalUrl}integrations/${integration.uuid}`);
|
26 | if (this.isIntegrationLocation) {
|
27 |
|
28 | if (!flags.skipLink) {
|
29 | await commands_1.linkIntegration.bind(this)(integration.uuid);
|
30 | }
|
31 | }
|
32 | }
|
33 | else {
|
34 | this.debug(data);
|
35 | this.error('Unable to create this integration, please retry');
|
36 | }
|
37 | }
|
38 | catch (e) {
|
39 | this.debug('%j', e.response);
|
40 | this.error(e);
|
41 | }
|
42 | }
|
43 | async askForName() {
|
44 | inquirer.registerPrompt('suggest', suggest);
|
45 | const suggestions = Array.from(Array(30).keys()).map(randomName);
|
46 | this.debug('%j', suggestions);
|
47 | return prompts_1.askForString('Integration name', {
|
48 | suggestions,
|
49 | validate: (input) => {
|
50 | return input.length > 0;
|
51 | },
|
52 | type: 'suggest'
|
53 | });
|
54 | }
|
55 | }
|
56 | IntegrationsCreate.description = 'create a new Integration';
|
57 | IntegrationsCreate.flags = Object.assign({}, base_command_1.default.flags, { description: command_1.flags.string({ char: 'd' }), name: command_1.flags.string({ char: 'n' }), skipLink: command_1.flags.boolean({ char: 'l' }) });
|
58 | tslib_1.__decorate([
|
59 | decorators_1.ensureFreshToken()
|
60 | ], IntegrationsCreate.prototype, "run", null);
|
61 | exports.default = IntegrationsCreate;
|
62 | function randomName() {
|
63 | return [bearSample(), nameSample()].join(' ');
|
64 | }
|
65 | function bearSample() {
|
66 | return bears[Math.floor(Math.random() * bears.length)];
|
67 | }
|
68 | function nameSample() {
|
69 | return names[Math.floor(Math.random() * names.length)];
|
70 | }
|
71 | const bears = [
|
72 | 'Cinnamon',
|
73 | 'Florida',
|
74 | 'Glacier',
|
75 | 'Haida Gwaii',
|
76 | 'Kermode',
|
77 | 'Spirit',
|
78 | 'Louisiana',
|
79 | 'Newfoundland',
|
80 | 'Baluchistan',
|
81 | 'Formosan',
|
82 | 'Himalayan',
|
83 | 'Ussuri',
|
84 | 'Alaska Peninsula',
|
85 | 'Atlas',
|
86 | 'Bergman',
|
87 | 'Cantabrian',
|
88 | 'Gobi',
|
89 | 'Grizzly',
|
90 | 'Kamchatka',
|
91 | 'Kodiak',
|
92 | 'Marsican',
|
93 | 'Sitka',
|
94 | 'Stickeen',
|
95 | 'Ussuri',
|
96 | 'Giant',
|
97 | 'Qinling',
|
98 | 'Sloth',
|
99 | 'Sun',
|
100 | 'Polar',
|
101 | 'Ursid hybrid',
|
102 | 'Spectacled'
|
103 | ];
|
104 | const names = [
|
105 | 'Alpha',
|
106 | 'Bravo',
|
107 | 'Charlie',
|
108 | 'Delta',
|
109 | 'Echo',
|
110 | 'Foxtrot',
|
111 | 'Golf',
|
112 | 'Hotel',
|
113 | 'India',
|
114 | 'Juliet',
|
115 | 'Kilo',
|
116 | 'Lima',
|
117 | 'Mike',
|
118 | 'November',
|
119 | 'Oscar',
|
120 | 'Papa',
|
121 | 'Quebec',
|
122 | 'Romeo',
|
123 | 'Sierra',
|
124 | 'Tango',
|
125 | 'Uniform',
|
126 | 'Victor',
|
127 | 'Whiskey',
|
128 | 'X-ray',
|
129 | 'Yankee',
|
130 | 'Zulu'
|
131 | ];
|
132 | const MUTATION = `
|
133 | mutation CLICreateIntegration($name: String!, $description: String!) {
|
134 | createIntegration(name: $name, description: $description) {
|
135 | integration {
|
136 | uuid: uuidv2
|
137 | name
|
138 | }
|
139 | }
|
140 | }
|
141 | `;
|