@contrail/flexplm 1.1.63 → 1.1.65

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.
@@ -665,6 +665,46 @@ describe('checkKeysAndValues', () => {
665
665
  expect(results.length).toBe(1);
666
666
  });
667
667
  });
668
+ describe('filterOutArchivedAndTrashedEntities', () => {
669
+ const config = {
670
+ apiHost: 'host',
671
+ userName: () => 'user',
672
+ password: () => 'pass',
673
+ urlContext: 'xxx',
674
+ vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
675
+ csrfEndpoint: '/servlet/rest/security/csrf',
676
+ itemPreDevelopmentLifecycleStages: ['concept']
677
+ };
678
+ const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
679
+ const dc = new data_converter_1.DataConverter(config, mapFileUtil);
680
+ it('filter out isArchived and isTrashed entities', () => {
681
+ const entities = [
682
+ { id: '1', name: 'Entity 1', isArchived: false, isTrashed: false },
683
+ { id: '2', name: 'Entity 2', isArchived: true, isTrashed: false },
684
+ { id: '3', name: 'Entity 3', isArchived: false, isTrashed: true },
685
+ { id: '4', name: 'Entity 4', isArchived: false, isTrashed: false }
686
+ ];
687
+ const filteredEntities = dc.filterOutArchivedAndTrashedEntities(entities);
688
+ expect(filteredEntities.length).toBe(2);
689
+ expect(filteredEntities).toEqual([
690
+ { id: '1', name: 'Entity 1', isArchived: false, isTrashed: false },
691
+ { id: '4', name: 'Entity 4', isArchived: false, isTrashed: false }
692
+ ]);
693
+ });
694
+ it('no entities to filter', () => {
695
+ const entities = [];
696
+ const filteredEntities = dc.filterOutArchivedAndTrashedEntities(entities);
697
+ expect(filteredEntities.length).toBe(0);
698
+ });
699
+ it('all entities are archived or trashed', () => {
700
+ const entities = [
701
+ { id: '1', name: 'Entity 1', isArchived: true, isTrashed: false },
702
+ { id: '2', name: 'Entity 2', isArchived: false, isTrashed: true }
703
+ ];
704
+ const filteredEntities = dc.filterOutArchivedAndTrashedEntities(entities);
705
+ expect(filteredEntities.length).toBe(0);
706
+ });
707
+ });
668
708
  describe('setUserListValue', () => {
669
709
  const config = {
670
710
  apiHost: 'host',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/flexplm",
3
- "version": "1.1.63",
3
+ "version": "1.1.65",
4
4
  "description": "Library used for integration with flexplm.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -41,6 +41,7 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@contrail/app-framework": "^1.3.4",
44
+ "@contrail/entity-types": "^1.5.2",
44
45
  "@contrail/sdk": "^1.4.3",
45
46
  "@contrail/transform-data": "^1.1.3",
46
47
  "@contrail/util": "^1.0.48",
@@ -1,5 +1,5 @@
1
1
  import { BaseProcessPublishAssortment } from './base-process-publish-assortment';
2
- import { apc_2bOWR2j9R0QThDVu_delete_history, fall_2003_deleteChanges_run2, fall_2003_fedMapping, fall_2003_fullChange, fall_2003_fullChange_run2, fall_2003_hydratedDetails, fall_2003_hydratedDetails_run2, plan1_across_month_DST, plan1_history } from './mockData';
2
+ import { apc_2bOWR2j9R0QThDVu_delete_history, fall_2003_deleteChanges_run2, fall_2003_fedMapping, fall_2003_fullChange, fall_2003_fullChange_run2, fall_2003_hydratedDetails, fall_2003_hydratedDetails_run2, plan1_across_month_DST, plan1_history, plan1_history_descending } from './mockData';
3
3
  import { FCConfig, SeasonFederation } from '../interfaces/interfaces';
4
4
  import { DataConverter } from '../util/data-converter';
5
5
  import { PublishChangeData } from '../interfaces/publish-change-data';
@@ -8,6 +8,7 @@ import { Entities } from '@contrail/sdk';
8
8
  import { TypeConversionUtils } from '../util/type-conversion-utils';
9
9
  import { MapUtil } from '../util/map-utils';
10
10
  import { ItemFamilyChanges } from '../interfaces/item-family-changes';
11
+ import { AssortmentPublishChange } from '@contrail/entity-types';
11
12
 
12
13
  let federatedId = '';
13
14
  jest.mock('../util/data-converter', () => {
@@ -512,7 +513,7 @@ describe('getSeasonFederation', () =>{
512
513
 
513
514
  describe('Test getSinceDate', () =>{
514
515
  it('getSinceDate from getSinceDateFromAPCs', async () =>{
515
- const history = new Array(...plan1_history);
516
+ const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
516
517
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
517
518
  const matchDate = new Date('2023-01-17T22:40:07.288Z');
518
519
 
@@ -529,7 +530,7 @@ describe('Test getSinceDate', () =>{
529
530
  expect(sinceDate).toEqual(matchDate);
530
531
  });
531
532
  it('getSinceDate date from config as year', async () =>{
532
- const history = new Array(...plan1_history);
533
+ const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
533
534
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
534
535
  const matchDate = new Date('2023-01-16T21:50:42.742Z');
535
536
 
@@ -548,7 +549,7 @@ describe('Test getSinceDate', () =>{
548
549
 
549
550
  it('getSinceDate date from config numberofdays-cross month', async () =>{
550
551
  const count = 10;
551
- const history = new Array(...plan1_across_month_DST);
552
+ const history = new Array(...plan1_across_month_DST) as any as AssortmentPublishChange[];
552
553
  const lastAPCId = '_mj--7nlyp7mmDrK';
553
554
  const matchDate = new Date('2023-02-25T19:13:58.902Z');
554
555
  const config = {sinceDate: 'numberofdays:'+ count } as any as FCConfig;
@@ -560,7 +561,7 @@ describe('Test getSinceDate', () =>{
560
561
  });
561
562
  it('getSinceDate date from config numberofdays-cross DST', async () =>{
562
563
  const count = 11;
563
- const history = new Array(...plan1_across_month_DST);
564
+ const history = new Array(...plan1_across_month_DST) as any as AssortmentPublishChange[];
564
565
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
565
566
  const matchDate = new Date('2023-03-06T21:50:42.742Z');
566
567
  const config = {sinceDate: 'numberofdays:'+ count } as any as FCConfig;
@@ -572,7 +573,7 @@ describe('Test getSinceDate', () =>{
572
573
  });
573
574
  it('getSinceDate date from config numberofpublishes', async () =>{
574
575
  const count = 3;
575
- const history = new Array(...plan1_history);
576
+ const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
576
577
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
577
578
  const matchDate = new Date('2023-01-17T22:35:20.517Z');
578
579
  const config = {sinceDate: 'numberofpublishes:'+ count } as any as FCConfig;
@@ -585,7 +586,7 @@ describe('Test getSinceDate', () =>{
585
586
 
586
587
  it('getSinceDate date from config numberofpublishes', async () =>{
587
588
  const count = 3;
588
- const history = new Array(...plan1_history);
589
+ const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
589
590
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
590
591
  const matchDate = new Date('2023-01-17T22:35:20.517Z');
591
592
  const config = {sinceDate: 'numberofpublishes:'+ count } as any as FCConfig;
@@ -602,7 +603,7 @@ describe('Test getSinceDate', () =>{
602
603
 
603
604
  describe('getSinceDateFromAPCSpecificDate', () =>{
604
605
  it('last apc - one day', () =>{
605
- const history = new Array(...plan1_history);
606
+ const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
606
607
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
607
608
  const matchDate = new Date('2023-01-16T21:50:42.742Z');
608
609
 
@@ -616,7 +617,7 @@ describe('getSinceDateFromAPCSpecificDate', () =>{
616
617
  });
617
618
 
618
619
  it('apc in the middle - one day', () =>{
619
- const history = new Array(...plan1_history);
620
+ const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
620
621
  const lastAPCId = 'GiT9CZXZGVljoYMR';
621
622
  const matchDate = new Date('2023-01-15T19:13:58.902Z');
622
623
 
@@ -629,7 +630,7 @@ describe('getSinceDateFromAPCSpecificDate', () =>{
629
630
  expect(sinceDate).toEqual(matchDate);
630
631
  });
631
632
  it('before initial publish', () => {
632
- const history = new Array(...plan1_history);
633
+ const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
633
634
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
634
635
  const matchDate = new Date('2023-01-15T19:13:58.902Z');
635
636
  const config = {} as FCConfig;
@@ -640,7 +641,7 @@ describe('getSinceDateFromAPCSpecificDate', () =>{
640
641
  expect(sinceDate).toEqual(matchDate);
641
642
  });
642
643
  it('numberofdays at 2 ', () => {
643
- const history = new Array(...plan1_history);
644
+ const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
644
645
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
645
646
  const matchDate = new Date('2023-01-15T19:13:58.902Z');
646
647
  const config = {} as FCConfig;
@@ -655,7 +656,7 @@ describe('getSinceDateFromAPCSpecificDate', () =>{
655
656
 
656
657
  describe('getSinceDateDaysPrevious', () =>{
657
658
  it('last apc - one day', () =>{
658
- const history = new Array(...plan1_history);
659
+ const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
659
660
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
660
661
  const matchDate = new Date('2023-01-16T21:50:42.742Z');
661
662
 
@@ -669,7 +670,7 @@ describe('getSinceDateDaysPrevious', () =>{
669
670
  });
670
671
 
671
672
  it('apc in the middle - one day', () =>{
672
- const history = new Array(...plan1_history);
673
+ const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
673
674
  const lastAPCId = 'GiT9CZXZGVljoYMR';
674
675
  const matchDate = new Date('2023-01-15T19:13:58.902Z');
675
676
 
@@ -682,7 +683,7 @@ describe('getSinceDateDaysPrevious', () =>{
682
683
  expect(sinceDate).toEqual(matchDate);
683
684
  });
684
685
  it('numberofdays greater than array size', () => {
685
- const history = new Array(...plan1_history);
686
+ const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
686
687
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
687
688
  const matchDate = new Date('2023-01-15T19:13:58.902Z');
688
689
  const config = {} as FCConfig;
@@ -693,7 +694,7 @@ describe('getSinceDateDaysPrevious', () =>{
693
694
  expect(sinceDate).toEqual(matchDate);
694
695
  });
695
696
  it('numberofdays at 2 ', () => {
696
- const history = new Array(...plan1_history);
697
+ const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
697
698
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
698
699
  const matchDate = new Date('2023-01-15T19:13:58.902Z');
699
700
  const config = {} as FCConfig;
@@ -706,9 +707,9 @@ describe('getSinceDateDaysPrevious', () =>{
706
707
 
707
708
  });
708
709
 
709
- describe('getSinceDateFromAPCs', () => {
710
- it('first / only apc', () => {
711
- const history = new Array(...plan1_history).slice(0, 1);
710
+ describe('getSinceDateFromAPCs - plan history in ascending order', () => {
711
+ it('oldest / only apc', () => {
712
+ const history = new Array(...plan1_history).slice(0, 1) as any as AssortmentPublishChange[];
712
713
  const lastAPCId = 'v9BKkHo-tpL0wUZN';
713
714
  const matchDate = new Date(0);
714
715
 
@@ -722,8 +723,8 @@ describe('getSinceDateFromAPCs', () => {
722
723
  expect(sinceDate).toEqual(matchDate);
723
724
  });
724
725
 
725
- it('first / multiple apcs in history', () => {
726
- const history = new Array(...plan1_history).slice(0, 3);
726
+ it('oldest / multiple apcs in history -ascending order', () => {
727
+ const history = new Array(...plan1_history).slice(0, 3) as any as AssortmentPublishChange[];
727
728
  const lastAPCId = 'v9BKkHo-tpL0wUZN';
728
729
  const matchDate = new Date(0);
729
730
 
@@ -737,8 +738,8 @@ describe('getSinceDateFromAPCs', () => {
737
738
  expect(sinceDate).toEqual(matchDate);
738
739
  });
739
740
 
740
- it('last apc', () => {
741
- const history = new Array(...plan1_history);
741
+ it('most recent apc -ascending order', () => {
742
+ const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
742
743
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
743
744
  const matchDate = new Date('2023-01-17T22:40:07.288Z');
744
745
 
@@ -752,8 +753,8 @@ describe('getSinceDateFromAPCs', () => {
752
753
  expect(sinceDate).toEqual(matchDate);
753
754
  });
754
755
 
755
- it('apc in the middle', () => {
756
- const history = new Array(...plan1_history);
756
+ it('apc in the middle -ascending order', () => {
757
+ const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
757
758
  const lastAPCId = 'GiT9CZXZGVljoYMR';
758
759
  const matchDate = new Date('2023-01-16T21:50:42.742Z');
759
760
 
@@ -767,10 +768,10 @@ describe('getSinceDateFromAPCs', () => {
767
768
  expect(sinceDate).toEqual(matchDate);
768
769
  });
769
770
 
770
- it('pastPublishCount greater than array size', () => {
771
- const history = new Array(...plan1_history);
771
+ it('pastPublishCount greater than array size -ascending order; so include all changes', () => {
772
+ const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
772
773
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
773
- const matchDate = new Date('2023-01-15T19:13:58.902Z');
774
+ const matchDate = new Date(0);
774
775
 
775
776
  const config = {} as FCConfig;
776
777
 
@@ -782,8 +783,100 @@ describe('getSinceDateFromAPCs', () => {
782
783
  expect(sinceDate).toEqual(matchDate);
783
784
  });
784
785
 
785
- it('pastPublishCount at 3 ', () => {
786
- const history = new Array(...plan1_history);
786
+ it('pastPublishCount at 3 -ascending order', () => {
787
+ const history = new Array(...plan1_history) as any as AssortmentPublishChange[];
788
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
789
+ const matchDate = new Date('2023-01-17T22:35:20.517Z');
790
+
791
+ const config = {} as FCConfig;
792
+
793
+ const mapFileUtil = new MapFileUtil(new Entities());
794
+ const dc = new DataConverter(config, mapFileUtil);
795
+ const ppa = new BaseProcessPublishAssortment(config, dc, mapFileUtil);
796
+
797
+ const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId, 3);
798
+ expect(sinceDate).toEqual(matchDate);
799
+ });
800
+ });
801
+
802
+ describe('getSinceDateFromAPCs - plan history in descending order', () => {
803
+ it('oldest / only apc', () => {
804
+ const history = new Array(...plan1_history_descending).slice(0, 1) as any as AssortmentPublishChange[];
805
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
806
+ const matchDate = new Date(0);
807
+
808
+ const config = {} as FCConfig;
809
+
810
+ const mapFileUtil = new MapFileUtil(new Entities());
811
+ const dc = new DataConverter(config, mapFileUtil);
812
+ const ppa = new BaseProcessPublishAssortment(config, dc, mapFileUtil);
813
+
814
+ const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
815
+ expect(sinceDate).toEqual(matchDate);
816
+ });
817
+
818
+ it('oldest / multiple apcs in history -descending order', () => {
819
+ const history = new Array(...plan1_history_descending).slice(0, 3) as any as AssortmentPublishChange[];
820
+ const lastAPCId = '4JM83QNiIO0IBkck';
821
+ const matchDate = new Date(0);
822
+
823
+ const config = {} as FCConfig;
824
+
825
+ const mapFileUtil = new MapFileUtil(new Entities());
826
+ const dc = new DataConverter(config, mapFileUtil);
827
+ const ppa = new BaseProcessPublishAssortment(config, dc, mapFileUtil);
828
+
829
+ const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
830
+ expect(sinceDate).toEqual(matchDate);
831
+ });
832
+
833
+ it('most recent apc -descending order', () => {
834
+ const history = new Array(...plan1_history_descending) as any as AssortmentPublishChange[];
835
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
836
+ const matchDate = new Date('2023-01-17T22:40:07.288Z');
837
+
838
+ const config = {} as FCConfig;
839
+
840
+ const mapFileUtil = new MapFileUtil(new Entities());
841
+ const dc = new DataConverter(config, mapFileUtil);
842
+ const ppa = new BaseProcessPublishAssortment(config, dc, mapFileUtil);
843
+
844
+ const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
845
+ expect(sinceDate).toEqual(matchDate);
846
+ });
847
+
848
+ it('apc in the middle -descending order', () => {
849
+ const history = new Array(...plan1_history_descending) as any as AssortmentPublishChange[];
850
+ const lastAPCId = 'GiT9CZXZGVljoYMR';
851
+ const matchDate = new Date('2023-01-16T21:50:42.742Z');
852
+
853
+ const config = {} as FCConfig;
854
+
855
+ const mapFileUtil = new MapFileUtil(new Entities());
856
+ const dc = new DataConverter(config, mapFileUtil);
857
+ const ppa = new BaseProcessPublishAssortment(config, dc, mapFileUtil);
858
+
859
+ const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId);
860
+ expect(sinceDate).toEqual(matchDate);
861
+ });
862
+
863
+ it('pastPublishCount greater than array size -descending order; so include all changes', () => {
864
+ const history = new Array(...plan1_history_descending) as any as AssortmentPublishChange[];
865
+ const lastAPCId = 'sJbGx1Fpq1v2MmcI';
866
+ const matchDate = new Date(0);
867
+
868
+ const config = {} as FCConfig;
869
+
870
+ const mapFileUtil = new MapFileUtil(new Entities());
871
+ const dc = new DataConverter(config, mapFileUtil);
872
+ const ppa = new BaseProcessPublishAssortment(config, dc, mapFileUtil);
873
+
874
+ const sinceDate = ppa.getSinceDateFromAPCs(history, lastAPCId, 20);
875
+ expect(sinceDate).toEqual(matchDate);
876
+ });
877
+
878
+ it('pastPublishCount at 3 -descending order', () => {
879
+ const history = new Array(...plan1_history_descending) as any as AssortmentPublishChange[];
787
880
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
788
881
  const matchDate = new Date('2023-01-17T22:35:20.517Z');
789
882
 
@@ -1048,9 +1141,10 @@ describe('buildDeleteChanges', () =>{
1048
1141
  ];
1049
1142
  const apc ={};
1050
1143
  const fullAPC = {
1144
+ id: 'apcId',
1051
1145
  deleteDataDownloadLink: 'deleteDataDownloadLink',
1052
1146
  returnedDeleteData
1053
- };
1147
+ } as AssortmentPublishChange;
1054
1148
  const previousApc = {};
1055
1149
  const ppa = new BaseProcessPublishAssortment(config, dc, mapFileUtil);
1056
1150
  const spy = jest.spyOn(ppa, 'downloadDeleteChanges')
@@ -1077,6 +1171,7 @@ describe('buildDeleteChanges', () =>{
1077
1171
  ];
1078
1172
  const apc ={};
1079
1173
  const fullAPC = {
1174
+ id: 'apcId',
1080
1175
  returnedDeleteData
1081
1176
  };
1082
1177
  const previousApc = undefined;
@@ -1110,13 +1205,14 @@ describe('buildDeleteChanges', () =>{
1110
1205
  deletes: [{id:'1'}, {id:'3'}]
1111
1206
  }
1112
1207
 
1208
+ } as AssortmentPublishChange;
1209
+ const previousApc: AssortmentPublishChange = {
1210
+ id: 'previousApcId',
1113
1211
  };
1114
- const previousApc = {
1115
- };
1116
- const fullPreviousApc = {
1212
+ const fullPreviousApc: AssortmentPublishChange = {
1117
1213
  id: previousApcId,
1118
1214
  assortmentBaselineDownloadLink: 'assortmentBaselineDownloadLink'
1119
- };
1215
+ } ;
1120
1216
  const previousApcBaseline = {
1121
1217
  assortmentItems: [
1122
1218
  { itemId: '1' },
@@ -1170,7 +1266,7 @@ describe('buildDeleteChanges', () =>{
1170
1266
  deletes: [{id:'1'}, {id:'3'}]
1171
1267
  }
1172
1268
 
1173
- };
1269
+ } as AssortmentPublishChange;
1174
1270
  const previousApc = {
1175
1271
  assortmentBaselineDownloadLink: 'assortmentBaselineDownloadLink'
1176
1272
  };
@@ -1,4 +1,4 @@
1
- import { Entities, Files, Request } from '@contrail/sdk';
1
+ import { API_VERSION, Entities, Files, Request } from '@contrail/sdk';
2
2
  import { AsyncEventsPayloadType, FCConfig, ProductFederation, SeasonalPayload, SeasonFederation, SkuFederation } from '../interfaces/interfaces';
3
3
  import { DataConverter } from '../util/data-converter';
4
4
  import { FlexPLMConnect } from '../util/flexplm-connect';
@@ -12,6 +12,7 @@ import path = require('path');
12
12
  import { MapFileUtil } from '@contrail/transform-data';
13
13
  import { Logger } from '@contrail/app-framework';
14
14
  import { EventShortMessageStatus } from '../util/event-short-message-status';
15
+ import { AssortmentPublishChange } from '@contrail/entity-types';
15
16
 
16
17
  export class BaseProcessPublishAssortment {
17
18
 
@@ -40,7 +41,7 @@ export class BaseProcessPublishAssortment {
40
41
  public async process(event) {
41
42
 
42
43
  const assortmentPublishChangeId = event.assortmentPublishChangeId;
43
- let apcHistory;
44
+ let apcHistory: AssortmentPublishChange[];
44
45
  let publisher;
45
46
  const assortmentId = event.assortmentId;
46
47
  try {
@@ -210,7 +211,7 @@ export class BaseProcessPublishAssortment {
210
211
  return this.assortment;
211
212
  }
212
213
 
213
- public async getSinceDate(assortmentId: any, assortmentPublishChangeId: any, apcHistory: object[]): Promise<Date> {
214
+ public async getSinceDate(assortmentId: any, assortmentPublishChangeId: any, apcHistory: AssortmentPublishChange[]): Promise<Date> {
214
215
 
215
216
  let sinceDate = null;
216
217
 
@@ -249,15 +250,34 @@ export class BaseProcessPublishAssortment {
249
250
  return sinceDate;
250
251
  }
251
252
 
252
- async getApcHistory(assortmentId: any) {
253
- const resource = `/assortments/${assortmentId}/history/`;
254
- return Request.request(resource, {
255
- method: 'GET',
256
- headers: {
257
- Accept: 'application/json',
258
- 'Content-Type': 'application/json'
253
+ async getApcHistory(assortmentId: string): Promise<AssortmentPublishChange[]> {
254
+ const apcs = [];
255
+ const MAX_PAGES = 1_000;
256
+ let nextPageKey = null;
257
+ const options = {
258
+ entityName: 'assortment',
259
+ id: assortmentId,
260
+ apiVersion: API_VERSION.V2,
261
+ nextPageKey,
262
+ relation: 'history',
263
+ };
264
+
265
+ let i = 0;
266
+ do {
267
+ const response = await new Entities().get(options);
268
+ if(response?.results){
269
+ apcs.push(...response.results);
259
270
  }
260
- });
271
+ nextPageKey = response?.nextPageKey;
272
+ options.nextPageKey = nextPageKey;
273
+ i++;
274
+ } while(nextPageKey && i < MAX_PAGES);
275
+
276
+ if(i === MAX_PAGES && nextPageKey){
277
+ throw new Error('Max pages reached getting APC history for assortmentId: ' + assortmentId);
278
+ }
279
+
280
+ return apcs;
261
281
  }
262
282
 
263
283
  protected updatedSinceDate(entity, sinceDate: Date): boolean {
@@ -265,7 +285,7 @@ export class BaseProcessPublishAssortment {
265
285
  return (updatedOn && new Date(updatedOn) > sinceDate);
266
286
  }
267
287
 
268
- getSinceDateFromAPCSpecificDate(apcHistory: any[], assortmentPublishChangeId: string, specificDate: Date):Date {
288
+ getSinceDateFromAPCSpecificDate(apcHistory: AssortmentPublishChange[], assortmentPublishChangeId: string, specificDate: Date):Date {
269
289
  const apc = apcHistory.find(apc => apc?.id === assortmentPublishChangeId);
270
290
  const apcDate = new Date(apc?.createdOn);
271
291
  let afterDate = apcDate;
@@ -286,7 +306,7 @@ export class BaseProcessPublishAssortment {
286
306
  const selectedDate = (beforeDate.getTime() !== 0)?beforeDate : afterDate;
287
307
  return selectedDate;
288
308
  }
289
- getSinceDateDaysPrevious(apcHistory: any[], assortmentPublishChangeId: string, daysBack):Date {
309
+ getSinceDateDaysPrevious(apcHistory: AssortmentPublishChange[], assortmentPublishChangeId: string, daysBack):Date {
290
310
  const apc = apcHistory.find(apc => apc?.id === assortmentPublishChangeId);
291
311
  const apcDate = new Date(apc?.createdOn);
292
312
  let afterDate = apcDate;
@@ -315,18 +335,14 @@ export class BaseProcessPublishAssortment {
315
335
  return selectedDate;
316
336
  }
317
337
 
318
- getSinceDateFromAPCs(apcHistory: any[], assortmentPublishChangeId: string, pastPublishCount = 1): Date {
338
+ getSinceDateFromAPCs(apcHistory: AssortmentPublishChange[], assortmentPublishChangeId: string, pastPublishCount = 1): Date {
319
339
  if(apcHistory.length === 1){
320
340
  return new Date(0);
321
341
  }
322
- const apcIndex = apcHistory.findIndex(apc => apc.id === assortmentPublishChangeId);
323
- if(apcIndex === 0){
324
- return new Date(0);
325
- }
326
- const apc = apcHistory[apcIndex];
342
+
343
+ const apc = apcHistory.find(apc => apc.id === assortmentPublishChangeId);
327
344
  const apcDate = new Date(apc?.createdOn);
328
- let sinceDate = new Date(0);
329
- const dateArray = [];
345
+ const dateArray: Date[] = [];
330
346
  for (const tempapc of apcHistory) {
331
347
  if (assortmentPublishChangeId !== tempapc?.id) {
332
348
  const tempDate = new Date(tempapc?.createdOn);
@@ -335,12 +351,15 @@ export class BaseProcessPublishAssortment {
335
351
  }
336
352
  }
337
353
  }
338
- dateArray.sort((a,b) => { return Date.parse(a) - Date.parse(b);});
339
- const arrIndex = (dateArray.length - pastPublishCount > 0)? dateArray.length - pastPublishCount: 0;
340
- sinceDate = dateArray[arrIndex];
341
- return sinceDate;
354
+ if(dateArray.length === 0 || pastPublishCount > dateArray.length){
355
+ return new Date(0);
356
+ }
357
+ dateArray.sort((a,b) => { return a.getTime() - b.getTime();});
358
+ const arrIndex = dateArray.length - pastPublishCount;
359
+ return dateArray[arrIndex];
342
360
  }
343
- protected getPublisher(assortmentPublishChange) {
361
+
362
+ protected getPublisher(assortmentPublishChange: AssortmentPublishChange) {
344
363
  const createdBy = assortmentPublishChange?.createdBy;
345
364
  const publisher = {};
346
365
  const includeKeys = ['email', 'firstName', 'isSsoUser', 'lastName'];
@@ -354,7 +373,7 @@ export class BaseProcessPublishAssortment {
354
373
 
355
374
  }
356
375
 
357
- async downloadAssortmentPublishChange(assortmentId: string, assortmentPublishChangeId: string) {
376
+ async downloadAssortmentPublishChange(assortmentId: string, assortmentPublishChangeId: string): Promise<AssortmentPublishChange> {
358
377
  const resourceString = '/assortments/' + assortmentId + '/history/' + assortmentPublishChangeId + '?relations=createdBy';
359
378
  return await Request.request(
360
379
  resourceString,
@@ -368,7 +387,7 @@ export class BaseProcessPublishAssortment {
368
387
  );
369
388
  }
370
389
 
371
- async downloadHydratedChangeDetail(assortmentPublishChange) {
390
+ async downloadHydratedChangeDetail(assortmentPublishChange: AssortmentPublishChange) {
372
391
  try {
373
392
  console.info('downloadHydratedChangeDetail-start');
374
393
  const link = assortmentPublishChange?.hydratedDetailDownloadLink;
@@ -382,7 +401,7 @@ export class BaseProcessPublishAssortment {
382
401
  return undefined;
383
402
  }
384
403
 
385
- async downloadAssortmentBaseline(assortmentPublishChange) {
404
+ async downloadAssortmentBaseline(assortmentPublishChange: AssortmentPublishChange) {
386
405
  console.info('downloadAssortmentBaseline-start');
387
406
  try {
388
407
  const link = assortmentPublishChange?.assortmentBaselineDownloadLink;