Merge branch 'renovate/all-minor-patch' into 'main'
[ProtonMail-WebClient.git] / packages / docs-core / lib / Api / Routes / DocsApiPublicRouteBuilder.ts
blobe5a4e4208284b1370e6e348fbeaf82480db91e9b
1 import type { CommentThreadType, CommonPublicCommentData, CreatePublicCommentData } from '../Types/Comments'
2 import type { DocsRoute } from './DocsRoute'
3 import { DocsApiRouteBuilder } from './DocsApiRouteBuilder'
5 /** For public token-based routes */
6 export class DocsApiPublicRouteBuilder extends DocsApiRouteBuilder {
7   private headers: { [key: string]: string }
9   constructor(params: { token: string; linkId: string; headers: { [key: string]: string } }) {
10     super(`docs/urls/${params.token}/documents/${params.linkId}`)
11     this.headers = params.headers
12   }
14   meta(): DocsRoute {
15     return {
16       method: 'get',
17       url: `${this.basePath}/meta`,
18       silence: true,
19       headers: this.headers,
20     }
21   }
23   commit(params: { commitId: string }): DocsRoute {
24     return {
25       method: 'get',
26       url: `${this.basePath}/commits/${params.commitId}`,
27       output: 'raw',
28       silence: true,
29       headers: this.headers,
30     }
31   }
33   /** Returns the IDs of all threads in the document */
34   getCommentThreads(): DocsRoute {
35     return {
36       method: 'get',
37       url: `${this.basePath}/threads`,
38       headers: this.headers,
39     }
40   }
42   createThread(params: {
43     data: { Mark: string; Comment: CreatePublicCommentData; Type: CommentThreadType }
44   }): DocsRoute {
45     return {
46       method: 'post',
47       url: `${this.basePath}/threads`,
48       data: params.data,
49       headers: this.headers,
50     }
51   }
53   addComment(params: {
54     threadId: string
55     data: CreatePublicCommentData & { ParentCommentId: string | null }
56   }): DocsRoute {
57     return {
58       method: 'post',
59       url: `${this.basePath}/threads/${params.threadId}`,
60       data: params.data,
61       headers: this.headers,
62     }
63   }
65   editComment(params: { threadId: string; commentId: string; data: CommonPublicCommentData }): DocsRoute {
66     return {
67       method: 'put',
68       url: `${this.basePath}/threads/${params.threadId}/comments/${params.commentId}`,
69       data: params.data,
70       headers: this.headers,
71     }
72   }
74   getThread(params: { threadId: string }): DocsRoute {
75     return {
76       method: 'get',
77       url: `${this.basePath}/threads/${params.threadId}`,
78       headers: this.headers,
79     }
80   }
82   resolveThread(params: { threadId: string }): DocsRoute {
83     return {
84       method: 'put',
85       url: `${this.basePath}/threads/${params.threadId}/resolve`,
86       headers: this.headers,
87     }
88   }
90   deleteThread(params: { threadId: string }): DocsRoute {
91     return {
92       method: 'delete',
93       url: `${this.basePath}/threads/${params.threadId}`,
94     }
95   }
97   unresolveThread(params: { threadId: string }): DocsRoute {
98     return {
99       method: 'put',
100       url: `${this.basePath}/threads/${params.threadId}/unresolve`,
101       headers: this.headers,
102     }
103   }
105   changeSuggestionState(params: { threadId: string; action: 'accept' | 'reject' | 'reopen' }): DocsRoute {
106     return {
107       method: 'put',
108       url: `${this.basePath}/threads/${params.threadId}/suggestion/${params.action}`,
109       headers: this.headers,
110     }
111   }
113   deleteComment(params: { threadId: string; commentId: string }): DocsRoute {
114     return {
115       method: 'delete',
116       url: `${this.basePath}/threads/${params.threadId}/comments/${params.commentId}`,
117       headers: this.headers,
118     }
119   }
121   createRealtimeValetToken(params: { commitId?: string }): DocsRoute {
122     return {
123       method: 'post',
124       url: `${this.basePath}/tokens`,
125       data: { LastCommitID: params.commitId ?? null },
126       silence: true,
127       headers: this.headers,
128     }
129   }