UNPKG

@zerokurns/unlayer-ts-client

Version:

TypeScript client library for the Unlayer Cloud API

90 lines (89 loc) 4.4 kB
import * as T from './types'; /** * Main client for interacting with the Unlayer Cloud API v2. */ export declare class UnlayerClient { private readonly apiKey; private readonly httpClient; /** * Creates an instance of the Unlayer API client. * @param apiKey - Your Unlayer Project API Key. * @param baseURL - Optional base URL for the API (defaults to production v2 URL). * @param timeout - Optional request timeout in milliseconds (defaults to 60000). */ constructor(apiKey: string, baseURL?: string, timeout?: number); /** * Private helper method to make requests and handle errors. * @param method - HTTP method ('get', 'post'). * @param path - API endpoint path (e.g., '/templates'). * @param params - Query parameters for GET requests. * @param data - Request body data for POST requests. * @returns Promise resolving to the API response data. */ private request; /** * Export a design to HTML format. * Corresponds to `POST /export/html` * @param payload - The export options and design JSON. * @returns The exported HTML and associated chunks. * @throws {UnlayerApiError} If the API request fails. * @see https://docs.unlayer.com/reference/export-html # Replace with actual docs link if available */ exportHtml(payload: T.ExportHtmlRequest): Promise<T.ExportHtmlResponse>; /** * Export a design to image (PNG) format. * Corresponds to `POST /export/image` * @param payload - The export options and design JSON. * @returns An object containing the URL of the generated image. * @throws {UnlayerApiError} If the API request fails. * @see https://docs.unlayer.com/reference/export-image # Replace with actual docs link if available */ exportImage(payload: T.ExportImageRequest): Promise<T.ExportImageResponse>; /** * Export a design to PDF format. * Corresponds to `POST /export/pdf` * @param payload - The export options and design JSON. * @returns An object containing the URL of the generated PDF. * @throws {UnlayerApiError} If the API request fails. * @see https://docs.unlayer.com/reference/export-pdf # Replace with actual docs link if available */ exportPdf(payload: T.ExportPdfRequest): Promise<T.ExportPdfResponse>; /** * Export a design as a ZIP archive containing HTML and assets. * Corresponds to `POST /export/zip` * @param payload - The export options and design JSON. * @returns An object containing the URL of the generated ZIP archive. * @throws {UnlayerApiError} If the API request fails. * @see https://docs.unlayer.com/reference/export-zip # Replace with actual docs link if available */ exportZip(payload: T.ExportZipRequest): Promise<T.ExportZipResponse>; /** * Get a list of available templates, optionally paginated. * Corresponds to `GET /templates` * @param params - Query parameters for pagination and design inclusion. * @returns An object containing a list of templates. * @throws {UnlayerApiError} If the API request fails. * @see https://docs.unlayer.com/reference/list-templates # Replace with actual docs link if available */ listTemplates(params?: T.ListTemplatesParams): Promise<T.ListTemplatesResponse>; /** * Get a specific template by its ID. * Corresponds to `GET /templates/{id}` * @param id - The ID of the template to retrieve. * @returns The specific template details including the design JSON. * @throws {UnlayerApiError} If the API request fails. * @throws {Error} If the template ID is not provided. * @see https://docs.unlayer.com/reference/get-template # Replace with actual docs link if available */ getTemplate(id: string): Promise<T.GetTemplateResponse>; /** * Render the HTML for a specific template. * Corresponds to `GET /templates/{id}/render` * @param id - The ID of the template to render. * @returns The rendered HTML, chunks, and AMP details. * @throws {UnlayerApiError} If the API request fails. * @throws {Error} If the template ID is not provided. * @see https://docs.unlayer.com/reference/render-template-html # Replace with actual docs link if available */ renderTemplateHtml(id: string): Promise<T.RenderTemplateHtmlResponse>; }