mirror of
https://github.com/vercel/commerce.git
synced 2025-05-17 23:16:59 +00:00
Convert hooks interfaces to types
This commit is contained in:
parent
77c6d90b7c
commit
e522ec1100
@ -4,8 +4,14 @@ import type {
|
|||||||
HookFetcherContext,
|
HookFetcherContext,
|
||||||
} from '@vercel/commerce/utils/types'
|
} from '@vercel/commerce/utils/types'
|
||||||
import { ValidationError } from '@vercel/commerce/utils/errors'
|
import { ValidationError } from '@vercel/commerce/utils/errors'
|
||||||
import useRemoveItem, { UseRemoveItem } from '@vercel/commerce/cart/use-remove-item'
|
import useRemoveItem, {
|
||||||
import type { Cart, LineItem, RemoveItemHook } from '@vercel/commerce/types/cart'
|
UseRemoveItem,
|
||||||
|
} from '@vercel/commerce/cart/use-remove-item'
|
||||||
|
import type {
|
||||||
|
Cart,
|
||||||
|
LineItem,
|
||||||
|
RemoveItemHook,
|
||||||
|
} from '@vercel/commerce/types/cart'
|
||||||
import useCart from './use-cart'
|
import useCart from './use-cart'
|
||||||
|
|
||||||
export type RemoveItemFn<T = any> = T extends LineItem
|
export type RemoveItemFn<T = any> = T extends LineItem
|
||||||
|
@ -13,15 +13,13 @@ export const withSchemaParser =
|
|||||||
fn: (...args: any[]) => Promise<OperationsData>
|
fn: (...args: any[]) => Promise<OperationsData>
|
||||||
) =>
|
) =>
|
||||||
async (...args: any[]) => {
|
async (...args: any[]) => {
|
||||||
const result = await fn(...args)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const result = await fn(...args)
|
||||||
parse(operation, result)
|
parse(operation, result)
|
||||||
|
return result
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw getOperationError(operation, error)
|
throw getOperationError(operation, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const parse = (operation: AllowedOperations, data: OperationsData) => {
|
const parse = (operation: AllowedOperations, data: OperationsData) => {
|
||||||
|
@ -178,14 +178,14 @@ export type CartHooks = {
|
|||||||
removeItem: RemoveItemHook
|
removeItem: RemoveItemHook
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GetCartHook {
|
export type GetCartHook = {
|
||||||
data: Cart | null
|
data: Cart | null
|
||||||
input: {}
|
input: {}
|
||||||
fetcherInput: { cartId?: string }
|
fetcherInput: { cartId?: string }
|
||||||
swrState: { isEmpty: boolean }
|
swrState: { isEmpty: boolean }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AddItemHook {
|
export type AddItemHook = {
|
||||||
data: Cart
|
data: Cart
|
||||||
input?: CartItemBody
|
input?: CartItemBody
|
||||||
fetcherInput: CartItemBody
|
fetcherInput: CartItemBody
|
||||||
@ -193,7 +193,7 @@ export interface AddItemHook {
|
|||||||
actionInput: CartItemBody
|
actionInput: CartItemBody
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateItemHook {
|
export type UpdateItemHook = {
|
||||||
data: Cart | null | undefined
|
data: Cart | null | undefined
|
||||||
input: { item?: LineItem; wait?: number }
|
input: { item?: LineItem; wait?: number }
|
||||||
fetcherInput: { itemId: string; item: CartItemBody }
|
fetcherInput: { itemId: string; item: CartItemBody }
|
||||||
@ -201,7 +201,7 @@ export interface UpdateItemHook {
|
|||||||
actionInput: CartItemBody & { id: string }
|
actionInput: CartItemBody & { id: string }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RemoveItemHook {
|
export type RemoveItemHook = {
|
||||||
data: Cart | null | undefined
|
data: Cart | null | undefined
|
||||||
input: { item?: LineItem }
|
input: { item?: LineItem }
|
||||||
fetcherInput: { itemId: string }
|
fetcherInput: { itemId: string }
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import type { UseSubmitCheckout } from '../checkout/use-submit-checkout'
|
import type { UseSubmitCheckout } from '../checkout/use-submit-checkout'
|
||||||
import type { Address, AddressFields } from './customer/address'
|
import type { AddressFields } from './customer/address'
|
||||||
import type { Card, CardFields } from './customer/card'
|
import type { Card, CardFields } from './customer/card'
|
||||||
import type { LineItem } from './cart'
|
import type { LineItem } from './cart'
|
||||||
|
|
||||||
export type Checkout = {
|
export interface Checkout {
|
||||||
/**
|
/**
|
||||||
* Indicates if the payment has been submitted.
|
* Indicates if the checkout has payment iformation collected.
|
||||||
*/
|
*/
|
||||||
hasPayment: boolean
|
hasPayment: boolean
|
||||||
/**
|
/**
|
||||||
@ -17,7 +17,7 @@ export type Checkout = {
|
|||||||
*/
|
*/
|
||||||
addressId: string
|
addressId: string
|
||||||
/**
|
/**
|
||||||
* The list of payments that the customer has selected for the checkout.
|
* The list of payment cards that the customer has available.
|
||||||
*/
|
*/
|
||||||
payments?: Card[]
|
payments?: Card[]
|
||||||
/**
|
/**
|
||||||
@ -30,7 +30,7 @@ export type Checkout = {
|
|||||||
lineItems?: LineItem[]
|
lineItems?: LineItem[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CheckoutBody = {
|
export interface CheckoutBody {
|
||||||
/**
|
/**
|
||||||
* The unique identifier for the cart.
|
* The unique identifier for the cart.
|
||||||
*/
|
*/
|
||||||
@ -47,15 +47,7 @@ export type CheckoutBody = {
|
|||||||
address: AddressFields
|
address: AddressFields
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CheckoutTypes {
|
export type SubmitCheckoutHook = {
|
||||||
card?: Card | CardFields
|
|
||||||
address?: Address | AddressFields
|
|
||||||
checkout?: Checkout
|
|
||||||
hasPayment?: boolean
|
|
||||||
hasShipping?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SubmitCheckoutHook {
|
|
||||||
data: Checkout
|
data: Checkout
|
||||||
input?: CheckoutBody
|
input?: CheckoutBody
|
||||||
fetcherInput: CheckoutBody
|
fetcherInput: CheckoutBody
|
||||||
@ -63,15 +55,15 @@ export interface SubmitCheckoutHook {
|
|||||||
actionInput: CheckoutBody
|
actionInput: CheckoutBody
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GetCheckoutHook {
|
export type GetCheckoutHook = {
|
||||||
data: Checkout | null | undefined
|
data: Checkout | null
|
||||||
input: {}
|
input: {}
|
||||||
fetcherInput: { cartId?: string }
|
fetcherInput: { cartId?: string }
|
||||||
swrState: { isEmpty: boolean }
|
swrState: { isEmpty: boolean }
|
||||||
mutations: { submit: UseSubmitCheckout }
|
mutations: { submit: UseSubmitCheckout }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CheckoutHooks {
|
export type CheckoutHooks = {
|
||||||
submitCheckout?: SubmitCheckoutHook
|
submitCheckout?: SubmitCheckoutHook
|
||||||
getCheckout: GetCheckoutHook
|
getCheckout: GetCheckoutHook
|
||||||
}
|
}
|
||||||
|
@ -53,14 +53,14 @@ export interface AddressFields {
|
|||||||
* Hooks for managing a customer's addresses.
|
* Hooks for managing a customer's addresses.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export interface GetAddressesHook {
|
export type GetAddressesHook = {
|
||||||
data: Address[] | null
|
data: Address[] | null
|
||||||
input: {}
|
input: {}
|
||||||
fetcherInput: { cartId?: string }
|
fetcherInput: { cartId?: string }
|
||||||
swrState: { isEmpty: boolean }
|
swrState: { isEmpty: boolean }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AddItemHook {
|
export type AddItemHook = {
|
||||||
data: Address
|
data: Address
|
||||||
input?: AddressFields
|
input?: AddressFields
|
||||||
fetcherInput: AddressFields
|
fetcherInput: AddressFields
|
||||||
@ -68,7 +68,7 @@ export interface AddItemHook {
|
|||||||
actionInput: AddressFields
|
actionInput: AddressFields
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateItemHook {
|
export type UpdateItemHook = {
|
||||||
data: Address | null
|
data: Address | null
|
||||||
input: { item?: AddressFields; wait?: number }
|
input: { item?: AddressFields; wait?: number }
|
||||||
fetcherInput: { itemId: string; item: AddressFields }
|
fetcherInput: { itemId: string; item: AddressFields }
|
||||||
@ -76,7 +76,7 @@ export interface UpdateItemHook {
|
|||||||
actionInput: AddressFields & { id: string }
|
actionInput: AddressFields & { id: string }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RemoveItemHook {
|
export type RemoveItemHook = {
|
||||||
data: Address | null | undefined
|
data: Address | null | undefined
|
||||||
input: { item?: Address }
|
input: { item?: Address }
|
||||||
fetcherInput: { itemId: string }
|
fetcherInput: { itemId: string }
|
||||||
@ -84,7 +84,7 @@ export interface RemoveItemHook {
|
|||||||
actionInput: { id: string }
|
actionInput: { id: string }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CustomerAddressHooks {
|
export type CustomerAddressHooks = {
|
||||||
getAddresses: GetAddressesHook
|
getAddresses: GetAddressesHook
|
||||||
addItem: AddItemHook
|
addItem: AddItemHook
|
||||||
updateItem: UpdateItemHook
|
updateItem: UpdateItemHook
|
||||||
|
@ -70,14 +70,14 @@ export interface CardFields {
|
|||||||
* Hooks for managing a customer's cards.
|
* Hooks for managing a customer's cards.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export interface GetCardsHook {
|
export type GetCardsHook = {
|
||||||
data: Card[] | null
|
data: Card[] | null
|
||||||
input: {}
|
input: {}
|
||||||
fetcherInput: { cartId?: string }
|
fetcherInput: { cartId?: string }
|
||||||
swrState: { isEmpty: boolean }
|
swrState: { isEmpty: boolean }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AddItemHook {
|
export type AddItemHook = {
|
||||||
data: Card
|
data: Card
|
||||||
input?: CardFields
|
input?: CardFields
|
||||||
fetcherInput: CardFields
|
fetcherInput: CardFields
|
||||||
@ -85,7 +85,7 @@ export interface AddItemHook {
|
|||||||
actionInput: CardFields
|
actionInput: CardFields
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateItemHook {
|
export type UpdateItemHook = {
|
||||||
data: Card | null | undefined
|
data: Card | null | undefined
|
||||||
input: { item?: CardFields; wait?: number }
|
input: { item?: CardFields; wait?: number }
|
||||||
fetcherInput: { itemId: string; item: CardFields }
|
fetcherInput: { itemId: string; item: CardFields }
|
||||||
@ -93,7 +93,7 @@ export interface UpdateItemHook {
|
|||||||
actionInput: CardFields & { id: string }
|
actionInput: CardFields & { id: string }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RemoveItemHook {
|
export type RemoveItemHook = {
|
||||||
data: Card | null | undefined
|
data: Card | null | undefined
|
||||||
input: { item?: Card }
|
input: { item?: Card }
|
||||||
fetcherInput: { itemId: string }
|
fetcherInput: { itemId: string }
|
||||||
|
@ -37,7 +37,7 @@ export interface Customer {
|
|||||||
acceptsMarketing?: boolean
|
acceptsMarketing?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CustomerHook {
|
export type CustomerHook = {
|
||||||
data: Customer | null | undefined
|
data: Customer | null | undefined
|
||||||
fetchData: { customer: Customer } | null
|
fetchData: { customer: Customer } | null
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ export interface LoginBody {
|
|||||||
password: string
|
password: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LoginHook {
|
export type LoginHook = {
|
||||||
data: null
|
data: null
|
||||||
actionInput: LoginBody
|
actionInput: LoginBody
|
||||||
fetcherInput: LoginBody
|
fetcherInput: LoginBody
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export interface LogoutHook {
|
export type LogoutHook = {
|
||||||
data: null
|
data: null
|
||||||
body: {
|
body: {
|
||||||
redirectTo?: string
|
redirectTo?: string
|
||||||
|
@ -162,7 +162,7 @@ export interface SearchProductsBody {
|
|||||||
/**
|
/**
|
||||||
* Fetches a list of products based on the given search criteria.
|
* Fetches a list of products based on the given search criteria.
|
||||||
*/
|
*/
|
||||||
export interface SearchProductsHook {
|
export type SearchProductsHook = {
|
||||||
data: {
|
data: {
|
||||||
/**
|
/**
|
||||||
* List of products matching the query.
|
* List of products matching the query.
|
||||||
@ -182,7 +182,7 @@ export interface SearchProductsHook {
|
|||||||
* Product API schema
|
* Product API schema
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export interface ProductsSchema {
|
export type ProductsSchema = {
|
||||||
endpoint: {
|
endpoint: {
|
||||||
options: {}
|
options: {}
|
||||||
handlers: {
|
handlers: {
|
||||||
@ -195,12 +195,12 @@ export interface ProductsSchema {
|
|||||||
* Product operations
|
* Product operations
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export interface GetAllProductPathsOperation {
|
export type GetAllProductPathsOperation = {
|
||||||
data: { products: Pick<Product, 'path'>[] }
|
data: { products: Pick<Product, 'path'>[] }
|
||||||
variables: { first?: number }
|
variables: { first?: number }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GetAllProductsOperation {
|
export type GetAllProductsOperation = {
|
||||||
data: { products: Product[] }
|
data: { products: Product[] }
|
||||||
variables: {
|
variables: {
|
||||||
relevance?: 'featured' | 'best_selling' | 'newest'
|
relevance?: 'featured' | 'best_selling' | 'newest'
|
||||||
@ -209,7 +209,7 @@ export interface GetAllProductsOperation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GetProductOperation {
|
export type GetProductOperation = {
|
||||||
data: { product?: Product }
|
data: { product?: Product }
|
||||||
variables: { path: string; slug?: never } | { path?: never; slug: string }
|
variables: { path: string; slug?: never } | { path?: never; slug: string }
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export type SignupBody = {
|
export interface SignupBody {
|
||||||
/**
|
/**
|
||||||
* The user's first name.
|
* The user's first name.
|
||||||
*/
|
*/
|
||||||
@ -17,7 +17,7 @@ export type SignupBody = {
|
|||||||
password: string
|
password: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SignupHook {
|
export type SignupHook = {
|
||||||
data: null
|
data: null
|
||||||
body: SignupBody
|
body: SignupBody
|
||||||
actionInput: SignupBody
|
actionInput: SignupBody
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export type Category = {
|
export interface Category {
|
||||||
/**
|
/**
|
||||||
* Unique identifier for the category.
|
* Unique identifier for the category.
|
||||||
*/
|
*/
|
||||||
@ -19,7 +19,7 @@ export type Category = {
|
|||||||
path: string
|
path: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Brand = {
|
export interface Brand {
|
||||||
/**
|
/**
|
||||||
* Unique identifier for the brand.
|
* Unique identifier for the brand.
|
||||||
*/
|
*/
|
||||||
|
@ -50,7 +50,7 @@ export interface WishlistItemBody {
|
|||||||
wishlistToken?: string
|
wishlistToken?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GetWishlistHook {
|
export type GetWishlistHook = {
|
||||||
data: Wishlist | null | undefined
|
data: Wishlist | null | undefined
|
||||||
body: { includeProducts?: boolean }
|
body: { includeProducts?: boolean }
|
||||||
input: { includeProducts?: boolean }
|
input: { includeProducts?: boolean }
|
||||||
@ -58,14 +58,14 @@ export interface GetWishlistHook {
|
|||||||
swrState: { isEmpty: boolean }
|
swrState: { isEmpty: boolean }
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AddItemHook {
|
export type AddItemHook = {
|
||||||
data: Wishlist | null | undefined
|
data: Wishlist | null | undefined
|
||||||
body: { item: WishlistItemBody }
|
body: { item: WishlistItemBody }
|
||||||
fetcherInput: { item: WishlistItemBody }
|
fetcherInput: { item: WishlistItemBody }
|
||||||
actionInput: WishlistItemBody
|
actionInput: WishlistItemBody
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RemoveItemHook {
|
export type RemoveItemHook = {
|
||||||
data: Wishlist | null | undefined
|
data: Wishlist | null | undefined
|
||||||
body: { itemId: string; wishlistToken?: string }
|
body: { itemId: string; wishlistToken?: string }
|
||||||
fetcherInput: { itemId: string; wishlistToken?: string }
|
fetcherInput: { itemId: string; wishlistToken?: string }
|
||||||
@ -91,7 +91,7 @@ export type WishlistSchema = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GetCustomerWishlistOperation {
|
export type GetCustomerWishlistOperation = {
|
||||||
data: { wishlist?: Wishlist }
|
data: { wishlist?: Wishlist }
|
||||||
variables: { customerId: string }
|
variables: { customerId: string }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user