@adobe/aio-cli-plugin-api-mesh 1.3.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,7 +12,12 @@ governing permissions and limitations under the License.
12
12
 
13
13
  const { Command, Flags } = require('@oclif/core');
14
14
  const SourceRegistryStorage = require('source-registry-storage-adapter');
15
- const { promptMultiselect, promptSelect, promptConfirm, initRequestId } = require('../../../helpers');
15
+ const {
16
+ promptMultiselect,
17
+ promptSelect,
18
+ promptConfirm,
19
+ initRequestId,
20
+ } = require('../../../helpers');
16
21
  const ncp = require('node-clipboardy');
17
22
  const chalk = require('chalk');
18
23
  const config = require('@adobe/aio-lib-core-config');
@@ -31,18 +36,18 @@ class GetCommand extends Command {
31
36
  await initRequestId();
32
37
 
33
38
  logger.info(`RequestId: ${global.requestId}`);
34
- let list
39
+ let list;
35
40
  try {
36
41
  list = await this.sourceRegistryStorage.getList();
37
42
  } catch (err) {
38
- this.log(err)
39
- this.error(`Cannot get the list of sources: ${err}`)
43
+ this.log(err);
44
+ this.error(`Cannot get the list of sources: ${err}`);
40
45
  }
41
46
  const { flags } = await this.parse(GetCommand);
42
47
  if (!flags.source && !flags.multiple) {
43
48
  this.error(
44
- `The "aio api-mesh:source:get" command requires additional parameters` +
45
- `\nUse "aio api-mesh:source:get --help" to see parameters information.`,
49
+ `\nThe "aio api-mesh:source:get" command requires additional parameters` +
50
+ `\nUse "aio api-mesh:source:get --help" to see parameters information.`,
46
51
  );
47
52
  }
48
53
  const sources = flags.multiple ? await this.handleMultiple(list) : flags.source;
@@ -54,7 +59,7 @@ class GetCommand extends Command {
54
59
  this.error(
55
60
  chalk.red(
56
61
  `The source with the name "${name}" doesn't exist.` +
57
- `\nUse "aio api-mesh:source:discover" command to see avaliable sources.`,
62
+ `\nUse "aio api-mesh:source:discover" command to see avaliable sources.`,
58
63
  ),
59
64
  );
60
65
  }
@@ -63,7 +68,7 @@ class GetCommand extends Command {
63
68
  this.error(
64
69
  chalk.red(
65
70
  `The version "${version}" for source name "${name}" doesn't exist.` +
66
- `\nUse "aio api-mesh:source:discover" command to see avaliable source versions.`,
71
+ `\nUse "aio api-mesh:source:discover" command to see avaliable source versions.`,
67
72
  ),
68
73
  );
69
74
  }
@@ -77,16 +82,19 @@ class GetCommand extends Command {
77
82
  'The sources are copied to the clipboard, please paste them to your API Mesh configuration',
78
83
  ),
79
84
  );
80
- const print = await promptConfirm(`Do you want to print Source configurations in console?`);
81
- if (print) {
85
+ if (!flags.confirm) {
86
+ const print = await promptConfirm(`Do you want to print Source configurations in console?`);
87
+ if (print) {
88
+ this.log(sourceConfigsString);
89
+ }
90
+ } else {
82
91
  this.log(sourceConfigsString);
83
92
  }
84
93
  } catch (error) {
85
94
  logger.error(error);
86
95
  this.error(`
87
- Something went wrong with "get" command. Please try again later.
88
- ${error}
89
- `);
96
+ \nSomething went wrong with "get" command. Please try again later.
97
+ \n${error}`);
90
98
  }
91
99
  }
92
100
 
@@ -116,6 +124,11 @@ class GetCommand extends Command {
116
124
  }
117
125
 
118
126
  GetCommand.flags = {
127
+ confirm: Flags.boolean({
128
+ char: 'c',
129
+ description: 'Auto confirm print action prompt. CLI will not check ask user to print source.',
130
+ default: false,
131
+ }),
119
132
  source: Flags.string({
120
133
  char: 's',
121
134
  description: 'Source name',
@@ -130,8 +143,8 @@ GetCommand.flags = {
130
143
 
131
144
  GetCommand.description = 'Command returns the content of a specific source.';
132
145
  GetCommand.examples = [
133
- '$ aio api-mesh:source:get <version>@<source_name>',
134
- '$ aio api-mesh:source:get <source_name>',
146
+ '$ aio api-mesh:source:get -s=<version>@<source_name>',
147
+ '$ aio api-mesh:source:get -s<source_name>',
135
148
  '$ aio api-mesh:source:get -m',
136
149
  ];
137
150
 
@@ -45,6 +45,7 @@ class InstallCommand extends Command {
45
45
  return obj;
46
46
  }, {})
47
47
  : {};
48
+
48
49
  if (filepath) {
49
50
  try {
50
51
  variables = { ...variables, ...JSON.parse(await readFile(filepath, 'utf8')) };
@@ -67,7 +68,7 @@ class InstallCommand extends Command {
67
68
  this.error(`Cannot get the list of sources: ${err}. RequestId: ${global.requestId}`);
68
69
  }
69
70
  const sources = flags.source ? flags.source : [args.source];
70
- const sourceConfigs = {sources: [], files: {}};
71
+ const sourceConfigs = { sources: [], files: {} };
71
72
  for (const source of sources) {
72
73
  let [name, version] = source.split('@');
73
74
  const normalizedName = this.normalizeName(name);
@@ -92,21 +93,27 @@ class InstallCommand extends Command {
92
93
  const jsonInterpolate = new JsonInterpolate({ variablesSchema: sourceConfig.variables });
93
94
  const sourceProviderString = JSON.stringify(sourceConfig.provider);
94
95
  const sourceVariables = jsonInterpolate.getJsonVariables(sourceProviderString);
95
- const missedVariables = jsonInterpolate.getMissedVariables(variables, sourceVariables);
96
- for (const missedVariable of missedVariables) {
97
- variables[missedVariable.name] = await promptInput(
98
- `Enter the value for variable ${missedVariable.name}:`,
96
+ const passedSourceVariables = this.getPassedSourceVariables(sourceVariables || [], variables);
97
+ const missedVariables = jsonInterpolate.getMissedVariables(
98
+ passedSourceVariables,
99
+ sourceVariables,
100
+ );
101
+ for (const missedVariable of missedVariables
102
+ .map(item => item.name)
103
+ .filter((value, index, self) => self.indexOf(value) === index)) {
104
+ passedSourceVariables[missedVariable] = await promptInput(
105
+ `Enter the value for variable ${missedVariable}:`,
99
106
  );
100
107
  }
101
108
 
102
109
  const { error, data } = jsonInterpolate.interpolate(
103
110
  JSON.stringify(sourceConfig.provider),
104
- variables,
111
+ passedSourceVariables,
105
112
  );
106
113
  if (error) {
107
114
  this.error(chalk.red(`${error.message}\n${error.list.map(err => err.message).join('\n')}`));
108
115
  }
109
-
116
+
110
117
  sourceConfigs.sources.push(JSON.parse(data));
111
118
  sourceConfigs.files[sourceConfig.provider.name] = sourceConfig.files;
112
119
  }
@@ -137,56 +144,58 @@ class InstallCommand extends Command {
137
144
  const verifiedSources = this.verifySourceAlreadyExists(
138
145
  mesh.meshConfig.sources,
139
146
  sourceConfigs.sources,
140
- );
147
+ );
141
148
 
142
149
  let override = false;
143
150
  if (verifiedSources.installed.length) {
144
- override = await promptConfirm(
145
- `The following sources are already installed: ${verifiedSources.installed
146
- .map(source => source.name)
147
- .join(', ')}.
151
+ override = flags.confirm
152
+ ? true
153
+ : await promptConfirm(
154
+ `The following sources are already installed: ${verifiedSources.installed
155
+ .map(source => source.name)
156
+ .join(', ')}.
148
157
  Do you want to override?`,
149
- );
150
- }
151
-
152
- const uniqueFiles = this.getSourceFiles(verifiedSources.unique.map(source => source.name), sourceConfigs.files);
153
- const installedFiles = this.getSourceFiles(verifiedSources.installed.map(source => source.name), sourceConfigs.files);
158
+ );
159
+ }
160
+
161
+ const uniqueFiles = this.getSourceFiles(
162
+ verifiedSources.unique.map(source => source.name),
163
+ sourceConfigs.files,
164
+ );
165
+ const installedFiles = this.getSourceFiles(
166
+ verifiedSources.installed.map(source => source.name),
167
+ sourceConfigs.files,
168
+ );
154
169
  let meshConfigFiles = mesh.meshConfig.files || [];
155
170
 
156
171
  if (override) {
157
172
  const installedMap = verifiedSources.installed.reduce((obj, source) => {
158
173
  obj[source.name] = true;
159
- return obj
174
+ return obj;
160
175
  }, {});
161
-
176
+
162
177
  mesh.meshConfig.sources = [
163
178
  ...mesh.meshConfig.sources.filter(source => !installedMap[source.name]),
164
- ...verifiedSources.installed
179
+ ...verifiedSources.installed,
165
180
  ];
166
181
 
167
182
  const installedFilesMap = installedFiles.reduce((obj, file) => {
168
183
  obj[file.path] = true;
169
- return obj
184
+ return obj;
170
185
  }, {});
171
186
 
172
187
  meshConfigFiles = [
173
188
  ...meshConfigFiles.filter(file => !installedFilesMap[file.path]),
174
- ...installedFiles
189
+ ...installedFiles,
175
190
  ];
176
191
  }
177
192
 
178
- mesh.meshConfig.sources = [
179
- ...mesh.meshConfig.sources,
180
- ...verifiedSources.unique
181
- ]
182
-
183
- meshConfigFiles = [
184
- ...meshConfigFiles,
185
- ...uniqueFiles
186
- ]
187
-
193
+ mesh.meshConfig.sources = [...mesh.meshConfig.sources, ...verifiedSources.unique];
194
+
195
+ meshConfigFiles = [...meshConfigFiles, ...uniqueFiles];
196
+
188
197
  if (meshConfigFiles.length) {
189
- mesh.meshConfig.files = meshConfigFiles
198
+ mesh.meshConfig.files = meshConfigFiles;
190
199
  }
191
200
 
192
201
  try {
@@ -222,12 +231,22 @@ class InstallCommand extends Command {
222
231
  let result = [];
223
232
  for (const source of sourcesList) {
224
233
  if (Array.isArray(filesList[source])) {
225
- result = [...result, ...filesList[source]]
234
+ result = [...result, ...filesList[source]];
226
235
  }
227
236
  }
228
237
  return result;
229
238
  }
230
239
 
240
+ getPassedSourceVariables(variablesInSource, passedVariables) {
241
+ const res = {};
242
+ variablesInSource.forEach(variable => {
243
+ if (passedVariables[variable.name]) {
244
+ res[variable.name] = passedVariables[variable.name];
245
+ }
246
+ });
247
+ return res;
248
+ }
249
+
231
250
  verifySourceAlreadyExists(meshSources, installSources) {
232
251
  const alreadyInstalledSources = [];
233
252
  const uniqueSourcesToInstall = [];
@@ -247,6 +266,17 @@ class InstallCommand extends Command {
247
266
  }
248
267
 
249
268
  InstallCommand.flags = {
269
+ 'source': Flags.string({
270
+ char: 's',
271
+ description: 'Source name',
272
+ multiple: true,
273
+ }),
274
+ 'confirm': Flags.boolean({
275
+ char: 'c',
276
+ description:
277
+ 'Auto confirm override action prompt. CLI will not check ask user to override source.',
278
+ default: false,
279
+ }),
250
280
  'variable': Flags.string({
251
281
  char: 'v',
252
282
  description: 'Variables required for the source',
@@ -0,0 +1,96 @@
1
+ const { Command } = require('@oclif/core');
2
+ const logger = require('../../classes/logger');
3
+ const { initRequestId, initSdk } = require('../../helpers');
4
+ const { getMeshId, getMesh } = require('../../lib/devConsole');
5
+ const { ignoreCacheFlag } = require('../../utils');
6
+
7
+ require('dotenv').config();
8
+
9
+ class StatusCommand extends Command {
10
+ static flags = {
11
+ ignoreCache: ignoreCacheFlag,
12
+ };
13
+
14
+ async run() {
15
+ await initRequestId();
16
+ logger.info(`RequestId: ${global.requestId}`);
17
+
18
+ const { flags } = await this.parse(StatusCommand);
19
+ const ignoreCache = await flags.ignoreCache;
20
+
21
+ const { imsOrgId, projectId, workspaceId } = await initSdk({
22
+ ignoreCache,
23
+ });
24
+
25
+ let meshId = null;
26
+
27
+ try {
28
+ meshId = await getMeshId(imsOrgId, projectId, workspaceId);
29
+ } catch (err) {
30
+ this.log(err.message);
31
+ this.error(
32
+ `Unable to get mesh ID. Please check the details and try again. RequestId: ${global.requestId}`,
33
+ );
34
+ }
35
+
36
+ if (meshId) {
37
+ try {
38
+ const mesh = await getMesh(imsOrgId, projectId, workspaceId, meshId);
39
+ switch (mesh.meshStatus) {
40
+ case 'success':
41
+ this.log(
42
+ '******************************************************************************************************',
43
+ );
44
+ this.log('Your mesh has been successfully built.');
45
+ this.log(
46
+ '******************************************************************************************************',
47
+ );
48
+ break;
49
+ case 'pending':
50
+ this.log(
51
+ '******************************************************************************************************',
52
+ );
53
+ this.log('Your mesh is awaiting processing.');
54
+ this.log(
55
+ '******************************************************************************************************',
56
+ );
57
+ break;
58
+ case 'building':
59
+ this.log(
60
+ '******************************************************************************************************',
61
+ );
62
+ this.log(
63
+ 'Your mesh is currently being provisioned. Please wait a few minutes before checking again.',
64
+ );
65
+ this.log(
66
+ '******************************************************************************************************',
67
+ );
68
+ break;
69
+ case 'error':
70
+ this.log(
71
+ '******************************************************************************************************',
72
+ );
73
+ this.log('Your mesh errored out with the following error. ', mesh.error);
74
+ this.log(
75
+ '******************************************************************************************************',
76
+ );
77
+ break;
78
+ }
79
+ } catch (err) {
80
+ this.log(err.message);
81
+
82
+ this.error(
83
+ `Unable to get the mesh status. If the error persists please contact support. RequestId: ${global.requestId}`,
84
+ );
85
+ }
86
+ } else {
87
+ this.error(
88
+ `Unable to get mesh status. No mesh found for Org(${imsOrgId}) -> Project(${projectId}) -> Workspace(${workspaceId}). Please check the details and try again.`,
89
+ );
90
+ }
91
+ }
92
+ }
93
+
94
+ StatusCommand.description = 'Get a mesh status with a given meshid.';
95
+
96
+ module.exports = StatusCommand;
@@ -82,7 +82,18 @@ class UpdateCommand extends Command {
82
82
  try {
83
83
  const response = await updateMesh(imsOrgId, projectId, workspaceId, meshId, data);
84
84
 
85
- this.log('Successfully updated the mesh with the id: %s', meshId);
85
+ this.log(
86
+ '******************************************************************************************************',
87
+ );
88
+ this.log(
89
+ 'Your mesh is being provisioned. Wait a few minutes before checking the status of your mesh %s',
90
+ meshId,
91
+ );
92
+ this.log('To check the status of your mesh, run:');
93
+ this.log('aio api-mesh:status');
94
+ this.log(
95
+ '******************************************************************************************************',
96
+ );
86
97
 
87
98
  return response;
88
99
  } catch (error) {
package/src/constants.js CHANGED
@@ -8,6 +8,7 @@ const StageConstants = {
8
8
  DEV_CONSOLE_API_KEY: 'adobe-api-manager-sms-stage',
9
9
  DEV_CONSOLE_TRANSPORTER_API_KEY: 'UDPWeb1',
10
10
  AIO_CLI_API_KEY: 'aio-cli-console-auth-stage',
11
+ SMS_BASE_URL: 'https://graph-stage.adobe.io/api-admin',
11
12
  };
12
13
 
13
14
  const ProdConstants = {
@@ -16,6 +17,7 @@ const ProdConstants = {
16
17
  DEV_CONSOLE_API_KEY: 'adobe-graph-prod',
17
18
  DEV_CONSOLE_TRANSPORTER_API_KEY: 'UDPWeb1',
18
19
  AIO_CLI_API_KEY: 'aio-cli-console-auth',
20
+ SMS_BASE_URL: 'https://graph.adobe.io/api-admin',
19
21
  };
20
22
 
21
23
  module.exports = clientEnv === 'stage' ? StageConstants : ProdConstants;
package/src/helpers.js CHANGED
@@ -26,6 +26,9 @@ const { objToString } = require('./utils');
26
26
 
27
27
  const { DEV_CONSOLE_BASE_URL, DEV_CONSOLE_API_KEY, AIO_CLI_API_KEY } = CONSTANTS;
28
28
 
29
+ /**
30
+ * @param configFilePath
31
+ */
29
32
  async function getDevConsoleConfigFromFile(configFilePath) {
30
33
  try {
31
34
  if (!fs.existsSync(configFilePath)) {
@@ -47,7 +50,7 @@ async function getDevConsoleConfigFromFile(configFilePath) {
47
50
  : data.baseUrl;
48
51
 
49
52
  const config = {
50
- baseUrl: baseUrl,
53
+ baseUrl,
51
54
  accessToken: (await getLibConsoleCLI()).accessToken,
52
55
  apiKey: data.apiKey,
53
56
  };
@@ -64,6 +67,9 @@ async function getDevConsoleConfigFromFile(configFilePath) {
64
67
  }
65
68
  }
66
69
 
70
+ /**
71
+ * @param configObject
72
+ */
67
73
  async function getDevConsoleConfigFromObject(configObject) {
68
74
  const { baseUrl, apiKey } = configObject;
69
75
  const config = {
@@ -325,15 +331,16 @@ async function getLibConsoleCLI() {
325
331
  const accessToken = await getToken(CLI);
326
332
 
327
333
  const consoleCLI = await libConsoleCLI.init({
328
- accessToken: accessToken,
334
+ accessToken,
329
335
  apiKey: AIO_CLI_API_KEY,
330
336
  env: clientEnv,
331
337
  });
332
338
 
333
- return { consoleCLI: consoleCLI, accessToken: accessToken };
339
+ return { consoleCLI, accessToken };
334
340
  }
335
341
 
336
342
  /**
343
+ * @param options
337
344
  * @returns {any} Returns an object with properties ready for consumption
338
345
  */
339
346
  async function initSdk(options) {
@@ -377,7 +384,6 @@ async function initRequestId() {
377
384
  * Function to run the CLI Y/N prompt to confirm the user's action
378
385
  *
379
386
  * @param {string} message
380
- *
381
387
  * @returns boolean
382
388
  */
383
389
  async function promptConfirm(message) {
@@ -405,9 +411,9 @@ async function promptMultiselect(message, choices) {
405
411
  const selected = await inquirer.prompt([
406
412
  {
407
413
  name: 'items',
408
- message: message,
414
+ message,
409
415
  type: 'checkbox',
410
- choices: choices,
416
+ choices,
411
417
  },
412
418
  ]);
413
419
 
@@ -425,9 +431,9 @@ async function promptSelect(message, choices) {
425
431
  const selected = await inquirer.prompt([
426
432
  {
427
433
  name: 'item',
428
- message: message,
434
+ message,
429
435
  type: 'list',
430
- choices: choices,
436
+ choices,
431
437
  },
432
438
  ]);
433
439
 
@@ -441,11 +447,11 @@ async function promptSelect(message, choices) {
441
447
  * @param {object[]} choices - list of options
442
448
  * @returns {object[]} - selected options
443
449
  */
444
- async function promptInput(message) {
450
+ async function promptInput(message) {
445
451
  const selected = await inquirer.prompt([
446
452
  {
447
453
  name: 'item',
448
- message: message,
454
+ message,
449
455
  type: 'input',
450
456
  },
451
457
  ]);
package/src/utils.js CHANGED
@@ -3,9 +3,8 @@
3
3
  * If the path evaluates to false, the default string is returned.
4
4
  *
5
5
  * @param {object} obj
6
- * @param {array<string>} path
6
+ * @param {Array<string>} path
7
7
  * @param {string} defaultString
8
- *
9
8
  * @returns {string}
10
9
  */
11
10
  function objToString(obj, path = [], defaultString = '') {
@@ -49,8 +48,14 @@ const autoConfirmActionFlag = Flags.boolean({
49
48
  default: false,
50
49
  });
51
50
 
51
+ const jsonFlag = Flags.boolean({
52
+ description: 'Output JSON',
53
+ default: false,
54
+ });
55
+
52
56
  module.exports = {
53
57
  objToString,
54
58
  ignoreCacheFlag,
55
59
  autoConfirmActionFlag,
60
+ jsonFlag,
56
61
  };