connectbase-client 3.25.0 → 3.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Connect Base
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,149 @@
1
+ # Migration to v2.0.0 — Presence/Typing 단일화
2
+
3
+ > 작성일: 2026-04-27
4
+ > 대상 버전: 1.12.x → 2.0.0 (1.13 deprecation 단계 생략, 즉시 제거)
5
+ > 영향: `cb.database.setPresence`, `cb.database.subscribePresence`, `DatabasePresenceState`, WebSocket URL
6
+
7
+ 본 문서는 v1.12.x 이전에서 v2.0.0 으로 업그레이드할 때 필요한 변경 사항을 안내합니다.
8
+ v2.0.0 에서 데이터베이스 측 presence/typing API 가 코드에서 완전히 제거되었습니다
9
+ (호출 시 `TypeError`). presence/typing 의 단일 SoT 는 `cb.realtime.*` 입니다.
10
+
11
+ ## 1. 책임 경계 변경
12
+
13
+ | 기능 | v1.12.x | v2.0.0 |
14
+ |------|---------|--------|
15
+ | presence 상태 설정/조회/구독 | `cb.database` / `cb.realtime` 양쪽 | `cb.realtime` 만 |
16
+ | typing 상태 | `cb.database` | `cb.realtime` 만 |
17
+ | DB 변경 구독 | `cb.database.connectRealtime` | (변경 없음) |
18
+ | WebSocket URL (DB) | `/v1/realtime/ws` | `/v1/database/realtime/ws` |
19
+
20
+ ## 2. setPresence 마이그레이션
21
+
22
+ ### Before (v1.12.x)
23
+
24
+ ```ts
25
+ cb.database.setPresence('online', 'web', { nickname: '홍길동' })
26
+ ```
27
+
28
+ ### After (v1.13+ / v2)
29
+
30
+ ```ts
31
+ await cb.realtime.setPresence('online', {
32
+ device: 'web',
33
+ metadata: { nickname: '홍길동' }
34
+ })
35
+ ```
36
+
37
+ **차이점**
38
+
39
+ - `cb.realtime.setPresence` 는 `Promise<void>` 를 반환합니다 (기존은 동기 void).
40
+ - `device` 와 `metadata` 가 두 번째 객체 파라미터의 옵션 필드입니다.
41
+ - 상태값에 `'busy'` 가 추가되어 있습니다 (`'online' | 'away' | 'busy' | 'offline'`).
42
+
43
+ ## 3. subscribePresence 마이그레이션
44
+
45
+ ### Before (v1.12.x)
46
+
47
+ ```ts
48
+ cb.database.subscribePresence(['user1', 'user2'], (states) => {
49
+ console.log(states['user1']?.last_seen) // string ISO
50
+ })
51
+ ```
52
+
53
+ ### After (옵션 1 — 단일 사용자별 구독)
54
+
55
+ ```ts
56
+ const unsub1 = await cb.realtime.subscribePresence('user1', (info) => {
57
+ console.log(info.lastSeen) // number (epoch ms)
58
+ })
59
+ const unsub2 = await cb.realtime.subscribePresence('user2', (info) => {
60
+ console.log(info.userId, info.status, info.eventType) // join/leave/update
61
+ })
62
+
63
+ // 정리
64
+ unsub1()
65
+ unsub2()
66
+ ```
67
+
68
+ ### After (옵션 2 — 앱 전체 변경 일괄 수신)
69
+
70
+ ```ts
71
+ const unsub = cb.realtime.onPresenceChange((info) => {
72
+ // 모든 사용자의 변경 이벤트가 한 콜백으로 전달됨
73
+ if (['user1', 'user2'].includes(info.userId)) {
74
+ console.log(info.userId, info.status)
75
+ }
76
+ })
77
+ ```
78
+
79
+ **차이점**
80
+
81
+ | 필드 | v1.12 (`DatabasePresenceState`) | v1.13+ (`PresenceInfo`) |
82
+ |------|-------------------------------|-----------------------|
83
+ | ID | `user_id` (snake) | `userId` (camel) |
84
+ | 마지막 활동 | `last_seen: string` (ISO) | `lastSeen: number` (epoch ms) |
85
+ | 상태 | `'online' \| 'away' \| 'offline'` | `'online' \| 'away' \| 'busy' \| 'offline'` |
86
+ | 이벤트 타입 | (없음) | `eventType?: 'join' \| 'leave' \| 'update'` |
87
+
88
+ ### 변환 헬퍼 (마이그레이션 보조)
89
+
90
+ 기존 `DatabasePresenceState` 모양으로 데이터를 가공하던 코드를 점진적으로 옮길 때 도움이
91
+ 되도록, v1 호환 형태(snake_case · ISO 문자열) 로 변환하는 헬퍼 예제. v2.0.0 에서는
92
+ `DatabasePresenceState` type 이 제거되었으므로 inline 타입으로 정의한다.
93
+
94
+ ```ts
95
+ import type { PresenceInfo } from 'connectbase-client'
96
+
97
+ interface LegacyPresenceState {
98
+ user_id: string
99
+ status: 'online' | 'away' | 'offline'
100
+ last_seen: string
101
+ device?: string
102
+ metadata?: Record<string, unknown>
103
+ }
104
+
105
+ function fromPresenceInfo(info: PresenceInfo): LegacyPresenceState {
106
+ return {
107
+ user_id: info.userId,
108
+ status: info.status === 'busy' ? 'away' : info.status,
109
+ last_seen: new Date(info.lastSeen).toISOString(),
110
+ device: info.device,
111
+ metadata: info.metadata,
112
+ }
113
+ }
114
+ ```
115
+
116
+ ## 4. typing 마이그레이션 (있는 경우)
117
+
118
+ `cb.database` 에는 공개된 typing 메서드가 없으므로 추가 마이그레이션은 불필요합니다.
119
+ `cb.realtime.startTyping(roomId)` / `cb.realtime.stopTyping(roomId)` /
120
+ `cb.realtime.onTypingChange(roomId, handler)` 를 그대로 사용하세요.
121
+
122
+ ## 5. WebSocket URL 변경
123
+
124
+ ```ts
125
+ await cb.database.connectRealtime({
126
+ accessToken: 'xxx',
127
+ dataServerUrl: 'https://data.connectbase.world',
128
+ })
129
+ // SDK 는 자동으로 /v1/database/realtime/ws 로 연결 (v1.13+).
130
+ // 사용자가 dataServerUrl 의 host:port 만 지정하면 path 는 SDK 가 결정.
131
+ ```
132
+
133
+ 옛 경로(`/v1/realtime/ws`) 는 v2.0.0 과 함께 서버에서도 제거되었습니다. 사용자 측
134
+ firewall/proxy 에 `/v1/database/realtime/` 경로 허용 규칙이 있는지 확인하세요.
135
+
136
+ ## 6. 런타임 동작 차이
137
+
138
+ - **v1.12.x**: 두 API 모두 동작.
139
+ - **v2.0.0**: `cb.database.setPresence` / `subscribePresence` 호출 시 `TypeError` (메서드 미존재).
140
+
141
+ ## 7. 자동 마이그레이션 (codemod)
142
+
143
+ 향후 별도 codemod 스크립트가 제공될 예정입니다. 우선은 위 가이드에 따라 수동 변경을
144
+ 권장합니다 (필드 네이밍/시그니처 차이가 있어 수동 검토가 안전).
145
+
146
+ ## 8. 문의
147
+
148
+ - 이슈: GitHub Issues
149
+ - 디스코드: 공식 채널의 `#sdk` 룸