@simpleapps-com/augur-api
Version:
TypeScript client library for Augur microservices API endpoints
266 lines • 12.4 kB
JavaScript
import { BaseServiceClient } from '../../core/base-client';
import { PriceEngineParamsSchema, PriceEngineResponseSchema, TaxEngineRequestSchema, TaxEngineResponseSchema, JobPriceHdrListParamsSchema, JobPriceHdrListResponseSchema, JobPriceHdrGetResponseSchema, JobPriceLineListParamsSchema, JobPriceLineListResponseSchema, JobPriceLineGetResponseSchema, HealthCheckResponseSchema, PingResponseSchema, } from './schemas';
/**
* Pricing API Client
* @description Client for interacting with Pricing microservice API endpoints for pricing calculations, tax computation, and job-based pricing management
* @example
* ```typescript
* import { HTTPClient } from '@augur/api-client/core';
* import { PricingClient } from '@augur/api-client/services/pricing';
*
* const http = new HTTPClient('pricing', { siteId: 'your-site-id', bearerToken: 'your-token' });
* const pricing = new PricingClient(http);
*
* // Get item price
* const price = await pricing.priceEngine.calculate({ customerId: 12345, itemId: 'ABC123', quantity: 10 });
*
* // Calculate tax
* const tax = await pricing.taxEngine.calculate({
* customer_id: 12345,
* postal_code: '12345',
* items: [{ item_id: 'ABC123', quantity: 2, unit_price: 25.99, extended_amount: 51.98 }],
* ship_to_address: { street: '123 Main St', city: 'Anytown', state: 'NY', postal_code: '12345' }
* });
*
* // List job price headers
* const jobHeaders = await pricing.jobPriceHdr.list({ limit: 25, q: 'contract' });
* ```
*/
export class PricingClient extends BaseServiceClient {
/**
* Create a new PricingClient instance
* @param http Configured HTTPClient instance
* @param baseUrl Base URL for the Pricing API (default: https://pricing.augur-api.com)
*/
constructor(http, baseUrl = 'https://pricing.augur-api.com') {
super('pricing', http, baseUrl);
/**
* Price engine operations
* @description Pricing calculations and price determination
*/
this.priceEngine = {
/**
* Calculate item price using the price engine
* @description Primary pricing endpoint for calculating item prices with sophisticated caching and compression
* @param params Pricing parameters including customer ID, item ID, quantity, and other options
* @returns Detailed pricing information including base price, unit price, discounts, and calculation details
* @throws ValidationError When parameters are invalid or response is malformed
* @example
* ```typescript
* const price = await client.priceEngine.calculate({
* customerId: 12345,
* itemId: 'ABC123',
* quantity: 10,
* unitOfMeasure: 'EA',
* shipToId: 456
* });
*
* console.log('Unit Price:', price.unit_price);
* console.log('Discount:', price.discount_percent);
* console.log('Price Source:', price.price_source);
* ```
*/
calculate: async (params) => {
return this.executeRequest({
method: 'GET',
path: '/price-engine',
paramsSchema: PriceEngineParamsSchema,
responseSchema: PriceEngineResponseSchema,
}, params);
},
};
/**
* Tax engine operations
* @description Tax calculations and jurisdiction-based tax determination
*/
this.taxEngine = {
/**
* Calculate tax using the tax engine
* @description Tax calculation endpoint with postal code-based rate lookups and jurisdiction breakdowns
* @param request Tax calculation request with customer, items, and shipping address information
* @returns Detailed tax calculation with total tax, rates, and jurisdiction-specific breakdowns
* @throws ValidationError When request is invalid or response is malformed
* @example
* ```typescript
* const tax = await client.taxEngine.calculate({
* customer_id: 12345,
* postal_code: '12345',
* items: [
* {
* item_id: 'ABC123',
* quantity: 2,
* unit_price: 25.99,
* extended_amount: 51.98
* }
* ],
* ship_to_address: {
* street: '123 Main St',
* city: 'Anytown',
* state: 'NY',
* postal_code: '12345'
* }
* });
*
* console.log('Total Tax:', tax.total_tax);
* console.log('Tax Rate:', tax.tax_rate);
* tax.jurisdictions.forEach(j => {
* console.log(`${j.jurisdiction_name}: ${j.tax_rate}% = $${j.tax_amount}`);
* });
* ```
*/
calculate: async (request) => {
return this.executeRequest({
method: 'POST',
path: '/tax-engine',
paramsSchema: TaxEngineRequestSchema,
responseSchema: TaxEngineResponseSchema,
}, request);
},
};
/**
* Job Price Header endpoints
* @description Methods for managing job-based pricing contracts and agreements
*/
this.jobPriceHdr = {
/**
* List job price headers with filtering and pagination
* @description Retrieves job price headers with optional search, filtering, and pagination
* @param params Optional filtering and pagination parameters
* @returns Paginated list of job price headers with total count
* @throws ValidationError When parameters are invalid or response is malformed
* @example
* ```typescript
* // Get all job price headers
* const headers = await client.jobPriceHeaders.list();
*
* // Search and filter
* const filtered = await client.jobPriceHeaders.list({
* q: 'contract',
* limit: 25,
* orderBy: 'job_no|ASC'
* });
*
* console.log(`Found ${filtered.total} job price headers`);
* filtered.data.forEach(header => {
* console.log(`${header.job_no}: ${header.job_description}`);
* });
* ```
*/
list: this.createListMethod('/job-price-hdr', JobPriceHdrListParamsSchema, JobPriceHdrListResponseSchema),
/**
* Get specific job price header details
* @description Retrieves detailed information for a specific job price header
* @param jobPriceHdrUid Job price header unique identifier
* @returns Complete job price header details including contract information
* @throws ValidationError When response is malformed
* @example
* ```typescript
* const header = await client.jobPriceHeaders.get(12345);
* console.log('Job:', header.job_no, header.job_description);
* console.log('Customer:', header.customer_id);
* console.log('Contract:', header.contract_no);
* console.log('Period:', header.start_date, 'to', header.end_date);
* ```
*/
get: this.createGetMethod('/job-price-hdr/{id}', JobPriceHdrGetResponseSchema),
};
/**
* Job Price Line endpoints
* @description Methods for managing individual line items within job pricing contracts
*/
this.jobPriceLines = {
/**
* List job price lines for a specific header
* @description Retrieves job price lines with optional filtering by status, inventory, and other criteria
* @param jobPriceHdrUid Job price header unique identifier
* @param params Optional filtering and pagination parameters
* @returns Paginated list of job price lines with total count
* @throws ValidationError When parameters are invalid or response is malformed
* @example
* ```typescript
* // Get all lines for a job
* const lines = await client.jobPriceLines.list(12345);
*
* // Filter by status and inventory
* const activeLines = await client.jobPriceLines.list(12345, {
* statusCd: 704, // Active
* invMastUid: 11111,
* limit: 50
* });
*
* console.log(`Found ${activeLines.total} active lines`);
* activeLines.data.forEach(line => {
* console.log(`${line.item_id}: $${line.price} (${line.uom})`);
* });
* ```
*/
list: async (jobPriceHdrUid, params) => {
return this.executeRequest({
method: 'GET',
path: '/job-price-hdr/{id}/lines',
paramsSchema: JobPriceLineListParamsSchema,
responseSchema: JobPriceLineListResponseSchema,
}, params, { id: String(jobPriceHdrUid) });
},
/**
* Get specific job price line details
* @description Retrieves detailed information for a specific job price line including pricing method and cost basis
* @param jobPriceHdrUid Job price header unique identifier
* @param jobPriceLineUid Job price line unique identifier
* @returns Complete job price line details including extended pricing information
* @throws ValidationError When response is malformed
* @example
* ```typescript
* const line = await client.jobPriceLines.get(12345, 67890);
* console.log('Item:', line.item_id, line.item_description);
* console.log('Price:', line.price, line.uom);
* console.log('Quantities - Ordered:', line.qty_ordered, 'Max:', line.qty_maximum);
* console.log('Margins - Discount:', line.discount_percent, 'Margin:', line.margin_percent);
* ```
*/
get: async (jobPriceHdrUid, jobPriceLineUid) => {
return this.executeRequest({
method: 'GET',
path: '/job-price-hdr/{hdrId}/lines/{lineId}',
responseSchema: JobPriceLineGetResponseSchema,
}, undefined, { hdrId: String(jobPriceHdrUid), lineId: String(jobPriceLineUid) });
},
};
/**
* Simple connectivity test (no bearer token required)
* @description Quick endpoint for testing basic connectivity without authentication
* @returns Simple pong response for connectivity verification
* @throws ValidationError When response is malformed
* @example
* ```typescript
* const pong = await client.ping();
* console.log('Ping response:', pong); // "pong"
* ```
*/
this.ping = this.createPingMethod(PingResponseSchema);
this.getHealthCheck = this.createHealthCheckMethod(HealthCheckResponseSchema);
/**
* Health Data Operations
* @description Direct access to health check data without response metadata
*/
this.healthData = {
/**
* Get health check data without response metadata
* @returns Promise<unknown> Health status data directly
*/
check: async () => {
const response = await this.getHealthCheck();
return response.data;
},
/**
* Get ping data without response metadata
* @returns Promise<unknown> Ping response data directly
*/
ping: async () => {
const response = await this.ping();
return response.data;
},
};
}
}
//# sourceMappingURL=client.js.map