@adobe/aio-cli-plugin-api-mesh 1.0.2-beta → 1.0.3-beta

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.
package/README.md CHANGED
@@ -47,6 +47,7 @@ aio config:set api-mesh.configPath <path_to_json_file>
47
47
  # Commands
48
48
 
49
49
  ```
50
+ aio api-mesh:describe
50
51
  aio api-mesh:get meshId
51
52
  aio api-mesh:get meshId PATH_OF_FILE_TO_DOWNLOAD_INTO
52
53
  aio api-mesh:create PATH_OF_MESH_CONFIG_JSON_FILE
@@ -1 +1 @@
1
- {"version":"1.0.2-beta","commands":{"PLUGINNAME":{"id":"PLUGINNAME","description":"Your description here","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":["$ aio PLUGINNAME:some_command"],"flags":{"someflag":{"name":"someflag","type":"option","char":"f","description":"this is some flag"}},"args":[]},"api-mesh:create":{"id":"api-mesh:create","description":"Create a mesh with the given config.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"file"}]},"api-mesh:delete":{"id":"api-mesh:delete","description":"Delete the config of a given mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"meshId"}]},"api-mesh:get":{"id":"api-mesh:get","description":"Get the config of a given mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"meshId"},{"name":"file"}]},"api-mesh:update":{"id":"api-mesh:update","description":"Update a mesh with the given config.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"meshId"},{"name":"file"}]}}}
1
+ {"version":"1.0.3-beta","commands":{"PLUGINNAME":{"id":"PLUGINNAME","description":"Your description here","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":["$ aio PLUGINNAME:some_command"],"flags":{"someflag":{"name":"someflag","type":"option","char":"f","description":"this is some flag"}},"args":[]},"api-mesh:create":{"id":"api-mesh:create","description":"Create a mesh with the given config.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"file"}]},"api-mesh:delete":{"id":"api-mesh:delete","description":"Delete the config of a given mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"meshId"}]},"api-mesh:describe":{"id":"api-mesh:describe","description":"Get details of a mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{},"args":[]},"api-mesh:get":{"id":"api-mesh:get","description":"Get the config of a given mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"meshId"},{"name":"file"}]},"api-mesh:update":{"id":"api-mesh:update","description":"Update a mesh with the given config.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"meshId"},{"name":"file"}]}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/aio-cli-plugin-api-mesh",
3
- "version": "1.0.2-beta",
3
+ "version": "1.0.3-beta",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -25,6 +25,57 @@ class SchemaServiceClient {
25
25
  this.apiKey = apiKey;
26
26
  }
27
27
 
28
+ async describeMesh(organizationId, projectId, workspaceId) {
29
+ const config = {
30
+ method: 'get',
31
+ url: `${this.devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/describe?API_KEY=${this.apiKey}`,
32
+ headers: {
33
+ 'Authorization': `Bearer ${this.accessToken}`,
34
+ 'x-request-id': global.requestId,
35
+ },
36
+ };
37
+
38
+ logger.info(
39
+ 'Initiating GET %s',
40
+ `${this.devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/describe?API_KEY=${this.apiKey}`,
41
+ );
42
+
43
+ try {
44
+ const response = await axios(config);
45
+
46
+ logger.info('Response from GET %s', response.status);
47
+
48
+ if (response && response.status === 200) {
49
+ logger.info(`Mesh Config : ${objToString(response, ['data'])}`);
50
+
51
+ return response.data;
52
+ } else {
53
+ // Non 200 response received
54
+ logger.error(
55
+ `Something went wrong: ${objToString(
56
+ response,
57
+ ['data'],
58
+ 'Unable to get mesh',
59
+ )}. Received ${response.status} response instead of 200`,
60
+ );
61
+
62
+ throw new Error(
63
+ `Something went wrong: ${objToString(response, ['data'], 'Unable to get mesh')}`,
64
+ );
65
+ }
66
+ } catch (error) {
67
+ if (error.response.status === 400) {
68
+ // The request was made and the server responded with a 400 status code
69
+ logger.error('Mesh not found');
70
+
71
+ return null;
72
+ } else {
73
+ // The request was made and the server responded with a different status code
74
+ logger.error('Error while describing mesh');
75
+ }
76
+ }
77
+ }
78
+
28
79
  async getMesh(organizationId, projectId, workspaceId, meshId) {
29
80
  const config = {
30
81
  method: 'get',
@@ -57,16 +57,15 @@ describe('create command tests', () => {
57
57
  jest.restoreAllMocks();
58
58
  });
59
59
 
60
- test('create-mesh-missing-file', async () => {
60
+ test('should fail mesh id is missing', async () => {
61
61
  expect.assertions(2);
62
62
  const runResult = CreateCommand.run([]);
63
63
  await expect(runResult instanceof Promise).toBeTruthy();
64
64
  await expect(runResult).rejects.toEqual(
65
- new Error(
66
- 'Unable to read the mesh configuration file provided. Please check the file and try again.',
67
- ),
65
+ new Error('Missing file path. Run aio api-mesh create --help for more info.'),
68
66
  );
69
67
  });
68
+
70
69
  test('create-mesh-with-configuration', async () => {
71
70
  expect.assertions(2);
72
71
  const runResult = CreateCommand.run(['src/commands/__fixtures__/sample_mesh.json']);
@@ -67,20 +67,18 @@ describe('delete command tests', () => {
67
67
  jest.restoreAllMocks();
68
68
  });
69
69
 
70
- test('delete-mesh-missing-meshId', async () => {
70
+ test('should fail if mesh id is missing', async () => {
71
71
  const runResult = DeleteCommand.run([]);
72
72
 
73
73
  return runResult.catch(err => {
74
74
  expect(err).toHaveProperty(
75
75
  'message',
76
- expect.stringMatching(
77
- /^Unable to delete mesh\. Please check the details and try again\. If the error persists please contact support\. RequestId: [a-z A-Z 0-9 -_]+/,
78
- ),
76
+ expect.stringMatching(/^Missing Mesh ID. Run aio api-mesh delete --help for more info/),
79
77
  );
80
78
  });
81
79
  });
82
80
 
83
- test('delete-mesh-with-meshId', async () => {
81
+ test('should delete if correct args are provided', async () => {
84
82
  jest
85
83
  .spyOn(SchemaServiceClient.prototype, 'deleteMesh')
86
84
  .mockImplementation(() => Promise.resolve({}));
@@ -0,0 +1,79 @@
1
+ /*
2
+ Copyright 2021 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ const mockConsoleCLIInstance = {};
14
+ jest.mock('@adobe/aio-lib-env');
15
+ jest.mock('@adobe/aio-cli-lib-console');
16
+ const orgs = [{ id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' }];
17
+ const selectedOrg = { id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' };
18
+
19
+ const projects = [{ id: '5678', title: 'Project01' }];
20
+ const selectedProject = { id: '5678', title: 'Project01' };
21
+
22
+ const workspaces = [{ id: '123456789', title: 'Workspace01' }];
23
+ const selectedWorkspace = { id: '123456789', title: 'Workspace01' };
24
+
25
+ function setDefaultMockConsoleCLI() {
26
+ mockConsoleCLIInstance.getToken = jest.fn().mockReturnValue('test_token');
27
+ mockConsoleCLIInstance.getCliEnv = jest.fn().mockReturnValue('prod');
28
+
29
+ mockConsoleCLIInstance.getOrganizations = jest.fn().mockResolvedValue(orgs);
30
+ mockConsoleCLIInstance.promptForSelectOrganization = jest.fn().mockResolvedValue(selectedOrg);
31
+
32
+ mockConsoleCLIInstance.getProjects = jest.fn().mockResolvedValue(projects);
33
+ mockConsoleCLIInstance.promptForSelectProject = jest.fn().mockResolvedValue(selectedProject);
34
+
35
+ mockConsoleCLIInstance.getWorkspaces = jest.fn().mockResolvedValue(workspaces);
36
+ mockConsoleCLIInstance.promptForSelectWorkspace = jest.fn().mockResolvedValue(selectedWorkspace);
37
+ }
38
+
39
+ jest.mock('@adobe/aio-cli-lib-console', () => ({
40
+ init: jest.fn().mockResolvedValue(mockConsoleCLIInstance),
41
+ cleanStdOut: jest.fn(),
42
+ }));
43
+
44
+ jest.mock('@adobe/aio-lib-ims');
45
+
46
+ const DescribeCommand = require('../describe');
47
+ const { SchemaServiceClient } = require('../../../classes/SchemaServiceClient');
48
+
49
+ describe('describe command tests', () => {
50
+ beforeEach(() => {
51
+ setDefaultMockConsoleCLI();
52
+ });
53
+
54
+ afterEach(() => {
55
+ jest.restoreAllMocks();
56
+ });
57
+
58
+ test('should error if wrong details are provided', async () => {
59
+ const runResult = DescribeCommand.run([]);
60
+
61
+ return runResult.catch(err => {
62
+ expect(err).toHaveProperty(
63
+ 'message',
64
+ expect.stringMatching(
65
+ /^Unable to get mesh details\. Please check the details and try again\. If the error persists please contact support\. RequestId: [a-z A-Z 0-9 -_]+/,
66
+ ),
67
+ );
68
+ });
69
+ });
70
+
71
+ test('should return meshId if correct details are provided', async () => {
72
+ const meshId = 'sample-mesh-id';
73
+ jest.spyOn(SchemaServiceClient.prototype, 'describeMesh').mockResolvedValue({ meshId });
74
+
75
+ const runResult = await DescribeCommand.run();
76
+
77
+ await expect(runResult).toEqual({ meshId });
78
+ });
79
+ });
@@ -53,20 +53,18 @@ describe('get command tests', () => {
53
53
  jest.restoreAllMocks();
54
54
  });
55
55
 
56
- test('get-mesh-missing-meshId', async () => {
56
+ test('should fail if mesh id is missing', async () => {
57
57
  const runResult = GetCommand.run([]);
58
58
 
59
59
  return runResult.catch(err => {
60
60
  expect(err).toHaveProperty(
61
61
  'message',
62
- expect.stringMatching(
63
- /^Unable to get mesh\. Please check the details and try again\. If the error persists please contact support\. RequestId: [a-z A-Z 0-9 -_]+/,
64
- ),
62
+ expect.stringMatching(/^Missing Mesh ID. Run aio api-mesh get --help for more info./),
65
63
  );
66
64
  });
67
65
  });
68
66
 
69
- test('get-mesh-with-meshId', async () => {
67
+ test('should pass if mesh id is provided', async () => {
70
68
  jest.spyOn(SchemaServiceClient.prototype, 'getMesh').mockImplementation(meshId => mockGetMesh);
71
69
  expect.assertions(1);
72
70
  const meshId = 'sample_merchant';
@@ -66,9 +66,18 @@ describe('update command tests', () => {
66
66
  jest.restoreAllMocks();
67
67
  });
68
68
 
69
- test('update-mesh-missing-meshId-file', async () => {
69
+ test('should fail if update file path is missing', async () => {
70
70
  expect.assertions(2);
71
- const runResult = UpdateCommand.run([]);
71
+ const runResult = UpdateCommand.run(['dummy_mesh_id']);
72
+ await expect(runResult instanceof Promise).toBeTruthy();
73
+ await expect(runResult).rejects.toEqual(
74
+ new Error('Missing required args. Run aio api-mesh update --help for more info.'),
75
+ );
76
+ });
77
+
78
+ test('should fail if dummy file path is provided', async () => {
79
+ expect.assertions(2);
80
+ const runResult = UpdateCommand.run(['dummy_mesh_id', 'dummy_file_path']);
72
81
  await expect(runResult instanceof Promise).toBeTruthy();
73
82
  await expect(runResult).rejects.toEqual(
74
83
  new Error(
@@ -77,7 +86,7 @@ describe('update command tests', () => {
77
86
  );
78
87
  });
79
88
 
80
- test('update-mesh-with-configuration', async () => {
89
+ test('should pass with valid args', async () => {
81
90
  expect.assertions(2);
82
91
  const runResult = UpdateCommand.run([
83
92
  'sample_merchant',
@@ -87,7 +96,7 @@ describe('update command tests', () => {
87
96
  await expect(runResult).resolves.toEqual(mockUpdateMesh);
88
97
  });
89
98
 
90
- test('should not delete if user prompt returns false', async () => {
99
+ test('should not update if user prompt returns false', async () => {
91
100
  inquirer.createPromptModule.mockReturnValue(
92
101
  jest.fn().mockResolvedValue({
93
102
  res: false,
@@ -24,6 +24,12 @@ class CreateCommand extends Command {
24
24
 
25
25
  const { args } = this.parse(CreateCommand);
26
26
 
27
+ if (!args.file) {
28
+ this.error('Missing file path. Run aio api-mesh create --help for more info.');
29
+
30
+ return;
31
+ }
32
+
27
33
  const { schemaServiceClient, imsOrgId, projectId, workspaceId } = await initSdk();
28
34
 
29
35
  let data;
@@ -26,6 +26,12 @@ class DeleteCommand extends Command {
26
26
 
27
27
  const { args } = this.parse(DeleteCommand);
28
28
 
29
+ if (!args.meshId) {
30
+ this.error('Missing Mesh ID. Run aio api-mesh delete --help for more info.');
31
+
32
+ return;
33
+ }
34
+
29
35
  const { schemaServiceClient, imsOrgId, projectId, workspaceId } = await initSdk();
30
36
 
31
37
  const shouldContinue = await promptConfirm(
@@ -0,0 +1,61 @@
1
+ /*
2
+ Copyright 2021 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ Unless required by applicable law or agreed to in writing, software distributed under
7
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
8
+ OF ANY KIND, either express or implied. See the License for the specific language
9
+ governing permissions and limitations under the License.
10
+ */
11
+
12
+ const { Command } = require('@oclif/command');
13
+ const logger = require('../../classes/logger');
14
+ const { initSdk, initRequestId } = require('../../helpers');
15
+
16
+ require('dotenv').config();
17
+
18
+ class DescribeCommand extends Command {
19
+ async run() {
20
+ await initRequestId();
21
+
22
+ logger.info(`RequestId: ${global.requestId}`);
23
+
24
+ const { schemaServiceClient, imsOrgId, projectId, workspaceId } = await initSdk();
25
+
26
+ try {
27
+ const meshDetails = await schemaServiceClient.describeMesh(imsOrgId, projectId, workspaceId);
28
+
29
+ if (meshDetails) {
30
+ const { meshId } = meshDetails;
31
+
32
+ if (meshId) {
33
+ this.log('Successfully retrieved mesh details \n');
34
+ this.log('Org ID: %s', imsOrgId);
35
+ this.log('Project ID: %s', projectId);
36
+ this.log('Workspace ID: %s', workspaceId);
37
+ this.log('Mesh ID: %s', meshId);
38
+
39
+ return meshDetails;
40
+ } else {
41
+ this.error(
42
+ `Unable to get mesh details. Please check the details and try again. RequestId: ${global.requestId}`,
43
+ { exit: false },
44
+ );
45
+ }
46
+ } else {
47
+ throw new Error(`Unable to get mesh details`);
48
+ }
49
+ } catch (error) {
50
+ this.log(error.message);
51
+
52
+ this.error(
53
+ `Unable to get mesh details. Please check the details and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
54
+ );
55
+ }
56
+ }
57
+ }
58
+
59
+ DescribeCommand.description = 'Get details of a mesh';
60
+
61
+ module.exports = DescribeCommand;
@@ -26,6 +26,12 @@ class GetCommand extends Command {
26
26
 
27
27
  const { args } = this.parse(GetCommand);
28
28
 
29
+ if (!args.meshId) {
30
+ this.error('Missing Mesh ID. Run aio api-mesh get --help for more info.');
31
+
32
+ return;
33
+ }
34
+
29
35
  const { schemaServiceClient, imsOrgId, projectId, workspaceId } = await initSdk();
30
36
 
31
37
  try {
@@ -25,6 +25,12 @@ class UpdateCommand extends Command {
25
25
 
26
26
  const { args } = this.parse(UpdateCommand);
27
27
 
28
+ if (!args.meshId || !args.file) {
29
+ this.error('Missing required args. Run aio api-mesh update --help for more info.');
30
+
31
+ return;
32
+ }
33
+
28
34
  const { schemaServiceClient, imsOrgId, projectId, workspaceId } = await initSdk();
29
35
  let data;
30
36