feat(SPA): screen to manage API keys (PART 2/3)
This commit is contained in:
1 parent
844842fdae
commit
514a082c96
30 files changed
+3844
-83
No files matched your search
@@ -0,0 +1,54 @@
|
||||
import { useApi } from '@/composables/useApi'
|
||||
|
||||
export type ApiKeyStatus = 'active' | 'expired' | 'revoked'
|
||||
|
||||
export interface ApiKey {
|
||||
id: number
|
||||
user_id: number
|
||||
name: string
|
||||
prefix: string
|
||||
status: ApiKeyStatus
|
||||
created_at: string
|
||||
last_used_at: string | null
|
||||
expires_at: string | null
|
||||
revoked_at: string | null
|
||||
created_by_name?: string
|
||||
}
|
||||
|
||||
export interface CreatedApiKey {
|
||||
id: number
|
||||
name: string
|
||||
prefix: string
|
||||
key: string
|
||||
created_at: string
|
||||
expires_at: string | null
|
||||
}
|
||||
|
||||
export interface CreateApiKeyInput {
|
||||
name: string
|
||||
expires_at?: string
|
||||
}
|
||||
|
||||
export const API_KEY_SKELETON_ROWS = 4
|
||||
|
||||
export function useApiKeys() {
|
||||
const { request } = useApi()
|
||||
|
||||
function listApiKeys(): Promise<ApiKey[]> {
|
||||
return request<ApiKey[]>('/v1/api-key')
|
||||
}
|
||||
|
||||
function createApiKey(input: CreateApiKeyInput): Promise<CreatedApiKey> {
|
||||
return request<CreatedApiKey>('/v1/api-key', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(input),
|
||||
})
|
||||
}
|
||||
|
||||
function revokeApiKey(id: number): Promise<void> {
|
||||
return request<void>(`/v1/api-key/${id}`, { method: 'DELETE' })
|
||||
}
|
||||
|
||||
return { listApiKeys, createApiKey, revokeApiKey }
|
||||
}
|
||||
Reference in new issue
Block a user