@plandesk/api 0.8.0 → 0.10.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/dist/events.d.ts +12 -3
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3 -1
- package/dist/routes/agent-runs.d.ts +1 -1
- package/dist/routes/agent-runs.js +20 -0
- package/dist/routes/comments.js +39 -31
- package/dist/routes/goals.d.ts +4 -0
- package/dist/routes/goals.js +138 -0
- package/dist/routes/projects.d.ts +1 -1
- package/dist/routes/projects.js +12 -1
- package/dist/routes/submissions.d.ts +5 -0
- package/dist/routes/submissions.js +58 -0
- package/dist/serialize.d.ts +26 -3
- package/dist/serialize.js +38 -1
- package/dist/server.js +5 -1
- package/dist/services/canvas.d.ts +2 -0
- package/dist/services/canvas.js +2 -1
- package/dist/services/comments.d.ts +10 -2
- package/dist/services/comments.js +71 -34
- package/dist/services/documents.js +2 -2
- package/dist/services/goals.d.ts +239 -0
- package/dist/services/goals.js +323 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.js +3 -0
- package/dist/services/notes.js +2 -1
- package/dist/services/projects.js +4 -1
- package/dist/services/sync.d.ts +5 -3
- package/dist/services/sync.js +45 -2
- package/dist/services/tasks.d.ts +10 -1
- package/dist/services/tasks.js +34 -5
- package/package.json +2 -2
- package/web/assets/index-DMKmd5gS.js +318 -0
- package/web/assets/index-DcD7-VGi.css +1 -0
- package/web/index.html +2 -2
- package/web/assets/index-CUxSE_WZ.css +0 -1
- package/web/assets/index-DSmNB4RA.js +0 -235
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createComment, deleteComment as dbDeleteComment, getComment as dbGetComment, getDocument as dbGetDocument, getNote as dbGetNote, getProject, getSubmission, getTask, listCommentsByProject as dbListCommentsByProject, listCommentsByTarget as dbListCommentsByTarget, updateComment as dbUpdateComment, } from '@plandesk/db';
|
|
2
2
|
import { serializeComment } from '../serialize.js';
|
|
3
3
|
export class InvalidCommentError extends Error {
|
|
4
4
|
constructor(message) {
|
|
@@ -11,34 +11,69 @@ function assertNonEmptyBody(body) {
|
|
|
11
11
|
throw new InvalidCommentError('Comment body must not be empty');
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
+
function targetProjectId(db, target) {
|
|
15
|
+
switch (target.type) {
|
|
16
|
+
case 'document':
|
|
17
|
+
return dbGetDocument(db, target.id)?.projectId;
|
|
18
|
+
case 'task':
|
|
19
|
+
return getTask(db, target.id)?.projectId;
|
|
20
|
+
case 'note':
|
|
21
|
+
return dbGetNote(db, target.id)?.projectId;
|
|
22
|
+
case 'submission':
|
|
23
|
+
return getSubmission(db, target.id)?.projectId;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function emitCommentCreated(eventBus, commentId, projectId, target) {
|
|
27
|
+
eventBus.emit({
|
|
28
|
+
type: 'comment_created',
|
|
29
|
+
commentId,
|
|
30
|
+
projectId,
|
|
31
|
+
target_type: target.type,
|
|
32
|
+
target_id: target.id,
|
|
33
|
+
...(target.type === 'document' ? { documentId: target.id } : {}),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function emitCommentUpdated(eventBus, commentId, projectId, target) {
|
|
37
|
+
eventBus.emit({
|
|
38
|
+
type: 'comment_updated',
|
|
39
|
+
commentId,
|
|
40
|
+
projectId,
|
|
41
|
+
target_type: target.type,
|
|
42
|
+
target_id: target.id,
|
|
43
|
+
...(target.type === 'document' ? { documentId: target.id } : {}),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
14
46
|
export function createCommentService(deps) {
|
|
15
47
|
const { db, eventBus } = deps;
|
|
16
48
|
return {
|
|
17
|
-
create(
|
|
18
|
-
const
|
|
19
|
-
if (!
|
|
49
|
+
create(target, input) {
|
|
50
|
+
const projectId = targetProjectId(db, target);
|
|
51
|
+
if (!projectId) {
|
|
20
52
|
return undefined;
|
|
21
53
|
}
|
|
22
54
|
assertNonEmptyBody(input.body);
|
|
23
|
-
const comment =
|
|
24
|
-
|
|
55
|
+
const comment = createComment(db, {
|
|
56
|
+
projectId,
|
|
57
|
+
targetType: target.type,
|
|
58
|
+
targetId: target.id,
|
|
25
59
|
body: input.body,
|
|
26
60
|
passage: input.passage,
|
|
27
61
|
});
|
|
28
|
-
eventBus.
|
|
29
|
-
type: 'comment_created',
|
|
30
|
-
commentId: comment.id,
|
|
31
|
-
documentId,
|
|
32
|
-
projectId: document.projectId,
|
|
33
|
-
});
|
|
62
|
+
emitCommentCreated(eventBus, comment.id, projectId, target);
|
|
34
63
|
return serializeComment(comment);
|
|
35
64
|
},
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
if (!
|
|
65
|
+
listByTarget(target, options) {
|
|
66
|
+
const projectId = targetProjectId(db, target);
|
|
67
|
+
if (!projectId) {
|
|
39
68
|
return undefined;
|
|
40
69
|
}
|
|
41
|
-
return
|
|
70
|
+
return dbListCommentsByTarget(db, target.type, target.id, options).map(serializeComment);
|
|
71
|
+
},
|
|
72
|
+
resolveTargetProjectId(target) {
|
|
73
|
+
return targetProjectId(db, target);
|
|
74
|
+
},
|
|
75
|
+
listByDocument(documentId, options) {
|
|
76
|
+
return this.listByTarget({ type: 'document', id: documentId }, options);
|
|
42
77
|
},
|
|
43
78
|
listByProject(projectId, options) {
|
|
44
79
|
const project = getProject(db, projectId);
|
|
@@ -48,47 +83,49 @@ export function createCommentService(deps) {
|
|
|
48
83
|
return dbListCommentsByProject(db, projectId, options).map(serializeComment);
|
|
49
84
|
},
|
|
50
85
|
update(id, input) {
|
|
51
|
-
const existing =
|
|
86
|
+
const existing = dbGetComment(db, id);
|
|
52
87
|
if (!existing) {
|
|
53
88
|
return undefined;
|
|
54
89
|
}
|
|
55
90
|
if (input.body !== undefined) {
|
|
56
91
|
assertNonEmptyBody(input.body);
|
|
57
92
|
}
|
|
58
|
-
const comment =
|
|
93
|
+
const comment = dbUpdateComment(db, id, input);
|
|
59
94
|
if (!comment) {
|
|
60
95
|
return undefined;
|
|
61
96
|
}
|
|
62
|
-
const
|
|
63
|
-
|
|
97
|
+
const projectId = targetProjectId(db, {
|
|
98
|
+
type: comment.targetType,
|
|
99
|
+
id: comment.targetId,
|
|
100
|
+
});
|
|
101
|
+
if (!projectId) {
|
|
64
102
|
return undefined;
|
|
65
103
|
}
|
|
66
|
-
eventBus
|
|
67
|
-
type:
|
|
68
|
-
|
|
69
|
-
documentId: comment.documentId,
|
|
70
|
-
projectId: document.projectId,
|
|
104
|
+
emitCommentUpdated(eventBus, id, projectId, {
|
|
105
|
+
type: comment.targetType,
|
|
106
|
+
id: comment.targetId,
|
|
71
107
|
});
|
|
72
108
|
return serializeComment(comment);
|
|
73
109
|
},
|
|
74
110
|
delete(id) {
|
|
75
|
-
const existing =
|
|
111
|
+
const existing = dbGetComment(db, id);
|
|
76
112
|
if (!existing) {
|
|
77
113
|
return false;
|
|
78
114
|
}
|
|
79
|
-
const
|
|
80
|
-
|
|
115
|
+
const projectId = targetProjectId(db, {
|
|
116
|
+
type: existing.targetType,
|
|
117
|
+
id: existing.targetId,
|
|
118
|
+
});
|
|
119
|
+
if (!projectId) {
|
|
81
120
|
return false;
|
|
82
121
|
}
|
|
83
|
-
const deleted =
|
|
122
|
+
const deleted = dbDeleteComment(db, id);
|
|
84
123
|
if (!deleted) {
|
|
85
124
|
return false;
|
|
86
125
|
}
|
|
87
|
-
eventBus
|
|
88
|
-
type:
|
|
89
|
-
|
|
90
|
-
documentId: existing.documentId,
|
|
91
|
-
projectId: document.projectId,
|
|
126
|
+
emitCommentUpdated(eventBus, id, projectId, {
|
|
127
|
+
type: existing.targetType,
|
|
128
|
+
id: existing.targetId,
|
|
92
129
|
});
|
|
93
130
|
return true;
|
|
94
131
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createDocument as dbCreateDocument,
|
|
1
|
+
import { createDocument as dbCreateDocument, deleteCommentsByTarget, deleteDocument as dbDeleteDocument, detachDocumentChildren, getDocument as dbGetDocument, getDocumentByTask as dbGetDocumentByTask, getFolderByProjectAndId, getProject, getTask, listDocuments as dbListDocuments, listFolders as dbListFolders, updateDocument as dbUpdateDocument, } from '@plandesk/db';
|
|
2
2
|
import { buildDocumentTree, buildFolderTree, serializeDocument, } from '../serialize.js';
|
|
3
3
|
export class InvalidDocumentError extends Error {
|
|
4
4
|
constructor(message) {
|
|
@@ -128,7 +128,7 @@ export function createDocumentService(deps) {
|
|
|
128
128
|
}
|
|
129
129
|
db.transaction((tx) => {
|
|
130
130
|
detachDocumentChildren(tx, id);
|
|
131
|
-
|
|
131
|
+
deleteCommentsByTarget(tx, 'document', id);
|
|
132
132
|
dbDeleteDocument(tx, id);
|
|
133
133
|
});
|
|
134
134
|
eventBus.emit({ type: 'canvas_updated', projectId: existing.projectId });
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { type Db, type GoalStatus } from '@plandesk/db';
|
|
2
|
+
import type { EventBus } from '../events.js';
|
|
3
|
+
export type GoalServiceDeps = {
|
|
4
|
+
db: Db;
|
|
5
|
+
eventBus: EventBus;
|
|
6
|
+
};
|
|
7
|
+
export declare class InvalidGoalTransitionError extends Error {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class GoalCompletionBlockedError extends Error {
|
|
11
|
+
incompleteTaskIds: string[];
|
|
12
|
+
constructor(incompleteTaskIds: string[]);
|
|
13
|
+
}
|
|
14
|
+
export declare class InvalidVerificationSurfaceError extends Error {
|
|
15
|
+
constructor(message: string);
|
|
16
|
+
}
|
|
17
|
+
export declare class GoalVerificationRequiredError extends Error {
|
|
18
|
+
requiredKind: VerificationSurfaceKind;
|
|
19
|
+
constructor(requiredKind: VerificationSurfaceKind);
|
|
20
|
+
}
|
|
21
|
+
export type VerificationSurfaceKind = 'gate_command' | 'acceptance_checklist' | 'human_sign_off';
|
|
22
|
+
export type GateCommandSurface = {
|
|
23
|
+
kind: 'gate_command';
|
|
24
|
+
command: string;
|
|
25
|
+
};
|
|
26
|
+
export type AcceptanceChecklistSurface = {
|
|
27
|
+
kind: 'acceptance_checklist';
|
|
28
|
+
items: Array<{
|
|
29
|
+
criterion: string;
|
|
30
|
+
}>;
|
|
31
|
+
};
|
|
32
|
+
export type HumanSignOffSurface = {
|
|
33
|
+
kind: 'human_sign_off';
|
|
34
|
+
};
|
|
35
|
+
export type VerificationSurface = GateCommandSurface | AcceptanceChecklistSurface | HumanSignOffSurface;
|
|
36
|
+
export type GateCommandEvidence = {
|
|
37
|
+
kind: 'gate_command';
|
|
38
|
+
exit_code: number;
|
|
39
|
+
command?: string;
|
|
40
|
+
detail?: string;
|
|
41
|
+
};
|
|
42
|
+
export type AcceptanceChecklistEvidence = {
|
|
43
|
+
kind: 'acceptance_checklist';
|
|
44
|
+
checked: string[];
|
|
45
|
+
};
|
|
46
|
+
export type HumanSignOffEvidence = {
|
|
47
|
+
kind: 'human_sign_off';
|
|
48
|
+
approved_by: string;
|
|
49
|
+
};
|
|
50
|
+
export type VerificationEvidence = GateCommandEvidence | AcceptanceChecklistEvidence | HumanSignOffEvidence;
|
|
51
|
+
export type LastVerificationRecord = {
|
|
52
|
+
at: string;
|
|
53
|
+
green: boolean;
|
|
54
|
+
kind: VerificationSurfaceKind | null;
|
|
55
|
+
detail?: string;
|
|
56
|
+
};
|
|
57
|
+
export type CreateGoalInput = {
|
|
58
|
+
objective: string;
|
|
59
|
+
verificationSurface?: string | null;
|
|
60
|
+
constraints?: string | null;
|
|
61
|
+
boundaries?: string | null;
|
|
62
|
+
iterationPolicy?: string | null;
|
|
63
|
+
stopCondition?: string | null;
|
|
64
|
+
budget?: string | null;
|
|
65
|
+
status?: GoalStatus;
|
|
66
|
+
};
|
|
67
|
+
export type UpdateGoalInput = {
|
|
68
|
+
objective?: string;
|
|
69
|
+
verificationSurface?: string | null;
|
|
70
|
+
constraints?: string | null;
|
|
71
|
+
boundaries?: string | null;
|
|
72
|
+
iterationPolicy?: string | null;
|
|
73
|
+
stopCondition?: string | null;
|
|
74
|
+
budget?: string | null;
|
|
75
|
+
};
|
|
76
|
+
export declare function parseVerificationSurface(raw: string | null): VerificationSurface | null;
|
|
77
|
+
export declare function evaluateEvidence(surface: VerificationSurface, evidence: VerificationEvidence): {
|
|
78
|
+
green: boolean;
|
|
79
|
+
detail?: string;
|
|
80
|
+
};
|
|
81
|
+
export declare function createGoalService(deps: GoalServiceDeps): {
|
|
82
|
+
create(projectId: string, input: CreateGoalInput): {
|
|
83
|
+
id: string;
|
|
84
|
+
project_id: string;
|
|
85
|
+
objective: string;
|
|
86
|
+
status: "active" | "paused" | "complete" | "blocked";
|
|
87
|
+
verification_surface: string | null;
|
|
88
|
+
constraints: string | null;
|
|
89
|
+
boundaries: string | null;
|
|
90
|
+
iteration_policy: string | null;
|
|
91
|
+
stop_condition: string | null;
|
|
92
|
+
budget: string | null;
|
|
93
|
+
last_verification: {
|
|
94
|
+
at: string;
|
|
95
|
+
green: boolean;
|
|
96
|
+
kind: string | null;
|
|
97
|
+
detail?: string;
|
|
98
|
+
} | null;
|
|
99
|
+
created_at: string;
|
|
100
|
+
updated_at: string;
|
|
101
|
+
} | undefined;
|
|
102
|
+
get(goalId: string): {
|
|
103
|
+
cycle_tasks: {
|
|
104
|
+
tags?: import("../serialize.js").SerializedTag[] | undefined;
|
|
105
|
+
id: string;
|
|
106
|
+
project_id: string;
|
|
107
|
+
goal_id: string;
|
|
108
|
+
label: string;
|
|
109
|
+
status: "scope" | "todo" | "in_progress" | "done" | "backlog";
|
|
110
|
+
description: string | null;
|
|
111
|
+
x: number;
|
|
112
|
+
y: number;
|
|
113
|
+
assignee: string | null;
|
|
114
|
+
due_date: string | null;
|
|
115
|
+
created_at: string;
|
|
116
|
+
updated_at: string;
|
|
117
|
+
}[];
|
|
118
|
+
id: string;
|
|
119
|
+
project_id: string;
|
|
120
|
+
objective: string;
|
|
121
|
+
status: "active" | "paused" | "complete" | "blocked";
|
|
122
|
+
verification_surface: string | null;
|
|
123
|
+
constraints: string | null;
|
|
124
|
+
boundaries: string | null;
|
|
125
|
+
iteration_policy: string | null;
|
|
126
|
+
stop_condition: string | null;
|
|
127
|
+
budget: string | null;
|
|
128
|
+
last_verification: {
|
|
129
|
+
at: string;
|
|
130
|
+
green: boolean;
|
|
131
|
+
kind: string | null;
|
|
132
|
+
detail?: string;
|
|
133
|
+
} | null;
|
|
134
|
+
created_at: string;
|
|
135
|
+
updated_at: string;
|
|
136
|
+
} | undefined;
|
|
137
|
+
listByProject(projectId: string): {
|
|
138
|
+
id: string;
|
|
139
|
+
project_id: string;
|
|
140
|
+
objective: string;
|
|
141
|
+
status: "active" | "paused" | "complete" | "blocked";
|
|
142
|
+
verification_surface: string | null;
|
|
143
|
+
constraints: string | null;
|
|
144
|
+
boundaries: string | null;
|
|
145
|
+
iteration_policy: string | null;
|
|
146
|
+
stop_condition: string | null;
|
|
147
|
+
budget: string | null;
|
|
148
|
+
last_verification: {
|
|
149
|
+
at: string;
|
|
150
|
+
green: boolean;
|
|
151
|
+
kind: string | null;
|
|
152
|
+
detail?: string;
|
|
153
|
+
} | null;
|
|
154
|
+
created_at: string;
|
|
155
|
+
updated_at: string;
|
|
156
|
+
}[] | undefined;
|
|
157
|
+
update(goalId: string, input: UpdateGoalInput): {
|
|
158
|
+
id: string;
|
|
159
|
+
project_id: string;
|
|
160
|
+
objective: string;
|
|
161
|
+
status: "active" | "paused" | "complete" | "blocked";
|
|
162
|
+
verification_surface: string | null;
|
|
163
|
+
constraints: string | null;
|
|
164
|
+
boundaries: string | null;
|
|
165
|
+
iteration_policy: string | null;
|
|
166
|
+
stop_condition: string | null;
|
|
167
|
+
budget: string | null;
|
|
168
|
+
last_verification: {
|
|
169
|
+
at: string;
|
|
170
|
+
green: boolean;
|
|
171
|
+
kind: string | null;
|
|
172
|
+
detail?: string;
|
|
173
|
+
} | null;
|
|
174
|
+
created_at: string;
|
|
175
|
+
updated_at: string;
|
|
176
|
+
} | undefined;
|
|
177
|
+
pause(goalId: string): {
|
|
178
|
+
id: string;
|
|
179
|
+
project_id: string;
|
|
180
|
+
objective: string;
|
|
181
|
+
status: "active" | "paused" | "complete" | "blocked";
|
|
182
|
+
verification_surface: string | null;
|
|
183
|
+
constraints: string | null;
|
|
184
|
+
boundaries: string | null;
|
|
185
|
+
iteration_policy: string | null;
|
|
186
|
+
stop_condition: string | null;
|
|
187
|
+
budget: string | null;
|
|
188
|
+
last_verification: {
|
|
189
|
+
at: string;
|
|
190
|
+
green: boolean;
|
|
191
|
+
kind: string | null;
|
|
192
|
+
detail?: string;
|
|
193
|
+
} | null;
|
|
194
|
+
created_at: string;
|
|
195
|
+
updated_at: string;
|
|
196
|
+
} | undefined;
|
|
197
|
+
resume(goalId: string): {
|
|
198
|
+
id: string;
|
|
199
|
+
project_id: string;
|
|
200
|
+
objective: string;
|
|
201
|
+
status: "active" | "paused" | "complete" | "blocked";
|
|
202
|
+
verification_surface: string | null;
|
|
203
|
+
constraints: string | null;
|
|
204
|
+
boundaries: string | null;
|
|
205
|
+
iteration_policy: string | null;
|
|
206
|
+
stop_condition: string | null;
|
|
207
|
+
budget: string | null;
|
|
208
|
+
last_verification: {
|
|
209
|
+
at: string;
|
|
210
|
+
green: boolean;
|
|
211
|
+
kind: string | null;
|
|
212
|
+
detail?: string;
|
|
213
|
+
} | null;
|
|
214
|
+
created_at: string;
|
|
215
|
+
updated_at: string;
|
|
216
|
+
} | undefined;
|
|
217
|
+
complete(goalId: string, evidence?: VerificationEvidence): {
|
|
218
|
+
id: string;
|
|
219
|
+
project_id: string;
|
|
220
|
+
objective: string;
|
|
221
|
+
status: "active" | "paused" | "complete" | "blocked";
|
|
222
|
+
verification_surface: string | null;
|
|
223
|
+
constraints: string | null;
|
|
224
|
+
boundaries: string | null;
|
|
225
|
+
iteration_policy: string | null;
|
|
226
|
+
stop_condition: string | null;
|
|
227
|
+
budget: string | null;
|
|
228
|
+
last_verification: {
|
|
229
|
+
at: string;
|
|
230
|
+
green: boolean;
|
|
231
|
+
kind: string | null;
|
|
232
|
+
detail?: string;
|
|
233
|
+
} | null;
|
|
234
|
+
created_at: string;
|
|
235
|
+
updated_at: string;
|
|
236
|
+
} | undefined;
|
|
237
|
+
};
|
|
238
|
+
export type GoalService = ReturnType<typeof createGoalService>;
|
|
239
|
+
//# sourceMappingURL=goals.d.ts.map
|