@contrail/flexplm 1.3.0-alpha.0 → 1.3.0-alpha.3
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 +31 -31
- package/.github/workflows/flexplm-lib.yml +27 -27
- package/CHANGELOG.md +1 -1
- package/lib/entity-processor/base-entity-processor.d.ts +42 -0
- package/lib/entity-processor/base-entity-processor.js +377 -0
- package/lib/entity-processor/base-entity-processor.spec.d.ts +1 -0
- package/lib/entity-processor/base-entity-processor.spec.js +426 -0
- package/lib/flexplm-request.d.ts +3 -0
- package/lib/flexplm-request.js +34 -0
- package/lib/flexplm-utils.d.ts +5 -0
- package/lib/flexplm-utils.js +33 -0
- package/lib/flexplm-utils.spec.d.ts +1 -0
- package/lib/flexplm-utils.spec.js +26 -0
- package/lib/index.d.ts +22 -0
- package/lib/index.js +38 -0
- package/lib/interfaces/interfaces.d.ts +105 -0
- package/lib/interfaces/interfaces.js +2 -0
- package/lib/interfaces/item-family-changes.d.ts +20 -0
- package/lib/interfaces/item-family-changes.js +56 -0
- package/lib/interfaces/publish-change-data.d.ts +19 -0
- package/lib/interfaces/publish-change-data.js +32 -0
- package/lib/publish/base-process-publish-assortment-callback.d.ts +9 -0
- package/lib/publish/base-process-publish-assortment-callback.js +38 -0
- package/lib/publish/base-process-publish-assortment.d.ts +93 -0
- package/lib/publish/base-process-publish-assortment.js +944 -0
- package/lib/publish/base-process-publish-assortment.spec.d.ts +1 -0
- package/lib/publish/base-process-publish-assortment.spec.js +1670 -0
- package/lib/publish/mockData.d.ts +1389 -0
- package/lib/publish/mockData.js +4519 -0
- package/lib/transform/identifier-conversion-spec-mockData.d.ts +0 -0
- package/lib/transform/identifier-conversion-spec-mockData.js +444 -0
- package/lib/transform/identifier-conversion.d.ts +15 -0
- package/lib/transform/identifier-conversion.js +212 -0
- package/lib/transform/identifier-conversion.spec.d.ts +1 -0
- package/lib/transform/identifier-conversion.spec.js +339 -0
- package/lib/util/config-defaults.d.ts +8 -0
- package/lib/util/config-defaults.js +85 -0
- package/lib/util/config-defaults.spec.d.ts +1 -0
- package/lib/util/config-defaults.spec.js +293 -0
- package/lib/util/data-converter-spec-mockData.d.ts +0 -0
- package/lib/util/data-converter-spec-mockData.js +205 -0
- package/lib/util/data-converter.d.ts +39 -0
- package/lib/util/data-converter.js +592 -0
- package/lib/util/data-converter.spec.d.ts +1 -0
- package/lib/util/data-converter.spec.js +904 -0
- package/lib/util/error-response-object.d.ts +4 -0
- package/lib/util/error-response-object.js +47 -0
- package/lib/util/error-response-object.spec.d.ts +1 -0
- package/lib/util/error-response-object.spec.js +99 -0
- package/lib/util/event-short-message-status.d.ts +18 -0
- package/lib/util/event-short-message-status.js +22 -0
- package/lib/util/federation.d.ts +15 -0
- package/lib/util/federation.js +149 -0
- package/lib/util/flexplm-connect.d.ts +22 -0
- package/lib/util/flexplm-connect.js +176 -0
- package/lib/util/flexplm-connect.spec.d.ts +1 -0
- package/lib/util/flexplm-connect.spec.js +88 -0
- package/lib/util/logger-config.d.ts +1 -0
- package/lib/util/logger-config.js +26 -0
- package/lib/util/map-util-spec-mockData.d.ts +0 -0
- package/lib/util/map-util-spec-mockData.js +205 -0
- package/lib/util/map-utils.d.ts +6 -0
- package/lib/util/map-utils.js +15 -0
- package/lib/util/map-utils.spec.d.ts +1 -0
- package/lib/util/map-utils.spec.js +89 -0
- package/lib/util/mockData.d.ts +79 -0
- package/lib/util/mockData.js +99 -0
- package/lib/util/thumbnail-util.d.ts +28 -0
- package/lib/util/thumbnail-util.js +202 -0
- package/lib/util/thumbnail-util.spec.d.ts +1 -0
- package/lib/util/thumbnail-util.spec.js +398 -0
- package/lib/util/type-conversion-utils-spec-mockData.d.ts +0 -0
- package/lib/util/type-conversion-utils-spec-mockData.js +259 -0
- package/lib/util/type-conversion-utils.d.ts +23 -0
- package/lib/util/type-conversion-utils.js +266 -0
- package/lib/util/type-conversion-utils.spec.d.ts +1 -0
- package/lib/util/type-conversion-utils.spec.js +868 -0
- package/lib/util/type-defaults.d.ts +16 -0
- package/lib/util/type-defaults.js +221 -0
- package/lib/util/type-defaults.spec.d.ts +1 -0
- package/lib/util/type-defaults.spec.js +516 -0
- package/lib/util/type-utils.d.ts +13 -0
- package/lib/util/type-utils.js +114 -0
- package/lib/util/type-utils.spec.d.ts +1 -0
- package/lib/util/type-utils.spec.js +190 -0
- package/package.json +1 -1
- package/publish.bat +4 -4
- package/publish.sh +4 -4
- package/src/entity-processor/base-entity-processor.spec.ts +157 -0
- package/src/entity-processor/base-entity-processor.ts +21 -2
- package/src/flexplm-request.ts +28 -28
- package/src/flexplm-utils.spec.ts +27 -27
- package/src/flexplm-utils.ts +29 -29
- package/src/index.ts +21 -21
- package/src/interfaces/item-family-changes.ts +66 -66
- package/src/interfaces/publish-change-data.ts +42 -42
- package/src/publish/base-process-publish-assortment-callback.ts +50 -50
- package/src/transform/identifier-conversion-spec-mockData.ts +495 -495
- package/src/transform/identifier-conversion.spec.ts +353 -353
- package/src/transform/identifier-conversion.ts +281 -281
- package/src/util/config-defaults.spec.ts +350 -350
- package/src/util/config-defaults.ts +92 -92
- package/src/util/data-converter-spec-mockData.ts +230 -230
- package/src/util/error-response-object.spec.ts +115 -115
- package/src/util/error-response-object.ts +49 -49
- package/src/util/federation.ts +172 -172
- package/src/util/logger-config.ts +19 -19
- package/src/util/map-util-spec-mockData.ts +230 -230
- package/src/util/map-utils.spec.ts +102 -102
- package/src/util/map-utils.ts +40 -40
- package/src/util/mockData.ts +97 -97
- package/src/util/thumbnail-util.spec.ts +190 -0
- package/src/util/thumbnail-util.ts +109 -1
- package/src/util/type-conversion-utils.spec.ts +25 -25
- package/src/util/type-conversion-utils.ts +10 -9
- package/src/util/type-defaults.spec.ts +668 -668
- package/src/util/type-defaults.ts +280 -280
- package/src/util/type-utils.spec.ts +227 -227
- package/src/util/type-utils.ts +144 -144
- package/tsconfig.json +28 -26
- package/tslint.json +57 -57
- package/scripts/output.png +0 -0
- package/scripts/test-get-request.ts +0 -35
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorResponseObject = void 0;
|
|
4
|
+
const app_framework_1 = require("@contrail/app-framework");
|
|
5
|
+
class ErrorResponseObject {
|
|
6
|
+
static getResponse(e) {
|
|
7
|
+
if (!e) {
|
|
8
|
+
const response = {
|
|
9
|
+
status: app_framework_1.AppActionCallbackStatus.FAILURE,
|
|
10
|
+
output: {
|
|
11
|
+
message: 'No error provided.'
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
return response;
|
|
15
|
+
}
|
|
16
|
+
const response = {
|
|
17
|
+
status: app_framework_1.AppActionCallbackStatus.FAILURE,
|
|
18
|
+
output: {
|
|
19
|
+
message: e.message
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const output = response.output;
|
|
23
|
+
if (e.details)
|
|
24
|
+
output.errorDetails = e.details;
|
|
25
|
+
if (e.code)
|
|
26
|
+
output.code = e.code;
|
|
27
|
+
if (e.errno)
|
|
28
|
+
output.errno = e.errno;
|
|
29
|
+
if (e.type)
|
|
30
|
+
output.type = e.type;
|
|
31
|
+
if (e.name)
|
|
32
|
+
output.errorName = e.name;
|
|
33
|
+
if (e.cause) {
|
|
34
|
+
output.cause = {};
|
|
35
|
+
const cause = output.cause;
|
|
36
|
+
if (e.cause.code)
|
|
37
|
+
cause.code = e.cause.code;
|
|
38
|
+
if (e.cause.message)
|
|
39
|
+
cause.message = e.cause.message;
|
|
40
|
+
}
|
|
41
|
+
if (e.stack) {
|
|
42
|
+
console.log('ErrorResponseObject.getResponse stack: ' + e.stack);
|
|
43
|
+
}
|
|
44
|
+
return response;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.ErrorResponseObject = ErrorResponseObject;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const app_framework_1 = require("@contrail/app-framework");
|
|
4
|
+
const error_response_object_1 = require("./error-response-object");
|
|
5
|
+
describe('getResponse() Tests', () => {
|
|
6
|
+
it('no error provided', () => {
|
|
7
|
+
const e = undefined;
|
|
8
|
+
const response = error_response_object_1.ErrorResponseObject.getResponse(e);
|
|
9
|
+
expect(response.status).toMatch(app_framework_1.AppActionCallbackStatus.FAILURE);
|
|
10
|
+
expect(response?.output?.message).toMatch('No error provided');
|
|
11
|
+
});
|
|
12
|
+
it('error with message', () => {
|
|
13
|
+
const e = {
|
|
14
|
+
message: 'Test'
|
|
15
|
+
};
|
|
16
|
+
const response = error_response_object_1.ErrorResponseObject.getResponse(e);
|
|
17
|
+
expect(response.status).toMatch(app_framework_1.AppActionCallbackStatus.FAILURE);
|
|
18
|
+
expect(response?.output?.message).toMatch('Test');
|
|
19
|
+
});
|
|
20
|
+
it('error with details', () => {
|
|
21
|
+
const details = {
|
|
22
|
+
message: 'Detail Message',
|
|
23
|
+
itemType: [
|
|
24
|
+
{
|
|
25
|
+
message: "Type 'item:product:newBalance:apparel' cannot be assigned to a property with type 'item'."
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
};
|
|
29
|
+
const e = {
|
|
30
|
+
message: 'Test',
|
|
31
|
+
details
|
|
32
|
+
};
|
|
33
|
+
const response = error_response_object_1.ErrorResponseObject.getResponse(e);
|
|
34
|
+
expect(response).toBeTruthy();
|
|
35
|
+
expect(response.status).toMatch(app_framework_1.AppActionCallbackStatus.FAILURE);
|
|
36
|
+
expect(response.output.message).toMatch('Test');
|
|
37
|
+
const errorDetails = response.output.errorDetails;
|
|
38
|
+
expect(errorDetails).toBeTruthy();
|
|
39
|
+
expect(errorDetails.message).toMatch('Detail Message');
|
|
40
|
+
expect(errorDetails).toHaveProperty('itemType');
|
|
41
|
+
});
|
|
42
|
+
it('error with cause', () => {
|
|
43
|
+
const cause = {
|
|
44
|
+
code: 401,
|
|
45
|
+
message: 'cause message'
|
|
46
|
+
};
|
|
47
|
+
const e = {
|
|
48
|
+
message: 'Test',
|
|
49
|
+
cause
|
|
50
|
+
};
|
|
51
|
+
const response = error_response_object_1.ErrorResponseObject.getResponse(e);
|
|
52
|
+
expect(response.status).toMatch(app_framework_1.AppActionCallbackStatus.FAILURE);
|
|
53
|
+
expect(response?.output?.message).toMatch('Test');
|
|
54
|
+
const resCause = response.output.cause;
|
|
55
|
+
expect(resCause).toBeTruthy();
|
|
56
|
+
expect(resCause.code).toBe(401);
|
|
57
|
+
expect(resCause.message).toMatch('cause message');
|
|
58
|
+
});
|
|
59
|
+
it('error with code', () => {
|
|
60
|
+
const e = {
|
|
61
|
+
message: 'Test',
|
|
62
|
+
code: 404
|
|
63
|
+
};
|
|
64
|
+
const response = error_response_object_1.ErrorResponseObject.getResponse(e);
|
|
65
|
+
expect(response.status).toMatch(app_framework_1.AppActionCallbackStatus.FAILURE);
|
|
66
|
+
expect(response?.output?.message).toMatch('Test');
|
|
67
|
+
expect(response.output.code).toBe(404);
|
|
68
|
+
});
|
|
69
|
+
it('error with code', () => {
|
|
70
|
+
const e = {
|
|
71
|
+
message: 'Test',
|
|
72
|
+
name: 'Error'
|
|
73
|
+
};
|
|
74
|
+
const response = error_response_object_1.ErrorResponseObject.getResponse(e);
|
|
75
|
+
expect(response.status).toMatch(app_framework_1.AppActionCallbackStatus.FAILURE);
|
|
76
|
+
expect(response?.output?.message).toMatch('Test');
|
|
77
|
+
expect(response.output.errorName).toMatch('Error');
|
|
78
|
+
});
|
|
79
|
+
it('error with errno', () => {
|
|
80
|
+
const e = {
|
|
81
|
+
message: 'Test',
|
|
82
|
+
errno: 500
|
|
83
|
+
};
|
|
84
|
+
const response = error_response_object_1.ErrorResponseObject.getResponse(e);
|
|
85
|
+
expect(response.status).toMatch(app_framework_1.AppActionCallbackStatus.FAILURE);
|
|
86
|
+
expect(response?.output?.message).toMatch('Test');
|
|
87
|
+
expect(response.output.errno).toBe(500);
|
|
88
|
+
});
|
|
89
|
+
it('error with type', () => {
|
|
90
|
+
const e = {
|
|
91
|
+
message: 'Test',
|
|
92
|
+
type: 'system'
|
|
93
|
+
};
|
|
94
|
+
const response = error_response_object_1.ErrorResponseObject.getResponse(e);
|
|
95
|
+
expect(response.status).toMatch(app_framework_1.AppActionCallbackStatus.FAILURE);
|
|
96
|
+
expect(response?.output?.message).toMatch('Test');
|
|
97
|
+
expect(response.output.type).toMatch('system');
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare enum EventShortMessageStatus {
|
|
2
|
+
SUCCESS = "Success",
|
|
3
|
+
FAILURE = "Failure",
|
|
4
|
+
CREATED = "Created",
|
|
5
|
+
ITEM_FAMILY_ID_MISSING = "Item_family_id_missing",
|
|
6
|
+
ITEM_FAMILY_NOT_FOUND = "Item_family_not_found",
|
|
7
|
+
PROJECT_ITEM_NOT_FOUND = "Project_item_not_found",
|
|
8
|
+
MISSING_IDENTIFIER_PROPERTIES = "Missing_identifier_properties",
|
|
9
|
+
MISSING_INPUT = "Missing_input",
|
|
10
|
+
NOT_CREATABLE = "Not_creatable",
|
|
11
|
+
NO_CHANGES = "No_Changes",
|
|
12
|
+
TOO_MANY_ENTITIES_FOUND = "Too_Many_Entities_Found",
|
|
13
|
+
UPDATED = "Updated",
|
|
14
|
+
NOT_PUBLISHABLE = "Not_Publishable",
|
|
15
|
+
NO_FEDERATION_INFO = "No_Federation_Information",
|
|
16
|
+
NO_EVENTS_TO_SEND = "No_Events_to_Send",
|
|
17
|
+
SENDING_EVENTS = "Sending_Events"
|
|
18
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventShortMessageStatus = void 0;
|
|
4
|
+
var EventShortMessageStatus;
|
|
5
|
+
(function (EventShortMessageStatus) {
|
|
6
|
+
EventShortMessageStatus["SUCCESS"] = "Success";
|
|
7
|
+
EventShortMessageStatus["FAILURE"] = "Failure";
|
|
8
|
+
EventShortMessageStatus["CREATED"] = "Created";
|
|
9
|
+
EventShortMessageStatus["ITEM_FAMILY_ID_MISSING"] = "Item_family_id_missing";
|
|
10
|
+
EventShortMessageStatus["ITEM_FAMILY_NOT_FOUND"] = "Item_family_not_found";
|
|
11
|
+
EventShortMessageStatus["PROJECT_ITEM_NOT_FOUND"] = "Project_item_not_found";
|
|
12
|
+
EventShortMessageStatus["MISSING_IDENTIFIER_PROPERTIES"] = "Missing_identifier_properties";
|
|
13
|
+
EventShortMessageStatus["MISSING_INPUT"] = "Missing_input";
|
|
14
|
+
EventShortMessageStatus["NOT_CREATABLE"] = "Not_creatable";
|
|
15
|
+
EventShortMessageStatus["NO_CHANGES"] = "No_Changes";
|
|
16
|
+
EventShortMessageStatus["TOO_MANY_ENTITIES_FOUND"] = "Too_Many_Entities_Found";
|
|
17
|
+
EventShortMessageStatus["UPDATED"] = "Updated";
|
|
18
|
+
EventShortMessageStatus["NOT_PUBLISHABLE"] = "Not_Publishable";
|
|
19
|
+
EventShortMessageStatus["NO_FEDERATION_INFO"] = "No_Federation_Information";
|
|
20
|
+
EventShortMessageStatus["NO_EVENTS_TO_SEND"] = "No_Events_to_Send";
|
|
21
|
+
EventShortMessageStatus["SENDING_EVENTS"] = "Sending_Events";
|
|
22
|
+
})(EventShortMessageStatus = exports.EventShortMessageStatus || (exports.EventShortMessageStatus = {}));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FederationRecord } from '../interfaces/interfaces';
|
|
2
|
+
export declare class Federation {
|
|
3
|
+
private CHUNK_SIZE;
|
|
4
|
+
getFederatedMappedRefId(entityType: string, entityId: string): Promise<string>;
|
|
5
|
+
createFederatedRecord(eventBody: any): Promise<any>;
|
|
6
|
+
getFederationRecordFromMappedRefId(mappedRefId: string): Promise<FederationRecord>;
|
|
7
|
+
static getEntityId(fedRecord: FederationRecord): {
|
|
8
|
+
entityType: string;
|
|
9
|
+
entityId: string;
|
|
10
|
+
};
|
|
11
|
+
getEntityFromMappedRefId(mappedRefId: string): Promise<any>;
|
|
12
|
+
getFederationRecordsFromIds(ids: string[]): Promise<FederationRecord[]>;
|
|
13
|
+
getFederationRecordsFromIdsBulk(ids: string[]): Promise<FederationRecord[]>;
|
|
14
|
+
splitIntoChunksByLen(arr: any, len: any): any[];
|
|
15
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Federation = void 0;
|
|
7
|
+
const sdk_1 = require("@contrail/sdk");
|
|
8
|
+
const p_limit_1 = __importDefault(require("p-limit"));
|
|
9
|
+
const limit = (0, p_limit_1.default)(30);
|
|
10
|
+
const FED_CONFIG = {
|
|
11
|
+
appIdentifier: '@vibeiq/flexplm-connector',
|
|
12
|
+
federationSchema: 'DEFAULT'
|
|
13
|
+
};
|
|
14
|
+
class Federation {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.CHUNK_SIZE = 50;
|
|
17
|
+
}
|
|
18
|
+
async getFederatedMappedRefId(entityType, entityId) {
|
|
19
|
+
const criteria = {
|
|
20
|
+
reference: entityType + ':' + entityId,
|
|
21
|
+
appIdentifier: FED_CONFIG.appIdentifier,
|
|
22
|
+
federationSchema: FED_CONFIG.federationSchema
|
|
23
|
+
};
|
|
24
|
+
console.log('getFederatedMappedRefId: ' + JSON.stringify(criteria));
|
|
25
|
+
const fedRecords = await new sdk_1.Entities().get({
|
|
26
|
+
entityName: 'federation',
|
|
27
|
+
criteria
|
|
28
|
+
});
|
|
29
|
+
const federatedId = (fedRecords[0])
|
|
30
|
+
? fedRecords[0]['mappedReference']
|
|
31
|
+
: '';
|
|
32
|
+
return federatedId;
|
|
33
|
+
}
|
|
34
|
+
async createFederatedRecord(eventBody) {
|
|
35
|
+
const itemResults = eventBody.payload;
|
|
36
|
+
for (let i = 0; i < itemResults.length; i++) {
|
|
37
|
+
if (!itemResults[i].federatedId) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const payload = {
|
|
41
|
+
appIdentifier: FED_CONFIG.appIdentifier,
|
|
42
|
+
reference: itemResults[i].entityReference,
|
|
43
|
+
mappedReference: itemResults[i].federatedId,
|
|
44
|
+
federationSchema: FED_CONFIG.federationSchema
|
|
45
|
+
};
|
|
46
|
+
try {
|
|
47
|
+
const results = await new sdk_1.Entities().create({ entityName: 'federation', object: payload });
|
|
48
|
+
return results;
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
console.log('createFederatedRecord-error: ', error);
|
|
52
|
+
throw new Error('Error creating federation record: ' + error.message);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async getFederationRecordFromMappedRefId(mappedRefId) {
|
|
57
|
+
const criteria = {
|
|
58
|
+
appIdentifier: FED_CONFIG.appIdentifier,
|
|
59
|
+
mappedReference: mappedRefId,
|
|
60
|
+
federationSchema: FED_CONFIG.federationSchema
|
|
61
|
+
};
|
|
62
|
+
try {
|
|
63
|
+
const fedRecords = await new sdk_1.Entities().get({
|
|
64
|
+
entityName: 'federation',
|
|
65
|
+
criteria
|
|
66
|
+
});
|
|
67
|
+
return (fedRecords && fedRecords[0]) ? fedRecords[0] : undefined;
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
console.log('getFederationData-error: ' + e.message);
|
|
71
|
+
}
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
static getEntityId(fedRecord) {
|
|
75
|
+
const entityString = fedRecord['reference'];
|
|
76
|
+
const entitySplit = entityString.split(':');
|
|
77
|
+
const entityType = entitySplit[0];
|
|
78
|
+
const entityId = entitySplit[1];
|
|
79
|
+
return { entityType, entityId };
|
|
80
|
+
}
|
|
81
|
+
async getEntityFromMappedRefId(mappedRefId) {
|
|
82
|
+
const fedRecord = await this.getFederationRecordFromMappedRefId(mappedRefId);
|
|
83
|
+
console.log('fedRecord: ' + JSON.stringify(fedRecord));
|
|
84
|
+
if (!fedRecord) {
|
|
85
|
+
console.log('Federation Record doesnt exist. Cant get entity!');
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const { entityType, entityId } = Federation.getEntityId(fedRecord);
|
|
89
|
+
const criteria = {
|
|
90
|
+
id: entityId
|
|
91
|
+
};
|
|
92
|
+
const entities = await new sdk_1.Entities().get({
|
|
93
|
+
entityName: entityType,
|
|
94
|
+
criteria
|
|
95
|
+
});
|
|
96
|
+
const entity = (entities && entities[0]) ? entities[0] : undefined;
|
|
97
|
+
return entity;
|
|
98
|
+
}
|
|
99
|
+
async getFederationRecordsFromIds(ids) {
|
|
100
|
+
const fedRecords = [];
|
|
101
|
+
for (let i = 0; i < ids.length; i++) {
|
|
102
|
+
const criteria = {
|
|
103
|
+
reference: ids[i],
|
|
104
|
+
appIdentifier: FED_CONFIG.appIdentifier,
|
|
105
|
+
federationSchema: FED_CONFIG.federationSchema
|
|
106
|
+
};
|
|
107
|
+
const recs = await new sdk_1.Entities().get({
|
|
108
|
+
entityName: 'federation',
|
|
109
|
+
criteria
|
|
110
|
+
});
|
|
111
|
+
if (recs[0]) {
|
|
112
|
+
fedRecords.push(recs[0]);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return fedRecords;
|
|
116
|
+
}
|
|
117
|
+
async getFederationRecordsFromIdsBulk(ids) {
|
|
118
|
+
const chunks = this.splitIntoChunksByLen(ids, this.CHUNK_SIZE);
|
|
119
|
+
const fedRecords = [];
|
|
120
|
+
const federatedPromises = [];
|
|
121
|
+
const entities = new sdk_1.Entities();
|
|
122
|
+
for (const chunk of chunks) {
|
|
123
|
+
const fedPromise = limit(async () => {
|
|
124
|
+
const criteria = {
|
|
125
|
+
references: chunk,
|
|
126
|
+
appIdentifier: FED_CONFIG.appIdentifier,
|
|
127
|
+
federationSchema: FED_CONFIG.federationSchema
|
|
128
|
+
};
|
|
129
|
+
const records = await entities.get({
|
|
130
|
+
entityName: 'federation',
|
|
131
|
+
criteria
|
|
132
|
+
});
|
|
133
|
+
fedRecords.push(...records);
|
|
134
|
+
});
|
|
135
|
+
federatedPromises.push(fedPromise);
|
|
136
|
+
}
|
|
137
|
+
await Promise.all(federatedPromises);
|
|
138
|
+
return fedRecords;
|
|
139
|
+
}
|
|
140
|
+
splitIntoChunksByLen(arr, len) {
|
|
141
|
+
const chunks = [], n = arr?.length;
|
|
142
|
+
let i = 0;
|
|
143
|
+
while (i < n) {
|
|
144
|
+
chunks.push(arr.slice(i, i += len));
|
|
145
|
+
}
|
|
146
|
+
return chunks;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.Federation = Federation;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { FCConfig, FlexPLMResponseData, PayloadType } from '../interfaces/interfaces';
|
|
2
|
+
export declare class FlexPLMConnect {
|
|
3
|
+
private config;
|
|
4
|
+
private vibeEventEndpoint;
|
|
5
|
+
private staticHeaders;
|
|
6
|
+
payloadSendAsArray: boolean;
|
|
7
|
+
constructor(_config: FCConfig, endPoint?: any, payloadAsArray?: any);
|
|
8
|
+
private getRequestOptions;
|
|
9
|
+
getCSRF(): Promise<{
|
|
10
|
+
nonce_key: any;
|
|
11
|
+
nonce: any;
|
|
12
|
+
}>;
|
|
13
|
+
sendRequest(csrf: any, payload: any): Promise<Response>;
|
|
14
|
+
protected processRequest(payload: any): Promise<FlexPLMResponseData>;
|
|
15
|
+
sendToFlexPLM(payload: PayloadType): Promise<FlexPLMResponseData>;
|
|
16
|
+
sendMultipleToFlexPLM(payload: PayloadType[]): Promise<FlexPLMResponseData>;
|
|
17
|
+
getRequest(params?: {
|
|
18
|
+
urlPath?: string;
|
|
19
|
+
includeUrlContext?: boolean;
|
|
20
|
+
returnFullResponse?: boolean;
|
|
21
|
+
}): Promise<Response | unknown>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FlexPLMConnect = void 0;
|
|
4
|
+
const app_framework_1 = require("@contrail/app-framework");
|
|
5
|
+
class FlexPLMConnect {
|
|
6
|
+
constructor(_config, endPoint = undefined, payloadAsArray = undefined) {
|
|
7
|
+
this.vibeEventEndpoint = '';
|
|
8
|
+
this.staticHeaders = undefined;
|
|
9
|
+
this.payloadSendAsArray = true;
|
|
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
|
+
getRequestOptions(method) {
|
|
22
|
+
const csrfOptions = {
|
|
23
|
+
method,
|
|
24
|
+
headers: {
|
|
25
|
+
'Content-Type': 'application/json',
|
|
26
|
+
PLM_ENV: this.config.plmEnviornment,
|
|
27
|
+
Authorization: 'Basic ' + Buffer.from(`${this.config.userName()}:${this.config.password()}`, 'binary').toString('base64')
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
if (this.staticHeaders) {
|
|
31
|
+
Object.assign(csrfOptions.headers, this.staticHeaders);
|
|
32
|
+
}
|
|
33
|
+
if (app_framework_1.Logger.isInfoOn()) {
|
|
34
|
+
const logOptions = JSON.parse(JSON.stringify(csrfOptions));
|
|
35
|
+
logOptions['headers']['Authorization'] = logOptions?.headers?.Authorization.substring(0, 9);
|
|
36
|
+
console.info('csrfOptions: ' + JSON.stringify(logOptions));
|
|
37
|
+
}
|
|
38
|
+
return csrfOptions;
|
|
39
|
+
}
|
|
40
|
+
async getCSRF() {
|
|
41
|
+
const urlContext = this.config.urlContext;
|
|
42
|
+
const csrfEndpoint = this.config.csrfEndpoint;
|
|
43
|
+
const csrfURL = this.config.apiHost + urlContext + csrfEndpoint;
|
|
44
|
+
console.info('csrfURL: ' + csrfURL);
|
|
45
|
+
const csrfOptions = this.getRequestOptions('GET');
|
|
46
|
+
const response = await fetch(csrfURL, csrfOptions);
|
|
47
|
+
if (response.status >= 300) {
|
|
48
|
+
const message = 'Error connecting to FlexPLM:status: ' + response.status;
|
|
49
|
+
console.error(message);
|
|
50
|
+
console.error(await response.text());
|
|
51
|
+
const e = new Error(message);
|
|
52
|
+
e['httpResponseStatus'] = response.status;
|
|
53
|
+
throw e;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const body = await response.json();
|
|
57
|
+
const nonce_key = body.items[0].attributes.nonce_key;
|
|
58
|
+
const nonce = body.items[0].attributes.nonce;
|
|
59
|
+
console.info('nonce_key: ' + nonce_key);
|
|
60
|
+
console.info('nonce: ' + nonce);
|
|
61
|
+
return {
|
|
62
|
+
nonce_key,
|
|
63
|
+
nonce
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
const message = 'Error connecting to FlexPLM: ' + e.message;
|
|
68
|
+
console.error(message);
|
|
69
|
+
console.error(await response.text());
|
|
70
|
+
throw new Error(message);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async sendRequest(csrf, payload) {
|
|
74
|
+
if (this.payloadSendAsArray && !Array.isArray(payload)) {
|
|
75
|
+
payload = [payload];
|
|
76
|
+
}
|
|
77
|
+
const xferOptions = this.getRequestOptions('POST');
|
|
78
|
+
xferOptions['body'] = JSON.stringify(payload);
|
|
79
|
+
xferOptions.headers[csrf.nonce_key] = csrf.nonce;
|
|
80
|
+
const urlContext = this.config.urlContext;
|
|
81
|
+
const vibeEventsURL = this.config.apiHost + urlContext + '/servlet/rest' + this.vibeEventEndpoint;
|
|
82
|
+
if (app_framework_1.Logger.isInfoOn()) {
|
|
83
|
+
console.info('Request:');
|
|
84
|
+
console.info('vibeEventsURL: ' + vibeEventsURL);
|
|
85
|
+
const logOptions = JSON.parse(JSON.stringify(xferOptions));
|
|
86
|
+
logOptions['headers']['Authorization'] = logOptions?.headers?.Authorization.substring(0, 9);
|
|
87
|
+
console.info('csrfOptions: ' + JSON.stringify(logOptions));
|
|
88
|
+
console.info('Making call to xfer data to FlexPLM');
|
|
89
|
+
}
|
|
90
|
+
const eventResponse = await fetch(vibeEventsURL, xferOptions);
|
|
91
|
+
return eventResponse;
|
|
92
|
+
}
|
|
93
|
+
async processRequest(payload) {
|
|
94
|
+
if (!payload) {
|
|
95
|
+
const message = 'No payload to send to FlexPLM';
|
|
96
|
+
console.error(message);
|
|
97
|
+
throw new Error(message);
|
|
98
|
+
}
|
|
99
|
+
if (app_framework_1.Logger.isInfoOn()) {
|
|
100
|
+
console.info('payload: ' + JSON.stringify(payload));
|
|
101
|
+
}
|
|
102
|
+
const csrf = await this.getCSRF();
|
|
103
|
+
if (!csrf) {
|
|
104
|
+
const message = 'Failed to get CSRF nonce';
|
|
105
|
+
console.error(message);
|
|
106
|
+
throw new Error(message);
|
|
107
|
+
}
|
|
108
|
+
const response = await this.sendRequest(csrf, payload);
|
|
109
|
+
const status = response.status;
|
|
110
|
+
if (status >= 300) {
|
|
111
|
+
const message = 'Error sending data to FlexPLM:status: ' + response.status;
|
|
112
|
+
console.error(message);
|
|
113
|
+
console.error(await response.text());
|
|
114
|
+
const e = new Error(message);
|
|
115
|
+
e['httpResponseStatus'] = status;
|
|
116
|
+
throw e;
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
const res = {
|
|
120
|
+
status,
|
|
121
|
+
};
|
|
122
|
+
if (![204, 205].includes(status)) {
|
|
123
|
+
try {
|
|
124
|
+
const data = await response.json();
|
|
125
|
+
res.data = data;
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
console.error('Error getting response body. Setting {} body: ' + e);
|
|
129
|
+
res.data = {};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
console.log('eventResponse.status: ' + status);
|
|
133
|
+
return res;
|
|
134
|
+
}
|
|
135
|
+
catch (e) {
|
|
136
|
+
const message = 'Error getting json data from FlexPLM: ' + e.message;
|
|
137
|
+
console.error(message);
|
|
138
|
+
console.error(await response.text());
|
|
139
|
+
throw new Error(message);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async sendToFlexPLM(payload) {
|
|
143
|
+
return await this.processRequest(payload);
|
|
144
|
+
}
|
|
145
|
+
async sendMultipleToFlexPLM(payload) {
|
|
146
|
+
return await this.processRequest(payload);
|
|
147
|
+
}
|
|
148
|
+
async getRequest(params) {
|
|
149
|
+
const { urlPath, includeUrlContext = true, returnFullResponse = false } = params || {};
|
|
150
|
+
const urlContext = includeUrlContext ? this.config.urlContext : '';
|
|
151
|
+
const path = urlPath || ('/servlet/rest' + this.vibeEventEndpoint);
|
|
152
|
+
const vibeEventsURL = this.config.apiHost + urlContext + path;
|
|
153
|
+
const csrfOptions = this.getRequestOptions('GET');
|
|
154
|
+
const response = await fetch(vibeEventsURL, csrfOptions);
|
|
155
|
+
if (response.status >= 300) {
|
|
156
|
+
const message = 'Error connecting to FlexPLM:status: ' + response.status;
|
|
157
|
+
console.error(message);
|
|
158
|
+
console.error(await response.text());
|
|
159
|
+
throw new Error(message);
|
|
160
|
+
}
|
|
161
|
+
if (returnFullResponse) {
|
|
162
|
+
return response;
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
const data = await response.json();
|
|
166
|
+
return data;
|
|
167
|
+
}
|
|
168
|
+
catch (e) {
|
|
169
|
+
const message = 'Error getting json data from FlexPLM: ' + e.message;
|
|
170
|
+
console.error(message);
|
|
171
|
+
console.error(await response.text());
|
|
172
|
+
throw new Error(message);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
exports.FlexPLMConnect = FlexPLMConnect;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const flexplm_connect_1 = require("./flexplm-connect");
|
|
4
|
+
const mockJsonData = { items: [{ id: '123', name: 'test' }] };
|
|
5
|
+
const mockResponse = (status, json = mockJsonData) => ({
|
|
6
|
+
status,
|
|
7
|
+
json: jest.fn().mockResolvedValue(json),
|
|
8
|
+
text: jest.fn().mockResolvedValue('error text'),
|
|
9
|
+
});
|
|
10
|
+
const globalFetch = global.fetch;
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
global.fetch = jest.fn().mockResolvedValue(mockResponse(200));
|
|
13
|
+
});
|
|
14
|
+
afterAll(() => {
|
|
15
|
+
global.fetch = globalFetch;
|
|
16
|
+
});
|
|
17
|
+
const createConfig = (overrides) => ({
|
|
18
|
+
apiHost: 'https://flexplm.example.com',
|
|
19
|
+
urlContext: '/FlexPLM',
|
|
20
|
+
vibeEventEndpoint: '/api/events',
|
|
21
|
+
csrfEndpoint: '/csrf',
|
|
22
|
+
plmEnviornment: 'test',
|
|
23
|
+
userName: () => 'user',
|
|
24
|
+
password: () => 'pass',
|
|
25
|
+
itemPreDevelopmentLifecycleStages: [],
|
|
26
|
+
payloadDefaultAsArray: true,
|
|
27
|
+
...overrides,
|
|
28
|
+
});
|
|
29
|
+
describe('FlexPLMConnect.getRequest', () => {
|
|
30
|
+
it('should call default URL with urlContext when no params provided', async () => {
|
|
31
|
+
const connect = new flexplm_connect_1.FlexPLMConnect(createConfig());
|
|
32
|
+
await connect.getRequest();
|
|
33
|
+
expect(global.fetch).toHaveBeenCalledWith('https://flexplm.example.com/FlexPLM/servlet/rest/api/events', expect.objectContaining({ method: 'GET' }));
|
|
34
|
+
});
|
|
35
|
+
it('should use the constructor endpoint in the default URL', async () => {
|
|
36
|
+
const connect = new flexplm_connect_1.FlexPLMConnect(createConfig(), '/custom/endpoint');
|
|
37
|
+
await connect.getRequest();
|
|
38
|
+
expect(global.fetch).toHaveBeenCalledWith('https://flexplm.example.com/FlexPLM/servlet/rest/custom/endpoint', expect.any(Object));
|
|
39
|
+
});
|
|
40
|
+
it('should return parsed JSON by default', async () => {
|
|
41
|
+
const connect = new flexplm_connect_1.FlexPLMConnect(createConfig());
|
|
42
|
+
const result = await connect.getRequest();
|
|
43
|
+
expect(result).toEqual(mockJsonData);
|
|
44
|
+
});
|
|
45
|
+
it('should use urlPath when provided', async () => {
|
|
46
|
+
const connect = new flexplm_connect_1.FlexPLMConnect(createConfig());
|
|
47
|
+
await connect.getRequest({ urlPath: '/custom/path' });
|
|
48
|
+
expect(global.fetch).toHaveBeenCalledWith('https://flexplm.example.com/FlexPLM/custom/path', expect.any(Object));
|
|
49
|
+
});
|
|
50
|
+
it('should exclude urlContext when includeUrlContext is false', async () => {
|
|
51
|
+
const connect = new flexplm_connect_1.FlexPLMConnect(createConfig());
|
|
52
|
+
await connect.getRequest({ includeUrlContext: false });
|
|
53
|
+
expect(global.fetch).toHaveBeenCalledWith('https://flexplm.example.com/servlet/rest/api/events', expect.any(Object));
|
|
54
|
+
});
|
|
55
|
+
it('should exclude urlContext with custom urlPath', async () => {
|
|
56
|
+
const connect = new flexplm_connect_1.FlexPLMConnect(createConfig());
|
|
57
|
+
await connect.getRequest({ urlPath: '/custom/path', includeUrlContext: false });
|
|
58
|
+
expect(global.fetch).toHaveBeenCalledWith('https://flexplm.example.com/custom/path', expect.any(Object));
|
|
59
|
+
});
|
|
60
|
+
it('should return full response when returnFullResponse is true', async () => {
|
|
61
|
+
const rawResponse = mockResponse(200);
|
|
62
|
+
global.fetch.mockResolvedValue(rawResponse);
|
|
63
|
+
const connect = new flexplm_connect_1.FlexPLMConnect(createConfig());
|
|
64
|
+
const result = await connect.getRequest({ returnFullResponse: true });
|
|
65
|
+
expect(result).toBe(rawResponse);
|
|
66
|
+
expect(rawResponse.json).not.toHaveBeenCalled();
|
|
67
|
+
});
|
|
68
|
+
it('should throw on status >= 300', async () => {
|
|
69
|
+
global.fetch.mockResolvedValue(mockResponse(404));
|
|
70
|
+
const connect = new flexplm_connect_1.FlexPLMConnect(createConfig());
|
|
71
|
+
await expect(connect.getRequest()).rejects.toThrow('Error connecting to FlexPLM:status: 404');
|
|
72
|
+
});
|
|
73
|
+
it('should throw on status >= 300 even with returnFullResponse', async () => {
|
|
74
|
+
global.fetch.mockResolvedValue(mockResponse(500));
|
|
75
|
+
const connect = new flexplm_connect_1.FlexPLMConnect(createConfig());
|
|
76
|
+
await expect(connect.getRequest({ returnFullResponse: true })).rejects.toThrow('Error connecting to FlexPLM:status: 500');
|
|
77
|
+
});
|
|
78
|
+
it('should throw when response.json() fails', async () => {
|
|
79
|
+
const badResponse = {
|
|
80
|
+
status: 200,
|
|
81
|
+
json: jest.fn().mockRejectedValue(new Error('Invalid JSON')),
|
|
82
|
+
text: jest.fn().mockResolvedValue('not json'),
|
|
83
|
+
};
|
|
84
|
+
global.fetch.mockResolvedValue(badResponse);
|
|
85
|
+
const connect = new flexplm_connect_1.FlexPLMConnect(createConfig());
|
|
86
|
+
await expect(connect.getRequest()).rejects.toThrow('Error getting json data from FlexPLM: Invalid JSON');
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function setLoggerConfig(appConfig: any): Promise<void>;
|