UNPKG

acquia-dam-sdk

Version:
72 lines (69 loc) 2.45 kB
import { ApiVersions, ApiRequestParams, ErrorTypes } from './types.js'; /** * Manages client-server communication. This class should not be modified directly. * @class */ declare class ApiClient { private _accessToken; readonly __sdkIdentifier = "dam-ts@development"; baseUrlMap: Map<ApiVersions, string>; constructor(accessToken?: string); /** * Sets the collective key in the v1 API Base URL * @param key The collective key */ private set _collectiveKey(value); /** * Sets the current access token. * @param token The Personal Access Token obtained from the DAM Admin UI or the Access Token obtained from the OAuth Authorization Code Flow. */ set accessToken(token: string); /** * Sends a request to the DAM API * @param requestParams Information about the request to send * @returns The data in the response body */ sendRequest<T>(requestParams: ApiRequestParams): Promise<T>; /** * Builds the full URL to send to the server * @param requestParams Information about the request * @returns The full URL to send */ protected buildUrl(requestParams: ApiRequestParams): string; /** * Builds the request headers * @param requestParams Information about the request * @returns The necessary headers including authentication */ protected buildHeaders(requestParams: ApiRequestParams): Headers; /** * Builds the request body * @param requestParams Information about the request * @returns The request body to send to the server */ protected buildBody(requestParams: ApiRequestParams): string | FormData; /** * Builds the request query string * @param params The request parameters * @returns The query string */ protected buildParams(params: object): Record<string, string>; /** * Parse the HTTP Response body * @param response The fetch API HTTP Response * @returns The body content */ protected parseBody<T>(response: Response): Promise<T>; /** * Transforms all timestamps into date objects * @param value The value to transform */ private parseBodyValues; } declare class AcquiaDAMError extends Error { statusCode?: number; body?: unknown; type: ErrorTypes; constructor(type: ErrorTypes, statusCode?: number, body?: object | string); } export { AcquiaDAMError, ApiClient };