@adobe/aio-cli-plugin-api-mesh 3.9.4-beta → 4.0.0-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.
@@ -1,5 +1,4 @@
1
1
  const { Command } = require('@oclif/core');
2
- const chalk = require('chalk');
3
2
 
4
3
  const logger = require('../../classes/logger');
5
4
  const { initRequestId, initSdk } = require('../../helpers');
@@ -28,123 +27,111 @@ class StatusCommand extends Command {
28
27
  try {
29
28
  meshId = await getMeshId(imsOrgId, projectId, workspaceId, workspaceName);
30
29
  } catch (err) {
30
+ // API Request failed
31
31
  this.log(err.message);
32
32
  this.error(
33
33
  `Unable to get mesh ID. Please check the details and try again. RequestId: ${global.requestId}`,
34
34
  );
35
35
  }
36
36
 
37
- if (meshId) {
38
- try {
39
- const mesh = await getMesh(imsOrgId, projectId, workspaceId, workspaceName, meshId);
40
- this.log(
41
- chalk.bgYellow(
42
- `\nAPI Mesh now runs at the edge and legacy mesh URLs will be deprecated.\nUse the following link to find more information on how to migrate your mesh:`,
43
- ),
44
- );
45
- this.log(
46
- chalk.underline.blue(
47
- 'https://developer.adobe.com/graphql-mesh-gateway/mesh/release/migration\n',
48
- ),
49
- );
50
- const meshLabel = chalk.bold(`Legacy Mesh:`);
51
-
52
- this.log(''.padEnd(102, '*'));
53
- this.displayMeshStatus(mesh, meshLabel);
54
- await this.displayEdgeMeshStatus(mesh, imsOrgCode, projectId, workspaceId);
55
- this.log(''.padEnd(102, '*'));
56
- } catch (err) {
57
- this.log(err.message);
58
- this.error(
59
- `Unable to get the mesh status. If the error persists please contact support. RequestId: ${global.requestId}`,
60
- );
61
- }
62
- } else {
37
+ // API Request succeeded, but mesh could not be found
38
+ if (!meshId) {
63
39
  this.error(
64
40
  `Unable to get mesh status. No mesh found for Org(${imsOrgId}) -> Project(${projectId}) -> Workspace(${workspaceId}). Please check the details and try again.`,
65
41
  );
66
42
  }
43
+
44
+ try {
45
+ const mesh = await getMesh(imsOrgId, projectId, workspaceId, workspaceName, meshId);
46
+ this.log(''.padEnd(102, '*'));
47
+ await this.displayMeshStatus(mesh, imsOrgCode, projectId, workspaceId);
48
+ this.log(''.padEnd(102, '*'));
49
+ } catch (err) {
50
+ // Error occurred while fetching/displaying the mesh status
51
+ this.error(
52
+ `Unable to get mesh status. If this error persists, contact support. RequestId: ${global.requestId}`,
53
+ );
54
+ }
67
55
  }
68
56
 
69
57
  /**
70
58
  * Display the status of the mesh.
71
59
  *
60
+ * While the mesh is not successfully built, display a message based on the build status.
61
+ * Once the build is successful, display a message based on the deployment status.
62
+ * @param mesh
63
+ * @param imsOrgCode
64
+ * @param projectId
65
+ * @param workspaceId
66
+ * @returns {Promise<void>}
67
+ */
68
+ async displayMeshStatus(mesh, imsOrgCode, projectId, workspaceId) {
69
+ if (mesh.meshStatus !== 'success') {
70
+ this.displayMeshBuildStatus(mesh);
71
+ } else {
72
+ await this.displayMeshDeploymentStatus(mesh, imsOrgCode, projectId, workspaceId);
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Display the status of the mesh build.
78
+ *
72
79
  * @param mesh - Mesh data
73
- * @param meshLabel - Label to display for the mesh based on the mesh type
74
80
  */
75
- displayMeshStatus(mesh, meshLabel = 'Your mesh') {
81
+ displayMeshBuildStatus(mesh) {
76
82
  switch (mesh.meshStatus) {
77
- case 'success':
78
- this.log(`${meshLabel} has been successfully built.`);
79
- break;
80
83
  case 'pending':
81
- this.log(`${meshLabel} is awaiting processing.`);
84
+ this.log('Mesh is awaiting processing.');
82
85
  break;
83
86
  case 'building':
84
- this.log(
85
- `${meshLabel} is currently being provisioned. Please wait a few minutes before checking again.`,
86
- );
87
+ this.log('Mesh is currently building. Wait a few minutes before checking again.');
87
88
  break;
88
89
  case 'error':
89
- this.log(
90
- meshLabel === 'Your mesh'
91
- ? `${meshLabel} errored out with the following error.`
92
- : `${meshLabel} build has errors.`,
93
- );
90
+ this.log('Mesh build has errors.');
94
91
  this.log(mesh.error);
95
92
  break;
93
+ default:
94
+ this.log('Mesh status is not available. Wait a few minutes and try again.');
95
+ break;
96
96
  }
97
97
  }
98
98
 
99
99
  /**
100
- * Display the status of the edge mesh.
100
+ * Display the status of the mesh deployment.
101
101
  *
102
- * While the mesh is not successfully built, the edge mesh status will match the legacy mesh status.
103
- * Once the build is successful, the edge mesh status will reflect the deployment status
104
102
  * @param mesh
105
103
  * @param imsOrgCode
106
104
  * @param projectId
107
105
  * @param workspaceId
108
106
  * @returns {Promise<void>}
109
107
  */
110
- async displayEdgeMeshStatus(mesh, imsOrgCode, projectId, workspaceId) {
111
- const edgeMeshLabel = chalk.bold(`Edge Mesh:`);
112
- const buildStatus = mesh.meshStatus;
113
-
114
- if (buildStatus !== 'success') {
115
- this.displayMeshStatus(mesh, edgeMeshLabel);
116
- } else {
117
- const meshDeployments = await getMeshDeployments(
118
- imsOrgCode,
119
- projectId,
120
- workspaceId,
121
- mesh.meshId,
122
- );
123
-
124
- const edgeDeploymentStatus = String(meshDeployments.status).toLowerCase();
125
-
126
- switch (edgeDeploymentStatus) {
127
- case 'success':
128
- this.log(`${edgeMeshLabel} has been successfully built.`);
129
- break;
130
- case 'provisioning':
131
- this.log(
132
- `${edgeMeshLabel} is currently being provisioned. Please wait a few minutes before checking again.`,
133
- );
134
- break;
135
- case 'de-provisioning':
136
- this.log(
137
- `${edgeMeshLabel} is currently being de-provisioned. Please wait a few minutes before checking again.`,
138
- );
139
- break;
140
- case 'error':
141
- this.log(`${edgeMeshLabel} ${meshDeployments.error}`);
142
- break;
143
- default:
144
- this.log(
145
- `${edgeMeshLabel} status is not available. Please wait for a while and try again.`,
146
- );
147
- }
108
+ async displayMeshDeploymentStatus(mesh, imsOrgCode, projectId, workspaceId) {
109
+ const meshDeployments = await getMeshDeployments(
110
+ imsOrgCode,
111
+ projectId,
112
+ workspaceId,
113
+ mesh.meshId,
114
+ );
115
+
116
+ const meshDeploymentStatus = String(meshDeployments.status).toLowerCase();
117
+
118
+ switch (meshDeploymentStatus) {
119
+ case 'provisioning':
120
+ this.log('Currently provisioning your mesh. Wait a few minutes and try again.');
121
+ break;
122
+ case 'de-provisioning':
123
+ this.log('Currently de-provisioning your mesh. Wait a few minutes and try again.');
124
+ break;
125
+ case 'success':
126
+ this.log('Mesh was built successfully.');
127
+ break;
128
+ case 'error':
129
+ this.log('Mesh build has errors.');
130
+ this.log(meshDeployments.error);
131
+ break;
132
+ default:
133
+ this.log('Mesh status is not available. Wait a few minutes and try again.');
134
+ break;
148
135
  }
149
136
  }
150
137
  }
package/src/constants.js CHANGED
@@ -3,24 +3,22 @@ const { getCliEnv } = require('@adobe/aio-lib-env');
3
3
  const clientEnv = getCliEnv();
4
4
 
5
5
  const StageConstants = {
6
- MULTITENANT_GRAPHQL_SERVER_BASE_URL: 'https://graph-stage.adobe.io/api',
7
6
  DEV_CONSOLE_BASE_URL: 'https://developers-stage.adobe.io/console',
8
7
  DEV_CONSOLE_API_KEY: 'adobe-api-manager-sms-stage',
9
8
  DEV_CONSOLE_TRANSPORTER_API_KEY: 'UDPWeb1',
10
9
  AIO_CLI_API_KEY: 'aio-cli-console-auth-stage',
11
10
  SMS_BASE_URL: 'https://graph-stage.adobe.io/api-admin',
12
- EDGE_MESH_BASE_URL: 'https://edge-stage-graph.adobe.io/api',
11
+ MESH_BASE_URL: 'https://edge-stage-graph.adobe.io/api',
13
12
  };
14
13
 
15
14
  const ProdConstants = {
16
- MULTITENANT_GRAPHQL_SERVER_BASE_URL: 'https://graph.adobe.io/api',
17
15
  DEV_CONSOLE_BASE_URL: 'https://developers.adobe.io/console',
18
16
  DEV_CONSOLE_API_KEY: 'adobe-graph-prod',
19
17
  DEV_CONSOLE_TRANSPORTER_API_KEY: 'UDPWeb1',
20
18
  AIO_CLI_API_KEY: 'aio-cli-console-auth',
21
19
  SMS_BASE_URL: 'https://graph.adobe.io/api-admin',
22
- EDGE_MESH_BASE_URL: 'https://edge-graph.adobe.io/api',
23
- EDGE_MESH_SANDBOX_BASE_URL: 'https://edge-sandbox-graph.adobe.io/api',
20
+ MESH_BASE_URL: 'https://edge-graph.adobe.io/api',
21
+ MESH_SANDBOX_BASE_URL: 'https://edge-sandbox-graph.adobe.io/api',
24
22
  };
25
23
 
26
24
  const envConstants = clientEnv === 'stage' ? StageConstants : ProdConstants;
@@ -90,21 +90,11 @@ const describeMesh = async (organizationId, projectId, workspaceId, workspaceNam
90
90
 
91
91
  logger.info('Response from getMeshId %s', meshId);
92
92
 
93
- if (meshId) {
94
- const credential = await getApiKeyCredential(organizationId, projectId, workspaceId);
95
-
96
- if (credential) {
97
- return { meshId, apiKey: credential.client_id };
98
- } else {
99
- logger.error('API Key credential not found on workspace');
100
-
101
- return { meshId, apiKey: null };
102
- }
103
- } else {
104
- logger.error(`Unable to retrieve meshId.`);
105
-
93
+ if (!meshId) {
106
94
  throw new Error(`Unable to retrieve meshId.`);
107
95
  }
96
+
97
+ return { meshId };
108
98
  } catch (error) {
109
99
  logger.error(error);
110
100
 
@@ -270,42 +260,8 @@ const createMesh = async (
270
260
  if (response && response.status === 201) {
271
261
  logger.info(`Mesh Config : ${objToString(response, ['data'])}`);
272
262
 
273
- let sdkList = [];
274
- let credential;
275
- let isApiKeyNew = false;
276
-
277
- credential = await getApiKeyCredential(organizationId, projectId, workspaceId);
278
- if (!credential) {
279
- logger.info('API Key credential not found on workspace');
280
-
281
- // try to create a new API key credential
282
- credential = await createAPIMeshCredentials(organizationId, projectId, workspaceId);
283
- isApiKeyNew = true;
284
- }
285
- // subscribe the credential to API mesh service
286
- sdkList = await subscribeCredentialToMeshService(
287
- organizationId,
288
- projectId,
289
- workspaceId,
290
- isApiKeyNew ? credential.id : credential.id_integration,
291
- );
292
- const newlyCreatedOrExistingApiKey = isApiKeyNew ? credential.apiKey : credential.client_id;
293
-
294
- if (sdkList) {
295
- logger.info(
296
- 'Successfully subscribed API Key %s to API Mesh service',
297
- isApiKeyNew ? credential.apiKey : credential.client_id,
298
- );
299
- } else {
300
- logger.error(
301
- 'Unable to subscribe API Key %s to API Mesh service',
302
- newlyCreatedOrExistingApiKey,
303
- );
304
- }
305
263
  return {
306
264
  mesh: response.data,
307
- apiKey: newlyCreatedOrExistingApiKey,
308
- sdkList,
309
265
  };
310
266
  } else {
311
267
  // Non 201 response received
@@ -586,7 +542,7 @@ const getMeshId = async (organizationId, projectId, workspaceId, workspaceName)
586
542
  logger.info('Response from GET %s', response.status);
587
543
 
588
544
  if (response && response.status === 200) {
589
- logger.info(`Mesh Config : ${objToString(response, ['data'])}`);
545
+ logger.debug(`Mesh response data : ${objToString(response, ['data'])}`);
590
546
 
591
547
  return response.data.meshId;
592
548
  } else {
@@ -1000,9 +956,9 @@ const getMeshDeployments = async (organizationCode, projectId, workspaceId, mesh
1000
956
  logger.error(`Error fetching deployments for mesh: ${meshId}`);
1001
957
 
1002
958
  return {
1003
- status: 'ERROR',
959
+ status: null,
1004
960
  meshId: meshId,
1005
- error: 'Mesh status is not available.',
961
+ error: null,
1006
962
  };
1007
963
  }
1008
964
  };
@@ -26,8 +26,8 @@
26
26
  "@graphql-mesh/soap": "0.14.25",
27
27
  "@graphql-mesh/http": "^0.96.9",
28
28
  "graphql": "^16.6.0",
29
- "@adobe/plugin-hooks": "0.3.2-beta",
30
- "@adobe/plugin-on-fetch": "0.1.1-alpha",
29
+ "@adobe/plugin-hooks": "0.3.2",
30
+ "@adobe/plugin-on-fetch": "0.1.1",
31
31
  "eslint-plugin-no-loops": "^0.3.0",
32
32
  "eslint-plugin-node": "^11.1.0",
33
33
  "eslint-plugin-security": "^1.5.0",
package/src/urlBuilder.js CHANGED
@@ -1,39 +1,6 @@
1
1
  const CONSTANTS = require('./constants');
2
- const { getMesh } = require('./lib/devConsole');
3
2
 
4
- const {
5
- MULTITENANT_GRAPHQL_SERVER_BASE_URL,
6
- EDGE_MESH_BASE_URL,
7
- EDGE_MESH_SANDBOX_BASE_URL,
8
- } = CONSTANTS;
9
-
10
- /**
11
- * Build the mesh url for the multitenant mesh.
12
- *
13
- * Gets the mesh details to checks for a custom domain in the case of a TI mesh.
14
- * @param imsOrgId
15
- * @param projectId
16
- * @param workspaceId
17
- * @param workspaceName
18
- * @param meshId
19
- * @param apiKey
20
- * @returns {Promise<string>}
21
- */
22
- async function buildMeshUrl(imsOrgId, projectId, workspaceId, workspaceName, meshId, apiKey) {
23
- const { meshURL: customBaseUrl } = await getMesh(
24
- imsOrgId,
25
- projectId,
26
- workspaceId,
27
- workspaceName,
28
- meshId,
29
- );
30
-
31
- return customBaseUrl
32
- ? `${customBaseUrl}/${meshId}/graphql`
33
- : `${MULTITENANT_GRAPHQL_SERVER_BASE_URL}/${meshId}/graphql${
34
- apiKey ? `?api_key=${apiKey}` : ''
35
- }`;
36
- }
3
+ const { MESH_BASE_URL, MESH_SANDBOX_BASE_URL } = CONSTANTS;
37
4
 
38
5
  /**
39
6
  * Builds the mesh url for the edge mesh.
@@ -43,16 +10,16 @@ async function buildMeshUrl(imsOrgId, projectId, workspaceId, workspaceName, mes
43
10
  * @param workspaceName
44
11
  * @returns {string}
45
12
  */
46
- function buildEdgeMeshUrl(meshId, workspaceName) {
13
+ function buildMeshUrl(meshId, workspaceName) {
47
14
  let baseUrl;
48
15
 
49
- if (EDGE_MESH_BASE_URL.includes('stage')) {
50
- baseUrl = EDGE_MESH_BASE_URL;
16
+ if (MESH_BASE_URL.includes('stage')) {
17
+ baseUrl = MESH_BASE_URL;
51
18
  } else {
52
- baseUrl = workspaceName === 'Production' ? EDGE_MESH_BASE_URL : EDGE_MESH_SANDBOX_BASE_URL;
19
+ baseUrl = workspaceName === 'Production' ? MESH_BASE_URL : MESH_SANDBOX_BASE_URL;
53
20
  }
54
21
 
55
22
  return `${baseUrl}/${meshId}/graphql`;
56
23
  }
57
24
 
58
- module.exports = { buildMeshUrl, buildEdgeMeshUrl };
25
+ module.exports = { buildMeshUrl };