rerobe-js-orm 4.6.5 → 4.6.7

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.
@@ -31,7 +31,7 @@ export default class Product extends Base {
31
31
  };
32
32
  toObjForTextTranslation(): TranslatableAttributes;
33
33
  toObjForTypesense(isCanonicalMerchant?: boolean): TypesenseProductObj;
34
- private deriveStockStatusFromSystemTags;
34
+ private deriveStockTimestampsFromSystemTags;
35
35
  buildUpdatedFieldsForSalesChannel(): {
36
36
  title: string;
37
37
  description: string;
@@ -560,7 +560,7 @@ class Product extends Base_1.default {
560
560
  description: this.utilities.sanitizeString(this.attributes.description),
561
561
  discountType: this.utilities.sanitizeString(this.consignmentAttributes.discountType),
562
562
  discountValue: this.utilities.sanitizeNumber(this.consignmentAttributes.discountValue, 0),
563
- stockStatus: 'Unknown',
563
+ stockStatus: '',
564
564
  stockStatusTimestamp: null,
565
565
  id: this.utilities.sanitizeString(this.filterAttributes.documentId),
566
566
  documentId: this.utilities.sanitizeString(this.filterAttributes.documentId),
@@ -579,9 +579,19 @@ class Product extends Base_1.default {
579
579
  stockTakeLatestTimestamp: null,
580
580
  stockTakeFirstTimestamp: null,
581
581
  };
582
- const stockDerivations = this.deriveStockStatusFromSystemTags();
583
- stagedObj.stockStatus = stockDerivations.stockStatus;
582
+ const stockDerivations = this.deriveStockTimestampsFromSystemTags();
584
583
  stagedObj.stockStatusTimestamp = this.utilities.sanitizeMillisTimeStamp(stockDerivations.stockStatusTimestamp);
584
+ // Derive stockStatus string from timestamps (no mutation performed inside derive)
585
+ if (stagedObj.stockStatusTimestamp &&
586
+ stagedObj.stockStatusTimestamp === stockDerivations.stockTakeLatestTimestamp) {
587
+ stagedObj.stockStatus = 'In stock';
588
+ }
589
+ else if (stagedObj.stockStatusTimestamp) {
590
+ stagedObj.stockStatus = 'In transit';
591
+ }
592
+ else {
593
+ stagedObj.stockStatus = '';
594
+ }
585
595
  stagedObj.stockTakeFirstTimestamp = this.utilities.sanitizeMillisTimeStamp(stockDerivations.stockTakeFirstTimestamp);
586
596
  stagedObj.stockTakeLatestTimestamp = this.utilities.sanitizeMillisTimeStamp(stockDerivations.stockTakeLatestTimestamp);
587
597
  if (((_a = this.consignmentAttributes) === null || _a === void 0 ? void 0 : _a.inventoryLocations) &&
@@ -600,7 +610,7 @@ class Product extends Base_1.default {
600
610
  });
601
611
  return stagedObj;
602
612
  }
603
- deriveStockStatusFromSystemTags() {
613
+ deriveStockTimestampsFromSystemTags() {
604
614
  const systemTags = Array.isArray(this.filterAttributes.systemTags) ? this.filterAttributes.systemTags : [];
605
615
  const stockTakeTags = systemTags.filter((t) => typeof t === 'string' && t.startsWith('stock-take|'));
606
616
  const inTransitTags = systemTags.filter((t) => typeof t === 'string' && t.startsWith('in-transit|'));
@@ -633,28 +643,22 @@ class Product extends Base_1.default {
633
643
  const stockTakeLatestSan = stockTakeLatest ? this.utilities.sanitizeMillisTimeStamp(stockTakeLatest) : null;
634
644
  const stockTakeFirstRaw = stockTakeTags.length ? parseLatestAndFirstTs(stockTakeTags).first : 0;
635
645
  const stockTakeFirstSan = stockTakeFirstRaw ? this.utilities.sanitizeMillisTimeStamp(stockTakeFirstRaw) : null;
636
- let stockStatus = 'Unknown';
637
646
  let stockStatusTimestamp = null;
638
647
  if (stockTakeLatest === 0 && inTransitLatest === 0) {
639
- stockStatus = 'Unknown';
640
648
  stockStatusTimestamp = null;
641
649
  }
642
650
  else if (stockTakeLatest >= inTransitLatest) {
643
- stockStatus = 'In stock';
644
651
  stockStatusTimestamp = stockTakeLatestSan;
645
652
  }
646
653
  else {
647
- stockStatus = 'In transit';
648
654
  stockStatusTimestamp = this.utilities.sanitizeMillisTimeStamp(inTransitLatest);
649
655
  }
650
- this.filterAttributes.stockStatus = stockStatus;
651
656
  this.timestampAttributes.stockStatusTimestamp = stockStatusTimestamp;
652
657
  this.timestampAttributes.stockTakeFirstTimestamp = stockTakeFirstSan;
653
658
  this.timestampAttributes.stockTakeLatestTimestamp = stockTakeLatestSan;
654
659
  return {
655
660
  stockTakeFirstTimestamp: stockTakeFirstSan,
656
661
  stockTakeLatestTimestamp: stockTakeLatestSan,
657
- stockStatus,
658
662
  stockStatusTimestamp,
659
663
  };
660
664
  }
@@ -371,7 +371,7 @@ type TypesenseProductObj = {
371
371
  description: string;
372
372
  discountType: string;
373
373
  discountValue: number;
374
- stockStatus: 'In stock' | 'In transit' | 'Unknown';
374
+ stockStatus: 'In stock' | 'In transit' | '';
375
375
  stockStatusTimestamp: number | null;
376
376
  id: string;
377
377
  documentId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "4.6.5",
3
+ "version": "4.6.7",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",