@final-commerce/command-frame 0.8.0-online.3 → 0.8.0-staging.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 +42 -0
  6. package/dist/actions/add-booking-to-cart/types.d.ts +23 -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 +10 -0
  11. package/dist/actions/cancel-booking/types.d.ts +10 -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 +6 -0
  16. package/dist/actions/get-booking-availability/types.d.ts +18 -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 +12 -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 +18 -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 +33 -0
  44. package/dist/actions/hold-booking/types.d.ts +24 -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 +26 -0
  51. package/dist/actions/remove-booking-from-cart/types.d.ts +12 -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 +12 -1
  59. package/dist/demo/database.js +127 -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 +2 -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,27 @@
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';
@@ -0,0 +1,8 @@
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';
@@ -0,0 +1,3 @@
1
+ export * from './booking-created/types';
2
+ export * from './booking-updated/types';
3
+ export * from './booking-setup-changed/types';
@@ -1,5 +1,5 @@
1
- import type { CFActiveProduct, CFModifierSelection } from "../../../../CommonTypes";
2
- import type { TopicEvent } from "../../../types";
1
+ import type { CFActiveProduct, CFModifierSelection } from '../../../../CommonTypes';
2
+ import type { TopicEvent } from '../../../types';
3
3
  /**
4
4
  * Payload for product-modifiers-updated event (FT-0010) — fired when a cart
5
5
  * line's modifier selections are replaced via setProductModifierSelections.
@@ -2,37 +2,37 @@
2
2
  * Cart Topic Types
3
3
  * Aggregated types for all cart-related events
4
4
  */
5
- export * from "./cart-created/types";
6
- export * from "./customer-assigned/types";
7
- export * from "./product-added/types";
8
- export * from "./product-deleted/types";
9
- export * from "./product-updated/types";
10
- export * from "./cart-discount-added/types";
11
- export * from "./cart-discount-removed/types";
12
- export * from "./cart-fee-added/types";
13
- export * from "./cart-fee-removed/types";
14
- export * from "./product-discount-added/types";
15
- export * from "./product-discount-removed/types";
16
- export * from "./product-fee-added/types";
17
- export * from "./product-fee-removed/types";
18
- export * from "./product-note-added/types";
19
- export * from "./product-note-removed/types";
20
- export * from "./product-modifiers-updated/types";
21
- import type { CartCreatedPayload } from "./cart-created/types";
22
- import type { CartCustomerAssignedPayload } from "./customer-assigned/types";
23
- import type { ProductAddedPayload } from "./product-added/types";
24
- import type { ProductDeletedPayload } from "./product-deleted/types";
25
- import type { CartProductUpdatedPayload } from "./product-updated/types";
26
- import type { CartDiscountAddedPayload } from "./cart-discount-added/types";
27
- import type { CartDiscountRemovedPayload } from "./cart-discount-removed/types";
28
- import type { CartFeeAddedPayload } from "./cart-fee-added/types";
29
- import type { CartFeeRemovedPayload } from "./cart-fee-removed/types";
30
- import type { ProductDiscountAddedPayload } from "./product-discount-added/types";
31
- import type { ProductDiscountRemovedPayload } from "./product-discount-removed/types";
32
- import type { ProductFeeAddedPayload } from "./product-fee-added/types";
33
- import type { ProductFeeRemovedPayload } from "./product-fee-removed/types";
34
- import type { ProductNoteAddedPayload } from "./product-note-added/types";
35
- import type { ProductNoteRemovedPayload } from "./product-note-removed/types";
36
- import type { ProductModifiersUpdatedPayload } from "./product-modifiers-updated/types";
5
+ export * from './cart-created/types';
6
+ export * from './customer-assigned/types';
7
+ export * from './product-added/types';
8
+ export * from './product-deleted/types';
9
+ export * from './product-updated/types';
10
+ export * from './cart-discount-added/types';
11
+ export * from './cart-discount-removed/types';
12
+ export * from './cart-fee-added/types';
13
+ export * from './cart-fee-removed/types';
14
+ export * from './product-discount-added/types';
15
+ export * from './product-discount-removed/types';
16
+ export * from './product-fee-added/types';
17
+ export * from './product-fee-removed/types';
18
+ export * from './product-note-added/types';
19
+ export * from './product-note-removed/types';
20
+ export * from './product-modifiers-updated/types';
21
+ import type { CartCreatedPayload } from './cart-created/types';
22
+ import type { CartCustomerAssignedPayload } from './customer-assigned/types';
23
+ import type { ProductAddedPayload } from './product-added/types';
24
+ import type { ProductDeletedPayload } from './product-deleted/types';
25
+ import type { CartProductUpdatedPayload } from './product-updated/types';
26
+ import type { CartDiscountAddedPayload } from './cart-discount-added/types';
27
+ import type { CartDiscountRemovedPayload } from './cart-discount-removed/types';
28
+ import type { CartFeeAddedPayload } from './cart-fee-added/types';
29
+ import type { CartFeeRemovedPayload } from './cart-fee-removed/types';
30
+ import type { ProductDiscountAddedPayload } from './product-discount-added/types';
31
+ import type { ProductDiscountRemovedPayload } from './product-discount-removed/types';
32
+ import type { ProductFeeAddedPayload } from './product-fee-added/types';
33
+ import type { ProductFeeRemovedPayload } from './product-fee-removed/types';
34
+ import type { ProductNoteAddedPayload } from './product-note-added/types';
35
+ import type { ProductNoteRemovedPayload } from './product-note-removed/types';
36
+ import type { ProductModifiersUpdatedPayload } from './product-modifiers-updated/types';
37
37
  export type CartEventPayload = CartCreatedPayload | CartCustomerAssignedPayload | ProductAddedPayload | ProductDeletedPayload | CartProductUpdatedPayload | CartDiscountAddedPayload | CartDiscountRemovedPayload | CartFeeAddedPayload | CartFeeRemovedPayload | ProductDiscountAddedPayload | ProductDiscountRemovedPayload | ProductFeeAddedPayload | ProductFeeRemovedPayload | ProductNoteAddedPayload | ProductNoteRemovedPayload | ProductModifiersUpdatedPayload;
38
- export type CartEventType = "cart-created" | "customer-assigned" | "customer-unassigned" | "product-added" | "product-deleted" | "product-updated" | "cart-discount-added" | "cart-discount-removed" | "cart-fee-added" | "cart-fee-removed" | "product-discount-added" | "product-discount-removed" | "product-fee-added" | "product-fee-removed" | "product-note-added" | "product-note-removed" | "product-modifiers-updated";
38
+ export type CartEventType = 'cart-created' | 'customer-assigned' | 'customer-unassigned' | 'product-added' | 'product-deleted' | 'product-updated' | 'cart-discount-added' | 'cart-discount-removed' | 'cart-fee-added' | 'cart-fee-removed' | 'product-discount-added' | 'product-discount-removed' | 'product-fee-added' | 'product-fee-removed' | 'product-note-added' | 'product-note-removed' | 'product-modifiers-updated';
@@ -3,19 +3,19 @@
3
3
  * Aggregated types for all cart-related events
4
4
  */
5
5
  // Re-export all event types
6
- export * from "./cart-created/types";
7
- export * from "./customer-assigned/types";
8
- export * from "./product-added/types";
9
- export * from "./product-deleted/types";
10
- export * from "./product-updated/types";
11
- export * from "./cart-discount-added/types";
12
- export * from "./cart-discount-removed/types";
13
- export * from "./cart-fee-added/types";
14
- export * from "./cart-fee-removed/types";
15
- export * from "./product-discount-added/types";
16
- export * from "./product-discount-removed/types";
17
- export * from "./product-fee-added/types";
18
- export * from "./product-fee-removed/types";
19
- export * from "./product-note-added/types";
20
- export * from "./product-note-removed/types";
21
- export * from "./product-modifiers-updated/types";
6
+ export * from './cart-created/types';
7
+ export * from './customer-assigned/types';
8
+ export * from './product-added/types';
9
+ export * from './product-deleted/types';
10
+ export * from './product-updated/types';
11
+ export * from './cart-discount-added/types';
12
+ export * from './cart-discount-removed/types';
13
+ export * from './cart-fee-added/types';
14
+ export * from './cart-fee-removed/types';
15
+ export * from './product-discount-added/types';
16
+ export * from './product-discount-removed/types';
17
+ export * from './product-fee-added/types';
18
+ export * from './product-fee-removed/types';
19
+ export * from './product-note-added/types';
20
+ export * from './product-note-removed/types';
21
+ export * from './product-modifiers-updated/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 "./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";
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';
@@ -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 "./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";
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';
@@ -4,7 +4,6 @@ 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";
8
7
  import { SplitPaymentsEventType, SplitPaymentsEventPayload } from "./split-payments/types";
9
8
  import { CustomTablesEventPayload, CustomTablesEventType } from "./custom-tables/types";
10
9
  import { PrintEventType, PrintEventPayload } from "./print/types";
@@ -16,6 +15,7 @@ import { VariantsEventType, VariantsEventPayload } from "./variants/types";
16
15
  import { TransactionsEventType, TransactionsEventPayload } from "./transactions/types";
17
16
  import { CategoriesEventType, CategoriesEventPayload } from "./categories/types";
18
17
  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,13 +23,6 @@ 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>;
33
26
  "split-payments": Record<SplitPaymentsEventType, SplitPaymentsEventPayload>;
34
27
  customTables: Record<CustomTablesEventType, CustomTablesEventPayload>;
35
28
  print: Record<PrintEventType, PrintEventPayload>;
@@ -41,4 +34,5 @@ export interface TopicEventPayloadMap {
41
34
  transactions: Record<TransactionsEventType, TransactionsEventPayload>;
42
35
  categories: Record<CategoriesEventType, CategoriesEventPayload>;
43
36
  attributes: Record<AttributesEventType, AttributesEventPayload>;
37
+ bookings: Record<BookingsEventType, BookingsEventPayload>;
44
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@final-commerce/command-frame",
3
- "version": "0.8.0-online.3",
3
+ "version": "0.8.0-staging.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.2.4-preprod.1"
60
+ "@final-commerce/common": "2.4.0-staging.1"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@commitlint/cli": "^19.0.0",
@@ -1,6 +0,0 @@
1
- /**
2
- * Resume Checkout action
3
- * Calls the resumeCheckout action on the parent window
4
- */
5
- import type { ResumeCheckout } from './types';
6
- export declare const resumeCheckout: ResumeCheckout;
@@ -1,8 +0,0 @@
1
- /**
2
- * Resume Checkout action
3
- * Calls the resumeCheckout action on the parent window
4
- */
5
- import { commandFrameClient } from '../../client';
6
- export const resumeCheckout = async (params) => {
7
- return await commandFrameClient.call('resumeCheckout', params ?? {});
8
- };
@@ -1,16 +0,0 @@
1
- import { ResumeCheckout } from './types';
2
- /**
3
- * Standalone mock of the checkout return leg.
4
- *
5
- * It reads the SAME query parameters the real provider sends a shopper back
6
- * with, so a builder can exercise the redirect path in preview by appending
7
- * them by hand:
8
- *
9
- * ?sessionId=CS_MOCK&redirectResult=MOCK
10
- *
11
- * Without them it answers `{ resumed: false }` and does nothing, which is what
12
- * the real command does on an ordinary page load. That is the branch a
13
- * checkout screen hits on every normal visit, so it is the one worth getting
14
- * right in a mock.
15
- */
16
- export declare const mockResumeCheckout: ResumeCheckout;
@@ -1,51 +0,0 @@
1
- import { mockPublishEvent } from '../../demo/database';
2
- /**
3
- * Standalone mock of the checkout return leg.
4
- *
5
- * It reads the SAME query parameters the real provider sends a shopper back
6
- * with, so a builder can exercise the redirect path in preview by appending
7
- * them by hand:
8
- *
9
- * ?sessionId=CS_MOCK&redirectResult=MOCK
10
- *
11
- * Without them it answers `{ resumed: false }` and does nothing, which is what
12
- * the real command does on an ordinary page load. That is the branch a
13
- * checkout screen hits on every normal visit, so it is the one worth getting
14
- * right in a mock.
15
- */
16
- export const mockResumeCheckout = async (params) => {
17
- console.log('[Mock] resumeCheckout called', params);
18
- const href = params?.url ?? (typeof window === 'undefined' ? '' : window.location.href);
19
- let redirectResult = null;
20
- try {
21
- redirectResult = new URL(href).searchParams.get('redirectResult');
22
- }
23
- catch {
24
- redirectResult = null;
25
- }
26
- if (!redirectResult) {
27
- return {
28
- success: true,
29
- timestamp: new Date().toISOString(),
30
- checkout: { resumed: false },
31
- };
32
- }
33
- const suffix = String(Date.now()).slice(-6);
34
- const checkout = {
35
- resumed: true,
36
- orderId: `mock-order-${suffix}`,
37
- receiptId: `ON-001-${suffix}`,
38
- // `Authorised` is what the real provider reports for a completed redirect.
39
- // It is NOT settlement — see the checkout topic docs.
40
- resultCode: 'Authorised',
41
- sessionResult: `mock-session-result-${suffix}`,
42
- orderPassword: `mock-pw-${suffix}`,
43
- };
44
- mockPublishEvent('checkout', 'payment-completed', {
45
- orderId: checkout.orderId,
46
- receiptId: checkout.receiptId,
47
- resultCode: checkout.resultCode,
48
- sessionResult: checkout.sessionResult,
49
- });
50
- return { success: true, timestamp: new Date().toISOString(), checkout };
51
- };
@@ -1,59 +0,0 @@
1
- export interface ResumeCheckoutParams {
2
- /**
3
- * Where to read the provider's return data from. Defaults to the current
4
- * page URL, which is where the shopper has just landed.
5
- *
6
- * Only override this if you moved the query string somewhere else before
7
- * calling — for example if your router strips it on mount.
8
- */
9
- url?: string;
10
- }
11
- /**
12
- * What the return leg produced. Every field past `resumed` is absent when
13
- * `resumed` is `false`.
14
- */
15
- export interface ResumeCheckoutResult {
16
- /**
17
- * `false` means THIS WAS AN ORDINARY PAGE LOAD — no provider return data was
18
- * in the URL, so there was nothing to finish and nothing happened. It is not
19
- * an error, and it is the answer on every normal visit to the page. Call this
20
- * unconditionally when your checkout or confirmation screen mounts and branch
21
- * on this field.
22
- */
23
- resumed: boolean;
24
- orderId?: string;
25
- receiptId?: string;
26
- /**
27
- * The provider's result code for the completed attempt, e.g. `Authorised` or
28
- * `Refused`. As everywhere else in this topic, `Authorised` is an
29
- * authorisation and NOT a settlement.
30
- */
31
- resultCode?: string;
32
- /** Opaque proof of the payment — see `PaymentCompletedPayload.sessionResult`. */
33
- sessionResult?: string;
34
- /**
35
- * The one-time order password from the original checkout, recovered from
36
- * browser storage. The page that held it in memory is gone, so this is the
37
- * only way back to the order's status after a redirect.
38
- */
39
- orderPassword?: string;
40
- }
41
- export interface ResumeCheckoutResponse {
42
- success: boolean;
43
- timestamp: string;
44
- checkout: ResumeCheckoutResult;
45
- }
46
- /**
47
- * Finish a checkout the shopper was redirected away from.
48
- *
49
- * SAFE TO CALL ON EVERY PAGE LOAD, and that is how it is meant to be used: on
50
- * an ordinary visit it finds no return data and answers `{ resumed: false }`
51
- * without touching the network. Calling it twice for one return is also safe —
52
- * the return data is consumed the first time.
53
- *
54
- * The outcome is ALSO published on the `checkout` topic (`payment-completed` or
55
- * `payment-failed`), exactly as it would have been had the shopper never left,
56
- * so a page that already subscribes needs no second code path. Subscribe first,
57
- * then call this, or the event fires before you are listening.
58
- */
59
- export type ResumeCheckout = (params?: ResumeCheckoutParams) => Promise<ResumeCheckoutResponse>;
@@ -1,13 +0,0 @@
1
- // Resume Checkout Types
2
- //
3
- // The RETURN LEG of an online checkout. Some payment methods — and 3-D Secure
4
- // on a card — take the shopper away to their bank or wallet and send them back
5
- // to `returnUrl` on a FRESH PAGE LOAD. The payment is not finished at that
6
- // point: the provider hands the browser a one-time result in the URL, and it
7
- // has to be handed back to the provider to complete the charge.
8
- //
9
- // `startCheckout` cannot do this. It ran in the page that is now gone.
10
- //
11
- // Served ONLY by the storefront runtime (a published website), like
12
- // `startCheckout`. On a register it does not exist.
13
- export {};
@@ -1,6 +0,0 @@
1
- /**
2
- * Start Checkout action
3
- * Calls the startCheckout action on the parent window
4
- */
5
- import type { StartCheckout } from './types';
6
- export declare const startCheckout: StartCheckout;
@@ -1,8 +0,0 @@
1
- /**
2
- * Start Checkout action
3
- * Calls the startCheckout action on the parent window
4
- */
5
- import { commandFrameClient } from '../../client';
6
- export const startCheckout = async (params) => {
7
- return await commandFrameClient.call('startCheckout', params);
8
- };
@@ -1,16 +0,0 @@
1
- import { StartCheckout } from './types';
2
- /**
3
- * Standalone mock of the storefront checkout.
4
- *
5
- * It mirrors the REFUSALS of the real command (empty cart, missing email,
6
- * container not on the page) in the same order, because those are what a
7
- * builder actually hits first — a mock that accepted anything would let a
8
- * checkout screen look finished and fail on the published site.
9
- *
10
- * The mounted box is deliberately labelled as a mock. The real command mounts
11
- * the provider's hosted card fields (iframes owned by the payment provider);
12
- * nothing here takes a card number, and the placeholder must never look like
13
- * it does. Its button publishes `payment-completed` so a flow's subscriber —
14
- * the only way the outcome ever arrives — can be exercised in preview.
15
- */
16
- export declare const mockStartCheckout: StartCheckout;
@@ -1,80 +0,0 @@
1
- import { MOCK_CART, MOCK_COMPANY, mockPublishEvent } from '../../demo/database';
2
- /**
3
- * Standalone mock of the storefront checkout.
4
- *
5
- * It mirrors the REFUSALS of the real command (empty cart, missing email,
6
- * container not on the page) in the same order, because those are what a
7
- * builder actually hits first — a mock that accepted anything would let a
8
- * checkout screen look finished and fail on the published site.
9
- *
10
- * The mounted box is deliberately labelled as a mock. The real command mounts
11
- * the provider's hosted card fields (iframes owned by the payment provider);
12
- * nothing here takes a card number, and the placeholder must never look like
13
- * it does. Its button publishes `payment-completed` so a flow's subscriber —
14
- * the only way the outcome ever arrives — can be exercised in preview.
15
- */
16
- export const mockStartCheckout = async (params) => {
17
- console.log('[Mock] startCheckout called', params);
18
- if (!params)
19
- throw new Error('Params required');
20
- if (!params.contact?.email || !params.contact.email.trim()) {
21
- throw new Error('startCheckout: contact.email is required — it is where the receipt goes');
22
- }
23
- if (!params.container || typeof params.container !== 'string') {
24
- throw new Error('startCheckout: container must be a CSS selector string (e.g. "#card-fields") — a DOM element cannot cross the command boundary');
25
- }
26
- const lineCount = (MOCK_CART.products?.length ?? 0) + (MOCK_CART.customSales?.length ?? 0);
27
- if (!lineCount) {
28
- throw new Error('startCheckout: cannot check out an empty cart');
29
- }
30
- // Resolved BEFORE the order is "created", exactly as the real command does:
31
- // finding out the selector is wrong after an order exists would leave an
32
- // unpaid order behind for a typo that cost nothing to catch first.
33
- const container = typeof document === 'undefined' ? null : document.querySelector(params.container);
34
- if (!container) {
35
- throw new Error(`startCheckout: checkout container "${params.container}" was not found on the page`);
36
- }
37
- const serverTotal = Math.round(MOCK_CART.amountToBeCharged || MOCK_CART.total);
38
- const currency = MOCK_COMPANY.settings?.currency ?? 'USD';
39
- const suffix = String(Date.now()).slice(-6);
40
- const order = {
41
- orderId: `mock-order-${suffix}`,
42
- receiptId: `ON-001-${suffix}`,
43
- serverTotal,
44
- currency,
45
- paymentStatus: 'ready',
46
- orderPassword: `mock-pw-${suffix}`,
47
- };
48
- mockPublishEvent('checkout', 'checkout-started', { ...order });
49
- container.replaceChildren();
50
- const box = document.createElement('div');
51
- box.setAttribute('data-mock-checkout', 'true');
52
- box.style.cssText =
53
- 'border:1px dashed #9aa;border-radius:8px;padding:16px;font:14px system-ui,sans-serif;text-align:center;color:#334';
54
- const label = document.createElement('div');
55
- label.textContent = 'Mock payment fields — the published site shows the real hosted card fields here.';
56
- label.style.cssText = 'margin-bottom:12px;opacity:.75';
57
- const button = document.createElement('button');
58
- button.type = 'button';
59
- button.textContent = `Simulate paying ${(serverTotal / 100).toFixed(2)} ${currency}`;
60
- button.style.cssText =
61
- 'padding:10px 16px;border:0;border-radius:6px;background:#111;color:#fff;font-size:14px;cursor:pointer';
62
- button.addEventListener('click', () => {
63
- button.disabled = true;
64
- // `Authorised` is what the real provider reports for a successful card
65
- // entry. It is NOT settlement — see the checkout topic docs.
66
- mockPublishEvent('checkout', 'payment-completed', {
67
- orderId: order.orderId,
68
- receiptId: order.receiptId,
69
- resultCode: 'Authorised',
70
- });
71
- });
72
- box.appendChild(label);
73
- box.appendChild(button);
74
- container.appendChild(box);
75
- return {
76
- success: true,
77
- timestamp: new Date().toISOString(),
78
- order,
79
- };
80
- };