From bcbb22cc4c0160b31cb6e5d705f27e9ba53bab25 Mon Sep 17 00:00:00 2001 From: Cecilia Panicali Date: Mon, 19 Aug 2024 14:53:44 +0200 Subject: [PATCH] Multiple-backends first commit --- app/(frontend)/layout.tsx | 2 +- app/(frontend)/product/[handle]/page.tsx | 2 +- app/(frontend)/search/[collection]/page.tsx | 2 +- app/(frontend)/search/layout.tsx | 2 +- app/(frontend)/search/page.tsx | 2 +- app/sitemap.ts | 2 +- components/cart/actions.ts | 2 +- components/cart/modal.tsx | 6 +- components/layout/navbar/search.tsx | 4 +- components/layout/search/filter/index.tsx | 2 +- components/layout/search/filter/item.tsx | 4 +- lib/bigcommerce/constants.ts | 62 ++ lib/bigcommerce/fragments/cart.ts | 187 ++++++ lib/bigcommerce/fragments/page.ts | 13 + lib/bigcommerce/fragments/product.ts | 178 +++++ lib/bigcommerce/index.ts | 696 ++++++++++++++++++++ lib/bigcommerce/mappers.ts | 333 ++++++++++ lib/bigcommerce/mutations/cart.ts | 151 +++++ lib/bigcommerce/queries/cart.ts | 94 +++ lib/bigcommerce/queries/category.ts | 28 + lib/bigcommerce/queries/checkout.ts | 20 + lib/bigcommerce/queries/menu.ts | 21 + lib/bigcommerce/queries/page.ts | 89 +++ lib/bigcommerce/queries/product.ts | 130 ++++ lib/bigcommerce/queries/route.ts | 35 + lib/bigcommerce/storefront-config.ts | 45 ++ lib/bigcommerce/type-guards.ts | 27 + lib/bigcommerce/types.ts | 606 +++++++++++++++++ lib/bigcommerce/utils.ts | 43 ++ lib/medusa/constants.ts | 39 ++ lib/medusa/helpers.ts | 46 ++ lib/medusa/index.ts | 520 +++++++++++++++ lib/medusa/type-guards.ts | 27 + lib/medusa/types.ts | 433 ++++++++++++ lib/medusa/utils.ts | 31 + lib/{ => shopify}/constants.ts | 0 lib/shopify/index.ts | 6 +- lib/shopify/revalidate.ts | 2 +- lib/{ => shopify}/type-guards.ts | 0 lib/{ => shopify}/utils.ts | 0 tsconfig.json | 21 +- 41 files changed, 3880 insertions(+), 33 deletions(-) create mode 100644 lib/bigcommerce/constants.ts create mode 100644 lib/bigcommerce/fragments/cart.ts create mode 100644 lib/bigcommerce/fragments/page.ts create mode 100644 lib/bigcommerce/fragments/product.ts create mode 100644 lib/bigcommerce/index.ts create mode 100644 lib/bigcommerce/mappers.ts create mode 100644 lib/bigcommerce/mutations/cart.ts create mode 100644 lib/bigcommerce/queries/cart.ts create mode 100644 lib/bigcommerce/queries/category.ts create mode 100644 lib/bigcommerce/queries/checkout.ts create mode 100644 lib/bigcommerce/queries/menu.ts create mode 100644 lib/bigcommerce/queries/page.ts create mode 100644 lib/bigcommerce/queries/product.ts create mode 100644 lib/bigcommerce/queries/route.ts create mode 100644 lib/bigcommerce/storefront-config.ts create mode 100644 lib/bigcommerce/type-guards.ts create mode 100644 lib/bigcommerce/types.ts create mode 100644 lib/bigcommerce/utils.ts create mode 100644 lib/medusa/constants.ts create mode 100644 lib/medusa/helpers.ts create mode 100644 lib/medusa/index.ts create mode 100644 lib/medusa/type-guards.ts create mode 100644 lib/medusa/types.ts create mode 100644 lib/medusa/utils.ts rename lib/{ => shopify}/constants.ts (100%) rename lib/{ => shopify}/type-guards.ts (100%) rename lib/{ => shopify}/utils.ts (100%) diff --git a/app/(frontend)/layout.tsx b/app/(frontend)/layout.tsx index 8262b2e..0ce82b4 100644 --- a/app/(frontend)/layout.tsx +++ b/app/(frontend)/layout.tsx @@ -1,3 +1,4 @@ +import { ensureStartsWith } from '@/lib/shopify/utils'; import config from '@/react-bricks/config'; import { CartProvider } from 'components/cart/cart-context'; import { Navbar } from 'components/layout/navbar'; @@ -8,7 +9,6 @@ import { ThemeProvider } from 'components/react-bricks/theme-provider'; import { WelcomeToast } from 'components/welcome-toast'; import { GeistSans } from 'geist/font/sans'; import { getCart } from 'lib/shopify'; -import { ensureStartsWith } from 'lib/utils'; import { cookies } from 'next/headers'; import { ReactNode } from 'react'; import { PageViewer, cleanPage, fetchPage, getBricks, register, types } from 'react-bricks/rsc'; diff --git a/app/(frontend)/product/[handle]/page.tsx b/app/(frontend)/product/[handle]/page.tsx index a0a3542..3f79be8 100644 --- a/app/(frontend)/product/[handle]/page.tsx +++ b/app/(frontend)/product/[handle]/page.tsx @@ -5,7 +5,7 @@ import ErrorNoKeys from '@/components/react-bricks/error-no-keys'; import ErrorNoPage from '@/components/react-bricks/error-no-page'; import { Product } from '@/lib/shopify/types'; import config from '@/react-bricks/config'; -import { HIDDEN_PRODUCT_TAG } from 'lib/constants'; +import { HIDDEN_PRODUCT_TAG } from '@/lib/shopify/constants'; import { getProduct } from 'lib/shopify'; import { cleanPage, fetchPage, getBricks, JsonLd, PageViewer, types } from 'react-bricks/rsc'; import { ClickToEdit } from 'react-bricks/rsc/client'; diff --git a/app/(frontend)/search/[collection]/page.tsx b/app/(frontend)/search/[collection]/page.tsx index e25542b..aad42d2 100644 --- a/app/(frontend)/search/[collection]/page.tsx +++ b/app/(frontend)/search/[collection]/page.tsx @@ -4,7 +4,7 @@ import { notFound } from 'next/navigation'; import Grid from 'components/grid'; import ProductGridItems from 'components/layout/product-grid-items'; -import { defaultSort, sorting } from 'lib/constants'; +import { defaultSort, sorting } from '@/lib/shopify/constants'; export async function generateMetadata({ params diff --git a/app/(frontend)/search/layout.tsx b/app/(frontend)/search/layout.tsx index 84cce22..2716e5a 100644 --- a/app/(frontend)/search/layout.tsx +++ b/app/(frontend)/search/layout.tsx @@ -1,6 +1,6 @@ import Collections from 'components/layout/search/collections'; import FilterList from 'components/layout/search/filter'; -import { sorting } from 'lib/constants'; +import { sorting } from '@/lib/shopify/constants'; export default function SearchLayout({ children }: { children: React.ReactNode }) { return ( diff --git a/app/(frontend)/search/page.tsx b/app/(frontend)/search/page.tsx index 60f11b1..8a5ff00 100644 --- a/app/(frontend)/search/page.tsx +++ b/app/(frontend)/search/page.tsx @@ -1,6 +1,6 @@ import Grid from 'components/grid'; import ProductGridItems from 'components/layout/product-grid-items'; -import { defaultSort, sorting } from 'lib/constants'; +import { defaultSort, sorting } from '@/lib/shopify/constants'; import { getProducts } from 'lib/shopify'; export const metadata = { diff --git a/app/sitemap.ts b/app/sitemap.ts index 8f31ee9..5cb4ecf 100644 --- a/app/sitemap.ts +++ b/app/sitemap.ts @@ -1,5 +1,5 @@ +import { validateEnvironmentVariables } from '@/lib/shopify/utils'; import { getCollections, getPages, getProducts } from 'lib/shopify'; -import { validateEnvironmentVariables } from 'lib/utils'; import { MetadataRoute } from 'next'; type Route = { diff --git a/components/cart/actions.ts b/components/cart/actions.ts index a2c5925..5e3e031 100644 --- a/components/cart/actions.ts +++ b/components/cart/actions.ts @@ -1,6 +1,6 @@ 'use server'; -import { TAGS } from 'lib/constants'; +import { TAGS } from '@/lib/shopify/constants'; import { addToCart, createCart, getCart, removeFromCart, updateCart } from 'lib/shopify'; import { revalidateTag } from 'next/cache'; import { cookies } from 'next/headers'; diff --git a/components/cart/modal.tsx b/components/cart/modal.tsx index ca1e346..59cf244 100644 --- a/components/cart/modal.tsx +++ b/components/cart/modal.tsx @@ -1,11 +1,11 @@ 'use client'; +import { createUrl } from '@/lib/shopify/utils'; import { Dialog, Transition } from '@headlessui/react'; import { ShoppingCartIcon } from '@heroicons/react/24/outline'; import LoadingDots from 'components/loading-dots'; import Price from 'components/price'; -import { DEFAULT_OPTION } from 'lib/constants'; -import { createUrl } from 'lib/utils'; +import { DEFAULT_OPTION } from '@/lib/shopify/constants'; import Image from 'next/image'; import Link from 'next/link'; import { Fragment, useEffect, useRef, useState } from 'react'; @@ -74,7 +74,7 @@ export default function CartModal() { leaveFrom="translate-x-0" leaveTo="translate-x-full" > - +

My Cart