UNPKG

8.37 kBTypeScriptView Raw
1import { Except, SetOptional } from 'type-fest';
2import { BasicMetaSysProps, Collection, DefaultElements, MakeRequest, SysLink } from '../common-types';
3import { ContentFields } from './content-type-fields';
4import { EditorInterface } from './editor-interface';
5import { Snapshot, SnapshotProps } from './snapshot';
6export declare type ContentTypeProps = {
7 sys: BasicMetaSysProps & {
8 space: SysLink;
9 environment: SysLink;
10 firstPublishedAt?: string;
11 publishedCounter?: number;
12 publishedVersion?: number;
13 };
14 name: string;
15 description: string;
16 /** Field used as the main display field for Entries */
17 displayField: string;
18 /** All the fields contained in this Content Type */
19 fields: ContentFields[];
20};
21export declare type CreateContentTypeProps = SetOptional<Except<ContentTypeProps, 'sys'>, 'description' | 'displayField'>;
22declare type ContentTypeApi = {
23 /**
24 * Sends an update to the server with any changes made to the object's properties. <br />
25 * <strong>Important note about deleting fields</strong>: The standard way to delete a field is with two updates: first omit the property from your responses (set the field attribute "omitted" to true), and then
26 * delete it by setting the attribute "deleted" to true. See the "Deleting fields" section in the
27 * <a href="https://www.contentful.com/developers/docs/references/content-management-api/#/reference/content-types/content-type">API reference</a> for more reasoning. Alternatively,
28 * you may use the convenience method omitAndDeleteField to do both steps at once.
29 * @return Object returned from the server with updated changes.
30 * @example ```javascript
31 * const contentful = require('contentful-management')
32 *
33 * const client = contentful.createClient({
34 * accessToken: '<content_management_api_key>'
35 * })
36 *
37 * client.getSpace('<space_id>')
38 * .then((space) => space.getEnvironment('<environment_id>'))
39 * .then((environment) => environment.getContentType('<contentType_id>'))
40 * .then((contentType) => {
41 * contentType.name = 'New name'
42 * return contentType.update()
43 * })
44 * .then(contentType => console.log(contentType))
45 * .catch(console.error)
46 * ```
47 */
48 update(): Promise<ContentType>;
49 /**
50 * Deletes this object on the server.
51 * @return Promise for the deletion. It contains no data, but the Promise error case should be handled.
52 * @example ```javascript
53 * const contentful = require('contentful-management')
54 *
55 * const client = contentful.createClient({
56 * accessToken: '<content_management_api_key>'
57 * })
58 *
59 * client.getSpace('<space_id>')
60 * .then((space) => space.getEnvironment('<environment_id>'))
61 * .then((environment) => environment.getContentType('<contentType_id>'))
62 * .then((contentType) => contentType.delete())
63 * .then(() => console.log('contentType deleted'))
64 * .catch(console.error)
65 * ```
66 */
67 delete(): Promise<void>;
68 /**
69 * Publishes the object
70 * @return Object returned from the server with updated metadata.
71 * @example ```javascript
72 * const contentful = require('contentful-management')
73 *
74 * const client = contentful.createClient({
75 * accessToken: '<content_management_api_key>'
76 * })
77 *
78 * client.getSpace('<space_id>')
79 * .then((space) => space.getEnvironment('<environment_id>'))
80 * .then((environment) => environment.getContentType('<contentType_id>'))
81 * .then((contentType) => contentType.publish())
82 * .then((contentType) => console.log(`${contentType.sys.id} is published`))
83 * .catch(console.error)
84 * ```
85 */
86 publish(): Promise<ContentType>;
87 /**
88 * Unpublishes the object
89 * @return Object returned from the server with updated metadata.
90 * @example ```javascript
91 * const contentful = require('contentful-management')
92 *
93 * const client = contentful.createClient({
94 * accessToken: '<content_management_api_key>'
95 * })
96 *
97 * client.getSpace('<space_id>')
98 * .then((space) => space.getEnvironment('<environment_id>'))
99 * .then((environment) => environment.getContentType('<contentType_id>'))
100 * .then((contentType) => contentType.unpublish())
101 * .then((contentType) => console.log(`${contentType.sys.id} is unpublished`))
102 * .catch(console.error)
103 * ```
104 */
105 unpublish(): Promise<ContentType>;
106 /**
107 * Gets the editor interface for the object <br />
108 * <strong>Important note</strong>: The editor interface only represent a published contentType.<br />
109 * To get the most recent representation of the contentType make sure to publish it first
110 * @return Object returned from the server with the current editor interface.
111 * @example ```javascript
112 * const contentful = require('contentful-management')
113 *
114 * const client = contentful.createClient({
115 * accessToken: '<content_management_api_key>'
116 * })
117 *
118 * client.getSpace('<space_id>')
119 * .then((space) => space.getEnvironment('<environment_id>'))
120 * .then((environment) => environment.getContentType('<contentType_id>'))
121 * .then((contentType) => contentType.getEditorInterface())
122 * .then((editorInterface) => console.log(editorInterface.contorls))
123 * .catch(console.error)
124 * ```
125 */
126 getEditorInterface(): Promise<EditorInterface>;
127 /**
128 * Checks if the contentType is in draft mode. This means it is not published.
129 */
130 isDraft(): boolean;
131 /**
132 * Checks if the contentType is published. A published contentType might have unpublished changes (@see {ContentType.isUpdated})
133 */
134 isPublished(): boolean;
135 /**
136 * Checks if the contentType is updated. This means the contentType was previously published but has unpublished changes.
137 */
138 isUpdated(): boolean;
139 /**
140 * Omits and deletes a field if it exists on the contentType. This is a convenience method which does both operations at once and potentially less
141 * safe than the standard way. See note about deleting fields on the Update method.
142 * @return Object returned from the server with updated metadata.
143 */
144 omitAndDeleteField(id: string): Promise<ContentType>;
145 /**
146 * Gets a snapshot of a contentType
147 * @param snapshotId - Id of the snapshot
148 * @example ```javascript
149 * const contentful = require('contentful-management')
150 *
151 * const client = contentful.createClient({
152 * accessToken: '<content_management_api_key>'
153 * })
154 *
155 * client.getSpace('<space_id>')
156 * .then((space) => space.getEnvironment('<environment_id>'))
157 * .then((environment) => environment.getContentType('<contentType_id>'))
158 * .then((entry) => entry.getSnapshot('<snapshot-id>'))
159 * .then((snapshot) => console.log(snapshot))
160 * .catch(console.error)
161 * ```
162 */
163 getSnapshot(snapshotId: string): Promise<SnapshotProps<ContentTypeProps>>;
164 /**
165 * Gets all snapshots of a contentType
166 * @example ```javascript
167 * const contentful = require('contentful-management')
168 *
169 * const client = contentful.createClient({
170 * accessToken: '<content_management_api_key>'
171 * })
172 *
173 * client.getSpace('<space_id>')
174 * .then((space) => space.getEnvironment('<environment_id>'))
175 * .then((environment) => environment.getContentType('<contentType_id>'))
176 * .then((entry) => entry.getSnapshots())
177 * .then((snapshots) => console.log(snapshots.items))
178 * .catch(console.error)
179 * ```
180 */
181 getSnapshots(): Promise<Collection<Snapshot<ContentTypeProps>, SnapshotProps<ContentTypeProps>>>;
182};
183export interface ContentType extends ContentTypeProps, DefaultElements<ContentTypeProps>, ContentTypeApi {
184}
185/**
186 * @private
187 * @param makeRequest - function to make requests via an adapter
188 * @param data - Raw content type data
189 * @return Wrapped content type data
190 */
191export declare function wrapContentType(makeRequest: MakeRequest, data: ContentTypeProps): ContentType;
192/**
193 * @private
194 */
195export declare const wrapContentTypeCollection: (makeRequest: MakeRequest, data: import("../common-types").CollectionProp<ContentTypeProps>) => Collection<ContentType, ContentTypeProps>;
196export {};