UNPKG

7.68 kBTypeScriptView Raw
1import type { Plugin } from './definitions';
2import { WebPlugin } from './web-plugin';
3/******** WEB VIEW PLUGIN ********/
4export interface WebViewPlugin extends Plugin {
5 setServerAssetPath(options: WebViewPath): Promise<void>;
6 setServerBasePath(options: WebViewPath): Promise<void>;
7 getServerBasePath(): Promise<WebViewPath>;
8 persistServerBasePath(): Promise<void>;
9}
10export interface WebViewPath {
11 path: string;
12}
13export declare const WebView: WebViewPlugin;
14export interface CapacitorCookiesPlugin {
15 getCookies(options?: GetCookieOptions): Promise<HttpCookieMap>;
16 /**
17 * Write a cookie to the device.
18 */
19 setCookie(options: SetCookieOptions): Promise<void>;
20 /**
21 * Delete a cookie from the device.
22 */
23 deleteCookie(options: DeleteCookieOptions): Promise<void>;
24 /**
25 * Clear cookies from the device at a given URL.
26 */
27 clearCookies(options: ClearCookieOptions): Promise<void>;
28 /**
29 * Clear all cookies on the device.
30 */
31 clearAllCookies(): Promise<void>;
32}
33interface HttpCookie {
34 /**
35 * The URL of the cookie.
36 */
37 url?: string;
38 /**
39 * The key of the cookie.
40 */
41 key: string;
42 /**
43 * The value of the cookie.
44 */
45 value: string;
46}
47interface HttpCookieMap {
48 [key: string]: string;
49}
50interface HttpCookieExtras {
51 /**
52 * The path to write the cookie to.
53 */
54 path?: string;
55 /**
56 * The date to expire the cookie.
57 */
58 expires?: string;
59}
60export type GetCookieOptions = Omit<HttpCookie, 'key' | 'value'>;
61export type SetCookieOptions = HttpCookie & HttpCookieExtras;
62export type DeleteCookieOptions = Omit<HttpCookie, 'value'>;
63export type ClearCookieOptions = Omit<HttpCookie, 'key' | 'value'>;
64export declare class CapacitorCookiesPluginWeb extends WebPlugin implements CapacitorCookiesPlugin {
65 getCookies(): Promise<HttpCookieMap>;
66 setCookie(options: SetCookieOptions): Promise<void>;
67 deleteCookie(options: DeleteCookieOptions): Promise<void>;
68 clearCookies(): Promise<void>;
69 clearAllCookies(): Promise<void>;
70}
71export declare const CapacitorCookies: CapacitorCookiesPlugin;
72/******** END COOKIES PLUGIN ********/
73/******** HTTP PLUGIN ********/
74export interface CapacitorHttpPlugin {
75 /**
76 * Make a Http Request to a server using native libraries.
77 */
78 request(options: HttpOptions): Promise<HttpResponse>;
79 /**
80 * Make a Http GET Request to a server using native libraries.
81 */
82 get(options: HttpOptions): Promise<HttpResponse>;
83 /**
84 * Make a Http POST Request to a server using native libraries.
85 */
86 post(options: HttpOptions): Promise<HttpResponse>;
87 /**
88 * Make a Http PUT Request to a server using native libraries.
89 */
90 put(options: HttpOptions): Promise<HttpResponse>;
91 /**
92 * Make a Http PATCH Request to a server using native libraries.
93 */
94 patch(options: HttpOptions): Promise<HttpResponse>;
95 /**
96 * Make a Http DELETE Request to a server using native libraries.
97 */
98 delete(options: HttpOptions): Promise<HttpResponse>;
99}
100/**
101 * How to parse the Http response before returning it to the client.
102 */
103export type HttpResponseType = 'arraybuffer' | 'blob' | 'json' | 'text' | 'document';
104export interface HttpOptions {
105 /**
106 * The URL to send the request to.
107 */
108 url: string;
109 /**
110 * The Http Request method to run. (Default is GET)
111 */
112 method?: string;
113 /**
114 * URL parameters to append to the request.
115 */
116 params?: HttpParams;
117 /**
118 * Note: On Android and iOS, data can only be a string or a JSON.
119 * FormData, Blob, ArrayBuffer, and other complex types are only directly supported on web
120 * or through enabling `CapacitorHttp` in the config and using the patched `window.fetch` or `XMLHttpRequest`.
121 *
122 * If you need to send a complex type, you should serialize the data to base64
123 * and set the `headers["Content-Type"]` and `dataType` attributes accordingly.
124 */
125 data?: any;
126 /**
127 * Http Request headers to send with the request.
128 */
129 headers?: HttpHeaders;
130 /**
131 * How long to wait to read additional data in milliseconds.
132 * Resets each time new data is received.
133 */
134 readTimeout?: number;
135 /**
136 * How long to wait for the initial connection in milliseconds.
137 */
138 connectTimeout?: number;
139 /**
140 * Sets whether automatic HTTP redirects should be disabled
141 */
142 disableRedirects?: boolean;
143 /**
144 * Extra arguments for fetch when running on the web
145 */
146 webFetchExtra?: RequestInit;
147 /**
148 * This is used to parse the response appropriately before returning it to
149 * the requestee. If the response content-type is "json", this value is ignored.
150 */
151 responseType?: HttpResponseType;
152 /**
153 * Use this option if you need to keep the URL unencoded in certain cases
154 * (already encoded, azure/firebase testing, etc.). The default is _true_.
155 */
156 shouldEncodeUrlParams?: boolean;
157 /**
158 * This is used if we've had to convert the data from a JS type that needs
159 * special handling in the native layer
160 */
161 dataType?: 'file' | 'formData';
162}
163export interface HttpParams {
164 /**
165 * A key/value dictionary of URL parameters to set.
166 */
167 [key: string]: string | string[];
168}
169export interface HttpHeaders {
170 /**
171 * A key/value dictionary of Http headers.
172 */
173 [key: string]: string;
174}
175export interface HttpResponse {
176 /**
177 * Additional data received with the Http response.
178 */
179 data: any;
180 /**
181 * The status code received from the Http response.
182 */
183 status: number;
184 /**
185 * The headers received from the Http response.
186 */
187 headers: HttpHeaders;
188 /**
189 * The response URL recieved from the Http response.
190 */
191 url: string;
192}
193/**
194 * Read in a Blob value and return it as a base64 string
195 * @param blob The blob value to convert to a base64 string
196 */
197export declare const readBlobAsBase64: (blob: Blob) => Promise<string>;
198/**
199 * Build the RequestInit object based on the options passed into the initial request
200 * @param options The Http plugin options
201 * @param extra Any extra RequestInit values
202 */
203export declare const buildRequestInit: (options: HttpOptions, extra?: RequestInit) => RequestInit;
204export declare class CapacitorHttpPluginWeb extends WebPlugin implements CapacitorHttpPlugin {
205 /**
206 * Perform an Http request given a set of options
207 * @param options Options to build the HTTP request
208 */
209 request(options: HttpOptions): Promise<HttpResponse>;
210 /**
211 * Perform an Http GET request given a set of options
212 * @param options Options to build the HTTP request
213 */
214 get(options: HttpOptions): Promise<HttpResponse>;
215 /**
216 * Perform an Http POST request given a set of options
217 * @param options Options to build the HTTP request
218 */
219 post(options: HttpOptions): Promise<HttpResponse>;
220 /**
221 * Perform an Http PUT request given a set of options
222 * @param options Options to build the HTTP request
223 */
224 put(options: HttpOptions): Promise<HttpResponse>;
225 /**
226 * Perform an Http PATCH request given a set of options
227 * @param options Options to build the HTTP request
228 */
229 patch(options: HttpOptions): Promise<HttpResponse>;
230 /**
231 * Perform an Http DELETE request given a set of options
232 * @param options Options to build the HTTP request
233 */
234 delete(options: HttpOptions): Promise<HttpResponse>;
235}
236export declare const CapacitorHttp: CapacitorHttpPlugin;
237export {};
238/******** END HTTP PLUGIN ********/