b23-lib 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/dist/Auth/index.js +1 -1
  2. package/dist/Auth/index.js.map +1 -1
  3. package/dist/Auth/index.mjs +1 -1
  4. package/dist/Auth/index.mjs.map +1 -1
  5. package/dist/Classes/Address.d.mts +1 -1
  6. package/dist/Classes/Address.d.ts +1 -1
  7. package/dist/Classes/Address.js.map +1 -1
  8. package/dist/Classes/Address.mjs +1 -1
  9. package/dist/Classes/Base.d.mts +5 -5
  10. package/dist/Classes/Base.d.ts +5 -5
  11. package/dist/Classes/Base.js.map +1 -1
  12. package/dist/Classes/Base.mjs +1 -1
  13. package/dist/Classes/Cart.d.mts +27 -12
  14. package/dist/Classes/Cart.d.ts +27 -12
  15. package/dist/Classes/Cart.js +1 -1
  16. package/dist/Classes/Cart.js.map +1 -1
  17. package/dist/Classes/Cart.mjs +1 -1
  18. package/dist/Classes/Cart.mjs.map +1 -1
  19. package/dist/Classes/Common.d.mts +2 -93
  20. package/dist/Classes/Common.d.ts +2 -93
  21. package/dist/Classes/Coupon.d.mts +33 -15
  22. package/dist/Classes/Coupon.d.ts +33 -15
  23. package/dist/Classes/Coupon.js +1 -1
  24. package/dist/Classes/Coupon.js.map +1 -1
  25. package/dist/Classes/Coupon.mjs +1 -1
  26. package/dist/Classes/Customer.d.mts +2 -2
  27. package/dist/Classes/Customer.d.ts +2 -2
  28. package/dist/Classes/Customer.js.map +1 -1
  29. package/dist/Classes/Customer.mjs +1 -1
  30. package/dist/Classes/Customer.mjs.map +1 -1
  31. package/dist/Classes/CustomerAddress.d.mts +1 -1
  32. package/dist/Classes/CustomerAddress.d.ts +1 -1
  33. package/dist/Classes/CustomerAddress.js.map +1 -1
  34. package/dist/Classes/CustomerAddress.mjs +1 -1
  35. package/dist/Classes/Enum.d.mts +43 -2
  36. package/dist/Classes/Enum.d.ts +43 -2
  37. package/dist/Classes/Enum.js +1 -1
  38. package/dist/Classes/Enum.js.map +1 -1
  39. package/dist/Classes/Enum.mjs +1 -1
  40. package/dist/Classes/Error.d.mts +59 -0
  41. package/dist/Classes/Error.d.ts +59 -0
  42. package/dist/Classes/Error.js +2 -0
  43. package/dist/Classes/Error.js.map +1 -0
  44. package/dist/Classes/Error.mjs +2 -0
  45. package/dist/Classes/Error.mjs.map +1 -0
  46. package/dist/Classes/ImageInfo.js +1 -1
  47. package/dist/Classes/ImageInfo.js.map +1 -1
  48. package/dist/Classes/ImageInfo.mjs +1 -1
  49. package/dist/Classes/Inventory.d.mts +25 -6
  50. package/dist/Classes/Inventory.d.ts +25 -6
  51. package/dist/Classes/Inventory.js +1 -1
  52. package/dist/Classes/Inventory.js.map +1 -1
  53. package/dist/Classes/Inventory.mjs +1 -1
  54. package/dist/Classes/Inventory.mjs.map +1 -1
  55. package/dist/Classes/LineItem.d.mts +140 -58
  56. package/dist/Classes/LineItem.d.ts +140 -58
  57. package/dist/Classes/LineItem.js +1 -1
  58. package/dist/Classes/LineItem.js.map +1 -1
  59. package/dist/Classes/LineItem.mjs +1 -1
  60. package/dist/Classes/Order.d.mts +7 -51
  61. package/dist/Classes/Order.d.ts +7 -51
  62. package/dist/Classes/Order.js +1 -1
  63. package/dist/Classes/Order.js.map +1 -1
  64. package/dist/Classes/Order.mjs +1 -1
  65. package/dist/Classes/Order.mjs.map +1 -1
  66. package/dist/Classes/Payment.d.mts +4 -4
  67. package/dist/Classes/Payment.d.ts +4 -4
  68. package/dist/Classes/Payment.js.map +1 -1
  69. package/dist/Classes/Payment.mjs +1 -1
  70. package/dist/Classes/Payment.mjs.map +1 -1
  71. package/dist/Classes/Price.d.mts +1 -82
  72. package/dist/Classes/Price.d.ts +1 -82
  73. package/dist/Classes/Price.js +1 -1
  74. package/dist/Classes/Price.js.map +1 -1
  75. package/dist/Classes/Price.mjs +1 -1
  76. package/dist/Classes/Product.d.mts +101 -87
  77. package/dist/Classes/Product.d.ts +101 -87
  78. package/dist/Classes/Product.js +1 -1
  79. package/dist/Classes/Product.js.map +1 -1
  80. package/dist/Classes/Product.mjs +1 -1
  81. package/dist/Classes/Product.mjs.map +1 -1
  82. package/dist/Classes/ShoppingContainer.d.mts +79 -63
  83. package/dist/Classes/ShoppingContainer.d.ts +79 -63
  84. package/dist/Classes/ShoppingContainer.js +1 -1
  85. package/dist/Classes/ShoppingContainer.js.map +1 -1
  86. package/dist/Classes/ShoppingContainer.mjs +1 -1
  87. package/dist/Classes/TaxRule.d.mts +63 -0
  88. package/dist/Classes/TaxRule.d.ts +63 -0
  89. package/dist/Classes/TaxRule.js +2 -0
  90. package/dist/Classes/TaxRule.js.map +1 -0
  91. package/dist/Classes/TaxRule.mjs +2 -0
  92. package/dist/Classes/TaxRule.mjs.map +1 -0
  93. package/dist/Classes/TieredPrice.d.mts +75 -0
  94. package/dist/Classes/TieredPrice.d.ts +75 -0
  95. package/dist/Classes/TieredPrice.js +2 -0
  96. package/dist/Classes/TieredPrice.js.map +1 -0
  97. package/dist/Classes/TieredPrice.mjs +2 -0
  98. package/dist/Classes/TieredPrice.mjs.map +1 -0
  99. package/dist/Common-D-UoxwM0.d.ts +210 -0
  100. package/dist/Common-FbQ5-3QN.d.mts +210 -0
  101. package/dist/chunk-54RUAXYE.mjs +2 -0
  102. package/dist/chunk-54RUAXYE.mjs.map +1 -0
  103. package/dist/{chunk-ATUUYYQT.mjs → chunk-55SOBG62.mjs} +2 -2
  104. package/dist/chunk-55SOBG62.mjs.map +1 -0
  105. package/dist/{chunk-H5GPM4LA.mjs → chunk-5KD2EW7O.mjs} +2 -2
  106. package/dist/{chunk-H5GPM4LA.mjs.map → chunk-5KD2EW7O.mjs.map} +1 -1
  107. package/dist/chunk-72DR3HF2.mjs +2 -0
  108. package/dist/chunk-72DR3HF2.mjs.map +1 -0
  109. package/dist/chunk-AMIRIUMH.mjs +2 -0
  110. package/dist/chunk-AMIRIUMH.mjs.map +1 -0
  111. package/dist/chunk-ISS46WVH.mjs +2 -0
  112. package/dist/chunk-ISS46WVH.mjs.map +1 -0
  113. package/dist/chunk-KWH7GE23.mjs +2 -0
  114. package/dist/chunk-KWH7GE23.mjs.map +1 -0
  115. package/dist/chunk-LXJGGXF3.mjs +2 -0
  116. package/dist/chunk-LXJGGXF3.mjs.map +1 -0
  117. package/dist/chunk-M4BZMGTB.mjs +2 -0
  118. package/dist/chunk-M4BZMGTB.mjs.map +1 -0
  119. package/dist/chunk-NJKSUUOB.mjs +2 -0
  120. package/dist/chunk-NJKSUUOB.mjs.map +1 -0
  121. package/dist/chunk-NUTKOIGY.mjs +2 -0
  122. package/dist/chunk-NUTKOIGY.mjs.map +1 -0
  123. package/dist/chunk-QLLM365R.mjs +2 -0
  124. package/dist/chunk-QLLM365R.mjs.map +1 -0
  125. package/dist/chunk-SFTIM3X7.mjs +2 -0
  126. package/dist/chunk-SFTIM3X7.mjs.map +1 -0
  127. package/dist/index.d.mts +44 -4
  128. package/dist/index.d.ts +44 -4
  129. package/dist/index.js +2 -2
  130. package/dist/index.js.map +1 -1
  131. package/dist/index.mjs +2 -2
  132. package/dist/index.mjs.map +1 -1
  133. package/package.json +1 -1
  134. package/dist/chunk-6PDP4ETM.mjs +0 -2
  135. package/dist/chunk-6PDP4ETM.mjs.map +0 -1
  136. package/dist/chunk-ATUUYYQT.mjs.map +0 -1
  137. package/dist/chunk-CKUUUEWT.mjs +0 -2
  138. package/dist/chunk-CKUUUEWT.mjs.map +0 -1
  139. package/dist/chunk-DKI6BDWK.mjs +0 -2
  140. package/dist/chunk-DKI6BDWK.mjs.map +0 -1
  141. package/dist/chunk-K3AXPTGG.mjs +0 -2
  142. package/dist/chunk-K3AXPTGG.mjs.map +0 -1
  143. package/dist/chunk-LMMJSJTO.mjs +0 -2
  144. package/dist/chunk-LMMJSJTO.mjs.map +0 -1
  145. package/dist/chunk-RWBNLNQ6.mjs +0 -2
  146. package/dist/chunk-RWBNLNQ6.mjs.map +0 -1
  147. package/dist/chunk-V4H3X4PI.mjs +0 -2
  148. package/dist/chunk-V4H3X4PI.mjs.map +0 -1
  149. package/dist/chunk-WOMA746Z.mjs +0 -2
  150. package/dist/chunk-WOMA746Z.mjs.map +0 -1
@@ -1,2 +1,2 @@
1
- export{a as CartState,c as DEFAULT_CART_CONFIG,b as LineItemNotFoundError,d as default}from'../chunk-LMMJSJTO.mjs';import'../chunk-WOMA746Z.mjs';import'../chunk-V4H3X4PI.mjs';import'../chunk-K3AXPTGG.mjs';import'../chunk-DKI6BDWK.mjs';import'../chunk-H5GPM4LA.mjs';import'../chunk-RWBNLNQ6.mjs';import'../chunk-6PDP4ETM.mjs';import'../chunk-ATUUYYQT.mjs';//# sourceMappingURL=Cart.mjs.map
1
+ import {a}from'../chunk-QLLM365R.mjs';import'../chunk-SFTIM3X7.mjs';import'../chunk-M4BZMGTB.mjs';import'../chunk-5KD2EW7O.mjs';import'../chunk-LXJGGXF3.mjs';import {b}from'../chunk-ISS46WVH.mjs';import'../chunk-KWH7GE23.mjs';import'../chunk-54RUAXYE.mjs';import'../chunk-72DR3HF2.mjs';import'../chunk-NUTKOIGY.mjs';import {a as a$1}from'../chunk-NJKSUUOB.mjs';import'../chunk-55SOBG62.mjs';var u=(r=>(r.ACTIVE="ACTIVE",r.FROZEN="FROZEN",r.MERGED="MERGED",r.ORDERED="ORDERED",r))(u||{}),p={expiresAtInSeconds:120*24*60*60},c=class extends a{state;expireAt;config;constructor(t,e=new Date,i=p){super(t,e),this.state=t.state,this.expireAt=t.expireAt&&typeof t.expireAt=="number"?t.expireAt:Math.floor(e.getTime()/1e3)+i.expiresAtInSeconds,this.config=i;}getState(){return this.state}getExpireAt(){return this.expireAt}isActive(){let t=Math.ceil(Date.now()/1e3);return this.state==="ACTIVE"&&this.expireAt>t}clearCartItems(){this.lineItems=[],this.coupons=[],this.shippingDetails=null,this.total.couponTotal={},this.calculateTotals();}validateLineItems(t){this.lineItems=this.lineItems.map(e=>{try{e.updateProductData(t[e.getProductKey()],this.country,this.currency);}catch(i){console.error(`Error recalculating line item ${e.getId()}:`,i),e.clearLineItem();}return e}).filter(e=>e.getId()),this.calculateTotals();}addLineItem(t){let e=t.getProductKey(),i=t.getSelectionAttribute(),r=b.generateSelectionAttributesKey(i),s=this.lineItems.findIndex(n=>n.getProductKey()===e&&b.generateSelectionAttributesKey(n.getSelectionAttribute())===r);return s>=0?this.lineItems[s].addSubItems(t.getSubItems(),!0):this.lineItems.push(t),this.calculateTotals(),s>=0?s:this.lineItems.length-1}updateLineItem(t,e,i){let r=this.lineItems,s=r.findIndex(n=>n.getId()===t);if(s<0)throw new a$1(t);return r[s].addSubItems([{size:e,quantity:i}],!1),this.calculateTotals(),s}removeLineItem(t){let i=this.lineItems.findIndex(r=>r.getId()===t);if(i<0)throw new a$1(t);return this.lineItems.splice(i,1),this.calculateTotals(),i}getDetails(){return {...super.getDetails(),state:this.getState(),expireAt:this.getExpireAt()}}};export{u as CartState,p as DEFAULT_CART_CONFIG,c as default};//# sourceMappingURL=Cart.mjs.map
2
2
  //# sourceMappingURL=Cart.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"Cart.mjs"}
1
+ {"version":3,"sources":["../../src/Classes/Cart.ts"],"names":["CartState","DEFAULT_CART_CONFIG","CartModel","BaseShoppingContainerModel","data","date","config","nowSeconds","products","lineItem","error","newLineItem","productKey","selectionAttribute","selectionAttributeKey","ProductModel","index","item","lineItemId","size","quantity","lineItems","LineItemNotFoundError"],"mappings":"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","file":"Cart.mjs","sourcesContent":["import { LineItemNotFoundError } from \"./Error\";\r\nimport LineItemModel from \"./LineItem\";\r\nimport ProductModel from \"./Product\";\r\nimport BaseShoppingContainerModel, { BaseShoppingContainerAttributes, BaseShoppingContainerData } from \"./ShoppingContainer\";\r\n\r\nexport enum CartState {\r\n ACTIVE = \"ACTIVE\",\r\n FROZEN = \"FROZEN\",\r\n MERGED = \"MERGED\",\r\n ORDERED = \"ORDERED\"\r\n}\r\n\r\n/**\r\n * Input attributes for creating or updating a CartModel.\r\n */\r\nexport type CartAttributes = BaseShoppingContainerAttributes & {\r\n state: CartState;\r\n expireAt: number;\r\n};\r\n\r\nexport type CartData = BaseShoppingContainerData & {\r\n state: CartState;\r\n expireAt: number;\r\n};\r\n\r\nexport type CartConfig = {\r\n expiresAtInSeconds: number;\r\n}\r\n\r\nexport const DEFAULT_CART_CONFIG: CartConfig = {\r\n expiresAtInSeconds: 120 * 24 * 60 * 60\r\n}\r\n\r\nexport default class CartModel extends BaseShoppingContainerModel {\r\n protected state: CartState;\r\n protected expireAt: number;\r\n protected config: CartConfig;\r\n\r\n constructor(data: CartAttributes, date: Date = new Date(), config: CartConfig = DEFAULT_CART_CONFIG) {\r\n super(data, date);\r\n this.state = data.state;\r\n this.expireAt = data.expireAt && typeof data.expireAt === 'number' ? data.expireAt : Math.floor(date.getTime() / 1000) + config.expiresAtInSeconds;\r\n this.config = config;\r\n }\r\n\r\n /**\r\n * Gets the current state of the cart (e.g., ACTIVE, ORDERED).\r\n * @returns The CartState enum value.\r\n */\r\n public getState(): CartState {\r\n return this.state;\r\n }\r\n\r\n /**\r\n * Gets the timestamp when the cart expires.\r\n * @returns The expiration timestamp in seconds (Unix epoch).\r\n */\r\n public getExpireAt(): number {\r\n return this.expireAt;\r\n }\r\n\r\n /**\r\n * Checks if the cart is currently active and not expired.\r\n * @returns True if active and not expired, false otherwise.\r\n */\r\n public isActive(): boolean {\r\n const nowSeconds = Math.ceil(Date.now() / 1000);\r\n return this.state === CartState.ACTIVE && (this.expireAt > nowSeconds);\r\n }\r\n\r\n /**\r\n * Clears all line items, coupons, and shipping details from the cart and resets totals.\r\n */\r\n public clearCartItems() {\r\n this.lineItems = [];\r\n this.coupons = [];\r\n this.shippingDetails = null;\r\n this.total.couponTotal = {};\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Validates line items against the current product catalog.\r\n * Updates product data for each item and removes invalid items.\r\n * @param products - A record map of ProductModels keyed by product ID/key.\r\n */\r\n public validateLineItems(products: Record<string, ProductModel>): void {\r\n this.lineItems = this.lineItems.map(lineItem => {\r\n try {\r\n lineItem.updateProductData(products[lineItem.getProductKey()], this.country, this.currency);\r\n } catch (error) {\r\n console.error(`Error recalculating line item ${lineItem.getId()}:`, error);\r\n lineItem.clearLineItem();\r\n }\r\n return lineItem;\r\n }).filter(lineItem => lineItem.getId());\r\n\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Adds a new line item or updates the quantity of an existing one.\r\n * @param newLineItem The LineItemModel to add.\r\n * @returns The index of the added/updated line item in the internal array.\r\n */\r\n public addLineItem(newLineItem: LineItemModel) {\r\n const productKey = newLineItem.getProductKey();\r\n const selectionAttribute = newLineItem.getSelectionAttribute();\r\n const selectionAttributeKey = ProductModel.generateSelectionAttributesKey(selectionAttribute);\r\n let index = this.lineItems.findIndex(\r\n (item) => item.getProductKey() === productKey && ProductModel.generateSelectionAttributesKey(item.getSelectionAttribute()) === selectionAttributeKey\r\n );\r\n\r\n if (index >= 0) {\r\n this.lineItems[index].addSubItems(newLineItem.getSubItems(), true);\r\n } else {\r\n this.lineItems.push(newLineItem);\r\n }\r\n\r\n this.calculateTotals();\r\n return index >= 0 ? index : this.lineItems.length - 1;\r\n }\r\n\r\n /**\r\n * Updates the quantity for a specific size within a line item.\r\n * @param lineItemId The ID of the LineItemModel to update.\r\n * @param size The size identifier within the line item.\r\n * @param quantity The new quantity for the size (0 to remove).\r\n * @returns The index of the updated line item.\r\n * @throws {Error} If the line item is not found.\r\n */\r\n public updateLineItem(lineItemId: string, size: string, quantity: number) {\r\n const lineItems = this.lineItems;\r\n let index = lineItems.findIndex((item) => item.getId() === lineItemId);\r\n\r\n if (index < 0) {\r\n throw new LineItemNotFoundError(lineItemId);\r\n }\r\n\r\n lineItems[index].addSubItems([{ size, quantity }], false);\r\n this.calculateTotals();\r\n\r\n return index;\r\n }\r\n\r\n /**\r\n * Removes a line item completely from the cart.\r\n * @param lineItemId The ID of the LineItemModel to remove.\r\n * @returns The index the item previously occupied.\r\n * @throws {Error} If the line item is not found.\r\n */\r\n public removeLineItem(lineItemId: string) {\r\n const lineItems = this.lineItems;\r\n const index = lineItems.findIndex((item) => item.getId() === lineItemId);\r\n\r\n if (index < 0) {\r\n throw new LineItemNotFoundError(lineItemId);\r\n }\r\n\r\n this.lineItems.splice(index, 1);\r\n this.calculateTotals();\r\n\r\n return index;\r\n }\r\n\r\n getDetails(): CartData {\r\n return {\r\n ...super.getDetails(),\r\n state: this.getState(),\r\n expireAt: this.getExpireAt(),\r\n }\r\n }\r\n}\r\n"]}
@@ -1,93 +1,2 @@
1
- import { OperationalCountry, OperationalCountryCurrency, OperationalLocale, OperationalLanguage } from './Enum.mjs';
2
-
3
- /**
4
- * Represents a ISO 3166-1 alpha-2 country code (e.g., 'US', 'IN').
5
- */
6
- type CountryCode = keyof typeof OperationalCountry;
7
- /**
8
- * Represents a ISO 4217 currency code (e.g., 'INR', 'USD').
9
- */
10
- type CurrencyCode = keyof typeof OperationalCountryCurrency;
11
- /**
12
- * /**
13
- * Represents a string that can be localized into multiple languages.
14
- * The 'en' property is mandatory and serves as the default English translation.
15
- * Additional properties can be added for other locales using their respective locale codes.
16
- */
17
- type LocalizedString = {
18
- en: string;
19
- } & {
20
- [locale in (LocaleCode | LanguageCode)]?: string;
21
- };
22
- /**
23
- * Represents a BCP 47 language tag (e.g., 'en-US', 'fr-FR').
24
- * Used to identify languages and regional variations.
25
- */
26
- type LocaleCode = keyof typeof OperationalLocale;
27
- type LanguageCode = keyof typeof OperationalLanguage;
28
- /**
29
- * Represents a pricing tier based on a minimum purchase quantity.
30
- */
31
- type PriceTier = {
32
- /** The minimum quantity required to achieve this unit price. */
33
- minQuantity: number;
34
- /** The price per unit at this quantity tier. */
35
- unitPrice: number;
36
- currency: CurrencyCode;
37
- country: CountryCode;
38
- };
39
- /**
40
- * Represents the base price information for a single unit in a specific country.
41
- */
42
- type BasePrice = {
43
- /** Enforces that this price is for a single unit. */
44
- minQuantity: 1;
45
- /** The price per unit. */
46
- unitPrice: number;
47
- currency: CurrencyCode;
48
- country: CountryCode;
49
- };
50
- type BasePriceList = BasePrice[];
51
- type PriceTierList = PriceTier[];
52
- type Color = {
53
- name: string;
54
- hex?: string;
55
- };
56
- /**
57
- * Represents a date and time string formatted according to the ISO 8601 standard.
58
- * Example: "2023-10-27T10:30:00Z"
59
- */
60
- type ISODateTime = string;
61
- type RegionalPrice = {
62
- country: CountryCode;
63
- currency: CurrencyCode;
64
- price: number;
65
- };
66
- type RegionalPriceList = RegionalPrice[];
67
- interface ShippingDetails {
68
- courierName: string;
69
- courierId?: string;
70
- serviceType?: string;
71
- rating?: number;
72
- estimatedDeliveryDays?: number;
73
- cost: number;
74
- currency?: string;
75
- isFallback: boolean;
76
- trackingUrl?: string;
77
- deliveryType?: string;
78
- insuranceAmount?: number;
79
- weight?: number;
80
- dimensions?: {
81
- length: number;
82
- width: number;
83
- height: number;
84
- unit?: string;
85
- };
86
- pickupDate?: string;
87
- deliveryDate?: string;
88
- status?: string;
89
- rawApiData?: any;
90
- [key: string]: any;
91
- }
92
-
93
- export type { BasePrice, BasePriceList, Color, CountryCode, CurrencyCode, ISODateTime, LanguageCode, LocaleCode, LocalizedString, PriceTier, PriceTierList, RegionalPrice, RegionalPriceList, ShippingDetails };
1
+ import './Enum.mjs';
2
+ export { f as Color, C as CountryCode, a as CurrencyCode, I as ISODateTimeUTC, h as LanguageCode, L as LocaleCode, c as LocalizedString, d as LocalizedValue, e as Prettify, R as RegionalPrice, S as ShippingDetails } from '../Common-FbQ5-3QN.mjs';
@@ -1,93 +1,2 @@
1
- import { OperationalCountry, OperationalCountryCurrency, OperationalLocale, OperationalLanguage } from './Enum.js';
2
-
3
- /**
4
- * Represents a ISO 3166-1 alpha-2 country code (e.g., 'US', 'IN').
5
- */
6
- type CountryCode = keyof typeof OperationalCountry;
7
- /**
8
- * Represents a ISO 4217 currency code (e.g., 'INR', 'USD').
9
- */
10
- type CurrencyCode = keyof typeof OperationalCountryCurrency;
11
- /**
12
- * /**
13
- * Represents a string that can be localized into multiple languages.
14
- * The 'en' property is mandatory and serves as the default English translation.
15
- * Additional properties can be added for other locales using their respective locale codes.
16
- */
17
- type LocalizedString = {
18
- en: string;
19
- } & {
20
- [locale in (LocaleCode | LanguageCode)]?: string;
21
- };
22
- /**
23
- * Represents a BCP 47 language tag (e.g., 'en-US', 'fr-FR').
24
- * Used to identify languages and regional variations.
25
- */
26
- type LocaleCode = keyof typeof OperationalLocale;
27
- type LanguageCode = keyof typeof OperationalLanguage;
28
- /**
29
- * Represents a pricing tier based on a minimum purchase quantity.
30
- */
31
- type PriceTier = {
32
- /** The minimum quantity required to achieve this unit price. */
33
- minQuantity: number;
34
- /** The price per unit at this quantity tier. */
35
- unitPrice: number;
36
- currency: CurrencyCode;
37
- country: CountryCode;
38
- };
39
- /**
40
- * Represents the base price information for a single unit in a specific country.
41
- */
42
- type BasePrice = {
43
- /** Enforces that this price is for a single unit. */
44
- minQuantity: 1;
45
- /** The price per unit. */
46
- unitPrice: number;
47
- currency: CurrencyCode;
48
- country: CountryCode;
49
- };
50
- type BasePriceList = BasePrice[];
51
- type PriceTierList = PriceTier[];
52
- type Color = {
53
- name: string;
54
- hex?: string;
55
- };
56
- /**
57
- * Represents a date and time string formatted according to the ISO 8601 standard.
58
- * Example: "2023-10-27T10:30:00Z"
59
- */
60
- type ISODateTime = string;
61
- type RegionalPrice = {
62
- country: CountryCode;
63
- currency: CurrencyCode;
64
- price: number;
65
- };
66
- type RegionalPriceList = RegionalPrice[];
67
- interface ShippingDetails {
68
- courierName: string;
69
- courierId?: string;
70
- serviceType?: string;
71
- rating?: number;
72
- estimatedDeliveryDays?: number;
73
- cost: number;
74
- currency?: string;
75
- isFallback: boolean;
76
- trackingUrl?: string;
77
- deliveryType?: string;
78
- insuranceAmount?: number;
79
- weight?: number;
80
- dimensions?: {
81
- length: number;
82
- width: number;
83
- height: number;
84
- unit?: string;
85
- };
86
- pickupDate?: string;
87
- deliveryDate?: string;
88
- status?: string;
89
- rawApiData?: any;
90
- [key: string]: any;
91
- }
92
-
93
- export type { BasePrice, BasePriceList, Color, CountryCode, CurrencyCode, ISODateTime, LanguageCode, LocaleCode, LocalizedString, PriceTier, PriceTierList, RegionalPrice, RegionalPriceList, ShippingDetails };
1
+ import './Enum.js';
2
+ export { f as Color, C as CountryCode, a as CurrencyCode, I as ISODateTimeUTC, h as LanguageCode, L as LocaleCode, c as LocalizedString, d as LocalizedValue, e as Prettify, R as RegionalPrice, S as ShippingDetails } from '../Common-D-UoxwM0.js';
@@ -1,5 +1,5 @@
1
1
  import BaseModel, { BaseAttributes } from './Base.mjs';
2
- import { LocalizedString, ISODateTime, RegionalPriceList, LocaleCode, CountryCode, RegionalPrice } from './Common.mjs';
2
+ import { c as LocalizedString, I as ISODateTimeUTC, R as RegionalPrice, C as CountryCode, b as PriceModel, L as LocaleCode, a as CurrencyCode } from '../Common-FbQ5-3QN.mjs';
3
3
  import '../Auth/index.mjs';
4
4
  import './Enum.mjs';
5
5
 
@@ -25,10 +25,10 @@ type CouponAttribute = BaseAttributes & {
25
25
  description: LocalizedString;
26
26
  type: CouponType;
27
27
  customerId?: string;
28
- validFrom: ISODateTime;
29
- validTo: ISODateTime;
30
- minCartValue: RegionalPriceList;
31
- maxCartDiscount: RegionalPriceList;
28
+ validFrom: ISODateTimeUTC;
29
+ validTo: ISODateTimeUTC;
30
+ minCartValue: RegionalPrice;
31
+ maxCartDiscount: RegionalPrice;
32
32
  discountMethod: CouponDiscountMethod;
33
33
  percentageValue?: number;
34
34
  applicableTo: ApplicableTo;
@@ -44,10 +44,14 @@ declare class CouponModel extends BaseModel {
44
44
  protected description: LocalizedString;
45
45
  protected type: CouponType;
46
46
  protected customerId?: string;
47
- protected validFrom: ISODateTime;
48
- protected validTo: ISODateTime;
49
- protected minCartValue: RegionalPriceList;
50
- protected maxCartDiscount: RegionalPriceList;
47
+ protected validFrom: ISODateTimeUTC;
48
+ protected validTo: ISODateTimeUTC;
49
+ protected minCartValue: {
50
+ [country in CountryCode]?: PriceModel;
51
+ };
52
+ protected maxCartDiscount: {
53
+ [country in CountryCode]?: PriceModel;
54
+ };
51
55
  protected discountMethod: CouponDiscountMethod;
52
56
  protected percentageValue: number;
53
57
  protected applicableTo: ApplicableTo;
@@ -87,33 +91,37 @@ declare class CouponModel extends BaseModel {
87
91
  /** Gets the specific customer ID this coupon is limited to, if any. */
88
92
  getCustomerId(): string;
89
93
  /** Gets the ISO date string from when the coupon is valid. */
90
- getValidFrom(): ISODateTime;
94
+ getValidFrom(): ISODateTimeUTC;
91
95
  /** Gets the ISO date string until when the coupon is valid. */
92
- getValidTo(): ISODateTime;
96
+ getValidTo(): ISODateTimeUTC;
93
97
  /**
94
98
  * Gets the list of minimum cart values required for the coupon across different regions.
95
99
  * Returns copies of the price objects.
96
100
  * @returns The full list of regional minimum cart values.
97
101
  */
98
- getMinCartValue(): RegionalPriceList;
102
+ getMinCartValue(): {
103
+ [country in CountryCode]?: PriceModel;
104
+ };
99
105
  /**
100
106
  * Gets the minimum cart value required for the coupon for a specific country.
101
107
  * @param country - The country code to filter the minimum value for.
102
108
  * @returns The regional minimum cart value for the specified country, or undefined if not set for that country.
103
109
  */
104
- getMinCartValue(country: CountryCode): RegionalPrice | undefined;
110
+ getMinCartValue(country: CountryCode): PriceModel | undefined;
105
111
  /**
106
112
  * Gets the list of maximum discount amounts allowed for the coupon across different regions.
107
113
  * Returns copies of the price objects.
108
114
  * @returns The full list of regional maximum discount caps.
109
115
  */
110
- getMaxCartDiscount(): RegionalPriceList;
116
+ getMaxCartDiscount(): {
117
+ [country in CountryCode]?: PriceModel;
118
+ };
111
119
  /**
112
120
  * Gets the maximum discount amount allowed for the coupon for a specific country.
113
121
  * @param country - The country code to filter the maximum discount for.
114
122
  * @returns The regional maximum discount cap for the specified country, or undefined if not set for that country.
115
123
  */
116
- getMaxCartDiscount(country: CountryCode): RegionalPrice | undefined;
124
+ getMaxCartDiscount(country: CountryCode): PriceModel | undefined;
117
125
  /** Gets the discount method (FLAT or PERCENTAGE). */
118
126
  getDiscountMethod(): CouponDiscountMethod;
119
127
  /** Gets the percentage discount value (0-100). */
@@ -138,6 +146,16 @@ declare class CouponModel extends BaseModel {
138
146
  * @returns True if the coupon's applicability rule matches the customer's status, false otherwise.
139
147
  */
140
148
  isApplicableTo(ftbCustomer: boolean): boolean;
149
+ /**
150
+ * Calculates the discount value for a given coupon based on the current container state.
151
+ * Returns 0 if the coupon is invalid, expired, or not applicable based on cart value or target category.
152
+ * @param cartValue - The cart subtotal as a PriceModel.
153
+ * @param shippingCost - The cart shipping cost.
154
+ * @param country - The country code.
155
+ * @param currency - The currency code.
156
+ * @returns The calculated discount amount (rounded according to country rules).
157
+ */
158
+ calculateApplicableCouponDiscount(cartValue: PriceModel, shippingCost: PriceModel, country: CountryCode, currency: CurrencyCode, checkExpiry?: boolean): PriceModel;
141
159
  }
142
160
 
143
161
  export { ApplicableTo, type CouponAttribute, CouponCategory, type CouponData, CouponDiscountMethod, CouponType, CouponModel as default };
@@ -1,5 +1,5 @@
1
1
  import BaseModel, { BaseAttributes } from './Base.js';
2
- import { LocalizedString, ISODateTime, RegionalPriceList, LocaleCode, CountryCode, RegionalPrice } from './Common.js';
2
+ import { c as LocalizedString, I as ISODateTimeUTC, R as RegionalPrice, C as CountryCode, b as PriceModel, L as LocaleCode, a as CurrencyCode } from '../Common-D-UoxwM0.js';
3
3
  import '../Auth/index.js';
4
4
  import './Enum.js';
5
5
 
@@ -25,10 +25,10 @@ type CouponAttribute = BaseAttributes & {
25
25
  description: LocalizedString;
26
26
  type: CouponType;
27
27
  customerId?: string;
28
- validFrom: ISODateTime;
29
- validTo: ISODateTime;
30
- minCartValue: RegionalPriceList;
31
- maxCartDiscount: RegionalPriceList;
28
+ validFrom: ISODateTimeUTC;
29
+ validTo: ISODateTimeUTC;
30
+ minCartValue: RegionalPrice;
31
+ maxCartDiscount: RegionalPrice;
32
32
  discountMethod: CouponDiscountMethod;
33
33
  percentageValue?: number;
34
34
  applicableTo: ApplicableTo;
@@ -44,10 +44,14 @@ declare class CouponModel extends BaseModel {
44
44
  protected description: LocalizedString;
45
45
  protected type: CouponType;
46
46
  protected customerId?: string;
47
- protected validFrom: ISODateTime;
48
- protected validTo: ISODateTime;
49
- protected minCartValue: RegionalPriceList;
50
- protected maxCartDiscount: RegionalPriceList;
47
+ protected validFrom: ISODateTimeUTC;
48
+ protected validTo: ISODateTimeUTC;
49
+ protected minCartValue: {
50
+ [country in CountryCode]?: PriceModel;
51
+ };
52
+ protected maxCartDiscount: {
53
+ [country in CountryCode]?: PriceModel;
54
+ };
51
55
  protected discountMethod: CouponDiscountMethod;
52
56
  protected percentageValue: number;
53
57
  protected applicableTo: ApplicableTo;
@@ -87,33 +91,37 @@ declare class CouponModel extends BaseModel {
87
91
  /** Gets the specific customer ID this coupon is limited to, if any. */
88
92
  getCustomerId(): string;
89
93
  /** Gets the ISO date string from when the coupon is valid. */
90
- getValidFrom(): ISODateTime;
94
+ getValidFrom(): ISODateTimeUTC;
91
95
  /** Gets the ISO date string until when the coupon is valid. */
92
- getValidTo(): ISODateTime;
96
+ getValidTo(): ISODateTimeUTC;
93
97
  /**
94
98
  * Gets the list of minimum cart values required for the coupon across different regions.
95
99
  * Returns copies of the price objects.
96
100
  * @returns The full list of regional minimum cart values.
97
101
  */
98
- getMinCartValue(): RegionalPriceList;
102
+ getMinCartValue(): {
103
+ [country in CountryCode]?: PriceModel;
104
+ };
99
105
  /**
100
106
  * Gets the minimum cart value required for the coupon for a specific country.
101
107
  * @param country - The country code to filter the minimum value for.
102
108
  * @returns The regional minimum cart value for the specified country, or undefined if not set for that country.
103
109
  */
104
- getMinCartValue(country: CountryCode): RegionalPrice | undefined;
110
+ getMinCartValue(country: CountryCode): PriceModel | undefined;
105
111
  /**
106
112
  * Gets the list of maximum discount amounts allowed for the coupon across different regions.
107
113
  * Returns copies of the price objects.
108
114
  * @returns The full list of regional maximum discount caps.
109
115
  */
110
- getMaxCartDiscount(): RegionalPriceList;
116
+ getMaxCartDiscount(): {
117
+ [country in CountryCode]?: PriceModel;
118
+ };
111
119
  /**
112
120
  * Gets the maximum discount amount allowed for the coupon for a specific country.
113
121
  * @param country - The country code to filter the maximum discount for.
114
122
  * @returns The regional maximum discount cap for the specified country, or undefined if not set for that country.
115
123
  */
116
- getMaxCartDiscount(country: CountryCode): RegionalPrice | undefined;
124
+ getMaxCartDiscount(country: CountryCode): PriceModel | undefined;
117
125
  /** Gets the discount method (FLAT or PERCENTAGE). */
118
126
  getDiscountMethod(): CouponDiscountMethod;
119
127
  /** Gets the percentage discount value (0-100). */
@@ -138,6 +146,16 @@ declare class CouponModel extends BaseModel {
138
146
  * @returns True if the coupon's applicability rule matches the customer's status, false otherwise.
139
147
  */
140
148
  isApplicableTo(ftbCustomer: boolean): boolean;
149
+ /**
150
+ * Calculates the discount value for a given coupon based on the current container state.
151
+ * Returns 0 if the coupon is invalid, expired, or not applicable based on cart value or target category.
152
+ * @param cartValue - The cart subtotal as a PriceModel.
153
+ * @param shippingCost - The cart shipping cost.
154
+ * @param country - The country code.
155
+ * @param currency - The currency code.
156
+ * @returns The calculated discount amount (rounded according to country rules).
157
+ */
158
+ calculateApplicableCouponDiscount(cartValue: PriceModel, shippingCost: PriceModel, country: CountryCode, currency: CurrencyCode, checkExpiry?: boolean): PriceModel;
141
159
  }
142
160
 
143
161
  export { ApplicableTo, type CouponAttribute, CouponCategory, type CouponData, CouponDiscountMethod, CouponType, CouponModel as default };
@@ -1,2 +1,2 @@
1
- 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var o=class{customFields;version;createdAt;modifiedAt;modifiedBy;constructor(e,t=new Date){this.customFields={...e.customFields},this.version=e.version??1,this.createdAt=e.createdAt&&!isNaN(Date.parse(e.createdAt))?new Date(e.createdAt).toISOString():t.toISOString(),this.modifiedAt=e.modifiedAt&&!isNaN(Date.parse(e.modifiedAt))?new Date(e.modifiedAt).toISOString():t.toISOString(),this.modifiedBy={...e.modifiedBy};}getDetails(){return {customFields:this.getAllCustomFields(),version:this.getVersion(),createdAt:this.getCreatedAt(),modifiedAt:this.getModifiedAt(),modifiedBy:this.getModifiedBy()}}getVersion(){return this.version}getCreatedAt(){return this.createdAt}getCreatedAtTime(){return new Date(this.createdAt).getTime()}getModifiedAt(){return this.modifiedAt}getModifiedAtTime(){return new Date(this.modifiedAt).getTime()}getModifiedBy(){return {...this.modifiedBy}}setModifiedBy(e,t,i,u){this.modifiedBy={id:e,authType:t,requestId:i,lambdaName:u};}getCustomField(e){return this.customFields[e]??null}setCustomField(e,t){this.customFields[e]=t;}getAllCustomFields(){return {...this.customFields}}};var r={"en-IN":"en","kn-IN":"kn"};var d=(t=>(t.COUPON="coupon",t.AUTOMATIC="automatic",t))(d||{}),c=(t=>(t.FLAT="flat",t.PERCENTAGE="percentage",t))(c||{}),l=(t=>(t.SHIPPING="SHIPPING",t.CUSTOMER="CUSTOMER",t))(l||{}),p=(t=>(t.ALL="all",t.FTB="ftb",t))(p||{}),n=class extends o{couponCode;name;description;type;customerId;validFrom;validTo;minCartValue;maxCartDiscount;discountMethod;percentageValue;applicableTo;category;constructor(e,t=new Date){super(e,t),this.couponCode=e.couponCode,this.name={...e.name},this.description={...e.description},this.type=e.type,this.customerId=e.customerId,this.validFrom=e.validFrom&&Date.parse(e.validFrom)?new Date(e.validFrom).toISOString():t.toISOString(),this.validTo=e.validTo&&Date.parse(e.validTo)?new Date(e.validTo).toISOString():t.toISOString(),this.minCartValue=e.minCartValue.map(i=>({...i})),this.maxCartDiscount=e.maxCartDiscount.map(i=>({...i})),this.discountMethod=e.discountMethod,this.percentageValue=e.percentageValue??0,this.applicableTo=e.applicableTo,this.category=e.category;}getCode(){return this.couponCode}getName(e){return e?this.name[e]??this.name[r[e]]??this.name.en:{...this.name}}getDescription(e){return e?this.description[e]??this.description[r[e]]??this.description.en:{...this.description}}getType(){return this.type}getCustomerId(){return this.customerId??""}getValidFrom(){return this.validFrom}getValidTo(){return this.validTo}getMinCartValue(e){return e?this.minCartValue.find(t=>t.country===e):this.minCartValue}getMaxCartDiscount(e){return e?this.maxCartDiscount.find(t=>t.country===e):this.maxCartDiscount}getDiscountMethod(){return this.discountMethod}getPercentageValue(){return this.percentageValue}getApplicableTo(){return this.applicableTo}getCategory(){return this.category}getDetails(){return {...super.getDetails(),couponCode:this.getCode(),name:this.getName(),description:this.getDescription(),type:this.getType(),customerId:this.getCustomerId(),validFrom:this.getValidFrom(),validTo:this.getValidTo(),minCartValue:this.getMinCartValue(),maxCartDiscount:this.getMaxCartDiscount(),discountMethod:this.getDiscountMethod(),percentageValue:this.getPercentageValue(),applicableTo:this.getApplicableTo(),category:this.getCategory()}}isActive(){return new Date(this.validFrom)<=new Date&&new Date(this.validTo)>=new Date}isApplicableTo(e){return this.applicableTo==="all"||this.applicableTo==="ftb"&&e}};exports.ApplicableTo=p;exports.CouponCategory=l;exports.CouponDiscountMethod=c;exports.CouponType=d;exports.default=n;//# sourceMappingURL=Coupon.js.map
1
+ 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var Z=require('crypto');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Z__default=/*#__PURE__*/_interopDefault(Z);var T=new Uint8Array(256),P=T.length;function O(){return P>T.length-16&&(Z__default.default.randomFillSync(T),P=0),T.slice(P,P+=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 X(r){return typeof r=="string"&&k.test(r)}var G=X;var d=[];for(let r=0;r<256;++r)d.push((r+256).toString(16).slice(1));function S(r,e=0){return d[r[e+0]]+d[r[e+1]]+d[r[e+2]]+d[r[e+3]]+"-"+d[r[e+4]]+d[r[e+5]]+"-"+d[r[e+6]]+d[r[e+7]]+"-"+d[r[e+8]]+d[r[e+9]]+"-"+d[r[e+10]]+d[r[e+11]]+d[r[e+12]]+d[r[e+13]]+d[r[e+14]]+d[r[e+15]]}function W(r){if(!G(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 Q=W;function J(r){r=unescape(encodeURIComponent(r));let e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t));return e}var _="6ba7b810-9dad-11d1-80b4-00c04fd430c8",ee="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function F(r,e,t){function i(n,o,s,p){var a;if(typeof n=="string"&&(n=J(n)),typeof o=="string"&&(o=Q(o)),((a=o)===null||a===void 0?void 0:a.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let c=new Uint8Array(16+n.length);if(c.set(o),c.set(n,o.length),c=t(c),c[6]=c[6]&15|e,c[8]=c[8]&63|128,s){p=p||0;for(let C=0;C<16;++C)s[p+C]=c[C];return s}return S(c)}try{i.name=r;}catch{}return i.DNS=_,i.URL=ee,i}var V={randomUUID:Z__default.default.randomUUID};function re(r,e,t){if(V.randomUUID&&!e&&!r)return V.randomUUID();r=r||{};let i=r.random||(r.rng||O)();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 S(i)}var z=re;function ne(r){return Array.isArray(r)?r=Buffer.from(r):typeof r=="string"&&(r=Buffer.from(r,"utf8")),Z__default.default.createHash("sha1").update(r).digest()}var K=ne;var oe=F("v5",80,K),B=oe;var f=class{customFields;version;createdAt;modifiedAt;modifiedBy;constructor(e,t=new Date){this.customFields={...e.customFields},this.version=e.version??1,this.createdAt=e.createdAt&&!isNaN(Date.parse(e.createdAt))?new Date(e.createdAt).toISOString():t.toISOString(),this.modifiedAt=e.modifiedAt&&!isNaN(Date.parse(e.modifiedAt))?new Date(e.modifiedAt).toISOString():t.toISOString(),this.modifiedBy={...e.modifiedBy};}getDetails(){return {customFields:this.getAllCustomFields(),version:this.getVersion(),createdAt:this.getCreatedAt(),modifiedAt:this.getModifiedAt(),modifiedBy:this.getModifiedBy()}}getVersion(){return this.version}getCreatedAt(){return this.createdAt}getCreatedAtTime(){return new Date(this.createdAt).getTime()}getModifiedAt(){return this.modifiedAt}getModifiedAtTime(){return new Date(this.modifiedAt).getTime()}getModifiedBy(){return {...this.modifiedBy}}setModifiedBy(e,t,i,n){this.modifiedBy={id:e,authType:t,requestId:i,lambdaName:n};}getCustomField(e){return this.customFields[e]??null}setCustomField(e,t){this.customFields[e]=t;}getAllCustomFields(){return {...this.customFields}}};var y={"en-IN":"en","kn-IN":"kn"};var H={INR:"\u20B9"},Y={INR:"en-IN"};var M=class extends Error{constructor(e="Failed to parse selection attributes key."){super(`SelectionAttributeParseError: ${e}`),this.name="SelectionAttributeParseError";}};var v=class extends Error{constructor(e="Tax category is not valid."){super(`InvalidTaxCategory: ${e}`),this.name="InvalidTaxCategoryError";}},w=class extends Error{constructor(e="Minimum quantity must be greater than zero."){super(`InvalidMinQuantity: ${e}`),this.name="InvalidMinQuantityError";}},E=class extends Error{constructor(e){super(`InvalidTieredPrice: ${e}`),this.name="InvalidTieredPriceError";}},L=class extends Error{constructor(e="Quantity must be greater than zero."){super(`InvalidQuantity: ${e}`),this.name="InvalidQuantityError";}},R=class extends Error{constructor(e){super(`NoApplicableTier: Quantity ${e} does not meet the minimum purchase requirement.`),this.name="NoApplicableTierError";}};var A=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";}},x=class extends Error{constructor(e="Invalid image source configuration."){super(`InvalidImageSource: ${e}`),this.name="InvalidImageSourceError";}};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 x("ImageInfoModel cannot be created without an 'original' source URL.")}getSources(){return {...this.sources}}getSource(e){return this.sources[e]||this.sources.original}getAlt(){return this.alt}getOrder(){return this.order}getLabel(){return this.label}setAlt(e){this.alt=e;}setOrder(e){this.order=e;}setLabel(e){this.label=e;}setSource(e,t){if(t===void 0){if(e==="original")throw new x("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 h=class r{amount;currency;constructor(e){if(e.amount<0)throw new A("Amount cannot be negative.");if(!e.currency)throw new b("Currency code is required.");this.amount=e.amount,this.currency=e.currency;}getCurrency(){return this.currency}getAmount(){return this.amount}getDetails(){return {amount:this.amount,currency:this.currency}}compareTo(e){if(e instanceof r){if(this.currency!==e.getCurrency())throw new m("Cannot compare prices in different currencies.")}else throw new g("Must be a PriceModel instance.");return this.amount-e.getAmount()}add(e){if(e instanceof r){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 r({amount:this.amount+e.getAmount(),currency:this.currency})}subtract(e){if(e instanceof r){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 r({amount:this.amount-e.getAmount(),currency:this.currency})}multiply(e){if(e instanceof r){if(this.currency!==e.getCurrency())throw new m("Cannot multiply prices in different currencies.");return new r({amount:this.amount*e.getAmount(),currency:this.currency})}else if(typeof e=="number"&&e>=0)return new r({amount:this.amount*e,currency:this.currency});throw new g("Must be a non-negative number.")}divide(e){if(e instanceof r){if(this.currency!==e.getCurrency())throw new m("Cannot divide prices in different currencies.");return new r({amount:this.amount/e.getAmount(),currency:this.currency})}else if(typeof e=="number"&&e>0)return new r({amount:this.amount/e,currency:this.currency});throw new g("Must be a positive number.")}min(...e){if(e.length===0)throw new g("Must provide at least one PriceModel.");return e.reduce((t,i)=>{if(i instanceof r){if(t.getCurrency()!==i.getCurrency())throw new m("Cannot compare prices in different currencies.")}else throw new g("Must be a PriceModel instance.");return t.compareTo(i)<0?t:i})}max(...e){if(e.length===0)throw new g("Must provide at least one PriceModel.");return e.reduce((t,i)=>{if(i instanceof r){if(t.getCurrency()!==i.getCurrency())throw new m("Cannot compare prices in different currencies.")}else throw new g("Must be a PriceModel instance.");return t.compareTo(i)>0?t:i})}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)}static getFormattedString(e,t,i={displayAsInteger:!1,style:"currency",currencyDisplay:"symbol"}){let n=Y[t];if(!t||!n)throw new b("Invalid currency code for formatting.");let o=e,s=i.displayAsInteger?0:r.getDecimalPlaces(t),p={style:i.style??"currency",currency:t,signDisplay:"never",currencyDisplay:i.currencyDisplay,minimumFractionDigits:s,maximumFractionDigits:s};i.displayAsInteger&&(o=Math.ceil(o));try{return new Intl.NumberFormat(n,p).format(o)}catch(a){return console.error(`Error formatting price for currency "${t}" and locale "${n}":`,a),`${H[t]??t} ${r.addThousandSeparators(o.toFixed(s))}`}}static getDecimalPlaces(e){switch(e){case"INR":default:return 2}}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 A("Amount cannot be negative for rounding.");if(t===void 0)throw new b("Invalid currency code for rounding.");let i=r.getDecimalPlaces(t),n=Math.pow(10,i);return Math.round(e*n)/n}};var N=class{baseUnitPrice;taxCategory;tiers;constructor(e){let t=new h(e.baseUnitPrice);if(!e.taxCategory)throw new v;let i=(e.tiers??[]).map(a=>({minQuantity:a.minQuantity,unitPrice:new h(a.unitPrice)})).sort((a,c)=>a.minQuantity-c.minQuantity);if(i.some(a=>a.minQuantity<=0))throw new w;let o=i.some(a=>a.unitPrice.getCurrency()!==t.getCurrency()),s=i.some((a,c)=>c>0&&a.unitPrice.compareTo(i[c-1].unitPrice)>0),p=i[0]?.unitPrice.compareTo(t)>0;if(o||s||p)throw new E("Tiers must share the same currency and must not increase in unit price.");this.baseUnitPrice=t,this.taxCategory=e.taxCategory,this.tiers=i;}getBaseUnitPrice(){return this.baseUnitPrice}getTaxCategory(){return this.taxCategory}getTiers(){return this.tiers}getDetails(){return {baseUnitPrice:this.baseUnitPrice.getDetails(),taxCategory:this.taxCategory,tiers:this.tiers.map(e=>({minQuantity:e.minQuantity,unitPrice:e.unitPrice.getDetails()}))}}getApplicableTier(e){if(e<=0)throw new L;for(let t=this.tiers.length-1;t>=0;t--)if(e>=this.tiers[t].minQuantity)return this.tiers[t];throw new R(e)}getMinQuantity(){return this.tiers[0]?.minQuantity??1}getMaxDiscountPercent(){if(!this.tiers.length)return 0;let e=this.tiers[this.tiers.length-1].unitPrice.getAmount(),t=this.baseUnitPrice.getAmount();return (t-e)/t*100}};var D=class r extends f{id;key;name;description;slug;brand;pricing;variants;targetGender;attributes;specifications;categories;isActive;searchTags;static productKeyRegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static productSKURegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static generateSelectionAttributesKey(e){return Object.keys(e).filter(i=>e[i]!==void 0&&i.toLowerCase()!=="size").sort().map(i=>e[i].name?`${i}:c+${e[i].name}`:`${i}:${e[i]}`).join("|")}static parseSelectionAttributesKey(e){try{let t={},i=e.split("|");for(let n of i){let[o,s]=n.split(":");s.startsWith("c+")?t[o]={name:s.slice(2)}:t[o]=s;}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((i,n)=>(e.pricing[n]&&(i[n]=new N(e.pricing[n])),i),{}),this.targetGender=e.targetGender,this.attributes=l.deepClone(e.attributes),this.specifications=l.deepClone(e.specifications),this.categories=l.deepClone(e.categories),this.variants=(e.variants||[]).map(i=>({sku:i.sku,selectionAttributes:i.selectionAttributes,images:{primary:new I(i.images.primary),gallery:(i.images.gallery||[]).map(n=>new I(n))}})),this.isActive=e.isActive,this.searchTags=e.searchTags?l.deepClone(e.searchTags):{en:[]};}getId(){return this.id}getKey(){return this.key}getName(e){return e?this.name[e]??this.name[y[e]]??this.name.en:l.deepClone(this.name)}getDescription(e){return e?this.description[e]??this.description[y[e]]??this.description.en:l.deepClone(this.description)}getSlug(e){return e?this.slug[e]??this.slug[y[e]]??this.slug.en:l.deepClone(this.slug)}getBrand(){return this.brand}getPriceDetails(e){return e?this.pricing[e]??null:this.pricing}getAttributes(){return l.deepClone(this.attributes)}getImagesBySelectionAttributes(e){let t=r.generateSelectionAttributesKey(e),i=this.variants.find(n=>r.generateSelectionAttributesKey(n.selectionAttributes)===t);return i?i.images:null}getImages(e,t){switch(t){case"PRIMARY":return this.getImagesBySelectionAttributes(e)?.primary??this.variants[0]?.images?.primary;case"GALLERY":return this.getImagesBySelectionAttributes(e)?.gallery??[];default:return this.getImagesBySelectionAttributes(e)??{primary:this.variants[0]?.images?.primary,gallery:[]}}}getIsActive(){return this.isActive}getTargetGender(){return this.targetGender}getCategories(){return l.deepClone(this.categories)}getSpecifications(e){return e?l.deepClone(this.specifications[e]??this.specifications[y[e]]??this.specifications.en):l.deepClone(this.specifications)}getSearchTags(e){return e?l.deepClone(this.searchTags[e]??this.searchTags[y[e]]??this.searchTags.en):l.deepClone(this.searchTags)}getDetails(){let e=super.getDetails();return {id:this.getId(),key:this.getKey(),name:this.getName(),description:this.getDescription(),slug:this.getSlug(),brand:this.getBrand(),pricing:Object.keys(this.pricing).reduce((t,i)=>(this.pricing[i]&&(t[i]=this.pricing[i]?.getDetails()),t),{}),attributes:this.getAttributes(),variants:this.variants.map(t=>({sku:t.sku,selectionAttributes:l.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(),specifications:this.getSpecifications(),searchTags:this.getSearchTags(),...e}}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)}};var se={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?B(r,e):z(),generateSearchId:(r,e)=>`${r}#${D.generateSelectionAttributesKey(e)}`,getKeyfromSearchId:r=>{let[e,t]=r.split("#");return {key:e,selectionAttribute:t}},deepClone(r){return structuredClone(r)}},l=se;var ae=(t=>(t.COUPON="coupon",t.AUTOMATIC="automatic",t))(ae||{}),ce=(t=>(t.FLAT="flat",t.PERCENTAGE="percentage",t))(ce||{}),ue=(t=>(t.SHIPPING="SHIPPING",t.CUSTOMER="CUSTOMER",t))(ue||{}),le=(t=>(t.ALL="all",t.FTB="ftb",t))(le||{}),$=class extends f{couponCode;name;description;type;customerId;validFrom;validTo;minCartValue;maxCartDiscount;discountMethod;percentageValue;applicableTo;category;constructor(e,t=new Date){if(super(e,t),this.couponCode=e.couponCode,this.name=l.deepClone(e.name),this.description=l.deepClone(e.description),this.type=e.type,this.customerId=e.customerId,this.validFrom=e.validFrom&&Date.parse(e.validFrom)?new Date(e.validFrom).toISOString():t.toISOString(),this.validTo=e.validTo&&Date.parse(e.validTo)?new Date(e.validTo).toISOString():t.toISOString(),this.minCartValue=Object.keys(e.minCartValue).reduce((i,n)=>{let o=e.minCartValue[n];return o&&(i[n]=new h(o)),i},{}),this.maxCartDiscount=Object.keys(e.maxCartDiscount).reduce((i,n)=>{let o=e.maxCartDiscount[n];return o&&(i[n]=new h(o)),i},{}),this.discountMethod=e.discountMethod,this.percentageValue=e.percentageValue??0,this.percentageValue>100)throw new g("Percentage value cannot be greater than 100");this.applicableTo=e.applicableTo,this.category=e.category;}getCode(){return this.couponCode}getName(e){return e?this.name[e]??this.name[y[e]]??this.name.en:{...this.name}}getDescription(e){return e?this.description[e]??this.description[y[e]]??this.description.en:{...this.description}}getType(){return this.type}getCustomerId(){return this.customerId??""}getValidFrom(){return this.validFrom}getValidTo(){return this.validTo}getMinCartValue(e){return e?this.minCartValue[e]:this.minCartValue}getMaxCartDiscount(e){return e?this.maxCartDiscount[e]:this.maxCartDiscount}getDiscountMethod(){return this.discountMethod}getPercentageValue(){return this.percentageValue}getApplicableTo(){return this.applicableTo}getCategory(){return this.category}getDetails(){return {...super.getDetails(),couponCode:this.getCode(),name:this.getName(),description:this.getDescription(),type:this.getType(),customerId:this.getCustomerId(),validFrom:this.getValidFrom(),validTo:this.getValidTo(),minCartValue:Object.keys(this.getMinCartValue()).reduce((e,t)=>{let i=this.getMinCartValue(t);return i&&(e[t]=i.getDetails()),e},{}),maxCartDiscount:Object.keys(this.getMaxCartDiscount()).reduce((e,t)=>{let i=this.getMaxCartDiscount(t);return i&&(e[t]=i.getDetails()),e},{}),discountMethod:this.getDiscountMethod(),percentageValue:this.getPercentageValue(),applicableTo:this.getApplicableTo(),category:this.getCategory()}}isActive(){return new Date(this.validFrom)<=new Date&&new Date(this.validTo)>=new Date}isApplicableTo(e){return this.applicableTo==="all"||this.applicableTo==="ftb"&&e}calculateApplicableCouponDiscount(e,t,i,n,o=!0){let s=new h({amount:0,currency:n}),p;if(o&&!this.isActive())return s;let a=this.getMinCartValue(i),c=this.getMaxCartDiscount(i);if(!a||a.compareTo(e)>0||!c)return s;let C=this.getCategory(),j=this.getDiscountMethod(),U=C==="SHIPPING"?t:e;if(U.getAmount()<=0)return s;switch(j){case"flat":let q=c;p=U.min(q);break;case"percentage":p=U.multiply(this.getPercentageValue()/100).round();break;default:return s}return p.min(c)}};exports.ApplicableTo=le;exports.CouponCategory=ue;exports.CouponDiscountMethod=ce;exports.CouponType=ae;exports.default=$;//# sourceMappingURL=Coupon.js.map
2
2
  //# sourceMappingURL=Coupon.js.map