@adobe/aio-cli-plugin-api-mesh 5.2.4-alpha.0 → 5.3.0-beta.1
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 +13 -6
- package/src/commands/api-mesh/__tests__/cache-purge.test.js +1 -2
- package/src/commands/api-mesh/__tests__/create.test.js +19 -22
- package/src/commands/api-mesh/__tests__/delete-log-forwarding.test.js +106 -0
- package/src/commands/api-mesh/__tests__/delete.test.js +1 -2
- package/src/commands/api-mesh/__tests__/describe.test.js +1 -3
- package/src/commands/api-mesh/__tests__/get.test.js +2 -2
- package/src/commands/api-mesh/__tests__/log-get-bulk.test.js +19 -213
- package/src/commands/api-mesh/__tests__/run.test.js +191 -65
- package/src/commands/api-mesh/__tests__/update.test.js +8 -7
- package/src/commands/api-mesh/cache/purge.js +1 -3
- package/src/commands/api-mesh/config/delete/log-forwarding.js +80 -0
- package/src/commands/api-mesh/create.js +22 -6
- package/src/commands/api-mesh/delete.js +1 -3
- package/src/commands/api-mesh/describe.js +1 -3
- package/src/commands/api-mesh/get.js +1 -3
- package/src/commands/api-mesh/log-get-bulk.js +5 -26
- package/src/commands/api-mesh/log-get.js +1 -3
- package/src/commands/api-mesh/log-list.js +1 -3
- package/src/commands/api-mesh/run.js +207 -168
- package/src/commands/api-mesh/source/discover.js +2 -9
- package/src/commands/api-mesh/source/get.js +1 -8
- package/src/commands/api-mesh/source/install.js +1 -2
- package/src/commands/api-mesh/status.js +1 -2
- package/src/commands/api-mesh/update.js +21 -6
- package/src/commands/{PLUGINNAME/__tests__/index.test.js → api-mesh.js} +13 -15
- package/src/helpers.js +73 -15
- package/src/hooks/initMetadata.js +8 -0
- package/src/lib/smsClient.js +115 -1
- package/src/meshArtifact.js +231 -0
- package/src/project.js +56 -0
- package/src/server.js +74 -32
- package/src/utils.js +26 -24
- package/src/{index.js → worker.js} +9 -7
- package/src/wranglerCli.js +54 -0
- package/wrangler.toml +13 -0
- package/src/commands/PLUGINNAME/index.js +0 -32
- package/src/wranglerServer.js +0 -80
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const GetBulkLogCommand = require('../log-get-bulk');
|
|
4
|
-
const {
|
|
4
|
+
const { initSdk, promptConfirm } = require('../../../helpers');
|
|
5
5
|
const { getMeshId, getPresignedUrls } = require('../../../lib/smsClient');
|
|
6
6
|
const {
|
|
7
7
|
suggestCorrectedDateFormat,
|
|
@@ -251,7 +251,6 @@ describe('GetBulkLogCommand', () => {
|
|
|
251
251
|
const command = new GetBulkLogCommand([], {});
|
|
252
252
|
await command.run();
|
|
253
253
|
|
|
254
|
-
expect(initRequestId).toHaveBeenCalled();
|
|
255
254
|
expect(initSdk).toHaveBeenCalled();
|
|
256
255
|
expect(getMeshId).toHaveBeenCalledWith('orgCode', 'projectId', 'workspaceId', 'workspaceName');
|
|
257
256
|
expect(getPresignedUrls).toHaveBeenCalledWith(
|
|
@@ -296,194 +295,11 @@ describe('GetBulkLogCommand startTime and endTime validation', () => {
|
|
|
296
295
|
);
|
|
297
296
|
});
|
|
298
297
|
|
|
299
|
-
describe('GetBulkLogCommand with --past and --from flags', () => {
|
|
300
|
-
let parseSpy;
|
|
301
|
-
|
|
302
|
-
let now;
|
|
303
|
-
let fromDate;
|
|
304
|
-
beforeEach(() => {
|
|
305
|
-
now = new Date();
|
|
306
|
-
fromDate = new Date(now);
|
|
307
|
-
fromDate.setDate(fromDate.getDate() - 29); // Set fromDate to 29 days ago
|
|
308
|
-
parseSpy = jest.spyOn(GetBulkLogCommand.prototype, 'parse').mockResolvedValue({
|
|
309
|
-
flags: {
|
|
310
|
-
past: '20mins',
|
|
311
|
-
from: fromDate.toISOString().slice(0, 10) + ':12:00:00',
|
|
312
|
-
filename: 'test.csv',
|
|
313
|
-
ignoreCache: false,
|
|
314
|
-
},
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
initSdk.mockResolvedValue({
|
|
318
|
-
imsOrgId: 'orgId',
|
|
319
|
-
imsOrgCode: 'orgCode',
|
|
320
|
-
projectId: 'projectId',
|
|
321
|
-
workspaceId: 'workspaceId',
|
|
322
|
-
workspaceName: 'workspaceName',
|
|
323
|
-
});
|
|
324
|
-
getMeshId.mockResolvedValue('meshId');
|
|
325
|
-
getPresignedUrls.mockResolvedValue({
|
|
326
|
-
presignedUrls: [{ key: 'log1.csv', url: 'http://example.com/someHash' }],
|
|
327
|
-
totalSize: 2048,
|
|
328
|
-
});
|
|
329
|
-
promptConfirm.mockResolvedValue(true);
|
|
330
|
-
global.requestId = 'dummy_request_id';
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
afterEach(() => {
|
|
334
|
-
jest.clearAllMocks();
|
|
335
|
-
// clear the date objects
|
|
336
|
-
now = null;
|
|
337
|
-
fromDate = null;
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
test('runs with valid --past and --from flags', async () => {
|
|
341
|
-
fs.existsSync.mockReturnValue(true);
|
|
342
|
-
fs.statSync.mockReturnValue({ size: 0 });
|
|
343
|
-
|
|
344
|
-
const mockWriteStream = {
|
|
345
|
-
write: jest.fn(),
|
|
346
|
-
end: jest.fn(),
|
|
347
|
-
on: jest.fn((event, callback) => {
|
|
348
|
-
if (event === 'finish') {
|
|
349
|
-
callback();
|
|
350
|
-
}
|
|
351
|
-
}),
|
|
352
|
-
};
|
|
353
|
-
fs.createWriteStream.mockReturnValue(mockWriteStream);
|
|
354
|
-
|
|
355
|
-
const command = new GetBulkLogCommand([], {});
|
|
356
|
-
await command.run();
|
|
357
|
-
|
|
358
|
-
expect(initRequestId).toHaveBeenCalled();
|
|
359
|
-
expect(initSdk).toHaveBeenCalled();
|
|
360
|
-
expect(getMeshId).toHaveBeenCalledWith('orgCode', 'projectId', 'workspaceId', 'workspaceName');
|
|
361
|
-
expect(getPresignedUrls).toHaveBeenCalledWith(
|
|
362
|
-
'orgCode',
|
|
363
|
-
'projectId',
|
|
364
|
-
'workspaceId',
|
|
365
|
-
'meshId',
|
|
366
|
-
expect.any(String),
|
|
367
|
-
expect.any(String),
|
|
368
|
-
);
|
|
369
|
-
expect(fs.createWriteStream).toHaveBeenCalledWith(path.resolve(process.cwd(), 'test.csv'), {
|
|
370
|
-
flags: 'a',
|
|
371
|
-
});
|
|
372
|
-
expect(mockWriteStream.write).toHaveBeenCalled();
|
|
373
|
-
expect(mockWriteStream.end).toHaveBeenCalled();
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
test('throws an error with invalid --from date components', async () => {
|
|
377
|
-
parseSpy.mockResolvedValueOnce({
|
|
378
|
-
flags: {
|
|
379
|
-
past: '20mins',
|
|
380
|
-
from: fromDate.toISOString().slice(0, 10) + ':25:61:61',
|
|
381
|
-
filename: 'test.csv',
|
|
382
|
-
ignoreCache: false,
|
|
383
|
-
},
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
const command = new GetBulkLogCommand([], {});
|
|
387
|
-
await expect(command.run()).rejects.toThrow(
|
|
388
|
-
'Invalid date components passed in --from. Correct the date.',
|
|
389
|
-
);
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
test('throws an error with invalid --from date format', async () => {
|
|
393
|
-
parseSpy.mockResolvedValueOnce({
|
|
394
|
-
flags: {
|
|
395
|
-
past: '15mins',
|
|
396
|
-
from: fromDate.toISOString().slice(0, 10).replace(/-/g, ':') + ':15:00:00',
|
|
397
|
-
filename: 'test.csv',
|
|
398
|
-
ignoreCache: false,
|
|
399
|
-
},
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
const command = new GetBulkLogCommand([], {});
|
|
403
|
-
await expect(command.run()).rejects.toThrow(
|
|
404
|
-
'Invalid format. Use the format YYYY-MM-DD:HH:MM:SS for --from.',
|
|
405
|
-
);
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
test('runs with valid --past flag without --from', async () => {
|
|
409
|
-
parseSpy.mockResolvedValueOnce({
|
|
410
|
-
flags: {
|
|
411
|
-
past: '15mins',
|
|
412
|
-
filename: 'test.csv',
|
|
413
|
-
ignoreCache: false,
|
|
414
|
-
},
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
fs.existsSync.mockReturnValue(true);
|
|
418
|
-
fs.statSync.mockReturnValue({ size: 0 });
|
|
419
|
-
|
|
420
|
-
const command = new GetBulkLogCommand([], {});
|
|
421
|
-
await command.run();
|
|
422
|
-
|
|
423
|
-
expect(initRequestId).toHaveBeenCalled();
|
|
424
|
-
expect(initSdk).toHaveBeenCalled();
|
|
425
|
-
expect(getMeshId).toHaveBeenCalledWith('orgCode', 'projectId', 'workspaceId', 'workspaceName');
|
|
426
|
-
expect(getPresignedUrls).toHaveBeenCalledWith(
|
|
427
|
-
'orgCode',
|
|
428
|
-
'projectId',
|
|
429
|
-
'workspaceId',
|
|
430
|
-
'meshId',
|
|
431
|
-
expect.any(String),
|
|
432
|
-
expect.any(String),
|
|
433
|
-
);
|
|
434
|
-
});
|
|
435
|
-
|
|
436
|
-
test('throws an error with edge case for --past duration', async () => {
|
|
437
|
-
parseSpy.mockResolvedValueOnce({
|
|
438
|
-
flags: {
|
|
439
|
-
past: '0s',
|
|
440
|
-
from: fromDate.toISOString().slice(0, 10) + ':12:00:00',
|
|
441
|
-
filename: 'test.csv',
|
|
442
|
-
ignoreCache: false,
|
|
443
|
-
},
|
|
444
|
-
});
|
|
445
|
-
|
|
446
|
-
const command = new GetBulkLogCommand([], {});
|
|
447
|
-
await expect(command.run()).rejects.toThrow(
|
|
448
|
-
'Invalid format. The past time window should be in minutes, for example, "20 mins", "15 minutes".',
|
|
449
|
-
);
|
|
450
|
-
});
|
|
451
|
-
|
|
452
|
-
test('runs with edge case for --from date', async () => {
|
|
453
|
-
parseSpy.mockResolvedValueOnce({
|
|
454
|
-
flags: {
|
|
455
|
-
past: '15mins',
|
|
456
|
-
from: fromDate.toISOString().slice(0, 10) + ':00:00:00',
|
|
457
|
-
filename: 'test.csv',
|
|
458
|
-
ignoreCache: false,
|
|
459
|
-
},
|
|
460
|
-
});
|
|
461
|
-
|
|
462
|
-
fs.existsSync.mockReturnValue(true);
|
|
463
|
-
fs.statSync.mockReturnValue({ size: 0 });
|
|
464
|
-
|
|
465
|
-
const command = new GetBulkLogCommand([], {});
|
|
466
|
-
await command.run();
|
|
467
|
-
|
|
468
|
-
expect(initRequestId).toHaveBeenCalled();
|
|
469
|
-
expect(initSdk).toHaveBeenCalled();
|
|
470
|
-
expect(getMeshId).toHaveBeenCalledWith('orgCode', 'projectId', 'workspaceId', 'workspaceName');
|
|
471
|
-
expect(getPresignedUrls).toHaveBeenCalledWith(
|
|
472
|
-
'orgCode',
|
|
473
|
-
'projectId',
|
|
474
|
-
'workspaceId',
|
|
475
|
-
'meshId',
|
|
476
|
-
expect.any(String),
|
|
477
|
-
expect.any(String),
|
|
478
|
-
);
|
|
479
|
-
});
|
|
480
|
-
});
|
|
481
|
-
|
|
482
298
|
describe('validateDateTimeRange', () => {
|
|
483
299
|
const testCases = [
|
|
484
300
|
{
|
|
485
|
-
startTime:
|
|
486
|
-
endTime:
|
|
301
|
+
startTime: new Date(new Date().getTime() - 45 * 60 * 1000).toISOString(),
|
|
302
|
+
endTime: new Date().toISOString(),
|
|
487
303
|
error:
|
|
488
304
|
'The maximum duration between startTime and endTime is 30 minutes. The current duration is 0 hours 45 minutes and 0 seconds.',
|
|
489
305
|
},
|
|
@@ -498,18 +314,18 @@ describe('validateDateTimeRange', () => {
|
|
|
498
314
|
error: 'Cannot get logs more than 30 days old. Adjust your time range.',
|
|
499
315
|
},
|
|
500
316
|
{
|
|
501
|
-
startTime:
|
|
502
|
-
endTime:
|
|
503
|
-
error: 'The minimum duration is 1
|
|
317
|
+
startTime: new Date(new Date().getTime() - 20 * 1000).toISOString(),
|
|
318
|
+
endTime: new Date().toISOString(),
|
|
319
|
+
error: 'The minimum duration is 1 minute. The current duration is 20 seconds.',
|
|
504
320
|
},
|
|
505
321
|
{
|
|
506
|
-
startTime:
|
|
507
|
-
endTime:
|
|
322
|
+
startTime: new Date().toISOString(),
|
|
323
|
+
endTime: new Date(new Date().getTime() - 0.5 * 60 * 1000).toISOString(),
|
|
508
324
|
error: 'endTime must be greater than startTime',
|
|
509
325
|
},
|
|
510
326
|
{
|
|
511
|
-
startTime:
|
|
512
|
-
endTime:
|
|
327
|
+
startTime: new Date(new Date().getTime() - 20 * 60 * 1000).toISOString(),
|
|
328
|
+
endTime: new Date().toISOString(),
|
|
513
329
|
error: null,
|
|
514
330
|
},
|
|
515
331
|
];
|
|
@@ -528,16 +344,9 @@ describe('validateDateTimeRange', () => {
|
|
|
528
344
|
|
|
529
345
|
describe('parsePastDuration', () => {
|
|
530
346
|
const validDurations = [
|
|
531
|
-
['
|
|
532
|
-
['
|
|
533
|
-
['
|
|
534
|
-
['20 min', 20 * 60 * 1000],
|
|
535
|
-
['20mins', 20 * 60 * 1000],
|
|
536
|
-
['20 mins', 20 * 60 * 1000],
|
|
537
|
-
['20minute', 20 * 60 * 1000],
|
|
538
|
-
['20 minute', 20 * 60 * 1000],
|
|
539
|
-
['20minutes', 20 * 60 * 1000],
|
|
540
|
-
['20 minutes', 20 * 60 * 1000],
|
|
347
|
+
['20', 20 * 60 * 1000],
|
|
348
|
+
['30', 30 * 60 * 1000],
|
|
349
|
+
['15', 15 * 60 * 1000],
|
|
541
350
|
];
|
|
542
351
|
|
|
543
352
|
test.each(validDurations)(
|
|
@@ -548,14 +357,11 @@ describe('parsePastDuration', () => {
|
|
|
548
357
|
},
|
|
549
358
|
);
|
|
550
359
|
|
|
551
|
-
const invalidDurations = ['20h', '20 hours', '20s', '20 seconds'];
|
|
360
|
+
const invalidDurations = ['20h', '20 hours', '20s', '20 seconds', 'minutes', 'NaN', 'abc', ''];
|
|
552
361
|
|
|
553
|
-
test.each(invalidDurations)(
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
);
|
|
559
|
-
},
|
|
560
|
-
);
|
|
362
|
+
test.each(invalidDurations)('throws an error for non-numeric input "%s"', invalidPastDuration => {
|
|
363
|
+
expect(() => parsePastDuration(invalidPastDuration)).toThrow(
|
|
364
|
+
'Invalid format. The time window must be an integer, for example "20" or "15".',
|
|
365
|
+
);
|
|
366
|
+
});
|
|
561
367
|
});
|