@lookiero/checkout 0.6.3 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/domain/checkout/model/checkout.d.ts +1 -2
- package/dist/domain/checkout/model/checkout.js +2 -3
- package/dist/index.d.ts +10 -1
- package/dist/index.js +5 -1
- package/dist/infrastructure/domain/checkout/react/useStartCheckout.d.ts +1 -1
- package/dist/infrastructure/domain/checkout/react/useStartCheckout.js +5 -1
- package/dist/infrastructure/projection/checkout/react/useViewFirstAvailableCheckoutByCustomerId.js +3 -0
- package/dist/infrastructure/ui/routing/CheckoutMiddleware.js +8 -1
- package/package.json +1 -1
|
@@ -5,9 +5,8 @@ declare enum CheckoutStatus {
|
|
|
5
5
|
AVAILABLE = "AVAILABLE",
|
|
6
6
|
NOTIFIED = "NOTIFIED",
|
|
7
7
|
STARTED = "STARTED",
|
|
8
|
-
COMPLETED = "COMPLETED",
|
|
9
8
|
SUBMITTED = "SUBMITTED",
|
|
10
|
-
|
|
9
|
+
COMPLETED = "COMPLETED"
|
|
11
10
|
}
|
|
12
11
|
interface Checkout extends AggregateRoot {
|
|
13
12
|
readonly status: CheckoutStatus;
|
|
@@ -6,13 +6,12 @@ var CheckoutStatus;
|
|
|
6
6
|
CheckoutStatus["AVAILABLE"] = "AVAILABLE";
|
|
7
7
|
CheckoutStatus["NOTIFIED"] = "NOTIFIED";
|
|
8
8
|
CheckoutStatus["STARTED"] = "STARTED";
|
|
9
|
-
CheckoutStatus["COMPLETED"] = "COMPLETED";
|
|
10
9
|
CheckoutStatus["SUBMITTED"] = "SUBMITTED";
|
|
11
|
-
CheckoutStatus["
|
|
10
|
+
CheckoutStatus["COMPLETED"] = "COMPLETED";
|
|
12
11
|
})(CheckoutStatus || (CheckoutStatus = {}));
|
|
13
12
|
const startCheckoutHandler = () => async ({ aggregateRoot, command }) => {
|
|
14
13
|
const { aggregateId } = command;
|
|
15
|
-
invariant(aggregateRoot.status !== CheckoutStatus.
|
|
14
|
+
invariant(aggregateRoot.status !== CheckoutStatus.SUBMITTED, "Checkout is already submitted");
|
|
16
15
|
invariant(aggregateRoot.status !== CheckoutStatus.COMPLETED, "Checkout is already completed");
|
|
17
16
|
return {
|
|
18
17
|
...aggregateRoot,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { EndpointFunction } from "@lookiero/i18n";
|
|
2
2
|
import { FC } from "react";
|
|
3
|
+
import { CheckoutStatus } from "./domain/checkout/model/checkout";
|
|
3
4
|
import { RootProps } from "./infrastructure/ui/Root";
|
|
5
|
+
import { CheckoutProjection } from "./projection/checkout/checkout";
|
|
4
6
|
import { IsCheckoutAccessibleByCustomerIdProjection } from "./projection/checkout/viewIsCheckoutAccessibleByCustomerId";
|
|
5
7
|
interface IsCheckoutAccessibleFunctionArgs {
|
|
6
8
|
readonly customerId: string | undefined;
|
|
@@ -8,6 +10,12 @@ interface IsCheckoutAccessibleFunctionArgs {
|
|
|
8
10
|
interface IsCheckoutAccessibleFunction {
|
|
9
11
|
(args: IsCheckoutAccessibleFunctionArgs): Promise<IsCheckoutAccessibleByCustomerIdProjection>;
|
|
10
12
|
}
|
|
13
|
+
interface FirstAvailableCheckoutByCustomerIdFunctionArgs {
|
|
14
|
+
readonly customerId: string | undefined;
|
|
15
|
+
}
|
|
16
|
+
interface FirstAvailableCheckoutByCustomerIdFunction {
|
|
17
|
+
(args: FirstAvailableCheckoutByCustomerIdFunctionArgs): Promise<CheckoutProjection>;
|
|
18
|
+
}
|
|
11
19
|
interface BootstrapFunctionArgs {
|
|
12
20
|
readonly getAuthToken: () => Promise<string>;
|
|
13
21
|
readonly apiUrl: string;
|
|
@@ -16,9 +24,10 @@ interface BootstrapFunctionArgs {
|
|
|
16
24
|
interface BootstrapFunctionReturn {
|
|
17
25
|
readonly Root: FC<RootProps>;
|
|
18
26
|
readonly isCheckoutAccessible: IsCheckoutAccessibleFunction;
|
|
27
|
+
readonly firstAvailableCheckoutByCustomerId: FirstAvailableCheckoutByCustomerIdFunction;
|
|
19
28
|
}
|
|
20
29
|
interface BootstrapFunction {
|
|
21
30
|
(args: BootstrapFunctionArgs): BootstrapFunctionReturn;
|
|
22
31
|
}
|
|
23
32
|
declare const bootstrap: BootstrapFunction;
|
|
24
|
-
export { bootstrap };
|
|
33
|
+
export { bootstrap, CheckoutStatus };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { fetchFetchTranslation } from "@lookiero/i18n";
|
|
2
2
|
import { i18n } from "@lookiero/i18n-react";
|
|
3
|
+
import { CheckoutStatus } from "./domain/checkout/model/checkout";
|
|
3
4
|
import { bootstrap as checkoutBootstrap } from "./infrastructure/delivery/bootstrap";
|
|
4
5
|
import { root } from "./infrastructure/ui/Root";
|
|
6
|
+
import { viewFirstAvailableCheckoutByCustomerId } from "./projection/checkout/viewFirstAvailableCheckoutByCustomerId";
|
|
5
7
|
import { viewIsCheckoutAccessibleByCustomerId, } from "./projection/checkout/viewIsCheckoutAccessibleByCustomerId";
|
|
6
8
|
const bootstrap = ({ apiUrl, getAuthToken, translations }) => {
|
|
7
9
|
const { Component: Messaging, queryBus } = checkoutBootstrap({ apiUrl, getAuthToken });
|
|
@@ -11,9 +13,11 @@ const bootstrap = ({ apiUrl, getAuthToken, translations }) => {
|
|
|
11
13
|
});
|
|
12
14
|
const Root = root({ Messaging, I18n, getAuthToken });
|
|
13
15
|
const isCheckoutAccessible = ({ customerId }) => queryBus(viewIsCheckoutAccessibleByCustomerId({ customerId }));
|
|
16
|
+
const firstAvailableCheckoutByCustomerId = ({ customerId }) => queryBus(viewFirstAvailableCheckoutByCustomerId({ customerId: customerId }));
|
|
14
17
|
return {
|
|
15
18
|
Root,
|
|
16
19
|
isCheckoutAccessible,
|
|
20
|
+
firstAvailableCheckoutByCustomerId,
|
|
17
21
|
};
|
|
18
22
|
};
|
|
19
|
-
export { bootstrap };
|
|
23
|
+
export { bootstrap, CheckoutStatus };
|
|
@@ -3,7 +3,7 @@ interface StartCheckoutFunction {
|
|
|
3
3
|
(): Promise<void>;
|
|
4
4
|
}
|
|
5
5
|
interface UseStartCheckoutArgs {
|
|
6
|
-
readonly checkoutId
|
|
6
|
+
readonly checkoutId?: string;
|
|
7
7
|
}
|
|
8
8
|
type UseStartCheckoutResult = [start: StartCheckoutFunction, status: CommandStatus];
|
|
9
9
|
interface UseStartCheckout {
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { useCommand } from "@lookiero/messaging-react";
|
|
2
2
|
import { useCallback } from "react";
|
|
3
|
+
import invariant from "tiny-invariant";
|
|
3
4
|
import { startCheckout } from "../../../../domain/checkout/command/startCheckout";
|
|
4
5
|
import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
|
|
5
6
|
const useStartCheckout = ({ checkoutId }) => {
|
|
6
7
|
const [commandBus, status] = useCommand({ contextId: MESSAGING_CONTEXT_ID });
|
|
7
|
-
const start = useCallback(() =>
|
|
8
|
+
const start = useCallback(() => {
|
|
9
|
+
invariant(checkoutId, "CheckoutId must be defined in order to start checkout");
|
|
10
|
+
return commandBus(startCheckout({ aggregateId: checkoutId }));
|
|
11
|
+
}, [checkoutId, commandBus]);
|
|
8
12
|
return [start, status];
|
|
9
13
|
};
|
|
10
14
|
export { useStartCheckout };
|
package/dist/infrastructure/projection/checkout/react/useViewFirstAvailableCheckoutByCustomerId.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useQuery } from "@lookiero/messaging-react";
|
|
2
|
+
import { CHECKOUT_STARTED } from "../../../../domain/checkout/model/checkoutStarted";
|
|
2
3
|
import { CHECKOUT_SUBMITTED } from "../../../../domain/checkout/model/checkoutSubmitted";
|
|
3
4
|
import { CHECKOUT_BOOKING_BOOKED, } from "../../../../domain/checkoutBooking/model/checkoutBookingBooked";
|
|
4
5
|
import { CHECKOUT_BOOKING_EXPIRED, } from "../../../../domain/checkoutBooking/model/checkoutBookingExpired";
|
|
@@ -11,6 +12,7 @@ import { MESSAGING_CONTEXT_ID } from "../../../delivery/baseBootstrap";
|
|
|
11
12
|
const isCheckoutItemKept = (event) => event.name === CHECKOUT_ITEM_KEPT;
|
|
12
13
|
const isCheckoutItemReturned = (event) => event.name === CHECKOUT_ITEM_RETURNED;
|
|
13
14
|
const isCheckoutItemReplaced = (event) => event.name === CHECKOUT_ITEM_REPLACED;
|
|
15
|
+
const isCheckoutStarted = (event) => event.name === CHECKOUT_STARTED;
|
|
14
16
|
const isCheckoutSubmitted = (event) => event.name === CHECKOUT_SUBMITTED;
|
|
15
17
|
const isCheckoutFeedbackGiven = (event) => event.name === CHECKOUT_FEEDBACK_GIVEN;
|
|
16
18
|
const isCheckoutBookingExpired = (event) => event.name === CHECKOUT_BOOKING_EXPIRED;
|
|
@@ -18,6 +20,7 @@ const isCheckoutBookingBooked = (event) => event.name === CHECKOUT_BOOKING_BOOKE
|
|
|
18
20
|
const shouldInvalidate = (event) => isCheckoutItemKept(event) ||
|
|
19
21
|
isCheckoutItemReplaced(event) ||
|
|
20
22
|
isCheckoutItemReturned(event) ||
|
|
23
|
+
isCheckoutStarted(event) ||
|
|
21
24
|
isCheckoutSubmitted(event) ||
|
|
22
25
|
isCheckoutFeedbackGiven(event) ||
|
|
23
26
|
isCheckoutBookingExpired(event) ||
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { QueryStatus } from "@lookiero/messaging-react";
|
|
2
|
-
import React, { useRef } from "react";
|
|
2
|
+
import React, { useEffect, useRef } from "react";
|
|
3
3
|
import { generatePath, Navigate, useMatch } from "react-router-native";
|
|
4
4
|
import { CheckoutStatus } from "../../../domain/checkout/model/checkout";
|
|
5
5
|
import { CheckoutItemStatus } from "../../../domain/checkoutItem/model/checkoutItem";
|
|
6
6
|
import { Spinner } from "../../../shared/ui/components/atoms/spinner/Spinner";
|
|
7
|
+
import { useStartCheckout } from "../../domain/checkout/react/useStartCheckout";
|
|
7
8
|
import { useViewFirstAvailableCheckoutByCustomerId } from "../../projection/checkout/react/useViewFirstAvailableCheckoutByCustomerId";
|
|
8
9
|
import { useShouldIntroBeShown } from "../../projection/uiSetting/react/useShouldIntroBeShown";
|
|
9
10
|
import { Routes } from "./routes";
|
|
@@ -15,6 +16,12 @@ const CheckoutMiddleware = ({ customerId, loader = React.createElement(Spinner,
|
|
|
15
16
|
const navigatedToFirstItemWithoutCustomerDecision = useRef(false);
|
|
16
17
|
const [checkout, checkoutStatus] = useViewFirstAvailableCheckoutByCustomerId({ customerId });
|
|
17
18
|
const firstItemWithoutCustomerDecision = checkout?.items.find((item) => item.status === CheckoutItemStatus.INITIAL);
|
|
19
|
+
const [startCheckout] = useStartCheckout({ checkoutId: checkout?.id });
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (checkout?.id) {
|
|
22
|
+
startCheckout();
|
|
23
|
+
}
|
|
24
|
+
}, [checkout?.id, startCheckout]);
|
|
18
25
|
const introRouteMatch = useMatch(`${basePath}/${Routes.INTRO}`);
|
|
19
26
|
const itemRouteMatch = useMatch(`${basePath}/${Routes.ITEM}`);
|
|
20
27
|
const itemDetailRouteMatch = useMatch(`${basePath}/${Routes.ITEM_DETAIL}`);
|