@contrail/flexplm 1.1.33 → 1.1.35

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.
@@ -148,50 +148,46 @@ class BaseProcessPublishAssortment {
148
148
  getSinceDateFromAPCSpecificDate(apcHistory, assortmentPublishChangeId, specificDate) {
149
149
  const apc = apcHistory.find(apc => apc['id'] === assortmentPublishChangeId);
150
150
  const apcDate = new Date(apc['createdOn']);
151
- const dateArray = [];
151
+ let afterDate = apcDate;
152
+ let beforeDate = new Date(0);
153
+ const sinceDate = specificDate;
152
154
  for (const tempapc of apcHistory) {
153
155
  if (assortmentPublishChangeId !== tempapc['id']) {
154
156
  const tempDate = new Date(tempapc['createdOn']);
155
157
  if (tempDate < apcDate) {
156
- dateArray.push(tempDate);
158
+ if (tempDate > sinceDate && tempDate < afterDate) {
159
+ afterDate = tempDate;
160
+ }
161
+ else if (tempDate < sinceDate && tempDate > beforeDate) {
162
+ beforeDate = tempDate;
163
+ }
157
164
  }
158
165
  }
159
166
  }
160
- dateArray.sort((a, b) => { return Date.parse(a) - Date.parse(b); });
161
- let sinceDate = specificDate;
162
- const sinceDateMilliseconds = sinceDate.getTime();
163
- for (const d of dateArray) {
164
- const milli = Date.parse(d);
165
- if (milli >= sinceDateMilliseconds) {
166
- sinceDate = d;
167
- break;
168
- }
169
- }
170
- return sinceDate;
167
+ const selectedDate = (beforeDate.getTime() !== 0) ? beforeDate : afterDate;
168
+ return selectedDate;
171
169
  }
172
170
  getSinceDateDaysPrevious(apcHistory, assortmentPublishChangeId, daysBack) {
173
171
  const apc = apcHistory.find(apc => apc['id'] === assortmentPublishChangeId);
174
172
  const apcDate = new Date(apc['createdOn']);
175
- const dateArray = [];
173
+ let afterDate = apcDate;
174
+ let beforeDate = new Date(0);
175
+ const sinceDate = new Date(apcDate.getUTCFullYear(), apcDate.getUTCMonth(), apcDate.getUTCDate() - daysBack, 0, (0 - apcDate.getTimezoneOffset()), 0);
176
176
  for (const tempapc of apcHistory) {
177
177
  if (assortmentPublishChangeId !== tempapc['id']) {
178
178
  const tempDate = new Date(tempapc['createdOn']);
179
179
  if (tempDate < apcDate) {
180
- dateArray.push(tempDate);
180
+ if (tempDate > sinceDate && tempDate < afterDate) {
181
+ afterDate = tempDate;
182
+ }
183
+ else if (tempDate < sinceDate && tempDate > beforeDate) {
184
+ beforeDate = tempDate;
185
+ }
181
186
  }
182
187
  }
183
188
  }
184
- dateArray.sort((a, b) => { return Date.parse(a) - Date.parse(b); });
185
- let sinceDate = new Date(apcDate.getUTCFullYear(), apcDate.getUTCMonth(), apcDate.getUTCDate() - daysBack, 0, (0 - apcDate.getTimezoneOffset()), 0);
186
- const sinceDateMilliseconds = sinceDate.getTime();
187
- for (const d of dateArray) {
188
- const milli = Date.parse(d);
189
- if (milli >= sinceDateMilliseconds) {
190
- sinceDate = d;
191
- break;
192
- }
193
- }
194
- return sinceDate;
189
+ const selectedDate = (beforeDate.getTime() !== 0) ? beforeDate : afterDate;
190
+ return selectedDate;
195
191
  }
196
192
  getSinceDateFromAPCs(apcHistory, assortmentPublishChangeId, pastPublishCount = 1) {
197
193
  if (apcHistory.length === 1) {
@@ -96,7 +96,7 @@ describe('Test getSinceDate', () => {
96
96
  it('getSinceDate date from config as year', async () => {
97
97
  const history = new Array(...mockData_1.plan1_history);
98
98
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
99
- const matchDate = new Date('2023-01-17T22:35:20.517Z');
99
+ const matchDate = new Date('2023-01-16T21:50:42.742Z');
100
100
  const config = { sinceDate: '2023-01-17' };
101
101
  const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
102
102
  const dc = new data_converter_1.DataConverter(config, mapFileUtil);
@@ -120,7 +120,7 @@ describe('Test getSinceDate', () => {
120
120
  expect(sinceDate).toEqual(matchDate);
121
121
  });
122
122
  it('getSinceDate date from config numberofdays-cross DST', async () => {
123
- const count = 12;
123
+ const count = 11;
124
124
  const history = new Array(...mockData_1.plan1_across_month_DST);
125
125
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
126
126
  const matchDate = new Date('2023-03-06T21:50:42.742Z');
@@ -163,7 +163,7 @@ describe('getSinceDateFromAPCSpecificDate', () => {
163
163
  it('last apc - one day', () => {
164
164
  const history = new Array(...mockData_1.plan1_history);
165
165
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
166
- const matchDate = new Date('2023-01-17T22:35:20.517Z');
166
+ const matchDate = new Date('2023-01-16T21:50:42.742Z');
167
167
  const config = {};
168
168
  const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
169
169
  const dc = new data_converter_1.DataConverter(config, mapFileUtil);
@@ -174,7 +174,7 @@ describe('getSinceDateFromAPCSpecificDate', () => {
174
174
  it('apc in the middle - one day', () => {
175
175
  const history = new Array(...mockData_1.plan1_history);
176
176
  const lastAPCId = 'GiT9CZXZGVljoYMR';
177
- const matchDate = new Date('2023-01-16T19:16:06.233Z');
177
+ const matchDate = new Date('2023-01-15T19:13:58.902Z');
178
178
  const config = {};
179
179
  const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
180
180
  const dc = new data_converter_1.DataConverter(config, mapFileUtil);
@@ -196,7 +196,7 @@ describe('getSinceDateFromAPCSpecificDate', () => {
196
196
  it('numberofdays at 2 ', () => {
197
197
  const history = new Array(...mockData_1.plan1_history);
198
198
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
199
- const matchDate = new Date('2023-01-16T19:16:06.233Z');
199
+ const matchDate = new Date('2023-01-15T19:13:58.902Z');
200
200
  const config = {};
201
201
  const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
202
202
  const dc = new data_converter_1.DataConverter(config, mapFileUtil);
@@ -209,7 +209,7 @@ describe('getSinceDateDaysPrevious', () => {
209
209
  it('last apc - one day', () => {
210
210
  const history = new Array(...mockData_1.plan1_history);
211
211
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
212
- const matchDate = new Date('2023-01-17T22:35:20.517Z');
212
+ const matchDate = new Date('2023-01-16T21:50:42.742Z');
213
213
  const config = {};
214
214
  const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
215
215
  const dc = new data_converter_1.DataConverter(config, mapFileUtil);
@@ -220,7 +220,7 @@ describe('getSinceDateDaysPrevious', () => {
220
220
  it('apc in the middle - one day', () => {
221
221
  const history = new Array(...mockData_1.plan1_history);
222
222
  const lastAPCId = 'GiT9CZXZGVljoYMR';
223
- const matchDate = new Date('2023-01-16T19:16:06.233Z');
223
+ const matchDate = new Date('2023-01-15T19:13:58.902Z');
224
224
  const config = {};
225
225
  const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
226
226
  const dc = new data_converter_1.DataConverter(config, mapFileUtil);
@@ -242,7 +242,7 @@ describe('getSinceDateDaysPrevious', () => {
242
242
  it('numberofdays at 2 ', () => {
243
243
  const history = new Array(...mockData_1.plan1_history);
244
244
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
245
- const matchDate = new Date('2023-01-16T19:16:06.233Z');
245
+ const matchDate = new Date('2023-01-15T19:13:58.902Z');
246
246
  const config = {};
247
247
  const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
248
248
  const dc = new data_converter_1.DataConverter(config, mapFileUtil);
@@ -8,22 +8,67 @@ export declare const thumbnail_content_entity: {
8
8
  fileName: string;
9
9
  primaryFileId: string;
10
10
  primaryFileUrl: string;
11
+ primaryFile: {
12
+ fileName: string;
13
+ id: string;
14
+ size: number;
15
+ };
11
16
  tinyViewableId: string;
12
17
  tinyViewableUrl: string;
18
+ tinyViewable: {
19
+ fileName: string;
20
+ id: string;
21
+ size: number;
22
+ };
13
23
  smallViewableId: string;
14
24
  smallViewableUrl: string;
25
+ smallViewable: {
26
+ fileName: string;
27
+ id: string;
28
+ size: number;
29
+ };
15
30
  mediumViewableId: string;
16
31
  mediumViewableUrl: string;
32
+ mediumViewable: {
33
+ fileName: string;
34
+ id: string;
35
+ size: number;
36
+ };
17
37
  largeViewableId: string;
18
38
  largeViewableUrl: string;
39
+ largeViewable: {
40
+ fileName: string;
41
+ id: string;
42
+ size: number;
43
+ };
19
44
  CS_300Id: string;
20
45
  CS_300Url: string;
46
+ CS_300: {
47
+ fileName: string;
48
+ id: string;
49
+ size: number;
50
+ };
21
51
  CS_500Id: string;
22
52
  CS_500Url: string;
53
+ CS_500: {
54
+ fileName: string;
55
+ id: string;
56
+ size: number;
57
+ };
23
58
  CS_800Id: string;
24
59
  CS_800Url: string;
60
+ CS_800: {
61
+ fileName: string;
62
+ id: string;
63
+ size: number;
64
+ };
25
65
  CS_1000Id: string;
26
66
  CS_1000Url: string;
67
+ CS_1000: {
68
+ fileName: string;
69
+ id: string;
70
+ size: number;
71
+ };
27
72
  createdOn: string;
28
73
  orgId: string;
29
74
  id: string;
@@ -32,8 +77,3 @@ export declare const thumbnail_content_entity: {
32
77
  updatedById: string;
33
78
  fileSize: number;
34
79
  };
35
- export declare const cuRficeyoStwTF_f_fileEntities: {
36
- fileName: string;
37
- id: string;
38
- size: number;
39
- }[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cuRficeyoStwTF_f_fileEntities = exports.thumbnail_content_entity = exports.four_custom_sizes = exports.empty_custom_sizes = void 0;
3
+ exports.thumbnail_content_entity = exports.four_custom_sizes = exports.empty_custom_sizes = void 0;
4
4
  exports.empty_custom_sizes = [];
5
5
  exports.four_custom_sizes = [
6
6
  {
@@ -28,73 +28,72 @@ exports.thumbnail_content_entity = {
28
28
  fileName: 'JACKET 300_SOLDIER OLIVE.png',
29
29
  primaryFileId: 'yn2d5oHD4rXHRzyB',
30
30
  primaryFileUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Ff646d3cd-e23a-4689-bd16-0301d2036720.png',
31
- tinyViewableId: '6HWzJrQ-Jx1iefmj',
32
- tinyViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fb68f8652-f33f-452f-ae34-25397b4521eb.png',
33
- smallViewableId: 'D3WRW4iRmjLzp5VX',
34
- smallViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F541c53f8-fd85-418e-ae28-ad7410658b90.png',
35
- mediumViewableId: 'AsRvJenpeqxksUNW',
36
- mediumViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fe803c2d3-3e1b-4d9c-9bb9-2c488f1f295b.png',
37
- largeViewableId: 'vo4N4mCd-tFrw101',
38
- largeViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fb1b7a55c-b8ba-4857-be4e-e1c3f11d8e9a.png',
39
- CS_300Id: '6A5AG33nVu3Z6ogO',
40
- CS_300Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F3f2ea306-a77f-4cc3-a49a-75fb5d8b113c.png',
41
- CS_500Id: 'rBaHc1J2xdOWdbhI',
42
- CS_500Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F979c8c65-b63f-4220-aa2e-11520f2f68bf.png',
43
- CS_800Id: 'ZPAeYI3JiqjQ7unY',
44
- CS_800Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fc58eeffa-2592-4698-a058-19281cda447c.png',
45
- CS_1000Id: 'Hg_CthwsD4ozopCb',
46
- CS_1000Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F2c827c7b-361b-4e05-b77d-4280294f9d9c.png',
47
- createdOn: '2023-07-05T15:02:13.950Z',
48
- orgId: '5LZnKVTNxvwMqufy',
49
- id: 'cuRficeyoStwTF-f',
50
- contentType: 'image/png',
51
- createdById: 'SWIFPZeZzkBvrSLD',
52
- updatedById: 'SWIFPZeZzkBvrSLD',
53
- fileSize: 1757973
54
- };
55
- exports.cuRficeyoStwTF_f_fileEntities = [
56
- {
31
+ primaryFile: {
57
32
  fileName: 'JACKET 300_SOLDIER OLIVE.png',
58
33
  id: 'yn2d5oHD4rXHRzyB',
59
34
  size: 1757973
60
35
  },
61
- {
36
+ tinyViewableId: '6HWzJrQ-Jx1iefmj',
37
+ tinyViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fb68f8652-f33f-452f-ae34-25397b4521eb.png',
38
+ tinyViewable: {
62
39
  fileName: 'JACKET 300_SOLDIER OLIVE_tiny.png',
63
40
  id: '6HWzJrQ-Jx1iefmj',
64
41
  size: 1784
65
42
  },
66
- {
43
+ smallViewableId: 'D3WRW4iRmjLzp5VX',
44
+ smallViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F541c53f8-fd85-418e-ae28-ad7410658b90.png',
45
+ smallViewable: {
67
46
  fileName: 'JACKET 300_SOLDIER OLIVE_small.png',
68
47
  id: 'D3WRW4iRmjLzp5VX',
69
48
  size: 8699
70
49
  },
71
- {
50
+ mediumViewableId: 'AsRvJenpeqxksUNW',
51
+ mediumViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fe803c2d3-3e1b-4d9c-9bb9-2c488f1f295b.png',
52
+ mediumViewable: {
72
53
  fileName: 'JACKET 300_SOLDIER OLIVE_medium.png',
73
54
  id: 'AsRvJenpeqxksUNW',
74
55
  size: 77558
75
56
  },
76
- {
57
+ largeViewableId: 'vo4N4mCd-tFrw101',
58
+ largeViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fb1b7a55c-b8ba-4857-be4e-e1c3f11d8e9a.png',
59
+ largeViewable: {
77
60
  fileName: 'JACKET 300_SOLDIER OLIVE_large.png',
78
61
  id: 'vo4N4mCd-tFrw101',
79
62
  size: 1781538
80
63
  },
81
- {
64
+ CS_300Id: '6A5AG33nVu3Z6ogO',
65
+ CS_300Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F3f2ea306-a77f-4cc3-a49a-75fb5d8b113c.png',
66
+ CS_300: {
82
67
  fileName: 'JACKET 300_SOLDIER OLIVE_CS_300.png',
83
68
  id: '6A5AG33nVu3Z6ogO',
84
69
  size: 141153
85
70
  },
86
- {
71
+ CS_500Id: 'rBaHc1J2xdOWdbhI',
72
+ CS_500Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F979c8c65-b63f-4220-aa2e-11520f2f68bf.png',
73
+ CS_500: {
87
74
  fileName: 'JACKET 300_SOLDIER OLIVE_CS_500.png',
88
75
  id: 'rBaHc1J2xdOWdbhI',
89
76
  size: 382057
90
77
  },
91
- {
78
+ CS_800Id: 'ZPAeYI3JiqjQ7unY',
79
+ CS_800Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fc58eeffa-2592-4698-a058-19281cda447c.png',
80
+ CS_800: {
92
81
  fileName: 'JACKET 300_SOLDIER OLIVE_CS_800.png',
93
82
  id: 'ZPAeYI3JiqjQ7unY',
94
83
  size: 1008702
95
- }, {
84
+ },
85
+ CS_1000Id: 'Hg_CthwsD4ozopCb',
86
+ CS_1000Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F2c827c7b-361b-4e05-b77d-4280294f9d9c.png',
87
+ CS_1000: {
96
88
  fileName: 'JACKET 300_SOLDIER OLIVE_CS_1000.png',
97
89
  id: 'Hg_CthwsD4ozopCb',
98
90
  size: 1605889
99
- }
100
- ];
91
+ },
92
+ createdOn: '2023-07-05T15:02:13.950Z',
93
+ orgId: '5LZnKVTNxvwMqufy',
94
+ id: 'cuRficeyoStwTF-f',
95
+ contentType: 'image/png',
96
+ createdById: 'SWIFPZeZzkBvrSLD',
97
+ updatedById: 'SWIFPZeZzkBvrSLD',
98
+ fileSize: 1757973
99
+ };
@@ -6,10 +6,14 @@ export declare class ThumbnailUtil {
6
6
  static NEW_THUMBNAIL_ID: string;
7
7
  static EXISTING_THUMBNAIL_ID: string;
8
8
  static REMOVE_THUMBNAIL: string;
9
+ static OOB_SIZES: {
10
+ slug: string;
11
+ }[];
9
12
  constructor(config: FCConfig);
10
13
  setOutboundThumbnail(data: any, event: any): Promise<any>;
14
+ isThumbnailNew(event: any, customSizes: any[]): boolean;
11
15
  getFileId(primaryViewableId: string): Promise<string>;
12
16
  getCustomSizes(): Promise<any[]>;
13
- getContentEntity(primaryViewableId: any): Promise<any>;
14
- getFileEntities(fileEntityIds: any[]): Promise<any>;
17
+ getContentEntity(primaryViewableId: any, sizes: any[]): Promise<any>;
18
+ logContentResults(content: any, relations: string[]): void;
15
19
  }
@@ -17,7 +17,8 @@ class ThumbnailUtil {
17
17
  const primaryViewableId = event.newData.primaryViewableId;
18
18
  const fileId = await this.getFileId(primaryViewableId);
19
19
  if (fileId) {
20
- const key = (event?.propertyDiffs?.largeViewableDownloadUrl)
20
+ const customSizes = await this.getCustomSizes();
21
+ const key = (this.isThumbnailNew(event, customSizes))
21
22
  ? ThumbnailUtil.NEW_THUMBNAIL_ID
22
23
  : ThumbnailUtil.EXISTING_THUMBNAIL_ID;
23
24
  data[key] = fileId;
@@ -28,42 +29,44 @@ class ThumbnailUtil {
28
29
  }
29
30
  return data;
30
31
  }
32
+ isThumbnailNew(event, customSizes) {
33
+ const propertyDiffs = event?.propertyDiffs;
34
+ if (propertyDiffs) {
35
+ const diffKeys = Object.keys(propertyDiffs);
36
+ const sizeKeys = ThumbnailUtil.OOB_SIZES.map(s => s.slug + 'DownloadUrl');
37
+ if (customSizes) {
38
+ sizeKeys.push(...customSizes.map(s => s.slug + 'Url'));
39
+ }
40
+ sizeKeys.push('primaryFileUrl');
41
+ console.info('diffKeys: ' + JSON.stringify(diffKeys));
42
+ console.info('sizeKeys: ' + JSON.stringify(sizeKeys));
43
+ return diffKeys.some(s => sizeKeys.includes(s));
44
+ }
45
+ return false;
46
+ }
31
47
  async getFileId(primaryViewableId) {
32
- console.info('getFileId()-' + primaryViewableId);
48
+ console.info('ThumbnailUtil.getFileId()-' + primaryViewableId);
33
49
  const sizes = await this.getCustomSizes();
34
- const OOBSizes = [{ slug: 'largeViewable' }, { slug: 'mediumViewable' }, { slug: 'smallViewable' }, { slug: 'tinyViewable' }];
50
+ const OOBSizes = JSON.parse(JSON.stringify(ThumbnailUtil.OOB_SIZES));
35
51
  sizes.push(...OOBSizes);
36
52
  console.info('sizes: ' + JSON.stringify(sizes));
37
- const content = await this.getContentEntity(primaryViewableId);
38
- if (app_framework_1.Logger.isDebugOn()) {
39
- console.debug('content: ' + JSON.stringify(content));
40
- }
53
+ const content = await this.getContentEntity(primaryViewableId, sizes);
41
54
  if (!content) {
42
55
  return undefined;
43
56
  }
44
57
  const contentKeys = Object.getOwnPropertyNames(content);
45
- const fileEntityIds = [];
46
- for (const size of sizes) {
47
- const key = size.slug + 'Id';
48
- if (contentKeys.includes(key) && !fileEntityIds.includes(content[key])) {
49
- fileEntityIds.push(content[key]);
50
- size['fileId'] = content[key];
51
- }
52
- }
53
- const fileResults = await this.getFileEntities(fileEntityIds);
54
- if (app_framework_1.Logger.isDebugOn()) {
55
- console.debug('fileResults: ' + JSON.stringify(fileResults));
56
- }
58
+ const isDebugOn = app_framework_1.Logger.isDebugOn();
57
59
  let fileId = undefined;
58
60
  let tempFileSize = 0;
59
- const isDebugOn = app_framework_1.Logger.isDebugOn();
60
- for (const sizeObj of sizes) {
61
- if (isDebugOn) {
62
- console.debug('size: ' + JSON.stringify(sizeObj));
63
- }
64
- if (sizeObj['fileId']) {
65
- const file = fileResults.find(f => f['id'] === sizeObj['fileId']);
66
- if (file['size'] > tempFileSize && file['size'] < this.max_thumbnail_size) {
61
+ for (const size of sizes) {
62
+ const slug = size?.slug;
63
+ if (contentKeys.includes(slug)) {
64
+ const file = content[slug];
65
+ if (isDebugOn) {
66
+ console.debug('size: ' + slug);
67
+ console.debug('fileId: ' + file['id']);
68
+ }
69
+ if (file && file['size'] > tempFileSize && file['size'] < this.max_thumbnail_size) {
67
70
  tempFileSize = file['size'];
68
71
  fileId = file['id'];
69
72
  if (isDebugOn) {
@@ -72,7 +75,7 @@ class ThumbnailUtil {
72
75
  }
73
76
  }
74
77
  }
75
- console.info('getFileId(): returning-' + fileId);
78
+ console.info('ThumbnailUtil.getFileId(): returning-' + fileId);
76
79
  return fileId;
77
80
  }
78
81
  async getCustomSizes() {
@@ -83,30 +86,33 @@ class ThumbnailUtil {
83
86
  sizes.push(...customSizes);
84
87
  return sizes;
85
88
  }
86
- async getContentEntity(primaryViewableId) {
89
+ async getContentEntity(primaryViewableId, sizes) {
87
90
  const criteria = {
88
91
  id: primaryViewableId
89
92
  };
93
+ const relations = sizes.map(s => s.slug);
94
+ relations.push('primaryFile');
90
95
  const contentResults = await this.entities.get({
91
96
  entityName: 'content',
92
- criteria
97
+ criteria,
98
+ relations
93
99
  });
94
- console.info('contentResults: ' + JSON.stringify(contentResults));
95
100
  const content = (contentResults && contentResults[0]) ? contentResults[0] : undefined;
101
+ this.logContentResults(content, relations);
96
102
  return content;
97
103
  }
98
- async getFileEntities(fileEntityIds) {
99
- const criteria = {
100
- ids: fileEntityIds
101
- };
102
- const fileResults = await this.entities.get({
103
- entityName: 'file',
104
- criteria
105
- });
106
- return fileResults;
104
+ logContentResults(content, relations) {
105
+ if (app_framework_1.Logger.isDebugOn()) {
106
+ const contentCopy = JSON.parse(JSON.stringify(content));
107
+ relations.forEach(r => {
108
+ delete contentCopy[r];
109
+ });
110
+ console.debug('content: ' + JSON.stringify(contentCopy));
111
+ }
107
112
  }
108
113
  }
109
114
  exports.ThumbnailUtil = ThumbnailUtil;
110
115
  ThumbnailUtil.NEW_THUMBNAIL_ID = 'NEW_THUMBNAIL_ID';
111
116
  ThumbnailUtil.EXISTING_THUMBNAIL_ID = 'EXISTING_THUMBNAIL_ID';
112
117
  ThumbnailUtil.REMOVE_THUMBNAIL = 'REMOVE_THUMBNAIL';
118
+ ThumbnailUtil.OOB_SIZES = [{ slug: 'largeViewable' }, { slug: 'mediumLargeViewable' }, { slug: 'mediumViewable' }, { slug: 'smallViewable' }, { slug: 'tinyViewable' }];
@@ -50,6 +50,8 @@ describe('ThumbnailUtil Tests', () => {
50
50
  }
51
51
  }
52
52
  };
53
+ const spyCustomSizes = jest.spyOn(tu, 'getCustomSizes');
54
+ spyCustomSizes.mockReturnValue(Promise.resolve(mockData_1.empty_custom_sizes));
53
55
  const spyGetFileId = jest.spyOn(tu, 'getFileId');
54
56
  spyGetFileId.mockReturnValue(Promise.resolve(thumbnailId));
55
57
  const results = await tu.setOutboundThumbnail(data, event);
@@ -70,6 +72,8 @@ describe('ThumbnailUtil Tests', () => {
70
72
  },
71
73
  propertyDiffs: {}
72
74
  };
75
+ const spyCustomSizes = jest.spyOn(tu, 'getCustomSizes');
76
+ spyCustomSizes.mockReturnValue(Promise.resolve(mockData_1.empty_custom_sizes));
73
77
  const spyGetFileId = jest.spyOn(tu, 'getFileId');
74
78
  spyGetFileId.mockReturnValue(Promise.resolve(thumbnailId));
75
79
  const results = await tu.setOutboundThumbnail(data, event);
@@ -90,10 +94,8 @@ describe('ThumbnailUtil Tests', () => {
90
94
  const spyCustomSizes = jest.spyOn(tu, 'getCustomSizes');
91
95
  spyCustomSizes.mockReturnValue(Promise.resolve(mockData_1.empty_custom_sizes));
92
96
  const spyContentEntity = jest.spyOn(tu, 'getContentEntity');
93
- const content = mockData_1.thumbnail_content_entity;
97
+ const content = JSON.parse(JSON.stringify(mockData_1.thumbnail_content_entity));
94
98
  spyContentEntity.mockReturnValue(Promise.resolve(content));
95
- const spyGetFileEntities = jest.spyOn(tu, 'getFileEntities');
96
- spyGetFileEntities.mockReturnValue(Promise.resolve(mockData_1.cuRficeyoStwTF_f_fileEntities));
97
99
  const results = await tu.getFileId(primaryFileId);
98
100
  expect(results).toEqual('vo4N4mCd-tFrw101');
99
101
  });
@@ -107,13 +109,10 @@ describe('ThumbnailUtil Tests', () => {
107
109
  const spyContentEntity = jest.spyOn(tu, 'getContentEntity');
108
110
  const content = mockData_1.thumbnail_content_entity;
109
111
  spyContentEntity.mockReturnValue(Promise.resolve(content));
110
- const spyGetFileEntities = jest.spyOn(tu, 'getFileEntities');
111
- spyGetFileEntities.mockReturnValue(Promise.resolve(mockData_1.cuRficeyoStwTF_f_fileEntities));
112
112
  const results = await tu.getFileId(primaryFileId);
113
113
  expect(results).toEqual('AsRvJenpeqxksUNW');
114
114
  });
115
115
  it('custom sizes, 750 * 1_024 max_thumbnail_size - result CS_500Id', async () => {
116
- console.log('custom sizes, 750 * 1_024 max_thumbnail_size - result CS_500Id');
117
116
  const config1 = {
118
117
  max_thumbnail_size: 750 * 1024
119
118
  };
@@ -123,10 +122,93 @@ describe('ThumbnailUtil Tests', () => {
123
122
  const spyContentEntity = jest.spyOn(tu, 'getContentEntity');
124
123
  const content = mockData_1.thumbnail_content_entity;
125
124
  spyContentEntity.mockReturnValue(Promise.resolve(content));
126
- const spyGetFileEntities = jest.spyOn(tu, 'getFileEntities');
127
- spyGetFileEntities.mockReturnValue(Promise.resolve(mockData_1.cuRficeyoStwTF_f_fileEntities));
128
125
  const results = await tu.getFileId(primaryFileId);
129
126
  expect(results).toEqual('rBaHc1J2xdOWdbhI');
130
127
  });
131
128
  });
129
+ describe('Test isThumbnailNew', () => {
130
+ const tu = new thumbnail_util_1.ThumbnailUtil(config);
131
+ it('no propertyDiffs', () => {
132
+ const event = {
133
+ newData: {
134
+ name: 'Test'
135
+ },
136
+ oldData: {
137
+ name: 'Test'
138
+ }
139
+ };
140
+ const results = tu.isThumbnailNew(event, undefined);
141
+ expect(results).toBeFalsy();
142
+ });
143
+ it('empty propertyDiffs', () => {
144
+ const event = {
145
+ newData: {
146
+ name: 'Test'
147
+ },
148
+ oldData: {
149
+ name: 'Test'
150
+ },
151
+ propertyDiffs: {}
152
+ };
153
+ const results = tu.isThumbnailNew(event, undefined);
154
+ expect(results).toBeFalsy();
155
+ });
156
+ it('propertyDiffs diff property', () => {
157
+ const event = {
158
+ newData: {
159
+ name: 'Test1'
160
+ },
161
+ oldData: {
162
+ name: 'Test'
163
+ },
164
+ propertyDiffs: {
165
+ name: {
166
+ propertyName: 'name',
167
+ oldValue: 'Test',
168
+ newValue: 'Test1'
169
+ }
170
+ }
171
+ };
172
+ const results = tu.isThumbnailNew(event, undefined);
173
+ expect(results).toBeFalsy();
174
+ });
175
+ it('propertyDiffs OOB property', () => {
176
+ const event = {
177
+ newData: {
178
+ name: 'Test1'
179
+ },
180
+ oldData: {
181
+ name: 'Test'
182
+ },
183
+ propertyDiffs: {
184
+ mediumLargeViewableDownloadUrl: {
185
+ propertyName: 'mediumLargeViewableDownloadUrl',
186
+ oldValue: '',
187
+ newValue: 'Test1'
188
+ }
189
+ }
190
+ };
191
+ const results = tu.isThumbnailNew(event, undefined);
192
+ expect(results).toBeTruthy();
193
+ });
194
+ it('propertyDiffs custom property', () => {
195
+ const event = {
196
+ newData: {
197
+ name: 'Test1'
198
+ },
199
+ oldData: {
200
+ name: 'Test'
201
+ },
202
+ propertyDiffs: {
203
+ RL_1000Url: {
204
+ propertyName: 'RL_1000Url',
205
+ oldValue: '',
206
+ newValue: 'Test1'
207
+ }
208
+ }
209
+ };
210
+ const results = tu.isThumbnailNew(event, [{ slug: 'RL_1000' }]);
211
+ expect(results).toBeTruthy();
212
+ });
213
+ });
132
214
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/flexplm",
3
- "version": "1.1.33",
3
+ "version": "1.1.35",
4
4
  "description": "Library used for integration with flexplm.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -105,7 +105,7 @@ describe('Test getSinceDate', () =>{
105
105
  it('getSinceDate date from config as year', async () =>{
106
106
  const history = new Array(...plan1_history);
107
107
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
108
- const matchDate = new Date('2023-01-17T22:35:20.517Z');
108
+ const matchDate = new Date('2023-01-16T21:50:42.742Z');
109
109
 
110
110
  const config = {sinceDate: '2023-01-17' } as any as FCConfig;
111
111
 
@@ -133,7 +133,7 @@ describe('Test getSinceDate', () =>{
133
133
  expect(sinceDate).toEqual(matchDate);
134
134
  });
135
135
  it('getSinceDate date from config numberofdays-cross DST', async () =>{
136
- const count = 12;
136
+ const count = 11;
137
137
  const history = new Array(...plan1_across_month_DST);
138
138
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
139
139
  const matchDate = new Date('2023-03-06T21:50:42.742Z');
@@ -178,7 +178,7 @@ describe('getSinceDateFromAPCSpecificDate', () =>{
178
178
  it('last apc - one day', () =>{
179
179
  const history = new Array(...plan1_history);
180
180
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
181
- const matchDate = new Date('2023-01-17T22:35:20.517Z');
181
+ const matchDate = new Date('2023-01-16T21:50:42.742Z');
182
182
 
183
183
  const config = {} as FCConfig;
184
184
  const mapFileUtil = new MapFileUtil(new Entities());
@@ -192,7 +192,7 @@ describe('getSinceDateFromAPCSpecificDate', () =>{
192
192
  it('apc in the middle - one day', () =>{
193
193
  const history = new Array(...plan1_history);
194
194
  const lastAPCId = 'GiT9CZXZGVljoYMR';
195
- const matchDate = new Date('2023-01-16T19:16:06.233Z');
195
+ const matchDate = new Date('2023-01-15T19:13:58.902Z');
196
196
 
197
197
  const config = {} as FCConfig;
198
198
  const mapFileUtil = new MapFileUtil(new Entities());
@@ -216,7 +216,7 @@ describe('getSinceDateFromAPCSpecificDate', () =>{
216
216
  it('numberofdays at 2 ', () => {
217
217
  const history = new Array(...plan1_history);
218
218
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
219
- const matchDate = new Date('2023-01-16T19:16:06.233Z');
219
+ const matchDate = new Date('2023-01-15T19:13:58.902Z');
220
220
  const config = {} as FCConfig;
221
221
  const mapFileUtil = new MapFileUtil(new Entities());
222
222
  const dc = new DataConverter(config, mapFileUtil);
@@ -231,7 +231,7 @@ describe('getSinceDateDaysPrevious', () =>{
231
231
  it('last apc - one day', () =>{
232
232
  const history = new Array(...plan1_history);
233
233
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
234
- const matchDate = new Date('2023-01-17T22:35:20.517Z');
234
+ const matchDate = new Date('2023-01-16T21:50:42.742Z');
235
235
 
236
236
  const config = {} as FCConfig;
237
237
  const mapFileUtil = new MapFileUtil(new Entities());
@@ -245,7 +245,7 @@ describe('getSinceDateDaysPrevious', () =>{
245
245
  it('apc in the middle - one day', () =>{
246
246
  const history = new Array(...plan1_history);
247
247
  const lastAPCId = 'GiT9CZXZGVljoYMR';
248
- const matchDate = new Date('2023-01-16T19:16:06.233Z');
248
+ const matchDate = new Date('2023-01-15T19:13:58.902Z');
249
249
 
250
250
  const config = {} as FCConfig;
251
251
  const mapFileUtil = new MapFileUtil(new Entities());
@@ -269,7 +269,7 @@ describe('getSinceDateDaysPrevious', () =>{
269
269
  it('numberofdays at 2 ', () => {
270
270
  const history = new Array(...plan1_history);
271
271
  const lastAPCId = 'sJbGx1Fpq1v2MmcI';
272
- const matchDate = new Date('2023-01-16T19:16:06.233Z');
272
+ const matchDate = new Date('2023-01-15T19:13:58.902Z');
273
273
  const config = {} as FCConfig;
274
274
  const mapFileUtil = new MapFileUtil(new Entities());
275
275
  const dc = new DataConverter(config, mapFileUtil);
@@ -178,47 +178,30 @@ export class BaseProcessPublishAssortment {
178
178
  getSinceDateFromAPCSpecificDate(apcHistory: object[], assortmentPublishChangeId: string, specificDate: Date):Date {
179
179
  const apc = apcHistory.find(apc => apc['id'] === assortmentPublishChangeId);
180
180
  const apcDate = new Date(apc['createdOn']);
181
- const dateArray = [];
181
+ let afterDate = apcDate;
182
+ let beforeDate = new Date(0);
183
+ const sinceDate = specificDate;
182
184
  for (const tempapc of apcHistory) {
183
185
  if (assortmentPublishChangeId !== tempapc['id']) {
184
186
  const tempDate = new Date(tempapc['createdOn']);
185
187
  if (tempDate < apcDate) {
186
- dateArray.push(tempDate);
188
+ if(tempDate > sinceDate && tempDate < afterDate){
189
+ afterDate = tempDate;
190
+ } else if(tempDate < sinceDate && tempDate > beforeDate){
191
+ beforeDate = tempDate;
192
+ }
187
193
  }
188
194
  }
189
195
  }
190
-
191
- dateArray.sort((a,b) => { return Date.parse(a) - Date.parse(b);});
192
-
193
- let sinceDate = specificDate;
194
-
195
- const sinceDateMilliseconds = sinceDate.getTime();
196
- for(const d of dateArray){
197
- const milli = Date.parse(d);
198
- if(milli >= sinceDateMilliseconds){
199
- sinceDate = d;
200
- break;
201
- }
202
- }
203
- return sinceDate;
204
-
196
+ const selectedDate = (beforeDate.getTime() !== 0)?beforeDate : afterDate;
197
+ return selectedDate;
205
198
  }
206
199
  getSinceDateDaysPrevious(apcHistory: object[], assortmentPublishChangeId: string, daysBack):Date {
207
200
  const apc = apcHistory.find(apc => apc['id'] === assortmentPublishChangeId);
208
201
  const apcDate = new Date(apc['createdOn']);
209
- const dateArray = [];
210
- for (const tempapc of apcHistory) {
211
- if (assortmentPublishChangeId !== tempapc['id']) {
212
- const tempDate = new Date(tempapc['createdOn']);
213
- if (tempDate < apcDate) {
214
- dateArray.push(tempDate);
215
- }
216
- }
217
- }
218
-
219
- dateArray.sort((a,b) => { return Date.parse(a) - Date.parse(b);});
220
-
221
- let sinceDate = new Date(
202
+ let afterDate = apcDate;
203
+ let beforeDate = new Date(0);
204
+ const sinceDate = new Date(
222
205
  apcDate.getUTCFullYear(),
223
206
  apcDate.getUTCMonth(),
224
207
  apcDate.getUTCDate()-daysBack,
@@ -226,15 +209,20 @@ export class BaseProcessPublishAssortment {
226
209
  (0 - apcDate.getTimezoneOffset()),
227
210
  0);
228
211
 
229
- const sinceDateMilliseconds = sinceDate.getTime();
230
- for(const d of dateArray){
231
- const milli = Date.parse(d);
232
- if(milli >= sinceDateMilliseconds){
233
- sinceDate = d;
234
- break;
212
+ for (const tempapc of apcHistory) {
213
+ if (assortmentPublishChangeId !== tempapc['id']) {
214
+ const tempDate = new Date(tempapc['createdOn']);
215
+ if (tempDate < apcDate) {
216
+ if(tempDate > sinceDate && tempDate < afterDate){
217
+ afterDate = tempDate;
218
+ } else if(tempDate < sinceDate && tempDate > beforeDate){
219
+ beforeDate = tempDate;
220
+ }
221
+ }
235
222
  }
236
223
  }
237
- return sinceDate;
224
+ const selectedDate = (beforeDate.getTime() !== 0)?beforeDate : afterDate;
225
+ return selectedDate;
238
226
  }
239
227
 
240
228
  getSinceDateFromAPCs(apcHistory: any[], assortmentPublishChangeId: string, pastPublishCount = 1): Date {
@@ -26,73 +26,72 @@ export const thumbnail_content_entity = {
26
26
  fileName: 'JACKET 300_SOLDIER OLIVE.png',
27
27
  primaryFileId: 'yn2d5oHD4rXHRzyB',
28
28
  primaryFileUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Ff646d3cd-e23a-4689-bd16-0301d2036720.png',
29
- tinyViewableId: '6HWzJrQ-Jx1iefmj',
30
- tinyViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fb68f8652-f33f-452f-ae34-25397b4521eb.png',
31
- smallViewableId: 'D3WRW4iRmjLzp5VX',
32
- smallViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F541c53f8-fd85-418e-ae28-ad7410658b90.png',
33
- mediumViewableId: 'AsRvJenpeqxksUNW',
34
- mediumViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fe803c2d3-3e1b-4d9c-9bb9-2c488f1f295b.png',
35
- largeViewableId: 'vo4N4mCd-tFrw101',
36
- largeViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fb1b7a55c-b8ba-4857-be4e-e1c3f11d8e9a.png',
37
- CS_300Id: '6A5AG33nVu3Z6ogO',
38
- CS_300Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F3f2ea306-a77f-4cc3-a49a-75fb5d8b113c.png',
39
- CS_500Id: 'rBaHc1J2xdOWdbhI',
40
- CS_500Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F979c8c65-b63f-4220-aa2e-11520f2f68bf.png',
41
- CS_800Id: 'ZPAeYI3JiqjQ7unY',
42
- CS_800Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fc58eeffa-2592-4698-a058-19281cda447c.png',
43
- CS_1000Id: 'Hg_CthwsD4ozopCb',
44
- CS_1000Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F2c827c7b-361b-4e05-b77d-4280294f9d9c.png',
45
- createdOn: '2023-07-05T15:02:13.950Z',
46
- orgId: '5LZnKVTNxvwMqufy',
47
- id: 'cuRficeyoStwTF-f',
48
- contentType: 'image/png',
49
- createdById: 'SWIFPZeZzkBvrSLD',
50
- updatedById: 'SWIFPZeZzkBvrSLD',
51
- fileSize: 1757973
52
- };
53
- export const cuRficeyoStwTF_f_fileEntities = [
54
- {
29
+ primaryFile: {
55
30
  fileName: 'JACKET 300_SOLDIER OLIVE.png',
56
31
  id: 'yn2d5oHD4rXHRzyB',
57
32
  size: 1757973
58
33
  },
59
- {
34
+ tinyViewableId: '6HWzJrQ-Jx1iefmj',
35
+ tinyViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fb68f8652-f33f-452f-ae34-25397b4521eb.png',
36
+ tinyViewable: {
60
37
  fileName: 'JACKET 300_SOLDIER OLIVE_tiny.png',
61
38
  id: '6HWzJrQ-Jx1iefmj',
62
39
  size: 1784
63
40
  },
64
- {
41
+ smallViewableId: 'D3WRW4iRmjLzp5VX',
42
+ smallViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F541c53f8-fd85-418e-ae28-ad7410658b90.png',
43
+ smallViewable: {
65
44
  fileName: 'JACKET 300_SOLDIER OLIVE_small.png',
66
45
  id: 'D3WRW4iRmjLzp5VX',
67
46
  size: 8699
68
47
  },
69
- {
48
+ mediumViewableId: 'AsRvJenpeqxksUNW',
49
+ mediumViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fe803c2d3-3e1b-4d9c-9bb9-2c488f1f295b.png',
50
+ mediumViewable: {
70
51
  fileName: 'JACKET 300_SOLDIER OLIVE_medium.png',
71
52
  id: 'AsRvJenpeqxksUNW',
72
53
  size: 77558
73
54
  },
74
- {
55
+ largeViewableId: 'vo4N4mCd-tFrw101',
56
+ largeViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fb1b7a55c-b8ba-4857-be4e-e1c3f11d8e9a.png',
57
+ largeViewable: {
75
58
  fileName: 'JACKET 300_SOLDIER OLIVE_large.png',
76
59
  id: 'vo4N4mCd-tFrw101',
77
60
  size: 1781538
78
61
  },
79
- {
62
+ CS_300Id: '6A5AG33nVu3Z6ogO',
63
+ CS_300Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F3f2ea306-a77f-4cc3-a49a-75fb5d8b113c.png',
64
+ CS_300: {
80
65
  fileName: 'JACKET 300_SOLDIER OLIVE_CS_300.png',
81
66
  id: '6A5AG33nVu3Z6ogO',
82
67
  size: 141153
83
68
  },
84
- {
69
+ CS_500Id: 'rBaHc1J2xdOWdbhI',
70
+ CS_500Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F979c8c65-b63f-4220-aa2e-11520f2f68bf.png',
71
+ CS_500: {
85
72
  fileName: 'JACKET 300_SOLDIER OLIVE_CS_500.png',
86
73
  id: 'rBaHc1J2xdOWdbhI',
87
74
  size: 382057
88
75
  },
89
- {
76
+ CS_800Id: 'ZPAeYI3JiqjQ7unY',
77
+ CS_800Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fc58eeffa-2592-4698-a058-19281cda447c.png',
78
+ CS_800:{
90
79
  fileName: 'JACKET 300_SOLDIER OLIVE_CS_800.png',
91
80
  id: 'ZPAeYI3JiqjQ7unY',
92
81
  size: 1008702
93
- },{
82
+ },
83
+ CS_1000Id: 'Hg_CthwsD4ozopCb',
84
+ CS_1000Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F2c827c7b-361b-4e05-b77d-4280294f9d9c.png',
85
+ CS_1000: {
94
86
  fileName: 'JACKET 300_SOLDIER OLIVE_CS_1000.png',
95
87
  id: 'Hg_CthwsD4ozopCb',
96
88
  size: 1605889
97
- }
98
- ];
89
+ },
90
+ createdOn: '2023-07-05T15:02:13.950Z',
91
+ orgId: '5LZnKVTNxvwMqufy',
92
+ id: 'cuRficeyoStwTF-f',
93
+ contentType: 'image/png',
94
+ createdById: 'SWIFPZeZzkBvrSLD',
95
+ updatedById: 'SWIFPZeZzkBvrSLD',
96
+ fileSize: 1757973
97
+ };
@@ -1,7 +1,7 @@
1
1
  import { FCConfig } from '../interfaces/interfaces';
2
2
  import { ThumbnailUtil } from './thumbnail-util';
3
3
 
4
- import { empty_custom_sizes, four_custom_sizes, thumbnail_content_entity, cuRficeyoStwTF_f_fileEntities } from './mockData';
4
+ import { empty_custom_sizes, four_custom_sizes, thumbnail_content_entity } from './mockData';
5
5
 
6
6
  describe('ThumbnailUtil Tests', () =>{
7
7
  const config = {} as FCConfig;
@@ -58,6 +58,8 @@ describe('ThumbnailUtil Tests', () =>{
58
58
  }
59
59
  };
60
60
 
61
+ const spyCustomSizes = jest.spyOn(tu, 'getCustomSizes');
62
+ spyCustomSizes.mockReturnValue(Promise.resolve(empty_custom_sizes));
61
63
  const spyGetFileId = jest.spyOn(tu, 'getFileId');
62
64
  spyGetFileId.mockReturnValue(Promise.resolve(thumbnailId));
63
65
  const results = await tu.setOutboundThumbnail(data, event);
@@ -80,6 +82,8 @@ describe('ThumbnailUtil Tests', () =>{
80
82
  propertyDiffs: {}
81
83
  };
82
84
 
85
+ const spyCustomSizes = jest.spyOn(tu, 'getCustomSizes');
86
+ spyCustomSizes.mockReturnValue(Promise.resolve(empty_custom_sizes));
83
87
  const spyGetFileId = jest.spyOn(tu, 'getFileId');
84
88
  spyGetFileId.mockReturnValue(Promise.resolve(thumbnailId));
85
89
  const results = await tu.setOutboundThumbnail(data, event);
@@ -101,11 +105,9 @@ describe('ThumbnailUtil Tests', () =>{
101
105
  const spyCustomSizes = jest.spyOn(tu, 'getCustomSizes');
102
106
  spyCustomSizes.mockReturnValue(Promise.resolve(empty_custom_sizes));
103
107
  const spyContentEntity = jest.spyOn(tu, 'getContentEntity');
104
- const content = thumbnail_content_entity;
105
- spyContentEntity.mockReturnValue(Promise.resolve(content));
108
+ const content = JSON.parse(JSON.stringify(thumbnail_content_entity));
106
109
 
107
- const spyGetFileEntities = jest.spyOn(tu, 'getFileEntities');
108
- spyGetFileEntities.mockReturnValue(Promise.resolve(cuRficeyoStwTF_f_fileEntities));
110
+ spyContentEntity.mockReturnValue(Promise.resolve(content));
109
111
 
110
112
  const results = await tu.getFileId(primaryFileId);
111
113
  expect(results).toEqual('vo4N4mCd-tFrw101');
@@ -122,15 +124,11 @@ describe('ThumbnailUtil Tests', () =>{
122
124
  const content = thumbnail_content_entity;
123
125
  spyContentEntity.mockReturnValue(Promise.resolve(content));
124
126
 
125
- const spyGetFileEntities = jest.spyOn(tu, 'getFileEntities');
126
- spyGetFileEntities.mockReturnValue(Promise.resolve(cuRficeyoStwTF_f_fileEntities));
127
-
128
127
  const results = await tu.getFileId(primaryFileId);
129
128
  expect(results).toEqual('AsRvJenpeqxksUNW');
130
129
  });
131
130
 
132
131
  it('custom sizes, 750 * 1_024 max_thumbnail_size - result CS_500Id', async () =>{
133
- console.log('custom sizes, 750 * 1_024 max_thumbnail_size - result CS_500Id');
134
132
  const config1 = {
135
133
  max_thumbnail_size: 750 * 1_024
136
134
  } as any as FCConfig;
@@ -141,12 +139,99 @@ describe('ThumbnailUtil Tests', () =>{
141
139
  const content = thumbnail_content_entity;
142
140
  spyContentEntity.mockReturnValue(Promise.resolve(content));
143
141
 
144
- const spyGetFileEntities = jest.spyOn(tu, 'getFileEntities');
145
- spyGetFileEntities.mockReturnValue(Promise.resolve(cuRficeyoStwTF_f_fileEntities));
146
-
147
142
  const results = await tu.getFileId(primaryFileId);
148
143
  expect(results).toEqual('rBaHc1J2xdOWdbhI');
149
144
  });
150
145
 
151
146
  });
147
+
148
+ describe('Test isThumbnailNew', () =>{
149
+ const tu = new ThumbnailUtil(config);
150
+ it('no propertyDiffs', () =>{
151
+ const event = {
152
+ newData: {
153
+ name: 'Test'
154
+ },
155
+ oldData:{
156
+ name: 'Test'
157
+ }
158
+ };
159
+ const results = tu.isThumbnailNew(event, undefined);
160
+ expect(results).toBeFalsy();
161
+ });
162
+
163
+ it('empty propertyDiffs', () =>{
164
+ const event = {
165
+ newData: {
166
+ name: 'Test'
167
+ },
168
+ oldData:{
169
+ name: 'Test'
170
+ },
171
+ propertyDiffs: {}
172
+ };
173
+ const results = tu.isThumbnailNew(event, undefined);
174
+ expect(results).toBeFalsy();
175
+ });
176
+
177
+ it('propertyDiffs diff property', () =>{
178
+ const event = {
179
+ newData: {
180
+ name: 'Test1'
181
+ },
182
+ oldData:{
183
+ name: 'Test'
184
+ },
185
+ propertyDiffs: {
186
+ name: {
187
+ propertyName: 'name',
188
+ oldValue: 'Test',
189
+ newValue: 'Test1'
190
+ }
191
+ }
192
+ };
193
+ const results = tu.isThumbnailNew(event, undefined);
194
+ expect(results).toBeFalsy();
195
+ });
196
+
197
+ it('propertyDiffs OOB property', () =>{
198
+ const event = {
199
+ newData: {
200
+ name: 'Test1'
201
+ },
202
+ oldData:{
203
+ name: 'Test'
204
+ },
205
+ propertyDiffs: {
206
+ mediumLargeViewableDownloadUrl: {
207
+ propertyName: 'mediumLargeViewableDownloadUrl',
208
+ oldValue: '',
209
+ newValue: 'Test1'
210
+ }
211
+ }
212
+ };
213
+ const results = tu.isThumbnailNew(event, undefined);
214
+ expect(results).toBeTruthy();
215
+ });
216
+
217
+ it('propertyDiffs custom property', () =>{
218
+ const event = {
219
+ newData: {
220
+ name: 'Test1'
221
+ },
222
+ oldData:{
223
+ name: 'Test'
224
+ },
225
+ propertyDiffs: {
226
+ RL_1000Url: {
227
+ propertyName: 'RL_1000Url',
228
+ oldValue: '',
229
+ newValue: 'Test1'
230
+ }
231
+ }
232
+ };
233
+ const results = tu.isThumbnailNew(event, [{slug: 'RL_1000'}]);
234
+ expect(results).toBeTruthy();
235
+ });
236
+ });
152
237
  });
@@ -8,6 +8,7 @@ export class ThumbnailUtil {
8
8
  static NEW_THUMBNAIL_ID = 'NEW_THUMBNAIL_ID';
9
9
  static EXISTING_THUMBNAIL_ID = 'EXISTING_THUMBNAIL_ID';
10
10
  static REMOVE_THUMBNAIL = 'REMOVE_THUMBNAIL';
11
+ static OOB_SIZES = [{ slug: 'largeViewable' }, { slug: 'mediumLargeViewable' }, { slug: 'mediumViewable' }, { slug: 'smallViewable' }, { slug: 'tinyViewable' }]
11
12
  constructor(private config: FCConfig){
12
13
  this.entities = new Entities();
13
14
  if(this.config['max_thumbnail_size']){
@@ -22,7 +23,8 @@ export class ThumbnailUtil {
22
23
  const fileId = await this.getFileId(primaryViewableId);
23
24
 
24
25
  if(fileId){
25
- const key = (event?.propertyDiffs?.largeViewableDownloadUrl)
26
+ const customSizes = await this.getCustomSizes();
27
+ const key = (this.isThumbnailNew(event, customSizes))
26
28
  ? ThumbnailUtil.NEW_THUMBNAIL_ID
27
29
  : ThumbnailUtil.EXISTING_THUMBNAIL_ID;
28
30
  data[key] = fileId;
@@ -33,52 +35,58 @@ export class ThumbnailUtil {
33
35
  }
34
36
  return data;
35
37
  }
38
+ /** Determines if a new image has been generated. If any viewable is new, there might be a better
39
+ * sized image. So send the fileId as new.
40
+ *
41
+ * @param event
42
+ * @param customSizes
43
+ * @returns boolean
44
+ */
45
+ public isThumbnailNew(event, customSizes: any[]): boolean {
46
+ const propertyDiffs = event?.propertyDiffs;
47
+ if(propertyDiffs){
48
+ const diffKeys = Object.keys(propertyDiffs);
49
+ const sizeKeys = ThumbnailUtil.OOB_SIZES.map( s => s.slug + 'DownloadUrl');
50
+ if(customSizes){
51
+ sizeKeys.push(...customSizes.map(s => s.slug+ 'Url'));
52
+ }
53
+ sizeKeys.push('primaryFileUrl');
54
+ console.info('diffKeys: ' + JSON.stringify(diffKeys));
55
+ console.info('sizeKeys: ' + JSON.stringify(sizeKeys));
56
+ return diffKeys.some(s => sizeKeys.includes(s));
57
+ }
58
+ return false;
59
+ }
36
60
 
37
61
  public async getFileId(primaryViewableId: string): Promise<string> {
38
- console.info('getFileId()-' + primaryViewableId);
62
+ console.info('ThumbnailUtil.getFileId()-' + primaryViewableId);
39
63
  const sizes = await this.getCustomSizes();
40
64
 
41
- const OOBSizes = [{ slug: 'largeViewable' }, { slug: 'mediumViewable' }, { slug: 'smallViewable' }, { slug: 'tinyViewable' }];
65
+ const OOBSizes = JSON.parse(JSON.stringify(ThumbnailUtil.OOB_SIZES));
42
66
  sizes.push(...OOBSizes);
43
67
  console.info('sizes: ' + JSON.stringify(sizes));
44
68
 
45
69
  //get Content
46
- const content = await this.getContentEntity(primaryViewableId);
47
- if(Logger.isDebugOn()){
48
- console.debug('content: ' + JSON.stringify(content));
49
-
50
- }
70
+ const content = await this.getContentEntity(primaryViewableId, sizes);
51
71
  if (!content) {
52
72
  return undefined;
53
73
  }
54
- //get file entities
55
- const contentKeys = Object.getOwnPropertyNames(content);
56
- const fileEntityIds = [];
57
- for (const size of sizes) {
58
- const key = size.slug + 'Id';
59
- if (contentKeys.includes(key) && !fileEntityIds.includes(content[key])) {
60
- fileEntityIds.push(content[key]);
61
- size['fileId'] = content[key];
62
- }
63
- }
64
-
65
- const fileResults = await this.getFileEntities(fileEntityIds);
66
74
 
67
- if(Logger.isDebugOn()){
68
- console.debug('fileResults: ' + JSON.stringify(fileResults));
69
- }
75
+ const contentKeys = Object.getOwnPropertyNames(content);
76
+ const isDebugOn = Logger.isDebugOn();
70
77
 
71
- // Finding largest image that is under the max limit
72
78
  let fileId = undefined;
73
79
  let tempFileSize = 0;
74
- const isDebugOn = Logger.isDebugOn();
75
- for (const sizeObj of sizes) {
76
- if(isDebugOn){
77
- console.debug('size: ' + JSON.stringify(sizeObj));
78
- }
79
- if (sizeObj['fileId']) {
80
- const file = fileResults.find(f => f['id'] === sizeObj['fileId']);
81
- if (file['size'] > tempFileSize && file['size'] < this.max_thumbnail_size) {
80
+
81
+ for(const size of sizes){
82
+ const slug = size?.slug;
83
+ if(contentKeys.includes(slug)){
84
+ const file = content[slug];
85
+ if(isDebugOn){
86
+ console.debug('size: ' + slug);
87
+ console.debug('fileId: ' + file['id']);
88
+ }
89
+ if(file && file['size'] > tempFileSize && file['size'] < this.max_thumbnail_size){
82
90
  tempFileSize = file['size'];
83
91
  fileId = file['id'];
84
92
  if(isDebugOn){
@@ -87,7 +95,7 @@ export class ThumbnailUtil {
87
95
  }
88
96
  }
89
97
  }
90
- console.info('getFileId(): returning-' + fileId);
98
+ console.info('ThumbnailUtil.getFileId(): returning-' + fileId);
91
99
  return fileId;
92
100
  }
93
101
 
@@ -100,29 +108,38 @@ export class ThumbnailUtil {
100
108
  return sizes;
101
109
  }
102
110
 
103
- async getContentEntity(primaryViewableId: any) {
111
+ async getContentEntity(primaryViewableId: any, sizes: any[]) {
104
112
  const criteria = {
105
113
  id: primaryViewableId
106
114
  };
115
+ const relations = sizes.map(s => s.slug);
116
+ relations.push('primaryFile');
107
117
  const contentResults = await this.entities.get({
108
118
  entityName: 'content',
109
- criteria
119
+ criteria,
120
+ relations
110
121
  });
111
- console.info('contentResults: ' + JSON.stringify(contentResults));
112
122
  const content = (contentResults && contentResults[0]) ? contentResults[0] : undefined;
123
+ this.logContentResults(content, relations);
113
124
  return content;
114
125
  }
115
126
 
116
- async getFileEntities(fileEntityIds: any[]) {
117
- const criteria = {
118
- ids: fileEntityIds
119
- };
120
-
121
- const fileResults = await this.entities.get({
122
- entityName: 'file',
123
- criteria
124
- });
125
- return fileResults;
126
- }
127
+ /** This outputs the content entity, without the inflated file entities.
128
+ * To help debugging issues with sending the thumbnail info.
129
+ * The inflated entities are removed, because are large and cause
130
+ * problems with log file size limits.
131
+ *
132
+ * @param content: the content with inflated objects
133
+ * @param relations: string[] of the slugs for inflated objects
134
+ */
135
+ logContentResults(content: any, relations: string[]) {
136
+ if(Logger.isDebugOn()){
137
+ const contentCopy = JSON.parse(JSON.stringify(content));
138
+ relations.forEach(r => {
139
+ delete contentCopy[r];
140
+ });
141
+ console.debug('content: ' + JSON.stringify(contentCopy));
142
+ }
143
+ }
127
144
 
128
145
  }