@devpad/api 2.1.2 → 2.1.4

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.
Files changed (2) hide show
  1. package/README.md +101 -98
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,149 +1,152 @@
1
1
  # @devpad/api
2
2
 
3
- TypeScript client library for the Devpad API - project and task management made simple.
3
+ TypeScript API client for [devpad](https://devpad.tools) project management, task tracking, milestones, goals, and more.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @devpad/api
9
- # or
10
- yarn add @devpad/api
11
- # or
12
8
  bun add @devpad/api
13
9
  ```
14
10
 
15
- ## Quick Start
11
+ ## Quick start
16
12
 
17
13
  ```typescript
18
- import DevpadApiClient from '@devpad/api';
14
+ import ApiClient from "@devpad/api";
19
15
 
20
- const client = new DevpadApiClient({
21
- api_key: 'your-api-key-here',
22
- base_url: 'https://devpad.tools/api/v1' // optional, defaults to localhost:4321
23
- });
24
-
25
- // Create a project
26
- const project = await client.projects.create({
27
- name: 'My New Project',
28
- description: 'A project created via API',
29
- visibility: 'private'
30
- });
31
-
32
- // Create a task
33
- const task = await client.tasks.create({
34
- project_id: project.data.project_id,
35
- title: 'Implement new feature',
36
- description: 'Add user authentication',
37
- status: 'pending',
38
- priority: 'high',
39
- tags: ['feature', 'auth']
16
+ const client = new ApiClient({
17
+ base_url: "https://devpad.tools/api/v1",
18
+ api_key: "your-api-key",
40
19
  });
41
20
  ```
42
21
 
43
- ## API Reference
22
+ The constructor also accepts `auth_mode`, `credentials`, `default_headers`, and `custom_fetch`. Auth mode is auto-detected from the `api_key` format.
44
23
 
45
- ### DevpadApiClient
24
+ ## Error handling
46
25
 
47
- Main client class that provides access to all API endpoints.
26
+ All methods return `ApiResult<T>` which is `Result<T, ApiResultError>` from `@f0rbit/corpus`. No try/catch needed.
48
27
 
49
28
  ```typescript
50
- const client = new DevpadApiClient({
51
- api_key: string; // Required: Your Devpad API key
52
- base_url?: string; // Optional: API base URL (defaults to localhost:4321/api/v1)
53
- });
54
- ```
29
+ import ApiClient, { type ApiResult } from "@devpad/api";
55
30
 
56
- ### Projects API
31
+ const result = await client.projects.list();
57
32
 
58
- #### `client.projects.list()`
59
- Get all projects for the authenticated user.
33
+ if (!result.ok) {
34
+ console.error(result.error.message, result.error.status_code);
35
+ return;
36
+ }
60
37
 
61
- #### `client.projects.get(id: string)`
62
- Get a specific project by ID.
38
+ const projects = result.value;
39
+ ```
63
40
 
64
- #### `client.projects.getByName(name: string)`
65
- Get a project by name.
41
+ The `ok()` and `err()` constructors are re-exported for building your own Results.
66
42
 
67
- #### `client.projects.create(data: ProjectCreate)`
68
- Create a new project.
43
+ ## API reference
69
44
 
70
- #### `client.projects.update(project_id: string, data: Partial<ProjectUpdate>)`
71
- Update an existing project.
45
+ ### Projects
72
46
 
73
- #### `client.projects.upsert(data: ProjectUpsert)`
74
- Create or update a project (unified endpoint).
47
+ ```typescript
48
+ client.projects.list()
49
+ client.projects.find(id)
50
+ client.projects.getByName(name)
51
+ client.projects.create(data)
52
+ client.projects.upsert(data)
53
+ client.projects.config.load(id)
54
+ client.projects.config.save(id, config)
55
+ client.projects.history(id)
56
+ client.projects.specification(id)
57
+ client.projects.scan.initiate(name)
58
+ client.projects.scan.updates(id)
59
+ client.projects.map()
60
+ ```
75
61
 
76
- ### Tasks API
62
+ ### Tasks
77
63
 
78
- #### `client.tasks.list(options?: { project_id?: string; tag_id?: string })`
79
- Get tasks, optionally filtered by project or tag.
64
+ ```typescript
65
+ client.tasks.list(params?) // optional { project_id, tag_id }
66
+ client.tasks.find(id)
67
+ client.tasks.getByProject(id)
68
+ client.tasks.create(data)
69
+ client.tasks.upsert(data)
70
+ client.tasks.delete(id)
71
+ client.tasks.history.get(id)
72
+ ```
80
73
 
81
- #### `client.tasks.get(id: string)`
82
- Get a specific task by ID.
74
+ ### Milestones
83
75
 
84
- #### `client.tasks.getByProject(project_id: string)`
85
- Get all tasks for a specific project.
76
+ ```typescript
77
+ client.milestones.list(params?) // optional { project_id }
78
+ client.milestones.find(id)
79
+ client.milestones.getByProject(id)
80
+ client.milestones.create(data)
81
+ client.milestones.update(id, data)
82
+ client.milestones.delete(id)
83
+ client.milestones.goals(id)
84
+ ```
86
85
 
87
- #### `client.tasks.create(data: TaskCreate)`
88
- Create a new task.
86
+ ### Goals
89
87
 
90
- #### `client.tasks.update(task_id: string, data: Partial<TaskUpdate>)`
91
- Update an existing task.
88
+ ```typescript
89
+ client.goals.list()
90
+ client.goals.find(id)
91
+ client.goals.create(data)
92
+ client.goals.update(id, data)
93
+ client.goals.delete(id)
94
+ ```
92
95
 
93
- #### `client.tasks.upsert(data: TaskUpsert)`
94
- Create or update a task (unified endpoint).
96
+ ### Tags
95
97
 
96
- ### Types
98
+ ```typescript
99
+ client.tags.list()
100
+ client.tags.save(tags)
101
+ ```
97
102
 
98
- The library exports TypeScript types for all API operations:
103
+ ### Auth
99
104
 
100
105
  ```typescript
101
- import {
102
- ProjectType,
103
- TaskType,
104
- TagType,
105
- ProjectCreate,
106
- ProjectUpdate,
107
- ProjectUpsert,
108
- TaskCreate,
109
- TaskUpdate,
110
- TaskUpsert,
111
- ApiResponse
112
- } from '@devpad/api';
106
+ client.auth.keys.list()
107
+ client.auth.keys.create(data)
108
+ client.auth.keys.update(id, data)
109
+ client.auth.keys.delete(id)
110
+ client.auth.user()
111
+ client.auth.login(code)
112
+ client.auth.loginUrl()
113
113
  ```
114
114
 
115
- ### Error Handling
115
+ ### User
116
116
 
117
- The client throws typed errors for different failure scenarios:
117
+ ```typescript
118
+ client.user.history()
119
+ ```
120
+
121
+ ### GitHub
118
122
 
119
123
  ```typescript
120
- import { ApiError, AuthenticationError, NetworkError } from '@devpad/api';
121
-
122
- try {
123
- await client.projects.create({ name: 'Test Project' });
124
- } catch (error) {
125
- if (error instanceof AuthenticationError) {
126
- console.error('Invalid API key');
127
- } else if (error instanceof ApiError) {
128
- console.error('API Error:', error.message, error.statusCode);
129
- } else if (error instanceof NetworkError) {
130
- console.error('Network Error:', error.message);
131
- }
132
- }
124
+ client.github.repos()
125
+ client.github.branches(owner, repo)
133
126
  ```
134
127
 
135
- ## Authentication
128
+ Blog and media namespaces also exist but are documented separately.
136
129
 
137
- To use this API client, you need a Devpad API key. You can generate one through the Devpad web interface at your account settings.
130
+ ## Types
138
131
 
139
- ## Development
132
+ ```typescript
133
+ import ApiClient, {
134
+ type ApiResult,
135
+ type ApiResultError,
136
+ type AuthMode, // "session" | "key" | "cookie"
137
+ } from "@devpad/api";
138
+
139
+ // Schema types re-exported for convenience
140
+ import type {
141
+ Project,
142
+ TaskWithDetails,
143
+ UpsertProject,
144
+ UpsertTodo,
145
+ } from "@devpad/api";
146
+ ```
140
147
 
141
- This package is built with TypeScript and uses Bun for development. The source code is available at [github.com/f0rbit/devpad](https://github.com/f0rbit/devpad).
148
+ Result utilities `ok` and `err` are also exported from the main entry point.
142
149
 
143
150
  ## License
144
151
 
145
152
  MIT
146
-
147
- ## Support
148
-
149
- For issues and feature requests, please visit the [GitHub repository](https://github.com/f0rbit/devpad/issues).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devpad/api",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "author": {
5
5
  "name": "f0rbit",
6
6
  "url": "https://github.com/f0rbit"
@@ -27,7 +27,7 @@
27
27
  "zod": "^3.22.4"
28
28
  },
29
29
  "devDependencies": {
30
- "@devpad/schema": "^2.1.2",
30
+ "@devpad/schema": "^2.1.4",
31
31
  "@types/node": "^20.11.24",
32
32
  "bun-types": "latest",
33
33
  "eslint": "^8.57.0",