mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: update front layout
This commit is contained in:
9
assets/utils/api/domain.ts
Normal file
9
assets/utils/api/domain.ts
Normal 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
69
assets/utils/api/index.ts
Normal 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
28
assets/utils/api/tld.ts
Normal 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
18
assets/utils/api/user.ts
Normal 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
|
||||
}
|
||||
52
assets/utils/api/watchlist.ts
Normal file
52
assets/utils/api/watchlist.ts
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user