b23-lib 1.7.32 → 1.7.34

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.
@@ -1,2 +0,0 @@
1
- import {d,e}from'./chunk-65X54TKF.mjs';var s=class i{price;country;constructor(r,e){if(this.country=e,r<0)throw new Error("InvalidPrice: Price cannot be negative.");this.price=r;}getCountry(){return this.country}getRoundedPrice(){return i.getRoundedPrice(this.price,this.country)}getFormattedString(r){return i.getFormattedString(this.price,this.country,r)}static getFormattedString(r,e$1,t,o={}){let c=o.displayAsInteger??!1,n=d[e$1];if(n===void 0)throw new Error("Currency mapping not found for CountryCode");let a=r,d$1=c?0:i.getDecimalPlaces(n),y={style:"currency",currency:n,signDisplay:"never",currencyDisplay:o.currencyDisplay,minimumFractionDigits:d$1,maximumFractionDigits:d$1};c&&(a=Math.round(a));try{return new Intl.NumberFormat(t,y).format(a)}catch(m){return console.error(`Error formatting price for locale "${t}" and currency "${n}":`,m),`${e[n]??n} ${i.addThousandSeparators(a.toFixed(d$1))}`}}static getDecimalPlaces(r){switch(r){case"INR":default:return 2}}static addThousandSeparators(r){let e=r.split("."),t=e[0],o=e.length>1?"."+e[1]:"";return t.replace(/\B(?=(\d{3})+(?!\d))/g,",")+o}static getRoundedPrice(r,e){if(r<0)throw new Error("Price cannot be negative for rounding.");let t=d[e];if(t===void 0)throw new Error(`Currency mapping not found for CountryCode: ${e}`);let o=i.getDecimalPlaces(t),c=Math.pow(10,o);return Math.round(r*c)/c}static getCurrency(r){return d[r]}};export{s as a};//# sourceMappingURL=chunk-GCT7VOSM.mjs.map
2
- //# sourceMappingURL=chunk-GCT7VOSM.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/Classes/Price.ts"],"names":["PriceModel","_PriceModel","price","country","locale","options","displayAsInteger","currency","CountryCurrencyMap","valueToFormat","fractionDigits","formattingOptions","error","CurrencySymbolMap","numStr","parts","integerPart","decimalPart","decimalPlaces","multiplier"],"mappings":"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AAA,CAAE,CAG1E,CAAA,IAAMe,CAAgBjB,CAAAA,CAAAA,CAAW,gBAAiBM,CAAAA,CAAQ,CACpDY,CAAAA,CAAAA,CAAa,IAAK,CAAA,GAAA,CAAI,EAAID,CAAAA,CAAa,CAG7C,CAAA,OAFqB,IAAK,CAAA,KAAA,CAAMhB,CAAQiB,CAAAA,CAAU,CAAIA,CAAAA,CAGxD,CASA,OAAO,WAAYhB,CAAAA,CAAAA,CAA8B,CAC/C,OAAOK,CAAmBL,CAAAA,CAAO,CACnC,CAEF","file":"chunk-GCT7VOSM.mjs","sourcesContent":["import { CountryCode, CurrencyCode, LocaleCode } from \"./Common\"; // Assuming these are in Common.ts\r\nimport { CountryCurrencyMap, CurrencySymbolMap } from \"./Enum\"; // Ensure these maps exist\r\n\r\nexport default class PriceModel {\r\n protected price: number;\r\n protected country: CountryCode;\r\n\r\n /**\r\n * Creates an instance of PriceModel, storing the currency-correct rounded price.\r\n * @param price - The initial price value.\r\n * @param country - The country 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(price: number, country: CountryCode) {\r\n this.country = country;\r\n\r\n if(price < 0) {\r\n throw new Error(\"InvalidPrice: Price cannot be negative.\");\r\n }\r\n\r\n this.price = price\r\n }\r\n\r\n /**\r\n * Gets the country code associated with this price instance.\r\n * The country code is used for determining currency and formatting rules.\r\n * @returns The CountryCode enum value.\r\n */\r\n public getCountry(): CountryCode {\r\n return this.country;\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 getRoundedPrice(): number {\r\n return PriceModel.getRoundedPrice(this.price, this.country);\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 * @param locale - The locale code (e.g., 'en-IN') to use for formatting rules.\r\n * @returns The formatted price string according to locale rules.\r\n * @throws {Error} If the currency mapping for the instance's country is not found (via the static method).\r\n */\r\n public getFormattedString(locale: LocaleCode){\r\n return PriceModel.getFormattedString(this.price, this.country, locale);\r\n }\r\n\r\n /**\r\n * Gets a locale-aware formatted display string for the price.\r\n * Uses Intl.NumberFormat for accurate formatting based on locale and currency.\r\n * @param price - The initial price value.\r\n * @param country - The country code used for rounding and determining the currency symbol.\r\n * @param locale - The locale code (e.g., 'en-IN') to use for formatting rules.\r\n * @param options - Configuration options for formatting.\r\n * @param options.displayAsInteger - If true, the formatted string will show the price rounded to the nearest integer (no decimals). Defaults to false.\r\n * @returns The formatted price string according to locale rules.\r\n */\r\n static getFormattedString(price: number, country: CountryCode, locale: LocaleCode, options: { displayAsInteger?: boolean, currencyDisplay?: 'symbol' | 'narrowSymbol' | 'code' | 'name' } = {}): string {\r\n const displayAsInteger = options.displayAsInteger ?? false;\r\n const currency: CurrencyCode | undefined = CountryCurrencyMap[country];\r\n\r\n if (currency === undefined) {\r\n throw new Error('Currency mapping not found for CountryCode');\r\n }\r\n\r\n let valueToFormat = price;\r\n const fractionDigits = displayAsInteger ? 0 : PriceModel.getDecimalPlaces(currency);\r\n\r\n let formattingOptions: Intl.NumberFormatOptions = {\r\n 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 (displayAsInteger) {\r\n valueToFormat = Math.round(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 locale \"${locale}\" and currency \"${currency}\":`, 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 '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 country - The country code to determine the currency and rounding rules.\r\n * @returns The rounded price as a number.\r\n * @throws {Error} If the country code is not found in the CountryCurrencyMap or price is negative.\r\n */\r\n static getRoundedPrice(price: number, country: CountryCode): number {\r\n if (price < 0) {\r\n throw new Error(\"Price cannot be negative for rounding.\");\r\n }\r\n\r\n const currency: CurrencyCode | undefined = CountryCurrencyMap[country];\r\n if (currency === undefined) {\r\n throw new Error(`Currency mapping not found for CountryCode: ${country}`);\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(price * multiplier) / multiplier;\r\n\r\n return roundedValue;\r\n }\r\n\r\n /**\r\n * Static method to retrieve the currency code associated with a given country code.\r\n * Uses the `CountryCurrencyMap` to find the corresponding currency.\r\n *\r\n * @param country - The country code (e.g., 'IN') for which to find the currency.\r\n * @returns The currency code (e.g., 'INR') as a string, or undefined if the mapping doesn't exist.\r\n */\r\n static getCurrency(country: CountryCode): string {\r\n return CountryCurrencyMap[country];\r\n }\r\n\r\n}"]}
@@ -1,2 +0,0 @@
1
- import v from'crypto';import C from'node:util';var I=new Uint8Array(256),x=I.length;function T(){return x>I.length-16&&(v.randomFillSync(I),x=0),I.slice(x,x+=16)}var O=/^(?:[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 L(t){return typeof t=="string"&&O.test(t)}var R=L;var n=[];for(let t=0;t<256;++t)n.push((t+256).toString(16).slice(1));function y(t,r=0){return n[t[r+0]]+n[t[r+1]]+n[t[r+2]]+n[t[r+3]]+"-"+n[t[r+4]]+n[t[r+5]]+"-"+n[t[r+6]]+n[t[r+7]]+"-"+n[t[r+8]]+n[t[r+9]]+"-"+n[t[r+10]]+n[t[r+11]]+n[t[r+12]]+n[t[r+13]]+n[t[r+14]]+n[t[r+15]]}function h(t){if(!R(t))throw TypeError("Invalid UUID");let r,e=new Uint8Array(16);return e[0]=(r=parseInt(t.slice(0,8),16))>>>24,e[1]=r>>>16&255,e[2]=r>>>8&255,e[3]=r&255,e[4]=(r=parseInt(t.slice(9,13),16))>>>8,e[5]=r&255,e[6]=(r=parseInt(t.slice(14,18),16))>>>8,e[7]=r&255,e[8]=(r=parseInt(t.slice(19,23),16))>>>8,e[9]=r&255,e[10]=(r=parseInt(t.slice(24,36),16))/1099511627776&255,e[11]=r/4294967296&255,e[12]=r>>>24&255,e[13]=r>>>16&255,e[14]=r>>>8&255,e[15]=r&255,e}var A=h;function F(t){t=unescape(encodeURIComponent(t));let r=[];for(let e=0;e<t.length;++e)r.push(t.charCodeAt(e));return r}var P="6ba7b810-9dad-11d1-80b4-00c04fd430c8",$="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function m(t,r,e){function s(u,f,p,o){var g;if(typeof u=="string"&&(u=F(u)),typeof f=="string"&&(f=A(f)),((g=f)===null||g===void 0?void 0:g.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let l=new Uint8Array(16+u.length);if(l.set(f),l.set(u,f.length),l=e(l),l[6]=l[6]&15|r,l[8]=l[8]&63|128,p){o=o||0;for(let d=0;d<16;++d)p[o+d]=l[d];return p}return y(l)}try{s.name=t;}catch{}return s.DNS=P,s.URL=$,s}var _={randomUUID:v.randomUUID};function K(t,r,e){if(_.randomUUID&&!r&&!t)return _.randomUUID();t=t||{};let s=t.random||(t.rng||T)();if(s[6]=s[6]&15|64,s[8]=s[8]&63|128,r){e=e||0;for(let u=0;u<16;++u)r[e+u]=s[u];return r}return y(s)}var S=K;function M(t){return Array.isArray(t)?t=Buffer.from(t):typeof t=="string"&&(t=Buffer.from(t,"utf8")),v.createHash("sha1").update(t).digest()}var D=M;var V=m("v5",80,D),U=V;var Y={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,r)=>r&&t?U(t,r):S(),generateSearchId:(t,r)=>`${t}#${r}`,getKeyfromSearchId:t=>{let[r,e]=t.split("#");return {key:r,variantId:e}}},Dt=Y;var N=Object.freeze({INVALID_UUID:"Invalid UUID",INVALID_EMAIL:"Invalid Email",INVALID_TOKEN:"Invalid Token",TOKEN_EXPIRED:"Token Expired",INVALID_VERIFIER:"Invalid Verifier",INVALID_PERMISSIONS:"Invalid Permissions",INVALID_AUTH_TYPE:"Invalid Authorization Type",USER_PRIVATE_KEY_NOT_FOUND:"User Private Key Not Found",USER_PUBLIC_KEY_NOT_FOUND:"User Public Key Not Found",ANONYMOUS_PRIVATE_KEY_NOT_FOUND:"Anonymous Private Key Not Found",ANONYMOUS_PUBLIC_KEY_NOT_FOUND:"Anonymous Public Key Not Found",SYSTEM_PRIVATE_KEY_NOT_FOUND:"System Private Key Not Found",SYSTEM_PUBLIC_KEY_NOT_FOUND:"System Public Key Not Found",ADMIN_PRIVATE_KEY_NOT_FOUND:"Admin Private Key Not Found",ADMIN_PUBLIC_KEY_NOT_FOUND:"Admin Public Key Not Found",SECRET_TOKEN_NOT_FOUND:"Secret Token Not Found",ANONYMOUS_SESSION_NOT_ALLOWED:"Anonymous Session Not Allowed",USER_SESSION_NOT_ALLOWED:"User Session Not Allowed",SYSTEM_SESSION_NOT_ALLOWED:"System Session Not Allowed",CDN_SESSION_NOT_ALLOWED:"CDN Session Not Allowed",INTERNAL_SERVER_ERROR:"Internal Server Error",SOMETHING_WENT_WRONG:"Something went wrong",AUTH_CONTEXT_NOT_INITIALIZED:"Auth Context not Initialized"});var E={logException:(t,r)=>{console.error(`Exception Occurred in Function: ${t}, Error: ${E.inspect(r)}`);},logError:(t,r)=>{console.error(`Error Occurred in Function: ${t}, Error: ${E.inspect(r)}`);},logWarning:(t,r)=>{console.warn(`Warning in Function: ${t} - ${E.inspect(r)}`);},logMessage:(t,r)=>{console.log(`Message in Function: ${t} - ${E.inspect(r)}`);},logInvalidPayload:(t,r)=>{console.error(`Invalid Payload received for Function: ${t}, Error: ${E.inspect(r)}`);},inspect:t=>typeof t=="string"?t:C.inspect(t)},c=E;var W={handleException:(t,r,e)=>{r.knownError?(r.logError&&c.logError(t,r),e.status(r.status).json({status:r.status,error:r.error})):r.status&&r.error?(c.logException(t,r),e.status(r.status).json({error:r.errorMessage||JSON.stringify(r.error),status:r.status})):(c.logException(t,r),e.status(500).json({status:500,error:N.INTERNAL_SERVER_ERROR}));},generateResponse:(t,r,e)=>({status:t,data:r,error:e}),generateError:(t,r,e=!0,s=!1)=>({status:t,error:r,knownError:e,logError:s})},Mt=W;var B=async(t,r,e="GET",s={},u)=>{let f={method:e,headers:{"Content-Type":"application/json",...s}};e!=="GET"&&u&&(f.body=JSON.stringify(u));let p=`${t}${r?"/"+r:""}`;try{let o=await fetch(p,f);if(!o.ok){let l,d=await o.text();try{l=JSON.parse(d);}catch{l={status:o.status,error:d||o.statusText},c.logWarning("Fetch",`Failed to parse error response body as JSON for URL-${p}. Raw text: ${d}`);}throw {status:o.status,statusText:o.statusText,error:l}}let g=await o.json();return c.logMessage("Fetch",`API call successful: URL-${p}, Status- ${o.status}`),{status:o.status,statusText:o.statusText,data:g.data}}catch(o){throw c.logError("Fetch",`API call failed: URL-${p}, Status- ${o.status||500}, Error- ${c.inspect(o.error||o)}`),{status:o.status||500,statusText:o.statusText||N.INTERNAL_SERVER_ERROR,error:o.error||{status:o.status||500,error:o.statusText||N.SOMETHING_WENT_WRONG}}}},Bt=B;export{Dt as a,N as b,c,Mt as d,Bt as e};//# sourceMappingURL=chunk-ZKQYV6UB.mjs.map
2
- //# sourceMappingURL=chunk-ZKQYV6UB.mjs.map