@contrail/flexplm 1.1.13 → 1.1.15
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.
- package/.github/pull_request_template.md +30 -0
- package/.github/workflows/flexplm-lib.yml +27 -0
- package/lib/flexplm-utils.spec.d.ts +1 -0
- package/lib/flexplm-utils.spec.js +26 -0
- package/lib/publish/base-process-publish-assortment.spec.d.ts +1 -0
- package/lib/publish/base-process-publish-assortment.spec.js +1053 -0
- package/lib/util/config-defaults.spec.d.ts +1 -0
- package/lib/util/config-defaults.spec.js +264 -0
- package/lib/util/data-converter.d.ts +4 -0
- package/lib/util/data-converter.js +88 -1
- package/lib/util/data-converter.spec.d.ts +1 -0
- package/lib/util/data-converter.spec.js +591 -0
- package/lib/util/map-utils.d.ts +2 -2
- package/lib/util/map-utils.js +5 -28
- package/lib/util/map-utils.spec.d.ts +1 -0
- package/lib/util/map-utils.spec.js +89 -0
- package/lib/util/thumbnail-util.spec.d.ts +1 -0
- package/lib/util/thumbnail-util.spec.js +132 -0
- package/lib/util/type-conversion-utils-spec-mockData.js +21 -0
- package/lib/util/type-conversion-utils.d.ts +7 -0
- package/lib/util/type-conversion-utils.js +88 -4
- package/lib/util/type-conversion-utils.spec.d.ts +1 -0
- package/lib/util/type-conversion-utils.spec.js +547 -0
- package/lib/util/type-defaults.d.ts +5 -0
- package/lib/util/type-defaults.js +66 -0
- package/lib/util/type-defaults.spec.d.ts +1 -0
- package/lib/util/type-defaults.spec.js +460 -0
- package/lib/util/type-utils.spec.d.ts +1 -0
- package/lib/util/type-utils.spec.js +190 -0
- package/package.json +2 -2
- package/publish.bat +5 -0
- package/publish.sh +5 -0
- package/src/entity-processor/base-entity-processor.ts +183 -0
- package/src/flexplm-request.ts +28 -0
- package/src/flexplm-utils.spec.ts +27 -0
- package/src/flexplm-utils.ts +29 -0
- package/src/index.ts +20 -0
- package/src/interfaces/interfaces.ts +120 -0
- package/src/interfaces/item-family-changes.ts +67 -0
- package/src/interfaces/publish-change-data.ts +43 -0
- package/src/publish/base-process-publish-assortment-callback.ts +23 -0
- package/src/publish/base-process-publish-assortment.spec.ts +1239 -0
- package/src/publish/base-process-publish-assortment.ts +1024 -0
- package/src/publish/mockData.ts +4561 -0
- package/src/transform/identifier-conversion.ts +226 -0
- package/src/util/config-defaults.spec.ts +315 -0
- package/src/util/config-defaults.ts +79 -0
- package/src/util/data-converter-spec-mockData.ts +231 -0
- package/src/util/data-converter.spec.ts +872 -0
- package/src/util/data-converter.ts +507 -0
- package/src/util/federation.ts +172 -0
- package/src/util/flexplm-connect.ts +169 -0
- package/src/util/logger-config.ts +20 -0
- package/src/util/map-util-spec-mockData.ts +231 -0
- package/src/util/map-utils.spec.ts +103 -0
- package/src/util/map-utils.ts +40 -0
- package/src/util/mockData.ts +98 -0
- package/src/util/thumbnail-util.spec.ts +152 -0
- package/src/util/thumbnail-util.ts +128 -0
- package/src/util/type-conversion-utils-spec-mockData.ts +238 -0
- package/src/util/type-conversion-utils.spec.ts +601 -0
- package/src/util/type-conversion-utils.ts +345 -0
- package/src/util/type-defaults.spec.ts +592 -0
- package/src/util/type-defaults.ts +261 -0
- package/src/util/type-utils.spec.ts +227 -0
- package/src/util/type-utils.ts +124 -0
- package/tsconfig.json +27 -0
- package/tslint.json +57 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { Logger } from '@contrail/app-framework';
|
|
2
|
+
import { FCConfig, FlexPLMResponseData, PayloadType } from '../interfaces/interfaces';
|
|
3
|
+
|
|
4
|
+
export class FlexPLMConnect {
|
|
5
|
+
private config: FCConfig;
|
|
6
|
+
private vibeEventEndpoint = '';
|
|
7
|
+
private staticHeaders = undefined;
|
|
8
|
+
public payloadSendAsArray = true;
|
|
9
|
+
constructor(_config: FCConfig, endPoint = undefined, payloadAsArray = undefined) {
|
|
10
|
+
this.config = _config;
|
|
11
|
+
this.vibeEventEndpoint = (endPoint)
|
|
12
|
+
? endPoint
|
|
13
|
+
: this.config.vibeEventEndpoint;
|
|
14
|
+
this.payloadSendAsArray = (payloadAsArray != undefined)
|
|
15
|
+
? payloadAsArray
|
|
16
|
+
: this.config['payloadDefaultAsArray'];
|
|
17
|
+
if(this.config?.flexplmConnect?.staticHeaders){
|
|
18
|
+
this.staticHeaders = this.config?.flexplmConnect?.staticHeaders;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
///////// Custom getRequestOptions: start
|
|
24
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
25
|
+
private getRequestOptions(method: string) {
|
|
26
|
+
const csrfOptions = {
|
|
27
|
+
method,
|
|
28
|
+
headers: {
|
|
29
|
+
'Content-Type': 'application/json',
|
|
30
|
+
PLM_ENV: this.config.plmEnviornment,
|
|
31
|
+
Authorization: 'Basic ' + Buffer.from(`${this.config.userName()}:${this.config.password()}`, 'binary').toString('base64')
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
if(this.staticHeaders){
|
|
35
|
+
Object.assign(csrfOptions.headers, this.staticHeaders);
|
|
36
|
+
}
|
|
37
|
+
if(Logger.isInfoOn()){
|
|
38
|
+
const logOptions = JSON.parse(JSON.stringify(csrfOptions));
|
|
39
|
+
logOptions['headers']['Authorization'] = logOptions?.headers?.Authorization.substring(0, 9);
|
|
40
|
+
console.info('csrfOptions: ' + JSON.stringify(logOptions));
|
|
41
|
+
}
|
|
42
|
+
return csrfOptions;
|
|
43
|
+
}
|
|
44
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
45
|
+
///////// Custom getRequestOptions: end
|
|
46
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
47
|
+
|
|
48
|
+
async getCSRF() {
|
|
49
|
+
const urlContext = this.config.urlContext;
|
|
50
|
+
const csrfEndpoint = this.config.csrfEndpoint;
|
|
51
|
+
const csrfURL: string = this.config.apiHost + urlContext + csrfEndpoint;
|
|
52
|
+
console.info('csrfURL: ' + csrfURL);
|
|
53
|
+
|
|
54
|
+
const csrfOptions = this.getRequestOptions('GET');
|
|
55
|
+
|
|
56
|
+
const response = await fetch(csrfURL, csrfOptions);
|
|
57
|
+
if(response.status >= 300){
|
|
58
|
+
const message = 'Error connecting to FlexPLM:status: ' + response.status;
|
|
59
|
+
console.error(message);
|
|
60
|
+
console.error(await response.text());
|
|
61
|
+
throw new Error(message);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
try{
|
|
65
|
+
|
|
66
|
+
const body = await response.json();
|
|
67
|
+
|
|
68
|
+
const nonce_key = body.items[0].attributes.nonce_key;
|
|
69
|
+
const nonce = body.items[0].attributes.nonce;
|
|
70
|
+
console.info('nonce_key: ' + nonce_key);
|
|
71
|
+
console.info('nonce: ' + nonce);
|
|
72
|
+
return {
|
|
73
|
+
nonce_key,
|
|
74
|
+
nonce
|
|
75
|
+
};
|
|
76
|
+
}catch(e){
|
|
77
|
+
const message = 'Error connecting to FlexPLM: ' + e.message;
|
|
78
|
+
console.error(message);
|
|
79
|
+
console.error(await response.text());
|
|
80
|
+
throw new Error(message);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async sendRequest(csrf, payload) {
|
|
85
|
+
|
|
86
|
+
if(this.payloadSendAsArray && !Array.isArray(payload)){
|
|
87
|
+
payload = [payload];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const xferOptions = this.getRequestOptions('POST');
|
|
91
|
+
|
|
92
|
+
xferOptions['body'] = JSON.stringify(payload);
|
|
93
|
+
xferOptions.headers[csrf.nonce_key] = csrf.nonce;
|
|
94
|
+
|
|
95
|
+
const urlContext = this.config.urlContext;
|
|
96
|
+
const vibeEventsURL: string = this.config.apiHost + urlContext + '/servlet/rest' + this.vibeEventEndpoint;
|
|
97
|
+
|
|
98
|
+
if(Logger.isInfoOn()){
|
|
99
|
+
console.info('Request:');
|
|
100
|
+
console.info('vibeEventsURL: ' + vibeEventsURL);
|
|
101
|
+
const logOptions = JSON.parse(JSON.stringify(xferOptions));
|
|
102
|
+
logOptions['headers']['Authorization'] = logOptions?.headers?.Authorization.substring(0, 9);
|
|
103
|
+
console.info('csrfOptions: ' + JSON.stringify(logOptions));
|
|
104
|
+
console.info('Making call to xfer data to FlexPLM');
|
|
105
|
+
}
|
|
106
|
+
const eventResponse = await fetch(vibeEventsURL, xferOptions);
|
|
107
|
+
return eventResponse;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
protected async processRequest(payload:any){
|
|
111
|
+
if(!payload){
|
|
112
|
+
const message = 'No payload to send to FlexPLM';
|
|
113
|
+
console.error(message);
|
|
114
|
+
throw new Error(message);
|
|
115
|
+
}
|
|
116
|
+
if(Logger.isInfoOn()){
|
|
117
|
+
console.info('payload: ' + JSON.stringify(payload));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const csrf = await this.getCSRF();
|
|
121
|
+
if(!csrf){
|
|
122
|
+
const message = 'Failed to get CSRF nonce';
|
|
123
|
+
console.error(message);
|
|
124
|
+
throw new Error(message);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const response = await this.sendRequest(csrf, payload);
|
|
128
|
+
const status = response.status;
|
|
129
|
+
if(status >= 300){
|
|
130
|
+
const message = 'Error sending data to FlexPLM:status: ' + response.status;
|
|
131
|
+
console.error(message);
|
|
132
|
+
console.error(await response.text());
|
|
133
|
+
throw new Error(message);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
try{
|
|
137
|
+
const res: FlexPLMResponseData = {
|
|
138
|
+
status,
|
|
139
|
+
};
|
|
140
|
+
if(![204, 205].includes(status)){
|
|
141
|
+
try{
|
|
142
|
+
const data = await response.json();
|
|
143
|
+
res.data = data;
|
|
144
|
+
} catch(e){
|
|
145
|
+
console.error('Error getting response body. Setting {} body: ' + e);
|
|
146
|
+
res.data = {};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
console.log('eventResponse.status: ' + status);
|
|
151
|
+
// console.log('eventBody: ', JSON.stringify(data));
|
|
152
|
+
return res;
|
|
153
|
+
|
|
154
|
+
}catch(e){
|
|
155
|
+
const message = 'Error getting json data from FlexPLM: ' + e.message;
|
|
156
|
+
console.error(message);
|
|
157
|
+
console.error(await response.text());
|
|
158
|
+
throw new Error(message);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
}
|
|
162
|
+
async sendToFlexPLM( payload: PayloadType){
|
|
163
|
+
return await this.processRequest(payload);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async sendMultipleToFlexPLM(payload: PayloadType[]){
|
|
167
|
+
return await this.processRequest(payload);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { LogLevel, Logger } from '@contrail/app-framework';
|
|
2
|
+
|
|
3
|
+
export async function setLoggerConfig(appConfig) {
|
|
4
|
+
let logLevel: LogLevel = LogLevel.INFO;
|
|
5
|
+
if(!appConfig.logLevel) {
|
|
6
|
+
//pass
|
|
7
|
+
} else if (appConfig.logLevel === 'error') {
|
|
8
|
+
logLevel = LogLevel.ERROR;
|
|
9
|
+
} else if (appConfig.logLevel === 'warn') {
|
|
10
|
+
logLevel = LogLevel.WARN;
|
|
11
|
+
} else if (appConfig.logLevel === 'info') {
|
|
12
|
+
logLevel = LogLevel.INFO;
|
|
13
|
+
} else if (appConfig.logLevel === 'debug') {
|
|
14
|
+
logLevel = LogLevel.DEBUG;
|
|
15
|
+
} else {
|
|
16
|
+
console.log('could not parse log level:', appConfig);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
Logger.setConfig({logLevel: logLevel});
|
|
20
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
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
|
+
|
|
31
|
+
return mapKey;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// flex2vibe: {
|
|
36
|
+
// LCSRevisableEntity: {
|
|
37
|
+
// getMapKey: (object) =>{ return object;}
|
|
38
|
+
// },
|
|
39
|
+
// LCSLast: {
|
|
40
|
+
// getMapKey: (object) => {return object;}
|
|
41
|
+
// },
|
|
42
|
+
// LCSMaterial: {
|
|
43
|
+
// getMapKey: (object) =>{ return object;}
|
|
44
|
+
// },
|
|
45
|
+
// LCSBusinessObject: {
|
|
46
|
+
// getMapKey: (object) => {return object;}
|
|
47
|
+
// }
|
|
48
|
+
// },
|
|
49
|
+
},
|
|
50
|
+
LCSProduct: {
|
|
51
|
+
vibeOwningKeys: ['itemNumber', 'lifecycleStage'],
|
|
52
|
+
vibe2flex: {
|
|
53
|
+
getClass: () => 'LCSProduct',
|
|
54
|
+
getSoftType: (entity /*, dependencies*/) =>{
|
|
55
|
+
const prodType = entity['prodType'];
|
|
56
|
+
let val = '';
|
|
57
|
+
switch (prodType) {
|
|
58
|
+
case 'acc':
|
|
59
|
+
val = 'Product\\Accesories';
|
|
60
|
+
break;
|
|
61
|
+
case 'app':
|
|
62
|
+
val = 'Product\\Apparel';
|
|
63
|
+
break;
|
|
64
|
+
case 'eqp':
|
|
65
|
+
val = 'Product\\Equipment';
|
|
66
|
+
break;
|
|
67
|
+
case 'foot':
|
|
68
|
+
val = 'Product\\Footwear';
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return val;
|
|
73
|
+
},
|
|
74
|
+
transformOrder: [{ processor: 'REKEY', rekeyDelete: true, rekeyTransformersKey: 'rekey' }, { processor: 'VALUE_TRANSFORM', functionTransformersKey: 'valueTransform' }],
|
|
75
|
+
rekey: {
|
|
76
|
+
productName: 'name',
|
|
77
|
+
vibeIQIdentifier: 'itemNumber'
|
|
78
|
+
},
|
|
79
|
+
valueTransform: {
|
|
80
|
+
transformEx: (row/*, dependencies*/) => {
|
|
81
|
+
return row['otherProp'] + 'xxx';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
},
|
|
86
|
+
flex2vibe: {
|
|
87
|
+
getClass: () => 'item',
|
|
88
|
+
transformOrder: [{ processor: 'REKEY', rekeyDelete: true, rekeyTransformersKey: 'rekey' }],
|
|
89
|
+
rekey: {
|
|
90
|
+
itemNumber: 'vibeIQIdentifier',
|
|
91
|
+
name: 'productName',
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
LCSSKU: {
|
|
96
|
+
vibeOwningKeys: ['itemNumber', 'lifecycleStage'],
|
|
97
|
+
vibe2flex: {
|
|
98
|
+
getClass: () => 'LCSSKU',
|
|
99
|
+
getSoftType: (entity /*, dependencies*/) =>{
|
|
100
|
+
const prodType = entity['prodType'];
|
|
101
|
+
let val = '';
|
|
102
|
+
switch (prodType) {
|
|
103
|
+
case 'acc':
|
|
104
|
+
val = 'Product\\Accesories';
|
|
105
|
+
break;
|
|
106
|
+
case 'app':
|
|
107
|
+
val = 'Product\\Apparel';
|
|
108
|
+
break;
|
|
109
|
+
case 'eqp':
|
|
110
|
+
val = 'Product\\Equipment';
|
|
111
|
+
break;
|
|
112
|
+
case 'foot':
|
|
113
|
+
val = 'Product\\Footwear';
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return val;
|
|
118
|
+
},
|
|
119
|
+
transformOrder: [{ processor: 'REKEY', rekeyDelete: true, rekeyTransformersKey: 'rekey' }],
|
|
120
|
+
rekey: {
|
|
121
|
+
skuName: 'optionName',
|
|
122
|
+
vibeIQIdentifier: 'itemNumber'
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
flex2vibe: {
|
|
126
|
+
transformOrder: [{ processor: 'REKEY', rekeyDelete: true, rekeyTransformersKey: 'rekey' }],
|
|
127
|
+
rekey: {
|
|
128
|
+
itemNumber: 'vibeIQIdentifier',
|
|
129
|
+
optionName: 'skuName',
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
packaging: {
|
|
135
|
+
vibe2flex: {
|
|
136
|
+
transformOrder: [{ processor: 'REKEY', rekeyDelete: true, rekeyTransformersKey: 'rekey' }],
|
|
137
|
+
rekey: {
|
|
138
|
+
retailPackType: 'packType',
|
|
139
|
+
retailIntroDate: 'introDate'
|
|
140
|
+
},
|
|
141
|
+
getSoftType: () => 'Revisable Entity\\packaging',
|
|
142
|
+
getClass: () => 'LCSRevisableEntity'
|
|
143
|
+
},
|
|
144
|
+
flex2vibe: {
|
|
145
|
+
transformOrder: [{ processor: 'REKEY', rekeyDelete: true, rekeyTransformersKey: 'rekey' }],
|
|
146
|
+
rekey: {
|
|
147
|
+
packType: 'retailPackType',
|
|
148
|
+
introDate: 'retailIntroDate'
|
|
149
|
+
},
|
|
150
|
+
getClass: () => 'custom-entity',
|
|
151
|
+
getSoftType: () => 'custom-entity:pack',
|
|
152
|
+
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
prefix: {
|
|
156
|
+
vibe2flex: {
|
|
157
|
+
transformOrder: [{ processor: 'REKEY', rekeyDelete: true, rekeyTransformersKey: 'rekey' }],
|
|
158
|
+
rekey: {
|
|
159
|
+
retailOwner: 'owner',
|
|
160
|
+
retailIntroDate: 'introDate'
|
|
161
|
+
},
|
|
162
|
+
getSoftType: () => 'Revisable Entity\\prefix',
|
|
163
|
+
getClass: () => 'LCSRevisableEntity'
|
|
164
|
+
},
|
|
165
|
+
flex2vibe: {
|
|
166
|
+
transformOrder: [{ processor: 'REKEY', rekeyDelete: true, rekeyTransformersKey: 'rekey' }],
|
|
167
|
+
rekey: {
|
|
168
|
+
owner: 'retailOwner',
|
|
169
|
+
introDate: 'retailIntroDate'
|
|
170
|
+
},
|
|
171
|
+
getClass: () => 'custom-entity',
|
|
172
|
+
getSoftType: () => 'custom-entity:prefix',
|
|
173
|
+
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
catName: {
|
|
177
|
+
getIdentifierProperties: () => ['catName', 'catNumber'],
|
|
178
|
+
getInformationalProperties: () => ['longName'],
|
|
179
|
+
vibe2flex: {
|
|
180
|
+
transformOrder: [],
|
|
181
|
+
getSoftType: () => 'Revisable Entity\\catName',
|
|
182
|
+
getClass: () => 'LCSLast'
|
|
183
|
+
},
|
|
184
|
+
flex2vibe: {
|
|
185
|
+
transformOrder: [],
|
|
186
|
+
getClass: () => 'custom-entity',
|
|
187
|
+
getSoftType: () => 'custom-entity:catName',
|
|
188
|
+
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
partnerOrg: {
|
|
192
|
+
vibe2flex: {
|
|
193
|
+
transformOrder: [],
|
|
194
|
+
getSoftType: () => 'Business Object\\partnerOrg',
|
|
195
|
+
getClass: () => 'LCSLifecycleManaged'
|
|
196
|
+
},
|
|
197
|
+
flex2vibe: {
|
|
198
|
+
transformOrder: [],
|
|
199
|
+
getClass: () => 'custom-entity',
|
|
200
|
+
getSoftType: () => 'custom-entity:partnerOrg',
|
|
201
|
+
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
catFamily: {
|
|
205
|
+
vibe2flex: {
|
|
206
|
+
transformOrder: [],
|
|
207
|
+
getSoftType: () => 'Revisable Entity\\catFamily',
|
|
208
|
+
getClass: () => 'LCSRevisableEntity'
|
|
209
|
+
},
|
|
210
|
+
flex2vibe: {
|
|
211
|
+
transformOrder: [],
|
|
212
|
+
getClass: () => 'custom-entity',
|
|
213
|
+
getSoftType: () => 'custom-entity:catFamily',
|
|
214
|
+
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
formName: {
|
|
218
|
+
vibe2flex: {
|
|
219
|
+
transformOrder: [],
|
|
220
|
+
getSoftType: () => 'Material\\form',
|
|
221
|
+
getClass: () => 'LCSMaterial'
|
|
222
|
+
},
|
|
223
|
+
flex2vibe: {
|
|
224
|
+
transformOrder: [],
|
|
225
|
+
getClass: () => 'custom-entity',
|
|
226
|
+
getSoftType: () => 'custom-entity:formName',
|
|
227
|
+
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
|
|
231
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
|
|
2
|
+
const maps = require('./map-util-spec-mockData').mapping;
|
|
3
|
+
|
|
4
|
+
const mockData = {
|
|
5
|
+
file1: maps
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const mockGetMapFileFunction = jest.fn(async (fileId) =>{
|
|
9
|
+
return mockData[fileId];
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
import { Entities } from '@contrail/sdk';
|
|
14
|
+
import { MapFileUtil } from '@contrail/transform-data';
|
|
15
|
+
import { MapUtil } from './map-utils';
|
|
16
|
+
|
|
17
|
+
describe('getMapKey', () =>{
|
|
18
|
+
const transformMapFile = 'file1';
|
|
19
|
+
const mapFileUtil = new MapFileUtil(new Entities());
|
|
20
|
+
let spy;
|
|
21
|
+
beforeAll(() =>{
|
|
22
|
+
spy = jest.spyOn(mapFileUtil, 'getMapFile').mockImplementation(mockGetMapFileFunction);
|
|
23
|
+
});
|
|
24
|
+
beforeEach(()=>{
|
|
25
|
+
spy.mockClear();
|
|
26
|
+
});
|
|
27
|
+
afterAll(() =>{
|
|
28
|
+
spy.mockRestore();
|
|
29
|
+
});
|
|
30
|
+
it('custom-entity:pack', async () =>{
|
|
31
|
+
const entity = {
|
|
32
|
+
typePath: 'custom-entity:pack',
|
|
33
|
+
entityType: 'custom-entity'
|
|
34
|
+
}
|
|
35
|
+
const expectedMapKey = 'packaging';
|
|
36
|
+
|
|
37
|
+
const results:string = await MapUtil.getMapKey(transformMapFile, mapFileUtil, entity, entity.entityType, 'vibe2flex');;
|
|
38
|
+
expect(results).toEqual(expectedMapKey);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('custom-entity:prefix', async () =>{
|
|
42
|
+
const entity = {
|
|
43
|
+
typePath: 'custom-entity:prefix',
|
|
44
|
+
entityType: 'custom-entity'
|
|
45
|
+
}
|
|
46
|
+
const expectedMapKey = 'prefix';
|
|
47
|
+
|
|
48
|
+
const results:string = await MapUtil.getMapKey(transformMapFile, mapFileUtil, entity, entity.entityType, 'vibe2flex');;
|
|
49
|
+
expect(results).toEqual(expectedMapKey);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('color - no mapping exists', async () =>{
|
|
53
|
+
const entity = {
|
|
54
|
+
typePath: 'color',
|
|
55
|
+
entityType: 'color'
|
|
56
|
+
}
|
|
57
|
+
const expectedMapKey = undefined;
|
|
58
|
+
|
|
59
|
+
const results:string = await MapUtil.getMapKey(transformMapFile, mapFileUtil, entity, entity.entityType, 'vibe2flex');;
|
|
60
|
+
expect(results).toEqual(expectedMapKey);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('getFullMapSection', () =>{
|
|
66
|
+
const transformMapFile = 'file1';
|
|
67
|
+
const mapFileUtil = new MapFileUtil(new Entities());
|
|
68
|
+
let spy;
|
|
69
|
+
beforeAll(() =>{
|
|
70
|
+
spy = jest.spyOn(mapFileUtil, 'getMapFile').mockImplementation(mockGetMapFileFunction);
|
|
71
|
+
});
|
|
72
|
+
beforeEach(()=>{
|
|
73
|
+
spy.mockClear();
|
|
74
|
+
});
|
|
75
|
+
afterAll(() =>{
|
|
76
|
+
spy.mockRestore();
|
|
77
|
+
});
|
|
78
|
+
it('custom-entity:pack', async () =>{
|
|
79
|
+
const mapKey = 'packaging';
|
|
80
|
+
|
|
81
|
+
const mapSection = await MapUtil.getFullMapSection(transformMapFile, mapFileUtil, mapKey);
|
|
82
|
+
expect(mapSection).toHaveProperty('vibe2flex');
|
|
83
|
+
expect(mapSection).toHaveProperty('flex2vibe');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('custom-entity:catName', async () =>{
|
|
87
|
+
const mapKey = 'catName';
|
|
88
|
+
|
|
89
|
+
const mapSection = await MapUtil.getFullMapSection(transformMapFile, mapFileUtil, mapKey);
|
|
90
|
+
expect(mapSection).toHaveProperty('vibe2flex');
|
|
91
|
+
expect(mapSection).toHaveProperty('flex2vibe');
|
|
92
|
+
expect(mapSection).toHaveProperty('getIdentifierProperties');
|
|
93
|
+
expect(mapSection).toHaveProperty('getInformationalProperties');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('color - no mapping exists', async () =>{
|
|
97
|
+
const mapKey = 'color';
|
|
98
|
+
|
|
99
|
+
const mapSection = await MapUtil.getFullMapSection(transformMapFile, mapFileUtil, mapKey);
|
|
100
|
+
expect(mapSection).toBeUndefined();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { MapFileUtil, TransformProcessor, TransformTask } from '@contrail/transform-data';
|
|
2
|
+
export class MapUtil {
|
|
3
|
+
/** Transforms the data, assumes mapSectionKey has been correctly determined.
|
|
4
|
+
*
|
|
5
|
+
* @param transformMapFile id of map file
|
|
6
|
+
* @param mapFileUtil
|
|
7
|
+
* @param data
|
|
8
|
+
* @param mapSectionKey key for section of map file
|
|
9
|
+
* @param direction vibe2flex or flex2vibe
|
|
10
|
+
* @returns The converted data
|
|
11
|
+
*/
|
|
12
|
+
static async applyTransformMap(transformMapFile, mapFileUtil, data: any, mapSectionKey: string, direction: string) {
|
|
13
|
+
return await mapFileUtil.applyTransformMap(transformMapFile, data, mapSectionKey, direction);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Returns the mapKey based on the 'typeConversion' section of the map file.
|
|
17
|
+
* If the map file doesn't have a section for the type in question, 'undefined' is returned.
|
|
18
|
+
*
|
|
19
|
+
* @param fileId
|
|
20
|
+
* @param mapFileUtil
|
|
21
|
+
* @param data The full object
|
|
22
|
+
* @param type The entity or object class of the object. The functions are keyed based on this.
|
|
23
|
+
* @param direction
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
static async getMapKey(transformMapFile, mapFileUtil: MapFileUtil, data: any, type: string, direction: string): Promise<string> {
|
|
27
|
+
return await mapFileUtil.getMapKey(transformMapFile, data, type, direction);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Returns the full map section with both directions; identifier and informational properties; etc.
|
|
31
|
+
*
|
|
32
|
+
* @param transformMapFile id if map file
|
|
33
|
+
* @param mapFileUtil
|
|
34
|
+
* @param mapSectionKey key of the map section
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
static async getFullMapSection(transformMapFile: string, mapFileUtil: MapFileUtil, mapSectionKey: string):Promise<any> {
|
|
38
|
+
return await mapFileUtil.getFullMapSection(transformMapFile, mapSectionKey);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export const empty_custom_sizes = [];
|
|
2
|
+
export const four_custom_sizes = [
|
|
3
|
+
{
|
|
4
|
+
size: 1000,
|
|
5
|
+
id: '-QwFOWnCs0Gb5jkA',
|
|
6
|
+
slug: 'CS_1000'
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
size: 300,
|
|
10
|
+
id: 'AKXOowvhJRnkerG8',
|
|
11
|
+
slug: 'CS_300'
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
size: 500,
|
|
15
|
+
id: '9asQ65N188RIYgnh',
|
|
16
|
+
slug: 'CS_500'
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
size: 800,
|
|
20
|
+
id: 'xkzhwE4nJ6iRwfvP',
|
|
21
|
+
slug: 'CS_800'
|
|
22
|
+
}
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
export const thumbnail_content_entity = {
|
|
26
|
+
fileName: 'JACKET 300_SOLDIER OLIVE.png',
|
|
27
|
+
primaryFileId: 'yn2d5oHD4rXHRzyB',
|
|
28
|
+
primaryFileUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Ff646d3cd-e23a-4689-bd16-0301d2036720.png',
|
|
29
|
+
tinyViewableId: '6HWzJrQ-Jx1iefmj',
|
|
30
|
+
tinyViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fb68f8652-f33f-452f-ae34-25397b4521eb.png',
|
|
31
|
+
smallViewableId: 'D3WRW4iRmjLzp5VX',
|
|
32
|
+
smallViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F541c53f8-fd85-418e-ae28-ad7410658b90.png',
|
|
33
|
+
mediumViewableId: 'AsRvJenpeqxksUNW',
|
|
34
|
+
mediumViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fe803c2d3-3e1b-4d9c-9bb9-2c488f1f295b.png',
|
|
35
|
+
largeViewableId: 'vo4N4mCd-tFrw101',
|
|
36
|
+
largeViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fb1b7a55c-b8ba-4857-be4e-e1c3f11d8e9a.png',
|
|
37
|
+
CS_300Id: '6A5AG33nVu3Z6ogO',
|
|
38
|
+
CS_300Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F3f2ea306-a77f-4cc3-a49a-75fb5d8b113c.png',
|
|
39
|
+
CS_500Id: 'rBaHc1J2xdOWdbhI',
|
|
40
|
+
CS_500Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F979c8c65-b63f-4220-aa2e-11520f2f68bf.png',
|
|
41
|
+
CS_800Id: 'ZPAeYI3JiqjQ7unY',
|
|
42
|
+
CS_800Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fc58eeffa-2592-4698-a058-19281cda447c.png',
|
|
43
|
+
CS_1000Id: 'Hg_CthwsD4ozopCb',
|
|
44
|
+
CS_1000Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F2c827c7b-361b-4e05-b77d-4280294f9d9c.png',
|
|
45
|
+
createdOn: '2023-07-05T15:02:13.950Z',
|
|
46
|
+
orgId: '5LZnKVTNxvwMqufy',
|
|
47
|
+
id: 'cuRficeyoStwTF-f',
|
|
48
|
+
contentType: 'image/png',
|
|
49
|
+
createdById: 'SWIFPZeZzkBvrSLD',
|
|
50
|
+
updatedById: 'SWIFPZeZzkBvrSLD',
|
|
51
|
+
fileSize: 1757973
|
|
52
|
+
};
|
|
53
|
+
export const cuRficeyoStwTF_f_fileEntities = [
|
|
54
|
+
{
|
|
55
|
+
fileName: 'JACKET 300_SOLDIER OLIVE.png',
|
|
56
|
+
id: 'yn2d5oHD4rXHRzyB',
|
|
57
|
+
size: 1757973
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
fileName: 'JACKET 300_SOLDIER OLIVE_tiny.png',
|
|
61
|
+
id: '6HWzJrQ-Jx1iefmj',
|
|
62
|
+
size: 1784
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
fileName: 'JACKET 300_SOLDIER OLIVE_small.png',
|
|
66
|
+
id: 'D3WRW4iRmjLzp5VX',
|
|
67
|
+
size: 8699
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
fileName: 'JACKET 300_SOLDIER OLIVE_medium.png',
|
|
71
|
+
id: 'AsRvJenpeqxksUNW',
|
|
72
|
+
size: 77558
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
fileName: 'JACKET 300_SOLDIER OLIVE_large.png',
|
|
76
|
+
id: 'vo4N4mCd-tFrw101',
|
|
77
|
+
size: 1781538
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
fileName: 'JACKET 300_SOLDIER OLIVE_CS_300.png',
|
|
81
|
+
id: '6A5AG33nVu3Z6ogO',
|
|
82
|
+
size: 141153
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
fileName: 'JACKET 300_SOLDIER OLIVE_CS_500.png',
|
|
86
|
+
id: 'rBaHc1J2xdOWdbhI',
|
|
87
|
+
size: 382057
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
fileName: 'JACKET 300_SOLDIER OLIVE_CS_800.png',
|
|
91
|
+
id: 'ZPAeYI3JiqjQ7unY',
|
|
92
|
+
size: 1008702
|
|
93
|
+
},{
|
|
94
|
+
fileName: 'JACKET 300_SOLDIER OLIVE_CS_1000.png',
|
|
95
|
+
id: 'Hg_CthwsD4ozopCb',
|
|
96
|
+
size: 1605889
|
|
97
|
+
}
|
|
98
|
+
];
|