@contrail/flexplm 1.1.4 → 1.1.5

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.
@@ -74,6 +74,7 @@ export interface SeasonalPayload extends EntityPayloadType {
74
74
  LCSSeason: SeasonFederation;
75
75
  LCSProduct?: ProductFederation;
76
76
  LCSSKU?: SkuFederation;
77
+ carriedFromSeason?: object;
77
78
  }
78
79
  export interface ExportPayloadType extends AsyncPayloadType {
79
80
  flexPLMTypePath: string;
@@ -11,6 +11,7 @@ export declare class BaseProcessPublishAssortment {
11
11
  private config;
12
12
  private mapFileUtil;
13
13
  private transformMapFile;
14
+ private cache;
14
15
  constructor(_config: FCConfig, _dc: DataConverter, _mapFileUtil: MapFileUtil);
15
16
  process(event: any): Promise<{
16
17
  results: {
@@ -54,4 +55,7 @@ export declare class BaseProcessPublishAssortment {
54
55
  getSeasonalData(projectItem: any): Promise<object>;
55
56
  protected getProductFederation(entityReference: string, itemToFederatedIdMapping: Map<string, string>, itemFamilyObject: any): Promise<ProductFederation>;
56
57
  protected getSKUFederation(entityReference: string, itemToFederatedIdMapping: Map<string, string>, itemObject: any): Promise<SkuFederation>;
58
+ getCarriedFromSeason(projectItem: any): Promise<SeasonFederation>;
59
+ getAssormentEntityFromId(assortmentId: any): Promise<any>;
60
+ getSeasonFederationFromAssortment(assortment: any): Promise<SeasonFederation>;
57
61
  }
@@ -8,9 +8,13 @@ const publish_change_data_1 = require("../interfaces/publish-change-data");
8
8
  const map_utils_1 = require("../util/map-utils");
9
9
  const fsPromise = require("fs/promises");
10
10
  const path = require("path");
11
+ const type_conversion_utils_1 = require("../util/type-conversion-utils");
11
12
  class BaseProcessPublishAssortment {
12
13
  constructor(_config, _dc, _mapFileUtil) {
13
14
  this.TTL = 7 * 24 * 60 * 60 * 1000;
15
+ this.cache = {
16
+ carriedFromSeason: {}
17
+ };
14
18
  this.config = _config;
15
19
  this.dc = _dc;
16
20
  this.mapFileUtil = _mapFileUtil;
@@ -444,6 +448,12 @@ class BaseProcessPublishAssortment {
444
448
  LCSProduct,
445
449
  data: seasonalData
446
450
  };
451
+ if ('ASSORTMENT' === projectItem.addedFromSource && projectItem.addedFromAssortment) {
452
+ const carriedFromSeason = this.getCarriedFromSeason(projectItem);
453
+ if (carriedFromSeason) {
454
+ psUpsert['carriedFromSeason'] = carriedFromSeason;
455
+ }
456
+ }
447
457
  events.push(psUpsert);
448
458
  }
449
459
  const colorAddUpdates = [];
@@ -467,6 +477,12 @@ class BaseProcessPublishAssortment {
467
477
  LCSSKU,
468
478
  data: seasonalData
469
479
  };
480
+ if ('ASSORTMENT' === projectItem.addedFromSource && projectItem.addedFromAssortment) {
481
+ const carriedFromSeason = this.getCarriedFromSeason(projectItem);
482
+ if (carriedFromSeason) {
483
+ csUpsert['carriedFromSeason'] = carriedFromSeason;
484
+ }
485
+ }
470
486
  events.push(csUpsert);
471
487
  }
472
488
  const data = {};
@@ -564,6 +580,62 @@ class BaseProcessPublishAssortment {
564
580
  skuObj = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, skuObj, 'LCSSKU', 'vibe2flex');
565
581
  return skuObj;
566
582
  }
583
+ async getCarriedFromSeason(projectItem) {
584
+ const addedFromAssortment = projectItem.addedFromAssortment;
585
+ if (this.cache.carriedFromSeason[addedFromAssortment]) {
586
+ return this.cache.carriedFromSeason[addedFromAssortment];
587
+ }
588
+ let seasonFederation = undefined;
589
+ const assortmentEntity = await this.getAssormentEntityFromId(addedFromAssortment);
590
+ if (assortmentEntity) {
591
+ seasonFederation = await this.getSeasonFederationFromAssortment(assortmentEntity);
592
+ }
593
+ this.cache.carriedFromSeason[addedFromAssortment] = seasonFederation;
594
+ return seasonFederation;
595
+ }
596
+ async getAssormentEntityFromId(assortmentId) {
597
+ let assortment;
598
+ try {
599
+ assortment = await new sdk_1.Entities().get({
600
+ entityName: 'assortment',
601
+ id: assortmentId
602
+ });
603
+ }
604
+ catch (e) {
605
+ console.warn(`No Assortment found for id: ${assortmentId}`);
606
+ }
607
+ return assortment;
608
+ }
609
+ async getSeasonFederationFromAssortment(assortment) {
610
+ assortment['flex2vibeMapKeyRoot'] = 'LCSSeason';
611
+ const flexPLMTypePath = await type_conversion_utils_1.TypeConversionUtils.getObjectTypePath(this.transformMapFile, this.mapFileUtil, assortment);
612
+ let seasonObj = {
613
+ entityReference: 'assortment:' + assortment.id,
614
+ objectClass: 'LCSSeason',
615
+ flexPLMTypePath
616
+ };
617
+ try {
618
+ const assortmentObj = await this.dc.getFlexPLMObjectData(assortment, [], true);
619
+ const identifierKeys = await type_conversion_utils_1.TypeConversionUtils.getIdentifierProperties(this.transformMapFile, this.mapFileUtil, assortment);
620
+ const informationKeys = await type_conversion_utils_1.TypeConversionUtils.getInformationalProperties(this.transformMapFile, this.mapFileUtil, assortment);
621
+ for (const key of identifierKeys.concat(informationKeys)) {
622
+ if (assortmentObj[key]) {
623
+ seasonObj[key] = assortmentObj[key];
624
+ }
625
+ }
626
+ const objectKeys = Object.keys(seasonObj);
627
+ const hasAllIdentifiers = identifierKeys.every(key => objectKeys.includes(key));
628
+ if (!hasAllIdentifiers) {
629
+ return undefined;
630
+ }
631
+ const mapKey = await type_conversion_utils_1.TypeConversionUtils.getMapKey(this.transformMapFile, this.mapFileUtil, assortment, type_conversion_utils_1.TypeConversionUtils.VIBE2FLEX_DIRECTION);
632
+ seasonObj = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, seasonObj, mapKey, type_conversion_utils_1.TypeConversionUtils.VIBE2FLEX_DIRECTION);
633
+ }
634
+ finally {
635
+ delete assortment['flex2vibeMapKeyRoot'];
636
+ }
637
+ return seasonObj;
638
+ }
567
639
  }
568
640
  exports.BaseProcessPublishAssortment = BaseProcessPublishAssortment;
569
641
  BaseProcessPublishAssortment.ASSORTMENT_NOT_PUBLISHABLE = 'Assortment isn\'t marked for publishing to FlexPLM';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/flexplm",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "Library used for integration with flexplm.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",