1 | import type { OpPatch } from 'json-patch';
|
2 | import type { MakeRequest } from './common-types';
|
3 | import type { CreateCommentProps } from './entities/comment';
|
4 | import type { Entry, EntryProps, EntryReferenceOptionsProps } from './entities/entry';
|
5 | import type { CreateTaskProps } from './entities/task';
|
6 | /**
|
7 | * @private
|
8 | */
|
9 | export type ContentfulEntryApi = ReturnType<typeof createEntryApi>;
|
10 | /**
|
11 | * @private
|
12 | */
|
13 | export default function createEntryApi(makeRequest: MakeRequest): {
|
14 | /**
|
15 | * Sends an update to the server with any changes made to the object's properties
|
16 | * @return Object returned from the server with updated changes.
|
17 | * @example ```javascript
|
18 | * const contentful = require('contentful-management')
|
19 | *
|
20 | * const client = contentful.createClient({
|
21 | * accessToken: '<content_management_api_key>'
|
22 | * })
|
23 | *
|
24 | * client.getSpace('<space_id>')
|
25 | * .then((space) => space.getEnvironment('<environment_id>'))
|
26 | * .then((environment) => environment.getEntry('<entry_id>'))
|
27 | * .then((entry) => {
|
28 | * entry.fields.title['en-US'] = 'New entry title'
|
29 | * return entry.update()
|
30 | * })
|
31 | * .then((entry) => console.log(`Entry ${entry.sys.id} updated.`))
|
32 | * .catch(console.error)
|
33 | * ```
|
34 | */
|
35 | update: () => Promise<Entry>;
|
36 | /**
|
37 | * Sends an JSON patch to the server with any changes made to the object's properties
|
38 | * @return Object returned from the server with updated changes.
|
39 | * @example ```javascript
|
40 | * const contentful = require('contentful-management')
|
41 | *
|
42 | * const client = contentful.createClient({
|
43 | * accessToken: '<content_management_api_key>'
|
44 | * })
|
45 | *
|
46 | * client.getSpace('<space_id>')
|
47 | * .then((space) => space.getEnvironment('<environment_id>'))
|
48 | * .then((environment) => environment.getEntry('<entry_id>'))
|
49 | * .then((entry) => entry.patch([
|
50 | * {
|
51 | * op: 'replace',
|
52 | * path: '/fields/title/en-US',
|
53 | * value: 'New entry title'
|
54 | * }
|
55 | * ]))
|
56 | * .then((entry) => console.log(`Entry ${entry.sys.id} updated.`))
|
57 | * .catch(console.error)
|
58 | * ```
|
59 | */
|
60 | patch: (ops: OpPatch[]) => Promise<Entry>;
|
61 | /**
|
62 | * Deletes this object on the server.
|
63 | * @return Promise for the deletion. It contains no data, but the Promise error case should be handled.
|
64 | * @example ```javascript
|
65 | * const contentful = require('contentful-management')
|
66 | *
|
67 | * const client = contentful.createClient({
|
68 | * accessToken: '<content_management_api_key>'
|
69 | * })
|
70 | *
|
71 | * client.getSpace('<space_id>')
|
72 | * .then((space) => space.getEnvironment('<environment_id>'))
|
73 | * .then((environment) => environment.getEntry('<entry_id>'))
|
74 | * .then((entry) => entry.delete())
|
75 | * .then(() => console.log(`Entry deleted.`))
|
76 | * .catch(console.error)
|
77 | * ```
|
78 | */
|
79 | delete: () => Promise<any>;
|
80 | /**
|
81 | * Publishes the object
|
82 | * @return Object returned from the server with updated metadata.
|
83 | * @example ```javascript
|
84 | * const contentful = require('contentful-management')
|
85 | *
|
86 | * const client = contentful.createClient({
|
87 | * accessToken: '<content_management_api_key>'
|
88 | * })
|
89 | *
|
90 | * client.getSpace('<space_id>')
|
91 | * .then((space) => space.getEnvironment('<environment_id>'))
|
92 | * .then((environment) => environment.getEntry('<entry_id>'))
|
93 | * .then((entry) => entry.publish())
|
94 | * .then((entry) => console.log(`Entry ${entry.sys.id} published.`))
|
95 | * .catch(console.error)
|
96 | * ```
|
97 | */
|
98 | publish: () => Promise<Entry>;
|
99 | /**
|
100 | * Unpublishes the object
|
101 | * @return Object returned from the server with updated metadata.
|
102 | * @example ```javascript
|
103 | * const contentful = require('contentful-management')
|
104 | *
|
105 | * const client = contentful.createClient({
|
106 | * accessToken: '<content_management_api_key>'
|
107 | * })
|
108 | *
|
109 | * client.getSpace('<space_id>')
|
110 | * .then((space) => space.getEnvironment('<environment_id>'))
|
111 | * .then((environment) => environment.getEntry('<entry_id>'))
|
112 | * .then((entry) => entry.unpublish())
|
113 | * .then((entry) => console.log(`Entry ${entry.sys.id} unpublished.`))
|
114 | * .catch(console.error)
|
115 | * ```
|
116 | */
|
117 | unpublish: () => Promise<Entry>;
|
118 | /**
|
119 | * Archives the object
|
120 | * @return Object returned from the server with updated metadata.
|
121 | * @example ```javascript
|
122 | * const contentful = require('contentful-management')
|
123 | *
|
124 | * const client = contentful.createClient({
|
125 | * accessToken: '<content_management_api_key>'
|
126 | * })
|
127 | *
|
128 | * client.getSpace('<space_id>')
|
129 | * .then((space) => space.getEnvironment('<environment_id>'))
|
130 | * .then((environment) => environment.getEntry('<entry_id>'))
|
131 | * .then((entry) => entry.archive())
|
132 | * .then((entry) => console.log(`Entry ${entry.sys.id} archived.`))
|
133 | * .catch(console.error)
|
134 | * ```
|
135 | */
|
136 | archive: () => Promise<Entry>;
|
137 | /**
|
138 | * Unarchives the object
|
139 | * @return Object returned from the server with updated metadata.
|
140 | * @example ```javascript
|
141 | * const contentful = require('contentful-management')
|
142 | *
|
143 | * const client = contentful.createClient({
|
144 | * accessToken: '<content_management_api_key>'
|
145 | * })
|
146 | *
|
147 | * client.getSpace('<space_id>')
|
148 | * .then((space) => space.getEnvironment('<environment_id>'))
|
149 | * .then((environment) => environment.getEntry('<entry_id>'))
|
150 | * .then((entry) => entry.unarchive())
|
151 | * .then((entry) => console.log(`Entry ${entry.sys.id} unarchived.`))
|
152 | * .catch(console.error)
|
153 | * ```
|
154 | */
|
155 | unarchive: () => Promise<Entry>;
|
156 | /**
|
157 | * Gets all snapshots of an entry
|
158 | * @example ```javascript
|
159 | * const contentful = require('contentful-management')
|
160 | *
|
161 | * const client = contentful.createClient({
|
162 | * accessToken: '<content_management_api_key>'
|
163 | * })
|
164 | *
|
165 | * client.getSpace('<space_id>')
|
166 | * .then((space) => space.getEnvironment('<environment_id>'))
|
167 | * .then((environment) => environment.getEntry('<entry_id>'))
|
168 | * .then((entry) => entry.getSnapshots())
|
169 | * .then((snapshots) => console.log(snapshots.items))
|
170 | * .catch(console.error)
|
171 | * ```
|
172 | */
|
173 | getSnapshots: (query?: {}) => Promise<import("./common-types").Collection<import("./export-types").Snapshot<EntryProps>, import("./export-types").SnapshotProps<EntryProps>>>;
|
174 | /**
|
175 | * Gets a snapshot of an entry
|
176 | * @param snapshotId - Id of the snapshot
|
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.getEntry('<entry_id>'))
|
187 | * .then((entry) => entry.getSnapshot('<snapshot_id>'))
|
188 | * .then((snapshot) => console.log(snapshot))
|
189 | * .catch(console.error)
|
190 | * ```
|
191 | */
|
192 | getSnapshot: (snapshotId: string) => Promise<import("./export-types").Snapshot<EntryProps>>;
|
193 | /**
|
194 | * Creates a new comment for an entry
|
195 | * @param data Object representation of the Comment to be created
|
196 | * @returns Promise for the newly created Comment
|
197 | * @example ```javascript
|
198 | * const contentful = require('contentful-management')
|
199 | *
|
200 | * const client = contentful.createClient({
|
201 | * accessToken: '<content_management_api_key>'
|
202 | * })
|
203 | *
|
204 | * client.getSpace('<space_id>')
|
205 | * .then((space) => space.getEnvironment('<environment-id>'))
|
206 | * .then((environment) => environment.getEntry('<entry-id>'))
|
207 | * .then((entry) => entry.createComment({
|
208 | * body: 'Something left to do'
|
209 | * }))
|
210 | * .then((comment) => console.log(comment))
|
211 | * .catch(console.error)
|
212 | * ```
|
213 | */
|
214 | createComment: (data: CreateCommentProps) => Promise<import("./entities/comment").Comment | import("./entities/comment").RichTextComment>;
|
215 | /**
|
216 | * Gets all comments of an entry
|
217 | * @returns
|
218 | * const contentful = require('contentful-management')
|
219 | *
|
220 | * const client = contentful.createClient({
|
221 | * accessToken: '<content_management_api_key>'
|
222 | * })
|
223 | *
|
224 | * client.getSpace('<space_id>')
|
225 | * .then((space) => space.getEnvironment('<environment-id>'))
|
226 | * .then((environment) => environment.getEntry('<entry-id>'))
|
227 | * .then((entry) => entry.getComments())
|
228 | * .then((comments) => console.log(comments))
|
229 | * .catch(console.error)
|
230 | * ```
|
231 | */
|
232 | getComments: () => Promise<import("./common-types").Collection<import("./entities/comment").Comment | import("./entities/comment").RichTextComment, import("./entities/comment").CommentProps | import("./entities/comment").RichTextCommentProps>>;
|
233 | /**
|
234 | * Gets a comment of an entry
|
235 | * @returns
|
236 | * const contentful = require('contentful-management')
|
237 | *
|
238 | * const client = contentful.createClient({
|
239 | * accessToken: '<content_management_api_key>'
|
240 | * })
|
241 | *
|
242 | * client.getSpace('<space_id>')
|
243 | * .then((space) => space.getEnvironment('<environment-id>'))
|
244 | * .then((environment) => environment.getEntry('<entry-id>'))
|
245 | * .then((entry) => entry.getComment(`<comment-id>`))
|
246 | * .then((comment) => console.log(comment))
|
247 | * .catch(console.error)
|
248 | * ```
|
249 | */
|
250 | getComment: (id: string) => Promise<import("./entities/comment").Comment | import("./entities/comment").RichTextComment>;
|
251 | /**
|
252 | * Creates a new task for an entry
|
253 | * @param data Object representation of the Task to be created
|
254 | * @returns Promise for the newly created Task
|
255 | * @example ```javascript
|
256 | * const contentful = require('contentful-management')
|
257 | *
|
258 | * const client = contentful.createClient({
|
259 | * accessToken: '<content_management_api_key>'
|
260 | * })
|
261 | *
|
262 | * client.getSpace('<space_id>')
|
263 | * .then((space) => space.getEnvironment('<environment-id>'))
|
264 | * .then((environment) => environment.getEntry('<entry-id>'))
|
265 | * .then((entry) => entry.createTask({
|
266 | * body: 'Something left to do',
|
267 | * assignedTo: '<user-id>',
|
268 | * status: 'active'
|
269 | * }))
|
270 | * .then((task) => console.log(task))
|
271 | * .catch(console.error)
|
272 | * ```
|
273 | */
|
274 | createTask: (data: CreateTaskProps) => Promise<import("./entities/task").Task>;
|
275 | /**
|
276 | * Gets all tasks of an entry
|
277 | * @returns
|
278 | * const contentful = require('contentful-management')
|
279 | *
|
280 | * const client = contentful.createClient({
|
281 | * accessToken: '<content_management_api_key>'
|
282 | * })
|
283 | *
|
284 | * client.getSpace('<space_id>')
|
285 | * .then((space) => space.getEnvironment('<environment-id>'))
|
286 | * .then((environment) => environment.getEntry('<entry-id>'))
|
287 | * .then((entry) => entry.getTasks())
|
288 | * .then((tasks) => console.log(tasks))
|
289 | * .catch(console.error)
|
290 | * ```
|
291 | */
|
292 | getTasks: (query?: {}) => Promise<import("./common-types").Collection<import("./entities/task").Task, import("./entities/task").TaskProps>>;
|
293 | /**
|
294 | * Gets a task of an entry
|
295 | * @returns
|
296 | * const contentful = require('contentful-management')
|
297 | *
|
298 | * const client = contentful.createClient({
|
299 | * accessToken: '<content_management_api_key>'
|
300 | * })
|
301 | *
|
302 | * client.getSpace('<space_id>')
|
303 | * .then((space) => space.getEnvironment('<environment-id>'))
|
304 | * .then((environment) => environment.getEntry('<entry-id>'))
|
305 | * .then((entry) => entry.getTask(`<task-id>`))
|
306 | * .then((task) => console.log(task))
|
307 | * .catch(console.error)
|
308 | * ```
|
309 | */
|
310 | getTask: (id: string) => Promise<import("./entities/task").Task>;
|
311 | /**
|
312 | * Checks if the entry is published. A published entry might have unpublished changes
|
313 | */
|
314 | isPublished: () => boolean;
|
315 | /**
|
316 | * Checks if the entry is updated. This means the entry was previously published but has unpublished changes.
|
317 | */
|
318 | isUpdated: () => boolean;
|
319 | /**
|
320 | * Checks if the entry is in draft mode. This means it is not published.
|
321 | */
|
322 | isDraft: () => boolean;
|
323 | /**
|
324 | * Checks if entry is archived. This means it's not exposed to the Delivery/Preview APIs.
|
325 | */
|
326 | isArchived: () => boolean;
|
327 | /**
|
328 | * Recursively collects references of an entry and their descendants
|
329 | */
|
330 | references: (options?: EntryReferenceOptionsProps) => Promise<import("./common-types").Collection<Entry, EntryProps<import("./common-types").KeyValueMap>>>;
|
331 | };
|