UNPKG

@simpleapps-com/augur-api

Version:

TypeScript client library for Augur microservices API endpoints

135 lines 5.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createProductsResource = createProductsResource; exports.createProductsDataResource = createProductsDataResource; const zod_1 = require("zod"); const schemas_1 = require("../schemas"); /** * Creates the products resource methods * OpenAPI Path: /products → products.* * @description Methods for CRUD operations on products and product search functionality */ 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: schemas_1.ProductListParamsSchema, responseSchema: schemas_1.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: schemas_1.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: schemas_1.UpdateProductRequestSchema, responseSchema: schemas_1.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: zod_1.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: schemas_1.EnableProductRequestSchema, responseSchema: schemas_1.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: schemas_1.ProductFindParamsSchema, responseSchema: schemas_1.ProductFindResponseSchema, }, params); }, }, }; return resource; } /** * Creates the productsData resource methods (data-only versions) */ 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