From 842a68a9affbecba8b2cf382ca250237447a2c6d Mon Sep 17 00:00:00 2001 From: Soumajit Ghosh Date: Thu, 20 Aug 2026 16:28:11 +0530 Subject: [PATCH] fix(analytics): validate missing event envelope --- src/lib/Insights/adapters/PlausibleAdapter.js | 4 +++- src/tests/lib/Insights/adapters/PlausibleAdapter.test.js | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib/Insights/adapters/PlausibleAdapter.js b/src/lib/Insights/adapters/PlausibleAdapter.js index 739a0115..6c1815e9 100644 --- a/src/lib/Insights/adapters/PlausibleAdapter.js +++ b/src/lib/Insights/adapters/PlausibleAdapter.js @@ -25,7 +25,9 @@ export class PlausibleAdapter { return `${this.env.PUBLIC_ANALYTICS_API_HOST}/api/event`; } - async forwardEvent(envelope, requestContext) { + async forwardEvent(envelope = {}, requestContext) { + // Disabled analytics intentionally ignores malformed events so local development + // and tests without a complete analytics configuration remain quiet. if (!this.isEnabled()) { return { status: 'analytics disabled' }; } diff --git a/src/tests/lib/Insights/adapters/PlausibleAdapter.test.js b/src/tests/lib/Insights/adapters/PlausibleAdapter.test.js index 5364216b..32339ed6 100644 --- a/src/tests/lib/Insights/adapters/PlausibleAdapter.test.js +++ b/src/tests/lib/Insights/adapters/PlausibleAdapter.test.js @@ -102,6 +102,12 @@ describe('PlausibleAdapter.forwardEvent', () => { ).rejects.toThrow('forwardEvent requires name and url'); }); + it('throws a clear validation error when called without an envelope', async () => { + await expect(new PlausibleAdapter(fullEnv).forwardEvent()).rejects.toThrow( + 'forwardEvent requires name and url' + ); + }); + it('POSTs to {apiHost}/api/event', async () => { await new PlausibleAdapter(fullEnv).forwardEvent(envelope, ctx); expect(global.fetch).toHaveBeenCalledWith(