UNPKG

5.2 kBTypeScriptView Raw
1import type { Plugin } from './definitions';
2import { WebPlugin } from './web-plugin';
3/******** WEB VIEW PLUGIN ********/
4export interface WebViewPlugin extends Plugin {
5 setServerBasePath(options: WebViewPath): Promise<void>;
6 getServerBasePath(): Promise<WebViewPath>;
7 persistServerBasePath(): Promise<void>;
8}
9export interface WebViewPath {
10 path: string;
11}
12export declare const WebView: WebViewPlugin;
13export interface CapacitorCookiesPlugin {
14 getCookies(options?: GetCookieOptions): Promise<HttpCookieMap>;
15 setCookie(options: SetCookieOptions): Promise<void>;
16 deleteCookie(options: DeleteCookieOptions): Promise<void>;
17 clearCookies(options: ClearCookieOptions): Promise<void>;
18 clearAllCookies(): Promise<void>;
19}
20interface HttpCookie {
21 url?: string;
22 key: string;
23 value: string;
24}
25interface HttpCookieMap {
26 [key: string]: string;
27}
28interface HttpCookieExtras {
29 path?: string;
30 expires?: string;
31}
32export type GetCookieOptions = Omit<HttpCookie, 'key' | 'value'>;
33export type SetCookieOptions = HttpCookie & HttpCookieExtras;
34export type DeleteCookieOptions = Omit<HttpCookie, 'value'>;
35export type ClearCookieOptions = Omit<HttpCookie, 'key' | 'value'>;
36export declare class CapacitorCookiesPluginWeb extends WebPlugin implements CapacitorCookiesPlugin {
37 getCookies(): Promise<HttpCookieMap>;
38 setCookie(options: SetCookieOptions): Promise<void>;
39 deleteCookie(options: DeleteCookieOptions): Promise<void>;
40 clearCookies(): Promise<void>;
41 clearAllCookies(): Promise<void>;
42}
43export declare const CapacitorCookies: CapacitorCookiesPlugin;
44/******** END COOKIES PLUGIN ********/
45/******** HTTP PLUGIN ********/
46export interface CapacitorHttpPlugin {
47 request(options: HttpOptions): Promise<HttpResponse>;
48 get(options: HttpOptions): Promise<HttpResponse>;
49 post(options: HttpOptions): Promise<HttpResponse>;
50 put(options: HttpOptions): Promise<HttpResponse>;
51 patch(options: HttpOptions): Promise<HttpResponse>;
52 delete(options: HttpOptions): Promise<HttpResponse>;
53}
54export type HttpResponseType = 'arraybuffer' | 'blob' | 'json' | 'text' | 'document';
55export interface HttpOptions {
56 url: string;
57 method?: string;
58 params?: HttpParams;
59 data?: any;
60 headers?: HttpHeaders;
61 /**
62 * How long to wait to read additional data. Resets each time new
63 * data is received
64 */
65 readTimeout?: number;
66 /**
67 * How long to wait for the initial connection.
68 */
69 connectTimeout?: number;
70 /**
71 * Sets whether automatic HTTP redirects should be disabled
72 */
73 disableRedirects?: boolean;
74 /**
75 * Extra arguments for fetch when running on the web
76 */
77 webFetchExtra?: RequestInit;
78 /**
79 * This is used to parse the response appropriately before returning it to
80 * the requestee. If the response content-type is "json", this value is ignored.
81 */
82 responseType?: HttpResponseType;
83 /**
84 * Use this option if you need to keep the URL unencoded in certain cases
85 * (already encoded, azure/firebase testing, etc.). The default is _true_.
86 */
87 shouldEncodeUrlParams?: boolean;
88}
89export interface HttpParams {
90 [key: string]: string | string[];
91}
92export interface HttpHeaders {
93 [key: string]: string;
94}
95export interface HttpResponse {
96 data: any;
97 status: number;
98 headers: HttpHeaders;
99 url: string;
100}
101/**
102 * Read in a Blob value and return it as a base64 string
103 * @param blob The blob value to convert to a base64 string
104 */
105export declare const readBlobAsBase64: (blob: Blob) => Promise<string>;
106/**
107 * Build the RequestInit object based on the options passed into the initial request
108 * @param options The Http plugin options
109 * @param extra Any extra RequestInit values
110 */
111export declare const buildRequestInit: (options: HttpOptions, extra?: RequestInit) => RequestInit;
112export declare class CapacitorHttpPluginWeb extends WebPlugin implements CapacitorHttpPlugin {
113 /**
114 * Perform an Http request given a set of options
115 * @param options Options to build the HTTP request
116 */
117 request(options: HttpOptions): Promise<HttpResponse>;
118 /**
119 * Perform an Http GET request given a set of options
120 * @param options Options to build the HTTP request
121 */
122 get(options: HttpOptions): Promise<HttpResponse>;
123 /**
124 * Perform an Http POST request given a set of options
125 * @param options Options to build the HTTP request
126 */
127 post(options: HttpOptions): Promise<HttpResponse>;
128 /**
129 * Perform an Http PUT request given a set of options
130 * @param options Options to build the HTTP request
131 */
132 put(options: HttpOptions): Promise<HttpResponse>;
133 /**
134 * Perform an Http PATCH request given a set of options
135 * @param options Options to build the HTTP request
136 */
137 patch(options: HttpOptions): Promise<HttpResponse>;
138 /**
139 * Perform an Http DELETE request given a set of options
140 * @param options Options to build the HTTP request
141 */
142 delete(options: HttpOptions): Promise<HttpResponse>;
143}
144export declare const CapacitorHttp: CapacitorHttpPlugin;
145export {};
146/******** END HTTP PLUGIN ********/