UNPKG

contentful-management

Version:
103 lines (102 loc) 3.68 kB
import type { Node, Text } from '@contentful/rich-text-types'; import type { BasicMetaSysProps, DefaultElements, GetCommentParams, GetEntryParams, GetSpaceEnvironmentParams, Link, MakeRequest, SysLink, VersionedLink } from '../common-types'; interface LinkWithReference<T extends string> extends Link<T> { sys: Link<T>['sys'] & { ref: string; }; } export type CommentSysProps = Pick<BasicMetaSysProps, 'id' | 'version' | 'createdAt' | 'createdBy' | 'updatedAt' | 'updatedBy'> & { type: 'Comment'; space: SysLink; environment: SysLink; parentEntity: Link<'ContentType'> | LinkWithReference<'ContentType'> | Link<'Entry'> | LinkWithReference<'Entry'> | VersionedLink<'Workflow'>; parent: Link<'Comment'> | null; }; export type PlainTextBodyProperty = 'plain-text'; export type RichTextBodyProperty = 'rich-text'; export type RichTextBodyFormat = { bodyFormat: RichTextBodyProperty; }; export type PlainTextBodyFormat = { bodyFormat?: PlainTextBodyProperty; }; export type CommentStatus = 'active' | 'resolved'; export type CommentProps = { sys: CommentSysProps; body: string; status: CommentStatus; }; export type CreateCommentProps = Omit<CommentProps, 'sys' | 'status'> & { status?: CommentStatus; }; export type UpdateCommentProps = Omit<CommentProps, 'sys'> & { sys: Pick<CommentSysProps, 'version'>; }; export declare enum CommentNode { Document = "document", Paragraph = "paragraph", Mention = "mention" } export interface Mention { nodeType: CommentNode.Mention; data: { target: Link<'User'> | Link<'Team'>; }; content: Text[]; } export interface RootParagraph extends Node { nodeType: CommentNode.Paragraph; content: (Text | Mention)[]; } export interface RichTextCommentDocument extends Node { nodeType: CommentNode.Document; content: RootParagraph[]; } export type RichTextCommentBodyPayload = { body: RichTextCommentDocument; }; export type RichTextCommentProps = Omit<CommentProps, 'body'> & RichTextCommentBodyPayload; export type GetCommentParentEntityParams = GetSpaceEnvironmentParams & ({ parentEntityType: 'ContentType'; parentEntityId: string; parentEntityReference?: string; } | { parentEntityType: 'Entry'; parentEntityId: string; parentEntityReference?: string; } | { parentEntityType: 'Workflow'; parentEntityId: string; parentEntityVersion?: number; }); export type GetManyCommentsParams = (GetEntryParams | GetCommentParentEntityParams) & { status?: CommentStatus; }; export type CreateCommentParams = (GetEntryParams | GetCommentParentEntityParams) & { parentCommentId?: string; }; export type UpdateCommentParams = GetCommentParams; export type DeleteCommentParams = GetCommentParams & { version: number; }; type CommentApi = { update(): Promise<Comment | RichTextComment>; delete(): Promise<void>; }; export interface Comment extends CommentProps, DefaultElements<CommentProps>, CommentApi { } export interface RichTextComment extends Omit<CommentProps, 'body'>, RichTextCommentProps, DefaultElements<CommentProps>, CommentApi { } /** * @private */ export default function createCommentApi(makeRequest: MakeRequest): CommentApi; /** * @private */ export declare function wrapComment(makeRequest: MakeRequest, data: CommentProps | RichTextCommentProps): Comment | RichTextComment; /** * @private */ export declare const wrapCommentCollection: (makeRequest: MakeRequest, data: import("../common-types").CollectionProp<CommentProps | RichTextCommentProps>) => import("../common-types").Collection<Comment | RichTextComment, CommentProps | RichTextCommentProps>; export {};