@chopkola/common 1.0.184 → 1.0.187

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.
@@ -1,26 +1,10 @@
1
1
  import { CartItemTypeEnum, CartStatusEnum, CartTypeEnum } from "./enum/collection";
2
- import { MoneyString, Timestamps, UUID, Nullable } from "./global";
3
- import { SelectedModifierOption } from "./menu_n_meal";
4
- /**
5
- * PRODUCTION NOTE:
6
- * We assign a `vendor_id` and `cart_type` directly to the Cart.
7
- * In food delivery platforms (like UberEats/Instacart), you generally
8
- * cannot mix hot restaurant food and grocery items in the same checkout,
9
- * nor can you easily mix vendors. This enforces business rules at the DB level.
10
- */
11
- export interface Cart extends Timestamps {
12
- id: UUID;
13
- user_id: Nullable<UUID>;
14
- session_id: string;
15
- cart_type: CartTypeEnum;
16
- status: CartStatusEnum;
17
- expires_at: Date;
18
- total_items: number;
19
- subtotal: MoneyString;
2
+ import { MoneyString, Timestamps, UUID, Nullable, DateString, TimeString } from "./global";
3
+ export interface CartSelectedModifierOption {
4
+ modifier_group_id: UUID;
5
+ modifier_option_id: UUID;
6
+ quantity: number;
20
7
  }
21
- /**
22
- * Base fields shared by ALL cart items
23
- */
24
8
  export interface BaseCartItem extends Timestamps {
25
9
  id: UUID;
26
10
  cart_id: UUID;
@@ -29,13 +13,9 @@ export interface BaseCartItem extends Timestamps {
29
13
  unit_price: MoneyString;
30
14
  total_price: MoneyString;
31
15
  }
32
- /**
33
- * MEAL CART ITEM (Restaurant)
34
- * Requires exact knowledge of which modifiers the user selected.
35
- */
36
16
  export interface MealCartItemMetadata {
37
17
  special_instructions: Nullable<string>;
38
- selected_options: SelectedModifierOption[];
18
+ selected_options: CartSelectedModifierOption[];
39
19
  }
40
20
  export interface MealCartItem extends BaseCartItem {
41
21
  item_type: CartItemTypeEnum.MEAL;
@@ -45,10 +25,6 @@ export interface MealCartItem extends BaseCartItem {
45
25
  inventory_item_id: null;
46
26
  metadata: MealCartItemMetadata;
47
27
  }
48
- /**
49
- * PRODUCT CART ITEM (Grocery/Retail)
50
- * Requires exact knowledge of the Inventory Item to reserve stock.
51
- */
52
28
  export interface ProductCartItemMetadata {
53
29
  special_instructions: Nullable<string>;
54
30
  accepts_substitutions: boolean;
@@ -61,38 +37,44 @@ export interface ProductCartItem extends BaseCartItem {
61
37
  inventory_item_id: UUID;
62
38
  metadata: ProductCartItemMetadata;
63
39
  }
64
- /**
65
- * 🚀 FINAL CART ITEM UNION
66
- * DB constraint: Item is either a Meal OR a Product.
67
- */
68
- export type CartItem = MealCartItem | ProductCartItem;
69
- /**
70
- * Used for the frontend Cart Page view.
71
- * Contains the Cart and an array of fully populated items.
72
- */
73
- export interface CartAggregate extends Cart {
74
- items: CartItem[];
40
+ export interface ReservationCartItemMetadata {
41
+ reservation_date: DateString;
42
+ reservation_time: TimeString;
43
+ party_size: number;
44
+ special_requests: Nullable<string>;
45
+ }
46
+ export interface ReservationCartItem extends BaseCartItem {
47
+ item_type: CartItemTypeEnum.RESERVATION;
48
+ meal_id: null;
49
+ product_id: null;
50
+ product_variant_id: null;
51
+ inventory_item_id: null;
52
+ metadata: ReservationCartItemMetadata;
53
+ }
54
+ export type CartItem = MealCartItem | ProductCartItem | ReservationCartItem;
55
+ export interface BaseCart<T extends CartItem> extends Timestamps {
56
+ id: UUID;
57
+ user_id: Nullable<UUID>;
58
+ session_id: string;
59
+ cart_type: CartTypeEnum;
60
+ vendor_id: UUID;
61
+ status: CartStatusEnum;
62
+ expires_at: Date;
63
+ total_items: number;
64
+ subtotal: MoneyString;
65
+ items: T[];
66
+ }
67
+ export interface RestaurantCart extends BaseCart<MealCartItem | ReservationCartItem> {
68
+ cart_type: CartTypeEnum.RESTAURANT;
69
+ delivery_fee_estimate?: MoneyString;
75
70
  tax_estimate?: MoneyString;
71
+ total_estimate?: MoneyString;
72
+ }
73
+ export interface GroceryCart extends BaseCart<ProductCartItem> {
74
+ cart_type: CartTypeEnum.GROCERY;
75
+ bag_fee_estimate?: MoneyString;
76
76
  delivery_fee_estimate?: MoneyString;
77
+ tax_estimate?: MoneyString;
77
78
  total_estimate?: MoneyString;
78
79
  }
79
- /** Base fields required from the frontend to add an item */
80
- type BaseAddToCartInput = {
81
- cart_id: UUID;
82
- quantity: number;
83
- };
84
- export type AddMealToCartInput = BaseAddToCartInput & {
85
- item_type: CartItemTypeEnum.MEAL;
86
- meal_id: UUID;
87
- metadata: MealCartItemMetadata;
88
- };
89
- export type AddProductToCartInput = BaseAddToCartInput & {
90
- item_type: CartItemTypeEnum.PRODUCT;
91
- product_id: UUID;
92
- product_variant_id?: UUID;
93
- inventory_item_id: UUID;
94
- metadata: ProductCartItemMetadata;
95
- };
96
- /** Frontend payload type for "Add To Cart" requests */
97
- export type AddToCartInput = AddMealToCartInput | AddProductToCartInput;
98
- export {};
80
+ export type CartAggregate = RestaurantCart | GroceryCart;
@@ -1,2 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ // function renderCart(cart: CartAggregate) {
4
+ // if (cart.cart_type === CartTypeEnum.RESTAURANT) {
5
+ // // TypeScript KNOWS this is a RestaurantCart.
6
+ // // It will auto-complete `meal_id` and `party_size` but throw an error if you type `product_id`.
7
+ // cart.items.forEach(item => {
8
+ // if (item.item_type === CartItemTypeEnum.MEAL) {
9
+ // console.log(item.meal_id); // ✅ Works
10
+ // }
11
+ // });
12
+ // }
13
+ // if (cart.cart_type === CartTypeEnum.GROCERY) {
14
+ // // TypeScript KNOWS this is a GroceryCart.
15
+ // // It will auto-complete `inventory_item_id`.
16
+ // cart.items.forEach(item => {
17
+ // console.log(item.inventory_item_id); // ✅ Works
18
+ // })
19
+ // }
20
+ // }
@@ -109,7 +109,8 @@ export declare enum CartTypeEnum {
109
109
  }
110
110
  export declare enum CartItemTypeEnum {
111
111
  MEAL = "meal",
112
- PRODUCT = "product"
112
+ PRODUCT = "product",
113
+ RESERVATION = "reservation"
113
114
  }
114
115
  export declare enum CartStatusEnum {
115
116
  ACTIVE = "active",
@@ -132,6 +132,7 @@ var CartItemTypeEnum;
132
132
  (function (CartItemTypeEnum) {
133
133
  CartItemTypeEnum["MEAL"] = "meal";
134
134
  CartItemTypeEnum["PRODUCT"] = "product";
135
+ CartItemTypeEnum["RESERVATION"] = "reservation";
135
136
  })(CartItemTypeEnum || (exports.CartItemTypeEnum = CartItemTypeEnum = {}));
136
137
  var CartStatusEnum;
137
138
  (function (CartStatusEnum) {
@@ -10,6 +10,10 @@ export type DecimalString = string & {
10
10
  };
11
11
  export type MoneyString = DecimalString;
12
12
  export type QuantityString = DecimalString;
13
+ /** ISO 8601 date string e.g. "2023-10-27" */
14
+ export type DateString = string & {
15
+ readonly __brand: "DateString";
16
+ };
13
17
  /** ISO 8601 time string e.g. "17:00" */
14
18
  export type TimeString = string & {
15
19
  readonly __brand: "TimeString";
@@ -69,6 +69,8 @@ export interface MenuWithMeals extends Menu {
69
69
  meals: (MealWithModifiers & {
70
70
  sort_order: number;
71
71
  })[];
72
+ today_order_items_count?: number;
73
+ all_time_order_items_count?: number;
72
74
  }
73
75
  export interface SelectedModifierOption {
74
76
  modifier_group_id: UUID;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chopkola/common",
3
- "version": "1.0.184",
3
+ "version": "1.0.187",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "akrosoft technology ltd",