b23-lib 1.7.23 → 1.7.25
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/Address.d.mts +1 -1
- package/dist/Classes/Address.d.ts +1 -1
- package/dist/Classes/Address.js +1 -1
- package/dist/Classes/Address.js.map +1 -1
- package/dist/Classes/Address.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/Cart.mjs.map +1 -1
- package/dist/Classes/CustomerAddress.js +1 -1
- package/dist/Classes/CustomerAddress.js.map +1 -1
- package/dist/Classes/CustomerAddress.mjs +1 -1
- package/dist/Classes/Order.d.mts +30 -3
- package/dist/Classes/Order.d.ts +30 -3
- 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/Price.d.mts +12 -2
- package/dist/Classes/Price.d.ts +12 -2
- package/dist/Classes/Price.js +1 -1
- package/dist/Classes/Price.js.map +1 -1
- package/dist/Classes/Price.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/{chunk-L5L7MGGW.mjs → chunk-ADECAEML.mjs} +2 -2
- package/dist/{chunk-L5L7MGGW.mjs.map → chunk-ADECAEML.mjs.map} +1 -1
- package/dist/chunk-GCT7VOSM.mjs +2 -0
- package/dist/chunk-GCT7VOSM.mjs.map +1 -0
- package/dist/chunk-HTJJLLGW.mjs +2 -0
- package/dist/chunk-HTJJLLGW.mjs.map +1 -0
- package/dist/chunk-Z6YNOEGK.mjs +2 -0
- package/dist/chunk-Z6YNOEGK.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-XZG7Y2WO.mjs +0 -2
- package/dist/chunk-XZG7Y2WO.mjs.map +0 -1
- package/dist/chunk-YGCESF37.mjs +0 -2
- package/dist/chunk-YGCESF37.mjs.map +0 -1
package/dist/Classes/Order.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { ISODateTime } from './Common.mjs';
|
|
1
2
|
import { PaymentStatus } from './Payment.mjs';
|
|
2
3
|
import BaseShoppingContainerModel, { BaseShoppingContainerAttributes, BaseShoppingContainerData } from './ShoppingContainer.mjs';
|
|
4
|
+
import './Enum.mjs';
|
|
3
5
|
import './Base.mjs';
|
|
4
6
|
import '../Auth/index.mjs';
|
|
5
|
-
import './Common.mjs';
|
|
6
|
-
import './Enum.mjs';
|
|
7
7
|
import './Address.mjs';
|
|
8
8
|
import './LineItem.mjs';
|
|
9
9
|
import './ImageInfo.mjs';
|
|
@@ -19,6 +19,18 @@ declare enum OrderState {
|
|
|
19
19
|
RETURNED = "RETURNED",
|
|
20
20
|
REFUNDED = "REFUNDED"
|
|
21
21
|
}
|
|
22
|
+
declare enum OrderLineItemState {
|
|
23
|
+
INITIAL = "INITIAL",
|
|
24
|
+
PROCESSING = "PROCESSING",
|
|
25
|
+
SHIPPED = "SHIPPED",
|
|
26
|
+
DELIVERED = "DELIVERED",
|
|
27
|
+
CANCELLED = "CANCELLED"
|
|
28
|
+
}
|
|
29
|
+
type OrderLineItemStateMap = Record<string, {
|
|
30
|
+
state: OrderLineItemState;
|
|
31
|
+
reason?: string;
|
|
32
|
+
transitionAt: ISODateTime;
|
|
33
|
+
}>;
|
|
22
34
|
/**
|
|
23
35
|
* Input attributes for creating an OrderModel.
|
|
24
36
|
* Extends CartAttributes but requires/adds order-specific fields.
|
|
@@ -30,6 +42,7 @@ type OrderAttributes = Required<Omit<BaseShoppingContainerAttributes, 'anonymous
|
|
|
30
42
|
paymentStatus: PaymentStatus;
|
|
31
43
|
holdReason?: string;
|
|
32
44
|
state: OrderState;
|
|
45
|
+
LineItemState: OrderLineItemStateMap;
|
|
33
46
|
};
|
|
34
47
|
/**
|
|
35
48
|
* Output data structure for an OrderModel.
|
|
@@ -41,6 +54,7 @@ declare class OrderModel extends BaseShoppingContainerModel {
|
|
|
41
54
|
protected paymentStatus: PaymentStatus;
|
|
42
55
|
protected holdReason: string;
|
|
43
56
|
protected state: OrderState;
|
|
57
|
+
protected LineItemState: OrderLineItemStateMap;
|
|
44
58
|
/**
|
|
45
59
|
* Creates an instance of OrderModel.
|
|
46
60
|
* @param data - The initial order attributes, including cart data.
|
|
@@ -73,6 +87,19 @@ declare class OrderModel extends BaseShoppingContainerModel {
|
|
|
73
87
|
* @returns The OrderState enum value.
|
|
74
88
|
*/
|
|
75
89
|
getState(): OrderState;
|
|
90
|
+
/**
|
|
91
|
+
* Gets the map tracking the state of each line item in the order.
|
|
92
|
+
* The keys are line item IDs, and the values contain the state, reason, and transition timestamp.
|
|
93
|
+
* @returns The OrderLineItemStateMap.
|
|
94
|
+
*/
|
|
95
|
+
getLineItemsStateMap(): OrderLineItemStateMap;
|
|
96
|
+
/**
|
|
97
|
+
* Gets the current state of a specific line item within the order.
|
|
98
|
+
* @param lineItemId - The ID of the line item whose state is requested.
|
|
99
|
+
* @returns The OrderLineItemState enum value for the specified line item.
|
|
100
|
+
* @throws {LineItemNotFoundError} If no line item with the given ID exists in the order's state map.
|
|
101
|
+
*/
|
|
102
|
+
getLineItemState(lineItemId: string): OrderLineItemState;
|
|
76
103
|
/**
|
|
77
104
|
* Gets a plain data object representing the order's current state.
|
|
78
105
|
* Includes all cart details plus order-specific information.
|
|
@@ -81,4 +108,4 @@ declare class OrderModel extends BaseShoppingContainerModel {
|
|
|
81
108
|
getDetails(): OrderData;
|
|
82
109
|
}
|
|
83
110
|
|
|
84
|
-
export { type OrderAttributes, type OrderData, OrderState, OrderModel as default };
|
|
111
|
+
export { type OrderAttributes, type OrderData, OrderLineItemState, type OrderLineItemStateMap, OrderState, OrderModel as default };
|
package/dist/Classes/Order.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { ISODateTime } from './Common.js';
|
|
1
2
|
import { PaymentStatus } from './Payment.js';
|
|
2
3
|
import BaseShoppingContainerModel, { BaseShoppingContainerAttributes, BaseShoppingContainerData } from './ShoppingContainer.js';
|
|
4
|
+
import './Enum.js';
|
|
3
5
|
import './Base.js';
|
|
4
6
|
import '../Auth/index.js';
|
|
5
|
-
import './Common.js';
|
|
6
|
-
import './Enum.js';
|
|
7
7
|
import './Address.js';
|
|
8
8
|
import './LineItem.js';
|
|
9
9
|
import './ImageInfo.js';
|
|
@@ -19,6 +19,18 @@ declare enum OrderState {
|
|
|
19
19
|
RETURNED = "RETURNED",
|
|
20
20
|
REFUNDED = "REFUNDED"
|
|
21
21
|
}
|
|
22
|
+
declare enum OrderLineItemState {
|
|
23
|
+
INITIAL = "INITIAL",
|
|
24
|
+
PROCESSING = "PROCESSING",
|
|
25
|
+
SHIPPED = "SHIPPED",
|
|
26
|
+
DELIVERED = "DELIVERED",
|
|
27
|
+
CANCELLED = "CANCELLED"
|
|
28
|
+
}
|
|
29
|
+
type OrderLineItemStateMap = Record<string, {
|
|
30
|
+
state: OrderLineItemState;
|
|
31
|
+
reason?: string;
|
|
32
|
+
transitionAt: ISODateTime;
|
|
33
|
+
}>;
|
|
22
34
|
/**
|
|
23
35
|
* Input attributes for creating an OrderModel.
|
|
24
36
|
* Extends CartAttributes but requires/adds order-specific fields.
|
|
@@ -30,6 +42,7 @@ type OrderAttributes = Required<Omit<BaseShoppingContainerAttributes, 'anonymous
|
|
|
30
42
|
paymentStatus: PaymentStatus;
|
|
31
43
|
holdReason?: string;
|
|
32
44
|
state: OrderState;
|
|
45
|
+
LineItemState: OrderLineItemStateMap;
|
|
33
46
|
};
|
|
34
47
|
/**
|
|
35
48
|
* Output data structure for an OrderModel.
|
|
@@ -41,6 +54,7 @@ declare class OrderModel extends BaseShoppingContainerModel {
|
|
|
41
54
|
protected paymentStatus: PaymentStatus;
|
|
42
55
|
protected holdReason: string;
|
|
43
56
|
protected state: OrderState;
|
|
57
|
+
protected LineItemState: OrderLineItemStateMap;
|
|
44
58
|
/**
|
|
45
59
|
* Creates an instance of OrderModel.
|
|
46
60
|
* @param data - The initial order attributes, including cart data.
|
|
@@ -73,6 +87,19 @@ declare class OrderModel extends BaseShoppingContainerModel {
|
|
|
73
87
|
* @returns The OrderState enum value.
|
|
74
88
|
*/
|
|
75
89
|
getState(): OrderState;
|
|
90
|
+
/**
|
|
91
|
+
* Gets the map tracking the state of each line item in the order.
|
|
92
|
+
* The keys are line item IDs, and the values contain the state, reason, and transition timestamp.
|
|
93
|
+
* @returns The OrderLineItemStateMap.
|
|
94
|
+
*/
|
|
95
|
+
getLineItemsStateMap(): OrderLineItemStateMap;
|
|
96
|
+
/**
|
|
97
|
+
* Gets the current state of a specific line item within the order.
|
|
98
|
+
* @param lineItemId - The ID of the line item whose state is requested.
|
|
99
|
+
* @returns The OrderLineItemState enum value for the specified line item.
|
|
100
|
+
* @throws {LineItemNotFoundError} If no line item with the given ID exists in the order's state map.
|
|
101
|
+
*/
|
|
102
|
+
getLineItemState(lineItemId: string): OrderLineItemState;
|
|
76
103
|
/**
|
|
77
104
|
* Gets a plain data object representing the order's current state.
|
|
78
105
|
* Includes all cart details plus order-specific information.
|
|
@@ -81,4 +108,4 @@ declare class OrderModel extends BaseShoppingContainerModel {
|
|
|
81
108
|
getDetails(): OrderData;
|
|
82
109
|
}
|
|
83
110
|
|
|
84
|
-
export { type OrderAttributes, type OrderData, OrderState, OrderModel as default };
|
|
111
|
+
export { type OrderAttributes, type OrderData, OrderLineItemState, type OrderLineItemStateMap, OrderState, OrderModel as default };
|
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 c=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 p=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 g=class{id;productKey;variantId;name;attributes;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.primaryImage=new p(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.en:{...this.name}}getAttributes(){return {...this.attributes}}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(),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 p({sources:{original:""}}),this.subItems=[],this.recalculateTotalQuantity(),this.recalculatePriceTotal();}};var y={IN:"INR"},C={INR:"\u20B9"};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,e={}){let i=e.displayAsInteger??!1,r=y[this.country];if(r===void 0)throw new Error("Currency mapping not found for CountryCode");let s=this.price,u=i?0:a.getDecimalPlaces(r),m={style:"currency",currency:r,signDisplay:"never",currencyDisplay:e.currencyDisplay,minimumFractionDigits:u,maximumFractionDigits:u};i&&(s=Math.round(s));try{return new Intl.NumberFormat(t,m).format(s)}catch(o){return console.error(`Error formatting price for locale "${t}" and currency "${r}":`,o),`${C[r]??r} ${a.addThousandSeparators(s.toFixed(u))}`}}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 h=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.en:{...this.name}}getDescription(t){return t?this.description[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 g(i)),this.billingAddress=t.billingAddress?new c(t.billingAddress,e):null,this.shippingAddress=t.shippingAddress?new c(t.shippingAddress,e):null,this.coupons=(t.coupons||[]).map(i=>new h(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=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 g(t.getDetails()))}getLineItemsCount(){return this.lineItems.length}getShippingDetails(){return this.shippingDetails?{...this.shippingDetails}:null}getShippingAddress(){return this.shippingAddress?new c(this.shippingAddress.getDetails()):null}hasShippingAddress(){return !!this.shippingAddress}hasBillingAddress(){return !!this.billingAddress}getBillingAddress(){return this.billingAddress?new c(this.billingAddress.getDetails()):null}getCoupons(){return this.coupons.map(t=>new h(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(),u=0,m=r==="SHIPPING"?this.total.shipping:this.total.subtotal;if(m<=0)return 0;switch(s){case"flat":let A=i?.price??0;u=Math.min(m,A);break;case"percentage":u=m*(t.getPercentageValue()/100);break;default:return 0}let o=Math.min(u,i.price);return n.getRoundedPrice(Math.max(0,o),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);}),n.getRoundedPrice(t,this.country)}updateCartTotals(){this.total.subtotal=n.getRoundedPrice(this.lineItems.reduce((r,s)=>r+s.getPriceTotals().subtotal,0),this.country),this.total.mrpTotal=n.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=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);}setShippingDetails(t){this.shippingDetails=t?{...t}:null,this.total.shipping=n.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 D=(o=>(o.PENDING_PAYMENT="PENDING_PAYMENT",o.PROCESSING="PROCESSING",o.SHIPPED="SHIPPED",o.PARTIALLY_SHIPPED="PARTIALLY_SHIPPED",o.DELIVERED="DELIVERED",o.CANCELLED="CANCELLED",o.RETURNED="RETURNED",o.REFUNDED="REFUNDED",o))(D||{}),I=class extends b{orderNumber;cartId;paymentStatus;holdReason;state;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;}getOrderNumber(){return this.orderNumber}getCartId(){return this.cartId}getPaymentStatus(){return this.paymentStatus}getHoldReason(){return this.holdReason}getState(){return this.state}getDetails(){return {...super.getDetails(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),shippingAddress:this.getShippingAddress().getDetails(),billingAddress:this.getBillingAddress().getDetails(),orderNumber:this.getOrderNumber(),cartId:this.getCartId(),paymentStatus:this.getPaymentStatus(),holdReason:this.getHoldReason(),state:this.getState()}}};exports.OrderState=D;exports.default=I;//# 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 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=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 m=class{id;productKey;variantId;name;attributes;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.primaryImage=new g(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.en:{...this.name}}getAttributes(){return {...this.attributes}}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,a)=>a.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(),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 g({sources:{original:""}}),this.subItems=[],this.recalculateTotalQuantity(),this.recalculatePriceTotal();}};var b={IN:"INR"},D={INR:"\u20B9"};var u=class o{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 o.getRoundedPrice(this.price,this.country)}getFormattedString(t){return o.getFormattedString(this.price,this.country,t)}static getFormattedString(t,e,i,r={}){let s=r.displayAsInteger??!1,a=b[e];if(a===void 0)throw new Error("Currency mapping not found for CountryCode");let c=t,n=s?0:o.getDecimalPlaces(a),y={style:"currency",currency:a,signDisplay:"never",currencyDisplay:r.currencyDisplay,minimumFractionDigits:n,maximumFractionDigits:n};s&&(c=Math.round(c));try{return new Intl.NumberFormat(i,y).format(c)}catch(f){return console.error(`Error formatting price for locale "${i}" and currency "${a}":`,f),`${D[a]??a} ${o.addThousandSeparators(c.toFixed(n))}`}}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=b[e];if(i===void 0)throw new Error(`Currency mapping not found for CountryCode: ${e}`);let r=o.getDecimalPlaces(i),s=Math.pow(10,r);return Math.round(t*s)/s}static getCurrency(t){return b[t]}};var h=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.en:{...this.name}}getDescription(t){return t?this.description[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 I=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 m(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 h(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 m(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 h(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(),a=0,c=r==="SHIPPING"?this.total.shipping:this.total.subtotal;if(c<=0)return 0;switch(s){case"flat":let y=i?.price??0;a=Math.min(c,y);break;case"percentage":a=c*(t.getPercentageValue()/100);break;default:return 0}let n=Math.min(a,i.price);return u.getRoundedPrice(Math.max(0,n),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 C=class extends Error{constructor(t){super(`Line item with ID '${t}' not found in the cart.`),this.name="LineItemNotFoundError";}};var S=(n=>(n.PENDING_PAYMENT="PENDING_PAYMENT",n.PROCESSING="PROCESSING",n.SHIPPED="SHIPPED",n.PARTIALLY_SHIPPED="PARTIALLY_SHIPPED",n.DELIVERED="DELIVERED",n.CANCELLED="CANCELLED",n.RETURNED="RETURNED",n.REFUNDED="REFUNDED",n))(S||{}),T=(s=>(s.INITIAL="INITIAL",s.PROCESSING="PROCESSING",s.SHIPPED="SHIPPED",s.DELIVERED="DELIVERED",s.CANCELLED="CANCELLED",s))(T||{}),A=class extends I{orderNumber;cartId;paymentStatus;holdReason;state;LineItemState;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,this.LineItemState={},t.lineItems.forEach(i=>{let r=this.LineItemState[i.id];this.LineItemState[i.id]={state:r?.state||"INITIAL",reason:r?.reason||"",transitionAt:r?.transitionAt||this.createdAt};});}getOrderNumber(){return this.orderNumber}getCartId(){return this.cartId}getPaymentStatus(){return this.paymentStatus}getHoldReason(){return this.holdReason}getState(){return this.state}getLineItemsStateMap(){return {...this.LineItemState}}getLineItemState(t){if(!this.LineItemState[t])throw new C(t);return this.LineItemState[t].state}getDetails(){return {...super.getDetails(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),shippingAddress:this.getShippingAddress().getDetails(),billingAddress:this.getBillingAddress().getDetails(),orderNumber:this.getOrderNumber(),cartId:this.getCartId(),paymentStatus:this.getPaymentStatus(),holdReason:this.getHoldReason(),state:this.getState(),LineItemState:this.getLineItemsStateMap()}}};exports.OrderLineItemState=T;exports.OrderState=S;exports.default=A;//# sourceMappingURL=Order.js.map
|
|
2
2
|
//# sourceMappingURL=Order.js.map
|