rerobe-js-orm 4.5.3 → 4.5.4

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.
@@ -604,27 +604,34 @@ class ProductFormState extends FormState_1.default {
604
604
  this.utilities.makeRandId(28);
605
605
  const existingInd = this.fields.variantInventory.selectedValues.findIndex((i) => i.id === id);
606
606
  const existing = existingInd !== -1 ? this.fields.variantInventory.selectedValues[existingInd] : {};
607
+ const coalesce = (v, fallback = null) => v !== undefined ? v : fallback;
607
608
  const next = {
608
609
  id,
609
610
  options: val.options || existing.options || {},
610
- locations: (val === null || val === void 0 ? void 0 : val.locations) !== undefined ? val.locations : existing.locations,
611
- price: (val === null || val === void 0 ? void 0 : val.price) !== undefined ? val.price : existing.price,
612
- compareAtPrice: (val === null || val === void 0 ? void 0 : val.compareAtPrice) !== undefined ? val.compareAtPrice : existing.compareAtPrice,
613
- salePrice: (val === null || val === void 0 ? void 0 : val.salePrice) !== undefined ? val.salePrice : existing.salePrice,
614
- isOnSale: (val === null || val === void 0 ? void 0 : val.isOnSale) !== undefined ? val.isOnSale : existing.isOnSale,
615
- sku: (val === null || val === void 0 ? void 0 : val.sku) !== undefined ? val.sku : existing.sku,
616
- taxable: (val === null || val === void 0 ? void 0 : val.taxable) !== undefined ? val.taxable : existing.taxable,
611
+ locations: (val === null || val === void 0 ? void 0 : val.locations) !== undefined ? val.locations : coalesce(existing.locations, null),
612
+ price: coalesce(val === null || val === void 0 ? void 0 : val.price, coalesce(existing.price, null)),
613
+ compareAtPrice: coalesce(val === null || val === void 0 ? void 0 : val.compareAtPrice, coalesce(existing.compareAtPrice, null)),
614
+ salePrice: coalesce(val === null || val === void 0 ? void 0 : val.salePrice, coalesce(existing.salePrice, null)),
615
+ isOnSale: coalesce(val === null || val === void 0 ? void 0 : val.isOnSale, coalesce(existing.isOnSale, null)),
616
+ sku: coalesce(val === null || val === void 0 ? void 0 : val.sku, coalesce(existing.sku, null)),
617
+ taxable: coalesce(val === null || val === void 0 ? void 0 : val.taxable, coalesce(existing.taxable, null)),
618
+ costPerItem: coalesce(val === null || val === void 0 ? void 0 : val.costPerItem, coalesce(existing.costPerItem, null)),
619
+ continueSellingWhenOutOfStock: coalesce(val === null || val === void 0 ? void 0 : val.continueSellingWhenOutOfStock, coalesce(existing.continueSellingWhenOutOfStock, null)),
620
+ shopifyId: coalesce(val === null || val === void 0 ? void 0 : val.shopifyId, coalesce(existing.shopifyId, null)),
617
621
  };
618
622
  const foundInd = this.fields.variantInventory.selectedValues.findIndex((i) => i.id === id);
619
623
  if (foundInd !== -1) {
620
624
  const foundI = this.fields.variantInventory.selectedValues[foundInd];
621
625
  let shouldToggleRemove = false;
622
626
  if ((val === null || val === void 0 ? void 0 : val.locations) !== undefined) {
623
- const norm = (arr = []) => [...arr]
624
- .filter((l) => l && l.id)
625
- .sort((a, b) => (a.id > b.id ? 1 : a.id < b.id ? -1 : 0))
626
- .map((l) => `${l.id}:${Number(l.availableAmount) || 0}:${Number(l.incomingAmount) || 0}`)
627
- .join('|');
627
+ const norm = (arr) => {
628
+ const list = Array.isArray(arr) ? arr : [];
629
+ return [...list]
630
+ .filter((l) => l && l.id)
631
+ .sort((a, b) => (a.id > b.id ? 1 : a.id < b.id ? -1 : 0))
632
+ .map((l) => `${l.id}:${Number(l.availableAmount) || 0}:${Number(l.incomingAmount) || 0}`)
633
+ .join('|');
634
+ };
628
635
  shouldToggleRemove = norm(foundI.locations) === norm(next.locations);
629
636
  }
630
637
  if (shouldToggleRemove) {
@@ -648,7 +655,7 @@ class ProductFormState extends FormState_1.default {
648
655
  // aggregate main inventoryLocations from variant locations (sum by location id)
649
656
  this.aggregateInventoryLocationsFromVariants();
650
657
  }
651
- // Public: define axes (≤3) for generating combinations
658
+ // Define axes (≤3) for generating combinations
652
659
  setVariantAxes(axes = {}) {
653
660
  const axisKeys = Object.keys(axes || {});
654
661
  if (axisKeys.length > 3) {
@@ -665,7 +672,7 @@ class ProductFormState extends FormState_1.default {
665
672
  }, {});
666
673
  }
667
674
  }
668
- // Public: regenerate variants from axes, preserving existing per-variant fields where options match
675
+ // Regenerate variants from axes, preserving existing per-variant fields where options match
669
676
  generateVariantsFromAxes(defaults = {}) {
670
677
  const axes = this.variantAxes || {};
671
678
  const axisKeys = Object.keys(axes);
@@ -691,19 +698,23 @@ class ProductFormState extends FormState_1.default {
691
698
  const combos = [];
692
699
  cartesian(axisKeys, 0, {}, combos);
693
700
  const regenerated = combos.map((opts) => {
694
- var _a, _b, _c, _d, _e, _f;
701
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
695
702
  const prev = this.getExistingVariantByOptions(opts);
696
703
  const id = (prev === null || prev === void 0 ? void 0 : prev.id) || this.utilities.makeRandId(28);
704
+ const nz = (v) => (v === undefined ? null : v);
697
705
  const merged = {
698
706
  id,
699
707
  options: opts,
700
- locations: (prev === null || prev === void 0 ? void 0 : prev.locations) || defaults.locations,
701
- price: (_a = prev === null || prev === void 0 ? void 0 : prev.price) !== null && _a !== void 0 ? _a : defaults.price,
702
- compareAtPrice: (_b = prev === null || prev === void 0 ? void 0 : prev.compareAtPrice) !== null && _b !== void 0 ? _b : defaults.compareAtPrice,
703
- salePrice: (_c = prev === null || prev === void 0 ? void 0 : prev.salePrice) !== null && _c !== void 0 ? _c : defaults.salePrice,
704
- isOnSale: (_d = prev === null || prev === void 0 ? void 0 : prev.isOnSale) !== null && _d !== void 0 ? _d : defaults.isOnSale,
705
- sku: (_e = prev === null || prev === void 0 ? void 0 : prev.sku) !== null && _e !== void 0 ? _e : defaults.sku,
706
- taxable: (_f = prev === null || prev === void 0 ? void 0 : prev.taxable) !== null && _f !== void 0 ? _f : defaults.taxable,
708
+ locations: nz((_a = prev === null || prev === void 0 ? void 0 : prev.locations) !== null && _a !== void 0 ? _a : defaults.locations),
709
+ price: nz((_b = prev === null || prev === void 0 ? void 0 : prev.price) !== null && _b !== void 0 ? _b : defaults.price),
710
+ compareAtPrice: nz((_c = prev === null || prev === void 0 ? void 0 : prev.compareAtPrice) !== null && _c !== void 0 ? _c : defaults.compareAtPrice),
711
+ salePrice: nz((_d = prev === null || prev === void 0 ? void 0 : prev.salePrice) !== null && _d !== void 0 ? _d : defaults.salePrice),
712
+ isOnSale: nz((_e = prev === null || prev === void 0 ? void 0 : prev.isOnSale) !== null && _e !== void 0 ? _e : defaults.isOnSale),
713
+ sku: nz((_f = prev === null || prev === void 0 ? void 0 : prev.sku) !== null && _f !== void 0 ? _f : defaults.sku),
714
+ taxable: nz((_g = prev === null || prev === void 0 ? void 0 : prev.taxable) !== null && _g !== void 0 ? _g : defaults.taxable),
715
+ costPerItem: nz((_h = prev === null || prev === void 0 ? void 0 : prev.costPerItem) !== null && _h !== void 0 ? _h : defaults.costPerItem),
716
+ continueSellingWhenOutOfStock: nz((_j = prev === null || prev === void 0 ? void 0 : prev.continueSellingWhenOutOfStock) !== null && _j !== void 0 ? _j : defaults.continueSellingWhenOutOfStock),
717
+ shopifyId: nz((_k = prev === null || prev === void 0 ? void 0 : prev.shopifyId) !== null && _k !== void 0 ? _k : defaults.shopifyId),
707
718
  };
708
719
  return merged;
709
720
  });
@@ -869,8 +880,10 @@ class ProductFormState extends FormState_1.default {
869
880
  return;
870
881
  const next = Object.assign({}, v);
871
882
  allowedKeys.forEach((k) => {
872
- if (patch[k] !== undefined)
873
- next[k] = patch[k];
883
+ if (patch[k] !== undefined) {
884
+ const val = patch[k];
885
+ next[k] = val === undefined ? null : val;
886
+ }
874
887
  });
875
888
  this.fields.variantInventory.selectedValues[idx] = next;
876
889
  });
@@ -406,6 +406,21 @@ class Product extends Base_1.default {
406
406
  const basePrice = ((_b = (_a = v.price) !== null && _a !== void 0 ? _a : this.attributes.price) !== null && _b !== void 0 ? _b : '0');
407
407
  const variant = Object.assign(Object.assign({}, baseVariantFields()), { optionValues,
408
408
  inventoryQuantities });
409
+ // Override inventory policy if allowed to continue selling
410
+ if (v.continueSellingWhenOutOfStock === true) {
411
+ variant.inventoryPolicy = 'CONTINUE';
412
+ }
413
+ else if (v.continueSellingWhenOutOfStock === false) {
414
+ variant.inventoryPolicy = 'DENY';
415
+ }
416
+ // Per-variant cost override
417
+ if (v.costPerItem !== undefined && v.costPerItem !== null) {
418
+ variant.inventoryItem.cost = this.utilities.sanitizeNumber(v.costPerItem, 0);
419
+ }
420
+ // Include variant id when present (for updates)
421
+ if (v.shopifyId) {
422
+ variant.id = v.shopifyId;
423
+ }
409
424
  if (v.sku) {
410
425
  variant.sku = v.sku;
411
426
  }
@@ -156,16 +156,16 @@ type VariantOptions = Record<string, string>;
156
156
  type VariantInventory = {
157
157
  id: string;
158
158
  options: VariantOptions;
159
- locations?: InventoryLocation[];
160
- price?: string;
161
- compareAtPrice?: string;
162
- salePrice?: string;
163
- isOnSale?: 'yes' | 'no';
164
- sku?: string;
165
- taxable?: 'yes' | 'no';
166
- shopifyId?: string;
167
- costPerItem?: string;
168
- continueSellingWhenOutOfStock?: boolean;
159
+ locations?: InventoryLocation[] | null;
160
+ price?: string | null;
161
+ compareAtPrice?: string | null;
162
+ salePrice?: string | null;
163
+ isOnSale?: 'yes' | 'no' | null;
164
+ sku?: string | null;
165
+ taxable?: 'yes' | 'no' | null;
166
+ shopifyId?: string | null;
167
+ costPerItem?: string | null;
168
+ continueSellingWhenOutOfStock?: boolean | null;
169
169
  };
170
170
  type ProductSellStatusKeys = 'SELL_REQUEST_REVIEW' | 'REJECTED' | 'HOLD' | 'ACCEPTED' | 'DROP_OFF_AT_REROBE' | 'SHIP_TO_REROBE' | 'AT_HOME_PICK_UP' | 'QUALITY_CONTROL' | 'LISTED' | 'SOLD' | 'RETURNED' | 'SOLD_SELLER_TO_BE_PAID' | 'SOLD_SELLER_PAID' | 'HIDDEN' | 'BOOKED' | 'OPEN';
171
171
  type ProductPublishKeys = 'USER_PUBLISHED' | 'MERCHANT_PUBLISHED';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "4.5.3",
3
+ "version": "4.5.4",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",