b23-lib 2.0.0 → 2.0.2
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/Auth/index.mjs.map +1 -1
- package/dist/Classes/Address.d.mts +1 -1
- package/dist/Classes/Address.d.ts +1 -1
- package/dist/Classes/Address.js.map +1 -1
- package/dist/Classes/Address.mjs +1 -1
- package/dist/Classes/Base.d.mts +5 -5
- package/dist/Classes/Base.d.ts +5 -5
- package/dist/Classes/Base.js.map +1 -1
- package/dist/Classes/Base.mjs +1 -1
- package/dist/Classes/Cart.d.mts +27 -12
- package/dist/Classes/Cart.d.ts +27 -12
- package/dist/Classes/Cart.js +1 -1
- 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/Common.d.mts +2 -93
- package/dist/Classes/Common.d.ts +2 -93
- package/dist/Classes/Coupon.d.mts +33 -15
- package/dist/Classes/Coupon.d.ts +33 -15
- 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/Customer.d.mts +2 -2
- package/dist/Classes/Customer.d.ts +2 -2
- package/dist/Classes/Customer.js.map +1 -1
- package/dist/Classes/Customer.mjs +1 -1
- package/dist/Classes/Customer.mjs.map +1 -1
- package/dist/Classes/CustomerAddress.d.mts +1 -1
- package/dist/Classes/CustomerAddress.d.ts +1 -1
- package/dist/Classes/CustomerAddress.js.map +1 -1
- package/dist/Classes/CustomerAddress.mjs +1 -1
- package/dist/Classes/Enum.d.mts +43 -2
- package/dist/Classes/Enum.d.ts +43 -2
- 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 +59 -0
- package/dist/Classes/Error.d.ts +59 -0
- package/dist/Classes/Error.js +2 -0
- package/dist/Classes/Error.js.map +1 -0
- package/dist/Classes/Error.mjs +2 -0
- package/dist/Classes/Error.mjs.map +1 -0
- package/dist/Classes/ImageInfo.js +1 -1
- package/dist/Classes/ImageInfo.js.map +1 -1
- package/dist/Classes/ImageInfo.mjs +1 -1
- package/dist/Classes/Inventory.d.mts +25 -6
- package/dist/Classes/Inventory.d.ts +25 -6
- 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/Inventory.mjs.map +1 -1
- package/dist/Classes/LineItem.d.mts +140 -58
- package/dist/Classes/LineItem.d.ts +140 -58
- package/dist/Classes/LineItem.js +1 -1
- package/dist/Classes/LineItem.js.map +1 -1
- package/dist/Classes/LineItem.mjs +1 -1
- package/dist/Classes/Order.d.mts +7 -51
- package/dist/Classes/Order.d.ts +7 -51
- package/dist/Classes/Order.js +1 -1
- 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/Payment.d.mts +4 -4
- package/dist/Classes/Payment.d.ts +4 -4
- package/dist/Classes/Payment.js.map +1 -1
- package/dist/Classes/Payment.mjs +1 -1
- package/dist/Classes/Payment.mjs.map +1 -1
- package/dist/Classes/Price.d.mts +1 -82
- package/dist/Classes/Price.d.ts +1 -82
- 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.d.mts +101 -87
- package/dist/Classes/Product.d.ts +101 -87
- 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/Product.mjs.map +1 -1
- package/dist/Classes/ShoppingContainer.d.mts +79 -63
- package/dist/Classes/ShoppingContainer.d.ts +79 -63
- package/dist/Classes/ShoppingContainer.js +1 -1
- package/dist/Classes/ShoppingContainer.js.map +1 -1
- package/dist/Classes/ShoppingContainer.mjs +1 -1
- package/dist/Classes/TaxRule.d.mts +63 -0
- package/dist/Classes/TaxRule.d.ts +63 -0
- package/dist/Classes/TaxRule.js +2 -0
- package/dist/Classes/TaxRule.js.map +1 -0
- package/dist/Classes/TaxRule.mjs +2 -0
- package/dist/Classes/TaxRule.mjs.map +1 -0
- package/dist/Classes/TieredPrice.d.mts +75 -0
- package/dist/Classes/TieredPrice.d.ts +75 -0
- package/dist/Classes/TieredPrice.js +2 -0
- package/dist/Classes/TieredPrice.js.map +1 -0
- package/dist/Classes/TieredPrice.mjs +2 -0
- package/dist/Classes/TieredPrice.mjs.map +1 -0
- package/dist/Common-D-UoxwM0.d.ts +210 -0
- package/dist/Common-FbQ5-3QN.d.mts +210 -0
- package/dist/chunk-54RUAXYE.mjs +2 -0
- package/dist/chunk-54RUAXYE.mjs.map +1 -0
- package/dist/{chunk-ATUUYYQT.mjs → chunk-55SOBG62.mjs} +2 -2
- package/dist/chunk-55SOBG62.mjs.map +1 -0
- package/dist/{chunk-H5GPM4LA.mjs → chunk-5KD2EW7O.mjs} +2 -2
- package/dist/{chunk-H5GPM4LA.mjs.map → chunk-5KD2EW7O.mjs.map} +1 -1
- package/dist/chunk-72DR3HF2.mjs +2 -0
- package/dist/chunk-72DR3HF2.mjs.map +1 -0
- package/dist/chunk-AMIRIUMH.mjs +2 -0
- package/dist/chunk-AMIRIUMH.mjs.map +1 -0
- package/dist/chunk-ISS46WVH.mjs +2 -0
- package/dist/chunk-ISS46WVH.mjs.map +1 -0
- package/dist/chunk-KWH7GE23.mjs +2 -0
- package/dist/chunk-KWH7GE23.mjs.map +1 -0
- package/dist/chunk-LXJGGXF3.mjs +2 -0
- package/dist/chunk-LXJGGXF3.mjs.map +1 -0
- package/dist/chunk-M4BZMGTB.mjs +2 -0
- package/dist/chunk-M4BZMGTB.mjs.map +1 -0
- package/dist/chunk-NJKSUUOB.mjs +2 -0
- package/dist/chunk-NJKSUUOB.mjs.map +1 -0
- package/dist/chunk-NUTKOIGY.mjs +2 -0
- package/dist/chunk-NUTKOIGY.mjs.map +1 -0
- package/dist/chunk-QLLM365R.mjs +2 -0
- package/dist/chunk-QLLM365R.mjs.map +1 -0
- package/dist/chunk-SFTIM3X7.mjs +2 -0
- package/dist/chunk-SFTIM3X7.mjs.map +1 -0
- package/dist/index.d.mts +44 -4
- package/dist/index.d.ts +44 -4
- 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 +1 -1
- package/dist/chunk-6PDP4ETM.mjs +0 -2
- package/dist/chunk-6PDP4ETM.mjs.map +0 -1
- package/dist/chunk-ATUUYYQT.mjs.map +0 -1
- package/dist/chunk-CKUUUEWT.mjs +0 -2
- package/dist/chunk-CKUUUEWT.mjs.map +0 -1
- package/dist/chunk-DKI6BDWK.mjs +0 -2
- package/dist/chunk-DKI6BDWK.mjs.map +0 -1
- package/dist/chunk-K3AXPTGG.mjs +0 -2
- package/dist/chunk-K3AXPTGG.mjs.map +0 -1
- package/dist/chunk-LMMJSJTO.mjs +0 -2
- package/dist/chunk-LMMJSJTO.mjs.map +0 -1
- package/dist/chunk-RWBNLNQ6.mjs +0 -2
- package/dist/chunk-RWBNLNQ6.mjs.map +0 -1
- package/dist/chunk-V4H3X4PI.mjs +0 -2
- package/dist/chunk-V4H3X4PI.mjs.map +0 -1
- package/dist/chunk-WOMA746Z.mjs +0 -2
- package/dist/chunk-WOMA746Z.mjs.map +0 -1
|
@@ -1,71 +1,90 @@
|
|
|
1
1
|
import BaseModel, { BaseAttributes } from './Base.mjs';
|
|
2
|
-
import {
|
|
3
|
-
import { GenderCategory } from './Enum.mjs';
|
|
2
|
+
import { e as Prettify, f as Color, c as LocalizedString, C as CountryCode, d as LocalizedValue, L as LocaleCode } from '../Common-FbQ5-3QN.mjs';
|
|
3
|
+
import { GenderCategory, ImageCategory } from './Enum.mjs';
|
|
4
4
|
import ImageInfoModel, { ImageInfoData } from './ImageInfo.mjs';
|
|
5
|
+
import { TieredPriceAttributes, TieredPriceModel } from './TieredPrice.mjs';
|
|
5
6
|
import '../Auth/index.mjs';
|
|
6
7
|
|
|
7
|
-
type
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
type ProductSelectionAttributes = Prettify<{
|
|
9
|
+
color: Color[];
|
|
10
|
+
size: string[];
|
|
11
|
+
} & {
|
|
12
|
+
[key: string]: string | string[] | Color[];
|
|
13
|
+
}>;
|
|
14
|
+
type SelectionAttributes = {
|
|
15
|
+
color: Color;
|
|
16
|
+
[key: string]: string | Color;
|
|
10
17
|
};
|
|
11
|
-
type
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
type VariantData = {
|
|
19
|
+
sku: string;
|
|
20
|
+
selectionAttributes: SelectionAttributes;
|
|
21
|
+
images: {
|
|
22
|
+
primary: ImageInfoData;
|
|
23
|
+
gallery: ImageInfoData[];
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
type VariantModel = {
|
|
27
|
+
sku: string;
|
|
28
|
+
selectionAttributes: SelectionAttributes;
|
|
29
|
+
images: {
|
|
30
|
+
primary: ImageInfoModel;
|
|
31
|
+
gallery: ImageInfoModel[];
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
type ProductSpecification = {
|
|
35
|
+
[key: string]: string | string[];
|
|
14
36
|
};
|
|
15
37
|
type ProductAttributes = BaseAttributes & {
|
|
16
38
|
id: string;
|
|
17
39
|
key: string;
|
|
18
|
-
variantId: string;
|
|
19
40
|
name: LocalizedString;
|
|
20
41
|
description: LocalizedString;
|
|
21
42
|
slug: LocalizedString;
|
|
22
43
|
brand: string;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
attributes: {
|
|
26
|
-
color: Color;
|
|
27
|
-
sizes: string[];
|
|
44
|
+
pricing: {
|
|
45
|
+
[country in CountryCode]?: TieredPriceAttributes;
|
|
28
46
|
};
|
|
29
|
-
primaryImage: ImageInfoData;
|
|
30
|
-
additionalImages?: ImageInfoData[];
|
|
31
|
-
isActive: boolean;
|
|
32
47
|
targetGender: GenderCategory;
|
|
48
|
+
attributes: ProductSelectionAttributes;
|
|
49
|
+
specifications: LocalizedValue<ProductSpecification>;
|
|
33
50
|
categories: string[];
|
|
34
|
-
|
|
35
|
-
|
|
51
|
+
variants: VariantData[];
|
|
52
|
+
isActive: boolean;
|
|
53
|
+
searchTags?: LocalizedValue<string[]>;
|
|
36
54
|
};
|
|
37
55
|
type ProductData = Required<ProductAttributes>;
|
|
38
|
-
type ProductSpecification = {
|
|
39
|
-
[key: string]: string | string[];
|
|
40
|
-
};
|
|
41
|
-
type LocalizedProductSpecification = {
|
|
42
|
-
en: ProductSpecification;
|
|
43
|
-
} & {
|
|
44
|
-
[locale in (LocaleCode | LanguageCode)]?: ProductSpecification;
|
|
45
|
-
};
|
|
46
56
|
declare class ProductModel extends BaseModel {
|
|
47
57
|
protected id: string;
|
|
48
58
|
protected key: string;
|
|
49
|
-
protected variantId: string;
|
|
50
59
|
protected name: LocalizedString;
|
|
51
60
|
protected description: LocalizedString;
|
|
52
61
|
protected slug: LocalizedString;
|
|
53
62
|
protected brand: string;
|
|
54
|
-
protected
|
|
55
|
-
|
|
56
|
-
protected attributes: {
|
|
57
|
-
color: Color;
|
|
58
|
-
sizes: string[];
|
|
63
|
+
protected pricing: {
|
|
64
|
+
[country in CountryCode]?: TieredPriceModel;
|
|
59
65
|
};
|
|
60
|
-
protected
|
|
61
|
-
protected additionalImages: ImageInfoModel[];
|
|
62
|
-
protected isActive: boolean;
|
|
66
|
+
protected variants: VariantModel[];
|
|
63
67
|
protected targetGender: GenderCategory;
|
|
68
|
+
protected attributes: ProductSelectionAttributes;
|
|
69
|
+
protected specifications: LocalizedValue<ProductSpecification>;
|
|
64
70
|
protected categories: string[];
|
|
65
|
-
protected
|
|
66
|
-
protected searchTags: string[]
|
|
71
|
+
protected isActive: boolean;
|
|
72
|
+
protected searchTags: LocalizedValue<string[]>;
|
|
67
73
|
static productKeyRegex: RegExp;
|
|
68
|
-
static
|
|
74
|
+
static productSKURegex: RegExp;
|
|
75
|
+
/**
|
|
76
|
+
* Generates a unique key for checking uniqueness for a given selection attributes.
|
|
77
|
+
* Excludes 'size' from the key generation.
|
|
78
|
+
* @param selectionAttributes - The selection attributes.
|
|
79
|
+
* @returns A string key representing the unique attribute combination.
|
|
80
|
+
*/
|
|
81
|
+
static generateSelectionAttributesKey(selectionAttributes: SelectionAttributes): string;
|
|
82
|
+
/**
|
|
83
|
+
* Parses a selection attributes key into an object.
|
|
84
|
+
* @param key - The selection attributes key to parse.
|
|
85
|
+
* @returns An object containing the parsed selection attributes.
|
|
86
|
+
*/
|
|
87
|
+
static parseSelectionAttributesKey(key: string): SelectionAttributes;
|
|
69
88
|
/**
|
|
70
89
|
* Creates an instance of ProductModel.
|
|
71
90
|
* Initializes properties based on the provided data, creating copies where necessary.
|
|
@@ -83,11 +102,6 @@ declare class ProductModel extends BaseModel {
|
|
|
83
102
|
* @returns Product Key.
|
|
84
103
|
*/
|
|
85
104
|
getKey(): string;
|
|
86
|
-
/**
|
|
87
|
-
* Gets the specific Variant ID.
|
|
88
|
-
* @returns Variant ID.
|
|
89
|
-
*/
|
|
90
|
-
getVariantId(): string;
|
|
91
105
|
/**
|
|
92
106
|
* Gets the full localized product name object.
|
|
93
107
|
* @returns A copy of the LocalizedString object for the name.
|
|
@@ -127,44 +141,42 @@ declare class ProductModel extends BaseModel {
|
|
|
127
141
|
*/
|
|
128
142
|
getBrand(): string;
|
|
129
143
|
/**
|
|
130
|
-
* Gets the
|
|
131
|
-
*
|
|
132
|
-
* If no country code is provided, it returns a list of all defined base prices across different countries.
|
|
133
|
-
* Returns copies of the price objects to prevent modification of internal state.
|
|
134
|
-
*
|
|
135
|
-
* @param country - Optional country code to retrieve the base price for a specific region.
|
|
144
|
+
* Gets the tiered price details for the product.
|
|
145
|
+
* @returns Pricing details mapped by country.
|
|
136
146
|
*/
|
|
137
|
-
|
|
138
|
-
|
|
147
|
+
getPriceDetails(): {
|
|
148
|
+
[country in CountryCode]?: TieredPriceModel;
|
|
149
|
+
};
|
|
139
150
|
/**
|
|
140
|
-
* Gets the
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
* @param country - Optional country code to filter the price tiers for a specific region.
|
|
145
|
-
* @returns A sorted list (by `minQuantity`) of applicable `PriceTier` objects. Returns an empty list if no tiers are defined or if none match the specified country.
|
|
151
|
+
* Gets the tiered price details for a specific country.
|
|
152
|
+
* @param country - The country code.
|
|
153
|
+
* @returns The tiered price model for the country, or null if not found.
|
|
146
154
|
*/
|
|
147
|
-
|
|
155
|
+
getPriceDetails(country: CountryCode): TieredPriceModel | null;
|
|
148
156
|
/**
|
|
149
157
|
* Gets the variant-specific attributes (color, sizes). Returns copies.
|
|
150
158
|
* @returns Product Attributes.
|
|
151
159
|
*/
|
|
152
|
-
getAttributes():
|
|
153
|
-
color: Color;
|
|
154
|
-
sizes: string[];
|
|
155
|
-
};
|
|
160
|
+
getAttributes(): ProductSelectionAttributes;
|
|
156
161
|
/**
|
|
157
|
-
* Gets
|
|
158
|
-
* @
|
|
162
|
+
* Gets the images for a specific selection attribute combination.
|
|
163
|
+
* @param selectionAttributes - The selection attributes to search for.
|
|
164
|
+
* @returns The matching image set or null if not found.
|
|
159
165
|
*/
|
|
160
|
-
|
|
166
|
+
private getImagesBySelectionAttributes;
|
|
161
167
|
/**
|
|
162
|
-
* Gets the
|
|
163
|
-
* @
|
|
168
|
+
* Gets the images for a specific selection attribute combination.
|
|
169
|
+
* @param selectionAttributes - The selection attributes to search for.
|
|
170
|
+
* @returns The matching image set or null if not found.
|
|
164
171
|
*/
|
|
165
|
-
|
|
172
|
+
getImages(selectionAttributes: SelectionAttributes): {
|
|
173
|
+
primary: ImageInfoModel;
|
|
174
|
+
gallery: ImageInfoModel[];
|
|
175
|
+
};
|
|
176
|
+
getImages(selectionAttributes: SelectionAttributes, category: ImageCategory.PRIMARY): ImageInfoModel;
|
|
177
|
+
getImages(selectionAttributes: SelectionAttributes, category: ImageCategory.GALLERY): ImageInfoModel[];
|
|
166
178
|
/**
|
|
167
|
-
* Checks if the product
|
|
179
|
+
* Checks if the product is active.
|
|
168
180
|
* @returns True if the product is active, false otherwise.
|
|
169
181
|
*/
|
|
170
182
|
getIsActive(): boolean;
|
|
@@ -182,7 +194,7 @@ declare class ProductModel extends BaseModel {
|
|
|
182
194
|
* Gets the full localized product specifications object.
|
|
183
195
|
* @returns Product Specifications
|
|
184
196
|
*/
|
|
185
|
-
getSpecifications():
|
|
197
|
+
getSpecifications(): LocalizedValue<ProductSpecification>;
|
|
186
198
|
/**
|
|
187
199
|
* Gets the product specifications for a specific locale, falling back to English ('en').
|
|
188
200
|
* @param locale - The desired locale code.
|
|
@@ -190,31 +202,33 @@ declare class ProductModel extends BaseModel {
|
|
|
190
202
|
*/
|
|
191
203
|
getSpecifications(locale: LocaleCode): ProductSpecification | undefined;
|
|
192
204
|
/**
|
|
193
|
-
* Gets the list of search tags. Returns a copy.
|
|
194
|
-
* @returns
|
|
205
|
+
* Gets the localized list of search tags. Returns a copy.
|
|
206
|
+
* @returns Localized array of search tags.
|
|
195
207
|
*/
|
|
196
|
-
getSearchTags(): string[]
|
|
208
|
+
getSearchTags(): LocalizedValue<string[]>;
|
|
209
|
+
/**
|
|
210
|
+
* Gets the search tags for a specific locale, falling back to English ('en').
|
|
211
|
+
* @param locale - The desired locale code.
|
|
212
|
+
* @returns The array of search tags for the specified locale, or undefined if not found.
|
|
213
|
+
*/
|
|
214
|
+
getSearchTags(locale: LocaleCode): string[] | undefined;
|
|
197
215
|
/**
|
|
198
216
|
*
|
|
199
217
|
* @returns ProductData
|
|
200
218
|
*/
|
|
201
219
|
getDetails(): ProductData;
|
|
202
220
|
/**
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* @
|
|
206
|
-
* @returns The maximum discount percentage (0-100), or 0 if calculation is not possible.
|
|
221
|
+
* Validates if the provided selection attributes exist for this product.
|
|
222
|
+
* @param selectionAttributes - The attributes to validate.
|
|
223
|
+
* @returns True if a valid selection attribute exists, false otherwise.
|
|
207
224
|
*/
|
|
208
|
-
|
|
225
|
+
validateSelectionAttribute(selectionAttributes: SelectionAttributes): boolean;
|
|
209
226
|
/**
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
* @param country - The country code for which to determine the minimum purchase quantity.
|
|
214
|
-
* @returns The minimum quantity required.
|
|
215
|
-
* @throws {Error} If no price tiers are defined for the specified country.
|
|
227
|
+
* Validates if a specific size is available for this product.
|
|
228
|
+
* @param size - The size to check.
|
|
229
|
+
* @returns True if the size exists in the product's attributes, false otherwise.
|
|
216
230
|
*/
|
|
217
|
-
|
|
231
|
+
validateSize(size: string): boolean;
|
|
218
232
|
}
|
|
219
233
|
|
|
220
|
-
export { type
|
|
234
|
+
export { type ProductAttributes, type ProductData, type ProductSelectionAttributes, type ProductSpecification, type SelectionAttributes, type VariantData, type VariantModel, ProductModel as default };
|
|
@@ -1,71 +1,90 @@
|
|
|
1
1
|
import BaseModel, { BaseAttributes } from './Base.js';
|
|
2
|
-
import {
|
|
3
|
-
import { GenderCategory } from './Enum.js';
|
|
2
|
+
import { e as Prettify, f as Color, c as LocalizedString, C as CountryCode, d as LocalizedValue, L as LocaleCode } from '../Common-D-UoxwM0.js';
|
|
3
|
+
import { GenderCategory, ImageCategory } from './Enum.js';
|
|
4
4
|
import ImageInfoModel, { ImageInfoData } from './ImageInfo.js';
|
|
5
|
+
import { TieredPriceAttributes, TieredPriceModel } from './TieredPrice.js';
|
|
5
6
|
import '../Auth/index.js';
|
|
6
7
|
|
|
7
|
-
type
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
type ProductSelectionAttributes = Prettify<{
|
|
9
|
+
color: Color[];
|
|
10
|
+
size: string[];
|
|
11
|
+
} & {
|
|
12
|
+
[key: string]: string | string[] | Color[];
|
|
13
|
+
}>;
|
|
14
|
+
type SelectionAttributes = {
|
|
15
|
+
color: Color;
|
|
16
|
+
[key: string]: string | Color;
|
|
10
17
|
};
|
|
11
|
-
type
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
type VariantData = {
|
|
19
|
+
sku: string;
|
|
20
|
+
selectionAttributes: SelectionAttributes;
|
|
21
|
+
images: {
|
|
22
|
+
primary: ImageInfoData;
|
|
23
|
+
gallery: ImageInfoData[];
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
type VariantModel = {
|
|
27
|
+
sku: string;
|
|
28
|
+
selectionAttributes: SelectionAttributes;
|
|
29
|
+
images: {
|
|
30
|
+
primary: ImageInfoModel;
|
|
31
|
+
gallery: ImageInfoModel[];
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
type ProductSpecification = {
|
|
35
|
+
[key: string]: string | string[];
|
|
14
36
|
};
|
|
15
37
|
type ProductAttributes = BaseAttributes & {
|
|
16
38
|
id: string;
|
|
17
39
|
key: string;
|
|
18
|
-
variantId: string;
|
|
19
40
|
name: LocalizedString;
|
|
20
41
|
description: LocalizedString;
|
|
21
42
|
slug: LocalizedString;
|
|
22
43
|
brand: string;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
attributes: {
|
|
26
|
-
color: Color;
|
|
27
|
-
sizes: string[];
|
|
44
|
+
pricing: {
|
|
45
|
+
[country in CountryCode]?: TieredPriceAttributes;
|
|
28
46
|
};
|
|
29
|
-
primaryImage: ImageInfoData;
|
|
30
|
-
additionalImages?: ImageInfoData[];
|
|
31
|
-
isActive: boolean;
|
|
32
47
|
targetGender: GenderCategory;
|
|
48
|
+
attributes: ProductSelectionAttributes;
|
|
49
|
+
specifications: LocalizedValue<ProductSpecification>;
|
|
33
50
|
categories: string[];
|
|
34
|
-
|
|
35
|
-
|
|
51
|
+
variants: VariantData[];
|
|
52
|
+
isActive: boolean;
|
|
53
|
+
searchTags?: LocalizedValue<string[]>;
|
|
36
54
|
};
|
|
37
55
|
type ProductData = Required<ProductAttributes>;
|
|
38
|
-
type ProductSpecification = {
|
|
39
|
-
[key: string]: string | string[];
|
|
40
|
-
};
|
|
41
|
-
type LocalizedProductSpecification = {
|
|
42
|
-
en: ProductSpecification;
|
|
43
|
-
} & {
|
|
44
|
-
[locale in (LocaleCode | LanguageCode)]?: ProductSpecification;
|
|
45
|
-
};
|
|
46
56
|
declare class ProductModel extends BaseModel {
|
|
47
57
|
protected id: string;
|
|
48
58
|
protected key: string;
|
|
49
|
-
protected variantId: string;
|
|
50
59
|
protected name: LocalizedString;
|
|
51
60
|
protected description: LocalizedString;
|
|
52
61
|
protected slug: LocalizedString;
|
|
53
62
|
protected brand: string;
|
|
54
|
-
protected
|
|
55
|
-
|
|
56
|
-
protected attributes: {
|
|
57
|
-
color: Color;
|
|
58
|
-
sizes: string[];
|
|
63
|
+
protected pricing: {
|
|
64
|
+
[country in CountryCode]?: TieredPriceModel;
|
|
59
65
|
};
|
|
60
|
-
protected
|
|
61
|
-
protected additionalImages: ImageInfoModel[];
|
|
62
|
-
protected isActive: boolean;
|
|
66
|
+
protected variants: VariantModel[];
|
|
63
67
|
protected targetGender: GenderCategory;
|
|
68
|
+
protected attributes: ProductSelectionAttributes;
|
|
69
|
+
protected specifications: LocalizedValue<ProductSpecification>;
|
|
64
70
|
protected categories: string[];
|
|
65
|
-
protected
|
|
66
|
-
protected searchTags: string[]
|
|
71
|
+
protected isActive: boolean;
|
|
72
|
+
protected searchTags: LocalizedValue<string[]>;
|
|
67
73
|
static productKeyRegex: RegExp;
|
|
68
|
-
static
|
|
74
|
+
static productSKURegex: RegExp;
|
|
75
|
+
/**
|
|
76
|
+
* Generates a unique key for checking uniqueness for a given selection attributes.
|
|
77
|
+
* Excludes 'size' from the key generation.
|
|
78
|
+
* @param selectionAttributes - The selection attributes.
|
|
79
|
+
* @returns A string key representing the unique attribute combination.
|
|
80
|
+
*/
|
|
81
|
+
static generateSelectionAttributesKey(selectionAttributes: SelectionAttributes): string;
|
|
82
|
+
/**
|
|
83
|
+
* Parses a selection attributes key into an object.
|
|
84
|
+
* @param key - The selection attributes key to parse.
|
|
85
|
+
* @returns An object containing the parsed selection attributes.
|
|
86
|
+
*/
|
|
87
|
+
static parseSelectionAttributesKey(key: string): SelectionAttributes;
|
|
69
88
|
/**
|
|
70
89
|
* Creates an instance of ProductModel.
|
|
71
90
|
* Initializes properties based on the provided data, creating copies where necessary.
|
|
@@ -83,11 +102,6 @@ declare class ProductModel extends BaseModel {
|
|
|
83
102
|
* @returns Product Key.
|
|
84
103
|
*/
|
|
85
104
|
getKey(): string;
|
|
86
|
-
/**
|
|
87
|
-
* Gets the specific Variant ID.
|
|
88
|
-
* @returns Variant ID.
|
|
89
|
-
*/
|
|
90
|
-
getVariantId(): string;
|
|
91
105
|
/**
|
|
92
106
|
* Gets the full localized product name object.
|
|
93
107
|
* @returns A copy of the LocalizedString object for the name.
|
|
@@ -127,44 +141,42 @@ declare class ProductModel extends BaseModel {
|
|
|
127
141
|
*/
|
|
128
142
|
getBrand(): string;
|
|
129
143
|
/**
|
|
130
|
-
* Gets the
|
|
131
|
-
*
|
|
132
|
-
* If no country code is provided, it returns a list of all defined base prices across different countries.
|
|
133
|
-
* Returns copies of the price objects to prevent modification of internal state.
|
|
134
|
-
*
|
|
135
|
-
* @param country - Optional country code to retrieve the base price for a specific region.
|
|
144
|
+
* Gets the tiered price details for the product.
|
|
145
|
+
* @returns Pricing details mapped by country.
|
|
136
146
|
*/
|
|
137
|
-
|
|
138
|
-
|
|
147
|
+
getPriceDetails(): {
|
|
148
|
+
[country in CountryCode]?: TieredPriceModel;
|
|
149
|
+
};
|
|
139
150
|
/**
|
|
140
|
-
* Gets the
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
* @param country - Optional country code to filter the price tiers for a specific region.
|
|
145
|
-
* @returns A sorted list (by `minQuantity`) of applicable `PriceTier` objects. Returns an empty list if no tiers are defined or if none match the specified country.
|
|
151
|
+
* Gets the tiered price details for a specific country.
|
|
152
|
+
* @param country - The country code.
|
|
153
|
+
* @returns The tiered price model for the country, or null if not found.
|
|
146
154
|
*/
|
|
147
|
-
|
|
155
|
+
getPriceDetails(country: CountryCode): TieredPriceModel | null;
|
|
148
156
|
/**
|
|
149
157
|
* Gets the variant-specific attributes (color, sizes). Returns copies.
|
|
150
158
|
* @returns Product Attributes.
|
|
151
159
|
*/
|
|
152
|
-
getAttributes():
|
|
153
|
-
color: Color;
|
|
154
|
-
sizes: string[];
|
|
155
|
-
};
|
|
160
|
+
getAttributes(): ProductSelectionAttributes;
|
|
156
161
|
/**
|
|
157
|
-
* Gets
|
|
158
|
-
* @
|
|
162
|
+
* Gets the images for a specific selection attribute combination.
|
|
163
|
+
* @param selectionAttributes - The selection attributes to search for.
|
|
164
|
+
* @returns The matching image set or null if not found.
|
|
159
165
|
*/
|
|
160
|
-
|
|
166
|
+
private getImagesBySelectionAttributes;
|
|
161
167
|
/**
|
|
162
|
-
* Gets the
|
|
163
|
-
* @
|
|
168
|
+
* Gets the images for a specific selection attribute combination.
|
|
169
|
+
* @param selectionAttributes - The selection attributes to search for.
|
|
170
|
+
* @returns The matching image set or null if not found.
|
|
164
171
|
*/
|
|
165
|
-
|
|
172
|
+
getImages(selectionAttributes: SelectionAttributes): {
|
|
173
|
+
primary: ImageInfoModel;
|
|
174
|
+
gallery: ImageInfoModel[];
|
|
175
|
+
};
|
|
176
|
+
getImages(selectionAttributes: SelectionAttributes, category: ImageCategory.PRIMARY): ImageInfoModel;
|
|
177
|
+
getImages(selectionAttributes: SelectionAttributes, category: ImageCategory.GALLERY): ImageInfoModel[];
|
|
166
178
|
/**
|
|
167
|
-
* Checks if the product
|
|
179
|
+
* Checks if the product is active.
|
|
168
180
|
* @returns True if the product is active, false otherwise.
|
|
169
181
|
*/
|
|
170
182
|
getIsActive(): boolean;
|
|
@@ -182,7 +194,7 @@ declare class ProductModel extends BaseModel {
|
|
|
182
194
|
* Gets the full localized product specifications object.
|
|
183
195
|
* @returns Product Specifications
|
|
184
196
|
*/
|
|
185
|
-
getSpecifications():
|
|
197
|
+
getSpecifications(): LocalizedValue<ProductSpecification>;
|
|
186
198
|
/**
|
|
187
199
|
* Gets the product specifications for a specific locale, falling back to English ('en').
|
|
188
200
|
* @param locale - The desired locale code.
|
|
@@ -190,31 +202,33 @@ declare class ProductModel extends BaseModel {
|
|
|
190
202
|
*/
|
|
191
203
|
getSpecifications(locale: LocaleCode): ProductSpecification | undefined;
|
|
192
204
|
/**
|
|
193
|
-
* Gets the list of search tags. Returns a copy.
|
|
194
|
-
* @returns
|
|
205
|
+
* Gets the localized list of search tags. Returns a copy.
|
|
206
|
+
* @returns Localized array of search tags.
|
|
195
207
|
*/
|
|
196
|
-
getSearchTags(): string[]
|
|
208
|
+
getSearchTags(): LocalizedValue<string[]>;
|
|
209
|
+
/**
|
|
210
|
+
* Gets the search tags for a specific locale, falling back to English ('en').
|
|
211
|
+
* @param locale - The desired locale code.
|
|
212
|
+
* @returns The array of search tags for the specified locale, or undefined if not found.
|
|
213
|
+
*/
|
|
214
|
+
getSearchTags(locale: LocaleCode): string[] | undefined;
|
|
197
215
|
/**
|
|
198
216
|
*
|
|
199
217
|
* @returns ProductData
|
|
200
218
|
*/
|
|
201
219
|
getDetails(): ProductData;
|
|
202
220
|
/**
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* @
|
|
206
|
-
* @returns The maximum discount percentage (0-100), or 0 if calculation is not possible.
|
|
221
|
+
* Validates if the provided selection attributes exist for this product.
|
|
222
|
+
* @param selectionAttributes - The attributes to validate.
|
|
223
|
+
* @returns True if a valid selection attribute exists, false otherwise.
|
|
207
224
|
*/
|
|
208
|
-
|
|
225
|
+
validateSelectionAttribute(selectionAttributes: SelectionAttributes): boolean;
|
|
209
226
|
/**
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
* @param country - The country code for which to determine the minimum purchase quantity.
|
|
214
|
-
* @returns The minimum quantity required.
|
|
215
|
-
* @throws {Error} If no price tiers are defined for the specified country.
|
|
227
|
+
* Validates if a specific size is available for this product.
|
|
228
|
+
* @param size - The size to check.
|
|
229
|
+
* @returns True if the size exists in the product's attributes, false otherwise.
|
|
216
230
|
*/
|
|
217
|
-
|
|
231
|
+
validateSize(size: string): boolean;
|
|
218
232
|
}
|
|
219
233
|
|
|
220
|
-
export { type
|
|
234
|
+
export { type ProductAttributes, type ProductData, type ProductSelectionAttributes, type ProductSpecification, type SelectionAttributes, type VariantData, type VariantModel, ProductModel as default };
|
package/dist/Classes/Product.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var n=class{customFields;version;createdAt;modifiedAt;modifiedBy;constructor(e,t=new Date){this.customFields={...e.customFields},this.version=e.version??1,this.createdAt=e.createdAt&&!isNaN(Date.parse(e.createdAt))?new Date(e.createdAt).toISOString():t.toISOString(),this.modifiedAt=e.modifiedAt&&!isNaN(Date.parse(e.modifiedAt))?new Date(e.modifiedAt).toISOString():t.toISOString(),this.modifiedBy={...e.modifiedBy};}getDetails(){return {customFields:this.getAllCustomFields(),version:this.getVersion(),createdAt:this.getCreatedAt(),modifiedAt:this.getModifiedAt(),modifiedBy:this.getModifiedBy()}}getVersion(){return this.version}getCreatedAt(){return this.createdAt}getCreatedAtTime(){return new Date(this.createdAt).getTime()}getModifiedAt(){return this.modifiedAt}getModifiedAtTime(){return new Date(this.modifiedAt).getTime()}getModifiedBy(){return {...this.modifiedBy}}setModifiedBy(e,t,i,a){this.modifiedBy={id:e,authType:t,requestId:i,lambdaName:a};}getCustomField(e){return this.customFields[e]??null}setCustomField(e,t){this.customFields[e]=t;}getAllCustomFields(){return {...this.customFields}}};var o={"en-IN":"en","kn-IN":"kn"};var r=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 "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 "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 d=class extends n{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,t=new Date){super(e,t),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(i=>({...i})),this.priceTiers=e.priceTiers?e.priceTiers.map(i=>({...i})):e.basePrices.map(i=>({...i})),this.attributes={...e.attributes,sizes:[...e.attributes.sizes]},this.primaryImage=new r(e.primaryImage),this.additionalImages=(e.additionalImages||[]).map(i=>new r(i)),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[o[e]]??this.name.en:{...this.name}}getDescription(e){return e?this.description[e]??this.description[o[e]]??this.description.en:{...this.description}}getSlug(e){return e?this.slug[e]??this.slug[o[e]]??this.slug.en:{...this.slug}}getBrand(){return this.brand}getBasePrices(e){if(e){let t=this.basePrices.find(i=>i.country===e);return t?{...t}:null}return this.basePrices.map(t=>({...t}))}getPriceTiers(e){return (e?this.priceTiers.filter(i=>i.country===e):this.priceTiers).map(i=>({...i})).sort((i,a)=>i.minQuantity-a.minQuantity)}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[o[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(t=>t.getDetails()),isActive:this.getIsActive(),targetGender:this.getTargetGender(),categories:this.getCategories(),specifications:this.getSpecifications(),searchTags:this.getSearchTags(),...e}}getMaxDiscountPercent(e){let t=this.basePrices.find(s=>s.country===e),i=this.priceTiers?.filter(s=>s.country===e).sort((s,u)=>s.unitPrice-u.unitPrice)[0]?.unitPrice;return !t||t.unitPrice<=0||i===void 0?0:Math.max(0,t.unitPrice-i)/t.unitPrice*100}getMinQuantity(e){let t=this.getPriceTiers(e);if(t.length===0)throw Error("No price tiers found for country");return t[0].minQuantity}};module.exports=d;//# sourceMappingURL=Product.js.map
|
|
1
|
+
'use strict';var Y=require('crypto');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Y__default=/*#__PURE__*/_interopDefault(Y);var D=new Uint8Array(256),S=D.length;function U(){return S>D.length-16&&(Y__default.default.randomFillSync(D),S=0),D.slice(S,S+=16)}var B=/^(?:[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 H(t){return typeof t=="string"&&B.test(t)}var k=H;var a=[];for(let t=0;t<256;++t)a.push((t+256).toString(16).slice(1));function T(t,e=0){return a[t[e+0]]+a[t[e+1]]+a[t[e+2]]+a[t[e+3]]+"-"+a[t[e+4]]+a[t[e+5]]+"-"+a[t[e+6]]+a[t[e+7]]+"-"+a[t[e+8]]+a[t[e+9]]+"-"+a[t[e+10]]+a[t[e+11]]+a[t[e+12]]+a[t[e+13]]+a[t[e+14]]+a[t[e+15]]}function Z(t){if(!k(t))throw TypeError("Invalid UUID");let e,r=new Uint8Array(16);return r[0]=(e=parseInt(t.slice(0,8),16))>>>24,r[1]=e>>>16&255,r[2]=e>>>8&255,r[3]=e&255,r[4]=(e=parseInt(t.slice(9,13),16))>>>8,r[5]=e&255,r[6]=(e=parseInt(t.slice(14,18),16))>>>8,r[7]=e&255,r[8]=(e=parseInt(t.slice(19,23),16))>>>8,r[9]=e&255,r[10]=(e=parseInt(t.slice(24,36),16))/1099511627776&255,r[11]=e/4294967296&255,r[12]=e>>>24&255,r[13]=e>>>16&255,r[14]=e>>>8&255,r[15]=e&255,r}var Q=Z;function q(t){t=unescape(encodeURIComponent(t));let e=[];for(let r=0;r<t.length;++r)e.push(t.charCodeAt(r));return e}var j="6ba7b810-9dad-11d1-80b4-00c04fd430c8",X="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function O(t,e,r){function i(n,o,d,p){var c;if(typeof n=="string"&&(n=q(n)),typeof o=="string"&&(o=Q(o)),((c=o)===null||c===void 0?void 0:c.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let u=new Uint8Array(16+n.length);if(u.set(o),u.set(n,o.length),u=r(u),u[6]=u[6]&15|e,u[8]=u[8]&63|128,d){p=p||0;for(let P=0;P<16;++P)d[p+P]=u[P];return d}return T(u)}try{i.name=t;}catch{}return i.DNS=j,i.URL=X,i}var $={randomUUID:Y__default.default.randomUUID};function J(t,e,r){if($.randomUUID&&!e&&!t)return $.randomUUID();t=t||{};let i=t.random||(t.rng||U)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,e){r=r||0;for(let n=0;n<16;++n)e[r+n]=i[n];return e}return T(i)}var F=J;function ee(t){return Array.isArray(t)?t=Buffer.from(t):typeof t=="string"&&(t=Buffer.from(t,"utf8")),Y__default.default.createHash("sha1").update(t).digest()}var G=ee;var te=O("v5",80,G),z=te;var re={isUUID:t=>/^[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(t),isEmail:t=>/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(t),isURL:t=>/^(http|https):\/\/[^ "]+$/.test(t),generateUUID:(t,e)=>e&&t?z(t,e):F(),generateSearchId:(t,e)=>`${t}#${A.generateSelectionAttributesKey(e)}`,getKeyfromSearchId:t=>{let[e,r]=t.split("#");return {key:e,selectionAttribute:r}},deepClone(t){return structuredClone(t)}},l=re;var I=class{customFields;version;createdAt;modifiedAt;modifiedBy;constructor(e,r=new Date){this.customFields={...e.customFields},this.version=e.version??1,this.createdAt=e.createdAt&&!isNaN(Date.parse(e.createdAt))?new Date(e.createdAt).toISOString():r.toISOString(),this.modifiedAt=e.modifiedAt&&!isNaN(Date.parse(e.modifiedAt))?new Date(e.modifiedAt).toISOString():r.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,r,i,n){this.modifiedBy={id:e,authType:r,requestId:i,lambdaName:n};}getCustomField(e){return this.customFields[e]??null}setCustomField(e,r){this.customFields[e]=r;}getAllCustomFields(){return {...this.customFields}}};var h={"en-IN":"en","kn-IN":"kn"};var V={INR:"\u20B9"},K={INR:"en-IN"};var w=class extends Error{constructor(e="Failed to parse selection attributes key."){super(`SelectionAttributeParseError: ${e}`),this.name="SelectionAttributeParseError";}};var M=class extends Error{constructor(e="Tax category is not valid."){super(`InvalidTaxCategory: ${e}`),this.name="InvalidTaxCategoryError";}},E=class extends Error{constructor(e="Minimum quantity must be greater than zero."){super(`InvalidMinQuantity: ${e}`),this.name="InvalidMinQuantityError";}},v=class extends Error{constructor(e){super(`InvalidTieredPrice: ${e}`),this.name="InvalidTieredPriceError";}},L=class extends Error{constructor(e="Quantity must be greater than zero."){super(`InvalidQuantity: ${e}`),this.name="InvalidQuantityError";}},R=class extends Error{constructor(e){super(`NoApplicableTier: Quantity ${e} does not meet the minimum purchase requirement.`),this.name="NoApplicableTierError";}};var C=class extends Error{constructor(e="Amount cannot be negative."){super(`InvalidAmount: ${e}`),this.name="InvalidPriceAmountError";}},f=class extends Error{constructor(e="Currency code is required."){super(`InvalidCurrency: ${e}`),this.name="InvalidCurrencyCodeError";}},m=class extends Error{constructor(e="Cannot perform operation on prices with different currencies."){super(`CurrencyMismatch: ${e}`),this.name="CurrencyMismatchError";}},g=class extends Error{constructor(e){super(`InvalidArgument: ${e}`),this.name="InvalidArgumentError";}},x=class extends Error{constructor(e="Invalid image source configuration."){super(`InvalidImageSource: ${e}`),this.name="InvalidImageSourceError";}};var y=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 x("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,r){if(r===void 0){if(e==="original")throw new x("Cannot remove the 'original' image source.");delete this.sources[e];}else this.sources[e]=r;}getDetails(){return {sources:this.getSources(),alt:this.getAlt(),order:this.getOrder(),label:this.getLabel()}}};var b=class t{amount;currency;constructor(e){if(e.amount<0)throw new C("Amount cannot be negative.");if(!e.currency)throw new f("Currency code is required.");this.amount=e.amount,this.currency=e.currency;}getCurrency(){return this.currency}getAmount(){return this.amount}getDetails(){return {amount:this.amount,currency:this.currency}}compareTo(e){if(e instanceof t){if(this.currency!==e.getCurrency())throw new m("Cannot compare prices in different currencies.")}else throw new g("Must be a PriceModel instance.");return this.amount-e.getAmount()}add(e){if(e instanceof t){if(this.currency!==e.getCurrency())throw new m("Cannot add prices in different currencies.")}else throw new g("Must be a PriceModel instance.");return new t({amount:this.amount+e.getAmount(),currency:this.currency})}subtract(e){if(e instanceof t){if(this.currency!==e.getCurrency())throw new m("Cannot subtract prices in different currencies.")}else throw new g("Must be a PriceModel instance.");return new t({amount:this.amount-e.getAmount(),currency:this.currency})}multiply(e){if(e instanceof t){if(this.currency!==e.getCurrency())throw new m("Cannot multiply prices in different currencies.");return new t({amount:this.amount*e.getAmount(),currency:this.currency})}else if(typeof e=="number"&&e>=0)return new t({amount:this.amount*e,currency:this.currency});throw new g("Must be a non-negative number.")}divide(e){if(e instanceof t){if(this.currency!==e.getCurrency())throw new m("Cannot divide prices in different currencies.");return new t({amount:this.amount/e.getAmount(),currency:this.currency})}else if(typeof e=="number"&&e>0)return new t({amount:this.amount/e,currency:this.currency});throw new g("Must be a positive number.")}min(...e){if(e.length===0)throw new g("Must provide at least one PriceModel.");return e.reduce((r,i)=>{if(i instanceof t){if(r.getCurrency()!==i.getCurrency())throw new m("Cannot compare prices in different currencies.")}else throw new g("Must be a PriceModel instance.");return r.compareTo(i)<0?r:i})}max(...e){if(e.length===0)throw new g("Must provide at least one PriceModel.");return e.reduce((r,i)=>{if(i instanceof t){if(r.getCurrency()!==i.getCurrency())throw new m("Cannot compare prices in different currencies.")}else throw new g("Must be a PriceModel instance.");return r.compareTo(i)>0?r:i})}zero(){return new t({currency:this.currency,amount:0})}isZero(){return this.amount===0}round(){return new t({currency:this.currency,amount:this.getRoundedAmount()})}getRoundedAmount(){return t.getRoundedAmount(this.amount,this.currency)}getFormattedString(){return t.getFormattedString(this.amount,this.currency)}static getFormattedString(e,r,i={displayAsInteger:!1,style:"currency",currencyDisplay:"symbol"}){let n=K[r];if(!r||!n)throw new f("Invalid currency code for formatting.");let o=e,d=i.displayAsInteger?0:t.getDecimalPlaces(r),p={style:i.style??"currency",currency:r,signDisplay:"never",currencyDisplay:i.currencyDisplay,minimumFractionDigits:d,maximumFractionDigits:d};i.displayAsInteger&&(o=Math.ceil(o));try{return new Intl.NumberFormat(n,p).format(o)}catch(c){return console.error(`Error formatting price for currency "${r}" and locale "${n}":`,c),`${V[r]??r} ${t.addThousandSeparators(o.toFixed(d))}`}}static getDecimalPlaces(e){switch(e){case"INR":default:return 2}}static addThousandSeparators(e){let r=e.split("."),i=r[0],n=r.length>1?"."+r[1]:"";return i.replace(/\B(?=(\d{3})+(?!\d))/g,",")+n}static getRoundedAmount(e,r){if(e<0)throw new C("Amount cannot be negative for rounding.");if(r===void 0)throw new f("Invalid currency code for rounding.");let i=t.getDecimalPlaces(r),n=Math.pow(10,i);return Math.round(e*n)/n}};var N=class{baseUnitPrice;taxCategory;tiers;constructor(e){let r=new b(e.baseUnitPrice);if(!e.taxCategory)throw new M;let i=(e.tiers??[]).map(c=>({minQuantity:c.minQuantity,unitPrice:new b(c.unitPrice)})).sort((c,u)=>c.minQuantity-u.minQuantity);if(i.some(c=>c.minQuantity<=0))throw new E;let o=i.some(c=>c.unitPrice.getCurrency()!==r.getCurrency()),d=i.some((c,u)=>u>0&&c.unitPrice.compareTo(i[u-1].unitPrice)>0),p=i[0]?.unitPrice.compareTo(r)>0;if(o||d||p)throw new v("Tiers must share the same currency and must not increase in unit price.");this.baseUnitPrice=r,this.taxCategory=e.taxCategory,this.tiers=i;}getBaseUnitPrice(){return this.baseUnitPrice}getTaxCategory(){return this.taxCategory}getTiers(){return this.tiers}getDetails(){return {baseUnitPrice:this.baseUnitPrice.getDetails(),taxCategory:this.taxCategory,tiers:this.tiers.map(e=>({minQuantity:e.minQuantity,unitPrice:e.unitPrice.getDetails()}))}}getApplicableTier(e){if(e<=0)throw new L;for(let r=this.tiers.length-1;r>=0;r--)if(e>=this.tiers[r].minQuantity)return this.tiers[r];throw new R(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(),r=this.baseUnitPrice.getAmount();return (r-e)/r*100}};var A=class t extends I{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){return Object.keys(e).filter(i=>e[i]!==void 0&&i.toLowerCase()!=="size").sort().map(i=>e[i].name?`${i}:c+${e[i].name}`:`${i}:${e[i]}`).join("|")}static parseSelectionAttributesKey(e){try{let r={},i=e.split("|");for(let n of i){let[o,d]=n.split(":");d.startsWith("c+")?r[o]={name:d.slice(2)}:r[o]=d;}return r}catch(r){throw new w(r?.message)}}constructor(e,r=new Date){super(e,r),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((i,n)=>(e.pricing[n]&&(i[n]=new N(e.pricing[n])),i),{}),this.targetGender=e.targetGender,this.attributes=l.deepClone(e.attributes),this.specifications=l.deepClone(e.specifications),this.categories=l.deepClone(e.categories),this.variants=(e.variants||[]).map(i=>({sku:i.sku,selectionAttributes:i.selectionAttributes,images:{primary:new y(i.images.primary),gallery:(i.images.gallery||[]).map(n=>new y(n))}})),this.isActive=e.isActive,this.searchTags=e.searchTags?l.deepClone(e.searchTags):{en:[]};}getId(){return this.id}getKey(){return this.key}getName(e){return e?this.name[e]??this.name[h[e]]??this.name.en:l.deepClone(this.name)}getDescription(e){return e?this.description[e]??this.description[h[e]]??this.description.en:l.deepClone(this.description)}getSlug(e){return e?this.slug[e]??this.slug[h[e]]??this.slug.en:l.deepClone(this.slug)}getBrand(){return this.brand}getPriceDetails(e){return e?this.pricing[e]??null:this.pricing}getAttributes(){return l.deepClone(this.attributes)}getImagesBySelectionAttributes(e){let r=t.generateSelectionAttributesKey(e),i=this.variants.find(n=>t.generateSelectionAttributesKey(n.selectionAttributes)===r);return i?i.images:null}getImages(e,r){switch(r){case"PRIMARY":return this.getImagesBySelectionAttributes(e)?.primary??this.variants[0]?.images?.primary;case"GALLERY":return this.getImagesBySelectionAttributes(e)?.gallery??[];default:return this.getImagesBySelectionAttributes(e)??{primary:this.variants[0]?.images?.primary,gallery:[]}}}getIsActive(){return this.isActive}getTargetGender(){return this.targetGender}getCategories(){return l.deepClone(this.categories)}getSpecifications(e){return e?l.deepClone(this.specifications[e]??this.specifications[h[e]]??this.specifications.en):l.deepClone(this.specifications)}getSearchTags(e){return e?l.deepClone(this.searchTags[e]??this.searchTags[h[e]]??this.searchTags.en):l.deepClone(this.searchTags)}getDetails(){let e=super.getDetails();return {id:this.getId(),key:this.getKey(),name:this.getName(),description:this.getDescription(),slug:this.getSlug(),brand:this.getBrand(),pricing:Object.keys(this.pricing).reduce((r,i)=>(this.pricing[i]&&(r[i]=this.pricing[i]?.getDetails()),r),{}),attributes:this.getAttributes(),variants:this.variants.map(r=>({sku:r.sku,selectionAttributes:l.deepClone(r.selectionAttributes),images:{primary:r.images.primary.getDetails(),gallery:r.images.gallery.map(i=>i.getDetails())}})),isActive:this.getIsActive(),targetGender:this.getTargetGender(),categories:this.getCategories(),specifications:this.getSpecifications(),searchTags:this.getSearchTags(),...e}}validateSelectionAttribute(e){let r=t.generateSelectionAttributesKey(e);return this.variants.some(i=>t.generateSelectionAttributesKey(i.selectionAttributes)===r)}validateSize(e){return this.attributes.size.includes(e)}};module.exports=A;//# sourceMappingURL=Product.js.map
|
|
2
2
|
//# sourceMappingURL=Product.js.map
|