/** * MachineMetrics-side allowlisting and FK-safe filtering for labor tickets imported from an ERP. * Connectors map ERP rows to {@link MMSendLaborTicket}; this module enforces MM mapping rules * before calling {@link StandardProcessDrivers.writeEntitiesToMM}. */ import { MMSendLaborTicket } from "../services/mm-api-service/types/send-types.js"; export type { MesMachineSettingRow } from "../services/mm-api-service/mes-machine-settings.js"; /** * Minimal shape of a work order operation row from an ERP batch (connectors pass through * unchanged). `work_order_id`, `sub` and `sequence_number` are required for the labor key. * * `lot` and `split` are optional. When EVERY row of a set carries both (see * {@link isLotSplitAwareRowSet}), the labor key becomes MM's full operation identity * (`workOrderId + lot + split + sub + sequenceNumber`), so a ticket for the wrong lot is * rejected by the filter instead of by MM's `work_order_operation_fk`, and the work-order * gap fill fetches it. Otherwise lot / split are ignored, as before, so connectors whose * tickets and operations disagree on an unset lot keep working. * * `part_number`, `part_revision` and `method` are optional and only read by the work-order * gap fill, to see which parts (and part operations) the bulk sync wrote through work orders * the gap fill did not fetch. */ export interface SyncedWorkOrderOperationRow { work_order_id?: unknown; lot?: unknown; split?: unknown; sub?: unknown; sequence_number?: unknown; part_number?: unknown; part_revision?: unknown; method?: unknown; } /** * Whether a synced row set opts into lot / split-aware labor keys: non-empty and every row * carries both `lot` and `split` (any value, including ""; `undefined` opts out). A set mixing * aware and unaware rows is unaware as a whole, so a connector cannot be half-precise. */ export declare function isLotSplitAwareRowSet(rows: ReadonlyArray): boolean; export interface FilterLaborTicketsForMmImportOptions { /** * Raw work order operations synced in the same from-ERP batch. The SDK builds FK keys via * {@link buildSyncedWorkOrderOperationKeySet}. Prefer this so connectors only fetch + forward rows. */ syncedWorkOrderOperations?: ReadonlyArray; /** * Precomputed keys when the connector already has a set (optional; ignored if `syncedWorkOrderOperations` is non-empty). * Always matched in the short form (`workOrderId + sub + sequenceNumber`); pass rows to get lot / split-aware matching. */ syncedWorkOrderOperationKeys?: ReadonlySet; /** Epicor/MES resource IDs allowed for labor import; if omitted, fetched via {@link getMesLaborImportResourceIds} */ resourceIds?: string[]; /** Operator ERP IDs allowed; if omitted, fetched via {@link getMappedOperatorErpIdsForImport} */ operatorIds?: string[]; } /** * Resolves the work-order-operation key set used for labor import FK matching. */ export declare function resolveSyncedWorkOrderOperationKeysForLaborImport(options: FilterLaborTicketsForMmImportOptions): Set; export interface FilterLaborTicketsForMmImportResult { accepted: MMSendLaborTicket[]; rejected: { missingFields: number; notInResourceAllowlist: number; notInOperatorAllowlist: number; notInSyncedWorkOrderOperation: number; }; } /** * Composite key for matching a labor ticket to a synced work order operation * (`workOrderId + sub + sequenceNumber`). Normalizes the work order id to uppercase ASCII * for stable joins across ERP batch vs labor rows. * * With `lotSplit` the key is MM's full operation identity, `workOrderId + lot + split + * sub + sequenceNumber` (lot / split trimmed, null → ""). Both sides of a comparison must * use the same form; {@link isLotSplitAwareRowSet} decides which one a row set gets. */ export declare function normalizeLaborTicketWorkOrderOpKey(workOrderId: unknown, sub: unknown, sequenceNumber: unknown, lotSplit?: { lot?: unknown; split?: unknown; }): string; /** The key of a synced row, in the form the whole set uses. */ export declare function syncedWorkOrderOperationRowKey(op: SyncedWorkOrderOperationRow, lotSplitAware: boolean): string; /** * Build a set of keys for work order operations produced during the same from-ERP batch as * labor import. Keys include lot / split when the set opts in ({@link isLotSplitAwareRowSet}). */ export declare function buildSyncedWorkOrderOperationKeySet(workOrderOps: ReadonlyArray): Set; /** * Loads machine-settings from MES (`GET /mes/settings/machine-settings`) via * {@link fetchMesMachineSettingsRows}, then returns deduped `laborResourceId` values where labor is enabled. * * Throws if `mmApiBaseUrl` / `mmApiAuthToken` are missing or the MES request fails — same requirements as * {@link MMApiClient.fetchMappedErpResourcesForCompany}. */ export declare function getMesLaborImportResourceIds(): Promise; /** * Mapped operator ERP IDs from the mapping auth service GraphQL proxy (same as legacy connector query). */ export declare function getMappedOperatorErpIdsForImport(): Promise; /** * Applies resource allowlist, operator allowlist, and synced work order operation keys. * Resolves canonical casing for personId using the operator allowlist (case-insensitive match). */ export declare function filterLaborTicketsForMmImport(tickets: readonly MMSendLaborTicket[], options: FilterLaborTicketsForMmImportOptions): Promise; //# sourceMappingURL=labor-import-from-erp.d.ts.map