b23-lib 3.8.0 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Auth/index.js +1 -1
- package/dist/Auth/index.js.map +1 -1
- package/dist/Auth/index.mjs +1 -1
- package/dist/Auth/index.mjs.map +1 -1
- package/dist/Classes/Cart.d.mts +1 -2
- package/dist/Classes/Cart.d.ts +1 -2
- 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/Charge.js +1 -1
- package/dist/Classes/Charge.js.map +1 -1
- package/dist/Classes/Charge.mjs +1 -1
- 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/Error.d.mts +4 -1
- package/dist/Classes/Error.d.ts +4 -1
- package/dist/Classes/Error.js +1 -1
- package/dist/Classes/Error.js.map +1 -1
- package/dist/Classes/Error.mjs +1 -1
- package/dist/Classes/ImageInfo.js.map +1 -1
- package/dist/Classes/ImageInfo.mjs +1 -1
- package/dist/Classes/Inventory.d.mts +1 -2
- package/dist/Classes/Inventory.d.ts +1 -2
- 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/Invoice.d.mts +1 -2
- package/dist/Classes/Invoice.d.ts +1 -2
- package/dist/Classes/Invoice.js.map +1 -1
- package/dist/Classes/Invoice.mjs +1 -1
- package/dist/Classes/LineItem.d.mts +1 -2
- package/dist/Classes/LineItem.d.ts +1 -2
- 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 +1 -2
- package/dist/Classes/Order.d.ts +1 -2
- 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/Price.js.map +1 -1
- package/dist/Classes/Price.mjs +1 -1
- package/dist/Classes/Product.d.mts +5 -257
- package/dist/Classes/Product.d.ts +5 -257
- package/dist/Classes/Product.js +1 -1
- package/dist/Classes/Product.js.map +1 -1
- package/dist/Classes/Product.mjs +1 -1
- package/dist/Classes/ShoppingContainer.d.mts +1 -2
- package/dist/Classes/ShoppingContainer.d.ts +1 -2
- 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.js +1 -1
- package/dist/Classes/TaxRule.js.map +1 -1
- package/dist/Classes/TaxRule.mjs +1 -1
- package/dist/Classes/TieredPrice.d.mts +5 -81
- package/dist/Classes/TieredPrice.d.ts +5 -81
- package/dist/Classes/TieredPrice.js +1 -1
- package/dist/Classes/TieredPrice.js.map +1 -1
- package/dist/Classes/TieredPrice.mjs +1 -1
- package/dist/Product-BywRotdH.d.mts +367 -0
- package/dist/Product-mtVUKzNI.d.ts +367 -0
- package/dist/chunk-4QU5WW6U.mjs +2 -0
- package/dist/chunk-4QU5WW6U.mjs.map +1 -0
- package/dist/chunk-7B5TAYNA.mjs +2 -0
- package/dist/chunk-7B5TAYNA.mjs.map +1 -0
- package/dist/{chunk-2B2XI6FG.mjs → chunk-7RAIVZKB.mjs} +2 -2
- package/dist/{chunk-2B2XI6FG.mjs.map → chunk-7RAIVZKB.mjs.map} +1 -1
- package/dist/{chunk-C3METQSR.mjs → chunk-EZ35IKUA.mjs} +2 -2
- package/dist/{chunk-C3METQSR.mjs.map → chunk-EZ35IKUA.mjs.map} +1 -1
- package/dist/{chunk-TU4HOP63.mjs → chunk-MPKIC2MS.mjs} +2 -2
- package/dist/{chunk-TU4HOP63.mjs.map → chunk-MPKIC2MS.mjs.map} +1 -1
- package/dist/{chunk-R5DM7WCD.mjs → chunk-O6BLQQO7.mjs} +2 -2
- package/dist/chunk-O6BLQQO7.mjs.map +1 -0
- package/dist/chunk-PNTRHKEH.mjs +2 -0
- package/dist/chunk-PNTRHKEH.mjs.map +1 -0
- package/dist/{chunk-PAOHRZCC.mjs → chunk-Q7FOHAQD.mjs} +2 -2
- package/dist/{chunk-PAOHRZCC.mjs.map → chunk-Q7FOHAQD.mjs.map} +1 -1
- package/dist/{chunk-AWKAKL2Y.mjs → chunk-REP6D3WD.mjs} +2 -2
- package/dist/{chunk-AWKAKL2Y.mjs.map → chunk-REP6D3WD.mjs.map} +1 -1
- package/dist/{chunk-VO7ZE5C3.mjs → chunk-UIQH5QIR.mjs} +2 -2
- package/dist/{chunk-VO7ZE5C3.mjs.map → chunk-UIQH5QIR.mjs.map} +1 -1
- package/dist/index.d.mts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-DURMXVHZ.mjs +0 -2
- package/dist/chunk-DURMXVHZ.mjs.map +0 -1
- package/dist/chunk-ID3CEA7W.mjs +0 -2
- package/dist/chunk-ID3CEA7W.mjs.map +0 -1
- package/dist/chunk-LJEJAR35.mjs +0 -2
- package/dist/chunk-LJEJAR35.mjs.map +0 -1
- package/dist/chunk-R5DM7WCD.mjs.map +0 -1
- package/dist/chunk-USMLRWT6.mjs +0 -2
- package/dist/chunk-USMLRWT6.mjs.map +0 -1
|
@@ -1,258 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
1
|
+
import './Base.js';
|
|
2
|
+
import '../Common-BtMFh79I.js';
|
|
3
|
+
import './Enum.js';
|
|
4
|
+
import './ImageInfo.js';
|
|
5
|
+
export { n as ProductAttributes, o as ProductData, k as ProductSelectionAttributes, b as ProductSpecification, S as SelectionAttributes, l as VariantData, m as VariantModel, P as default } from '../Product-mtVUKzNI.js';
|
|
6
6
|
import '../Auth/index.js';
|
|
7
|
-
|
|
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;
|
|
17
|
-
};
|
|
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[];
|
|
36
|
-
};
|
|
37
|
-
type ProductAttributes = BaseAttributes & {
|
|
38
|
-
id: string;
|
|
39
|
-
key: string;
|
|
40
|
-
name: LocalizedString;
|
|
41
|
-
description: LocalizedString;
|
|
42
|
-
slug: LocalizedString;
|
|
43
|
-
brand: string;
|
|
44
|
-
pricing: {
|
|
45
|
-
[country in CountryCode]?: TieredPriceAttributes;
|
|
46
|
-
};
|
|
47
|
-
targetGender: GenderCategory;
|
|
48
|
-
attributes: ProductSelectionAttributes;
|
|
49
|
-
specifications: LocalizedValue<ProductSpecification>;
|
|
50
|
-
categories: string[];
|
|
51
|
-
productType?: ProductType;
|
|
52
|
-
variants: VariantData[];
|
|
53
|
-
isActive: boolean;
|
|
54
|
-
searchTags?: LocalizedValue<string[]>;
|
|
55
|
-
};
|
|
56
|
-
type ProductData = Required<ProductAttributes>;
|
|
57
|
-
declare class ProductModel extends BaseModel {
|
|
58
|
-
protected id: string;
|
|
59
|
-
protected key: string;
|
|
60
|
-
protected name: LocalizedString;
|
|
61
|
-
protected description: LocalizedString;
|
|
62
|
-
protected slug: LocalizedString;
|
|
63
|
-
protected brand: string;
|
|
64
|
-
protected pricing: {
|
|
65
|
-
[country in CountryCode]?: TieredPriceModel;
|
|
66
|
-
};
|
|
67
|
-
protected variants: VariantModel[];
|
|
68
|
-
protected targetGender: GenderCategory;
|
|
69
|
-
protected attributes: ProductSelectionAttributes;
|
|
70
|
-
protected specifications: LocalizedValue<ProductSpecification>;
|
|
71
|
-
protected categories: string[];
|
|
72
|
-
protected productType: ProductType;
|
|
73
|
-
protected isActive: boolean;
|
|
74
|
-
protected searchTags: LocalizedValue<string[]>;
|
|
75
|
-
static productKeyRegex: RegExp;
|
|
76
|
-
static productSKURegex: RegExp;
|
|
77
|
-
/**
|
|
78
|
-
* Generates a unique key for checking uniqueness for a given selection attributes.
|
|
79
|
-
* Excludes 'size' from the key generation.
|
|
80
|
-
* @param selectionAttributes - The selection attributes.
|
|
81
|
-
* @returns A string key representing the unique attribute combination.
|
|
82
|
-
*/
|
|
83
|
-
static generateSelectionAttributesKey(selectionAttributes: SelectionAttributes): string;
|
|
84
|
-
/**
|
|
85
|
-
* Parses a selection attributes key into an object.
|
|
86
|
-
* @param key - The selection attributes key to parse.
|
|
87
|
-
* @returns An object containing the parsed selection attributes.
|
|
88
|
-
*/
|
|
89
|
-
static parseSelectionAttributesKey(key: string): SelectionAttributes;
|
|
90
|
-
/**
|
|
91
|
-
* Creates an instance of ProductModel.
|
|
92
|
-
* Initializes properties based on the provided data, creating copies where necessary.
|
|
93
|
-
* @param data - The initial product attributes.
|
|
94
|
-
* @param date - Optional date for setting creation/modification times (defaults to now).
|
|
95
|
-
*/
|
|
96
|
-
constructor(data: ProductAttributes, date?: Date);
|
|
97
|
-
/**
|
|
98
|
-
* Gets the base Product ID.
|
|
99
|
-
* @returns Product ID.
|
|
100
|
-
*/
|
|
101
|
-
getId(): string;
|
|
102
|
-
/**
|
|
103
|
-
* Gets the user-friendly product key.
|
|
104
|
-
* @returns Product Key.
|
|
105
|
-
*/
|
|
106
|
-
getKey(): string;
|
|
107
|
-
/**
|
|
108
|
-
* Gets the full localized product name object.
|
|
109
|
-
* @returns A copy of the LocalizedString object for the name.
|
|
110
|
-
*/
|
|
111
|
-
getName(): LocalizedString;
|
|
112
|
-
/**
|
|
113
|
-
* Gets the product name for a specific locale, falling back to English ('en').
|
|
114
|
-
* @param locale - The desired locale code.
|
|
115
|
-
* @returns The name string for the specified locale.
|
|
116
|
-
*/
|
|
117
|
-
getName(locale: LocaleCode): string;
|
|
118
|
-
/**
|
|
119
|
-
* Gets the full localized product description object.
|
|
120
|
-
* @returns A copy of the LocalizedString object for the description.
|
|
121
|
-
*/
|
|
122
|
-
getDescription(): LocalizedString;
|
|
123
|
-
/**
|
|
124
|
-
* Gets the product description for a specific locale, falling back to English ('en').
|
|
125
|
-
* @param locale - The desired locale code.
|
|
126
|
-
* @returns The description string for the specified locale.
|
|
127
|
-
*/
|
|
128
|
-
getDescription(locale: LocaleCode): string;
|
|
129
|
-
/**
|
|
130
|
-
* Gets the full localized product slug object.
|
|
131
|
-
* @returns A copy of the LocalizedString object for the slug.
|
|
132
|
-
*/
|
|
133
|
-
getSlug(): LocalizedString;
|
|
134
|
-
/**
|
|
135
|
-
* Gets the product slug for a specific locale, falling back to English ('en').
|
|
136
|
-
* @param locale - The desired locale code.
|
|
137
|
-
* @returns The slug string for the specified locale.
|
|
138
|
-
*/
|
|
139
|
-
getSlug(locale: LocaleCode): string;
|
|
140
|
-
/**
|
|
141
|
-
* Gets the brand associated with the product.
|
|
142
|
-
* @returns The brand name string.
|
|
143
|
-
*/
|
|
144
|
-
getBrand(): string;
|
|
145
|
-
/**
|
|
146
|
-
* Gets the tiered price details for the product.
|
|
147
|
-
* @returns Pricing details mapped by country.
|
|
148
|
-
*/
|
|
149
|
-
getPriceDetails(): {
|
|
150
|
-
[country in CountryCode]?: TieredPriceModel;
|
|
151
|
-
};
|
|
152
|
-
/**
|
|
153
|
-
* Gets the tiered price details for a specific country.
|
|
154
|
-
* @param country - The country code.
|
|
155
|
-
* @returns The tiered price model for the country, or null if not found.
|
|
156
|
-
*/
|
|
157
|
-
getPriceDetails(country: CountryCode): TieredPriceModel | null;
|
|
158
|
-
/**
|
|
159
|
-
* Gets the variant-specific attributes (color, sizes). Returns copies.
|
|
160
|
-
* @returns Product Attributes.
|
|
161
|
-
*/
|
|
162
|
-
getAttributes(): ProductSelectionAttributes;
|
|
163
|
-
/**
|
|
164
|
-
* Gets the variant-specific attributes (color, sizes). Returns copies.
|
|
165
|
-
* @returns Product Attributes.
|
|
166
|
-
*/
|
|
167
|
-
getVariants(): VariantModel[];
|
|
168
|
-
/**
|
|
169
|
-
* Gets the images for a specific selection attribute combination.
|
|
170
|
-
* @param selectionAttributes - The selection attributes to search for.
|
|
171
|
-
* @returns The matching image set or null if not found.
|
|
172
|
-
*/
|
|
173
|
-
private getImagesBySelectionAttributes;
|
|
174
|
-
/**
|
|
175
|
-
* Gets the images for a specific selection attribute combination.
|
|
176
|
-
* @param selectionAttributes - The selection attributes to search for.
|
|
177
|
-
* @returns The matching image set or null if not found.
|
|
178
|
-
*/
|
|
179
|
-
getImages(selectionAttributes: SelectionAttributes): {
|
|
180
|
-
primary: ImageInfoModel;
|
|
181
|
-
gallery: ImageInfoModel[];
|
|
182
|
-
};
|
|
183
|
-
getImages(selectionAttributes: SelectionAttributes, category: ImageCategory.PRIMARY): ImageInfoModel;
|
|
184
|
-
getImages(selectionAttributes: SelectionAttributes, category: ImageCategory.GALLERY): ImageInfoModel[];
|
|
185
|
-
/**
|
|
186
|
-
* Checks if the product is active.
|
|
187
|
-
* @returns True if the product is active, false otherwise.
|
|
188
|
-
*/
|
|
189
|
-
getIsActive(): boolean;
|
|
190
|
-
/**
|
|
191
|
-
* Gets the target gender category for the product.
|
|
192
|
-
* @returns The GenderCategory enum value.
|
|
193
|
-
*/
|
|
194
|
-
getTargetGender(): GenderCategory;
|
|
195
|
-
/**
|
|
196
|
-
* Gets the list of categories the product belongs to. Returns a copy.
|
|
197
|
-
* @returns An array of category.
|
|
198
|
-
*/
|
|
199
|
-
getCategories(): string[];
|
|
200
|
-
/**
|
|
201
|
-
* Gets the product type.
|
|
202
|
-
* @returns ProductType.
|
|
203
|
-
*/
|
|
204
|
-
getProductType(): ProductType;
|
|
205
|
-
/**
|
|
206
|
-
* Gets the full localized product specifications object.
|
|
207
|
-
* @returns Product Specifications
|
|
208
|
-
*/
|
|
209
|
-
getSpecifications(): LocalizedValue<ProductSpecification>;
|
|
210
|
-
/**
|
|
211
|
-
* Gets the product specifications for a specific locale, falling back to English ('en').
|
|
212
|
-
* @param locale - The desired locale code.
|
|
213
|
-
* @returns The ProductSpecification object for the specified locale, or undefined if not found.
|
|
214
|
-
*/
|
|
215
|
-
getSpecifications(locale: LocaleCode): ProductSpecification;
|
|
216
|
-
/**
|
|
217
|
-
* Gets the localized list of search tags. Returns a copy.
|
|
218
|
-
* @returns Localized array of search tags.
|
|
219
|
-
*/
|
|
220
|
-
getSearchTags(): LocalizedValue<string[]>;
|
|
221
|
-
/**
|
|
222
|
-
* Gets the search tags for a specific locale, falling back to English ('en').
|
|
223
|
-
* @param locale - The desired locale code.
|
|
224
|
-
* @returns The array of search tags for the specified locale, or undefined if not found.
|
|
225
|
-
*/
|
|
226
|
-
getSearchTags(locale: LocaleCode): string[];
|
|
227
|
-
/**
|
|
228
|
-
*
|
|
229
|
-
* @returns ProductData
|
|
230
|
-
*/
|
|
231
|
-
getDetails(): ProductData;
|
|
232
|
-
/**
|
|
233
|
-
* Checks if the provided selection attributes are valid for the product.
|
|
234
|
-
* @param selectionAttributes The selection attributes to validate.
|
|
235
|
-
* @throws {SelectionAttributeParseError} If the selection attributes are invalid.
|
|
236
|
-
*/
|
|
237
|
-
checkSelectionAttributes(selectionAttributes: SelectionAttributes): void;
|
|
238
|
-
/**
|
|
239
|
-
* Gets the SKU of the variant matching the selection attributes.
|
|
240
|
-
* @param selectionAttributes - The selection attributes to search for.
|
|
241
|
-
* @returns The SKU string, or undefined if no matching variant is found.
|
|
242
|
-
*/
|
|
243
|
-
getSku(selectionAttributes: SelectionAttributes): string | undefined;
|
|
244
|
-
/**
|
|
245
|
-
* Validates if the provided selection attributes exist for this product.
|
|
246
|
-
* @param selectionAttributes - The attributes to validate.
|
|
247
|
-
* @returns True if a valid selection attribute exists, false otherwise.
|
|
248
|
-
*/
|
|
249
|
-
validateSelectionAttribute(selectionAttributes: SelectionAttributes): boolean;
|
|
250
|
-
/**
|
|
251
|
-
* Validates if a specific size is available for this product.
|
|
252
|
-
* @param size - The size to check.
|
|
253
|
-
* @returns True if the size exists in the product's attributes, false otherwise.
|
|
254
|
-
*/
|
|
255
|
-
validateSize(size: string): boolean;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
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 q=require('crypto');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var q__default=/*#__PURE__*/_interopDefault(q);var T=new Uint8Array(256),D=T.length;function O(){return D>T.length-16&&(q__default.default.randomFillSync(T),D=0),T.slice(D,D+=16)}var V=/^(?:[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 Z(t){return typeof t=="string"&&V.test(t)}var Q=Z;var a=[];for(let t=0;t<256;++t)a.push((t+256).toString(16).slice(1));function w(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 J(t){if(!Q(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 G=J;function X(t){t=unescape(encodeURIComponent(t));let e=[];for(let r=0;r<t.length;++r)e.push(t.charCodeAt(r));return e}var W="6ba7b810-9dad-11d1-80b4-00c04fd430c8",_="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function $(t,e,r){function i(n,s,l,h){var c;if(typeof n=="string"&&(n=X(n)),typeof s=="string"&&(s=G(s)),((c=s)===null||c===void 0?void 0:c.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let d=new Uint8Array(16+n.length);if(d.set(s),d.set(n,s.length),d=r(d),d[6]=d[6]&15|e,d[8]=d[8]&63|128,l){h=h||0;for(let S=0;S<16;++S)l[h+S]=d[S];return l}return w(d)}try{i.name=t;}catch{}return i.DNS=W,i.URL=_,i}var F={randomUUID:q__default.default.randomUUID};function te(t,e,r){if(F.randomUUID&&!e&&!t)return F.randomUUID();t=t||{};let i=t.random||(t.rng||O)();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 w(i)}var z=te;function ie(t){return Array.isArray(t)?t=Buffer.from(t):typeof t=="string"&&(t=Buffer.from(t,"utf8")),q__default.default.createHash("sha1").update(t).digest()}var K=ie;var ne=$("v5",80,K),B=ne;var se={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?B(t,e):z(),generateSearchId:(t,e)=>`${t}#${y.generateSelectionAttributesKey(e)}`,getKeyfromSearchId:t=>{let[e,r]=t.split("#");return {key:e,selectionAttributes:y.parseSelectionAttributesKey(r)}},deepClone(t){return structuredClone(t)}},u=se;var j=t=>structuredClone(t),k=class{customFields;constructor(e,r=new Date){this.customFields={...e.customFields};}getCustomField(e){let r=this.customFields[e];return r==null?r:j(r)}setCustomField(e,r){this.customFields[e]=r;}getAllCustomFields(){return j(this.customFields)}},x=class extends k{version;createdAt;modifiedAt;modifiedBy;constructor(e,r=new Date){super(e),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};}};var f={"en-IN":"en","kn-IN":"kn"};var H={INR:"\u20B9"},Y={INR:"en-IN"};var E=class extends Error{constructor(e){super(`Duplicate selection attribute found: ${e}`),this.name="DuplicateSelectionAttributeError";}};var p=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";}},v=class extends Error{constructor(e="Minimum quantity must be greater than zero."){super(`InvalidMinQuantity: ${e}`),this.name="InvalidMinQuantityError";}},R=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";}},N=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";}},b=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";}},P=class extends Error{constructor(e="Invalid image source configuration."){super(`InvalidImageSource: ${e}`),this.name="InvalidImageSourceError";}};var A=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 P("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 P("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 I=class t{#e;amount;currency;constructor(e){if(this.#e="PriceModel",e.amount<0)throw new C("Amount cannot be negative.");if(!e.currency)throw new b("Currency code is required.");this.currency=e.currency,this.amount=parseFloat(e.amount.toFixed(t.getPrecisionPlaces(this.currency)));}get kind(){return this.#e}static isPriceModel(e){return typeof e=="object"&&e!==null&&e.kind==="PriceModel"}getCurrency(){return this.currency}getAmount(){return this.amount}getDetails(){return {amount:this.amount,currency:this.currency}}getPreciseAmount(e){return parseFloat(e.toFixed(t.getPrecisionPlaces(this.currency)))}compareTo(e){if(t.isPriceModel(e)){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.getPreciseAmount(this.amount-e.getAmount())}add(e){if(t.isPriceModel(e)){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.getPreciseAmount(this.amount+e.getAmount()),currency:this.currency})}subtract(e){if(t.isPriceModel(e)){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.getPreciseAmount(this.amount-e.getAmount()),currency:this.currency})}multiply(e){if(t.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new m("Cannot multiply prices in different currencies.");return new t({amount:this.getPreciseAmount(this.amount*e.getAmount()),currency:this.currency})}else if(typeof e=="number"&&e>=0)return new t({amount:this.getPreciseAmount(this.amount*e),currency:this.currency});throw new g("Must be a non-negative number.")}divide(e){if(t.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new m("Cannot divide prices in different currencies.");return new t({amount:this.getPreciseAmount(this.amount/e.getAmount()),currency:this.currency})}else if(typeof e=="number"&&e>0)return new t({amount:this.getPreciseAmount(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(t.isPriceModel(i)){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},this)}max(...e){if(e.length===0)throw new g("Must provide at least one PriceModel.");return e.reduce((r,i)=>{if(t.isPriceModel(i)){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},this)}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)}toString(){return this.getFormattedString()}static getFormattedString(e,r,i={displayAsInteger:!1,style:"currency",currencyDisplay:"symbol"}){let n=Y[r];if(!r||!n)throw new b("Invalid currency code for formatting.");let s=e,l=i.displayAsInteger?0:t.getDecimalPlaces(r),h={style:i.style??"currency",currency:r,signDisplay:"never",currencyDisplay:i.currencyDisplay,minimumFractionDigits:l,maximumFractionDigits:l};i.displayAsInteger&&(s=Math.ceil(s));try{return new Intl.NumberFormat(n,h).format(s)}catch(c){return console.error(`Error formatting price for currency "${r}" and locale "${n}":`,c),`${H[r]??r} ${t.addThousandSeparators(s.toFixed(l))}`}}static getDecimalPlaces(e){switch(e){case"INR":default:return 2}}static getPrecisionPlaces(e){switch(e){case"INR":default:return 6}}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 b("Invalid currency code for rounding.");let i=t.getDecimalPlaces(r),n=Math.pow(10,i);return Math.round(e*n)/n}static getSmallestUnit(e){let r=t.getDecimalPlaces(e);return 1/Math.pow(10,r)}};var U=class{baseUnitPrice;taxCategory;isTaxInclusive;tiers;constructor(e){let r=new I(e.baseUnitPrice);if(!e.taxCategory)throw new M;let i=(e.tiers??[]).map(c=>({minQuantity:c.minQuantity,unitPrice:new I(c.unitPrice)})).sort((c,d)=>c.minQuantity-d.minQuantity);if(i.some(c=>c.minQuantity<=0))throw new v;let s=i.some(c=>c.unitPrice.getCurrency()!==r.getCurrency()),l=i.some((c,d)=>d>0&&c.unitPrice.compareTo(i[d-1].unitPrice)>0),h=i[0]?.unitPrice.compareTo(r)>0;if(s||l||h)throw new R("Tiers must share the same currency and must not increase in unit price.");this.baseUnitPrice=r,this.taxCategory=e.taxCategory,this.isTaxInclusive=e.isTaxInclusive??!1,this.tiers=i;}getBaseUnitPrice(){return this.baseUnitPrice}getTaxCategory(){return this.taxCategory}getIsTaxInclusive(){return this.isTaxInclusive}getTiers(){return this.tiers.map(e=>({minQuantity:e.minQuantity,unitPrice:e.unitPrice}))}getDetails(){return {baseUnitPrice:this.baseUnitPrice.getDetails(),taxCategory:this.taxCategory,isTaxInclusive:this.isTaxInclusive,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){let i=this.tiers[r];return {minQuantity:i.minQuantity,unitPrice:i.unitPrice}}throw new N(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 y=class t extends x{id;key;name;description;slug;brand;pricing;variants;targetGender;attributes;specifications;categories;productType;isActive;searchTags;static productKeyRegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static productSKURegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static generateSelectionAttributesKey(e){if(typeof e!="object")throw new p("Selection attributes must be an object");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("|").toLowerCase()}static parseSelectionAttributesKey(e){try{let r={},i=e.split("|");for(let n of i){let[s,l]=n.split(":");l.startsWith("c+")?r[s]={name:l.slice(2)}:r[s]=l;}return r}catch(r){throw new p(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((n,s)=>(e.pricing[s]&&(n[s]=new U(e.pricing[s])),n),{}),this.targetGender=e.targetGender,this.attributes=u.deepClone(e.attributes),this.specifications=u.deepClone(e.specifications),this.categories=u.deepClone(e.categories),this.productType=e.productType??"GOODS";let i=new Set;this.variants=(e.variants||[]).map(n=>{if(!n.selectionAttributes||typeof n.selectionAttributes!="object")throw new p("Selection attributes are required");this.checkSelectionAttributes(n.selectionAttributes);let s=t.generateSelectionAttributesKey(n.selectionAttributes);if(i.has(s))throw new E(s);return i.add(s),{sku:n.sku,selectionAttributes:n.selectionAttributes,images:{primary:new A(n.images.primary),gallery:(n.images.gallery||[]).map(l=>new A(l))}}}),this.isActive=e.isActive,this.searchTags=e.searchTags?u.deepClone(e.searchTags):{en:[]};}getId(){return this.id}getKey(){return this.key}getName(e){return e?this.name[e]??this.name[f[e]]??this.name.en:u.deepClone(this.name)}getDescription(e){return e?this.description[e]??this.description[f[e]]??this.description.en:u.deepClone(this.description)}getSlug(e){return e?this.slug[e]??this.slug[f[e]]??this.slug.en:u.deepClone(this.slug)}getBrand(){return this.brand}getPriceDetails(e){return e?this.pricing[e]??null:{...this.pricing}}getAttributes(){return u.deepClone(this.attributes)}getVariants(){return this.variants.map(e=>({sku:e.sku,selectionAttributes:u.deepClone(e.selectionAttributes),images:{primary:e.images.primary,gallery:[...e.images.gallery]}}))}getImagesBySelectionAttributes(e){let r=t.generateSelectionAttributesKey(e),i=this.variants.find(n=>t.generateSelectionAttributesKey(n.selectionAttributes)===r);return i?{primary:i.images.primary,gallery:[...i.images.gallery]}: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 u.deepClone(this.categories)}getProductType(){return this.productType}getSpecifications(e){return e?u.deepClone(this.specifications[e]??this.specifications[f[e]]??this.specifications.en):u.deepClone(this.specifications)}getSearchTags(e){return e?u.deepClone(this.searchTags[e]??this.searchTags[f[e]]??this.searchTags.en):u.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:u.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(),productType:this.getProductType(),specifications:this.getSpecifications(),searchTags:this.getSearchTags(),...e}}checkSelectionAttributes(e){if(!e||typeof e!="object")throw new p("Selection attributes are required");Object.keys(this.attributes).forEach(r=>{if(r.toLowerCase()==="size")return;let i=this.attributes[r],n=e[r];if(n===void 0)throw new p(`Selection attribute '${r}' is missing`);if(typeof i=="string"){if(typeof n!="string"||i!==n)throw new p(`Selection attribute '${r}' is invalid`)}else if(Array.isArray(i)){if(i.length>0&&typeof i[0]=="string"){if(typeof n!="string"||!i.includes(n))throw new p(`Selection attribute '${r}' is invalid`)}else if(typeof n!="object"||!("name"in n)||i.findIndex(s=>s.name===n.name)<0)throw new p(`Selection attribute '${r}' is invalid`)}});}getSku(e){let r=t.generateSelectionAttributesKey(e);return this.variants.find(n=>t.generateSelectionAttributesKey(n.selectionAttributes)===r)?.sku}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=y;//# sourceMappingURL=Product.js.map
|
|
1
|
+
'use strict';var X=require('crypto');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var X__default=/*#__PURE__*/_interopDefault(X);var L=new Uint8Array(256),U=L.length;function $(){return U>L.length-16&&(X__default.default.randomFillSync(L),U=0),L.slice(U,U+=16)}var K=/^(?:[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 W(r){return typeof r=="string"&&K.test(r)}var q=W;var l=[];for(let r=0;r<256;++r)l.push((r+256).toString(16).slice(1));function R(r,e=0){return l[r[e+0]]+l[r[e+1]]+l[r[e+2]]+l[r[e+3]]+"-"+l[r[e+4]]+l[r[e+5]]+"-"+l[r[e+6]]+l[r[e+7]]+"-"+l[r[e+8]]+l[r[e+9]]+"-"+l[r[e+10]]+l[r[e+11]]+l[r[e+12]]+l[r[e+13]]+l[r[e+14]]+l[r[e+15]]}function _(r){if(!q(r))throw TypeError("Invalid UUID");let e,t=new Uint8Array(16);return t[0]=(e=parseInt(r.slice(0,8),16))>>>24,t[1]=e>>>16&255,t[2]=e>>>8&255,t[3]=e&255,t[4]=(e=parseInt(r.slice(9,13),16))>>>8,t[5]=e&255,t[6]=(e=parseInt(r.slice(14,18),16))>>>8,t[7]=e&255,t[8]=(e=parseInt(r.slice(19,23),16))>>>8,t[9]=e&255,t[10]=(e=parseInt(r.slice(24,36),16))/1099511627776&255,t[11]=e/4294967296&255,t[12]=e>>>24&255,t[13]=e>>>16&255,t[14]=e>>>8&255,t[15]=e&255,t}var j=_;function ee(r){r=unescape(encodeURIComponent(r));let e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t));return e}var te="6ba7b810-9dad-11d1-80b4-00c04fd430c8",re="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function F(r,e,t){function i(n,s,o,c){var g;if(typeof n=="string"&&(n=ee(n)),typeof s=="string"&&(s=j(s)),((g=s)===null||g===void 0?void 0:g.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let a=new Uint8Array(16+n.length);if(a.set(s),a.set(n,s.length),a=t(a),a[6]=a[6]&15|e,a[8]=a[8]&63|128,o){c=c||0;for(let h=0;h<16;++h)o[c+h]=a[h];return o}return R(a)}try{i.name=r;}catch{}return i.DNS=te,i.URL=re,i}var B={randomUUID:X__default.default.randomUUID};function ne(r,e,t){if(B.randomUUID&&!e&&!r)return B.randomUUID();r=r||{};let i=r.random||(r.rng||$)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,e){t=t||0;for(let n=0;n<16;++n)e[t+n]=i[n];return e}return R(i)}var z=ne;function oe(r){return Array.isArray(r)?r=Buffer.from(r):typeof r=="string"&&(r=Buffer.from(r,"utf8")),X__default.default.createHash("sha1").update(r).digest()}var H=oe;var ce=F("v5",80,H),k=ce;var ae={isUUID:r=>/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(r),isEmail:r=>/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(r),isURL:r=>/^(http|https):\/\/[^ "]+$/.test(r),generateUUID:(r,e)=>e&&r?k(r,e):z(),generateSearchId:(r,e)=>`${r}#${f.generateSelectionAttributesKey(e)}`,getKeyfromSearchId:r=>{let[e,t]=r.split("#");return {key:e,selectionAttributes:f.parseSelectionAttributesKey(t)}},deepClone(r){return structuredClone(r)}},d=ae;var Y=r=>structuredClone(r),Q=class{customFields;constructor(e,t=new Date){this.customFields={...e.customFields};}getCustomField(e){let t=this.customFields[e];return t==null?t:Y(t)}setCustomField(e,t){this.customFields[e]=t;}getAllCustomFields(){return Y(this.customFields)}},S=class extends Q{version;createdAt;modifiedAt;modifiedBy;constructor(e,t=new Date){super(e),this.version=e.version??1,this.createdAt=e.createdAt&&!isNaN(Date.parse(e.createdAt))?new Date(e.createdAt).toISOString():t.toISOString(),this.modifiedAt=e.modifiedAt&&!isNaN(Date.parse(e.modifiedAt))?new Date(e.modifiedAt).toISOString():t.toISOString(),this.modifiedBy={...e.modifiedBy};}getDetails(){return {customFields:this.getAllCustomFields(),version:this.getVersion(),createdAt:this.getCreatedAt(),modifiedAt:this.getModifiedAt(),modifiedBy:this.getModifiedBy()}}getVersion(){return this.version}getCreatedAt(){return this.createdAt}getCreatedAtTime(){return new Date(this.createdAt).getTime()}getModifiedAt(){return this.modifiedAt}getModifiedAtTime(){return new Date(this.modifiedAt).getTime()}getModifiedBy(){return {...this.modifiedBy}}setModifiedBy(e,t,i,n){this.modifiedBy={id:e,authType:t,requestId:i,lambdaName:n};}};var x={"en-IN":"en","kn-IN":"kn"};var Z={INR:"\u20B9"},J={INR:"en-IN"};var N=class extends Error{constructor(e){super(`Duplicate selection attribute found: ${e}`),this.name="DuplicateSelectionAttributeError";}};var m=class extends Error{constructor(e="Failed to parse selection attributes key."){super(`SelectionAttributeParseError: ${e}`),this.name="SelectionAttributeParseError";}};var O=class extends Error{constructor(e="Tax category is not valid."){super(`InvalidTaxCategory: ${e}`),this.name="InvalidTaxCategoryError";}},D=class extends Error{constructor(e="Minimum quantity must be greater than zero."){super(`InvalidMinQuantity: ${e}`),this.name="InvalidMinQuantityError";}},b=class extends Error{constructor(e){super(`InvalidTieredPrice: ${e}`),this.name="InvalidTieredPriceError";}},w=class extends Error{constructor(e="Quantity must be greater than zero."){super(`InvalidQuantity: ${e}`),this.name="InvalidQuantityError";}},E=class extends Error{constructor(e){super(`NoApplicableTier: Quantity ${e} does not meet the minimum purchase requirement.`),this.name="NoApplicableTierError";}};var M=class extends Error{constructor(e="Amount cannot be negative."){super(`InvalidAmount: ${e}`),this.name="InvalidPriceAmountError";}},C=class extends Error{constructor(e="Currency code is required."){super(`InvalidCurrency: ${e}`),this.name="InvalidCurrencyCodeError";}},y=class extends Error{constructor(e="Cannot perform operation on prices with different currencies."){super(`CurrencyMismatch: ${e}`),this.name="CurrencyMismatchError";}},p=class extends Error{constructor(e){super(`InvalidArgument: ${e}`),this.name="InvalidArgumentError";}},v=class extends Error{constructor(e="Invalid image source configuration."){super(`InvalidImageSource: ${e}`),this.name="InvalidImageSourceError";}};var A=class extends Error{constructor(e="Invalid pricing type."){super(`InvalidPricingType: ${e}`),this.name="InvalidPricingTypeError";}};var I=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 v("ImageInfoModel cannot be created without an 'original' source URL.")}getSources(){return {...this.sources}}getSource(e){return this.sources[e]||this.sources.original}getAlt(){return this.alt}getOrder(){return this.order}getLabel(){return this.label}setAlt(e){this.alt=e;}setOrder(e){this.order=e;}setLabel(e){this.label=e;}setSource(e,t){if(t===void 0){if(e==="original")throw new v("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 P=class r{#e;amount;currency;constructor(e){if(this.#e="PriceModel",e.amount<0)throw new M("Amount cannot be negative.");if(!e.currency)throw new C("Currency code is required.");this.currency=e.currency,this.amount=parseFloat(e.amount.toFixed(r.getPrecisionPlaces(this.currency)));}get kind(){return this.#e}static isPriceModel(e){return typeof e=="object"&&e!==null&&e.kind==="PriceModel"}getCurrency(){return this.currency}getAmount(){return this.amount}getDetails(){return {amount:this.amount,currency:this.currency}}getPreciseAmount(e){return parseFloat(e.toFixed(r.getPrecisionPlaces(this.currency)))}compareTo(e){if(r.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new y("Cannot compare prices in different currencies.")}else throw new p("Must be a PriceModel instance.");return this.getPreciseAmount(this.amount-e.getAmount())}add(e){if(r.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new y("Cannot add prices in different currencies.")}else throw new p("Must be a PriceModel instance.");return new r({amount:this.getPreciseAmount(this.amount+e.getAmount()),currency:this.currency})}subtract(e){if(r.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new y("Cannot subtract prices in different currencies.")}else throw new p("Must be a PriceModel instance.");return new r({amount:this.getPreciseAmount(this.amount-e.getAmount()),currency:this.currency})}multiply(e){if(r.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new y("Cannot multiply prices in different currencies.");return new r({amount:this.getPreciseAmount(this.amount*e.getAmount()),currency:this.currency})}else if(typeof e=="number"&&e>=0)return new r({amount:this.getPreciseAmount(this.amount*e),currency:this.currency});throw new p("Must be a non-negative number.")}divide(e){if(r.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new y("Cannot divide prices in different currencies.");return new r({amount:this.getPreciseAmount(this.amount/e.getAmount()),currency:this.currency})}else if(typeof e=="number"&&e>0)return new r({amount:this.getPreciseAmount(this.amount/e),currency:this.currency});throw new p("Must be a positive number.")}min(...e){if(e.length===0)throw new p("Must provide at least one PriceModel.");return e.reduce((t,i)=>{if(r.isPriceModel(i)){if(t.getCurrency()!==i.getCurrency())throw new y("Cannot compare prices in different currencies.")}else throw new p("Must be a PriceModel instance.");return t.compareTo(i)<0?t:i},this)}max(...e){if(e.length===0)throw new p("Must provide at least one PriceModel.");return e.reduce((t,i)=>{if(r.isPriceModel(i)){if(t.getCurrency()!==i.getCurrency())throw new y("Cannot compare prices in different currencies.")}else throw new p("Must be a PriceModel instance.");return t.compareTo(i)>0?t:i},this)}zero(){return new r({currency:this.currency,amount:0})}isZero(){return this.amount===0}round(){return new r({currency:this.currency,amount:this.getRoundedAmount()})}getRoundedAmount(){return r.getRoundedAmount(this.amount,this.currency)}getFormattedString(){return r.getFormattedString(this.amount,this.currency)}toString(){return this.getFormattedString()}static getFormattedString(e,t,i={displayAsInteger:!1,style:"currency",currencyDisplay:"symbol"}){let n=J[t];if(!t||!n)throw new C("Invalid currency code for formatting.");let s=e,o=i.displayAsInteger?0:r.getDecimalPlaces(t),c={style:i.style??"currency",currency:t,signDisplay:"never",currencyDisplay:i.currencyDisplay,minimumFractionDigits:o,maximumFractionDigits:o};i.displayAsInteger&&(s=Math.ceil(s));try{return new Intl.NumberFormat(n,c).format(s)}catch(g){return console.error(`Error formatting price for currency "${t}" and locale "${n}":`,g),`${Z[t]??t} ${r.addThousandSeparators(s.toFixed(o))}`}}static getDecimalPlaces(e){switch(e){case"INR":default:return 2}}static getPrecisionPlaces(e){switch(e){case"INR":default:return 6}}static addThousandSeparators(e){let t=e.split("."),i=t[0],n=t.length>1?"."+t[1]:"";return i.replace(/\B(?=(\d{3})+(?!\d))/g,",")+n}static getRoundedAmount(e,t){if(e<0)throw new M("Amount cannot be negative for rounding.");if(t===void 0)throw new C("Invalid currency code for rounding.");let i=r.getDecimalPlaces(t),n=Math.pow(10,i);return Math.round(e*n)/n}static getSmallestUnit(e){let t=r.getDecimalPlaces(e);return 1/Math.pow(10,t)}};var T=class{type;taxCategory;isTaxInclusive;static create(e){return e.type==="selection"?new G(e):new V(e)}constructor(e){if(!e.taxCategory)throw new O;this.taxCategory=e.taxCategory,this.isTaxInclusive=e.isTaxInclusive??!1,this.type=e.type??"volume";}getType(){return this.type}getTaxCategory(){return this.taxCategory}getIsTaxInclusive(){return this.isTaxInclusive}},V=class extends T{baseUnitPrice;tiers;currency;constructor(e){if(super(e),this.type="volume",!e.baseUnitPrice)throw new b("Base unit price is required for volume pricing.");this.baseUnitPrice=new P(e.baseUnitPrice),this.currency=e.currency??this.baseUnitPrice.getCurrency();let t=(e.tiers??[]).map(c=>({enabled:c.enabled??!0,minQuantity:c.minQuantity,unitPrice:new P(c.unitPrice)})).sort((c,g)=>c.minQuantity-g.minQuantity);if(t.some(c=>c.minQuantity<=0))throw new D;let n=this.baseUnitPrice.getCurrency()!==this.currency||t.some(c=>c.unitPrice.getCurrency()!==this.currency),s=t.some((c,g)=>g>0&&c.unitPrice.compareTo(t[g-1].unitPrice)>0),o=t[0]?.unitPrice.compareTo(this.baseUnitPrice)>0;if(n||s||o)throw new b("Tiers must share the same currency and must not increase in unit price.");this.tiers=t;}getBaseUnitPrice(){return this.baseUnitPrice}getCurrency(){return this.baseUnitPrice.getCurrency()}getApplicableUnitPrice(e){if(e<=0)throw new w;let t=this.tiers.filter(i=>i.enabled);for(let i=t.length-1;i>=0;i--){let n=t[i];if(e>=n.minQuantity)return n.unitPrice}throw new E(e)}getMinQuantity(){return this.tiers.filter(t=>t.enabled)[0]?.minQuantity??1}getMaxDiscountPercent(){let e=this.tiers.filter(s=>s.enabled);if(!e.length)return 0;let t=Math.min(...e.map(s=>s.unitPrice.getAmount())),i=this.baseUnitPrice.getAmount(),n=(i-t)/i*100;return n>0?n:0}getDetails(){return {type:this.type,taxCategory:this.taxCategory,isTaxInclusive:this.isTaxInclusive,currency:this.currency,baseUnitPrice:this.baseUnitPrice.getDetails(),tiers:this.tiers.map(e=>({enabled:e.enabled,minQuantity:e.minQuantity,unitPrice:e.unitPrice.getDetails()}))}}},G=class extends T{currency;selections;constructor(e){super(e),this.type="selection",this.currency=e.currency,this.selections=(e.selections??[]).map(t=>{if(!t.baseUnitPrice)throw new b("Base unit price is required for each selection.");let i=new P(t.baseUnitPrice),n=(t.tiers??[]).map(a=>({enabled:a.enabled??!0,minQuantity:a.minQuantity??1,unitPrice:new P(a.unitPrice)})).sort((a,h)=>a.minQuantity-h.minQuantity);if(n.some(a=>a.minQuantity<=0))throw new D;let o=i.getCurrency()!==this.currency||n.some(a=>a.unitPrice.getCurrency()!==this.currency),c=n.some((a,h)=>h>0&&a.unitPrice.compareTo(n[h-1].unitPrice)>0),g=n[0]?.unitPrice.compareTo(i)>0;if(o||c||g)throw new b("Tiers must share the same currency and must not increase in unit price within the same selection.");return {selectionAttributes:{...t.selectionAttributes},baseUnitPrice:i,tiers:n}});}findMatch(e){let t=f.generateSelectionAttributesKey(e),i=this.selections.find(n=>f.generateSelectionAttributesKey(n.selectionAttributes)===t);if(!i)throw new b("No pricing configuration found for selection variant.");return i}getBaseUnitPrice(e){if(!e)throw new A("Selection attributes are required to get base unit price for selection pricing.");return this.findMatch(e).baseUnitPrice}getCurrency(){return this.currency}getApplicableUnitPrice(e,t){if(e<=0)throw new w;if(!t)throw new A("Selection attributes are required to get applicable unit price for selection pricing.");let n=this.findMatch(t).tiers.filter(s=>s.enabled);for(let s=n.length-1;s>=0;s--){let o=n[s];if(e>=o.minQuantity)return o.unitPrice}throw new E(e)}getMinQuantity(e){if(!e)throw new A("Selection attributes are required to get min quantity for selection pricing.");return this.findMatch(e).tiers.filter(n=>n.enabled)[0]?.minQuantity??1}getMaxDiscountPercent(e){if(!e)throw new A("Selection attributes are required to get max discount for selection pricing.");let t=this.findMatch(e),i=t.tiers.filter(c=>c.enabled);if(!i.length)return 0;let n=Math.min(...i.map(c=>c.unitPrice.getAmount())),s=t.baseUnitPrice.getAmount(),o=(s-n)/s*100;return o>0?o:0}getDetails(){return {type:this.type,taxCategory:this.taxCategory,isTaxInclusive:this.isTaxInclusive,currency:this.currency,selections:this.selections.map(e=>({selectionAttributes:e.selectionAttributes,baseUnitPrice:e.baseUnitPrice.getDetails(),...e.tiers.length>0?{tiers:e.tiers.map(t=>({enabled:t.enabled,minQuantity:t.minQuantity,unitPrice:t.unitPrice.getDetails()}))}:{}}))}}};var f=class r extends S{id;key;name;description;slug;brand;pricing;variants;targetGender;attributes;specifications;categories;productType;isActive;searchTags;static productKeyRegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static productSKURegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static generateSelectionAttributesKey(e){if(typeof e!="object")throw new m("Selection attributes must be an object");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("|").toLowerCase()}static parseSelectionAttributesKey(e){try{let t={},i=e.split("|");for(let n of i){let[s,o]=n.split(":");o.startsWith("c+")?t[s]={name:o.slice(2)}:t[s]=o;}return t}catch(t){throw new m(t?.message)}}constructor(e,t=new Date){super(e,t),this.id=e.id,this.key=e.key,this.name={...e.name},this.description={...e.description},this.slug={...e.slug},this.brand=e.brand,this.pricing=Object.keys(e.pricing).reduce((n,s)=>(e.pricing[s]&&(n[s]=T.create(e.pricing[s])),n),{}),this.targetGender=e.targetGender,this.attributes=d.deepClone(e.attributes),this.specifications=d.deepClone(e.specifications),this.categories=d.deepClone(e.categories),this.productType=e.productType??"GOODS";let i=new Set;this.variants=(e.variants||[]).map(n=>{if(!n.selectionAttributes||typeof n.selectionAttributes!="object")throw new m("Selection attributes are required");this.checkSelectionAttributes(n.selectionAttributes);let s=r.generateSelectionAttributesKey(n.selectionAttributes);if(i.has(s))throw new N(s);return i.add(s),{sku:n.sku,selectionAttributes:n.selectionAttributes,images:{primary:new I(n.images.primary),gallery:(n.images.gallery||[]).map(o=>new I(o))}}}),this.isActive=e.isActive,this.searchTags=e.searchTags?d.deepClone(e.searchTags):{en:[]};}getId(){return this.id}getKey(){return this.key}getName(e){return e?this.name[e]??this.name[x[e]]??this.name.en:d.deepClone(this.name)}getDescription(e){return e?this.description[e]??this.description[x[e]]??this.description.en:d.deepClone(this.description)}getSlug(e){return e?this.slug[e]??this.slug[x[e]]??this.slug.en:d.deepClone(this.slug)}getBrand(){return this.brand}getPriceDetails(e){return e?this.pricing[e]??null:{...this.pricing}}getAttributes(){return d.deepClone(this.attributes)}getVariants(){return this.variants.map(e=>({sku:e.sku,selectionAttributes:d.deepClone(e.selectionAttributes),images:{primary:e.images.primary,gallery:[...e.images.gallery]}}))}getImagesBySelectionAttributes(e){let t=r.generateSelectionAttributesKey(e),i=this.variants.find(n=>r.generateSelectionAttributesKey(n.selectionAttributes)===t);return i?{primary:i.images.primary,gallery:[...i.images.gallery]}:null}getImages(e,t){switch(t){case"PRIMARY":return this.getImagesBySelectionAttributes(e)?.primary??this.variants[0]?.images?.primary;case"GALLERY":return this.getImagesBySelectionAttributes(e)?.gallery??[];default:return this.getImagesBySelectionAttributes(e)??{primary:this.variants[0]?.images?.primary,gallery:[]}}}getIsActive(){return this.isActive}getTargetGender(){return this.targetGender}getCategories(){return d.deepClone(this.categories)}getProductType(){return this.productType}getSpecifications(e){return e?d.deepClone(this.specifications[e]??this.specifications[x[e]]??this.specifications.en):d.deepClone(this.specifications)}getSearchTags(e){return e?d.deepClone(this.searchTags[e]??this.searchTags[x[e]]??this.searchTags.en):d.deepClone(this.searchTags)}getDetails(){let e=super.getDetails();return {id:this.getId(),key:this.getKey(),name:this.getName(),description:this.getDescription(),slug:this.getSlug(),brand:this.getBrand(),pricing:Object.keys(this.pricing).reduce((t,i)=>(this.pricing[i]&&(t[i]=this.pricing[i]?.getDetails()),t),{}),attributes:this.getAttributes(),variants:this.variants.map(t=>({sku:t.sku,selectionAttributes:d.deepClone(t.selectionAttributes),images:{primary:t.images.primary.getDetails(),gallery:t.images.gallery.map(i=>i.getDetails())}})),isActive:this.getIsActive(),targetGender:this.getTargetGender(),categories:this.getCategories(),productType:this.getProductType(),specifications:this.getSpecifications(),searchTags:this.getSearchTags(),...e}}checkSelectionAttributes(e){if(!e||typeof e!="object")throw new m("Selection attributes are required");Object.keys(this.attributes).forEach(t=>{if(t.toLowerCase()==="size")return;let i=this.attributes[t],n=e[t];if(n===void 0)throw new m(`Selection attribute '${t}' is missing`);if(typeof i=="string"){if(typeof n!="string"||i!==n)throw new m(`Selection attribute '${t}' is invalid`)}else if(Array.isArray(i)){if(i.length>0&&typeof i[0]=="string"){if(typeof n!="string"||!i.includes(n))throw new m(`Selection attribute '${t}' is invalid`)}else if(typeof n!="object"||!("name"in n)||i.findIndex(s=>s.name===n.name)<0)throw new m(`Selection attribute '${t}' is invalid`)}});}getSku(e){let t=r.generateSelectionAttributesKey(e);return this.variants.find(n=>r.generateSelectionAttributesKey(n.selectionAttributes)===t)?.sku}validateSelectionAttribute(e){let t=r.generateSelectionAttributesKey(e);return this.variants.some(i=>r.generateSelectionAttributesKey(i.selectionAttributes)===t)}validateSize(e){return this.attributes.size.includes(e)}};module.exports=f;//# sourceMappingURL=Product.js.map
|
|
2
2
|
//# sourceMappingURL=Product.js.map
|