@contrail/flexplm 1.2.1 → 1.3.0-alpha.04c91a9

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 (125) hide show
  1. package/.github/pull_request_template.md +31 -31
  2. package/.github/workflows/flexplm-lib.yml +27 -27
  3. package/.github/workflows/publish-to-npm.yml +131 -0
  4. package/CHANGELOG.md +10 -0
  5. package/lib/entity-processor/base-entity-processor.d.ts +42 -42
  6. package/lib/entity-processor/base-entity-processor.js +385 -363
  7. package/lib/entity-processor/base-entity-processor.spec.d.ts +1 -1
  8. package/lib/entity-processor/base-entity-processor.spec.js +397 -302
  9. package/lib/flexplm-request.d.ts +3 -3
  10. package/lib/flexplm-request.js +34 -34
  11. package/lib/flexplm-utils.d.ts +5 -5
  12. package/lib/flexplm-utils.js +33 -33
  13. package/lib/flexplm-utils.spec.d.ts +1 -1
  14. package/lib/flexplm-utils.spec.js +26 -26
  15. package/lib/index.d.ts +22 -22
  16. package/lib/index.js +38 -38
  17. package/lib/interfaces/interfaces.d.ts +105 -105
  18. package/lib/interfaces/interfaces.js +2 -2
  19. package/lib/interfaces/item-family-changes.d.ts +20 -20
  20. package/lib/interfaces/item-family-changes.js +56 -56
  21. package/lib/interfaces/publish-change-data.d.ts +19 -19
  22. package/lib/interfaces/publish-change-data.js +32 -32
  23. package/lib/publish/base-process-publish-assortment-callback.d.ts +9 -9
  24. package/lib/publish/base-process-publish-assortment-callback.js +38 -38
  25. package/lib/publish/base-process-publish-assortment.d.ts +93 -93
  26. package/lib/publish/base-process-publish-assortment.js +944 -944
  27. package/lib/publish/base-process-publish-assortment.spec.d.ts +1 -1
  28. package/lib/publish/base-process-publish-assortment.spec.js +1670 -1670
  29. package/lib/publish/mockData.d.ts +1389 -1389
  30. package/lib/publish/mockData.js +4519 -4519
  31. package/lib/transform/identifier-conversion-spec-mockData.js +444 -444
  32. package/lib/transform/identifier-conversion.d.ts +15 -15
  33. package/lib/transform/identifier-conversion.js +212 -212
  34. package/lib/transform/identifier-conversion.spec.d.ts +1 -1
  35. package/lib/transform/identifier-conversion.spec.js +339 -339
  36. package/lib/util/config-defaults.d.ts +8 -8
  37. package/lib/util/config-defaults.js +85 -85
  38. package/lib/util/config-defaults.spec.d.ts +1 -1
  39. package/lib/util/config-defaults.spec.js +293 -293
  40. package/lib/util/data-converter-spec-mockData.js +205 -205
  41. package/lib/util/data-converter.d.ts +39 -39
  42. package/lib/util/data-converter.js +592 -592
  43. package/lib/util/data-converter.spec.d.ts +1 -1
  44. package/lib/util/data-converter.spec.js +904 -904
  45. package/lib/util/error-response-object.d.ts +4 -4
  46. package/lib/util/error-response-object.js +47 -47
  47. package/lib/util/error-response-object.spec.d.ts +1 -1
  48. package/lib/util/error-response-object.spec.js +99 -99
  49. package/lib/util/event-short-message-status.d.ts +19 -18
  50. package/lib/util/event-short-message-status.js +23 -22
  51. package/lib/util/federation.d.ts +15 -15
  52. package/lib/util/federation.js +149 -149
  53. package/lib/util/flexplm-connect.d.ts +22 -18
  54. package/lib/util/flexplm-connect.js +176 -171
  55. package/lib/util/flexplm-connect.spec.d.ts +1 -0
  56. package/lib/util/flexplm-connect.spec.js +88 -0
  57. package/lib/util/logger-config.d.ts +1 -1
  58. package/lib/util/logger-config.js +26 -26
  59. package/lib/util/map-util-spec-mockData.js +205 -205
  60. package/lib/util/map-utils.d.ts +6 -6
  61. package/lib/util/map-utils.js +15 -15
  62. package/lib/util/map-utils.spec.d.ts +1 -1
  63. package/lib/util/map-utils.spec.js +89 -89
  64. package/lib/util/mockData.d.ts +80 -79
  65. package/lib/util/mockData.js +103 -99
  66. package/lib/util/thumbnail-util.d.ts +34 -19
  67. package/lib/util/thumbnail-util.js +215 -114
  68. package/lib/util/thumbnail-util.spec.d.ts +1 -1
  69. package/lib/util/thumbnail-util.spec.js +434 -242
  70. package/lib/util/type-conversion-utils-spec-mockData.js +259 -241
  71. package/lib/util/type-conversion-utils.d.ts +23 -21
  72. package/lib/util/type-conversion-utils.js +265 -223
  73. package/lib/util/type-conversion-utils.spec.d.ts +1 -1
  74. package/lib/util/type-conversion-utils.spec.js +868 -708
  75. package/lib/util/type-defaults.d.ts +16 -16
  76. package/lib/util/type-defaults.js +221 -221
  77. package/lib/util/type-defaults.spec.d.ts +1 -1
  78. package/lib/util/type-defaults.spec.js +516 -516
  79. package/lib/util/type-utils.d.ts +13 -13
  80. package/lib/util/type-utils.js +114 -114
  81. package/lib/util/type-utils.spec.d.ts +1 -1
  82. package/lib/util/type-utils.spec.js +190 -190
  83. package/package.json +1 -1
  84. package/publish.bat +4 -4
  85. package/publish.sh +4 -4
  86. package/src/entity-processor/base-entity-processor.spec.ts +122 -0
  87. package/src/entity-processor/base-entity-processor.ts +31 -2
  88. package/src/flexplm-request.ts +28 -28
  89. package/src/flexplm-utils.spec.ts +27 -27
  90. package/src/flexplm-utils.ts +29 -29
  91. package/src/index.ts +21 -21
  92. package/src/interfaces/item-family-changes.ts +66 -66
  93. package/src/interfaces/publish-change-data.ts +42 -42
  94. package/src/publish/base-process-publish-assortment-callback.ts +50 -50
  95. package/src/transform/identifier-conversion-spec-mockData.ts +495 -495
  96. package/src/transform/identifier-conversion.spec.ts +353 -353
  97. package/src/transform/identifier-conversion.ts +281 -281
  98. package/src/util/config-defaults.spec.ts +350 -350
  99. package/src/util/config-defaults.ts +92 -92
  100. package/src/util/data-converter-spec-mockData.ts +230 -230
  101. package/src/util/error-response-object.spec.ts +115 -115
  102. package/src/util/error-response-object.ts +49 -49
  103. package/src/util/event-short-message-status.ts +1 -0
  104. package/src/util/federation.ts +172 -172
  105. package/src/util/flexplm-connect.spec.ts +132 -0
  106. package/src/util/flexplm-connect.ts +14 -5
  107. package/src/util/logger-config.ts +19 -19
  108. package/src/util/map-util-spec-mockData.ts +230 -230
  109. package/src/util/map-utils.spec.ts +102 -102
  110. package/src/util/map-utils.ts +40 -40
  111. package/src/util/mockData.ts +101 -97
  112. package/src/util/thumbnail-util.spec.ts +239 -0
  113. package/src/util/thumbnail-util.ts +140 -5
  114. package/src/util/type-conversion-utils-spec-mockData.ts +18 -0
  115. package/src/util/type-conversion-utils.spec.ts +184 -0
  116. package/src/util/type-conversion-utils.ts +75 -1
  117. package/src/util/type-defaults.spec.ts +668 -668
  118. package/src/util/type-defaults.ts +280 -280
  119. package/src/util/type-utils.spec.ts +227 -227
  120. package/src/util/type-utils.ts +144 -144
  121. package/tsconfig.json +23 -26
  122. package/tslint.json +57 -57
  123. package/.claude/settings.local.json +0 -8
  124. package/scripts/output.png +0 -0
  125. package/scripts/test-get-request.ts +0 -35
@@ -1,282 +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 = (object.flexPLMObjectClass === 'LCSProduct') ? 'family' : 'color';
278
- criteria['roles'] = roles;
279
-
280
- return criteria;
281
- }
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 = (object.flexPLMObjectClass === 'LCSProduct') ? 'family' : 'color';
278
+ criteria['roles'] = roles;
279
+
280
+ return criteria;
281
+ }
282
282
  }