mirror of
https://github.com/vercel/commerce.git
synced 2025-06-15 11:51:21 +00:00
* Update product types * Cart types progress, add zod & initial schema validator * Update normalize.ts * Update with-schema-parser.ts * Updated types, schemas & providers * Fix providers after schema parse errors * Fix paths * More provider fixes * Fix kibocommerce & commercejs * Add customer updated types & fixes * Add checkout & customer types * Import core types only from commerce * Update tsconfig.json * Convert hooks interfaces to types * Requested changes * Change to relative paths * Move Zod dependency
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import type { Product } from '@vercel/commerce/types/product'
|
|
|
|
import type { RawProduct } from '../types/product'
|
|
|
|
export function normalize(product: RawProduct): Product {
|
|
return {
|
|
id: product.ID,
|
|
name: product.Name,
|
|
description: product.Description,
|
|
slug: product.ID,
|
|
path: `/${product.ID}`,
|
|
images: product.xp.Images,
|
|
price: {
|
|
value: product.xp.Price,
|
|
currencyCode: product.xp.PriceCurrency,
|
|
},
|
|
variants: product.xp.Variants?.length
|
|
? product.xp.Variants.map((variant) => ({
|
|
id: variant.ID,
|
|
sku: variant.ID,
|
|
name: product.Name,
|
|
options: variant.Specs.map((spec) => ({
|
|
id: spec.SpecID,
|
|
__typename: 'MultipleChoiceOption',
|
|
displayName: spec.Name,
|
|
values: [
|
|
{
|
|
label: spec.Value,
|
|
},
|
|
],
|
|
})),
|
|
}))
|
|
: [],
|
|
options: product.xp.Specs?.length
|
|
? product.xp.Specs.map((spec) => ({
|
|
id: spec.ID,
|
|
displayName: spec.Name,
|
|
values: spec.Options.map((option) => ({
|
|
label: option.Value,
|
|
...(option.xp?.hexColor && { hexColors: [option.xp.hexColor] }),
|
|
})),
|
|
}))
|
|
: [],
|
|
}
|
|
}
|