feat: add database record of webhook refresh attempts#440
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a persistent audit trail for webhook refresh operations by recording the outcome of each refreshWebhooks attempt (per run, per data source) in the database. This fits into the server’s webhook maintenance flow (cron + per-source refresh) and makes webhook lifecycle changes observable and debuggable.
Changes:
- Introduces a
webhookRefreshLogtable (migration + schema/model wiring) and repository helpers to write/read log rows. - Updates
DataSourceAdaptor.toggleWebhook()to return a structuredWebhookToggleResultand updates adaptors to populate it. - Enhances
refreshWebhooksto persist the toggle outcome/error, and adds feature/unit tests around the new behavior.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/server/adaptors/airtable.test.ts | Updates Airtable webhook toggle test to assert lifecycle actions/ids and adds timeout. |
| tests/setup.ts | Makes webhook test server startup awaitable to avoid unhandled async error events. |
| tests/feature/webhookRefreshLog.test.ts | Adds feature tests for JSONB round-tripping and job-driven log insertion. |
| src/server/services/database/schema.ts | Adds WebhookRefreshLog interface and registers it on the database schema type. |
| src/server/services/database/index.ts | Registers webhookRefreshLog table type on the Kysely Database interface. |
| src/server/repositories/WebhookRefreshLog.ts | New repository functions to insert logs and query by data source. |
| src/server/models/WebhookRefreshLog.ts | New Kysely table typings for webhookRefreshLog. |
| src/server/jobs/refreshWebhooks.ts | Generates a run id and writes audit rows per processed data source (success/failure). |
| src/server/adaptors/zetkin.ts | Updates adaptor to return WebhookToggleResult for unsupported webhooks (but signature currently mismatched). |
| src/server/adaptors/mailchimp.ts | Returns structured toggle results (created/kept/removed) with webhook ids. |
| src/server/adaptors/googlesheets.ts | Returns structured toggle results with sheet ids/details. |
| src/server/adaptors/csv.ts | Updates signature to return WebhookToggleResult (still throws Unimplemented). |
| src/server/adaptors/airtable.ts | Returns structured toggle results including expiration details. |
| src/server/adaptors/actionnetwork.ts | Returns noop structured result for unsupported webhooks. |
| src/server/adaptors/abstract.ts | Introduces WebhookToggleResult and updates DataSourceAdaptor.toggleWebhook contract. |
| src/models/WebhookRefreshLog.ts | Adds shared Zod schema + types for webhook refresh logs/actions. |
| migrations/1781568000000_webhook_refresh_log.ts | Creates webhookRefreshLog table + index for querying by dataSourceId/createdAt. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
420
to
426
| if (!enable) { | ||
| logger.info( | ||
| `Removing Airtable webhooks for data source ${this.dataSourceId}`, | ||
| ); | ||
| await this.removeWebhooks(webhooks); | ||
| return; | ||
| return { action: "removed", oldWebhookIds, newWebhookIds: [] }; | ||
| } |
Comment on lines
423
to
430
| // Remove webhooks on user request | ||
| if (!enable) { | ||
| logger.info( | ||
| `Removing Mailchimp webhooks for data source ${this.dataSourceId}`, | ||
| ); | ||
| await this.removeWebhooks(webhooks); | ||
| return; | ||
| return { action: "removed", oldWebhookIds, newWebhookIds: [] }; | ||
| } |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…ge/ts-mapped into feat/track-webhook-refresh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.