diff --git a/packages/bigcommerce/src/cart/use-remove-item.tsx b/packages/bigcommerce/src/cart/use-remove-item.tsx index 8bea34f41..bed12c96b 100644 --- a/packages/bigcommerce/src/cart/use-remove-item.tsx +++ b/packages/bigcommerce/src/cart/use-remove-item.tsx @@ -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 extends LineItem diff --git a/packages/commerce/src/api/utils/with-schema-parser.ts b/packages/commerce/src/api/utils/with-schema-parser.ts index 41af1987e..aabe1ea8f 100644 --- a/packages/commerce/src/api/utils/with-schema-parser.ts +++ b/packages/commerce/src/api/utils/with-schema-parser.ts @@ -13,15 +13,13 @@ export const withSchemaParser = fn: (...args: any[]) => Promise ) => 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) => { diff --git a/packages/commerce/src/types/cart.ts b/packages/commerce/src/types/cart.ts index 686308029..261aba4a9 100644 --- a/packages/commerce/src/types/cart.ts +++ b/packages/commerce/src/types/cart.ts @@ -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 } diff --git a/packages/commerce/src/types/checkout.ts b/packages/commerce/src/types/checkout.ts index a1ce6937c..8b5d428fc 100644 --- a/packages/commerce/src/types/checkout.ts +++ b/packages/commerce/src/types/checkout.ts @@ -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 } diff --git a/packages/commerce/src/types/customer/address.ts b/packages/commerce/src/types/customer/address.ts index f32fa5cab..ec4aace50 100644 --- a/packages/commerce/src/types/customer/address.ts +++ b/packages/commerce/src/types/customer/address.ts @@ -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 diff --git a/packages/commerce/src/types/customer/card.ts b/packages/commerce/src/types/customer/card.ts index 406d74b89..11956ffcc 100644 --- a/packages/commerce/src/types/customer/card.ts +++ b/packages/commerce/src/types/customer/card.ts @@ -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 } diff --git a/packages/commerce/src/types/customer/index.ts b/packages/commerce/src/types/customer/index.ts index 87d954028..89a963a29 100644 --- a/packages/commerce/src/types/customer/index.ts +++ b/packages/commerce/src/types/customer/index.ts @@ -37,7 +37,7 @@ export interface Customer { acceptsMarketing?: boolean } -export interface CustomerHook { +export type CustomerHook = { data: Customer | null | undefined fetchData: { customer: Customer } | null } diff --git a/packages/commerce/src/types/login.ts b/packages/commerce/src/types/login.ts index 1ea50e9a3..e032b1827 100644 --- a/packages/commerce/src/types/login.ts +++ b/packages/commerce/src/types/login.ts @@ -9,7 +9,7 @@ export interface LoginBody { password: string } -export interface LoginHook { +export type LoginHook = { data: null actionInput: LoginBody fetcherInput: LoginBody diff --git a/packages/commerce/src/types/logout.ts b/packages/commerce/src/types/logout.ts index 6a949eb3c..df981b06e 100644 --- a/packages/commerce/src/types/logout.ts +++ b/packages/commerce/src/types/logout.ts @@ -1,4 +1,4 @@ -export interface LogoutHook { +export type LogoutHook = { data: null body: { redirectTo?: string diff --git a/packages/commerce/src/types/product.ts b/packages/commerce/src/types/product.ts index 5c0790217..2f6c34acb 100644 --- a/packages/commerce/src/types/product.ts +++ b/packages/commerce/src/types/product.ts @@ -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[] } 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 } } diff --git a/packages/commerce/src/types/signup.ts b/packages/commerce/src/types/signup.ts index b7c7a4b2f..17754cf15 100644 --- a/packages/commerce/src/types/signup.ts +++ b/packages/commerce/src/types/signup.ts @@ -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 diff --git a/packages/commerce/src/types/site.ts b/packages/commerce/src/types/site.ts index 57b885a1f..3552db08f 100644 --- a/packages/commerce/src/types/site.ts +++ b/packages/commerce/src/types/site.ts @@ -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. */ diff --git a/packages/commerce/src/types/wishlist.ts b/packages/commerce/src/types/wishlist.ts index aa6341963..5c5e0d1ea 100644 --- a/packages/commerce/src/types/wishlist.ts +++ b/packages/commerce/src/types/wishlist.ts @@ -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 } }