UNPKG

@sassoftware/vi-api

Version:
369 lines (368 loc) 15.8 kB
export interface HttpResponse<R> { body: R | null; headers: Record<string, string | string[]>; status: number; statusText: string; url: string | null; } /** * This API provides functionality for making REST requests. * * Accessed from the window at `window.sas.vi.http` * * @example window.sas.vi.http.get("example_url", {...}) * @category API */ export interface HttpApi { /** * @method * @description Constructs a GET request that interprets the body as a text stream and returns the full HttpResponse. * @param url {string} Endpoint URL. * @param [options] {HttpApi~StringRequestOptions} HTTP options to send with the request. * @return A Promise of the HttpResponse for the request. * The response body is a string. */ get(url: string, options?: { headers?: Record<string, string | string[]>; params?: Record<string, string | string[]>; responseType: "text"; }): Promise<HttpResponse<string>>; /** * @method * @description Constructs a GET request that interprets the body as a JSON object and returns the full HttpResponse. * @template R * @param url {string} Endpoint URL. * @param options {HttpApi~JsonRequestOptions} HTTP options to send with the request. * @return A Promise of the HttpResponse for the request. * The response body is an object of type {@link R}. */ get<R>(url: string, options?: { headers?: Record<string, string | string[]>; params?: Record<string, string | string[]>; responseType: "json"; }): Promise<HttpResponse<R>>; /** * @method * @description Constructs a GET request that interprets the body as a Blob and returns the full HttpResponse. * @template R * @param url {string} Endpoint URL. * @param options {HttpApi~BlobRequestOptions} HTTP options to send with the request. * @return A Promise of the HttpResponse for the request. * The response body is a Blob. */ get(url: string, options?: { headers?: Record<string, string | string[]>; params?: Record<string, string | string[]>; responseType: "blob"; }): Promise<HttpResponse<Blob>>; /** * @method * @description Constructs a HEAD request that returns a null body and the full HttpResponse. * @param url {string} Endpoint URL. * @param options {HttpApi~HeadOptions} HTTP options to send with the request. * @return A Promise of the HttpResponse for the request with the response body of null. */ head(url: string, options?: { headers?: Record<string, string | string[]>; params?: Record<string, string | string[]>; }): Promise<HttpResponse<null>>; /** * @method * @description Constructs a POST request that interprets the body as a text stream and returns the full HttpResponse. * @param url {string} Endpoint URL. * @param body {(any|null)} Content to replace with current content. * @param options {HttpApi~StringRequestOptions} HTTP options * @return A Promise of the HttpResponse for the request. * The response body is a string. */ post(url: string, body: any | null, options?: { headers?: Record<string, string | string[]>; params?: Record<string, string | string[]>; responseType: "text"; }): Promise<HttpResponse<string>>; /** * @method * @template R * @description Constructs a POST request that interprets the body as a JSON object and returns the full HttpResponse. * @param url {string} Endpoint URL. * @param body {(any|null)} Content to replace with current content. * @param options {HttpApi~JsonRequestOptions} HTTP options * @return A Promise of the HttpResponse for the request. * The response body is an object of type {@link R}. */ post<R>(url: string, body: any | null, options?: { headers?: Record<string, string | string[]>; params?: Record<string, string | string[]>; responseType: "json"; }): Promise<HttpResponse<R>>; /** * @method * @description Constructs a POST request that interprets the body as a Blob and returns the full HttpResponse. * @param url {string} Endpoint URL. * @param body {(any|null)} Content to replace with current content. * @param options {HttpApi~BlobRequestOptions} HTTP options * @return A Promise of the HttpResponse for the request. * The response body is a Blob. */ post(url: string, body: any | null, options?: { headers?: Record<string, string | string[]>; params?: Record<string, string | string[]>; responseType: "blob"; }): Promise<HttpResponse<Blob>>; /** * @method * @description Constructs a PUT request that interprets the body as a text stream and returns the full HttpResponse. * @param url {string} Endpoint URL. * @param body {(any|null)} Content to replace with current content. * @param options {HttpApi~StringRequestOptions} HTTP options. * @return A Promise of the HttpResponse for the request. * The response body is a string. */ put(url: string, body: any | null, options?: { headers?: Record<string, string | string[]>; params?: Record<string, string | string[]>; responseType: "text"; }): Promise<HttpResponse<string>>; /** * @method * @template R * @description Constructs a PUT request that interprets the body as a JSON object and returns the full HttpResponse. * @param url {string} Endpoint URL. * @param body {(any|null)} Content to replace with current content. * @param options {HttpApi~JsonRequestOptions} HTTP options. * @return A Promise of the HttpResponse for the request. * The response body is an object of type {@link R}. */ put<R>(url: string, body: any | null, options?: { headers?: Record<string, string | string[]>; params?: Record<string, string | string[]>; responseType: "json"; }): Promise<HttpResponse<R>>; /** * @method * @description Constructs a PUT request that interprets the body as a Blob and returns the full HttpResponse. * @param url {string} Endpoint URL. * @param body {(any|null)} Content to replace with current content. * @param options {HttpApi~BlobRequestOptions} HTTP options. * @return A Promise of the HttpResponse for the request. * The response body is a Blob. */ put(url: string, body: any | null, options?: { headers?: Record<string, string | string[]>; params?: Record<string, string | string[]>; responseType: "blob"; }): Promise<HttpResponse<Blob>>; /** * @method * @description Constructs a PATCH request that interprets the body as a text stream and returns the full HttpResponse. * @param url {string} Endpoint URL. * @param body {(any|null)} Content to replace with current content. * @param options {HttpApi~StringRequestOptions} HTTP options. * @return A Promise of the HttpResponse for the request. * The response body is a string. */ patch(url: string, body: any | null, options?: { headers?: Record<string, string | string[]>; params?: Record<string, string | string[]>; responseType: "text"; }): Promise<HttpResponse<string>>; /** * @method * @template R * @description Constructs a PATCH request that interprets the body as a JSON object and returns the full HttpResponse. * @param url {string} Endpoint URL. * @param body {(any|null)} Content to replace with current content. * @param options {HttpApi~JsonRequestOptions} HTTP options. * @return A Promise of the HttpResponse for the request. * The response body is an object of type {@link R}. */ patch<R>(url: string, body: any | null, options?: { headers?: Record<string, string | string[]>; params?: Record<string, string | string[]>; responseType: "json"; }): Promise<HttpResponse<R>>; /** * @method * @description Constructs a PATCH request that interprets the body as a Blob and returns the full HttpResponse. * @param url {string} Endpoint URL. * @param body {(any|null)} Content to replace with current content. * @param options {HttpApi~BlobRequestOptions} HTTP options. * @return A Promise of the HttpResponse for the request. * The response body is a Blob. */ patch(url: string, body: any | null, options?: { headers?: Record<string, string | string[]>; params?: Record<string, string | string[]>; responseType: "blob"; }): Promise<HttpResponse<Blob>>; /** * @method * @description Constructs a DELETE request that interprets the body as a text stream and returns the full HttpResponse. * @param url {string} Endpoint URL. * @param options {HttpApi~StringRequestOptions} HTTP options. * @return A Promise of the HttpResponse for the request. * The response body is a string. */ delete(url: string, options?: { headers?: Record<string, string | string[]>; params?: Record<string, string | string[]>; responseType: "text"; }): Promise<HttpResponse<string>>; /** * @method * @template R * @description Constructs a DELETE request that interprets the body as a JSON object and returns the full HttpResponse. * @param url {string} Endpoint URL. * @param options {HttpApi~JsonRequestOptions} HTTP options. * @return A Promise of the HttpResponse for the request. * The response body is an object of type {@link R}. */ delete<R>(url: string, options?: { headers?: Record<string, string | string[]>; params?: Record<string, string | string[]>; responseType: "json"; }): Promise<HttpResponse<R>>; /** * @method * @description Constructs a DELETE request that interprets the body as a Blob and returns the full HttpResponse. * @param url {string} Endpoint URL. * @param options {HttpApi~BlobRequestOptions} HTTP options. * @return A Promise of the HttpResponse for the request. * The response body is a Blob. */ delete(url: string, options?: { headers?: Record<string, string | string[]>; params?: Record<string, string | string[]>; responseType: "blob"; }): Promise<HttpResponse<Blob>>; /** * @method * @description Constructs an OPTIONS request that interprets the body as a text stream and returns the full HttpResponse. * @param url {string} Endpoint URL. * @param options {HttpApi~StringRequestOptions} HTTP options. * @return A Promise of the HttpResponse for the request. * The response body is a string. */ options(url: string, options?: { headers?: Record<string, string | string[]>; params?: Record<string, string | string[]>; responseType: "text"; }): Promise<HttpResponse<string>>; /** * @method * @template R * @description Constructs an OPTIONS request that interprets the body as a JSON object and returns the full HttpResponse. * @param url {string} Endpoint URL. * @param options {HttpApi~JsonRequestOptions} HTTP options. * @return A Promise of the HttpResponse for the request. * The response body is an object of type {@link R}. */ options<R>(url: string, options?: { headers?: Record<string, string | string[]>; params?: Record<string, string | string[]>; responseType: "json"; }): Promise<HttpResponse<R>>; /** * @method * @description Constructs an OPTIONS request that interprets the body as a Blob and returns the full HttpResponse. * @param url {string} Endpoint URL. * @param options {HttpApi~BlobRequestOptions} HTTP options. * @return A Promise of the HttpResponse for the request. * The response body is a Blob. */ options(url: string, options?: { headers?: Record<string, string | string[]>; params?: Record<string, string | string[]>; responseType: "blob"; }): Promise<HttpResponse<Blob>>; /** * @method * @description Constructs a request that interprets the body as a text stream and returns the full HttpResponse. * @param method {string} * @param url {string} Endpoint URL. * @param options {HttpApi~StringGenericRequestOptions} HTTP options. * @return A Promise of the HttpResponse for the request. * The response body is a string. */ request(method: string, url: string, options?: { body?: any | null; headers?: Record<string, string | string[]>; params?: Record<string, string | string[]>; responseType: "text"; }): Promise<HttpResponse<string>>; /** * @method * @template R * @description Constructs a request that interprets the body as a JSON object and returns the full HttpResponse. * @param method {string} * @param url {string} Endpoint URL. * @param options {HttpApi~JsonGenericRequestOptions} HTTP options. * @return A Promise of the HttpResponse for the request. * The response body is an object of type {@link R}. */ request<R>(method: string, url: string, options?: { body?: any | null; headers?: Record<string, string | string[]>; params?: Record<string, string | string[]>; responseType: "json"; }): Promise<HttpResponse<R>>; /** * @method * @description Constructs a request that interprets the body as a Blob and returns the full HttpResponse. * @param method {string} * @param url {string} Endpoint URL. * @param options {HttpApi~BlobGenericRequestOptions} HTTP options. * @return A Promise of the HttpResponse for the request. * The response body is a Blob. */ request(method: string, url: string, options?: { body?: any | null; headers?: Record<string, string | string[]>; params?: Record<string, string | string[]>; responseType: "blob"; }): Promise<HttpResponse<Blob>>; } /** * @typedef {Object} HttpApi~StringRequestOptions * @property [headers] {Record<string, string | string[]>} * @property [params] {Record<string, string | string[]>} * @property responseType {"text"} */ /** * @typedef {Object} HttpApi~JsonRequestOptions * @property [headers] {Record<string, string | string[]>} * @property [params] {Record<string, string | string[]>} * @property responseType {"json"} */ /** * @typedef {Object} HttpApi~BlobRequestOptions * @property [headers] {Record<string, string | string[]>} * @property [params] {Record<string, string | string[]>} * @property responseType {"blob"} */ /** * @typedef {Object} HttpApi~HeadOptions * @property [headers] {Record<string, string | string[]>} * @property [params] {Record<string, string | string[]>} */ /** * @typedef {Object} HttpApi~StringGenericRequestOptions * @property [body] {(any|null)} * @property [headers] {Record<string, string | string[]>} * @property [params] {Record<string, string | string[]>} * @property [responseType] {"text"} */ /** * @typedef {Object} HttpApi~JsonGenericRequestOptions * @property [body] {(any|null)} * @property [headers] {Record<string, string | string[]>} * @property [params] {Record<string, string | string[]>} * @property [responseType] {"json"} */ /** * @typedef {Object} HttpApi~BlobGenericRequestOptions * @property [body] {(any|null)} * @property [headers] {Record<string, string | string[]>} * @property [params] {Record<string, string | string[]>} * @property [responseType] {"blob"} */