context_drop 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/README.md +93 -25
- data/app/assets/javascripts/context_drop/context_drop.js +209 -59
- data/app/controllers/context_drop/configs_controller.rb +3 -1
- data/app/javascript/context_drop/__tests__/api-client.test.ts +310 -0
- data/app/javascript/context_drop/__tests__/widget.test.ts +499 -0
- data/app/javascript/context_drop/api-client.ts +153 -48
- data/app/javascript/context_drop/types.ts +1 -0
- data/app/javascript/context_drop/widget.ts +56 -11
- data/lib/context_drop/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8e85646e98e14b9d251eed6f1ec7ebca93d1139ce054423488256703b55d90f6
|
|
4
|
+
data.tar.gz: a548299755be327a69d04879210310c062c1bf843e7eb801afdf35bec5752b24
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 845dc9ae6803ed867276fffaa94324f8fc7ea7f5f526ed42f3c91bd9e2bd89dafbb45428b8a8b448bdac6d104220143354b5e46b26031f369de665d9f70347e5
|
|
7
|
+
data.tar.gz: e5e07b0ba1e732fa5a42752ea7385e513ae038484f0fd5c8895eb3f431cba1fb92a87e7dd2aa3bd5ee79bf1b6a1472a282cbca752b37a04e512619ff64057f03
|
data/README.md
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="docs/images/context-drop-hero.svg" alt="ContextDrop
|
|
2
|
+
<img src="docs/images/context-drop-hero.svg" alt="ContextDrop, Self-hosted contextual feedback engine, tactile DOM pin-drop widget, and IDE MCP server for Ruby on Rails" width="100%" />
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
|
-
<strong>Stop decoding vague bug reports
|
|
7
|
-
|
|
6
|
+
<strong>Stop decoding vague bug reports! Let users pin the problem with your Rails app</strong><br />
|
|
7
|
+
Mountable Rails Engine · Shadow DOM Widget · Overlapping Layer Picker · Active Storage · MCP Server
|
|
8
8
|
</p>
|
|
9
9
|
|
|
10
10
|
<p align="center">
|
|
11
|
-
<a href="
|
|
12
|
-
<a href="
|
|
13
|
-
<
|
|
14
|
-
<
|
|
11
|
+
<a href="https://rubygems.org/gems/context_drop"><img src="https://img.shields.io/gem/v/context_drop?label=RubyGems&color=2563eb" alt="Gem Version" /></a>
|
|
12
|
+
<a href="https://rubygems.org/gems/context_drop"><img src="https://img.shields.io/gem/dt/context_drop?label=Downloads&color=0f172a" alt="Gem Downloads" /></a>
|
|
13
|
+
<img src="https://img.shields.io/badge/Ruby-%3E%3D%203.1-CC342D?logo=ruby&logoColor=white" alt="Ruby >= 3.1" />
|
|
14
|
+
<img src="https://img.shields.io/badge/Rails-%3E%3D%207.1-D30001?logo=rubyonrails&logoColor=white" alt="Rails >= 7.1" />
|
|
15
|
+
<a href="MIT-LICENSE"><img src="https://img.shields.io/badge/License-MIT-16a34a" alt="MIT License" /></a>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
<p align="center">
|
|
19
|
+
<a href="https://rubygems.org/gems/context_drop">RubyGems</a> ·
|
|
20
|
+
<a href="#quickstart">Quickstart</a> ·
|
|
21
|
+
<a href="#interactive-playground">Live Demo</a> ·
|
|
22
|
+
<a href="#dom-pinning--layer-disambiguation">Layer Picker</a> ·
|
|
23
|
+
<a href="#mcp">MCP Server</a> ·
|
|
15
24
|
<a href="#zero-trust-privacy--redaction">Privacy & Redaction</a> ·
|
|
16
25
|
<a href="#configuration">Configuration</a>
|
|
17
26
|
</p>
|
|
@@ -22,7 +31,7 @@
|
|
|
22
31
|
|
|
23
32
|
When someone reports *"the button on the checkout card isn't working,"* engineers usually spend 20 minutes hunting down which view partial, feature flag, viewport width, or overlapping toast banner caused the problem.
|
|
24
33
|
|
|
25
|
-
**ContextDrop** (`context_drop`) embeds a tactile, zero-bleed **Shadow DOM feedback composer and DOM pin selector** directly into your Ruby on Rails application (`Rails >= 7.1`, including `Rails 8+`). Reporters click **Pin Element**, point at any UI component
|
|
34
|
+
**ContextDrop** (`context_drop`) embeds a tactile, zero-bleed **Shadow DOM feedback composer and DOM pin selector** directly into your Ruby on Rails application (`Rails >= 7.1`, including `Rails 8+`). Reporters click **Pin Element**, point at any UI component (even underneath floating badges or cascading overlays) attach a privacy-redacted screenshot, and send.
|
|
26
35
|
|
|
27
36
|
<p align="center">
|
|
28
37
|
<img src="docs/images/demo-pinning-layers.jpg" alt="ContextDrop Pin Mode highlighting an overlapping DOM layer with live dimensions and the Compact Pinning Bar" width="100%" />
|
|
@@ -84,6 +93,8 @@
|
|
|
84
93
|
|
|
85
94
|
### 1. Install the Gem & Run the Generator
|
|
86
95
|
|
|
96
|
+
Install [`context_drop` from RubyGems.org](https://rubygems.org/gems/context_drop) (or add `gem "context_drop"` to your `Gemfile`):
|
|
97
|
+
|
|
87
98
|
```bash
|
|
88
99
|
bundle add context_drop
|
|
89
100
|
bin/rails generate context_drop:install
|
|
@@ -183,7 +194,7 @@ Real-world Rails interfaces have sticky navbars, floating promo ribbons, translu
|
|
|
183
194
|
1. **Top-Left Pin Selector & Freely Draggable Dock:** Click **Pin Element** in the top-left corner of the chatbox (or from the floating dock). The chatbox collapses into the **Compact Pinning Bar** so it never blocks the page.
|
|
184
195
|
2. **Scroll-Wheel & Keyboard Depth Cycling:** While hovering any coordinate, roll your mouse wheel (`wheel`) or press `ArrowUp` / `ArrowDown` (`[` / `]`) to cycle through overlapping sibling layers (`document.elementsFromPoint`), child nodes, and parent containers while keeping a dashed ghost outline on the original leaf node.
|
|
185
196
|
3. **Click-to-Pick Layer Stack Popover:** Clicking a multi-layer spot anchors the pin and opens a Figma-style **Layer & Hierarchy Picker** displaying every candidate layer (`Topmost`, `Overlap`, `Child`, `Parent` badges with pixel dimensions) with live hover preview on the page. Hold `Shift+Click` or press `Enter` to pin immediately.
|
|
186
|
-
4. **Interactive DOM Breadcrumb Bar:** Both the Compact Pinning Bar and the Layer Popover render an interactive ancestor trail (`main.demo-shell > section#scenario > button`)
|
|
197
|
+
4. **Interactive DOM Breadcrumb Bar:** Both the Compact Pinning Bar and the Layer Popover render an interactive ancestor trail (`main.demo-shell > section#scenario > button`) hover any segment to preview or click to pin it directly.
|
|
187
198
|
5. **Capture-Phase Host Protection:** All `pointerdown`, `mousedown`, `mouseup`, `click`, and `wheel` events are intercepted in the capture phase during Pin Mode so underlying links, forms, and buttons are never triggered by mistake.
|
|
188
199
|
|
|
189
200
|
---
|
|
@@ -192,33 +203,88 @@ Real-world Rails interfaces have sticky navbars, floating promo ribbons, translu
|
|
|
192
203
|
|
|
193
204
|
ContextDrop ships with a built-in **Model Context Protocol (MCP)** server (`ContextDrop::MCP::Server`) so you or your AI coding agent can pull bug reports, inspect exact CSS selectors and DOM paths, view multimodal screenshots, and mark issues resolved without leaving your editor.
|
|
194
205
|
|
|
195
|
-
|
|
196
|
-
-
|
|
197
|
-
|
|
206
|
+
<p align="center">
|
|
207
|
+
<img src="docs/images/demo-mcp-agent.png" alt="ContextDrop MCP server tool calls (list_feedbacks and get_feedback) and root-cause diagnosis inside an AI coding agent" width="100%" />
|
|
208
|
+
</p>
|
|
209
|
+
|
|
210
|
+
> **Above:** Triage flow inside an AI coding agent connected to the `context-drop` MCP server on the live playground. The agent invokes `list_feedbacks` (`{ status: "new" }`) and `get_feedback` (`{ id: 12, include_images: true }`), inspects both the structured `ElementReference` geometry (`button#upgrade-cluster-btn`, `169.1×33px`) and the redacted multimodal `image/png` screenshot block, and pinpoints the exact overlapping CSS rule in `demo/index.html`.
|
|
198
211
|
|
|
199
|
-
###
|
|
212
|
+
### Exposed MCP Capabilities
|
|
200
213
|
|
|
201
|
-
|
|
214
|
+
| Type | Name / URI | Description |
|
|
215
|
+
|---|---|---|
|
|
216
|
+
| **Tool** | `list_feedbacks` | Filter & paginate submissions by `status` (`new`, `reviewed`, `resolved`, `dismissed`), `page_url`, or free-text `query` across messages, selectors, and DOM paths. |
|
|
217
|
+
| **Tool** | `get_feedback` | Fetch full `Feedback`, all `ElementReference` DOM snapshots, and inline base64 `image` blocks (`include_images: true` by default). |
|
|
218
|
+
| **Tool** | `get_feedback_attachment` | Retrieve an individual `Attachment` record and its binary screenshot/image as an MCP `image` content block. |
|
|
219
|
+
| **Tool** | `update_feedback_status` | Transition a feedback record between `new`, `reviewed`, `resolved`, and `dismissed`. |
|
|
220
|
+
| **Resource** | `contextdrop://feedbacks/new` | Live JSON feed of unresolved `new` feedback records (up to 50 most recent). |
|
|
221
|
+
| **Resource** | `contextdrop://feedbacks/{id}` | Full JSON snapshot of a specific feedback submission, its pinned elements, and attachment metadata. |
|
|
222
|
+
| **Prompt** | `investigate_feedback` | Generates a structured root-cause investigation brief (with attached screenshots) for a given `feedback_id`. |
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
### Option 1: Project-Scoped Local `stdio` (Inherited Shell Environment)
|
|
227
|
+
|
|
228
|
+
When using a workspace-scoped MCP file (e.g., `.mcp.json` in Claude Code or `.cursor/mcp.json` launched from a terminal) where your IDE already runs inside the Rails root and inherits your Ruby shell `PATH`:
|
|
202
229
|
|
|
203
230
|
```json
|
|
204
231
|
{
|
|
205
232
|
"mcpServers": {
|
|
206
233
|
"context-drop": {
|
|
207
|
-
"command": "
|
|
208
|
-
"args": ["context_drop:mcp"]
|
|
234
|
+
"command": "bundle",
|
|
235
|
+
"args": ["exec", "./bin/rails", "context_drop:mcp"]
|
|
209
236
|
}
|
|
210
237
|
}
|
|
211
238
|
}
|
|
212
239
|
```
|
|
213
240
|
|
|
214
|
-
### Option 2:
|
|
241
|
+
### Option 2: Strict Sandboxes, Global IDE Configs & Ruby Version Managers (`rbenv`, `mise`, `asdf`, `rvm`)
|
|
215
242
|
|
|
216
|
-
|
|
243
|
+
Strict sandboxed coding agents and GUI-launched desktop IDEs (such as **Antigravity** `mcp_config.json`, **Claude Desktop**, global `~/.cursor/mcp.json`, **Windsurf**, or VS Code launched from macOS Finder / Linux desktop) typically spawn MCP subprocesses with:
|
|
244
|
+
1. **A non-project working directory** (often `/` or `$HOME`, causing relative `./bin/rails` or `Gemfile` lookup to fail), and
|
|
245
|
+
2. **A stripped minimal `PATH`** (`/usr/bin:/bin:/usr/sbin:/sbin`) without sourcing `~/.zshrc` or `~/.bashrc`—causing `/usr/bin/env ruby` inside `bin/rails` to hit an outdated system Ruby (e.g., macOS Ruby `2.6`) or fail to locate `bundle` and Homebrew native libraries (`libpq`, `sqlite3`, `vips`).
|
|
246
|
+
|
|
247
|
+
To make `stdio` work reliably in strict sandboxes, wrap the launch command with `/bin/zsh -c` (or `/bin/bash -c` on Linux), `cd` into your Rails application root, `exec` your version manager's `bundle` binary directly, and declare an explicit absolute `PATH`:
|
|
217
248
|
|
|
218
249
|
```json
|
|
219
250
|
{
|
|
220
251
|
"mcpServers": {
|
|
221
|
-
"context-drop
|
|
252
|
+
"context-drop": {
|
|
253
|
+
"command": "/bin/zsh",
|
|
254
|
+
"args": [
|
|
255
|
+
"-c",
|
|
256
|
+
"cd /absolute/path/to/your-rails-app && exec /Users/<you>/.rbenv/shims/bundle exec ./bin/rails context_drop:mcp"
|
|
257
|
+
],
|
|
258
|
+
"env": {
|
|
259
|
+
"PATH": "/Users/<you>/.rbenv/shims:/Users/<you>/.rbenv/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
> [!TIP]
|
|
267
|
+
> **Adapting Option 2 to any machine or Ruby version manager:**
|
|
268
|
+
> - **Use literal absolute paths (avoid `~` or `$HOME` inside JSON `env`):** MCP hosts pass `env` directly to `execve` without shell expansion. Run `pwd`, `which bundle`, and `echo $PATH` in your Rails app terminal to get your exact paths.
|
|
269
|
+
> - **Keep `exec` before `bundle`:** `exec` replaces the `zsh`/`bash` wrapper in-place so `stdin`/`stdout` JSON-RPC frames remain unbuffered and IDE shutdown signals (`SIGTERM`) cleanly terminate the Ruby process without leaving orphans.
|
|
270
|
+
> - **Debug `stdio` boot issues:** Set `"CONTEXT_DROP_MCP_DEBUG": "1"` inside `"env"` to stream verbose Rails/ActiveRecord boot diagnostics to `stderr` (MCP `stdout` always stays strictly reserved for JSON-RPC frames).
|
|
271
|
+
|
|
272
|
+
| Ruby Environment / OS | `<bundle-path>` for `exec` | Directories to Prepend to `env.PATH` |
|
|
273
|
+
|---|---|---|
|
|
274
|
+
| **`rbenv`** (macOS / Linux) | `/Users/<you>/.rbenv/shims/bundle` | `/Users/<you>/.rbenv/shims:/Users/<you>/.rbenv/bin` |
|
|
275
|
+
| **`mise`** (macOS / Linux) | `/Users/<you>/.local/share/mise/shims/bundle` | `/Users/<you>/.local/share/mise/shims` |
|
|
276
|
+
| **`asdf`** (macOS / Linux) | `/Users/<you>/.asdf/shims/bundle` | `/Users/<you>/.asdf/shims:/Users/<you>/.asdf/bin` |
|
|
277
|
+
| **`rvm`** (macOS / Linux) | `/Users/<you>/.rvm/wrappers/default/bundle` | `/Users/<you>/.rvm/gems/default/bin:/Users/<you>/.rvm/bin` |
|
|
278
|
+
| **Homebrew / Linux `/usr/local`** | `/opt/homebrew/opt/ruby/bin/bundle` or `/usr/local/bin/bundle` | `/opt/homebrew/opt/ruby/bin:/opt/homebrew/bin:/usr/local/bin` |
|
|
279
|
+
|
|
280
|
+
### Option 3: Streamable HTTP Transport (Docker, Isolated Sandboxes, Staging & Production)
|
|
281
|
+
|
|
282
|
+
If your Rails app runs inside **Docker / Devcontainers**, if your agent sandbox blocks host binary execution outside the workspace, or if you want to triage feedback directly from **staging or production**, enable the HTTP endpoint with a bearer token (`CONTEXT_DROP_MCP_ENABLED=true` and `CONTEXT_DROP_MCP_API_KEY=<your-secret-token>`) and point your MCP client to `POST /context_drop/mcp`:
|
|
283
|
+
|
|
284
|
+
```json
|
|
285
|
+
{
|
|
286
|
+
"mcpServers": {
|
|
287
|
+
"context-drop-http": {
|
|
222
288
|
"url": "https://staging.example.com/context_drop/mcp",
|
|
223
289
|
"headers": {
|
|
224
290
|
"Authorization": "Bearer <your-secret-token>"
|
|
@@ -228,8 +294,10 @@ Enable MCP on your staging or production server with a bearer token (`CONTEXT_DR
|
|
|
228
294
|
}
|
|
229
295
|
```
|
|
230
296
|
|
|
297
|
+
*(For local Docker or strict-sandbox setups, use `"url": "http://localhost:3000/context_drop/mcp"` against your running `bin/rails server`.)*
|
|
298
|
+
|
|
231
299
|
Once connected, prompt your coding agent directly in your IDE:
|
|
232
|
-
> *"
|
|
300
|
+
> *"Check the `context-drop` MCP server for new feedbacks, inspect the pinned element selector and screenshot, diagnose the root cause in our Rails views/CSS, and mark the feedback resolved."*
|
|
233
301
|
|
|
234
302
|
---
|
|
235
303
|
|
|
@@ -250,13 +318,13 @@ ContextDrop is engineered for production environments where customer privacy and
|
|
|
250
318
|
|
|
251
319
|
---
|
|
252
320
|
|
|
253
|
-
##
|
|
321
|
+
## Triage Dashboard
|
|
254
322
|
|
|
255
|
-
ContextDrop includes a
|
|
323
|
+
ContextDrop includes a triage interface mounted inside your Rails application at `/context_drop/dashboard/feedbacks`:
|
|
256
324
|
|
|
257
325
|
- **Filter & Search:** Filter submissions by status (`new`, `reviewed`, `resolved`, `dismissed`), originating `page_url`, or free-text query across messages, CSS selectors, and DOM paths.
|
|
258
|
-
- **Inspect
|
|
259
|
-
- **
|
|
326
|
+
- **Inspect Context:** View submitter attribution, browser/viewport metadata, inline Active Storage screenshot galleries, and structured `ElementReference` cards (`selector`, `dom_path`, `bounding_rect`, `attributes_snapshot`).
|
|
327
|
+
- **Triage Actions:** Transition feedback status between `Mark Reviewed`, `Mark Resolved`, and `Dismiss`.
|
|
260
328
|
|
|
261
329
|
---
|
|
262
330
|
|
|
@@ -275,7 +343,7 @@ ContextDrop.configure do |config|
|
|
|
275
343
|
# Allow unauthenticated visitors to submit feedback
|
|
276
344
|
config.allow_anonymous = true
|
|
277
345
|
|
|
278
|
-
# Polymorphic submitter attribution
|
|
346
|
+
# Polymorphic submitter attribution, return any ActiveRecord model (User, Employee, AdminUser) or nil
|
|
279
347
|
config.current_submitter = ->(controller) { controller.try(:current_user) }
|
|
280
348
|
|
|
281
349
|
# Authorization hooks
|
|
@@ -1157,83 +1157,188 @@
|
|
|
1157
1157
|
// --- Module: api-client.ts ---
|
|
1158
1158
|
class ContextDropApiClient {
|
|
1159
1159
|
baseUrl ;
|
|
1160
|
+
cachedCsrfToken = null;
|
|
1161
|
+
inFlightConfigPromise = null;
|
|
1160
1162
|
|
|
1161
1163
|
constructor(baseUrl = "/context_drop") {
|
|
1162
1164
|
this.baseUrl = baseUrl.replace(/\/+$/, "") || "/context_drop";
|
|
1163
1165
|
}
|
|
1164
1166
|
|
|
1165
1167
|
getCsrfToken() {
|
|
1168
|
+
const metaToken = this.getMetaCsrfToken();
|
|
1169
|
+
if (metaToken) {
|
|
1170
|
+
return metaToken;
|
|
1171
|
+
}
|
|
1172
|
+
return this.cachedCsrfToken;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
setCsrfToken(token ) {
|
|
1176
|
+
this.cachedCsrfToken = token ? token.trim() : null;
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
getMetaCsrfToken() {
|
|
1166
1180
|
if (typeof document === "undefined") return null;
|
|
1167
1181
|
const meta = document.querySelector('meta[name="csrf-token"]');
|
|
1168
|
-
|
|
1182
|
+
const content = meta ? meta.getAttribute("content") : null;
|
|
1183
|
+
return content && content.trim().length > 0 ? content.trim() : null;
|
|
1169
1184
|
}
|
|
1170
1185
|
|
|
1171
1186
|
async fetchConfig() {
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1187
|
+
if (this.inFlightConfigPromise) {
|
|
1188
|
+
return this.inFlightConfigPromise;
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
this.inFlightConfigPromise = (async () => {
|
|
1192
|
+
try {
|
|
1193
|
+
const response = await fetch(`${this.baseUrl}/config`, {
|
|
1194
|
+
method: "GET",
|
|
1195
|
+
credentials: "same-origin",
|
|
1196
|
+
headers: {
|
|
1197
|
+
Accept: "application/json"
|
|
1198
|
+
}
|
|
1199
|
+
});
|
|
1200
|
+
|
|
1201
|
+
if (!response.ok) {
|
|
1202
|
+
throw new Error(`Failed to fetch ContextDrop config (${response.status})`);
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
const config = (await response.json()) ;
|
|
1206
|
+
if (config && typeof config.csrf_token === "string" && config.csrf_token.trim().length > 0) {
|
|
1207
|
+
this.cachedCsrfToken = config.csrf_token.trim();
|
|
1208
|
+
if (typeof document !== "undefined") {
|
|
1209
|
+
const meta = document.querySelector('meta[name="csrf-token"]');
|
|
1210
|
+
if (meta) {
|
|
1211
|
+
meta.setAttribute("content", this.cachedCsrfToken);
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
return config;
|
|
1216
|
+
} finally {
|
|
1217
|
+
this.inFlightConfigPromise = null;
|
|
1177
1218
|
}
|
|
1178
|
-
});
|
|
1219
|
+
})();
|
|
1220
|
+
|
|
1221
|
+
return this.inFlightConfigPromise;
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
async resolveCsrfToken(forceRefresh = false) {
|
|
1225
|
+
if (!forceRefresh) {
|
|
1226
|
+
const metaToken = this.getMetaCsrfToken();
|
|
1227
|
+
if (metaToken) {
|
|
1228
|
+
return metaToken;
|
|
1229
|
+
}
|
|
1230
|
+
if (this.cachedCsrfToken) {
|
|
1231
|
+
return this.cachedCsrfToken;
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1179
1234
|
|
|
1180
|
-
|
|
1181
|
-
|
|
1235
|
+
try {
|
|
1236
|
+
const config = await this.fetchConfig();
|
|
1237
|
+
if (config && config.csrf_token) {
|
|
1238
|
+
return config.csrf_token.trim();
|
|
1239
|
+
}
|
|
1240
|
+
} catch {
|
|
1241
|
+
// Continue and fall back to current token or null
|
|
1182
1242
|
}
|
|
1183
1243
|
|
|
1184
|
-
return
|
|
1244
|
+
return this.cachedCsrfToken || this.getMetaCsrfToken();
|
|
1185
1245
|
}
|
|
1186
1246
|
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1247
|
+
isCsrfError(status , message ) {
|
|
1248
|
+
if (status !== 422) return false;
|
|
1249
|
+
return /csrf|authenticity/i.test(message);
|
|
1250
|
+
}
|
|
1190
1251
|
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1252
|
+
async executeWithCsrfRetry (
|
|
1253
|
+
requestFn ,
|
|
1254
|
+
defaultErrorMessage
|
|
1255
|
+
) {
|
|
1256
|
+
let csrfToken = await this.resolveCsrfToken(false);
|
|
1257
|
+
let response = await requestFn(csrfToken);
|
|
1258
|
+
|
|
1259
|
+
if (response.ok) {
|
|
1260
|
+
return (await response.json()) ;
|
|
1197
1261
|
}
|
|
1198
1262
|
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1263
|
+
if (response.status === 422) {
|
|
1264
|
+
const rawText = await response.text();
|
|
1265
|
+
let parsedError = null;
|
|
1266
|
+
try {
|
|
1267
|
+
const json = JSON.parse(rawText) ;
|
|
1268
|
+
if (json && typeof json.error === "string") {
|
|
1269
|
+
parsedError = json.error;
|
|
1270
|
+
}
|
|
1271
|
+
} catch {
|
|
1272
|
+
// Not JSON
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
const errorMessage = parsedError || rawText || "";
|
|
1276
|
+
const shouldRetryCsrf =
|
|
1277
|
+
this.isCsrfError(response.status, errorMessage) || (!csrfToken && response.status === 422);
|
|
1205
1278
|
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1279
|
+
if (shouldRetryCsrf) {
|
|
1280
|
+
csrfToken = await this.resolveCsrfToken(true);
|
|
1281
|
+
response = await requestFn(csrfToken);
|
|
1282
|
+
if (response.ok) {
|
|
1283
|
+
return (await response.json()) ;
|
|
1284
|
+
}
|
|
1285
|
+
const retryErrBody = await response.json().catch(() => ({}));
|
|
1286
|
+
throw new Error(
|
|
1287
|
+
(retryErrBody ).error || `${defaultErrorMessage} (${response.status})`
|
|
1288
|
+
);
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
throw new Error(parsedError || errorMessage || `${defaultErrorMessage} (${response.status})`);
|
|
1209
1292
|
}
|
|
1210
1293
|
|
|
1211
|
-
|
|
1294
|
+
const errBody = await response.json().catch(() => ({}));
|
|
1295
|
+
throw new Error(
|
|
1296
|
+
(errBody ).error || `${defaultErrorMessage} (${response.status})`
|
|
1297
|
+
);
|
|
1212
1298
|
}
|
|
1213
1299
|
|
|
1214
|
-
async
|
|
1215
|
-
const
|
|
1216
|
-
|
|
1217
|
-
|
|
1300
|
+
async uploadAttachment(file , filename ) {
|
|
1301
|
+
const makeRequest = async (csrfToken ) => {
|
|
1302
|
+
const formData = new FormData();
|
|
1303
|
+
formData.append("file", file, filename);
|
|
1304
|
+
|
|
1305
|
+
const headers = {
|
|
1306
|
+
Accept: "application/json"
|
|
1307
|
+
};
|
|
1308
|
+
if (csrfToken) {
|
|
1309
|
+
headers["X-CSRF-Token"] = csrfToken;
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
return fetch(`${this.baseUrl}/attachments`, {
|
|
1313
|
+
method: "POST",
|
|
1314
|
+
credentials: "same-origin",
|
|
1315
|
+
headers,
|
|
1316
|
+
body: formData
|
|
1317
|
+
});
|
|
1218
1318
|
};
|
|
1219
|
-
const csrf = this.getCsrfToken();
|
|
1220
|
-
if (csrf) {
|
|
1221
|
-
headers["X-CSRF-Token"] = csrf;
|
|
1222
|
-
}
|
|
1223
1319
|
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
credentials: "same-origin",
|
|
1227
|
-
headers,
|
|
1228
|
-
body: JSON.stringify({ feedback: payload })
|
|
1229
|
-
});
|
|
1320
|
+
return this.executeWithCsrfRetry(makeRequest, "Upload failed");
|
|
1321
|
+
}
|
|
1230
1322
|
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1323
|
+
async submitFeedback(payload ) {
|
|
1324
|
+
const makeRequest = async (csrfToken ) => {
|
|
1325
|
+
const headers = {
|
|
1326
|
+
"Content-Type": "application/json",
|
|
1327
|
+
Accept: "application/json"
|
|
1328
|
+
};
|
|
1329
|
+
if (csrfToken) {
|
|
1330
|
+
headers["X-CSRF-Token"] = csrfToken;
|
|
1331
|
+
}
|
|
1235
1332
|
|
|
1236
|
-
|
|
1333
|
+
return fetch(`${this.baseUrl}/feedback`, {
|
|
1334
|
+
method: "POST",
|
|
1335
|
+
credentials: "same-origin",
|
|
1336
|
+
headers,
|
|
1337
|
+
body: JSON.stringify({ feedback: payload })
|
|
1338
|
+
});
|
|
1339
|
+
};
|
|
1340
|
+
|
|
1341
|
+
return this.executeWithCsrfRetry(makeRequest, "Submission failed");
|
|
1237
1342
|
}
|
|
1238
1343
|
}
|
|
1239
1344
|
|
|
@@ -2646,6 +2751,9 @@
|
|
|
2646
2751
|
limits: { ...this.config.limits, ...(parsed.limits || {}) },
|
|
2647
2752
|
privacy: { ...this.config.privacy, ...(parsed.privacy || {}) }
|
|
2648
2753
|
};
|
|
2754
|
+
if (parsed.csrf_token) {
|
|
2755
|
+
this.apiClient.setCsrfToken(parsed.csrf_token);
|
|
2756
|
+
}
|
|
2649
2757
|
} catch {
|
|
2650
2758
|
// Ignore malformed JSON attribute
|
|
2651
2759
|
}
|
|
@@ -2681,6 +2789,28 @@
|
|
|
2681
2789
|
let initialTop = 0;
|
|
2682
2790
|
let dragging = false;
|
|
2683
2791
|
let moved = false;
|
|
2792
|
+
let suppressNextClick = false;
|
|
2793
|
+
let suppressClickTimer = null;
|
|
2794
|
+
|
|
2795
|
+
const clearSuppressClick = () => {
|
|
2796
|
+
suppressNextClick = false;
|
|
2797
|
+
if (suppressClickTimer !== null) {
|
|
2798
|
+
clearTimeout(suppressClickTimer);
|
|
2799
|
+
suppressClickTimer = null;
|
|
2800
|
+
}
|
|
2801
|
+
};
|
|
2802
|
+
|
|
2803
|
+
if (onClickFallback) {
|
|
2804
|
+
handleEl.addEventListener("click", (ev ) => {
|
|
2805
|
+
if (suppressNextClick) {
|
|
2806
|
+
clearSuppressClick();
|
|
2807
|
+
ev.preventDefault();
|
|
2808
|
+
ev.stopPropagation();
|
|
2809
|
+
return;
|
|
2810
|
+
}
|
|
2811
|
+
onClickFallback();
|
|
2812
|
+
});
|
|
2813
|
+
}
|
|
2684
2814
|
|
|
2685
2815
|
const onPointerMove = (ev ) => {
|
|
2686
2816
|
if (!dragging) return;
|
|
@@ -2695,30 +2825,48 @@
|
|
|
2695
2825
|
}
|
|
2696
2826
|
};
|
|
2697
2827
|
|
|
2698
|
-
const
|
|
2699
|
-
if (!dragging) return;
|
|
2828
|
+
const cleanupDrag = () => {
|
|
2700
2829
|
dragging = false;
|
|
2701
2830
|
this.pinDockEl?.classList.remove("is-dragging");
|
|
2702
2831
|
window.removeEventListener("pointermove", onPointerMove);
|
|
2703
2832
|
window.removeEventListener("pointerup", onPointerUp);
|
|
2704
|
-
|
|
2705
|
-
|
|
2833
|
+
window.removeEventListener("pointercancel", onPointerCancel);
|
|
2834
|
+
};
|
|
2835
|
+
|
|
2836
|
+
const onPointerUp = () => {
|
|
2837
|
+
if (!dragging) return;
|
|
2838
|
+
cleanupDrag();
|
|
2839
|
+
if (moved && onClickFallback) {
|
|
2840
|
+
suppressNextClick = true;
|
|
2841
|
+
if (suppressClickTimer !== null) {
|
|
2842
|
+
clearTimeout(suppressClickTimer);
|
|
2843
|
+
}
|
|
2844
|
+
suppressClickTimer = setTimeout(() => {
|
|
2845
|
+
suppressNextClick = false;
|
|
2846
|
+
suppressClickTimer = null;
|
|
2847
|
+
}, 0);
|
|
2706
2848
|
}
|
|
2707
2849
|
};
|
|
2708
2850
|
|
|
2851
|
+
const onPointerCancel = () => {
|
|
2852
|
+
if (!dragging) return;
|
|
2853
|
+
cleanupDrag();
|
|
2854
|
+
clearSuppressClick();
|
|
2855
|
+
};
|
|
2856
|
+
|
|
2709
2857
|
handleEl.addEventListener("pointerdown", (ev ) => {
|
|
2710
2858
|
// Only primary mouse button or touch
|
|
2711
2859
|
if (ev.button !== 0) return;
|
|
2712
|
-
const targetEl =
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
) {
|
|
2860
|
+
const targetEl =
|
|
2861
|
+
ev.target && typeof (ev.target ).closest === "function"
|
|
2862
|
+
? (ev.target )
|
|
2863
|
+
: null;
|
|
2864
|
+
const closestBtn = targetEl?.closest("button");
|
|
2865
|
+
if (closestBtn && closestBtn !== handleEl && handleEl.contains(closestBtn)) {
|
|
2718
2866
|
return;
|
|
2719
2867
|
}
|
|
2720
2868
|
|
|
2721
|
-
if (!this.rootContainer) return;
|
|
2869
|
+
if (!this.rootContainer || typeof window === "undefined") return;
|
|
2722
2870
|
const rect = this.rootContainer.getBoundingClientRect();
|
|
2723
2871
|
startX = ev.clientX;
|
|
2724
2872
|
startY = ev.clientY;
|
|
@@ -2726,9 +2874,11 @@
|
|
|
2726
2874
|
initialTop = this.freePos ? this.freePos.top : rect.top;
|
|
2727
2875
|
dragging = true;
|
|
2728
2876
|
moved = false;
|
|
2877
|
+
clearSuppressClick();
|
|
2729
2878
|
|
|
2730
2879
|
window.addEventListener("pointermove", onPointerMove);
|
|
2731
2880
|
window.addEventListener("pointerup", onPointerUp);
|
|
2881
|
+
window.addEventListener("pointercancel", onPointerCancel);
|
|
2732
2882
|
});
|
|
2733
2883
|
}
|
|
2734
2884
|
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
module ContextDrop
|
|
4
4
|
class ConfigsController < ApplicationController
|
|
5
|
+
skip_forgery_protection only: [:widget_bundle] if respond_to?(:skip_forgery_protection)
|
|
5
6
|
before_action :enforce_submission_authorization!, only: [:show]
|
|
6
7
|
|
|
7
8
|
def show
|
|
8
|
-
|
|
9
|
+
token = form_authenticity_token if respond_to?(:form_authenticity_token, true)
|
|
10
|
+
render json: ContextDrop.config.public_widget_config.merge(csrf_token: token), status: :ok
|
|
9
11
|
end
|
|
10
12
|
|
|
11
13
|
def widget_bundle
|