diff --git a/lib/bigcommerce/api/index.ts b/lib/bigcommerce/api/index.ts index 457451326..f5dad43e4 100644 --- a/lib/bigcommerce/api/index.ts +++ b/lib/bigcommerce/api/index.ts @@ -69,12 +69,3 @@ export default class BigcommerceAPI implements CommerceAPI { }; } } - -let h = new BigcommerceAPI({ apiToken: '', commerceUrl: '' }); - -async function yay() { - const x = await h.getAllProducts<{ custom: 'val' }>({ query: 'yes' }); - const y = await h.getAllProducts(); - - console.log(x.products); -} diff --git a/lib/commerce-api.ts b/lib/commerce-api.ts new file mode 100644 index 000000000..38d5dfd66 --- /dev/null +++ b/lib/commerce-api.ts @@ -0,0 +1,9 @@ +import BigcommerceAPI from './bigcommerce/api'; + +const API_URL = process.env.NEXT_EXAMPLE_BIGCOMMERCE_STOREFRONT_API_URL!; +const API_TOKEN = process.env.NEXT_EXAMPLE_BIGCOMMERCE_STOREFRONT_API_TOKEN!; + +export const commerce = new BigcommerceAPI({ + commerceUrl: API_URL, + apiToken: API_TOKEN, +}); diff --git a/lib/commerce/api/index.ts b/lib/commerce/api/index.ts index 27fafd902..7bd9f893c 100644 --- a/lib/commerce/api/index.ts +++ b/lib/commerce/api/index.ts @@ -14,7 +14,7 @@ export interface CommerceAPI { fetch(query: string, queryData?: CommerceAPIFetchOptions): Promise; - getAllProducts(options?: { query?: string }): Promise; + getAllProducts(options?: { query: string }): Promise; } // export default class CommerceAPI { diff --git a/pages/index.tsx b/pages/index.tsx index 3f7ab723f..89e476476 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,6 +1,20 @@ -import { Layout } from "@components/core"; +import { GetStaticPropsContext, InferGetStaticPropsType } from 'next'; +import { commerce } from 'lib/commerce-api'; +import { Layout } from '@components/core'; + +export async function getStaticProps({ preview }: GetStaticPropsContext) { + const products = await commerce.getAllProducts(); + + return { + props: { products }, + }; +} + +export default function Home({ + products, +}: InferGetStaticPropsType) { + console.log('PRODUCTS', products); -export default function Home() { return (