mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 13:41:22 +00:00
Removed commerce.endpoint
This commit is contained in:
parent
6af5794ac5
commit
9347c1cc21
@ -1,4 +1,5 @@
|
|||||||
import type { GetAPISchema } from '@commerce/api'
|
import { GetAPISchema, createEndpoint } from '@commerce/api'
|
||||||
|
import wishlist from '@commerce/api/endpoints/wishlist'
|
||||||
import type { WishlistSchema } from '../../../types/wishlist'
|
import type { WishlistSchema } from '../../../types/wishlist'
|
||||||
import type { BigcommerceAPI } from '../..'
|
import type { BigcommerceAPI } from '../..'
|
||||||
import getWishlist from './get-wishlist'
|
import getWishlist from './get-wishlist'
|
||||||
@ -9,4 +10,15 @@ export type WishlistAPI = GetAPISchema<BigcommerceAPI, WishlistSchema>
|
|||||||
|
|
||||||
export type WishlistEndpoint = WishlistAPI['endpoint']
|
export type WishlistEndpoint = WishlistAPI['endpoint']
|
||||||
|
|
||||||
export const handlers = { getWishlist, addItem, removeItem }
|
export const handlers: WishlistEndpoint['handlers'] = {
|
||||||
|
getWishlist,
|
||||||
|
addItem,
|
||||||
|
removeItem,
|
||||||
|
}
|
||||||
|
|
||||||
|
const wishlistEndpoint = createEndpoint({
|
||||||
|
handler: wishlist as WishlistAPI['endpoint']['handler'],
|
||||||
|
handlers,
|
||||||
|
})
|
||||||
|
|
||||||
|
export default wishlistEndpoint
|
||||||
|
@ -134,19 +134,8 @@ export type BigcommerceAPI<P extends Provider = Provider> = CommerceAPI<P>
|
|||||||
|
|
||||||
export function getCommerceApi<P extends Provider>(
|
export function getCommerceApi<P extends Provider>(
|
||||||
customProvider: P = provider as any
|
customProvider: P = provider as any
|
||||||
) {
|
): BigcommerceAPI<P> {
|
||||||
const api: BigcommerceAPI<P> = commerceApi(customProvider)
|
return commerceApi(customProvider)
|
||||||
|
|
||||||
return Object.assign(api, {
|
|
||||||
endpoint<E extends APIs>(
|
|
||||||
context: E['endpoint'] & {
|
|
||||||
config?: P['config']
|
|
||||||
options?: E['schema']['endpoint']['options']
|
|
||||||
}
|
|
||||||
): NextApiHandler {
|
|
||||||
return getEndpoint(api, context)
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getConfig(userConfig?: Partial<BigcommerceConfig>) {
|
export function getConfig(userConfig?: Partial<BigcommerceConfig>) {
|
||||||
|
@ -132,6 +132,18 @@ export function getEndpoint<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const createEndpoint = <API extends GetAPISchema<any, any>>(
|
||||||
|
endpoint: API['endpoint']
|
||||||
|
) => <P extends APIProvider>(
|
||||||
|
commerce: CommerceAPI<P>,
|
||||||
|
context?: Partial<API['endpoint']> & {
|
||||||
|
config?: P['config']
|
||||||
|
options?: API['schema']['endpoint']['options']
|
||||||
|
}
|
||||||
|
): NextApiHandler => {
|
||||||
|
return getEndpoint(commerce, { ...endpoint, ...context })
|
||||||
|
}
|
||||||
|
|
||||||
export interface CommerceAPIConfig {
|
export interface CommerceAPIConfig {
|
||||||
locale?: string
|
locale?: string
|
||||||
commerceUrl: string
|
commerceUrl: string
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
import wishlist from '@commerce/api/endpoints/wishlist'
|
import wishlistEndpoint from '@framework/api/endpoints/wishlist'
|
||||||
import { WishlistAPI, handlers } from '@framework/api/endpoints/wishlist'
|
|
||||||
import commerce from '@lib/api/commerce'
|
import commerce from '@lib/api/commerce'
|
||||||
|
|
||||||
export default commerce.endpoint({
|
export default wishlistEndpoint(commerce)
|
||||||
handler: wishlist as WishlistAPI['endpoint']['handler'],
|
|
||||||
handlers,
|
|
||||||
})
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user