From c82f2c5e6141191c589f7ccae1f2be317746b695 Mon Sep 17 00:00:00 2001 From: Luis Alvarez Date: Tue, 27 Oct 2020 05:16:20 -0500 Subject: [PATCH] Remove updated hooks --- lib/bigcommerce/api/cart/handlers/add-item.ts | 40 - lib/bigcommerce/api/checkout.ts | 77 - lib/bigcommerce/api/fragments/product.ts | 113 - lib/bigcommerce/api/index.ts | 88 - .../api/operations/get-all-products.ts | 132 -- .../api/operations/get-customer-wishlist.ts | 87 - lib/bigcommerce/api/operations/get-product.ts | 118 - .../api/operations/get-site-info.ts | 106 - .../api/wishlist/handlers/get-wishlist.ts | 37 - lib/bigcommerce/api/wishlist/index.ts | 103 - lib/bigcommerce/cart/use-remove-item.tsx | 51 - lib/bigcommerce/schema.d.ts | 2064 ----------------- lib/bigcommerce/wishlist/use-add-item.tsx | 57 - lib/bigcommerce/wishlist/use-remove-item.tsx | 61 - lib/bigcommerce/wishlist/use-wishlist.tsx | 76 - lib/commerce/utils/types.ts | 24 - 16 files changed, 3234 deletions(-) delete mode 100644 lib/bigcommerce/api/cart/handlers/add-item.ts delete mode 100644 lib/bigcommerce/api/checkout.ts delete mode 100644 lib/bigcommerce/api/fragments/product.ts delete mode 100644 lib/bigcommerce/api/index.ts delete mode 100644 lib/bigcommerce/api/operations/get-all-products.ts delete mode 100644 lib/bigcommerce/api/operations/get-customer-wishlist.ts delete mode 100644 lib/bigcommerce/api/operations/get-product.ts delete mode 100644 lib/bigcommerce/api/operations/get-site-info.ts delete mode 100644 lib/bigcommerce/api/wishlist/handlers/get-wishlist.ts delete mode 100644 lib/bigcommerce/api/wishlist/index.ts delete mode 100644 lib/bigcommerce/cart/use-remove-item.tsx delete mode 100644 lib/bigcommerce/schema.d.ts delete mode 100644 lib/bigcommerce/wishlist/use-add-item.tsx delete mode 100644 lib/bigcommerce/wishlist/use-remove-item.tsx delete mode 100644 lib/bigcommerce/wishlist/use-wishlist.tsx delete mode 100644 lib/commerce/utils/types.ts diff --git a/lib/bigcommerce/api/cart/handlers/add-item.ts b/lib/bigcommerce/api/cart/handlers/add-item.ts deleted file mode 100644 index 25ae3880e..000000000 --- a/lib/bigcommerce/api/cart/handlers/add-item.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { parseCartItem } from '../../utils/parse-item' -import getCartCookie from '../../utils/get-cart-cookie' -import type { CartHandlers } from '..' - -// Return current cart info -const addItem: CartHandlers['addItem'] = async ({ - res, - body: { cartId, item }, - config, -}) => { - if (!item) { - return res.status(400).json({ - data: null, - errors: [{ message: 'Missing item' }], - }) - } - if (!item.quantity) item.quantity = 1 - - const options = { - method: 'POST', - body: JSON.stringify({ - line_items: [parseCartItem(item)], - ...(!cartId && config.storeChannelId - ? { channel_id: config.storeChannelId } - : {}), - }), - } - const { data } = cartId - ? await config.storeApiFetch(`/v3/carts/${cartId}/items`, options) - : await config.storeApiFetch('/v3/carts', options) - - // Create or update the cart cookie - res.setHeader( - 'Set-Cookie', - getCartCookie(config.cartCookie, data.id, config.cartCookieMaxAge) - ) - res.status(200).json({ data }) -} - -export default addItem diff --git a/lib/bigcommerce/api/checkout.ts b/lib/bigcommerce/api/checkout.ts deleted file mode 100644 index 530f4c40a..000000000 --- a/lib/bigcommerce/api/checkout.ts +++ /dev/null @@ -1,77 +0,0 @@ -import isAllowedMethod from './utils/is-allowed-method' -import createApiHandler, { - BigcommerceApiHandler, -} from './utils/create-api-handler' -import { BigcommerceApiError } from './utils/errors' - -const METHODS = ['GET'] -const fullCheckout = true - -// TODO: a complete implementation should have schema validation for `req.body` -const checkoutApi: BigcommerceApiHandler = async (req, res, config) => { - if (!isAllowedMethod(req, res, METHODS)) return - - const { cookies } = req - const cartId = cookies[config.cartCookie] - - try { - if (!cartId) { - res.redirect('/cart') - return - } - - const { data } = await config.storeApiFetch( - `/v3/carts/${cartId}/redirect_urls`, - { - method: 'POST', - } - ) - - if (fullCheckout) { - res.redirect(data.checkout_url) - return - } - - // TODO: make the embedded checkout work too! - const html = ` - - - - - - Checkout - - - - -
- - - ` - - res.status(200) - res.setHeader('Content-Type', 'text/html') - res.write(html) - res.end() - } catch (error) { - console.error(error) - - const message = - error instanceof BigcommerceApiError - ? 'An unexpected error ocurred with the Bigcommerce API' - : 'An unexpected error ocurred' - - res.status(500).json({ data: null, errors: [{ message }] }) - } -} - -export default createApiHandler(checkoutApi, {}, {}) diff --git a/lib/bigcommerce/api/fragments/product.ts b/lib/bigcommerce/api/fragments/product.ts deleted file mode 100644 index d266b8c92..000000000 --- a/lib/bigcommerce/api/fragments/product.ts +++ /dev/null @@ -1,113 +0,0 @@ -export const productPrices = /* GraphQL */ ` - fragment productPrices on Prices { - price { - value - currencyCode - } - salePrice { - value - currencyCode - } - retailPrice { - value - currencyCode - } - } -` - -export const swatchOptionFragment = /* GraphQL */ ` - fragment swatchOption on SwatchOptionValue { - isDefault - hexColors - } -` - -export const multipleChoiceOptionFragment = /* GraphQL */ ` - fragment multipleChoiceOption on MultipleChoiceOption { - values { - edges { - node { - label - ...swatchOption - } - } - } - } - - ${swatchOptionFragment} -` - -export const productInfoFragment = /* GraphQL */ ` - fragment productInfo on Product { - entityId - name - path - brand { - entityId - } - description - prices { - ...productPrices - } - images { - edges { - node { - urlOriginal - altText - isDefault - } - } - } - variants { - edges { - node { - entityId - defaultImage { - urlOriginal - altText - isDefault - } - } - } - } - productOptions { - edges { - node { - __typename - entityId - displayName - ...multipleChoiceOption - } - } - } - localeMeta: metafields(namespace: $locale, keys: ["name", "description"]) - @include(if: $hasLocale) { - edges { - node { - key - value - } - } - } - } - - ${productPrices} - ${multipleChoiceOptionFragment} -` - -export const productConnectionFragment = /* GraphQL */ ` - fragment productConnnection on ProductConnection { - pageInfo { - startCursor - endCursor - } - edges { - cursor - node { - ...productInfo - } - } - } - - ${productInfoFragment} -` diff --git a/lib/bigcommerce/api/index.ts b/lib/bigcommerce/api/index.ts deleted file mode 100644 index 545d8590d..000000000 --- a/lib/bigcommerce/api/index.ts +++ /dev/null @@ -1,88 +0,0 @@ -import type { RequestInit } from '@vercel/fetch' -import type { CommerceAPIConfig } from '../../commerce/api' -import fetchGraphqlApi from './utils/fetch-graphql-api' -import fetchStoreApi from './utils/fetch-store-api' - -export interface BigcommerceConfig extends CommerceAPIConfig { - // Indicates if the returned metadata with translations should be applied to the - // data or returned as it is - applyLocale?: boolean - storeApiUrl: string - storeApiToken: string - storeApiClientId: string - storeChannelId?: string - storeApiFetch(endpoint: string, options?: RequestInit): Promise -} - -const API_URL = process.env.BIGCOMMERCE_STOREFRONT_API_URL -const API_TOKEN = process.env.BIGCOMMERCE_STOREFRONT_API_TOKEN -const STORE_API_URL = process.env.BIGCOMMERCE_STORE_API_URL -const STORE_API_TOKEN = process.env.BIGCOMMERCE_STORE_API_TOKEN -const STORE_API_CLIENT_ID = process.env.BIGCOMMERCE_STORE_API_CLIENT_ID -const STORE_CHANNEL_ID = process.env.BIGCOMMERCE_CHANNEL_ID - -if (!API_URL) { - throw new Error( - `The environment variable BIGCOMMERCE_STOREFRONT_API_URL is missing and it's required to access your store` - ) -} - -if (!API_TOKEN) { - throw new Error( - `The environment variable BIGCOMMERCE_STOREFRONT_API_TOKEN is missing and it's required to access your store` - ) -} - -if (!(STORE_API_URL && STORE_API_TOKEN && STORE_API_CLIENT_ID)) { - throw new Error( - `The environment variables BIGCOMMERCE_STORE_API_URL, BIGCOMMERCE_STORE_API_TOKEN, BIGCOMMERCE_STORE_API_CLIENT_ID have to be set in order to access the REST API of your store` - ) -} - -export class Config { - private config: BigcommerceConfig - - constructor(config: Omit) { - this.config = { - ...config, - // The customerCookie is not customizable for now, BC sets the cookie and it's - // not important to rename it - customerCookie: 'SHOP_TOKEN', - } - } - - getConfig(userConfig: Partial = {}) { - return Object.entries(userConfig).reduce( - (cfg, [key, value]) => Object.assign(cfg, { [key]: value }), - { ...this.config } - ) - } - - setConfig(newConfig: Partial) { - Object.assign(this.config, newConfig) - } -} - -const ONE_DAY = 60 * 60 * 24 -const config = new Config({ - commerceUrl: API_URL, - apiToken: API_TOKEN, - cartCookie: process.env.BIGCOMMERCE_CART_COOKIE ?? 'bc_cartId', - cartCookieMaxAge: ONE_DAY * 30, - fetch: fetchGraphqlApi, - applyLocale: true, - // REST API only - storeApiUrl: STORE_API_URL, - storeApiToken: STORE_API_TOKEN, - storeApiClientId: STORE_API_CLIENT_ID, - storeChannelId: STORE_CHANNEL_ID, - storeApiFetch: fetchStoreApi, -}) - -export function getConfig(userConfig?: Partial) { - return config.getConfig(userConfig) -} - -export function setConfig(newConfig: Partial) { - return config.setConfig(newConfig) -} diff --git a/lib/bigcommerce/api/operations/get-all-products.ts b/lib/bigcommerce/api/operations/get-all-products.ts deleted file mode 100644 index 0cd9737c2..000000000 --- a/lib/bigcommerce/api/operations/get-all-products.ts +++ /dev/null @@ -1,132 +0,0 @@ -import type { - GetAllProductsQuery, - GetAllProductsQueryVariables, -} from '../../schema' -import type { RecursivePartial, RecursiveRequired } from '../utils/types' -import filterEdges from '../utils/filter-edges' -import setProductLocaleMeta from '../utils/set-product-locale-meta' -import { productConnectionFragment } from '../fragments/product' -import { BigcommerceConfig, getConfig } from '..' - -export const getAllProductsQuery = /* GraphQL */ ` - query getAllProducts( - $hasLocale: Boolean = false - $locale: String = "null" - $entityIds: [Int!] - $first: Int = 10 - $products: Boolean = false - $featuredProducts: Boolean = false - $bestSellingProducts: Boolean = false - $newestProducts: Boolean = false - ) { - site { - products(first: $first, entityIds: $entityIds) @include(if: $products) { - ...productConnnection - } - featuredProducts(first: $first) @include(if: $featuredProducts) { - ...productConnnection - } - bestSellingProducts(first: $first) @include(if: $bestSellingProducts) { - ...productConnnection - } - newestProducts(first: $first) @include(if: $newestProducts) { - ...productConnnection - } - } - } - - ${productConnectionFragment} -` - -export type ProductEdge = NonNullable< - NonNullable[0] -> - -export type ProductNode = ProductEdge['node'] - -export type GetAllProductsResult< - T extends Record = { - products: ProductEdge[] - } -> = T - -const FIELDS = [ - 'products', - 'featuredProducts', - 'bestSellingProducts', - 'newestProducts', -] - -export type ProductTypes = - | 'products' - | 'featuredProducts' - | 'bestSellingProducts' - | 'newestProducts' - -export type ProductVariables = { field?: ProductTypes } & Omit< - GetAllProductsQueryVariables, - ProductTypes | 'hasLocale' -> - -async function getAllProducts(opts?: { - variables?: ProductVariables - config?: BigcommerceConfig - preview?: boolean -}): Promise - -async function getAllProducts< - T extends Record, - V = any ->(opts: { - query: string - variables?: V - config?: BigcommerceConfig - preview?: boolean -}): Promise> - -async function getAllProducts({ - query = getAllProductsQuery, - variables: { field = 'products', ...vars } = {}, - config, -}: { - query?: string - variables?: ProductVariables - config?: BigcommerceConfig - preview?: boolean -} = {}): Promise { - config = getConfig(config) - - const locale = vars.locale || config.locale - const variables: GetAllProductsQueryVariables = { - ...vars, - locale, - hasLocale: !!locale, - } - - 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>( - query, - { variables } - ) - const edges = data.site?.[field]?.edges - const products = filterEdges(edges as RecursiveRequired) - - if (locale && config.applyLocale) { - products.forEach((product: RecursivePartial) => { - if (product.node) setProductLocaleMeta(product.node) - }) - } - - return { products } -} - -export default getAllProducts diff --git a/lib/bigcommerce/api/operations/get-customer-wishlist.ts b/lib/bigcommerce/api/operations/get-customer-wishlist.ts deleted file mode 100644 index 2c1299b46..000000000 --- a/lib/bigcommerce/api/operations/get-customer-wishlist.ts +++ /dev/null @@ -1,87 +0,0 @@ -import type { RecursivePartial, RecursiveRequired } from '../utils/types' -import { definitions } from '../definitions/wishlist' -import { BigcommerceConfig, getConfig } from '..' -import getAllProducts, { ProductEdge } from './get-all-products' - -export type Wishlist = Omit & { - items?: WishlistItem[] -} - -export type WishlistItem = NonNullable< - definitions['wishlist_Full']['items'] ->[0] & { - product?: ProductEdge['node'] -} - -export type GetCustomerWishlistResult< - T extends { wishlist?: any } = { wishlist?: Wishlist } -> = T - -export type GetCustomerWishlistVariables = { - customerId: number -} - -async function getCustomerWishlist(opts: { - variables: GetCustomerWishlistVariables - config?: BigcommerceConfig - includeProducts?: boolean -}): Promise - -async function getCustomerWishlist< - T extends { wishlist?: any }, - V = any ->(opts: { - url: string - variables: V - config?: BigcommerceConfig - includeProducts?: boolean -}): Promise> - -async function getCustomerWishlist({ - config, - variables, - includeProducts, -}: { - url?: string - variables: GetCustomerWishlistVariables - config?: BigcommerceConfig - includeProducts?: boolean -}): Promise { - config = getConfig(config) - - const { data = [] } = await config.storeApiFetch< - RecursivePartial<{ data: Wishlist[] }> - >(`/v3/wishlists?customer_id=${variables.customerId}`) - const wishlist = data[0] - - if (includeProducts && wishlist?.items?.length) { - const entityIds = wishlist.items - ?.map((item) => item?.product_id) - .filter((id): id is number => !!id) - - if (entityIds?.length) { - const graphqlData = await getAllProducts({ - variables: { first: 100, entityIds }, - config, - }) - // Put the products in an object that we can use to get them by id - const productsById = graphqlData.products.reduce<{ - [k: number]: ProductEdge - }>((prods, p) => { - prods[p.node.entityId] = p - return prods - }, {}) - // Populate the wishlist items with the graphql products - wishlist.items.forEach((item) => { - const product = item && productsById[item.product_id!] - if (item && product) { - item.product = product.node - } - }) - } - } - - return { wishlist: wishlist as RecursiveRequired } -} - -export default getCustomerWishlist diff --git a/lib/bigcommerce/api/operations/get-product.ts b/lib/bigcommerce/api/operations/get-product.ts deleted file mode 100644 index e75e87607..000000000 --- a/lib/bigcommerce/api/operations/get-product.ts +++ /dev/null @@ -1,118 +0,0 @@ -import type { GetProductQuery, GetProductQueryVariables } from '../../schema' -import setProductLocaleMeta from '../utils/set-product-locale-meta' -import { productInfoFragment } from '../fragments/product' -import { BigcommerceConfig, getConfig } from '..' - -export const getProductQuery = /* GraphQL */ ` - query getProduct( - $hasLocale: Boolean = false - $locale: String = "null" - $path: String! - ) { - site { - route(path: $path) { - node { - __typename - ... on Product { - ...productInfo - variants { - edges { - node { - entityId - defaultImage { - urlOriginal - altText - isDefault - } - prices { - ...productPrices - } - inventory { - aggregated { - availableToSell - warningLevel - } - isInStock - } - productOptions { - edges { - node { - __typename - entityId - displayName - ...multipleChoiceOption - } - } - } - } - } - } - } - } - } - } - } - - ${productInfoFragment} -` - -export type ProductNode = Extract< - GetProductQuery['site']['route']['node'], - { __typename: 'Product' } -> - -export type GetProductResult< - T extends { product?: any } = { product?: ProductNode } -> = T - -export type ProductVariables = { locale?: string } & ( - | { path: string; slug?: never } - | { path?: never; slug: string } -) - -async function getProduct(opts: { - variables: ProductVariables - config?: BigcommerceConfig - preview?: boolean -}): Promise - -async function getProduct(opts: { - query: string - variables: V - config?: BigcommerceConfig - preview?: boolean -}): Promise> - -async function getProduct({ - query = getProductQuery, - variables: { slug, ...vars }, - config, -}: { - query?: string - variables: ProductVariables - config?: BigcommerceConfig - preview?: boolean -}): Promise { - config = getConfig(config) - - const locale = vars.locale || config.locale - const variables: GetProductQueryVariables = { - ...vars, - locale, - hasLocale: !!locale, - path: slug ? `/${slug}/` : vars.path!, - } - const { data } = await config.fetch(query, { variables }) - const product = data.site?.route?.node - - if (product?.__typename === 'Product') { - if (locale && config.applyLocale) { - setProductLocaleMeta(product) - } - return { product } - } - - return {} -} - -export default getProduct diff --git a/lib/bigcommerce/api/operations/get-site-info.ts b/lib/bigcommerce/api/operations/get-site-info.ts deleted file mode 100644 index 44c0cfeb5..000000000 --- a/lib/bigcommerce/api/operations/get-site-info.ts +++ /dev/null @@ -1,106 +0,0 @@ -import type { GetSiteInfoQuery, GetSiteInfoQueryVariables } from '../../schema' -import type { RecursivePartial, RecursiveRequired } from '../utils/types' -import filterEdges from '../utils/filter-edges' -import { BigcommerceConfig, getConfig } from '..' -import { categoryTreeItemFragment } from '../fragments/category-tree' - -// Get 3 levels of categories -export const getSiteInfoQuery = /* GraphQL */ ` - query getSiteInfo { - site { - categoryTree { - ...categoryTreeItem - children { - ...categoryTreeItem - children { - ...categoryTreeItem - } - } - } - brands { - pageInfo { - startCursor - endCursor - } - edges { - cursor - node { - entityId - name - defaultImage { - urlOriginal - altText - } - pageTitle - metaDesc - metaKeywords - searchKeywords - path - } - } - } - } - } - ${categoryTreeItemFragment} -` - -export type CategoriesTree = NonNullable< - GetSiteInfoQuery['site']['categoryTree'] -> - -export type BrandEdge = NonNullable< - NonNullable[0] -> - -export type Brands = BrandEdge[] - -export type GetSiteInfoResult< - T extends { categories: any[]; brands: any[] } = { - categories: CategoriesTree - brands: Brands - } -> = T - -async function getSiteInfo(opts?: { - variables?: GetSiteInfoQueryVariables - config?: BigcommerceConfig - preview?: boolean -}): Promise - -async function getSiteInfo< - T extends { categories: any[]; brands: any[] }, - V = any ->(opts: { - query: string - variables?: V - config?: BigcommerceConfig - preview?: boolean -}): Promise> - -async function getSiteInfo({ - query = getSiteInfoQuery, - variables, - config, -}: { - query?: string - variables?: GetSiteInfoQueryVariables - config?: BigcommerceConfig - preview?: boolean -} = {}): Promise { - config = getConfig(config) - // 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>( - query, - { variables } - ) - const categories = data.site?.categoryTree - const brands = data.site?.brands?.edges - - return { - categories: (categories as RecursiveRequired) ?? [], - brands: filterEdges(brands as RecursiveRequired), - } -} - -export default getSiteInfo diff --git a/lib/bigcommerce/api/wishlist/handlers/get-wishlist.ts b/lib/bigcommerce/api/wishlist/handlers/get-wishlist.ts deleted file mode 100644 index 3eb3000cc..000000000 --- a/lib/bigcommerce/api/wishlist/handlers/get-wishlist.ts +++ /dev/null @@ -1,37 +0,0 @@ -import getCustomerId from '../../operations/get-customer-id' -import getCustomerWishlist from '../../operations/get-customer-wishlist' -import type { Wishlist, WishlistHandlers } from '..' - -// Return wishlist info -const getWishlist: WishlistHandlers['getWishlist'] = async ({ - res, - body: { customerToken, includeProducts }, - config, -}) => { - let result: { data?: Wishlist } = {} - - if (customerToken) { - const customerId = - customerToken && (await getCustomerId({ customerToken, config })) - - if (!customerId) { - // If the customerToken is invalid, then this request is too - return res.status(404).json({ - data: null, - errors: [{ message: 'Wishlist not found' }], - }) - } - - const { wishlist } = await getCustomerWishlist({ - variables: { customerId }, - includeProducts, - config, - }) - - result = { data: wishlist } - } - - res.status(200).json({ data: result.data ?? null }) -} - -export default getWishlist diff --git a/lib/bigcommerce/api/wishlist/index.ts b/lib/bigcommerce/api/wishlist/index.ts deleted file mode 100644 index 94194dd41..000000000 --- a/lib/bigcommerce/api/wishlist/index.ts +++ /dev/null @@ -1,103 +0,0 @@ -import isAllowedMethod from '../utils/is-allowed-method' -import createApiHandler, { - BigcommerceApiHandler, - BigcommerceHandler, -} from '../utils/create-api-handler' -import { BigcommerceApiError } from '../utils/errors' -import type { - Wishlist, - WishlistItem, -} from '../operations/get-customer-wishlist' -import getWishlist from './handlers/get-wishlist' -import addItem from './handlers/add-item' -import removeItem from './handlers/remove-item' - -export type { Wishlist, WishlistItem } - -export type ItemBody = { - productId: number - variantId: number -} - -export type AddItemBody = { item: ItemBody } - -export type RemoveItemBody = { itemId: string } - -export type WishlistBody = { - customer_id: number - is_public: number - name: string - items: any[] -} - -export type AddWishlistBody = { wishlist: WishlistBody } - -export type WishlistHandlers = { - getWishlist: BigcommerceHandler< - Wishlist, - { customerToken?: string; includeProducts?: boolean } - > - addItem: BigcommerceHandler< - Wishlist, - { customerToken?: string } & Partial - > - removeItem: BigcommerceHandler< - Wishlist, - { customerToken?: string } & Partial - > -} - -const METHODS = ['GET', 'POST', 'DELETE'] - -// TODO: a complete implementation should have schema validation for `req.body` -const wishlistApi: BigcommerceApiHandler = async ( - req, - res, - config, - handlers -) => { - if (!isAllowedMethod(req, res, METHODS)) return - - const { cookies } = req - const customerToken = cookies[config.customerCookie] - - try { - // Return current wishlist info - if (req.method === 'GET') { - const body = { - customerToken, - includeProducts: req.query.products === '1', - } - return await handlers['getWishlist']({ req, res, config, body }) - } - - // Add an item to the wishlist - if (req.method === 'POST') { - const body = { ...req.body, customerToken } - return await handlers['addItem']({ req, res, config, body }) - } - - // Remove an item from the wishlist - if (req.method === 'DELETE') { - const body = { ...req.body, customerToken } - return await handlers['removeItem']({ req, res, config, body }) - } - } catch (error) { - console.error(error) - - const message = - error instanceof BigcommerceApiError - ? 'An unexpected error ocurred with the Bigcommerce API' - : 'An unexpected error ocurred' - - res.status(500).json({ data: null, errors: [{ message }] }) - } -} - -export const handlers = { - getWishlist, - addItem, - removeItem, -} - -export default createApiHandler(wishlistApi, handlers, {}) diff --git a/lib/bigcommerce/cart/use-remove-item.tsx b/lib/bigcommerce/cart/use-remove-item.tsx deleted file mode 100644 index 6660d02aa..000000000 --- a/lib/bigcommerce/cart/use-remove-item.tsx +++ /dev/null @@ -1,51 +0,0 @@ -import { useCallback } from 'react' -import { HookFetcher } from '../../commerce/utils/types' -import useCartRemoveItem from '../../commerce/cart/use-remove-item' -import type { RemoveItemBody } from '../api/cart' -import useCart, { Cart } from './use-cart' - -const defaultOpts = { - url: '/api/bigcommerce/cart', - method: 'DELETE', -} - -export type RemoveItemInput = { - id: string -} - -export const fetcher: HookFetcher = ( - options, - { itemId }, - fetch -) => { - return fetch({ - ...defaultOpts, - ...options, - body: { itemId }, - }) -} - -export function extendHook(customFetcher: typeof fetcher) { - const useRemoveItem = (item?: any) => { - const { mutate } = useCart() - const fn = useCartRemoveItem( - defaultOpts, - customFetcher - ) - - return useCallback( - async function removeItem(input: RemoveItemInput) { - const data = await fn({ itemId: input.id ?? item?.id }) - await mutate(data, false) - return data - }, - [fn, mutate] - ) - } - - useRemoveItem.extend = extendHook - - return useRemoveItem -} - -export default extendHook(fetcher) diff --git a/lib/bigcommerce/schema.d.ts b/lib/bigcommerce/schema.d.ts deleted file mode 100644 index 04824e263..000000000 --- a/lib/bigcommerce/schema.d.ts +++ /dev/null @@ -1,2064 +0,0 @@ -export type Maybe = T | null -export type Exact = { - [K in keyof T]: T[K] -} -/** All built-in and custom scalars, mapped to their actual values */ -export type Scalars = { - ID: string - String: string - Boolean: boolean - Int: number - Float: number - DateTime: any - /** The `BigDecimal` scalar type represents signed fractional values with arbitrary precision. */ - BigDecimal: any - /** The `Long` scalar type represents non-fractional signed whole numeric values. Long can represent values between -(2^63) and 2^63 - 1. */ - Long: any -} - -/** Login result */ -export type LoginResult = { - __typename?: 'LoginResult' - /** The result of a login */ - result: Scalars['String'] -} - -/** Logout result */ -export type LogoutResult = { - __typename?: 'LogoutResult' - /** The result of a logout */ - result: Scalars['String'] -} - -export type Mutation = { - __typename?: 'Mutation' - login: LoginResult - logout: LogoutResult -} - -export type MutationLoginArgs = { - email: Scalars['String'] - password: Scalars['String'] -} - -/** Aggregated */ -export type Aggregated = { - __typename?: 'Aggregated' - /** Number of available products in stock. This can be 'null' if inventory is not set orif the store's Inventory Settings disable displaying stock levels on the storefront. */ - availableToSell: Scalars['Long'] - /** Indicates a threshold low-stock level. This can be 'null' if the inventory warning level is not set or if the store's Inventory Settings disable displaying stock levels on the storefront. */ - warningLevel: Scalars['Int'] -} - -/** Aggregated Product Inventory */ -export type AggregatedInventory = { - __typename?: 'AggregatedInventory' - /** Number of available products in stock. This can be 'null' if inventory is not set orif the store's Inventory Settings disable displaying stock levels on the storefront. */ - availableToSell: Scalars['Int'] - /** Indicates a threshold low-stock level. This can be 'null' if the inventory warning level is not set or if the store's Inventory Settings disable displaying stock levels on the storefront. */ - warningLevel: Scalars['Int'] -} - -/** Brand */ -export type Brand = Node & { - __typename?: 'Brand' - /** The ID of an object */ - id: Scalars['ID'] - /** Id of the brand. */ - entityId: Scalars['Int'] - /** Name of the brand. */ - name: Scalars['String'] - /** Default image for brand. */ - defaultImage?: Maybe - /** Page title for the brand. */ - pageTitle: Scalars['String'] - /** Meta description for the brand. */ - metaDesc: Scalars['String'] - /** Meta keywords for the brand. */ - metaKeywords: Array - /** Search keywords for the brand. */ - searchKeywords: Array - /** Path for the brand page. */ - path: Scalars['String'] - products: ProductConnection - /** Metafield data related to a brand. */ - metafields: MetafieldConnection -} - -/** Brand */ -export type BrandProductsArgs = { - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe -} - -/** Brand */ -export type BrandMetafieldsArgs = { - namespace: Scalars['String'] - keys?: Maybe> - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe -} - -/** A connection to a list of items. */ -export type BrandConnection = { - __typename?: 'BrandConnection' - /** Information to aid in pagination. */ - pageInfo: PageInfo - /** A list of edges. */ - edges?: Maybe>> -} - -/** An edge in a connection. */ -export type BrandEdge = { - __typename?: 'BrandEdge' - /** The item at the end of the edge. */ - node: Brand - /** A cursor for use in pagination. */ - cursor: Scalars['String'] -} - -/** Breadcrumb */ -export type Breadcrumb = { - __typename?: 'Breadcrumb' - /** Category id. */ - entityId: Scalars['Int'] - /** Name of the category. */ - name: Scalars['String'] -} - -/** A connection to a list of items. */ -export type BreadcrumbConnection = { - __typename?: 'BreadcrumbConnection' - /** Information to aid in pagination. */ - pageInfo: PageInfo - /** A list of edges. */ - edges?: Maybe>> -} - -/** An edge in a connection. */ -export type BreadcrumbEdge = { - __typename?: 'BreadcrumbEdge' - /** The item at the end of the edge. */ - node: Breadcrumb - /** A cursor for use in pagination. */ - cursor: Scalars['String'] -} - -/** Bulk pricing tier that sets a fixed price for the product or variant. */ -export type BulkPricingFixedPriceDiscount = BulkPricingTier & { - __typename?: 'BulkPricingFixedPriceDiscount' - /** This price will override the current product price. */ - price: Scalars['BigDecimal'] - /** Minimum item quantity that applies to this bulk pricing tier. */ - minimumQuantity: Scalars['Int'] - /** Maximum item quantity that applies to this bulk pricing tier - if not defined then the tier does not have an upper bound. */ - maximumQuantity?: Maybe -} - -/** Bulk pricing tier that reduces the price of the product or variant by a percentage. */ -export type BulkPricingPercentageDiscount = BulkPricingTier & { - __typename?: 'BulkPricingPercentageDiscount' - /** The percentage that will be removed from the product price. */ - percentOff: Scalars['BigDecimal'] - /** Minimum item quantity that applies to this bulk pricing tier. */ - minimumQuantity: Scalars['Int'] - /** Maximum item quantity that applies to this bulk pricing tier - if not defined then the tier does not have an upper bound. */ - maximumQuantity?: Maybe -} - -/** Bulk pricing tier that will subtract an amount from the price of the product or variant. */ -export type BulkPricingRelativePriceDiscount = BulkPricingTier & { - __typename?: 'BulkPricingRelativePriceDiscount' - /** The price of the product/variant will be reduced by this priceAdjustment. */ - priceAdjustment: Scalars['BigDecimal'] - /** Minimum item quantity that applies to this bulk pricing tier. */ - minimumQuantity: Scalars['Int'] - /** Maximum item quantity that applies to this bulk pricing tier - if not defined then the tier does not have an upper bound. */ - maximumQuantity?: Maybe -} - -/** A set of bulk pricing tiers that define price discounts which apply when purchasing specified quantities of a product or variant. */ -export type BulkPricingTier = { - /** Minimum item quantity that applies to this bulk pricing tier. */ - minimumQuantity: Scalars['Int'] - /** Maximum item quantity that applies to this bulk pricing tier - if not defined then the tier does not have an upper bound. */ - maximumQuantity?: Maybe -} - -/** Product Option */ -export type CatalogProductOption = { - /** Unique ID for the option. */ - entityId: Scalars['Int'] - /** Display name for the option. */ - displayName: Scalars['String'] - /** One of the option values is required to be selected for the checkout. */ - isRequired: Scalars['Boolean'] -} - -/** Product Option Value */ -export type CatalogProductOptionValue = { - /** Unique ID for the option value. */ - entityId: Scalars['Int'] - /** Label for the option value. */ - label: Scalars['String'] - /** Indicates whether this value is the chosen default selected value. */ - isDefault: Scalars['Boolean'] -} - -/** Category */ -export type Category = Node & { - __typename?: 'Category' - /** The ID of an object */ - id: Scalars['ID'] - /** Unique ID for the category. */ - entityId: Scalars['Int'] - /** Category name. */ - name: Scalars['String'] - /** Category path. */ - path: Scalars['String'] - /** Default image for the category. */ - defaultImage?: Maybe - /** Category description. */ - description: Scalars['String'] - /** Category breadcrumbs. */ - breadcrumbs: BreadcrumbConnection - products: ProductConnection - /** Metafield data related to a category. */ - metafields: MetafieldConnection -} - -/** Category */ -export type CategoryBreadcrumbsArgs = { - depth: Scalars['Int'] - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe -} - -/** Category */ -export type CategoryProductsArgs = { - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe -} - -/** Category */ -export type CategoryMetafieldsArgs = { - namespace: Scalars['String'] - keys?: Maybe> - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe -} - -/** A connection to a list of items. */ -export type CategoryConnection = { - __typename?: 'CategoryConnection' - /** Information to aid in pagination. */ - pageInfo: PageInfo - /** A list of edges. */ - edges?: Maybe>> -} - -/** An edge in a connection. */ -export type CategoryEdge = { - __typename?: 'CategoryEdge' - /** The item at the end of the edge. */ - node: Category - /** A cursor for use in pagination. */ - cursor: Scalars['String'] -} - -/** An item in a tree of categories. */ -export type CategoryTreeItem = { - __typename?: 'CategoryTreeItem' - /** The id category. */ - entityId: Scalars['Int'] - /** The name of category. */ - name: Scalars['String'] - /** Path assigned to this category */ - path: Scalars['String'] - /** The description of this category. */ - description: Scalars['String'] - /** The number of products in this category. */ - productCount: Scalars['Int'] - /** Subcategories of this category */ - children: Array -} - -/** A simple yes/no question represented by a checkbox. */ -export type CheckboxOption = CatalogProductOption & { - __typename?: 'CheckboxOption' - /** Indicates the default checked status. */ - checkedByDefault: Scalars['Boolean'] - /** Unique ID for the option. */ - entityId: Scalars['Int'] - /** Display name for the option. */ - displayName: Scalars['String'] - /** One of the option values is required to be selected for the checkout. */ - isRequired: Scalars['Boolean'] -} - -/** Contact field */ -export type ContactField = { - __typename?: 'ContactField' - /** Store address line. */ - address: Scalars['String'] - /** Store country. */ - country: Scalars['String'] - /** Store address type. */ - addressType: Scalars['String'] - /** Store email. */ - email: Scalars['String'] - /** Store phone number. */ - phone: Scalars['String'] -} - -/** Custom field */ -export type CustomField = { - __typename?: 'CustomField' - /** Custom field id. */ - entityId: Scalars['Int'] - /** Name of the custom field. */ - name: Scalars['String'] - /** Value of the custom field. */ - value: Scalars['String'] -} - -/** A connection to a list of items. */ -export type CustomFieldConnection = { - __typename?: 'CustomFieldConnection' - /** Information to aid in pagination. */ - pageInfo: PageInfo - /** A list of edges. */ - edges?: Maybe>> -} - -/** An edge in a connection. */ -export type CustomFieldEdge = { - __typename?: 'CustomFieldEdge' - /** The item at the end of the edge. */ - node: CustomField - /** A cursor for use in pagination. */ - cursor: Scalars['String'] -} - -/** A customer that shops on a store */ -export type Customer = { - __typename?: 'Customer' - /** The ID of the customer. */ - entityId: Scalars['Int'] - /** The company name of the customer. */ - company: Scalars['String'] - /** The customer group id of the customer. */ - customerGroupId: Scalars['Int'] - /** The email address of the customer. */ - email: Scalars['String'] - /** The first name of the customer. */ - firstName: Scalars['String'] - /** The last name of the customer. */ - lastName: Scalars['String'] - /** The notes of the customer. */ - notes: Scalars['String'] - /** The phone number of the customer. */ - phone: Scalars['String'] - /** The tax exempt category of the customer. */ - taxExemptCategory: Scalars['String'] - /** Customer addresses count. */ - addressCount: Scalars['Int'] - /** Customer attributes count. */ - attributeCount: Scalars['Int'] - /** Customer store credit. */ - storeCredit: Array - /** Customer attributes. */ - attributes: CustomerAttributes -} - -/** A custom, store-specific attribute for a customer */ -export type CustomerAttribute = { - __typename?: 'CustomerAttribute' - /** The ID of the custom customer attribute */ - entityId: Scalars['Int'] - /** The value of the custom customer attribute */ - value?: Maybe - /** The name of the custom customer attribute */ - name: Scalars['String'] -} - -/** Custom, store-specific customer attributes */ -export type CustomerAttributes = { - __typename?: 'CustomerAttributes' - attribute: CustomerAttribute -} - -/** Custom, store-specific customer attributes */ -export type CustomerAttributesAttributeArgs = { - entityId: Scalars['Int'] -} - -/** A calendar for allowing selection of a date. */ -export type DateFieldOption = CatalogProductOption & { - __typename?: 'DateFieldOption' - /** Unique ID for the option. */ - entityId: Scalars['Int'] - /** Display name for the option. */ - displayName: Scalars['String'] - /** One of the option values is required to be selected for the checkout. */ - isRequired: Scalars['Boolean'] -} - -/** Date Time Extended */ -export type DateTimeExtended = { - __typename?: 'DateTimeExtended' - /** ISO-8601 formatted date in UTC */ - utc: Scalars['DateTime'] -} - -/** Display field */ -export type DisplayField = { - __typename?: 'DisplayField' - /** Short date format. */ - shortDateFormat: Scalars['String'] - /** Extended date format. */ - extendedDateFormat: Scalars['String'] -} - -/** A form allowing selection and uploading of a file from the user's local computer. */ -export type FileUploadFieldOption = CatalogProductOption & { - __typename?: 'FileUploadFieldOption' - /** Unique ID for the option. */ - entityId: Scalars['Int'] - /** Display name for the option. */ - displayName: Scalars['String'] - /** One of the option values is required to be selected for the checkout. */ - isRequired: Scalars['Boolean'] -} - -/** Image */ -export type Image = { - __typename?: 'Image' - /** Absolute path to image using store CDN. */ - url: Scalars['String'] - /** Absolute path to original image using store CDN. */ - urlOriginal: Scalars['String'] - /** Text description of an image that can be used for SEO and/or accessibility purposes. */ - altText: Scalars['String'] - /** Indicates whether this is the primary image. */ - isDefault: Scalars['Boolean'] -} - -/** Image */ -export type ImageUrlArgs = { - width: Scalars['Int'] - height?: Maybe -} - -/** A connection to a list of items. */ -export type ImageConnection = { - __typename?: 'ImageConnection' - /** Information to aid in pagination. */ - pageInfo: PageInfo - /** A list of edges. */ - edges?: Maybe>> -} - -/** An edge in a connection. */ -export type ImageEdge = { - __typename?: 'ImageEdge' - /** The item at the end of the edge. */ - node: Image - /** A cursor for use in pagination. */ - cursor: Scalars['String'] -} - -/** An inventory */ -export type Inventory = { - __typename?: 'Inventory' - /** Locations */ - locations: LocationConnection -} - -/** An inventory */ -export type InventoryLocationsArgs = { - entityIds?: Maybe> - codes?: Maybe> - typeIds?: Maybe> - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe -} - -/** Inventory By Locations */ -export type InventoryByLocations = { - __typename?: 'InventoryByLocations' - /** Location id. */ - locationEntityId: Scalars['Long'] - /** Number of available products in stock. */ - availableToSell: Scalars['Long'] - /** Indicates a threshold low-stock level. */ - warningLevel: Scalars['Int'] - /** Indicates whether this product is in stock. */ - isInStock: Scalars['Boolean'] -} - -/** A connection to a list of items. */ -export type LocationConnection = { - __typename?: 'LocationConnection' - /** Information to aid in pagination. */ - pageInfo: PageInfo - /** A list of edges. */ - edges?: Maybe>> -} - -/** An edge in a connection. */ -export type LocationEdge = { - __typename?: 'LocationEdge' - /** The item at the end of the edge. */ - node: InventoryByLocations - /** A cursor for use in pagination. */ - cursor: Scalars['String'] -} - -/** Logo field */ -export type LogoField = { - __typename?: 'LogoField' - /** Logo title. */ - title: Scalars['String'] - /** Store logo image. */ - image: Image -} - -/** Measurement */ -export type Measurement = { - __typename?: 'Measurement' - /** Unformatted weight measurement value. */ - value: Scalars['Float'] - /** Unit of measurement. */ - unit: Scalars['String'] -} - -/** A connection to a list of items. */ -export type MetafieldConnection = { - __typename?: 'MetafieldConnection' - /** Information to aid in pagination. */ - pageInfo: PageInfo - /** A list of edges. */ - edges?: Maybe>> -} - -/** An edge in a connection. */ -export type MetafieldEdge = { - __typename?: 'MetafieldEdge' - /** The item at the end of the edge. */ - node: Metafields - /** A cursor for use in pagination. */ - cursor: Scalars['String'] -} - -/** Key/Value pairs of data attached tied to a resource entity (product, brand, category, etc.) */ -export type Metafields = { - __typename?: 'Metafields' - /** The ID of an object */ - id: Scalars['ID'] - /** The ID of the metafield when referencing via our backend API. */ - entityId: Scalars['Int'] - /** A label for identifying a metafield data value. */ - key: Scalars['String'] - /** A metafield value. */ - value: Scalars['String'] -} - -/** A money object - includes currency code and a money amount */ -export type Money = { - __typename?: 'Money' - /** Currency code of the current money. */ - currencyCode: Scalars['String'] - /** The amount of money. */ - value: Scalars['BigDecimal'] -} - -/** A min and max pair of money objects */ -export type MoneyRange = { - __typename?: 'MoneyRange' - /** Minimum money object. */ - min: Money - /** Maximum money object. */ - max: Money -} - -/** A multi-line text input field, aka a text box. */ -export type MultiLineTextFieldOption = CatalogProductOption & { - __typename?: 'MultiLineTextFieldOption' - /** Unique ID for the option. */ - entityId: Scalars['Int'] - /** Display name for the option. */ - displayName: Scalars['String'] - /** One of the option values is required to be selected for the checkout. */ - isRequired: Scalars['Boolean'] -} - -/** An option type that has a fixed list of values. */ -export type MultipleChoiceOption = CatalogProductOption & { - __typename?: 'MultipleChoiceOption' - /** The chosen display style for this multiple choice option. */ - displayStyle: Scalars['String'] - /** List of option values. */ - values: ProductOptionValueConnection - /** Unique ID for the option. */ - entityId: Scalars['Int'] - /** Display name for the option. */ - displayName: Scalars['String'] - /** One of the option values is required to be selected for the checkout. */ - isRequired: Scalars['Boolean'] -} - -/** An option type that has a fixed list of values. */ -export type MultipleChoiceOptionValuesArgs = { - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe -} - -/** A simple multiple choice value comprised of an id and a label. */ -export type MultipleChoiceOptionValue = CatalogProductOptionValue & { - __typename?: 'MultipleChoiceOptionValue' - /** Unique ID for the option value. */ - entityId: Scalars['Int'] - /** Label for the option value. */ - label: Scalars['String'] - /** Indicates whether this value is the chosen default selected value. */ - isDefault: Scalars['Boolean'] -} - -/** An object with an ID */ -export type Node = { - /** The id of the object. */ - id: Scalars['ID'] -} - -/** A single line text input field that only accepts numbers. */ -export type NumberFieldOption = CatalogProductOption & { - __typename?: 'NumberFieldOption' - /** Unique ID for the option. */ - entityId: Scalars['Int'] - /** Display name for the option. */ - displayName: Scalars['String'] - /** One of the option values is required to be selected for the checkout. */ - isRequired: Scalars['Boolean'] -} - -/** A connection to a list of items. */ -export type OptionConnection = { - __typename?: 'OptionConnection' - /** Information to aid in pagination. */ - pageInfo: PageInfo - /** A list of edges. */ - edges?: Maybe>> -} - -/** An edge in a connection. */ -export type OptionEdge = { - __typename?: 'OptionEdge' - /** The item at the end of the edge. */ - node: ProductOption - /** A cursor for use in pagination. */ - cursor: Scalars['String'] -} - -/** A connection to a list of items. */ -export type OptionValueConnection = { - __typename?: 'OptionValueConnection' - /** Information to aid in pagination. */ - pageInfo: PageInfo - /** A list of edges. */ - edges?: Maybe>> -} - -/** An edge in a connection. */ -export type OptionValueEdge = { - __typename?: 'OptionValueEdge' - /** The item at the end of the edge. */ - node: ProductOptionValue - /** A cursor for use in pagination. */ - cursor: Scalars['String'] -} - -export type OptionValueId = { - optionEntityId: Scalars['Int'] - valueEntityId: Scalars['Int'] -} - -/** Information about pagination in a connection. */ -export type PageInfo = { - __typename?: 'PageInfo' - /** When paginating forwards, are there more items? */ - hasNextPage: Scalars['Boolean'] - /** When paginating backwards, are there more items? */ - hasPreviousPage: Scalars['Boolean'] - /** When paginating backwards, the cursor to continue. */ - startCursor?: Maybe - /** When paginating forwards, the cursor to continue. */ - endCursor?: Maybe -} - -/** The min and max range of prices that apply to this product. */ -export type PriceRanges = { - __typename?: 'PriceRanges' - /** Product price min/max range. */ - priceRange: MoneyRange - /** Product retail price min/max range. */ - retailPriceRange?: Maybe -} - -/** The various prices that can be set on a product. */ -export type Prices = { - __typename?: 'Prices' - /** Calculated price of the product. */ - price: Money - /** Sale price of the product. */ - salePrice?: Maybe - /** Original price of the product. */ - basePrice?: Maybe - /** Retail price of the product. */ - retailPrice?: Maybe - /** Minimum advertised price of the product. */ - mapPrice?: Maybe - /** Product price min/max range. */ - priceRange: MoneyRange - /** Product retail price min/max range. */ - retailPriceRange?: Maybe - /** The difference between the retail price (MSRP) and the current price, which can be presented to the shopper as their savings. */ - saved?: Maybe - /** List of bulk pricing tiers applicable to a product or variant. */ - bulkPricing: Array -} - -/** Product */ -export type Product = Node & { - __typename?: 'Product' - /** The ID of an object */ - id: Scalars['ID'] - /** Id of the product. */ - entityId: Scalars['Int'] - /** Default product variant when no options are selected. */ - sku: Scalars['String'] - /** Relative URL path to product page. */ - path: Scalars['String'] - /** Name of the product. */ - name: Scalars['String'] - /** Description of the product. */ - description: Scalars['String'] - /** Description of the product in plain text. */ - plainTextDescription: Scalars['String'] - /** Warranty information of the product. */ - warranty: Scalars['String'] - /** Minimum purchasable quantity for this product in a single order. */ - minPurchaseQuantity?: Maybe - /** Maximum purchasable quantity for this product in a single order. */ - maxPurchaseQuantity?: Maybe - /** Absolute URL path for adding a product to cart. */ - addToCartUrl: Scalars['String'] - /** Absolute URL path for adding a product to customer's wishlist. */ - addToWishlistUrl: Scalars['String'] - /** Prices object determined by supplied product ID, variant ID, and selected option IDs. */ - prices?: Maybe - /** - * The minimum and maximum price of this product based on variant pricing and/or modifier price rules. - * @deprecated Use priceRanges inside prices node instead. - */ - priceRanges?: Maybe - /** Weight of the product. */ - weight?: Maybe - /** Height of the product. */ - height?: Maybe - /** Width of the product. */ - width?: Maybe - /** Depth of the product. */ - depth?: Maybe - /** Product options. */ - options: OptionConnection - /** Product options. */ - productOptions: ProductOptionConnection - /** Summary of the product reviews, includes the total number of reviews submitted and summation of the ratings on the reviews (ratings range from 0-5 per review). */ - reviewSummary: Reviews - /** Type of product, ex: physical, digital */ - type: Scalars['String'] - /** - * The availability state of the product. - * @deprecated Use status inside availabilityV2 instead. - */ - availability: Scalars['String'] - /** - * A few words telling the customer how long it will normally take to ship this product, such as 'Usually ships in 24 hours'. - * @deprecated Use description inside availabilityV2 instead. - */ - availabilityDescription: Scalars['String'] - /** The availability state of the product. */ - availabilityV2: ProductAvailability - /** List of categories associated with the product. */ - categories: CategoryConnection - /** Brand associated with the product. */ - brand?: Maybe - /** Variants associated with the product. */ - variants: VariantConnection - /** Custom fields of the product. */ - customFields: CustomFieldConnection - /** A list of the images for a product. */ - images: ImageConnection - /** Default image for a product. */ - defaultImage?: Maybe - /** Related products for this product. */ - relatedProducts: RelatedProductsConnection - /** Inventory information of the product. */ - inventory: ProductInventory - /** Metafield data related to a product. */ - metafields: MetafieldConnection - /** - * Product creation date - * @deprecated Alpha version. Do not use in production. - */ - createdAt: DateTimeExtended -} - -/** Product */ -export type ProductPlainTextDescriptionArgs = { - characterLimit?: Maybe -} - -/** Product */ -export type ProductPricesArgs = { - includeTax?: Maybe - currencyCode?: Maybe -} - -/** Product */ -export type ProductPriceRangesArgs = { - includeTax?: Maybe -} - -/** Product */ -export type ProductOptionsArgs = { - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe -} - -/** Product */ -export type ProductProductOptionsArgs = { - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe -} - -/** Product */ -export type ProductCategoriesArgs = { - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe -} - -/** Product */ -export type ProductVariantsArgs = { - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe - entityIds?: Maybe> - optionValueIds?: Maybe> -} - -/** Product */ -export type ProductCustomFieldsArgs = { - names?: Maybe> - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe -} - -/** Product */ -export type ProductImagesArgs = { - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe -} - -/** Product */ -export type ProductRelatedProductsArgs = { - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe -} - -/** Product */ -export type ProductMetafieldsArgs = { - namespace: Scalars['String'] - keys?: Maybe> - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe -} - -/** Product availability */ -export type ProductAvailability = { - /** The availability state of the product. */ - status: ProductAvailabilityStatus - /** A few words telling the customer how long it will normally take to ship this product, such as 'Usually ships in 24 hours'. */ - description: Scalars['String'] -} - -/** Product availability status */ -export enum ProductAvailabilityStatus { - Available = 'Available', - Preorder = 'Preorder', - Unavailable = 'Unavailable', -} - -/** Available Product */ -export type ProductAvailable = ProductAvailability & { - __typename?: 'ProductAvailable' - /** The availability state of the product. */ - status: ProductAvailabilityStatus - /** A few words telling the customer how long it will normally take to ship this product, such as 'Usually ships in 24 hours'. */ - description: Scalars['String'] -} - -/** A connection to a list of items. */ -export type ProductConnection = { - __typename?: 'ProductConnection' - /** Information to aid in pagination. */ - pageInfo: PageInfo - /** A list of edges. */ - edges?: Maybe>> -} - -/** An edge in a connection. */ -export type ProductEdge = { - __typename?: 'ProductEdge' - /** The item at the end of the edge. */ - node: Product - /** A cursor for use in pagination. */ - cursor: Scalars['String'] -} - -/** Product Inventory Information */ -export type ProductInventory = { - __typename?: 'ProductInventory' - /** Indicates whether this product is in stock. */ - isInStock: Scalars['Boolean'] - /** Indicates whether this product's inventory is being tracked on variant level. If true, you may wish to check the variants node to understand the true inventory of each individual variant, rather than relying on this product-level aggregate to understand how many items may be added to cart. */ - hasVariantInventory: Scalars['Boolean'] - /** Aggregated product inventory information. This data may not be available if not set or if the store's Inventory Settings have disabled displaying stock levels on the storefront. */ - aggregated?: Maybe -} - -/** Product Option */ -export type ProductOption = { - __typename?: 'ProductOption' - /** Unique ID for the option. */ - entityId: Scalars['Int'] - /** Display name for the option. */ - displayName: Scalars['String'] - /** One of the option values is required to be selected for the checkout. */ - isRequired: Scalars['Boolean'] - /** Option values. */ - values: OptionValueConnection -} - -/** Product Option */ -export type ProductOptionValuesArgs = { - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe -} - -/** A connection to a list of items. */ -export type ProductOptionConnection = { - __typename?: 'ProductOptionConnection' - /** Information to aid in pagination. */ - pageInfo: PageInfo - /** A list of edges. */ - edges?: Maybe>> -} - -/** An edge in a connection. */ -export type ProductOptionEdge = { - __typename?: 'ProductOptionEdge' - /** The item at the end of the edge. */ - node: CatalogProductOption - /** A cursor for use in pagination. */ - cursor: Scalars['String'] -} - -/** Product Option Value */ -export type ProductOptionValue = { - __typename?: 'ProductOptionValue' - /** Unique ID for the option value. */ - entityId: Scalars['Int'] - /** Label for the option value. */ - label: Scalars['String'] -} - -/** A connection to a list of items. */ -export type ProductOptionValueConnection = { - __typename?: 'ProductOptionValueConnection' - /** Information to aid in pagination. */ - pageInfo: PageInfo - /** A list of edges. */ - edges?: Maybe>> -} - -/** An edge in a connection. */ -export type ProductOptionValueEdge = { - __typename?: 'ProductOptionValueEdge' - /** The item at the end of the edge. */ - node: CatalogProductOptionValue - /** A cursor for use in pagination. */ - cursor: Scalars['String'] -} - -/** A Product PickList Value - a product to be mapped to the base product if selected. */ -export type ProductPickListOptionValue = CatalogProductOptionValue & { - __typename?: 'ProductPickListOptionValue' - /** The ID of the product associated with this option value. */ - productId: Scalars['Int'] - /** Unique ID for the option value. */ - entityId: Scalars['Int'] - /** Label for the option value. */ - label: Scalars['String'] - /** Indicates whether this value is the chosen default selected value. */ - isDefault: Scalars['Boolean'] -} - -/** PreOrder Product */ -export type ProductPreOrder = ProductAvailability & { - __typename?: 'ProductPreOrder' - /** The message to be shown in the store when a product is put into the pre-order availability state, e.g. "Expected release date is %%DATE%%" */ - message?: Maybe - /** Product release date */ - willBeReleasedAt?: Maybe - /** The availability state of the product. */ - status: ProductAvailabilityStatus - /** A few words telling the customer how long it will normally take to ship this product, such as 'Usually ships in 24 hours'. */ - description: Scalars['String'] -} - -/** Unavailable Product */ -export type ProductUnavailable = ProductAvailability & { - __typename?: 'ProductUnavailable' - /** The message to be shown in the store when "Call for pricing" is enabled for this product, e.g. "Contact us at 555-5555" */ - message?: Maybe - /** The availability state of the product. */ - status: ProductAvailabilityStatus - /** A few words telling the customer how long it will normally take to ship this product, such as 'Usually ships in 24 hours'. */ - description: Scalars['String'] -} - -export type Query = { - __typename?: 'Query' - site: Site - /** The currently logged in customer. */ - customer?: Maybe - /** Fetches an object given its ID */ - node?: Maybe - /** @deprecated Alpha version. Do not use in production. */ - inventory: Inventory -} - -export type QueryNodeArgs = { - id: Scalars['ID'] -} - -/** A connection to a list of items. */ -export type RelatedProductsConnection = { - __typename?: 'RelatedProductsConnection' - /** Information to aid in pagination. */ - pageInfo: PageInfo - /** A list of edges. */ - edges?: Maybe>> -} - -/** An edge in a connection. */ -export type RelatedProductsEdge = { - __typename?: 'RelatedProductsEdge' - /** The item at the end of the edge. */ - node: Product - /** A cursor for use in pagination. */ - cursor: Scalars['String'] -} - -/** Review Rating Summary */ -export type Reviews = { - __typename?: 'Reviews' - /** Total number of reviews on product. */ - numberOfReviews: Scalars['Int'] - /** Summation of rating scores from each review. */ - summationOfRatings: Scalars['Int'] -} - -/** route */ -export type Route = { - __typename?: 'Route' - /** node */ - node?: Maybe -} - -/** Store settings information from the control panel. */ -export type Settings = { - __typename?: 'Settings' - /** The name of the store. */ - storeName: Scalars['String'] - /** The hash of the store. */ - storeHash: Scalars['String'] - /** The current store status. */ - status: StorefrontStatusType - /** Logo information for the store. */ - logo: LogoField - /** Contact information for the store. */ - contact?: Maybe - /** Store urls. */ - url: UrlField - /** Store display format information. */ - display: DisplayField - /** Channel ID. */ - channelId: Scalars['Long'] -} - -/** A site */ -export type Site = { - __typename?: 'Site' - categoryTree: Array - /** Details of the brand. */ - brands: BrandConnection - /** Details of the products. */ - products: ProductConnection - /** Details of the newest products. */ - newestProducts: ProductConnection - /** Details of the best selling products. */ - bestSellingProducts: ProductConnection - /** Details of the featured products. */ - featuredProducts: ProductConnection - /** A single product object with variant pricing overlay capabilities. */ - product?: Maybe - /** Route for a node */ - route: Route - /** Store settings. */ - settings?: Maybe -} - -/** A site */ -export type SiteBrandsArgs = { - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe - productEntityIds?: Maybe> -} - -/** A site */ -export type SiteProductsArgs = { - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe - ids?: Maybe> - entityIds?: Maybe> -} - -/** A site */ -export type SiteNewestProductsArgs = { - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe -} - -/** A site */ -export type SiteBestSellingProductsArgs = { - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe -} - -/** A site */ -export type SiteFeaturedProductsArgs = { - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe -} - -/** A site */ -export type SiteProductArgs = { - id?: Maybe - entityId?: Maybe - variantEntityId?: Maybe - optionValueIds?: Maybe> - sku?: Maybe -} - -/** A site */ -export type SiteRouteArgs = { - path: Scalars['String'] -} - -/** Storefront Mode */ -export enum StorefrontStatusType { - Launched = 'LAUNCHED', - Maintenance = 'MAINTENANCE', - PreLaunch = 'PRE_LAUNCH', - Hibernation = 'HIBERNATION', -} - -/** A swatch option value - swatch values can be associated with a list of hexidecimal colors or an image. */ -export type SwatchOptionValue = CatalogProductOptionValue & { - __typename?: 'SwatchOptionValue' - /** List of up to 3 hex encoded colors to associate with a swatch value. */ - hexColors: Array - /** Absolute path of a swatch texture image. */ - imageUrl?: Maybe - /** Unique ID for the option value. */ - entityId: Scalars['Int'] - /** Label for the option value. */ - label: Scalars['String'] - /** Indicates whether this value is the chosen default selected value. */ - isDefault: Scalars['Boolean'] -} - -/** A swatch option value - swatch values can be associated with a list of hexidecimal colors or an image. */ -export type SwatchOptionValueImageUrlArgs = { - width: Scalars['Int'] - height?: Maybe -} - -/** A single line text input field. */ -export type TextFieldOption = CatalogProductOption & { - __typename?: 'TextFieldOption' - /** Unique ID for the option. */ - entityId: Scalars['Int'] - /** Display name for the option. */ - displayName: Scalars['String'] - /** One of the option values is required to be selected for the checkout. */ - isRequired: Scalars['Boolean'] -} - -/** Url field */ -export type UrlField = { - __typename?: 'UrlField' - /** Store url. */ - vanityUrl: Scalars['String'] - /** CDN url to fetch assets. */ - cdnUrl: Scalars['String'] -} - -/** Variant */ -export type Variant = Node & { - __typename?: 'Variant' - /** The ID of an object */ - id: Scalars['ID'] - /** Id of the variant. */ - entityId: Scalars['Int'] - /** Sku of the variant. */ - sku: Scalars['String'] - /** The variant's weight. If a weight was not explicitly specified on the variant, this will be the product's weight. */ - weight?: Maybe - /** The variant's height. If a height was not explicitly specified on the variant, this will be the product's height. */ - height?: Maybe - /** The variant's width. If a width was not explicitly specified on the variant, this will be the product's width. */ - width?: Maybe - /** The variant's depth. If a depth was not explicitly specified on the variant, this will be the product's depth. */ - depth?: Maybe - /** The options which define a variant. */ - options: OptionConnection - /** Product options that compose this variant. */ - productOptions: ProductOptionConnection - /** Default image for a variant. */ - defaultImage?: Maybe - /** Variant prices */ - prices?: Maybe - /** Variant inventory */ - inventory?: Maybe - /** Metafield data related to a variant. */ - metafields: MetafieldConnection -} - -/** Variant */ -export type VariantOptionsArgs = { - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe -} - -/** Variant */ -export type VariantProductOptionsArgs = { - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe -} - -/** Variant */ -export type VariantPricesArgs = { - includeTax?: Maybe - currencyCode?: Maybe -} - -/** Variant */ -export type VariantMetafieldsArgs = { - namespace: Scalars['String'] - keys?: Maybe> - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe -} - -/** A connection to a list of items. */ -export type VariantConnection = { - __typename?: 'VariantConnection' - /** Information to aid in pagination. */ - pageInfo: PageInfo - /** A list of edges. */ - edges?: Maybe>> -} - -/** An edge in a connection. */ -export type VariantEdge = { - __typename?: 'VariantEdge' - /** The item at the end of the edge. */ - node: Variant - /** A cursor for use in pagination. */ - cursor: Scalars['String'] -} - -/** Variant Inventory */ -export type VariantInventory = { - __typename?: 'VariantInventory' - /** Aggregated product variant inventory information. This data may not be available if not set or if the store's Inventory Settings have disabled displaying stock levels on the storefront. */ - aggregated?: Maybe - /** Indicates whether this product is in stock. */ - isInStock: Scalars['Boolean'] - /** Inventory by locations. */ - byLocation?: Maybe -} - -/** Variant Inventory */ -export type VariantInventoryByLocationArgs = { - locationEntityIds?: Maybe> - before?: Maybe - after?: Maybe - first?: Maybe - last?: Maybe -} - -/** Please select a currency */ -export enum CurrencyCode { - Adp = 'ADP', - Aed = 'AED', - Afa = 'AFA', - Afn = 'AFN', - Alk = 'ALK', - All = 'ALL', - Amd = 'AMD', - Ang = 'ANG', - Aoa = 'AOA', - Aok = 'AOK', - Aon = 'AON', - Aor = 'AOR', - Ara = 'ARA', - Arl = 'ARL', - Arm = 'ARM', - Arp = 'ARP', - Ars = 'ARS', - Ats = 'ATS', - Aud = 'AUD', - Awg = 'AWG', - Azm = 'AZM', - Azn = 'AZN', - Bad = 'BAD', - Bam = 'BAM', - Ban = 'BAN', - Bbd = 'BBD', - Bdt = 'BDT', - Bec = 'BEC', - Bef = 'BEF', - Bel = 'BEL', - Bgl = 'BGL', - Bgm = 'BGM', - Bgn = 'BGN', - Bgo = 'BGO', - Bhd = 'BHD', - Bif = 'BIF', - Bmd = 'BMD', - Bnd = 'BND', - Bob = 'BOB', - Bol = 'BOL', - Bop = 'BOP', - Bov = 'BOV', - Brb = 'BRB', - Brc = 'BRC', - Bre = 'BRE', - Brl = 'BRL', - Brn = 'BRN', - Brr = 'BRR', - Brz = 'BRZ', - Bsd = 'BSD', - Btn = 'BTN', - Buk = 'BUK', - Bwp = 'BWP', - Byb = 'BYB', - Byr = 'BYR', - Bzd = 'BZD', - Cad = 'CAD', - Cdf = 'CDF', - Che = 'CHE', - Chf = 'CHF', - Chw = 'CHW', - Cle = 'CLE', - Clf = 'CLF', - Clp = 'CLP', - Cnx = 'CNX', - Cny = 'CNY', - Cop = 'COP', - Cou = 'COU', - Crc = 'CRC', - Csd = 'CSD', - Csk = 'CSK', - Cve = 'CVE', - Cyp = 'CYP', - Czk = 'CZK', - Ddm = 'DDM', - Dem = 'DEM', - Djf = 'DJF', - Dkk = 'DKK', - Dop = 'DOP', - Dzd = 'DZD', - Ecs = 'ECS', - Ecv = 'ECV', - Eek = 'EEK', - Egp = 'EGP', - Ern = 'ERN', - Esa = 'ESA', - Esb = 'ESB', - Esp = 'ESP', - Etb = 'ETB', - Eur = 'EUR', - Fim = 'FIM', - Fjd = 'FJD', - Fkp = 'FKP', - Frf = 'FRF', - Gbp = 'GBP', - Gek = 'GEK', - Gel = 'GEL', - Ghc = 'GHC', - Ghs = 'GHS', - Gip = 'GIP', - Gmd = 'GMD', - Gnf = 'GNF', - Gns = 'GNS', - Gqe = 'GQE', - Grd = 'GRD', - Gtq = 'GTQ', - Gwe = 'GWE', - Gwp = 'GWP', - Gyd = 'GYD', - Hkd = 'HKD', - Hnl = 'HNL', - Hrd = 'HRD', - Hrk = 'HRK', - Htg = 'HTG', - Huf = 'HUF', - Idr = 'IDR', - Iep = 'IEP', - Ilp = 'ILP', - Ilr = 'ILR', - Ils = 'ILS', - Inr = 'INR', - Iqd = 'IQD', - Isj = 'ISJ', - Isk = 'ISK', - Itl = 'ITL', - Jmd = 'JMD', - Jod = 'JOD', - Jpy = 'JPY', - Kes = 'KES', - Kgs = 'KGS', - Khr = 'KHR', - Kmf = 'KMF', - Krh = 'KRH', - Kro = 'KRO', - Krw = 'KRW', - Kwd = 'KWD', - Kyd = 'KYD', - Kzt = 'KZT', - Lak = 'LAK', - Lbp = 'LBP', - Lkr = 'LKR', - Lrd = 'LRD', - Lsl = 'LSL', - Ltl = 'LTL', - Ltt = 'LTT', - Luc = 'LUC', - Luf = 'LUF', - Lul = 'LUL', - Lvl = 'LVL', - Lvr = 'LVR', - Lyd = 'LYD', - Mad = 'MAD', - Maf = 'MAF', - Mcf = 'MCF', - Mdc = 'MDC', - Mdl = 'MDL', - Mga = 'MGA', - Mgf = 'MGF', - Mkd = 'MKD', - Mkn = 'MKN', - Mlf = 'MLF', - Mmk = 'MMK', - Mnt = 'MNT', - Mop = 'MOP', - Mro = 'MRO', - Mtl = 'MTL', - Mtp = 'MTP', - Mur = 'MUR', - Mvp = 'MVP', - Mvr = 'MVR', - Mwk = 'MWK', - Mxn = 'MXN', - Mxp = 'MXP', - Mxv = 'MXV', - Myr = 'MYR', - Mze = 'MZE', - Mzm = 'MZM', - Mzn = 'MZN', - Nad = 'NAD', - Ngn = 'NGN', - Nic = 'NIC', - Nio = 'NIO', - Nlg = 'NLG', - Nok = 'NOK', - Npr = 'NPR', - Nzd = 'NZD', - Omr = 'OMR', - Pab = 'PAB', - Pei = 'PEI', - Pen = 'PEN', - Pes = 'PES', - Pgk = 'PGK', - Php = 'PHP', - Pkr = 'PKR', - Pln = 'PLN', - Plz = 'PLZ', - Pte = 'PTE', - Pyg = 'PYG', - Qar = 'QAR', - Rhd = 'RHD', - Rol = 'ROL', - Ron = 'RON', - Rsd = 'RSD', - Rub = 'RUB', - Rur = 'RUR', - Rwf = 'RWF', - Sar = 'SAR', - Sbd = 'SBD', - Scr = 'SCR', - Sdd = 'SDD', - Sdg = 'SDG', - Sdp = 'SDP', - Sek = 'SEK', - Sgd = 'SGD', - Shp = 'SHP', - Sit = 'SIT', - Skk = 'SKK', - Sll = 'SLL', - Sos = 'SOS', - Srd = 'SRD', - Srg = 'SRG', - Ssp = 'SSP', - Std = 'STD', - Sur = 'SUR', - Svc = 'SVC', - Syp = 'SYP', - Szl = 'SZL', - Thb = 'THB', - Tjr = 'TJR', - Tjs = 'TJS', - Tmm = 'TMM', - Tmt = 'TMT', - Tnd = 'TND', - Top = 'TOP', - Tpe = 'TPE', - Trl = 'TRL', - Try = 'TRY', - Ttd = 'TTD', - Twd = 'TWD', - Tzs = 'TZS', - Uah = 'UAH', - Uak = 'UAK', - Ugs = 'UGS', - Ugx = 'UGX', - Usd = 'USD', - Usn = 'USN', - Uss = 'USS', - Uyi = 'UYI', - Uyp = 'UYP', - Uyu = 'UYU', - Uzs = 'UZS', - Veb = 'VEB', - Vef = 'VEF', - Vnd = 'VND', - Vnn = 'VNN', - Vuv = 'VUV', - Wst = 'WST', - Xaf = 'XAF', - Xcd = 'XCD', - Xeu = 'XEU', - Xfo = 'XFO', - Xfu = 'XFU', - Xof = 'XOF', - Xpf = 'XPF', - Xre = 'XRE', - Ydd = 'YDD', - Yer = 'YER', - Yud = 'YUD', - Yum = 'YUM', - Yun = 'YUN', - Yur = 'YUR', - Zal = 'ZAL', - Zar = 'ZAR', - Zmk = 'ZMK', - Zmw = 'ZMW', - Zrn = 'ZRN', - Zrz = 'ZRZ', - Zwd = 'ZWD', - Zwl = 'ZWL', - Zwr = 'ZWR', -} - -export type GetLoggedInCustomerQueryVariables = Exact<{ [key: string]: never }> - -export type GetLoggedInCustomerQuery = { __typename?: 'Query' } & { - customer?: Maybe< - { __typename?: 'Customer' } & Pick< - Customer, - | 'entityId' - | 'firstName' - | 'lastName' - | 'email' - | 'company' - | 'customerGroupId' - | 'notes' - | 'phone' - | 'addressCount' - | 'attributeCount' - > & { - storeCredit: Array< - { __typename?: 'Money' } & Pick - > - } - > -} - -export type CategoryTreeItemFragment = { - __typename?: 'CategoryTreeItem' -} & Pick< - CategoryTreeItem, - 'entityId' | 'name' | 'path' | 'description' | 'productCount' -> - -export type ProductPricesFragment = { __typename?: 'Prices' } & { - price: { __typename?: 'Money' } & Pick - salePrice?: Maybe< - { __typename?: 'Money' } & Pick - > - retailPrice?: Maybe< - { __typename?: 'Money' } & Pick - > -} - -export type SwatchOptionFragment = { __typename?: 'SwatchOptionValue' } & Pick< - SwatchOptionValue, - 'isDefault' | 'hexColors' -> - -export type MultipleChoiceOptionFragment = { - __typename?: 'MultipleChoiceOption' -} & { - values: { __typename?: 'ProductOptionValueConnection' } & { - edges?: Maybe< - Array< - Maybe< - { __typename?: 'ProductOptionValueEdge' } & { - node: - | ({ __typename?: 'MultipleChoiceOptionValue' } & Pick< - MultipleChoiceOptionValue, - 'label' - >) - | ({ __typename?: 'ProductPickListOptionValue' } & Pick< - ProductPickListOptionValue, - 'label' - >) - | ({ __typename?: 'SwatchOptionValue' } & Pick< - SwatchOptionValue, - 'label' - > & - SwatchOptionFragment) - } - > - > - > - } -} - -export type ProductInfoFragment = { __typename?: 'Product' } & Pick< - Product, - 'entityId' | 'name' | 'path' | 'description' -> & { - brand?: Maybe<{ __typename?: 'Brand' } & Pick> - prices?: Maybe<{ __typename?: 'Prices' } & ProductPricesFragment> - images: { __typename?: 'ImageConnection' } & { - edges?: Maybe< - Array< - Maybe< - { __typename?: 'ImageEdge' } & { - node: { __typename?: 'Image' } & Pick< - Image, - 'urlOriginal' | 'altText' | 'isDefault' - > - } - > - > - > - } - variants: { __typename?: 'VariantConnection' } & { - edges?: Maybe< - Array< - Maybe< - { __typename?: 'VariantEdge' } & { - node: { __typename?: 'Variant' } & Pick & { - defaultImage?: Maybe< - { __typename?: 'Image' } & Pick< - Image, - 'urlOriginal' | 'altText' | 'isDefault' - > - > - } - } - > - > - > - } - productOptions: { __typename?: 'ProductOptionConnection' } & { - edges?: Maybe< - Array< - Maybe< - { __typename?: 'ProductOptionEdge' } & { - node: - | ({ __typename: 'CheckboxOption' } & Pick< - CheckboxOption, - 'entityId' | 'displayName' - >) - | ({ __typename: 'DateFieldOption' } & Pick< - DateFieldOption, - 'entityId' | 'displayName' - >) - | ({ __typename: 'FileUploadFieldOption' } & Pick< - FileUploadFieldOption, - 'entityId' | 'displayName' - >) - | ({ __typename: 'MultiLineTextFieldOption' } & Pick< - MultiLineTextFieldOption, - 'entityId' | 'displayName' - >) - | ({ __typename: 'MultipleChoiceOption' } & Pick< - MultipleChoiceOption, - 'entityId' | 'displayName' - > & - MultipleChoiceOptionFragment) - | ({ __typename: 'NumberFieldOption' } & Pick< - NumberFieldOption, - 'entityId' | 'displayName' - >) - | ({ __typename: 'TextFieldOption' } & Pick< - TextFieldOption, - 'entityId' | 'displayName' - >) - } - > - > - > - } - localeMeta: { __typename?: 'MetafieldConnection' } & { - edges?: Maybe< - Array< - Maybe< - { __typename?: 'MetafieldEdge' } & { - node: { __typename?: 'Metafields' } & Pick< - Metafields, - 'key' | 'value' - > - } - > - > - > - } - } - -export type ProductConnnectionFragment = { - __typename?: 'ProductConnection' -} & { - pageInfo: { __typename?: 'PageInfo' } & Pick< - PageInfo, - 'startCursor' | 'endCursor' - > - edges?: Maybe< - Array< - Maybe< - { __typename?: 'ProductEdge' } & Pick & { - node: { __typename?: 'Product' } & ProductInfoFragment - } - > - > - > -} - -export type GetAllProductPathsQueryVariables = Exact<{ - first?: Maybe -}> - -export type GetAllProductPathsQuery = { __typename?: 'Query' } & { - site: { __typename?: 'Site' } & { - products: { __typename?: 'ProductConnection' } & { - edges?: Maybe< - Array< - Maybe< - { __typename?: 'ProductEdge' } & { - node: { __typename?: 'Product' } & Pick - } - > - > - > - } - } -} - -export type GetAllProductsQueryVariables = Exact<{ - hasLocale?: Maybe - locale?: Maybe - entityIds?: Maybe> - first?: Maybe - products?: Maybe - featuredProducts?: Maybe - bestSellingProducts?: Maybe - newestProducts?: Maybe -}> - -export type GetAllProductsQuery = { __typename?: 'Query' } & { - site: { __typename?: 'Site' } & { - products: { __typename?: 'ProductConnection' } & ProductConnnectionFragment - featuredProducts: { - __typename?: 'ProductConnection' - } & ProductConnnectionFragment - bestSellingProducts: { - __typename?: 'ProductConnection' - } & ProductConnnectionFragment - newestProducts: { - __typename?: 'ProductConnection' - } & ProductConnnectionFragment - } -} - -export type GetCustomerIdQueryVariables = Exact<{ [key: string]: never }> - -export type GetCustomerIdQuery = { __typename?: 'Query' } & { - customer?: Maybe<{ __typename?: 'Customer' } & Pick> -} - -export type GetProductQueryVariables = Exact<{ - hasLocale?: Maybe - locale?: Maybe - path: Scalars['String'] -}> - -export type GetProductQuery = { __typename?: 'Query' } & { - site: { __typename?: 'Site' } & { - route: { __typename?: 'Route' } & { - node?: Maybe< - | { __typename: 'Brand' } - | { __typename: 'Category' } - | ({ __typename: 'Product' } & { - variants: { __typename?: 'VariantConnection' } & { - edges?: Maybe< - Array< - Maybe< - { __typename?: 'VariantEdge' } & { - node: { __typename?: 'Variant' } & Pick< - Variant, - 'entityId' - > & { - defaultImage?: Maybe< - { __typename?: 'Image' } & Pick< - Image, - 'urlOriginal' | 'altText' | 'isDefault' - > - > - prices?: Maybe< - { __typename?: 'Prices' } & ProductPricesFragment - > - inventory?: Maybe< - { __typename?: 'VariantInventory' } & Pick< - VariantInventory, - 'isInStock' - > & { - aggregated?: Maybe< - { __typename?: 'Aggregated' } & Pick< - Aggregated, - 'availableToSell' | 'warningLevel' - > - > - } - > - productOptions: { - __typename?: 'ProductOptionConnection' - } & { - edges?: Maybe< - Array< - Maybe< - { __typename?: 'ProductOptionEdge' } & { - node: - | ({ - __typename: 'CheckboxOption' - } & Pick< - CheckboxOption, - 'entityId' | 'displayName' - >) - | ({ - __typename: 'DateFieldOption' - } & Pick< - DateFieldOption, - 'entityId' | 'displayName' - >) - | ({ - __typename: 'FileUploadFieldOption' - } & Pick< - FileUploadFieldOption, - 'entityId' | 'displayName' - >) - | ({ - __typename: 'MultiLineTextFieldOption' - } & Pick< - MultiLineTextFieldOption, - 'entityId' | 'displayName' - >) - | ({ - __typename: 'MultipleChoiceOption' - } & Pick< - MultipleChoiceOption, - 'entityId' | 'displayName' - > & - MultipleChoiceOptionFragment) - | ({ - __typename: 'NumberFieldOption' - } & Pick< - NumberFieldOption, - 'entityId' | 'displayName' - >) - | ({ - __typename: 'TextFieldOption' - } & Pick< - TextFieldOption, - 'entityId' | 'displayName' - >) - } - > - > - > - } - } - } - > - > - > - } - } & ProductInfoFragment) - | { __typename: 'Variant' } - > - } - } -} - -export type GetSiteInfoQueryVariables = Exact<{ [key: string]: never }> - -export type GetSiteInfoQuery = { __typename?: 'Query' } & { - site: { __typename?: 'Site' } & { - categoryTree: Array< - { __typename?: 'CategoryTreeItem' } & { - children: Array< - { __typename?: 'CategoryTreeItem' } & { - children: Array< - { __typename?: 'CategoryTreeItem' } & CategoryTreeItemFragment - > - } & CategoryTreeItemFragment - > - } & CategoryTreeItemFragment - > - brands: { __typename?: 'BrandConnection' } & { - pageInfo: { __typename?: 'PageInfo' } & Pick< - PageInfo, - 'startCursor' | 'endCursor' - > - edges?: Maybe< - Array< - Maybe< - { __typename?: 'BrandEdge' } & Pick & { - node: { __typename?: 'Brand' } & Pick< - Brand, - | 'entityId' - | 'name' - | 'pageTitle' - | 'metaDesc' - | 'metaKeywords' - | 'searchKeywords' - | 'path' - > & { - defaultImage?: Maybe< - { __typename?: 'Image' } & Pick< - Image, - 'urlOriginal' | 'altText' - > - > - } - } - > - > - > - } - } -} - -export type LoginMutationVariables = Exact<{ - email: Scalars['String'] - password: Scalars['String'] -}> - -export type LoginMutation = { __typename?: 'Mutation' } & { - login: { __typename?: 'LoginResult' } & Pick -} diff --git a/lib/bigcommerce/wishlist/use-add-item.tsx b/lib/bigcommerce/wishlist/use-add-item.tsx deleted file mode 100644 index 8815ca72d..000000000 --- a/lib/bigcommerce/wishlist/use-add-item.tsx +++ /dev/null @@ -1,57 +0,0 @@ -import { useCallback } from 'react' -import { HookFetcher } from '../../commerce/utils/types' -import { CommerceError } from '../../commerce/utils/errors' -import useWishlistAddItem from '../../commerce/wishlist/use-add-item' -import type { ItemBody, AddItemBody } from '../api/wishlist' -import useCustomer from '../use-customer' -import useWishlist, { UseWishlistOptions, Wishlist } from './use-wishlist' - -const defaultOpts = { - url: '/api/bigcommerce/wishlist', - method: 'POST', -} - -export type AddItemInput = ItemBody - -export const fetcher: HookFetcher = ( - options, - { item }, - fetch -) => { - // TODO: add validations before doing the fetch - return fetch({ - ...defaultOpts, - ...options, - body: { item }, - }) -} - -export function extendHook(customFetcher: typeof fetcher) { - const useAddItem = (opts?: UseWishlistOptions) => { - const { data: customer } = useCustomer() - const { revalidate } = useWishlist(opts) - const fn = useWishlistAddItem(defaultOpts, customFetcher) - - return useCallback( - async function addItem(input: AddItemInput) { - if (!customer) { - // A signed customer is required in order to have a wishlist - throw new CommerceError({ - message: 'Signed customer not found', - }) - } - - const data = await fn({ item: input }) - await revalidate() - return data - }, - [fn, revalidate, customer] - ) - } - - useAddItem.extend = extendHook - - return useAddItem -} - -export default extendHook(fetcher) diff --git a/lib/bigcommerce/wishlist/use-remove-item.tsx b/lib/bigcommerce/wishlist/use-remove-item.tsx deleted file mode 100644 index 133c6d9ff..000000000 --- a/lib/bigcommerce/wishlist/use-remove-item.tsx +++ /dev/null @@ -1,61 +0,0 @@ -import { useCallback } from 'react' -import { HookFetcher } from '../../commerce/utils/types' -import { CommerceError } from '../../commerce/utils/errors' -import useWishlistRemoveItem from '../../commerce/wishlist/use-remove-item' -import type { RemoveItemBody } from '../api/wishlist' -import useCustomer from '../use-customer' -import useWishlist, { UseWishlistOptions, Wishlist } from './use-wishlist' - -const defaultOpts = { - url: '/api/bigcommerce/wishlist', - method: 'DELETE', -} - -export type RemoveItemInput = { - id: string | number -} - -export const fetcher: HookFetcher = ( - options, - { itemId }, - fetch -) => { - return fetch({ - ...defaultOpts, - ...options, - body: { itemId }, - }) -} - -export function extendHook(customFetcher: typeof fetcher) { - const useRemoveItem = (opts?: UseWishlistOptions) => { - const { data: customer } = useCustomer() - const { revalidate } = useWishlist(opts) - const fn = useWishlistRemoveItem( - defaultOpts, - customFetcher - ) - - return useCallback( - async function removeItem(input: RemoveItemInput) { - if (!customer) { - // A signed customer is required in order to have a wishlist - throw new CommerceError({ - message: 'Signed customer not found', - }) - } - - const data = await fn({ itemId: String(input.id) }) - await revalidate() - return data - }, - [fn, revalidate, customer] - ) - } - - useRemoveItem.extend = extendHook - - return useRemoveItem -} - -export default extendHook(fetcher) diff --git a/lib/bigcommerce/wishlist/use-wishlist.tsx b/lib/bigcommerce/wishlist/use-wishlist.tsx deleted file mode 100644 index 0d4c843b8..000000000 --- a/lib/bigcommerce/wishlist/use-wishlist.tsx +++ /dev/null @@ -1,76 +0,0 @@ -import { HookFetcher } from '../../commerce/utils/types' -import { SwrOptions } from '../../commerce/utils/use-data' -import useCommerceWishlist from '../../commerce/wishlist/use-wishlist' -import type { Wishlist } from '../api/wishlist' -import useCustomer from '../use-customer' - -const defaultOpts = { - url: '/api/bigcommerce/wishlist', - method: 'GET', -} - -export type { Wishlist } - -export interface UseWishlistOptions { - includeProducts?: boolean -} - -export interface UseWishlistInput extends UseWishlistOptions { - customerId?: number -} - -export const fetcher: HookFetcher = ( - options, - { customerId, includeProducts }, - fetch -) => { - if (!customerId) return null - - // Use a dummy base as we only care about the relative path - const url = new URL(options?.url ?? defaultOpts.url, 'http://a') - - if (includeProducts) url.searchParams.set('products', '1') - - return fetch({ - url: url.pathname + url.search, - method: options?.method ?? defaultOpts.method, - }) -} - -export function extendHook( - customFetcher: typeof fetcher, - swrOptions?: SwrOptions -) { - const useWishlist = ({ includeProducts }: UseWishlistOptions = {}) => { - const { data: customer } = useCustomer() - const response = useCommerceWishlist( - defaultOpts, - [ - ['customerId', customer?.entityId], - ['includeProducts', includeProducts], - ], - customFetcher, - { - revalidateOnFocus: false, - ...swrOptions, - } - ) - - // Uses a getter to only calculate the prop when required - // response.data is also a getter and it's better to not trigger it early - Object.defineProperty(response, 'isEmpty', { - get() { - return (response.data?.items?.length || 0) <= 0 - }, - set: (x) => x, - }) - - return response - } - - useWishlist.extend = extendHook - - return useWishlist -} - -export default extendHook(fetcher) diff --git a/lib/commerce/utils/types.ts b/lib/commerce/utils/types.ts deleted file mode 100644 index b983d3391..000000000 --- a/lib/commerce/utils/types.ts +++ /dev/null @@ -1,24 +0,0 @@ -// Core fetcher added by CommerceProvider -export type Fetcher = (options: FetcherOptions) => T | Promise - -export type FetcherOptions = { - url?: string - query?: string - method?: string - variables?: any - body?: any -} - -export type HookFetcher = ( - options: HookFetcherOptions | null, - input: Input, - fetch: (options: FetcherOptions) => Promise -) => Result | Promise - -export type HookFetcherOptions = { - query?: string - url?: string - method?: string -} - -export type HookInput = [string, string | number | boolean | undefined][]