@contrail/transform-data 1.0.12 → 1.0.14

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.
File without changes
@@ -0,0 +1,205 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ exports.mapping = {
4
+ typeConversion: {
5
+ vibe2flex: {
6
+ 'custom-entity': {
7
+ getMapKey: (entity) => {
8
+ const typePath = entity['typePath'];
9
+ let mapKey = '';
10
+ switch (typePath) {
11
+ case 'custom-entity:pack':
12
+ mapKey = 'packaging';
13
+ break;
14
+ case 'custom-entity:prefix':
15
+ mapKey = 'prefix';
16
+ break;
17
+ case 'custom-entity:catName':
18
+ mapKey = 'catName';
19
+ break;
20
+ case 'custom-entity:partnerOrg':
21
+ mapKey = 'partnerOrg';
22
+ break;
23
+ case 'custom-entity:catFamily':
24
+ mapKey = 'catFamily';
25
+ break;
26
+ case 'custom-entity:formName':
27
+ mapKey = 'formName';
28
+ break;
29
+ }
30
+ return mapKey;
31
+ }
32
+ }
33
+ }
34
+ },
35
+ LCSProduct: {
36
+ vibeOwningKeys: ['itemNumber', 'lifecycleStage'],
37
+ vibe2flex: {
38
+ getClass: () => 'LCSProduct',
39
+ getSoftType: (entity) => {
40
+ const prodType = entity['prodType'];
41
+ let val = '';
42
+ switch (prodType) {
43
+ case 'acc':
44
+ val = 'Product\\Accesories';
45
+ break;
46
+ case 'app':
47
+ val = 'Product\\Apparel';
48
+ break;
49
+ case 'eqp':
50
+ val = 'Product\\Equipment';
51
+ break;
52
+ case 'foot':
53
+ val = 'Product\\Footwear';
54
+ break;
55
+ }
56
+ return val;
57
+ },
58
+ transformOrder: [{ processor: 'REKEY', rekeyDelete: true, rekeyTransformersKey: 'rekey' }, { processor: 'VALUE_TRANSFORM', functionTransformersKey: 'valueTransform' }],
59
+ rekey: {
60
+ productName: 'name',
61
+ vibeIQIdentifier: 'itemNumber'
62
+ },
63
+ valueTransform: {
64
+ transformEx: (row) => {
65
+ return row['otherProp'] + 'xxx';
66
+ }
67
+ }
68
+ },
69
+ flex2vibe: {
70
+ getClass: () => 'item',
71
+ transformOrder: [{ processor: 'REKEY', rekeyDelete: true, rekeyTransformersKey: 'rekey' }],
72
+ rekey: {
73
+ itemNumber: 'vibeIQIdentifier',
74
+ name: 'productName',
75
+ }
76
+ }
77
+ },
78
+ LCSSKU: {
79
+ vibeOwningKeys: ['itemNumber', 'lifecycleStage'],
80
+ vibe2flex: {
81
+ getClass: () => 'LCSSKU',
82
+ getSoftType: (entity) => {
83
+ const prodType = entity['prodType'];
84
+ let val = '';
85
+ switch (prodType) {
86
+ case 'acc':
87
+ val = 'Product\\Accesories';
88
+ break;
89
+ case 'app':
90
+ val = 'Product\\Apparel';
91
+ break;
92
+ case 'eqp':
93
+ val = 'Product\\Equipment';
94
+ break;
95
+ case 'foot':
96
+ val = 'Product\\Footwear';
97
+ break;
98
+ }
99
+ return val;
100
+ },
101
+ transformOrder: [{ processor: 'REKEY', rekeyDelete: true, rekeyTransformersKey: 'rekey' }],
102
+ rekey: {
103
+ skuName: 'optionName',
104
+ vibeIQIdentifier: 'itemNumber'
105
+ }
106
+ },
107
+ flex2vibe: {
108
+ transformOrder: [{ processor: 'REKEY', rekeyDelete: true, rekeyTransformersKey: 'rekey' }],
109
+ rekey: {
110
+ itemNumber: 'vibeIQIdentifier',
111
+ optionName: 'skuName',
112
+ }
113
+ }
114
+ },
115
+ packaging: {
116
+ vibe2flex: {
117
+ transformOrder: [{ processor: 'REKEY', rekeyDelete: true, rekeyTransformersKey: 'rekey' }],
118
+ rekey: {
119
+ retailPackType: 'packType',
120
+ retailIntroDate: 'introDate'
121
+ },
122
+ getSoftType: () => 'Revisable Entity\\packaging',
123
+ getClass: () => 'LCSRevisableEntity'
124
+ },
125
+ flex2vibe: {
126
+ transformOrder: [{ processor: 'REKEY', rekeyDelete: true, rekeyTransformersKey: 'rekey' }],
127
+ rekey: {
128
+ packType: 'retailPackType',
129
+ introDate: 'retailIntroDate'
130
+ },
131
+ getClass: () => 'custom-entity',
132
+ getSoftType: () => 'custom-entity:pack',
133
+ }
134
+ },
135
+ prefix: {
136
+ vibe2flex: {
137
+ transformOrder: [{ processor: 'REKEY', rekeyDelete: true, rekeyTransformersKey: 'rekey' }],
138
+ rekey: {
139
+ retailOwner: 'owner',
140
+ retailIntroDate: 'introDate'
141
+ },
142
+ getSoftType: () => 'Revisable Entity\\prefix',
143
+ getClass: () => 'LCSRevisableEntity'
144
+ },
145
+ flex2vibe: {
146
+ transformOrder: [{ processor: 'REKEY', rekeyDelete: true, rekeyTransformersKey: 'rekey' }],
147
+ rekey: {
148
+ owner: 'retailOwner',
149
+ introDate: 'retailIntroDate'
150
+ },
151
+ getClass: () => 'custom-entity',
152
+ getSoftType: () => 'custom-entity:prefix',
153
+ }
154
+ },
155
+ catName: {
156
+ getIdentifierProperties: () => ['catName', 'catNumber'],
157
+ getInformationalProperties: () => ['longName'],
158
+ vibe2flex: {
159
+ transformOrder: [],
160
+ getSoftType: () => 'Revisable Entity\\catName',
161
+ getClass: () => 'LCSLast'
162
+ },
163
+ flex2vibe: {
164
+ transformOrder: [],
165
+ getClass: () => 'custom-entity',
166
+ getSoftType: () => 'custom-entity:catName',
167
+ }
168
+ },
169
+ partnerOrg: {
170
+ vibe2flex: {
171
+ transformOrder: [],
172
+ getSoftType: () => 'Business Object\\partnerOrg',
173
+ getClass: () => 'LCSLifecycleManaged'
174
+ },
175
+ flex2vibe: {
176
+ transformOrder: [],
177
+ getClass: () => 'custom-entity',
178
+ getSoftType: () => 'custom-entity:partnerOrg',
179
+ }
180
+ },
181
+ catFamily: {
182
+ vibe2flex: {
183
+ transformOrder: [],
184
+ getSoftType: () => 'Revisable Entity\\catFamily',
185
+ getClass: () => 'LCSRevisableEntity'
186
+ },
187
+ flex2vibe: {
188
+ transformOrder: [],
189
+ getClass: () => 'custom-entity',
190
+ getSoftType: () => 'custom-entity:catFamily',
191
+ }
192
+ },
193
+ formName: {
194
+ vibe2flex: {
195
+ transformOrder: [],
196
+ getSoftType: () => 'Material\\form',
197
+ getClass: () => 'LCSMaterial'
198
+ },
199
+ flex2vibe: {
200
+ transformOrder: [],
201
+ getClass: () => 'custom-entity',
202
+ getSoftType: () => 'custom-entity:formName',
203
+ }
204
+ },
205
+ };
@@ -6,7 +6,10 @@ export declare class MapFileUtil {
6
6
  static ERROR_RETRIEVING: string;
7
7
  constructor(entities: any);
8
8
  getMapFile(fileId: string): Promise<any>;
9
- getMappingSectionFromMap(mapFile: any, objectClass: string, direction: string): {};
10
- getMappingSection(fileId: string, objectClass: string, direction: string): Promise<{}>;
11
- static getTransformTasks(mapSection: object): TransformTask[];
9
+ getMappingSectionFromMap(mapFile: any, mapSectionKey: string, direction: string): {};
10
+ getFullMapSection(transformMapFile: string, mapSectionKey: string): Promise<any>;
11
+ getMappingSection(fileId: string, mapSectionKey: string, direction: string): Promise<{}>;
12
+ getMapKey(fileId: any, data: any, type: string, direction: string): Promise<string>;
13
+ static getTransformTasks(directionalMapSection: object): TransformTask[];
14
+ applyTransformMap(fileId: any, data: any, mapSectionKey: string, direction: string): Promise<any>;
12
15
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MapFileUtil = void 0;
4
+ const processor_1 = require("../processor");
4
5
  class MapFileUtil {
5
6
  constructor(entities) {
6
7
  this.entities = entities;
@@ -41,24 +42,42 @@ class MapFileUtil {
41
42
  this.cache[fileId] = mappingFile;
42
43
  return mappingFile;
43
44
  }
44
- getMappingSectionFromMap(mapFile, objectClass, direction) {
45
+ getMappingSectionFromMap(mapFile, mapSectionKey, direction) {
45
46
  let mapping = {};
46
- if (mapFile[objectClass]) {
47
- const classMapping = mapFile[objectClass];
47
+ if (mapFile[mapSectionKey]) {
48
+ const classMapping = mapFile[mapSectionKey];
48
49
  if (classMapping[direction]) {
49
50
  mapping = classMapping[direction];
50
51
  }
51
52
  }
52
53
  return mapping;
53
54
  }
54
- async getMappingSection(fileId, objectClass, direction) {
55
+ async getFullMapSection(transformMapFile, mapSectionKey) {
56
+ if (mapSectionKey) {
57
+ const mapFile = await this.getMapFile(transformMapFile);
58
+ if (mapFile) {
59
+ const mapSection = mapFile[mapSectionKey];
60
+ return mapSection;
61
+ }
62
+ }
63
+ return undefined;
64
+ }
65
+ async getMappingSection(fileId, mapSectionKey, direction) {
55
66
  const map = await this.getMapFile(fileId);
56
- const mapSection = this.getMappingSectionFromMap(map, objectClass, direction);
57
- return mapSection;
67
+ const directional = this.getMappingSectionFromMap(map, mapSectionKey, direction);
68
+ return directional;
69
+ }
70
+ async getMapKey(fileId, data, type, direction) {
71
+ const mappingData = await this.getMappingSection(fileId, 'typeConversion', direction);
72
+ if (mappingData && mappingData[type] && mappingData[type]['getMapKey']) {
73
+ const mapKey = await mappingData[type]['getMapKey'](data);
74
+ return mapKey;
75
+ }
76
+ return undefined;
58
77
  }
59
- static getTransformTasks(mapSection) {
78
+ static getTransformTasks(directionalMapSection) {
60
79
  const tasks = [];
61
- const order = mapSection['transformOrder'];
80
+ const order = directionalMapSection['transformOrder'];
62
81
  if (order) {
63
82
  for (const step of order) {
64
83
  const task = {
@@ -69,7 +88,7 @@ class MapFileUtil {
69
88
  for (const mapping of ['conditionalTransformDefinitions', 'functionTransformers', 'rekeyTransformers', 'removeKeys']) {
70
89
  const mapKey = step[mapping + 'Key'];
71
90
  if (mapKey) {
72
- task[mapping] = mapSection[mapKey];
91
+ task[mapping] = directionalMapSection[mapKey];
73
92
  }
74
93
  }
75
94
  tasks.push(task);
@@ -77,6 +96,19 @@ class MapFileUtil {
77
96
  }
78
97
  return tasks;
79
98
  }
99
+ async applyTransformMap(fileId, data, mapSectionKey, direction) {
100
+ if (fileId && data) {
101
+ const mapping = await this.getMappingSection(fileId, mapSectionKey, direction);
102
+ if (mapping) {
103
+ const tasks = MapFileUtil.getTransformTasks(mapping);
104
+ if (tasks.length > 0) {
105
+ const convertedArray = processor_1.TransformProcessor.transformData([data], tasks);
106
+ data = convertedArray[0];
107
+ }
108
+ }
109
+ }
110
+ return data;
111
+ }
80
112
  }
81
113
  exports.MapFileUtil = MapFileUtil;
82
114
  MapFileUtil.FILE_NOT_FOUND = 'Mapping File not found for id: ';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/transform-data",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "Libraries for transforming data",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",