diff --git a/lib/bigcommerce/api/operations/get-all-products.ts b/lib/bigcommerce/api/operations/get-all-products.ts index 796c10585..5b3bd1f8b 100644 --- a/lib/bigcommerce/api/operations/get-all-products.ts +++ b/lib/bigcommerce/api/operations/get-all-products.ts @@ -53,6 +53,13 @@ export type GetAllProductsResult< T extends Record = { products: Products } > = T +const FIELDS = [ + 'products', + 'featuredProducts', + 'bestSellingProducts', + 'newestProducts', +] + export type ProductTypes = | 'products' | 'featuredProducts' @@ -92,21 +99,14 @@ async function getAllProducts({ ...vars, } - switch (field) { - case 'products': - variables.products = true - break - case 'featuredProducts': - variables.featuredProducts = true - break - case 'bestSellingProducts': - variables.bestSellingProducts = true - break - case 'newestProducts': - variables.newestProducts = true - break + if (!FIELDS.includes(field)) { + throw new Error( + `The field variable has to match one of ${FIELDS.join(', ')}` + ) } + variables[field] = true + // RecursivePartial forces the method to check for every prop in the data, which is // required in case there's a custom `query` const data = await config.fetch>( diff --git a/lib/bigcommerce/api/wishlist/handlers/get-wishlist.ts b/lib/bigcommerce/api/wishlist/handlers/get-wishlist.ts index 1fcbeaed8..5d0aa19c5 100644 --- a/lib/bigcommerce/api/wishlist/handlers/get-wishlist.ts +++ b/lib/bigcommerce/api/wishlist/handlers/get-wishlist.ts @@ -1,4 +1,3 @@ -import { BigcommerceApiError } from '../../utils/errors' import type { Wishlist, WishlistHandlers } from '..' // Return wishlist info