UNPKG

2.57 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2018 Google LLC
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17/// <reference types="node" />
18import { Agent, AgentOptions as HttpsAgentOptions } from 'https';
19import { AgentOptions as HttpAgentOptions } from 'http';
20import { PassThrough, Readable } from 'stream';
21import { TeenyStatistics } from './TeenyStatistics';
22export interface CoreOptions {
23 method?: string;
24 timeout?: number;
25 gzip?: boolean;
26 json?: any;
27 headers?: Headers;
28 body?: string | {};
29 useQuerystring?: boolean;
30 qs?: any;
31 proxy?: string;
32 multipart?: RequestPart[];
33 forever?: boolean;
34 pool?: HttpsAgentOptions | HttpAgentOptions;
35}
36export interface OptionsWithUri extends CoreOptions {
37 uri: string;
38}
39export interface OptionsWithUrl extends CoreOptions {
40 url: string;
41}
42export declare type Options = OptionsWithUri | OptionsWithUrl;
43export interface Request extends PassThrough {
44 agent: Agent | false;
45 headers: Headers;
46 href?: string;
47}
48export interface Response<T = any> {
49 statusCode: number;
50 headers: Headers;
51 body: T;
52 request: Request;
53 statusMessage?: string;
54}
55export interface RequestPart {
56 body: string | Readable;
57}
58export interface RequestCallback<T = any> {
59 (err: Error | null, response: Response, body?: T): void;
60}
61export declare class RequestError extends Error {
62 code?: number;
63}
64interface Headers {
65 [index: string]: any;
66}
67declare function teenyRequest(reqOpts: Options): Request;
68declare namespace teenyRequest {
69 var defaults: (defaults: CoreOptions) => (reqOpts: Options, callback?: RequestCallback<any> | undefined) => void | Request;
70 var stats: TeenyStatistics;
71 var resetStats: () => void;
72}
73declare function teenyRequest(reqOpts: Options, callback: RequestCallback): void;
74declare namespace teenyRequest {
75 var defaults: (defaults: CoreOptions) => (reqOpts: Options, callback?: RequestCallback<any> | undefined) => void | Request;
76 var stats: TeenyStatistics;
77 var resetStats: () => void;
78}
79export { teenyRequest };