b23-lib 1.6.2 → 1.7.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.
- package/dist/Auth/index.cjs +2 -0
- package/dist/Auth/index.cjs.map +1 -0
- package/dist/Auth/index.d.cts +130 -0
- package/dist/Auth/index.d.ts +130 -0
- package/dist/Auth/index.js +2 -0
- package/dist/Auth/index.js.map +1 -0
- package/dist/Classes/Address.cjs +2 -0
- package/dist/Classes/Address.cjs.map +1 -0
- package/dist/Classes/Address.d.cts +142 -0
- package/dist/Classes/Address.d.ts +142 -0
- package/dist/Classes/Address.js +2 -0
- package/dist/Classes/Address.js.map +1 -0
- package/dist/Classes/Base.cjs +2 -0
- package/dist/Classes/Base.cjs.map +1 -0
- package/dist/Classes/Base.d.cts +98 -0
- package/dist/Classes/Base.d.ts +98 -0
- package/dist/Classes/Base.js +2 -0
- package/dist/Classes/Base.js.map +1 -0
- package/dist/Classes/Cart.cjs +2 -0
- package/dist/Classes/Cart.cjs.map +1 -0
- package/dist/Classes/Cart.d.cts +68 -0
- package/dist/Classes/Cart.d.ts +68 -0
- package/dist/Classes/Cart.js +2 -0
- package/dist/Classes/Cart.js.map +1 -0
- package/dist/Classes/Common.cjs +2 -0
- package/dist/Classes/Common.cjs.map +1 -0
- package/dist/Classes/Common.d.cts +75 -0
- package/dist/Classes/Common.d.ts +75 -0
- package/dist/Classes/Common.js +2 -0
- package/dist/Classes/Common.js.map +1 -0
- package/dist/Classes/Coupon.cjs +2 -0
- package/dist/Classes/Coupon.cjs.map +1 -0
- package/dist/Classes/Coupon.d.cts +142 -0
- package/dist/Classes/Coupon.d.ts +142 -0
- package/dist/Classes/Coupon.js +2 -0
- package/dist/Classes/Coupon.js.map +1 -0
- package/dist/Classes/Customer.cjs +2 -0
- package/dist/Classes/Customer.cjs.map +1 -0
- package/dist/Classes/Customer.d.cts +97 -0
- package/dist/Classes/Customer.d.ts +97 -0
- package/dist/Classes/Customer.js +2 -0
- package/dist/Classes/Customer.js.map +1 -0
- package/dist/Classes/CustomerAddress.cjs +2 -0
- package/dist/Classes/CustomerAddress.cjs.map +1 -0
- package/dist/Classes/CustomerAddress.d.cts +71 -0
- package/dist/Classes/CustomerAddress.d.ts +71 -0
- package/dist/Classes/CustomerAddress.js +2 -0
- package/dist/Classes/CustomerAddress.js.map +1 -0
- package/dist/Classes/Enum.cjs +2 -0
- package/dist/Classes/Enum.cjs.map +1 -0
- package/dist/Classes/Enum.d.cts +34 -0
- package/dist/Classes/Enum.d.ts +34 -0
- package/dist/Classes/Enum.js +2 -0
- package/dist/Classes/Enum.js.map +1 -0
- package/dist/Classes/ImageInfo.cjs +2 -0
- package/dist/Classes/ImageInfo.cjs.map +1 -0
- package/dist/Classes/ImageInfo.d.cts +92 -0
- package/dist/Classes/ImageInfo.d.ts +92 -0
- package/dist/Classes/ImageInfo.js +2 -0
- package/dist/Classes/ImageInfo.js.map +1 -0
- package/dist/Classes/LineItem.cjs +2 -0
- package/dist/Classes/LineItem.cjs.map +1 -0
- package/dist/Classes/LineItem.d.cts +124 -0
- package/dist/Classes/LineItem.d.ts +124 -0
- package/dist/Classes/LineItem.js +2 -0
- package/dist/Classes/LineItem.js.map +1 -0
- package/dist/Classes/Order.cjs +2 -0
- package/dist/Classes/Order.cjs.map +1 -0
- package/dist/Classes/Order.d.cts +83 -0
- package/dist/Classes/Order.d.ts +83 -0
- package/dist/Classes/Order.js +2 -0
- package/dist/Classes/Order.js.map +1 -0
- package/dist/Classes/Payment.cjs +2 -0
- package/dist/Classes/Payment.cjs.map +1 -0
- package/dist/Classes/Payment.d.cts +161 -0
- package/dist/Classes/Payment.d.ts +161 -0
- package/dist/Classes/Payment.js +2 -0
- package/dist/Classes/Payment.js.map +1 -0
- package/dist/Classes/Price.cjs +2 -0
- package/dist/Classes/Price.cjs.map +1 -0
- package/dist/Classes/Price.d.cts +70 -0
- package/dist/Classes/Price.d.ts +70 -0
- package/dist/Classes/Price.js +2 -0
- package/dist/Classes/Price.js.map +1 -0
- package/dist/Classes/Product.cjs +2 -0
- package/dist/Classes/Product.cjs.map +1 -0
- package/dist/Classes/Product.d.cts +209 -0
- package/dist/Classes/Product.d.ts +209 -0
- package/dist/Classes/Product.js +2 -0
- package/dist/Classes/Product.js.map +1 -0
- package/dist/Classes/ShoppingContainer.cjs +2 -0
- package/dist/Classes/ShoppingContainer.cjs.map +1 -0
- package/dist/Classes/ShoppingContainer.d.cts +194 -0
- package/dist/Classes/ShoppingContainer.d.ts +194 -0
- package/dist/Classes/ShoppingContainer.js +2 -0
- package/dist/Classes/ShoppingContainer.js.map +1 -0
- package/dist/Dynamodb/index.cjs +2 -0
- package/dist/Dynamodb/index.cjs.map +1 -0
- package/dist/Dynamodb/index.d.cts +58 -0
- package/dist/Dynamodb/index.d.ts +58 -0
- package/dist/Dynamodb/index.js +2 -0
- package/dist/Dynamodb/index.js.map +1 -0
- package/dist/chunk-2ESSIPYR.js +2 -0
- package/dist/chunk-2ESSIPYR.js.map +1 -0
- package/dist/chunk-2IVRLXCO.js +2 -0
- package/dist/chunk-2IVRLXCO.js.map +1 -0
- package/dist/chunk-42S4IPCA.js +2 -0
- package/dist/chunk-42S4IPCA.js.map +1 -0
- package/dist/chunk-7UEGCYYY.js +2 -0
- package/dist/chunk-7UEGCYYY.js.map +1 -0
- package/dist/chunk-IYDPJQAK.js +2 -0
- package/dist/chunk-IYDPJQAK.js.map +1 -0
- package/dist/chunk-P5BGQ3PJ.js +2 -0
- package/dist/chunk-P5BGQ3PJ.js.map +1 -0
- package/dist/chunk-PD6TDU7F.js +2 -0
- package/dist/chunk-PD6TDU7F.js.map +1 -0
- package/dist/chunk-Q2WQECY6.js +2 -0
- package/dist/chunk-Q2WQECY6.js.map +1 -0
- package/dist/chunk-XL3K64E6.js +2 -0
- package/dist/chunk-XL3K64E6.js.map +1 -0
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +240 -0
- package/dist/index.d.ts +1 -186
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +164 -1
- package/dist/index.d.mts +0 -425
- package/dist/index.mjs +0 -2
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import BaseModel, { BaseAttributes } from './Base.cjs';
|
|
2
|
+
import { LocalizedString, BasePriceList, PriceTierList, Color, LocaleCode, CountryCode } from './Common.cjs';
|
|
3
|
+
import { GenderCategory } from './Enum.cjs';
|
|
4
|
+
import ImageInfoModel, { ImageInfoData } from './ImageInfo.cjs';
|
|
5
|
+
|
|
6
|
+
type ProductVariantIdentifier = {
|
|
7
|
+
key: string;
|
|
8
|
+
variantId: string;
|
|
9
|
+
};
|
|
10
|
+
type ProductHashKey = {
|
|
11
|
+
id: string;
|
|
12
|
+
variantId: string;
|
|
13
|
+
};
|
|
14
|
+
type ProductAttributes = BaseAttributes & {
|
|
15
|
+
id: string;
|
|
16
|
+
key: string;
|
|
17
|
+
variantId: string;
|
|
18
|
+
name: LocalizedString;
|
|
19
|
+
description: LocalizedString;
|
|
20
|
+
slug: LocalizedString;
|
|
21
|
+
brand: string;
|
|
22
|
+
basePrices: BasePriceList;
|
|
23
|
+
priceTiers: PriceTierList;
|
|
24
|
+
attributes: {
|
|
25
|
+
color: Color;
|
|
26
|
+
sizes: string[];
|
|
27
|
+
};
|
|
28
|
+
primaryImage: ImageInfoData;
|
|
29
|
+
additionalImages?: ImageInfoData[];
|
|
30
|
+
isActive: boolean;
|
|
31
|
+
targetGender: GenderCategory;
|
|
32
|
+
categories: string[];
|
|
33
|
+
specifications: {
|
|
34
|
+
[locale: string]: {
|
|
35
|
+
[key: string]: string | string[];
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
searchTags?: string[];
|
|
39
|
+
};
|
|
40
|
+
type ProductData = Required<ProductAttributes>;
|
|
41
|
+
type ProductSpecification = {
|
|
42
|
+
[key: string]: string | string[];
|
|
43
|
+
};
|
|
44
|
+
type LocalizedProductSpecification = {
|
|
45
|
+
en: ProductSpecification;
|
|
46
|
+
} & {
|
|
47
|
+
[locale in LocaleCode]?: ProductSpecification;
|
|
48
|
+
};
|
|
49
|
+
declare class ProductModel extends BaseModel {
|
|
50
|
+
protected id: string;
|
|
51
|
+
protected key: string;
|
|
52
|
+
protected variantId: string;
|
|
53
|
+
protected name: LocalizedString;
|
|
54
|
+
protected description: LocalizedString;
|
|
55
|
+
protected slug: LocalizedString;
|
|
56
|
+
protected brand: string;
|
|
57
|
+
protected basePrices: BasePriceList;
|
|
58
|
+
protected priceTiers: PriceTierList;
|
|
59
|
+
protected attributes: {
|
|
60
|
+
color: Color;
|
|
61
|
+
sizes: string[];
|
|
62
|
+
};
|
|
63
|
+
protected primaryImage: ImageInfoModel;
|
|
64
|
+
protected additionalImages: ImageInfoModel[];
|
|
65
|
+
protected isActive: boolean;
|
|
66
|
+
protected targetGender: GenderCategory;
|
|
67
|
+
protected categories: string[];
|
|
68
|
+
protected specifications: LocalizedProductSpecification;
|
|
69
|
+
protected searchTags: string[];
|
|
70
|
+
static productKeyRegex: RegExp;
|
|
71
|
+
static variantIdRegex: RegExp;
|
|
72
|
+
/**
|
|
73
|
+
* Creates an instance of ProductModel.
|
|
74
|
+
* Initializes properties based on the provided data, creating copies where necessary.
|
|
75
|
+
* @param data - The initial product attributes.
|
|
76
|
+
* @param date - Optional date for setting creation/modification times (defaults to now).
|
|
77
|
+
*/
|
|
78
|
+
constructor(data: ProductAttributes, date?: Date);
|
|
79
|
+
/**
|
|
80
|
+
* Gets the base Product ID.
|
|
81
|
+
* @returns Product ID.
|
|
82
|
+
*/
|
|
83
|
+
getId(): string;
|
|
84
|
+
/**
|
|
85
|
+
* Gets the user-friendly product key.
|
|
86
|
+
* @returns Product Key.
|
|
87
|
+
*/
|
|
88
|
+
getKey(): string;
|
|
89
|
+
/**
|
|
90
|
+
* Gets the specific Variant ID.
|
|
91
|
+
* @returns Variant ID.
|
|
92
|
+
*/
|
|
93
|
+
getVariantId(): string;
|
|
94
|
+
/**
|
|
95
|
+
* Gets the full localized product name object.
|
|
96
|
+
* @returns A copy of the LocalizedString object for the name.
|
|
97
|
+
*/
|
|
98
|
+
getName(): LocalizedString;
|
|
99
|
+
/**
|
|
100
|
+
* Gets the product name for a specific locale, falling back to English ('en').
|
|
101
|
+
* @param locale - The desired locale code.
|
|
102
|
+
* @returns The name string for the specified locale.
|
|
103
|
+
*/
|
|
104
|
+
getName(locale: LocaleCode): string;
|
|
105
|
+
/**
|
|
106
|
+
* Gets the full localized product description object.
|
|
107
|
+
* @returns A copy of the LocalizedString object for the description.
|
|
108
|
+
*/
|
|
109
|
+
getDescription(): LocalizedString;
|
|
110
|
+
/**
|
|
111
|
+
* Gets the product description for a specific locale, falling back to English ('en').
|
|
112
|
+
* @param locale - The desired locale code.
|
|
113
|
+
* @returns The description string for the specified locale.
|
|
114
|
+
*/
|
|
115
|
+
getDescription(locale: LocaleCode): string;
|
|
116
|
+
/**
|
|
117
|
+
* Gets the full localized product slug object.
|
|
118
|
+
* @returns A copy of the LocalizedString object for the slug.
|
|
119
|
+
*/
|
|
120
|
+
getSlug(): LocalizedString;
|
|
121
|
+
/**
|
|
122
|
+
* Gets the product slug for a specific locale, falling back to English ('en').
|
|
123
|
+
* @param locale - The desired locale code.
|
|
124
|
+
* @returns The slug string for the specified locale.
|
|
125
|
+
*/
|
|
126
|
+
getSlug(locale: LocaleCode): string;
|
|
127
|
+
/**
|
|
128
|
+
* Gets the brand associated with the product.
|
|
129
|
+
* @returns The brand name string.
|
|
130
|
+
*/
|
|
131
|
+
getBrand(): string;
|
|
132
|
+
/**
|
|
133
|
+
* Gets the list of base prices. Returns copies of the price objects.
|
|
134
|
+
* Optionally filters by country.
|
|
135
|
+
* @param country - Optional country code to filter prices for.
|
|
136
|
+
* @returns A list of base prices (or an empty list if none match).
|
|
137
|
+
*/
|
|
138
|
+
getBasePrices(country?: CountryCode): BasePriceList;
|
|
139
|
+
/**
|
|
140
|
+
* Gets the list of quantity-based price tiers. Returns copies of the tier objects.
|
|
141
|
+
* Optionally filters by country.
|
|
142
|
+
* @param country - Optional country code to filter tiers for.
|
|
143
|
+
* @returns A list of price tiers (or an empty list if none match or none exist).
|
|
144
|
+
*/
|
|
145
|
+
getPriceTiers(country?: CountryCode): PriceTierList;
|
|
146
|
+
/**
|
|
147
|
+
* Gets the variant-specific attributes (color, sizes). Returns copies.
|
|
148
|
+
* @returns Product Attributes.
|
|
149
|
+
*/
|
|
150
|
+
getAttributes(): {
|
|
151
|
+
color: Color;
|
|
152
|
+
sizes: string[];
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Gets details of product's primary image.
|
|
156
|
+
* @returns The ImageInfoModel instance for the primary image.
|
|
157
|
+
*/
|
|
158
|
+
getPrimaryImage(): ImageInfoModel;
|
|
159
|
+
/**
|
|
160
|
+
* Gets the list of additional product images.
|
|
161
|
+
* @returns An array of ImageInfoModel instances.
|
|
162
|
+
*/
|
|
163
|
+
getAdditionalImages(): ImageInfoModel[];
|
|
164
|
+
/**
|
|
165
|
+
* Checks if the product variant is active.
|
|
166
|
+
* @returns True if the product is active, false otherwise.
|
|
167
|
+
*/
|
|
168
|
+
getIsActive(): boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Gets the target gender category for the product.
|
|
171
|
+
* @returns The GenderCategory enum value.
|
|
172
|
+
*/
|
|
173
|
+
getTargetGender(): GenderCategory;
|
|
174
|
+
/**
|
|
175
|
+
* Gets the list of categories the product belongs to. Returns a copy.
|
|
176
|
+
* @returns An array of category.
|
|
177
|
+
*/
|
|
178
|
+
getCategories(): string[];
|
|
179
|
+
/**
|
|
180
|
+
* Gets the full localized product specifications object.
|
|
181
|
+
* @returns Product Specifications
|
|
182
|
+
*/
|
|
183
|
+
getSpecifications(): LocalizedProductSpecification;
|
|
184
|
+
/**
|
|
185
|
+
* Gets the product specifications for a specific locale, falling back to English ('en').
|
|
186
|
+
* @param locale - The desired locale code.
|
|
187
|
+
* @returns The ProductSpecification object for the specified locale, or undefined if not found.
|
|
188
|
+
*/
|
|
189
|
+
getSpecifications(locale: LocaleCode): ProductSpecification | undefined;
|
|
190
|
+
/**
|
|
191
|
+
* Gets the list of search tags. Returns a copy.
|
|
192
|
+
* @returns An array of search tags.
|
|
193
|
+
*/
|
|
194
|
+
getSearchTags(): string[];
|
|
195
|
+
/**
|
|
196
|
+
*
|
|
197
|
+
* @returns ProductData
|
|
198
|
+
*/
|
|
199
|
+
getDetails(): ProductData;
|
|
200
|
+
/**
|
|
201
|
+
* Calculates the maximum potential discount percentage for a given country
|
|
202
|
+
* based on the lowest price tier compared to the base price.
|
|
203
|
+
* @param country - The country code to calculate the discount for.
|
|
204
|
+
* @returns The maximum discount percentage (0-100), or 0 if calculation is not possible.
|
|
205
|
+
*/
|
|
206
|
+
getMaxDiscountPercent(country: CountryCode): number;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export { type LocalizedProductSpecification, type ProductAttributes, type ProductData, type ProductHashKey, type ProductSpecification, type ProductVariantIdentifier, ProductModel as default };
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import BaseModel, { BaseAttributes } from './Base.js';
|
|
2
|
+
import { LocalizedString, BasePriceList, PriceTierList, Color, LocaleCode, CountryCode } from './Common.js';
|
|
3
|
+
import { GenderCategory } from './Enum.js';
|
|
4
|
+
import ImageInfoModel, { ImageInfoData } from './ImageInfo.js';
|
|
5
|
+
|
|
6
|
+
type ProductVariantIdentifier = {
|
|
7
|
+
key: string;
|
|
8
|
+
variantId: string;
|
|
9
|
+
};
|
|
10
|
+
type ProductHashKey = {
|
|
11
|
+
id: string;
|
|
12
|
+
variantId: string;
|
|
13
|
+
};
|
|
14
|
+
type ProductAttributes = BaseAttributes & {
|
|
15
|
+
id: string;
|
|
16
|
+
key: string;
|
|
17
|
+
variantId: string;
|
|
18
|
+
name: LocalizedString;
|
|
19
|
+
description: LocalizedString;
|
|
20
|
+
slug: LocalizedString;
|
|
21
|
+
brand: string;
|
|
22
|
+
basePrices: BasePriceList;
|
|
23
|
+
priceTiers: PriceTierList;
|
|
24
|
+
attributes: {
|
|
25
|
+
color: Color;
|
|
26
|
+
sizes: string[];
|
|
27
|
+
};
|
|
28
|
+
primaryImage: ImageInfoData;
|
|
29
|
+
additionalImages?: ImageInfoData[];
|
|
30
|
+
isActive: boolean;
|
|
31
|
+
targetGender: GenderCategory;
|
|
32
|
+
categories: string[];
|
|
33
|
+
specifications: {
|
|
34
|
+
[locale: string]: {
|
|
35
|
+
[key: string]: string | string[];
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
searchTags?: string[];
|
|
39
|
+
};
|
|
40
|
+
type ProductData = Required<ProductAttributes>;
|
|
41
|
+
type ProductSpecification = {
|
|
42
|
+
[key: string]: string | string[];
|
|
43
|
+
};
|
|
44
|
+
type LocalizedProductSpecification = {
|
|
45
|
+
en: ProductSpecification;
|
|
46
|
+
} & {
|
|
47
|
+
[locale in LocaleCode]?: ProductSpecification;
|
|
48
|
+
};
|
|
49
|
+
declare class ProductModel extends BaseModel {
|
|
50
|
+
protected id: string;
|
|
51
|
+
protected key: string;
|
|
52
|
+
protected variantId: string;
|
|
53
|
+
protected name: LocalizedString;
|
|
54
|
+
protected description: LocalizedString;
|
|
55
|
+
protected slug: LocalizedString;
|
|
56
|
+
protected brand: string;
|
|
57
|
+
protected basePrices: BasePriceList;
|
|
58
|
+
protected priceTiers: PriceTierList;
|
|
59
|
+
protected attributes: {
|
|
60
|
+
color: Color;
|
|
61
|
+
sizes: string[];
|
|
62
|
+
};
|
|
63
|
+
protected primaryImage: ImageInfoModel;
|
|
64
|
+
protected additionalImages: ImageInfoModel[];
|
|
65
|
+
protected isActive: boolean;
|
|
66
|
+
protected targetGender: GenderCategory;
|
|
67
|
+
protected categories: string[];
|
|
68
|
+
protected specifications: LocalizedProductSpecification;
|
|
69
|
+
protected searchTags: string[];
|
|
70
|
+
static productKeyRegex: RegExp;
|
|
71
|
+
static variantIdRegex: RegExp;
|
|
72
|
+
/**
|
|
73
|
+
* Creates an instance of ProductModel.
|
|
74
|
+
* Initializes properties based on the provided data, creating copies where necessary.
|
|
75
|
+
* @param data - The initial product attributes.
|
|
76
|
+
* @param date - Optional date for setting creation/modification times (defaults to now).
|
|
77
|
+
*/
|
|
78
|
+
constructor(data: ProductAttributes, date?: Date);
|
|
79
|
+
/**
|
|
80
|
+
* Gets the base Product ID.
|
|
81
|
+
* @returns Product ID.
|
|
82
|
+
*/
|
|
83
|
+
getId(): string;
|
|
84
|
+
/**
|
|
85
|
+
* Gets the user-friendly product key.
|
|
86
|
+
* @returns Product Key.
|
|
87
|
+
*/
|
|
88
|
+
getKey(): string;
|
|
89
|
+
/**
|
|
90
|
+
* Gets the specific Variant ID.
|
|
91
|
+
* @returns Variant ID.
|
|
92
|
+
*/
|
|
93
|
+
getVariantId(): string;
|
|
94
|
+
/**
|
|
95
|
+
* Gets the full localized product name object.
|
|
96
|
+
* @returns A copy of the LocalizedString object for the name.
|
|
97
|
+
*/
|
|
98
|
+
getName(): LocalizedString;
|
|
99
|
+
/**
|
|
100
|
+
* Gets the product name for a specific locale, falling back to English ('en').
|
|
101
|
+
* @param locale - The desired locale code.
|
|
102
|
+
* @returns The name string for the specified locale.
|
|
103
|
+
*/
|
|
104
|
+
getName(locale: LocaleCode): string;
|
|
105
|
+
/**
|
|
106
|
+
* Gets the full localized product description object.
|
|
107
|
+
* @returns A copy of the LocalizedString object for the description.
|
|
108
|
+
*/
|
|
109
|
+
getDescription(): LocalizedString;
|
|
110
|
+
/**
|
|
111
|
+
* Gets the product description for a specific locale, falling back to English ('en').
|
|
112
|
+
* @param locale - The desired locale code.
|
|
113
|
+
* @returns The description string for the specified locale.
|
|
114
|
+
*/
|
|
115
|
+
getDescription(locale: LocaleCode): string;
|
|
116
|
+
/**
|
|
117
|
+
* Gets the full localized product slug object.
|
|
118
|
+
* @returns A copy of the LocalizedString object for the slug.
|
|
119
|
+
*/
|
|
120
|
+
getSlug(): LocalizedString;
|
|
121
|
+
/**
|
|
122
|
+
* Gets the product slug for a specific locale, falling back to English ('en').
|
|
123
|
+
* @param locale - The desired locale code.
|
|
124
|
+
* @returns The slug string for the specified locale.
|
|
125
|
+
*/
|
|
126
|
+
getSlug(locale: LocaleCode): string;
|
|
127
|
+
/**
|
|
128
|
+
* Gets the brand associated with the product.
|
|
129
|
+
* @returns The brand name string.
|
|
130
|
+
*/
|
|
131
|
+
getBrand(): string;
|
|
132
|
+
/**
|
|
133
|
+
* Gets the list of base prices. Returns copies of the price objects.
|
|
134
|
+
* Optionally filters by country.
|
|
135
|
+
* @param country - Optional country code to filter prices for.
|
|
136
|
+
* @returns A list of base prices (or an empty list if none match).
|
|
137
|
+
*/
|
|
138
|
+
getBasePrices(country?: CountryCode): BasePriceList;
|
|
139
|
+
/**
|
|
140
|
+
* Gets the list of quantity-based price tiers. Returns copies of the tier objects.
|
|
141
|
+
* Optionally filters by country.
|
|
142
|
+
* @param country - Optional country code to filter tiers for.
|
|
143
|
+
* @returns A list of price tiers (or an empty list if none match or none exist).
|
|
144
|
+
*/
|
|
145
|
+
getPriceTiers(country?: CountryCode): PriceTierList;
|
|
146
|
+
/**
|
|
147
|
+
* Gets the variant-specific attributes (color, sizes). Returns copies.
|
|
148
|
+
* @returns Product Attributes.
|
|
149
|
+
*/
|
|
150
|
+
getAttributes(): {
|
|
151
|
+
color: Color;
|
|
152
|
+
sizes: string[];
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Gets details of product's primary image.
|
|
156
|
+
* @returns The ImageInfoModel instance for the primary image.
|
|
157
|
+
*/
|
|
158
|
+
getPrimaryImage(): ImageInfoModel;
|
|
159
|
+
/**
|
|
160
|
+
* Gets the list of additional product images.
|
|
161
|
+
* @returns An array of ImageInfoModel instances.
|
|
162
|
+
*/
|
|
163
|
+
getAdditionalImages(): ImageInfoModel[];
|
|
164
|
+
/**
|
|
165
|
+
* Checks if the product variant is active.
|
|
166
|
+
* @returns True if the product is active, false otherwise.
|
|
167
|
+
*/
|
|
168
|
+
getIsActive(): boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Gets the target gender category for the product.
|
|
171
|
+
* @returns The GenderCategory enum value.
|
|
172
|
+
*/
|
|
173
|
+
getTargetGender(): GenderCategory;
|
|
174
|
+
/**
|
|
175
|
+
* Gets the list of categories the product belongs to. Returns a copy.
|
|
176
|
+
* @returns An array of category.
|
|
177
|
+
*/
|
|
178
|
+
getCategories(): string[];
|
|
179
|
+
/**
|
|
180
|
+
* Gets the full localized product specifications object.
|
|
181
|
+
* @returns Product Specifications
|
|
182
|
+
*/
|
|
183
|
+
getSpecifications(): LocalizedProductSpecification;
|
|
184
|
+
/**
|
|
185
|
+
* Gets the product specifications for a specific locale, falling back to English ('en').
|
|
186
|
+
* @param locale - The desired locale code.
|
|
187
|
+
* @returns The ProductSpecification object for the specified locale, or undefined if not found.
|
|
188
|
+
*/
|
|
189
|
+
getSpecifications(locale: LocaleCode): ProductSpecification | undefined;
|
|
190
|
+
/**
|
|
191
|
+
* Gets the list of search tags. Returns a copy.
|
|
192
|
+
* @returns An array of search tags.
|
|
193
|
+
*/
|
|
194
|
+
getSearchTags(): string[];
|
|
195
|
+
/**
|
|
196
|
+
*
|
|
197
|
+
* @returns ProductData
|
|
198
|
+
*/
|
|
199
|
+
getDetails(): ProductData;
|
|
200
|
+
/**
|
|
201
|
+
* Calculates the maximum potential discount percentage for a given country
|
|
202
|
+
* based on the lowest price tier compared to the base price.
|
|
203
|
+
* @param country - The country code to calculate the discount for.
|
|
204
|
+
* @returns The maximum discount percentage (0-100), or 0 if calculation is not possible.
|
|
205
|
+
*/
|
|
206
|
+
getMaxDiscountPercent(country: CountryCode): number;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export { type LocalizedProductSpecification, type ProductAttributes, type ProductData, type ProductHashKey, type ProductSpecification, type ProductVariantIdentifier, ProductModel as default };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {b}from'../chunk-IYDPJQAK.js';import {a}from'../chunk-Q2WQECY6.js';var n=class extends a{id;key;variantId;name;description;slug;brand;basePrices;priceTiers;attributes;primaryImage;additionalImages;isActive;targetGender;categories;specifications;searchTags;static productKeyRegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static variantIdRegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;constructor(e,i=new Date){super(e,i),this.id=e.id,this.key=e.key,this.variantId=e.variantId,this.name=e.name,this.description=e.description,this.slug=e.slug,this.brand=e.brand,this.basePrices=e.basePrices.map(t=>({...t})),this.priceTiers=e.priceTiers?e.priceTiers.map(t=>({...t})):e.basePrices.map(t=>({...t})),this.attributes={...e.attributes,sizes:[...e.attributes.sizes]},this.primaryImage=new b(e.primaryImage),this.additionalImages=(e.additionalImages||[]).map(t=>new b(t)),this.isActive=e.isActive,this.targetGender=e.targetGender,this.categories=[...e.categories],this.specifications=JSON.parse(JSON.stringify({...e.specifications})),this.searchTags=e.searchTags?[...e.searchTags]:[];}getId(){return this.id}getKey(){return this.key}getVariantId(){return this.variantId}getName(e){return e?this.name[e]??this.name.en:{...this.name}}getDescription(e){return e?this.description[e]??this.description.en:{...this.description}}getSlug(e){return e?this.slug[e]??this.slug.en:{...this.slug}}getBrand(){return this.brand}getBasePrices(e){return (e?this.basePrices.filter(t=>t.country===e):this.basePrices).map(t=>({...t}))}getPriceTiers(e){return (e?this.priceTiers.filter(t=>t.country===e):this.priceTiers).map(t=>({...t}))}getAttributes(){return {...this.attributes,color:{...this.attributes.color},sizes:[...this.attributes.sizes]}}getPrimaryImage(){return this.primaryImage}getAdditionalImages(){return this.additionalImages}getIsActive(){return this.isActive}getTargetGender(){return this.targetGender}getCategories(){return [...this.categories]}getSpecifications(e){return e?this.specifications[e]??this.specifications.en:JSON.parse(JSON.stringify(this.specifications))}getSearchTags(){return [...this.searchTags]}getDetails(){let e=super.getDetails();return {id:this.getId(),key:this.getKey(),variantId:this.getVariantId(),name:this.getName(),description:this.getDescription(),slug:this.getSlug(),brand:this.getBrand(),basePrices:this.getBasePrices(),priceTiers:this.getPriceTiers(),attributes:this.getAttributes(),primaryImage:this.getPrimaryImage().getDetails(),additionalImages:this.getAdditionalImages().map(i=>i.getDetails()),isActive:this.getIsActive(),targetGender:this.getTargetGender(),categories:this.getCategories(),specifications:this.getSpecifications(),searchTags:this.getSearchTags(),...e}}getMaxDiscountPercent(e){let i=this.basePrices.find(r=>r.country===e),t=this.priceTiers?.filter(r=>r.country===e).sort((r,c)=>r.unitPrice-c.unitPrice)[0]?.unitPrice;return !i||i.unitPrice<=0||t===void 0?0:Math.max(0,i.unitPrice-t)/i.unitPrice*100}};export{n as default};//# sourceMappingURL=Product.js.map
|
|
2
|
+
//# sourceMappingURL=Product.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/Classes/Product.ts"],"names":["ProductModel","BaseModel","data","date","price","tier","ImageInfoModel","image","locale","country","baseDetails","basePrice","lowestTierPrice","a","b"],"mappings":"0EAsDA,IAAqBA,CAArB,CAAA,cAA0CC,CAAU,CACtC,EACA,CAAA,GAAA,CACA,SAEA,CAAA,IAAA,CACA,WACA,CAAA,IAAA,CACA,KAEA,CAAA,UAAA,CACA,UAEA,CAAA,UAAA,CAKA,YACA,CAAA,gBAAA,CAEA,QACA,CAAA,YAAA,CACA,UACA,CAAA,cAAA,CACA,UAEV,CAAA,OAAO,eAAkB,CAAA,kCAAA,CACzB,OAAO,cAAA,CAAiB,kCAQxB,CAAA,WAAA,CAAYC,EAAyBC,CAAa,CAAA,IAAI,IAAQ,CAAA,CAC1D,KAAMD,CAAAA,CAAAA,CAAMC,CAAI,CAAA,CAChB,IAAK,CAAA,EAAA,CAAKD,CAAK,CAAA,EAAA,CACf,IAAK,CAAA,GAAA,CAAMA,CAAK,CAAA,GAAA,CAChB,IAAK,CAAA,SAAA,CAAYA,CAAK,CAAA,SAAA,CACtB,IAAK,CAAA,IAAA,CAAOA,CAAK,CAAA,IAAA,CACjB,IAAK,CAAA,WAAA,CAAcA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Ac,CAAA,IAAA,CAAK,eAAgB,EAAA,CAAE,UAAW,EAAA,CAChD,gBAAkB,CAAA,IAAA,CAAK,mBAAoB,EAAA,CAAE,GAAIH,CAAAA,CAAAA,EAASA,CAAM,CAAA,UAAA,EAAY,CAAA,CAC5E,QAAU,CAAA,IAAA,CAAK,WAAY,EAAA,CAC3B,YAAc,CAAA,IAAA,CAAK,eAAgB,EAAA,CACnC,UAAY,CAAA,IAAA,CAAK,eACjB,CAAA,cAAA,CAAgB,IAAK,CAAA,iBAAA,EACrB,CAAA,UAAA,CAAY,IAAK,CAAA,aAAA,EACjB,CAAA,GAAGG,CACP,CACJ,CAQA,qBAAA,CAAsBD,CAA8B,CAAA,CAElD,IAAME,CAAAA,CAAY,IAAK,CAAA,UAAA,CAAW,IAAKP,CAAAA,CAAAA,EAASA,CAAM,CAAA,OAAA,GAAYK,CAAO,CAAA,CAGnEG,CAAkB,CAAA,IAAA,CAAK,UACC,EAAA,MAAA,CAAOP,CAAQA,EAAAA,CAAAA,CAAK,UAAYI,CAAO,CAAA,CACxC,IAAK,CAAA,CAACI,CAAGC,CAAAA,CAAAA,GAAMD,CAAE,CAAA,SAAA,CAAYC,CAAE,CAAA,SAAS,CAAE,CAAA,CAAC,CAAG,EAAA,SAAA,CAG3E,OAAI,CAACH,CAAaA,EAAAA,CAAAA,CAAU,SAAa,EAAA,CAAA,EAAKC,CAAoB,GAAA,KAAA,CAAA,CACvD,CAIM,CAAA,IAAA,CAAK,GAAI,CAAA,CAAA,CAAGD,CAAU,CAAA,SAAA,CAAYC,CAAe,CAAA,CAG/CD,CAAU,CAAA,SAAA,CAAa,GAC5C,CACF","file":"Product.js","sourcesContent":["import BaseModel, { BaseAttributes } from \"./Base\";\r\nimport { BasePriceList, PriceTierList, Color, LocalizedString, CountryCode, LocaleCode } from './Common';\r\nimport { GenderCategory } from \"./Enum\";\r\nimport ImageInfoModel, { ImageInfoData } from \"./ImageInfo\";\r\n\r\nexport type ProductVariantIdentifier = {\r\n key: string;\r\n variantId: string;\r\n};\r\n\r\nexport type ProductHashKey = {\r\n id: string;\r\n variantId: string;\r\n}\r\n\r\nexport type ProductAttributes = BaseAttributes & {\r\n id: string;\r\n key: string;\r\n variantId: string;\r\n\r\n name: LocalizedString;\r\n description: LocalizedString;\r\n slug: LocalizedString;\r\n brand: string;\r\n\r\n basePrices: BasePriceList;\r\n priceTiers: PriceTierList;\r\n\r\n attributes: {\r\n color: Color;\r\n sizes: string[];\r\n };\r\n\r\n primaryImage: ImageInfoData;\r\n additionalImages?: ImageInfoData[];\r\n\r\n // Metadata & Categorization\r\n isActive: boolean;\r\n targetGender: GenderCategory;\r\n categories: string[];\r\n specifications: { [locale: string]: { [key: string]: string | string[] } };\r\n searchTags?: string[];\r\n};\r\n\r\nexport type ProductData = Required<ProductAttributes>\r\n\r\nexport type ProductSpecification = { [key: string]: string | string[] };\r\n\r\nexport type LocalizedProductSpecification = {\r\n en: ProductSpecification\r\n} & {\r\n [locale in LocaleCode]?: ProductSpecification\r\n}\r\n\r\nexport default class ProductModel extends BaseModel {\r\n protected id: string;\r\n protected key: string;\r\n protected variantId: string;\r\n\r\n protected name: LocalizedString;\r\n protected description: LocalizedString;\r\n protected slug: LocalizedString;\r\n protected brand: string;\r\n\r\n protected basePrices: BasePriceList;\r\n protected priceTiers: PriceTierList;\r\n\r\n protected attributes: {\r\n color: Color;\r\n sizes: string[];\r\n };\r\n\r\n protected primaryImage: ImageInfoModel;\r\n protected additionalImages: ImageInfoModel[];\r\n\r\n protected isActive: boolean;\r\n protected targetGender: GenderCategory;\r\n protected categories: string[];\r\n protected specifications: LocalizedProductSpecification;\r\n protected searchTags: string[];\r\n\r\n static productKeyRegex = /^(?!\\s)(?!.*\\s$)[A-Z0-9-]{4,16}$/;\r\n static variantIdRegex = /^(?!\\s)(?!.*\\s$)[A-Z0-9-]{4,16}$/;\r\n\r\n /**\r\n * Creates an instance of ProductModel.\r\n * Initializes properties based on the provided data, creating copies where necessary.\r\n * @param data - The initial product attributes.\r\n * @param date - Optional date for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: ProductAttributes, date: Date = new Date()) {\r\n super(data, date);\r\n this.id = data.id;\r\n this.key = data.key;\r\n this.variantId = data.variantId;\r\n this.name = data.name;\r\n this.description = data.description;\r\n this.slug = data.slug;\r\n this.brand = data.brand;\r\n\r\n this.basePrices = data.basePrices.map(price => ({ ...price }));\r\n this.priceTiers = data.priceTiers ? \r\n data.priceTiers.map(tier => ({ ...tier })) \r\n : \r\n data.basePrices.map(price => ({ ...price }));;\r\n\r\n this.attributes = {\r\n ...data.attributes,\r\n sizes: [...data.attributes.sizes]\r\n };\r\n\r\n this.primaryImage = new ImageInfoModel(data.primaryImage);\r\n this.additionalImages = (data.additionalImages || []).map(image => new ImageInfoModel(image));\r\n this.isActive = data.isActive;\r\n this.targetGender = data.targetGender;\r\n this.categories = [...data.categories];\r\n this.specifications = JSON.parse(JSON.stringify({ ...data.specifications }));\r\n this.searchTags = data.searchTags ? [...data.searchTags] : [];\r\n }\r\n\r\n /**\r\n * Gets the base Product ID.\r\n * @returns Product ID.\r\n */\r\n getId(): string {\r\n return this.id;\r\n }\r\n\r\n /**\r\n * Gets the user-friendly product key.\r\n * @returns Product Key.\r\n */\r\n getKey(): string {\r\n return this.key;\r\n }\r\n\r\n /**\r\n * Gets the specific Variant ID.\r\n * @returns Variant ID.\r\n */\r\n getVariantId(): string {\r\n return this.variantId;\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 this.name[locale] ?? this.name.en;\r\n } else {\r\n return { ...this.name };\r\n }\r\n }\r\n\r\n /**\r\n * Gets the full localized product description object.\r\n * @returns A copy of the LocalizedString object for the description.\r\n */\r\n getDescription(): LocalizedString\r\n /**\r\n * Gets the product description for a specific locale, falling back to English ('en').\r\n * @param locale - The desired locale code.\r\n * @returns The description string for the specified locale.\r\n */\r\n getDescription(locale: LocaleCode): string\r\n getDescription(locale?: LocaleCode): LocalizedString | string {\r\n if(locale){\r\n return this.description[locale] ?? this.description.en;\r\n } else {\r\n return { ...this.description };\r\n }\r\n }\r\n\r\n /**\r\n * Gets the full localized product slug object.\r\n * @returns A copy of the LocalizedString object for the slug.\r\n */\r\n getSlug(): LocalizedString\r\n /**\r\n * Gets the product slug for a specific locale, falling back to English ('en').\r\n * @param locale - The desired locale code.\r\n * @returns The slug string for the specified locale.\r\n */\r\n getSlug(locale: LocaleCode): string\r\n getSlug(locale?: LocaleCode): LocalizedString | string {\r\n if (locale) {\r\n return this.slug[locale] ?? this.slug.en;\r\n } else {\r\n return { ...this.slug };\r\n }\r\n }\r\n\r\n /**\r\n * Gets the brand associated with the product.\r\n * @returns The brand name string.\r\n */\r\n getBrand(): string {\r\n return this.brand;\r\n }\r\n\r\n /**\r\n * Gets the list of base prices. Returns copies of the price objects.\r\n * Optionally filters by country.\r\n * @param country - Optional country code to filter prices for.\r\n * @returns A list of base prices (or an empty list if none match).\r\n */\r\n getBasePrices(country?: CountryCode): BasePriceList {\r\n const filteredPrices = country ? this.basePrices.filter(price => price.country === country) : this.basePrices;\r\n return filteredPrices.map(price => ({ ...price }));\r\n }\r\n\r\n /**\r\n * Gets the list of quantity-based price tiers. Returns copies of the tier objects.\r\n * Optionally filters by country.\r\n * @param country - Optional country code to filter tiers for.\r\n * @returns A list of price tiers (or an empty list if none match or none exist).\r\n */\r\n getPriceTiers(country?: CountryCode): PriceTierList {\r\n const filteredTiers = country ? this.priceTiers.filter(tier => tier.country === country) : this.priceTiers;\r\n return filteredTiers.map(tier => ({ ...tier }));\r\n }\r\n\r\n /**\r\n * Gets the variant-specific attributes (color, sizes). Returns copies.\r\n * @returns Product Attributes.\r\n */\r\n getAttributes(): { color: Color; sizes: string[] } {\r\n return {\r\n ...this.attributes,\r\n color: { ...this.attributes.color }, // Copy color object\r\n sizes: [...this.attributes.sizes]\r\n };\r\n }\r\n\r\n /**\r\n * Gets details of product's primary image.\r\n * @returns The ImageInfoModel instance for the primary image.\r\n */\r\n getPrimaryImage(): ImageInfoModel {\r\n return this.primaryImage;\r\n }\r\n\r\n /**\r\n * Gets the list of additional product images.\r\n * @returns An array of ImageInfoModel instances.\r\n */\r\n getAdditionalImages(): ImageInfoModel[] {\r\n return this.additionalImages;\r\n }\r\n\r\n /**\r\n * Checks if the product variant is active.\r\n * @returns True if the product is active, false otherwise.\r\n */\r\n getIsActive(): boolean {\r\n return this.isActive;\r\n }\r\n\r\n /**\r\n * Gets the target gender category for the product.\r\n * @returns The GenderCategory enum value.\r\n */\r\n getTargetGender(): GenderCategory {\r\n return this.targetGender;\r\n }\r\n\r\n /**\r\n * Gets the list of categories the product belongs to. Returns a copy.\r\n * @returns An array of category.\r\n */\r\n getCategories(): string[] {\r\n return [...this.categories];\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(): LocalizedProductSpecification\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): LocalizedProductSpecification | ProductSpecification | undefined {\r\n if(locale){\r\n return this.specifications[locale] ?? this.specifications.en;\r\n } else {\r\n return JSON.parse(JSON.stringify(this.specifications));\r\n }\r\n }\r\n\r\n /**\r\n * Gets the list of search tags. Returns a copy.\r\n * @returns An array of search tags.\r\n */\r\n getSearchTags(): string[] {\r\n return [...this.searchTags];\r\n }\r\n\r\n /**\r\n *\r\n * @returns ProductData\r\n */\r\n getDetails(): ProductData {\r\n const baseDetails = super.getDetails();\r\n return {\r\n id: this.getId(),\r\n key: this.getKey(),\r\n variantId: this.getVariantId(),\r\n name: this.getName(),\r\n description: this.getDescription(),\r\n slug: this.getSlug(),\r\n brand: this.getBrand(),\r\n basePrices: this.getBasePrices(),\r\n priceTiers: this.getPriceTiers(),\r\n attributes: this.getAttributes(),\r\n primaryImage: this.getPrimaryImage().getDetails(),\r\n additionalImages: this.getAdditionalImages().map(image => image.getDetails()),\r\n isActive: this.getIsActive(),\r\n targetGender: this.getTargetGender(),\r\n categories: this.getCategories(),\r\n specifications: this.getSpecifications(),\r\n searchTags: this.getSearchTags(),\r\n ...baseDetails\r\n }; \r\n }\r\n\r\n /**\r\n * Calculates the maximum potential discount percentage for a given country\r\n * based on the lowest price tier compared to the base price.\r\n * @param country - The country code to calculate the discount for.\r\n * @returns The maximum discount percentage (0-100), or 0 if calculation is not possible.\r\n */\r\n getMaxDiscountPercent(country: CountryCode): number {\r\n // Find base price for the country (should be unique per country)\r\n const basePrice = this.basePrices.find(price => price.country === country);\r\n\r\n // Find the lowest unit price among tiers for the country\r\n const lowestTierPrice = this.priceTiers\r\n ?.filter(tier => tier.country === country) // Filter tiers for the country first\r\n .sort((a, b) => a.unitPrice - b.unitPrice)[0]?.unitPrice; // Then sort and get lowest\r\n\r\n // Validate prices before calculation\r\n if (!basePrice || basePrice.unitPrice <= 0 || lowestTierPrice === undefined) {\r\n return 0; // Cannot calculate discount\r\n }\r\n\r\n // Calculate discount, ensuring it's not negative\r\n const discount = Math.max(0, basePrice.unitPrice - lowestTierPrice);\r\n\r\n // Calculate percentage\r\n return (discount / basePrice.unitPrice) * 100;\r\n }\r\n}"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var u=class{customFields;version;createdAt;modifiedAt;modifiedBy;constructor(t,e=new Date){this.customFields={...t.customFields},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){this.modifiedBy=t;}getCustomField(t){return this.customFields[t]??null}setCustomField(t,e){this.customFields[t]=e;}getAllCustomFields(){return {...this.customFields}}};var l=class extends u{id;firstName;lastName;phone;email;addressLine1;addressLine2;city;postalCode;state;country;isBillingAddress;isShippingAddress;constructor(t,e=new Date){super(t,e),this.id=t.id,this.firstName=t.firstName,this.lastName=t.lastName,this.phone=t.phone,this.email=t.email,this.addressLine1=t.addressLine1,this.addressLine2=t.addressLine2||"",this.city=t.city,this.postalCode=t.postalCode,this.state=t.state,this.country=t.country,this.isBillingAddress=t.isBillingAddress,this.isShippingAddress=t.isShippingAddress;}getDetails(){return {...super.getDetails(),id:this.getId(),firstName:this.getFirstName(),lastName:this.getLastName(),phone:this.getPhone(),email:this.getEmail(),addressLine1:this.getAddressLine1(),addressLine2:this.getAddressLine2(),city:this.getCity(),postalCode:this.getPostalCode(),state:this.getState(),country:this.getCountry(),isBillingAddress:this.getIsBillingAddress(),isShippingAddress:this.getIsShippingAddress()}}getId(){return this.id}getFirstName(){return this.firstName}getLastName(){return this.lastName}getPhone(){return this.phone}getEmail(){return this.email}getAddressLine1(){return this.addressLine1}getAddressLine2(){return this.addressLine2}getCity(){return this.city}getPostalCode(){return this.postalCode}getState(){return this.state}getCountry(){return this.country}getIsBillingAddress(){return this.isBillingAddress}getIsShippingAddress(){return this.isShippingAddress}getAddressType(){return this.isBillingAddress&&this.isShippingAddress?"billing&shipping":this.isBillingAddress?"billing":this.isShippingAddress?"shipping":"none"}static checkIfShippingAddress(t){return t==="shipping"||t==="billing&shipping"}static checkIfBillingAddress(t){return t==="billing"||t==="billing&shipping"}};var d=class{sources;alt;order;label;constructor(t){if(this.sources={...t.sources},this.alt=t.alt,this.order=t.order,this.label=t.label,!this.sources.original)throw "ImageInfoModel cannot be created without an 'original' source URL."}getSources(){return {...this.sources}}getSource(t){return this.sources[t]||this.sources.original}getAlt(){return this.alt}getOrder(){return this.order}getLabel(){return this.label}setAlt(t){this.alt=t;}setOrder(t){this.order=t;}setLabel(t){this.label=t;}setSource(t,e){if(e===void 0){if(t==="original")throw "Cannot remove the 'original' image source.";delete this.sources[t];}else this.sources[t]=e;}getDetails(){return {sources:this.getSources(),alt:this.getAlt(),order:this.getOrder(),label:this.getLabel()}}};var p=class{id;productKey;variantId;name;attributes;primaryImage;subItems;totalQuantity;basePrice;priceTotals;priceTiers;constructor(t){this.id=t.id,this.productKey=t.productKey,this.variantId=t.variantId,this.name={...t.name},this.attributes={...t.attributes},this.primaryImage=new d(t.primaryImage),this.subItems=t.subItems.map(e=>({...e})),this.basePrice={...t.basePrice},this.priceTiers=t.priceTiers.map(e=>({...e})),this.totalQuantity=0,this.priceTotals={subtotal:0,mrpTotal:0},this.recalculateTotalQuantity(),this.recalculatePriceTotal();}getId(){return this.id}getProductKey(){return this.productKey}getVariantId(){return this.variantId}getName(t){return t?this.name[t]??this.name.en:{...this.name}}getAttributes(){return {...this.attributes}}getImage(){return this.primaryImage}getSubItems(){return this.subItems.map(t=>({...t}))}getTotalQuantity(){return this.totalQuantity}getBasePrice(){return {...this.basePrice}}getPriceTotals(){return {...this.priceTotals}}getPriceTiers(){return this.priceTiers.map(t=>({...t}))}recalculateTotalQuantity(){this.totalQuantity=this.subItems.reduce((t,e)=>t+e.quantity,0);}recalculatePriceTotal(){let t=this.totalQuantity,e=this.basePrice.unitPrice,i=null;for(let r of this.priceTiers.sort((s,a)=>a.minQuantity-s.minQuantity))if(t>=r.minQuantity){i=r;break}i&&(e=i.unitPrice),this.priceTotals.mrpTotal=this.basePrice.unitPrice*t,this.priceTotals.subtotal=e*t;}getDetails(){return {id:this.getId(),productKey:this.getProductKey(),variantId:this.getVariantId(),name:this.getName(),attributes:this.getAttributes(),primaryImage:this.getImage().getDetails(),subItems:this.getSubItems(),totalQuantity:this.getTotalQuantity(),basePrice:this.getBasePrice(),priceTotals:this.getPriceTotals(),priceTiers:this.getPriceTiers()}}addSubItems(t,e){t.forEach(i=>{let r=this.subItems.find(s=>s.size===i.size);r?r.quantity=e?r.quantity+i.quantity:i.quantity:this.subItems.push(i);}),this.subItems=this.subItems.filter(i=>i.quantity),this.recalculateTotalQuantity(),this.recalculatePriceTotal();}clearLineItem(){this.id="",this.productKey="",this.variantId="",this.name={en:""},this.attributes={color:{name:"",hex:""}},this.primaryImage=new d({sources:{original:""}}),this.subItems=[],this.recalculateTotalQuantity(),this.recalculatePriceTotal();}};var h={IN:"INR"},I={INR:"\u20B9"};var o=class n{price;country;constructor(t,e){if(this.country=e,t<0)throw new Error("InvalidPrice: Price cannot be negative.");this.price=t;}getCountry(){return this.country}getRoundedPrice(){return n.getRoundedPrice(this.price,this.country)}getFormattedString(t,e={}){let i=e.displayAsInteger??!1,r=h[this.country];if(r===void 0)throw new Error("Currency mapping not found for CountryCode");let s=this.price,a=i?0:n.getDecimalPlaces(r),m={style:"currency",currency:r,signDisplay:"never",currencyDisplay:e.currencyDisplay,minimumFractionDigits:a,maximumFractionDigits:a};i&&(s=Math.round(s));try{return new Intl.NumberFormat(t,m).format(s)}catch(y){return console.error(`Error formatting price for locale "${t}" and currency "${r}":`,y),`${I[r]??r} ${n.addThousandSeparators(s.toFixed(a))}`}}static getDecimalPlaces(t){switch(t){case"INR":default:return 2}}static addThousandSeparators(t){let e=t.split("."),i=e[0],r=e.length>1?"."+e[1]:"";return i.replace(/\B(?=(\d{3})+(?!\d))/g,",")+r}static getRoundedPrice(t,e){if(t<0)throw new Error("Price cannot be negative for rounding.");let i=h[e];if(i===void 0)throw new Error(`Currency mapping not found for CountryCode: ${e}`);let r=n.getDecimalPlaces(i),s=Math.pow(10,r);return Math.round(t*s)/s}static getCurrency(t){return h[t]}};o.getRoundedPrice(-1,"IN");var g=class extends u{couponCode;name;description;type;customerId;validFrom;validTo;minCartValue;maxCartDiscount;discountMethod;percentageValue;applicableTo;category;constructor(t,e=new Date){super(t,e),this.couponCode=t.couponCode,this.name={...t.name},this.description={...t.description},this.type=t.type,this.customerId=t.customerId,this.validFrom=t.validFrom&&Date.parse(t.validFrom)?new Date(t.validFrom).toISOString():e.toISOString(),this.validTo=t.validTo&&Date.parse(t.validTo)?new Date(t.validTo).toISOString():e.toISOString(),this.minCartValue=t.minCartValue.map(i=>({...i})),this.maxCartDiscount=t.maxCartDiscount.map(i=>({...i})),this.discountMethod=t.discountMethod,this.percentageValue=t.percentageValue??0,this.applicableTo=t.applicableTo,this.category=t.category;}getCode(){return this.couponCode}getName(t){return t?this.name[t]??this.name.en:{...this.name}}getDescription(t){return t?this.description[t]??this.description.en:{...this.description}}getType(){return this.type}getCustomerId(){return this.customerId??""}getValidFrom(){return this.validFrom}getValidTo(){return this.validTo}getMinCartValue(t){return t?this.minCartValue.find(e=>e.country===t):this.minCartValue}getMaxCartDiscount(t){return t?this.maxCartDiscount.find(e=>e.country===t):this.maxCartDiscount}getDiscountMethod(){return this.discountMethod}getPercentageValue(){return this.percentageValue}getApplicableTo(){return this.applicableTo}getCategory(){return this.category}getDetails(){return {...super.getDetails(),couponCode:this.getCode(),name:this.getName(),description:this.getDescription(),type:this.getType(),customerId:this.getCustomerId(),validFrom:this.getValidFrom(),validTo:this.getValidTo(),minCartValue:this.getMinCartValue(),maxCartDiscount:this.getMaxCartDiscount(),discountMethod:this.getDiscountMethod(),percentageValue:this.getPercentageValue(),applicableTo:this.getApplicableTo(),category:this.getCategory()}}isActive(){return new Date(this.validFrom)<=new Date&&new Date(this.validTo)>=new Date}isApplicableTo(t){return this.applicableTo==="all"||this.applicableTo==="ftb"&&t}};var b=class extends u{id;customerId;customerEmail;anonymousId;lineItems;shippingDetails;shippingAddress;billingAddress;coupons;total;country;currency;locale;constructor(t,e=new Date){super(t,e),this.id=t.id,this.customerId=t.customerId,this.customerEmail=t.customerEmail,this.anonymousId=t.anonymousId,this.country=t.country,this.currency=t.currency,this.locale=t.locale,this.lineItems=(t.lineItems??[]).map(i=>new p(i)),this.billingAddress=t.billingAddress?new l(t.billingAddress,e):null,this.shippingAddress=t.shippingAddress?new l(t.shippingAddress,e):null,this.coupons=(t.coupons||[]).map(i=>new g(i)),this.shippingDetails=t.shippingDetails?{...t.shippingDetails}:null,this.total={shipping:t.total?.shipping||0,effectiveShipping:t.total?.effectiveShipping||t.total?.shipping||0,subtotal:0,mrpTotal:0,couponTotal:t.total?.couponTotal||{},grandTotal:t.total?.grandTotal||0},this.recalculateBaseTotals();}recalculateBaseTotals(){this.total.subtotal=o.getRoundedPrice(this.lineItems.reduce((t,e)=>t+e.getPriceTotals().subtotal,0),this.country),this.total.mrpTotal=o.getRoundedPrice(this.lineItems.reduce((t,e)=>t+e.getPriceTotals().mrpTotal,0),this.country);}getId(){return this.id}getCustomerId(){return this.customerId}getCustomerEmail(){return this.customerEmail}getAnonymousId(){return this.anonymousId}getLineItems(){return this.lineItems.map(t=>new p(t.getDetails()))}getShippingDetails(){return this.shippingDetails?{...this.shippingDetails}:null}getShippingAddress(){return this.shippingAddress?new l(this.shippingAddress.getDetails()):null}getBillingAddress(){return this.billingAddress?new l(this.billingAddress.getDetails()):null}getCoupons(){return this.coupons.map(t=>new g(t.getDetails()))}getCountry(){return this.country}getCurrency(){return this.currency}getLocale(){return this.locale}getTotal(){return {...this.total,couponTotal:{...this.total.couponTotal}}}calculateApplicableCouponDiscount(t){if(!t.isActive())return 0;let e=t.getMinCartValue(this.country),i=t.getMaxCartDiscount(this.country);if(!e||this.total.subtotal<e.price||!i||i.price<0)return 0;let r=t.getCategory(),s=t.getDiscountMethod(),a=0,m=r==="SHIPPING"?this.total.shipping:this.total.subtotal;if(m<=0)return 0;switch(s){case"flat":let C=i?.price??0;a=Math.min(m,C);break;case"percentage":a=m*(t.getPercentageValue()/100);break;default:return 0}let y=Math.min(a,i.price);return o.getRoundedPrice(Math.max(0,y),this.country)}recalculateCouponTotals(){this.total.couponTotal={};let t=0;return this.coupons.forEach(e=>{let i=this.calculateApplicableCouponDiscount(e);i>0&&(this.total.couponTotal[e.getCode()]=i,t+=i);}),o.getRoundedPrice(t,this.country)}updateCartTotals(){this.total.subtotal=o.getRoundedPrice(this.lineItems.reduce((r,s)=>r+s.getPriceTotals().subtotal,0),this.country),this.total.mrpTotal=o.getRoundedPrice(this.lineItems.reduce((r,s)=>r+s.getPriceTotals().mrpTotal,0),this.country),this.recalculateCouponTotals();let t=this.coupons.filter(r=>r.getCategory()==="SHIPPING").reduce((r,s)=>r+(this.total.couponTotal[s.getCode()]??0),0);this.total.effectiveShipping=o.getRoundedPrice(Math.max(0,this.total.shipping-t),this.country);let e=this.coupons.filter(r=>r.getCategory()!=="SHIPPING").reduce((r,s)=>r+(this.total.couponTotal[s.getCode()]??0),0),i=this.total.subtotal+this.total.effectiveShipping;this.total.grandTotal=o.getRoundedPrice(Math.max(0,i-e),this.country);}setShippingDetails(t){this.shippingDetails=t?{...t}:null,this.total.shipping=o.getRoundedPrice(this.shippingDetails?.estimatedCost??0,this.country),this.updateCartTotals();}getDetails(){return {...super.getDetails(),id:this.getId(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),anonymousId:this.getAnonymousId(),lineItems:this.getLineItems().map(t=>t.getDetails()),shippingDetails:this.getShippingDetails(),shippingAddress:this.getShippingAddress()?.getDetails()||null,billingAddress:this.getBillingAddress()?.getDetails()||null,coupons:this.getCoupons().map(t=>t.getDetails()),total:this.getTotal(),country:this.getCountry(),currency:this.getCurrency(),locale:this.getLocale()}}};module.exports=b;//# sourceMappingURL=ShoppingContainer.cjs.map
|
|
2
|
+
//# sourceMappingURL=ShoppingContainer.cjs.map
|