Update types

This commit is contained in:
Catalin Pinte 2022-12-07 14:34:39 +02:00
parent f9a26370ef
commit 1ba9d3bd6e
6 changed files with 79 additions and 101 deletions

View File

@ -1,8 +1,6 @@
import type { Page } from '@vercel/commerce/types/page'
import type {
Product,
ProductCustomField,
} from '@vercel/commerce/types/product'
import type { Product } from '@vercel/commerce/types/product'
import type { CustomField } from '@vercel/commerce/types/common'
import type { Cart, LineItem } from '@vercel/commerce/types/cart'
import type { Category, Brand } from '@vercel/commerce/types/site'
import type { BigcommerceCart, BCCategory, BCBrand } from '../types'
@ -153,9 +151,7 @@ export function normalizeBrand(brand: BCBrand): Brand {
}
}
function normalizeCustomFieldsValue(
field: CustomFieldEdge
): ProductCustomField {
function normalizeCustomFieldsValue(field: CustomFieldEdge): CustomField {
const {
node: { entityId, name, value },
} = field

View File

@ -34,3 +34,67 @@ export interface Image {
*/
height?: number
}
export interface CustomField {
/**
* The unique identifier for the custom field.
*/
id: string
/**
* The name of the custom field.
*/
name: string
/**
* The value of the custom field.
*/
value: string
}
export interface Metafield {
/**
* The unique identifier for the metafield.
*/
key: string
/**
* The namespace for the metafield, which is a container for a set of metadata.
* @example `rating`
*/
namespace: string
/**
* The value of the metafield, usually a string that can be might parsed into JSON.
* @example `{"value": 5, "scale_max": 5}`
*/
value: any
/**
* The value of the metafield, complete with HTML formatting.
*/
valueHtml?: string
/**
* The type of the metafield, used to determine how the value should be interpreted.
* For example: `string`, `integer`, `boolean`, `json` ...
*/
type?: string
/**
* The name of the metafield, that can be used as a label.
*/
name?: string
}
export interface Metafields {
/**
* The namespace for the metafield, which is a container for a set of metadata.
* @example `reviews`, `specifications`
*/
[namespace: string]: {
/**
* The key of the metafield, which is the name of the metafield.
* @example `rating`
*/
[key: string]: Metafield
}
}

View File

@ -1,4 +1,4 @@
import { Image } from './common'
import { CustomField, Image, Metafields } from './common'
export interface ProductPrice {
/**
@ -84,89 +84,6 @@ export interface ProductVariant {
image?: Image
}
/**
*
* The product metafield object, which is a custom field attached to a product. It can be used to store additional information about the product in a structured format.
* @example `reviews`
*/
export interface ProductMetafield {
/**
* The unique identifier for the metafield.
*/
key: string
/**
* The namespace for the metafield, which is a container for a set of metadata.
* @example `rating`
*/
namespace: string
/**
* The value of the metafield, usually a string that can be might parsed into JSON.
* @example `{"value": 5, "scale_max": 5}`
*/
value: any
/**
* The value of the metafield, complete with HTML formatting.
*/
valueHtml?: string
/**
* The type of the metafield, used to determine how the value should be interpreted.
* For example: `string`, `integer`, `boolean`, `json` ...
*/
type?: string
/**
* The name of the metafield, that can be used as a label.
*/
name?: string
}
/**
* The product metafields are custom fields that can be added to a product. They are used to store additional information about the product.
* @example
* {
* // Namespace, the container for a set of metadata
* reviews: {
* // Key of the metafield
* rating: {
* key: 'rating',
* value: 5,
* // ... other metafield properties
* }
* }
*/
export interface ProductMetafields {
/**
* The namespace for the metafield, which is a container for a set of metadata.
* @example `reviews`, `specifications`
*/
[namespace: string]: {
/**
* The key of the metafield, which is the name of the metafield.
* @example `rating`
*/
[key: string]: ProductMetafield
}
}
export interface ProductCustomField {
/**
* The unique identifier for the custom field.
*/
id: string
/**
* The name of the custom field.
*/
name: string
/**
* The value of the custom field.
*/
value: string
}
export interface Product {
/**
* The unique identifier for the product.
@ -209,7 +126,7 @@ export interface Product {
* value: 'Aisle 3, Shelf 5, Bin 6'
* }]
*/
customFields?: ProductCustomField[]
customFields?: CustomField[]
/**
* Advanced custom fields that can be added to a product. They are used to store additional information about the product, in a structured format, grouped by namespaces.
* @example
@ -226,7 +143,7 @@ export interface Product {
* }
* }
*/
metafields?: ProductMetafields
metafields?: Metafields
/**
* List of the products variants.
*/

View File

@ -1,5 +1,6 @@
import type { Page } from '@vercel/commerce/types/page'
import type { Product, ProductMetafield } from '@vercel/commerce/types/product'
import type { Product } from '@vercel/commerce/types/product'
import type { Metafield } from '@vercel/commerce/types/common'
import type { Cart, LineItem } from '@vercel/commerce/types/cart'
import type { Category } from '@vercel/commerce/types/site'
import type { MetafieldType } from '../types/metafields'
@ -17,7 +18,7 @@ import type {
PageEdge,
Collection,
Maybe,
Metafield,
Metafield as ShopifyMetafield,
} from '../../schema'
import { colorMap } from './colors'
@ -137,10 +138,10 @@ export function normalizeProduct(
}
export function normalizeMetafields(
metafields: Maybe<Metafield>[],
metafields: Maybe<ShopifyMetafield>[],
locale?: string
) {
const output: Record<string, Record<string, ProductMetafield>> = {}
const output: Record<string, Record<string, Metafield>> = {}
if (!metafields) return output

View File

@ -1,7 +1,7 @@
import { ProductCustomField } from '@commerce/types/product'
import type { CustomField } from '@commerce/types/common'
interface Props {
customFields: ProductCustomField[]
customFields: CustomField[]
}
const ProductCustomFields: React.FC<Props> = ({ customFields }) => {

View File

@ -1,9 +1,9 @@
import type { FC } from 'react'
import type { ProductMetafields as IProductMetafields } from '@commerce/types/product'
import type { Metafields } from '@commerce/types/common'
import Text from '@components/ui/Text'
interface Props {
metafields: IProductMetafields
metafields: Metafields
/**
* The namespace of the metafields to display.
*/