mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 05:31:22 +00:00
Removed many testing types
This commit is contained in:
parent
fed3c82c69
commit
e6df8dfb40
@ -1,4 +1,4 @@
|
||||
import { EndpointSchema, GetAPISchema } from '@commerce/api'
|
||||
import { GetAPISchema } from '@commerce/api'
|
||||
import getCart from './get-cart'
|
||||
import addItem from './add-item'
|
||||
import updateItem from './handlers/update-item'
|
||||
|
@ -2,11 +2,9 @@ import type { RequestInit } from '@vercel/fetch'
|
||||
import {
|
||||
CommerceAPI as CoreCommerceAPI,
|
||||
CommerceAPIConfig,
|
||||
GetEndpointsSchema,
|
||||
} from '@commerce/api'
|
||||
import fetchGraphqlApi from './utils/fetch-graphql-api'
|
||||
import fetchStoreApi from './utils/fetch-store-api'
|
||||
import { CartEndpointSchema } from './cart'
|
||||
|
||||
export interface BigcommerceConfig extends CommerceAPIConfig {
|
||||
// Indicates if the returned metadata with translations should be applied to the
|
||||
@ -106,8 +104,6 @@ export const provider = {
|
||||
|
||||
export type Provider = typeof provider
|
||||
|
||||
export type EndpointsSchema = { cart: CartEndpointSchema }
|
||||
|
||||
export class CommerceAPI<
|
||||
P extends Provider = Provider
|
||||
> extends CoreCommerceAPI<P> {
|
||||
@ -116,11 +112,6 @@ export class CommerceAPI<
|
||||
}
|
||||
}
|
||||
|
||||
export type CommerceAPIEndpoints = GetEndpointsSchema<
|
||||
CommerceAPI,
|
||||
EndpointsSchema
|
||||
>
|
||||
|
||||
export function getConfig(userConfig?: Partial<BigcommerceConfig>) {
|
||||
return config.getConfig(userConfig)
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
import type { APIEndpoint } from '../utils/types'
|
||||
import { CommerceAPIError } from '../utils/errors'
|
||||
import isAllowedOperation from '../utils/is-allowed-operation'
|
||||
import type { GetAPISchema, CommerceAPI, CartSchema } from '..'
|
||||
import type { GetAPISchema, CartSchema } from '..'
|
||||
|
||||
const cartApi: GetAPISchema<
|
||||
CommerceAPI,
|
||||
CartSchema
|
||||
>['endpoint']['handler'] = async (ctx) => {
|
||||
const cartApi: GetAPISchema<any, CartSchema>['endpoint']['handler'] = async (
|
||||
ctx
|
||||
) => {
|
||||
const { req, res, handlers, config } = ctx
|
||||
|
||||
if (
|
||||
@ -20,6 +19,7 @@ const cartApi: GetAPISchema<
|
||||
return
|
||||
}
|
||||
|
||||
const body2 = req.body
|
||||
const { cookies } = req
|
||||
const cartId = cookies[config.cartCookie]
|
||||
|
||||
|
@ -3,49 +3,6 @@ import type { RequestInit, Response } from '@vercel/fetch'
|
||||
import type { APIEndpoint, APIHandler } from './utils/types'
|
||||
import type { Cart } from '../types'
|
||||
|
||||
export type CartEndpoint = APIEndpoint<any, any, CartHandlers<CommerceAPI>, any>
|
||||
|
||||
export type CartHandlersBase<C extends CommerceAPI> = {
|
||||
getCart: APIHandler<
|
||||
any,
|
||||
CartHandlersBase<C>,
|
||||
Cart | null,
|
||||
any,
|
||||
{ yay: string }
|
||||
>
|
||||
addItem: APIHandler<any, CartHandlersBase<C>, Cart, any>
|
||||
updateItem: APIHandler<any, CartHandlersBase<C>, Cart, any>
|
||||
removeItem: APIHandler<any, CartHandlersBase<C>, Cart, any>
|
||||
}
|
||||
|
||||
export type CartHandlers<
|
||||
C extends CommerceAPI,
|
||||
T extends CartHandlersBase<C> = CartHandlersBase<C>
|
||||
> = T
|
||||
|
||||
export type CartHandlersType = {
|
||||
getCart: { data: Cart | null; body: any; options: {} }
|
||||
addItem: { data: Cart; body: any; options: {} }
|
||||
updateItem: { data: Cart; body: any; options: {} }
|
||||
removeItem: { data: Cart; body: any; options: {} }
|
||||
}
|
||||
|
||||
export type CartHandlers2<
|
||||
C extends CommerceAPI,
|
||||
T extends CartHandlersType = CartHandlersType
|
||||
> = {
|
||||
getCart: APIHandler<
|
||||
any,
|
||||
CartHandlersBase<C>,
|
||||
Cart | null,
|
||||
any,
|
||||
{ yay: string }
|
||||
>
|
||||
addItem: APIHandler<any, CartHandlersBase<C>, Cart, any>
|
||||
updateItem: APIHandler<any, CartHandlersBase<C>, Cart, any>
|
||||
removeItem: APIHandler<any, CartHandlersBase<C>, Cart, any>
|
||||
}
|
||||
|
||||
export type CartSchema = {
|
||||
endpoint: {
|
||||
options: {}
|
||||
@ -65,10 +22,10 @@ export type GetAPISchema<
|
||||
S extends APISchemas = APISchemas
|
||||
> = {
|
||||
schema: S
|
||||
endpoint: EndpointContext2<C, S['endpoint']>
|
||||
endpoint: EndpointContext<C, S['endpoint']>
|
||||
}
|
||||
|
||||
export type EndpointContext2<
|
||||
export type EndpointContext<
|
||||
C extends CommerceAPI,
|
||||
E extends EndpointSchemaBase
|
||||
> = {
|
||||
@ -76,31 +33,6 @@ export type EndpointContext2<
|
||||
operations: EndpointHandlers<C, E>
|
||||
}
|
||||
|
||||
export type EndpointsSchema = {
|
||||
cart?: {
|
||||
options: {}
|
||||
operations: {
|
||||
getCart: { data?: Cart | null; body?: any }
|
||||
addItem: { data?: Cart; body?: any }
|
||||
updateItem: { data?: Cart; body?: any }
|
||||
removeItem: { data?: Cart; body?: any }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type GetEndpointsSchema<
|
||||
C extends CommerceAPI,
|
||||
Schema extends EndpointsSchema
|
||||
> = {
|
||||
[E in keyof EndpointsSchema]-?: {
|
||||
schema: Schema[E]
|
||||
} & EndpointContext<C, NonNullable<Schema[E]>>
|
||||
}
|
||||
|
||||
export type GetEndpointsFromSchema<T> = T[keyof T] extends { endpoint: infer E }
|
||||
? E
|
||||
: never
|
||||
|
||||
export type EndpointSchemaBase = {
|
||||
options: {}
|
||||
operations: {
|
||||
@ -108,24 +40,10 @@ export type EndpointSchemaBase = {
|
||||
}
|
||||
}
|
||||
|
||||
export type OperationData<T> = T extends { data?: infer D; body?: any }
|
||||
? D
|
||||
: never
|
||||
|
||||
export type EndpointSchema<
|
||||
E extends keyof EndpointsSchema,
|
||||
Handlers extends EndpointsSchema[E]
|
||||
> = Handlers
|
||||
|
||||
export type Endpoint<
|
||||
C extends CommerceAPI,
|
||||
E extends EndpointSchemaBase
|
||||
> = APIEndpoint<
|
||||
C,
|
||||
EndpointHandlers<C, E>,
|
||||
OperationData<E['operations'][keyof E['operations']]>,
|
||||
E['options']
|
||||
>
|
||||
> = APIEndpoint<C, EndpointHandlers<C, E>, any, E['options']>
|
||||
|
||||
export type EndpointHandlers<
|
||||
C extends CommerceAPI,
|
||||
@ -140,26 +58,10 @@ export type EndpointHandlers<
|
||||
>
|
||||
}
|
||||
|
||||
export type HandlerOperations<E> = E extends APIEndpoint<any, any, infer T>
|
||||
? T
|
||||
: never
|
||||
|
||||
export type HandlerOptions<E> = E extends APIEndpoint<any, any, any, infer T>
|
||||
? T
|
||||
: never
|
||||
|
||||
export type APIProvider = {
|
||||
config: CommerceAPIConfig
|
||||
}
|
||||
|
||||
export type EndpointContext<
|
||||
C extends CommerceAPI,
|
||||
E extends EndpointSchemaBase
|
||||
> = {
|
||||
endpoint: Endpoint<C, E>
|
||||
operations: EndpointHandlers<C, E>
|
||||
}
|
||||
|
||||
export class CommerceAPI<P extends APIProvider = APIProvider> {
|
||||
constructor(readonly provider: P) {
|
||||
this.provider = provider
|
||||
|
Loading…
x
Reference in New Issue
Block a user