feat: update front layout

This commit is contained in:
Maël Gangloff
2024-07-25 02:09:49 +02:00
parent 465aeb1ec9
commit 08da62c1b5
18 changed files with 405 additions and 168 deletions

View File

@@ -0,0 +1,9 @@
import {Domain, request} from ".";
export async function getDomain(ldhName: string): Promise<Domain> {
const response = await request<Domain>({
url: 'domains/' + ldhName
})
return response.data
}

69
assets/utils/api/index.ts Normal file
View File

@@ -0,0 +1,69 @@
import axios, {AxiosRequestConfig, AxiosResponse} from "axios";
export interface Event {
action: string
date: string
}
export interface Entity {
handle: string
events: Event[]
roles: string[]
}
export interface Nameserver {
ldhName: string
entities: Entity[]
}
export interface Tld {
tld: string
contractTerminated: boolean
dateOfContractSignature: string
registryOperator: string
delegationDate: string
removalDate: string
specification13: boolean
type: string
}
export interface Domain {
ldhName: string
handle: string
status: string[]
events: Event[]
entities: Entity[]
nameservers: Nameserver[]
tld: Tld
}
export interface User {
email: string
roles: string[]
}
export interface Watchlist {
domains: string[]
triggers: Event[]
}
export async function request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig): Promise<R> {
const axiosConfig: AxiosRequestConfig = {
...config,
baseURL: '/api',
withCredentials: true,
headers: {
...config.headers,
Accept: 'application/json'
}
}
return await axios.request<T, R, D>(axiosConfig)
}
export * from './domain'
export * from './tld'
export * from './user'
export * from './watchlist'

28
assets/utils/api/tld.ts Normal file
View File

@@ -0,0 +1,28 @@
import {request} from "./index";
interface Tld {
tld: string
contractTerminated: boolean
registryOperator: string
specification13: boolean
}
export async function getTldList(params: object): Promise<Tld[]> {
let page = 1
let response = (await request<Tld[]>({
url: 'tld',
params: {...params, page},
})).data
const tldList: Tld[] = response;
while (response.length !== 0) {
page++
response = (await request<Tld[]>({
url: 'tld',
params: {...params, page},
})).data
tldList.push(...response)
}
return tldList
}

18
assets/utils/api/user.ts Normal file
View File

@@ -0,0 +1,18 @@
import {request, User} from "./index";
export async function login(email: string, password: string): Promise<boolean> {
const response = await request({
method: 'POST',
url: 'login',
data: {email, password}
})
return response.status === 200
}
export async function getUser(): Promise<User> {
const response = await request<User>({
url: 'me'
})
return response.data
}

View File

@@ -0,0 +1,52 @@
import {Event, request, Watchlist} from "./index";
export async function getWatchlists() {
const response = await request<{ token: string }[]>({
url: 'watchlists'
})
return response.data
}
export async function getWatchlist(token: string) {
const response = await request<Watchlist>({
url: 'watchlists/' + token
})
return response.data
}
export async function postWatchlist(domains: string[], triggers: Event[]) {
const response = await request<{ token: string }>({
method: 'POST',
url: 'watchlists',
data: {
domains,
triggers
},
headers: {
"Content-Type": 'application/json'
}
})
return response.data
}
export async function deleteWatchlist(token: string): Promise<void> {
await request({
method: 'DELETE',
url: 'watchlists/' + token
})
}
export async function patchWatchlist(domains: string[], triggers: Event[]) {
const response = await request<Watchlist>({
method: 'PATCH',
url: 'watchlists',
data: {
domains,
triggers
},
headers: {
"Content-Type": 'application/merge-patch+json'
}
})
return response.data
}