@munchi_oy/cart-engine 0.1.4 → 0.1.5

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/index.cjs CHANGED
@@ -587,6 +587,7 @@ var Cart = class _Cart {
587
587
  _invoiceCompany;
588
588
  _staffId;
589
589
  _shiftId;
590
+ _aggregateMatchingItemsOnAdd;
590
591
  version = "1.0.2";
591
592
  constructor(id, createdAt, options) {
592
593
  this.id = id;
@@ -595,6 +596,7 @@ var Cart = class _Cart {
595
596
  this.provider = options.provider;
596
597
  this.orderType = options.orderType;
597
598
  this.orderNumber = options.orderNumber;
599
+ this._aggregateMatchingItemsOnAdd = options.aggregateMatchingItemsOnAdd;
598
600
  this.checkoutModel = options.checkoutModel;
599
601
  this._business = options.business;
600
602
  this.currency = options.currency;
@@ -620,6 +622,7 @@ var Cart = class _Cart {
620
622
  provider: options.provider ?? import_core4.ProviderEnum.MunchiPos,
621
623
  orderType: options.orderType ?? import_core4.OrderTypePOS.DineIn,
622
624
  orderNumber: options.orderNumber,
625
+ aggregateMatchingItemsOnAdd: options.aggregateMatchingItemsOnAdd ?? false,
623
626
  checkoutModel: options.checkoutModel ?? import_core4.CheckoutModelEnum.Full,
624
627
  tableService: options.tableService ?? null,
625
628
  equalSplitState: options.equalSplitState ?? null,
@@ -635,6 +638,7 @@ var Cart = class _Cart {
635
638
  provider: orderDto.provider,
636
639
  orderType: orderDto.orderType,
637
640
  orderNumber: orderDto.orderNumber,
641
+ aggregateMatchingItemsOnAdd: false,
638
642
  checkoutModel: orderDto.checkoutModel,
639
643
  tableService: orderDto.tableService ?? null,
640
644
  equalSplitState: orderDto.equalSplitState ?? null,
@@ -696,6 +700,9 @@ var Cart = class _Cart {
696
700
  get invoiceCompany() {
697
701
  return this._invoiceCompany;
698
702
  }
703
+ get aggregateMatchingItemsOnAdd() {
704
+ return this._aggregateMatchingItemsOnAdd;
705
+ }
699
706
  get guestCount() {
700
707
  return this._tableService?.seats ?? null;
701
708
  }
@@ -725,6 +732,9 @@ var Cart = class _Cart {
725
732
  this._invoiceCompany = company;
726
733
  this.touch();
727
734
  }
735
+ setAggregateMatchingItemsOnAdd(enabled) {
736
+ this._aggregateMatchingItemsOnAdd = enabled;
737
+ }
728
738
  addItem(itemData, requiresPrep = false) {
729
739
  const lockedStatuses = [
730
740
  import_core4.KitchenStatus.DispatchedToKitchen,
@@ -732,9 +742,9 @@ var Cart = class _Cart {
732
742
  import_core4.KitchenStatus.Completed,
733
743
  import_core4.KitchenStatus.Cancelled
734
744
  ];
735
- const existingModifiableItem = this._items.find(
745
+ const existingModifiableItem = this._aggregateMatchingItemsOnAdd ? this._items.find(
736
746
  (item) => item.posId === itemData.posId && isEqual(item.options, itemData.options) && item.comments === itemData.comments && !lockedStatuses.includes(item.kitchenStatus) && item.discount === null
737
- );
747
+ ) : void 0;
738
748
  if (existingModifiableItem) {
739
749
  this._items = this._items.map((item) => {
740
750
  if (item.lineItemId !== existingModifiableItem.lineItemId) {
@@ -757,13 +767,24 @@ var Cart = class _Cart {
757
767
  this.touch();
758
768
  return;
759
769
  }
760
- this._items.push({
761
- ...itemData,
762
- lineItemId: (0, import_cuid2.createId)(),
763
- kitchenStatus: requiresPrep ? import_core4.KitchenStatus.Pending : import_core4.KitchenStatus.NotApplicable,
764
- paymentStatus: import_core4.PosPaymentStatus.Unpaid,
765
- discount: null
766
- });
770
+ const quantityPerLine = this._aggregateMatchingItemsOnAdd ? [itemData.quantity] : Array.from({ length: itemData.quantity }, () => 1);
771
+ for (const quantity of quantityPerLine) {
772
+ this._items.push({
773
+ ...itemData,
774
+ quantity,
775
+ itemPrice: calculateItemPrice({
776
+ basePriceInMinorUnit: itemData.basePrice.amount,
777
+ quantity,
778
+ taxRate: itemData.taxRate,
779
+ options: itemData.options,
780
+ currency: this.currency
781
+ }),
782
+ lineItemId: (0, import_cuid2.createId)(),
783
+ kitchenStatus: requiresPrep ? import_core4.KitchenStatus.Pending : import_core4.KitchenStatus.NotApplicable,
784
+ paymentStatus: import_core4.PosPaymentStatus.Unpaid,
785
+ discount: null
786
+ });
787
+ }
767
788
  this.touch();
768
789
  }
769
790
  updateItem(lineItemId, updatedItem) {
@@ -1372,6 +1393,7 @@ var Cart = class _Cart {
1372
1393
  provider: this.provider,
1373
1394
  orderType: this.orderType,
1374
1395
  orderNumber: this.orderNumber,
1396
+ aggregateMatchingItemsOnAdd: this._aggregateMatchingItemsOnAdd,
1375
1397
  checkoutModel: this.checkoutModel,
1376
1398
  tableService: this._tableService,
1377
1399
  equalSplitState: this._equalSplitState,
@@ -1430,7 +1452,7 @@ var ApplyTo = /* @__PURE__ */ ((ApplyTo2) => {
1430
1452
  })(ApplyTo || {});
1431
1453
 
1432
1454
  // src/version.ts
1433
- var VERSION = "0.1.4";
1455
+ var VERSION = "0.1.5";
1434
1456
  // Annotate the CommonJS export names for ESM import in node:
1435
1457
  0 && (module.exports = {
1436
1458
  ApplyTo,
package/dist/index.d.cts CHANGED
@@ -16,6 +16,7 @@ interface CartCreateOptions {
16
16
  currency: CurrencyCode;
17
17
  business: PosBusinessDto;
18
18
  orderNumber: string;
19
+ aggregateMatchingItemsOnAdd?: boolean;
19
20
  orderType?: OrderTypePOS;
20
21
  provider?: ProviderEnum;
21
22
  checkoutModel?: CheckoutModelEnum;
@@ -60,6 +61,7 @@ declare class Cart {
60
61
  private _invoiceCompany;
61
62
  private _staffId;
62
63
  private _shiftId;
64
+ private _aggregateMatchingItemsOnAdd;
63
65
  private version;
64
66
  private constructor();
65
67
  static create(options: CartCreateOptions): Cart;
@@ -74,12 +76,14 @@ declare class Cart {
74
76
  get loyaltyProgramId(): string | null;
75
77
  get loyaltyTransactionIds(): readonly string[];
76
78
  get invoiceCompany(): InvoiceCompanyResponseDto | null;
79
+ get aggregateMatchingItemsOnAdd(): boolean;
77
80
  get guestCount(): number | null;
78
81
  get tableService(): PosOrderTableServiceDto | null;
79
82
  get equalSplitState(): PosOrderEqualSplitStateDto | null;
80
83
  get equalSplitPartCount(): number | null;
81
84
  get price(): PosOrderPriceDto;
82
85
  setInvoiceCompany(company: InvoiceCompanyResponseDto | null): void;
86
+ setAggregateMatchingItemsOnAdd(enabled: boolean): void;
83
87
  addItem(itemData: CartItemAddData, requiresPrep?: boolean): void;
84
88
  updateItem(lineItemId: string, updatedItem: PosOrderItemDto): void;
85
89
  removeItem(lineItemId: string): void;
@@ -240,6 +244,6 @@ declare function calculateOrderTaxSummary(details: {
240
244
  currency: CurrencyCode;
241
245
  }): PosOrderDtoTaxSummary;
242
246
 
243
- declare const VERSION = "0.1.4";
247
+ declare const VERSION = "0.1.5";
244
248
 
245
249
  export { ApplyTo, Cart, type CartCreateOptions, type CartItemAddData, type CartOptionPayload, type CartPriceSnapshot, type DiscountStrategyFn, type InternalPosDiscount, type SequentialDiscountCalculation, type SplitPricingResult, type SplitTargetAmount, type TaxInclusiveSplitResult, type UpdatableCartDetails, VERSION, allocateProportionalMinorUnits, calculateCartPriceSnapshot, calculateDiscountAmount, calculateEqualSplitPartPricing, calculateItemPrice, calculateItemSplitSeatPricing, calculateOrderTaxSummary, calculateSequentialDiscountTotal, splitTaxInclusiveAmount };
package/dist/index.d.ts CHANGED
@@ -16,6 +16,7 @@ interface CartCreateOptions {
16
16
  currency: CurrencyCode;
17
17
  business: PosBusinessDto;
18
18
  orderNumber: string;
19
+ aggregateMatchingItemsOnAdd?: boolean;
19
20
  orderType?: OrderTypePOS;
20
21
  provider?: ProviderEnum;
21
22
  checkoutModel?: CheckoutModelEnum;
@@ -60,6 +61,7 @@ declare class Cart {
60
61
  private _invoiceCompany;
61
62
  private _staffId;
62
63
  private _shiftId;
64
+ private _aggregateMatchingItemsOnAdd;
63
65
  private version;
64
66
  private constructor();
65
67
  static create(options: CartCreateOptions): Cart;
@@ -74,12 +76,14 @@ declare class Cart {
74
76
  get loyaltyProgramId(): string | null;
75
77
  get loyaltyTransactionIds(): readonly string[];
76
78
  get invoiceCompany(): InvoiceCompanyResponseDto | null;
79
+ get aggregateMatchingItemsOnAdd(): boolean;
77
80
  get guestCount(): number | null;
78
81
  get tableService(): PosOrderTableServiceDto | null;
79
82
  get equalSplitState(): PosOrderEqualSplitStateDto | null;
80
83
  get equalSplitPartCount(): number | null;
81
84
  get price(): PosOrderPriceDto;
82
85
  setInvoiceCompany(company: InvoiceCompanyResponseDto | null): void;
86
+ setAggregateMatchingItemsOnAdd(enabled: boolean): void;
83
87
  addItem(itemData: CartItemAddData, requiresPrep?: boolean): void;
84
88
  updateItem(lineItemId: string, updatedItem: PosOrderItemDto): void;
85
89
  removeItem(lineItemId: string): void;
@@ -240,6 +244,6 @@ declare function calculateOrderTaxSummary(details: {
240
244
  currency: CurrencyCode;
241
245
  }): PosOrderDtoTaxSummary;
242
246
 
243
- declare const VERSION = "0.1.4";
247
+ declare const VERSION = "0.1.5";
244
248
 
245
249
  export { ApplyTo, Cart, type CartCreateOptions, type CartItemAddData, type CartOptionPayload, type CartPriceSnapshot, type DiscountStrategyFn, type InternalPosDiscount, type SequentialDiscountCalculation, type SplitPricingResult, type SplitTargetAmount, type TaxInclusiveSplitResult, type UpdatableCartDetails, VERSION, allocateProportionalMinorUnits, calculateCartPriceSnapshot, calculateDiscountAmount, calculateEqualSplitPartPricing, calculateItemPrice, calculateItemSplitSeatPricing, calculateOrderTaxSummary, calculateSequentialDiscountTotal, splitTaxInclusiveAmount };
package/dist/index.js CHANGED
@@ -557,6 +557,7 @@ var Cart = class _Cart {
557
557
  _invoiceCompany;
558
558
  _staffId;
559
559
  _shiftId;
560
+ _aggregateMatchingItemsOnAdd;
560
561
  version = "1.0.2";
561
562
  constructor(id, createdAt, options) {
562
563
  this.id = id;
@@ -565,6 +566,7 @@ var Cart = class _Cart {
565
566
  this.provider = options.provider;
566
567
  this.orderType = options.orderType;
567
568
  this.orderNumber = options.orderNumber;
569
+ this._aggregateMatchingItemsOnAdd = options.aggregateMatchingItemsOnAdd;
568
570
  this.checkoutModel = options.checkoutModel;
569
571
  this._business = options.business;
570
572
  this.currency = options.currency;
@@ -590,6 +592,7 @@ var Cart = class _Cart {
590
592
  provider: options.provider ?? Provider.MunchiPos,
591
593
  orderType: options.orderType ?? OrderTypePOS.DineIn,
592
594
  orderNumber: options.orderNumber,
595
+ aggregateMatchingItemsOnAdd: options.aggregateMatchingItemsOnAdd ?? false,
593
596
  checkoutModel: options.checkoutModel ?? CheckoutModel.Full,
594
597
  tableService: options.tableService ?? null,
595
598
  equalSplitState: options.equalSplitState ?? null,
@@ -605,6 +608,7 @@ var Cart = class _Cart {
605
608
  provider: orderDto.provider,
606
609
  orderType: orderDto.orderType,
607
610
  orderNumber: orderDto.orderNumber,
611
+ aggregateMatchingItemsOnAdd: false,
608
612
  checkoutModel: orderDto.checkoutModel,
609
613
  tableService: orderDto.tableService ?? null,
610
614
  equalSplitState: orderDto.equalSplitState ?? null,
@@ -666,6 +670,9 @@ var Cart = class _Cart {
666
670
  get invoiceCompany() {
667
671
  return this._invoiceCompany;
668
672
  }
673
+ get aggregateMatchingItemsOnAdd() {
674
+ return this._aggregateMatchingItemsOnAdd;
675
+ }
669
676
  get guestCount() {
670
677
  return this._tableService?.seats ?? null;
671
678
  }
@@ -695,6 +702,9 @@ var Cart = class _Cart {
695
702
  this._invoiceCompany = company;
696
703
  this.touch();
697
704
  }
705
+ setAggregateMatchingItemsOnAdd(enabled) {
706
+ this._aggregateMatchingItemsOnAdd = enabled;
707
+ }
698
708
  addItem(itemData, requiresPrep = false) {
699
709
  const lockedStatuses = [
700
710
  KitchenStatus3.DispatchedToKitchen,
@@ -702,9 +712,9 @@ var Cart = class _Cart {
702
712
  KitchenStatus3.Completed,
703
713
  KitchenStatus3.Cancelled
704
714
  ];
705
- const existingModifiableItem = this._items.find(
715
+ const existingModifiableItem = this._aggregateMatchingItemsOnAdd ? this._items.find(
706
716
  (item) => item.posId === itemData.posId && isEqual(item.options, itemData.options) && item.comments === itemData.comments && !lockedStatuses.includes(item.kitchenStatus) && item.discount === null
707
- );
717
+ ) : void 0;
708
718
  if (existingModifiableItem) {
709
719
  this._items = this._items.map((item) => {
710
720
  if (item.lineItemId !== existingModifiableItem.lineItemId) {
@@ -727,13 +737,24 @@ var Cart = class _Cart {
727
737
  this.touch();
728
738
  return;
729
739
  }
730
- this._items.push({
731
- ...itemData,
732
- lineItemId: createId(),
733
- kitchenStatus: requiresPrep ? KitchenStatus3.Pending : KitchenStatus3.NotApplicable,
734
- paymentStatus: PosPaymentStatus.Unpaid,
735
- discount: null
736
- });
740
+ const quantityPerLine = this._aggregateMatchingItemsOnAdd ? [itemData.quantity] : Array.from({ length: itemData.quantity }, () => 1);
741
+ for (const quantity of quantityPerLine) {
742
+ this._items.push({
743
+ ...itemData,
744
+ quantity,
745
+ itemPrice: calculateItemPrice({
746
+ basePriceInMinorUnit: itemData.basePrice.amount,
747
+ quantity,
748
+ taxRate: itemData.taxRate,
749
+ options: itemData.options,
750
+ currency: this.currency
751
+ }),
752
+ lineItemId: createId(),
753
+ kitchenStatus: requiresPrep ? KitchenStatus3.Pending : KitchenStatus3.NotApplicable,
754
+ paymentStatus: PosPaymentStatus.Unpaid,
755
+ discount: null
756
+ });
757
+ }
737
758
  this.touch();
738
759
  }
739
760
  updateItem(lineItemId, updatedItem) {
@@ -1342,6 +1363,7 @@ var Cart = class _Cart {
1342
1363
  provider: this.provider,
1343
1364
  orderType: this.orderType,
1344
1365
  orderNumber: this.orderNumber,
1366
+ aggregateMatchingItemsOnAdd: this._aggregateMatchingItemsOnAdd,
1345
1367
  checkoutModel: this.checkoutModel,
1346
1368
  tableService: this._tableService,
1347
1369
  equalSplitState: this._equalSplitState,
@@ -1400,7 +1422,7 @@ var ApplyTo = /* @__PURE__ */ ((ApplyTo2) => {
1400
1422
  })(ApplyTo || {});
1401
1423
 
1402
1424
  // src/version.ts
1403
- var VERSION = "0.1.4";
1425
+ var VERSION = "0.1.5";
1404
1426
  export {
1405
1427
  ApplyTo,
1406
1428
  Cart,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@munchi_oy/cart-engine",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Headless settlement engine for Munchi POS, kiosk, and mobile flows",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,