webspresso 0.0.108 → 0.0.110
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/LICENSE +21 -0
- package/README.md +3 -3
- package/bin/commands/add-esbuild.js +7 -3
- package/bin/commands/add-tailwind.js +9 -5
- package/bin/commands/build.js +20 -4
- package/bin/commands/dev.js +57 -7
- package/bin/commands/doctor.js +42 -1
- package/bin/commands/favicon-generate.js +10 -3
- package/bin/commands/new.js +8 -3
- package/bin/commands/start.js +3 -1
- package/bin/utils/add-command.js +16 -0
- package/core/app.js +45 -3
- package/core/auth/authenticate.js +3 -3
- package/core/auth/hash.js +167 -43
- package/core/auth/index.js +13 -1
- package/core/auth/jwt.js +21 -2
- package/core/auth/manager.js +63 -14
- package/core/auth/middleware.js +4 -2
- package/core/auth/oauth.js +5 -1
- package/core/auth/tokens.js +7 -2
- package/core/auth/totp.js +42 -6
- package/core/auth/user-agent.js +2 -0
- package/core/client/adapter/datastar.js +1401 -0
- package/core/client/api.js +1337 -0
- package/core/client/controller.js +1706 -0
- package/core/client/debug.js +367 -0
- package/core/client/devtool.js +1134 -0
- package/core/client/forms.js +1164 -0
- package/core/client/fragments.js +894 -0
- package/core/client/index.d.ts +59 -0
- package/core/client/index.js +391 -0
- package/core/client/lite.js +175 -0
- package/core/client/server-fragments.js +868 -0
- package/core/client/storage.js +339 -0
- package/core/client/utils.js +281 -0
- package/core/compression/middleware.js +277 -26
- package/core/context/app-context.js +25 -3
- package/core/context/request.js +32 -4
- package/core/errors/middleware.js +14 -0
- package/core/events/dispatcher.js +33 -0
- package/core/forms/flash.js +136 -102
- package/core/health/middleware.js +36 -6
- package/core/http/pipeline.js +45 -6
- package/core/index.js +25 -7
- package/core/kernel/view.js +41 -10
- package/core/metrics/middleware.js +30 -6
- package/core/metrics/registry.js +13 -5
- package/core/orm/cache/fingerprint.js +32 -11
- package/core/orm/cache/layer.js +19 -2
- package/core/orm/hidden.js +145 -0
- package/core/orm/model.js +48 -2
- package/core/orm/query-builder.js +343 -6
- package/core/orm/query-filters.js +14 -2
- package/core/orm/repository.js +64 -13
- package/core/orm/schema-helpers.js +9 -6
- package/core/orm/transaction.js +50 -6
- package/core/orm/types.js +4 -0
- package/core/queue/adapters/database.js +184 -2
- package/core/queue/adapters/memory.js +153 -5
- package/core/queue/adapters/redis.js +59 -4
- package/core/queue/job.js +14 -1
- package/core/queue/manager.js +115 -0
- package/core/resilience/circuit-breaker.js +27 -8
- package/core/services/builtins/exchange.js +174 -7
- package/core/services/builtins/file-manager.js +36 -0
- package/core/services/builtins/mail.js +27 -0
- package/core/services/builtins/queue.js +144 -0
- package/core/services/builtins/security.js +118 -0
- package/core/services/builtins/webhook.js +110 -0
- package/core/services/executor.js +38 -16
- package/core/services/index.js +4 -1
- package/core/sse/stream.js +28 -5
- package/core/utils/timeout.js +8 -1
- package/core/validation/compiler.js +10 -7
- package/index.d.ts +1320 -74
- package/index.js +128 -8
- package/package.json +75 -27
- package/plugins/admin-panel/client/parts/08-record-list.js +717 -70
- package/plugins/admin-panel/index.js +19 -8
- package/plugins/csrf/index.js +3 -3
- package/plugins/data-exchange/export.js +214 -0
- package/plugins/data-exchange/import.js +48 -5
- package/plugins/data-exchange/index.js +70 -28
- package/plugins/data-exchange/preview.js +266 -0
- package/plugins/data-exchange/template.js +242 -0
- package/plugins/email/admin-component.js +783 -141
- package/plugins/email/api-handlers.js +51 -1
- package/plugins/email/index.js +5 -0
- package/plugins/email/service.js +48 -0
- package/plugins/file-manager/admin-component.js +1546 -70
- package/plugins/file-manager/api-handlers.js +166 -1
- package/plugins/file-manager/core.js +598 -8
- package/plugins/file-manager/index.js +8 -0
- package/plugins/index.js +7 -0
- package/plugins/mcp/auth.js +3 -3
- package/plugins/oauth/index.js +36 -3
- package/plugins/queue/admin-component.js +1092 -0
- package/plugins/queue/api-handlers.js +248 -0
- package/plugins/queue/index.js +69 -0
- package/plugins/rest-resources/index.js +7 -2
- package/plugins/security/admin-component.js +689 -0
- package/plugins/security/api-handlers.js +169 -0
- package/plugins/security/audit.js +153 -0
- package/plugins/security/bruteforce.js +244 -0
- package/plugins/security/firewall.js +459 -0
- package/plugins/security/headers.js +214 -0
- package/plugins/security/honeypot.js +234 -0
- package/plugins/security/incident-recorder.js +137 -0
- package/plugins/security/index.js +211 -0
- package/plugins/seo-checker/analyzer.js +20 -7
- package/plugins/upload/index.js +36 -0
- package/plugins/webhooks/admin-component.js +702 -175
- package/plugins/webhooks/api-handlers.js +75 -1
- package/plugins/webhooks/dispatcher.js +290 -11
- package/plugins/webhooks/index.js +37 -2
- package/plugins/webhooks/sender.js +56 -0
- package/plugins/xlsx/engine.js +19 -4
- package/src/api/api-loader.js +19 -1
- package/src/bundle/index.js +443 -17
- package/src/client-runtime/bootstrap-swup.js +9 -0
- package/src/client-runtime/mount.js +15 -20
- package/src/client-runtime/resolve.js +3 -2
- package/src/dev/api-typegen.js +1300 -0
- package/src/dev/banner.js +10 -1
- package/src/dev/colors.js +1 -1
- package/src/dev/index.js +7 -1
- package/src/dev/typegen.js +173 -17
- package/src/dev-reload/index.js +1 -1
- package/src/discovery/file-route-parser.js +17 -3
- package/src/discovery/scan-routes.js +4 -1
- package/src/file-router.js +253 -69
- package/src/helpers.js +46 -26
- package/src/njk-frontmatter.js +30 -4
- package/src/routing/cascading.js +26 -8
- package/src/routing/mount-discovered-routes.js +76 -0
- package/src/server.js +231 -70
- package/views/partials/webspresso-client-runtime.njk +1 -9
- package/.agents/ADMIN.md +0 -426
- package/.agents/AGENTS.md +0 -96
- package/.agents/ARCHITECTURE.md +0 -163
- package/.agents/AUTH.md +0 -581
- package/.agents/CACHE.md +0 -148
- package/.agents/CLI.md +0 -649
- package/.agents/COMPRESSION.md +0 -59
- package/.agents/CONTEXT.md +0 -152
- package/.agents/CONVENTIONS.md +0 -50
- package/.agents/EARLY_HINTS.md +0 -120
- package/.agents/EMAIL.md +0 -223
- package/.agents/ERRORS.md +0 -260
- package/.agents/EVENTS.md +0 -179
- package/.agents/FLAGS.md +0 -118
- package/.agents/HEALTH.md +0 -118
- package/.agents/LIMITS.md +0 -109
- package/.agents/LOGGING.md +0 -93
- package/.agents/MCP.md +0 -103
- package/.agents/METRICS.md +0 -127
- package/.agents/MIGRATION_JOBS.md +0 -95
- package/.agents/ORM.md +0 -700
- package/.agents/PLUGINS.md +0 -729
- package/.agents/QUEUE.md +0 -290
- package/.agents/RATE_LIMIT.md +0 -147
- package/.agents/REALTIME.md +0 -213
- package/.agents/RESILIENCE.md +0 -235
- package/.agents/ROUTING.md +0 -605
- package/.agents/SCALE_OUT.md +0 -109
- package/.agents/SECRETS.md +0 -117
- package/.agents/SERVICES.md +0 -341
- package/.agents/SHUTDOWN.md +0 -74
- package/.agents/STREAMING.md +0 -108
- package/.agents/WORKFLOW.md +0 -27
- package/.agents/internal/DOCUMENTATION_REVIEW.md +0 -485
- package/.agents/internal/TECHNICAL_REVIEW.md +0 -428
- package/.agents/skills/webspresso-admin-and-plugins/SKILL.md +0 -122
- package/.agents/skills/webspresso-framework/SKILL.md +0 -89
- package/.agents/skills/webspresso-orm-and-database/SKILL.md +0 -127
- package/.agents/skills/webspresso-routing-and-api/SKILL.md +0 -130
- package/.agents/skills/webspresso-services/SKILL.md +0 -134
- package/.cursorrules +0 -14
- package/AGENTS.md +0 -203
- package/CLAUDE.md +0 -54
- package/core/kernel/run-demo.js +0 -58
- package/plugins/admin-panel/styles.js +0 -9
- package/plugins/data-exchange/export-xlsx.js +0 -119
- package/src/client-runtime/bootstrap-alpine-swup.js +0 -34
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Webhooks Admin Panel Component — Mithril SPA Component Generator
|
|
3
|
-
* Features endpoints management,
|
|
3
|
+
* Features endpoints management, interactive payload & ping testing, delivery log inspector, secret rotation, and bulk retry
|
|
4
4
|
* @module plugins/webhooks/admin-component
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -55,14 +55,89 @@ function generateWebhooksComponent(options = {}) {
|
|
|
55
55
|
return ['*'];
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
var EVENT_PRESETS = {
|
|
59
|
+
'ping': {
|
|
60
|
+
label: 'Ping Handshake (ping)',
|
|
61
|
+
payload: {
|
|
62
|
+
ping: true,
|
|
63
|
+
message: 'Manual webhook ping test from Webspresso Admin',
|
|
64
|
+
timestamp: new Date().toISOString()
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
'order.created': {
|
|
68
|
+
label: 'Order Created (order.created)',
|
|
69
|
+
payload: {
|
|
70
|
+
id: 'ord_9824',
|
|
71
|
+
event: 'order.created',
|
|
72
|
+
amount: 149.50,
|
|
73
|
+
currency: 'USD',
|
|
74
|
+
status: 'paid',
|
|
75
|
+
customer: {
|
|
76
|
+
id: 'cust_401',
|
|
77
|
+
name: 'Jane Doe',
|
|
78
|
+
email: 'jane.doe@example.com'
|
|
79
|
+
},
|
|
80
|
+
items: [
|
|
81
|
+
{ sku: 'PREM-SUB', name: 'Annual Pro Plan', qty: 1, unit_price: 149.50 }
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
'user.registered': {
|
|
86
|
+
label: 'User Registered (user.registered)',
|
|
87
|
+
payload: {
|
|
88
|
+
id: 1042,
|
|
89
|
+
event: 'user.registered',
|
|
90
|
+
email: 'developer@example.com',
|
|
91
|
+
username: 'octocat',
|
|
92
|
+
plan: 'developer',
|
|
93
|
+
created_at: new Date().toISOString()
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
'payment.succeeded': {
|
|
97
|
+
label: 'Payment Succeeded (payment.succeeded)',
|
|
98
|
+
payload: {
|
|
99
|
+
id: 'pay_7721',
|
|
100
|
+
event: 'payment.succeeded',
|
|
101
|
+
amount: 49.00,
|
|
102
|
+
currency: 'EUR',
|
|
103
|
+
payment_method: 'card_visa',
|
|
104
|
+
receipt_url: 'https://example.com/receipts/pay_7721'
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
'custom': {
|
|
108
|
+
label: 'Custom JSON Payload',
|
|
109
|
+
payload: {
|
|
110
|
+
event: 'custom.event',
|
|
111
|
+
data: {
|
|
112
|
+
test: true,
|
|
113
|
+
value: 42
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
58
119
|
function WebhooksPage() {
|
|
59
120
|
var activeTab = 'endpoints'; // 'endpoints' | 'deliveries'
|
|
60
121
|
var loading = false;
|
|
61
122
|
var error = null;
|
|
62
123
|
var successToast = null;
|
|
63
124
|
|
|
125
|
+
// Global Stats
|
|
126
|
+
var stats = {
|
|
127
|
+
totalEndpoints: 0,
|
|
128
|
+
activeEndpoints: 0,
|
|
129
|
+
totalDeliveries: 0,
|
|
130
|
+
successfulDeliveries: 0,
|
|
131
|
+
failedDeliveries: 0,
|
|
132
|
+
successRate: 100,
|
|
133
|
+
avgDurationMs: 0
|
|
134
|
+
};
|
|
135
|
+
|
|
64
136
|
// Endpoints state
|
|
65
137
|
var endpoints = [];
|
|
138
|
+
var searchEndpoints = '';
|
|
139
|
+
var filterEndpointActive = '';
|
|
140
|
+
var revealedSecrets = {};
|
|
66
141
|
var showEndpointModal = false;
|
|
67
142
|
var editingEndpoint = null;
|
|
68
143
|
var endpointForm = {
|
|
@@ -74,6 +149,14 @@ function generateWebhooksComponent(options = {}) {
|
|
|
74
149
|
description: '',
|
|
75
150
|
};
|
|
76
151
|
|
|
152
|
+
// Interactive Test / Ping Modal state
|
|
153
|
+
var showTestModal = false;
|
|
154
|
+
var testEndpointTarget = null;
|
|
155
|
+
var testEvent = 'ping';
|
|
156
|
+
var testPayloadStr = JSON.stringify(EVENT_PRESETS['ping'].payload, null, 2);
|
|
157
|
+
var testResult = null;
|
|
158
|
+
var testInProgress = false;
|
|
159
|
+
|
|
77
160
|
// Deliveries state
|
|
78
161
|
var deliveries = [];
|
|
79
162
|
var deliveryTotal = 0;
|
|
@@ -82,7 +165,14 @@ function generateWebhooksComponent(options = {}) {
|
|
|
82
165
|
var deliveryPages = 1;
|
|
83
166
|
var filterEvent = '';
|
|
84
167
|
var filterSuccess = '';
|
|
168
|
+
var filterEndpointId = '';
|
|
85
169
|
var activeDeliveryModal = null;
|
|
170
|
+
var selectedDeliveryIds = {};
|
|
171
|
+
var bulkRetrying = false;
|
|
172
|
+
|
|
173
|
+
// Replay with edit state inside delivery modal
|
|
174
|
+
var replayEditMode = false;
|
|
175
|
+
var replayPayloadStr = '';
|
|
86
176
|
|
|
87
177
|
function setToast(msg) {
|
|
88
178
|
successToast = msg;
|
|
@@ -101,15 +191,75 @@ function generateWebhooksComponent(options = {}) {
|
|
|
101
191
|
return res;
|
|
102
192
|
}
|
|
103
193
|
|
|
194
|
+
function copyToClipboard(text, label) {
|
|
195
|
+
if (navigator && navigator.clipboard && navigator.clipboard.writeText) {
|
|
196
|
+
navigator.clipboard.writeText(text).then(function() {
|
|
197
|
+
setToast((label || 'Text') + ' copied to clipboard!');
|
|
198
|
+
}).catch(function() {
|
|
199
|
+
setToast('Failed to copy to clipboard.');
|
|
200
|
+
});
|
|
201
|
+
} else {
|
|
202
|
+
var el = document.createElement('textarea');
|
|
203
|
+
el.value = text;
|
|
204
|
+
document.body.appendChild(el);
|
|
205
|
+
el.select();
|
|
206
|
+
document.execCommand('copy');
|
|
207
|
+
document.body.removeChild(el);
|
|
208
|
+
setToast((label || 'Text') + ' copied to clipboard!');
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
var clientApi = {
|
|
213
|
+
get: function(path) {
|
|
214
|
+
if (typeof api !== 'undefined' && api && typeof api.get === 'function') {
|
|
215
|
+
return api.get(path);
|
|
216
|
+
}
|
|
217
|
+
var adminPath = window.__ADMIN_PATH__ || '/_admin';
|
|
218
|
+
return m.request({ method: 'GET', url: adminPath + '/api' + path });
|
|
219
|
+
},
|
|
220
|
+
post: function(path, data) {
|
|
221
|
+
if (typeof api !== 'undefined' && api && typeof api.post === 'function') {
|
|
222
|
+
return api.post(path, data);
|
|
223
|
+
}
|
|
224
|
+
var adminPath = window.__ADMIN_PATH__ || '/_admin';
|
|
225
|
+
return m.request({ method: 'POST', url: adminPath + '/api' + path, body: data });
|
|
226
|
+
},
|
|
227
|
+
put: function(path, data) {
|
|
228
|
+
if (typeof api !== 'undefined' && api && typeof api.put === 'function') {
|
|
229
|
+
return api.put(path, data);
|
|
230
|
+
}
|
|
231
|
+
var adminPath = window.__ADMIN_PATH__ || '/_admin';
|
|
232
|
+
return m.request({ method: 'PUT', url: adminPath + '/api' + path, body: data });
|
|
233
|
+
},
|
|
234
|
+
delete: function(path) {
|
|
235
|
+
if (typeof api !== 'undefined' && api && typeof api.delete === 'function') {
|
|
236
|
+
return api.delete(path);
|
|
237
|
+
}
|
|
238
|
+
var adminPath = window.__ADMIN_PATH__ || '/_admin';
|
|
239
|
+
return m.request({ method: 'DELETE', url: adminPath + '/api' + path });
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
function loadStats() {
|
|
244
|
+
return clientApi.get(API + '/stats').then(function(res) {
|
|
245
|
+
if (res) {
|
|
246
|
+
stats = res;
|
|
247
|
+
m.redraw();
|
|
248
|
+
}
|
|
249
|
+
}).catch(function() {});
|
|
250
|
+
}
|
|
251
|
+
|
|
104
252
|
function loadEndpoints() {
|
|
105
253
|
loading = true;
|
|
106
254
|
error = null;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
255
|
+
var q = '?';
|
|
256
|
+
if (searchEndpoints) q += 'search=' + encodeURIComponent(searchEndpoints) + '&';
|
|
257
|
+
if (filterEndpointActive !== '') q += 'active=' + encodeURIComponent(filterEndpointActive) + '&';
|
|
258
|
+
|
|
259
|
+
return clientApi.get(API + '/endpoints' + q).then(function(res) {
|
|
260
|
+
endpoints = (res && res.items) || [];
|
|
112
261
|
loading = false;
|
|
262
|
+
loadStats();
|
|
113
263
|
m.redraw();
|
|
114
264
|
}).catch(function(err) {
|
|
115
265
|
loading = false;
|
|
@@ -122,18 +272,18 @@ function generateWebhooksComponent(options = {}) {
|
|
|
122
272
|
loading = true;
|
|
123
273
|
error = null;
|
|
124
274
|
var q = '?page=' + deliveryPage + '&limit=' + deliveryLimit;
|
|
125
|
-
if (filterEvent) q += '&
|
|
275
|
+
if (filterEvent) q += '&search=' + encodeURIComponent(filterEvent);
|
|
126
276
|
if (filterSuccess !== '') q += '&success=' + encodeURIComponent(filterSuccess);
|
|
277
|
+
if (filterEndpointId) q += '&endpointId=' + encodeURIComponent(filterEndpointId);
|
|
127
278
|
|
|
128
|
-
return
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
deliveryPage = res.page || 1;
|
|
135
|
-
deliveryPages = res.pages || 1;
|
|
279
|
+
return clientApi.get(API + '/deliveries' + q).then(function(res) {
|
|
280
|
+
deliveries = (res && res.items) || [];
|
|
281
|
+
deliveryTotal = (res && res.total) || 0;
|
|
282
|
+
deliveryPage = (res && res.page) || 1;
|
|
283
|
+
deliveryPages = (res && res.pages) || 1;
|
|
284
|
+
selectedDeliveryIds = {};
|
|
136
285
|
loading = false;
|
|
286
|
+
loadStats();
|
|
137
287
|
m.redraw();
|
|
138
288
|
}).catch(function(err) {
|
|
139
289
|
loading = false;
|
|
@@ -144,7 +294,6 @@ function generateWebhooksComponent(options = {}) {
|
|
|
144
294
|
|
|
145
295
|
function saveEndpoint() {
|
|
146
296
|
var isEdit = !!editingEndpoint;
|
|
147
|
-
var method = isEdit ? 'PUT' : 'POST';
|
|
148
297
|
var url = isEdit ? API + '/endpoints/' + editingEndpoint.id : API + '/endpoints';
|
|
149
298
|
|
|
150
299
|
var payload = {
|
|
@@ -156,14 +305,12 @@ function generateWebhooksComponent(options = {}) {
|
|
|
156
305
|
description: endpointForm.description,
|
|
157
306
|
};
|
|
158
307
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
body: payload,
|
|
163
|
-
}).then(function() {
|
|
308
|
+
var req = isEdit ? clientApi.put(url, payload) : clientApi.post(url, payload);
|
|
309
|
+
|
|
310
|
+
return req.then(function() {
|
|
164
311
|
showEndpointModal = false;
|
|
165
312
|
editingEndpoint = null;
|
|
166
|
-
setToast(isEdit ? 'Endpoint updated.' : 'New endpoint created.');
|
|
313
|
+
setToast(isEdit ? 'Endpoint updated successfully.' : 'New endpoint created successfully.');
|
|
167
314
|
loadEndpoints();
|
|
168
315
|
}).catch(function(err) {
|
|
169
316
|
alert((err.response && err.response.error) || err.message || 'Save failed.');
|
|
@@ -174,10 +321,7 @@ function generateWebhooksComponent(options = {}) {
|
|
|
174
321
|
if (!confirm('Are you sure you want to delete endpoint "' + ep.name + '"?')) {
|
|
175
322
|
return;
|
|
176
323
|
}
|
|
177
|
-
|
|
178
|
-
method: 'DELETE',
|
|
179
|
-
url: API + '/endpoints/' + ep.id,
|
|
180
|
-
}).then(function() {
|
|
324
|
+
clientApi.delete(API + '/endpoints/' + ep.id).then(function() {
|
|
181
325
|
setToast('Endpoint deleted.');
|
|
182
326
|
loadEndpoints();
|
|
183
327
|
}).catch(function(err) {
|
|
@@ -185,33 +329,77 @@ function generateWebhooksComponent(options = {}) {
|
|
|
185
329
|
});
|
|
186
330
|
}
|
|
187
331
|
|
|
188
|
-
function
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
332
|
+
function rotateSecret(ep) {
|
|
333
|
+
if (!confirm('Rotate signing secret for "' + ep.name + '"?\\n\\nThe previous secret will remain stored for signature verification during grace period.')) {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
clientApi.post(API + '/endpoints/' + ep.id + '/rotate-secret', {}).then(function(res) {
|
|
337
|
+
setToast('Secret rotated! New secret: ' + (res.secret || ''));
|
|
338
|
+
loadEndpoints();
|
|
339
|
+
}).catch(function(err) {
|
|
340
|
+
alert((err.response && err.response.error) || err.message || 'Secret rotation failed.');
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function openTestModal(ep) {
|
|
345
|
+
testEndpointTarget = ep;
|
|
346
|
+
testEvent = 'ping';
|
|
347
|
+
testPayloadStr = JSON.stringify(EVENT_PRESETS['ping'].payload, null, 2);
|
|
348
|
+
testResult = null;
|
|
349
|
+
testInProgress = false;
|
|
350
|
+
showTestModal = true;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function setEventPreset(evtKey) {
|
|
354
|
+
testEvent = evtKey;
|
|
355
|
+
if (EVENT_PRESETS[evtKey]) {
|
|
356
|
+
testPayloadStr = JSON.stringify(EVENT_PRESETS[evtKey].payload, null, 2);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function runWebhookTest() {
|
|
361
|
+
if (!testEndpointTarget) return;
|
|
362
|
+
|
|
363
|
+
var parsedPayload;
|
|
364
|
+
try {
|
|
365
|
+
parsedPayload = JSON.parse(testPayloadStr);
|
|
366
|
+
} catch (e) {
|
|
367
|
+
alert('Invalid JSON in payload: ' + e.message);
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
testInProgress = true;
|
|
372
|
+
testResult = null;
|
|
373
|
+
|
|
374
|
+
clientApi.post(API + '/endpoints/' + testEndpointTarget.id + '/test', {
|
|
375
|
+
event: testEvent,
|
|
376
|
+
payload: parsedPayload,
|
|
193
377
|
}).then(function(res) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
378
|
+
testInProgress = false;
|
|
379
|
+
testResult = res;
|
|
380
|
+
if (res && res.success) {
|
|
381
|
+
setToast('Test delivery successful! (' + res.statusCode + ' in ' + (res.durationMs || 0) + 'ms)');
|
|
198
382
|
}
|
|
199
|
-
|
|
383
|
+
loadStats();
|
|
384
|
+
m.redraw();
|
|
200
385
|
}).catch(function(err) {
|
|
201
|
-
|
|
386
|
+
testInProgress = false;
|
|
387
|
+
testResult = {
|
|
388
|
+
success: false,
|
|
389
|
+
statusCode: 0,
|
|
390
|
+
error: (err.response && err.response.error) || err.message || 'Network dispatch error',
|
|
391
|
+
};
|
|
392
|
+
m.redraw();
|
|
202
393
|
});
|
|
203
394
|
}
|
|
204
395
|
|
|
205
396
|
function retryDelivery(dlv) {
|
|
206
397
|
setToast('Retrying delivery #' + dlv.id + '...');
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}).then(function(res) {
|
|
211
|
-
if (res.success) {
|
|
212
|
-
setToast('Retry successful! (' + res.statusCode + ')');
|
|
398
|
+
clientApi.post(API + '/deliveries/' + dlv.id + '/retry', {}).then(function(res) {
|
|
399
|
+
if (res && res.success) {
|
|
400
|
+
setToast('Retry successful! (HTTP ' + res.statusCode + ')');
|
|
213
401
|
} else {
|
|
214
|
-
alert('Retry failed: ' + (res.error || ('HTTP ' + res.statusCode)));
|
|
402
|
+
alert('Retry failed: ' + ((res && res.error) || ('HTTP ' + (res && res.statusCode))));
|
|
215
403
|
}
|
|
216
404
|
loadDeliveries();
|
|
217
405
|
}).catch(function(err) {
|
|
@@ -219,6 +407,66 @@ function generateWebhooksComponent(options = {}) {
|
|
|
219
407
|
});
|
|
220
408
|
}
|
|
221
409
|
|
|
410
|
+
function replayActiveDelivery() {
|
|
411
|
+
if (!activeDeliveryModal) return;
|
|
412
|
+
var dlv = activeDeliveryModal;
|
|
413
|
+
var body = {};
|
|
414
|
+
|
|
415
|
+
if (replayEditMode) {
|
|
416
|
+
try {
|
|
417
|
+
body.payload = JSON.parse(replayPayloadStr);
|
|
418
|
+
} catch (e) {
|
|
419
|
+
alert('Invalid JSON payload: ' + e.message);
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
setToast('Replaying delivery #' + dlv.id + '...');
|
|
425
|
+
clientApi.post(API + '/deliveries/' + dlv.id + '/replay', body).then(function(res) {
|
|
426
|
+
if (res && res.success) {
|
|
427
|
+
setToast('Replay successful! Created delivery #' + (res.deliveryId || res.id) + ' (HTTP ' + res.statusCode + ')');
|
|
428
|
+
activeDeliveryModal = null;
|
|
429
|
+
replayEditMode = false;
|
|
430
|
+
} else {
|
|
431
|
+
alert('Replay failed: ' + ((res && res.error) || ('HTTP ' + (res && res.statusCode))));
|
|
432
|
+
}
|
|
433
|
+
loadDeliveries();
|
|
434
|
+
}).catch(function(err) {
|
|
435
|
+
alert('Failed to replay delivery: ' + err.message);
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function bulkRetrySelected() {
|
|
440
|
+
var ids = Object.keys(selectedDeliveryIds).filter(function(k) { return selectedDeliveryIds[k]; });
|
|
441
|
+
if (ids.length === 0) return;
|
|
442
|
+
|
|
443
|
+
if (!confirm('Retry ' + ids.length + ' selected deliveries?')) return;
|
|
444
|
+
|
|
445
|
+
bulkRetrying = true;
|
|
446
|
+
clientApi.post(API + '/deliveries/bulk-retry', { ids: ids }).then(function(res) {
|
|
447
|
+
bulkRetrying = false;
|
|
448
|
+
selectedDeliveryIds = {};
|
|
449
|
+
setToast('Bulk retry finished: ' + (res ? res.succeeded : 0) + ' succeeded, ' + (res ? res.failed : 0) + ' failed.');
|
|
450
|
+
loadDeliveries();
|
|
451
|
+
}).catch(function(err) {
|
|
452
|
+
bulkRetrying = false;
|
|
453
|
+
alert('Bulk retry failed: ' + err.message);
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
function toggleSelectAllDeliveries(checked) {
|
|
458
|
+
selectedDeliveryIds = {};
|
|
459
|
+
if (checked) {
|
|
460
|
+
for (var i = 0; i < deliveries.length; i++) {
|
|
461
|
+
selectedDeliveryIds[deliveries[i].id] = true;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function getSelectedCount() {
|
|
467
|
+
return Object.keys(selectedDeliveryIds).filter(function(k) { return selectedDeliveryIds[k]; }).length;
|
|
468
|
+
}
|
|
469
|
+
|
|
222
470
|
function openNewModal() {
|
|
223
471
|
editingEndpoint = null;
|
|
224
472
|
endpointForm = {
|
|
@@ -246,18 +494,42 @@ function generateWebhooksComponent(options = {}) {
|
|
|
246
494
|
showEndpointModal = true;
|
|
247
495
|
}
|
|
248
496
|
|
|
497
|
+
// Keydown listener for Esc key
|
|
498
|
+
function onKeyDown(e) {
|
|
499
|
+
if (e.key === 'Escape') {
|
|
500
|
+
if (showTestModal) {
|
|
501
|
+
showTestModal = false;
|
|
502
|
+
m.redraw();
|
|
503
|
+
} else if (showEndpointModal) {
|
|
504
|
+
showEndpointModal = false;
|
|
505
|
+
m.redraw();
|
|
506
|
+
} else if (activeDeliveryModal) {
|
|
507
|
+
activeDeliveryModal = null;
|
|
508
|
+
m.redraw();
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
249
513
|
return {
|
|
250
514
|
oninit: function() {
|
|
251
515
|
loadEndpoints();
|
|
516
|
+
loadStats();
|
|
517
|
+
window.addEventListener('keydown', onKeyDown);
|
|
518
|
+
},
|
|
519
|
+
|
|
520
|
+
onremove: function() {
|
|
521
|
+
window.removeEventListener('keydown', onKeyDown);
|
|
252
522
|
},
|
|
253
523
|
|
|
254
524
|
view: function() {
|
|
255
|
-
var totalEndpoints = endpoints.length;
|
|
256
|
-
var activeEndpoints = endpoints.filter(function(e) { return e.is_active; }).length;
|
|
525
|
+
var totalEndpoints = stats.totalEndpoints || endpoints.length;
|
|
526
|
+
var activeEndpoints = stats.activeEndpoints || endpoints.filter(function(e) { return e.is_active; }).length;
|
|
527
|
+
var selectedCount = getSelectedCount();
|
|
528
|
+
var allSelected = deliveries.length > 0 && selectedCount === deliveries.length;
|
|
257
529
|
|
|
258
530
|
return m('div.space-y-6', [
|
|
259
531
|
// Toast Notification
|
|
260
|
-
successToast ? m('div.fixed.bottom-5.right-5.z-50.px-4.py-2.5.rounded-xl.bg-emerald-600.text-white.text-sm.font-medium.shadow-
|
|
532
|
+
successToast ? m('div.fixed.bottom-5.right-5.z-50.px-4.py-2.5.rounded-xl.bg-emerald-600.text-white.text-sm.font-medium.shadow-xl.flex.items-center.gap-2.animate-fade-in', [
|
|
261
533
|
m('span', '✓'),
|
|
262
534
|
m('span', successToast),
|
|
263
535
|
]) : null,
|
|
@@ -265,9 +537,12 @@ function generateWebhooksComponent(options = {}) {
|
|
|
265
537
|
// Page Header
|
|
266
538
|
m('div.flex.flex-col.sm:flex-row.sm:items-center.sm:justify-between.gap-4.border-b.border-gray-200.dark:border-slate-800.pb-5', [
|
|
267
539
|
m('div', [
|
|
268
|
-
m('
|
|
540
|
+
m('div.flex.items-center.gap-3', [
|
|
541
|
+
m('div.w-9.h-9.rounded-xl.bg-indigo-600/10.text-indigo-600.dark:bg-indigo-500/20.dark:text-indigo-400.flex.items-center.justify-center.font-bold.text-lg', '🪝'),
|
|
542
|
+
m('h1.text-2xl.font-bold.text-gray-900.dark:text-white', 'Webhooks Engine'),
|
|
543
|
+
]),
|
|
269
544
|
m('p.text-sm.text-gray-500.dark:text-slate-400.mt-1',
|
|
270
|
-
'
|
|
545
|
+
'HMAC-SHA256 cryptographically signed webhook dispatches, live payload testing, and delivery audit history.'
|
|
271
546
|
),
|
|
272
547
|
]),
|
|
273
548
|
m('div.flex.items-center.gap-3', [
|
|
@@ -275,154 +550,257 @@ function generateWebhooksComponent(options = {}) {
|
|
|
275
550
|
onclick: openNewModal,
|
|
276
551
|
}, [
|
|
277
552
|
m('span', '+'),
|
|
278
|
-
m('span', 'Add
|
|
553
|
+
m('span', 'Add Webhook Endpoint'),
|
|
279
554
|
]),
|
|
280
555
|
]),
|
|
281
556
|
]),
|
|
282
557
|
|
|
283
|
-
//
|
|
558
|
+
// Metrics Summary Banner
|
|
284
559
|
m('div.grid.grid-cols-2.sm:grid-cols-4.gap-4', [
|
|
285
560
|
m('div.p-4.rounded-2xl.bg-white.dark:bg-slate-800.border.border-gray-200.dark:border-slate-700.shadow-sm', [
|
|
286
|
-
m('div.text-xs.font-medium.text-gray-500.dark:text-slate-400', '
|
|
287
|
-
m('div.text-2xl.font-bold.text-gray-900.dark:text-white.mt-1',
|
|
561
|
+
m('div.text-xs.font-medium.text-gray-500.dark:text-slate-400', 'Active Endpoints'),
|
|
562
|
+
m('div.text-2xl.font-bold.text-gray-900.dark:text-white.mt-1', [
|
|
563
|
+
m('span.text-emerald-600.dark:text-emerald-400', activeEndpoints),
|
|
564
|
+
m('span.text-gray-400.text-lg.font-normal', ' / ' + totalEndpoints),
|
|
565
|
+
]),
|
|
288
566
|
]),
|
|
289
567
|
m('div.p-4.rounded-2xl.bg-white.dark:bg-slate-800.border.border-gray-200.dark:border-slate-700.shadow-sm', [
|
|
290
|
-
m('div.text-xs.font-medium.text-gray-500.dark:text-slate-400', '
|
|
291
|
-
m('div.text-2xl.font-bold.text-
|
|
568
|
+
m('div.text-xs.font-medium.text-gray-500.dark:text-slate-400', 'Total Deliveries'),
|
|
569
|
+
m('div.text-2xl.font-bold.text-indigo-600.dark:text-indigo-400.mt-1', stats.totalDeliveries || deliveryTotal || 0),
|
|
292
570
|
]),
|
|
293
571
|
m('div.p-4.rounded-2xl.bg-white.dark:bg-slate-800.border.border-gray-200.dark:border-slate-700.shadow-sm', [
|
|
294
|
-
m('div.text-xs.font-medium.text-gray-500.dark:text-slate-400', '
|
|
295
|
-
m('div.text-2xl.font-bold.
|
|
572
|
+
m('div.text-xs.font-medium.text-gray-500.dark:text-slate-400', 'Delivery Success Rate'),
|
|
573
|
+
m('div.text-2xl.font-bold.mt-1', {
|
|
574
|
+
class: (stats.successRate >= 95 ? 'text-emerald-600 dark:text-emerald-400' : (stats.successRate >= 80 ? 'text-amber-500' : 'text-rose-600'))
|
|
575
|
+
}, stats.successRate + '%'),
|
|
296
576
|
]),
|
|
297
577
|
m('div.p-4.rounded-2xl.bg-white.dark:bg-slate-800.border.border-gray-200.dark:border-slate-700.shadow-sm', [
|
|
298
|
-
m('div.text-xs.font-medium.text-gray-500.dark:text-slate-400', '
|
|
299
|
-
m('div.text-
|
|
578
|
+
m('div.text-xs.font-medium.text-gray-500.dark:text-slate-400', 'Average Latency'),
|
|
579
|
+
m('div.text-2xl.font-bold.text-gray-900.dark:text-white.mt-1', (stats.avgDurationMs || 0) + ' ms'),
|
|
300
580
|
]),
|
|
301
581
|
]),
|
|
302
582
|
|
|
303
|
-
// Tabs Switcher
|
|
583
|
+
// Navigation Tabs Switcher
|
|
304
584
|
m('div.flex.border-b.border-gray-200.dark:border-slate-700', [
|
|
305
|
-
m('button.px-5.py-2.5.text-sm.font-
|
|
585
|
+
m('button.px-5.py-2.5.text-sm.font-semibold.border-b-2.transition-colors.flex.items-center.gap-2', {
|
|
306
586
|
class: activeTab === 'endpoints'
|
|
307
|
-
? 'border-indigo-600
|
|
308
|
-
: 'border-transparent
|
|
587
|
+
? 'border-indigo-600 text-indigo-600 dark:text-indigo-400 dark:border-indigo-400'
|
|
588
|
+
: 'border-transparent text-gray-500 hover:text-gray-700 dark:text-slate-400 dark:hover:text-slate-200',
|
|
309
589
|
onclick: function() { activeTab = 'endpoints'; loadEndpoints(); },
|
|
310
|
-
},
|
|
311
|
-
|
|
590
|
+
}, [
|
|
591
|
+
m('span', 'Endpoints'),
|
|
592
|
+
m('span.px-2.py-0.5.text-xs.rounded-full.bg-gray-100.dark:bg-slate-700.text-gray-700.dark:text-slate-300', totalEndpoints),
|
|
593
|
+
]),
|
|
594
|
+
m('button.px-5.py-2.5.text-sm.font-semibold.border-b-2.transition-colors.flex.items-center.gap-2', {
|
|
312
595
|
class: activeTab === 'deliveries'
|
|
313
|
-
? 'border-indigo-600
|
|
314
|
-
: 'border-transparent
|
|
596
|
+
? 'border-indigo-600 text-indigo-600 dark:text-indigo-400 dark:border-indigo-400'
|
|
597
|
+
: 'border-transparent text-gray-500 hover:text-gray-700 dark:text-slate-400 dark:hover:text-slate-200',
|
|
315
598
|
onclick: function() { activeTab = 'deliveries'; loadDeliveries(); },
|
|
316
|
-
},
|
|
599
|
+
}, [
|
|
600
|
+
m('span', 'Delivery Audit Logs'),
|
|
601
|
+
stats.failedDeliveries > 0 ? m('span.px-2.py-0.5.text-xs.rounded-full.bg-rose-100.text-rose-700.dark:bg-rose-950/50.dark:text-rose-300', stats.failedDeliveries + ' failed') : null,
|
|
602
|
+
]),
|
|
317
603
|
]),
|
|
318
604
|
|
|
319
605
|
// TAB 1: ENDPOINTS LIST
|
|
320
|
-
activeTab === 'endpoints' ? m('div.
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
m('
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
606
|
+
activeTab === 'endpoints' ? m('div.space-y-4', [
|
|
607
|
+
// Filter & Search Bar
|
|
608
|
+
m('div.flex.flex-col.sm:flex-row.gap-3.items-center.justify-between.bg-white.dark:bg-slate-800.p-3.rounded-xl.border.border-gray-200.dark:border-slate-700', [
|
|
609
|
+
m('div.flex.items-center.gap-3.w-full.sm:w-auto', [
|
|
610
|
+
m('input.px-3.py-1.5.text-xs.border.border-gray-200.dark:border-slate-700.rounded-lg.bg-transparent.text-gray-900.dark:text-white.w-56', {
|
|
611
|
+
placeholder: 'Search name or URL...',
|
|
612
|
+
value: searchEndpoints,
|
|
613
|
+
oninput: function(e) { searchEndpoints = e.target.value; },
|
|
614
|
+
onkeydown: function(e) { if (e.key === 'Enter') loadEndpoints(); },
|
|
615
|
+
}),
|
|
616
|
+
m('select.px-3.py-1.5.text-xs.border.border-gray-200.dark:border-slate-700.rounded-lg.bg-transparent.text-gray-900.dark:text-white', {
|
|
617
|
+
value: filterEndpointActive,
|
|
618
|
+
onchange: function(e) { filterEndpointActive = e.target.value; loadEndpoints(); },
|
|
619
|
+
}, [
|
|
620
|
+
m('option', { value: '' }, 'All Statuses'),
|
|
621
|
+
m('option', { value: 'true' }, 'Active Only'),
|
|
622
|
+
m('option', { value: 'false' }, 'Inactive Only'),
|
|
334
623
|
]),
|
|
335
|
-
m('
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
m('
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
m('span.w-1.5.h-1.5.rounded-full.bg-gray-400'),
|
|
358
|
-
'Inactive'
|
|
359
|
-
]),
|
|
360
|
-
]),
|
|
361
|
-
m('td.p-4', [
|
|
362
|
-
stats.total > 0
|
|
363
|
-
? m('div.text-xs', [
|
|
364
|
-
m('span.font-medium', stats.successRate + '% '),
|
|
365
|
-
m('span.text-gray-400', '(' + stats.successful + '/' + stats.total + ')'),
|
|
366
|
-
])
|
|
367
|
-
: m('span.text-xs.text-gray-400', 'No deliveries'),
|
|
624
|
+
m('button.px-3.py-1.5.text-xs.font-medium.rounded-lg.bg-gray-100.dark:bg-slate-700.text-gray-700.dark:text-slate-200.hover:bg-gray-200', {
|
|
625
|
+
onclick: function() { loadEndpoints(); },
|
|
626
|
+
}, 'Search'),
|
|
627
|
+
]),
|
|
628
|
+
m('div.text-xs.text-gray-500.dark:text-slate-400', endpoints.length + ' endpoints displayed'),
|
|
629
|
+
]),
|
|
630
|
+
|
|
631
|
+
// Endpoints Table
|
|
632
|
+
m('div.bg-white.dark:bg-slate-800.border.border-gray-200.dark:border-slate-700.rounded-2xl.overflow-hidden.shadow-sm', [
|
|
633
|
+
endpoints.length === 0 ? m('div.p-12.text-center.text-gray-500.dark:text-slate-400', [
|
|
634
|
+
m('p.text-base.font-medium', 'No webhook endpoints found.'),
|
|
635
|
+
m('p.text-xs.mt-1', 'Add a new endpoint above to start forwarding real-time events to external webhooks.'),
|
|
636
|
+
]) : m('div.overflow-x-auto', [
|
|
637
|
+
m('table.w-full.text-left.text-sm', [
|
|
638
|
+
m('thead.bg-gray-50.dark:bg-slate-750.text-xs.uppercase.text-gray-500.dark:text-slate-400.border-b.border-gray-200.dark:border-slate-700', [
|
|
639
|
+
m('tr', [
|
|
640
|
+
m('th.p-4', 'Endpoint & Destination'),
|
|
641
|
+
m('th.p-4', 'Subscribed Events'),
|
|
642
|
+
m('th.p-4', 'Signing Secret'),
|
|
643
|
+
m('th.p-4', 'Status'),
|
|
644
|
+
m('th.p-4', 'Health'),
|
|
645
|
+
m('th.p-4.text-right', 'Actions'),
|
|
368
646
|
]),
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
647
|
+
]),
|
|
648
|
+
m('tbody.divide-y.divide-gray-100.dark:divide-slate-700', endpoints.map(function(ep) {
|
|
649
|
+
var evts = parseEvents(ep.events);
|
|
650
|
+
var epStats = ep.stats || { total: 0, successful: 0, successRate: 100 };
|
|
651
|
+
var isRevealed = !!revealedSecrets[ep.id];
|
|
652
|
+
var maskedSecret = ep.secret
|
|
653
|
+
? (isRevealed ? ep.secret : (ep.secret.slice(0, 6) + '••••••••••••••••••••••••••••'))
|
|
654
|
+
: '—';
|
|
655
|
+
|
|
656
|
+
return m('tr.hover:bg-gray-50/60.dark:hover:bg-slate-750/50.transition-colors', [
|
|
657
|
+
// Name & URL
|
|
658
|
+
m('td.p-4', [
|
|
659
|
+
m('div.font-semibold.text-gray-900.dark:text-white.flex.items-center.gap-2', [
|
|
660
|
+
ep.name,
|
|
661
|
+
m('span.text-xs.font-normal.text-gray-400', '#' + ep.id),
|
|
662
|
+
]),
|
|
663
|
+
m('div.text-xs.font-mono.text-indigo-600.dark:text-indigo-400.truncate.max-w-xs.mt-0.5', { title: ep.url }, ep.url),
|
|
664
|
+
ep.description ? m('div.text-xs.text-gray-400.mt-1', ep.description) : null,
|
|
380
665
|
]),
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
666
|
+
|
|
667
|
+
// Events
|
|
668
|
+
m('td.p-4', [
|
|
669
|
+
m('div.flex.flex-wrap.gap-1.max-w-xs', evts.map(function(evt) {
|
|
670
|
+
return m('span.px-2.py-0.5.text-xs.font-mono.rounded-md.bg-gray-100.dark:bg-slate-700.text-gray-700.dark:text-slate-300', evt);
|
|
671
|
+
})),
|
|
672
|
+
]),
|
|
673
|
+
|
|
674
|
+
// Secret with Reveal & Copy & Rotate
|
|
675
|
+
m('td.p-4', [
|
|
676
|
+
m('div.flex.items-center.gap-1.5', [
|
|
677
|
+
m('span.text-xs.font-mono.text-gray-600.dark:text-slate-300', maskedSecret),
|
|
678
|
+
ep.secret ? m('button.p-1.text-xs.text-gray-400.hover:text-gray-700.dark:hover:text-slate-200.rounded', {
|
|
679
|
+
title: isRevealed ? 'Hide secret' : 'Reveal secret',
|
|
680
|
+
onclick: function() { revealedSecrets[ep.id] = !isRevealed; },
|
|
681
|
+
}, isRevealed ? '🙈' : '👁️') : null,
|
|
682
|
+
ep.secret ? m('button.p-1.text-xs.text-gray-400.hover:text-gray-700.dark:hover:text-slate-200.rounded', {
|
|
683
|
+
title: 'Copy signing secret',
|
|
684
|
+
onclick: function() { copyToClipboard(ep.secret, 'Signing secret'); },
|
|
685
|
+
}, '📋') : null,
|
|
686
|
+
m('button.p-1.text-xs.text-indigo-600.hover:text-indigo-700.dark:text-indigo-400.rounded', {
|
|
687
|
+
title: 'Rotate secret',
|
|
688
|
+
onclick: function() { rotateSecret(ep); },
|
|
689
|
+
}, '🔄'),
|
|
690
|
+
]),
|
|
691
|
+
]),
|
|
692
|
+
|
|
693
|
+
// Status pill
|
|
694
|
+
m('td.p-4', [
|
|
695
|
+
ep.is_active
|
|
696
|
+
? m('span.inline-flex.items-center.gap-1.5.px-2.5.py-1.rounded-full.text-xs.font-medium.bg-emerald-50.text-emerald-700.dark:bg-emerald-950/40.dark:text-emerald-300', [
|
|
697
|
+
m('span.w-1.5.h-1.5.rounded-full.bg-emerald-500'),
|
|
698
|
+
'Active'
|
|
699
|
+
])
|
|
700
|
+
: m('span.inline-flex.items-center.gap-1.5.px-2.5.py-1.rounded-full.text-xs.font-medium.bg-gray-100.text-gray-600.dark:bg-slate-700.dark:text-slate-400', [
|
|
701
|
+
m('span.w-1.5.h-1.5.rounded-full.bg-gray-400'),
|
|
702
|
+
'Inactive'
|
|
703
|
+
]),
|
|
704
|
+
]),
|
|
705
|
+
|
|
706
|
+
// Health & stats
|
|
707
|
+
m('td.p-4', [
|
|
708
|
+
epStats.total > 0
|
|
709
|
+
? m('div.text-xs', [
|
|
710
|
+
m('span.font-semibold', {
|
|
711
|
+
class: epStats.successRate >= 90 ? 'text-emerald-600' : 'text-rose-600'
|
|
712
|
+
}, epStats.successRate + '% '),
|
|
713
|
+
m('span.text-gray-400', '(' + epStats.successful + '/' + epStats.total + ')'),
|
|
714
|
+
])
|
|
715
|
+
: m('span.text-xs.text-gray-400', 'No deliveries yet'),
|
|
716
|
+
]),
|
|
717
|
+
|
|
718
|
+
// Actions
|
|
719
|
+
m('td.p-4.text-right', [
|
|
720
|
+
m('div.inline-flex.items-center.gap-1.5', [
|
|
721
|
+
m('button.px-2.5.py-1.text-xs.font-semibold.rounded-lg.bg-indigo-50.text-indigo-600.dark:bg-indigo-950/50.dark:text-indigo-300.hover:bg-indigo-100.transition-colors', {
|
|
722
|
+
onclick: function() { openTestModal(ep); },
|
|
723
|
+
}, '⚡ Test / Ping'),
|
|
724
|
+
m('button.px-2.5.py-1.text-xs.font-medium.rounded-lg.border.border-gray-200.dark:border-slate-700.text-gray-700.dark:text-slate-200.hover:bg-gray-100.dark:hover:bg-slate-700.transition-colors', {
|
|
725
|
+
onclick: function() { openEditModal(ep); },
|
|
726
|
+
}, 'Edit'),
|
|
727
|
+
m('button.px-2.5.py-1.text-xs.font-medium.rounded-lg.border.border-gray-200.dark:border-slate-700.text-rose-600.hover:bg-rose-50.dark:hover:bg-slate-700.transition-colors', {
|
|
728
|
+
onclick: function() { deleteEndpoint(ep); },
|
|
729
|
+
}, 'Delete'),
|
|
730
|
+
]),
|
|
731
|
+
]),
|
|
732
|
+
]);
|
|
733
|
+
})),
|
|
734
|
+
]),
|
|
384
735
|
]),
|
|
385
736
|
]),
|
|
386
737
|
]) : null,
|
|
387
738
|
|
|
388
|
-
// TAB 2: DELIVERIES
|
|
739
|
+
// TAB 2: DELIVERIES AUDIT LOG
|
|
389
740
|
activeTab === 'deliveries' ? m('div.space-y-4', [
|
|
390
741
|
// Filter Bar
|
|
391
742
|
m('div.flex.flex-col.sm:flex-row.gap-3.items-center.justify-between.bg-white.dark:bg-slate-800.p-3.rounded-xl.border.border-gray-200.dark:border-slate-700', [
|
|
392
|
-
m('div.flex.items-center.gap-
|
|
393
|
-
m('input.px-3.py-1.5.text-xs.border.border-gray-200.dark:border-slate-700.rounded-lg.bg-transparent.text-gray-900.dark:text-white', {
|
|
394
|
-
placeholder: '
|
|
743
|
+
m('div.flex.flex-wrap.items-center.gap-2.5.w-full.sm:w-auto', [
|
|
744
|
+
m('input.px-3.py-1.5.text-xs.border.border-gray-200.dark:border-slate-700.rounded-lg.bg-transparent.text-gray-900.dark:text-white.w-48', {
|
|
745
|
+
placeholder: 'Search event or payload...',
|
|
395
746
|
value: filterEvent,
|
|
396
747
|
oninput: function(e) { filterEvent = e.target.value; },
|
|
748
|
+
onkeydown: function(e) { if (e.key === 'Enter') { deliveryPage = 1; loadDeliveries(); } },
|
|
397
749
|
}),
|
|
398
750
|
m('select.px-3.py-1.5.text-xs.border.border-gray-200.dark:border-slate-700.rounded-lg.bg-transparent.text-gray-900.dark:text-white', {
|
|
399
751
|
value: filterSuccess,
|
|
400
|
-
onchange: function(e) { filterSuccess = e.target.value; },
|
|
752
|
+
onchange: function(e) { filterSuccess = e.target.value; deliveryPage = 1; loadDeliveries(); },
|
|
401
753
|
}, [
|
|
402
754
|
m('option', { value: '' }, 'All Statuses'),
|
|
403
|
-
m('option', { value: 'true' }, 'Success
|
|
404
|
-
m('option', { value: 'false' }, 'Failed
|
|
755
|
+
m('option', { value: 'true' }, 'Success (2xx)'),
|
|
756
|
+
m('option', { value: 'false' }, 'Failed'),
|
|
757
|
+
]),
|
|
758
|
+
m('select.px-3.py-1.5.text-xs.border.border-gray-200.dark:border-slate-700.rounded-lg.bg-transparent.text-gray-900.dark:text-white', {
|
|
759
|
+
value: filterEndpointId,
|
|
760
|
+
onchange: function(e) { filterEndpointId = e.target.value; deliveryPage = 1; loadDeliveries(); },
|
|
761
|
+
}, [
|
|
762
|
+
m('option', { value: '' }, 'All Endpoints'),
|
|
763
|
+
endpoints.map(function(ep) {
|
|
764
|
+
return m('option', { value: String(ep.id) }, ep.name + ' (#' + ep.id + ')');
|
|
765
|
+
}),
|
|
405
766
|
]),
|
|
406
767
|
m('button.px-3.py-1.5.text-xs.font-medium.rounded-lg.bg-gray-100.dark:bg-slate-700.text-gray-700.dark:text-slate-200.hover:bg-gray-200', {
|
|
407
768
|
onclick: function() { deliveryPage = 1; loadDeliveries(); },
|
|
408
769
|
}, 'Filter'),
|
|
409
770
|
]),
|
|
410
|
-
m('div.
|
|
771
|
+
m('div.flex.items-center.gap-3', [
|
|
772
|
+
selectedCount > 0 ? m('button.px-3.py-1.5.text-xs.font-semibold.rounded-lg.bg-indigo-600.text-white.hover:bg-indigo-500.transition-colors.flex.items-center.gap-1.5', {
|
|
773
|
+
disabled: bulkRetrying,
|
|
774
|
+
onclick: bulkRetrySelected,
|
|
775
|
+
}, [
|
|
776
|
+
bulkRetrying ? m('span.animate-spin', '⟳') : null,
|
|
777
|
+
'Retry Selected (' + selectedCount + ')',
|
|
778
|
+
]) : null,
|
|
779
|
+
m('div.text-xs.text-gray-500.dark:text-slate-400', 'Total: ' + deliveryTotal + ' deliveries'),
|
|
780
|
+
]),
|
|
411
781
|
]),
|
|
412
782
|
|
|
413
783
|
// Deliveries Table
|
|
414
784
|
m('div.bg-white.dark:bg-slate-800.border.border-gray-200.dark:border-slate-700.rounded-2xl.overflow-hidden.shadow-sm', [
|
|
415
785
|
deliveries.length === 0 ? m('div.p-12.text-center.text-gray-500.dark:text-slate-400', [
|
|
416
|
-
m('p.text-base.font-medium', 'No delivery records found
|
|
786
|
+
m('p.text-base.font-medium', 'No delivery records found.'),
|
|
787
|
+
m('p.text-xs.mt-1', 'Deliveries will appear here automatically when events are triggered or test pings sent.'),
|
|
417
788
|
]) : m('div.overflow-x-auto', [
|
|
418
789
|
m('table.w-full.text-left.text-sm', [
|
|
419
790
|
m('thead.bg-gray-50.dark:bg-slate-750.text-xs.uppercase.text-gray-500.dark:text-slate-400.border-b.border-gray-200.dark:border-slate-700', [
|
|
420
791
|
m('tr', [
|
|
792
|
+
m('th.p-4.w-8', [
|
|
793
|
+
m('input[type=checkbox]', {
|
|
794
|
+
checked: allSelected,
|
|
795
|
+
onchange: function(e) { toggleSelectAllDeliveries(e.target.checked); },
|
|
796
|
+
}),
|
|
797
|
+
]),
|
|
421
798
|
m('th.p-4', 'Status'),
|
|
422
|
-
m('th.p-4', 'Event'),
|
|
799
|
+
m('th.p-4', 'Event Name'),
|
|
800
|
+
m('th.p-4', 'Target Endpoint'),
|
|
423
801
|
m('th.p-4', 'Duration'),
|
|
424
802
|
m('th.p-4', 'Attempt'),
|
|
425
|
-
m('th.p-4', '
|
|
803
|
+
m('th.p-4', 'Dispatched At'),
|
|
426
804
|
m('th.p-4.text-right', 'Actions'),
|
|
427
805
|
]),
|
|
428
806
|
]),
|
|
@@ -431,9 +809,18 @@ function generateWebhooksComponent(options = {}) {
|
|
|
431
809
|
var badgeClass = isSuccess
|
|
432
810
|
? 'bg-emerald-50 text-emerald-700 border-emerald-200 dark:bg-emerald-950/40 dark:text-emerald-300'
|
|
433
811
|
: 'bg-rose-50 text-rose-700 border-rose-200 dark:bg-rose-950/40 dark:text-rose-300';
|
|
434
|
-
var statusLabel = dlv.status_code ? 'HTTP ' + dlv.status_code : (isSuccess ? '200 OK' : '
|
|
812
|
+
var statusLabel = dlv.status_code ? 'HTTP ' + dlv.status_code : (isSuccess ? '200 OK' : 'Failed');
|
|
813
|
+
var isSelected = !!selectedDeliveryIds[dlv.id];
|
|
435
814
|
|
|
436
|
-
return m('tr.hover:bg-gray-50/60.dark:hover:bg-slate-750/50.transition-colors',
|
|
815
|
+
return m('tr.hover:bg-gray-50/60.dark:hover:bg-slate-750/50.transition-colors', {
|
|
816
|
+
class: isSelected ? 'bg-indigo-50/30 dark:bg-indigo-950/20' : '',
|
|
817
|
+
}, [
|
|
818
|
+
m('td.p-4', [
|
|
819
|
+
m('input[type=checkbox]', {
|
|
820
|
+
checked: isSelected,
|
|
821
|
+
onchange: function(e) { selectedDeliveryIds[dlv.id] = e.target.checked; },
|
|
822
|
+
}),
|
|
823
|
+
]),
|
|
437
824
|
m('td.p-4', [
|
|
438
825
|
m('span.inline-flex.items-center.px-2.5.py-0.5.rounded-full.text-xs.font-semibold.border', {
|
|
439
826
|
class: badgeClass,
|
|
@@ -441,19 +828,22 @@ function generateWebhooksComponent(options = {}) {
|
|
|
441
828
|
]),
|
|
442
829
|
m('td.p-4', [
|
|
443
830
|
m('span.font-mono.font-semibold.text-gray-900.dark:text-white', dlv.event),
|
|
444
|
-
m('div.text-xs.text-gray-400', '
|
|
831
|
+
m('div.text-xs.font-mono.text-gray-400', 'ID: #' + dlv.id),
|
|
832
|
+
]),
|
|
833
|
+
m('td.p-4', [
|
|
834
|
+
m('div.text-xs.font-medium.text-gray-800.dark:text-slate-200', 'Endpoint #' + dlv.endpoint_id),
|
|
445
835
|
]),
|
|
446
836
|
m('td.p-4.text-xs.text-gray-600.dark:text-slate-300', (dlv.duration_ms != null ? dlv.duration_ms + ' ms' : '—')),
|
|
447
837
|
m('td.p-4.text-xs.text-gray-600.dark:text-slate-300', dlv.attempt + ' / ' + dlv.max_attempts),
|
|
448
838
|
m('td.p-4.text-xs.text-gray-500.dark:text-slate-400', formatRelativeTime(dlv.created_at)),
|
|
449
839
|
m('td.p-4.text-right', [
|
|
450
|
-
m('div.inline-flex.items-center.gap-
|
|
451
|
-
m('button.px-2.5.py-1.text-xs.font-medium.rounded-lg.border.border-gray-200.dark:border-slate-700.text-indigo-600.hover:bg-indigo-50.dark:hover:bg-slate-700', {
|
|
452
|
-
onclick: function() { activeDeliveryModal = dlv; },
|
|
453
|
-
}, '
|
|
454
|
-
|
|
840
|
+
m('div.inline-flex.items-center.gap-1.5', [
|
|
841
|
+
m('button.px-2.5.py-1.text-xs.font-medium.rounded-lg.border.border-gray-200.dark:border-slate-700.text-indigo-600.dark:text-indigo-400.hover:bg-indigo-50.dark:hover:bg-slate-700', {
|
|
842
|
+
onclick: function() { activeDeliveryModal = dlv; replayEditMode = false; },
|
|
843
|
+
}, 'Inspect'),
|
|
844
|
+
m('button.px-2.5.py-1.text-xs.font-medium.rounded-lg.bg-gray-100.dark:bg-slate-700.text-gray-700.dark:text-slate-200.hover:bg-gray-200', {
|
|
455
845
|
onclick: function() { retryDelivery(dlv); },
|
|
456
|
-
}, 'Retry')
|
|
846
|
+
}, 'Retry'),
|
|
457
847
|
]),
|
|
458
848
|
]),
|
|
459
849
|
]);
|
|
@@ -479,26 +869,120 @@ function generateWebhooksComponent(options = {}) {
|
|
|
479
869
|
]),
|
|
480
870
|
]) : null,
|
|
481
871
|
|
|
482
|
-
// MODAL:
|
|
872
|
+
// MODAL 1: INTERACTIVE PAYLOAD & PING TESTER
|
|
873
|
+
showTestModal && testEndpointTarget ? m('div.fixed.inset-0.z-50.flex.items-center.justify-center.p-4.bg-black/50.backdrop-blur-sm', [
|
|
874
|
+
m('div.bg-white.dark:bg-slate-800.rounded-2xl.border.border-gray-200.dark:border-slate-700.shadow-2xl.w-full.max-w-2xl.max-h-[92vh].flex.flex-col.overflow-hidden', [
|
|
875
|
+
m('div.p-5.border-b.border-gray-200.dark:border-slate-700.flex.items-center.justify-between', [
|
|
876
|
+
m('div', [
|
|
877
|
+
m('h3.text-base.font-bold.text-gray-900.dark:text-white', 'Live Webhook Tester'),
|
|
878
|
+
m('p.text-xs.text-indigo-600.dark:text-indigo-400.font-mono.mt-0.5', testEndpointTarget.name + ' (' + testEndpointTarget.url + ')'),
|
|
879
|
+
]),
|
|
880
|
+
m('button.text-gray-400.hover:text-gray-600.dark:hover:text-white', {
|
|
881
|
+
onclick: function() { showTestModal = false; },
|
|
882
|
+
}, '✕'),
|
|
883
|
+
]),
|
|
884
|
+
m('div.p-5.space-y-4.overflow-y-auto.flex-1', [
|
|
885
|
+
// Preset Event Selector
|
|
886
|
+
m('div', [
|
|
887
|
+
m('label.block.text-xs.font-semibold.text-gray-700.dark:text-slate-300.mb-1.5', 'Select Event Preset:'),
|
|
888
|
+
m('div.grid.grid-cols-2.sm:grid-cols-3.gap-2', Object.keys(EVENT_PRESETS).map(function(key) {
|
|
889
|
+
var preset = EVENT_PRESETS[key];
|
|
890
|
+
var isSelected = testEvent === key;
|
|
891
|
+
return m('button.px-3.py-2.text-xs.font-medium.rounded-xl.border.text-left.transition-all', {
|
|
892
|
+
class: isSelected
|
|
893
|
+
? 'border-indigo-600 bg-indigo-50/50 text-indigo-700 dark:border-indigo-400 dark:bg-indigo-950/40 dark:text-indigo-300'
|
|
894
|
+
: 'border-gray-200 dark:border-slate-700 text-gray-700 dark:text-slate-300 hover:bg-gray-50 dark:hover:bg-slate-750',
|
|
895
|
+
onclick: function() { setEventPreset(key); },
|
|
896
|
+
}, preset.label);
|
|
897
|
+
})),
|
|
898
|
+
]),
|
|
899
|
+
|
|
900
|
+
// Custom Event Name (if custom)
|
|
901
|
+
m('div', [
|
|
902
|
+
m('label.block.text-xs.font-semibold.text-gray-700.dark:text-slate-300.mb-1', 'Event Name (X-Webspresso-Event)'),
|
|
903
|
+
m('input.w-full.px-3.py-2.text-xs.font-mono.border.border-gray-300.dark:border-slate-600.rounded-xl.bg-transparent.text-gray-900.dark:text-white', {
|
|
904
|
+
value: testEvent,
|
|
905
|
+
oninput: function(e) { testEvent = e.target.value; },
|
|
906
|
+
}),
|
|
907
|
+
]),
|
|
908
|
+
|
|
909
|
+
// Payload JSON Editor
|
|
910
|
+
m('div', [
|
|
911
|
+
m('div.flex.items-center.justify-between.mb-1', [
|
|
912
|
+
m('label.text-xs.font-semibold.text-gray-700.dark:text-slate-300', 'Request Payload (JSON)'),
|
|
913
|
+
m('button.text-xs.text-indigo-600.dark:text-indigo-400.hover:underline', {
|
|
914
|
+
onclick: function() {
|
|
915
|
+
try {
|
|
916
|
+
testPayloadStr = JSON.stringify(JSON.parse(testPayloadStr), null, 2);
|
|
917
|
+
} catch (e) {
|
|
918
|
+
alert('Syntax Error: ' + e.message);
|
|
919
|
+
}
|
|
920
|
+
},
|
|
921
|
+
}, 'Prettify JSON'),
|
|
922
|
+
]),
|
|
923
|
+
m('textarea.w-full.h-36.p-3.font-mono.text-xs.border.border-gray-300.dark:border-slate-600.rounded-xl.bg-slate-900.text-slate-100.focus:outline-none', {
|
|
924
|
+
value: testPayloadStr,
|
|
925
|
+
oninput: function(e) { testPayloadStr = e.target.value; },
|
|
926
|
+
}),
|
|
927
|
+
]),
|
|
928
|
+
|
|
929
|
+
// Live Result Box
|
|
930
|
+
testResult ? m('div.p-4.rounded-xl.border', {
|
|
931
|
+
class: testResult.success
|
|
932
|
+
? 'bg-emerald-50/50 border-emerald-200 dark:bg-emerald-950/20 dark:border-emerald-800'
|
|
933
|
+
: 'bg-rose-50/50 border-rose-200 dark:bg-rose-950/20 dark:border-rose-800'
|
|
934
|
+
}, [
|
|
935
|
+
m('div.flex.items-center.justify-between.mb-2', [
|
|
936
|
+
m('div.flex.items-center.gap-2', [
|
|
937
|
+
m('span.text-xs.font-bold.px-2.py-0.5.rounded-md', {
|
|
938
|
+
class: testResult.success ? 'bg-emerald-600 text-white' : 'bg-rose-600 text-white'
|
|
939
|
+
}, testResult.statusCode ? 'HTTP ' + testResult.statusCode : (testResult.success ? '200 OK' : 'FAILED')),
|
|
940
|
+
m('span.text-xs.font-semibold.text-gray-700.dark:text-slate-200', '⏱️ ' + (testResult.durationMs || 0) + ' ms'),
|
|
941
|
+
]),
|
|
942
|
+
m('span.text-xs.text-gray-500', 'Delivery ID: #' + (testResult.deliveryId || '—')),
|
|
943
|
+
]),
|
|
944
|
+
testResult.error ? m('div.text-xs.text-rose-600.dark:text-rose-400.font-medium.mb-2', testResult.error) : null,
|
|
945
|
+
testResult.responseBody ? m('div', [
|
|
946
|
+
m('div.text-xs.font-semibold.text-gray-600.dark:text-slate-400.mb-1', 'Server Response Body:'),
|
|
947
|
+
m('pre.p-2.rounded-lg.bg-slate-900.text-slate-100.text-xs.font-mono.overflow-x-auto.max-h-28', testResult.responseBody),
|
|
948
|
+
]) : null,
|
|
949
|
+
]) : null,
|
|
950
|
+
]),
|
|
951
|
+
m('div.p-4.border-t.border-gray-200.dark:border-slate-700.flex.items-center.justify-end.gap-3', [
|
|
952
|
+
m('button.px-4.py-2.text-xs.font-medium.rounded-xl.border.border-gray-300.dark:border-slate-600.text-gray-700.dark:text-slate-200', {
|
|
953
|
+
onclick: function() { showTestModal = false; },
|
|
954
|
+
}, 'Close'),
|
|
955
|
+
m('button.px-4.py-2.text-xs.font-semibold.rounded-xl.bg-indigo-600.text-white.hover:bg-indigo-500.flex.items-center.gap-2', {
|
|
956
|
+
disabled: testInProgress,
|
|
957
|
+
onclick: runWebhookTest,
|
|
958
|
+
}, [
|
|
959
|
+
testInProgress ? m('span.animate-spin', '⟳') : m('span', '⚡'),
|
|
960
|
+
testInProgress ? 'Dispatching...' : 'Send Webhook Test',
|
|
961
|
+
]),
|
|
962
|
+
]),
|
|
963
|
+
]),
|
|
964
|
+
]) : null,
|
|
965
|
+
|
|
966
|
+
// MODAL 2: CREATE / EDIT ENDPOINT
|
|
483
967
|
showEndpointModal ? m('div.fixed.inset-0.z-50.flex.items-center.justify-center.p-4.bg-black/50.backdrop-blur-sm', [
|
|
484
968
|
m('div.bg-white.dark:bg-slate-800.rounded-2xl.border.border-gray-200.dark:border-slate-700.shadow-2xl.w-full.max-w-lg.p-6.space-y-4', [
|
|
485
969
|
m('div.flex.items-center.justify-between', [
|
|
486
|
-
m('h3.text-lg.font-bold.text-gray-900.dark:text-white', editingEndpoint ? 'Edit Endpoint' : 'New Webhook Endpoint'),
|
|
970
|
+
m('h3.text-lg.font-bold.text-gray-900.dark:text-white', editingEndpoint ? 'Edit Webhook Endpoint' : 'New Webhook Endpoint'),
|
|
487
971
|
m('button.text-gray-400.hover:text-gray-600.dark:hover:text-white', {
|
|
488
972
|
onclick: function() { showEndpointModal = false; },
|
|
489
973
|
}, '✕'),
|
|
490
974
|
]),
|
|
491
975
|
m('div.space-y-3', [
|
|
492
976
|
m('div', [
|
|
493
|
-
m('label.block.text-xs.font-semibold.text-gray-700.dark:text-slate-300.mb-1', 'Name /
|
|
977
|
+
m('label.block.text-xs.font-semibold.text-gray-700.dark:text-slate-300.mb-1', 'Name / Identifier *'),
|
|
494
978
|
m('input.w-full.px-3.py-2.text-sm.border.border-gray-300.dark:border-slate-600.rounded-xl.bg-transparent.text-gray-900.dark:text-white', {
|
|
495
|
-
placeholder: 'e.g.
|
|
979
|
+
placeholder: 'e.g. Stripe Order Webhook',
|
|
496
980
|
value: endpointForm.name,
|
|
497
981
|
oninput: function(e) { endpointForm.name = e.target.value; },
|
|
498
982
|
}),
|
|
499
983
|
]),
|
|
500
984
|
m('div', [
|
|
501
|
-
m('label.block.text-xs.font-semibold.text-gray-700.dark:text-slate-300.mb-1', '
|
|
985
|
+
m('label.block.text-xs.font-semibold.text-gray-700.dark:text-slate-300.mb-1', 'Destination URL *'),
|
|
502
986
|
m('input.w-full.px-3.py-2.text-sm.border.border-gray-300.dark:border-slate-600.rounded-xl.bg-transparent.text-gray-900.dark:text-white', {
|
|
503
987
|
placeholder: 'https://example.com/api/webhook',
|
|
504
988
|
value: endpointForm.url,
|
|
@@ -507,7 +991,7 @@ function generateWebhooksComponent(options = {}) {
|
|
|
507
991
|
]),
|
|
508
992
|
m('div', [
|
|
509
993
|
m('div.flex.items-center.justify-between.mb-1', [
|
|
510
|
-
m('label.text-xs.font-semibold.text-gray-700.dark:text-slate-300', 'Signing Secret'),
|
|
994
|
+
m('label.text-xs.font-semibold.text-gray-700.dark:text-slate-300', 'HMAC Signing Secret'),
|
|
511
995
|
m('button.text-xs.text-indigo-600.dark:text-indigo-400.hover:underline', {
|
|
512
996
|
type: 'button',
|
|
513
997
|
onclick: function() { endpointForm.secret = generateRandomSecret(); },
|
|
@@ -519,20 +1003,28 @@ function generateWebhooksComponent(options = {}) {
|
|
|
519
1003
|
}),
|
|
520
1004
|
]),
|
|
521
1005
|
m('div', [
|
|
522
|
-
m('label.block.text-xs.font-semibold.text-gray-700.dark:text-slate-300.mb-1', 'Subscribed Events (Comma-separated
|
|
1006
|
+
m('label.block.text-xs.font-semibold.text-gray-700.dark:text-slate-300.mb-1', 'Subscribed Events (Comma-separated or * for wildcard)'),
|
|
523
1007
|
m('input.w-full.px-3.py-2.text-sm.border.border-gray-300.dark:border-slate-600.rounded-xl.bg-transparent.text-gray-900.dark:text-white', {
|
|
524
|
-
placeholder: '
|
|
1008
|
+
placeholder: 'order.*, user.registered, ping',
|
|
525
1009
|
value: endpointForm.events,
|
|
526
1010
|
oninput: function(e) { endpointForm.events = e.target.value; },
|
|
527
1011
|
}),
|
|
528
1012
|
]),
|
|
1013
|
+
m('div', [
|
|
1014
|
+
m('label.block.text-xs.font-semibold.text-gray-700.dark:text-slate-300.mb-1', 'Description (Optional)'),
|
|
1015
|
+
m('input.w-full.px-3.py-2.text-sm.border.border-gray-300.dark:border-slate-600.rounded-xl.bg-transparent.text-gray-900.dark:text-white', {
|
|
1016
|
+
placeholder: 'Target external service notes...',
|
|
1017
|
+
value: endpointForm.description,
|
|
1018
|
+
oninput: function(e) { endpointForm.description = e.target.value; },
|
|
1019
|
+
}),
|
|
1020
|
+
]),
|
|
529
1021
|
m('div.flex.items-center.gap-2.pt-1', [
|
|
530
1022
|
m('input[type=checkbox]', {
|
|
531
1023
|
id: 'active_check',
|
|
532
1024
|
checked: endpointForm.is_active,
|
|
533
1025
|
onchange: function(e) { endpointForm.is_active = e.target.checked; },
|
|
534
1026
|
}),
|
|
535
|
-
m('label.text-xs.font-medium.text-gray-700.dark:text-slate-300', { for: 'active_check' }, 'Enable this endpoint to receive events'),
|
|
1027
|
+
m('label.text-xs.font-medium.text-gray-700.dark:text-slate-300', { for: 'active_check' }, 'Enable this endpoint to actively receive matching events'),
|
|
536
1028
|
]),
|
|
537
1029
|
]),
|
|
538
1030
|
m('div.flex.items-center.justify-end.gap-3.pt-3.border-t.border-gray-100.dark:border-slate-700', [
|
|
@@ -541,34 +1033,61 @@ function generateWebhooksComponent(options = {}) {
|
|
|
541
1033
|
}, 'Cancel'),
|
|
542
1034
|
m('button.px-4.py-2.text-xs.font-semibold.rounded-xl.bg-indigo-600.text-white.hover:bg-indigo-500', {
|
|
543
1035
|
onclick: saveEndpoint,
|
|
544
|
-
}, editingEndpoint ? 'Update' : '
|
|
1036
|
+
}, editingEndpoint ? 'Update Endpoint' : 'Create Endpoint'),
|
|
545
1037
|
]),
|
|
546
1038
|
]),
|
|
547
1039
|
]) : null,
|
|
548
1040
|
|
|
549
|
-
// MODAL: DELIVERY DETAILS
|
|
1041
|
+
// MODAL 3: DELIVERY DETAILS & REPLAY
|
|
550
1042
|
activeDeliveryModal ? m('div.fixed.inset-0.z-50.flex.items-center.justify-center.p-4.bg-black/50.backdrop-blur-sm', [
|
|
551
|
-
m('div.bg-white.dark:bg-slate-800.rounded-2xl.border.border-gray-200.dark:border-slate-700.shadow-2xl.w-full.max-w-2xl.max-h-[
|
|
1043
|
+
m('div.bg-white.dark:bg-slate-800.rounded-2xl.border.border-gray-200.dark:border-slate-700.shadow-2xl.w-full.max-w-2xl.max-h-[92vh].flex.flex-col.overflow-hidden', [
|
|
552
1044
|
m('div.p-5.border-b.border-gray-200.dark:border-slate-700.flex.items-center.justify-between', [
|
|
553
1045
|
m('div', [
|
|
554
|
-
m('h3.text-base.font-bold.text-gray-900.dark:text-white', 'Delivery
|
|
1046
|
+
m('h3.text-base.font-bold.text-gray-900.dark:text-white', 'Delivery Inspection #' + activeDeliveryModal.id),
|
|
555
1047
|
m('span.text-xs.text-gray-500.dark:text-slate-400', activeDeliveryModal.event + ' — ' + formatRelativeTime(activeDeliveryModal.created_at)),
|
|
556
1048
|
]),
|
|
557
1049
|
m('button.text-gray-400.hover:text-gray-600.dark:hover:text-white', {
|
|
558
|
-
onclick: function() { activeDeliveryModal = null; },
|
|
1050
|
+
onclick: function() { activeDeliveryModal = null; replayEditMode = false; },
|
|
559
1051
|
}, '✕'),
|
|
560
1052
|
]),
|
|
561
1053
|
m('div.p-5.space-y-4.overflow-y-auto.flex-1', [
|
|
562
|
-
m('div.grid.grid-cols-2.sm:grid-cols-
|
|
563
|
-
m('div', [
|
|
564
|
-
|
|
565
|
-
|
|
1054
|
+
m('div.grid.grid-cols-2.sm:grid-cols-4.gap-2.text-xs.p-3.bg-gray-50.dark:bg-slate-750.rounded-xl', [
|
|
1055
|
+
m('div', [
|
|
1056
|
+
m('span.text-gray-400.block', 'Status'),
|
|
1057
|
+
m('span.font-semibold', {
|
|
1058
|
+
class: activeDeliveryModal.success ? 'text-emerald-600' : 'text-rose-600'
|
|
1059
|
+
}, activeDeliveryModal.success ? '200 OK' : ('HTTP ' + (activeDeliveryModal.status_code || 'Error'))),
|
|
1060
|
+
]),
|
|
1061
|
+
m('div', [m('span.text-gray-400.block', 'Latency'), m('span.font-semibold', (activeDeliveryModal.duration_ms || 0) + ' ms')]),
|
|
566
1062
|
m('div', [m('span.text-gray-400.block', 'Attempt'), m('span.font-semibold', activeDeliveryModal.attempt + ' / ' + activeDeliveryModal.max_attempts)]),
|
|
567
|
-
m('div
|
|
1063
|
+
m('div', [m('span.text-gray-400.block', 'Endpoint ID'), m('span.font-semibold', '#' + activeDeliveryModal.endpoint_id)]),
|
|
1064
|
+
activeDeliveryModal.error ? m('div.col-span-2.sm:col-span-4.mt-1', [
|
|
1065
|
+
m('span.text-gray-400.block', 'Error Message'),
|
|
1066
|
+
m('span.text-rose-600.font-medium', activeDeliveryModal.error),
|
|
1067
|
+
]) : null,
|
|
568
1068
|
]),
|
|
1069
|
+
|
|
1070
|
+
// Payload JSON
|
|
569
1071
|
m('div', [
|
|
570
|
-
m('
|
|
571
|
-
|
|
1072
|
+
m('div.flex.items-center.justify-between.mb-1', [
|
|
1073
|
+
m('label.text-xs.font-semibold.text-gray-700.dark:text-slate-300', 'Dispatched Payload (JSON)'),
|
|
1074
|
+
m('button.text-xs.text-indigo-600.dark:text-indigo-400.hover:underline', {
|
|
1075
|
+
onclick: function() {
|
|
1076
|
+
replayEditMode = !replayEditMode;
|
|
1077
|
+
if (replayEditMode) {
|
|
1078
|
+
try {
|
|
1079
|
+
replayPayloadStr = JSON.stringify(JSON.parse(activeDeliveryModal.payload), null, 2);
|
|
1080
|
+
} catch (e) {
|
|
1081
|
+
replayPayloadStr = activeDeliveryModal.payload || '';
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
},
|
|
1085
|
+
}, replayEditMode ? 'Cancel Edit' : 'Edit Payload for Replay'),
|
|
1086
|
+
]),
|
|
1087
|
+
replayEditMode ? m('textarea.w-full.h-36.p-3.font-mono.text-xs.border.border-gray-300.dark:border-slate-600.rounded-xl.bg-slate-900.text-slate-100', {
|
|
1088
|
+
value: replayPayloadStr,
|
|
1089
|
+
oninput: function(e) { replayPayloadStr = e.target.value; },
|
|
1090
|
+
}) : m('pre.p-3.rounded-xl.bg-slate-900.text-slate-100.text-xs.font-mono.overflow-x-auto.max-h-56',
|
|
572
1091
|
(function() {
|
|
573
1092
|
try {
|
|
574
1093
|
return JSON.stringify(JSON.parse(activeDeliveryModal.payload), null, 2);
|
|
@@ -578,16 +1097,24 @@ function generateWebhooksComponent(options = {}) {
|
|
|
578
1097
|
})()
|
|
579
1098
|
),
|
|
580
1099
|
]),
|
|
1100
|
+
|
|
1101
|
+
// Response body
|
|
581
1102
|
activeDeliveryModal.response_body ? m('div', [
|
|
582
|
-
m('label.block.text-xs.font-semibold.text-gray-700.dark:text-slate-300.mb-1', 'Target Response Body'),
|
|
583
|
-
m('pre.p-3.rounded-xl.bg-slate-900.text-slate-100.text-xs.font-mono.overflow-x-auto.max-h-
|
|
1103
|
+
m('label.block.text-xs.font-semibold.text-gray-700.dark:text-slate-300.mb-1', 'Target Server Response Body'),
|
|
1104
|
+
m('pre.p-3.rounded-xl.bg-slate-900.text-slate-100.text-xs.font-mono.overflow-x-auto.max-h-36',
|
|
584
1105
|
activeDeliveryModal.response_body
|
|
585
1106
|
),
|
|
586
1107
|
]) : null,
|
|
587
1108
|
]),
|
|
588
|
-
m('div.p-4.border-t.border-gray-200.dark:border-slate-700.flex.justify-
|
|
589
|
-
m('button.px-4.py-2.text-xs.font-semibold.rounded-xl.bg-indigo-600.text-white.hover:bg-indigo-500', {
|
|
590
|
-
onclick:
|
|
1109
|
+
m('div.p-4.border-t.border-gray-200.dark:border-slate-700.flex.items-center.justify-between', [
|
|
1110
|
+
m('button.px-4.py-2.text-xs.font-semibold.rounded-xl.bg-indigo-600.text-white.hover:bg-indigo-500.flex.items-center.gap-1.5', {
|
|
1111
|
+
onclick: replayActiveDelivery,
|
|
1112
|
+
}, [
|
|
1113
|
+
m('span', '⟳'),
|
|
1114
|
+
replayEditMode ? 'Replay with Edited Payload' : 'Replay Delivery Now',
|
|
1115
|
+
]),
|
|
1116
|
+
m('button.px-4.py-2.text-xs.font-medium.rounded-xl.border.border-gray-300.dark:border-slate-600.text-gray-700.dark:text-slate-200', {
|
|
1117
|
+
onclick: function() { activeDeliveryModal = null; replayEditMode = false; },
|
|
591
1118
|
}, 'Close'),
|
|
592
1119
|
]),
|
|
593
1120
|
]),
|