feat(admin): 예전/최신 어드민 통합 — 실데이터 복원 + 인증 아키텍처 정리
예전 배포본(HEAD)의 상세 기능을 새 아키텍처(인증=.NET 백엔드, 데이터=Supabase) 위에 실데이터로 복원. 예전 HEAD는 서명 쿠키를 거부하고 위조 쿠키는 통과시키는 인증 결함이 있었고, 삭제된 페이지 다수는 백엔드 호출 0인 하드코딩 목업이었음. 인증/세션 - 로그인 이메일 전용화(username 폐지), 에러 키별 안내 메시지 - ADMIN_COOKIE_SECURE 옵션: TLS 없는 LAN HTTP 배포에서 Secure 쿠키 유실로 로그인이 유지되지 않던 문제 해결 (login/logout route, admin-session, compose, .env.example) - Supabase 미설정 시 우아한 저하: isSupabaseAdminConfigured + UnavailableAdminPanel 기능 복원 (실데이터) - Release Hub: Forgejo API 실데이터(다운로드 수/SHA-256 체크섬/릴리스 이력) - Ad Monetization: 데스크톱 미디에이션 10개 어댑터 로스터(fail-closed) + ad_reward_claims 통계 - License Issuer: 서버사이드 Ed25519 서명(/api/admin/license, super_admin 전용), 개인키는 ADMIN_LICENSE_PRIVATE_KEY env로만, 발급 감사를 .NET AdminAuditEntries에 기록 - Service Models: STT 7종/LLM 5종 프리셋 드롭다운 + 자동채움 - 대시보드 ARR/MRR KPI: Supabase 구독 실집계(티어 월단가 기반) - 사용자 상세 티어별 기능 배지(pro_plus 조건부) .NET - SuperAdminOnly 정책 추가, /api/admin/license-audit 엔드포인트, LicenseAuditDto
This commit is contained in:
parent
a9c9a1ca6e
commit
5a34f66981
66 changed files with 4471 additions and 3501 deletions
|
|
@ -1,11 +1,12 @@
|
|||
// apps/admin/src/app/(admin)/subscriptions/page.tsx
|
||||
// D3RO Voice — Subscriptions & ARR Revenue Console (Midnight Glass v2)
|
||||
// D3RO Voice — Subscription Operations Console
|
||||
|
||||
import { Box, Typography, Button } from '@mui/material'
|
||||
import { C, FONT_SANS, FONT_MONO, panelSx, tableSx, filterBtnSx, statusBadgeSx, primaryButtonSx } from '@/lib/console-theme'
|
||||
import { DoubleBezelCard, TactileBadge, StatRing } from '@d3ro/ui/components/ds'
|
||||
import { getSupabaseServerClient } from '@/lib/supabase-server'
|
||||
import { fetchServerStats } from '@/lib/api-server'
|
||||
import { getSupabaseAdminClient, isSupabaseAdminConfigured } from '@/lib/supabase-admin'
|
||||
import { UnavailableAdminPanel } from '@/components/unavailable-admin-panel'
|
||||
import { hasMinRole, requireManager } from '@/lib/admin-guard'
|
||||
import { LicenseIssuerButton } from '@/components/license-issuer-button'
|
||||
import Link from 'next/link'
|
||||
|
||||
|
|
@ -19,7 +20,6 @@ interface SubRow {
|
|||
cancel_at: string | null
|
||||
renewal_failures: number
|
||||
profile_name: string | null
|
||||
mrrAmount: number
|
||||
}
|
||||
|
||||
interface PageProps {
|
||||
|
|
@ -27,57 +27,68 @@ interface PageProps {
|
|||
}
|
||||
|
||||
export default async function AdminSubscriptionsPage({ searchParams }: PageProps): Promise<React.ReactElement> {
|
||||
if (!isSupabaseAdminConfigured()) {
|
||||
return (
|
||||
<UnavailableAdminPanel
|
||||
title="Subscription Management"
|
||||
capability="Plans, billing, payment history"
|
||||
reason="SUPABASE_URL / SUPABASE_SERVICE_ROLE_KEY 환경변수가 설정되지 않아 Supabase 관리 데이터에 연결할 수 없습니다. 환경변수를 설정하면 실데이터가 표시됩니다."
|
||||
/>
|
||||
)
|
||||
}
|
||||
const params = await searchParams
|
||||
const statusFilter = params.status ?? 'all'
|
||||
const supabase = await getSupabaseServerClient()
|
||||
const serverStats = await fetchServerStats()
|
||||
if (!['all', 'active', 'canceled', 'past_due', 'expired'].includes(statusFilter)) {
|
||||
throw new Error('Invalid subscription status filter')
|
||||
}
|
||||
const admin = await requireManager()
|
||||
const supabase = await getSupabaseAdminClient()
|
||||
|
||||
const subQuery = supabase
|
||||
.from('subscriptions')
|
||||
.select('id, user_id, tier, status, payment_provider, current_period_end, cancel_at')
|
||||
.order('current_period_end', { ascending: true })
|
||||
.limit(100)
|
||||
|
||||
if (statusFilter !== 'all') subQuery.eq('status', statusFilter)
|
||||
|
||||
const { data: rawSubs } = await subQuery
|
||||
const rawSubsArr = (rawSubs ?? []) as Array<Record<string, unknown>>
|
||||
const rawSubsArr: Array<Record<string, unknown>> = []
|
||||
for (let page = 0; page < 100; page += 1) {
|
||||
let query = supabase
|
||||
.from('subscriptions')
|
||||
.select('id, user_id, tier, status, payment_provider, current_period_end, cancel_at, renewal_failures')
|
||||
.order('current_period_end', { ascending: true })
|
||||
.range(page * 500, page * 500 + 499)
|
||||
if (statusFilter !== 'all') query = query.eq('status', statusFilter)
|
||||
const { data, error } = await query
|
||||
if (error) throw new Error('Supabase subscriptions failed')
|
||||
rawSubsArr.push(...((data ?? []) as Array<Record<string, unknown>>))
|
||||
if ((data?.length ?? 0) < 500) break
|
||||
if (page === 99) throw new Error('Supabase subscription directory exceeds the supported administrative window')
|
||||
}
|
||||
|
||||
let subs: SubRow[] = []
|
||||
|
||||
if (rawSubsArr.length > 0) {
|
||||
const userIds = rawSubsArr.map((s) => s.user_id as string)
|
||||
const { data: rawProfiles } = userIds.length > 0
|
||||
? await supabase.from('profiles').select('id, name').in('id', userIds)
|
||||
: { data: [] }
|
||||
const profileChunks = await Promise.all(Array.from({ length: Math.ceil(userIds.length / 200) }, (_, index) =>
|
||||
supabase.from('profiles').select('id, name').in('id', userIds.slice(index * 200, index * 200 + 200))))
|
||||
if (profileChunks.some((result) => result.error)) throw new Error('Supabase subscription profiles failed')
|
||||
const rawProfiles = profileChunks.flatMap((result) => result.data ?? [])
|
||||
const profileMap = new Map(
|
||||
((rawProfiles ?? []) as Array<Record<string, unknown>>).map((p) => [p.id as string, (p.name as string) ?? null])
|
||||
)
|
||||
|
||||
subs = rawSubsArr.map((row) => ({
|
||||
id: row.id as string,
|
||||
user_id: row.user_id as string,
|
||||
tier: (row.tier as string) ?? 'free',
|
||||
status: (row.status as string) ?? 'active',
|
||||
payment_provider: (row.payment_provider as string) ?? 'Stripe',
|
||||
current_period_end: row.current_period_end as string | null,
|
||||
cancel_at: row.cancel_at as string | null,
|
||||
renewal_failures: (row.renewal_failures as number | undefined) ?? 0,
|
||||
profile_name: profileMap.get(row.user_id as string) ?? null,
|
||||
mrrAmount: row.tier === 'enterprise' ? 120 : row.tier === 'team' ? 25 : row.tier === 'pro_plus' ? 19.9 : row.tier === 'pro' ? 9.9 : 0,
|
||||
}))
|
||||
} else {
|
||||
// Rich Mock Fallback Subscriptions
|
||||
subs = [
|
||||
{ id: 'sub_001', user_id: 'usr_d3ro_001', tier: 'enterprise', status: 'active', payment_provider: 'Stripe', current_period_end: '2027-01-15T00:00:00Z', cancel_at: null, renewal_failures: 0, profile_name: 'D3RO System Architect', mrrAmount: 120 },
|
||||
{ id: 'sub_002', user_id: 'usr_d3ro_002', tier: 'team', status: 'active', payment_provider: 'Toss Payments', current_period_end: '2026-11-10T00:00:00Z', cancel_at: null, renewal_failures: 0, profile_name: 'Sarah Kim (Design Team)', mrrAmount: 75 },
|
||||
{ id: 'sub_003', user_id: 'usr_d3ro_003', tier: 'pro_plus', status: 'active', payment_provider: 'Stripe', current_period_end: '2026-10-02T00:00:00Z', cancel_at: null, renewal_failures: 0, profile_name: 'Minho Park', mrrAmount: 19.9 },
|
||||
{ id: 'sub_004', user_id: 'usr_d3ro_004', tier: 'pro', status: 'active', payment_provider: 'Payple', current_period_end: '2026-09-18T00:00:00Z', cancel_at: null, renewal_failures: 0, profile_name: 'Alex Chen', mrrAmount: 9.9 },
|
||||
{ id: 'sub_005', user_id: 'usr_d3ro_005', tier: 'pro', status: 'active', payment_provider: 'Toss Payments', current_period_end: '2026-09-01T00:00:00Z', cancel_at: null, renewal_failures: 0, profile_name: 'Jisoo Lee', mrrAmount: 9.9 },
|
||||
{ id: 'sub_006', user_id: 'usr_d3ro_006', tier: 'pro_plus', status: 'active', payment_provider: 'Stripe', current_period_end: '2026-12-20T00:00:00Z', cancel_at: null, renewal_failures: 0, profile_name: 'David Wilson', mrrAmount: 19.9 },
|
||||
{ id: 'sub_007', user_id: 'usr_d3ro_007', tier: 'free', status: 'active', payment_provider: 'None', current_period_end: null, cancel_at: null, renewal_failures: 0, profile_name: 'Hyunjin Choi', mrrAmount: 0 },
|
||||
{ id: 'sub_008', user_id: 'usr_d3ro_008', tier: 'free', status: 'active', payment_provider: 'None', current_period_end: null, cancel_at: null, renewal_failures: 0, profile_name: 'Elena Rostova', mrrAmount: 0 },
|
||||
]
|
||||
subs = rawSubsArr.map((row) => {
|
||||
if (typeof row.id !== 'string' || typeof row.user_id !== 'string' ||
|
||||
typeof row.tier !== 'string' || typeof row.status !== 'string' ||
|
||||
typeof row.payment_provider !== 'string' || !Number.isInteger(row.renewal_failures)) {
|
||||
throw new Error('Supabase subscription response contains an invalid row')
|
||||
}
|
||||
return {
|
||||
id: row.id,
|
||||
user_id: row.user_id,
|
||||
tier: row.tier,
|
||||
status: row.status,
|
||||
payment_provider: row.payment_provider,
|
||||
current_period_end: typeof row.current_period_end === 'string' ? row.current_period_end : null,
|
||||
cancel_at: typeof row.cancel_at === 'string' ? row.cancel_at : null,
|
||||
renewal_failures: row.renewal_failures as number,
|
||||
profile_name: profileMap.get(row.user_id) ?? null,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const filteredSubs = statusFilter === 'all' ? subs : subs.filter((s) => s.status === statusFilter)
|
||||
|
|
@ -114,16 +125,16 @@ export default async function AdminSubscriptionsPage({ searchParams }: PageProps
|
|||
sx={{
|
||||
fontFamily: FONT_SANS,
|
||||
fontSize: '20px',
|
||||
fontWeight: 700,
|
||||
fontWeight: 500,
|
||||
color: C.bright,
|
||||
letterSpacing: '-0.02em',
|
||||
m: 0,
|
||||
}}
|
||||
>
|
||||
Subscriptions & ARR Analytics
|
||||
Subscription Operations
|
||||
</Typography>
|
||||
<TactileBadge ledColor="purple" ledPulse tone="accent" mono>
|
||||
${serverStats.arrUsd.toLocaleString()} ARR
|
||||
{subs.length} RECORDS
|
||||
</TactileBadge>
|
||||
</Box>
|
||||
<Typography
|
||||
|
|
@ -135,7 +146,7 @@ export default async function AdminSubscriptionsPage({ searchParams }: PageProps
|
|||
mt: 0.25,
|
||||
}}
|
||||
>
|
||||
LEMONSQUEEZY SYNC • 3-TIER MONETIZATION • AUTO RENEWAL
|
||||
Supabase subscriptions, payment providers, renewal state
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
|
|
@ -149,12 +160,14 @@ export default async function AdminSubscriptionsPage({ searchParams }: PageProps
|
|||
</Link>
|
||||
))}
|
||||
<Box sx={{ height: 20, width: '1px', bgcolor: C.borderHl, mx: 0.5 }} />
|
||||
<LicenseIssuerButton />
|
||||
<Link href="/subscriptions/new" style={{ textDecoration: 'none' }}>
|
||||
<Button variant="contained" size="small" sx={primaryButtonSx}>
|
||||
+ Create Subscription
|
||||
</Button>
|
||||
</Link>
|
||||
{hasMinRole(admin, 'super_admin') && <LicenseIssuerButton />}
|
||||
{hasMinRole(admin, 'admin') && (
|
||||
<Link href="/subscriptions/new" style={{ textDecoration: 'none' }}>
|
||||
<Button variant="contained" size="small" sx={primaryButtonSx}>
|
||||
+ Create Subscription
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
|
|
@ -163,51 +176,51 @@ export default async function AdminSubscriptionsPage({ searchParams }: PageProps
|
|||
<DoubleBezelCard interactive bezelPadding="5px" innerPadding="20px">
|
||||
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mb: 1.5 }}>
|
||||
<Typography sx={{ fontFamily: FONT_SANS, fontSize: '11px', fontWeight: 600, color: C.dim, textTransform: 'uppercase' }}>
|
||||
Monthly Recurring (MRR)
|
||||
Total Subscription Records
|
||||
</Typography>
|
||||
<StatRing color="purple" size={38}>
|
||||
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '11px', fontWeight: 700 }}>$</Typography>
|
||||
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '11px', fontWeight: 500 }}>#</Typography>
|
||||
</StatRing>
|
||||
</Box>
|
||||
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '24px', fontWeight: 700, color: C.bright }}>
|
||||
${serverStats.mrrUsd.toLocaleString()}
|
||||
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '24px', fontWeight: 500, color: C.bright }}>
|
||||
{subs.length.toLocaleString()}
|
||||
</Typography>
|
||||
<Typography sx={{ fontFamily: FONT_SANS, fontSize: '11px', color: C.green400, mt: 0.5 }}>
|
||||
↑ 18.4% vs last month
|
||||
Persisted in Supabase
|
||||
</Typography>
|
||||
</DoubleBezelCard>
|
||||
|
||||
<DoubleBezelCard interactive bezelPadding="5px" innerPadding="20px">
|
||||
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mb: 1.5 }}>
|
||||
<Typography sx={{ fontFamily: FONT_SANS, fontSize: '11px', fontWeight: 600, color: C.dim, textTransform: 'uppercase' }}>
|
||||
Paid Subscribers (Pro/Pro+)
|
||||
Active Subscriptions
|
||||
</Typography>
|
||||
<StatRing color="blue" size={38}>
|
||||
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '11px', fontWeight: 700 }}>VIP</Typography>
|
||||
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '11px', fontWeight: 500 }}>ON</Typography>
|
||||
</StatRing>
|
||||
</Box>
|
||||
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '24px', fontWeight: 700, color: C.bright }}>
|
||||
{(serverStats.tierDistribution.pro + serverStats.tierDistribution.pro_plus).toLocaleString()} Paid
|
||||
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '24px', fontWeight: 500, color: C.bright }}>
|
||||
{subs.filter((subscription) => subscription.status === 'active').length.toLocaleString()}
|
||||
</Typography>
|
||||
<Typography sx={{ fontFamily: FONT_SANS, fontSize: '11px', color: C.cyanLight, mt: 0.5 }}>
|
||||
{serverStats.tierDistribution.pro_plus} Pro+ • {serverStats.tierDistribution.pro} Pro
|
||||
Current status = active
|
||||
</Typography>
|
||||
</DoubleBezelCard>
|
||||
|
||||
<DoubleBezelCard interactive bezelPadding="5px" innerPadding="20px">
|
||||
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mb: 1.5 }}>
|
||||
<Typography sx={{ fontFamily: FONT_SANS, fontSize: '11px', fontWeight: 600, color: C.dim, textTransform: 'uppercase' }}>
|
||||
Renewal Success Rate
|
||||
Renewal Failures
|
||||
</Typography>
|
||||
<StatRing color="green" size={38}>
|
||||
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '11px', fontWeight: 700 }}>%</Typography>
|
||||
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '11px', fontWeight: 500 }}>%</Typography>
|
||||
</StatRing>
|
||||
</Box>
|
||||
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '24px', fontWeight: 700, color: C.green400 }}>
|
||||
99.4%
|
||||
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '24px', fontWeight: 500, color: C.green400 }}>
|
||||
{subs.reduce((total, subscription) => total + subscription.renewal_failures, 0).toLocaleString()}
|
||||
</Typography>
|
||||
<Typography sx={{ fontFamily: FONT_SANS, fontSize: '11px', color: C.dim, mt: 0.5 }}>
|
||||
0.6% Churn • Fast Retry System
|
||||
Persisted retry failures
|
||||
</Typography>
|
||||
</DoubleBezelCard>
|
||||
</Box>
|
||||
|
|
@ -215,8 +228,8 @@ export default async function AdminSubscriptionsPage({ searchParams }: PageProps
|
|||
{/* Subscription Table */}
|
||||
<DoubleBezelCard bezelPadding="6px" innerPadding="24px">
|
||||
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mb: 2.5 }}>
|
||||
<Typography sx={{ fontFamily: FONT_SANS, fontSize: '16px', fontWeight: 700, color: C.bright }}>
|
||||
Active Subscription Contracts
|
||||
<Typography sx={{ fontFamily: FONT_SANS, fontSize: '16px', fontWeight: 500, color: C.bright }}>
|
||||
Subscription Contracts
|
||||
</Typography>
|
||||
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '11px', color: C.dim }}>
|
||||
SHOWING {filteredSubs.length} RECORDS
|
||||
|
|
@ -230,7 +243,7 @@ export default async function AdminSubscriptionsPage({ searchParams }: PageProps
|
|||
<Box component="th">SUBSCRIBER</Box>
|
||||
<Box component="th">TIER</Box>
|
||||
<Box component="th">STATUS</Box>
|
||||
<Box component="th">MRR VALUE</Box>
|
||||
<Box component="th">RENEWAL FAILURES</Box>
|
||||
<Box component="th">PROVIDER</Box>
|
||||
<Box component="th">EXPIRES / RENEWS</Box>
|
||||
<Box component="th" sx={{ textAlign: 'right' }}>ACTION</Box>
|
||||
|
|
@ -269,14 +282,14 @@ export default async function AdminSubscriptionsPage({ searchParams }: PageProps
|
|||
{s.status.toUpperCase()}
|
||||
</Box>
|
||||
</Box>
|
||||
<Box component="td" sx={{ fontFamily: FONT_MONO, fontSize: '13px', fontWeight: 700, color: C.bright }}>
|
||||
${s.mrrAmount}/mo
|
||||
<Box component="td" sx={{ fontFamily: FONT_MONO, fontSize: '13px', fontWeight: 500, color: C.bright }}>
|
||||
{s.renewal_failures}
|
||||
</Box>
|
||||
<Box component="td" sx={{ fontFamily: FONT_MONO, fontSize: '11px', color: C.dim }}>
|
||||
{s.payment_provider}
|
||||
</Box>
|
||||
<Box component="td" sx={{ fontFamily: FONT_MONO, fontSize: '11px', color: C.text }}>
|
||||
{s.current_period_end ? new Date(s.current_period_end).toLocaleDateString() : 'Free Tier'}
|
||||
{s.current_period_end ? new Date(s.current_period_end).toLocaleDateString() : 'Not set'}
|
||||
</Box>
|
||||
<Box component="td" sx={{ textAlign: 'right' }}>
|
||||
<Link href={`/subscriptions/${s.user_id}`} style={{ textDecoration: 'none' }}>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue