@whotracksme/reporting 5.1.19 β†’ 5.1.20

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/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # v5.1.20 (Thu Aug 01 2024)
2
+
3
+ #### πŸ› Bug Fix
4
+
5
+ - Support expansion for plain objects in deduplicator expressions [#86](https://github.com/whotracksme/webextension-packages/pull/86) ([@philipp-classen](https://github.com/philipp-classen))
6
+
7
+ #### Authors: 1
8
+
9
+ - Philipp Claßen ([@philipp-classen](https://github.com/philipp-classen))
10
+
11
+ ---
12
+
1
13
  # v5.1.19 (Thu Aug 01 2024)
2
14
 
3
15
  #### πŸ› Bug Fix
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whotracksme/reporting",
3
- "version": "5.1.19",
3
+ "version": "5.1.20",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "scripts": {
@@ -65,6 +65,18 @@ function extractPath(obj, path, pos = 0) {
65
65
  if (results.length > 0) {
66
66
  return { match: true, value: results };
67
67
  }
68
+ } else if (obj && typeof obj === 'object') {
69
+ // handle plain objects
70
+ const results = {};
71
+ for (const [key, val] of Object.entries(obj)) {
72
+ const { match, value } = extractPath(val, path, pos + 1);
73
+ if (match) {
74
+ results[key] = value;
75
+ }
76
+ }
77
+ if (Object.keys(results).length > 0) {
78
+ return { match: true, value: results };
79
+ }
68
80
  }
69
81
  return { match: false };
70
82
  }
@@ -413,6 +413,169 @@ describe('#computeDeduplicationKey', function () {
413
413
  );
414
414
  });
415
415
 
416
+ it('should handle the expansion of array-like objects', function () {
417
+ duplicatedPayload(
418
+ {
419
+ 0: {
420
+ x: 'foo',
421
+ },
422
+ 1: {
423
+ x: 'bar',
424
+ },
425
+ },
426
+ {
427
+ 0: {
428
+ x: 'foo',
429
+ },
430
+ 1: {
431
+ x: 'bar',
432
+ },
433
+ },
434
+ '[].x',
435
+ );
436
+
437
+ nonDuplicatedPayload(
438
+ {
439
+ 0: {
440
+ x: 'foo',
441
+ },
442
+ 1: {
443
+ x: 'bar',
444
+ },
445
+ },
446
+ {
447
+ 0: {
448
+ x: 'foo',
449
+ },
450
+ 1: {
451
+ x: 'not bar',
452
+ },
453
+ },
454
+ '[].x',
455
+ );
456
+
457
+ duplicatedPayload(
458
+ {
459
+ 0: {
460
+ x: 'foo',
461
+ },
462
+ 1: {
463
+ x: 'bar',
464
+ },
465
+ },
466
+ {
467
+ 0: {
468
+ x: 'foo',
469
+ },
470
+ 1: {
471
+ x: 'bar',
472
+ ignore: 'not part of key',
473
+ },
474
+ },
475
+ '[].x',
476
+ );
477
+
478
+ duplicatedPayload(
479
+ {
480
+ x: {
481
+ foo: 'foo',
482
+ bar: 'bar',
483
+ },
484
+ y: {
485
+ foo: 'foo',
486
+ bar: 'bar',
487
+ },
488
+ },
489
+ {
490
+ y: {
491
+ bar: 'bar',
492
+ foo: 'foo',
493
+ },
494
+ x: {
495
+ bar: 'bar',
496
+ foo: 'foo',
497
+ },
498
+ },
499
+ '[].foo,[].bar',
500
+ );
501
+ });
502
+
503
+ it('should handle the expansion of plain objects', function () {
504
+ duplicatedPayload(
505
+ {
506
+ foo: 'foo',
507
+ bar: 'bar',
508
+ },
509
+ {
510
+ bar: 'bar',
511
+ foo: 'foo',
512
+ },
513
+ '[]',
514
+ );
515
+
516
+ duplicatedPayload(
517
+ {
518
+ foo: {
519
+ x: 'foo',
520
+ },
521
+ bar: {
522
+ x: 'bar',
523
+ },
524
+ },
525
+ {
526
+ bar: {
527
+ x: 'bar',
528
+ },
529
+ foo: {
530
+ x: 'foo',
531
+ },
532
+ },
533
+ '[].x',
534
+ );
535
+
536
+ nonDuplicatedPayload(
537
+ {
538
+ foo: {
539
+ x: 'foo',
540
+ y: 'only in first elem',
541
+ },
542
+ bar: {
543
+ x: 'bar',
544
+ },
545
+ },
546
+ {
547
+ bar: {
548
+ x: 'bar',
549
+ },
550
+ foo: {
551
+ x: 'foo',
552
+ },
553
+ },
554
+ '[].x,[].y',
555
+ );
556
+
557
+ duplicatedPayload(
558
+ {
559
+ foo: {
560
+ x: 'foo',
561
+ y: 'only in first elem, but will be ignored',
562
+ },
563
+ bar: {
564
+ x: 'bar',
565
+ },
566
+ },
567
+ {
568
+ bar: {
569
+ x: 'bar',
570
+ },
571
+ foo: {
572
+ x: 'foo',
573
+ },
574
+ },
575
+ '[].x',
576
+ );
577
+ });
578
+
416
579
  it('should ignore the order of fields (non-nested)', function () {
417
580
  duplicatedPayload(
418
581
  {