@adobe/aio-cli-plugin-api-mesh 2.3.1 → 2.3.3
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 +1 -1
- package/src/commands/__fixtures__/sample_mesh_with_composer_files.json +42 -0
- package/src/commands/api-mesh/__tests__/create.test.js +102 -56
- package/src/commands/api-mesh/__tests__/delete.test.js +2 -2
- package/src/commands/api-mesh/__tests__/get.test.js +2 -2
- package/src/commands/api-mesh/__tests__/init.test.js +17 -17
- package/src/commands/api-mesh/__tests__/update.test.js +15 -15
- package/src/commands/api-mesh/create.js +13 -6
- package/src/commands/api-mesh/describe.js +9 -3
- package/src/constants.js +7 -2
- package/src/utils.js +42 -17
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"2.3.
|
|
1
|
+
{"version":"2.3.3","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":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false},"json":{"name":"json","type":"boolean","description":"Output JSON","allowNo":false},"env":{"name":"env","type":"option","char":"e","description":"Path to env file","default":".env"}},"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":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false}},"args":[]},"api-mesh:describe":{"id":"api-mesh:describe","description":"Get details of a mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"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":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"json":{"name":"json","type":"boolean","description":"Output JSON","allowNo":false}},"args":[{"name":"file"}]},"api-mesh:init":{"id":"api-mesh:init","description":"This command will create a workspace where you can organise your API mesh configuration and other files","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":[{"description":"API mesh workspace init","command":"aio api-mesh init commerce-mesh"},{"description":"API mesh workspace init with flags","command":"aio api-mesh init commerce-mesh --path ./mesh_projects/test_mesh --git y --packageManager yarn"}],"flags":{"path":{"name":"path","type":"option","char":"p","default":"."},"packageManager":{"name":"packageManager","type":"option","char":"m","options":["npm","yarn"]},"git":{"name":"git","type":"option","char":"g","options":["y","n"]}},"args":[{"name":"projectName","description":"Project name","required":true}]},"api-mesh:status":{"id":"api-mesh:status","description":"Get a mesh status with a given meshid.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[]},"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":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false},"env":{"name":"env","type":"option","char":"e","description":"Path to env file","default":".env"}},"args":[{"name":"file"}]},"api-mesh:source:discover":{"id":"api-mesh:source:discover","description":"Return the list of avaliable sources","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"confirm":{"name":"confirm","type":"boolean","char":"c","description":"Auto confirm install action prompt. CLI will not check ask user to install source.","allowNo":false}},"args":[]},"api-mesh:source:get":{"id":"api-mesh:source:get","description":"Command returns the content of a specific source.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":["$ aio api-mesh:source:get -s=<version>@<source_name>","$ aio api-mesh:source:get -s<source_name>","$ aio api-mesh:source:get -m"],"flags":{"confirm":{"name":"confirm","type":"boolean","char":"c","description":"Auto confirm print action prompt. CLI will not check ask user to print source.","allowNo":false},"source":{"name":"source","type":"option","char":"s","description":"Source name"},"multiple":{"name":"multiple","type":"boolean","char":"m","description":"Select multiple sources","allowNo":false}},"args":[]},"api-mesh:source:install":{"id":"api-mesh:source:install","description":"Command to install the source to your API mesh.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":["$ aio api-mesh:source:install <version>@<source_name>","$ aio api-mesh:source:install <source_name> -v <variable_name>=<variable_value>","$ aio api-mesh:source:install <source_name> -f <path_to_variables_file>"],"flags":{"source":{"name":"source","type":"option","char":"s","description":"Source name"},"confirm":{"name":"confirm","type":"boolean","char":"c","description":"Auto confirm override action prompt. CLI will not check ask user to override source.","allowNo":false},"variable":{"name":"variable","type":"option","char":"v","description":"Variables required for the source"},"variable-file":{"name":"variable-file","type":"option","char":"f","description":"Variables file path"},"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[{"name":"source"}]}}}
|
package/package.json
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meshConfig": {
|
|
3
|
+
"sources": [
|
|
4
|
+
{
|
|
5
|
+
"name": "<json_source_name>",
|
|
6
|
+
"handler": {
|
|
7
|
+
"JsonSchema": {
|
|
8
|
+
"baseUrl": "<json_source__baseurl>",
|
|
9
|
+
"operations": [
|
|
10
|
+
{
|
|
11
|
+
"type": "Query",
|
|
12
|
+
"field": "<query>",
|
|
13
|
+
"path": "<query_path>",
|
|
14
|
+
"method": "POST",
|
|
15
|
+
"requestSchema": "./requestParams.json"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"plugins": [
|
|
23
|
+
{
|
|
24
|
+
"hooks": {
|
|
25
|
+
"beforeAll": {
|
|
26
|
+
"composer": "./hooks.js#functionName"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
"files": [
|
|
32
|
+
{
|
|
33
|
+
"path": "./requestParams.json",
|
|
34
|
+
"content": "{\"type\":\"dummyContent\"}"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"path": "./hooks.js",
|
|
38
|
+
"content": "module.exports.functionName = () => { console.log('beforeAll hook'); }"
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -14,6 +14,7 @@ const mockConsoleCLIInstance = {};
|
|
|
14
14
|
|
|
15
15
|
const CreateCommand = require('../create');
|
|
16
16
|
const sampleCreateMeshConfig = require('../../__fixtures__/sample_mesh.json');
|
|
17
|
+
const meshConfigWithComposerFiles = require('../../__fixtures__/sample_mesh_with_composer_files.json');
|
|
17
18
|
const {
|
|
18
19
|
initSdk,
|
|
19
20
|
initRequestId,
|
|
@@ -165,6 +166,78 @@ describe('create command tests', () => {
|
|
|
165
166
|
`);
|
|
166
167
|
expect(CreateCommand.aliases).toMatchInlineSnapshot(`[]`);
|
|
167
168
|
});
|
|
169
|
+
|
|
170
|
+
test('should pass if a valid mesh config file with composer files are provided', async () => {
|
|
171
|
+
createMesh.mockResolvedValueOnce({
|
|
172
|
+
meshId: 'dummy_mesh_id',
|
|
173
|
+
meshConfig: meshConfigWithComposerFiles.meshConfig,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
parseSpy.mockResolvedValueOnce({
|
|
177
|
+
args: { file: 'src/commands/__fixtures__/sample_mesh_with_composer_files.json' },
|
|
178
|
+
flags: {
|
|
179
|
+
autoConfirmAction: Promise.resolve(true),
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
const output = await CreateCommand.run();
|
|
184
|
+
|
|
185
|
+
expect(output).toMatchInlineSnapshot(`
|
|
186
|
+
{
|
|
187
|
+
"adobeIdIntegrationsForWorkspace": {
|
|
188
|
+
"apiKey": "dummy_api_key",
|
|
189
|
+
"id": "dummy_id",
|
|
190
|
+
},
|
|
191
|
+
"mesh": {
|
|
192
|
+
"meshConfig": {
|
|
193
|
+
"files": [
|
|
194
|
+
{
|
|
195
|
+
"content": "{"type":"dummyContent"}",
|
|
196
|
+
"path": "./requestParams.json",
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
"content": "module.exports.functionName = () => { console.log('beforeAll hook'); }",
|
|
200
|
+
"path": "./hooks.js",
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
"plugins": [
|
|
204
|
+
{
|
|
205
|
+
"hooks": {
|
|
206
|
+
"beforeAll": {
|
|
207
|
+
"composer": "./hooks.js#functionName",
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
"sources": [
|
|
213
|
+
{
|
|
214
|
+
"handler": {
|
|
215
|
+
"JsonSchema": {
|
|
216
|
+
"baseUrl": "<json_source__baseurl>",
|
|
217
|
+
"operations": [
|
|
218
|
+
{
|
|
219
|
+
"field": "<query>",
|
|
220
|
+
"method": "POST",
|
|
221
|
+
"path": "<query_path>",
|
|
222
|
+
"requestSchema": "./requestParams.json",
|
|
223
|
+
"type": "Query",
|
|
224
|
+
},
|
|
225
|
+
],
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
"name": "<json_source_name>",
|
|
229
|
+
},
|
|
230
|
+
],
|
|
231
|
+
},
|
|
232
|
+
"meshId": "dummy_mesh_id",
|
|
233
|
+
},
|
|
234
|
+
"sdkList": [
|
|
235
|
+
"dummy_service",
|
|
236
|
+
],
|
|
237
|
+
}
|
|
238
|
+
`);
|
|
239
|
+
});
|
|
240
|
+
|
|
168
241
|
test('should fail if create mesh api has failed', async () => {
|
|
169
242
|
createMesh.mockRejectedValueOnce(new Error('create mesh api failed'));
|
|
170
243
|
|
|
@@ -189,6 +262,7 @@ describe('create command tests', () => {
|
|
|
189
262
|
]
|
|
190
263
|
`);
|
|
191
264
|
});
|
|
265
|
+
|
|
192
266
|
test('should create if a valid mesh config file is provided', async () => {
|
|
193
267
|
const runResult = await CreateCommand.run();
|
|
194
268
|
|
|
@@ -295,7 +369,7 @@ describe('create command tests', () => {
|
|
|
295
369
|
let fetchedMeshConfig = sampleCreateMeshConfig;
|
|
296
370
|
fetchedMeshConfig.meshId = 'dummy_id';
|
|
297
371
|
fetchedMeshConfig.meshURL = 'https://tigraph.adobe.io';
|
|
298
|
-
getMesh.
|
|
372
|
+
getMesh.mockResolvedValueOnce(fetchedMeshConfig);
|
|
299
373
|
|
|
300
374
|
const runResult = await CreateCommand.run();
|
|
301
375
|
|
|
@@ -753,7 +827,7 @@ describe('create command tests', () => {
|
|
|
753
827
|
});
|
|
754
828
|
|
|
755
829
|
test('should successfully create a mesh if provided env file is valid, mesh interpolation is successful and interpolated mesh is a valid JSON', async () => {
|
|
756
|
-
parseSpy.
|
|
830
|
+
parseSpy.mockResolvedValueOnce({
|
|
757
831
|
args: { file: 'src/commands/__fixtures__/sample_mesh_with_placeholder' },
|
|
758
832
|
flags: {
|
|
759
833
|
ignoreCache: mockIgnoreCacheFlag,
|
|
@@ -804,7 +878,7 @@ describe('create command tests', () => {
|
|
|
804
878
|
});
|
|
805
879
|
|
|
806
880
|
test('should return error if inputMesh is not a valid JSON', async () => {
|
|
807
|
-
parseSpy.
|
|
881
|
+
parseSpy.mockResolvedValueOnce({
|
|
808
882
|
args: { file: 'src/commands/__fixtures__/sample_invalid_mesh.txt' },
|
|
809
883
|
flags: {
|
|
810
884
|
ignoreCache: mockIgnoreCacheFlag,
|
|
@@ -855,12 +929,12 @@ describe('create command tests', () => {
|
|
|
855
929
|
],
|
|
856
930
|
};
|
|
857
931
|
|
|
858
|
-
createMesh.
|
|
932
|
+
createMesh.mockResolvedValueOnce({
|
|
859
933
|
meshId: 'dummy_mesh_id',
|
|
860
934
|
meshConfig: meshConfig,
|
|
861
935
|
});
|
|
862
936
|
|
|
863
|
-
parseSpy.
|
|
937
|
+
parseSpy.mockResolvedValueOnce({
|
|
864
938
|
args: { file: 'src/commands/__fixtures__/sample_mesh_files.json' },
|
|
865
939
|
flags: {
|
|
866
940
|
autoConfirmAction: Promise.resolve(false),
|
|
@@ -970,7 +1044,7 @@ describe('create command tests', () => {
|
|
|
970
1044
|
});
|
|
971
1045
|
|
|
972
1046
|
test('should fail if the file name is more than 25 characters', async () => {
|
|
973
|
-
parseSpy.
|
|
1047
|
+
parseSpy.mockResolvedValueOnce({
|
|
974
1048
|
args: { file: 'src/commands/__fixtures__/sample_mesh_invalid_file_name.json' },
|
|
975
1049
|
flags: {
|
|
976
1050
|
autoConfirmAction: Promise.resolve(false),
|
|
@@ -998,36 +1072,8 @@ describe('create command tests', () => {
|
|
|
998
1072
|
`);
|
|
999
1073
|
});
|
|
1000
1074
|
|
|
1001
|
-
test('should fail if the file paths in files array and filenames in sources, transforms, additionalResolvers do not match in mesh config', async () => {
|
|
1002
|
-
parseSpy.mockResolvedValue({
|
|
1003
|
-
args: { file: 'src/commands/__fixtures__/sample_mesh_mismatching_path.json' },
|
|
1004
|
-
flags: {
|
|
1005
|
-
autoConfirmAction: Promise.resolve(false),
|
|
1006
|
-
},
|
|
1007
|
-
});
|
|
1008
|
-
|
|
1009
|
-
const output = CreateCommand.run();
|
|
1010
|
-
|
|
1011
|
-
await expect(output).rejects.toEqual(new Error('Input mesh config is not valid.'));
|
|
1012
|
-
|
|
1013
|
-
expect(logSpy.mock.calls).toMatchInlineSnapshot(`
|
|
1014
|
-
[
|
|
1015
|
-
[
|
|
1016
|
-
"Please make sure the file names are matching in meshConfig.",
|
|
1017
|
-
],
|
|
1018
|
-
]
|
|
1019
|
-
`);
|
|
1020
|
-
expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
|
|
1021
|
-
[
|
|
1022
|
-
[
|
|
1023
|
-
"Input mesh config is not valid.",
|
|
1024
|
-
],
|
|
1025
|
-
]
|
|
1026
|
-
`);
|
|
1027
|
-
});
|
|
1028
|
-
|
|
1029
1075
|
test('should fail if the file is of type other than js, json extension', async () => {
|
|
1030
|
-
parseSpy.
|
|
1076
|
+
parseSpy.mockResolvedValueOnce({
|
|
1031
1077
|
args: { file: 'src/commands/__fixtures__/sample_mesh_invalid_type.json' },
|
|
1032
1078
|
flags: {
|
|
1033
1079
|
autoConfirmAction: Promise.resolve(false),
|
|
@@ -1055,7 +1101,7 @@ describe('create command tests', () => {
|
|
|
1055
1101
|
});
|
|
1056
1102
|
|
|
1057
1103
|
test('should fail if the files do not exist in the mesh directory or subdirectory', async () => {
|
|
1058
|
-
parseSpy.
|
|
1104
|
+
parseSpy.mockResolvedValueOnce({
|
|
1059
1105
|
args: { file: 'src/commands/__fixtures__/sample_mesh_invalid_paths.json' },
|
|
1060
1106
|
flags: {
|
|
1061
1107
|
autoConfirmAction: Promise.resolve(false),
|
|
@@ -1093,7 +1139,7 @@ describe('create command tests', () => {
|
|
|
1093
1139
|
});
|
|
1094
1140
|
|
|
1095
1141
|
test('should fail if import files function fails', async () => {
|
|
1096
|
-
parseSpy.
|
|
1142
|
+
parseSpy.mockResolvedValueOnce({
|
|
1097
1143
|
args: { file: 'src/commands/__fixtures__/sample_mesh_files.json' },
|
|
1098
1144
|
flags: {
|
|
1099
1145
|
autoConfirmAction: Promise.resolve(false),
|
|
@@ -1158,19 +1204,19 @@ describe('create command tests', () => {
|
|
|
1158
1204
|
],
|
|
1159
1205
|
};
|
|
1160
1206
|
|
|
1161
|
-
promptConfirm.
|
|
1207
|
+
promptConfirm.mockResolvedValueOnce(false).mockResolvedValueOnce(true);
|
|
1162
1208
|
|
|
1163
|
-
importFiles.
|
|
1209
|
+
importFiles.mockResolvedValueOnce(meshConfig);
|
|
1164
1210
|
|
|
1165
|
-
createMesh.
|
|
1211
|
+
createMesh.mockResolvedValueOnce({
|
|
1166
1212
|
meshId: 'dummy_mesh_id',
|
|
1167
1213
|
meshConfig: meshConfig,
|
|
1168
1214
|
});
|
|
1169
1215
|
|
|
1170
|
-
parseSpy.
|
|
1216
|
+
parseSpy.mockResolvedValueOnce({
|
|
1171
1217
|
args: { file: 'src/commands/__fixtures__/sample_mesh_with_files_array.json' },
|
|
1172
1218
|
flags: {
|
|
1173
|
-
autoConfirmAction: Promise.resolve(
|
|
1219
|
+
autoConfirmAction: Promise.resolve(true),
|
|
1174
1220
|
},
|
|
1175
1221
|
});
|
|
1176
1222
|
|
|
@@ -1298,12 +1344,12 @@ describe('create command tests', () => {
|
|
|
1298
1344
|
],
|
|
1299
1345
|
};
|
|
1300
1346
|
|
|
1301
|
-
promptConfirm.
|
|
1347
|
+
promptConfirm.mockResolvedValueOnce(true).mockResolvedValueOnce(true);
|
|
1302
1348
|
|
|
1303
|
-
parseSpy.
|
|
1349
|
+
parseSpy.mockResolvedValueOnce({
|
|
1304
1350
|
args: { file: 'src/commands/__fixtures__/sample_mesh_with_files_array.json' },
|
|
1305
1351
|
flags: {
|
|
1306
|
-
autoConfirmAction: Promise.resolve(
|
|
1352
|
+
autoConfirmAction: Promise.resolve(true),
|
|
1307
1353
|
},
|
|
1308
1354
|
});
|
|
1309
1355
|
|
|
@@ -1311,7 +1357,7 @@ describe('create command tests', () => {
|
|
|
1311
1357
|
meshConfig,
|
|
1312
1358
|
});
|
|
1313
1359
|
|
|
1314
|
-
createMesh.
|
|
1360
|
+
createMesh.mockResolvedValueOnce({
|
|
1315
1361
|
meshId: 'dummy_mesh_id',
|
|
1316
1362
|
meshConfig: meshConfig,
|
|
1317
1363
|
});
|
|
@@ -1443,20 +1489,20 @@ describe('create command tests', () => {
|
|
|
1443
1489
|
],
|
|
1444
1490
|
};
|
|
1445
1491
|
|
|
1446
|
-
parseSpy.
|
|
1492
|
+
parseSpy.mockResolvedValueOnce({
|
|
1447
1493
|
args: { file: 'src/commands/__fixtures__/sample_fully_qualified_mesh.json' },
|
|
1448
1494
|
flags: {
|
|
1449
|
-
autoConfirmAction: Promise.resolve(
|
|
1495
|
+
autoConfirmAction: Promise.resolve(true),
|
|
1450
1496
|
},
|
|
1451
1497
|
});
|
|
1452
1498
|
|
|
1453
|
-
promptConfirm.
|
|
1499
|
+
promptConfirm.mockResolvedValueOnce(true);
|
|
1454
1500
|
|
|
1455
1501
|
importFiles.mockResolvedValueOnce({
|
|
1456
1502
|
meshConfig,
|
|
1457
1503
|
});
|
|
1458
1504
|
|
|
1459
|
-
createMesh.
|
|
1505
|
+
createMesh.mockResolvedValueOnce({
|
|
1460
1506
|
meshId: 'dummy_mesh_id',
|
|
1461
1507
|
meshConfig: meshConfig,
|
|
1462
1508
|
});
|
|
@@ -1587,15 +1633,15 @@ describe('create command tests', () => {
|
|
|
1587
1633
|
],
|
|
1588
1634
|
};
|
|
1589
1635
|
|
|
1590
|
-
createMesh.
|
|
1636
|
+
createMesh.mockResolvedValueOnce({
|
|
1591
1637
|
meshId: 'dummy_mesh_id',
|
|
1592
1638
|
meshConfig: meshConfig,
|
|
1593
1639
|
});
|
|
1594
1640
|
|
|
1595
|
-
parseSpy.
|
|
1641
|
+
parseSpy.mockResolvedValueOnce({
|
|
1596
1642
|
args: { file: 'src/commands/__fixtures__/sample_mesh_subdirectory.json' },
|
|
1597
1643
|
flags: {
|
|
1598
|
-
autoConfirmAction: Promise.resolve(
|
|
1644
|
+
autoConfirmAction: Promise.resolve(true),
|
|
1599
1645
|
},
|
|
1600
1646
|
});
|
|
1601
1647
|
|
|
@@ -1702,7 +1748,7 @@ describe('create command tests', () => {
|
|
|
1702
1748
|
});
|
|
1703
1749
|
|
|
1704
1750
|
test('should fail if the file is outside the workspace directory', async () => {
|
|
1705
|
-
parseSpy.
|
|
1751
|
+
parseSpy.mockResolvedValueOnce({
|
|
1706
1752
|
args: { file: 'src/commands/__fixtures__/sample_mesh_outside_workspace_dir.json' },
|
|
1707
1753
|
flags: {
|
|
1708
1754
|
autoConfirmAction: Promise.resolve(false),
|
|
@@ -1729,7 +1775,7 @@ describe('create command tests', () => {
|
|
|
1729
1775
|
});
|
|
1730
1776
|
|
|
1731
1777
|
test('should fail if the file has invalid JSON content', async () => {
|
|
1732
|
-
parseSpy.
|
|
1778
|
+
parseSpy.mockResolvedValueOnce({
|
|
1733
1779
|
args: { file: 'src/commands/__fixtures__/sample_mesh_invalid_file_content.json' },
|
|
1734
1780
|
flags: {
|
|
1735
1781
|
autoConfirmAction: Promise.resolve(false),
|
|
@@ -1766,7 +1812,7 @@ describe('create command tests', () => {
|
|
|
1766
1812
|
});
|
|
1767
1813
|
|
|
1768
1814
|
test('should fail if the file path starts from home directory i.e., path starts with ~/', async () => {
|
|
1769
|
-
parseSpy.
|
|
1815
|
+
parseSpy.mockResolvedValueOnce({
|
|
1770
1816
|
args: { file: 'src/commands/__fixtures__/sample_mesh_path_from_home.json' },
|
|
1771
1817
|
flags: {
|
|
1772
1818
|
autoConfirmAction: Promise.resolve(false),
|
|
@@ -112,7 +112,7 @@ describe('delete command tests', () => {
|
|
|
112
112
|
});
|
|
113
113
|
|
|
114
114
|
test('should fail if mesh id is missing', async () => {
|
|
115
|
-
getMeshId.
|
|
115
|
+
getMeshId.mockResolvedValueOnce(null);
|
|
116
116
|
const runResult = DeleteCommand.run();
|
|
117
117
|
|
|
118
118
|
return runResult.catch(err => {
|
|
@@ -147,7 +147,7 @@ describe('delete command tests', () => {
|
|
|
147
147
|
});
|
|
148
148
|
|
|
149
149
|
test('should not ask for prompt if autoConfirmAction is set', async () => {
|
|
150
|
-
parseSpy.
|
|
150
|
+
parseSpy.mockResolvedValueOnce({
|
|
151
151
|
args: {},
|
|
152
152
|
flags: {
|
|
153
153
|
ignoreCache: mockIgnoreCacheFlag,
|
|
@@ -109,7 +109,7 @@ describe('get command tests', () => {
|
|
|
109
109
|
});
|
|
110
110
|
|
|
111
111
|
test('should fail if mesh id is missing', async () => {
|
|
112
|
-
getMeshId.
|
|
112
|
+
getMeshId.mockResolvedValueOnce(null);
|
|
113
113
|
const runResult = GetCommand.run();
|
|
114
114
|
|
|
115
115
|
return runResult.catch(err => {
|
|
@@ -128,7 +128,7 @@ describe('get command tests', () => {
|
|
|
128
128
|
});
|
|
129
129
|
|
|
130
130
|
test('should fail if getMeshId failed', async () => {
|
|
131
|
-
getMeshId.
|
|
131
|
+
getMeshId.mockRejectedValueOnce(new Error('getMeshId failed'));
|
|
132
132
|
const runResult = GetCommand.run();
|
|
133
133
|
|
|
134
134
|
return runResult.catch(err => {
|
|
@@ -95,7 +95,7 @@ describe('Workspace init command tests', () => {
|
|
|
95
95
|
});
|
|
96
96
|
|
|
97
97
|
test('Command should pass with no flags', async () => {
|
|
98
|
-
parseSpy.
|
|
98
|
+
parseSpy.mockResolvedValueOnce({
|
|
99
99
|
args: {
|
|
100
100
|
projectName: mockProjectName,
|
|
101
101
|
},
|
|
@@ -103,7 +103,7 @@ describe('Workspace init command tests', () => {
|
|
|
103
103
|
path: './template',
|
|
104
104
|
},
|
|
105
105
|
});
|
|
106
|
-
promptSelect.
|
|
106
|
+
promptSelect.mockResolvedValueOnce('yarn');
|
|
107
107
|
await InitCommand.run();
|
|
108
108
|
expect(promptConfirm).toHaveBeenCalled();
|
|
109
109
|
expect(promptSelect).toHaveBeenCalled();
|
|
@@ -121,7 +121,7 @@ describe('Workspace init command tests', () => {
|
|
|
121
121
|
});
|
|
122
122
|
|
|
123
123
|
test('Command should pass and create git project if git flag is provided', async () => {
|
|
124
|
-
parseSpy.
|
|
124
|
+
parseSpy.mockResolvedValueOnce({
|
|
125
125
|
args: {
|
|
126
126
|
projectName: mockProjectName,
|
|
127
127
|
},
|
|
@@ -149,7 +149,7 @@ describe('Workspace init command tests', () => {
|
|
|
149
149
|
});
|
|
150
150
|
|
|
151
151
|
test('Command should fail if git flag is provided and git init fails', async () => {
|
|
152
|
-
parseSpy.
|
|
152
|
+
parseSpy.mockResolvedValueOnce({
|
|
153
153
|
args: {
|
|
154
154
|
projectName: mockProjectName,
|
|
155
155
|
},
|
|
@@ -178,7 +178,7 @@ describe('Workspace init command tests', () => {
|
|
|
178
178
|
});
|
|
179
179
|
|
|
180
180
|
test('Command should pass and create yarn project if yarn is package manager', async () => {
|
|
181
|
-
parseSpy.
|
|
181
|
+
parseSpy.mockResolvedValueOnce({
|
|
182
182
|
args: {
|
|
183
183
|
projectName: mockProjectName,
|
|
184
184
|
},
|
|
@@ -203,7 +203,7 @@ describe('Workspace init command tests', () => {
|
|
|
203
203
|
});
|
|
204
204
|
|
|
205
205
|
test('Command should pass and create yarn + git project if yarn is package manager and git flag is set', async () => {
|
|
206
|
-
parseSpy.
|
|
206
|
+
parseSpy.mockResolvedValueOnce({
|
|
207
207
|
args: {
|
|
208
208
|
projectName: mockProjectName,
|
|
209
209
|
},
|
|
@@ -227,7 +227,7 @@ describe('Workspace init command tests', () => {
|
|
|
227
227
|
});
|
|
228
228
|
|
|
229
229
|
test('Command should pass with creating the sub directory if the directory already exists', async () => {
|
|
230
|
-
parseSpy.
|
|
230
|
+
parseSpy.mockResolvedValueOnce({
|
|
231
231
|
args: {
|
|
232
232
|
projectName: mockProjectName,
|
|
233
233
|
},
|
|
@@ -237,7 +237,7 @@ describe('Workspace init command tests', () => {
|
|
|
237
237
|
packageManager: mockPMDefaultFlag,
|
|
238
238
|
},
|
|
239
239
|
});
|
|
240
|
-
access.
|
|
240
|
+
access.mockResolvedValueOnce({});
|
|
241
241
|
|
|
242
242
|
await InitCommand.run();
|
|
243
243
|
|
|
@@ -252,7 +252,7 @@ describe('Workspace init command tests', () => {
|
|
|
252
252
|
});
|
|
253
253
|
|
|
254
254
|
test('Command should fail if the directory already exists and sub directory of project name exists', async () => {
|
|
255
|
-
parseSpy.
|
|
255
|
+
parseSpy.mockResolvedValueOnce({
|
|
256
256
|
args: {
|
|
257
257
|
projectName: mockProjectName,
|
|
258
258
|
},
|
|
@@ -262,7 +262,7 @@ describe('Workspace init command tests', () => {
|
|
|
262
262
|
packageManager: mockPMDefaultFlag,
|
|
263
263
|
},
|
|
264
264
|
});
|
|
265
|
-
access.
|
|
265
|
+
access.mockResolvedValueOnce({});
|
|
266
266
|
mkdir.mockRejectedValue(new Error());
|
|
267
267
|
|
|
268
268
|
await expect(InitCommand.run()).rejects.toThrow();
|
|
@@ -280,7 +280,7 @@ describe('Workspace init command tests', () => {
|
|
|
280
280
|
});
|
|
281
281
|
|
|
282
282
|
test('Command should fail if directory creation fails', async () => {
|
|
283
|
-
parseSpy.
|
|
283
|
+
parseSpy.mockResolvedValueOnce({
|
|
284
284
|
args: {
|
|
285
285
|
projectName: mockProjectName,
|
|
286
286
|
},
|
|
@@ -306,7 +306,7 @@ describe('Workspace init command tests', () => {
|
|
|
306
306
|
});
|
|
307
307
|
|
|
308
308
|
test('Command should fail if npm install fails', async () => {
|
|
309
|
-
parseSpy.
|
|
309
|
+
parseSpy.mockResolvedValueOnce({
|
|
310
310
|
args: {
|
|
311
311
|
projectName: mockProjectName,
|
|
312
312
|
},
|
|
@@ -333,7 +333,7 @@ describe('Workspace init command tests', () => {
|
|
|
333
333
|
});
|
|
334
334
|
|
|
335
335
|
test('Command should fail if yarn install fails', async () => {
|
|
336
|
-
parseSpy.
|
|
336
|
+
parseSpy.mockResolvedValueOnce({
|
|
337
337
|
args: {
|
|
338
338
|
projectName: mockProjectName,
|
|
339
339
|
},
|
|
@@ -360,7 +360,7 @@ describe('Workspace init command tests', () => {
|
|
|
360
360
|
});
|
|
361
361
|
|
|
362
362
|
test('Command should exit if sub directory prompt is provided with no', async () => {
|
|
363
|
-
parseSpy.
|
|
363
|
+
parseSpy.mockResolvedValueOnce({
|
|
364
364
|
args: {
|
|
365
365
|
projectName: mockProjectName,
|
|
366
366
|
},
|
|
@@ -373,7 +373,7 @@ describe('Workspace init command tests', () => {
|
|
|
373
373
|
// create workspace prompt
|
|
374
374
|
promptConfirm.mockResolvedValueOnce(true);
|
|
375
375
|
// access passes
|
|
376
|
-
access.
|
|
376
|
+
access.mockResolvedValueOnce({});
|
|
377
377
|
// create in sub directory prompt
|
|
378
378
|
promptConfirm.mockResolvedValueOnce(false);
|
|
379
379
|
await InitCommand.run();
|
|
@@ -383,8 +383,8 @@ describe('Workspace init command tests', () => {
|
|
|
383
383
|
});
|
|
384
384
|
|
|
385
385
|
test('test createPackageJson', async () => {
|
|
386
|
-
jest.spyOn(fs, 'readFile').
|
|
387
|
-
jest.spyOn(fs, 'writeFile').
|
|
386
|
+
jest.spyOn(fs, 'readFile').mockResolvedValueOnce({});
|
|
387
|
+
jest.spyOn(fs, 'writeFile').mockResolvedValueOnce({});
|
|
388
388
|
|
|
389
389
|
await expect(InitCommand.prototype.createPackageJson()).resolves;
|
|
390
390
|
});
|
|
@@ -89,7 +89,7 @@ describe('update command tests', () => {
|
|
|
89
89
|
],
|
|
90
90
|
},
|
|
91
91
|
};
|
|
92
|
-
readFile.
|
|
92
|
+
readFile.mockResolvedValueOnce(JSON.stringify(sampleMesh));
|
|
93
93
|
|
|
94
94
|
parseSpy.mockResolvedValueOnce({
|
|
95
95
|
args: { file: 'src/commands/__fixtures__/sample_mesh.json' },
|
|
@@ -148,7 +148,7 @@ describe('update command tests', () => {
|
|
|
148
148
|
],
|
|
149
149
|
},
|
|
150
150
|
};
|
|
151
|
-
readFile.
|
|
151
|
+
readFile.mockResolvedValueOnce(JSON.stringify(sampleMesh));
|
|
152
152
|
|
|
153
153
|
parseSpy.mockResolvedValueOnce({
|
|
154
154
|
args: { file: 'src/commands/__fixtures__/sample_mesh.json' },
|
|
@@ -207,7 +207,7 @@ describe('update command tests', () => {
|
|
|
207
207
|
],
|
|
208
208
|
},
|
|
209
209
|
};
|
|
210
|
-
readFile.
|
|
210
|
+
readFile.mockResolvedValueOnce(JSON.stringify(sampleMesh));
|
|
211
211
|
|
|
212
212
|
parseSpy.mockResolvedValueOnce({
|
|
213
213
|
args: { file: 'src/commands/__fixtures__/sample_mesh.json' },
|
|
@@ -267,7 +267,7 @@ describe('update command tests', () => {
|
|
|
267
267
|
],
|
|
268
268
|
},
|
|
269
269
|
};
|
|
270
|
-
readFile.
|
|
270
|
+
readFile.mockResolvedValueOnce(JSON.stringify(sampleMesh));
|
|
271
271
|
|
|
272
272
|
parseSpy.mockResolvedValueOnce({
|
|
273
273
|
args: { file: 'src/commands/__fixtures__/sample_mesh.json' },
|
|
@@ -277,7 +277,7 @@ describe('update command tests', () => {
|
|
|
277
277
|
},
|
|
278
278
|
});
|
|
279
279
|
|
|
280
|
-
getMeshId.
|
|
280
|
+
getMeshId.mockResolvedValueOnce(null);
|
|
281
281
|
const runResult = UpdateCommand.run();
|
|
282
282
|
|
|
283
283
|
await expect(runResult).rejects.toMatchInlineSnapshot(
|
|
@@ -308,7 +308,7 @@ describe('update command tests', () => {
|
|
|
308
308
|
],
|
|
309
309
|
},
|
|
310
310
|
};
|
|
311
|
-
readFile.
|
|
311
|
+
readFile.mockResolvedValueOnce(JSON.stringify(sampleMesh));
|
|
312
312
|
|
|
313
313
|
parseSpy.mockResolvedValueOnce({
|
|
314
314
|
args: { file: 'src/commands/__fixtures__/sample_mesh.json' },
|
|
@@ -349,7 +349,7 @@ describe('update command tests', () => {
|
|
|
349
349
|
],
|
|
350
350
|
},
|
|
351
351
|
};
|
|
352
|
-
readFile.
|
|
352
|
+
readFile.mockResolvedValueOnce(JSON.stringify(sampleMesh));
|
|
353
353
|
|
|
354
354
|
parseSpy.mockResolvedValueOnce({
|
|
355
355
|
args: { file: 'src/commands/__fixtures__/sample_mesh.json' },
|
|
@@ -451,7 +451,7 @@ describe('update command tests', () => {
|
|
|
451
451
|
],
|
|
452
452
|
},
|
|
453
453
|
};
|
|
454
|
-
readFile.
|
|
454
|
+
readFile.mockResolvedValueOnce(JSON.stringify(sampleMesh));
|
|
455
455
|
|
|
456
456
|
parseSpy.mockResolvedValueOnce({
|
|
457
457
|
args: { file: 'src/commands/__fixtures__/sample_mesh.json' },
|
|
@@ -500,7 +500,7 @@ describe('update command tests', () => {
|
|
|
500
500
|
],
|
|
501
501
|
},
|
|
502
502
|
};
|
|
503
|
-
readFile.
|
|
503
|
+
readFile.mockResolvedValueOnce(JSON.stringify(sampleMesh));
|
|
504
504
|
|
|
505
505
|
let meshConfig = {
|
|
506
506
|
sources: [
|
|
@@ -530,12 +530,12 @@ describe('update command tests', () => {
|
|
|
530
530
|
],
|
|
531
531
|
};
|
|
532
532
|
|
|
533
|
-
updateMesh.
|
|
533
|
+
updateMesh.mockResolvedValueOnce({
|
|
534
534
|
meshId: 'dummy_mesh_id',
|
|
535
535
|
meshConfig: meshConfig,
|
|
536
536
|
});
|
|
537
537
|
|
|
538
|
-
parseSpy.
|
|
538
|
+
parseSpy.mockResolvedValueOnce({
|
|
539
539
|
args: { file: 'src/commands/__fixtures__/sample_mesh_files.json' },
|
|
540
540
|
flags: {
|
|
541
541
|
autoConfirmAction: mockAutoApproveAction,
|
|
@@ -645,9 +645,9 @@ describe('update command tests', () => {
|
|
|
645
645
|
],
|
|
646
646
|
},
|
|
647
647
|
};
|
|
648
|
-
readFile.
|
|
648
|
+
readFile.mockResolvedValueOnce(JSON.stringify(sampleMesh));
|
|
649
649
|
|
|
650
|
-
parseSpy.
|
|
650
|
+
parseSpy.mockResolvedValueOnce({
|
|
651
651
|
args: { file: 'src/commands/__fixtures__/sample_mesh_invalid_file_name.json' },
|
|
652
652
|
flags: {
|
|
653
653
|
ignoreCache: mockIgnoreCacheFlag,
|
|
@@ -700,9 +700,9 @@ describe('update command tests', () => {
|
|
|
700
700
|
],
|
|
701
701
|
},
|
|
702
702
|
};
|
|
703
|
-
readFile.
|
|
703
|
+
readFile.mockResolvedValueOnce(JSON.stringify(sampleMesh));
|
|
704
704
|
|
|
705
|
-
parseSpy.
|
|
705
|
+
parseSpy.mockResolvedValueOnce({
|
|
706
706
|
args: { file: 'src/commands/__fixtures__/sample_mesh_files.json' },
|
|
707
707
|
flags: {
|
|
708
708
|
ignoreCache: mockIgnoreCacheFlag,
|
|
@@ -10,7 +10,6 @@ governing permissions and limitations under the License.
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
const { Command } = require('@oclif/core');
|
|
13
|
-
|
|
14
13
|
const { initSdk, initRequestId, promptConfirm, importFiles } = require('../../helpers');
|
|
15
14
|
const logger = require('../../classes/logger');
|
|
16
15
|
const CONSTANTS = require('../../constants');
|
|
@@ -31,7 +30,7 @@ const {
|
|
|
31
30
|
subscribeCredentialToMeshService,
|
|
32
31
|
} = require('../../lib/devConsole');
|
|
33
32
|
|
|
34
|
-
const { MULTITENANT_GRAPHQL_SERVER_BASE_URL } = CONSTANTS;
|
|
33
|
+
const { MULTITENANT_GRAPHQL_SERVER_BASE_URL, TMOConstants } = CONSTANTS;
|
|
35
34
|
|
|
36
35
|
class CreateCommand extends Command {
|
|
37
36
|
static args = [{ name: 'file' }];
|
|
@@ -157,10 +156,18 @@ class CreateCommand extends Command {
|
|
|
157
156
|
? MULTITENANT_GRAPHQL_SERVER_BASE_URL
|
|
158
157
|
: meshURL;
|
|
159
158
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
159
|
+
if (
|
|
160
|
+
meshUrl === TMOConstants.TMO_STAGE_URL ||
|
|
161
|
+
meshUrl === TMOConstants.TMO_SANDBOX_URL ||
|
|
162
|
+
meshUrl === TMOConstants.TMO_PROD_URL
|
|
163
|
+
) {
|
|
164
|
+
this.log('Mesh Endpoint: %s\n', `${meshUrl}/${mesh.meshId}/graphql`);
|
|
165
|
+
} else {
|
|
166
|
+
this.log(
|
|
167
|
+
'Mesh Endpoint: %s\n',
|
|
168
|
+
`${meshUrl}/${mesh.meshId}/graphql?api_key=${adobeIdIntegrationsForWorkspace.apiKey}`,
|
|
169
|
+
);
|
|
170
|
+
}
|
|
164
171
|
} else {
|
|
165
172
|
this.log(
|
|
166
173
|
'Unable to subscribe API Key %s to API Mesh service',
|
|
@@ -19,7 +19,7 @@ const { describeMesh, getMesh } = require('../../lib/devConsole');
|
|
|
19
19
|
|
|
20
20
|
require('dotenv').config();
|
|
21
21
|
|
|
22
|
-
const { MULTITENANT_GRAPHQL_SERVER_BASE_URL } = CONSTANTS;
|
|
22
|
+
const { MULTITENANT_GRAPHQL_SERVER_BASE_URL, TMOConstants } = CONSTANTS;
|
|
23
23
|
|
|
24
24
|
class DescribeCommand extends Command {
|
|
25
25
|
static flags = {
|
|
@@ -55,11 +55,17 @@ class DescribeCommand extends Command {
|
|
|
55
55
|
const { meshURL } = await getMesh(imsOrgId, projectId, workspaceId, meshId);
|
|
56
56
|
const meshUrl = meshURL === '' ? MULTITENANT_GRAPHQL_SERVER_BASE_URL : meshURL;
|
|
57
57
|
|
|
58
|
-
if (
|
|
58
|
+
if (
|
|
59
|
+
apiKey &&
|
|
60
|
+
(meshUrl === TMOConstants.TMO_STAGE_URL ||
|
|
61
|
+
meshUrl === TMOConstants.TMO_SANDBOX_URL ||
|
|
62
|
+
meshUrl === TMOConstants.TMO_PROD_URL)
|
|
63
|
+
) {
|
|
64
|
+
this.log('Mesh Endpoint: %s\n', `${meshUrl}/${meshId}/graphql`);
|
|
65
|
+
} else if (apiKey) {
|
|
59
66
|
this.log('API Key: %s', apiKey);
|
|
60
67
|
this.log('Mesh Endpoint: %s\n', `${meshUrl}/${meshId}/graphql?api_key=${apiKey}`);
|
|
61
68
|
}
|
|
62
|
-
|
|
63
69
|
return meshDetails;
|
|
64
70
|
} else {
|
|
65
71
|
logger.error(
|
package/src/constants.js
CHANGED
|
@@ -19,5 +19,10 @@ const ProdConstants = {
|
|
|
19
19
|
AIO_CLI_API_KEY: 'aio-cli-console-auth',
|
|
20
20
|
SMS_BASE_URL: 'https://graph.adobe.io/api-admin',
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const TMOConstants = {
|
|
23
|
+
TMO_STAGE_URL: 'https://tigraph-dev.adobe.io/api',
|
|
24
|
+
TMO_SANDBOX_URL: 'https://tigraph-sandbox.adobe.io/api',
|
|
25
|
+
TMO_PROD_URL: 'https://tigraph.adobe.io/api',
|
|
26
|
+
};
|
|
27
|
+
const envConstants = clientEnv === 'stage' ? StageConstants : ProdConstants;
|
|
28
|
+
module.exports = { ...envConstants, TMOConstants };
|
package/src/utils.js
CHANGED
|
@@ -79,7 +79,7 @@ function getFilesInMeshConfig(data, meshConfigName) {
|
|
|
79
79
|
|
|
80
80
|
// Additional Resolvers
|
|
81
81
|
data.meshConfig.additionalResolvers?.forEach(additionalResolver => {
|
|
82
|
-
if (!fileURLRegex.test(additionalResolver)) {
|
|
82
|
+
if (typeof additionalResolver === 'string' && !fileURLRegex.test(additionalResolver)) {
|
|
83
83
|
filesList.push(additionalResolver);
|
|
84
84
|
}
|
|
85
85
|
});
|
|
@@ -88,7 +88,9 @@ function getFilesInMeshConfig(data, meshConfigName) {
|
|
|
88
88
|
data.meshConfig.sources.transforms?.forEach(transform => {
|
|
89
89
|
transform.replaceField?.replacements.forEach(replacement => {
|
|
90
90
|
if (replacement.composer && !fileURLRegex.test(replacement.composer)) {
|
|
91
|
-
|
|
91
|
+
const [filename] = replacement.composer.split('#');
|
|
92
|
+
|
|
93
|
+
filesList.push(filename);
|
|
92
94
|
}
|
|
93
95
|
});
|
|
94
96
|
});
|
|
@@ -97,16 +99,51 @@ function getFilesInMeshConfig(data, meshConfigName) {
|
|
|
97
99
|
data.meshConfig.transforms?.forEach(transform => {
|
|
98
100
|
transform.replaceField?.replacements.forEach(replacement => {
|
|
99
101
|
if (replacement.composer && !fileURLRegex.test(replacement.composer)) {
|
|
100
|
-
|
|
102
|
+
const [filename] = replacement.composer.split('#');
|
|
103
|
+
|
|
104
|
+
filesList.push(filename);
|
|
101
105
|
}
|
|
102
106
|
});
|
|
103
107
|
});
|
|
104
108
|
|
|
109
|
+
// Hooks Plugin - mesh level
|
|
110
|
+
data.meshConfig.plugins?.forEach(plugin => {
|
|
111
|
+
if (plugin.hooks) {
|
|
112
|
+
if (plugin.hooks.beforeAll) {
|
|
113
|
+
const composer = plugin.hooks.beforeAll.composer;
|
|
114
|
+
|
|
115
|
+
if (composer && !fileURLRegex.test(composer)) {
|
|
116
|
+
const [filename] = composer.split('#');
|
|
117
|
+
|
|
118
|
+
filesList.push(filename);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// OnFetch plugin - mesh level
|
|
125
|
+
data.meshConfig.plugins?.forEach(plugin => {
|
|
126
|
+
if (plugin.onFetch) {
|
|
127
|
+
plugin.onFetch.forEach(onFetchConfig => {
|
|
128
|
+
const handler = onFetchConfig.handler;
|
|
129
|
+
|
|
130
|
+
if (handler) {
|
|
131
|
+
filesList.push(handler);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// remove duplicate files
|
|
138
|
+
filesList = [...new Set(filesList)];
|
|
139
|
+
|
|
140
|
+
logger.info(`Files to be imported: ${filesList.join(', ')}`);
|
|
141
|
+
|
|
105
142
|
try {
|
|
106
143
|
if (filesList.length) {
|
|
107
144
|
checkFilesAreUnderMeshDirectory(filesList, meshConfigName);
|
|
108
145
|
validateFileType(filesList);
|
|
109
|
-
validateFileName(filesList
|
|
146
|
+
validateFileName(filesList);
|
|
110
147
|
}
|
|
111
148
|
} catch (err) {
|
|
112
149
|
logger.error(err.message);
|
|
@@ -226,9 +263,8 @@ function validateFileType(filesList) {
|
|
|
226
263
|
* Validate the filenames
|
|
227
264
|
*
|
|
228
265
|
* @param filesList Files in sources, tranforms or additionalResolvers in the meshConfig
|
|
229
|
-
* @param data MeshConfig
|
|
230
266
|
*/
|
|
231
|
-
function validateFileName(filesList
|
|
267
|
+
function validateFileName(filesList) {
|
|
232
268
|
const filesWithInvalidNames = [];
|
|
233
269
|
|
|
234
270
|
// Check if the file names are less than 25 characters
|
|
@@ -244,17 +280,6 @@ function validateFileName(filesList, data) {
|
|
|
244
280
|
`Mesh file names must be less than 25 characters. The following file(s) are invalid: ${filesWithInvalidNames}.`,
|
|
245
281
|
);
|
|
246
282
|
}
|
|
247
|
-
|
|
248
|
-
// check if the the filePaths in the files array match
|
|
249
|
-
// the fileNames in sources, transforms or additionalResolvers
|
|
250
|
-
|
|
251
|
-
if (data.meshConfig.files) {
|
|
252
|
-
for (let i = 0; i < data.meshConfig.files.length; i++) {
|
|
253
|
-
if (filesList.indexOf(data.meshConfig.files[i].path) == -1) {
|
|
254
|
-
throw new Error(`Please make sure the file names are matching in meshConfig.`);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
283
|
}
|
|
259
284
|
|
|
260
285
|
/**validates the environment file content
|