context-drop 0.2.0 → 0.3.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/README.md +6 -5
- package/app/assets/javascripts/context_drop/context_drop.js +1039 -26
- package/dist/app/javascript/context_drop/api-client.d.ts +13 -1
- package/dist/app/javascript/context_drop/api-client.js +192 -1
- package/dist/app/javascript/context_drop/icons.d.ts +2 -0
- package/dist/app/javascript/context_drop/icons.js +2 -0
- package/dist/app/javascript/context_drop/styles.d.ts +1 -1
- package/dist/app/javascript/context_drop/styles.js +181 -0
- package/dist/app/javascript/context_drop/types.d.ts +83 -6
- package/dist/app/javascript/context_drop/widget.d.ts +18 -0
- package/dist/app/javascript/context_drop/widget.js +550 -25
- package/dist/src/cli.js +1 -1
- package/dist/src/mcp/dispatcher.js +36 -10
- 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 +584 -81
- package/dist/src/server/storage/local.d.ts +1 -1
- package/dist/src/server/storage/local.js +261 -8
- package/dist/src/server/storage/memory.d.ts +4 -1
- package/dist/src/server/storage/memory.js +169 -3
- package/dist/src/server/storage/postgres.d.ts +1 -1
- package/dist/src/server/storage/postgres.js +189 -6
- package/dist/src/server/types.d.ts +38 -1
- package/dist/src/server/types.js +1 -1
- package/package.json +1 -1
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
|
}
|
|
@@ -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,
|
|
@@ -371,6 +381,7 @@ export class ContextDropMcpDispatcher {
|
|
|
371
381
|
const offset = Math.max(0, Number.isFinite(rawOffset) ? Math.trunc(rawOffset) : 0);
|
|
372
382
|
const pageUrl = String(args["page_url"] ?? "").trim() || null;
|
|
373
383
|
const query = String(args["query"] ?? "").trim() || null;
|
|
384
|
+
const includeDeleted = Boolean(args["include_deleted"]);
|
|
374
385
|
const requestedEnv = (String(args["environment"] ?? "").trim().toLowerCase()) || "all";
|
|
375
386
|
const remotes = this.router.getRemoteEnvironments();
|
|
376
387
|
const hostEnv = this.router.hostEnvironment;
|
|
@@ -381,7 +392,8 @@ export class ContextDropMcpDispatcher {
|
|
|
381
392
|
page_url: pageUrl,
|
|
382
393
|
query,
|
|
383
394
|
limit: fetchWindow,
|
|
384
|
-
offset: 0
|
|
395
|
+
offset: 0,
|
|
396
|
+
include_deleted: includeDeleted
|
|
385
397
|
});
|
|
386
398
|
const remoteEntries = Object.entries(remotes);
|
|
387
399
|
if (remoteEntries.length === 0) {
|
|
@@ -401,7 +413,8 @@ export class ContextDropMcpDispatcher {
|
|
|
401
413
|
page_url: pageUrl,
|
|
402
414
|
query,
|
|
403
415
|
limit: fetchWindow,
|
|
404
|
-
offset: 0
|
|
416
|
+
offset: 0,
|
|
417
|
+
include_deleted: includeDeleted
|
|
405
418
|
});
|
|
406
419
|
}
|
|
407
420
|
catch (err) {
|
|
@@ -441,7 +454,8 @@ export class ContextDropMcpDispatcher {
|
|
|
441
454
|
page_url: pageUrl,
|
|
442
455
|
query,
|
|
443
456
|
limit,
|
|
444
|
-
offset
|
|
457
|
+
offset,
|
|
458
|
+
include_deleted: includeDeleted
|
|
445
459
|
});
|
|
446
460
|
return successJsonTool({
|
|
447
461
|
environment: hostEnv,
|
|
@@ -459,7 +473,8 @@ export class ContextDropMcpDispatcher {
|
|
|
459
473
|
page_url: pageUrl,
|
|
460
474
|
query,
|
|
461
475
|
limit,
|
|
462
|
-
offset
|
|
476
|
+
offset,
|
|
477
|
+
include_deleted: includeDeleted
|
|
463
478
|
});
|
|
464
479
|
return successJsonTool({
|
|
465
480
|
environment: requestedEnv,
|
|
@@ -480,7 +495,8 @@ export class ContextDropMcpDispatcher {
|
|
|
480
495
|
page_url: pageUrl,
|
|
481
496
|
query,
|
|
482
497
|
limit,
|
|
483
|
-
offset
|
|
498
|
+
offset,
|
|
499
|
+
include_deleted: includeDeleted
|
|
484
500
|
});
|
|
485
501
|
if (fallbackRes.total > 0) {
|
|
486
502
|
return successJsonTool({
|
|
@@ -505,6 +521,8 @@ export class ContextDropMcpDispatcher {
|
|
|
505
521
|
remoteArgs["page_url"] = filter.page_url;
|
|
506
522
|
if (filter.query)
|
|
507
523
|
remoteArgs["query"] = filter.query;
|
|
524
|
+
if (filter.include_deleted)
|
|
525
|
+
remoteArgs["include_deleted"] = true;
|
|
508
526
|
const toolRes = await this.remoteClient.callTool(envName, cfg, "list_feedbacks", remoteArgs);
|
|
509
527
|
const textBlock = toolRes.content.find((b) => b.type === "text");
|
|
510
528
|
const parsed = textBlock?.text ? JSON.parse(textBlock.text) : {};
|
|
@@ -533,16 +551,17 @@ export class ContextDropMcpDispatcher {
|
|
|
533
551
|
return errorTool("Missing required parameter: id");
|
|
534
552
|
}
|
|
535
553
|
const includeImages = args["include_images"] !== undefined ? Boolean(args["include_images"]) : true;
|
|
554
|
+
const includeDeleted = Boolean(args["include_deleted"]);
|
|
536
555
|
const [targetEnv, feedbackId] = this.router.parseTarget(rawId, args["environment"]);
|
|
537
556
|
if (!this.router.isLocalTarget(targetEnv)) {
|
|
538
557
|
const remoteCfg = this.router.getRemoteConfig(targetEnv);
|
|
539
558
|
if (!remoteCfg || !targetEnv) {
|
|
540
559
|
return errorTool(`Unknown remote environment '${targetEnv}'`);
|
|
541
560
|
}
|
|
542
|
-
return this.fetchRemoteFeedback(targetEnv, remoteCfg, feedbackId, includeImages);
|
|
561
|
+
return this.fetchRemoteFeedback(targetEnv, remoteCfg, feedbackId, includeImages, includeDeleted);
|
|
543
562
|
}
|
|
544
563
|
const feedback = await this.storage.getFeedback(feedbackId);
|
|
545
|
-
if (!feedback) {
|
|
564
|
+
if (!feedback || (!includeDeleted && feedback.deleted_at)) {
|
|
546
565
|
return errorTool(`Feedback #${feedbackId} not found`);
|
|
547
566
|
}
|
|
548
567
|
const payload = serializeFullFeedback(feedback, this.router);
|
|
@@ -571,12 +590,15 @@ export class ContextDropMcpDispatcher {
|
|
|
571
590
|
isError: false
|
|
572
591
|
};
|
|
573
592
|
}
|
|
574
|
-
async fetchRemoteFeedback(envName, remoteCfg, feedbackId, includeImages) {
|
|
593
|
+
async fetchRemoteFeedback(envName, remoteCfg, feedbackId, includeImages, includeDeleted = false) {
|
|
575
594
|
try {
|
|
576
|
-
const
|
|
595
|
+
const remoteArgs = {
|
|
577
596
|
id: feedbackId,
|
|
578
597
|
include_images: includeImages
|
|
579
|
-
}
|
|
598
|
+
};
|
|
599
|
+
if (includeDeleted)
|
|
600
|
+
remoteArgs["include_deleted"] = true;
|
|
601
|
+
const res = await this.remoteClient.callTool(envName, remoteCfg, "get_feedback", remoteArgs);
|
|
580
602
|
if (res.isError)
|
|
581
603
|
return res;
|
|
582
604
|
const updatedBlocks = res.content.map((block) => {
|
|
@@ -623,6 +645,10 @@ export class ContextDropMcpDispatcher {
|
|
|
623
645
|
if (!found) {
|
|
624
646
|
return errorTool(`Attachment #${attId} not found`);
|
|
625
647
|
}
|
|
648
|
+
const parentFb = await this.storage.getFeedback(found.attachment.feedback_id);
|
|
649
|
+
if (parentFb?.deleted_at) {
|
|
650
|
+
return errorTool(`Attachment #${attId} not found`);
|
|
651
|
+
}
|
|
626
652
|
const envName = this.router.hostEnvironment;
|
|
627
653
|
const { attachment, element_selector, data } = found;
|
|
628
654
|
const metaPayload = {
|
package/dist/src/next/index.d.ts
CHANGED
|
@@ -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
|
*/
|
package/dist/src/react/index.js
CHANGED
|
@@ -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
|
};
|