b23-lib 3.0.6 → 3.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/dist/Auth/index.js +1 -1
  2. package/dist/Auth/index.js.map +1 -1
  3. package/dist/Auth/index.mjs +1 -1
  4. package/dist/Auth/index.mjs.map +1 -1
  5. package/dist/Classes/Address.d.mts +1 -1
  6. package/dist/Classes/Address.d.ts +1 -1
  7. package/dist/Classes/Address.js +1 -1
  8. package/dist/Classes/Address.js.map +1 -1
  9. package/dist/Classes/Address.mjs +1 -1
  10. package/dist/Classes/Base.d.mts +1 -1
  11. package/dist/Classes/Base.d.ts +1 -1
  12. package/dist/Classes/Base.js +1 -1
  13. package/dist/Classes/Base.js.map +1 -1
  14. package/dist/Classes/Base.mjs +1 -1
  15. package/dist/Classes/Cart.d.mts +1 -1
  16. package/dist/Classes/Cart.d.ts +1 -1
  17. package/dist/Classes/Cart.js +1 -1
  18. package/dist/Classes/Cart.js.map +1 -1
  19. package/dist/Classes/Cart.mjs +1 -1
  20. package/dist/Classes/Cart.mjs.map +1 -1
  21. package/dist/Classes/Charge.d.mts +11 -1
  22. package/dist/Classes/Charge.d.ts +11 -1
  23. package/dist/Classes/Charge.js +1 -1
  24. package/dist/Classes/Charge.js.map +1 -1
  25. package/dist/Classes/Charge.mjs +1 -1
  26. package/dist/Classes/Common.d.mts +1 -1
  27. package/dist/Classes/Common.d.ts +1 -1
  28. package/dist/Classes/Coupon.d.mts +1 -1
  29. package/dist/Classes/Coupon.d.ts +1 -1
  30. package/dist/Classes/Coupon.js +1 -1
  31. package/dist/Classes/Coupon.js.map +1 -1
  32. package/dist/Classes/Coupon.mjs +1 -1
  33. package/dist/Classes/Customer.d.mts +1 -1
  34. package/dist/Classes/Customer.d.ts +1 -1
  35. package/dist/Classes/Customer.js +1 -1
  36. package/dist/Classes/Customer.js.map +1 -1
  37. package/dist/Classes/Customer.mjs +1 -1
  38. package/dist/Classes/Customer.mjs.map +1 -1
  39. package/dist/Classes/CustomerAddress.d.mts +1 -1
  40. package/dist/Classes/CustomerAddress.d.ts +1 -1
  41. package/dist/Classes/CustomerAddress.js +1 -1
  42. package/dist/Classes/CustomerAddress.js.map +1 -1
  43. package/dist/Classes/CustomerAddress.mjs +1 -1
  44. package/dist/Classes/CustomerAddress.mjs.map +1 -1
  45. package/dist/Classes/Inventory.d.mts +1 -1
  46. package/dist/Classes/Inventory.d.ts +1 -1
  47. package/dist/Classes/Inventory.js +1 -1
  48. package/dist/Classes/Inventory.js.map +1 -1
  49. package/dist/Classes/Inventory.mjs +1 -1
  50. package/dist/Classes/Inventory.mjs.map +1 -1
  51. package/dist/Classes/LineItem.d.mts +1 -1
  52. package/dist/Classes/LineItem.d.ts +1 -1
  53. package/dist/Classes/LineItem.js +1 -1
  54. package/dist/Classes/LineItem.js.map +1 -1
  55. package/dist/Classes/LineItem.mjs +1 -1
  56. package/dist/Classes/Order.d.mts +5 -5
  57. package/dist/Classes/Order.d.ts +5 -5
  58. package/dist/Classes/Order.js +1 -1
  59. package/dist/Classes/Order.js.map +1 -1
  60. package/dist/Classes/Order.mjs +1 -1
  61. package/dist/Classes/Order.mjs.map +1 -1
  62. package/dist/Classes/Payment.d.mts +1 -1
  63. package/dist/Classes/Payment.d.ts +1 -1
  64. package/dist/Classes/Payment.js +1 -1
  65. package/dist/Classes/Payment.js.map +1 -1
  66. package/dist/Classes/Payment.mjs +1 -1
  67. package/dist/Classes/Payment.mjs.map +1 -1
  68. package/dist/Classes/Price.d.mts +1 -1
  69. package/dist/Classes/Price.d.ts +1 -1
  70. package/dist/Classes/Product.d.mts +1 -1
  71. package/dist/Classes/Product.d.ts +1 -1
  72. package/dist/Classes/Product.js +1 -1
  73. package/dist/Classes/Product.js.map +1 -1
  74. package/dist/Classes/Product.mjs +1 -1
  75. package/dist/Classes/ShoppingContainer.d.mts +43 -2
  76. package/dist/Classes/ShoppingContainer.d.ts +43 -2
  77. package/dist/Classes/ShoppingContainer.js +1 -1
  78. package/dist/Classes/ShoppingContainer.js.map +1 -1
  79. package/dist/Classes/ShoppingContainer.mjs +1 -1
  80. package/dist/Classes/TaxRule.d.mts +1 -1
  81. package/dist/Classes/TaxRule.d.ts +1 -1
  82. package/dist/Classes/TaxRule.js +1 -1
  83. package/dist/Classes/TaxRule.js.map +1 -1
  84. package/dist/Classes/TaxRule.mjs +1 -1
  85. package/dist/Classes/TieredPrice.d.mts +1 -1
  86. package/dist/Classes/TieredPrice.d.ts +1 -1
  87. package/dist/Classes/TieredPrice.js +1 -1
  88. package/dist/Classes/TieredPrice.js.map +1 -1
  89. package/dist/Classes/TieredPrice.mjs +1 -1
  90. package/dist/{Common-Bd8Xv8x4.d.mts → Common-XM4zQpWC.d.mts} +1 -1
  91. package/dist/{Common-CXp_zjft.d.ts → Common-uAn7Sunn.d.ts} +1 -1
  92. package/dist/chunk-GJ2DSRIP.mjs +2 -0
  93. package/dist/chunk-GJ2DSRIP.mjs.map +1 -0
  94. package/dist/chunk-HKXV6QWV.mjs +2 -0
  95. package/dist/chunk-HKXV6QWV.mjs.map +1 -0
  96. package/dist/chunk-IQNK7EEI.mjs +2 -0
  97. package/dist/chunk-IQNK7EEI.mjs.map +1 -0
  98. package/dist/{chunk-6VRUVGN3.mjs → chunk-L3CNGDFJ.mjs} +2 -2
  99. package/dist/chunk-L3CNGDFJ.mjs.map +1 -0
  100. package/dist/{chunk-YSUBOEFT.mjs → chunk-R3ZADSUJ.mjs} +2 -2
  101. package/dist/{chunk-YSUBOEFT.mjs.map → chunk-R3ZADSUJ.mjs.map} +1 -1
  102. package/dist/chunk-RHSKHT5F.mjs +2 -0
  103. package/dist/chunk-RHSKHT5F.mjs.map +1 -0
  104. package/dist/chunk-URFRPQCT.mjs +2 -0
  105. package/dist/chunk-URFRPQCT.mjs.map +1 -0
  106. package/dist/chunk-XBFSNBKL.mjs +2 -0
  107. package/dist/chunk-XBFSNBKL.mjs.map +1 -0
  108. package/dist/index.d.mts +1 -1
  109. package/dist/index.d.ts +1 -1
  110. package/dist/index.js +2 -2
  111. package/dist/index.js.map +1 -1
  112. package/dist/index.mjs +1 -1
  113. package/dist/index.mjs.map +1 -1
  114. package/package.json +1 -1
  115. package/dist/chunk-2ZQIRKRB.mjs +0 -2
  116. package/dist/chunk-2ZQIRKRB.mjs.map +0 -1
  117. package/dist/chunk-52Y5EI7O.mjs +0 -2
  118. package/dist/chunk-52Y5EI7O.mjs.map +0 -1
  119. package/dist/chunk-6KCJVEZD.mjs +0 -2
  120. package/dist/chunk-6KCJVEZD.mjs.map +0 -1
  121. package/dist/chunk-6VRUVGN3.mjs.map +0 -1
  122. package/dist/chunk-DLLGHKS5.mjs +0 -2
  123. package/dist/chunk-DLLGHKS5.mjs.map +0 -1
  124. package/dist/chunk-HR5HHV6O.mjs +0 -2
  125. package/dist/chunk-HR5HHV6O.mjs.map +0 -1
  126. package/dist/chunk-Y5D6RHTJ.mjs +0 -2
  127. package/dist/chunk-Y5D6RHTJ.mjs.map +0 -1
  128. package/dist/chunk-YKRWZ24N.mjs +0 -2
  129. package/dist/chunk-YKRWZ24N.mjs.map +0 -1
@@ -1,7 +1,7 @@
1
1
  import BaseModel, { BaseAttributes, BaseData } from './Base.mjs';
2
2
  import AddressModel, { AddressData } from './Address.mjs';
3
3
  import LineItemModel, { LineItemData } from './LineItem.mjs';
4
- import { P as PriceData, b as PriceModel, S as ShippingDetails, C as CountryCode, a as CurrencyCode, L as LocaleCode } from '../Common-Bd8Xv8x4.mjs';
4
+ import { b as PriceData, c as PriceModel, S as ShippingDetails, C as CountryCode, a as CurrencyCode, L as LocaleCode } from '../Common-XM4zQpWC.mjs';
5
5
  import CouponModel, { CouponData } from './Coupon.mjs';
6
6
  import { TaxSystem } from './Enum.mjs';
7
7
  import ChargeModel, { ChargeData } from './Charge.mjs';
@@ -226,7 +226,48 @@ declare abstract class BaseShoppingContainerModel extends BaseModel {
226
226
  * Gets a defensive copy of the calculated totals for the container.
227
227
  * @returns An object containing shipping, subtotal, coupon, and grand totals.
228
228
  */
229
- getTotal(): ShoppingContainerTotalModel;
229
+ getTotal(): {
230
+ subtotal: PriceModel;
231
+ netSubtotal: PriceModel;
232
+ lineItemTaxTotal: PriceModel;
233
+ lineItemTaxBreakdown: {
234
+ [k: string]: {
235
+ system: TaxSystem;
236
+ totalAmount: PriceModel;
237
+ subSystems: {
238
+ [x: string]: PriceModel;
239
+ };
240
+ };
241
+ };
242
+ chargesTotal: PriceModel;
243
+ shippingCharge: PriceModel;
244
+ netShippingCharge: PriceModel;
245
+ chargeTaxTotal: PriceModel;
246
+ chargeTaxBreakdown: {
247
+ [k: string]: {
248
+ system: TaxSystem;
249
+ totalAmount: PriceModel;
250
+ subSystems: {
251
+ [x: string]: PriceModel;
252
+ };
253
+ };
254
+ };
255
+ taxTotal: PriceModel;
256
+ taxBreakdown: {
257
+ [k: string]: {
258
+ system: TaxSystem;
259
+ totalAmount: PriceModel;
260
+ subSystems: {
261
+ [x: string]: PriceModel;
262
+ };
263
+ };
264
+ };
265
+ discounts: {
266
+ [x: string]: PriceModel;
267
+ };
268
+ totalDiscount: PriceModel;
269
+ grandTotal: PriceModel;
270
+ };
230
271
  /**
231
272
  * Gets a plain data object representing the shopping container's current state.
232
273
  * Includes details from the base model and specific container properties.
@@ -1,7 +1,7 @@
1
1
  import BaseModel, { BaseAttributes, BaseData } from './Base.js';
2
2
  import AddressModel, { AddressData } from './Address.js';
3
3
  import LineItemModel, { LineItemData } from './LineItem.js';
4
- import { P as PriceData, b as PriceModel, S as ShippingDetails, C as CountryCode, a as CurrencyCode, L as LocaleCode } from '../Common-CXp_zjft.js';
4
+ import { b as PriceData, c as PriceModel, S as ShippingDetails, C as CountryCode, a as CurrencyCode, L as LocaleCode } from '../Common-uAn7Sunn.js';
5
5
  import CouponModel, { CouponData } from './Coupon.js';
6
6
  import { TaxSystem } from './Enum.js';
7
7
  import ChargeModel, { ChargeData } from './Charge.js';
@@ -226,7 +226,48 @@ declare abstract class BaseShoppingContainerModel extends BaseModel {
226
226
  * Gets a defensive copy of the calculated totals for the container.
227
227
  * @returns An object containing shipping, subtotal, coupon, and grand totals.
228
228
  */
229
- getTotal(): ShoppingContainerTotalModel;
229
+ getTotal(): {
230
+ subtotal: PriceModel;
231
+ netSubtotal: PriceModel;
232
+ lineItemTaxTotal: PriceModel;
233
+ lineItemTaxBreakdown: {
234
+ [k: string]: {
235
+ system: TaxSystem;
236
+ totalAmount: PriceModel;
237
+ subSystems: {
238
+ [x: string]: PriceModel;
239
+ };
240
+ };
241
+ };
242
+ chargesTotal: PriceModel;
243
+ shippingCharge: PriceModel;
244
+ netShippingCharge: PriceModel;
245
+ chargeTaxTotal: PriceModel;
246
+ chargeTaxBreakdown: {
247
+ [k: string]: {
248
+ system: TaxSystem;
249
+ totalAmount: PriceModel;
250
+ subSystems: {
251
+ [x: string]: PriceModel;
252
+ };
253
+ };
254
+ };
255
+ taxTotal: PriceModel;
256
+ taxBreakdown: {
257
+ [k: string]: {
258
+ system: TaxSystem;
259
+ totalAmount: PriceModel;
260
+ subSystems: {
261
+ [x: string]: PriceModel;
262
+ };
263
+ };
264
+ };
265
+ discounts: {
266
+ [x: string]: PriceModel;
267
+ };
268
+ totalDiscount: PriceModel;
269
+ grandTotal: PriceModel;
270
+ };
230
271
  /**
231
272
  * Gets a plain data object representing the shopping container's current state.
232
273
  * Includes details from the base model and specific container properties.
@@ -1,2 +1,2 @@
1
- 'use strict';var St=require('crypto');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var St__default=/*#__PURE__*/_interopDefault(St);var B=class{customFields;constructor(t,e=new Date){this.customFields={...t.customFields};}getCustomField(t){return this.customFields[t]??null}setCustomField(t,e){this.customFields[t]=e;}getAllCustomFields(){return {...this.customFields}}},A=class extends B{version;createdAt;modifiedAt;modifiedBy;constructor(t,e=new Date){super(t),this.version=t.version??1,this.createdAt=t.createdAt&&!isNaN(Date.parse(t.createdAt))?new Date(t.createdAt).toISOString():e.toISOString(),this.modifiedAt=t.modifiedAt&&!isNaN(Date.parse(t.modifiedAt))?new Date(t.modifiedAt).toISOString():e.toISOString(),this.modifiedBy={...t.modifiedBy};}getDetails(){return {customFields:this.getAllCustomFields(),version:this.getVersion(),createdAt:this.getCreatedAt(),modifiedAt:this.getModifiedAt(),modifiedBy:this.getModifiedBy()}}getVersion(){return this.version}getCreatedAt(){return this.createdAt}getCreatedAtTime(){return new Date(this.createdAt).getTime()}getModifiedAt(){return this.modifiedAt}getModifiedAtTime(){return new Date(this.modifiedAt).getTime()}getModifiedBy(){return {...this.modifiedBy}}setModifiedBy(t,e,i,r){this.modifiedBy={id:t,authType:e,requestId:i,lambdaName:r};}};var v=class extends A{id;firstName;lastName;company;phone;email;addressLine1;addressLine2;city;postalCode;state;country;isBillingAddress;isShippingAddress;constructor(t,e=new Date){super(t,e),this.id=t.id,this.firstName=t.firstName,this.lastName=t.lastName||"",this.company=t.company||"",this.phone=t.phone,this.email=t.email,this.addressLine1=t.addressLine1,this.addressLine2=t.addressLine2||"",this.city=t.city,this.postalCode=t.postalCode,this.state=t.state,this.country=t.country,this.isBillingAddress=t.isBillingAddress,this.isShippingAddress=t.isShippingAddress;}getDetails(){return {...super.getDetails(),id:this.getId(),firstName:this.getFirstName(),lastName:this.getLastName(),company:this.getCompany(),phone:this.getPhone(),email:this.getEmail(),addressLine1:this.getAddressLine1(),addressLine2:this.getAddressLine2(),city:this.getCity(),postalCode:this.getPostalCode(),state:this.getState(),country:this.getCountry(),isBillingAddress:this.getIsBillingAddress(),isShippingAddress:this.getIsShippingAddress()}}getId(){return this.id}getFirstName(){return this.firstName}getLastName(){return this.lastName}getCompany(){return this.company}getPhone(){return this.phone}getEmail(){return this.email}getAddressLine1(){return this.addressLine1}getAddressLine2(){return this.addressLine2}getCity(){return this.city}getPostalCode(){return this.postalCode}getState(){return this.state}getCountry(){return this.country}getIsBillingAddress(){return this.isBillingAddress}getIsShippingAddress(){return this.isShippingAddress}getAddressType(){return this.isBillingAddress&&this.isShippingAddress?"billing&shipping":this.isBillingAddress?"billing":this.isShippingAddress?"shipping":"none"}static checkIfShippingAddress(t){return t==="shipping"||t==="billing&shipping"}static checkIfBillingAddress(t){return t==="billing"||t==="billing&shipping"}};var H=new Uint8Array(256),K=H.length;function dt(){return K>H.length-16&&(St__default.default.randomFillSync(H),K=0),H.slice(K,K+=16)}var bt=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function Dt(o){return typeof o=="string"&&bt.test(o)}var xt=Dt;var f=[];for(let o=0;o<256;++o)f.push((o+256).toString(16).slice(1));function Q(o,t=0){return f[o[t+0]]+f[o[t+1]]+f[o[t+2]]+f[o[t+3]]+"-"+f[o[t+4]]+f[o[t+5]]+"-"+f[o[t+6]]+f[o[t+7]]+"-"+f[o[t+8]]+f[o[t+9]]+"-"+f[o[t+10]]+f[o[t+11]]+f[o[t+12]]+f[o[t+13]]+f[o[t+14]]+f[o[t+15]]}function At(o){if(!xt(o))throw TypeError("Invalid UUID");let t,e=new Uint8Array(16);return e[0]=(t=parseInt(o.slice(0,8),16))>>>24,e[1]=t>>>16&255,e[2]=t>>>8&255,e[3]=t&255,e[4]=(t=parseInt(o.slice(9,13),16))>>>8,e[5]=t&255,e[6]=(t=parseInt(o.slice(14,18),16))>>>8,e[7]=t&255,e[8]=(t=parseInt(o.slice(19,23),16))>>>8,e[9]=t&255,e[10]=(t=parseInt(o.slice(24,36),16))/1099511627776&255,e[11]=t/4294967296&255,e[12]=t>>>24&255,e[13]=t>>>16&255,e[14]=t>>>8&255,e[15]=t&255,e}var Tt=At;function Mt(o){o=unescape(encodeURIComponent(o));let t=[];for(let e=0;e<o.length;++e)t.push(o.charCodeAt(e));return t}var wt="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Lt="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function gt(o,t,e){function i(r,s,a,u){var l;if(typeof r=="string"&&(r=Mt(r)),typeof s=="string"&&(s=Tt(s)),((l=s)===null||l===void 0?void 0:l.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let c=new Uint8Array(16+r.length);if(c.set(s),c.set(r,s.length),c=e(c),c[6]=c[6]&15|t,c[8]=c[8]&63|128,a){u=u||0;for(let d=0;d<16;++d)a[u+d]=c[d];return a}return Q(c)}try{i.name=o;}catch{}return i.DNS=wt,i.URL=Lt,i}var pt={randomUUID:St__default.default.randomUUID};function Et(o,t,e){if(pt.randomUUID&&!t&&!o)return pt.randomUUID();o=o||{};let i=o.random||(o.rng||dt)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,t){e=e||0;for(let r=0;r<16;++r)t[e+r]=i[r];return t}return Q(i)}var mt=Et;function Bt(o){return Array.isArray(o)?o=Buffer.from(o):typeof o=="string"&&(o=Buffer.from(o,"utf8")),St__default.default.createHash("sha1").update(o).digest()}var ft=Bt;var Nt=gt("v5",80,ft),ht=Nt;var P={"en-IN":"en","kn-IN":"kn"};var Ct={INR:"\u20B9"},It={INR:"en-IN"};var Z=(d=>(d.INITIAL="INITIAL",d.PROCESSING="PROCESSING",d.SHIPPED="SHIPPED",d.DELIVERED="DELIVERED",d.CANCELLED="CANCELLED",d.RETURN_REQUESTED="RETURN_REQUESTED",d.RETURNED="RETURNED",d.REFUND_INITIATED="REFUND_INITIATED",d.REFUNDED="REFUNDED",d.ON_HOLD="ON_HOLD",d))(Z||{});var Y=class extends Error{constructor(t){super(`Invalid line item state: ${t}`),this.name="InvalidLineItemStateError";}},J=class extends Error{constructor(t){super(`Duplicate size found: ${t}`),this.name="DuplicateSizeError";}},W=class extends Error{constructor(t){super(`Duplicate selection attribute found: ${t}`),this.name="DuplicateSelectionAttributeError";}},X=class extends Error{constructor(t="Product and selection attributes do not match."){super(`ProductMismatch: ${t}`),this.name="ProductMismatchError";}},_=class extends Error{constructor(t="Product is not active."){super(`ProductInactive: ${t}`),this.name="ProductInactiveError";}},M=class extends Error{constructor(t="Failed to parse selection attributes key."){super(`SelectionAttributeParseError: ${t}`),this.name="SelectionAttributeParseError";}},tt=class extends Error{constructor(t="Size does not match."){super(`SizeMismatch: ${t}`),this.name="SizeMismatchError";}},et=class extends Error{constructor(t="Pricing details not available for the product"){super(`NotFound: ${t}`),this.name="PricingNotFoundError";}},N=class extends Error{constructor(t="Tax rule category mismatch."){super(`InvalidTaxRule: ${t}`),this.name="InvalidTaxRuleError";}},it=class extends Error{constructor(t="Tax category is not valid."){super(`InvalidTaxCategory: ${t}`),this.name="InvalidTaxCategoryError";}},rt=class extends Error{constructor(t="Minimum quantity must be greater than zero."){super(`InvalidMinQuantity: ${t}`),this.name="InvalidMinQuantityError";}},ot=class extends Error{constructor(t){super(`InvalidTieredPrice: ${t}`),this.name="InvalidTieredPriceError";}},st=class extends Error{constructor(t="Quantity must be greater than zero."){super(`InvalidQuantity: ${t}`),this.name="InvalidQuantityError";}},nt=class extends Error{constructor(t){super(`NoApplicableTier: Quantity ${t} does not meet the minimum purchase requirement.`),this.name="NoApplicableTierError";}},at=class extends Error{constructor(t="No applicable tax slab or multiple slabs found for the given unit price."){super(`TaxSlabNotFound: ${t}`),this.name="TaxSlabNotFoundError";}},$=class extends Error{constructor(t="Amount cannot be negative."){super(`InvalidAmount: ${t}`),this.name="InvalidPriceAmountError";}},U=class extends Error{constructor(t="Currency code is required."){super(`InvalidCurrency: ${t}`),this.name="InvalidCurrencyCodeError";}},w=class extends Error{constructor(t="Cannot perform operation on prices with different currencies."){super(`CurrencyMismatch: ${t}`),this.name="CurrencyMismatchError";}},C=class extends Error{constructor(t){super(`InvalidArgument: ${t}`),this.name="InvalidArgumentError";}},j=class extends Error{constructor(t="Invalid image source configuration."){super(`InvalidImageSource: ${t}`),this.name="InvalidImageSourceError";}};var L=class{sources;alt;order;label;constructor(t){if(this.sources={...t.sources},this.alt=t.alt,this.order=t.order,this.label=t.label,!this.sources.original)throw new j("ImageInfoModel cannot be created without an 'original' source URL.")}getSources(){return {...this.sources}}getSource(t){return this.sources[t]||this.sources.original}getAlt(){return this.alt}getOrder(){return this.order}getLabel(){return this.label}setAlt(t){this.alt=t;}setOrder(t){this.order=t;}setLabel(t){this.label=t;}setSource(t,e){if(e===void 0){if(t==="original")throw new j("Cannot remove the 'original' image source.");delete this.sources[t];}else this.sources[t]=e;}getDetails(){return {sources:this.getSources(),alt:this.getAlt(),order:this.getOrder(),label:this.getLabel()}}};var n=class o{#t;amount;currency;constructor(t){if(this.#t="PriceModel",t.amount<0)throw new $("Amount cannot be negative.");if(!t.currency)throw new U("Currency code is required.");this.amount=t.amount,this.currency=t.currency;}get kind(){return this.#t}static isPriceModel(t){return typeof t=="object"&&t!==null&&t.kind==="PriceModel"}getCurrency(){return this.currency}getAmount(){return this.amount}getDetails(){return {amount:this.amount,currency:this.currency}}compareTo(t){if(o.isPriceModel(t)){if(this.currency!==t.getCurrency())throw new w("Cannot compare prices in different currencies.")}else throw new C("Must be a PriceModel instance.");return this.amount-t.getAmount()}add(t){if(o.isPriceModel(t)){if(this.currency!==t.getCurrency())throw new w("Cannot add prices in different currencies.")}else throw new C("Must be a PriceModel instance.");return new o({amount:this.amount+t.getAmount(),currency:this.currency})}subtract(t){if(o.isPriceModel(t)){if(this.currency!==t.getCurrency())throw new w("Cannot subtract prices in different currencies.")}else throw new C("Must be a PriceModel instance.");return new o({amount:this.amount-t.getAmount(),currency:this.currency})}multiply(t){if(o.isPriceModel(t)){if(this.currency!==t.getCurrency())throw new w("Cannot multiply prices in different currencies.");return new o({amount:this.amount*t.getAmount(),currency:this.currency})}else if(typeof t=="number"&&t>=0)return new o({amount:this.amount*t,currency:this.currency});throw new C("Must be a non-negative number.")}divide(t){if(o.isPriceModel(t)){if(this.currency!==t.getCurrency())throw new w("Cannot divide prices in different currencies.");return new o({amount:this.amount/t.getAmount(),currency:this.currency})}else if(typeof t=="number"&&t>0)return new o({amount:this.amount/t,currency:this.currency});throw new C("Must be a positive number.")}min(...t){if(t.length===0)throw new C("Must provide at least one PriceModel.");return t.reduce((e,i)=>{if(o.isPriceModel(i)){if(e.getCurrency()!==i.getCurrency())throw new w("Cannot compare prices in different currencies.")}else throw new C("Must be a PriceModel instance.");return e.compareTo(i)<0?e:i},this)}max(...t){if(t.length===0)throw new C("Must provide at least one PriceModel.");return t.reduce((e,i)=>{if(o.isPriceModel(i)){if(e.getCurrency()!==i.getCurrency())throw new w("Cannot compare prices in different currencies.")}else throw new C("Must be a PriceModel instance.");return e.compareTo(i)>0?e:i},this)}zero(){return new o({currency:this.currency,amount:0})}isZero(){return this.amount===0}round(){return new o({currency:this.currency,amount:this.getRoundedAmount()})}getRoundedAmount(){return o.getRoundedAmount(this.amount,this.currency)}getFormattedString(){return o.getFormattedString(this.amount,this.currency)}toString(){return this.getFormattedString()}static getFormattedString(t,e,i={displayAsInteger:!1,style:"currency",currencyDisplay:"symbol"}){let r=It[e];if(!e||!r)throw new U("Invalid currency code for formatting.");let s=t,a=i.displayAsInteger?0:o.getDecimalPlaces(e),u={style:i.style??"currency",currency:e,signDisplay:"never",currencyDisplay:i.currencyDisplay,minimumFractionDigits:a,maximumFractionDigits:a};i.displayAsInteger&&(s=Math.ceil(s));try{return new Intl.NumberFormat(r,u).format(s)}catch(l){return console.error(`Error formatting price for currency "${e}" and locale "${r}":`,l),`${Ct[e]??e} ${o.addThousandSeparators(s.toFixed(a))}`}}static getDecimalPlaces(t){switch(t){case"INR":default:return 2}}static addThousandSeparators(t){let e=t.split("."),i=e[0],r=e.length>1?"."+e[1]:"";return i.replace(/\B(?=(\d{3})+(?!\d))/g,",")+r}static getRoundedAmount(t,e){if(t<0)throw new $("Amount cannot be negative for rounding.");if(e===void 0)throw new U("Invalid currency code for rounding.");let i=o.getDecimalPlaces(e),r=Math.pow(10,i);return Math.round(t*r)/r}};var O=class{baseUnitPrice;taxCategory;tiers;constructor(t){let e=new n(t.baseUnitPrice);if(!t.taxCategory)throw new it;let i=(t.tiers??[]).map(l=>({minQuantity:l.minQuantity,unitPrice:new n(l.unitPrice)})).sort((l,c)=>l.minQuantity-c.minQuantity);if(i.some(l=>l.minQuantity<=0))throw new rt;let s=i.some(l=>l.unitPrice.getCurrency()!==e.getCurrency()),a=i.some((l,c)=>c>0&&l.unitPrice.compareTo(i[c-1].unitPrice)>0),u=i[0]?.unitPrice.compareTo(e)>0;if(s||a||u)throw new ot("Tiers must share the same currency and must not increase in unit price.");this.baseUnitPrice=e,this.taxCategory=t.taxCategory,this.tiers=i;}getBaseUnitPrice(){return this.baseUnitPrice}getTaxCategory(){return this.taxCategory}getTiers(){return this.tiers}getDetails(){return {baseUnitPrice:this.baseUnitPrice.getDetails(),taxCategory:this.taxCategory,tiers:this.tiers.map(t=>({minQuantity:t.minQuantity,unitPrice:t.unitPrice.getDetails()}))}}getApplicableTier(t){if(t<=0)throw new st;for(let e=this.tiers.length-1;e>=0;e--)if(t>=this.tiers[e].minQuantity)return this.tiers[e];throw new nt(t)}getMinQuantity(){return this.tiers[0]?.minQuantity??1}getMaxDiscountPercent(){if(!this.tiers.length)return 0;let t=this.tiers[this.tiers.length-1].unitPrice.getAmount(),e=this.baseUnitPrice.getAmount();return (e-t)/e*100}};var k=class o extends A{id;key;name;description;slug;brand;pricing;variants;targetGender;attributes;specifications;categories;isActive;searchTags;static productKeyRegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static productSKURegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static generateSelectionAttributesKey(t){if(typeof t!="object")throw new M("Selection attributes must be an object");return Object.keys(t).filter(i=>t[i]!==void 0&&i.toLowerCase()!=="size").sort().map(i=>t[i].name?`${i}:c+${t[i].name}`:`${i}:${t[i]}`).join("|").toLowerCase()}static parseSelectionAttributesKey(t){try{let e={},i=t.split("|");for(let r of i){let[s,a]=r.split(":");a.startsWith("c+")?e[s]={name:a.slice(2)}:e[s]=a;}return e}catch(e){throw new M(e?.message)}}constructor(t,e=new Date){super(t,e),this.id=t.id,this.key=t.key,this.name={...t.name},this.description={...t.description},this.slug={...t.slug},this.brand=t.brand,this.pricing=Object.keys(t.pricing).reduce((r,s)=>(t.pricing[s]&&(r[s]=new O(t.pricing[s])),r),{}),this.targetGender=t.targetGender,this.attributes=g.deepClone(t.attributes),this.specifications=g.deepClone(t.specifications),this.categories=g.deepClone(t.categories);let i=new Set;this.variants=(t.variants||[]).map(r=>{if(!r.selectionAttributes||typeof r.selectionAttributes!="object")throw new M("Selection attributes are required");this.checkSelectionAttributes(r.selectionAttributes);let s=o.generateSelectionAttributesKey(r.selectionAttributes);if(i.has(s))throw new W(s);return i.add(s),{sku:r.sku,selectionAttributes:r.selectionAttributes,images:{primary:new L(r.images.primary),gallery:(r.images.gallery||[]).map(a=>new L(a))}}}),this.isActive=t.isActive,this.searchTags=t.searchTags?g.deepClone(t.searchTags):{en:[]};}getId(){return this.id}getKey(){return this.key}getName(t){return t?this.name[t]??this.name[P[t]]??this.name.en:g.deepClone(this.name)}getDescription(t){return t?this.description[t]??this.description[P[t]]??this.description.en:g.deepClone(this.description)}getSlug(t){return t?this.slug[t]??this.slug[P[t]]??this.slug.en:g.deepClone(this.slug)}getBrand(){return this.brand}getPriceDetails(t){return t?this.pricing[t]??null:this.pricing}getAttributes(){return g.deepClone(this.attributes)}getVariants(){return this.variants.map(t=>({sku:t.sku,selectionAttributes:t.selectionAttributes,images:{primary:t.images.primary,gallery:t.images.gallery}}))}getImagesBySelectionAttributes(t){let e=o.generateSelectionAttributesKey(t),i=this.variants.find(r=>o.generateSelectionAttributesKey(r.selectionAttributes)===e);return i?i.images:null}getImages(t,e){switch(e){case"PRIMARY":return this.getImagesBySelectionAttributes(t)?.primary??this.variants[0]?.images?.primary;case"GALLERY":return this.getImagesBySelectionAttributes(t)?.gallery??[];default:return this.getImagesBySelectionAttributes(t)??{primary:this.variants[0]?.images?.primary,gallery:[]}}}getIsActive(){return this.isActive}getTargetGender(){return this.targetGender}getCategories(){return g.deepClone(this.categories)}getSpecifications(t){return t?g.deepClone(this.specifications[t]??this.specifications[P[t]]??this.specifications.en):g.deepClone(this.specifications)}getSearchTags(t){return t?g.deepClone(this.searchTags[t]??this.searchTags[P[t]]??this.searchTags.en):g.deepClone(this.searchTags)}getDetails(){let t=super.getDetails();return {id:this.getId(),key:this.getKey(),name:this.getName(),description:this.getDescription(),slug:this.getSlug(),brand:this.getBrand(),pricing:Object.keys(this.pricing).reduce((e,i)=>(this.pricing[i]&&(e[i]=this.pricing[i]?.getDetails()),e),{}),attributes:this.getAttributes(),variants:this.variants.map(e=>({sku:e.sku,selectionAttributes:g.deepClone(e.selectionAttributes),images:{primary:e.images.primary.getDetails(),gallery:e.images.gallery.map(i=>i.getDetails())}})),isActive:this.getIsActive(),targetGender:this.getTargetGender(),categories:this.getCategories(),specifications:this.getSpecifications(),searchTags:this.getSearchTags(),...t}}checkSelectionAttributes(t){if(!t||typeof t!="object")throw new M("Selection attributes are required");Object.keys(this.attributes).forEach(e=>{if(e.toLowerCase()==="size")return;let i=this.attributes[e],r=t[e];if(r===void 0)throw new M(`Selection attribute '${e}' is missing`);if(typeof i=="string"){if(typeof r!="string"||i!==r)throw new M(`Selection attribute '${e}' is invalid`)}else if(Array.isArray(i)){if(i.length>0&&typeof i[0]=="string"){if(typeof r!="string"||!i.includes(r))throw new M(`Selection attribute '${e}' is invalid`)}else if(typeof r!="object"||!("name"in r)||i.findIndex(s=>s.name===r.name)<0)throw new M(`Selection attribute '${e}' is invalid`)}});}validateSelectionAttribute(t){let e=o.generateSelectionAttributesKey(t);return this.variants.some(i=>o.generateSelectionAttributesKey(i.selectionAttributes)===e)}validateSize(t){return this.attributes.size.includes(t)}};var Ut={isUUID:o=>/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(o),isEmail:o=>/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(o),isURL:o=>/^(http|https):\/\/[^ "]+$/.test(o),generateUUID:(o,t)=>t&&o?ht(o,t):mt(),generateSearchId:(o,t)=>`${o}#${k.generateSelectionAttributesKey(t)}`,getKeyfromSearchId:o=>{let[t,e]=o.split("#");return {key:t,selectionAttributes:k.parseSelectionAttributesKey(e)}},deepClone(o){return structuredClone(o)}},g=Ut;var ct=class{taxRuleId;taxCategory;taxSystem;taxSubSystem;taxCountry;effectiveFrom;effectiveTo;constructor(t){this.taxRuleId=t.taxRuleId,this.taxSystem=t.taxSystem,this.taxSubSystem=t.taxSubSystem,this.taxCategory=t.taxCategory,this.taxCountry=t.taxCountry,this.effectiveFrom=new Date(t.effectiveFrom).toISOString(),this.effectiveTo=t.effectiveTo?new Date(t.effectiveTo).toISOString():void 0;}getTaxRuleId(){return this.taxRuleId}getTaxSystem(){return this.taxSystem}getTaxSubSystem(){return this.taxSubSystem}getTaxCategory(){return this.taxCategory}getTaxCountry(){return this.taxCountry}getEffectiveFrom(){return this.effectiveFrom}getEffectiveTo(){return this.effectiveTo}getDetails(){return {taxRuleId:this.getTaxRuleId(),taxSystem:this.getTaxSystem(),taxSubSystem:this.getTaxSubSystem(),taxCategory:this.getTaxCategory(),taxCountry:this.getTaxCountry(),effectiveFrom:this.effectiveFrom,effectiveTo:this.effectiveTo?this.effectiveTo:void 0}}appliesTo(t,e,i=new Date){return this.taxCategory===t&&this.taxCountry===e&&Date.parse(this.effectiveFrom)<=i.getTime()&&(this.effectiveTo?Date.parse(this.effectiveTo)>=i.getTime():!0)}static getTaxRateDisplayString(t,e,i){let r=e*100,s=r%1===0?r.toString():r.toFixed(2).replace(/\.?0+$/,"");return i?.percentageOnly?`${s}%`:t.getTaxSystem()==="GST"?`${t.getTaxSubSystem()} ${s}%`:`${t.getTaxSystem()} ${s}%`}},lt=class o extends ct{slabs;constructor(t){super(t),this.slabs=t.slabs.map(e=>({rate:e.rate,minUnitPrice:new n(e.minUnitPrice),maxUnitPrice:e.maxUnitPrice?new n(e.maxUnitPrice):void 0}));}getSlabs(){return this.slabs}getDetails(){return {...super.getDetails(),slabs:this.getSlabs().map(t=>({rate:t.rate,minUnitPrice:t.minUnitPrice.getDetails(),maxUnitPrice:t.maxUnitPrice?t.maxUnitPrice.getDetails():void 0}))}}getApplicableTaxRate(t){return o.getApplicableTaxRate(t,this.slabs)}calculateTax(t){let e=this.getApplicableTaxRate(t);return t.multiply(e)}static getApplicableTaxRate(t,e){let i=e.filter(r=>(r.minUnitPrice===void 0||t.compareTo(r.minUnitPrice)>=0)&&(r.maxUnitPrice===void 0||t.compareTo(r.maxUnitPrice)<0));if(i.length!==1)throw new at;return i[0].rate}},ut=class extends ct{rate;constructor(t){super(t),this.rate=t.rate;}getApplicableTaxRate(){return this.rate}calculateTax(t){let e=this.getApplicableTaxRate();return t.multiply(e)}getDetails(){return {...super.getDetails(),rate:this.getApplicableTaxRate()}}};var F=class extends B{id;productKey;selectionAttributes;name;specifications;primaryImage;subItems;pricing;state;total;constructor(t){super(t),this.id=t.id,this.productKey=t.productKey,this.selectionAttributes=g.deepClone(t.selectionAttributes),this.name=g.deepClone(t.name),this.specifications=g.deepClone(t.specifications),this.primaryImage=new L(t.primaryImage),this.subItems=g.deepClone(t.subItems);let e=new Set;this.subItems.forEach(i=>{if(e.has(i.size))throw new J(i.size);e.add(i.size);}),this.pricing={unitPrice:new n(t.pricing.unitPrice),tierPricing:new O(t.pricing.tierPricing),taxCategory:t.pricing.taxCategory,applicableTaxRule:t.pricing.applicableTaxRule.map(i=>new lt(i))},this.state=t.state??"INITIAL",this.total={quantity:t.total.quantity,unitPrice:new n(t.total.unitPrice),subtotal:new n(t.total.subtotal),discounts:Object.fromEntries(Object.entries(t.total.discounts).map(([i,r])=>[i,new n(r)])),totalDiscount:new n(t.total.totalDiscount),netUnitPrice:new n(t.total.netUnitPrice),netSubtotal:new n(t.total.netSubtotal),taxBreakdown:Object.fromEntries(Object.entries(t.total.taxBreakdown).map(([i,r])=>[i,{rate:r.rate,taxableUnitPrice:new n(r.taxableUnitPrice),taxPerUnit:new n(r.taxPerUnit),amount:new n(r.amount),system:r.system,subSystem:r.subSystem}])),taxTotal:new n(t.total.taxTotal),grandTotal:new n(t.total.grandTotal)};}getId(){return this.id}getProductKey(){return this.productKey}getSelectionAttributes(){return g.deepClone(this.selectionAttributes)}getName(t){return t?g.deepClone(this.name[t]??this.name[P[t]]??this.name.en):g.deepClone(this.name)}getSpecifications(t){return t?g.deepClone(this.specifications[t]??this.specifications[P[t]]??this.specifications.en):g.deepClone(this.specifications)}getImage(){return this.primaryImage}getSubItems(){return g.deepClone(this.subItems)}getTotalQuantity(){return this.total.quantity}getPricing(){return {unitPrice:this.pricing.unitPrice,tierPricing:this.pricing.tierPricing,taxCategory:this.pricing.taxCategory,applicableTaxRule:this.pricing.applicableTaxRule}}getState(){return this.state}getTotal(){return {quantity:this.total.quantity,unitPrice:this.total.unitPrice,subtotal:this.total.subtotal,discounts:Object.fromEntries(Object.entries(this.total.discounts).map(([t,e])=>[t,e])),totalDiscount:this.total.totalDiscount,netUnitPrice:this.total.netUnitPrice,netSubtotal:this.total.netSubtotal,taxBreakdown:this.total.taxBreakdown,taxTotal:this.total.taxTotal,grandTotal:this.total.grandTotal}}getDetails(){let t=this.getPricing(),e=this.getTotal();return {id:this.getId(),productKey:this.getProductKey(),selectionAttributes:this.getSelectionAttributes(),name:this.getName(),specifications:this.getSpecifications(),primaryImage:this.getImage().getDetails(),subItems:this.getSubItems(),pricing:{unitPrice:t.unitPrice.getDetails(),tierPricing:t.tierPricing.getDetails(),taxCategory:t.taxCategory,applicableTaxRule:t.applicableTaxRule.map(i=>i.getDetails())},state:this.getState(),total:{quantity:e.quantity,unitPrice:e.unitPrice.getDetails(),subtotal:e.subtotal.getDetails(),discounts:Object.fromEntries(Object.entries(e.discounts).map(([i,r])=>[i,r.getDetails()])),totalDiscount:e.totalDiscount.getDetails(),netUnitPrice:e.netUnitPrice.getDetails(),netSubtotal:e.netSubtotal.getDetails(),taxBreakdown:Object.fromEntries(Object.entries(e.taxBreakdown).map(([i,r])=>[i,{rate:r.rate,taxableUnitPrice:r.taxableUnitPrice.getDetails(),taxPerUnit:r.taxPerUnit.getDetails(),amount:r.amount.getDetails(),system:r.system,subSystem:r.subSystem}])),taxTotal:e.taxTotal.getDetails(),grandTotal:e.grandTotal.getDetails()},customFields:this.getAllCustomFields()}}addSubItems(t,e){t.forEach(i=>{let r=this.subItems.find(s=>s.size===i.size);r?r.quantity=e?r.quantity+i.quantity:i.quantity:this.subItems.push(i);}),this.subItems=this.subItems.filter(i=>i.quantity>0),this.calculateTotals();}updateProductData(t,e,i){if(this.productKey!==t.getKey()||!t.validateSelectionAttribute(this.selectionAttributes))throw new X;if(!t.getIsActive())throw new _;this.subItems.forEach(u=>{if(!t.validateSize(u.size))throw new tt});let r=t.getPriceDetails(e);if(!r||r.getBaseUnitPrice().getCurrency()!==i)throw new et;this.name=t.getName(),this.specifications=t.getSpecifications(),this.primaryImage=t.getImages(this.selectionAttributes).primary;let s=this.subItems.reduce((u,l)=>u+l.quantity,0),{unitPrice:a}=r.getApplicableTier(s);this.pricing={unitPrice:a,tierPricing:r,taxCategory:r.getTaxCategory(),applicableTaxRule:this.pricing.applicableTaxRule},this.calculateTotals();}updateDiscounts(t){let e={};t.forEach(i=>{e[i.coupon.getCode()]=i.amount;}),this.total.discounts=e,this.calculateTotals();}updateTax(t){t.forEach(e=>{if(!e.appliesTo(this.pricing.taxCategory,e.getTaxCountry()))throw new N}),this.pricing.applicableTaxRule=t,this.calculateTotals();}calculateTotals(){let t=this.pricing.unitPrice.zero(),e=this.subItems.reduce((h,x)=>h+x.quantity,0);if(this.state==="CANCELLED"){this.total={quantity:0,unitPrice:t,subtotal:t,discounts:{},totalDiscount:t,netUnitPrice:t,netSubtotal:t,taxBreakdown:{},taxTotal:t,grandTotal:t};return}let{unitPrice:i}=this.pricing.tierPricing.getApplicableTier(e),r=i.multiply(e),s=Object.values(this.total.discounts).reduce((h,x)=>h.add(x),t),a=r.subtract(s),u=e>0?a.divide(e):t,l={},c=t;this.pricing.applicableTaxRule.forEach(h=>{let x=h.getApplicableTaxRate(u),S=h.calculateTax(u),D=S.multiply(e).round();l[h.getTaxRuleId()]={rate:x,taxableUnitPrice:u,taxPerUnit:S,amount:D,system:h.getTaxSystem(),subSystem:h.getTaxSubSystem()},c=c.add(D);});let d=a.add(c);this.total={quantity:e,unitPrice:i,subtotal:r,discounts:this.total.discounts,totalDiscount:s,netUnitPrice:u,netSubtotal:a,taxBreakdown:l,taxTotal:c,grandTotal:d};}updateState(t){if(this.state in Z)this.state!==t&&(this.state=t);else throw new Y(t)}clearLineItem(){let t=this.pricing.unitPrice.zero();this.id="",this.productKey="",this.selectionAttributes={color:{name:""}},this.name={en:""},this.primaryImage=new L({sources:{original:""}}),this.subItems=[],this.pricing={unitPrice:t,tierPricing:this.pricing.tierPricing,taxCategory:this.pricing.taxCategory,applicableTaxRule:[]},this.total={quantity:0,unitPrice:t,subtotal:t,discounts:{},totalDiscount:t,netUnitPrice:t,netSubtotal:t,taxBreakdown:{},taxTotal:t,grandTotal:t};}};var G=class extends A{couponCode;name;description;type;customerId;validFrom;validTo;minCartValue;maxCartDiscount;discountMethod;percentageValue;applicableTo;category;constructor(t,e=new Date){if(super(t,e),this.couponCode=t.couponCode,this.name=g.deepClone(t.name),this.description=g.deepClone(t.description),this.type=t.type,this.customerId=t.customerId,this.validFrom=t.validFrom&&Date.parse(t.validFrom)?new Date(t.validFrom).toISOString():e.toISOString(),this.validTo=t.validTo&&Date.parse(t.validTo)?new Date(t.validTo).toISOString():e.toISOString(),this.minCartValue=Object.keys(t.minCartValue).reduce((i,r)=>{let s=t.minCartValue[r];return s&&(i[r]=new n(s)),i},{}),this.maxCartDiscount=Object.keys(t.maxCartDiscount).reduce((i,r)=>{let s=t.maxCartDiscount[r];return s&&(i[r]=new n(s)),i},{}),this.discountMethod=t.discountMethod,this.percentageValue=t.percentageValue??0,this.percentageValue>100)throw new C("Percentage value cannot be greater than 100");this.applicableTo=t.applicableTo,this.category=t.category;}getCode(){return this.couponCode}getName(t){return t?this.name[t]??this.name[P[t]]??this.name.en:{...this.name}}getDescription(t){return t?this.description[t]??this.description[P[t]]??this.description.en:{...this.description}}getType(){return this.type}getCustomerId(){return this.customerId??""}getValidFrom(){return this.validFrom}getValidTo(){return this.validTo}getMinCartValue(t){return t?this.minCartValue[t]:this.minCartValue}getMaxCartDiscount(t){return t?this.maxCartDiscount[t]:this.maxCartDiscount}getDiscountMethod(){return this.discountMethod}getPercentageValue(){return this.percentageValue}getApplicableTo(){return this.applicableTo}getCategory(){return this.category}getDetails(){return {...super.getDetails(),couponCode:this.getCode(),name:this.getName(),description:this.getDescription(),type:this.getType(),customerId:this.getCustomerId(),validFrom:this.getValidFrom(),validTo:this.getValidTo(),minCartValue:Object.keys(this.getMinCartValue()).reduce((t,e)=>{let i=this.getMinCartValue(e);return i&&(t[e]=i.getDetails()),t},{}),maxCartDiscount:Object.keys(this.getMaxCartDiscount()).reduce((t,e)=>{let i=this.getMaxCartDiscount(e);return i&&(t[e]=i.getDetails()),t},{}),discountMethod:this.getDiscountMethod(),percentageValue:this.getPercentageValue(),applicableTo:this.getApplicableTo(),category:this.getCategory()}}isActive(){return new Date(this.validFrom)<=new Date&&new Date(this.validTo)>=new Date}isApplicableTo(t){return this.applicableTo==="all"||this.applicableTo==="ftb"&&t}calculateApplicableCouponDiscount(t,e,i,r,s=!0){let a=new n({amount:0,currency:r}),u;if(s&&!this.isActive())return a;let l=this.getMinCartValue(i),c=this.getMaxCartDiscount(i);if(!l||l.compareTo(t)>0||!c)return a;let d=this.getCategory(),h=this.getDiscountMethod(),x=d==="SHIPPING"?e:t;if(x.getAmount()<=0)return a;switch(h){case"flat":let D=c;u=x.min(D);break;case"percentage":u=x.multiply(this.getPercentageValue()/100).round();break;default:return a}return u.min(c)}};var z=class extends B{id;name;category;lineItemId;chargeType;pricing;total;constructor(t){super(t),this.id=t.id,this.name=t.name,this.category=t.category,this.lineItemId=t.lineItemId,this.chargeType=t.chargeType,this.pricing={price:new n(t.pricing.price),taxCategory:t.pricing.taxCategory,applicableTaxRule:t.pricing.applicableTaxRule.map(e=>new ut(e))},this.total={price:new n(t.total.price),discounts:Object.fromEntries(Object.entries(t.total.discounts).map(([e,i])=>[e,new n(i)])),totalDiscount:new n(t.total.totalDiscount),netPrice:new n(t.total.netPrice),taxBreakdown:Object.fromEntries(Object.entries(t.total.taxBreakdown).map(([e,i])=>[e,{rate:i.rate,taxablePrice:new n(i.taxablePrice),amount:new n(i.amount),system:i.system,subSystem:i.subSystem}])),taxTotal:new n(t.total.taxTotal),grandTotal:new n(t.total.grandTotal)};}getId(){return this.id}getName(){return this.name}getCategory(){return this.category}getChargeType(){return this.chargeType}getLineItemId(){return this.lineItemId}getPricing(){return this.pricing}getTotal(){return this.total}getApplicableTaxRules(){return this.pricing.applicableTaxRule}updateTax(t){t.forEach(e=>{if(!e.appliesTo(this.pricing.taxCategory,e.getTaxCountry()))throw new N}),this.pricing.applicableTaxRule=t,this.calculateTotals();}updateDiscounts(t){let e={};t.forEach(i=>{e[i.coupon.getCode()]=i.amount;}),this.total.discounts=e,this.calculateTotals();}calculateTotals(){let t=this.pricing.price.zero(),e=this.pricing.price,i=Object.values(this.total.discounts).reduce((y,I)=>y.add(I),t),r=e.subtract(i),s={},a=this.pricing.applicableTaxRule.reduce((y,I)=>y+I.getApplicableTaxRate(),0),u=r.divide(1+a).round(),l=a>0?r.subtract(u):t,c=t,d=this.pricing.applicableTaxRule.reduce((y,I)=>I.getApplicableTaxRate()>y.getApplicableTaxRate()?I:y),h=d.getTaxRuleId();this.pricing.applicableTaxRule.forEach(y=>{if(y.getTaxRuleId()===h)return;let I=y.getApplicableTaxRate(),V=a>0?l.multiply(I).divide(a).round():t;s[y.getTaxRuleId()]={rate:I,taxablePrice:u,amount:V,system:y.getTaxSystem(),subSystem:y.getTaxSubSystem()},c=c.add(V);});let x=l.subtract(c);s[h]={rate:d.getApplicableTaxRate(),taxablePrice:u,amount:x,system:d.getTaxSystem(),subSystem:d.getTaxSubSystem()};let S=u,D=r;this.total={price:e,discounts:this.total.discounts,netPrice:S,totalDiscount:i,taxBreakdown:s,taxTotal:l,grandTotal:D};}getDetails(){return {id:this.id,name:g.deepClone(this.name),category:this.category,lineItemId:this.lineItemId,chargeType:this.chargeType,pricing:{price:this.pricing.price.getDetails(),taxCategory:this.pricing.taxCategory,applicableTaxRule:this.pricing.applicableTaxRule.map(e=>e.getDetails())},total:{price:this.total.price.getDetails(),discounts:Object.fromEntries(Object.entries(this.total.discounts).map(([e,i])=>[e,i.getDetails()])),totalDiscount:this.total.totalDiscount.getDetails(),netPrice:this.total.netPrice.getDetails(),taxBreakdown:Object.fromEntries(Object.entries(this.total.taxBreakdown).map(([e,i])=>[e,{rate:i.rate,taxablePrice:i.taxablePrice.getDetails(),amount:i.amount.getDetails(),system:i.system,subSystem:i.subSystem}])),taxTotal:this.total.taxTotal.getDetails(),grandTotal:this.total.grandTotal.getDetails()},customFields:this.getAllCustomFields()}}};var yt=class extends A{id;customerId;customerEmail;anonymousId;lineItems;charges;shippingDetails;shippingAddress;billingAddress;coupons;total;country;currency;locale;constructor(t,e=new Date){super(t,e),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 F(i)),this.charges=(t.charges??[]).map(i=>new z(i)),this.billingAddress=t.billingAddress?new v(t.billingAddress,e):null,this.shippingAddress=t.shippingAddress?new v(t.shippingAddress,e):null,this.coupons=(t.coupons??[]).map(i=>new G(i)),this.shippingDetails=t.shippingDetails?g.deepClone(t.shippingDetails):null,this.total={subtotal:new n(t.total.subtotal),netSubtotal:new n(t.total.netSubtotal),lineItemTaxTotal:new n(t.total.lineItemTaxTotal||{amount:0,currency:t.currency}),lineItemTaxBreakdown:this.mapTaxBreakdown(t.total.lineItemTaxBreakdown||{}),chargesTotal:new n(t.total.chargesTotal||{amount:0,currency:t.currency}),shippingCharge:new n(t.total.shippingCharge),netShippingCharge:new n(t.total.netShippingCharge),chargeTaxTotal:new n(t.total.chargeTaxTotal||{amount:0,currency:t.currency}),chargeTaxBreakdown:this.mapTaxBreakdown(t.total.chargeTaxBreakdown||{}),taxTotal:new n(t.total.taxTotal),taxBreakdown:this.mapTaxBreakdown(t.total.taxBreakdown),discounts:Object.fromEntries(Object.entries(t.total.discounts).map(([i,r])=>[i,new n(r)])),totalDiscount:new n(t.total.totalDiscount),grandTotal:new n(t.total.grandTotal)};}mapTaxBreakdown(t){return Object.fromEntries(Object.entries(t||{}).map(([e,i])=>[e,{system:i.system,totalAmount:new n(i.totalAmount),subSystems:Object.fromEntries(Object.entries(i.subSystems).map(([r,s])=>[r,new n(s)]))}]))}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(([r,s])=>[r,s.getDetails()]))}]))}getId(){return this.id}getCustomerId(){return this.customerId}getCustomerEmail(){return this.customerEmail}getAnonymousId(){return this.anonymousId}getLineItems(){return this.lineItems.map(t=>new F(t.getDetails()))}getLineItemsCount(){return this.lineItems.length}getCharges(){return this.charges.map(t=>new z(t.getDetails()))}addCharge(t){this.charges.push(t),this.calculateTotals();}clearCharges(){this.charges=[],this.calculateTotals();}getShippingDetails(){return this.shippingDetails?{...this.shippingDetails}:null}getShippingAddress(){return this.shippingAddress?new v(this.shippingAddress.getDetails()):null}hasShippingAddress(){return !!this.shippingAddress}hasBillingAddress(){return !!this.billingAddress}getBillingAddress(){return this.billingAddress?new v(this.billingAddress.getDetails()):null}getCoupons(){return this.coupons}getCountry(){return this.country}getCurrency(){return this.currency}getLocale(){return this.locale}getTotal(){return this.total}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:{subtotal:t.subtotal.getDetails(),netSubtotal:t.netSubtotal.getDetails(),lineItemTaxTotal:t.lineItemTaxTotal.getDetails(),lineItemTaxBreakdown:this.serializeTaxBreakdown(t.lineItemTaxBreakdown),chargesTotal:t.chargesTotal.getDetails(),shippingCharge:t.shippingCharge.getDetails(),netShippingCharge:t.netShippingCharge.getDetails(),chargeTaxTotal:t.chargeTaxTotal.getDetails(),chargeTaxBreakdown:this.serializeTaxBreakdown(t.chargeTaxBreakdown),taxTotal:t.taxTotal.getDetails(),taxBreakdown:this.serializeTaxBreakdown(t.taxBreakdown),discounts:Object.fromEntries(Object.entries(t.discounts).map(([e,i])=>[e,i.getDetails()])),totalDiscount:t.totalDiscount.getDetails(),grandTotal:t.grandTotal.getDetails()},country:this.getCountry(),currency:this.getCurrency(),locale:this.getLocale()}}calculateTotals(){let t=new n({amount:0,currency:this.currency}),e=this.lineItems.filter(p=>p.getState()!=="CANCELLED"),i=e.reduce((p,m)=>p.add(m.getTotal().subtotal),t),r=e.reduce((p,m)=>p.add(m.getTotal().netSubtotal),t),s=this.charges.filter(p=>p.getChargeType()==="SHIPPING").reduce((p,m)=>p.add(m.getTotal().price),t),a=t,u={},l={};this.coupons.forEach(p=>{let m=p.calculateApplicableCouponDiscount(i,s,this.country,this.currency);a=a.add(m),u[p.getCode()]=m,p.getCategory()!=="SHIPPING"&&(l[p.getCode()]=m);}),this.applyDiscountsInLineItem(l);let c=this.coupons.find(p=>p.getCategory()==="SHIPPING");c?this.applyDiscuountsInShippingCharges({[c.getCode()]:u[c.getCode()]||t}):this.applyDiscuountsInShippingCharges({});let d=this.charges.reduce((p,m)=>p.add(m.getTotal().grandTotal),t),h=this.charges.filter(p=>p.getChargeType()==="SHIPPING").reduce((p,m)=>p.add(m.getTotal().grandTotal),t),x=t,S=t,D=t,y={},I={},V={},q=(p,m)=>{Object.entries(p).forEach(([Ot,R])=>{let T=R.system,E=R.subSystem;m[T]||(m[T]={system:T,totalAmount:t,subSystems:{}}),m[T].subSystems[E]?m[T].subSystems[E]=m[T].subSystems[E].add(R.amount):m[T].subSystems[E]=R.amount,m[T].totalAmount=m[T].totalAmount.add(R.amount),y[T]||(y[T]={system:T,totalAmount:t,subSystems:{}}),y[T].subSystems[E]?y[T].subSystems[E]=y[T].subSystems[E].add(R.amount):y[T].subSystems[E]=R.amount,y[T].totalAmount=y[T].totalAmount.add(R.amount);});};e.forEach(p=>{let m=p.getTotal().taxBreakdown;m&&(q(m,I),q(m,y),S=S.add(p.getTotal().taxTotal));}),this.charges.forEach(p=>{let m=p.getTotal().taxBreakdown;m&&(q(m,V),q(m,y),D=D.add(p.getTotal().taxTotal));}),x=S.add(D);let Pt=r.add(S).add(d);this.total={subtotal:i,netSubtotal:r,lineItemTaxTotal:S,lineItemTaxBreakdown:I,chargesTotal:d,shippingCharge:s,netShippingCharge:h,chargeTaxTotal:D,chargeTaxBreakdown:V,taxTotal:x,taxBreakdown:y,discounts:u,totalDiscount:a,grandTotal:Pt};}updateShippingDetails(t){this.shippingDetails=t,this.calculateTotals();}applyCoupons(t){let e=t.filter(r=>r.getCategory()==="SHIPPING"),i=t.filter(r=>r.getCategory()!=="SHIPPING");this.coupons=[],this.total.totalDiscount=this.total.subtotal.zero(),this.total.discounts={},i.length&&this.applyNonShippingCoupons(i),this.applyDiscountsInLineItem(this.total.discounts),e.length&&this.applyShippingCoupons(e),this.calculateTotals();}applyDiscountsInLineItem(t){let e=Array.from(Object.entries(t)).filter(r=>!r[1].isZero()),i=new Map;this.lineItems.forEach(r=>i.set(r.getId(),[])),e.forEach(([r,s])=>{let a=this.coupons.find(c=>c.getCode()===r);if(!a||s.isZero())return;let u=this.lineItems.filter(c=>c.getState()!=="CANCELLED"&&!c.getTotal().subtotal.isZero()).sort((c,d)=>c.getTotal().subtotal.compareTo(d.getTotal().subtotal)),l=new n({amount:0,currency:this.currency});u.forEach((c,d)=>{let h;d===u.length-1?h=s.subtract(l):h=s.multiply(c.getTotal().subtotal).divide(this.total.subtotal).round(),l=l.add(h),i.get(c.getId())?.push({coupon:a,amount:h});});}),this.lineItems.forEach(r=>{r.getState()==="CANCELLED"||this.total.subtotal.isZero()?r.updateDiscounts([]):r.updateDiscounts(i.get(r.getId())||[]);});}applyDiscuountsInShippingCharges(t){let e=Array.from(Object.entries(t)).filter(s=>!s[1].isZero()),i=this.charges.filter(s=>s.getChargeType()==="SHIPPING"),r=new Map;i.forEach(s=>r.set(s.getId(),[])),e.forEach(([s,a])=>{let u=this.coupons.find(d=>d.getCode()===s);if(!u||a.isZero())return;let l=i.sort((d,h)=>d.getTotal().grandTotal.compareTo(h.getTotal().grandTotal)),c=new n({amount:0,currency:this.currency});l.forEach((d,h)=>{let x;h===l.length-1?x=a.subtract(c):x=a.multiply(d.getTotal().grandTotal).divide(this.total.subtotal).round(),c=c.add(x),r.get(d.getId())?.push({coupon:u,amount:x});});}),i.forEach(s=>{s.updateDiscounts(r.get(s.getId())||[]);});}applyNonShippingCoupons(t){let e=t.filter(i=>i.getType()==="coupon");if(e.length===1){let i=e[0].calculateApplicableCouponDiscount(this.total.subtotal,this.total.shippingCharge,this.country,this.currency);i.getAmount()>0&&(this.coupons.push(e[0]),this.total.discounts[e[0].getCode()]=i,this.total.totalDiscount=i);}}applyShippingCoupons(t){if(this.total.shippingCharge.getAmount()>0&&t.length>0){let e=this.total.subtotal.subtract(this.total.totalDiscount),i=t.reduce((s,a)=>{if(!s)return a;let u=a.calculateApplicableCouponDiscount(e,this.total.shippingCharge,this.country,this.currency).min(this.total.shippingCharge),l=s.calculateApplicableCouponDiscount(e,this.total.shippingCharge,this.country,this.currency).min(this.total.shippingCharge);return u===l?a.getType()==="coupon"?a:s:u.compareTo(l)>0?a:s}),r=i.calculateApplicableCouponDiscount(e,this.total.shippingCharge,this.country,this.currency).min(this.total.shippingCharge);r.getAmount()>0&&(this.coupons.push(i),this.total.discounts[i.getCode()]=r,this.total.totalDiscount=this.total.totalDiscount.add(r),this.total.netShippingCharge=this.total.shippingCharge.subtract(r));}}};module.exports=yt;//# sourceMappingURL=ShoppingContainer.js.map
1
+ 'use strict';var It=require('crypto');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var It__default=/*#__PURE__*/_interopDefault(It);var Q=new Uint8Array(256),K=Q.length;function dt(){return K>Q.length-16&&(It__default.default.randomFillSync(Q),K=0),Q.slice(K,K+=16)}var bt=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function Dt(o){return typeof o=="string"&&bt.test(o)}var xt=Dt;var f=[];for(let o=0;o<256;++o)f.push((o+256).toString(16).slice(1));function H(o,t=0){return f[o[t+0]]+f[o[t+1]]+f[o[t+2]]+f[o[t+3]]+"-"+f[o[t+4]]+f[o[t+5]]+"-"+f[o[t+6]]+f[o[t+7]]+"-"+f[o[t+8]]+f[o[t+9]]+"-"+f[o[t+10]]+f[o[t+11]]+f[o[t+12]]+f[o[t+13]]+f[o[t+14]]+f[o[t+15]]}function At(o){if(!xt(o))throw TypeError("Invalid UUID");let t,e=new Uint8Array(16);return e[0]=(t=parseInt(o.slice(0,8),16))>>>24,e[1]=t>>>16&255,e[2]=t>>>8&255,e[3]=t&255,e[4]=(t=parseInt(o.slice(9,13),16))>>>8,e[5]=t&255,e[6]=(t=parseInt(o.slice(14,18),16))>>>8,e[7]=t&255,e[8]=(t=parseInt(o.slice(19,23),16))>>>8,e[9]=t&255,e[10]=(t=parseInt(o.slice(24,36),16))/1099511627776&255,e[11]=t/4294967296&255,e[12]=t>>>24&255,e[13]=t>>>16&255,e[14]=t>>>8&255,e[15]=t&255,e}var Tt=At;function Mt(o){o=unescape(encodeURIComponent(o));let t=[];for(let e=0;e<o.length;++e)t.push(o.charCodeAt(e));return t}var wt="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Lt="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function gt(o,t,e){function i(r,s,a,d){var l;if(typeof r=="string"&&(r=Mt(r)),typeof s=="string"&&(s=Tt(s)),((l=s)===null||l===void 0?void 0:l.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let c=new Uint8Array(16+r.length);if(c.set(s),c.set(r,s.length),c=e(c),c[6]=c[6]&15|t,c[8]=c[8]&63|128,a){d=d||0;for(let g=0;g<16;++g)a[d+g]=c[g];return a}return H(c)}try{i.name=o;}catch{}return i.DNS=wt,i.URL=Lt,i}var pt={randomUUID:It__default.default.randomUUID};function Et(o,t,e){if(pt.randomUUID&&!t&&!o)return pt.randomUUID();o=o||{};let i=o.random||(o.rng||dt)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,t){e=e||0;for(let r=0;r<16;++r)t[e+r]=i[r];return t}return H(i)}var mt=Et;function Bt(o){return Array.isArray(o)?o=Buffer.from(o):typeof o=="string"&&(o=Buffer.from(o,"utf8")),It__default.default.createHash("sha1").update(o).digest()}var ft=Bt;var Nt=gt("v5",80,ft),ht=Nt;var C={"en-IN":"en","kn-IN":"kn"};var Ct={INR:"\u20B9"},Pt={INR:"en-IN"};var Z=(g=>(g.INITIAL="INITIAL",g.PROCESSING="PROCESSING",g.SHIPPED="SHIPPED",g.DELIVERED="DELIVERED",g.CANCELLED="CANCELLED",g.RETURN_REQUESTED="RETURN_REQUESTED",g.RETURNED="RETURNED",g.REFUND_INITIATED="REFUND_INITIATED",g.REFUNDED="REFUNDED",g.ON_HOLD="ON_HOLD",g))(Z||{});var Y=class extends Error{constructor(t){super(`Invalid line item state: ${t}`),this.name="InvalidLineItemStateError";}},J=class extends Error{constructor(t){super(`Duplicate size found: ${t}`),this.name="DuplicateSizeError";}},W=class extends Error{constructor(t){super(`Duplicate selection attribute found: ${t}`),this.name="DuplicateSelectionAttributeError";}},X=class extends Error{constructor(t="Product and selection attributes do not match."){super(`ProductMismatch: ${t}`),this.name="ProductMismatchError";}},_=class extends Error{constructor(t="Product is not active."){super(`ProductInactive: ${t}`),this.name="ProductInactiveError";}},A=class extends Error{constructor(t="Failed to parse selection attributes key."){super(`SelectionAttributeParseError: ${t}`),this.name="SelectionAttributeParseError";}},tt=class extends Error{constructor(t="Size does not match."){super(`SizeMismatch: ${t}`),this.name="SizeMismatchError";}},et=class extends Error{constructor(t="Pricing details not available for the product"){super(`NotFound: ${t}`),this.name="PricingNotFoundError";}},N=class extends Error{constructor(t="Tax rule category mismatch."){super(`InvalidTaxRule: ${t}`),this.name="InvalidTaxRuleError";}},it=class extends Error{constructor(t="Tax category is not valid."){super(`InvalidTaxCategory: ${t}`),this.name="InvalidTaxCategoryError";}},rt=class extends Error{constructor(t="Minimum quantity must be greater than zero."){super(`InvalidMinQuantity: ${t}`),this.name="InvalidMinQuantityError";}},ot=class extends Error{constructor(t){super(`InvalidTieredPrice: ${t}`),this.name="InvalidTieredPriceError";}},st=class extends Error{constructor(t="Quantity must be greater than zero."){super(`InvalidQuantity: ${t}`),this.name="InvalidQuantityError";}},nt=class extends Error{constructor(t){super(`NoApplicableTier: Quantity ${t} does not meet the minimum purchase requirement.`),this.name="NoApplicableTierError";}},at=class extends Error{constructor(t="No applicable tax slab or multiple slabs found for the given unit price."){super(`TaxSlabNotFound: ${t}`),this.name="TaxSlabNotFoundError";}},V=class extends Error{constructor(t="Amount cannot be negative."){super(`InvalidAmount: ${t}`),this.name="InvalidPriceAmountError";}},U=class extends Error{constructor(t="Currency code is required."){super(`InvalidCurrency: ${t}`),this.name="InvalidCurrencyCodeError";}},w=class extends Error{constructor(t="Cannot perform operation on prices with different currencies."){super(`CurrencyMismatch: ${t}`),this.name="CurrencyMismatchError";}},P=class extends Error{constructor(t){super(`InvalidArgument: ${t}`),this.name="InvalidArgumentError";}},$=class extends Error{constructor(t="Invalid image source configuration."){super(`InvalidImageSource: ${t}`),this.name="InvalidImageSourceError";}};var L=class{sources;alt;order;label;constructor(t){if(this.sources={...t.sources},this.alt=t.alt,this.order=t.order,this.label=t.label,!this.sources.original)throw new $("ImageInfoModel cannot be created without an 'original' source URL.")}getSources(){return {...this.sources}}getSource(t){return this.sources[t]||this.sources.original}getAlt(){return this.alt}getOrder(){return this.order}getLabel(){return this.label}setAlt(t){this.alt=t;}setOrder(t){this.order=t;}setLabel(t){this.label=t;}setSource(t,e){if(e===void 0){if(t==="original")throw new $("Cannot remove the 'original' image source.");delete this.sources[t];}else this.sources[t]=e;}getDetails(){return {sources:this.getSources(),alt:this.getAlt(),order:this.getOrder(),label:this.getLabel()}}};var n=class o{#t;amount;currency;constructor(t){if(this.#t="PriceModel",t.amount<0)throw new V("Amount cannot be negative.");if(!t.currency)throw new U("Currency code is required.");this.amount=t.amount,this.currency=t.currency;}get kind(){return this.#t}static isPriceModel(t){return typeof t=="object"&&t!==null&&t.kind==="PriceModel"}getCurrency(){return this.currency}getAmount(){return this.amount}getDetails(){return {amount:this.amount,currency:this.currency}}compareTo(t){if(o.isPriceModel(t)){if(this.currency!==t.getCurrency())throw new w("Cannot compare prices in different currencies.")}else throw new P("Must be a PriceModel instance.");return this.amount-t.getAmount()}add(t){if(o.isPriceModel(t)){if(this.currency!==t.getCurrency())throw new w("Cannot add prices in different currencies.")}else throw new P("Must be a PriceModel instance.");return new o({amount:this.amount+t.getAmount(),currency:this.currency})}subtract(t){if(o.isPriceModel(t)){if(this.currency!==t.getCurrency())throw new w("Cannot subtract prices in different currencies.")}else throw new P("Must be a PriceModel instance.");return new o({amount:this.amount-t.getAmount(),currency:this.currency})}multiply(t){if(o.isPriceModel(t)){if(this.currency!==t.getCurrency())throw new w("Cannot multiply prices in different currencies.");return new o({amount:this.amount*t.getAmount(),currency:this.currency})}else if(typeof t=="number"&&t>=0)return new o({amount:this.amount*t,currency:this.currency});throw new P("Must be a non-negative number.")}divide(t){if(o.isPriceModel(t)){if(this.currency!==t.getCurrency())throw new w("Cannot divide prices in different currencies.");return new o({amount:this.amount/t.getAmount(),currency:this.currency})}else if(typeof t=="number"&&t>0)return new o({amount:this.amount/t,currency:this.currency});throw new P("Must be a positive number.")}min(...t){if(t.length===0)throw new P("Must provide at least one PriceModel.");return t.reduce((e,i)=>{if(o.isPriceModel(i)){if(e.getCurrency()!==i.getCurrency())throw new w("Cannot compare prices in different currencies.")}else throw new P("Must be a PriceModel instance.");return e.compareTo(i)<0?e:i},this)}max(...t){if(t.length===0)throw new P("Must provide at least one PriceModel.");return t.reduce((e,i)=>{if(o.isPriceModel(i)){if(e.getCurrency()!==i.getCurrency())throw new w("Cannot compare prices in different currencies.")}else throw new P("Must be a PriceModel instance.");return e.compareTo(i)>0?e:i},this)}zero(){return new o({currency:this.currency,amount:0})}isZero(){return this.amount===0}round(){return new o({currency:this.currency,amount:this.getRoundedAmount()})}getRoundedAmount(){return o.getRoundedAmount(this.amount,this.currency)}getFormattedString(){return o.getFormattedString(this.amount,this.currency)}toString(){return this.getFormattedString()}static getFormattedString(t,e,i={displayAsInteger:!1,style:"currency",currencyDisplay:"symbol"}){let r=Pt[e];if(!e||!r)throw new U("Invalid currency code for formatting.");let s=t,a=i.displayAsInteger?0:o.getDecimalPlaces(e),d={style:i.style??"currency",currency:e,signDisplay:"never",currencyDisplay:i.currencyDisplay,minimumFractionDigits:a,maximumFractionDigits:a};i.displayAsInteger&&(s=Math.ceil(s));try{return new Intl.NumberFormat(r,d).format(s)}catch(l){return console.error(`Error formatting price for currency "${e}" and locale "${r}":`,l),`${Ct[e]??e} ${o.addThousandSeparators(s.toFixed(a))}`}}static getDecimalPlaces(t){switch(t){case"INR":default:return 2}}static addThousandSeparators(t){let e=t.split("."),i=e[0],r=e.length>1?"."+e[1]:"";return i.replace(/\B(?=(\d{3})+(?!\d))/g,",")+r}static getRoundedAmount(t,e){if(t<0)throw new V("Amount cannot be negative for rounding.");if(e===void 0)throw new U("Invalid currency code for rounding.");let i=o.getDecimalPlaces(e),r=Math.pow(10,i);return Math.round(t*r)/r}};var O=class{baseUnitPrice;taxCategory;tiers;constructor(t){let e=new n(t.baseUnitPrice);if(!t.taxCategory)throw new it;let i=(t.tiers??[]).map(l=>({minQuantity:l.minQuantity,unitPrice:new n(l.unitPrice)})).sort((l,c)=>l.minQuantity-c.minQuantity);if(i.some(l=>l.minQuantity<=0))throw new rt;let s=i.some(l=>l.unitPrice.getCurrency()!==e.getCurrency()),a=i.some((l,c)=>c>0&&l.unitPrice.compareTo(i[c-1].unitPrice)>0),d=i[0]?.unitPrice.compareTo(e)>0;if(s||a||d)throw new ot("Tiers must share the same currency and must not increase in unit price.");this.baseUnitPrice=e,this.taxCategory=t.taxCategory,this.tiers=i;}getBaseUnitPrice(){return this.baseUnitPrice}getTaxCategory(){return this.taxCategory}getTiers(){return this.tiers.map(t=>({minQuantity:t.minQuantity,unitPrice:t.unitPrice}))}getDetails(){return {baseUnitPrice:this.baseUnitPrice.getDetails(),taxCategory:this.taxCategory,tiers:this.tiers.map(t=>({minQuantity:t.minQuantity,unitPrice:t.unitPrice.getDetails()}))}}getApplicableTier(t){if(t<=0)throw new st;for(let e=this.tiers.length-1;e>=0;e--)if(t>=this.tiers[e].minQuantity){let i=this.tiers[e];return {minQuantity:i.minQuantity,unitPrice:i.unitPrice}}throw new nt(t)}getMinQuantity(){return this.tiers[0]?.minQuantity??1}getMaxDiscountPercent(){if(!this.tiers.length)return 0;let t=this.tiers[this.tiers.length-1].unitPrice.getAmount(),e=this.baseUnitPrice.getAmount();return (e-t)/e*100}};var k=class o extends M{id;key;name;description;slug;brand;pricing;variants;targetGender;attributes;specifications;categories;isActive;searchTags;static productKeyRegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static productSKURegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static generateSelectionAttributesKey(t){if(typeof t!="object")throw new A("Selection attributes must be an object");return Object.keys(t).filter(i=>t[i]!==void 0&&i.toLowerCase()!=="size").sort().map(i=>t[i].name?`${i}:c+${t[i].name}`:`${i}:${t[i]}`).join("|").toLowerCase()}static parseSelectionAttributesKey(t){try{let e={},i=t.split("|");for(let r of i){let[s,a]=r.split(":");a.startsWith("c+")?e[s]={name:a.slice(2)}:e[s]=a;}return e}catch(e){throw new A(e?.message)}}constructor(t,e=new Date){super(t,e),this.id=t.id,this.key=t.key,this.name={...t.name},this.description={...t.description},this.slug={...t.slug},this.brand=t.brand,this.pricing=Object.keys(t.pricing).reduce((r,s)=>(t.pricing[s]&&(r[s]=new O(t.pricing[s])),r),{}),this.targetGender=t.targetGender,this.attributes=u.deepClone(t.attributes),this.specifications=u.deepClone(t.specifications),this.categories=u.deepClone(t.categories);let i=new Set;this.variants=(t.variants||[]).map(r=>{if(!r.selectionAttributes||typeof r.selectionAttributes!="object")throw new A("Selection attributes are required");this.checkSelectionAttributes(r.selectionAttributes);let s=o.generateSelectionAttributesKey(r.selectionAttributes);if(i.has(s))throw new W(s);return i.add(s),{sku:r.sku,selectionAttributes:r.selectionAttributes,images:{primary:new L(r.images.primary),gallery:(r.images.gallery||[]).map(a=>new L(a))}}}),this.isActive=t.isActive,this.searchTags=t.searchTags?u.deepClone(t.searchTags):{en:[]};}getId(){return this.id}getKey(){return this.key}getName(t){return t?this.name[t]??this.name[C[t]]??this.name.en:u.deepClone(this.name)}getDescription(t){return t?this.description[t]??this.description[C[t]]??this.description.en:u.deepClone(this.description)}getSlug(t){return t?this.slug[t]??this.slug[C[t]]??this.slug.en:u.deepClone(this.slug)}getBrand(){return this.brand}getPriceDetails(t){return t?this.pricing[t]??null:{...this.pricing}}getAttributes(){return u.deepClone(this.attributes)}getVariants(){return this.variants.map(t=>({sku:t.sku,selectionAttributes:u.deepClone(t.selectionAttributes),images:{primary:t.images.primary,gallery:[...t.images.gallery]}}))}getImagesBySelectionAttributes(t){let e=o.generateSelectionAttributesKey(t),i=this.variants.find(r=>o.generateSelectionAttributesKey(r.selectionAttributes)===e);return i?{primary:i.images.primary,gallery:[...i.images.gallery]}:null}getImages(t,e){switch(e){case"PRIMARY":return this.getImagesBySelectionAttributes(t)?.primary??this.variants[0]?.images?.primary;case"GALLERY":return this.getImagesBySelectionAttributes(t)?.gallery??[];default:return this.getImagesBySelectionAttributes(t)??{primary:this.variants[0]?.images?.primary,gallery:[]}}}getIsActive(){return this.isActive}getTargetGender(){return this.targetGender}getCategories(){return u.deepClone(this.categories)}getSpecifications(t){return t?u.deepClone(this.specifications[t]??this.specifications[C[t]]??this.specifications.en):u.deepClone(this.specifications)}getSearchTags(t){return t?u.deepClone(this.searchTags[t]??this.searchTags[C[t]]??this.searchTags.en):u.deepClone(this.searchTags)}getDetails(){let t=super.getDetails();return {id:this.getId(),key:this.getKey(),name:this.getName(),description:this.getDescription(),slug:this.getSlug(),brand:this.getBrand(),pricing:Object.keys(this.pricing).reduce((e,i)=>(this.pricing[i]&&(e[i]=this.pricing[i]?.getDetails()),e),{}),attributes:this.getAttributes(),variants:this.variants.map(e=>({sku:e.sku,selectionAttributes:u.deepClone(e.selectionAttributes),images:{primary:e.images.primary.getDetails(),gallery:e.images.gallery.map(i=>i.getDetails())}})),isActive:this.getIsActive(),targetGender:this.getTargetGender(),categories:this.getCategories(),specifications:this.getSpecifications(),searchTags:this.getSearchTags(),...t}}checkSelectionAttributes(t){if(!t||typeof t!="object")throw new A("Selection attributes are required");Object.keys(this.attributes).forEach(e=>{if(e.toLowerCase()==="size")return;let i=this.attributes[e],r=t[e];if(r===void 0)throw new A(`Selection attribute '${e}' is missing`);if(typeof i=="string"){if(typeof r!="string"||i!==r)throw new A(`Selection attribute '${e}' is invalid`)}else if(Array.isArray(i)){if(i.length>0&&typeof i[0]=="string"){if(typeof r!="string"||!i.includes(r))throw new A(`Selection attribute '${e}' is invalid`)}else if(typeof r!="object"||!("name"in r)||i.findIndex(s=>s.name===r.name)<0)throw new A(`Selection attribute '${e}' is invalid`)}});}validateSelectionAttribute(t){let e=o.generateSelectionAttributesKey(t);return this.variants.some(i=>o.generateSelectionAttributesKey(i.selectionAttributes)===e)}validateSize(t){return this.attributes.size.includes(t)}};var Ut={isUUID:o=>/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(o),isEmail:o=>/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(o),isURL:o=>/^(http|https):\/\/[^ "]+$/.test(o),generateUUID:(o,t)=>t&&o?ht(o,t):mt(),generateSearchId:(o,t)=>`${o}#${k.generateSelectionAttributesKey(t)}`,getKeyfromSearchId:o=>{let[t,e]=o.split("#");return {key:t,selectionAttributes:k.parseSelectionAttributesKey(e)}},deepClone(o){return structuredClone(o)}},u=Ut;var B=class{customFields;constructor(t,e=new Date){this.customFields={...t.customFields};}getCustomField(t){let e=this.customFields[t];return e==null?e:u.deepClone(e)}setCustomField(t,e){this.customFields[t]=e;}getAllCustomFields(){return u.deepClone(this.customFields)}},M=class extends B{version;createdAt;modifiedAt;modifiedBy;constructor(t,e=new Date){super(t),this.version=t.version??1,this.createdAt=t.createdAt&&!isNaN(Date.parse(t.createdAt))?new Date(t.createdAt).toISOString():e.toISOString(),this.modifiedAt=t.modifiedAt&&!isNaN(Date.parse(t.modifiedAt))?new Date(t.modifiedAt).toISOString():e.toISOString(),this.modifiedBy={...t.modifiedBy};}getDetails(){return {customFields:this.getAllCustomFields(),version:this.getVersion(),createdAt:this.getCreatedAt(),modifiedAt:this.getModifiedAt(),modifiedBy:this.getModifiedBy()}}getVersion(){return this.version}getCreatedAt(){return this.createdAt}getCreatedAtTime(){return new Date(this.createdAt).getTime()}getModifiedAt(){return this.modifiedAt}getModifiedAtTime(){return new Date(this.modifiedAt).getTime()}getModifiedBy(){return {...this.modifiedBy}}setModifiedBy(t,e,i,r){this.modifiedBy={id:t,authType:e,requestId:i,lambdaName:r};}};var v=class extends M{id;firstName;lastName;company;phone;email;addressLine1;addressLine2;city;postalCode;state;country;isBillingAddress;isShippingAddress;constructor(t,e=new Date){super(t,e),this.id=t.id,this.firstName=t.firstName,this.lastName=t.lastName||"",this.company=t.company||"",this.phone=t.phone,this.email=t.email,this.addressLine1=t.addressLine1,this.addressLine2=t.addressLine2||"",this.city=t.city,this.postalCode=t.postalCode,this.state=t.state,this.country=t.country,this.isBillingAddress=t.isBillingAddress,this.isShippingAddress=t.isShippingAddress;}getDetails(){return {...super.getDetails(),id:this.getId(),firstName:this.getFirstName(),lastName:this.getLastName(),company:this.getCompany(),phone:this.getPhone(),email:this.getEmail(),addressLine1:this.getAddressLine1(),addressLine2:this.getAddressLine2(),city:this.getCity(),postalCode:this.getPostalCode(),state:this.getState(),country:this.getCountry(),isBillingAddress:this.getIsBillingAddress(),isShippingAddress:this.getIsShippingAddress()}}getId(){return this.id}getFirstName(){return this.firstName}getLastName(){return this.lastName}getCompany(){return this.company}getPhone(){return this.phone}getEmail(){return this.email}getAddressLine1(){return this.addressLine1}getAddressLine2(){return this.addressLine2}getCity(){return this.city}getPostalCode(){return this.postalCode}getState(){return this.state}getCountry(){return this.country}getIsBillingAddress(){return this.isBillingAddress}getIsShippingAddress(){return this.isShippingAddress}getAddressType(){return this.isBillingAddress&&this.isShippingAddress?"billing&shipping":this.isBillingAddress?"billing":this.isShippingAddress?"shipping":"none"}static checkIfShippingAddress(t){return t==="shipping"||t==="billing&shipping"}static checkIfBillingAddress(t){return t==="billing"||t==="billing&shipping"}};var ct=class{taxRuleId;taxCategory;taxSystem;taxSubSystem;taxCountry;effectiveFrom;effectiveTo;constructor(t){this.taxRuleId=t.taxRuleId,this.taxSystem=t.taxSystem,this.taxSubSystem=t.taxSubSystem,this.taxCategory=t.taxCategory,this.taxCountry=t.taxCountry,this.effectiveFrom=new Date(t.effectiveFrom).toISOString(),this.effectiveTo=t.effectiveTo?new Date(t.effectiveTo).toISOString():void 0;}getTaxRuleId(){return this.taxRuleId}getTaxSystem(){return this.taxSystem}getTaxSubSystem(){return this.taxSubSystem}getTaxCategory(){return this.taxCategory}getTaxCountry(){return this.taxCountry}getEffectiveFrom(){return this.effectiveFrom}getEffectiveTo(){return this.effectiveTo}getDetails(){return {taxRuleId:this.getTaxRuleId(),taxSystem:this.getTaxSystem(),taxSubSystem:this.getTaxSubSystem(),taxCategory:this.getTaxCategory(),taxCountry:this.getTaxCountry(),effectiveFrom:this.effectiveFrom,effectiveTo:this.effectiveTo?this.effectiveTo:void 0}}appliesTo(t,e,i=new Date){return this.taxCategory===t&&this.taxCountry===e&&Date.parse(this.effectiveFrom)<=i.getTime()&&(this.effectiveTo?Date.parse(this.effectiveTo)>=i.getTime():!0)}static getTaxRateDisplayString(t,e,i){let r=e*100,s=r%1===0?r.toString():r.toFixed(2).replace(/\.?0+$/,"");return i?.percentageOnly?`${s}%`:t.getTaxSystem()==="GST"?`${t.getTaxSubSystem()} ${s}%`:`${t.getTaxSystem()} ${s}%`}},lt=class o extends ct{slabs;constructor(t){super(t),this.slabs=t.slabs.map(e=>({rate:e.rate,minUnitPrice:new n(e.minUnitPrice),maxUnitPrice:e.maxUnitPrice?new n(e.maxUnitPrice):void 0}));}getSlabs(){return this.slabs.map(t=>({rate:t.rate,minUnitPrice:t.minUnitPrice,maxUnitPrice:t.maxUnitPrice}))}getDetails(){return {...super.getDetails(),slabs:this.getSlabs().map(t=>({rate:t.rate,minUnitPrice:t.minUnitPrice.getDetails(),maxUnitPrice:t.maxUnitPrice?t.maxUnitPrice.getDetails():void 0}))}}getApplicableTaxRate(t){return o.getApplicableTaxRate(t,this.slabs)}calculateTax(t){let e=this.getApplicableTaxRate(t);return t.multiply(e)}static getApplicableTaxRate(t,e){let i=e.filter(r=>(r.minUnitPrice===void 0||t.compareTo(r.minUnitPrice)>=0)&&(r.maxUnitPrice===void 0||t.compareTo(r.maxUnitPrice)<0));if(i.length!==1)throw new at;return i[0].rate}},ut=class extends ct{rate;constructor(t){super(t),this.rate=t.rate;}getApplicableTaxRate(){return this.rate}calculateTax(t){let e=this.getApplicableTaxRate();return t.multiply(e)}getDetails(){return {...super.getDetails(),rate:this.getApplicableTaxRate()}}};var F=class extends B{id;productKey;selectionAttributes;name;specifications;primaryImage;subItems;pricing;state;total;constructor(t){super(t),this.id=t.id,this.productKey=t.productKey,this.selectionAttributes=u.deepClone(t.selectionAttributes),this.name=u.deepClone(t.name),this.specifications=u.deepClone(t.specifications),this.primaryImage=new L(t.primaryImage),this.subItems=u.deepClone(t.subItems);let e=new Set;this.subItems.forEach(i=>{if(e.has(i.size))throw new J(i.size);e.add(i.size);}),this.pricing={unitPrice:new n(t.pricing.unitPrice),tierPricing:new O(t.pricing.tierPricing),taxCategory:t.pricing.taxCategory,applicableTaxRule:t.pricing.applicableTaxRule.map(i=>new lt(i))},this.state=t.state??"INITIAL",this.total={quantity:t.total.quantity,unitPrice:new n(t.total.unitPrice),subtotal:new n(t.total.subtotal),discounts:Object.fromEntries(Object.entries(t.total.discounts).map(([i,r])=>[i,new n(r)])),totalDiscount:new n(t.total.totalDiscount),netUnitPrice:new n(t.total.netUnitPrice),netSubtotal:new n(t.total.netSubtotal),taxBreakdown:Object.fromEntries(Object.entries(t.total.taxBreakdown).map(([i,r])=>[i,{rate:r.rate,taxableUnitPrice:new n(r.taxableUnitPrice),taxPerUnit:new n(r.taxPerUnit),amount:new n(r.amount),system:r.system,subSystem:r.subSystem}])),taxTotal:new n(t.total.taxTotal),grandTotal:new n(t.total.grandTotal)};}getId(){return this.id}getProductKey(){return this.productKey}getSelectionAttributes(){return u.deepClone(this.selectionAttributes)}getName(t){return t?u.deepClone(this.name[t]??this.name[C[t]]??this.name.en):u.deepClone(this.name)}getSpecifications(t){return t?u.deepClone(this.specifications[t]??this.specifications[C[t]]??this.specifications.en):u.deepClone(this.specifications)}getImage(){return this.primaryImage}getSubItems(){return u.deepClone(this.subItems)}getTotalQuantity(){return this.total.quantity}getPricing(){return {unitPrice:this.pricing.unitPrice,tierPricing:this.pricing.tierPricing,taxCategory:this.pricing.taxCategory,applicableTaxRule:[...this.pricing.applicableTaxRule]}}getState(){return this.state}getTotal(){return {quantity:this.total.quantity,unitPrice:this.total.unitPrice,subtotal:this.total.subtotal,discounts:Object.fromEntries(Object.entries(this.total.discounts).map(([t,e])=>[t,e])),totalDiscount:this.total.totalDiscount,netUnitPrice:this.total.netUnitPrice,netSubtotal:this.total.netSubtotal,taxBreakdown:Object.fromEntries(Object.entries(this.total.taxBreakdown).map(([t,e])=>[t,{rate:e.rate,taxableUnitPrice:e.taxableUnitPrice,taxPerUnit:e.taxPerUnit,amount:e.amount,system:e.system,subSystem:e.subSystem}])),taxTotal:this.total.taxTotal,grandTotal:this.total.grandTotal}}getDetails(){let t=this.getPricing(),e=this.getTotal();return {id:this.getId(),productKey:this.getProductKey(),selectionAttributes:this.getSelectionAttributes(),name:this.getName(),specifications:this.getSpecifications(),primaryImage:this.getImage().getDetails(),subItems:this.getSubItems(),pricing:{unitPrice:t.unitPrice.getDetails(),tierPricing:t.tierPricing.getDetails(),taxCategory:t.taxCategory,applicableTaxRule:t.applicableTaxRule.map(i=>i.getDetails())},state:this.getState(),total:{quantity:e.quantity,unitPrice:e.unitPrice.getDetails(),subtotal:e.subtotal.getDetails(),discounts:Object.fromEntries(Object.entries(e.discounts).map(([i,r])=>[i,r.getDetails()])),totalDiscount:e.totalDiscount.getDetails(),netUnitPrice:e.netUnitPrice.getDetails(),netSubtotal:e.netSubtotal.getDetails(),taxBreakdown:Object.fromEntries(Object.entries(e.taxBreakdown).map(([i,r])=>[i,{rate:r.rate,taxableUnitPrice:r.taxableUnitPrice.getDetails(),taxPerUnit:r.taxPerUnit.getDetails(),amount:r.amount.getDetails(),system:r.system,subSystem:r.subSystem}])),taxTotal:e.taxTotal.getDetails(),grandTotal:e.grandTotal.getDetails()},customFields:this.getAllCustomFields()}}addSubItems(t,e){t.forEach(i=>{let r=this.subItems.find(s=>s.size===i.size);r?r.quantity=e?r.quantity+i.quantity:i.quantity:this.subItems.push(i);}),this.subItems=this.subItems.filter(i=>i.quantity>0),this.calculateTotals();}updateProductData(t,e,i){if(this.productKey!==t.getKey()||!t.validateSelectionAttribute(this.selectionAttributes))throw new X;if(!t.getIsActive())throw new _;this.subItems.forEach(d=>{if(!t.validateSize(d.size))throw new tt});let r=t.getPriceDetails(e);if(!r||r.getBaseUnitPrice().getCurrency()!==i)throw new et;this.name=t.getName(),this.specifications=t.getSpecifications(),this.primaryImage=t.getImages(this.selectionAttributes).primary;let s=this.subItems.reduce((d,l)=>d+l.quantity,0),{unitPrice:a}=r.getApplicableTier(s);this.pricing={unitPrice:a,tierPricing:r,taxCategory:r.getTaxCategory(),applicableTaxRule:this.pricing.applicableTaxRule},this.calculateTotals();}updateDiscounts(t){let e={};t.forEach(i=>{e[i.coupon.getCode()]=i.amount;}),this.total.discounts=e,this.calculateTotals();}updateTax(t){t.forEach(e=>{if(!e.appliesTo(this.pricing.taxCategory,e.getTaxCountry()))throw new N}),this.pricing.applicableTaxRule=t,this.calculateTotals();}calculateTotals(){let t=this.pricing.unitPrice.zero(),e=this.subItems.reduce((h,x)=>h+x.quantity,0);if(this.state==="CANCELLED"){this.total={quantity:0,unitPrice:t,subtotal:t,discounts:{},totalDiscount:t,netUnitPrice:t,netSubtotal:t,taxBreakdown:{},taxTotal:t,grandTotal:t};return}let{unitPrice:i}=this.pricing.tierPricing.getApplicableTier(e),r=i.multiply(e),s=Object.values(this.total.discounts).reduce((h,x)=>h.add(x),t),a=r.subtract(s),d=e>0?a.divide(e):t,l={},c=t;this.pricing.applicableTaxRule.forEach(h=>{let x=h.getApplicableTaxRate(d),I=h.calculateTax(d),D=I.multiply(e).round();l[h.getTaxRuleId()]={rate:x,taxableUnitPrice:d,taxPerUnit:I,amount:D,system:h.getTaxSystem(),subSystem:h.getTaxSubSystem()},c=c.add(D);});let g=a.add(c);this.total={quantity:e,unitPrice:i,subtotal:r,discounts:this.total.discounts,totalDiscount:s,netUnitPrice:d,netSubtotal:a,taxBreakdown:l,taxTotal:c,grandTotal:g};}updateState(t){if(this.state in Z)this.state!==t&&(this.state=t);else throw new Y(t)}clearLineItem(){let t=this.pricing.unitPrice.zero();this.id="",this.productKey="",this.selectionAttributes={color:{name:""}},this.name={en:""},this.primaryImage=new L({sources:{original:""}}),this.subItems=[],this.pricing={unitPrice:t,tierPricing:this.pricing.tierPricing,taxCategory:this.pricing.taxCategory,applicableTaxRule:[]},this.total={quantity:0,unitPrice:t,subtotal:t,discounts:{},totalDiscount:t,netUnitPrice:t,netSubtotal:t,taxBreakdown:{},taxTotal:t,grandTotal:t};}};var G=class extends M{couponCode;name;description;type;customerId;validFrom;validTo;minCartValue;maxCartDiscount;discountMethod;percentageValue;applicableTo;category;constructor(t,e=new Date){if(super(t,e),this.couponCode=t.couponCode,this.name=u.deepClone(t.name),this.description=u.deepClone(t.description),this.type=t.type,this.customerId=t.customerId,this.validFrom=t.validFrom&&Date.parse(t.validFrom)?new Date(t.validFrom).toISOString():e.toISOString(),this.validTo=t.validTo&&Date.parse(t.validTo)?new Date(t.validTo).toISOString():e.toISOString(),this.minCartValue=Object.keys(t.minCartValue).reduce((i,r)=>{let s=t.minCartValue[r];return s&&(i[r]=new n(s)),i},{}),this.maxCartDiscount=Object.keys(t.maxCartDiscount).reduce((i,r)=>{let s=t.maxCartDiscount[r];return s&&(i[r]=new n(s)),i},{}),this.discountMethod=t.discountMethod,this.percentageValue=t.percentageValue??0,this.percentageValue>100)throw new P("Percentage value cannot be greater than 100");this.applicableTo=t.applicableTo,this.category=t.category;}getCode(){return this.couponCode}getName(t){return t?this.name[t]??this.name[C[t]]??this.name.en:{...this.name}}getDescription(t){return t?this.description[t]??this.description[C[t]]??this.description.en:{...this.description}}getType(){return this.type}getCustomerId(){return this.customerId??""}getValidFrom(){return this.validFrom}getValidTo(){return this.validTo}getMinCartValue(t){return t?this.minCartValue[t]:{...this.minCartValue}}getMaxCartDiscount(t){return t?this.maxCartDiscount[t]:{...this.maxCartDiscount}}getDiscountMethod(){return this.discountMethod}getPercentageValue(){return this.percentageValue}getApplicableTo(){return this.applicableTo}getCategory(){return this.category}getDetails(){return {...super.getDetails(),couponCode:this.getCode(),name:this.getName(),description:this.getDescription(),type:this.getType(),customerId:this.getCustomerId(),validFrom:this.getValidFrom(),validTo:this.getValidTo(),minCartValue:Object.keys(this.getMinCartValue()).reduce((t,e)=>{let i=this.getMinCartValue(e);return i&&(t[e]=i.getDetails()),t},{}),maxCartDiscount:Object.keys(this.getMaxCartDiscount()).reduce((t,e)=>{let i=this.getMaxCartDiscount(e);return i&&(t[e]=i.getDetails()),t},{}),discountMethod:this.getDiscountMethod(),percentageValue:this.getPercentageValue(),applicableTo:this.getApplicableTo(),category:this.getCategory()}}isActive(){return new Date(this.validFrom)<=new Date&&new Date(this.validTo)>=new Date}isApplicableTo(t){return this.applicableTo==="all"||this.applicableTo==="ftb"&&t}calculateApplicableCouponDiscount(t,e,i,r,s=!0){let a=new n({amount:0,currency:r}),d;if(s&&!this.isActive())return a;let l=this.getMinCartValue(i),c=this.getMaxCartDiscount(i);if(!l||l.compareTo(t)>0||!c)return a;let g=this.getCategory(),h=this.getDiscountMethod(),x=g==="SHIPPING"?e:t;if(x.getAmount()<=0)return a;switch(h){case"flat":let D=c;d=x.min(D);break;case"percentage":d=x.multiply(this.getPercentageValue()/100).round();break;default:return a}return d.min(c)}};var z=class extends B{id;name;category;lineItemId;chargeType;pricing;total;constructor(t){super(t),this.id=t.id,this.name=t.name,this.category=t.category,this.lineItemId=t.lineItemId,this.chargeType=t.chargeType,this.pricing={price:new n(t.pricing.price),taxCategory:t.pricing.taxCategory,applicableTaxRule:t.pricing.applicableTaxRule.map(e=>new ut(e))},this.total={price:new n(t.total.price),discounts:Object.fromEntries(Object.entries(t.total.discounts).map(([e,i])=>[e,new n(i)])),totalDiscount:new n(t.total.totalDiscount),netPrice:new n(t.total.netPrice),taxBreakdown:Object.fromEntries(Object.entries(t.total.taxBreakdown).map(([e,i])=>[e,{rate:i.rate,taxablePrice:new n(i.taxablePrice),amount:new n(i.amount),system:i.system,subSystem:i.subSystem}])),taxTotal:new n(t.total.taxTotal),grandTotal:new n(t.total.grandTotal)};}getId(){return this.id}getName(t){return t?u.deepClone(this.name[t]??this.name[C[t]]??this.name.en):u.deepClone(this.name)}getCategory(){return this.category}getChargeType(){return this.chargeType}getLineItemId(){return this.lineItemId}getPricing(){return {price:this.pricing.price,taxCategory:this.pricing.taxCategory,applicableTaxRule:[...this.pricing.applicableTaxRule]}}getTotal(){return {price:this.total.price,discounts:{...this.total.discounts},netPrice:this.total.netPrice,totalDiscount:this.total.totalDiscount,taxBreakdown:Object.fromEntries(Object.entries(this.total.taxBreakdown).map(([t,e])=>[t,{rate:e.rate,taxablePrice:e.taxablePrice,amount:e.amount,system:e.system,subSystem:e.subSystem}])),taxTotal:this.total.taxTotal,grandTotal:this.total.grandTotal}}getApplicableTaxRules(){return [...this.pricing.applicableTaxRule]}updateTax(t){t.forEach(e=>{if(!e.appliesTo(this.pricing.taxCategory,e.getTaxCountry()))throw new N}),this.pricing.applicableTaxRule=t,this.calculateTotals();}updateDiscounts(t){let e={};t.forEach(i=>{e[i.coupon.getCode()]=i.amount;}),this.total.discounts=e,this.calculateTotals();}calculateTotals(){let t=this.pricing.price.zero(),e=this.pricing.price,i=Object.values(this.total.discounts).reduce((y,S)=>y.add(S),t),r=e.subtract(i),s={},a=this.pricing.applicableTaxRule.reduce((y,S)=>y+S.getApplicableTaxRate(),0),d=r.divide(1+a).round(),l=a>0?r.subtract(d):t,c=t,g=this.pricing.applicableTaxRule.reduce((y,S)=>S.getApplicableTaxRate()>y.getApplicableTaxRate()?S:y),h=g.getTaxRuleId();this.pricing.applicableTaxRule.forEach(y=>{if(y.getTaxRuleId()===h)return;let S=y.getApplicableTaxRate(),j=a>0?l.multiply(S).divide(a).round():t;s[y.getTaxRuleId()]={rate:S,taxablePrice:d,amount:j,system:y.getTaxSystem(),subSystem:y.getTaxSubSystem()},c=c.add(j);});let x=l.subtract(c);s[h]={rate:g.getApplicableTaxRate(),taxablePrice:d,amount:x,system:g.getTaxSystem(),subSystem:g.getTaxSubSystem()};let I=d,D=r;this.total={price:e,discounts:this.total.discounts,netPrice:I,totalDiscount:i,taxBreakdown:s,taxTotal:l,grandTotal:D};}getDetails(){return {id:this.id,name:u.deepClone(this.name),category:this.category,lineItemId:this.lineItemId,chargeType:this.chargeType,pricing:{price:this.pricing.price.getDetails(),taxCategory:this.pricing.taxCategory,applicableTaxRule:this.pricing.applicableTaxRule.map(e=>e.getDetails())},total:{price:this.total.price.getDetails(),discounts:Object.fromEntries(Object.entries(this.total.discounts).map(([e,i])=>[e,i.getDetails()])),totalDiscount:this.total.totalDiscount.getDetails(),netPrice:this.total.netPrice.getDetails(),taxBreakdown:Object.fromEntries(Object.entries(this.total.taxBreakdown).map(([e,i])=>[e,{rate:i.rate,taxablePrice:i.taxablePrice.getDetails(),amount:i.amount.getDetails(),system:i.system,subSystem:i.subSystem}])),taxTotal:this.total.taxTotal.getDetails(),grandTotal:this.total.grandTotal.getDetails()},customFields:this.getAllCustomFields()}}};var yt=class extends M{id;customerId;customerEmail;anonymousId;lineItems;charges;shippingDetails;shippingAddress;billingAddress;coupons;total;country;currency;locale;constructor(t,e=new Date){super(t,e),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 F(i)),this.charges=(t.charges??[]).map(i=>new z(i)),this.billingAddress=t.billingAddress?new v(t.billingAddress,e):null,this.shippingAddress=t.shippingAddress?new v(t.shippingAddress,e):null,this.coupons=(t.coupons??[]).map(i=>new G(i)),this.shippingDetails=t.shippingDetails?u.deepClone(t.shippingDetails):null,this.total={subtotal:new n(t.total.subtotal),netSubtotal:new n(t.total.netSubtotal),lineItemTaxTotal:new n(t.total.lineItemTaxTotal||{amount:0,currency:t.currency}),lineItemTaxBreakdown:this.mapTaxBreakdown(t.total.lineItemTaxBreakdown||{}),chargesTotal:new n(t.total.chargesTotal||{amount:0,currency:t.currency}),shippingCharge:new n(t.total.shippingCharge),netShippingCharge:new n(t.total.netShippingCharge),chargeTaxTotal:new n(t.total.chargeTaxTotal||{amount:0,currency:t.currency}),chargeTaxBreakdown:this.mapTaxBreakdown(t.total.chargeTaxBreakdown||{}),taxTotal:new n(t.total.taxTotal),taxBreakdown:this.mapTaxBreakdown(t.total.taxBreakdown),discounts:Object.fromEntries(Object.entries(t.total.discounts).map(([i,r])=>[i,new n(r)])),totalDiscount:new n(t.total.totalDiscount),grandTotal:new n(t.total.grandTotal)};}mapTaxBreakdown(t){return Object.fromEntries(Object.entries(t||{}).map(([e,i])=>[e,{system:i.system,totalAmount:new n(i.totalAmount),subSystems:Object.fromEntries(Object.entries(i.subSystems).map(([r,s])=>[r,new n(s)]))}]))}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(([r,s])=>[r,s.getDetails()]))}]))}getId(){return this.id}getCustomerId(){return this.customerId}getCustomerEmail(){return this.customerEmail}getAnonymousId(){return this.anonymousId}getLineItems(){return this.lineItems.map(t=>new F(t.getDetails()))}getLineItemsCount(){return this.lineItems.length}getCharges(){return this.charges.map(t=>new z(t.getDetails()))}addCharge(t){this.charges.push(t),this.calculateTotals();}clearCharges(){this.charges=[],this.calculateTotals();}getShippingDetails(){return this.shippingDetails?u.deepClone(this.shippingDetails):null}getShippingAddress(){return this.shippingAddress?new v(this.shippingAddress.getDetails()):null}hasShippingAddress(){return !!this.shippingAddress}hasBillingAddress(){return !!this.billingAddress}getBillingAddress(){return this.billingAddress?new v(this.billingAddress.getDetails()):null}getCoupons(){return [...this.coupons]}getCountry(){return this.country}getCurrency(){return this.currency}getLocale(){return this.locale}getTotal(){return {subtotal:this.total.subtotal,netSubtotal:this.total.netSubtotal,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}}])),chargesTotal:this.total.chargesTotal,shippingCharge:this.total.shippingCharge,netShippingCharge:this.total.netShippingCharge,chargeTaxTotal:this.total.chargeTaxTotal,chargeTaxBreakdown:Object.fromEntries(Object.entries(this.total.chargeTaxBreakdown).map(([t,e])=>[t,{system:e.system,totalAmount:e.totalAmount,subSystems:{...e.subSystems}}])),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}}])),discounts:{...this.total.discounts},totalDiscount:this.total.totalDiscount,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:{subtotal:t.subtotal.getDetails(),netSubtotal:t.netSubtotal.getDetails(),lineItemTaxTotal:t.lineItemTaxTotal.getDetails(),lineItemTaxBreakdown:this.serializeTaxBreakdown(t.lineItemTaxBreakdown),chargesTotal:t.chargesTotal.getDetails(),shippingCharge:t.shippingCharge.getDetails(),netShippingCharge:t.netShippingCharge.getDetails(),chargeTaxTotal:t.chargeTaxTotal.getDetails(),chargeTaxBreakdown:this.serializeTaxBreakdown(t.chargeTaxBreakdown),taxTotal:t.taxTotal.getDetails(),taxBreakdown:this.serializeTaxBreakdown(t.taxBreakdown),discounts:Object.fromEntries(Object.entries(t.discounts).map(([e,i])=>[e,i.getDetails()])),totalDiscount:t.totalDiscount.getDetails(),grandTotal:t.grandTotal.getDetails()},country:this.getCountry(),currency:this.getCurrency(),locale:this.getLocale()}}calculateTotals(){let t=new n({amount:0,currency:this.currency}),e=this.lineItems.filter(p=>p.getState()!=="CANCELLED"),i=e.reduce((p,m)=>p.add(m.getTotal().subtotal),t),r=e.reduce((p,m)=>p.add(m.getTotal().netSubtotal),t),s=this.charges.filter(p=>p.getChargeType()==="SHIPPING").reduce((p,m)=>p.add(m.getTotal().price),t),a=t,d={},l={};this.coupons.forEach(p=>{let m=p.calculateApplicableCouponDiscount(i,s,this.country,this.currency);a=a.add(m),d[p.getCode()]=m,p.getCategory()!=="SHIPPING"&&(l[p.getCode()]=m);}),this.applyDiscountsInLineItem(l);let c=this.coupons.find(p=>p.getCategory()==="SHIPPING");c?this.applyDiscuountsInShippingCharges({[c.getCode()]:d[c.getCode()]||t}):this.applyDiscuountsInShippingCharges({});let g=this.charges.reduce((p,m)=>p.add(m.getTotal().grandTotal),t),h=this.charges.filter(p=>p.getChargeType()==="SHIPPING").reduce((p,m)=>p.add(m.getTotal().grandTotal),t),x=t,I=t,D=t,y={},S={},j={},q=(p,m)=>{Object.entries(p).forEach(([Ot,R])=>{let T=R.system,E=R.subSystem;m[T]||(m[T]={system:T,totalAmount:t,subSystems:{}}),m[T].subSystems[E]?m[T].subSystems[E]=m[T].subSystems[E].add(R.amount):m[T].subSystems[E]=R.amount,m[T].totalAmount=m[T].totalAmount.add(R.amount),y[T]||(y[T]={system:T,totalAmount:t,subSystems:{}}),y[T].subSystems[E]?y[T].subSystems[E]=y[T].subSystems[E].add(R.amount):y[T].subSystems[E]=R.amount,y[T].totalAmount=y[T].totalAmount.add(R.amount);});};e.forEach(p=>{let m=p.getTotal().taxBreakdown;m&&(q(m,S),q(m,y),I=I.add(p.getTotal().taxTotal));}),this.charges.forEach(p=>{let m=p.getTotal().taxBreakdown;m&&(q(m,j),q(m,y),D=D.add(p.getTotal().taxTotal));}),x=I.add(D);let St=r.add(I).add(g);this.total={subtotal:i,netSubtotal:r,lineItemTaxTotal:I,lineItemTaxBreakdown:S,chargesTotal:g,shippingCharge:s,netShippingCharge:h,chargeTaxTotal:D,chargeTaxBreakdown:j,taxTotal:x,taxBreakdown:y,discounts:d,totalDiscount:a,grandTotal:St};}updateShippingDetails(t){this.shippingDetails=t,this.calculateTotals();}applyCoupons(t){let e=t.filter(r=>r.getCategory()==="SHIPPING"),i=t.filter(r=>r.getCategory()!=="SHIPPING");this.coupons=[],this.total.totalDiscount=this.total.subtotal.zero(),this.total.discounts={},i.length&&this.applyNonShippingCoupons(i),this.applyDiscountsInLineItem(this.total.discounts),e.length&&this.applyShippingCoupons(e),this.calculateTotals();}applyDiscountsInLineItem(t){let e=Array.from(Object.entries(t)).filter(r=>!r[1].isZero()),i=new Map;this.lineItems.forEach(r=>i.set(r.getId(),[])),e.forEach(([r,s])=>{let a=this.coupons.find(c=>c.getCode()===r);if(!a||s.isZero())return;let d=this.lineItems.filter(c=>c.getState()!=="CANCELLED"&&!c.getTotal().subtotal.isZero()).sort((c,g)=>c.getTotal().subtotal.compareTo(g.getTotal().subtotal)),l=new n({amount:0,currency:this.currency});d.forEach((c,g)=>{let h;g===d.length-1?h=s.subtract(l):h=s.multiply(c.getTotal().subtotal).divide(this.total.subtotal).round(),l=l.add(h),i.get(c.getId())?.push({coupon:a,amount:h});});}),this.lineItems.forEach(r=>{r.getState()==="CANCELLED"||this.total.subtotal.isZero()?r.updateDiscounts([]):r.updateDiscounts(i.get(r.getId())||[]);});}applyDiscuountsInShippingCharges(t){let e=Array.from(Object.entries(t)).filter(s=>!s[1].isZero()),i=this.charges.filter(s=>s.getChargeType()==="SHIPPING"),r=new Map;i.forEach(s=>r.set(s.getId(),[])),e.forEach(([s,a])=>{let d=this.coupons.find(g=>g.getCode()===s);if(!d||a.isZero())return;let l=i.sort((g,h)=>g.getTotal().grandTotal.compareTo(h.getTotal().grandTotal)),c=new n({amount:0,currency:this.currency});l.forEach((g,h)=>{let x;h===l.length-1?x=a.subtract(c):x=a.multiply(g.getTotal().grandTotal).divide(this.total.subtotal).round(),c=c.add(x),r.get(g.getId())?.push({coupon:d,amount:x});});}),i.forEach(s=>{s.updateDiscounts(r.get(s.getId())||[]);});}applyNonShippingCoupons(t){let e=t.filter(i=>i.getType()==="coupon");if(e.length===1){let i=e[0].calculateApplicableCouponDiscount(this.total.subtotal,this.total.shippingCharge,this.country,this.currency);i.getAmount()>0&&(this.coupons.push(e[0]),this.total.discounts[e[0].getCode()]=i,this.total.totalDiscount=i);}}applyShippingCoupons(t){if(this.total.shippingCharge.getAmount()>0&&t.length>0){let e=this.total.subtotal.subtract(this.total.totalDiscount),i=t.reduce((s,a)=>{if(!s)return a;let d=a.calculateApplicableCouponDiscount(e,this.total.shippingCharge,this.country,this.currency).min(this.total.shippingCharge),l=s.calculateApplicableCouponDiscount(e,this.total.shippingCharge,this.country,this.currency).min(this.total.shippingCharge);return d===l?a.getType()==="coupon"?a:s:d.compareTo(l)>0?a:s}),r=i.calculateApplicableCouponDiscount(e,this.total.shippingCharge,this.country,this.currency).min(this.total.shippingCharge);r.getAmount()>0&&(this.coupons.push(i),this.total.discounts[i.getCode()]=r,this.total.totalDiscount=this.total.totalDiscount.add(r),this.total.netShippingCharge=this.total.shippingCharge.subtract(r));}}};module.exports=yt;//# sourceMappingURL=ShoppingContainer.js.map
2
2
  //# sourceMappingURL=ShoppingContainer.js.map