UNPKG

@simpleapps-com/augur-api

Version:

TypeScript client library for Augur microservices API endpoints

473 lines 22.8 kB
import { BaseServiceClient } from '../../core/base-client'; import { // Health check schemas HealthCheckResponseSchema, // State management schemas StateListParamsSchema, StateGetParamsSchema, CreateStateRequestSchema, UpdateStateRequestSchema, StateListResponseSchema, StateResponseSchema, DeleteResponseSchema, // Inventory master schemas AlsoBoughtListResponseSchema, InvMastTagListResponseSchema, InvMastTagResponseSchema, CreateInvMastTagRequestSchema, UpdateInvMastTagRequestSchema, InvMastWebDescListResponseSchema, InvMastWebDescResponseSchema, CreateInvMastWebDescRequestSchema, UpdateInvMastWebDescRequestSchema, // Item category schemas ItemCategoryResponseSchema, // Order reset schemas OrderResetApiResponseSchema, } from './schemas'; /** * Legacy API Client * @description Client for interacting with Legacy microservice API endpoints for legacy data structures, state management, inventory operations, and order processing * @example * ```typescript * import { HTTPClient } from '@augur/api-client/core'; * import { LegacyClient } from '@augur/api-client/services/legacy'; * * const http = new HTTPClient('legacy', { siteId: 'your-site-id', bearerToken: 'your-token' }); * const legacy = new LegacyClient(http); * * // List states * const states = await legacy.states.list({ limit: 25, twoLetterCode: 'CA' }); * * // Get inventory tags * const tags = await legacy.invMast.tags.list(12345); * * // Reset order * const resetResult = await legacy.orders.reset(67890); * ``` */ export class LegacyClient extends BaseServiceClient { /** * Create a new LegacyClient instance * @param http Configured HTTPClient instance * @param baseUrl Base URL for the Legacy API (default: https://legacy.augur-api.com) */ constructor(http, baseUrl = 'https://legacy.augur-api.com') { super('legacy', http, baseUrl); /** * Health check endpoint * @description Service health monitoring (requires only x-site-id header, no bearer token) */ this.getHealthCheck = this.createHealthCheckMethod(HealthCheckResponseSchema); /** * State management endpoints * @description CRUD operations for US states and provinces with tax information */ this.states = { /** * List states with optional filtering and pagination * @description Retrieve a paginated list of states with optional filtering by two-letter code * @param params Optional filtering and pagination parameters * @returns Paginated list of state objects with tax information * @throws ValidationError When parameters are invalid or response is malformed * @example * ```typescript * // List all states * const allStates = await client.states.list(); * * // Filter by state code * const californiaStates = await client.states.list({ * twoLetterCode: 'CA', * limit: 10 * }); * * // Paginated results * const statesPage = await client.states.list({ * limit: 25, * offset: 50 * }); * ``` */ list: this.createListMethod('/legacy/state', StateListParamsSchema, StateListResponseSchema), /** * Get state details by UID * @description Retrieve complete details for a specific state including tax information * @param stateUid State unique identifier * @param params Optional query parameters * @returns Complete state object with tax and administrative information * @throws ValidationError When parameters are invalid or response is malformed * @example * ```typescript * // Get state by UID * const state = await client.states.get(1); * console.log(state.state_name, state.tax_rate); * * // Get with additional filtering * const state = await client.states.get(1, { twoLetterCode: 'CA' }); * ``` */ get: this.createGetMethod('/legacy/state/{id}', StateResponseSchema, StateGetParamsSchema), /** * Create a new state record * @description Add a new state or province to the system with tax configuration * @param stateData State information including name, code, and tax settings * @returns Created state object with assigned state_uid * @throws ValidationError When state data is invalid or response is malformed * @example * ```typescript * const newState = await client.states.create({ * country_uid: 1, * two_letter_code: 'TX', * state_name: 'Texas', * tax_rate: 0.0625, * active: 1, * tax_shipping: 0 * }); * console.log('Created state with UID:', newState.state_uid); * ``` */ create: this.createCreateMethod('/legacy/state', CreateStateRequestSchema, StateResponseSchema), /** * Update an existing state record * @description Modify state information including tax rates and administrative details * @param stateUid State unique identifier * @param stateData Updated state information (partial updates supported) * @returns Updated state object * @throws ValidationError When state data is invalid or response is malformed * @example * ```typescript * const updatedState = await client.states.update(1, { * state_name: 'California Updated', * tax_rate: 0.0925, * active: 1 * }); * ``` */ update: this.createUpdateMethod('/legacy/state/{id}', UpdateStateRequestSchema, StateResponseSchema), /** * Delete a state record * @description Remove a state from the system (use with caution) * @param stateUid State unique identifier * @returns Confirmation of deletion * @throws ValidationError When response is malformed * @example * ```typescript * const result = await client.states.delete(1); * console.log('State deleted:', result.deleted); * ``` */ delete: this.createDeleteMethod('/legacy/state/{id}', DeleteResponseSchema), }; /** * Inventory master operations * @description Operations for inventory items including also-bought analysis, tagging, and web descriptions */ this.invMast = { /** * Get products frequently bought with a specific item * @description Retrieve products commonly purchased together for recommendation systems * @param invMastUid Inventory master unique identifier * @returns Array of related products with relationship strength data * @throws ValidationError When response is malformed * @example * ```typescript * const alsoBought = await client.invMast.getAlsoBought(12345); * alsoBought.forEach(product => { * console.log(`${product.item_desc} - Frequency: ${product.frequency}`); * }); * ``` */ getAlsoBought: async (invMastUid) => { return this.executeRequest({ method: 'GET', path: '/inv-mast/{id}/also-bought', responseSchema: AlsoBoughtListResponseSchema, }, undefined, { id: String(invMastUid) }); }, /** * Inventory tags management * @description CRUD operations for inventory item tags and metadata */ tags: { /** * List tags for an inventory item * @description Retrieve all tags associated with a specific inventory item * @param invMastUid Inventory master unique identifier * @returns Array of tag objects for the item * @throws ValidationError When response is malformed * @example * ```typescript * const tags = await client.invMast.tags.list(12345); * tags.forEach(tag => { * console.log(`${tag.tag_name}: ${tag.tag_value}`); * }); * ``` */ list: async (invMastUid) => { return this.executeRequest({ method: 'GET', path: '/inv-mast/{id}/tags', responseSchema: InvMastTagListResponseSchema, }, undefined, { id: String(invMastUid) }); }, /** * Get specific tag details * @description Retrieve details of a specific inventory tag * @param invMastUid Inventory master unique identifier * @param invMastTagsUid Tag unique identifier * @returns Complete tag object * @throws ValidationError When response is malformed * @example * ```typescript * const tag = await client.invMast.tags.get(12345, 67890); * console.log(`Tag: ${tag.tag_name} = ${tag.tag_value}`); * ``` */ get: async (invMastUid, invMastTagsUid) => { return this.executeRequest({ method: 'GET', path: '/inv-mast/{invMastUid}/tags/{invMastTagsUid}', responseSchema: InvMastTagResponseSchema, }, undefined, { invMastUid: String(invMastUid), invMastTagsUid: String(invMastTagsUid), }); }, /** * Create a new tag for an inventory item * @description Add a new tag to an inventory item for categorization or metadata * @param invMastUid Inventory master unique identifier * @param tagData Tag information including name and value * @returns Created tag object with assigned UID * @throws ValidationError When tag data is invalid or response is malformed * @example * ```typescript * const newTag = await client.invMast.tags.create(12345, { * tag_name: 'Featured Product', * tag_value: 'true', * active: 1 * }); * ``` */ create: async (invMastUid, tagData) => { return this.executeRequest({ method: 'POST', path: '/inv-mast/{id}/tags', paramsSchema: CreateInvMastTagRequestSchema, responseSchema: InvMastTagResponseSchema, }, tagData, { id: String(invMastUid) }); }, /** * Update an existing inventory tag * @description Modify tag information for an inventory item * @param invMastUid Inventory master unique identifier * @param invMastTagsUid Tag unique identifier * @param tagData Updated tag information * @returns Updated tag object * @throws ValidationError When tag data is invalid or response is malformed * @example * ```typescript * const updatedTag = await client.invMast.tags.update(12345, 67890, { * tag_name: 'Premium Product', * tag_value: 'true' * }); * ``` */ update: async (invMastUid, invMastTagsUid, tagData) => { return this.executeRequest({ method: 'PUT', path: '/inv-mast/{invMastUid}/tags/{invMastTagsUid}', paramsSchema: UpdateInvMastTagRequestSchema, responseSchema: InvMastTagResponseSchema, }, tagData, { invMastUid: String(invMastUid), invMastTagsUid: String(invMastTagsUid), }); }, /** * Delete an inventory tag * @description Remove a tag from an inventory item * @param invMastUid Inventory master unique identifier * @param invMastTagsUid Tag unique identifier * @returns Confirmation of deletion * @throws ValidationError When response is malformed * @example * ```typescript * const result = await client.invMast.tags.delete(12345, 67890); * console.log('Tag deleted:', result.deleted); * ``` */ delete: async (invMastUid, invMastTagsUid) => { return this.executeRequest({ method: 'DELETE', path: '/inv-mast/{invMastUid}/tags/{invMastTagsUid}', responseSchema: DeleteResponseSchema, }, undefined, { invMastUid: String(invMastUid), invMastTagsUid: String(invMastTagsUid), }); }, }, /** * Web descriptions management * @description CRUD operations for inventory item web descriptions and marketing content */ webDescriptions: { /** * List web descriptions for an inventory item * @description Retrieve all web descriptions for display on websites and catalogs * @param invMastUid Inventory master unique identifier * @returns Array of web description objects * @throws ValidationError When response is malformed * @example * ```typescript * const descriptions = await client.invMast.webDescriptions.list(12345); * descriptions.forEach(desc => { * console.log(`${desc.description_type}: ${desc.description_text}`); * }); * ``` */ list: async (invMastUid) => { return this.executeRequest({ method: 'GET', path: '/inv-mast/{id}/web-desc', responseSchema: InvMastWebDescListResponseSchema, }, undefined, { id: String(invMastUid) }); }, /** * Get specific web description details * @description Retrieve details of a specific web description * @param invMastUid Inventory master unique identifier * @param invMastWebDescUid Web description unique identifier * @returns Complete web description object * @throws ValidationError When response is malformed * @example * ```typescript * const desc = await client.invMast.webDescriptions.get(12345, 67890); * console.log(desc.description_type, desc.description_text); * ``` */ get: async (invMastUid, invMastWebDescUid) => { return this.executeRequest({ method: 'GET', path: '/inv-mast/{invMastUid}/web-desc/{invMastWebDescUid}', responseSchema: InvMastWebDescResponseSchema, }, undefined, { invMastUid: String(invMastUid), invMastWebDescUid: String(invMastWebDescUid), }); }, /** * Create a new web description * @description Add web description content for an inventory item * @param invMastUid Inventory master unique identifier * @param descData Web description content and metadata * @returns Created web description object with assigned UID * @throws ValidationError When description data is invalid or response is malformed * @example * ```typescript * const newDesc = await client.invMast.webDescriptions.create(12345, { * description_type: 'long', * description_text: 'Detailed product description for web display', * display_order: 1 * }); * ``` */ create: async (invMastUid, descData) => { return this.executeRequest({ method: 'POST', path: '/inv-mast/{id}/web-desc', paramsSchema: CreateInvMastWebDescRequestSchema, responseSchema: InvMastWebDescResponseSchema, }, descData, { id: String(invMastUid) }); }, /** * Update an existing web description * @description Modify web description content for an inventory item * @param invMastUid Inventory master unique identifier * @param invMastWebDescUid Web description unique identifier * @param descData Updated description information * @returns Updated web description object * @throws ValidationError When description data is invalid or response is malformed * @example * ```typescript * const updatedDesc = await client.invMast.webDescriptions.update(12345, 67890, { * description_text: 'Updated detailed product description', * display_order: 2 * }); * ``` */ update: async (invMastUid, invMastWebDescUid, descData) => { return this.executeRequest({ method: 'PUT', path: '/inv-mast/{invMastUid}/web-desc/{invMastWebDescUid}', paramsSchema: UpdateInvMastWebDescRequestSchema, responseSchema: InvMastWebDescResponseSchema, }, descData, { invMastUid: String(invMastUid), invMastWebDescUid: String(invMastWebDescUid), }); }, /** * Delete a web description * @description Remove web description content from an inventory item * @param invMastUid Inventory master unique identifier * @param invMastWebDescUid Web description unique identifier * @returns Confirmation of deletion * @throws ValidationError When response is malformed * @example * ```typescript * const result = await client.invMast.webDescriptions.delete(12345, 67890); * console.log('Description deleted:', result.deleted); * ``` */ delete: async (invMastUid, invMastWebDescUid) => { return this.executeRequest({ method: 'DELETE', path: '/inv-mast/{invMastUid}/web-desc/{invMastWebDescUid}', responseSchema: DeleteResponseSchema, }, undefined, { invMastUid: String(invMastUid), invMastWebDescUid: String(invMastWebDescUid), }); }, }, }; /** * Item category operations * @description Operations for hierarchical item categorization */ this.itemCategory = { /** * Get item category details * @description Retrieve complete details for a specific item category including hierarchical information * @param itemCategoryUid Item category unique identifier * @returns Complete category object with hierarchy details * @throws ValidationError When response is malformed * @example * ```typescript * const category = await client.itemCategory.get(12345); * console.log(category.item_category_desc, category.path, category.level); * ``` */ get: async (itemCategoryUid) => { return this.executeRequest({ method: 'GET', path: '/item-category/{id}', responseSchema: ItemCategoryResponseSchema, }, undefined, { id: String(itemCategoryUid) }); }, }; /** * Order management operations * @description Operations for order processing and management */ this.orders = { /** * Reset order for reprocessing * @description Reset an order by ID for reprocessing (can use web_orders_uid or web_reference_no) * @param orderId Order identifier (web_orders_uid or web_reference_no) * @returns Order reset confirmation with processing status * @throws ValidationError When response is malformed * @example * ```typescript * const resetResult = await client.orders.reset(12345); * console.log(resetResult.reset_status, resetResult.message); * ``` */ reset: async (orderId) => { return this.executeRequest({ method: 'GET', path: '/orders/{id}/reset', responseSchema: OrderResetApiResponseSchema, }, undefined, { id: String(orderId) }); }, }; } } //# sourceMappingURL=client.js.map