mirror of
https://github.com/vercel/commerce.git
synced 2025-07-25 11:11:24 +00:00
Updated commerce types
This commit is contained in:
@@ -1,32 +1,12 @@
|
||||
import type { GetAPISchema } from '@commerce/api'
|
||||
import type { AddItemOperation } from '@commerce/types'
|
||||
import type { CartSchema } from '../../types/cart'
|
||||
import type { CommerceAPI } from '..'
|
||||
import getCart from './get-cart'
|
||||
import addItem from './add-item'
|
||||
import updateItem from './update-item'
|
||||
import removeItem from './remove-item'
|
||||
import type {
|
||||
GetCartHandlerBody,
|
||||
AddCartItemHandlerBody,
|
||||
UpdateCartItemHandlerBody,
|
||||
RemoveCartItemHandlerBody,
|
||||
Cart,
|
||||
} from '../../types'
|
||||
import type { CommerceAPI } from '..'
|
||||
|
||||
export type CartAPI = GetAPISchema<
|
||||
CommerceAPI,
|
||||
{
|
||||
endpoint: {
|
||||
options: {}
|
||||
operations: {
|
||||
getCart: { data: Cart | null; body: GetCartHandlerBody }
|
||||
addItem: { data: Cart; body: AddItemOperation['body'] }
|
||||
updateItem: { data: Cart; body: UpdateCartItemHandlerBody }
|
||||
removeItem: { data: Cart; body: RemoveCartItemHandlerBody }
|
||||
}
|
||||
}
|
||||
}
|
||||
>
|
||||
export type CartAPI = GetAPISchema<CommerceAPI, CartSchema>
|
||||
|
||||
export type CartEndpoint = CartAPI['endpoint']
|
||||
|
||||
|
@@ -1,58 +0,0 @@
|
||||
import * as Core from '@commerce/types'
|
||||
|
||||
// TODO: this type should match:
|
||||
// https://developer.bigcommerce.com/api-reference/cart-checkout/server-server-cart-api/cart/getacart#responses
|
||||
export type BigcommerceCart = {
|
||||
id: string
|
||||
parent_id?: string
|
||||
customer_id: number
|
||||
email: string
|
||||
currency: { code: string }
|
||||
tax_included: boolean
|
||||
base_amount: number
|
||||
discount_amount: number
|
||||
cart_amount: number
|
||||
line_items: {
|
||||
custom_items: any[]
|
||||
digital_items: any[]
|
||||
gift_certificates: any[]
|
||||
physical_items: any[]
|
||||
}
|
||||
created_time: string
|
||||
discounts?: { id: number; discounted_amount: number }[]
|
||||
// TODO: add missing fields
|
||||
}
|
||||
|
||||
export type Cart = Core.Cart & {
|
||||
lineItems: LineItem[]
|
||||
}
|
||||
|
||||
export type LineItem = Core.LineItem
|
||||
|
||||
/**
|
||||
* Cart mutations
|
||||
*/
|
||||
|
||||
export type OptionSelections = {
|
||||
option_id: number
|
||||
option_value: number | string
|
||||
}
|
||||
|
||||
export type CartItemBody = Core.CartItemBody & {
|
||||
productId: string // The product id is always required for BC
|
||||
optionSelections?: OptionSelections
|
||||
}
|
||||
|
||||
export type GetCartHandlerBody = Core.GetCartHandlerBody
|
||||
|
||||
export type AddCartItemBody = Core.AddCartItemBody<CartItemBody>
|
||||
|
||||
export type AddCartItemHandlerBody = Core.AddCartItemHandlerBody<CartItemBody>
|
||||
|
||||
export type UpdateCartItemBody = Core.UpdateCartItemBody<CartItemBody>
|
||||
|
||||
export type UpdateCartItemHandlerBody = Core.UpdateCartItemHandlerBody<CartItemBody>
|
||||
|
||||
export type RemoveCartItemBody = Core.RemoveCartItemBody
|
||||
|
||||
export type RemoveCartItemHandlerBody = Core.RemoveCartItemHandlerBody
|
74
framework/bigcommerce/types/cart.ts
Normal file
74
framework/bigcommerce/types/cart.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import * as Core from '@commerce/types/cart'
|
||||
|
||||
export * from '@commerce/types/cart'
|
||||
|
||||
// TODO: this type should match:
|
||||
// https://developer.bigcommerce.com/api-reference/cart-checkout/server-server-cart-api/cart/getacart#responses
|
||||
export type BigcommerceCart = {
|
||||
id: string
|
||||
parent_id?: string
|
||||
customer_id: number
|
||||
email: string
|
||||
currency: { code: string }
|
||||
tax_included: boolean
|
||||
base_amount: number
|
||||
discount_amount: number
|
||||
cart_amount: number
|
||||
line_items: {
|
||||
custom_items: any[]
|
||||
digital_items: any[]
|
||||
gift_certificates: any[]
|
||||
physical_items: any[]
|
||||
}
|
||||
created_time: string
|
||||
discounts?: { id: number; discounted_amount: number }[]
|
||||
// TODO: add missing fields
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend core cart types
|
||||
*/
|
||||
|
||||
export type Cart = Core.Cart & {
|
||||
lineItems: Core.LineItem[]
|
||||
}
|
||||
|
||||
export type OptionSelections = {
|
||||
option_id: number
|
||||
option_value: number | string
|
||||
}
|
||||
|
||||
export type CartItemBody = Core.CartItemBody & {
|
||||
productId: string // The product id is always required for BC
|
||||
optionSelections?: OptionSelections
|
||||
}
|
||||
|
||||
export type CartHooks = Core.CartHooks & {
|
||||
getCart: { data: Cart | null }
|
||||
addItem: { data: Cart; body: { item: CartItemBody } }
|
||||
updateItem: { data: Cart; body: { item: CartItemBody } }
|
||||
removeItem: { data: Cart | null }
|
||||
}
|
||||
|
||||
export type GetCartHook = CartHooks['getCart']
|
||||
export type AddItemHook = CartHooks['addItem']
|
||||
export type UpdateItemHook = CartHooks['updateItem']
|
||||
export type RemoveItemHook = CartHooks['removeItem']
|
||||
|
||||
export type CartSchema = Core.CartSchema & {
|
||||
endpoint: {
|
||||
operations: CartOperations
|
||||
}
|
||||
}
|
||||
|
||||
export type CartOperations = {
|
||||
getCart: GetCartHook
|
||||
addItem: AddItemHook
|
||||
updateItem: UpdateItemHook
|
||||
removeItem: RemoveItemHook
|
||||
}
|
||||
|
||||
export type GetCartOperation = CartOperations['getCart']
|
||||
export type AddItemOperation = CartOperations['addItem']
|
||||
export type UpdateItemOperation = CartOperations['updateItem']
|
||||
export type RemoveItemOperation = CartOperations['removeItem']
|
2
framework/bigcommerce/types/index.ts
Normal file
2
framework/bigcommerce/types/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from '@commerce/types'
|
||||
export * from './cart'
|
Reference in New Issue
Block a user