UNPKG

@umbraco/headless-client

Version:
129 lines (128 loc) 3.97 kB
import { ManagementClient, DeliveryClient, AuthenticationClient } from './Clients'; import { Endpoint } from './Endpoint'; /** * Client Options * @public */ export interface ClientOptions { /** * The Project Alias is a HTTP friendly version of the Project Name under your Umbraco Cloud account. */ projectAlias: string; /** * The default culture sent with all requests to the Content Delivery API, this can be overwritten per function */ language?: string; /** * An API Key is requierd when interacting with the Management API and when protection is enabled for the Delivery API */ apiKey?: string; /** * Determines if the {@link DeliveryClient} should call the Preview API or the Content Delivery endpoints. * * @remarks * If true an apiKey must be supplied. */ preview?: boolean; /** * Used to retrieve access tokens for requests to the APIs. * @param request - The request that's about to be sent. * @returns an oauth token that should be used for this request or undefined if no token should be used. */ accessTokenResolver?(request: { data?: any; headers: any; method: 'get' | 'GET' | 'post' | 'POST' | 'put' | 'PUT' | 'delete' | 'DELETE'; url: string; }): string | undefined; } /** * Proxy options * @public */ export interface ProxyOptions { /** * A custom url for the Content Delivery endpoint. */ cdnProxyUrl: string; /** * A custom url for the Content Management endpoint. */ apiProxyUrl: string; /** * The default culture sent with all requests to the Content Delivery API, this can be overwritten per function */ language?: string; } /** * Entry class for accessing the Content Delivery and Content Management APIs. * @public * * @example * * To get started you need create a new instance of the `Client` passing {@link ClientOptions}. * * ```typescript * import { Client } from '@umbraco/headless-client' * * const client = new Client({ * projectAlias: '<your-project-alias>', * apiKey: '<your-api-key>', * language: '<iso-code>', * }) * ``` * * You might want to proxy your request through a server to hide the project alias and the api key, * this can be done by creating a new instance of the `Client` class passing in {@link ProxyOptions}. * * ```typescript * import { Client } from '@umbraco/headless-client' * * const client = new Client({ * apiProxyUrl: '<proxy-url>', * cdnProxyUrl: '<proxy-url>', * language: '<iso-code>', * }) * ``` * */ export declare class Client { readonly options: ClientOptions | ProxyOptions; /** * Constructs a new instance of the `Client` class with the given options. * @param options - The options. See {@link ClientOptions} or {@link ProxyOptions}. */ constructor(options: ClientOptions | ProxyOptions); /** * Get Delivery client for fetching content and media from CDN. * See {@link DeliveryClient} */ readonly delivery: DeliveryClient; /** * Get Manager Client for managing content on Umbraco Heartcore. * See {@link ManagementClient} */ readonly management: ManagementClient; /** * Get Authentication Client for authenticating members and Backoffice users. * See {@link AuthenticationClient} */ readonly authentication: AuthenticationClient; /** * Makes request from and [Endpoint] * @internal */ makeRequest: <R extends unknown>(endpoint: Endpoint<R>, data?: any) => Promise<R>; /** * Sets the API to be used. * @param apikey - API Key * @deprecated Use `apiKey` in the constructor options instead. */ setAPIKey: (apikey: string) => void; /** * @deprecated Use `options.apiKey` instead. */ getAPIKey: () => string | undefined; private readonly getEmbeddedData; private readonly getPagedData; }