context-drop 0.2.0 → 0.3.1
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 +6 -5
- package/app/assets/javascripts/context_drop/context_drop.js +1589 -99
- package/dist/app/javascript/context_drop/api-client.d.ts +14 -1
- package/dist/app/javascript/context_drop/api-client.js +217 -1
- package/dist/app/javascript/context_drop/icons.d.ts +3 -0
- package/dist/app/javascript/context_drop/icons.js +3 -0
- package/dist/app/javascript/context_drop/styles.d.ts +1 -1
- package/dist/app/javascript/context_drop/styles.js +311 -0
- package/dist/app/javascript/context_drop/types.d.ts +124 -6
- package/dist/app/javascript/context_drop/widget.d.ts +23 -0
- package/dist/app/javascript/context_drop/widget.js +847 -31
- package/dist/src/cli.js +1 -1
- package/dist/src/mcp/dispatcher.js +65 -12
- package/dist/src/next/index.d.ts +1 -1
- package/dist/src/react/index.d.ts +16 -2
- package/dist/src/react/index.js +21 -1
- package/dist/src/server/handler.d.ts +7 -1
- package/dist/src/server/handler.js +710 -81
- package/dist/src/server/storage/local.d.ts +1 -1
- package/dist/src/server/storage/local.js +434 -10
- package/dist/src/server/storage/memory.d.ts +4 -1
- package/dist/src/server/storage/memory.js +241 -3
- package/dist/src/server/storage/postgres.d.ts +1 -1
- package/dist/src/server/storage/postgres.js +303 -10
- package/dist/src/server/types.d.ts +65 -2
- package/dist/src/server/types.js +3 -2
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import crypto from "node:crypto";
|
|
2
|
-
import { toFeedbackSummary } from "./memory.js";
|
|
2
|
+
import { hasAuthenticatedSubmitter, toFeedbackSummary } from "./memory.js";
|
|
3
3
|
function resolvePgSecret(explicit) {
|
|
4
4
|
const raw = explicit ||
|
|
5
5
|
process.env.CONTEXT_DROP_SECRET ||
|
|
@@ -92,8 +92,13 @@ export function createPostgresStorageAdapter(options) {
|
|
|
92
92
|
submitter JSONB NOT NULL DEFAULT '{}'::jsonb,
|
|
93
93
|
metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
|
|
94
94
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
95
|
-
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
95
|
+
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
96
|
+
deleted_at TIMESTAMPTZ
|
|
96
97
|
);
|
|
98
|
+
`);
|
|
99
|
+
await pool.query(`
|
|
100
|
+
ALTER TABLE context_drop_feedbacks
|
|
101
|
+
ADD COLUMN IF NOT EXISTS deleted_at TIMESTAMPTZ;
|
|
97
102
|
`);
|
|
98
103
|
await pool.query(`
|
|
99
104
|
CREATE INDEX IF NOT EXISTS idx_context_drop_feedbacks_env_status
|
|
@@ -114,11 +119,23 @@ export function createPostgresStorageAdapter(options) {
|
|
|
114
119
|
metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
|
|
115
120
|
captured_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
116
121
|
);
|
|
122
|
+
`);
|
|
123
|
+
await pool.query(`
|
|
124
|
+
CREATE TABLE IF NOT EXISTS context_drop_comments (
|
|
125
|
+
id BIGSERIAL PRIMARY KEY,
|
|
126
|
+
feedback_id BIGINT NOT NULL REFERENCES context_drop_feedbacks(id) ON DELETE CASCADE,
|
|
127
|
+
author_type TEXT,
|
|
128
|
+
author_label TEXT,
|
|
129
|
+
body TEXT,
|
|
130
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
131
|
+
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
132
|
+
);
|
|
117
133
|
`);
|
|
118
134
|
await pool.query(`
|
|
119
135
|
CREATE TABLE IF NOT EXISTS context_drop_attachments (
|
|
120
136
|
id BIGSERIAL PRIMARY KEY,
|
|
121
137
|
feedback_id BIGINT NOT NULL REFERENCES context_drop_feedbacks(id) ON DELETE CASCADE,
|
|
138
|
+
comment_id BIGINT REFERENCES context_drop_comments(id) ON DELETE CASCADE,
|
|
122
139
|
element_reference_id BIGINT REFERENCES context_drop_element_references(id) ON DELETE SET NULL,
|
|
123
140
|
attachment_type TEXT NOT NULL,
|
|
124
141
|
filename TEXT,
|
|
@@ -129,6 +146,13 @@ export function createPostgresStorageAdapter(options) {
|
|
|
129
146
|
metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
|
|
130
147
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
131
148
|
);
|
|
149
|
+
`);
|
|
150
|
+
await pool.query(`
|
|
151
|
+
ALTER TABLE context_drop_attachments
|
|
152
|
+
ADD COLUMN IF NOT EXISTS comment_id BIGINT REFERENCES context_drop_comments(id) ON DELETE CASCADE;
|
|
153
|
+
`);
|
|
154
|
+
await pool.query(`
|
|
155
|
+
UPDATE context_drop_feedbacks SET status = 'fixed' WHERE status = 'resolved';
|
|
132
156
|
`);
|
|
133
157
|
})();
|
|
134
158
|
}
|
|
@@ -136,16 +160,20 @@ export function createPostgresStorageAdapter(options) {
|
|
|
136
160
|
}
|
|
137
161
|
async function hydrateFeedbackRow(row) {
|
|
138
162
|
const fbId = Number(row["id"]);
|
|
139
|
-
const [elRes, attRes] = await Promise.all([
|
|
163
|
+
const [elRes, attRes, commentRes] = await Promise.all([
|
|
140
164
|
pool.query(`SELECT id, feedback_id, client_ref, tag_name, selector, dom_path, text_content,
|
|
141
165
|
attributes_snapshot, bounding_rect, viewport, metadata, captured_at
|
|
142
166
|
FROM context_drop_element_references
|
|
143
167
|
WHERE feedback_id = $1
|
|
144
168
|
ORDER BY id ASC`, [fbId]),
|
|
145
|
-
pool.query(`SELECT id, feedback_id, element_reference_id, attachment_type, filename,
|
|
169
|
+
pool.query(`SELECT id, feedback_id, comment_id, element_reference_id, attachment_type, filename,
|
|
146
170
|
content_type, byte_size, blob_key, metadata, created_at
|
|
147
171
|
FROM context_drop_attachments
|
|
148
172
|
WHERE feedback_id = $1
|
|
173
|
+
ORDER BY id ASC`, [fbId]),
|
|
174
|
+
pool.query(`SELECT id, feedback_id, author_type, author_label, body, created_at, updated_at
|
|
175
|
+
FROM context_drop_comments
|
|
176
|
+
WHERE feedback_id = $1
|
|
149
177
|
ORDER BY id ASC`, [fbId])
|
|
150
178
|
]);
|
|
151
179
|
const elements = elRes.rows.map((el) => ({
|
|
@@ -162,9 +190,12 @@ export function createPostgresStorageAdapter(options) {
|
|
|
162
190
|
metadata: parseJsonColumn(el["metadata"], {}),
|
|
163
191
|
captured_at: toIsoString(el["captured_at"])
|
|
164
192
|
}));
|
|
165
|
-
const
|
|
193
|
+
const allAttachments = attRes.rows.map((att) => ({
|
|
166
194
|
id: Number(att["id"]),
|
|
167
195
|
feedback_id: fbId,
|
|
196
|
+
comment_id: att["comment_id"] !== null && att["comment_id"] !== undefined
|
|
197
|
+
? Number(att["comment_id"])
|
|
198
|
+
: null,
|
|
168
199
|
element_reference_id: att["element_reference_id"] !== null && att["element_reference_id"] !== undefined
|
|
169
200
|
? Number(att["element_reference_id"])
|
|
170
201
|
: null,
|
|
@@ -178,10 +209,34 @@ export function createPostgresStorageAdapter(options) {
|
|
|
178
209
|
metadata: parseJsonColumn(att["metadata"], {}),
|
|
179
210
|
created_at: toIsoString(att["created_at"])
|
|
180
211
|
}));
|
|
212
|
+
const attachments = allAttachments.filter((a) => a.comment_id === null || a.comment_id === undefined);
|
|
213
|
+
const attachmentsByComment = new Map();
|
|
214
|
+
for (const a of allAttachments) {
|
|
215
|
+
if (a.comment_id !== null && a.comment_id !== undefined) {
|
|
216
|
+
const list = attachmentsByComment.get(Number(a.comment_id)) ?? [];
|
|
217
|
+
list.push(a);
|
|
218
|
+
attachmentsByComment.set(Number(a.comment_id), list);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const comments = commentRes.rows.map((c) => {
|
|
222
|
+
const cid = Number(c["id"]);
|
|
223
|
+
return {
|
|
224
|
+
id: cid,
|
|
225
|
+
feedback_id: fbId,
|
|
226
|
+
author_type: c["author_type"] ?? null,
|
|
227
|
+
author_label: String(c["author_label"] || "You"),
|
|
228
|
+
body: c["body"] ?? null,
|
|
229
|
+
attachments: attachmentsByComment.get(cid) ?? [],
|
|
230
|
+
created_at: toIsoString(c["created_at"]),
|
|
231
|
+
updated_at: toIsoString(c["updated_at"])
|
|
232
|
+
};
|
|
233
|
+
});
|
|
234
|
+
const rawStatus = String(row["status"] ?? "new");
|
|
235
|
+
const normalizedStatus = (rawStatus === "resolved" ? "fixed" : rawStatus);
|
|
181
236
|
return {
|
|
182
237
|
id: fbId,
|
|
183
238
|
environment: String(row["environment"] ?? "production"),
|
|
184
|
-
status:
|
|
239
|
+
status: normalizedStatus,
|
|
185
240
|
message: row["message"] ?? null,
|
|
186
241
|
page_url: String(row["page_url"] ?? ""),
|
|
187
242
|
user_agent: row["user_agent"] ?? null,
|
|
@@ -190,11 +245,16 @@ export function createPostgresStorageAdapter(options) {
|
|
|
190
245
|
metadata: parseJsonColumn(row["metadata"], {}),
|
|
191
246
|
element_references: elements,
|
|
192
247
|
attachments,
|
|
248
|
+
comments,
|
|
193
249
|
created_at: toIsoString(row["created_at"]),
|
|
194
|
-
updated_at: toIsoString(row["updated_at"])
|
|
250
|
+
updated_at: toIsoString(row["updated_at"]),
|
|
251
|
+
deleted_at: row["deleted_at"] ? toIsoString(row["deleted_at"]) : null
|
|
195
252
|
};
|
|
196
253
|
}
|
|
197
254
|
return {
|
|
255
|
+
getOwnershipSecret() {
|
|
256
|
+
return secretKey;
|
|
257
|
+
},
|
|
198
258
|
async savePendingBlob(blob) {
|
|
199
259
|
await ensureMigrated();
|
|
200
260
|
const rawId = crypto.randomUUID();
|
|
@@ -338,6 +398,9 @@ export function createPostgresStorageAdapter(options) {
|
|
|
338
398
|
const offset = Math.max(0, filter.offset ?? 0);
|
|
339
399
|
const clauses = [];
|
|
340
400
|
const values = [];
|
|
401
|
+
if (!filter.include_deleted) {
|
|
402
|
+
clauses.push("f.deleted_at IS NULL");
|
|
403
|
+
}
|
|
341
404
|
if (filter.environment && filter.environment.trim().length > 0) {
|
|
342
405
|
values.push(filter.environment.trim().toLowerCase());
|
|
343
406
|
clauses.push(`LOWER(f.environment) = $${values.length}`);
|
|
@@ -372,6 +435,47 @@ export function createPostgresStorageAdapter(options) {
|
|
|
372
435
|
records: hydrated.map(toFeedbackSummary)
|
|
373
436
|
};
|
|
374
437
|
},
|
|
438
|
+
async listOwnFeedbacks(query) {
|
|
439
|
+
await ensureMigrated();
|
|
440
|
+
const limit = Math.max(1, Math.min(50, query.limit ?? 20));
|
|
441
|
+
const ownershipClauses = [];
|
|
442
|
+
const values = [];
|
|
443
|
+
if (hasAuthenticatedSubmitter(query.submitter)) {
|
|
444
|
+
values.push(String(query.submitter?.type || "User").trim());
|
|
445
|
+
const typeParam = `$${values.length}`;
|
|
446
|
+
values.push(String(query.submitter?.id).trim());
|
|
447
|
+
const idParam = `$${values.length}`;
|
|
448
|
+
ownershipClauses.push(`(COALESCE(NULLIF(f.submitter->>'type', ''), 'User') = ${typeParam} AND f.submitter->>'id' = ${idParam})`);
|
|
449
|
+
}
|
|
450
|
+
if (query.session_id && query.session_id.trim().length > 0) {
|
|
451
|
+
values.push(query.session_id.trim());
|
|
452
|
+
const sidParam = `$${values.length}`;
|
|
453
|
+
ownershipClauses.push(`((f.submitter->>'id' IS NULL OR f.submitter->>'id' = '') AND f.session_id = ${sidParam})`);
|
|
454
|
+
}
|
|
455
|
+
const numericTokenIds = (query.token_ids ?? [])
|
|
456
|
+
.map((t) => Number(t))
|
|
457
|
+
.filter((n) => Number.isInteger(n) && n > 0);
|
|
458
|
+
if (numericTokenIds.length > 0) {
|
|
459
|
+
values.push(numericTokenIds);
|
|
460
|
+
const idsParam = `$${values.length}`;
|
|
461
|
+
ownershipClauses.push(`((f.submitter->>'id' IS NULL OR f.submitter->>'id' = '') AND f.id = ANY(${idsParam}::bigint[]))`);
|
|
462
|
+
}
|
|
463
|
+
if (ownershipClauses.length === 0) {
|
|
464
|
+
return { total: 0, records: [] };
|
|
465
|
+
}
|
|
466
|
+
const whereSql = `WHERE f.deleted_at IS NULL AND (${ownershipClauses.join(" OR ")})`;
|
|
467
|
+
const countRes = await pool.query(`SELECT COUNT(*)::int AS total FROM context_drop_feedbacks f ${whereSql}`, values);
|
|
468
|
+
const total = Number(countRes.rows[0]?.["total"] ?? 0);
|
|
469
|
+
const pageValues = [...values, limit];
|
|
470
|
+
const rowsRes = await pool.query(`SELECT f.* FROM context_drop_feedbacks f ${whereSql}
|
|
471
|
+
ORDER BY f.created_at DESC, f.id DESC
|
|
472
|
+
LIMIT $${pageValues.length}`, pageValues);
|
|
473
|
+
const hydrated = await Promise.all(rowsRes.rows.map(hydrateFeedbackRow));
|
|
474
|
+
return {
|
|
475
|
+
total,
|
|
476
|
+
records: hydrated
|
|
477
|
+
};
|
|
478
|
+
},
|
|
375
479
|
async getFeedback(id) {
|
|
376
480
|
await ensureMigrated();
|
|
377
481
|
const res = await pool.query("SELECT * FROM context_drop_feedbacks WHERE id = $1", [
|
|
@@ -382,6 +486,141 @@ export function createPostgresStorageAdapter(options) {
|
|
|
382
486
|
return null;
|
|
383
487
|
return hydrateFeedbackRow(row);
|
|
384
488
|
},
|
|
489
|
+
async updateFeedback(id, input) {
|
|
490
|
+
await ensureMigrated();
|
|
491
|
+
const fbId = Number(id);
|
|
492
|
+
const existing = await this.getFeedback(fbId);
|
|
493
|
+
if (!existing || existing.deleted_at)
|
|
494
|
+
return null;
|
|
495
|
+
const nextMessage = input.message !== undefined ? input.message : existing.message;
|
|
496
|
+
const nextMetadata = input.metadata !== undefined ? input.metadata : existing.metadata;
|
|
497
|
+
const contentEdited = input.message !== undefined ||
|
|
498
|
+
input.metadata !== undefined ||
|
|
499
|
+
input.element_references !== undefined ||
|
|
500
|
+
input.attachments !== undefined;
|
|
501
|
+
const nextStatus = input.status ?? (contentEdited ? "updated" : existing.status);
|
|
502
|
+
await pool.query(`UPDATE context_drop_feedbacks
|
|
503
|
+
SET message = $1, metadata = $2::jsonb, status = $3, updated_at = NOW()
|
|
504
|
+
WHERE id = $4`, [nextMessage, JSON.stringify(nextMetadata || {}), nextStatus, fbId]);
|
|
505
|
+
const elIdByRef = new Map();
|
|
506
|
+
if (input.element_references !== undefined) {
|
|
507
|
+
await pool.query("DELETE FROM context_drop_element_references WHERE feedback_id = $1", [fbId]);
|
|
508
|
+
for (let idx = 0; idx < input.element_references.length; idx++) {
|
|
509
|
+
const el = input.element_references[idx];
|
|
510
|
+
const elRes = await pool.query(`INSERT INTO context_drop_element_references
|
|
511
|
+
(feedback_id, client_ref, tag_name, selector, dom_path, text_content,
|
|
512
|
+
attributes_snapshot, bounding_rect, viewport, metadata, captured_at)
|
|
513
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7::jsonb, $8::jsonb, $9::jsonb, $10::jsonb, $11::timestamptz)
|
|
514
|
+
RETURNING id`, [
|
|
515
|
+
fbId,
|
|
516
|
+
el.client_ref,
|
|
517
|
+
el.tag_name,
|
|
518
|
+
el.selector,
|
|
519
|
+
el.dom_path,
|
|
520
|
+
el.text_content,
|
|
521
|
+
JSON.stringify(el.attributes_snapshot || {}),
|
|
522
|
+
JSON.stringify(el.bounding_rect || {}),
|
|
523
|
+
JSON.stringify(el.viewport || {}),
|
|
524
|
+
JSON.stringify(el.metadata || {}),
|
|
525
|
+
el.captured_at
|
|
526
|
+
]);
|
|
527
|
+
elIdByRef.set(el.client_ref || String(idx), Number(elRes.rows[0]["id"]));
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
else {
|
|
531
|
+
existing.element_references.forEach((el, idx) => {
|
|
532
|
+
elIdByRef.set(el.client_ref || String(idx), Number(el.id));
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
if (input.attachments !== undefined) {
|
|
536
|
+
const retainedIds = new Set();
|
|
537
|
+
const prevById = new Map();
|
|
538
|
+
for (const a of existing.attachments) {
|
|
539
|
+
prevById.set(String(a.id), a);
|
|
540
|
+
}
|
|
541
|
+
for (const spec of input.attachments) {
|
|
542
|
+
if (spec.kind === "retain") {
|
|
543
|
+
const prev = prevById.get(String(spec.existing_id));
|
|
544
|
+
if (!prev)
|
|
545
|
+
continue;
|
|
546
|
+
retainedIds.add(Number(prev.id));
|
|
547
|
+
const linkedElId = spec.element_client_ref !== undefined
|
|
548
|
+
? spec.element_client_ref
|
|
549
|
+
? elIdByRef.get(spec.element_client_ref) ?? null
|
|
550
|
+
: null
|
|
551
|
+
: input.element_references === undefined && prev.element_reference_id !== null
|
|
552
|
+
? Number(prev.element_reference_id)
|
|
553
|
+
: null;
|
|
554
|
+
const nextAttMeta = spec.update_metadata && spec.metadata ? spec.metadata : prev.metadata;
|
|
555
|
+
await pool.query(`UPDATE context_drop_attachments
|
|
556
|
+
SET element_reference_id = $1, metadata = $2::jsonb
|
|
557
|
+
WHERE id = $3`, [linkedElId, JSON.stringify(nextAttMeta || {}), Number(prev.id)]);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
for (const prev of existing.attachments) {
|
|
561
|
+
if (!retainedIds.has(Number(prev.id))) {
|
|
562
|
+
await pool.query("DELETE FROM context_drop_attachments WHERE id = $1", [
|
|
563
|
+
Number(prev.id)
|
|
564
|
+
]);
|
|
565
|
+
if (prev.blob_key && blobStore?.deleteBlob) {
|
|
566
|
+
await blobStore.deleteBlob(prev.blob_key);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
for (const spec of input.attachments) {
|
|
571
|
+
if (spec.kind !== "create")
|
|
572
|
+
continue;
|
|
573
|
+
const linkedElId = spec.element_client_ref
|
|
574
|
+
? elIdByRef.get(spec.element_client_ref) ?? null
|
|
575
|
+
: null;
|
|
576
|
+
let blobKey = null;
|
|
577
|
+
let inlineBytes = null;
|
|
578
|
+
if (spec.data) {
|
|
579
|
+
if (blobStore) {
|
|
580
|
+
const saved = await blobStore.putBlob({
|
|
581
|
+
key: `att_${fbId}_${crypto.randomUUID()}`,
|
|
582
|
+
data: spec.data,
|
|
583
|
+
contentType: spec.content_type || "image/png",
|
|
584
|
+
filename: spec.filename || "attachment.png"
|
|
585
|
+
});
|
|
586
|
+
blobKey = saved.key;
|
|
587
|
+
}
|
|
588
|
+
else {
|
|
589
|
+
inlineBytes = Buffer.from(spec.data);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
await pool.query(`INSERT INTO context_drop_attachments
|
|
593
|
+
(feedback_id, element_reference_id, attachment_type, filename, content_type, byte_size, blob_key, data, metadata)
|
|
594
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9::jsonb)`, [
|
|
595
|
+
fbId,
|
|
596
|
+
linkedElId,
|
|
597
|
+
spec.attachment_type,
|
|
598
|
+
spec.filename,
|
|
599
|
+
spec.content_type,
|
|
600
|
+
spec.byte_size,
|
|
601
|
+
blobKey,
|
|
602
|
+
inlineBytes,
|
|
603
|
+
JSON.stringify(spec.metadata || {})
|
|
604
|
+
]);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
return this.getFeedback(fbId);
|
|
608
|
+
},
|
|
609
|
+
async softDeleteFeedback(id) {
|
|
610
|
+
await ensureMigrated();
|
|
611
|
+
const fbId = Number(id);
|
|
612
|
+
const existing = await this.getFeedback(fbId);
|
|
613
|
+
if (!existing || existing.deleted_at)
|
|
614
|
+
return null;
|
|
615
|
+
const res = await pool.query(`UPDATE context_drop_feedbacks
|
|
616
|
+
SET deleted_at = NOW(), updated_at = NOW()
|
|
617
|
+
WHERE id = $1 AND deleted_at IS NULL
|
|
618
|
+
RETURNING *`, [fbId]);
|
|
619
|
+
const row = res.rows[0];
|
|
620
|
+
if (!row)
|
|
621
|
+
return null;
|
|
622
|
+
return hydrateFeedbackRow(row);
|
|
623
|
+
},
|
|
385
624
|
async getAttachment(attachmentId) {
|
|
386
625
|
await ensureMigrated();
|
|
387
626
|
const res = await pool.query(`SELECT a.*, e.selector AS element_selector
|
|
@@ -428,19 +667,73 @@ export function createPostgresStorageAdapter(options) {
|
|
|
428
667
|
async updateFeedbackStatus(id, status) {
|
|
429
668
|
await ensureMigrated();
|
|
430
669
|
const existing = await this.getFeedback(id);
|
|
431
|
-
if (!existing)
|
|
670
|
+
if (!existing || existing.deleted_at)
|
|
432
671
|
return null;
|
|
433
|
-
const
|
|
672
|
+
const res = await pool.query(`UPDATE context_drop_feedbacks
|
|
434
673
|
SET status = $1, updated_at = NOW()
|
|
435
674
|
WHERE id = $2
|
|
436
675
|
RETURNING *`, [status, Number(id)]);
|
|
437
|
-
const row =
|
|
676
|
+
const row = res.rows[0];
|
|
438
677
|
if (!row)
|
|
439
678
|
return null;
|
|
440
679
|
return {
|
|
441
680
|
previous_status: existing.status,
|
|
442
681
|
feedback: await hydrateFeedbackRow(row)
|
|
443
682
|
};
|
|
683
|
+
},
|
|
684
|
+
async addComment(feedbackId, input) {
|
|
685
|
+
await ensureMigrated();
|
|
686
|
+
const fbId = Number(feedbackId);
|
|
687
|
+
const existing = await this.getFeedback(fbId);
|
|
688
|
+
if (!existing || existing.deleted_at)
|
|
689
|
+
return null;
|
|
690
|
+
const commentRes = await pool.query(`INSERT INTO context_drop_comments (feedback_id, author_type, author_label, body)
|
|
691
|
+
VALUES ($1, $2, $3, $4)
|
|
692
|
+
RETURNING id`, [fbId, input.author_type ?? "User", input.author_label || "You", input.body]);
|
|
693
|
+
const commentId = Number(commentRes.rows[0]["id"]);
|
|
694
|
+
for (const att of input.attachments ?? []) {
|
|
695
|
+
let blobKey = null;
|
|
696
|
+
let inlineData = null;
|
|
697
|
+
if (att.data) {
|
|
698
|
+
if (blobStore) {
|
|
699
|
+
const saved = await blobStore.putBlob({
|
|
700
|
+
key: `fb_${fbId}_comment_${commentId}_${crypto.randomUUID()}`,
|
|
701
|
+
data: att.data,
|
|
702
|
+
contentType: att.content_type || "image/png",
|
|
703
|
+
filename: att.filename || "image.png"
|
|
704
|
+
});
|
|
705
|
+
blobKey = saved.key;
|
|
706
|
+
}
|
|
707
|
+
else {
|
|
708
|
+
inlineData = Buffer.from(att.data);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
await pool.query(`INSERT INTO context_drop_attachments
|
|
712
|
+
(feedback_id, comment_id, element_reference_id, attachment_type, filename, content_type, byte_size, blob_key, data, metadata)
|
|
713
|
+
VALUES ($1, $2, NULL, $3, $4, $5, $6, $7, $8, $9::jsonb)`, [
|
|
714
|
+
fbId,
|
|
715
|
+
commentId,
|
|
716
|
+
att.attachment_type,
|
|
717
|
+
att.filename,
|
|
718
|
+
att.content_type,
|
|
719
|
+
att.byte_size,
|
|
720
|
+
blobKey,
|
|
721
|
+
inlineData,
|
|
722
|
+
JSON.stringify(att.metadata || {})
|
|
723
|
+
]);
|
|
724
|
+
}
|
|
725
|
+
const nextStatus = input.status ?? "updated";
|
|
726
|
+
await pool.query(`UPDATE context_drop_feedbacks SET status = $1, updated_at = NOW() WHERE id = $2`, [nextStatus, fbId]);
|
|
727
|
+
const updated = await this.getFeedback(fbId);
|
|
728
|
+
if (!updated)
|
|
729
|
+
return null;
|
|
730
|
+
const createdComment = (updated.comments ?? []).find((c) => Number(c.id) === commentId);
|
|
731
|
+
if (!createdComment)
|
|
732
|
+
return null;
|
|
733
|
+
return {
|
|
734
|
+
comment: createdComment,
|
|
735
|
+
feedback: updated
|
|
736
|
+
};
|
|
444
737
|
}
|
|
445
738
|
};
|
|
446
739
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BoundingRectSnapshot, SelectionMode, ViewportSnapshot, WidgetPosition } from "../../app/javascript/context_drop/types.js";
|
|
2
|
-
export declare const VERSION = "0.
|
|
3
|
-
export type FeedbackStatus = "new" | "
|
|
2
|
+
export declare const VERSION = "0.3.1";
|
|
3
|
+
export type FeedbackStatus = "new" | "updated" | "fixed" | "reviewed" | "dismissed";
|
|
4
4
|
export declare const FEEDBACK_STATUSES: readonly FeedbackStatus[];
|
|
5
5
|
export interface SubmitterIdentity {
|
|
6
6
|
type?: string | null;
|
|
@@ -24,6 +24,7 @@ export interface StoredElementReference {
|
|
|
24
24
|
export interface StoredAttachment {
|
|
25
25
|
id: number | string;
|
|
26
26
|
feedback_id: number | string;
|
|
27
|
+
comment_id?: number | string | null;
|
|
27
28
|
element_reference_id: number | string | null;
|
|
28
29
|
attachment_type: "image" | "screenshot";
|
|
29
30
|
filename: string | null;
|
|
@@ -33,6 +34,16 @@ export interface StoredAttachment {
|
|
|
33
34
|
metadata: Record<string, unknown>;
|
|
34
35
|
created_at: string;
|
|
35
36
|
}
|
|
37
|
+
export interface StoredComment {
|
|
38
|
+
id: number | string;
|
|
39
|
+
feedback_id: number | string;
|
|
40
|
+
author_type?: string | null;
|
|
41
|
+
author_label: string;
|
|
42
|
+
body: string | null;
|
|
43
|
+
attachments: StoredAttachment[];
|
|
44
|
+
created_at: string;
|
|
45
|
+
updated_at: string;
|
|
46
|
+
}
|
|
36
47
|
export interface StoredFeedbackRecord {
|
|
37
48
|
id: number | string;
|
|
38
49
|
environment: string;
|
|
@@ -45,8 +56,11 @@ export interface StoredFeedbackRecord {
|
|
|
45
56
|
metadata: Record<string, unknown>;
|
|
46
57
|
element_references: StoredElementReference[];
|
|
47
58
|
attachments: StoredAttachment[];
|
|
59
|
+
comments?: StoredComment[];
|
|
60
|
+
comments_count?: number;
|
|
48
61
|
created_at: string;
|
|
49
62
|
updated_at: string;
|
|
63
|
+
deleted_at?: string | null;
|
|
50
64
|
}
|
|
51
65
|
export interface FeedbackSummaryItem {
|
|
52
66
|
id: number | string;
|
|
@@ -58,8 +72,11 @@ export interface FeedbackSummaryItem {
|
|
|
58
72
|
submitter: string;
|
|
59
73
|
attachments_count: number;
|
|
60
74
|
element_references_count: number;
|
|
75
|
+
comments_count?: number;
|
|
61
76
|
element_selectors: string[];
|
|
62
77
|
created_at: string;
|
|
78
|
+
deleted?: boolean;
|
|
79
|
+
deleted_at?: string | null;
|
|
63
80
|
}
|
|
64
81
|
export interface FeedbackQueryFilter {
|
|
65
82
|
environment?: string | null;
|
|
@@ -68,6 +85,7 @@ export interface FeedbackQueryFilter {
|
|
|
68
85
|
query?: string | null;
|
|
69
86
|
limit?: number;
|
|
70
87
|
offset?: number;
|
|
88
|
+
include_deleted?: boolean;
|
|
71
89
|
}
|
|
72
90
|
export interface ValidatedUpload {
|
|
73
91
|
data: Uint8Array;
|
|
@@ -97,6 +115,17 @@ export interface CreateAttachmentInput {
|
|
|
97
115
|
data: Uint8Array | null;
|
|
98
116
|
metadata: Record<string, unknown>;
|
|
99
117
|
}
|
|
118
|
+
export interface RetainedAttachmentInput {
|
|
119
|
+
existing_id: string | number;
|
|
120
|
+
element_client_ref?: string | null;
|
|
121
|
+
metadata?: Record<string, unknown>;
|
|
122
|
+
update_metadata?: boolean;
|
|
123
|
+
}
|
|
124
|
+
export type UpdateAttachmentSpec = ({
|
|
125
|
+
kind: "retain";
|
|
126
|
+
} & RetainedAttachmentInput) | ({
|
|
127
|
+
kind: "create";
|
|
128
|
+
} & CreateAttachmentInput);
|
|
100
129
|
export interface CreateFeedbackRecordInput {
|
|
101
130
|
environment: string;
|
|
102
131
|
message: string | null;
|
|
@@ -108,6 +137,26 @@ export interface CreateFeedbackRecordInput {
|
|
|
108
137
|
element_references: SanitizedElementInput[];
|
|
109
138
|
attachments: CreateAttachmentInput[];
|
|
110
139
|
}
|
|
140
|
+
export interface UpdateFeedbackRecordInput {
|
|
141
|
+
message?: string | null;
|
|
142
|
+
status?: FeedbackStatus;
|
|
143
|
+
metadata?: Record<string, unknown>;
|
|
144
|
+
element_references?: SanitizedElementInput[];
|
|
145
|
+
attachments?: UpdateAttachmentSpec[];
|
|
146
|
+
}
|
|
147
|
+
export interface CreateCommentInput {
|
|
148
|
+
author_type?: string | null;
|
|
149
|
+
author_label?: string | null;
|
|
150
|
+
body: string | null;
|
|
151
|
+
attachments: CreateAttachmentInput[];
|
|
152
|
+
status?: FeedbackStatus;
|
|
153
|
+
}
|
|
154
|
+
export interface OwnFeedbackLookupQuery {
|
|
155
|
+
submitter?: SubmitterIdentity | null;
|
|
156
|
+
session_id?: string | null;
|
|
157
|
+
token_ids?: Array<string | number>;
|
|
158
|
+
limit?: number;
|
|
159
|
+
}
|
|
111
160
|
export interface BlobStorageAdapter {
|
|
112
161
|
putBlob(input: {
|
|
113
162
|
key: string;
|
|
@@ -130,7 +179,13 @@ export interface StorageAdapter {
|
|
|
130
179
|
total: number;
|
|
131
180
|
records: FeedbackSummaryItem[];
|
|
132
181
|
}>;
|
|
182
|
+
listOwnFeedbacks(query: OwnFeedbackLookupQuery): Promise<{
|
|
183
|
+
total: number;
|
|
184
|
+
records: StoredFeedbackRecord[];
|
|
185
|
+
}>;
|
|
133
186
|
getFeedback(id: string | number): Promise<StoredFeedbackRecord | null>;
|
|
187
|
+
updateFeedback(id: string | number, input: UpdateFeedbackRecordInput): Promise<StoredFeedbackRecord | null>;
|
|
188
|
+
softDeleteFeedback(id: string | number): Promise<StoredFeedbackRecord | null>;
|
|
134
189
|
getAttachment(attachmentId: string | number): Promise<{
|
|
135
190
|
attachment: StoredAttachment;
|
|
136
191
|
element_selector: string | null;
|
|
@@ -141,6 +196,11 @@ export interface StorageAdapter {
|
|
|
141
196
|
previous_status: FeedbackStatus;
|
|
142
197
|
feedback: StoredFeedbackRecord;
|
|
143
198
|
} | null>;
|
|
199
|
+
addComment?(feedbackId: string | number, input: CreateCommentInput): Promise<{
|
|
200
|
+
comment: StoredComment;
|
|
201
|
+
feedback: StoredFeedbackRecord;
|
|
202
|
+
} | null>;
|
|
203
|
+
getOwnershipSecret?(): Buffer;
|
|
144
204
|
}
|
|
145
205
|
export interface RemoteMcpEnvironmentConfig {
|
|
146
206
|
url: string;
|
|
@@ -156,6 +216,7 @@ export interface ContextDropServerConfig {
|
|
|
156
216
|
selectionMode?: "auto" | SelectionMode;
|
|
157
217
|
allowAnonymous?: boolean;
|
|
158
218
|
allowedOrigins?: Array<string | RegExp>;
|
|
219
|
+
ownershipSecret?: string;
|
|
159
220
|
storage?: StorageAdapter;
|
|
160
221
|
storageDir?: string;
|
|
161
222
|
features?: {
|
|
@@ -181,6 +242,8 @@ export interface ContextDropServerConfig {
|
|
|
181
242
|
resolveSubmitter?: (request: Request) => Promise<SubmitterIdentity | null> | SubmitterIdentity | null;
|
|
182
243
|
authorizeSubmission?: (request: Request, submitter: SubmitterIdentity | null) => Promise<boolean> | boolean;
|
|
183
244
|
onFeedbackCreated?: (feedback: StoredFeedbackRecord) => Promise<void> | void;
|
|
245
|
+
onFeedbackUpdated?: (feedback: StoredFeedbackRecord) => Promise<void> | void;
|
|
246
|
+
onFeedbackDeleted?: (feedback: StoredFeedbackRecord) => Promise<void> | void;
|
|
184
247
|
mcp?: {
|
|
185
248
|
enabled?: boolean;
|
|
186
249
|
apiKey?: string;
|
package/dist/src/server/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "context-drop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Self-hosted contextual feedback widget, Next.js & Rails integration, and unified multi-environment MCP server for AI coding agents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/src/index.js",
|