UNPKG

@accounter/server

Version:
63 lines (62 loc) 3.31 kB
import type { Injector } from 'graphql-modules'; import { Currency, DocumentType } from '../../../shared/enums.js'; import type { BusinessMatchData, OwnerMatchInfo } from '../../app-providers/helpers/business-matcher.helper.js'; import type { IInsertDocumentsParams } from '../types.js'; export declare const uploadToCloudinary: (injector: Injector, file: File | Blob) => Promise<{ fileUrl: string; imageUrl: string; }>; /** * Give the pooled Postgres connection back before a long stretch of external * work (download, Cloudinary upload, OCR). * * Document ingestion is the one request shape that pauses on the database for * minutes at a time, and holding the connection across that pause is what makes * the pause dangerous: the connection sits `idle in transaction`, occupying a * pool slot, exposed to `idle_in_transaction_session_timeout` and to the leak * watchdog — both of which kill the session out from under a request that is * perfectly healthy, so its closing INSERT fails. Releasing costs one BEGIN on * the next query, which is nothing next to the OCR round trip it brackets. * * Best-effort by design: this is a resource optimization, and a client that * cannot be resolved or released must not fail the upload. */ export declare function releaseDbConnectionForExternalWork(injector: Injector): Promise<void>; export type OcrData = { isOwnerIssuer?: boolean; counterpartyId?: string; documentType: DocumentType; serial?: string; date?: Date; amount?: number; currency?: Currency; vat?: number; allocationNumber?: string; description?: string; remarks?: string; suggestedIssuer?: string; suggestedRecipient?: string; }; /** * Pre-resolved inputs for the OCR business matching, for callers that cannot use * the auth-coupled `BusinessesProvider` / `AdminContextProvider` loaders — namely * the gateway email-ingestion path, which runs under a control-plane context * where their `TenantAwareDBClient` throws "Missing businessId in AuthContext". */ export type BusinessMatchContext = { businesses: BusinessMatchData[]; owner?: OwnerMatchInfo; }; export declare function getOcrData(injector: Injector, file: File | Blob, isSensitive?: boolean | null, matchContext?: BusinessMatchContext): Promise<OcrData>; export declare function getDocumentFromUrlsAndOcrData(injector: Injector, fileUrl: string, imageUrl: string, ocrData: OcrData, adminBusinessId: string, chargeId?: string | null, fileHash?: number, vatFallbackContext?: { counterpartyCountry: string | null; adminLocality: string | null; }): Promise<IInsertDocumentsParams['documents'][number]>; /** * Turn the OCR business-match UUIDs (`suggestedIssuer` / `suggestedRecipient`) * into `isOwnerIssuer` + `counterpartyId`. `counterpartyId` is only filled when * unset (`??=`), so a caller that already resolved the counterparty from a * higher-confidence source (e.g. the email-ingestion grant) keeps it. */ export declare function resolveOwnerSideFromUuids(ocrData: OcrData, ownerId: string): void; export declare function getDocumentFromFile(injector: Injector, file: File | Blob, chargeId?: string | null, isSensitive?: boolean | null, counterPartyId?: string, hash?: number): Promise<IInsertDocumentsParams['documents'][number]>;