UNPKG

@simpleapps-com/augur-api

Version:

TypeScript client library for Augur microservices API endpoints

470 lines 15.4 kB
import { AugurAPIConfig, AugurContext } from './core/config'; import { DiscoveryEndpoint as BaseDiscoveryEndpoint } from './core/base-client'; import { JoomlaClient } from './services/joomla'; import { CommerceClient } from './services/commerce'; import { PricingClient } from './services/pricing'; import { VMIClient } from './services/vmi'; import { OpenSearchClient } from './services/open-search'; import { ItemsClient } from './services/items'; import { LegacyClient } from './services/legacy'; import { NexusClient } from './services/nexus'; import { AgrSiteClient } from './services/agr-site'; import { CustomersClient } from './services/customers'; import { OrdersClient } from './services/orders'; import { P21PimClient } from './services/p21-pim'; import { PaymentsClient } from './services/payments'; import { AgrInfoClient } from './services/agr-info'; import { AgrWorkClient } from './services/agr-work'; import { AvalaraClient } from './services/avalara'; import { BrandFolderClient } from './services/brand-folder'; import { GregorovichClient } from './services/gregorovich'; import { LogisticsClient } from './services/logistics'; import { P21ApisClient } from './services/p21-apis'; import { P21CoreClient } from './services/p21-core'; import { P21SismClient } from './services/p21-sism'; import { ShippingClient } from './services/shipping'; import { SlackClient } from './services/slack'; import { SmartyStreetsClient } from './services/smarty-streets'; import { UPSClient } from './services/ups'; /** * Interface for discovery endpoint information - re-export base discovery endpoint */ export type DiscoveryEndpoint = BaseDiscoveryEndpoint; /** * Re-export context and error types for convenience */ export type { AugurContext } from './core/config'; export { ContextCreationError } from './core/config'; /** * Interface for service discovery results */ export interface ServiceMap { /** Service name */ serviceName: string; /** Service description */ description: string; /** Base URL for the service */ baseUrl: string; /** Number of discoverable endpoints */ endpointCount: number; /** Array of discoverable endpoints */ endpoints: DiscoveryEndpoint[]; } /** * Interface for endpoint search results */ export interface EndpointSearchResult { /** The matching endpoint */ endpoint: DiscoveryEndpoint; /** Relevance score (0-1) */ score: number; /** Reason why this endpoint matched */ matchReason: string; } /** * Main client factory for accessing Augur microservices * * @example * ```typescript * // Traditional approach * const api = new AugurAPI({ * siteId: 'my-site-id', * bearerToken: 'my-bearer-token' * }); * * // Context-aware approach (recommended) * const api = AugurAPI.fromContext(context); * * // Access Joomla service * const users = await api.joomla.users.list(); * * // Access Commerce service * const cart = await api.commerce.cartHeaders.lookup({ userId: 123, customerId: 456, contactId: 789 }); * * // Access Pricing service * const price = await api.pricing.getPrice({ customerId: 12345, itemId: 'ABC123', quantity: 10 }); * * // Access VMI service * const warehouses = await api.vmi.warehouses.list({ customerId: 12345 }); * * // Access OpenSearch service * const searchResults = await api.opensearch.itemSearch.search({ q: 'electrical wire', searchType: 'query' }); * * // Access Items service * const product = await api.items.products.get(12345); * const categories = await api.items.categories.get(100); * * // Access Legacy service * const states = await api.legacy.states.list({ twoLetterCode: 'CA' }); * const alsoBought = await api.legacy.inventory.getAlsoBought(12345); * * // Access Nexus service * const binTransfer = await api.nexus.binTransfers.create({ * usersId: 1001, * locationId: 5.0, * transfers: [{ lineNo: 1, invMastUid: 67890, itemId: 'ITEM001', toBin: 'A1-01', fromBin: 'B2-05', lot: 'LOT123', uom: 'EA', quantity: 10 }] * }); * * // Access AGR Site service * const health = await api.agrSite.getHealthCheck(); * const settings = await api.agrSite.settings.list({ serviceName: 'commerce' }); * const transcript = await api.agrSite.fyxerTranscripts.create({ link: 'https://example.com/doc.pdf' }); * * // Access Customers service * const customers = await api.customers.customer.list({ limit: 10 }); * const customer = await api.customers.customer.get(12345); * const contacts = await api.customers.customer.contacts.list(12345, { q: 'John' }); * const newContact = await api.customers.customer.contacts.create(12345, { * firstName: 'Jane', lastName: 'Doe', email: 'jane@example.com' * }); * * // Access Orders service * const orders = await api.orders.orders.lookup({ limit: 10, q: '12345' }); * const orderDoc = await api.orders.orders.getDocument(12345678, { postalCode: '12345' }); * const salesRepOrders = await api.orders.salesRep.getOrders(123); * const purchaseOrders = await api.orders.purchaseOrders.list({ complete: 'N', limit: 20 }); * const invoiceReprint = await api.orders.invoices.reprint('INV123456'); * * // Access P21 PIM service * const invExtensions = await api.p21Pim.inventoryMasterExtensions.list({ limit: 20 }); * const displaySuggestions = await api.p21Pim.items.suggestDisplayDescription(12345); * const webSuggestions = await api.p21Pim.items.suggestWebDescription(12345, { limit: 5 }); * const podcasts = await api.p21Pim.podcasts.list({ q: 'manufacturing' }); * * // Access Payments service * const transactionSetup = await api.payments.unified.transactionSetup({ customerId: '123' }); * const accountQuery = await api.payments.unified.accountQuery({ * customerId: '123', * transactionSetupId: transactionSetup.data.transactionSetupId * }); * const surcharge = await api.payments.unified.surcharge({ * customerId: '123', * paymentAccountId: '456', * amount: '100.00', * fromState: 'CA', * toState: 'NY', * country: 'US' * }); * ``` */ export declare class AugurAPI { private config; private _joomla?; private _commerce?; private _pricing?; private _vmi?; private _opensearch?; private _items?; private _legacy?; private _nexus?; private _agrSite?; private _customers?; private _orders?; private _p21Pim?; private _payments?; private _agrInfo?; private _agrWork?; private _avalara?; private _brandFolder?; private _gregorovich?; private _logistics?; private _p21Apis?; private _p21Core?; private _p21Sism?; private _shipping?; private _slack?; private _smartyStreets?; private _ups?; constructor(config: AugurAPIConfig); /** * Create AugurAPI client from context object * * Automatically extracts siteId and authentication token from context, * eliminating the need for manual configuration boilerplate. * * @param context Context object containing siteId and authentication * @param options Optional configuration overrides * @returns AugurAPI instance configured from context * * @example * ```typescript * // Instead of manual configuration: * const userJwt = await getToken({ req: request }); * const api = new AugurAPI({ siteId: context.siteId, bearerToken: userJwt.jwtToken }); * * // Simply use: * const api = AugurAPI.fromContext(context); * * // With optional overrides: * const api = AugurAPI.fromContext(context, { timeout: 10000 }); * ``` * * @throws {ContextCreationError} When context is invalid or missing required fields */ static fromContext(context: AugurContext, options?: Partial<AugurAPIConfig>): AugurAPI; /** * Access Joomla service endpoints */ get joomla(): JoomlaClient; /** * Access Commerce service endpoints */ get commerce(): CommerceClient; /** * Access Pricing service endpoints */ get pricing(): PricingClient; /** * Access VMI (Vendor Managed Inventory) service endpoints */ get vmi(): VMIClient; /** * Access OpenSearch service endpoints */ get opensearch(): OpenSearchClient; /** * Access Items service endpoints */ get items(): ItemsClient; /** * Access Legacy service endpoints */ get legacy(): LegacyClient; /** * Access Nexus (Warehouse Management) service endpoints */ get nexus(): NexusClient; /** * Access AGR Site service endpoints */ get agrSite(): AgrSiteClient; /** * Access Customers service endpoints */ get customers(): CustomersClient; /** * Access Orders service endpoints */ get orders(): OrdersClient; /** * Access P21 PIM (Product Information Management) service endpoints */ get p21Pim(): P21PimClient; /** * Access Payments service endpoints */ get payments(): PaymentsClient; /** * Access AGR Info service endpoints */ get agrInfo(): AgrInfoClient; /** * Access AGR Work service endpoints */ get agrWork(): AgrWorkClient; /** * Access Avalara service endpoints */ get avalara(): AvalaraClient; /** * Access Brand Folder service endpoints */ get brandFolder(): BrandFolderClient; /** * Access Gregorovich service endpoints */ get gregorovich(): GregorovichClient; /** * Access Logistics service endpoints */ get logistics(): LogisticsClient; /** * Access P21 APIs service endpoints */ get p21Apis(): P21ApisClient; /** * Access P21 Core service endpoints */ get p21Core(): P21CoreClient; /** * Access P21 SISM service endpoints */ get p21Sism(): P21SismClient; /** * Access Shipping service endpoints */ get shipping(): ShippingClient; /** * Access Slack service endpoints */ get slack(): SlackClient; /** * Access SmartyStreets service endpoints */ get smartyStreets(): SmartyStreetsClient; /** * Access UPS service endpoints */ get ups(): UPSClient; /** * Update authentication token * @param bearerToken New bearer token */ setAuthToken(bearerToken: string): void; /** * Update site ID * @param siteId New site ID */ setSiteId(siteId: string): void; /** * Discover all available services and their capabilities * * Returns a complete service map showing all discoverable endpoints across * all microservices, enabling AI agents to understand the full API topology. * * @returns Promise<ServiceMap[]> Array of service maps with endpoint metadata * * @example * ```typescript * const api = new AugurAPI({ siteId: 'my-site', bearerToken: 'token' }); * const services = await api.discover(); * * // Find all user-related endpoints * const userEndpoints = services.flatMap(s => s.endpoints) * .filter(e => e.searchTerms.some(term => term.includes('user'))); * * // Show service capabilities * services.forEach(service => { * console.log(`${service.serviceName}: ${service.endpointCount} endpoints`); * service.endpoints.forEach(endpoint => { * console.log(` ${endpoint.fullPath} - ${endpoint.description}`); * }); * }); * ``` */ discover(): Promise<ServiceMap[]>; /** * Find endpoints by search term or functionality description * * Searches across all services to find endpoints that match the given search term. * Uses intelligent matching against endpoint descriptions, search terms, domains, * and common usage patterns. * * @param searchTerm The functionality or term to search for * @param options Search options for filtering and ranking * @returns Promise<EndpointSearchResult[]> Array of matching endpoints with relevance scores * * @example * ```typescript * const api = new AugurAPI({ siteId: 'my-site', bearerToken: 'token' }); * * // Find user-related endpoints * const userEndpoints = await api.findEndpoint('users'); * console.log(`Found ${userEndpoints.length} user-related endpoints`); * * // Find authentication endpoints * const authEndpoints = await api.findEndpoint('authentication'); * * // Find inventory management * const inventoryEndpoints = await api.findEndpoint('inventory management'); * * // Show results with scores * userEndpoints.forEach(result => { * console.log(`${result.endpoint.fullPath} (${result.score.toFixed(2)}) - ${result.matchReason}`); * }); * ``` */ findEndpoint(searchTerm: string, options?: { /** Minimum relevance score (0-1, default: 0.1) */ minScore?: number; /** Maximum number of results (default: 10) */ maxResults?: number; /** Filter by specific service */ service?: string; /** Filter by business domain */ domain?: string; /** Include only GET endpoints */ readOnly?: boolean; }): Promise<EndpointSearchResult[]>; /** * Get endpoints filtered by service, domain, and method options */ private getFilteredEndpoints; /** * Search and score endpoints against search term */ private searchAndScoreEndpoints; /** * Check if endpoint has required fields */ private isValidEndpoint; /** * Calculate final score with domain filter adjustments */ private calculateFinalScore; /** * Calculate relevance score for an endpoint against a search term */ private calculateEndpointRelevance; /** * Process exact matches with appropriate combining logic */ private processExactMatches; /** * Check if match type should be exclusive (no combining) */ private isExclusiveMatch; /** * Check if match type can be combined with partial matches */ private isCombinableMatch; /** * Process fallback matches when no exact match found */ private processFallbackMatches; /** * Calculate exact field matches with high scores */ private calculateExactMatches; /** * Check for path substring matches */ private checkPathSubstringMatch; /** * Check for description substring matches */ private checkDescriptionSubstringMatch; /** * Check for other substring matches (domain, service) */ private checkOtherSubstringMatches; /** * Check for exact field matches */ private checkExactFieldMatches; /** * Check search terms and common patterns */ private checkSearchTermsAndPatterns; /** * Calculate partial word matches with lower scores */ private calculatePartialMatches; /** * Build searchable text from endpoint fields */ private buildSearchableText; /** * Count matching words in text */ private countWordMatches; /** * Build partial match result with score and reason */ private buildPartialMatchResult; /** * Calculate multi-word matches by finding the best match for each word */ private calculateMultiWordMatches; } //# sourceMappingURL=client.d.ts.map