Added ability to define user attributes as callback functions#110
Conversation
WalkthroughThe changes introduce support for user attributes defined as callback functions in the consent management platform integration. The code now evaluates any function-valued user attributes before including them in API requests, and the changelog has been updated to document this new feature. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CmpApiIntegration
participant ConsentAPI
User->>CmpApiIntegration: Initiate consent API request with user.attributes
CmpApiIntegration->>CmpApiIntegration: Iterate over user.attributes
alt Attribute is a function
CmpApiIntegration->>CmpApiIntegration: Call function, get value
else Attribute is not a function
CmpApiIntegration->>CmpApiIntegration: Use value directly
end
CmpApiIntegration->>ConsentAPI: Send request with evaluated attributes
Poem
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure ✨ Finishing Touches
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. 🪧 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 (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/Integration/CmpApiIntegration.mjs (2)
23-29: Consider adding error handling for attribute callbacks.If a callback function throws an exception, it could cause the entire consent API request to fail silently. Consider adding try/catch handling.
Object.keys(user.attributes).forEach(key => { const value = user.attributes[key]; - attributes[key] = 'function' === typeof value ? value() : value; + if ('function' === typeof value) { + try { + attributes[key] = value(); + } catch (error) { + console.warn(`Error executing callback for attribute "${key}":`, error); + attributes[key] = null; + } + } else { + attributes[key] = value; + } });
23-29: Consider passing context to attribute callbacks.Currently, callbacks are executed without parameters. You might want to consider passing useful context like the current consent state, which would allow for more powerful dynamic attributes.
-Object.keys(user.attributes).forEach(key => { - const value = user.attributes[key]; - attributes[key] = 'function' === typeof value ? value() : value; -}); +Object.keys(user.attributes).forEach(key => { + const value = user.attributes[key]; + attributes[key] = 'function' === typeof value ? value(userConsent) : value; +});
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (2)
CHANGELOG.md(1 hunks)src/Integration/CmpApiIntegration.mjs(1 hunks)
🧰 Additional context used
🪛 LanguageTool
CHANGELOG.md
[duplication] ~9-~9: Possible typo: you repeated a word.
Context: ...spec/v2.0.0.html). ## [Unreleased] ### Added - Added ability to define user attributes as ca...
(ENGLISH_WORD_REPEAT_RULE)
🔇 Additional comments (3)
CHANGELOG.md (1)
9-10: LGTM - Clear and well-placed changelog entry.The changelog entry clearly describes the new feature and follows the project's changelog format.
🧰 Tools
🪛 LanguageTool
[duplication] ~9-~9: Possible typo: you repeated a word.
Context: ...spec/v2.0.0.html). ## [Unreleased] ### Added - Added ability to define user attributes as ca...(ENGLISH_WORD_REPEAT_RULE)
src/Integration/CmpApiIntegration.mjs (2)
23-29: Correctly implements attribute callback processing.The implementation properly evaluates function attributes before sending them to the API. This allows for dynamic attribute values that can be computed at the time of consent interaction.
36-36: Correctly uses the processed attributes in the request body.The implementation correctly uses the newly processed attributes object in the request payload.
Summary by CodeRabbit