mirror of
https://github.com/vercel/commerce.git
synced 2025-05-17 15:06:59 +00:00
Fix providers after schema parse errors
This commit is contained in:
parent
ba0e7beb73
commit
a44a6c0291
@ -2,10 +2,13 @@ import type {
|
||||
OperationContext,
|
||||
OperationOptions,
|
||||
} from '@vercel/commerce/api/operations'
|
||||
import type { Page, GetAllPagesOperation } from '../../types/page'
|
||||
import type { GetAllPagesOperation } from '../../types/page'
|
||||
import type { RecursivePartial, RecursiveRequired } from '../utils/types'
|
||||
import { BigcommerceConfig, Provider } from '..'
|
||||
|
||||
import { definitions } from '../definitions/store-content'
|
||||
import { normalizePage } from '../../lib/normalize'
|
||||
|
||||
export default function getAllPagesOperation({
|
||||
commerce,
|
||||
}: OperationContext<Provider>) {
|
||||
@ -33,12 +36,14 @@ export default function getAllPagesOperation({
|
||||
// RecursivePartial forces the method to check for every prop in the data, which is
|
||||
// required in case there's a custom `url`
|
||||
const { data } = await cfg.storeApiFetch<
|
||||
RecursivePartial<{ data: Page[] }>
|
||||
RecursivePartial<{ data: definitions['page_Full'][] }>
|
||||
>('/v3/content/pages')
|
||||
const pages = (data as RecursiveRequired<typeof data>) ?? []
|
||||
|
||||
return {
|
||||
pages: preview ? pages : pages.filter((p) => p.is_visible),
|
||||
pages: preview
|
||||
? pages.map(normalizePage)
|
||||
: pages.filter((p) => p.is_visible).map(normalizePage),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ export function normalizePage(page: definitions['page_Full']): Page {
|
||||
name: page.name,
|
||||
is_visible: page.is_visible,
|
||||
sort_order: page.sort_order,
|
||||
body: page.body,
|
||||
body: page.body ?? '',
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ const normalizePage = (
|
||||
id: spreePage.id,
|
||||
name: spreePage.attributes.title,
|
||||
url: `/${usedCommerceLocale}/${spreePage.attributes.slug}`,
|
||||
body: spreePage.attributes.content,
|
||||
body: spreePage.attributes.content ?? '',
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,10 +31,13 @@ export default function getAllPagesOperation({
|
||||
const { locale, fetch } = config
|
||||
const data = await fetch('content', 'list', ['pages'])
|
||||
const pages =
|
||||
data?.results?.map(({ slug, ...rest }: { slug: string }) => ({
|
||||
url: `/${locale}/${slug}`,
|
||||
data?.results?.map(
|
||||
({ slug, body, ...rest }: { slug: string; body: string }) => ({
|
||||
...rest,
|
||||
})) ?? []
|
||||
url: `/${locale}/${slug}`,
|
||||
body: body ?? '',
|
||||
})
|
||||
) ?? []
|
||||
return {
|
||||
pages,
|
||||
}
|
||||
|
@ -210,7 +210,7 @@ function normalizeLineItem({
|
||||
price: price,
|
||||
listPrice: price,
|
||||
},
|
||||
path: '',
|
||||
path: `/${product.slug}`,
|
||||
discounts: [],
|
||||
options: [
|
||||
{
|
||||
|
@ -45,7 +45,7 @@ export function normalizeCart(order: CartFragment): Cart {
|
||||
productId: l.productVariant.productId,
|
||||
images: [{ url: l.featuredAsset?.preview + '?preset=thumb' || '' }],
|
||||
discounts: l.discounts.map((d) => ({ value: d.amount / 100 })),
|
||||
path: '',
|
||||
path: `/${l.productVariant.product.slug}`,
|
||||
variant: {
|
||||
id: l.productVariant.id,
|
||||
name: l.productVariant.name,
|
||||
|
Loading…
x
Reference in New Issue
Block a user