b23-lib 2.2.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) 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/Classes/Cart.d.mts +1 -0
  5. package/dist/Classes/Cart.d.ts +1 -0
  6. package/dist/Classes/Cart.js +1 -2
  7. package/dist/Classes/Cart.js.map +1 -1
  8. package/dist/Classes/Cart.mjs +1 -1
  9. package/dist/Classes/Cart.mjs.map +1 -1
  10. package/dist/Classes/Charge.d.mts +99 -0
  11. package/dist/Classes/Charge.d.ts +99 -0
  12. package/dist/Classes/Charge.js +2 -0
  13. package/dist/Classes/Charge.js.map +1 -0
  14. package/dist/Classes/Charge.mjs +2 -0
  15. package/dist/Classes/Charge.mjs.map +1 -0
  16. package/dist/Classes/Coupon.js +1 -1
  17. package/dist/Classes/Coupon.js.map +1 -1
  18. package/dist/Classes/Coupon.mjs +1 -1
  19. package/dist/Classes/Enum.d.mts +4 -4
  20. package/dist/Classes/Enum.d.ts +4 -4
  21. package/dist/Classes/Enum.js +1 -1
  22. package/dist/Classes/Enum.js.map +1 -1
  23. package/dist/Classes/Enum.mjs +1 -1
  24. package/dist/Classes/Error.d.mts +4 -1
  25. package/dist/Classes/Error.d.ts +4 -1
  26. package/dist/Classes/Error.js +1 -1
  27. package/dist/Classes/Error.js.map +1 -1
  28. package/dist/Classes/Error.mjs +1 -1
  29. package/dist/Classes/ImageInfo.js.map +1 -1
  30. package/dist/Classes/ImageInfo.mjs +1 -1
  31. package/dist/Classes/Inventory.js +1 -1
  32. package/dist/Classes/Inventory.js.map +1 -1
  33. package/dist/Classes/Inventory.mjs +1 -1
  34. package/dist/Classes/LineItem.d.mts +46 -48
  35. package/dist/Classes/LineItem.d.ts +46 -48
  36. package/dist/Classes/LineItem.js +1 -2
  37. package/dist/Classes/LineItem.js.map +1 -1
  38. package/dist/Classes/LineItem.mjs +1 -1
  39. package/dist/Classes/Order.d.mts +1 -1
  40. package/dist/Classes/Order.d.ts +1 -1
  41. package/dist/Classes/Order.js +1 -2
  42. package/dist/Classes/Order.js.map +1 -1
  43. package/dist/Classes/Order.mjs +1 -1
  44. package/dist/Classes/Order.mjs.map +1 -1
  45. package/dist/Classes/Price.js +1 -1
  46. package/dist/Classes/Price.js.map +1 -1
  47. package/dist/Classes/Price.mjs +1 -1
  48. package/dist/Classes/Product.js +1 -1
  49. package/dist/Classes/Product.js.map +1 -1
  50. package/dist/Classes/Product.mjs +1 -1
  51. package/dist/Classes/ShoppingContainer.d.mts +98 -40
  52. package/dist/Classes/ShoppingContainer.d.ts +98 -40
  53. package/dist/Classes/ShoppingContainer.js +1 -2
  54. package/dist/Classes/ShoppingContainer.js.map +1 -1
  55. package/dist/Classes/ShoppingContainer.mjs +1 -1
  56. package/dist/Classes/TaxCategoryModel.d.mts +42 -0
  57. package/dist/Classes/TaxCategoryModel.d.ts +42 -0
  58. package/dist/Classes/TaxCategoryModel.js +2 -0
  59. package/dist/Classes/TaxCategoryModel.js.map +1 -0
  60. package/dist/Classes/TaxCategoryModel.mjs +2 -0
  61. package/dist/Classes/TaxCategoryModel.mjs.map +1 -0
  62. package/dist/Classes/TaxRule.d.mts +59 -79
  63. package/dist/Classes/TaxRule.d.ts +59 -79
  64. package/dist/Classes/TaxRule.js +1 -2
  65. package/dist/Classes/TaxRule.js.map +1 -1
  66. package/dist/Classes/TaxRule.mjs +1 -1
  67. package/dist/Classes/TieredPrice.d.mts +4 -4
  68. package/dist/Classes/TieredPrice.d.ts +4 -4
  69. package/dist/Classes/TieredPrice.js +1 -1
  70. package/dist/Classes/TieredPrice.js.map +1 -1
  71. package/dist/Classes/TieredPrice.mjs +1 -1
  72. package/dist/{chunk-EV4HUBJL.mjs → chunk-6X5O25W5.mjs} +2 -2
  73. package/dist/chunk-6X5O25W5.mjs.map +1 -0
  74. package/dist/chunk-FC4P26U3.mjs +2 -0
  75. package/dist/chunk-FC4P26U3.mjs.map +1 -0
  76. package/dist/chunk-IIPG3DTO.mjs +2 -0
  77. package/dist/chunk-IIPG3DTO.mjs.map +1 -0
  78. package/dist/{chunk-LEHPVA3Q.mjs → chunk-JE7BAYI5.mjs} +2 -2
  79. package/dist/{chunk-LEHPVA3Q.mjs.map → chunk-JE7BAYI5.mjs.map} +1 -1
  80. package/dist/chunk-KKQLCW6A.mjs +2 -0
  81. package/dist/chunk-KKQLCW6A.mjs.map +1 -0
  82. package/dist/chunk-PTIPDRB4.mjs +2 -0
  83. package/dist/chunk-PTIPDRB4.mjs.map +1 -0
  84. package/dist/{chunk-GF427QWC.mjs → chunk-RSMXGZD4.mjs} +2 -2
  85. package/dist/{chunk-GF427QWC.mjs.map → chunk-RSMXGZD4.mjs.map} +1 -1
  86. package/dist/{chunk-WSUPVXRZ.mjs → chunk-RSTZJZSQ.mjs} +2 -2
  87. package/dist/{chunk-WSUPVXRZ.mjs.map → chunk-RSTZJZSQ.mjs.map} +1 -1
  88. package/dist/chunk-U7DES3CI.mjs +2 -0
  89. package/dist/chunk-U7DES3CI.mjs.map +1 -0
  90. package/dist/{chunk-JHELVQYY.mjs → chunk-XPKK6DFA.mjs} +2 -2
  91. package/dist/chunk-XPKK6DFA.mjs.map +1 -0
  92. package/dist/chunk-XXETAAL4.mjs +2 -0
  93. package/dist/chunk-XXETAAL4.mjs.map +1 -0
  94. package/dist/index.d.mts +1 -5
  95. package/dist/index.d.ts +1 -5
  96. package/dist/index.js +2 -2
  97. package/dist/index.js.map +1 -1
  98. package/dist/index.mjs +2 -2
  99. package/dist/index.mjs.map +1 -1
  100. package/package.json +21 -1
  101. package/dist/chunk-43SMYXYL.mjs +0 -2
  102. package/dist/chunk-43SMYXYL.mjs.map +0 -1
  103. package/dist/chunk-5VI4V3SF.mjs +0 -2
  104. package/dist/chunk-5VI4V3SF.mjs.map +0 -1
  105. package/dist/chunk-72DR3HF2.mjs +0 -2
  106. package/dist/chunk-72DR3HF2.mjs.map +0 -1
  107. package/dist/chunk-CKJONVT3.mjs +0 -2
  108. package/dist/chunk-CKJONVT3.mjs.map +0 -1
  109. package/dist/chunk-EV4HUBJL.mjs.map +0 -1
  110. package/dist/chunk-JHELVQYY.mjs.map +0 -1
  111. package/dist/chunk-RQC4PNOV.mjs +0 -3
  112. package/dist/chunk-RQC4PNOV.mjs.map +0 -1
@@ -1,2 +1,2 @@
1
- import {i,h}from'./chunk-72DR3HF2.mjs';import {q,r,s,t}from'./chunk-JHELVQYY.mjs';var d=class t$1{#e;amount;currency;constructor(e){if(this.#e="PriceModel",e.amount<0)throw new q("Amount cannot be negative.");if(!e.currency)throw new r("Currency code is required.");this.amount=e.amount,this.currency=e.currency;}get kind(){return this.#e}static isPriceModel(e){return typeof e=="object"&&e!==null&&e.kind==="PriceModel"}getCurrency(){return this.currency}getAmount(){return this.amount}getDetails(){return {amount:this.amount,currency:this.currency}}compareTo(e){if(t$1.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new s("Cannot compare prices in different currencies.")}else throw new t("Must be a PriceModel instance.");return this.amount-e.getAmount()}add(e){if(t$1.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new s("Cannot add prices in different currencies.")}else throw new t("Must be a PriceModel instance.");return new t$1({amount:this.amount+e.getAmount(),currency:this.currency})}subtract(e){if(t$1.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new s("Cannot subtract prices in different currencies.")}else throw new t("Must be a PriceModel instance.");return new t$1({amount:this.amount-e.getAmount(),currency:this.currency})}multiply(e){if(t$1.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new s("Cannot multiply prices in different currencies.");return new t$1({amount:this.amount*e.getAmount(),currency:this.currency})}else if(typeof e=="number"&&e>=0)return new t$1({amount:this.amount*e,currency:this.currency});throw new t("Must be a non-negative number.")}divide(e){if(t$1.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new s("Cannot divide prices in different currencies.");return new t$1({amount:this.amount/e.getAmount(),currency:this.currency})}else if(typeof e=="number"&&e>0)return new t$1({amount:this.amount/e,currency:this.currency});throw new t("Must be a positive number.")}min(...e){if(e.length===0)throw new t("Must provide at least one PriceModel.");return e.reduce((r,n)=>{if(t$1.isPriceModel(n)){if(r.getCurrency()!==n.getCurrency())throw new s("Cannot compare prices in different currencies.")}else throw new t("Must be a PriceModel instance.");return r.compareTo(n)<0?r:n},this)}max(...e){if(e.length===0)throw new t("Must provide at least one PriceModel.");return e.reduce((r,n)=>{if(t$1.isPriceModel(n)){if(r.getCurrency()!==n.getCurrency())throw new s("Cannot compare prices in different currencies.")}else throw new t("Must be a PriceModel instance.");return r.compareTo(n)>0?r:n},this)}zero(){return new t$1({currency:this.currency,amount:0})}isZero(){return this.amount===0}round(){return new t$1({currency:this.currency,amount:this.getRoundedAmount()})}getRoundedAmount(){return t$1.getRoundedAmount(this.amount,this.currency)}getFormattedString(){return t$1.getFormattedString(this.amount,this.currency)}toString(){return this.getFormattedString()}static getFormattedString(e,r$1,n={displayAsInteger:!1,style:"currency",currencyDisplay:"symbol"}){let c=i[r$1];if(!r$1||!c)throw new r("Invalid currency code for formatting.");let o=e,a=n.displayAsInteger?0:t$1.getDecimalPlaces(r$1),h$1={style:n.style??"currency",currency:r$1,signDisplay:"never",currencyDisplay:n.currencyDisplay,minimumFractionDigits:a,maximumFractionDigits:a};n.displayAsInteger&&(o=Math.ceil(o));try{return new Intl.NumberFormat(c,h$1).format(o)}catch(g){return console.error(`Error formatting price for currency "${r$1}" and locale "${c}":`,g),`${h[r$1]??r$1} ${t$1.addThousandSeparators(o.toFixed(a))}`}}static getDecimalPlaces(e){switch(e){case"INR":default:return 2}}static addThousandSeparators(e){let r=e.split("."),n=r[0],c=r.length>1?"."+r[1]:"";return n.replace(/\B(?=(\d{3})+(?!\d))/g,",")+c}static getRoundedAmount(e,r$1){if(e<0)throw new q("Amount cannot be negative for rounding.");if(r$1===void 0)throw new r("Invalid currency code for rounding.");let n=t$1.getDecimalPlaces(r$1),c=Math.pow(10,n);return Math.round(e*c)/c}};export{d as a};//# sourceMappingURL=chunk-EV4HUBJL.mjs.map
2
- //# sourceMappingURL=chunk-EV4HUBJL.mjs.map
1
+ import {i,h}from'./chunk-FC4P26U3.mjs';import {q,r,s,t}from'./chunk-XPKK6DFA.mjs';var d=class t$1{#e;amount;currency;constructor(e){if(this.#e="PriceModel",e.amount<0)throw new q("Amount cannot be negative.");if(!e.currency)throw new r("Currency code is required.");this.amount=e.amount,this.currency=e.currency;}get kind(){return this.#e}static isPriceModel(e){return typeof e=="object"&&e!==null&&e.kind==="PriceModel"}getCurrency(){return this.currency}getAmount(){return this.amount}getDetails(){return {amount:this.amount,currency:this.currency}}compareTo(e){if(t$1.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new s("Cannot compare prices in different currencies.")}else throw new t("Must be a PriceModel instance.");return this.amount-e.getAmount()}add(e){if(t$1.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new s("Cannot add prices in different currencies.")}else throw new t("Must be a PriceModel instance.");return new t$1({amount:this.amount+e.getAmount(),currency:this.currency})}subtract(e){if(t$1.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new s("Cannot subtract prices in different currencies.")}else throw new t("Must be a PriceModel instance.");return new t$1({amount:this.amount-e.getAmount(),currency:this.currency})}multiply(e){if(t$1.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new s("Cannot multiply prices in different currencies.");return new t$1({amount:this.amount*e.getAmount(),currency:this.currency})}else if(typeof e=="number"&&e>=0)return new t$1({amount:this.amount*e,currency:this.currency});throw new t("Must be a non-negative number.")}divide(e){if(t$1.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new s("Cannot divide prices in different currencies.");return new t$1({amount:this.amount/e.getAmount(),currency:this.currency})}else if(typeof e=="number"&&e>0)return new t$1({amount:this.amount/e,currency:this.currency});throw new t("Must be a positive number.")}min(...e){if(e.length===0)throw new t("Must provide at least one PriceModel.");return e.reduce((r,n)=>{if(t$1.isPriceModel(n)){if(r.getCurrency()!==n.getCurrency())throw new s("Cannot compare prices in different currencies.")}else throw new t("Must be a PriceModel instance.");return r.compareTo(n)<0?r:n},this)}max(...e){if(e.length===0)throw new t("Must provide at least one PriceModel.");return e.reduce((r,n)=>{if(t$1.isPriceModel(n)){if(r.getCurrency()!==n.getCurrency())throw new s("Cannot compare prices in different currencies.")}else throw new t("Must be a PriceModel instance.");return r.compareTo(n)>0?r:n},this)}zero(){return new t$1({currency:this.currency,amount:0})}isZero(){return this.amount===0}round(){return new t$1({currency:this.currency,amount:this.getRoundedAmount()})}getRoundedAmount(){return t$1.getRoundedAmount(this.amount,this.currency)}getFormattedString(){return t$1.getFormattedString(this.amount,this.currency)}toString(){return this.getFormattedString()}static getFormattedString(e,r$1,n={displayAsInteger:!1,style:"currency",currencyDisplay:"symbol"}){let c=i[r$1];if(!r$1||!c)throw new r("Invalid currency code for formatting.");let o=e,a=n.displayAsInteger?0:t$1.getDecimalPlaces(r$1),h$1={style:n.style??"currency",currency:r$1,signDisplay:"never",currencyDisplay:n.currencyDisplay,minimumFractionDigits:a,maximumFractionDigits:a};n.displayAsInteger&&(o=Math.ceil(o));try{return new Intl.NumberFormat(c,h$1).format(o)}catch(g){return console.error(`Error formatting price for currency "${r$1}" and locale "${c}":`,g),`${h[r$1]??r$1} ${t$1.addThousandSeparators(o.toFixed(a))}`}}static getDecimalPlaces(e){switch(e){case"INR":default:return 2}}static addThousandSeparators(e){let r=e.split("."),n=r[0],c=r.length>1?"."+r[1]:"";return n.replace(/\B(?=(\d{3})+(?!\d))/g,",")+c}static getRoundedAmount(e,r$1){if(e<0)throw new q("Amount cannot be negative for rounding.");if(r$1===void 0)throw new r("Invalid currency code for rounding.");let n=t$1.getDecimalPlaces(r$1),c=Math.pow(10,n);return Math.round(e*c)/c}};export{d as a};//# sourceMappingURL=chunk-6X5O25W5.mjs.map
2
+ //# sourceMappingURL=chunk-6X5O25W5.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/Classes/Price.ts"],"names":["PriceModel","_PriceModel","#kind","data","InvalidPriceAmountError","InvalidCurrencyCodeError","obj","priceModel","CurrencyMismatchError","InvalidArgumentError","factor","divisor","priceModels","minPrice","currentPrice","maxPrice","amount","currency","options","locale","CurrencyLocaleMap","valueToFormat","fractionDigits","formattingOptions","error","CurrencySymbolMap","numStr","parts","integerPart","decimalPart","decimalPlaces","multiplier"],"mappings":"kFAgBA,IAAqBA,EAArB,MAAqBC,GAAW,CAC9BC,EAAAA,CACU,OACA,QAQV,CAAA,WAAA,CAAYC,CAAuB,CAAA,CAEjC,GADA,IAAKD,CAAAA,EAAAA,CAAQ,aACTC,CAAK,CAAA,MAAA,CAAS,EAChB,MAAM,IAAIC,CAAwB,CAAA,4BAA4B,EAGhE,GAAI,CAACD,CAAK,CAAA,QAAA,CACR,MAAM,IAAIE,CAAAA,CAAyB,4BAA4B,CAAA,CAGjE,KAAK,MAASF,CAAAA,CAAAA,CAAK,OACnB,IAAK,CAAA,QAAA,CAAWA,EAAK,SACvB,CAEA,IAAI,IAAA,EAAO,CACT,OAAO,IAAA,CAAKD,EACd,CAEA,OAAO,YAAaI,CAAAA,CAAAA,CAAiC,CACnD,OAAO,OAAOA,CAAQ,EAAA,QAAA,EACpBA,IAAQ,IACPA,EAAAA,CAAAA,CAAY,OAAS,YAC1B,CAMO,WAA4B,EAAA,CACjC,OAAO,IAAK,CAAA,QACd,CAKO,SAAoB,EAAA,CACzB,OAAO,IAAK,CAAA,MACd,CAMO,UAAA,EAAwB,CAC7B,OAAO,CACL,OAAQ,IAAK,CAAA,MAAA,CACb,SAAU,IAAK,CAAA,QACjB,CACF,CAoCO,UAAUC,CAAgC,CAAA,CAC/C,GAAKN,GAAAA,CAAW,aAAaM,CAAU,CAAA,CAAA,CAEhC,GAAI,IAAA,CAAK,WAAaA,CAAW,CAAA,WAAA,GACtC,MAAM,IAAIC,EAAsB,gDAAgD,CAAA,CAAA,KAF1E,MAAA,IAAIC,EAAqB,gCAAgC,CAAA,CAKjE,O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I,EAGxD,CAAA,OADyBC,EAAY,OAAQ,CAAA,uBAAA,CAAyB,GAAG,CAC/CC,CAAAA,CAC5B,CAWA,OAAO,iBAAiBb,CAAgBC,CAAAA,GAAAA,CAAgC,CACtE,GAAID,EAAS,CACX,CAAA,MAAM,IAAIZ,CAAAA,CAAwB,yCAAyC,CAG7E,CAAA,GAAIa,MAAa,KACf,CAAA,CAAA,MAAM,IAAIZ,CAAyB,CAAA,qCAAqC,CAG1E,CAAA,IAAMyB,EAAgB7B,GAAW,CAAA,gBAAA,CAAiBgB,GAAQ,CACpDc,CAAAA,CAAAA,CAAa,KAAK,GAAI,CAAA,EAAA,CAAID,CAAa,CAAA,CAG7C,OAFqB,IAAK,CAAA,KAAA,CAAMd,EAASe,CAAU,CAAA,CAAIA,CAGzD,CACF","file":"chunk-6X5O25W5.mjs","sourcesContent":["import { CurrencyCode } from \"./Common\";\r\nimport { CurrencyLocaleMap, CurrencySymbolMap, OperationalCountryCurrency } from \"./Enum\";\r\nimport {\r\n InvalidPriceAmountError,\r\n InvalidCurrencyCodeError,\r\n CurrencyMismatchError,\r\n InvalidArgumentError\r\n} from \"./Error\";\r\n\r\nexport type PriceAttributes = {\r\n amount: number;\r\n currency: CurrencyCode;\r\n}\r\n\r\nexport type PriceData = PriceAttributes;\r\n\r\nexport default class PriceModel {\r\n #kind: string;\r\n protected amount: number;\r\n protected currency: CurrencyCode;\r\n\r\n /**\r\n * Creates an instance of PriceModel, storing the currency-correct rounded price.\r\n * @param amount - The initial price value.\r\n * @param currency - The currency code used for rounding and determining the currency symbol.\r\n * @throws {Error} If price is negative or country/currency mapping is missing.\r\n */\r\n constructor(data: PriceAttributes) {\r\n this.#kind = \"PriceModel\";\r\n if (data.amount < 0) {\r\n throw new InvalidPriceAmountError(\"Amount cannot be negative.\");\r\n }\r\n\r\n if (!data.currency) {\r\n throw new InvalidCurrencyCodeError(\"Currency code is required.\");\r\n }\r\n\r\n this.amount = data.amount;\r\n this.currency = data.currency;\r\n }\r\n\r\n get kind() {\r\n return this.#kind;\r\n }\r\n\r\n static isPriceModel(obj: unknown): obj is PriceModel {\r\n return typeof obj === \"object\" &&\r\n obj !== null &&\r\n (obj as any).kind === \"PriceModel\";\r\n }\r\n\r\n /**\r\n * Gets the currency associated with this price instance.\r\n * @returns The CurrencyCode enum value.\r\n */\r\n public getCurrency(): CurrencyCode {\r\n return this.currency;\r\n }\r\n\r\n /**\r\n * Returns the raw numeric price value.\r\n */\r\n public getAmount(): number {\r\n return this.amount;\r\n }\r\n\r\n /**\r\n *\r\n * @returns PriceData\r\n */\r\n public getDetails(): PriceData {\r\n return {\r\n amount: this.amount,\r\n currency: this.currency\r\n }\r\n }\r\n\r\n /**\r\n * Compares this price with another {@link PriceModel} instance.\r\n *\r\n * The comparison is performed using the numeric price value and is only valid\r\n * when both prices are expressed in the same currency.\r\n *\r\n * ### Comparison result:\r\n * - Returns a **negative number** if this price is **less than** `priceModel`\r\n * - Returns **zero** if both prices are **equal**\r\n * - Returns a **positive number** if this price is **greater than** `priceModel`\r\n *\r\n * @param priceModel - The {@link PriceModel} instance to compare against.\r\n *\r\n * @returns\r\n * A signed number representing the comparison result:\r\n * - `< 0` → this price is lower\r\n * - `0` → prices are equal\r\n * - `> 0` → this price is higher\r\n *\r\n * @throws {Error}\r\n * Throws an error if:\r\n * - `priceModel` is not an instance of {@link PriceModel}\r\n * - The currencies of the two prices do not match\r\n *\r\n * @example\r\n * ```ts\r\n * const a = new PriceModel(\"USD\", 100);\r\n * const b = new PriceModel(\"USD\", 150);\r\n *\r\n * a.compareTo(b); // -50\r\n * b.compareTo(a); // 50\r\n * a.compareTo(a); // 0\r\n * ```\r\n */\r\n public compareTo(priceModel: PriceModel): number {\r\n if (!PriceModel.isPriceModel(priceModel)) {\r\n throw new InvalidArgumentError(\"Must be a PriceModel instance.\");\r\n } else if (this.currency !== priceModel.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot compare prices in different currencies.\");\r\n }\r\n\r\n return this.amount - priceModel.getAmount();\r\n }\r\n\r\n public add(priceModel: PriceModel): PriceModel {\r\n if (!PriceModel.isPriceModel(priceModel)) {\r\n throw new InvalidArgumentError(\"Must be a PriceModel instance.\");\r\n } else if (this.currency !== priceModel.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot add prices in different currencies.\");\r\n }\r\n\r\n return new PriceModel({\r\n amount: this.amount + priceModel.getAmount(),\r\n currency: this.currency\r\n });\r\n }\r\n\r\n public subtract(priceModel: PriceModel): PriceModel {\r\n if (!PriceModel.isPriceModel(priceModel)) {\r\n throw new InvalidArgumentError(\"Must be a PriceModel instance.\");\r\n } else if (this.currency !== priceModel.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot subtract prices in different currencies.\");\r\n }\r\n\r\n return new PriceModel({\r\n amount: this.amount - priceModel.getAmount(),\r\n currency: this.currency\r\n });\r\n }\r\n\r\n public multiply(factor: number | PriceModel): PriceModel {\r\n if (PriceModel.isPriceModel(factor)) {\r\n if (this.currency !== factor.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot multiply prices in different currencies.\");\r\n }\r\n return new PriceModel({\r\n amount: this.amount * factor.getAmount(),\r\n currency: this.currency\r\n });\r\n } else if (typeof factor === \"number\" && factor >= 0) {\r\n return new PriceModel({\r\n amount: this.amount * factor,\r\n currency: this.currency\r\n });\r\n }\r\n\r\n throw new InvalidArgumentError(\"Must be a non-negative number.\");\r\n }\r\n\r\n public divide(divisor: number | PriceModel): PriceModel {\r\n if (PriceModel.isPriceModel(divisor)) {\r\n if (this.currency !== divisor.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot divide prices in different currencies.\");\r\n }\r\n return new PriceModel({\r\n amount: this.amount / divisor.getAmount(),\r\n currency: this.currency\r\n });\r\n } else if (typeof divisor === \"number\" && divisor > 0) {\r\n return new PriceModel({\r\n amount: this.amount / divisor,\r\n currency: this.currency\r\n });\r\n }\r\n\r\n throw new InvalidArgumentError(\"Must be a positive number.\");\r\n }\r\n\r\n public min(...priceModels: PriceModel[]): PriceModel {\r\n if (priceModels.length === 0) {\r\n throw new InvalidArgumentError(\"Must provide at least one PriceModel.\");\r\n }\r\n\r\n return priceModels.reduce((minPrice, currentPrice) => {\r\n if (!PriceModel.isPriceModel(currentPrice)) {\r\n throw new InvalidArgumentError(\"Must be a PriceModel instance.\");\r\n } else if (minPrice.getCurrency() !== currentPrice.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot compare prices in different currencies.\");\r\n }\r\n\r\n return minPrice.compareTo(currentPrice) < 0 ? minPrice : currentPrice;\r\n }, this);\r\n }\r\n\r\n public max(...priceModels: PriceModel[]): PriceModel {\r\n if (priceModels.length === 0) {\r\n throw new InvalidArgumentError(\"Must provide at least one PriceModel.\");\r\n }\r\n\r\n return priceModels.reduce((maxPrice, currentPrice) => {\r\n if (!PriceModel.isPriceModel(currentPrice)) {\r\n throw new InvalidArgumentError(\"Must be a PriceModel instance.\");\r\n } else if (maxPrice.getCurrency() !== currentPrice.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot compare prices in different currencies.\");\r\n }\r\n\r\n return maxPrice.compareTo(currentPrice) > 0 ? maxPrice : currentPrice;\r\n }, this);\r\n }\r\n\r\n /**\r\n * Gets a zero value PriceModel for the same currency.\r\n * @returns A PriceModel instance representing zero in the same currency.\r\n */\r\n public zero(): PriceModel {\r\n return new PriceModel({\r\n currency: this.currency,\r\n amount: 0\r\n });\r\n }\r\n\r\n /**\r\n * Checks if the price is zero.\r\n * @returns True if the price is zero, false otherwise.\r\n */\r\n public isZero(): boolean {\r\n return this.amount === 0;\r\n }\r\n\r\n\r\n public round(): PriceModel {\r\n return new PriceModel({\r\n currency: this.currency,\r\n amount: this.getRoundedAmount()\r\n });\r\n }\r\n /**\r\n * Gets the rounded price value based on standard currency rules.\r\n * @returns The numeric price, rounded according to its currency's typical decimal places.\r\n */\r\n public getRoundedAmount(): number {\r\n return PriceModel.getRoundedAmount(this.amount, this.currency);\r\n }\r\n\r\n /**\r\n * Gets a locale-aware formatted display string for the price stored in this instance.\r\n * Uses the static `PriceModel.getFormattedString` method for the actual formatting.\r\n * @returns The formatted price string according to locale rules.\r\n */\r\n public getFormattedString() {\r\n return PriceModel.getFormattedString(this.amount, this.currency);\r\n }\r\n\r\n /**\r\n * Uses the static `PriceModel.getFormattedString` method for the actual formatting.\r\n * @returns The formatted price string according to locale rules.\r\n */\r\n toString() {\r\n return this.getFormattedString();\r\n }\r\n\r\n\r\n /**\r\n * Gets a locale-aware formatted display string for the amount.\r\n * Uses Intl.NumberFormat for accurate formatting based on locale and currency.\r\n * @param amount - The initial amount value.\r\n * @param currency - The currency code for formatting.\r\n * @param options - Configuration options for formatting.\r\n * @param options.displayAsInteger - If true, the formatted string will show the amount rounded to the next nearest integer (no decimals). Defaults to false.\r\n * @param options.style - The style of formatting, either 'currency' or 'decimal'. Defaults to 'currency'.\r\n * @param options.currencyDisplay - The display format for the currency symbol. Options are 'symbol', 'narrowSymbol', 'code', or 'name'. Defaults to 'symbol'.\r\n * @returns The formatted price string according to locale rules.\r\n * @throws {Error} If currency code is invalid.\r\n */\r\n static getFormattedString(amount: number, currency: CurrencyCode, options: {\r\n displayAsInteger?: boolean,\r\n style?: 'currency' | 'decimal',\r\n currencyDisplay?: 'symbol' | 'narrowSymbol' | 'code' | 'name'\r\n } = {\r\n displayAsInteger: false,\r\n style: 'currency',\r\n currencyDisplay: 'symbol'\r\n }): string {\r\n\r\n const locale = CurrencyLocaleMap[currency];\r\n if (!currency || !locale) {\r\n throw new InvalidCurrencyCodeError('Invalid currency code for formatting.');\r\n }\r\n\r\n let valueToFormat = amount;\r\n const fractionDigits = options.displayAsInteger ? 0 : PriceModel.getDecimalPlaces(currency);\r\n\r\n let formattingOptions: Intl.NumberFormatOptions = {\r\n style: options.style ?? 'currency',\r\n currency: currency,\r\n signDisplay: 'never',\r\n currencyDisplay: options.currencyDisplay,\r\n minimumFractionDigits: fractionDigits,\r\n maximumFractionDigits: fractionDigits,\r\n };\r\n\r\n if (options.displayAsInteger) {\r\n valueToFormat = Math.ceil(valueToFormat);\r\n }\r\n\r\n try {\r\n return new Intl.NumberFormat(locale, formattingOptions).format(valueToFormat);\r\n } catch (error) {\r\n console.error(`Error formatting price for currency \"${currency}\" and locale \"${locale}\":`, error);\r\n // Basic fallback without symbol if Intl fails completely\r\n return `${CurrencySymbolMap[currency] ?? currency} ${PriceModel.addThousandSeparators(valueToFormat.toFixed(fractionDigits))}`;\r\n }\r\n }\r\n\r\n /**\r\n * Helper method to determine standard decimal places for a currency.\r\n * @param currency - The currency code.\r\n * @returns The number of decimal places (0, 2, or 3 based on common rules).\r\n */\r\n private static getDecimalPlaces(currency: CurrencyCode): number {\r\n switch (currency) {\r\n case OperationalCountryCurrency.INR:\r\n default:\r\n return 2;\r\n }\r\n }\r\n\r\n /**\r\n * Adds basic thousand separators (commas) to a number string.\r\n * Does not handle different locale separators (e.g., periods, spaces).\r\n * @param numStr - The number string (potentially with decimals).\r\n * @returns The number string with commas added.\r\n */\r\n private static addThousandSeparators(numStr: string): string {\r\n const parts = numStr.split('.');\r\n const integerPart = parts[0];\r\n const decimalPart = parts.length > 1 ? '.' + parts[1] : '';\r\n\r\n const formattedInteger = integerPart.replace(/\\B(?=(\\d{3})+(?!\\d))/g, ',');\r\n return formattedInteger + decimalPart;\r\n }\r\n\r\n /**\r\n * Rounds a price value according to the standard decimal places\r\n * for the currency associated with the given country.\r\n *\r\n * @param price - The price value to round. Must be a non-negative number.\r\n * @param currency - The currency code to determine the rounding rules.\r\n * @returns The rounded price as a number.\r\n * @throws {Error} If the price is negative or currency is invalid.\r\n */\r\n static getRoundedAmount(amount: number, currency: CurrencyCode): number {\r\n if (amount < 0) {\r\n throw new InvalidPriceAmountError(\"Amount cannot be negative for rounding.\");\r\n }\r\n\r\n if (currency === undefined) {\r\n throw new InvalidCurrencyCodeError('Invalid currency code for rounding.');\r\n }\r\n\r\n const decimalPlaces = PriceModel.getDecimalPlaces(currency);\r\n const multiplier = Math.pow(10, decimalPlaces);\r\n const roundedValue = Math.round(amount * multiplier) / multiplier;\r\n\r\n return roundedValue;\r\n }\r\n}"]}
@@ -0,0 +1,2 @@
1
+ var R=(n=>(n.IN="IN",n))(R||{}),p=(n=>(n.INR="INR",n))(p||{}),r=(I=>(I["en-IN"]="en-IN",I["kn-IN"]="kn-IN",I))(r||{}),D=(N=>(N.en="en",N.kn="kn",N))(D||{}),T={"en-IN":"en","kn-IN":"kn"},x={"en-IN":"IN","kn-IN":"IN"},U={IN:"INR"},M={INR:"\u20B9"},P={INR:"en-IN"},l=(o=>(o.MALE="Male",o.FEMALE="Female",o.UNISEX="Unisex",o.KIDS="Kids",o.BOY="Boy",o.GIRL="Girl",o.GENERAL="General",o))(l||{}),u=(N=>(N.PRIMARY="PRIMARY",N.GALLERY="GALLERY",N))(u||{}),c=(N=>(N.SHIPPING="SHIPPING",N.ADJUSTMENT="ADJUSTMENT",N))(c||{}),a=(n=>(n.GST="GST",n))(a||{}),L=(E=>(E.INITIAL="INITIAL",E.PROCESSING="PROCESSING",E.SHIPPED="SHIPPED",E.DELIVERED="DELIVERED",E.CANCELLED="CANCELLED",E.RETURN_REQUESTED="RETURN_REQUESTED",E.RETURNED="RETURNED",E.REFUND_INITIATED="REFUND_INITIATED",E.REFUNDED="REFUNDED",E.ON_HOLD="ON_HOLD",E))(L||{});export{R as a,p as b,r as c,D as d,T as e,x as f,U as g,M as h,P as i,l as j,u as k,c as l,a as m,L as n};//# sourceMappingURL=chunk-FC4P26U3.mjs.map
2
+ //# sourceMappingURL=chunk-FC4P26U3.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/Classes/Enum.ts"],"names":["OperationalCountry","OperationalCountryCurrency","OperationalLocale","OperationalLanguage","LocaleLanguageMap","LocaleCountryMap","CountryCurrencyMap","CurrencySymbolMap","CurrencyLocaleMap","GenderCategory","ImageCategory","ChargeType","TaxSystem","LineItemState"],"mappings":"AAGO,IAAKA,CACGA,CAAAA,CAAAA,CAAAA,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CAAA,EAAA,EAAA,CAAA,CAKAC,OACVA,CAAA,CAAA,QAAA,CAAW,UACXA,CAAAA,CAAAA,CAAA,UAAa,CAAA,YAAA,CAFHA,CAAA,CAAA,EAAA,CAAA,EAAA,EAAA,CAAA,CAKAC,OACVA,CAAA,CAAA,GAAA,CAAM,KADIA,CAAAA,CAAAA,CAAAA,EAAAA,CAAAA,EAAA,EAkBAC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,GACVA,CAAA,CAAA,OAAA,CAAU,UACVA,CAAA,CAAA,UAAA,CAAa,YACbA,CAAAA,CAAAA,CAAA,OAAU,CAAA,SAAA,CACVA,CAAA,CAAA,SAAA,CAAY,YACZA,CAAA,CAAA,SAAA,CAAY,WACZA,CAAAA,CAAAA,CAAA,gBAAmB,CAAA,kBAAA,CACnBA,CAAA,CAAA,QAAA,CAAW,WACXA,CAAA,CAAA,gBAAA,CAAmB,kBACnBA,CAAAA,CAAAA,CAAA,QAAW,CAAA,UAAA,CACXA,CAAA,CAAA,OAAA,CAAU,UAVAA,CAAA,CAAA,EAAA,CAAA,EAAA,EAAA","file":"chunk-FC4P26U3.mjs","sourcesContent":["/**\r\n * Represents the countries where the application operates or products are available.\r\n */\r\nexport enum OperationalCountry {\r\n /** India */ IN = 'IN',\r\n}\r\n\r\nexport enum OperationalCountryCurrency {\r\n /** India */ INR = 'INR',\r\n}\r\n\r\nexport enum OperationalLocale {\r\n /** India */ 'en-IN' = 'en-IN',\r\n /** India ( Kannada) */ 'kn-IN' = 'kn-IN'\r\n}\r\n\r\nexport enum OperationalLanguage {\r\n en = 'en',\r\n kn = 'kn'\r\n}\r\n\r\nexport const LocaleLanguageMap: Record<OperationalLocale, OperationalLanguage> = {\r\n [OperationalLocale[\"en-IN\"]]: OperationalLanguage.en,\r\n [OperationalLocale[\"kn-IN\"]]: OperationalLanguage.kn,\r\n}\r\n\r\nexport const LocaleCountryMap: Record<OperationalLocale, OperationalCountry> = {\r\n [OperationalLocale[\"en-IN\"]]: OperationalCountry.IN,\r\n [OperationalLocale[\"kn-IN\"]]: OperationalCountry.IN,\r\n}\r\n\r\n/**\r\n * Defines the supported ISO 4217 currency codes as an enumeration.\r\n */\r\nexport const CountryCurrencyMap = {\r\n /** India */[OperationalCountry.IN]: OperationalCountryCurrency.INR,\r\n};\r\n\r\nexport const CurrencySymbolMap = {\r\n [OperationalCountryCurrency.INR]: '₹',\r\n}\r\n\r\nexport const CurrencyLocaleMap = {\r\n [OperationalCountryCurrency.INR]: OperationalLocale[\"en-IN\"],\r\n}\r\n\r\n/**\r\n * Defines standard gender categories for product targeting.\r\n */\r\nexport enum GenderCategory {\r\n MALE = 'Male',\r\n FEMALE = 'Female',\r\n UNISEX = 'Unisex',\r\n KIDS = 'Kids',\r\n BOY = 'Boy',\r\n GIRL = 'Girl',\r\n GENERAL = 'General',\r\n}\r\n\r\nexport enum ImageCategory {\r\n PRIMARY = 'PRIMARY',\r\n GALLERY = 'GALLERY'\r\n}\r\n\r\nexport enum ChargeType {\r\n SHIPPING = 'SHIPPING',\r\n ADJUSTMENT = 'ADJUSTMENT'\r\n}\r\n\r\nexport enum TaxSystem {\r\n GST = 'GST',\r\n}\r\n\r\n/**\r\n * LineItemState\r\n * \r\n * INITIAL: Item added to order, not yet processed.\r\n * PROCESSING: Item is being prepared for shipment.\r\n * SHIPPED: Item dispatched to customer.\r\n * DELIVERED: Item delivered to customer.\r\n * CANCELLED: Item cancelled before shipment or delivery.\r\n * RETURN_REQUESTED: Customer requests to return item.\r\n * RETURNED: Item received back from customer.\r\n * REFUND_INITIATED: Refund initiated for item.\r\n * REFUNDED: Refund processed for item.\r\n * ON_HOLD: Item is paused due to payment, inventory, or other issues.\r\n */\r\nexport enum LineItemState {\r\n INITIAL = \"INITIAL\",\r\n PROCESSING = \"PROCESSING\",\r\n SHIPPED = \"SHIPPED\",\r\n DELIVERED = \"DELIVERED\",\r\n CANCELLED = \"CANCELLED\",\r\n RETURN_REQUESTED = \"RETURN_REQUESTED\",\r\n RETURNED = \"RETURNED\",\r\n REFUND_INITIATED = \"REFUND_INITIATED\",\r\n REFUNDED = \"REFUNDED\",\r\n ON_HOLD = \"ON_HOLD\",\r\n}"]}
@@ -0,0 +1,2 @@
1
+ import {a as a$4}from'./chunk-XXETAAL4.mjs';import {a as a$1}from'./chunk-JE7BAYI5.mjs';import {a as a$3}from'./chunk-U7DES3CI.mjs';import {a as a$2}from'./chunk-6X5O25W5.mjs';import {e,n}from'./chunk-FC4P26U3.mjs';import {b as b$1}from'./chunk-RSTZJZSQ.mjs';import {c,e as e$1,f,h,i,j,b as b$2}from'./chunk-XPKK6DFA.mjs';import {a}from'./chunk-6KCJVEZD.mjs';var b=class extends a{id;productKey;selectionAttributes;name;specifications;primaryImage;subItems;pricing;state;total;constructor(t){super(t),this.id=t.id,this.productKey=t.productKey,this.selectionAttributes=a$1.deepClone(t.selectionAttributes),this.name=a$1.deepClone(t.name),this.specifications=a$1.deepClone(t.specifications),this.primaryImage=new b$1(t.primaryImage),this.subItems=a$1.deepClone(t.subItems);let e=new Set;this.subItems.forEach(i=>{if(e.has(i.size))throw new c(i.size);e.add(i.size);}),this.pricing={unitPrice:new a$2(t.pricing.unitPrice),tierPricing:new a$3(t.pricing.tierPricing),taxCategory:t.pricing.taxCategory,applicableTaxRule:t.pricing.applicableTaxRule.map(i=>new a$4(i))},this.state=t.state??"INITIAL",this.total={quantity:t.total.quantity,unitPrice:new a$2(t.total.unitPrice),subtotal:new a$2(t.total.subtotal),discounts:Object.fromEntries(Object.entries(t.total.discounts).map(([i,a])=>[i,new a$2(a)])),totalDiscount:new a$2(t.total.totalDiscount),netUnitPrice:new a$2(t.total.netUnitPrice),netSubtotal:new a$2(t.total.netSubtotal),taxBreakdown:Object.fromEntries(Object.entries(t.total.taxBreakdown).map(([i,a])=>[i,{rate:a.rate,taxableUnitPrice:new a$2(a.taxableUnitPrice),taxPerUnit:new a$2(a.taxPerUnit),amount:new a$2(a.amount),system:a.system,subSystem:a.subSystem}])),taxTotal:new a$2(t.total.taxTotal),grandTotal:new a$2(t.total.grandTotal)};}getId(){return this.id}getProductKey(){return this.productKey}getSelectionAttributes(){return a$1.deepClone(this.selectionAttributes)}getName(t){return t?a$1.deepClone(this.name[t]??this.name[e[t]]??this.name.en):a$1.deepClone(this.name)}getSpecifications(t){return t?a$1.deepClone(this.specifications[t]??this.specifications[e[t]]??this.specifications.en):a$1.deepClone(this.specifications)}getImage(){return this.primaryImage}getSubItems(){return a$1.deepClone(this.subItems)}getTotalQuantity(){return this.total.quantity}getPricing(){return {unitPrice:this.pricing.unitPrice,tierPricing:this.pricing.tierPricing,taxCategory:this.pricing.taxCategory,applicableTaxRule:this.pricing.applicableTaxRule}}getState(){return this.state}getTotal(){return {quantity:this.total.quantity,unitPrice:this.total.unitPrice,subtotal:this.total.subtotal,discounts:Object.fromEntries(Object.entries(this.total.discounts).map(([t,e])=>[t,e])),totalDiscount:this.total.totalDiscount,netUnitPrice:this.total.netUnitPrice,netSubtotal:this.total.netSubtotal,taxBreakdown:this.total.taxBreakdown,taxTotal:this.total.taxTotal,grandTotal:this.total.grandTotal}}getDetails(){let t=this.getPricing(),e=this.getTotal();return {id:this.getId(),productKey:this.getProductKey(),selectionAttributes:this.getSelectionAttributes(),name:this.getName(),specifications:this.getSpecifications(),primaryImage:this.getImage().getDetails(),subItems:this.getSubItems(),pricing:{unitPrice:t.unitPrice.getDetails(),tierPricing:t.tierPricing.getDetails(),taxCategory:t.taxCategory,applicableTaxRule:t.applicableTaxRule.map(i=>i.getDetails())},state:this.getState(),total:{quantity:e.quantity,unitPrice:e.unitPrice.getDetails(),subtotal:e.subtotal.getDetails(),discounts:Object.fromEntries(Object.entries(e.discounts).map(([i,a])=>[i,a.getDetails()])),totalDiscount:e.totalDiscount.getDetails(),netUnitPrice:e.netUnitPrice.getDetails(),netSubtotal:e.netSubtotal.getDetails(),taxBreakdown:Object.fromEntries(Object.entries(e.taxBreakdown).map(([i,a])=>[i,{rate:a.rate,taxableUnitPrice:a.taxableUnitPrice.getDetails(),taxPerUnit:a.taxPerUnit.getDetails(),amount:a.amount.getDetails(),system:a.system,subSystem:a.subSystem}])),taxTotal:e.taxTotal.getDetails(),grandTotal:e.grandTotal.getDetails()},customFields:this.getAllCustomFields()}}addSubItems(t,e){t.forEach(i=>{let a=this.subItems.find(c=>c.size===i.size);a?a.quantity=e?a.quantity+i.quantity:i.quantity:this.subItems.push(i);}),this.subItems=this.subItems.filter(i=>i.quantity>0),this.calculateTotals();}updateProductData(t,e,i$1){if(this.productKey!==t.getKey()||!t.validateSelectionAttribute(this.selectionAttributes))throw new e$1;if(!t.getIsActive())throw new f;this.subItems.forEach(s=>{if(!t.validateSize(s.size))throw new h});let a=t.getPriceDetails(e);if(!a||a.getBaseUnitPrice().getCurrency()!==i$1)throw new i;this.name=t.getName(),this.specifications=t.getSpecifications(),this.primaryImage=t.getImages(this.selectionAttributes).primary;let c=this.subItems.reduce((s,g)=>s+g.quantity,0),{unitPrice:l}=a.getApplicableTier(c);this.pricing={unitPrice:l,tierPricing:a,taxCategory:a.getTaxCategory(),applicableTaxRule:this.pricing.applicableTaxRule},this.calculateTotals();}updateDiscounts(t){let e={};t.forEach(i=>{e[i.coupon.getCode()]=i.amount;}),this.total.discounts=e,this.calculateTotals();}updateTax(t){t.forEach(e=>{if(!e.appliesTo(this.pricing.taxCategory,e.getCountry()))throw new j}),this.pricing.applicableTaxRule=t,this.calculateTotals();}calculateTotals(){let t=this.pricing.unitPrice.zero(),e=this.subItems.reduce((n,u)=>n+u.quantity,0);if(this.state==="CANCELLED"){this.total={quantity:0,unitPrice:t,subtotal:t,discounts:{},totalDiscount:t,netUnitPrice:t,netSubtotal:t,taxBreakdown:{},taxTotal:t,grandTotal:t};return}let{unitPrice:i}=this.pricing.tierPricing.getApplicableTier(e),a=i.multiply(e),c=Object.values(this.total.discounts).reduce((n,u)=>n.add(u),t),l=a.subtract(c),s=e>0?l.divide(e):t,g={},d=t;this.pricing.applicableTaxRule.forEach(n=>{let u=n.getApplicableTaxRate(s),P=n.calculateTax(s),h=P.multiply(e);g[n.getTaxRuleId()]={rate:u,taxableUnitPrice:s,taxPerUnit:P,amount:h,system:n.getTaxSystem(),subSystem:n.getTaxSubSystem()},d=d.add(h);});let A=l.add(d);this.total={quantity:e,unitPrice:i,subtotal:a,discounts:this.total.discounts,totalDiscount:c,netUnitPrice:s,netSubtotal:l,taxBreakdown:g,taxTotal:d,grandTotal:A};}updateState(t){if(this.state in n)this.state!==t&&(this.state=t);else throw new b$2(t)}clearLineItem(){let t=this.pricing.unitPrice.zero();this.id="",this.productKey="",this.selectionAttributes={color:{name:""}},this.name={en:""},this.primaryImage=new b$1({sources:{original:""}}),this.subItems=[],this.pricing={unitPrice:t,tierPricing:this.pricing.tierPricing,taxCategory:this.pricing.taxCategory,applicableTaxRule:[]},this.total={quantity:0,unitPrice:t,subtotal:t,discounts:{},totalDiscount:t,netUnitPrice:t,netSubtotal:t,taxBreakdown:{},taxTotal:t,grandTotal:t};}};export{b as a};//# sourceMappingURL=chunk-IIPG3DTO.mjs.map
2
+ //# sourceMappingURL=chunk-IIPG3DTO.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/Classes/LineItem.ts"],"names":["LineItemModel","CustomFieldModel","data","Utils_default","ImageInfoModel","uniqueSelectionAttributes","item","DuplicateSizeError","PriceModel","TieredPriceModel","rule","TaxRuleModel","couponCode","discount","taxRuleId","taxBreakdown","locale","LocaleLanguageMap","pricing","total","subItems","addQuantity","subItem","existingSubItem","sub","product","cartCountry","cartCurrency","ProductMismatchError","ProductInactiveError","SizeMismatchError","productPricing","PricingNotFoundError","quantity","sum","s","unitPrice","appliedDiscounts","lineItemDiscounts","taxRules","taxRule","InvalidTaxRuleError","zero","totalQuantity","subTotal","totalDiscount","netSubtotal","netUnitPrice","taxTotal","rate","taxPerUnit","amount","grandTotal","newState","LineItemState","InvalidLineItemStateError"],"mappings":"uWAmGA,IAAqBA,CAArB,CAAA,cAA2CC,CAAiB,CACh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AAA,IAAA,CAAK,QAAQ,SAAU,CAAA,IAAA,EACpC,CAAA,IAAA,CAAK,GAAK,EACV,CAAA,IAAA,CAAK,UAAa,CAAA,EAAA,CAClB,KAAK,mBAAsB,CAAA,CAAE,KAAO,CAAA,CAAE,IAAM,CAAA,EAAG,CAAE,CAAA,CACjD,KAAK,IAAO,CAAA,CAAE,EAAI,CAAA,EAAG,CACrB,CAAA,IAAA,CAAK,YAAe,CAAA,IAAItC,IAAe,CAAE,OAAA,CAAS,CAAE,QAAA,CAAU,EAAG,CAAE,CAAC,CAAA,CACpE,KAAK,QAAW,CAAA,EAChB,CAAA,IAAA,CAAK,OAAU,CAAA,CACb,SAAWsC,CAAAA,CAAAA,CACX,YAAa,IAAK,CAAA,OAAA,CAAQ,WAC1B,CAAA,WAAA,CAAa,IAAK,CAAA,OAAA,CAAQ,WAC1B,CAAA,iBAAA,CAAmB,EACrB,CAAA,CACA,IAAK,CAAA,KAAA,CAAQ,CACX,QAAA,CAAU,CACV,CAAA,SAAA,CAAWA,EACX,QAAUA,CAAAA,CAAAA,CACV,SAAW,CAAA,EACX,CAAA,aAAA,CAAeA,CACf,CAAA,YAAA,CAAcA,EACd,WAAaA,CAAAA,CAAAA,CACb,YAAc,CAAA,GACd,QAAUA,CAAAA,CAAAA,CACV,UAAYA,CAAAA,CACd,EACF,CACF","file":"chunk-IIPG3DTO.mjs","sourcesContent":["import Utils from \"../Utils\";\r\nimport { Color, CountryCode, CurrencyCode, LocaleCode, LocalizedString, LocalizedValue } from \"./Common\";\r\nimport CouponModel from \"./Coupon\";\r\nimport { LineItemState, LocaleLanguageMap, TaxSystem } from \"./Enum\";\r\nimport ImageInfoModel, { ImageInfoData } from \"./ImageInfo\";\r\nimport PriceModel, { PriceData } from \"./Price\";\r\nimport ProductModel, { ProductSelectionAttributes, ProductSpecification, SelectionAttributes } from \"./Product\";\r\nimport { TaxRuleData, TaxRuleModel, TaxSlabModel, TaxSlabs } from \"./TaxRule\";\r\nimport { TieredPriceData, TieredPriceModel } from \"./TieredPrice\";\r\nimport {\r\n DuplicateSizeError,\r\n ProductMismatchError,\r\n ProductInactiveError,\r\n SizeMismatchError,\r\n PricingNotFoundError,\r\n InvalidTaxRuleError,\r\n InvalidLineItemStateError\r\n} from \"./Error\";\r\nimport { CustomFieldAttributes, CustomFieldModel } from \"./Base\";\r\n\r\nexport type SubItem = {\r\n size: string | 'ONESIZE';\r\n quantity: number;\r\n};\r\n\r\nexport type LineItemPricing = {\r\n unitPrice: PriceData;\r\n tierPricing: TieredPriceData;\r\n taxCategory: string;\r\n applicableTaxRule: TaxRuleData[];\r\n};\r\n\r\nexport type LineItemTaxBreakdown = {\r\n rate: number; // 0.09 for 9%\r\n taxableUnitPrice: PriceData; // effectiveUnitPrice used for calculation\r\n taxPerUnit: PriceData; // tax on single unit\r\n amount: PriceData; // taxPerUnit × quantity (total tax)\r\n system: TaxSystem;\r\n subSystem: string;\r\n};\r\n\r\nexport type LineItemTaxBreakdownModel = {\r\n rate: number;\r\n taxableUnitPrice: PriceModel;\r\n taxPerUnit: PriceModel;\r\n amount: PriceModel;\r\n system: TaxSystem;\r\n subSystem: string;\r\n};\r\n\r\nexport type LineItemTotals = {\r\n quantity: number;\r\n unitPrice: PriceData; // original unit price (from tier pricing)\r\n subtotal: PriceData; // unitPrice × quantity\r\n discounts: Record<string, PriceData>; // couponCode -> discount mapping\r\n totalDiscount: PriceData; // sum of all discounts\r\n netUnitPrice: PriceData; // unit price after discounts\r\n netSubtotal: PriceData; // subtotal - totalDiscount (taxable amount)\r\n taxBreakdown: Record<string, LineItemTaxBreakdown>;\r\n taxTotal: PriceData; // sum of all tax amounts\r\n grandTotal: PriceData; // effectiveSubtotal + taxTotal\r\n};\r\n\r\nexport type LineItemTotalsModel = {\r\n quantity: number;\r\n unitPrice: PriceModel;\r\n subtotal: PriceModel;\r\n discounts: Record<string, PriceModel>;\r\n totalDiscount: PriceModel;\r\n netUnitPrice: PriceModel;\r\n netSubtotal: PriceModel;\r\n taxBreakdown: Record<string, LineItemTaxBreakdownModel>;\r\n taxTotal: PriceModel;\r\n grandTotal: PriceModel;\r\n};\r\n\r\nexport type LineItemAttributes = CustomFieldAttributes & {\r\n id: string;\r\n\r\n productKey: string;\r\n selectionAttributes: SelectionAttributes;\r\n\r\n name: LocalizedString;\r\n specifications: LocalizedValue<ProductSpecification>;\r\n primaryImage: ImageInfoData;\r\n\r\n subItems: SubItem[];\r\n\r\n pricing: LineItemPricing;\r\n\r\n state?: LineItemState;\r\n total: LineItemTotals;\r\n}\r\n\r\nexport type LineItemData = Required<LineItemAttributes>;\r\n\r\n/**\r\n * Represents a line item within a shopping cart.\r\n */\r\nexport default class LineItemModel extends CustomFieldModel {\r\n protected id: string;\r\n protected productKey: string;\r\n protected selectionAttributes: SelectionAttributes;\r\n\r\n protected name: LocalizedString;\r\n protected specifications: LocalizedValue<ProductSpecification>;\r\n protected primaryImage: ImageInfoModel;\r\n protected subItems: SubItem[];\r\n protected pricing: {\r\n unitPrice: PriceModel;\r\n tierPricing: TieredPriceModel;\r\n taxCategory: string;\r\n applicableTaxRule: TaxRuleModel[];\r\n };\r\n\r\n protected state: LineItemState;\r\n protected total: LineItemTotalsModel;\r\n\r\n /**\r\n * Creates an instance of LineItemModel.\r\n * @param data - The initial line item attributes.\r\n */\r\n constructor(data: LineItemAttributes) {\r\n super(data);\r\n this.id = data.id;\r\n this.productKey = data.productKey;\r\n this.selectionAttributes = Utils.deepClone(data.selectionAttributes);\r\n\r\n this.name = Utils.deepClone(data.name);\r\n this.specifications = Utils.deepClone(data.specifications);\r\n this.primaryImage = new ImageInfoModel(data.primaryImage);\r\n this.subItems = Utils.deepClone(data.subItems);\r\n\r\n let uniqueSelectionAttributes = new Set();\r\n this.subItems.forEach(item => {\r\n if (uniqueSelectionAttributes.has(item.size)) {\r\n throw new DuplicateSizeError(item.size);\r\n }\r\n uniqueSelectionAttributes.add(item.size);\r\n });\r\n\r\n this.pricing = {\r\n unitPrice: new PriceModel(data.pricing.unitPrice),\r\n tierPricing: new TieredPriceModel(data.pricing.tierPricing),\r\n taxCategory: data.pricing.taxCategory,\r\n applicableTaxRule: data.pricing.applicableTaxRule.map(rule => new TaxRuleModel(rule)),\r\n }\r\n\r\n this.state = data.state ?? LineItemState.INITIAL;\r\n\r\n this.total = {\r\n quantity: data.total.quantity,\r\n unitPrice: new PriceModel(data.total.unitPrice),\r\n subtotal: new PriceModel(data.total.subtotal),\r\n discounts: Object.fromEntries(\r\n Object.entries(data.total.discounts).map(([couponCode, discount]) => [\r\n couponCode,\r\n new PriceModel(discount),\r\n ])\r\n ),\r\n totalDiscount: new PriceModel(data.total.totalDiscount),\r\n netUnitPrice: new PriceModel(data.total.netUnitPrice),\r\n netSubtotal: new PriceModel(data.total.netSubtotal),\r\n taxBreakdown: Object.fromEntries(\r\n Object.entries(data.total.taxBreakdown).map(([taxRuleId, taxBreakdown]) => [\r\n taxRuleId,\r\n {\r\n rate: taxBreakdown.rate,\r\n taxableUnitPrice: new PriceModel(taxBreakdown.taxableUnitPrice),\r\n taxPerUnit: new PriceModel(taxBreakdown.taxPerUnit),\r\n amount: new PriceModel(taxBreakdown.amount),\r\n system: taxBreakdown.system,\r\n subSystem: taxBreakdown.subSystem\r\n }\r\n ])\r\n ),\r\n taxTotal: new PriceModel(data.total.taxTotal),\r\n grandTotal: new PriceModel(data.total.grandTotal),\r\n }\r\n }\r\n\r\n /**\r\n * Gets the unique identifier of the line item.\r\n * @returns The unique ID string.\r\n */\r\n getId(): string {\r\n return this.id;\r\n }\r\n\r\n /**\r\n * Gets the product key associated with this line item.\r\n * @returns The product key string.\r\n */\r\n getProductKey(): string {\r\n return this.productKey;\r\n }\r\n\r\n /**\r\n * Gets the selection attributes (e.g., size, color) for this line item.\r\n * @returns A copy of the selection attributes object.\r\n */\r\n getSelectionAttributes(): SelectionAttributes {\r\n return Utils.deepClone(this.selectionAttributes);\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 Utils.deepClone(this.name[locale] ?? this.name[LocaleLanguageMap[locale]] ?? this.name.en);\r\n } else {\r\n return Utils.deepClone(this.name);\r\n }\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(): LocalizedValue<ProductSpecification>\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): LocalizedValue<ProductSpecification> | ProductSpecification | undefined {\r\n if (locale) {\r\n return Utils.deepClone(this.specifications[locale] ?? this.specifications[LocaleLanguageMap[locale]] ?? this.specifications.en);\r\n } else {\r\n return Utils.deepClone(this.specifications);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the image information model for this line item.\r\n * @returns The ImageInfoModel instance.\r\n */\r\n getImage(): ImageInfoModel {\r\n return this.primaryImage;\r\n }\r\n\r\n /**\r\n * Gets the sub-items (size/quantity breakdown).\r\n * @returns A copy of the array of SubItems.\r\n */\r\n getSubItems(): SubItem[] {\r\n return Utils.deepClone(this.subItems);\r\n }\r\n\r\n /**\r\n * Gets the total quantity for this line item across all sub-items.\r\n * @returns The total quantity as a number.\r\n */\r\n getTotalQuantity(): number {\r\n return this.total.quantity;\r\n }\r\n\r\n /**\r\n * Gets the pricing information model for this line item.\r\n * @returns An object containing unit price, tiered pricing, tax category, and tax details.\r\n */\r\n getPricing() {\r\n return {\r\n unitPrice: this.pricing.unitPrice,\r\n tierPricing: this.pricing.tierPricing,\r\n taxCategory: this.pricing.taxCategory,\r\n applicableTaxRule: this.pricing.applicableTaxRule,\r\n };\r\n }\r\n\r\n /**\r\n * Gets the current state of the line item.\r\n * @returns The LineItemState enum value.\r\n */\r\n getState() {\r\n return this.state;\r\n }\r\n\r\n /**\r\n * Gets the total price for this line item (including all sub-items).\r\n * @returns An object containing line item totals including subtotal, tax, discounts, and grand total.\r\n */\r\n getTotal(): LineItemTotalsModel {\r\n return {\r\n quantity: this.total.quantity,\r\n unitPrice: this.total.unitPrice,\r\n subtotal: this.total.subtotal,\r\n discounts: Object.fromEntries(\r\n Object.entries(this.total.discounts).map(([couponCode, discount]) => [\r\n couponCode,\r\n discount,\r\n ])\r\n ),\r\n totalDiscount: this.total.totalDiscount,\r\n netUnitPrice: this.total.netUnitPrice,\r\n netSubtotal: this.total.netSubtotal,\r\n taxBreakdown: this.total.taxBreakdown,\r\n taxTotal: this.total.taxTotal,\r\n grandTotal: this.total.grandTotal,\r\n };\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the line item's details.\r\n * @returns LineItemData.\r\n */\r\n getDetails(): LineItemData {\r\n const pricing = this.getPricing();\r\n const total = this.getTotal();\r\n return {\r\n id: this.getId(),\r\n productKey: this.getProductKey(),\r\n selectionAttributes: this.getSelectionAttributes(),\r\n name: this.getName(),\r\n specifications: this.getSpecifications(),\r\n primaryImage: this.getImage().getDetails(),\r\n subItems: this.getSubItems(),\r\n pricing: {\r\n unitPrice: pricing.unitPrice.getDetails(),\r\n tierPricing: pricing.tierPricing.getDetails(),\r\n taxCategory: pricing.taxCategory,\r\n applicableTaxRule: pricing.applicableTaxRule.map(rule => rule.getDetails()),\r\n },\r\n state: this.getState(),\r\n total: {\r\n quantity: total.quantity,\r\n unitPrice: total.unitPrice.getDetails(),\r\n subtotal: total.subtotal.getDetails(),\r\n discounts: Object.fromEntries(\r\n Object.entries(total.discounts).map(([couponCode, discount]) => [\r\n couponCode,\r\n discount.getDetails(),\r\n ])\r\n ),\r\n totalDiscount: total.totalDiscount.getDetails(),\r\n netUnitPrice: total.netUnitPrice.getDetails(),\r\n netSubtotal: total.netSubtotal.getDetails(),\r\n taxBreakdown: Object.fromEntries(\r\n Object.entries(total.taxBreakdown).map(([taxRuleId, taxBreakdown]) => [\r\n taxRuleId,\r\n {\r\n rate: taxBreakdown.rate,\r\n taxableUnitPrice: taxBreakdown.taxableUnitPrice.getDetails(),\r\n taxPerUnit: taxBreakdown.taxPerUnit.getDetails(),\r\n amount: taxBreakdown.amount.getDetails(),\r\n system: taxBreakdown.system,\r\n subSystem: taxBreakdown.subSystem\r\n }\r\n ])\r\n ),\r\n taxTotal: total.taxTotal.getDetails(),\r\n grandTotal: total.grandTotal.getDetails(),\r\n },\r\n customFields: this.getAllCustomFields()\r\n };\r\n }\r\n\r\n /**\r\n * Adds or updates sub-items (e.g., sizes with quantities) to the line item.\r\n * If a sub-item with the same size already exists, its quantity is either\r\n * updated by adding the new quantity or replaced entirely, based on the `addQuantity` flag.\r\n * Sub-items with a resulting quantity of 0 are removed.\r\n * @param subItems - An array of `SubItem` objects to add or update.\r\n * @param addQuantity - If true, adds the quantity from `subItem` to the existing quantity.\r\n * If false, replaces the existing quantity with the one from `subItem`.\r\n */\r\n addSubItems(subItems: SubItem[], addQuantity: boolean): void {\r\n subItems.forEach(subItem => {\r\n const existingSubItem = this.subItems.find(item => item.size === subItem.size);\r\n if (existingSubItem) {\r\n existingSubItem.quantity = addQuantity ? existingSubItem.quantity + subItem.quantity : subItem.quantity;\r\n } else {\r\n this.subItems.push(subItem);\r\n }\r\n })\r\n this.subItems = this.subItems.filter(sub => sub.quantity > 0);\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Updates the line item with the latest product data (price, image, name, specifications).\r\n * Validates that the product matches the line item's selection and is active.\r\n * @param product - The product model to update from.\r\n * @param cartCountry - The country code for pricing context.\r\n * @param cartCurrency - The currency code for pricing context.\r\n * @throws {Error} If product mismatch, inactive, size mismatch, or pricing missing.\r\n */\r\n public updateProductData(product: ProductModel, cartCountry: CountryCode, cartCurrency: CurrencyCode): void {\r\n if (this.productKey !== product.getKey() || !product.validateSelectionAttribute(this.selectionAttributes)) {\r\n throw new ProductMismatchError();\r\n } else if (!product.getIsActive()) {\r\n throw new ProductInactiveError();\r\n }\r\n\r\n this.subItems.forEach(subItem => {\r\n if (!product.validateSize(subItem.size)) {\r\n throw new SizeMismatchError();\r\n }\r\n });\r\n\r\n const productPricing = product.getPriceDetails(cartCountry);\r\n if (!productPricing || productPricing.getBaseUnitPrice().getCurrency() !== cartCurrency) {\r\n throw new PricingNotFoundError();\r\n }\r\n this.name = product.getName();\r\n this.specifications = product.getSpecifications();\r\n this.primaryImage = product.getImages(this.selectionAttributes).primary;\r\n\r\n const quantity = this.subItems.reduce((sum, s) => sum + s.quantity, 0);\r\n const { unitPrice } = productPricing.getApplicableTier(quantity);\r\n\r\n this.pricing = {\r\n unitPrice: unitPrice,\r\n tierPricing: productPricing,\r\n taxCategory: productPricing.getTaxCategory(),\r\n applicableTaxRule: this.pricing.applicableTaxRule\r\n }\r\n\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Updates the discounts applied to this line item and recalculates totals.\r\n * @param appliedDiscounts - List of coupons and their allocated discount amounts.\r\n */\r\n public updateDiscounts(appliedDiscounts: { coupon: CouponModel, amount: PriceModel }[]): void {\r\n let lineItemDiscounts = {} as Record<string, PriceModel>;\r\n appliedDiscounts.forEach(discount => {\r\n lineItemDiscounts[discount.coupon.getCode()] = discount.amount;\r\n });\r\n\r\n this.total.discounts = lineItemDiscounts;\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Updates the tax rule for this line item and recalculates totals.\r\n * @param taxRule - The new tax rule to apply.\r\n * @throws {Error} If the tax rule category does not match the item's tax category.\r\n */\r\n public updateTax(taxRules: TaxRuleModel[]): void {\r\n taxRules.forEach(taxRule => {\r\n if (!taxRule.appliesTo(this.pricing.taxCategory, taxRule.getCountry())) {\r\n throw new InvalidTaxRuleError();\r\n }\r\n });\r\n\r\n // Remove the old taxableUnitPrice calculation - no longer needed\r\n this.pricing.applicableTaxRule = taxRules;\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Recalculates the line item totals based on current quantity, unit price, discounts, and tax rates.\r\n */\r\n public calculateTotals(): void {\r\n const zero = this.pricing.unitPrice.zero();\r\n const totalQuantity = this.subItems.reduce((sum, s) => sum + s.quantity, 0);\r\n\r\n if (this.state === LineItemState.CANCELLED) {\r\n this.total = {\r\n quantity: 0,\r\n unitPrice: zero,\r\n subtotal: zero,\r\n discounts: {},\r\n totalDiscount: zero,\r\n netUnitPrice: zero,\r\n netSubtotal: zero,\r\n taxBreakdown: {},\r\n taxTotal: zero,\r\n grandTotal: zero\r\n };\r\n return;\r\n }\r\n\r\n const { unitPrice } = this.pricing.tierPricing.getApplicableTier(totalQuantity);\r\n const subTotal = unitPrice.multiply(totalQuantity);\r\n const totalDiscount = Object.values(this.total.discounts).reduce((sum, s) => sum.add(s), zero);\r\n const netSubtotal = subTotal.subtract(totalDiscount);\r\n const netUnitPrice = totalQuantity > 0 ? netSubtotal.divide(totalQuantity) : zero;\r\n\r\n // Calculate tax for each applicable rule\r\n const taxBreakdown: Record<string, LineItemTaxBreakdownModel> = {};\r\n let taxTotal = zero;\r\n this.pricing.applicableTaxRule.forEach(taxRule => {\r\n const rate = taxRule.getApplicableTaxRate(netUnitPrice);\r\n const taxPerUnit = taxRule.calculateTax(netUnitPrice);\r\n const amount = taxPerUnit.multiply(totalQuantity);\r\n taxBreakdown[taxRule.getTaxRuleId()] = {\r\n rate: rate,\r\n taxableUnitPrice: netUnitPrice,\r\n taxPerUnit: taxPerUnit,\r\n amount: amount,\r\n system: taxRule.getTaxSystem(),\r\n subSystem: taxRule.getTaxSubSystem()\r\n };\r\n taxTotal = taxTotal.add(amount);\r\n });\r\n\r\n const grandTotal = netSubtotal.add(taxTotal);\r\n\r\n this.total = {\r\n quantity: totalQuantity,\r\n unitPrice: unitPrice,\r\n subtotal: subTotal,\r\n discounts: this.total.discounts,\r\n totalDiscount: totalDiscount,\r\n netUnitPrice: netUnitPrice,\r\n netSubtotal: netSubtotal,\r\n taxBreakdown: taxBreakdown,\r\n taxTotal: taxTotal,\r\n grandTotal: grandTotal\r\n };\r\n }\r\n\r\n /**\r\n * Updates the line item's state.\r\n * @param newState \r\n */\r\n public updateState(newState: LineItemState): void {\r\n if (this.state in LineItemState) {\r\n if (this.state !== newState) {\r\n this.state = newState;\r\n }\r\n } else {\r\n throw new InvalidLineItemStateError(newState);\r\n }\r\n }\r\n\r\n /**\r\n * Resets the line item's properties to their default empty or initial state.\r\n * Useful for clearing out line item data without creating a new instance.\r\n * Recalculates total quantity and price total afterwards (which will be zero).\r\n */\r\n clearLineItem(): void {\r\n const zero = this.pricing.unitPrice.zero()\r\n this.id = '';\r\n this.productKey = '';\r\n this.selectionAttributes = { color: { name: '' } };\r\n this.name = { en: '' };\r\n this.primaryImage = new ImageInfoModel({ sources: { original: '' } });\r\n this.subItems = [];\r\n this.pricing = {\r\n unitPrice: zero,\r\n tierPricing: this.pricing.tierPricing,\r\n taxCategory: this.pricing.taxCategory,\r\n applicableTaxRule: []\r\n }\r\n this.total = {\r\n quantity: 0,\r\n unitPrice: zero,\r\n subtotal: zero,\r\n discounts: {},\r\n totalDiscount: zero,\r\n netUnitPrice: zero,\r\n netSubtotal: zero,\r\n taxBreakdown: {},\r\n taxTotal: zero,\r\n grandTotal: zero\r\n };\r\n }\r\n}"]}
@@ -1,2 +1,2 @@
1
- import {a as a$1}from'./chunk-43SMYXYL.mjs';import {e}from'./chunk-72DR3HF2.mjs';import {b as b$2}from'./chunk-WSUPVXRZ.mjs';import {g,d}from'./chunk-JHELVQYY.mjs';import {b as b$1}from'./chunk-6KCJVEZD.mjs';import K from'crypto';var y=new Uint8Array(256),h=y.length;function I(){return h>y.length-16&&(K.randomFillSync(y),h=0),y.slice(h,h+=16)}var z=/^(?:[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 $(t){return typeof t=="string"&&z.test(t)}var U=$;var n=[];for(let t=0;t<256;++t)n.push((t+256).toString(16).slice(1));function b(t,e=0){return n[t[e+0]]+n[t[e+1]]+n[t[e+2]]+n[t[e+3]]+"-"+n[t[e+4]]+n[t[e+5]]+"-"+n[t[e+6]]+n[t[e+7]]+"-"+n[t[e+8]]+n[t[e+9]]+"-"+n[t[e+10]]+n[t[e+11]]+n[t[e+12]]+n[t[e+13]]+n[t[e+14]]+n[t[e+15]]}function k(t){if(!U(t))throw TypeError("Invalid UUID");let e,i=new Uint8Array(16);return i[0]=(e=parseInt(t.slice(0,8),16))>>>24,i[1]=e>>>16&255,i[2]=e>>>8&255,i[3]=e&255,i[4]=(e=parseInt(t.slice(9,13),16))>>>8,i[5]=e&255,i[6]=(e=parseInt(t.slice(14,18),16))>>>8,i[7]=e&255,i[8]=(e=parseInt(t.slice(19,23),16))>>>8,i[9]=e&255,i[10]=(e=parseInt(t.slice(24,36),16))/1099511627776&255,i[11]=e/4294967296&255,i[12]=e>>>24&255,i[13]=e>>>16&255,i[14]=e>>>8&255,i[15]=e&255,i}var M=k;function V(t){t=unescape(encodeURIComponent(t));let e=[];for(let i=0;i<t.length;++i)e.push(t.charCodeAt(i));return e}var G="6ba7b810-9dad-11d1-80b4-00c04fd430c8",B="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function x(t,e,i){function r(o,s,u,S){var A;if(typeof o=="string"&&(o=V(o)),typeof s=="string"&&(s=M(s)),((A=s)===null||A===void 0?void 0:A.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let g=new Uint8Array(16+o.length);if(g.set(s),g.set(o,s.length),g=i(g),g[6]=g[6]&15|e,g[8]=g[8]&63|128,u){S=S||0;for(let m=0;m<16;++m)u[S+m]=g[m];return u}return b(g)}try{r.name=t;}catch{}return r.DNS=G,r.URL=B,r}var L={randomUUID:K.randomUUID};function j(t,e,i){if(L.randomUUID&&!e&&!t)return L.randomUUID();t=t||{};let r=t.random||(t.rng||I)();if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,e){i=i||0;for(let o=0;o<16;++o)e[i+o]=r[o];return e}return b(r)}var D=j;function Z(t){return Array.isArray(t)?t=Buffer.from(t):typeof t=="string"&&(t=Buffer.from(t,"utf8")),K.createHash("sha1").update(t).digest()}var R=Z;var q=x("v5",80,R),P=q;var O={isUUID:t=>/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(t),isEmail:t=>/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(t),isURL:t=>/^(http|https):\/\/[^ "]+$/.test(t),generateUUID:(t,e)=>e&&t?P(t,e):D(),generateSearchId:(t,e)=>`${t}#${f.generateSelectionAttributesKey(e)}`,getKeyfromSearchId:t=>{let[e,i]=t.split("#");return {key:e,selectionAttributes:f.parseSelectionAttributesKey(i)}},deepClone(t){return structuredClone(t)}},a=O;var f=class t extends b$1{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){if(typeof e!="object")throw new g("Selection attributes must be an object");return Object.keys(e).filter(r=>e[r]!==void 0&&r.toLowerCase()!=="size").sort().map(r=>e[r].name?`${r}:c+${e[r].name}`:`${r}:${e[r]}`).join("|").toLowerCase()}static parseSelectionAttributesKey(e){try{let i={},r=e.split("|");for(let o of r){let[s,u]=o.split(":");u.startsWith("c+")?i[s]={name:u.slice(2)}:i[s]=u;}return i}catch(i){throw new g(i?.message)}}constructor(e,i=new Date){super(e,i),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((o,s)=>(e.pricing[s]&&(o[s]=new a$1(e.pricing[s])),o),{}),this.targetGender=e.targetGender,this.attributes=a.deepClone(e.attributes),this.specifications=a.deepClone(e.specifications),this.categories=a.deepClone(e.categories);let r=new Set;this.variants=(e.variants||[]).map(o=>{if(!o.selectionAttributes||typeof o.selectionAttributes!="object")throw new g("Selection attributes are required");this.checkSelectionAttributes(o.selectionAttributes);let s=t.generateSelectionAttributesKey(o.selectionAttributes);if(r.has(s))throw new d(s);return r.add(s),{sku:o.sku,selectionAttributes:o.selectionAttributes,images:{primary:new b$2(o.images.primary),gallery:(o.images.gallery||[]).map(u=>new b$2(u))}}}),this.isActive=e.isActive,this.searchTags=e.searchTags?a.deepClone(e.searchTags):{en:[]};}getId(){return this.id}getKey(){return this.key}getName(e$1){return e$1?this.name[e$1]??this.name[e[e$1]]??this.name.en:a.deepClone(this.name)}getDescription(e$1){return e$1?this.description[e$1]??this.description[e[e$1]]??this.description.en:a.deepClone(this.description)}getSlug(e$1){return e$1?this.slug[e$1]??this.slug[e[e$1]]??this.slug.en:a.deepClone(this.slug)}getBrand(){return this.brand}getPriceDetails(e){return e?this.pricing[e]??null:this.pricing}getAttributes(){return a.deepClone(this.attributes)}getVariants(){return this.variants.map(e=>({sku:e.sku,selectionAttributes:e.selectionAttributes,images:{primary:e.images.primary,gallery:e.images.gallery}}))}getImagesBySelectionAttributes(e){let i=t.generateSelectionAttributesKey(e),r=this.variants.find(o=>t.generateSelectionAttributesKey(o.selectionAttributes)===i);return r?r.images:null}getImages(e,i){switch(i){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 a.deepClone(this.categories)}getSpecifications(e$1){return e$1?a.deepClone(this.specifications[e$1]??this.specifications[e[e$1]]??this.specifications.en):a.deepClone(this.specifications)}getSearchTags(e$1){return e$1?a.deepClone(this.searchTags[e$1]??this.searchTags[e[e$1]]??this.searchTags.en):a.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((i,r)=>(this.pricing[r]&&(i[r]=this.pricing[r]?.getDetails()),i),{}),attributes:this.getAttributes(),variants:this.variants.map(i=>({sku:i.sku,selectionAttributes:a.deepClone(i.selectionAttributes),images:{primary:i.images.primary.getDetails(),gallery:i.images.gallery.map(r=>r.getDetails())}})),isActive:this.getIsActive(),targetGender:this.getTargetGender(),categories:this.getCategories(),specifications:this.getSpecifications(),searchTags:this.getSearchTags(),...e}}checkSelectionAttributes(e){if(!e||typeof e!="object")throw new g("Selection attributes are required");Object.keys(this.attributes).forEach(i=>{if(i.toLowerCase()==="size")return;let r=this.attributes[i],o=e[i];if(o===void 0)throw new g(`Selection attribute '${i}' is missing`);if(typeof r=="string"){if(typeof o!="string"||r!==o)throw new g(`Selection attribute '${i}' is invalid`)}else if(Array.isArray(r)){if(r.length>0&&typeof r[0]=="string"){if(typeof o!="string"||!r.includes(o))throw new g(`Selection attribute '${i}' is invalid`)}else if(typeof o!="object"||!("name"in o)||r.findIndex(s=>s.name===o.name)<0)throw new g(`Selection attribute '${i}' is invalid`)}});}validateSelectionAttribute(e){let i=t.generateSelectionAttributesKey(e);return this.variants.some(r=>t.generateSelectionAttributesKey(r.selectionAttributes)===i)}validateSize(e){return this.attributes.size.includes(e)}};export{a,f as b};//# sourceMappingURL=chunk-LEHPVA3Q.mjs.map
2
- //# sourceMappingURL=chunk-LEHPVA3Q.mjs.map
1
+ import {a as a$1}from'./chunk-U7DES3CI.mjs';import {e}from'./chunk-FC4P26U3.mjs';import {b as b$2}from'./chunk-RSTZJZSQ.mjs';import {g,d}from'./chunk-XPKK6DFA.mjs';import {b as b$1}from'./chunk-6KCJVEZD.mjs';import K from'crypto';var y=new Uint8Array(256),h=y.length;function I(){return h>y.length-16&&(K.randomFillSync(y),h=0),y.slice(h,h+=16)}var z=/^(?:[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 $(t){return typeof t=="string"&&z.test(t)}var U=$;var n=[];for(let t=0;t<256;++t)n.push((t+256).toString(16).slice(1));function b(t,e=0){return n[t[e+0]]+n[t[e+1]]+n[t[e+2]]+n[t[e+3]]+"-"+n[t[e+4]]+n[t[e+5]]+"-"+n[t[e+6]]+n[t[e+7]]+"-"+n[t[e+8]]+n[t[e+9]]+"-"+n[t[e+10]]+n[t[e+11]]+n[t[e+12]]+n[t[e+13]]+n[t[e+14]]+n[t[e+15]]}function k(t){if(!U(t))throw TypeError("Invalid UUID");let e,i=new Uint8Array(16);return i[0]=(e=parseInt(t.slice(0,8),16))>>>24,i[1]=e>>>16&255,i[2]=e>>>8&255,i[3]=e&255,i[4]=(e=parseInt(t.slice(9,13),16))>>>8,i[5]=e&255,i[6]=(e=parseInt(t.slice(14,18),16))>>>8,i[7]=e&255,i[8]=(e=parseInt(t.slice(19,23),16))>>>8,i[9]=e&255,i[10]=(e=parseInt(t.slice(24,36),16))/1099511627776&255,i[11]=e/4294967296&255,i[12]=e>>>24&255,i[13]=e>>>16&255,i[14]=e>>>8&255,i[15]=e&255,i}var M=k;function V(t){t=unescape(encodeURIComponent(t));let e=[];for(let i=0;i<t.length;++i)e.push(t.charCodeAt(i));return e}var G="6ba7b810-9dad-11d1-80b4-00c04fd430c8",B="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function x(t,e,i){function r(o,s,u,S){var A;if(typeof o=="string"&&(o=V(o)),typeof s=="string"&&(s=M(s)),((A=s)===null||A===void 0?void 0:A.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let g=new Uint8Array(16+o.length);if(g.set(s),g.set(o,s.length),g=i(g),g[6]=g[6]&15|e,g[8]=g[8]&63|128,u){S=S||0;for(let m=0;m<16;++m)u[S+m]=g[m];return u}return b(g)}try{r.name=t;}catch{}return r.DNS=G,r.URL=B,r}var L={randomUUID:K.randomUUID};function j(t,e,i){if(L.randomUUID&&!e&&!t)return L.randomUUID();t=t||{};let r=t.random||(t.rng||I)();if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,e){i=i||0;for(let o=0;o<16;++o)e[i+o]=r[o];return e}return b(r)}var D=j;function Z(t){return Array.isArray(t)?t=Buffer.from(t):typeof t=="string"&&(t=Buffer.from(t,"utf8")),K.createHash("sha1").update(t).digest()}var R=Z;var q=x("v5",80,R),P=q;var O={isUUID:t=>/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(t),isEmail:t=>/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(t),isURL:t=>/^(http|https):\/\/[^ "]+$/.test(t),generateUUID:(t,e)=>e&&t?P(t,e):D(),generateSearchId:(t,e)=>`${t}#${f.generateSelectionAttributesKey(e)}`,getKeyfromSearchId:t=>{let[e,i]=t.split("#");return {key:e,selectionAttributes:f.parseSelectionAttributesKey(i)}},deepClone(t){return structuredClone(t)}},a=O;var f=class t extends b$1{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){if(typeof e!="object")throw new g("Selection attributes must be an object");return Object.keys(e).filter(r=>e[r]!==void 0&&r.toLowerCase()!=="size").sort().map(r=>e[r].name?`${r}:c+${e[r].name}`:`${r}:${e[r]}`).join("|").toLowerCase()}static parseSelectionAttributesKey(e){try{let i={},r=e.split("|");for(let o of r){let[s,u]=o.split(":");u.startsWith("c+")?i[s]={name:u.slice(2)}:i[s]=u;}return i}catch(i){throw new g(i?.message)}}constructor(e,i=new Date){super(e,i),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((o,s)=>(e.pricing[s]&&(o[s]=new a$1(e.pricing[s])),o),{}),this.targetGender=e.targetGender,this.attributes=a.deepClone(e.attributes),this.specifications=a.deepClone(e.specifications),this.categories=a.deepClone(e.categories);let r=new Set;this.variants=(e.variants||[]).map(o=>{if(!o.selectionAttributes||typeof o.selectionAttributes!="object")throw new g("Selection attributes are required");this.checkSelectionAttributes(o.selectionAttributes);let s=t.generateSelectionAttributesKey(o.selectionAttributes);if(r.has(s))throw new d(s);return r.add(s),{sku:o.sku,selectionAttributes:o.selectionAttributes,images:{primary:new b$2(o.images.primary),gallery:(o.images.gallery||[]).map(u=>new b$2(u))}}}),this.isActive=e.isActive,this.searchTags=e.searchTags?a.deepClone(e.searchTags):{en:[]};}getId(){return this.id}getKey(){return this.key}getName(e$1){return e$1?this.name[e$1]??this.name[e[e$1]]??this.name.en:a.deepClone(this.name)}getDescription(e$1){return e$1?this.description[e$1]??this.description[e[e$1]]??this.description.en:a.deepClone(this.description)}getSlug(e$1){return e$1?this.slug[e$1]??this.slug[e[e$1]]??this.slug.en:a.deepClone(this.slug)}getBrand(){return this.brand}getPriceDetails(e){return e?this.pricing[e]??null:this.pricing}getAttributes(){return a.deepClone(this.attributes)}getVariants(){return this.variants.map(e=>({sku:e.sku,selectionAttributes:e.selectionAttributes,images:{primary:e.images.primary,gallery:e.images.gallery}}))}getImagesBySelectionAttributes(e){let i=t.generateSelectionAttributesKey(e),r=this.variants.find(o=>t.generateSelectionAttributesKey(o.selectionAttributes)===i);return r?r.images:null}getImages(e,i){switch(i){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 a.deepClone(this.categories)}getSpecifications(e$1){return e$1?a.deepClone(this.specifications[e$1]??this.specifications[e[e$1]]??this.specifications.en):a.deepClone(this.specifications)}getSearchTags(e$1){return e$1?a.deepClone(this.searchTags[e$1]??this.searchTags[e[e$1]]??this.searchTags.en):a.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((i,r)=>(this.pricing[r]&&(i[r]=this.pricing[r]?.getDetails()),i),{}),attributes:this.getAttributes(),variants:this.variants.map(i=>({sku:i.sku,selectionAttributes:a.deepClone(i.selectionAttributes),images:{primary:i.images.primary.getDetails(),gallery:i.images.gallery.map(r=>r.getDetails())}})),isActive:this.getIsActive(),targetGender:this.getTargetGender(),categories:this.getCategories(),specifications:this.getSpecifications(),searchTags:this.getSearchTags(),...e}}checkSelectionAttributes(e){if(!e||typeof e!="object")throw new g("Selection attributes are required");Object.keys(this.attributes).forEach(i=>{if(i.toLowerCase()==="size")return;let r=this.attributes[i],o=e[i];if(o===void 0)throw new g(`Selection attribute '${i}' is missing`);if(typeof r=="string"){if(typeof o!="string"||r!==o)throw new g(`Selection attribute '${i}' is invalid`)}else if(Array.isArray(r)){if(r.length>0&&typeof r[0]=="string"){if(typeof o!="string"||!r.includes(o))throw new g(`Selection attribute '${i}' is invalid`)}else if(typeof o!="object"||!("name"in o)||r.findIndex(s=>s.name===o.name)<0)throw new g(`Selection attribute '${i}' is invalid`)}});}validateSelectionAttribute(e){let i=t.generateSelectionAttributesKey(e);return this.variants.some(r=>t.generateSelectionAttributesKey(r.selectionAttributes)===i)}validateSize(e){return this.attributes.size.includes(e)}};export{a,f as b};//# sourceMappingURL=chunk-JE7BAYI5.mjs.map
2
+ //# sourceMappingURL=chunk-JE7BAYI5.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../node_modules/uuid/dist/esm-node/rng.js","../node_modules/uuid/dist/esm-node/regex.js","../node_modules/uuid/dist/esm-node/validate.js","../node_modules/uuid/dist/esm-node/stringify.js","../node_modules/uuid/dist/esm-node/parse.js","../node_modules/uuid/dist/esm-node/v35.js","../node_modules/uuid/dist/esm-node/native.js","../node_modules/uuid/dist/esm-node/v4.js","../node_modules/uuid/dist/esm-node/sha1.js","../node_modules/uuid/dist/esm-node/v5.js","../src/Utils/index.ts","../src/Classes/Product.ts"],"names":["rnds8Pool","poolPtr","rng","crypto","regex_default","validate","uuid","validate_default","byteToHex","i","unsafeStringify","arr","offset","parse","v","parse_default","stringToBytes","str","bytes","DNS","URL","v35","name","version","hashfunc","generateUUID","value","namespace","buf","_namespace","native_default","v4","options","rnds","v4_default","sha1","sha1_default","v5","v5_default","Utils","key","selectionAttributes","ProductModel","searchId","selectionAttributesKey","obj","Utils_default","_ProductModel","BaseModel","SelectionAttributeParseError","attributes","parts","part","error","data","date","acc","country","TieredPriceModel","uniqueSelectionAttributes","variant","DuplicateSelectionAttributeError","ImageInfoModel","image","locale","LocaleLanguageMap","searchKey","match","category","baseDetails","img","allowedAttributeValues","providedValue","c","size"],"mappings":"sOACA,IAAMA,CAAAA,CAAY,IAAI,UAAW,CAAA,GAAG,EAEhCC,CAAUD,CAAAA,CAAAA,CAAU,OACT,SAARE,CAAAA,EAAuB,CAC5B,OAAID,CAAAA,CAAUD,EAAU,MAAS,CAAA,EAAA,GAC/BG,CAAO,CAAA,cAAA,CAAeH,CAAS,CAAA,CAC/BC,EAAU,CAGLD,CAAAA,CAAAA,CAAAA,CAAU,MAAMC,CAASA,CAAAA,CAAAA,EAAW,EAAE,CAC/C,CCXA,IAAOG,CAAQ,CAAA,qHAAA,CCEf,SAASC,CAASC,CAAAA,CAAAA,CAAM,CACtB,OAAO,OAAOA,GAAS,QAAYF,EAAAA,CAAAA,CAAM,IAAKE,CAA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,CAAED,CAAoC,CAAA,QAAA,CAASC,CAAa,CAAA,CACnG,MAAM,IAAIvB,EAA6B,CAAwBT,qBAAAA,EAAAA,CAAG,cAAc,CAKhF,CAAA,KAAA,GAAA,OAAOgC,GAAkB,QACzB,EAAA,EAAE,MAAUA,GAAAA,CAAAA,CAAAA,EACXD,CAAmC,CAAA,SAAA,CAAUE,GAAKA,CAAE,CAAA,IAAA,GAAUD,EAAwB,IAAI,CAAA,CAAI,EAE/F,MAAM,IAAIvB,EAA6B,CAAwBT,qBAAAA,EAAAA,CAAG,cAAc,CAIxF,CAAA,CAAC,EACH,CAOA,0BAAA,CAA2BC,EAAmD,CAC5E,IAAMyB,CAAYnB,CAAAA,CAAAA,CAAa,8BAA+BN,CAAAA,CAAmB,EAEjF,OAAO,IAAA,CAAK,SAAS,IAAKmB,CAAAA,CAAAA,EAAWb,EAAa,8BAA+Ba,CAAAA,CAAAA,CAAQ,mBAAmB,CAAA,GAAMM,CAAS,CAC7H,CAOA,YAAaQ,CAAAA,CAAAA,CAAuB,CAClC,OAAO,IAAA,CAAK,WAAW,IAAK,CAAA,QAAA,CAASA,CAAI,CAC3C,CACF","file":"chunk-LEHPVA3Q.mjs","sourcesContent":["import crypto from 'crypto';\nconst rnds8Pool = new Uint8Array(256); // # of random values to pre-allocate\n\nlet poolPtr = rnds8Pool.length;\nexport default function rng() {\n if (poolPtr > rnds8Pool.length - 16) {\n crypto.randomFillSync(rnds8Pool);\n poolPtr = 0;\n }\n\n return rnds8Pool.slice(poolPtr, poolPtr += 16);\n}","export default /^(?:[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;","import REGEX from './regex.js';\n\nfunction validate(uuid) {\n return typeof uuid === 'string' && REGEX.test(uuid);\n}\n\nexport default validate;","import validate from './validate.js';\n/**\n * Convert array of 16 byte values to UUID string format of the form:\n * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\n */\n\nconst byteToHex = [];\n\nfor (let i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).slice(1));\n}\n\nexport function unsafeStringify(arr, offset = 0) {\n // Note: Be careful editing this code! It's been tuned for performance\n // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434\n return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];\n}\n\nfunction stringify(arr, offset = 0) {\n const uuid = unsafeStringify(arr, offset); // Consistency check for valid UUID. If this throws, it's likely due to one\n // of the following:\n // - One or more input array values don't map to a hex octet (leading to\n // \"undefined\" in the uuid)\n // - Invalid input values for the RFC `version` or `variant` fields\n\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n\n return uuid;\n}\n\nexport default stringify;","import validate from './validate.js';\n\nfunction parse(uuid) {\n if (!validate(uuid)) {\n throw TypeError('Invalid UUID');\n }\n\n let v;\n const arr = new Uint8Array(16); // Parse ########-....-....-....-............\n\n arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;\n arr[1] = v >>> 16 & 0xff;\n arr[2] = v >>> 8 & 0xff;\n arr[3] = v & 0xff; // Parse ........-####-....-....-............\n\n arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8;\n arr[5] = v & 0xff; // Parse ........-....-####-....-............\n\n arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8;\n arr[7] = v & 0xff; // Parse ........-....-....-####-............\n\n arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8;\n arr[9] = v & 0xff; // Parse ........-....-....-....-############\n // (Use \"/\" to avoid 32-bit truncation when bit-shifting high-order bytes)\n\n arr[10] = (v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000 & 0xff;\n arr[11] = v / 0x100000000 & 0xff;\n arr[12] = v >>> 24 & 0xff;\n arr[13] = v >>> 16 & 0xff;\n arr[14] = v >>> 8 & 0xff;\n arr[15] = v & 0xff;\n return arr;\n}\n\nexport default parse;","import { unsafeStringify } from './stringify.js';\nimport parse from './parse.js';\n\nfunction stringToBytes(str) {\n str = unescape(encodeURIComponent(str)); // UTF8 escape\n\n const bytes = [];\n\n for (let i = 0; i < str.length; ++i) {\n bytes.push(str.charCodeAt(i));\n }\n\n return bytes;\n}\n\nexport const DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';\nexport const URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';\nexport default function v35(name, version, hashfunc) {\n function generateUUID(value, namespace, buf, offset) {\n var _namespace;\n\n if (typeof value === 'string') {\n value = stringToBytes(value);\n }\n\n if (typeof namespace === 'string') {\n namespace = parse(namespace);\n }\n\n if (((_namespace = namespace) === null || _namespace === void 0 ? void 0 : _namespace.length) !== 16) {\n throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');\n } // Compute hash of namespace and value, Per 4.3\n // Future: Use spread syntax when supported on all platforms, e.g. `bytes =\n // hashfunc([...namespace, ... value])`\n\n\n let bytes = new Uint8Array(16 + value.length);\n bytes.set(namespace);\n bytes.set(value, namespace.length);\n bytes = hashfunc(bytes);\n bytes[6] = bytes[6] & 0x0f | version;\n bytes[8] = bytes[8] & 0x3f | 0x80;\n\n if (buf) {\n offset = offset || 0;\n\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = bytes[i];\n }\n\n return buf;\n }\n\n return unsafeStringify(bytes);\n } // Function#name is not settable on some platforms (#270)\n\n\n try {\n generateUUID.name = name; // eslint-disable-next-line no-empty\n } catch (err) {} // For CommonJS default export support\n\n\n generateUUID.DNS = DNS;\n generateUUID.URL = URL;\n return generateUUID;\n}","import crypto from 'crypto';\nexport default {\n randomUUID: crypto.randomUUID\n};","import native from './native.js';\nimport rng from './rng.js';\nimport { unsafeStringify } from './stringify.js';\n\nfunction v4(options, buf, offset) {\n if (native.randomUUID && !buf && !options) {\n return native.randomUUID();\n }\n\n options = options || {};\n const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`\n\n rnds[6] = rnds[6] & 0x0f | 0x40;\n rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided\n\n if (buf) {\n offset = offset || 0;\n\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n\n return buf;\n }\n\n return unsafeStringify(rnds);\n}\n\nexport default v4;","import crypto from 'crypto';\n\nfunction sha1(bytes) {\n if (Array.isArray(bytes)) {\n bytes = Buffer.from(bytes);\n } else if (typeof bytes === 'string') {\n bytes = Buffer.from(bytes, 'utf8');\n }\n\n return crypto.createHash('sha1').update(bytes).digest();\n}\n\nexport default sha1;","import v35 from './v35.js';\nimport sha1 from './sha1.js';\nconst v5 = v35('v5', 0x50, sha1);\nexport default v5;","import { v4 as uuidv4, v5 as uuidv5 } from 'uuid';\r\nimport ProductModel, { SelectionAttributes } from '../Classes/Product';\r\n\r\nconst Utils = {\r\n isUUID: (value: string): boolean => {\r\n const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\r\n return uuidRegex.test(value);\r\n },\r\n\r\n isEmail: (value: string): boolean => {\r\n const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$/;\r\n return emailRegex.test(value);\r\n },\r\n\r\n isURL: (value: string): boolean => {\r\n const urlRegex = /^(http|https):\\/\\/[^ \"]+$/;\r\n return urlRegex.test(value);\r\n },\r\n \r\n generateUUID: (value?: string, namespace?: string) => {\r\n if(namespace && value){\r\n return uuidv5(value, namespace);\r\n }\r\n return uuidv4();\r\n },\r\n\r\n generateSearchId: (key: string, selectionAttributes: SelectionAttributes) => {\r\n return `${key}#${ProductModel.generateSelectionAttributesKey(selectionAttributes)}`;\r\n },\r\n\r\n getKeyfromSearchId: (searchId: string) => {\r\n const [key, selectionAttributesKey] = searchId.split('#');\r\n return {\r\n key,\r\n selectionAttributes: ProductModel.parseSelectionAttributesKey(selectionAttributesKey)\r\n }\r\n },\r\n\r\n /**\r\n * Deep clones an object using `structuredClone`. Don't use this on a class instance.\r\n * @param obj - The object to clone.\r\n * @returns A deep clone of the object.\r\n */\r\n deepClone<T>(obj: T): T {\r\n return structuredClone(obj);\r\n }\r\n}\r\n\r\nexport default Utils;\r\n","import Utils from \"../Utils\";\r\nimport BaseModel, { BaseAttributes } from \"./Base\";\r\nimport { Color, LocalizedString, CountryCode, LocaleCode, LocalizedValue, Prettify } from './Common';\r\nimport { GenderCategory, ImageCategory, LocaleLanguageMap } from \"./Enum\";\r\nimport { DuplicateSelectionAttributeError, DuplicateSizeError, SelectionAttributeParseError } from \"./Error\";\r\nimport ImageInfoModel, { ImageInfoData } from \"./ImageInfo\";\r\nimport { TieredPriceModel, TieredPriceAttributes, TieredPriceData } from \"./TieredPrice\";\r\n\r\nexport type ProductSelectionAttributes = Prettify<{\r\n color: Color[];\r\n size: string[];\r\n} & {\r\n [key: string]: string | string[] | Color[];\r\n}>;\r\n\r\nexport type SelectionAttributes = {\r\n color: Color;\r\n [key: string]: string | Color;\r\n};\r\n\r\nexport type VariantData = {\r\n sku: string;\r\n selectionAttributes: SelectionAttributes;\r\n images: {\r\n primary: ImageInfoData;\r\n gallery: ImageInfoData[];\r\n };\r\n};\r\n\r\nexport type VariantModel = {\r\n sku: string;\r\n selectionAttributes: SelectionAttributes;\r\n images: {\r\n primary: ImageInfoModel;\r\n gallery: ImageInfoModel[];\r\n };\r\n};\r\n\r\n\r\nexport type ProductSpecification = { [key: string]: string | string[] };\r\n\r\nexport type ProductAttributes = BaseAttributes & {\r\n id: string;\r\n key: string;\r\n\r\n name: LocalizedString;\r\n description: LocalizedString;\r\n slug: LocalizedString;\r\n brand: string;\r\n\r\n pricing: {\r\n [country in CountryCode]?: TieredPriceAttributes;\r\n };\r\n\r\n targetGender: GenderCategory;\r\n attributes: ProductSelectionAttributes;\r\n specifications: LocalizedValue<ProductSpecification>;\r\n categories: string[];\r\n\r\n variants: VariantData[];\r\n\r\n // Metadata\r\n isActive: boolean;\r\n searchTags?: LocalizedValue<string[]>;\r\n};\r\n\r\nexport type ProductData = Required<ProductAttributes>\r\n\r\nexport default class ProductModel extends BaseModel {\r\n protected id: string;\r\n protected key: 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 pricing: {\r\n [country in CountryCode]?: TieredPriceModel;\r\n };\r\n\r\n protected variants: VariantModel[];\r\n\r\n protected targetGender: GenderCategory;\r\n protected attributes: ProductSelectionAttributes;\r\n protected specifications: LocalizedValue<ProductSpecification>;\r\n protected categories: string[];\r\n\r\n // Metadata\r\n protected isActive: boolean;\r\n\r\n protected searchTags: LocalizedValue<string[]>;\r\n\r\n static productKeyRegex = /^(?!\\s)(?!.*\\s$)[A-Z0-9-]{4,16}$/;\r\n static productSKURegex = /^(?!\\s)(?!.*\\s$)[A-Z0-9-]{4,16}$/;\r\n\r\n /**\r\n * Generates a unique key for checking uniqueness for a given selection attributes.\r\n * Excludes 'size' from the key generation.\r\n * @param selectionAttributes - The selection attributes.\r\n * @returns A string key representing the unique attribute combination.\r\n */\r\n static generateSelectionAttributesKey(selectionAttributes: SelectionAttributes): string {\r\n if (typeof selectionAttributes !== 'object') {\r\n throw new SelectionAttributeParseError('Selection attributes must be an object');\r\n }\r\n\r\n const sortedKeys = Object.keys(selectionAttributes)\r\n .filter(key => selectionAttributes[key] !== undefined && key.toLowerCase() !== 'size')\r\n .sort()\r\n\r\n return sortedKeys.map(key => {\r\n if ((selectionAttributes[key] as Color).name) {\r\n return `${key}:c+${(selectionAttributes[key] as Color).name}`;\r\n }\r\n return `${key}:${selectionAttributes[key]}`;\r\n }).join('|').toLowerCase();\r\n }\r\n\r\n /**\r\n * Parses a selection attributes key into an object.\r\n * @param key - The selection attributes key to parse.\r\n * @returns An object containing the parsed selection attributes.\r\n */\r\n static parseSelectionAttributesKey(key: string): SelectionAttributes {\r\n try {\r\n const attributes: SelectionAttributes = {} as unknown as SelectionAttributes;\r\n const parts = key.split('|');\r\n for (const part of parts) {\r\n const [key, value] = part.split(':');\r\n if (value.startsWith('c+')) {\r\n attributes[key] = { name: value.slice(2) } as Color;\r\n } else {\r\n attributes[key] = value;\r\n }\r\n }\r\n return attributes;\r\n } catch (error: any) {\r\n throw new SelectionAttributeParseError(error?.message);\r\n }\r\n }\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\r\n this.id = data.id;\r\n this.key = data.key;\r\n\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.pricing = (Object.keys(data.pricing) as CountryCode[]).reduce((acc, country) => {\r\n if (data.pricing[country]) {\r\n acc[country] = new TieredPriceModel(data.pricing[country]);\r\n }\r\n return acc;\r\n }, {} as { [country in CountryCode]?: TieredPriceModel });\r\n\r\n this.targetGender = data.targetGender;\r\n this.attributes = Utils.deepClone(data.attributes);\r\n this.specifications = Utils.deepClone(data.specifications);\r\n this.categories = Utils.deepClone(data.categories);\r\n\r\n const uniqueSelectionAttributes = new Set<string>();\r\n this.variants = (data.variants || []).map(variant => {\r\n if (!variant.selectionAttributes || typeof variant.selectionAttributes !== 'object') {\r\n throw new SelectionAttributeParseError('Selection attributes are required');\r\n }\r\n\r\n this.checkSelectionAttributes(variant.selectionAttributes);\r\n const key = ProductModel.generateSelectionAttributesKey(variant.selectionAttributes);\r\n if (uniqueSelectionAttributes.has(key)) {\r\n throw new DuplicateSelectionAttributeError(key);\r\n }\r\n uniqueSelectionAttributes.add(key);\r\n return {\r\n sku: variant.sku,\r\n selectionAttributes: variant.selectionAttributes,\r\n images: {\r\n primary: new ImageInfoModel(variant.images.primary),\r\n gallery: (variant.images.gallery || []).map(image => new ImageInfoModel(image))\r\n }\r\n };\r\n });\r\n\r\n this.isActive = data.isActive;\r\n this.searchTags = data.searchTags ? Utils.deepClone(data.searchTags) : { en: [] };\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 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[LocaleLanguageMap[locale]] ?? this.name.en;\r\n } else {\r\n return Utils.deepClone(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[LocaleLanguageMap[locale]] ?? this.description.en;\r\n } else {\r\n return Utils.deepClone(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[LocaleLanguageMap[locale]] ?? this.slug.en;\r\n } else {\r\n return Utils.deepClone(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 tiered price details for the product.\r\n * @returns Pricing details mapped by country.\r\n */\r\n getPriceDetails(): { [country in CountryCode]?: TieredPriceModel }\r\n /**\r\n * Gets the tiered price details for a specific country.\r\n * @param country - The country code.\r\n * @returns The tiered price model for the country, or null if not found.\r\n */\r\n getPriceDetails(country: CountryCode): TieredPriceModel | null\r\n getPriceDetails(country?: CountryCode): { [country in CountryCode]?: TieredPriceModel } | TieredPriceModel | null {\r\n if (country) {\r\n return this.pricing[country] ?? null;\r\n }\r\n return this.pricing;\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(): ProductSelectionAttributes {\r\n return Utils.deepClone(this.attributes);\r\n }\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 getVariants(): VariantModel[] {\r\n return this.variants.map(variant => ({\r\n sku: variant.sku,\r\n selectionAttributes: variant.selectionAttributes,\r\n images: {\r\n primary: variant.images.primary,\r\n gallery: variant.images.gallery\r\n }\r\n }));\r\n }\r\n\r\n /**\r\n * Gets the images for a specific selection attribute combination.\r\n * @param selectionAttributes - The selection attributes to search for.\r\n * @returns The matching image set or null if not found.\r\n */\r\n private getImagesBySelectionAttributes(selectionAttributes: SelectionAttributes): { primary: ImageInfoModel; gallery: ImageInfoModel[] } | null {\r\n const searchKey = ProductModel.generateSelectionAttributesKey(selectionAttributes);\r\n\r\n const match = this.variants.find(variant =>\r\n ProductModel.generateSelectionAttributesKey(variant.selectionAttributes) === searchKey\r\n );\r\n\r\n return match ? match.images : null;\r\n }\r\n\r\n /**\r\n * Gets the images for a specific selection attribute combination.\r\n * @param selectionAttributes - The selection attributes to search for.\r\n * @returns The matching image set or null if not found.\r\n */\r\n getImages(selectionAttributes: SelectionAttributes): { primary: ImageInfoModel; gallery: ImageInfoModel[] }\r\n getImages(selectionAttributes: SelectionAttributes, category: ImageCategory.PRIMARY): ImageInfoModel\r\n getImages(selectionAttributes: SelectionAttributes, category: ImageCategory.GALLERY): ImageInfoModel[]\r\n getImages(selectionAttributes: SelectionAttributes, category?: ImageCategory): { primary: ImageInfoModel; gallery: ImageInfoModel[] } | ImageInfoModel | ImageInfoModel[] {\r\n switch (category) {\r\n case ImageCategory.PRIMARY:\r\n return this.getImagesBySelectionAttributes(selectionAttributes)?.primary ?? this.variants[0]?.images?.primary;\r\n case ImageCategory.GALLERY:\r\n return this.getImagesBySelectionAttributes(selectionAttributes)?.gallery ?? [];\r\n default:\r\n return this.getImagesBySelectionAttributes(selectionAttributes) ?? { primary: this.variants[0]?.images?.primary, gallery: [] };\r\n }\r\n }\r\n\r\n\r\n /**\r\n * Checks if the product 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 Utils.deepClone(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(): LocalizedValue<ProductSpecification>\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\r\n getSpecifications(locale?: LocaleCode): LocalizedValue<ProductSpecification> | ProductSpecification {\r\n if (locale) {\r\n return Utils.deepClone(this.specifications[locale] ?? this.specifications[LocaleLanguageMap[locale]] ?? this.specifications.en);\r\n } else {\r\n return Utils.deepClone(this.specifications);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the localized list of search tags. Returns a copy.\r\n * @returns Localized array of search tags.\r\n */\r\n getSearchTags(): LocalizedValue<string[]>\r\n /**\r\n * Gets the search tags for a specific locale, falling back to English ('en').\r\n * @param locale - The desired locale code.\r\n * @returns The array of search tags for the specified locale, or undefined if not found.\r\n */\r\n getSearchTags(locale: LocaleCode): string[]\r\n getSearchTags(locale?: LocaleCode): LocalizedValue<string[]> | string[] {\r\n if (locale) {\r\n return Utils.deepClone(this.searchTags[locale] ?? this.searchTags[LocaleLanguageMap[locale]] ?? this.searchTags.en);\r\n } else {\r\n return Utils.deepClone(this.searchTags);\r\n }\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 name: this.getName(),\r\n description: this.getDescription(),\r\n slug: this.getSlug(),\r\n brand: this.getBrand(),\r\n pricing: (Object.keys(this.pricing) as CountryCode[]).reduce((acc, country) => {\r\n if (this.pricing[country]) {\r\n acc[country] = this.pricing[country]?.getDetails();\r\n }\r\n return acc;\r\n }, {} as { [country in CountryCode]: TieredPriceData }),\r\n attributes: this.getAttributes(),\r\n variants: this.variants.map(v => ({\r\n sku: v.sku,\r\n selectionAttributes: Utils.deepClone(v.selectionAttributes),\r\n images: {\r\n primary: v.images.primary.getDetails(),\r\n gallery: v.images.gallery.map(img => img.getDetails())\r\n }\r\n })),\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 * Checks if the provided selection attributes are valid for the product.\r\n * @param selectionAttributes The selection attributes to validate.\r\n * @throws {SelectionAttributeParseError} If the selection attributes are invalid.\r\n */\r\n checkSelectionAttributes(selectionAttributes: SelectionAttributes): void {\r\n if (!selectionAttributes || typeof selectionAttributes !== 'object') {\r\n throw new SelectionAttributeParseError('Selection attributes are required');\r\n }\r\n\r\n Object.keys(this.attributes).forEach(key => {\r\n if(key.toLowerCase() === 'size') return;\r\n \r\n const allowedAttributeValues = this.attributes[key];\r\n const providedValue = selectionAttributes[key];\r\n\r\n if (providedValue === undefined) {\r\n throw new SelectionAttributeParseError(`Selection attribute '${key}' is missing`);\r\n }\r\n\r\n if (typeof allowedAttributeValues === 'string') {\r\n if (typeof providedValue !== 'string' || allowedAttributeValues !== providedValue) {\r\n throw new SelectionAttributeParseError(`Selection attribute '${key}' is invalid`);\r\n }\r\n } else if (Array.isArray(allowedAttributeValues)) {\r\n if (allowedAttributeValues.length > 0 && typeof allowedAttributeValues[0] === 'string') {\r\n if (typeof providedValue !== 'string' || !(allowedAttributeValues as string[]).includes(providedValue)) {\r\n throw new SelectionAttributeParseError(`Selection attribute '${key}' is invalid`);\r\n }\r\n } else {\r\n // Color validation\r\n if (\r\n typeof providedValue !== 'object' ||\r\n !('name' in providedValue) ||\r\n (allowedAttributeValues as Color[]).findIndex(c => c.name === (providedValue as Color).name) < 0\r\n ) {\r\n throw new SelectionAttributeParseError(`Selection attribute '${key}' is invalid`);\r\n }\r\n }\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Validates if the provided selection attributes exist for this product.\r\n * @param selectionAttributes - The attributes to validate.\r\n * @returns True if a valid selection attribute exists, false otherwise.\r\n */\r\n validateSelectionAttribute(selectionAttributes: SelectionAttributes): boolean {\r\n const searchKey = ProductModel.generateSelectionAttributesKey(selectionAttributes);\r\n\r\n return this.variants.some(variant => ProductModel.generateSelectionAttributesKey(variant.selectionAttributes) === searchKey);\r\n }\r\n\r\n /**\r\n * Validates if a specific size is available for this product.\r\n * @param size - The size to check.\r\n * @returns True if the size exists in the product's attributes, false otherwise.\r\n */\r\n validateSize(size: string): boolean {\r\n return this.attributes.size.includes(size);\r\n }\r\n}"]}
1
+ {"version":3,"sources":["../node_modules/uuid/dist/esm-node/rng.js","../node_modules/uuid/dist/esm-node/regex.js","../node_modules/uuid/dist/esm-node/validate.js","../node_modules/uuid/dist/esm-node/stringify.js","../node_modules/uuid/dist/esm-node/parse.js","../node_modules/uuid/dist/esm-node/v35.js","../node_modules/uuid/dist/esm-node/native.js","../node_modules/uuid/dist/esm-node/v4.js","../node_modules/uuid/dist/esm-node/sha1.js","../node_modules/uuid/dist/esm-node/v5.js","../src/Utils/index.ts","../src/Classes/Product.ts"],"names":["rnds8Pool","poolPtr","rng","crypto","regex_default","validate","uuid","validate_default","byteToHex","i","unsafeStringify","arr","offset","parse","v","parse_default","stringToBytes","str","bytes","DNS","URL","v35","name","version","hashfunc","generateUUID","value","namespace","buf","_namespace","native_default","v4","options","rnds","v4_default","sha1","sha1_default","v5","v5_default","Utils","key","selectionAttributes","ProductModel","searchId","selectionAttributesKey","obj","Utils_default","_ProductModel","BaseModel","SelectionAttributeParseError","attributes","parts","part","error","data","date","acc","country","TieredPriceModel","uniqueSelectionAttributes","variant","DuplicateSelectionAttributeError","ImageInfoModel","image","locale","LocaleLanguageMap","searchKey","match","category","baseDetails","img","allowedAttributeValues","providedValue","c","size"],"mappings":"sOACA,IAAMA,CAAAA,CAAY,IAAI,UAAW,CAAA,GAAG,EAEhCC,CAAUD,CAAAA,CAAAA,CAAU,OACT,SAARE,CAAAA,EAAuB,CAC5B,OAAID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I,OAAOC,GAAkB,QAAYD,EAAAA,CAAAA,GAA2BC,EAClE,MAAM,IAAIvB,EAA6B,CAAwBT,qBAAAA,EAAAA,CAAG,cAAc,CAEzE,CAAA,KAAA,GAAA,KAAA,CAAM,QAAQ+B,CAAsB,CAAA,CAAA,CAC7C,GAAIA,CAAuB,CAAA,MAAA,CAAS,CAAK,EAAA,OAAOA,CAAuB,CAAA,CAAC,GAAM,QAC5E,CAAA,CAAA,GAAI,OAAOC,CAAkB,EAAA,QAAA,EAAY,CAAED,CAAoC,CAAA,QAAA,CAASC,CAAa,CAAA,CACnG,MAAM,IAAIvB,EAA6B,CAAwBT,qBAAAA,EAAAA,CAAG,cAAc,CAKhF,CAAA,KAAA,GAAA,OAAOgC,GAAkB,QACzB,EAAA,EAAE,MAAUA,GAAAA,CAAAA,CAAAA,EACXD,CAAmC,CAAA,SAAA,CAAUE,GAAKA,CAAE,CAAA,IAAA,GAAUD,EAAwB,IAAI,CAAA,CAAI,EAE/F,MAAM,IAAIvB,EAA6B,CAAwBT,qBAAAA,EAAAA,CAAG,cAAc,CAIxF,CAAA,CAAC,EACH,CAOA,0BAAA,CAA2BC,EAAmD,CAC5E,IAAMyB,CAAYnB,CAAAA,CAAAA,CAAa,8BAA+BN,CAAAA,CAAmB,EAEjF,OAAO,IAAA,CAAK,SAAS,IAAKmB,CAAAA,CAAAA,EAAWb,EAAa,8BAA+Ba,CAAAA,CAAAA,CAAQ,mBAAmB,CAAA,GAAMM,CAAS,CAC7H,CAOA,YAAaQ,CAAAA,CAAAA,CAAuB,CAClC,OAAO,IAAA,CAAK,WAAW,IAAK,CAAA,QAAA,CAASA,CAAI,CAC3C,CACF","file":"chunk-JE7BAYI5.mjs","sourcesContent":["import crypto from 'crypto';\nconst rnds8Pool = new Uint8Array(256); // # of random values to pre-allocate\n\nlet poolPtr = rnds8Pool.length;\nexport default function rng() {\n if (poolPtr > rnds8Pool.length - 16) {\n crypto.randomFillSync(rnds8Pool);\n poolPtr = 0;\n }\n\n return rnds8Pool.slice(poolPtr, poolPtr += 16);\n}","export default /^(?:[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;","import REGEX from './regex.js';\n\nfunction validate(uuid) {\n return typeof uuid === 'string' && REGEX.test(uuid);\n}\n\nexport default validate;","import validate from './validate.js';\n/**\n * Convert array of 16 byte values to UUID string format of the form:\n * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\n */\n\nconst byteToHex = [];\n\nfor (let i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).slice(1));\n}\n\nexport function unsafeStringify(arr, offset = 0) {\n // Note: Be careful editing this code! It's been tuned for performance\n // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434\n return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];\n}\n\nfunction stringify(arr, offset = 0) {\n const uuid = unsafeStringify(arr, offset); // Consistency check for valid UUID. If this throws, it's likely due to one\n // of the following:\n // - One or more input array values don't map to a hex octet (leading to\n // \"undefined\" in the uuid)\n // - Invalid input values for the RFC `version` or `variant` fields\n\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n\n return uuid;\n}\n\nexport default stringify;","import validate from './validate.js';\n\nfunction parse(uuid) {\n if (!validate(uuid)) {\n throw TypeError('Invalid UUID');\n }\n\n let v;\n const arr = new Uint8Array(16); // Parse ########-....-....-....-............\n\n arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;\n arr[1] = v >>> 16 & 0xff;\n arr[2] = v >>> 8 & 0xff;\n arr[3] = v & 0xff; // Parse ........-####-....-....-............\n\n arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8;\n arr[5] = v & 0xff; // Parse ........-....-####-....-............\n\n arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8;\n arr[7] = v & 0xff; // Parse ........-....-....-####-............\n\n arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8;\n arr[9] = v & 0xff; // Parse ........-....-....-....-############\n // (Use \"/\" to avoid 32-bit truncation when bit-shifting high-order bytes)\n\n arr[10] = (v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000 & 0xff;\n arr[11] = v / 0x100000000 & 0xff;\n arr[12] = v >>> 24 & 0xff;\n arr[13] = v >>> 16 & 0xff;\n arr[14] = v >>> 8 & 0xff;\n arr[15] = v & 0xff;\n return arr;\n}\n\nexport default parse;","import { unsafeStringify } from './stringify.js';\nimport parse from './parse.js';\n\nfunction stringToBytes(str) {\n str = unescape(encodeURIComponent(str)); // UTF8 escape\n\n const bytes = [];\n\n for (let i = 0; i < str.length; ++i) {\n bytes.push(str.charCodeAt(i));\n }\n\n return bytes;\n}\n\nexport const DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';\nexport const URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';\nexport default function v35(name, version, hashfunc) {\n function generateUUID(value, namespace, buf, offset) {\n var _namespace;\n\n if (typeof value === 'string') {\n value = stringToBytes(value);\n }\n\n if (typeof namespace === 'string') {\n namespace = parse(namespace);\n }\n\n if (((_namespace = namespace) === null || _namespace === void 0 ? void 0 : _namespace.length) !== 16) {\n throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');\n } // Compute hash of namespace and value, Per 4.3\n // Future: Use spread syntax when supported on all platforms, e.g. `bytes =\n // hashfunc([...namespace, ... value])`\n\n\n let bytes = new Uint8Array(16 + value.length);\n bytes.set(namespace);\n bytes.set(value, namespace.length);\n bytes = hashfunc(bytes);\n bytes[6] = bytes[6] & 0x0f | version;\n bytes[8] = bytes[8] & 0x3f | 0x80;\n\n if (buf) {\n offset = offset || 0;\n\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = bytes[i];\n }\n\n return buf;\n }\n\n return unsafeStringify(bytes);\n } // Function#name is not settable on some platforms (#270)\n\n\n try {\n generateUUID.name = name; // eslint-disable-next-line no-empty\n } catch (err) {} // For CommonJS default export support\n\n\n generateUUID.DNS = DNS;\n generateUUID.URL = URL;\n return generateUUID;\n}","import crypto from 'crypto';\nexport default {\n randomUUID: crypto.randomUUID\n};","import native from './native.js';\nimport rng from './rng.js';\nimport { unsafeStringify } from './stringify.js';\n\nfunction v4(options, buf, offset) {\n if (native.randomUUID && !buf && !options) {\n return native.randomUUID();\n }\n\n options = options || {};\n const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`\n\n rnds[6] = rnds[6] & 0x0f | 0x40;\n rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided\n\n if (buf) {\n offset = offset || 0;\n\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n\n return buf;\n }\n\n return unsafeStringify(rnds);\n}\n\nexport default v4;","import crypto from 'crypto';\n\nfunction sha1(bytes) {\n if (Array.isArray(bytes)) {\n bytes = Buffer.from(bytes);\n } else if (typeof bytes === 'string') {\n bytes = Buffer.from(bytes, 'utf8');\n }\n\n return crypto.createHash('sha1').update(bytes).digest();\n}\n\nexport default sha1;","import v35 from './v35.js';\nimport sha1 from './sha1.js';\nconst v5 = v35('v5', 0x50, sha1);\nexport default v5;","import { v4 as uuidv4, v5 as uuidv5 } from 'uuid';\r\nimport ProductModel, { SelectionAttributes } from '../Classes/Product';\r\n\r\nconst Utils = {\r\n isUUID: (value: string): boolean => {\r\n const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\r\n return uuidRegex.test(value);\r\n },\r\n\r\n isEmail: (value: string): boolean => {\r\n const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$/;\r\n return emailRegex.test(value);\r\n },\r\n\r\n isURL: (value: string): boolean => {\r\n const urlRegex = /^(http|https):\\/\\/[^ \"]+$/;\r\n return urlRegex.test(value);\r\n },\r\n \r\n generateUUID: (value?: string, namespace?: string) => {\r\n if(namespace && value){\r\n return uuidv5(value, namespace);\r\n }\r\n return uuidv4();\r\n },\r\n\r\n generateSearchId: (key: string, selectionAttributes: SelectionAttributes) => {\r\n return `${key}#${ProductModel.generateSelectionAttributesKey(selectionAttributes)}`;\r\n },\r\n\r\n getKeyfromSearchId: (searchId: string) => {\r\n const [key, selectionAttributesKey] = searchId.split('#');\r\n return {\r\n key,\r\n selectionAttributes: ProductModel.parseSelectionAttributesKey(selectionAttributesKey)\r\n }\r\n },\r\n\r\n /**\r\n * Deep clones an object using `structuredClone`. Don't use this on a class instance.\r\n * @param obj - The object to clone.\r\n * @returns A deep clone of the object.\r\n */\r\n deepClone<T>(obj: T): T {\r\n return structuredClone(obj);\r\n }\r\n}\r\n\r\nexport default Utils;\r\n","import Utils from \"../Utils\";\r\nimport BaseModel, { BaseAttributes } from \"./Base\";\r\nimport { Color, LocalizedString, CountryCode, LocaleCode, LocalizedValue, Prettify } from './Common';\r\nimport { GenderCategory, ImageCategory, LocaleLanguageMap } from \"./Enum\";\r\nimport { DuplicateSelectionAttributeError, DuplicateSizeError, SelectionAttributeParseError } from \"./Error\";\r\nimport ImageInfoModel, { ImageInfoData } from \"./ImageInfo\";\r\nimport { TieredPriceModel, TieredPriceAttributes, TieredPriceData } from \"./TieredPrice\";\r\n\r\nexport type ProductSelectionAttributes = Prettify<{\r\n color: Color[];\r\n size: string[];\r\n} & {\r\n [key: string]: string | string[] | Color[];\r\n}>;\r\n\r\nexport type SelectionAttributes = {\r\n color: Color;\r\n [key: string]: string | Color;\r\n};\r\n\r\nexport type VariantData = {\r\n sku: string;\r\n selectionAttributes: SelectionAttributes;\r\n images: {\r\n primary: ImageInfoData;\r\n gallery: ImageInfoData[];\r\n };\r\n};\r\n\r\nexport type VariantModel = {\r\n sku: string;\r\n selectionAttributes: SelectionAttributes;\r\n images: {\r\n primary: ImageInfoModel;\r\n gallery: ImageInfoModel[];\r\n };\r\n};\r\n\r\n\r\nexport type ProductSpecification = { [key: string]: string | string[] };\r\n\r\nexport type ProductAttributes = BaseAttributes & {\r\n id: string;\r\n key: string;\r\n\r\n name: LocalizedString;\r\n description: LocalizedString;\r\n slug: LocalizedString;\r\n brand: string;\r\n\r\n pricing: {\r\n [country in CountryCode]?: TieredPriceAttributes;\r\n };\r\n\r\n targetGender: GenderCategory;\r\n attributes: ProductSelectionAttributes;\r\n specifications: LocalizedValue<ProductSpecification>;\r\n categories: string[];\r\n\r\n variants: VariantData[];\r\n\r\n // Metadata\r\n isActive: boolean;\r\n searchTags?: LocalizedValue<string[]>;\r\n};\r\n\r\nexport type ProductData = Required<ProductAttributes>\r\n\r\nexport default class ProductModel extends BaseModel {\r\n protected id: string;\r\n protected key: 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 pricing: {\r\n [country in CountryCode]?: TieredPriceModel;\r\n };\r\n\r\n protected variants: VariantModel[];\r\n\r\n protected targetGender: GenderCategory;\r\n protected attributes: ProductSelectionAttributes;\r\n protected specifications: LocalizedValue<ProductSpecification>;\r\n protected categories: string[];\r\n\r\n // Metadata\r\n protected isActive: boolean;\r\n\r\n protected searchTags: LocalizedValue<string[]>;\r\n\r\n static productKeyRegex = /^(?!\\s)(?!.*\\s$)[A-Z0-9-]{4,16}$/;\r\n static productSKURegex = /^(?!\\s)(?!.*\\s$)[A-Z0-9-]{4,16}$/;\r\n\r\n /**\r\n * Generates a unique key for checking uniqueness for a given selection attributes.\r\n * Excludes 'size' from the key generation.\r\n * @param selectionAttributes - The selection attributes.\r\n * @returns A string key representing the unique attribute combination.\r\n */\r\n static generateSelectionAttributesKey(selectionAttributes: SelectionAttributes): string {\r\n if (typeof selectionAttributes !== 'object') {\r\n throw new SelectionAttributeParseError('Selection attributes must be an object');\r\n }\r\n\r\n const sortedKeys = Object.keys(selectionAttributes)\r\n .filter(key => selectionAttributes[key] !== undefined && key.toLowerCase() !== 'size')\r\n .sort()\r\n\r\n return sortedKeys.map(key => {\r\n if ((selectionAttributes[key] as Color).name) {\r\n return `${key}:c+${(selectionAttributes[key] as Color).name}`;\r\n }\r\n return `${key}:${selectionAttributes[key]}`;\r\n }).join('|').toLowerCase();\r\n }\r\n\r\n /**\r\n * Parses a selection attributes key into an object.\r\n * @param key - The selection attributes key to parse.\r\n * @returns An object containing the parsed selection attributes.\r\n */\r\n static parseSelectionAttributesKey(key: string): SelectionAttributes {\r\n try {\r\n const attributes: SelectionAttributes = {} as unknown as SelectionAttributes;\r\n const parts = key.split('|');\r\n for (const part of parts) {\r\n const [key, value] = part.split(':');\r\n if (value.startsWith('c+')) {\r\n attributes[key] = { name: value.slice(2) } as Color;\r\n } else {\r\n attributes[key] = value;\r\n }\r\n }\r\n return attributes;\r\n } catch (error: any) {\r\n throw new SelectionAttributeParseError(error?.message);\r\n }\r\n }\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\r\n this.id = data.id;\r\n this.key = data.key;\r\n\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.pricing = (Object.keys(data.pricing) as CountryCode[]).reduce((acc, country) => {\r\n if (data.pricing[country]) {\r\n acc[country] = new TieredPriceModel(data.pricing[country]);\r\n }\r\n return acc;\r\n }, {} as { [country in CountryCode]?: TieredPriceModel });\r\n\r\n this.targetGender = data.targetGender;\r\n this.attributes = Utils.deepClone(data.attributes);\r\n this.specifications = Utils.deepClone(data.specifications);\r\n this.categories = Utils.deepClone(data.categories);\r\n\r\n const uniqueSelectionAttributes = new Set<string>();\r\n this.variants = (data.variants || []).map(variant => {\r\n if (!variant.selectionAttributes || typeof variant.selectionAttributes !== 'object') {\r\n throw new SelectionAttributeParseError('Selection attributes are required');\r\n }\r\n\r\n this.checkSelectionAttributes(variant.selectionAttributes);\r\n const key = ProductModel.generateSelectionAttributesKey(variant.selectionAttributes);\r\n if (uniqueSelectionAttributes.has(key)) {\r\n throw new DuplicateSelectionAttributeError(key);\r\n }\r\n uniqueSelectionAttributes.add(key);\r\n return {\r\n sku: variant.sku,\r\n selectionAttributes: variant.selectionAttributes,\r\n images: {\r\n primary: new ImageInfoModel(variant.images.primary),\r\n gallery: (variant.images.gallery || []).map(image => new ImageInfoModel(image))\r\n }\r\n };\r\n });\r\n\r\n this.isActive = data.isActive;\r\n this.searchTags = data.searchTags ? Utils.deepClone(data.searchTags) : { en: [] };\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 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[LocaleLanguageMap[locale]] ?? this.name.en;\r\n } else {\r\n return Utils.deepClone(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[LocaleLanguageMap[locale]] ?? this.description.en;\r\n } else {\r\n return Utils.deepClone(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[LocaleLanguageMap[locale]] ?? this.slug.en;\r\n } else {\r\n return Utils.deepClone(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 tiered price details for the product.\r\n * @returns Pricing details mapped by country.\r\n */\r\n getPriceDetails(): { [country in CountryCode]?: TieredPriceModel }\r\n /**\r\n * Gets the tiered price details for a specific country.\r\n * @param country - The country code.\r\n * @returns The tiered price model for the country, or null if not found.\r\n */\r\n getPriceDetails(country: CountryCode): TieredPriceModel | null\r\n getPriceDetails(country?: CountryCode): { [country in CountryCode]?: TieredPriceModel } | TieredPriceModel | null {\r\n if (country) {\r\n return this.pricing[country] ?? null;\r\n }\r\n return this.pricing;\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(): ProductSelectionAttributes {\r\n return Utils.deepClone(this.attributes);\r\n }\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 getVariants(): VariantModel[] {\r\n return this.variants.map(variant => ({\r\n sku: variant.sku,\r\n selectionAttributes: variant.selectionAttributes,\r\n images: {\r\n primary: variant.images.primary,\r\n gallery: variant.images.gallery\r\n }\r\n }));\r\n }\r\n\r\n /**\r\n * Gets the images for a specific selection attribute combination.\r\n * @param selectionAttributes - The selection attributes to search for.\r\n * @returns The matching image set or null if not found.\r\n */\r\n private getImagesBySelectionAttributes(selectionAttributes: SelectionAttributes): { primary: ImageInfoModel; gallery: ImageInfoModel[] } | null {\r\n const searchKey = ProductModel.generateSelectionAttributesKey(selectionAttributes);\r\n\r\n const match = this.variants.find(variant =>\r\n ProductModel.generateSelectionAttributesKey(variant.selectionAttributes) === searchKey\r\n );\r\n\r\n return match ? match.images : null;\r\n }\r\n\r\n /**\r\n * Gets the images for a specific selection attribute combination.\r\n * @param selectionAttributes - The selection attributes to search for.\r\n * @returns The matching image set or null if not found.\r\n */\r\n getImages(selectionAttributes: SelectionAttributes): { primary: ImageInfoModel; gallery: ImageInfoModel[] }\r\n getImages(selectionAttributes: SelectionAttributes, category: ImageCategory.PRIMARY): ImageInfoModel\r\n getImages(selectionAttributes: SelectionAttributes, category: ImageCategory.GALLERY): ImageInfoModel[]\r\n getImages(selectionAttributes: SelectionAttributes, category?: ImageCategory): { primary: ImageInfoModel; gallery: ImageInfoModel[] } | ImageInfoModel | ImageInfoModel[] {\r\n switch (category) {\r\n case ImageCategory.PRIMARY:\r\n return this.getImagesBySelectionAttributes(selectionAttributes)?.primary ?? this.variants[0]?.images?.primary;\r\n case ImageCategory.GALLERY:\r\n return this.getImagesBySelectionAttributes(selectionAttributes)?.gallery ?? [];\r\n default:\r\n return this.getImagesBySelectionAttributes(selectionAttributes) ?? { primary: this.variants[0]?.images?.primary, gallery: [] };\r\n }\r\n }\r\n\r\n\r\n /**\r\n * Checks if the product 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 Utils.deepClone(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(): LocalizedValue<ProductSpecification>\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\r\n getSpecifications(locale?: LocaleCode): LocalizedValue<ProductSpecification> | ProductSpecification {\r\n if (locale) {\r\n return Utils.deepClone(this.specifications[locale] ?? this.specifications[LocaleLanguageMap[locale]] ?? this.specifications.en);\r\n } else {\r\n return Utils.deepClone(this.specifications);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the localized list of search tags. Returns a copy.\r\n * @returns Localized array of search tags.\r\n */\r\n getSearchTags(): LocalizedValue<string[]>\r\n /**\r\n * Gets the search tags for a specific locale, falling back to English ('en').\r\n * @param locale - The desired locale code.\r\n * @returns The array of search tags for the specified locale, or undefined if not found.\r\n */\r\n getSearchTags(locale: LocaleCode): string[]\r\n getSearchTags(locale?: LocaleCode): LocalizedValue<string[]> | string[] {\r\n if (locale) {\r\n return Utils.deepClone(this.searchTags[locale] ?? this.searchTags[LocaleLanguageMap[locale]] ?? this.searchTags.en);\r\n } else {\r\n return Utils.deepClone(this.searchTags);\r\n }\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 name: this.getName(),\r\n description: this.getDescription(),\r\n slug: this.getSlug(),\r\n brand: this.getBrand(),\r\n pricing: (Object.keys(this.pricing) as CountryCode[]).reduce((acc, country) => {\r\n if (this.pricing[country]) {\r\n acc[country] = this.pricing[country]?.getDetails();\r\n }\r\n return acc;\r\n }, {} as { [country in CountryCode]: TieredPriceData }),\r\n attributes: this.getAttributes(),\r\n variants: this.variants.map(v => ({\r\n sku: v.sku,\r\n selectionAttributes: Utils.deepClone(v.selectionAttributes),\r\n images: {\r\n primary: v.images.primary.getDetails(),\r\n gallery: v.images.gallery.map(img => img.getDetails())\r\n }\r\n })),\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 * Checks if the provided selection attributes are valid for the product.\r\n * @param selectionAttributes The selection attributes to validate.\r\n * @throws {SelectionAttributeParseError} If the selection attributes are invalid.\r\n */\r\n checkSelectionAttributes(selectionAttributes: SelectionAttributes): void {\r\n if (!selectionAttributes || typeof selectionAttributes !== 'object') {\r\n throw new SelectionAttributeParseError('Selection attributes are required');\r\n }\r\n\r\n Object.keys(this.attributes).forEach(key => {\r\n if(key.toLowerCase() === 'size') return;\r\n \r\n const allowedAttributeValues = this.attributes[key];\r\n const providedValue = selectionAttributes[key];\r\n\r\n if (providedValue === undefined) {\r\n throw new SelectionAttributeParseError(`Selection attribute '${key}' is missing`);\r\n }\r\n\r\n if (typeof allowedAttributeValues === 'string') {\r\n if (typeof providedValue !== 'string' || allowedAttributeValues !== providedValue) {\r\n throw new SelectionAttributeParseError(`Selection attribute '${key}' is invalid`);\r\n }\r\n } else if (Array.isArray(allowedAttributeValues)) {\r\n if (allowedAttributeValues.length > 0 && typeof allowedAttributeValues[0] === 'string') {\r\n if (typeof providedValue !== 'string' || !(allowedAttributeValues as string[]).includes(providedValue)) {\r\n throw new SelectionAttributeParseError(`Selection attribute '${key}' is invalid`);\r\n }\r\n } else {\r\n // Color validation\r\n if (\r\n typeof providedValue !== 'object' ||\r\n !('name' in providedValue) ||\r\n (allowedAttributeValues as Color[]).findIndex(c => c.name === (providedValue as Color).name) < 0\r\n ) {\r\n throw new SelectionAttributeParseError(`Selection attribute '${key}' is invalid`);\r\n }\r\n }\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Validates if the provided selection attributes exist for this product.\r\n * @param selectionAttributes - The attributes to validate.\r\n * @returns True if a valid selection attribute exists, false otherwise.\r\n */\r\n validateSelectionAttribute(selectionAttributes: SelectionAttributes): boolean {\r\n const searchKey = ProductModel.generateSelectionAttributesKey(selectionAttributes);\r\n\r\n return this.variants.some(variant => ProductModel.generateSelectionAttributesKey(variant.selectionAttributes) === searchKey);\r\n }\r\n\r\n /**\r\n * Validates if a specific size is available for this product.\r\n * @param size - The size to check.\r\n * @returns True if the size exists in the product's attributes, false otherwise.\r\n */\r\n validateSize(size: string): boolean {\r\n return this.attributes.size.includes(size);\r\n }\r\n}"]}
@@ -0,0 +1,2 @@
1
+ import {b}from'./chunk-XXETAAL4.mjs';import {a as a$2}from'./chunk-JE7BAYI5.mjs';import {a as a$1}from'./chunk-6X5O25W5.mjs';import {a}from'./chunk-6KCJVEZD.mjs';var u=class extends a{id;name;category;lineItemId;chargeType;pricing;total;constructor(t){super(t),this.id=t.id,this.name=t.name,this.category=t.category,this.lineItemId=t.lineItemId,this.chargeType=t.chargeType,this.pricing={price:new a$1(t.pricing.price),taxCategory:t.pricing.taxCategory,applicableTaxRule:t.pricing.applicableTaxRule.map(a=>new b(a))},this.total={price:new a$1(t.total.price),discounts:Object.fromEntries(Object.entries(t.total.discounts).map(([a,e])=>[a,new a$1(e)])),totalDiscount:new a$1(t.total.totalDiscount),netPrice:new a$1(t.total.netPrice),taxBreakdown:Object.fromEntries(Object.entries(t.total.taxBreakdown).map(([a,e])=>[a,{rate:e.rate,taxablePrice:new a$1(e.taxablePrice),amount:new a$1(e.amount),system:e.system,subSystem:e.subSystem}])),taxTotal:new a$1(t.total.taxTotal),grandTotal:new a$1(t.total.grandTotal)};}getId(){return this.id}getName(){return this.name}getCategory(){return this.category}getChargeType(){return this.chargeType}getLineItemId(){return this.lineItemId}getPricing(){return this.pricing}getTotal(){return this.total}getApplicableTaxRules(){return this.pricing.applicableTaxRule}updateDiscounts(t){let a={};t.forEach(e=>{a[e.coupon.getCode()]=e.amount;}),this.total.discounts=a,this.calculateTotals();}calculateTotals(){let t=this.pricing.price.zero(),a=this.pricing.price,e=Object.values(this.total.discounts).reduce((i,o)=>i.add(o),t),c=a.subtract(e),n={},d=this.pricing.applicableTaxRule.reduce((i,o)=>i+o.getApplicableTaxRate(),0),s=c.divide(1+d).round(),p=c.subtract(s),g=t,l=this.pricing.applicableTaxRule.reduce((i,o)=>o.getApplicableTaxRate()>i.getApplicableTaxRate()?o:i),m=l.getTaxRuleId();this.pricing.applicableTaxRule.forEach(i=>{if(i.getTaxRuleId()===m)return;let o=i.getApplicableTaxRate(),x=p.multiply(o).divide(d).round();n[i.getTaxRuleId()]={rate:o,taxablePrice:s,amount:x,system:i.getTaxSystem(),subSystem:i.getTaxSubSystem()},g=g.add(x);});let y=p.subtract(g);n[m]={rate:l.getApplicableTaxRate(),taxablePrice:s,amount:y,system:l.getTaxSystem(),subSystem:l.getTaxSubSystem()};let P=s,C=c;this.total={price:a,discounts:this.total.discounts,netPrice:P,totalDiscount:e,taxBreakdown:n,taxTotal:p,grandTotal:C};}updateTax(t){this.pricing.applicableTaxRule=t,this.calculateTotals();}getDetails(){return {id:this.id,name:a$2.deepClone(this.name),category:this.category,lineItemId:this.lineItemId,chargeType:this.chargeType,pricing:{price:this.pricing.price.getDetails(),taxCategory:this.pricing.taxCategory,applicableTaxRule:this.pricing.applicableTaxRule.map(a=>a.getDetails())},total:{price:this.total.price.getDetails(),discounts:Object.fromEntries(Object.entries(this.total.discounts).map(([a,e])=>[a,e.getDetails()])),totalDiscount:this.total.totalDiscount.getDetails(),netPrice:this.total.netPrice.getDetails(),taxBreakdown:Object.fromEntries(Object.entries(this.total.taxBreakdown).map(([a,e])=>[a,{rate:e.rate,taxablePrice:e.taxablePrice.getDetails(),amount:e.amount.getDetails(),system:e.system,subSystem:e.subSystem}])),taxTotal:this.total.taxTotal.getDetails(),grandTotal:this.total.grandTotal.getDetails()},customFields:this.getAllCustomFields()}}};export{u as a};//# sourceMappingURL=chunk-KKQLCW6A.mjs.map
2
+ //# sourceMappingURL=chunk-KKQLCW6A.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/Classes/Charge.ts"],"names":["ChargeModel","CustomFieldModel","data","PriceModel","r","FixedTaxRuleModel","discountId","discount","taxRuleId","taxBreakdown","appliedDiscounts","chargeDiscounts","zero","price","totalDiscount","sum","s","grossAmount","totalRate","taxableBase","totalTaxAmount","distributedTax","maxRateRule","prev","current","maxRateRuleId","taxRule","rate","taxAmount","maxRateTaxAmount","netPrice","grandTotal","applicableTaxRule","Utils_default","k","v"],"mappings":"kKAqEA,IAAqBA,CAArB,CAAA,cAAyCC,CAAiB,CAC5C,GACA,IACA,CAAA,QAAA,CACA,UACA,CAAA,UAAA,CACA,OAKA,CAAA,KAAA,CAEV,WAAYC,CAAAA,CAAAA,CAAwB,CAChC,KAAMA,CAAAA,CAAI,CACV,CAAA,IAAA,CAAK,EAAKA,CAAAA,CAAAA,CAAK,EACf,CAAA,IAAA,CAAK,KAAOA,CAAK,CAAA,IAAA,CACjB,IAAK,CAAA,QAAA,CAAWA,EAAK,QACrB,CAAA,IAAA,CAAK,UAAaA,CAAAA,CAAAA,CAAK,WACvB,IAAK,CAAA,UAAA,CAAaA,CAAK,CAAA,UAAA,CACvB,IAAK,CAAA,OAAA,CAAU,CACX,KAAA,CAAO,IAAIC,GAAWD,CAAAA,CAAAA,CAAK,OAAQ,CAAA,KAAK,EACxC,WAAaA,CAAAA,CAAAA,CAAK,OAAQ,CAAA,WAAA,CAC1B,kBAA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,CAAA,UAAA,EAC9B,CAAA,YAAA,CAAc,OAAO,WAAY,CAAA,MAAA,CAAO,OAAQ,CAAA,IAAA,CAAK,KAAM,CAAA,YAAY,CAAE,CAAA,GAAA,CAAI,CAAC,CAACD,CAAAA,CAAGC,CAAC,CAAA,GAAM,CAACD,CAAG,CAAA,CACzF,IAAMC,CAAAA,CAAAA,CAAE,KACR,YAAcA,CAAAA,CAAAA,CAAE,YAAa,CAAA,UAAA,EAC7B,CAAA,MAAA,CAAQA,CAAE,CAAA,MAAA,CAAO,YACjB,CAAA,MAAA,CAAQA,CAAE,CAAA,MAAA,CACV,UAAWA,CAAE,CAAA,SACjB,CAAC,CAAC,CAAC,CACH,CAAA,QAAA,CAAU,IAAK,CAAA,KAAA,CAAM,QAAS,CAAA,UAAA,EAC9B,CAAA,UAAA,CAAY,KAAK,KAAM,CAAA,UAAA,CAAW,UAAW,EACjD,EACA,YAAc,CAAA,IAAA,CAAK,kBAAmB,EAC1C,CAEJ,CACJ","file":"chunk-KKQLCW6A.mjs","sourcesContent":["import BaseModel, { BaseAttributes, BaseData, CustomFieldAttributes, CustomFieldModel } from \"./Base\";\r\nimport Utils from \"../Utils\";\r\nimport { LocalizedString } from \"./Common\";\r\nimport { ChargeType, TaxSystem } from \"./Enum\";\r\nimport { InvalidChargeError } from \"./Error\";\r\nimport PriceModel, { PriceData } from \"./Price\";\r\nimport { FixedTaxRuleData, FixedTaxRuleModel, TaxRuleData, TaxRuleModel } from \"./TaxRule\";\r\nimport CouponModel from \"./Coupon\";\r\n\r\nexport type ChargePricing = {\r\n price: PriceData;\r\n taxCategory: string;\r\n applicableTaxRule: FixedTaxRuleData[];\r\n};\r\n\r\nexport type ChargeTaxBreakdown = {\r\n rate: number;\r\n taxablePrice: PriceData;\r\n amount: PriceData;\r\n system: TaxSystem;\r\n subSystem: string;\r\n};\r\n\r\nexport type ChargeTaxBreakdownModel = {\r\n rate: number;\r\n taxablePrice: PriceModel;\r\n amount: PriceModel;\r\n system: TaxSystem;\r\n subSystem: string;\r\n};\r\n\r\nexport type ChargeTotals = {\r\n price: PriceData;\r\n discounts: Record<string, PriceData>;\r\n totalDiscount: PriceData;\r\n netPrice: PriceData;\r\n taxBreakdown: Record<string, ChargeTaxBreakdown>;\r\n taxTotal: PriceData;\r\n grandTotal: PriceData;\r\n};\r\n\r\nexport type ChargeTotalsModel = {\r\n price: PriceModel;\r\n discounts: Record<string, PriceModel>;\r\n totalDiscount: PriceModel;\r\n netPrice: PriceModel;\r\n taxBreakdown: Record<string, ChargeTaxBreakdownModel>;\r\n taxTotal: PriceModel;\r\n grandTotal: PriceModel;\r\n};\r\n\r\nexport type ChargeAttributes = CustomFieldAttributes & {\r\n id: string;\r\n name: LocalizedString;\r\n category: string;\r\n lineItemId?: string;\r\n chargeType: ChargeType;\r\n pricing: ChargePricing;\r\n total: ChargeTotals;\r\n};\r\n\r\nexport type ChargeData = Omit<Required<ChargeAttributes>, 'lineItemId'> & {\r\n lineItemId?: string;\r\n};\r\n\r\n/**\r\n * Represents an additional charge (or discount if amount is negative) in a shopping container.\r\n * Supports its own tax rules.\r\n */\r\nexport default class ChargeModel extends CustomFieldModel {\r\n protected id: string;\r\n protected name: LocalizedString;\r\n protected category: string;\r\n protected lineItemId?: string;\r\n protected chargeType: ChargeType;\r\n protected pricing: {\r\n price: PriceModel;\r\n taxCategory: string;\r\n applicableTaxRule: FixedTaxRuleModel[];\r\n };\r\n protected total: ChargeTotalsModel;\r\n\r\n constructor(data: ChargeAttributes) {\r\n super(data);\r\n this.id = data.id;\r\n this.name = data.name;\r\n this.category = data.category;\r\n this.lineItemId = data.lineItemId;\r\n this.chargeType = data.chargeType;\r\n this.pricing = {\r\n price: new PriceModel(data.pricing.price),\r\n taxCategory: data.pricing.taxCategory,\r\n applicableTaxRule: data.pricing.applicableTaxRule.map(r => new FixedTaxRuleModel(r))\r\n };\r\n\r\n this.total = {\r\n price: new PriceModel(data.total.price),\r\n discounts: Object.fromEntries(\r\n Object.entries(data.total.discounts).map(([discountId, discount]) => [\r\n discountId,\r\n new PriceModel(discount)\r\n ])\r\n ),\r\n totalDiscount: new PriceModel(data.total.totalDiscount),\r\n netPrice: new PriceModel(data.total.netPrice),\r\n taxBreakdown: Object.fromEntries(\r\n Object.entries(data.total.taxBreakdown).map(([taxRuleId, taxBreakdown]) => [\r\n taxRuleId,\r\n {\r\n rate: taxBreakdown.rate,\r\n taxablePrice: new PriceModel(taxBreakdown.taxablePrice),\r\n amount: new PriceModel(taxBreakdown.amount),\r\n system: taxBreakdown.system,\r\n subSystem: taxBreakdown.subSystem\r\n }\r\n ])\r\n ),\r\n taxTotal: new PriceModel(data.total.taxTotal),\r\n grandTotal: new PriceModel(data.total.grandTotal),\r\n };\r\n }\r\n\r\n public getId(): string { return this.id; }\r\n public getName(): LocalizedString { return this.name; }\r\n public getCategory(): string { return this.category; }\r\n public getChargeType(): ChargeType { return this.chargeType; }\r\n public getLineItemId(): string | undefined { return this.lineItemId; }\r\n public getPricing() { return this.pricing; }\r\n public getTotal(): ChargeTotalsModel { return this.total; }\r\n\r\n public getApplicableTaxRules(): TaxRuleModel[] {\r\n return this.pricing.applicableTaxRule;\r\n }\r\n\r\n\r\n /**\r\n * Updates the discounts applied to this line item and recalculates totals.\r\n * @param appliedDiscounts - List of coupons and their allocated discount amounts.\r\n */\r\n public updateDiscounts(appliedDiscounts: { coupon: CouponModel, amount: PriceModel }[]): void {\r\n let chargeDiscounts = {} as Record<string, PriceModel>;\r\n appliedDiscounts.forEach(discount => {\r\n chargeDiscounts[discount.coupon.getCode()] = discount.amount;\r\n });\r\n\r\n this.total.discounts = chargeDiscounts;\r\n this.calculateTotals();\r\n }\r\n\r\n public calculateTotals(): void {\r\n const zero = this.pricing.price.zero();\r\n const price = this.pricing.price;\r\n\r\n const totalDiscount = Object.values(this.total.discounts).reduce((sum, s) => sum.add(s), zero);\r\n const grossAmount = price.subtract(totalDiscount);\r\n\r\n const taxBreakdown: Record<string, ChargeTaxBreakdownModel> = {};\r\n\r\n // 1. Calculate total rate for inclusive back-calculation\r\n const totalRate = this.pricing.applicableTaxRule.reduce((sum, r) => sum + r.getApplicableTaxRate(), 0);\r\n\r\n // 2. Calculate BASE and TOTAL TAX using balancing logic\r\n // We round the base first, then define tax as the residual (Gross - Base)\r\n // This guarantees Base + Tax === GrandTotal (inclusive price)\r\n const taxableBase = grossAmount.divide(1 + totalRate).round();\r\n const totalTaxAmount = grossAmount.subtract(taxableBase);\r\n\r\n // 3. Distribute total tax among rules\r\n // We find the rule with the largest rate to absorb the rounding residual\r\n let distributedTax = zero;\r\n const maxRateRule = this.pricing.applicableTaxRule.reduce((prev, current) =>\r\n (current.getApplicableTaxRate() > prev.getApplicableTaxRate()) ? current : prev\r\n );\r\n const maxRateRuleId = maxRateRule.getTaxRuleId();\r\n\r\n // Calculate all other rules first\r\n this.pricing.applicableTaxRule.forEach((taxRule) => {\r\n if (taxRule.getTaxRuleId() === maxRateRuleId) return;\r\n\r\n const rate = taxRule.getApplicableTaxRate();\r\n const taxAmount = totalTaxAmount.multiply(rate).divide(totalRate).round();\r\n\r\n taxBreakdown[taxRule.getTaxRuleId()] = {\r\n rate: rate,\r\n taxablePrice: taxableBase,\r\n amount: taxAmount,\r\n system: taxRule.getTaxSystem(),\r\n subSystem: taxRule.getTaxSubSystem()\r\n };\r\n distributedTax = distributedTax.add(taxAmount);\r\n });\r\n\r\n // Assign residual to the largest rate rule\r\n const maxRateTaxAmount = totalTaxAmount.subtract(distributedTax);\r\n taxBreakdown[maxRateRuleId] = {\r\n rate: maxRateRule.getApplicableTaxRate(),\r\n taxablePrice: taxableBase,\r\n amount: maxRateTaxAmount,\r\n system: maxRateRule.getTaxSystem(),\r\n subSystem: maxRateRule.getTaxSubSystem()\r\n };\r\n\r\n const netPrice = taxableBase;\r\n const grandTotal = grossAmount;\r\n\r\n this.total = {\r\n price: price,\r\n discounts: this.total.discounts,\r\n netPrice: netPrice,\r\n totalDiscount: totalDiscount,\r\n taxBreakdown: taxBreakdown,\r\n taxTotal: totalTaxAmount,\r\n grandTotal: grandTotal\r\n };\r\n }\r\n\r\n public updateTax(applicableTaxRule: FixedTaxRuleModel[]): void {\r\n this.pricing.applicableTaxRule = applicableTaxRule;\r\n this.calculateTotals();\r\n }\r\n\r\n\r\n public getDetails(): ChargeData {\r\n const details: ChargeData = {\r\n id: this.id,\r\n name: Utils.deepClone(this.name),\r\n category: this.category,\r\n lineItemId: this.lineItemId,\r\n chargeType: this.chargeType,\r\n pricing: {\r\n price: this.pricing.price.getDetails(),\r\n taxCategory: this.pricing.taxCategory,\r\n applicableTaxRule: this.pricing.applicableTaxRule.map(r => r.getDetails())\r\n },\r\n total: {\r\n price: this.total.price.getDetails(),\r\n discounts: Object.fromEntries(Object.entries(this.total.discounts).map(([k, v]) => [k, v.getDetails()])),\r\n totalDiscount: this.total.totalDiscount.getDetails(),\r\n netPrice: this.total.netPrice.getDetails(),\r\n taxBreakdown: Object.fromEntries(Object.entries(this.total.taxBreakdown).map(([k, v]) => [k, {\r\n rate: v.rate,\r\n taxablePrice: v.taxablePrice.getDetails(),\r\n amount: v.amount.getDetails(),\r\n system: v.system,\r\n subSystem: v.subSystem\r\n }])),\r\n taxTotal: this.total.taxTotal.getDetails(),\r\n grandTotal: this.total.grandTotal.getDetails()\r\n },\r\n customFields: this.getAllCustomFields()\r\n };\r\n return details;\r\n }\r\n}\r\n"]}
@@ -0,0 +1,2 @@
1
+ import {a}from'./chunk-IIPG3DTO.mjs';import {b as b$1}from'./chunk-YSUBOEFT.mjs';import {a as a$1}from'./chunk-KKQLCW6A.mjs';import {e}from'./chunk-RSMXGZD4.mjs';import {a as a$2}from'./chunk-JE7BAYI5.mjs';import {a as a$3}from'./chunk-6X5O25W5.mjs';import {b}from'./chunk-6KCJVEZD.mjs';var w=class extends b{id;customerId;customerEmail;anonymousId;lineItems;charges;shippingDetails;shippingAddress;billingAddress;coupons;total;country;currency;locale;constructor(t,s=new Date){super(t,s),this.id=t.id,this.customerId=t.customerId,this.customerEmail=t.customerEmail,this.anonymousId=t.anonymousId,this.country=t.country,this.currency=t.currency,this.locale=t.locale,this.lineItems=(t.lineItems??[]).map(e=>new a(e)),this.charges=(t.charges??[]).map(e=>new a$1(e)),this.billingAddress=t.billingAddress?new b$1(t.billingAddress,s):null,this.shippingAddress=t.shippingAddress?new b$1(t.shippingAddress,s):null,this.coupons=(t.coupons??[]).map(e$1=>new e(e$1)),this.shippingDetails=t.shippingDetails?a$2.deepClone(t.shippingDetails):null,this.total={subtotal:new a$3(t.total.subtotal),netSubtotal:new a$3(t.total.netSubtotal),lineItemTaxTotal:new a$3(t.total.lineItemTaxTotal||{amount:0,currency:t.currency}),lineItemTaxBreakdown:this.mapTaxBreakdown(t.total.lineItemTaxBreakdown||{}),chargesTotal:new a$3(t.total.chargesTotal||{amount:0,currency:t.currency}),shippingCharge:new a$3(t.total.shippingCharge),netShippingCharge:new a$3(t.total.netShippingCharge),chargeTaxTotal:new a$3(t.total.chargeTaxTotal||{amount:0,currency:t.currency}),chargeTaxBreakdown:this.mapTaxBreakdown(t.total.chargeTaxBreakdown||{}),taxTotal:new a$3(t.total.taxTotal),taxBreakdown:this.mapTaxBreakdown(t.total.taxBreakdown),discounts:Object.fromEntries(Object.entries(t.total.discounts).map(([e,o])=>[e,new a$3(o)])),totalDiscount:new a$3(t.total.totalDiscount),grandTotal:new a$3(t.total.grandTotal)};}mapTaxBreakdown(t){return Object.fromEntries(Object.entries(t||{}).map(([s,e])=>[s,{system:e.system,totalAmount:new a$3(e.totalAmount),subSystems:Object.fromEntries(Object.entries(e.subSystems).map(([o,n])=>[o,new a$3(n)]))}]))}serializeTaxBreakdown(t){return Object.fromEntries(Object.entries(t||{}).map(([s,e])=>[s,{system:e.system,totalAmount:e.totalAmount.getDetails(),subSystems:Object.fromEntries(Object.entries(e.subSystems).map(([o,n])=>[o,n.getDetails()]))}]))}getId(){return this.id}getCustomerId(){return this.customerId}getCustomerEmail(){return this.customerEmail}getAnonymousId(){return this.anonymousId}getLineItems(){return this.lineItems.map(t=>new a(t.getDetails()))}getLineItemsCount(){return this.lineItems.length}getCharges(){return this.charges.map(t=>new a$1(t.getDetails()))}addCharge(t){this.charges.push(t),this.calculateTotals();}clearCharges(){this.charges=[],this.calculateTotals();}getShippingDetails(){return this.shippingDetails?{...this.shippingDetails}:null}getShippingAddress(){return this.shippingAddress?new b$1(this.shippingAddress.getDetails()):null}hasShippingAddress(){return !!this.shippingAddress}hasBillingAddress(){return !!this.billingAddress}getBillingAddress(){return this.billingAddress?new b$1(this.billingAddress.getDetails()):null}getCoupons(){return this.coupons}getCountry(){return this.country}getCurrency(){return this.currency}getLocale(){return this.locale}getTotal(){return this.total}getDetails(){let t=this.getTotal();return {...super.getDetails(),id:this.getId(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),anonymousId:this.getAnonymousId(),lineItems:this.getLineItems().map(s=>s.getDetails()),charges:this.getCharges().map(s=>s.getDetails()),shippingDetails:this.getShippingDetails(),shippingAddress:this.getShippingAddress()?.getDetails()||null,billingAddress:this.getBillingAddress()?.getDetails()||null,coupons:this.getCoupons().map(s=>s.getDetails()),total:{subtotal:t.subtotal.getDetails(),netSubtotal:t.netSubtotal.getDetails(),lineItemTaxTotal:t.lineItemTaxTotal.getDetails(),lineItemTaxBreakdown:this.serializeTaxBreakdown(t.lineItemTaxBreakdown),chargesTotal:t.chargesTotal.getDetails(),shippingCharge:t.shippingCharge.getDetails(),netShippingCharge:t.netShippingCharge.getDetails(),chargeTaxTotal:t.chargeTaxTotal.getDetails(),chargeTaxBreakdown:this.serializeTaxBreakdown(t.chargeTaxBreakdown),taxTotal:t.taxTotal.getDetails(),taxBreakdown:this.serializeTaxBreakdown(t.taxBreakdown),discounts:Object.fromEntries(Object.entries(t.discounts).map(([s,e])=>[s,e.getDetails()])),totalDiscount:t.totalDiscount.getDetails(),grandTotal:t.grandTotal.getDetails()},country:this.getCountry(),currency:this.getCurrency(),locale:this.getLocale()}}calculateTotals(){let t=new a$3({amount:0,currency:this.currency}),s=this.lineItems.filter(i=>i.getState()!=="CANCELLED"),e=s.reduce((i,a)=>i.add(a.getTotal().subtotal),t),o=s.reduce((i,a)=>i.add(a.getTotal().netSubtotal),t),n=this.charges.filter(i=>i.getChargeType()==="SHIPPING").reduce((i,a)=>i.add(a.getTotal().price),t),u=t,d={},g={};this.coupons.forEach(i=>{let a=i.calculateApplicableCouponDiscount(e,n,this.country,this.currency);u=u.add(a),d[i.getCode()]=a,i.getCategory()!=="SHIPPING"&&(g[i.getCode()]=a);}),this.applyDiscountsInLineItem(g);let l=this.coupons.find(i=>i.getCategory()==="SHIPPING");l&&this.applyDiscuountsInShippingCharges({[l.getCode()]:d[l.getCode()]||t});let p=this.charges.reduce((i,a)=>i.add(a.getTotal().grandTotal),t),m=this.charges.filter(i=>i.getChargeType()==="SHIPPING").reduce((i,a)=>i.add(a.getTotal().grandTotal),t),y=t,x=t,D=t,h={},M={},A={},S=(i,a)=>{Object.entries(i).forEach(([R,T])=>{let r=T.system,C=T.subSystem;a[r]||(a[r]={system:r,totalAmount:t,subSystems:{}}),a[r].subSystems[C]?a[r].subSystems[C]=a[r].subSystems[C].add(T.amount):a[r].subSystems[C]=T.amount,a[r].totalAmount=a[r].totalAmount.add(T.amount),h[r]||(h[r]={system:r,totalAmount:t,subSystems:{}}),h[r].subSystems[C]?h[r].subSystems[C]=h[r].subSystems[C].add(T.amount):h[r].subSystems[C]=T.amount,h[r].totalAmount=h[r].totalAmount.add(T.amount);});};s.forEach(i=>{let a=i.getTotal().taxBreakdown;a&&(S(a,M),S(a,h),x=x.add(i.getTotal().taxTotal));}),this.charges.forEach(i=>{let a=i.getTotal().taxBreakdown;a&&(S(a,A),S(a,h),D=D.add(i.getTotal().taxTotal));}),y=x.add(D);let E=o.add(x).add(p);this.total={subtotal:e,netSubtotal:o,lineItemTaxTotal:x,lineItemTaxBreakdown:M,chargesTotal:p,shippingCharge:n,netShippingCharge:m,chargeTaxTotal:D,chargeTaxBreakdown:A,taxTotal:y,taxBreakdown:h,discounts:d,totalDiscount:u,grandTotal:E};}updateShippingDetails(t){this.shippingDetails=t,this.calculateTotals();}applyCoupons(t){let s=t.filter(o=>o.getCategory()==="SHIPPING"),e=t.filter(o=>o.getCategory()!=="SHIPPING");this.coupons=[],this.total.totalDiscount=this.total.subtotal.zero(),this.total.discounts={},e.length&&this.applyNonShippingCoupons(e),this.applyDiscountsInLineItem(this.total.discounts),s.length&&this.applyShippingCoupons(s),this.calculateTotals();}applyDiscountsInLineItem(t){let s=Array.from(Object.entries(t)).filter(o=>!o[1].isZero()),e=new Map;this.lineItems.forEach(o=>e.set(o.getId(),[])),s.forEach(([o,n])=>{let u=this.coupons.find(l=>l.getCode()===o);if(!u||n.isZero())return;let d=this.lineItems.filter(l=>l.getState()!=="CANCELLED"&&!l.getTotal().subtotal.isZero()).sort((l,p)=>l.getTotal().subtotal.compareTo(p.getTotal().subtotal)),g=new a$3({amount:0,currency:this.currency});d.forEach((l,p)=>{let m;p===d.length-1?m=n.subtract(g):m=n.multiply(l.getTotal().subtotal).divide(this.total.subtotal).round(),g=g.add(m),e.get(l.getId())?.push({coupon:u,amount:m});});}),this.lineItems.forEach(o=>{o.getState()==="CANCELLED"||this.total.subtotal.isZero()?o.updateDiscounts([]):o.updateDiscounts(e.get(o.getId())||[]);});}applyDiscuountsInShippingCharges(t){let s=Array.from(Object.entries(t)).filter(n=>!n[1].isZero()),e=this.charges.filter(n=>n.getChargeType()==="SHIPPING"),o=new Map;e.forEach(n=>o.set(n.getId(),[])),s.forEach(([n,u])=>{let d=this.coupons.find(p=>p.getCode()===n);if(!d||u.isZero())return;let g=e.sort((p,m)=>p.getTotal().grandTotal.compareTo(m.getTotal().grandTotal)),l=new a$3({amount:0,currency:this.currency});g.forEach((p,m)=>{let y;m===g.length-1?y=u.subtract(l):y=u.multiply(p.getTotal().grandTotal).divide(this.total.subtotal).round(),l=l.add(y),o.get(p.getId())?.push({coupon:d,amount:y});});}),e.forEach(n=>{n.updateDiscounts(o.get(n.getId())||[]);});}updateTax(t,s={}){this.lineItems.forEach(e=>{let o=t[e.getId()];o&&e.updateTax(o);}),this.charges.forEach(e=>{let o=s[e.getId()];o&&e.updateTax(o);}),this.calculateTotals();}applyNonShippingCoupons(t){let s=t.filter(e=>e.getType()==="coupon");if(s.length===1){let e=s[0].calculateApplicableCouponDiscount(this.total.subtotal,this.total.shippingCharge,this.country,this.currency);e.getAmount()>0&&(this.coupons.push(s[0]),this.total.discounts[s[0].getCode()]=e,this.total.totalDiscount=e);}}applyShippingCoupons(t){if(this.total.shippingCharge.getAmount()>0&&t.length>0){let s=this.total.subtotal.subtract(this.total.totalDiscount),e=t.reduce((n,u)=>{if(!n)return u;let d=u.calculateApplicableCouponDiscount(s,this.total.shippingCharge,this.country,this.currency).min(this.total.shippingCharge),g=n.calculateApplicableCouponDiscount(s,this.total.shippingCharge,this.country,this.currency).min(this.total.shippingCharge);return d===g?u.getType()==="coupon"?u:n:d.compareTo(g)>0?u:n}),o=e.calculateApplicableCouponDiscount(s,this.total.shippingCharge,this.country,this.currency).min(this.total.shippingCharge);o.getAmount()>0&&(this.coupons.push(e),this.total.discounts[e.getCode()]=o,this.total.totalDiscount=this.total.totalDiscount.add(o),this.total.netShippingCharge=this.total.shippingCharge.subtract(o));}}};export{w as a};//# sourceMappingURL=chunk-PTIPDRB4.mjs.map
2
+ //# sourceMappingURL=chunk-PTIPDRB4.mjs.map