hooktrace 0.1.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.
@@ -0,0 +1,358 @@
1
+ :root {
2
+ --bg: #0b1120;
3
+ --card-bg: #1e293b;
4
+ --card-border: #334155;
5
+ --text: #f8fafc;
6
+ --text-muted: #94a3b8;
7
+ --primary: #38bdf8;
8
+ --primary-hover: #0284c7;
9
+ --green: #34d399;
10
+ --green-bg: #064e3b;
11
+ --red: #f87171;
12
+ --red-bg: #7f1d1d;
13
+ --code-bg: #0f172a;
14
+ }
15
+
16
+ * {
17
+ box-sizing: border-box;
18
+ margin: 0;
19
+ padding: 0;
20
+ }
21
+
22
+ body {
23
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
24
+ background: var(--bg);
25
+ color: var(--text);
26
+ line-height: 1.5;
27
+ min-height: 100vh;
28
+ }
29
+
30
+ .navbar {
31
+ background: #0f172a;
32
+ border-bottom: 1px solid var(--card-border);
33
+ padding: 14px 24px;
34
+ display: flex;
35
+ justify-content: space-between;
36
+ align-items: center;
37
+ position: sticky;
38
+ top: 0;
39
+ z-index: 100;
40
+ }
41
+
42
+ .nav-brand {
43
+ font-size: 18px;
44
+ font-weight: 700;
45
+ color: var(--primary);
46
+ text-decoration: none;
47
+ display: flex;
48
+ align-items: center;
49
+ gap: 8px;
50
+ }
51
+
52
+ .nav-brand span {
53
+ font-size: 11px;
54
+ background: #334155;
55
+ color: #cbd5e1;
56
+ padding: 2px 6px;
57
+ border-radius: 4px;
58
+ font-weight: 500;
59
+ }
60
+
61
+ .nav-links {
62
+ display: flex;
63
+ gap: 16px;
64
+ align-items: center;
65
+ }
66
+
67
+ .nav-links a {
68
+ color: var(--text-muted);
69
+ text-decoration: none;
70
+ font-size: 14px;
71
+ font-weight: 500;
72
+ padding: 6px 12px;
73
+ border-radius: 6px;
74
+ transition: all 0.15s;
75
+ }
76
+
77
+ .nav-links a:hover,
78
+ .nav-links a.active {
79
+ color: var(--text);
80
+ background: var(--card-bg);
81
+ }
82
+
83
+ .container {
84
+ max-width: 1200px;
85
+ margin: 30px auto;
86
+ padding: 0 20px;
87
+ }
88
+
89
+ .stats-grid {
90
+ display: grid;
91
+ grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
92
+ gap: 16px;
93
+ margin-bottom: 24px;
94
+ }
95
+
96
+ .stat-card {
97
+ background: var(--card-bg);
98
+ border: 1px solid var(--card-border);
99
+ border-radius: 8px;
100
+ padding: 16px;
101
+ }
102
+
103
+ .stat-title {
104
+ font-size: 12px;
105
+ font-weight: 600;
106
+ text-transform: uppercase;
107
+ color: var(--text-muted);
108
+ letter-spacing: 0.5px;
109
+ }
110
+
111
+ .stat-value {
112
+ font-size: 28px;
113
+ font-weight: 700;
114
+ margin-top: 4px;
115
+ color: var(--text);
116
+ }
117
+
118
+ .stat-value.ok {
119
+ color: var(--green);
120
+ }
121
+
122
+ .stat-value.err {
123
+ color: var(--red);
124
+ }
125
+
126
+ .card {
127
+ background: var(--card-bg);
128
+ border: 1px solid var(--card-border);
129
+ border-radius: 8px;
130
+ overflow: hidden;
131
+ margin-bottom: 24px;
132
+ }
133
+
134
+ .card-header {
135
+ padding: 16px 20px;
136
+ border-bottom: 1px solid var(--card-border);
137
+ display: flex;
138
+ justify-content: space-between;
139
+ align-items: center;
140
+ }
141
+
142
+ .card-title {
143
+ font-size: 16px;
144
+ font-weight: 600;
145
+ color: var(--text);
146
+ }
147
+
148
+ .badge {
149
+ display: inline-flex;
150
+ align-items: center;
151
+ gap: 4px;
152
+ padding: 3px 10px;
153
+ border-radius: 12px;
154
+ font-size: 12px;
155
+ font-weight: 600;
156
+ }
157
+
158
+ .badge-ok {
159
+ background: var(--green-bg);
160
+ color: var(--green);
161
+ border: 1px solid rgba(52, 211, 153, 0.3);
162
+ }
163
+
164
+ .badge-err {
165
+ background: var(--red-bg);
166
+ color: var(--red);
167
+ border: 1px solid rgba(248, 113, 113, 0.3);
168
+ }
169
+
170
+ .badge-neutral {
171
+ background: #334155;
172
+ color: #cbd5e1;
173
+ }
174
+
175
+ table {
176
+ width: 100%;
177
+ border-collapse: collapse;
178
+ font-size: 14px;
179
+ text-align: left;
180
+ }
181
+
182
+ th {
183
+ background: #131c31;
184
+ color: var(--text-muted);
185
+ font-weight: 600;
186
+ padding: 12px 16px;
187
+ border-bottom: 1px solid var(--card-border);
188
+ font-size: 12px;
189
+ text-transform: uppercase;
190
+ }
191
+
192
+ td {
193
+ padding: 14px 16px;
194
+ border-bottom: 1px solid rgba(51, 65, 85, 0.6);
195
+ vertical-align: middle;
196
+ }
197
+
198
+ tr:hover td {
199
+ background: rgba(51, 65, 85, 0.3);
200
+ }
201
+
202
+ a.row-link {
203
+ color: var(--primary);
204
+ text-decoration: none;
205
+ font-weight: 500;
206
+ }
207
+
208
+ a.row-link:hover {
209
+ text-decoration: underline;
210
+ }
211
+
212
+ .btn {
213
+ background: var(--primary);
214
+ color: #0b1120;
215
+ font-weight: 600;
216
+ padding: 8px 14px;
217
+ border-radius: 6px;
218
+ text-decoration: none;
219
+ border: none;
220
+ cursor: pointer;
221
+ font-size: 13px;
222
+ display: inline-flex;
223
+ align-items: center;
224
+ gap: 6px;
225
+ }
226
+
227
+ .btn:hover {
228
+ background: #7dd3fc;
229
+ }
230
+
231
+ .btn-sm {
232
+ padding: 4px 10px;
233
+ font-size: 12px;
234
+ }
235
+
236
+ .btn:disabled {
237
+ opacity: 0.7;
238
+ cursor: wait;
239
+ }
240
+
241
+ .spinner {
242
+ width: 12px;
243
+ height: 12px;
244
+ border: 2px solid rgba(11, 17, 32, 0.25);
245
+ border-top-color: #0b1120;
246
+ border-radius: 50%;
247
+ display: inline-block;
248
+ animation: hooktrace-spin 0.7s linear infinite;
249
+ }
250
+
251
+ @keyframes hooktrace-spin {
252
+ to {
253
+ transform: rotate(360deg);
254
+ }
255
+ }
256
+
257
+ .api-banner {
258
+ background: var(--card-bg);
259
+ border: 1px solid var(--card-border);
260
+ border-left: 4px solid var(--primary);
261
+ border-radius: 8px;
262
+ padding: 14px 16px;
263
+ margin-bottom: 20px;
264
+ }
265
+
266
+ .api-banner-ok {
267
+ border-left-color: var(--green);
268
+ }
269
+
270
+ .api-banner-err {
271
+ border-left-color: var(--red);
272
+ }
273
+
274
+ .api-banner-head {
275
+ display: flex;
276
+ justify-content: space-between;
277
+ align-items: center;
278
+ gap: 12px;
279
+ }
280
+
281
+ .api-banner-meta {
282
+ font-size: 13px;
283
+ color: var(--text-muted);
284
+ margin-top: 4px;
285
+ }
286
+
287
+ .api-banner pre {
288
+ margin-top: 10px;
289
+ max-height: 220px;
290
+ font-size: 12px;
291
+ }
292
+
293
+ .btn-danger {
294
+ background: #ef4444;
295
+ color: white;
296
+ }
297
+
298
+ .btn-danger:hover {
299
+ background: #dc2626;
300
+ }
301
+
302
+ .btn-outline {
303
+ background: transparent;
304
+ color: var(--text-muted);
305
+ border: 1px solid var(--card-border);
306
+ }
307
+
308
+ .btn-outline:hover {
309
+ color: var(--text);
310
+ background: var(--card-bg);
311
+ }
312
+
313
+ pre {
314
+ background: var(--code-bg);
315
+ padding: 16px;
316
+ border-radius: 6px;
317
+ overflow-x: auto;
318
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
319
+ font-size: 13px;
320
+ line-height: 1.5;
321
+ color: #cbd5e1;
322
+ border: 1px solid var(--card-border);
323
+ }
324
+
325
+ code {
326
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
327
+ background: rgba(51, 65, 85, 0.5);
328
+ padding: 2px 6px;
329
+ border-radius: 4px;
330
+ font-size: 12px;
331
+ }
332
+
333
+ .empty-state {
334
+ text-align: center;
335
+ padding: 48px 20px;
336
+ color: var(--text-muted);
337
+ }
338
+
339
+ .filter-bar {
340
+ display: flex;
341
+ gap: 10px;
342
+ align-items: center;
343
+ }
344
+
345
+ .filter-bar select {
346
+ background: #0f172a;
347
+ border: 1px solid var(--card-border);
348
+ color: var(--text);
349
+ padding: 6px 12px;
350
+ border-radius: 6px;
351
+ font-size: 13px;
352
+ outline: none;
353
+ }
354
+
355
+ .hidden {
356
+ display: none;
357
+ }
358
+
@@ -0,0 +1,41 @@
1
+ <div class="card">
2
+ <div class="card-header">
3
+ <div class="card-title">Active Registered Contracts (<%= contracts.size %>)</div>
4
+ </div>
5
+
6
+ <% if contracts.empty? %>
7
+ <div class="empty-state">
8
+ <p>No contracts registered yet.</p>
9
+ <p style="margin-top: 8px; font-size: 13px;">
10
+ Define contracts using <code>Hooktrace.define</code> or load JSON files with <code>Hooktrace.load_contracts_from</code>.
11
+ </p>
12
+ </div>
13
+ <% else %>
14
+ <% contracts.each do |contract| %>
15
+ <% dom_id = "raw-#{contract.name.gsub(/[^a-z0-9]/i, "_")}" %>
16
+ <div style="border-bottom: 1px solid var(--card-border); padding: 20px;">
17
+ <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px;">
18
+ <div style="display: flex; align-items: center; gap: 10px;">
19
+ <span style="font-size: 16px; font-weight: 700; color: var(--primary);"><%= h(contract.name) %></span>
20
+ <span class="badge badge-neutral"><%= contract.fields.size %> root fields</span>
21
+ </div>
22
+ <button
23
+ class="btn btn-outline"
24
+ style="padding: 4px 10px; font-size: 12px;"
25
+ onclick="document.getElementById('<%= dom_id %>').classList.toggle('hidden')"
26
+ >
27
+ Toggle JSON
28
+ </button>
29
+ </div>
30
+ <div style="font-size: 13px; color: var(--text-muted); margin-bottom: 12px;">
31
+ Fields:
32
+ <%= contract.fields.map { |f| "<code>#{h(f.name)}</code> (#{h(f.type)}#{", required" if f.required?})" }.join(", ") %>
33
+ </div>
34
+ <div id="<%= dom_id %>" class="hidden" style="margin-top: 10px;">
35
+ <pre><%= h(JSON.pretty_generate(contract.to_h)) %></pre>
36
+ </div>
37
+ </div>
38
+ <% end %>
39
+ <% end %>
40
+ </div>
41
+
@@ -0,0 +1,53 @@
1
+ <div style="margin-bottom: 16px;">
2
+ <a href="<%= base_path %>/events" style="color: var(--primary); text-decoration: none; font-size: 14px;">&larr; Back to Events</a>
3
+ </div>
4
+
5
+ <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
6
+ <div>
7
+ <h1 style="font-size: 24px; font-weight: 700; display: flex; align-items: center; gap: 12px;">
8
+ <span><%= h(event.event_type) %></span>
9
+ <span id="event-detail-badge" class="badge <%= event.valid? ? "badge-ok" : "badge-err" %>">
10
+ <%= event.valid? ? "✓ Valid Payload" : "✗ Contract Violation" %>
11
+ </span>
12
+ </h1>
13
+ <div style="color: var(--text-muted); font-size: 13px; margin-top: 4px;">
14
+ Event ID: <code><%= h(event.id) %></code> &bull;
15
+ Received at: <%= h(event.received_at) %> &bull;
16
+ Provider: <%= h(event.provider) %>
17
+ </div>
18
+ </div>
19
+ <% if event.invalid? %>
20
+ <form method="POST" action="<%= base_path %>/events/<%= h(event.id) %>/revalidate" class="js-revalidate-form" data-event-id="<%= h(event.id) %>">
21
+ <button type="submit" class="btn">↻ Re-validate Event</button>
22
+ </form>
23
+ <% end %>
24
+ </div>
25
+
26
+ <div id="revalidate-feedback" class="hidden"></div>
27
+
28
+ <% if event.errors.any? %>
29
+ <div id="event-violations-card" class="card" style="border-left: 4px solid var(--red); margin-bottom: 20px;">
30
+ <div class="card-header" style="background: rgba(127, 29, 29, 0.2);">
31
+ <div class="card-title" style="color: var(--red);">Contract Violations (<%= event.errors.size %>)</div>
32
+ </div>
33
+ <div style="padding: 16px;">
34
+ <ul style="list-style: none;">
35
+ <% event.errors.each do |err| %>
36
+ <li style="padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,0.05); font-size: 13px;">
37
+ <code><%= h(err["path"] || err[:path] || "$") %></code>:
38
+ <strong style="color: var(--red);">[<%= h(err["code"] || err[:code] || "error") %>]</strong>
39
+ <%= h(err["message"] || err[:message] || "") %>
40
+ </li>
41
+ <% end %>
42
+ </ul>
43
+ </div>
44
+ </div>
45
+ <% end %>
46
+
47
+ <div class="card">
48
+ <div class="card-header">
49
+ <div class="card-title">Full JSON Payload</div>
50
+ </div>
51
+ <pre><%= h(JSON.pretty_generate(event.payload)) %></pre>
52
+ </div>
53
+
@@ -0,0 +1,100 @@
1
+ <div class="stats-grid">
2
+ <div class="stat-card">
3
+ <div class="stat-title">Total Webhooks</div>
4
+ <div class="stat-value"><%= stats[:total] %></div>
5
+ </div>
6
+ <div class="stat-card">
7
+ <div class="stat-title">Passed</div>
8
+ <div class="stat-value ok" data-stat="passed"><%= stats[:passed] %></div>
9
+ </div>
10
+ <div class="stat-card">
11
+ <div class="stat-title">Contract Violations</div>
12
+ <div class="stat-value <%= "err" if stats[:failed].positive? %>" data-stat="failed"><%= stats[:failed] %></div>
13
+ </div>
14
+ <div class="stat-card">
15
+ <div class="stat-title">Pass Rate</div>
16
+ <div class="stat-value <%= stats[:pass_rate] >= 100.0 ? "ok" : "err" %>" data-stat="pass_rate"><%= stats[:pass_rate] %>%</div>
17
+ </div>
18
+ <div class="stat-card">
19
+ <div class="stat-title">Active Contracts</div>
20
+ <div class="stat-value"><%= contracts_count %></div>
21
+ </div>
22
+ </div>
23
+
24
+ <div id="revalidate-feedback" class="hidden"></div>
25
+
26
+ <div class="card">
27
+ <div class="card-header">
28
+ <div class="card-title">Captured Webhook Payloads</div>
29
+ <div style="display: flex; gap: 12px; align-items: center;">
30
+ <form method="GET" action="<%= base_path %>/events" class="filter-bar">
31
+ <select name="status" onchange="this.form.submit()">
32
+ <option value="" <%= "selected" if status_filter.nil? || status_filter.empty? %>>All Statuses</option>
33
+ <option value="valid" <%= "selected" if status_filter == "valid" %>>✓ Valid Only</option>
34
+ <option value="invalid" <%= "selected" if status_filter == "invalid" %>>✗ Violations Only</option>
35
+ </select>
36
+ </form>
37
+ <% if events.any? %>
38
+ <form method="POST" action="<%= base_path %>/events/clear" onsubmit="return confirm('Clear all recorded webhook events?');">
39
+ <button type="submit" class="btn btn-outline" style="color: #ef4444;">Clear History</button>
40
+ </form>
41
+ <% end %>
42
+ </div>
43
+ </div>
44
+
45
+ <% if events.empty? %>
46
+ <div class="empty-state">
47
+ <p>No webhook events recorded yet.</p>
48
+ <p style="margin-top: 8px; font-size: 13px;">Send a webhook to your endpoint or trigger a test payment to see live verification here.</p>
49
+ </div>
50
+ <% else %>
51
+ <table>
52
+ <thead>
53
+ <tr>
54
+ <th>Status</th>
55
+ <th>Event Type</th>
56
+ <th>Provider</th>
57
+ <th>Event ID</th>
58
+ <th>Errors</th>
59
+ <th>Received At</th>
60
+ <th></th>
61
+ </tr>
62
+ </thead>
63
+ <tbody>
64
+ <% events.each do |event| %>
65
+ <tr data-event-row="<%= h(event.id) %>">
66
+ <td data-event-status>
67
+ <span class="badge <%= event.valid? ? "badge-ok" : "badge-err" %>">
68
+ <%= event.valid? ? "✓ Valid" : "✗ Violation" %>
69
+ </span>
70
+ </td>
71
+ <td><strong><%= h(event.event_type) %></strong></td>
72
+ <td><span class="badge badge-neutral"><%= h(event.provider) %></span></td>
73
+ <td><code><%= h(event.id) %></code></td>
74
+ <td data-event-errors>
75
+ <% if event.errors.any? %>
76
+ <span style="color: #f87171; font-weight: 600;"><%= event.errors.size %> error(s)</span>
77
+ <% else %>
78
+ <span style="color: #94a3b8;">—</span>
79
+ <% end %>
80
+ </td>
81
+ <td style="color: var(--text-muted); font-size: 13px;"><%= h(event.received_at) %></td>
82
+ <td style="text-align: right;">
83
+ <div style="display: inline-flex; align-items: center; gap: 10px;">
84
+ <% if event.invalid? %>
85
+ <% return_path = status_filter && !status_filter.empty? ? "/events?status=#{CGI.escape(status_filter)}" : "/events" %>
86
+ <form method="POST" action="<%= base_path %>/events/<%= h(event.id) %>/revalidate" class="js-revalidate-form" data-event-id="<%= h(event.id) %>" style="display: inline;">
87
+ <input type="hidden" name="return_to" value="<%= h(return_path) %>">
88
+ <button type="submit" class="btn btn-sm">↻ Re-validate</button>
89
+ </form>
90
+ <% end %>
91
+ <a href="<%= base_path %>/events/<%= h(event.id) %>" class="row-link">Inspect &rarr;</a>
92
+ </div>
93
+ </td>
94
+ </tr>
95
+ <% end %>
96
+ </tbody>
97
+ </table>
98
+ <% end %>
99
+ </div>
100
+
@@ -0,0 +1,143 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title><%= h(title) %> — Hooktrace Web</title>
7
+ <style><%= stylesheet %></style>
8
+ </head>
9
+ <body>
10
+ <nav class="navbar">
11
+ <a href="<%= base_path %>/events" class="nav-brand">
12
+ ⚡ Hooktrace <span>v<%= h(Hooktrace::VERSION) %></span>
13
+ </a>
14
+ <div class="nav-links">
15
+ <a href="<%= base_path %>/events" class="<%= "active" if active_tab == "events" %>">Webhook Events</a>
16
+ <a href="<%= base_path %>/contracts" class="<%= "active" if active_tab == "contracts" %>">Contracts</a>
17
+ </div>
18
+ </nav>
19
+ <main class="container">
20
+ <%= content %>
21
+ </main>
22
+ <script>
23
+ (function() {
24
+ function escapeHtml(str) {
25
+ return String(str)
26
+ .replace(/&/g, "&amp;")
27
+ .replace(/</g, "&lt;")
28
+ .replace(/>/g, "&gt;")
29
+ .replace(/"/g, "&quot;");
30
+ }
31
+
32
+ function renderFeedback(el, ok, apiLabel, httpStatus, message, payload) {
33
+ el.className = "api-banner " + (ok ? "api-banner-ok" : "api-banner-err");
34
+ el.innerHTML =
35
+ '<div class="api-banner-head">' +
36
+ '<div>' +
37
+ '<strong>' + escapeHtml(message) + '</strong>' +
38
+ '<div class="api-banner-meta">API Called: <code>' + escapeHtml(apiLabel) + '</code> &bull; HTTP ' + escapeHtml(httpStatus) + '</div>' +
39
+ '</div>' +
40
+ '<button type="button" class="btn btn-outline btn-sm" onclick="this.closest(\'.api-banner\').className=\'hidden\'">Dismiss</button>' +
41
+ '</div>' +
42
+ '<pre>' + escapeHtml(JSON.stringify(payload, null, 2)) + '</pre>';
43
+ }
44
+
45
+ function updateStats(stats) {
46
+ if (!stats) return;
47
+ var passedEl = document.querySelector('[data-stat="passed"]');
48
+ var failedEl = document.querySelector('[data-stat="failed"]');
49
+ var rateEl = document.querySelector('[data-stat="pass_rate"]');
50
+ if (passedEl) passedEl.textContent = stats.passed;
51
+ if (failedEl) {
52
+ failedEl.textContent = stats.failed;
53
+ failedEl.className = "stat-value" + (stats.failed > 0 ? " err" : "");
54
+ }
55
+ if (rateEl) {
56
+ rateEl.textContent = stats.pass_rate + "%";
57
+ rateEl.className = "stat-value " + (stats.pass_rate >= 100.0 ? "ok" : "err");
58
+ }
59
+ }
60
+
61
+ function updateEventUI(form, eventId, data) {
62
+ updateStats(data.stats);
63
+ var row = Array.prototype.find.call(document.querySelectorAll("[data-event-row]"), function(tr) {
64
+ return tr.getAttribute("data-event-row") === eventId;
65
+ });
66
+ if (row) {
67
+ var statusCell = row.querySelector("[data-event-status]");
68
+ var errorsCell = row.querySelector("[data-event-errors]");
69
+ if (statusCell) {
70
+ statusCell.innerHTML = '<span class="badge ' + (data.valid ? 'badge-ok' : 'badge-err') + '">' +
71
+ (data.valid ? '✓ Valid' : '✗ Violation') + '</span>';
72
+ }
73
+ if (errorsCell) {
74
+ var count = Array.isArray(data.errors) ? data.errors.length : 0;
75
+ errorsCell.innerHTML = count > 0
76
+ ? '<span style="color: #f87171; font-weight: 600;">' + count + ' error(s)</span>'
77
+ : '<span style="color: #94a3b8;">—</span>';
78
+ }
79
+ if (data.valid) form.remove();
80
+ }
81
+
82
+ var detailBadge = document.getElementById("event-detail-badge");
83
+ if (detailBadge) {
84
+ detailBadge.className = "badge " + (data.valid ? "badge-ok" : "badge-err");
85
+ detailBadge.textContent = data.valid ? "✓ Valid Payload" : "✗ Contract Violation";
86
+ if (data.valid) {
87
+ form.remove();
88
+ var violationsCard = document.getElementById("event-violations-card");
89
+ if (violationsCard) violationsCard.remove();
90
+ }
91
+ }
92
+ }
93
+
94
+ document.addEventListener("submit", async function(e) {
95
+ var form = e.target;
96
+ if (!form || !form.classList || !form.classList.contains("js-revalidate-form")) return;
97
+ e.preventDefault();
98
+
99
+ var btn = form.querySelector('button[type="submit"]');
100
+ var originalHtml = btn ? btn.innerHTML : "";
101
+ var feedback = document.getElementById("revalidate-feedback");
102
+ var apiPath = new URL(form.action, window.location.origin).pathname;
103
+ var eventId = form.getAttribute("data-event-id") || "";
104
+
105
+ if (btn) {
106
+ btn.disabled = true;
107
+ btn.innerHTML = '<span class="spinner"></span> Re-validating...';
108
+ }
109
+
110
+ try {
111
+ var res = await fetch(form.action, {
112
+ method: "POST",
113
+ headers: { "Accept": "application/json" }
114
+ });
115
+ var contentType = res.headers.get("content-type") || "";
116
+ if (contentType.indexOf("application/json") === -1) {
117
+ throw new Error("Expected JSON response (HTTP " + res.status + "). Restart your Rails server to load updated Hooktrace gem code.");
118
+ }
119
+ var data = await res.json();
120
+ if (feedback) {
121
+ var msg = data.message || (data.valid ? "Re-validation passed." : "Contract violation remains.");
122
+ renderFeedback(feedback, Boolean(res.ok && data.valid), data.api || ("POST " + apiPath), res.status, msg, data);
123
+ }
124
+ if (res.ok) updateEventUI(form, eventId, data);
125
+ if (btn && document.body.contains(btn)) {
126
+ btn.disabled = false;
127
+ btn.innerHTML = originalHtml;
128
+ }
129
+ } catch (err) {
130
+ if (feedback) {
131
+ renderFeedback(feedback, false, "POST " + apiPath, "Error", "Failed to revalidate event: " + err.message, { error: err.message });
132
+ }
133
+ if (btn) {
134
+ btn.disabled = false;
135
+ btn.innerHTML = originalHtml;
136
+ }
137
+ }
138
+ });
139
+ })();
140
+ </script>
141
+ </body>
142
+ </html>
143
+