import type { IssueView, JobView } from '../web/jobView.js'; /** The header that the routes that change an import require (§ 8.3). */ export declare const IMPORT_REQUEST_HEADER = "X-Import-Request"; export type HttpMethod = 'GET' | 'POST' | 'DELETE'; export interface HttpRequest { method: HttpMethod; url: string; headers?: Record; params?: Record; body?: FormData; /** Bytes sent so far and in all, for the bar of an upload. */ onUploadProgress?: (sent: number, total: number) => void; signal?: AbortSignal; } /** What came back: any HTTP status is an answer; only no answer at all is a throw. */ export interface HttpReply { status: number; headers: Record; data: unknown; } /** The one thing the page needs from a browser: a request that never rejects on a status. */ export interface Http { send(request: HttpRequest): Promise; } /** An answer that is not a success, as the page needs to show and to act on it. */ export interface ApiFailure { /** 0 when there was no answer (network down, or the request was aborted). */ status: number; /** The code of § 8.3, when the API sent one. */ code: string | null; message: string; details: Record; /** From the `Retry-After` header of a 429, in milliseconds. */ retryAfterMs: number | null; aborted: boolean; } export type ApiResult = { ok: true; data: T; } | { ok: false; error: ApiFailure; }; export interface IssuesPage { phase: 'validate' | 'import'; page: number; limit: number; total: number; byCode: Record; truncated: boolean; items: IssueView[]; } export interface IssuesQuery { severity?: 'error' | 'warning'; code?: string; column?: string; page?: number; limit?: number; } export interface UploadArgs { entity: string; mode: string; checkImages: boolean; file: Blob & { name?: string; }; } export interface UploadOutcome { job: JobView; /** An earlier unfinished import of the type was replaced (D-11). */ replaced: boolean; } /** * `Retry-After` is a number of seconds or a date (RFC 9110). A value that is * neither, or a date in the past, is no help: the page then uses its own wait. */ export declare function parseRetryAfter(value: string | undefined, nowMs: number): number | null; /** * The calls of the import pages. The addresses come from the page's GraphQL * query (`url(routeId: ...)`), so a store that moves its API keeps working. Every * call that changes an import carries the header that a form on another site * cannot send; the reads do not need it. */ export declare function createImportApi(http: Http, clock: () => number): { getJob: (url: string, signal?: AbortSignal) => Promise>; /** The open jobs of every entity, and the stopped or interrupted ones (§ 8.3). */ listOpen: (url: string, signal?: AbortSignal) => Promise>; issues: (url: string, query: IssuesQuery, signal?: AbortSignal) => Promise>; start: (url: string) => Promise>; cancel: (url: string) => Promise>; resume: (url: string) => Promise>; recheck: (url: string) => Promise>; remove: (url: string) => Promise>; /** * The upload. The fields come **before** the file, because the server reads * them while the file streams in (§ 8.3); `FormData` keeps the order. */ upload: (url: string, args: UploadArgs, progress?: (sent: number, total: number) => void, signal?: AbortSignal) => Promise>; }; export type ImportApi = ReturnType;