writekit/frontends/studio/src/stores/apiKeys.ts
Josh bef5dd4437 refactor: move studio to frontends workspace
- Move studio from root to frontends/studio/
- Add owner-tools frontend for live blog admin UI
- Add shared ui component library
- Set up npm workspaces for frontends
- Add enhanced code block extension for editor

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 02:06:19 +02:00

34 lines
1.1 KiB
TypeScript

import { atom } from 'nanostores'
import { createFetcherStore, createMutatorStore, invalidateKeys } from './fetcher'
import type { APIKey } from '../types'
export const $apiKeys = createFetcherStore<APIKey[]>(['/api/studio/api-keys'])
export const $creating = atom(false)
export const $newKey = atom<string | null>(null)
export async function createAPIKey(name: string): Promise<APIKey> {
$creating.set(true)
try {
const res = await fetch('/api/studio/api-keys', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name }),
})
if (!res.ok) throw new Error('Failed to create API key')
const key = await res.json()
$newKey.set(key.key)
invalidateKeys('/api/studio/api-keys')
return key
} finally {
$creating.set(false)
}
}
export const $deleteAPIKey = createMutatorStore<string>(
async ({ data: key, invalidate }) => {
const res = await fetch(`/api/studio/api-keys/${key}`, { method: 'DELETE' })
if (!res.ok) throw new Error('Failed to delete API key')
invalidate('/api/studio/api-keys')
}
)