Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/3.7.0 Edge GA #163

Merged
merged 18 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adobe/aio-cli-plugin-api-mesh",
"version": "3.6.1",
"version": "3.7.0",
"description": "Adobe I/O CLI plugin to develop and manage API mesh sources",
"keywords": [
"oclif-plugin"
Expand Down
69 changes: 46 additions & 23 deletions src/commands/api-mesh/__tests__/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ jest.mock('../../../lib/devConsole');
jest.mock('chalk', () => ({
red: jest.fn(text => text), // Return the input text without any color formatting
bold: jest.fn(text => text),
underline: {
blue: jest.fn(text => text),
},
bgYellow: jest.fn(text => text),
}));
jest.mock('crypto');

Expand Down Expand Up @@ -409,10 +413,23 @@ describe('create command tests', () => {
"dummy_api_key",
],
[
"Mesh Endpoint: %s
"
API Mesh now runs at the edge and legacy mesh URLs will be deprecated.
Use the following link to find more information on how to migrate your mesh:",
],
[
"https://developer.adobe.com/graphql-mesh-gateway/mesh/release/migration
",
],
[
"Legacy Mesh Endpoint: %s",
"https://graph.adobe.io/api/dummy_mesh_id/graphql?api_key=dummy_api_key",
],
[
"Edge Mesh Endpoint: %s
",
"https://edge-sandbox-graph.adobe.io/api/dummy_mesh_id/graphql",
],
]
`);
expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`[]`);
Expand Down Expand Up @@ -502,10 +519,23 @@ describe('create command tests', () => {
"dummy_api_key",
],
[
"Mesh Endpoint: %s
"
API Mesh now runs at the edge and legacy mesh URLs will be deprecated.
Use the following link to find more information on how to migrate your mesh:",
],
[
"https://developer.adobe.com/graphql-mesh-gateway/mesh/release/migration
",
],
[
"Legacy Mesh Endpoint: %s",
"https://tigraph.adobe.io/dummy_mesh_id/graphql",
],
[
"Edge Mesh Endpoint: %s
",
"https://edge-sandbox-graph.adobe.io/api/dummy_mesh_id/graphql",
],
]
`);
expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`[]`);
Expand Down Expand Up @@ -693,10 +723,23 @@ describe('create command tests', () => {
"dummy_api_key",
],
[
"Mesh Endpoint: %s
"
API Mesh now runs at the edge and legacy mesh URLs will be deprecated.
Use the following link to find more information on how to migrate your mesh:",
],
[
"https://developer.adobe.com/graphql-mesh-gateway/mesh/release/migration
",
],
[
"Legacy Mesh Endpoint: %s",
"https://graph.adobe.io/api/dummy_mesh_id/graphql?api_key=dummy_api_key",
],
[
"Edge Mesh Endpoint: %s
",
"https://edge-sandbox-graph.adobe.io/api/dummy_mesh_id/graphql",
],
]
`);
expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`[]`);
Expand Down Expand Up @@ -1883,26 +1926,6 @@ describe('create command tests', () => {
);
});

test('should not show edge mesh url if feature is disabled', async () => {
// mock the edge mesh url feature to be disabled
getTenantFeatures.mockResolvedValueOnce({
imsOrgId: selectedOrg.code,
showCloudflareURL: false,
});

await CreateCommand.run();

expect(logSpy).not.toHaveBeenCalledWith(
expect.stringContaining('Edge Mesh Endpoint:'),
expect.any(String),
);

expect(logSpy).toHaveBeenCalledWith(
expect.stringContaining('Mesh Endpoint:'),
'https://graph.adobe.io/api/dummy_mesh_id/graphql?api_key=dummy_api_key',
);
});

test('should return error if mesh has placeholders and the provided secrets file is invalid', async () => {
parseSpy.mockResolvedValueOnce({
args: { file: 'src/commands/__fixtures__/sample_secrets_mesh.json' },
Expand Down
84 changes: 61 additions & 23 deletions src/commands/api-mesh/__tests__/describe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ jest.mock('@adobe/aio-cli-lib-console', () => ({
cleanStdOut: jest.fn(),
}));
jest.mock('../../../lib/devConsole');
jest.mock('chalk', () => ({
bold: jest.fn(text => text), // Return the input text without any color formatting
underline: {
blue: jest.fn(text => text),
},
bgYellow: jest.fn(text => text),
}));

const DescribeCommand = require('../describe');
const { initSdk, initRequestId } = require('../../../helpers');
Expand Down Expand Up @@ -179,10 +186,27 @@ describe('describe command tests', () => {
"dummy_meshId",
],
[
"Mesh Endpoint: %s
"
API Mesh now runs at the edge and legacy mesh URLs will be deprecated.
Use the following link to find more information on how to migrate your mesh:",
],
[
"https://developer.adobe.com/graphql-mesh-gateway/mesh/release/migration
",
],
[
"Legacy Mesh Endpoint: %s",
"https://graph.adobe.io/api/dummy_meshId/graphql",
],
[
"Edge Mesh Endpoint: %s
",
"https://edge-sandbox-graph.adobe.io/api/dummy_meshId/graphql",
],
[
"Update your mesh before using the edge mesh endpoint.
You can validate your edge mesh status using the aio api-mesh status command.",
],
]
`);
expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`[]`);
Expand Down Expand Up @@ -227,10 +251,27 @@ describe('describe command tests', () => {
"dummy_meshId",
],
[
"Mesh Endpoint: %s
"
API Mesh now runs at the edge and legacy mesh URLs will be deprecated.
Use the following link to find more information on how to migrate your mesh:",
],
[
"https://developer.adobe.com/graphql-mesh-gateway/mesh/release/migration
",
],
[
"Legacy Mesh Endpoint: %s",
"https://graph.adobe.io/api/dummy_meshId/graphql?api_key=dummy_apiKey",
],
[
"Edge Mesh Endpoint: %s
",
"https://edge-sandbox-graph.adobe.io/api/dummy_meshId/graphql",
],
[
"Update your mesh before using the edge mesh endpoint.
You can validate your edge mesh status using the aio api-mesh status command.",
],
]
`);
});
Expand Down Expand Up @@ -279,10 +320,27 @@ describe('describe command tests', () => {
"dummy_meshId",
],
[
"Mesh Endpoint: %s
"
API Mesh now runs at the edge and legacy mesh URLs will be deprecated.
Use the following link to find more information on how to migrate your mesh:",
],
[
"https://developer.adobe.com/graphql-mesh-gateway/mesh/release/migration
",
],
[
"Legacy Mesh Endpoint: %s",
"https://tigraph.adobe.io/dummy_meshId/graphql",
],
[
"Edge Mesh Endpoint: %s
",
"https://edge-sandbox-graph.adobe.io/api/dummy_meshId/graphql",
],
[
"Update your mesh before using the edge mesh endpoint.
You can validate your edge mesh status using the aio api-mesh status command.",
],
]
`);
expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`[]`);
Expand Down Expand Up @@ -337,24 +395,4 @@ describe('describe command tests', () => {
'https://edge-sandbox-graph.adobe.io/api/dummy_meshId/graphql',
);
});

test('should not show edge mesh url if feature is disabled', async () => {
// mock the edge mesh url feature to be disabled
getTenantFeatures.mockResolvedValueOnce({
imsOrgId: selectedOrg.code,
showCloudflareURL: false,
});

await DescribeCommand.run();

expect(logSpy).not.toHaveBeenCalledWith(
expect.stringContaining('Edge Mesh Endpoint:'),
expect.any(String),
);

expect(logSpy).toHaveBeenCalledWith(
expect.stringContaining('Mesh Endpoint:'),
'https://graph.adobe.io/api/dummy_meshId/graphql?api_key=dummy_apiKey',
);
});
});
24 changes: 14 additions & 10 deletions src/commands/api-mesh/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const {
validateSecretsFile,
encryptSecrets,
} = require('../../utils');
const { createMesh, getTenantFeatures, getPublicEncryptionKey } = require('../../lib/devConsole');
const { createMesh, getPublicEncryptionKey } = require('../../lib/devConsole');
const { buildEdgeMeshUrl, buildMeshUrl } = require('../../urlBuilder');

class CreateCommand extends Command {
Expand Down Expand Up @@ -170,15 +170,19 @@ class CreateCommand extends Command {
apiKey,
);

const { showCloudflareURL: showEdgeMeshUrl } = await getTenantFeatures(imsOrgCode);

if (showEdgeMeshUrl) {
const edgeMeshUrl = buildEdgeMeshUrl(mesh.meshId, workspaceName);
this.log('Legacy Mesh Endpoint: %s', meshUrl);
this.log(chalk.bold('Edge Mesh Endpoint: %s\n'), edgeMeshUrl);
} else {
this.log('Mesh Endpoint: %s\n', meshUrl);
}
const edgeMeshUrl = buildEdgeMeshUrl(mesh.meshId, workspaceName);
this.log(
chalk.bgYellow(
`\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:`,
),
);
this.log(
chalk.underline.blue(
'https://developer.adobe.com/graphql-mesh-gateway/mesh/release/migration\n',
),
);
this.log('Legacy Mesh Endpoint: %s', meshUrl);
this.log(chalk.bold('Edge Mesh Endpoint: %s\n'), edgeMeshUrl);
} else {
this.log('Unable to subscribe API Key %s to API Mesh service', apiKey);
}
Expand Down
31 changes: 20 additions & 11 deletions src/commands/api-mesh/describe.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const chalk = require('chalk');
const logger = require('../../classes/logger');
const { initSdk, initRequestId } = require('../../helpers');
const { ignoreCacheFlag } = require('../../utils');
const { describeMesh, getTenantFeatures } = require('../../lib/devConsole');
const { describeMesh } = require('../../lib/devConsole');
const { buildMeshUrl, buildEdgeMeshUrl } = require('../../urlBuilder');

require('dotenv').config();
Expand All @@ -32,7 +32,7 @@ class DescribeCommand extends Command {

const { flags } = await this.parse(DescribeCommand);
const ignoreCache = await flags.ignoreCache;
const { imsOrgId, imsOrgCode, projectId, workspaceId, workspaceName } = await initSdk({
const { imsOrgId, projectId, workspaceId, workspaceName } = await initSdk({
ignoreCache,
});

Expand All @@ -41,7 +41,6 @@ class DescribeCommand extends Command {

if (meshDetails) {
const { meshId, apiKey } = meshDetails;
const { showCloudflareURL: showEdgeMeshUrl } = await getTenantFeatures(imsOrgCode);

if (meshId) {
const meshUrl = await buildMeshUrl(
Expand All @@ -59,14 +58,24 @@ class DescribeCommand extends Command {
this.log('Workspace ID: %s', workspaceId);
this.log('Mesh ID: %s', meshId);

if (showEdgeMeshUrl) {
const edgeMeshUrl = buildEdgeMeshUrl(meshId, workspaceName);
this.log('Legacy Mesh Endpoint: %s', meshUrl);
this.log(chalk.bold('Edge Mesh Endpoint: %s\n'), edgeMeshUrl);
} else {
this.log('Mesh Endpoint: %s\n', meshUrl);
}

const edgeMeshUrl = buildEdgeMeshUrl(meshId, workspaceName);
this.log(
chalk.bgYellow(
`\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:`,
),
);
this.log(
chalk.underline.blue(
'https://developer.adobe.com/graphql-mesh-gateway/mesh/release/migration\n',
),
);
this.log('Legacy Mesh Endpoint: %s', meshUrl);
this.log(chalk.bold('Edge Mesh Endpoint: %s\n'), edgeMeshUrl);
this.log(
chalk.bgYellow(
'Update your mesh before using the edge mesh endpoint.\nYou can validate your edge mesh status using the aio api-mesh status command.',
),
);
return meshDetails;
} else {
logger.error(
Expand Down
24 changes: 13 additions & 11 deletions src/commands/api-mesh/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ const chalk = require('chalk');

const logger = require('../../classes/logger');
const { initRequestId, initSdk } = require('../../helpers');
const {
getMeshId,
getMesh,
getTenantFeatures,
getMeshDeployments,
} = require('../../lib/devConsole');
const { getMeshId, getMesh, getMeshDeployments } = require('../../lib/devConsole');
const { ignoreCacheFlag } = require('../../utils');

require('dotenv').config();
Expand Down Expand Up @@ -41,15 +36,22 @@ class StatusCommand extends Command {

if (meshId) {
try {
const { showCloudflareURL: showEdgeMeshUrl } = await getTenantFeatures(imsOrgCode);
const mesh = await getMesh(imsOrgId, projectId, workspaceId, workspaceName, meshId);
const meshLabel = showEdgeMeshUrl ? chalk.bold(`Legacy Mesh:`) : 'Your mesh';
this.log(
chalk.bgYellow(
`\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:`,
),
);
this.log(
chalk.underline.blue(
'https://developer.adobe.com/graphql-mesh-gateway/mesh/release/migration\n',
),
);
const meshLabel = chalk.bold(`Legacy Mesh:`);

this.log(''.padEnd(102, '*'));
this.displayMeshStatus(mesh, meshLabel);
if (showEdgeMeshUrl) {
await this.displayEdgeMeshStatus(mesh, imsOrgCode, projectId, workspaceId);
}
await this.displayEdgeMeshStatus(mesh, imsOrgCode, projectId, workspaceId);
this.log(''.padEnd(102, '*'));
} catch (err) {
this.log(err.message);
Expand Down
1 change: 1 addition & 0 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
plugins: tenantMesh.plugins,
graphqlEndpoint: `/graphql`,
graphiql: true,
maskedErrors: false,
cors: corsOptions,
context: initialContext => ({
...initialContext,
Expand Down Expand Up @@ -190,10 +191,10 @@
}
yogaServer = await getYogaServer();
} catch (error) {
console.error(error);

Check warning on line 194 in src/server.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check warning on line 194 in src/server.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check warning on line 194 in src/server.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check warning on line 194 in src/server.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check warning on line 194 in src/server.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check warning on line 194 in src/server.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check warning on line 194 in src/server.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check warning on line 194 in src/server.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check warning on line 194 in src/server.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
process.exit(1);
}

console.log(`Server is running on http://localhost:${portNo}/graphql`);

Check warning on line 198 in src/server.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check warning on line 198 in src/server.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check warning on line 198 in src/server.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check warning on line 198 in src/server.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check warning on line 198 in src/server.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check warning on line 198 in src/server.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check warning on line 198 in src/server.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check warning on line 198 in src/server.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check warning on line 198 in src/server.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
},
);
Loading