b23-lib 3.2.4 → 3.3.1

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.
@@ -1,2 +1,2 @@
1
- import {a}from'../chunk-VTBHWXR4.mjs';import'../chunk-B2VFJRLS.mjs';import'../chunk-RQ2FFWUW.mjs';import'../chunk-HX32EJ3F.mjs';import'../chunk-G6LH7V5B.mjs';import'../chunk-SOZHGHMY.mjs';import {b}from'../chunk-MHLRJ4IJ.mjs';import'../chunk-FCRJAAPY.mjs';import'../chunk-2B2XI6FG.mjs';import'../chunk-LI5JQ6UC.mjs';import'../chunk-QK4XJ3GB.mjs';import {a as a$1}from'../chunk-R5DM7WCD.mjs';import'../chunk-UXZBULDS.mjs';var u=(i=>(i.ACTIVE="ACTIVE",i.FROZEN="FROZEN",i.MERGED="MERGED",i.ORDERED="ORDERED",i))(u||{}),p={expiresAtInSeconds:120*24*60*60},c=class extends a{state;expireAt;config;constructor(t,e=new Date,r=p){super(t,e),this.state=t.state,this.expireAt=t.expireAt&&typeof t.expireAt=="number"?t.expireAt:Math.floor(e.getTime()/1e3)+r.expiresAtInSeconds,this.config=r;}getState(){return this.state}getExpireAt(){return this.expireAt}isActive(){let t=Math.ceil(Date.now()/1e3);return this.state==="ACTIVE"&&this.expireAt>t}clearCartItems(){this.lineItems=[],this.charges=[],this.coupons=[],this.shippingDetails=null,this.calculateTotals();}validateLineItems(t){this.lineItems=this.lineItems.map(e=>{try{e.updateProductData(t[e.getProductKey()],this.country,this.currency);}catch(r){console.error(`Error recalculating line item ${e.getId()}:`,r),e.clearLineItem();}return e}).filter(e=>e.getId()),this.calculateTotals();}addLineItem(t){let e=t.getProductKey(),r=t.getSelectionAttributes(),i=b.generateSelectionAttributesKey(r),s=this.lineItems.findIndex(n=>n.getProductKey()===e&&b.generateSelectionAttributesKey(n.getSelectionAttributes())===i);return s>=0?this.lineItems[s].addSubItems(t.getSubItems(),!0):this.lineItems.push(t),this.calculateTotals(),s>=0?s:this.lineItems.length-1}updateLineItem(t,e,r){let i=this.lineItems,s=i.findIndex(n=>n.getId()===t);if(s<0)throw new a$1(t);return i[s].addSubItems([{size:e,quantity:r}],!1),this.calculateTotals(),s}removeLineItem(t){let r=this.lineItems.findIndex(i=>i.getId()===t);if(r<0)throw new a$1(t);return this.lineItems.splice(r,1),this.charges=this.charges.filter(i=>i.getLineItemId()!==t),this.calculateTotals(),r}getDetails(){return {...super.getDetails(),state:this.getState(),expireAt:this.getExpireAt()}}};export{u as CartState,p as DEFAULT_CART_CONFIG,c as default};//# sourceMappingURL=Cart.mjs.map
1
+ import {a}from'../chunk-3TUSUSXQ.mjs';import'../chunk-B2VFJRLS.mjs';import'../chunk-HX32EJ3F.mjs';import'../chunk-G6LH7V5B.mjs';import'../chunk-SOZHGHMY.mjs';import'../chunk-RQ2FFWUW.mjs';import {b}from'../chunk-MHLRJ4IJ.mjs';import'../chunk-FCRJAAPY.mjs';import'../chunk-2B2XI6FG.mjs';import'../chunk-LI5JQ6UC.mjs';import'../chunk-QK4XJ3GB.mjs';import {a as a$1}from'../chunk-R5DM7WCD.mjs';import'../chunk-UXZBULDS.mjs';var u=(i=>(i.ACTIVE="ACTIVE",i.FROZEN="FROZEN",i.MERGED="MERGED",i.ORDERED="ORDERED",i))(u||{}),p={expiresAtInSeconds:120*24*60*60},c=class extends a{state;expireAt;config;constructor(t,e=new Date,r=p){super(t,e),this.state=t.state,this.expireAt=t.expireAt&&typeof t.expireAt=="number"?t.expireAt:Math.floor(e.getTime()/1e3)+r.expiresAtInSeconds,this.config=r;}getState(){return this.state}getExpireAt(){return this.expireAt}isActive(){let t=Math.ceil(Date.now()/1e3);return this.state==="ACTIVE"&&this.expireAt>t}clearCartItems(){this.lineItems=[],this.charges=[],this.coupons=[],this.shippingDetails=null,this.calculateTotals();}validateLineItems(t){this.lineItems=this.lineItems.map(e=>{try{e.updateProductData(t[e.getProductKey()],this.country,this.currency);}catch(r){console.error(`Error recalculating line item ${e.getId()}:`,r),e.clearLineItem();}return e}).filter(e=>e.getId()),this.calculateTotals();}addLineItem(t){let e=t.getProductKey(),r=t.getSelectionAttributes(),i=b.generateSelectionAttributesKey(r),s=this.lineItems.findIndex(n=>n.getProductKey()===e&&b.generateSelectionAttributesKey(n.getSelectionAttributes())===i);return s>=0?this.lineItems[s].addSubItems(t.getSubItems(),!0):this.lineItems.push(t),this.calculateTotals(),s>=0?s:this.lineItems.length-1}updateLineItem(t,e,r){let i=this.lineItems,s=i.findIndex(n=>n.getId()===t);if(s<0)throw new a$1(t);return i[s].addSubItems([{size:e,quantity:r}],!1),this.calculateTotals(),s}removeLineItem(t){let r=this.lineItems.findIndex(i=>i.getId()===t);if(r<0)throw new a$1(t);return this.lineItems.splice(r,1),this.charges=this.charges.filter(i=>i.getLineItemId()!==t),this.calculateTotals(),r}getDetails(){return {...super.getDetails(),state:this.getState(),expireAt:this.getExpireAt()}}};export{u as CartState,p as DEFAULT_CART_CONFIG,c as default};//# sourceMappingURL=Cart.mjs.map
2
2
  //# sourceMappingURL=Cart.mjs.map
@@ -1,2 +1,2 @@
1
- import {a as a$1}from'../chunk-VTBHWXR4.mjs';import'../chunk-B2VFJRLS.mjs';import'../chunk-RQ2FFWUW.mjs';import {b}from'../chunk-HX32EJ3F.mjs';import'../chunk-G6LH7V5B.mjs';import'../chunk-SOZHGHMY.mjs';import'../chunk-MHLRJ4IJ.mjs';import'../chunk-FCRJAAPY.mjs';import'../chunk-2B2XI6FG.mjs';import'../chunk-LI5JQ6UC.mjs';import'../chunk-QK4XJ3GB.mjs';import {a as a$2}from'../chunk-R5DM7WCD.mjs';import'../chunk-UXZBULDS.mjs';var a=(s=>(s.PLACED="PLACED",s.PENDING_PAYMENT="PENDING_PAYMENT",s.PROCESSING="PROCESSING",s.CANCELLED="CANCELLED",s.COMPLETED="COMPLETED",s))(a||{}),i=class extends a$1{orderNumber;cartId;paymentStatus;holdReason;state;shippingAddress;billingAddress;constructor(t,e=new Date){super(t,e),this.orderNumber=t.orderNumber,this.cartId=t.cartId,this.paymentStatus=t.paymentStatus,this.holdReason=t.holdReason||"",this.state=t.state,this.shippingAddress=new b(t.shippingAddress,e),this.billingAddress=new b(t.billingAddress,e);}getCustomerId(){return this.customerId}getCustomerEmail(){return this.customerEmail}getShippingAddress(){return this.shippingAddress}getBillingAddress(){return this.billingAddress}getOrderNumber(){return this.orderNumber}getCartId(){return this.cartId}getPaymentStatus(){return this.paymentStatus}getHoldReason(){return this.holdReason}getState(){return this.state}getLineItemState(t){let e=this.getLineItems().find(o=>o.getId()===t);if(!e)throw new a$2(t);return e.getState()}getDetails(){return {...super.getDetails(),orderNumber:this.getOrderNumber(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),shippingAddress:this.getShippingAddress().getDetails(),billingAddress:this.getBillingAddress().getDetails(),cartId:this.getCartId(),paymentStatus:this.getPaymentStatus(),holdReason:this.getHoldReason(),state:this.getState()}}};export{a as OrderState,i as default};//# sourceMappingURL=Order.mjs.map
1
+ import {a as a$1}from'../chunk-3TUSUSXQ.mjs';import'../chunk-B2VFJRLS.mjs';import {b}from'../chunk-HX32EJ3F.mjs';import'../chunk-G6LH7V5B.mjs';import'../chunk-SOZHGHMY.mjs';import'../chunk-RQ2FFWUW.mjs';import'../chunk-MHLRJ4IJ.mjs';import'../chunk-FCRJAAPY.mjs';import'../chunk-2B2XI6FG.mjs';import'../chunk-LI5JQ6UC.mjs';import'../chunk-QK4XJ3GB.mjs';import {a as a$2}from'../chunk-R5DM7WCD.mjs';import'../chunk-UXZBULDS.mjs';var a=(s=>(s.PLACED="PLACED",s.PENDING_PAYMENT="PENDING_PAYMENT",s.PROCESSING="PROCESSING",s.CANCELLED="CANCELLED",s.COMPLETED="COMPLETED",s))(a||{}),i=class extends a$1{orderNumber;cartId;paymentStatus;holdReason;state;shippingAddress;billingAddress;constructor(t,e=new Date){super(t,e),this.orderNumber=t.orderNumber,this.cartId=t.cartId,this.paymentStatus=t.paymentStatus,this.holdReason=t.holdReason||"",this.state=t.state,this.shippingAddress=new b(t.shippingAddress,e),this.billingAddress=new b(t.billingAddress,e);}getCustomerId(){return this.customerId}getCustomerEmail(){return this.customerEmail}getShippingAddress(){return this.shippingAddress}getBillingAddress(){return this.billingAddress}getOrderNumber(){return this.orderNumber}getCartId(){return this.cartId}getPaymentStatus(){return this.paymentStatus}getHoldReason(){return this.holdReason}getState(){return this.state}getLineItemState(t){let e=this.getLineItems().find(o=>o.getId()===t);if(!e)throw new a$2(t);return e.getState()}getDetails(){return {...super.getDetails(),orderNumber:this.getOrderNumber(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),shippingAddress:this.getShippingAddress().getDetails(),billingAddress:this.getBillingAddress().getDetails(),cartId:this.getCartId(),paymentStatus:this.getPaymentStatus(),holdReason:this.getHoldReason(),state:this.getState()}}};export{a as OrderState,i as default};//# sourceMappingURL=Order.mjs.map
2
2
  //# sourceMappingURL=Order.mjs.map
@@ -1,2 +1,2 @@
1
- export{a as default}from'../chunk-VTBHWXR4.mjs';import'../chunk-B2VFJRLS.mjs';import'../chunk-RQ2FFWUW.mjs';import'../chunk-HX32EJ3F.mjs';import'../chunk-G6LH7V5B.mjs';import'../chunk-SOZHGHMY.mjs';import'../chunk-MHLRJ4IJ.mjs';import'../chunk-FCRJAAPY.mjs';import'../chunk-2B2XI6FG.mjs';import'../chunk-LI5JQ6UC.mjs';import'../chunk-QK4XJ3GB.mjs';import'../chunk-R5DM7WCD.mjs';import'../chunk-UXZBULDS.mjs';//# sourceMappingURL=ShoppingContainer.mjs.map
1
+ export{a as default}from'../chunk-3TUSUSXQ.mjs';import'../chunk-B2VFJRLS.mjs';import'../chunk-HX32EJ3F.mjs';import'../chunk-G6LH7V5B.mjs';import'../chunk-SOZHGHMY.mjs';import'../chunk-RQ2FFWUW.mjs';import'../chunk-MHLRJ4IJ.mjs';import'../chunk-FCRJAAPY.mjs';import'../chunk-2B2XI6FG.mjs';import'../chunk-LI5JQ6UC.mjs';import'../chunk-QK4XJ3GB.mjs';import'../chunk-R5DM7WCD.mjs';import'../chunk-UXZBULDS.mjs';//# sourceMappingURL=ShoppingContainer.mjs.map
2
2
  //# sourceMappingURL=ShoppingContainer.mjs.map
@@ -1,2 +1,2 @@
1
- import {a}from'./chunk-B2VFJRLS.mjs';import {e}from'./chunk-RQ2FFWUW.mjs';import {b as b$1}from'./chunk-HX32EJ3F.mjs';import {a as a$1}from'./chunk-G6LH7V5B.mjs';import {a as a$2}from'./chunk-MHLRJ4IJ.mjs';import {a as a$3}from'./chunk-LI5JQ6UC.mjs';import {b}from'./chunk-UXZBULDS.mjs';var B=class extends b{id;customerId;customerEmail;anonymousId;lineItems;charges;shippingDetails;shippingAddress;billingAddress;coupons;total;country;currency;locale;constructor(t,e$1=new Date){super(t,e$1),this.id=t.id,this.customerId=t.customerId,this.customerEmail=t.customerEmail,this.anonymousId=t.anonymousId,this.country=t.country,this.currency=t.currency,this.locale=t.locale,this.lineItems=(t.lineItems??[]).map(i=>new a(i)),this.charges=(t.charges??[]).map(i=>new a$1(i)),this.billingAddress=t.billingAddress?new b$1(t.billingAddress,e$1):null,this.shippingAddress=t.shippingAddress?new b$1(t.shippingAddress,e$1):null,this.coupons=(t.coupons??[]).map(i=>new e(i)),this.shippingDetails=t.shippingDetails?a$2.deepClone(t.shippingDetails):null,this.total={lineItemSubtotal:new a$3(t.total.lineItemSubtotal),netLineItemSubtotal:new a$3(t.total.netLineItemSubtotal),lineItemTaxTotal:new a$3(t.total.lineItemTaxTotal),lineItemTaxBreakdown:this.mapTaxBreakdown(t.total.lineItemTaxBreakdown),additiveCharges:new a$3(t.total.additiveCharges),netAdditiveCharges:new a$3(t.total.netAdditiveCharges),additiveChargesTaxTotal:new a$3(t.total.additiveChargesTaxTotal),additiveChargesTaxBreakdown:this.mapTaxBreakdown(t.total.additiveChargesTaxBreakdown),adjustmentCharges:new a$3(t.total.adjustmentCharges),shippingCharges:new a$3(t.total.shippingCharges),netShippingCharges:new a$3(t.total.netShippingCharges),discountTotal:new a$3(t.total.discountTotal),discountBreakdown:Object.fromEntries(Object.entries(t.total.discountBreakdown).map(([i,a])=>[i,new a$3(a)])),taxTotal:new a$3(t.total.taxTotal),taxBreakdown:this.mapTaxBreakdown(t.total.taxBreakdown),grandTotal:new a$3(t.total.grandTotal)};}mapTaxBreakdown(t){return Object.fromEntries(Object.entries(t||{}).map(([e,i])=>[e,{system:i.system,totalAmount:new a$3(i.totalAmount),subSystems:Object.fromEntries(Object.entries(i.subSystems).map(([a,n])=>[a,new a$3(n)]))}]))}serializeTaxBreakdown(t){return Object.fromEntries(Object.entries(t||{}).map(([e,i])=>[e,{system:i.system,totalAmount:i.totalAmount.getDetails(),subSystems:Object.fromEntries(Object.entries(i.subSystems).map(([a,n])=>[a,n.getDetails()]))}]))}getId(){return this.id}getCustomerId(){return this.customerId}getCustomerEmail(){return this.customerEmail}getAnonymousId(){return this.anonymousId}getLineItems(){return this.lineItems.map(t=>new a(t.getDetails()))}getLineItemsCount(){return this.lineItems.length}getCharges(){return this.charges.map(t=>new a$1(t.getDetails()))}addCharge(t){this.charges.push(t),this.calculateTotals();}clearCharges(){this.charges=[],this.calculateTotals();}getShippingDetails(){return this.shippingDetails?a$2.deepClone(this.shippingDetails):null}getShippingAddress(){return this.shippingAddress?new b$1(this.shippingAddress.getDetails()):null}hasShippingAddress(){return !!this.shippingAddress}hasBillingAddress(){return !!this.billingAddress}getBillingAddress(){return this.billingAddress?new b$1(this.billingAddress.getDetails()):null}getCoupons(){return [...this.coupons]}getCountry(){return this.country}getCurrency(){return this.currency}getLocale(){return this.locale}getTotal(){return {lineItemSubtotal:this.total.lineItemSubtotal,netLineItemSubtotal:this.total.netLineItemSubtotal,lineItemTaxTotal:this.total.lineItemTaxTotal,lineItemTaxBreakdown:Object.fromEntries(Object.entries(this.total.lineItemTaxBreakdown).map(([t,e])=>[t,{system:e.system,totalAmount:e.totalAmount,subSystems:{...e.subSystems}}])),additiveCharges:this.total.additiveCharges,netAdditiveCharges:this.total.netAdditiveCharges,additiveChargesTaxTotal:this.total.additiveChargesTaxTotal,additiveChargesTaxBreakdown:Object.fromEntries(Object.entries(this.total.additiveChargesTaxBreakdown).map(([t,e])=>[t,{system:e.system,totalAmount:e.totalAmount,subSystems:{...e.subSystems}}])),adjustmentCharges:this.total.adjustmentCharges,shippingCharges:this.total.shippingCharges,netShippingCharges:this.total.netShippingCharges,discountBreakdown:{...this.total.discountBreakdown},discountTotal:this.total.discountTotal,taxTotal:this.total.taxTotal,taxBreakdown:Object.fromEntries(Object.entries(this.total.taxBreakdown).map(([t,e])=>[t,{system:e.system,totalAmount:e.totalAmount,subSystems:{...e.subSystems}}])),grandTotal:this.total.grandTotal}}getDetails(){let t=this.getTotal();return {...super.getDetails(),id:this.getId(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),anonymousId:this.getAnonymousId(),lineItems:this.getLineItems().map(e=>e.getDetails()),charges:this.getCharges().map(e=>e.getDetails()),shippingDetails:this.getShippingDetails(),shippingAddress:this.getShippingAddress()?.getDetails()||null,billingAddress:this.getBillingAddress()?.getDetails()||null,coupons:this.getCoupons().map(e=>e.getDetails()),total:{lineItemSubtotal:t.lineItemSubtotal.getDetails(),netLineItemSubtotal:t.netLineItemSubtotal.getDetails(),lineItemTaxTotal:t.lineItemTaxTotal.getDetails(),lineItemTaxBreakdown:this.serializeTaxBreakdown(t.lineItemTaxBreakdown),additiveCharges:t.additiveCharges.getDetails(),netAdditiveCharges:t.netAdditiveCharges.getDetails(),additiveChargesTaxTotal:t.additiveChargesTaxTotal.getDetails(),additiveChargesTaxBreakdown:this.serializeTaxBreakdown(t.additiveChargesTaxBreakdown),adjustmentCharges:t.adjustmentCharges.getDetails(),shippingCharges:t.shippingCharges.getDetails(),netShippingCharges:t.netShippingCharges.getDetails(),discountTotal:t.discountTotal.getDetails(),discountBreakdown:Object.fromEntries(Object.entries(t.discountBreakdown).map(([e,i])=>[e,i.getDetails()])),taxTotal:t.taxTotal.getDetails(),taxBreakdown:this.serializeTaxBreakdown(t.taxBreakdown),grandTotal:t.grandTotal.getDetails()},country:this.getCountry(),currency:this.getCurrency(),locale:this.getLocale()}}calculateTotals(){let t=new a$3({amount:0,currency:this.currency}),e=this.lineItems.filter(s=>s.getState()!=="CANCELLED"),i=e.reduce((s,o)=>s.add(o.getTotal().subtotal),t),a=this.charges.filter(s=>s.getType()==="SHIPPING").reduce((s,o)=>s.add(o.getTotal().chargeAmount),t);this.total.lineItemSubtotal=i,this.total.shippingCharges=a;let n=t,d={},u={};this.coupons.forEach(s=>{let o=s.calculateApplicableCouponDiscount(i,a,this.country,this.currency);n=n.add(o),d[s.getCode()]=o,s.getCategory()!=="SHIPPING"&&(u[s.getCode()]=o);}),this.total.discountTotal=n,this.total.discountBreakdown=d,this.applyDiscountsInLineItem(u);let h=this.coupons.find(s=>s.getCategory()==="SHIPPING");h?this.applyDiscountsInShippingCharges({[h.getCode()]:d[h.getCode()]||t}):this.applyDiscountsInShippingCharges({});let g=this.lineItems.reduce((s,o)=>s.add(o.getTotal().netSubtotal),t),c=this.charges.filter(s=>s.getType()==="SHIPPING").reduce((s,o)=>s.add(o.getTotal().grandTotal),t);this.total.netLineItemSubtotal=g,this.total.netShippingCharges=c;let m=this.charges.filter(s=>s.getImpact()==="ADD").reduce((s,o)=>s.add(o.getTotal().chargeAmount),t),y=this.charges.filter(s=>s.getImpact()==="ADD").reduce((s,o)=>s.add(o.getTotal().grandTotal),t),f=this.charges.filter(s=>s.getImpact()==="SUBTRACT").reduce((s,o)=>s.add(o.getTotal().grandTotal),t),M=t,I=t,b=t,p={},k={},P={},x=(s,o)=>{Object.entries(s).forEach(([O,C])=>{let l=C.system,T=C.subSystem;o[l]||(o[l]={system:l,totalAmount:t,subSystems:{}}),o[l].subSystems[T]?o[l].subSystems[T]=o[l].subSystems[T].add(C.taxAmount):o[l].subSystems[T]=C.taxAmount,o[l].totalAmount=o[l].totalAmount.add(C.taxAmount),p[l]||(p[l]={system:l,totalAmount:t,subSystems:{}}),p[l].subSystems[T]?p[l].subSystems[T]=p[l].subSystems[T].add(C.taxAmount):p[l].subSystems[T]=C.taxAmount,p[l].totalAmount=p[l].totalAmount.add(C.taxAmount);});};e.forEach(s=>{let o=s.getTotal().taxBreakdown;o&&(x(o,k),x(o,p),I=I.add(s.getTotal().taxTotal));}),this.charges.forEach(s=>{let o=s.getTotal().taxBreakdown;o&&(x(o,P),x(o,p),b=b.add(s.getTotal().taxTotal));}),M=I.add(b);let E=g.add(I).add(y).subtract(f);this.total={lineItemSubtotal:i,netLineItemSubtotal:g,lineItemTaxTotal:I,lineItemTaxBreakdown:k,additiveCharges:m,netAdditiveCharges:y,additiveChargesTaxTotal:b,additiveChargesTaxBreakdown:P,adjustmentCharges:f,shippingCharges:a,netShippingCharges:c,discountTotal:n,discountBreakdown:d,taxTotal:M,taxBreakdown:p,grandTotal:E};}updateShippingDetails(t){this.shippingDetails=t;}applyCoupons(t){let e=t.filter(a=>a.getCategory()==="SHIPPING"),i=t.filter(a=>a.getCategory()!=="SHIPPING");this.coupons=[],this.total.discountTotal=this.total.lineItemSubtotal.zero(),this.total.discountBreakdown={},i.length&&this.applyNonShippingCoupons(i),this.applyDiscountsInLineItem(this.total.discountBreakdown),e.length&&this.applyShippingCoupons(e),this.calculateTotals();}applyDiscountsInLineItem(t){let e=Array.from(Object.entries(t)).filter(a=>!a[1].isZero()),i=new Map;this.lineItems.forEach(a=>i.set(a.getId(),[])),e.forEach(([a,n])=>{let d=this.coupons.find(g=>g.getCode()===a);if(!d||n.isZero())return;let u=this.lineItems.filter(g=>g.getState()!=="CANCELLED"&&!g.getTotal().subtotal.isZero()).sort((g,c)=>g.getTotal().subtotal.compareTo(c.getTotal().subtotal)),h=new a$3({amount:0,currency:this.currency});u.forEach((g,c)=>{let m;c===u.length-1?m=n.subtract(h):m=n.multiply(g.getTotal().subtotal).divide(this.total.lineItemSubtotal).round(),h=h.add(m),i.get(g.getId())?.push({coupon:d,amount:m});});}),this.lineItems.forEach(a=>{a.getState()==="CANCELLED"||this.total.lineItemSubtotal.isZero()?a.updateDiscounts([]):a.updateDiscounts(i.get(a.getId())||[]);});}applyDiscountsInShippingCharges(t){let e=Array.from(Object.entries(t)).filter(n=>!n[1].isZero()),i=this.charges.filter(n=>n.getType()==="SHIPPING"),a=new Map;i.forEach(n=>a.set(n.getId(),[])),e.forEach(([n,d])=>{let u=this.coupons.find(c=>c.getCode()===n);if(!u||d.isZero())return;let h=i.sort((c,m)=>c.getTotal().grandTotal.compareTo(m.getTotal().grandTotal)),g=new a$3({amount:0,currency:this.currency});h.forEach((c,m)=>{let y;m===h.length-1?y=d.subtract(g):y=d.multiply(c.getTotal().chargeAmount).divide(this.total.shippingCharges).round(),g=g.add(y),a.get(c.getId())?.push({coupon:u,amount:y});});}),i.forEach(n=>{n.updateDiscounts(a.get(n.getId())||[]);});}applyNonShippingCoupons(t){let e=t.filter(i=>i.getType()==="coupon");if(e.length===1){let i=e[0].calculateApplicableCouponDiscount(this.total.lineItemSubtotal,this.total.shippingCharges,this.country,this.currency);i.getAmount()>0&&(this.coupons.push(e[0]),this.total.discountTotal=i,this.total.discountBreakdown[e[0].getCode()]=i);}}applyShippingCoupons(t){if(this.total.shippingCharges.getAmount()>0&&t.length>0){let e=this.total.lineItemSubtotal.subtract(this.total.discountTotal),i=t.reduce((n,d)=>{if(!n)return d;let u=d.calculateApplicableCouponDiscount(e,this.total.shippingCharges,this.country,this.currency).min(this.total.shippingCharges),h=n.calculateApplicableCouponDiscount(e,this.total.shippingCharges,this.country,this.currency).min(this.total.shippingCharges);return u.compareTo(h)===0?d.getType()==="coupon"?d:n:u.compareTo(h)>0?d:n}),a=i.calculateApplicableCouponDiscount(e,this.total.shippingCharges,this.country,this.currency).min(this.total.shippingCharges);a.getAmount()>0&&(this.coupons.push(i),this.total.discountTotal=this.total.discountTotal.add(a),this.total.discountBreakdown[i.getCode()]=a);}}};export{B as a};//# sourceMappingURL=chunk-VTBHWXR4.mjs.map
2
- //# sourceMappingURL=chunk-VTBHWXR4.mjs.map
1
+ import {a}from'./chunk-B2VFJRLS.mjs';import {b as b$1}from'./chunk-HX32EJ3F.mjs';import {a as a$1}from'./chunk-G6LH7V5B.mjs';import {e}from'./chunk-RQ2FFWUW.mjs';import {a as a$2}from'./chunk-MHLRJ4IJ.mjs';import {a as a$3}from'./chunk-LI5JQ6UC.mjs';import {b}from'./chunk-UXZBULDS.mjs';var B=class extends b{id;customerId;customerEmail;anonymousId;lineItems;charges;shippingDetails;shippingAddress;billingAddress;coupons;total;country;currency;locale;constructor(t,e$1=new Date){super(t,e$1),this.id=t.id,this.customerId=t.customerId,this.customerEmail=t.customerEmail,this.anonymousId=t.anonymousId,this.country=t.country,this.currency=t.currency,this.locale=t.locale,this.lineItems=(t.lineItems??[]).map(i=>new a(i)),this.charges=(t.charges??[]).map(i=>new a$1(i)),this.billingAddress=t.billingAddress?new b$1(t.billingAddress,e$1):null,this.shippingAddress=t.shippingAddress?new b$1(t.shippingAddress,e$1):null,this.coupons=(t.coupons??[]).map(i=>new e(i)),this.shippingDetails=t.shippingDetails?a$2.deepClone(t.shippingDetails):null,this.total={lineItemSubtotal:new a$3(t.total.lineItemSubtotal),netLineItemSubtotal:new a$3(t.total.netLineItemSubtotal),lineItemTaxTotal:new a$3(t.total.lineItemTaxTotal),lineItemTaxBreakdown:this.mapTaxBreakdown(t.total.lineItemTaxBreakdown),additiveCharges:new a$3(t.total.additiveCharges),netAdditiveCharges:new a$3(t.total.netAdditiveCharges),additiveChargesTaxTotal:new a$3(t.total.additiveChargesTaxTotal),additiveChargesTaxBreakdown:this.mapTaxBreakdown(t.total.additiveChargesTaxBreakdown),adjustmentCharges:new a$3(t.total.adjustmentCharges),shippingCharges:new a$3(t.total.shippingCharges),netShippingCharges:new a$3(t.total.netShippingCharges),discountTotal:new a$3(t.total.discountTotal),discountBreakdown:Object.fromEntries(Object.entries(t.total.discountBreakdown).map(([i,a])=>[i,new a$3(a)])),taxTotal:new a$3(t.total.taxTotal),taxBreakdown:this.mapTaxBreakdown(t.total.taxBreakdown),grandTotal:new a$3(t.total.grandTotal)};}mapTaxBreakdown(t){return Object.fromEntries(Object.entries(t||{}).map(([e,i])=>[e,{system:i.system,totalAmount:new a$3(i.totalAmount),subSystems:Object.fromEntries(Object.entries(i.subSystems).map(([a,n])=>[a,new a$3(n)]))}]))}serializeTaxBreakdown(t){return Object.fromEntries(Object.entries(t||{}).map(([e,i])=>[e,{system:i.system,totalAmount:i.totalAmount.getDetails(),subSystems:Object.fromEntries(Object.entries(i.subSystems).map(([a,n])=>[a,n.getDetails()]))}]))}getId(){return this.id}getCustomerId(){return this.customerId}getCustomerEmail(){return this.customerEmail}getAnonymousId(){return this.anonymousId}getLineItems(){return this.lineItems.map(t=>new a(t.getDetails()))}getLineItemsCount(){return this.lineItems.length}getCharges(){return this.charges.map(t=>new a$1(t.getDetails()))}addCharge(t){this.charges.push(t),this.calculateTotals();}clearCharges(){this.charges=[],this.calculateTotals();}getShippingDetails(){return this.shippingDetails?a$2.deepClone(this.shippingDetails):null}getShippingAddress(){return this.shippingAddress?new b$1(this.shippingAddress.getDetails()):null}hasShippingAddress(){return !!this.shippingAddress}hasBillingAddress(){return !!this.billingAddress}getBillingAddress(){return this.billingAddress?new b$1(this.billingAddress.getDetails()):null}getCoupons(){return [...this.coupons]}getCountry(){return this.country}getCurrency(){return this.currency}getLocale(){return this.locale}getTotal(){return {lineItemSubtotal:this.total.lineItemSubtotal,netLineItemSubtotal:this.total.netLineItemSubtotal,lineItemTaxTotal:this.total.lineItemTaxTotal,lineItemTaxBreakdown:Object.fromEntries(Object.entries(this.total.lineItemTaxBreakdown).map(([t,e])=>[t,{system:e.system,totalAmount:e.totalAmount,subSystems:{...e.subSystems}}])),additiveCharges:this.total.additiveCharges,netAdditiveCharges:this.total.netAdditiveCharges,additiveChargesTaxTotal:this.total.additiveChargesTaxTotal,additiveChargesTaxBreakdown:Object.fromEntries(Object.entries(this.total.additiveChargesTaxBreakdown).map(([t,e])=>[t,{system:e.system,totalAmount:e.totalAmount,subSystems:{...e.subSystems}}])),adjustmentCharges:this.total.adjustmentCharges,shippingCharges:this.total.shippingCharges,netShippingCharges:this.total.netShippingCharges,discountBreakdown:{...this.total.discountBreakdown},discountTotal:this.total.discountTotal,taxTotal:this.total.taxTotal,taxBreakdown:Object.fromEntries(Object.entries(this.total.taxBreakdown).map(([t,e])=>[t,{system:e.system,totalAmount:e.totalAmount,subSystems:{...e.subSystems}}])),grandTotal:this.total.grandTotal}}getDetails(){let t=this.getTotal();return {...super.getDetails(),id:this.getId(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),anonymousId:this.getAnonymousId(),lineItems:this.getLineItems().map(e=>e.getDetails()),charges:this.getCharges().map(e=>e.getDetails()),shippingDetails:this.getShippingDetails(),shippingAddress:this.getShippingAddress()?.getDetails()||null,billingAddress:this.getBillingAddress()?.getDetails()||null,coupons:this.getCoupons().map(e=>e.getDetails()),total:{lineItemSubtotal:t.lineItemSubtotal.getDetails(),netLineItemSubtotal:t.netLineItemSubtotal.getDetails(),lineItemTaxTotal:t.lineItemTaxTotal.getDetails(),lineItemTaxBreakdown:this.serializeTaxBreakdown(t.lineItemTaxBreakdown),additiveCharges:t.additiveCharges.getDetails(),netAdditiveCharges:t.netAdditiveCharges.getDetails(),additiveChargesTaxTotal:t.additiveChargesTaxTotal.getDetails(),additiveChargesTaxBreakdown:this.serializeTaxBreakdown(t.additiveChargesTaxBreakdown),adjustmentCharges:t.adjustmentCharges.getDetails(),shippingCharges:t.shippingCharges.getDetails(),netShippingCharges:t.netShippingCharges.getDetails(),discountTotal:t.discountTotal.getDetails(),discountBreakdown:Object.fromEntries(Object.entries(t.discountBreakdown).map(([e,i])=>[e,i.getDetails()])),taxTotal:t.taxTotal.getDetails(),taxBreakdown:this.serializeTaxBreakdown(t.taxBreakdown),grandTotal:t.grandTotal.getDetails()},country:this.getCountry(),currency:this.getCurrency(),locale:this.getLocale()}}calculateTotals(){let t=new a$3({amount:0,currency:this.currency}),e=this.lineItems.filter(s=>s.getState()!=="CANCELLED"),i=e.reduce((s,o)=>s.add(o.getTotal().subtotal),t),a=this.charges.filter(s=>s.getType()==="SHIPPING").reduce((s,o)=>s.add(o.getTotal().chargeAmount),t);this.total.lineItemSubtotal=i,this.total.shippingCharges=a;let n=t,d={},u={};this.coupons.forEach(s=>{let o=s.calculateApplicableCouponDiscount(i,a,this.country,this.currency);n=n.add(o),d[s.getCode()]=o,s.getCategory()!=="SHIPPING"&&(u[s.getCode()]=o);}),this.total.discountTotal=n,this.total.discountBreakdown=d,this.applyDiscountsInLineItem(u);let h=this.coupons.find(s=>s.getCategory()==="SHIPPING");h?this.applyDiscountsInShippingCharges({[h.getCode()]:d[h.getCode()]||t}):this.applyDiscountsInShippingCharges({});let g=this.lineItems.reduce((s,o)=>s.add(o.getTotal().netSubtotal),t),c=this.charges.filter(s=>s.getType()==="SHIPPING").reduce((s,o)=>s.add(o.getTotal().grandTotal),t);this.total.netLineItemSubtotal=g,this.total.netShippingCharges=c;let m=this.charges.filter(s=>s.getImpact()==="ADD").reduce((s,o)=>s.add(o.getTotal().chargeAmount),t),y=this.charges.filter(s=>s.getImpact()==="ADD").reduce((s,o)=>s.add(o.getTotal().grandTotal),t),f=this.charges.filter(s=>s.getImpact()==="SUBTRACT").reduce((s,o)=>s.add(o.getTotal().grandTotal),t),M=t,I=t,b=t,p={},k={},P={},x=(s,o)=>{Object.entries(s).forEach(([O,C])=>{let l=C.system,T=C.subSystem;o[l]||(o[l]={system:l,totalAmount:t,subSystems:{}}),o[l].subSystems[T]?o[l].subSystems[T]=o[l].subSystems[T].add(C.taxAmount):o[l].subSystems[T]=C.taxAmount,o[l].totalAmount=o[l].totalAmount.add(C.taxAmount),p[l]||(p[l]={system:l,totalAmount:t,subSystems:{}}),p[l].subSystems[T]?p[l].subSystems[T]=p[l].subSystems[T].add(C.taxAmount):p[l].subSystems[T]=C.taxAmount,p[l].totalAmount=p[l].totalAmount.add(C.taxAmount);});};e.forEach(s=>{let o=s.getTotal().taxBreakdown;o&&(x(o,k),x(o,p),I=I.add(s.getTotal().taxTotal));}),this.charges.forEach(s=>{let o=s.getTotal().taxBreakdown;o&&(x(o,P),x(o,p),b=b.add(s.getTotal().taxTotal));}),M=I.add(b);let E=g.add(I).add(y).subtract(f);this.total={lineItemSubtotal:i,netLineItemSubtotal:g,lineItemTaxTotal:I,lineItemTaxBreakdown:k,additiveCharges:m,netAdditiveCharges:y,additiveChargesTaxTotal:b,additiveChargesTaxBreakdown:P,adjustmentCharges:f,shippingCharges:a,netShippingCharges:c,discountTotal:n,discountBreakdown:d,taxTotal:M,taxBreakdown:p,grandTotal:E};}updateShippingDetails(t){this.shippingDetails=t;}applyCoupons(t){let e=t.filter(a=>a.getCategory()==="SHIPPING"),i=t.filter(a=>a.getCategory()!=="SHIPPING");this.coupons=[],this.total.discountTotal=this.total.lineItemSubtotal.zero(),this.total.discountBreakdown={},i.length&&this.applyNonShippingCoupons(i),this.applyDiscountsInLineItem(this.total.discountBreakdown),e.length&&this.applyShippingCoupons(e),this.calculateTotals();}applyDiscountsInLineItem(t){let e=Array.from(Object.entries(t)).filter(a=>!a[1].isZero()),i=new Map;this.lineItems.forEach(a=>i.set(a.getId(),[])),e.forEach(([a,n])=>{let d=this.coupons.find(g=>g.getCode()===a);if(!d||n.isZero())return;let u=this.lineItems.filter(g=>g.getState()!=="CANCELLED"&&!g.getTotal().subtotal.isZero()).sort((g,c)=>g.getTotal().subtotal.compareTo(c.getTotal().subtotal)),h=new a$3({amount:0,currency:this.currency});u.forEach((g,c)=>{let m;c===u.length-1?m=n.subtract(h):m=n.multiply(g.getTotal().subtotal).divide(this.total.lineItemSubtotal).round(),h=h.add(m),i.get(g.getId())?.push({coupon:d,amount:m});});}),this.lineItems.forEach(a=>{a.getState()==="CANCELLED"||this.total.lineItemSubtotal.isZero()?a.updateDiscounts([]):a.updateDiscounts(i.get(a.getId())||[]);});}applyDiscountsInShippingCharges(t){let e=Array.from(Object.entries(t)).filter(n=>!n[1].isZero()),i=this.charges.filter(n=>n.getType()==="SHIPPING"),a=new Map;i.forEach(n=>a.set(n.getId(),[])),e.forEach(([n,d])=>{let u=this.coupons.find(c=>c.getCode()===n);if(!u||d.isZero())return;let h=i.sort((c,m)=>c.getTotal().grandTotal.compareTo(m.getTotal().grandTotal)),g=new a$3({amount:0,currency:this.currency});h.forEach((c,m)=>{let y;m===h.length-1?y=d.subtract(g):y=d.multiply(c.getTotal().chargeAmount).divide(this.total.shippingCharges).round(),g=g.add(y),a.get(c.getId())?.push({coupon:u,amount:y});});}),i.forEach(n=>{n.updateDiscounts(a.get(n.getId())||[]);});}applyNonShippingCoupons(t){let e=t.filter(i=>i.getType()==="coupon");if(e.length===1){let i=e[0].calculateApplicableCouponDiscount(this.total.lineItemSubtotal,this.total.shippingCharges,this.country,this.currency);i.getAmount()>0&&(this.coupons.push(e[0]),this.total.discountTotal=i,this.total.discountBreakdown[e[0].getCode()]=i);}}applyShippingCoupons(t){if(this.total.shippingCharges.getAmount()>0&&t.length>0){let e=this.total.lineItemSubtotal.subtract(this.total.discountTotal),i=t.reduce((n,d)=>{if(!n)return d;let u=d.calculateApplicableCouponDiscount(e,this.total.shippingCharges,this.country,this.currency).min(this.total.shippingCharges),h=n.calculateApplicableCouponDiscount(e,this.total.shippingCharges,this.country,this.currency).min(this.total.shippingCharges);return u.compareTo(h)===0?d.getType()==="coupon"?d:n:u.compareTo(h)>0?d:n}),a=i.calculateApplicableCouponDiscount(e,this.total.shippingCharges,this.country,this.currency).min(this.total.shippingCharges);a.getAmount()>0&&(this.coupons.push(i),this.total.discountTotal=this.total.discountTotal.add(a),this.total.discountBreakdown[i.getCode()]=a);}}};export{B as a};//# sourceMappingURL=chunk-3TUSUSXQ.mjs.map
2
+ //# sourceMappingURL=chunk-3TUSUSXQ.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Classes/ShoppingContainer.ts"],"names":["BaseShoppingContainerModel","BaseModel","data","date","item","LineItemModel","charge","ChargeModel","AddressModel","coupon","CouponModel","Utils_default","PriceModel","key","value","breakdown","systemKey","systemValue","subKey","subValue","totals","zero","filteredLineItems","lineitem","lineItemSubtotal","total","lineItem","shippingCharges","discountTotal","discountBreakdown","nonShippingCouponTotal","couponValue","shippingCoupon","netLineItemSubtotal","netShippingCharges","additiveCharges","netAdditiveCharges","adjustmentCharges","taxTotal","lineItemTaxTotal","additiveChargesTaxTotal","taxBreakdown","lineItemTaxBreakdown","additiveChargesTaxBreakdown","mergeTax","sourceBreakdown","targetBreakdown","ruleId","system","subsystem","lineItemTaxes","chargeTaxes","grandTotal","shippingDetails","applicableCoupons","shippingCoupons","otherCoupons","couponTotal","couponDiscounts","couponDiscount","itemDiscounts","li","code","c","validItems","a","b","distributed","index","amount","chargeDiscounts","validCharges","coupons","maxValuedCoupon","maxCoupon","currentCoupon","currentCouponValue","maxCouponValue"],"mappings":"+RAkIA,IAA8BA,CAA9B,CAAA,cAAiEC,CAAU,CAC/D,EACA,CAAA,UAAA,CACA,aACA,CAAA,WAAA,CACA,SACA,CAAA,OAAA,CACA,eACA,CAAA,eAAA,CACA,cAGA,CAAA,OAAA,CAGA,KAEA,CAAA,OAAA,CACA,QACA,CAAA,MAAA,CAQV,WAAYC,CAAAA,CAAAA,CAAuCC,GAAa,CAAA,IAAI,IAAQ,CAAA,CAC1E,KAAMD,CAAAA,CAAAA,CAAMC,GAAI,CAAA,CAChB,IAAK,CAAA,EAAA,CAAKD,CAAK,CAAA,EAAA,CACf,IAAK,CAAA,UAAA,CAAaA,CAAK,CAAA,UAAA,CACvB,IAAK,CAAA,aAAA,CAAgBA,CAAK,CAAA,aAAA,CAC1B,IAAK,CAAA,WAAA,CAAcA,CAAK,CAAA,WAAA,CACxB,IAAK,CAAA,OAAA,CAAUA,CAAK,CAAA,OAAA,CACpB,IAAK,CAAA,QAAA,CAAWA,CAAK,CAAA,QAAA,CACrB,IAAK,CAAA,MAAA,CAASA,CAAK,CAAA,MAAA,CACnB,IAAK,CAAA,SAAA,CAAA,CAAa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AAA,CAAK,QAAQ,CAAA,CAAE,GAAI,CAAA,IAAA,CAAK,KAAM,CAAA,eAAe,CACjL4C,CAAAA,CAAAA,CAAiBH,CAAU,CAAA,iCAAA,CAAkCzC,CAAqB,CAAA,IAAA,CAAK,KAAM,CAAA,eAAA,CAAiB,IAAK,CAAA,OAAA,CAAS,IAAK,CAAA,QAAQ,CAAE,CAAA,GAAA,CAAI,IAAK,CAAA,KAAA,CAAM,eAAe,CAE/K,CAAA,OAAI2C,CAAmB,CAAA,SAAA,CAAUC,CAAc,CAAA,GAAM,CAC5CF,CAAAA,CAAAA,CAAc,OAAQ,EAAA,GAAM,QAAoBA,CAAAA,CAAAA,CAAgBD,CAElEE,CAAAA,CAAAA,CAAmB,SAAUC,CAAAA,CAAc,CAAI,CAAA,CAAA,CAAIF,CAAgBD,CAAAA,CAC5E,CAAC,CAAA,CAEK3C,CAAc0C,CAAAA,CAAAA,CAAgB,iCAAkCxC,CAAAA,CAAAA,CAAqB,IAAK,CAAA,KAAA,CAAM,eAAiB,CAAA,IAAA,CAAK,OAAS,CAAA,IAAA,CAAK,QAAQ,CAAE,CAAA,GAAA,CAAI,IAAK,CAAA,KAAA,CAAM,eAAe,CAAA,CAC9KF,CAAY,CAAA,SAAA,EAAc,CAAA,CAAA,GAC5B,IAAK,CAAA,OAAA,CAAQ,IAAK0C,CAAAA,CAAe,CACjC,CAAA,IAAA,CAAK,KAAM,CAAA,aAAA,CAAgB,IAAK,CAAA,KAAA,CAAM,aAAc,CAAA,GAAA,CAAI1C,CAAW,CAAA,CACnE,IAAK,CAAA,KAAA,CAAM,iBAAkB0C,CAAAA,CAAAA,CAAgB,OAAQ,EAAC,CAAI1C,CAAAA,CAAAA,EAE9D,CACF,CACF","file":"chunk-VTBHWXR4.mjs","sourcesContent":["import BaseModel, { BaseAttributes, BaseData } from \"./Base\";\r\nimport AddressModel, { AddressData } from \"./Address\";\r\nimport LineItemModel, { LineItemData, LineItemTaxBreakdown, LineItemTaxBreakdownModel } from \"./LineItem\";\r\nimport { CountryCode, CurrencyCode, LocaleCode, ShippingDetails } from \"./Common\";\r\nimport PriceModel, { PriceData } from \"./Price\";\r\nimport CouponModel, { CouponCategory, CouponData, CouponType } from \"./Coupon\";\r\nimport Utils from \"../Utils\";\r\nimport { ChargeImpact, ChargeType, LineItemState, TaxSystem } from \"./Enum\";\r\nimport ChargeModel, { ChargeData, ChargeTaxBreakdownModel } from \"./Charge\";\r\n\r\n/**\r\n * Breakdown of a specific tax system (e.g., GST, VAT) for the entire container.\r\n * Groups taxes by system and then by specific rule/subsystem.\r\n */\r\nexport type TaxSystemBreakdown = {\r\n /** Name of the tax system (e.g., GST) */\r\n system: TaxSystem;\r\n /** Total tax amount collected for this system across all line items and charges */\r\n totalAmount: PriceData;\r\n /** Detailed breakdown by rule/subsystem to total tax amount (e.g., CGST, SGST) */\r\n subSystems: Record<string, PriceData>;\r\n};\r\n\r\n/**\r\n * Internal model for tax system breakdown using PriceModel instances.\r\n */\r\nexport type TaxSystemBreakdownModel = {\r\n system: TaxSystem;\r\n totalAmount: PriceModel;\r\n subSystems: Record<string, PriceModel>;\r\n};\r\n\r\nexport type ShoppingContainerTaxBreakdownModel = Record<string, TaxSystemBreakdownModel>;\r\n\r\n/**\r\n * Comprehensive totals for a shopping container, logically grouped by source.\r\n */\r\nexport type ShoppingContainerTotal = {\r\n // --- Item Totals ---\r\n /** Sum of all line item prices before any discounts or taxes */\r\n lineItemSubtotal: PriceData;\r\n /** Total item subtotal after item-level discounts have been applied (taxable base for items) */\r\n netLineItemSubtotal: PriceData;\r\n /** Total tax collected specifically from line items */\r\n lineItemTaxTotal: PriceData;\r\n /** Granular tax breakdown for all line items */\r\n lineItemTaxBreakdown: Record<string, TaxSystemBreakdown>;\r\n\r\n // --- Charge Totals ---\r\n /** Sum of pre-discount chargeAmount for additive charges (tax-inclusive) */\r\n additiveCharges: PriceData;\r\n /** Sum of post-discount netChargeAmount for additive charges – final payable (tax-inclusive) */\r\n netAdditiveCharges: PriceData;\r\n /** Tax reverse-calculated from additive charges only */\r\n additiveChargesTaxTotal: PriceData;\r\n /** Granular tax breakdown from additive charges */\r\n additiveChargesTaxBreakdown: Record<string, TaxSystemBreakdown>;\r\n\r\n /** Sum of post-discount netChargeAmount for subtractive charges – absolute amount to subtract */\r\n adjustmentCharges: PriceData;\r\n\r\n /** Pre-discount shipping gross (tax-inclusive, part of additive charges) */\r\n shippingCharges: PriceData;\r\n /** Shipping cost after any shipping-specific discounts */\r\n netShippingCharges: PriceData;\r\n\r\n // --- Aggregate Totals ---\r\n /** Combined total tax (lineItemTaxTotal + chargeTaxTotal) */\r\n taxTotal: PriceData;\r\n /** Combined granular tax breakdown for the entire container */\r\n taxBreakdown: Record<string, TaxSystemBreakdown>;\r\n /** Sum of all coupon discounts applied to the container */\r\n discountTotal: PriceData;\r\n /** Map of applied coupon codes to their calculated discount amounts */\r\n discountBreakdown: Record<string, PriceData>;\r\n /** Final total amount to be paid (NetSubtotal + ChargesTotal + TaxTotal - (any remaining discounts)) */\r\n grandTotal: PriceData;\r\n};\r\n\r\n/**\r\n * Internal model version of ShoppingContainerTotal using PriceModel instances.\r\n */\r\nexport type ShoppingContainerTotalModel = {\r\n lineItemSubtotal: PriceModel;\r\n netLineItemSubtotal: PriceModel;\r\n lineItemTaxTotal: PriceModel;\r\n lineItemTaxBreakdown: Record<string, TaxSystemBreakdownModel>;\r\n\r\n additiveCharges: PriceModel;\r\n netAdditiveCharges: PriceModel;\r\n additiveChargesTaxTotal: PriceModel;\r\n additiveChargesTaxBreakdown: Record<string, TaxSystemBreakdownModel>;\r\n\r\n adjustmentCharges: PriceModel;\r\n\r\n shippingCharges: PriceModel;\r\n netShippingCharges: PriceModel;\r\n\r\n taxTotal: PriceModel;\r\n taxBreakdown: Record<string, TaxSystemBreakdownModel>;\r\n discountTotal: PriceModel;\r\n discountBreakdown: Record<string, PriceModel>;\r\n grandTotal: PriceModel;\r\n};\r\n\r\n\r\nexport type BaseShoppingContainerAttributes = BaseAttributes & {\r\n id: string;\r\n customerId?: string;\r\n customerEmail?: string;\r\n anonymousId?: string;\r\n lineItems: LineItemData[];\r\n charges: ChargeData[];\r\n shippingDetails: ShippingDetails | null;\r\n shippingAddress?: AddressData | null;\r\n billingAddress?: AddressData | null;\r\n coupons: CouponData[];\r\n total: ShoppingContainerTotal;\r\n country: CountryCode;\r\n currency: CurrencyCode;\r\n locale: LocaleCode;\r\n};\r\n\r\nexport type BaseShoppingContainerData = BaseShoppingContainerAttributes & BaseData\r\n\r\n\r\n/**\r\n * Abstract base class for shopping-related containers like carts and orders.\r\n * Manages common elements such as line items, addresses, coupons, and totals.\r\n */\r\nexport default abstract class BaseShoppingContainerModel extends BaseModel {\r\n protected id: string;\r\n protected customerId?: string;\r\n protected customerEmail?: string;\r\n protected anonymousId?: string;\r\n protected lineItems: LineItemModel[];\r\n protected charges: ChargeModel[];\r\n protected shippingDetails: ShippingDetails | null;\r\n protected shippingAddress: AddressModel | null;\r\n protected billingAddress: AddressModel | null;\r\n\r\n // CouponsCodes\r\n protected coupons: CouponModel[];\r\n\r\n // Cart Totals\r\n protected total: ShoppingContainerTotalModel;\r\n\r\n protected country: CountryCode;\r\n protected currency: CurrencyCode;\r\n protected locale: LocaleCode;\r\n\r\n /**\r\n * Creates an instance of BaseShoppingContainerModel.\r\n * Initializes common properties and calculates initial base totals.\r\n * @param data - The initial attributes for the shopping container.\r\n * @param date - Optional date object for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: BaseShoppingContainerAttributes, date: Date = new Date()) {\r\n super(data, date);\r\n this.id = data.id;\r\n this.customerId = data.customerId;\r\n this.customerEmail = data.customerEmail;\r\n this.anonymousId = data.anonymousId;\r\n this.country = data.country;\r\n this.currency = data.currency;\r\n this.locale = data.locale;\r\n this.lineItems = (data.lineItems ?? []).map(item => new LineItemModel(item));\r\n this.charges = (data.charges ?? []).map(charge => new ChargeModel(charge));\r\n this.billingAddress = data.billingAddress ? new AddressModel(data.billingAddress, date) : null;\r\n this.shippingAddress = data.shippingAddress ? new AddressModel(data.shippingAddress, date) : null;\r\n this.coupons = (data.coupons ?? []).map(coupon => new CouponModel(coupon));\r\n\r\n this.shippingDetails = data.shippingDetails ? Utils.deepClone(data.shippingDetails) : null;\r\n\r\n this.total = {\r\n lineItemSubtotal: new PriceModel(data.total.lineItemSubtotal),\r\n netLineItemSubtotal: new PriceModel(data.total.netLineItemSubtotal),\r\n lineItemTaxTotal: new PriceModel(data.total.lineItemTaxTotal),\r\n lineItemTaxBreakdown: this.mapTaxBreakdown(data.total.lineItemTaxBreakdown),\r\n\r\n additiveCharges: new PriceModel(data.total.additiveCharges),\r\n netAdditiveCharges: new PriceModel(data.total.netAdditiveCharges),\r\n additiveChargesTaxTotal: new PriceModel(data.total.additiveChargesTaxTotal),\r\n\r\n additiveChargesTaxBreakdown: this.mapTaxBreakdown(data.total.additiveChargesTaxBreakdown),\r\n adjustmentCharges: new PriceModel(data.total.adjustmentCharges),\r\n shippingCharges: new PriceModel(data.total.shippingCharges),\r\n netShippingCharges: new PriceModel(data.total.netShippingCharges),\r\n\r\n discountTotal: new PriceModel(data.total.discountTotal),\r\n discountBreakdown: Object.fromEntries(\r\n Object.entries(data.total.discountBreakdown).map(([key, value]) => [key, new PriceModel(value)])\r\n ),\r\n\r\n taxTotal: new PriceModel(data.total.taxTotal),\r\n taxBreakdown: this.mapTaxBreakdown(data.total.taxBreakdown),\r\n grandTotal: new PriceModel(data.total.grandTotal),\r\n };\r\n }\r\n\r\n private mapTaxBreakdown(breakdown: Record<string, TaxSystemBreakdown>): Record<string, TaxSystemBreakdownModel> {\r\n return Object.fromEntries(\r\n Object.entries(breakdown || {}).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n system: systemValue.system,\r\n totalAmount: new PriceModel(systemValue.totalAmount),\r\n subSystems: Object.fromEntries(\r\n Object.entries(systemValue.subSystems).map(([subKey, subValue]) => [\r\n subKey,\r\n new PriceModel(subValue)\r\n ])\r\n )\r\n }\r\n ])\r\n );\r\n }\r\n\r\n private serializeTaxBreakdown(breakdown: Record<string, TaxSystemBreakdownModel>): Record<string, TaxSystemBreakdown> {\r\n return Object.fromEntries(\r\n Object.entries(breakdown || {}).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n system: systemValue.system,\r\n totalAmount: systemValue.totalAmount.getDetails(),\r\n subSystems: Object.fromEntries(\r\n Object.entries(systemValue.subSystems).map(([subKey, subValue]) => [\r\n subKey,\r\n subValue.getDetails()\r\n ])\r\n )\r\n }\r\n ])\r\n );\r\n }\r\n\r\n /**\r\n * Gets the unique identifier for this shopping container (cart ID or order ID).\r\n * @returns The ID string.\r\n */\r\n public getId(): string {\r\n return this.id;\r\n }\r\n\r\n /**\r\n * Gets the customer ID associated with this container, if available.\r\n * @returns The customer ID string, or undefined.\r\n */\r\n public getCustomerId(): string | undefined {\r\n return this.customerId;\r\n }\r\n\r\n /**\r\n * Gets the customer email associated with this container, if available.\r\n * @returns The customer email string, or undefined.\r\n */\r\n public getCustomerEmail(): string | undefined {\r\n return this.customerEmail;\r\n }\r\n\r\n /**\r\n * Gets the anonymous user ID associated with this container, if available.\r\n * @returns The anonymous ID string, or undefined.\r\n */\r\n public getAnonymousId(): string | undefined {\r\n return this.anonymousId;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the line items in the container.\r\n * Each item is a new LineItemModel instance created from the original's details.\r\n * @returns An array of LineItemModel instances.\r\n */\r\n public getLineItems(): LineItemModel[] {\r\n // Return new instances to prevent modification of internal state\r\n return this.lineItems.map(item => new LineItemModel(item.getDetails()));\r\n }\r\n\r\n /**\r\n * Gets current number of line items in the container.\r\n * @returns The count of line items.\r\n */\r\n public getLineItemsCount(): number {\r\n return this.lineItems.length;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the charges in the container.\r\n * @returns An array of ChargeModel instances.\r\n */\r\n public getCharges(): ChargeModel[] {\r\n return this.charges.map(charge => new ChargeModel(charge.getDetails()));\r\n }\r\n\r\n /**\r\n * Adds a new charge to the container and recalculates totals.\r\n * @param charge - The charge to add.\r\n */\r\n public addCharge(charge: ChargeModel): void {\r\n this.charges.push(charge);\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Clears all charges from the container and recalculates totals.\r\n */\r\n public clearCharges(): void {\r\n this.charges = [];\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Gets a copy of the shipping details associated with the container.\r\n * @returns A ShippingDetails object, or null if none are set.\r\n */\r\n public getShippingDetails(): ShippingDetails | null {\r\n return this.shippingDetails ? Utils.deepClone(this.shippingDetails) : null;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the shipping address associated with the container.\r\n * Returns a new AddressModel instance created from the original's details.\r\n * @returns An AddressModel instance, or null if no shipping address is set.\r\n */\r\n public getShippingAddress(): AddressModel | null {\r\n return this.shippingAddress ? new AddressModel(this.shippingAddress.getDetails()) : null;\r\n }\r\n\r\n /**\r\n * Checks if a shipping address is associated with this container.\r\n * @returns True if a shipping address is set, false otherwise.\r\n */\r\n public hasShippingAddress(): boolean {\r\n return !!this.shippingAddress;\r\n }\r\n\r\n /**\r\n * Checks if a billing address is associated with this container.\r\n * @returns True if a billing address is set, false otherwise.\r\n */\r\n public hasBillingAddress(): boolean {\r\n return !!this.billingAddress;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the billing address associated with the container.\r\n * Returns a new AddressModel instance created from the original's details.\r\n * @returns An AddressModel instance, or null if no billing address is set.\r\n */\r\n public getBillingAddress(): AddressModel | null {\r\n return this.billingAddress ? new AddressModel(this.billingAddress.getDetails()) : null;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the coupons applied to the container.\r\n * Each item is a new CouponModel instance created from the original's details.\r\n * @returns An array of CouponModel instances.\r\n */\r\n public getCoupons(): CouponModel[] {\r\n return [...this.coupons];\r\n }\r\n\r\n /**\r\n * Gets the country code associated with this container.\r\n * @returns The CountryCode enum value.\r\n */\r\n public getCountry(): CountryCode {\r\n return this.country;\r\n }\r\n\r\n /**\r\n * Gets the currency code associated with this container.\r\n * @returns The CurrencyCode enum value.\r\n */\r\n public getCurrency(): CurrencyCode {\r\n return this.currency;\r\n }\r\n\r\n /**\r\n * Gets the locale code associated with this container.\r\n * @returns The LocaleCode enum value.\r\n */\r\n public getLocale(): LocaleCode {\r\n return this.locale;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the calculated totals for the container.\r\n * @returns An object containing shipping, subtotal, coupon, and grand totals.\r\n */\r\n public getTotal() {\r\n return {\r\n lineItemSubtotal: this.total.lineItemSubtotal,\r\n netLineItemSubtotal: this.total.netLineItemSubtotal,\r\n lineItemTaxTotal: this.total.lineItemTaxTotal,\r\n lineItemTaxBreakdown: Object.fromEntries(\r\n Object.entries(this.total.lineItemTaxBreakdown).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n system: systemValue.system,\r\n totalAmount: systemValue.totalAmount,\r\n subSystems: { ...systemValue.subSystems }\r\n }\r\n ])\r\n ),\r\n additiveCharges: this.total.additiveCharges,\r\n netAdditiveCharges : this.total.netAdditiveCharges,\r\n additiveChargesTaxTotal: this.total.additiveChargesTaxTotal,\r\n additiveChargesTaxBreakdown: Object.fromEntries(\r\n Object.entries(this.total.additiveChargesTaxBreakdown).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n system: systemValue.system,\r\n totalAmount: systemValue.totalAmount,\r\n subSystems: { ...systemValue.subSystems }\r\n }\r\n ])\r\n ),\r\n adjustmentCharges: this.total.adjustmentCharges,\r\n shippingCharges: this.total.shippingCharges,\r\n netShippingCharges: this.total.netShippingCharges,\r\n discountBreakdown: { ...this.total.discountBreakdown },\r\n discountTotal: this.total.discountTotal,\r\n taxTotal: this.total.taxTotal,\r\n taxBreakdown: Object.fromEntries(\r\n Object.entries(this.total.taxBreakdown).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n system: systemValue.system,\r\n totalAmount: systemValue.totalAmount,\r\n subSystems: { ...systemValue.subSystems }\r\n }\r\n ])\r\n ),\r\n grandTotal: this.total.grandTotal,\r\n };\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the shopping container's current state.\r\n * Includes details from the base model and specific container properties.\r\n * @returns BaseShoppingContainerData object suitable for serialization or API responses.\r\n */\r\n getDetails(): BaseShoppingContainerData {\r\n const totals = this.getTotal();\r\n return {\r\n ...super.getDetails(),\r\n id: this.getId(),\r\n customerId: this.getCustomerId(),\r\n customerEmail: this.getCustomerEmail(),\r\n anonymousId: this.getAnonymousId(),\r\n lineItems: this.getLineItems().map(item => item.getDetails()),\r\n charges: this.getCharges().map(charge => charge.getDetails()),\r\n shippingDetails: this.getShippingDetails(),\r\n shippingAddress: this.getShippingAddress()?.getDetails() || null,\r\n billingAddress: this.getBillingAddress()?.getDetails() || null,\r\n coupons: this.getCoupons().map(coupon => coupon.getDetails()),\r\n total: {\r\n // Item Totals\r\n lineItemSubtotal: totals.lineItemSubtotal.getDetails(),\r\n netLineItemSubtotal: totals.netLineItemSubtotal.getDetails(),\r\n lineItemTaxTotal: totals.lineItemTaxTotal.getDetails(),\r\n lineItemTaxBreakdown: this.serializeTaxBreakdown(totals.lineItemTaxBreakdown),\r\n\r\n // Charge Totals\r\n additiveCharges: totals.additiveCharges.getDetails(),\r\n netAdditiveCharges: totals.netAdditiveCharges.getDetails(),\r\n additiveChargesTaxTotal: totals.additiveChargesTaxTotal.getDetails(),\r\n additiveChargesTaxBreakdown: this.serializeTaxBreakdown(totals.additiveChargesTaxBreakdown),\r\n\r\n adjustmentCharges: totals.adjustmentCharges.getDetails(),\r\n\r\n shippingCharges: totals.shippingCharges.getDetails(),\r\n netShippingCharges: totals.netShippingCharges.getDetails(),\r\n\r\n // Aggregate Totals\r\n discountTotal: totals.discountTotal.getDetails(),\r\n discountBreakdown: Object.fromEntries(\r\n Object.entries(totals.discountBreakdown).map(([key, value]) => [key, value.getDetails()])\r\n ),\r\n taxTotal: totals.taxTotal.getDetails(),\r\n taxBreakdown: this.serializeTaxBreakdown(totals.taxBreakdown),\r\n grandTotal: totals.grandTotal.getDetails(),\r\n },\r\n country: this.getCountry(),\r\n currency: this.getCurrency(),\r\n locale: this.getLocale(),\r\n };\r\n }\r\n\r\n /**\r\n * Recalculates the total costs for the shopping container.\r\n * This includes summing line items, calculating shipping, applying coupons, and computing taxes.\r\n */\r\n public calculateTotals(): void {\r\n const zero = new PriceModel({ amount: 0, currency: this.currency });\r\n \r\n // 1. Calculate LineItem subtotals and Shipping Cost\r\n const filteredLineItems = this.lineItems.filter(lineitem => lineitem.getState() !== LineItemState.CANCELLED);\r\n const lineItemSubtotal = filteredLineItems.reduce((total, lineItem) => total.add(lineItem.getTotal().subtotal), zero);\r\n const shippingCharges = this.charges\r\n .filter(charge => charge.getType() === ChargeType.SHIPPING)\r\n .reduce((total, charge) => total.add(charge.getTotal().chargeAmount), zero);\r\n\r\n // 1.1 Assign lineitemSubTotal and shipping charges to total, which will be used for coupon calculations\r\n this.total.lineItemSubtotal = lineItemSubtotal;\r\n this.total.shippingCharges = shippingCharges;\r\n\r\n // 2. Calculate coupon values based on gross subtotal & shipping\r\n let discountTotal = zero;\r\n let discountBreakdown: Record<string, PriceModel> = {};\r\n let nonShippingCouponTotal: Record<string, PriceModel> = {};\r\n this.coupons.forEach(coupon => {\r\n const couponValue = coupon.calculateApplicableCouponDiscount(lineItemSubtotal, shippingCharges, this.country, this.currency);\r\n discountTotal = discountTotal.add(couponValue);\r\n discountBreakdown[coupon.getCode()] = couponValue;\r\n if (coupon.getCategory() !== CouponCategory.SHIPPING) {\r\n nonShippingCouponTotal[coupon.getCode()] = couponValue;\r\n }\r\n })\r\n\r\n // 2.1. Assign discount total and breakdown to total\r\n this.total.discountTotal = discountTotal;\r\n this.total.discountBreakdown = discountBreakdown;\r\n\r\n // 3. Apply discounts at lineitem and shipping charges\r\n this.applyDiscountsInLineItem(nonShippingCouponTotal);\r\n\r\n const shippingCoupon = this.coupons.find(coupon => coupon.getCategory() === CouponCategory.SHIPPING);\r\n if(shippingCoupon) {\r\n this.applyDiscountsInShippingCharges({[shippingCoupon.getCode()] : discountBreakdown[shippingCoupon.getCode()] || zero});\r\n } else {\r\n // If no shipping coupon, ensure any previous discounts on shipping charges are cleared\r\n this.applyDiscountsInShippingCharges({});\r\n }\r\n\r\n // 3.1 Calculate net lineitemSubtotal and net shipping after discount\r\n const netLineItemSubtotal = this.lineItems.reduce((total, lineItem) => total.add(lineItem.getTotal().netSubtotal), zero);\r\n const netShippingCharges = this.charges\r\n .filter(charge => charge.getType() === ChargeType.SHIPPING)\r\n .reduce((total, charge) => total.add(charge.getTotal().grandTotal), zero);\r\n\r\n // 3.2 Assign net lineitemSubtotal and net shipping to total\r\n this.total.netLineItemSubtotal = netLineItemSubtotal;\r\n this.total.netShippingCharges = netShippingCharges;\r\n\r\n // 4. Calculate charges and net charges after discount\r\n const additiveCharges = this.charges\r\n .filter(charge => charge.getImpact() === ChargeImpact.ADD)\r\n .reduce((total, charge) => total.add(charge.getTotal().chargeAmount), zero);\r\n const netAdditiveCharges = this.charges\r\n .filter(charge => charge.getImpact() === ChargeImpact.ADD)\r\n .reduce((total, charge) => total.add(charge.getTotal().grandTotal), zero);\r\n const adjustmentCharges = this.charges\r\n .filter(charge => charge.getImpact() === ChargeImpact.SUBTRACT)\r\n .reduce((total, charge) => total.add(charge.getTotal().grandTotal), zero);\r\n\r\n // 5. Aggregate Taxes & Grand Total from all items and charges\r\n let taxTotal = zero;\r\n let lineItemTaxTotal = zero;\r\n let additiveChargesTaxTotal = zero;\r\n\r\n const taxBreakdown: ShoppingContainerTaxBreakdownModel = {};\r\n const lineItemTaxBreakdown: ShoppingContainerTaxBreakdownModel = {};\r\n const additiveChargesTaxBreakdown: ShoppingContainerTaxBreakdownModel = {};\r\n\r\n // Helper to merge tax breakdowns into hierarchical structure\r\n const mergeTax = (\r\n sourceBreakdown: Record<string, LineItemTaxBreakdownModel | ChargeTaxBreakdownModel>,\r\n targetBreakdown: ShoppingContainerTaxBreakdownModel\r\n ) => {\r\n Object.entries(sourceBreakdown).forEach(([ruleId, breakdown]) => {\r\n const system = breakdown.system;\r\n const subsystem = breakdown.subSystem;\r\n\r\n // Populate Target Breakdown\r\n if (!targetBreakdown[system]) {\r\n targetBreakdown[system] = { system, totalAmount: zero, subSystems: {} };\r\n }\r\n if (!targetBreakdown[system].subSystems[subsystem]) {\r\n targetBreakdown[system].subSystems[subsystem] = breakdown.taxAmount;\r\n } else {\r\n targetBreakdown[system].subSystems[subsystem] = targetBreakdown[system].subSystems[subsystem].add(breakdown.taxAmount);\r\n }\r\n targetBreakdown[system].totalAmount = targetBreakdown[system].totalAmount.add(breakdown.taxAmount);\r\n\r\n // Populate Combined taxBreakdown\r\n if (!taxBreakdown[system]) {\r\n taxBreakdown[system] = { system, totalAmount: zero, subSystems: {} };\r\n }\r\n if (!taxBreakdown[system].subSystems[subsystem]) {\r\n taxBreakdown[system].subSystems[subsystem] = breakdown.taxAmount;\r\n } else {\r\n taxBreakdown[system].subSystems[subsystem] = taxBreakdown[system].subSystems[subsystem].add(breakdown.taxAmount);\r\n }\r\n taxBreakdown[system].totalAmount = taxBreakdown[system].totalAmount.add(breakdown.taxAmount);\r\n });\r\n };\r\n\r\n // 5.1 Merge line item taxes\r\n filteredLineItems.forEach(lineItem => {\r\n const lineItemTaxes = lineItem.getTotal().taxBreakdown;\r\n if (lineItemTaxes) {\r\n mergeTax(lineItemTaxes, lineItemTaxBreakdown);\r\n mergeTax(lineItemTaxes, taxBreakdown);\r\n lineItemTaxTotal = lineItemTaxTotal.add(lineItem.getTotal().taxTotal);\r\n }\r\n });\r\n\r\n // 5.2 Merge charge taxes\r\n this.charges.forEach(charge => {\r\n const chargeTaxes = charge.getTotal().taxBreakdown;\r\n if (chargeTaxes) {\r\n mergeTax(chargeTaxes, additiveChargesTaxBreakdown);\r\n mergeTax(chargeTaxes, taxBreakdown);\r\n additiveChargesTaxTotal = additiveChargesTaxTotal.add(charge.getTotal().taxTotal);\r\n }\r\n });\r\n\r\n // 5.3 Calculate total tax\r\n taxTotal = lineItemTaxTotal.add(additiveChargesTaxTotal);\r\n\r\n // 6. Final Grand Total: netLineItemSubtotal + lineItemTaxTotal + netAdditiveCharges (includes netShippingCharges) - adjustmentCharges\r\n const grandTotal = netLineItemSubtotal.add(lineItemTaxTotal).add(netAdditiveCharges).subtract(adjustmentCharges);\r\n\r\n\r\n // 7. Reconstruct total object\r\n this.total = {\r\n lineItemSubtotal: lineItemSubtotal,\r\n netLineItemSubtotal: netLineItemSubtotal,\r\n lineItemTaxTotal: lineItemTaxTotal,\r\n lineItemTaxBreakdown: lineItemTaxBreakdown,\r\n\r\n additiveCharges: additiveCharges,\r\n netAdditiveCharges: netAdditiveCharges,\r\n additiveChargesTaxTotal: additiveChargesTaxTotal,\r\n additiveChargesTaxBreakdown: additiveChargesTaxBreakdown,\r\n\r\n adjustmentCharges: adjustmentCharges,\r\n shippingCharges: shippingCharges,\r\n netShippingCharges: netShippingCharges,\r\n\r\n discountTotal: discountTotal,\r\n discountBreakdown: discountBreakdown,\r\n taxTotal: taxTotal,\r\n taxBreakdown: taxBreakdown,\r\n grandTotal: grandTotal,\r\n };\r\n }\r\n\r\n /**\r\n * Updates the shipping details and recalculates the totals.\r\n * @param shippingDetails - The new shipping details to apply.\r\n */\r\n public updateShippingDetails(shippingDetails: ShippingDetails): void {\r\n this.shippingDetails = shippingDetails;\r\n }\r\n\r\n /**\r\n * Applies a list of coupons to the shopping container.\r\n * Filters out invalid coupons, separates shipping and non-shipping coupons,\r\n * and distributes discounts to line items.\r\n * @param applicableCoupons - The list of coupons to attempt to apply.\r\n */\r\n public applyCoupons(applicableCoupons: CouponModel[]): void {\r\n //Apply coupons\r\n const shippingCoupons = applicableCoupons.filter(coupon => coupon.getCategory() === CouponCategory.SHIPPING);\r\n const otherCoupons = applicableCoupons.filter(coupon => coupon.getCategory() !== CouponCategory.SHIPPING);\r\n\r\n this.coupons = [];\r\n this.total.discountTotal = this.total.lineItemSubtotal.zero();\r\n this.total.discountBreakdown = {};\r\n // Apply non shipping coupons\r\n otherCoupons.length && this.applyNonShippingCoupons(otherCoupons);\r\n this.applyDiscountsInLineItem(this.total.discountBreakdown);\r\n\r\n // Apply shipping coupons\r\n shippingCoupons.length && this.applyShippingCoupons(shippingCoupons);\r\n\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Distributes the total discount amount among the line items.\r\n * @param couponTotal - A record of coupon codes and their calculated discount amounts.\r\n */\r\n private applyDiscountsInLineItem(couponTotal: Record<string, PriceModel>) {\r\n const couponDiscounts: [string, PriceModel][] = Array.from(Object.entries(couponTotal))\r\n .filter(couponDiscount => !couponDiscount[1].isZero());\r\n\r\n const itemDiscounts = new Map<string, { coupon: CouponModel, amount: PriceModel }[]>();\r\n this.lineItems.forEach(li => itemDiscounts.set(li.getId(), []));\r\n\r\n couponDiscounts.forEach(([code, discountTotal]) => {\r\n const coupon = this.coupons.find(c => c.getCode() === code);\r\n if (!coupon || discountTotal.isZero()) return;\r\n\r\n const validItems = this.lineItems\r\n .filter(li => li.getState() !== LineItemState.CANCELLED && !li.getTotal().subtotal.isZero())\r\n .sort((a, b) => a.getTotal().subtotal.compareTo(b.getTotal().subtotal));\r\n\r\n let distributed = new PriceModel({ amount: 0, currency: this.currency });\r\n\r\n validItems.forEach((item, index) => {\r\n let amount: PriceModel;\r\n if (index === validItems.length - 1) {\r\n amount = discountTotal.subtract(distributed);\r\n } else {\r\n amount = discountTotal.multiply(item.getTotal().subtotal).divide(this.total.lineItemSubtotal).round();\r\n }\r\n distributed = distributed.add(amount);\r\n itemDiscounts.get(item.getId())?.push({ coupon, amount });\r\n });\r\n });\r\n\r\n this.lineItems.forEach(lineItem => {\r\n if (lineItem.getState() === LineItemState.CANCELLED || this.total.lineItemSubtotal.isZero()) {\r\n lineItem.updateDiscounts([]);\r\n } else {\r\n lineItem.updateDiscounts(itemDiscounts.get(lineItem.getId()) || []);\r\n }\r\n });\r\n }\r\n\r\n private applyDiscountsInShippingCharges(couponTotal: Record<string, PriceModel>) {\r\n const couponDiscounts: [string, PriceModel][] = Array.from(Object.entries(couponTotal))\r\n .filter(couponDiscount => !couponDiscount[1].isZero());\r\n const shippingCharges = this.charges.filter(charge => charge.getType() === ChargeType.SHIPPING);\r\n\r\n const chargeDiscounts = new Map<string, { coupon: CouponModel, amount: PriceModel }[]>();\r\n shippingCharges.forEach(li => chargeDiscounts.set(li.getId(), []));\r\n\r\n couponDiscounts.forEach(([code, discountTotal]) => {\r\n const coupon = this.coupons.find(c => c.getCode() === code);\r\n if (!coupon || discountTotal.isZero()) return;\r\n\r\n const validCharges = shippingCharges\r\n .sort((a, b) => a.getTotal().grandTotal.compareTo(b.getTotal().grandTotal));\r\n\r\n let distributed = new PriceModel({ amount: 0, currency: this.currency });\r\n\r\n validCharges.forEach((charge, index) => {\r\n let amount: PriceModel;\r\n if (index === validCharges.length - 1) {\r\n amount = discountTotal.subtract(distributed);\r\n } else {\r\n amount = discountTotal.multiply(charge.getTotal().chargeAmount).divide(this.total.shippingCharges).round();\r\n }\r\n distributed = distributed.add(amount);\r\n chargeDiscounts.get(charge.getId())?.push({ coupon, amount });\r\n });\r\n });\r\n\r\n shippingCharges.forEach(charge => {\r\n charge.updateDiscounts(chargeDiscounts.get(charge.getId()) || []);\r\n });\r\n }\r\n\r\n /**\r\n * Selects and applies the best applicable non-shipping coupon.\r\n * Currently supports applying only a single coupon of type COUPON.\r\n * @param applicableCoupons - List of available non-shipping coupons.\r\n */\r\n private applyNonShippingCoupons(applicableCoupons: CouponModel[]) {\r\n const coupons = applicableCoupons.filter(coupon => coupon.getType() === CouponType.COUPON);\r\n if (coupons.length === 1) {\r\n const couponValue = coupons[0].calculateApplicableCouponDiscount(this.total.lineItemSubtotal, this.total.shippingCharges, this.country, this.currency);\r\n if (couponValue.getAmount() > 0) {\r\n this.coupons.push(coupons[0]);\r\n this.total.discountTotal = couponValue;\r\n this.total.discountBreakdown[coupons[0].getCode()] = couponValue;\r\n }\r\n }\r\n // Todo: Add support to other type in future like promotion\r\n }\r\n\r\n /**\r\n * Selects and applies the best applicable shipping coupon.\r\n * @param applicableCoupons - List of available shipping coupons.\r\n */\r\n private applyShippingCoupons(applicableCoupons: CouponModel[]) {\r\n if (this.total.shippingCharges.getAmount() > 0 && applicableCoupons.length > 0) {\r\n const netLineItemSubtotal = this.total.lineItemSubtotal.subtract(this.total.discountTotal);\r\n\r\n const maxValuedCoupon = applicableCoupons.reduce((maxCoupon, currentCoupon) => {\r\n if (!maxCoupon) return currentCoupon;\r\n\r\n const currentCouponValue = currentCoupon.calculateApplicableCouponDiscount(netLineItemSubtotal, this.total.shippingCharges, this.country, this.currency).min(this.total.shippingCharges);\r\n const maxCouponValue = maxCoupon.calculateApplicableCouponDiscount(netLineItemSubtotal, this.total.shippingCharges, this.country, this.currency).min(this.total.shippingCharges);\r\n\r\n if (currentCouponValue.compareTo(maxCouponValue) === 0) {\r\n return currentCoupon.getType() === CouponType.COUPON ? currentCoupon : maxCoupon;\r\n }\r\n return currentCouponValue.compareTo(maxCouponValue) > 0 ? currentCoupon : maxCoupon;\r\n });\r\n\r\n const couponValue = maxValuedCoupon.calculateApplicableCouponDiscount(netLineItemSubtotal, this.total.shippingCharges, this.country, this.currency).min(this.total.shippingCharges);\r\n if (couponValue.getAmount() > 0) {\r\n this.coupons.push(maxValuedCoupon);\r\n this.total.discountTotal = this.total.discountTotal.add(couponValue);\r\n this.total.discountBreakdown[maxValuedCoupon.getCode()] = couponValue;\r\n }\r\n }\r\n }\r\n}\r\n\r\n\r\n"]}
1
+ {"version":3,"sources":["../src/Classes/ShoppingContainer.ts"],"names":["BaseShoppingContainerModel","BaseModel","data","date","item","LineItemModel","charge","ChargeModel","AddressModel","coupon","CouponModel","Utils_default","PriceModel","key","value","breakdown","systemKey","systemValue","subKey","subValue","totals","zero","filteredLineItems","lineitem","lineItemSubtotal","total","lineItem","shippingCharges","discountTotal","discountBreakdown","nonShippingCouponTotal","couponValue","shippingCoupon","netLineItemSubtotal","netShippingCharges","additiveCharges","netAdditiveCharges","adjustmentCharges","taxTotal","lineItemTaxTotal","additiveChargesTaxTotal","taxBreakdown","lineItemTaxBreakdown","additiveChargesTaxBreakdown","mergeTax","sourceBreakdown","targetBreakdown","ruleId","system","subsystem","lineItemTaxes","chargeTaxes","grandTotal","shippingDetails","applicableCoupons","shippingCoupons","otherCoupons","couponTotal","couponDiscounts","couponDiscount","itemDiscounts","li","code","c","validItems","a","b","distributed","index","amount","chargeDiscounts","validCharges","coupons","maxValuedCoupon","maxCoupon","currentCoupon","currentCouponValue","maxCouponValue"],"mappings":"+RAkIA,IAA8BA,CAA9B,CAAA,cAAiEC,CAAU,CAC/D,EACA,CAAA,UAAA,CACA,aACA,CAAA,WAAA,CACA,SACA,CAAA,OAAA,CACA,eACA,CAAA,eAAA,CACA,cAGA,CAAA,OAAA,CAGA,KAEA,CAAA,OAAA,CACA,QACA,CAAA,MAAA,CAQV,WAAYC,CAAAA,CAAAA,CAAuCC,GAAa,CAAA,IAAI,IAAQ,CAAA,CAC1E,KAAMD,CAAAA,CAAAA,CAAMC,GAAI,CAAA,CAChB,IAAK,CAAA,EAAA,CAAKD,CAAK,CAAA,EAAA,CACf,IAAK,CAAA,UAAA,CAAaA,CAAK,CAAA,UAAA,CACvB,IAAK,CAAA,aAAA,CAAgBA,CAAK,CAAA,aAAA,CAC1B,IAAK,CAAA,WAAA,CAAcA,CAAK,CAAA,WAAA,CACxB,IAAK,CAAA,OAAA,CAAUA,CAAK,CAAA,OAAA,CACpB,IAAK,CAAA,QAAA,CAAWA,CAAK,CAAA,QAAA,CACrB,IAAK,CAAA,MAAA,CAASA,CAAK,CAAA,MAAA,CACnB,IAAK,CAAA,SAAA,CAAA,CAAaA,CAAK,CAAA,SAAA,EAAa,EAAI,EAAA,GAAA,CAAIE,CAAQ,EAAA,IAAIC,CAAcD,CAAAA,CAAI,CAAC,CAAA,CAC3E,IAAK,CAAA,OAAA,CAAA,CAAWF,CAAK,CAAA,OAAA,EAAW,EAAC,EAAG,GAAII,CAAAA,CAAAA,EAAU,I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IAAK,CAAA,QAAQ,CAAE,CAAA,GAAA,CAAI,IAAK,CAAA,KAAA,CAAM,eAAe,CAE/K,CAAA,OAAI2C,CAAmB,CAAA,SAAA,CAAUC,CAAc,CAAA,GAAM,CAC5CF,CAAAA,CAAAA,CAAc,OAAQ,EAAA,GAAM,QAAoBA,CAAAA,CAAAA,CAAgBD,CAElEE,CAAAA,CAAAA,CAAmB,SAAUC,CAAAA,CAAc,CAAI,CAAA,CAAA,CAAIF,CAAgBD,CAAAA,CAC5E,CAAC,CAAA,CAEK3C,CAAc0C,CAAAA,CAAAA,CAAgB,iCAAkCxC,CAAAA,CAAAA,CAAqB,IAAK,CAAA,KAAA,CAAM,eAAiB,CAAA,IAAA,CAAK,OAAS,CAAA,IAAA,CAAK,QAAQ,CAAE,CAAA,GAAA,CAAI,IAAK,CAAA,KAAA,CAAM,eAAe,CAAA,CAC9KF,CAAY,CAAA,SAAA,EAAc,CAAA,CAAA,GAC5B,IAAK,CAAA,OAAA,CAAQ,IAAK0C,CAAAA,CAAe,CACjC,CAAA,IAAA,CAAK,KAAM,CAAA,aAAA,CAAgB,IAAK,CAAA,KAAA,CAAM,aAAc,CAAA,GAAA,CAAI1C,CAAW,CAAA,CACnE,IAAK,CAAA,KAAA,CAAM,iBAAkB0C,CAAAA,CAAAA,CAAgB,OAAQ,EAAC,CAAI1C,CAAAA,CAAAA,EAE9D,CACF,CACF","file":"chunk-3TUSUSXQ.mjs","sourcesContent":["import BaseModel, { BaseAttributes, BaseData } from \"./Base\";\r\nimport AddressModel, { AddressData } from \"./Address\";\r\nimport LineItemModel, { LineItemData, LineItemTaxBreakdown, LineItemTaxBreakdownModel } from \"./LineItem\";\r\nimport { CountryCode, CurrencyCode, LocaleCode, ShippingDetails } from \"./Common\";\r\nimport PriceModel, { PriceData } from \"./Price\";\r\nimport CouponModel, { CouponCategory, CouponData, CouponType } from \"./Coupon\";\r\nimport Utils from \"../Utils\";\r\nimport { ChargeImpact, ChargeType, LineItemState, TaxSystem } from \"./Enum\";\r\nimport ChargeModel, { ChargeData, ChargeTaxBreakdownModel } from \"./Charge\";\r\n\r\n/**\r\n * Breakdown of a specific tax system (e.g., GST, VAT) for the entire container.\r\n * Groups taxes by system and then by specific rule/subsystem.\r\n */\r\nexport type TaxSystemBreakdown = {\r\n /** Name of the tax system (e.g., GST) */\r\n system: TaxSystem;\r\n /** Total tax amount collected for this system across all line items and charges */\r\n totalAmount: PriceData;\r\n /** Detailed breakdown by rule/subsystem to total tax amount (e.g., CGST, SGST) */\r\n subSystems: Record<string, PriceData>;\r\n};\r\n\r\n/**\r\n * Internal model for tax system breakdown using PriceModel instances.\r\n */\r\nexport type TaxSystemBreakdownModel = {\r\n system: TaxSystem;\r\n totalAmount: PriceModel;\r\n subSystems: Record<string, PriceModel>;\r\n};\r\n\r\nexport type ShoppingContainerTaxBreakdownModel = Record<string, TaxSystemBreakdownModel>;\r\n\r\n/**\r\n * Comprehensive totals for a shopping container, logically grouped by source.\r\n */\r\nexport type ShoppingContainerTotal = {\r\n // --- Item Totals ---\r\n /** Sum of all line item prices before any discounts or taxes */\r\n lineItemSubtotal: PriceData;\r\n /** Total item subtotal after item-level discounts have been applied (taxable base for items) */\r\n netLineItemSubtotal: PriceData;\r\n /** Total tax collected specifically from line items */\r\n lineItemTaxTotal: PriceData;\r\n /** Granular tax breakdown for all line items */\r\n lineItemTaxBreakdown: Record<string, TaxSystemBreakdown>;\r\n\r\n // --- Charge Totals ---\r\n /** Sum of pre-discount chargeAmount for additive charges (tax-inclusive) */\r\n additiveCharges: PriceData;\r\n /** Sum of post-discount netChargeAmount for additive charges – final payable (tax-inclusive) */\r\n netAdditiveCharges: PriceData;\r\n /** Tax reverse-calculated from additive charges only */\r\n additiveChargesTaxTotal: PriceData;\r\n /** Granular tax breakdown from additive charges */\r\n additiveChargesTaxBreakdown: Record<string, TaxSystemBreakdown>;\r\n\r\n /** Sum of post-discount netChargeAmount for subtractive charges – absolute amount to subtract */\r\n adjustmentCharges: PriceData;\r\n\r\n /** Pre-discount shipping gross (tax-inclusive, part of additive charges) */\r\n shippingCharges: PriceData;\r\n /** Shipping cost after any shipping-specific discounts */\r\n netShippingCharges: PriceData;\r\n\r\n // --- Aggregate Totals ---\r\n /** Combined total tax (lineItemTaxTotal + chargeTaxTotal) */\r\n taxTotal: PriceData;\r\n /** Combined granular tax breakdown for the entire container */\r\n taxBreakdown: Record<string, TaxSystemBreakdown>;\r\n /** Sum of all coupon discounts applied to the container */\r\n discountTotal: PriceData;\r\n /** Map of applied coupon codes to their calculated discount amounts */\r\n discountBreakdown: Record<string, PriceData>;\r\n /** Final total amount to be paid (NetSubtotal + ChargesTotal + TaxTotal - (any remaining discounts)) */\r\n grandTotal: PriceData;\r\n};\r\n\r\n/**\r\n * Internal model version of ShoppingContainerTotal using PriceModel instances.\r\n */\r\nexport type ShoppingContainerTotalModel = {\r\n lineItemSubtotal: PriceModel;\r\n netLineItemSubtotal: PriceModel;\r\n lineItemTaxTotal: PriceModel;\r\n lineItemTaxBreakdown: Record<string, TaxSystemBreakdownModel>;\r\n\r\n additiveCharges: PriceModel;\r\n netAdditiveCharges: PriceModel;\r\n additiveChargesTaxTotal: PriceModel;\r\n additiveChargesTaxBreakdown: Record<string, TaxSystemBreakdownModel>;\r\n\r\n adjustmentCharges: PriceModel;\r\n\r\n shippingCharges: PriceModel;\r\n netShippingCharges: PriceModel;\r\n\r\n taxTotal: PriceModel;\r\n taxBreakdown: Record<string, TaxSystemBreakdownModel>;\r\n discountTotal: PriceModel;\r\n discountBreakdown: Record<string, PriceModel>;\r\n grandTotal: PriceModel;\r\n};\r\n\r\n\r\nexport type BaseShoppingContainerAttributes = BaseAttributes & {\r\n id: string;\r\n customerId?: string;\r\n customerEmail?: string;\r\n anonymousId?: string;\r\n lineItems: LineItemData[];\r\n charges: ChargeData[];\r\n shippingDetails: ShippingDetails | null;\r\n shippingAddress?: AddressData | null;\r\n billingAddress?: AddressData | null;\r\n coupons: CouponData[];\r\n total: ShoppingContainerTotal;\r\n country: CountryCode;\r\n currency: CurrencyCode;\r\n locale: LocaleCode;\r\n};\r\n\r\nexport type BaseShoppingContainerData = BaseShoppingContainerAttributes & BaseData\r\n\r\n\r\n/**\r\n * Abstract base class for shopping-related containers like carts and orders.\r\n * Manages common elements such as line items, addresses, coupons, and totals.\r\n */\r\nexport default abstract class BaseShoppingContainerModel extends BaseModel {\r\n protected id: string;\r\n protected customerId?: string;\r\n protected customerEmail?: string;\r\n protected anonymousId?: string;\r\n protected lineItems: LineItemModel[];\r\n protected charges: ChargeModel[];\r\n protected shippingDetails: ShippingDetails | null;\r\n protected shippingAddress: AddressModel | null;\r\n protected billingAddress: AddressModel | null;\r\n\r\n // CouponsCodes\r\n protected coupons: CouponModel[];\r\n\r\n // Cart Totals\r\n protected total: ShoppingContainerTotalModel;\r\n\r\n protected country: CountryCode;\r\n protected currency: CurrencyCode;\r\n protected locale: LocaleCode;\r\n\r\n /**\r\n * Creates an instance of BaseShoppingContainerModel.\r\n * Initializes common properties and calculates initial base totals.\r\n * @param data - The initial attributes for the shopping container.\r\n * @param date - Optional date object for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: BaseShoppingContainerAttributes, date: Date = new Date()) {\r\n super(data, date);\r\n this.id = data.id;\r\n this.customerId = data.customerId;\r\n this.customerEmail = data.customerEmail;\r\n this.anonymousId = data.anonymousId;\r\n this.country = data.country;\r\n this.currency = data.currency;\r\n this.locale = data.locale;\r\n this.lineItems = (data.lineItems ?? []).map(item => new LineItemModel(item));\r\n this.charges = (data.charges ?? []).map(charge => new ChargeModel(charge));\r\n this.billingAddress = data.billingAddress ? new AddressModel(data.billingAddress, date) : null;\r\n this.shippingAddress = data.shippingAddress ? new AddressModel(data.shippingAddress, date) : null;\r\n this.coupons = (data.coupons ?? []).map(coupon => new CouponModel(coupon));\r\n\r\n this.shippingDetails = data.shippingDetails ? Utils.deepClone(data.shippingDetails) : null;\r\n\r\n this.total = {\r\n lineItemSubtotal: new PriceModel(data.total.lineItemSubtotal),\r\n netLineItemSubtotal: new PriceModel(data.total.netLineItemSubtotal),\r\n lineItemTaxTotal: new PriceModel(data.total.lineItemTaxTotal),\r\n lineItemTaxBreakdown: this.mapTaxBreakdown(data.total.lineItemTaxBreakdown),\r\n\r\n additiveCharges: new PriceModel(data.total.additiveCharges),\r\n netAdditiveCharges: new PriceModel(data.total.netAdditiveCharges),\r\n additiveChargesTaxTotal: new PriceModel(data.total.additiveChargesTaxTotal),\r\n\r\n additiveChargesTaxBreakdown: this.mapTaxBreakdown(data.total.additiveChargesTaxBreakdown),\r\n adjustmentCharges: new PriceModel(data.total.adjustmentCharges),\r\n shippingCharges: new PriceModel(data.total.shippingCharges),\r\n netShippingCharges: new PriceModel(data.total.netShippingCharges),\r\n\r\n discountTotal: new PriceModel(data.total.discountTotal),\r\n discountBreakdown: Object.fromEntries(\r\n Object.entries(data.total.discountBreakdown).map(([key, value]) => [key, new PriceModel(value)])\r\n ),\r\n\r\n taxTotal: new PriceModel(data.total.taxTotal),\r\n taxBreakdown: this.mapTaxBreakdown(data.total.taxBreakdown),\r\n grandTotal: new PriceModel(data.total.grandTotal),\r\n };\r\n }\r\n\r\n private mapTaxBreakdown(breakdown: Record<string, TaxSystemBreakdown>): Record<string, TaxSystemBreakdownModel> {\r\n return Object.fromEntries(\r\n Object.entries(breakdown || {}).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n system: systemValue.system,\r\n totalAmount: new PriceModel(systemValue.totalAmount),\r\n subSystems: Object.fromEntries(\r\n Object.entries(systemValue.subSystems).map(([subKey, subValue]) => [\r\n subKey,\r\n new PriceModel(subValue)\r\n ])\r\n )\r\n }\r\n ])\r\n );\r\n }\r\n\r\n private serializeTaxBreakdown(breakdown: Record<string, TaxSystemBreakdownModel>): Record<string, TaxSystemBreakdown> {\r\n return Object.fromEntries(\r\n Object.entries(breakdown || {}).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n system: systemValue.system,\r\n totalAmount: systemValue.totalAmount.getDetails(),\r\n subSystems: Object.fromEntries(\r\n Object.entries(systemValue.subSystems).map(([subKey, subValue]) => [\r\n subKey,\r\n subValue.getDetails()\r\n ])\r\n )\r\n }\r\n ])\r\n );\r\n }\r\n\r\n /**\r\n * Gets the unique identifier for this shopping container (cart ID or order ID).\r\n * @returns The ID string.\r\n */\r\n public getId(): string {\r\n return this.id;\r\n }\r\n\r\n /**\r\n * Gets the customer ID associated with this container, if available.\r\n * @returns The customer ID string, or undefined.\r\n */\r\n public getCustomerId(): string | undefined {\r\n return this.customerId;\r\n }\r\n\r\n /**\r\n * Gets the customer email associated with this container, if available.\r\n * @returns The customer email string, or undefined.\r\n */\r\n public getCustomerEmail(): string | undefined {\r\n return this.customerEmail;\r\n }\r\n\r\n /**\r\n * Gets the anonymous user ID associated with this container, if available.\r\n * @returns The anonymous ID string, or undefined.\r\n */\r\n public getAnonymousId(): string | undefined {\r\n return this.anonymousId;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the line items in the container.\r\n * Each item is a new LineItemModel instance created from the original's details.\r\n * @returns An array of LineItemModel instances.\r\n */\r\n public getLineItems(): LineItemModel[] {\r\n // Return new instances to prevent modification of internal state\r\n return this.lineItems.map(item => new LineItemModel(item.getDetails()));\r\n }\r\n\r\n /**\r\n * Gets current number of line items in the container.\r\n * @returns The count of line items.\r\n */\r\n public getLineItemsCount(): number {\r\n return this.lineItems.length;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the charges in the container.\r\n * @returns An array of ChargeModel instances.\r\n */\r\n public getCharges(): ChargeModel[] {\r\n return this.charges.map(charge => new ChargeModel(charge.getDetails()));\r\n }\r\n\r\n /**\r\n * Adds a new charge to the container and recalculates totals.\r\n * @param charge - The charge to add.\r\n */\r\n public addCharge(charge: ChargeModel): void {\r\n this.charges.push(charge);\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Clears all charges from the container and recalculates totals.\r\n */\r\n public clearCharges(): void {\r\n this.charges = [];\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Gets a copy of the shipping details associated with the container.\r\n * @returns A ShippingDetails object, or null if none are set.\r\n */\r\n public getShippingDetails(): ShippingDetails | null {\r\n return this.shippingDetails ? Utils.deepClone(this.shippingDetails) : null;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the shipping address associated with the container.\r\n * Returns a new AddressModel instance created from the original's details.\r\n * @returns An AddressModel instance, or null if no shipping address is set.\r\n */\r\n public getShippingAddress(): AddressModel | null {\r\n return this.shippingAddress ? new AddressModel(this.shippingAddress.getDetails()) : null;\r\n }\r\n\r\n /**\r\n * Checks if a shipping address is associated with this container.\r\n * @returns True if a shipping address is set, false otherwise.\r\n */\r\n public hasShippingAddress(): boolean {\r\n return !!this.shippingAddress;\r\n }\r\n\r\n /**\r\n * Checks if a billing address is associated with this container.\r\n * @returns True if a billing address is set, false otherwise.\r\n */\r\n public hasBillingAddress(): boolean {\r\n return !!this.billingAddress;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the billing address associated with the container.\r\n * Returns a new AddressModel instance created from the original's details.\r\n * @returns An AddressModel instance, or null if no billing address is set.\r\n */\r\n public getBillingAddress(): AddressModel | null {\r\n return this.billingAddress ? new AddressModel(this.billingAddress.getDetails()) : null;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the coupons applied to the container.\r\n * Each item is a new CouponModel instance created from the original's details.\r\n * @returns An array of CouponModel instances.\r\n */\r\n public getCoupons(): CouponModel[] {\r\n return [...this.coupons];\r\n }\r\n\r\n /**\r\n * Gets the country code associated with this container.\r\n * @returns The CountryCode enum value.\r\n */\r\n public getCountry(): CountryCode {\r\n return this.country;\r\n }\r\n\r\n /**\r\n * Gets the currency code associated with this container.\r\n * @returns The CurrencyCode enum value.\r\n */\r\n public getCurrency(): CurrencyCode {\r\n return this.currency;\r\n }\r\n\r\n /**\r\n * Gets the locale code associated with this container.\r\n * @returns The LocaleCode enum value.\r\n */\r\n public getLocale(): LocaleCode {\r\n return this.locale;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the calculated totals for the container.\r\n * @returns An object containing shipping, subtotal, coupon, and grand totals.\r\n */\r\n public getTotal() {\r\n return {\r\n lineItemSubtotal: this.total.lineItemSubtotal,\r\n netLineItemSubtotal: this.total.netLineItemSubtotal,\r\n lineItemTaxTotal: this.total.lineItemTaxTotal,\r\n lineItemTaxBreakdown: Object.fromEntries(\r\n Object.entries(this.total.lineItemTaxBreakdown).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n system: systemValue.system,\r\n totalAmount: systemValue.totalAmount,\r\n subSystems: { ...systemValue.subSystems }\r\n }\r\n ])\r\n ),\r\n additiveCharges: this.total.additiveCharges,\r\n netAdditiveCharges : this.total.netAdditiveCharges,\r\n additiveChargesTaxTotal: this.total.additiveChargesTaxTotal,\r\n additiveChargesTaxBreakdown: Object.fromEntries(\r\n Object.entries(this.total.additiveChargesTaxBreakdown).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n system: systemValue.system,\r\n totalAmount: systemValue.totalAmount,\r\n subSystems: { ...systemValue.subSystems }\r\n }\r\n ])\r\n ),\r\n adjustmentCharges: this.total.adjustmentCharges,\r\n shippingCharges: this.total.shippingCharges,\r\n netShippingCharges: this.total.netShippingCharges,\r\n discountBreakdown: { ...this.total.discountBreakdown },\r\n discountTotal: this.total.discountTotal,\r\n taxTotal: this.total.taxTotal,\r\n taxBreakdown: Object.fromEntries(\r\n Object.entries(this.total.taxBreakdown).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n system: systemValue.system,\r\n totalAmount: systemValue.totalAmount,\r\n subSystems: { ...systemValue.subSystems }\r\n }\r\n ])\r\n ),\r\n grandTotal: this.total.grandTotal,\r\n };\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the shopping container's current state.\r\n * Includes details from the base model and specific container properties.\r\n * @returns BaseShoppingContainerData object suitable for serialization or API responses.\r\n */\r\n getDetails(): BaseShoppingContainerData {\r\n const totals = this.getTotal();\r\n return {\r\n ...super.getDetails(),\r\n id: this.getId(),\r\n customerId: this.getCustomerId(),\r\n customerEmail: this.getCustomerEmail(),\r\n anonymousId: this.getAnonymousId(),\r\n lineItems: this.getLineItems().map(item => item.getDetails()),\r\n charges: this.getCharges().map(charge => charge.getDetails()),\r\n shippingDetails: this.getShippingDetails(),\r\n shippingAddress: this.getShippingAddress()?.getDetails() || null,\r\n billingAddress: this.getBillingAddress()?.getDetails() || null,\r\n coupons: this.getCoupons().map(coupon => coupon.getDetails()),\r\n total: {\r\n // Item Totals\r\n lineItemSubtotal: totals.lineItemSubtotal.getDetails(),\r\n netLineItemSubtotal: totals.netLineItemSubtotal.getDetails(),\r\n lineItemTaxTotal: totals.lineItemTaxTotal.getDetails(),\r\n lineItemTaxBreakdown: this.serializeTaxBreakdown(totals.lineItemTaxBreakdown),\r\n\r\n // Charge Totals\r\n additiveCharges: totals.additiveCharges.getDetails(),\r\n netAdditiveCharges: totals.netAdditiveCharges.getDetails(),\r\n additiveChargesTaxTotal: totals.additiveChargesTaxTotal.getDetails(),\r\n additiveChargesTaxBreakdown: this.serializeTaxBreakdown(totals.additiveChargesTaxBreakdown),\r\n\r\n adjustmentCharges: totals.adjustmentCharges.getDetails(),\r\n\r\n shippingCharges: totals.shippingCharges.getDetails(),\r\n netShippingCharges: totals.netShippingCharges.getDetails(),\r\n\r\n // Aggregate Totals\r\n discountTotal: totals.discountTotal.getDetails(),\r\n discountBreakdown: Object.fromEntries(\r\n Object.entries(totals.discountBreakdown).map(([key, value]) => [key, value.getDetails()])\r\n ),\r\n taxTotal: totals.taxTotal.getDetails(),\r\n taxBreakdown: this.serializeTaxBreakdown(totals.taxBreakdown),\r\n grandTotal: totals.grandTotal.getDetails(),\r\n },\r\n country: this.getCountry(),\r\n currency: this.getCurrency(),\r\n locale: this.getLocale(),\r\n };\r\n }\r\n\r\n /**\r\n * Recalculates the total costs for the shopping container.\r\n * This includes summing line items, calculating shipping, applying coupons, and computing taxes.\r\n */\r\n public calculateTotals(): void {\r\n const zero = new PriceModel({ amount: 0, currency: this.currency });\r\n \r\n // 1. Calculate LineItem subtotals and Shipping Cost\r\n const filteredLineItems = this.lineItems.filter(lineitem => lineitem.getState() !== LineItemState.CANCELLED);\r\n const lineItemSubtotal = filteredLineItems.reduce((total, lineItem) => total.add(lineItem.getTotal().subtotal), zero);\r\n const shippingCharges = this.charges\r\n .filter(charge => charge.getType() === ChargeType.SHIPPING)\r\n .reduce((total, charge) => total.add(charge.getTotal().chargeAmount), zero);\r\n\r\n // 1.1 Assign lineitemSubTotal and shipping charges to total, which will be used for coupon calculations\r\n this.total.lineItemSubtotal = lineItemSubtotal;\r\n this.total.shippingCharges = shippingCharges;\r\n\r\n // 2. Calculate coupon values based on gross subtotal & shipping\r\n let discountTotal = zero;\r\n let discountBreakdown: Record<string, PriceModel> = {};\r\n let nonShippingCouponTotal: Record<string, PriceModel> = {};\r\n this.coupons.forEach(coupon => {\r\n const couponValue = coupon.calculateApplicableCouponDiscount(lineItemSubtotal, shippingCharges, this.country, this.currency);\r\n discountTotal = discountTotal.add(couponValue);\r\n discountBreakdown[coupon.getCode()] = couponValue;\r\n if (coupon.getCategory() !== CouponCategory.SHIPPING) {\r\n nonShippingCouponTotal[coupon.getCode()] = couponValue;\r\n }\r\n })\r\n\r\n // 2.1. Assign discount total and breakdown to total\r\n this.total.discountTotal = discountTotal;\r\n this.total.discountBreakdown = discountBreakdown;\r\n\r\n // 3. Apply discounts at lineitem and shipping charges\r\n this.applyDiscountsInLineItem(nonShippingCouponTotal);\r\n\r\n const shippingCoupon = this.coupons.find(coupon => coupon.getCategory() === CouponCategory.SHIPPING);\r\n if(shippingCoupon) {\r\n this.applyDiscountsInShippingCharges({[shippingCoupon.getCode()] : discountBreakdown[shippingCoupon.getCode()] || zero});\r\n } else {\r\n // If no shipping coupon, ensure any previous discounts on shipping charges are cleared\r\n this.applyDiscountsInShippingCharges({});\r\n }\r\n\r\n // 3.1 Calculate net lineitemSubtotal and net shipping after discount\r\n const netLineItemSubtotal = this.lineItems.reduce((total, lineItem) => total.add(lineItem.getTotal().netSubtotal), zero);\r\n const netShippingCharges = this.charges\r\n .filter(charge => charge.getType() === ChargeType.SHIPPING)\r\n .reduce((total, charge) => total.add(charge.getTotal().grandTotal), zero);\r\n\r\n // 3.2 Assign net lineitemSubtotal and net shipping to total\r\n this.total.netLineItemSubtotal = netLineItemSubtotal;\r\n this.total.netShippingCharges = netShippingCharges;\r\n\r\n // 4. Calculate charges and net charges after discount\r\n const additiveCharges = this.charges\r\n .filter(charge => charge.getImpact() === ChargeImpact.ADD)\r\n .reduce((total, charge) => total.add(charge.getTotal().chargeAmount), zero);\r\n const netAdditiveCharges = this.charges\r\n .filter(charge => charge.getImpact() === ChargeImpact.ADD)\r\n .reduce((total, charge) => total.add(charge.getTotal().grandTotal), zero);\r\n const adjustmentCharges = this.charges\r\n .filter(charge => charge.getImpact() === ChargeImpact.SUBTRACT)\r\n .reduce((total, charge) => total.add(charge.getTotal().grandTotal), zero);\r\n\r\n // 5. Aggregate Taxes & Grand Total from all items and charges\r\n let taxTotal = zero;\r\n let lineItemTaxTotal = zero;\r\n let additiveChargesTaxTotal = zero;\r\n\r\n const taxBreakdown: ShoppingContainerTaxBreakdownModel = {};\r\n const lineItemTaxBreakdown: ShoppingContainerTaxBreakdownModel = {};\r\n const additiveChargesTaxBreakdown: ShoppingContainerTaxBreakdownModel = {};\r\n\r\n // Helper to merge tax breakdowns into hierarchical structure\r\n const mergeTax = (\r\n sourceBreakdown: Record<string, LineItemTaxBreakdownModel | ChargeTaxBreakdownModel>,\r\n targetBreakdown: ShoppingContainerTaxBreakdownModel\r\n ) => {\r\n Object.entries(sourceBreakdown).forEach(([ruleId, breakdown]) => {\r\n const system = breakdown.system;\r\n const subsystem = breakdown.subSystem;\r\n\r\n // Populate Target Breakdown\r\n if (!targetBreakdown[system]) {\r\n targetBreakdown[system] = { system, totalAmount: zero, subSystems: {} };\r\n }\r\n if (!targetBreakdown[system].subSystems[subsystem]) {\r\n targetBreakdown[system].subSystems[subsystem] = breakdown.taxAmount;\r\n } else {\r\n targetBreakdown[system].subSystems[subsystem] = targetBreakdown[system].subSystems[subsystem].add(breakdown.taxAmount);\r\n }\r\n targetBreakdown[system].totalAmount = targetBreakdown[system].totalAmount.add(breakdown.taxAmount);\r\n\r\n // Populate Combined taxBreakdown\r\n if (!taxBreakdown[system]) {\r\n taxBreakdown[system] = { system, totalAmount: zero, subSystems: {} };\r\n }\r\n if (!taxBreakdown[system].subSystems[subsystem]) {\r\n taxBreakdown[system].subSystems[subsystem] = breakdown.taxAmount;\r\n } else {\r\n taxBreakdown[system].subSystems[subsystem] = taxBreakdown[system].subSystems[subsystem].add(breakdown.taxAmount);\r\n }\r\n taxBreakdown[system].totalAmount = taxBreakdown[system].totalAmount.add(breakdown.taxAmount);\r\n });\r\n };\r\n\r\n // 5.1 Merge line item taxes\r\n filteredLineItems.forEach(lineItem => {\r\n const lineItemTaxes = lineItem.getTotal().taxBreakdown;\r\n if (lineItemTaxes) {\r\n mergeTax(lineItemTaxes, lineItemTaxBreakdown);\r\n mergeTax(lineItemTaxes, taxBreakdown);\r\n lineItemTaxTotal = lineItemTaxTotal.add(lineItem.getTotal().taxTotal);\r\n }\r\n });\r\n\r\n // 5.2 Merge charge taxes\r\n this.charges.forEach(charge => {\r\n const chargeTaxes = charge.getTotal().taxBreakdown;\r\n if (chargeTaxes) {\r\n mergeTax(chargeTaxes, additiveChargesTaxBreakdown);\r\n mergeTax(chargeTaxes, taxBreakdown);\r\n additiveChargesTaxTotal = additiveChargesTaxTotal.add(charge.getTotal().taxTotal);\r\n }\r\n });\r\n\r\n // 5.3 Calculate total tax\r\n taxTotal = lineItemTaxTotal.add(additiveChargesTaxTotal);\r\n\r\n // 6. Final Grand Total: netLineItemSubtotal + lineItemTaxTotal + netAdditiveCharges (includes netShippingCharges) - adjustmentCharges\r\n const grandTotal = netLineItemSubtotal.add(lineItemTaxTotal).add(netAdditiveCharges).subtract(adjustmentCharges);\r\n\r\n\r\n // 7. Reconstruct total object\r\n this.total = {\r\n lineItemSubtotal: lineItemSubtotal,\r\n netLineItemSubtotal: netLineItemSubtotal,\r\n lineItemTaxTotal: lineItemTaxTotal,\r\n lineItemTaxBreakdown: lineItemTaxBreakdown,\r\n\r\n additiveCharges: additiveCharges,\r\n netAdditiveCharges: netAdditiveCharges,\r\n additiveChargesTaxTotal: additiveChargesTaxTotal,\r\n additiveChargesTaxBreakdown: additiveChargesTaxBreakdown,\r\n\r\n adjustmentCharges: adjustmentCharges,\r\n shippingCharges: shippingCharges,\r\n netShippingCharges: netShippingCharges,\r\n\r\n discountTotal: discountTotal,\r\n discountBreakdown: discountBreakdown,\r\n taxTotal: taxTotal,\r\n taxBreakdown: taxBreakdown,\r\n grandTotal: grandTotal,\r\n };\r\n }\r\n\r\n /**\r\n * Updates the shipping details and recalculates the totals.\r\n * @param shippingDetails - The new shipping details to apply.\r\n */\r\n public updateShippingDetails(shippingDetails: ShippingDetails): void {\r\n this.shippingDetails = shippingDetails;\r\n }\r\n\r\n /**\r\n * Applies a list of coupons to the shopping container.\r\n * Filters out invalid coupons, separates shipping and non-shipping coupons,\r\n * and distributes discounts to line items.\r\n * @param applicableCoupons - The list of coupons to attempt to apply.\r\n */\r\n public applyCoupons(applicableCoupons: CouponModel[]): void {\r\n //Apply coupons\r\n const shippingCoupons = applicableCoupons.filter(coupon => coupon.getCategory() === CouponCategory.SHIPPING);\r\n const otherCoupons = applicableCoupons.filter(coupon => coupon.getCategory() !== CouponCategory.SHIPPING);\r\n\r\n this.coupons = [];\r\n this.total.discountTotal = this.total.lineItemSubtotal.zero();\r\n this.total.discountBreakdown = {};\r\n // Apply non shipping coupons\r\n otherCoupons.length && this.applyNonShippingCoupons(otherCoupons);\r\n this.applyDiscountsInLineItem(this.total.discountBreakdown);\r\n\r\n // Apply shipping coupons\r\n shippingCoupons.length && this.applyShippingCoupons(shippingCoupons);\r\n\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Distributes the total discount amount among the line items.\r\n * @param couponTotal - A record of coupon codes and their calculated discount amounts.\r\n */\r\n private applyDiscountsInLineItem(couponTotal: Record<string, PriceModel>) {\r\n const couponDiscounts: [string, PriceModel][] = Array.from(Object.entries(couponTotal))\r\n .filter(couponDiscount => !couponDiscount[1].isZero());\r\n\r\n const itemDiscounts = new Map<string, { coupon: CouponModel, amount: PriceModel }[]>();\r\n this.lineItems.forEach(li => itemDiscounts.set(li.getId(), []));\r\n\r\n couponDiscounts.forEach(([code, discountTotal]) => {\r\n const coupon = this.coupons.find(c => c.getCode() === code);\r\n if (!coupon || discountTotal.isZero()) return;\r\n\r\n const validItems = this.lineItems\r\n .filter(li => li.getState() !== LineItemState.CANCELLED && !li.getTotal().subtotal.isZero())\r\n .sort((a, b) => a.getTotal().subtotal.compareTo(b.getTotal().subtotal));\r\n\r\n let distributed = new PriceModel({ amount: 0, currency: this.currency });\r\n\r\n validItems.forEach((item, index) => {\r\n let amount: PriceModel;\r\n if (index === validItems.length - 1) {\r\n amount = discountTotal.subtract(distributed);\r\n } else {\r\n amount = discountTotal.multiply(item.getTotal().subtotal).divide(this.total.lineItemSubtotal).round();\r\n }\r\n distributed = distributed.add(amount);\r\n itemDiscounts.get(item.getId())?.push({ coupon, amount });\r\n });\r\n });\r\n\r\n this.lineItems.forEach(lineItem => {\r\n if (lineItem.getState() === LineItemState.CANCELLED || this.total.lineItemSubtotal.isZero()) {\r\n lineItem.updateDiscounts([]);\r\n } else {\r\n lineItem.updateDiscounts(itemDiscounts.get(lineItem.getId()) || []);\r\n }\r\n });\r\n }\r\n\r\n private applyDiscountsInShippingCharges(couponTotal: Record<string, PriceModel>) {\r\n const couponDiscounts: [string, PriceModel][] = Array.from(Object.entries(couponTotal))\r\n .filter(couponDiscount => !couponDiscount[1].isZero());\r\n const shippingCharges = this.charges.filter(charge => charge.getType() === ChargeType.SHIPPING);\r\n\r\n const chargeDiscounts = new Map<string, { coupon: CouponModel, amount: PriceModel }[]>();\r\n shippingCharges.forEach(li => chargeDiscounts.set(li.getId(), []));\r\n\r\n couponDiscounts.forEach(([code, discountTotal]) => {\r\n const coupon = this.coupons.find(c => c.getCode() === code);\r\n if (!coupon || discountTotal.isZero()) return;\r\n\r\n const validCharges = shippingCharges\r\n .sort((a, b) => a.getTotal().grandTotal.compareTo(b.getTotal().grandTotal));\r\n\r\n let distributed = new PriceModel({ amount: 0, currency: this.currency });\r\n\r\n validCharges.forEach((charge, index) => {\r\n let amount: PriceModel;\r\n if (index === validCharges.length - 1) {\r\n amount = discountTotal.subtract(distributed);\r\n } else {\r\n amount = discountTotal.multiply(charge.getTotal().chargeAmount).divide(this.total.shippingCharges).round();\r\n }\r\n distributed = distributed.add(amount);\r\n chargeDiscounts.get(charge.getId())?.push({ coupon, amount });\r\n });\r\n });\r\n\r\n shippingCharges.forEach(charge => {\r\n charge.updateDiscounts(chargeDiscounts.get(charge.getId()) || []);\r\n });\r\n }\r\n\r\n /**\r\n * Selects and applies the best applicable non-shipping coupon.\r\n * Currently supports applying only a single coupon of type COUPON.\r\n * @param applicableCoupons - List of available non-shipping coupons.\r\n */\r\n private applyNonShippingCoupons(applicableCoupons: CouponModel[]) {\r\n const coupons = applicableCoupons.filter(coupon => coupon.getType() === CouponType.COUPON);\r\n if (coupons.length === 1) {\r\n const couponValue = coupons[0].calculateApplicableCouponDiscount(this.total.lineItemSubtotal, this.total.shippingCharges, this.country, this.currency);\r\n if (couponValue.getAmount() > 0) {\r\n this.coupons.push(coupons[0]);\r\n this.total.discountTotal = couponValue;\r\n this.total.discountBreakdown[coupons[0].getCode()] = couponValue;\r\n }\r\n }\r\n // Todo: Add support to other type in future like promotion\r\n }\r\n\r\n /**\r\n * Selects and applies the best applicable shipping coupon.\r\n * @param applicableCoupons - List of available shipping coupons.\r\n */\r\n private applyShippingCoupons(applicableCoupons: CouponModel[]) {\r\n if (this.total.shippingCharges.getAmount() > 0 && applicableCoupons.length > 0) {\r\n const netLineItemSubtotal = this.total.lineItemSubtotal.subtract(this.total.discountTotal);\r\n\r\n const maxValuedCoupon = applicableCoupons.reduce((maxCoupon, currentCoupon) => {\r\n if (!maxCoupon) return currentCoupon;\r\n\r\n const currentCouponValue = currentCoupon.calculateApplicableCouponDiscount(netLineItemSubtotal, this.total.shippingCharges, this.country, this.currency).min(this.total.shippingCharges);\r\n const maxCouponValue = maxCoupon.calculateApplicableCouponDiscount(netLineItemSubtotal, this.total.shippingCharges, this.country, this.currency).min(this.total.shippingCharges);\r\n\r\n if (currentCouponValue.compareTo(maxCouponValue) === 0) {\r\n return currentCoupon.getType() === CouponType.COUPON ? currentCoupon : maxCoupon;\r\n }\r\n return currentCouponValue.compareTo(maxCouponValue) > 0 ? currentCoupon : maxCoupon;\r\n });\r\n\r\n const couponValue = maxValuedCoupon.calculateApplicableCouponDiscount(netLineItemSubtotal, this.total.shippingCharges, this.country, this.currency).min(this.total.shippingCharges);\r\n if (couponValue.getAmount() > 0) {\r\n this.coupons.push(maxValuedCoupon);\r\n this.total.discountTotal = this.total.discountTotal.add(couponValue);\r\n this.total.discountBreakdown[maxValuedCoupon.getCode()] = couponValue;\r\n }\r\n }\r\n }\r\n}\r\n\r\n\r\n"]}
package/dist/index.d.mts CHANGED
@@ -317,4 +317,51 @@ declare const Logger: {
317
317
  inspect: (context: any) => string;
318
318
  };
319
319
 
320
- export { type ErrorType, Fetch, Logger, ResponseUtility, Schema, type SuccessType, Utils };
320
+ /**
321
+ * In-memory cache with per-entry TTL expiration and LRU-style eviction.
322
+ *
323
+ * Keys are `string` and values are generic (`T`).
324
+ * Expired entries are removed lazily on `get` and periodically by a cleanup timer.
325
+ */
326
+ declare class MemoryCache<T> {
327
+ private cache;
328
+ private maxSize;
329
+ private ttl;
330
+ private cleanupInterval;
331
+ /**
332
+ * Creates a cache instance.
333
+ *
334
+ * @param maxSize Maximum number of live entries allowed in cache. Must be >= 1.
335
+ * @param ttl Time-to-live in milliseconds for each entry from write time. Must be >= 1.
336
+ */
337
+ constructor(maxSize?: number, ttl?: number);
338
+ /**
339
+ * Removes expired entries from the cache.
340
+ */
341
+ private cleanup;
342
+ /**
343
+ * Stores or updates a value in cache.
344
+ * If the key already exists, the value and expiry are replaced.
345
+ * If capacity is reached and key is new, least-recently-used entry is evicted.
346
+ *
347
+ * @param key Cache key.
348
+ * @param value Value to store.
349
+ */
350
+ set(key: string, value: T): void;
351
+ /**
352
+ * Reads a value by key.
353
+ * Returns `undefined` if the key does not exist or if the entry has expired.
354
+ * Access refreshes recency for eviction order (LRU behavior).
355
+ *
356
+ * @param key Cache key.
357
+ * @returns Cached value or `undefined`.
358
+ */
359
+ get(key: string): T | undefined;
360
+ /**
361
+ * Stops the background cleanup timer.
362
+ * Call when the cache instance is no longer needed.
363
+ */
364
+ dispose(): void;
365
+ }
366
+
367
+ export { type ErrorType, Fetch, Logger, MemoryCache, ResponseUtility, Schema, type SuccessType, Utils };
package/dist/index.d.ts CHANGED
@@ -317,4 +317,51 @@ declare const Logger: {
317
317
  inspect: (context: any) => string;
318
318
  };
319
319
 
320
- export { type ErrorType, Fetch, Logger, ResponseUtility, Schema, type SuccessType, Utils };
320
+ /**
321
+ * In-memory cache with per-entry TTL expiration and LRU-style eviction.
322
+ *
323
+ * Keys are `string` and values are generic (`T`).
324
+ * Expired entries are removed lazily on `get` and periodically by a cleanup timer.
325
+ */
326
+ declare class MemoryCache<T> {
327
+ private cache;
328
+ private maxSize;
329
+ private ttl;
330
+ private cleanupInterval;
331
+ /**
332
+ * Creates a cache instance.
333
+ *
334
+ * @param maxSize Maximum number of live entries allowed in cache. Must be >= 1.
335
+ * @param ttl Time-to-live in milliseconds for each entry from write time. Must be >= 1.
336
+ */
337
+ constructor(maxSize?: number, ttl?: number);
338
+ /**
339
+ * Removes expired entries from the cache.
340
+ */
341
+ private cleanup;
342
+ /**
343
+ * Stores or updates a value in cache.
344
+ * If the key already exists, the value and expiry are replaced.
345
+ * If capacity is reached and key is new, least-recently-used entry is evicted.
346
+ *
347
+ * @param key Cache key.
348
+ * @param value Value to store.
349
+ */
350
+ set(key: string, value: T): void;
351
+ /**
352
+ * Reads a value by key.
353
+ * Returns `undefined` if the key does not exist or if the entry has expired.
354
+ * Access refreshes recency for eviction order (LRU behavior).
355
+ *
356
+ * @param key Cache key.
357
+ * @returns Cached value or `undefined`.
358
+ */
359
+ get(key: string): T | undefined;
360
+ /**
361
+ * Stops the background cleanup timer.
362
+ * Call when the cache instance is no longer needed.
363
+ */
364
+ dispose(): void;
365
+ }
366
+
367
+ export { type ErrorType, Fetch, Logger, MemoryCache, ResponseUtility, Schema, type SuccessType, Utils };