Updated urls to the API

This commit is contained in:
Luis Alvarez 2021-05-25 21:53:04 -05:00
parent cf9b341dc9
commit 746028f25b
11 changed files with 16 additions and 19 deletions

View File

@ -9,7 +9,7 @@ export default useLogin as UseLogin<typeof handler>
export const handler: MutationHook<LoginHook> = { export const handler: MutationHook<LoginHook> = {
fetchOptions: { fetchOptions: {
url: '/api/bigcommerce/customers/login', url: '/api/login',
method: 'POST', method: 'POST',
}, },
async fetcher({ input: { email, password }, options, fetch }) { async fetcher({ input: { email, password }, options, fetch }) {

View File

@ -8,7 +8,7 @@ export default useLogout as UseLogout<typeof handler>
export const handler: MutationHook<LogoutHook> = { export const handler: MutationHook<LogoutHook> = {
fetchOptions: { fetchOptions: {
url: '/api/bigcommerce/customers/logout', url: '/api/logout',
method: 'GET', method: 'GET',
}, },
useHook: ({ fetch }) => () => { useHook: ({ fetch }) => () => {

View File

@ -9,7 +9,7 @@ export default useSignup as UseSignup<typeof handler>
export const handler: MutationHook<SignupHook> = { export const handler: MutationHook<SignupHook> = {
fetchOptions: { fetchOptions: {
url: '/api/bigcommerce/customers/signup', url: '/api/signup',
method: 'POST', method: 'POST',
}, },
async fetcher({ async fetcher({

View File

@ -9,7 +9,7 @@ export default useAddItem as UseAddItem<typeof handler>
export const handler: MutationHook<AddItemHook> = { export const handler: MutationHook<AddItemHook> = {
fetchOptions: { fetchOptions: {
url: '/api/bigcommerce/cart', url: '/api/cart',
method: 'POST', method: 'POST',
}, },
async fetcher({ input: item, options, fetch }) { async fetcher({ input: item, options, fetch }) {

View File

@ -7,7 +7,7 @@ export default useCart as UseCart<typeof handler>
export const handler: SWRHook<GetCartHook> = { export const handler: SWRHook<GetCartHook> = {
fetchOptions: { fetchOptions: {
url: '/api/bigcommerce/cart', url: '/api/cart',
method: 'GET', method: 'GET',
}, },
useHook: ({ useData }) => (input) => { useHook: ({ useData }) => (input) => {

View File

@ -20,7 +20,7 @@ export default useRemoveItem as UseRemoveItem<typeof handler>
export const handler = { export const handler = {
fetchOptions: { fetchOptions: {
url: '/api/bigcommerce/cart', url: '/api/cart',
method: 'DELETE', method: 'DELETE',
}, },
async fetcher({ async fetcher({

View File

@ -6,7 +6,7 @@ import type {
} from '@commerce/utils/types' } from '@commerce/utils/types'
import { ValidationError } from '@commerce/utils/errors' import { ValidationError } from '@commerce/utils/errors'
import useUpdateItem, { UseUpdateItem } from '@commerce/cart/use-update-item' import useUpdateItem, { UseUpdateItem } from '@commerce/cart/use-update-item'
import type { LineItem, UpdateItemHook } from '../types' import type { LineItem, UpdateItemHook } from '../types/cart'
import { handler as removeItemHandler } from './use-remove-item' import { handler as removeItemHandler } from './use-remove-item'
import useCart from './use-cart' import useCart from './use-cart'
@ -18,7 +18,7 @@ export default useUpdateItem as UseUpdateItem<typeof handler>
export const handler = { export const handler = {
fetchOptions: { fetchOptions: {
url: '/api/bigcommerce/cart', url: '/api/cart',
method: 'PUT', method: 'PUT',
}, },
async fetcher({ async fetcher({

View File

@ -8,7 +8,7 @@ export default useWishlist as UseWishlist<typeof handler>
export const handler: SWRHook<GetWishlistHook> = { export const handler: SWRHook<GetWishlistHook> = {
fetchOptions: { fetchOptions: {
url: '/api/bigcommerce/wishlist', url: '/api/wishlist',
method: 'GET', method: 'GET',
}, },
async fetcher({ input: { customerId, includeProducts }, options, fetch }) { async fetcher({ input: { customerId, includeProducts }, options, fetch }) {

View File

@ -149,7 +149,7 @@ export const handler: SWRHook<
{ isEmpty?: boolean } { isEmpty?: boolean }
> = { > = {
fetchOptions: { fetchOptions: {
url: '/api/bigcommerce/cart', url: '/api/cart',
method: 'GET', method: 'GET',
}, },
async fetcher({ input: { cartId }, options, fetch }) { async fetcher({ input: { cartId }, options, fetch }) {
@ -197,7 +197,7 @@ export default useAddItem as UseAddItem<typeof handler>
export const handler: MutationHook<Cart, {}, CartItemBody> = { export const handler: MutationHook<Cart, {}, CartItemBody> = {
fetchOptions: { fetchOptions: {
url: '/api/bigcommerce/cart', url: '/api/cart',
method: 'POST', method: 'POST',
}, },
async fetcher({ input: item, options, fetch }) { async fetcher({ input: item, options, fetch }) {

View File

@ -43,12 +43,9 @@ export type HookFetcherFn<H extends HookSchemaBase> = (
export type HookFetcherContext<H extends HookSchemaBase> = { export type HookFetcherContext<H extends HookSchemaBase> = {
options: HookFetcherOptions options: HookFetcherOptions
input: H['fetchInput'] input: H['fetchInput']
fetch: { fetch: <T = H['fetchData'], B = H['body']>(
( options: FetcherOptions<B>
options: FetcherOptions<H['body'] extends {} ? H['body'] : never> ) => Promise<T>
): Promise<H['fetchData'] extends {} | null ? H['fetchData'] : any>
<T = any, B = any>(options: FetcherOptions<B>): Promise<T>
}
} }
export type HookFetcherOptions = { method?: string } & ( export type HookFetcherOptions = { method?: string } & (

View File

@ -18,13 +18,13 @@ module.exports = withCommerceConfig({
return [ return [
(isBC || isShopify) && { (isBC || isShopify) && {
source: '/checkout', source: '/checkout',
destination: '/api/bigcommerce/checkout', destination: '/api/checkout',
}, },
// The logout is also an action so this route is not required, but it's also another way // The logout is also an action so this route is not required, but it's also another way
// you can allow a logout! // you can allow a logout!
isBC && { isBC && {
source: '/logout', source: '/logout',
destination: '/api/bigcommerce/customers/logout?redirect_to=/', destination: '/api/logout?redirect_to=/',
}, },
// Rewrites for /search // Rewrites for /search
{ {