@lookiero/checkout 0.2.8 → 0.2.9

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 (82) hide show
  1. package/dist/domain/checkout/command/startCheckout.d.ts +12 -0
  2. package/dist/domain/checkout/command/startCheckout.js +4 -0
  3. package/dist/domain/checkout/model/checkout.d.ts +17 -0
  4. package/dist/domain/checkout/model/checkout.js +20 -0
  5. package/dist/domain/checkout/model/checkoutStarted.d.ts +13 -0
  6. package/dist/domain/checkout/model/checkoutStarted.js +4 -0
  7. package/dist/domain/checkout/model/checkouts.d.ts +7 -0
  8. package/dist/domain/checkout/model/checkouts.js +1 -0
  9. package/dist/domain/checkoutBooking/command/bookSizeReplaceableProductVariantsForCheckoutItem.d.ts +0 -1
  10. package/dist/domain/checkoutBooking/model/checkoutBooking.d.ts +0 -1
  11. package/dist/domain/checkoutBooking/model/checkoutBooking.js +1 -3
  12. package/dist/domain/checkoutBooking/model/checkoutBookingBooked.d.ts +0 -1
  13. package/dist/index.d.ts +1 -0
  14. package/dist/index.js +1 -0
  15. package/dist/infrastructure/delivery/bootstrap.js +13 -4
  16. package/dist/infrastructure/delivery/{_mock/bootstrap.mock.js → bootstrap.mock.js} +14 -13
  17. package/dist/infrastructure/domain/checkout/model/httpCheckouts.d.ts +16 -0
  18. package/dist/infrastructure/domain/checkout/model/httpCheckouts.js +21 -0
  19. package/dist/infrastructure/domain/checkout/model/httpCheckoutsStart.d.ts +5 -0
  20. package/dist/infrastructure/domain/checkout/model/httpCheckoutsStart.js +14 -0
  21. package/dist/infrastructure/domain/checkout/react/useStartCheckout.d.ts +13 -0
  22. package/dist/infrastructure/domain/checkout/react/useStartCheckout.js +10 -0
  23. package/dist/infrastructure/domain/checkoutBooking/model/httpCheckoutBookings.js +2 -2
  24. package/dist/infrastructure/domain/{react → checkoutBooking/react}/useBookSizeReplaceableProductVariantsForCheckoutItem.js +2 -3
  25. package/dist/infrastructure/domain/{react → uiSetting/react}/useSetCheckoutIntroShown.js +1 -1
  26. package/dist/infrastructure/domain/{react → uiSetting/react}/useUpdateUiSetting.js +2 -2
  27. package/dist/infrastructure/projection/{httpBookedSizeReplaceableProductVariantsForCheckoutItemView.d.ts → bookedSizeReplaceableProductVariants/httpBookedSizeReplaceableProductVariantsForCheckoutItemView.d.ts} +2 -2
  28. package/dist/infrastructure/projection/{react → bookedSizeReplaceableProductVariants/react}/useViewBookedSizeReplaceableProductVariantsForCheckoutItem.d.ts +1 -1
  29. package/dist/infrastructure/projection/{react → bookedSizeReplaceableProductVariants/react}/useViewBookedSizeReplaceableProductVariantsForCheckoutItem.js +2 -2
  30. package/dist/infrastructure/projection/checkout/checkout.d.ts +53 -0
  31. package/dist/infrastructure/projection/{httpFirstAvailableCheckoutByCustomerIdView.js → checkout/checkout.js} +1 -8
  32. package/dist/infrastructure/projection/checkout/checkout.mock.d.ts +17 -0
  33. package/dist/infrastructure/{delivery/_mock → projection/checkout}/checkout.mock.js +13 -10
  34. package/dist/infrastructure/projection/checkout/httpCheckoutByIdView.d.ts +12 -0
  35. package/dist/infrastructure/projection/checkout/httpCheckoutByIdView.js +9 -0
  36. package/dist/infrastructure/projection/checkout/httpFirstAvailableCheckoutByCustomerIdView.d.ts +12 -0
  37. package/dist/infrastructure/projection/checkout/httpFirstAvailableCheckoutByCustomerIdView.js +9 -0
  38. package/dist/infrastructure/projection/{httpFiveItemsDiscountByCustomerIdView.d.ts → checkout/httpFiveItemsDiscountByCustomerIdView.d.ts} +2 -2
  39. package/dist/infrastructure/projection/{httpIsCheckoutEnabledByCustomerIdView.d.ts → checkout/httpIsCheckoutEnabledByCustomerIdView.d.ts} +2 -2
  40. package/dist/infrastructure/projection/{react → checkout/react}/useViewFirstAvailableCheckoutByCustomerId.d.ts +1 -1
  41. package/dist/infrastructure/projection/{react → checkout/react}/useViewFirstAvailableCheckoutByCustomerId.js +2 -2
  42. package/dist/infrastructure/projection/{react → checkout/react}/useViewFiveItemsDiscountByCustomerId.d.ts +1 -1
  43. package/dist/infrastructure/projection/{react → checkout/react}/useViewFiveItemsDiscountByCustomerId.js +2 -2
  44. package/dist/infrastructure/projection/{react → checkout/react}/useViewIsCheckoutAccessibleByCustomerId.d.ts +1 -1
  45. package/dist/infrastructure/projection/{react → checkout/react}/useViewIsCheckoutAccessibleByCustomerId.js +2 -2
  46. package/dist/infrastructure/projection/uiSetting/react/useViewCheckoutIntroShown.d.ts +2 -0
  47. package/dist/infrastructure/projection/{react → uiSetting/react}/useViewCheckoutIntroShown.js +1 -1
  48. package/dist/infrastructure/projection/{react → uiSetting/react}/useViewUiSettingByKey.d.ts +1 -1
  49. package/dist/infrastructure/projection/{react → uiSetting/react}/useViewUiSettingByKey.js +3 -3
  50. package/dist/infrastructure/projection/{storageUiSettingByKeyView.d.ts → uiSetting/storageUiSettingByKeyView.d.ts} +3 -3
  51. package/dist/infrastructure/ui/Root.js +1 -1
  52. package/dist/infrastructure/ui/components/atoms/price/Price.d.ts +1 -1
  53. package/dist/infrastructure/ui/components/atoms/price/Price.js +2 -2
  54. package/dist/infrastructure/ui/routing/CheckoutAccessibilityMiddleware.d.ts +0 -1
  55. package/dist/infrastructure/ui/routing/CheckoutAccessibilityMiddleware.js +2 -3
  56. package/dist/infrastructure/ui/routing/CheckoutMiddleware.js +3 -3
  57. package/dist/infrastructure/ui/views/intro/Intro.js +6 -6
  58. package/dist/infrastructure/ui/views/item/components/banner/CustomerDecissionBanner.d.ts +1 -1
  59. package/dist/infrastructure/ui/views/item/components/banner/CustomerDecissionBanner.js +3 -3
  60. package/dist/infrastructure/ui/views/item/components/productVariantActions/ProductVariantActions.d.ts +1 -1
  61. package/dist/infrastructure/ui/views/item/components/productVariantActions/ProductVariantActions.js +2 -2
  62. package/dist/infrastructure/ui/views/item/components/productVariantDescription/ProductVariantDescription.d.ts +1 -1
  63. package/dist/infrastructure/ui/views/item/components/productVariantDescription/ProductVariantDescription.js +3 -3
  64. package/dist/infrastructure/ui/views/item/components/productVariantSlider/ProductVariantSlider.d.ts +1 -1
  65. package/dist/projection/checkout/checkout.d.ts +78 -0
  66. package/dist/projection/checkout/checkout.js +29 -0
  67. package/dist/projection/checkout/viewCheckoutById.d.ts +25 -0
  68. package/dist/projection/checkout/viewCheckoutById.js +8 -0
  69. package/dist/projection/checkout/viewFirstAvailableCheckoutByCustomerId.d.ts +3 -83
  70. package/dist/projection/checkout/viewFirstAvailableCheckoutByCustomerId.js +1 -36
  71. package/package.json +3 -1
  72. package/dist/infrastructure/delivery/_mock/checkout.mock.d.ts +0 -9
  73. package/dist/infrastructure/projection/httpFirstAvailableCheckoutByCustomerIdView.d.ts +0 -60
  74. package/dist/infrastructure/projection/react/useViewCheckoutIntroShown.d.ts +0 -2
  75. /package/dist/infrastructure/delivery/{_mock/bootstrap.mock.d.ts → bootstrap.mock.d.ts} +0 -0
  76. /package/dist/infrastructure/domain/{react → checkoutBooking/react}/useBookSizeReplaceableProductVariantsForCheckoutItem.d.ts +0 -0
  77. /package/dist/infrastructure/domain/{react → uiSetting/react}/useSetCheckoutIntroShown.d.ts +0 -0
  78. /package/dist/infrastructure/domain/{react → uiSetting/react}/useUpdateUiSetting.d.ts +0 -0
  79. /package/dist/infrastructure/projection/{httpBookedSizeReplaceableProductVariantsForCheckoutItemView.js → bookedSizeReplaceableProductVariants/httpBookedSizeReplaceableProductVariantsForCheckoutItemView.js} +0 -0
  80. /package/dist/infrastructure/projection/{httpFiveItemsDiscountByCustomerIdView.js → checkout/httpFiveItemsDiscountByCustomerIdView.js} +0 -0
  81. /package/dist/infrastructure/projection/{httpIsCheckoutEnabledByCustomerIdView.js → checkout/httpIsCheckoutEnabledByCustomerIdView.js} +0 -0
  82. /package/dist/infrastructure/projection/{storageUiSettingByKeyView.js → uiSetting/storageUiSettingByKeyView.js} +0 -0
@@ -0,0 +1,12 @@
1
+ import { Command } from "@lookiero/messaging";
2
+ declare const START_CHECKOUT = "start_checkout";
3
+ interface StartCheckoutPayload {
4
+ readonly aggregateId: string;
5
+ }
6
+ interface StartCheckout extends Command<typeof START_CHECKOUT>, StartCheckoutPayload {
7
+ }
8
+ interface StartCheckoutFunction {
9
+ (payload: StartCheckoutPayload): StartCheckout;
10
+ }
11
+ declare const startCheckout: StartCheckoutFunction;
12
+ export { START_CHECKOUT, StartCheckout, startCheckout };
@@ -0,0 +1,4 @@
1
+ import { command } from "@lookiero/messaging";
2
+ const START_CHECKOUT = "start_checkout";
3
+ const startCheckout = ({ aggregateId }) => command({ aggregateId, name: START_CHECKOUT });
4
+ export { START_CHECKOUT, startCheckout };
@@ -0,0 +1,17 @@
1
+ import { AggregateRoot, CommandHandlerFunction } from "@lookiero/messaging";
2
+ import { StartCheckout } from "../command/startCheckout";
3
+ declare enum CheckoutStatus {
4
+ AVAILABLE = "AVAILABLE",
5
+ NOTIFIED = "NOTIFIED",
6
+ STARTED = "STARTED",
7
+ COMPLETED = "COMPLETED"
8
+ }
9
+ interface Checkout extends AggregateRoot {
10
+ readonly status: CheckoutStatus;
11
+ readonly customerId: string;
12
+ readonly boxId: string;
13
+ readonly bookingId: string;
14
+ readonly expiresOn: Date;
15
+ }
16
+ declare const startCheckoutHandler: CommandHandlerFunction<StartCheckout, Checkout>;
17
+ export { Checkout, CheckoutStatus, startCheckoutHandler };
@@ -0,0 +1,20 @@
1
+ import invariant from "tiny-invariant";
2
+ import { checkoutStarted } from "./checkoutStarted";
3
+ var CheckoutStatus;
4
+ (function (CheckoutStatus) {
5
+ CheckoutStatus["AVAILABLE"] = "AVAILABLE";
6
+ CheckoutStatus["NOTIFIED"] = "NOTIFIED";
7
+ CheckoutStatus["STARTED"] = "STARTED";
8
+ CheckoutStatus["COMPLETED"] = "COMPLETED";
9
+ })(CheckoutStatus || (CheckoutStatus = {}));
10
+ const startCheckoutHandler = () => async ({ aggregateRoot, command }) => {
11
+ const { aggregateId } = command;
12
+ invariant(aggregateRoot.status !== CheckoutStatus.STARTED, "Checkout is already started");
13
+ invariant(aggregateRoot.status !== CheckoutStatus.COMPLETED, "Checkout is already completed");
14
+ return {
15
+ ...aggregateRoot,
16
+ status: CheckoutStatus.STARTED,
17
+ domainEvents: checkoutStarted({ aggregateId }),
18
+ };
19
+ };
20
+ export { CheckoutStatus, startCheckoutHandler };
@@ -0,0 +1,13 @@
1
+ import { DomainEvent } from "@lookiero/messaging";
2
+ declare const CHECKOUT_STARTED = "checkout_started";
3
+ interface CheckoutStartedPayload {
4
+ readonly aggregateId: string;
5
+ }
6
+ interface CheckoutStarted extends DomainEvent<typeof CHECKOUT_STARTED>, CheckoutStartedPayload {
7
+ }
8
+ interface CheckoutStartedFunction {
9
+ (payload: CheckoutStartedPayload): CheckoutStarted;
10
+ }
11
+ declare const checkoutStarted: CheckoutStartedFunction;
12
+ export type { CheckoutStarted };
13
+ export { CHECKOUT_STARTED, checkoutStarted };
@@ -0,0 +1,4 @@
1
+ import { domainEvent } from "@lookiero/messaging";
2
+ const CHECKOUT_STARTED = "checkout_started";
3
+ const checkoutStarted = ({ aggregateId }) => domainEvent({ aggregateId, name: CHECKOUT_STARTED });
4
+ export { CHECKOUT_STARTED, checkoutStarted };
@@ -0,0 +1,7 @@
1
+ import { RepositoryGetFunction, RepositoryGetFunctionArgs, RepositorySaveFunction, RepositorySaveFunctionArgs } from "@lookiero/messaging";
2
+ import { Checkout } from "./checkout";
3
+ interface CheckoutsGetFunction<CheckoutsGetFunctionArgs extends RepositoryGetFunctionArgs> extends RepositoryGetFunction<Checkout, CheckoutsGetFunctionArgs> {
4
+ }
5
+ interface CheckoutsSaveFunction<CheckoutsSaveFunctionArgs extends RepositorySaveFunctionArgs> extends RepositorySaveFunction<Checkout, CheckoutsSaveFunctionArgs> {
6
+ }
7
+ export { CheckoutsGetFunction, CheckoutsSaveFunction };
@@ -0,0 +1 @@
1
+ export {};
@@ -4,7 +4,6 @@ interface BookSizeReplaceableProductVariantsForCheckoutItemPayload {
4
4
  readonly aggregateId: string;
5
5
  readonly checkoutId: string;
6
6
  readonly checkoutItemId: string;
7
- readonly checkoutBookingId: string;
8
7
  }
9
8
  interface BookSizeReplaceableProductVariantsForCheckoutItem extends Command<typeof BOOK_SIZE_REPLACEABLE_PRODUCT_VARIANTS_FOR_CHECKOUT_ITEM>, BookSizeReplaceableProductVariantsForCheckoutItemPayload {
10
9
  }
@@ -3,7 +3,6 @@ import { BookSizeReplaceableProductVariantsForCheckoutItem } from "../command/bo
3
3
  interface CheckoutBooking extends AggregateRoot {
4
4
  readonly checkoutId: string;
5
5
  readonly checkoutItemId: string;
6
- readonly checkoutBookingId: string;
7
6
  }
8
7
  declare const bookSizeReplaceableProductVariantsForCheckoutItemHandler: CommandHandlerFunction<BookSizeReplaceableProductVariantsForCheckoutItem, CheckoutBooking>;
9
8
  export { CheckoutBooking, bookSizeReplaceableProductVariantsForCheckoutItemHandler };
@@ -1,16 +1,14 @@
1
1
  import { checkoutBookingBooked } from "./checkoutBookingBooked";
2
2
  const bookSizeReplaceableProductVariantsForCheckoutItemHandler = () => async ({ aggregateRoot, command }) => {
3
- const { aggregateId, checkoutId, checkoutItemId, checkoutBookingId } = command;
3
+ const { aggregateId, checkoutId, checkoutItemId } = command;
4
4
  return {
5
5
  ...aggregateRoot,
6
6
  checkoutId,
7
7
  checkoutItemId,
8
- checkoutBookingId,
9
8
  domainEvents: checkoutBookingBooked({
10
9
  aggregateId,
11
10
  checkoutId,
12
11
  checkoutItemId,
13
- checkoutBookingId,
14
12
  }),
15
13
  };
16
14
  };
@@ -4,7 +4,6 @@ interface CheckoutBookingBookedPayload {
4
4
  readonly aggregateId: string;
5
5
  readonly checkoutId: string;
6
6
  readonly checkoutItemId: string;
7
- readonly checkoutBookingId: string;
8
7
  }
9
8
  interface CheckoutBookingBooked extends DomainEvent<typeof CHECKOUT_BOOKING_BOOKED>, CheckoutBookingBookedPayload {
10
9
  }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { EndpointFunction } from "@lookiero/i18n";
2
2
  import { FC } from "react";
3
+ import "react-native-get-random-values";
3
4
  import { RootProps } from "./infrastructure/ui/Root";
4
5
  import { IsCheckoutAccessibleByCustomerIdProjection } from "./projection/checkout/viewIsCheckoutAccessibleByCustomerId";
5
6
  interface IsCheckoutAccessibleFunctionArgs {
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { fetchFetchTranslation } from "@lookiero/i18n";
2
2
  import { i18n } from "@lookiero/i18n-react";
3
+ import "react-native-get-random-values";
3
4
  import { bootstrap as checkoutBootstrap } from "./infrastructure/delivery/bootstrap";
4
5
  import { root } from "./infrastructure/ui/Root";
5
6
  import { viewIsCheckoutAccessibleByCustomerId, } from "./projection/checkout/viewIsCheckoutAccessibleByCustomerId";
@@ -1,23 +1,31 @@
1
1
  import { bootstrap as messagingBootstrap } from "@lookiero/messaging-react";
2
+ import { START_CHECKOUT } from "../../domain/checkout/command/startCheckout";
3
+ import { startCheckoutHandler } from "../../domain/checkout/model/checkout";
2
4
  import { UPDATE_UI_SETTING } from "../../domain/uiSetting/command/updateUiSetting";
3
5
  import { updateUiSettingHandler } from "../../domain/uiSetting/model/uiSetting";
6
+ import { viewCheckoutByIdHandler, VIEW_CHECKOUT_BY_ID } from "../../projection/checkout/viewCheckoutById";
4
7
  import { viewFirstAvailableCheckoutByCustomerIdHandler, VIEW_FIRST_AVAILABLE_CHECKOUT_BY_CUSTOMER_ID, } from "../../projection/checkout/viewFirstAvailableCheckoutByCustomerId";
5
8
  import { viewFiveItemsDiscountByCustomerIdHandler, VIEW_FIVE_ITEMS_DISCOUNT_BY_CUSTOMER_ID, } from "../../projection/checkout/viewFiveItemsDiscountByCustomerId";
6
9
  import { viewIsCheckoutAccessibleByCustomerIdHandler, VIEW_IS_CHECKOUT_ACCESSIBLE_BY_CUSTOMER_ID, } from "../../projection/checkout/viewIsCheckoutAccessibleByCustomerId";
7
10
  import { viewIsCheckoutEnabledByCustomerIdHandler, VIEW_IS_CHECKOUT_ENABLED_BY_CUSTOMER_ID, } from "../../projection/checkout/viewIsCheckoutEnabledByCustomerId";
8
11
  import { viewUiSettingByKeyHandler, VIEW_UI_SETTING_BY_KEY } from "../../projection/uiSetting/viewUiSettingByKey";
12
+ import { getCheckout, saveCheckout } from "../domain/checkout/model/httpCheckouts";
9
13
  import { getUiSetting, saveUiSetting } from "../domain/uiSetting/model/storageUiSettings";
10
14
  import { read, write } from "../persistence/asyncStorageStorage";
11
- import { httpFirstAvailableCheckoutByCustomerIdView } from "../projection/httpFirstAvailableCheckoutByCustomerIdView";
12
- import { httpFiveItemsDiscountByCustomerIdView } from "../projection/httpFiveItemsDiscountByCustomerIdView";
13
- import { httpIsCheckoutEnabledByCustomerIdView } from "../projection/httpIsCheckoutEnabledByCustomerIdView";
14
- import { storageUiSettingByKeyView } from "../projection/storageUiSettingByKeyView";
15
+ import { httpCheckoutByIdView } from "../projection/checkout/httpCheckoutByIdView";
16
+ import { httpFirstAvailableCheckoutByCustomerIdView } from "../projection/checkout/httpFirstAvailableCheckoutByCustomerIdView";
17
+ import { httpFiveItemsDiscountByCustomerIdView } from "../projection/checkout/httpFiveItemsDiscountByCustomerIdView";
18
+ import { httpIsCheckoutEnabledByCustomerIdView } from "../projection/checkout/httpIsCheckoutEnabledByCustomerIdView";
19
+ import { storageUiSettingByKeyView } from "../projection/uiSetting/storageUiSettingByKeyView";
15
20
  import { fetchHttpGet, fetchHttpPost } from "./http/fetchHttpClient";
16
21
  const CHECKOUT_MESSAGING_REACT_ID = "Checkout";
17
22
  const bootstrap = ({ apiUrl, getAuthToken }) => {
18
23
  const httpGet = fetchHttpGet({ apiUrl, getAuthToken });
19
24
  const httpPost = fetchHttpPost({ apiUrl, getAuthToken });
20
25
  return messagingBootstrap({ id: CHECKOUT_MESSAGING_REACT_ID })
26
+ .query(VIEW_CHECKOUT_BY_ID, viewCheckoutByIdHandler, {
27
+ view: httpCheckoutByIdView({ httpPost }),
28
+ })
21
29
  .query(VIEW_FIRST_AVAILABLE_CHECKOUT_BY_CUSTOMER_ID, viewFirstAvailableCheckoutByCustomerIdHandler, {
22
30
  view: httpFirstAvailableCheckoutByCustomerIdView({ httpPost }),
23
31
  })
@@ -32,6 +40,7 @@ const bootstrap = ({ apiUrl, getAuthToken }) => {
32
40
  view: storageUiSettingByKeyView({ read }),
33
41
  })
34
42
  .command(UPDATE_UI_SETTING, updateUiSettingHandler, {})(getUiSetting, saveUiSetting, { read, write })
43
+ .command(START_CHECKOUT, startCheckoutHandler, {})(getCheckout, saveCheckout, { httpPost })
35
44
  .build();
36
45
  };
37
46
  export { bootstrap, CHECKOUT_MESSAGING_REACT_ID };
@@ -1,17 +1,18 @@
1
1
  import { bootstrap as messagingBootstrap } from "@lookiero/messaging-react";
2
- import { UPDATE_UI_SETTING } from "../../../domain/uiSetting/command/updateUiSetting";
3
- import { updateUiSettingHandler } from "../../../domain/uiSetting/model/uiSetting";
4
- import { CheckoutItemStatus, viewFirstAvailableCheckoutByCustomerIdHandler, VIEW_FIRST_AVAILABLE_CHECKOUT_BY_CUSTOMER_ID, } from "../../../projection/checkout/viewFirstAvailableCheckoutByCustomerId";
5
- import { viewIsCheckoutAccessibleByCustomerIdHandler, VIEW_IS_CHECKOUT_ACCESSIBLE_BY_CUSTOMER_ID, } from "../../../projection/checkout/viewIsCheckoutAccessibleByCustomerId";
6
- import { viewIsCheckoutEnabledByCustomerIdHandler, VIEW_IS_CHECKOUT_ENABLED_BY_CUSTOMER_ID, } from "../../../projection/checkout/viewIsCheckoutEnabledByCustomerId";
7
- import { CHECKOUT_MESSAGING_REACT_ID } from "../bootstrap";
8
- import { viewUiSettingByKeyHandler, VIEW_UI_SETTING_BY_KEY } from "../../../projection/uiSetting/viewUiSettingByKey";
9
- import { getUiSetting, saveUiSetting } from "../../domain/uiSetting/model/storageUiSettings";
10
- import { storageUiSettingByKeyView } from "../../projection/storageUiSettingByKeyView";
11
- import { startedCheckoutWithItems } from "./checkout.mock";
12
- import { read, write } from "../../persistence/asyncStorageStorage";
13
- import { viewFiveItemsDiscountByCustomerIdHandler, VIEW_FIVE_ITEMS_DISCOUNT_BY_CUSTOMER_ID, } from "../../../projection/checkout/viewFiveItemsDiscountByCustomerId";
14
- const firstAvailableCheckoutByCustomerIdView = async () => startedCheckoutWithItems({ status: [CheckoutItemStatus.KEPT, CheckoutItemStatus.INITIAL] });
2
+ import { UPDATE_UI_SETTING } from "../../domain/uiSetting/command/updateUiSetting";
3
+ import { updateUiSettingHandler } from "../../domain/uiSetting/model/uiSetting";
4
+ import { CheckoutItemStatus } from "../../projection/checkout/checkout";
5
+ import { viewFirstAvailableCheckoutByCustomerIdHandler, VIEW_FIRST_AVAILABLE_CHECKOUT_BY_CUSTOMER_ID, } from "../../projection/checkout/viewFirstAvailableCheckoutByCustomerId";
6
+ import { viewFiveItemsDiscountByCustomerIdHandler, VIEW_FIVE_ITEMS_DISCOUNT_BY_CUSTOMER_ID, } from "../../projection/checkout/viewFiveItemsDiscountByCustomerId";
7
+ import { viewIsCheckoutAccessibleByCustomerIdHandler, VIEW_IS_CHECKOUT_ACCESSIBLE_BY_CUSTOMER_ID, } from "../../projection/checkout/viewIsCheckoutAccessibleByCustomerId";
8
+ import { viewIsCheckoutEnabledByCustomerIdHandler, VIEW_IS_CHECKOUT_ENABLED_BY_CUSTOMER_ID, } from "../../projection/checkout/viewIsCheckoutEnabledByCustomerId";
9
+ import { viewUiSettingByKeyHandler, VIEW_UI_SETTING_BY_KEY } from "../../projection/uiSetting/viewUiSettingByKey";
10
+ import { getUiSetting, saveUiSetting } from "../domain/uiSetting/model/storageUiSettings";
11
+ import { read, write } from "../persistence/asyncStorageStorage";
12
+ import { startedCheckoutWithStatusProjection } from "../projection/checkout/checkout.mock";
13
+ import { storageUiSettingByKeyView } from "../projection/uiSetting/storageUiSettingByKeyView";
14
+ import { CHECKOUT_MESSAGING_REACT_ID } from "./bootstrap";
15
+ const firstAvailableCheckoutByCustomerIdView = async () => startedCheckoutWithStatusProjection({ status: [CheckoutItemStatus.KEPT, CheckoutItemStatus.INITIAL] });
15
16
  const isCheckoutEnabledByCustomerIdView = async () => true;
16
17
  const fiveItemsDiscountByCustomerIdView = async () => 25;
17
18
  const bootstrap = () => messagingBootstrap({ id: CHECKOUT_MESSAGING_REACT_ID })
@@ -0,0 +1,16 @@
1
+ import { RepositoryGetFunctionArgs, RepositorySaveFunctionArgs } from "@lookiero/messaging";
2
+ import { CheckoutsGetFunction, CheckoutsSaveFunction } from "../../../../domain/checkout/model/checkouts";
3
+ import { HttpPostFunction } from "../../../delivery/http/httpClient";
4
+ interface HttpCheckoutsGetFunctionArgs extends RepositoryGetFunctionArgs {
5
+ }
6
+ interface HttpCheckoutsGetFunction extends CheckoutsGetFunction<HttpCheckoutsGetFunctionArgs> {
7
+ }
8
+ declare const getCheckout: HttpCheckoutsGetFunction;
9
+ interface HttpCheckoutsSaveFunctionArgs extends RepositorySaveFunctionArgs {
10
+ readonly httpPost: HttpPostFunction;
11
+ }
12
+ interface HttpCheckoutsSaveFunction extends CheckoutsSaveFunction<HttpCheckoutsSaveFunctionArgs> {
13
+ }
14
+ declare const saveCheckout: HttpCheckoutsSaveFunction;
15
+ export type { HttpCheckoutsSaveFunction };
16
+ export { getCheckout, saveCheckout };
@@ -0,0 +1,21 @@
1
+ import invariant from "tiny-invariant";
2
+ import { viewCheckoutById, } from "../../../../projection/checkout/viewCheckoutById";
3
+ import { httpCheckoutsStart } from "./httpCheckoutsStart";
4
+ const toDomain = (checkout) => {
5
+ invariant(checkout, "No checkout found!");
6
+ return {
7
+ id: checkout.id,
8
+ status: checkout.status,
9
+ customerId: checkout.customerId,
10
+ boxId: checkout.boxId,
11
+ bookingId: checkout.bookingId,
12
+ expiresOn: checkout.expiresOn,
13
+ aggregateId: checkout.id,
14
+ domainEvents: [],
15
+ };
16
+ };
17
+ const getCheckout = ({ queryBus }) => async (aggregateId) => toDomain(await queryBus(viewCheckoutById({ checkoutId: aggregateId })));
18
+ const saveCheckout = ({ httpPost }) => async (aggregateRoot) => {
19
+ await httpCheckoutsStart({ httpPost })(aggregateRoot);
20
+ };
21
+ export { getCheckout, saveCheckout };
@@ -0,0 +1,5 @@
1
+ import { HttpCheckoutsSaveFunction } from "./httpCheckouts";
2
+ interface HttpCheckoutsStartFunction extends HttpCheckoutsSaveFunction {
3
+ }
4
+ declare const httpCheckoutsStart: HttpCheckoutsStartFunction;
5
+ export { httpCheckoutsStart };
@@ -0,0 +1,14 @@
1
+ import { CHECKOUT_STARTED } from "../../../../domain/checkout/model/checkoutStarted";
2
+ const isCheckoutStarted = (event) => event.name === CHECKOUT_STARTED;
3
+ const httpCheckoutsStart = ({ httpPost }) => async ({ aggregateId, domainEvents }) => {
4
+ const checkoutEvents = Array.isArray(domainEvents) ? domainEvents : [domainEvents];
5
+ const checkoutStarted = checkoutEvents.find(isCheckoutStarted);
6
+ if (!checkoutStarted) {
7
+ return;
8
+ }
9
+ httpPost({
10
+ endpoint: "/start-checkout",
11
+ body: { checkout_id: aggregateId },
12
+ });
13
+ };
14
+ export { httpCheckoutsStart };
@@ -0,0 +1,13 @@
1
+ import { CommandStatus } from "@lookiero/messaging-react";
2
+ interface StartCheckoutFunction {
3
+ (): Promise<void>;
4
+ }
5
+ interface UseStartCheckoutArgs {
6
+ readonly checkoutId: string;
7
+ }
8
+ declare type UseStartCheckoutResult = [start: StartCheckoutFunction, status: CommandStatus];
9
+ interface UseStartCheckout {
10
+ (args: UseStartCheckoutArgs): UseStartCheckoutResult;
11
+ }
12
+ declare const useStartCheckout: UseStartCheckout;
13
+ export { useStartCheckout };
@@ -0,0 +1,10 @@
1
+ import { useCommand } from "@lookiero/messaging-react";
2
+ import { useCallback } from "react";
3
+ import { startCheckout } from "../../../../domain/checkout/command/startCheckout";
4
+ import { CHECKOUT_MESSAGING_REACT_ID } from "../../../delivery/bootstrap";
5
+ const useStartCheckout = ({ checkoutId }) => {
6
+ const [commandBus, status] = useCommand({ contextId: CHECKOUT_MESSAGING_REACT_ID });
7
+ const start = useCallback(async () => await commandBus(startCheckout({ aggregateId: checkoutId })), [checkoutId, commandBus]);
8
+ return [start, status];
9
+ };
10
+ export { useStartCheckout };
@@ -1,11 +1,11 @@
1
- const saveCheckoutBooking = ({ httpPost }) => async ({ checkoutId, checkoutItemId, checkoutBookingId }) => {
1
+ const saveCheckoutBooking = ({ httpPost }) => async ({ aggregateId, checkoutId, checkoutItemId }) => {
2
2
  try {
3
3
  const response = await httpPost({
4
4
  endpoint: "/book-size-replaceable-product-variants-for-checkout-item",
5
5
  body: {
6
6
  checkout_id: checkoutId,
7
7
  checkout_item_id: checkoutItemId,
8
- checkout_booking_id: checkoutBookingId,
8
+ checkout_booking_id: aggregateId,
9
9
  },
10
10
  });
11
11
  if (!response.ok) {
@@ -1,14 +1,13 @@
1
1
  import { useCommand } from "@lookiero/messaging-react";
2
2
  import { useCallback } from "react";
3
3
  import { v4 as uuid } from "uuid";
4
- import { bookSizeReplaceableProductVariantsForCheckoutItem } from "../../../domain/checkoutBooking/command/bookSizeReplaceableProductVariantsForCheckoutItem";
4
+ import { bookSizeReplaceableProductVariantsForCheckoutItem } from "../../../../domain/checkoutBooking/command/bookSizeReplaceableProductVariantsForCheckoutItem";
5
5
  const useBookSizeReplaceableProductVariantsForCheckoutItem = ({ checkoutId, checkoutItemId, checkoutBookingId }) => {
6
6
  const [commandBus, status] = useCommand();
7
7
  const book = useCallback(async () => await commandBus(bookSizeReplaceableProductVariantsForCheckoutItem({
8
- aggregateId: uuid(),
8
+ aggregateId: checkoutBookingId || uuid(),
9
9
  checkoutId,
10
10
  checkoutItemId,
11
- checkoutBookingId,
12
11
  })), [checkoutBookingId, checkoutId, checkoutItemId, commandBus]);
13
12
  return [book, status];
14
13
  };
@@ -1,5 +1,5 @@
1
1
  import { useCallback } from "react";
2
- import { UISettings } from "../../ui/settings/UISettings";
2
+ import { UISettings } from "../../../ui/settings/UISettings";
3
3
  import { useUpdateUiSetting } from "./useUpdateUiSetting";
4
4
  const useSetCheckoutIntroShown = () => {
5
5
  const [update, status] = useUpdateUiSetting();
@@ -1,8 +1,8 @@
1
1
  import { useCommand } from "@lookiero/messaging-react";
2
2
  import { useCallback } from "react";
3
3
  import { v4 as uuid } from "uuid";
4
- import { updateUiSetting } from "../../../domain/uiSetting/command/updateUiSetting";
5
- import { CHECKOUT_MESSAGING_REACT_ID } from "../../delivery/bootstrap";
4
+ import { updateUiSetting } from "../../../../domain/uiSetting/command/updateUiSetting";
5
+ import { CHECKOUT_MESSAGING_REACT_ID } from "../../../delivery/bootstrap";
6
6
  const useUpdateUiSetting = () => {
7
7
  const [commandBus, status] = useCommand({ contextId: CHECKOUT_MESSAGING_REACT_ID });
8
8
  const update = useCallback(async ({ key, value }) => await commandBus(updateUiSetting({
@@ -1,5 +1,5 @@
1
- import { BookedSizeReplaceableProductVariantsProjection, BookedSizeReplaceableProductVariantsForCheckoutItemView } from "../../projection/bookedSizeReplaceableProductVariants/viewBookedSizeReplaceableProductVariantsForCheckoutItem";
2
- import { HttpPostFunction } from "../delivery/http/httpClient";
1
+ import { BookedSizeReplaceableProductVariantsForCheckoutItemView, BookedSizeReplaceableProductVariantsProjection } from "../../../projection/bookedSizeReplaceableProductVariants/viewBookedSizeReplaceableProductVariantsForCheckoutItem";
2
+ import { HttpPostFunction } from "../../delivery/http/httpClient";
3
3
  interface SizeFormatDto {
4
4
  readonly size: string;
5
5
  readonly format: string;
@@ -1,5 +1,5 @@
1
1
  import { UseQueryFunctionResult } from "@lookiero/messaging-react";
2
- import { BookedSizeReplaceableProductVariantsProjection } from "../../../projection/bookedSizeReplaceableProductVariants/viewBookedSizeReplaceableProductVariantsForCheckoutItem";
2
+ import { BookedSizeReplaceableProductVariantsProjection } from "../../../../projection/bookedSizeReplaceableProductVariants/viewBookedSizeReplaceableProductVariantsForCheckoutItem";
3
3
  interface UseViewBookedSizeReplaceableProductVariantsForCheckoutItemFunctionArgs {
4
4
  readonly checkoutItemId: string;
5
5
  }
@@ -1,6 +1,6 @@
1
1
  import { useQuery } from "@lookiero/messaging-react";
2
- import { viewBookedSizeReplaceableProductVariantsForCheckoutItem, } from "../../../projection/bookedSizeReplaceableProductVariants/viewBookedSizeReplaceableProductVariantsForCheckoutItem";
3
- import { CHECKOUT_MESSAGING_REACT_ID } from "../../delivery/bootstrap";
2
+ import { viewBookedSizeReplaceableProductVariantsForCheckoutItem, } from "../../../../projection/bookedSizeReplaceableProductVariants/viewBookedSizeReplaceableProductVariantsForCheckoutItem";
3
+ import { CHECKOUT_MESSAGING_REACT_ID } from "../../../delivery/bootstrap";
4
4
  const useViewBookedSizeReplaceableProductVariantsForCheckoutItem = ({ checkoutItemId }) => useQuery({
5
5
  query: viewBookedSizeReplaceableProductVariantsForCheckoutItem({ checkoutItemId }),
6
6
  contextId: CHECKOUT_MESSAGING_REACT_ID,
@@ -0,0 +1,53 @@
1
+ import { CheckoutStatus } from "../../../domain/checkout/model/checkout";
2
+ import { CheckoutItemStatus, CheckoutProjection, Currency, MediaPerspective } from "../../../projection/checkout/checkout";
3
+ interface CheckoutItemDto {
4
+ readonly id: string;
5
+ readonly status: CheckoutItemStatus;
6
+ readonly product_variant: {
7
+ readonly id: string;
8
+ readonly media: {
9
+ readonly id: string;
10
+ readonly url: string;
11
+ readonly perspective: MediaPerspective;
12
+ }[];
13
+ readonly brand: string;
14
+ readonly name: string;
15
+ readonly price: {
16
+ readonly amount: number;
17
+ readonly currency: Currency;
18
+ readonly discounted_price?: {
19
+ readonly amount: number;
20
+ readonly percentage: number;
21
+ };
22
+ };
23
+ readonly size: {
24
+ readonly id: string;
25
+ readonly lookiero: string;
26
+ readonly uk: string;
27
+ readonly it: string;
28
+ readonly europe: string;
29
+ readonly unique: boolean;
30
+ readonly visual_order?: number;
31
+ };
32
+ readonly color: {
33
+ readonly id: string;
34
+ readonly label: string;
35
+ };
36
+ };
37
+ readonly replaced_for?: string;
38
+ }
39
+ interface CheckoutDto {
40
+ readonly id: string;
41
+ readonly customer_id: string;
42
+ readonly box_id: string;
43
+ readonly booking_id: string;
44
+ readonly status: CheckoutStatus;
45
+ readonly expires_on: string;
46
+ readonly items: CheckoutItemDto[];
47
+ }
48
+ interface ToCheckoutProjectionFunction {
49
+ (checkoutDto: CheckoutDto): CheckoutProjection;
50
+ }
51
+ declare const toCheckoutProjection: ToCheckoutProjectionFunction;
52
+ export type { CheckoutDto, CheckoutItemDto };
53
+ export { toCheckoutProjection };
@@ -44,11 +44,4 @@ const toCheckoutProjection = (checkoutDto) => ({
44
44
  },
45
45
  })),
46
46
  });
47
- const httpFirstAvailableCheckoutByCustomerIdView = ({ httpPost }) => async ({ customerId }) => {
48
- const response = await httpPost({
49
- endpoint: "/view-first-available-checkout-by-customer-id",
50
- body: { customer_id: customerId },
51
- });
52
- return !response.ok || response.status === 404 ? undefined : toCheckoutProjection((await response.json()).result);
53
- };
54
- export { toCheckoutProjection, httpFirstAvailableCheckoutByCustomerIdView };
47
+ export { toCheckoutProjection };
@@ -0,0 +1,17 @@
1
+ import { CheckoutItemStatus, CheckoutProjection } from "../../../projection/checkout/checkout";
2
+ import { CheckoutDto } from "./checkout";
3
+ interface StartedCheckoutWithStatusDtoFunctionArgs {
4
+ readonly status: CheckoutItemStatus[];
5
+ }
6
+ interface StartedCheckoutWithStatusDtoFunction {
7
+ (args: StartedCheckoutWithStatusDtoFunctionArgs): CheckoutDto;
8
+ }
9
+ declare const startedCheckoutWithStatusDto: StartedCheckoutWithStatusDtoFunction;
10
+ interface StartedCheckoutWithStatusProjectionFunctionArgs {
11
+ readonly status: CheckoutItemStatus[];
12
+ }
13
+ interface StartedCheckoutWithStatusProjectionFunction {
14
+ (args: StartedCheckoutWithStatusProjectionFunctionArgs): CheckoutProjection;
15
+ }
16
+ declare const startedCheckoutWithStatusProjection: StartedCheckoutWithStatusProjectionFunction;
17
+ export { startedCheckoutWithStatusDto, startedCheckoutWithStatusProjection };
@@ -1,9 +1,11 @@
1
1
  import { v4 as uuid } from "uuid";
2
- import { CheckoutStatus, Currency, MediaPerspective, } from "../../../projection/checkout/viewFirstAvailableCheckoutByCustomerId";
3
- const checkoutItem = ({ status }) => ({
2
+ import { CheckoutStatus } from "../../../domain/checkout/model/checkout";
3
+ import { Currency, MediaPerspective, } from "../../../projection/checkout/checkout";
4
+ import { toCheckoutProjection } from "./checkout";
5
+ const checkoutItemDto = ({ status }) => ({
4
6
  id: uuid(),
5
7
  status,
6
- productVariant: {
8
+ product_variant: {
7
9
  id: uuid(),
8
10
  media: [
9
11
  {
@@ -32,14 +34,15 @@ const checkoutItem = ({ status }) => ({
32
34
  },
33
35
  },
34
36
  });
35
- const checkoutWithItems = ({ items }) => ({
37
+ const checkoutWithItemsDto = ({ items }) => ({
36
38
  id: uuid(),
37
39
  status: CheckoutStatus.STARTED,
38
- customerId: uuid(),
39
- boxId: uuid(),
40
- bookingId: uuid(),
41
- expiresOn: new Date("2022-09-20"),
40
+ customer_id: uuid(),
41
+ box_id: uuid(),
42
+ booking_id: uuid(),
43
+ expires_on: "2022-09-20",
42
44
  items,
43
45
  });
44
- const startedCheckoutWithItems = ({ status }) => checkoutWithItems({ items: status.map((status) => checkoutItem({ status })) });
45
- export { startedCheckoutWithItems };
46
+ const startedCheckoutWithStatusDto = ({ status }) => checkoutWithItemsDto({ items: status.map((status) => checkoutItemDto({ status })) });
47
+ const startedCheckoutWithStatusProjection = ({ status }) => toCheckoutProjection(startedCheckoutWithStatusDto({ status }));
48
+ export { startedCheckoutWithStatusDto, startedCheckoutWithStatusProjection };
@@ -0,0 +1,12 @@
1
+ import { CheckoutByIdView } from "../../../projection/checkout/viewCheckoutById";
2
+ import { HttpPostFunction } from "../../delivery/http/httpClient";
3
+ interface HttpCheckoutByIdView extends CheckoutByIdView {
4
+ }
5
+ interface HttpCheckoutByIdViewFunctionArgs {
6
+ readonly httpPost: HttpPostFunction;
7
+ }
8
+ interface HttpCheckoutByIdViewFunction {
9
+ (args: HttpCheckoutByIdViewFunctionArgs): HttpCheckoutByIdView;
10
+ }
11
+ declare const httpCheckoutByIdView: HttpCheckoutByIdViewFunction;
12
+ export { httpCheckoutByIdView };
@@ -0,0 +1,9 @@
1
+ import { toCheckoutProjection } from "./checkout";
2
+ const httpCheckoutByIdView = ({ httpPost }) => async ({ checkoutId }) => {
3
+ const response = await httpPost({
4
+ endpoint: "/view-checkout-by-id",
5
+ body: { checkout_id: checkoutId },
6
+ });
7
+ return !response.ok || response.status === 404 ? undefined : toCheckoutProjection((await response.json()).result);
8
+ };
9
+ export { httpCheckoutByIdView };
@@ -0,0 +1,12 @@
1
+ import { FirstAvailableCheckoutByCustomerIdView } from "../../../projection/checkout/viewFirstAvailableCheckoutByCustomerId";
2
+ import { HttpPostFunction } from "../../delivery/http/httpClient";
3
+ interface HttpFirstAvailableCheckoutByCustomerIdView extends FirstAvailableCheckoutByCustomerIdView {
4
+ }
5
+ interface HttpFirstAvailableCheckoutByCustomerIdViewFunctionArgs {
6
+ readonly httpPost: HttpPostFunction;
7
+ }
8
+ interface HttpFirstAvailableCheckoutByCustomerIdViewFunction {
9
+ (args: HttpFirstAvailableCheckoutByCustomerIdViewFunctionArgs): HttpFirstAvailableCheckoutByCustomerIdView;
10
+ }
11
+ declare const httpFirstAvailableCheckoutByCustomerIdView: HttpFirstAvailableCheckoutByCustomerIdViewFunction;
12
+ export { httpFirstAvailableCheckoutByCustomerIdView };
@@ -0,0 +1,9 @@
1
+ import { toCheckoutProjection } from "./checkout";
2
+ const httpFirstAvailableCheckoutByCustomerIdView = ({ httpPost }) => async ({ customerId }) => {
3
+ const response = await httpPost({
4
+ endpoint: "/view-first-available-checkout-by-customer-id",
5
+ body: { customer_id: customerId },
6
+ });
7
+ return !response.ok || response.status === 404 ? undefined : toCheckoutProjection((await response.json()).result);
8
+ };
9
+ export { httpFirstAvailableCheckoutByCustomerIdView };
@@ -1,5 +1,5 @@
1
- import { FiveItemsDiscountByCustomerIdView } from "../../projection/checkout/viewFiveItemsDiscountByCustomerId";
2
- import { HttpGetFunction } from "../delivery/http/httpClient";
1
+ import { FiveItemsDiscountByCustomerIdView } from "../../../projection/checkout/viewFiveItemsDiscountByCustomerId";
2
+ import { HttpGetFunction } from "../../delivery/http/httpClient";
3
3
  interface HttpFiveItemsDiscountByCustomerIdView extends FiveItemsDiscountByCustomerIdView {
4
4
  }
5
5
  interface HttpFiveItemsDiscountByCustomerIdViewFunctionArgs {
@@ -1,5 +1,5 @@
1
- import { IsCheckoutEnabledByCustomerIdView } from "../../projection/checkout/viewIsCheckoutEnabledByCustomerId";
2
- import { HttpGetFunction } from "../delivery/http/httpClient";
1
+ import { IsCheckoutEnabledByCustomerIdView } from "../../../projection/checkout/viewIsCheckoutEnabledByCustomerId";
2
+ import { HttpGetFunction } from "../../delivery/http/httpClient";
3
3
  interface HttpIsCheckoutEnabledByCustomerIdView extends IsCheckoutEnabledByCustomerIdView {
4
4
  }
5
5
  interface HttpIsCheckoutEnabledByCustomerIdViewFunctionArgs {
@@ -1,5 +1,5 @@
1
1
  import { UseQueryFunctionResult } from "@lookiero/messaging-react";
2
- import { CheckoutProjection } from "../../../projection/checkout/viewFirstAvailableCheckoutByCustomerId";
2
+ import { CheckoutProjection } from "../../../../projection/checkout/checkout";
3
3
  interface UseViewFirstAvailableCheckoutByCustomerIdFunctionArgs {
4
4
  readonly customerId: string;
5
5
  }