🎉 Init
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
import axios from 'axios'
|
||||
|
||||
export const apiClient = axios.create({
|
||||
baseURL: '/api',
|
||||
})
|
||||
@@ -0,0 +1,13 @@
|
||||
import axios from 'axios'
|
||||
|
||||
const ERROR_MESSAGES: Record<string, string> = {
|
||||
secret_conflict: 'Ein Secret mit diesem Namen existiert bereits in einem der ausgewählten Namespaces.',
|
||||
}
|
||||
|
||||
export function extractErrorMessage(error: unknown): string {
|
||||
if (axios.isAxiosError(error) && typeof error.response?.data?.error === 'string') {
|
||||
const key = error.response.data.error
|
||||
return ERROR_MESSAGES[key] ?? key
|
||||
}
|
||||
return 'Etwas ist schiefgelaufen.'
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { apiClient } from './client'
|
||||
|
||||
export function exportSecrets(): Promise<Blob> {
|
||||
return apiClient.get('/_export', { responseType: 'blob' }).then((response) => response.data)
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { apiClient } from './client'
|
||||
|
||||
export function importSecrets(secrets: unknown): Promise<void> {
|
||||
return apiClient.post('/_import', secrets).then(() => undefined)
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { apiClient } from './client'
|
||||
import type { Secret } from '../types/Secret'
|
||||
|
||||
interface SecretResponse {
|
||||
id: string
|
||||
name: string
|
||||
namespaces: string[]
|
||||
contentHash: string
|
||||
entries: Record<string, string>
|
||||
type: string
|
||||
}
|
||||
|
||||
function toSecret(response: SecretResponse): Secret {
|
||||
return {
|
||||
id: response.id,
|
||||
name: response.name,
|
||||
namespaces: response.namespaces,
|
||||
contentHash: response.contentHash,
|
||||
entries: Object.entries(response.entries).map(([key, value]) => ({ key, value })),
|
||||
type: response.type,
|
||||
}
|
||||
}
|
||||
|
||||
export function getSecrets(searchText?: string): Promise<Secret[]> {
|
||||
return apiClient
|
||||
.get<SecretResponse[]>('/secrets', { params: { searchText } })
|
||||
.then((response) => response.data.map(toSecret))
|
||||
}
|
||||
|
||||
export interface SecretCreatePayload {
|
||||
name: string
|
||||
namespaces: string[]
|
||||
entries: Record<string, string>
|
||||
type: string
|
||||
}
|
||||
|
||||
export function createSecret(payload: SecretCreatePayload): Promise<void> {
|
||||
return apiClient.post('/secrets', payload).then(() => undefined)
|
||||
}
|
||||
|
||||
export function updateSecret(id: string, payload: SecretCreatePayload): Promise<void> {
|
||||
return apiClient.put(`/secrets/${id}`, payload).then(() => undefined)
|
||||
}
|
||||
|
||||
export function deleteSecret(id: string): Promise<void> {
|
||||
return apiClient.delete(`/secrets/${id}`).then(() => undefined)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { apiClient } from './client'
|
||||
|
||||
export function getVerificationValue(): Promise<string | null> {
|
||||
return apiClient
|
||||
.get<{ value: string } | ''>('/verification', { validateStatus: (status) => status === 200 || status === 204 })
|
||||
.then((response) => (response.status === 204 ? null : (response.data as { value: string }).value))
|
||||
}
|
||||
|
||||
export function setVerificationValue(value: string): Promise<void> {
|
||||
return apiClient.post('/verification', { value }).then(() => undefined)
|
||||
}
|
||||
Reference in New Issue
Block a user