From 5b8e758e3021e742324d3f3a7a3db28fa689fd3d Mon Sep 17 00:00:00 2001 From: Zaiste Date: Tue, 15 Jun 2021 14:38:41 +0200 Subject: [PATCH] custom checkout 404 for Saleor --- .../saleor/api/endpoints/checkout/index.ts | 62 +++++++++++++------ .../saleor/api/operations/get-all-pages.ts | 15 ++--- next.config.js | 2 +- 3 files changed, 49 insertions(+), 30 deletions(-) diff --git a/framework/saleor/api/endpoints/checkout/index.ts b/framework/saleor/api/endpoints/checkout/index.ts index f15672435..45ae5a6d9 100644 --- a/framework/saleor/api/endpoints/checkout/index.ts +++ b/framework/saleor/api/endpoints/checkout/index.ts @@ -1,16 +1,9 @@ -import { CommerceAPI, GetAPISchema, createEndpoint } from '@commerce/api' -import checkoutEndpoint from '@commerce/api/endpoints/checkout' +import { NextApiHandler } from 'next' +import { CommerceAPI, createEndpoint, GetAPISchema } from '@commerce/api' import { CheckoutSchema } from '@commerce/types/checkout' +import checkoutEndpoint from '@commerce/api/endpoints/checkout' -export type CheckoutAPI = GetAPISchema - -export type CheckoutEndpoint = CheckoutAPI['endpoint'] - -const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({ - req, - res, - config, -}) => { +const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({ req, res, config }) => { try { const html = ` @@ -18,17 +11,42 @@ const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({ - Checkout + Saleor Checkout + -
- - - -

Checkout not yet implemented :(

-

- See #64 -

+
+
+ +

+ Check vercel/commerce#64 for details +

+
@@ -47,6 +65,10 @@ const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({ } } +export type CheckoutAPI = GetAPISchema + +export type CheckoutEndpoint = CheckoutAPI['endpoint'] + export const handlers: CheckoutEndpoint['handlers'] = { checkout } const checkoutApi = createEndpoint({ diff --git a/framework/saleor/api/operations/get-all-pages.ts b/framework/saleor/api/operations/get-all-pages.ts index f3ed54e27..7ba07450d 100644 --- a/framework/saleor/api/operations/get-all-pages.ts +++ b/framework/saleor/api/operations/get-all-pages.ts @@ -6,14 +6,9 @@ import * as Query from '../../utils/queries' export type Page = any - export type GetAllPagesResult< - T extends { pages: any[] } = { pages: Page[] } - > = T - -export default function getAllPagesOperation({ - commerce, -}: OperationContext) { +export type GetAllPagesResult = T +export default function getAllPagesOperation({ commerce }: OperationContext) { async function getAllPages({ query = Query.PageMany, config, @@ -27,7 +22,9 @@ export default function getAllPagesOperation({ } = {}): Promise { const { fetch, locale, locales = ['en-US'] } = commerce.getConfig(config) - const { data } = await fetch(query, { variables }, + const { data } = await fetch( + query, + { variables }, { ...(locale && { headers: { @@ -42,7 +39,7 @@ export default function getAllPagesOperation({ url: `/${locale}/${slug}`, name, })) - + return { pages } } diff --git a/next.config.js b/next.config.js index 77d586e6c..c51f47704 100644 --- a/next.config.js +++ b/next.config.js @@ -22,7 +22,7 @@ module.exports = withCommerceConfig({ }, rewrites() { return [ - (isBC || isShopify || isSwell || isVendure) && { + (isBC || isShopify || isSwell || isVendure || isSaleor) && { source: '/checkout', destination: '/api/checkout', },