Dynamic API routes (#836)

* Add dynamic API endpoints

* Add missing dependency

* Update api handlers

* Updates

* Fix build errors

* Update package.json

* Add checkout endpoint parser & update errors

* Update tsconfig.json

* Update cart.ts

* Update parser

* Update errors.ts

* Update errors.ts

* Move to Edge runtime

* Revert to local

* Fix switchable runtimes

* Make nodejs default runtime

* Update pnpm-lock.yaml

* Update handlers

* Fix build errors

* Change headers
This commit is contained in:
Catalin Pinte
2022-10-30 20:41:21 +02:00
committed by GitHub
parent a5b367a747
commit c75b0fc001
316 changed files with 2482 additions and 2176 deletions

View File

@@ -1 +0,0 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -1 +0,0 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -1 +0,0 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -2,11 +2,9 @@ import type { CheckoutEndpoint } from '.'
const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
req: _request,
res: response,
config: _config,
}) => {
try {
const html = `
const html = `
<!DOCTYPE html>
<html lang="en">
<head>
@@ -28,17 +26,11 @@ const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
</html>
`
response.status(200)
response.setHeader('Content-Type', 'text/html')
response.write(html)
response.end()
} catch (error) {
console.error(error)
const message = 'An unexpected error ocurred'
response.status(500).json({ data: null, errors: [{ message }] })
}
return new Response(html, {
headers: {
'content-type': 'text/html',
},
})
}
export default getCheckout

View File

@@ -1 +0,0 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -1 +0,0 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -1 +0,0 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -0,0 +1,11 @@
import type { SpreeApiProvider, SpreeApi } from '..'
import createEndpoints from '@vercel/commerce/api/endpoints'
import checkout from './checkout'
const endpoints = {
checkout,
}
export default function spreeAPI(commerce: SpreeApi) {
return createEndpoints<SpreeApiProvider>(commerce, endpoints)
}

View File

@@ -1 +0,0 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -1 +0,0 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -1 +0,0 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -1 +0,0 @@
export default function noopApi(...args: any[]): void {}

View File

@@ -9,7 +9,6 @@ import { GraphQLFetcher, GraphQLFetcherResult } from '@vercel/commerce/api'
import createCustomizedFetchFetcher, {
fetchResponseKey,
} from '../../utils/create-customized-fetch-fetcher'
import fetch, { Request } from 'node-fetch'
import type { SpreeSdkResponseWithRawResponse } from '../../types'
import prettyPrintSpreeSdkErrors from '../../utils/pretty-print-spree-sdk-errors'

View File

@@ -5,8 +5,7 @@ import type {
JsonApiSingleResponse,
} from '@spree/storefront-api-v2-sdk/types/interfaces/JsonApi'
import type { ResultResponse } from '@spree/storefront-api-v2-sdk/types/interfaces/ResultResponse'
import type { Response } from '@vercel/fetch'
import type { ProductOption, Product } from '@vercel/commerce/types/product'
import type { ProductOption } from '@vercel/commerce/types/product'
import type {
Wishlist as CoreWishlist,
WishlistItemBody as CoreWishlistItemBody,