@contrail/flexplm 2.0.0-alpha.fe82e73 → 3.0.0-alpha.9e154b3
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/entity-processor/base-entity-processor.d.ts +0 -29
- package/lib/entity-processor/base-entity-processor.js +143 -238
- package/lib/entity-processor/base-entity-processor.spec.js +0 -210
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/lib/interfaces/interfaces.d.ts +1 -1
- package/lib/publish/base-process-publish-assortment-callback.js +0 -30
- package/lib/publish/base-process-publish-assortment.d.ts +0 -24
- package/lib/publish/base-process-publish-assortment.js +132 -238
- package/lib/publish/base-process-publish-assortment.spec.js +0 -188
- package/lib/util/config-defaults.js +0 -2
- package/lib/util/error-response-object.js +0 -2
- package/lib/util/flexplm-connect.d.ts +9 -4
- package/lib/util/flexplm-connect.js +172 -202
- package/lib/util/flexplm-connect.spec.js +166 -2
- package/lib/util/thumbnail-util.d.ts +1 -2
- package/lib/util/thumbnail-util.js +6 -34
- package/lib/util/thumbnail-util.spec.js +0 -42
- package/lib/util/type-utils.d.ts +3 -3
- package/package.json +19 -13
- package/lib/__tests__/telemetry-test-utils.d.ts +0 -8
- package/lib/__tests__/telemetry-test-utils.js +0 -30
- package/lib/publish/base-process-publish-assortment-callback.spec.d.ts +0 -1
- package/lib/publish/base-process-publish-assortment-callback.spec.js +0 -62
- package/lib/util/flexplm-connect.telemetry.spec.d.ts +0 -1
- package/lib/util/flexplm-connect.telemetry.spec.js +0 -212
- package/lib/util/telemetry-attributes.d.ts +0 -68
- package/lib/util/telemetry-attributes.js +0 -73
- package/lib/util/telemetry-utils.d.ts +0 -3
- package/lib/util/telemetry-utils.js +0 -10
|
@@ -11,12 +11,6 @@ const fsPromise = require("fs/promises");
|
|
|
11
11
|
const path = require("path");
|
|
12
12
|
const app_framework_1 = require("@contrail/app-framework");
|
|
13
13
|
const event_short_message_status_1 = require("../util/event-short-message-status");
|
|
14
|
-
const telemetry_1 = require("@contrail/telemetry");
|
|
15
|
-
const api_1 = require("@opentelemetry/api");
|
|
16
|
-
const telemetry_attributes_1 = require("../util/telemetry-attributes");
|
|
17
|
-
const telemetry_utils_1 = require("../util/telemetry-utils");
|
|
18
|
-
const PUBLISH_FILE_HYDRATED_DETAIL = 'hydrated_detail';
|
|
19
|
-
const PUBLISH_FILE_BASELINE = 'baseline';
|
|
20
14
|
class BaseProcessPublishAssortment {
|
|
21
15
|
constructor(_config, _dc, _mapFileUtil) {
|
|
22
16
|
this.TTL = 30 * 24 * 60 * 60 * 1000; // 30 days
|
|
@@ -30,119 +24,61 @@ class BaseProcessPublishAssortment {
|
|
|
30
24
|
this.orgSlug = this.config?.orgSlug || 'unset-orgSlug';
|
|
31
25
|
}
|
|
32
26
|
async process(event) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
});
|
|
27
|
+
const assortmentPublishChangeId = event.assortmentPublishChangeId;
|
|
28
|
+
let apcHistory;
|
|
29
|
+
let publisher;
|
|
30
|
+
const assortmentId = event.assortmentId;
|
|
31
|
+
try {
|
|
32
|
+
console.info('process-start: assortmentId: ' + assortmentId
|
|
33
|
+
+ ', assortmentPublishChangeId: ' + assortmentPublishChangeId);
|
|
34
|
+
let seasonFed;
|
|
42
35
|
try {
|
|
43
|
-
|
|
44
|
-
try {
|
|
45
|
-
seasonFed = await this.getSeasonFederation(assortmentId);
|
|
46
|
-
}
|
|
47
|
-
catch (e) {
|
|
48
|
-
const message = e.message;
|
|
49
|
-
const eventStatus = (message.includes(BaseProcessPublishAssortment.ASSORTMENT_NOT_PUBLISHABLE)) ? event_short_message_status_1.EventShortMessageStatus.NOT_PUBLISHABLE :
|
|
50
|
-
(message.startsWith(BaseProcessPublishAssortment.ASSORTMENT_NO_FED_INFO)) ? event_short_message_status_1.EventShortMessageStatus.NO_FEDERATION_INFO :
|
|
51
|
-
event_short_message_status_1.EventShortMessageStatus.FAILURE;
|
|
52
|
-
if (eventStatus === event_short_message_status_1.EventShortMessageStatus.FAILURE) {
|
|
53
|
-
span.recordException(e);
|
|
54
|
-
span.setStatus({ code: api_1.SpanStatusCode.ERROR, message });
|
|
55
|
-
}
|
|
56
|
-
this.recordPublishStatus({
|
|
57
|
-
status: eventStatus,
|
|
58
|
-
assortmentId,
|
|
59
|
-
assortmentPublishChangeId,
|
|
60
|
-
message,
|
|
61
|
-
// Only an unexpected error is swallowed here; the other two are expected skips.
|
|
62
|
-
error: eventStatus === event_short_message_status_1.EventShortMessageStatus.FAILURE ? e : undefined,
|
|
63
|
-
});
|
|
64
|
-
const output = {
|
|
65
|
-
results: { message, event },
|
|
66
|
-
skip_await: true
|
|
67
|
-
};
|
|
68
|
-
return output;
|
|
69
|
-
}
|
|
70
|
-
apcHistory = await this.getApcHistory(assortmentId);
|
|
71
|
-
const sinceDate = await this.getSinceDate(assortmentId, assortmentPublishChangeId, apcHistory);
|
|
72
|
-
//Get detail information
|
|
73
|
-
const assortmentPublishChange = await this.downloadAssortmentPublishChange(assortmentId, assortmentPublishChangeId);
|
|
74
|
-
publisher = this.getPublisher(assortmentPublishChange);
|
|
75
|
-
const changeDetail = await this.downloadHydratedChangeDetail(assortmentPublishChange);
|
|
76
|
-
// Without the change detail the counts are unknown, not zero; failed_downloads says why.
|
|
77
|
-
if (changeDetail) {
|
|
78
|
-
span.setAttributes({
|
|
79
|
-
[telemetry_attributes_1.ATTR_FLEXPLM_PUBLISH_ADDED_COUNT]: changeDetail.adds?.length ?? 0,
|
|
80
|
-
[telemetry_attributes_1.ATTR_FLEXPLM_PUBLISH_REMOVED_COUNT]: changeDetail.deletes?.length ?? 0,
|
|
81
|
-
[telemetry_attributes_1.ATTR_FLEXPLM_PUBLISH_CHANGED_COUNT]: changeDetail.updates?.length ?? 0,
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
const assortmentBaseline = await this.downloadAssortmentBaseline(assortmentPublishChange);
|
|
85
|
-
const failedDownloads = [!changeDetail && PUBLISH_FILE_HYDRATED_DETAIL, !assortmentBaseline && PUBLISH_FILE_BASELINE].filter(Boolean);
|
|
86
|
-
if (failedDownloads.length > 0) {
|
|
87
|
-
span.setAttribute(telemetry_attributes_1.ATTR_FLEXPLM_PUBLISH_FAILED_DOWNLOADS, failedDownloads);
|
|
88
|
-
}
|
|
89
|
-
const deleteChanges = await this.getDeleteChanges(assortmentPublishChange, apcHistory, assortmentBaseline, sinceDate);
|
|
90
|
-
const releasedForDevelopmentItemIds = this.getReleasedForDevelopmentItemAndFamilyIds(assortmentBaseline, deleteChanges);
|
|
91
|
-
const itemToFederatedIdMapping = await this.getItemFederatedIds( /*allItemIds*/);
|
|
92
|
-
const pcd = new publish_change_data_1.PublishChangeData(assortmentId, seasonFed, assortmentPublishChangeId, sinceDate, publisher);
|
|
93
|
-
pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
|
|
94
|
-
pcd.releasedForDevelopmentItemIds = releasedForDevelopmentItemIds;
|
|
95
|
-
const output = await this.processPublish(pcd, changeDetail, assortmentBaseline, deleteChanges);
|
|
96
|
-
output['publishInfo'] = await this.getPublishInfo(assortmentId, assortmentPublishChangeId, apcHistory, publisher);
|
|
97
|
-
return output;
|
|
36
|
+
seasonFed = await this.getSeasonFederation(assortmentId);
|
|
98
37
|
}
|
|
99
38
|
catch (e) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
39
|
+
const message = e.message;
|
|
40
|
+
const eventStatus = (message.includes(BaseProcessPublishAssortment.ASSORTMENT_NOT_PUBLISHABLE)) ? event_short_message_status_1.EventShortMessageStatus.NOT_PUBLISHABLE :
|
|
41
|
+
(message.startsWith(BaseProcessPublishAssortment.ASSORTMENT_NO_FED_INFO)) ? event_short_message_status_1.EventShortMessageStatus.NO_FEDERATION_INFO :
|
|
42
|
+
event_short_message_status_1.EventShortMessageStatus.FAILURE;
|
|
43
|
+
const processStatus = 'BaseProcessPublishAssortment: ' + eventStatus
|
|
44
|
+
+ ': assortmentId: ' + event.assortmentId + ': assortmentPublishChangeId: ' + event.assortmentPublishChangeId
|
|
45
|
+
+ ', orgSlug: ' + this.orgSlug;
|
|
46
|
+
console.log(JSON.stringify(processStatus));
|
|
47
|
+
console.log(message);
|
|
48
|
+
const output = {
|
|
49
|
+
results: { message, event },
|
|
50
|
+
skip_await: true
|
|
51
|
+
};
|
|
52
|
+
return output;
|
|
113
53
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
[
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
direction: 'publish', status, assortment_id: assortmentId, publish_change_id: assortmentPublishChangeId,
|
|
132
|
-
product_season_count: resultsCount?.productSeasons, colorway_season_count: resultsCount?.colorwaySeasons, reason: message,
|
|
133
|
-
sent_unrecorded: sentUnrecorded,
|
|
134
|
-
};
|
|
135
|
-
if (sentUnrecorded) {
|
|
136
|
-
telemetry_1.logger.error({ error, flexplm }, 'FlexPLM assortment publish sent but not recorded');
|
|
137
|
-
}
|
|
138
|
-
else if (status === event_short_message_status_1.EventShortMessageStatus.FAILURE) {
|
|
139
|
-
telemetry_1.logger.error({ error, flexplm }, 'FlexPLM assortment publish failed');
|
|
140
|
-
}
|
|
141
|
-
else if (status === event_short_message_status_1.EventShortMessageStatus.NO_FEDERATION_INFO) {
|
|
142
|
-
telemetry_1.logger.warn({ flexplm }, 'FlexPLM assortment publish skipped');
|
|
54
|
+
apcHistory = await this.getApcHistory(assortmentId);
|
|
55
|
+
const sinceDate = await this.getSinceDate(assortmentId, assortmentPublishChangeId, apcHistory);
|
|
56
|
+
//Get detail information
|
|
57
|
+
const assortmentPublishChange = await this.downloadAssortmentPublishChange(assortmentId, assortmentPublishChangeId);
|
|
58
|
+
publisher = this.getPublisher(assortmentPublishChange);
|
|
59
|
+
const changeDetail = await this.downloadHydratedChangeDetail(assortmentPublishChange);
|
|
60
|
+
const assortmentBaseline = await this.downloadAssortmentBaseline(assortmentPublishChange);
|
|
61
|
+
const deleteChanges = await this.getDeleteChanges(assortmentPublishChange, apcHistory, assortmentBaseline, sinceDate);
|
|
62
|
+
const releasedForDevelopmentItemIds = this.getReleasedForDevelopmentItemAndFamilyIds(assortmentBaseline, deleteChanges);
|
|
63
|
+
const itemToFederatedIdMapping = await this.getItemFederatedIds( /*allItemIds*/);
|
|
64
|
+
const pcd = new publish_change_data_1.PublishChangeData(assortmentId, seasonFed, assortmentPublishChangeId, sinceDate, publisher);
|
|
65
|
+
pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
|
|
66
|
+
pcd.releasedForDevelopmentItemIds = releasedForDevelopmentItemIds;
|
|
67
|
+
const output = await this.processPublish(pcd, changeDetail, assortmentBaseline, deleteChanges);
|
|
68
|
+
output['publishInfo'] = await this.getPublishInfo(assortmentId, assortmentPublishChangeId, apcHistory, publisher);
|
|
69
|
+
console.info('process-end');
|
|
70
|
+
return output;
|
|
143
71
|
}
|
|
144
|
-
|
|
145
|
-
|
|
72
|
+
catch (e) {
|
|
73
|
+
try {
|
|
74
|
+
const publishInfo = await this.getPublishInfo(assortmentId, assortmentPublishChangeId, apcHistory, publisher);
|
|
75
|
+
e.publishInfo = publishInfo;
|
|
76
|
+
}
|
|
77
|
+
catch (e2) {
|
|
78
|
+
console.error('getPublishInfo failed: ' + e2.message);
|
|
79
|
+
}
|
|
80
|
+
console.error('process failed: assortmentId: ' + assortmentId + ': ' + e.message);
|
|
81
|
+
throw e;
|
|
146
82
|
}
|
|
147
83
|
}
|
|
148
84
|
async getPublishInfo(assortmentId, assortmentPublishChangeId, apcHistory, publisher) {
|
|
@@ -275,18 +211,13 @@ class BaseProcessPublishAssortment {
|
|
|
275
211
|
return sinceDate;
|
|
276
212
|
}
|
|
277
213
|
async getApcHistory(assortmentId) {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
if (Array.isArray(history))
|
|
288
|
-
span.setAttribute(telemetry_attributes_1.ATTR_FLEXPLM_PUBLISH_HISTORY_COUNT, history.length);
|
|
289
|
-
return history;
|
|
214
|
+
const resource = `/assortments/${assortmentId}/history/`;
|
|
215
|
+
return sdk_1.Request.request(resource, {
|
|
216
|
+
method: 'GET',
|
|
217
|
+
headers: {
|
|
218
|
+
Accept: 'application/json',
|
|
219
|
+
'Content-Type': 'application/json'
|
|
220
|
+
}
|
|
290
221
|
});
|
|
291
222
|
}
|
|
292
223
|
updatedSinceDate(entity, sinceDate) {
|
|
@@ -384,42 +315,30 @@ class BaseProcessPublishAssortment {
|
|
|
384
315
|
});
|
|
385
316
|
}
|
|
386
317
|
async downloadHydratedChangeDetail(assortmentPublishChange) {
|
|
387
|
-
|
|
318
|
+
try {
|
|
319
|
+
const link = assortmentPublishChange?.hydratedDetailDownloadLink;
|
|
320
|
+
const response = await fetch(link);
|
|
321
|
+
const data = await response.json();
|
|
322
|
+
return data;
|
|
323
|
+
}
|
|
324
|
+
catch (e) {
|
|
325
|
+
console.error('Error hydratedDetailDownloadLink: ' + e.message);
|
|
326
|
+
}
|
|
327
|
+
return undefined;
|
|
388
328
|
}
|
|
389
329
|
async downloadAssortmentBaseline(assortmentPublishChange) {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
httpStatus = response.status;
|
|
401
|
-
span.setAttribute(telemetry_attributes_1.ATTR_HTTP_RESPONSE_STATUS_CODE, httpStatus);
|
|
402
|
-
if (!response.ok) {
|
|
403
|
-
throw new Error('Download failed: status: ' + httpStatus);
|
|
404
|
-
}
|
|
405
|
-
return await response.json();
|
|
406
|
-
}
|
|
407
|
-
catch (e) {
|
|
408
|
-
span.recordException(e);
|
|
409
|
-
span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: e?.message });
|
|
410
|
-
telemetry_1.logger.error({ error: e, flexplm: { direction: 'publish', publish_file: file, http_status: httpStatus } }, 'FlexPLM publish file download failed');
|
|
411
|
-
return undefined;
|
|
412
|
-
}
|
|
413
|
-
});
|
|
330
|
+
try {
|
|
331
|
+
const link = assortmentPublishChange?.assortmentBaselineDownloadLink;
|
|
332
|
+
const response = await fetch(link);
|
|
333
|
+
const data = await response.json();
|
|
334
|
+
return data;
|
|
335
|
+
}
|
|
336
|
+
catch (e) {
|
|
337
|
+
console.error('Error assortmentBaselineDownloadLink: ' + e.message);
|
|
338
|
+
}
|
|
339
|
+
return undefined;
|
|
414
340
|
}
|
|
415
341
|
async getDeleteChanges(assortmentPublishChange, apcHistory, assortmentBaseline, sinceDate) {
|
|
416
|
-
return (0, telemetry_1.traceSection)('get_delete_changes', {}, async (span) => {
|
|
417
|
-
const deleteChanges = await this.collectDeleteChanges(assortmentPublishChange, apcHistory, assortmentBaseline, sinceDate);
|
|
418
|
-
span.setAttribute(telemetry_attributes_1.ATTR_FLEXPLM_PUBLISH_DELETE_CHANGE_COUNT, deleteChanges?.length ?? 0);
|
|
419
|
-
return deleteChanges;
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
async collectDeleteChanges(assortmentPublishChange, apcHistory, assortmentBaseline, sinceDate) {
|
|
423
342
|
const currentAPCIndex = apcHistory.findIndex(pc => pc?.id === assortmentPublishChange?.id);
|
|
424
343
|
if (currentAPCIndex == 0) {
|
|
425
344
|
return [];
|
|
@@ -464,7 +383,6 @@ class BaseProcessPublishAssortment {
|
|
|
464
383
|
console.info('getDeleteChanges(): baselineItems: ' + currentAssortmentItemIds.length
|
|
465
384
|
+ ', scanned ' + scannedCount + ' historical delete changes, added ' + addedCount
|
|
466
385
|
+ ', deleteIds: ' + deleteIds.length);
|
|
467
|
-
(0, telemetry_utils_1.setActiveSpanAttributes)({ [telemetry_attributes_1.ATTR_FLEXPLM_PUBLISH_HISTORICAL_DELETE_COUNT]: addedCount });
|
|
468
386
|
console.info('getDeleteChanges()-deleteIds: ' + deleteIds);
|
|
469
387
|
}
|
|
470
388
|
return apcDeletes;
|
|
@@ -641,12 +559,12 @@ class BaseProcessPublishAssortment {
|
|
|
641
559
|
pcd.itemFamilyChanges = this.getItemFamilyChanges(pcd, changeDetail, assortmentItemFullChangeMap, assortmentItemDeleteMap);
|
|
642
560
|
const events = await this.getEventsForPublishChangeData(pcd);
|
|
643
561
|
if (events.length === 0) {
|
|
562
|
+
const processStatus = 'BaseProcessPublishAssortment: ' + event_short_message_status_1.EventShortMessageStatus.NO_EVENTS_TO_SEND
|
|
563
|
+
+ ': assortmentId: ' + pcd.assortmentId + ': assortmentPublishChangeId: ' + pcd.assortmentPublishChangeId
|
|
564
|
+
+ ', orgSlug: ' + this.orgSlug;
|
|
565
|
+
console.log(processStatus);
|
|
644
566
|
const message = 'No Events to Send; returning';
|
|
645
|
-
|
|
646
|
-
status: event_short_message_status_1.EventShortMessageStatus.NO_EVENTS_TO_SEND,
|
|
647
|
-
assortmentId: pcd.assortmentId,
|
|
648
|
-
assortmentPublishChangeId: pcd.assortmentPublishChangeId,
|
|
649
|
-
});
|
|
567
|
+
console.log(message);
|
|
650
568
|
return {
|
|
651
569
|
results: { message, event },
|
|
652
570
|
skip_await: true
|
|
@@ -654,12 +572,11 @@ class BaseProcessPublishAssortment {
|
|
|
654
572
|
}
|
|
655
573
|
const results = await this.sendEvents(events);
|
|
656
574
|
const resultsCount = this.getResultsCount(events);
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
});
|
|
575
|
+
const processStatus = 'BaseProcessPublishAssortment: ' + event_short_message_status_1.EventShortMessageStatus.SENDING_EVENTS
|
|
576
|
+
+ ': assortmentId: ' + pcd.assortmentId + ': assortmentPublishChangeId: ' + pcd.assortmentPublishChangeId
|
|
577
|
+
+ ': resultsCount: ' + JSON.stringify(resultsCount)
|
|
578
|
+
+ ', orgSlug: ' + this.orgSlug;
|
|
579
|
+
console.log(processStatus);
|
|
663
580
|
return { results, event, resultsCount };
|
|
664
581
|
}
|
|
665
582
|
getResultsCount(events) {
|
|
@@ -678,7 +595,6 @@ class BaseProcessPublishAssortment {
|
|
|
678
595
|
console.info('sendEvents()');
|
|
679
596
|
const eventType = 'ASYNC_PUBLISH_SEASON';
|
|
680
597
|
const sendMode = (this.config?.sendMode[eventType] || '').toLowerCase();
|
|
681
|
-
(0, telemetry_utils_1.setActiveSpanAttributes)({ [telemetry_attributes_1.ATTR_FLEXPLM_PUBLISH_SEND_MODE]: sendMode });
|
|
682
598
|
switch (sendMode) {
|
|
683
599
|
case 'sendtoflexplm':
|
|
684
600
|
return this.sendToFlexPLM(events, eventType);
|
|
@@ -688,25 +604,22 @@ class BaseProcessPublishAssortment {
|
|
|
688
604
|
case 'vibeiqfile-dontsendtoflexplm':
|
|
689
605
|
return this.handleVibeIQFile(events, eventType, sendMode);
|
|
690
606
|
default:
|
|
691
|
-
telemetry_1.logger.warn({ flexplm: { direction: 'publish', send_mode: sendMode, payload_count: events?.length ?? 0 } }, 'Unknown FlexPLM publish sendMode; events not sent');
|
|
692
607
|
return {}; // Or handle other cases as required
|
|
693
608
|
}
|
|
694
609
|
}
|
|
695
610
|
async sendToFlexPLM(events, eventType) {
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
: { result, outboundPublishEvent };
|
|
709
|
-
});
|
|
611
|
+
const outboundPublishEvent = {
|
|
612
|
+
taskId: this.config.taskId,
|
|
613
|
+
eventType,
|
|
614
|
+
objectClass: 'LCSSeason',
|
|
615
|
+
events
|
|
616
|
+
};
|
|
617
|
+
const flexPLMConnect = new flexplm_connect_1.FlexPLMConnect(this.config);
|
|
618
|
+
const result = await this.sendAndRecordPublishEvent(flexPLMConnect, outboundPublishEvent);
|
|
619
|
+
const isResultObject = typeof result === 'object' && result !== null;
|
|
620
|
+
return isResultObject
|
|
621
|
+
? { ...result, outboundPublishEvent }
|
|
622
|
+
: { result, outboundPublishEvent };
|
|
710
623
|
}
|
|
711
624
|
async sendAndRecordPublishEvent(flexPLMConnect, outboundPublishEvent) {
|
|
712
625
|
let sendResult;
|
|
@@ -755,7 +668,6 @@ class BaseProcessPublishAssortment {
|
|
|
755
668
|
};
|
|
756
669
|
}
|
|
757
670
|
catch (e) {
|
|
758
|
-
telemetry_1.logger.error({ error: e, flexplm: { direction: 'publish', send_mode: 'localfile' } }, 'Saving FlexPLM publish events to a local file failed');
|
|
759
671
|
results['error'] = e.message;
|
|
760
672
|
}
|
|
761
673
|
finally {
|
|
@@ -766,7 +678,7 @@ class BaseProcessPublishAssortment {
|
|
|
766
678
|
async handleVibeIQFile(events, eventType, sendMode) {
|
|
767
679
|
const eventBuffer = Buffer.from(JSON.stringify(events), 'utf-8');
|
|
768
680
|
const fileName = 'ASYNC_PUBLISH_SEASON-events.json';
|
|
769
|
-
const uploadFile = await
|
|
681
|
+
const uploadFile = await new sdk_1.Files().createAndUploadFileFromBuffer(eventBuffer, 'application/json', fileName, null, this.TTL);
|
|
770
682
|
const outboundPublishEvent = {
|
|
771
683
|
taskId: this.config.taskId,
|
|
772
684
|
eventType,
|
|
@@ -776,14 +688,12 @@ class BaseProcessPublishAssortment {
|
|
|
776
688
|
eventsAdminDownloadLink: uploadFile.adminDownloadUrl
|
|
777
689
|
};
|
|
778
690
|
if (sendMode === 'vibeiqfile') {
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
: { result, outboundPublishEvent };
|
|
786
|
-
});
|
|
691
|
+
const flexPLMConnect = new flexplm_connect_1.FlexPLMConnect(this.config);
|
|
692
|
+
const result = await this.sendAndRecordPublishEvent(flexPLMConnect, outboundPublishEvent);
|
|
693
|
+
const isResultObject = typeof result === 'object' && result !== null;
|
|
694
|
+
return isResultObject
|
|
695
|
+
? { ...result, outboundPublishEvent }
|
|
696
|
+
: { result, outboundPublishEvent };
|
|
787
697
|
}
|
|
788
698
|
else {
|
|
789
699
|
await this.sendPublishPayloadEvent(outboundPublishEvent);
|
|
@@ -794,24 +704,22 @@ class BaseProcessPublishAssortment {
|
|
|
794
704
|
}
|
|
795
705
|
}
|
|
796
706
|
async sendPublishPayloadEvent(outboundPublishEvent) {
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
object: eventBody
|
|
814
|
-
});
|
|
707
|
+
console.info('sendPublishPayloadEvent()');
|
|
708
|
+
let initialEvent = {};
|
|
709
|
+
if (this.config?.event) {
|
|
710
|
+
initialEvent = (typeof this.config?.event === 'string')
|
|
711
|
+
? JSON.parse(this.config?.event)
|
|
712
|
+
: this.config?.event;
|
|
713
|
+
}
|
|
714
|
+
const eventBody = {
|
|
715
|
+
originSystemType: 'VibeIQ',
|
|
716
|
+
objectClass: 'AssortmentPublishedToFlexPLM',
|
|
717
|
+
outboundPublishEvent,
|
|
718
|
+
initialEvent
|
|
719
|
+
};
|
|
720
|
+
await new sdk_1.Entities().create({
|
|
721
|
+
entityName: 'external-event',
|
|
722
|
+
object: eventBody
|
|
815
723
|
});
|
|
816
724
|
}
|
|
817
725
|
getCurrentDateString() {
|
|
@@ -904,7 +812,6 @@ class BaseProcessPublishAssortment {
|
|
|
904
812
|
}
|
|
905
813
|
}
|
|
906
814
|
}
|
|
907
|
-
const skippedDeletes = [];
|
|
908
815
|
for (const [itemId, delEntity] of assortmentItemDeleteMap) {
|
|
909
816
|
const itemFamilyId = delEntity?.item?.itemFamilyId;
|
|
910
817
|
const item = delEntity?.item;
|
|
@@ -916,7 +823,7 @@ class BaseProcessPublishAssortment {
|
|
|
916
823
|
}
|
|
917
824
|
else {
|
|
918
825
|
if (!item) {
|
|
919
|
-
|
|
826
|
+
console.error('Failed to find deleted item entity: itemFamilyId: ' + itemFamilyId + ', itemId: ' + itemId);
|
|
920
827
|
continue;
|
|
921
828
|
}
|
|
922
829
|
}
|
|
@@ -948,14 +855,6 @@ class BaseProcessPublishAssortment {
|
|
|
948
855
|
ifc.colorDeletes.push(itemId);
|
|
949
856
|
}
|
|
950
857
|
} //End deletes for loop
|
|
951
|
-
if (skippedDeletes.length > 0) {
|
|
952
|
-
// These deletes are not sent to FlexPLM; one warning for the publish rather than one per item.
|
|
953
|
-
(0, telemetry_utils_1.setActiveSpanAttributes)({ [telemetry_attributes_1.ATTR_FLEXPLM_PUBLISH_SKIPPED_DELETE_COUNT]: skippedDeletes.length });
|
|
954
|
-
telemetry_1.logger.warn({ flexplm: {
|
|
955
|
-
direction: 'publish', assortment_id: pcd.assortmentId, publish_change_id: pcd.assortmentPublishChangeId,
|
|
956
|
-
skipped_delete_count: skippedDeletes.length, skipped_deletes: skippedDeletes,
|
|
957
|
-
} }, 'FlexPLM publish skipped deleted items with no item entity');
|
|
958
|
-
}
|
|
959
858
|
if (app_framework_1.Logger.isDebugOn()) {
|
|
960
859
|
console.debug('returning size: ' + itemFamilyChanges.size);
|
|
961
860
|
for (const [key, value] of itemFamilyChanges) {
|
|
@@ -965,21 +864,16 @@ class BaseProcessPublishAssortment {
|
|
|
965
864
|
return itemFamilyChanges;
|
|
966
865
|
}
|
|
967
866
|
async getEventsForPublishChangeData(publishChangeData) {
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
const events = await this.getEventsForItemFamilyChanges(itemFamilyChange, publishChangeData.assortmentId, publishChangeData.seasonFed, publishChangeData.itemToFederatedIdMapping);
|
|
974
|
-
if (events.length > 0) {
|
|
975
|
-
seasonalPayloads.push(...events);
|
|
976
|
-
}
|
|
867
|
+
const seasonalPayloads = [];
|
|
868
|
+
for (const itemFamilyChange of publishChangeData.itemFamilyChanges.values()) {
|
|
869
|
+
const events = await this.getEventsForItemFamilyChanges(itemFamilyChange, publishChangeData.assortmentId, publishChangeData.seasonFed, publishChangeData.itemToFederatedIdMapping);
|
|
870
|
+
if (events.length > 0) {
|
|
871
|
+
seasonalPayloads.push(...events);
|
|
977
872
|
}
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
});
|
|
873
|
+
}
|
|
874
|
+
console.info('getEventsForPublishChangeData: itemFamilies: '
|
|
875
|
+
+ publishChangeData.itemFamilyChanges.size + ', payloads: ' + seasonalPayloads.length);
|
|
876
|
+
return seasonalPayloads;
|
|
983
877
|
}
|
|
984
878
|
/**Returns the events for a given ItemFamilyChanges object
|
|
985
879
|
*
|