b23-lib 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) 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.map +1 -1
  8. package/dist/Classes/Address.mjs +1 -1
  9. package/dist/Classes/Base.d.mts +5 -5
  10. package/dist/Classes/Base.d.ts +5 -5
  11. package/dist/Classes/Base.js.map +1 -1
  12. package/dist/Classes/Base.mjs +1 -1
  13. package/dist/Classes/Cart.d.mts +27 -12
  14. package/dist/Classes/Cart.d.ts +27 -12
  15. package/dist/Classes/Cart.js +1 -1
  16. package/dist/Classes/Cart.js.map +1 -1
  17. package/dist/Classes/Cart.mjs +1 -1
  18. package/dist/Classes/Cart.mjs.map +1 -1
  19. package/dist/Classes/Common.d.mts +2 -93
  20. package/dist/Classes/Common.d.ts +2 -93
  21. package/dist/Classes/Coupon.d.mts +33 -15
  22. package/dist/Classes/Coupon.d.ts +33 -15
  23. package/dist/Classes/Coupon.js +1 -1
  24. package/dist/Classes/Coupon.js.map +1 -1
  25. package/dist/Classes/Coupon.mjs +1 -1
  26. package/dist/Classes/Customer.d.mts +2 -2
  27. package/dist/Classes/Customer.d.ts +2 -2
  28. package/dist/Classes/Customer.js.map +1 -1
  29. package/dist/Classes/Customer.mjs +1 -1
  30. package/dist/Classes/Customer.mjs.map +1 -1
  31. package/dist/Classes/CustomerAddress.d.mts +1 -1
  32. package/dist/Classes/CustomerAddress.d.ts +1 -1
  33. package/dist/Classes/CustomerAddress.js.map +1 -1
  34. package/dist/Classes/CustomerAddress.mjs +1 -1
  35. package/dist/Classes/Enum.d.mts +43 -2
  36. package/dist/Classes/Enum.d.ts +43 -2
  37. package/dist/Classes/Enum.js +1 -1
  38. package/dist/Classes/Enum.js.map +1 -1
  39. package/dist/Classes/Enum.mjs +1 -1
  40. package/dist/Classes/Error.d.mts +59 -0
  41. package/dist/Classes/Error.d.ts +59 -0
  42. package/dist/Classes/Error.js +2 -0
  43. package/dist/Classes/Error.js.map +1 -0
  44. package/dist/Classes/Error.mjs +2 -0
  45. package/dist/Classes/Error.mjs.map +1 -0
  46. package/dist/Classes/ImageInfo.js +1 -1
  47. package/dist/Classes/ImageInfo.js.map +1 -1
  48. package/dist/Classes/ImageInfo.mjs +1 -1
  49. package/dist/Classes/Inventory.d.mts +25 -6
  50. package/dist/Classes/Inventory.d.ts +25 -6
  51. package/dist/Classes/Inventory.js +1 -1
  52. package/dist/Classes/Inventory.js.map +1 -1
  53. package/dist/Classes/Inventory.mjs +1 -1
  54. package/dist/Classes/Inventory.mjs.map +1 -1
  55. package/dist/Classes/LineItem.d.mts +140 -58
  56. package/dist/Classes/LineItem.d.ts +140 -58
  57. package/dist/Classes/LineItem.js +1 -1
  58. package/dist/Classes/LineItem.js.map +1 -1
  59. package/dist/Classes/LineItem.mjs +1 -1
  60. package/dist/Classes/Order.d.mts +7 -51
  61. package/dist/Classes/Order.d.ts +7 -51
  62. package/dist/Classes/Order.js +1 -1
  63. package/dist/Classes/Order.js.map +1 -1
  64. package/dist/Classes/Order.mjs +1 -1
  65. package/dist/Classes/Order.mjs.map +1 -1
  66. package/dist/Classes/Payment.d.mts +4 -4
  67. package/dist/Classes/Payment.d.ts +4 -4
  68. package/dist/Classes/Payment.js.map +1 -1
  69. package/dist/Classes/Payment.mjs +1 -1
  70. package/dist/Classes/Payment.mjs.map +1 -1
  71. package/dist/Classes/Price.d.mts +1 -82
  72. package/dist/Classes/Price.d.ts +1 -82
  73. package/dist/Classes/Price.js +1 -1
  74. package/dist/Classes/Price.js.map +1 -1
  75. package/dist/Classes/Price.mjs +1 -1
  76. package/dist/Classes/Product.d.mts +103 -85
  77. package/dist/Classes/Product.d.ts +103 -85
  78. package/dist/Classes/Product.js +1 -1
  79. package/dist/Classes/Product.js.map +1 -1
  80. package/dist/Classes/Product.mjs +1 -1
  81. package/dist/Classes/Product.mjs.map +1 -1
  82. package/dist/Classes/ShoppingContainer.d.mts +79 -63
  83. package/dist/Classes/ShoppingContainer.d.ts +79 -63
  84. package/dist/Classes/ShoppingContainer.js +1 -1
  85. package/dist/Classes/ShoppingContainer.js.map +1 -1
  86. package/dist/Classes/ShoppingContainer.mjs +1 -1
  87. package/dist/Classes/TaxRule.d.mts +63 -0
  88. package/dist/Classes/TaxRule.d.ts +63 -0
  89. package/dist/Classes/TaxRule.js +2 -0
  90. package/dist/Classes/TaxRule.js.map +1 -0
  91. package/dist/Classes/TaxRule.mjs +2 -0
  92. package/dist/Classes/TaxRule.mjs.map +1 -0
  93. package/dist/Classes/TieredPrice.d.mts +75 -0
  94. package/dist/Classes/TieredPrice.d.ts +75 -0
  95. package/dist/Classes/TieredPrice.js +2 -0
  96. package/dist/Classes/TieredPrice.js.map +1 -0
  97. package/dist/Classes/TieredPrice.mjs +2 -0
  98. package/dist/Classes/TieredPrice.mjs.map +1 -0
  99. package/dist/Common-D-UoxwM0.d.ts +210 -0
  100. package/dist/Common-FbQ5-3QN.d.mts +210 -0
  101. package/dist/chunk-2SGUPNWZ.mjs +2 -0
  102. package/dist/chunk-2SGUPNWZ.mjs.map +1 -0
  103. package/dist/chunk-54RUAXYE.mjs +2 -0
  104. package/dist/chunk-54RUAXYE.mjs.map +1 -0
  105. package/dist/{chunk-ATUUYYQT.mjs → chunk-55SOBG62.mjs} +2 -2
  106. package/dist/chunk-55SOBG62.mjs.map +1 -0
  107. package/dist/{chunk-H5GPM4LA.mjs → chunk-5KD2EW7O.mjs} +2 -2
  108. package/dist/{chunk-H5GPM4LA.mjs.map → chunk-5KD2EW7O.mjs.map} +1 -1
  109. package/dist/chunk-72DR3HF2.mjs +2 -0
  110. package/dist/chunk-72DR3HF2.mjs.map +1 -0
  111. package/dist/chunk-AMIRIUMH.mjs +2 -0
  112. package/dist/chunk-AMIRIUMH.mjs.map +1 -0
  113. package/dist/chunk-CEGQFFYZ.mjs +2 -0
  114. package/dist/chunk-CEGQFFYZ.mjs.map +1 -0
  115. package/dist/chunk-EP7WVZXC.mjs +2 -0
  116. package/dist/chunk-EP7WVZXC.mjs.map +1 -0
  117. package/dist/chunk-KWH7GE23.mjs +2 -0
  118. package/dist/chunk-KWH7GE23.mjs.map +1 -0
  119. package/dist/chunk-LNIZAPER.mjs +2 -0
  120. package/dist/chunk-LNIZAPER.mjs.map +1 -0
  121. package/dist/chunk-NJKSUUOB.mjs +2 -0
  122. package/dist/chunk-NJKSUUOB.mjs.map +1 -0
  123. package/dist/chunk-NUTKOIGY.mjs +2 -0
  124. package/dist/chunk-NUTKOIGY.mjs.map +1 -0
  125. package/dist/chunk-RBROVHJ4.mjs +2 -0
  126. package/dist/chunk-RBROVHJ4.mjs.map +1 -0
  127. package/dist/index.d.mts +9 -6
  128. package/dist/index.d.ts +9 -6
  129. package/dist/index.js +2 -2
  130. package/dist/index.js.map +1 -1
  131. package/dist/index.mjs +2 -2
  132. package/dist/index.mjs.map +1 -1
  133. package/package.json +1 -1
  134. package/dist/chunk-6PDP4ETM.mjs +0 -2
  135. package/dist/chunk-6PDP4ETM.mjs.map +0 -1
  136. package/dist/chunk-ATUUYYQT.mjs.map +0 -1
  137. package/dist/chunk-CKUUUEWT.mjs +0 -2
  138. package/dist/chunk-CKUUUEWT.mjs.map +0 -1
  139. package/dist/chunk-DKI6BDWK.mjs +0 -2
  140. package/dist/chunk-DKI6BDWK.mjs.map +0 -1
  141. package/dist/chunk-K3AXPTGG.mjs +0 -2
  142. package/dist/chunk-K3AXPTGG.mjs.map +0 -1
  143. package/dist/chunk-LMMJSJTO.mjs +0 -2
  144. package/dist/chunk-LMMJSJTO.mjs.map +0 -1
  145. package/dist/chunk-RWBNLNQ6.mjs +0 -2
  146. package/dist/chunk-RWBNLNQ6.mjs.map +0 -1
  147. package/dist/chunk-V4H3X4PI.mjs +0 -2
  148. package/dist/chunk-V4H3X4PI.mjs.map +0 -1
  149. package/dist/chunk-WOMA746Z.mjs +0 -2
  150. package/dist/chunk-WOMA746Z.mjs.map +0 -1
@@ -1,67 +1,102 @@
1
- import { LocalizedString, Color, BasePrice, PriceTier, LocaleCode } from './Common.js';
1
+ import { P as PriceData, C as CountryCode, c as LocalizedString, d as LocalizedValue, b as PriceModel, L as LocaleCode, a as CurrencyCode } from '../Common-D-UoxwM0.js';
2
+ import CouponModel from './Coupon.js';
3
+ import { TaxCategory, TaxSystem, LineItemState } from './Enum.js';
2
4
  import ImageInfoModel, { ImageInfoData } from './ImageInfo.js';
3
- import { LocalizedProductSpecification, ProductSpecification } from './Product.js';
4
- import './Enum.js';
5
+ import ProductModel, { SelectionAttributes, ProductSpecification } from './Product.js';
6
+ import { TaxSlabs, TaxRuleModel } from './TaxRule.js';
7
+ import { TieredPriceData, TieredPriceModel } from './TieredPrice.js';
5
8
  import './Base.js';
6
9
  import '../Auth/index.js';
7
10
 
8
11
  type SubItem = {
9
- size: string;
12
+ size: string | 'ONESIZE';
10
13
  quantity: number;
11
14
  };
15
+ type LineItemPricing = {
16
+ unitPrice: PriceData;
17
+ tierPricing: TieredPriceData;
18
+ taxCategory: TaxCategory;
19
+ tax: {
20
+ taxRuleId: string;
21
+ taxSystem: TaxSystem;
22
+ country: CountryCode;
23
+ rate: number;
24
+ taxSlabs: TaxSlabs;
25
+ };
26
+ };
27
+ type LineItemTotals = {
28
+ quantity: number;
29
+ subtotal: PriceData;
30
+ discounts: Record<string, PriceData>;
31
+ taxableAmount: PriceData;
32
+ taxTotal: PriceData;
33
+ grandTotal: PriceData;
34
+ };
12
35
  type LineItemAttributes = {
13
36
  id: string;
14
37
  productKey: string;
15
- variantId: string;
38
+ selectionAttribute: SelectionAttributes;
16
39
  name: LocalizedString;
17
- attributes: {
18
- color: Color;
19
- };
20
- specifications: LocalizedProductSpecification;
40
+ specifications: LocalizedValue<ProductSpecification>;
21
41
  primaryImage: ImageInfoData;
22
42
  subItems: SubItem[];
23
- basePrice: BasePrice;
24
- priceTiers: PriceTier[];
25
- };
26
- type LineItemData = LineItemAttributes & {
27
- totalQuantity: number;
28
- priceTotals: {
29
- subtotal: number;
30
- mrpTotal: number;
31
- };
43
+ pricing: LineItemPricing;
44
+ state?: LineItemState;
45
+ total: LineItemTotals;
32
46
  };
47
+ type LineItemData = Required<LineItemAttributes>;
33
48
  /**
34
49
  * Represents a line item within a shopping cart.
35
50
  */
36
51
  declare class LineItemModel {
37
52
  protected id: string;
38
53
  protected productKey: string;
39
- protected variantId: string;
54
+ protected selectionAttribute: SelectionAttributes;
40
55
  protected name: LocalizedString;
41
- protected attributes: {
42
- color: Color;
43
- };
44
- protected specifications: LocalizedProductSpecification;
56
+ protected specifications: LocalizedValue<ProductSpecification>;
45
57
  protected primaryImage: ImageInfoModel;
46
58
  protected subItems: SubItem[];
47
- protected totalQuantity: number;
48
- protected basePrice: BasePrice;
49
- protected priceTotals: {
50
- subtotal: number;
51
- mrpTotal: number;
59
+ protected pricing: {
60
+ unitPrice: PriceModel;
61
+ tierPricing: TieredPriceModel;
62
+ taxCategory: TaxCategory;
63
+ tax: {
64
+ taxRuleId: string;
65
+ taxSystem: TaxSystem;
66
+ country: CountryCode;
67
+ taxSlabs: TaxSlabs;
68
+ rate: number;
69
+ };
70
+ };
71
+ protected state: LineItemState;
72
+ protected total: {
73
+ quantity: number;
74
+ subtotal: PriceModel;
75
+ discounts: Record<string, PriceModel>;
76
+ taxableAmount: PriceModel;
77
+ taxTotal: PriceModel;
78
+ grandTotal: PriceModel;
52
79
  };
53
- protected priceTiers: PriceTier[];
54
80
  /**
55
81
  * Creates an instance of LineItemModel.
56
82
  * @param data - The initial line item attributes.
57
83
  */
58
84
  constructor(data: LineItemAttributes);
59
- /** Gets the unique identifier of the line item. */
85
+ /**
86
+ * Gets the unique identifier of the line item.
87
+ * @returns The unique ID string.
88
+ */
60
89
  getId(): string;
61
- /** Gets the product key associated with this line item. */
90
+ /**
91
+ * Gets the product key associated with this line item.
92
+ * @returns The product key string.
93
+ */
62
94
  getProductKey(): string;
63
- /** Gets the product variant ID associated with this line item. */
64
- getVariantId(): string;
95
+ /**
96
+ * Gets the selection attributes (e.g., size, color) for this line item.
97
+ * @returns A copy of the selection attributes object.
98
+ */
99
+ getSelectionAttribute(): SelectionAttributes;
65
100
  /**
66
101
  * Gets the full localized product name object.
67
102
  * @returns A copy of the LocalizedString object for the name.
@@ -73,45 +108,67 @@ declare class LineItemModel {
73
108
  * @returns The name string for the specified locale.
74
109
  */
75
110
  getName(locale: LocaleCode): string;
76
- /** Gets the variant attributes. */
77
- getAttributes(): {
78
- color: Color;
79
- };
80
111
  /**
81
112
  * Gets the full localized product specifications object.
82
113
  * @returns Product Specifications
83
114
  */
84
- getSpecifications(): LocalizedProductSpecification;
115
+ getSpecifications(): LocalizedValue<ProductSpecification>;
85
116
  /**
86
117
  * Gets the product specifications for a specific locale, falling back to English ('en').
87
118
  * @param locale - The desired locale code.
88
119
  * @returns The ProductSpecification object for the specified locale, or undefined if not found.
89
120
  */
90
121
  getSpecifications(locale: LocaleCode): ProductSpecification | undefined;
91
- /** Gets the image information model for this line item. */
122
+ /**
123
+ * Gets the image information model for this line item.
124
+ * @returns The ImageInfoModel instance.
125
+ */
92
126
  getImage(): ImageInfoModel;
93
- /** Gets the sub-items (size/quantity breakdown). */
127
+ /**
128
+ * Gets the sub-items (size/quantity breakdown).
129
+ * @returns A copy of the array of SubItems.
130
+ */
94
131
  getSubItems(): SubItem[];
95
- /** Gets the total quantity for this line item across all sub-items. */
132
+ /**
133
+ * Gets the total quantity for this line item across all sub-items.
134
+ * @returns The total quantity as a number.
135
+ */
96
136
  getTotalQuantity(): number;
97
- /** Gets the base price for a single unit. */
98
- getBasePrice(): BasePrice;
99
- /** Gets the calculated price details (subtotal, mrpTotal) for this line item. */
100
- getPriceTotals(): {
101
- subtotal: number;
102
- mrpTotal: number;
137
+ /**
138
+ * Gets the pricing information model for this line item.
139
+ * @returns An object containing unit price, tiered pricing, tax category, and tax details.
140
+ */
141
+ getPricing(): {
142
+ unitPrice: PriceModel;
143
+ tierPricing: TieredPriceModel;
144
+ taxCategory: TaxCategory;
145
+ tax: {
146
+ taxRuleId: string;
147
+ taxSystem: TaxSystem;
148
+ country: "IN";
149
+ rate: number;
150
+ taxSlabs: TaxSlabs;
151
+ };
103
152
  };
104
- /** Gets the applicable price tiers for this product variant. */
105
- getPriceTiers(): PriceTier[];
106
153
  /**
107
- * Recalculates the total quantity based on the quantities in subItems.
154
+ * Gets the current state of the line item.
155
+ * @returns The LineItemState enum value.
108
156
  */
109
- protected recalculateTotalQuantity(): void;
157
+ getState(): LineItemState;
110
158
  /**
111
- * Recalculates the line item's price (subtotal and mrpTotal)
112
- * based on total quantity, base price, and applicable price tiers.
159
+ * Gets the total price for this line item (including all sub-items).
160
+ * @returns An object containing line item totals including subtotal, tax, discounts, and grand total.
113
161
  */
114
- protected recalculatePriceTotal(): void;
162
+ getTotal(): {
163
+ quantity: number;
164
+ subtotal: PriceModel;
165
+ taxableAmount: PriceModel;
166
+ taxTotal: PriceModel;
167
+ discounts: {
168
+ [k: string]: PriceModel;
169
+ };
170
+ grandTotal: PriceModel;
171
+ };
115
172
  /**
116
173
  * Gets a plain data object representing the line item's details.
117
174
  * @returns LineItemData.
@@ -122,19 +179,44 @@ declare class LineItemModel {
122
179
  * If a sub-item with the same size already exists, its quantity is either
123
180
  * updated by adding the new quantity or replaced entirely, based on the `addQuantity` flag.
124
181
  * Sub-items with a resulting quantity of 0 are removed.
125
- * Recalculates total quantity and price totals afterwards.
126
- *
127
182
  * @param subItems - An array of `SubItem` objects to add or update.
128
183
  * @param addQuantity - If true, adds the quantity from `subItem` to the existing quantity.
129
184
  * If false, replaces the existing quantity with the one from `subItem`.
130
185
  */
131
186
  addSubItems(subItems: SubItem[], addQuantity: boolean): void;
187
+ /**
188
+ * Updates the line item with the latest product data (price, image, name, specifications).
189
+ * Validates that the product matches the line item's selection and is active.
190
+ * @param product - The product model to update from.
191
+ * @param cartCountry - The country code for pricing context.
192
+ * @param cartCurrency - The currency code for pricing context.
193
+ * @throws {Error} If product mismatch, inactive, size mismatch, or pricing missing.
194
+ */
195
+ updateProductData(product: ProductModel, cartCountry: CountryCode, cartCurrency: CurrencyCode): void;
196
+ /**
197
+ * Updates the discounts applied to this line item and recalculates totals.
198
+ * @param appliedDiscounts - List of coupons and their allocated discount amounts.
199
+ */
200
+ updateDiscounts(appliedDiscounts: {
201
+ coupon: CouponModel;
202
+ amount: PriceModel;
203
+ }[]): void;
204
+ /**
205
+ * Updates the tax rule for this line item and recalculates totals.
206
+ * @param taxRule - The new tax rule to apply.
207
+ * @throws {Error} If the tax rule category does not match the item's tax category.
208
+ */
209
+ updateTax(taxRule: TaxRuleModel): void;
210
+ /**
211
+ * Recalculates the line item totals based on current quantity, unit price, discounts, and tax rates.
212
+ */
213
+ calculateTotals(): void;
132
214
  /**
133
215
  * Resets the line item's properties to their default empty or initial state.
134
216
  * Useful for clearing out line item data without creating a new instance.
135
- * Recalculates total quantity and price totals afterwards (which will be zero).
217
+ * Recalculates total quantity and price total afterwards (which will be zero).
136
218
  */
137
219
  clearLineItem(): void;
138
220
  }
139
221
 
140
- export { type LineItemAttributes, type LineItemData, type SubItem, LineItemModel as default };
222
+ export { type LineItemAttributes, type LineItemData, type LineItemPricing, type LineItemTotals, type SubItem, LineItemModel as default };
@@ -1,2 +1,2 @@
1
- 'use strict';var n={"en-IN":"en","kn-IN":"kn"};var s=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 "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 "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 o=class{id;productKey;variantId;name;attributes;specifications;primaryImage;subItems;totalQuantity;basePrice;priceTotals;priceTiers;constructor(t){this.id=t.id,this.productKey=t.productKey,this.variantId=t.variantId,this.name={...t.name},this.attributes={...t.attributes},this.specifications={...t.specifications},this.primaryImage=new s(t.primaryImage),this.subItems=t.subItems.map(e=>({...e})),this.basePrice={...t.basePrice},this.priceTiers=t.priceTiers.map(e=>({...e})),this.totalQuantity=0,this.priceTotals={subtotal:0,mrpTotal:0},this.recalculateTotalQuantity(),this.recalculatePriceTotal();}getId(){return this.id}getProductKey(){return this.productKey}getVariantId(){return this.variantId}getName(t){return t?this.name[t]??this.name[n[t]]??this.name.en:{...this.name}}getAttributes(){return {...this.attributes}}getSpecifications(t){return t?this.specifications[t]??this.specifications[n[t]]??this.specifications.en:JSON.parse(JSON.stringify(this.specifications))}getImage(){return this.primaryImage}getSubItems(){return this.subItems.map(t=>({...t}))}getTotalQuantity(){return this.totalQuantity}getBasePrice(){return {...this.basePrice}}getPriceTotals(){return {...this.priceTotals}}getPriceTiers(){return this.priceTiers.map(t=>({...t}))}recalculateTotalQuantity(){this.totalQuantity=this.subItems.reduce((t,e)=>t+e.quantity,0);}recalculatePriceTotal(){let t=this.totalQuantity,e=this.basePrice.unitPrice,i=null;for(let r of this.priceTiers.sort((a,l)=>l.minQuantity-a.minQuantity))if(t>=r.minQuantity){i=r;break}i&&(e=i.unitPrice),this.priceTotals.mrpTotal=this.basePrice.unitPrice*t,this.priceTotals.subtotal=e*t;}getDetails(){return {id:this.getId(),productKey:this.getProductKey(),variantId:this.getVariantId(),name:this.getName(),attributes:this.getAttributes(),specifications:this.getSpecifications(),primaryImage:this.getImage().getDetails(),subItems:this.getSubItems(),totalQuantity:this.getTotalQuantity(),basePrice:this.getBasePrice(),priceTotals:this.getPriceTotals(),priceTiers:this.getPriceTiers()}}addSubItems(t,e){t.forEach(i=>{let r=this.subItems.find(a=>a.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),this.recalculateTotalQuantity(),this.recalculatePriceTotal();}clearLineItem(){this.id="",this.productKey="",this.variantId="",this.name={en:""},this.attributes={color:{name:"",hex:""}},this.primaryImage=new s({sources:{original:""}}),this.subItems=[],this.recalculateTotalQuantity(),this.recalculatePriceTotal();}};module.exports=o;//# sourceMappingURL=LineItem.js.map
1
+ 'use strict';var re=require('crypto');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var re__default=/*#__PURE__*/_interopDefault(re);var D=new Uint8Array(256),P=D.length;function V(){return P>D.length-16&&(re__default.default.randomFillSync(D),P=0),D.slice(P,P+=16)}var X=/^(?:[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 ie(r){return typeof r=="string"&&X.test(r)}var W=ie;var g=[];for(let r=0;r<256;++r)g.push((r+256).toString(16).slice(1));function v(r,e=0){return g[r[e+0]]+g[r[e+1]]+g[r[e+2]]+g[r[e+3]]+"-"+g[r[e+4]]+g[r[e+5]]+"-"+g[r[e+6]]+g[r[e+7]]+"-"+g[r[e+8]]+g[r[e+9]]+"-"+g[r[e+10]]+g[r[e+11]]+g[r[e+12]]+g[r[e+13]]+g[r[e+14]]+g[r[e+15]]}function ne(r){if(!W(r))throw TypeError("Invalid UUID");let e,t=new Uint8Array(16);return t[0]=(e=parseInt(r.slice(0,8),16))>>>24,t[1]=e>>>16&255,t[2]=e>>>8&255,t[3]=e&255,t[4]=(e=parseInt(r.slice(9,13),16))>>>8,t[5]=e&255,t[6]=(e=parseInt(r.slice(14,18),16))>>>8,t[7]=e&255,t[8]=(e=parseInt(r.slice(19,23),16))>>>8,t[9]=e&255,t[10]=(e=parseInt(r.slice(24,36),16))/1099511627776&255,t[11]=e/4294967296&255,t[12]=e>>>24&255,t[13]=e>>>16&255,t[14]=e>>>8&255,t[15]=e&255,t}var J=ne;function oe(r){r=unescape(encodeURIComponent(r));let e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t));return e}var se="6ba7b810-9dad-11d1-80b4-00c04fd430c8",ae="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function G(r,e,t){function i(n,s,u,d){var a;if(typeof n=="string"&&(n=oe(n)),typeof s=="string"&&(s=J(s)),((a=s)===null||a===void 0?void 0:a.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let l=new Uint8Array(16+n.length);if(l.set(s),l.set(n,s.length),l=t(l),l[6]=l[6]&15|e,l[8]=l[8]&63|128,u){d=d||0;for(let x=0;x<16;++x)u[d+x]=l[x];return u}return v(l)}try{i.name=r;}catch{}return i.DNS=se,i.URL=ae,i}var j={randomUUID:re__default.default.randomUUID};function ue(r,e,t){if(j.randomUUID&&!e&&!r)return j.randomUUID();r=r||{};let i=r.random||(r.rng||V)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,e){t=t||0;for(let n=0;n<16;++n)e[t+n]=i[n];return e}return v(i)}var Y=ue;function ge(r){return Array.isArray(r)?r=Buffer.from(r):typeof r=="string"&&(r=Buffer.from(r,"utf8")),re__default.default.createHash("sha1").update(r).digest()}var _=ge;var de=G("v5",80,_),H=de;var b=class{customFields;version;createdAt;modifiedAt;modifiedBy;constructor(e,t=new Date){this.customFields={...e.customFields},this.version=e.version??1,this.createdAt=e.createdAt&&!isNaN(Date.parse(e.createdAt))?new Date(e.createdAt).toISOString():t.toISOString(),this.modifiedAt=e.modifiedAt&&!isNaN(Date.parse(e.modifiedAt))?new Date(e.modifiedAt).toISOString():t.toISOString(),this.modifiedBy={...e.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(e,t,i,n){this.modifiedBy={id:e,authType:t,requestId:i,lambdaName:n};}getCustomField(e){return this.customFields[e]??null}setCustomField(e,t){this.customFields[e]=t;}getAllCustomFields(){return {...this.customFields}}};var y={"en-IN":"en","kn-IN":"kn"};var ee={INR:"\u20B9"},te={INR:"en-IN"};var w=class extends Error{constructor(e){super(`Duplicate size found: ${e}`),this.name="DuplicateSizeError";}},M=class extends Error{constructor(e="Product and selection attributes do not match."){super(`ProductMismatch: ${e}`),this.name="ProductMismatchError";}},E=class extends Error{constructor(e="Product is not active."){super(`ProductInactive: ${e}`),this.name="ProductInactiveError";}},L=class extends Error{constructor(e="Failed to parse selection attributes key."){super(`SelectionAttributeParseError: ${e}`),this.name="SelectionAttributeParseError";}},R=class extends Error{constructor(e="Size does not match."){super(`SizeMismatch: ${e}`),this.name="SizeMismatchError";}},U=class extends Error{constructor(e="Pricing details not available for the product"){super(`NotFound: ${e}`),this.name="PricingNotFoundError";}},N=class extends Error{constructor(e="Tax rule category mismatch."){super(`InvalidTaxRule: ${e}`),this.name="InvalidTaxRuleError";}},z=class extends Error{constructor(e="Tax category is not valid."){super(`InvalidTaxCategory: ${e}`),this.name="InvalidTaxCategoryError";}},O=class extends Error{constructor(e="Minimum quantity must be greater than zero."){super(`InvalidMinQuantity: ${e}`),this.name="InvalidMinQuantityError";}},F=class extends Error{constructor(e){super(`InvalidTieredPrice: ${e}`),this.name="InvalidTieredPriceError";}},B=class extends Error{constructor(e="Quantity must be greater than zero."){super(`InvalidQuantity: ${e}`),this.name="InvalidQuantityError";}},$=class extends Error{constructor(e){super(`NoApplicableTier: Quantity ${e} does not meet the minimum purchase requirement.`),this.name="NoApplicableTierError";}},k=class extends Error{constructor(e="No applicable tax slab or multiple slabs found for the given unit price."){super(`TaxSlabNotFound: ${e}`),this.name="TaxSlabNotFoundError";}},T=class extends Error{constructor(e="Amount cannot be negative."){super(`InvalidAmount: ${e}`),this.name="InvalidPriceAmountError";}},I=class extends Error{constructor(e="Currency code is required."){super(`InvalidCurrency: ${e}`),this.name="InvalidCurrencyCodeError";}},h=class extends Error{constructor(e="Cannot perform operation on prices with different currencies."){super(`CurrencyMismatch: ${e}`),this.name="CurrencyMismatchError";}},p=class extends Error{constructor(e){super(`InvalidArgument: ${e}`),this.name="InvalidArgumentError";}},S=class extends Error{constructor(e="Invalid image source configuration."){super(`InvalidImageSource: ${e}`),this.name="InvalidImageSourceError";}};var f=class{sources;alt;order;label;constructor(e){if(this.sources={...e.sources},this.alt=e.alt,this.order=e.order,this.label=e.label,!this.sources.original)throw new S("ImageInfoModel cannot be created without an 'original' source URL.")}getSources(){return {...this.sources}}getSource(e){return this.sources[e]||this.sources.original}getAlt(){return this.alt}getOrder(){return this.order}getLabel(){return this.label}setAlt(e){this.alt=e;}setOrder(e){this.order=e;}setLabel(e){this.label=e;}setSource(e,t){if(t===void 0){if(e==="original")throw new S("Cannot remove the 'original' image source.");delete this.sources[e];}else this.sources[e]=t;}getDetails(){return {sources:this.getSources(),alt:this.getAlt(),order:this.getOrder(),label:this.getLabel()}}};var m=class r{amount;currency;constructor(e){if(e.amount<0)throw new T("Amount cannot be negative.");if(!e.currency)throw new I("Currency code is required.");this.amount=e.amount,this.currency=e.currency;}getCurrency(){return this.currency}getAmount(){return this.amount}getDetails(){return {amount:this.amount,currency:this.currency}}compareTo(e){if(e instanceof r){if(this.currency!==e.getCurrency())throw new h("Cannot compare prices in different currencies.")}else throw new p("Must be a PriceModel instance.");return this.amount-e.getAmount()}add(e){if(e instanceof r){if(this.currency!==e.getCurrency())throw new h("Cannot add prices in different currencies.")}else throw new p("Must be a PriceModel instance.");return new r({amount:this.amount+e.getAmount(),currency:this.currency})}subtract(e){if(e instanceof r){if(this.currency!==e.getCurrency())throw new h("Cannot subtract prices in different currencies.")}else throw new p("Must be a PriceModel instance.");return new r({amount:this.amount-e.getAmount(),currency:this.currency})}multiply(e){if(e instanceof r){if(this.currency!==e.getCurrency())throw new h("Cannot multiply prices in different currencies.");return new r({amount:this.amount*e.getAmount(),currency:this.currency})}else if(typeof e=="number"&&e>=0)return new r({amount:this.amount*e,currency:this.currency});throw new p("Must be a non-negative number.")}divide(e){if(e instanceof r){if(this.currency!==e.getCurrency())throw new h("Cannot divide prices in different currencies.");return new r({amount:this.amount/e.getAmount(),currency:this.currency})}else if(typeof e=="number"&&e>0)return new r({amount:this.amount/e,currency:this.currency});throw new p("Must be a positive number.")}min(...e){if(e.length===0)throw new p("Must provide at least one PriceModel.");return e.reduce((t,i)=>{if(i instanceof r){if(t.getCurrency()!==i.getCurrency())throw new h("Cannot compare prices in different currencies.")}else throw new p("Must be a PriceModel instance.");return t.compareTo(i)<0?t:i})}max(...e){if(e.length===0)throw new p("Must provide at least one PriceModel.");return e.reduce((t,i)=>{if(i instanceof r){if(t.getCurrency()!==i.getCurrency())throw new h("Cannot compare prices in different currencies.")}else throw new p("Must be a PriceModel instance.");return t.compareTo(i)>0?t:i})}zero(){return new r({currency:this.currency,amount:0})}isZero(){return this.amount===0}round(){return new r({currency:this.currency,amount:this.getRoundedAmount()})}getRoundedAmount(){return r.getRoundedAmount(this.amount,this.currency)}getFormattedString(){return r.getFormattedString(this.amount,this.currency)}static getFormattedString(e,t,i={displayAsInteger:!1,style:"currency",currencyDisplay:"symbol"}){let n=te[t];if(!t||!n)throw new I("Invalid currency code for formatting.");let s=e,u=i.displayAsInteger?0:r.getDecimalPlaces(t),d={style:i.style??"currency",currency:t,signDisplay:"never",currencyDisplay:i.currencyDisplay,minimumFractionDigits:u,maximumFractionDigits:u};i.displayAsInteger&&(s=Math.ceil(s));try{return new Intl.NumberFormat(n,d).format(s)}catch(a){return console.error(`Error formatting price for currency "${t}" and locale "${n}":`,a),`${ee[t]??t} ${r.addThousandSeparators(s.toFixed(u))}`}}static getDecimalPlaces(e){switch(e){case"INR":default:return 2}}static addThousandSeparators(e){let t=e.split("."),i=t[0],n=t.length>1?"."+t[1]:"";return i.replace(/\B(?=(\d{3})+(?!\d))/g,",")+n}static getRoundedAmount(e,t){if(e<0)throw new T("Amount cannot be negative for rounding.");if(t===void 0)throw new I("Invalid currency code for rounding.");let i=r.getDecimalPlaces(t),n=Math.pow(10,i);return Math.round(e*n)/n}};var C=class{baseUnitPrice;taxCategory;tiers;constructor(e){let t=new m(e.baseUnitPrice);if(!e.taxCategory)throw new z;let i=(e.tiers??[]).map(a=>({minQuantity:a.minQuantity,unitPrice:new m(a.unitPrice)})).sort((a,l)=>a.minQuantity-l.minQuantity);if(i.some(a=>a.minQuantity<=0))throw new O;let s=i.some(a=>a.unitPrice.getCurrency()!==t.getCurrency()),u=i.some((a,l)=>l>0&&a.unitPrice.compareTo(i[l-1].unitPrice)>0),d=i[0]?.unitPrice.compareTo(t)>0;if(s||u||d)throw new F("Tiers must share the same currency and must not increase in unit price.");this.baseUnitPrice=t,this.taxCategory=e.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(e=>({minQuantity:e.minQuantity,unitPrice:e.unitPrice.getDetails()}))}}getApplicableTier(e){if(e<=0)throw new B;for(let t=this.tiers.length-1;t>=0;t--)if(e>=this.tiers[t].minQuantity)return this.tiers[t];throw new $(e)}getMinQuantity(){return this.tiers[0]?.minQuantity??1}getMaxDiscountPercent(){if(!this.tiers.length)return 0;let e=this.tiers[this.tiers.length-1].unitPrice.getAmount(),t=this.baseUnitPrice.getAmount();return (t-e)/t*100}};var A=class r extends b{id;key;sku;name;description;slug;brand;pricing;variants;targetGender;attributes;specifications;categories;isActive;searchTags;static productKeyRegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static generateSelectionAttributesKey(e){return Object.keys(e).filter(i=>e[i]!==void 0&&i.toLowerCase()!=="size").sort().map(i=>e[i].name?`${i}:c+${e[i].name}`:`${i}:${e[i]}`).join("|")}static parseSelectionAttributesKey(e){try{let t={},i=e.split("|");for(let n of i){let[s,u]=n.split(":");u.startsWith("c+")?t[s]={name:u.slice(2)}:t[s]=u;}return t}catch(t){throw new L(t?.message)}}constructor(e,t=new Date){super(e,t),this.id=e.id,this.key=e.key,this.sku=e.sku,this.name={...e.name},this.description={...e.description},this.slug={...e.slug},this.brand=e.brand,this.pricing=Object.keys(e.pricing).reduce((i,n)=>(e.pricing[n]&&(i[n]=new C(e.pricing[n])),i),{}),this.targetGender=e.targetGender,this.attributes=o.deepClone(e.attributes),this.specifications=o.deepClone(e.specifications),this.categories=o.deepClone(e.categories),this.variants=(e.variants||[]).map(i=>({selectionAttributes:i.selectionAttributes,images:{primary:new f(i.images.primary),gallery:(i.images.gallery||[]).map(n=>new f(n))}})),this.isActive=e.isActive,this.searchTags=e.searchTags?o.deepClone(e.searchTags):{en:[]};}getId(){return this.id}getKey(){return this.key}getSku(){return this.sku}getName(e){return e?this.name[e]??this.name[y[e]]??this.name.en:o.deepClone(this.name)}getDescription(e){return e?this.description[e]??this.description[y[e]]??this.description.en:o.deepClone(this.description)}getSlug(e){return e?this.slug[e]??this.slug[y[e]]??this.slug.en:o.deepClone(this.slug)}getBrand(){return this.brand}getPriceDetails(e){return e?this.pricing[e]??null:this.pricing}getAttributes(){return o.deepClone(this.attributes)}getImagesBySelectionAttributes(e){let t=r.generateSelectionAttributesKey(e),i=this.variants.find(n=>r.generateSelectionAttributesKey(n.selectionAttributes)===t);return i?i.images:null}getImages(e,t){switch(t){case"PRIMARY":return this.getImagesBySelectionAttributes(e)?.primary??this.variants[0]?.images?.primary;case"GALLERY":return this.getImagesBySelectionAttributes(e)?.gallery??[];default:return this.getImagesBySelectionAttributes(e)??{primary:this.variants[0]?.images?.primary,gallery:[]}}}getIsActive(){return this.isActive}getTargetGender(){return this.targetGender}getCategories(){return o.deepClone(this.categories)}getSpecifications(e){return e?o.deepClone(this.specifications[e]??this.specifications[y[e]]??this.specifications.en):o.deepClone(this.specifications)}getSearchTags(e){return e?o.deepClone(this.searchTags[e]??this.searchTags[y[e]]??this.searchTags.en):o.deepClone(this.searchTags)}getDetails(){let e=super.getDetails();return {id:this.getId(),key:this.getKey(),sku:this.getSku(),name:this.getName(),description:this.getDescription(),slug:this.getSlug(),brand:this.getBrand(),pricing:Object.keys(this.pricing).reduce((t,i)=>(this.pricing[i]&&(t[i]=this.pricing[i]?.getDetails()),t),{}),attributes:this.getAttributes(),variants:this.variants.map(t=>({selectionAttributes:o.deepClone(t.selectionAttributes),images:{primary:t.images.primary.getDetails(),gallery:t.images.gallery.map(i=>i.getDetails())}})),isActive:this.getIsActive(),targetGender:this.getTargetGender(),categories:this.getCategories(),specifications:this.getSpecifications(),searchTags:this.getSearchTags(),...e}}validateSelectionAttribute(e){let t=r.generateSelectionAttributesKey(e);return this.variants.some(i=>r.generateSelectionAttributesKey(i.selectionAttributes)===t)}validateSize(e){return this.attributes.size.includes(e)}};var me={isUUID:r=>/^[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(r),isEmail:r=>/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(r),isURL:r=>/^(http|https):\/\/[^ "]+$/.test(r),generateUUID:(r,e)=>e&&r?H(r,e):Y(),generateSearchId:(r,e)=>`${r}#${A.generateSelectionAttributesKey(e)}`,getKeyfromSearchId:r=>{let[e,t]=r.split("#");return {key:e,selectionAttribute:t}},deepClone(r){return structuredClone(r)}},o=me;var q=class r extends b{taxRuleId;taxSystem;taxCategory;country;slabs;effectiveFrom;effectiveTo;constructor(e,t=new Date){super(e,t),this.taxRuleId=e.taxRuleId,this.taxSystem=e.taxSystem,this.taxCategory=e.taxCategory,this.country=e.country,this.slabs=o.deepClone(e.slabs),this.effectiveFrom=new Date(e.effectiveFrom),this.effectiveTo=e.effectiveTo?new Date(e.effectiveTo):void 0;}getTaxRuleId(){return this.taxRuleId}getTaxSystem(){return this.taxSystem}getTaxCategory(){return this.taxCategory}getCountry(){return this.country}getSlabs(){return o.deepClone(this.slabs)}getDetails(){return {taxRuleId:this.getTaxRuleId(),taxSystem:this.getTaxSystem(),taxCategory:this.getTaxCategory(),country:this.getCountry(),slabs:this.getSlabs(),effectiveFrom:this.effectiveFrom.toISOString(),effectiveTo:this.effectiveTo?this.effectiveTo.toISOString():void 0,...super.getDetails()}}appliesTo(e,t,i=new Date){return this.taxCategory===e&&this.country===t&&this.effectiveFrom<=i&&(this.effectiveTo?this.effectiveTo>=i:!0)}getApplicableTaxRate(e){return r.getApplicableTaxRate(e,this.slabs)}static getApplicableTaxRate(e,t){let i=e.getAmount(),n=t.filter(s=>(s.minUnitPrice===void 0||i>=s.minUnitPrice)&&(s.maxUnitPrice===void 0||i<s.maxUnitPrice));if(n.length!==1)throw new k;return n[0].rate}};var Z=class{id;productKey;selectionAttribute;name;specifications;primaryImage;subItems;pricing;state;total;constructor(e){this.id=e.id,this.productKey=e.productKey,this.selectionAttribute=o.deepClone(e.selectionAttribute),this.name=o.deepClone(e.name),this.specifications=o.deepClone(e.specifications),this.primaryImage=new f(e.primaryImage),this.subItems=o.deepClone(e.subItems);let t=new Set;this.subItems.forEach(i=>{if(t.has(i.size))throw new w(i.size);t.add(i.size);}),this.pricing={unitPrice:new m(e.pricing.unitPrice),tierPricing:new C(e.pricing.tierPricing),taxCategory:e.pricing.taxCategory,tax:{taxRuleId:e.pricing.tax.taxRuleId,taxSystem:e.pricing.tax.taxSystem,country:e.pricing.tax.country,rate:e.pricing.tax.rate,taxSlabs:o.deepClone(e.pricing.tax.taxSlabs)}},this.state=e.state??"INITIAL",this.total={quantity:e.total.quantity,subtotal:new m(e.total.subtotal),discounts:Object.fromEntries(Object.entries(e.total.discounts).map(([i,n])=>[i,new m(n)])),taxableAmount:new m(e.total.taxableAmount),taxTotal:new m(e.total.taxTotal),grandTotal:new m(e.total.grandTotal)};}getId(){return this.id}getProductKey(){return this.productKey}getSelectionAttribute(){return o.deepClone(this.selectionAttribute)}getName(e){return e?o.deepClone(this.name[e]??this.name[y[e]]??this.name.en):o.deepClone(this.name)}getSpecifications(e){return e?o.deepClone(this.specifications[e]??this.specifications[y[e]]??this.specifications.en):o.deepClone(this.specifications)}getImage(){return this.primaryImage}getSubItems(){return o.deepClone(this.subItems)}getTotalQuantity(){return this.total.quantity}getPricing(){return {unitPrice:this.pricing.unitPrice,tierPricing:this.pricing.tierPricing,taxCategory:this.pricing.taxCategory,tax:{taxRuleId:this.pricing.tax.taxRuleId,taxSystem:this.pricing.tax.taxSystem,country:this.pricing.tax.country,rate:this.pricing.tax.rate,taxSlabs:o.deepClone(this.pricing.tax.taxSlabs)}}}getState(){return this.state}getTotal(){return {quantity:this.total.quantity,subtotal:this.total.subtotal,taxableAmount:this.total.taxableAmount,taxTotal:this.total.taxTotal,discounts:Object.fromEntries(Object.entries(this.total.discounts).map(([e,t])=>[e,t])),grandTotal:this.total.grandTotal}}getDetails(){return {id:this.getId(),productKey:this.getProductKey(),selectionAttribute:this.getSelectionAttribute(),name:this.getName(),specifications:this.getSpecifications(),primaryImage:this.getImage().getDetails(),subItems:this.getSubItems(),pricing:{unitPrice:this.getPricing().unitPrice.getDetails(),tierPricing:this.getPricing().tierPricing.getDetails(),taxCategory:this.getPricing().taxCategory,tax:this.getPricing().tax},state:this.getState(),total:{quantity:this.getTotal().quantity,subtotal:this.getTotal().subtotal.getDetails(),taxableAmount:this.getTotal().taxableAmount.getDetails(),taxTotal:this.getTotal().taxTotal.getDetails(),discounts:Object.fromEntries(Object.entries(this.getTotal().discounts).map(([e,t])=>[e,t.getDetails()])),grandTotal:this.getTotal().grandTotal.getDetails()}}}addSubItems(e,t){e.forEach(i=>{let n=this.subItems.find(s=>s.size===i.size);n?n.quantity=t?n.quantity+i.quantity:i.quantity:this.subItems.push(i);}),this.subItems=this.subItems.filter(i=>i.quantity>=0),this.calculateTotals();}updateProductData(e,t,i){if(this.productKey!==e.getKey()||!e.validateSelectionAttribute(this.selectionAttribute))throw new M;if(!e.getIsActive())throw new E;this.subItems.forEach(d=>{if(!e.validateSize(d.size))throw new R});let n=e.getPriceDetails(t);if(!n||n.getBaseUnitPrice().getCurrency()!==i)throw new U;this.name=e.getName(),this.specifications=e.getSpecifications(),this.primaryImage=e.getImages(this.selectionAttribute).primary;let s=this.subItems.reduce((d,a)=>d+a.quantity,0),{unitPrice:u}=n.getApplicableTier(s);this.pricing={unitPrice:u,tierPricing:n,taxCategory:n.getTaxCategory(),tax:this.pricing.tax},this.calculateTotals();}updateDiscounts(e){let t={};e.forEach(i=>{t[i.coupon.getCode()]=i.amount;}),this.total.discounts=t,this.calculateTotals();}updateTax(e){if(!e.appliesTo(this.pricing.taxCategory,this.pricing.tax.country))throw new N;let t=this.total.taxableAmount.divide(this.total.quantity);this.pricing.tax={taxRuleId:e.getTaxRuleId(),taxSystem:e.getTaxSystem(),country:e.getCountry(),rate:e.getApplicableTaxRate(t),taxSlabs:e.getSlabs()},this.calculateTotals();}calculateTotals(){let e=this.pricing.unitPrice.zero(),t=this.subItems.reduce((K,Q)=>K+Q.quantity,0),{unitPrice:i}=this.pricing.tierPricing.getApplicableTier(t),n=i.multiply(t),s=Object.values(this.total.discounts).reduce((K,Q)=>K.add(Q),e),u=n.subtract(s),d=u.divide(t),a=q.getApplicableTaxRate(d,this.pricing.tax.taxSlabs),l=u.multiply(a).round(),x=n.subtract(s).add(l);this.total={quantity:t,subtotal:n,taxableAmount:u,taxTotal:l,discounts:this.total.discounts,grandTotal:x};}clearLineItem(){let e=this.pricing.unitPrice.zero();this.id="",this.productKey="",this.selectionAttribute={color:{name:""}},this.name={en:""},this.primaryImage=new f({sources:{original:""}}),this.subItems=[],this.pricing={unitPrice:e,tierPricing:this.pricing.tierPricing,taxCategory:this.pricing.taxCategory,tax:this.pricing.tax},this.total={quantity:0,subtotal:e,taxableAmount:e,taxTotal:e,discounts:{},grandTotal:e};}};module.exports=Z;//# sourceMappingURL=LineItem.js.map
2
2
  //# sourceMappingURL=LineItem.js.map