contentful-management
Version:
Client for Contentful's Content Management API
139 lines (138 loc) • 5.53 kB
TypeScript
import type { ExoCursorPaginatedCollectionProp, GetSpaceEnvironmentParams, GetTemplateParams } from '../../common-types';
import type { CreateTemplateProps, TemplateProps, TemplateQueryOptions, UpsertTemplateProps } from '../../entities/template';
import type { OptionalDefaults } from '../wrappers/wrap';
export type TemplatePlainClientAPI = {
/**
* Fetches all templates for a space and environment
* @param params the space, environment IDs and query options (see {@link TemplateQueryOptions})
* @returns a collection of templates
* @throws if the request fails, or the space or environment is not found
* @internal - Experimental endpoint, subject to breaking changes without notice
* @example
* ```javascript
* const templates = await client.template.getMany({
* spaceId: '<space_id>',
* environmentId: '<environment_id>',
* query: {
* limit: 10,
* },
* });
* ```
*/
getMany(params: OptionalDefaults<GetSpaceEnvironmentParams & {
query: TemplateQueryOptions;
}>): Promise<ExoCursorPaginatedCollectionProp<TemplateProps>>;
/**
* Fetches a single template by ID
* @param params the space, environment, and template IDs
* @returns the template
* @throws if the request fails, or the space, environment, or template is not found
* @internal - Experimental endpoint, subject to breaking changes without notice
* @example
* ```javascript
* const template = await client.template.get({
* spaceId: '<space_id>',
* environmentId: '<environment_id>',
* templateId: '<template_id>',
* });
* ```
*/
get(params: OptionalDefaults<GetTemplateParams>): Promise<TemplateProps>;
/**
* Creates a new template
* @param params the space and environment IDs
* @param data the template data
* @returns the created template
* @throws if the request fails, or the space or environment is not found
* @internal - Experimental endpoint, subject to breaking changes without notice
* @example
* ```javascript
* const template = await client.template.create({
* spaceId: '<space_id>',
* environmentId: '<environment_id>',
* }, {
* name: 'My Template',
* description: 'A new template',
* viewports: [],
* contentProperties: [],
* designProperties: [],
* });
* ```
*/
create(params: OptionalDefaults<GetSpaceEnvironmentParams>, data: CreateTemplateProps): Promise<TemplateProps>;
/**
* Upserts a template (creates or updates via PUT)
* @param params the space, environment, and template IDs
* @param data the template data to upsert (include sys.version for updates, omit for creates)
* @returns the upserted template
* @throws if the request fails
* @internal - Experimental endpoint, subject to breaking changes without notice
* @example
* ```javascript
* const current = await client.template.get({ templateId: '<template_id>' });
* const updated = await client.template.upsert({
* spaceId: '<space_id>',
* environmentId: '<environment_id>',
* templateId: '<template_id>',
* }, {
* sys: { id: current.sys.id, type: 'Template', version: current.sys.version },
* name: 'Updated Template',
* ...otherFields,
* });
* ```
*/
upsert(params: OptionalDefaults<GetTemplateParams>, data: UpsertTemplateProps): Promise<TemplateProps>;
/**
* Deletes a template
* @param params the space, environment, and template IDs
* @throws if the request fails, or the space, environment, or template is not found
* @internal - Experimental endpoint, subject to breaking changes without notice
* @example
* ```javascript
* await client.template.delete({
* spaceId: '<space_id>',
* environmentId: '<environment_id>',
* templateId: '<template_id>',
* });
* ```
*/
delete(params: OptionalDefaults<GetTemplateParams>): Promise<void>;
/**
* Publishes a template
* @param params the space, environment, and template IDs, plus the current version
* @returns the published template
* @throws if the request fails, or the space, environment, or template is not found
* @internal - Experimental endpoint, subject to breaking changes without notice
* @example
* ```javascript
* const template = await client.template.publish({
* spaceId: '<space_id>',
* environmentId: '<environment_id>',
* templateId: '<template_id>',
* version: 1,
* });
* ```
*/
publish(params: OptionalDefaults<GetTemplateParams & {
version: number;
}>): Promise<TemplateProps>;
/**
* Unpublishes a template
* @param params the space, environment, and template IDs, plus the current version
* @returns the unpublished template
* @throws if the request fails, or the space, environment, or template is not found
* @internal - Experimental endpoint, subject to breaking changes without notice
* @example
* ```javascript
* const template = await client.template.unpublish({
* spaceId: '<space_id>',
* environmentId: '<environment_id>',
* templateId: '<template_id>',
* version: 2,
* });
* ```
*/
unpublish(params: OptionalDefaults<GetTemplateParams & {
version: number;
}>): Promise<TemplateProps>;
};