UNPKG

2.3 kBTypeScriptView Raw
1import * as superagent from 'superagent';
2import { BitGo, VerifyResponseOptions } from './bitgo';
3export interface BitGoRequest<ResultType = any> extends superagent.SuperAgentRequest {
4 result: (optionalField?: string) => Promise<ResultType>;
5}
6/**
7 * Add the bitgo-specific result() function on a superagent request.
8 *
9 * If the server response is successful, the `result()` function will return either the entire response body,
10 * or the field from the response body specified by the `optionalField` parameter if it is provided.
11 *
12 * If the server response with an error, `result()` will handle HTTP errors appropriately by
13 * rethrowing them as an `ApiResponseError` if possible, and otherwise rethrowing the underlying response error.
14 *
15 * @param req
16 */
17export declare function toBitgoRequest<ResponseResultType = any>(req: superagent.SuperAgentRequest): BitGoRequest<ResponseResultType>;
18/**
19 * Return a function which extracts the specified response body property from the response if successful,
20 * otherwise throw an `ApiErrorResponse` parsed from the response body.
21 * @param optionalField
22 */
23export declare function handleResponseResult<ResponseResultType>(optionalField?: string): (res: superagent.Response) => ResponseResultType;
24/**
25 * Handle an error or an error containing an HTTP response and use it to throw a well-formed error object.
26 *
27 * @param e
28 */
29export declare function handleResponseError(e: Error & {
30 response?: superagent.Response;
31}): never;
32/**
33 * Serialize request data based on the request content type
34 * Note: Not sure this is still needed or even useful. Consider removing.
35 * @param req
36 */
37export declare function serializeRequestData(req: superagent.Request): string | undefined;
38/**
39 * Set the superagent query string correctly for browsers or node.
40 * @param req
41 */
42export declare function setRequestQueryString(req: superagent.SuperAgentRequest): void;
43/**
44 * Verify that the response received from the server is signed correctly.
45 * Right now, it is very permissive with the timestamp variance.
46 */
47export declare function verifyResponse(bitgo: BitGo, token: string | undefined, method: VerifyResponseOptions['method'], req: superagent.SuperAgentRequest, response: superagent.Response): superagent.Response;
48//# sourceMappingURL=api.d.ts.map
\No newline at end of file