mirror of
https://github.com/vercel/commerce.git
synced 2025-05-20 16:36:59 +00:00
Update types
This commit is contained in:
parent
f9a26370ef
commit
1ba9d3bd6e
@ -1,8 +1,6 @@
|
|||||||
import type { Page } from '@vercel/commerce/types/page'
|
import type { Page } from '@vercel/commerce/types/page'
|
||||||
import type {
|
import type { Product } from '@vercel/commerce/types/product'
|
||||||
Product,
|
import type { CustomField } from '@vercel/commerce/types/common'
|
||||||
ProductCustomField,
|
|
||||||
} from '@vercel/commerce/types/product'
|
|
||||||
import type { Cart, LineItem } from '@vercel/commerce/types/cart'
|
import type { Cart, LineItem } from '@vercel/commerce/types/cart'
|
||||||
import type { Category, Brand } from '@vercel/commerce/types/site'
|
import type { Category, Brand } from '@vercel/commerce/types/site'
|
||||||
import type { BigcommerceCart, BCCategory, BCBrand } from '../types'
|
import type { BigcommerceCart, BCCategory, BCBrand } from '../types'
|
||||||
@ -153,9 +151,7 @@ export function normalizeBrand(brand: BCBrand): Brand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeCustomFieldsValue(
|
function normalizeCustomFieldsValue(field: CustomFieldEdge): CustomField {
|
||||||
field: CustomFieldEdge
|
|
||||||
): ProductCustomField {
|
|
||||||
const {
|
const {
|
||||||
node: { entityId, name, value },
|
node: { entityId, name, value },
|
||||||
} = field
|
} = field
|
||||||
|
@ -34,3 +34,67 @@ export interface Image {
|
|||||||
*/
|
*/
|
||||||
height?: number
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Image } from './common'
|
import { CustomField, Image, Metafields } from './common'
|
||||||
|
|
||||||
export interface ProductPrice {
|
export interface ProductPrice {
|
||||||
/**
|
/**
|
||||||
@ -84,89 +84,6 @@ export interface ProductVariant {
|
|||||||
image?: Image
|
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 {
|
export interface Product {
|
||||||
/**
|
/**
|
||||||
* The unique identifier for the product.
|
* The unique identifier for the product.
|
||||||
@ -209,7 +126,7 @@ export interface Product {
|
|||||||
* value: 'Aisle 3, Shelf 5, Bin 6'
|
* 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.
|
* 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
|
* @example
|
||||||
@ -226,7 +143,7 @@ export interface Product {
|
|||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
metafields?: ProductMetafields
|
metafields?: Metafields
|
||||||
/**
|
/**
|
||||||
* List of the product’s variants.
|
* List of the product’s variants.
|
||||||
*/
|
*/
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import type { Page } from '@vercel/commerce/types/page'
|
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 { Cart, LineItem } from '@vercel/commerce/types/cart'
|
||||||
import type { Category } from '@vercel/commerce/types/site'
|
import type { Category } from '@vercel/commerce/types/site'
|
||||||
import type { MetafieldType } from '../types/metafields'
|
import type { MetafieldType } from '../types/metafields'
|
||||||
@ -17,7 +18,7 @@ import type {
|
|||||||
PageEdge,
|
PageEdge,
|
||||||
Collection,
|
Collection,
|
||||||
Maybe,
|
Maybe,
|
||||||
Metafield,
|
Metafield as ShopifyMetafield,
|
||||||
} from '../../schema'
|
} from '../../schema'
|
||||||
|
|
||||||
import { colorMap } from './colors'
|
import { colorMap } from './colors'
|
||||||
@ -137,10 +138,10 @@ export function normalizeProduct(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function normalizeMetafields(
|
export function normalizeMetafields(
|
||||||
metafields: Maybe<Metafield>[],
|
metafields: Maybe<ShopifyMetafield>[],
|
||||||
locale?: string
|
locale?: string
|
||||||
) {
|
) {
|
||||||
const output: Record<string, Record<string, ProductMetafield>> = {}
|
const output: Record<string, Record<string, Metafield>> = {}
|
||||||
|
|
||||||
if (!metafields) return output
|
if (!metafields) return output
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { ProductCustomField } from '@commerce/types/product'
|
import type { CustomField } from '@commerce/types/common'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
customFields: ProductCustomField[]
|
customFields: CustomField[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const ProductCustomFields: React.FC<Props> = ({ customFields }) => {
|
const ProductCustomFields: React.FC<Props> = ({ customFields }) => {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import type { FC } from 'react'
|
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'
|
import Text from '@components/ui/Text'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
metafields: IProductMetafields
|
metafields: Metafields
|
||||||
/**
|
/**
|
||||||
* The namespace of the metafields to display.
|
* The namespace of the metafields to display.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user