UNPKG

bc-webclient-mcp

Version:

Model Context Protocol (MCP) server for Microsoft Dynamics 365 Business Central via WebUI protocol. Enables AI assistants to interact with BC through the web client protocol, supporting Card, List, and Document pages with full line item support and server

140 lines 4.85 kB
/** * BC CRUD Service * * High-level service for Create, Read, Update, Delete operations on BC forms. * Implements the complete LoadForm → Field Resolution → SaveValue flow with * CompletedInteractions barriers and FormState management. * * Critical architecture: * - Single-flight requests: wait for CompletedInteractions before next request * - FormState lifecycle: FormToShow → LoadForm → buildIndices → ready * - Field resolution: Use multi-index (Caption, ScopedCaption, SourceExpr, Name) * - oldValue: Always from FormState.node.value.formatted * - Dialog handling: Semantic button selection (yes/no/ok/cancel) */ import { BCRawWebSocketClient } from '../connection/clients/BCRawWebSocketClient.js'; import { FormStateService } from './form-state-service.js'; import { ButtonIntent } from '../types/form-state.js'; /** * SaveValue options */ export interface SaveValueOptions { /** Override oldValue (default: read from FormState) */ oldValueOverride?: string; /** Control path of next field to activate (default: same field) */ nextFieldPath?: string; /** Timeout in milliseconds */ timeoutMs?: number; } /** * LoadForm options */ export interface LoadFormOptions { /** Whether to wait for indices to be built (default: true) */ waitForReady?: boolean; /** Retry once if LoadForm incomplete (default: true) */ retry?: boolean; /** Timeout in milliseconds */ timeoutMs?: number; } /** * Create record options */ export interface CreateRecordOptions { /** Fields to fill: fieldName/caption → value */ fields: Record<string, string>; /** Form ID of the list to create from (if known) */ listFormId?: string; /** Control path of the "New" button (if known) */ newButtonPath?: string; /** Timeout in milliseconds */ timeoutMs?: number; } /** * Update field options */ export interface UpdateFieldOptions { /** Override oldValue (default: read from FormState) */ oldValueOverride?: string; /** Timeout in milliseconds */ timeoutMs?: number; } /** * Delete record options */ export interface DeleteRecordOptions { /** Control path of the delete button (if known) */ deleteButtonPath?: string; /** Whether to confirm deletion (default: true) */ confirm?: boolean; /** Timeout in milliseconds */ timeoutMs?: number; } /** * BC CRUD Service */ export declare class BCCrudService { private client; private formStateService; /** Whether to enforce single-flight requests (v1: true for safety) */ private singleFlightMode; /** In-flight request tracker */ private inflightRequest; constructor(client: BCRawWebSocketClient, formStateService?: FormStateService); /** * Single-flight wrapper: ensures only one request in flight at a time */ private withSingleFlight; /** * Load form metadata and build field indices * * CRITICAL: Must be called after FormToShow before field interactions! * * @param formId - The form ID to load * @param options - Load options * @param openFormHandlers - Optional: handlers from OpenForm (contains FormToShow with control tree) */ loadForm(formId: string, options?: LoadFormOptions, openFormHandlers?: unknown[]): Promise<void>; /** Invoke LoadForm and collect both immediate and async handlers */ private invokeLoadFormWithListener; /** Process FormToShow handler to initialize FormState */ private processFormShowHandler; /** Apply LogicalClientChangeHandler changes to FormState */ private applyHandlerChanges; /** Build indices and validate form readiness, retrying if needed */ private finalizeFormState; /** * Save field value using field name/caption resolution * * Automatically resolves field name to control path and retrieves oldValue from FormState. */ saveField(formId: string, fieldKey: string, newValue: string, options?: SaveValueOptions): Promise<void>; /** * Invoke a system action (New, Delete, etc.) */ invokeSystemAction(formId: string, systemAction: number, controlPath: string, options?: { timeoutMs?: number; key?: string; }): Promise<unknown[]>; /** * Handle dialog confirmation by semantic button selection */ confirmDialog(dialogFormId: string, intent: ButtonIntent, options?: { timeoutMs?: number; }): Promise<void>; /** * Close a form */ closeForm(formId: string, options?: { timeoutMs?: number; }): Promise<void>; /** * Get FormStateService for advanced operations */ getFormStateService(): FormStateService; /** * Get underlying client for advanced operations */ getClient(): BCRawWebSocketClient; } //# sourceMappingURL=bc-crud-service.d.ts.map