import type { OpPatch } from 'json-patch'; import type { MakeRequest } from './common-types'; import type { CreateCommentProps } from './entities/comment'; import type { Entry, EntryProps, EntryReferenceOptionsProps } from './entities/entry'; import type { CreateTaskProps } from './entities/task'; /** * @private */ export type ContentfulEntryApi = ReturnType; /** * @private */ export default function createEntryApi(makeRequest: MakeRequest): { /** * Sends an update to the server with any changes made to the object's properties * @return Object returned from the server with updated changes. * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getEnvironment('')) * .then((environment) => environment.getEntry('')) * .then((entry) => { * entry.fields.title['en-US'] = 'New entry title' * return entry.update() * }) * .then((entry) => console.log(`Entry ${entry.sys.id} updated.`)) * .catch(console.error) * ``` */ update: () => Promise; /** * Sends an JSON patch to the server with any changes made to the object's properties * @return Object returned from the server with updated changes. * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getEnvironment('')) * .then((environment) => environment.getEntry('')) * .then((entry) => entry.patch([ * { * op: 'replace', * path: '/fields/title/en-US', * value: 'New entry title' * } * ])) * .then((entry) => console.log(`Entry ${entry.sys.id} updated.`)) * .catch(console.error) * ``` */ patch: (ops: OpPatch[]) => Promise; /** * Deletes this object on the server. * @return Promise for the deletion. It contains no data, but the Promise error case should be handled. * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getEnvironment('')) * .then((environment) => environment.getEntry('')) * .then((entry) => entry.delete()) * .then(() => console.log(`Entry deleted.`)) * .catch(console.error) * ``` */ delete: () => Promise; /** * Publishes the object * @return Object returned from the server with updated metadata. * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getEnvironment('')) * .then((environment) => environment.getEntry('')) * .then((entry) => entry.publish()) * .then((entry) => console.log(`Entry ${entry.sys.id} published.`)) * .catch(console.error) * ``` */ publish: () => Promise; /** * Unpublishes the object * @return Object returned from the server with updated metadata. * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getEnvironment('')) * .then((environment) => environment.getEntry('')) * .then((entry) => entry.unpublish()) * .then((entry) => console.log(`Entry ${entry.sys.id} unpublished.`)) * .catch(console.error) * ``` */ unpublish: () => Promise; /** * Archives the object * @return Object returned from the server with updated metadata. * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getEnvironment('')) * .then((environment) => environment.getEntry('')) * .then((entry) => entry.archive()) * .then((entry) => console.log(`Entry ${entry.sys.id} archived.`)) * .catch(console.error) * ``` */ archive: () => Promise; /** * Unarchives the object * @return Object returned from the server with updated metadata. * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getEnvironment('')) * .then((environment) => environment.getEntry('')) * .then((entry) => entry.unarchive()) * .then((entry) => console.log(`Entry ${entry.sys.id} unarchived.`)) * .catch(console.error) * ``` */ unarchive: () => Promise; /** * Gets all snapshots of an entry * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getEnvironment('')) * .then((environment) => environment.getEntry('')) * .then((entry) => entry.getSnapshots()) * .then((snapshots) => console.log(snapshots.items)) * .catch(console.error) * ``` */ getSnapshots: (query?: {}) => Promise, import("./export-types").SnapshotProps>>; /** * Gets a snapshot of an entry * @param snapshotId - Id of the snapshot * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getEnvironment('')) * .then((environment) => environment.getEntry('')) * .then((entry) => entry.getSnapshot('')) * .then((snapshot) => console.log(snapshot)) * .catch(console.error) * ``` */ getSnapshot: (snapshotId: string) => Promise>; /** * Creates a new comment for an entry * @param data Object representation of the Comment to be created * @returns Promise for the newly created Comment * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getEnvironment('')) * .then((environment) => environment.getEntry('')) * .then((entry) => entry.createComment({ * body: 'Something left to do' * })) * .then((comment) => console.log(comment)) * .catch(console.error) * ``` */ createComment: (data: CreateCommentProps) => Promise; /** * Gets all comments of an entry * @returns * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getEnvironment('')) * .then((environment) => environment.getEntry('')) * .then((entry) => entry.getComments()) * .then((comments) => console.log(comments)) * .catch(console.error) * ``` */ getComments: () => Promise>; /** * Gets a comment of an entry * @returns * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getEnvironment('')) * .then((environment) => environment.getEntry('')) * .then((entry) => entry.getComment(``)) * .then((comment) => console.log(comment)) * .catch(console.error) * ``` */ getComment: (id: string) => Promise; /** * Creates a new task for an entry * @param data Object representation of the Task to be created * @returns Promise for the newly created Task * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getEnvironment('')) * .then((environment) => environment.getEntry('')) * .then((entry) => entry.createTask({ * body: 'Something left to do', * assignedTo: '', * status: 'active' * })) * .then((task) => console.log(task)) * .catch(console.error) * ``` */ createTask: (data: CreateTaskProps) => Promise; /** * Gets all tasks of an entry * @returns * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getEnvironment('')) * .then((environment) => environment.getEntry('')) * .then((entry) => entry.getTasks()) * .then((tasks) => console.log(tasks)) * .catch(console.error) * ``` */ getTasks: (query?: {}) => Promise>; /** * Gets a task of an entry * @returns * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getEnvironment('')) * .then((environment) => environment.getEntry('')) * .then((entry) => entry.getTask(``)) * .then((task) => console.log(task)) * .catch(console.error) * ``` */ getTask: (id: string) => Promise; /** * Checks if the entry is published. A published entry might have unpublished changes */ isPublished: () => boolean; /** * Checks if the entry is updated. This means the entry was previously published but has unpublished changes. */ isUpdated: () => boolean; /** * Checks if the entry is in draft mode. This means it is not published. */ isDraft: () => boolean; /** * Checks if entry is archived. This means it's not exposed to the Delivery/Preview APIs. */ isArchived: () => boolean; /** * Recursively collects references of an entry and their descendants */ references: (options?: EntryReferenceOptionsProps) => Promise>>; };