UNPKG

@simpleapps-com/augur-api

Version:

TypeScript client library for Augur microservices API endpoints

131 lines 5.38 kB
import { z } from 'zod'; import { ProductListParamsSchema, ProductListResponseSchema, ProductResponseSchema, ProductFindParamsSchema, ProductFindResponseSchema, UpdateProductRequestSchema, EnableProductRequestSchema, } from '../schemas'; /** * Creates the products resource methods * OpenAPI Path: /products → products.* * @description Methods for CRUD operations on products and product search functionality */ export function createProductsResource(executeRequest) { const resource = { /** * List products with filtering * @description Returns products for a customer and distributor with optional filtering and pagination * @param params Filtering and pagination parameters (customerId and distributorsUid are required) * @returns Array of product objects * @throws ValidationError When parameters are invalid or response is malformed */ list: async (params) => { return executeRequest({ method: 'GET', path: '/products', paramsSchema: ProductListParamsSchema, responseSchema: ProductListResponseSchema, }, params); }, /** * Get product details by ID * @description Returns detailed information for a specific product * @param productsUid Product unique identifier * @returns Product details * @throws ValidationError When response is malformed */ get: async (productsUid) => { return executeRequest({ method: 'GET', path: `/products/${productsUid}`, responseSchema: ProductResponseSchema, }, undefined); }, /** * Update product information * @description Updates product details with provided data * @param productsUid Product unique identifier * @param request Product update data * @returns Updated product information * @throws ValidationError When request is invalid or response is malformed */ update: async (productsUid, request) => { return executeRequest({ method: 'PUT', path: `/products/${productsUid}`, paramsSchema: UpdateProductRequestSchema, responseSchema: ProductResponseSchema, }, request); }, /** * Soft delete a product * @description Marks product as deleted without removing data * @param productsUid Product unique identifier * @returns Boolean indicating successful deletion * @throws ValidationError When response is malformed */ delete: async (productsUid) => { await executeRequest({ method: 'DELETE', path: `/products/${productsUid}`, responseSchema: z.unknown(), }); return true; }, /** * Enable, disable, or delete a product * @description Changes product status using status codes * @param productsUid Product unique identifier * @param request Status change request with new status code * @returns Updated product information * @throws ValidationError When request is invalid or response is malformed */ enable: async (productsUid, request) => { return executeRequest({ method: 'PUT', path: '/products/{productsUid}/enable', paramsSchema: EnableProductRequestSchema, responseSchema: ProductResponseSchema, }, request, { productsUid: String(productsUid) }); }, /** * Products find endpoints * @description Methods for searching products across VMI and Prophet 21 */ find: { /** * Search across both VMI products and Prophet 21 items * @description Searches both VMI custom products and Prophet 21 items with prefix matching * @param params Search parameters with customer ID and optional prefix filter * @returns Array of found items with type indicator (limited to 10 results) * @throws ValidationError When parameters are invalid or response is malformed */ get: async (params) => { return executeRequest({ method: 'GET', path: '/products/find', paramsSchema: ProductFindParamsSchema, responseSchema: ProductFindResponseSchema, }, params); }, }, }; return resource; } /** * Creates the productsData resource methods (data-only versions) */ export function createProductsDataResource(products) { return { list: async (params) => { const response = await products.list(params); return response.data; }, get: async (productsUid) => { const response = await products.get(productsUid); return response.data; }, find: { get: async (params) => { const response = await products.find.get(params); return response.data; }, }, }; } //# sourceMappingURL=products.js.map