@adobe/aio-cli-plugin-api-mesh 4.1.1-beta.1 → 5.0.0-alpha
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/oclif.manifest.json +1 -1
- package/package.json +3 -13
- package/src/commands/api-mesh/__tests__/create.test.js +217 -293
- package/src/commands/api-mesh/__tests__/delete.test.js +6 -6
- package/src/commands/api-mesh/__tests__/describe.test.js +2 -17
- package/src/commands/api-mesh/__tests__/get.test.js +9 -78
- package/src/commands/api-mesh/__tests__/log-get-bulk.test.js +1 -1
- package/src/commands/api-mesh/__tests__/run.test.js +22 -25
- package/src/commands/api-mesh/__tests__/status.test.js +1 -1
- package/src/commands/api-mesh/__tests__/update.test.js +8 -9
- package/src/commands/api-mesh/create.js +6 -9
- package/src/commands/api-mesh/delete.js +5 -5
- package/src/commands/api-mesh/describe.js +3 -3
- package/src/commands/api-mesh/get.js +8 -11
- package/src/commands/api-mesh/init.js +0 -2
- package/src/commands/api-mesh/log-get-bulk.js +2 -2
- package/src/commands/api-mesh/log-get.js +2 -2
- package/src/commands/api-mesh/log-list.js +1 -1
- package/src/commands/api-mesh/run.js +9 -35
- package/src/commands/api-mesh/source/install.js +3 -2
- package/src/commands/api-mesh/status.js +4 -6
- package/src/commands/api-mesh/update.js +7 -9
- package/src/constants.js +2 -0
- package/src/helpers.js +4 -71
- package/src/lib/devConsole.js +38 -32
- package/src/server.js +198 -36
- package/src/serverUtils.js +3 -3
- package/src/cors.js +0 -28
- package/src/fixPlugins.js +0 -28
- package/src/hooks/versionCompare.js +0 -23
- package/src/index.js +0 -44
- package/src/plugins/complianceHeaders/complianceHeaders.js +0 -55
- package/src/plugins/complianceHeaders/index.js +0 -2
- package/src/plugins/httpDetailsExtensions/LICENSE +0 -21
- package/src/plugins/httpDetailsExtensions/index.js +0 -81
- package/src/secrets.js +0 -34
- package/src/served.js +0 -22
- package/src/templates/wrangler.toml +0 -14
- package/src/utils/logger.js +0 -42
- package/src/utils/requestId.js +0 -26
- package/src/wranglerServer.js +0 -80
package/src/lib/devConsole.js
CHANGED
|
@@ -12,7 +12,7 @@ const exec = util.promisify(require('child_process').exec);
|
|
|
12
12
|
const contentDisposition = require('content-disposition');
|
|
13
13
|
const chalk = require('chalk');
|
|
14
14
|
|
|
15
|
-
const { DEV_CONSOLE_TRANSPORTER_API_KEY, SMS_BASE_URL } = CONSTANTS;
|
|
15
|
+
const { DEV_CONSOLE_TRANSPORTER_API_KEY, SMS_BASE_URL, SMS_API_KEY } = CONSTANTS;
|
|
16
16
|
|
|
17
17
|
const { objToString, getDevConsoleConfig } = require('../helpers');
|
|
18
18
|
|
|
@@ -113,7 +113,7 @@ const describeMesh = async (organizationId, projectId, workspaceId, workspaceNam
|
|
|
113
113
|
* @returns
|
|
114
114
|
*/
|
|
115
115
|
const listLogs = async (organizationCode, projectId, workspaceId, meshId, fileName) => {
|
|
116
|
-
const { accessToken
|
|
116
|
+
const { accessToken } = await getDevConsoleConfig();
|
|
117
117
|
const url = `${SMS_BASE_URL}/organizations/${organizationCode}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}/logs/list`;
|
|
118
118
|
const config = {
|
|
119
119
|
method: 'get',
|
|
@@ -121,7 +121,7 @@ const listLogs = async (organizationCode, projectId, workspaceId, meshId, fileNa
|
|
|
121
121
|
headers: {
|
|
122
122
|
'Authorization': `Bearer ${accessToken}`,
|
|
123
123
|
'x-request-id': global.requestId,
|
|
124
|
-
'
|
|
124
|
+
'x-api-key': SMS_API_KEY,
|
|
125
125
|
},
|
|
126
126
|
};
|
|
127
127
|
|
|
@@ -142,20 +142,21 @@ const listLogs = async (organizationCode, projectId, workspaceId, meshId, fileNa
|
|
|
142
142
|
};
|
|
143
143
|
|
|
144
144
|
const getMesh = async (organizationId, projectId, workspaceId, workspaceName, meshId) => {
|
|
145
|
-
const {
|
|
145
|
+
const { accessToken } = await getDevConsoleConfig();
|
|
146
146
|
const config = {
|
|
147
147
|
method: 'get',
|
|
148
|
-
url: `${
|
|
148
|
+
url: `${SMS_BASE_URL}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}`,
|
|
149
149
|
headers: {
|
|
150
150
|
'Authorization': `Bearer ${accessToken}`,
|
|
151
151
|
'x-request-id': global.requestId,
|
|
152
152
|
'workspaceName': workspaceName,
|
|
153
|
+
'x-api-key': SMS_API_KEY,
|
|
153
154
|
},
|
|
154
155
|
};
|
|
155
156
|
|
|
156
157
|
logger.info(
|
|
157
158
|
'Initiating GET %s',
|
|
158
|
-
`${
|
|
159
|
+
`${SMS_BASE_URL}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}`,
|
|
159
160
|
);
|
|
160
161
|
|
|
161
162
|
try {
|
|
@@ -232,10 +233,10 @@ const createMesh = async (
|
|
|
232
233
|
projectName,
|
|
233
234
|
data,
|
|
234
235
|
) => {
|
|
235
|
-
const {
|
|
236
|
+
const { accessToken } = await getDevConsoleConfig();
|
|
236
237
|
const config = {
|
|
237
238
|
method: 'post',
|
|
238
|
-
url: `${
|
|
239
|
+
url: `${SMS_BASE_URL}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes`,
|
|
239
240
|
headers: {
|
|
240
241
|
'Authorization': `Bearer ${accessToken}`,
|
|
241
242
|
'Content-Type': 'application/json',
|
|
@@ -243,13 +244,14 @@ const createMesh = async (
|
|
|
243
244
|
'workspaceName': workspaceName,
|
|
244
245
|
'orgName': orgName,
|
|
245
246
|
'projectName': projectName,
|
|
247
|
+
'x-api-key': SMS_API_KEY,
|
|
246
248
|
},
|
|
247
249
|
data: JSON.stringify(data),
|
|
248
250
|
};
|
|
249
251
|
|
|
250
252
|
logger.info(
|
|
251
253
|
'Initiating POST %s',
|
|
252
|
-
`${
|
|
254
|
+
`${SMS_BASE_URL}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes`,
|
|
253
255
|
);
|
|
254
256
|
|
|
255
257
|
try {
|
|
@@ -343,10 +345,10 @@ const updateMesh = async (
|
|
|
343
345
|
meshId,
|
|
344
346
|
data,
|
|
345
347
|
) => {
|
|
346
|
-
const {
|
|
348
|
+
const { accessToken } = await getDevConsoleConfig();
|
|
347
349
|
const config = {
|
|
348
350
|
method: 'put',
|
|
349
|
-
url: `${
|
|
351
|
+
url: `${SMS_BASE_URL}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}`,
|
|
350
352
|
headers: {
|
|
351
353
|
'Authorization': `Bearer ${accessToken}`,
|
|
352
354
|
'Content-Type': 'application/json',
|
|
@@ -354,13 +356,14 @@ const updateMesh = async (
|
|
|
354
356
|
'workspaceName': workspaceName,
|
|
355
357
|
'orgName': orgName,
|
|
356
358
|
'projectName': projectName,
|
|
359
|
+
'x-api-key': SMS_API_KEY,
|
|
357
360
|
},
|
|
358
361
|
data: JSON.stringify(data),
|
|
359
362
|
};
|
|
360
363
|
|
|
361
364
|
logger.info(
|
|
362
365
|
'Initiating PUT %s',
|
|
363
|
-
`${
|
|
366
|
+
`${SMS_BASE_URL}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}`,
|
|
364
367
|
);
|
|
365
368
|
|
|
366
369
|
try {
|
|
@@ -433,19 +436,20 @@ const updateMesh = async (
|
|
|
433
436
|
};
|
|
434
437
|
|
|
435
438
|
const deleteMesh = async (organizationId, projectId, workspaceId, meshId) => {
|
|
436
|
-
const {
|
|
439
|
+
const { accessToken } = await getDevConsoleConfig();
|
|
437
440
|
const config = {
|
|
438
441
|
method: 'delete',
|
|
439
|
-
url: `${
|
|
442
|
+
url: `${SMS_BASE_URL}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}`,
|
|
440
443
|
headers: {
|
|
441
444
|
'Authorization': `Bearer ${accessToken}`,
|
|
442
445
|
'x-request-id': global.requestId,
|
|
446
|
+
'x-api-key': SMS_API_KEY,
|
|
443
447
|
},
|
|
444
448
|
};
|
|
445
449
|
|
|
446
450
|
logger.info(
|
|
447
451
|
'Initiating DELETE %s',
|
|
448
|
-
`${
|
|
452
|
+
`${SMS_BASE_URL}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}`,
|
|
449
453
|
);
|
|
450
454
|
|
|
451
455
|
try {
|
|
@@ -517,23 +521,24 @@ const deleteMesh = async (organizationId, projectId, workspaceId, meshId) => {
|
|
|
517
521
|
}
|
|
518
522
|
};
|
|
519
523
|
|
|
520
|
-
const getMeshId = async (
|
|
521
|
-
const {
|
|
524
|
+
const getMeshId = async (organizationCode, projectId, workspaceId, workspaceName) => {
|
|
525
|
+
const { accessToken } = await getDevConsoleConfig();
|
|
522
526
|
logger.info('Initiating Mesh ID request');
|
|
523
527
|
|
|
524
528
|
const config = {
|
|
525
529
|
method: 'get',
|
|
526
|
-
url: `${
|
|
530
|
+
url: `${SMS_BASE_URL}/organizations/${organizationCode}/projects/${projectId}/workspaces/${workspaceId}/mesh`,
|
|
527
531
|
headers: {
|
|
528
532
|
'Authorization': `Bearer ${accessToken}`,
|
|
529
533
|
'x-request-id': global.requestId,
|
|
530
534
|
'workspaceName': workspaceName,
|
|
535
|
+
'x-api-key': SMS_API_KEY,
|
|
531
536
|
},
|
|
532
537
|
};
|
|
533
538
|
|
|
534
539
|
logger.info(
|
|
535
540
|
'Initiating GET %s',
|
|
536
|
-
`${
|
|
541
|
+
`${SMS_BASE_URL}/organizations/${organizationCode}/projects/${projectId}/workspaces/${workspaceId}/mesh`,
|
|
537
542
|
);
|
|
538
543
|
|
|
539
544
|
try {
|
|
@@ -805,21 +810,22 @@ const unsubscribeCredentialFromMeshService = async (
|
|
|
805
810
|
};
|
|
806
811
|
|
|
807
812
|
const getMeshArtifact = async (organizationId, projectId, workspaceId, workspaceName, meshId) => {
|
|
808
|
-
const {
|
|
813
|
+
const { accessToken } = await getDevConsoleConfig();
|
|
809
814
|
const config = {
|
|
810
815
|
method: 'get',
|
|
811
|
-
url: `${
|
|
816
|
+
url: `${SMS_BASE_URL}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}/artifact`,
|
|
812
817
|
headers: {
|
|
813
818
|
'Authorization': `Bearer ${accessToken}`,
|
|
814
819
|
'x-request-id': global.requestId,
|
|
815
820
|
'workspaceName': workspaceName,
|
|
821
|
+
'x-api-key': SMS_API_KEY,
|
|
816
822
|
},
|
|
817
823
|
responseType: 'arraybuffer',
|
|
818
824
|
};
|
|
819
825
|
|
|
820
826
|
logger.info(
|
|
821
827
|
'Initiating GET %s',
|
|
822
|
-
`${
|
|
828
|
+
`${SMS_BASE_URL}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}/artifact`,
|
|
823
829
|
);
|
|
824
830
|
|
|
825
831
|
try {
|
|
@@ -862,14 +868,14 @@ const getMeshArtifact = async (organizationId, projectId, workspaceId, workspace
|
|
|
862
868
|
* @returns {Promise<Object>}
|
|
863
869
|
*/
|
|
864
870
|
const getTenantFeatures = async organizationCode => {
|
|
865
|
-
const { accessToken
|
|
871
|
+
const { accessToken } = await getDevConsoleConfig();
|
|
866
872
|
const config = {
|
|
867
873
|
method: 'get',
|
|
868
874
|
url: `${SMS_BASE_URL}/organizations/${organizationCode}/features`,
|
|
869
875
|
headers: {
|
|
870
876
|
'Authorization': `Bearer ${accessToken}`,
|
|
871
877
|
'x-request-id': global.requestId,
|
|
872
|
-
'
|
|
878
|
+
'x-api-key': SMS_API_KEY,
|
|
873
879
|
},
|
|
874
880
|
};
|
|
875
881
|
|
|
@@ -917,14 +923,14 @@ const getTenantFeatures = async organizationCode => {
|
|
|
917
923
|
* @returns {Promise<Object>}
|
|
918
924
|
*/
|
|
919
925
|
const getMeshDeployments = async (organizationCode, projectId, workspaceId, meshId) => {
|
|
920
|
-
const { accessToken
|
|
926
|
+
const { accessToken } = await getDevConsoleConfig();
|
|
921
927
|
const config = {
|
|
922
928
|
method: 'get',
|
|
923
929
|
url: `${SMS_BASE_URL}/organizations/${organizationCode}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}/deployments/latest`,
|
|
924
930
|
headers: {
|
|
925
931
|
'Authorization': `Bearer ${accessToken}`,
|
|
926
932
|
'x-request-id': global.requestId,
|
|
927
|
-
'
|
|
933
|
+
'x-api-key': SMS_API_KEY,
|
|
928
934
|
},
|
|
929
935
|
};
|
|
930
936
|
|
|
@@ -973,14 +979,14 @@ const getMeshDeployments = async (organizationCode, projectId, workspaceId, mesh
|
|
|
973
979
|
* @returns string
|
|
974
980
|
*/
|
|
975
981
|
const getPublicEncryptionKey = async organizationCode => {
|
|
976
|
-
const { accessToken
|
|
982
|
+
const { accessToken } = await getDevConsoleConfig();
|
|
977
983
|
const config = {
|
|
978
984
|
method: 'get',
|
|
979
985
|
url: `${SMS_BASE_URL}/organizations/${organizationCode}/getPublicKey`,
|
|
980
986
|
headers: {
|
|
981
987
|
'Authorization': `Bearer ${accessToken}`,
|
|
982
988
|
'x-request-id': global.requestId,
|
|
983
|
-
'
|
|
989
|
+
'x-api-key': SMS_API_KEY,
|
|
984
990
|
},
|
|
985
991
|
};
|
|
986
992
|
logger.info(
|
|
@@ -1018,14 +1024,14 @@ const getPresignedUrls = async (
|
|
|
1018
1024
|
startTime,
|
|
1019
1025
|
endTime,
|
|
1020
1026
|
) => {
|
|
1021
|
-
const { accessToken
|
|
1027
|
+
const { accessToken } = await getDevConsoleConfig();
|
|
1022
1028
|
const config = {
|
|
1023
1029
|
method: 'get',
|
|
1024
1030
|
url: `${SMS_BASE_URL}/organizations/${organizationCode}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}/logs?startDateTime=${startTime}&endDateTime=${endTime}`,
|
|
1025
1031
|
headers: {
|
|
1026
1032
|
'Authorization': `Bearer ${accessToken}`,
|
|
1027
1033
|
'x-request-id': global.requestId,
|
|
1028
|
-
'
|
|
1034
|
+
'x-api-key': SMS_API_KEY,
|
|
1029
1035
|
},
|
|
1030
1036
|
};
|
|
1031
1037
|
|
|
@@ -1057,14 +1063,14 @@ const getPresignedUrls = async (
|
|
|
1057
1063
|
};
|
|
1058
1064
|
|
|
1059
1065
|
const getLogsByRayId = async (organizationCode, projectId, workspaceId, meshId, rayId) => {
|
|
1060
|
-
const { accessToken
|
|
1066
|
+
const { accessToken } = await getDevConsoleConfig();
|
|
1061
1067
|
const config = {
|
|
1062
1068
|
method: 'get',
|
|
1063
1069
|
url: `${SMS_BASE_URL}/organizations/${organizationCode}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}/logs/${rayId}`,
|
|
1064
1070
|
headers: {
|
|
1065
1071
|
'Authorization': `Bearer ${accessToken}`,
|
|
1066
1072
|
'x-request-id': global.requestId,
|
|
1067
|
-
'
|
|
1073
|
+
'x-api-key': SMS_API_KEY,
|
|
1068
1074
|
},
|
|
1069
1075
|
};
|
|
1070
1076
|
|
package/src/server.js
CHANGED
|
@@ -1,38 +1,200 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
// Resolve the path to 'fastify' and 'graphql-yoga' within the local 'node_modules'
|
|
2
|
+
const fastifyPath = require.resolve('fastify', { paths: [process.cwd()] });
|
|
3
|
+
const yogaPath = require.resolve('graphql-yoga', { paths: [process.cwd()] });
|
|
4
|
+
|
|
5
|
+
// Load 'fastify' and 'graphql-yoga' using the resolved paths
|
|
6
|
+
const fastify = require(fastifyPath);
|
|
7
|
+
const { createYoga } = require(yogaPath);
|
|
8
|
+
const logger = require('./classes/logger');
|
|
9
|
+
|
|
10
|
+
//Load the functions from serverUtils.js
|
|
11
|
+
const {
|
|
12
|
+
readMeshConfig,
|
|
13
|
+
removeRequestHeaders,
|
|
14
|
+
prepSourceResponseHeaders,
|
|
15
|
+
processResponseHeaders,
|
|
16
|
+
readSecretsFile,
|
|
17
|
+
} = require('./serverUtils');
|
|
18
|
+
|
|
19
|
+
let yogaServer = null;
|
|
20
|
+
let meshConfig;
|
|
21
|
+
|
|
22
|
+
// catch unhandled promise rejections
|
|
23
|
+
process.on('unhandledRejection', reason => {
|
|
24
|
+
logger.error('Unhandled Rejection at:', reason.stack || reason);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// catch uncaught exceptions
|
|
28
|
+
process.on('uncaughtException', err => {
|
|
29
|
+
logger.error('Uncaught Exception thrown');
|
|
30
|
+
logger.error(err.stack);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// get meshId from command line arguments
|
|
35
|
+
const meshId = process.argv[2];
|
|
36
|
+
|
|
37
|
+
// get PORT number from command line arguments
|
|
38
|
+
const portNo = parseInt(process.argv[3]);
|
|
39
|
+
|
|
40
|
+
const getCORSOptions = () => {
|
|
41
|
+
try {
|
|
42
|
+
const currentWorkingDirectory = process.cwd();
|
|
43
|
+
const meshConfigPath = `${currentWorkingDirectory}/mesh-artifact/${meshId}/.meshrc.json`;
|
|
44
|
+
|
|
45
|
+
const meshConfig = require(meshConfigPath);
|
|
46
|
+
const { responseConfig } = meshConfig;
|
|
47
|
+
const { CORS } = responseConfig;
|
|
48
|
+
|
|
49
|
+
return CORS;
|
|
50
|
+
} catch (e) {
|
|
51
|
+
return {};
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// Custom get secrets handler
|
|
56
|
+
const getSecretsHandler = {
|
|
57
|
+
get: function (target, prop, receiver) {
|
|
58
|
+
if (prop === 'toJSON') {
|
|
59
|
+
// Handle the toJSON case
|
|
60
|
+
return () => target;
|
|
61
|
+
}
|
|
62
|
+
if (prop in target) {
|
|
63
|
+
return Reflect.get(target, prop, receiver);
|
|
64
|
+
} else {
|
|
65
|
+
throw new Error(`The secret ${String(prop)} is not available.`);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
set: function () {
|
|
69
|
+
throw new Error('Setting secrets is not allowed');
|
|
70
|
+
},
|
|
36
71
|
};
|
|
37
72
|
|
|
38
|
-
|
|
73
|
+
const getYogaServer = async () => {
|
|
74
|
+
if (yogaServer) {
|
|
75
|
+
return yogaServer;
|
|
76
|
+
} else {
|
|
77
|
+
const currentWorkingDirectory = process.cwd();
|
|
78
|
+
const meshArtifactsPath = `${currentWorkingDirectory}/mesh-artifact/${meshId}`;
|
|
79
|
+
|
|
80
|
+
const meshArtifacts = require(meshArtifactsPath);
|
|
81
|
+
const { getBuiltMesh } = meshArtifacts;
|
|
82
|
+
|
|
83
|
+
const tenantMesh = await getBuiltMesh();
|
|
84
|
+
const corsOptions = getCORSOptions();
|
|
85
|
+
|
|
86
|
+
const secrets = readSecretsFile(meshId);
|
|
87
|
+
|
|
88
|
+
const secretsProxy = new Proxy(secrets, getSecretsHandler);
|
|
89
|
+
|
|
90
|
+
logger.info('Creating graphQL server');
|
|
91
|
+
|
|
92
|
+
meshConfig = readMeshConfig(meshId);
|
|
93
|
+
|
|
94
|
+
yogaServer = createYoga({
|
|
95
|
+
plugins: tenantMesh.plugins,
|
|
96
|
+
graphqlEndpoint: `/graphql`,
|
|
97
|
+
graphiql: true,
|
|
98
|
+
maskedErrors: false,
|
|
99
|
+
cors: corsOptions,
|
|
100
|
+
context: initialContext => ({
|
|
101
|
+
...initialContext,
|
|
102
|
+
secrets: secretsProxy,
|
|
103
|
+
}),
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
return yogaServer;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const app = fastify();
|
|
111
|
+
|
|
112
|
+
app.route({
|
|
113
|
+
method: ['GET', 'POST'],
|
|
114
|
+
url: '/graphql',
|
|
115
|
+
handler: async (req, res) => {
|
|
116
|
+
logger.info('Request received: ', req.body);
|
|
117
|
+
|
|
118
|
+
let body = null;
|
|
119
|
+
let responseBody = null;
|
|
120
|
+
let includeMetaData = false;
|
|
121
|
+
|
|
122
|
+
if (req.headers['x-include-metadata'] && req.headers['x-include-metadata'].length > 0) {
|
|
123
|
+
if (req.headers['x-include-metadata'].toLowerCase() === 'true') {
|
|
124
|
+
includeMetaData = true;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const response = await yogaServer.handleNodeRequest(req, {
|
|
129
|
+
req,
|
|
130
|
+
reply: res,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
try {
|
|
135
|
+
body = await response.text();
|
|
136
|
+
if (body) {
|
|
137
|
+
responseBody = JSON.parse(body);
|
|
138
|
+
}
|
|
139
|
+
} catch (err) {
|
|
140
|
+
logger.error(`Error parsing response body: ${err}`);
|
|
141
|
+
logger.error(response);
|
|
142
|
+
throw new Error(`Error parsing response body: ${err}`);
|
|
143
|
+
}
|
|
144
|
+
//Set the value of includeHTTPDetails flag
|
|
145
|
+
|
|
146
|
+
const includeHTTPDetails = !!meshConfig?.responseConfig?.includeHTTPDetails;
|
|
147
|
+
const meshHTTPDetails = responseBody?.extensions?.httpDetails;
|
|
148
|
+
logger.info('Mesh HTTP Details: ', meshHTTPDetails);
|
|
149
|
+
|
|
150
|
+
/* the logic for handling mesh response headers using includeMetaData */
|
|
151
|
+
prepSourceResponseHeaders(meshHTTPDetails, req.id);
|
|
152
|
+
const responseHeaders = processResponseHeaders(meshId, req.id, includeMetaData, req.method);
|
|
153
|
+
|
|
154
|
+
/** Adding the yoga response headers to the response */
|
|
155
|
+
response.headers?.forEach((value, key) => {
|
|
156
|
+
res.header(key, value);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// Delete the httpDetails extensions details if mesh owner has disabled those details in the config
|
|
160
|
+
if (includeHTTPDetails !== true) {
|
|
161
|
+
delete responseBody?.extensions?.httpDetails;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
//make sure to remove the request headers from cache after the request is complete
|
|
165
|
+
removeRequestHeaders(req.id);
|
|
166
|
+
const fastifyResponseBody = JSON.stringify(responseBody);
|
|
167
|
+
res.status(response.status).headers(responseHeaders).send(fastifyResponseBody);
|
|
168
|
+
} catch (err) {
|
|
169
|
+
logger.error(`Error parsing response body: ${err}`);
|
|
170
|
+
//we have this fallback catch clause if someone wants to load the graphiql engine. This returns the default headers back
|
|
171
|
+
response.headers?.forEach((value, key) => {
|
|
172
|
+
res.header(key, value);
|
|
173
|
+
});
|
|
174
|
+
res.status(response.status);
|
|
175
|
+
res.send(response.body);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return res;
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
app.listen(
|
|
183
|
+
{
|
|
184
|
+
//set the port no of the server based on the input value
|
|
185
|
+
port: portNo,
|
|
186
|
+
},
|
|
187
|
+
async err => {
|
|
188
|
+
try {
|
|
189
|
+
if (err) {
|
|
190
|
+
throw new Error(`Server setup error: ${err.message}`);
|
|
191
|
+
}
|
|
192
|
+
yogaServer = await getYogaServer();
|
|
193
|
+
} catch (error) {
|
|
194
|
+
console.error(error);
|
|
195
|
+
process.exit(1);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
console.log(`Server is running on http://localhost:${portNo}/graphql`);
|
|
199
|
+
},
|
|
200
|
+
);
|
package/src/serverUtils.js
CHANGED
|
@@ -318,13 +318,13 @@ function ccDirectivesToString(directives) {
|
|
|
318
318
|
|
|
319
319
|
/**
|
|
320
320
|
* Returns secrets content from artifacts
|
|
321
|
-
* @param
|
|
321
|
+
* @param meshId
|
|
322
322
|
* @returns
|
|
323
323
|
*/
|
|
324
|
-
function readSecretsFile(
|
|
324
|
+
function readSecretsFile(meshId) {
|
|
325
325
|
let secrets = {};
|
|
326
326
|
try {
|
|
327
|
-
const filePath = path.resolve(process.cwd(), `${
|
|
327
|
+
const filePath = path.resolve(process.cwd(), 'mesh-artifact', `${meshId}`, 'secrets.yaml');
|
|
328
328
|
if (fs.existsSync(filePath)) {
|
|
329
329
|
secrets = YAML.parse(fs.readFileSync(filePath, 'utf8'));
|
|
330
330
|
}
|
package/src/cors.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get default CORS options.
|
|
3
|
-
* @param env Environment.
|
|
4
|
-
*/
|
|
5
|
-
const getDefaultCorsOptions = env => {
|
|
6
|
-
return env.CORS_DEFAULT_URL
|
|
7
|
-
? {
|
|
8
|
-
origin: env.CORS_DEFAULT_URL,
|
|
9
|
-
}
|
|
10
|
-
: {};
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Get CORS options. Merges default CORS options with custom specific options if present in the mesh configuration.
|
|
15
|
-
* Custom CORS options overwrite the default options to ensure that specific requirements can be met without altering
|
|
16
|
-
* the default configuration.
|
|
17
|
-
* @param env Environment.
|
|
18
|
-
* @param meshConfig Mesh configuration.
|
|
19
|
-
*/
|
|
20
|
-
const getCorsOptions = (env, meshConfig) => {
|
|
21
|
-
const defaultCorsOptions = getDefaultCorsOptions(env);
|
|
22
|
-
return {
|
|
23
|
-
...defaultCorsOptions,
|
|
24
|
-
...meshConfig.responseConfig?.CORS,
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
module.exports = { getCorsOptions };
|
package/src/fixPlugins.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
/**
|
|
4
|
-
* Modifies `index.js` of a mesh artifact to mutate plugin references for edge compatibility. Current forces
|
|
5
|
-
* `@graphql-mesh/plugin-http-details-extensions` to resolve to local fork instead.
|
|
6
|
-
*/
|
|
7
|
-
async function fixPlugins(meshArtifactPath) {
|
|
8
|
-
try {
|
|
9
|
-
console.log('Modifying mesh artifact to fix plugins for edge compatibility.');
|
|
10
|
-
const data = fs.readFileSync(meshArtifactPath, 'utf8');
|
|
11
|
-
const updatedData = data.replace(
|
|
12
|
-
/@graphql-mesh\/plugin-http-details-extensions/g,
|
|
13
|
-
'../src/plugins/httpDetailsExtensions',
|
|
14
|
-
);
|
|
15
|
-
fs.writeFileSync(meshArtifactPath, updatedData, 'utf8');
|
|
16
|
-
} catch (err) {
|
|
17
|
-
console.error(err);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Execute fixPlugins if run directly from CLI
|
|
22
|
-
if (require.main === module) {
|
|
23
|
-
fixPlugins();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
module.exports = {
|
|
27
|
-
fixPlugins,
|
|
28
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const { getPluginVersionDetails, isCurrentVersionLatest } = require('../helpers');
|
|
2
|
-
const chalk = require('chalk');
|
|
3
|
-
|
|
4
|
-
const hook = async function () {
|
|
5
|
-
const installedPlugins = this.config.plugins;
|
|
6
|
-
|
|
7
|
-
const { currentVersion, latestVersion } = await getPluginVersionDetails(installedPlugins);
|
|
8
|
-
|
|
9
|
-
if (!isCurrentVersionLatest(currentVersion, latestVersion)) {
|
|
10
|
-
this.warn(
|
|
11
|
-
`@adobe/aio-cli-plugin-api-mesh update available from ${chalk.yellowBright(
|
|
12
|
-
currentVersion,
|
|
13
|
-
)} to ${chalk.yellowBright(latestVersion)}`,
|
|
14
|
-
);
|
|
15
|
-
this.warn(
|
|
16
|
-
`Run ${chalk.greenBright(
|
|
17
|
-
'aio plugins:install @adobe/aio-cli-plugin-api-mesh',
|
|
18
|
-
)} to update to the latest`,
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
module.exports = hook;
|
package/src/index.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { ServedTier, addServedHeader } from './served';
|
|
2
|
-
import { bindedlogger as logger } from './utils/logger';
|
|
3
|
-
import { getRequestId } from './utils/requestId';
|
|
4
|
-
import { buildServer } from './wranglerServer';
|
|
5
|
-
|
|
6
|
-
let server;
|
|
7
|
-
|
|
8
|
-
export default {
|
|
9
|
-
setServer(newServer) {
|
|
10
|
-
server = newServer;
|
|
11
|
-
},
|
|
12
|
-
/**
|
|
13
|
-
* Fetch.
|
|
14
|
-
* @param request Request.
|
|
15
|
-
* @param env Environment.
|
|
16
|
-
* @param ctx Event context.
|
|
17
|
-
*/
|
|
18
|
-
async fetch(request, env, ctx) {
|
|
19
|
-
const requestId = getRequestId(request);
|
|
20
|
-
// Retrieve environment variables
|
|
21
|
-
const { MESH_ID: meshId, LOG_LEVEL: logLevel } = env;
|
|
22
|
-
const loggerInstance = logger({ logLevel, meshId, requestId });
|
|
23
|
-
const meshArtifacts = await import('../.mesh');
|
|
24
|
-
const rawMesh = await import('../.mesh/.meshrc.json');
|
|
25
|
-
|
|
26
|
-
if (!server) {
|
|
27
|
-
server = await this.buildAndCacheServer(env, loggerInstance, meshArtifacts, rawMesh);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
loggerInstance.debug('WORKER HOT: Fetching via worker');
|
|
31
|
-
const response = await server.fetch(request, ctx);
|
|
32
|
-
addServedHeader(response, ServedTier.WORKER_HOT);
|
|
33
|
-
return response;
|
|
34
|
-
},
|
|
35
|
-
/**
|
|
36
|
-
* Build and cache mesh instance/server in global variable.
|
|
37
|
-
* @param env
|
|
38
|
-
* @param loggerInstance
|
|
39
|
-
*/
|
|
40
|
-
async buildAndCacheServer(env, loggerInstance, meshArtifacts, meshConfig) {
|
|
41
|
-
server = await buildServer(loggerInstance, env, meshArtifacts, meshConfig);
|
|
42
|
-
return server;
|
|
43
|
-
},
|
|
44
|
-
};
|