-
Notifications
You must be signed in to change notification settings - Fork 559
feat: add webhook producer to service-utils #7439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add webhook producer to service-utils #7439
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
🦋 Changeset detectedLatest commit: 4233f2e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughA new webhook producer feature is introduced in the Changes
Sequence Diagram(s)sequenceDiagram
participant App as Application
participant WEP as WebhookEventProducer
participant KP as KafkaProducer
App->>WEP: new WebhookEventProducer({ kafkaProducer: KP })
App->>WEP: sendEvents(topic, events)
WEP->>WEP: Validate and normalize events
WEP->>KP: sendEvents(topic, normalizedEvents)
KP-->>WEP: Promise resolved/rejected
WEP-->>App: Promise resolved/rejected
sequenceDiagram
participant App as Application
participant U2P as UsageV2Producer
participant KP as KafkaProducer
App->>U2P: new UsageV2Producer({ kafkaProducer: KP, source })
App->>U2P: sendEvents(topic, events)
U2P->>KP: sendEvents(topic, mappedEvents)
KP-->>U2P: Promise resolved/rejected
U2P-->>App: Promise resolved/rejected
📜 Recent review detailsConfiguration used: CodeRabbit UI ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (3)
🧰 Additional context used📓 Path-based instructions (1)`**/*.@(ts|tsx)`: Accept a typed 'props' object and export a named function (e.g., export function MyComponent()). Combine class names via 'cn', expose 'className' prop if useful. ...
🧬 Code Graph Analysis (1)packages/service-utils/src/node/webhookProducer.ts (1)
⏰ Context from checks skipped due to timeout of 90000ms (9)
🔇 Additional comments (5)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7439 +/- ##
=======================================
Coverage 51.96% 51.96%
=======================================
Files 947 947
Lines 63820 63820
Branches 4214 4217 +3
=======================================
Hits 33163 33163
Misses 30551 30551
Partials 106 106
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
.changeset/slimy-tigers-trade.md
(1 hunks)packages/service-utils/README-shared-producer.md
(1 hunks)packages/service-utils/src/node/index.ts
(1 hunks)packages/service-utils/src/node/usageV2.ts
(2 hunks)packages/service-utils/src/node/webhookProducer.ts
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.@(ts|tsx)`: Accept a typed 'props' object and export a named function (e.g., export function MyComponent()). Combine class names via 'cn', expose 'className' prop if useful. ...
**/*.@(ts|tsx)
: Accept a typed 'props' object and export a named function (e.g., export function MyComponent()).
Combine class names via 'cn', expose 'className' prop if useful.
Reuse core UI primitives; avoid re-implementing buttons, cards, modals.
Local state or effects live inside; data fetching happens in hooks.
Merge class names with 'cn' from '@/lib/utils' to keep conditional logic readable.
Stick to design-tokens: background ('bg-card'), borders ('border-border'), muted text ('text-muted-foreground') etc.
Use the 'container' class with a 'max-w-7xl' cap for page width consistency.
Spacing utilities ('px-', 'py-', 'gap-*') are preferred over custom margins.
Responsive helpers follow mobile-first ('max-sm', 'md', 'lg', 'xl').
Never hard-code colors – always go through Tailwind variables.
Tailwind CSS is the styling system – avoid inline styles or CSS modules.
Prefix files with 'import "server-only";' so they never end up in the client bundle (for server-only code).
packages/service-utils/src/node/index.ts
packages/service-utils/src/node/webhookProducer.ts
packages/service-utils/src/node/usageV2.ts
🧬 Code Graph Analysis (1)
packages/service-utils/src/node/usageV2.ts (2)
packages/service-utils/src/node/kafka.ts (1)
KafkaProducer
(32-119)packages/service-utils/src/core/usageV2.ts (2)
UsageV2Source
(14-14)UsageV2Event
(82-87)
⏰ Context from checks skipped due to timeout of 90000ms (8)
- GitHub Check: Size
- GitHub Check: E2E Tests (pnpm, esbuild)
- GitHub Check: E2E Tests (pnpm, vite)
- GitHub Check: E2E Tests (pnpm, webpack)
- GitHub Check: Unit Tests
- GitHub Check: Build Packages
- GitHub Check: Lint Packages
- GitHub Check: Analyze (javascript)
🔇 Additional comments (7)
.changeset/slimy-tigers-trade.md (1)
1-6
: LGTM! Changelog entry is properly formatted.The changeset correctly identifies this as a minor version update for adding the new webhook producer feature.
packages/service-utils/src/node/index.ts (1)
22-22
: LGTM! Export statement follows existing patterns.The new export for the webhook producer is correctly formatted and positioned.
packages/service-utils/README-shared-producer.md (1)
1-67
: Excellent documentation for the shared producer pattern.The README provides clear examples and explains the benefits of sharing a KafkaProducer instance across multiple event producers. The code examples are syntactically correct and demonstrate both the recommended and legacy usage patterns effectively.
packages/service-utils/src/node/usageV2.ts (2)
23-63
: Well-implemented constructor pattern for shared producer support.The union type constructor correctly supports both shared KafkaProducer instances and individual connection parameters, following the same pattern as the new WebhookEventProducer.
75-89
: Prefix stripping logic is correct and simplified.The updated logic correctly strips the prefixes using fixed slice lengths:
- "team_" prefix (5 characters) →
slice(5)
- "prj_" prefix (4 characters) →
slice(4)
This is more efficient than using constants and the logic is sound.
packages/service-utils/src/node/webhookProducer.ts (2)
4-13
: Interface definition looks good.The WebhookEvent interface is well-defined with appropriate types and clear documentation for the payload field.
28-59
: Constructor pattern correctly implements shared producer support.The constructor follows the same union type pattern as UsageV2Producer, supporting both shared KafkaProducer instances and individual connection parameters.
size-limit report 📦
|
407bc2c
to
4233f2e
Compare
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
[SDK] Feature: Add webhook producer to service-utils
This PR adds a new
WebhookEventProducer
class to the service-utils package, enabling services to emit webhook events to Kafka topics. It also introduces a shared KafkaProducer pattern to improve efficiency when using multiple producers in the same service.Key changes:
WebhookEventProducer
class for sending webhook eventsUsageV2Producer
to support shared KafkaProducer instancesHow to test
The implementation can be tested by creating a shared KafkaProducer and using it with both UsageV2Producer and WebhookEventProducer as shown in the documentation.
Summary by CodeRabbit
PR-Codex overview
This PR introduces a new
WebhookEventProducer
class to the@thirdweb-dev/service-utils
package, enabling the emission of webhook events via Kafka. It also modifies theUsageV2Producer
to support a sharedKafkaProducer
instance.Detailed summary
WebhookEventProducer
class inpackages/service-utils/src/node/webhookProducer.ts
.sendEvents
method for emitting webhook events.UsageV2Producer
constructor to optionally accept a sharedKafkaProducer
.TEAM_ID_PREFIX
andPROJECT_ID_PREFIX
fromusageV2.ts
.WebhookEventProducer
frompackages/service-utils/src/node/index.ts
.