@contrail/flexplm 1.1.64 → 1.1.65
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/lib/publish/base-process-publish-assortment.d.ts +10 -9
- package/lib/publish/base-process-publish-assortment.js +30 -17
- package/lib/publish/base-process-publish-assortment.spec.js +81 -9
- package/lib/publish/mockData.d.ts +68 -0
- package/lib/publish/mockData.js +257 -1
- package/package.json +2 -1
- package/src/publish/base-process-publish-assortment.spec.ts +131 -35
- package/src/publish/base-process-publish-assortment.ts +48 -29
- package/src/publish/mockData.ts +4817 -4560
- package/src/util/flexplm-connect.ts +199 -199
|
@@ -1,199 +1,199 @@
|
|
|
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
|
-
const e = new Error(message);
|
|
62
|
-
e['httpResponseStatus'] = response.status;
|
|
63
|
-
throw e;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
try{
|
|
67
|
-
|
|
68
|
-
const body = await response.json();
|
|
69
|
-
|
|
70
|
-
const nonce_key = body.items[0].attributes.nonce_key;
|
|
71
|
-
const nonce = body.items[0].attributes.nonce;
|
|
72
|
-
console.info('nonce_key: ' + nonce_key);
|
|
73
|
-
console.info('nonce: ' + nonce);
|
|
74
|
-
return {
|
|
75
|
-
nonce_key,
|
|
76
|
-
nonce
|
|
77
|
-
};
|
|
78
|
-
}catch(e){
|
|
79
|
-
const message = 'Error connecting to FlexPLM: ' + e.message;
|
|
80
|
-
console.error(message);
|
|
81
|
-
console.error(await response.text());
|
|
82
|
-
throw new Error(message);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async sendRequest(csrf, payload) {
|
|
87
|
-
|
|
88
|
-
if(this.payloadSendAsArray && !Array.isArray(payload)){
|
|
89
|
-
payload = [payload];
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const xferOptions = this.getRequestOptions('POST');
|
|
93
|
-
|
|
94
|
-
xferOptions['body'] = JSON.stringify(payload);
|
|
95
|
-
xferOptions.headers[csrf.nonce_key] = csrf.nonce;
|
|
96
|
-
|
|
97
|
-
const urlContext = this.config.urlContext;
|
|
98
|
-
const vibeEventsURL: string = this.config.apiHost + urlContext + '/servlet/rest' + this.vibeEventEndpoint;
|
|
99
|
-
|
|
100
|
-
if(Logger.isInfoOn()){
|
|
101
|
-
console.info('Request:');
|
|
102
|
-
console.info('vibeEventsURL: ' + vibeEventsURL);
|
|
103
|
-
const logOptions = JSON.parse(JSON.stringify(xferOptions));
|
|
104
|
-
logOptions['headers']['Authorization'] = logOptions?.headers?.Authorization.substring(0, 9);
|
|
105
|
-
console.info('csrfOptions: ' + JSON.stringify(logOptions));
|
|
106
|
-
console.info('Making call to xfer data to FlexPLM');
|
|
107
|
-
}
|
|
108
|
-
const eventResponse = await fetch(vibeEventsURL, xferOptions);
|
|
109
|
-
return eventResponse;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
protected async processRequest(payload:any){
|
|
113
|
-
if(!payload){
|
|
114
|
-
const message = 'No payload to send to FlexPLM';
|
|
115
|
-
console.error(message);
|
|
116
|
-
throw new Error(message);
|
|
117
|
-
}
|
|
118
|
-
if(Logger.isInfoOn()){
|
|
119
|
-
console.info('payload: ' + JSON.stringify(payload));
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const csrf = await this.getCSRF();
|
|
123
|
-
if(!csrf){
|
|
124
|
-
const message = 'Failed to get CSRF nonce';
|
|
125
|
-
console.error(message);
|
|
126
|
-
throw new Error(message);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const response = await this.sendRequest(csrf, payload);
|
|
130
|
-
const status = response.status;
|
|
131
|
-
if(status >= 300){
|
|
132
|
-
const message = 'Error sending data to FlexPLM:status: ' + response.status;
|
|
133
|
-
console.error(message);
|
|
134
|
-
console.error(await response.text());
|
|
135
|
-
const e = new Error(message);
|
|
136
|
-
e['httpResponseStatus'] = status;
|
|
137
|
-
throw e;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
try{
|
|
141
|
-
const res: FlexPLMResponseData = {
|
|
142
|
-
status,
|
|
143
|
-
};
|
|
144
|
-
if(![204, 205].includes(status)){
|
|
145
|
-
try{
|
|
146
|
-
const data = await response.json();
|
|
147
|
-
res.data = data;
|
|
148
|
-
} catch(e){
|
|
149
|
-
console.error('Error getting response body. Setting {} body: ' + e);
|
|
150
|
-
res.data = {};
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
console.log('eventResponse.status: ' + status);
|
|
155
|
-
// console.log('eventBody: ', JSON.stringify(data));
|
|
156
|
-
return res;
|
|
157
|
-
|
|
158
|
-
}catch(e){
|
|
159
|
-
const message = 'Error getting json data from FlexPLM: ' + e.message;
|
|
160
|
-
console.error(message);
|
|
161
|
-
console.error(await response.text());
|
|
162
|
-
throw new Error(message);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
async sendToFlexPLM( payload: PayloadType){
|
|
167
|
-
return await this.processRequest(payload);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
async sendMultipleToFlexPLM(payload: PayloadType[]){
|
|
171
|
-
return await this.processRequest(payload);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/** Runs a get request to FlexPLM using the endpoint provided in the constructor
|
|
175
|
-
*
|
|
176
|
-
*/
|
|
177
|
-
async getRequest(){
|
|
178
|
-
const urlContext = this.config.urlContext;
|
|
179
|
-
const vibeEventsURL: string = this.config.apiHost + urlContext + '/servlet/rest' + this.vibeEventEndpoint;
|
|
180
|
-
const csrfOptions = this.getRequestOptions('GET');
|
|
181
|
-
const response = await fetch(vibeEventsURL, csrfOptions);
|
|
182
|
-
|
|
183
|
-
if(response.status >= 300){
|
|
184
|
-
const message = 'Error connecting to FlexPLM:status: ' + response.status;
|
|
185
|
-
console.error(message);
|
|
186
|
-
console.error(await response.text());
|
|
187
|
-
throw new Error(message);
|
|
188
|
-
}
|
|
189
|
-
try {
|
|
190
|
-
const data = await response.json();
|
|
191
|
-
return data;
|
|
192
|
-
} catch(e){
|
|
193
|
-
const message = 'Error getting json data from FlexPLM: ' + e.message;
|
|
194
|
-
console.error(message);
|
|
195
|
-
console.error(await response.text());
|
|
196
|
-
throw new Error(message);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
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
|
+
const e = new Error(message);
|
|
62
|
+
e['httpResponseStatus'] = response.status;
|
|
63
|
+
throw e;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
try{
|
|
67
|
+
|
|
68
|
+
const body = await response.json();
|
|
69
|
+
|
|
70
|
+
const nonce_key = body.items[0].attributes.nonce_key;
|
|
71
|
+
const nonce = body.items[0].attributes.nonce;
|
|
72
|
+
console.info('nonce_key: ' + nonce_key);
|
|
73
|
+
console.info('nonce: ' + nonce);
|
|
74
|
+
return {
|
|
75
|
+
nonce_key,
|
|
76
|
+
nonce
|
|
77
|
+
};
|
|
78
|
+
}catch(e){
|
|
79
|
+
const message = 'Error connecting to FlexPLM: ' + e.message;
|
|
80
|
+
console.error(message);
|
|
81
|
+
console.error(await response.text());
|
|
82
|
+
throw new Error(message);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async sendRequest(csrf, payload) {
|
|
87
|
+
|
|
88
|
+
if(this.payloadSendAsArray && !Array.isArray(payload)){
|
|
89
|
+
payload = [payload];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const xferOptions = this.getRequestOptions('POST');
|
|
93
|
+
|
|
94
|
+
xferOptions['body'] = JSON.stringify(payload);
|
|
95
|
+
xferOptions.headers[csrf.nonce_key] = csrf.nonce;
|
|
96
|
+
|
|
97
|
+
const urlContext = this.config.urlContext;
|
|
98
|
+
const vibeEventsURL: string = this.config.apiHost + urlContext + '/servlet/rest' + this.vibeEventEndpoint;
|
|
99
|
+
|
|
100
|
+
if(Logger.isInfoOn()){
|
|
101
|
+
console.info('Request:');
|
|
102
|
+
console.info('vibeEventsURL: ' + vibeEventsURL);
|
|
103
|
+
const logOptions = JSON.parse(JSON.stringify(xferOptions));
|
|
104
|
+
logOptions['headers']['Authorization'] = logOptions?.headers?.Authorization.substring(0, 9);
|
|
105
|
+
console.info('csrfOptions: ' + JSON.stringify(logOptions));
|
|
106
|
+
console.info('Making call to xfer data to FlexPLM');
|
|
107
|
+
}
|
|
108
|
+
const eventResponse = await fetch(vibeEventsURL, xferOptions);
|
|
109
|
+
return eventResponse;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
protected async processRequest(payload:any){
|
|
113
|
+
if(!payload){
|
|
114
|
+
const message = 'No payload to send to FlexPLM';
|
|
115
|
+
console.error(message);
|
|
116
|
+
throw new Error(message);
|
|
117
|
+
}
|
|
118
|
+
if(Logger.isInfoOn()){
|
|
119
|
+
console.info('payload: ' + JSON.stringify(payload));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const csrf = await this.getCSRF();
|
|
123
|
+
if(!csrf){
|
|
124
|
+
const message = 'Failed to get CSRF nonce';
|
|
125
|
+
console.error(message);
|
|
126
|
+
throw new Error(message);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const response = await this.sendRequest(csrf, payload);
|
|
130
|
+
const status = response.status;
|
|
131
|
+
if(status >= 300){
|
|
132
|
+
const message = 'Error sending data to FlexPLM:status: ' + response.status;
|
|
133
|
+
console.error(message);
|
|
134
|
+
console.error(await response.text());
|
|
135
|
+
const e = new Error(message);
|
|
136
|
+
e['httpResponseStatus'] = status;
|
|
137
|
+
throw e;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
try{
|
|
141
|
+
const res: FlexPLMResponseData = {
|
|
142
|
+
status,
|
|
143
|
+
};
|
|
144
|
+
if(![204, 205].includes(status)){
|
|
145
|
+
try{
|
|
146
|
+
const data = await response.json();
|
|
147
|
+
res.data = data;
|
|
148
|
+
} catch(e){
|
|
149
|
+
console.error('Error getting response body. Setting {} body: ' + e);
|
|
150
|
+
res.data = {};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
console.log('eventResponse.status: ' + status);
|
|
155
|
+
// console.log('eventBody: ', JSON.stringify(data));
|
|
156
|
+
return res;
|
|
157
|
+
|
|
158
|
+
}catch(e){
|
|
159
|
+
const message = 'Error getting json data from FlexPLM: ' + e.message;
|
|
160
|
+
console.error(message);
|
|
161
|
+
console.error(await response.text());
|
|
162
|
+
throw new Error(message);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
}
|
|
166
|
+
async sendToFlexPLM( payload: PayloadType){
|
|
167
|
+
return await this.processRequest(payload);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async sendMultipleToFlexPLM(payload: PayloadType[]){
|
|
171
|
+
return await this.processRequest(payload);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Runs a get request to FlexPLM using the endpoint provided in the constructor
|
|
175
|
+
*
|
|
176
|
+
*/
|
|
177
|
+
async getRequest(){
|
|
178
|
+
const urlContext = this.config.urlContext;
|
|
179
|
+
const vibeEventsURL: string = this.config.apiHost + urlContext + '/servlet/rest' + this.vibeEventEndpoint;
|
|
180
|
+
const csrfOptions = this.getRequestOptions('GET');
|
|
181
|
+
const response = await fetch(vibeEventsURL, csrfOptions);
|
|
182
|
+
|
|
183
|
+
if(response.status >= 300){
|
|
184
|
+
const message = 'Error connecting to FlexPLM:status: ' + response.status;
|
|
185
|
+
console.error(message);
|
|
186
|
+
console.error(await response.text());
|
|
187
|
+
throw new Error(message);
|
|
188
|
+
}
|
|
189
|
+
try {
|
|
190
|
+
const data = await response.json();
|
|
191
|
+
return data;
|
|
192
|
+
} catch(e){
|
|
193
|
+
const message = 'Error getting json data from FlexPLM: ' + e.message;
|
|
194
|
+
console.error(message);
|
|
195
|
+
console.error(await response.text());
|
|
196
|
+
throw new Error(message);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|