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