@adobe/aio-cli-plugin-api-mesh 1.0.1-beta → 1.0.2-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
@@ -24,7 +24,7 @@ $ aio discover -i
24
24
  Install project dependencies. `npm install`
25
25
 
26
26
  ```
27
- aio plugins:link commerce-gateway/tenant
27
+ aio plugins:link api-mesh
28
28
  ```
29
29
 
30
30
  ### Configuration
@@ -1 +1 @@
1
- {"version":"1.0.1-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.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"}]}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/aio-cli-plugin-api-mesh",
3
- "version": "1.0.1-beta",
3
+ "version": "1.0.2-beta",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -15,6 +15,7 @@
15
15
  "@oclif/errors": "^1.1.2",
16
16
  "axios": "^0.23.0",
17
17
  "dotenv": "^16.0.1",
18
+ "inquirer": "^8.2.4",
18
19
  "pino": "^7.9.2",
19
20
  "pino-pretty": "^7.6.0",
20
21
  "uuid": "^8.3.2"
@@ -13,6 +13,8 @@ governing permissions and limitations under the License.
13
13
  jest.mock('@adobe/aio-lib-env');
14
14
  jest.mock('@adobe/aio-cli-lib-console');
15
15
 
16
+ const inquirer = require('inquirer');
17
+
16
18
  const mockConsoleCLIInstance = {};
17
19
 
18
20
  const orgs = [{ id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' }];
@@ -42,8 +44,17 @@ jest.mock('@adobe/aio-cli-lib-console', () => ({
42
44
  init: jest.fn().mockResolvedValue(mockConsoleCLIInstance),
43
45
  cleanStdOut: jest.fn(),
44
46
  }));
47
+
45
48
  jest.mock('@adobe/aio-lib-ims');
46
49
 
50
+ jest.mock('inquirer', () => ({
51
+ createPromptModule: jest.fn().mockReturnValue(
52
+ jest.fn().mockResolvedValue({
53
+ res: true,
54
+ }),
55
+ ),
56
+ }));
57
+
47
58
  const DeleteCommand = require('../delete');
48
59
  const { SchemaServiceClient } = require('../../../classes/SchemaServiceClient');
49
60
 
@@ -79,4 +90,17 @@ describe('delete command tests', () => {
79
90
 
80
91
  await expect(runResult).resolves.toEqual({});
81
92
  });
93
+
94
+ test('should not delete if user prompt returns false', async () => {
95
+ inquirer.createPromptModule.mockReturnValue(
96
+ jest.fn().mockResolvedValue({
97
+ res: false,
98
+ }),
99
+ );
100
+
101
+ const meshId = 'sample_merchant';
102
+ const runResult = await DeleteCommand.run([meshId]);
103
+
104
+ expect(runResult).toBe('Delete cancelled');
105
+ });
82
106
  });
@@ -10,6 +10,8 @@ OF ANY KIND, either express or implied. See the License for the specific languag
10
10
  governing permissions and limitations under the License.
11
11
  */
12
12
 
13
+ const inquirer = require('inquirer');
14
+
13
15
  const mockConsoleCLIInstance = {};
14
16
  jest.mock('@adobe/aio-lib-env');
15
17
  const orgs = [{ id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' }];
@@ -35,11 +37,20 @@ function setDefaultMockConsoleCLI() {
35
37
  mockConsoleCLIInstance.promptForSelectWorkspace = jest.fn().mockResolvedValue(selectedWorkspace);
36
38
  }
37
39
 
40
+ jest.mock('inquirer', () => ({
41
+ createPromptModule: jest.fn().mockReturnValue(
42
+ jest.fn().mockResolvedValue({
43
+ res: true,
44
+ }),
45
+ ),
46
+ }));
47
+
38
48
  jest.mock('@adobe/aio-cli-lib-console', () => ({
39
49
  init: jest.fn().mockResolvedValue(mockConsoleCLIInstance),
40
50
  cleanStdOut: jest.fn(),
41
51
  }));
42
52
  jest.mock('@adobe/aio-lib-ims');
53
+
43
54
  const UpdateCommand = require('../update');
44
55
  const { SchemaServiceClient } = require('../../../classes/SchemaServiceClient');
45
56
  const mockUpdateMesh = require('../../__fixtures__/sample_mesh.json');
@@ -65,6 +76,7 @@ describe('update command tests', () => {
65
76
  ),
66
77
  );
67
78
  });
79
+
68
80
  test('update-mesh-with-configuration', async () => {
69
81
  expect.assertions(2);
70
82
  const runResult = UpdateCommand.run([
@@ -74,4 +86,19 @@ describe('update command tests', () => {
74
86
  await expect(runResult instanceof Promise).toBeTruthy();
75
87
  await expect(runResult).resolves.toEqual(mockUpdateMesh);
76
88
  });
89
+
90
+ test('should not delete if user prompt returns false', async () => {
91
+ inquirer.createPromptModule.mockReturnValue(
92
+ jest.fn().mockResolvedValue({
93
+ res: false,
94
+ }),
95
+ );
96
+
97
+ const runResult = await UpdateCommand.run([
98
+ 'sample_merchant',
99
+ 'src/commands/__fixtures__/sample_mesh.json',
100
+ ]);
101
+
102
+ expect(runResult).toBe('Update cancelled');
103
+ });
77
104
  });
@@ -10,8 +10,9 @@ governing permissions and limitations under the License.
10
10
  */
11
11
 
12
12
  const { Command } = require('@oclif/command');
13
+
13
14
  const logger = require('../../classes/logger');
14
- const { initSdk, initRequestId } = require('../../helpers');
15
+ const { initSdk, initRequestId, promptConfirm } = require('../../helpers');
15
16
 
16
17
  require('dotenv').config();
17
18
 
@@ -27,23 +28,33 @@ class DeleteCommand extends Command {
27
28
 
28
29
  const { schemaServiceClient, imsOrgId, projectId, workspaceId } = await initSdk();
29
30
 
30
- try {
31
- const response = await schemaServiceClient.deleteMesh(
32
- imsOrgId,
33
- projectId,
34
- workspaceId,
35
- args.meshId,
36
- );
31
+ const shouldContinue = await promptConfirm(
32
+ `Are you sure you want to delete the mesh: ${args.meshId}?`,
33
+ );
34
+
35
+ if (shouldContinue) {
36
+ try {
37
+ const response = await schemaServiceClient.deleteMesh(
38
+ imsOrgId,
39
+ projectId,
40
+ workspaceId,
41
+ args.meshId,
42
+ );
43
+
44
+ this.log('Successfully deleted mesh %s', args.meshId);
37
45
 
38
- this.log('Successfully deleted mesh %s', args.meshId);
46
+ return response;
47
+ } catch (error) {
48
+ this.log(error.message);
39
49
 
40
- return response;
41
- } catch (error) {
42
- this.log(error.message);
50
+ this.error(
51
+ `Unable to delete mesh. Please check the details and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
52
+ );
53
+ }
54
+ } else {
55
+ this.log('Delete cancelled');
43
56
 
44
- this.error(
45
- `Unable to delete mesh. Please check the details and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
46
- );
57
+ return 'Delete cancelled';
47
58
  }
48
59
  }
49
60
  }
@@ -11,8 +11,9 @@ governing permissions and limitations under the License.
11
11
 
12
12
  const { Command } = require('@oclif/command');
13
13
  const { readFile } = require('fs/promises');
14
+
14
15
  const logger = require('../../classes/logger');
15
- const { initSdk, initRequestId } = require('../../helpers');
16
+ const { initSdk, initRequestId, promptConfirm } = require('../../helpers');
16
17
 
17
18
  class UpdateCommand extends Command {
18
19
  static args = [{ name: 'meshId' }, { name: 'file' }];
@@ -38,24 +39,34 @@ class UpdateCommand extends Command {
38
39
  );
39
40
  }
40
41
 
41
- try {
42
- const response = await schemaServiceClient.updateMesh(
43
- imsOrgId,
44
- projectId,
45
- workspaceId,
46
- args.meshId,
47
- data,
48
- );
42
+ const shouldContinue = await promptConfirm(
43
+ `Are you sure you want to update the mesh: ${args.meshId}?`,
44
+ );
49
45
 
50
- this.log('Successfully updated the mesh with the id: %s', args.meshId);
46
+ if (shouldContinue) {
47
+ try {
48
+ const response = await schemaServiceClient.updateMesh(
49
+ imsOrgId,
50
+ projectId,
51
+ workspaceId,
52
+ args.meshId,
53
+ data,
54
+ );
51
55
 
52
- return response;
53
- } catch (error) {
54
- this.log(error.message);
56
+ this.log('Successfully updated the mesh with the id: %s', args.meshId);
55
57
 
56
- this.error(
57
- `Unable to update the mesh. Please check the mesh configuration file and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
58
- );
58
+ return response;
59
+ } catch (error) {
60
+ this.log(error.message);
61
+
62
+ this.error(
63
+ `Unable to update the mesh. Please check the mesh configuration file and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
64
+ );
65
+ }
66
+ } else {
67
+ this.log('Update cancelled');
68
+
69
+ return 'Update cancelled';
59
70
  }
60
71
  }
61
72
  }
package/src/helpers.js CHANGED
@@ -9,19 +9,21 @@ OF ANY KIND, either express or implied. See the License for the specific languag
9
9
  governing permissions and limitations under the License.
10
10
  */
11
11
 
12
+ const fs = require('fs');
13
+ const inquirer = require('inquirer');
14
+
12
15
  const Config = require('@adobe/aio-lib-core-config');
13
16
  const { getToken, context } = require('@adobe/aio-lib-ims');
14
17
  const { CLI } = require('@adobe/aio-lib-ims/src/context');
15
- const fs = require('fs');
16
18
  const libConsoleCLI = require('@adobe/aio-cli-lib-console');
17
- const { SchemaServiceClient } = require('./classes/SchemaServiceClient');
18
19
  const { getCliEnv } = require('@adobe/aio-lib-env');
20
+ const aioConsoleLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-api-mesh', {
21
+ provider: 'debug',
22
+ });
23
+
24
+ const { SchemaServiceClient } = require('./classes/SchemaServiceClient');
19
25
  const logger = require('../src/classes/logger');
20
26
  const { UUID } = require('./classes/UUID');
21
- const aioConsoleLogger = require('@adobe/aio-lib-core-logging')(
22
- '@adobe/aio-cli-plugin-api-mesh',
23
- { provider: 'debug' },
24
- );
25
27
 
26
28
  const CONSOLE_API_KEYS = {
27
29
  prod: 'aio-cli-console-auth',
@@ -190,7 +192,30 @@ async function initRequestId() {
190
192
  global.requestId = UUID.newUuid().toString();
191
193
  }
192
194
 
195
+ /**
196
+ * Function to run the CLI Y/N prompt to confirm the user's action
197
+ *
198
+ * @param {string} message
199
+ *
200
+ * @returns boolean
201
+ */
202
+ async function promptConfirm(message) {
203
+ const prompt = inquirer.createPromptModule({ output: process.stderr });
204
+
205
+ const confirm = await prompt([
206
+ {
207
+ type: 'confirm',
208
+ name: 'res',
209
+ message,
210
+ },
211
+ ]);
212
+
213
+ return confirm.res;
214
+ }
215
+
193
216
  module.exports = {
217
+ promptConfirm,
218
+ getLibConsoleCLI,
194
219
  getDevConsoleConfig,
195
220
  initSdk,
196
221
  initRequestId,