Em dashes (—) and en dashes (–) had spread across comments, docs, tests, and a few UI strings, reading as AI-generated boilerplate rather than house style. Replaced each with punctuation matching its context: colon for explanatory clauses, comma for asides, plain hyphen for numeric/legal ranges (e.g. "21-23§"), "to"/"till" for date ranges, parentheses for paired-dash asides. messages/en.json and messages/sv.json were fixed by hand together to keep sv/en in sync. Left untouched where the dash is the functional subject rather than decorative punctuation: date-range-parser.ts's separator regex, charset-repair.ts's CP1252 byte-mapping table (and its test), the SIE encoding mojibake docs, generic-csv.ts's minus-sign normalizer, the agent system-prompt files that already instruct against em dashes, and a golden iXBRL test fixture compared byte-for-byte. Also fixes two bugs surfaced along the way: an off-by-one in ApiKeysPanel's scope-label split (a leftover from an earlier partial pass), and a charset-repair test that had lost the literal en-dash it exists to verify. Regenerated the agent atom seed migration (skills:generate) since 27 SKILL.md files changed. Added a CLAUDE.md rule against em/en dashes, with an explicit carve-out for the functional-dash cases above. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
95 lines
3.2 KiB
TypeScript
95 lines
3.2 KiB
TypeScript
import { createClient } from '@/lib/supabase/server'
|
|
import { NextResponse } from 'next/server'
|
|
import { requireWritePermission } from '@/lib/auth/require-write'
|
|
import { z } from 'zod'
|
|
|
|
/**
|
|
* GET /api/settings/oauth-clients: list the current user's registered
|
|
* redirect URIs.
|
|
* POST /api/settings/oauth-clients: register a new redirect URI for use
|
|
* with the MCP OAuth flow.
|
|
*
|
|
* Built-in patterns (claude.ai, claude.com, localhost) bypass this table
|
|
* entirely: registrations here are only for self-hosted custom apps.
|
|
*/
|
|
|
|
const RegistrationSchema = z.object({
|
|
client_name: z.string().trim().min(1).max(100),
|
|
// Reject loopback first (covers http:// too) so the user gets the helpful
|
|
// "already allowed" message instead of being told to use https for localhost.
|
|
// Non-loopback URIs must use https.
|
|
redirect_uri: z
|
|
.string()
|
|
.url('redirect_uri must be a valid URL')
|
|
.refine(
|
|
(u) => !/^https?:\/\/(localhost|127\.0\.0\.1|\[::1\]|::1)(:|\/|$)/i.test(u),
|
|
'localhost är redan tillåtet utan registrering'
|
|
)
|
|
.refine((u) => u.startsWith('https://'), 'redirect_uri måste använda https://')
|
|
.max(500),
|
|
})
|
|
|
|
export async function GET() {
|
|
const supabase = await createClient()
|
|
const { data: { user } } = await supabase.auth.getUser()
|
|
if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
|
|
const { data, error } = await supabase
|
|
.from('oauth_client_registrations')
|
|
.select('id, client_name, redirect_uri, created_at, revoked_at')
|
|
.eq('user_id', user.id)
|
|
.order('created_at', { ascending: false })
|
|
|
|
if (error) {
|
|
return NextResponse.json({ error: error.message }, { status: 500 })
|
|
}
|
|
|
|
return NextResponse.json({ data })
|
|
}
|
|
|
|
export async function POST(request: Request) {
|
|
const supabase = await createClient()
|
|
const { data: { user } } = await supabase.auth.getUser()
|
|
if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
|
|
const writeCheck = await requireWritePermission(supabase, user.id)
|
|
if (!writeCheck.ok) return writeCheck.response
|
|
|
|
let body: z.infer<typeof RegistrationSchema>
|
|
try {
|
|
const json = await request.json()
|
|
body = RegistrationSchema.parse(json)
|
|
} catch (err) {
|
|
const message =
|
|
err instanceof z.ZodError
|
|
? err.issues[0]?.message ?? 'Ogiltig redirect URI'
|
|
: err instanceof SyntaxError
|
|
? 'Ogiltig JSON i request body'
|
|
: 'Ogiltig redirect URI'
|
|
return NextResponse.json({ error: message }, { status: 400 })
|
|
}
|
|
|
|
const { data, error } = await supabase
|
|
.from('oauth_client_registrations')
|
|
.insert({
|
|
user_id: user.id,
|
|
client_name: body.client_name,
|
|
redirect_uri: body.redirect_uri,
|
|
})
|
|
.select('id, client_name, redirect_uri, created_at')
|
|
.single()
|
|
|
|
if (error) {
|
|
// Unique-index violation on redirect_uri → 409
|
|
if (error.code === '23505') {
|
|
return NextResponse.json(
|
|
{ error: 'Den här redirect URI:n är redan registrerad.' },
|
|
{ status: 409 }
|
|
)
|
|
}
|
|
return NextResponse.json({ error: error.message }, { status: 500 })
|
|
}
|
|
|
|
return NextResponse.json({ data })
|
|
}
|