mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 05:31:22 +00:00
Renamed endpoint operations to handlers
This commit is contained in:
parent
6bcf9f9e75
commit
012f4b052f
@ -58,9 +58,9 @@ export type RemoveItemHook = CartHooks['removeItem']
|
|||||||
|
|
||||||
export type CartSchema = Core.CartSchema<CartTypes>
|
export type CartSchema = Core.CartSchema<CartTypes>
|
||||||
|
|
||||||
export type CartOperations = Core.CartOperations<CartTypes>
|
export type CartHandlers = Core.CartHandlers<CartTypes>
|
||||||
|
|
||||||
export type GetCartOperation = CartOperations['getCart']
|
export type GetCartHandler = CartHandlers['getCart']
|
||||||
export type AddItemOperation = CartOperations['addItem']
|
export type AddItemHandler = CartHandlers['addItem']
|
||||||
export type UpdateItemOperation = CartOperations['updateItem']
|
export type UpdateItemHandler = CartHandlers['updateItem']
|
||||||
export type RemoveItemOperation = CartOperations['removeItem']
|
export type RemoveItemHandler = CartHandlers['removeItem']
|
||||||
|
@ -33,12 +33,12 @@ export type EndpointContext<
|
|||||||
E extends EndpointSchemaBase
|
E extends EndpointSchemaBase
|
||||||
> = {
|
> = {
|
||||||
handler: Endpoint<C, E>
|
handler: Endpoint<C, E>
|
||||||
operations: EndpointHandlers<C, E>
|
handlers: EndpointHandlers<C, E>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EndpointSchemaBase = {
|
export type EndpointSchemaBase = {
|
||||||
options: {}
|
options: {}
|
||||||
operations: {
|
handlers: {
|
||||||
[k: string]: { data?: any; body?: any }
|
[k: string]: { data?: any; body?: any }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,11 +52,11 @@ export type EndpointHandlers<
|
|||||||
C extends CommerceAPI,
|
C extends CommerceAPI,
|
||||||
E extends EndpointSchemaBase
|
E extends EndpointSchemaBase
|
||||||
> = {
|
> = {
|
||||||
[H in keyof E['operations']]: APIHandler<
|
[H in keyof E['handlers']]: APIHandler<
|
||||||
C,
|
C,
|
||||||
EndpointHandlers<C, E>,
|
EndpointHandlers<C, E>,
|
||||||
E['operations'][H]['data'],
|
E['handlers'][H]['data'],
|
||||||
E['operations'][H]['body'],
|
E['handlers'][H]['body'],
|
||||||
E['options']
|
E['options']
|
||||||
>
|
>
|
||||||
}
|
}
|
||||||
@ -122,7 +122,7 @@ export function getEndpoint<
|
|||||||
res,
|
res,
|
||||||
commerce,
|
commerce,
|
||||||
config: cfg,
|
config: cfg,
|
||||||
operations: context.operations,
|
handlers: context.handlers,
|
||||||
options: context.options ?? {},
|
options: context.options ?? {},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ export type APIHandlerContext<
|
|||||||
res: NextApiResponse<APIResponse<Data>>
|
res: NextApiResponse<APIResponse<Data>>
|
||||||
commerce: C
|
commerce: C
|
||||||
config: C['provider']['config']
|
config: C['provider']['config']
|
||||||
operations: H
|
handlers: H
|
||||||
/**
|
/**
|
||||||
* Custom configs that may be used by a particular handler
|
* Custom configs that may be used by a particular handler
|
||||||
*/
|
*/
|
||||||
|
@ -136,37 +136,33 @@ export type RemoveItemHook<T extends CartTypes = CartTypes> = {
|
|||||||
export type CartSchema<T extends CartTypes = CartTypes> = {
|
export type CartSchema<T extends CartTypes = CartTypes> = {
|
||||||
endpoint: {
|
endpoint: {
|
||||||
options: {}
|
options: {}
|
||||||
operations: CartOperations<T>
|
handlers: CartHandlers<T>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CartOperations<T extends CartTypes = CartTypes> = {
|
export type CartHandlers<T extends CartTypes = CartTypes> = {
|
||||||
getCart: GetCartOperation<T>
|
getCart: GetCartHandler<T>
|
||||||
addItem: AddItemOperation<T>
|
addItem: AddItemHandler<T>
|
||||||
updateItem: UpdateItemOperation<T>
|
updateItem: UpdateItemHandler<T>
|
||||||
removeItem: RemoveItemOperation<T>
|
removeItem: RemoveItemHandler<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type GetCartOperation<
|
export type GetCartHandler<T extends CartTypes = CartTypes> = GetCartHook<T> & {
|
||||||
T extends CartTypes = CartTypes
|
|
||||||
> = GetCartHook<T> & {
|
|
||||||
body: { cartId?: string }
|
body: { cartId?: string }
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AddItemOperation<
|
export type AddItemHandler<T extends CartTypes = CartTypes> = AddItemHook<T> & {
|
||||||
T extends CartTypes = CartTypes
|
|
||||||
> = AddItemHook<T> & {
|
|
||||||
body: { cartId: string }
|
body: { cartId: string }
|
||||||
}
|
}
|
||||||
|
|
||||||
export type UpdateItemOperation<
|
export type UpdateItemHandler<
|
||||||
T extends CartTypes = CartTypes
|
T extends CartTypes = CartTypes
|
||||||
> = UpdateItemHook<T> & {
|
> = UpdateItemHook<T> & {
|
||||||
data: T['cart']
|
data: T['cart']
|
||||||
body: { cartId: string }
|
body: { cartId: string }
|
||||||
}
|
}
|
||||||
|
|
||||||
export type RemoveItemOperation<
|
export type RemoveItemHandler<
|
||||||
T extends CartTypes = CartTypes
|
T extends CartTypes = CartTypes
|
||||||
> = RemoveItemHook<T> & {
|
> = RemoveItemHook<T> & {
|
||||||
body: { cartId: string }
|
body: { cartId: string }
|
||||||
|
@ -8,16 +8,10 @@ export type CustomerTypes = {
|
|||||||
export type CustomerSchema<T extends CustomerTypes = CustomerTypes> = {
|
export type CustomerSchema<T extends CustomerTypes = CustomerTypes> = {
|
||||||
endpoint: {
|
endpoint: {
|
||||||
options: {}
|
options: {}
|
||||||
operations: {
|
handlers: {
|
||||||
getLoggedInCustomer: {
|
getLoggedInCustomer: {
|
||||||
data: { customer: T['customer'] } | null
|
data: { customer: T['customer'] } | null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// export type CustomerOperations<T extends CustomerTypes = CustomerTypes> = {
|
|
||||||
// getLoggedInCustomer: GetCartOperation<T>
|
|
||||||
// }
|
|
||||||
|
|
||||||
// export type GetLoggedInCustomerOperation = {}
|
|
||||||
|
@ -10,7 +10,7 @@ export type LoginTypes = {
|
|||||||
export type LoginSchema<T extends LoginTypes = LoginTypes> = {
|
export type LoginSchema<T extends LoginTypes = LoginTypes> = {
|
||||||
endpoint: {
|
endpoint: {
|
||||||
options: {}
|
options: {}
|
||||||
operations: {
|
handlers: {
|
||||||
login: {
|
login: {
|
||||||
data: null
|
data: null
|
||||||
body: T['body']
|
body: T['body']
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
export type LogoutSchema = {
|
export type LogoutSchema = {
|
||||||
endpoint: {
|
endpoint: {
|
||||||
options: {}
|
options: {}
|
||||||
operations: {
|
handlers: {
|
||||||
logout: {
|
logout: {
|
||||||
data: null
|
data: null
|
||||||
body: { redirectTo?: string }
|
body: { redirectTo?: string }
|
||||||
|
@ -12,7 +12,7 @@ export type SignupTypes = {
|
|||||||
export type SignupSchema<T extends SignupTypes = SignupTypes> = {
|
export type SignupSchema<T extends SignupTypes = SignupTypes> = {
|
||||||
endpoint: {
|
endpoint: {
|
||||||
options: {}
|
options: {}
|
||||||
operations: {
|
handlers: {
|
||||||
signup: {
|
signup: {
|
||||||
data: null
|
data: null
|
||||||
body: T['body']
|
body: T['body']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user