Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,32 @@ export const createClient = (config: { baseUrl?: string, auth?: AuthConfig } = {
baseUrl: config.baseUrl || 'https://{environment}.example.com/v{version}',
middleware
}, {
/**
* Product catalog operations
*
* Endpoints for managing products in the store.
*/
'products': {
/**
* List products
*
* Retrieve a paginated list of products with filtering options.
*/
'GET': f.builder().def_json().def_searchparams(z.object({ category: z.enum(['electronics', 'clothing', 'books']).optional(), priceRange: z.array(z.number()).optional(), page: z.number().int().min(1).optional(), limit: z.number().int().min(1).max(100).optional(), sort: z.record(z.string(), z.enum(['asc', 'desc'])).optional() }).parse).def_response(async ({ json }) => z.array(Model.Product).parse(await json())),
/**
* Create a new product
*
* Add a new product to the catalog. Supports different product types via polymorphism.
*/
'POST': f.builder().def_json().def_body(Model.Product.parse).def_response(async ({ json }) => Model.Product.parse(await json()))
},
'orders': {
'$orderId': {
/**
* Get order details
*
* Retrieve details of a specific order.
*/
'GET': f.builder().def_json().def_response(async ({ json }) => Model.Order.parse(await json()))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,35 @@ export const createClient = (config: { baseUrl?: string, auth?: AuthConfig } = {
baseUrl: config.baseUrl || 'https://{environment}.example-commerce.com/api/v2',
middleware
}, {
/**
* Product Collection
*
* Endpoint for searching and creating products.
*/
'products': {
/**
* Search and filter products
*/
'GET': f.builder().def_json().def_searchparams(z.object({ searchQuery: z.string().optional(), tags: z.array(z.string()).optional(), page: z.number().int().min(1).optional() }).parse).def_response(async ({ json }) => Model.PaginatedProductResponse.parse(await json())),
/**
* Add a new product with an image
*/
'POST': f.builder().def_json().def_body(z.instanceof(FormData).parse).def_response(async ({ json }) => Model.Product.parse(await json())),
'$productId': {
/**
* Get a single product by its ID
*/
'GET': f.builder().def_json().def_response(async ({ json }) => Model.Product.parse(await json()))
}
},
'orders': {
'$orderId': {
'process': {
/**
* Process an order asynchronously
*
* Begins processing an order. A callback URL is invoked upon completion.
*/
'POST': f.builder().def_json()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@ export const createClient = (config: { baseUrl?: string, auth?: AuthConfig } = {
middleware
}, {
'books': {
/**
* Get a list of books
*/
'GET': f.builder().def_json().def_response(async ({ json }) => z.array(Model.Book).parse(await json())),
/**
* Create a new book
*/
'POST': f.builder().def_json().def_body(Model.BookRequest.parse).def_response(async ({ json }) => Model.Book.parse(await json())),
'$id': {
/**
* Get a book by ID
*/
'GET': f.builder().def_json().def_response(async ({ json }) => Model.Book.parse(await json()))
}
}
Expand Down
Loading
Loading