@codeguide/core 0.0.27 → 0.0.29
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 +50 -41
- package/__tests__/services/codespace/codespace-v2.test.ts +29 -18
- package/__tests__/services/usage/usage-service.test.ts +597 -85
- package/codeguide.ts +6 -0
- package/dist/codeguide.d.ts +3 -1
- package/dist/codeguide.js +2 -0
- package/dist/index.d.ts +4 -3
- package/dist/services/base/base-service.d.ts +21 -0
- package/dist/services/base/base-service.js +114 -0
- package/dist/services/codespace/codespace-service.d.ts +55 -1
- package/dist/services/codespace/codespace-service.js +260 -5
- package/dist/services/codespace/codespace-types.d.ts +193 -13
- package/dist/services/codespace/index.d.ts +1 -1
- package/dist/services/index.d.ts +4 -0
- package/dist/services/index.js +7 -1
- package/dist/services/projects/project-types.d.ts +66 -32
- package/dist/services/repository-analysis/repository-types.d.ts +1 -0
- package/dist/services/starter-kits/index.d.ts +2 -0
- package/dist/services/starter-kits/index.js +20 -0
- package/dist/services/starter-kits/starter-kits-service.d.ts +13 -0
- package/dist/services/starter-kits/starter-kits-service.js +27 -0
- package/dist/services/starter-kits/starter-kits-types.d.ts +34 -0
- package/dist/services/starter-kits/starter-kits-types.js +2 -0
- package/dist/services/tasks/task-service.d.ts +2 -1
- package/dist/services/tasks/task-service.js +8 -0
- package/dist/services/tasks/task-types.d.ts +26 -7
- package/dist/services/usage/usage-service.d.ts +5 -2
- package/dist/services/usage/usage-service.js +58 -9
- package/dist/services/usage/usage-types.d.ts +207 -34
- package/dist/services/users/index.d.ts +2 -0
- package/dist/services/users/index.js +20 -0
- package/dist/services/users/user-service.d.ts +12 -0
- package/dist/services/users/user-service.js +17 -0
- package/dist/services/users/user-types.d.ts +55 -0
- package/dist/services/users/user-types.js +2 -0
- package/docs/.vitepress/README.md +51 -0
- package/docs/.vitepress/config.ts +139 -0
- package/docs/.vitepress/theme/custom.css +80 -0
- package/docs/.vitepress/theme/index.ts +13 -0
- package/docs/.vitepress/tsconfig.json +19 -0
- package/docs/QUICKSTART.md +77 -0
- package/docs/README.md +134 -0
- package/docs/README_SETUP.md +46 -0
- package/docs/authentication.md +351 -0
- package/docs/codeguide-client.md +350 -0
- package/docs/codespace-models.md +1004 -0
- package/docs/codespace-service.md +558 -81
- package/docs/index.md +135 -0
- package/docs/package.json +14 -0
- package/docs/projects-service.md +688 -0
- package/docs/security-keys-service.md +773 -0
- package/docs/starter-kits-service.md +249 -0
- package/docs/task-service.md +955 -0
- package/docs/testsprite_tests/TC001_Homepage_Load_and_Hero_Section_Display.py +70 -0
- package/docs/testsprite_tests/TC002_Sidebar_Navigation_ExpandCollapse_Functionality.py +73 -0
- package/docs/testsprite_tests/TC003_Full_Text_Local_Search_with_Keyboard_Shortcut.py +90 -0
- package/docs/testsprite_tests/TC004_Dark_Mode_Toggle_and_Persistence.py +73 -0
- package/docs/testsprite_tests/TC005_Mobile_Responsiveness_and_Touch_Navigation.py +113 -0
- package/docs/testsprite_tests/TC006_GitHub_Integration_Edit_this_page_Links.py +73 -0
- package/docs/testsprite_tests/TC007_Syntax_Highlighting_and_Code_Copy_Functionality.py +73 -0
- package/docs/testsprite_tests/TC008_Auto_Generated_Table_of_Contents_Accuracy.py +73 -0
- package/docs/testsprite_tests/TC009_SEO_and_Content_Discoverability_Verification.py +73 -0
- package/docs/testsprite_tests/TC010_Accessibility_Compliance_WCAG_AA.py +73 -0
- package/docs/testsprite_tests/TC011_Local_Development_Workflow_Build_and_Hot_Reload.py +74 -0
- package/docs/testsprite_tests/TC012_Performance_Metrics_Compliance.py +73 -0
- package/docs/testsprite_tests/standard_prd.json +122 -0
- package/docs/testsprite_tests/testsprite-mcp-test-report.html +2508 -0
- package/docs/testsprite_tests/testsprite-mcp-test-report.md +273 -0
- package/docs/testsprite_tests/testsprite_frontend_test_plan.json +390 -0
- package/docs/usage-service.md +616 -0
- package/index.ts +11 -3
- package/package.json +16 -2
- package/plans/CODESPACE_LOGS_STREAMING_GUIDE.md +320 -0
- package/plans/CODESPACE_TASK_LOGS_API_COMPLETE_GUIDE.md +821 -0
- package/services/base/base-service.ts +130 -0
- package/services/codespace/codespace-service.ts +347 -8
- package/services/codespace/codespace-types.ts +263 -14
- package/services/codespace/index.ts +16 -1
- package/services/index.ts +4 -0
- package/services/projects/README.md +107 -34
- package/services/projects/project-types.ts +69 -32
- package/services/repository-analysis/repository-types.ts +1 -0
- package/services/starter-kits/index.ts +2 -0
- package/services/starter-kits/starter-kits-service.ts +33 -0
- package/services/starter-kits/starter-kits-types.ts +38 -0
- package/services/tasks/task-service.ts +10 -0
- package/services/tasks/task-types.ts +29 -7
- package/services/usage/usage-service.ts +59 -10
- package/services/usage/usage-types.ts +239 -34
- package/services/users/index.ts +2 -0
- package/services/users/user-service.ts +15 -0
- package/services/users/user-types.ts +59 -0
|
@@ -0,0 +1,688 @@
|
|
|
1
|
+
# Projects Service
|
|
2
|
+
|
|
3
|
+
The Projects Service provides methods for managing projects, including creation, retrieval, updates, deletion, and repository connections.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Projects Service allows you to:
|
|
8
|
+
- Create and manage projects
|
|
9
|
+
- Retrieve projects with filtering and pagination
|
|
10
|
+
- Connect GitHub repositories to projects
|
|
11
|
+
- Manage project documents
|
|
12
|
+
- Update and delete projects
|
|
13
|
+
|
|
14
|
+
## Setup
|
|
15
|
+
|
|
16
|
+
### Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @codeguide/core
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Basic Initialization
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { CodeGuide } from '@codeguide/core'
|
|
26
|
+
|
|
27
|
+
const codeguide = new CodeGuide({
|
|
28
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
29
|
+
databaseApiKey: 'sk_your_database_api_key',
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
// Access the projects service
|
|
33
|
+
const projects = codeguide.projects
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Methods Overview
|
|
37
|
+
|
|
38
|
+
| Method | Description | Endpoint |
|
|
39
|
+
|--------|-------------|----------|
|
|
40
|
+
| `getAllProjects()` | Get all projects with optional filtering | `GET /projects` |
|
|
41
|
+
| `getPaginatedProjects()` | Get paginated projects with advanced filtering | `GET /projects/paginated` |
|
|
42
|
+
| `getProjectById()` | Get a specific project by ID | `GET /projects/{id}` |
|
|
43
|
+
| `createProject()` | Create a new project | `POST /projects` |
|
|
44
|
+
| `updateProject()` | Update an existing project | `PUT /projects/{id}` |
|
|
45
|
+
| `deleteProject()` | Delete a project | `DELETE /projects/{id}` |
|
|
46
|
+
| `getProjectDocuments()` | Get documents for a project | `GET /projects/{id}/documents` |
|
|
47
|
+
| `connectRepository()` | Connect a GitHub repository to a project | `POST /projects/{id}/repository` |
|
|
48
|
+
|
|
49
|
+
## Detailed Method Documentation
|
|
50
|
+
|
|
51
|
+
### 1. getAllProjects()
|
|
52
|
+
|
|
53
|
+
Retrieves all projects for the authenticated user with optional filtering.
|
|
54
|
+
|
|
55
|
+
#### Signature
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
async getAllProjects(params?: GetProjectsRequest): Promise<Project[]>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
#### Parameters
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
interface GetProjectsRequest {
|
|
65
|
+
has_repository?: boolean // Filter by repository connection status
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
#### Returns
|
|
70
|
+
|
|
71
|
+
- `Promise<Project[]>`: Array of project objects
|
|
72
|
+
|
|
73
|
+
#### Example
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
// Get all projects
|
|
77
|
+
const allProjects = await codeguide.projects.getAllProjects()
|
|
78
|
+
|
|
79
|
+
// Get only projects with repositories
|
|
80
|
+
const projectsWithRepos = await codeguide.projects.getAllProjects({
|
|
81
|
+
has_repository: true,
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
console.log(`Found ${projectsWithRepos.length} projects with repositories`)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 2. getPaginatedProjects()
|
|
88
|
+
|
|
89
|
+
Retrieves projects with pagination and advanced filtering options.
|
|
90
|
+
|
|
91
|
+
#### Signature
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
async getPaginatedProjects(params: PaginatedProjectsRequest): Promise<PaginatedProjectsResponse>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
#### Parameters
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
interface PaginatedProjectsRequest {
|
|
101
|
+
page?: number // Page number (default: 1)
|
|
102
|
+
page_size?: number // Items per page
|
|
103
|
+
search_query?: string // Search query string
|
|
104
|
+
status?: string // Filter by status
|
|
105
|
+
start_date?: string // Filter by start date (ISO format)
|
|
106
|
+
end_date?: string // Filter by end date (ISO format)
|
|
107
|
+
sort_by_date?: 'asc' | 'desc' // Sort order by date
|
|
108
|
+
has_repository?: boolean // Filter by repository connection
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
#### Returns
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
interface PaginatedProjectsResponse {
|
|
116
|
+
status: string
|
|
117
|
+
data: Project[]
|
|
118
|
+
count: number // Total number of items
|
|
119
|
+
page: number // Current page
|
|
120
|
+
page_size: number // Items per page
|
|
121
|
+
total_pages: number // Total number of pages
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### Example
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
// Get first page of projects
|
|
129
|
+
const firstPage = await codeguide.projects.getPaginatedProjects({
|
|
130
|
+
page: 1,
|
|
131
|
+
page_size: 10,
|
|
132
|
+
sort_by_date: 'desc',
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
console.log(`Page ${firstPage.page} of ${firstPage.total_pages}`)
|
|
136
|
+
console.log(`Showing ${firstPage.data.length} of ${firstPage.count} projects`)
|
|
137
|
+
|
|
138
|
+
// Search projects
|
|
139
|
+
const searchResults = await codeguide.projects.getPaginatedProjects({
|
|
140
|
+
search_query: 'authentication',
|
|
141
|
+
page_size: 20,
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
// Filter by date range
|
|
145
|
+
const recentProjects = await codeguide.projects.getPaginatedProjects({
|
|
146
|
+
start_date: '2024-01-01',
|
|
147
|
+
end_date: '2024-12-31',
|
|
148
|
+
sort_by_date: 'desc',
|
|
149
|
+
})
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### 3. getProjectById()
|
|
153
|
+
|
|
154
|
+
Retrieves a specific project by its ID.
|
|
155
|
+
|
|
156
|
+
#### Signature
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
async getProjectById(projectId: string): Promise<Project>
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
#### Parameters
|
|
163
|
+
|
|
164
|
+
- `projectId` (string, required): The project ID
|
|
165
|
+
|
|
166
|
+
#### Returns
|
|
167
|
+
|
|
168
|
+
- `Promise<Project>`: Project object with full details
|
|
169
|
+
|
|
170
|
+
#### Example
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
const project = await codeguide.projects.getProjectById('proj_123456')
|
|
174
|
+
|
|
175
|
+
console.log(`Project: ${project.title}`)
|
|
176
|
+
console.log(`Description: ${project.description}`)
|
|
177
|
+
console.log(`Repositories: ${project.project_repositories.length}`)
|
|
178
|
+
console.log(`Documents: ${project.project_documents.length}`)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### 4. createProject()
|
|
182
|
+
|
|
183
|
+
Creates a new project.
|
|
184
|
+
|
|
185
|
+
#### Signature
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
async createProject(request: CreateProjectRequest): Promise<Project>
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
#### Parameters
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
interface CreateProjectRequest {
|
|
195
|
+
title: string // Required: Project title
|
|
196
|
+
description: string // Required: Project description
|
|
197
|
+
category_id?: string // Optional: Category ID
|
|
198
|
+
codie_tool_id?: string // Optional: Codie tool ID
|
|
199
|
+
tools_selected?: string[] // Optional: Selected tools
|
|
200
|
+
ai_questionaire?: Record<string, any> // Optional: AI questionnaire data
|
|
201
|
+
project_outline?: Record<string, any> // Optional: Project outline
|
|
202
|
+
github_url?: string // Optional: GitHub URL
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
#### Returns
|
|
207
|
+
|
|
208
|
+
- `Promise<Project>`: Created project object
|
|
209
|
+
|
|
210
|
+
#### Example
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
// Basic project creation
|
|
214
|
+
const project = await codeguide.projects.createProject({
|
|
215
|
+
title: 'My New Project',
|
|
216
|
+
description: 'A project for building a web application',
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
console.log(`Created project: ${project.id}`)
|
|
220
|
+
|
|
221
|
+
// Project with additional metadata
|
|
222
|
+
const detailedProject = await codeguide.projects.createProject({
|
|
223
|
+
title: 'E-commerce Platform',
|
|
224
|
+
description: 'Full-featured e-commerce solution',
|
|
225
|
+
category_id: 'cat_123',
|
|
226
|
+
tools_selected: ['react', 'nodejs', 'postgresql'],
|
|
227
|
+
github_url: 'https://github.com/user/ecommerce',
|
|
228
|
+
ai_questionaire: {
|
|
229
|
+
target_audience: 'Small businesses',
|
|
230
|
+
tech_stack: 'React, Node.js',
|
|
231
|
+
},
|
|
232
|
+
})
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### 5. updateProject()
|
|
236
|
+
|
|
237
|
+
Updates an existing project.
|
|
238
|
+
|
|
239
|
+
#### Signature
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
async updateProject(projectId: string, request: UpdateProjectRequest): Promise<Project>
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
#### Parameters
|
|
246
|
+
|
|
247
|
+
- `projectId` (string, required): The project ID to update
|
|
248
|
+
- `request` (UpdateProjectRequest): Update request object
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
interface UpdateProjectRequest {
|
|
252
|
+
title?: string // Optional: New title
|
|
253
|
+
description?: string // Optional: New description
|
|
254
|
+
category_id?: string // Optional: New category ID
|
|
255
|
+
codie_tool_id?: string // Optional: New Codie tool ID
|
|
256
|
+
tools_selected?: string[] // Optional: Updated tools
|
|
257
|
+
ai_questionaire?: Record<string, any> // Optional: Updated questionnaire
|
|
258
|
+
project_outline?: Record<string, any> // Optional: Updated outline
|
|
259
|
+
github_url?: string // Optional: Updated GitHub URL
|
|
260
|
+
status?: string // Optional: Project status
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
#### Returns
|
|
265
|
+
|
|
266
|
+
- `Promise<Project>`: Updated project object
|
|
267
|
+
|
|
268
|
+
#### Example
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
// Update project title and description
|
|
272
|
+
const updated = await codeguide.projects.updateProject('proj_123456', {
|
|
273
|
+
title: 'Updated Project Title',
|
|
274
|
+
description: 'Updated description',
|
|
275
|
+
})
|
|
276
|
+
|
|
277
|
+
// Update project status
|
|
278
|
+
const statusUpdated = await codeguide.projects.updateProject('proj_123456', {
|
|
279
|
+
status: 'completed',
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
// Update multiple fields
|
|
283
|
+
const multiUpdate = await codeguide.projects.updateProject('proj_123456', {
|
|
284
|
+
title: 'New Title',
|
|
285
|
+
tools_selected: ['react', 'typescript'],
|
|
286
|
+
github_url: 'https://github.com/user/new-repo',
|
|
287
|
+
})
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### 6. deleteProject()
|
|
291
|
+
|
|
292
|
+
Deletes a project.
|
|
293
|
+
|
|
294
|
+
#### Signature
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
async deleteProject(projectId: string): Promise<{ status: string; message: string }>
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
#### Parameters
|
|
301
|
+
|
|
302
|
+
- `projectId` (string, required): The project ID to delete
|
|
303
|
+
|
|
304
|
+
#### Returns
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
{
|
|
308
|
+
status: string // Status of the deletion
|
|
309
|
+
message: string // Deletion message
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
#### Example
|
|
314
|
+
|
|
315
|
+
```typescript
|
|
316
|
+
const result = await codeguide.projects.deleteProject('proj_123456')
|
|
317
|
+
|
|
318
|
+
console.log(result.status) // "success"
|
|
319
|
+
console.log(result.message) // "Project deleted successfully"
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### 7. getProjectDocuments()
|
|
323
|
+
|
|
324
|
+
Retrieves documents associated with a project.
|
|
325
|
+
|
|
326
|
+
#### Signature
|
|
327
|
+
|
|
328
|
+
```typescript
|
|
329
|
+
async getProjectDocuments(
|
|
330
|
+
projectId: string,
|
|
331
|
+
params?: GetProjectDocumentsRequest
|
|
332
|
+
): Promise<GetProjectDocumentsResponse>
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
#### Parameters
|
|
336
|
+
|
|
337
|
+
- `projectId` (string, required): The project ID
|
|
338
|
+
- `params` (GetProjectDocumentsRequest, optional): Query parameters
|
|
339
|
+
|
|
340
|
+
```typescript
|
|
341
|
+
interface GetProjectDocumentsRequest {
|
|
342
|
+
current_version_only?: boolean // Only return current versions
|
|
343
|
+
}
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
#### Returns
|
|
347
|
+
|
|
348
|
+
```typescript
|
|
349
|
+
interface GetProjectDocumentsResponse {
|
|
350
|
+
status: string
|
|
351
|
+
data: ProjectDocument[]
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
interface ProjectDocument {
|
|
355
|
+
id: string
|
|
356
|
+
created_at: string
|
|
357
|
+
updated_at: string | null
|
|
358
|
+
project_id: string
|
|
359
|
+
user_id: string
|
|
360
|
+
title: string
|
|
361
|
+
document_type: string
|
|
362
|
+
description: string | null
|
|
363
|
+
content: string
|
|
364
|
+
custom_document_type: string
|
|
365
|
+
last_action: string
|
|
366
|
+
is_current_version: boolean
|
|
367
|
+
status: string
|
|
368
|
+
}
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
#### Example
|
|
372
|
+
|
|
373
|
+
```typescript
|
|
374
|
+
// Get all documents
|
|
375
|
+
const allDocs = await codeguide.projects.getProjectDocuments('proj_123456')
|
|
376
|
+
|
|
377
|
+
// Get only current versions
|
|
378
|
+
const currentDocs = await codeguide.projects.getProjectDocuments('proj_123456', {
|
|
379
|
+
current_version_only: true,
|
|
380
|
+
})
|
|
381
|
+
|
|
382
|
+
console.log(`Found ${currentDocs.data.length} current documents`)
|
|
383
|
+
currentDocs.data.forEach(doc => {
|
|
384
|
+
console.log(`- ${doc.title} (${doc.document_type})`)
|
|
385
|
+
})
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
### 8. connectRepository()
|
|
389
|
+
|
|
390
|
+
Connects a GitHub repository to a project.
|
|
391
|
+
|
|
392
|
+
#### Signature
|
|
393
|
+
|
|
394
|
+
```typescript
|
|
395
|
+
async connectRepository(
|
|
396
|
+
projectId: string,
|
|
397
|
+
request: ConnectRepositoryRequest
|
|
398
|
+
): Promise<ConnectRepositoryResponse>
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
#### Parameters
|
|
402
|
+
|
|
403
|
+
- `projectId` (string, required): The project ID
|
|
404
|
+
- `request` (ConnectRepositoryRequest): Repository connection request
|
|
405
|
+
|
|
406
|
+
```typescript
|
|
407
|
+
interface ConnectRepositoryRequest {
|
|
408
|
+
repo_url: string // Required: GitHub repository URL
|
|
409
|
+
branch: string // Required: Branch name
|
|
410
|
+
github_token?: string // Optional: GitHub personal access token
|
|
411
|
+
}
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
#### Returns
|
|
415
|
+
|
|
416
|
+
```typescript
|
|
417
|
+
interface ConnectRepositoryResponse {
|
|
418
|
+
status: string
|
|
419
|
+
data: {
|
|
420
|
+
id: string
|
|
421
|
+
project_id: string
|
|
422
|
+
repo_url: string
|
|
423
|
+
branch: string
|
|
424
|
+
connection_status: 'pending' | 'connected' | 'failed'
|
|
425
|
+
created_at: string
|
|
426
|
+
updated_at: string
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
#### Validation Rules
|
|
432
|
+
|
|
433
|
+
The method validates:
|
|
434
|
+
- Repository URL must be a valid GitHub URL (format: `https://github.com/user/repo`)
|
|
435
|
+
- Branch name must contain only alphanumeric characters, dots, underscores, and hyphens
|
|
436
|
+
- GitHub token (if provided) must be a valid personal access token (prefixes: `ghp_`, `gho_`, `ghu_`, `ghs_`, `ghr_`)
|
|
437
|
+
|
|
438
|
+
#### Example
|
|
439
|
+
|
|
440
|
+
```typescript
|
|
441
|
+
// Connect repository without token (uses stored token if available)
|
|
442
|
+
const connection = await codeguide.projects.connectRepository('proj_123456', {
|
|
443
|
+
repo_url: 'https://github.com/user/my-repo',
|
|
444
|
+
branch: 'main',
|
|
445
|
+
})
|
|
446
|
+
|
|
447
|
+
console.log(`Connection status: ${connection.data.connection_status}`)
|
|
448
|
+
|
|
449
|
+
// Connect repository with explicit token
|
|
450
|
+
const connectionWithToken = await codeguide.projects.connectRepository('proj_123456', {
|
|
451
|
+
repo_url: 'https://github.com/user/my-repo',
|
|
452
|
+
branch: 'develop',
|
|
453
|
+
github_token: 'ghp_your_github_token',
|
|
454
|
+
})
|
|
455
|
+
|
|
456
|
+
// Check connection status
|
|
457
|
+
if (connectionWithToken.data.connection_status === 'connected') {
|
|
458
|
+
console.log('Repository connected successfully')
|
|
459
|
+
} else if (connectionWithToken.data.connection_status === 'pending') {
|
|
460
|
+
console.log('Repository connection pending')
|
|
461
|
+
} else {
|
|
462
|
+
console.log('Repository connection failed')
|
|
463
|
+
}
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
## Type Definitions
|
|
467
|
+
|
|
468
|
+
### Project
|
|
469
|
+
|
|
470
|
+
```typescript
|
|
471
|
+
interface Project {
|
|
472
|
+
id: string
|
|
473
|
+
title: string
|
|
474
|
+
description: string
|
|
475
|
+
user_id: string
|
|
476
|
+
created_at: string
|
|
477
|
+
updated_at: string
|
|
478
|
+
project_documents: ProjectDocument[]
|
|
479
|
+
project_repositories: ProjectRepository[]
|
|
480
|
+
category?: Category
|
|
481
|
+
codie_tool?: CodieTool
|
|
482
|
+
github_url?: string
|
|
483
|
+
status?: string
|
|
484
|
+
tools_selected?: string[]
|
|
485
|
+
ai_questionaire?: Record<string, any>
|
|
486
|
+
project_outline?: Record<string, any>
|
|
487
|
+
}
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
### ProjectRepository
|
|
491
|
+
|
|
492
|
+
```typescript
|
|
493
|
+
interface ProjectRepository {
|
|
494
|
+
id: string
|
|
495
|
+
project_id: string
|
|
496
|
+
repo_url: string
|
|
497
|
+
branch: string
|
|
498
|
+
author: string
|
|
499
|
+
name: string
|
|
500
|
+
connection_status: 'pending' | 'connected' | 'failed'
|
|
501
|
+
created_at: string
|
|
502
|
+
updated_at: string
|
|
503
|
+
}
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
### Category
|
|
507
|
+
|
|
508
|
+
```typescript
|
|
509
|
+
interface Category {
|
|
510
|
+
id: string
|
|
511
|
+
name: string
|
|
512
|
+
description?: string
|
|
513
|
+
}
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
### CodieTool
|
|
517
|
+
|
|
518
|
+
```typescript
|
|
519
|
+
interface CodieTool {
|
|
520
|
+
id: string
|
|
521
|
+
name: string
|
|
522
|
+
description?: string
|
|
523
|
+
category?: string
|
|
524
|
+
}
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
## Error Handling
|
|
528
|
+
|
|
529
|
+
### Validation Errors
|
|
530
|
+
|
|
531
|
+
```typescript
|
|
532
|
+
try {
|
|
533
|
+
await codeguide.projects.connectRepository('proj_123', {
|
|
534
|
+
repo_url: 'invalid-url',
|
|
535
|
+
branch: 'main',
|
|
536
|
+
})
|
|
537
|
+
} catch (error) {
|
|
538
|
+
console.error(error.message) // "Repository URL must be a valid GitHub URL"
|
|
539
|
+
}
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
### API Errors
|
|
543
|
+
|
|
544
|
+
```typescript
|
|
545
|
+
try {
|
|
546
|
+
const project = await codeguide.projects.getProjectById('invalid_id')
|
|
547
|
+
} catch (error) {
|
|
548
|
+
if (error.message.includes('404')) {
|
|
549
|
+
console.error('Project not found')
|
|
550
|
+
} else if (error.message.includes('401')) {
|
|
551
|
+
console.error('Authentication failed')
|
|
552
|
+
} else {
|
|
553
|
+
console.error('API error:', error.message)
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
## Complete Examples
|
|
559
|
+
|
|
560
|
+
### Example 1: Project Lifecycle
|
|
561
|
+
|
|
562
|
+
```typescript
|
|
563
|
+
import { CodeGuide } from '@codeguide/core'
|
|
564
|
+
|
|
565
|
+
const codeguide = new CodeGuide({
|
|
566
|
+
baseUrl: 'https://api.codeguide.ai',
|
|
567
|
+
databaseApiKey: process.env.CODEGUIDE_API_KEY!,
|
|
568
|
+
})
|
|
569
|
+
|
|
570
|
+
async function projectLifecycle() {
|
|
571
|
+
try {
|
|
572
|
+
// 1. Create a new project
|
|
573
|
+
const project = await codeguide.projects.createProject({
|
|
574
|
+
title: 'My Web Application',
|
|
575
|
+
description: 'A modern web application built with React and Node.js',
|
|
576
|
+
})
|
|
577
|
+
|
|
578
|
+
console.log(`Created project: ${project.id}`)
|
|
579
|
+
|
|
580
|
+
// 2. Connect a repository
|
|
581
|
+
const repo = await codeguide.projects.connectRepository(project.id, {
|
|
582
|
+
repo_url: 'https://github.com/user/my-web-app',
|
|
583
|
+
branch: 'main',
|
|
584
|
+
})
|
|
585
|
+
|
|
586
|
+
console.log(`Repository connected: ${repo.data.connection_status}`)
|
|
587
|
+
|
|
588
|
+
// 3. Update project with additional information
|
|
589
|
+
const updated = await codeguide.projects.updateProject(project.id, {
|
|
590
|
+
tools_selected: ['react', 'nodejs', 'typescript'],
|
|
591
|
+
status: 'in_progress',
|
|
592
|
+
})
|
|
593
|
+
|
|
594
|
+
console.log(`Project updated: ${updated.title}`)
|
|
595
|
+
|
|
596
|
+
// 4. Get project documents
|
|
597
|
+
const documents = await codeguide.projects.getProjectDocuments(project.id, {
|
|
598
|
+
current_version_only: true,
|
|
599
|
+
})
|
|
600
|
+
|
|
601
|
+
console.log(`Found ${documents.data.length} documents`)
|
|
602
|
+
|
|
603
|
+
// 5. Get full project details
|
|
604
|
+
const fullProject = await codeguide.projects.getProjectById(project.id)
|
|
605
|
+
console.log(`Project has ${fullProject.project_repositories.length} repositories`)
|
|
606
|
+
} catch (error) {
|
|
607
|
+
console.error('Error:', error.message)
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
projectLifecycle()
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
### Example 2: Project Search and Filtering
|
|
615
|
+
|
|
616
|
+
```typescript
|
|
617
|
+
async function searchProjects() {
|
|
618
|
+
// Search for projects
|
|
619
|
+
const searchResults = await codeguide.projects.getPaginatedProjects({
|
|
620
|
+
search_query: 'authentication',
|
|
621
|
+
page: 1,
|
|
622
|
+
page_size: 10,
|
|
623
|
+
sort_by_date: 'desc',
|
|
624
|
+
})
|
|
625
|
+
|
|
626
|
+
console.log(`Found ${searchResults.count} projects matching "authentication"`)
|
|
627
|
+
|
|
628
|
+
// Get projects with repositories
|
|
629
|
+
const projectsWithRepos = await codeguide.projects.getPaginatedProjects({
|
|
630
|
+
has_repository: true,
|
|
631
|
+
page_size: 20,
|
|
632
|
+
})
|
|
633
|
+
|
|
634
|
+
console.log(`Found ${projectsWithRepos.data.length} projects with repositories`)
|
|
635
|
+
|
|
636
|
+
// Filter by date range
|
|
637
|
+
const recentProjects = await codeguide.projects.getPaginatedProjects({
|
|
638
|
+
start_date: '2024-01-01',
|
|
639
|
+
end_date: '2024-12-31',
|
|
640
|
+
sort_by_date: 'desc',
|
|
641
|
+
page_size: 50,
|
|
642
|
+
})
|
|
643
|
+
|
|
644
|
+
console.log(`Found ${recentProjects.count} projects in 2024`)
|
|
645
|
+
}
|
|
646
|
+
```
|
|
647
|
+
|
|
648
|
+
### Example 3: Batch Operations
|
|
649
|
+
|
|
650
|
+
```typescript
|
|
651
|
+
async function batchOperations() {
|
|
652
|
+
// Get all projects
|
|
653
|
+
const allProjects = await codeguide.projects.getAllProjects()
|
|
654
|
+
|
|
655
|
+
// Process each project
|
|
656
|
+
for (const project of allProjects) {
|
|
657
|
+
console.log(`Processing: ${project.title}`)
|
|
658
|
+
|
|
659
|
+
// Get documents for each project
|
|
660
|
+
const docs = await codeguide.projects.getProjectDocuments(project.id, {
|
|
661
|
+
current_version_only: true,
|
|
662
|
+
})
|
|
663
|
+
|
|
664
|
+
console.log(` - ${docs.data.length} documents`)
|
|
665
|
+
|
|
666
|
+
// Check repository status
|
|
667
|
+
if (project.project_repositories.length > 0) {
|
|
668
|
+
const repo = project.project_repositories[0]
|
|
669
|
+
console.log(` - Repository: ${repo.connection_status}`)
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
## Best Practices
|
|
676
|
+
|
|
677
|
+
1. **Use Pagination**: For large datasets, use `getPaginatedProjects()` instead of `getAllProjects()`
|
|
678
|
+
2. **Validate Input**: Validate repository URLs and branch names before calling `connectRepository()`
|
|
679
|
+
3. **Handle Errors**: Always wrap API calls in try-catch blocks
|
|
680
|
+
4. **Cache Results**: Cache project data when possible to reduce API calls
|
|
681
|
+
5. **Use Filters**: Use query parameters to filter results server-side rather than client-side
|
|
682
|
+
|
|
683
|
+
## Related Documentation
|
|
684
|
+
|
|
685
|
+
- [CodeGuide Client](./codeguide-client.md) - Client initialization
|
|
686
|
+
- [Authentication](./authentication.md) - Authentication methods
|
|
687
|
+
- [Codespace Service](./codespace-service.md) - Creating codespace tasks for projects
|
|
688
|
+
|