@lookiero/checkout 0.8.4-beta.3 → 0.8.5

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 (71) hide show
  1. package/dist/domain/checkout/model/checkout.js +1 -0
  2. package/dist/infrastructure/delivery/http/fetchHttpClient.js +36 -19
  3. package/dist/infrastructure/delivery/http/httpClient.d.ts +9 -3
  4. package/dist/infrastructure/domain/checkout/react/useStartCheckout.d.ts +3 -1
  5. package/dist/infrastructure/domain/checkout/react/useStartCheckout.js +11 -4
  6. package/dist/infrastructure/domain/checkout/react/useSubmitCheckout.d.ts +3 -1
  7. package/dist/infrastructure/domain/checkout/react/useSubmitCheckout.js +19 -6
  8. package/dist/infrastructure/domain/checkoutBooking/react/useBlockCheckoutBooking.d.ts +2 -0
  9. package/dist/infrastructure/domain/checkoutBooking/react/useBlockCheckoutBooking.js +20 -4
  10. package/dist/infrastructure/domain/checkoutBooking/react/useBookCheckoutBookingForCheckoutItem.d.ts +2 -0
  11. package/dist/infrastructure/domain/checkoutBooking/react/useBookCheckoutBookingForCheckoutItem.js +20 -5
  12. package/dist/infrastructure/domain/checkoutFeedback/react/useGiveCheckoutFeedback.d.ts +2 -0
  13. package/dist/infrastructure/domain/checkoutFeedback/react/useGiveCheckoutFeedback.js +20 -5
  14. package/dist/infrastructure/domain/checkoutItem/react/useKeepCheckoutItem.d.ts +2 -0
  15. package/dist/infrastructure/domain/checkoutItem/react/useKeepCheckoutItem.js +19 -4
  16. package/dist/infrastructure/domain/checkoutItem/react/useReplaceCheckoutItem.d.ts +2 -0
  17. package/dist/infrastructure/domain/checkoutItem/react/useReplaceCheckoutItem.js +20 -5
  18. package/dist/infrastructure/domain/checkoutItem/react/useReturnCheckoutItem.d.ts +2 -0
  19. package/dist/infrastructure/domain/checkoutItem/react/useReturnCheckoutItem.js +20 -5
  20. package/dist/infrastructure/domain/uiSetting/react/useUpdateUiSetting.d.ts +5 -1
  21. package/dist/infrastructure/domain/uiSetting/react/useUpdateUiSetting.js +13 -6
  22. package/dist/infrastructure/projection/bookedProductsVariants/httpBookedProductsVariantsForCheckoutItemView.js +9 -8
  23. package/dist/infrastructure/projection/checkout/httpCheckoutByIdView.js +9 -8
  24. package/dist/infrastructure/projection/checkout/httpFirstAvailableCheckoutByCustomerIdView.js +9 -8
  25. package/dist/infrastructure/projection/checkout/httpFiveItemsDiscountByCustomerIdView.js +8 -7
  26. package/dist/infrastructure/projection/checkout/httpIsCheckoutEnabledByCustomerIdView.js +8 -7
  27. package/dist/infrastructure/projection/checkout/react/useViewFirstAvailableCheckoutByCustomerId.js +1 -4
  28. package/dist/infrastructure/projection/checkoutBooking/httpCheckoutBookingByIdView.js +9 -8
  29. package/dist/infrastructure/projection/checkoutItem/httpCheckoutItemByIdView.js +9 -8
  30. package/dist/infrastructure/projection/checkoutQuestion/httpCheckoutQuestionsByCheckoutIdView.js +9 -8
  31. package/dist/infrastructure/projection/payment/httpPaymentFlowPayloadByCheckoutIdView.js +9 -8
  32. package/dist/infrastructure/projection/pricing/httpPricingByCheckoutIdView.js +9 -8
  33. package/dist/infrastructure/projection/returnQuestion/httpReturnQuestionsByCheckoutItemIdView.js +9 -8
  34. package/dist/infrastructure/ui/Root.js +2 -1
  35. package/dist/infrastructure/ui/hooks/usePaymentInstrumentEvents.d.ts +8 -1
  36. package/dist/infrastructure/ui/hooks/usePaymentInstrumentEvents.js +2 -2
  37. package/dist/infrastructure/ui/hooks/useSubmitCheckout.d.ts +2 -0
  38. package/dist/infrastructure/ui/hooks/useSubmitCheckout.js +9 -10
  39. package/dist/infrastructure/ui/i18n/i18n.d.ts +1 -0
  40. package/dist/infrastructure/ui/i18n/i18n.js +1 -0
  41. package/dist/infrastructure/ui/routing/CheckoutMiddleware.js +3 -1
  42. package/dist/infrastructure/ui/views/checkout/components/checkoutPaymentModal/CheckoutPaymentModal.js +3 -0
  43. package/dist/infrastructure/ui/views/checkout/components/paymentInstrument/PaymentInstrument.js +3 -1
  44. package/dist/infrastructure/ui/views/feedback/Feedback.js +3 -0
  45. package/dist/infrastructure/ui/views/item/Item.js +6 -1
  46. package/dist/shared/logging/Logger.d.ts +7 -0
  47. package/dist/shared/logging/Logger.js +1 -0
  48. package/dist/shared/logging/SentryLogger.d.ts +3 -8
  49. package/dist/shared/logging/SentryLogger.js +27 -33
  50. package/dist/shared/logging/SentryLoggerHOC.d.ts +15 -0
  51. package/dist/shared/logging/SentryLoggerHOC.js +24 -0
  52. package/dist/shared/logging/useLogger.d.ts +12 -0
  53. package/dist/shared/logging/useLogger.js +10 -0
  54. package/dist/shared/notifications/infrastructure/domain/notification/react/useCreateNotification.d.ts +2 -0
  55. package/dist/shared/notifications/infrastructure/domain/notification/react/useCreateNotification.js +14 -7
  56. package/dist/shared/notifications/infrastructure/domain/notification/react/useRemoveNotification.d.ts +2 -0
  57. package/dist/shared/notifications/infrastructure/domain/notification/react/useRemoveNotification.js +9 -2
  58. package/dist/shared/notifications/infrastructure/ui/views/Notifications.js +3 -1
  59. package/package.json +2 -1
  60. package/dist/infrastructure/domain/uiSetting/react/useIncrementIntroShownCount.d.ts +0 -10
  61. package/dist/infrastructure/domain/uiSetting/react/useIncrementIntroShownCount.js +0 -11
  62. package/dist/infrastructure/projection/uiSetting/react/useShouldIntroBeShown.d.ts +0 -6
  63. package/dist/infrastructure/projection/uiSetting/react/useShouldIntroBeShown.js +0 -7
  64. package/dist/infrastructure/projection/uiSetting/react/useViewIntroShownCount.d.ts +0 -6
  65. package/dist/infrastructure/projection/uiSetting/react/useViewIntroShownCount.js +0 -9
  66. package/dist/infrastructure/ui/hooks/usePaymentInstrumentUpdateEvents.d.ts +0 -2
  67. package/dist/infrastructure/ui/hooks/usePaymentInstrumentUpdateEvents.js +0 -28
  68. package/dist/infrastructure/ui/views/intro/Intro.d.ts +0 -6
  69. package/dist/infrastructure/ui/views/intro/Intro.js +0 -52
  70. package/dist/infrastructure/ui/views/intro/Intro.style.d.ts +0 -52
  71. package/dist/infrastructure/ui/views/intro/Intro.style.js +0 -55
@@ -11,6 +11,7 @@ var CheckoutStatus;
11
11
  })(CheckoutStatus || (CheckoutStatus = {}));
12
12
  const startCheckoutHandler = () => async ({ aggregateRoot, command }) => {
13
13
  const { aggregateId } = command;
14
+ invariant(aggregateRoot.status !== CheckoutStatus.STARTED, "Checkout is already started");
14
15
  invariant(aggregateRoot.status !== CheckoutStatus.SUBMITTED, "Checkout is already submitted");
15
16
  invariant(aggregateRoot.status !== CheckoutStatus.COMPLETED, "Checkout is already completed");
16
17
  return {
@@ -1,20 +1,37 @@
1
- const fetchHttpPost = ({ apiUrl, getAuthToken }) => async ({ endpoint, body, signal }) => fetch(`${apiUrl}${endpoint}`, {
2
- method: "POST",
3
- headers: {
4
- ["Content-Type"]: "application/json",
5
- authorization: `Bearer ${await getAuthToken()}`,
6
- },
7
- body: JSON.stringify(body),
8
- signal,
9
- });
10
- const fetchHttpGet = ({ apiUrl, getAuthToken }) => async ({ endpoint, signal }) => fetch(`${apiUrl}${endpoint}`, {
11
- method: "GET",
12
- credentials: "include",
13
- headers: {
14
- Authorization: `Bearer ${await getAuthToken()}`,
15
- ["Content-Type"]: "application/json",
16
- },
17
- referrer: "",
18
- signal,
19
- });
1
+ const fetchHttpPost = ({ apiUrl, getAuthToken }) => async ({ endpoint, body, signal, result }) => {
2
+ const response = await fetch(`${apiUrl}${endpoint}`, {
3
+ method: "POST",
4
+ headers: {
5
+ ["Content-Type"]: "application/json",
6
+ authorization: `Bearer ${await getAuthToken()}`,
7
+ },
8
+ body: JSON.stringify(body),
9
+ signal,
10
+ });
11
+ return await processResponse({ response, result });
12
+ };
13
+ const fetchHttpGet = ({ apiUrl, getAuthToken }) => async ({ endpoint, signal, result }) => {
14
+ const response = await fetch(`${apiUrl}${endpoint}`, {
15
+ method: "GET",
16
+ credentials: "include",
17
+ headers: {
18
+ Authorization: `Bearer ${await getAuthToken()}`,
19
+ ["Content-Type"]: "application/json",
20
+ },
21
+ referrer: "",
22
+ signal,
23
+ });
24
+ return await processResponse({ response, result });
25
+ };
26
+ const processResponse = async ({ response, result }) => {
27
+ if (response.ok) {
28
+ const responseText = await response.text();
29
+ const responseResult = responseText ? JSON.parse(responseText) : responseText;
30
+ return result?.success(responseResult) ?? responseResult;
31
+ }
32
+ if (result?.error !== undefined) {
33
+ return result.error;
34
+ }
35
+ throw new Error(response.statusText);
36
+ };
20
37
  export { fetchHttpGet, fetchHttpPost };
@@ -1,16 +1,22 @@
1
+ interface HttpFunctionResult {
2
+ readonly error: any;
3
+ readonly success: (response: any) => any;
4
+ }
1
5
  interface HttpGetFunctionArgs {
2
6
  readonly endpoint: string;
3
7
  readonly signal?: AbortSignal;
8
+ readonly result?: HttpFunctionResult;
4
9
  }
5
10
  interface HttpGetFunction {
6
- (args: HttpGetFunctionArgs): Promise<Response>;
11
+ (args: HttpGetFunctionArgs): Promise<any>;
7
12
  }
8
13
  interface HttpPostFunctionArgs {
9
14
  readonly endpoint: string;
10
15
  readonly body: Record<string, unknown>;
11
16
  readonly signal?: AbortSignal;
17
+ readonly result?: HttpFunctionResult;
12
18
  }
13
19
  interface HttpPostFunction {
14
- (args: HttpPostFunctionArgs): Promise<Response>;
20
+ (args: HttpPostFunctionArgs): Promise<any>;
15
21
  }
16
- export type { HttpGetFunction, HttpPostFunction };
22
+ export type { HttpGetFunction, HttpPostFunction, HttpFunctionResult };
@@ -1,9 +1,11 @@
1
1
  import { CommandStatus } from "@lookiero/messaging-react";
2
+ import { Logger } from "../../../../shared/logging/Logger";
2
3
  interface StartCheckoutFunction {
3
- (): Promise<void>;
4
+ (): Promise<void> | undefined;
4
5
  }
5
6
  interface UseStartCheckoutArgs {
6
7
  readonly checkoutId?: string;
8
+ readonly logger: Logger;
7
9
  }
8
10
  type UseStartCheckoutResult = [start: StartCheckoutFunction, status: CommandStatus];
9
11
  interface UseStartCheckout {
@@ -3,12 +3,19 @@ import { useCallback } from "react";
3
3
  import invariant from "tiny-invariant";
4
4
  import { startCheckout } from "../../../../domain/checkout/command/startCheckout";
5
5
  import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
6
- const useStartCheckout = ({ checkoutId }) => {
6
+ const useStartCheckout = ({ checkoutId, logger }) => {
7
7
  const [commandBus, status] = useCommand({ contextId: MESSAGING_CONTEXT_ID });
8
- const start = useCallback(() => {
8
+ const start = useCallback(async () => {
9
9
  invariant(checkoutId, "CheckoutId must be defined in order to start checkout");
10
- return commandBus(startCheckout({ aggregateId: checkoutId }));
11
- }, [checkoutId, commandBus]);
10
+ try {
11
+ return await commandBus(startCheckout({ aggregateId: checkoutId }));
12
+ }
13
+ catch (error) {
14
+ if (!error?.message?.includes("Checkout is already started")) {
15
+ logger.captureException(error);
16
+ }
17
+ }
18
+ }, [checkoutId, commandBus, logger]);
12
19
  return [start, status];
13
20
  };
14
21
  export { useStartCheckout };
@@ -1,10 +1,12 @@
1
1
  import { CommandStatus } from "@lookiero/messaging-react";
2
+ import { Logger } from "../../../../shared/logging/Logger";
2
3
  interface SubmitFunction {
3
- (): Promise<void>;
4
+ (): Promise<void> | undefined;
4
5
  }
5
6
  type UseSubmitCheckout = [submit: SubmitFunction, status: CommandStatus];
6
7
  interface UseSubmitCheckoutFunctionArgs {
7
8
  readonly checkoutId?: string;
9
+ readonly logger: Logger;
8
10
  }
9
11
  interface UseSubmitCheckoutFunction {
10
12
  (args: UseSubmitCheckoutFunctionArgs): UseSubmitCheckout;
@@ -2,15 +2,28 @@ import { useCommand } from "@lookiero/messaging-react";
2
2
  import { useCallback } from "react";
3
3
  import invariant from "tiny-invariant";
4
4
  import { submitCheckout } from "../../../../domain/checkout/command/submitCheckout";
5
+ import { useCreateNotification } from "../../../../shared/notifications";
6
+ import { NotificationLevel } from "../../../../shared/notifications/domain/notification/model/notification";
5
7
  import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
6
- const useSubmitCheckout = ({ checkoutId }) => {
8
+ import { I18nMessages } from "../../../ui/i18n/i18n";
9
+ const useSubmitCheckout = ({ checkoutId, logger }) => {
7
10
  const [commandBus, status] = useCommand({ contextId: MESSAGING_CONTEXT_ID });
8
- const submit = useCallback(() => {
11
+ const [createNotification] = useCreateNotification({ contextId: MESSAGING_CONTEXT_ID, logger });
12
+ const submit = useCallback(async () => {
9
13
  invariant(checkoutId, "CheckoutId must be defined in order to submit checkout");
10
- return commandBus(submitCheckout({
11
- aggregateId: checkoutId,
12
- }));
13
- }, [checkoutId, commandBus]);
14
+ try {
15
+ return await commandBus(submitCheckout({
16
+ aggregateId: checkoutId,
17
+ }));
18
+ }
19
+ catch (error) {
20
+ logger.captureException(error);
21
+ createNotification({
22
+ level: NotificationLevel.ERROR,
23
+ bodyI18nKey: I18nMessages.TOAST_GENERIC_ERROR,
24
+ });
25
+ }
26
+ }, [checkoutId, commandBus, createNotification, logger]);
14
27
  return [submit, status];
15
28
  };
16
29
  export { useSubmitCheckout };
@@ -1,10 +1,12 @@
1
1
  import { CommandStatus } from "@lookiero/messaging-react";
2
+ import { Logger } from "../../../../shared/logging/Logger";
2
3
  interface BlockCheckoutBookingFunction {
3
4
  (): Promise<void>;
4
5
  }
5
6
  type UseBlockCheckoutBooking = [blockCheckoutBooking: BlockCheckoutBookingFunction, status: CommandStatus];
6
7
  interface UseBlockCheckoutBookingFunctionArgs {
7
8
  readonly checkoutBookingId: string;
9
+ readonly logger: Logger;
8
10
  }
9
11
  interface UseBlockCheckoutBookingFunction {
10
12
  (args: UseBlockCheckoutBookingFunctionArgs): UseBlockCheckoutBooking;
@@ -1,12 +1,28 @@
1
1
  import { useCommand } from "@lookiero/messaging-react";
2
2
  import { useCallback } from "react";
3
3
  import { blockCheckoutBooking as blockCheckoutBookingCommand } from "../../../../domain/checkoutBooking/command/blockCheckoutBooking";
4
+ import { useCreateNotification } from "../../../../shared/notifications";
5
+ import { NotificationLevel } from "../../../../shared/notifications/domain/notification/model/notification";
4
6
  import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
5
- const useBlockCheckoutBooking = ({ checkoutBookingId }) => {
7
+ import { I18nMessages } from "../../../ui/i18n/i18n";
8
+ const useBlockCheckoutBooking = ({ checkoutBookingId, logger }) => {
6
9
  const [commandBus, status] = useCommand({ contextId: MESSAGING_CONTEXT_ID });
7
- const blockCheckoutBooking = useCallback(() => commandBus(blockCheckoutBookingCommand({
8
- aggregateId: checkoutBookingId,
9
- })), [checkoutBookingId, commandBus]);
10
+ const [createNotification] = useCreateNotification({ contextId: MESSAGING_CONTEXT_ID, logger });
11
+ const blockCheckoutBooking = useCallback(async () => {
12
+ try {
13
+ await commandBus(blockCheckoutBookingCommand({
14
+ aggregateId: checkoutBookingId,
15
+ }));
16
+ }
17
+ catch (error) {
18
+ logger.captureException(error);
19
+ createNotification({
20
+ level: NotificationLevel.ERROR,
21
+ bodyI18nKey: I18nMessages.TOAST_GENERIC_ERROR,
22
+ });
23
+ throw error;
24
+ }
25
+ }, [checkoutBookingId, commandBus, createNotification, logger]);
10
26
  return [blockCheckoutBooking, status];
11
27
  };
12
28
  export { useBlockCheckoutBooking };
@@ -1,4 +1,5 @@
1
1
  import { CommandStatus } from "@lookiero/messaging-react";
2
+ import { Logger } from "../../../../shared/logging/Logger";
2
3
  interface BookFunction {
3
4
  (): Promise<void>;
4
5
  }
@@ -6,6 +7,7 @@ type UseBookCheckoutBookingForCheckoutItem = [book: BookFunction, status: Comman
6
7
  interface UseBookCheckoutBookingForCheckoutItemFunctionArgs {
7
8
  readonly checkoutItemId: string;
8
9
  readonly checkoutBookingId: string | undefined;
10
+ readonly logger: Logger;
9
11
  }
10
12
  interface UseBookCheckoutBookingForCheckoutItemFunction {
11
13
  (args: UseBookCheckoutBookingForCheckoutItemFunctionArgs): UseBookCheckoutBookingForCheckoutItem;
@@ -2,13 +2,28 @@ import { useCommand } from "@lookiero/messaging-react";
2
2
  import { useCallback } from "react";
3
3
  import { v4 as uuid } from "uuid";
4
4
  import { bookCheckoutBookingForCheckoutItem } from "../../../../domain/checkoutBooking/command/bookCheckoutBookingForCheckoutItem";
5
+ import { useCreateNotification } from "../../../../shared/notifications";
6
+ import { NotificationLevel } from "../../../../shared/notifications/domain/notification/model/notification";
5
7
  import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
6
- const useBookCheckoutBookingForCheckoutItem = ({ checkoutItemId, checkoutBookingId, }) => {
8
+ import { I18nMessages } from "../../../ui/i18n/i18n";
9
+ const useBookCheckoutBookingForCheckoutItem = ({ checkoutItemId, checkoutBookingId, logger, }) => {
7
10
  const [commandBus, status] = useCommand({ contextId: MESSAGING_CONTEXT_ID });
8
- const book = useCallback(() => commandBus(bookCheckoutBookingForCheckoutItem({
9
- aggregateId: checkoutBookingId || uuid(),
10
- checkoutItemId,
11
- })), [checkoutBookingId, checkoutItemId, commandBus]);
11
+ const [createNotification] = useCreateNotification({ contextId: MESSAGING_CONTEXT_ID, logger });
12
+ const book = useCallback(async () => {
13
+ try {
14
+ await commandBus(bookCheckoutBookingForCheckoutItem({
15
+ aggregateId: checkoutBookingId || uuid(),
16
+ checkoutItemId,
17
+ }));
18
+ }
19
+ catch (error) {
20
+ logger.captureException(error);
21
+ createNotification({
22
+ level: NotificationLevel.ERROR,
23
+ bodyI18nKey: I18nMessages.TOAST_GENERIC_ERROR,
24
+ });
25
+ }
26
+ }, [checkoutBookingId, checkoutItemId, commandBus, createNotification, logger]);
12
27
  return [book, status];
13
28
  };
14
29
  export { useBookCheckoutBookingForCheckoutItem };
@@ -1,5 +1,6 @@
1
1
  import { CommandStatus } from "@lookiero/messaging-react";
2
2
  import { Feedbacks } from "../../../../domain/checkoutFeedback/model/feedbacks";
3
+ import { Logger } from "../../../../shared/logging/Logger";
3
4
  interface GiveCheckoutFeedbackFunctionArgs {
4
5
  readonly feedbacks: Feedbacks;
5
6
  }
@@ -9,6 +10,7 @@ interface GiveCheckoutFeedbackFunction {
9
10
  type UseGiveCheckoutFeedback = [giveCheckoutFeedback: GiveCheckoutFeedbackFunction, status: CommandStatus];
10
11
  interface UseGiveCheckoutFeedbackFunctionArgs {
11
12
  readonly checkoutId: string;
13
+ readonly logger: Logger;
12
14
  }
13
15
  interface UseGiveCheckoutFeedbackFunction {
14
16
  (args: UseGiveCheckoutFeedbackFunctionArgs): UseGiveCheckoutFeedback;
@@ -1,13 +1,28 @@
1
1
  import { useCommand } from "@lookiero/messaging-react";
2
2
  import { useCallback } from "react";
3
3
  import { giveCheckoutFeedback as giveCheckoutFeedbackCommand } from "../../../../domain/checkoutFeedback/command/giveCheckoutFeedback";
4
+ import { useCreateNotification } from "../../../../shared/notifications";
5
+ import { NotificationLevel } from "../../../../shared/notifications/domain/notification/model/notification";
4
6
  import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
5
- const useGiveCheckoutFeedback = ({ checkoutId }) => {
7
+ import { I18nMessages } from "../../../ui/i18n/i18n";
8
+ const useGiveCheckoutFeedback = ({ checkoutId, logger }) => {
6
9
  const [commandBus, status] = useCommand({ contextId: MESSAGING_CONTEXT_ID });
7
- const giveCheckoutFeedback = useCallback(({ feedbacks }) => commandBus(giveCheckoutFeedbackCommand({
8
- checkoutId,
9
- feedbacks,
10
- })), [checkoutId, commandBus]);
10
+ const [createNotification] = useCreateNotification({ contextId: MESSAGING_CONTEXT_ID, logger });
11
+ const giveCheckoutFeedback = useCallback(async ({ feedbacks }) => {
12
+ try {
13
+ await commandBus(giveCheckoutFeedbackCommand({
14
+ checkoutId,
15
+ feedbacks,
16
+ }));
17
+ }
18
+ catch (error) {
19
+ logger.captureException(error);
20
+ createNotification({
21
+ level: NotificationLevel.ERROR,
22
+ bodyI18nKey: I18nMessages.TOAST_GENERIC_ERROR,
23
+ });
24
+ }
25
+ }, [checkoutId, commandBus, createNotification, logger]);
11
26
  return [giveCheckoutFeedback, status];
12
27
  };
13
28
  export { useGiveCheckoutFeedback };
@@ -1,9 +1,11 @@
1
1
  import { CommandStatus } from "@lookiero/messaging-react";
2
+ import { Logger } from "../../../../shared/logging/Logger";
2
3
  interface KeepCheckoutItemFunction {
3
4
  (): Promise<void>;
4
5
  }
5
6
  interface UseKeepCheckoutItemFunctionArgs {
6
7
  readonly checkoutItemId: string;
8
+ readonly logger: Logger;
7
9
  }
8
10
  type UseKeepCheckoutItemResult = [keep: KeepCheckoutItemFunction, status: CommandStatus];
9
11
  interface UseKeepCheckoutItemFunction {
@@ -1,12 +1,27 @@
1
1
  import { useCommand } from "@lookiero/messaging-react";
2
2
  import { useCallback } from "react";
3
3
  import { keepCheckoutItem } from "../../../../domain/checkoutItem/command/keepCheckoutItem";
4
+ import { useCreateNotification } from "../../../../shared/notifications";
5
+ import { NotificationLevel } from "../../../../shared/notifications/domain/notification/model/notification";
4
6
  import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
5
- const useKeepCheckoutItem = ({ checkoutItemId }) => {
7
+ import { I18nMessages } from "../../../ui/i18n/i18n";
8
+ const useKeepCheckoutItem = ({ checkoutItemId, logger }) => {
6
9
  const [commandBus, status] = useCommand({ contextId: MESSAGING_CONTEXT_ID });
7
- const keep = useCallback(() => commandBus(keepCheckoutItem({
8
- aggregateId: checkoutItemId,
9
- })), [checkoutItemId, commandBus]);
10
+ const [createNotification] = useCreateNotification({ contextId: MESSAGING_CONTEXT_ID, logger });
11
+ const keep = useCallback(async () => {
12
+ try {
13
+ await commandBus(keepCheckoutItem({
14
+ aggregateId: checkoutItemId,
15
+ }));
16
+ }
17
+ catch (error) {
18
+ logger.captureException(error);
19
+ createNotification({
20
+ level: NotificationLevel.ERROR,
21
+ bodyI18nKey: I18nMessages.TOAST_GENERIC_ERROR,
22
+ });
23
+ }
24
+ }, [checkoutItemId, commandBus, createNotification, logger]);
10
25
  return [keep, status];
11
26
  };
12
27
  export { useKeepCheckoutItem };
@@ -1,4 +1,5 @@
1
1
  import { CommandStatus } from "@lookiero/messaging-react";
2
+ import { Logger } from "../../../../shared/logging/Logger";
2
3
  interface ReplaceCheckoutItemFunctionArgs {
3
4
  readonly replacedForId: string;
4
5
  }
@@ -7,6 +8,7 @@ interface ReplaceCheckoutItemFunction {
7
8
  }
8
9
  interface UseReplaceCheckoutItemFunctionArgs {
9
10
  readonly checkoutItemId: string;
11
+ readonly logger: Logger;
10
12
  }
11
13
  type UseReplaceCheckoutItemResult = [replace: ReplaceCheckoutItemFunction, status: CommandStatus];
12
14
  interface UseReplaceCheckoutItemFunction {
@@ -1,13 +1,28 @@
1
1
  import { useCommand } from "@lookiero/messaging-react";
2
2
  import { useCallback } from "react";
3
3
  import { replaceCheckoutItem } from "../../../../domain/checkoutItem/command/replaceCheckoutItem";
4
+ import { useCreateNotification } from "../../../../shared/notifications";
5
+ import { NotificationLevel } from "../../../../shared/notifications/domain/notification/model/notification";
4
6
  import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
5
- const useReplaceCheckoutItem = ({ checkoutItemId }) => {
7
+ import { I18nMessages } from "../../../ui/i18n/i18n";
8
+ const useReplaceCheckoutItem = ({ checkoutItemId, logger }) => {
6
9
  const [commandBus, status] = useCommand({ contextId: MESSAGING_CONTEXT_ID });
7
- const replace = useCallback(({ replacedForId }) => commandBus(replaceCheckoutItem({
8
- aggregateId: checkoutItemId,
9
- replacedForId,
10
- })), [checkoutItemId, commandBus]);
10
+ const [createNotification] = useCreateNotification({ contextId: MESSAGING_CONTEXT_ID, logger });
11
+ const replace = useCallback(async ({ replacedForId }) => {
12
+ try {
13
+ await commandBus(replaceCheckoutItem({
14
+ aggregateId: checkoutItemId,
15
+ replacedForId,
16
+ }));
17
+ }
18
+ catch (error) {
19
+ logger.captureException(error);
20
+ createNotification({
21
+ level: NotificationLevel.ERROR,
22
+ bodyI18nKey: I18nMessages.TOAST_GENERIC_ERROR,
23
+ });
24
+ }
25
+ }, [checkoutItemId, commandBus, createNotification, logger]);
11
26
  return [replace, status];
12
27
  };
13
28
  export { useReplaceCheckoutItem };
@@ -1,5 +1,6 @@
1
1
  import { CommandStatus } from "@lookiero/messaging-react";
2
2
  import { Feedbacks } from "../../../../domain/checkoutItem/model/feedbacks";
3
+ import { Logger } from "../../../../shared/logging/Logger";
3
4
  interface ReturnCheckoutItemFunctionArgs {
4
5
  readonly feedbacks: Feedbacks;
5
6
  }
@@ -8,6 +9,7 @@ interface ReturnCheckoutItemFunction {
8
9
  }
9
10
  interface UseReturnCheckoutItemFunctionArgs {
10
11
  readonly checkoutItemId: string;
12
+ readonly logger: Logger;
11
13
  }
12
14
  type UseReturnCheckoutItemResult = [returnCheckoutItem: ReturnCheckoutItemFunction, status: CommandStatus];
13
15
  interface UseReturnCheckoutItemFunction {
@@ -1,13 +1,28 @@
1
1
  import { useCommand } from "@lookiero/messaging-react";
2
2
  import { useCallback } from "react";
3
3
  import { returnCheckoutItem as returnCheckoutItemCommand } from "../../../../domain/checkoutItem/command/returnCheckoutItem";
4
+ import { useCreateNotification } from "../../../../shared/notifications";
5
+ import { NotificationLevel } from "../../../../shared/notifications/domain/notification/model/notification";
4
6
  import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
5
- const useReturnCheckoutItem = ({ checkoutItemId }) => {
7
+ import { I18nMessages } from "../../../ui/i18n/i18n";
8
+ const useReturnCheckoutItem = ({ checkoutItemId, logger }) => {
6
9
  const [commandBus, status] = useCommand({ contextId: MESSAGING_CONTEXT_ID });
7
- const returnCheckoutItem = useCallback(({ feedbacks }) => commandBus(returnCheckoutItemCommand({
8
- aggregateId: checkoutItemId,
9
- feedbacks,
10
- })), [checkoutItemId, commandBus]);
10
+ const [createNotification] = useCreateNotification({ contextId: MESSAGING_CONTEXT_ID, logger });
11
+ const returnCheckoutItem = useCallback(async ({ feedbacks }) => {
12
+ try {
13
+ await commandBus(returnCheckoutItemCommand({
14
+ aggregateId: checkoutItemId,
15
+ feedbacks,
16
+ }));
17
+ }
18
+ catch (error) {
19
+ logger.captureException(error);
20
+ createNotification({
21
+ level: NotificationLevel.ERROR,
22
+ bodyI18nKey: I18nMessages.TOAST_GENERIC_ERROR,
23
+ });
24
+ }
25
+ }, [checkoutItemId, commandBus, createNotification, logger]);
11
26
  return [returnCheckoutItem, status];
12
27
  };
13
28
  export { useReturnCheckoutItem };
@@ -1,4 +1,5 @@
1
1
  import { CommandStatus } from "@lookiero/messaging-react";
2
+ import { Logger } from "../../../../shared/logging/Logger";
2
3
  interface UpdateFunctionArgs {
3
4
  readonly key: string;
4
5
  readonly value: unknown;
@@ -7,8 +8,11 @@ interface UpdateFunction {
7
8
  (args: UpdateFunctionArgs): Promise<void>;
8
9
  }
9
10
  type UseUpdateUiSetting = [update: UpdateFunction, status: CommandStatus];
11
+ interface UseUpdateUiSettingArgs {
12
+ readonly logger: Logger;
13
+ }
10
14
  interface UseUpdateUiSettingFunction {
11
- (): UseUpdateUiSetting;
15
+ (args: UseUpdateUiSettingArgs): UseUpdateUiSetting;
12
16
  }
13
17
  declare const useUpdateUiSetting: UseUpdateUiSettingFunction;
14
18
  export { useUpdateUiSetting };
@@ -3,13 +3,20 @@ import { useCallback } from "react";
3
3
  import { v4 as uuid } from "uuid";
4
4
  import { updateUiSetting } from "../../../../domain/uiSetting/command/updateUiSetting";
5
5
  import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
6
- const useUpdateUiSetting = () => {
6
+ const useUpdateUiSetting = ({ logger }) => {
7
7
  const [commandBus, status] = useCommand({ contextId: MESSAGING_CONTEXT_ID });
8
- const update = useCallback(({ key, value }) => commandBus(updateUiSetting({
9
- aggregateId: uuid(),
10
- key,
11
- value,
12
- })), [commandBus]);
8
+ const update = useCallback(async ({ key, value }) => {
9
+ try {
10
+ await commandBus(updateUiSetting({
11
+ aggregateId: uuid(),
12
+ key,
13
+ value,
14
+ }));
15
+ }
16
+ catch (error) {
17
+ logger.captureException(error);
18
+ }
19
+ }, [commandBus, logger]);
13
20
  return [update, status];
14
21
  };
15
22
  export { useUpdateUiSetting };
@@ -1,9 +1,10 @@
1
- const httpBookedProductsVariantsForCheckoutItemView = ({ httpPost }) => async ({ checkoutItemId, signal }) => {
2
- const response = await httpPost({
3
- endpoint: "/view-booked-product-variants-for-checkout-item",
4
- body: { checkoutItemId },
5
- signal,
6
- });
7
- return !response.ok || response.status === 404 ? null : (await response.json()).result;
8
- };
1
+ const httpBookedProductsVariantsForCheckoutItemView = ({ httpPost }) => async ({ checkoutItemId, signal }) => await httpPost({
2
+ endpoint: "/view-booked-product-variants-for-checkout-item",
3
+ body: { checkoutItemId },
4
+ signal,
5
+ result: {
6
+ error: null,
7
+ success: (response) => response.result,
8
+ },
9
+ });
9
10
  export { httpBookedProductsVariantsForCheckoutItemView };
@@ -1,10 +1,11 @@
1
1
  import { toCheckoutProjection } from "./checkout";
2
- const httpCheckoutByIdView = ({ httpPost }) => async ({ checkoutId, signal }) => {
3
- const response = await httpPost({
4
- endpoint: "/view-checkout-by-id",
5
- body: { checkoutId },
6
- signal,
7
- });
8
- return !response.ok || response.status === 404 ? null : toCheckoutProjection((await response.json()).result);
9
- };
2
+ const httpCheckoutByIdView = ({ httpPost }) => async ({ checkoutId, signal }) => await httpPost({
3
+ endpoint: "/view-checkout-by-id",
4
+ body: { checkoutId },
5
+ signal,
6
+ result: {
7
+ error: null,
8
+ success: (response) => toCheckoutProjection(response.result),
9
+ },
10
+ });
10
11
  export { httpCheckoutByIdView };
@@ -1,10 +1,11 @@
1
1
  import { toCheckoutProjection } from "./checkout";
2
- const httpFirstAvailableCheckoutByCustomerIdView = ({ httpPost }) => async ({ customerId, signal }) => {
3
- const response = await httpPost({
4
- endpoint: "/view-first-available-checkout-by-customer-id",
5
- body: { customerId },
6
- signal,
7
- });
8
- return !response.ok || response.status === 404 ? null : toCheckoutProjection((await response.json()).result);
9
- };
2
+ const httpFirstAvailableCheckoutByCustomerIdView = ({ httpPost }) => async ({ customerId, signal }) => await httpPost({
3
+ endpoint: "/view-first-available-checkout-by-customer-id",
4
+ body: { customerId },
5
+ signal,
6
+ result: {
7
+ error: null,
8
+ success: (response) => toCheckoutProjection(response.result),
9
+ },
10
+ });
10
11
  export { httpFirstAvailableCheckoutByCustomerIdView };
@@ -1,8 +1,9 @@
1
- const httpFiveItemsDiscountByCustomerIdView = ({ httpGet }) => async ({ customerId, signal }) => {
2
- const response = await httpGet({
3
- endpoint: `/view-five-items-discount-by-customer-id/${customerId}`,
4
- signal,
5
- });
6
- return !response.ok ? 0 : await response.json();
7
- };
1
+ const httpFiveItemsDiscountByCustomerIdView = ({ httpGet }) => async ({ customerId, signal }) => await httpGet({
2
+ endpoint: `/view-five-items-discount-by-customer-id/${customerId}`,
3
+ signal,
4
+ result: {
5
+ error: 0,
6
+ success: (response) => response,
7
+ },
8
+ });
8
9
  export { httpFiveItemsDiscountByCustomerIdView };
@@ -1,8 +1,9 @@
1
- const httpIsCheckoutEnabledByCustomerIdView = ({ httpGet }) => async ({ customerId, signal }) => {
2
- const response = await httpGet({
3
- endpoint: `/is-new-checkout-enabled/${customerId}`,
4
- signal,
5
- });
6
- return !response.ok ? false : await response.json();
7
- };
1
+ const httpIsCheckoutEnabledByCustomerIdView = ({ httpGet }) => async ({ customerId, signal }) => await httpGet({
2
+ endpoint: `/is-new-checkout-enabled/${customerId}`,
3
+ signal,
4
+ result: {
5
+ error: false,
6
+ success: (response) => response,
7
+ },
8
+ });
8
9
  export { httpIsCheckoutEnabledByCustomerIdView };