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/dist/src/cli.js CHANGED
@@ -113,7 +113,7 @@ function runInitCommand(args, cwd = process.cwd()) {
113
113
  fs.writeFileSync(routeFile, [
114
114
  'import { createContextDropNextHandler } from "context-drop/next/server";',
115
115
  "",
116
- "export const { GET, POST, OPTIONS } = createContextDropNextHandler({",
116
+ "export const { GET, POST, PATCH, PUT, DELETE, OPTIONS } = createContextDropNextHandler({",
117
117
  " mcp: {",
118
118
  " enabled: Boolean(process.env.CONTEXT_DROP_MCP_API_KEY),",
119
119
  " apiKey: process.env.CONTEXT_DROP_MCP_API_KEY",
@@ -48,6 +48,10 @@ const TOOL_DEFINITIONS = [
48
48
  offset: {
49
49
  type: "integer",
50
50
  description: "Pagination offset (default 0)."
51
+ },
52
+ include_deleted: {
53
+ type: "boolean",
54
+ description: "When true, includes soft-deleted feedback records. Defaults to false."
51
55
  }
52
56
  }
53
57
  }
@@ -70,6 +74,10 @@ const TOOL_DEFINITIONS = [
70
74
  include_images: {
71
75
  type: "boolean",
72
76
  description: "When true (default), includes attached screenshots and images as base64 MCP image content blocks."
77
+ },
78
+ include_deleted: {
79
+ type: "boolean",
80
+ description: "When true, allows retrieving a soft-deleted feedback record. Defaults to false."
73
81
  }
74
82
  }
75
83
  }
@@ -94,7 +102,7 @@ const TOOL_DEFINITIONS = [
94
102
  },
95
103
  {
96
104
  name: "update_feedback_status",
97
- description: "Transition a ContextDrop feedback record's status ('new', 'reviewed', 'resolved', 'dismissed') in local or remote environments.",
105
+ description: "Transition a ContextDrop feedback record's status ('new', 'updated', 'fixed', 'reviewed', 'dismissed') in local or remote environments.",
98
106
  inputSchema: {
99
107
  type: "object",
100
108
  required: ["id", "status"],
@@ -204,6 +212,8 @@ function serializeFullFeedback(record, router) {
204
212
  metadata: record.metadata ?? {},
205
213
  created_at: record.created_at,
206
214
  updated_at: record.updated_at,
215
+ deleted: Boolean(record.deleted_at),
216
+ deleted_at: record.deleted_at ?? null,
207
217
  element_references: record.element_references.map((el) => ({
208
218
  id: el.id,
209
219
  client_ref: el.client_ref,
@@ -227,6 +237,21 @@ function serializeFullFeedback(record, router) {
227
237
  content_type: att.content_type,
228
238
  byte_size: att.byte_size,
229
239
  created_at: att.created_at
240
+ })),
241
+ comments: (record.comments ?? []).map((comment) => ({
242
+ id: comment.id,
243
+ author_label: comment.author_label,
244
+ author_type: comment.author_type ?? null,
245
+ body: comment.body,
246
+ attachments: (comment.attachments ?? []).map((att) => ({
247
+ id: att.id,
248
+ attachment_type: att.attachment_type,
249
+ filename: att.filename,
250
+ content_type: att.content_type,
251
+ byte_size: att.byte_size,
252
+ created_at: att.created_at
253
+ })),
254
+ created_at: comment.created_at
230
255
  }))
231
256
  };
232
257
  }
@@ -371,6 +396,7 @@ export class ContextDropMcpDispatcher {
371
396
  const offset = Math.max(0, Number.isFinite(rawOffset) ? Math.trunc(rawOffset) : 0);
372
397
  const pageUrl = String(args["page_url"] ?? "").trim() || null;
373
398
  const query = String(args["query"] ?? "").trim() || null;
399
+ const includeDeleted = Boolean(args["include_deleted"]);
374
400
  const requestedEnv = (String(args["environment"] ?? "").trim().toLowerCase()) || "all";
375
401
  const remotes = this.router.getRemoteEnvironments();
376
402
  const hostEnv = this.router.hostEnvironment;
@@ -381,7 +407,8 @@ export class ContextDropMcpDispatcher {
381
407
  page_url: pageUrl,
382
408
  query,
383
409
  limit: fetchWindow,
384
- offset: 0
410
+ offset: 0,
411
+ include_deleted: includeDeleted
385
412
  });
386
413
  const remoteEntries = Object.entries(remotes);
387
414
  if (remoteEntries.length === 0) {
@@ -401,7 +428,8 @@ export class ContextDropMcpDispatcher {
401
428
  page_url: pageUrl,
402
429
  query,
403
430
  limit: fetchWindow,
404
- offset: 0
431
+ offset: 0,
432
+ include_deleted: includeDeleted
405
433
  });
406
434
  }
407
435
  catch (err) {
@@ -441,7 +469,8 @@ export class ContextDropMcpDispatcher {
441
469
  page_url: pageUrl,
442
470
  query,
443
471
  limit,
444
- offset
472
+ offset,
473
+ include_deleted: includeDeleted
445
474
  });
446
475
  return successJsonTool({
447
476
  environment: hostEnv,
@@ -459,7 +488,8 @@ export class ContextDropMcpDispatcher {
459
488
  page_url: pageUrl,
460
489
  query,
461
490
  limit,
462
- offset
491
+ offset,
492
+ include_deleted: includeDeleted
463
493
  });
464
494
  return successJsonTool({
465
495
  environment: requestedEnv,
@@ -480,7 +510,8 @@ export class ContextDropMcpDispatcher {
480
510
  page_url: pageUrl,
481
511
  query,
482
512
  limit,
483
- offset
513
+ offset,
514
+ include_deleted: includeDeleted
484
515
  });
485
516
  if (fallbackRes.total > 0) {
486
517
  return successJsonTool({
@@ -505,6 +536,8 @@ export class ContextDropMcpDispatcher {
505
536
  remoteArgs["page_url"] = filter.page_url;
506
537
  if (filter.query)
507
538
  remoteArgs["query"] = filter.query;
539
+ if (filter.include_deleted)
540
+ remoteArgs["include_deleted"] = true;
508
541
  const toolRes = await this.remoteClient.callTool(envName, cfg, "list_feedbacks", remoteArgs);
509
542
  const textBlock = toolRes.content.find((b) => b.type === "text");
510
543
  const parsed = textBlock?.text ? JSON.parse(textBlock.text) : {};
@@ -533,16 +566,17 @@ export class ContextDropMcpDispatcher {
533
566
  return errorTool("Missing required parameter: id");
534
567
  }
535
568
  const includeImages = args["include_images"] !== undefined ? Boolean(args["include_images"]) : true;
569
+ const includeDeleted = Boolean(args["include_deleted"]);
536
570
  const [targetEnv, feedbackId] = this.router.parseTarget(rawId, args["environment"]);
537
571
  if (!this.router.isLocalTarget(targetEnv)) {
538
572
  const remoteCfg = this.router.getRemoteConfig(targetEnv);
539
573
  if (!remoteCfg || !targetEnv) {
540
574
  return errorTool(`Unknown remote environment '${targetEnv}'`);
541
575
  }
542
- return this.fetchRemoteFeedback(targetEnv, remoteCfg, feedbackId, includeImages);
576
+ return this.fetchRemoteFeedback(targetEnv, remoteCfg, feedbackId, includeImages, includeDeleted);
543
577
  }
544
578
  const feedback = await this.storage.getFeedback(feedbackId);
545
- if (!feedback) {
579
+ if (!feedback || (!includeDeleted && feedback.deleted_at)) {
546
580
  return errorTool(`Feedback #${feedbackId} not found`);
547
581
  }
548
582
  const payload = serializeFullFeedback(feedback, this.router);
@@ -565,18 +599,33 @@ export class ContextDropMcpDispatcher {
565
599
  });
566
600
  }
567
601
  }
602
+ for (const comment of feedback.comments ?? []) {
603
+ for (const att of comment.attachments ?? []) {
604
+ const bytes = await this.storage.getAttachmentBytes(att.id);
605
+ if (bytes && bytes.byteLength > 0 && bytes.byteLength <= MAX_INLINE_IMAGE_BYTES) {
606
+ contentBlocks.push({
607
+ type: "image",
608
+ data: Buffer.from(bytes).toString("base64"),
609
+ mimeType: att.content_type || "image/png"
610
+ });
611
+ }
612
+ }
613
+ }
568
614
  }
569
615
  return {
570
616
  content: contentBlocks,
571
617
  isError: false
572
618
  };
573
619
  }
574
- async fetchRemoteFeedback(envName, remoteCfg, feedbackId, includeImages) {
620
+ async fetchRemoteFeedback(envName, remoteCfg, feedbackId, includeImages, includeDeleted = false) {
575
621
  try {
576
- const res = await this.remoteClient.callTool(envName, remoteCfg, "get_feedback", {
622
+ const remoteArgs = {
577
623
  id: feedbackId,
578
624
  include_images: includeImages
579
- });
625
+ };
626
+ if (includeDeleted)
627
+ remoteArgs["include_deleted"] = true;
628
+ const res = await this.remoteClient.callTool(envName, remoteCfg, "get_feedback", remoteArgs);
580
629
  if (res.isError)
581
630
  return res;
582
631
  const updatedBlocks = res.content.map((block) => {
@@ -623,6 +672,10 @@ export class ContextDropMcpDispatcher {
623
672
  if (!found) {
624
673
  return errorTool(`Attachment #${attId} not found`);
625
674
  }
675
+ const parentFb = await this.storage.getFeedback(found.attachment.feedback_id);
676
+ if (parentFb?.deleted_at) {
677
+ return errorTool(`Attachment #${attId} not found`);
678
+ }
626
679
  const envName = this.router.hostEnvironment;
627
680
  const { attachment, element_selector, data } = found;
628
681
  const metaPayload = {
@@ -825,7 +878,7 @@ export class ContextDropMcpDispatcher {
825
878
  `1. Locate the page route corresponding to \`${pageUrl}\` (in Next.js \`app/**/page.tsx\` / \`pages/**\`, React router, or Rails \`config/routes.rb\` & \`app/views/\`).`,
826
879
  `2. Search components and templates for the attached DOM selectors (\`${selectorsList || "N/A"}\`) and data-testid / class / text landmarks.`,
827
880
  `3. Inspect any attached screenshots (\`get_feedback\` with \`id: "${qualified}"\`) to verify the visual layout or behavior issue.`,
828
- `4. Implement and verify the fix locally, then call \`update_feedback_status\` (\`id: "${qualified}"\`, \`status: "resolved"\`) once complete.`
881
+ `4. Implement and verify the fix locally, then call \`update_feedback_status\` (\`id: "${qualified}"\`, \`status: "fixed"\`) once complete.`
829
882
  ].join("\n");
830
883
  const imageBlocks = res.content.filter((b) => b.type === "image");
831
884
  const messageContent = [{ type: "text", text: instructions }, ...imageBlocks];
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { useContextDrop, type ContextDropHandle, type ContextDropProps } from "../react/index.js";
3
- export type { ContextDropHandle, ContextDropProps, FeedbackSubmissionPayload, FeedbackSubmissionResponse, SelectionMode, WidgetConfig, WidgetPosition } from "../react/index.js";
3
+ export type { ContextDropHandle, ContextDropProps, FeedbackDeleteResponse, FeedbackSubmissionPayload, FeedbackSubmissionResponse, FeedbackUpdatePayload, FeedbackUpdateResponse, SelectionMode, WidgetConfig, WidgetPosition } from "../react/index.js";
4
4
  export { useContextDrop };
5
5
  /**
6
6
  * Drop-in Next.js Client Component for App Router (`app/layout.tsx`) and Pages Router (`pages/_app.tsx`).
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
- import type { FeedbackSubmissionPayload, FeedbackSubmissionResponse, SelectionMode, WidgetConfig, WidgetPosition } from "../../app/javascript/context_drop/types.js";
2
+ import type { FeedbackDeleteResponse, FeedbackSubmissionPayload, FeedbackSubmissionResponse, FeedbackUpdatePayload, FeedbackUpdateResponse, SelectionMode, WidgetConfig, WidgetPosition } from "../../app/javascript/context_drop/types.js";
3
3
  import { ContextDropWidgetElement, registerContextDropWidget } from "../../app/javascript/context_drop/widget.js";
4
- export type { FeedbackSubmissionPayload, FeedbackSubmissionResponse, SelectionMode, WidgetConfig, WidgetPosition };
4
+ export type { FeedbackDeleteResponse, FeedbackSubmissionPayload, FeedbackSubmissionResponse, FeedbackUpdatePayload, FeedbackUpdateResponse, SelectionMode, WidgetConfig, WidgetPosition };
5
5
  export { ContextDropWidgetElement, registerContextDropWidget };
6
6
  export interface ContextDropHandle {
7
7
  open: () => void;
@@ -65,6 +65,20 @@ export interface ContextDropProps {
65
65
  response: FeedbackSubmissionResponse;
66
66
  payload: FeedbackSubmissionPayload;
67
67
  }) => void;
68
+ /**
69
+ * Fired after a user updates one of their own feedbacks.
70
+ */
71
+ onUpdated?: (event: {
72
+ response: FeedbackUpdateResponse;
73
+ payload: FeedbackUpdatePayload;
74
+ }) => void;
75
+ /**
76
+ * Fired after a user soft-deletes one of their own feedbacks.
77
+ */
78
+ onDeleted?: (event: {
79
+ response: FeedbackDeleteResponse;
80
+ id: number | string;
81
+ }) => void;
68
82
  /**
69
83
  * Fired when a feedback submission fails.
70
84
  */
@@ -3,13 +3,17 @@ import * as React from "react";
3
3
  import { ContextDropWidgetElement, registerContextDropWidget } from "../../app/javascript/context_drop/widget.js";
4
4
  export { ContextDropWidgetElement, registerContextDropWidget };
5
5
  export const ContextDrop = React.forwardRef(function ContextDrop(props, forwardedRef) {
6
- const { endpoint = "/context_drop", position, placeholder, theme, selectionMode, environment, metadata, config, credentials, headers, disabled = false, onSubmitted, onError, onOpenChange } = props;
6
+ const { endpoint = "/context_drop", position, placeholder, theme, selectionMode, environment, metadata, config, credentials, headers, disabled = false, onSubmitted, onUpdated, onDeleted, onError, onOpenChange } = props;
7
7
  const [mounted, setMounted] = React.useState(false);
8
8
  const elementRef = React.useRef(null);
9
9
  const onSubmittedRef = React.useRef(onSubmitted);
10
+ const onUpdatedRef = React.useRef(onUpdated);
11
+ const onDeletedRef = React.useRef(onDeleted);
10
12
  const onErrorRef = React.useRef(onError);
11
13
  const onOpenChangeRef = React.useRef(onOpenChange);
12
14
  onSubmittedRef.current = onSubmitted;
15
+ onUpdatedRef.current = onUpdated;
16
+ onDeletedRef.current = onDeleted;
13
17
  onErrorRef.current = onError;
14
18
  onOpenChangeRef.current = onOpenChange;
15
19
  React.useEffect(() => {
@@ -47,6 +51,18 @@ export const ContextDrop = React.forwardRef(function ContextDrop(props, forwarde
47
51
  onSubmittedRef.current(detail);
48
52
  }
49
53
  };
54
+ const handleUpdate = (ev) => {
55
+ const detail = ev.detail;
56
+ if (detail && onUpdatedRef.current) {
57
+ onUpdatedRef.current(detail);
58
+ }
59
+ };
60
+ const handleDelete = (ev) => {
61
+ const detail = ev.detail;
62
+ if (detail && onDeletedRef.current) {
63
+ onDeletedRef.current(detail);
64
+ }
65
+ };
50
66
  const handleError = (ev) => {
51
67
  const detail = ev.detail;
52
68
  if (detail && onErrorRef.current) {
@@ -60,11 +76,15 @@ export const ContextDrop = React.forwardRef(function ContextDrop(props, forwarde
60
76
  onOpenChangeRef.current?.(false);
61
77
  };
62
78
  el.addEventListener("context-drop:submit", handleSubmit);
79
+ el.addEventListener("context-drop:update", handleUpdate);
80
+ el.addEventListener("context-drop:delete", handleDelete);
63
81
  el.addEventListener("context-drop:error", handleError);
64
82
  el.addEventListener("context-drop:open", handleOpen);
65
83
  el.addEventListener("context-drop:close", handleClose);
66
84
  return () => {
67
85
  el.removeEventListener("context-drop:submit", handleSubmit);
86
+ el.removeEventListener("context-drop:update", handleUpdate);
87
+ el.removeEventListener("context-drop:delete", handleDelete);
68
88
  el.removeEventListener("context-drop:error", handleError);
69
89
  el.removeEventListener("context-drop:open", handleOpen);
70
90
  el.removeEventListener("context-drop:close", handleClose);
@@ -1,5 +1,8 @@
1
1
  import { type ContextDropServerConfig, type StorageAdapter } from "./types.js";
2
2
  export declare function isOriginExplicitlyAllowed(originHeader: string | null | undefined, allowedOrigins?: Array<string | RegExp>): boolean;
3
+ export declare function generateOwnershipToken(feedbackId: string | number, secret: Buffer): string;
4
+ export declare function verifyOwnershipToken(token: string | null | undefined, feedbackId: string | number, secret: Buffer): boolean;
5
+ export declare function extractVerifiedOwnershipIds(rawTokens: string, secret: Buffer): string[];
3
6
  export declare function defineContextDropConfig(config: ContextDropServerConfig): ContextDropServerConfig;
4
7
  export interface ContextDropFetchHandler {
5
8
  (request: Request): Promise<Response>;
@@ -13,12 +16,15 @@ export declare function createContextDropFetchHandler(config?: ContextDropServer
13
16
  * @example
14
17
  * ```ts
15
18
  * import { createContextDropNextHandler } from "context-drop/next/server";
16
- * export const { GET, POST, OPTIONS } = createContextDropNextHandler();
19
+ * export const { GET, POST, PATCH, PUT, DELETE, OPTIONS } = createContextDropNextHandler();
17
20
  * ```
18
21
  */
19
22
  export declare function createContextDropNextHandler(config?: ContextDropServerConfig): {
20
23
  GET: (request: Request) => Promise<Response>;
21
24
  POST: (request: Request) => Promise<Response>;
25
+ PATCH: (request: Request) => Promise<Response>;
26
+ PUT: (request: Request) => Promise<Response>;
27
+ DELETE: (request: Request) => Promise<Response>;
22
28
  OPTIONS: (request: Request) => Promise<Response>;
23
29
  handler: ContextDropFetchHandler;
24
30
  };