mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 15:36:58 +00:00
Replaced all imports to @commerce
This commit is contained in:
parent
40dcb39451
commit
512d8b7778
@ -1,5 +1,5 @@
|
||||
import { GetAPISchema, createEndpoint } from '@commerce/api'
|
||||
import checkoutEndpoint from '@commerce/api/endpoints/checkout'
|
||||
import { GetAPISchema, createEndpoint } from '@vercel/commerce/api'
|
||||
import checkoutEndpoint from '@vercel/commerce/api/endpoints/checkout'
|
||||
import type { CheckoutSchema } from '../../../types/checkout'
|
||||
import type { ShopifyAPI } from '../..'
|
||||
import getCheckout from './get-checkout'
|
||||
|
@ -2,7 +2,7 @@ import {
|
||||
CommerceAPI,
|
||||
CommerceAPIConfig,
|
||||
getCommerceApi as commerceApi,
|
||||
} from '@commerce/api'
|
||||
} from '@vercel/commerce/api'
|
||||
|
||||
import {
|
||||
API_URL,
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type {
|
||||
OperationContext,
|
||||
OperationOptions,
|
||||
} from '@commerce/api/operations'
|
||||
} from '@vercel/commerce/api/operations'
|
||||
import {
|
||||
GetAllPagesQuery,
|
||||
GetAllPagesQueryVariables,
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type {
|
||||
OperationContext,
|
||||
OperationOptions,
|
||||
} from '@commerce/api/operations'
|
||||
} from '@vercel/commerce/api/operations'
|
||||
import { GetAllProductPathsOperation } from '../../types/product'
|
||||
import {
|
||||
GetAllProductPathsQuery,
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type {
|
||||
OperationContext,
|
||||
OperationOptions,
|
||||
} from '@commerce/api/operations'
|
||||
} from '@vercel/commerce/api/operations'
|
||||
import { GetAllProductsOperation } from '../../types/product'
|
||||
import {
|
||||
GetAllProductsQuery,
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type {
|
||||
OperationContext,
|
||||
OperationOptions,
|
||||
} from '@commerce/api/operations'
|
||||
} from '@vercel/commerce/api/operations'
|
||||
import { normalizePage } from '../../utils'
|
||||
import type { ShopifyConfig, Provider } from '..'
|
||||
import {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type {
|
||||
OperationContext,
|
||||
OperationOptions,
|
||||
} from '@commerce/api/operations'
|
||||
} from '@vercel/commerce/api/operations'
|
||||
import { GetProductOperation } from '../../types/product'
|
||||
import { normalizeProduct, getProductQuery } from '../../utils'
|
||||
import type { ShopifyConfig, Provider } from '..'
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type {
|
||||
OperationContext,
|
||||
OperationOptions,
|
||||
} from '@commerce/api/operations'
|
||||
} from '@vercel/commerce/api/operations'
|
||||
import { GetSiteInfoQueryVariables } from '../../../schema'
|
||||
import type { ShopifyConfig, Provider } from '..'
|
||||
import { GetSiteInfoOperation } from '../../types/site'
|
||||
|
@ -1,5 +1,5 @@
|
||||
import type { ServerResponse } from 'http'
|
||||
import type { OperationContext } from '@commerce/api/operations'
|
||||
import type { OperationContext } from '@vercel/commerce/api/operations'
|
||||
import type { LoginOperation } from '../../types/login'
|
||||
import type { ShopifyConfig, Provider } from '..'
|
||||
import {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import type { GraphQLFetcher } from '@commerce/api'
|
||||
import type { GraphQLFetcher } from '@vercel/commerce/api'
|
||||
import fetch from './fetch'
|
||||
|
||||
import { API_URL, API_TOKEN } from '../../const'
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { useCallback } from 'react'
|
||||
import type { MutationHook } from '@commerce/utils/types'
|
||||
import { CommerceError } from '@commerce/utils/errors'
|
||||
import useLogin, { UseLogin } from '@commerce/auth/use-login'
|
||||
import type { MutationHook } from '@vercel/commerce/utils/types'
|
||||
import { CommerceError } from '@vercel/commerce/utils/errors'
|
||||
import useLogin, { UseLogin } from '@vercel/commerce/auth/use-login'
|
||||
import type { LoginHook } from '../types/login'
|
||||
import useCustomer from '../customer/use-customer'
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { useCallback } from 'react'
|
||||
import type { MutationHook } from '@commerce/utils/types'
|
||||
import useLogout, { UseLogout } from '@commerce/auth/use-logout'
|
||||
import type { MutationHook } from '@vercel/commerce/utils/types'
|
||||
import useLogout, { UseLogout } from '@vercel/commerce/auth/use-logout'
|
||||
import type { LogoutHook } from '../types/logout'
|
||||
import useCustomer from '../customer/use-customer'
|
||||
import customerAccessTokenDeleteMutation from '../utils/mutations/customer-access-token-delete'
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { useCallback } from 'react'
|
||||
import type { MutationHook } from '@commerce/utils/types'
|
||||
import { CommerceError } from '@commerce/utils/errors'
|
||||
import useSignup, { UseSignup } from '@commerce/auth/use-signup'
|
||||
import type { MutationHook } from '@vercel/commerce/utils/types'
|
||||
import { CommerceError } from '@vercel/commerce/utils/errors'
|
||||
import useSignup, { UseSignup } from '@vercel/commerce/auth/use-signup'
|
||||
import type { SignupHook } from '../types/signup'
|
||||
import useCustomer from '../customer/use-customer'
|
||||
import { Mutation, MutationCustomerCreateArgs } from '../../schema'
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { useCallback } from 'react'
|
||||
import type { MutationHook } from '@commerce/utils/types'
|
||||
import { CommerceError } from '@commerce/utils/errors'
|
||||
import useAddItem, { UseAddItem } from '@commerce/cart/use-add-item'
|
||||
import type { MutationHook } from '@vercel/commerce/utils/types'
|
||||
import { CommerceError } from '@vercel/commerce/utils/errors'
|
||||
import useAddItem, { UseAddItem } from '@vercel/commerce/cart/use-add-item'
|
||||
import type { AddItemHook } from '../types/cart'
|
||||
import useCart from './use-cart'
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { useMemo } from 'react'
|
||||
import useCommerceCart, { UseCart } from '@commerce/cart/use-cart'
|
||||
import useCommerceCart, { UseCart } from '@vercel/commerce/cart/use-cart'
|
||||
|
||||
import { SWRHook } from '@commerce/utils/types'
|
||||
import { SWRHook } from '@vercel/commerce/utils/types'
|
||||
import { checkoutToCart } from '../utils'
|
||||
import getCheckoutQuery from '../utils/queries/get-checkout-query'
|
||||
import { GetCartHook } from '../types/cart'
|
||||
|
@ -2,9 +2,11 @@ import { useCallback } from 'react'
|
||||
import type {
|
||||
MutationHookContext,
|
||||
HookFetcherContext,
|
||||
} from '@commerce/utils/types'
|
||||
import { ValidationError } from '@commerce/utils/errors'
|
||||
import useRemoveItem, { UseRemoveItem } from '@commerce/cart/use-remove-item'
|
||||
} 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 '../types/cart'
|
||||
import useCart from './use-cart'
|
||||
|
||||
|
@ -3,9 +3,11 @@ import debounce from 'lodash.debounce'
|
||||
import type {
|
||||
HookFetcherContext,
|
||||
MutationHookContext,
|
||||
} from '@commerce/utils/types'
|
||||
import { ValidationError } from '@commerce/utils/errors'
|
||||
import useUpdateItem, { UseUpdateItem } from '@commerce/cart/use-update-item'
|
||||
} from '@vercel/commerce/utils/types'
|
||||
import { ValidationError } from '@vercel/commerce/utils/errors'
|
||||
import useUpdateItem, {
|
||||
UseUpdateItem,
|
||||
} from '@vercel/commerce/cart/use-update-item'
|
||||
|
||||
import useCart from './use-cart'
|
||||
import { handler as removeItemHandler } from './use-remove-item'
|
||||
|
@ -1,5 +1,7 @@
|
||||
import { SWRHook } from '@commerce/utils/types'
|
||||
import useCheckout, { UseCheckout } from '@commerce/checkout/use-checkout'
|
||||
import { SWRHook } from '@vercel/commerce/utils/types'
|
||||
import useCheckout, {
|
||||
UseCheckout,
|
||||
} from '@vercel/commerce/checkout/use-checkout'
|
||||
|
||||
export default useCheckout as UseCheckout<typeof handler>
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
import useAddItem, { UseAddItem } from '@commerce/customer/address/use-add-item'
|
||||
import { MutationHook } from '@commerce/utils/types'
|
||||
import useAddItem, {
|
||||
UseAddItem,
|
||||
} from '@vercel/commerce/customer/address/use-add-item'
|
||||
import { MutationHook } from '@vercel/commerce/utils/types'
|
||||
|
||||
export default useAddItem as UseAddItem<typeof handler>
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
import useAddItem, { UseAddItem } from '@commerce/customer/card/use-add-item'
|
||||
import { MutationHook } from '@commerce/utils/types'
|
||||
import useAddItem, {
|
||||
UseAddItem,
|
||||
} from '@vercel/commerce/customer/card/use-add-item'
|
||||
import { MutationHook } from '@vercel/commerce/utils/types'
|
||||
|
||||
export default useAddItem as UseAddItem<typeof handler>
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
import useCustomer, { UseCustomer } from '@commerce/customer/use-customer'
|
||||
import useCustomer, {
|
||||
UseCustomer,
|
||||
} from '@vercel/commerce/customer/use-customer'
|
||||
import type { CustomerHook } from '../types/customer'
|
||||
import { SWRHook } from '@commerce/utils/types'
|
||||
import { SWRHook } from '@vercel/commerce/utils/types'
|
||||
import { getCustomerQuery, getCustomerToken } from '../utils'
|
||||
import { GetCustomerQuery, GetCustomerQueryVariables } from '../../schema'
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Fetcher } from '@commerce/utils/types'
|
||||
import { Fetcher } from '@vercel/commerce/utils/types'
|
||||
import { API_TOKEN, API_URL } from './const'
|
||||
import { handleFetchResponse } from './utils'
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
import { getCommerceProvider, useCommerce as useCoreCommerce } from '@commerce'
|
||||
import {
|
||||
getCommerceProvider,
|
||||
useCommerce as useCoreCommerce,
|
||||
} from '@vercel/commerce'
|
||||
import { shopifyProvider, ShopifyProvider } from './provider'
|
||||
|
||||
export { shopifyProvider }
|
||||
|
@ -1,2 +1,2 @@
|
||||
export * from '@commerce/product/use-price'
|
||||
export { default } from '@commerce/product/use-price'
|
||||
export * from '@vercel/commerce/product/use-price'
|
||||
export { default } from '@vercel/commerce/product/use-price'
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { SWRHook } from '@commerce/utils/types'
|
||||
import useSearch, { UseSearch } from '@commerce/product/use-search'
|
||||
import { SWRHook } from '@vercel/commerce/utils/types'
|
||||
import useSearch, { UseSearch } from '@vercel/commerce/product/use-search'
|
||||
|
||||
import {
|
||||
CollectionEdge,
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as Core from '@commerce/types/cart'
|
||||
import * as Core from '@vercel/commerce/types/cart'
|
||||
|
||||
export * from '@commerce/types/cart'
|
||||
export * from '@vercel/commerce/types/cart'
|
||||
|
||||
export type ShopifyCart = {}
|
||||
|
||||
|
@ -1 +1 @@
|
||||
export * from '@commerce/types/checkout'
|
||||
export * from '@vercel/commerce/types/checkout'
|
||||
|
@ -1 +1 @@
|
||||
export * from '@commerce/types/common'
|
||||
export * from '@vercel/commerce/types/common'
|
||||
|
@ -1,5 +1,5 @@
|
||||
import * as Core from '@commerce/types/customer'
|
||||
import * as Core from '@vercel/commerce/types/customer'
|
||||
|
||||
export * from '@commerce/types/customer'
|
||||
export * from '@vercel/commerce/types/customer'
|
||||
|
||||
export type CustomerSchema = Core.CustomerSchema
|
||||
|
@ -1,7 +1,7 @@
|
||||
import * as Core from '@commerce/types/login'
|
||||
import * as Core from '@vercel/commerce/types/login'
|
||||
import type { CustomerAccessTokenCreateInput } from '../../schema'
|
||||
|
||||
export * from '@commerce/types/login'
|
||||
export * from '@vercel/commerce/types/login'
|
||||
|
||||
export type LoginOperation = Core.LoginOperation & {
|
||||
variables: CustomerAccessTokenCreateInput
|
||||
|
@ -1 +1 @@
|
||||
export * from '@commerce/types/logout'
|
||||
export * from '@vercel/commerce/types/logout'
|
||||
|
@ -1,5 +1,5 @@
|
||||
import * as Core from '@commerce/types/page'
|
||||
export * from '@commerce/types/page'
|
||||
import * as Core from '@vercel/commerce/types/page'
|
||||
export * from '@vercel/commerce/types/page'
|
||||
|
||||
export type Page = Core.Page
|
||||
|
||||
|
@ -1 +1 @@
|
||||
export * from '@commerce/types/product'
|
||||
export * from '@vercel/commerce/types/product'
|
||||
|
@ -1 +1 @@
|
||||
export * from '@commerce/types/signup'
|
||||
export * from '@vercel/commerce/types/signup'
|
||||
|
@ -1 +1 @@
|
||||
export * from '@commerce/types/site'
|
||||
export * from '@vercel/commerce/types/site'
|
||||
|
@ -1 +1 @@
|
||||
export * from '@commerce/types/wishlist'
|
||||
export * from '@vercel/commerce/types/wishlist'
|
||||
|
@ -13,7 +13,7 @@ import {
|
||||
Mutation,
|
||||
MutationCheckoutCreateArgs,
|
||||
} from '../../schema'
|
||||
import { FetcherOptions } from '@commerce/utils/types'
|
||||
import { FetcherOptions } from '@vercel/commerce/utils/types'
|
||||
|
||||
export const checkoutCreate = async (
|
||||
fetch: <T = any, B = Body>(options: FetcherOptions<B>) => Promise<T>,
|
||||
|
@ -1,5 +1,5 @@
|
||||
import type { Cart } from '../types/cart'
|
||||
import { CommerceError } from '@commerce/utils/errors'
|
||||
import { CommerceError } from '@vercel/commerce/utils/errors'
|
||||
|
||||
import {
|
||||
CheckoutLineItemsAddPayload,
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { FetcherOptions } from '@commerce/utils/types'
|
||||
import { FetcherOptions } from '@vercel/commerce/utils/types'
|
||||
import throwUserErrors from './throw-user-errors'
|
||||
|
||||
import {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { FetcherError } from '@commerce/utils/errors'
|
||||
import { FetcherError } from '@vercel/commerce/utils/errors'
|
||||
|
||||
export function getError(errors: any[] | null, status: number) {
|
||||
errors = errors ?? [{ message: 'Failed to fetch Shopify API' }]
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { FetcherOptions } from '@commerce/utils/types'
|
||||
import { FetcherOptions } from '@vercel/commerce/utils/types'
|
||||
import { CustomerAccessTokenCreateInput } from '../../schema'
|
||||
import { setCustomerToken } from './customer-token'
|
||||
import { customerAccessTokenCreateMutation } from './mutations'
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { ValidationError } from '@commerce/utils/errors'
|
||||
import { ValidationError } from '@vercel/commerce/utils/errors'
|
||||
|
||||
import {
|
||||
CheckoutErrorCode,
|
||||
|
@ -1,7 +1,7 @@
|
||||
// TODO: replace this hook and other wishlist hooks with a handler, or remove them if
|
||||
// Shopify doesn't have a wishlist
|
||||
|
||||
import { HookFetcher } from '@commerce/utils/types'
|
||||
import { HookFetcher } from '@vercel/commerce/utils/types'
|
||||
import { Product } from '../../schema'
|
||||
|
||||
const defaultOpts = {}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { createEndpoint } from '@commerce/api'
|
||||
import type { GetAPISchema, CommerceAPI } from '@commerce/api'
|
||||
import checkoutEndpoint from '@commerce/api/endpoints/checkout'
|
||||
import type { CheckoutSchema } from '@commerce/types/checkout'
|
||||
import { createEndpoint } from '@vercel/commerce/api'
|
||||
import type { GetAPISchema, CommerceAPI } from '@vercel/commerce/api'
|
||||
import checkoutEndpoint from '@vercel/commerce/api/endpoints/checkout'
|
||||
import type { CheckoutSchema } from '@vercel/commerce/types/checkout'
|
||||
import getCheckout from './get-checkout'
|
||||
import type { SpreeApiProvider } from '../..'
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import type { CommerceAPI, CommerceAPIConfig } from '@commerce/api'
|
||||
import { getCommerceApi as commerceApi } from '@commerce/api'
|
||||
import type { CommerceAPI, CommerceAPIConfig } from '@vercel/commerce/api'
|
||||
import { getCommerceApi as commerceApi } from '@vercel/commerce/api'
|
||||
import createApiFetch from './utils/create-api-fetch'
|
||||
|
||||
import getAllPages from './operations/get-all-pages'
|
||||
|
@ -1,8 +1,8 @@
|
||||
import type {
|
||||
OperationContext,
|
||||
OperationOptions,
|
||||
} from '@commerce/api/operations'
|
||||
import type { GetAllPagesOperation, Page } from '@commerce/types/page'
|
||||
} from '@vercel/commerce/api/operations'
|
||||
import type { GetAllPagesOperation, Page } from '@vercel/commerce/types/page'
|
||||
import { requireConfigValue } from '../../isomorphic-config'
|
||||
import normalizePage from '../../utils/normalizations/normalize-page'
|
||||
import type { IPages } from '@spree/storefront-api-v2-sdk/types/interfaces/Page'
|
||||
|
@ -1,9 +1,9 @@
|
||||
import type {
|
||||
OperationContext,
|
||||
OperationOptions,
|
||||
} from '@commerce/api/operations'
|
||||
import type { Product } from '@commerce/types/product'
|
||||
import type { GetAllProductPathsOperation } from '@commerce/types/product'
|
||||
} from '@vercel/commerce/api/operations'
|
||||
import type { Product } from '@vercel/commerce/types/product'
|
||||
import type { GetAllProductPathsOperation } from '@vercel/commerce/types/product'
|
||||
import { requireConfigValue } from '../../isomorphic-config'
|
||||
import type { IProductsSlugs, SpreeSdkVariables } from '../../types'
|
||||
import getProductPath from '../../utils/get-product-path'
|
||||
|
@ -1,9 +1,9 @@
|
||||
import type { Product } from '@commerce/types/product'
|
||||
import type { GetAllProductsOperation } from '@commerce/types/product'
|
||||
import type { Product } from '@vercel/commerce/types/product'
|
||||
import type { GetAllProductsOperation } from '@vercel/commerce/types/product'
|
||||
import type {
|
||||
OperationContext,
|
||||
OperationOptions,
|
||||
} from '@commerce/api/operations'
|
||||
} from '@vercel/commerce/api/operations'
|
||||
import type { IProducts } from '@spree/storefront-api-v2-sdk/types/interfaces/Product'
|
||||
import type { SpreeApiConfig, SpreeApiProvider } from '../index'
|
||||
import type { SpreeSdkVariables } from '../../types'
|
||||
|
@ -1,8 +1,8 @@
|
||||
import type {
|
||||
OperationContext,
|
||||
OperationOptions,
|
||||
} from '@commerce/api/operations'
|
||||
import type { GetPageOperation } from '@commerce/types/page'
|
||||
} from '@vercel/commerce/api/operations'
|
||||
import type { GetPageOperation } from '@vercel/commerce/types/page'
|
||||
import type { SpreeSdkVariables } from '../../types'
|
||||
import type { SpreeApiConfig, SpreeApiProvider } from '..'
|
||||
import type { IPage } from '@spree/storefront-api-v2-sdk/types/interfaces/Page'
|
||||
|
@ -1,9 +1,9 @@
|
||||
import type { SpreeApiConfig, SpreeApiProvider } from '../index'
|
||||
import type { GetProductOperation } from '@commerce/types/product'
|
||||
import type { GetProductOperation } from '@vercel/commerce/types/product'
|
||||
import type {
|
||||
OperationContext,
|
||||
OperationOptions,
|
||||
} from '@commerce/api/operations'
|
||||
} from '@vercel/commerce/api/operations'
|
||||
import type { IProduct } from '@spree/storefront-api-v2-sdk/types/interfaces/Product'
|
||||
import type { SpreeSdkVariables } from '../../types'
|
||||
import MissingSlugVariableError from '../../errors/MissingSlugVariableError'
|
||||
|
@ -1,8 +1,11 @@
|
||||
import type {
|
||||
OperationContext,
|
||||
OperationOptions,
|
||||
} from '@commerce/api/operations'
|
||||
import type { Category, GetSiteInfoOperation } from '@commerce/types/site'
|
||||
} from '@vercel/commerce/api/operations'
|
||||
import type {
|
||||
Category,
|
||||
GetSiteInfoOperation,
|
||||
} from '@vercel/commerce/types/site'
|
||||
import type {
|
||||
ITaxons,
|
||||
TaxonAttr,
|
||||
|
@ -5,7 +5,7 @@ import convertSpreeErrorToGraphQlError from '../../utils/convert-spree-error-to-
|
||||
import type { ResultResponse } from '@spree/storefront-api-v2-sdk/types/interfaces/ResultResponse'
|
||||
import getSpreeSdkMethodFromEndpointPath from '../../utils/get-spree-sdk-method-from-endpoint-path'
|
||||
import SpreeSdkMethodFromEndpointPathError from '../../errors/SpreeSdkMethodFromEndpointPathError'
|
||||
import { GraphQLFetcher, GraphQLFetcherResult } from '@commerce/api'
|
||||
import { GraphQLFetcher, GraphQLFetcherResult } from '@vercel/commerce/api'
|
||||
import createCustomizedFetchFetcher, {
|
||||
fetchResponseKey,
|
||||
} from '../../utils/create-customized-fetch-fetcher'
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { useCallback } from 'react'
|
||||
import type { MutationHook } from '@commerce/utils/types'
|
||||
import useLogin, { UseLogin } from '@commerce/auth/use-login'
|
||||
import type { LoginHook } from '@commerce/types/login'
|
||||
import type { MutationHook } from '@vercel/commerce/utils/types'
|
||||
import useLogin, { UseLogin } from '@vercel/commerce/auth/use-login'
|
||||
import type { LoginHook } from '@vercel/commerce/types/login'
|
||||
import type { AuthTokenAttr } from '@spree/storefront-api-v2-sdk/types/interfaces/Authentication'
|
||||
import { FetcherError, ValidationError } from '@commerce/utils/errors'
|
||||
import { FetcherError, ValidationError } from '@vercel/commerce/utils/errors'
|
||||
import useCustomer from '../customer/use-customer'
|
||||
import useCart from '../cart/use-cart'
|
||||
import useWishlist from '../wishlist/use-wishlist'
|
||||
@ -60,25 +60,26 @@ export const handler: MutationHook<LoginHook> = {
|
||||
}
|
||||
},
|
||||
useHook: ({ fetch }) => {
|
||||
const useWrappedHook: ReturnType<MutationHook<LoginHook>['useHook']> =
|
||||
() => {
|
||||
const customer = useCustomer()
|
||||
const cart = useCart()
|
||||
const wishlist = useWishlist()
|
||||
const useWrappedHook: ReturnType<
|
||||
MutationHook<LoginHook>['useHook']
|
||||
> = () => {
|
||||
const customer = useCustomer()
|
||||
const cart = useCart()
|
||||
const wishlist = useWishlist()
|
||||
|
||||
return useCallback(
|
||||
async function login(input) {
|
||||
const data = await fetch({ input })
|
||||
return useCallback(
|
||||
async function login(input) {
|
||||
const data = await fetch({ input })
|
||||
|
||||
await customer.revalidate()
|
||||
await cart.revalidate()
|
||||
await wishlist.revalidate()
|
||||
await customer.revalidate()
|
||||
await cart.revalidate()
|
||||
await wishlist.revalidate()
|
||||
|
||||
return data
|
||||
},
|
||||
[customer, cart, wishlist]
|
||||
)
|
||||
}
|
||||
return data
|
||||
},
|
||||
[customer, cart, wishlist]
|
||||
)
|
||||
}
|
||||
|
||||
return useWrappedHook
|
||||
},
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { MutationHook } from '@commerce/utils/types'
|
||||
import useLogout, { UseLogout } from '@commerce/auth/use-logout'
|
||||
import type { LogoutHook } from '@commerce/types/logout'
|
||||
import { MutationHook } from '@vercel/commerce/utils/types'
|
||||
import useLogout, { UseLogout } from '@vercel/commerce/auth/use-logout'
|
||||
import type { LogoutHook } from '@vercel/commerce/types/logout'
|
||||
import { useCallback } from 'react'
|
||||
import useCustomer from '../customer/use-customer'
|
||||
import useCart from '../cart/use-cart'
|
||||
@ -52,28 +52,29 @@ export const handler: MutationHook<LogoutHook> = {
|
||||
return null
|
||||
},
|
||||
useHook: ({ fetch }) => {
|
||||
const useWrappedHook: ReturnType<MutationHook<LogoutHook>['useHook']> =
|
||||
() => {
|
||||
const customer = useCustomer({
|
||||
swrOptions: { isPaused: () => true },
|
||||
})
|
||||
const cart = useCart({
|
||||
swrOptions: { isPaused: () => true },
|
||||
})
|
||||
const wishlist = useWishlist({
|
||||
swrOptions: { isPaused: () => true },
|
||||
})
|
||||
const useWrappedHook: ReturnType<
|
||||
MutationHook<LogoutHook>['useHook']
|
||||
> = () => {
|
||||
const customer = useCustomer({
|
||||
swrOptions: { isPaused: () => true },
|
||||
})
|
||||
const cart = useCart({
|
||||
swrOptions: { isPaused: () => true },
|
||||
})
|
||||
const wishlist = useWishlist({
|
||||
swrOptions: { isPaused: () => true },
|
||||
})
|
||||
|
||||
return useCallback(async () => {
|
||||
const data = await fetch()
|
||||
return useCallback(async () => {
|
||||
const data = await fetch()
|
||||
|
||||
await customer.mutate(null, false)
|
||||
await cart.mutate(null, false)
|
||||
await wishlist.mutate(null, false)
|
||||
await customer.mutate(null, false)
|
||||
await cart.mutate(null, false)
|
||||
await wishlist.mutate(null, false)
|
||||
|
||||
return data
|
||||
}, [customer, cart, wishlist])
|
||||
}
|
||||
return data
|
||||
}, [customer, cart, wishlist])
|
||||
}
|
||||
|
||||
return useWrappedHook
|
||||
},
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { useCallback } from 'react'
|
||||
import type { GraphQLFetcherResult } from '@commerce/api'
|
||||
import type { MutationHook } from '@commerce/utils/types'
|
||||
import useSignup, { UseSignup } from '@commerce/auth/use-signup'
|
||||
import type { SignupHook } from '@commerce/types/signup'
|
||||
import { ValidationError } from '@commerce/utils/errors'
|
||||
import type { GraphQLFetcherResult } from '@vercel/commerce/api'
|
||||
import type { MutationHook } from '@vercel/commerce/utils/types'
|
||||
import useSignup, { UseSignup } from '@vercel/commerce/auth/use-signup'
|
||||
import type { SignupHook } from '@vercel/commerce/types/signup'
|
||||
import { ValidationError } from '@vercel/commerce/utils/errors'
|
||||
import type { IAccount } from '@spree/storefront-api-v2-sdk/types/interfaces/Account'
|
||||
import type { AuthTokenAttr } from '@spree/storefront-api-v2-sdk/types/interfaces/Authentication'
|
||||
import useCustomer from '../customer/use-customer'
|
||||
@ -70,25 +70,26 @@ export const handler: MutationHook<SignupHook> = {
|
||||
return null
|
||||
},
|
||||
useHook: ({ fetch }) => {
|
||||
const useWrappedHook: ReturnType<MutationHook<SignupHook>['useHook']> =
|
||||
() => {
|
||||
const customer = useCustomer()
|
||||
const cart = useCart()
|
||||
const wishlist = useWishlist()
|
||||
const useWrappedHook: ReturnType<
|
||||
MutationHook<SignupHook>['useHook']
|
||||
> = () => {
|
||||
const customer = useCustomer()
|
||||
const cart = useCart()
|
||||
const wishlist = useWishlist()
|
||||
|
||||
return useCallback(
|
||||
async (input) => {
|
||||
const data = await fetch({ input })
|
||||
return useCallback(
|
||||
async (input) => {
|
||||
const data = await fetch({ input })
|
||||
|
||||
await customer.revalidate()
|
||||
await cart.revalidate()
|
||||
await wishlist.revalidate()
|
||||
await customer.revalidate()
|
||||
await cart.revalidate()
|
||||
await wishlist.revalidate()
|
||||
|
||||
return data
|
||||
},
|
||||
[customer, cart, wishlist]
|
||||
)
|
||||
}
|
||||
return data
|
||||
},
|
||||
[customer, cart, wishlist]
|
||||
)
|
||||
}
|
||||
|
||||
return useWrappedHook
|
||||
},
|
||||
|
@ -1,18 +1,18 @@
|
||||
import useAddItem from '@commerce/cart/use-add-item'
|
||||
import type { UseAddItem } from '@commerce/cart/use-add-item'
|
||||
import type { MutationHook } from '@commerce/utils/types'
|
||||
import useAddItem from '@vercel/commerce/cart/use-add-item'
|
||||
import type { UseAddItem } from '@vercel/commerce/cart/use-add-item'
|
||||
import type { MutationHook } from '@vercel/commerce/utils/types'
|
||||
import { useCallback } from 'react'
|
||||
import useCart from './use-cart'
|
||||
import type { AddItemHook } from '@commerce/types/cart'
|
||||
import type { AddItemHook } from '@vercel/commerce/types/cart'
|
||||
import normalizeCart from '../utils/normalizations/normalize-cart'
|
||||
import type { GraphQLFetcherResult } from '@commerce/api'
|
||||
import type { GraphQLFetcherResult } from '@vercel/commerce/api'
|
||||
import type { IOrder } from '@spree/storefront-api-v2-sdk/types/interfaces/Order'
|
||||
import type { IToken } from '@spree/storefront-api-v2-sdk/types/interfaces/Token'
|
||||
import type { AddItem } from '@spree/storefront-api-v2-sdk/types/interfaces/endpoints/CartClass'
|
||||
import { setCartToken } from '../utils/tokens/cart-token'
|
||||
import ensureIToken from '../utils/tokens/ensure-itoken'
|
||||
import createEmptyCart from '../utils/create-empty-cart'
|
||||
import { FetcherError } from '@commerce/utils/errors'
|
||||
import { FetcherError } from '@vercel/commerce/utils/errors'
|
||||
import isLoggedIn from '../utils/tokens/is-logged-in'
|
||||
|
||||
export default useAddItem as UseAddItem<typeof handler>
|
||||
@ -96,21 +96,22 @@ export const handler: MutationHook<AddItemHook> = {
|
||||
}
|
||||
},
|
||||
useHook: ({ fetch }) => {
|
||||
const useWrappedHook: ReturnType<MutationHook<AddItemHook>['useHook']> =
|
||||
() => {
|
||||
const { mutate } = useCart()
|
||||
const useWrappedHook: ReturnType<
|
||||
MutationHook<AddItemHook>['useHook']
|
||||
> = () => {
|
||||
const { mutate } = useCart()
|
||||
|
||||
return useCallback(
|
||||
async (input) => {
|
||||
const data = await fetch({ input })
|
||||
return useCallback(
|
||||
async (input) => {
|
||||
const data = await fetch({ input })
|
||||
|
||||
await mutate(data, false)
|
||||
await mutate(data, false)
|
||||
|
||||
return data
|
||||
},
|
||||
[mutate]
|
||||
)
|
||||
}
|
||||
return data
|
||||
},
|
||||
[mutate]
|
||||
)
|
||||
}
|
||||
|
||||
return useWrappedHook
|
||||
},
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { useMemo } from 'react'
|
||||
import type { SWRHook } from '@commerce/utils/types'
|
||||
import useCart from '@commerce/cart/use-cart'
|
||||
import type { UseCart } from '@commerce/cart/use-cart'
|
||||
import type { GetCartHook } from '@commerce/types/cart'
|
||||
import type { SWRHook } from '@vercel/commerce/utils/types'
|
||||
import useCart from '@vercel/commerce/cart/use-cart'
|
||||
import type { UseCart } from '@vercel/commerce/cart/use-cart'
|
||||
import type { GetCartHook } from '@vercel/commerce/types/cart'
|
||||
import normalizeCart from '../utils/normalizations/normalize-cart'
|
||||
import type { GraphQLFetcherResult } from '@commerce/api'
|
||||
import type { GraphQLFetcherResult } from '@vercel/commerce/api'
|
||||
import type { IOrder } from '@spree/storefront-api-v2-sdk/types/interfaces/Order'
|
||||
import type { IToken } from '@spree/storefront-api-v2-sdk/types/interfaces/Token'
|
||||
import { FetcherError } from '@commerce/utils/errors'
|
||||
import { FetcherError } from '@vercel/commerce/utils/errors'
|
||||
import { setCartToken } from '../utils/tokens/cart-token'
|
||||
import ensureIToken from '../utils/tokens/ensure-itoken'
|
||||
import isLoggedIn from '../utils/tokens/is-logged-in'
|
||||
|
@ -1,18 +1,18 @@
|
||||
import type { MutationHook } from '@commerce/utils/types'
|
||||
import useRemoveItem from '@commerce/cart/use-remove-item'
|
||||
import type { UseRemoveItem } from '@commerce/cart/use-remove-item'
|
||||
import type { RemoveItemHook } from '@commerce/types/cart'
|
||||
import type { MutationHook } from '@vercel/commerce/utils/types'
|
||||
import useRemoveItem from '@vercel/commerce/cart/use-remove-item'
|
||||
import type { UseRemoveItem } from '@vercel/commerce/cart/use-remove-item'
|
||||
import type { RemoveItemHook } from '@vercel/commerce/types/cart'
|
||||
import useCart from './use-cart'
|
||||
import { useCallback } from 'react'
|
||||
import normalizeCart from '../utils/normalizations/normalize-cart'
|
||||
import type { IOrder } from '@spree/storefront-api-v2-sdk/types/interfaces/Order'
|
||||
import type { GraphQLFetcherResult } from '@commerce/api'
|
||||
import type { GraphQLFetcherResult } from '@vercel/commerce/api'
|
||||
import type { IQuery } from '@spree/storefront-api-v2-sdk/types/interfaces/Query'
|
||||
import type { IToken } from '@spree/storefront-api-v2-sdk/types/interfaces/Token'
|
||||
import ensureIToken from '../utils/tokens/ensure-itoken'
|
||||
import createEmptyCart from '../utils/create-empty-cart'
|
||||
import { setCartToken } from '../utils/tokens/cart-token'
|
||||
import { FetcherError } from '@commerce/utils/errors'
|
||||
import { FetcherError } from '@vercel/commerce/utils/errors'
|
||||
import isLoggedIn from '../utils/tokens/is-logged-in'
|
||||
|
||||
export default useRemoveItem as UseRemoveItem<typeof handler>
|
||||
@ -94,24 +94,25 @@ export const handler: MutationHook<RemoveItemHook> = {
|
||||
}
|
||||
},
|
||||
useHook: ({ fetch }) => {
|
||||
const useWrappedHook: ReturnType<MutationHook<RemoveItemHook>['useHook']> =
|
||||
() => {
|
||||
const { mutate } = useCart()
|
||||
const useWrappedHook: ReturnType<
|
||||
MutationHook<RemoveItemHook>['useHook']
|
||||
> = () => {
|
||||
const { mutate } = useCart()
|
||||
|
||||
return useCallback(
|
||||
async (input) => {
|
||||
const data = await fetch({ input: { itemId: input.id } })
|
||||
return useCallback(
|
||||
async (input) => {
|
||||
const data = await fetch({ input: { itemId: input.id } })
|
||||
|
||||
// Upon calling cart.removeItem, Spree returns the old version of the cart,
|
||||
// with the already removed line item. Invalidate the useCart mutation
|
||||
// to fetch the cart again.
|
||||
await mutate(data, true)
|
||||
// Upon calling cart.removeItem, Spree returns the old version of the cart,
|
||||
// with the already removed line item. Invalidate the useCart mutation
|
||||
// to fetch the cart again.
|
||||
await mutate(data, true)
|
||||
|
||||
return data
|
||||
},
|
||||
[mutate]
|
||||
)
|
||||
}
|
||||
return data
|
||||
},
|
||||
[mutate]
|
||||
)
|
||||
}
|
||||
|
||||
return useWrappedHook
|
||||
},
|
||||
|
@ -1,12 +1,14 @@
|
||||
import type { MutationHook } from '@commerce/utils/types'
|
||||
import useUpdateItem, { UseUpdateItem } from '@commerce/cart/use-update-item'
|
||||
import type { UpdateItemHook } from '@commerce/types/cart'
|
||||
import type { MutationHook } from '@vercel/commerce/utils/types'
|
||||
import useUpdateItem, {
|
||||
UseUpdateItem,
|
||||
} from '@vercel/commerce/cart/use-update-item'
|
||||
import type { UpdateItemHook } from '@vercel/commerce/types/cart'
|
||||
import useCart from './use-cart'
|
||||
import { useMemo } from 'react'
|
||||
import { FetcherError, ValidationError } from '@commerce/utils/errors'
|
||||
import { FetcherError, ValidationError } from '@vercel/commerce/utils/errors'
|
||||
import type { IToken } from '@spree/storefront-api-v2-sdk/types/interfaces/Token'
|
||||
import type { SetQuantity } from '@spree/storefront-api-v2-sdk/types/interfaces/endpoints/CartClass'
|
||||
import type { GraphQLFetcherResult } from '@commerce/api'
|
||||
import type { GraphQLFetcherResult } from '@vercel/commerce/api'
|
||||
import type { IOrder } from '@spree/storefront-api-v2-sdk/types/interfaces/Order'
|
||||
import normalizeCart from '../utils/normalizations/normalize-cart'
|
||||
import debounce from 'lodash.debounce'
|
||||
@ -103,42 +105,43 @@ export const handler: MutationHook<UpdateItemHook> = {
|
||||
}
|
||||
},
|
||||
useHook: ({ fetch }) => {
|
||||
const useWrappedHook: ReturnType<MutationHook<UpdateItemHook>['useHook']> =
|
||||
(context) => {
|
||||
const { mutate } = useCart()
|
||||
const useWrappedHook: ReturnType<
|
||||
MutationHook<UpdateItemHook>['useHook']
|
||||
> = (context) => {
|
||||
const { mutate } = useCart()
|
||||
|
||||
return useMemo(
|
||||
() =>
|
||||
debounce(async (input: UpdateItemHook['actionInput']) => {
|
||||
const itemId = context?.item?.id
|
||||
const productId = input.productId ?? context?.item?.productId
|
||||
const variantId = input.variantId ?? context?.item?.variantId
|
||||
const quantity = input.quantity
|
||||
return useMemo(
|
||||
() =>
|
||||
debounce(async (input: UpdateItemHook['actionInput']) => {
|
||||
const itemId = context?.item?.id
|
||||
const productId = input.productId ?? context?.item?.productId
|
||||
const variantId = input.variantId ?? context?.item?.variantId
|
||||
const quantity = input.quantity
|
||||
|
||||
if (!itemId || !productId || !variantId) {
|
||||
throw new ValidationError({
|
||||
message: 'Invalid input used for this operation',
|
||||
})
|
||||
}
|
||||
|
||||
const data = await fetch({
|
||||
input: {
|
||||
item: {
|
||||
productId,
|
||||
variantId,
|
||||
quantity,
|
||||
},
|
||||
itemId,
|
||||
},
|
||||
if (!itemId || !productId || !variantId) {
|
||||
throw new ValidationError({
|
||||
message: 'Invalid input used for this operation',
|
||||
})
|
||||
}
|
||||
|
||||
await mutate(data, false)
|
||||
const data = await fetch({
|
||||
input: {
|
||||
item: {
|
||||
productId,
|
||||
variantId,
|
||||
quantity,
|
||||
},
|
||||
itemId,
|
||||
},
|
||||
})
|
||||
|
||||
return data
|
||||
}, context?.wait ?? 500),
|
||||
[mutate, context]
|
||||
)
|
||||
}
|
||||
await mutate(data, false)
|
||||
|
||||
return data
|
||||
}, context?.wait ?? 500),
|
||||
[mutate, context]
|
||||
)
|
||||
}
|
||||
|
||||
return useWrappedHook
|
||||
},
|
||||
|
@ -1,5 +1,7 @@
|
||||
import { SWRHook } from '@commerce/utils/types'
|
||||
import useCheckout, { UseCheckout } from '@commerce/checkout/use-checkout'
|
||||
import { SWRHook } from '@vercel/commerce/utils/types'
|
||||
import useCheckout, {
|
||||
UseCheckout,
|
||||
} from '@vercel/commerce/checkout/use-checkout'
|
||||
|
||||
export default useCheckout as UseCheckout<typeof handler>
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import useAddItem from '@commerce/customer/address/use-add-item'
|
||||
import type { UseAddItem } from '@commerce/customer/address/use-add-item'
|
||||
import type { MutationHook } from '@commerce/utils/types'
|
||||
import useAddItem from '@vercel/commerce/customer/address/use-add-item'
|
||||
import type { UseAddItem } from '@vercel/commerce/customer/address/use-add-item'
|
||||
import type { MutationHook } from '@vercel/commerce/utils/types'
|
||||
|
||||
export default useAddItem as UseAddItem<typeof handler>
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import useAddItem from '@commerce/customer/address/use-add-item'
|
||||
import type { UseAddItem } from '@commerce/customer/address/use-add-item'
|
||||
import type { MutationHook } from '@commerce/utils/types'
|
||||
import useAddItem from '@vercel/commerce/customer/address/use-add-item'
|
||||
import type { UseAddItem } from '@vercel/commerce/customer/address/use-add-item'
|
||||
import type { MutationHook } from '@vercel/commerce/utils/types'
|
||||
|
||||
export default useAddItem as UseAddItem<typeof handler>
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
import type { SWRHook } from '@commerce/utils/types'
|
||||
import useCustomer from '@commerce/customer/use-customer'
|
||||
import type { UseCustomer } from '@commerce/customer/use-customer'
|
||||
import type { CustomerHook } from '@commerce/types/customer'
|
||||
import type { SWRHook } from '@vercel/commerce/utils/types'
|
||||
import useCustomer from '@vercel/commerce/customer/use-customer'
|
||||
import type { UseCustomer } from '@vercel/commerce/customer/use-customer'
|
||||
import type { CustomerHook } from '@vercel/commerce/types/customer'
|
||||
import type { IToken } from '@spree/storefront-api-v2-sdk/types/interfaces/Token'
|
||||
import type { GraphQLFetcherResult } from '@commerce/api'
|
||||
import type { GraphQLFetcherResult } from '@vercel/commerce/api'
|
||||
import type { IAccount } from '@spree/storefront-api-v2-sdk/types/interfaces/Account'
|
||||
import { FetcherError } from '@commerce/utils/errors'
|
||||
import { FetcherError } from '@vercel/commerce/utils/errors'
|
||||
import normalizeUser from '../utils/normalizations/normalize-user'
|
||||
import isLoggedIn from '../utils/tokens/is-logged-in'
|
||||
import ensureIToken from '../utils/tokens/ensure-itoken'
|
||||
|
@ -1,8 +1,8 @@
|
||||
import type { Fetcher } from '@commerce/utils/types'
|
||||
import type { Fetcher } from '@vercel/commerce/utils/types'
|
||||
import convertSpreeErrorToGraphQlError from './utils/convert-spree-error-to-graph-ql-error'
|
||||
import { makeClient, errors } from '@spree/storefront-api-v2-sdk'
|
||||
import type { ResultResponse } from '@spree/storefront-api-v2-sdk/types/interfaces/ResultResponse'
|
||||
import type { GraphQLFetcherResult } from '@commerce/api'
|
||||
import type { GraphQLFetcherResult } from '@vercel/commerce/api'
|
||||
import { requireConfigValue } from './isomorphic-config'
|
||||
import getSpreeSdkMethodFromEndpointPath from './utils/get-spree-sdk-method-from-endpoint-path'
|
||||
import SpreeSdkMethodFromEndpointPathError from './errors/SpreeSdkMethodFromEndpointPathError'
|
||||
|
@ -4,12 +4,12 @@ import {
|
||||
CommerceProviderProps,
|
||||
CoreCommerceProvider,
|
||||
useCommerce as useCoreCommerce,
|
||||
} from '@commerce'
|
||||
} from '@vercel/commerce'
|
||||
import { spreeProvider } from './provider'
|
||||
import type { SpreeProvider } from './provider'
|
||||
import { SWRConfig } from 'swr'
|
||||
import handleTokenErrors from './utils/handle-token-errors'
|
||||
import useLogout from '@commerce/auth/use-logout'
|
||||
import useLogout from '@vercel/commerce/auth/use-logout'
|
||||
|
||||
export { spreeProvider }
|
||||
export type { SpreeProvider }
|
||||
|
@ -1,2 +1,2 @@
|
||||
export * from '@commerce/product/use-price'
|
||||
export { default } from '@commerce/product/use-price'
|
||||
export * from '@vercel/commerce/product/use-price'
|
||||
export { default } from '@vercel/commerce/product/use-price'
|
||||
|
@ -1,9 +1,12 @@
|
||||
import type { SWRHook } from '@commerce/utils/types'
|
||||
import useSearch from '@commerce/product/use-search'
|
||||
import type { Product, SearchProductsHook } from '@commerce/types/product'
|
||||
import type { UseSearch } from '@commerce/product/use-search'
|
||||
import type { SWRHook } from '@vercel/commerce/utils/types'
|
||||
import useSearch from '@vercel/commerce/product/use-search'
|
||||
import type {
|
||||
Product,
|
||||
SearchProductsHook,
|
||||
} from '@vercel/commerce/types/product'
|
||||
import type { UseSearch } from '@vercel/commerce/product/use-search'
|
||||
import normalizeProduct from '../utils/normalizations/normalize-product'
|
||||
import type { GraphQLFetcherResult } from '@commerce/api'
|
||||
import type { GraphQLFetcherResult } from '@vercel/commerce/api'
|
||||
import { IProducts } from '@spree/storefront-api-v2-sdk/types/interfaces/Product'
|
||||
import { requireConfigValue } from '../isomorphic-config'
|
||||
|
||||
|
@ -6,13 +6,13 @@ import type {
|
||||
} from '@spree/storefront-api-v2-sdk/types/interfaces/JsonApi'
|
||||
import type { ResultResponse } from '@spree/storefront-api-v2-sdk/types/interfaces/ResultResponse'
|
||||
import type { Response } from '@vercel/fetch'
|
||||
import type { ProductOption, Product } from '@commerce/types/product'
|
||||
import type { ProductOption, Product } from '@vercel/commerce/types/product'
|
||||
import type {
|
||||
AddItemHook,
|
||||
RemoveItemHook,
|
||||
WishlistItemBody,
|
||||
WishlistTypes,
|
||||
} from '@commerce/types/wishlist'
|
||||
} from '@vercel/commerce/types/wishlist'
|
||||
|
||||
export type UnknownObjectValues = Record<string, unknown>
|
||||
|
||||
@ -136,7 +136,7 @@ export type UserOAuthTokens = {
|
||||
|
||||
// TODO: ExplicitCommerceWishlist is a temporary type
|
||||
// derived from tsx views. It will be removed once
|
||||
// Wishlist in @commerce/types/wishlist is updated
|
||||
// Wishlist in @vercel/commerce/types/wishlist is updated
|
||||
// to a more specific type than `any`.
|
||||
export type ExplicitCommerceWishlist = {
|
||||
id: string
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { FetcherError } from '@commerce/utils/errors'
|
||||
import { FetcherError } from '@vercel/commerce/utils/errors'
|
||||
import { errors } from '@spree/storefront-api-v2-sdk'
|
||||
|
||||
const convertSpreeErrorToGraphQlError = (
|
||||
|
@ -1,5 +1,5 @@
|
||||
import type { GraphQLFetcherResult } from '@commerce/api'
|
||||
import type { HookFetcherContext } from '@commerce/utils/types'
|
||||
import type { GraphQLFetcherResult } from '@vercel/commerce/api'
|
||||
import type { HookFetcherContext } from '@vercel/commerce/utils/types'
|
||||
import type { IOrder } from '@spree/storefront-api-v2-sdk/types/interfaces/Order'
|
||||
import type { IToken } from '@spree/storefront-api-v2-sdk/types/interfaces/Token'
|
||||
import ensureIToken from './tokens/ensure-itoken'
|
||||
|
@ -1,4 +1,4 @@
|
||||
import type { ProductOptionValues } from '@commerce/types/product'
|
||||
import type { ProductOptionValues } from '@vercel/commerce/types/product'
|
||||
import type {
|
||||
JsonApiDocument,
|
||||
JsonApiResponse,
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Based on https://github.com/spark-solutions/spree2vuestorefront/blob/d88d85ae1bcd2ec99b13b81cd2e3c25600a0216e/src/utils/index.ts
|
||||
|
||||
import type { ProductImage } from '@commerce/types/product'
|
||||
import type { ProductImage } from '@vercel/commerce/types/product'
|
||||
import type { SpreeProductImage } from '../types'
|
||||
|
||||
const getMediaGallery = (
|
||||
|
@ -1,5 +1,5 @@
|
||||
import type { GraphQLFetcherResult } from '@commerce/api'
|
||||
import type { HookFetcherContext } from '@commerce/utils/types'
|
||||
import type { GraphQLFetcherResult } from '@vercel/commerce/api'
|
||||
import type { HookFetcherContext } from '@vercel/commerce/utils/types'
|
||||
import type { AuthTokenAttr } from '@spree/storefront-api-v2-sdk/types/interfaces/Authentication'
|
||||
import type { AssociateCart } from '@spree/storefront-api-v2-sdk/types/interfaces/endpoints/CartClass'
|
||||
import type { IOrder } from '@spree/storefront-api-v2-sdk/types/interfaces/Order'
|
||||
|
@ -3,12 +3,12 @@ import type {
|
||||
LineItem,
|
||||
ProductVariant,
|
||||
SelectedOption,
|
||||
} from '@commerce/types/cart'
|
||||
} from '@vercel/commerce/types/cart'
|
||||
import MissingLineItemVariantError from '../../errors/MissingLineItemVariantError'
|
||||
import { requireConfigValue } from '../../isomorphic-config'
|
||||
import type { OrderAttr } from '@spree/storefront-api-v2-sdk/types/interfaces/Order'
|
||||
import type { ProductAttr } from '@spree/storefront-api-v2-sdk/types/interfaces/Product'
|
||||
import type { Image } from '@commerce/types/common'
|
||||
import type { Image } from '@vercel/commerce/types/common'
|
||||
import { jsonApi } from '@spree/storefront-api-v2-sdk'
|
||||
import createGetAbsoluteImageUrl from '../create-get-absolute-image-url'
|
||||
import getMediaGallery from '../get-media-gallery'
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Page } from '@commerce/types/page'
|
||||
import { Page } from '@vercel/commerce/types/page'
|
||||
import type { PageAttr } from '@spree/storefront-api-v2-sdk/types/interfaces/Page'
|
||||
import { SpreeSdkResponse } from '../../types'
|
||||
|
||||
|
@ -3,7 +3,7 @@ import type {
|
||||
ProductImage,
|
||||
ProductPrice,
|
||||
ProductVariant,
|
||||
} from '@commerce/types/product'
|
||||
} from '@vercel/commerce/types/product'
|
||||
import type { ProductAttr } from '@spree/storefront-api-v2-sdk/types/interfaces/Product'
|
||||
import type { RelationType } from '@spree/storefront-api-v2-sdk/types/interfaces/Relationships'
|
||||
import { jsonApi } from '@spree/storefront-api-v2-sdk'
|
||||
|
@ -1,4 +1,4 @@
|
||||
import type { Customer } from '@commerce/types/customer'
|
||||
import type { Customer } from '@vercel/commerce/types/customer'
|
||||
import type { AccountAttr } from '@spree/storefront-api-v2-sdk/types/interfaces/Account'
|
||||
import type { SpreeSdkResponse } from '../../types'
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import type { GraphQLFetcherResult } from '@commerce/api'
|
||||
import type { HookFetcherContext } from '@commerce/utils/types'
|
||||
import type { GraphQLFetcherResult } from '@vercel/commerce/api'
|
||||
import type { HookFetcherContext } from '@vercel/commerce/utils/types'
|
||||
import TokensNotRejectedError from '../../errors/TokensNotRejectedError'
|
||||
import type { UserOAuthTokens } from '../../types'
|
||||
import type { EmptyObjectResponse } from '@spree/storefront-api-v2-sdk/types/interfaces/EmptyObject'
|
||||
|
@ -1,17 +1,17 @@
|
||||
import { useCallback } from 'react'
|
||||
import type { MutationHook } from '@commerce/utils/types'
|
||||
import useAddItem from '@commerce/wishlist/use-add-item'
|
||||
import type { UseAddItem } from '@commerce/wishlist/use-add-item'
|
||||
import type { MutationHook } from '@vercel/commerce/utils/types'
|
||||
import useAddItem from '@vercel/commerce/wishlist/use-add-item'
|
||||
import type { UseAddItem } from '@vercel/commerce/wishlist/use-add-item'
|
||||
import useWishlist from './use-wishlist'
|
||||
import type { ExplicitWishlistAddItemHook } from '../types'
|
||||
import type {
|
||||
WishedItem,
|
||||
WishlistsAddWishedItem,
|
||||
} from '@spree/storefront-api-v2-sdk/types/interfaces/WishedItem'
|
||||
import type { GraphQLFetcherResult } from '@commerce/api'
|
||||
import type { GraphQLFetcherResult } from '@vercel/commerce/api'
|
||||
import ensureIToken from '../utils/tokens/ensure-itoken'
|
||||
import type { IToken } from '@spree/storefront-api-v2-sdk/types/interfaces/Token'
|
||||
import type { AddItemHook } from '@commerce/types/wishlist'
|
||||
import type { AddItemHook } from '@vercel/commerce/types/wishlist'
|
||||
import isLoggedIn from '../utils/tokens/is-logged-in'
|
||||
|
||||
export default useAddItem as UseAddItem<typeof handler>
|
||||
@ -55,32 +55,33 @@ export const handler: MutationHook<ExplicitWishlistAddItemHook> = {
|
||||
return null
|
||||
},
|
||||
useHook: ({ fetch }) => {
|
||||
const useWrappedHook: ReturnType<MutationHook<AddItemHook>['useHook']> =
|
||||
() => {
|
||||
const wishlist = useWishlist()
|
||||
const useWrappedHook: ReturnType<
|
||||
MutationHook<AddItemHook>['useHook']
|
||||
> = () => {
|
||||
const wishlist = useWishlist()
|
||||
|
||||
return useCallback(
|
||||
async (item) => {
|
||||
if (!wishlist.data) {
|
||||
return null
|
||||
}
|
||||
return useCallback(
|
||||
async (item) => {
|
||||
if (!wishlist.data) {
|
||||
return null
|
||||
}
|
||||
|
||||
const data = await fetch({
|
||||
input: {
|
||||
item: {
|
||||
...item,
|
||||
wishlistToken: wishlist.data.token,
|
||||
},
|
||||
const data = await fetch({
|
||||
input: {
|
||||
item: {
|
||||
...item,
|
||||
wishlistToken: wishlist.data.token,
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
await wishlist.revalidate()
|
||||
await wishlist.revalidate()
|
||||
|
||||
return data
|
||||
},
|
||||
[wishlist]
|
||||
)
|
||||
}
|
||||
return data
|
||||
},
|
||||
[wishlist]
|
||||
)
|
||||
}
|
||||
|
||||
return useWrappedHook
|
||||
},
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { useCallback } from 'react'
|
||||
import type { MutationHook } from '@commerce/utils/types'
|
||||
import useRemoveItem from '@commerce/wishlist/use-remove-item'
|
||||
import type { UseRemoveItem } from '@commerce/wishlist/use-remove-item'
|
||||
import type { MutationHook } from '@vercel/commerce/utils/types'
|
||||
import useRemoveItem from '@vercel/commerce/wishlist/use-remove-item'
|
||||
import type { UseRemoveItem } from '@vercel/commerce/wishlist/use-remove-item'
|
||||
import useWishlist from './use-wishlist'
|
||||
import type { ExplicitWishlistRemoveItemHook } from '../types'
|
||||
import isLoggedIn from '../utils/tokens/is-logged-in'
|
||||
import ensureIToken from '../utils/tokens/ensure-itoken'
|
||||
import type { IToken } from '@spree/storefront-api-v2-sdk/types/interfaces/Token'
|
||||
import type { GraphQLFetcherResult } from '@commerce/api'
|
||||
import type { GraphQLFetcherResult } from '@vercel/commerce/api'
|
||||
import type { WishedItem } from '@spree/storefront-api-v2-sdk/types/interfaces/WishedItem'
|
||||
|
||||
export default useRemoveItem as UseRemoveItem<typeof handler>
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { useMemo } from 'react'
|
||||
import type { SWRHook } from '@commerce/utils/types'
|
||||
import useWishlist from '@commerce/wishlist/use-wishlist'
|
||||
import type { UseWishlist } from '@commerce/wishlist/use-wishlist'
|
||||
import type { GetWishlistHook } from '@commerce/types/wishlist'
|
||||
import type { SWRHook } from '@vercel/commerce/utils/types'
|
||||
import useWishlist from '@vercel/commerce/wishlist/use-wishlist'
|
||||
import type { UseWishlist } from '@vercel/commerce/wishlist/use-wishlist'
|
||||
import type { GetWishlistHook } from '@vercel/commerce/types/wishlist'
|
||||
import type { IToken } from '@spree/storefront-api-v2-sdk/types/interfaces/Token'
|
||||
import type { GraphQLFetcherResult } from '@commerce/api'
|
||||
import type { GraphQLFetcherResult } from '@vercel/commerce/api'
|
||||
import type { Wishlist } from '@spree/storefront-api-v2-sdk/types/interfaces/Wishlist'
|
||||
import ensureIToken from '../utils/tokens/ensure-itoken'
|
||||
import normalizeWishlist from '../utils/normalizations/normalize-wishlist'
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { CommerceAPI, createEndpoint, GetAPISchema } from '@commerce/api'
|
||||
import { CheckoutSchema } from '@commerce/types/checkout'
|
||||
import { CommerceAPI, createEndpoint, GetAPISchema } from '@vercel/commerce/api'
|
||||
import { CheckoutSchema } from '@vercel/commerce/types/checkout'
|
||||
import { SWELL_CHECKOUT_URL_COOKIE } from '../../../const'
|
||||
import checkoutEndpoint from '@commerce/api/endpoints/checkout'
|
||||
import checkoutEndpoint from '@vercel/commerce/api/endpoints/checkout'
|
||||
|
||||
const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
|
||||
req,
|
||||
|
@ -2,7 +2,7 @@ import {
|
||||
CommerceAPI,
|
||||
CommerceAPIConfig,
|
||||
getCommerceApi as commerceApi,
|
||||
} from '@commerce/api'
|
||||
} from '@vercel/commerce/api'
|
||||
import {
|
||||
SWELL_CHECKOUT_ID_COOKIE,
|
||||
SWELL_CUSTOMER_TOKEN_COOKIE,
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Provider, SwellConfig } from '..'
|
||||
import type { OperationContext } from '@commerce/api/operations'
|
||||
import type { OperationContext } from '@vercel/commerce/api/operations'
|
||||
import type { Page } from '../../types/page'
|
||||
|
||||
export type GetAllPagesResult<T extends { pages: any[] } = { pages: Page[] }> =
|
||||
|
@ -1,7 +1,10 @@
|
||||
import { SwellProduct } from '../../types'
|
||||
import { SwellConfig, Provider } from '..'
|
||||
import { OperationContext, OperationOptions } from '@commerce/api/operations'
|
||||
import { GetAllProductPathsOperation } from '@commerce/types/product'
|
||||
import {
|
||||
OperationContext,
|
||||
OperationOptions,
|
||||
} from '@vercel/commerce/api/operations'
|
||||
import { GetAllProductPathsOperation } from '@vercel/commerce/types/product'
|
||||
|
||||
export default function getAllProductPathsOperation({
|
||||
commerce,
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { normalizeProduct } from '../../utils/normalize'
|
||||
import { SwellProduct } from '../../types'
|
||||
import { Product } from '@commerce/types/product'
|
||||
import { Product } from '@vercel/commerce/types/product'
|
||||
import { Provider, SwellConfig } from '../'
|
||||
import { OperationContext } from '@commerce/api/operations'
|
||||
import { OperationContext } from '@vercel/commerce/api/operations'
|
||||
|
||||
export type ProductVariables = { first?: number }
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
import { Page } from '../../../schema'
|
||||
import { SwellConfig, Provider } from '..'
|
||||
import { OperationContext, OperationOptions } from '@commerce/api/operations'
|
||||
import {
|
||||
OperationContext,
|
||||
OperationOptions,
|
||||
} from '@vercel/commerce/api/operations'
|
||||
import { GetPageOperation } from '../../types/page'
|
||||
|
||||
export type GetPageResult<T extends { page?: any } = { page?: Page }> = T
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { normalizeProduct } from '../../utils'
|
||||
|
||||
import { Product } from '@commerce/types/product'
|
||||
import { OperationContext } from '@commerce/api/operations'
|
||||
import { Product } from '@vercel/commerce/types/product'
|
||||
import { OperationContext } from '@vercel/commerce/api/operations'
|
||||
import { Provider, SwellConfig } from '../'
|
||||
|
||||
export default function getProductOperation({
|
||||
|
@ -1,8 +1,8 @@
|
||||
import getCategories from '../../utils/get-categories'
|
||||
import getVendors, { Brands } from '../../utils/get-vendors'
|
||||
import { Provider, SwellConfig } from '../'
|
||||
import type { OperationContext } from '@commerce/api/operations'
|
||||
import type { Category } from '@commerce/types/site'
|
||||
import type { OperationContext } from '@vercel/commerce/api/operations'
|
||||
import type { Category } from '@vercel/commerce/types/site'
|
||||
|
||||
export type GetSiteInfoResult<
|
||||
T extends { categories: any[]; brands: any[] } = {
|
||||
|
@ -2,7 +2,7 @@ import type { ServerResponse } from 'http'
|
||||
import type {
|
||||
OperationContext,
|
||||
OperationOptions,
|
||||
} from '@commerce/api/operations'
|
||||
} from '@vercel/commerce/api/operations'
|
||||
import type { LoginOperation } from '../../types/login'
|
||||
import { Provider, SwellConfig } from '..'
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { useCallback } from 'react'
|
||||
import type { MutationHook } from '@commerce/utils/types'
|
||||
import { CommerceError, ValidationError } from '@commerce/utils/errors'
|
||||
import type { MutationHook } from '@vercel/commerce/utils/types'
|
||||
import { CommerceError, ValidationError } from '@vercel/commerce/utils/errors'
|
||||
import useCustomer from '../customer/use-customer'
|
||||
import {
|
||||
CustomerUserError,
|
||||
Mutation,
|
||||
MutationCheckoutCreateArgs,
|
||||
} from '../../schema'
|
||||
import useLogin, { UseLogin } from '@commerce/auth/use-login'
|
||||
import useLogin, { UseLogin } from '@vercel/commerce/auth/use-login'
|
||||
import { LoginHook } from '../types/login'
|
||||
import { setCustomerToken } from '../utils'
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { useCallback } from 'react'
|
||||
import type { MutationHook } from '@commerce/utils/types'
|
||||
import useLogout, { UseLogout } from '@commerce/auth/use-logout'
|
||||
import type { MutationHook } from '@vercel/commerce/utils/types'
|
||||
import useLogout, { UseLogout } from '@vercel/commerce/auth/use-logout'
|
||||
import useCustomer from '../customer/use-customer'
|
||||
import { getCustomerToken, setCustomerToken } from '../utils/customer-token'
|
||||
import { LogoutHook } from '../types/logout'
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { useCallback } from 'react'
|
||||
import type { MutationHook } from '@commerce/utils/types'
|
||||
import { CommerceError } from '@commerce/utils/errors'
|
||||
import useSignup, { UseSignup } from '@commerce/auth/use-signup'
|
||||
import type { MutationHook } from '@vercel/commerce/utils/types'
|
||||
import { CommerceError } from '@vercel/commerce/utils/errors'
|
||||
import useSignup, { UseSignup } from '@vercel/commerce/auth/use-signup'
|
||||
import useCustomer from '../customer/use-customer'
|
||||
import { SignupHook } from '../types/signup'
|
||||
import handleLogin from '../utils/handle-login'
|
||||
|
@ -1,6 +1,6 @@
|
||||
import type { MutationHook } from '@commerce/utils/types'
|
||||
import { CommerceError } from '@commerce/utils/errors'
|
||||
import useAddItem, { UseAddItem } from '@commerce/cart/use-add-item'
|
||||
import type { MutationHook } from '@vercel/commerce/utils/types'
|
||||
import { CommerceError } from '@vercel/commerce/utils/errors'
|
||||
import useAddItem, { UseAddItem } from '@vercel/commerce/cart/use-add-item'
|
||||
import useCart from './use-cart'
|
||||
import { checkoutToCart } from './utils'
|
||||
import { getCheckoutId } from '../utils'
|
||||
|
@ -1,9 +1,9 @@
|
||||
import useCart, { UseCart } from '@commerce/cart/use-cart'
|
||||
import { SWRHook } from '@commerce/utils/types'
|
||||
import useCart, { UseCart } from '@vercel/commerce/cart/use-cart'
|
||||
import { SWRHook } from '@vercel/commerce/utils/types'
|
||||
import { useMemo } from 'react'
|
||||
import { normalizeCart } from '../utils/normalize'
|
||||
import { checkoutCreate, checkoutToCart } from './utils'
|
||||
import type { GetCartHook } from '@commerce/types/cart'
|
||||
import type { GetCartHook } from '@vercel/commerce/types/cart'
|
||||
|
||||
export default useCart as UseCart<typeof handler>
|
||||
|
||||
|
@ -2,10 +2,16 @@ import { useCallback } from 'react'
|
||||
import type {
|
||||
MutationHookContext,
|
||||
HookFetcherContext,
|
||||
} from '@commerce/utils/types'
|
||||
} from '@vercel/commerce/utils/types'
|
||||
|
||||
import useRemoveItem, { UseRemoveItem } from '@commerce/cart/use-remove-item'
|
||||
import type { Cart, LineItem, RemoveItemHook } from '@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'
|
||||
import { checkoutToCart } from './utils'
|
||||
|
||||
|
@ -4,16 +4,18 @@ import type {
|
||||
HookFetcherContext,
|
||||
MutationHook,
|
||||
MutationHookContext,
|
||||
} from '@commerce/utils/types'
|
||||
import { ValidationError } from '@commerce/utils/errors'
|
||||
} from '@vercel/commerce/utils/types'
|
||||
import { ValidationError } from '@vercel/commerce/utils/errors'
|
||||
// import useUpdateItem, {
|
||||
// UpdateItemInput as UpdateItemInputBase,
|
||||
// UseUpdateItem,
|
||||
// } from '@commerce/cart/use-update-item'
|
||||
import useUpdateItem, { UseUpdateItem } from '@commerce/cart/use-update-item'
|
||||
// } from '@vercel/commerce/cart/use-update-item'
|
||||
import useUpdateItem, {
|
||||
UseUpdateItem,
|
||||
} from '@vercel/commerce/cart/use-update-item'
|
||||
import useCart from './use-cart'
|
||||
import { handler as removeItemHandler } from './use-remove-item'
|
||||
import { CartItemBody, LineItem } from '@commerce/types/cart'
|
||||
import { CartItemBody, LineItem } from '@vercel/commerce/types/cart'
|
||||
import { checkoutToCart } from './utils'
|
||||
import { UpdateItemHook } from '../types/cart'
|
||||
// export type UpdateItemInput<T = any> = T extends LineItem
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Cart } from '../../types'
|
||||
import { CommerceError } from '@commerce/utils/errors'
|
||||
import { CommerceError } from '@vercel/commerce/utils/errors'
|
||||
|
||||
import {
|
||||
CheckoutLineItemsAddPayload,
|
||||
|
@ -1,5 +1,7 @@
|
||||
import { SWRHook } from '@commerce/utils/types'
|
||||
import useCheckout, { UseCheckout } from '@commerce/checkout/use-checkout'
|
||||
import { SWRHook } from '@vercel/commerce/utils/types'
|
||||
import useCheckout, {
|
||||
UseCheckout,
|
||||
} from '@vercel/commerce/checkout/use-checkout'
|
||||
|
||||
export default useCheckout as UseCheckout<typeof handler>
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
import useAddItem, { UseAddItem } from '@commerce/customer/address/use-add-item'
|
||||
import { MutationHook } from '@commerce/utils/types'
|
||||
import useAddItem, {
|
||||
UseAddItem,
|
||||
} from '@vercel/commerce/customer/address/use-add-item'
|
||||
import { MutationHook } from '@vercel/commerce/utils/types'
|
||||
|
||||
export default useAddItem as UseAddItem<typeof handler>
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user