@lookiero/checkout 0.4.0-beta.2 → 0.4.0-beta.3

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/index.d.ts CHANGED
@@ -18,7 +18,7 @@ interface BootstrapFunctionReturn {
18
18
  readonly isCheckoutAccessible: IsCheckoutAccessibleFunction;
19
19
  }
20
20
  interface BootstrapFunction {
21
- (args: BootstrapFunctionArgs): Promise<BootstrapFunctionReturn>;
21
+ (args: BootstrapFunctionArgs): BootstrapFunctionReturn;
22
22
  }
23
23
  declare const bootstrap: BootstrapFunction;
24
24
  export { bootstrap };
package/dist/index.js CHANGED
@@ -4,15 +4,14 @@ import { bootstrap as checkoutBootstrap } from "./infrastructure/delivery/bootst
4
4
  import { root } from "./infrastructure/ui/Root";
5
5
  import { viewIsCheckoutAccessibleByCustomerId, } from "./projection/checkout/viewIsCheckoutAccessibleByCustomerId";
6
6
  import { notificationsRoot } from "./shared/notifications";
7
- const bootstrap = async ({ apiUrl, getAuthToken, translations }) => {
8
- const authToken = await getAuthToken();
9
- const { Component: Messaging, queryBus } = checkoutBootstrap({ apiUrl, authToken });
7
+ const bootstrap = ({ apiUrl, getAuthToken, translations }) => {
8
+ const { Component: Messaging, queryBus } = checkoutBootstrap({ apiUrl, getAuthToken });
10
9
  const I18n = i18n({
11
10
  fetchTranslation: fetchFetchTranslation({ endpoint: translations }),
12
11
  contextId: "CheckoutI18n",
13
12
  });
14
13
  const Notifications = notificationsRoot();
15
- const Root = root({ Messaging, I18n, Notifications, authToken });
14
+ const Root = root({ Messaging, I18n, Notifications, getAuthToken });
16
15
  const isCheckoutAccessible = ({ customerId }) => queryBus(viewIsCheckoutAccessibleByCustomerId({ customerId }));
17
16
  return {
18
17
  Root,
@@ -1,6 +1,6 @@
1
1
  import { BuildBootstrapFunctionReturn } from "@lookiero/messaging-react";
2
2
  interface BootstrapFunctionArgs {
3
- readonly authToken: string;
3
+ readonly getAuthToken: () => Promise<string>;
4
4
  readonly apiUrl: string;
5
5
  }
6
6
  interface BootstrapFunction {
@@ -17,9 +17,9 @@ import { httpReturnQuestionsByCheckoutItemIdView } from "../projection/returnQue
17
17
  import { storageUiSettingByKeyView } from "../projection/uiSetting/storageUiSettingByKeyView";
18
18
  import { baseBootstrap } from "./baseBootstrap";
19
19
  import { fetchHttpGet, fetchHttpPost } from "./http/fetchHttpClient";
20
- const bootstrap = ({ apiUrl, authToken }) => {
21
- const httpGet = fetchHttpGet({ apiUrl, authToken });
22
- const httpPost = fetchHttpPost({ apiUrl, authToken });
20
+ const bootstrap = ({ apiUrl, getAuthToken }) => {
21
+ const httpGet = fetchHttpGet({ apiUrl, getAuthToken });
22
+ const httpPost = fetchHttpPost({ apiUrl, getAuthToken });
23
23
  return baseBootstrap({
24
24
  checkoutByIdView: httpCheckoutByIdView({ httpPost }),
25
25
  firstAvailableCheckoutByCustomerIdView: httpFirstAvailableCheckoutByCustomerIdView({ httpPost }),
@@ -1,7 +1,7 @@
1
1
  import { HttpGetFunction, HttpPostFunction } from "./httpClient";
2
2
  interface FetchHttpFunctionArgs {
3
3
  readonly apiUrl: string;
4
- readonly authToken: string;
4
+ readonly getAuthToken: () => Promise<string>;
5
5
  }
6
6
  interface FetchHttpPostFunction {
7
7
  (args: FetchHttpFunctionArgs): HttpPostFunction;
@@ -1,17 +1,17 @@
1
- const fetchHttpPost = ({ apiUrl, authToken }) => async ({ endpoint, body, signal }) => fetch(`${apiUrl}${endpoint}`, {
1
+ const fetchHttpPost = ({ apiUrl, getAuthToken }) => async ({ endpoint, body, signal }) => fetch(`${apiUrl}${endpoint}`, {
2
2
  method: "POST",
3
3
  headers: {
4
4
  ["Content-Type"]: "application/json",
5
- authorization: `Bearer ${authToken}`,
5
+ authorization: `Bearer ${await getAuthToken()}`,
6
6
  },
7
7
  body: JSON.stringify(body),
8
8
  signal,
9
9
  });
10
- const fetchHttpGet = ({ apiUrl, authToken }) => async ({ endpoint, signal }) => fetch(`${apiUrl}${endpoint}`, {
10
+ const fetchHttpGet = ({ apiUrl, getAuthToken }) => async ({ endpoint, signal }) => fetch(`${apiUrl}${endpoint}`, {
11
11
  method: "GET",
12
12
  credentials: "include",
13
13
  headers: {
14
- Authorization: `Bearer ${authToken}`,
14
+ Authorization: `Bearer ${await getAuthToken()}`,
15
15
  ["Content-Type"]: "application/json",
16
16
  },
17
17
  referrer: "",
@@ -8,7 +8,7 @@ interface RootFunctionArgs {
8
8
  readonly Notifications: NotificationsRoot;
9
9
  readonly I18n: I18n;
10
10
  readonly development?: boolean;
11
- readonly authToken: string;
11
+ readonly getAuthToken: () => Promise<string>;
12
12
  }
13
13
  interface RootFunction {
14
14
  (args: RootFunctionArgs): FC<RootProps>;
@@ -1,12 +1,12 @@
1
1
  import React, { useCallback } from "react";
2
2
  import { Platform } from "react-native";
3
3
  import { Routing } from "./routing/Routing";
4
- const root = ({ Messaging, I18n, Notifications, authToken, development }) =>
4
+ const root = ({ Messaging, I18n, Notifications, getAuthToken, development }) =>
5
5
  // eslint-disable-next-line react/display-name, react/prop-types
6
6
  ({ basePath, locale = "en", customerId, menu, onNotAccessible, useRedirect }) => {
7
7
  const handleOnI18nError = useCallback(() => void 0, []);
8
8
  return (React.createElement(Messaging, { includeReactQueryDevTools: Platform.OS === "web" },
9
9
  React.createElement(Notifications, { includeReactQueryDevTools: Platform.OS === "web" },
10
- React.createElement(Routing, { I18n: I18n, authToken: authToken, basePath: basePath, customerId: customerId, locale: locale, menu: menu, useRedirect: useRedirect, onI18nError: development ? undefined : handleOnI18nError, onNotAccessible: onNotAccessible }))));
10
+ React.createElement(Routing, { I18n: I18n, basePath: basePath, customerId: customerId, getAuthToken: getAuthToken, locale: locale, menu: menu, useRedirect: useRedirect, onI18nError: development ? undefined : handleOnI18nError, onNotAccessible: onNotAccessible }))));
11
11
  };
12
12
  export { root };
@@ -6,7 +6,7 @@ interface RoutingProps {
6
6
  readonly customerId: string | undefined;
7
7
  readonly locale: string;
8
8
  readonly I18n: I18n;
9
- readonly authToken: string;
9
+ readonly getAuthToken: () => Promise<string>;
10
10
  readonly menu: Menu;
11
11
  readonly onNotAccessible: () => void;
12
12
  readonly onI18nError?: (err: Error) => void;
@@ -11,7 +11,7 @@ const Item = lazy(() => import("../views/item/Item").then((module) => ({ default
11
11
  const Summary = lazy(() => import("../views/summary/Summary").then((module) => ({ default: module.Summary })));
12
12
  const Checkout = lazy(() => import("../views/checkout/Checkout").then((module) => ({ default: module.Checkout })));
13
13
  const Feedback = lazy(() => import("../views/feedback/Feedback").then((module) => ({ default: module.Feedback })));
14
- const Routing = ({ basePath = "", customerId, locale, I18n, authToken, menu, onI18nError, onNotAccessible, useRedirect, }) => {
14
+ const Routing = ({ basePath = "", customerId, locale, I18n, getAuthToken, menu, onI18nError, onNotAccessible, useRedirect, }) => {
15
15
  const routes = useRoutes([
16
16
  {
17
17
  path: "",
@@ -45,7 +45,7 @@ const Routing = ({ basePath = "", customerId, locale, I18n, authToken, menu, onI
45
45
  {
46
46
  path: Routes.CHECKOUT,
47
47
  element: (React.createElement(Suspense, { fallback: React.createElement(Spinner, null) },
48
- React.createElement(Checkout, { authToken: authToken, customerId: customerId, useRedirect: useRedirect }))),
48
+ React.createElement(Checkout, { customerId: customerId, getAuthToken: getAuthToken, useRedirect: useRedirect }))),
49
49
  },
50
50
  {
51
51
  path: Routes.FEEDBACK,
@@ -1,7 +1,7 @@
1
1
  import { FC } from "react";
2
2
  interface CheckoutProps {
3
3
  readonly customerId: string;
4
- readonly authToken: string;
4
+ readonly getAuthToken: () => Promise<string>;
5
5
  readonly useRedirect: () => Record<string, string>;
6
6
  }
7
7
  declare const Checkout: FC<CheckoutProps>;
@@ -3,7 +3,7 @@ import { useI18nMessage } from "@lookiero/i18n-react";
3
3
  import { CommandStatus, QueryStatus } from "@lookiero/messaging-react";
4
4
  import { PaymentFlow, PaymentInstrumentSelect, PaymentMethod, Section } from "@lookiero/payments-front";
5
5
  import { ChargeStatus } from "@lookiero/payments-front/build/infrastructure/CheckoutAPI";
6
- import React, { useCallback, useMemo, useRef, useState } from "react";
6
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
7
7
  import { View } from "react-native";
8
8
  import { useNavigate } from "react-router-native";
9
9
  import { CheckoutItemStatus } from "../../../../domain/checkoutItem/model/checkoutItem";
@@ -24,10 +24,15 @@ import { Pricing } from "../summary/components/pricing/Pricing";
24
24
  import { style } from "./Checkout.style";
25
25
  import { CheckoutSuccessModal } from "./components/checkoutSuccessModal/CheckoutSuccessModal";
26
26
  import { DeliveryBanner } from "./components/deliveryBanner/DeliveryBanner";
27
- const Checkout = ({ customerId, authToken, useRedirect }) => {
27
+ const Checkout = ({ customerId, getAuthToken, useRedirect }) => {
28
28
  const titleText = useI18nMessage({ id: I18nMessages.CHECKOUT_TITLE });
29
29
  const paymentInstrumentSelectRef = useRef(null);
30
30
  const paymentFlowRef = useRef(null);
31
+ const [authToken, setAuthToken] = useState();
32
+ useEffect(() => {
33
+ const loadAuthToken = async () => setAuthToken(await getAuthToken());
34
+ loadAuthToken();
35
+ }, [getAuthToken]);
31
36
  const [checkout, checkoutStatus] = useViewFirstAvailableCheckoutByCustomerId({ customerId });
32
37
  const [pricing, pricingStatus] = useViewPricingByCheckoutId({ checkoutId: checkout?.id });
33
38
  const [paymentFlowPayload] = useViewPaymentFlowPayloadByCheckoutId({
@@ -83,6 +88,6 @@ const Checkout = ({ customerId, authToken, useRedirect }) => {
83
88
  React.createElement(ProductVariant, { brand: checkoutItem.productVariant.brand, color: checkoutItem.productVariant.color, media: checkoutItem.productVariant.media, name: checkoutItem.productVariant.name, price: checkoutItem.price, size: checkoutItem.productVariant.size, status: checkoutItem.status })))),
84
89
  pricing && (React.createElement(View, { style: style.pricingContainer },
85
90
  React.createElement(Pricing, { balanceDiscount: pricing.balanceDiscount, busy: processingCheckout || markAsPaidStatus === CommandStatus.LOADING, collapsible: false, discount: pricing.discount, discountPercentage: pricing.discountPercentage, orderTotal: pricing.orderTotal, service: pricing.service, subtotal: pricing.subtotal, totalCheckoutItemsKept: checkoutItemsKept?.length || 0, onSubmit: handleOnSubmitCheckout }))))),
86
- React.createElement(PaymentFlow, { ref: paymentFlowRef, token: authToken })));
91
+ authToken && React.createElement(PaymentFlow, { ref: paymentFlowRef, token: authToken })));
87
92
  };
88
93
  export { Checkout };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lookiero/checkout",
3
- "version": "0.4.0-beta.2",
3
+ "version": "0.4.0-beta.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [