b23-lib 1.7.0 → 1.7.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.
Files changed (127) hide show
  1. package/dist/Auth/index.d.mts +130 -0
  2. package/dist/Auth/index.d.ts +130 -0
  3. package/dist/Auth/index.js +2 -0
  4. package/dist/Auth/index.js.map +1 -0
  5. package/dist/Auth/index.mjs +2 -0
  6. package/dist/Auth/index.mjs.map +1 -0
  7. package/dist/Classes/Address.d.mts +142 -0
  8. package/dist/Classes/Address.d.ts +142 -0
  9. package/dist/Classes/Address.js +2 -0
  10. package/dist/Classes/Address.js.map +1 -0
  11. package/dist/Classes/Address.mjs +2 -0
  12. package/dist/Classes/Address.mjs.map +1 -0
  13. package/dist/Classes/Base.d.mts +98 -0
  14. package/dist/Classes/Base.d.ts +98 -0
  15. package/dist/Classes/Base.js +2 -0
  16. package/dist/Classes/Base.js.map +1 -0
  17. package/dist/Classes/Base.mjs +2 -0
  18. package/dist/Classes/Base.mjs.map +1 -0
  19. package/dist/Classes/Cart.d.mts +68 -0
  20. package/dist/Classes/Cart.d.ts +68 -0
  21. package/dist/Classes/Cart.js +2 -0
  22. package/dist/Classes/Cart.js.map +1 -0
  23. package/dist/Classes/Cart.mjs +2 -0
  24. package/dist/Classes/Cart.mjs.map +1 -0
  25. package/dist/Classes/Common.d.mts +75 -0
  26. package/dist/Classes/Common.d.ts +75 -0
  27. package/dist/Classes/Common.js +2 -0
  28. package/dist/Classes/Common.js.map +1 -0
  29. package/dist/Classes/Common.mjs +2 -0
  30. package/dist/Classes/Common.mjs.map +1 -0
  31. package/dist/Classes/Coupon.d.mts +142 -0
  32. package/dist/Classes/Coupon.d.ts +142 -0
  33. package/dist/Classes/Coupon.js +2 -0
  34. package/dist/Classes/Coupon.js.map +1 -0
  35. package/dist/Classes/Coupon.mjs +2 -0
  36. package/dist/Classes/Coupon.mjs.map +1 -0
  37. package/dist/Classes/Customer.d.mts +97 -0
  38. package/dist/Classes/Customer.d.ts +97 -0
  39. package/dist/Classes/Customer.js +2 -0
  40. package/dist/Classes/Customer.js.map +1 -0
  41. package/dist/Classes/Customer.mjs +2 -0
  42. package/dist/Classes/Customer.mjs.map +1 -0
  43. package/dist/Classes/CustomerAddress.d.mts +71 -0
  44. package/dist/Classes/CustomerAddress.d.ts +71 -0
  45. package/dist/Classes/CustomerAddress.js +2 -0
  46. package/dist/Classes/CustomerAddress.js.map +1 -0
  47. package/dist/Classes/CustomerAddress.mjs +2 -0
  48. package/dist/Classes/CustomerAddress.mjs.map +1 -0
  49. package/dist/Classes/Enum.d.mts +34 -0
  50. package/dist/Classes/Enum.d.ts +34 -0
  51. package/dist/Classes/Enum.js +2 -0
  52. package/dist/Classes/Enum.js.map +1 -0
  53. package/dist/Classes/Enum.mjs +2 -0
  54. package/dist/Classes/Enum.mjs.map +1 -0
  55. package/dist/Classes/ImageInfo.d.mts +92 -0
  56. package/dist/Classes/ImageInfo.d.ts +92 -0
  57. package/dist/Classes/ImageInfo.js +2 -0
  58. package/dist/Classes/ImageInfo.js.map +1 -0
  59. package/dist/Classes/ImageInfo.mjs +2 -0
  60. package/dist/Classes/ImageInfo.mjs.map +1 -0
  61. package/dist/Classes/LineItem.d.mts +124 -0
  62. package/dist/Classes/LineItem.d.ts +124 -0
  63. package/dist/Classes/LineItem.js +2 -0
  64. package/dist/Classes/LineItem.js.map +1 -0
  65. package/dist/Classes/LineItem.mjs +2 -0
  66. package/dist/Classes/LineItem.mjs.map +1 -0
  67. package/dist/Classes/Order.d.mts +83 -0
  68. package/dist/Classes/Order.d.ts +83 -0
  69. package/dist/Classes/Order.js +2 -0
  70. package/dist/Classes/Order.js.map +1 -0
  71. package/dist/Classes/Order.mjs +2 -0
  72. package/dist/Classes/Order.mjs.map +1 -0
  73. package/dist/Classes/Payment.d.mts +161 -0
  74. package/dist/Classes/Payment.d.ts +161 -0
  75. package/dist/Classes/Payment.js +2 -0
  76. package/dist/Classes/Payment.js.map +1 -0
  77. package/dist/Classes/Payment.mjs +2 -0
  78. package/dist/Classes/Payment.mjs.map +1 -0
  79. package/dist/Classes/Price.d.mts +70 -0
  80. package/dist/Classes/Price.d.ts +70 -0
  81. package/dist/Classes/Price.js +2 -0
  82. package/dist/Classes/Price.js.map +1 -0
  83. package/dist/Classes/Price.mjs +2 -0
  84. package/dist/Classes/Price.mjs.map +1 -0
  85. package/dist/Classes/Product.d.mts +209 -0
  86. package/dist/Classes/Product.d.ts +209 -0
  87. package/dist/Classes/Product.js +2 -0
  88. package/dist/Classes/Product.js.map +1 -0
  89. package/dist/Classes/Product.mjs +2 -0
  90. package/dist/Classes/Product.mjs.map +1 -0
  91. package/dist/Classes/ShoppingContainer.d.mts +194 -0
  92. package/dist/Classes/ShoppingContainer.d.ts +194 -0
  93. package/dist/Classes/ShoppingContainer.js +2 -0
  94. package/dist/Classes/ShoppingContainer.js.map +1 -0
  95. package/dist/Classes/ShoppingContainer.mjs +2 -0
  96. package/dist/Classes/ShoppingContainer.mjs.map +1 -0
  97. package/dist/Dynamodb/index.d.mts +58 -0
  98. package/dist/Dynamodb/index.d.ts +58 -0
  99. package/dist/Dynamodb/index.js +2 -0
  100. package/dist/Dynamodb/index.js.map +1 -0
  101. package/dist/Dynamodb/index.mjs +2 -0
  102. package/dist/Dynamodb/index.mjs.map +1 -0
  103. package/dist/chunk-4H4LJ3UL.mjs +2 -0
  104. package/dist/chunk-4H4LJ3UL.mjs.map +1 -0
  105. package/dist/chunk-65X54TKF.mjs +2 -0
  106. package/dist/chunk-65X54TKF.mjs.map +1 -0
  107. package/dist/chunk-763MN5XV.mjs +2 -0
  108. package/dist/chunk-763MN5XV.mjs.map +1 -0
  109. package/dist/chunk-CWKGR4AF.mjs +2 -0
  110. package/dist/chunk-CWKGR4AF.mjs.map +1 -0
  111. package/dist/chunk-DKI6BDWK.mjs +2 -0
  112. package/dist/chunk-DKI6BDWK.mjs.map +1 -0
  113. package/dist/chunk-SPLTJRHG.mjs +2 -0
  114. package/dist/chunk-SPLTJRHG.mjs.map +1 -0
  115. package/dist/chunk-T6IVHYQQ.mjs +2 -0
  116. package/dist/chunk-T6IVHYQQ.mjs.map +1 -0
  117. package/dist/chunk-T6YCHB3K.mjs +2 -0
  118. package/dist/chunk-T6YCHB3K.mjs.map +1 -0
  119. package/dist/chunk-WU6FFDBS.mjs +2 -0
  120. package/dist/chunk-WU6FFDBS.mjs.map +1 -0
  121. package/dist/index.d.mts +1 -624
  122. package/dist/index.d.ts +1 -624
  123. package/dist/index.js +2 -1
  124. package/dist/index.js.map +1 -1
  125. package/dist/index.mjs +2 -1
  126. package/dist/index.mjs.map +1 -1
  127. package/package.json +163 -1
@@ -0,0 +1,209 @@
1
+ import BaseModel, { BaseAttributes } from './Base.js';
2
+ import { LocalizedString, BasePriceList, PriceTierList, Color, LocaleCode, CountryCode } from './Common.js';
3
+ import { GenderCategory } from './Enum.js';
4
+ import ImageInfoModel, { ImageInfoData } from './ImageInfo.js';
5
+
6
+ type ProductVariantIdentifier = {
7
+ key: string;
8
+ variantId: string;
9
+ };
10
+ type ProductHashKey = {
11
+ id: string;
12
+ variantId: string;
13
+ };
14
+ type ProductAttributes = BaseAttributes & {
15
+ id: string;
16
+ key: string;
17
+ variantId: string;
18
+ name: LocalizedString;
19
+ description: LocalizedString;
20
+ slug: LocalizedString;
21
+ brand: string;
22
+ basePrices: BasePriceList;
23
+ priceTiers: PriceTierList;
24
+ attributes: {
25
+ color: Color;
26
+ sizes: string[];
27
+ };
28
+ primaryImage: ImageInfoData;
29
+ additionalImages?: ImageInfoData[];
30
+ isActive: boolean;
31
+ targetGender: GenderCategory;
32
+ categories: string[];
33
+ specifications: {
34
+ [locale: string]: {
35
+ [key: string]: string | string[];
36
+ };
37
+ };
38
+ searchTags?: string[];
39
+ };
40
+ type ProductData = Required<ProductAttributes>;
41
+ type ProductSpecification = {
42
+ [key: string]: string | string[];
43
+ };
44
+ type LocalizedProductSpecification = {
45
+ en: ProductSpecification;
46
+ } & {
47
+ [locale in LocaleCode]?: ProductSpecification;
48
+ };
49
+ declare class ProductModel extends BaseModel {
50
+ protected id: string;
51
+ protected key: string;
52
+ protected variantId: string;
53
+ protected name: LocalizedString;
54
+ protected description: LocalizedString;
55
+ protected slug: LocalizedString;
56
+ protected brand: string;
57
+ protected basePrices: BasePriceList;
58
+ protected priceTiers: PriceTierList;
59
+ protected attributes: {
60
+ color: Color;
61
+ sizes: string[];
62
+ };
63
+ protected primaryImage: ImageInfoModel;
64
+ protected additionalImages: ImageInfoModel[];
65
+ protected isActive: boolean;
66
+ protected targetGender: GenderCategory;
67
+ protected categories: string[];
68
+ protected specifications: LocalizedProductSpecification;
69
+ protected searchTags: string[];
70
+ static productKeyRegex: RegExp;
71
+ static variantIdRegex: RegExp;
72
+ /**
73
+ * Creates an instance of ProductModel.
74
+ * Initializes properties based on the provided data, creating copies where necessary.
75
+ * @param data - The initial product attributes.
76
+ * @param date - Optional date for setting creation/modification times (defaults to now).
77
+ */
78
+ constructor(data: ProductAttributes, date?: Date);
79
+ /**
80
+ * Gets the base Product ID.
81
+ * @returns Product ID.
82
+ */
83
+ getId(): string;
84
+ /**
85
+ * Gets the user-friendly product key.
86
+ * @returns Product Key.
87
+ */
88
+ getKey(): string;
89
+ /**
90
+ * Gets the specific Variant ID.
91
+ * @returns Variant ID.
92
+ */
93
+ getVariantId(): string;
94
+ /**
95
+ * Gets the full localized product name object.
96
+ * @returns A copy of the LocalizedString object for the name.
97
+ */
98
+ getName(): LocalizedString;
99
+ /**
100
+ * Gets the product name for a specific locale, falling back to English ('en').
101
+ * @param locale - The desired locale code.
102
+ * @returns The name string for the specified locale.
103
+ */
104
+ getName(locale: LocaleCode): string;
105
+ /**
106
+ * Gets the full localized product description object.
107
+ * @returns A copy of the LocalizedString object for the description.
108
+ */
109
+ getDescription(): LocalizedString;
110
+ /**
111
+ * Gets the product description for a specific locale, falling back to English ('en').
112
+ * @param locale - The desired locale code.
113
+ * @returns The description string for the specified locale.
114
+ */
115
+ getDescription(locale: LocaleCode): string;
116
+ /**
117
+ * Gets the full localized product slug object.
118
+ * @returns A copy of the LocalizedString object for the slug.
119
+ */
120
+ getSlug(): LocalizedString;
121
+ /**
122
+ * Gets the product slug for a specific locale, falling back to English ('en').
123
+ * @param locale - The desired locale code.
124
+ * @returns The slug string for the specified locale.
125
+ */
126
+ getSlug(locale: LocaleCode): string;
127
+ /**
128
+ * Gets the brand associated with the product.
129
+ * @returns The brand name string.
130
+ */
131
+ getBrand(): string;
132
+ /**
133
+ * Gets the list of base prices. Returns copies of the price objects.
134
+ * Optionally filters by country.
135
+ * @param country - Optional country code to filter prices for.
136
+ * @returns A list of base prices (or an empty list if none match).
137
+ */
138
+ getBasePrices(country?: CountryCode): BasePriceList;
139
+ /**
140
+ * Gets the list of quantity-based price tiers. Returns copies of the tier objects.
141
+ * Optionally filters by country.
142
+ * @param country - Optional country code to filter tiers for.
143
+ * @returns A list of price tiers (or an empty list if none match or none exist).
144
+ */
145
+ getPriceTiers(country?: CountryCode): PriceTierList;
146
+ /**
147
+ * Gets the variant-specific attributes (color, sizes). Returns copies.
148
+ * @returns Product Attributes.
149
+ */
150
+ getAttributes(): {
151
+ color: Color;
152
+ sizes: string[];
153
+ };
154
+ /**
155
+ * Gets details of product's primary image.
156
+ * @returns The ImageInfoModel instance for the primary image.
157
+ */
158
+ getPrimaryImage(): ImageInfoModel;
159
+ /**
160
+ * Gets the list of additional product images.
161
+ * @returns An array of ImageInfoModel instances.
162
+ */
163
+ getAdditionalImages(): ImageInfoModel[];
164
+ /**
165
+ * Checks if the product variant is active.
166
+ * @returns True if the product is active, false otherwise.
167
+ */
168
+ getIsActive(): boolean;
169
+ /**
170
+ * Gets the target gender category for the product.
171
+ * @returns The GenderCategory enum value.
172
+ */
173
+ getTargetGender(): GenderCategory;
174
+ /**
175
+ * Gets the list of categories the product belongs to. Returns a copy.
176
+ * @returns An array of category.
177
+ */
178
+ getCategories(): string[];
179
+ /**
180
+ * Gets the full localized product specifications object.
181
+ * @returns Product Specifications
182
+ */
183
+ getSpecifications(): LocalizedProductSpecification;
184
+ /**
185
+ * Gets the product specifications for a specific locale, falling back to English ('en').
186
+ * @param locale - The desired locale code.
187
+ * @returns The ProductSpecification object for the specified locale, or undefined if not found.
188
+ */
189
+ getSpecifications(locale: LocaleCode): ProductSpecification | undefined;
190
+ /**
191
+ * Gets the list of search tags. Returns a copy.
192
+ * @returns An array of search tags.
193
+ */
194
+ getSearchTags(): string[];
195
+ /**
196
+ *
197
+ * @returns ProductData
198
+ */
199
+ getDetails(): ProductData;
200
+ /**
201
+ * Calculates the maximum potential discount percentage for a given country
202
+ * based on the lowest price tier compared to the base price.
203
+ * @param country - The country code to calculate the discount for.
204
+ * @returns The maximum discount percentage (0-100), or 0 if calculation is not possible.
205
+ */
206
+ getMaxDiscountPercent(country: CountryCode): number;
207
+ }
208
+
209
+ export { type LocalizedProductSpecification, type ProductAttributes, type ProductData, type ProductHashKey, type ProductSpecification, type ProductVariantIdentifier, ProductModel as default };
@@ -0,0 +1,2 @@
1
+ '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){this.modifiedBy=e;}getCustomField(e){return this.customFields[e]??null}setCustomField(e,t){this.customFields[e]=t;}getAllCustomFields(){return {...this.customFields}}};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 o=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.en:{...this.name}}getDescription(e){return e?this.description[e]??this.description.en:{...this.description}}getSlug(e){return e?this.slug[e]??this.slug.en:{...this.slug}}getBrand(){return this.brand}getBasePrices(e){return (e?this.basePrices.filter(i=>i.country===e):this.basePrices).map(i=>({...i}))}getPriceTiers(e){return (e?this.priceTiers.filter(i=>i.country===e):this.priceTiers).map(i=>({...i}))}getAttributes(){return {...this.attributes,color:{...this.attributes.color},sizes:[...this.attributes.sizes]}}getPrimaryImage(){return this.primaryImage}getAdditionalImages(){return this.additionalImages}getIsActive(){return this.isActive}getTargetGender(){return this.targetGender}getCategories(){return [...this.categories]}getSpecifications(e){return e?this.specifications[e]??this.specifications.en:JSON.parse(JSON.stringify(this.specifications))}getSearchTags(){return [...this.searchTags]}getDetails(){let e=super.getDetails();return {id:this.getId(),key:this.getKey(),variantId:this.getVariantId(),name:this.getName(),description:this.getDescription(),slug:this.getSlug(),brand:this.getBrand(),basePrices:this.getBasePrices(),priceTiers:this.getPriceTiers(),attributes:this.getAttributes(),primaryImage:this.getPrimaryImage().getDetails(),additionalImages:this.getAdditionalImages().map(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,d)=>s.unitPrice-d.unitPrice)[0]?.unitPrice;return !t||t.unitPrice<=0||i===void 0?0:Math.max(0,t.unitPrice-i)/t.unitPrice*100}};module.exports=o;//# sourceMappingURL=Product.js.map
2
+ //# sourceMappingURL=Product.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/Classes/Base.ts","../../src/Classes/ImageInfo.ts","../../src/Classes/Product.ts"],"names":["BaseModel","data","date","modifiedBy","fieldName","value","ImageInfoModel","resolutionKey","altText","order","label","url","ProductModel","price","tier","image","locale","country","baseDetails","basePrice","lowestTierPrice","a","b"],"mappings":"aA0BA,IAAqBA,CAAAA,CAArB,KAA+B,CACnB,YAAA,CACA,QACA,SACA,CAAA,UAAA,CACA,UAQV,CAAA,WAAA,CAAYC,CAAsBC,CAAAA,CAAAA,CAAa,IAAI,IAAQ,CAAA,CACzD,KAAK,YAAe,CAAA,CAAE,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AAQA,EAAAA,CAAAA,CAAK,OAAYG,GAAAA,CAAO,EACxC,IAAK,CAAA,CAACI,CAAGC,CAAAA,CAAAA,GAAMD,CAAE,CAAA,SAAA,CAAYC,EAAE,SAAS,CAAA,CAAE,CAAC,CAAG,EAAA,SAAA,CAG3E,OAAI,CAACH,CAAAA,EAAaA,CAAU,CAAA,SAAA,EAAa,CAAKC,EAAAA,CAAAA,GAAoB,OACvD,CAIM,CAAA,IAAA,CAAK,GAAI,CAAA,CAAA,CAAGD,CAAU,CAAA,SAAA,CAAYC,CAAe,CAG/CD,CAAAA,CAAAA,CAAU,SAAa,CAAA,GAC5C,CACF","file":"Product.js","sourcesContent":["import { ISODateTime } from \"./Common\";\r\n\r\nexport interface CustomFields {\r\n [key: string]: any;\r\n}\r\n\r\nexport type BaseAttributes = {\r\n customFields?: CustomFields;\r\n version?: number;\r\n createdAt?: ISODateTime;\r\n modifiedAt?: ISODateTime;\r\n modifiedBy?: string;\r\n};\r\n\r\nexport type BaseData = {\r\n customFields: CustomFields;\r\n version: number;\r\n createdAt: ISODateTime;\r\n modifiedAt: ISODateTime;\r\n modifiedBy: string;\r\n};\r\n\r\n/**\r\n * Provides common foundational properties and methods for other data models.\r\n * Handles tracking of custom fields, versioning, and timestamps.\r\n */\r\nexport default class BaseModel {\r\n protected customFields: CustomFields;\r\n protected version: number;\r\n protected createdAt: ISODateTime;\r\n protected modifiedAt: ISODateTime;\r\n protected modifiedBy: string;\r\n\r\n /**\r\n * Creates an instance of BaseModel.\r\n * Initializes common properties like timestamps, version, and custom fields.\r\n * @param data - Optional initial attributes for the base model.\r\n * @param date - Optional date object to use for default timestamps (defaults to current time).\r\n */\r\n constructor(data: BaseAttributes, date: Date = new Date()) {\r\n this.customFields = { ...data.customFields };\r\n this.version = data.version ?? 1;\r\n this.createdAt = data.createdAt && !isNaN(Date.parse(data.createdAt))\r\n ?\r\n new Date(data.createdAt).toISOString()\r\n :\r\n date.toISOString();\r\n this.modifiedAt = data.modifiedAt && !isNaN(Date.parse(data.modifiedAt))\r\n ? new Date(data.modifiedAt).toISOString()\r\n : date.toISOString();\r\n\r\n this.modifiedBy = data.modifiedBy ?? '';\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the base model's current state.\r\n * @returns BaseData object containing common properties.\r\n */\r\n getDetails(): BaseData {\r\n return {\r\n customFields: this.getAllCustomFields(), // Use getter to return a copy\r\n version: this.getVersion(),\r\n createdAt: this.getCreatedAt(),\r\n modifiedAt: this.getModifiedAt(),\r\n modifiedBy: this.getModifiedBy(),\r\n }\r\n }\r\n\r\n /**\r\n * Gets the current version number of the model instance.\r\n * @returns The version number.\r\n */\r\n getVersion(): number {\r\n return this.version;\r\n }\r\n\r\n /**\r\n * Gets the creation timestamp as an ISO 8601 string.\r\n * @returns The creation timestamp string.\r\n */\r\n getCreatedAt(): string {\r\n return this.createdAt;\r\n }\r\n\r\n /**\r\n * Gets the creation timestamp as a Unix epoch time (milliseconds).\r\n * @returns The creation time in milliseconds since the epoch.\r\n */\r\n getCreatedAtTime(): number {\r\n return new Date(this.createdAt).getTime();\r\n }\r\n\r\n\r\n /**\r\n * Gets the last modification timestamp as an ISO 8601 string.\r\n * @returns The last modification timestamp string.\r\n */\r\n getModifiedAt(): string {\r\n return this.modifiedAt;\r\n }\r\n\r\n /**\r\n * Gets the last modification timestamp as a Unix epoch time (milliseconds).\r\n * @returns The last modification time in milliseconds since the epoch.\r\n */\r\n getModifiedAtTime(): number {\r\n return new Date(this.modifiedAt).getTime();\r\n }\r\n\r\n /**\r\n * Gets the identifier of the user or process that last modified the instance.\r\n * @returns The modifier identifier string.\r\n */\r\n getModifiedBy(): string {\r\n return this.modifiedBy;\r\n }\r\n\r\n /**\r\n * Sets the identifier of the user or process that last modified the instance.\r\n * @param modifiedBy - The identifier string.\r\n */\r\n setModifiedBy(modifiedBy: string): void {\r\n this.modifiedBy = modifiedBy;\r\n }\r\n\r\n /**\r\n * Retrieves the value of a specific custom field.\r\n * @param fieldName - The name (key) of the custom field to retrieve.\r\n * @returns The value of the custom field, or null if the field does not exist.\r\n */\r\n getCustomField(fieldName: string): any {\r\n return this.customFields[fieldName] ?? null;\r\n }\r\n\r\n /**\r\n * Sets the value of a specific custom field.\r\n * Also updates the modification timestamp and increments the version.\r\n * @param fieldName - The name (key) of the custom field to set.\r\n * @param value - The value to assign to the custom field.\r\n */\r\n setCustomField(fieldName: string, value: any): void {\r\n this.customFields[fieldName] = value;\r\n }\r\n\r\n /**\r\n * Retrieves a shallow copy of all custom fields associated with the instance.\r\n * @returns An object containing all custom fields.\r\n */\r\n getAllCustomFields(): CustomFields {\r\n return { ...this.customFields };\r\n }\r\n}\r\n","export enum ImageResolution {\r\n THUMBNAIL = 'thumbnail',\r\n SMALL = 'small',\r\n MEDIUM = 'medium',\r\n LARGE = 'large',\r\n ORIGINAL = 'original',\r\n}\r\n\r\nexport type ImageInfoAttribute = {\r\n sources: { [key in ImageResolution]?: string } & { original: string };\r\n alt?: string;\r\n order?: number;\r\n label?: string;\r\n};\r\n\r\nexport type ImageInfoData = ImageInfoAttribute;\r\n\r\n/**\r\n * Represents and manages structured image data, including multiple resolutions.\r\n */\r\nexport default class ImageInfoModel {\r\n protected sources: { [key in ImageResolution]?: string } & { original: string };\r\n protected alt?: string;\r\n protected order?: number;\r\n protected label?: string;\r\n\r\n /**\r\n * Creates an instance of ImageInfoModel.\r\n * @param data - The initial image data.\r\n */\r\n constructor(data: ImageInfoAttribute) {\r\n this.sources = { ...data.sources };\r\n this.alt = data.alt;\r\n this.order = data.order;\r\n this.label = data.label;\r\n\r\n if (!this.sources.original) {\r\n throw (\"ImageInfoModel cannot be created without an 'original' source URL.\");\r\n }\r\n }\r\n\r\n /**\r\n * Gets the sources object containing URLs for different resolutions.\r\n * Returns a copy to prevent external modification.\r\n */\r\n getSources() {\r\n return { ...this.sources };\r\n }\r\n\r\n /**\r\n * Gets the URL for a specific resolution key.\r\n * @param resolutionKey - The key of the desired resolution (e.g., 'thumbnail', 'medium').\r\n * @returns The URL string if the key doesn't exist, otherwise original image URL will be returned.\r\n */\r\n getSource(resolutionKey: ImageResolution): string{\r\n return this.sources[resolutionKey] || this.sources.original;\r\n }\r\n\r\n /**\r\n * Gets the alternative text for the image.\r\n */\r\n getAlt(): string | undefined {\r\n return this.alt;\r\n }\r\n\r\n /**\r\n * Gets the display order number for the image.\r\n */\r\n getOrder(): number | undefined {\r\n return this.order;\r\n }\r\n\r\n /**\r\n * Gets the display label or caption for the image.\r\n */\r\n getLabel(): string | undefined {\r\n return this.label;\r\n }\r\n\r\n /**\r\n * Sets the alternative text for the image.\r\n * @param altText - The new alt text.\r\n */\r\n setAlt(altText: string | undefined): void {\r\n this.alt = altText;\r\n // Potentially add logic here to trigger updates if needed\r\n }\r\n\r\n /**\r\n * Sets the display order for the image.\r\n * @param order - The new order number.\r\n */\r\n setOrder(order: number | undefined): void {\r\n this.order = order;\r\n }\r\n\r\n /**\r\n * Sets the display label for the image.\r\n * @param label - The new label text.\r\n */\r\n setLabel(label: string | undefined): void {\r\n this.label = label;\r\n }\r\n\r\n /**\r\n * Updates or adds a URL for a specific resolution.\r\n * @param resolutionKey - The key of the resolution to update/add.\r\n * @param url - The URL for the resolution. Set to undefined to remove.\r\n */\r\n setSource(resolutionKey: ImageResolution, url: string | undefined): void {\r\n if (url === undefined) {\r\n // Prevent deleting the 'original' key if it's required\r\n if (resolutionKey === 'original') {\r\n throw (\"Cannot remove the 'original' image source.\");\r\n return;\r\n }\r\n delete this.sources[resolutionKey];\r\n } else {\r\n this.sources[resolutionKey] = url;\r\n }\r\n }\r\n\r\n /**\r\n * Returns a plain JavaScript object representation of the image info.\r\n */\r\n getDetails(): ImageInfoData {\r\n return {\r\n sources: this.getSources(),\r\n alt: this.getAlt(),\r\n order: this.getOrder(),\r\n label: this.getLabel(),\r\n };\r\n }\r\n}","import BaseModel, { BaseAttributes } from \"./Base\";\r\nimport { BasePriceList, PriceTierList, Color, LocalizedString, CountryCode, LocaleCode } from './Common';\r\nimport { GenderCategory } from \"./Enum\";\r\nimport ImageInfoModel, { ImageInfoData } from \"./ImageInfo\";\r\n\r\nexport type ProductVariantIdentifier = {\r\n key: string;\r\n variantId: string;\r\n};\r\n\r\nexport type ProductHashKey = {\r\n id: string;\r\n variantId: string;\r\n}\r\n\r\nexport type ProductAttributes = BaseAttributes & {\r\n id: string;\r\n key: string;\r\n variantId: string;\r\n\r\n name: LocalizedString;\r\n description: LocalizedString;\r\n slug: LocalizedString;\r\n brand: string;\r\n\r\n basePrices: BasePriceList;\r\n priceTiers: PriceTierList;\r\n\r\n attributes: {\r\n color: Color;\r\n sizes: string[];\r\n };\r\n\r\n primaryImage: ImageInfoData;\r\n additionalImages?: ImageInfoData[];\r\n\r\n // Metadata & Categorization\r\n isActive: boolean;\r\n targetGender: GenderCategory;\r\n categories: string[];\r\n specifications: { [locale: string]: { [key: string]: string | string[] } };\r\n searchTags?: string[];\r\n};\r\n\r\nexport type ProductData = Required<ProductAttributes>\r\n\r\nexport type ProductSpecification = { [key: string]: string | string[] };\r\n\r\nexport type LocalizedProductSpecification = {\r\n en: ProductSpecification\r\n} & {\r\n [locale in LocaleCode]?: ProductSpecification\r\n}\r\n\r\nexport default class ProductModel extends BaseModel {\r\n protected id: string;\r\n protected key: string;\r\n protected variantId: string;\r\n\r\n protected name: LocalizedString;\r\n protected description: LocalizedString;\r\n protected slug: LocalizedString;\r\n protected brand: string;\r\n\r\n protected basePrices: BasePriceList;\r\n protected priceTiers: PriceTierList;\r\n\r\n protected attributes: {\r\n color: Color;\r\n sizes: string[];\r\n };\r\n\r\n protected primaryImage: ImageInfoModel;\r\n protected additionalImages: ImageInfoModel[];\r\n\r\n protected isActive: boolean;\r\n protected targetGender: GenderCategory;\r\n protected categories: string[];\r\n protected specifications: LocalizedProductSpecification;\r\n protected searchTags: string[];\r\n\r\n static productKeyRegex = /^(?!\\s)(?!.*\\s$)[A-Z0-9-]{4,16}$/;\r\n static variantIdRegex = /^(?!\\s)(?!.*\\s$)[A-Z0-9-]{4,16}$/;\r\n\r\n /**\r\n * Creates an instance of ProductModel.\r\n * Initializes properties based on the provided data, creating copies where necessary.\r\n * @param data - The initial product attributes.\r\n * @param date - Optional date for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: ProductAttributes, date: Date = new Date()) {\r\n super(data, date);\r\n this.id = data.id;\r\n this.key = data.key;\r\n this.variantId = data.variantId;\r\n this.name = data.name;\r\n this.description = data.description;\r\n this.slug = data.slug;\r\n this.brand = data.brand;\r\n\r\n this.basePrices = data.basePrices.map(price => ({ ...price }));\r\n this.priceTiers = data.priceTiers ? \r\n data.priceTiers.map(tier => ({ ...tier })) \r\n : \r\n data.basePrices.map(price => ({ ...price }));;\r\n\r\n this.attributes = {\r\n ...data.attributes,\r\n sizes: [...data.attributes.sizes]\r\n };\r\n\r\n this.primaryImage = new ImageInfoModel(data.primaryImage);\r\n this.additionalImages = (data.additionalImages || []).map(image => new ImageInfoModel(image));\r\n this.isActive = data.isActive;\r\n this.targetGender = data.targetGender;\r\n this.categories = [...data.categories];\r\n this.specifications = JSON.parse(JSON.stringify({ ...data.specifications }));\r\n this.searchTags = data.searchTags ? [...data.searchTags] : [];\r\n }\r\n\r\n /**\r\n * Gets the base Product ID.\r\n * @returns Product ID.\r\n */\r\n getId(): string {\r\n return this.id;\r\n }\r\n\r\n /**\r\n * Gets the user-friendly product key.\r\n * @returns Product Key.\r\n */\r\n getKey(): string {\r\n return this.key;\r\n }\r\n\r\n /**\r\n * Gets the specific Variant ID.\r\n * @returns Variant ID.\r\n */\r\n getVariantId(): string {\r\n return this.variantId;\r\n }\r\n\r\n /**\r\n * Gets the full localized product name object.\r\n * @returns A copy of the LocalizedString object for the name.\r\n */\r\n getName(): LocalizedString\r\n /**\r\n * Gets the product name for a specific locale, falling back to English ('en').\r\n * @param locale - The desired locale code.\r\n * @returns The name string for the specified locale.\r\n */\r\n getName(locale: LocaleCode): string\r\n getName(locale?: LocaleCode): LocalizedString | string {\r\n if(locale) {\r\n return this.name[locale] ?? this.name.en;\r\n } else {\r\n return { ...this.name };\r\n }\r\n }\r\n\r\n /**\r\n * Gets the full localized product description object.\r\n * @returns A copy of the LocalizedString object for the description.\r\n */\r\n getDescription(): LocalizedString\r\n /**\r\n * Gets the product description for a specific locale, falling back to English ('en').\r\n * @param locale - The desired locale code.\r\n * @returns The description string for the specified locale.\r\n */\r\n getDescription(locale: LocaleCode): string\r\n getDescription(locale?: LocaleCode): LocalizedString | string {\r\n if(locale){\r\n return this.description[locale] ?? this.description.en;\r\n } else {\r\n return { ...this.description };\r\n }\r\n }\r\n\r\n /**\r\n * Gets the full localized product slug object.\r\n * @returns A copy of the LocalizedString object for the slug.\r\n */\r\n getSlug(): LocalizedString\r\n /**\r\n * Gets the product slug for a specific locale, falling back to English ('en').\r\n * @param locale - The desired locale code.\r\n * @returns The slug string for the specified locale.\r\n */\r\n getSlug(locale: LocaleCode): string\r\n getSlug(locale?: LocaleCode): LocalizedString | string {\r\n if (locale) {\r\n return this.slug[locale] ?? this.slug.en;\r\n } else {\r\n return { ...this.slug };\r\n }\r\n }\r\n\r\n /**\r\n * Gets the brand associated with the product.\r\n * @returns The brand name string.\r\n */\r\n getBrand(): string {\r\n return this.brand;\r\n }\r\n\r\n /**\r\n * Gets the list of base prices. Returns copies of the price objects.\r\n * Optionally filters by country.\r\n * @param country - Optional country code to filter prices for.\r\n * @returns A list of base prices (or an empty list if none match).\r\n */\r\n getBasePrices(country?: CountryCode): BasePriceList {\r\n const filteredPrices = country ? this.basePrices.filter(price => price.country === country) : this.basePrices;\r\n return filteredPrices.map(price => ({ ...price }));\r\n }\r\n\r\n /**\r\n * Gets the list of quantity-based price tiers. Returns copies of the tier objects.\r\n * Optionally filters by country.\r\n * @param country - Optional country code to filter tiers for.\r\n * @returns A list of price tiers (or an empty list if none match or none exist).\r\n */\r\n getPriceTiers(country?: CountryCode): PriceTierList {\r\n const filteredTiers = country ? this.priceTiers.filter(tier => tier.country === country) : this.priceTiers;\r\n return filteredTiers.map(tier => ({ ...tier }));\r\n }\r\n\r\n /**\r\n * Gets the variant-specific attributes (color, sizes). Returns copies.\r\n * @returns Product Attributes.\r\n */\r\n getAttributes(): { color: Color; sizes: string[] } {\r\n return {\r\n ...this.attributes,\r\n color: { ...this.attributes.color }, // Copy color object\r\n sizes: [...this.attributes.sizes]\r\n };\r\n }\r\n\r\n /**\r\n * Gets details of product's primary image.\r\n * @returns The ImageInfoModel instance for the primary image.\r\n */\r\n getPrimaryImage(): ImageInfoModel {\r\n return this.primaryImage;\r\n }\r\n\r\n /**\r\n * Gets the list of additional product images.\r\n * @returns An array of ImageInfoModel instances.\r\n */\r\n getAdditionalImages(): ImageInfoModel[] {\r\n return this.additionalImages;\r\n }\r\n\r\n /**\r\n * Checks if the product variant is active.\r\n * @returns True if the product is active, false otherwise.\r\n */\r\n getIsActive(): boolean {\r\n return this.isActive;\r\n }\r\n\r\n /**\r\n * Gets the target gender category for the product.\r\n * @returns The GenderCategory enum value.\r\n */\r\n getTargetGender(): GenderCategory {\r\n return this.targetGender;\r\n }\r\n\r\n /**\r\n * Gets the list of categories the product belongs to. Returns a copy.\r\n * @returns An array of category.\r\n */\r\n getCategories(): string[] {\r\n return [...this.categories];\r\n }\r\n\r\n /**\r\n * Gets the full localized product specifications object.\r\n * @returns Product Specifications\r\n */\r\n getSpecifications(): LocalizedProductSpecification\r\n /**\r\n * Gets the product specifications for a specific locale, falling back to English ('en').\r\n * @param locale - The desired locale code.\r\n * @returns The ProductSpecification object for the specified locale, or undefined if not found.\r\n */\r\n getSpecifications(locale: LocaleCode): ProductSpecification | undefined\r\n getSpecifications(locale?: LocaleCode): LocalizedProductSpecification | ProductSpecification | undefined {\r\n if(locale){\r\n return this.specifications[locale] ?? this.specifications.en;\r\n } else {\r\n return JSON.parse(JSON.stringify(this.specifications));\r\n }\r\n }\r\n\r\n /**\r\n * Gets the list of search tags. Returns a copy.\r\n * @returns An array of search tags.\r\n */\r\n getSearchTags(): string[] {\r\n return [...this.searchTags];\r\n }\r\n\r\n /**\r\n *\r\n * @returns ProductData\r\n */\r\n getDetails(): ProductData {\r\n const baseDetails = super.getDetails();\r\n return {\r\n id: this.getId(),\r\n key: this.getKey(),\r\n variantId: this.getVariantId(),\r\n name: this.getName(),\r\n description: this.getDescription(),\r\n slug: this.getSlug(),\r\n brand: this.getBrand(),\r\n basePrices: this.getBasePrices(),\r\n priceTiers: this.getPriceTiers(),\r\n attributes: this.getAttributes(),\r\n primaryImage: this.getPrimaryImage().getDetails(),\r\n additionalImages: this.getAdditionalImages().map(image => image.getDetails()),\r\n isActive: this.getIsActive(),\r\n targetGender: this.getTargetGender(),\r\n categories: this.getCategories(),\r\n specifications: this.getSpecifications(),\r\n searchTags: this.getSearchTags(),\r\n ...baseDetails\r\n }; \r\n }\r\n\r\n /**\r\n * Calculates the maximum potential discount percentage for a given country\r\n * based on the lowest price tier compared to the base price.\r\n * @param country - The country code to calculate the discount for.\r\n * @returns The maximum discount percentage (0-100), or 0 if calculation is not possible.\r\n */\r\n getMaxDiscountPercent(country: CountryCode): number {\r\n // Find base price for the country (should be unique per country)\r\n const basePrice = this.basePrices.find(price => price.country === country);\r\n\r\n // Find the lowest unit price among tiers for the country\r\n const lowestTierPrice = this.priceTiers\r\n ?.filter(tier => tier.country === country) // Filter tiers for the country first\r\n .sort((a, b) => a.unitPrice - b.unitPrice)[0]?.unitPrice; // Then sort and get lowest\r\n\r\n // Validate prices before calculation\r\n if (!basePrice || basePrice.unitPrice <= 0 || lowestTierPrice === undefined) {\r\n return 0; // Cannot calculate discount\r\n }\r\n\r\n // Calculate discount, ensuring it's not negative\r\n const discount = Math.max(0, basePrice.unitPrice - lowestTierPrice);\r\n\r\n // Calculate percentage\r\n return (discount / basePrice.unitPrice) * 100;\r\n }\r\n}"]}
@@ -0,0 +1,2 @@
1
+ import {b}from'../chunk-DKI6BDWK.mjs';import {a}from'../chunk-SPLTJRHG.mjs';var n=class extends a{id;key;variantId;name;description;slug;brand;basePrices;priceTiers;attributes;primaryImage;additionalImages;isActive;targetGender;categories;specifications;searchTags;static productKeyRegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static variantIdRegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;constructor(e,i=new Date){super(e,i),this.id=e.id,this.key=e.key,this.variantId=e.variantId,this.name=e.name,this.description=e.description,this.slug=e.slug,this.brand=e.brand,this.basePrices=e.basePrices.map(t=>({...t})),this.priceTiers=e.priceTiers?e.priceTiers.map(t=>({...t})):e.basePrices.map(t=>({...t})),this.attributes={...e.attributes,sizes:[...e.attributes.sizes]},this.primaryImage=new b(e.primaryImage),this.additionalImages=(e.additionalImages||[]).map(t=>new b(t)),this.isActive=e.isActive,this.targetGender=e.targetGender,this.categories=[...e.categories],this.specifications=JSON.parse(JSON.stringify({...e.specifications})),this.searchTags=e.searchTags?[...e.searchTags]:[];}getId(){return this.id}getKey(){return this.key}getVariantId(){return this.variantId}getName(e){return e?this.name[e]??this.name.en:{...this.name}}getDescription(e){return e?this.description[e]??this.description.en:{...this.description}}getSlug(e){return e?this.slug[e]??this.slug.en:{...this.slug}}getBrand(){return this.brand}getBasePrices(e){return (e?this.basePrices.filter(t=>t.country===e):this.basePrices).map(t=>({...t}))}getPriceTiers(e){return (e?this.priceTiers.filter(t=>t.country===e):this.priceTiers).map(t=>({...t}))}getAttributes(){return {...this.attributes,color:{...this.attributes.color},sizes:[...this.attributes.sizes]}}getPrimaryImage(){return this.primaryImage}getAdditionalImages(){return this.additionalImages}getIsActive(){return this.isActive}getTargetGender(){return this.targetGender}getCategories(){return [...this.categories]}getSpecifications(e){return e?this.specifications[e]??this.specifications.en:JSON.parse(JSON.stringify(this.specifications))}getSearchTags(){return [...this.searchTags]}getDetails(){let e=super.getDetails();return {id:this.getId(),key:this.getKey(),variantId:this.getVariantId(),name:this.getName(),description:this.getDescription(),slug:this.getSlug(),brand:this.getBrand(),basePrices:this.getBasePrices(),priceTiers:this.getPriceTiers(),attributes:this.getAttributes(),primaryImage:this.getPrimaryImage().getDetails(),additionalImages:this.getAdditionalImages().map(i=>i.getDetails()),isActive:this.getIsActive(),targetGender:this.getTargetGender(),categories:this.getCategories(),specifications:this.getSpecifications(),searchTags:this.getSearchTags(),...e}}getMaxDiscountPercent(e){let i=this.basePrices.find(r=>r.country===e),t=this.priceTiers?.filter(r=>r.country===e).sort((r,c)=>r.unitPrice-c.unitPrice)[0]?.unitPrice;return !i||i.unitPrice<=0||t===void 0?0:Math.max(0,i.unitPrice-t)/i.unitPrice*100}};export{n as default};//# sourceMappingURL=Product.mjs.map
2
+ //# sourceMappingURL=Product.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/Classes/Product.ts"],"names":["ProductModel","BaseModel","data","date","price","tier","ImageInfoModel","image","locale","country","baseDetails","basePrice","lowestTierPrice","a","b"],"mappings":"4EAsDA,IAAqBA,CAArB,CAAA,cAA0CC,CAAU,CACtC,EACA,CAAA,GAAA,CACA,SAEA,CAAA,IAAA,CACA,WACA,CAAA,IAAA,CACA,KAEA,CAAA,UAAA,CACA,UAEA,CAAA,UAAA,CAKA,YACA,CAAA,gBAAA,CAEA,QACA,CAAA,YAAA,CACA,UACA,CAAA,cAAA,CACA,UAEV,CAAA,OAAO,eAAkB,CAAA,kCAAA,CACzB,OAAO,cAAA,CAAiB,kCAQxB,CAAA,WAAA,CAAYC,EAAyBC,CAAa,CAAA,IAAI,IAAQ,CAAA,CAC1D,KAAMD,CAAAA,CAAAA,CAAMC,CAAI,CAAA,CAChB,IAAK,CAAA,EAAA,CAAKD,CAAK,CAAA,EAAA,CACf,IAAK,CAAA,GAAA,CAAMA,CAAK,CAAA,GAAA,CAChB,IAAK,CAAA,SAAA,CAAYA,CAAK,CAAA,SAAA,CACtB,IAAK,CAAA,IAAA,CAAOA,CAAK,CAAA,IAAA,CACjB,IAAK,CAAA,WAAA,CAAcA,CAAK,CAAA,WAAA,CACxB,IAAK,CAAA,IAAA,CAAOA,CAAK,CAAA,IAAA,CACjB,KAAK,KAAQA,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AAoB,EAAA,CAAE,GAAIH,CAAAA,CAAAA,EAASA,CAAM,CAAA,UAAA,EAAY,CAAA,CAC5E,QAAU,CAAA,IAAA,CAAK,WAAY,EAAA,CAC3B,YAAc,CAAA,IAAA,CAAK,eAAgB,EAAA,CACnC,UAAY,CAAA,IAAA,CAAK,eACjB,CAAA,cAAA,CAAgB,IAAK,CAAA,iBAAA,EACrB,CAAA,UAAA,CAAY,IAAK,CAAA,aAAA,EACjB,CAAA,GAAGG,CACP,CACJ,CAQA,qBAAA,CAAsBD,CAA8B,CAAA,CAElD,IAAME,CAAAA,CAAY,IAAK,CAAA,UAAA,CAAW,IAAKP,CAAAA,CAAAA,EAASA,CAAM,CAAA,OAAA,GAAYK,CAAO,CAAA,CAGnEG,CAAkB,CAAA,IAAA,CAAK,UACC,EAAA,MAAA,CAAOP,CAAQA,EAAAA,CAAAA,CAAK,UAAYI,CAAO,CAAA,CACxC,IAAK,CAAA,CAACI,CAAGC,CAAAA,CAAAA,GAAMD,CAAE,CAAA,SAAA,CAAYC,CAAE,CAAA,SAAS,CAAE,CAAA,CAAC,CAAG,EAAA,SAAA,CAG3E,OAAI,CAACH,CAAaA,EAAAA,CAAAA,CAAU,SAAa,EAAA,CAAA,EAAKC,CAAoB,GAAA,KAAA,CAAA,CACvD,CAIM,CAAA,IAAA,CAAK,GAAI,CAAA,CAAA,CAAGD,CAAU,CAAA,SAAA,CAAYC,CAAe,CAAA,CAG/CD,CAAU,CAAA,SAAA,CAAa,GAC5C,CACF","file":"Product.mjs","sourcesContent":["import BaseModel, { BaseAttributes } from \"./Base\";\r\nimport { BasePriceList, PriceTierList, Color, LocalizedString, CountryCode, LocaleCode } from './Common';\r\nimport { GenderCategory } from \"./Enum\";\r\nimport ImageInfoModel, { ImageInfoData } from \"./ImageInfo\";\r\n\r\nexport type ProductVariantIdentifier = {\r\n key: string;\r\n variantId: string;\r\n};\r\n\r\nexport type ProductHashKey = {\r\n id: string;\r\n variantId: string;\r\n}\r\n\r\nexport type ProductAttributes = BaseAttributes & {\r\n id: string;\r\n key: string;\r\n variantId: string;\r\n\r\n name: LocalizedString;\r\n description: LocalizedString;\r\n slug: LocalizedString;\r\n brand: string;\r\n\r\n basePrices: BasePriceList;\r\n priceTiers: PriceTierList;\r\n\r\n attributes: {\r\n color: Color;\r\n sizes: string[];\r\n };\r\n\r\n primaryImage: ImageInfoData;\r\n additionalImages?: ImageInfoData[];\r\n\r\n // Metadata & Categorization\r\n isActive: boolean;\r\n targetGender: GenderCategory;\r\n categories: string[];\r\n specifications: { [locale: string]: { [key: string]: string | string[] } };\r\n searchTags?: string[];\r\n};\r\n\r\nexport type ProductData = Required<ProductAttributes>\r\n\r\nexport type ProductSpecification = { [key: string]: string | string[] };\r\n\r\nexport type LocalizedProductSpecification = {\r\n en: ProductSpecification\r\n} & {\r\n [locale in LocaleCode]?: ProductSpecification\r\n}\r\n\r\nexport default class ProductModel extends BaseModel {\r\n protected id: string;\r\n protected key: string;\r\n protected variantId: string;\r\n\r\n protected name: LocalizedString;\r\n protected description: LocalizedString;\r\n protected slug: LocalizedString;\r\n protected brand: string;\r\n\r\n protected basePrices: BasePriceList;\r\n protected priceTiers: PriceTierList;\r\n\r\n protected attributes: {\r\n color: Color;\r\n sizes: string[];\r\n };\r\n\r\n protected primaryImage: ImageInfoModel;\r\n protected additionalImages: ImageInfoModel[];\r\n\r\n protected isActive: boolean;\r\n protected targetGender: GenderCategory;\r\n protected categories: string[];\r\n protected specifications: LocalizedProductSpecification;\r\n protected searchTags: string[];\r\n\r\n static productKeyRegex = /^(?!\\s)(?!.*\\s$)[A-Z0-9-]{4,16}$/;\r\n static variantIdRegex = /^(?!\\s)(?!.*\\s$)[A-Z0-9-]{4,16}$/;\r\n\r\n /**\r\n * Creates an instance of ProductModel.\r\n * Initializes properties based on the provided data, creating copies where necessary.\r\n * @param data - The initial product attributes.\r\n * @param date - Optional date for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: ProductAttributes, date: Date = new Date()) {\r\n super(data, date);\r\n this.id = data.id;\r\n this.key = data.key;\r\n this.variantId = data.variantId;\r\n this.name = data.name;\r\n this.description = data.description;\r\n this.slug = data.slug;\r\n this.brand = data.brand;\r\n\r\n this.basePrices = data.basePrices.map(price => ({ ...price }));\r\n this.priceTiers = data.priceTiers ? \r\n data.priceTiers.map(tier => ({ ...tier })) \r\n : \r\n data.basePrices.map(price => ({ ...price }));;\r\n\r\n this.attributes = {\r\n ...data.attributes,\r\n sizes: [...data.attributes.sizes]\r\n };\r\n\r\n this.primaryImage = new ImageInfoModel(data.primaryImage);\r\n this.additionalImages = (data.additionalImages || []).map(image => new ImageInfoModel(image));\r\n this.isActive = data.isActive;\r\n this.targetGender = data.targetGender;\r\n this.categories = [...data.categories];\r\n this.specifications = JSON.parse(JSON.stringify({ ...data.specifications }));\r\n this.searchTags = data.searchTags ? [...data.searchTags] : [];\r\n }\r\n\r\n /**\r\n * Gets the base Product ID.\r\n * @returns Product ID.\r\n */\r\n getId(): string {\r\n return this.id;\r\n }\r\n\r\n /**\r\n * Gets the user-friendly product key.\r\n * @returns Product Key.\r\n */\r\n getKey(): string {\r\n return this.key;\r\n }\r\n\r\n /**\r\n * Gets the specific Variant ID.\r\n * @returns Variant ID.\r\n */\r\n getVariantId(): string {\r\n return this.variantId;\r\n }\r\n\r\n /**\r\n * Gets the full localized product name object.\r\n * @returns A copy of the LocalizedString object for the name.\r\n */\r\n getName(): LocalizedString\r\n /**\r\n * Gets the product name for a specific locale, falling back to English ('en').\r\n * @param locale - The desired locale code.\r\n * @returns The name string for the specified locale.\r\n */\r\n getName(locale: LocaleCode): string\r\n getName(locale?: LocaleCode): LocalizedString | string {\r\n if(locale) {\r\n return this.name[locale] ?? this.name.en;\r\n } else {\r\n return { ...this.name };\r\n }\r\n }\r\n\r\n /**\r\n * Gets the full localized product description object.\r\n * @returns A copy of the LocalizedString object for the description.\r\n */\r\n getDescription(): LocalizedString\r\n /**\r\n * Gets the product description for a specific locale, falling back to English ('en').\r\n * @param locale - The desired locale code.\r\n * @returns The description string for the specified locale.\r\n */\r\n getDescription(locale: LocaleCode): string\r\n getDescription(locale?: LocaleCode): LocalizedString | string {\r\n if(locale){\r\n return this.description[locale] ?? this.description.en;\r\n } else {\r\n return { ...this.description };\r\n }\r\n }\r\n\r\n /**\r\n * Gets the full localized product slug object.\r\n * @returns A copy of the LocalizedString object for the slug.\r\n */\r\n getSlug(): LocalizedString\r\n /**\r\n * Gets the product slug for a specific locale, falling back to English ('en').\r\n * @param locale - The desired locale code.\r\n * @returns The slug string for the specified locale.\r\n */\r\n getSlug(locale: LocaleCode): string\r\n getSlug(locale?: LocaleCode): LocalizedString | string {\r\n if (locale) {\r\n return this.slug[locale] ?? this.slug.en;\r\n } else {\r\n return { ...this.slug };\r\n }\r\n }\r\n\r\n /**\r\n * Gets the brand associated with the product.\r\n * @returns The brand name string.\r\n */\r\n getBrand(): string {\r\n return this.brand;\r\n }\r\n\r\n /**\r\n * Gets the list of base prices. Returns copies of the price objects.\r\n * Optionally filters by country.\r\n * @param country - Optional country code to filter prices for.\r\n * @returns A list of base prices (or an empty list if none match).\r\n */\r\n getBasePrices(country?: CountryCode): BasePriceList {\r\n const filteredPrices = country ? this.basePrices.filter(price => price.country === country) : this.basePrices;\r\n return filteredPrices.map(price => ({ ...price }));\r\n }\r\n\r\n /**\r\n * Gets the list of quantity-based price tiers. Returns copies of the tier objects.\r\n * Optionally filters by country.\r\n * @param country - Optional country code to filter tiers for.\r\n * @returns A list of price tiers (or an empty list if none match or none exist).\r\n */\r\n getPriceTiers(country?: CountryCode): PriceTierList {\r\n const filteredTiers = country ? this.priceTiers.filter(tier => tier.country === country) : this.priceTiers;\r\n return filteredTiers.map(tier => ({ ...tier }));\r\n }\r\n\r\n /**\r\n * Gets the variant-specific attributes (color, sizes). Returns copies.\r\n * @returns Product Attributes.\r\n */\r\n getAttributes(): { color: Color; sizes: string[] } {\r\n return {\r\n ...this.attributes,\r\n color: { ...this.attributes.color }, // Copy color object\r\n sizes: [...this.attributes.sizes]\r\n };\r\n }\r\n\r\n /**\r\n * Gets details of product's primary image.\r\n * @returns The ImageInfoModel instance for the primary image.\r\n */\r\n getPrimaryImage(): ImageInfoModel {\r\n return this.primaryImage;\r\n }\r\n\r\n /**\r\n * Gets the list of additional product images.\r\n * @returns An array of ImageInfoModel instances.\r\n */\r\n getAdditionalImages(): ImageInfoModel[] {\r\n return this.additionalImages;\r\n }\r\n\r\n /**\r\n * Checks if the product variant is active.\r\n * @returns True if the product is active, false otherwise.\r\n */\r\n getIsActive(): boolean {\r\n return this.isActive;\r\n }\r\n\r\n /**\r\n * Gets the target gender category for the product.\r\n * @returns The GenderCategory enum value.\r\n */\r\n getTargetGender(): GenderCategory {\r\n return this.targetGender;\r\n }\r\n\r\n /**\r\n * Gets the list of categories the product belongs to. Returns a copy.\r\n * @returns An array of category.\r\n */\r\n getCategories(): string[] {\r\n return [...this.categories];\r\n }\r\n\r\n /**\r\n * Gets the full localized product specifications object.\r\n * @returns Product Specifications\r\n */\r\n getSpecifications(): LocalizedProductSpecification\r\n /**\r\n * Gets the product specifications for a specific locale, falling back to English ('en').\r\n * @param locale - The desired locale code.\r\n * @returns The ProductSpecification object for the specified locale, or undefined if not found.\r\n */\r\n getSpecifications(locale: LocaleCode): ProductSpecification | undefined\r\n getSpecifications(locale?: LocaleCode): LocalizedProductSpecification | ProductSpecification | undefined {\r\n if(locale){\r\n return this.specifications[locale] ?? this.specifications.en;\r\n } else {\r\n return JSON.parse(JSON.stringify(this.specifications));\r\n }\r\n }\r\n\r\n /**\r\n * Gets the list of search tags. Returns a copy.\r\n * @returns An array of search tags.\r\n */\r\n getSearchTags(): string[] {\r\n return [...this.searchTags];\r\n }\r\n\r\n /**\r\n *\r\n * @returns ProductData\r\n */\r\n getDetails(): ProductData {\r\n const baseDetails = super.getDetails();\r\n return {\r\n id: this.getId(),\r\n key: this.getKey(),\r\n variantId: this.getVariantId(),\r\n name: this.getName(),\r\n description: this.getDescription(),\r\n slug: this.getSlug(),\r\n brand: this.getBrand(),\r\n basePrices: this.getBasePrices(),\r\n priceTiers: this.getPriceTiers(),\r\n attributes: this.getAttributes(),\r\n primaryImage: this.getPrimaryImage().getDetails(),\r\n additionalImages: this.getAdditionalImages().map(image => image.getDetails()),\r\n isActive: this.getIsActive(),\r\n targetGender: this.getTargetGender(),\r\n categories: this.getCategories(),\r\n specifications: this.getSpecifications(),\r\n searchTags: this.getSearchTags(),\r\n ...baseDetails\r\n }; \r\n }\r\n\r\n /**\r\n * Calculates the maximum potential discount percentage for a given country\r\n * based on the lowest price tier compared to the base price.\r\n * @param country - The country code to calculate the discount for.\r\n * @returns The maximum discount percentage (0-100), or 0 if calculation is not possible.\r\n */\r\n getMaxDiscountPercent(country: CountryCode): number {\r\n // Find base price for the country (should be unique per country)\r\n const basePrice = this.basePrices.find(price => price.country === country);\r\n\r\n // Find the lowest unit price among tiers for the country\r\n const lowestTierPrice = this.priceTiers\r\n ?.filter(tier => tier.country === country) // Filter tiers for the country first\r\n .sort((a, b) => a.unitPrice - b.unitPrice)[0]?.unitPrice; // Then sort and get lowest\r\n\r\n // Validate prices before calculation\r\n if (!basePrice || basePrice.unitPrice <= 0 || lowestTierPrice === undefined) {\r\n return 0; // Cannot calculate discount\r\n }\r\n\r\n // Calculate discount, ensuring it's not negative\r\n const discount = Math.max(0, basePrice.unitPrice - lowestTierPrice);\r\n\r\n // Calculate percentage\r\n return (discount / basePrice.unitPrice) * 100;\r\n }\r\n}"]}
@@ -0,0 +1,194 @@
1
+ import BaseModel, { BaseAttributes, BaseData } from './Base.mjs';
2
+ import AddressModel, { AddressData } from './Address.mjs';
3
+ import LineItemModel, { LineItemData } from './LineItem.mjs';
4
+ import { ShippingDetails, CountryCode, CurrencyCode, LocaleCode } from './Common.mjs';
5
+ import CouponModel, { CouponData } from './Coupon.mjs';
6
+ import './ImageInfo.mjs';
7
+ import './Enum.mjs';
8
+
9
+ type BaseShoppingContainerAttributes = BaseAttributes & {
10
+ id: string;
11
+ customerId?: string;
12
+ customerEmail?: string;
13
+ anonymousId?: string;
14
+ lineItems: LineItemData[];
15
+ shippingDetails: ShippingDetails | null;
16
+ shippingAddress?: AddressData | null;
17
+ billingAddress?: AddressData | null;
18
+ coupons?: CouponData[];
19
+ total?: {
20
+ shipping?: number;
21
+ effectiveShipping?: number;
22
+ subtotal?: number;
23
+ mrpTotal?: number;
24
+ couponTotal?: {
25
+ [key: string]: number;
26
+ };
27
+ grandTotal?: number;
28
+ };
29
+ country: CountryCode;
30
+ currency: CurrencyCode;
31
+ locale: LocaleCode;
32
+ };
33
+ type BaseShoppingContainerData = Omit<BaseShoppingContainerAttributes, 'coupons' | 'total'> & BaseData & {
34
+ coupons: CouponData[];
35
+ total: {
36
+ shipping: number;
37
+ effectiveShipping: number;
38
+ subtotal: number;
39
+ mrpTotal: number;
40
+ couponTotal: {
41
+ [key: string]: number;
42
+ };
43
+ grandTotal: number;
44
+ };
45
+ };
46
+ /**
47
+ * Abstract base class for shopping-related containers like carts and orders.
48
+ * Manages common elements such as line items, addresses, coupons, and totals.
49
+ */
50
+ declare abstract class BaseShoppingContainerModel extends BaseModel {
51
+ protected id: string;
52
+ protected customerId?: string;
53
+ protected customerEmail?: string;
54
+ protected anonymousId?: string;
55
+ protected lineItems: LineItemModel[];
56
+ protected shippingDetails: ShippingDetails | null;
57
+ protected shippingAddress: AddressModel | null;
58
+ protected billingAddress: AddressModel | null;
59
+ protected coupons: CouponModel[];
60
+ protected total: {
61
+ shipping: number;
62
+ effectiveShipping: number;
63
+ subtotal: number;
64
+ mrpTotal: number;
65
+ couponTotal: {
66
+ [key: string]: number;
67
+ };
68
+ grandTotal: number;
69
+ };
70
+ protected country: CountryCode;
71
+ protected currency: CurrencyCode;
72
+ protected locale: LocaleCode;
73
+ /**
74
+ * Creates an instance of BaseShoppingContainerModel.
75
+ * Initializes common properties and calculates initial base totals.
76
+ * @param data - The initial attributes for the shopping container.
77
+ * @param date - Optional date object for setting creation/modification times (defaults to now).
78
+ */
79
+ constructor(data: BaseShoppingContainerAttributes, date?: Date);
80
+ /**
81
+ * Recalculates the subtotal and mrpTotal based on the current line items.
82
+ * Uses PriceModel for rounding based on the country.
83
+ */
84
+ protected recalculateBaseTotals(): void;
85
+ /**
86
+ * Gets the unique identifier for this shopping container (cart ID or order ID).
87
+ * @returns The ID string.
88
+ */
89
+ getId(): string;
90
+ /**
91
+ * Gets the customer ID associated with this container, if available.
92
+ * @returns The customer ID string, or undefined.
93
+ */
94
+ getCustomerId(): string | undefined;
95
+ /**
96
+ * Gets the customer email associated with this container, if available.
97
+ * @returns The customer email string, or undefined.
98
+ */
99
+ getCustomerEmail(): string | undefined;
100
+ /**
101
+ * Gets the anonymous user ID associated with this container, if available.
102
+ * @returns The anonymous ID string, or undefined.
103
+ */
104
+ getAnonymousId(): string | undefined;
105
+ /**
106
+ * Gets a defensive copy of the line items in the container.
107
+ * Each item is a new LineItemModel instance created from the original's details.
108
+ * @returns An array of LineItemModel instances.
109
+ */
110
+ getLineItems(): LineItemModel[];
111
+ /**
112
+ * Gets a copy of the shipping details associated with the container.
113
+ * @returns A ShippingDetails object, or null if none are set.
114
+ */
115
+ getShippingDetails(): ShippingDetails | null;
116
+ /**
117
+ * Gets a defensive copy of the shipping address associated with the container.
118
+ * Returns a new AddressModel instance created from the original's details.
119
+ * @returns An AddressModel instance, or null if no shipping address is set.
120
+ */
121
+ getShippingAddress(): AddressModel | null;
122
+ /**
123
+ * Gets a defensive copy of the billing address associated with the container.
124
+ * Returns a new AddressModel instance created from the original's details.
125
+ * @returns An AddressModel instance, or null if no billing address is set.
126
+ */
127
+ getBillingAddress(): AddressModel | null;
128
+ /**
129
+ * Gets a defensive copy of the coupons applied to the container.
130
+ * Each item is a new CouponModel instance created from the original's details.
131
+ * @returns An array of CouponModel instances.
132
+ */
133
+ getCoupons(): CouponModel[];
134
+ /**
135
+ * Gets the country code associated with this container.
136
+ * @returns The CountryCode enum value.
137
+ */
138
+ getCountry(): CountryCode;
139
+ /**
140
+ * Gets the currency code associated with this container.
141
+ * @returns The CurrencyCode enum value.
142
+ */
143
+ getCurrency(): CurrencyCode;
144
+ /**
145
+ * Gets the locale code associated with this container.
146
+ * @returns The LocaleCode enum value.
147
+ */
148
+ getLocale(): LocaleCode;
149
+ /**
150
+ * Gets a defensive copy of the calculated totals for the container.
151
+ * @returns An object containing shipping, subtotal, coupon, and grand totals.
152
+ */
153
+ getTotal(): {
154
+ couponTotal: {
155
+ [x: string]: number;
156
+ };
157
+ shipping: number;
158
+ effectiveShipping: number;
159
+ subtotal: number;
160
+ mrpTotal: number;
161
+ grandTotal: number;
162
+ };
163
+ /**
164
+ * Calculates the discount value for a given coupon based on the current container state.
165
+ * Returns 0 if the coupon is invalid, expired, or not applicable based on cart value or target category.
166
+ * @param coupon - The CouponModel instance to evaluate.
167
+ * @returns The calculated discount amount (rounded according to country rules).
168
+ */
169
+ calculateApplicableCouponDiscount(coupon: CouponModel): number;
170
+ /**
171
+ * Recalculates the `couponTotal` map based on currently applied coupons.
172
+ * Iterates through coupons, calculates their applicable discount, and stores it.
173
+ * @returns The total discount amount from all valid and applicable coupons (rounded).
174
+ */
175
+ recalculateCouponTotals(): number;
176
+ /**
177
+ * Recalculates all container totals (subtotal, mrpTotal, coupons, shipping, grandTotal).
178
+ * Should be called whenever line items, coupons, or base shipping cost change.
179
+ */
180
+ updateCartTotals(): void;
181
+ /**
182
+ * Updates the shipping details (including estimated cost) for the container and recalculates totals.
183
+ * @param details - The new ShippingDetails object, or null to clear shipping details and cost.
184
+ */
185
+ setShippingDetails(details: ShippingDetails | null): void;
186
+ /**
187
+ * Gets a plain data object representing the shopping container's current state.
188
+ * Includes details from the base model and specific container properties.
189
+ * @returns BaseShoppingContainerData object suitable for serialization or API responses.
190
+ */
191
+ getDetails(): BaseShoppingContainerData;
192
+ }
193
+
194
+ export { type BaseShoppingContainerAttributes, type BaseShoppingContainerData, BaseShoppingContainerModel as default };