b23-lib 2.0.17 → 2.0.18

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 (89) 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/Address.d.mts +1 -1
  5. package/dist/Classes/Address.d.ts +1 -1
  6. package/dist/Classes/Base.d.mts +1 -1
  7. package/dist/Classes/Base.d.ts +1 -1
  8. package/dist/Classes/Cart.d.mts +1 -1
  9. package/dist/Classes/Cart.d.ts +1 -1
  10. package/dist/Classes/Cart.js +1 -1
  11. package/dist/Classes/Cart.js.map +1 -1
  12. package/dist/Classes/Cart.mjs +1 -1
  13. package/dist/Classes/Common.d.mts +1 -1
  14. package/dist/Classes/Common.d.ts +1 -1
  15. package/dist/Classes/Coupon.d.mts +1 -1
  16. package/dist/Classes/Coupon.d.ts +1 -1
  17. package/dist/Classes/Coupon.js +1 -1
  18. package/dist/Classes/Coupon.js.map +1 -1
  19. package/dist/Classes/Coupon.mjs +1 -1
  20. package/dist/Classes/Customer.d.mts +1 -1
  21. package/dist/Classes/Customer.d.ts +1 -1
  22. package/dist/Classes/CustomerAddress.d.mts +1 -1
  23. package/dist/Classes/CustomerAddress.d.ts +1 -1
  24. package/dist/Classes/Inventory.d.mts +1 -1
  25. package/dist/Classes/Inventory.d.ts +1 -1
  26. package/dist/Classes/Inventory.js +1 -1
  27. package/dist/Classes/Inventory.js.map +1 -1
  28. package/dist/Classes/Inventory.mjs +1 -1
  29. package/dist/Classes/LineItem.d.mts +1 -1
  30. package/dist/Classes/LineItem.d.ts +1 -1
  31. package/dist/Classes/LineItem.js +1 -1
  32. package/dist/Classes/LineItem.js.map +1 -1
  33. package/dist/Classes/LineItem.mjs +1 -1
  34. package/dist/Classes/Order.d.mts +1 -1
  35. package/dist/Classes/Order.d.ts +1 -1
  36. package/dist/Classes/Order.js +1 -1
  37. package/dist/Classes/Order.js.map +1 -1
  38. package/dist/Classes/Order.mjs +1 -1
  39. package/dist/Classes/Payment.d.mts +1 -1
  40. package/dist/Classes/Payment.d.ts +1 -1
  41. package/dist/Classes/Price.d.mts +1 -1
  42. package/dist/Classes/Price.d.ts +1 -1
  43. package/dist/Classes/Price.js +1 -1
  44. package/dist/Classes/Price.js.map +1 -1
  45. package/dist/Classes/Price.mjs +1 -1
  46. package/dist/Classes/Product.d.mts +1 -1
  47. package/dist/Classes/Product.d.ts +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 +1 -1
  52. package/dist/Classes/ShoppingContainer.d.ts +1 -1
  53. package/dist/Classes/ShoppingContainer.js +1 -1
  54. package/dist/Classes/ShoppingContainer.js.map +1 -1
  55. package/dist/Classes/ShoppingContainer.mjs +1 -1
  56. package/dist/Classes/TaxRule.d.mts +1 -1
  57. package/dist/Classes/TaxRule.d.ts +1 -1
  58. package/dist/Classes/TaxRule.js +1 -1
  59. package/dist/Classes/TaxRule.js.map +1 -1
  60. package/dist/Classes/TaxRule.mjs +1 -1
  61. package/dist/Classes/TieredPrice.d.mts +1 -1
  62. package/dist/Classes/TieredPrice.d.ts +1 -1
  63. package/dist/Classes/TieredPrice.js +1 -1
  64. package/dist/Classes/TieredPrice.js.map +1 -1
  65. package/dist/Classes/TieredPrice.mjs +1 -1
  66. package/dist/{Common-5lGZCX-j.d.mts → Common-Bd8Xv8x4.d.mts} +3 -0
  67. package/dist/{Common-C6bnAhuf.d.ts → Common-CXp_zjft.d.ts} +3 -0
  68. package/dist/{chunk-KGCBP35B.mjs → chunk-32EBLG32.mjs} +2 -2
  69. package/dist/{chunk-KGCBP35B.mjs.map → chunk-32EBLG32.mjs.map} +1 -1
  70. package/dist/{chunk-ZHUEVC3L.mjs → chunk-53QIYV5Y.mjs} +2 -2
  71. package/dist/{chunk-ZHUEVC3L.mjs.map → chunk-53QIYV5Y.mjs.map} +1 -1
  72. package/dist/{chunk-G5ZDSYCU.mjs → chunk-BJS5MEA4.mjs} +2 -2
  73. package/dist/{chunk-G5ZDSYCU.mjs.map → chunk-BJS5MEA4.mjs.map} +1 -1
  74. package/dist/chunk-R32ZSPV6.mjs +2 -0
  75. package/dist/chunk-R32ZSPV6.mjs.map +1 -0
  76. package/dist/{chunk-WEXGU2UL.mjs → chunk-U5CHHGFX.mjs} +2 -2
  77. package/dist/{chunk-WEXGU2UL.mjs.map → chunk-U5CHHGFX.mjs.map} +1 -1
  78. package/dist/{chunk-PE55IHCY.mjs → chunk-VM2PEONB.mjs} +2 -2
  79. package/dist/{chunk-PE55IHCY.mjs.map → chunk-VM2PEONB.mjs.map} +1 -1
  80. package/dist/{chunk-3ZEYSNQ4.mjs → chunk-ZVLJ5BAG.mjs} +2 -2
  81. package/dist/{chunk-3ZEYSNQ4.mjs.map → chunk-ZVLJ5BAG.mjs.map} +1 -1
  82. package/dist/index.d.mts +1 -1
  83. package/dist/index.d.ts +1 -1
  84. package/dist/index.js +1 -1
  85. package/dist/index.js.map +1 -1
  86. package/dist/index.mjs +1 -1
  87. package/package.json +1 -1
  88. package/dist/chunk-5I6SCJMC.mjs +0 -2
  89. package/dist/chunk-5I6SCJMC.mjs.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- export{d as Fetch,b as Logger,c as ResponseUtility}from'./chunk-AMIRIUMH.mjs';import {b}from'./chunk-G5ZDSYCU.mjs';export{a as Utils}from'./chunk-G5ZDSYCU.mjs';import'./chunk-3ZEYSNQ4.mjs';import'./chunk-5I6SCJMC.mjs';import {l,j,a,b as b$1,c,d as d$1}from'./chunk-72DR3HF2.mjs';import'./chunk-7LEGYAOJ.mjs';import'./chunk-DGFO2MH6.mjs';import'./chunk-55SOBG62.mjs';var d={$id:"standards",definitions:{lowercaseText:{type:"string",pattern:"^(?!\\s)(?!.*\\s$)[a-z]*$"},lowercaseText10:{type:"string",pattern:"^(?!\\s)(?!.*\\s$)[a-z]{0,10}$"},lowercaseText16:{type:"string",pattern:"^(?!\\s)(?!.*\\s$)[a-z]{0,16}$"},lowercaseText30:{type:"string",pattern:"^(?!\\s)(?!.*\\s$)[a-z]{0,30}$"},lowercaseText50:{type:"string",pattern:"^(?!\\s)(?!.*\\s$)[a-z]{0,50}$"},lowercaseText256:{type:"string",pattern:"^(?!\\s)(?!.*\\s$)[a-z]{0,256}$"},text:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).*$"},text10:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).{0,10}$"},text16:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).{0,16}$"},text30:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).{0,30}$"},text50:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).{0,50}$"},text256:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).{0,256}$"},requiredText:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).+$"},requiredText10:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).{1,10}$"},requiredText16:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).{1,16}$"},requiredText30:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).{1,30}$"},requiredText50:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).{1,50}$"},requiredText256:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).{1,256}$"},url:{type:"string",pattern:"^https://[^\\s/$.?#].[^\\s]*$",maxLength:2048},uuid:{type:"string",minLength:1,pattern:"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"},productKey:{type:"string",pattern:b.productKeyRegex.source},productSku:{type:"string",pattern:b.productSKURegex.source},taxCategory:{type:"string",enum:Object.values(l)},genderCategory:{type:"string",enum:Object.values(j)},price:{type:"object",properties:{amount:{type:"number",minimum:0},currency:{$ref:"#/definitions/currency"}},required:["amount","currency"]},color:{type:"object",properties:{name:{type:"string"},hexCode:{type:"string"}},required:["name"]},attributeValue:{oneOf:[{type:"string"},{$ref:"#/definitions/color"}]},selectionAttributes:{type:"object",properties:{color:{$ref:"#/definitions/color"}},required:["color"],additionalProperties:{$ref:"#/definitions/attributeValue"}},firstName:{$ref:"#/definitions/requiredText30"},lastName:{$ref:"#/definitions/text30"},company:{$ref:"#/definitions/text50"},phone:{type:"string",pattern:"^[0-9]{10}$"},email:{type:"string",pattern:"^[^\\s]+@[^\\s]+\\.[^\\s]+$"},addressLine1:{$ref:"#/definitions/requiredText50"},addressLine2:{$ref:"#/definitions/text50"},city:{$ref:"#/definitions/requiredText30"},postalCode:{$ref:"#/definitions/requiredText16"},state:{type:"string",enum:["AP","AR","AS","BR","CT","GA","GJ","HR","HP","JH","KA","KL","MP","MH","MN","ML","MZ","NL","OR","PB","RJ","SK","TN","TG","TR","UP","UT","WB","AN","CH","DH","LD","DL","PY","LA","JK"]},country:{type:"string",enum:Object.values(a)},currency:{type:"string",enum:Object.values(b$1)},locale:{type:"string",enum:Object.values(c)},language:{type:"string",enum:Object.values(d$1)},localeOrLanguage:{type:"string",enum:[...Object.values(c),...Object.values(d$1)]},addressType:{type:"string",enum:["shipping","billing","billing&shipping"]},address:{type:"object",properties:{firstName:{$ref:"standards#/definitions/firstName"},lastName:{$ref:"standards#/definitions/lastName"},company:{$ref:"standards#/definitions/company"},phone:{$ref:"standards#/definitions/phone"},email:{$ref:"standards#/definitions/email"},addressLine1:{$ref:"standards#/definitions/addressLine1"},addressLine2:{$ref:"standards#/definitions/addressLine2"},city:{$ref:"standards#/definitions/city"},postalCode:{$ref:"standards#/definitions/postalCode"},state:{$ref:"standards#/definitions/state"},country:{$ref:"standards#/definitions/country"}},required:["firstName","lastName","phone","email","addressLine1","postalCode","state","country"]}}};var $={getStandardSchemaDefinition(){return d}},g=$;
1
+ export{d as Fetch,b as Logger,c as ResponseUtility}from'./chunk-AMIRIUMH.mjs';import {b}from'./chunk-BJS5MEA4.mjs';export{a as Utils}from'./chunk-BJS5MEA4.mjs';import'./chunk-ZVLJ5BAG.mjs';import'./chunk-7LEGYAOJ.mjs';import'./chunk-R32ZSPV6.mjs';import {l,j,a,b as b$1,c,d as d$1}from'./chunk-72DR3HF2.mjs';import'./chunk-DGFO2MH6.mjs';import'./chunk-55SOBG62.mjs';var d={$id:"standards",definitions:{lowercaseText:{type:"string",pattern:"^(?!\\s)(?!.*\\s$)[a-z]*$"},lowercaseText10:{type:"string",pattern:"^(?!\\s)(?!.*\\s$)[a-z]{0,10}$"},lowercaseText16:{type:"string",pattern:"^(?!\\s)(?!.*\\s$)[a-z]{0,16}$"},lowercaseText30:{type:"string",pattern:"^(?!\\s)(?!.*\\s$)[a-z]{0,30}$"},lowercaseText50:{type:"string",pattern:"^(?!\\s)(?!.*\\s$)[a-z]{0,50}$"},lowercaseText256:{type:"string",pattern:"^(?!\\s)(?!.*\\s$)[a-z]{0,256}$"},text:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).*$"},text10:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).{0,10}$"},text16:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).{0,16}$"},text30:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).{0,30}$"},text50:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).{0,50}$"},text256:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).{0,256}$"},requiredText:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).+$"},requiredText10:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).{1,10}$"},requiredText16:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).{1,16}$"},requiredText30:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).{1,30}$"},requiredText50:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).{1,50}$"},requiredText256:{type:"string",pattern:"^(?!\\s)(?!.*\\s$).{1,256}$"},url:{type:"string",pattern:"^https://[^\\s/$.?#].[^\\s]*$",maxLength:2048},uuid:{type:"string",minLength:1,pattern:"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"},productKey:{type:"string",pattern:b.productKeyRegex.source},productSku:{type:"string",pattern:b.productSKURegex.source},taxCategory:{type:"string",enum:Object.values(l)},genderCategory:{type:"string",enum:Object.values(j)},price:{type:"object",properties:{amount:{type:"number",minimum:0},currency:{$ref:"#/definitions/currency"}},required:["amount","currency"]},color:{type:"object",properties:{name:{type:"string"},hexCode:{type:"string"}},required:["name"]},attributeValue:{oneOf:[{type:"string"},{$ref:"#/definitions/color"}]},selectionAttributes:{type:"object",properties:{color:{$ref:"#/definitions/color"}},required:["color"],additionalProperties:{$ref:"#/definitions/attributeValue"}},firstName:{$ref:"#/definitions/requiredText30"},lastName:{$ref:"#/definitions/text30"},company:{$ref:"#/definitions/text50"},phone:{type:"string",pattern:"^[0-9]{10}$"},email:{type:"string",pattern:"^[^\\s]+@[^\\s]+\\.[^\\s]+$"},addressLine1:{$ref:"#/definitions/requiredText50"},addressLine2:{$ref:"#/definitions/text50"},city:{$ref:"#/definitions/requiredText30"},postalCode:{$ref:"#/definitions/requiredText16"},state:{type:"string",enum:["AP","AR","AS","BR","CT","GA","GJ","HR","HP","JH","KA","KL","MP","MH","MN","ML","MZ","NL","OR","PB","RJ","SK","TN","TG","TR","UP","UT","WB","AN","CH","DH","LD","DL","PY","LA","JK"]},country:{type:"string",enum:Object.values(a)},currency:{type:"string",enum:Object.values(b$1)},locale:{type:"string",enum:Object.values(c)},language:{type:"string",enum:Object.values(d$1)},localeOrLanguage:{type:"string",enum:[...Object.values(c),...Object.values(d$1)]},addressType:{type:"string",enum:["shipping","billing","billing&shipping"]},address:{type:"object",properties:{firstName:{$ref:"standards#/definitions/firstName"},lastName:{$ref:"standards#/definitions/lastName"},company:{$ref:"standards#/definitions/company"},phone:{$ref:"standards#/definitions/phone"},email:{$ref:"standards#/definitions/email"},addressLine1:{$ref:"standards#/definitions/addressLine1"},addressLine2:{$ref:"standards#/definitions/addressLine2"},city:{$ref:"standards#/definitions/city"},postalCode:{$ref:"standards#/definitions/postalCode"},state:{$ref:"standards#/definitions/state"},country:{$ref:"standards#/definitions/country"}},required:["firstName","lastName","phone","email","addressLine1","postalCode","state","country"]}}};var $={getStandardSchemaDefinition(){return d}},g=$;
2
2
  export{g as Schema};//# sourceMappingURL=index.mjs.map
3
3
  //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "b23-lib",
3
- "version": "2.0.17",
3
+ "version": "2.0.18",
4
4
  "description": "This repo hold common classes, type and util functiona",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -1,2 +0,0 @@
1
- import {i,h}from'./chunk-72DR3HF2.mjs';import {p,q,r,s}from'./chunk-DGFO2MH6.mjs';var m=class t{amount;currency;constructor(e){if(e.amount<0)throw new p("Amount cannot be negative.");if(!e.currency)throw new q("Currency code is required.");this.amount=e.amount,this.currency=e.currency;}getCurrency(){return this.currency}getAmount(){return this.amount}getDetails(){return {amount:this.amount,currency:this.currency}}compareTo(e){if(e instanceof t){if(this.currency!==e.getCurrency())throw new r("Cannot compare prices in different currencies.")}else throw new s("Must be a PriceModel instance.");return this.amount-e.getAmount()}add(e){if(e instanceof t){if(this.currency!==e.getCurrency())throw new r("Cannot add prices in different currencies.")}else throw new s("Must be a PriceModel instance.");return new t({amount:this.amount+e.getAmount(),currency:this.currency})}subtract(e){if(e instanceof t){if(this.currency!==e.getCurrency())throw new r("Cannot subtract prices in different currencies.")}else throw new s("Must be a PriceModel instance.");return new t({amount:this.amount-e.getAmount(),currency:this.currency})}multiply(e){if(e instanceof t){if(this.currency!==e.getCurrency())throw new r("Cannot multiply prices in different currencies.");return new t({amount:this.amount*e.getAmount(),currency:this.currency})}else if(typeof e=="number"&&e>=0)return new t({amount:this.amount*e,currency:this.currency});throw new s("Must be a non-negative number.")}divide(e){if(e instanceof t){if(this.currency!==e.getCurrency())throw new r("Cannot divide prices in different currencies.");return new t({amount:this.amount/e.getAmount(),currency:this.currency})}else if(typeof e=="number"&&e>0)return new t({amount:this.amount/e,currency:this.currency});throw new s("Must be a positive number.")}min(...e){if(e.length===0)throw new s("Must provide at least one PriceModel.");return e.reduce((r$1,n)=>{if(n instanceof t){if(r$1.getCurrency()!==n.getCurrency())throw new r("Cannot compare prices in different currencies.")}else throw new s("Must be a PriceModel instance.");return r$1.compareTo(n)<0?r$1:n})}max(...e){if(e.length===0)throw new s("Must provide at least one PriceModel.");return e.reduce((r$1,n)=>{if(n instanceof t){if(r$1.getCurrency()!==n.getCurrency())throw new r("Cannot compare prices in different currencies.")}else throw new s("Must be a PriceModel instance.");return r$1.compareTo(n)>0?r$1:n})}zero(){return new t({currency:this.currency,amount:0})}isZero(){return this.amount===0}round(){return new t({currency:this.currency,amount:this.getRoundedAmount()})}getRoundedAmount(){return t.getRoundedAmount(this.amount,this.currency)}getFormattedString(){return t.getFormattedString(this.amount,this.currency)}toString(){return this.getFormattedString()}static getFormattedString(e,r,n={displayAsInteger:!1,style:"currency",currencyDisplay:"symbol"}){let u=i[r];if(!r||!u)throw new q("Invalid currency code for formatting.");let o=e,s=n.displayAsInteger?0:t.getDecimalPlaces(r),h$1={style:n.style??"currency",currency:r,signDisplay:"never",currencyDisplay:n.currencyDisplay,minimumFractionDigits:s,maximumFractionDigits:s};n.displayAsInteger&&(o=Math.ceil(o));try{return new Intl.NumberFormat(u,h$1).format(o)}catch(f){return console.error(`Error formatting price for currency "${r}" and locale "${u}":`,f),`${h[r]??r} ${t.addThousandSeparators(o.toFixed(s))}`}}static getDecimalPlaces(e){switch(e){case"INR":default:return 2}}static addThousandSeparators(e){let r=e.split("."),n=r[0],u=r.length>1?"."+r[1]:"";return n.replace(/\B(?=(\d{3})+(?!\d))/g,",")+u}static getRoundedAmount(e,r){if(e<0)throw new p("Amount cannot be negative for rounding.");if(r===void 0)throw new q("Invalid currency code for rounding.");let n=t.getDecimalPlaces(r),u=Math.pow(10,n);return Math.round(e*u)/u}};export{m as a};//# sourceMappingURL=chunk-5I6SCJMC.mjs.map
2
- //# sourceMappingURL=chunk-5I6SCJMC.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/Classes/Price.ts"],"names":["PriceModel","_PriceModel","data","InvalidPriceAmountError","InvalidCurrencyCodeError","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,CAAW,CACpB,MAAA,CACA,SAQV,WAAYC,CAAAA,CAAAA,CAAuB,CACjC,GAAIA,EAAK,MAAS,CAAA,CAAA,CAChB,MAAM,IAAIC,EAAwB,4BAA4B,CAAA,CAGhE,GAAI,CAACD,EAAK,QACR,CAAA,MAAM,IAAIE,CAAAA,CAAyB,4BAA4B,CAGjE,CAAA,IAAA,CAAK,MAASF,CAAAA,CAAAA,CAAK,OACnB,IAAK,CAAA,QAAA,CAAWA,CAAK,CAAA,SACvB,CAMO,WAA4B,EAAA,CACjC,OAAO,IAAA,CAAK,QACd,CAKO,SAAA,EAAoB,CACzB,OAAO,KAAK,MACd,CAMO,UAAwB,EAAA,CAC7B,OAAO,CACL,MAAA,CAAQ,IAAK,CAAA,MAAA,CACb,SAAU,IAAK,CAAA,QACjB,CACF,CAoCO,UAAUG,CAAgC,CAAA,CAC/C,GAAMA,CAAAA,YAAsBJ,GAErB,GAAI,IAAA,CAAK,QAAaI,GAAAA,CAAAA,CAAW,aACtC,CAAA,MAAM,IAAIC,CAAAA,CAAsB,gDAAgD,CAFhF,CAAA,KAAA,MAAM,IAAIC,CAAAA,CAAqB,gCAAgC,CAKjE,CAAA,OAAO,IAAK,CAAA,MAAA,CAASF,EAAW,SAAU,EAC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AAA,CAAiBb,CAAgBC,CAAAA,CAAAA,CAAgC,CACtE,GAAID,CAAAA,CAAS,CACX,CAAA,MAAM,IAAIX,CAAwB,CAAA,yCAAyC,CAG7E,CAAA,GAAIY,IAAa,KACf,CAAA,CAAA,MAAM,IAAIX,CAAAA,CAAyB,qCAAqC,CAG1E,CAAA,IAAMwB,CAAgB3B,CAAAA,CAAAA,CAAW,iBAAiBc,CAAQ,CAAA,CACpDc,CAAa,CAAA,IAAA,CAAK,IAAI,EAAID,CAAAA,CAAa,CAG7C,CAAA,OAFqB,KAAK,KAAMd,CAAAA,CAAAA,CAASe,CAAU,CAAA,CAAIA,CAGzD,CACF","file":"chunk-5I6SCJMC.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 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 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 /**\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 instanceof 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 instanceof 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 instanceof 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 (factor instanceof PriceModel) {\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 (divisor instanceof PriceModel) {\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 (!(currentPrice instanceof PriceModel)) {\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 });\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 (!(currentPrice instanceof PriceModel)) {\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 });\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}"]}