mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 13:41:22 +00:00
Merge branch 'nodejs-provider' of https://github.com/vercel/commerce into shopify-updates
This commit is contained in:
commit
55fa2fdd81
@ -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 }) {
|
||||||
|
@ -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 }) => () => {
|
||||||
|
@ -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({
|
||||||
|
@ -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 }) {
|
||||||
|
@ -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) => {
|
||||||
|
@ -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({
|
||||||
|
@ -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({
|
||||||
|
@ -23,9 +23,9 @@ export const handler: SWRHook<SearchProductsHook> = {
|
|||||||
|
|
||||||
if (search) url.searchParams.set('search', search)
|
if (search) url.searchParams.set('search', search)
|
||||||
if (Number.isInteger(categoryId))
|
if (Number.isInteger(categoryId))
|
||||||
url.searchParams.set('category', String(categoryId))
|
url.searchParams.set('categoryId', String(categoryId))
|
||||||
if (Number.isInteger(brandId))
|
if (Number.isInteger(brandId))
|
||||||
url.searchParams.set('brand', String(brandId))
|
url.searchParams.set('brandId', String(brandId))
|
||||||
if (sort) url.searchParams.set('sort', sort)
|
if (sort) url.searchParams.set('sort', sort)
|
||||||
|
|
||||||
return fetch({
|
return fetch({
|
||||||
|
@ -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 }) {
|
||||||
|
@ -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 }) {
|
||||||
|
@ -111,14 +111,14 @@ export type CartHooks<T extends CartTypes = CartTypes> = {
|
|||||||
export type GetCartHook<T extends CartTypes = CartTypes> = {
|
export type GetCartHook<T extends CartTypes = CartTypes> = {
|
||||||
data: T['cart'] | null
|
data: T['cart'] | null
|
||||||
input: {}
|
input: {}
|
||||||
fetchInput: { cartId?: string }
|
fetcherInput: { cartId?: string }
|
||||||
swrState: { isEmpty: boolean }
|
swrState: { isEmpty: boolean }
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AddItemHook<T extends CartTypes = CartTypes> = {
|
export type AddItemHook<T extends CartTypes = CartTypes> = {
|
||||||
data: T['cart']
|
data: T['cart']
|
||||||
input: T['itemBody']
|
input?: T['itemBody']
|
||||||
fetchInput: T['itemBody']
|
fetcherInput: T['itemBody']
|
||||||
body: { item: T['itemBody'] }
|
body: { item: T['itemBody'] }
|
||||||
actionInput: T['itemBody']
|
actionInput: T['itemBody']
|
||||||
}
|
}
|
||||||
@ -126,15 +126,15 @@ export type AddItemHook<T extends CartTypes = CartTypes> = {
|
|||||||
export type UpdateItemHook<T extends CartTypes = CartTypes> = {
|
export type UpdateItemHook<T extends CartTypes = CartTypes> = {
|
||||||
data: T['cart'] | null
|
data: T['cart'] | null
|
||||||
input: { item?: T['item']; wait?: number }
|
input: { item?: T['item']; wait?: number }
|
||||||
fetchInput: { itemId: string; item: T['itemBody'] }
|
fetcherInput: { itemId: string; item: T['itemBody'] }
|
||||||
body: { itemId: string; item?: T['itemBody'] }
|
body: { itemId: string; item: T['itemBody'] }
|
||||||
actionInput: T['itemBody'] & { id: string }
|
actionInput: T['itemBody'] & { id: string }
|
||||||
}
|
}
|
||||||
|
|
||||||
export type RemoveItemHook<T extends CartTypes = CartTypes> = {
|
export type RemoveItemHook<T extends CartTypes = CartTypes> = {
|
||||||
data: T['cart'] | null
|
data: T['cart'] | null
|
||||||
input: { item?: T['item'] }
|
input: { item?: T['item'] }
|
||||||
fetchInput: { itemId: string }
|
fetcherInput: { itemId: string }
|
||||||
body: { itemId: string }
|
body: { itemId: string }
|
||||||
actionInput: { id: string }
|
actionInput: { id: string }
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ export type CustomerTypes = {
|
|||||||
export type CustomerHook<T extends CustomerTypes = CustomerTypes> = {
|
export type CustomerHook<T extends CustomerTypes = CustomerTypes> = {
|
||||||
data: T['customer'] | null
|
data: T['customer'] | null
|
||||||
fetchData: { customer: T['customer'] } | null
|
fetchData: { customer: T['customer'] } | null
|
||||||
// actionInput: T['body']
|
|
||||||
// fetchInput: T['body']
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CustomerSchema<T extends CustomerTypes = CustomerTypes> = {
|
export type CustomerSchema<T extends CustomerTypes = CustomerTypes> = {
|
||||||
|
@ -10,7 +10,7 @@ export type LoginTypes = {
|
|||||||
export type LoginHook<T extends LoginTypes = LoginTypes> = {
|
export type LoginHook<T extends LoginTypes = LoginTypes> = {
|
||||||
data: null
|
data: null
|
||||||
actionInput: LoginBody
|
actionInput: LoginBody
|
||||||
fetchInput: LoginBody
|
fetcherInput: LoginBody
|
||||||
body: T['body']
|
body: T['body']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,20 +65,14 @@ export type SearchProductsHook<T extends ProductTypes = ProductTypes> = {
|
|||||||
}
|
}
|
||||||
body: T['searchBody']
|
body: T['searchBody']
|
||||||
input: T['searchBody']
|
input: T['searchBody']
|
||||||
fetchInput: T['searchBody']
|
fetcherInput: T['searchBody']
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ProductsSchema<T extends ProductTypes = ProductTypes> = {
|
export type ProductsSchema<T extends ProductTypes = ProductTypes> = {
|
||||||
endpoint: {
|
endpoint: {
|
||||||
options: {}
|
options: {}
|
||||||
handlers: {
|
handlers: {
|
||||||
getProducts: {
|
getProducts: SearchProductsHook<T>
|
||||||
data: {
|
|
||||||
products: T['product'][]
|
|
||||||
found: boolean
|
|
||||||
}
|
|
||||||
body: SearchProductsHook<T>['body']
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ export type SignupHook<T extends SignupTypes = SignupTypes> = {
|
|||||||
data: null
|
data: null
|
||||||
body: T['body']
|
body: T['body']
|
||||||
actionInput: T['body']
|
actionInput: T['body']
|
||||||
fetchInput: T['body']
|
fetcherInput: T['body']
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SignupSchema<T extends SignupTypes = SignupTypes> = {
|
export type SignupSchema<T extends SignupTypes = SignupTypes> = {
|
||||||
|
@ -15,21 +15,21 @@ export type GetWishlistHook<T extends WishlistTypes = WishlistTypes> = {
|
|||||||
data: T['wishlist'] | null
|
data: T['wishlist'] | null
|
||||||
body: { includeProducts?: boolean }
|
body: { includeProducts?: boolean }
|
||||||
input: { includeProducts?: boolean }
|
input: { includeProducts?: boolean }
|
||||||
fetchInput: { customerId: string; includeProducts?: boolean }
|
fetcherInput: { customerId: string; includeProducts?: boolean }
|
||||||
swrState: { isEmpty: boolean }
|
swrState: { isEmpty: boolean }
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AddItemHook<T extends WishlistTypes = WishlistTypes> = {
|
export type AddItemHook<T extends WishlistTypes = WishlistTypes> = {
|
||||||
data: T['wishlist']
|
data: T['wishlist']
|
||||||
body: { item: T['itemBody'] }
|
body: { item: T['itemBody'] }
|
||||||
fetchInput: { item: T['itemBody'] }
|
fetcherInput: { item: T['itemBody'] }
|
||||||
actionInput: T['itemBody']
|
actionInput: T['itemBody']
|
||||||
}
|
}
|
||||||
|
|
||||||
export type RemoveItemHook<T extends WishlistTypes = WishlistTypes> = {
|
export type RemoveItemHook<T extends WishlistTypes = WishlistTypes> = {
|
||||||
data: T['wishlist'] | null
|
data: T['wishlist'] | null
|
||||||
body: { itemId: string }
|
body: { itemId: string }
|
||||||
fetchInput: { itemId: string }
|
fetcherInput: { itemId: string }
|
||||||
actionInput: { id: string }
|
actionInput: { id: string }
|
||||||
input: { wishlist?: { includeProducts?: boolean } }
|
input: { wishlist?: { includeProducts?: boolean } }
|
||||||
}
|
}
|
||||||
|
@ -42,13 +42,13 @@ 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['fetcherInput']
|
||||||
fetch: {
|
fetch: <
|
||||||
(
|
T = H['fetchData'] extends {} | null ? H['fetchData'] : any,
|
||||||
options: FetcherOptions<H['body'] extends {} ? H['body'] : never>
|
B = H['body']
|
||||||
): Promise<H['fetchData'] extends {} | null ? H['fetchData'] : any>
|
>(
|
||||||
<T = any, B = any>(options: FetcherOptions<B>): Promise<T>
|
options: FetcherOptions<B>
|
||||||
}
|
) => Promise<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type HookFetcherOptions = { method?: string } & (
|
export type HookFetcherOptions = { method?: string } & (
|
||||||
@ -77,7 +77,7 @@ export type HookSchemaBase = {
|
|||||||
// Input expected by the hook
|
// Input expected by the hook
|
||||||
input?: {}
|
input?: {}
|
||||||
// Input expected before doing a fetch operation (aka fetch handler)
|
// Input expected before doing a fetch operation (aka fetch handler)
|
||||||
fetchInput?: {}
|
fetcherInput?: {}
|
||||||
// Body object expected by the fetch operation
|
// Body object expected by the fetch operation
|
||||||
body?: {}
|
body?: {}
|
||||||
// Data returned by the fetch operation
|
// Data returned by the fetch operation
|
||||||
@ -101,7 +101,7 @@ export type SWRHook<H extends SWRHookSchemaBase> = {
|
|||||||
useHook(
|
useHook(
|
||||||
context: SWRHookContext<H>
|
context: SWRHookContext<H>
|
||||||
): HookFunction<
|
): HookFunction<
|
||||||
H['input'] & { swrOptions?: SwrOptions<H['data'], H['fetchInput']> },
|
H['input'] & { swrOptions?: SwrOptions<H['data'], H['fetcherInput']> },
|
||||||
ResponseState<H['data']> & H['swrState']
|
ResponseState<H['data']> & H['swrState']
|
||||||
>
|
>
|
||||||
fetchOptions: HookFetcherOptions
|
fetchOptions: HookFetcherOptions
|
||||||
@ -111,7 +111,7 @@ export type SWRHook<H extends SWRHookSchemaBase> = {
|
|||||||
export type SWRHookContext<H extends SWRHookSchemaBase> = {
|
export type SWRHookContext<H extends SWRHookSchemaBase> = {
|
||||||
useData(context?: {
|
useData(context?: {
|
||||||
input?: HookFetchInput | HookSWRInput
|
input?: HookFetchInput | HookSWRInput
|
||||||
swrOptions?: SwrOptions<H['data'], H['fetchInput']>
|
swrOptions?: SwrOptions<H['data'], H['fetcherInput']>
|
||||||
}): ResponseState<H['data']>
|
}): ResponseState<H['data']>
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,11 +130,13 @@ export type MutationHook<H extends MutationSchemaBase> = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type MutationHookContext<H extends MutationSchemaBase> = {
|
export type MutationHookContext<H extends MutationSchemaBase> = {
|
||||||
fetch: keyof H['fetchInput'] extends never
|
fetch: keyof H['fetcherInput'] extends never
|
||||||
? () => H['data'] | Promise<H['data']>
|
? () => H['data'] | Promise<H['data']>
|
||||||
: Partial<H['fetchInput']> extends H['fetchInput']
|
: Partial<H['fetcherInput']> extends H['fetcherInput']
|
||||||
? (context?: { input?: H['fetchInput'] }) => H['data'] | Promise<H['data']>
|
? (context?: {
|
||||||
: (context: { input: H['fetchInput'] }) => H['data'] | Promise<H['data']>
|
input?: H['fetcherInput']
|
||||||
|
}) => H['data'] | Promise<H['data']>
|
||||||
|
: (context: { input: H['fetcherInput'] }) => H['data'] | Promise<H['data']>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SwrOptions<Data, Input = null, Result = any> = ConfigInterface<
|
export type SwrOptions<Data, Input = null, Result = any> = ConfigInterface<
|
||||||
|
@ -22,7 +22,7 @@ export type UseData = <H extends SWRHookSchemaBase>(
|
|||||||
},
|
},
|
||||||
input: HookFetchInput | HookSWRInput,
|
input: HookFetchInput | HookSWRInput,
|
||||||
fetcherFn: Fetcher,
|
fetcherFn: Fetcher,
|
||||||
swrOptions?: SwrOptions<H['data'], H['fetchInput']>
|
swrOptions?: SwrOptions<H['data'], H['fetcherInput']>
|
||||||
) => ResponseState<H['data']>
|
) => ResponseState<H['data']>
|
||||||
|
|
||||||
const useData: UseData = (options, input, fetcherFn, swrOptions) => {
|
const useData: UseData = (options, input, fetcherFn, swrOptions) => {
|
||||||
|
@ -24,7 +24,7 @@ module.exports = withCommerceConfig({
|
|||||||
// 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
|
||||||
{
|
{
|
||||||
|
@ -6,6 +6,7 @@ import { useRouter } from 'next/router'
|
|||||||
|
|
||||||
import { Layout } from '@components/common'
|
import { Layout } from '@components/common'
|
||||||
import { ProductCard } from '@components/product'
|
import { ProductCard } from '@components/product'
|
||||||
|
import type { Product } from '@commerce/types/product'
|
||||||
import { Container, Grid, Skeleton } from '@components/ui'
|
import { Container, Grid, Skeleton } from '@components/ui'
|
||||||
|
|
||||||
import useSearch from '@framework/product/use-search'
|
import useSearch from '@framework/product/use-search'
|
||||||
@ -19,8 +20,6 @@ import {
|
|||||||
useSearchMeta,
|
useSearchMeta,
|
||||||
} from '@lib/search'
|
} from '@lib/search'
|
||||||
|
|
||||||
import type { Product } from '@commerce/types/product'
|
|
||||||
|
|
||||||
// TODO(bc) Remove this. This should come from the API
|
// TODO(bc) Remove this. This should come from the API
|
||||||
import getSlug from '@lib/get-slug'
|
import getSlug from '@lib/get-slug'
|
||||||
|
|
||||||
@ -35,9 +34,8 @@ const SORT = Object.entries({
|
|||||||
export async function getStaticProps({
|
export async function getStaticProps({
|
||||||
preview,
|
preview,
|
||||||
locale,
|
locale,
|
||||||
locales,
|
|
||||||
}: GetStaticPropsContext) {
|
}: GetStaticPropsContext) {
|
||||||
const config = { locale, locales }
|
const config = { locale }
|
||||||
const { pages } = await commerce.getAllPages({ config, preview })
|
const { pages } = await commerce.getAllPages({ config, preview })
|
||||||
const { categories, brands } = await commerce.getSiteInfo({ config, preview })
|
const { categories, brands } = await commerce.getSiteInfo({ config, preview })
|
||||||
return {
|
return {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user