b23-lib 2.1.7 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Auth/index.js +1 -1
- package/dist/Auth/index.js.map +1 -1
- package/dist/Auth/index.mjs +1 -1
- package/dist/Classes/Cart.d.mts +1 -0
- package/dist/Classes/Cart.d.ts +1 -0
- package/dist/Classes/Cart.js +1 -2
- package/dist/Classes/Cart.js.map +1 -1
- package/dist/Classes/Cart.mjs +1 -1
- package/dist/Classes/Cart.mjs.map +1 -1
- package/dist/Classes/Charge.d.mts +99 -0
- package/dist/Classes/Charge.d.ts +99 -0
- package/dist/Classes/Charge.js +2 -0
- package/dist/Classes/Charge.js.map +1 -0
- package/dist/Classes/Charge.mjs +2 -0
- package/dist/Classes/Charge.mjs.map +1 -0
- package/dist/Classes/Coupon.js +1 -1
- package/dist/Classes/Coupon.js.map +1 -1
- package/dist/Classes/Coupon.mjs +1 -1
- package/dist/Classes/Enum.d.mts +4 -4
- package/dist/Classes/Enum.d.ts +4 -4
- package/dist/Classes/Enum.js +1 -1
- package/dist/Classes/Enum.js.map +1 -1
- package/dist/Classes/Enum.mjs +1 -1
- package/dist/Classes/Error.d.mts +4 -1
- package/dist/Classes/Error.d.ts +4 -1
- package/dist/Classes/Error.js +1 -1
- package/dist/Classes/Error.js.map +1 -1
- package/dist/Classes/Error.mjs +1 -1
- package/dist/Classes/ImageInfo.js.map +1 -1
- package/dist/Classes/ImageInfo.mjs +1 -1
- package/dist/Classes/Inventory.js +1 -1
- package/dist/Classes/Inventory.js.map +1 -1
- package/dist/Classes/Inventory.mjs +1 -1
- package/dist/Classes/LineItem.d.mts +46 -48
- package/dist/Classes/LineItem.d.ts +46 -48
- package/dist/Classes/LineItem.js +1 -2
- package/dist/Classes/LineItem.js.map +1 -1
- package/dist/Classes/LineItem.mjs +1 -1
- package/dist/Classes/Order.d.mts +1 -1
- package/dist/Classes/Order.d.ts +1 -1
- package/dist/Classes/Order.js +1 -2
- package/dist/Classes/Order.js.map +1 -1
- package/dist/Classes/Order.mjs +1 -1
- package/dist/Classes/Order.mjs.map +1 -1
- package/dist/Classes/Price.js +1 -1
- package/dist/Classes/Price.js.map +1 -1
- package/dist/Classes/Price.mjs +1 -1
- package/dist/Classes/Product.js +1 -1
- package/dist/Classes/Product.js.map +1 -1
- package/dist/Classes/Product.mjs +1 -1
- package/dist/Classes/ShoppingContainer.d.mts +98 -40
- package/dist/Classes/ShoppingContainer.d.ts +98 -40
- package/dist/Classes/ShoppingContainer.js +1 -2
- package/dist/Classes/ShoppingContainer.js.map +1 -1
- package/dist/Classes/ShoppingContainer.mjs +1 -1
- package/dist/Classes/TaxCategoryModel.d.mts +42 -0
- package/dist/Classes/TaxCategoryModel.d.ts +42 -0
- package/dist/Classes/TaxCategoryModel.js +2 -0
- package/dist/Classes/TaxCategoryModel.js.map +1 -0
- package/dist/Classes/TaxCategoryModel.mjs +2 -0
- package/dist/Classes/TaxCategoryModel.mjs.map +1 -0
- package/dist/Classes/TaxRule.d.mts +59 -79
- package/dist/Classes/TaxRule.d.ts +59 -79
- package/dist/Classes/TaxRule.js +1 -2
- package/dist/Classes/TaxRule.js.map +1 -1
- package/dist/Classes/TaxRule.mjs +1 -1
- package/dist/Classes/TieredPrice.d.mts +4 -4
- package/dist/Classes/TieredPrice.d.ts +4 -4
- package/dist/Classes/TieredPrice.js +1 -1
- package/dist/Classes/TieredPrice.js.map +1 -1
- package/dist/Classes/TieredPrice.mjs +1 -1
- package/dist/{chunk-TJ7AZBND.mjs → chunk-6X5O25W5.mjs} +2 -2
- package/dist/chunk-6X5O25W5.mjs.map +1 -0
- package/dist/chunk-FC4P26U3.mjs +2 -0
- package/dist/chunk-FC4P26U3.mjs.map +1 -0
- package/dist/chunk-IIPG3DTO.mjs +2 -0
- package/dist/chunk-IIPG3DTO.mjs.map +1 -0
- package/dist/{chunk-AWZ6KRLF.mjs → chunk-JE7BAYI5.mjs} +2 -2
- package/dist/{chunk-AWZ6KRLF.mjs.map → chunk-JE7BAYI5.mjs.map} +1 -1
- package/dist/chunk-KKQLCW6A.mjs +2 -0
- package/dist/chunk-KKQLCW6A.mjs.map +1 -0
- package/dist/chunk-PTIPDRB4.mjs +2 -0
- package/dist/chunk-PTIPDRB4.mjs.map +1 -0
- package/dist/{chunk-WS7ZY5ZZ.mjs → chunk-RSMXGZD4.mjs} +2 -2
- package/dist/{chunk-WS7ZY5ZZ.mjs.map → chunk-RSMXGZD4.mjs.map} +1 -1
- package/dist/{chunk-WSUPVXRZ.mjs → chunk-RSTZJZSQ.mjs} +2 -2
- package/dist/{chunk-WSUPVXRZ.mjs.map → chunk-RSTZJZSQ.mjs.map} +1 -1
- package/dist/chunk-U7DES3CI.mjs +2 -0
- package/dist/chunk-U7DES3CI.mjs.map +1 -0
- package/dist/{chunk-JHELVQYY.mjs → chunk-XPKK6DFA.mjs} +2 -2
- package/dist/chunk-XPKK6DFA.mjs.map +1 -0
- package/dist/chunk-XXETAAL4.mjs +2 -0
- package/dist/chunk-XXETAAL4.mjs.map +1 -0
- package/dist/index.d.mts +1 -5
- package/dist/index.d.ts +1 -5
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -1
- package/dist/chunk-232FJYNB.mjs +0 -2
- package/dist/chunk-232FJYNB.mjs.map +0 -1
- package/dist/chunk-72DR3HF2.mjs +0 -2
- package/dist/chunk-72DR3HF2.mjs.map +0 -1
- package/dist/chunk-ARMBZF3E.mjs +0 -3
- package/dist/chunk-ARMBZF3E.mjs.map +0 -1
- package/dist/chunk-JHELVQYY.mjs.map +0 -1
- package/dist/chunk-SFUOYZ3L.mjs +0 -2
- package/dist/chunk-SFUOYZ3L.mjs.map +0 -1
- package/dist/chunk-TJ7AZBND.mjs.map +0 -1
- package/dist/chunk-ZE7D77FR.mjs +0 -2
- package/dist/chunk-ZE7D77FR.mjs.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { P as PriceData,
|
|
1
|
+
import { P as PriceData, b as PriceModel, c as LocalizedString, d as LocalizedValue, L as LocaleCode, C as CountryCode, a as CurrencyCode } from '../Common-Bd8Xv8x4.mjs';
|
|
2
2
|
import CouponModel from './Coupon.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { TaxSystem, LineItemState } from './Enum.mjs';
|
|
4
4
|
import ImageInfoModel, { ImageInfoData } from './ImageInfo.mjs';
|
|
5
5
|
import ProductModel, { SelectionAttributes, ProductSpecification } from './Product.mjs';
|
|
6
|
-
import {
|
|
6
|
+
import { TaxRuleData, TaxRuleModel } from './TaxRule.mjs';
|
|
7
7
|
import { TieredPriceData, TieredPriceModel } from './TieredPrice.mjs';
|
|
8
8
|
import { CustomFieldAttributes, CustomFieldModel } from './Base.mjs';
|
|
9
9
|
import '../Auth/index.mjs';
|
|
@@ -15,23 +15,49 @@ type SubItem = {
|
|
|
15
15
|
type LineItemPricing = {
|
|
16
16
|
unitPrice: PriceData;
|
|
17
17
|
tierPricing: TieredPriceData;
|
|
18
|
-
taxCategory:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
taxCategory: string;
|
|
19
|
+
applicableTaxRule: TaxRuleData[];
|
|
20
|
+
};
|
|
21
|
+
type LineItemTaxBreakdown = {
|
|
22
|
+
rate: number;
|
|
23
|
+
taxableUnitPrice: PriceData;
|
|
24
|
+
taxPerUnit: PriceData;
|
|
25
|
+
amount: PriceData;
|
|
26
|
+
system: TaxSystem;
|
|
27
|
+
subSystem: string;
|
|
28
|
+
};
|
|
29
|
+
type LineItemTaxBreakdownModel = {
|
|
30
|
+
rate: number;
|
|
31
|
+
taxableUnitPrice: PriceModel;
|
|
32
|
+
taxPerUnit: PriceModel;
|
|
33
|
+
amount: PriceModel;
|
|
34
|
+
system: TaxSystem;
|
|
35
|
+
subSystem: string;
|
|
26
36
|
};
|
|
27
37
|
type LineItemTotals = {
|
|
28
38
|
quantity: number;
|
|
39
|
+
unitPrice: PriceData;
|
|
29
40
|
subtotal: PriceData;
|
|
30
41
|
discounts: Record<string, PriceData>;
|
|
31
|
-
|
|
42
|
+
totalDiscount: PriceData;
|
|
43
|
+
netUnitPrice: PriceData;
|
|
44
|
+
netSubtotal: PriceData;
|
|
45
|
+
taxBreakdown: Record<string, LineItemTaxBreakdown>;
|
|
32
46
|
taxTotal: PriceData;
|
|
33
47
|
grandTotal: PriceData;
|
|
34
48
|
};
|
|
49
|
+
type LineItemTotalsModel = {
|
|
50
|
+
quantity: number;
|
|
51
|
+
unitPrice: PriceModel;
|
|
52
|
+
subtotal: PriceModel;
|
|
53
|
+
discounts: Record<string, PriceModel>;
|
|
54
|
+
totalDiscount: PriceModel;
|
|
55
|
+
netUnitPrice: PriceModel;
|
|
56
|
+
netSubtotal: PriceModel;
|
|
57
|
+
taxBreakdown: Record<string, LineItemTaxBreakdownModel>;
|
|
58
|
+
taxTotal: PriceModel;
|
|
59
|
+
grandTotal: PriceModel;
|
|
60
|
+
};
|
|
35
61
|
type LineItemAttributes = CustomFieldAttributes & {
|
|
36
62
|
id: string;
|
|
37
63
|
productKey: string;
|
|
@@ -59,24 +85,11 @@ declare class LineItemModel extends CustomFieldModel {
|
|
|
59
85
|
protected pricing: {
|
|
60
86
|
unitPrice: PriceModel;
|
|
61
87
|
tierPricing: TieredPriceModel;
|
|
62
|
-
taxCategory:
|
|
63
|
-
|
|
64
|
-
taxRuleId: string;
|
|
65
|
-
taxSystem: TaxSystem;
|
|
66
|
-
country: CountryCode;
|
|
67
|
-
taxSlabs: TaxSlabModel[];
|
|
68
|
-
rate: number;
|
|
69
|
-
};
|
|
88
|
+
taxCategory: string;
|
|
89
|
+
applicableTaxRule: TaxRuleModel[];
|
|
70
90
|
};
|
|
71
91
|
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;
|
|
79
|
-
};
|
|
92
|
+
protected total: LineItemTotalsModel;
|
|
80
93
|
/**
|
|
81
94
|
* Creates an instance of LineItemModel.
|
|
82
95
|
* @param data - The initial line item attributes.
|
|
@@ -141,14 +154,8 @@ declare class LineItemModel extends CustomFieldModel {
|
|
|
141
154
|
getPricing(): {
|
|
142
155
|
unitPrice: PriceModel;
|
|
143
156
|
tierPricing: TieredPriceModel;
|
|
144
|
-
taxCategory:
|
|
145
|
-
|
|
146
|
-
taxRuleId: string;
|
|
147
|
-
taxSystem: TaxSystem;
|
|
148
|
-
country: "IN";
|
|
149
|
-
rate: number;
|
|
150
|
-
taxSlabs: TaxSlabModel[];
|
|
151
|
-
};
|
|
157
|
+
taxCategory: string;
|
|
158
|
+
applicableTaxRule: TaxRuleModel[];
|
|
152
159
|
};
|
|
153
160
|
/**
|
|
154
161
|
* Gets the current state of the line item.
|
|
@@ -159,16 +166,7 @@ declare class LineItemModel extends CustomFieldModel {
|
|
|
159
166
|
* Gets the total price for this line item (including all sub-items).
|
|
160
167
|
* @returns An object containing line item totals including subtotal, tax, discounts, and grand total.
|
|
161
168
|
*/
|
|
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
|
-
};
|
|
169
|
+
getTotal(): LineItemTotalsModel;
|
|
172
170
|
/**
|
|
173
171
|
* Gets a plain data object representing the line item's details.
|
|
174
172
|
* @returns LineItemData.
|
|
@@ -206,7 +204,7 @@ declare class LineItemModel extends CustomFieldModel {
|
|
|
206
204
|
* @param taxRule - The new tax rule to apply.
|
|
207
205
|
* @throws {Error} If the tax rule category does not match the item's tax category.
|
|
208
206
|
*/
|
|
209
|
-
updateTax(
|
|
207
|
+
updateTax(taxRules: TaxRuleModel[]): void;
|
|
210
208
|
/**
|
|
211
209
|
* Recalculates the line item totals based on current quantity, unit price, discounts, and tax rates.
|
|
212
210
|
*/
|
|
@@ -224,4 +222,4 @@ declare class LineItemModel extends CustomFieldModel {
|
|
|
224
222
|
clearLineItem(): void;
|
|
225
223
|
}
|
|
226
224
|
|
|
227
|
-
export { type LineItemAttributes, type LineItemData, type LineItemPricing, type LineItemTotals, type SubItem, LineItemModel as default };
|
|
225
|
+
export { type LineItemAttributes, type LineItemData, type LineItemPricing, type LineItemTaxBreakdown, type LineItemTaxBreakdownModel, type LineItemTotals, type LineItemTotalsModel, type SubItem, LineItemModel as default };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { P as PriceData,
|
|
1
|
+
import { P as PriceData, b as PriceModel, c as LocalizedString, d as LocalizedValue, L as LocaleCode, C as CountryCode, a as CurrencyCode } from '../Common-CXp_zjft.js';
|
|
2
2
|
import CouponModel from './Coupon.js';
|
|
3
|
-
import {
|
|
3
|
+
import { TaxSystem, LineItemState } from './Enum.js';
|
|
4
4
|
import ImageInfoModel, { ImageInfoData } from './ImageInfo.js';
|
|
5
5
|
import ProductModel, { SelectionAttributes, ProductSpecification } from './Product.js';
|
|
6
|
-
import {
|
|
6
|
+
import { TaxRuleData, TaxRuleModel } from './TaxRule.js';
|
|
7
7
|
import { TieredPriceData, TieredPriceModel } from './TieredPrice.js';
|
|
8
8
|
import { CustomFieldAttributes, CustomFieldModel } from './Base.js';
|
|
9
9
|
import '../Auth/index.js';
|
|
@@ -15,23 +15,49 @@ type SubItem = {
|
|
|
15
15
|
type LineItemPricing = {
|
|
16
16
|
unitPrice: PriceData;
|
|
17
17
|
tierPricing: TieredPriceData;
|
|
18
|
-
taxCategory:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
taxCategory: string;
|
|
19
|
+
applicableTaxRule: TaxRuleData[];
|
|
20
|
+
};
|
|
21
|
+
type LineItemTaxBreakdown = {
|
|
22
|
+
rate: number;
|
|
23
|
+
taxableUnitPrice: PriceData;
|
|
24
|
+
taxPerUnit: PriceData;
|
|
25
|
+
amount: PriceData;
|
|
26
|
+
system: TaxSystem;
|
|
27
|
+
subSystem: string;
|
|
28
|
+
};
|
|
29
|
+
type LineItemTaxBreakdownModel = {
|
|
30
|
+
rate: number;
|
|
31
|
+
taxableUnitPrice: PriceModel;
|
|
32
|
+
taxPerUnit: PriceModel;
|
|
33
|
+
amount: PriceModel;
|
|
34
|
+
system: TaxSystem;
|
|
35
|
+
subSystem: string;
|
|
26
36
|
};
|
|
27
37
|
type LineItemTotals = {
|
|
28
38
|
quantity: number;
|
|
39
|
+
unitPrice: PriceData;
|
|
29
40
|
subtotal: PriceData;
|
|
30
41
|
discounts: Record<string, PriceData>;
|
|
31
|
-
|
|
42
|
+
totalDiscount: PriceData;
|
|
43
|
+
netUnitPrice: PriceData;
|
|
44
|
+
netSubtotal: PriceData;
|
|
45
|
+
taxBreakdown: Record<string, LineItemTaxBreakdown>;
|
|
32
46
|
taxTotal: PriceData;
|
|
33
47
|
grandTotal: PriceData;
|
|
34
48
|
};
|
|
49
|
+
type LineItemTotalsModel = {
|
|
50
|
+
quantity: number;
|
|
51
|
+
unitPrice: PriceModel;
|
|
52
|
+
subtotal: PriceModel;
|
|
53
|
+
discounts: Record<string, PriceModel>;
|
|
54
|
+
totalDiscount: PriceModel;
|
|
55
|
+
netUnitPrice: PriceModel;
|
|
56
|
+
netSubtotal: PriceModel;
|
|
57
|
+
taxBreakdown: Record<string, LineItemTaxBreakdownModel>;
|
|
58
|
+
taxTotal: PriceModel;
|
|
59
|
+
grandTotal: PriceModel;
|
|
60
|
+
};
|
|
35
61
|
type LineItemAttributes = CustomFieldAttributes & {
|
|
36
62
|
id: string;
|
|
37
63
|
productKey: string;
|
|
@@ -59,24 +85,11 @@ declare class LineItemModel extends CustomFieldModel {
|
|
|
59
85
|
protected pricing: {
|
|
60
86
|
unitPrice: PriceModel;
|
|
61
87
|
tierPricing: TieredPriceModel;
|
|
62
|
-
taxCategory:
|
|
63
|
-
|
|
64
|
-
taxRuleId: string;
|
|
65
|
-
taxSystem: TaxSystem;
|
|
66
|
-
country: CountryCode;
|
|
67
|
-
taxSlabs: TaxSlabModel[];
|
|
68
|
-
rate: number;
|
|
69
|
-
};
|
|
88
|
+
taxCategory: string;
|
|
89
|
+
applicableTaxRule: TaxRuleModel[];
|
|
70
90
|
};
|
|
71
91
|
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;
|
|
79
|
-
};
|
|
92
|
+
protected total: LineItemTotalsModel;
|
|
80
93
|
/**
|
|
81
94
|
* Creates an instance of LineItemModel.
|
|
82
95
|
* @param data - The initial line item attributes.
|
|
@@ -141,14 +154,8 @@ declare class LineItemModel extends CustomFieldModel {
|
|
|
141
154
|
getPricing(): {
|
|
142
155
|
unitPrice: PriceModel;
|
|
143
156
|
tierPricing: TieredPriceModel;
|
|
144
|
-
taxCategory:
|
|
145
|
-
|
|
146
|
-
taxRuleId: string;
|
|
147
|
-
taxSystem: TaxSystem;
|
|
148
|
-
country: "IN";
|
|
149
|
-
rate: number;
|
|
150
|
-
taxSlabs: TaxSlabModel[];
|
|
151
|
-
};
|
|
157
|
+
taxCategory: string;
|
|
158
|
+
applicableTaxRule: TaxRuleModel[];
|
|
152
159
|
};
|
|
153
160
|
/**
|
|
154
161
|
* Gets the current state of the line item.
|
|
@@ -159,16 +166,7 @@ declare class LineItemModel extends CustomFieldModel {
|
|
|
159
166
|
* Gets the total price for this line item (including all sub-items).
|
|
160
167
|
* @returns An object containing line item totals including subtotal, tax, discounts, and grand total.
|
|
161
168
|
*/
|
|
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
|
-
};
|
|
169
|
+
getTotal(): LineItemTotalsModel;
|
|
172
170
|
/**
|
|
173
171
|
* Gets a plain data object representing the line item's details.
|
|
174
172
|
* @returns LineItemData.
|
|
@@ -206,7 +204,7 @@ declare class LineItemModel extends CustomFieldModel {
|
|
|
206
204
|
* @param taxRule - The new tax rule to apply.
|
|
207
205
|
* @throws {Error} If the tax rule category does not match the item's tax category.
|
|
208
206
|
*/
|
|
209
|
-
updateTax(
|
|
207
|
+
updateTax(taxRules: TaxRuleModel[]): void;
|
|
210
208
|
/**
|
|
211
209
|
* Recalculates the line item totals based on current quantity, unit price, discounts, and tax rates.
|
|
212
210
|
*/
|
|
@@ -224,4 +222,4 @@ declare class LineItemModel extends CustomFieldModel {
|
|
|
224
222
|
clearLineItem(): void;
|
|
225
223
|
}
|
|
226
224
|
|
|
227
|
-
export { type LineItemAttributes, type LineItemData, type LineItemPricing, type LineItemTotals, type SubItem, LineItemModel as default };
|
|
225
|
+
export { type LineItemAttributes, type LineItemData, type LineItemPricing, type LineItemTaxBreakdown, type LineItemTaxBreakdownModel, type LineItemTotals, type LineItemTotalsModel, type SubItem, LineItemModel as default };
|
package/dist/Classes/LineItem.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
'use strict';var ct=require('crypto');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var ct__default=/*#__PURE__*/_interopDefault(ct);var L=new Uint8Array(256),v=L.length;function Y(){return v>L.length-16&&(ct__default.default.randomFillSync(L),v=0),L.slice(v,v+=16)}var et=/^(?:[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 ut(i){return typeof i=="string"&&et.test(i)}var rt=ut;var p=[];for(let i=0;i<256;++i)p.push((i+256).toString(16).slice(1));function R(i,t=0){return p[i[t+0]]+p[i[t+1]]+p[i[t+2]]+p[i[t+3]]+"-"+p[i[t+4]]+p[i[t+5]]+"-"+p[i[t+6]]+p[i[t+7]]+"-"+p[i[t+8]]+p[i[t+9]]+"-"+p[i[t+10]]+p[i[t+11]]+p[i[t+12]]+p[i[t+13]]+p[i[t+14]]+p[i[t+15]]}function lt(i){if(!rt(i))throw TypeError("Invalid UUID");let t,e=new Uint8Array(16);return e[0]=(t=parseInt(i.slice(0,8),16))>>>24,e[1]=t>>>16&255,e[2]=t>>>8&255,e[3]=t&255,e[4]=(t=parseInt(i.slice(9,13),16))>>>8,e[5]=t&255,e[6]=(t=parseInt(i.slice(14,18),16))>>>8,e[7]=t&255,e[8]=(t=parseInt(i.slice(19,23),16))>>>8,e[9]=t&255,e[10]=(t=parseInt(i.slice(24,36),16))/1099511627776&255,e[11]=t/4294967296&255,e[12]=t>>>24&255,e[13]=t>>>16&255,e[14]=t>>>8&255,e[15]=t&255,e}var it=lt;function gt(i){i=unescape(encodeURIComponent(i));let t=[];for(let e=0;e<i.length;++e)t.push(i.charCodeAt(e));return t}var dt="6ba7b810-9dad-11d1-80b4-00c04fd430c8",mt="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function H(i,t,e){function r(n,o,a,c){var u;if(typeof n=="string"&&(n=gt(n)),typeof o=="string"&&(o=it(o)),((u=o)===null||u===void 0?void 0:u.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(o),l.set(n,o.length),l=e(l),l[6]=l[6]&15|t,l[8]=l[8]&63|128,a){c=c||0;for(let g=0;g<16;++g)a[c+g]=l[g];return a}return R(l)}try{r.name=i;}catch{}return r.DNS=dt,r.URL=mt,r}var Z={randomUUID:ct__default.default.randomUUID};function ht(i,t,e){if(Z.randomUUID&&!t&&!i)return Z.randomUUID();i=i||{};let r=i.random||(i.rng||Y)();if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,t){e=e||0;for(let n=0;n<16;++n)t[e+n]=r[n];return t}return R(r)}var X=ht;function ft(i){return Array.isArray(i)?i=Buffer.from(i):typeof i=="string"&&(i=Buffer.from(i,"utf8")),ct__default.default.createHash("sha1").update(i).digest()}var nt=ft;var xt=H("v5",80,nt),W=xt;var D=class{customFields;constructor(t,e=new Date){this.customFields={...t.customFields};}getCustomField(t){return this.customFields[t]??null}setCustomField(t,e){this.customFields[t]=e;}getAllCustomFields(){return {...this.customFields}}},S=class extends D{version;createdAt;modifiedAt;modifiedBy;constructor(t,e=new Date){super(t),this.version=t.version??1,this.createdAt=t.createdAt&&!isNaN(Date.parse(t.createdAt))?new Date(t.createdAt).toISOString():e.toISOString(),this.modifiedAt=t.modifiedAt&&!isNaN(Date.parse(t.modifiedAt))?new Date(t.modifiedAt).toISOString():e.toISOString(),this.modifiedBy={...t.modifiedBy};}getDetails(){return {customFields:this.getAllCustomFields(),version:this.getVersion(),createdAt:this.getCreatedAt(),modifiedAt:this.getModifiedAt(),modifiedBy:this.getModifiedBy()}}getVersion(){return this.version}getCreatedAt(){return this.createdAt}getCreatedAtTime(){return new Date(this.createdAt).getTime()}getModifiedAt(){return this.modifiedAt}getModifiedAtTime(){return new Date(this.modifiedAt).getTime()}getModifiedBy(){return {...this.modifiedBy}}setModifiedBy(t,e,r,n){this.modifiedBy={id:t,authType:e,requestId:r,lambdaName:n};}};var x={"en-IN":"en","kn-IN":"kn"};var ot={INR:"\u20B9"},at={INR:"en-IN"};var J=(g=>(g.INITIAL="INITIAL",g.PROCESSING="PROCESSING",g.SHIPPED="SHIPPED",g.DELIVERED="DELIVERED",g.CANCELLED="CANCELLED",g.RETURN_REQUESTED="RETURN_REQUESTED",g.RETURNED="RETURNED",g.REFUND_INITIATED="REFUND_INITIATED",g.REFUNDED="REFUNDED",g.ON_HOLD="ON_HOLD",g))(J||{});var E=class extends Error{constructor(t){super(`Invalid line item state: ${t}`),this.name="InvalidLineItemStateError";}},U=class extends Error{constructor(t){super(`Duplicate size found: ${t}`),this.name="DuplicateSizeError";}},N=class extends Error{constructor(t){super(`Duplicate selection attribute found: ${t}`),this.name="DuplicateSelectionAttributeError";}},F=class extends Error{constructor(t="Product and selection attributes do not match."){super(`ProductMismatch: ${t}`),this.name="ProductMismatchError";}},$=class extends Error{constructor(t="Product is not active."){super(`ProductInactive: ${t}`),this.name="ProductInactiveError";}},y=class extends Error{constructor(t="Failed to parse selection attributes key."){super(`SelectionAttributeParseError: ${t}`),this.name="SelectionAttributeParseError";}},z=class extends Error{constructor(t="Size does not match."){super(`SizeMismatch: ${t}`),this.name="SizeMismatchError";}},O=class extends Error{constructor(t="Pricing details not available for the product"){super(`NotFound: ${t}`),this.name="PricingNotFoundError";}},B=class extends Error{constructor(t="Tax rule category mismatch."){super(`InvalidTaxRule: ${t}`),this.name="InvalidTaxRuleError";}},k=class extends Error{constructor(t="Tax category is not valid."){super(`InvalidTaxCategory: ${t}`),this.name="InvalidTaxCategoryError";}},G=class extends Error{constructor(t="Minimum quantity must be greater than zero."){super(`InvalidMinQuantity: ${t}`),this.name="InvalidMinQuantityError";}},q=class extends Error{constructor(t){super(`InvalidTieredPrice: ${t}`),this.name="InvalidTieredPriceError";}},K=class extends Error{constructor(t="Quantity must be greater than zero."){super(`InvalidQuantity: ${t}`),this.name="InvalidQuantityError";}},V=class extends Error{constructor(t){super(`NoApplicableTier: Quantity ${t} does not meet the minimum purchase requirement.`),this.name="NoApplicableTierError";}},Q=class extends Error{constructor(t="No applicable tax slab or multiple slabs found for the given unit price."){super(`TaxSlabNotFound: ${t}`),this.name="TaxSlabNotFoundError";}},w=class extends Error{constructor(t="Amount cannot be negative."){super(`InvalidAmount: ${t}`),this.name="InvalidPriceAmountError";}},T=class extends Error{constructor(t="Currency code is required."){super(`InvalidCurrency: ${t}`),this.name="InvalidCurrencyCodeError";}},f=class extends Error{constructor(t="Cannot perform operation on prices with different currencies."){super(`CurrencyMismatch: ${t}`),this.name="CurrencyMismatchError";}},h=class extends Error{constructor(t){super(`InvalidArgument: ${t}`),this.name="InvalidArgumentError";}},M=class extends Error{constructor(t="Invalid image source configuration."){super(`InvalidImageSource: ${t}`),this.name="InvalidImageSourceError";}};var b=class{sources;alt;order;label;constructor(t){if(this.sources={...t.sources},this.alt=t.alt,this.order=t.order,this.label=t.label,!this.sources.original)throw new M("ImageInfoModel cannot be created without an 'original' source URL.")}getSources(){return {...this.sources}}getSource(t){return this.sources[t]||this.sources.original}getAlt(){return this.alt}getOrder(){return this.order}getLabel(){return this.label}setAlt(t){this.alt=t;}setOrder(t){this.order=t;}setLabel(t){this.label=t;}setSource(t,e){if(e===void 0){if(t==="original")throw new M("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 m=class i{#t;amount;currency;constructor(t){if(this.#t="PriceModel",t.amount<0)throw new w("Amount cannot be negative.");if(!t.currency)throw new T("Currency code is required.");this.amount=t.amount,this.currency=t.currency;}get kind(){return this.#t}static isPriceModel(t){return typeof t=="object"&&t!==null&&t.kind==="PriceModel"}getCurrency(){return this.currency}getAmount(){return this.amount}getDetails(){return {amount:this.amount,currency:this.currency}}compareTo(t){if(i.isPriceModel(t)){if(this.currency!==t.getCurrency())throw new f("Cannot compare prices in different currencies.")}else throw new h("Must be a PriceModel instance.");return this.amount-t.getAmount()}add(t){if(i.isPriceModel(t)){if(this.currency!==t.getCurrency())throw new f("Cannot add prices in different currencies.")}else throw new h("Must be a PriceModel instance.");return new i({amount:this.amount+t.getAmount(),currency:this.currency})}subtract(t){if(i.isPriceModel(t)){if(this.currency!==t.getCurrency())throw new f("Cannot subtract prices in different currencies.")}else throw new h("Must be a PriceModel instance.");return new i({amount:this.amount-t.getAmount(),currency:this.currency})}multiply(t){if(i.isPriceModel(t)){if(this.currency!==t.getCurrency())throw new f("Cannot multiply prices in different currencies.");return new i({amount:this.amount*t.getAmount(),currency:this.currency})}else if(typeof t=="number"&&t>=0)return new i({amount:this.amount*t,currency:this.currency});throw new h("Must be a non-negative number.")}divide(t){if(i.isPriceModel(t)){if(this.currency!==t.getCurrency())throw new f("Cannot divide prices in different currencies.");return new i({amount:this.amount/t.getAmount(),currency:this.currency})}else if(typeof t=="number"&&t>0)return new i({amount:this.amount/t,currency:this.currency});throw new h("Must be a positive number.")}min(...t){if(t.length===0)throw new h("Must provide at least one PriceModel.");return t.reduce((e,r)=>{if(i.isPriceModel(r)){if(e.getCurrency()!==r.getCurrency())throw new f("Cannot compare prices in different currencies.")}else throw new h("Must be a PriceModel instance.");return e.compareTo(r)<0?e:r})}max(...t){if(t.length===0)throw new h("Must provide at least one PriceModel.");return t.reduce((e,r)=>{if(i.isPriceModel(r)){if(e.getCurrency()!==r.getCurrency())throw new f("Cannot compare prices in different currencies.")}else throw new h("Must be a PriceModel instance.");return e.compareTo(r)>0?e:r})}zero(){return new i({currency:this.currency,amount:0})}isZero(){return this.amount===0}round(){return new i({currency:this.currency,amount:this.getRoundedAmount()})}getRoundedAmount(){return i.getRoundedAmount(this.amount,this.currency)}getFormattedString(){return i.getFormattedString(this.amount,this.currency)}toString(){return this.getFormattedString()}static getFormattedString(t,e,r={displayAsInteger:!1,style:"currency",currencyDisplay:"symbol"}){let n=at[e];if(!e||!n)throw new T("Invalid currency code for formatting.");let o=t,a=r.displayAsInteger?0:i.getDecimalPlaces(e),c={style:r.style??"currency",currency:e,signDisplay:"never",currencyDisplay:r.currencyDisplay,minimumFractionDigits:a,maximumFractionDigits:a};r.displayAsInteger&&(o=Math.ceil(o));try{return new Intl.NumberFormat(n,c).format(o)}catch(u){return console.error(`Error formatting price for currency "${e}" and locale "${n}":`,u),`${ot[e]??e} ${i.addThousandSeparators(o.toFixed(a))}`}}static getDecimalPlaces(t){switch(t){case"INR":default:return 2}}static addThousandSeparators(t){let e=t.split("."),r=e[0],n=e.length>1?"."+e[1]:"";return r.replace(/\B(?=(\d{3})+(?!\d))/g,",")+n}static getRoundedAmount(t,e){if(t<0)throw new w("Amount cannot be negative for rounding.");if(e===void 0)throw new T("Invalid currency code for rounding.");let r=i.getDecimalPlaces(e),n=Math.pow(10,r);return Math.round(t*n)/n}};var C=class{baseUnitPrice;taxCategory;tiers;constructor(t){let e=new m(t.baseUnitPrice);if(!t.taxCategory)throw new k;let r=(t.tiers??[]).map(u=>({minQuantity:u.minQuantity,unitPrice:new m(u.unitPrice)})).sort((u,l)=>u.minQuantity-l.minQuantity);if(r.some(u=>u.minQuantity<=0))throw new G;let o=r.some(u=>u.unitPrice.getCurrency()!==e.getCurrency()),a=r.some((u,l)=>l>0&&u.unitPrice.compareTo(r[l-1].unitPrice)>0),c=r[0]?.unitPrice.compareTo(e)>0;if(o||a||c)throw new q("Tiers must share the same currency and must not increase in unit price.");this.baseUnitPrice=e,this.taxCategory=t.taxCategory,this.tiers=r;}getBaseUnitPrice(){return this.baseUnitPrice}getTaxCategory(){return this.taxCategory}getTiers(){return this.tiers}getDetails(){return {baseUnitPrice:this.baseUnitPrice.getDetails(),taxCategory:this.taxCategory,tiers:this.tiers.map(t=>({minQuantity:t.minQuantity,unitPrice:t.unitPrice.getDetails()}))}}getApplicableTier(t){if(t<=0)throw new K;for(let e=this.tiers.length-1;e>=0;e--)if(t>=this.tiers[e].minQuantity)return this.tiers[e];throw new V(t)}getMinQuantity(){return this.tiers[0]?.minQuantity??1}getMaxDiscountPercent(){if(!this.tiers.length)return 0;let t=this.tiers[this.tiers.length-1].unitPrice.getAmount(),e=this.baseUnitPrice.getAmount();return (e-t)/e*100}};var I=class i extends S{id;key;name;description;slug;brand;pricing;variants;targetGender;attributes;specifications;categories;isActive;searchTags;static productKeyRegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static productSKURegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static generateSelectionAttributesKey(t){if(typeof t!="object")throw new y("Selection attributes must be an object");return Object.keys(t).filter(r=>t[r]!==void 0&&r.toLowerCase()!=="size").sort().map(r=>t[r].name?`${r}:c+${t[r].name}`:`${r}:${t[r]}`).join("|").toLowerCase()}static parseSelectionAttributesKey(t){try{let e={},r=t.split("|");for(let n of r){let[o,a]=n.split(":");a.startsWith("c+")?e[o]={name:a.slice(2)}:e[o]=a;}return e}catch(e){throw new y(e?.message)}}constructor(t,e=new Date){super(t,e),this.id=t.id,this.key=t.key,this.name={...t.name},this.description={...t.description},this.slug={...t.slug},this.brand=t.brand,this.pricing=Object.keys(t.pricing).reduce((n,o)=>(t.pricing[o]&&(n[o]=new C(t.pricing[o])),n),{}),this.targetGender=t.targetGender,this.attributes=s.deepClone(t.attributes),this.specifications=s.deepClone(t.specifications),this.categories=s.deepClone(t.categories);let r=new Set;this.variants=(t.variants||[]).map(n=>{if(!n.selectionAttributes||typeof n.selectionAttributes!="object")throw new y("Selection attributes are required");this.checkSelectionAttributes(n.selectionAttributes);let o=i.generateSelectionAttributesKey(n.selectionAttributes);if(r.has(o))throw new N(o);return r.add(o),{sku:n.sku,selectionAttributes:n.selectionAttributes,images:{primary:new b(n.images.primary),gallery:(n.images.gallery||[]).map(a=>new b(a))}}}),this.isActive=t.isActive,this.searchTags=t.searchTags?s.deepClone(t.searchTags):{en:[]};}getId(){return this.id}getKey(){return this.key}getName(t){return t?this.name[t]??this.name[x[t]]??this.name.en:s.deepClone(this.name)}getDescription(t){return t?this.description[t]??this.description[x[t]]??this.description.en:s.deepClone(this.description)}getSlug(t){return t?this.slug[t]??this.slug[x[t]]??this.slug.en:s.deepClone(this.slug)}getBrand(){return this.brand}getPriceDetails(t){return t?this.pricing[t]??null:this.pricing}getAttributes(){return s.deepClone(this.attributes)}getVariants(){return this.variants.map(t=>({sku:t.sku,selectionAttributes:t.selectionAttributes,images:{primary:t.images.primary,gallery:t.images.gallery}}))}getImagesBySelectionAttributes(t){let e=i.generateSelectionAttributesKey(t),r=this.variants.find(n=>i.generateSelectionAttributesKey(n.selectionAttributes)===e);return r?r.images:null}getImages(t,e){switch(e){case"PRIMARY":return this.getImagesBySelectionAttributes(t)?.primary??this.variants[0]?.images?.primary;case"GALLERY":return this.getImagesBySelectionAttributes(t)?.gallery??[];default:return this.getImagesBySelectionAttributes(t)??{primary:this.variants[0]?.images?.primary,gallery:[]}}}getIsActive(){return this.isActive}getTargetGender(){return this.targetGender}getCategories(){return s.deepClone(this.categories)}getSpecifications(t){return t?s.deepClone(this.specifications[t]??this.specifications[x[t]]??this.specifications.en):s.deepClone(this.specifications)}getSearchTags(t){return t?s.deepClone(this.searchTags[t]??this.searchTags[x[t]]??this.searchTags.en):s.deepClone(this.searchTags)}getDetails(){let t=super.getDetails();return {id:this.getId(),key:this.getKey(),name:this.getName(),description:this.getDescription(),slug:this.getSlug(),brand:this.getBrand(),pricing:Object.keys(this.pricing).reduce((e,r)=>(this.pricing[r]&&(e[r]=this.pricing[r]?.getDetails()),e),{}),attributes:this.getAttributes(),variants:this.variants.map(e=>({sku:e.sku,selectionAttributes:s.deepClone(e.selectionAttributes),images:{primary:e.images.primary.getDetails(),gallery:e.images.gallery.map(r=>r.getDetails())}})),isActive:this.getIsActive(),targetGender:this.getTargetGender(),categories:this.getCategories(),specifications:this.getSpecifications(),searchTags:this.getSearchTags(),...t}}checkSelectionAttributes(t){if(!t||typeof t!="object")throw new y("Selection attributes are required");Object.keys(this.attributes).forEach(e=>{if(e.toLowerCase()==="size")return;let r=this.attributes[e],n=t[e];if(n===void 0)throw new y(`Selection attribute '${e}' is missing`);if(typeof r=="string"){if(typeof n!="string"||r!==n)throw new y(`Selection attribute '${e}' is invalid`)}else if(Array.isArray(r)){if(r.length>0&&typeof r[0]=="string"){if(typeof n!="string"||!r.includes(n))throw new y(`Selection attribute '${e}' is invalid`)}else if(typeof n!="object"||!("name"in n)||r.findIndex(o=>o.name===n.name)<0)throw new y(`Selection attribute '${e}' is invalid`)}});}validateSelectionAttribute(t){let e=i.generateSelectionAttributesKey(t);return this.variants.some(r=>i.generateSelectionAttributesKey(r.selectionAttributes)===e)}validateSize(t){return this.attributes.size.includes(t)}};var bt={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,t)=>t&&i?W(i,t):X(),generateSearchId:(i,t)=>`${i}#${I.generateSelectionAttributesKey(t)}`,getKeyfromSearchId:i=>{let[t,e]=i.split("#");return {key:t,selectionAttributes:I.parseSelectionAttributesKey(e)}},deepClone(i){return structuredClone(i)}},s=bt;var _=class{getBreakdown(t,e,r){let n=t*100,o=n%1===0?n.toString():n.toFixed(2).replace(/\.?0+$/,"");if(e==="IN"&&r?.merchantState&&r?.customerState)if(r.merchantState.toLowerCase().trim()===r.customerState.toLowerCase().trim()){let a=n/2%1===0?(n/2).toString():(n/2).toFixed(2).replace(/\.?0+$/,"");return {totalRate:t,label:`${a}% CGST + ${a}% SGST`,components:[{rate:t/2,label:`${a}% CGST`,type:"CGST"},{rate:t/2,label:`${a}% SGST`,type:"SGST"}]}}else return {totalRate:t,label:`${o}% IGST`,components:[{rate:t,label:`${o}% IGST`,type:"IGST"}]};return {totalRate:t,label:`${o}% GST`,components:[{rate:t,label:`${o}% GST`,type:"GST"}]}}getLongName(){return "Goods and Services Tax"}},st={GST:new _},j=class i extends S{taxRuleId;taxSystem;taxCategory;country;slabs;effectiveFrom;effectiveTo;constructor(t,e=new Date){super(t,e),this.taxRuleId=t.taxRuleId,this.taxSystem=t.taxSystem,this.taxCategory=t.taxCategory,this.country=t.country,this.slabs=t.slabs.map(r=>({rate:r.rate,minUnitPrice:new m(r.minUnitPrice),maxUnitPrice:r.maxUnitPrice?new m(r.maxUnitPrice):void 0})),this.effectiveFrom=new Date(t.effectiveFrom),this.effectiveTo=t.effectiveTo?new Date(t.effectiveTo):void 0;}getTaxRuleId(){return this.taxRuleId}getTaxSystem(){return this.taxSystem}getTaxCategory(){return this.taxCategory}getCountry(){return this.country}getSlabs(){return this.slabs}getDetails(){return {taxRuleId:this.getTaxRuleId(),taxSystem:this.getTaxSystem(),taxCategory:this.getTaxCategory(),country:this.getCountry(),slabs:this.getSlabs().map(t=>({rate:t.rate,minUnitPrice:t.minUnitPrice.getDetails(),maxUnitPrice:t.maxUnitPrice?t.maxUnitPrice.getDetails():void 0})),effectiveFrom:this.effectiveFrom.toISOString(),effectiveTo:this.effectiveTo?this.effectiveTo.toISOString():void 0,...super.getDetails()}}appliesTo(t,e,r=new Date){return this.taxCategory===t&&this.country===e&&this.effectiveFrom<=r&&(this.effectiveTo?this.effectiveTo>=r:!0)}getApplicableTaxRate(t){return i.getApplicableTaxRate(t,this.slabs)}getTaxRateDisplayString(t,e){let r=this.getApplicableTaxRate(t);return i.getTaxRateDisplayString(r,{taxSystem:this.taxSystem,merchantState:e?.merchantState,customerState:e?.customerState})}getTaxRateBreakdown(t,e){let r=this.getApplicableTaxRate(t),n=st[this.taxSystem];if(n)return n.getBreakdown(r,this.country,e);let o=r*100,c=`${o%1===0?o.toString():o.toFixed(2).replace(/\.?0+$/,"")}% ${this.taxSystem}`;return {totalRate:r,label:c,components:[{rate:r,label:c,type:this.taxSystem}]}}getFormattedTaxRate(t,e={}){let n=this.getApplicableTaxRate(t)*100,o=n%1===0?n.toString():n.toFixed(2).replace(/\.?0+$/,""),a=e.variant||"short",c="";switch(a){case"percentageOnly":c=`${o}%`;break;case"detailed":let u=this.getTaxRateBreakdown(t,e),l=e.separator||(e.multiline?`
|
|
2
|
-
`:" + ");c=u.components.map(A=>A.label).join(l);break;case"long":let g=st[this.taxSystem],P=g?g.getLongName(this.country):this.taxSystem.toString();c=`${o}% ${P}`;break;case"short":default:c=`${o}% ${this.taxSystem}`;break}return e.includeTaxesSuffix&&(c+=" (Incl. Taxes)"),c}static getApplicableTaxRate(t,e){let r=e.filter(n=>(n.minUnitPrice===void 0||t.compareTo(n.minUnitPrice)>=0)&&(n.maxUnitPrice===void 0||t.compareTo(n.maxUnitPrice)<0));if(r.length!==1)throw new Q;return r[0].rate}static getTaxRateDisplayString(t,e){let r=t*100,n=r%1===0?r.toString():r.toFixed(2).replace(/\.?0+$/,"");if(e.taxSystem==="GST"&&e.merchantState&&e.customerState)if(e.merchantState.toLowerCase().trim()===e.customerState.toLowerCase().trim()){let o=r/2%1===0?(r/2).toString():(r/2).toFixed(2).replace(/\.?0+$/,"");return `${o}% CGST + ${o}% SGST`}else return `${n}% IGST`;return e.taxSystem?`${n}% ${e.taxSystem}`:`${n}%`}};var tt=class extends D{id;productKey;selectionAttributes;name;specifications;primaryImage;subItems;pricing;state;total;constructor(t){super(t),this.id=t.id,this.productKey=t.productKey,this.selectionAttributes=s.deepClone(t.selectionAttributes),this.name=s.deepClone(t.name),this.specifications=s.deepClone(t.specifications),this.primaryImage=new b(t.primaryImage),this.subItems=s.deepClone(t.subItems);let e=new Set;this.subItems.forEach(r=>{if(e.has(r.size))throw new U(r.size);e.add(r.size);}),this.pricing={unitPrice:new m(t.pricing.unitPrice),tierPricing:new C(t.pricing.tierPricing),taxCategory:t.pricing.taxCategory,tax:{taxRuleId:t.pricing.tax.taxRuleId,taxSystem:t.pricing.tax.taxSystem,country:t.pricing.tax.country,rate:t.pricing.tax.rate,taxSlabs:t.pricing.tax.taxSlabs.map(r=>({rate:r.rate,minUnitPrice:new m(r.minUnitPrice),maxUnitPrice:r.maxUnitPrice?new m(r.maxUnitPrice):void 0}))}},this.state=t.state??"INITIAL",this.total={quantity:t.total.quantity,subtotal:new m(t.total.subtotal),discounts:Object.fromEntries(Object.entries(t.total.discounts).map(([r,n])=>[r,new m(n)])),taxableAmount:new m(t.total.taxableAmount),taxTotal:new m(t.total.taxTotal),grandTotal:new m(t.total.grandTotal)};}getId(){return this.id}getProductKey(){return this.productKey}getSelectionAttributes(){return s.deepClone(this.selectionAttributes)}getName(t){return t?s.deepClone(this.name[t]??this.name[x[t]]??this.name.en):s.deepClone(this.name)}getSpecifications(t){return t?s.deepClone(this.specifications[t]??this.specifications[x[t]]??this.specifications.en):s.deepClone(this.specifications)}getImage(){return this.primaryImage}getSubItems(){return s.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: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(([t,e])=>[t,e])),grandTotal:this.total.grandTotal}}getDetails(){return {id:this.getId(),productKey:this.getProductKey(),selectionAttributes:this.getSelectionAttributes(),name:this.getName(),specifications:this.getSpecifications(),primaryImage:this.getImage().getDetails(),subItems:this.getSubItems(),pricing:{unitPrice:this.getPricing().unitPrice.getDetails(),tierPricing:this.getPricing().tierPricing.getDetails(),taxCategory:this.getPricing().taxCategory,tax:{taxRuleId:this.getPricing().tax.taxRuleId,taxSystem:this.getPricing().tax.taxSystem,country:this.getPricing().tax.country,rate:this.getPricing().tax.rate,taxSlabs:this.getPricing().tax.taxSlabs.map(t=>({rate:t.rate,minUnitPrice:t.minUnitPrice.getDetails(),maxUnitPrice:t.maxUnitPrice?t.maxUnitPrice.getDetails():void 0}))}},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(([t,e])=>[t,e.getDetails()])),grandTotal:this.getTotal().grandTotal.getDetails()},customFields:this.getAllCustomFields()}}addSubItems(t,e){t.forEach(r=>{let n=this.subItems.find(o=>o.size===r.size);n?n.quantity=e?n.quantity+r.quantity:r.quantity:this.subItems.push(r);}),this.subItems=this.subItems.filter(r=>r.quantity>0),this.calculateTotals();}updateProductData(t,e,r){if(this.productKey!==t.getKey()||!t.validateSelectionAttribute(this.selectionAttributes))throw new F;if(!t.getIsActive())throw new $;this.subItems.forEach(c=>{if(!t.validateSize(c.size))throw new z});let n=t.getPriceDetails(e);if(!n||n.getBaseUnitPrice().getCurrency()!==r)throw new O;this.name=t.getName(),this.specifications=t.getSpecifications(),this.primaryImage=t.getImages(this.selectionAttributes).primary;let o=this.subItems.reduce((c,u)=>c+u.quantity,0),{unitPrice:a}=n.getApplicableTier(o);this.pricing={unitPrice:a,tierPricing:n,taxCategory:n.getTaxCategory(),tax:this.pricing.tax},this.calculateTotals();}updateDiscounts(t){let e={};t.forEach(r=>{e[r.coupon.getCode()]=r.amount;}),this.total.discounts=e,this.calculateTotals();}updateTax(t){if(!t.appliesTo(this.pricing.taxCategory,this.pricing.tax.country))throw new B;let e=this.total.quantity>0?this.total.taxableAmount.divide(this.total.quantity):this.total.taxableAmount.zero();this.pricing.tax={taxRuleId:t.getTaxRuleId(),taxSystem:t.getTaxSystem(),country:t.getCountry(),rate:t.getApplicableTaxRate(e),taxSlabs:t.getSlabs()},this.calculateTotals();}calculateTotals(){let t=this.pricing.unitPrice.zero(),e=this.subItems.reduce((P,A)=>P+A.quantity,0);if(this.state==="CANCELLED"){this.total={quantity:0,subtotal:t,taxableAmount:t,taxTotal:t,discounts:{},grandTotal:t};return}let{unitPrice:r}=this.pricing.tierPricing.getApplicableTier(e),n=r.multiply(e),o=Object.values(this.total.discounts).reduce((P,A)=>P.add(A),t),a=n.subtract(o),c=e>0?a.divide(e):t,u=j.getApplicableTaxRate(c,this.pricing.tax.taxSlabs),l=a.multiply(u).round(),g=n.subtract(o).add(l);this.total={quantity:e,subtotal:n,taxableAmount:a,taxTotal:l,discounts:this.total.discounts,grandTotal:g};}updateState(t){if(this.state in J)this.state!==t&&(this.state=t);else throw new E(t)}clearLineItem(){let t=this.pricing.unitPrice.zero();this.id="",this.productKey="",this.selectionAttributes={color:{name:""}},this.name={en:""},this.primaryImage=new b({sources:{original:""}}),this.subItems=[],this.pricing={unitPrice:t,tierPricing:this.pricing.tierPricing,taxCategory:this.pricing.taxCategory,tax:this.pricing.tax},this.total={quantity:0,subtotal:t,taxableAmount:t,taxTotal:t,discounts:{},grandTotal:t};}};module.exports=tt;//# sourceMappingURL=LineItem.js.map
|
|
1
|
+
'use strict';var ce=require('crypto');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var ce__default=/*#__PURE__*/_interopDefault(ce);var U=new Uint8Array(256),v=U.length;function H(){return v>U.length-16&&(ce__default.default.randomFillSync(U),v=0),U.slice(v,v+=16)}var ie=/^(?:[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 ue(i){return typeof i=="string"&&ie.test(i)}var re=ue;var m=[];for(let i=0;i<256;++i)m.push((i+256).toString(16).slice(1));function L(i,e=0){return m[i[e+0]]+m[i[e+1]]+m[i[e+2]]+m[i[e+3]]+"-"+m[i[e+4]]+m[i[e+5]]+"-"+m[i[e+6]]+m[i[e+7]]+"-"+m[i[e+8]]+m[i[e+9]]+"-"+m[i[e+10]]+m[i[e+11]]+m[i[e+12]]+m[i[e+13]]+m[i[e+14]]+m[i[e+15]]}function le(i){if(!re(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 ne=le;function de(i){i=unescape(encodeURIComponent(i));let e=[];for(let t=0;t<i.length;++t)e.push(i.charCodeAt(t));return e}var ge="6ba7b810-9dad-11d1-80b4-00c04fd430c8",me="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function Y(i,e,t){function r(n,o,c,p){var u;if(typeof n=="string"&&(n=de(n)),typeof o=="string"&&(o=ne(o)),((u=o)===null||u===void 0?void 0:u.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(o),l.set(n,o.length),l=t(l),l[6]=l[6]&15|e,l[8]=l[8]&63|128,c){p=p||0;for(let g=0;g<16;++g)c[p+g]=l[g];return c}return L(l)}try{r.name=i;}catch{}return r.DNS=ge,r.URL=me,r}var Z={randomUUID:ce__default.default.randomUUID};function he(i,e,t){if(Z.randomUUID&&!e&&!i)return Z.randomUUID();i=i||{};let r=i.random||(i.rng||H)();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 L(r)}var J=he;function fe(i){return Array.isArray(i)?i=Buffer.from(i):typeof i=="string"&&(i=Buffer.from(i,"utf8")),ce__default.default.createHash("sha1").update(i).digest()}var oe=fe;var be=Y("v5",80,oe),X=be;var A=class{customFields;constructor(e,t=new Date){this.customFields={...e.customFields};}getCustomField(e){return this.customFields[e]??null}setCustomField(e,t){this.customFields[e]=t;}getAllCustomFields(){return {...this.customFields}}},D=class extends A{version;createdAt;modifiedAt;modifiedBy;constructor(e,t=new Date){super(e),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,r,n){this.modifiedBy={id:e,authType:t,requestId:r,lambdaName:n};}};var x={"en-IN":"en","kn-IN":"kn"};var se={INR:"\u20B9"},ae={INR:"en-IN"};var W=(g=>(g.INITIAL="INITIAL",g.PROCESSING="PROCESSING",g.SHIPPED="SHIPPED",g.DELIVERED="DELIVERED",g.CANCELLED="CANCELLED",g.RETURN_REQUESTED="RETURN_REQUESTED",g.RETURNED="RETURNED",g.REFUND_INITIATED="REFUND_INITIATED",g.REFUNDED="REFUNDED",g.ON_HOLD="ON_HOLD",g))(W||{});var E=class extends Error{constructor(e){super(`Invalid line item state: ${e}`),this.name="InvalidLineItemStateError";}},R=class extends Error{constructor(e){super(`Duplicate size found: ${e}`),this.name="DuplicateSizeError";}},N=class extends Error{constructor(e){super(`Duplicate selection attribute found: ${e}`),this.name="DuplicateSelectionAttributeError";}},F=class extends Error{constructor(e="Product and selection attributes do not match."){super(`ProductMismatch: ${e}`),this.name="ProductMismatchError";}},O=class extends Error{constructor(e="Product is not active."){super(`ProductInactive: ${e}`),this.name="ProductInactiveError";}},y=class extends Error{constructor(e="Failed to parse selection attributes key."){super(`SelectionAttributeParseError: ${e}`),this.name="SelectionAttributeParseError";}},z=class extends Error{constructor(e="Size does not match."){super(`SizeMismatch: ${e}`),this.name="SizeMismatchError";}},$=class extends Error{constructor(e="Pricing details not available for the product"){super(`NotFound: ${e}`),this.name="PricingNotFoundError";}},B=class extends Error{constructor(e="Tax rule category mismatch."){super(`InvalidTaxRule: ${e}`),this.name="InvalidTaxRuleError";}},k=class extends Error{constructor(e="Tax category is not valid."){super(`InvalidTaxCategory: ${e}`),this.name="InvalidTaxCategoryError";}},q=class extends Error{constructor(e="Minimum quantity must be greater than zero."){super(`InvalidMinQuantity: ${e}`),this.name="InvalidMinQuantityError";}},K=class extends Error{constructor(e){super(`InvalidTieredPrice: ${e}`),this.name="InvalidTieredPriceError";}},V=class extends Error{constructor(e="Quantity must be greater than zero."){super(`InvalidQuantity: ${e}`),this.name="InvalidQuantityError";}},Q=class extends Error{constructor(e){super(`NoApplicableTier: Quantity ${e} does not meet the minimum purchase requirement.`),this.name="NoApplicableTierError";}},G=class extends Error{constructor(e="No applicable tax slab or multiple slabs found for the given unit price."){super(`TaxSlabNotFound: ${e}`),this.name="TaxSlabNotFoundError";}},w=class extends Error{constructor(e="Amount cannot be negative."){super(`InvalidAmount: ${e}`),this.name="InvalidPriceAmountError";}},S=class extends Error{constructor(e="Currency code is required."){super(`InvalidCurrency: ${e}`),this.name="InvalidCurrencyCodeError";}},f=class extends Error{constructor(e="Cannot perform operation on prices with different currencies."){super(`CurrencyMismatch: ${e}`),this.name="CurrencyMismatchError";}},h=class extends Error{constructor(e){super(`InvalidArgument: ${e}`),this.name="InvalidArgumentError";}},M=class extends Error{constructor(e="Invalid image source configuration."){super(`InvalidImageSource: ${e}`),this.name="InvalidImageSourceError";}};var P=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 M("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 M("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 a=class i{#e;amount;currency;constructor(e){if(this.#e="PriceModel",e.amount<0)throw new w("Amount cannot be negative.");if(!e.currency)throw new S("Currency code is required.");this.amount=e.amount,this.currency=e.currency;}get kind(){return this.#e}static isPriceModel(e){return typeof e=="object"&&e!==null&&e.kind==="PriceModel"}getCurrency(){return this.currency}getAmount(){return this.amount}getDetails(){return {amount:this.amount,currency:this.currency}}compareTo(e){if(i.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new f("Cannot compare prices in different currencies.")}else throw new h("Must be a PriceModel instance.");return this.amount-e.getAmount()}add(e){if(i.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new f("Cannot add prices in different currencies.")}else throw new h("Must be a PriceModel instance.");return new i({amount:this.amount+e.getAmount(),currency:this.currency})}subtract(e){if(i.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new f("Cannot subtract prices in different currencies.")}else throw new h("Must be a PriceModel instance.");return new i({amount:this.amount-e.getAmount(),currency:this.currency})}multiply(e){if(i.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new f("Cannot multiply prices in different currencies.");return new i({amount:this.amount*e.getAmount(),currency:this.currency})}else if(typeof e=="number"&&e>=0)return new i({amount:this.amount*e,currency:this.currency});throw new h("Must be a non-negative number.")}divide(e){if(i.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new f("Cannot divide prices in different currencies.");return new i({amount:this.amount/e.getAmount(),currency:this.currency})}else if(typeof e=="number"&&e>0)return new i({amount:this.amount/e,currency:this.currency});throw new h("Must be a positive number.")}min(...e){if(e.length===0)throw new h("Must provide at least one PriceModel.");return e.reduce((t,r)=>{if(i.isPriceModel(r)){if(t.getCurrency()!==r.getCurrency())throw new f("Cannot compare prices in different currencies.")}else throw new h("Must be a PriceModel instance.");return t.compareTo(r)<0?t:r},this)}max(...e){if(e.length===0)throw new h("Must provide at least one PriceModel.");return e.reduce((t,r)=>{if(i.isPriceModel(r)){if(t.getCurrency()!==r.getCurrency())throw new f("Cannot compare prices in different currencies.")}else throw new h("Must be a PriceModel instance.");return t.compareTo(r)>0?t:r},this)}zero(){return new i({currency:this.currency,amount:0})}isZero(){return this.amount===0}round(){return new i({currency:this.currency,amount:this.getRoundedAmount()})}getRoundedAmount(){return i.getRoundedAmount(this.amount,this.currency)}getFormattedString(){return i.getFormattedString(this.amount,this.currency)}toString(){return this.getFormattedString()}static getFormattedString(e,t,r={displayAsInteger:!1,style:"currency",currencyDisplay:"symbol"}){let n=ae[t];if(!t||!n)throw new S("Invalid currency code for formatting.");let o=e,c=r.displayAsInteger?0:i.getDecimalPlaces(t),p={style:r.style??"currency",currency:t,signDisplay:"never",currencyDisplay:r.currencyDisplay,minimumFractionDigits:c,maximumFractionDigits:c};r.displayAsInteger&&(o=Math.ceil(o));try{return new Intl.NumberFormat(n,p).format(o)}catch(u){return console.error(`Error formatting price for currency "${t}" and locale "${n}":`,u),`${se[t]??t} ${i.addThousandSeparators(o.toFixed(c))}`}}static getDecimalPlaces(e){switch(e){case"INR":default:return 2}}static addThousandSeparators(e){let t=e.split("."),r=t[0],n=t.length>1?"."+t[1]:"";return r.replace(/\B(?=(\d{3})+(?!\d))/g,",")+n}static getRoundedAmount(e,t){if(e<0)throw new w("Amount cannot be negative for rounding.");if(t===void 0)throw new S("Invalid currency code for rounding.");let r=i.getDecimalPlaces(t),n=Math.pow(10,r);return Math.round(e*n)/n}};var I=class{baseUnitPrice;taxCategory;tiers;constructor(e){let t=new a(e.baseUnitPrice);if(!e.taxCategory)throw new k;let r=(e.tiers??[]).map(u=>({minQuantity:u.minQuantity,unitPrice:new a(u.unitPrice)})).sort((u,l)=>u.minQuantity-l.minQuantity);if(r.some(u=>u.minQuantity<=0))throw new q;let o=r.some(u=>u.unitPrice.getCurrency()!==t.getCurrency()),c=r.some((u,l)=>l>0&&u.unitPrice.compareTo(r[l-1].unitPrice)>0),p=r[0]?.unitPrice.compareTo(t)>0;if(o||c||p)throw new K("Tiers must share the same currency and must not increase in unit price.");this.baseUnitPrice=t,this.taxCategory=e.taxCategory,this.tiers=r;}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 V;for(let t=this.tiers.length-1;t>=0;t--)if(e>=this.tiers[t].minQuantity)return this.tiers[t];throw new Q(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 T=class i extends D{id;key;name;description;slug;brand;pricing;variants;targetGender;attributes;specifications;categories;isActive;searchTags;static productKeyRegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static productSKURegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static generateSelectionAttributesKey(e){if(typeof e!="object")throw new y("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[o,c]=n.split(":");c.startsWith("c+")?t[o]={name:c.slice(2)}:t[o]=c;}return t}catch(t){throw new y(t?.message)}}constructor(e,t=new Date){super(e,t),this.id=e.id,this.key=e.key,this.name={...e.name},this.description={...e.description},this.slug={...e.slug},this.brand=e.brand,this.pricing=Object.keys(e.pricing).reduce((n,o)=>(e.pricing[o]&&(n[o]=new I(e.pricing[o])),n),{}),this.targetGender=e.targetGender,this.attributes=s.deepClone(e.attributes),this.specifications=s.deepClone(e.specifications),this.categories=s.deepClone(e.categories);let r=new Set;this.variants=(e.variants||[]).map(n=>{if(!n.selectionAttributes||typeof n.selectionAttributes!="object")throw new y("Selection attributes are required");this.checkSelectionAttributes(n.selectionAttributes);let o=i.generateSelectionAttributesKey(n.selectionAttributes);if(r.has(o))throw new N(o);return r.add(o),{sku:n.sku,selectionAttributes:n.selectionAttributes,images:{primary:new P(n.images.primary),gallery:(n.images.gallery||[]).map(c=>new P(c))}}}),this.isActive=e.isActive,this.searchTags=e.searchTags?s.deepClone(e.searchTags):{en:[]};}getId(){return this.id}getKey(){return this.key}getName(e){return e?this.name[e]??this.name[x[e]]??this.name.en:s.deepClone(this.name)}getDescription(e){return e?this.description[e]??this.description[x[e]]??this.description.en:s.deepClone(this.description)}getSlug(e){return e?this.slug[e]??this.slug[x[e]]??this.slug.en:s.deepClone(this.slug)}getBrand(){return this.brand}getPriceDetails(e){return e?this.pricing[e]??null:this.pricing}getAttributes(){return s.deepClone(this.attributes)}getVariants(){return this.variants.map(e=>({sku:e.sku,selectionAttributes: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?r.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 s.deepClone(this.categories)}getSpecifications(e){return e?s.deepClone(this.specifications[e]??this.specifications[x[e]]??this.specifications.en):s.deepClone(this.specifications)}getSearchTags(e){return e?s.deepClone(this.searchTags[e]??this.searchTags[x[e]]??this.searchTags.en):s.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:s.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(),specifications:this.getSpecifications(),searchTags:this.getSearchTags(),...e}}checkSelectionAttributes(e){if(!e||typeof e!="object")throw new y("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 y(`Selection attribute '${t}' is missing`);if(typeof r=="string"){if(typeof n!="string"||r!==n)throw new y(`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 y(`Selection attribute '${t}' is invalid`)}else if(typeof n!="object"||!("name"in n)||r.findIndex(o=>o.name===n.name)<0)throw new y(`Selection attribute '${t}' is invalid`)}});}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 xe={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?X(i,e):J(),generateSearchId:(i,e)=>`${i}#${T.generateSelectionAttributesKey(e)}`,getKeyfromSearchId:i=>{let[e,t]=i.split("#");return {key:e,selectionAttributes:T.parseSelectionAttributesKey(t)}},deepClone(i){return structuredClone(i)}},s=xe;var j=class i{taxRuleId;taxCategory;taxSystem;taxSubSystem;country;slabs;effectiveFrom;effectiveTo;constructor(e){this.taxRuleId=e.taxRuleId,this.taxSystem=e.taxSystem,this.taxSubSystem=e.taxSubSystem,this.taxCategory=e.taxCategory,this.country=e.country,this.slabs=e.slabs.map(t=>({rate:t.rate,minUnitPrice:new a(t.minUnitPrice),maxUnitPrice:t.maxUnitPrice?new a(t.maxUnitPrice):void 0})),this.effectiveFrom=new Date(e.effectiveFrom),this.effectiveTo=e.effectiveTo?new Date(e.effectiveTo):void 0;}getTaxRuleId(){return this.taxRuleId}getTaxSystem(){return this.taxSystem}getTaxSubSystem(){return this.taxSubSystem}getTaxCategory(){return this.taxCategory}getCountry(){return this.country}getSlabs(){return this.slabs}getDetails(){return {taxRuleId:this.getTaxRuleId(),taxSystem:this.getTaxSystem(),taxSubSystem:this.getTaxSubSystem(),taxCategory:this.getTaxCategory(),country:this.getCountry(),slabs:this.getSlabs().map(e=>({rate:e.rate,minUnitPrice:e.minUnitPrice.getDetails(),maxUnitPrice:e.maxUnitPrice?e.maxUnitPrice.getDetails():void 0})),effectiveFrom:this.effectiveFrom.toISOString(),effectiveTo:this.effectiveTo?this.effectiveTo.toISOString():void 0}}appliesTo(e,t,r=new Date){return this.taxCategory===e&&this.country===t&&this.effectiveFrom<=r&&(this.effectiveTo?this.effectiveTo>=r:!0)}getApplicableTaxRate(e){return i.getApplicableTaxRate(e,this.slabs)}calculateTax(e){let t=this.getApplicableTaxRate(e);return e.multiply(t).round()}static getApplicableTaxRate(e,t){let r=t.filter(n=>(n.minUnitPrice===void 0||e.compareTo(n.minUnitPrice)>=0)&&(n.maxUnitPrice===void 0||e.compareTo(n.maxUnitPrice)<0));if(r.length!==1)throw new G;return r[0].rate}static getTaxRateDisplayString(e,t,r){let n=t*100,o=n%1===0?n.toString():n.toFixed(2).replace(/\.?0+$/,"");return r.percentageOnly?`${o}%`:e.getTaxSystem()==="GST"?`${o}% ${e.getTaxSubSystem()}`:`${o}% ${e.getTaxSystem()}`}};var _=class extends A{id;productKey;selectionAttributes;name;specifications;primaryImage;subItems;pricing;state;total;constructor(e){super(e),this.id=e.id,this.productKey=e.productKey,this.selectionAttributes=s.deepClone(e.selectionAttributes),this.name=s.deepClone(e.name),this.specifications=s.deepClone(e.specifications),this.primaryImage=new P(e.primaryImage),this.subItems=s.deepClone(e.subItems);let t=new Set;this.subItems.forEach(r=>{if(t.has(r.size))throw new R(r.size);t.add(r.size);}),this.pricing={unitPrice:new a(e.pricing.unitPrice),tierPricing:new I(e.pricing.tierPricing),taxCategory:e.pricing.taxCategory,applicableTaxRule:e.pricing.applicableTaxRule.map(r=>new j(r))},this.state=e.state??"INITIAL",this.total={quantity:e.total.quantity,unitPrice:new a(e.total.unitPrice),subtotal:new a(e.total.subtotal),discounts:Object.fromEntries(Object.entries(e.total.discounts).map(([r,n])=>[r,new a(n)])),totalDiscount:new a(e.total.totalDiscount),netUnitPrice:new a(e.total.netUnitPrice),netSubtotal:new a(e.total.netSubtotal),taxBreakdown:Object.fromEntries(Object.entries(e.total.taxBreakdown).map(([r,n])=>[r,{rate:n.rate,taxableUnitPrice:new a(n.taxableUnitPrice),taxPerUnit:new a(n.taxPerUnit),amount:new a(n.amount),system:n.system,subSystem:n.subSystem}])),taxTotal:new a(e.total.taxTotal),grandTotal:new a(e.total.grandTotal)};}getId(){return this.id}getProductKey(){return this.productKey}getSelectionAttributes(){return s.deepClone(this.selectionAttributes)}getName(e){return e?s.deepClone(this.name[e]??this.name[x[e]]??this.name.en):s.deepClone(this.name)}getSpecifications(e){return e?s.deepClone(this.specifications[e]??this.specifications[x[e]]??this.specifications.en):s.deepClone(this.specifications)}getImage(){return this.primaryImage}getSubItems(){return s.deepClone(this.subItems)}getTotalQuantity(){return this.total.quantity}getPricing(){return {unitPrice:this.pricing.unitPrice,tierPricing:this.pricing.tierPricing,taxCategory:this.pricing.taxCategory,applicableTaxRule:this.pricing.applicableTaxRule}}getState(){return this.state}getTotal(){return {quantity:this.total.quantity,unitPrice:this.total.unitPrice,subtotal:this.total.subtotal,discounts:Object.fromEntries(Object.entries(this.total.discounts).map(([e,t])=>[e,t])),totalDiscount:this.total.totalDiscount,netUnitPrice:this.total.netUnitPrice,netSubtotal:this.total.netSubtotal,taxBreakdown:this.total.taxBreakdown,taxTotal:this.total.taxTotal,grandTotal:this.total.grandTotal}}getDetails(){let e=this.getPricing(),t=this.getTotal();return {id:this.getId(),productKey:this.getProductKey(),selectionAttributes:this.getSelectionAttributes(),name:this.getName(),specifications:this.getSpecifications(),primaryImage:this.getImage().getDetails(),subItems:this.getSubItems(),pricing:{unitPrice:e.unitPrice.getDetails(),tierPricing:e.tierPricing.getDetails(),taxCategory:e.taxCategory,applicableTaxRule:e.applicableTaxRule.map(r=>r.getDetails())},state:this.getState(),total:{quantity:t.quantity,unitPrice:t.unitPrice.getDetails(),subtotal:t.subtotal.getDetails(),discounts:Object.fromEntries(Object.entries(t.discounts).map(([r,n])=>[r,n.getDetails()])),totalDiscount:t.totalDiscount.getDetails(),netUnitPrice:t.netUnitPrice.getDetails(),netSubtotal:t.netSubtotal.getDetails(),taxBreakdown:Object.fromEntries(Object.entries(t.taxBreakdown).map(([r,n])=>[r,{rate:n.rate,taxableUnitPrice:n.taxableUnitPrice.getDetails(),taxPerUnit:n.taxPerUnit.getDetails(),amount:n.amount.getDetails(),system:n.system,subSystem:n.subSystem}])),taxTotal:t.taxTotal.getDetails(),grandTotal:t.grandTotal.getDetails()},customFields:this.getAllCustomFields()}}addSubItems(e,t){e.forEach(r=>{let n=this.subItems.find(o=>o.size===r.size);n?n.quantity=t?n.quantity+r.quantity:r.quantity:this.subItems.push(r);}),this.subItems=this.subItems.filter(r=>r.quantity>0),this.calculateTotals();}updateProductData(e,t,r){if(this.productKey!==e.getKey()||!e.validateSelectionAttribute(this.selectionAttributes))throw new F;if(!e.getIsActive())throw new O;this.subItems.forEach(p=>{if(!e.validateSize(p.size))throw new z});let n=e.getPriceDetails(t);if(!n||n.getBaseUnitPrice().getCurrency()!==r)throw new $;this.name=e.getName(),this.specifications=e.getSpecifications(),this.primaryImage=e.getImages(this.selectionAttributes).primary;let o=this.subItems.reduce((p,u)=>p+u.quantity,0),{unitPrice:c}=n.getApplicableTier(o);this.pricing={unitPrice:c,tierPricing:n,taxCategory:n.getTaxCategory(),applicableTaxRule:this.pricing.applicableTaxRule},this.calculateTotals();}updateDiscounts(e){let t={};e.forEach(r=>{t[r.coupon.getCode()]=r.amount;}),this.total.discounts=t,this.calculateTotals();}updateTax(e){e.forEach(t=>{if(!t.appliesTo(this.pricing.taxCategory,t.getCountry()))throw new B}),this.pricing.applicableTaxRule=e,this.calculateTotals();}calculateTotals(){let e=this.pricing.unitPrice.zero(),t=this.subItems.reduce((b,C)=>b+C.quantity,0);if(this.state==="CANCELLED"){this.total={quantity:0,unitPrice:e,subtotal:e,discounts:{},totalDiscount:e,netUnitPrice:e,netSubtotal:e,taxBreakdown:{},taxTotal:e,grandTotal:e};return}let{unitPrice:r}=this.pricing.tierPricing.getApplicableTier(t),n=r.multiply(t),o=Object.values(this.total.discounts).reduce((b,C)=>b.add(C),e),c=n.subtract(o),p=t>0?c.divide(t):e,u={},l=e;this.pricing.applicableTaxRule.forEach(b=>{let C=b.getApplicableTaxRate(p),ee=b.calculateTax(p),te=ee.multiply(t);u[b.getTaxRuleId()]={rate:C,taxableUnitPrice:p,taxPerUnit:ee,amount:te,system:b.getTaxSystem(),subSystem:b.getTaxSubSystem()},l=l.add(te);});let g=c.add(l);this.total={quantity:t,unitPrice:r,subtotal:n,discounts:this.total.discounts,totalDiscount:o,netUnitPrice:p,netSubtotal:c,taxBreakdown:u,taxTotal:l,grandTotal:g};}updateState(e){if(this.state in W)this.state!==e&&(this.state=e);else throw new E(e)}clearLineItem(){let e=this.pricing.unitPrice.zero();this.id="",this.productKey="",this.selectionAttributes={color:{name:""}},this.name={en:""},this.primaryImage=new P({sources:{original:""}}),this.subItems=[],this.pricing={unitPrice:e,tierPricing:this.pricing.tierPricing,taxCategory:this.pricing.taxCategory,applicableTaxRule:[]},this.total={quantity:0,unitPrice:e,subtotal:e,discounts:{},totalDiscount:e,netUnitPrice:e,netSubtotal:e,taxBreakdown:{},taxTotal:e,grandTotal:e};}};module.exports=_;//# sourceMappingURL=LineItem.js.map
|
|
3
2
|
//# sourceMappingURL=LineItem.js.map
|