@adobe/aio-cli-plugin-api-mesh 5.2.3 → 5.2.4-alpha.0

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.
Files changed (42) hide show
  1. package/oclif.manifest.json +1 -1
  2. package/package.json +5 -10
  3. package/src/commands/{api-mesh.js → PLUGINNAME/__tests__/index.test.js} +15 -13
  4. package/src/commands/PLUGINNAME/index.js +32 -0
  5. package/src/commands/api-mesh/__tests__/cache-purge.test.js +2 -2
  6. package/src/commands/api-mesh/__tests__/create.test.js +9 -21
  7. package/src/commands/api-mesh/__tests__/delete.test.js +2 -2
  8. package/src/commands/api-mesh/__tests__/describe.test.js +2 -2
  9. package/src/commands/api-mesh/__tests__/get-log-forwarding.test.js +149 -0
  10. package/src/commands/api-mesh/__tests__/get.test.js +2 -2
  11. package/src/commands/api-mesh/__tests__/log-get-bulk.test.js +2 -2
  12. package/src/commands/api-mesh/__tests__/log-get.test.js +2 -2
  13. package/src/commands/api-mesh/__tests__/log-list.test.js +2 -2
  14. package/src/commands/api-mesh/__tests__/run.test.js +67 -193
  15. package/src/commands/api-mesh/__tests__/set-log-forwarding.test.js +246 -0
  16. package/src/commands/api-mesh/__tests__/status.test.js +2 -2
  17. package/src/commands/api-mesh/__tests__/update.test.js +4 -6
  18. package/src/commands/api-mesh/cache/purge.js +1 -1
  19. package/src/commands/api-mesh/config/get/log-forwarding.js +78 -0
  20. package/src/commands/api-mesh/config/set/log-forwarding.js +156 -0
  21. package/src/commands/api-mesh/create.js +4 -3
  22. package/src/commands/api-mesh/delete.js +1 -1
  23. package/src/commands/api-mesh/describe.js +1 -1
  24. package/src/commands/api-mesh/get.js +1 -1
  25. package/src/commands/api-mesh/log-get-bulk.js +1 -1
  26. package/src/commands/api-mesh/log-get.js +1 -1
  27. package/src/commands/api-mesh/log-list.js +1 -1
  28. package/src/commands/api-mesh/run.js +162 -208
  29. package/src/commands/api-mesh/source/__tests__/install.test.js +2 -2
  30. package/src/commands/api-mesh/source/install.js +1 -1
  31. package/src/commands/api-mesh/status.js +1 -1
  32. package/src/commands/api-mesh/update.js +4 -3
  33. package/src/helpers.js +29 -20
  34. package/src/{worker.js → index.js} +7 -9
  35. package/src/lib/{devConsole.js → smsClient.js} +186 -1
  36. package/src/server.js +32 -74
  37. package/src/utils.js +46 -10
  38. package/src/wranglerServer.js +80 -0
  39. package/src/meshArtifact.js +0 -231
  40. package/src/project.js +0 -56
  41. package/src/wranglerCli.js +0 -54
  42. package/wrangler.toml +0 -13
@@ -19,8 +19,8 @@ const {
19
19
  initSdk,
20
20
  writeSecretsFile,
21
21
  } = require('../../../helpers');
22
- const { start } = require('../../../wranglerCli');
23
- const { getMeshId, getMeshArtifact } = require('../../../lib/devConsole');
22
+ const { runServer } = require('../../../server');
23
+ const { getMeshId, getMeshArtifact } = require('../../../lib/smsClient');
24
24
  require('@adobe-apimesh/mesh-builder');
25
25
 
26
26
  jest.mock('../../../helpers', () => ({
@@ -32,25 +32,20 @@ jest.mock('../../../helpers', () => ({
32
32
  }),
33
33
  initRequestId: jest.fn().mockResolvedValue({}),
34
34
  interpolateMesh: jest.fn().mockResolvedValue({}),
35
- importFiles: jest.fn().mockResolvedValue({}),
35
+ importFiles: jest.fn().mockResolvedValue(),
36
36
  promptConfirm: jest.fn().mockResolvedValue(true),
37
37
  setUpTenantFiles: jest.fn().mockResolvedValue(),
38
38
  writeSecretsFile: jest.fn().mockResolvedValue(),
39
39
  }));
40
40
 
41
- jest.mock('../../../wranglerCli', () => ({
42
- start: jest.fn().mockResolvedValue(),
41
+ jest.mock('../../../server', () => ({
42
+ runServer: jest.fn().mockResolvedValue(),
43
43
  }));
44
44
 
45
- jest.mock('../../../lib/devConsole', () => ({
45
+ jest.mock('../../../lib/smsClient', () => ({
46
46
  getMeshId: jest.fn().mockResolvedValue('mockMeshId'),
47
47
  getMeshArtifact: jest.fn().mockResolvedValue(),
48
48
  }));
49
-
50
- jest.mock('../../../fixPlugins', () => ({
51
- fixPlugins: jest.fn().mockResolvedValue({}),
52
- }));
53
-
54
49
  jest.mock('chalk', () => ({
55
50
  red: jest.fn(text => text), // Return the input text without any color formatting
56
51
  }));
@@ -80,6 +75,7 @@ const originalEnv = {
80
75
  API_MESH_TIER: 'NON-TI',
81
76
  };
82
77
 
78
+ const defaultPort = 5000;
83
79
  const os = require('os');
84
80
 
85
81
  describe('run command tests', () => {
@@ -98,6 +94,10 @@ describe('run command tests', () => {
98
94
  platformSpy.mockRestore();
99
95
  });
100
96
 
97
+ beforeAll(() => {
98
+ jest.spyOn(RunCommand.prototype, 'copyMeshContent').mockImplementation(() => {});
99
+ });
100
+
101
101
  test('snapshot run command description', () => {
102
102
  expect(RunCommand.description).toMatchInlineSnapshot(
103
103
  `"Run a local development server that builds and compiles a mesh locally"`,
@@ -138,18 +138,8 @@ describe('run command tests', () => {
138
138
  "parse": [Function],
139
139
  "type": "option",
140
140
  },
141
- "inspectPort": {
142
- "char": "i",
143
- "default": 9229,
144
- "description": "Port number for the local dev server inspector",
145
- "input": [],
146
- "multiple": false,
147
- "parse": [Function],
148
- "type": "option",
149
- },
150
141
  "port": {
151
142
  "char": "p",
152
- "default": 5000,
153
143
  "description": "Port number for the local dev server",
154
144
  "input": [],
155
145
  "multiple": false,
@@ -198,23 +188,15 @@ describe('run command tests', () => {
198
188
  });
199
189
 
200
190
  test('should use the port number provided in the flags for starting the server', async () => {
201
- const cliInput = {
191
+ const parseOutput = {
202
192
  args: { file: 'src/commands/__fixtures__/sample_mesh.json' },
203
- flags: {
204
- port: 6000,
205
- debug: false,
206
- inspectPort: 9229,
207
- },
193
+ flags: { port: 6000, debug: false },
208
194
  };
209
- parseSpy.mockResolvedValueOnce(cliInput);
195
+
196
+ parseSpy.mockResolvedValue(parseOutput);
210
197
 
211
198
  await RunCommand.run();
212
- expect(start).toHaveBeenCalledWith(
213
- expect.anything(),
214
- cliInput.flags.port,
215
- cliInput.flags.debug,
216
- cliInput.flags.inspectPort,
217
- );
199
+ expect(runServer).toHaveBeenCalledWith(parseOutput.flags.port);
218
200
  });
219
201
 
220
202
  test('should use the port number provided in the .env file if there is no port', async () => {
@@ -223,23 +205,15 @@ describe('run command tests', () => {
223
205
  PORT: 7000,
224
206
  };
225
207
 
226
- const cliInput = {
208
+ const parseOutput = {
227
209
  args: { file: 'src/commands/__fixtures__/sample_mesh.json' },
228
- flags: {
229
- port: 5000,
230
- debug: false,
231
- inspectPort: 9229,
232
- },
210
+ flags: { debug: false },
233
211
  };
234
- parseSpy.mockResolvedValueOnce(cliInput);
212
+
213
+ parseSpy.mockResolvedValue(parseOutput);
235
214
 
236
215
  await RunCommand.run();
237
- expect(start).toHaveBeenCalledWith(
238
- expect.anything(),
239
- process.env.PORT,
240
- cliInput.flags.debug,
241
- cliInput.flags.inspectPort,
242
- );
216
+ expect(runServer).toHaveBeenCalledWith(process.env.PORT);
243
217
  });
244
218
 
245
219
  test('should use the default port if port number is not provided explicitly', async () => {
@@ -247,23 +221,15 @@ describe('run command tests', () => {
247
221
  ...originalEnv,
248
222
  };
249
223
 
250
- const cliInput = {
224
+ const parseOutput = {
251
225
  args: { file: 'src/commands/__fixtures__/sample_mesh.json' },
252
- flags: {
253
- port: 5000,
254
- debug: false,
255
- inspectPort: 9229,
256
- },
226
+ flags: { debug: false },
257
227
  };
258
- parseSpy.mockResolvedValueOnce(cliInput);
228
+
229
+ parseSpy.mockResolvedValue(parseOutput);
259
230
 
260
231
  await RunCommand.run();
261
- expect(start).toHaveBeenCalledWith(
262
- expect.anything(),
263
- cliInput.flags.port,
264
- cliInput.flags.debug,
265
- cliInput.flags.inspectPort,
266
- );
232
+ expect(runServer).toHaveBeenCalledWith(defaultPort);
267
233
  });
268
234
 
269
235
  test('should return error for run command if the mesh has placeholders and env file provided using --env flag is not found', async () => {
@@ -411,6 +377,14 @@ describe('run command tests', () => {
411
377
  });
412
378
 
413
379
  test('should successfully run the mesh if provided env file is valid, mesh interpolation is successful and interpolated mesh is a valid JSON', async () => {
380
+ parseSpy.mockResolvedValueOnce({
381
+ args: { file: 'src/commands/__fixtures__/sample_mesh_with_placeholder' },
382
+ flags: {
383
+ env: 'src/commands/__fixtures__/env_valid',
384
+ debug: false,
385
+ },
386
+ });
387
+
414
388
  //sampleInterpolated mesh where the mesh string is a valid JSON
415
389
  const sampleInterpolatedMesh =
416
390
  '{"meshConfig":{"sources":[{"name":"<api-name>","handler":{"graphql":{"endpoint":"<api-url>"}}}],"responseConfig":{"includeHTTPDetails":true}}}';
@@ -421,24 +395,8 @@ describe('run command tests', () => {
421
395
  interpolatedMeshData: sampleInterpolatedMesh,
422
396
  });
423
397
 
424
- const cliInput = {
425
- args: { file: 'src/commands/__fixtures__/sample_mesh_with_placeholder' },
426
- flags: {
427
- env: 'src/commands/__fixtures__/env_valid',
428
- port: 5000,
429
- debug: false,
430
- inspectPort: 9229,
431
- },
432
- };
433
- parseSpy.mockResolvedValueOnce(cliInput);
434
-
435
398
  await RunCommand.run();
436
- expect(start).toHaveBeenCalledWith(
437
- expect.anything(),
438
- cliInput.flags.port,
439
- cliInput.flags.debug,
440
- cliInput.flags.inspectPort,
441
- );
399
+ expect(runServer).toHaveBeenCalledWith(defaultPort);
442
400
  });
443
401
 
444
402
  // file import tests
@@ -471,30 +429,20 @@ describe('run command tests', () => {
471
429
  ],
472
430
  };
473
431
 
474
- const cliInput = {
432
+ parseSpy.mockResolvedValueOnce({
475
433
  args: { file: 'src/commands/__fixtures__/sample_mesh_files.json' },
476
434
  flags: {
477
435
  autoConfirmAction: Promise.resolve(true),
478
- port: 5000,
479
436
  debug: false,
480
- inspectPort: 9229,
481
437
  },
482
- };
483
- parseSpy.mockResolvedValueOnce(cliInput);
438
+ });
484
439
 
485
440
  importFiles.mockResolvedValueOnce({
486
- data: {
487
- meshConfig,
488
- },
441
+ meshConfig,
489
442
  });
490
443
 
491
444
  await RunCommand.run();
492
- expect(start).toHaveBeenCalledWith(
493
- expect.anything(),
494
- cliInput.flags.port,
495
- cliInput.flags.debug,
496
- cliInput.flags.inspectPort,
497
- );
445
+ expect(runServer).toHaveBeenCalledWith(defaultPort);
498
446
  });
499
447
 
500
448
  test('should fail if the file name is more than 25 characters', async () => {
@@ -660,29 +608,17 @@ describe('run command tests', () => {
660
608
 
661
609
  promptConfirm.mockResolvedValueOnce(false).mockResolvedValueOnce(true);
662
610
 
663
- importFiles.mockResolvedValueOnce({
664
- data: {
665
- meshConfig,
666
- },
667
- });
611
+ importFiles.mockResolvedValueOnce(meshConfig);
668
612
 
669
- const cliInput = {
613
+ parseSpy.mockResolvedValueOnce({
670
614
  args: { file: 'src/commands/__fixtures__/sample_mesh_with_files_array.json' },
671
615
  flags: {
672
- port: 5000,
673
616
  debug: false,
674
- inspectPort: 9229,
675
617
  },
676
- };
677
- parseSpy.mockResolvedValueOnce(cliInput);
618
+ });
678
619
 
679
620
  await RunCommand.run();
680
- expect(start).toHaveBeenCalledWith(
681
- expect.anything(),
682
- cliInput.flags.port,
683
- cliInput.flags.debug,
684
- cliInput.flags.inspectPort,
685
- );
621
+ expect(runServer).toHaveBeenCalledWith(defaultPort);
686
622
  });
687
623
 
688
624
  test('should override if prompt returns Yes, if there is files array', async () => {
@@ -716,30 +652,20 @@ describe('run command tests', () => {
716
652
 
717
653
  promptConfirm.mockResolvedValueOnce(true).mockResolvedValueOnce(true);
718
654
 
719
- const cliInput = {
655
+ parseSpy.mockResolvedValueOnce({
720
656
  args: { file: 'src/commands/__fixtures__/sample_mesh_with_files_array.json' },
721
657
  flags: {
722
- port: 5000,
723
658
  debug: false,
724
- inspectPort: 9229,
725
659
  },
726
- };
727
- parseSpy.mockResolvedValueOnce(cliInput);
660
+ });
728
661
 
729
662
  importFiles.mockResolvedValueOnce({
730
- data: {
731
- meshConfig,
732
- },
663
+ meshConfig,
733
664
  });
734
665
 
735
666
  await RunCommand.run();
736
667
 
737
- expect(start).toHaveBeenCalledWith(
738
- expect.anything(),
739
- cliInput.flags.port,
740
- cliInput.flags.debug,
741
- cliInput.flags.inspectPort,
742
- );
668
+ expect(runServer).toHaveBeenCalledWith(defaultPort);
743
669
  });
744
670
 
745
671
  test('should pass for a fully-qualified meshConfig even if the file does not exist in fileSystem', async () => {
@@ -771,32 +697,22 @@ describe('run command tests', () => {
771
697
  ],
772
698
  };
773
699
 
774
- const cliInput = {
700
+ parseSpy.mockResolvedValueOnce({
775
701
  args: { file: 'src/commands/__fixtures__/sample_fully_qualified_mesh.json' },
776
702
  flags: {
777
703
  autoConfirmAction: Promise.resolve(true),
778
- port: 5000,
779
704
  debug: false,
780
- inspectPort: 9229,
781
705
  },
782
- };
783
- parseSpy.mockResolvedValueOnce(cliInput);
706
+ });
784
707
 
785
708
  promptConfirm.mockResolvedValueOnce(true);
786
709
 
787
710
  importFiles.mockResolvedValueOnce({
788
- data: {
789
- meshConfig,
790
- },
711
+ meshConfig,
791
712
  });
792
713
 
793
714
  await RunCommand.run();
794
- expect(start).toHaveBeenCalledWith(
795
- expect.anything(),
796
- cliInput.flags.port,
797
- cliInput.flags.debug,
798
- cliInput.flags.inspectPort,
799
- );
715
+ expect(runServer).toHaveBeenCalledWith(defaultPort);
800
716
  });
801
717
 
802
718
  test('should pass if the file is located in subdirectory of mesh directory', async () => {
@@ -828,31 +744,21 @@ describe('run command tests', () => {
828
744
  ],
829
745
  };
830
746
 
831
- const cliInput = {
747
+ parseSpy.mockResolvedValueOnce({
832
748
  args: { file: 'src/commands/__fixtures__/sample_mesh_subdirectory.json' },
833
749
  flags: {
834
750
  autoConfirmAction: Promise.resolve(true),
835
- port: 5000,
836
751
  debug: false,
837
- inspectPort: 9229,
838
752
  },
839
- };
840
- parseSpy.mockResolvedValueOnce(cliInput);
753
+ });
841
754
 
842
755
  importFiles.mockResolvedValueOnce({
843
- data: {
844
- meshConfig,
845
- },
756
+ meshConfig,
846
757
  });
847
758
 
848
759
  await RunCommand.run();
849
760
 
850
- expect(start).toHaveBeenCalledWith(
851
- expect.anything(),
852
- cliInput.flags.port,
853
- cliInput.flags.debug,
854
- cliInput.flags.inspectPort,
855
- );
761
+ expect(runServer).toHaveBeenCalledWith(defaultPort);
856
762
  });
857
763
 
858
764
  test('should fail if the file is outside the workspace directory', async () => {
@@ -1013,25 +919,17 @@ describe('run command tests', () => {
1013
919
  });
1014
920
 
1015
921
  test('should successfully run the mesh if provided secrets file is valid', async () => {
1016
- const cliInput = {
922
+ parseSpy.mockResolvedValueOnce({
1017
923
  args: { file: 'src/commands/__fixtures__/sample_secrets_mesh.json' },
1018
924
  flags: {
1019
925
  secrets: 'src/commands/__fixtures__/secrets_valid.yaml',
1020
- port: 5000,
1021
926
  debug: false,
1022
- inspectPort: 9229,
1023
927
  },
1024
- };
1025
- parseSpy.mockResolvedValueOnce(cliInput);
928
+ });
1026
929
 
1027
930
  await RunCommand.run();
1028
931
  expect(writeSecretsFile).toHaveBeenCalled();
1029
- expect(start).toHaveBeenCalledWith(
1030
- expect.anything(),
1031
- cliInput.flags.port,
1032
- cliInput.flags.debug,
1033
- cliInput.flags.inspectPort,
1034
- );
932
+ expect(runServer).toHaveBeenCalledWith(defaultPort);
1035
933
  });
1036
934
 
1037
935
  test('should return error if ran with secrets against windows platform with batch variables', async () => {
@@ -1059,72 +957,48 @@ describe('run command tests', () => {
1059
957
 
1060
958
  test('should pass if ran with secrets against linux platform with batch variables', async () => {
1061
959
  platformSpy.mockReturnValue('linux');
1062
- const cliInput = {
960
+ parseSpy.mockResolvedValueOnce({
1063
961
  args: { file: 'src/commands/__fixtures__/sample_secrets_mesh.json' },
1064
962
  flags: {
1065
963
  secrets: 'src/commands/__fixtures__/secrets_with_batch_variables.yaml',
1066
- port: 5000,
1067
964
  debug: false,
1068
- inspectPort: 9229,
1069
965
  },
1070
- };
1071
- parseSpy.mockResolvedValueOnce(cliInput);
966
+ });
1072
967
 
1073
968
  await RunCommand.run();
1074
969
  expect(writeSecretsFile).toHaveBeenCalled();
1075
- expect(start).toHaveBeenCalledWith(
1076
- expect.anything(),
1077
- cliInput.flags.port,
1078
- cliInput.flags.debug,
1079
- cliInput.flags.inspectPort,
1080
- );
970
+ expect(runServer).toHaveBeenCalledWith(defaultPort);
1081
971
  });
1082
972
 
1083
973
  test('should pass if ran with secrets against darwin(macOS) platform with batch variables', async () => {
1084
974
  platformSpy.mockReturnValue('darwin');
1085
- const cliInput = {
975
+ parseSpy.mockResolvedValueOnce({
1086
976
  args: { file: 'src/commands/__fixtures__/sample_secrets_mesh.json' },
1087
977
  flags: {
1088
978
  secrets: 'src/commands/__fixtures__/secrets_with_batch_variables.yaml',
1089
- port: 5000,
1090
979
  debug: false,
1091
- inspectPort: 9229,
1092
980
  },
1093
- };
1094
- parseSpy.mockResolvedValueOnce(cliInput);
981
+ });
1095
982
 
1096
983
  await RunCommand.run();
1097
984
  expect(writeSecretsFile).toHaveBeenCalled();
1098
- expect(start).toHaveBeenCalledWith(
1099
- expect.anything(),
1100
- cliInput.flags.port,
1101
- cliInput.flags.debug,
1102
- cliInput.flags.inspectPort,
1103
- );
985
+ expect(runServer).toHaveBeenCalledWith(defaultPort);
1104
986
  });
1105
987
 
1106
988
  test('should escape variables that are preceded by backslash symbol', async () => {
1107
- const cliInput = {
989
+ parseSpy.mockResolvedValueOnce({
1108
990
  args: { file: 'src/commands/__fixtures__/sample_mesh_with_escaped_secrets.json' },
1109
991
  flags: {
1110
992
  secrets: 'src/commands/__fixtures__/secrets_with_escaped_variables.yaml',
1111
- port: 5000,
1112
993
  debug: false,
1113
- inspectPort: 9229,
1114
994
  },
1115
- };
1116
- parseSpy.mockResolvedValueOnce(cliInput);
995
+ });
1117
996
 
1118
997
  await RunCommand.run();
1119
998
  expect(writeSecretsFile).toHaveBeenCalledWith(
1120
999
  'Home: rootPath\nHomeString: $HOME\nHomeWithSlash: \\rootPath\nHomeStringWithSlash: \\$HOME\n',
1121
1000
  expect.anything(),
1122
1001
  );
1123
- expect(start).toHaveBeenCalledWith(
1124
- expect.anything(),
1125
- cliInput.flags.port,
1126
- cliInput.flags.debug,
1127
- cliInput.flags.inspectPort,
1128
- );
1002
+ expect(runServer).toHaveBeenCalledWith(defaultPort);
1129
1003
  });
1130
1004
  });