@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,320 @@
1
+ export class TypeDefaults {
2
+ static NO_ENTITY_TYPE = 'Not able to determine the entity type of the entity object';
3
+ static NO_OBJECT_CLASS = 'Please ensure that the flexPLMObjectClass property is provided.';
4
+ static NO_TYPE_PATH = 'Please ensure that the flexPLMTypePath property is provided.';
5
+ static processLCSMaterialAsItem = false;
6
+ constructor() {
7
+ }
8
+
9
+ /** Applies values from the resolved config to TypeDefaults static state.
10
+ * Currently toggles whether LCSMaterial is treated as an item (new) or a
11
+ * custom-entity (old) based on config.LCSMaterial.processAsItem.
12
+ * Technically this could cause side effects if different parts of the code
13
+ * expect different behavior, but in practice * @param config will be
14
+ * consistent across the app and this is simpler than passing this config
15
+ * through multiple layers of function calls.
16
+ */
17
+ static applyConfig(config: any): void {
18
+ TypeDefaults.processLCSMaterialAsItem = TypeDefaults.isPropertyTrue(config?.LCSMaterial?.processAsItem);
19
+ }
20
+
21
+ static isPropertyTrue(value: any): boolean {
22
+ return value === true || (typeof value === 'string' && value.toLowerCase() === 'true');
23
+ }
24
+ /**Takes in full entity and returs the default FlexPLM
25
+ * object class.
26
+ *
27
+ * @param entity
28
+ * @returns string
29
+ */
30
+ static getDefaultObjectClass(entity): string {
31
+ const entityType = this.getEntityType(entity);
32
+ let objectClass = '';
33
+ if ('item' === entityType) {
34
+ if (entity.roles.includes('family')) {
35
+ objectClass = 'LCSProduct';
36
+ } else if (entity.roles.includes('color')) {
37
+ objectClass = 'LCSSKU';
38
+ }
39
+ } else if ('project-item' === entityType) {
40
+ if (entity.roles.includes('family')) {
41
+ objectClass = 'LCSProductSeasonLink';
42
+ } else if (entity.roles.includes('color')) {
43
+ objectClass = 'LCSSKUSeasonLink';
44
+ }
45
+ } else if ('color' === entityType) {
46
+ objectClass = 'LCSColor';
47
+ } else if ('custom-entity' === entityType) {
48
+ objectClass = 'LCSRevisableEntity';
49
+ } else if ('project' === entityType) {
50
+ objectClass = 'LCSSeason';
51
+ } else if ('assortment' === entityType) {
52
+ if('LCSSeason' === entity.flex2vibeMapKeyRoot || entity.publishToFlexPLM){
53
+ objectClass = 'LCSSeason';
54
+ }else{
55
+ objectClass = 'SeasonGroup';
56
+ }
57
+ }
58
+ return objectClass;
59
+
60
+ }
61
+
62
+ /**Takes in full entity and returns the default FlexPLM type path
63
+ * object class.
64
+ *
65
+ * @param entity
66
+ * @returns string
67
+ */
68
+ static getDefaultObjectTypePath(entity): string {
69
+ let typePath = '';
70
+ const entityType = this.getEntityType(entity);
71
+
72
+ switch (entityType) {
73
+ case 'item':
74
+ case 'project-item':
75
+ typePath = 'Product';
76
+ break;
77
+ case 'color':
78
+ typePath = 'Color';
79
+ break;
80
+ case 'custom-entity':
81
+ typePath = 'Revisable Entity';
82
+ break;
83
+ case 'project':
84
+ typePath = 'Season';
85
+ break;
86
+ case 'assortment':
87
+ if('LCSSeason' === entity.flex2vibeMapKeyRoot || entity.publishToFlexPLM){
88
+ typePath = 'Season';
89
+ }else{
90
+ typePath = 'Season Group';
91
+ }
92
+ break;
93
+ }
94
+
95
+ return typePath;
96
+ }
97
+
98
+ /**Takes in full entity and returns the slugs for the default identifier
99
+ * properties. These properties are used when searching for an entity
100
+ * object class.
101
+ *
102
+ * @param entity
103
+ * @returns string[]
104
+ */
105
+
106
+ static getDefaultIdentifierProperties(entity): string[] {
107
+ const identifierProps: string[] = [];
108
+ const entityType = this.getEntityType(entity);
109
+
110
+ switch (entityType) {
111
+ case 'item':
112
+ identifierProps.push('itemNumber');
113
+ break;
114
+ case 'project':
115
+ identifierProps.push('flexPLMSeasonName');
116
+ break;
117
+ case 'assortment':
118
+ if('LCSSeason' === entity.flex2vibeMapKeyRoot ||entity.publishToFlexPLM){
119
+ identifierProps.push('flexPLMSeasonName');
120
+ }else{
121
+ identifierProps.push('seasonGroupName');
122
+ }
123
+ break;
124
+ case 'color':
125
+ case 'custom-entity':
126
+ identifierProps.push('name');
127
+ break;
128
+ }
129
+
130
+ return identifierProps;
131
+ }
132
+
133
+ /** Takes in full entity and returns the slugs for informational
134
+ * properties. These properties are helpful when debugging issues
135
+ * where the identifier properties don't find a match.
136
+ *
137
+ * @param entity
138
+ * @returns string[]
139
+ */
140
+ static getDefaultInformationalProperties(entity): string[] {
141
+ const entityType = this.getEntityType(entity);
142
+ let properties:string[] = [];
143
+ if ('item' === entityType) {
144
+ if (entity.roles.includes('family')) {
145
+ properties.push('name');
146
+ } else if (entity.roles.includes('color')) {
147
+ properties.push('optionName');
148
+ }
149
+ } else if (['project', 'assortment'].includes(entityType)) {
150
+ properties.push('name');
151
+ }
152
+ return properties;
153
+
154
+ }
155
+
156
+ /** Returns the VibeIQ entity type from an entity.
157
+ * Throws error if it can't determine the entity type
158
+ *
159
+ * @param entity
160
+ * @returns string
161
+ */
162
+ static getEntityType(entity: any) {
163
+ let entityType = entity['entityType'];
164
+ if (!entityType) {
165
+ const typePath: string = entity['typePath'];
166
+ if (typePath) {
167
+ const types = typePath.split(':');
168
+ if (types && types[0]) {
169
+ entityType = types[0];
170
+ }
171
+ }
172
+ }
173
+ if (!entityType) {
174
+ throw Error(TypeDefaults.NO_ENTITY_TYPE);
175
+ }
176
+ return entityType;
177
+ }
178
+
179
+ /**Takes in full object and returns the default VibeIQ
180
+ * entity class.
181
+ *
182
+ * @param entity
183
+ * @returns string
184
+ */
185
+ static getDefaultEntityClass(object): string {
186
+ let entityClass = '';
187
+ let objectClass = TypeDefaults.getObjectClass(object);
188
+ const itemClasses = TypeDefaults.processLCSMaterialAsItem
189
+ ? ['LCSProduct', 'LCSSKU', 'LCSMaterial']
190
+ : ['LCSProduct', 'LCSSKU'];
191
+ const customEntityClasses = TypeDefaults.processLCSMaterialAsItem
192
+ ? ['LCSRevisableEntity', 'LCSLifecycleManaged', 'LCSLast']
193
+ : ['LCSRevisableEntity', 'LCSLifecycleManaged', 'LCSLast', 'LCSMaterial'];
194
+
195
+ if(itemClasses.includes(objectClass)){
196
+ entityClass = 'item';
197
+ }else if(['LCSProductSeasonLink', 'LCSSKUSeasonLink'].includes(objectClass)){
198
+ entityClass = 'project-item'
199
+ } else if('LCSColor' === objectClass){
200
+ entityClass = 'color';
201
+ } else if(['LCSSeason', 'SeasonGroup'].includes(objectClass)) {
202
+ entityClass = 'assortment';
203
+ } else if(customEntityClasses.includes(objectClass)) {
204
+ entityClass = 'custom-entity';
205
+ }
206
+
207
+ if(entityClass === '')
208
+ throw Error(TypeDefaults.NO_OBJECT_CLASS);
209
+
210
+ return entityClass;
211
+ }
212
+
213
+ /**Takes in full object and returns the default VibeIQ type path
214
+ * object class.
215
+ *
216
+ * @param object
217
+ * @returns string
218
+ */
219
+ static getDefaultEntityTypePath(object): string {
220
+ let typePath = '';
221
+ const objectClass = TypeDefaults.getObjectClass(object);
222
+
223
+ switch (objectClass) {
224
+ case 'LCSProduct':
225
+ case 'LCSSKU':
226
+ typePath = 'item';
227
+ break;
228
+ case 'LCSMaterial':
229
+ if (TypeDefaults.processLCSMaterialAsItem) {
230
+ typePath = 'item:material';
231
+ }
232
+ break;
233
+ case 'LCSProductSeasonLink':
234
+ case 'LCSSKUSeasonLink':
235
+ typePath = 'project-item';
236
+ break;
237
+ case 'LCSColor':
238
+ typePath = 'color';
239
+ break;
240
+ case 'LCSSeason':
241
+ case 'SeasonGroup':
242
+ typePath = 'assortment';
243
+ break;
244
+ }
245
+
246
+ if(typePath === '')
247
+ throw Error(TypeDefaults.NO_TYPE_PATH);
248
+
249
+ return typePath;
250
+ }
251
+
252
+ /**Takes in full entity and returns the slugs for the default identifier
253
+ * properties. These properties are used when searching for an entity
254
+ * object class.
255
+ *
256
+ * @param entity
257
+ * @returns string[]
258
+ */
259
+
260
+ static getDefaultIdentifierPropertiesFromObject(object): string[] {
261
+ const identifierProps: string[] = [];
262
+ const objectClass = TypeDefaults.getObjectClass(object);
263
+
264
+ switch (objectClass) {
265
+ case 'LCSProduct':
266
+ case 'LCSSKU':
267
+ identifierProps.push('itemNumber');
268
+ break;
269
+ case 'LCSMaterial':
270
+ if (TypeDefaults.processLCSMaterialAsItem) {
271
+ identifierProps.push('itemNumber');
272
+ } else {
273
+ identifierProps.push('name');
274
+ }
275
+ break;
276
+ case 'LCSSeason':
277
+ identifierProps.push('flexPLMSeasonName');
278
+ break;
279
+ case 'SeasonGroup':
280
+ identifierProps.push('seasonGroupName');
281
+ break;
282
+ case 'LCSColor':
283
+ case 'LCSRevisableEntity':
284
+ case 'LCSLifecycleManaged':
285
+ case 'LCSLast':
286
+ identifierProps.push('name');
287
+ break;
288
+ }
289
+
290
+ return identifierProps;
291
+ }
292
+
293
+ /** Takes in full object and returns the slugs for informational
294
+ * properties. These properties are helpful when debugging issues
295
+ * where the identifier properties don't find a match.
296
+ *
297
+ * @param object
298
+ * @returns string[]
299
+ */
300
+ static getDefaultInformationalPropertiesFromObject(object): string[] {
301
+ const objectClass = TypeDefaults.getObjectClass(object);
302
+ let properties:string[] = [];
303
+ const itemClasses = TypeDefaults.processLCSMaterialAsItem
304
+ ? ['LCSProduct', 'LCSMaterial']
305
+ : ['LCSProduct'];
306
+
307
+ if (itemClasses.includes(objectClass)) {
308
+ properties.push('name');
309
+ } else if ('LCSSKU' === objectClass) {
310
+ properties.push('optionName');
311
+ } else if (['LCSSeason', 'SeasonGroup'].includes(objectClass)) {
312
+ properties.push('name');
313
+ }
314
+ return properties;
315
+ }
316
+
317
+ static getObjectClass(object: any): string {
318
+ return (object)? object['flexPLMObjectClass']: '';
319
+ }
320
+ }
@@ -0,0 +1,227 @@
1
+ import { TypeUtils } from './type-utils';
2
+
3
+ describe('TypeUtils.getEventObjectClass() tests', () =>{
4
+
5
+ const tu = new TypeUtils();
6
+
7
+ it('LCSProduct', () =>{
8
+ const entityType = 'item';
9
+ const newData = {
10
+ roles: ['family']
11
+ };
12
+
13
+ const objectClass = tu.getEventObjectClass(entityType, newData);
14
+
15
+ expect(objectClass).toEqual('LCSProduct');
16
+ });
17
+
18
+ it('LCSSKU', () =>{
19
+ const entityType = 'item';
20
+ const newData = {
21
+ roles: ['color']
22
+ };
23
+
24
+ const objectClass = tu.getEventObjectClass(entityType, newData);
25
+
26
+ expect(objectClass).toEqual('LCSSKU');
27
+ });
28
+
29
+ it('LCSProductSeasonLink', () =>{
30
+ const entityType = 'project-item';
31
+ const newData = {
32
+ roles: ['family']
33
+ };
34
+
35
+ const objectClass = tu.getEventObjectClass(entityType, newData);
36
+
37
+ expect(objectClass).toEqual('LCSProductSeasonLink');
38
+ });
39
+
40
+ it('LCSSKUSeasonLink', () =>{
41
+ const entityType = 'project-item';
42
+ const newData = {
43
+ roles: ['color']
44
+ };
45
+
46
+ const objectClass = tu.getEventObjectClass(entityType, newData);
47
+
48
+ expect(objectClass).toEqual('LCSSKUSeasonLink');
49
+ });
50
+ it('LCSColor', () =>{
51
+ const entityType = 'color';
52
+ const newData = {};
53
+
54
+ const objectClass = tu.getEventObjectClass(entityType, newData);
55
+
56
+ expect(objectClass).toEqual('LCSColor');
57
+ });
58
+
59
+ it('LCSRevisableEntity', () =>{
60
+ const entityType = 'custom-entity';
61
+ const newData = {};
62
+
63
+ const objectClass = tu.getEventObjectClass(entityType, newData);
64
+
65
+ expect(objectClass).toEqual('LCSRevisableEntity');
66
+ });
67
+
68
+ });
69
+ describe('filterProperties-item', () => {
70
+
71
+ const itemType = {
72
+ typePath: 'item'
73
+ };
74
+ itemType['typeProperties'] = [
75
+ {
76
+ id: 'H4NazLloHdUVhc71',
77
+ slug: 'null',
78
+ propertyLevel: null
79
+ },
80
+ {
81
+ id: 'H4NazLloHdUVhc71',
82
+ slug: 'family',
83
+ propertyLevel: 'family'
84
+ },
85
+ {
86
+ id: 'H4NazLloHdUVhc71',
87
+ slug: 'option',
88
+ propertyLevel: 'option'
89
+ },
90
+ {
91
+ id: 'H4NazLloHdUVhc71',
92
+ slug: 'overridable',
93
+ propertyLevel: 'overridable'
94
+ },
95
+ {
96
+ id: 'H4NazLloHdUVhc71',
97
+ slug: 'all',
98
+ propertyLevel: 'all'
99
+ },
100
+ ];
101
+ const tu = new TypeUtils();
102
+
103
+ it('item-family', () =>{
104
+ const len = 4;
105
+ const newData = {
106
+ roles: ['family']
107
+ };
108
+
109
+ const filteredProps = tu.filterTypeProperties(itemType, newData);
110
+ expect(filteredProps.length).toEqual(len);
111
+ });
112
+
113
+ it('item-option', () =>{
114
+ const len = 4;
115
+ const newData = {
116
+ roles: ['option']
117
+ };
118
+
119
+ const filteredProps = tu.filterTypeProperties(itemType, newData);
120
+ expect(filteredProps.length).toEqual(len);
121
+ });
122
+
123
+ it('item-no-roles', () =>{
124
+ const len = 5;
125
+ const newData = {
126
+ };
127
+
128
+ const filteredProps = tu.filterTypeProperties(itemType, newData);
129
+ expect(filteredProps.length).toEqual(len);
130
+ });
131
+ });
132
+
133
+ //project-item
134
+ describe('filterProperties-project-item', () => {
135
+
136
+ const projectItemType = {
137
+ typePath: 'project-item'
138
+ };
139
+ projectItemType['typeProperties'] = [
140
+ {
141
+ id: 'H4NazLloHdUVhc71',
142
+ slug: 'null',
143
+ propertyLevel: null
144
+ },
145
+ {
146
+ id: 'H4NazLloHdUVhc71',
147
+ slug: 'family',
148
+ propertyLevel: 'family'
149
+ },
150
+ {
151
+ id: 'H4NazLloHdUVhc71',
152
+ slug: 'option',
153
+ propertyLevel: 'option'
154
+ },
155
+ {
156
+ id: 'H4NazLloHdUVhc71',
157
+ slug: 'overridable',
158
+ propertyLevel: 'overridable'
159
+ },
160
+ {
161
+ id: 'H4NazLloHdUVhc71',
162
+ slug: 'all',
163
+ propertyLevel: 'all'
164
+ },
165
+ ];
166
+ const tu = new TypeUtils();
167
+
168
+ it('item-family', () =>{
169
+ const len = 4;
170
+ const newData = {
171
+ roles: ['family']
172
+ };
173
+
174
+ const filteredProps = tu.filterTypeProperties(projectItemType, newData);
175
+ expect(filteredProps.length).toEqual(len);
176
+ });
177
+
178
+ it('item-option', () =>{
179
+ const len = 4;
180
+ const newData = {
181
+ roles: ['option']
182
+ };
183
+
184
+ const filteredProps = tu.filterTypeProperties(projectItemType, newData);
185
+ expect(filteredProps.length).toEqual(len);
186
+ });
187
+ });
188
+
189
+ //color
190
+ describe('filterProperties-color', () => {
191
+ const colorType = {
192
+ typePath: 'color'
193
+ };
194
+ colorType['typeProperties'] = [
195
+ {
196
+ id: 'H4NazLloHdUVhc71',
197
+ slug: 'null',
198
+ },
199
+ {
200
+ id: 'H4NazLloHdUVhc71',
201
+ slug: 'family',
202
+ },
203
+ {
204
+ id: 'H4NazLloHdUVhc71',
205
+ slug: 'option',
206
+ },
207
+ {
208
+ id: 'H4NazLloHdUVhc71',
209
+ slug: 'overridable',
210
+ },
211
+ {
212
+ id: 'H4NazLloHdUVhc71',
213
+ slug: 'all',
214
+ },
215
+ ];
216
+ const tu = new TypeUtils();
217
+
218
+ it('color', () =>{
219
+ const len = 5;
220
+ const newData = {
221
+ roles: ['family']
222
+ };
223
+
224
+ const filteredProps = tu.filterTypeProperties(colorType, newData);
225
+ expect(filteredProps.length).toEqual(len);
226
+ });
227
+ });
@@ -0,0 +1,144 @@
1
+ import { Logger } from '@contrail/app-framework';
2
+ import { TypeClientOptions, Types } from '@contrail/sdk';
3
+ import { TypeProperty } from '@contrail/types';
4
+ import { TypeConversionUtils } from './type-conversion-utils';
5
+
6
+ export class TypeUtils {
7
+ private typesObj: Types;
8
+ constructor() {
9
+ this.typesObj = new Types();
10
+ }
11
+
12
+ async getTypeById(id) {
13
+ // this.logger.log('!-getTypeById: ' + id);
14
+ const type = await this.typesObj.getType({
15
+ id,
16
+ relations: ['typeProperties', 'typeInterfaces']
17
+ });
18
+ return type;
19
+ }
20
+
21
+ async getByRootAndPath(options: TypeClientOptions) {
22
+ const type = await this.typesObj.getByRootAndPath(options);
23
+ return type;
24
+ }
25
+
26
+ /** Deprecated: use TypeConversionUtils.getObjectTypePath() */
27
+ static getFlexPLMTypePath(entity) {
28
+ return entity['flexPLMTypePath'] || entity['flexTypePath'] || '';
29
+ }
30
+
31
+ /** Deprecated: use TypeConversionUtils.getObjectClass()
32
+ *
33
+ * @param entityType
34
+ * @param newData
35
+ * @returns
36
+ */
37
+ getEventObjectClass(entityType: string, newData): string {
38
+ let objectClass = '';
39
+ if ('item' === entityType) {
40
+ if (newData.roles.includes('family')) {
41
+ objectClass = 'LCSProduct';
42
+ } else if (newData.roles.includes('color')) {
43
+ objectClass = 'LCSSKU';
44
+ }
45
+ } else if ('project-item' === entityType) {
46
+ if (newData.roles.includes('family')) {
47
+ objectClass = 'LCSProductSeasonLink';
48
+ } else if (newData.roles.includes('color')) {
49
+ objectClass = 'LCSSKUSeasonLink';
50
+ }
51
+ } else if ('color' === entityType) {
52
+ objectClass = 'LCSColor';
53
+ } else if ('custom-entity' === entityType) {
54
+ objectClass = 'LCSRevisableEntity';
55
+
56
+ }
57
+ return objectClass;
58
+ }
59
+
60
+ /** Gets the VibeIQ entity type for the object data
61
+ * @param data: object data
62
+ */
63
+ async getEntityTypeClientOptionsUsingMapping(transformMapFile, mapFileUtil, data): Promise<TypeClientOptions> {
64
+ const root = await TypeConversionUtils.getEntityClassFromObject(transformMapFile, mapFileUtil, data);
65
+ const path = await TypeConversionUtils.getEntityTypePathFromOjbect(transformMapFile, mapFileUtil, data);
66
+
67
+ let tco: TypeClientOptions = {
68
+ root,
69
+ path
70
+ };
71
+
72
+
73
+
74
+ return tco;
75
+ }
76
+
77
+ /** Gets the VibeIQ entity type for the object data
78
+ * @param objectClass: string object class
79
+ * @param data: object data
80
+ */
81
+ getEntityTypeClientOptions(objectClass: string, data): TypeClientOptions {
82
+ let tco: TypeClientOptions;
83
+ if (['LCSProduct', 'LCSSKU'].includes(objectClass)) {
84
+ tco = {
85
+ root: 'item'
86
+ };
87
+ } else if ('LCSSeason' === objectClass) {
88
+ tco = {
89
+ root: 'assortment'
90
+ };
91
+ } else if ('LCSColor' === objectClass) {
92
+ tco = {
93
+ root: 'color'
94
+ };
95
+ } else if (['LCSBusinessObject', 'LCSRevisableEntity', 'LCSLast'].includes(objectClass)) {
96
+ //TODO need to write logic using mapping file
97
+ tco = {
98
+ root: 'custom-entity'
99
+ };
100
+ console.log('data: ' + data);
101
+ }
102
+
103
+ return tco;
104
+ }
105
+ /** This will filter the properties based the newData entity.
106
+ * It is assumed the type is correct for the entity
107
+ *
108
+ * @param type entire type object
109
+ * @param newData the entity being processed
110
+ * @returns TypeProperty[] of applicable properties
111
+ */
112
+ filterTypeProperties(type, newData): TypeProperty[] {
113
+ let filteredProps: TypeProperty[] = type['typeProperties'];
114
+ const typePath = type['typePath'];
115
+ const roles = newData['roles'];
116
+ if (typePath && (typePath.startsWith('item') || typePath.startsWith('project-item'))) {
117
+ if (Logger.isDebugOn()) {
118
+ console.debug('filterTypeProperties():id: ' +newData?.id
119
+ + ', typePath: ' + typePath
120
+ + ', newData.roles: ' + newData?.roles);
121
+ }
122
+ if (roles) {
123
+ const isFamily = roles.includes('family');
124
+ if (Logger.isDebugOn()) {
125
+ console.debug('isFamily: ' + isFamily);
126
+ }
127
+
128
+ filteredProps = filteredProps.filter(prop => {
129
+ const propertyLevel = prop.propertyLevel;
130
+ const applies =
131
+ (isFamily && 'option' != propertyLevel) ||
132
+ (!isFamily && 'family' != propertyLevel);
133
+ return applies;
134
+ });
135
+
136
+ } else {
137
+ console.error('filterTypeProperties():Entity missing role-id: ' + newData['id']);
138
+ }
139
+ }
140
+
141
+ return filteredProps;
142
+ }
143
+
144
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2020",
4
+ "module": "commonjs",
5
+ "declaration": true,
6
+ "rootDir": "./src",
7
+ "outDir": "./lib",
8
+ "types": ["jest", "node"],
9
+ "experimentalDecorators": true,
10
+ "esModuleInterop": true,
11
+ "strictPropertyInitialization": false,
12
+ "noImplicitAny": false,
13
+ "allowSyntheticDefaultImports": true,
14
+ "emitDecoratorMetadata": true,
15
+ "removeComments": true,
16
+ "skipLibCheck": true,
17
+ "lib": [
18
+ "ES2020",
19
+ "dom",
20
+ ],
21
+ },
22
+ "include": ["src"],
23
+ "exclude": ["node_modules", "**/__tests__/*"]
24
+ }