import { ERPObjType } from "../../types/erp-types.js"; import { BatchCacheManager } from "../../services/caching-service/batch-cache-manager.js"; import { IToRESTApiObject, MMSendLaborTicket } from "../../services/mm-api-service/index.js"; import { WriteEntitiesToMMResult } from "./standard-process-drivers.js"; /** * Handles processing of entities to the MachineMetrics API */ export declare class MMEntityProcessor { /** * Writes entities to MM API with deduplication and caching. * * Optionally writes large record sets in sequential chunks to keep each MM * API call within its timeout budget. Chunking is OFF by default so it never * interferes with connectors that chunk at their own layer: it activates only * when `options.chunkSize` is set (> 0) or, absent that, when env * `MM_API_WRITE_CHUNK_SIZE` / `CoreConfiguration.mmApiWriteChunkSize` is set * (> 0). When a `batchCacheManager` is provided, successfully written chunks * are cached immediately, so a failure partway through is safe to retry — * already-written records dedupe locally. With `batchCacheManager: null` a * retry re-sends already-written chunks (MM upserts are idempotent, but * reported counts will differ). * * IMPORTANT: All datetime fields on `mmRecords` MUST already be expressed as * ISO-8601 UTC strings (either trailing `Z` or an explicit offset). The SDK * does not apply timezone conversion on this path. It forwards values directly * to MachineMetrics and only reserializes them for validation. Connector code * is responsible for converting local ERP times to UTC before invoking this API. */ static writeEntities(entityType: ERPObjType, mmRecords: IToRESTApiObject[], batchCacheManager: BatchCacheManager | null, options?: { connectorType?: string; chunkSize?: number; queryParams?: Record; }): Promise; /** * Splits records into chunks of the configured size. * Chunk size resolution: explicit `chunkSize` argument, then * `CoreConfiguration.mmApiWriteChunkSize`. Fractional values are floored to * a whole number of records per request; unset, non-finite, or values that * floor to <= 0 disable chunking (the default), returning the record set as * a single chunk. */ private static _chunkRecords; /** * Sends a single chunk and handles its response. Same contract as the * original single-shot write path. */ private static _writeChunk; /** * Writes chunks sequentially, aggregating results across chunks. * * Structured per-chunk failures (MMBatchValidationError from a 207 or a * structured 500) do not stop processing — remaining chunks are still * written, and one aggregated MMBatchValidationError is thrown at the end. * Non-structured exceptions (network, auth, timeout) abort immediately and * are rethrown as-is, discarding the counts accumulated from earlier chunks. * When a `batchCacheManager` is in use, those chunks are already cached, so * a retry of the full record set dedupes them locally; with * `batchCacheManager: null` a retry re-sends them (harmless for MM's * idempotent upserts, but the caller cannot tell part of the batch landed). */ private static _writeChunked; /** * Deduplicates records against cache * Returns the records to process and the result object * If the batchCacheManager is provided, the records are deduplicated against the cache * If the batchCacheManager is not provided, the records are not deduplicated */ private static _prepareAndDedupe; /** * Sends records to MM API */ private static _sendToAPI; /** * Handles exceptions from API calls, converting structured 500 errors to MMBatchValidationError * @throws MMBatchValidationError for structured 500 errors * @throws The original exception for all other errors */ private static _handleException; /** * Handles the MM API response based on HTTP status code, caching successful records * and throwing exceptions for partial failures * * @returns The final result for success cases * @throws MMBatchValidationError for partial success cases * @throws Error for unknown status codes */ private static _handleResponse; /** * PUBLIC: marks labor tickets imported from ERP in the local sync ledger so the next * to-erp cycle can dedupe them by signature. Safe to call before AND after the MM POST * (upsertAttempt is idempotent on (system, laborTicketRef)). */ static markLaborTicketsInLedger(tickets: MMSendLaborTicket[], connectorType: string, label?: string): Promise<{ written: number; skippedNoKey: number; failed: number; }>; private static _markLaborTicketsInLedger; } //# sourceMappingURL=mm-entity-processor.d.ts.map