b23-lib 1.9.5 → 1.11.0
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/Classes/Cart.d.mts +5 -0
- package/dist/Classes/Cart.d.ts +5 -0
- 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/Order.d.mts +33 -5
- package/dist/Classes/Order.d.ts +33 -5
- 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/Order.mjs.map +1 -1
- package/dist/Classes/ShoppingContainer.d.mts +4 -12
- package/dist/Classes/ShoppingContainer.d.ts +4 -12
- package/dist/Classes/ShoppingContainer.js +1 -1
- package/dist/Classes/ShoppingContainer.js.map +1 -1
- package/dist/Classes/ShoppingContainer.mjs +1 -1
- package/dist/chunk-4LCZLYP7.mjs +2 -0
- package/dist/chunk-4LCZLYP7.mjs.map +1 -0
- package/dist/chunk-QKV5D6JZ.mjs +2 -0
- package/dist/chunk-QKV5D6JZ.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-AAJXUZCX.mjs +0 -2
- package/dist/chunk-AAJXUZCX.mjs.map +0 -1
- package/dist/chunk-FA6HHGIB.mjs +0 -2
- package/dist/chunk-FA6HHGIB.mjs.map +0 -1
package/dist/Classes/Order.d.ts
CHANGED
|
@@ -10,23 +10,45 @@ import './ImageInfo.js';
|
|
|
10
10
|
import './Product.js';
|
|
11
11
|
import './Coupon.js';
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* PLACED: Order created, awaiting payment.
|
|
15
|
+
* PENDING_PAYMENT: Waiting for payment confirmation.
|
|
16
|
+
* PROCESSING: Payment received, order is being fulfilled. Stays here until all line items reach a final state.
|
|
17
|
+
* CANCELLED: All line items are cancelled, or order is cancelled before fulfillment.
|
|
18
|
+
* COMPLETED: All line items are delivered, returned, or refunded.
|
|
19
|
+
*/
|
|
13
20
|
declare enum OrderState {
|
|
14
21
|
PLACED = "PLACED",
|
|
15
22
|
PENDING_PAYMENT = "PENDING_PAYMENT",
|
|
16
23
|
PROCESSING = "PROCESSING",
|
|
17
|
-
SHIPPED = "SHIPPED",
|
|
18
|
-
DELIVERED = "DELIVERED",
|
|
19
24
|
CANCELLED = "CANCELLED",
|
|
20
|
-
RETURNED = "RETURNED",
|
|
21
|
-
REFUNDED = "REFUNDED",
|
|
22
25
|
COMPLETED = "COMPLETED"
|
|
23
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* OrderLineItemState
|
|
29
|
+
*
|
|
30
|
+
* INITIAL: Item added to order, not yet processed.
|
|
31
|
+
* PROCESSING: Item is being prepared for shipment.
|
|
32
|
+
* SHIPPED: Item dispatched to customer.
|
|
33
|
+
* DELIVERED: Item delivered to customer.
|
|
34
|
+
* CANCELLED: Item cancelled before shipment or delivery.
|
|
35
|
+
* RETURN_REQUESTED: Customer requests to return item.
|
|
36
|
+
* RETURNED: Item received back from customer.
|
|
37
|
+
* REFUND_REQUESTED: Refund initiated for item.
|
|
38
|
+
* REFUNDED: Refund processed for item.
|
|
39
|
+
* ON_HOLD: Item is paused due to payment, inventory, or other issues.
|
|
40
|
+
*/
|
|
24
41
|
declare enum OrderLineItemState {
|
|
25
42
|
INITIAL = "INITIAL",
|
|
26
43
|
PROCESSING = "PROCESSING",
|
|
27
44
|
SHIPPED = "SHIPPED",
|
|
28
45
|
DELIVERED = "DELIVERED",
|
|
29
|
-
CANCELLED = "CANCELLED"
|
|
46
|
+
CANCELLED = "CANCELLED",
|
|
47
|
+
RETURN_REQUESTED = "RETURN_REQUESTED",
|
|
48
|
+
RETURNED = "RETURNED",
|
|
49
|
+
REFUND_REQUESTED = "REFUND_REQUESTED",
|
|
50
|
+
REFUNDED = "REFUNDED",
|
|
51
|
+
ON_HOLD = "ON_HOLD"
|
|
30
52
|
}
|
|
31
53
|
type OrderLineItemStateMap = Record<string, {
|
|
32
54
|
state: OrderLineItemState;
|
|
@@ -72,6 +94,12 @@ declare class OrderModel extends BaseShoppingContainerModel {
|
|
|
72
94
|
* @param config - Optional cart configuration (might be less relevant for orders).
|
|
73
95
|
*/
|
|
74
96
|
constructor(data: OrderAttributes, date?: Date);
|
|
97
|
+
/**
|
|
98
|
+
* Recalculates the subtotal and mrpTotal based on the current line items.
|
|
99
|
+
* Uses PriceModel for rounding based on the country.
|
|
100
|
+
*/
|
|
101
|
+
protected recalculateOrderBaseTotals(): void;
|
|
102
|
+
updateOrderTotals(): void;
|
|
75
103
|
/**
|
|
76
104
|
* Gets the customer ID associated with this order.
|
|
77
105
|
* Overrides the base method to guarantee a non-undefined return type for orders.
|
package/dist/Classes/Order.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var l=class{customFields;version;createdAt;modifiedAt;modifiedBy;constructor(t,e=new Date){this.customFields={...t.customFields},this.version=t.version??1,this.createdAt=t.createdAt&&!isNaN(Date.parse(t.createdAt))?new Date(t.createdAt).toISOString():e.toISOString(),this.modifiedAt=t.modifiedAt&&!isNaN(Date.parse(t.modifiedAt))?new Date(t.modifiedAt).toISOString():e.toISOString(),this.modifiedBy={...t.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(t,e,i,r){this.modifiedBy={id:t,authType:e,requestId:i,lambdaName:r};}getCustomField(t){return this.customFields[t]??null}setCustomField(t,e){this.customFields[t]=e;}getAllCustomFields(){return {...this.customFields}}};var p=class extends l{id;firstName;lastName;phone;email;addressLine1;addressLine2;city;postalCode;state;country;isBillingAddress;isShippingAddress;constructor(t,e=new Date){super(t,e),this.id=t.id,this.firstName=t.firstName,this.lastName=t.lastName||"",this.phone=t.phone,this.email=t.email,this.addressLine1=t.addressLine1,this.addressLine2=t.addressLine2||"",this.city=t.city,this.postalCode=t.postalCode,this.state=t.state,this.country=t.country,this.isBillingAddress=t.isBillingAddress,this.isShippingAddress=t.isShippingAddress;}getDetails(){return {...super.getDetails(),id:this.getId(),firstName:this.getFirstName(),lastName:this.getLastName(),phone:this.getPhone(),email:this.getEmail(),addressLine1:this.getAddressLine1(),addressLine2:this.getAddressLine2(),city:this.getCity(),postalCode:this.getPostalCode(),state:this.getState(),country:this.getCountry(),isBillingAddress:this.getIsBillingAddress(),isShippingAddress:this.getIsShippingAddress()}}getId(){return this.id}getFirstName(){return this.firstName}getLastName(){return this.lastName}getPhone(){return this.phone}getEmail(){return this.email}getAddressLine1(){return this.addressLine1}getAddressLine2(){return this.addressLine2}getCity(){return this.city}getPostalCode(){return this.postalCode}getState(){return this.state}getCountry(){return this.country}getIsBillingAddress(){return this.isBillingAddress}getIsShippingAddress(){return this.isShippingAddress}getAddressType(){return this.isBillingAddress&&this.isShippingAddress?"billing&shipping":this.isBillingAddress?"billing":this.isShippingAddress?"shipping":"none"}static checkIfShippingAddress(t){return t==="shipping"||t==="billing&shipping"}static checkIfBillingAddress(t){return t==="billing"||t==="billing&shipping"}};var g={"en-IN":"en","kn-IN":"kn"};var y={IN:"INR"},D={INR:"\u20B9"};var m=class{sources;alt;order;label;constructor(t){if(this.sources={...t.sources},this.alt=t.alt,this.order=t.order,this.label=t.label,!this.sources.original)throw "ImageInfoModel cannot be created without an 'original' source URL."}getSources(){return {...this.sources}}getSource(t){return this.sources[t]||this.sources.original}getAlt(){return this.alt}getOrder(){return this.order}getLabel(){return this.label}setAlt(t){this.alt=t;}setOrder(t){this.order=t;}setLabel(t){this.label=t;}setSource(t,e){if(e===void 0){if(t==="original")throw "Cannot remove the 'original' image source.";delete this.sources[t];}else this.sources[t]=e;}getDetails(){return {sources:this.getSources(),alt:this.getAlt(),order:this.getOrder(),label:this.getLabel()}}};var h=class{id;productKey;variantId;name;attributes;specifications;primaryImage;subItems;totalQuantity;basePrice;priceTotals;priceTiers;constructor(t){this.id=t.id,this.productKey=t.productKey,this.variantId=t.variantId,this.name={...t.name},this.attributes={...t.attributes},this.specifications={...t.specifications},this.primaryImage=new m(t.primaryImage),this.subItems=t.subItems.map(e=>({...e})),this.basePrice={...t.basePrice},this.priceTiers=t.priceTiers.map(e=>({...e})),this.totalQuantity=0,this.priceTotals={subtotal:0,mrpTotal:0},this.recalculateTotalQuantity(),this.recalculatePriceTotal();}getId(){return this.id}getProductKey(){return this.productKey}getVariantId(){return this.variantId}getName(t){return t?this.name[t]??this.name[g[t]]??this.name.en:{...this.name}}getAttributes(){return {...this.attributes}}getSpecifications(t){return t?this.specifications[t]??this.specifications[g[t]]??this.specifications.en:JSON.parse(JSON.stringify(this.specifications))}getImage(){return this.primaryImage}getSubItems(){return this.subItems.map(t=>({...t}))}getTotalQuantity(){return this.totalQuantity}getBasePrice(){return {...this.basePrice}}getPriceTotals(){return {...this.priceTotals}}getPriceTiers(){return this.priceTiers.map(t=>({...t}))}recalculateTotalQuantity(){this.totalQuantity=this.subItems.reduce((t,e)=>t+e.quantity,0);}recalculatePriceTotal(){let t=this.totalQuantity,e=this.basePrice.unitPrice,i=null;for(let r of this.priceTiers.sort((s,o)=>o.minQuantity-s.minQuantity))if(t>=r.minQuantity){i=r;break}i&&(e=i.unitPrice),this.priceTotals.mrpTotal=this.basePrice.unitPrice*t,this.priceTotals.subtotal=e*t;}getDetails(){return {id:this.getId(),productKey:this.getProductKey(),variantId:this.getVariantId(),name:this.getName(),attributes:this.getAttributes(),specifications:this.getSpecifications(),primaryImage:this.getImage().getDetails(),subItems:this.getSubItems(),totalQuantity:this.getTotalQuantity(),basePrice:this.getBasePrice(),priceTotals:this.getPriceTotals(),priceTiers:this.getPriceTiers()}}addSubItems(t,e){t.forEach(i=>{let r=this.subItems.find(s=>s.size===i.size);r?r.quantity=e?r.quantity+i.quantity:i.quantity:this.subItems.push(i);}),this.subItems=this.subItems.filter(i=>i.quantity),this.recalculateTotalQuantity(),this.recalculatePriceTotal();}clearLineItem(){this.id="",this.productKey="",this.variantId="",this.name={en:""},this.attributes={color:{name:"",hex:""}},this.primaryImage=new m({sources:{original:""}}),this.subItems=[],this.recalculateTotalQuantity(),this.recalculatePriceTotal();}};var u=class n{price;country;constructor(t,e){if(this.country=e,t<0)throw new Error("InvalidPrice: Price cannot be negative.");this.price=t;}getCountry(){return this.country}getRoundedPrice(){return n.getRoundedPrice(this.price,this.country)}getFormattedString(t){return n.getFormattedString(this.price,this.country,t)}static getFormattedString(t,e,i,r={}){let s=r.displayAsInteger??!1,o=y[e];if(o===void 0)throw new Error("Currency mapping not found for CountryCode");let d=t,C=s?0:n.getDecimalPlaces(o),a={style:r.style??"currency",currency:o,signDisplay:"never",currencyDisplay:r.currencyDisplay,minimumFractionDigits:C,maximumFractionDigits:C};s&&(d=Math.round(d));try{return new Intl.NumberFormat(i,a).format(d)}catch(S){return console.error(`Error formatting price for country "${e}" and currency "${o}":`,S),`${D[o]??o} ${n.addThousandSeparators(d.toFixed(C))}`}}static getDecimalPlaces(t){switch(t){case"INR":default:return 2}}static addThousandSeparators(t){let e=t.split("."),i=e[0],r=e.length>1?"."+e[1]:"";return i.replace(/\B(?=(\d{3})+(?!\d))/g,",")+r}static getRoundedPrice(t,e){if(t<0)throw new Error("Price cannot be negative for rounding.");let i=y[e];if(i===void 0)throw new Error(`Currency mapping not found for CountryCode: ${e}`);let r=n.getDecimalPlaces(i),s=Math.pow(10,r);return Math.round(t*s)/s}static getCurrency(t){return y[t]}};var I=class extends l{couponCode;name;description;type;customerId;validFrom;validTo;minCartValue;maxCartDiscount;discountMethod;percentageValue;applicableTo;category;constructor(t,e=new Date){super(t,e),this.couponCode=t.couponCode,this.name={...t.name},this.description={...t.description},this.type=t.type,this.customerId=t.customerId,this.validFrom=t.validFrom&&Date.parse(t.validFrom)?new Date(t.validFrom).toISOString():e.toISOString(),this.validTo=t.validTo&&Date.parse(t.validTo)?new Date(t.validTo).toISOString():e.toISOString(),this.minCartValue=t.minCartValue.map(i=>({...i})),this.maxCartDiscount=t.maxCartDiscount.map(i=>({...i})),this.discountMethod=t.discountMethod,this.percentageValue=t.percentageValue??0,this.applicableTo=t.applicableTo,this.category=t.category;}getCode(){return this.couponCode}getName(t){return t?this.name[t]??this.name[g[t]]??this.name.en:{...this.name}}getDescription(t){return t?this.description[t]??this.description[g[t]]??this.description.en:{...this.description}}getType(){return this.type}getCustomerId(){return this.customerId??""}getValidFrom(){return this.validFrom}getValidTo(){return this.validTo}getMinCartValue(t){return t?this.minCartValue.find(e=>e.country===t):this.minCartValue}getMaxCartDiscount(t){return t?this.maxCartDiscount.find(e=>e.country===t):this.maxCartDiscount}getDiscountMethod(){return this.discountMethod}getPercentageValue(){return this.percentageValue}getApplicableTo(){return this.applicableTo}getCategory(){return this.category}getDetails(){return {...super.getDetails(),couponCode:this.getCode(),name:this.getName(),description:this.getDescription(),type:this.getType(),customerId:this.getCustomerId(),validFrom:this.getValidFrom(),validTo:this.getValidTo(),minCartValue:this.getMinCartValue(),maxCartDiscount:this.getMaxCartDiscount(),discountMethod:this.getDiscountMethod(),percentageValue:this.getPercentageValue(),applicableTo:this.getApplicableTo(),category:this.getCategory()}}isActive(){return new Date(this.validFrom)<=new Date&&new Date(this.validTo)>=new Date}isApplicableTo(t){return this.applicableTo==="all"||this.applicableTo==="ftb"&&t}};var b=class extends l{id;customerId;customerEmail;anonymousId;lineItems;shippingDetails;shippingAddress;billingAddress;coupons;total;country;currency;locale;constructor(t,e=new Date){super(t,e),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(i=>new h(i)),this.billingAddress=t.billingAddress?new p(t.billingAddress,e):null,this.shippingAddress=t.shippingAddress?new p(t.shippingAddress,e):null,this.coupons=(t.coupons||[]).map(i=>new I(i)),this.shippingDetails=t.shippingDetails?{...t.shippingDetails}:null,this.total={shipping:t.total?.shipping||0,effectiveShipping:t.total?.effectiveShipping??t.total?.shipping??0,subtotal:0,mrpTotal:0,couponTotal:t.total?.couponTotal||{},grandTotal:t.total?.grandTotal||0},this.recalculateBaseTotals();}recalculateBaseTotals(){this.total.subtotal=u.getRoundedPrice(this.lineItems.reduce((t,e)=>t+e.getPriceTotals().subtotal,0),this.country),this.total.mrpTotal=u.getRoundedPrice(this.lineItems.reduce((t,e)=>t+e.getPriceTotals().mrpTotal,0),this.country);}getId(){return this.id}getCustomerId(){return this.customerId}getCustomerEmail(){return this.customerEmail}getAnonymousId(){return this.anonymousId}getLineItems(){return this.lineItems.map(t=>new h(t.getDetails()))}getLineItemsCount(){return this.lineItems.length}getShippingDetails(){return this.shippingDetails?{...this.shippingDetails}:null}getShippingAddress(){return this.shippingAddress?new p(this.shippingAddress.getDetails()):null}hasShippingAddress(){return !!this.shippingAddress}hasBillingAddress(){return !!this.billingAddress}getBillingAddress(){return this.billingAddress?new p(this.billingAddress.getDetails()):null}getCoupons(){return this.coupons.map(t=>new I(t.getDetails()))}getCountry(){return this.country}getCurrency(){return this.currency}getLocale(){return this.locale}getTotal(){return {...this.total,couponTotal:{...this.total.couponTotal}}}calculateApplicableCouponDiscount(t){if(!t.isActive())return 0;let e=t.getMinCartValue(this.country),i=t.getMaxCartDiscount(this.country);if(!e||this.total.subtotal<e.price||!i||i.price<0)return 0;let r=t.getCategory(),s=t.getDiscountMethod(),o=0,d=r==="SHIPPING"?this.total.shipping:this.total.subtotal;if(d<=0)return 0;switch(s){case"flat":let a=i?.price??0;o=Math.min(d,a);break;case"percentage":o=d*(t.getPercentageValue()/100);break;default:return 0}let C=Math.min(o,i.price);return u.getRoundedPrice(Math.max(0,C),this.country)}recalculateCouponTotals(){this.total.couponTotal={};let t=0;return this.coupons.forEach(e=>{let i=this.calculateApplicableCouponDiscount(e);i>0&&(this.total.couponTotal[e.getCode()]=i,t+=i);}),u.getRoundedPrice(t,this.country)}updateCartTotals(){this.total.subtotal=u.getRoundedPrice(this.lineItems.reduce((r,s)=>r+s.getPriceTotals().subtotal,0),this.country),this.total.mrpTotal=u.getRoundedPrice(this.lineItems.reduce((r,s)=>r+s.getPriceTotals().mrpTotal,0),this.country),this.recalculateCouponTotals();let t=this.coupons.filter(r=>r.getCategory()==="SHIPPING").reduce((r,s)=>r+(this.total.couponTotal[s.getCode()]??0),0);this.total.effectiveShipping=u.getRoundedPrice(Math.max(0,this.total.shipping-t),this.country);let e=this.coupons.filter(r=>r.getCategory()!=="SHIPPING").reduce((r,s)=>r+(this.total.couponTotal[s.getCode()]??0),0),i=this.total.subtotal+this.total.effectiveShipping;this.total.grandTotal=u.getRoundedPrice(Math.max(0,i-e),this.country);}setShippingDetails(t){this.shippingDetails=t?{...t}:null,this.total.shipping=u.getRoundedPrice(this.shippingDetails?.estimatedCost??0,this.country),this.updateCartTotals();}getDetails(){return {...super.getDetails(),id:this.getId(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),anonymousId:this.getAnonymousId(),lineItems:this.getLineItems().map(t=>t.getDetails()),shippingDetails:this.getShippingDetails(),shippingAddress:this.getShippingAddress()?.getDetails()||null,billingAddress:this.getBillingAddress()?.getDetails()||null,coupons:this.getCoupons().map(t=>t.getDetails()),total:this.getTotal(),country:this.getCountry(),currency:this.getCurrency(),locale:this.getLocale()}}};var A=class extends Error{constructor(t){super(`Line item with ID '${t}' not found in the cart.`),this.name="LineItemNotFoundError";}};var T=(a=>(a.PLACED="PLACED",a.PENDING_PAYMENT="PENDING_PAYMENT",a.PROCESSING="PROCESSING",a.SHIPPED="SHIPPED",a.DELIVERED="DELIVERED",a.CANCELLED="CANCELLED",a.RETURNED="RETURNED",a.REFUNDED="REFUNDED",a.COMPLETED="COMPLETED",a))(T||{}),L=(s=>(s.INITIAL="INITIAL",s.PROCESSING="PROCESSING",s.SHIPPED="SHIPPED",s.DELIVERED="DELIVERED",s.CANCELLED="CANCELLED",s))(L||{}),f=class extends b{orderNumber;cartId;paymentStatus;holdReason;state;lineItemStateMap;constructor(t,e=new Date){super(t,e),this.orderNumber=t.orderNumber,this.cartId=t.cartId,this.paymentStatus=t.paymentStatus,this.holdReason=t.holdReason||"",this.state=t.state;let i={};t.lineItems.forEach(r=>{let s=t.lineItemStateMap?.[r.id];i[r.id]={state:s?.state||"INITIAL",reason:s?.reason||"",transitionAt:s?.transitionAt||this.createdAt};}),this.lineItemStateMap=i;}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}getLineItemsStateMap(){return {...this.lineItemStateMap}}getLineItemState(t){if(!this.lineItemStateMap[t])throw new A(t);return this.lineItemStateMap[t].state}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(),lineItemStateMap:this.getLineItemsStateMap()}}};exports.OrderLineItemState=L;exports.OrderState=T;exports.default=f;//# sourceMappingURL=Order.js.map
|
|
1
|
+
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var l=class{customFields;version;createdAt;modifiedAt;modifiedBy;constructor(t,e=new Date){this.customFields={...t.customFields},this.version=t.version??1,this.createdAt=t.createdAt&&!isNaN(Date.parse(t.createdAt))?new Date(t.createdAt).toISOString():e.toISOString(),this.modifiedAt=t.modifiedAt&&!isNaN(Date.parse(t.modifiedAt))?new Date(t.modifiedAt).toISOString():e.toISOString(),this.modifiedBy={...t.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(t,e,i,r){this.modifiedBy={id:t,authType:e,requestId:i,lambdaName:r};}getCustomField(t){return this.customFields[t]??null}setCustomField(t,e){this.customFields[t]=e;}getAllCustomFields(){return {...this.customFields}}};var h={"en-IN":"en","kn-IN":"kn"};var y={IN:"INR"},D={INR:"\u20B9"};var m=class extends l{couponCode;name;description;type;customerId;validFrom;validTo;minCartValue;maxCartDiscount;discountMethod;percentageValue;applicableTo;category;constructor(t,e=new Date){super(t,e),this.couponCode=t.couponCode,this.name={...t.name},this.description={...t.description},this.type=t.type,this.customerId=t.customerId,this.validFrom=t.validFrom&&Date.parse(t.validFrom)?new Date(t.validFrom).toISOString():e.toISOString(),this.validTo=t.validTo&&Date.parse(t.validTo)?new Date(t.validTo).toISOString():e.toISOString(),this.minCartValue=t.minCartValue.map(i=>({...i})),this.maxCartDiscount=t.maxCartDiscount.map(i=>({...i})),this.discountMethod=t.discountMethod,this.percentageValue=t.percentageValue??0,this.applicableTo=t.applicableTo,this.category=t.category;}getCode(){return this.couponCode}getName(t){return t?this.name[t]??this.name[h[t]]??this.name.en:{...this.name}}getDescription(t){return t?this.description[t]??this.description[h[t]]??this.description.en:{...this.description}}getType(){return this.type}getCustomerId(){return this.customerId??""}getValidFrom(){return this.validFrom}getValidTo(){return this.validTo}getMinCartValue(t){return t?this.minCartValue.find(e=>e.country===t):this.minCartValue}getMaxCartDiscount(t){return t?this.maxCartDiscount.find(e=>e.country===t):this.maxCartDiscount}getDiscountMethod(){return this.discountMethod}getPercentageValue(){return this.percentageValue}getApplicableTo(){return this.applicableTo}getCategory(){return this.category}getDetails(){return {...super.getDetails(),couponCode:this.getCode(),name:this.getName(),description:this.getDescription(),type:this.getType(),customerId:this.getCustomerId(),validFrom:this.getValidFrom(),validTo:this.getValidTo(),minCartValue:this.getMinCartValue(),maxCartDiscount:this.getMaxCartDiscount(),discountMethod:this.getDiscountMethod(),percentageValue:this.getPercentageValue(),applicableTo:this.getApplicableTo(),category:this.getCategory()}}isActive(){return new Date(this.validFrom)<=new Date&&new Date(this.validTo)>=new Date}isApplicableTo(t){return this.applicableTo==="all"||this.applicableTo==="ftb"&&t}};var n=class a{price;country;constructor(t,e){if(this.country=e,t<0)throw new Error("InvalidPrice: Price cannot be negative.");this.price=t;}getCountry(){return this.country}getRoundedPrice(){return a.getRoundedPrice(this.price,this.country)}getFormattedString(t){return a.getFormattedString(this.price,this.country,t)}static getFormattedString(t,e,i,r={}){let s=r.displayAsInteger??!1,u=y[e];if(u===void 0)throw new Error("Currency mapping not found for CountryCode");let d=t,g=s?0:a.getDecimalPlaces(u),f={style:r.style??"currency",currency:u,signDisplay:"never",currencyDisplay:r.currencyDisplay,minimumFractionDigits:g,maximumFractionDigits:g};s&&(d=Math.round(d));try{return new Intl.NumberFormat(i,f).format(d)}catch(o){return console.error(`Error formatting price for country "${e}" and currency "${u}":`,o),`${D[u]??u} ${a.addThousandSeparators(d.toFixed(g))}`}}static getDecimalPlaces(t){switch(t){case"INR":default:return 2}}static addThousandSeparators(t){let e=t.split("."),i=e[0],r=e.length>1?"."+e[1]:"";return i.replace(/\B(?=(\d{3})+(?!\d))/g,",")+r}static getRoundedPrice(t,e){if(t<0)throw new Error("Price cannot be negative for rounding.");let i=y[e];if(i===void 0)throw new Error(`Currency mapping not found for CountryCode: ${e}`);let r=a.getDecimalPlaces(i),s=Math.pow(10,r);return Math.round(t*s)/s}static getCurrency(t){return y[t]}};var p=class extends l{id;firstName;lastName;phone;email;addressLine1;addressLine2;city;postalCode;state;country;isBillingAddress;isShippingAddress;constructor(t,e=new Date){super(t,e),this.id=t.id,this.firstName=t.firstName,this.lastName=t.lastName||"",this.phone=t.phone,this.email=t.email,this.addressLine1=t.addressLine1,this.addressLine2=t.addressLine2||"",this.city=t.city,this.postalCode=t.postalCode,this.state=t.state,this.country=t.country,this.isBillingAddress=t.isBillingAddress,this.isShippingAddress=t.isShippingAddress;}getDetails(){return {...super.getDetails(),id:this.getId(),firstName:this.getFirstName(),lastName:this.getLastName(),phone:this.getPhone(),email:this.getEmail(),addressLine1:this.getAddressLine1(),addressLine2:this.getAddressLine2(),city:this.getCity(),postalCode:this.getPostalCode(),state:this.getState(),country:this.getCountry(),isBillingAddress:this.getIsBillingAddress(),isShippingAddress:this.getIsShippingAddress()}}getId(){return this.id}getFirstName(){return this.firstName}getLastName(){return this.lastName}getPhone(){return this.phone}getEmail(){return this.email}getAddressLine1(){return this.addressLine1}getAddressLine2(){return this.addressLine2}getCity(){return this.city}getPostalCode(){return this.postalCode}getState(){return this.state}getCountry(){return this.country}getIsBillingAddress(){return this.isBillingAddress}getIsShippingAddress(){return this.isShippingAddress}getAddressType(){return this.isBillingAddress&&this.isShippingAddress?"billing&shipping":this.isBillingAddress?"billing":this.isShippingAddress?"shipping":"none"}static checkIfShippingAddress(t){return t==="shipping"||t==="billing&shipping"}static checkIfBillingAddress(t){return t==="billing"||t==="billing&shipping"}};var I=class{sources;alt;order;label;constructor(t){if(this.sources={...t.sources},this.alt=t.alt,this.order=t.order,this.label=t.label,!this.sources.original)throw "ImageInfoModel cannot be created without an 'original' source URL."}getSources(){return {...this.sources}}getSource(t){return this.sources[t]||this.sources.original}getAlt(){return this.alt}getOrder(){return this.order}getLabel(){return this.label}setAlt(t){this.alt=t;}setOrder(t){this.order=t;}setLabel(t){this.label=t;}setSource(t,e){if(e===void 0){if(t==="original")throw "Cannot remove the 'original' image source.";delete this.sources[t];}else this.sources[t]=e;}getDetails(){return {sources:this.getSources(),alt:this.getAlt(),order:this.getOrder(),label:this.getLabel()}}};var C=class{id;productKey;variantId;name;attributes;specifications;primaryImage;subItems;totalQuantity;basePrice;priceTotals;priceTiers;constructor(t){this.id=t.id,this.productKey=t.productKey,this.variantId=t.variantId,this.name={...t.name},this.attributes={...t.attributes},this.specifications={...t.specifications},this.primaryImage=new I(t.primaryImage),this.subItems=t.subItems.map(e=>({...e})),this.basePrice={...t.basePrice},this.priceTiers=t.priceTiers.map(e=>({...e})),this.totalQuantity=0,this.priceTotals={subtotal:0,mrpTotal:0},this.recalculateTotalQuantity(),this.recalculatePriceTotal();}getId(){return this.id}getProductKey(){return this.productKey}getVariantId(){return this.variantId}getName(t){return t?this.name[t]??this.name[h[t]]??this.name.en:{...this.name}}getAttributes(){return {...this.attributes}}getSpecifications(t){return t?this.specifications[t]??this.specifications[h[t]]??this.specifications.en:JSON.parse(JSON.stringify(this.specifications))}getImage(){return this.primaryImage}getSubItems(){return this.subItems.map(t=>({...t}))}getTotalQuantity(){return this.totalQuantity}getBasePrice(){return {...this.basePrice}}getPriceTotals(){return {...this.priceTotals}}getPriceTiers(){return this.priceTiers.map(t=>({...t}))}recalculateTotalQuantity(){this.totalQuantity=this.subItems.reduce((t,e)=>t+e.quantity,0);}recalculatePriceTotal(){let t=this.totalQuantity,e=this.basePrice.unitPrice,i=null;for(let r of this.priceTiers.sort((s,u)=>u.minQuantity-s.minQuantity))if(t>=r.minQuantity){i=r;break}i&&(e=i.unitPrice),this.priceTotals.mrpTotal=this.basePrice.unitPrice*t,this.priceTotals.subtotal=e*t;}getDetails(){return {id:this.getId(),productKey:this.getProductKey(),variantId:this.getVariantId(),name:this.getName(),attributes:this.getAttributes(),specifications:this.getSpecifications(),primaryImage:this.getImage().getDetails(),subItems:this.getSubItems(),totalQuantity:this.getTotalQuantity(),basePrice:this.getBasePrice(),priceTotals:this.getPriceTotals(),priceTiers:this.getPriceTiers()}}addSubItems(t,e){t.forEach(i=>{let r=this.subItems.find(s=>s.size===i.size);r?r.quantity=e?r.quantity+i.quantity:i.quantity:this.subItems.push(i);}),this.subItems=this.subItems.filter(i=>i.quantity),this.recalculateTotalQuantity(),this.recalculatePriceTotal();}clearLineItem(){this.id="",this.productKey="",this.variantId="",this.name={en:""},this.attributes={color:{name:"",hex:""}},this.primaryImage=new I({sources:{original:""}}),this.subItems=[],this.recalculateTotalQuantity(),this.recalculatePriceTotal();}};var b=class extends l{id;customerId;customerEmail;anonymousId;lineItems;shippingDetails;shippingAddress;billingAddress;coupons;total;country;currency;locale;constructor(t,e=new Date){super(t,e),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(i=>new C(i)),this.billingAddress=t.billingAddress?new p(t.billingAddress,e):null,this.shippingAddress=t.shippingAddress?new p(t.shippingAddress,e):null,this.coupons=(t.coupons||[]).map(i=>new m(i)),this.shippingDetails=t.shippingDetails?{...t.shippingDetails}:null,this.total={shipping:t.total?.shipping||0,effectiveShipping:t.total?.effectiveShipping??t.total?.shipping??0,subtotal:t.total?.subtotal||0,mrpTotal:t.total?.mrpTotal||0,couponTotal:t.total?.couponTotal||{},grandTotal:t.total?.grandTotal||0};}recalculateBaseTotals(){this.total.subtotal=n.getRoundedPrice(this.lineItems.reduce((t,e)=>t+e.getPriceTotals().subtotal,0),this.country),this.total.mrpTotal=n.getRoundedPrice(this.lineItems.reduce((t,e)=>t+e.getPriceTotals().mrpTotal,0),this.country);}getId(){return this.id}getCustomerId(){return this.customerId}getCustomerEmail(){return this.customerEmail}getAnonymousId(){return this.anonymousId}getLineItems(){return this.lineItems.map(t=>new C(t.getDetails()))}getLineItemsCount(){return this.lineItems.length}getShippingDetails(){return this.shippingDetails?{...this.shippingDetails}:null}getShippingAddress(){return this.shippingAddress?new p(this.shippingAddress.getDetails()):null}hasShippingAddress(){return !!this.shippingAddress}hasBillingAddress(){return !!this.billingAddress}getBillingAddress(){return this.billingAddress?new p(this.billingAddress.getDetails()):null}getCoupons(){return this.coupons.map(t=>new m(t.getDetails()))}getCountry(){return this.country}getCurrency(){return this.currency}getLocale(){return this.locale}getTotal(){return {...this.total,couponTotal:{...this.total.couponTotal}}}calculateApplicableCouponDiscount(t,e=!0){if(e&&!t.isActive())return 0;let i=t.getMinCartValue(this.country),r=t.getMaxCartDiscount(this.country);if(!i||this.total.subtotal<i.price||!r||r.price<0)return 0;let s=t.getCategory(),u=t.getDiscountMethod(),d=0,g=s==="SHIPPING"?this.total.shipping:this.total.subtotal;if(g<=0)return 0;switch(u){case"flat":let o=r?.price??0;d=Math.min(g,o);break;case"percentage":d=g*(t.getPercentageValue()/100);break;default:return 0}let f=Math.min(d,r.price);return n.getRoundedPrice(Math.max(0,f),this.country)}recalculateCouponTotals(t=!0){this.total.couponTotal={};let e=0;return this.coupons.forEach(i=>{let r=this.calculateApplicableCouponDiscount(i,t);r>0&&(this.total.couponTotal[i.getCode()]=r,e+=r);}),n.getRoundedPrice(e,this.country)}getDetails(){return {...super.getDetails(),id:this.getId(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),anonymousId:this.getAnonymousId(),lineItems:this.getLineItems().map(t=>t.getDetails()),shippingDetails:this.getShippingDetails(),shippingAddress:this.getShippingAddress()?.getDetails()||null,billingAddress:this.getBillingAddress()?.getDetails()||null,coupons:this.getCoupons().map(t=>t.getDetails()),total:this.getTotal(),country:this.getCountry(),currency:this.getCurrency(),locale:this.getLocale()}}};var A=class extends Error{constructor(t){super(`Line item with ID '${t}' not found in the cart.`),this.name="LineItemNotFoundError";}};var L=(s=>(s.PLACED="PLACED",s.PENDING_PAYMENT="PENDING_PAYMENT",s.PROCESSING="PROCESSING",s.CANCELLED="CANCELLED",s.COMPLETED="COMPLETED",s))(L||{}),P=(o=>(o.INITIAL="INITIAL",o.PROCESSING="PROCESSING",o.SHIPPED="SHIPPED",o.DELIVERED="DELIVERED",o.CANCELLED="CANCELLED",o.RETURN_REQUESTED="RETURN_REQUESTED",o.RETURNED="RETURNED",o.REFUND_REQUESTED="REFUND_REQUESTED",o.REFUNDED="REFUNDED",o.ON_HOLD="ON_HOLD",o))(P||{}),S=class extends b{orderNumber;cartId;paymentStatus;holdReason;state;lineItemStateMap;constructor(t,e=new Date){super(t,e),this.orderNumber=t.orderNumber,this.cartId=t.cartId,this.paymentStatus=t.paymentStatus,this.holdReason=t.holdReason||"",this.state=t.state;let i={};t.lineItems.forEach(r=>{let s=t.lineItemStateMap?.[r.id];i[r.id]={state:s?.state||"INITIAL",reason:s?.reason||"",transitionAt:s?.transitionAt||this.createdAt};}),this.lineItemStateMap=i,this.recalculateOrderBaseTotals();}recalculateOrderBaseTotals(){this.total.subtotal=n.getRoundedPrice(this.lineItems.filter(t=>this.lineItemStateMap[t.getId()]?.state!=="CANCELLED").reduce((t,e)=>t+e.getPriceTotals().subtotal,0),this.country),this.total.mrpTotal=n.getRoundedPrice(this.lineItems.filter(t=>this.lineItemStateMap[t.getId()]?.state!=="CANCELLED").reduce((t,e)=>t+e.getPriceTotals().mrpTotal,0),this.country);}updateOrderTotals(){this.recalculateOrderBaseTotals(),this.recalculateCouponTotals(!1);let t=this.coupons.filter(r=>r.getCategory()==="SHIPPING").reduce((r,s)=>r+(this.total.couponTotal[s.getCode()]??0),0);this.total.effectiveShipping=n.getRoundedPrice(Math.max(0,this.total.shipping-t),this.country);let e=this.coupons.filter(r=>r.getCategory()!=="SHIPPING").reduce((r,s)=>r+(this.total.couponTotal[s.getCode()]??0),0),i=this.total.subtotal+this.total.effectiveShipping;this.total.grandTotal=n.getRoundedPrice(Math.max(0,i-e),this.country);}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}getLineItemsStateMap(){return {...this.lineItemStateMap}}getLineItemState(t){if(!this.lineItemStateMap[t])throw new A(t);return this.lineItemStateMap[t].state}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(),lineItemStateMap:this.getLineItemsStateMap()}}};exports.OrderLineItemState=P;exports.OrderState=L;exports.default=S;//# sourceMappingURL=Order.js.map
|
|
2
2
|
//# sourceMappingURL=Order.js.map
|