Repository navigation
feat: source transformation endpoint for facebook_lead_ads_native source - #4746
Conversation
Summary by CodeRabbit
WalkthroughAdds TypeScript types and a transformation module for Facebook Lead Ads native V2 payloads. The transform validates the body, iterates entries and changes, creates IDENTIFY events for valid lead records (userId, anonymousId, messageId, context.traits, timestamps), logs/skips invalid items, and errors if no events are produced. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant Transform
participant Extractor as V2 Body Extractor
participant Processor as Entry/Change Processor
participant Output
Caller->>Transform: process(payload)
Transform->>Extractor: getBodyFromV2SpecPayload(payload)
alt invalid V2 payload
Extractor-->>Transform: throw TransformationError
Transform-->>Caller: Error
else valid body
Extractor-->>Transform: body
Transform->>Processor: iterate entries
loop each entry
alt no changes
Processor-->>Transform: log skip (no changes)
else has changes
loop each change
alt missing required fields
Processor-->>Transform: log skip (missing field)
else valid change
Processor->>Processor: generate UUID (anonymousId)
Processor->>Processor: compose messageId (page:form:lead)
Processor->>Output: emit IDENTIFY event
end
end
end
end
alt no events created
Transform-->>Caller: throw TransformationError
else events created
Transform-->>Caller: return events[]
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/sources/facebook_lead_ads_native/transform.ts (3)
8-8: Use consistent ES6 import syntax.The file mixes ES6 imports (lines 1-7) with CommonJS require. For consistency, convert this to an ES6 import statement.
Apply this diff:
-const { getBodyFromV2SpecPayload } = require('../../v0/util'); +import { getBodyFromV2SpecPayload } from '../../v0/util';
37-42: Consider more specific logging for missing fields.While the validation logic is correct, the log message could be more helpful by indicating which specific field is missing (value, leadgen_id, page_id, or form_id).
Consider this enhancement:
- if (!value || !value.leadgen_id || !value.page_id || !value.form_id) { - logger.info('[facebook_lead_ads_native] Skipping change: missing required fields', { - entryId: entry.id, - }); + if (!value) { + logger.info('[facebook_lead_ads_native] Skipping change: missing value field', { + entryId: entry.id, + }); + return; + } + + const missingFields = []; + if (!value.leadgen_id) missingFields.push('leadgen_id'); + if (!value.page_id) missingFields.push('page_id'); + if (!value.form_id) missingFields.push('form_id'); + + if (missingFields.length > 0) { + logger.info('[facebook_lead_ads_native] Skipping change: missing required fields', { + entryId: entry.id, + missingFields, + }); return; }
49-49: Consider messageId collision risk.The messageId composition uses dashes to concatenate IDs. While Facebook IDs typically don't contain dashes, consider using a more collision-resistant approach if there's any possibility of dash characters in the IDs.
If collision risk exists, consider alternatives:
// Option 1: Use a delimiter less likely to appear in IDs messageId: `${value.page_id}|${value.form_id}|${value.leadgen_id}`, // Option 2: Use a hash function for guaranteed uniqueness import { createHash } from 'crypto'; messageId: createHash('sha256').update(`${value.page_id}${value.form_id}${value.leadgen_id}`).digest('hex'),
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
README.mdis excluded by!**/*.mdtest/integrations/sources/facebook_lead_ads_native/data.tsis excluded by!**/test/**
📒 Files selected for processing (2)
src/sources/facebook_lead_ads_native/transform.ts(1 hunks)src/sources/facebook_lead_ads_native/type.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: ItsSudip
Repo: rudderlabs/rudder-transformer PR: 4497
File: src/v0/destinations/tiktok_ads/transformV2.js:686-691
Timestamp: 2025-07-15T06:27:07.528Z
Learning: For TikTok Ads destination in src/v0/destinations/tiktok_ads/transformV2.js, there are plans for a future enhancement to group events by eventSource when batching to ensure all events in a batch have the same event_source value, as acknowledged by ItsSudip in PR #4497.
📚 Learning: 2025-03-21T12:32:28.443Z
Learnt from: krishna2020
Repo: rudderlabs/rudder-transformer PR: 4178
File: src/sources/shopify/transform.js:37-45
Timestamp: 2025-03-21T12:32:28.443Z
Learning: The getBodyFromV2SpecPayload function in Shopify source transformation throws an error if request is not defined, making additional null checks in getEventFromV2Request function unnecessary.
Applied to files:
src/sources/facebook_lead_ads_native/transform.ts
🧬 Code graph analysis (1)
src/sources/facebook_lead_ads_native/transform.ts (4)
src/sources/facebook_lead_ads_native/type.ts (4)
InputEventType(18-21)OutputEventType(23-36)FacebookEntry(12-16)FacebookChange(8-10)src/constants/index.js (1)
EventType(1-10)src/types/sourceTransformation.ts (1)
SourceInputV2(28-31)src/v0/util/index.js (1)
getBodyFromV2SpecPayload(2442-2452)
⏰ 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). (8)
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Code Coverage
- GitHub Check: test_and_publish
- GitHub Check: UT Tests
- GitHub Check: Analyze (go)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (6)
src/sources/facebook_lead_ads_native/type.ts (2)
1-21: Input type definitions look good.The input types appropriately model the Facebook webhook payload structure with optional fields, allowing for flexible validation in the transformation logic. The hierarchy (InputEventType → FacebookEntry → FacebookChange → FacebookChangeValue) correctly represents the nested structure of Facebook Lead Ads webhooks.
23-36: Output type enforces RudderStack event contract correctly.The OutputEventType properly defines required fields for the identify event, ensuring downstream consumers receive well-formed events. The nested context.traits structure for page_id and form_id aligns with RudderStack conventions.
src/sources/facebook_lead_ads_native/transform.ts (4)
10-20: Top-level validation is appropriate.The validation logic correctly ensures the webhook payload has the expected structure (object must be "page" and entry array must exist and be non-empty) before processing.
48-48: Verify anonymousId generation strategy.A new UUID is generated for each event's anonymousId, meaning multiple events from the same lead will have different anonymousIds. Confirm this is the intended behavior. If the same leadgen_id can appear multiple times, consider deriving the anonymousId consistently from the leadgen_id for better identity resolution.
Example of consistent anonymousId approach:
// If consistent anonymousId is desired import { createHash } from 'crypto'; anonymousId: createHash('sha256').update(value.leadgen_id).digest('hex'),
65-70: Final validation ensures output quality.The check for empty events array with appropriate error handling ensures the function either returns valid events or fails explicitly, preventing silent failures.
72-77: Entry point function is well-structured.The process function provides a clean entry point with clear separation of concerns: payload extraction via getBodyFromV2SpecPayload and event transformation via processEvent.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #4746 +/- ##
===========================================
- Coverage 91.92% 91.92% -0.01%
===========================================
Files 651 652 +1
Lines 34609 34650 +41
Branches 8121 8143 +22
===========================================
+ Hits 31816 31853 +37
+ Misses 2563 2548 -15
- Partials 230 249 +19 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Allure Test reports for this run are available at:
|
1 similar comment
|
Allure Test reports for this run are available at:
|
486df3d to
44add48
Compare
|
Allure Test reports for this run are available at:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/sources/facebook_lead_ads_native/transform.ts (2)
46-46: Consider a more robust messageId composition.The current messageId uses simple hyphen concatenation. If any of the component IDs (
page_id,form_id,leadgen_id) contain hyphens, this could lead to ambiguous parsing or potential collisions.Consider using a delimiter that's less likely to appear in IDs, or encode the components:
- messageId: `${value.page_id}-${value.form_id}-${value.leadgen_id}`, + messageId: `${value.page_id}:${value.form_id}:${value.leadgen_id}`,Alternatively, generate a hash-based messageId for guaranteed uniqueness:
import { createHash } from 'crypto'; messageId: createHash('sha256') .update(`${value.page_id}${value.form_id}${value.leadgen_id}`) .digest('hex') .substring(0, 32),
35-40: Consider more descriptive validation logging.While the validation logic is correct, the log message could be more helpful by specifying which required fields are missing. This would aid in debugging webhook issues.
// Skip if required fields are missing if (!value || !value.leadgen_id || !value.page_id || !value.form_id) { logger.info('[facebook_lead_ads_native] Skipping change: missing required fields', { entryId: entry.id, + hasValue: !!value, + hasLeadgenId: !!value?.leadgen_id, + hasPageId: !!value?.page_id, + hasFormId: !!value?.form_id, }); return; }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
test/integrations/sources/facebook_lead_ads_native/data.tsis excluded by!**/test/**
📒 Files selected for processing (2)
src/sources/facebook_lead_ads_native/transform.ts(1 hunks)src/sources/facebook_lead_ads_native/type.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/sources/facebook_lead_ads_native/type.ts
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: ItsSudip
Repo: rudderlabs/rudder-transformer PR: 4497
File: src/v0/destinations/tiktok_ads/transformV2.js:686-691
Timestamp: 2025-07-15T06:27:07.528Z
Learning: For TikTok Ads destination in src/v0/destinations/tiktok_ads/transformV2.js, there are plans for a future enhancement to group events by eventSource when batching to ensure all events in a batch have the same event_source value, as acknowledged by ItsSudip in PR #4497.
🧬 Code graph analysis (1)
src/sources/facebook_lead_ads_native/transform.ts (4)
src/sources/facebook_lead_ads_native/type.ts (4)
InputEventType(18-21)OutputEventType(23-35)FacebookEntry(12-16)FacebookChange(8-10)src/constants/index.js (1)
EventType(1-10)src/types/sourceTransformation.ts (1)
SourceInputV2(28-31)src/v0/util/index.js (1)
getBodyFromV2SpecPayload(2442-2452)
⏰ 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). (8)
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Code Coverage
- GitHub Check: UT Tests
- GitHub Check: test_and_publish
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Analyze (go)
🔇 Additional comments (1)
src/sources/facebook_lead_ads_native/transform.ts (1)
21-21: No timestamp conversion issues detected.The verification confirms that Facebook Lead Ads webhooks provide both
entry.timeandvalue.created_timeas Unix epoch timestamps in seconds (integers). The code's multiplication by 1000 is correct—it properly converts seconds to milliseconds for JavaScript'sDateobject constructor. The timestamp handling at lines 21 and 53–54 is accurate and requires no changes.
|
Allure Test reports for this run are available at:
|
|
* feat: introduce e2e tests UT (#4686) * chore: update slack notification list (#4706) * chore: skip pushing docker images for dependabot (#4714) * chore: skip building images for debendabot * chore: review comments * chore: skip docker login for dependabot * chore: skip docker login for dependabot * chore: misc * chore: misc * chore: misc * chore: misc * chore: review comments * chore: review comments * chore: review comments * chore: review comments * chore: review comments * chore: add dub to new test structure (#4717) * chore: add readme for campaign_manager (#4710) * chore: update GAOC readme with quota link (#4723) * chore: apply security best practices (#4708) [StepSecurity] Apply security best practices Signed-off-by: StepSecurity Bot <[email protected]> * feat: add validation of diff in staging deployment workflow (#4722) * chore(deps-dev): bump commander from 10.0.1 to 14.0.2 Bumps [commander](https://github.com/tj/commander.js) from 10.0.1 to 14.0.2. - [Release notes](https://github.com/tj/commander.js/releases) - [Changelog](https://github.com/tj/commander.js/blob/master/CHANGELOG.md) - [Commits](tj/commander.js@v10.0.1...v14.0.2) --- updated-dependencies: - dependency-name: commander dependency-version: 14.0.2 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * chore(deps-dev): bump supertest from 6.3.4 to 7.1.4 (#4525) --- updated-dependencies: - dependency-name: supertest dependency-version: 7.1.4 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore: add env vars for controlling the connection pooling on python transformations (#4738) * chore: update facebook conversion api version from 22.0 to 24.0 (#4734) * chore: update facebook conversion api version from 22.0 to 23.0 * chore: update facebook conversion api version from 23.0 to 45.0 * chore: fix typo * chore: update facebook custom audience api version from 22.0 to 23.0 (#4735) * chore: update facebook custom audience api version from 22.0 to 23.0 * chore: update facebook custom audience api version from 23.0 to 24.0 * chore: update facebook custom audience api version from 24.0 to 23.0 as it has some breaking changes * chore: update facebook pixel api version from 22.0 to 24.0 (#4737) * chore: update facebook pixel api version from 22.0 to 24.0 * chore: update facebook app events api version from 22.0 to 24.0 (#4736) * chore: move rs-ai memory bank to transformer * chore: add nodemon for hot reloading (#4748) * chore: refactor code to update variable name in more readable format (#4747) * feat: source transformation endpoint for facebook_lead_ads_native source (#4746) * chore: disable clustering in nodemon configuration (#4749) * chore: run format check on all files (#4750) * fix: intercom rETL flow when user_id only provided as identifier (#4739) * chore: apply security best practices from step security (#4727) [StepSecurity] Apply security best practices Signed-off-by: StepSecurity Bot <[email protected]> Co-authored-by: stepsecurity-app[bot] <188008098+stepsecurity-app[bot]@users.noreply.github.com> * chore(deps): bump actions/setup-node from 5.0.0 to 6.0.0 Bumps [actions/setup-node](https://github.com/actions/setup-node) from 5.0.0 to 6.0.0. - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](actions/setup-node@v5.0.0...v6.0.0) --- updated-dependencies: - dependency-name: actions/setup-node dependency-version: 6.0.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * chore: remove logs logging request/response body (#4754) * chore: disable pyroscope for primary process in cluster mode (#4756) * feat(reddit): onboard v3 api (#4699) * feat(reddit): onboard v3 api * chore: implement router batching flow * feat: enable batching scenario * chore: add test cases * chore: address coderabbit comments * chore: add mock for timestamp * chore: add documentation for reddit * fix: use crypto for hashing * chore: address coderabbit comment * chore: address comments * chore: add validation and remove double type assertion * chore: remove undefined files from final palyload * chore: fix test case * feat(reddit): onboard v3 api * chore: implement router batching flow * feat: enable batching scenario * chore: add test cases * chore: address coderabbit comments * chore: add mock for timestamp * chore: add documentation for reddit * fix: use crypto for hashing * chore: address coderabbit comment * chore: address comments * chore: add validation and remove double type assertion * chore: remove undefined files from final palyload * chore: fix test case * chore: apply format * chore: apply format * chore(deps): bump actions/checkout from 4.3.0 to 5.0.0 Bumps [actions/checkout](https://github.com/actions/checkout) from 4.3.0 to 5.0.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](actions/checkout@v4.3.0...08c6903) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: 5.0.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * feat: add advertiser_tracking_enabled mapping for pinterest without featureFlag (#4740) * chore(deps): bump actions/stale from 10.0.0 to 10.1.0 Bumps [actions/stale](https://github.com/actions/stale) from 10.0.0 to 10.1.0. - [Release notes](https://github.com/actions/stale/releases) - [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md) - [Commits](actions/stale@v10.0.0...v10.1.0) --- updated-dependencies: - dependency-name: actions/stale dependency-version: 10.1.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * chore: handle breaking changes for commander * chore: fix breaking commander changes * chore(release): 1.112.0 --------- Signed-off-by: StepSecurity Bot <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Rohith BCS <[email protected]> Co-authored-by: Vinay Teki <[email protected]> Co-authored-by: Mahesh Kutty <[email protected]> Co-authored-by: Sudip Paul <[email protected]> Co-authored-by: stepsecurity-app[bot] <188008098+stepsecurity-app[bot]@users.noreply.github.com> Co-authored-by: Krishna Chaitanya <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jayachand Mopidevi <[email protected]> Co-authored-by: GitHub Actions <[email protected]> Co-authored-by: shekhar-rudder <[email protected]>



Summary
Adds source transformation support for Facebook Lead Ads Native webhooks, converting Facebook lead generation events into RudderStack identify events.
Changes
facebook_lead_ads_nativesourceidentifyeventleadgen_idtoanonymousIdand includespage_idandform_idas traitsobject,entry,leadgen_id,page_id,form_id)Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?
N/A
Any new dependencies introduced with this change?
N/A
Any new generic utility introduced or modified. Please explain the changes.
N/A
Any technical or performance related pointers to consider with the change?
N/A
@coderabbitai review
Developer checklist
My code follows the style guidelines of this project
No breaking changes are being introduced.
All related docs linked with the PR?
All changes manually tested?
Any documentation changes needed with this change?
Is the PR limited to 10 file changes?
Is the PR limited to one linear task?
Are relevant unit and component test-cases added in new readability format?
Reviewer checklist
Is the type of change in the PR title appropriate as per the changes?
Verified that there are no credentials or confidential data exposed with the changes.