@final-commerce/command-frame 0.8.0-online.4 → 0.8.0-preprod.1

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.
Files changed (102) hide show
  1. package/dist/CommonTypes.d.ts +26 -1
  2. package/dist/actions/add-booking-to-cart/action.d.ts +6 -0
  3. package/dist/actions/add-booking-to-cart/action.js +8 -0
  4. package/dist/actions/add-booking-to-cart/mock.d.ts +2 -0
  5. package/dist/actions/add-booking-to-cart/mock.js +66 -0
  6. package/dist/actions/add-booking-to-cart/types.d.ts +27 -0
  7. package/dist/actions/cancel-booking/action.d.ts +6 -0
  8. package/dist/actions/cancel-booking/action.js +8 -0
  9. package/dist/actions/cancel-booking/mock.d.ts +2 -0
  10. package/dist/actions/cancel-booking/mock.js +31 -0
  11. package/dist/actions/cancel-booking/types.d.ts +14 -0
  12. package/dist/actions/get-booking-availability/action.d.ts +6 -0
  13. package/dist/actions/get-booking-availability/action.js +8 -0
  14. package/dist/actions/get-booking-availability/mock.d.ts +2 -0
  15. package/dist/actions/get-booking-availability/mock.js +12 -0
  16. package/dist/actions/get-booking-availability/types.d.ts +37 -0
  17. package/dist/actions/get-booking-resources/action.d.ts +6 -0
  18. package/dist/actions/get-booking-resources/action.js +8 -0
  19. package/dist/actions/get-booking-resources/mock.d.ts +2 -0
  20. package/dist/actions/get-booking-resources/mock.js +7 -0
  21. package/dist/actions/get-booking-resources/types.d.ts +16 -0
  22. package/dist/actions/get-booking-resources/types.js +1 -0
  23. package/dist/actions/get-bookings/action.d.ts +6 -0
  24. package/dist/actions/get-bookings/action.js +8 -0
  25. package/dist/actions/get-bookings/mock.d.ts +2 -0
  26. package/dist/actions/get-bookings/mock.js +20 -0
  27. package/dist/actions/get-bookings/types.d.ts +22 -0
  28. package/dist/actions/get-bookings/types.js +1 -0
  29. package/dist/actions/get-context/mock.js +4 -0
  30. package/dist/actions/get-product-modifier-selections/action.d.ts +1 -1
  31. package/dist/actions/get-product-modifier-selections/action.js +2 -2
  32. package/dist/actions/get-product-modifier-selections/mock.d.ts +1 -1
  33. package/dist/actions/get-product-modifier-selections/mock.js +5 -5
  34. package/dist/actions/get-product-modifier-selections/types.d.ts +1 -1
  35. package/dist/actions/get-products/mock.js +6 -0
  36. package/dist/actions/get-products/types.d.ts +25 -3
  37. package/dist/actions/get-refund-plan/types.d.ts +5 -2
  38. package/dist/actions/get-remaining-refundable-quantities/mock.js +1 -0
  39. package/dist/actions/get-remaining-refundable-quantities/types.d.ts +8 -0
  40. package/dist/actions/hold-booking/action.d.ts +6 -0
  41. package/dist/actions/hold-booking/action.js +8 -0
  42. package/dist/actions/hold-booking/mock.d.ts +2 -0
  43. package/dist/actions/hold-booking/mock.js +37 -0
  44. package/dist/actions/hold-booking/types.d.ts +28 -0
  45. package/dist/actions/hold-booking/types.js +1 -0
  46. package/dist/actions/process-partial-refund/types.d.ts +2 -2
  47. package/dist/actions/remove-booking-from-cart/action.d.ts +6 -0
  48. package/dist/actions/remove-booking-from-cart/action.js +8 -0
  49. package/dist/actions/remove-booking-from-cart/mock.d.ts +2 -0
  50. package/dist/actions/remove-booking-from-cart/mock.js +40 -0
  51. package/dist/actions/remove-booking-from-cart/types.d.ts +16 -0
  52. package/dist/actions/remove-booking-from-cart/types.js +1 -0
  53. package/dist/actions/set-product-modifier-selections/action.d.ts +1 -1
  54. package/dist/actions/set-product-modifier-selections/action.js +2 -2
  55. package/dist/actions/set-product-modifier-selections/mock.d.ts +1 -1
  56. package/dist/actions/set-product-modifier-selections/mock.js +7 -7
  57. package/dist/actions/set-product-modifier-selections/types.d.ts +2 -2
  58. package/dist/demo/database.d.ts +18 -1
  59. package/dist/demo/database.js +183 -0
  60. package/dist/index.d.ts +16 -6
  61. package/dist/index.js +15 -5
  62. package/dist/projects/render/mocks.js +14 -4
  63. package/dist/projects/render/types.d.ts +8 -13
  64. package/dist/pubsub/topics/bookings/booking-created/types.d.ts +6 -0
  65. package/dist/pubsub/topics/bookings/booking-created/types.js +1 -0
  66. package/dist/pubsub/topics/bookings/booking-setup-changed/types.d.ts +15 -0
  67. package/dist/pubsub/topics/bookings/booking-setup-changed/types.js +1 -0
  68. package/dist/pubsub/topics/bookings/booking-updated/types.d.ts +6 -0
  69. package/dist/pubsub/topics/bookings/booking-updated/types.js +1 -0
  70. package/dist/pubsub/topics/bookings/index.d.ts +3 -0
  71. package/dist/pubsub/topics/bookings/index.js +27 -0
  72. package/dist/pubsub/topics/bookings/types.d.ts +8 -0
  73. package/dist/pubsub/topics/bookings/types.js +3 -0
  74. package/dist/pubsub/topics/cart/product-modifiers-updated/types.d.ts +2 -2
  75. package/dist/pubsub/topics/cart/types.d.ts +33 -33
  76. package/dist/pubsub/topics/cart/types.js +16 -16
  77. package/dist/pubsub/topics/index.d.ts +17 -17
  78. package/dist/pubsub/topics/index.js +17 -17
  79. package/dist/pubsub/topics/types.d.ts +2 -8
  80. package/package.json +5 -2
  81. package/dist/actions/resume-checkout/action.d.ts +0 -6
  82. package/dist/actions/resume-checkout/action.js +0 -8
  83. package/dist/actions/resume-checkout/mock.d.ts +0 -16
  84. package/dist/actions/resume-checkout/mock.js +0 -51
  85. package/dist/actions/resume-checkout/types.d.ts +0 -59
  86. package/dist/actions/resume-checkout/types.js +0 -13
  87. package/dist/actions/start-checkout/action.d.ts +0 -6
  88. package/dist/actions/start-checkout/action.js +0 -8
  89. package/dist/actions/start-checkout/mock.d.ts +0 -16
  90. package/dist/actions/start-checkout/mock.js +0 -80
  91. package/dist/actions/start-checkout/types.d.ts +0 -81
  92. package/dist/actions/start-checkout/types.js +0 -10
  93. package/dist/pubsub/topics/checkout/checkout-started/types.d.ts +0 -26
  94. package/dist/pubsub/topics/checkout/index.d.ts +0 -7
  95. package/dist/pubsub/topics/checkout/index.js +0 -28
  96. package/dist/pubsub/topics/checkout/payment-completed/types.d.ts +0 -31
  97. package/dist/pubsub/topics/checkout/payment-failed/types.d.ts +0 -20
  98. package/dist/pubsub/topics/checkout/types.d.ts +0 -12
  99. package/dist/pubsub/topics/checkout/types.js +0 -8
  100. /package/dist/{pubsub/topics/checkout/checkout-started → actions/add-booking-to-cart}/types.js +0 -0
  101. /package/dist/{pubsub/topics/checkout/payment-completed → actions/cancel-booking}/types.js +0 -0
  102. /package/dist/{pubsub/topics/checkout/payment-failed → actions/get-booking-availability}/types.js +0 -0
@@ -0,0 +1,37 @@
1
+ import { MOCK_BOOKINGS, MOCK_BOOKING_RESOURCES, mockLiveBookings } from '../../demo/database';
2
+ import { ReservationStatus } from '@final-commerce/common';
3
+ const BUFFER_MINUTES = 5;
4
+ const HOLD_MINUTES = 10;
5
+ let held = 0;
6
+ export const mockHoldBooking = async (params) => {
7
+ console.log('[Mock] holdBooking called', params);
8
+ const startAt = new Date(params.startAt);
9
+ const endAt = new Date(params.endAt);
10
+ const bufferEndAt = new Date(endAt.getTime() + BUFFER_MINUTES * 60000);
11
+ // The mock refuses a taken window like the host does. A mock that always said yes would
12
+ // let a booking screen ship without ever handling the one error it will actually meet.
13
+ const clash = mockLiveBookings().some((entry) => entry.resourceId === params.resourceId &&
14
+ new Date(entry.startAt) < bufferEndAt &&
15
+ new Date(entry.bufferEndAt) > startAt);
16
+ if (clash) {
17
+ return { success: false, reason: 'That window has just been taken — pick another slot.', timestamp: new Date().toISOString() };
18
+ }
19
+ const booking = {
20
+ // A counter, not a clock: two holds in the same millisecond used to share an id, and cancel
21
+ // or remove then acted on the wrong row. Scripted tests hit that routinely.
22
+ id: `bk_mock_${(held += 1)}`,
23
+ productId: params.productId,
24
+ resourceId: params.resourceId,
25
+ variantId: params.variantId,
26
+ startAt: startAt.toISOString(),
27
+ endAt: endAt.toISOString(),
28
+ bufferEndAt: bufferEndAt.toISOString(),
29
+ customerId: params.customerId,
30
+ status: ReservationStatus.HELD,
31
+ expiresAt: new Date(Date.now() + HOLD_MINUTES * 60000).toISOString(),
32
+ resourceName: MOCK_BOOKING_RESOURCES.find(({ id }) => id === params.resourceId)?.name,
33
+ };
34
+ // Held in the same list availability reads, so the slot really does disappear.
35
+ MOCK_BOOKINGS.push(booking);
36
+ return { success: true, booking, timestamp: new Date().toISOString() };
37
+ };
@@ -0,0 +1,28 @@
1
+ import { CFBooking } from '../../CommonTypes';
2
+ export interface HoldBookingParams {
3
+ productId: string;
4
+ /** Which resource serves it: a member of staff, a room, a scooter. */
5
+ resourceId: string;
6
+ /** Must be the START of a slot the host offered, ISO 8601. */
7
+ startAt: string;
8
+ /**
9
+ * End of the window — the `endAt` of the slot you picked, or of the last slot in a stay.
10
+ * Required: a window that cannot be lined up with the grid is refused, and the till
11
+ * has no local copy of the rules to derive it from.
12
+ */
13
+ endAt: string;
14
+ /** The variant being sold, when the flow already knows which one. */
15
+ variantId?: string;
16
+ /** Whom the booking is for. Omit for a walk-in. */
17
+ customerId?: string;
18
+ }
19
+ export interface HoldBookingResponse {
20
+ /** False when the command was refused — a taken window, a rule, a booking that is not yours. */
21
+ success: boolean;
22
+ /** Why it was refused, in words a cashier can act on. Absent on success. */
23
+ reason?: string;
24
+ /** The claim. `expiresAt` says how long it survives unpaid; `id` is what you confirm or cancel. */
25
+ booking?: CFBooking;
26
+ timestamp: string;
27
+ }
28
+ export type HoldBooking = (params: HoldBookingParams) => Promise<HoldBookingResponse>;
@@ -0,0 +1 @@
1
+ export {};
@@ -131,10 +131,10 @@ export interface ProcessPartialRefundParams {
131
131
  };
132
132
  /** Optional items to refund. */
133
133
  items?: {
134
- /** internalId or variantId or customSaleId. */
134
+ /** internalId or variantId, customSaleId, or a booking's own internalId. */
135
135
  itemKey: string;
136
136
  quantity: number;
137
- type?: 'product' | 'customSale' | 'fee' | 'tip';
137
+ type?: 'product' | 'customSale' | 'fee' | 'tip' | 'reservation';
138
138
  /**
139
139
  * Per-item stock disposition for a refunded **product** line — the
140
140
  * headless equivalent of the old refund popup's per-row restock/damaged
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Remove booking from cart action
3
+ * Calls the removeBookingFromCart action on the parent window
4
+ */
5
+ import type { RemoveBookingFromCart } from './types';
6
+ export declare const removeBookingFromCart: RemoveBookingFromCart;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Remove booking from cart action
3
+ * Calls the removeBookingFromCart action on the parent window
4
+ */
5
+ import { commandFrameClient } from '../../client';
6
+ export const removeBookingFromCart = async (params) => {
7
+ return await commandFrameClient.call('removeBookingFromCart', params);
8
+ };
@@ -0,0 +1,2 @@
1
+ import { RemoveBookingFromCart } from './types';
2
+ export declare const mockRemoveBookingFromCart: RemoveBookingFromCart;
@@ -0,0 +1,40 @@
1
+ import { ReservationStatus } from '@final-commerce/common';
2
+ import { MOCK_BOOKINGS, MOCK_CART, mockPublishEvent } from '../../demo/database';
3
+ export const mockRemoveBookingFromCart = async (params) => {
4
+ console.log('[Mock] removeBookingFromCart called', params);
5
+ const reservations = MOCK_CART.reservations ?? [];
6
+ const cartIndex = reservations.findIndex(({ internalId }) => internalId === params.reservationInternalId);
7
+ const [removed] = cartIndex >= 0 ? reservations.splice(cartIndex, 1) : [];
8
+ if (removed) {
9
+ const line = removed.total || removed.price * (removed.quantity ?? 1);
10
+ MOCK_CART.subtotal -= line;
11
+ MOCK_CART.total -= line;
12
+ MOCK_CART.amountToBeCharged = MOCK_CART.total;
13
+ MOCK_CART.remainingBalance = MOCK_CART.total;
14
+ mockPublishEvent('cart', 'cart-created', { cart: MOCK_CART });
15
+ }
16
+ // The hold has to go back, or the mock is a trap: `addBookingToCart` pushes into the very list
17
+ // availability reads, so add → remove → add the same slot used to refuse forever with "that
18
+ // window has just been taken". The reservation id is `res_<booking.id>`, the link back to the row.
19
+ const bookingId = removed?.bookingId ?? params.reservationInternalId.replace(/^res_/, '');
20
+ // CANCELLED, not deleted — the host releases a window by moving the row, and a mock that
21
+ // erased it hid both the trail and the fact that a released booking is still a booking.
22
+ const released = MOCK_BOOKINGS.find(({ id }) => id === bookingId);
23
+ if (released)
24
+ released.status = ReservationStatus.CANCELLED;
25
+ // An id the cart does not have is a refusal, as it is on the host — resolving with an empty
26
+ // booking made a failed remove look like a successful one.
27
+ if (!removed) {
28
+ return {
29
+ success: false,
30
+ reason: `Reservation ${params.reservationInternalId} is not in the cart`,
31
+ timestamp: new Date().toISOString(),
32
+ };
33
+ }
34
+ return {
35
+ success: true,
36
+ reservationInternalId: params.reservationInternalId,
37
+ booking: released,
38
+ timestamp: new Date().toISOString(),
39
+ };
40
+ };
@@ -0,0 +1,16 @@
1
+ import { CFBooking } from '../../CommonTypes';
2
+ export interface RemoveBookingFromCartParams {
3
+ /** The reservation's own id, as `addBookingToCart` returned it. */
4
+ reservationInternalId: string;
5
+ }
6
+ export interface RemoveBookingFromCartResponse {
7
+ /** False when the command was refused — a taken window, a rule, a booking that is not yours. */
8
+ success: boolean;
9
+ /** Why it was refused, in words a cashier can act on. Absent on success. */
10
+ reason?: string;
11
+ reservationInternalId?: string;
12
+ /** The released hold, so the caller can see it is no longer held. */
13
+ booking?: CFBooking;
14
+ timestamp: string;
15
+ }
16
+ export type RemoveBookingFromCart = (params: RemoveBookingFromCartParams) => Promise<RemoveBookingFromCartResponse>;
@@ -0,0 +1 @@
1
+ export {};
@@ -2,5 +2,5 @@
2
2
  * Set product modifier selections action
3
3
  * Calls the setProductModifierSelections action on the parent window
4
4
  */
5
- import type { SetProductModifierSelections } from "./types";
5
+ import type { SetProductModifierSelections } from './types';
6
6
  export declare const setProductModifierSelections: SetProductModifierSelections;
@@ -2,7 +2,7 @@
2
2
  * Set product modifier selections action
3
3
  * Calls the setProductModifierSelections action on the parent window
4
4
  */
5
- import { commandFrameClient } from "../../client";
5
+ import { commandFrameClient } from '../../client';
6
6
  export const setProductModifierSelections = async (params) => {
7
- return await commandFrameClient.call("setProductModifierSelections", params);
7
+ return await commandFrameClient.call('setProductModifierSelections', params);
8
8
  };
@@ -1,2 +1,2 @@
1
- import { SetProductModifierSelections } from "./types";
1
+ import { SetProductModifierSelections } from './types';
2
2
  export declare const mockSetProductModifierSelections: SetProductModifierSelections;
@@ -1,15 +1,15 @@
1
- import { MOCK_CART, MOCK_PRODUCTS, buildCartLineModifiers, buildModifierRows } from "../../demo/database";
1
+ import { MOCK_CART, MOCK_PRODUCTS, buildCartLineModifiers, buildModifierRows } from '../../demo/database';
2
2
  export const mockSetProductModifierSelections = async (params) => {
3
- console.log("[Mock] setProductModifierSelections called", params);
3
+ console.log('[Mock] setProductModifierSelections called', params);
4
4
  if (!params?.selections) {
5
5
  return {
6
6
  success: false,
7
- reason: "selections is required (pass [] to clear)",
7
+ reason: 'selections is required (pass [] to clear)',
8
8
  internalId: params?.internalId,
9
9
  selections: [],
10
10
  rows: [],
11
11
  modifiersTotal: 0,
12
- timestamp: new Date().toISOString()
12
+ timestamp: new Date().toISOString(),
13
13
  };
14
14
  }
15
15
  // Write the selections onto the mock cart line (last line when no internalId).
@@ -22,12 +22,12 @@ export const mockSetProductModifierSelections = async (params) => {
22
22
  if (!line) {
23
23
  return {
24
24
  success: false,
25
- reason: "No matching cart line",
25
+ reason: 'No matching cart line',
26
26
  internalId: params.internalId,
27
27
  selections: [],
28
28
  rows: [],
29
29
  modifiersTotal: 0,
30
- timestamp: new Date().toISOString()
30
+ timestamp: new Date().toISOString(),
31
31
  };
32
32
  }
33
33
  // Full replacement — passing [] clears the rows. The line drops the product's resolved
@@ -44,6 +44,6 @@ export const mockSetProductModifierSelections = async (params) => {
44
44
  selections: params.selections,
45
45
  rows,
46
46
  modifiersTotal,
47
- timestamp: new Date().toISOString()
47
+ timestamp: new Date().toISOString(),
48
48
  };
49
49
  };
@@ -1,5 +1,5 @@
1
- import type { ModifierSelection } from "../get-product-modifier-selections/types";
2
- import type { CFProdModifierBreakdown } from "../../CommonTypes";
1
+ import type { ModifierSelection } from '../get-product-modifier-selections/types';
2
+ import type { CFProdModifierBreakdown } from '../../CommonTypes';
3
3
  export interface SetProductModifierSelectionsParams {
4
4
  /** The cart line to edit. Defaults to the active product's line. */
5
5
  internalId?: string;
@@ -2,7 +2,7 @@
2
2
  * Mock Database for Standalone/Demo Mode
3
3
  * Stores mock data that mimics the Render environment
4
4
  */
5
- import { CFActiveCompany, CFActiveUser, CFActiveStation, CFActiveOutlet, CFActiveOrder, CFCustomer, CFProduct, CFActiveCart, CFCategory, CFActiveProduct, CFSession, CFActiveRefundDetails, CFSmartGridLayout, CFCartLineModifier, CFProdModifierBreakdown, CFModifierSelection, CFResolvedModifier } from '../CommonTypes';
5
+ import { CFActiveCompany, CFActiveUser, CFActiveStation, CFActiveOutlet, CFActiveOrder, CFCustomer, CFProduct, CFActiveCart, CFCategory, CFActiveProduct, CFSession, CFActiveRefundDetails, CFSmartGridLayout, CFBooking, CFBookingAvailability, CFBookingResource, CFCartLineModifier, CFProdModifierBreakdown, CFModifierSelection, CFResolvedModifier } from '../CommonTypes';
6
6
  export * from './mocks';
7
7
  /** Replace mock catalog / context data in place (same array references mock handlers use). */
8
8
  export interface MockDatabaseConfig {
@@ -15,6 +15,10 @@ export interface MockDatabaseConfig {
15
15
  products?: CFProduct[];
16
16
  orders?: CFActiveOrder[];
17
17
  parkedOrders?: CFActiveOrder[];
18
+ /** Who is scarce: the staff, rooms or machines the dataset's services are booked against. */
19
+ bookingResources?: CFBookingResource[];
20
+ /** Windows already taken when the dataset loads, so a calendar does not open empty. */
21
+ bookings?: CFBooking[];
18
22
  }
19
23
  export declare const MOCK_COMPANY: CFActiveCompany;
20
24
  export declare const MOCK_OUTLET_MAIN: CFActiveOutlet;
@@ -59,6 +63,7 @@ export declare const MOCK_STATIONS: import("@final-commerce/common/pos-types").A
59
63
  export declare const MOCK_OUTLETS: import("@final-commerce/common/pos-types").ActiveOutlet[];
60
64
  export declare const MOCK_CUSTOMERS: import("@final-commerce/common/pos-types").ActiveCustomer[];
61
65
  export declare const MOCK_CATEGORIES: import("@final-commerce/common/pos-types").Category[];
66
+ export declare const MOCK_PRODUCT_HAIRCUT: CFProduct;
62
67
  export declare const MOCK_PRODUCTS: import("@final-commerce/common/pos-types").FullProduct[];
63
68
  export declare const MOCK_ORDERS: import("@final-commerce/common/pos-types").ActiveOrder[];
64
69
  export declare const MOCK_PARKED_ORDERS: CFActiveOrder[];
@@ -87,6 +92,18 @@ export declare const createOrderFromCart: (paymentType: string, amount: number,
87
92
  * open with `amountToBeCharged` reset to what's left, and returns null.
88
93
  */
89
94
  export declare const applyMockPayment: (amount: number, paymentType: string, processor?: string) => CFActiveOrder | null;
95
+ export declare const MOCK_BOOKING_RULES_ID = "rule_salon_30";
96
+ export declare const MOCK_BOOKING_RESOURCES: CFBookingResource[];
97
+ /**
98
+ * The clock this mock shop keeps — the same one `getContext` reports. They used to disagree: the
99
+ * slot hours were built with `setHours`, which is the MACHINE's clock, while the context claimed
100
+ * Vancouver. On a machine in Paris a correct screen showed a salon open from midnight to nine.
101
+ */
102
+ export declare const MOCK_SHOP_TIME_ZONE = "America/Vancouver";
103
+ export declare const MOCK_BOOKINGS: CFBooking[];
104
+ /** Live = confirmed, or held and not yet expired. An expired hold occupies nothing. */
105
+ export declare const mockLiveBookings: () => CFBooking[];
106
+ export declare const mockBookingAvailability: (productId: string, from: Date, to: Date, resourceId?: string) => CFBookingAvailability;
90
107
  /**
91
108
  * Price the cashier's raw modifier answers into the rows a CART line carries (FT-0010).
92
109
  *
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import { CFProductType, CFUserTypes, CurrencyCode, } from '../CommonTypes';
6
6
  import { extendPrice, resolveUnit, toBase } from '@final-commerce/common';
7
+ import { BookingRatePeriod, BookingResourceKind, BookingType, ReservationStatus } from '@final-commerce/common';
7
8
  export * from './mocks';
8
9
  // Asset Imports - Using Remote URLs to avoid build complexity with asset copying
9
10
  const ASSETS_BASE_URL = 'https://raw.githubusercontent.com/Final-Commerce/command-frame/refs/heads/main/src/demo/assets';
@@ -649,6 +650,14 @@ export const MOCK_CATEGORIES = [
649
650
  MOCK_CATEGORY_VEGAN,
650
651
  MOCK_CATEGORY_SPICY,
651
652
  ];
653
+ // A service, not a thing on a shelf: no stock, sold as a slot of somebody's time.
654
+ // `bookingRulesId` is what tells a catalogue screen to ask for slots instead of stock.
655
+ export const MOCK_PRODUCT_HAIRCUT = {
656
+ ...createSimpleProduct('prod_haircut', 'Haircut', 4500, '', [MOCK_CATEGORY_SPECIALTY], 'Cut and finish, 30 minutes.'),
657
+ images: [],
658
+ productType: CFProductType.BOOKING,
659
+ bookingRulesId: 'rule_salon_30',
660
+ };
652
661
  export const MOCK_PRODUCTS = [
653
662
  MOCK_PRODUCT_BASIL_ALMOND,
654
663
  MOCK_PRODUCT_BEER,
@@ -664,6 +673,7 @@ export const MOCK_PRODUCTS = [
664
673
  MOCK_PRODUCT_CHILI_GARLIC,
665
674
  MOCK_PRODUCT_HABANERO,
666
675
  MOCK_PRODUCT_BLACK_GARLIC,
676
+ MOCK_PRODUCT_HAIRCUT,
667
677
  ];
668
678
  export const MOCK_ORDERS = [MOCK_ORDER_1, MOCK_ORDER_2, MOCK_ORDER_3, MOCK_ORDER_4];
669
679
  export const MOCK_PARKED_ORDERS = [MOCK_PARKED_ORDER_1, MOCK_PARKED_ORDER_2];
@@ -678,6 +688,7 @@ export let MOCK_CART = {
678
688
  remainingBalance: 0,
679
689
  products: [],
680
690
  customSales: [],
691
+ reservations: [],
681
692
  nonRevenueItems: [],
682
693
  customer: null,
683
694
  };
@@ -698,6 +709,7 @@ export const resetMockCart = () => {
698
709
  remainingBalance: 0,
699
710
  products: [],
700
711
  customSales: [],
712
+ reservations: [],
701
713
  nonRevenueItems: [],
702
714
  customer: null,
703
715
  };
@@ -742,6 +754,12 @@ export function setMockDatabase(config) {
742
754
  if (config.parkedOrders !== undefined) {
743
755
  MOCK_PARKED_ORDERS.splice(0, MOCK_PARKED_ORDERS.length, ...config.parkedOrders);
744
756
  }
757
+ if (config.bookingResources !== undefined) {
758
+ MOCK_BOOKING_RESOURCES.splice(0, MOCK_BOOKING_RESOURCES.length, ...config.bookingResources);
759
+ }
760
+ if (config.bookings !== undefined) {
761
+ MOCK_BOOKINGS.splice(0, MOCK_BOOKINGS.length, ...config.bookings);
762
+ }
745
763
  if (MOCK_OUTLETS.length > 0) {
746
764
  Object.assign(MOCK_OUTLET_MAIN, MOCK_OUTLETS[0]);
747
765
  if (MOCK_OUTLET_MAIN.id === undefined && MOCK_OUTLET_MAIN._id !== undefined) {
@@ -878,6 +896,30 @@ export const createOrderFromCart = (paymentType, amount, processor = 'cash') =>
878
896
  billing: MOCK_CART.customer?.billing || null,
879
897
  shipping: MOCK_CART.customer?.shipping || null,
880
898
  lineItems,
899
+ // A paid booking is a sale: it belongs on the order (and thus the receipt),
900
+ // in its own array rather than among the line items, and CONFIRMED — payment
901
+ // is what turns a held window into a kept appointment.
902
+ reservations: (MOCK_CART.reservations ?? []).map((reservation) => ({
903
+ internalId: reservation.internalId,
904
+ bookingId: reservation.bookingId,
905
+ productId: reservation.productId,
906
+ variantId: reservation.variantId,
907
+ resourceId: reservation.resourceId,
908
+ name: reservation.name,
909
+ resourceName: reservation.resourceName,
910
+ price: reservation.price,
911
+ quantity: reservation.quantity,
912
+ total: reservation.total,
913
+ taxTableId: reservation.taxTableId,
914
+ startAt: reservation.startAt,
915
+ endAt: reservation.endAt,
916
+ bufferEndAt: reservation.bufferEndAt,
917
+ // The mock computes no tax anywhere — line items ship `taxes: []` too.
918
+ taxes: [],
919
+ // Neither `expiresAt` nor a status comes along: a booking's state lives on its own
920
+ // row — which is what `getBookings` reads — and a copy frozen on the order would be
921
+ // wrong from the next moment on.
922
+ })),
881
923
  customSales: [],
882
924
  balance: 0,
883
925
  user: employeeUser,
@@ -886,6 +928,18 @@ export const createOrderFromCart = (paymentType, amount, processor = 'cash') =>
886
928
  createdAt: new Date().toISOString(),
887
929
  };
888
930
  MOCK_ORDERS.push(newOrder);
931
+ // Payment is what turns a held window into a kept appointment, so the ROW moves too — the
932
+ // comment above said CONFIRMED while nothing set it. Left held, a paid appointment dropped out
933
+ // of `getBookings` when its deadline passed and the window could be taken again, which is the
934
+ // one transition a booking screen most needs to be able to test.
935
+ for (const reservation of newOrder.reservations ?? []) {
936
+ const row = MOCK_BOOKINGS.find(({ id }) => id === reservation.bookingId);
937
+ if (row) {
938
+ row.status = ReservationStatus.CONFIRMED;
939
+ row.orderId = newOrder._id;
940
+ row.expiresAt = undefined;
941
+ }
942
+ }
889
943
  resetMockCart();
890
944
  // Publish cart-created event after cart is reset (simulates new empty cart)
891
945
  mockPublishEvent('cart', 'cart-created', {});
@@ -914,6 +968,135 @@ export const applyMockPayment = (amount, paymentType, processor = 'cash') => {
914
968
  mockPublishEvent('payments', 'payment-done', { order });
915
969
  return order;
916
970
  };
971
+ // ── Booking (FT-0064) ────────────────────────────────────────────────────────────
972
+ // A salon: one service, two people who can perform it, a 30-minute slot with a
973
+ // 5-minute turnaround, open 9–18. Enough to click through a booking screen with no
974
+ // server. Availability here is COMPUTED, exactly as the host computes it — a mock
975
+ // that returned a fixed list of slots would hide the one behaviour that matters:
976
+ // a slot disappears once somebody takes it.
977
+ export const MOCK_BOOKING_RULES_ID = 'rule_salon_30';
978
+ const SLOT_MINUTES = 30;
979
+ const BUFFER_MINUTES = 5;
980
+ const OPEN_HOUR = 9;
981
+ const CLOSE_HOUR = 18;
982
+ // Rooms, not people: a resource is whatever is scarce, and a room is the case that
983
+ // reads the same in every vertical a dataset might describe.
984
+ export const MOCK_BOOKING_RESOURCES = [
985
+ { id: 'res_room_1', name: 'Room 1', kind: BookingResourceKind.ROOM },
986
+ { id: 'res_room_2', name: 'Room 2', kind: BookingResourceKind.ROOM },
987
+ ];
988
+ /**
989
+ * The clock this mock shop keeps — the same one `getContext` reports. They used to disagree: the
990
+ * slot hours were built with `setHours`, which is the MACHINE's clock, while the context claimed
991
+ * Vancouver. On a machine in Paris a correct screen showed a salon open from midnight to nine.
992
+ */
993
+ export const MOCK_SHOP_TIME_ZONE = 'America/Vancouver';
994
+ const at = (dayOffset, hour, minute = 0) => {
995
+ // The shop's wall clock, not this machine's. Two passes, because the offset is a function of
996
+ // the instant and the instant is what we are solving for.
997
+ const naive = Date.UTC(new Date().getUTCFullYear(), new Date().getUTCMonth(), new Date().getUTCDate() + dayOffset, hour, minute);
998
+ const offsetAt = (instant) => {
999
+ const parts = {};
1000
+ for (const part of new Intl.DateTimeFormat('en-US', {
1001
+ timeZone: MOCK_SHOP_TIME_ZONE,
1002
+ hour12: false,
1003
+ year: 'numeric',
1004
+ month: '2-digit',
1005
+ day: '2-digit',
1006
+ hour: '2-digit',
1007
+ minute: '2-digit',
1008
+ }).formatToParts(new Date(instant))) {
1009
+ parts[part.type] = part.value;
1010
+ }
1011
+ const asUtc = Date.UTC(Number(parts.year), Number(parts.month) - 1, Number(parts.day), Number(parts.hour) % 24, Number(parts.minute));
1012
+ return asUtc - instant;
1013
+ };
1014
+ return new Date(naive - offsetAt(naive - offsetAt(naive)));
1015
+ };
1016
+ const booking = (id, resourceId, start, status, customerName) => ({
1017
+ id,
1018
+ productId: MOCK_PRODUCT_HAIRCUT._id,
1019
+ resourceId,
1020
+ startAt: start.toISOString(),
1021
+ endAt: new Date(start.getTime() + SLOT_MINUTES * 60000).toISOString(),
1022
+ bufferEndAt: new Date(start.getTime() + (SLOT_MINUTES + BUFFER_MINUTES) * 60000).toISOString(),
1023
+ status,
1024
+ productName: MOCK_PRODUCT_HAIRCUT.name,
1025
+ resourceName: MOCK_BOOKING_RESOURCES.find((resource) => resource.id === resourceId)?.name,
1026
+ customerName,
1027
+ });
1028
+ export const MOCK_BOOKINGS = [
1029
+ booking('bk_1', 'res_room_1', at(0, 10), ReservationStatus.CONFIRMED, 'Alex Green'),
1030
+ booking('bk_2', 'res_room_2', at(0, 11, 30), ReservationStatus.CONFIRMED, 'Dana White'),
1031
+ booking('bk_3', 'res_room_1', at(1, 9, 30), ReservationStatus.CONFIRMED, 'Sam Blue'),
1032
+ ];
1033
+ /** Live = confirmed, or held and not yet expired. An expired hold occupies nothing. */
1034
+ export const mockLiveBookings = () => MOCK_BOOKINGS.filter(({ status, expiresAt }) => status === ReservationStatus.CONFIRMED ||
1035
+ (status === ReservationStatus.HELD && (!expiresAt || new Date(expiresAt) > new Date())));
1036
+ const takenBy = (resourceId, startAt, bufferEndAt) => mockLiveBookings().some((entry) => entry.resourceId === resourceId && new Date(entry.startAt) < bufferEndAt && new Date(entry.bufferEndAt) > startAt);
1037
+ /** The mock's shop day for an instant, `YYYY-MM-DD`, built from parts so it never reads as D/M/Y. */
1038
+ const shopDayOf = (instant) => {
1039
+ const parts = {};
1040
+ for (const part of new Intl.DateTimeFormat('en-CA', {
1041
+ timeZone: MOCK_SHOP_TIME_ZONE,
1042
+ year: 'numeric',
1043
+ month: '2-digit',
1044
+ day: '2-digit',
1045
+ }).formatToParts(instant)) {
1046
+ parts[part.type] = part.value;
1047
+ }
1048
+ return `${parts.year}-${parts.month}-${parts.day}`;
1049
+ };
1050
+ export const mockBookingAvailability = (productId, from, to, resourceId) => {
1051
+ const serving = resourceId
1052
+ ? MOCK_BOOKING_RESOURCES.filter((resource) => resource.id === resourceId)
1053
+ : MOCK_BOOKING_RESOURCES;
1054
+ const slots = [];
1055
+ const step = (SLOT_MINUTES + BUFFER_MINUTES) * 60000;
1056
+ for (let day = 0; day < 14; day += 1) {
1057
+ const open = at(day, OPEN_HOUR);
1058
+ const close = at(day, CLOSE_HOUR);
1059
+ // Overlap, not containment. Asking from noon used to return nothing for today, because the
1060
+ // day's opening hour lay before the range start — so an afternoon question got an empty
1061
+ // calendar and read as "fully booked".
1062
+ if (close <= from || open >= to)
1063
+ continue;
1064
+ for (let start = open.getTime(); start + SLOT_MINUTES * 60000 <= close.getTime(); start += step) {
1065
+ const startAt = new Date(start);
1066
+ const endAt = new Date(start + SLOT_MINUTES * 60000);
1067
+ const bufferEndAt = new Date(start + (SLOT_MINUTES + BUFFER_MINUTES) * 60000);
1068
+ if (bufferEndAt < new Date())
1069
+ continue;
1070
+ const resources = serving.map((resource) => {
1071
+ const free = takenBy(resource.id, startAt, bufferEndAt) ? 0 : 1;
1072
+ return { resourceId: resource.id, name: resource.name, capacity: 1, booked: 1 - free, free };
1073
+ });
1074
+ slots.push({
1075
+ startAt: startAt.toISOString(),
1076
+ endAt: endAt.toISOString(),
1077
+ bufferEndAt: bufferEndAt.toISOString(),
1078
+ canStart: true,
1079
+ capacity: resources.length,
1080
+ booked: resources.reduce((sum, entry) => sum + entry.booked, 0),
1081
+ free: resources.reduce((sum, entry) => sum + entry.free, 0),
1082
+ resources,
1083
+ // The shop day, as the real host stamps it. The mock keeps one shop on the machine's
1084
+ // own clock, so here that is the machine's day — the point is that the FIELD is there,
1085
+ // so a screen built against the mock never learns to work the day out for itself.
1086
+ dayKey: shopDayOf(startAt),
1087
+ });
1088
+ }
1089
+ }
1090
+ return {
1091
+ productId,
1092
+ bookingRulesId: MOCK_BOOKING_RULES_ID,
1093
+ bookingType: BookingType.APPOINTMENT,
1094
+ ratePeriod: BookingRatePeriod.SLOT,
1095
+ slots,
1096
+ timeZone: MOCK_SHOP_TIME_ZONE,
1097
+ days: [...new Set(slots.map((slot) => slot.dayKey))],
1098
+ };
1099
+ };
917
1100
  /**
918
1101
  * Price the cashier's raw modifier answers into the rows a CART line carries (FT-0010).
919
1102
  *
package/dist/index.d.ts CHANGED
@@ -2,6 +2,13 @@ export declare const command: {
2
2
  readonly exampleFunction: import(".").ExampleFunction;
3
3
  readonly generateAPIKey: import(".").GenerateAPIKey;
4
4
  readonly getProducts: import(".").GetProducts;
5
+ readonly getBookingResources: import(".").GetBookingResources;
6
+ readonly getBookingAvailability: import(".").GetBookingAvailability;
7
+ readonly getBookings: import(".").GetBookings;
8
+ readonly holdBooking: import(".").HoldBooking;
9
+ readonly addBookingToCart: import(".").AddBookingToCart;
10
+ readonly removeBookingFromCart: import(".").RemoveBookingFromCart;
11
+ readonly cancelBooking: import(".").CancelBooking;
5
12
  readonly addCustomSale: import(".").AddCustomSale;
6
13
  readonly editCustomSale: import(".").EditCustomSale;
7
14
  readonly addNonRevenueItem: import(".").AddNonRevenueItem;
@@ -45,8 +52,6 @@ export declare const command: {
45
52
  readonly integrationPayment: import(".").IntegrationPayment;
46
53
  readonly createPaymentLink: import(".").CreatePaymentLink;
47
54
  readonly chargeMoto: import(".").ChargeMoto;
48
- readonly startCheckout: import(".").StartCheckout;
49
- readonly resumeCheckout: import(".").ResumeCheckout;
50
55
  readonly addCustomerNote: import(".").AddCustomerNote;
51
56
  readonly removeCustomerNote: import(".").RemoveCustomerNote;
52
57
  readonly removeCustomerFromCart: import(".").RemoveCustomerFromCart;
@@ -123,6 +128,13 @@ export declare const command: {
123
128
  export type { ExampleFunction, ExampleFunctionParams, ExampleFunctionResponse } from './actions/example-function/types';
124
129
  export type { GenerateAPIKey, GenerateAPIKeyParams, GenerateAPIKeyResponse } from './actions/generate-api-key/types';
125
130
  export type { GetProducts, GetProductsParams, GetProductsResponse } from './actions/get-products/types';
131
+ export type { GetBookingResources, GetBookingResourcesParams, GetBookingResourcesResponse, } from './actions/get-booking-resources/types';
132
+ export type { GetBookingAvailability, GetBookingAvailabilityParams, GetBookingAvailabilityResponse, } from './actions/get-booking-availability/types';
133
+ export type { GetBookings, GetBookingsParams, GetBookingsResponse } from './actions/get-bookings/types';
134
+ export type { HoldBooking, HoldBookingParams, HoldBookingResponse } from './actions/hold-booking/types';
135
+ export type { AddBookingToCart, AddBookingToCartParams, AddBookingToCartResponse, } from './actions/add-booking-to-cart/types';
136
+ export type { RemoveBookingFromCart, RemoveBookingFromCartParams, RemoveBookingFromCartResponse, } from './actions/remove-booking-from-cart/types';
137
+ export type { CancelBooking, CancelBookingParams, CancelBookingResponse } from './actions/cancel-booking/types';
126
138
  export type { AddCustomSale, AddCustomSaleParams, AddCustomSaleResponse } from './actions/add-custom-sale/types';
127
139
  export type { EditCustomSale, EditCustomSaleParams, EditCustomSaleResponse } from './actions/edit-custom-sale/types';
128
140
  export type { AddNonRevenueItem, AddNonRevenueItemParams, AddNonRevenueItemResponse, } from './actions/add-non-revenue-item/types';
@@ -184,8 +196,6 @@ export type { RedeemPayment, RedeemPaymentParams, RedeemPaymentResponse } from '
184
196
  export type { IntegrationPayment, IntegrationPaymentParams, IntegrationPaymentResponse, IntegrationEmvData, } from './actions/integration-payment/types';
185
197
  export type { CreatePaymentLink, CreatePaymentLinkParams, CreatePaymentLinkResponse, } from './actions/create-payment-link/types';
186
198
  export type { ChargeMoto, ChargeMotoParams, ChargeMotoResponse, ChargeMotoCardFields, } from './actions/charge-moto/types';
187
- export type { StartCheckout, StartCheckoutParams, StartCheckoutResponse, StartCheckoutContact, StartCheckoutOrder, } from './actions/start-checkout/types';
188
- export type { ResumeCheckout, ResumeCheckoutParams, ResumeCheckoutResponse, ResumeCheckoutResult, } from './actions/resume-checkout/types';
189
199
  export type { AddCustomerNote, AddCustomerNoteParams, AddCustomerNoteResponse, } from './actions/add-customer-note/types';
190
200
  export type { RemoveCustomerNote, RemoveCustomerNoteParams, RemoveCustomerNoteResponse, } from './actions/remove-customer-note/types';
191
201
  export type { RemoveCustomerFromCart, RemoveCustomerFromCartResponse } from './actions/remove-customer-from-cart/types';
@@ -242,7 +252,6 @@ export { refundsTopic } from './pubsub/topics/refunds';
242
252
  export { productsTopic } from './pubsub/topics/products';
243
253
  export { cartTopic } from './pubsub/topics/cart';
244
254
  export { paymentsTopic } from './pubsub/topics/payments';
245
- export { checkoutTopic } from './pubsub/topics/checkout';
246
255
  export { splitPaymentsTopic } from './pubsub/topics/split-payments';
247
256
  export { customTablesTopic } from './pubsub/topics/custom-tables';
248
257
  export { printTopic } from './pubsub/topics/print';
@@ -254,6 +263,7 @@ export { variantsTopic } from './pubsub/topics/variants';
254
263
  export { transactionsTopic } from './pubsub/topics/transactions';
255
264
  export { categoriesTopic } from './pubsub/topics/categories';
256
265
  export { attributesTopic } from './pubsub/topics/attributes';
266
+ export { bookingsTopic } from './pubsub/topics/bookings';
257
267
  export type { CustomerCreatedPayload, CustomerUpdatedPayload, CustomerNoteAddedPayload, CustomerNoteDeletedPayload, CustomerAssignedPayload, CustomerUnassignedPayload, CustomerActiveSetPayload, CustomerActiveGetPayload, CustomerCreatedEvent, CustomerUpdatedEvent, CustomerNoteAddedEvent, CustomerNoteDeletedEvent, CustomerAssignedEvent, CustomerUnassignedEvent, CustomerActiveSetEvent, CustomerActiveGetEvent, CustomersEventType, CustomersEventPayload, } from './pubsub/topics/customers/types';
258
268
  export type { OrderCreatedPayload, OrderUpdatedPayload, OrderVoidedPayload, OrderActiveSetPayload, OrderActiveGetPayload, OrderCreatedEvent, OrderUpdatedEvent, OrderVoidedEvent, OrderActiveSetEvent, OrderActiveGetEvent, OrderStateTransitionCompletedPayload, OrderStateTransitionBlockedPayload, OrderStateTransitionCompletedEvent, OrderStateTransitionBlockedEvent, OrdersEventType, OrdersEventPayload, } from './pubsub/topics/orders/types';
259
269
  export type { RefundCreatedPayload, RefundUpdatedPayload, RefundActiveSetPayload, RefundActiveGetPayload, RefundCreatedEvent, RefundUpdatedEvent, RefundActiveSetEvent, RefundActiveGetEvent, RefundsEventType, RefundsEventPayload, } from './pubsub/topics/refunds/types';
@@ -264,11 +274,11 @@ export type { SessionActiveSetPayload, SessionActiveGetPayload, SessionActiveSet
264
274
  export type { UserActiveSetPayload, UserActiveGetPayload, UserActiveSetEvent, UserActiveGetEvent, UserCreatedPayload, UserCreatedEvent, UserUpdatedPayload, UserUpdatedEvent, UsersEventType, UsersEventPayload, } from './pubsub/topics/users/types';
265
275
  export type { VariantCreatedPayload, VariantCreatedEvent, VariantUpdatedPayload, VariantUpdatedEvent, VariantsEventType, VariantsEventPayload, } from './pubsub/topics/variants/types';
266
276
  export type { TransactionCreatedPayload, TransactionCreatedEvent, TransactionUpdatedPayload, TransactionUpdatedEvent, TransactionsEventType, TransactionsEventPayload, } from './pubsub/topics/transactions/types';
277
+ export type { BookingCreatedPayload, BookingCreatedEvent, BookingUpdatedPayload, BookingUpdatedEvent, BookingSetupChangedPayload, BookingSetupChangedEvent, BookingsEventType, BookingsEventPayload, } from './pubsub/topics/bookings/types';
267
278
  export type { CategoryCreatedPayload, CategoryCreatedEvent, CategoryUpdatedPayload, CategoryUpdatedEvent, CategoriesEventType, CategoriesEventPayload, } from './pubsub/topics/categories/types';
268
279
  export type { AttributeCreatedPayload, AttributeCreatedEvent, AttributeUpdatedPayload, AttributeUpdatedEvent, AttributesEventType, AttributesEventPayload, } from './pubsub/topics/attributes/types';
269
280
  export type { CartCreatedPayload, CartCustomerAssignedPayload, ProductAddedPayload, ProductDeletedPayload, CartDiscountAddedPayload, CartDiscountRemovedPayload, CartFeeAddedPayload, CartFeeRemovedPayload, ProductDiscountAddedPayload, ProductDiscountRemovedPayload, ProductFeeAddedPayload, ProductFeeRemovedPayload, ProductNoteAddedPayload, ProductNoteRemovedPayload, CartCreatedEvent, CartCustomerAssignedEvent, ProductAddedEvent, ProductDeletedEvent, CartDiscountAddedEvent, CartDiscountRemovedEvent, CartFeeAddedEvent, CartFeeRemovedEvent, ProductDiscountAddedEvent, ProductDiscountRemovedEvent, ProductFeeAddedEvent, ProductFeeRemovedEvent, ProductNoteAddedEvent, ProductNoteRemovedEvent, CartEventType, CartEventPayload, } from './pubsub/topics/cart/types';
270
281
  export type { PaymentDonePayload, PaymentErrPayload, PaymentDoneEvent, PaymentErrEvent, PaymentsEventType, PaymentsEventPayload, } from './pubsub/topics/payments/types';
271
- export type { CheckoutStartedPayload, PaymentCompletedPayload, PaymentFailedPayload, CheckoutStartedEvent, PaymentCompletedEvent, PaymentFailedEvent, CheckoutEventType, CheckoutEventPayload, } from './pubsub/topics/checkout/types';
272
282
  export type { SplitPaymentUpdatedPayload, SplitPaymentUpdatedEvent, SplitPaymentsEventType, SplitPaymentsEventPayload, } from './pubsub/topics/split-payments/types';
273
283
  export type { RowCreatedPayload, RowUpdatedPayload, RowDeletedPayload, RowCreatedEvent, RowUpdatedEvent, RowDeletedEvent, CustomTablesEventType, CustomTablesEventPayload, } from './pubsub/topics/custom-tables/types';
274
284
  export type { PrintStartedPayload, PrintCompletedPayload, PrintErrorPayload, PrintStartedEvent, PrintCompletedEvent, PrintErrorEvent, PrintEventType, PrintEventPayload, } from './pubsub/topics/print/types';