packages/api-client (@d3ro/api-client) 신규: - types.ts: 12개 테이블 Row/Insert/Update 타입 + Database 형식 - client.ts: createD3roSupabaseClient 팩토리 (placeholder fallback) - auth.ts: signInWithOAuth/signOut/getSession/onAuthStateChange - meetings.ts: 회의 + 메모 + 문서 + 전사 CRUD - history.ts: 음성 입력 이력 CRUD - usage.ts: 일일 쿼터 + 구독 조회 - 루트 barrel은 types만 re-export, 함수는 subpath import 전용 apps/web (@d3ro/web) 신규 — Next.js 15 App Router: - transpilePackages: @d3ro/core, ui, i18n, api-client - ThemeProvider (MUI + AppRouterCacheProvider) - I18nProvider (localStorage 어댑터) - AuthProvider (Supabase session Context) - 라우트 9개: - / (auth 상태 기반 리다이렉트) - /login (Google/GitHub OAuth, 미설정 경고) - /auth/callback (code -> session 교환) - /dashboard (요약 카드 + 최근 회의) - /meetings (카드 그리드 리스트) - /meetings/[id] (transcripts/memos/documents) - /record (getUserMedia + MediaRecorder + stt-proxy) - Sidebar, 인증 가드, 9바 웨이브폼, 레벨 미터 packages/ui 확장: - MetalCard가 BoxProps 상속 (sx/onClick 등 전달) - theme.ts에 typoSx(key) 헬퍼 추가 (d3roTypo -> MUI sx 변환) - d3roPalette.tag.blue 추가 (M5 정리 포함) - DS 컴포넌트 9개에 'use client' directive - MetalDial 미사용 import 제거 packages/i18n 확장: - ko.json에 7개 새 키 (nav.meetings/record/logout, login.*) 설계 결정: - Database 제네릭 현재는 기본 타입 (V2-4에서 supabase gen types로 자동화) - api-client barrel은 타입만 노출해서 컴파일 전파 차단 - DS 컴포넌트 client 경계 명시 - env 없어도 Next.js 빌드 성공 (placeholder URL/key) 검증: - web typecheck OK - desktop typecheck OK (회귀 없음) - web next build OK (9 라우트 정적/동적 생성) - desktop build OK (회귀 없음)
56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
// packages/api-client/src/client.ts
|
|
// Supabase 클라이언트 팩토리. 각 앱이 자신의 env에서 URL/KEY를 주입하여 생성.
|
|
|
|
import { createClient, type SupabaseClient } from '@supabase/supabase-js'
|
|
import type { Database } from './types'
|
|
|
|
export type D3roSupabaseClient = SupabaseClient<Database>
|
|
|
|
export interface CreateClientOptions {
|
|
url: string | undefined
|
|
anonKey: string | undefined
|
|
/**
|
|
* SSR 환경에서 세션 영속화를 쿠키 기반으로 하려면 별도 storage adapter를 주입.
|
|
* 지정하지 않으면 기본(localStorage in browser, 메모리 in SSR).
|
|
*/
|
|
auth?: {
|
|
persistSession?: boolean
|
|
autoRefreshToken?: boolean
|
|
storageKey?: string
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Supabase 클라이언트 생성.
|
|
* url 또는 anonKey가 비어있으면 "dummy" 클라이언트를 반환 — 모든 쿼리는 빈 결과.
|
|
* 이렇게 해야 env가 세팅되지 않은 상태에서도 빌드/SSR이 실패하지 않는다.
|
|
*/
|
|
export function createD3roSupabaseClient(options: CreateClientOptions): D3roSupabaseClient {
|
|
const { url, anonKey, auth } = options
|
|
|
|
if (!url || !anonKey) {
|
|
// Env가 없으면 fallback URL로 생성. 실제 호출은 런타임에 실패하지만
|
|
// 빌드/타입체크는 통과. 앱 상단에서 isClientConfigured()로 체크해야 함.
|
|
return createClient<Database>('https://placeholder.supabase.co', 'placeholder-anon-key', {
|
|
auth: {
|
|
persistSession: false,
|
|
autoRefreshToken: false
|
|
}
|
|
})
|
|
}
|
|
|
|
return createClient<Database>(url, anonKey, {
|
|
auth: {
|
|
persistSession: auth?.persistSession ?? true,
|
|
autoRefreshToken: auth?.autoRefreshToken ?? true,
|
|
storageKey: auth?.storageKey
|
|
}
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Env가 실제로 세팅되었는지 확인. UI에서 "Supabase 미설정" 경고 표시용.
|
|
*/
|
|
export function isClientConfigured(options: CreateClientOptions): boolean {
|
|
return Boolean(options.url && options.anonKey)
|
|
}
|