@final-commerce/command-frame 0.7.0-staging.3 → 0.8.0-online.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 (76) hide show
  1. package/dist/CommonTypes.d.ts +1 -11
  2. package/dist/actions/start-checkout/action.d.ts +6 -0
  3. package/dist/actions/start-checkout/action.js +8 -0
  4. package/dist/actions/start-checkout/mock.d.ts +16 -0
  5. package/dist/actions/start-checkout/mock.js +80 -0
  6. package/dist/actions/start-checkout/types.d.ts +81 -0
  7. package/dist/actions/start-checkout/types.js +10 -0
  8. package/dist/demo/database.d.ts +1 -8
  9. package/dist/demo/database.js +0 -93
  10. package/dist/index.d.ts +4 -16
  11. package/dist/index.js +3 -15
  12. package/dist/projects/render/mocks.js +2 -14
  13. package/dist/projects/render/types.d.ts +7 -8
  14. package/dist/pubsub/topics/checkout/checkout-started/types.d.ts +26 -0
  15. package/dist/pubsub/topics/checkout/index.d.ts +7 -0
  16. package/dist/pubsub/topics/checkout/index.js +28 -0
  17. package/dist/pubsub/topics/checkout/payment-completed/types.d.ts +19 -0
  18. package/dist/pubsub/topics/checkout/payment-failed/types.d.ts +20 -0
  19. package/dist/pubsub/topics/checkout/types.d.ts +12 -0
  20. package/dist/pubsub/topics/checkout/types.js +8 -0
  21. package/dist/pubsub/topics/index.d.ts +17 -17
  22. package/dist/pubsub/topics/index.js +17 -17
  23. package/dist/pubsub/topics/types.d.ts +8 -2
  24. package/package.json +2 -2
  25. package/dist/actions/add-booking-to-cart/action.d.ts +0 -6
  26. package/dist/actions/add-booking-to-cart/action.js +0 -8
  27. package/dist/actions/add-booking-to-cart/mock.d.ts +0 -2
  28. package/dist/actions/add-booking-to-cart/mock.js +0 -8
  29. package/dist/actions/add-booking-to-cart/types.d.ts +0 -23
  30. package/dist/actions/cancel-booking/action.d.ts +0 -6
  31. package/dist/actions/cancel-booking/action.js +0 -8
  32. package/dist/actions/cancel-booking/mock.d.ts +0 -2
  33. package/dist/actions/cancel-booking/mock.js +0 -10
  34. package/dist/actions/cancel-booking/types.d.ts +0 -10
  35. package/dist/actions/get-booking-availability/action.d.ts +0 -6
  36. package/dist/actions/get-booking-availability/action.js +0 -8
  37. package/dist/actions/get-booking-availability/mock.d.ts +0 -2
  38. package/dist/actions/get-booking-availability/mock.js +0 -6
  39. package/dist/actions/get-booking-availability/types.d.ts +0 -18
  40. package/dist/actions/get-booking-resources/action.d.ts +0 -6
  41. package/dist/actions/get-booking-resources/action.js +0 -8
  42. package/dist/actions/get-booking-resources/mock.d.ts +0 -2
  43. package/dist/actions/get-booking-resources/mock.js +0 -7
  44. package/dist/actions/get-booking-resources/types.d.ts +0 -12
  45. package/dist/actions/get-booking-resources/types.js +0 -1
  46. package/dist/actions/get-bookings/action.d.ts +0 -6
  47. package/dist/actions/get-bookings/action.js +0 -8
  48. package/dist/actions/get-bookings/mock.d.ts +0 -2
  49. package/dist/actions/get-bookings/mock.js +0 -20
  50. package/dist/actions/get-bookings/types.d.ts +0 -18
  51. package/dist/actions/get-bookings/types.js +0 -1
  52. package/dist/actions/hold-booking/action.d.ts +0 -6
  53. package/dist/actions/hold-booking/action.js +0 -8
  54. package/dist/actions/hold-booking/mock.d.ts +0 -2
  55. package/dist/actions/hold-booking/mock.js +0 -33
  56. package/dist/actions/hold-booking/types.d.ts +0 -24
  57. package/dist/actions/hold-booking/types.js +0 -1
  58. package/dist/actions/remove-booking-from-cart/action.d.ts +0 -6
  59. package/dist/actions/remove-booking-from-cart/action.js +0 -8
  60. package/dist/actions/remove-booking-from-cart/mock.d.ts +0 -2
  61. package/dist/actions/remove-booking-from-cart/mock.js +0 -16
  62. package/dist/actions/remove-booking-from-cart/types.d.ts +0 -12
  63. package/dist/actions/remove-booking-from-cart/types.js +0 -1
  64. package/dist/pubsub/topics/bookings/booking-created/types.d.ts +0 -6
  65. package/dist/pubsub/topics/bookings/booking-created/types.js +0 -1
  66. package/dist/pubsub/topics/bookings/booking-setup-changed/types.d.ts +0 -15
  67. package/dist/pubsub/topics/bookings/booking-setup-changed/types.js +0 -1
  68. package/dist/pubsub/topics/bookings/booking-updated/types.d.ts +0 -6
  69. package/dist/pubsub/topics/bookings/booking-updated/types.js +0 -1
  70. package/dist/pubsub/topics/bookings/index.d.ts +0 -3
  71. package/dist/pubsub/topics/bookings/index.js +0 -27
  72. package/dist/pubsub/topics/bookings/types.d.ts +0 -8
  73. package/dist/pubsub/topics/bookings/types.js +0 -3
  74. /package/dist/{actions/add-booking-to-cart → pubsub/topics/checkout/checkout-started}/types.js +0 -0
  75. /package/dist/{actions/cancel-booking → pubsub/topics/checkout/payment-completed}/types.js +0 -0
  76. /package/dist/{actions/get-booking-availability → pubsub/topics/checkout/payment-failed}/types.js +0 -0
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Checkout Topic Definition
3
+ * Defines the checkout topic and its available event types
4
+ */
5
+ export const checkoutTopic = {
6
+ id: "checkout",
7
+ name: "Checkout",
8
+ description: "Topic for online (website) checkout events",
9
+ eventTypes: [
10
+ {
11
+ id: "checkout-started",
12
+ name: "Checkout Started",
13
+ description: "Published when the order has been created and the payment fields are mounted"
14
+ },
15
+ {
16
+ id: "payment-completed",
17
+ name: "Payment Completed",
18
+ description: "Published when the shopper's payment succeeds on their side (authorisation, not settlement)"
19
+ },
20
+ {
21
+ id: "payment-failed",
22
+ name: "Payment Failed",
23
+ description: "Published when a payment attempt is refused or errors; the shopper can retry"
24
+ }
25
+ ]
26
+ };
27
+ // Re-export types
28
+ export * from "./types";
@@ -0,0 +1,19 @@
1
+ import type { TopicEvent } from "../../../types";
2
+ /**
3
+ * Payload for payment-completed event
4
+ *
5
+ * THIS IS NOT SETTLEMENT. It reports that the SHOPPER'S side finished —
6
+ * `resultCode` is the provider's own outcome, typically `Authorised`. The money
7
+ * is confirmed by the provider's capture webhook reaching the backend, out of
8
+ * band and after this page is done, so this event cannot and does not claim it.
9
+ */
10
+ export interface PaymentCompletedPayload {
11
+ orderId: string;
12
+ receiptId: string;
13
+ /** The provider's result code, e.g. `Authorised`. */
14
+ resultCode: string;
15
+ }
16
+ /**
17
+ * Typed event for payment-completed
18
+ */
19
+ export type PaymentCompletedEvent = TopicEvent<PaymentCompletedPayload>;
@@ -0,0 +1,20 @@
1
+ import type { TopicEvent } from "../../../types";
2
+ /**
3
+ * Payload for payment-failed event
4
+ *
5
+ * ONE DECLINED ATTEMPT, NOT A DEAD CHECKOUT. The order and the mounted payment
6
+ * fields both survive, so the shopper can try another card without the page
7
+ * starting a new checkout.
8
+ */
9
+ export interface PaymentFailedPayload {
10
+ orderId: string;
11
+ receiptId: string;
12
+ /** The provider's result code, e.g. `Refused`, or an error name. */
13
+ resultCode: string;
14
+ /** Present when the failure carried a message worth showing. */
15
+ message?: string;
16
+ }
17
+ /**
18
+ * Typed event for payment-failed
19
+ */
20
+ export type PaymentFailedEvent = TopicEvent<PaymentFailedPayload>;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Checkout Topic Types
3
+ * Aggregated types for all online-checkout events
4
+ */
5
+ export * from "./checkout-started/types";
6
+ export * from "./payment-completed/types";
7
+ export * from "./payment-failed/types";
8
+ import type { CheckoutStartedPayload } from "./checkout-started/types";
9
+ import type { PaymentCompletedPayload } from "./payment-completed/types";
10
+ import type { PaymentFailedPayload } from "./payment-failed/types";
11
+ export type CheckoutEventPayload = CheckoutStartedPayload | PaymentCompletedPayload | PaymentFailedPayload;
12
+ export type CheckoutEventType = "checkout-started" | "payment-completed" | "payment-failed";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Checkout Topic Types
3
+ * Aggregated types for all online-checkout events
4
+ */
5
+ // Re-export all event types
6
+ export * from "./checkout-started/types";
7
+ export * from "./payment-completed/types";
8
+ export * from "./payment-failed/types";
@@ -2,20 +2,20 @@
2
2
  * Pub/Sub Topics
3
3
  * Export all available topics and their types
4
4
  */
5
- export * from './customers';
6
- export * from './orders';
7
- export * from './bookings';
8
- export * from './refunds';
9
- export * from './products';
10
- export * from './cart';
11
- export * from './payments';
12
- export * from './custom-tables';
13
- export * from './print';
14
- export * from './outlet';
15
- export * from './station';
16
- export * from './session';
17
- export * from './users';
18
- export * from './variants';
19
- export * from './transactions';
20
- export * from './categories';
21
- export * from './attributes';
5
+ export * from "./customers";
6
+ export * from "./orders";
7
+ export * from "./refunds";
8
+ export * from "./products";
9
+ export * from "./cart";
10
+ export * from "./payments";
11
+ export * from "./checkout";
12
+ export * from "./custom-tables";
13
+ export * from "./print";
14
+ export * from "./outlet";
15
+ export * from "./station";
16
+ export * from "./session";
17
+ export * from "./users";
18
+ export * from "./variants";
19
+ export * from "./transactions";
20
+ export * from "./categories";
21
+ export * from "./attributes";
@@ -2,20 +2,20 @@
2
2
  * Pub/Sub Topics
3
3
  * Export all available topics and their types
4
4
  */
5
- export * from './customers';
6
- export * from './orders';
7
- export * from './bookings';
8
- export * from './refunds';
9
- export * from './products';
10
- export * from './cart';
11
- export * from './payments';
12
- export * from './custom-tables';
13
- export * from './print';
14
- export * from './outlet';
15
- export * from './station';
16
- export * from './session';
17
- export * from './users';
18
- export * from './variants';
19
- export * from './transactions';
20
- export * from './categories';
21
- export * from './attributes';
5
+ export * from "./customers";
6
+ export * from "./orders";
7
+ export * from "./refunds";
8
+ export * from "./products";
9
+ export * from "./cart";
10
+ export * from "./payments";
11
+ export * from "./checkout";
12
+ export * from "./custom-tables";
13
+ export * from "./print";
14
+ export * from "./outlet";
15
+ export * from "./station";
16
+ export * from "./session";
17
+ export * from "./users";
18
+ export * from "./variants";
19
+ export * from "./transactions";
20
+ export * from "./categories";
21
+ export * from "./attributes";
@@ -4,6 +4,7 @@ import { RefundsEventType, RefundsEventPayload } from "./refunds/types";
4
4
  import { ProductsEventType, ProductsEventPayload } from "./products/types";
5
5
  import { CartEventType, CartEventPayload } from "./cart/types";
6
6
  import { PaymentsEventType, PaymentsEventPayload } from "./payments/types";
7
+ import { CheckoutEventType, CheckoutEventPayload } from "./checkout/types";
7
8
  import { SplitPaymentsEventType, SplitPaymentsEventPayload } from "./split-payments/types";
8
9
  import { CustomTablesEventPayload, CustomTablesEventType } from "./custom-tables/types";
9
10
  import { PrintEventType, PrintEventPayload } from "./print/types";
@@ -15,7 +16,6 @@ import { VariantsEventType, VariantsEventPayload } from "./variants/types";
15
16
  import { TransactionsEventType, TransactionsEventPayload } from "./transactions/types";
16
17
  import { CategoriesEventType, CategoriesEventPayload } from "./categories/types";
17
18
  import { AttributesEventType, AttributesEventPayload } from "./attributes/types";
18
- import { BookingsEventType, BookingsEventPayload } from "./bookings/types";
19
19
  export interface TopicEventPayloadMap {
20
20
  customers: Record<CustomersEventType, CustomersEventPayload>;
21
21
  orders: Record<OrdersEventType, OrdersEventPayload>;
@@ -23,6 +23,13 @@ export interface TopicEventPayloadMap {
23
23
  products: Record<ProductsEventType, ProductsEventPayload>;
24
24
  cart: Record<CartEventType, CartEventPayload>;
25
25
  payments: Record<PaymentsEventType, PaymentsEventPayload>;
26
+ /**
27
+ * ONLINE checkout only (a published website), where the POS `payments`
28
+ * topic never fires: `payments` reports a till tender settling in front of
29
+ * a cashier, while a web shopper's outcome arrives asynchronously and can
30
+ * only ever be an authorisation until the provider's webhook lands.
31
+ */
32
+ checkout: Record<CheckoutEventType, CheckoutEventPayload>;
26
33
  "split-payments": Record<SplitPaymentsEventType, SplitPaymentsEventPayload>;
27
34
  customTables: Record<CustomTablesEventType, CustomTablesEventPayload>;
28
35
  print: Record<PrintEventType, PrintEventPayload>;
@@ -34,5 +41,4 @@ export interface TopicEventPayloadMap {
34
41
  transactions: Record<TransactionsEventType, TransactionsEventPayload>;
35
42
  categories: Record<CategoriesEventType, CategoriesEventPayload>;
36
43
  attributes: Record<AttributesEventType, AttributesEventPayload>;
37
- bookings: Record<BookingsEventType, BookingsEventPayload>;
38
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@final-commerce/command-frame",
3
- "version": "0.7.0-staging.3",
3
+ "version": "0.8.0-online.1",
4
4
  "description": "Commands Frame library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -57,7 +57,7 @@
57
57
  "ignoreBranchesMissingTickets": true
58
58
  },
59
59
  "dependencies": {
60
- "@final-commerce/common": "2.3.0-staging.3"
60
+ "@final-commerce/common": "2.2.2"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@commitlint/cli": "^19.0.0",
@@ -1,6 +0,0 @@
1
- /**
2
- * Add booking to cart action
3
- * Calls the addBookingToCart action on the parent window
4
- */
5
- import type { AddBookingToCart } from './types';
6
- export declare const addBookingToCart: AddBookingToCart;
@@ -1,8 +0,0 @@
1
- /**
2
- * Add booking to cart action
3
- * Calls the addBookingToCart action on the parent window
4
- */
5
- import { commandFrameClient } from '../../client';
6
- export const addBookingToCart = async (params) => {
7
- return await commandFrameClient.call('addBookingToCart', params);
8
- };
@@ -1,2 +0,0 @@
1
- import { AddBookingToCart } from './types';
2
- export declare const mockAddBookingToCart: AddBookingToCart;
@@ -1,8 +0,0 @@
1
- import { mockHoldBooking } from '../hold-booking/mock';
2
- export const mockAddBookingToCart = async (params) => {
3
- console.log('[Mock] addBookingToCart called', params);
4
- // Same claim as holdBooking — including its refusal when the window is already taken. The mock
5
- // cart is not modelled here; what a booking screen must handle is the refusal, not the line.
6
- const { booking } = await mockHoldBooking(params);
7
- return { booking, reservationInternalId: `res_${booking.id}`, timestamp: new Date().toISOString() };
8
- };
@@ -1,23 +0,0 @@
1
- import { CFBooking } from '../../CommonTypes';
2
- export interface AddBookingToCartParams {
3
- /** The bookable product (`productType: 'booking'`). */
4
- productId: string;
5
- /** Which resource serves it: a member of staff, a room, a scooter. */
6
- resourceId: string;
7
- /** Must be the START of a slot getBookingAvailability offered, ISO 8601. */
8
- startAt: string;
9
- /** End of the window — the slot's own `endAt`, or the last slot's for a stay. */
10
- endAt: string;
11
- /** The variant being sold. Defaults to the product's only variant. */
12
- variantId?: string;
13
- /** Whom the booking is for. Omit for a walk-in. */
14
- customerId?: string;
15
- }
16
- export interface AddBookingToCartResponse {
17
- /** The claim the cart now stands on: `id` cancels or releases it, `expiresAt` is your clock. */
18
- booking: CFBooking;
19
- /** Identity of the reservation inside the cart and, later, the order. */
20
- reservationInternalId: string;
21
- timestamp: string;
22
- }
23
- export type AddBookingToCart = (params: AddBookingToCartParams) => Promise<AddBookingToCartResponse>;
@@ -1,6 +0,0 @@
1
- /**
2
- * Cancel booking action
3
- * Calls the cancelBooking action on the parent window
4
- */
5
- import type { CancelBooking } from './types';
6
- export declare const cancelBooking: CancelBooking;
@@ -1,8 +0,0 @@
1
- /**
2
- * Cancel booking action
3
- * Calls the cancelBooking action on the parent window
4
- */
5
- import { commandFrameClient } from '../../client';
6
- export const cancelBooking = async (params) => {
7
- return await commandFrameClient.call('cancelBooking', params);
8
- };
@@ -1,2 +0,0 @@
1
- import { CancelBooking } from './types';
2
- export declare const mockCancelBooking: CancelBooking;
@@ -1,10 +0,0 @@
1
- import { MOCK_BOOKINGS } from '../../demo/database';
2
- import { ReservationStatus } from '@final-commerce/common';
3
- export const mockCancelBooking = async (params) => {
4
- console.log('[Mock] cancelBooking called', params);
5
- const booking = MOCK_BOOKINGS.find(({ id }) => id === params.bookingId);
6
- if (!booking)
7
- throw new Error(`No booking ${params.bookingId}`);
8
- booking.status = ReservationStatus.CANCELLED;
9
- return { booking, timestamp: new Date().toISOString() };
10
- };
@@ -1,10 +0,0 @@
1
- import { CFBooking } from '../../CommonTypes';
2
- export interface CancelBookingParams {
3
- /** `id` of the booking returned by holdBooking or getBookings. */
4
- bookingId: string;
5
- }
6
- export interface CancelBookingResponse {
7
- booking: CFBooking;
8
- timestamp: string;
9
- }
10
- export type CancelBooking = (params: CancelBookingParams) => Promise<CancelBookingResponse>;
@@ -1,6 +0,0 @@
1
- /**
2
- * Get booking availability action
3
- * Calls the getBookingAvailability action on the parent window
4
- */
5
- import type { GetBookingAvailability } from './types';
6
- export declare const getBookingAvailability: GetBookingAvailability;
@@ -1,8 +0,0 @@
1
- /**
2
- * Get booking availability action
3
- * Calls the getBookingAvailability action on the parent window
4
- */
5
- import { commandFrameClient } from '../../client';
6
- export const getBookingAvailability = async (params) => {
7
- return await commandFrameClient.call('getBookingAvailability', params);
8
- };
@@ -1,2 +0,0 @@
1
- import { GetBookingAvailability } from './types';
2
- export declare const mockGetBookingAvailability: GetBookingAvailability;
@@ -1,6 +0,0 @@
1
- import { mockBookingAvailability } from '../../demo/database';
2
- export const mockGetBookingAvailability = async (params) => {
3
- console.log('[Mock] getBookingAvailability called', params);
4
- const availability = mockBookingAvailability(params.productId, new Date(params.from), new Date(params.to), params.resourceId);
5
- return { availability, timestamp: new Date().toISOString() };
6
- };
@@ -1,18 +0,0 @@
1
- import { CFBookingAvailability } from '../../CommonTypes';
2
- export interface GetBookingAvailabilityParams {
3
- /** The bookable product (`productType: 'booking'`) whose calendar you are drawing. */
4
- productId: string;
5
- /** Range start, ISO 8601. */
6
- from: string;
7
- /** Range end, ISO 8601. */
8
- to: string;
9
- /** Narrow the answer to one resource — "only Marco", "only room 4". */
10
- resourceId?: string;
11
- /** Narrow to the resources standing at one outlet. */
12
- outletId?: string;
13
- }
14
- export interface GetBookingAvailabilityResponse {
15
- availability: CFBookingAvailability;
16
- timestamp: string;
17
- }
18
- export type GetBookingAvailability = (params: GetBookingAvailabilityParams) => Promise<GetBookingAvailabilityResponse>;
@@ -1,6 +0,0 @@
1
- /**
2
- * Get booking resources action
3
- * Calls the getBookingResources action on the parent window
4
- */
5
- import type { GetBookingResources } from './types';
6
- export declare const getBookingResources: GetBookingResources;
@@ -1,8 +0,0 @@
1
- /**
2
- * Get booking resources action
3
- * Calls the getBookingResources action on the parent window
4
- */
5
- import { commandFrameClient } from '../../client';
6
- export const getBookingResources = async (params) => {
7
- return await commandFrameClient.call('getBookingResources', params);
8
- };
@@ -1,2 +0,0 @@
1
- import { GetBookingResources } from './types';
2
- export declare const mockGetBookingResources: GetBookingResources;
@@ -1,7 +0,0 @@
1
- import { MOCK_BOOKING_RESOURCES } from '../../demo/database';
2
- export const mockGetBookingResources = async (params) => {
3
- console.log('[Mock] getBookingResources called', params);
4
- // A resource knows nothing about outlets — where it works lives in its own records, which the
5
- // host reads. The mock has no such records, so `outletId` narrows nothing here.
6
- return { resources: MOCK_BOOKING_RESOURCES, timestamp: new Date().toISOString() };
7
- };
@@ -1,12 +0,0 @@
1
- import { CFBookingResource } from '../../CommonTypes';
2
- export interface GetBookingResourcesParams {
3
- /** Only the resources that serve this bookable product. Omit for the whole company. */
4
- productId?: string;
5
- /** Only resources standing at this outlet (a resource with no outlet serves all of them). */
6
- outletId?: string;
7
- }
8
- export interface GetBookingResourcesResponse {
9
- resources: CFBookingResource[];
10
- timestamp: string;
11
- }
12
- export type GetBookingResources = (params?: GetBookingResourcesParams) => Promise<GetBookingResourcesResponse>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- /**
2
- * Get bookings action
3
- * Calls the getBookings action on the parent window
4
- */
5
- import type { GetBookings } from './types';
6
- export declare const getBookings: GetBookings;
@@ -1,8 +0,0 @@
1
- /**
2
- * Get bookings action
3
- * Calls the getBookings action on the parent window
4
- */
5
- import { commandFrameClient } from '../../client';
6
- export const getBookings = async (params) => {
7
- return await commandFrameClient.call('getBookings', params);
8
- };
@@ -1,2 +0,0 @@
1
- import { GetBookings } from './types';
2
- export declare const mockGetBookings: GetBookings;
@@ -1,20 +0,0 @@
1
- import { MOCK_BOOKINGS, mockLiveBookings } from '../../demo/database';
2
- export const mockGetBookings = async (params) => {
3
- console.log('[Mock] getBookings called', params);
4
- let bookings = params?.includeExpired ? MOCK_BOOKINGS : mockLiveBookings();
5
- if (params?.resourceId)
6
- bookings = bookings.filter((entry) => entry.resourceId === params.resourceId);
7
- if (params?.productId)
8
- bookings = bookings.filter((entry) => entry.productId === params.productId);
9
- if (params?.customerId)
10
- bookings = bookings.filter((entry) => entry.customerId === params.customerId);
11
- if (params?.from) {
12
- const from = new Date(params.from);
13
- bookings = bookings.filter((entry) => new Date(entry.bufferEndAt) > from);
14
- }
15
- if (params?.to) {
16
- const to = new Date(params.to);
17
- bookings = bookings.filter((entry) => new Date(entry.startAt) < to);
18
- }
19
- return { bookings, timestamp: new Date().toISOString() };
20
- };
@@ -1,18 +0,0 @@
1
- import { CFBooking } from '../../CommonTypes';
2
- export interface GetBookingsParams {
3
- /** Everything taking this resource's time — the one query a day view needs. */
4
- resourceId?: string;
5
- productId?: string;
6
- /** This customer's appointments. */
7
- customerId?: string;
8
- /** Bookings whose window overlaps this range, ISO 8601. */
9
- from?: string;
10
- to?: string;
11
- /** Defaults to live bookings only (confirmed, plus holds that have not expired). */
12
- includeExpired?: boolean;
13
- }
14
- export interface GetBookingsResponse {
15
- bookings: CFBooking[];
16
- timestamp: string;
17
- }
18
- export type GetBookings = (params?: GetBookingsParams) => Promise<GetBookingsResponse>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- /**
2
- * Hold booking action
3
- * Calls the holdBooking action on the parent window
4
- */
5
- import type { HoldBooking } from './types';
6
- export declare const holdBooking: HoldBooking;
@@ -1,8 +0,0 @@
1
- /**
2
- * Hold booking action
3
- * Calls the holdBooking action on the parent window
4
- */
5
- import { commandFrameClient } from '../../client';
6
- export const holdBooking = async (params) => {
7
- return await commandFrameClient.call('holdBooking', params);
8
- };
@@ -1,2 +0,0 @@
1
- import { HoldBooking } from './types';
2
- export declare const mockHoldBooking: HoldBooking;
@@ -1,33 +0,0 @@
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
- export const mockHoldBooking = async (params) => {
6
- console.log('[Mock] holdBooking called', params);
7
- const startAt = new Date(params.startAt);
8
- const endAt = new Date(params.endAt);
9
- const bufferEndAt = new Date(endAt.getTime() + BUFFER_MINUTES * 60000);
10
- // The mock refuses a taken window like the host does. A mock that always said yes would
11
- // let a booking screen ship without ever handling the one error it will actually meet.
12
- const clash = mockLiveBookings().some((entry) => entry.resourceId === params.resourceId &&
13
- new Date(entry.startAt) < bufferEndAt &&
14
- new Date(entry.bufferEndAt) > startAt);
15
- if (clash)
16
- throw new Error('That window has just been taken — pick another slot.');
17
- const booking = {
18
- id: `bk_mock_${Date.now()}`,
19
- productId: params.productId,
20
- resourceId: params.resourceId,
21
- variantId: params.variantId,
22
- startAt: startAt.toISOString(),
23
- endAt: endAt.toISOString(),
24
- bufferEndAt: bufferEndAt.toISOString(),
25
- customerId: params.customerId,
26
- status: ReservationStatus.HELD,
27
- expiresAt: new Date(Date.now() + HOLD_MINUTES * 60000).toISOString(),
28
- resourceName: MOCK_BOOKING_RESOURCES.find(({ id }) => id === params.resourceId)?.name,
29
- };
30
- // Held in the same list availability reads, so the slot really does disappear.
31
- MOCK_BOOKINGS.push(booking);
32
- return { booking, timestamp: new Date().toISOString() };
33
- };
@@ -1,24 +0,0 @@
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: the server refuses a window it cannot line up with its own grid, 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
- /** The claim. `expiresAt` says how long it survives unpaid; `id` is what you confirm or cancel. */
21
- booking: CFBooking;
22
- timestamp: string;
23
- }
24
- export type HoldBooking = (params: HoldBookingParams) => Promise<HoldBookingResponse>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
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;
@@ -1,8 +0,0 @@
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
- };
@@ -1,2 +0,0 @@
1
- import { RemoveBookingFromCart } from './types';
2
- export declare const mockRemoveBookingFromCart: RemoveBookingFromCart;
@@ -1,16 +0,0 @@
1
- import { MOCK_BOOKINGS } from '../../demo/database';
2
- export const mockRemoveBookingFromCart = async (params) => {
3
- console.log('[Mock] removeBookingFromCart called', params);
4
- // The hold has to go back, or the mock is a trap: `addBookingToCart` pushes into the very list
5
- // availability reads, so add → remove → add the same slot used to refuse forever with "that
6
- // window has just been taken". The reservation id the mock hands out is `res_<booking.id>`,
7
- // which is the only link back to the row.
8
- const bookingId = params.reservationInternalId.replace(/^res_/, '');
9
- const index = MOCK_BOOKINGS.findIndex(({ id }) => id === bookingId);
10
- const [released] = index >= 0 ? MOCK_BOOKINGS.splice(index, 1) : [];
11
- return {
12
- reservationInternalId: params.reservationInternalId,
13
- booking: released,
14
- timestamp: new Date().toISOString(),
15
- };
16
- };
@@ -1,12 +0,0 @@
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
- reservationInternalId: string;
8
- /** The released hold, so the caller can see it is no longer held. */
9
- booking?: CFBooking;
10
- timestamp: string;
11
- }
12
- export type RemoveBookingFromCart = (params: RemoveBookingFromCartParams) => Promise<RemoveBookingFromCartResponse>;