This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
150 lines (128 loc) · 4.76 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import { SuperVizSdkOptions } from '../../common/types/sdk-options.types';
import { doRequest } from '../../common/utils';
import { Annotation } from '../../components/comments/types';
import config from '../config';
import {
AnnotationParams,
CommentParams,
CreateOrUpdateParticipantParams,
FetchAnnotationsParams,
MentionParams
} from './types';
export default class ApiService {
static createUrl(baseUrl: string, path: string, query = {}): string {
const url = new URL(path, baseUrl);
Object.keys(query).forEach((key) => url.searchParams.append(key, query[key]));
return url.toString();
}
static validateApiKey(baseUrl: string, apiKey: string) {
const path: string = '/user/checkapikey';
const url: string = this.createUrl(baseUrl, path);
return doRequest(url, 'POST', { apiKey });
}
static fetchConfig(baseUrl: string, apiKey: string) {
const path: string = '/immersive-config';
const url: string = this.createUrl(baseUrl, path);
return doRequest(url, 'POST', { apiKey });
}
static async fetchLimits(baseUrl: string, apikey: string) {
const path: string = '/user/check_limits';
const url: string = this.createUrl(baseUrl, path);
const result = await doRequest(url, 'GET', '', { apikey });
return result.usage;
}
static async fetchWaterMark(baseUrl: string, apiKey: string) {
const path = '/user/watermark';
const url = this.createUrl(baseUrl, path);
const { message } = await doRequest(url, 'POST', { apiKey });
return message;
}
static async createAnnotations(baseUrl: string, apiKey: string, annotations: AnnotationParams) {
const path = '/annotations';
const url = this.createUrl(baseUrl, path);
return doRequest(url, 'POST', { ...annotations }, { apikey: apiKey });
}
static async updateComment(baseUrl: string, apiKey: string, commentId: string, text: string) {
const path = `/comments/${commentId}`;
const url = this.createUrl(baseUrl, path);
return doRequest(
url,
'PUT',
{
text,
},
{ apikey: apiKey },
);
}
static async createComment(baseUrl: string, apiKey: string, comment: CommentParams) {
const path = '/comments';
const url = this.createUrl(baseUrl, path);
return doRequest(url, 'POST', { ...comment }, { apikey: apiKey });
}
static async fetchAnnotation(baseUrl: string, apiKey: string, query: FetchAnnotationsParams) {
const path = '/annotations';
const url = this.createUrl(baseUrl, path, {
roomId: query.roomId,
url: query.url,
});
return doRequest(url, 'GET', undefined, { apikey: apiKey });
}
static async resolveAnnotation(
baseUrl: string,
apiKey: string,
annotationId: string,
): Promise<Annotation> {
const path = `/annotations/resolve/${annotationId}`;
const url = this.createUrl(baseUrl, path);
return doRequest(url, 'POST', {}, { apikey: apiKey });
}
static async deleteComment(baseUrl: string, apiKey: string, commentId: string) {
const path = `/comments/${commentId}`;
const url = this.createUrl(baseUrl, path);
return doRequest(url, 'DELETE', {}, { apikey: apiKey });
}
static async deleteAnnotation(baseUrl: string, apiKey: string, annotationId: string) {
const path = `/annotations/${annotationId}`;
const url = this.createUrl(baseUrl, path);
return doRequest(url, 'DELETE', {}, { apikey: apiKey });
}
static async createOrUpdateParticipant(
participant: CreateOrUpdateParticipantParams,
): Promise<void> {
const baseUrl = config.get<string>('apiUrl');
const path = '/participants';
const url = this.createUrl(baseUrl, path);
return doRequest(url, 'POST', { ...participant }, { apikey: config.get<string>('apiKey') });
}
static async sendActivity(userId: string, groupId: string, groupName: string, product: string) {
const path = '/activity';
const baseUrl = config.get<string>('apiUrl');
const meetingId = config.get<string>('roomId');
const apikey = config.get<string>('apiKey');
const url = this.createUrl(baseUrl, path);
const body = {
groupId,
groupName,
meetingId,
product,
userId,
};
return doRequest(url, 'POST', body, { apikey });
}
static async fetchParticipantsByGroup(
groupId: string,
) {
const path = `/groups/participants/${groupId}`;
const baseUrl = config.get<string>('apiUrl');
const url = this.createUrl(baseUrl, path, { take: 10000 });
return doRequest(url, 'GET', undefined, { apikey: config.get('apiKey') });
}
static async createMentions(
mentionParams: MentionParams
) {
const path = '/mentions';
const baseUrl = config.get<string>('apiUrl');
const url = this.createUrl(baseUrl, path);
return doRequest(url, 'POST', mentionParams, { apikey: config.get('apiKey') });
}
}