UNPKG

@seancrowe/chiliconnector-base

Version:

Wrapper around Fetch for working with CHILI publish web services

90 lines (89 loc) 3.84 kB
/// <reference types="node" /> type ChiliRequestConfig = { timeout?: number; method?: Method; parameters?: Record<string, string>; // eslint-disable-next-line @typescript-eslint/ban-types body?: string | object | null; mode?: Mode; }; type BaseRequestSettings = { mode?: Mode; timeout?: number; headers?: Headers; }; type Method = `GET` | `HEAD` | `POST` | `DELETE` | `OPTIONS` | `PUT`; type Mode = "cors" | "same-origin"; declare class ChiliResponse { private readonly _response; private readonly _isNode; constructor(response: Response); get ok(): boolean; get headers(): Headers; get redirected(): boolean; get status(): number; get statusText(): string; get type(): "basic" | "cors" | "default" | "error" | "opaque" | "opaqueredirect"; get url(): string; clone(): ChiliResponse; get streamUsed(): boolean; readAsNodeStream(): NodeJS.ReadableStream | null; readAsBrowserStream(): ReadableStream<Uint8Array> | null; readAsStream(): ReadableStream<Uint8Array> | NodeJS.ReadableStream | null; get body(): ReadableStream<Uint8Array> | NodeJS.ReadableStream | null; readAsArrayBuffer(): Promise<ArrayBuffer>; arrayBuffer(): Promise<ArrayBuffer>; readAsBlob(): Promise<Blob>; blob(): Promise<Blob>; readAsString(): Promise<string>; text(): Promise<string>; readAsJson(): Promise<Record<string, any>>; json(): Promise<Record<string, any>>; private static _jsonifyResponse; } declare class ChiliFetch { protected readonly _basePath: string; protected readonly _defaultHeaders: Headers; protected readonly _defaultTimeout: number; protected readonly _defaultMode: Mode; constructor(basePath: string, baseRequestSettings?: BaseRequestSettings); set apiKey(apikey: string | null); get apiKey(): string | null; private static _encode; fetch(path: string, chiliRequestConfig?: ChiliRequestConfig): Promise<ChiliResponse>; } declare abstract class ChiliConnector { // eslint-disable-next-line @typescript-eslint/ban-types abstract api: object; protected _basePath: string; protected readonly _chiliFetch: ChiliFetch; protected constructor(basePath: string, baseRequestSettings?: BaseRequestSettings); abstract isConnectionGood(throwError: boolean): Promise<boolean>; set apiKey(apiKey: string | null); get apiKey(): string | null; } declare function isConnectionGoodV1(basePath: string, throwError: boolean): Promise<boolean>; declare namespace ChiliTypes { type ChiliRequestConfig = { timeout?: number; method?: Method; parameters?: Record<string, string>; // eslint-disable-next-line @typescript-eslint/ban-types body?: string | object | null; mode?: Mode; }; type BaseRequestSettings = { mode?: Mode; timeout?: number; headers?: Headers; }; type RequestOptions = { mode?: Mode; timeout?: number; }; type Method = `GET` | `HEAD` | `POST` | `DELETE` | `OPTIONS` | `PUT`; type Mode = "cors" | "same-origin"; type ResourceNameV1 = "Users" | "UserGroups" | "DataSources" | "DynamicAssetProviders" | "XinetSettings" | "SwitchServerSettings" | "PdfExportSettings" | "HtmlExportSettings" | "IdmlExportSettings" | "OdfExportSettings" | "ImageConversionProfiles" | "DocumentTemplates" | "ImageTransformations" | "BarcodeTypes" | "OdtImportSettings" | "StructuredTextImportSettings" | "DocumentConstraints" | "ThreeDModels" | "FoldingSettings" | "Documents" | "Fonts" | "WorkSpaces" | "ViewPreferences" | "Assets"; type RestAPIVersion1 = "1" | "1.1"; } export { isConnectionGoodV1, ChiliTypes, ChiliConnector, ChiliFetch, ChiliResponse };