-
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathrequest.d.ts
More file actions
146 lines (125 loc) · 4.66 KB
/
request.d.ts
File metadata and controls
146 lines (125 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import { File, HttpRequestOptions, ImageSource } from '@nativescript/core';
import * as Https from './request.common';
export function getManager(): any; // okhttp3.OkHttpClient or AFHTTPSessionManager
export interface HttpsSSLPinningOptions {
host: string;
certificate: string;
allowInvalidCertificates?: boolean;
validatesDomainName?: boolean;
commonName?: string;
}
export interface CacheOptions {
diskLocation: string;
diskSize: number;
memorySize?: number;
forceCache?: boolean;
}
export interface HttpsFormDataParam {
data: any;
parameterName: string;
fileName?: string;
contentType?: string;
}
export interface HttpsRequestObject {
[key: string]: string | number | boolean | HttpsRequestObject | any[] | HttpsFormDataParam;
}
export interface Headers {
[k: string]: string;
}
export type CachePolicy = 'noCache' | 'onlyCache' | 'ignoreCache';
export interface HttpsRequestOptions extends HttpRequestOptions {
url: string;
tag?: string; // optional request tag to allow to cancel it
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
headers?: Headers;
params?: HttpsRequestObject;
body?: HttpsRequestObject | HttpsFormDataParam[] | File;
/**
* content can be used to pass native custom okhttp3.RequestBody
*/
content?: string | any;
/**
* Default 10 (seconds).
*/
timeout?: number;
/**
* On Android large responses may crash the app (fi. https://httpbin.org/bytes/10000).
* By setting this to true and when not using useLegacy, we allow large responses on the main thread (which this plugin currently does).
* Note that once set to true, this policy remains active until the app is killed.
*/
allowLargeResponse?: boolean;
/**
* iOS for now
*/
onProgress?: (current: number, total: number) => void;
/**
* default to true. Put to false to run response callback on current thread
*/
responseOnMainThread?: boolean;
progressOnMainThread?: boolean;
cachePolicy?: CachePolicy;
/**
* default to true. Android and iOS only store cookies in memory! it will be cleared after an app restart
*/
cookiesEnabled?: boolean;
/**
* iOS only: Resolve request promise as soon as headers are received, before download completes.
* This allows inspecting status/headers and cancelling before full download.
* When true, toFile()/toJSON()/etc. will wait for download completion.
* Default: false (waits for full download before resolving)
*/
earlyResolve?: boolean;
/**
* iOS only: Response size threshold (in bytes) for using file download vs memory loading.
* Responses larger than this will be downloaded to temp file (memory efficient).
* Responses smaller will be loaded into memory (faster for small responses).
* Default: 1048576 (1 MB). Set to 0 to always use memory, -1 to always use file download.
*/
downloadSizeThreshold?: number;
}
export interface HttpsResponse<T = any> {
headers?: Headers;
statusCode?: number;
contentLength: number;
content?: T;
response?: string;
reason?: string;
description?: string;
url?: string;
failure?: any;
}
export interface HttpsRequest {
nativeRequest;
cancel();
run(success, failure);
}
export interface HttpsResponseLegacy<T = any> {
contentLength: number;
toArrayBuffer(): ArrayBuffer;
toArrayBufferAsync(): Promise<ArrayBuffer>;
toString(): string;
toStringAsync(): Promise<string>;
toJSON(): T;
toJSONAsync(): Promise<T>;
toImage(): Promise<ImageSource>;
// toImageAsync(): Promise<ImageSource>;
toFile(destinationFilePath: string): Promise<File>;
// toFileAsync(destinationFilePath: string): Promise<File>;
}
export function enableSSLPinning(options: HttpsSSLPinningOptions);
export function disableSSLPinning();
// export declare function request<T = any>(options: HttpsRequestOptions): Promise<HttpsResponse<HttpsResponseLegacy<T>>>;
export declare function request<T = any, U extends boolean = true>(
options: HttpsRequestOptions,
useLegacy?: U
): U extends true ? Promise<HttpsResponse<HttpsResponseLegacy<T>>> : Promise<HttpsResponse<T>>;
export function setCache(options?: CacheOptions);
export function clearCache();
export function removeCachedResponse(url: string);
export function createRequest(opts: HttpsRequestOptions): HttpsRequest;
export function cancelRequest(tag: string);
export function cancelAllRequests();
export function clearCookies();
export function addNetworkInterceptor(interceptor);
export function getClient(opts: Partial<HttpsRequestOptions>);
export * from './request.common';