b23-lib 3.8.0 → 3.9.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 (102) 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/Cart.d.mts +1 -2
  6. package/dist/Classes/Cart.d.ts +1 -2
  7. package/dist/Classes/Cart.js +1 -1
  8. package/dist/Classes/Cart.js.map +1 -1
  9. package/dist/Classes/Cart.mjs +1 -1
  10. package/dist/Classes/Cart.mjs.map +1 -1
  11. package/dist/Classes/Charge.js +1 -1
  12. package/dist/Classes/Charge.js.map +1 -1
  13. package/dist/Classes/Charge.mjs +1 -1
  14. package/dist/Classes/Coupon.js +1 -1
  15. package/dist/Classes/Coupon.js.map +1 -1
  16. package/dist/Classes/Coupon.mjs +1 -1
  17. package/dist/Classes/Error.d.mts +4 -1
  18. package/dist/Classes/Error.d.ts +4 -1
  19. package/dist/Classes/Error.js +1 -1
  20. package/dist/Classes/Error.js.map +1 -1
  21. package/dist/Classes/Error.mjs +1 -1
  22. package/dist/Classes/ImageInfo.js.map +1 -1
  23. package/dist/Classes/ImageInfo.mjs +1 -1
  24. package/dist/Classes/Inventory.d.mts +1 -2
  25. package/dist/Classes/Inventory.d.ts +1 -2
  26. package/dist/Classes/Inventory.js +1 -1
  27. package/dist/Classes/Inventory.js.map +1 -1
  28. package/dist/Classes/Inventory.mjs +1 -1
  29. package/dist/Classes/Inventory.mjs.map +1 -1
  30. package/dist/Classes/Invoice.d.mts +1 -2
  31. package/dist/Classes/Invoice.d.ts +1 -2
  32. package/dist/Classes/Invoice.js.map +1 -1
  33. package/dist/Classes/Invoice.mjs +1 -1
  34. package/dist/Classes/LineItem.d.mts +1 -2
  35. package/dist/Classes/LineItem.d.ts +1 -2
  36. package/dist/Classes/LineItem.js +1 -1
  37. package/dist/Classes/LineItem.js.map +1 -1
  38. package/dist/Classes/LineItem.mjs +1 -1
  39. package/dist/Classes/Order.d.mts +1 -2
  40. package/dist/Classes/Order.d.ts +1 -2
  41. package/dist/Classes/Order.js +1 -1
  42. package/dist/Classes/Order.js.map +1 -1
  43. package/dist/Classes/Order.mjs +1 -1
  44. package/dist/Classes/Order.mjs.map +1 -1
  45. package/dist/Classes/Price.js.map +1 -1
  46. package/dist/Classes/Price.mjs +1 -1
  47. package/dist/Classes/Product.d.mts +5 -257
  48. package/dist/Classes/Product.d.ts +5 -257
  49. package/dist/Classes/Product.js +1 -1
  50. package/dist/Classes/Product.js.map +1 -1
  51. package/dist/Classes/Product.mjs +1 -1
  52. package/dist/Classes/ShoppingContainer.d.mts +1 -2
  53. package/dist/Classes/ShoppingContainer.d.ts +1 -2
  54. package/dist/Classes/ShoppingContainer.js +1 -1
  55. package/dist/Classes/ShoppingContainer.js.map +1 -1
  56. package/dist/Classes/ShoppingContainer.mjs +1 -1
  57. package/dist/Classes/TaxRule.js +1 -1
  58. package/dist/Classes/TaxRule.js.map +1 -1
  59. package/dist/Classes/TaxRule.mjs +1 -1
  60. package/dist/Classes/TieredPrice.d.mts +5 -81
  61. package/dist/Classes/TieredPrice.d.ts +5 -81
  62. package/dist/Classes/TieredPrice.js +1 -1
  63. package/dist/Classes/TieredPrice.js.map +1 -1
  64. package/dist/Classes/TieredPrice.mjs +1 -1
  65. package/dist/Product-BywRotdH.d.mts +367 -0
  66. package/dist/Product-mtVUKzNI.d.ts +367 -0
  67. package/dist/chunk-4QU5WW6U.mjs +2 -0
  68. package/dist/chunk-4QU5WW6U.mjs.map +1 -0
  69. package/dist/chunk-7B5TAYNA.mjs +2 -0
  70. package/dist/chunk-7B5TAYNA.mjs.map +1 -0
  71. package/dist/{chunk-2B2XI6FG.mjs → chunk-7RAIVZKB.mjs} +2 -2
  72. package/dist/{chunk-2B2XI6FG.mjs.map → chunk-7RAIVZKB.mjs.map} +1 -1
  73. package/dist/{chunk-C3METQSR.mjs → chunk-EZ35IKUA.mjs} +2 -2
  74. package/dist/{chunk-C3METQSR.mjs.map → chunk-EZ35IKUA.mjs.map} +1 -1
  75. package/dist/{chunk-TU4HOP63.mjs → chunk-MPKIC2MS.mjs} +2 -2
  76. package/dist/{chunk-TU4HOP63.mjs.map → chunk-MPKIC2MS.mjs.map} +1 -1
  77. package/dist/{chunk-R5DM7WCD.mjs → chunk-O6BLQQO7.mjs} +2 -2
  78. package/dist/chunk-O6BLQQO7.mjs.map +1 -0
  79. package/dist/chunk-PNTRHKEH.mjs +2 -0
  80. package/dist/chunk-PNTRHKEH.mjs.map +1 -0
  81. package/dist/{chunk-PAOHRZCC.mjs → chunk-Q7FOHAQD.mjs} +2 -2
  82. package/dist/{chunk-PAOHRZCC.mjs.map → chunk-Q7FOHAQD.mjs.map} +1 -1
  83. package/dist/{chunk-AWKAKL2Y.mjs → chunk-REP6D3WD.mjs} +2 -2
  84. package/dist/{chunk-AWKAKL2Y.mjs.map → chunk-REP6D3WD.mjs.map} +1 -1
  85. package/dist/{chunk-VO7ZE5C3.mjs → chunk-UIQH5QIR.mjs} +2 -2
  86. package/dist/{chunk-VO7ZE5C3.mjs.map → chunk-UIQH5QIR.mjs.map} +1 -1
  87. package/dist/index.d.mts +1 -2
  88. package/dist/index.d.ts +1 -2
  89. package/dist/index.js +2 -2
  90. package/dist/index.js.map +1 -1
  91. package/dist/index.mjs +1 -1
  92. package/dist/index.mjs.map +1 -1
  93. package/package.json +1 -1
  94. package/dist/chunk-DURMXVHZ.mjs +0 -2
  95. package/dist/chunk-DURMXVHZ.mjs.map +0 -1
  96. package/dist/chunk-ID3CEA7W.mjs +0 -2
  97. package/dist/chunk-ID3CEA7W.mjs.map +0 -1
  98. package/dist/chunk-LJEJAR35.mjs +0 -2
  99. package/dist/chunk-LJEJAR35.mjs.map +0 -1
  100. package/dist/chunk-R5DM7WCD.mjs.map +0 -1
  101. package/dist/chunk-USMLRWT6.mjs +0 -2
  102. package/dist/chunk-USMLRWT6.mjs.map +0 -1
@@ -0,0 +1,367 @@
1
+ import BaseModel, { BaseAttributes } from './Classes/Base.js';
2
+ import { a as PriceModel, P as PriceData, b as Prettify, c as CurrencyCode, f as Color, d as LocalizedString, C as CountryCode, e as LocalizedValue, L as LocaleCode } from './Common-BtMFh79I.js';
3
+ import { GenderCategory, ProductType, ImageCategory } from './Classes/Enum.js';
4
+ import ImageInfoModel, { ImageInfoData } from './Classes/ImageInfo.js';
5
+
6
+ declare enum PricingType {
7
+ VOLUME = "volume",
8
+ SELECTION = "selection"
9
+ }
10
+ /**
11
+ * Represents a pricing tier based on a minimum purchase quantity.
12
+ */
13
+ type PriceTier = {
14
+ enabled: boolean;
15
+ minQuantity: number;
16
+ unitPrice: PriceModel;
17
+ };
18
+ type PriceTierData = {
19
+ enabled: boolean;
20
+ minQuantity: number;
21
+ unitPrice: PriceData;
22
+ };
23
+ /**
24
+ * Represents the configuration for a specific selection variant.
25
+ */
26
+ type SelectionPricingData = {
27
+ selectionAttributes: SelectionAttributes;
28
+ baseUnitPrice: PriceData;
29
+ tiers?: PriceTierData[];
30
+ };
31
+ type SelectionPricing = {
32
+ selectionAttributes: SelectionAttributes;
33
+ baseUnitPrice: PriceModel;
34
+ tiers: PriceTier[];
35
+ };
36
+ type PriceTierAttributes = Prettify<Omit<PriceTierData, 'enabled'> & {
37
+ enabled?: boolean;
38
+ }>;
39
+ /**
40
+ * Represents the attributes required for tiered pricing.
41
+ */
42
+ type TieredPriceAttributes = Prettify<{
43
+ taxCategory: string;
44
+ isTaxInclusive?: boolean;
45
+ } & ({
46
+ currency?: CurrencyCode;
47
+ type?: PricingType.VOLUME;
48
+ baseUnitPrice: PriceData;
49
+ tiers?: PriceTierAttributes[];
50
+ } | {
51
+ currency: CurrencyCode;
52
+ type: PricingType.SELECTION;
53
+ selections: (Omit<SelectionPricingData, 'tiers'> & {
54
+ tiers?: PriceTierAttributes[];
55
+ })[];
56
+ })>;
57
+ type TieredPriceData = Prettify<{
58
+ taxCategory: string;
59
+ isTaxInclusive: boolean;
60
+ currency: CurrencyCode;
61
+ } & ({
62
+ type?: PricingType.VOLUME;
63
+ baseUnitPrice: PriceData;
64
+ tiers: PriceTierData[];
65
+ } | {
66
+ type: PricingType.SELECTION;
67
+ selections: SelectionPricingData[];
68
+ })>;
69
+ declare abstract class TieredPriceModel {
70
+ protected type: PricingType;
71
+ protected taxCategory: string;
72
+ protected isTaxInclusive: boolean;
73
+ /**
74
+ * Factory method to instantiate the correct concrete TieredPriceModel implementation.
75
+ */
76
+ static create(data: TieredPriceAttributes): TieredPriceModel;
77
+ constructor(data: TieredPriceAttributes);
78
+ getType(): PricingType;
79
+ getTaxCategory(): string;
80
+ getIsTaxInclusive(): boolean;
81
+ abstract getBaseUnitPrice(selectionAttributes?: SelectionAttributes): PriceModel;
82
+ abstract getDetails(): TieredPriceData;
83
+ abstract getCurrency(): string;
84
+ abstract getApplicableUnitPrice(quantity: number, selectionAttributes?: SelectionAttributes): PriceModel;
85
+ abstract getMinQuantity(selectionAttributes?: SelectionAttributes): number;
86
+ abstract getMaxDiscountPercent(selectionAttributes?: SelectionAttributes): number;
87
+ }
88
+ declare class VolumeTieredPriceModel extends TieredPriceModel {
89
+ protected baseUnitPrice: PriceModel;
90
+ protected tiers: PriceTier[];
91
+ protected currency: CurrencyCode;
92
+ constructor(data: Extract<TieredPriceAttributes, {
93
+ type?: PricingType.VOLUME;
94
+ }>);
95
+ getBaseUnitPrice(): PriceModel;
96
+ getCurrency(): string;
97
+ getApplicableUnitPrice(quantity: number): PriceModel;
98
+ getMinQuantity(): number;
99
+ getMaxDiscountPercent(): number;
100
+ getDetails(): TieredPriceData;
101
+ }
102
+ declare class SelectionTieredPriceModel extends TieredPriceModel {
103
+ protected currency: CurrencyCode;
104
+ protected selections: SelectionPricing[];
105
+ constructor(data: Extract<TieredPriceAttributes, {
106
+ type: PricingType.SELECTION;
107
+ }>);
108
+ protected findMatch(selectionAttributes: SelectionAttributes): SelectionPricing;
109
+ getBaseUnitPrice(selectionAttributes?: SelectionAttributes): PriceModel;
110
+ getCurrency(): string;
111
+ getApplicableUnitPrice(quantity: number, selectionAttributes?: SelectionAttributes): PriceModel;
112
+ getMinQuantity(selectionAttributes?: SelectionAttributes): number;
113
+ getMaxDiscountPercent(selectionAttributes?: SelectionAttributes): number;
114
+ getDetails(): TieredPriceData;
115
+ }
116
+
117
+ type ProductSelectionAttributes = Prettify<{
118
+ color: Color[];
119
+ size: string[];
120
+ } & {
121
+ [key: string]: string | string[] | Color[];
122
+ }>;
123
+ type SelectionAttributes = {
124
+ color: Color;
125
+ [key: string]: string | Color;
126
+ };
127
+ type VariantData = {
128
+ sku: string;
129
+ selectionAttributes: SelectionAttributes;
130
+ images: {
131
+ primary: ImageInfoData;
132
+ gallery: ImageInfoData[];
133
+ };
134
+ };
135
+ type VariantModel = {
136
+ sku: string;
137
+ selectionAttributes: SelectionAttributes;
138
+ images: {
139
+ primary: ImageInfoModel;
140
+ gallery: ImageInfoModel[];
141
+ };
142
+ };
143
+ type ProductSpecification = {
144
+ [key: string]: string | string[];
145
+ };
146
+ type ProductAttributes = BaseAttributes & {
147
+ id: string;
148
+ key: string;
149
+ name: LocalizedString;
150
+ description: LocalizedString;
151
+ slug: LocalizedString;
152
+ brand: string;
153
+ pricing: {
154
+ [country in CountryCode]?: TieredPriceAttributes;
155
+ };
156
+ targetGender: GenderCategory;
157
+ attributes: ProductSelectionAttributes;
158
+ specifications: LocalizedValue<ProductSpecification>;
159
+ categories: string[];
160
+ productType?: ProductType;
161
+ variants: VariantData[];
162
+ isActive: boolean;
163
+ searchTags?: LocalizedValue<string[]>;
164
+ };
165
+ type ProductData = Required<ProductAttributes>;
166
+ declare class ProductModel extends BaseModel {
167
+ protected id: string;
168
+ protected key: string;
169
+ protected name: LocalizedString;
170
+ protected description: LocalizedString;
171
+ protected slug: LocalizedString;
172
+ protected brand: string;
173
+ protected pricing: {
174
+ [country in CountryCode]?: TieredPriceModel;
175
+ };
176
+ protected variants: VariantModel[];
177
+ protected targetGender: GenderCategory;
178
+ protected attributes: ProductSelectionAttributes;
179
+ protected specifications: LocalizedValue<ProductSpecification>;
180
+ protected categories: string[];
181
+ protected productType: ProductType;
182
+ protected isActive: boolean;
183
+ protected searchTags: LocalizedValue<string[]>;
184
+ static productKeyRegex: RegExp;
185
+ static productSKURegex: RegExp;
186
+ /**
187
+ * Generates a unique key for checking uniqueness for a given selection attributes.
188
+ * Excludes 'size' from the key generation.
189
+ * @param selectionAttributes - The selection attributes.
190
+ * @returns A string key representing the unique attribute combination.
191
+ */
192
+ static generateSelectionAttributesKey(selectionAttributes: SelectionAttributes): string;
193
+ /**
194
+ * Parses a selection attributes key into an object.
195
+ * @param key - The selection attributes key to parse.
196
+ * @returns An object containing the parsed selection attributes.
197
+ */
198
+ static parseSelectionAttributesKey(key: string): SelectionAttributes;
199
+ /**
200
+ * Creates an instance of ProductModel.
201
+ * Initializes properties based on the provided data, creating copies where necessary.
202
+ * @param data - The initial product attributes.
203
+ * @param date - Optional date for setting creation/modification times (defaults to now).
204
+ */
205
+ constructor(data: ProductAttributes, date?: Date);
206
+ /**
207
+ * Gets the base Product ID.
208
+ * @returns Product ID.
209
+ */
210
+ getId(): string;
211
+ /**
212
+ * Gets the user-friendly product key.
213
+ * @returns Product Key.
214
+ */
215
+ getKey(): string;
216
+ /**
217
+ * Gets the full localized product name object.
218
+ * @returns A copy of the LocalizedString object for the name.
219
+ */
220
+ getName(): LocalizedString;
221
+ /**
222
+ * Gets the product name for a specific locale, falling back to English ('en').
223
+ * @param locale - The desired locale code.
224
+ * @returns The name string for the specified locale.
225
+ */
226
+ getName(locale: LocaleCode): string;
227
+ /**
228
+ * Gets the full localized product description object.
229
+ * @returns A copy of the LocalizedString object for the description.
230
+ */
231
+ getDescription(): LocalizedString;
232
+ /**
233
+ * Gets the product description for a specific locale, falling back to English ('en').
234
+ * @param locale - The desired locale code.
235
+ * @returns The description string for the specified locale.
236
+ */
237
+ getDescription(locale: LocaleCode): string;
238
+ /**
239
+ * Gets the full localized product slug object.
240
+ * @returns A copy of the LocalizedString object for the slug.
241
+ */
242
+ getSlug(): LocalizedString;
243
+ /**
244
+ * Gets the product slug for a specific locale, falling back to English ('en').
245
+ * @param locale - The desired locale code.
246
+ * @returns The slug string for the specified locale.
247
+ */
248
+ getSlug(locale: LocaleCode): string;
249
+ /**
250
+ * Gets the brand associated with the product.
251
+ * @returns The brand name string.
252
+ */
253
+ getBrand(): string;
254
+ /**
255
+ * Gets the tiered price details for the product.
256
+ * @returns Pricing details mapped by country.
257
+ */
258
+ getPriceDetails(): {
259
+ [country in CountryCode]?: TieredPriceModel;
260
+ };
261
+ /**
262
+ * Gets the tiered price details for a specific country.
263
+ * @param country - The country code.
264
+ * @returns The tiered price model for the country, or null if not found.
265
+ */
266
+ getPriceDetails(country: CountryCode): TieredPriceModel | null;
267
+ /**
268
+ * Gets the variant-specific attributes (color, sizes). Returns copies.
269
+ * @returns Product Attributes.
270
+ */
271
+ getAttributes(): ProductSelectionAttributes;
272
+ /**
273
+ * Gets the variant-specific attributes (color, sizes). Returns copies.
274
+ * @returns Product Attributes.
275
+ */
276
+ getVariants(): VariantModel[];
277
+ /**
278
+ * Gets the images for a specific selection attribute combination.
279
+ * @param selectionAttributes - The selection attributes to search for.
280
+ * @returns The matching image set or null if not found.
281
+ */
282
+ private getImagesBySelectionAttributes;
283
+ /**
284
+ * Gets the images for a specific selection attribute combination.
285
+ * @param selectionAttributes - The selection attributes to search for.
286
+ * @returns The matching image set or null if not found.
287
+ */
288
+ getImages(selectionAttributes: SelectionAttributes): {
289
+ primary: ImageInfoModel;
290
+ gallery: ImageInfoModel[];
291
+ };
292
+ getImages(selectionAttributes: SelectionAttributes, category: ImageCategory.PRIMARY): ImageInfoModel;
293
+ getImages(selectionAttributes: SelectionAttributes, category: ImageCategory.GALLERY): ImageInfoModel[];
294
+ /**
295
+ * Checks if the product is active.
296
+ * @returns True if the product is active, false otherwise.
297
+ */
298
+ getIsActive(): boolean;
299
+ /**
300
+ * Gets the target gender category for the product.
301
+ * @returns The GenderCategory enum value.
302
+ */
303
+ getTargetGender(): GenderCategory;
304
+ /**
305
+ * Gets the list of categories the product belongs to. Returns a copy.
306
+ * @returns An array of category.
307
+ */
308
+ getCategories(): string[];
309
+ /**
310
+ * Gets the product type.
311
+ * @returns ProductType.
312
+ */
313
+ getProductType(): ProductType;
314
+ /**
315
+ * Gets the full localized product specifications object.
316
+ * @returns Product Specifications
317
+ */
318
+ getSpecifications(): LocalizedValue<ProductSpecification>;
319
+ /**
320
+ * Gets the product specifications for a specific locale, falling back to English ('en').
321
+ * @param locale - The desired locale code.
322
+ * @returns The ProductSpecification object for the specified locale, or undefined if not found.
323
+ */
324
+ getSpecifications(locale: LocaleCode): ProductSpecification;
325
+ /**
326
+ * Gets the localized list of search tags. Returns a copy.
327
+ * @returns Localized array of search tags.
328
+ */
329
+ getSearchTags(): LocalizedValue<string[]>;
330
+ /**
331
+ * Gets the search tags for a specific locale, falling back to English ('en').
332
+ * @param locale - The desired locale code.
333
+ * @returns The array of search tags for the specified locale, or undefined if not found.
334
+ */
335
+ getSearchTags(locale: LocaleCode): string[];
336
+ /**
337
+ *
338
+ * @returns ProductData
339
+ */
340
+ getDetails(): ProductData;
341
+ /**
342
+ * Checks if the provided selection attributes are valid for the product.
343
+ * @param selectionAttributes The selection attributes to validate.
344
+ * @throws {SelectionAttributeParseError} If the selection attributes are invalid.
345
+ */
346
+ checkSelectionAttributes(selectionAttributes: SelectionAttributes): void;
347
+ /**
348
+ * Gets the SKU of the variant matching the selection attributes.
349
+ * @param selectionAttributes - The selection attributes to search for.
350
+ * @returns The SKU string, or undefined if no matching variant is found.
351
+ */
352
+ getSku(selectionAttributes: SelectionAttributes): string | undefined;
353
+ /**
354
+ * Validates if the provided selection attributes exist for this product.
355
+ * @param selectionAttributes - The attributes to validate.
356
+ * @returns True if a valid selection attribute exists, false otherwise.
357
+ */
358
+ validateSelectionAttribute(selectionAttributes: SelectionAttributes): boolean;
359
+ /**
360
+ * Validates if a specific size is available for this product.
361
+ * @param size - The size to check.
362
+ * @returns True if the size exists in the product's attributes, false otherwise.
363
+ */
364
+ validateSize(size: string): boolean;
365
+ }
366
+
367
+ export { ProductModel as P, type SelectionAttributes as S, type TieredPriceData as T, VolumeTieredPriceModel as V, TieredPriceModel as a, type ProductSpecification as b, PricingType as c, type PriceTier as d, type PriceTierData as e, type SelectionPricingData as f, type SelectionPricing as g, type PriceTierAttributes as h, type TieredPriceAttributes as i, SelectionTieredPriceModel as j, type ProductSelectionAttributes as k, type VariantData as l, type VariantModel as m, type ProductAttributes as n, type ProductData as o };
@@ -0,0 +1,2 @@
1
+ import {a as a$4,b as b$1}from'./chunk-MPKIC2MS.mjs';import {a as a$3}from'./chunk-EZ35IKUA.mjs';import {a as a$1,c}from'./chunk-7B5TAYNA.mjs';import {b}from'./chunk-7RAIVZKB.mjs';import {a as a$2}from'./chunk-UIQH5QIR.mjs';import {e,o}from'./chunk-PL5HGCWN.mjs';import {d,c as c$1,f,g,i,j,k,b as b$2}from'./chunk-O6BLQQO7.mjs';import {a}from'./chunk-UXZBULDS.mjs';var I=class extends a{id;productKey;sku;selectionAttributes;name;specifications;primaryImage;subItems;pricing;state;productType;total;constructor(t){super(t),this.id=t.id,this.productKey=t.productKey,this.sku=t.sku,this.selectionAttributes=a$1.deepClone(t.selectionAttributes),this.name=a$1.deepClone(t.name),this.specifications=a$1.deepClone(t.specifications),this.primaryImage=new b(t.primaryImage),this.subItems=a$1.deepClone(t.subItems);let e=new Set;this.subItems.forEach(i=>{if(e.has(i.size))throw new d(i.size);e.add(i.size);}),this.pricing={unitPrice:new a$2(t.pricing.unitPrice),tierPricing:c.create(t.pricing.tierPricing),taxCategory:t.pricing.taxCategory,applicableTaxRule:t.pricing.applicableTaxRule.map(i=>new a$3(i))},this.validateTaxRules(this.pricing.applicableTaxRule),this.state=t.state??"INITIAL",this.productType=t.productType??"GOODS",this.total={quantity:t.total.quantity,unitPrice:new a$2(t.total.unitPrice),subtotal:new a$2(t.total.subtotal),discountTotal:new a$2(t.total.discountTotal),discountBreakdown:Object.fromEntries(Object.entries(t.total.discountBreakdown).map(([i,a])=>[i,new a$2(a)])),netUnitPrice:new a$2(t.total.netUnitPrice),netSubtotal:new a$2(t.total.netSubtotal),taxTotal:new a$2(t.total.taxTotal),taxBreakdown:Object.fromEntries(Object.entries(t.total.taxBreakdown).map(([i,a])=>[i,{rate:a.rate,taxableUnitPrice:new a$2(a.taxableUnitPrice),taxPerUnit:new a$2(a.taxPerUnit),taxAmount:new a$2(a.taxAmount),system:a.system,subSystem:a.subSystem}])),grandTotal:new a$2(t.total.grandTotal)};}getId(){return this.id}getProductKey(){return this.productKey}getSku(){return this.sku}getSelectionAttributes(){return a$1.deepClone(this.selectionAttributes)}getName(t){return t?a$1.deepClone(this.name[t]??this.name[e[t]]??this.name.en):a$1.deepClone(this.name)}getSpecifications(t){return t?a$1.deepClone(this.specifications[t]??this.specifications[e[t]]??this.specifications.en):a$1.deepClone(this.specifications)}getImage(){return this.primaryImage}getSubItems(){return a$1.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}getProductType(){return this.productType}getTotal(){return {quantity:this.total.quantity,unitPrice:this.total.unitPrice,subtotal:this.total.subtotal,discountTotal:this.total.discountTotal,discountBreakdown:Object.fromEntries(Object.entries(this.total.discountBreakdown).map(([t,e])=>[t,e])),netUnitPrice:this.total.netUnitPrice,netSubtotal:this.total.netSubtotal,taxTotal:this.total.taxTotal,taxBreakdown:Object.fromEntries(Object.entries(this.total.taxBreakdown).map(([t,e])=>[t,{rate:e.rate,taxableUnitPrice:e.taxableUnitPrice,taxPerUnit:e.taxPerUnit,taxAmount:e.taxAmount,system:e.system,subSystem:e.subSystem}])),grandTotal:this.total.grandTotal}}getDetails(){let t=this.getPricing(),e=this.getTotal();return {id:this.getId(),productKey:this.getProductKey(),sku:this.getSku(),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(),productType:this.getProductType(),total:{quantity:e.quantity,unitPrice:e.unitPrice.getDetails(),subtotal:e.subtotal.getDetails(),discountTotal:e.discountTotal.getDetails(),discountBreakdown:Object.fromEntries(Object.entries(e.discountBreakdown).map(([i,a])=>[i,a.getDetails()])),netUnitPrice:e.netUnitPrice.getDetails(),netSubtotal:e.netSubtotal.getDetails(),taxTotal:e.taxTotal.getDetails(),taxBreakdown:Object.fromEntries(Object.entries(e.taxBreakdown).map(([i,a])=>[i,{rate:a.rate,taxableUnitPrice:a.taxableUnitPrice.getDetails(),taxPerUnit:a.taxPerUnit.getDetails(),taxAmount:a.taxAmount.getDetails(),system:a.system,subSystem:a.subSystem}])),grandTotal:e.grandTotal.getDetails()},customFields:this.getAllCustomFields()}}validateTaxRules(t){let e=new Set;for(let i=0;i<t.length;i++){let a=t[i].getTaxRuleId();if(e.has(a))throw new c$1("Duplicate tax rule ID found: "+a);e.add(a);}}addSubItems(t,e){t.forEach(i=>{let a=this.subItems.find(u=>u.size===i.size);a?a.quantity=e?a.quantity+i.quantity:i.quantity:this.subItems.push(i);}),this.subItems=this.subItems.filter(i=>i.quantity>0),this.calculateTotals();}updateProductData(t,e,i$1){if(this.productKey!==t.getKey()||!t.validateSelectionAttribute(this.selectionAttributes))throw new f;if(!t.getIsActive())throw new g;this.subItems.forEach(c=>{if(!t.validateSize(c.size))throw new i});let a=t.getPriceDetails(e);if(!a||a.getCurrency()!==i$1)throw new j;this.name=t.getName(),this.specifications=t.getSpecifications(),this.sku=t.getSku(this.selectionAttributes),this.primaryImage=t.getImages(this.selectionAttributes).primary;let u=this.subItems.reduce((c,p)=>c+p.quantity,0),b=a.getApplicableUnitPrice(u,this.selectionAttributes);this.productType=t.getProductType(),this.pricing={unitPrice:b,tierPricing:a,taxCategory:a.getTaxCategory(),applicableTaxRule:this.pricing.applicableTaxRule},this.calculateTotals();}updateDiscounts(t){let e={};t.forEach(i=>{e[i.coupon.getCode()]=i.amount;}),this.total.discountBreakdown=e,this.calculateTotals();}updateTax(t){t.forEach(e=>{if(!e.appliesTo(this.pricing.taxCategory,e.getCountry()))throw new k}),this.validateTaxRules(t),this.pricing.applicableTaxRule=t,this.calculateTotals();}calculateTotals(){let t=this.pricing.unitPrice.zero(),e=this.subItems.reduce((s,n)=>s+n.quantity,0);if(this.state==="CANCELLED"){this.total={quantity:0,unitPrice:t,subtotal:t,discountTotal:t,discountBreakdown:{},netUnitPrice:t,netSubtotal:t,taxTotal:t,taxBreakdown:{},grandTotal:t};return}let i=this.pricing.tierPricing.getApplicableUnitPrice(e,this.selectionAttributes),a=i.multiply(e),u=Object.values(this.total.discountBreakdown).reduce((s,n)=>s.add(n),t),b=a.subtract(u),c=e>0?b.divide(e):t,p={},d=t,P=i,S=a,h=b,l=c;this.pricing.tierPricing.getIsTaxInclusive()?(P=a$4(i,this.pricing.applicableTaxRule),S=P.multiply(e),c.getAmount()>0&&(l=a$4(c,this.pricing.applicableTaxRule),h=l.multiply(e),b$1(l,c,this.pricing.applicableTaxRule).forEach(n=>{let g=n.taxAmount.multiply(e).round(),m=this.pricing.applicableTaxRule.find(O=>O.getTaxRuleId()===n.ruleId);p[n.ruleId]={rate:n.rate,taxableUnitPrice:l,taxPerUnit:n.taxAmount,taxAmount:g,system:m.getTaxSystem(),subSystem:m.getTaxSubSystem()},d=d.add(g);}))):this.pricing.applicableTaxRule.forEach(s=>{let n=s.getApplicableTaxRate(l),g=s.calculateTax(l),m=g.multiply(e).round();p[s.getTaxRuleId()]={rate:n,taxableUnitPrice:l,taxPerUnit:g,taxAmount:m,system:s.getTaxSystem(),subSystem:s.getTaxSubSystem()},d=d.add(m);});let v=h.add(d);this.total={quantity:e,unitPrice:P,subtotal:S,discountTotal:u,discountBreakdown:this.total.discountBreakdown,netUnitPrice:l,netSubtotal:h,taxTotal:d,taxBreakdown:p,grandTotal:v};}updateState(t){if(this.state in o)this.state!==t&&(this.state=t);else throw new b$2(t)}clearLineItem(){let t=this.pricing.unitPrice.zero();this.id="",this.productKey="",this.sku="",this.selectionAttributes={color:{name:""}},this.name={en:""},this.primaryImage=new b({sources:{original:""}}),this.subItems=[],this.productType="GOODS",this.pricing={unitPrice:t,tierPricing:this.pricing.tierPricing,taxCategory:this.pricing.taxCategory,applicableTaxRule:[]},this.total={quantity:0,unitPrice:t,subtotal:t,discountTotal:t,discountBreakdown:{},netUnitPrice:t,netSubtotal:t,taxTotal:t,taxBreakdown:{},grandTotal:t};}};export{I as a};//# sourceMappingURL=chunk-4QU5WW6U.mjs.map
2
+ //# sourceMappingURL=chunk-4QU5WW6U.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/Classes/LineItem.ts"],"names":["LineItemModel","CustomFieldModel","data","Utils_default","ImageInfoModel","uniqueSelectionAttributes","item","DuplicateSizeError","PriceModel","TieredPriceModel","rule","TaxRuleModel","couponCode","discount","taxRuleId","taxBreakdown","locale","LocaleLanguageMap","pricing","total","taxRules","uniqueTaxRule","currentTaxRuleId","InvalidLineItemTaxRuleError","subItems","addQuantity","subItem","existingSubItem","sub","product","cartCountry","cartCurrency","ProductMismatchError","ProductInactiveError","SizeMismatchError","productPricing","PricingNotFoundError","quantity","sum","s","unitPrice","appliedDiscounts","lineItemDiscounts","taxRule","InvalidTaxRuleError","zero","totalQuantity","tierUnitPrice","initialSubTotal","totalDiscount","initialNetSubtotal","initialNetUnitPrice","taxTotal","finalUnitPrice","finalSubTotal","finalNetSubtotal","finalNetUnitPrice","extractExclusiveBase","calculateDistributedTaxes","dt","taxAmount","r","rate","taxPerUnit","grandTotal","newState","LineItemState","InvalidLineItemStateError"],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,CAAaA,CACb,CAAA,QAAA,CAAUA,EACV,YAAc,CAAA,GACd,UAAYA,CAAAA,CACd,EACF,CACF","file":"chunk-4QU5WW6U.mjs","sourcesContent":["import Utils from \"../Utils\";\r\nimport { Color, CountryCode, CurrencyCode, LocaleCode, LocalizedString, LocalizedValue } from \"./Common\";\r\nimport CouponModel from \"./Coupon\";\r\nimport { LineItemState, LocaleLanguageMap, TaxSystem, ProductType } from \"./Enum\";\r\nimport ImageInfoModel, { ImageInfoData } from \"./ImageInfo\";\r\nimport PriceModel, { PriceData } from \"./Price\";\r\nimport ProductModel, { ProductSelectionAttributes, ProductSpecification, SelectionAttributes } from \"./Product\";\r\nimport { TaxRuleData, TaxRuleModel } from \"./TaxRule\";\r\nimport { TieredPriceData, TieredPriceModel } from \"./TieredPrice\";\r\nimport {\r\n DuplicateSizeError,\r\n ProductMismatchError,\r\n ProductInactiveError,\r\n SizeMismatchError,\r\n PricingNotFoundError,\r\n InvalidTaxRuleError,\r\n InvalidLineItemStateError,\r\n InvalidLineItemTaxRuleError\r\n} from \"./Error\";\r\nimport { CustomFieldAttributes, CustomFieldModel } from \"./Base\";\r\nimport { extractExclusiveBase, calculateDistributedTaxes } from \"../Utils/TaxMath\";\r\n\r\nexport type SubItem = {\r\n size: string | 'ONESIZE';\r\n quantity: number;\r\n};\r\n\r\nexport type LineItemPricing = {\r\n unitPrice: PriceData;\r\n tierPricing: TieredPriceData;\r\n taxCategory: string;\r\n applicableTaxRule: TaxRuleData[];\r\n};\r\n\r\nexport type LineItemPricingModel = {\r\n unitPrice: PriceModel;\r\n tierPricing: TieredPriceModel;\r\n taxCategory: string;\r\n applicableTaxRule: TaxRuleModel[];\r\n};\r\n\r\nexport type LineItemTaxBreakdown = {\r\n rate: number; // 0.09 for 9%\r\n taxableUnitPrice: PriceData; // effectiveUnitPrice used for calculation\r\n taxPerUnit: PriceData; // tax on single unit\r\n taxAmount: PriceData; // taxPerUnit × quantity (total tax)\r\n system: TaxSystem;\r\n subSystem: string;\r\n};\r\n\r\nexport type LineItemTaxBreakdownModel = {\r\n rate: number;\r\n taxableUnitPrice: PriceModel;\r\n taxPerUnit: PriceModel;\r\n taxAmount: PriceModel;\r\n system: TaxSystem;\r\n subSystem: string;\r\n};\r\n\r\nexport type LineItemTotals = {\r\n quantity: number;\r\n unitPrice: PriceData; // original unit price (from tier pricing)\r\n subtotal: PriceData; // unitPrice × quantity\r\n discountTotal: PriceData; // sum of all discounts\r\n discountBreakdown: Record<string, PriceData>; // couponCode -> discount mapping\r\n netUnitPrice: PriceData; // unit price after discounts\r\n netSubtotal: PriceData; // subtotal - totalDiscount (taxable amount)\r\n taxTotal: PriceData; // sum of all tax amounts\r\n taxBreakdown: Record<string, LineItemTaxBreakdown>; // tax breakdown by tax rule\r\n grandTotal: PriceData; // effectiveSubtotal + taxTotal\r\n};\r\n\r\nexport type LineItemTotalsModel = {\r\n quantity: number;\r\n unitPrice: PriceModel;\r\n subtotal: PriceModel;\r\n discountTotal: PriceModel;\r\n discountBreakdown: Record<string, PriceModel>;\r\n netUnitPrice: PriceModel;\r\n netSubtotal: PriceModel;\r\n taxTotal: PriceModel;\r\n taxBreakdown: Record<string, LineItemTaxBreakdownModel>;\r\n grandTotal: PriceModel;\r\n};\r\n\r\nexport type LineItemAttributes = CustomFieldAttributes & {\r\n id: string;\r\n\r\n productKey: string;\r\n sku: string;\r\n selectionAttributes: SelectionAttributes;\r\n\r\n name: LocalizedString;\r\n specifications: LocalizedValue<ProductSpecification>;\r\n primaryImage: ImageInfoData;\r\n\r\n subItems: SubItem[];\r\n\r\n pricing: LineItemPricing;\r\n\r\n state?: LineItemState;\r\n productType?: ProductType;\r\n total: LineItemTotals;\r\n}\r\n\r\nexport type LineItemData = Required<LineItemAttributes>;\r\n\r\n/**\r\n * Represents a line item within a shopping cart.\r\n */\r\nexport default class LineItemModel extends CustomFieldModel {\r\n protected id: string;\r\n protected productKey: string;\r\n protected sku: string;\r\n protected selectionAttributes: SelectionAttributes;\r\n\r\n protected name: LocalizedString;\r\n protected specifications: LocalizedValue<ProductSpecification>;\r\n protected primaryImage: ImageInfoModel;\r\n protected subItems: SubItem[];\r\n protected pricing: LineItemPricingModel;\r\n\r\n protected state: LineItemState;\r\n protected productType: ProductType;\r\n protected total: LineItemTotalsModel;\r\n\r\n /**\r\n * Creates an instance of LineItemModel.\r\n * @param data - The initial line item attributes.\r\n */\r\n constructor(data: LineItemAttributes) {\r\n super(data);\r\n this.id = data.id;\r\n this.productKey = data.productKey;\r\n this.sku = data.sku;\r\n this.selectionAttributes = Utils.deepClone(data.selectionAttributes);\r\n\r\n this.name = Utils.deepClone(data.name);\r\n this.specifications = Utils.deepClone(data.specifications);\r\n this.primaryImage = new ImageInfoModel(data.primaryImage);\r\n this.subItems = Utils.deepClone(data.subItems);\r\n\r\n let uniqueSelectionAttributes = new Set();\r\n this.subItems.forEach(item => {\r\n if (uniqueSelectionAttributes.has(item.size)) {\r\n throw new DuplicateSizeError(item.size);\r\n }\r\n uniqueSelectionAttributes.add(item.size);\r\n });\r\n\r\n this.pricing = {\r\n unitPrice: new PriceModel(data.pricing.unitPrice),\r\n tierPricing: TieredPriceModel.create(data.pricing.tierPricing),\r\n taxCategory: data.pricing.taxCategory,\r\n applicableTaxRule: data.pricing.applicableTaxRule.map(rule => new TaxRuleModel(rule)),\r\n }\r\n this.validateTaxRules(this.pricing.applicableTaxRule);\r\n\r\n this.state = data.state ?? LineItemState.INITIAL;\r\n this.productType = data.productType ?? ProductType.GOODS;\r\n\r\n this.total = {\r\n quantity: data.total.quantity,\r\n unitPrice: new PriceModel(data.total.unitPrice),\r\n subtotal: new PriceModel(data.total.subtotal),\r\n discountTotal: new PriceModel(data.total.discountTotal),\r\n discountBreakdown: Object.fromEntries(\r\n Object.entries(data.total.discountBreakdown).map(([couponCode, discount]) => [\r\n couponCode,\r\n new PriceModel(discount),\r\n ])\r\n ),\r\n netUnitPrice: new PriceModel(data.total.netUnitPrice),\r\n netSubtotal: new PriceModel(data.total.netSubtotal),\r\n taxTotal: new PriceModel(data.total.taxTotal),\r\n taxBreakdown: Object.fromEntries(\r\n Object.entries(data.total.taxBreakdown).map(([taxRuleId, taxBreakdown]) => [\r\n taxRuleId,\r\n {\r\n rate: taxBreakdown.rate,\r\n taxableUnitPrice: new PriceModel(taxBreakdown.taxableUnitPrice),\r\n taxPerUnit: new PriceModel(taxBreakdown.taxPerUnit),\r\n taxAmount: new PriceModel(taxBreakdown.taxAmount),\r\n system: taxBreakdown.system,\r\n subSystem: taxBreakdown.subSystem\r\n }\r\n ])\r\n ),\r\n grandTotal: new PriceModel(data.total.grandTotal),\r\n }\r\n }\r\n\r\n /**\r\n * Gets the unique identifier of the line item.\r\n * @returns The unique ID string.\r\n */\r\n getId(): string {\r\n return this.id;\r\n }\r\n\r\n /**\r\n * Gets the product key associated with this line item.\r\n * @returns The product key string.\r\n */\r\n getProductKey(): string {\r\n return this.productKey;\r\n }\r\n\r\n /**\r\n * Gets the SKU of the line item.\r\n * @returns The SKU string.\r\n */\r\n getSku(): string {\r\n return this.sku;\r\n }\r\n\r\n /**\r\n * Gets the selection attributes (e.g., size, color) for this line item.\r\n * @returns A copy of the selection attributes object.\r\n */\r\n getSelectionAttributes(): SelectionAttributes {\r\n return Utils.deepClone(this.selectionAttributes);\r\n }\r\n\r\n /**\r\n * Gets the full localized product name object.\r\n * @returns A copy of the LocalizedString object for the name.\r\n */\r\n getName(): LocalizedString\r\n /**\r\n * Gets the product name for a specific locale, falling back to English ('en').\r\n * @param locale - The desired locale code.\r\n * @returns The name string for the specified locale.\r\n */\r\n getName(locale: LocaleCode): string\r\n getName(locale?: LocaleCode): LocalizedString | string {\r\n if (locale) {\r\n return Utils.deepClone(this.name[locale] ?? this.name[LocaleLanguageMap[locale]] ?? this.name.en);\r\n } else {\r\n return Utils.deepClone(this.name);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the full localized product specifications object.\r\n * @returns Product Specifications\r\n */\r\n getSpecifications(): LocalizedValue<ProductSpecification>\r\n /**\r\n * Gets the product specifications for a specific locale, falling back to English ('en').\r\n * @param locale - The desired locale code.\r\n * @returns The ProductSpecification object for the specified locale, or undefined if not found.\r\n */\r\n getSpecifications(locale: LocaleCode): ProductSpecification | undefined\r\n getSpecifications(locale?: LocaleCode): LocalizedValue<ProductSpecification> | ProductSpecification | undefined {\r\n if (locale) {\r\n return Utils.deepClone(this.specifications[locale] ?? this.specifications[LocaleLanguageMap[locale]] ?? this.specifications.en);\r\n } else {\r\n return Utils.deepClone(this.specifications);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the image information model for this line item.\r\n * @returns The ImageInfoModel instance.\r\n */\r\n getImage(): ImageInfoModel {\r\n return this.primaryImage;\r\n }\r\n\r\n /**\r\n * Gets the sub-items (size/quantity breakdown).\r\n * @returns A copy of the array of SubItems.\r\n */\r\n getSubItems(): SubItem[] {\r\n return Utils.deepClone(this.subItems);\r\n }\r\n\r\n /**\r\n * Gets the total quantity for this line item across all sub-items.\r\n * @returns The total quantity as a number.\r\n */\r\n getTotalQuantity(): number {\r\n return this.total.quantity;\r\n }\r\n\r\n /**\r\n * Gets the pricing information model for this line item.\r\n * @returns An object containing unit price, tiered pricing, tax category, and tax details.\r\n */\r\n getPricing() {\r\n return {\r\n unitPrice: this.pricing.unitPrice,\r\n tierPricing: this.pricing.tierPricing,\r\n taxCategory: this.pricing.taxCategory,\r\n applicableTaxRule: [...this.pricing.applicableTaxRule],\r\n };\r\n }\r\n\r\n /**\r\n * Gets the current state of the line item.\r\n * @returns The LineItemState enum value.\r\n */\r\n getState() {\r\n return this.state;\r\n }\r\n\r\n /**\r\n * Gets the product type.\r\n * @returns ProductType.\r\n */\r\n getProductType(): ProductType {\r\n return this.productType;\r\n }\r\n\r\n /**\r\n * Gets the total price for this line item (including all sub-items).\r\n * @returns An object containing line item totals including subtotal, tax, discounts, and grand total.\r\n */\r\n getTotal(): LineItemTotalsModel {\r\n return {\r\n quantity: this.total.quantity,\r\n unitPrice: this.total.unitPrice,\r\n subtotal: this.total.subtotal,\r\n discountTotal: this.total.discountTotal,\r\n discountBreakdown: Object.fromEntries(\r\n Object.entries(this.total.discountBreakdown).map(([couponCode, discount]) => [\r\n couponCode,\r\n discount,\r\n ])\r\n ),\r\n netUnitPrice: this.total.netUnitPrice,\r\n netSubtotal: this.total.netSubtotal,\r\n taxTotal: this.total.taxTotal,\r\n taxBreakdown: Object.fromEntries(\r\n Object.entries(this.total.taxBreakdown).map(([taxRuleId, taxBreakdown]) => [\r\n taxRuleId,\r\n {\r\n rate: taxBreakdown.rate,\r\n taxableUnitPrice: taxBreakdown.taxableUnitPrice,\r\n taxPerUnit: taxBreakdown.taxPerUnit,\r\n taxAmount: taxBreakdown.taxAmount,\r\n system: taxBreakdown.system,\r\n subSystem: taxBreakdown.subSystem\r\n }\r\n ])\r\n ),\r\n grandTotal: this.total.grandTotal,\r\n };\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the line item's details.\r\n * @returns LineItemData.\r\n */\r\n getDetails(): LineItemData {\r\n const pricing = this.getPricing();\r\n const total = this.getTotal();\r\n return {\r\n id: this.getId(),\r\n productKey: this.getProductKey(),\r\n sku: this.getSku(),\r\n selectionAttributes: this.getSelectionAttributes(),\r\n name: this.getName(),\r\n specifications: this.getSpecifications(),\r\n primaryImage: this.getImage().getDetails(),\r\n subItems: this.getSubItems(),\r\n pricing: {\r\n unitPrice: pricing.unitPrice.getDetails(),\r\n tierPricing: pricing.tierPricing.getDetails(),\r\n taxCategory: pricing.taxCategory,\r\n applicableTaxRule: pricing.applicableTaxRule.map(rule => rule.getDetails()),\r\n },\r\n state: this.getState(),\r\n productType: this.getProductType(),\r\n total: {\r\n quantity: total.quantity,\r\n unitPrice: total.unitPrice.getDetails(),\r\n subtotal: total.subtotal.getDetails(),\r\n discountTotal: total.discountTotal.getDetails(),\r\n discountBreakdown: Object.fromEntries(\r\n Object.entries(total.discountBreakdown).map(([couponCode, discount]) => [\r\n couponCode,\r\n discount.getDetails(),\r\n ])\r\n ),\r\n netUnitPrice: total.netUnitPrice.getDetails(),\r\n netSubtotal: total.netSubtotal.getDetails(),\r\n taxTotal: total.taxTotal.getDetails(),\r\n taxBreakdown: Object.fromEntries(\r\n Object.entries(total.taxBreakdown).map(([taxRuleId, taxBreakdown]) => [\r\n taxRuleId,\r\n {\r\n rate: taxBreakdown.rate,\r\n taxableUnitPrice: taxBreakdown.taxableUnitPrice.getDetails(),\r\n taxPerUnit: taxBreakdown.taxPerUnit.getDetails(),\r\n taxAmount: taxBreakdown.taxAmount.getDetails(),\r\n system: taxBreakdown.system,\r\n subSystem: taxBreakdown.subSystem\r\n }\r\n ])\r\n ),\r\n grandTotal: total.grandTotal.getDetails(),\r\n },\r\n customFields: this.getAllCustomFields()\r\n };\r\n }\r\n\r\n /**\r\n\t * Validates that there are no overlapping price brackets for any tax rules within the charge.\r\n\t * @param taxRules - The list of tax rules to validate.\r\n\t * @throws {InvalidLineItemTaxRuleError} Duplicate tax rule IDs will results in error.\r\n\t */\r\n private validateTaxRules(taxRules: TaxRuleModel[]): void {\r\n const uniqueTaxRule = new Set();\r\n for (let i = 0; i < taxRules.length; i++) {\r\n const currentTaxRuleId = taxRules[i].getTaxRuleId();\r\n if (uniqueTaxRule.has(currentTaxRuleId)) {\r\n throw new InvalidLineItemTaxRuleError(\"Duplicate tax rule ID found: \" + currentTaxRuleId);\r\n } else {\r\n uniqueTaxRule.add(currentTaxRuleId);\r\n }\r\n }\r\n }\r\n /**\r\n * Adds or updates sub-items (e.g., sizes with quantities) to the line item.\r\n * If a sub-item with the same size already exists, its quantity is either\r\n * updated by adding the new quantity or replaced entirely, based on the `addQuantity` flag.\r\n * Sub-items with a resulting quantity of 0 are removed.\r\n * @param subItems - An array of `SubItem` objects to add or update.\r\n * @param addQuantity - If true, adds the quantity from `subItem` to the existing quantity.\r\n * If false, replaces the existing quantity with the one from `subItem`.\r\n */\r\n addSubItems(subItems: SubItem[], addQuantity: boolean): void {\r\n subItems.forEach(subItem => {\r\n const existingSubItem = this.subItems.find(item => item.size === subItem.size);\r\n if (existingSubItem) {\r\n existingSubItem.quantity = addQuantity ? existingSubItem.quantity + subItem.quantity : subItem.quantity;\r\n } else {\r\n this.subItems.push(subItem);\r\n }\r\n })\r\n this.subItems = this.subItems.filter(sub => sub.quantity > 0);\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Updates the line item with the latest product data (price, image, name, specifications).\r\n * Validates that the product matches the line item's selection and is active.\r\n * @param product - The product model to update from.\r\n * @param cartCountry - The country code for pricing context.\r\n * @param cartCurrency - The currency code for pricing context.\r\n * @throws {Error} If product mismatch, inactive, size mismatch, or pricing missing.\r\n */\r\n public updateProductData(product: ProductModel, cartCountry: CountryCode, cartCurrency: CurrencyCode): void {\r\n if (this.productKey !== product.getKey() || !product.validateSelectionAttribute(this.selectionAttributes)) {\r\n throw new ProductMismatchError();\r\n } else if (!product.getIsActive()) {\r\n throw new ProductInactiveError();\r\n }\r\n\r\n this.subItems.forEach(subItem => {\r\n if (!product.validateSize(subItem.size)) {\r\n throw new SizeMismatchError();\r\n }\r\n });\r\n\r\n const productPricing = product.getPriceDetails(cartCountry);\r\n if (!productPricing || productPricing.getCurrency() !== cartCurrency) {\r\n throw new PricingNotFoundError();\r\n }\r\n this.name = product.getName();\r\n this.specifications = product.getSpecifications();\r\n this.sku = product.getSku(this.selectionAttributes) as string;\r\n this.primaryImage = product.getImages(this.selectionAttributes).primary;\r\n\r\n const quantity = this.subItems.reduce((sum, s) => sum + s.quantity, 0);\r\n \r\n const unitPrice = productPricing.getApplicableUnitPrice(quantity, this.selectionAttributes);\r\n\r\n\r\n this.productType = product.getProductType();\r\n\r\n this.pricing = {\r\n unitPrice: unitPrice,\r\n tierPricing: productPricing,\r\n taxCategory: productPricing.getTaxCategory(),\r\n applicableTaxRule: this.pricing.applicableTaxRule\r\n }\r\n\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Updates the discounts applied to this line item and recalculates totals.\r\n * @param appliedDiscounts - List of coupons and their allocated discount amounts.\r\n */\r\n public updateDiscounts(appliedDiscounts: { coupon: CouponModel, amount: PriceModel }[]): void {\r\n let lineItemDiscounts = {} as Record<string, PriceModel>;\r\n appliedDiscounts.forEach(discount => {\r\n lineItemDiscounts[discount.coupon.getCode()] = discount.amount;\r\n });\r\n\r\n this.total.discountBreakdown = lineItemDiscounts;\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Updates the tax rule for this line item and recalculates totals.\r\n * @param taxRule - The new tax rule to apply.\r\n * @throws {Error} If the tax rule category does not match the item's tax category.\r\n */\r\n public updateTax(taxRules: TaxRuleModel[]): void {\r\n taxRules.forEach(taxRule => {\r\n if (!taxRule.appliesTo(this.pricing.taxCategory, taxRule.getCountry())) {\r\n throw new InvalidTaxRuleError();\r\n }\r\n });\r\n\r\n this.validateTaxRules(taxRules);\r\n this.pricing.applicableTaxRule = taxRules;\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Recalculates the line item totals based on current quantity, unit price, discounts, and tax rates.\r\n */\r\n public calculateTotals(): void {\r\n const zero = this.pricing.unitPrice.zero();\r\n const totalQuantity = this.subItems.reduce((sum, s) => sum + s.quantity, 0);\r\n\r\n if (this.state === LineItemState.CANCELLED) {\r\n this.total = {\r\n quantity: 0,\r\n unitPrice: zero,\r\n subtotal: zero,\r\n discountTotal: zero,\r\n discountBreakdown: {},\r\n netUnitPrice: zero,\r\n netSubtotal: zero,\r\n taxTotal: zero,\r\n taxBreakdown: {},\r\n grandTotal: zero\r\n };\r\n return;\r\n }\r\n\r\n const tierUnitPrice = this.pricing.tierPricing.getApplicableUnitPrice(totalQuantity, this.selectionAttributes);\r\n \r\n // Initial totals are treated as inclusive if the product is tax inclusive\r\n const initialSubTotal = tierUnitPrice.multiply(totalQuantity);\r\n const totalDiscount = Object.values(this.total.discountBreakdown).reduce((sum, s) => sum.add(s), zero);\r\n const initialNetSubtotal = initialSubTotal.subtract(totalDiscount);\r\n const initialNetUnitPrice = totalQuantity > 0 ? initialNetSubtotal.divide(totalQuantity) : zero;\r\n\r\n const taxBreakdown: Record<string, LineItemTaxBreakdownModel> = {};\r\n let taxTotal = zero;\r\n \r\n let finalUnitPrice = tierUnitPrice;\r\n let finalSubTotal = initialSubTotal;\r\n let finalNetSubtotal = initialNetSubtotal;\r\n let finalNetUnitPrice = initialNetUnitPrice;\r\n\r\n if (this.pricing.tierPricing.getIsTaxInclusive()) {\r\n // 1. Reverse calculate unit price for the base fields\r\n finalUnitPrice = extractExclusiveBase(tierUnitPrice, this.pricing.applicableTaxRule);\r\n finalSubTotal = finalUnitPrice.multiply(totalQuantity);\r\n\r\n // 2. Reverse calculate net unit price and distribute taxes perfectly\r\n if (initialNetUnitPrice.getAmount() > 0) {\r\n finalNetUnitPrice = extractExclusiveBase(initialNetUnitPrice, this.pricing.applicableTaxRule);\r\n finalNetSubtotal = finalNetUnitPrice.multiply(totalQuantity);\r\n\r\n const distributedTaxes = calculateDistributedTaxes(finalNetUnitPrice, initialNetUnitPrice, this.pricing.applicableTaxRule);\r\n \r\n distributedTaxes.forEach(dt => {\r\n const taxAmount = dt.taxAmount.multiply(totalQuantity).round();\r\n const taxRule = this.pricing.applicableTaxRule.find(r => r.getTaxRuleId() === dt.ruleId)!;\r\n \r\n taxBreakdown[dt.ruleId] = {\r\n rate: dt.rate,\r\n taxableUnitPrice: finalNetUnitPrice,\r\n taxPerUnit: dt.taxAmount,\r\n taxAmount: taxAmount,\r\n system: taxRule.getTaxSystem(),\r\n subSystem: taxRule.getTaxSubSystem()\r\n };\r\n taxTotal = taxTotal.add(taxAmount);\r\n });\r\n }\r\n } else {\r\n // Standard exclusive tax calculation\r\n this.pricing.applicableTaxRule.forEach(taxRule => {\r\n const rate = taxRule.getApplicableTaxRate(finalNetUnitPrice);\r\n const taxPerUnit = taxRule.calculateTax(finalNetUnitPrice);\r\n const taxAmount = taxPerUnit.multiply(totalQuantity).round();\r\n taxBreakdown[taxRule.getTaxRuleId()] = {\r\n rate: rate,\r\n taxableUnitPrice: finalNetUnitPrice,\r\n taxPerUnit: taxPerUnit,\r\n taxAmount: taxAmount,\r\n system: taxRule.getTaxSystem(),\r\n subSystem: taxRule.getTaxSubSystem()\r\n };\r\n taxTotal = taxTotal.add(taxAmount);\r\n });\r\n }\r\n\r\n const grandTotal = finalNetSubtotal.add(taxTotal);\r\n\r\n this.total = {\r\n quantity: totalQuantity,\r\n unitPrice: finalUnitPrice,\r\n subtotal: finalSubTotal,\r\n discountTotal: totalDiscount,\r\n discountBreakdown: this.total.discountBreakdown,\r\n netUnitPrice: finalNetUnitPrice,\r\n netSubtotal: finalNetSubtotal,\r\n taxTotal: taxTotal,\r\n taxBreakdown: taxBreakdown,\r\n grandTotal: grandTotal\r\n };\r\n }\r\n\r\n /**\r\n * Updates the line item's state.\r\n * @param newState \r\n */\r\n public updateState(newState: LineItemState): void {\r\n if (this.state in LineItemState) {\r\n if (this.state !== newState) {\r\n this.state = newState;\r\n }\r\n } else {\r\n throw new InvalidLineItemStateError(newState);\r\n }\r\n }\r\n\r\n /**\r\n * Resets the line item's properties to their default empty or initial state.\r\n * Useful for clearing out line item data without creating a new instance.\r\n * Recalculates total quantity and price total afterwards (which will be zero).\r\n */\r\n clearLineItem(): void {\r\n const zero = this.pricing.unitPrice.zero()\r\n this.id = '';\r\n this.productKey = '';\r\n this.sku = '';\r\n this.selectionAttributes = { color: { name: '' } };\r\n this.name = { en: '' };\r\n this.primaryImage = new ImageInfoModel({ sources: { original: '' } });\r\n this.subItems = [];\r\n this.productType = ProductType.GOODS;\r\n this.pricing = {\r\n unitPrice: zero,\r\n tierPricing: this.pricing.tierPricing,\r\n taxCategory: this.pricing.taxCategory,\r\n applicableTaxRule: []\r\n }\r\n this.total = {\r\n quantity: 0,\r\n unitPrice: zero,\r\n subtotal: zero,\r\n discountTotal: zero,\r\n discountBreakdown: {},\r\n netUnitPrice: zero,\r\n netSubtotal: zero,\r\n taxTotal: zero,\r\n taxBreakdown: {},\r\n grandTotal: zero\r\n };\r\n }\r\n}\r\n"]}
@@ -0,0 +1,2 @@
1
+ import {b as b$1}from'./chunk-7RAIVZKB.mjs';import {a}from'./chunk-UIQH5QIR.mjs';import {e as e$1}from'./chunk-PL5HGCWN.mjs';import {h,e,l as l$1,n,m,o,p,y}from'./chunk-O6BLQQO7.mjs';import {b}from'./chunk-UXZBULDS.mjs';import G from'crypto';var C=new Uint8Array(256),T=C.length;function M(){return T>C.length-16&&(G.randomFillSync(C),T=0),C.slice(T,T+=16)}var R=/^(?:[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 j(i){return typeof i=="string"&&R.test(i)}var $=j;var u=[];for(let i=0;i<256;++i)u.push((i+256).toString(16).slice(1));function x(i,e=0){return u[i[e+0]]+u[i[e+1]]+u[i[e+2]]+u[i[e+3]]+"-"+u[i[e+4]]+u[i[e+5]]+"-"+u[i[e+6]]+u[i[e+7]]+"-"+u[i[e+8]]+u[i[e+9]]+"-"+u[i[e+10]]+u[i[e+11]]+u[i[e+12]]+u[i[e+13]]+u[i[e+14]]+u[i[e+15]]}function q(i){if(!$(i))throw TypeError("Invalid UUID");let e,t=new Uint8Array(16);return t[0]=(e=parseInt(i.slice(0,8),16))>>>24,t[1]=e>>>16&255,t[2]=e>>>8&255,t[3]=e&255,t[4]=(e=parseInt(i.slice(9,13),16))>>>8,t[5]=e&255,t[6]=(e=parseInt(i.slice(14,18),16))>>>8,t[7]=e&255,t[8]=(e=parseInt(i.slice(19,23),16))>>>8,t[9]=e&255,t[10]=(e=parseInt(i.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 B=q;function Z(i){i=unescape(encodeURIComponent(i));let e=[];for(let t=0;t<i.length;++t)e.push(i.charCodeAt(t));return e}var Y="6ba7b810-9dad-11d1-80b4-00c04fd430c8",F="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function v(i,e,t){function r(n,s,a,c){var p;if(typeof n=="string"&&(n=Z(n)),typeof s=="string"&&(s=B(s)),((p=s)===null||p===void 0?void 0:p.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let o=new Uint8Array(16+n.length);if(o.set(s),o.set(n,s.length),o=t(o),o[6]=o[6]&15|e,o[8]=o[8]&63|128,a){c=c||0;for(let y=0;y<16;++y)a[c+y]=o[y];return a}return x(o)}try{r.name=i;}catch{}return r.DNS=Y,r.URL=F,r}var L={randomUUID:G.randomUUID};function W(i,e,t){if(L.randomUUID&&!e&&!i)return L.randomUUID();i=i||{};let r=i.random||(i.rng||M)();if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,e){t=t||0;for(let n=0;n<16;++n)e[t+n]=r[n];return e}return x(r)}var E=W;function J(i){return Array.isArray(i)?i=Buffer.from(i):typeof i=="string"&&(i=Buffer.from(i,"utf8")),G.createHash("sha1").update(i).digest()}var N=J;var _=v("v5",80,N),z=_;var ee={isUUID:i=>/^[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(i),isEmail:i=>/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(i),isURL:i=>/^(http|https):\/\/[^ "]+$/.test(i),generateUUID:(i,e)=>e&&i?z(i,e):E(),generateSearchId:(i,e)=>`${i}#${f.generateSelectionAttributesKey(e)}`,getKeyfromSearchId:i=>{let[e,t]=i.split("#");return {key:e,selectionAttributes:f.parseSelectionAttributesKey(t)}},deepClone(i){return structuredClone(i)}},l=ee;var f=class i extends b{id;key;name;description;slug;brand;pricing;variants;targetGender;attributes;specifications;categories;productType;isActive;searchTags;static productKeyRegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static productSKURegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static generateSelectionAttributesKey(e){if(typeof e!="object")throw new h("Selection attributes must be an object");return Object.keys(e).filter(r=>e[r]!==void 0&&r.toLowerCase()!=="size").sort().map(r=>e[r].name?`${r}:c+${e[r].name}`:`${r}:${e[r]}`).join("|").toLowerCase()}static parseSelectionAttributesKey(e){try{let t={},r=e.split("|");for(let n of r){let[s,a]=n.split(":");a.startsWith("c+")?t[s]={name:a.slice(2)}:t[s]=a;}return t}catch(t){throw new h(t?.message)}}constructor(e$1,t=new Date){super(e$1,t),this.id=e$1.id,this.key=e$1.key,this.name={...e$1.name},this.description={...e$1.description},this.slug={...e$1.slug},this.brand=e$1.brand,this.pricing=Object.keys(e$1.pricing).reduce((n,s)=>(e$1.pricing[s]&&(n[s]=P.create(e$1.pricing[s])),n),{}),this.targetGender=e$1.targetGender,this.attributes=l.deepClone(e$1.attributes),this.specifications=l.deepClone(e$1.specifications),this.categories=l.deepClone(e$1.categories),this.productType=e$1.productType??"GOODS";let r=new Set;this.variants=(e$1.variants||[]).map(n=>{if(!n.selectionAttributes||typeof n.selectionAttributes!="object")throw new h("Selection attributes are required");this.checkSelectionAttributes(n.selectionAttributes);let s=i.generateSelectionAttributesKey(n.selectionAttributes);if(r.has(s))throw new e(s);return r.add(s),{sku:n.sku,selectionAttributes:n.selectionAttributes,images:{primary:new b$1(n.images.primary),gallery:(n.images.gallery||[]).map(a=>new b$1(a))}}}),this.isActive=e$1.isActive,this.searchTags=e$1.searchTags?l.deepClone(e$1.searchTags):{en:[]};}getId(){return this.id}getKey(){return this.key}getName(e){return e?this.name[e]??this.name[e$1[e]]??this.name.en:l.deepClone(this.name)}getDescription(e){return e?this.description[e]??this.description[e$1[e]]??this.description.en:l.deepClone(this.description)}getSlug(e){return e?this.slug[e]??this.slug[e$1[e]]??this.slug.en:l.deepClone(this.slug)}getBrand(){return this.brand}getPriceDetails(e){return e?this.pricing[e]??null:{...this.pricing}}getAttributes(){return l.deepClone(this.attributes)}getVariants(){return this.variants.map(e=>({sku:e.sku,selectionAttributes:l.deepClone(e.selectionAttributes),images:{primary:e.images.primary,gallery:[...e.images.gallery]}}))}getImagesBySelectionAttributes(e){let t=i.generateSelectionAttributesKey(e),r=this.variants.find(n=>i.generateSelectionAttributesKey(n.selectionAttributes)===t);return r?{primary:r.images.primary,gallery:[...r.images.gallery]}: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 l.deepClone(this.categories)}getProductType(){return this.productType}getSpecifications(e){return e?l.deepClone(this.specifications[e]??this.specifications[e$1[e]]??this.specifications.en):l.deepClone(this.specifications)}getSearchTags(e){return e?l.deepClone(this.searchTags[e]??this.searchTags[e$1[e]]??this.searchTags.en):l.deepClone(this.searchTags)}getDetails(){let e=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((t,r)=>(this.pricing[r]&&(t[r]=this.pricing[r]?.getDetails()),t),{}),attributes:this.getAttributes(),variants:this.variants.map(t=>({sku:t.sku,selectionAttributes:l.deepClone(t.selectionAttributes),images:{primary:t.images.primary.getDetails(),gallery:t.images.gallery.map(r=>r.getDetails())}})),isActive:this.getIsActive(),targetGender:this.getTargetGender(),categories:this.getCategories(),productType:this.getProductType(),specifications:this.getSpecifications(),searchTags:this.getSearchTags(),...e}}checkSelectionAttributes(e){if(!e||typeof e!="object")throw new h("Selection attributes are required");Object.keys(this.attributes).forEach(t=>{if(t.toLowerCase()==="size")return;let r=this.attributes[t],n=e[t];if(n===void 0)throw new h(`Selection attribute '${t}' is missing`);if(typeof r=="string"){if(typeof n!="string"||r!==n)throw new h(`Selection attribute '${t}' is invalid`)}else if(Array.isArray(r)){if(r.length>0&&typeof r[0]=="string"){if(typeof n!="string"||!r.includes(n))throw new h(`Selection attribute '${t}' is invalid`)}else if(typeof n!="object"||!("name"in n)||r.findIndex(s=>s.name===n.name)<0)throw new h(`Selection attribute '${t}' is invalid`)}});}getSku(e){let t=i.generateSelectionAttributesKey(e);return this.variants.find(n=>i.generateSelectionAttributesKey(n.selectionAttributes)===t)?.sku}validateSelectionAttribute(e){let t=i.generateSelectionAttributesKey(e);return this.variants.some(r=>i.generateSelectionAttributesKey(r.selectionAttributes)===t)}validateSize(e){return this.attributes.size.includes(e)}};var te=(t=>(t.VOLUME="volume",t.SELECTION="selection",t))(te||{}),P=class{type;taxCategory;isTaxInclusive;static create(e){return e.type==="selection"?new K(e):new Q(e)}constructor(e){if(!e.taxCategory)throw new l$1;this.taxCategory=e.taxCategory,this.isTaxInclusive=e.isTaxInclusive??!1,this.type=e.type??"volume";}getType(){return this.type}getTaxCategory(){return this.taxCategory}getIsTaxInclusive(){return this.isTaxInclusive}},Q=class extends P{baseUnitPrice;tiers;currency;constructor(e){if(super(e),this.type="volume",!e.baseUnitPrice)throw new n("Base unit price is required for volume pricing.");this.baseUnitPrice=new a(e.baseUnitPrice),this.currency=e.currency??this.baseUnitPrice.getCurrency();let t=(e.tiers??[]).map(c=>({enabled:c.enabled??!0,minQuantity:c.minQuantity,unitPrice:new a(c.unitPrice)})).sort((c,p)=>c.minQuantity-p.minQuantity);if(t.some(c=>c.minQuantity<=0))throw new m;let n$1=this.baseUnitPrice.getCurrency()!==this.currency||t.some(c=>c.unitPrice.getCurrency()!==this.currency),s=t.some((c,p)=>p>0&&c.unitPrice.compareTo(t[p-1].unitPrice)>0),a$1=t[0]?.unitPrice.compareTo(this.baseUnitPrice)>0;if(n$1||s||a$1)throw new n("Tiers must share the same currency and must not increase in unit price.");this.tiers=t;}getBaseUnitPrice(){return this.baseUnitPrice}getCurrency(){return this.baseUnitPrice.getCurrency()}getApplicableUnitPrice(e){if(e<=0)throw new o;let t=this.tiers.filter(r=>r.enabled);for(let r=t.length-1;r>=0;r--){let n=t[r];if(e>=n.minQuantity)return n.unitPrice}throw new p(e)}getMinQuantity(){return this.tiers.filter(t=>t.enabled)[0]?.minQuantity??1}getMaxDiscountPercent(){let e=this.tiers.filter(s=>s.enabled);if(!e.length)return 0;let t=Math.min(...e.map(s=>s.unitPrice.getAmount())),r=this.baseUnitPrice.getAmount(),n=(r-t)/r*100;return n>0?n:0}getDetails(){return {type:this.type,taxCategory:this.taxCategory,isTaxInclusive:this.isTaxInclusive,currency:this.currency,baseUnitPrice:this.baseUnitPrice.getDetails(),tiers:this.tiers.map(e=>({enabled:e.enabled,minQuantity:e.minQuantity,unitPrice:e.unitPrice.getDetails()}))}}},K=class extends P{currency;selections;constructor(e){super(e),this.type="selection",this.currency=e.currency,this.selections=(e.selections??[]).map(t=>{if(!t.baseUnitPrice)throw new n("Base unit price is required for each selection.");let r=new a(t.baseUnitPrice),n$1=(t.tiers??[]).map(o=>({enabled:o.enabled??!0,minQuantity:o.minQuantity??1,unitPrice:new a(o.unitPrice)})).sort((o,y)=>o.minQuantity-y.minQuantity);if(n$1.some(o=>o.minQuantity<=0))throw new m;let a$1=r.getCurrency()!==this.currency||n$1.some(o=>o.unitPrice.getCurrency()!==this.currency),c=n$1.some((o,y)=>y>0&&o.unitPrice.compareTo(n$1[y-1].unitPrice)>0),p=n$1[0]?.unitPrice.compareTo(r)>0;if(a$1||c||p)throw new n("Tiers must share the same currency and must not increase in unit price within the same selection.");return {selectionAttributes:{...t.selectionAttributes},baseUnitPrice:r,tiers:n$1}});}findMatch(e){let t=f.generateSelectionAttributesKey(e),r=this.selections.find(n=>f.generateSelectionAttributesKey(n.selectionAttributes)===t);if(!r)throw new n("No pricing configuration found for selection variant.");return r}getBaseUnitPrice(e){if(!e)throw new y("Selection attributes are required to get base unit price for selection pricing.");return this.findMatch(e).baseUnitPrice}getCurrency(){return this.currency}getApplicableUnitPrice(e,t){if(e<=0)throw new o;if(!t)throw new y("Selection attributes are required to get applicable unit price for selection pricing.");let n=this.findMatch(t).tiers.filter(s=>s.enabled);for(let s=n.length-1;s>=0;s--){let a=n[s];if(e>=a.minQuantity)return a.unitPrice}throw new p(e)}getMinQuantity(e){if(!e)throw new y("Selection attributes are required to get min quantity for selection pricing.");return this.findMatch(e).tiers.filter(n=>n.enabled)[0]?.minQuantity??1}getMaxDiscountPercent(e){if(!e)throw new y("Selection attributes are required to get max discount for selection pricing.");let t=this.findMatch(e),r=t.tiers.filter(c=>c.enabled);if(!r.length)return 0;let n=Math.min(...r.map(c=>c.unitPrice.getAmount())),s=t.baseUnitPrice.getAmount(),a=(s-n)/s*100;return a>0?a:0}getDetails(){return {type:this.type,taxCategory:this.taxCategory,isTaxInclusive:this.isTaxInclusive,currency:this.currency,selections:this.selections.map(e=>({selectionAttributes:e.selectionAttributes,baseUnitPrice:e.baseUnitPrice.getDetails(),...e.tiers.length>0?{tiers:e.tiers.map(t=>({enabled:t.enabled,minQuantity:t.minQuantity,unitPrice:t.unitPrice.getDetails()}))}:{}}))}}};export{l as a,te as b,P as c,Q as d,K as e,f};//# sourceMappingURL=chunk-7B5TAYNA.mjs.map
2
+ //# sourceMappingURL=chunk-7B5TAYNA.mjs.map