@contrail/flexplm 2.0.0-alpha.9af4b96 → 2.0.0-alpha.baca70f
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 -212
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -2
- 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 -243
- 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 +10 -12
- package/lib/__tests__/telemetry-test-utils.d.ts +0 -8
- package/lib/__tests__/telemetry-test-utils.js +0 -30
- package/lib/flexplm-request.d.ts +0 -3
- package/lib/flexplm-request.js +0 -34
- 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,120 +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
|
-
}
|
|
113
|
-
|
|
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;
|
|
114
53
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
[
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
direction: 'publish', status, assortment_id: assortmentId, publish_change_id: assortmentPublishChangeId,
|
|
133
|
-
product_season_count: resultsCount?.productSeasons, colorway_season_count: resultsCount?.colorwaySeasons, reason: message,
|
|
134
|
-
sent_unrecorded: sentUnrecorded,
|
|
135
|
-
};
|
|
136
|
-
if (sentUnrecorded) {
|
|
137
|
-
telemetry_1.logger.error({ error, flexplm }, 'FlexPLM assortment publish sent but not recorded: %j', flexplm);
|
|
138
|
-
}
|
|
139
|
-
else if (status === event_short_message_status_1.EventShortMessageStatus.FAILURE) {
|
|
140
|
-
telemetry_1.logger.error({ error, flexplm }, 'FlexPLM assortment publish failed: %j', flexplm);
|
|
141
|
-
}
|
|
142
|
-
else if (status === event_short_message_status_1.EventShortMessageStatus.NO_FEDERATION_INFO) {
|
|
143
|
-
telemetry_1.logger.warn({ flexplm }, 'FlexPLM assortment publish skipped: %j', flexplm);
|
|
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;
|
|
144
71
|
}
|
|
145
|
-
|
|
146
|
-
|
|
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;
|
|
147
82
|
}
|
|
148
83
|
}
|
|
149
84
|
async getPublishInfo(assortmentId, assortmentPublishChangeId, apcHistory, publisher) {
|
|
@@ -276,18 +211,13 @@ class BaseProcessPublishAssortment {
|
|
|
276
211
|
return sinceDate;
|
|
277
212
|
}
|
|
278
213
|
async getApcHistory(assortmentId) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
if (Array.isArray(history))
|
|
289
|
-
span.setAttribute(telemetry_attributes_1.ATTR_FLEXPLM_PUBLISH_HISTORY_COUNT, history.length);
|
|
290
|
-
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
|
+
}
|
|
291
221
|
});
|
|
292
222
|
}
|
|
293
223
|
updatedSinceDate(entity, sinceDate) {
|
|
@@ -385,43 +315,30 @@ class BaseProcessPublishAssortment {
|
|
|
385
315
|
});
|
|
386
316
|
}
|
|
387
317
|
async downloadHydratedChangeDetail(assortmentPublishChange) {
|
|
388
|
-
|
|
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;
|
|
389
328
|
}
|
|
390
329
|
async downloadAssortmentBaseline(assortmentPublishChange) {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
httpStatus = response.status;
|
|
402
|
-
span.setAttribute(telemetry_attributes_1.ATTR_HTTP_RESPONSE_STATUS_CODE, httpStatus);
|
|
403
|
-
if (!response.ok) {
|
|
404
|
-
throw new Error('Download failed: status: ' + httpStatus);
|
|
405
|
-
}
|
|
406
|
-
return await response.json();
|
|
407
|
-
}
|
|
408
|
-
catch (e) {
|
|
409
|
-
span.recordException(e);
|
|
410
|
-
span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: e?.message });
|
|
411
|
-
const flexplm = { direction: 'publish', publish_file: file, http_status: httpStatus };
|
|
412
|
-
telemetry_1.logger.error({ error: e, flexplm }, 'FlexPLM publish file download failed: %j', flexplm);
|
|
413
|
-
return undefined;
|
|
414
|
-
}
|
|
415
|
-
});
|
|
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;
|
|
416
340
|
}
|
|
417
341
|
async getDeleteChanges(assortmentPublishChange, apcHistory, assortmentBaseline, sinceDate) {
|
|
418
|
-
return (0, telemetry_1.traceSection)('get_delete_changes', {}, async (span) => {
|
|
419
|
-
const deleteChanges = await this.collectDeleteChanges(assortmentPublishChange, apcHistory, assortmentBaseline, sinceDate);
|
|
420
|
-
span.setAttribute(telemetry_attributes_1.ATTR_FLEXPLM_PUBLISH_DELETE_CHANGE_COUNT, deleteChanges?.length ?? 0);
|
|
421
|
-
return deleteChanges;
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
async collectDeleteChanges(assortmentPublishChange, apcHistory, assortmentBaseline, sinceDate) {
|
|
425
342
|
const currentAPCIndex = apcHistory.findIndex(pc => pc?.id === assortmentPublishChange?.id);
|
|
426
343
|
if (currentAPCIndex == 0) {
|
|
427
344
|
return [];
|
|
@@ -466,7 +383,6 @@ class BaseProcessPublishAssortment {
|
|
|
466
383
|
console.info('getDeleteChanges(): baselineItems: ' + currentAssortmentItemIds.length
|
|
467
384
|
+ ', scanned ' + scannedCount + ' historical delete changes, added ' + addedCount
|
|
468
385
|
+ ', deleteIds: ' + deleteIds.length);
|
|
469
|
-
(0, telemetry_utils_1.setActiveSpanAttributes)({ [telemetry_attributes_1.ATTR_FLEXPLM_PUBLISH_HISTORICAL_DELETE_COUNT]: addedCount });
|
|
470
386
|
console.info('getDeleteChanges()-deleteIds: ' + deleteIds);
|
|
471
387
|
}
|
|
472
388
|
return apcDeletes;
|
|
@@ -643,12 +559,12 @@ class BaseProcessPublishAssortment {
|
|
|
643
559
|
pcd.itemFamilyChanges = this.getItemFamilyChanges(pcd, changeDetail, assortmentItemFullChangeMap, assortmentItemDeleteMap);
|
|
644
560
|
const events = await this.getEventsForPublishChangeData(pcd);
|
|
645
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);
|
|
646
566
|
const message = 'No Events to Send; returning';
|
|
647
|
-
|
|
648
|
-
status: event_short_message_status_1.EventShortMessageStatus.NO_EVENTS_TO_SEND,
|
|
649
|
-
assortmentId: pcd.assortmentId,
|
|
650
|
-
assortmentPublishChangeId: pcd.assortmentPublishChangeId,
|
|
651
|
-
});
|
|
567
|
+
console.log(message);
|
|
652
568
|
return {
|
|
653
569
|
results: { message, event },
|
|
654
570
|
skip_await: true
|
|
@@ -656,12 +572,11 @@ class BaseProcessPublishAssortment {
|
|
|
656
572
|
}
|
|
657
573
|
const results = await this.sendEvents(events);
|
|
658
574
|
const resultsCount = this.getResultsCount(events);
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
});
|
|
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);
|
|
665
580
|
return { results, event, resultsCount };
|
|
666
581
|
}
|
|
667
582
|
getResultsCount(events) {
|
|
@@ -680,7 +595,6 @@ class BaseProcessPublishAssortment {
|
|
|
680
595
|
console.info('sendEvents()');
|
|
681
596
|
const eventType = 'ASYNC_PUBLISH_SEASON';
|
|
682
597
|
const sendMode = (this.config?.sendMode[eventType] || '').toLowerCase();
|
|
683
|
-
(0, telemetry_utils_1.setActiveSpanAttributes)({ [telemetry_attributes_1.ATTR_FLEXPLM_PUBLISH_SEND_MODE]: sendMode });
|
|
684
598
|
switch (sendMode) {
|
|
685
599
|
case 'sendtoflexplm':
|
|
686
600
|
return this.sendToFlexPLM(events, eventType);
|
|
@@ -690,26 +604,22 @@ class BaseProcessPublishAssortment {
|
|
|
690
604
|
case 'vibeiqfile-dontsendtoflexplm':
|
|
691
605
|
return this.handleVibeIQFile(events, eventType, sendMode);
|
|
692
606
|
default:
|
|
693
|
-
const flexplm = { direction: 'publish', send_mode: sendMode, payload_count: events?.length ?? 0 };
|
|
694
|
-
telemetry_1.logger.warn({ flexplm }, 'Unknown FlexPLM publish sendMode; events not sent: %j', flexplm);
|
|
695
607
|
return {}; // Or handle other cases as required
|
|
696
608
|
}
|
|
697
609
|
}
|
|
698
610
|
async sendToFlexPLM(events, eventType) {
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
: { result, outboundPublishEvent };
|
|
712
|
-
});
|
|
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 };
|
|
713
623
|
}
|
|
714
624
|
async sendAndRecordPublishEvent(flexPLMConnect, outboundPublishEvent) {
|
|
715
625
|
let sendResult;
|
|
@@ -758,8 +668,6 @@ class BaseProcessPublishAssortment {
|
|
|
758
668
|
};
|
|
759
669
|
}
|
|
760
670
|
catch (e) {
|
|
761
|
-
const flexplm = { direction: 'publish', send_mode: 'localfile' };
|
|
762
|
-
telemetry_1.logger.error({ error: e, flexplm }, 'Saving FlexPLM publish events to a local file failed: %j', flexplm);
|
|
763
671
|
results['error'] = e.message;
|
|
764
672
|
}
|
|
765
673
|
finally {
|
|
@@ -770,7 +678,7 @@ class BaseProcessPublishAssortment {
|
|
|
770
678
|
async handleVibeIQFile(events, eventType, sendMode) {
|
|
771
679
|
const eventBuffer = Buffer.from(JSON.stringify(events), 'utf-8');
|
|
772
680
|
const fileName = 'ASYNC_PUBLISH_SEASON-events.json';
|
|
773
|
-
const uploadFile = await
|
|
681
|
+
const uploadFile = await new sdk_1.Files().createAndUploadFileFromBuffer(eventBuffer, 'application/json', fileName, null, this.TTL);
|
|
774
682
|
const outboundPublishEvent = {
|
|
775
683
|
taskId: this.config.taskId,
|
|
776
684
|
eventType,
|
|
@@ -780,14 +688,12 @@ class BaseProcessPublishAssortment {
|
|
|
780
688
|
eventsAdminDownloadLink: uploadFile.adminDownloadUrl
|
|
781
689
|
};
|
|
782
690
|
if (sendMode === 'vibeiqfile') {
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
: { result, outboundPublishEvent };
|
|
790
|
-
});
|
|
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 };
|
|
791
697
|
}
|
|
792
698
|
else {
|
|
793
699
|
await this.sendPublishPayloadEvent(outboundPublishEvent);
|
|
@@ -798,24 +704,22 @@ class BaseProcessPublishAssortment {
|
|
|
798
704
|
}
|
|
799
705
|
}
|
|
800
706
|
async sendPublishPayloadEvent(outboundPublishEvent) {
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
object: eventBody
|
|
818
|
-
});
|
|
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
|
|
819
723
|
});
|
|
820
724
|
}
|
|
821
725
|
getCurrentDateString() {
|
|
@@ -908,7 +812,6 @@ class BaseProcessPublishAssortment {
|
|
|
908
812
|
}
|
|
909
813
|
}
|
|
910
814
|
}
|
|
911
|
-
const skippedDeletes = [];
|
|
912
815
|
for (const [itemId, delEntity] of assortmentItemDeleteMap) {
|
|
913
816
|
const itemFamilyId = delEntity?.item?.itemFamilyId;
|
|
914
817
|
const item = delEntity?.item;
|
|
@@ -920,7 +823,7 @@ class BaseProcessPublishAssortment {
|
|
|
920
823
|
}
|
|
921
824
|
else {
|
|
922
825
|
if (!item) {
|
|
923
|
-
|
|
826
|
+
console.error('Failed to find deleted item entity: itemFamilyId: ' + itemFamilyId + ', itemId: ' + itemId);
|
|
924
827
|
continue;
|
|
925
828
|
}
|
|
926
829
|
}
|
|
@@ -952,15 +855,6 @@ class BaseProcessPublishAssortment {
|
|
|
952
855
|
ifc.colorDeletes.push(itemId);
|
|
953
856
|
}
|
|
954
857
|
} //End deletes for loop
|
|
955
|
-
if (skippedDeletes.length > 0) {
|
|
956
|
-
// These deletes are not sent to FlexPLM; one warning for the publish rather than one per item.
|
|
957
|
-
(0, telemetry_utils_1.setActiveSpanAttributes)({ [telemetry_attributes_1.ATTR_FLEXPLM_PUBLISH_SKIPPED_DELETE_COUNT]: skippedDeletes.length });
|
|
958
|
-
const flexplm = {
|
|
959
|
-
direction: 'publish', assortment_id: pcd.assortmentId, publish_change_id: pcd.assortmentPublishChangeId,
|
|
960
|
-
skipped_delete_count: skippedDeletes.length, skipped_deletes: skippedDeletes,
|
|
961
|
-
};
|
|
962
|
-
telemetry_1.logger.warn({ flexplm }, 'FlexPLM publish skipped deleted items with no item entity: %j', flexplm);
|
|
963
|
-
}
|
|
964
858
|
if (app_framework_1.Logger.isDebugOn()) {
|
|
965
859
|
console.debug('returning size: ' + itemFamilyChanges.size);
|
|
966
860
|
for (const [key, value] of itemFamilyChanges) {
|
|
@@ -970,21 +864,16 @@ class BaseProcessPublishAssortment {
|
|
|
970
864
|
return itemFamilyChanges;
|
|
971
865
|
}
|
|
972
866
|
async getEventsForPublishChangeData(publishChangeData) {
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
const events = await this.getEventsForItemFamilyChanges(itemFamilyChange, publishChangeData.assortmentId, publishChangeData.seasonFed, publishChangeData.itemToFederatedIdMapping);
|
|
979
|
-
if (events.length > 0) {
|
|
980
|
-
seasonalPayloads.push(...events);
|
|
981
|
-
}
|
|
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);
|
|
982
872
|
}
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
});
|
|
873
|
+
}
|
|
874
|
+
console.info('getEventsForPublishChangeData: itemFamilies: '
|
|
875
|
+
+ publishChangeData.itemFamilyChanges.size + ', payloads: ' + seasonalPayloads.length);
|
|
876
|
+
return seasonalPayloads;
|
|
988
877
|
}
|
|
989
878
|
/**Returns the events for a given ItemFamilyChanges object
|
|
990
879
|
*
|