import type { EnvInterface, MfaReceipts, MfaRequired } from "./index.ts"; import { CubeSignerClient, MultiRegionEnv } from "./index.ts"; import type { AcceptedResponse, AcceptedValue, SignDryRun, JsonRpcResponse, JsonRpcResult } from "./schema_types.ts"; /** * Response type, which can be either a value of type {@link U} * or {@link AcceptedResponse} (status code 202) which requires MFA. */ export type Response = U | AcceptedResponse; /** * Request function which optionally takes additional headers * (which, for example, can be used to attach an MFA receipt). */ export type RequestFn = (headers?: HeadersInit) => Promise>; /** * Map function occasionally used to map a response from the API into a higher-level type. */ export type MapFn = (u: U) => V; /** * Take a {@link Response} and a {@link MapFn} function and return * a {@link Response} that maps the value of the original response when its status code is 200. * * @param resp Original response * @param mapFn Map to apply to the response value when its status code is 200. * @returns Response whose value for status code 200 is mapped from U to V */ export declare function mapResponse(resp: Response, mapFn: MapFn): Response; /** * A response of a CubeSigner request. */ export declare class CubeSignerResponse { #private; /** * @returns The {@link AcceptedValue} if the response status code is 202. */ asAccepted(): AcceptedValue | undefined; /** * @returns The associated {@link MfaRequired} value, if the response status code is 202 and the response indicates that MFA is required. */ asMfaRequired(): MfaRequired | undefined; /** * @returns The associated {@link SignDryRun} value, if the response status code is 202 and the response is a dry run of a sign operation. */ asSignDryRun(): SignDryRun | undefined; /** * @returns Whether this response is a "200 Success" (in which case it is safe to call {@link data}) */ isSuccess(): boolean; /** * @returns The underlying {@link MfaRequired} response (if any). */ private get mfaRequired(); /** @returns The first MFA id associated with this request (if any) */ mfaId(): string | undefined; /** @returns The MFA ids associated with this request (if any) */ mfaIds(): string[]; /** @returns True if this request requires an MFA approval */ requiresMfa(): boolean; /** * @returns Session information to use for any MFA approval requests (if any was included in the response). */ mfaClient(): Promise; /** @returns The response data, if no MFA is required */ data(): U; /** * Approve the MFA request using a given session and a TOTP code. * * @param client CubeSigner whose session to use * @param code 6-digit TOTP code * @returns The result of resubmitting the request with the approval */ totpApprove(client: CubeSignerClient, code: string): Promise>; /** * Reject the MFA request using a given session and a TOTP code. * * @param client CubeSigner whose session to use * @param code 6-digit TOTP code */ totpReject(client: CubeSignerClient, code: string): Promise; /** * Approve the MFA request using a given {@link CubeSignerClient} instance (i.e., its session). * * @param client CubeSigner whose session to use * @returns The result of resubmitting the request with the approval */ approve(client: CubeSignerClient): Promise>; /** * Reject the MFA request using a given {@link CubeSignerClient} instance (i.e., its session). * * @param client CubeSigner whose session to use */ reject(client: CubeSignerClient): Promise; /** * Resubmits the request with a given MFA receipt(s) attached. * * @param mfaReceipt The MFA receipt(s) * @returns The result of signing after MFA approval */ execWithMfaApproval(mfaReceipt: MfaReceipts): Promise>; /** * Constructor. * * @param env The environment where the response comes from * @param requestFn * The function that this response is from. * This argument is used to resend requests with different headers if needed. * @param resp The response as returned by the OpenAPI client. * @internal */ protected constructor(env: MultiRegionEnv, requestFn: RequestFn, resp: Response); /** * Static constructor. * * @param env The environment where the response comes from * @param requestFn * The request function that this response is from. * This argument is used to resend requests with different headers if needed. * @param mfaReceipt Optional MFA receipt(s) * @returns New instance of this class. * @internal */ static create(env: EnvInterface | MultiRegionEnv, requestFn: RequestFn, mfaReceipt?: MfaReceipts): Promise>; /** * Similar to {@link create} except that unwraps the {@link JsonRpcResponse} * to throw an {@link ErrResponse} on error * * @param env The environment where the response comes from * @param reqFn * The request function that this response is from. * This argument is used to resend requests with different headers if needed. * @param mfaReceipt Optional MFA receipt(s) * @returns New instance of this class. * @internal */ static createForJsonRpc(env: EnvInterface | MultiRegionEnv, reqFn: RequestFn, mfaReceipt?: MfaReceipts): Promise>; /** * Return HTTP headers containing a given MFA receipt. * * @param mfaReceipt MFA receipt(s) * @returns Headers including {@link mfaReceipt} * @internal */ static getMfaHeaders(mfaReceipt?: MfaReceipts): HeadersInit | undefined; } //# sourceMappingURL=response.d.ts.map