63 lines
1.6 KiB
TypeScript
Raw Normal View History

2024-12-30 23:50:15 +01:00
import {request} from './index'
2024-12-31 13:55:42 +01:00
import type {ConnectorElement} from '../../components/tracking/connector/ConnectorsList'
2024-07-29 19:04:50 +02:00
2024-07-30 00:55:36 +02:00
export enum ConnectorProvider {
2025-01-06 22:58:00 +01:00
OVHcloud = 'ovh',
Gandi = 'gandi',
AutoDNS = 'autodns',
Namecheap = 'namecheap',
2025-02-24 22:18:49 +01:00
'Name.com' = 'namecom',
EPP = 'epp'
2024-07-29 19:04:50 +02:00
}
2024-12-30 23:50:15 +01:00
export interface Connector {
2024-07-29 19:04:50 +02:00
provider: ConnectorProvider
2025-02-25 22:29:22 +01:00
authData: Record<string, Record<string, string>>,
objURI?: { key: string, value: string }[],
extURI?: { key: string, value: string }[]
2024-07-29 19:04:50 +02:00
}
2024-12-30 23:50:15 +01:00
interface ConnectorResponse {
'hydra:totalItems': number
'hydra:member': ConnectorElement[]
}
export async function getConnectors(): Promise<ConnectorResponse> {
const response = await request<ConnectorResponse>({
2024-07-29 19:04:50 +02:00
url: 'connectors'
})
return response.data
}
export async function postConnector(connector: Connector) {
2025-02-25 22:29:22 +01:00
for (const key of ['objURI', 'extURI'] as (keyof Connector)[]) {
if (key in connector) {
const obj = connector[key] as { key: string, value: string }[]
connector.authData[key] = obj.reduce((acc: { [key: string]: string }, x) => ({
...acc,
[x.key]: x.value
}), {})
delete connector[key]
}
}
2024-07-29 19:04:50 +02:00
const response = await request<Connector & { id: string }>({
method: 'POST',
url: 'connectors',
data: connector,
headers: {
2024-12-30 23:50:15 +01:00
'Content-Type': 'application/json'
2024-07-29 19:04:50 +02:00
}
})
return response.data
}
export async function deleteConnector(token: string): Promise<void> {
await request({
method: 'DELETE',
url: 'connectors/' + token
})
}