2024-11-18 20:09:26 +00:00
|
|
|
'use client';
|
|
|
|
|
|
2025-01-28 17:04:27 +00:00
|
|
|
import { fileSourceResponseSchema, getVersionResponseSchema, listRepositoriesResponseSchema, searchResponseSchema } from "@/lib/schemas";
|
|
|
|
|
import { FileSourceRequest, FileSourceResponse, GetVersionResponse, ListRepositoriesResponse, SearchRequest, SearchResponse } from "@/lib/types";
|
2024-09-10 06:16:41 +00:00
|
|
|
|
2025-02-12 21:05:44 +00:00
|
|
|
export const search = async (body: SearchRequest, domain: string): Promise<SearchResponse> => {
|
2025-03-18 04:22:05 +00:00
|
|
|
const result = await fetch("/api/search", {
|
2024-09-10 06:16:41 +00:00
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
2025-02-12 21:05:44 +00:00
|
|
|
"X-Org-Domain": domain,
|
2024-09-10 06:16:41 +00:00
|
|
|
},
|
|
|
|
|
body: JSON.stringify(body),
|
2025-03-07 17:23:55 +00:00
|
|
|
}).then(response => response.json());
|
2024-09-10 06:16:41 +00:00
|
|
|
|
|
|
|
|
return searchResponseSchema.parse(result);
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-12 21:05:44 +00:00
|
|
|
export const fetchFileSource = async (body: FileSourceRequest, domain: string): Promise<FileSourceResponse> => {
|
2025-03-18 04:22:05 +00:00
|
|
|
const result = await fetch("/api/source", {
|
2024-09-10 06:16:41 +00:00
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
2025-02-12 21:05:44 +00:00
|
|
|
"X-Org-Domain": domain,
|
2024-09-10 06:16:41 +00:00
|
|
|
},
|
2024-11-07 02:28:10 +00:00
|
|
|
body: JSON.stringify(body),
|
2024-09-10 06:16:41 +00:00
|
|
|
}).then(response => response.json());
|
|
|
|
|
|
|
|
|
|
return fileSourceResponseSchema.parse(result);
|
2024-09-11 05:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
2025-02-12 21:05:44 +00:00
|
|
|
export const getRepos = async (domain: string): Promise<ListRepositoriesResponse> => {
|
2025-03-18 04:22:05 +00:00
|
|
|
const result = await fetch("/api/repos", {
|
2024-09-11 05:59:17 +00:00
|
|
|
method: "GET",
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
2025-02-12 21:05:44 +00:00
|
|
|
"X-Org-Domain": domain,
|
2024-09-11 05:59:17 +00:00
|
|
|
},
|
|
|
|
|
}).then(response => response.json());
|
|
|
|
|
|
|
|
|
|
return listRepositoriesResponseSchema.parse(result);
|
|
|
|
|
}
|
2024-11-18 20:09:26 +00:00
|
|
|
|
2025-01-28 17:04:27 +00:00
|
|
|
export const getVersion = async (): Promise<GetVersionResponse> => {
|
2025-03-18 04:22:05 +00:00
|
|
|
const result = await fetch("/api/version", {
|
2025-01-28 17:04:27 +00:00
|
|
|
method: "GET",
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
},
|
|
|
|
|
}).then(response => response.json());
|
|
|
|
|
return getVersionResponseSchema.parse(result);
|
|
|
|
|
}
|