@final-commerce/command-frame 0.7.0-staging.4 → 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.
- package/dist/CommonTypes.d.ts +1 -11
- package/dist/actions/start-checkout/action.d.ts +6 -0
- package/dist/actions/start-checkout/action.js +8 -0
- package/dist/actions/start-checkout/mock.d.ts +16 -0
- package/dist/actions/start-checkout/mock.js +80 -0
- package/dist/actions/start-checkout/types.d.ts +81 -0
- package/dist/actions/start-checkout/types.js +10 -0
- package/dist/demo/database.d.ts +1 -12
- package/dist/demo/database.js +0 -127
- package/dist/index.d.ts +4 -16
- package/dist/index.js +3 -15
- package/dist/projects/render/mocks.js +2 -14
- package/dist/projects/render/types.d.ts +7 -8
- package/dist/pubsub/topics/checkout/checkout-started/types.d.ts +26 -0
- package/dist/pubsub/topics/checkout/index.d.ts +7 -0
- package/dist/pubsub/topics/checkout/index.js +28 -0
- package/dist/pubsub/topics/checkout/payment-completed/types.d.ts +19 -0
- package/dist/pubsub/topics/checkout/payment-failed/types.d.ts +20 -0
- package/dist/pubsub/topics/checkout/types.d.ts +12 -0
- package/dist/pubsub/topics/checkout/types.js +8 -0
- package/dist/pubsub/topics/index.d.ts +17 -17
- package/dist/pubsub/topics/index.js +17 -17
- package/dist/pubsub/topics/types.d.ts +8 -2
- package/package.json +2 -2
- package/dist/actions/add-booking-to-cart/action.d.ts +0 -6
- package/dist/actions/add-booking-to-cart/action.js +0 -8
- package/dist/actions/add-booking-to-cart/mock.d.ts +0 -2
- package/dist/actions/add-booking-to-cart/mock.js +0 -44
- package/dist/actions/add-booking-to-cart/types.d.ts +0 -23
- package/dist/actions/cancel-booking/action.d.ts +0 -6
- package/dist/actions/cancel-booking/action.js +0 -8
- package/dist/actions/cancel-booking/mock.d.ts +0 -2
- package/dist/actions/cancel-booking/mock.js +0 -10
- package/dist/actions/cancel-booking/types.d.ts +0 -10
- package/dist/actions/get-booking-availability/action.d.ts +0 -6
- package/dist/actions/get-booking-availability/action.js +0 -8
- package/dist/actions/get-booking-availability/mock.d.ts +0 -2
- package/dist/actions/get-booking-availability/mock.js +0 -6
- package/dist/actions/get-booking-availability/types.d.ts +0 -18
- package/dist/actions/get-booking-resources/action.d.ts +0 -6
- package/dist/actions/get-booking-resources/action.js +0 -8
- package/dist/actions/get-booking-resources/mock.d.ts +0 -2
- package/dist/actions/get-booking-resources/mock.js +0 -7
- package/dist/actions/get-booking-resources/types.d.ts +0 -12
- package/dist/actions/get-booking-resources/types.js +0 -1
- package/dist/actions/get-bookings/action.d.ts +0 -6
- package/dist/actions/get-bookings/action.js +0 -8
- package/dist/actions/get-bookings/mock.d.ts +0 -2
- package/dist/actions/get-bookings/mock.js +0 -20
- package/dist/actions/get-bookings/types.d.ts +0 -18
- package/dist/actions/get-bookings/types.js +0 -1
- package/dist/actions/hold-booking/action.d.ts +0 -6
- package/dist/actions/hold-booking/action.js +0 -8
- package/dist/actions/hold-booking/mock.d.ts +0 -2
- package/dist/actions/hold-booking/mock.js +0 -33
- package/dist/actions/hold-booking/types.d.ts +0 -24
- package/dist/actions/hold-booking/types.js +0 -1
- package/dist/actions/remove-booking-from-cart/action.d.ts +0 -6
- package/dist/actions/remove-booking-from-cart/action.js +0 -8
- package/dist/actions/remove-booking-from-cart/mock.d.ts +0 -2
- package/dist/actions/remove-booking-from-cart/mock.js +0 -26
- package/dist/actions/remove-booking-from-cart/types.d.ts +0 -12
- package/dist/actions/remove-booking-from-cart/types.js +0 -1
- package/dist/pubsub/topics/bookings/booking-created/types.d.ts +0 -6
- package/dist/pubsub/topics/bookings/booking-created/types.js +0 -1
- package/dist/pubsub/topics/bookings/booking-setup-changed/types.d.ts +0 -15
- package/dist/pubsub/topics/bookings/booking-setup-changed/types.js +0 -1
- package/dist/pubsub/topics/bookings/booking-updated/types.d.ts +0 -6
- package/dist/pubsub/topics/bookings/booking-updated/types.js +0 -1
- package/dist/pubsub/topics/bookings/index.d.ts +0 -3
- package/dist/pubsub/topics/bookings/index.js +0 -27
- package/dist/pubsub/topics/bookings/types.d.ts +0 -8
- package/dist/pubsub/topics/bookings/types.js +0 -3
- /package/dist/{actions/add-booking-to-cart → pubsub/topics/checkout/checkout-started}/types.js +0 -0
- /package/dist/{actions/cancel-booking → pubsub/topics/checkout/payment-completed}/types.js +0 -0
- /package/dist/{actions/get-booking-availability → pubsub/topics/checkout/payment-failed}/types.js +0 -0
|
@@ -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,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,26 +0,0 @@
|
|
|
1
|
-
import { MOCK_BOOKINGS, MOCK_CART, mockPublishEvent } from '../../demo/database';
|
|
2
|
-
export const mockRemoveBookingFromCart = async (params) => {
|
|
3
|
-
console.log('[Mock] removeBookingFromCart called', params);
|
|
4
|
-
const reservations = MOCK_CART.reservations ?? [];
|
|
5
|
-
const cartIndex = reservations.findIndex(({ internalId }) => internalId === params.reservationInternalId);
|
|
6
|
-
const [removed] = cartIndex >= 0 ? reservations.splice(cartIndex, 1) : [];
|
|
7
|
-
if (removed) {
|
|
8
|
-
const line = removed.total || removed.price * (removed.quantity ?? 1);
|
|
9
|
-
MOCK_CART.subtotal -= line;
|
|
10
|
-
MOCK_CART.total -= line;
|
|
11
|
-
MOCK_CART.amountToBeCharged = MOCK_CART.total;
|
|
12
|
-
MOCK_CART.remainingBalance = MOCK_CART.total;
|
|
13
|
-
mockPublishEvent('cart', 'reservation-removed', { reservation: removed });
|
|
14
|
-
}
|
|
15
|
-
// The hold has to go back, or the mock is a trap: `addBookingToCart` pushes into the very list
|
|
16
|
-
// availability reads, so add → remove → add the same slot used to refuse forever with "that
|
|
17
|
-
// window has just been taken". The reservation id is `res_<booking.id>`, the link back to the row.
|
|
18
|
-
const bookingId = removed?.bookingId ?? params.reservationInternalId.replace(/^res_/, '');
|
|
19
|
-
const index = MOCK_BOOKINGS.findIndex(({ id }) => id === bookingId);
|
|
20
|
-
const [released] = index >= 0 ? MOCK_BOOKINGS.splice(index, 1) : [];
|
|
21
|
-
return {
|
|
22
|
-
reservationInternalId: params.reservationInternalId,
|
|
23
|
-
booking: released,
|
|
24
|
-
timestamp: new Date().toISOString(),
|
|
25
|
-
};
|
|
26
|
-
};
|
|
@@ -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>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { TopicEvent } from '../../../types';
|
|
2
|
-
/**
|
|
3
|
-
* What a booking can be MADE of changed — a rule set, a resource, who serves a product, or where
|
|
4
|
-
* a resource works. Occupancy is untouched.
|
|
5
|
-
*
|
|
6
|
-
* Deliberately carries no row: the change can span several collections at once (a rule set edited
|
|
7
|
-
* AND a product↔resource link removed), and a subscriber cannot act on a partial picture anyway.
|
|
8
|
-
* The only correct reaction is to re-ask `getBookingResources` and `getBookingAvailability`,
|
|
9
|
-
* because both previous answers were computed from the old setup.
|
|
10
|
-
*/
|
|
11
|
-
export interface BookingSetupChangedPayload {
|
|
12
|
-
/** Which collection moved, when the host knows: `booking-rules`, `booking-resources`, … */
|
|
13
|
-
collection?: string;
|
|
14
|
-
}
|
|
15
|
-
export type BookingSetupChangedEvent = TopicEvent<BookingSetupChangedPayload>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export const bookingsTopic = {
|
|
2
|
-
id: 'bookings',
|
|
3
|
-
name: 'Bookings',
|
|
4
|
-
description: 'Topic for bookings synced from the database. A booking IS the occupancy, so this is the ' +
|
|
5
|
-
'signal that somebody else took (or freed) a window: re-ask getBookingAvailability when it ' +
|
|
6
|
-
'fires instead of polling the server on a timer.',
|
|
7
|
-
eventTypes: [
|
|
8
|
-
{
|
|
9
|
-
id: 'booking-created',
|
|
10
|
-
name: 'Booking Created',
|
|
11
|
-
description: 'Published when a booking made elsewhere — another till, the back office — is synced in',
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
id: 'booking-updated',
|
|
15
|
-
name: 'Booking Updated',
|
|
16
|
-
description: 'Published when a synced booking changes: confirmed after payment, cancelled, or expired',
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
id: 'booking-setup-changed',
|
|
20
|
-
name: 'Booking Setup Changed',
|
|
21
|
-
description: 'Published when what a booking can be MADE of changes: a rule set, a resource, who serves ' +
|
|
22
|
-
'a product, or where a resource works. Occupancy is untouched — re-ask getBookingResources ' +
|
|
23
|
-
'and getBookingAvailability, because both answers were computed from the old setup.',
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
};
|
|
27
|
-
export * from './types';
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from './booking-created/types';
|
|
2
|
-
export * from './booking-updated/types';
|
|
3
|
-
export * from './booking-setup-changed/types';
|
|
4
|
-
import type { BookingCreatedPayload } from './booking-created/types';
|
|
5
|
-
import type { BookingUpdatedPayload } from './booking-updated/types';
|
|
6
|
-
import type { BookingSetupChangedPayload } from './booking-setup-changed/types';
|
|
7
|
-
export type BookingsEventPayload = BookingCreatedPayload | BookingUpdatedPayload | BookingSetupChangedPayload;
|
|
8
|
-
export type BookingsEventType = 'booking-created' | 'booking-updated' | 'booking-setup-changed';
|
/package/dist/{actions/add-booking-to-cart → pubsub/topics/checkout/checkout-started}/types.js
RENAMED
|
File without changes
|
|
File without changes
|
/package/dist/{actions/get-booking-availability → pubsub/topics/checkout/payment-failed}/types.js
RENAMED
|
File without changes
|