4
0
forked from crowetic/commerce
commerce/framework/types.d.ts

168 lines
4.1 KiB
TypeScript
Raw Normal View History

2021-01-10 16:16:49 -03:00
interface Entity {
2021-01-06 17:01:32 -03:00
id: string | number
2021-01-10 16:16:49 -03:00
[prop: string]: any
}
interface Product extends Entity {
2021-01-06 17:01:32 -03:00
name: string
description: string
slug?: string
path?: string
2021-01-11 14:13:29 -03:00
images: ProductImage[]
variants: ProductVariant[]
2021-01-10 15:55:11 -03:00
price: ProductPrice
2021-01-11 14:54:05 -03:00
options: ProductOption[]
2021-01-14 12:58:41 -03:00
sku?: string
2021-01-06 17:01:32 -03:00
}
2021-01-11 14:54:05 -03:00
interface ProductOption extends Entity {
displayName: string
values: ProductOptionValues[]
}
interface ProductOptionValues {
label: string
hexColors?: string[]
}
2021-01-07 16:28:50 -03:00
interface ProductImage {
url: string
alt?: string
}
interface ProductVariant {
id: string | number
2021-01-11 16:16:00 -03:00
options: ProductOption[]
2021-01-07 16:28:50 -03:00
}
2021-01-06 17:01:32 -03:00
2021-01-07 11:58:00 -03:00
interface ProductPrice {
2021-01-10 15:55:11 -03:00
value: number
2021-01-10 16:16:49 -03:00
currencyCode: 'USD' | 'ARS' | string | undefined
2021-01-14 12:58:41 -03:00
retailPrice?: number
salePrice?: number
listPrice?: number
extendedSalePrice?: number
extendedListPrice?: number
2021-01-06 17:01:32 -03:00
}
2021-01-09 12:05:40 -03:00
2021-01-25 13:51:15 -05:00
interface DiscountBase {
// The value of the discount, can be an amount or percentage
value: number
}
interface BaseLineItem {
id: string
variantId: string
name: string
quantity: number
discounts: DiscountBase[]
variant: BaseProductVariant
}
interface Measurement {
value: number
unit: 'KILOGRAMS' | 'GRAMS' | 'POUNDS' | 'OUNCES'
}
interface Image {
url: string
altText?: string
width?: number
height?: number
}
interface BaseProductVariant {
id: string
// The SKU (stock keeping unit) associated with the product variant.
sku: string
// The product variants title, or the product's name.
name: string
// Indicates whether this product variant is in stock.
isInStock: boolean
// Indicates if the product variant is available for sale.
availableForSale: boolean
// Whether a customer needs to provide a shipping address when placing
// an order for the product variant.
requiresShipping: boolean
// Image associated with the product variant. Falls back to the product image
// if no image is available.
image: Image
// The variant's weight. If a weight was not explicitly specified on the
// variant this will be the product's weight.
weight?: Measurement
// The variant's height. If a height was not explicitly specified on the
// variant, this will be the product's height.
height?: Measurement
// The variant's width. If a width was not explicitly specified on the
// variant, this will be the product's width.
width?: Measurement
// The variant's depth. If a depth was not explicitly specified on the
// variant, this will be the product's depth.
depth?: Measurement
}
// Shopping cart, a.k.a Checkout
interface BaseCart {
id: string
// ID of the customer to which the cart belongs.
customerId?: string
// The email assigned to this cart
email?: string
// The date and time when the cart was created.
createdAt: string
// The currency used for this cart
currency: { code: string }
// Specifies if taxes are included in the line items.
taxesIncluded: boolean
lineItems: Pick<Product, 'id' | 'name' | 'prices'> & CartItem[]
// The sum of all the prices of all the items in the cart.
// Duties, taxes, shipping and discounts excluded.
lineItemsSubtotalPrice: number
// Price of the cart before duties, shipping and taxes.
subtotalPrice: number
// The sum of all the prices of all the items in the cart.
// Duties, taxes and discounts included.
totalPrice: number
// Discounts that have been applied on the cart.
discounts?: DiscountBase[]
}
2021-01-10 16:16:49 -03:00
interface Cart extends Entity {
2021-01-12 16:59:07 -03:00
id: string | undefined
currency: { code: string }
taxIncluded?: boolean
2021-01-19 12:33:50 -03:00
items: Pick<Product, 'id' | 'name' | 'prices'> & CartItem[]
2021-01-19 11:07:40 -03:00
subTotal: number | string
total: number | string
2021-01-19 12:33:50 -03:00
customerId: Customer['id']
2021-01-14 12:58:41 -03:00
}
interface CartItem extends Entity {
quantity: number
productId: Product['id']
variantId: ProductVariant['id']
images: ProductImage[]
2021-01-09 12:07:17 -03:00
}
2021-01-10 16:16:49 -03:00
interface Wishlist extends Entity {
2021-01-09 12:07:17 -03:00
products: Pick<Product, 'id' | 'name' | 'prices'>[]
2021-01-09 12:05:40 -03:00
}
2021-01-09 12:17:31 -03:00
interface Order {}
2021-01-11 16:16:00 -03:00
interface Customer extends Entity {}
2021-01-09 12:05:40 -03:00
2021-01-10 14:11:00 -03:00
type UseCustomerResponse = {
customer: Customer
} | null
2021-01-10 16:16:49 -03:00
interface Category extends Entity {
2021-01-09 12:17:31 -03:00
name: string
}
2021-01-10 16:16:49 -03:00
interface Brand extends Entity {
2021-01-09 12:17:31 -03:00
name: string
}
2021-01-09 12:05:40 -03:00
2021-01-09 12:17:31 -03:00
type Features = 'wishlist' | 'customer'