feeef 0.12.7 → 0.12.9

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/build/index.js CHANGED
@@ -3131,6 +3131,27 @@ function shouldSuppressPixelEvents(order) {
3131
3131
  }
3132
3132
 
3133
3133
  // src/core/entities/product_offer_policy.ts
3134
+ function finiteOfferNumber(value) {
3135
+ if (value === null || value === void 0 || value === "") return void 0;
3136
+ const n = typeof value === "number" ? value : Number(value);
3137
+ return Number.isFinite(n) ? n : void 0;
3138
+ }
3139
+ function clampQuantityToOfferLimits(offer, quantity) {
3140
+ let q = finiteOfferNumber(quantity);
3141
+ if (q === void 0 || q < 0) q = 1;
3142
+ const minQ = finiteOfferNumber(offer.minQuantity);
3143
+ const maxQ = finiteOfferNumber(offer.maxQuantity);
3144
+ if (minQ !== void 0 && minQ > 0) {
3145
+ q = Math.max(q, minQ);
3146
+ }
3147
+ if (maxQ !== void 0 && maxQ > 0) {
3148
+ q = Math.min(q, maxQ);
3149
+ }
3150
+ if (minQ !== void 0 && maxQ !== void 0 && minQ > 0 && maxQ > 0 && minQ > maxQ) {
3151
+ q = minQ;
3152
+ }
3153
+ return q;
3154
+ }
3134
3155
  function readForceOffer(product) {
3135
3156
  return product.forceOffer === true || product.force_offer === true;
3136
3157
  }
@@ -3349,33 +3370,18 @@ var CartService = class extends NotifiableService {
3349
3370
  applyProductOfferPolicy(item) {
3350
3371
  const forced = resolveForcedProductOffer(item.product);
3351
3372
  if (forced) {
3352
- const quantity = this.clampQuantityToOfferLimits(forced, item.quantity);
3373
+ const quantity = clampQuantityToOfferLimits(forced, item.quantity);
3353
3374
  return { ...item, offer: forced, quantity };
3354
3375
  }
3355
3376
  if (!item.offer) {
3356
3377
  const initial = resolveInitialProductOffer(item.product);
3357
3378
  if (initial) {
3358
- const quantity = this.clampQuantityToOfferLimits(initial, item.quantity);
3379
+ const quantity = clampQuantityToOfferLimits(initial, item.quantity);
3359
3380
  return { ...item, offer: initial, quantity };
3360
3381
  }
3361
3382
  }
3362
3383
  return item;
3363
3384
  }
3364
- /**
3365
- * Clamps the quantity to be within the offer's min/max range
3366
- * @param offer - The offer containing quantity constraints
3367
- * @param quantity - The quantity to clamp
3368
- * @returns The clamped quantity value
3369
- */
3370
- clampQuantityToOfferLimits(offer, quantity) {
3371
- if (offer.minQuantity !== void 0) {
3372
- quantity = Math.max(quantity, offer.minQuantity);
3373
- }
3374
- if (offer.maxQuantity !== void 0) {
3375
- quantity = Math.min(quantity, offer.maxQuantity);
3376
- }
3377
- return quantity;
3378
- }
3379
3385
  /**
3380
3386
  * Update item by unique key (product ID + variant + offer + addons).
3381
3387
  * @param item - The item to identify the cart item to update.
@@ -3387,7 +3393,7 @@ var CartService = class extends NotifiableService {
3387
3393
  const currentItem = this.items[index];
3388
3394
  const newItem = { ...currentItem, ...updates };
3389
3395
  if (newItem.offer) {
3390
- newItem.quantity = this.clampQuantityToOfferLimits(newItem.offer, newItem.quantity);
3396
+ newItem.quantity = clampQuantityToOfferLimits(newItem.offer, newItem.quantity);
3391
3397
  }
3392
3398
  this.items[index] = newItem;
3393
3399
  this.cachedSubtotal = null;
@@ -3403,6 +3409,12 @@ var CartService = class extends NotifiableService {
3403
3409
  updateCurrentItem(updates, notify = true) {
3404
3410
  if (!this.currentItem) return;
3405
3411
  this.currentItem = { ...this.currentItem, ...updates };
3412
+ if (this.currentItem.offer) {
3413
+ this.currentItem.quantity = clampQuantityToOfferLimits(
3414
+ this.currentItem.offer,
3415
+ this.currentItem.quantity
3416
+ );
3417
+ }
3406
3418
  const existingItemIndex = this.findItemIndex(this.currentItem);
3407
3419
  if (existingItemIndex !== -1) {
3408
3420
  this.items[existingItemIndex] = this.currentItem;
@@ -3592,12 +3604,14 @@ var CartService = class extends NotifiableService {
3592
3604
  }
3593
3605
  }
3594
3606
  if (offer) {
3595
- if (offer.price !== void 0) {
3596
- price = offer.price;
3607
+ const offerPrice = finiteOfferNumber(offer.price);
3608
+ if (offerPrice !== void 0) {
3609
+ price = offerPrice;
3597
3610
  discount = 0;
3598
3611
  }
3599
3612
  }
3600
- let total = (price - discount) * quantity;
3613
+ const safeQty = finiteOfferNumber(quantity) ?? 0;
3614
+ let total = (price - discount) * safeQty;
3601
3615
  if (addons && product.addons) {
3602
3616
  for (const [addonId, addonQuantity] of Object.entries(addons)) {
3603
3617
  const addon = product.addons.find((a) => a.title === addonId);
@@ -3615,8 +3629,10 @@ var CartService = class extends NotifiableService {
3615
3629
  * @returns boolean indicating if the offer is valid for the quantity
3616
3630
  */
3617
3631
  isOfferValidForQuantity(offer, quantity) {
3618
- if (offer.minQuantity && quantity < offer.minQuantity) return false;
3619
- if (offer.maxQuantity && quantity > offer.maxQuantity) return false;
3632
+ const minQ = finiteOfferNumber(offer.minQuantity);
3633
+ const maxQ = finiteOfferNumber(offer.maxQuantity);
3634
+ if (minQ !== void 0 && minQ > 0 && quantity < minQ) return false;
3635
+ if (maxQ !== void 0 && maxQ > 0 && quantity > maxQ) return false;
3620
3636
  return true;
3621
3637
  }
3622
3638
  /**
@@ -3631,7 +3647,7 @@ var CartService = class extends NotifiableService {
3631
3647
  if (next === "blocked") return;
3632
3648
  const updatedItem = { ...existingItem, offer: next };
3633
3649
  if (next) {
3634
- updatedItem.quantity = this.clampQuantityToOfferLimits(next, existingItem.quantity);
3650
+ updatedItem.quantity = clampQuantityToOfferLimits(next, existingItem.quantity);
3635
3651
  }
3636
3652
  this.updateItem(item, updatedItem);
3637
3653
  this.cachedSubtotal = null;
@@ -3647,7 +3663,7 @@ var CartService = class extends NotifiableService {
3647
3663
  if (next === "blocked") return;
3648
3664
  const updatedItem = { ...this.currentItem, offer: next };
3649
3665
  if (next) {
3650
- updatedItem.quantity = this.clampQuantityToOfferLimits(next, this.currentItem.quantity);
3666
+ updatedItem.quantity = clampQuantityToOfferLimits(next, this.currentItem.quantity);
3651
3667
  }
3652
3668
  this.updateCurrentItem(updatedItem, true);
3653
3669
  this.cachedSubtotal = null;
@@ -5979,6 +5995,7 @@ export {
5979
5995
  batchSummaryAllFailed,
5980
5996
  batchSummaryHasFailures,
5981
5997
  batchUpdateManyBody,
5998
+ clampQuantityToOfferLimits,
5982
5999
  convertDartColorToCssNumber,
5983
6000
  convertOrderEntityToOrderTrackEntity,
5984
6001
  createFeeefTransmit,
@@ -5987,6 +6004,7 @@ export {
5987
6004
  cssColorToHslString,
5988
6005
  dartColorToCssColor,
5989
6006
  defaultVoiceTtsTokenEstimates,
6007
+ finiteOfferNumber,
5990
6008
  formatProductLandingPageOrderReference,
5991
6009
  formatProductOrderReference,
5992
6010
  generatePublicIntegrationsData,