@contrail/flexplm 1.1.25 → 1.1.27
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/error-response-object.spec.ts +13 -0
- package/error-response-object.ts +38 -0
- package/lib/entity-processor/base-entity-processor.d.ts +2 -2
- package/lib/entity-processor/base-entity-processor.js +8 -1
- package/lib/publish/base-process-publish-assortment-callback.d.ts +2 -1
- package/lib/publish/base-process-publish-assortment-callback.js +21 -6
- package/lib/util/data-converter.js +37 -4
- package/package.json +2 -2
- package/src/entity-processor/base-entity-processor.ts +10 -1
- package/src/publish/base-process-publish-assortment-callback.ts +32 -10
- package/src/util/data-converter.ts +39 -5
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AppActionCallbackStatus } from "@contrail/app-framework";
|
|
2
|
+
import { ErrorResponseObject } from "./error-response-object";
|
|
3
|
+
|
|
4
|
+
describe('getResponse() Tests', () =>{
|
|
5
|
+
it('status set', () => {
|
|
6
|
+
const e = {
|
|
7
|
+
message: 'Test'
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const response = ErrorResponseObject.getResponse(e);
|
|
11
|
+
expect(response.status).toMatch(AppActionCallbackStatus.FAILURE);
|
|
12
|
+
})
|
|
13
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { AppActionCallBack, AppActionCallbackStatus } from "@contrail/app-framework";
|
|
2
|
+
|
|
3
|
+
export class ErrorResponseObject {
|
|
4
|
+
|
|
5
|
+
/** Returns a response, checking for multiple possible error details
|
|
6
|
+
*
|
|
7
|
+
* @param e
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
public static getResponse(e): AppActionCallBack {
|
|
11
|
+
const response: AppActionCallBack = {
|
|
12
|
+
status: AppActionCallbackStatus.FAILURE,
|
|
13
|
+
output: {
|
|
14
|
+
message: e.message
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
if(!e){
|
|
18
|
+
return response;
|
|
19
|
+
}
|
|
20
|
+
const output = response.output;
|
|
21
|
+
|
|
22
|
+
//Errors when persisting in VibeIQ
|
|
23
|
+
if(e?.details){
|
|
24
|
+
output.errorDetails = e.details;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//Has original cause
|
|
28
|
+
if(e?.cause){
|
|
29
|
+
const cause = {
|
|
30
|
+
code: e.cause.code,
|
|
31
|
+
message: e.cause.message,
|
|
32
|
+
};
|
|
33
|
+
output.cause = cause;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return response;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -26,8 +26,8 @@ export declare abstract class BaseEntityProcessor {
|
|
|
26
26
|
updateEntity(entityName: any, entity: any, diffs: any): Promise<any>;
|
|
27
27
|
protected abstract getIncomingEntity(event: any, inboundData: any): Promise<IncomingEntityResponse>;
|
|
28
28
|
protected abstract getCreateEntity(inboundData: any): Promise<IncomingEntityResponse>;
|
|
29
|
-
outbound(event: any): Promise<
|
|
30
|
-
handleOutgoingUpsert(entityType: any, event: any): Promise<
|
|
29
|
+
outbound(event: any): Promise<any>;
|
|
30
|
+
handleOutgoingUpsert(entityType: any, event: any): Promise<any>;
|
|
31
31
|
handleOutgoingDelete(entityType: any, event: any): Promise<void>;
|
|
32
32
|
protected abstract getOutgoingUpsertPayload(entityType: any, event: any): Promise<EntityPayloadType>;
|
|
33
33
|
}
|
|
@@ -152,7 +152,14 @@ class BaseEntityProcessor {
|
|
|
152
152
|
};
|
|
153
153
|
}
|
|
154
154
|
const payload = await this.getOutgoingUpsertPayload(entityType, event);
|
|
155
|
-
|
|
155
|
+
const flexResponse = await new flexplm_connect_1.FlexPLMConnect(this.config).sendToFlexPLM(payload);
|
|
156
|
+
const flexPayload = flexResponse?.results?.data?.payload[0];
|
|
157
|
+
if (flexPayload) {
|
|
158
|
+
const inboundData = await this.getTransformedData(flexPayload);
|
|
159
|
+
const inboundEntityUpdates = await this.getUpdatesForEntity(event.newData, inboundData);
|
|
160
|
+
flexResponse['inboundEntityUpdates'] = inboundEntityUpdates;
|
|
161
|
+
}
|
|
162
|
+
return flexResponse;
|
|
156
163
|
}
|
|
157
164
|
async handleOutgoingDelete(entityType, event) {
|
|
158
165
|
console.warn('delete is not configured', entityType, event.oldData);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { FCConfig } from
|
|
1
|
+
import { FCConfig } from "../interfaces/interfaces";
|
|
2
2
|
export declare class BaseProcessPublishAssortmentCallback {
|
|
3
3
|
private config;
|
|
4
4
|
constructor(_config: FCConfig);
|
|
5
5
|
process(event: any): Promise<{
|
|
6
6
|
message: string;
|
|
7
7
|
}>;
|
|
8
|
+
private checkFailuresAndSendNotification;
|
|
8
9
|
}
|
|
@@ -1,19 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseProcessPublishAssortmentCallback = void 0;
|
|
4
|
+
const sdk_1 = require("@contrail/sdk");
|
|
4
5
|
class BaseProcessPublishAssortmentCallback {
|
|
5
6
|
constructor(_config) {
|
|
6
7
|
this.config = _config;
|
|
7
8
|
}
|
|
8
9
|
async process(event) {
|
|
9
|
-
console.log(
|
|
10
|
-
console.log(
|
|
11
|
-
console.log(
|
|
12
|
-
const statusCounts = this.config[
|
|
13
|
-
console.log(
|
|
10
|
+
console.log("ProcessPublishAssortmentCallback-process()");
|
|
11
|
+
console.log("ProcessPublishAssortmentCallback-event: " + JSON.stringify(event));
|
|
12
|
+
console.log("ProcessPublishAssortmentCallback-config: " + JSON.stringify(this.config));
|
|
13
|
+
const statusCounts = this.config["statusCounts"];
|
|
14
|
+
console.log("statusCounts: " + JSON.stringify(statusCounts));
|
|
15
|
+
this.checkFailuresAndSendNotification(event);
|
|
14
16
|
return {
|
|
15
|
-
message:
|
|
17
|
+
message: "Done ProcessPublishAssortmentCallback-process()",
|
|
16
18
|
};
|
|
17
19
|
}
|
|
20
|
+
checkFailuresAndSendNotification(event) {
|
|
21
|
+
const statusCounts = JSON.parse(this.config["statusCounts"]);
|
|
22
|
+
if (statusCounts["INVALID"] > 0 || statusCounts["FAILURE"] > 0) {
|
|
23
|
+
new sdk_1.Notification().Dispatch({
|
|
24
|
+
message: `There were errors when publishing the season data. Please review the event and config information from context.`,
|
|
25
|
+
level: sdk_1.LogLevel.WARN,
|
|
26
|
+
context: {
|
|
27
|
+
event,
|
|
28
|
+
config: this.config,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
18
33
|
}
|
|
19
34
|
exports.BaseProcessPublishAssortmentCallback = BaseProcessPublishAssortmentCallback;
|
|
@@ -374,20 +374,53 @@ class DataConverter {
|
|
|
374
374
|
}
|
|
375
375
|
}
|
|
376
376
|
if (!objectReferenceId) {
|
|
377
|
-
console.warn(`The passed in object reference criteria ${JSON.stringify(combinedCriteria)}
|
|
377
|
+
console.warn(`The passed in object reference criteria ${JSON.stringify(combinedCriteria)} didn't match any entities.`);
|
|
378
378
|
return objectReferenceId;
|
|
379
379
|
}
|
|
380
380
|
this.objRefCache[cacheKey] = objectReferenceId;
|
|
381
381
|
return objectReferenceId;
|
|
382
382
|
}
|
|
383
383
|
async getAllObjectReferences(entityType, rootTypeCriteria) {
|
|
384
|
+
const entities = new sdk_1.Entities();
|
|
384
385
|
let loads = [];
|
|
385
386
|
let nextPageKey;
|
|
387
|
+
let usedV2 = false;
|
|
386
388
|
do {
|
|
387
|
-
const loadPage = await
|
|
388
|
-
|
|
389
|
-
|
|
389
|
+
const loadPage = await entities.get({
|
|
390
|
+
entityName: entityType,
|
|
391
|
+
criteria: rootTypeCriteria,
|
|
392
|
+
apiVersion: sdk_1.API_VERSION.V2,
|
|
393
|
+
nextPageKey,
|
|
394
|
+
});
|
|
395
|
+
nextPageKey = loadPage?.nextPageKey;
|
|
396
|
+
if (Object.keys(loadPage).includes('results')) {
|
|
397
|
+
usedV2 = true;
|
|
398
|
+
loads.push(...loadPage.results);
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
nextPageKey = null;
|
|
402
|
+
}
|
|
390
403
|
} while (nextPageKey);
|
|
404
|
+
if (!usedV2) {
|
|
405
|
+
const take = 1000;
|
|
406
|
+
let skip = 0;
|
|
407
|
+
let done = false;
|
|
408
|
+
while (!done) {
|
|
409
|
+
const loadPage = await entities.get({
|
|
410
|
+
entityName: entityType,
|
|
411
|
+
criteria: rootTypeCriteria,
|
|
412
|
+
take,
|
|
413
|
+
skip,
|
|
414
|
+
});
|
|
415
|
+
loads.push(...loadPage);
|
|
416
|
+
if (loadPage.length !== take) {
|
|
417
|
+
done = true;
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
skip += take;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
391
424
|
return loads;
|
|
392
425
|
}
|
|
393
426
|
checkKeysAndValues(criteria, arrayOfObjects, entityTypePath) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/flexplm",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.27",
|
|
4
4
|
"description": "Library used for integration with flexplm.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@contrail/app-framework": "^1.2.4",
|
|
42
|
-
"@contrail/sdk": "^1.3.
|
|
42
|
+
"@contrail/sdk": "^1.3.7",
|
|
43
43
|
"@contrail/transform-data": "^1.0.14",
|
|
44
44
|
"axios": "^1.4.0",
|
|
45
45
|
"p-limit": "^3.1.0"
|
|
@@ -197,7 +197,16 @@ export abstract class BaseEntityProcessor {
|
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
const payload = await this.getOutgoingUpsertPayload(entityType, event);
|
|
200
|
-
|
|
200
|
+
const flexResponse: any = await new FlexPLMConnect(this.config).sendToFlexPLM(payload);
|
|
201
|
+
|
|
202
|
+
const flexPayload = flexResponse?.results?.data?.payload[0];
|
|
203
|
+
if(flexPayload) {
|
|
204
|
+
const inboundData = await this.getTransformedData(flexPayload);
|
|
205
|
+
const inboundEntityUpdates = await this.getUpdatesForEntity(event.newData, inboundData)
|
|
206
|
+
flexResponse['inboundEntityUpdates'] = inboundEntityUpdates;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return flexResponse;
|
|
201
210
|
}
|
|
202
211
|
|
|
203
212
|
async handleOutgoingDelete(entityType, event) {
|
|
@@ -1,23 +1,45 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LogLevel, Notification } from "@contrail/sdk";
|
|
2
|
+
import { FCConfig } from "../interfaces/interfaces";
|
|
2
3
|
|
|
3
4
|
export class BaseProcessPublishAssortmentCallback {
|
|
4
5
|
private config: FCConfig;
|
|
5
6
|
|
|
6
|
-
constructor(_config:FCConfig){
|
|
7
|
+
constructor(_config: FCConfig) {
|
|
7
8
|
this.config = _config;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
public async process(event){
|
|
11
|
-
console.log(
|
|
11
|
+
public async process(event) {
|
|
12
|
+
console.log("ProcessPublishAssortmentCallback-process()");
|
|
12
13
|
|
|
13
|
-
console.log(
|
|
14
|
-
|
|
14
|
+
console.log(
|
|
15
|
+
"ProcessPublishAssortmentCallback-event: " + JSON.stringify(event)
|
|
16
|
+
);
|
|
17
|
+
console.log(
|
|
18
|
+
"ProcessPublishAssortmentCallback-config: " + JSON.stringify(this.config)
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const statusCounts = this.config["statusCounts"];
|
|
22
|
+
console.log("statusCounts: " + JSON.stringify(statusCounts));
|
|
23
|
+
|
|
24
|
+
this.checkFailuresAndSendNotification(event);
|
|
15
25
|
|
|
16
|
-
const statusCounts = this.config['statusCounts'];
|
|
17
|
-
console.log('statusCounts: ' + JSON.stringify(statusCounts));
|
|
18
26
|
return {
|
|
19
|
-
message:
|
|
27
|
+
message: "Done ProcessPublishAssortmentCallback-process()",
|
|
20
28
|
};
|
|
21
29
|
}
|
|
22
30
|
|
|
23
|
-
|
|
31
|
+
private checkFailuresAndSendNotification(event) {
|
|
32
|
+
const statusCounts = JSON.parse(this.config["statusCounts"]);
|
|
33
|
+
|
|
34
|
+
if (statusCounts["INVALID"] > 0 || statusCounts["FAILURE"] > 0) {
|
|
35
|
+
new Notification().Dispatch({
|
|
36
|
+
message: `There were errors when publishing the season data. Please review the event and config information from context.`,
|
|
37
|
+
level: LogLevel.WARN,
|
|
38
|
+
context: {
|
|
39
|
+
event,
|
|
40
|
+
config: this.config,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -458,7 +458,7 @@ export class DataConverter {
|
|
|
458
458
|
}
|
|
459
459
|
|
|
460
460
|
if (!objectReferenceId) {
|
|
461
|
-
console.warn(`The passed in object reference criteria ${JSON.stringify(combinedCriteria)}
|
|
461
|
+
console.warn(`The passed in object reference criteria ${JSON.stringify(combinedCriteria)} didn't match any entities.`);
|
|
462
462
|
return objectReferenceId;
|
|
463
463
|
}
|
|
464
464
|
|
|
@@ -475,13 +475,47 @@ export class DataConverter {
|
|
|
475
475
|
* @returns {Promise<Array>} A Promise that resolves to an array containing all object references.
|
|
476
476
|
*/
|
|
477
477
|
async getAllObjectReferences(entityType, rootTypeCriteria) {
|
|
478
|
-
|
|
478
|
+
const entities = new Entities();
|
|
479
|
+
let loads = [];
|
|
479
480
|
let nextPageKey;
|
|
481
|
+
let usedV2 = false;
|
|
480
482
|
do {
|
|
481
|
-
const loadPage = await
|
|
482
|
-
|
|
483
|
-
|
|
483
|
+
const loadPage = await entities.get({
|
|
484
|
+
entityName: entityType,
|
|
485
|
+
criteria: rootTypeCriteria,
|
|
486
|
+
apiVersion: API_VERSION.V2,
|
|
487
|
+
nextPageKey,
|
|
488
|
+
});
|
|
489
|
+
nextPageKey = loadPage?.nextPageKey;
|
|
490
|
+
if (Object.keys(loadPage).includes('results')) {
|
|
491
|
+
usedV2 = true;
|
|
492
|
+
loads.push(...loadPage.results);
|
|
493
|
+
} else {
|
|
494
|
+
nextPageKey = null;
|
|
495
|
+
}
|
|
484
496
|
} while (nextPageKey);
|
|
497
|
+
|
|
498
|
+
if (!usedV2) {
|
|
499
|
+
const take = 1000;
|
|
500
|
+
let skip = 0;
|
|
501
|
+
let done = false;
|
|
502
|
+
while (!done) {
|
|
503
|
+
const loadPage = await entities.get({
|
|
504
|
+
entityName: entityType,
|
|
505
|
+
criteria: rootTypeCriteria,
|
|
506
|
+
take,
|
|
507
|
+
skip,
|
|
508
|
+
});
|
|
509
|
+
loads.push(...loadPage);
|
|
510
|
+
|
|
511
|
+
if (loadPage.length !== take) {
|
|
512
|
+
done = true;
|
|
513
|
+
} else {
|
|
514
|
+
skip += take;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
485
519
|
return loads;
|
|
486
520
|
}
|
|
487
521
|
|