@devpad/api 2.0.0 → 2.0.2

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/dist/index.d.ts CHANGED
@@ -1,13 +1,541 @@
1
- import { ApiClient } from "./api-client";
2
- export type { Project, ProjectConfig, SaveConfigRequest, Task, TaskWithDetails, UpsertProject, UpsertTag, UpsertTodo, } from "@devpad/schema";
3
- export type { AccessKey, Category, CategoryCreate, Post, PostContent, PostCreate, PostListParams, PostsResponse, PostUpdate, VersionInfo, } from "@devpad/schema/blog";
4
- export type { Account, AddFilterInput, CreateProfileInput, PlatformSettings, Profile, ProfileFilter, Timeline, UpdateProfileInput, } from "@devpad/schema/media";
5
- export type { AuthMode } from "./api-client";
6
- export { getUserFriendlyErrorMessage, parseZodErrors } from "./error-handlers";
7
- export type { ApiError, AuthenticationError, NetworkError, ValidationError } from "./errors";
8
- export type { RequestHistoryEntry, RequestOptions } from "./request";
9
- export { type ApiResult, type ApiResultError, err, ok, type Result, wrap } from "./result";
10
- export { getTool, type ToolDefinition, toolNames, tools } from "./tools";
11
- export { ApiClient };
12
- export default ApiClient;
13
- //# sourceMappingURL=index.d.ts.map
1
+ import { A as ApiKey, P as Project, v as UpsertProject, L as GetConfigResult, E as SaveConfigRequest, M as Milestone, G as Goal, H as TaskWithDetails, w as UpsertTodo, x as UpsertTag, $ as HistoryAction, Q as TagWithTypedColor, a4 as BufferedQueue } from './types.d-CoHRMrYJ.js';
2
+ export { D as ProjectConfig, T as Task } from './types.d-CoHRMrYJ.js';
3
+ import { S as PostListParams, a0 as PostsResponse, O as Post, Q as PostCreate, a2 as PostUpdate, V as VersionInfo, P as PostContent, C as Category, t as CategoryCreate, A as AccessKey } from './types.d-1hBObc_N.js';
4
+ import { aC as Profile, C as CreateProfileInput, U as UpdateProfileInput, aD as ProfileFilter, A as AddFilterInput, Z as Timeline, ad as Account, H as PlatformSettings } from './types.d-UV8B6hPN.js';
5
+ import { Result } from '@f0rbit/corpus';
6
+ export { Result, err, ok } from '@f0rbit/corpus';
7
+ import { z } from 'zod';
8
+ import 'drizzle-orm';
9
+ import './schema.d-BceDyQED.js';
10
+ import 'drizzle-orm/sqlite-core';
11
+ import './media.d-R87HGuRp.js';
12
+
13
+ type RequestOptions = {
14
+ method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
15
+ headers?: Record<string, string>;
16
+ body?: unknown;
17
+ query?: Record<string, string>;
18
+ };
19
+ type RequestHistoryEntry = {
20
+ timestamp: string;
21
+ method: string;
22
+ path: string;
23
+ options: RequestOptions;
24
+ url: string;
25
+ status?: number;
26
+ duration?: number;
27
+ error?: string;
28
+ };
29
+
30
+ type ApiResultError = {
31
+ message: string;
32
+ code?: string;
33
+ status_code?: number;
34
+ };
35
+ type ApiResult<T> = Result<T, ApiResultError>;
36
+ declare function wrap<T>(fn: () => Promise<T>): Promise<ApiResult<T>>;
37
+
38
+ type TagWithCount = {
39
+ tag: string;
40
+ count: number;
41
+ };
42
+ type SanitizedToken = {
43
+ id: string;
44
+ name: string | null;
45
+ note: string | null;
46
+ enabled: boolean;
47
+ created_at: string;
48
+ };
49
+ type CreatedToken = SanitizedToken & {
50
+ token: string;
51
+ };
52
+ type AccessKeyCreate = {
53
+ name: string;
54
+ note?: string;
55
+ };
56
+ type AccessKeyUpdate = {
57
+ name?: string;
58
+ note?: string;
59
+ enabled?: boolean;
60
+ };
61
+ /**
62
+ * Authentication mode for the API client
63
+ */
64
+ type AuthMode = "session" | "key" | "cookie";
65
+ /**
66
+ * API client with Result-wrapped operations for clean error handling
67
+ * All methods return ApiResult<T> types using @f0rbit/corpus Result
68
+ */
69
+ declare class ApiClient {
70
+ private readonly clients;
71
+ private _api_key;
72
+ private _auth_mode;
73
+ constructor(options: {
74
+ base_url?: string;
75
+ api_key?: string;
76
+ auth_mode?: AuthMode;
77
+ max_history_size?: number;
78
+ credentials?: "include" | "omit" | "same-origin";
79
+ default_headers?: Record<string, string>;
80
+ custom_fetch?: typeof fetch;
81
+ });
82
+ /**
83
+ * Auth namespace with Result-wrapped operations
84
+ */
85
+ readonly auth: {
86
+ session: () => Promise<ApiResult<{
87
+ authenticated: boolean;
88
+ user: any;
89
+ session: any;
90
+ }>>;
91
+ keys: {
92
+ list: () => Promise<ApiResult<ApiKey[]>>;
93
+ create: (name?: string) => Promise<ApiResult<{
94
+ message: string;
95
+ key: string;
96
+ }>>;
97
+ revoke: (key_id: string) => Promise<ApiResult<{
98
+ message: string;
99
+ success: boolean;
100
+ }>>;
101
+ remove: (key_id: string) => Promise<ApiResult<{
102
+ message: string;
103
+ success: boolean;
104
+ }>>;
105
+ };
106
+ };
107
+ /**
108
+ * Projects namespace with Result-wrapped operations
109
+ */
110
+ readonly projects: {
111
+ /**
112
+ * List projects with optional filtering
113
+ */
114
+ list: (filters?: {
115
+ private?: boolean;
116
+ }) => Promise<ApiResult<Project[]>>;
117
+ /**
118
+ * Get project map
119
+ */
120
+ map: (filters?: {
121
+ private?: boolean;
122
+ }) => Promise<ApiResult<Record<string, Project>>>;
123
+ /**
124
+ * Get project by ID
125
+ */
126
+ find: (id: string) => Promise<ApiResult<Project | null>>;
127
+ /**
128
+ * Get project by name
129
+ */
130
+ getByName: (name: string) => Promise<ApiResult<Project>>;
131
+ /**
132
+ * Get project by ID (throws if not found)
133
+ */
134
+ getById: (id: string) => Promise<ApiResult<Project>>;
135
+ /**
136
+ * Create a new project
137
+ */
138
+ create: (data: Omit<UpsertProject, "id">) => Promise<ApiResult<Project>>;
139
+ /**
140
+ * Update an existing project
141
+ */
142
+ update: (idOrData: string | UpsertProject, changes?: Partial<Omit<UpsertProject, "id" | "project_id">>) => Promise<ApiResult<Project>>;
143
+ /**
144
+ * Project configuration operations
145
+ */
146
+ config: {
147
+ /**
148
+ * Get project configuration
149
+ */
150
+ load: (project_id: string) => Promise<ApiResult<GetConfigResult>>;
151
+ /**
152
+ * Save project configuration
153
+ */
154
+ save: (request: SaveConfigRequest) => Promise<ApiResult<void>>;
155
+ };
156
+ /**
157
+ * Scanning operations
158
+ */
159
+ scan: {
160
+ /**
161
+ * Initiate a repository scan (returns stream)
162
+ */
163
+ initiate: (project_id: string) => Promise<ReadableStream<string>>;
164
+ /**
165
+ * Get pending scan updates for a project
166
+ */
167
+ updates: (project_id: string) => Promise<ApiResult<any[]>>;
168
+ /**
169
+ * Process scan results
170
+ */
171
+ update: (project_id: string, data: any) => Promise<ApiResult<void>>;
172
+ };
173
+ /**
174
+ * Get project history
175
+ */
176
+ history: (project_id: string) => Promise<ApiResult<any[]>>;
177
+ /**
178
+ * Legacy methods (keeping for compatibility)
179
+ */
180
+ upsert: (data: UpsertProject) => Promise<ApiResult<Project>>;
181
+ /**
182
+ * Fetch project specification from GitHub
183
+ */
184
+ specification: (project_id: string) => Promise<ApiResult<string>>;
185
+ /**
186
+ * Delete project (soft delete)
187
+ */
188
+ deleteProject: (project: Project) => Promise<ApiResult<void>>;
189
+ };
190
+ /**
191
+ * Milestones namespace with Result-wrapped operations
192
+ */
193
+ readonly milestones: {
194
+ /**
195
+ * List milestones for authenticated user
196
+ */
197
+ list: () => Promise<ApiResult<Milestone[]>>;
198
+ /**
199
+ * Get milestones by project ID
200
+ */
201
+ getByProject: (project_id: string) => Promise<ApiResult<Milestone[]>>;
202
+ /**
203
+ * Get milestone by ID
204
+ */
205
+ find: (id: string) => Promise<ApiResult<Milestone | null>>;
206
+ /**
207
+ * Create new milestone
208
+ */
209
+ create: (data: {
210
+ project_id: string;
211
+ name: string;
212
+ description?: string;
213
+ target_time?: string;
214
+ target_version?: string;
215
+ }) => Promise<ApiResult<Milestone>>;
216
+ /**
217
+ * Update milestone
218
+ */
219
+ update: (id: string, data: {
220
+ name?: string;
221
+ description?: string;
222
+ target_time?: string;
223
+ target_version?: string;
224
+ }) => Promise<ApiResult<Milestone>>;
225
+ /**
226
+ * Delete milestone (soft delete)
227
+ */
228
+ delete: (id: string) => Promise<ApiResult<{
229
+ success: boolean;
230
+ message: string;
231
+ }>>;
232
+ /**
233
+ * Get goals for a milestone
234
+ */
235
+ goals: (id: string) => Promise<ApiResult<Goal[]>>;
236
+ };
237
+ /**
238
+ * Goals namespace with Result-wrapped operations
239
+ */
240
+ readonly goals: {
241
+ /**
242
+ * List goals for authenticated user
243
+ */
244
+ list: () => Promise<ApiResult<Goal[]>>;
245
+ /**
246
+ * Get goal by ID
247
+ */
248
+ find: (id: string) => Promise<ApiResult<Goal | null>>;
249
+ /**
250
+ * Create new goal
251
+ */
252
+ create: (data: {
253
+ milestone_id: string;
254
+ name: string;
255
+ description?: string;
256
+ target_time?: string;
257
+ }) => Promise<ApiResult<Goal>>;
258
+ /**
259
+ * Update goal
260
+ */
261
+ update: (id: string, data: {
262
+ name?: string;
263
+ description?: string;
264
+ target_time?: string;
265
+ }) => Promise<ApiResult<Goal>>;
266
+ /**
267
+ * Delete goal (soft delete)
268
+ */
269
+ delete: (id: string) => Promise<ApiResult<{
270
+ success: boolean;
271
+ message: string;
272
+ }>>;
273
+ };
274
+ /**
275
+ * Tasks namespace with Result-wrapped operations
276
+ */
277
+ readonly tasks: {
278
+ /**
279
+ * List tasks with optional filtering
280
+ */
281
+ list: (filters?: {
282
+ project_id?: string;
283
+ tag_id?: string;
284
+ }) => Promise<ApiResult<TaskWithDetails[]>>;
285
+ /**
286
+ * Get task by ID
287
+ */
288
+ find: (id: string) => Promise<ApiResult<TaskWithDetails | null>>;
289
+ /**
290
+ * Get tasks by project ID
291
+ */
292
+ getByProject: (project_id: string) => Promise<ApiResult<TaskWithDetails[]>>;
293
+ /**
294
+ * Create a new task
295
+ */
296
+ create: (data: Omit<UpsertTodo, "id"> & {
297
+ tags?: UpsertTag[];
298
+ }) => Promise<ApiResult<TaskWithDetails>>;
299
+ /**
300
+ * Update an existing task
301
+ */
302
+ update: (id: string, changes: Partial<Omit<UpsertTodo, "id">> & {
303
+ tags?: UpsertTag[];
304
+ }) => Promise<ApiResult<TaskWithDetails>>;
305
+ /**
306
+ * Upsert task (create or update)
307
+ */
308
+ upsert: (data: UpsertTodo & {
309
+ tags?: UpsertTag[];
310
+ }) => Promise<ApiResult<TaskWithDetails>>;
311
+ /**
312
+ * Save tags for tasks
313
+ */
314
+ saveTags: (data: any) => Promise<ApiResult<void>>;
315
+ /**
316
+ * Delete task (soft delete)
317
+ */
318
+ deleteTask: (task: TaskWithDetails) => Promise<ApiResult<void>>;
319
+ /**
320
+ * Task history operations
321
+ */
322
+ history: {
323
+ /**
324
+ * Get task history by task ID
325
+ */
326
+ get: (task_id: string) => Promise<ApiResult<HistoryAction[]>>;
327
+ };
328
+ };
329
+ /**
330
+ * Tags namespace with Result-wrapped operations
331
+ */
332
+ readonly tags: {
333
+ /**
334
+ * List tags for authenticated user
335
+ */
336
+ list: () => Promise<ApiResult<TagWithTypedColor[]>>;
337
+ };
338
+ /**
339
+ * GitHub namespace with Result-wrapped operations
340
+ */
341
+ readonly github: {
342
+ /**
343
+ * List repositories for authenticated user
344
+ */
345
+ repos: () => Promise<ApiResult<any[]>>;
346
+ /**
347
+ * List branches for a GitHub repository
348
+ */
349
+ branches: (owner: string, repo: string) => Promise<ApiResult<any[]>>;
350
+ };
351
+ readonly blog: {
352
+ posts: {
353
+ list: (params?: Partial<PostListParams>) => Promise<ApiResult<PostsResponse>>;
354
+ getBySlug: (slug: string) => Promise<ApiResult<Post>>;
355
+ create: (data: PostCreate) => Promise<ApiResult<Post>>;
356
+ update: (uuid: string, data: PostUpdate) => Promise<ApiResult<Post>>;
357
+ delete: (uuid: string) => Promise<ApiResult<{
358
+ success: boolean;
359
+ }>>;
360
+ versions: (uuid: string) => Promise<ApiResult<{
361
+ versions: VersionInfo[];
362
+ }>>;
363
+ version: (uuid: string, hash: string) => Promise<ApiResult<PostContent>>;
364
+ restore: (uuid: string, hash: string) => Promise<ApiResult<Post>>;
365
+ };
366
+ tags: {
367
+ list: () => Promise<ApiResult<{
368
+ tags: TagWithCount[];
369
+ }>>;
370
+ getForPost: (uuid: string) => Promise<ApiResult<{
371
+ tags: string[];
372
+ }>>;
373
+ setForPost: (uuid: string, tags: string[]) => Promise<ApiResult<{
374
+ tags: string[];
375
+ }>>;
376
+ addToPost: (uuid: string, tags: string[]) => Promise<ApiResult<{
377
+ tags: string[];
378
+ }>>;
379
+ removeFromPost: (uuid: string, tag: string) => Promise<ApiResult<void>>;
380
+ };
381
+ categories: {
382
+ tree: () => Promise<ApiResult<{
383
+ categories: Category[];
384
+ }>>;
385
+ create: (data: CategoryCreate) => Promise<ApiResult<Category>>;
386
+ update: (name: string, data: {
387
+ name: string;
388
+ }) => Promise<ApiResult<Category>>;
389
+ delete: (name: string) => Promise<ApiResult<void>>;
390
+ };
391
+ tokens: {
392
+ list: () => Promise<ApiResult<{
393
+ tokens: SanitizedToken[];
394
+ }>>;
395
+ create: (data: AccessKeyCreate) => Promise<ApiResult<CreatedToken>>;
396
+ update: (id: string, data: AccessKeyUpdate) => Promise<ApiResult<AccessKey>>;
397
+ delete: (id: string) => Promise<ApiResult<void>>;
398
+ };
399
+ };
400
+ readonly media: {
401
+ profiles: {
402
+ list: () => Promise<ApiResult<Profile[]>>;
403
+ create: (data: CreateProfileInput) => Promise<ApiResult<Profile>>;
404
+ get: (id: string) => Promise<ApiResult<Profile>>;
405
+ update: (id: string, data: UpdateProfileInput) => Promise<ApiResult<Profile>>;
406
+ delete: (id: string) => Promise<ApiResult<{
407
+ success: boolean;
408
+ }>>;
409
+ filters: {
410
+ list: (profile_id: string) => Promise<ApiResult<ProfileFilter[]>>;
411
+ add: (profile_id: string, data: AddFilterInput) => Promise<ApiResult<ProfileFilter>>;
412
+ remove: (profile_id: string, filter_id: string) => Promise<ApiResult<void>>;
413
+ };
414
+ timeline: (slug: string, params?: {
415
+ limit?: number;
416
+ before?: string;
417
+ }) => Promise<ApiResult<Timeline>>;
418
+ };
419
+ connections: {
420
+ list: (profile_id: string, options?: {
421
+ include_settings?: boolean;
422
+ }) => Promise<ApiResult<Account[]>>;
423
+ create: (data: {
424
+ profile_id: string;
425
+ platform: string;
426
+ access_token: string;
427
+ refresh_token?: string;
428
+ platform_user_id?: string;
429
+ platform_username?: string;
430
+ token_expires_at?: string;
431
+ }) => Promise<ApiResult<Account>>;
432
+ delete: (account_id: string) => Promise<ApiResult<{
433
+ success: boolean;
434
+ }>>;
435
+ refresh: (account_id: string) => Promise<ApiResult<any>>;
436
+ refreshAll: () => Promise<ApiResult<any>>;
437
+ updateStatus: (account_id: string, is_active: boolean) => Promise<ApiResult<Account>>;
438
+ settings: {
439
+ get: (account_id: string) => Promise<ApiResult<PlatformSettings>>;
440
+ update: (account_id: string, settings: Record<string, unknown>) => Promise<ApiResult<any>>;
441
+ };
442
+ repos: (account_id: string) => Promise<ApiResult<any[]>>;
443
+ subreddits: (account_id: string) => Promise<ApiResult<any[]>>;
444
+ };
445
+ credentials: {
446
+ check: (platform: string, profile_id: string) => Promise<ApiResult<{
447
+ exists: boolean;
448
+ isVerified: boolean;
449
+ clientId: string | null;
450
+ }>>;
451
+ save: (platform: string, data: {
452
+ profile_id: string;
453
+ client_id: string;
454
+ client_secret: string;
455
+ redirect_uri?: string;
456
+ reddit_username?: string;
457
+ }) => Promise<ApiResult<{
458
+ success: boolean;
459
+ id: string;
460
+ }>>;
461
+ delete: (platform: string, profile_id: string) => Promise<ApiResult<{
462
+ success: boolean;
463
+ }>>;
464
+ };
465
+ timeline: {
466
+ get: (user_id: string, params?: {
467
+ from?: string;
468
+ to?: string;
469
+ }) => Promise<ApiResult<Timeline>>;
470
+ getRaw: (user_id: string, platform: string, account_id: string) => Promise<ApiResult<any>>;
471
+ };
472
+ };
473
+ /**
474
+ * User namespace with Result-wrapped operations
475
+ */
476
+ readonly user: {
477
+ /**
478
+ * Get user activity history
479
+ */
480
+ history: () => Promise<ApiResult<any[]>>;
481
+ /**
482
+ * Update user preferences
483
+ */
484
+ preferences: (data: {
485
+ id: string;
486
+ task_view: string;
487
+ }) => Promise<ApiResult<any>>;
488
+ };
489
+ /**
490
+ * Get request history for debugging
491
+ */
492
+ history(): BufferedQueue<RequestHistoryEntry>;
493
+ /**
494
+ * Get the API key
495
+ */
496
+ getApiKey(): string;
497
+ /**
498
+ * Get the authentication mode
499
+ */
500
+ getAuthMode(): AuthMode;
501
+ }
502
+
503
+ declare class ApiError extends Error {
504
+ readonly code?: string;
505
+ readonly statusCode?: number;
506
+ constructor(message: string, options?: {
507
+ code?: string;
508
+ statusCode?: number;
509
+ });
510
+ static fromResponse(response: Response): ApiError;
511
+ }
512
+ declare class AuthenticationError extends ApiError {
513
+ constructor(message?: string);
514
+ }
515
+ declare class NetworkError extends ApiError {
516
+ constructor(message?: string);
517
+ }
518
+ declare class ValidationError extends ApiError {
519
+ constructor(message?: string);
520
+ }
521
+
522
+ /**
523
+ * Parse Zod validation errors into user-friendly messages
524
+ */
525
+ declare function parseZodErrors(errorMessage: string): string;
526
+ /**
527
+ * Get user-friendly error message from any error
528
+ */
529
+ declare function getUserFriendlyErrorMessage(error: unknown): string;
530
+
531
+ interface ToolDefinition<TInput = any, TOutput = any> {
532
+ name: string;
533
+ description: string;
534
+ inputSchema: z.ZodType<TInput>;
535
+ execute: (client: ApiClient, input: TInput) => Promise<TOutput>;
536
+ }
537
+ declare const tools: Record<string, ToolDefinition>;
538
+ declare const toolNames: string[];
539
+ declare function getTool(name: string): ToolDefinition | undefined;
540
+
541
+ export { AccessKey, Account, AddFilterInput, ApiClient, ApiError, type ApiResult, type ApiResultError, type AuthMode, AuthenticationError, Category, CategoryCreate, CreateProfileInput, NetworkError, PlatformSettings, Post, PostContent, PostCreate, PostListParams, PostUpdate, PostsResponse, Profile, ProfileFilter, Project, type RequestHistoryEntry, type RequestOptions, SaveConfigRequest, TaskWithDetails, Timeline, type ToolDefinition, UpdateProfileInput, UpsertProject, UpsertTag, UpsertTodo, ValidationError, VersionInfo, ApiClient as default, getTool, getUserFriendlyErrorMessage, parseZodErrors, toolNames, tools, wrap };