-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathclient.ts
More file actions
62 lines (53 loc) · 1.83 KB
/
client.ts
File metadata and controls
62 lines (53 loc) · 1.83 KB
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
'use client';
import { ServiceError } from "@/lib/serviceError";
import { GetVersionResponse, GetReposResponse } from "@/lib/types";
import { isServiceError } from "@/lib/utils";
import {
FileSourceResponse,
FileSourceRequest,
SearchRequest,
SearchResponse,
} from "@/features/search/types";
export const search = async (body: SearchRequest, domain: string): Promise<SearchResponse | ServiceError> => {
const result = await fetch("/api/search", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Org-Domain": domain,
},
body: JSON.stringify(body),
}).then(response => response.json());
if (isServiceError(result)) {
return result;
}
return result as SearchResponse | ServiceError;
}
export const fetchFileSource = async (body: FileSourceRequest, domain: string): Promise<FileSourceResponse | ServiceError> => {
const result = await fetch("/api/source", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Org-Domain": domain,
},
body: JSON.stringify(body),
}).then(response => response.json());
return result as FileSourceResponse | ServiceError;
}
export const getRepos = async (): Promise<GetReposResponse> => {
const result = await fetch("/api/repos", {
method: "GET",
headers: {
"Content-Type": "application/json",
},
}).then(response => response.json());
return result as GetReposResponse | ServiceError;
}
export const getVersion = async (): Promise<GetVersionResponse> => {
const result = await fetch("/api/version", {
method: "GET",
headers: {
"Content-Type": "application/json",
},
}).then(response => response.json());
return result as GetVersionResponse;
}