-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Include metadata field in lead.created and sale.created webhook payload
#2854
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds a nullable top-level Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client
participant API as Conversions API
participant Xform as Transform (lead/sale)
participant Schema as Webhook Schema
participant WH as Webhook Dispatcher
participant Sub as Subscriber
Client->>API: Track Lead/Sale (payload includes metadata)
API->>Xform: Build event object { ..., metadata }
Xform->>Schema: Parse/validate event (metadata: object | null)
Schema-->>Xform: Validated event
Xform-->>WH: Emit webhook { ..., metadata }
WH-->>Sub: Deliver webhook
Note over Xform,Schema: New nullable `metadata` field flows through validation and dispatch
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
lead.created and sale.created webhook payloadlead.created and sale.created webhook payload
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: 0
🧹 Nitpick comments (6)
apps/web/lib/webhook/sample-events/lead-created.json (2)
77-79: Add a concrete metadata example for clarityIncluding a small object (instead of null) better illustrates shape and keys. Optional but helpful for integrators.
Example:
"metadata": { "plan": "pro", "source": "newsletter" }
1-80: Consider using a documentation-reserved IP in samplesThe sample shows a real-looking IP. Prefer 203.0.113.0/24, 198.51.100.0/24, or 192.0.2.0/24 ranges in examples.
apps/web/lib/api/conversions/track-sale.ts (1)
424-435: Minor: add a comment to avoid future confusionsaleData.metadata remains stringified for Tinybird ingestion, while webhook uses the raw object via the later spread. A brief comment near the saleData construction would prevent regressions.
apps/web/lib/api/conversions/track-lead.ts (1)
160-171: Verify metadata serialization consistency across pathsYou stringify metadata for Tinybird ingestion elsewhere; here you forward the raw object for the webhook. That’s fine—just ensure docs note: storage = string, webhook = object.
apps/web/lib/webhook/schemas.ts (2)
26-26: Schema addition looks good; add a brief descriptionmetadata: z.record(z.unknown()).nullable().default(null) is fine. Consider .describe("Arbitrary user-provided key-value metadata") to improve OpenAPI.
35-35: Mirror description on sale schema and confirm OpenAPI includes itEnsure the generated spec surfaces metadata under both lead.created and sale.created events.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
apps/web/lib/api/conversions/track-lead.ts(1 hunks)apps/web/lib/api/conversions/track-sale.ts(1 hunks)apps/web/lib/webhook/sample-events/lead-created.json(1 hunks)apps/web/lib/webhook/schemas.ts(2 hunks)apps/web/lib/webhook/transform.ts(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Vade Review
- GitHub Check: build
🔇 Additional comments (4)
apps/web/lib/api/conversions/track-sale.ts (1)
539-540: Passing raw object metadata to webhook is correct; confirm response schema parityThis overrides the stringified metadata in saleData for the webhook path—intended and good. Please confirm trackSaleResponseSchema.sss accepts metadata as an object to match the response you return.
If it doesn’t, update the response schema or serialize consistently.
apps/web/lib/api/conversions/track-lead.ts (1)
325-333: Good: metadata now included in lead webhook payloadThis matches the updated schema and transform. No issues spotted.
apps/web/lib/webhook/transform.ts (2)
75-78: LGTM: lead metadata passthroughThe null defaulting is correct and aligns with the schema.
104-107: LGTM: sale metadata passthroughCorrectly prefers the object provided by callers (over any stringified value upstream).
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: 0
🧹 Nitpick comments (1)
apps/web/lib/webhook/sample-events/sale-created.json (1)
83-84: Consider a non-null example to clarify expected usage.Showing a minimal populated object improves DX and sets expectations for nesting/key types.
- "metadata": null + "metadata": { + "source": "checkout", + "coupon": "WELCOME10", + "extra": { "plan": "pro", "seats": 5 } + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/web/lib/webhook/sample-events/sale-created.json(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Vade Review
- GitHub Check: build
🔇 Additional comments (2)
apps/web/lib/webhook/sample-events/sale-created.json (2)
83-84: LGTM: metadata field added and JSON stays valid.The comma after the sale object and the root-level "metadata": null are correct. No JSON trailing-comma issues.
83-84: Verify event name and parallel sample updates.
- Confirm that eventName "Subscription" is the intended value for sale.created consumers.
- Ensure lead-created.json carries the same top-level metadata shape and null default.
Summary by CodeRabbit
New Features
Documentation
Tests