b23-lib 2.0.1 → 2.0.3
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.
- package/dist/Auth/index.js +1 -1
- package/dist/Auth/index.js.map +1 -1
- package/dist/Auth/index.mjs +1 -1
- package/dist/Classes/Cart.js +1 -1
- package/dist/Classes/Cart.js.map +1 -1
- package/dist/Classes/Cart.mjs +1 -1
- package/dist/Classes/Coupon.js +1 -1
- package/dist/Classes/Coupon.js.map +1 -1
- package/dist/Classes/Coupon.mjs +1 -1
- package/dist/Classes/Inventory.js +1 -1
- package/dist/Classes/Inventory.js.map +1 -1
- package/dist/Classes/Inventory.mjs +1 -1
- package/dist/Classes/LineItem.js +1 -1
- package/dist/Classes/LineItem.js.map +1 -1
- package/dist/Classes/LineItem.mjs +1 -1
- package/dist/Classes/Order.js +1 -1
- package/dist/Classes/Order.js.map +1 -1
- package/dist/Classes/Order.mjs +1 -1
- package/dist/Classes/Product.d.mts +8 -7
- package/dist/Classes/Product.d.ts +8 -7
- package/dist/Classes/Product.js +1 -1
- package/dist/Classes/Product.js.map +1 -1
- package/dist/Classes/Product.mjs +1 -1
- package/dist/Classes/ShoppingContainer.js +1 -1
- package/dist/Classes/ShoppingContainer.js.map +1 -1
- package/dist/Classes/ShoppingContainer.mjs +1 -1
- package/dist/Classes/TaxRule.js +1 -1
- package/dist/Classes/TaxRule.js.map +1 -1
- package/dist/Classes/TaxRule.mjs +1 -1
- package/dist/{chunk-RBROVHJ4.mjs → chunk-3DSTZDT6.mjs} +2 -2
- package/dist/{chunk-RBROVHJ4.mjs.map → chunk-3DSTZDT6.mjs.map} +1 -1
- package/dist/{chunk-EP7WVZXC.mjs → chunk-B7VG6LHU.mjs} +2 -2
- package/dist/{chunk-EP7WVZXC.mjs.map → chunk-B7VG6LHU.mjs.map} +1 -1
- package/dist/chunk-HUDDEQPH.mjs +2 -0
- package/dist/chunk-HUDDEQPH.mjs.map +1 -0
- package/dist/{chunk-2SGUPNWZ.mjs → chunk-V2IDNBA2.mjs} +2 -2
- package/dist/{chunk-2SGUPNWZ.mjs.map → chunk-V2IDNBA2.mjs.map} +1 -1
- package/dist/{chunk-CEGQFFYZ.mjs → chunk-X7DG44HI.mjs} +2 -2
- package/dist/{chunk-CEGQFFYZ.mjs.map → chunk-X7DG44HI.mjs.map} +1 -1
- package/dist/index.d.mts +38 -1
- package/dist/index.d.ts +38 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-LNIZAPER.mjs +0 -2
- package/dist/chunk-LNIZAPER.mjs.map +0 -1
package/dist/Classes/Order.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {a}from'../chunk-
|
|
1
|
+
import {a}from'../chunk-3DSTZDT6.mjs';import'../chunk-X7DG44HI.mjs';import'../chunk-B7VG6LHU.mjs';import'../chunk-5KD2EW7O.mjs';import'../chunk-V2IDNBA2.mjs';import'../chunk-HUDDEQPH.mjs';import'../chunk-KWH7GE23.mjs';import'../chunk-54RUAXYE.mjs';import'../chunk-72DR3HF2.mjs';import'../chunk-NUTKOIGY.mjs';import {a as a$1}from'../chunk-NJKSUUOB.mjs';import'../chunk-55SOBG62.mjs';var o=(e=>(e.PLACED="PLACED",e.PENDING_PAYMENT="PENDING_PAYMENT",e.PROCESSING="PROCESSING",e.CANCELLED="CANCELLED",e.COMPLETED="COMPLETED",e))(o||{}),r=class extends a{orderNumber;cartId;paymentStatus;holdReason;state;constructor(t,s=new Date){super(t,s),this.orderNumber=t.orderNumber,this.cartId=t.cartId,this.paymentStatus=t.paymentStatus,this.holdReason=t.holdReason||"",this.state=t.state;}getCustomerId(){return this.customerId}getCustomerEmail(){return this.customerEmail}getShippingAddress(){return this.shippingAddress}getBillingAddress(){return this.billingAddress}getOrderNumber(){return this.orderNumber}getCartId(){return this.cartId}getPaymentStatus(){return this.paymentStatus}getHoldReason(){return this.holdReason}getState(){return this.state}getLineItemState(t){let s=this.getLineItems().find(a=>a.getId()===t);if(!s)throw new a$1(t);return s.getState()}getDetails(){return {...super.getDetails(),orderNumber:this.getOrderNumber(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),shippingAddress:this.getShippingAddress().getDetails(),billingAddress:this.getBillingAddress().getDetails(),cartId:this.getCartId(),paymentStatus:this.getPaymentStatus(),holdReason:this.getHoldReason(),state:this.getState()}}};export{o as OrderState,r as default};//# sourceMappingURL=Order.mjs.map
|
|
2
2
|
//# sourceMappingURL=Order.mjs.map
|
|
@@ -16,6 +16,7 @@ type SelectionAttributes = {
|
|
|
16
16
|
[key: string]: string | Color;
|
|
17
17
|
};
|
|
18
18
|
type VariantData = {
|
|
19
|
+
sku: string;
|
|
19
20
|
selectionAttributes: SelectionAttributes;
|
|
20
21
|
images: {
|
|
21
22
|
primary: ImageInfoData;
|
|
@@ -23,6 +24,7 @@ type VariantData = {
|
|
|
23
24
|
};
|
|
24
25
|
};
|
|
25
26
|
type VariantModel = {
|
|
27
|
+
sku: string;
|
|
26
28
|
selectionAttributes: SelectionAttributes;
|
|
27
29
|
images: {
|
|
28
30
|
primary: ImageInfoModel;
|
|
@@ -35,7 +37,6 @@ type ProductSpecification = {
|
|
|
35
37
|
type ProductAttributes = BaseAttributes & {
|
|
36
38
|
id: string;
|
|
37
39
|
key: string;
|
|
38
|
-
sku: string;
|
|
39
40
|
name: LocalizedString;
|
|
40
41
|
description: LocalizedString;
|
|
41
42
|
slug: LocalizedString;
|
|
@@ -55,7 +56,6 @@ type ProductData = Required<ProductAttributes>;
|
|
|
55
56
|
declare class ProductModel extends BaseModel {
|
|
56
57
|
protected id: string;
|
|
57
58
|
protected key: string;
|
|
58
|
-
protected sku: string;
|
|
59
59
|
protected name: LocalizedString;
|
|
60
60
|
protected description: LocalizedString;
|
|
61
61
|
protected slug: LocalizedString;
|
|
@@ -71,6 +71,7 @@ declare class ProductModel extends BaseModel {
|
|
|
71
71
|
protected isActive: boolean;
|
|
72
72
|
protected searchTags: LocalizedValue<string[]>;
|
|
73
73
|
static productKeyRegex: RegExp;
|
|
74
|
+
static productSKURegex: RegExp;
|
|
74
75
|
/**
|
|
75
76
|
* Generates a unique key for checking uniqueness for a given selection attributes.
|
|
76
77
|
* Excludes 'size' from the key generation.
|
|
@@ -101,11 +102,6 @@ declare class ProductModel extends BaseModel {
|
|
|
101
102
|
* @returns Product Key.
|
|
102
103
|
*/
|
|
103
104
|
getKey(): string;
|
|
104
|
-
/**
|
|
105
|
-
* Gets the SKU for the product.
|
|
106
|
-
* @returns SKU string.
|
|
107
|
-
*/
|
|
108
|
-
getSku(): string;
|
|
109
105
|
/**
|
|
110
106
|
* Gets the full localized product name object.
|
|
111
107
|
* @returns A copy of the LocalizedString object for the name.
|
|
@@ -162,6 +158,11 @@ declare class ProductModel extends BaseModel {
|
|
|
162
158
|
* @returns Product Attributes.
|
|
163
159
|
*/
|
|
164
160
|
getAttributes(): ProductSelectionAttributes;
|
|
161
|
+
/**
|
|
162
|
+
* Gets the variant-specific attributes (color, sizes). Returns copies.
|
|
163
|
+
* @returns Product Attributes.
|
|
164
|
+
*/
|
|
165
|
+
getVariants(): VariantModel[];
|
|
165
166
|
/**
|
|
166
167
|
* Gets the images for a specific selection attribute combination.
|
|
167
168
|
* @param selectionAttributes - The selection attributes to search for.
|
|
@@ -16,6 +16,7 @@ type SelectionAttributes = {
|
|
|
16
16
|
[key: string]: string | Color;
|
|
17
17
|
};
|
|
18
18
|
type VariantData = {
|
|
19
|
+
sku: string;
|
|
19
20
|
selectionAttributes: SelectionAttributes;
|
|
20
21
|
images: {
|
|
21
22
|
primary: ImageInfoData;
|
|
@@ -23,6 +24,7 @@ type VariantData = {
|
|
|
23
24
|
};
|
|
24
25
|
};
|
|
25
26
|
type VariantModel = {
|
|
27
|
+
sku: string;
|
|
26
28
|
selectionAttributes: SelectionAttributes;
|
|
27
29
|
images: {
|
|
28
30
|
primary: ImageInfoModel;
|
|
@@ -35,7 +37,6 @@ type ProductSpecification = {
|
|
|
35
37
|
type ProductAttributes = BaseAttributes & {
|
|
36
38
|
id: string;
|
|
37
39
|
key: string;
|
|
38
|
-
sku: string;
|
|
39
40
|
name: LocalizedString;
|
|
40
41
|
description: LocalizedString;
|
|
41
42
|
slug: LocalizedString;
|
|
@@ -55,7 +56,6 @@ type ProductData = Required<ProductAttributes>;
|
|
|
55
56
|
declare class ProductModel extends BaseModel {
|
|
56
57
|
protected id: string;
|
|
57
58
|
protected key: string;
|
|
58
|
-
protected sku: string;
|
|
59
59
|
protected name: LocalizedString;
|
|
60
60
|
protected description: LocalizedString;
|
|
61
61
|
protected slug: LocalizedString;
|
|
@@ -71,6 +71,7 @@ declare class ProductModel extends BaseModel {
|
|
|
71
71
|
protected isActive: boolean;
|
|
72
72
|
protected searchTags: LocalizedValue<string[]>;
|
|
73
73
|
static productKeyRegex: RegExp;
|
|
74
|
+
static productSKURegex: RegExp;
|
|
74
75
|
/**
|
|
75
76
|
* Generates a unique key for checking uniqueness for a given selection attributes.
|
|
76
77
|
* Excludes 'size' from the key generation.
|
|
@@ -101,11 +102,6 @@ declare class ProductModel extends BaseModel {
|
|
|
101
102
|
* @returns Product Key.
|
|
102
103
|
*/
|
|
103
104
|
getKey(): string;
|
|
104
|
-
/**
|
|
105
|
-
* Gets the SKU for the product.
|
|
106
|
-
* @returns SKU string.
|
|
107
|
-
*/
|
|
108
|
-
getSku(): string;
|
|
109
105
|
/**
|
|
110
106
|
* Gets the full localized product name object.
|
|
111
107
|
* @returns A copy of the LocalizedString object for the name.
|
|
@@ -162,6 +158,11 @@ declare class ProductModel extends BaseModel {
|
|
|
162
158
|
* @returns Product Attributes.
|
|
163
159
|
*/
|
|
164
160
|
getAttributes(): ProductSelectionAttributes;
|
|
161
|
+
/**
|
|
162
|
+
* Gets the variant-specific attributes (color, sizes). Returns copies.
|
|
163
|
+
* @returns Product Attributes.
|
|
164
|
+
*/
|
|
165
|
+
getVariants(): VariantModel[];
|
|
165
166
|
/**
|
|
166
167
|
* Gets the images for a specific selection attribute combination.
|
|
167
168
|
* @param selectionAttributes - The selection attributes to search for.
|
package/dist/Classes/Product.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var Y=require('crypto');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Y__default=/*#__PURE__*/_interopDefault(Y);var D=new Uint8Array(256),S=D.length;function U(){return S>D.length-16&&(Y__default.default.randomFillSync(D),S=0),D.slice(S,S+=16)}var $=/^(?:[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 H(t){return typeof t=="string"&&$.test(t)}var k=H;var a=[];for(let t=0;t<256;++t)a.push((t+256).toString(16).slice(1));function T(t,e=0){return a[t[e+0]]+a[t[e+1]]+a[t[e+2]]+a[t[e+3]]+"-"+a[t[e+4]]+a[t[e+5]]+"-"+a[t[e+6]]+a[t[e+7]]+"-"+a[t[e+8]]+a[t[e+9]]+"-"+a[t[e+10]]+a[t[e+11]]+a[t[e+12]]+a[t[e+13]]+a[t[e+14]]+a[t[e+15]]}function q(t){if(!k(t))throw TypeError("Invalid UUID");let e,r=new Uint8Array(16);return r[0]=(e=parseInt(t.slice(0,8),16))>>>24,r[1]=e>>>16&255,r[2]=e>>>8&255,r[3]=e&255,r[4]=(e=parseInt(t.slice(9,13),16))>>>8,r[5]=e&255,r[6]=(e=parseInt(t.slice(14,18),16))>>>8,r[7]=e&255,r[8]=(e=parseInt(t.slice(19,23),16))>>>8,r[9]=e&255,r[10]=(e=parseInt(t.slice(24,36),16))/1099511627776&255,r[11]=e/4294967296&255,r[12]=e>>>24&255,r[13]=e>>>16&255,r[14]=e>>>8&255,r[15]=e&255,r}var Q=q;function Z(t){t=unescape(encodeURIComponent(t));let e=[];for(let r=0;r<t.length;++r)e.push(t.charCodeAt(r));return e}var j="6ba7b810-9dad-11d1-80b4-00c04fd430c8",X="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function O(t,e,r){function i(n,o,d,p){var c;if(typeof n=="string"&&(n=Z(n)),typeof o=="string"&&(o=Q(o)),((c=o)===null||c===void 0?void 0:c.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let u=new Uint8Array(16+n.length);if(u.set(o),u.set(n,o.length),u=r(u),u[6]=u[6]&15|e,u[8]=u[8]&63|128,d){p=p||0;for(let P=0;P<16;++P)d[p+P]=u[P];return d}return T(u)}try{i.name=t;}catch{}return i.DNS=j,i.URL=X,i}var F={randomUUID:Y__default.default.randomUUID};function J(t,e,r){if(F.randomUUID&&!e&&!t)return F.randomUUID();t=t||{};let i=t.random||(t.rng||U)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,e){r=r||0;for(let n=0;n<16;++n)e[r+n]=i[n];return e}return T(i)}var z=J;function ee(t){return Array.isArray(t)?t=Buffer.from(t):typeof t=="string"&&(t=Buffer.from(t,"utf8")),Y__default.default.createHash("sha1").update(t).digest()}var G=ee;var te=O("v5",80,G),B=te;var re={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?B(t,e):z(),generateSearchId:(t,e)=>`${t}#${A.generateSelectionAttributesKey(e)}`,getKeyfromSearchId:t=>{let[e,r]=t.split("#");return {key:e,selectionAttribute:r}},deepClone(t){return structuredClone(t)}},l=re;var I=class{customFields;version;createdAt;modifiedAt;modifiedBy;constructor(e,r=new Date){this.customFields={...e.customFields},this.version=e.version??1,this.createdAt=e.createdAt&&!isNaN(Date.parse(e.createdAt))?new Date(e.createdAt).toISOString():r.toISOString(),this.modifiedAt=e.modifiedAt&&!isNaN(Date.parse(e.modifiedAt))?new Date(e.modifiedAt).toISOString():r.toISOString(),this.modifiedBy={...e.modifiedBy};}getDetails(){return {customFields:this.getAllCustomFields(),version:this.getVersion(),createdAt:this.getCreatedAt(),modifiedAt:this.getModifiedAt(),modifiedBy:this.getModifiedBy()}}getVersion(){return this.version}getCreatedAt(){return this.createdAt}getCreatedAtTime(){return new Date(this.createdAt).getTime()}getModifiedAt(){return this.modifiedAt}getModifiedAtTime(){return new Date(this.modifiedAt).getTime()}getModifiedBy(){return {...this.modifiedBy}}setModifiedBy(e,r,i,n){this.modifiedBy={id:e,authType:r,requestId:i,lambdaName:n};}getCustomField(e){return this.customFields[e]??null}setCustomField(e,r){this.customFields[e]=r;}getAllCustomFields(){return {...this.customFields}}};var h={"en-IN":"en","kn-IN":"kn"};var V={INR:"\u20B9"},K={INR:"en-IN"};var w=class extends Error{constructor(e="Failed to parse selection attributes key."){super(`SelectionAttributeParseError: ${e}`),this.name="SelectionAttributeParseError";}};var M=class extends Error{constructor(e="Tax category is not valid."){super(`InvalidTaxCategory: ${e}`),this.name="InvalidTaxCategoryError";}},E=class extends Error{constructor(e="Minimum quantity must be greater than zero."){super(`InvalidMinQuantity: ${e}`),this.name="InvalidMinQuantityError";}},v=class extends Error{constructor(e){super(`InvalidTieredPrice: ${e}`),this.name="InvalidTieredPriceError";}},L=class extends Error{constructor(e="Quantity must be greater than zero."){super(`InvalidQuantity: ${e}`),this.name="InvalidQuantityError";}},N=class extends Error{constructor(e){super(`NoApplicableTier: Quantity ${e} does not meet the minimum purchase requirement.`),this.name="NoApplicableTierError";}};var C=class extends Error{constructor(e="Amount cannot be negative."){super(`InvalidAmount: ${e}`),this.name="InvalidPriceAmountError";}},f=class extends Error{constructor(e="Currency code is required."){super(`InvalidCurrency: ${e}`),this.name="InvalidCurrencyCodeError";}},m=class extends Error{constructor(e="Cannot perform operation on prices with different currencies."){super(`CurrencyMismatch: ${e}`),this.name="CurrencyMismatchError";}},g=class extends Error{constructor(e){super(`InvalidArgument: ${e}`),this.name="InvalidArgumentError";}},x=class extends Error{constructor(e="Invalid image source configuration."){super(`InvalidImageSource: ${e}`),this.name="InvalidImageSourceError";}};var y=class{sources;alt;order;label;constructor(e){if(this.sources={...e.sources},this.alt=e.alt,this.order=e.order,this.label=e.label,!this.sources.original)throw new x("ImageInfoModel cannot be created without an 'original' source URL.")}getSources(){return {...this.sources}}getSource(e){return this.sources[e]||this.sources.original}getAlt(){return this.alt}getOrder(){return this.order}getLabel(){return this.label}setAlt(e){this.alt=e;}setOrder(e){this.order=e;}setLabel(e){this.label=e;}setSource(e,r){if(r===void 0){if(e==="original")throw new x("Cannot remove the 'original' image source.");delete this.sources[e];}else this.sources[e]=r;}getDetails(){return {sources:this.getSources(),alt:this.getAlt(),order:this.getOrder(),label:this.getLabel()}}};var b=class t{amount;currency;constructor(e){if(e.amount<0)throw new C("Amount cannot be negative.");if(!e.currency)throw new f("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 m("Cannot compare prices in different currencies.")}else throw new g("Must be a PriceModel instance.");return this.amount-e.getAmount()}add(e){if(e instanceof t){if(this.currency!==e.getCurrency())throw new m("Cannot add prices in different currencies.")}else throw new g("Must be a PriceModel instance.");return new t({amount:this.amount+e.getAmount(),currency:this.currency})}subtract(e){if(e instanceof t){if(this.currency!==e.getCurrency())throw new m("Cannot subtract prices in different currencies.")}else throw new g("Must be a PriceModel instance.");return new t({amount:this.amount-e.getAmount(),currency:this.currency})}multiply(e){if(e instanceof t){if(this.currency!==e.getCurrency())throw new m("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 g("Must be a non-negative number.")}divide(e){if(e instanceof t){if(this.currency!==e.getCurrency())throw new m("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 g("Must be a positive number.")}min(...e){if(e.length===0)throw new g("Must provide at least one PriceModel.");return e.reduce((r,i)=>{if(i instanceof t){if(r.getCurrency()!==i.getCurrency())throw new m("Cannot compare prices in different currencies.")}else throw new g("Must be a PriceModel instance.");return r.compareTo(i)<0?r:i})}max(...e){if(e.length===0)throw new g("Must provide at least one PriceModel.");return e.reduce((r,i)=>{if(i instanceof t){if(r.getCurrency()!==i.getCurrency())throw new m("Cannot compare prices in different currencies.")}else throw new g("Must be a PriceModel instance.");return r.compareTo(i)>0?r:i})}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)}static getFormattedString(e,r,i={displayAsInteger:!1,style:"currency",currencyDisplay:"symbol"}){let n=K[r];if(!r||!n)throw new f("Invalid currency code for formatting.");let o=e,d=i.displayAsInteger?0:t.getDecimalPlaces(r),p={style:i.style??"currency",currency:r,signDisplay:"never",currencyDisplay:i.currencyDisplay,minimumFractionDigits:d,maximumFractionDigits:d};i.displayAsInteger&&(o=Math.ceil(o));try{return new Intl.NumberFormat(n,p).format(o)}catch(c){return console.error(`Error formatting price for currency "${r}" and locale "${n}":`,c),`${V[r]??r} ${t.addThousandSeparators(o.toFixed(d))}`}}static getDecimalPlaces(e){switch(e){case"INR":default:return 2}}static addThousandSeparators(e){let r=e.split("."),i=r[0],n=r.length>1?"."+r[1]:"";return i.replace(/\B(?=(\d{3})+(?!\d))/g,",")+n}static getRoundedAmount(e,r){if(e<0)throw new C("Amount cannot be negative for rounding.");if(r===void 0)throw new f("Invalid currency code for rounding.");let i=t.getDecimalPlaces(r),n=Math.pow(10,i);return Math.round(e*n)/n}};var R=class{baseUnitPrice;taxCategory;tiers;constructor(e){let r=new b(e.baseUnitPrice);if(!e.taxCategory)throw new M;let i=(e.tiers??[]).map(c=>({minQuantity:c.minQuantity,unitPrice:new b(c.unitPrice)})).sort((c,u)=>c.minQuantity-u.minQuantity);if(i.some(c=>c.minQuantity<=0))throw new E;let o=i.some(c=>c.unitPrice.getCurrency()!==r.getCurrency()),d=i.some((c,u)=>u>0&&c.unitPrice.compareTo(i[u-1].unitPrice)>0),p=i[0]?.unitPrice.compareTo(r)>0;if(o||d||p)throw new v("Tiers must share the same currency and must not increase in unit price.");this.baseUnitPrice=r,this.taxCategory=e.taxCategory,this.tiers=i;}getBaseUnitPrice(){return this.baseUnitPrice}getTaxCategory(){return this.taxCategory}getTiers(){return this.tiers}getDetails(){return {baseUnitPrice:this.baseUnitPrice.getDetails(),taxCategory:this.taxCategory,tiers:this.tiers.map(e=>({minQuantity:e.minQuantity,unitPrice:e.unitPrice.getDetails()}))}}getApplicableTier(e){if(e<=0)throw new L;for(let r=this.tiers.length-1;r>=0;r--)if(e>=this.tiers[r].minQuantity)return this.tiers[r];throw new N(e)}getMinQuantity(){return this.tiers[0]?.minQuantity??1}getMaxDiscountPercent(){if(!this.tiers.length)return 0;let e=this.tiers[this.tiers.length-1].unitPrice.getAmount(),r=this.baseUnitPrice.getAmount();return (r-e)/r*100}};var A=class t extends I{id;key;sku;name;description;slug;brand;pricing;variants;targetGender;attributes;specifications;categories;isActive;searchTags;static productKeyRegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static generateSelectionAttributesKey(e){return Object.keys(e).filter(i=>e[i]!==void 0&&i.toLowerCase()!=="size").sort().map(i=>e[i].name?`${i}:c+${e[i].name}`:`${i}:${e[i]}`).join("|")}static parseSelectionAttributesKey(e){try{let r={},i=e.split("|");for(let n of i){let[o,d]=n.split(":");d.startsWith("c+")?r[o]={name:d.slice(2)}:r[o]=d;}return r}catch(r){throw new w(r?.message)}}constructor(e,r=new Date){super(e,r),this.id=e.id,this.key=e.key,this.sku=e.sku,this.name={...e.name},this.description={...e.description},this.slug={...e.slug},this.brand=e.brand,this.pricing=Object.keys(e.pricing).reduce((i,n)=>(e.pricing[n]&&(i[n]=new R(e.pricing[n])),i),{}),this.targetGender=e.targetGender,this.attributes=l.deepClone(e.attributes),this.specifications=l.deepClone(e.specifications),this.categories=l.deepClone(e.categories),this.variants=(e.variants||[]).map(i=>({selectionAttributes:i.selectionAttributes,images:{primary:new y(i.images.primary),gallery:(i.images.gallery||[]).map(n=>new y(n))}})),this.isActive=e.isActive,this.searchTags=e.searchTags?l.deepClone(e.searchTags):{en:[]};}getId(){return this.id}getKey(){return this.key}getSku(){return this.sku}getName(e){return e?this.name[e]??this.name[h[e]]??this.name.en:l.deepClone(this.name)}getDescription(e){return e?this.description[e]??this.description[h[e]]??this.description.en:l.deepClone(this.description)}getSlug(e){return e?this.slug[e]??this.slug[h[e]]??this.slug.en:l.deepClone(this.slug)}getBrand(){return this.brand}getPriceDetails(e){return e?this.pricing[e]??null:this.pricing}getAttributes(){return l.deepClone(this.attributes)}getImagesBySelectionAttributes(e){let r=t.generateSelectionAttributesKey(e),i=this.variants.find(n=>t.generateSelectionAttributesKey(n.selectionAttributes)===r);return i?i.images:null}getImages(e,r){switch(r){case"PRIMARY":return this.getImagesBySelectionAttributes(e)?.primary??this.variants[0]?.images?.primary;case"GALLERY":return this.getImagesBySelectionAttributes(e)?.gallery??[];default:return this.getImagesBySelectionAttributes(e)??{primary:this.variants[0]?.images?.primary,gallery:[]}}}getIsActive(){return this.isActive}getTargetGender(){return this.targetGender}getCategories(){return l.deepClone(this.categories)}getSpecifications(e){return e?l.deepClone(this.specifications[e]??this.specifications[h[e]]??this.specifications.en):l.deepClone(this.specifications)}getSearchTags(e){return e?l.deepClone(this.searchTags[e]??this.searchTags[h[e]]??this.searchTags.en):l.deepClone(this.searchTags)}getDetails(){let e=super.getDetails();return {id:this.getId(),key:this.getKey(),sku:this.getSku(),name:this.getName(),description:this.getDescription(),slug:this.getSlug(),brand:this.getBrand(),pricing:Object.keys(this.pricing).reduce((r,i)=>(this.pricing[i]&&(r[i]=this.pricing[i]?.getDetails()),r),{}),attributes:this.getAttributes(),variants:this.variants.map(r=>({selectionAttributes:l.deepClone(r.selectionAttributes),images:{primary:r.images.primary.getDetails(),gallery:r.images.gallery.map(i=>i.getDetails())}})),isActive:this.getIsActive(),targetGender:this.getTargetGender(),categories:this.getCategories(),specifications:this.getSpecifications(),searchTags:this.getSearchTags(),...e}}validateSelectionAttribute(e){let r=t.generateSelectionAttributesKey(e);return this.variants.some(i=>t.generateSelectionAttributesKey(i.selectionAttributes)===r)}validateSize(e){return this.attributes.size.includes(e)}};module.exports=A;//# sourceMappingURL=Product.js.map
|
|
1
|
+
'use strict';var Y=require('crypto');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Y__default=/*#__PURE__*/_interopDefault(Y);var D=new Uint8Array(256),S=D.length;function U(){return S>D.length-16&&(Y__default.default.randomFillSync(D),S=0),D.slice(S,S+=16)}var B=/^(?:[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 H(t){return typeof t=="string"&&B.test(t)}var k=H;var a=[];for(let t=0;t<256;++t)a.push((t+256).toString(16).slice(1));function T(t,e=0){return a[t[e+0]]+a[t[e+1]]+a[t[e+2]]+a[t[e+3]]+"-"+a[t[e+4]]+a[t[e+5]]+"-"+a[t[e+6]]+a[t[e+7]]+"-"+a[t[e+8]]+a[t[e+9]]+"-"+a[t[e+10]]+a[t[e+11]]+a[t[e+12]]+a[t[e+13]]+a[t[e+14]]+a[t[e+15]]}function Z(t){if(!k(t))throw TypeError("Invalid UUID");let e,r=new Uint8Array(16);return r[0]=(e=parseInt(t.slice(0,8),16))>>>24,r[1]=e>>>16&255,r[2]=e>>>8&255,r[3]=e&255,r[4]=(e=parseInt(t.slice(9,13),16))>>>8,r[5]=e&255,r[6]=(e=parseInt(t.slice(14,18),16))>>>8,r[7]=e&255,r[8]=(e=parseInt(t.slice(19,23),16))>>>8,r[9]=e&255,r[10]=(e=parseInt(t.slice(24,36),16))/1099511627776&255,r[11]=e/4294967296&255,r[12]=e>>>24&255,r[13]=e>>>16&255,r[14]=e>>>8&255,r[15]=e&255,r}var Q=Z;function q(t){t=unescape(encodeURIComponent(t));let e=[];for(let r=0;r<t.length;++r)e.push(t.charCodeAt(r));return e}var j="6ba7b810-9dad-11d1-80b4-00c04fd430c8",X="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function O(t,e,r){function i(n,o,d,p){var c;if(typeof n=="string"&&(n=q(n)),typeof o=="string"&&(o=Q(o)),((c=o)===null||c===void 0?void 0:c.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let u=new Uint8Array(16+n.length);if(u.set(o),u.set(n,o.length),u=r(u),u[6]=u[6]&15|e,u[8]=u[8]&63|128,d){p=p||0;for(let P=0;P<16;++P)d[p+P]=u[P];return d}return T(u)}try{i.name=t;}catch{}return i.DNS=j,i.URL=X,i}var $={randomUUID:Y__default.default.randomUUID};function J(t,e,r){if($.randomUUID&&!e&&!t)return $.randomUUID();t=t||{};let i=t.random||(t.rng||U)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,e){r=r||0;for(let n=0;n<16;++n)e[r+n]=i[n];return e}return T(i)}var F=J;function ee(t){return Array.isArray(t)?t=Buffer.from(t):typeof t=="string"&&(t=Buffer.from(t,"utf8")),Y__default.default.createHash("sha1").update(t).digest()}var V=ee;var te=O("v5",80,V),z=te;var re={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?z(t,e):F(),generateSearchId:(t,e)=>`${t}#${A.generateSelectionAttributesKey(e)}`,getKeyfromSearchId:t=>{let[e,r]=t.split("#");return {key:e,selectionAttribute:r}},deepClone(t){return structuredClone(t)}},l=re;var I=class{customFields;version;createdAt;modifiedAt;modifiedBy;constructor(e,r=new Date){this.customFields={...e.customFields},this.version=e.version??1,this.createdAt=e.createdAt&&!isNaN(Date.parse(e.createdAt))?new Date(e.createdAt).toISOString():r.toISOString(),this.modifiedAt=e.modifiedAt&&!isNaN(Date.parse(e.modifiedAt))?new Date(e.modifiedAt).toISOString():r.toISOString(),this.modifiedBy={...e.modifiedBy};}getDetails(){return {customFields:this.getAllCustomFields(),version:this.getVersion(),createdAt:this.getCreatedAt(),modifiedAt:this.getModifiedAt(),modifiedBy:this.getModifiedBy()}}getVersion(){return this.version}getCreatedAt(){return this.createdAt}getCreatedAtTime(){return new Date(this.createdAt).getTime()}getModifiedAt(){return this.modifiedAt}getModifiedAtTime(){return new Date(this.modifiedAt).getTime()}getModifiedBy(){return {...this.modifiedBy}}setModifiedBy(e,r,i,n){this.modifiedBy={id:e,authType:r,requestId:i,lambdaName:n};}getCustomField(e){return this.customFields[e]??null}setCustomField(e,r){this.customFields[e]=r;}getAllCustomFields(){return {...this.customFields}}};var h={"en-IN":"en","kn-IN":"kn"};var G={INR:"\u20B9"},K={INR:"en-IN"};var w=class extends Error{constructor(e="Failed to parse selection attributes key."){super(`SelectionAttributeParseError: ${e}`),this.name="SelectionAttributeParseError";}};var M=class extends Error{constructor(e="Tax category is not valid."){super(`InvalidTaxCategory: ${e}`),this.name="InvalidTaxCategoryError";}},E=class extends Error{constructor(e="Minimum quantity must be greater than zero."){super(`InvalidMinQuantity: ${e}`),this.name="InvalidMinQuantityError";}},v=class extends Error{constructor(e){super(`InvalidTieredPrice: ${e}`),this.name="InvalidTieredPriceError";}},L=class extends Error{constructor(e="Quantity must be greater than zero."){super(`InvalidQuantity: ${e}`),this.name="InvalidQuantityError";}},R=class extends Error{constructor(e){super(`NoApplicableTier: Quantity ${e} does not meet the minimum purchase requirement.`),this.name="NoApplicableTierError";}};var C=class extends Error{constructor(e="Amount cannot be negative."){super(`InvalidAmount: ${e}`),this.name="InvalidPriceAmountError";}},f=class extends Error{constructor(e="Currency code is required."){super(`InvalidCurrency: ${e}`),this.name="InvalidCurrencyCodeError";}},m=class extends Error{constructor(e="Cannot perform operation on prices with different currencies."){super(`CurrencyMismatch: ${e}`),this.name="CurrencyMismatchError";}},g=class extends Error{constructor(e){super(`InvalidArgument: ${e}`),this.name="InvalidArgumentError";}},x=class extends Error{constructor(e="Invalid image source configuration."){super(`InvalidImageSource: ${e}`),this.name="InvalidImageSourceError";}};var y=class{sources;alt;order;label;constructor(e){if(this.sources={...e.sources},this.alt=e.alt,this.order=e.order,this.label=e.label,!this.sources.original)throw new x("ImageInfoModel cannot be created without an 'original' source URL.")}getSources(){return {...this.sources}}getSource(e){return this.sources[e]||this.sources.original}getAlt(){return this.alt}getOrder(){return this.order}getLabel(){return this.label}setAlt(e){this.alt=e;}setOrder(e){this.order=e;}setLabel(e){this.label=e;}setSource(e,r){if(r===void 0){if(e==="original")throw new x("Cannot remove the 'original' image source.");delete this.sources[e];}else this.sources[e]=r;}getDetails(){return {sources:this.getSources(),alt:this.getAlt(),order:this.getOrder(),label:this.getLabel()}}};var b=class t{amount;currency;constructor(e){if(e.amount<0)throw new C("Amount cannot be negative.");if(!e.currency)throw new f("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 m("Cannot compare prices in different currencies.")}else throw new g("Must be a PriceModel instance.");return this.amount-e.getAmount()}add(e){if(e instanceof t){if(this.currency!==e.getCurrency())throw new m("Cannot add prices in different currencies.")}else throw new g("Must be a PriceModel instance.");return new t({amount:this.amount+e.getAmount(),currency:this.currency})}subtract(e){if(e instanceof t){if(this.currency!==e.getCurrency())throw new m("Cannot subtract prices in different currencies.")}else throw new g("Must be a PriceModel instance.");return new t({amount:this.amount-e.getAmount(),currency:this.currency})}multiply(e){if(e instanceof t){if(this.currency!==e.getCurrency())throw new m("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 g("Must be a non-negative number.")}divide(e){if(e instanceof t){if(this.currency!==e.getCurrency())throw new m("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 g("Must be a positive number.")}min(...e){if(e.length===0)throw new g("Must provide at least one PriceModel.");return e.reduce((r,i)=>{if(i instanceof t){if(r.getCurrency()!==i.getCurrency())throw new m("Cannot compare prices in different currencies.")}else throw new g("Must be a PriceModel instance.");return r.compareTo(i)<0?r:i})}max(...e){if(e.length===0)throw new g("Must provide at least one PriceModel.");return e.reduce((r,i)=>{if(i instanceof t){if(r.getCurrency()!==i.getCurrency())throw new m("Cannot compare prices in different currencies.")}else throw new g("Must be a PriceModel instance.");return r.compareTo(i)>0?r:i})}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)}static getFormattedString(e,r,i={displayAsInteger:!1,style:"currency",currencyDisplay:"symbol"}){let n=K[r];if(!r||!n)throw new f("Invalid currency code for formatting.");let o=e,d=i.displayAsInteger?0:t.getDecimalPlaces(r),p={style:i.style??"currency",currency:r,signDisplay:"never",currencyDisplay:i.currencyDisplay,minimumFractionDigits:d,maximumFractionDigits:d};i.displayAsInteger&&(o=Math.ceil(o));try{return new Intl.NumberFormat(n,p).format(o)}catch(c){return console.error(`Error formatting price for currency "${r}" and locale "${n}":`,c),`${G[r]??r} ${t.addThousandSeparators(o.toFixed(d))}`}}static getDecimalPlaces(e){switch(e){case"INR":default:return 2}}static addThousandSeparators(e){let r=e.split("."),i=r[0],n=r.length>1?"."+r[1]:"";return i.replace(/\B(?=(\d{3})+(?!\d))/g,",")+n}static getRoundedAmount(e,r){if(e<0)throw new C("Amount cannot be negative for rounding.");if(r===void 0)throw new f("Invalid currency code for rounding.");let i=t.getDecimalPlaces(r),n=Math.pow(10,i);return Math.round(e*n)/n}};var N=class{baseUnitPrice;taxCategory;tiers;constructor(e){let r=new b(e.baseUnitPrice);if(!e.taxCategory)throw new M;let i=(e.tiers??[]).map(c=>({minQuantity:c.minQuantity,unitPrice:new b(c.unitPrice)})).sort((c,u)=>c.minQuantity-u.minQuantity);if(i.some(c=>c.minQuantity<=0))throw new E;let o=i.some(c=>c.unitPrice.getCurrency()!==r.getCurrency()),d=i.some((c,u)=>u>0&&c.unitPrice.compareTo(i[u-1].unitPrice)>0),p=i[0]?.unitPrice.compareTo(r)>0;if(o||d||p)throw new v("Tiers must share the same currency and must not increase in unit price.");this.baseUnitPrice=r,this.taxCategory=e.taxCategory,this.tiers=i;}getBaseUnitPrice(){return this.baseUnitPrice}getTaxCategory(){return this.taxCategory}getTiers(){return this.tiers}getDetails(){return {baseUnitPrice:this.baseUnitPrice.getDetails(),taxCategory:this.taxCategory,tiers:this.tiers.map(e=>({minQuantity:e.minQuantity,unitPrice:e.unitPrice.getDetails()}))}}getApplicableTier(e){if(e<=0)throw new L;for(let r=this.tiers.length-1;r>=0;r--)if(e>=this.tiers[r].minQuantity)return this.tiers[r];throw new R(e)}getMinQuantity(){return this.tiers[0]?.minQuantity??1}getMaxDiscountPercent(){if(!this.tiers.length)return 0;let e=this.tiers[this.tiers.length-1].unitPrice.getAmount(),r=this.baseUnitPrice.getAmount();return (r-e)/r*100}};var A=class t extends I{id;key;name;description;slug;brand;pricing;variants;targetGender;attributes;specifications;categories;isActive;searchTags;static productKeyRegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static productSKURegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static generateSelectionAttributesKey(e){return Object.keys(e).filter(i=>e[i]!==void 0&&i.toLowerCase()!=="size").sort().map(i=>e[i].name?`${i}:c+${e[i].name}`:`${i}:${e[i]}`).join("|")}static parseSelectionAttributesKey(e){try{let r={},i=e.split("|");for(let n of i){let[o,d]=n.split(":");d.startsWith("c+")?r[o]={name:d.slice(2)}:r[o]=d;}return r}catch(r){throw new w(r?.message)}}constructor(e,r=new Date){super(e,r),this.id=e.id,this.key=e.key,this.name={...e.name},this.description={...e.description},this.slug={...e.slug},this.brand=e.brand,this.pricing=Object.keys(e.pricing).reduce((i,n)=>(e.pricing[n]&&(i[n]=new N(e.pricing[n])),i),{}),this.targetGender=e.targetGender,this.attributes=l.deepClone(e.attributes),this.specifications=l.deepClone(e.specifications),this.categories=l.deepClone(e.categories),this.variants=(e.variants||[]).map(i=>({sku:i.sku,selectionAttributes:i.selectionAttributes,images:{primary:new y(i.images.primary),gallery:(i.images.gallery||[]).map(n=>new y(n))}})),this.isActive=e.isActive,this.searchTags=e.searchTags?l.deepClone(e.searchTags):{en:[]};}getId(){return this.id}getKey(){return this.key}getName(e){return e?this.name[e]??this.name[h[e]]??this.name.en:l.deepClone(this.name)}getDescription(e){return e?this.description[e]??this.description[h[e]]??this.description.en:l.deepClone(this.description)}getSlug(e){return e?this.slug[e]??this.slug[h[e]]??this.slug.en:l.deepClone(this.slug)}getBrand(){return this.brand}getPriceDetails(e){return e?this.pricing[e]??null:this.pricing}getAttributes(){return l.deepClone(this.attributes)}getVariants(){return this.variants.map(e=>({sku:e.sku,selectionAttributes:e.selectionAttributes,images:{primary:e.images.primary,gallery:e.images.gallery}}))}getImagesBySelectionAttributes(e){let r=t.generateSelectionAttributesKey(e),i=this.variants.find(n=>t.generateSelectionAttributesKey(n.selectionAttributes)===r);return i?i.images:null}getImages(e,r){switch(r){case"PRIMARY":return this.getImagesBySelectionAttributes(e)?.primary??this.variants[0]?.images?.primary;case"GALLERY":return this.getImagesBySelectionAttributes(e)?.gallery??[];default:return this.getImagesBySelectionAttributes(e)??{primary:this.variants[0]?.images?.primary,gallery:[]}}}getIsActive(){return this.isActive}getTargetGender(){return this.targetGender}getCategories(){return l.deepClone(this.categories)}getSpecifications(e){return e?l.deepClone(this.specifications[e]??this.specifications[h[e]]??this.specifications.en):l.deepClone(this.specifications)}getSearchTags(e){return e?l.deepClone(this.searchTags[e]??this.searchTags[h[e]]??this.searchTags.en):l.deepClone(this.searchTags)}getDetails(){let e=super.getDetails();return {id:this.getId(),key:this.getKey(),name:this.getName(),description:this.getDescription(),slug:this.getSlug(),brand:this.getBrand(),pricing:Object.keys(this.pricing).reduce((r,i)=>(this.pricing[i]&&(r[i]=this.pricing[i]?.getDetails()),r),{}),attributes:this.getAttributes(),variants:this.variants.map(r=>({sku:r.sku,selectionAttributes:l.deepClone(r.selectionAttributes),images:{primary:r.images.primary.getDetails(),gallery:r.images.gallery.map(i=>i.getDetails())}})),isActive:this.getIsActive(),targetGender:this.getTargetGender(),categories:this.getCategories(),specifications:this.getSpecifications(),searchTags:this.getSearchTags(),...e}}validateSelectionAttribute(e){let r=t.generateSelectionAttributesKey(e);return this.variants.some(i=>t.generateSelectionAttributesKey(i.selectionAttributes)===r)}validateSize(e){return this.attributes.size.includes(e)}};module.exports=A;//# sourceMappingURL=Product.js.map
|
|
2
2
|
//# sourceMappingURL=Product.js.map
|