@taco_tsinghua/graphnode-sdk 0.1.17 → 0.1.21
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/README.md +91 -333
- package/dist/client.d.ts +24 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +34 -8
- package/dist/client.js.map +1 -1
- package/dist/endpoints/ai.d.ts +25 -30
- package/dist/endpoints/ai.d.ts.map +1 -1
- package/dist/endpoints/ai.js +220 -31
- package/dist/endpoints/ai.js.map +1 -1
- package/dist/endpoints/graph.d.ts +4 -1
- package/dist/endpoints/graph.d.ts.map +1 -1
- package/dist/endpoints/graph.js +10 -0
- package/dist/endpoints/graph.js.map +1 -1
- package/dist/endpoints/graphAi.d.ts +21 -0
- package/dist/endpoints/graphAi.d.ts.map +1 -1
- package/dist/endpoints/graphAi.js +24 -0
- package/dist/endpoints/graphAi.js.map +1 -1
- package/dist/endpoints/notification.d.ts +13 -0
- package/dist/endpoints/notification.d.ts.map +1 -1
- package/dist/endpoints/notification.js +17 -0
- package/dist/endpoints/notification.js.map +1 -1
- package/dist/endpoints/sync.d.ts +3 -1
- package/dist/endpoints/sync.d.ts.map +1 -1
- package/dist/endpoints/sync.js.map +1 -1
- package/dist/http-builder.d.ts +38 -0
- package/dist/http-builder.d.ts.map +1 -1
- package/dist/http-builder.js +43 -6
- package/dist/http-builder.js.map +1 -1
- package/dist/types/graph.d.ts +66 -0
- package/dist/types/graph.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/client.ts +140 -0
- package/src/config.ts +9 -0
- package/src/endpoints/agent.ts +171 -0
- package/src/endpoints/ai.ts +296 -0
- package/src/endpoints/auth.apple.ts +39 -0
- package/src/endpoints/auth.google.ts +39 -0
- package/src/endpoints/conversations.ts +362 -0
- package/src/endpoints/graph.ts +398 -0
- package/src/endpoints/graphAi.ts +111 -0
- package/src/endpoints/health.ts +40 -0
- package/src/endpoints/me.ts +97 -0
- package/src/endpoints/note.ts +351 -0
- package/src/endpoints/notification.ts +69 -0
- package/src/endpoints/sync.ts +71 -0
- package/src/http-builder.ts +290 -0
- package/src/index.ts +60 -0
- package/src/types/aiInput.ts +111 -0
- package/src/types/conversation.ts +51 -0
- package/src/types/graph.ts +201 -0
- package/src/types/graphAi.ts +21 -0
- package/src/types/me.ts +49 -0
- package/src/types/message.ts +40 -0
- package/src/types/note.ts +89 -0
- package/src/types/problem.ts +22 -0
- package/src/types/sync.ts +35 -0
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { RequestBuilder, type HttpResponse } from '../http-builder.js';
|
|
2
|
+
import type {
|
|
3
|
+
NoteDto,
|
|
4
|
+
NoteCreateDto,
|
|
5
|
+
NoteUpdateDto,
|
|
6
|
+
FolderDto,
|
|
7
|
+
FolderCreateDto,
|
|
8
|
+
FolderUpdateDto,
|
|
9
|
+
} from '../types/note.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Note API
|
|
13
|
+
*
|
|
14
|
+
* 노트(Note)와 폴더(Folder)를 관리하는 API 클래스입니다.
|
|
15
|
+
* `/v1/notes` 및 `/v1/folders` 엔드포인트 하위의 API들을 호출합니다.
|
|
16
|
+
*
|
|
17
|
+
* 주요 기능:
|
|
18
|
+
* - 노트 관리 (생성, 조회, 수정, 삭제) (`createNote`, `listNotes`, `getNote`, `updateNote`, `deleteNote`)
|
|
19
|
+
* - 폴더 관리 (생성, 조회, 수정, 삭제) (`createFolder`, `listFolders`, `getFolder`, `updateFolder`, `deleteFolder`)
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export class NoteApi {
|
|
24
|
+
private readonly rb: RequestBuilder;
|
|
25
|
+
|
|
26
|
+
constructor(rb: RequestBuilder) {
|
|
27
|
+
this.rb = rb.path('/v1');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// --- Notes ---
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 새 노트를 생성합니다.
|
|
34
|
+
* @param dto - 생성할 노트 데이터
|
|
35
|
+
* - `id` (string): 노트 고유 ID (UUID, 클라이언트 생성)
|
|
36
|
+
* - `content` (string): 노트 내용 (Markdown)
|
|
37
|
+
* - `title` (string, optional): 노트 제목
|
|
38
|
+
* - `folderId` (string | null, optional): 상위 폴더 ID (없으면 최상위)
|
|
39
|
+
* @returns 생성된 노트 정보
|
|
40
|
+
* - `id` (string): 노트 ID
|
|
41
|
+
* - `ownerUserId` (string): 소유자 ID
|
|
42
|
+
* - `title` (string): 제목
|
|
43
|
+
* - `content` (string): 내용
|
|
44
|
+
* - `folderId` (string | null): 폴더 ID
|
|
45
|
+
* - `createdAt` (string): 생성 일시 (ISO 8601)
|
|
46
|
+
* - `updatedAt` (string): 수정 일시 (ISO 8601)
|
|
47
|
+
* @example
|
|
48
|
+
* const response = await client.note.createNote({
|
|
49
|
+
* id: '550e8400-e29b-41d4-a716-446655440000',
|
|
50
|
+
* title: 'Meeting Notes',
|
|
51
|
+
* content: '# Weekly Sync\n- Discussed Q3 goals\n- Reviewed metrics',
|
|
52
|
+
* folderId: null
|
|
53
|
+
* });
|
|
54
|
+
*
|
|
55
|
+
* console.log(response.data);
|
|
56
|
+
* // Output:
|
|
57
|
+
* {
|
|
58
|
+
* id: '550e8400-e29b-41d4-a716-446655440000',
|
|
59
|
+
* title: 'Meeting Notes',
|
|
60
|
+
* content: '# Weekly Sync...',
|
|
61
|
+
* folderId: null,
|
|
62
|
+
* createdAt: '2023-10-27T10:00:00Z',
|
|
63
|
+
* updatedAt: '2023-10-27T10:00:00Z',
|
|
64
|
+
* ownerUserId: 'user-123'
|
|
65
|
+
* }
|
|
66
|
+
*/
|
|
67
|
+
createNote(dto: NoteCreateDto): Promise<HttpResponse<NoteDto>> {
|
|
68
|
+
return this.rb.path('/notes').post<NoteDto>(dto);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 사용자의 모든 노트를 가져옵니다.
|
|
73
|
+
* @returns 노트 목록 (NoteDto 배열)
|
|
74
|
+
* @example
|
|
75
|
+
* const response = await client.note.listNotes();
|
|
76
|
+
*
|
|
77
|
+
* console.log(response.data);
|
|
78
|
+
* // Output:
|
|
79
|
+
* [
|
|
80
|
+
* {
|
|
81
|
+
* id: '550e8400-e29b-41d4-a716-446655440000',
|
|
82
|
+
* title: 'Meeting Notes',
|
|
83
|
+
* content: '...',
|
|
84
|
+
* folderId: null,
|
|
85
|
+
* createdAt: '...',
|
|
86
|
+
* updatedAt: '...',
|
|
87
|
+
* ownerUserId: 'user-123'
|
|
88
|
+
* },
|
|
89
|
+
* {
|
|
90
|
+
* id: '661f9511-f30c-52e5-b827-557766551111',
|
|
91
|
+
* title: 'Ideas',
|
|
92
|
+
* content: '...',
|
|
93
|
+
* folderId: 'folder-123',
|
|
94
|
+
* createdAt: '...',
|
|
95
|
+
* updatedAt: '...',
|
|
96
|
+
* ownerUserId: 'user-123'
|
|
97
|
+
* }
|
|
98
|
+
* ]
|
|
99
|
+
*/
|
|
100
|
+
listNotes(): Promise<HttpResponse<NoteDto[]>> {
|
|
101
|
+
return this.rb.path('/notes').get<NoteDto[]>();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 특정 ID의 노트를 가져옵니다.
|
|
106
|
+
* @param id - 가져올 노트의 ID (UUID)
|
|
107
|
+
* @returns 요청한 노트 상세 정보
|
|
108
|
+
* @example
|
|
109
|
+
* const response = await client.note.getNote('550e8400-e29b-41d4-a716-446655440000');
|
|
110
|
+
*
|
|
111
|
+
* console.log(response.data);
|
|
112
|
+
* // Output:
|
|
113
|
+
* {
|
|
114
|
+
* id: '550e8400-e29b-41d4-a716-446655440000',
|
|
115
|
+
* title: 'Meeting Notes',
|
|
116
|
+
* content: '# Weekly Sync\n- Discussed Q3 goals...',
|
|
117
|
+
* folderId: null,
|
|
118
|
+
* createdAt: '...',
|
|
119
|
+
* updatedAt: '...',
|
|
120
|
+
* ownerUserId: 'user-123'
|
|
121
|
+
* }
|
|
122
|
+
*/
|
|
123
|
+
getNote(id: string): Promise<HttpResponse<NoteDto>> {
|
|
124
|
+
return this.rb.path(`/notes/${id}`).get<NoteDto>();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 특정 노드를 업데이트합니다.
|
|
129
|
+
* @param id - 업데이트할 노트의 ID
|
|
130
|
+
* @param dto - 업데이트할 데이터
|
|
131
|
+
* - `title` (string, optional): 변경할 제목
|
|
132
|
+
* - `content` (string, optional): 변경할 내용
|
|
133
|
+
* - `folderId` (string | null, optional): 이동할 폴더 ID
|
|
134
|
+
* @returns 업데이트된 노트 정보
|
|
135
|
+
* @example
|
|
136
|
+
* const response = await client.note.updateNote('550e8400-e29b-41d4-a716-446655440000', {
|
|
137
|
+
* title: 'Q3 Review Meeting',
|
|
138
|
+
* content: '# Q3 Review\n- Goals achieved'
|
|
139
|
+
* });
|
|
140
|
+
*
|
|
141
|
+
* console.log(response.data);
|
|
142
|
+
* // Output:
|
|
143
|
+
* {
|
|
144
|
+
* id: '550e8400-e29b-41d4-a716-446655440000',
|
|
145
|
+
* title: 'Q3 Review Meeting',
|
|
146
|
+
* content: '# Q3 Review...',
|
|
147
|
+
* folderId: null,
|
|
148
|
+
* createdAt: '...',
|
|
149
|
+
* updatedAt: '2023-10-27T11:30:00Z',
|
|
150
|
+
* ownerUserId: 'user-123'
|
|
151
|
+
* }
|
|
152
|
+
*/
|
|
153
|
+
updateNote(id: string, dto: NoteUpdateDto): Promise<HttpResponse<NoteDto>> {
|
|
154
|
+
return this.rb.path(`/notes/${id}`).patch<NoteDto>(dto);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 특정 노트를 삭제합니다.
|
|
159
|
+
* @param id - 삭제할 노트의 ID
|
|
160
|
+
* @param permanent - 영구 삭제 여부 (true: 영구 삭제, false/undefined: 휴지통 이동)
|
|
161
|
+
* @returns 성공 시 빈 응답
|
|
162
|
+
* @example
|
|
163
|
+
* // 휴지통으로 이동 (Soft Delete)
|
|
164
|
+
* const response = await client.note.deleteNote('550e8400-e29b-41d4-a716-446655440000');
|
|
165
|
+
*
|
|
166
|
+
* console.log(response.data);
|
|
167
|
+
* // Output:
|
|
168
|
+
* {
|
|
169
|
+
* ok: true
|
|
170
|
+
* }
|
|
171
|
+
*/
|
|
172
|
+
deleteNote(id: string, permanent?: boolean): Promise<HttpResponse<void>> {
|
|
173
|
+
return this.rb.path(`/notes/${id}`).query({ permanent }).delete<void>();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* 모든 노트를 삭제합니다.
|
|
178
|
+
* @returns 삭제된 노트 수
|
|
179
|
+
* @example
|
|
180
|
+
* const response = await client.note.deleteAllNotes();
|
|
181
|
+
* console.log(response.data.deletedCount); // 10
|
|
182
|
+
*/
|
|
183
|
+
async deleteAllNotes(): Promise<HttpResponse<{ deletedCount: number }>> {
|
|
184
|
+
return this.rb.path('/notes').delete<{ deletedCount: number }>();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* 특정 노트를 복구합니다.
|
|
189
|
+
* @param id - 복구할 노트의 ID
|
|
190
|
+
* @returns 복구된 노트 정보
|
|
191
|
+
* @example
|
|
192
|
+
* const response = await client.note.restoreNote('550e8400-e29b-41d4-a716-446655440000');
|
|
193
|
+
*
|
|
194
|
+
* console.log(response.data);
|
|
195
|
+
* // Output:
|
|
196
|
+
* {
|
|
197
|
+
* id: '550e8400-e29b-41d4-a716-446655440000',
|
|
198
|
+
* title: 'Meeting Notes',
|
|
199
|
+
* content: '...',
|
|
200
|
+
* folderId: null,
|
|
201
|
+
* createdAt: '...',
|
|
202
|
+
* updatedAt: '...',
|
|
203
|
+
* ownerUserId: 'user-123'
|
|
204
|
+
* }
|
|
205
|
+
*/
|
|
206
|
+
restoreNote(id: string): Promise<HttpResponse<NoteDto>> {
|
|
207
|
+
return this.rb.path(`/notes/${id}/restore`).post<NoteDto>({});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// --- Folders ---
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* 새 폴더를 생성합니다.
|
|
214
|
+
* @param dto - 생성할 폴더 데이터
|
|
215
|
+
* - `name` (string): 폴더 이름
|
|
216
|
+
* - `parentId` (string | null, optional): 상위 폴더 ID (없으면 최상위)
|
|
217
|
+
* @returns 생성된 폴더 정보
|
|
218
|
+
* - `id` (string): 폴더 ID
|
|
219
|
+
* - `ownerUserId` (string): 소유자 ID
|
|
220
|
+
* - `name` (string): 폴더 이름
|
|
221
|
+
* - `parentId` (string | null): 상위 폴더 ID
|
|
222
|
+
* - `createdAt` (string): 생성 일시
|
|
223
|
+
* - `updatedAt` (string): 수정 일시
|
|
224
|
+
* @example
|
|
225
|
+
* const response = await client.note.createFolder({
|
|
226
|
+
* name: 'Work Projects',
|
|
227
|
+
* parentId: null
|
|
228
|
+
* });
|
|
229
|
+
*
|
|
230
|
+
* console.log(response.data);
|
|
231
|
+
* // Output:
|
|
232
|
+
* {
|
|
233
|
+
* id: 'folder-123',
|
|
234
|
+
* name: 'Work Projects',
|
|
235
|
+
* parentId: null,
|
|
236
|
+
* createdAt: '...',
|
|
237
|
+
* updatedAt: '...',
|
|
238
|
+
* ownerUserId: 'user-123'
|
|
239
|
+
* }
|
|
240
|
+
*/
|
|
241
|
+
createFolder(dto: FolderCreateDto): Promise<HttpResponse<FolderDto>> {
|
|
242
|
+
return this.rb.path('/folders').post<FolderDto>(dto);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* 사용자의 모든 폴더를 가져옵니다.
|
|
247
|
+
* @returns 폴더 목록 (FolderDto 배열)
|
|
248
|
+
* @example
|
|
249
|
+
* const response = await client.note.listFolders();
|
|
250
|
+
*
|
|
251
|
+
* console.log(response.data);
|
|
252
|
+
* // Output:
|
|
253
|
+
* [
|
|
254
|
+
* {
|
|
255
|
+
* id: 'folder-123',
|
|
256
|
+
* name: 'Work Projects',
|
|
257
|
+
* parentId: null,
|
|
258
|
+
* createdAt: '...',
|
|
259
|
+
* updatedAt: '...',
|
|
260
|
+
* ownerUserId: 'user-123'
|
|
261
|
+
* },
|
|
262
|
+
* {
|
|
263
|
+
* id: 'folder-124',
|
|
264
|
+
* name: 'Personal',
|
|
265
|
+
* parentId: null,
|
|
266
|
+
* createdAt: '...',
|
|
267
|
+
* updatedAt: '...',
|
|
268
|
+
* ownerUserId: 'user-123'
|
|
269
|
+
* }
|
|
270
|
+
* ]
|
|
271
|
+
*/
|
|
272
|
+
listFolders(): Promise<HttpResponse<FolderDto[]>> {
|
|
273
|
+
return this.rb.path('/folders').get<FolderDto[]>();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* 특정 ID의 폴더를 가져옵니다.
|
|
278
|
+
* @param id - 가져올 폴더의 ID
|
|
279
|
+
* @returns 요청한 폴더 상세 정보
|
|
280
|
+
* @example
|
|
281
|
+
* const response = await client.note.getFolder('folder-123');
|
|
282
|
+
*
|
|
283
|
+
* console.log(response.data);
|
|
284
|
+
* // Output:
|
|
285
|
+
* {
|
|
286
|
+
* id: 'folder-123',
|
|
287
|
+
* name: 'Work Projects',
|
|
288
|
+
* parentId: null,
|
|
289
|
+
* createdAt: '...',
|
|
290
|
+
* updatedAt: '...',
|
|
291
|
+
* ownerUserId: 'user-123'
|
|
292
|
+
* }
|
|
293
|
+
*/
|
|
294
|
+
getFolder(id: string): Promise<HttpResponse<FolderDto>> {
|
|
295
|
+
return this.rb.path(`/folders/${id}`).get<FolderDto>();
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* 특정 폴더를 업데이트합니다.
|
|
300
|
+
* @param id - 업데이트할 폴더의 ID
|
|
301
|
+
* @param dto - 업데이트할 데이터
|
|
302
|
+
* - `name` (string, optional): 변경할 폴더 이름
|
|
303
|
+
* - `parentId` (string | null, optional): 이동할 상위 폴더 ID
|
|
304
|
+
* @returns 업데이트된 폴더 정보
|
|
305
|
+
* @example
|
|
306
|
+
* const response = await client.note.updateFolder('folder-123', {
|
|
307
|
+
* name: 'Archived Projects',
|
|
308
|
+
* parentId: 'folder-999' // Move to another folder
|
|
309
|
+
* });
|
|
310
|
+
* console.log(response.data.name); // 'Archived Projects'
|
|
311
|
+
* console.log(response.data.parentId); // 'folder-999'
|
|
312
|
+
*/
|
|
313
|
+
updateFolder(id: string, dto: FolderUpdateDto): Promise<HttpResponse<FolderDto>> {
|
|
314
|
+
return this.rb.path(`/folders/${id}`).patch<FolderDto>(dto);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* 특정 폴더를 삭제합니다.
|
|
319
|
+
* @param id - 삭제할 폴더의 ID
|
|
320
|
+
* @param permanent - 영구 삭제 여부 (true: 영구 삭제, false/undefined: 휴지통 이동)
|
|
321
|
+
* @returns 성공 시 빈 응답
|
|
322
|
+
* @example
|
|
323
|
+
* await client.note.deleteFolder('folder-123');
|
|
324
|
+
*/
|
|
325
|
+
deleteFolder(id: string, permanent?: boolean): Promise<HttpResponse<void>> {
|
|
326
|
+
return this.rb.path(`/folders/${id}`).query({ permanent }).delete<void>();
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* 모든 폴더를 삭제합니다.
|
|
331
|
+
* @returns 삭제된 폴더 수
|
|
332
|
+
* @example
|
|
333
|
+
* const response = await client.note.deleteAllFolders();
|
|
334
|
+
* console.log(response.data.deletedCount); // 3
|
|
335
|
+
*/
|
|
336
|
+
async deleteAllFolders(): Promise<HttpResponse<{ deletedCount: number }>> {
|
|
337
|
+
return this.rb.path('/folders').delete<{ deletedCount: number }>();
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* 특정 폴더를 복구합니다.
|
|
342
|
+
* @param id - 복구할 폴더의 ID
|
|
343
|
+
* @returns 복구된 폴더 정보
|
|
344
|
+
* @example
|
|
345
|
+
* const response = await client.note.restoreFolder('folder-123');
|
|
346
|
+
* console.log(response.data.id); // 'folder-123'
|
|
347
|
+
*/
|
|
348
|
+
restoreFolder(id: string): Promise<HttpResponse<FolderDto>> {
|
|
349
|
+
return this.rb.path(`/folders/${id}/restore`).post<FolderDto>({});
|
|
350
|
+
}
|
|
351
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { RequestBuilder } from '../http-builder.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Notification API
|
|
5
|
+
*
|
|
6
|
+
* 사용자 알림 및 실시간 이벤트 스트림을 관리하는 API 클래스입니다.
|
|
7
|
+
* `/v1/notifications` 엔드포인트 하위의 API들을 사용합니다.
|
|
8
|
+
*
|
|
9
|
+
* 주요 기능:
|
|
10
|
+
* - 실시간 알림 스트림 URL 조회 (`getStreamUrl`)
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export class NotificationApi {
|
|
15
|
+
private readonly rb: RequestBuilder;
|
|
16
|
+
|
|
17
|
+
constructor(rb: RequestBuilder) {
|
|
18
|
+
this.rb = rb.path('/v1/notifications');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated
|
|
23
|
+
* 실시간 알림 수신을 위한 SSE(Server-Sent Events) 스트림 URL을 반환합니다.
|
|
24
|
+
*
|
|
25
|
+
* 이 엔드포인트는 `text/event-stream` 형식으로 데이터를 스트리밍합니다.
|
|
26
|
+
* 클라이언트는 `EventSource` API를 사용하여 연결해야 합니다.
|
|
27
|
+
*
|
|
28
|
+
* 참고:
|
|
29
|
+
* - 이 메서드는 HTTP 요청을 수행하지 않고, 연결 가능한 URL 문자열만 반환합니다.
|
|
30
|
+
* - 세션 기반 인증을 사용하므로, 브라우저의 `EventSource`가 쿠키를 전송하도록 설정해야 합니다.
|
|
31
|
+
*
|
|
32
|
+
* @returns SSE 연결을 위한 전체 URL 문자열
|
|
33
|
+
* @example
|
|
34
|
+
* const url = client.notification.getStreamUrl();
|
|
35
|
+
* const eventSource = new EventSource(url, { withCredentials: true });
|
|
36
|
+
*
|
|
37
|
+
* eventSource.onmessage = (event) => {
|
|
38
|
+
* const data = JSON.parse(event.data);
|
|
39
|
+
* console.log('Received notification:', data);
|
|
40
|
+
* };
|
|
41
|
+
*
|
|
42
|
+
* eventSource.onerror = (err) => {
|
|
43
|
+
* console.error('SSE Error:', err);
|
|
44
|
+
* eventSource.close();
|
|
45
|
+
* };
|
|
46
|
+
*/
|
|
47
|
+
getStreamUrl(): string {
|
|
48
|
+
return this.rb.path('/stream').url();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* FCM 디바이스 토큰을 등록합니다.
|
|
53
|
+
*
|
|
54
|
+
* @param token - FCM 디바이스 토큰
|
|
55
|
+
*/
|
|
56
|
+
async registerDeviceToken(token: string): Promise<void> {
|
|
57
|
+
await this.rb.path('/device-token').post({ token });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* FCM 디바이스 토큰을 삭제(등록 해제)합니다.
|
|
62
|
+
*
|
|
63
|
+
* @param token - 삭제할 FCM 디바이스 토큰
|
|
64
|
+
*/
|
|
65
|
+
async removeDeviceToken(token: string): Promise<void> {
|
|
66
|
+
await this.rb.path('/device-token').delete({ token });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { RequestBuilder, type HttpResponse } from '../http-builder.js';
|
|
2
|
+
import type { SyncPushRequest, SyncPullResponse } from '../types/sync.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Sync API
|
|
6
|
+
*
|
|
7
|
+
* 클라이언트와 서버 간의 데이터 동기화를 처리하는 API 클래스입니다.
|
|
8
|
+
* `/v1/sync` 엔드포인트 하위의 API들을 호출합니다.
|
|
9
|
+
*
|
|
10
|
+
* 주요 기능:
|
|
11
|
+
* - 변경 사항 가져오기 (Pull) (`pull`)
|
|
12
|
+
* - 변경 사항 보내기 (Push) (`push`)
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export class SyncApi {
|
|
17
|
+
constructor(private rb: RequestBuilder) {}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 서버로부터 변경된 데이터를 가져옵니다 (Pull).
|
|
21
|
+
* @param since - 마지막 동기화 시각 (ISO 8601). 생략 시 모든 데이터를 가져옵니다.
|
|
22
|
+
* @returns 변경된 데이터 목록 및 서버 시각
|
|
23
|
+
* - `conversations` (ConversationDto[]): 변경된 대화 목록
|
|
24
|
+
* - `messages` (MessageDto[]): 변경된 메시지 목록
|
|
25
|
+
* - `notes` (NoteDto[]): 변경된 노트 목록
|
|
26
|
+
* - `folders` (FolderDto[]): 변경된 폴더 목록
|
|
27
|
+
* - `serverTime` (string): 서버 현재 시각 (ISO 8601) - 다음 동기화 커서로 사용
|
|
28
|
+
* @example
|
|
29
|
+
* const lastSyncTime = '2023-10-27T10:00:00Z';
|
|
30
|
+
* const response = await client.sync.pull(lastSyncTime);
|
|
31
|
+
* console.log(response.data);
|
|
32
|
+
* // Output:
|
|
33
|
+
* {
|
|
34
|
+
* conversations: [
|
|
35
|
+
* { id: 'c_123', title: 'New Chat', ... }
|
|
36
|
+
* ],
|
|
37
|
+
* messages: [
|
|
38
|
+
* { id: 'm_456', content: 'Hello', ... }
|
|
39
|
+
* ],
|
|
40
|
+
* notes: [],
|
|
41
|
+
* folders: [],
|
|
42
|
+
* serverTime: '2023-10-27T12:00:00Z' // Use this for next sync
|
|
43
|
+
* }
|
|
44
|
+
*/
|
|
45
|
+
pull(since?: string | Date): Promise<HttpResponse<SyncPullResponse>> {
|
|
46
|
+
const sinceStr = since instanceof Date ? since.toISOString() : since;
|
|
47
|
+
return this.rb.path('/v1/sync/pull').query({ since: sinceStr }).get<SyncPullResponse>();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 클라이언트의 변경 사항을 서버로 전송합니다 (Push).
|
|
52
|
+
* @param data - 변경된 데이터 목록
|
|
53
|
+
* - `conversations` (ConversationDto[], optional): 변경된 대화 목록
|
|
54
|
+
* - `messages` (MessageDto[], optional): 변경된 메시지 목록 (conversationId 포함)
|
|
55
|
+
* - `notes` (NoteDto[], optional): 변경된 노트 목록
|
|
56
|
+
* - `folders` (FolderDto[], optional): 변경된 폴더 목록
|
|
57
|
+
* @example
|
|
58
|
+
* await client.sync.push({
|
|
59
|
+
* conversations: [
|
|
60
|
+
* { id: 'c_1', title: 'Updated Title', updatedAt: '2024-02-20T10:00:00Z' }
|
|
61
|
+
* ],
|
|
62
|
+
* messages: [
|
|
63
|
+
* { id: 'm_1', conversationId: 'c_1', content: 'New message', role: 'user' }
|
|
64
|
+
* ]
|
|
65
|
+
* });
|
|
66
|
+
* console.log('Sync push completed');
|
|
67
|
+
*/
|
|
68
|
+
push(data: SyncPushRequest): Promise<HttpResponse<{ success: boolean }>> {
|
|
69
|
+
return this.rb.path('/v1/sync/push').post<{ success: boolean }>(data);
|
|
70
|
+
}
|
|
71
|
+
}
|