import FormData from 'form-data'; import { Client } from '../../Client'; import { PagedResponse, ContentManagementContent, ContentManagementContentRequest } from '../../Responses'; import { APIContentChildrenOptions, APIContentPublishOptions, APIContentUnpublishOptions } from '../../RequestOptions'; /** * ContentManagementClient is used to access the Content part of the Content Management API. * @public * * @example * The {@link ContentManagementClient} must be accessed through {@link Client}. * * ```typescript * import { Client } from '@umbraco/headless-client' * * const client = new Client({ * projectAlias: '', * apiKey: '', * language: '', * }) * * const contentClient = client.management.content * ``` */ export declare class ContentManagementClient { private readonly client; /** * @internal */ constructor(client: Client); private readonly makeRequest; /** * Fetch all content at the root of the tree, which the authorized user has access to according to the 'Start node'-permissions. * @returns a `Promise` that resolves to an array of {@link ContentManagementContent}, */ root(): Promise; /** * Fetch a single Content item by its id. * @param id - GUID id of the Content item. * @returns a `Promise` that resolves to a {@link ContentManagementContent} if found, otherwise `undefined`. */ byId(id: string): Promise; /** * Fetch all children of a Content item. * @param id - GUID id of the Content item. * @param options - Request options. See {@link APIContentChildrenOptions}. * @returns a `Promise` that resolves to a {@link PagedResponse} of {@link ContentManagementContent} if found, otherwise `undefined`. */ children(id: string, options?: APIContentChildrenOptions): Promise | undefined>; /** * Create a new Content item. * @param body - The Content to create. See {@link ContentManagementContentRequest}. * @returns a `Promise` that resolves to the newly created {@link ContentManagementContent}. * * @example * ```typescript * const content = await client.management.content.create({ * name: { * $invariant: '', * }, * contentTypeAlias: '', * parentId: '', * }) * ``` * * If the Content Type includes an `Upload` or an `Image Cropper` property and you want to upload a file you need to pass a `FormData` object to the function instead, * * ```typescript * import FormData from `form-data` * import fs from 'fs' * import path from 'path' * * const data = new FormData() * * data.append(JSON.stringify({ * name: { * $invariant: '', * }, * contentTypeAlias: '', * parentId: '', * // if myFile is of type `Upload` and is culture variant * myFile: { * 'en-US': 'my-file.txt', * }, * // if myImage is of type `Image Cropper` and is culture invariant * myImage: { * $invariant: { * src: 'my-image.jpg', * }, * }, * })) * * data.append('myFile.en-US', fs.createReadStream(path.join(__dirname, 'my-file.txt'))) * data.append('myImage.$invariant', fs.createReadStream(path.join(__dirname, 'my-image.txt'))) * * const content = await client.management.content.create(data) * ``` * * See {@link https://our.umbraco.com/documentation/Umbraco-Heartcore/API-Documentation/Content-Management/content/#create-content} for more info on the structure of the document. */ create(body: ContentManagementContentRequest | FormData): Promise; /** * Publish a Content item. * @param id - GUID id of the Content item. * @param options - Request options. See {@link APIContentPublishOptions}. * @returns a `Promise` that resolves to a {@link ContentManagementContent} if found, otherwise `undefined`. */ publish(id: string, options?: APIContentPublishOptions): Promise; /** * Unpublish a Content item. * @param id - GUID id of the Content item. * @param options - Request options. See {@link APIContentPublishOptions}. * @returns a `Promise` that resolves to a {@link ContentManagementContent} if found, otherwise `undefined`. */ unPublish(id: string, options?: APIContentUnpublishOptions): Promise; /** * Update a Content item. * @param id - GUID id of the Content item. * @param body - Content to update, must be a complete Content item including all cultures. See {@link ContentManagementContentRequest}. * @returns a `Promise` that resolves to a {@link ContentManagementContent} of the updated Content item if found, otherwise `undefined`. * * @example * ```typescript * const content = await client.management.content.update('', { * name: { * $invariant: '', * }, * contentTypeAlias: '', * parentId: '', * }) * ``` * * If the Content Type includes an `Upload` or an `Image Cropper` property and you want to upload a file you need to pass a `FormData` object to the function instead, * * ```typescript * import FormData from `form-data` * import fs from 'fs' * import path from 'path' * * const data = new FormData() * * data.append(JSON.stringify({ * name: { * $invariant: '', * }, * contentTypeAlias: '', * parentId: '', * // if myFile is of type `Upload` and is culture variant * myFile: { * 'en-US': 'my-file.txt', * }, * // if myImage is of type `Image Cropper` and is culture invariant * myImage: { * $invariant: { * src: 'my-image.jpg', * }, * }, * })) * * data.append('myFile.en-US', fs.createReadStream(path.join(__dirname, 'my-file.txt'))) * data.append('myImage.$invariant', fs.createReadStream(path.join(__dirname, 'my-image.txt'))) * * const content = await client.management.content.update('', data) * ``` * * See {@link https://our.umbraco.com/documentation/Umbraco-Heartcore/API-Documentation/Content-Management/content/#update-content} for more info on the structure of the document. */ update(id: string, body: ContentManagementContentRequest | FormData): Promise; /** * Delete a Content item. * @param id - GUID id of the Content item. * @returns a `Promise` that resolves to a {@link ContentManagementContent} of the deleted Content item if found, otherwise `undefined`. */ delete(id: string): Promise; }