import { APIError, ErrorCode } from "./generated/codes"; import { Dict } from "./commonTypes"; import { RequestDetails } from "./requestDetails"; export declare type BackoffRetryResult = { type: "expected"; value: T; } | { type: "unexpected"; value: T; } | { type: "exhausted"; }; export interface ResultInfo { result: BackoffRetryResult; nextTryInMS: number; attemptNumber: number; totalAttempts: number; } export interface BackoffRetryOpts { getNextTryInMS?: (numTries: number) => number; getTimeoutMS?: (numTries: number) => number; numTries?: number; reportResult?: (result: ResultInfo) => void; forceNextTry?: (info: ResultInfo) => Promise; } export declare const defaultNextTryInMS: (n: number) => 100 | 1000 | 200 | 500 | 2000; export declare const defaultTimeoutMS: (n: number) => 3000 | 6000 | 9000; export declare const extendedTimeoutMS: (n: number) => number; export declare function backoffRetry(cb: (timeoutMS: number) => Promise>, opts?: BackoffRetryOpts): Promise; export interface AbstractOp { __opType: T; __opVariablesType: VT; __tag: "graphql-operation"; } export interface AbstractOpWithData { __opType: T; __opVariablesType: { data: DataT; }; __tag: "graphql-operation"; } export interface GenericAPIError { code?: ErrorCode; meta?: Dict; field?: string; message?: string; } export interface GraphError { message: string; path?: (string | number)[]; apiError?: APIError; } export declare type SystemErrorType = "no_error" | "timeout" | "no_status" | "bad_status" | "unrecognized_data_body" | "unrecognized_error_body" | "more_than_one_operation"; export declare type RequestResponseMulti = { kind: "data_or_error"; errors?: GraphError[]; data?: T; details: RequestDetails; } | { kind: "system_error"; type: SystemErrorType; details: RequestDetails; }; export declare type RequestResponseError = { kind: "error"; error: GraphError; details: RequestDetails; } | { kind: "system_error"; type: SystemErrorType; details: RequestDetails; } | { kind: "custom_error"; text: string; }; export declare function requestErrorPrefix(details: RequestDetails): string; export declare function prettyPrintGraphErrors(errors: GraphError[]): string; export declare function prettyPrintAPIError(err: APIError): string; export declare function prettyPrintGraphError(gerr: GraphError): string; export declare function prettyPrintRequestResponseError(err: RequestResponseError, detailed?: boolean): string; export declare type RequestResponseData = { kind: "data"; data: T; } | RequestResponseError; export declare type RequestResponse = RequestResponseData>; export declare function request(query: T): (variables?: T["__opVariablesType"], opts?: GraphQLOpts) => Promise>; export declare function requestMulti(query: T): (variables?: T["__opVariablesType"], opts?: GraphQLOpts) => Promise>; export declare type GraphQLOpts = BackoffRetryOpts> & { /** Locale field for API calls. */ locale?: string; /** API endpoint URL (omit for default, default is good for most users) */ url?: string; /** Optional authorization token. If customer is logged in, customer's JWT should be used here. */ authToken?: string; /** Analytics session id. */ sessionID?: string; /** Use commerce API endpoint. Only applies if "url" was not specified. */ commerce?: boolean; /** Device id. Used in commerce API. */ deviceID?: string; }; export declare function graphqlBackoffRetry(query: string, variables?: Variables, opts?: GraphQLOpts): Promise>;