import Vnmf from '../../index' declare module '../../index' { namespace request { interface Option { /** Developer Server Interface Address */ url: string /** Parameters of the request */ data?: U /** Set the requested header,header Could not close temporary folder: %s Referer。 * * `content-type` Default As `application/json` */ header?: VnmfGeneral.IAnyObject /** Timeout,in milliseconds * @default 2000 * @supported weapp, h5, tt */ timeout?: number /** HTTP Method of request * @default GET */ method?: keyof Method /** Returned data format */ dataType?: keyof DataType | string /** Type of data responded */ responseType?: keyof ResponseType /** Open http2 * @default false * @supported weapp */ enableHttp2?: boolean /** Open quic * @default false * @supported weapp */ enableQuic?: boolean /** Open cache * @default false * @supported weapp, tt */ enableCache?: boolean /** Whether or not to open HttpDNS Services。If it's on, on.,Needs to fill in simultaneously httpDNSServiceId 。 HttpDNS Details of the usage Move ResolutionHttpDNS * @default false * @supported weapp */ enableHttpDNS?: boolean /** HttpDNS Service provider Id。 HttpDNS Details of the usage Move ResolutionHttpDNS * @supported weapp */ httpDNSServiceId?: string /** Open transfer-encoding chunked。 * @default false * @supported weapp */ enableChunked?: boolean /** Interface calls a successful echo function */ success?: (result: SuccessCallbackResult) => void /** Interface call failed echo function */ fail?: (res: VnmfGeneral.CallbackResult) => void /** Interface call to the end of echo function(Call successfully、Any failure will be enforced.) */ complete?: (res: VnmfGeneral.CallbackResult) => void /** Settings H5 Could not close temporary folder: %sjsonpHow to get data * @default false * @supported h5 */ jsonp?: boolean /** Settings H5 End jsonp Request url Whether or not to be cached * @default false * @supported h5 */ jsonpCache?: boolean /** Settings H5 Could not close temporary folder: %s * @default "same-origin" * @supported h5 */ mode?: keyof CorsMode /** Settings H5 Could not close temporary folder: %s Cookie * @default "omit" * @supported h5 */ credentials?: keyof Credentials /** Settings H5 End Cache Mode * @default "default" * @supported h5 */ cache?: keyof Cache /** Settings H5 Number of peer requests for retry * @default 2 * @supported h5 */ retryTimes?: number /** Settings H5 The spin-down interface requested by the client * @supported h5 */ backup?: string | string[] /** Settings H5 Data validation function for which the end-requested response,If returned false,And ask for a spin-down interface.,If there's no bottom interface,,The request failed. * @supported h5 */ dataCheck?(): boolean /** Settings H5 Could not close temporary folder: %s * @default false * @supported h5 */ useStore?: boolean /** Settings H5 Could not close temporary folder: %s key * @supported h5 */ storeCheckKey?: string /** Settings H5 Could not close temporary folder: %s * @supported h5 */ storeSign?: string /** Settings H5 End request validation function,Settings are not required as a rule * @supported h5 */ storeCheck?(): boolean } interface SuccessCallbackResult < T extends string | VnmfGeneral.IAnyObject | ArrayBuffer = any | any > extends VnmfGeneral.CallbackResult { /** Data returned by Developer Server */ data: T /** Backed by Developer Server HTTP Response Header */ header: VnmfGeneral.IAnyObject /** Backed by Developer Server HTTP Status Code */ statusCode: number /** Call Results */ errMsg: string /** cookies */ cookies?: string[] } /** Returned data format */ interface DataType { /** Returned Data As JSON,Once you return, you'll have the data returned. JSON.parse * Other: Do not start with the contents of return JSON.parse */ json } /** HTTP Method of request */ interface Method { /** HTTP Request OPTIONS */ OPTIONS /** HTTP Request GET */ GET /** HTTP Request HEAD */ HEAD /** HTTP Request POST */ POST /** HTTP Request PUT */ PUT /** HTTP Request DELETE */ DELETE /** HTTP Request TRACE */ TRACE /** HTTP Request CONNECT */ CONNECT } /** Type of data responded */ interface ResponseType { /** Reply to Data is Text */ text /** The answer to the data is... ArrayBuffer */ arraybuffer } /** Cross-domain Policy */ interface CorsMode { /** Cross-domain requests will receive a non-transparent response */ 'no-cors' /** Allow cross-domain requests */ cors /** The request is always sent to the current source */ 'same-origin' } /** Could not close temporary folder: %s */ interface Credentials { /** Whether it's a cross-domain request or not.,Always send the request field locally cookies、 HTTP Basic authentication Could not close temporary folder: %s */ include /** ♪ Only whenURLSend as Reply Script cookies、 HTTP Basic authentication Could not close temporary folder: %s */ 'same-origin' /** Never Sendcookies */ omit } /** Cache Policy */ interface Cache { /** Browser fromHTTPRequest for matching in cache */ default /** Browser inHTTPRequest for matching in cache */ 'no-cache' /** Browser retrieves resources directly from remote servers,Do Not View Cache,Then update the cache using downloaded resource */ reload /** Browser inHTTPRequest for matching in cache */ 'force-cache' /** Browser inHTTPRequest for matching in cache */ 'only-if-cached' } } /** Network Request Tasker * @supported weapp, h5, rn, alipay, swan, tt, qq * @example * Reciprocal function(Callback)Usage: * * ```tsx * const requestTask = Vnmf.request({ * url: 'test.php', //Example:,Could not close temporary folder: %s * data: { * x: '' , * y: '' * }, * header: { * 'content-type': 'application/json' // Default value * }, * success: function (res) { * console.log(res.data) * } * }) * requestTask.abort() * ``` * @example * Promise Usage: * * ```tsx * const requestTask = Vnmf.request({ * url: 'test.php', //Example:,Could not close temporary folder: %s * data: { * x: '' , * y: '' * }, * header: { * 'content-type': 'application/json' // Default value * }, * success: function (res) { * console.log(res.data) * } * }) * requestTask.then(res => { * console.log(res.data) * }) * requestTask.abort() * ``` * @example * async/await Usage: * * ```tsx * const requestTask = Vnmf.request(params) * const res = await requestTask * requestTask.abort() * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/RequestTask.html */ interface RequestTask extends Promise> { /** Interrupt requested task * @supported weapp, tt * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/RequestTask.abort.html */ abort(): void /** Listening. HTTP Response Header Events。It'll be sooner than requesting the completion of incident. * @supported weapp * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/RequestTask.onHeadersReceived.html */ onHeadersReceived( /** HTTP Response Header Event echo function */ callback: RequestTask.onHeadersReceived.Callback, ): void /** Disable listening. HTTP Response Header Events * @supported weapp * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/RequestTask.offHeadersReceived.html */ offHeadersReceived( /** HTTP Response Header Event echo function */ callback: RequestTask.onHeadersReceived.Callback, ): void /** Listening. Transfer-Encoding Chunk Received Events。♪ When the new one's receivedchunkTime Trigger。 * @supported weapp * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/RequestTask.onChunkReceived.html */ onChunkReceived( /** Transfer-Encoding Chunk Received Event echo function */ callback: RequestTask.onChunkReceived.Callback, ): void /** Listening. Transfer-Encoding Chunk Received Events。♪ When the new one's receivedchunkTime Trigger。 * @supported weapp * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/RequestTask.offChunkReceived.html */ offChunkReceived( /** Transfer-Encoding Chunk Received Event echo function */ callback: RequestTask.onChunkReceived.Callback, ): void } namespace RequestTask { namespace onHeadersReceived { /** HTTP Response Header Event echo function */ type Callback = (result: CallbackResult) => void interface CallbackResult { /** Backed by Developer Server HTTP Response Header */ header: VnmfGeneral.IAnyObject } } namespace onChunkReceived { /** Transfer-Encoding Chunk Received Event echo function */ type Callback = (result: CallbackResult) => void interface CallbackResult { /** Developer server returns new each time chunk It's time. Response */ res: Response } /** Developer server returns new each time chunk It's time. Response */ interface Response { /** Returnedchunk buffer */ data: ArrayBuffer } } } /** @ignore */ type interceptor = (chain: Chain) => any /** @ignore */ interface Chain { index: number requestParams: RequestParams interceptors: interceptor[] proceed(requestParams: RequestParams): any } /** @ignore */ interface interceptors { logInterceptor(chain: Chain): Promise timeoutInterceptor(chain: Chain): Promise } interface VnmfStatic { /** Launch HTTPS Network Request。Read carefully before using[Relevant notes](https://developers.weixin.qq.com/miniprogram/dev/framework/ability/network.html)。 * * **data Description of parameters** * The data that was eventually sent to the server is String Type,If it's in, in. data No, it's not. String Type,It's going to be converted. String 。The conversion rules are as follows:: * - Yeah. `GET` Data on methods,Converts data to query string(`encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...`) * - Yeah. `POST` Methodology and `header['content-type']` Yes. `application/json` Data,It's going to be about the data. JSON Sequence * - Yeah. `POST` Methodology and `header['content-type']` Yes. `application/x-www-form-urlencoded` Data,Converts data to query string `(encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...)` * @supported weapp, h5, rn, alipay, swan, tt, qq * @example * ```tsx * Vnmf.request({ * url: 'test.php', //Example:,Could not close temporary folder: %s * data: { * x: '', * y: '' * }, * header: { * 'content-type': 'application/json' // Default value * }, * success: function (res) { * console.log(res.data) * } * }) * ``` * @example * async/await Usage: * * ```tsx * const res = await Vnmf.request(params) * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/wx.request.html */ request(option: request.Option): RequestTask /** Interceptors can be used to perform additional operations before or after the request is sent.。 * * Calling `Vnmf.request` Before initiating the request,Call `Vnmf.addInterceptor` By requesting the addition of a interceptor.,The interceptor's call sequence follows the onion model.。 * Interceptors are a function.,Accept chain Object as Parameter。chain Organisation **requestParmas** Properties,Arguments requested by the representative。Last call in the interceptor. `chain.proceed(requestParams)` Call the next interceptor or launch request.。 * * Vnmf Two built-in interceptors were provided. `logInterceptor` and `timeoutInterceptor`,The information used to print the request and error dropped while was timed。 * @supported weapp, h5, alipay, swan, tt, qq * @example * ```tsx * const interceptor = function (chain) { * const requestParams = chain.requestParams * const { method, data, url } = requestParams * * console.log(`http ${method || 'GET'} --> ${url} data: `, data) * * return chain.proceed(requestParams) * .then(res => { * console.log(`http <-- ${url} result:`, res) * return res * }) * } * Vnmf.addInterceptor(interceptor) * Vnmf.request({ url }) * ``` * @example * ```tsx * Vnmf.addInterceptor(Vnmf.interceptors.logInterceptor) * Vnmf.addInterceptor(Vnmf.interceptors.timeoutInterceptor) * Vnmf.request({ url }) * ``` * @since 1.2.16 */ addInterceptor(interceptor: interceptor): any interceptors: interceptors } }