@contrail/flexplm 1.5.0-alpha.98b8b06 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/.github/pull_request_template.md +31 -0
  2. package/.github/workflows/flexplm-lib.yml +27 -0
  3. package/.github/workflows/publish-to-npm.yml +121 -0
  4. package/CHANGELOG.md +45 -0
  5. package/lib/entity-processor/base-entity-processor.d.ts +0 -65
  6. package/lib/entity-processor/base-entity-processor.js +0 -71
  7. package/lib/entity-processor/base-entity-processor.spec.js +0 -1
  8. package/lib/index.d.ts +0 -1
  9. package/lib/index.js +0 -1
  10. package/lib/publish/base-process-publish-assortment.d.ts +0 -25
  11. package/lib/publish/base-process-publish-assortment.js +6 -60
  12. package/lib/publish/base-process-publish-assortment.spec.js +4 -22
  13. package/lib/publish/mockData.js +0 -5
  14. package/lib/transform/identifier-conversion-spec-mockData.js +6 -34
  15. package/lib/transform/identifier-conversion.d.ts +0 -36
  16. package/lib/transform/identifier-conversion.js +0 -36
  17. package/lib/transform/identifier-conversion.spec.js +0 -4
  18. package/lib/util/config-defaults.js +0 -3
  19. package/lib/util/config-defaults.spec.js +0 -9
  20. package/lib/util/data-converter-spec-mockData.js +3 -17
  21. package/lib/util/data-converter.d.ts +0 -97
  22. package/lib/util/data-converter.js +1 -127
  23. package/lib/util/data-converter.spec.js +0 -2
  24. package/lib/util/error-response-object.d.ts +0 -5
  25. package/lib/util/error-response-object.js +0 -7
  26. package/lib/util/event-short-message-status.js +0 -1
  27. package/lib/util/federation.js +0 -8
  28. package/lib/util/flexplm-connect.d.ts +0 -7
  29. package/lib/util/flexplm-connect.js +0 -14
  30. package/lib/util/logger-config.js +0 -1
  31. package/lib/util/map-util-spec-mockData.js +3 -17
  32. package/lib/util/map-utils.d.ts +0 -27
  33. package/lib/util/map-utils.js +0 -27
  34. package/lib/util/thumbnail-util.d.ts +0 -21
  35. package/lib/util/thumbnail-util.js +1 -28
  36. package/lib/util/thumbnail-util.spec.js +0 -6
  37. package/lib/util/type-conversion-utils-spec-mockData.js +3 -3
  38. package/lib/util/type-conversion-utils.d.ts +1 -152
  39. package/lib/util/type-conversion-utils.js +1 -155
  40. package/lib/util/type-defaults.d.ts +0 -66
  41. package/lib/util/type-defaults.js +0 -66
  42. package/lib/util/type-defaults.spec.js +5 -5
  43. package/lib/util/type-utils.d.ts +0 -21
  44. package/lib/util/type-utils.js +0 -23
  45. package/lib/util/type-utils.spec.js +0 -2
  46. package/package.json +6 -21
  47. package/publish.bat +5 -0
  48. package/publish.sh +5 -0
  49. package/src/entity-processor/base-entity-processor.spec.ts +689 -0
  50. package/src/entity-processor/base-entity-processor.ts +583 -0
  51. package/src/flexplm-request.ts +28 -0
  52. package/src/flexplm-utils.spec.ts +27 -0
  53. package/src/flexplm-utils.ts +29 -0
  54. package/src/index.ts +22 -0
  55. package/src/interfaces/interfaces.ts +122 -0
  56. package/src/interfaces/item-family-changes.ts +67 -0
  57. package/src/interfaces/publish-change-data.ts +43 -0
  58. package/src/publish/base-process-publish-assortment-callback.ts +50 -0
  59. package/src/publish/base-process-publish-assortment.spec.ts +1992 -0
  60. package/src/publish/base-process-publish-assortment.ts +1134 -0
  61. package/src/publish/mockData.ts +4561 -0
  62. package/src/transform/identifier-conversion-spec-mockData.ts +496 -0
  63. package/src/transform/identifier-conversion.spec.ts +386 -0
  64. package/src/transform/identifier-conversion.ts +282 -0
  65. package/src/util/config-defaults.spec.ts +445 -0
  66. package/src/util/config-defaults.ts +106 -0
  67. package/src/util/data-converter-spec-mockData.ts +231 -0
  68. package/src/util/data-converter.spec.ts +1622 -0
  69. package/src/util/data-converter.ts +819 -0
  70. package/src/util/error-response-object.spec.ts +116 -0
  71. package/src/util/error-response-object.ts +50 -0
  72. package/src/util/event-short-message-status.ts +22 -0
  73. package/src/util/federation.ts +172 -0
  74. package/src/util/flexplm-connect.spec.ts +132 -0
  75. package/src/util/flexplm-connect.ts +208 -0
  76. package/src/util/logger-config.ts +20 -0
  77. package/src/util/map-util-spec-mockData.ts +231 -0
  78. package/src/util/map-utils.spec.ts +103 -0
  79. package/src/util/map-utils.ts +41 -0
  80. package/src/util/mockData.ts +101 -0
  81. package/src/util/thumbnail-util.spec.ts +508 -0
  82. package/src/util/thumbnail-util.ts +272 -0
  83. package/src/util/type-conversion-utils-spec-mockData.ts +272 -0
  84. package/src/util/type-conversion-utils.spec.ts +1031 -0
  85. package/src/util/type-conversion-utils.ts +490 -0
  86. package/src/util/type-defaults.spec.ts +797 -0
  87. package/src/util/type-defaults.ts +320 -0
  88. package/src/util/type-utils.spec.ts +227 -0
  89. package/src/util/type-utils.ts +144 -0
  90. package/tsconfig.json +24 -0
  91. package/tslint.json +57 -0
  92. package/lib/cli/commands/compile.d.ts +0 -4
  93. package/lib/cli/commands/compile.js +0 -73
  94. package/lib/cli/commands/compile.spec.d.ts +0 -1
  95. package/lib/cli/commands/compile.spec.js +0 -80
  96. package/lib/cli/commands/create.d.ts +0 -5
  97. package/lib/cli/commands/create.js +0 -77
  98. package/lib/cli/commands/create.spec.d.ts +0 -1
  99. package/lib/cli/commands/create.spec.js +0 -78
  100. package/lib/cli/commands/upload.d.ts +0 -17
  101. package/lib/cli/commands/upload.js +0 -228
  102. package/lib/cli/commands/upload.spec.d.ts +0 -1
  103. package/lib/cli/commands/upload.spec.js +0 -88
  104. package/lib/cli/index.d.ts +0 -5
  105. package/lib/cli/index.js +0 -70
  106. package/lib/cli/index.spec.d.ts +0 -1
  107. package/lib/cli/index.spec.js +0 -85
  108. package/lib/cli/template/mapping-template.ts.template +0 -62
  109. package/lib/interfaces/mapping-file.d.ts +0 -460
  110. package/lib/interfaces/mapping-file.js +0 -2
  111. package/scripts/copy-template.js +0 -10
@@ -0,0 +1,386 @@
1
+ import { MapFileUtil } from "@contrail/transform-data";
2
+ import { IdentifierConversion } from "./identifier-conversion";
3
+ import { DataConverter } from "../util/data-converter";
4
+ import { FCConfig } from "../interfaces/interfaces";
5
+ import { Entities } from "@contrail/sdk";
6
+ import { TypeDefaults } from "../util/type-defaults";
7
+
8
+ const mapFile1Data = require('./identifier-conversion-spec-mockData');
9
+ const mapFile1Mappings = mapFile1Data?.mapping;
10
+ const mapFile2Mappings = mapFile1Data?.mapping2;
11
+ const mappings = {
12
+ mapFile1: mapFile1Mappings,
13
+ mapFile2: mapFile2Mappings
14
+ };
15
+
16
+ describe('getAssortmentFromObject', () => {
17
+ const transformMapFile1 = 'mapFile1';
18
+ const transformMapFile2 = 'mapFile2';
19
+ const config = {} as FCConfig;
20
+ const mapFileUtil = new MapFileUtil(new Entities());
21
+ mapFileUtil.getMapFile = async (fileId: string) => {
22
+ return mappings[fileId];
23
+ };
24
+ const dc = new DataConverter(config, mapFileUtil);
25
+ dc.getEntityValues = async (objectClass: string, data: any, keysToSkip: string[] = []) => {
26
+ const entityValues = {};
27
+ for (const key of Object.keys(data)) {
28
+ const value = data[key];
29
+ if (value) {
30
+ const to = typeof value;
31
+ if (['string', 'number', 'boolean'].includes(to)) {
32
+ entityValues[key] = value;
33
+ } else if (Array.isArray(value)) {
34
+ //multi select
35
+ entityValues[key] = value.map((v) => v.value);
36
+ } else if (value.value) {
37
+ //single select
38
+ entityValues[key] = value.value;
39
+ }
40
+ }
41
+ }
42
+ return entityValues;
43
+ };
44
+
45
+ it('should error if no object is provided', async () => {
46
+ try {
47
+ await IdentifierConversion.getAssortmentCriteriaFromObject(transformMapFile1, mapFileUtil, dc, null);
48
+ } catch (e) {
49
+ expect(e.message).toEqual(expect.stringContaining(IdentifierConversion.MISSING_OBJECT));
50
+ }
51
+ });
52
+
53
+ it('should error if no flexPLMObjectClass is provided', async () => {
54
+ try {
55
+ await IdentifierConversion.getAssortmentCriteriaFromObject(transformMapFile1, mapFileUtil, dc, {});
56
+ } catch (e) {
57
+ expect(e.message).toEqual(expect.stringContaining(IdentifierConversion.MISSING_FLEXPLM_OBJECT_CLASS));
58
+ }
59
+ });
60
+
61
+ it('should return the assortment criteria from the object - flexPLMSeasonName', async () => {
62
+ const object = {
63
+ "brand": {
64
+ "display": "Vibe IQ",
65
+ "value": "vibeiq"
66
+ },
67
+ "flexPLMObjectClass": "LCSSeason",
68
+ "flexPLMTypePath": "Season",
69
+ "seasonName": "Vibe IQ Spring 2004",
70
+ "seasonType": {
71
+ "display": "Spring",
72
+ "value": "spring"
73
+ },
74
+ "year": {
75
+ "display": "2004",
76
+ "value": "2004"
77
+ }
78
+ };
79
+ const criteriaObject = {
80
+ flexPLMObjectClass: 'LCSSeason',
81
+ flexPLMSeasonName: 'Vibe IQ Spring 2004',
82
+ flexPLMTypePath: 'Season'
83
+ };
84
+ const resultsObject = {
85
+ flexPLMSeasonName: 'Vibe IQ Spring 2004'
86
+ };
87
+ let getEntityValuesSpyOn = undefined
88
+ try {
89
+
90
+ getEntityValuesSpyOn = jest.spyOn(dc, 'getEntityValues');
91
+ const result = await IdentifierConversion.getAssortmentCriteriaFromObject(transformMapFile1, mapFileUtil, dc, object);
92
+ expect(getEntityValuesSpyOn).toHaveBeenCalledWith('LCSSeason', criteriaObject, []);
93
+ expect(result).toEqual(resultsObject);
94
+ } finally {
95
+ if (getEntityValuesSpyOn) {
96
+ getEntityValuesSpyOn.mockRestore();
97
+ }
98
+ }
99
+ });
100
+
101
+ it('should return the assortment criteria from the object - brand,year,seasonType', async () => {
102
+ const object = {
103
+ brand: {
104
+ display: "Vibe IQ",
105
+ value: "vibeiq"
106
+ },
107
+ flexPLMObjectClass: "LCSSeason",
108
+ flexPLMTypePath: "Season",
109
+ seasonName: "Vibe IQ Spring 2004",
110
+ seasonType: {
111
+ display: "Spring",
112
+ value: "spring"
113
+ },
114
+ year: {
115
+ "display": "2004",
116
+ "value": "2004"
117
+ }
118
+ };
119
+ const criteriaObject = {
120
+ flexPLMObjectClass: 'LCSSeason',
121
+ brand: {
122
+ "display": "Vibe IQ",
123
+ "value": "vibeiq"
124
+ },
125
+ year: {
126
+ "display": "2004",
127
+ "value": "2004"
128
+ },
129
+ seasonType: {
130
+ "display": "Spring",
131
+ "value": "spring"
132
+ },
133
+ flexPLMTypePath: 'Season'
134
+ };
135
+ const resultsObject = {
136
+ brand: 'vibeiq',
137
+ year: '2004',
138
+ seasonType: 'spring'
139
+ };
140
+ let getEntityValuesSpyOn = undefined
141
+ try {
142
+
143
+ getEntityValuesSpyOn = jest.spyOn(dc, 'getEntityValues');
144
+ const result = await IdentifierConversion.getAssortmentCriteriaFromObject(transformMapFile2, mapFileUtil, dc, object);
145
+ expect(getEntityValuesSpyOn).toHaveBeenCalledWith('LCSSeason', criteriaObject, []);
146
+ expect(result).toEqual(resultsObject);
147
+ } finally {
148
+ if (getEntityValuesSpyOn) {
149
+ getEntityValuesSpyOn.mockRestore();
150
+ }
151
+ }
152
+ });
153
+
154
+ });
155
+
156
+ describe('getItemCriteriaFromObject', () => {
157
+ const transformMapFile1 = 'mapFile1';
158
+ const transformMapFile2 = 'mapFile2';
159
+ const config = {} as FCConfig;
160
+ const mapFileUtil = new MapFileUtil(new Entities());
161
+ mapFileUtil.getMapFile = async (fileId: string) => {
162
+ return mappings[fileId];
163
+ };
164
+ const dc = new DataConverter(config, mapFileUtil);
165
+ dc.getEntityValues = async (objectClass: string, data: any, keysToSkip: string[] = []) => {
166
+ const entityValues = {};
167
+ for (const key of Object.keys(data)) {
168
+ const value = data[key];
169
+ if (value) {
170
+ const to = typeof value;
171
+ if (['string', 'number', 'boolean'].includes(to)) {
172
+ entityValues[key] = value;
173
+ } else if (Array.isArray(value)) {
174
+ //multi select
175
+ entityValues[key] = value.map((v) => v.value);
176
+ } else if (value.value) {
177
+ //single select
178
+ entityValues[key] = value.value;
179
+ }
180
+ }
181
+ }
182
+ return entityValues;
183
+ };
184
+
185
+ it('should error if no object is provided', async () => {
186
+ try {
187
+ await IdentifierConversion.getItemCriteriaFromObject(transformMapFile1, mapFileUtil, dc, null);
188
+ } catch (e) {
189
+ expect(e.message).toEqual(expect.stringContaining(IdentifierConversion.MISSING_OBJECT));
190
+ }
191
+ });
192
+
193
+ it('should error if no flexPLMObjectClass is provided', async () => {
194
+ try {
195
+ await IdentifierConversion.getItemCriteriaFromObject(transformMapFile1, mapFileUtil, dc, {});
196
+ } catch (e) {
197
+ expect(e.message).toEqual(expect.stringContaining(IdentifierConversion.MISSING_FLEXPLM_OBJECT_CLASS));
198
+ }
199
+ });
200
+
201
+ it('should error if missing identifier properties -itemNumber', async () => {
202
+ const object = {
203
+ "flexBoolean": false,
204
+ "flexMultiSelect": [
205
+ ],
206
+ "flexNumber": 0,
207
+ "flexPLMObjectClass": "LCSProduct",
208
+ "flexPLMTypePath": "Product\\Pants",
209
+ "flexSingleList": {
210
+ "display": "Five",
211
+ "value": "five"
212
+ },
213
+ "productName": "Feb 3 - 1 Option A",
214
+ "NotvibeIQIdentifier": 966
215
+ };
216
+ const criteriaObject = {
217
+ flexPLMObjectClass: 'LCSProduct',
218
+ flexPLMTypePath: 'Product\\Pants',
219
+ };
220
+
221
+ let getEntityValuesSpyOn = undefined
222
+ try {
223
+
224
+ getEntityValuesSpyOn = jest.spyOn(dc, 'getEntityValues');
225
+ await IdentifierConversion.getItemCriteriaFromObject(transformMapFile1, mapFileUtil, dc, object);
226
+ }catch (e) {
227
+ expect(getEntityValuesSpyOn).toHaveBeenCalledWith('LCSProduct', criteriaObject, []);
228
+ expect(e.message).toEqual(expect.stringContaining(IdentifierConversion.INBOUND_ENTITY_MISSING_IDENIFIER_PROPS));
229
+
230
+ } finally {
231
+ if (getEntityValuesSpyOn) {
232
+ getEntityValuesSpyOn.mockRestore();
233
+ }
234
+ }
235
+ });
236
+
237
+ it('should return the item family criteria from the object -itemNumber', async () => {
238
+ const object = {
239
+ "flexBoolean": false,
240
+ "flexMultiSelect": [
241
+ ],
242
+ "flexNumber": 0,
243
+ "flexPLMObjectClass": "LCSProduct",
244
+ "flexPLMTypePath": "Product\\Pants",
245
+ "flexSingleList": {
246
+ "display": "Five",
247
+ "value": "five"
248
+ },
249
+ "productName": "Feb 3 - 1 Option A",
250
+ "vibeIQIdentifier": 966
251
+ };
252
+ const criteriaObject = {
253
+ flexPLMObjectClass: 'LCSProduct',
254
+ itemNumber: 966,
255
+ flexPLMTypePath: 'Product\\Pants',
256
+ };
257
+ const resultsObject = {
258
+ roles: 'family',
259
+ itemNumber: 966
260
+ };
261
+ let getEntityValuesSpyOn = undefined
262
+ try {
263
+
264
+ getEntityValuesSpyOn = jest.spyOn(dc, 'getEntityValues');
265
+ const result = await IdentifierConversion.getItemCriteriaFromObject(transformMapFile1, mapFileUtil, dc, object);
266
+ expect(getEntityValuesSpyOn).toHaveBeenCalledWith('LCSProduct', criteriaObject, []);
267
+ expect(result).toEqual(resultsObject);
268
+ } finally {
269
+ if (getEntityValuesSpyOn) {
270
+ getEntityValuesSpyOn.mockRestore();
271
+ }
272
+ }
273
+ });
274
+
275
+ it('should return the item option criteria from the object -itemNumber', async () => {
276
+ const object = {
277
+ "flexBoolean": false,
278
+ "flexMultiSelect": [
279
+ ],
280
+ "flexNumber": 0,
281
+ "flexPLMObjectClass": "LCSSKU",
282
+ "flexPLMTypePath": "Product\\Pants",
283
+ "flexSingleList": {
284
+ "display": "Five",
285
+ "value": "five"
286
+ },
287
+ "productName": "Feb 3 - 1 Option A",
288
+ "vibeIQIdentifier": 2876
289
+ };
290
+ const criteriaObject = {
291
+ flexPLMObjectClass: 'LCSSKU',
292
+ itemNumber: 2876,
293
+ flexPLMTypePath: 'Product\\Pants',
294
+ };
295
+ const resultsObject = {
296
+ roles: 'color',
297
+ itemNumber: 2876
298
+ };
299
+ let getEntityValuesSpyOn = undefined
300
+ try {
301
+
302
+ getEntityValuesSpyOn = jest.spyOn(dc, 'getEntityValues');
303
+ const result = await IdentifierConversion.getItemCriteriaFromObject(transformMapFile1, mapFileUtil, dc, object);
304
+ expect(getEntityValuesSpyOn).toHaveBeenCalledWith('LCSSKU', criteriaObject, []);
305
+ expect(result).toEqual(resultsObject);
306
+ } finally {
307
+ if (getEntityValuesSpyOn) {
308
+ getEntityValuesSpyOn.mockRestore();
309
+ }
310
+ }
311
+ });
312
+
313
+ it('should return the item family criteria from the object -LCSMaterial', async () => {
314
+ const object = {
315
+ "flexPLMObjectClass": "LCSMaterial",
316
+ "flexPLMTypePath": "Material\\form",
317
+ "itemNumber": "MAT-100"
318
+ };
319
+ const criteriaObject = {
320
+ flexPLMObjectClass: 'LCSMaterial',
321
+ itemNumber: 'MAT-100',
322
+ flexPLMTypePath: 'Material\\form',
323
+ };
324
+ const resultsObject = {
325
+ roles: 'family',
326
+ itemNumber: 'MAT-100'
327
+ };
328
+ let getEntityValuesSpyOn = undefined
329
+ TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: true } });
330
+ try {
331
+
332
+ getEntityValuesSpyOn = jest.spyOn(dc, 'getEntityValues');
333
+ const result = await IdentifierConversion.getItemCriteriaFromObject(transformMapFile1, mapFileUtil, dc, object);
334
+ expect(getEntityValuesSpyOn).toHaveBeenCalledWith('LCSMaterial', criteriaObject, []);
335
+ expect(result).toEqual(resultsObject);
336
+ } finally {
337
+ if (getEntityValuesSpyOn) {
338
+ getEntityValuesSpyOn.mockRestore();
339
+ }
340
+ TypeDefaults.applyConfig({});
341
+ }
342
+ });
343
+
344
+ it('should return the item option criteria from the object -uniqueIdentifierA, uniqueIdentifierB', async () => {
345
+ const object = {
346
+ "flexBoolean": false,
347
+ "flexMultiSelect": [
348
+ ],
349
+ "flexNumber": 0,
350
+ "flexPLMObjectClass": "LCSSKU",
351
+ "flexPLMTypePath": "Product\\Pants",
352
+ "flexSingleList": {
353
+ "display": "Five",
354
+ "value": "five"
355
+ },
356
+ "productName": "Feb 3 - 1 Option A",
357
+ uniqueIdentifierA: 28,
358
+ uniqueIdentifierB: 29,
359
+ "vibeIQIdentifier": 2876
360
+ };
361
+ const criteriaObject = {
362
+ flexPLMObjectClass: 'LCSSKU',
363
+ uniqueIdentifierA: 28,
364
+ uniqueIdentifierB: 29,
365
+ flexPLMTypePath: 'Product\\Pants',
366
+ };
367
+ const resultsObject = {
368
+ roles: 'color',
369
+ uniqueIdentifierA: 28,
370
+ uniqueIdentifierB: 29,
371
+ };
372
+ let getEntityValuesSpyOn = undefined
373
+ try {
374
+
375
+ getEntityValuesSpyOn = jest.spyOn(dc, 'getEntityValues');
376
+ const result = await IdentifierConversion.getItemCriteriaFromObject(transformMapFile2, mapFileUtil, dc, object);
377
+ expect(getEntityValuesSpyOn).toHaveBeenCalledWith('LCSSKU', criteriaObject, []);
378
+ expect(result).toEqual(resultsObject);
379
+ } finally {
380
+ if (getEntityValuesSpyOn) {
381
+ getEntityValuesSpyOn.mockRestore();
382
+ }
383
+ }
384
+ });
385
+
386
+ });
@@ -0,0 +1,282 @@
1
+ import { MapFileUtil } from "@contrail/transform-data";
2
+ import { ProductFederation, SeasonFederation, SeasonGroupFederation, SkuFederation } from "../interfaces/interfaces";
3
+ import { MapUtil } from "../util/map-utils";
4
+ import { TypeConversionUtils } from "../util/type-conversion-utils";
5
+ import { DataConverter } from "../util/data-converter";
6
+ import { EventShortMessageStatus } from "../util/event-short-message-status";
7
+
8
+ export class IdentifierConversion {
9
+ static readonly INBOUND_ENTITY_MISSING_IDENIFIER_PROPS = 'IdentifierConversion.getEntityCriteriaFromObject(): missing identifier properties: ';
10
+
11
+ static readonly MISSING_OBJECT = 'IdentifierConversion.getEntityCriteriaFromObject(): missing: object';
12
+
13
+ static readonly MISSING_FLEXPLM_OBJECT_CLASS = 'IdentifierConversion.getEntityCriteriaFromObject(): missing: flexPLMObjectClass';
14
+
15
+ /** Takes in an assortment and returns an object to query for an LCSSeason
16
+ * This will only return the identifier properties, and information properties if specified.
17
+ * @param transformMapFile
18
+ * @param mapFileUtil
19
+ * @param dc
20
+ * @param assortment
21
+ * @param includeInformationKeys defaults true
22
+ * @returns
23
+ */
24
+ static async getSeasonIdentityObject(transformMapFile: string, mapFileUtil: MapFileUtil, dc: DataConverter, assortment, includeInformationKeys = true): Promise<SeasonFederation>{
25
+ if(!assortment){
26
+ throw new Error('IdentifierConversion.getSeasonIdentityObject(): assortment must be provided.');
27
+ }
28
+ assortment['flex2vibeMapKeyRoot'] = 'LCSSeason';
29
+ const flexPLMTypePath = await TypeConversionUtils.getObjectTypePath(transformMapFile, mapFileUtil, assortment);
30
+
31
+ let seasonObj: any = {
32
+ entityReference: 'assortment:' + assortment?.id,
33
+ objectClass: 'LCSSeason' as const,
34
+ flexPLMTypePath
35
+ };
36
+
37
+ try{
38
+ const assortmentObj = await dc.getFlexPLMObjectData(assortment, [], true);
39
+ const identifierKeys: string[] = await TypeConversionUtils.getIdentifierProperties(transformMapFile, mapFileUtil, assortment);
40
+ for(const key of identifierKeys){
41
+ if(assortmentObj[key]){
42
+ seasonObj[key] = assortmentObj[key];
43
+ }
44
+ }
45
+ if(includeInformationKeys){
46
+ const informationKeys: string[] = await TypeConversionUtils
47
+ .getInformationalProperties(transformMapFile, mapFileUtil, assortment);
48
+ for(const key of informationKeys){
49
+ if(assortmentObj[key]){
50
+ seasonObj[key] = assortmentObj[key];
51
+ }
52
+ }
53
+ }
54
+
55
+ const objectKeys = Object.keys(seasonObj);
56
+ const hasAllIdentifiers = identifierKeys.every(key => objectKeys.includes(key));
57
+ if(!hasAllIdentifiers){
58
+ console.error('IdentifierConversion.getSeasonIdentityObject(): doesnt have all identifier properties - '+ identifierKeys);
59
+ console.error('assortment: ' + JSON.stringify(assortment));
60
+ }
61
+
62
+ const mapKey:string = await TypeConversionUtils
63
+ .getMapKey(transformMapFile, mapFileUtil, assortment, TypeConversionUtils.VIBE2FLEX_DIRECTION);
64
+ seasonObj = await MapUtil
65
+ .applyTransformMap(transformMapFile, mapFileUtil, seasonObj, mapKey, TypeConversionUtils.VIBE2FLEX_DIRECTION);
66
+ } finally {
67
+ delete assortment['flex2vibeMapKeyRoot'];
68
+ }
69
+
70
+ return seasonObj as SeasonFederation;
71
+ }
72
+
73
+ /** Takes in an assortment and returns an object to query for an SeasonGroup
74
+ * This will only return the identifier properties, and information properties if specified.
75
+ * @param transformMapFile
76
+ * @param mapFileUtil
77
+ * @param dc
78
+ * @param assortment
79
+ * @param includeInformationKeys defaults true
80
+ * @returns
81
+ */
82
+ static async getSeasonGroupIdentityObject(transformMapFile: string, mapFileUtil: MapFileUtil, dc: DataConverter, assortment, includeInformationKeys = true): Promise<SeasonGroupFederation> {
83
+ if(!assortment){
84
+ throw new Error('IdentifierConversion.getSeasonGroupIdentityObject(): assortment must be provided.');
85
+ }
86
+ assortment['flex2vibeMapKeyRoot'] = 'SeasonGroup';
87
+ const flexPLMTypePath = await TypeConversionUtils.getObjectTypePath(transformMapFile, mapFileUtil, assortment);
88
+
89
+ let seasonGroupObj = {
90
+ entityReference: 'assortment:' + assortment?.id,
91
+ objectClass: 'SeasonGroup' as const,
92
+ flexPLMTypePath
93
+ };
94
+
95
+ try {
96
+ const assortmentObj = await dc.getFlexPLMObjectData(assortment, [], true);
97
+
98
+ const identifierKeys: string[] = await TypeConversionUtils
99
+ .getIdentifierProperties(transformMapFile, mapFileUtil, assortment);
100
+ for (const key of identifierKeys) {
101
+ if (assortmentObj[key]) {
102
+ seasonGroupObj[key] = assortmentObj[key];
103
+ }
104
+ }
105
+
106
+ if(includeInformationKeys){
107
+ const informationKeys: string[] = await TypeConversionUtils
108
+ .getInformationalProperties(transformMapFile, mapFileUtil, assortment);
109
+ for (const key of informationKeys) {
110
+ if (assortmentObj[key]) {
111
+ seasonGroupObj[key] = assortmentObj[key];
112
+ }
113
+ }
114
+
115
+ }
116
+ const objectKeys = Object.keys(seasonGroupObj);
117
+ const hasAllIdentifiers = identifierKeys.every(key => objectKeys.includes(key));
118
+
119
+ if (!hasAllIdentifiers) {
120
+ console.error('IdentifierConversion.getSeasonGroupIdentityObject(): doesnt have all identifier properties - '+ identifierKeys);
121
+ console.error('assortment: ' + JSON.stringify(assortment));
122
+ }
123
+
124
+ const mapKey: string = await TypeConversionUtils.getMapKey(transformMapFile, mapFileUtil, assortment, TypeConversionUtils.VIBE2FLEX_DIRECTION);
125
+ seasonGroupObj = await MapUtil.applyTransformMap(transformMapFile, mapFileUtil, seasonGroupObj, mapKey, TypeConversionUtils.VIBE2FLEX_DIRECTION);
126
+
127
+ } finally {
128
+ delete assortment['flex2vibeMapKeyRoot'];
129
+ }
130
+ return seasonGroupObj;
131
+ }
132
+
133
+ /** Takes in an item and returns an object to query for an LCSProduct
134
+ * This will only return the identifier properties, and information properties if specified.
135
+ * @param transformMapFile
136
+ * @param mapFileUtil
137
+ * @param dc
138
+ * @param assortment
139
+ * @param includeInformationKeys defaults true
140
+ * @returns
141
+ */
142
+ static async getProductIdentityObject(transformMapFile: string, mapFileUtil: MapFileUtil, dc: DataConverter, itemFamilyObject, includeInformationKeys = true): Promise<ProductFederation> {
143
+ if(!itemFamilyObject){
144
+ throw new Error('IdentifierConversion.getProductIdentityObject(): itemFamilyObject must be provided.');
145
+ }
146
+ const itemObj = await dc.getFlexPLMObjectData(itemFamilyObject, [], true);
147
+ const flexPLMTypePath = await TypeConversionUtils.getObjectTypePath(transformMapFile, mapFileUtil, itemFamilyObject);
148
+ let prodObj: ProductFederation = {
149
+ entityReference: 'item:' + itemFamilyObject?.id,
150
+ objectClass: 'LCSProduct' as const,
151
+ flexPLMTypePath
152
+ };
153
+
154
+ const identifierKeys: string[] = await TypeConversionUtils
155
+ .getIdentifierProperties(transformMapFile, mapFileUtil, itemFamilyObject);
156
+ for (const key of identifierKeys) {
157
+ if (itemObj[key]) {
158
+ prodObj[key] = itemObj[key];
159
+ }
160
+ }
161
+
162
+ if(includeInformationKeys){
163
+ const informationKeys: string[] = await TypeConversionUtils
164
+ .getInformationalProperties(transformMapFile, mapFileUtil, itemFamilyObject);
165
+ for (const key of informationKeys) {
166
+ if (itemObj[key]) {
167
+ prodObj[key] = itemObj[key];
168
+ }
169
+ }
170
+ }
171
+
172
+ const vibeIQIdentifier = 'vibeIQIdentifier';
173
+ if (!prodObj[vibeIQIdentifier]) {
174
+ prodObj['vibeIQIdentifier'] = itemFamilyObject['identifier'] || itemFamilyObject['itemNumber'];
175
+ }
176
+
177
+ const mapKey: string = await TypeConversionUtils
178
+ .getMapKey(transformMapFile, mapFileUtil, itemFamilyObject, TypeConversionUtils.VIBE2FLEX_DIRECTION);
179
+ prodObj = await MapUtil
180
+ .applyTransformMap(transformMapFile, mapFileUtil, prodObj, mapKey, TypeConversionUtils.VIBE2FLEX_DIRECTION);
181
+
182
+ return prodObj as ProductFederation;
183
+ }
184
+
185
+ /** Takes in an item and returns an object to query for an LCSSKU
186
+ * This will only return the identifier properties, and information properties if specified.
187
+ * @param transformMapFile
188
+ * @param mapFileUtil
189
+ * @param dc
190
+ * @param assortment
191
+ * @param includeInformationKeys defaults true
192
+ * @returns
193
+ */
194
+ static async getSKUIdentityObject(transformMapFile: string, mapFileUtil: MapFileUtil, dc: DataConverter, itemObject, includeInformationKeys = true): Promise<SkuFederation> {
195
+ if(!itemObject){
196
+ throw new Error('IdentifierConversion.getSKUIdentityObject(): itemObject must be provided.');
197
+ }
198
+ const itemObj = await dc.getFlexPLMObjectData(itemObject, [], true);
199
+ const flexPLMTypePath = await TypeConversionUtils.getObjectTypePath(transformMapFile, mapFileUtil, itemObject);
200
+ let skuObj: SkuFederation = {
201
+ entityReference: 'item:' + itemObject?.id,
202
+ objectClass: 'LCSSKU' as const,
203
+ flexPLMTypePath
204
+ };
205
+
206
+ const identifierKeys: string[] = await TypeConversionUtils.getIdentifierProperties(transformMapFile, mapFileUtil, itemObject);
207
+ for (const key of identifierKeys) {
208
+ if (itemObj[key]) {
209
+ skuObj[key] = itemObj[key];
210
+ }
211
+ }
212
+
213
+ if(includeInformationKeys){
214
+ const informationKeys: string[] = await TypeConversionUtils.getInformationalProperties(transformMapFile, mapFileUtil, itemObject);
215
+ for (const key of informationKeys) {
216
+ if (itemObj[key]) {
217
+ skuObj[key] = itemObj[key];
218
+ }
219
+ }
220
+ }
221
+
222
+ const vibeIQIdentifier = 'vibeIQIdentifier';
223
+ if (!skuObj[vibeIQIdentifier]) {
224
+ skuObj['vibeIQIdentifier'] = itemObject['identifier'] || itemObject['itemNumber'];
225
+ }
226
+
227
+ const mapKey: string = await TypeConversionUtils.getMapKey(transformMapFile, mapFileUtil, itemObject, TypeConversionUtils.VIBE2FLEX_DIRECTION);
228
+ skuObj = await MapUtil.applyTransformMap(transformMapFile, mapFileUtil, skuObj, mapKey, TypeConversionUtils.VIBE2FLEX_DIRECTION);
229
+
230
+ return skuObj as SkuFederation;
231
+ }
232
+
233
+ static async getEntityCriteriaFromObject(transformMapFile: string, mapFileUtil: MapFileUtil, dc: DataConverter, object: any): Promise<any> {
234
+ if(!object){
235
+ const e =new Error(IdentifierConversion.MISSING_OBJECT)
236
+ e['shortStatusMessage'] = EventShortMessageStatus.MISSING_INPUT;
237
+ throw e;
238
+ } else if(!object.flexPLMObjectClass){
239
+ const e = new Error(IdentifierConversion.MISSING_FLEXPLM_OBJECT_CLASS);
240
+ e['shortStatusMessage'] = EventShortMessageStatus.MISSING_INPUT;
241
+ throw e;
242
+ }
243
+ const mapKey: string = await TypeConversionUtils.getMapKeyFromObject(transformMapFile, mapFileUtil, object, TypeConversionUtils.FLEX2VIBE_DIRECTION);
244
+
245
+ const identifierKeys: string[] = await TypeConversionUtils.getIdentifierPropertiesFromObject(transformMapFile, mapFileUtil, object);
246
+ const objectData = await MapUtil.applyTransformMap(transformMapFile, mapFileUtil, object, mapKey, TypeConversionUtils.FLEX2VIBE_DIRECTION);
247
+
248
+ let identifierValues = identifierKeys.reduce((acc, key) => {
249
+ acc[key] = objectData[key];
250
+ return acc;
251
+ }, {});
252
+ identifierValues['flexPLMObjectClass']= objectData?.flexPLMObjectClass;
253
+ identifierValues['flexPLMTypePath']= objectData?.flexPLMTypePath;
254
+
255
+ identifierValues = await dc.getEntityValues(objectData?.flexPLMObjectClass, identifierValues, []);
256
+
257
+ const entityKeys = Object.keys(identifierValues);
258
+ const hasAllIdentifiers = identifierKeys.every(key => entityKeys.includes(key));
259
+ if (!hasAllIdentifiers) {
260
+ const e = new Error(IdentifierConversion.INBOUND_ENTITY_MISSING_IDENIFIER_PROPS + identifierKeys);
261
+ e['shortStatusMessage'] = EventShortMessageStatus.MISSING_IDENTIFIER_PROPERTIES;
262
+
263
+ throw e;
264
+ }
265
+ const criteria = {};
266
+ for (const key of identifierKeys) {
267
+ criteria[key] = identifierValues[key];
268
+ }
269
+ return criteria;
270
+ }
271
+ static async getAssortmentCriteriaFromObject(transformMapFile: string, mapFileUtil: MapFileUtil, dc: DataConverter, object: any): Promise<any> {
272
+ return IdentifierConversion.getEntityCriteriaFromObject(transformMapFile, mapFileUtil, dc, object);
273
+ }
274
+
275
+ static async getItemCriteriaFromObject(transformMapFile: string, mapFileUtil: MapFileUtil, dc: DataConverter, object: any): Promise<any> {
276
+ const criteria = await IdentifierConversion.getEntityCriteriaFromObject(transformMapFile, mapFileUtil, dc, object);
277
+ const roles = (['LCSProduct', 'LCSMaterial'].includes(object.flexPLMObjectClass)) ? 'family' : 'color';
278
+ criteria['roles'] = roles;
279
+
280
+ return criteria;
281
+ }
282
+ }