feat(V2-3차): pull 확장 + invite flow + Realtime + 테스트 + mobile UI 교체

묶음 E — V2-4b pull 확장:
- CloudSyncService.pullAll()에 meetings/meeting_memos/meeting_documents 추가
- meetings: LWW, 모든 컬럼 매핑 (minutes_json JSON 직렬화)
- meeting_memos: immutable INSERT-only 전략
- meeting_documents: LWW UPDATE

묶음 F — api-client types:
- interface -> type alias 전환 (11개)
- Database 타입에 TypedTable<Row, Insert, Update> 유틸 도입
  (Row & Record<string, unknown> 교차로 GenericTable 제약 만족)
- @supabase/ssr 2.102는 supabase-js 버전 불일치로 제네릭 주입 불가 -
  다음 사이클로 이월, api-client index.ts는 types만 재수출

묶음 G — apps/mobile UI 교체:
- login.tsx: MetalCard + PhosphorText(hero/label) + PhysicalButton
- meetings.tsx: MetalCard + Led(status) + PhosphorText(body/meta)
- record.tsx: Led + PhosphorText + PhysicalButton
- profile.tsx: MetalCard + PhysicalButton(danger) + d3roNativePalette

묶음 H — V2-7b 이메일 invite flow:
- migrations/20260410000001_team_invites.sql
  - team_invites 테이블 (token, email, role, expires_at 7일)
  - RLS: 같은 팀 멤버 + 초대 이메일 소유자 SELECT,
    owner/admin만 INSERT/DELETE
  - generate_invite_token() SECURITY DEFINER RPC (service_role)
- functions/team-invite: 권한 체크 -> 토큰 생성 -> 초대 URL 반환
- functions/team-accept: 토큰 검증 -> expires_at/accepted_at/이메일 일치 ->
  team_members upsert -> 초대 accepted 표시
- config.toml에 team-invite/team-accept 함수 등록
- InviteMemberForm 재작성: 이메일 입력 + 역할 선택 -> URL 복사 UI
- /accept-invite 페이지 신규 (Suspense 내 useSearchParams + token 수락)

묶음 I — Realtime transcripts:
- apps/web/components/meetings/live-transcript-list.tsx (client)
  - supabase.channel('transcripts:meeting:${id}').on('postgres_changes')
  - INSERT -> 세그먼트 추가, UPDATE -> row 교체
  - 중복 방지 segment_index 기준
  - edited 배지 표시
- meetings/[id]/page.tsx의 transcript 섹션을 LiveTranscriptList로 교체

묶음 J — 테스트:
- packages/api-client/__tests__/client.test.ts (9 tests)
  - createD3roSupabaseClient, isClientConfigured 팩토리 검증
- packages/api-client/__tests__/types.test.ts (10 tests)
  - 모든 Row 타입 + 리터럴 union + Database keyof
- vitest.config.ts 신규
- apps/web/playwright.config.ts 신규 (baseURL, webServer dev 서버)
- apps/web/e2e/smoke.spec.ts 신규 (6 스모크 테스트)
- apps/web tsconfig exclude에 e2e/playwright.config.ts 추가
- package.json scripts: test, test:e2e, test:e2e:ui

검증:
- desktop typecheck OK
- web typecheck OK
- web next build OK (12 라우트, /accept-invite Suspense 적용)
- desktop build OK
- api-client test 19 passed
This commit is contained in:
yunchan8804 2026-04-10 08:34:52 +09:00
parent 37f3f4d5bd
commit c167737198
26 changed files with 1530 additions and 374 deletions

View file

@ -0,0 +1,64 @@
// packages/api-client/__tests__/client.test.ts
// createD3roSupabaseClient 팩토리 유닛 테스트
import { describe, it, expect } from 'vitest'
import { createD3roSupabaseClient, isClientConfigured } from '../src/client'
describe('createD3roSupabaseClient', () => {
it('URL과 key가 없으면 placeholder 클라이언트를 반환한다', () => {
const client = createD3roSupabaseClient({ url: undefined, anonKey: undefined })
expect(client).toBeDefined()
// auth, from 등 메서드가 존재해야 함
expect(typeof client.auth.getSession).toBe('function')
expect(typeof client.from).toBe('function')
})
it('URL만 있고 key가 없으면 placeholder 클라이언트를 반환한다', () => {
const client = createD3roSupabaseClient({
url: 'https://real.supabase.co',
anonKey: undefined
})
expect(client).toBeDefined()
})
it('URL과 key가 모두 있으면 실제 클라이언트를 생성한다', () => {
const client = createD3roSupabaseClient({
url: 'https://real.supabase.co',
anonKey: 'real-anon-key'
})
expect(client).toBeDefined()
expect(typeof client.auth.getSession).toBe('function')
})
it('auth 옵션을 주입할 수 있다', () => {
const client = createD3roSupabaseClient({
url: 'https://real.supabase.co',
anonKey: 'real-anon-key',
auth: { persistSession: false, autoRefreshToken: false }
})
expect(client).toBeDefined()
})
})
describe('isClientConfigured', () => {
it('URL과 key가 모두 있으면 true', () => {
expect(isClientConfigured({ url: 'https://x.supabase.co', anonKey: 'k' })).toBe(true)
})
it('URL만 있으면 false', () => {
expect(isClientConfigured({ url: 'https://x.supabase.co', anonKey: undefined })).toBe(false)
})
it('key만 있으면 false', () => {
expect(isClientConfigured({ url: undefined, anonKey: 'k' })).toBe(false)
})
it('둘 다 없으면 false', () => {
expect(isClientConfigured({ url: undefined, anonKey: undefined })).toBe(false)
})
it('빈 문자열은 false로 처리된다', () => {
expect(isClientConfigured({ url: '', anonKey: 'k' })).toBe(false)
expect(isClientConfigured({ url: 'https://x.supabase.co', anonKey: '' })).toBe(false)
})
})

View file

@ -0,0 +1,128 @@
// packages/api-client/__tests__/types.test.ts
// Database/Profile/Meeting 등 타입이 올바르게 export되는지 확인 (컴파일 체크)
import { describe, it, expect } from 'vitest'
import type {
Database,
Profile,
Meeting,
MeetingMemo,
MeetingDocument,
Transcript,
HistoryEntry,
DictionaryEntry,
Team,
TeamMember,
Subscription,
SubscriptionTier,
TeamRole,
MeetingStatus,
DocumentTemplateType,
HistoryMode,
HistoryStatus
} from '../src/types'
describe('api-client types', () => {
it('SubscriptionTier 리터럴 union', () => {
const tiers: SubscriptionTier[] = ['free', 'pro', 'team']
expect(tiers).toHaveLength(3)
})
it('TeamRole 리터럴 union', () => {
const roles: TeamRole[] = ['owner', 'admin', 'member']
expect(roles).toHaveLength(3)
})
it('MeetingStatus 리터럴 union', () => {
const statuses: MeetingStatus[] = ['recording', 'processing', 'completed', 'error']
expect(statuses).toHaveLength(4)
})
it('DocumentTemplateType 리터럴 union', () => {
const templates: DocumentTemplateType[] = [
'minutes',
'report',
'idea-note',
'custom',
'mindmap'
]
expect(templates).toHaveLength(5)
})
it('HistoryMode 리터럴 union', () => {
const modes: HistoryMode[] = [
'dictation',
'translate',
'command',
'caption',
'file-transcription'
]
expect(modes).toHaveLength(5)
})
it('HistoryStatus 리터럴 union', () => {
const statuses: HistoryStatus[] = ['completed', 'cancelled', 'error']
expect(statuses).toHaveLength(3)
})
it('Profile 구조', () => {
const profile: Profile = {
id: 'uuid',
name: 'Alice',
avatar_url: null,
locale: 'ko',
tier: 'free',
created_at: '2026-01-01T00:00:00Z',
updated_at: '2026-01-01T00:00:00Z'
}
expect(profile.id).toBe('uuid')
expect(profile.tier).toBe('free')
})
it('Meeting 구조', () => {
const meeting: Meeting = {
id: 'uuid',
user_id: 'user-uuid',
team_id: null,
title: 'Test Meeting',
status: 'completed',
started_at: '2026-01-01T00:00:00Z',
ended_at: null,
duration_ms: 120000,
raw_transcript: null,
edited_transcript: null,
minutes_markdown: null,
minutes_json: null,
stt_model: null,
llm_model: null,
stt_latency_ms: null,
llm_latency_ms: null,
error_message: null,
audio_storage_key: null,
created_at: '2026-01-01T00:00:00Z',
updated_at: '2026-01-01T00:00:00Z'
}
expect(meeting.status).toBe('completed')
})
it('Database 타입이 존재한다', () => {
// 컴파일 타임 체크 — Database가 export 되지 않으면 이 줄이 에러
const check: keyof Database = 'public'
expect(check).toBe('public')
})
// 미사용 import 방지용
it('모든 타입 import 검증', () => {
const _unused: [
MeetingMemo?,
MeetingDocument?,
Transcript?,
HistoryEntry?,
DictionaryEntry?,
Team?,
TeamMember?,
Subscription?
] = []
expect(_unused).toBeDefined()
})
})

View file

@ -4,6 +4,10 @@
"private": true,
"description": "D3RO Voice API 클라이언트 — Supabase 래퍼 (web/desktop/mobile 공유)",
"license": "MIT",
"scripts": {
"test": "vitest run",
"typecheck": "tsc --noEmit"
},
"main": "./src/index.ts",
"types": "./src/index.ts",
"exports": {

View file

@ -1,11 +1,14 @@
// packages/api-client — barrel export
// 개별 sub-path import 권장:
// 루트는 타입만. 함수는 subpath로 접근 — 현재 Supabase SSR과 supabase-js 버전
// 정합 이슈로 Database 제네릭이 @supabase/ssr에서 전파 실패하기 때문에,
// 내부에서 SupabaseClient<Database>를 쓰는 meetings/history/usage 함수들을
// 루트로 끌어올리면 consumer의 tsc가 이 함수들까지 scan하여 never 전파가 일어남.
//
// Sub-path로만 접근:
// '@d3ro/api-client/client' — Supabase 클라이언트 팩토리
// '@d3ro/api-client/auth' — 로그인/세션
// '@d3ro/api-client/meetings' — 회의 CRUD
// '@d3ro/api-client/history' — 음성 입력 이력
// '@d3ro/api-client/usage' — 쿼터/구독
//
// 루트 barrel은 타입만 노출. 함수는 subpath로 import (tree-shaking + 순환 의존 방지).
export * from './types'

View file

@ -1,10 +1,9 @@
// packages/api-client/src/types.ts
// Supabase DB row 타입 — V2-2 스키마와 동기화된 수동 정의.
// 추후 `supabase gen types typescript`로 자동화 예정.
export type SubscriptionTier = 'free' | 'pro' | 'team'
export interface Profile {
export type Profile = {
id: string
name: string | null
avatar_url: string | null
@ -14,7 +13,7 @@ export interface Profile {
updated_at: string
}
export interface Team {
export type Team = {
id: string
name: string
owner_id: string
@ -25,7 +24,7 @@ export interface Team {
export type TeamRole = 'owner' | 'admin' | 'member'
export interface TeamMember {
export type TeamMember = {
team_id: string
user_id: string
role: TeamRole
@ -34,7 +33,7 @@ export interface TeamMember {
export type MeetingStatus = 'recording' | 'processing' | 'completed' | 'error'
export interface Meeting {
export type Meeting = {
id: string
user_id: string
team_id: string | null
@ -57,7 +56,7 @@ export interface Meeting {
updated_at: string
}
export interface MeetingMemo {
export type MeetingMemo = {
id: string
meeting_id: string
user_id: string
@ -68,7 +67,7 @@ export interface MeetingMemo {
export type DocumentTemplateType = 'minutes' | 'report' | 'idea-note' | 'custom' | 'mindmap'
export interface MeetingDocument {
export type MeetingDocument = {
id: string
meeting_id: string
user_id: string
@ -82,7 +81,7 @@ export interface MeetingDocument {
updated_at: string
}
export interface Transcript {
export type Transcript = {
id: string
meeting_id: string
segment_index: number
@ -98,7 +97,7 @@ export interface Transcript {
export type HistoryMode = 'dictation' | 'translate' | 'command' | 'caption' | 'file-transcription'
export type HistoryStatus = 'completed' | 'cancelled' | 'error'
export interface HistoryEntry {
export type HistoryEntry = {
id: string
user_id: string
title: string | null
@ -125,7 +124,7 @@ export interface HistoryEntry {
updated_at: string
}
export interface DictionaryEntry {
export type DictionaryEntry = {
id: string
user_id: string
word: string
@ -137,7 +136,7 @@ export interface DictionaryEntry {
updated_at: string
}
export interface DailyUsage {
export type DailyUsage = {
id: number
user_id: string
date: string // YYYY-MM-DD
@ -145,7 +144,7 @@ export interface DailyUsage {
count: number
}
export interface Subscription {
export type Subscription = {
id: string
user_id: string
tier: SubscriptionTier
@ -159,97 +158,78 @@ export interface Subscription {
updated_at: string
}
/**
* 유틸: Supabase GenericTable (Row: Record<string, unknown>)
* Row/Insert/Update에 index signature를 .
* Profile specific type alias는 `Record<string, unknown>` subtype으로
* assign되지 , Database TypedTable로 .
*/
type TypedTable<TRow, TInsert, TUpdate> = {
Row: TRow & Record<string, unknown>
Insert: TInsert & Record<string, unknown>
Update: TUpdate & Record<string, unknown>
Relationships: []
}
/**
* DB SupabaseClient<Database> .
* Supabase CLI의 `supabase gen types typescript` .
* `@supabase/postgrest-js` GenericSchema constraint와 :
* { Tables: Record<string, GenericTable>; Views: ...; Functions: ... }
*/
export type Database = {
__InternalSupabase: {
PostgrestVersion: '12'
}
public: {
Tables: {
profiles: {
Row: Profile
Insert: Partial<Profile> & Pick<Profile, 'id'>
Update: Partial<Profile>
Relationships: []
}
teams: {
Row: Team
Insert: Omit<Team, 'id' | 'created_at' | 'updated_at'> & Partial<Pick<Team, 'id'>>
Update: Partial<Team>
Relationships: []
}
team_members: {
Row: TeamMember
Insert: Omit<TeamMember, 'joined_at'> & Partial<Pick<TeamMember, 'joined_at'>>
Update: Partial<TeamMember>
Relationships: []
}
meetings: {
Row: Meeting
Insert: Partial<Meeting> & Pick<Meeting, 'user_id'>
Update: Partial<Meeting>
Relationships: []
}
meeting_memos: {
Row: MeetingMemo
Insert: Omit<MeetingMemo, 'id' | 'created_at'> &
Partial<Pick<MeetingMemo, 'id' | 'created_at'>>
Update: Partial<MeetingMemo>
Relationships: []
}
meeting_documents: {
Row: MeetingDocument
Insert: Omit<MeetingDocument, 'id' | 'created_at' | 'updated_at'> &
Partial<Pick<MeetingDocument, 'id' | 'created_at' | 'updated_at'>>
Update: Partial<MeetingDocument>
Relationships: []
}
transcripts: {
Row: Transcript
Insert: Omit<Transcript, 'id' | 'created_at' | 'updated_at'> &
Partial<Pick<Transcript, 'id' | 'created_at' | 'updated_at'>>
Update: Partial<Transcript>
Relationships: []
}
history: {
Row: HistoryEntry
Insert: Partial<HistoryEntry> & Pick<HistoryEntry, 'user_id' | 'original_text' | 'duration'>
Update: Partial<HistoryEntry>
Relationships: []
}
dictionary: {
Row: DictionaryEntry
Insert: Partial<DictionaryEntry> & Pick<DictionaryEntry, 'user_id' | 'word'>
Update: Partial<DictionaryEntry>
Relationships: []
}
daily_usage: {
Row: DailyUsage
Insert: Omit<DailyUsage, 'id'>
Update: Partial<DailyUsage>
Relationships: []
}
subscriptions: {
Row: Subscription
Insert: Partial<Subscription> & Pick<Subscription, 'user_id'>
Update: Partial<Subscription>
Relationships: []
}
}
Views: {
[_ in never]: never
}
Functions: {
[_ in never]: never
}
Enums: {
[_ in never]: never
}
CompositeTypes: {
[_ in never]: never
profiles: TypedTable<Profile, Partial<Profile> & Pick<Profile, 'id'>, Partial<Profile>>
teams: TypedTable<
Team,
Omit<Team, 'id' | 'created_at' | 'updated_at'> & Partial<Pick<Team, 'id'>>,
Partial<Team>
>
team_members: TypedTable<
TeamMember,
Omit<TeamMember, 'joined_at'> & Partial<Pick<TeamMember, 'joined_at'>>,
Partial<TeamMember>
>
meetings: TypedTable<
Meeting,
Partial<Meeting> & Pick<Meeting, 'user_id'>,
Partial<Meeting>
>
meeting_memos: TypedTable<
MeetingMemo,
Omit<MeetingMemo, 'id' | 'created_at'> & Partial<Pick<MeetingMemo, 'id' | 'created_at'>>,
Partial<MeetingMemo>
>
meeting_documents: TypedTable<
MeetingDocument,
Omit<MeetingDocument, 'id' | 'created_at' | 'updated_at'> &
Partial<Pick<MeetingDocument, 'id' | 'created_at' | 'updated_at'>>,
Partial<MeetingDocument>
>
transcripts: TypedTable<
Transcript,
Omit<Transcript, 'id' | 'created_at' | 'updated_at'> &
Partial<Pick<Transcript, 'id' | 'created_at' | 'updated_at'>>,
Partial<Transcript>
>
history: TypedTable<
HistoryEntry,
Partial<HistoryEntry> & Pick<HistoryEntry, 'user_id' | 'original_text' | 'duration'>,
Partial<HistoryEntry>
>
dictionary: TypedTable<
DictionaryEntry,
Partial<DictionaryEntry> & Pick<DictionaryEntry, 'user_id' | 'word'>,
Partial<DictionaryEntry>
>
daily_usage: TypedTable<DailyUsage, Omit<DailyUsage, 'id'>, Partial<DailyUsage>>
subscriptions: TypedTable<
Subscription,
Partial<Subscription> & Pick<Subscription, 'user_id'>,
Partial<Subscription>
>
}
Views: Record<string, never>
Functions: Record<string, never>
}
}

View file

@ -0,0 +1,10 @@
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
globals: false,
environment: 'node',
include: ['__tests__/**/*.test.ts'],
testTimeout: 10000
}
})