@munchi_oy/cart-engine 0.1.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.
@@ -0,0 +1,157 @@
1
+ import { CurrencyCode, PosBusinessDto, OrderTypePOS, PosDiscountDto, PosOrderItemDto, LocatorType, OrderFormat, OrderRefundStatus, OrderStatusEnum, PosOrderDto, PosCustomerDto, PaymentRefundDto, InvoiceCompanyResponseDto, PosOrderPriceDto, KitchenStatus, PosPaymentStatus, TransactionDto, DiscountType, MoneyDto, ItemPriceDto, PosOrderDtoTaxSummary } from '@munchi_oy/core';
2
+
3
+ declare enum ApplyTo {
4
+ Order = "order",
5
+ Item = "item"
6
+ }
7
+ interface UpdatableCartDetails {
8
+ orderNumber?: string;
9
+ spotNumber?: string | null;
10
+ orderType?: OrderTypePOS;
11
+ comments?: string | null;
12
+ _locatorType?: LocatorType;
13
+ }
14
+ interface CartCreateOptions {
15
+ businessId: string;
16
+ currency: CurrencyCode;
17
+ business: PosBusinessDto;
18
+ orderNumber: string;
19
+ orderType?: OrderTypePOS;
20
+ createdAt?: Date;
21
+ staffId?: string | null;
22
+ shiftId?: string | null;
23
+ }
24
+ type CartItemAddData = Omit<PosOrderItemDto, "lineItemId" | "kitchenStatus" | "paymentStatus" | "discount">;
25
+ type InternalPosDiscount = Omit<PosDiscountDto, "createdAt"> & {
26
+ createdAt: string;
27
+ };
28
+
29
+ declare class Cart {
30
+ readonly id: string;
31
+ readonly businessId: string;
32
+ readonly currency: CurrencyCode;
33
+ readonly createdAt: Date;
34
+ orderNumber: string;
35
+ orderType: OrderTypePOS;
36
+ orderFormat: OrderFormat;
37
+ spotNumber: string | null;
38
+ comments: string | null;
39
+ orderRefundStatus: OrderRefundStatus;
40
+ updatedAt: Date;
41
+ status: OrderStatusEnum;
42
+ private _loyaltyTransactionIds;
43
+ private _loyaltyProgramId;
44
+ private _items;
45
+ private _locatorType;
46
+ private _business;
47
+ private _discounts;
48
+ private _customer;
49
+ private _refunds;
50
+ private _taxSummary;
51
+ private _newlyCancelledItemIds;
52
+ private _invoiceCompany;
53
+ private _staffId;
54
+ private _shiftId;
55
+ private version;
56
+ private constructor();
57
+ static create(options: CartCreateOptions): Cart;
58
+ static fromData(orderDto: PosOrderDto): Cart;
59
+ get items(): readonly PosOrderItemDto[];
60
+ get locatorType(): LocatorType;
61
+ get staffId(): string | null;
62
+ get shiftId(): string | null;
63
+ get discounts(): readonly InternalPosDiscount[];
64
+ get customer(): PosCustomerDto | null;
65
+ get refunds(): readonly PaymentRefundDto[];
66
+ get loyaltyProgramId(): string | null;
67
+ get loyaltyTransactionIds(): readonly string[];
68
+ get invoiceCompany(): InvoiceCompanyResponseDto | null;
69
+ get price(): PosOrderPriceDto;
70
+ setInvoiceCompany(company: InvoiceCompanyResponseDto | null): void;
71
+ addItem(itemData: CartItemAddData, requiresPrep?: boolean): void;
72
+ updateItem(lineItemId: string, updatedItem: PosOrderItemDto): void;
73
+ removeItem(lineItemId: string): void;
74
+ updateItemStatus(lineItemId: string, newStatus: KitchenStatus | PosPaymentStatus): void;
75
+ getNewlyCancelledItemIds(): string[];
76
+ clearCancellationTracking(): void;
77
+ applyDiscountToCart(discountData: Omit<PosDiscountDto, "scope" | "lineItemId" | "createdAt">): void;
78
+ applyDiscountToItem(lineItemId: string, discountData: Omit<PosDiscountDto, "scope" | "lineItemId" | "createdAt">): void;
79
+ removeItemDiscount(lineItemId: string): void;
80
+ removeDiscount(discountId: string): void;
81
+ setCustomer(customer: PosCustomerDto | null): void;
82
+ updateDetails(details: UpdatableCartDetails): void;
83
+ setComment(details: {
84
+ scope: ApplyTo;
85
+ comment: string | null;
86
+ lineItemId?: string;
87
+ }): void;
88
+ setStaffContext(staffId: string | null, shiftId: string | null): void;
89
+ updateOrderStatus(newStatus: OrderStatusEnum): void;
90
+ updateOrderFormat(newFormat: OrderFormat): void;
91
+ updateLoyaltyProgramId(id: string): void;
92
+ updateLoyaltyTransactionId(id: string): void;
93
+ setLoyaltyContext(customer: PosCustomerDto | null, loyaltyProgramId: string | null): void;
94
+ toJSON(paymentEvents?: TransactionDto[]): PosOrderDto;
95
+ clone(): Cart;
96
+ private calculateOrderTaxSummary;
97
+ private touch;
98
+ }
99
+
100
+ type DiscountStrategyFn = (value: number, totalAmount: number) => number;
101
+ declare function calculateDiscountAmount(type: DiscountType, value: number, totalAmountBeforeDiscounts: number): number;
102
+ interface SequentialDiscountCalculation {
103
+ totalDiscountAmount: number;
104
+ remainingAmount: number;
105
+ }
106
+ declare function calculateSequentialDiscountTotal(discounts: ReadonlyArray<Pick<InternalPosDiscount, "type" | "value">>, initialAmount: number): SequentialDiscountCalculation;
107
+
108
+ declare const allocateProportionalMinorUnits: (weights: number[], totalAmount: number) => number[];
109
+
110
+ interface CartOptionPayload {
111
+ suboptions: {
112
+ price: MoneyDto;
113
+ quantity: number;
114
+ }[];
115
+ }
116
+ interface CartPriceSnapshot {
117
+ activeItems: PosOrderItemDto[];
118
+ totalBeforeDiscountsAmount: number;
119
+ subtotalItemDiscountsAmount: number;
120
+ subtotalBasketDiscountsAmount: number;
121
+ totalDiscountsAmount: number;
122
+ totalAmount: number;
123
+ price: PosOrderPriceDto;
124
+ }
125
+ declare function calculateItemPrice(details: {
126
+ basePriceInMinorUnit: number;
127
+ quantity: number;
128
+ taxRate: number;
129
+ options: CartOptionPayload[];
130
+ currency: CurrencyCode;
131
+ discount?: {
132
+ type: DiscountType;
133
+ value: number;
134
+ };
135
+ }): ItemPriceDto;
136
+ declare function calculateCartPriceSnapshot(details: {
137
+ items: readonly PosOrderItemDto[];
138
+ discounts: readonly InternalPosDiscount[];
139
+ currency: CurrencyCode;
140
+ }): CartPriceSnapshot;
141
+
142
+ interface TaxInclusiveSplitResult {
143
+ taxRate: number;
144
+ totalWithTax: number;
145
+ totalWithoutTax: number;
146
+ totalTax: number;
147
+ }
148
+ declare function splitTaxInclusiveAmount(totalWithTax: number, taxRate: number): TaxInclusiveSplitResult;
149
+ declare function calculateOrderTaxSummary(details: {
150
+ items: readonly PosOrderItemDto[];
151
+ discounts: readonly InternalPosDiscount[];
152
+ currency: CurrencyCode;
153
+ }): PosOrderDtoTaxSummary;
154
+
155
+ declare const VERSION = "0.1.0";
156
+
157
+ export { ApplyTo, Cart, type CartCreateOptions, type CartItemAddData, type CartOptionPayload, type CartPriceSnapshot, type DiscountStrategyFn, type InternalPosDiscount, type SequentialDiscountCalculation, type TaxInclusiveSplitResult, type UpdatableCartDetails, VERSION, allocateProportionalMinorUnits, calculateCartPriceSnapshot, calculateDiscountAmount, calculateItemPrice, calculateOrderTaxSummary, calculateSequentialDiscountTotal, splitTaxInclusiveAmount };
@@ -0,0 +1,157 @@
1
+ import { CurrencyCode, PosBusinessDto, OrderTypePOS, PosDiscountDto, PosOrderItemDto, LocatorType, OrderFormat, OrderRefundStatus, OrderStatusEnum, PosOrderDto, PosCustomerDto, PaymentRefundDto, InvoiceCompanyResponseDto, PosOrderPriceDto, KitchenStatus, PosPaymentStatus, TransactionDto, DiscountType, MoneyDto, ItemPriceDto, PosOrderDtoTaxSummary } from '@munchi_oy/core';
2
+
3
+ declare enum ApplyTo {
4
+ Order = "order",
5
+ Item = "item"
6
+ }
7
+ interface UpdatableCartDetails {
8
+ orderNumber?: string;
9
+ spotNumber?: string | null;
10
+ orderType?: OrderTypePOS;
11
+ comments?: string | null;
12
+ _locatorType?: LocatorType;
13
+ }
14
+ interface CartCreateOptions {
15
+ businessId: string;
16
+ currency: CurrencyCode;
17
+ business: PosBusinessDto;
18
+ orderNumber: string;
19
+ orderType?: OrderTypePOS;
20
+ createdAt?: Date;
21
+ staffId?: string | null;
22
+ shiftId?: string | null;
23
+ }
24
+ type CartItemAddData = Omit<PosOrderItemDto, "lineItemId" | "kitchenStatus" | "paymentStatus" | "discount">;
25
+ type InternalPosDiscount = Omit<PosDiscountDto, "createdAt"> & {
26
+ createdAt: string;
27
+ };
28
+
29
+ declare class Cart {
30
+ readonly id: string;
31
+ readonly businessId: string;
32
+ readonly currency: CurrencyCode;
33
+ readonly createdAt: Date;
34
+ orderNumber: string;
35
+ orderType: OrderTypePOS;
36
+ orderFormat: OrderFormat;
37
+ spotNumber: string | null;
38
+ comments: string | null;
39
+ orderRefundStatus: OrderRefundStatus;
40
+ updatedAt: Date;
41
+ status: OrderStatusEnum;
42
+ private _loyaltyTransactionIds;
43
+ private _loyaltyProgramId;
44
+ private _items;
45
+ private _locatorType;
46
+ private _business;
47
+ private _discounts;
48
+ private _customer;
49
+ private _refunds;
50
+ private _taxSummary;
51
+ private _newlyCancelledItemIds;
52
+ private _invoiceCompany;
53
+ private _staffId;
54
+ private _shiftId;
55
+ private version;
56
+ private constructor();
57
+ static create(options: CartCreateOptions): Cart;
58
+ static fromData(orderDto: PosOrderDto): Cart;
59
+ get items(): readonly PosOrderItemDto[];
60
+ get locatorType(): LocatorType;
61
+ get staffId(): string | null;
62
+ get shiftId(): string | null;
63
+ get discounts(): readonly InternalPosDiscount[];
64
+ get customer(): PosCustomerDto | null;
65
+ get refunds(): readonly PaymentRefundDto[];
66
+ get loyaltyProgramId(): string | null;
67
+ get loyaltyTransactionIds(): readonly string[];
68
+ get invoiceCompany(): InvoiceCompanyResponseDto | null;
69
+ get price(): PosOrderPriceDto;
70
+ setInvoiceCompany(company: InvoiceCompanyResponseDto | null): void;
71
+ addItem(itemData: CartItemAddData, requiresPrep?: boolean): void;
72
+ updateItem(lineItemId: string, updatedItem: PosOrderItemDto): void;
73
+ removeItem(lineItemId: string): void;
74
+ updateItemStatus(lineItemId: string, newStatus: KitchenStatus | PosPaymentStatus): void;
75
+ getNewlyCancelledItemIds(): string[];
76
+ clearCancellationTracking(): void;
77
+ applyDiscountToCart(discountData: Omit<PosDiscountDto, "scope" | "lineItemId" | "createdAt">): void;
78
+ applyDiscountToItem(lineItemId: string, discountData: Omit<PosDiscountDto, "scope" | "lineItemId" | "createdAt">): void;
79
+ removeItemDiscount(lineItemId: string): void;
80
+ removeDiscount(discountId: string): void;
81
+ setCustomer(customer: PosCustomerDto | null): void;
82
+ updateDetails(details: UpdatableCartDetails): void;
83
+ setComment(details: {
84
+ scope: ApplyTo;
85
+ comment: string | null;
86
+ lineItemId?: string;
87
+ }): void;
88
+ setStaffContext(staffId: string | null, shiftId: string | null): void;
89
+ updateOrderStatus(newStatus: OrderStatusEnum): void;
90
+ updateOrderFormat(newFormat: OrderFormat): void;
91
+ updateLoyaltyProgramId(id: string): void;
92
+ updateLoyaltyTransactionId(id: string): void;
93
+ setLoyaltyContext(customer: PosCustomerDto | null, loyaltyProgramId: string | null): void;
94
+ toJSON(paymentEvents?: TransactionDto[]): PosOrderDto;
95
+ clone(): Cart;
96
+ private calculateOrderTaxSummary;
97
+ private touch;
98
+ }
99
+
100
+ type DiscountStrategyFn = (value: number, totalAmount: number) => number;
101
+ declare function calculateDiscountAmount(type: DiscountType, value: number, totalAmountBeforeDiscounts: number): number;
102
+ interface SequentialDiscountCalculation {
103
+ totalDiscountAmount: number;
104
+ remainingAmount: number;
105
+ }
106
+ declare function calculateSequentialDiscountTotal(discounts: ReadonlyArray<Pick<InternalPosDiscount, "type" | "value">>, initialAmount: number): SequentialDiscountCalculation;
107
+
108
+ declare const allocateProportionalMinorUnits: (weights: number[], totalAmount: number) => number[];
109
+
110
+ interface CartOptionPayload {
111
+ suboptions: {
112
+ price: MoneyDto;
113
+ quantity: number;
114
+ }[];
115
+ }
116
+ interface CartPriceSnapshot {
117
+ activeItems: PosOrderItemDto[];
118
+ totalBeforeDiscountsAmount: number;
119
+ subtotalItemDiscountsAmount: number;
120
+ subtotalBasketDiscountsAmount: number;
121
+ totalDiscountsAmount: number;
122
+ totalAmount: number;
123
+ price: PosOrderPriceDto;
124
+ }
125
+ declare function calculateItemPrice(details: {
126
+ basePriceInMinorUnit: number;
127
+ quantity: number;
128
+ taxRate: number;
129
+ options: CartOptionPayload[];
130
+ currency: CurrencyCode;
131
+ discount?: {
132
+ type: DiscountType;
133
+ value: number;
134
+ };
135
+ }): ItemPriceDto;
136
+ declare function calculateCartPriceSnapshot(details: {
137
+ items: readonly PosOrderItemDto[];
138
+ discounts: readonly InternalPosDiscount[];
139
+ currency: CurrencyCode;
140
+ }): CartPriceSnapshot;
141
+
142
+ interface TaxInclusiveSplitResult {
143
+ taxRate: number;
144
+ totalWithTax: number;
145
+ totalWithoutTax: number;
146
+ totalTax: number;
147
+ }
148
+ declare function splitTaxInclusiveAmount(totalWithTax: number, taxRate: number): TaxInclusiveSplitResult;
149
+ declare function calculateOrderTaxSummary(details: {
150
+ items: readonly PosOrderItemDto[];
151
+ discounts: readonly InternalPosDiscount[];
152
+ currency: CurrencyCode;
153
+ }): PosOrderDtoTaxSummary;
154
+
155
+ declare const VERSION = "0.1.0";
156
+
157
+ export { ApplyTo, Cart, type CartCreateOptions, type CartItemAddData, type CartOptionPayload, type CartPriceSnapshot, type DiscountStrategyFn, type InternalPosDiscount, type SequentialDiscountCalculation, type TaxInclusiveSplitResult, type UpdatableCartDetails, VERSION, allocateProportionalMinorUnits, calculateCartPriceSnapshot, calculateDiscountAmount, calculateItemPrice, calculateOrderTaxSummary, calculateSequentialDiscountTotal, splitTaxInclusiveAmount };