Skip to content

Commit 5f4b410

Browse files
committed
refactor: move create elastic path client into lib
1 parent 9a2b9de commit 5f4b410

File tree

27 files changed

+50
-29
lines changed

27 files changed

+50
-29
lines changed

examples/simple/src/app/(auth)/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ACCOUNT_MEMBER_TOKEN_COOKIE_NAME } from "../../lib/cookie-constants";
77
import { retrieveAccountMemberCredentials } from "../../lib/retrieve-account-member-credentials";
88
import { revalidatePath, revalidateTag } from "next/cache";
99
import { getErrorMessage } from "../../lib/get-error-message";
10-
import { createElasticPathClient } from "../(store)/membership/create-elastic-path-client";
10+
import { createElasticPathClient } from "../../lib/create-elastic-path-client";
1111
import { postV2AccountMembersTokens } from "@epcc-sdk/sdks-shopper";
1212
import { createCookieFromGenerateTokenResponse } from "../../lib/create-cookie-from-generate-token-response";
1313

examples/simple/src/app/(auth)/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ReactNode } from "react";
33
import { getStoreInitialState } from "../../lib/get-store-initial-state";
44
import { Providers } from "../providers";
55
import clsx from "clsx";
6-
import { createElasticPathClient } from "../(store)/membership/create-elastic-path-client";
6+
import { createElasticPathClient } from "../../lib/create-elastic-path-client";
77

88
const SITE_NAME = process.env.NEXT_PUBLIC_SITE_NAME;
99
const baseUrl = process.env.NEXT_PUBLIC_VERCEL_URL

examples/simple/src/app/(checkout)/checkout/AccountCheckout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
getV2AccountMembersAccountMemberId,
1010
ResponseCurrency,
1111
} from "@epcc-sdk/sdks-shopper";
12-
import { createElasticPathClient } from "../../(store)/membership/create-elastic-path-client";
12+
import { createElasticPathClient } from "../../../lib/create-elastic-path-client";
1313
import { getCart } from "@epcc-sdk/sdks-shopper";
1414
import { TAGS } from "../../../lib/constants";
1515
import { AccountCheckoutForm } from "./AccoutCheckoutForm";

examples/simple/src/app/(checkout)/checkout/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
CheckoutForm,
77
checkoutFormSchema,
88
} from "../../../components/checkout/form-schema/checkout-form-schema";
9-
import { createElasticPathClient } from "../../(store)/membership/create-elastic-path-client";
9+
import { createElasticPathClient } from "../../../lib/create-elastic-path-client";
1010
import {
1111
manageCarts,
1212
checkoutApi,

examples/simple/src/app/(checkout)/checkout/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { cookies } from "next/headers";
66
import { notFound } from "next/navigation";
77
import { CheckoutViews } from "./CheckoutViews";
88
import { getAllCurrencies, getCart } from "@epcc-sdk/sdks-shopper";
9-
import { createElasticPathClient } from "../../(store)/membership/create-elastic-path-client";
9+
import { createElasticPathClient } from "../../../lib/create-elastic-path-client";
1010
import { OrderConfirmationProvider } from "./OrderConfirmationProvider";
1111
import { TAGS } from "../../../lib/constants";
1212
import { isAccountAuthenticated } from "@epcc-sdk/sdks-nextjs";

examples/simple/src/app/(checkout)/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ReactNode } from "react";
33
import { getStoreInitialState } from "../../lib/get-store-initial-state";
44
import { Providers } from "../providers";
55
import clsx from "clsx";
6-
import { createElasticPathClient } from "../(store)/membership/create-elastic-path-client";
6+
import { createElasticPathClient } from "../../lib/create-elastic-path-client";
77

88
const SITE_NAME = process.env.NEXT_PUBLIC_SITE_NAME;
99
const baseUrl = process.env.NEXT_PUBLIC_VERCEL_URL

examples/simple/src/app/(store)/account/addresses/[addressId]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ArrowLeftIcon } from "@heroicons/react/24/outline";
1111
import React from "react";
1212
import { Separator } from "../../../../../components/separator/Separator";
1313
import { UpdateForm } from "./UpdateForm";
14-
import { createElasticPathClient } from "../../../membership/create-elastic-path-client";
14+
import { createElasticPathClient } from "../../../../../lib/create-elastic-path-client";
1515
import { getV2AccountAddress } from "@epcc-sdk/sdks-shopper";
1616

1717
export const dynamic = "force-dynamic";

examples/simple/src/app/(store)/account/addresses/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ACCOUNT_MEMBER_TOKEN_COOKIE_NAME } from "../../../../lib/cookie-constan
1010
import { revalidatePath, revalidateTag } from "next/cache";
1111
import { shippingAddressSchema } from "../../../../components/checkout/form-schema/checkout-form-schema";
1212
import { redirect } from "next/navigation";
13-
import { createElasticPathClient } from "../../membership/create-elastic-path-client";
13+
import { createElasticPathClient } from "../../../../lib/create-elastic-path-client";
1414
import {
1515
deleteV2AccountAddress,
1616
postV2AccountAddress,

examples/simple/src/app/(store)/account/addresses/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Button } from "../../../../components/button/Button";
1111
import { Separator } from "../../../../components/separator/Separator";
1212
import React from "react";
1313
import { DeleteAddressBtn } from "./DeleteAddressBtn";
14-
import { createElasticPathClient } from "../../membership/create-elastic-path-client";
14+
import { createElasticPathClient } from "../../../../lib/create-elastic-path-client";
1515
import { getV2AccountAddresses } from "@epcc-sdk/sdks-shopper";
1616
import { TAGS } from "../../../../lib/constants";
1717

examples/simple/src/app/(store)/account/orders/[orderId]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ArrowLeftIcon } from "@heroicons/react/24/outline";
77
import Link from "next/link";
88
import { formatIsoDateString } from "../../../../../lib/format-iso-date-string";
99
import { OrderLineItem } from "./OrderLineItem";
10-
import { createElasticPathClient } from "../../../membership/create-elastic-path-client";
10+
import { createElasticPathClient } from "../../../../../lib/create-elastic-path-client";
1111
import {
1212
getAnOrder,
1313
CartItemsObjectResponse,

examples/simple/src/app/(store)/account/orders/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { retrieveAccountMemberCredentials } from "../../../../lib/retrieve-accou
55
import { ResourcePagination } from "../../../../components/pagination/ResourcePagination";
66
import { DEFAULT_PAGINATION_LIMIT, TAGS } from "../../../../lib/constants";
77
import { OrderItemWithDetails } from "./OrderItemWithDetails";
8-
import { createElasticPathClient } from "../../membership/create-elastic-path-client";
8+
import { createElasticPathClient } from "../../../../lib/create-elastic-path-client";
99
import {
1010
getByContextAllProducts,
1111
getCustomerOrders,

examples/simple/src/app/(store)/account/summary/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { retrieveAccountMemberCredentials } from "../../../../lib/retrieve-accou
66
import { ACCOUNT_MEMBER_TOKEN_COOKIE_NAME } from "../../../../lib/cookie-constants";
77
import { revalidatePath, revalidateTag } from "next/cache";
88
import { getErrorMessage } from "../../../../lib/get-error-message";
9-
import { createElasticPathClient } from "../../membership/create-elastic-path-client";
9+
import { createElasticPathClient } from "../../../../lib/create-elastic-path-client";
1010
import {
1111
putV2AccountsAccountId,
1212
postV2AccountMembersTokens,

examples/simple/src/app/(store)/account/summary/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Label } from "../../../../components/label/Label";
99
import { Input } from "../../../../components/input/Input";
1010
import { FormStatusButton } from "../../../../components/button/FormStatusButton";
1111
import { YourInfoForm } from "./YourInfoForm";
12-
import { createElasticPathClient } from "../../membership/create-elastic-path-client";
12+
import { createElasticPathClient } from "../../../../lib/create-elastic-path-client";
1313
import {
1414
getV2AccountsAccountId,
1515
getV2AccountMembersAccountMemberId,

examples/simple/src/app/(store)/cart/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { LockClosedIcon } from "@heroicons/react/24/solid";
66
import { getCartItems, getByContextAllProducts } from "@epcc-sdk/sdks-shopper";
77
import { CART_COOKIE_NAME } from "../../../lib/cookie-constants";
88
import { cookies } from "next/headers";
9-
import { createElasticPathClient } from "../membership/create-elastic-path-client";
9+
import { createElasticPathClient } from "../../../lib/create-elastic-path-client";
1010
import { TAGS } from "../../../lib/constants";
1111

1212
export default async function CartPage() {

examples/simple/src/app/(store)/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Providers } from "../providers";
55
import Header from "../../components/header/Header";
66
import { Toaster } from "../../components/toast/toaster";
77
import Footer from "../../components/footer/Footer";
8-
import { createElasticPathClient } from "./membership/create-elastic-path-client";
8+
import { createElasticPathClient } from "../../lib/create-elastic-path-client";
99

1010
const { SITE_NAME } = process.env;
1111
const baseUrl = process.env.NEXT_PUBLIC_VERCEL_URL

examples/simple/src/app/(store)/products/[productId]/actions/cart-actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
updateACartItem,
1111
} from "@epcc-sdk/sdks-shopper";
1212
import { revalidateTag } from "next/cache";
13-
import { createElasticPathClient } from "../../../membership/create-elastic-path-client";
13+
import { createElasticPathClient } from "../../../../../lib/create-elastic-path-client";
1414
import { createBundleFormSchema } from "../../../../../components/product/bundles/validation-schema";
1515
import { formSelectedOptionsToData } from "../../../../../components/product/bundles/form-parsers";
1616

examples/simple/src/app/(store)/products/[productId]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
getAllFiles,
88
ElasticPathFile,
99
} from "@epcc-sdk/sdks-shopper";
10-
import { createElasticPathClient } from "../../membership/create-elastic-path-client";
10+
import { createElasticPathClient } from "../../../../lib/create-elastic-path-client";
1111
import { SimpleProductContent } from "../../../../components/product/standard/SimpleProductContent";
1212
import { SimpleProductProvider } from "../../../../components/product/standard/SimpleProductProvider";
1313
import { VariationProductProvider } from "../../../../components/product/variations/VariationProductProvider";

examples/simple/src/app/(store)/search/[[...node]]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Search } from "../search";
22
import { Metadata } from "next";
33
import { notFound } from "next/navigation";
4-
import { createElasticPathClient } from "../../membership/create-elastic-path-client";
4+
import { createElasticPathClient } from "../../../../lib/create-elastic-path-client";
55
import {
66
Client,
77
getByContextAllHierarchies,

examples/simple/src/app/providers.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Events } from "../lib/event-context";
55
import { StoreProvider } from "./(store)/StoreProvider";
66
import { InitialState } from "../lib/get-store-initial-state";
77
import { ClientProvider } from "./(store)/ClientProvider";
8-
import { createElasticPathClient } from "./(store)/membership/create-elastic-path-client";
8+
import { createElasticPathClient } from "../lib/create-elastic-path-client";
99

1010
const queryClient = new QueryClient({
1111
defaultOptions: {

examples/simple/src/components/checkout-sidebar/actions.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { cookies } from "next/headers";
33
import { revalidateTag } from "next/cache";
44
import { z } from "zod";
55
import { getErrorMessage } from "../../lib/get-error-message";
6-
import { createElasticPathClient } from "../../app/(store)/membership/create-elastic-path-client";
6+
import { createElasticPathClient } from "../../lib/create-elastic-path-client";
77
import { manageCarts } from "@epcc-sdk/sdks-shopper";
88
import { COOKIE_PREFIX_KEY } from "../../lib/cookie-constants";
99

@@ -15,9 +15,8 @@ export async function applyDiscount(formData: FormData) {
1515
try {
1616
const client = await createElasticPathClient();
1717

18-
const cartCookie = (await cookies()).get(
19-
`${COOKIE_PREFIX_KEY}_ep_cart`,
20-
)?.value;
18+
const cartCookie = (await cookies()).get(`${COOKIE_PREFIX_KEY}_ep_cart`)
19+
?.value;
2120

2221
if (!cartCookie) {
2322
throw new Error("Cart cookie not found");

examples/simple/src/components/featured-products/FeaturedProducts.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Link from "next/link";
44
import { ArrowRightIcon, EyeSlashIcon } from "@heroicons/react/24/outline";
55
import Image from "next/image";
66
import { fetchFeaturedProducts } from "./fetchFeaturedProducts";
7-
import { createElasticPathClient } from "../../app/(store)/membership/create-elastic-path-client";
7+
import { createElasticPathClient } from "../../lib/create-elastic-path-client";
88

99
interface IFeaturedProductsProps {
1010
title: string;

examples/simple/src/components/header/account/AccountMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { AccountSwitcher } from "./AccountSwitcher";
22
import { AccountPopover } from "./AccountPopover";
33
import { getV2AccountMembersAccountMemberId } from "@epcc-sdk/sdks-shopper";
4-
import { createElasticPathClient } from "../../../app/(store)/membership/create-elastic-path-client";
4+
import { createElasticPathClient } from "../../../lib/create-elastic-path-client";
55
import { retrieveAccountMemberCredentials } from "../../../lib/retrieve-account-member-credentials";
66
import { cookies } from "next/headers";
77
import { ACCOUNT_MEMBER_TOKEN_COOKIE_NAME } from "../../../lib/cookie-constants";

examples/simple/src/components/header/navigation/Cart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use server";
22

33
import { CartSheet } from "../../cart/CartSheet";
4-
import { createElasticPathClient } from "../../../app/(store)/membership/create-elastic-path-client";
4+
import { createElasticPathClient } from "../../../lib/create-elastic-path-client";
55
import { cookies } from "next/headers";
66
import { CART_COOKIE_NAME } from "../../../lib/cookie-constants";
77
import { getCart } from "@epcc-sdk/sdks-shopper";

examples/simple/src/components/header/navigation/MobileNavBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import EpIcon from "../../icons/ep-icon";
44
import { MobileNavBarButton } from "./MobileNavBarButton";
55
import { buildSiteNavigation } from "../../../lib/build-site-navigation";
66
import { CartSheet } from "../../cart/CartSheet";
7-
import { createElasticPathClient } from "../../../app/(store)/membership/create-elastic-path-client";
7+
import { createElasticPathClient } from "../../../lib/create-elastic-path-client";
88
import { cookies } from "next/headers";
99
import {
1010
ACCOUNT_MEMBER_TOKEN_COOKIE_NAME,

examples/simple/src/components/header/navigation/NavBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use server";
22
import { NavBarPopover } from "./NavBarPopover";
33
import { buildSiteNavigation } from "../../../lib/build-site-navigation";
4-
import { createElasticPathClient } from "../../../app/(store)/membership/create-elastic-path-client";
4+
import { createElasticPathClient } from "../../../lib/create-elastic-path-client";
55

66
export default async function NavBar() {
77
const client = await createElasticPathClient();

examples/simple/src/lib/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { createElasticPathClient } from "../app/(store)/membership/create-elastic-path-client";
1+
import { createElasticPathClient } from "./create-elastic-path-client";
22

33
export const client = createElasticPathClient();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { createClient } from "@epcc-sdk/sdks-shopper";
2+
import { applyDefaultNextMiddleware } from "@epcc-sdk/sdks-nextjs";
3+
4+
export function createElasticPathClient() {
5+
const localClient = createClient({
6+
// set default base url for requests made by this client
7+
baseUrl: `https://${process.env.NEXT_PUBLIC_EPCC_ENDPOINT_URL}`,
8+
});
9+
applyDefaultNextMiddleware(localClient);
10+
applyMultiLocationInventoryMiddleware(localClient);
11+
12+
return localClient;
13+
}
14+
15+
function applyMultiLocationInventoryMiddleware(
16+
client: ReturnType<typeof createClient>,
17+
) {
18+
client.interceptors.request.use((request) => {
19+
request.headers.set("EP-Inventories-Multi-Location", "true");
20+
return request;
21+
});
22+
}

0 commit comments

Comments
 (0)