Merge branch 'renovate/all-minor-patch' into 'main'
[ProtonMail-WebClient.git] / packages / docs-core / lib / Api / Routes / DocsApiPrivateRouteBuilder.ts
blobf84f1c183158618243e24dd54c52ec6ef1807f7a
1 import type { CommentThreadType, CommonPrivateCommentData, CreatePrivateCommentData } from '../Types/Comments'
2 import { DocsApiRouteBuilder } from './DocsApiRouteBuilder'
3 import type { DocsRoute } from './DocsRoute'
5 /**
6  * For private authenticated routes.
7  */
8 export class DocsApiPrivateRouteBuilder extends DocsApiRouteBuilder {
9   constructor(params: { volumeId: string; linkId: string }) {
10     super(`docs/volumes/${params.volumeId}/documents/${params.linkId}`)
11   }
13   meta(): DocsRoute {
14     return {
15       method: 'get',
16       url: `${this.basePath}/meta`,
17       silence: true,
18     }
19   }
21   commit(params: { commitId: string }): DocsRoute {
22     return {
23       method: 'get',
24       url: `${this.basePath}/commits/${params.commitId}`,
25       output: 'raw',
26       silence: true,
27     }
28   }
30   seedInitialCommit(params: { data: Uint8Array }): DocsRoute {
31     return {
32       method: 'post',
33       url: `${this.basePath}/seed-initial-commit`,
34       input: 'protobuf',
35       data: params.data,
36     }
37   }
39   lock(params: { fetchCommitId?: string }): DocsRoute {
40     return {
41       method: 'post',
42       url: `${this.basePath}/lock`,
43       data: { FetchCommitID: params.fetchCommitId },
44       output: 'raw',
45       silence: true,
46     }
47   }
49   squashCommit(params: { commitId: string; data: Uint8Array }): DocsRoute {
50     return {
51       method: 'put',
52       url: `${this.basePath}/commits/${params.commitId}/squash`,
53       input: 'protobuf',
54       data: params.data,
55     }
56   }
58   createDocument(): DocsRoute {
59     return {
60       method: 'post',
61       url: `${this.basePath}`,
62       silence: true,
63       data: {},
64     }
65   }
67   getCommentThreads(): DocsRoute {
68     return {
69       method: 'get',
70       url: `${this.basePath}/threads`,
71     }
72   }
74   createThread(params: {
75     data: { Mark: string; Comment: CreatePrivateCommentData; Type: CommentThreadType }
76   }): DocsRoute {
77     return {
78       method: 'post',
79       url: `${this.basePath}/threads`,
80       data: params.data,
81     }
82   }
84   deleteThread(params: { threadId: string }): DocsRoute {
85     return {
86       method: 'delete',
87       url: `${this.basePath}/threads/${params.threadId}`,
88     }
89   }
91   addComment(params: {
92     threadId: string
93     data: CreatePrivateCommentData & { ParentCommentId: string | null }
94   }): DocsRoute {
95     return {
96       method: 'post',
97       url: `${this.basePath}/threads/${params.threadId}`,
98       data: params.data,
99     }
100   }
102   getThread(params: { threadId: string }): DocsRoute {
103     return {
104       method: 'get',
105       url: `${this.basePath}/threads/${params.threadId}`,
106     }
107   }
109   resolveThread(params: { threadId: string }): DocsRoute {
110     return {
111       method: 'put',
112       url: `${this.basePath}/threads/${params.threadId}/resolve`,
113     }
114   }
116   editComment(params: { threadId: string; commentId: string; data: CommonPrivateCommentData }): DocsRoute {
117     return {
118       method: 'put',
119       url: `${this.basePath}/threads/${params.threadId}/comments/${params.commentId}`,
120       data: params.data,
121     }
122   }
124   unresolveThread(params: { threadId: string }): DocsRoute {
125     return {
126       method: 'put',
127       url: `${this.basePath}/threads/${params.threadId}/unresolve`,
128     }
129   }
131   changeSuggestionState(params: { threadId: string; action: 'accept' | 'reject' | 'reopen' }): DocsRoute {
132     return {
133       method: 'put',
134       url: `${this.basePath}/threads/${params.threadId}/suggestion/${params.action}`,
135     }
136   }
138   deleteComment(params: { threadId: string; commentId: string }): DocsRoute {
139     return {
140       method: 'delete',
141       url: `${this.basePath}/threads/${params.threadId}/comments/${params.commentId}`,
142     }
143   }
145   createRealtimeValetToken(params: { commitId?: string }): DocsRoute {
146     return {
147       method: 'post',
148       url: `${this.basePath}/tokens`,
149       data: { LastCommitID: params.commitId ?? null },
150       silence: true,
151     }
152   }