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