@contrail/flexplm 1.1.4 → 1.1.6

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;
@@ -90,15 +94,19 @@ class BaseProcessPublishAssortment {
90
94
  const sinceDateString = String(this.config['sinceDate'] || '');
91
95
  if (sinceDateString.includes('-')) {
92
96
  const [year, month, day] = sinceDateString.split('-').map(Number);
93
- const minutes = -new Date().getTimezoneOffset();
94
- return new Date(year, month - 1, day, 0, minutes);
97
+ const d = new Date(year, month - 1, day, 0, 0);
98
+ const minutes = -d.getTimezoneOffset();
99
+ d.setUTCMinutes(minutes);
100
+ return d;
95
101
  }
96
102
  if (sinceDateString.includes(':')) {
97
103
  const [type, countStr] = sinceDateString.split(':');
98
104
  const count = parseInt(countStr);
99
105
  if (type.trim().toLowerCase() === 'numberofdays') {
100
106
  const currentDate = new Date();
101
- return new Date(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate() - count, 0, -currentDate.getTimezoneOffset());
107
+ const d = new Date(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate() - count, 0, 0);
108
+ d.setUTCMinutes(-d.getTimezoneOffset());
109
+ return d;
102
110
  }
103
111
  if (type.trim().toLowerCase() === 'numberofpublishes') {
104
112
  const apcHistory = await this.getApcHistory(assortmentId);
@@ -444,6 +452,12 @@ class BaseProcessPublishAssortment {
444
452
  LCSProduct,
445
453
  data: seasonalData
446
454
  };
455
+ if ('ASSORTMENT' === projectItem.addedFromSource && projectItem.addedFromAssortment) {
456
+ const carriedFromSeason = await this.getCarriedFromSeason(projectItem);
457
+ if (carriedFromSeason) {
458
+ psUpsert['carriedFromSeason'] = carriedFromSeason;
459
+ }
460
+ }
447
461
  events.push(psUpsert);
448
462
  }
449
463
  const colorAddUpdates = [];
@@ -467,6 +481,12 @@ class BaseProcessPublishAssortment {
467
481
  LCSSKU,
468
482
  data: seasonalData
469
483
  };
484
+ if ('ASSORTMENT' === projectItem.addedFromSource && projectItem.addedFromAssortment) {
485
+ const carriedFromSeason = await this.getCarriedFromSeason(projectItem);
486
+ if (carriedFromSeason) {
487
+ csUpsert['carriedFromSeason'] = carriedFromSeason;
488
+ }
489
+ }
470
490
  events.push(csUpsert);
471
491
  }
472
492
  const data = {};
@@ -564,6 +584,62 @@ class BaseProcessPublishAssortment {
564
584
  skuObj = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, skuObj, 'LCSSKU', 'vibe2flex');
565
585
  return skuObj;
566
586
  }
587
+ async getCarriedFromSeason(projectItem) {
588
+ const addedFromAssortment = projectItem.addedFromAssortment;
589
+ if (this.cache.carriedFromSeason[addedFromAssortment]) {
590
+ return this.cache.carriedFromSeason[addedFromAssortment];
591
+ }
592
+ let seasonFederation = undefined;
593
+ const assortmentEntity = await this.getAssormentEntityFromId(addedFromAssortment);
594
+ if (assortmentEntity) {
595
+ seasonFederation = await this.getSeasonFederationFromAssortment(assortmentEntity);
596
+ }
597
+ this.cache.carriedFromSeason[addedFromAssortment] = seasonFederation;
598
+ return seasonFederation;
599
+ }
600
+ async getAssormentEntityFromId(assortmentId) {
601
+ let assortment;
602
+ try {
603
+ assortment = await new sdk_1.Entities().get({
604
+ entityName: 'assortment',
605
+ id: assortmentId
606
+ });
607
+ }
608
+ catch (e) {
609
+ console.warn(`No Assortment found for id: ${assortmentId}`);
610
+ }
611
+ return assortment;
612
+ }
613
+ async getSeasonFederationFromAssortment(assortment) {
614
+ assortment['flex2vibeMapKeyRoot'] = 'LCSSeason';
615
+ const flexPLMTypePath = await type_conversion_utils_1.TypeConversionUtils.getObjectTypePath(this.transformMapFile, this.mapFileUtil, assortment);
616
+ let seasonObj = {
617
+ entityReference: 'assortment:' + assortment.id,
618
+ objectClass: 'LCSSeason',
619
+ flexPLMTypePath
620
+ };
621
+ try {
622
+ const assortmentObj = await this.dc.getFlexPLMObjectData(assortment, [], true);
623
+ const identifierKeys = await type_conversion_utils_1.TypeConversionUtils.getIdentifierProperties(this.transformMapFile, this.mapFileUtil, assortment);
624
+ const informationKeys = await type_conversion_utils_1.TypeConversionUtils.getInformationalProperties(this.transformMapFile, this.mapFileUtil, assortment);
625
+ for (const key of identifierKeys.concat(informationKeys)) {
626
+ if (assortmentObj[key]) {
627
+ seasonObj[key] = assortmentObj[key];
628
+ }
629
+ }
630
+ const objectKeys = Object.keys(seasonObj);
631
+ const hasAllIdentifiers = identifierKeys.every(key => objectKeys.includes(key));
632
+ if (!hasAllIdentifiers) {
633
+ return undefined;
634
+ }
635
+ const mapKey = await type_conversion_utils_1.TypeConversionUtils.getMapKey(this.transformMapFile, this.mapFileUtil, assortment, type_conversion_utils_1.TypeConversionUtils.VIBE2FLEX_DIRECTION);
636
+ seasonObj = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, seasonObj, mapKey, type_conversion_utils_1.TypeConversionUtils.VIBE2FLEX_DIRECTION);
637
+ }
638
+ finally {
639
+ delete assortment['flex2vibeMapKeyRoot'];
640
+ }
641
+ return seasonObj;
642
+ }
567
643
  }
568
644
  exports.BaseProcessPublishAssortment = BaseProcessPublishAssortment;
569
645
  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.6",
4
4
  "description": "Library used for integration with flexplm.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",