@contrail/flexplm 1.3.0-alpha.0 → 1.3.0-alpha.4

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.
Files changed (124) hide show
  1. package/.claude/settings.local.json +2 -1
  2. package/.github/pull_request_template.md +31 -31
  3. package/.github/workflows/flexplm-lib.yml +27 -27
  4. package/CHANGELOG.md +1 -1
  5. package/lib/entity-processor/base-entity-processor.d.ts +42 -0
  6. package/lib/entity-processor/base-entity-processor.js +377 -0
  7. package/lib/entity-processor/base-entity-processor.spec.d.ts +1 -0
  8. package/lib/entity-processor/base-entity-processor.spec.js +426 -0
  9. package/lib/flexplm-request.d.ts +3 -0
  10. package/lib/flexplm-request.js +34 -0
  11. package/lib/flexplm-utils.d.ts +5 -0
  12. package/lib/flexplm-utils.js +33 -0
  13. package/lib/flexplm-utils.spec.d.ts +1 -0
  14. package/lib/flexplm-utils.spec.js +26 -0
  15. package/lib/index.d.ts +22 -0
  16. package/lib/index.js +38 -0
  17. package/lib/interfaces/interfaces.d.ts +105 -0
  18. package/lib/interfaces/interfaces.js +2 -0
  19. package/lib/interfaces/item-family-changes.d.ts +20 -0
  20. package/lib/interfaces/item-family-changes.js +56 -0
  21. package/lib/interfaces/publish-change-data.d.ts +19 -0
  22. package/lib/interfaces/publish-change-data.js +32 -0
  23. package/lib/publish/base-process-publish-assortment-callback.d.ts +9 -0
  24. package/lib/publish/base-process-publish-assortment-callback.js +38 -0
  25. package/lib/publish/base-process-publish-assortment.d.ts +93 -0
  26. package/lib/publish/base-process-publish-assortment.js +944 -0
  27. package/lib/publish/base-process-publish-assortment.spec.d.ts +1 -0
  28. package/lib/publish/base-process-publish-assortment.spec.js +1670 -0
  29. package/lib/publish/mockData.d.ts +1389 -0
  30. package/lib/publish/mockData.js +4519 -0
  31. package/lib/transform/identifier-conversion-spec-mockData.d.ts +0 -0
  32. package/lib/transform/identifier-conversion-spec-mockData.js +444 -0
  33. package/lib/transform/identifier-conversion.d.ts +15 -0
  34. package/lib/transform/identifier-conversion.js +212 -0
  35. package/lib/transform/identifier-conversion.spec.d.ts +1 -0
  36. package/lib/transform/identifier-conversion.spec.js +339 -0
  37. package/lib/util/config-defaults.d.ts +8 -0
  38. package/lib/util/config-defaults.js +85 -0
  39. package/lib/util/config-defaults.spec.d.ts +1 -0
  40. package/lib/util/config-defaults.spec.js +293 -0
  41. package/lib/util/data-converter-spec-mockData.d.ts +0 -0
  42. package/lib/util/data-converter-spec-mockData.js +205 -0
  43. package/lib/util/data-converter.d.ts +39 -0
  44. package/lib/util/data-converter.js +592 -0
  45. package/lib/util/data-converter.spec.d.ts +1 -0
  46. package/lib/util/data-converter.spec.js +904 -0
  47. package/lib/util/error-response-object.d.ts +4 -0
  48. package/lib/util/error-response-object.js +47 -0
  49. package/lib/util/error-response-object.spec.d.ts +1 -0
  50. package/lib/util/error-response-object.spec.js +99 -0
  51. package/lib/util/event-short-message-status.d.ts +18 -0
  52. package/lib/util/event-short-message-status.js +22 -0
  53. package/lib/util/federation.d.ts +15 -0
  54. package/lib/util/federation.js +149 -0
  55. package/lib/util/flexplm-connect.d.ts +22 -0
  56. package/lib/util/flexplm-connect.js +176 -0
  57. package/lib/util/flexplm-connect.spec.d.ts +1 -0
  58. package/lib/util/flexplm-connect.spec.js +88 -0
  59. package/lib/util/logger-config.d.ts +1 -0
  60. package/lib/util/logger-config.js +26 -0
  61. package/lib/util/map-util-spec-mockData.d.ts +0 -0
  62. package/lib/util/map-util-spec-mockData.js +205 -0
  63. package/lib/util/map-utils.d.ts +6 -0
  64. package/lib/util/map-utils.js +15 -0
  65. package/lib/util/map-utils.spec.d.ts +1 -0
  66. package/lib/util/map-utils.spec.js +89 -0
  67. package/lib/util/mockData.d.ts +80 -0
  68. package/lib/util/mockData.js +103 -0
  69. package/lib/util/thumbnail-util.d.ts +34 -0
  70. package/lib/util/thumbnail-util.js +211 -0
  71. package/lib/util/thumbnail-util.spec.d.ts +1 -0
  72. package/lib/util/thumbnail-util.spec.js +398 -0
  73. package/lib/util/type-conversion-utils-spec-mockData.d.ts +0 -0
  74. package/lib/util/type-conversion-utils-spec-mockData.js +259 -0
  75. package/lib/util/type-conversion-utils.d.ts +23 -0
  76. package/lib/util/type-conversion-utils.js +266 -0
  77. package/lib/util/type-conversion-utils.spec.d.ts +1 -0
  78. package/lib/util/type-conversion-utils.spec.js +868 -0
  79. package/lib/util/type-defaults.d.ts +16 -0
  80. package/lib/util/type-defaults.js +221 -0
  81. package/lib/util/type-defaults.spec.d.ts +1 -0
  82. package/lib/util/type-defaults.spec.js +516 -0
  83. package/lib/util/type-utils.d.ts +13 -0
  84. package/lib/util/type-utils.js +114 -0
  85. package/lib/util/type-utils.spec.d.ts +1 -0
  86. package/lib/util/type-utils.spec.js +190 -0
  87. package/package.json +1 -1
  88. package/publish.bat +4 -4
  89. package/publish.sh +4 -4
  90. package/src/entity-processor/base-entity-processor.spec.ts +157 -0
  91. package/src/entity-processor/base-entity-processor.ts +21 -2
  92. package/src/flexplm-request.ts +28 -28
  93. package/src/flexplm-utils.spec.ts +27 -27
  94. package/src/flexplm-utils.ts +29 -29
  95. package/src/index.ts +21 -21
  96. package/src/interfaces/item-family-changes.ts +66 -66
  97. package/src/interfaces/publish-change-data.ts +42 -42
  98. package/src/publish/base-process-publish-assortment-callback.ts +50 -50
  99. package/src/transform/identifier-conversion-spec-mockData.ts +495 -495
  100. package/src/transform/identifier-conversion.spec.ts +353 -353
  101. package/src/transform/identifier-conversion.ts +281 -281
  102. package/src/util/config-defaults.spec.ts +350 -350
  103. package/src/util/config-defaults.ts +92 -92
  104. package/src/util/data-converter-spec-mockData.ts +230 -230
  105. package/src/util/error-response-object.spec.ts +115 -115
  106. package/src/util/error-response-object.ts +49 -49
  107. package/src/util/federation.ts +172 -172
  108. package/src/util/logger-config.ts +19 -19
  109. package/src/util/map-util-spec-mockData.ts +230 -230
  110. package/src/util/map-utils.spec.ts +102 -102
  111. package/src/util/map-utils.ts +40 -40
  112. package/src/util/mockData.ts +101 -97
  113. package/src/util/thumbnail-util.spec.ts +190 -0
  114. package/src/util/thumbnail-util.ts +126 -5
  115. package/src/util/type-conversion-utils.spec.ts +25 -25
  116. package/src/util/type-conversion-utils.ts +10 -9
  117. package/src/util/type-defaults.spec.ts +668 -668
  118. package/src/util/type-defaults.ts +280 -280
  119. package/src/util/type-utils.spec.ts +227 -227
  120. package/src/util/type-utils.ts +144 -144
  121. package/tsconfig.json +28 -26
  122. package/tslint.json +57 -57
  123. package/scripts/output.png +0 -0
  124. package/scripts/test-get-request.ts +0 -35
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "permissions": {
3
3
  "allow": [
4
- "Bash(npx jest:*)"
4
+ "Bash(npx jest:*)",
5
+ "Bash(npx tsc:*)"
5
6
  ]
6
7
  }
7
8
  }
@@ -1,31 +1,31 @@
1
- ## What
2
- - [ ] Bugfix
3
- - [ ] Feature
4
- - [ ] Enhancement
5
-
6
- Description:
7
- <!--
8
- Describe the functional changes of the PR.
9
-
10
- If the mechanism of your change are complex, describe them in detail as you
11
- would if you were explaining them to a team mate.
12
-
13
- If the PR is simple, there is no need to repeat yourself. A small description
14
- is sufficient.
15
- -->
16
-
17
- ## Why
18
- <!--
19
- why is this change needed? Same rules as with #What
20
- -->
21
-
22
-
23
- ## Testing added
24
- <!--
25
- Describe the testing you added to this PR
26
- -->
27
-
28
-
29
- ## Link to Jira ticket(s)
30
- https://vibe-team.atlassian.net/browse/VIBE-TICKET_NUMBER_HERE
31
-
1
+ ## What
2
+ - [ ] Bugfix
3
+ - [ ] Feature
4
+ - [ ] Enhancement
5
+
6
+ Description:
7
+ <!--
8
+ Describe the functional changes of the PR.
9
+
10
+ If the mechanism of your change are complex, describe them in detail as you
11
+ would if you were explaining them to a team mate.
12
+
13
+ If the PR is simple, there is no need to repeat yourself. A small description
14
+ is sufficient.
15
+ -->
16
+
17
+ ## Why
18
+ <!--
19
+ why is this change needed? Same rules as with #What
20
+ -->
21
+
22
+
23
+ ## Testing added
24
+ <!--
25
+ Describe the testing you added to this PR
26
+ -->
27
+
28
+
29
+ ## Link to Jira ticket(s)
30
+ https://vibe-team.atlassian.net/browse/VIBE-TICKET_NUMBER_HERE
31
+
@@ -1,27 +1,27 @@
1
- name: flexplm-lib-tests
2
- on:
3
- pull_request:
4
- workflow_dispatch: # allow running in github actions manually
5
- jobs:
6
- test:
7
- runs-on: ubuntu-24.04
8
- strategy:
9
- matrix:
10
- node-version: [22.14.0]
11
- steps:
12
- - name: Node.js
13
- uses: actions/setup-node@v3
14
- with:
15
- node-version: ${{ matrix.node-version }}
16
-
17
- - uses: actions/checkout@v3
18
-
19
- - name: NPM Install
20
- env:
21
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
22
- run: npm ci
23
-
24
- - name: Unit Tests -
25
- env:
26
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
27
- run: npm test
1
+ name: flexplm-lib-tests
2
+ on:
3
+ pull_request:
4
+ workflow_dispatch: # allow running in github actions manually
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-24.04
8
+ strategy:
9
+ matrix:
10
+ node-version: [22.14.0]
11
+ steps:
12
+ - name: Node.js
13
+ uses: actions/setup-node@v3
14
+ with:
15
+ node-version: ${{ matrix.node-version }}
16
+
17
+ - uses: actions/checkout@v3
18
+
19
+ - name: NPM Install
20
+ env:
21
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
22
+ run: npm ci
23
+
24
+ - name: Unit Tests -
25
+ env:
26
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
27
+ run: npm test
package/CHANGELOG.md CHANGED
@@ -7,7 +7,7 @@ Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- ## [1.1.67] - 2026-xx-xx
10
+ ## [1.2.1] - 2026-04-08
11
11
 
12
12
  ### Added
13
13
  - Added EventShortMessageStatus status values for adding items to projects functionality.
@@ -0,0 +1,42 @@
1
+ import { FCConfig, EntityPayloadType } from '../interfaces/interfaces';
2
+ import { DataConverter } from '../util/data-converter';
3
+ import { TypeUtils } from '../util/type-utils';
4
+ import { MapFileUtil } from '@contrail/transform-data';
5
+ export declare class IncomingEntityResponse {
6
+ entity: any;
7
+ earlyReturn: any;
8
+ }
9
+ export declare abstract class BaseEntityProcessor {
10
+ protected config: FCConfig;
11
+ protected dc: DataConverter;
12
+ protected mapFileUtil: MapFileUtil;
13
+ protected baseType: string;
14
+ protected typeUtil: TypeUtils;
15
+ protected transformMapFile: string;
16
+ protected entities: any;
17
+ protected orgSlug: string;
18
+ constructor(config: FCConfig, dc: DataConverter, mapFileUtil: MapFileUtil, baseType: string);
19
+ inbound(event: EntityPayloadType): Promise<any>;
20
+ handleIncomingUpsert(event: EntityPayloadType): Promise<any>;
21
+ getInboundStatusMessage(statusObject: any): string;
22
+ queryEntityWithSubTypeCriteria(entityType: string, entityTypePath: string, propertyCriteria: any): Promise<any[]>;
23
+ getCriteriaForEntity(entityType: string, entityTypePath: string, propertyCriteria: any): Promise<any>;
24
+ getRootTypePropertyKeys(rootType: any, propertyCriteria?: any): string[];
25
+ handleIncomingDelete(event: any): Promise<void>;
26
+ getTransformedData(event: any): Promise<any>;
27
+ getUpdatesForEntity(entity: any, inboundData: any): Promise<object>;
28
+ getVibeOwningKeys(entity: any): Promise<any[]>;
29
+ getVibeOwningKeysFromInbound(entity: any): Promise<any[]>;
30
+ createEntity(entityName: any, changes: any): Promise<any>;
31
+ updateEntity(entityName: any, entity: any, diffs: any): Promise<any>;
32
+ protected abstract getIncomingEntity(event: any, inboundData: any): Promise<IncomingEntityResponse>;
33
+ protected abstract getCreateEntity(inboundData: any): Promise<IncomingEntityResponse>;
34
+ outbound(event: any): Promise<any>;
35
+ handleOutgoingUpsert(entityType: any, event: any): Promise<any>;
36
+ getOutboundEntityUpdates(event: any, flexResponse: any): Promise<any>;
37
+ handleOutgoingDelete(entityType: any, event: any): Promise<void>;
38
+ protected abstract getOutgoingUpsertPayload(entityType: any, event: any): Promise<EntityPayloadType>;
39
+ protected triggerNewEvent(triggerKey: string, event: any): Promise<any>;
40
+ protected sendUpsertToFlexPLM(event: any): Promise<any>;
41
+ protected getEntityCurrentStateUpsertPayload(event: any): Promise<EntityPayloadType>;
42
+ }
@@ -0,0 +1,377 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseEntityProcessor = exports.IncomingEntityResponse = void 0;
4
+ const type_utils_1 = require("../util/type-utils");
5
+ const flexplm_connect_1 = require("../util/flexplm-connect");
6
+ const map_utils_1 = require("../util/map-utils");
7
+ const sdk_1 = require("@contrail/sdk");
8
+ const type_conversion_utils_1 = require("../util/type-conversion-utils");
9
+ const thumbnail_util_1 = require("../util/thumbnail-util");
10
+ const event_short_message_status_1 = require("../util/event-short-message-status");
11
+ const UNSUPPORTED_TYPE = 'Unsupported eventType.';
12
+ class IncomingEntityResponse {
13
+ }
14
+ exports.IncomingEntityResponse = IncomingEntityResponse;
15
+ class BaseEntityProcessor {
16
+ constructor(config, dc, mapFileUtil, baseType) {
17
+ this.config = config;
18
+ this.dc = dc;
19
+ this.mapFileUtil = mapFileUtil;
20
+ this.baseType = baseType;
21
+ this.typeUtil = new type_utils_1.TypeUtils();
22
+ this.transformMapFile = this.config?.transformMapFile;
23
+ this.entities = new sdk_1.Entities();
24
+ this.orgSlug = this.config?.orgSlug || 'unset-orgSlug';
25
+ }
26
+ async inbound(event) {
27
+ const eventType = event.eventType;
28
+ console.log(`inbound entity: ${eventType}:${event.objectClass}`);
29
+ switch (eventType) {
30
+ case 'PERSIST':
31
+ return await this.handleIncomingUpsert(event);
32
+ case 'DELETE':
33
+ return await this.handleIncomingDelete(event);
34
+ default:
35
+ console.error(UNSUPPORTED_TYPE);
36
+ return {
37
+ status: 500,
38
+ data: { UNSUPPORTED_TYPE }
39
+ };
40
+ }
41
+ }
42
+ async handleIncomingUpsert(event) {
43
+ const inboundData = await this.getTransformedData(event);
44
+ const incomingEntityResponse = await this.getIncomingEntity(event, inboundData);
45
+ if (incomingEntityResponse.earlyReturn) {
46
+ const statusMsg = this.getInboundStatusMessage({
47
+ status: event_short_message_status_1.EventShortMessageStatus.FAILURE,
48
+ statusMessage: incomingEntityResponse.earlyReturn.shortStatusMessage || '',
49
+ objectClass: event.objectClass,
50
+ federatedId: event.federatedId
51
+ });
52
+ console.log(statusMsg);
53
+ return incomingEntityResponse.earlyReturn;
54
+ }
55
+ const entity = incomingEntityResponse.entity;
56
+ if (!entity) {
57
+ const createEntityResponse = await this.getCreateEntity(inboundData);
58
+ if (createEntityResponse.earlyReturn) {
59
+ const status = (createEntityResponse.earlyReturn.shortStatusMessage === event_short_message_status_1.EventShortMessageStatus.NOT_CREATABLE)
60
+ ? event_short_message_status_1.EventShortMessageStatus.SUCCESS
61
+ : event_short_message_status_1.EventShortMessageStatus.FAILURE;
62
+ const statusMsg = this.getInboundStatusMessage({
63
+ status,
64
+ statusMessage: createEntityResponse.earlyReturn.shortStatusMessage || '',
65
+ objectClass: event.objectClass,
66
+ federatedId: event.federatedId
67
+ });
68
+ console.log(statusMsg);
69
+ return createEntityResponse.earlyReturn;
70
+ }
71
+ const createdEntity = await this.createEntity(this.baseType, createEntityResponse.entity);
72
+ const shouldSyncThumbnail = await type_conversion_utils_1.TypeConversionUtils.syncInboundImages(this.transformMapFile, this.mapFileUtil, event.data);
73
+ if (shouldSyncThumbnail) {
74
+ const thumbnailUpdates = await new thumbnail_util_1.ThumbnailUtil(this.config).syncThumbnailToVibeIQ({ entityId: createdEntity.id, primaryViewableId: createdEntity.primaryViewableId, event, entityName: this.baseType });
75
+ if (thumbnailUpdates) {
76
+ await this.updateEntity(this.baseType, createdEntity, thumbnailUpdates);
77
+ }
78
+ }
79
+ const statusMsg = this.getInboundStatusMessage({
80
+ status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
81
+ statusMessage: event_short_message_status_1.EventShortMessageStatus.CREATED,
82
+ objectClass: event.objectClass,
83
+ entityId: 'id',
84
+ federatedId: event.federatedId
85
+ });
86
+ console.log(statusMsg);
87
+ return createdEntity;
88
+ }
89
+ const diffs = await this.getUpdatesForEntity(entity, inboundData);
90
+ const shouldSyncThumbnail = await type_conversion_utils_1.TypeConversionUtils.syncInboundImages(this.transformMapFile, this.mapFileUtil, event.data);
91
+ let thumbnailUpdates;
92
+ if (shouldSyncThumbnail) {
93
+ thumbnailUpdates = await new thumbnail_util_1.ThumbnailUtil(this.config).syncThumbnailToVibeIQ({ entityId: entity.id, primaryViewableId: entity.primaryViewableId, event, entityName: this.baseType });
94
+ }
95
+ const allUpdates = { ...diffs, ...thumbnailUpdates };
96
+ if (Object.getOwnPropertyNames(allUpdates).length == 0) {
97
+ const statusMsg = this.getInboundStatusMessage({
98
+ status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
99
+ statusMessage: event_short_message_status_1.EventShortMessageStatus.NO_CHANGES,
100
+ objectClass: event.objectClass,
101
+ entityId: entity.id,
102
+ federatedId: event.federatedId
103
+ });
104
+ console.log(statusMsg);
105
+ const message = 'No Changes to persist for entity: ' + entity.id;
106
+ return {
107
+ status: 200,
108
+ data: { message }
109
+ };
110
+ }
111
+ const updatedEntity = await this.updateEntity(this.baseType, entity, allUpdates);
112
+ const statusMsg = this.getInboundStatusMessage({
113
+ status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
114
+ statusMessage: event_short_message_status_1.EventShortMessageStatus.UPDATED,
115
+ objectClass: event.objectClass,
116
+ entityId: entity.id,
117
+ federatedId: event.federatedId
118
+ });
119
+ console.log(statusMsg);
120
+ return updatedEntity;
121
+ }
122
+ getInboundStatusMessage(statusObject) {
123
+ return 'BaseEntityProcessor: inbound: status: ' + statusObject.status
124
+ + ', statusMessage: ' + statusObject.statusMessage
125
+ + ', entityType: ' + this.baseType
126
+ + ', entityId: ' + statusObject.entityId
127
+ + ', objectClass: ' + statusObject.objectClass
128
+ + ', federatedId: ' + statusObject.federatedId
129
+ + ', orgSlug: ' + this.orgSlug;
130
+ }
131
+ async queryEntityWithSubTypeCriteria(entityType, entityTypePath, propertyCriteria) {
132
+ if (!entityType || !entityTypePath) {
133
+ throw new Error('type and entityTypePath must be defined');
134
+ }
135
+ if (!propertyCriteria || Object.getOwnPropertyNames(propertyCriteria).length == 0) {
136
+ throw new Error('propertyCriteria must be defined and have at least one property');
137
+ }
138
+ const { rootTypeCriteria, subTypeCriteria } = await this.getCriteriaForEntity(entityType, entityTypePath, propertyCriteria);
139
+ const returnedEntities = await this.dc.getAllObjectReferences(entityType, rootTypeCriteria, subTypeCriteria);
140
+ return returnedEntities;
141
+ }
142
+ async getCriteriaForEntity(entityType, entityTypePath, propertyCriteria) {
143
+ if (!entityType || !entityTypePath) {
144
+ throw new Error('type and entityTypePath must be defined');
145
+ }
146
+ if (!propertyCriteria || Object.getOwnPropertyNames(propertyCriteria).length == 0) {
147
+ throw new Error('propertyCriteria must be defined and have at least one property');
148
+ }
149
+ const rootType = await this.typeUtil.getByRootAndPath({ root: entityType });
150
+ const rootTypePropertyKeys = await this.getRootTypePropertyKeys(rootType, propertyCriteria);
151
+ const rootTypeCriteria = {};
152
+ const subTypeCriteria = {};
153
+ if (entityType !== entityTypePath) {
154
+ subTypeCriteria['typePath'] = entityTypePath;
155
+ }
156
+ for (const key in propertyCriteria) {
157
+ if (rootTypePropertyKeys.includes(key)) {
158
+ rootTypeCriteria[key] = propertyCriteria[key];
159
+ }
160
+ else {
161
+ subTypeCriteria[key] = propertyCriteria[key];
162
+ }
163
+ }
164
+ return { rootTypeCriteria, subTypeCriteria };
165
+ }
166
+ getRootTypePropertyKeys(rootType, propertyCriteria = null) {
167
+ const props = rootType['typeProperties'];
168
+ const rootTypePropertyKeys = props.map(prop => prop.slug);
169
+ return rootTypePropertyKeys;
170
+ }
171
+ async handleIncomingDelete(event) {
172
+ console.warn('delete is not configured', event);
173
+ }
174
+ async getTransformedData(event) {
175
+ let inboundData = event.data;
176
+ console.debug('inboundData: ' + JSON.stringify(inboundData));
177
+ const mapKey = await type_conversion_utils_1.TypeConversionUtils.getMapKeyFromObject(this.transformMapFile, this.mapFileUtil, inboundData, type_conversion_utils_1.TypeConversionUtils.FLEX2VIBE_DIRECTION);
178
+ inboundData = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, inboundData, mapKey, type_conversion_utils_1.TypeConversionUtils.FLEX2VIBE_DIRECTION);
179
+ console.debug('Transformed-inboundData: ' + JSON.stringify(inboundData));
180
+ return inboundData;
181
+ }
182
+ async getUpdatesForEntity(entity, inboundData) {
183
+ const vibeOwningKeys = await this.getVibeOwningKeys(entity);
184
+ let updates = {
185
+ typeId: entity.typeId,
186
+ roles: entity.roles,
187
+ id: entity.id,
188
+ };
189
+ updates = await this.dc.setEntityValues(updates, inboundData, vibeOwningKeys);
190
+ for (const prop of ['typeId', 'roles', 'id']) {
191
+ delete updates[prop];
192
+ }
193
+ return this.dc.getPersistableChanges(entity, updates);
194
+ }
195
+ async getVibeOwningKeys(entity) {
196
+ let vibeOwningKeys = [];
197
+ if (this.transformMapFile && entity) {
198
+ const mapKey = await type_conversion_utils_1.TypeConversionUtils.getMapKey(this.transformMapFile, this.mapFileUtil, entity, type_conversion_utils_1.TypeConversionUtils.VIBE2FLEX_DIRECTION);
199
+ const mapSection = await map_utils_1.MapUtil.getFullMapSection(this.transformMapFile, this.mapFileUtil, mapKey);
200
+ vibeOwningKeys = mapSection?.vibeOwningKeys || [];
201
+ }
202
+ console.debug('vibeOwningKeys: ' + vibeOwningKeys);
203
+ return vibeOwningKeys;
204
+ }
205
+ async getVibeOwningKeysFromInbound(entity) {
206
+ let vibeOwningKeys = [];
207
+ if (this.transformMapFile && entity) {
208
+ const mapKey = await type_conversion_utils_1.TypeConversionUtils.getMapKeyFromObject(this.transformMapFile, this.mapFileUtil, entity, type_conversion_utils_1.TypeConversionUtils.FLEX2VIBE_DIRECTION);
209
+ const mapSection = await map_utils_1.MapUtil.getFullMapSection(this.transformMapFile, this.mapFileUtil, mapKey);
210
+ vibeOwningKeys = mapSection?.vibeOwningKeys || [];
211
+ }
212
+ console.debug('vibeOwningKeys: ' + vibeOwningKeys);
213
+ return vibeOwningKeys;
214
+ }
215
+ async createEntity(entityName, changes) {
216
+ const options = {
217
+ entityName: entityName,
218
+ object: changes,
219
+ };
220
+ console.log("createEntity: " + JSON.stringify(options));
221
+ return await new sdk_1.Entities().create(options);
222
+ }
223
+ async updateEntity(entityName, entity, diffs) {
224
+ const options = {
225
+ entityName: entityName,
226
+ id: entity['id'],
227
+ object: diffs
228
+ };
229
+ console.log('updateEntity: ' + JSON.stringify(options));
230
+ return await new sdk_1.Entities().update(options);
231
+ }
232
+ async outbound(event) {
233
+ const entityType = event.entityType;
234
+ const eventType = event.eventType;
235
+ const entityId = event.id;
236
+ console.log(`outbound: ${entityType}:${entityId}`);
237
+ switch (eventType) {
238
+ case 'update':
239
+ case 'create':
240
+ return await this.handleOutgoingUpsert(entityType, event);
241
+ case 'delete':
242
+ return await this.handleOutgoingDelete(entityType, event);
243
+ case 'sendUpsertToFlexPLM':
244
+ return await this.sendUpsertToFlexPLM(event);
245
+ default:
246
+ console.log(UNSUPPORTED_TYPE);
247
+ return {
248
+ status: 500,
249
+ data: { UNSUPPORTED_TYPE }
250
+ };
251
+ }
252
+ }
253
+ async handleOutgoingUpsert(entityType, event) {
254
+ const objectClass = await type_conversion_utils_1.TypeConversionUtils.getObjectClass(this.transformMapFile, this.mapFileUtil, event.newData);
255
+ if (!objectClass) {
256
+ const message = 'ObjectClass must have a value.';
257
+ console.log(message);
258
+ return {
259
+ status: 500,
260
+ data: { message }
261
+ };
262
+ }
263
+ try {
264
+ const payload = await this.getOutgoingUpsertPayload(entityType, event);
265
+ const flexResponse = await new flexplm_connect_1.FlexPLMConnect(this.config).sendToFlexPLM(payload);
266
+ const outboundEntityUpdates = await this.getOutboundEntityUpdates(event, flexResponse);
267
+ if (outboundEntityUpdates) {
268
+ flexResponse['outboundEntityUpdates'] = outboundEntityUpdates;
269
+ }
270
+ const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.SUCCESS
271
+ + ', statusMessage: ' + flexResponse.status
272
+ + ', entityType: ' + this.baseType
273
+ + ', entityId: ' + event.id
274
+ + ', objectClass: ' + payload.objectClass
275
+ + ', updateFromResponse: ' + ((outboundEntityUpdates && Object.keys(outboundEntityUpdates).length > 0) ? 'true' : 'false')
276
+ + ', orgSlug: ' + this.orgSlug;
277
+ console.log(statusMsg);
278
+ return flexResponse;
279
+ }
280
+ catch (e) {
281
+ const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.FAILURE
282
+ + ', statusMessage: ' + e.httpResponseStatus
283
+ + ', entityType: ' + this.baseType
284
+ + ', entityId: ' + event.id
285
+ + ', objectClass: ' + objectClass
286
+ + ', updateFromResponse: ' + 'false'
287
+ + ', orgSlug: ' + this.orgSlug;
288
+ console.log(statusMsg);
289
+ throw e;
290
+ }
291
+ }
292
+ async getOutboundEntityUpdates(event, flexResponse) {
293
+ const payload = flexResponse?.data?.payload;
294
+ const flexPayload = (payload) ? payload[0] : undefined;
295
+ let outboundEntityUpdates = undefined;
296
+ if (flexPayload && 'OK' === flexPayload.status) {
297
+ if (flexPayload.data && !flexPayload.data?.flexPLMObjectClass) {
298
+ flexPayload.data.flexPLMObjectClass = flexPayload.objectClass;
299
+ }
300
+ const inboundData = await this.getTransformedData(flexPayload);
301
+ outboundEntityUpdates = await this.getUpdatesForEntity(event.newData, inboundData);
302
+ }
303
+ return outboundEntityUpdates;
304
+ }
305
+ async handleOutgoingDelete(entityType, event) {
306
+ console.warn('delete is not configured', entityType, event.oldData);
307
+ }
308
+ async triggerNewEvent(triggerKey, event) {
309
+ const newEvent = {
310
+ entityName: 'event-workflow-request',
311
+ object: {
312
+ triggerKey,
313
+ event
314
+ }
315
+ };
316
+ const response = await this.entities.create(newEvent);
317
+ return response;
318
+ }
319
+ async sendUpsertToFlexPLM(event) {
320
+ const payload = await this.getEntityCurrentStateUpsertPayload(event);
321
+ if (!payload) {
322
+ const message = 'No payload to send to FlexPLM';
323
+ console.log(message);
324
+ return {
325
+ status: 500,
326
+ data: { message }
327
+ };
328
+ }
329
+ ;
330
+ let objectClass = payload.objectClass;
331
+ try {
332
+ const flexResponse = await new flexplm_connect_1.FlexPLMConnect(this.config).sendToFlexPLM(payload);
333
+ const outboundEntityUpdates = await this.getOutboundEntityUpdates(event, flexResponse);
334
+ if (outboundEntityUpdates) {
335
+ flexResponse['outboundEntityUpdates'] = outboundEntityUpdates;
336
+ }
337
+ const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.SUCCESS
338
+ + ', statusMessage: ' + flexResponse.status
339
+ + ', entityType: ' + this.baseType
340
+ + ', entityId: ' + event.id
341
+ + ', objectClass: ' + objectClass
342
+ + ', updateFromResponse: ' + ((outboundEntityUpdates && Object.keys(outboundEntityUpdates).length > 0) ? 'true' : 'false')
343
+ + ', orgSlug: ' + this.orgSlug;
344
+ console.log(statusMsg);
345
+ return flexResponse;
346
+ }
347
+ catch (e) {
348
+ const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.FAILURE
349
+ + ', statusMessage: ' + e.httpResponseStatus
350
+ + ', entityType: ' + this.baseType
351
+ + ', entityId: ' + event.id
352
+ + ', objectClass: ' + objectClass
353
+ + ', updateFromResponse: ' + 'false'
354
+ + ', orgSlug: ' + this.orgSlug;
355
+ console.log(statusMsg);
356
+ throw e;
357
+ }
358
+ }
359
+ async getEntityCurrentStateUpsertPayload(event) {
360
+ const id = event.id;
361
+ if (!id) {
362
+ return undefined;
363
+ }
364
+ const entity = await this.entities.get({
365
+ entityName: this.baseType,
366
+ id
367
+ });
368
+ if (!entity) {
369
+ return undefined;
370
+ }
371
+ event.newData = entity;
372
+ event.oldData = entity;
373
+ const payload = await this.getOutgoingUpsertPayload(this.baseType, event);
374
+ return payload;
375
+ }
376
+ }
377
+ exports.BaseEntityProcessor = BaseEntityProcessor;