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 CartOperations = Core.CartOperations<CartTypes>
|
||||
export type CartHandlers = Core.CartHandlers<CartTypes>
|
||||
|
||||
export type GetCartOperation = CartOperations['getCart']
|
||||
export type AddItemOperation = CartOperations['addItem']
|
||||
export type UpdateItemOperation = CartOperations['updateItem']
|
||||
export type RemoveItemOperation = CartOperations['removeItem']
|
||||
export type GetCartHandler = CartHandlers['getCart']
|
||||
export type AddItemHandler = CartHandlers['addItem']
|
||||
export type UpdateItemHandler = CartHandlers['updateItem']
|
||||
export type RemoveItemHandler = CartHandlers['removeItem']
|
||||
|
@ -33,12 +33,12 @@ export type EndpointContext<
|
||||
E extends EndpointSchemaBase
|
||||
> = {
|
||||
handler: Endpoint<C, E>
|
||||
operations: EndpointHandlers<C, E>
|
||||
handlers: EndpointHandlers<C, E>
|
||||
}
|
||||
|
||||
export type EndpointSchemaBase = {
|
||||
options: {}
|
||||
operations: {
|
||||
handlers: {
|
||||
[k: string]: { data?: any; body?: any }
|
||||
}
|
||||
}
|
||||
@ -52,11 +52,11 @@ export type EndpointHandlers<
|
||||
C extends CommerceAPI,
|
||||
E extends EndpointSchemaBase
|
||||
> = {
|
||||
[H in keyof E['operations']]: APIHandler<
|
||||
[H in keyof E['handlers']]: APIHandler<
|
||||
C,
|
||||
EndpointHandlers<C, E>,
|
||||
E['operations'][H]['data'],
|
||||
E['operations'][H]['body'],
|
||||
E['handlers'][H]['data'],
|
||||
E['handlers'][H]['body'],
|
||||
E['options']
|
||||
>
|
||||
}
|
||||
@ -122,7 +122,7 @@ export function getEndpoint<
|
||||
res,
|
||||
commerce,
|
||||
config: cfg,
|
||||
operations: context.operations,
|
||||
handlers: context.handlers,
|
||||
options: context.options ?? {},
|
||||
})
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ export type APIHandlerContext<
|
||||
res: NextApiResponse<APIResponse<Data>>
|
||||
commerce: C
|
||||
config: C['provider']['config']
|
||||
operations: H
|
||||
handlers: H
|
||||
/**
|
||||
* 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> = {
|
||||
endpoint: {
|
||||
options: {}
|
||||
operations: CartOperations<T>
|
||||
handlers: CartHandlers<T>
|
||||
}
|
||||
}
|
||||
|
||||
export type CartOperations<T extends CartTypes = CartTypes> = {
|
||||
getCart: GetCartOperation<T>
|
||||
addItem: AddItemOperation<T>
|
||||
updateItem: UpdateItemOperation<T>
|
||||
removeItem: RemoveItemOperation<T>
|
||||
export type CartHandlers<T extends CartTypes = CartTypes> = {
|
||||
getCart: GetCartHandler<T>
|
||||
addItem: AddItemHandler<T>
|
||||
updateItem: UpdateItemHandler<T>
|
||||
removeItem: RemoveItemHandler<T>
|
||||
}
|
||||
|
||||
export type GetCartOperation<
|
||||
T extends CartTypes = CartTypes
|
||||
> = GetCartHook<T> & {
|
||||
export type GetCartHandler<T extends CartTypes = CartTypes> = GetCartHook<T> & {
|
||||
body: { cartId?: string }
|
||||
}
|
||||
|
||||
export type AddItemOperation<
|
||||
T extends CartTypes = CartTypes
|
||||
> = AddItemHook<T> & {
|
||||
export type AddItemHandler<T extends CartTypes = CartTypes> = AddItemHook<T> & {
|
||||
body: { cartId: string }
|
||||
}
|
||||
|
||||
export type UpdateItemOperation<
|
||||
export type UpdateItemHandler<
|
||||
T extends CartTypes = CartTypes
|
||||
> = UpdateItemHook<T> & {
|
||||
data: T['cart']
|
||||
body: { cartId: string }
|
||||
}
|
||||
|
||||
export type RemoveItemOperation<
|
||||
export type RemoveItemHandler<
|
||||
T extends CartTypes = CartTypes
|
||||
> = RemoveItemHook<T> & {
|
||||
body: { cartId: string }
|
||||
|
@ -8,16 +8,10 @@ export type CustomerTypes = {
|
||||
export type CustomerSchema<T extends CustomerTypes = CustomerTypes> = {
|
||||
endpoint: {
|
||||
options: {}
|
||||
operations: {
|
||||
handlers: {
|
||||
getLoggedInCustomer: {
|
||||
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> = {
|
||||
endpoint: {
|
||||
options: {}
|
||||
operations: {
|
||||
handlers: {
|
||||
login: {
|
||||
data: null
|
||||
body: T['body']
|
||||
|
@ -1,7 +1,7 @@
|
||||
export type LogoutSchema = {
|
||||
endpoint: {
|
||||
options: {}
|
||||
operations: {
|
||||
handlers: {
|
||||
logout: {
|
||||
data: null
|
||||
body: { redirectTo?: string }
|
||||
|
@ -12,7 +12,7 @@ export type SignupTypes = {
|
||||
export type SignupSchema<T extends SignupTypes = SignupTypes> = {
|
||||
endpoint: {
|
||||
options: {}
|
||||
operations: {
|
||||
handlers: {
|
||||
signup: {
|
||||
data: null
|
||||
body: T['body']
|
||||
|
Loading…
x
Reference in New Issue
Block a user